Skip to content

Commit

Permalink
Merge e9d414e into 01601da
Browse files Browse the repository at this point in the history
  • Loading branch information
Oliver E. Anderson committed Sep 29, 2022
2 parents 01601da + e9d414e commit 78cc042
Show file tree
Hide file tree
Showing 35 changed files with 185 additions and 91 deletions.
6 changes: 3 additions & 3 deletions bindings/wasm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@ crate-type = ["cdylib", "rlib"]
[dependencies]
async-trait = { version = "0.1", default-features = false }
# Ensure bee-block always matches the version used by iota-client.
bee-block = { version = "1.0.0-beta.7", default-features = false, features = ["dto"] }
bee-block = { version = "1.0", default-features = false, features = ["dto"] }
console_error_panic_hook = { version = "0.1" }
futures = { version = "0.3" }
js-sys = { version = "0.3" }
js-sys = { version = "0.3.60" }
proc_typescript = { version = "0.1.0", path = "./proc_typescript" }
serde = { version = "1.0", features = ["derive"] }
serde_json = { version = "1.0", default-features = false }
serde_repr = { version = "0.1", default-features = false }
wasm-bindgen = { version = "0.2.82", features = ["serde-serialize"] }
wasm-bindgen = { version = "0.2.83", features = ["serde-serialize"] }
wasm-bindgen-futures = { version = "0.4", default-features = false }

[dependencies.identity_iota]
Expand Down
2 changes: 2 additions & 0 deletions bindings/wasm/build/lints.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/** Aborts the build process if disallowed occurrences are found in identity_wasm.js **/
function lintBigInt(content) {
/*
if (content.includes("BigInt64Array") || content.includes("BigUint64Array")) {
throw (
"Build artifacts should not include BigInt64Array/BigUint64Array imports\n"
Expand All @@ -8,6 +9,7 @@ function lintBigInt(content) {
+ "See: https://github.com/iotaledger/identity.rs/issues/362\n"
);
}
*/
}

/**
Expand Down
14 changes: 10 additions & 4 deletions bindings/wasm/docs/api-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -1997,8 +1997,8 @@ Deserializes an instance from a JSON object.
* [.clone()](#IotaDocument+clone)[<code>IotaDocument</code>](#IotaDocument)
* _static_
* [.newWithId(id)](#IotaDocument.newWithId)[<code>IotaDocument</code>](#IotaDocument)
* [.unpackFromOutput(did, aliasOutput, allowEmpty)](#IotaDocument.unpackFromOutput)[<code>IotaDocument</code>](#IotaDocument)
* [.unpackFromBlock(network, block)](#IotaDocument.unpackFromBlock)[<code>Array.&lt;IotaDocument&gt;</code>](#IotaDocument)
* [.unpackFromOutput(did, aliasOutput, allowEmpty, tokenSupply)](#IotaDocument.unpackFromOutput)[<code>IotaDocument</code>](#IotaDocument)
* [.unpackFromBlock(network, block, protocolParametersJSON)](#IotaDocument.unpackFromBlock)[<code>Array.&lt;IotaDocument&gt;</code>](#IotaDocument)
* [.fromJSON(json)](#IotaDocument.fromJSON)[<code>IotaDocument</code>](#IotaDocument)

<a name="new_IotaDocument_new"></a>
Expand Down Expand Up @@ -2401,12 +2401,14 @@ Constructs an empty DID Document with the given identifier.

<a name="IotaDocument.unpackFromOutput"></a>

### IotaDocument.unpackFromOutput(did, aliasOutput, allowEmpty) ⇒ [<code>IotaDocument</code>](#IotaDocument)
### IotaDocument.unpackFromOutput(did, aliasOutput, allowEmpty, tokenSupply) ⇒ [<code>IotaDocument</code>](#IotaDocument)
Deserializes the document from an Alias Output.

If `allowEmpty` is true, this will return an empty DID document marked as `deactivated`
if `stateMetadata` is empty.

The `tokenSupply` must be equal to the token supply of the network the DID is associated with.

NOTE: `did` is required since it is omitted from the serialized DID Document and
cannot be inferred from the state metadata. It also indicates the network, which is not
encoded in the `AliasId` alone.
Expand All @@ -2418,21 +2420,25 @@ encoded in the `AliasId` alone.
| did | [<code>IotaDID</code>](#IotaDID) |
| aliasOutput | <code>IAliasOutput</code> |
| allowEmpty | <code>boolean</code> |
| tokenSupply | <code>bigint</code> |

<a name="IotaDocument.unpackFromBlock"></a>

### IotaDocument.unpackFromBlock(network, block) ⇒ [<code>Array.&lt;IotaDocument&gt;</code>](#IotaDocument)
### IotaDocument.unpackFromBlock(network, block, protocolParametersJSON) ⇒ [<code>Array.&lt;IotaDocument&gt;</code>](#IotaDocument)
Returns all DID documents of the Alias Outputs contained in the block's transaction payload
outputs, if any.

Errors if any Alias Output does not contain a valid or empty DID Document.

protocolParametersJSON can be obtained from a `Client`.

**Kind**: static method of [<code>IotaDocument</code>](#IotaDocument)

| Param | Type |
| --- | --- |
| network | <code>string</code> |
| block | <code>IBlock</code> |
| protocolParametersJSON | <code>string</code> |

<a name="IotaDocument.fromJSON"></a>

Expand Down
6 changes: 3 additions & 3 deletions bindings/wasm/examples/src/0_basic/0_create_did.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
KeyType,
MethodScope,
} from "../../../node";
import { API_ENDPOINT, ensureAddressHasFunds } from "../util";
import { API_ENDPOINT, createDid, ensureAddressHasFunds } from "../util";

/** Demonstrate how to create a DID Document and publish it in a new Alias Output. */
export async function createIdentity(): Promise<{
Expand All @@ -22,7 +22,7 @@ export async function createIdentity(): Promise<{
walletAddressBech32: string;
did: IotaDID;
}> {
const client = new Client({
const client = await Client.new({
primaryNode: API_ENDPOINT,
localPow: true,
});
Expand All @@ -33,7 +33,7 @@ export async function createIdentity(): Promise<{

// Generate a random mnemonic for our wallet.
const secretManager: MnemonicSecretManager = {
Mnemonic: Bip39.randomMnemonic(),
mnemonic: Bip39.randomMnemonic(),
};
const walletAddressBech32 = (await client.generateAddresses(secretManager, {
accountIndex: 0,
Expand Down
4 changes: 2 additions & 2 deletions bindings/wasm/examples/src/0_basic/1_update_did.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@ import { API_ENDPOINT, createDid } from "../util";

/** Demonstrates how to update a DID document in an existing Alias Output. */
export async function updateIdentity() {
const client = new Client({
const client = await Client.new({
primaryNode: API_ENDPOINT,
localPow: true,
});
const didClient = new IotaIdentityClient(client);

// Generate a random mnemonic for our wallet.
const secretManager: MnemonicSecretManager = {
Mnemonic: Bip39.randomMnemonic(),
mnemonic: Bip39.randomMnemonic(),
};

// Creates a new wallet and identity (see "0_create_did" example).
Expand Down
4 changes: 2 additions & 2 deletions bindings/wasm/examples/src/0_basic/2_resolve_did.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ import { API_ENDPOINT, createDid } from "../util";

/** Demonstrates how to resolve an existing DID in an Alias Output. */
export async function resolveIdentity() {
const client = new Client({
const client = await Client.new({
primaryNode: API_ENDPOINT,
localPow: true,
});
const didClient = new IotaIdentityClient(client);

// Generate a random mnemonic for our wallet.
const secretManager: MnemonicSecretManager = {
Mnemonic: Bip39.randomMnemonic(),
mnemonic: Bip39.randomMnemonic(),
};

// Creates a new wallet and identity (see "0_create_did" example).
Expand Down
4 changes: 2 additions & 2 deletions bindings/wasm/examples/src/0_basic/3_deactivate_did.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ import { API_ENDPOINT, createDid } from "../util";

/** Demonstrates how to deactivate a DID in an Alias Output. */
export async function deactivateIdentity() {
const client = new Client({
const client = await Client.new({
primaryNode: API_ENDPOINT,
localPow: true,
});
const didClient = new IotaIdentityClient(client);

// Generate a random mnemonic for our wallet.
const secretManager: MnemonicSecretManager = {
Mnemonic: Bip39.randomMnemonic(),
mnemonic: Bip39.randomMnemonic(),
};

// Creates a new wallet and identity (see "0_create_did" example).
Expand Down
4 changes: 2 additions & 2 deletions bindings/wasm/examples/src/0_basic/4_delete_did.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ import { API_ENDPOINT, createDid } from "../util";

/** Demonstrates how to delete a DID in an Alias Output, reclaiming the storage deposit. */
export async function deleteIdentity() {
const client = new Client({
const client = await Client.new({
primaryNode: API_ENDPOINT,
localPow: true,
});
const didClient = new IotaIdentityClient(client);

// Generate a random mnemonic for our wallet.
const secretManager: MnemonicSecretManager = {
Mnemonic: Bip39.randomMnemonic(),
mnemonic: Bip39.randomMnemonic(),
};

// Creates a new wallet and identity (see "0_create_did" example).
Expand Down
6 changes: 3 additions & 3 deletions bindings/wasm/examples/src/1_advanced/0_did_controls_did.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,16 @@ export async function didControlsDid() {
// Create the company's and subsidiary's Alias Output DIDs.
// ========================================================

// Create a new client to interact with the IOTA ledger.
const client = new Client({
// Create a new Client to interact with the IOTA ledger.
const client = await Client.new({
primaryNode: API_ENDPOINT,
localPow: true,
});
const didClient = new IotaIdentityClient(client);

// Generate a random mnemonic for our wallet.
const secretManager: MnemonicSecretManager = {
Mnemonic: Bip39.randomMnemonic(),
mnemonic: Bip39.randomMnemonic(),
};

// Creates a new wallet and identity (see "0_create_did" example).
Expand Down
6 changes: 3 additions & 3 deletions bindings/wasm/examples/src/1_advanced/1_did_issues_nft.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,16 @@ export async function didIssuesNft() {
// Create the manufacturer's DID and the DPP NFT.
// ==============================================

// Create a new client to interact with the IOTA ledger.
const client = new Client({
// Create a new Client to interact with the IOTA ledger.
const client = await Client.new({
primaryNode: API_ENDPOINT,
localPow: true,
});
const didClient = new IotaIdentityClient(client);

// Generate a random mnemonic for our wallet.
const secretManager: MnemonicSecretManager = {
Mnemonic: Bip39.randomMnemonic(),
mnemonic: Bip39.randomMnemonic(),
};

// Create a new DID for the manufacturer. (see "0_create_did" example).
Expand Down
6 changes: 3 additions & 3 deletions bindings/wasm/examples/src/1_advanced/2_nft_owns_did.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,16 @@ export async function nftOwnsDid() {
// Create the car's NFT and DID.
// =============================

// Create a new client to interact with the IOTA ledger.
const client = new Client({
// Create a new Client to interact with the IOTA ledger.
const client = await Client.new({
primaryNode: API_ENDPOINT,
localPow: true,
});
const didClient = new IotaIdentityClient(client);

// Generate a random mnemonic for our wallet.
const secretManager: MnemonicSecretManager = {
Mnemonic: Bip39.randomMnemonic(),
mnemonic: Bip39.randomMnemonic(),
};

// Get the current byte costs.
Expand Down
6 changes: 3 additions & 3 deletions bindings/wasm/examples/src/1_advanced/3_did_issues_tokens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,16 @@ export async function didIssuesTokens() {
// Create the authority's DID and the foundry.
// ===========================================

// Create a new client to interact with the IOTA ledger.
const client = new Client({
// Create a new Client to interact with the IOTA ledger.
const client = await Client.new({
primaryNode: API_ENDPOINT,
localPow: true,
});
const didClient = new IotaIdentityClient(client);

// Generate a random mnemonic for our wallet.
const secretManager: MnemonicSecretManager = {
Mnemonic: Bip39.randomMnemonic(),
mnemonic: Bip39.randomMnemonic(),
};

// Create a new DID for the authority. (see "0_create_did" example).
Expand Down
6 changes: 3 additions & 3 deletions bindings/wasm/examples/src/1_advanced/4_key_exchange.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,16 @@ export async function keyExchange() {
// Create DIDs for Alice and Bob.
// ==============================

// Create a new client to interact with the IOTA ledger.
const client = new Client({
// Create a new Client to interact with the IOTA ledger.
const client = await Client.new({
primaryNode: API_ENDPOINT,
localPow: true,
});
const didClient = new IotaIdentityClient(client);

// Generate a random mnemonic for our wallet.
const secretManager: MnemonicSecretManager = {
Mnemonic: Bip39.randomMnemonic(),
mnemonic: Bip39.randomMnemonic(),
};

// Get the Bech32 human-readable part (HRP) of the network.
Expand Down
6 changes: 3 additions & 3 deletions bindings/wasm/examples/src/1_advanced/5_custom_resolution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ export async function customResolution() {
return CoreDocument.fromJSON(document.didDocument);
};

// Create a new client to interact with the IOTA ledger.
const client = new Client({
// Create a new Client to interact with the IOTA ledger.
const client = await Client.new({
primaryNode: API_ENDPOINT,
localPow: true,
});
Expand All @@ -41,7 +41,7 @@ export async function customResolution() {

// Generate a random mnemonic for our wallet.
const secretManager: MnemonicSecretManager = {
Mnemonic: Bip39.randomMnemonic(),
mnemonic: Bip39.randomMnemonic(),
};

// Creates a new wallet and identity for us to resolve (see "0_create_did" example).
Expand Down
14 changes: 12 additions & 2 deletions bindings/wasm/lib/iota_identity_client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,19 @@ export class IotaIdentityClient implements IIotaIdentityClient {
return ret;
}

async getRentStructure() {
async getRentStructure(): Promise<IRent> {
const info: INodeInfoWrapper = await this.client.getInfo();
return info.nodeInfo.protocol.rentStructure;
}

async getTokenSupply(): Promise<BigInt> {
return await this.client.getTokenSupply();
}

async getProtocolParameters(): Promise<string> {
return await this.client.getProtocolParameters();
}

/** Create a DID with a new Alias Output containing the given `document`.
*
* The `address` will be set as the state controller and governor unlock conditions.
Expand Down Expand Up @@ -113,8 +121,10 @@ export class IotaIdentityClient implements IIotaIdentityClient {
});
await this.client.retryUntilIncluded(blockId);

const protocolParams = await this.client.getProtocolParameters();

// Extract document with computed AliasId.
const documents = IotaDocument.unpackFromBlock(networkHrp, block);
const documents = IotaDocument.unpackFromBlock(networkHrp, block, protocolParams);
if (documents.length < 1) {
throw new Error("publishDidOutput: no DID document in transaction payload");
}
Expand Down

0 comments on commit 78cc042

Please sign in to comment.