Skip to content

Commit

Permalink
Update to iota-client 2.0.1-rc.4 and iota-client-wasm 0.5.0-alpha…
Browse files Browse the repository at this point in the history
….6 (#1088)
  • Loading branch information
Oliver E. Anderson authored Nov 24, 2022
1 parent 2f19dbd commit c251d90
Show file tree
Hide file tree
Showing 42 changed files with 221 additions and 223 deletions.
3 changes: 1 addition & 2 deletions bindings/wasm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ crate-type = ["cdylib", "rlib"]
async-trait = { version = "0.1", default-features = false }
console_error_panic_hook = { version = "0.1" }
futures = { version = "0.3" }
# Pin until iota-client v2.0.1-rc.4 is released
iota-types = { version = "=1.0.0-rc.1", default-features = false, features = ["block", "api", "dto", "std"] }
iota-types = { version = "1.0.0-rc.3", default-features = false, features = ["block", "api", "dto", "std"] }
js-sys = { version = "0.3.60" }
proc_typescript = { version = "0.1.0", path = "./proc_typescript" }
serde = { version = "1.0", features = ["derive"] }
Expand Down
2 changes: 1 addition & 1 deletion bindings/wasm/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ const API_ENDPOINT = "http://127.0.0.1:14265";
/** Demonstrate how to create a DID Document. */
async function main() {
// Create a new client with the given network endpoint.
const client = await Client.new({
const client = new Client({
primaryNode: API_ENDPOINT,
localPow: true,
});
Expand Down
52 changes: 30 additions & 22 deletions bindings/wasm/docs/api-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,8 @@ See <code>IVerifierOptions</code>.</p>
## Members

<dl>
<dt><a href="#StateMetadataEncoding">StateMetadataEncoding</a></dt>
<dd></dd>
<dt><a href="#StatusCheck">StatusCheck</a></dt>
<dd><p>Controls validation behaviour when checking whether or not a credential has been revoked by its
<a href="https://www.w3.org/TR/vc-data-model/#status"><code>credentialStatus</code></a>.</p>
Expand Down Expand Up @@ -148,8 +150,6 @@ This variant is the default used if no other variant is specified when construct
<dd></dd>
<dt><a href="#MethodRelationship">MethodRelationship</a></dt>
<dd></dd>
<dt><a href="#StateMetadataEncoding">StateMetadataEncoding</a></dt>
<dd></dd>
</dl>

## Functions
Expand Down Expand Up @@ -510,13 +510,13 @@ A method-agnostic DID Document.
* [.properties()](#CoreDocument+properties) ⇒ <code>Map.&lt;string, any&gt;</code>
* [.setPropertyUnchecked(key, value)](#CoreDocument+setPropertyUnchecked)
* [.service()](#CoreDocument+service)[<code>Array.&lt;CoreService&gt;</code>](#CoreService)
* [.insertService(service)](#CoreDocument+insertService) ⇒ <code>boolean</code>
* [.removeService(didUrl)](#CoreDocument+removeService) ⇒ <code>boolean</code>
* [.insertService(service)](#CoreDocument+insertService)
* [.removeService(didUrl)](#CoreDocument+removeService)[<code>CoreService</code>](#CoreService) \| <code>undefined</code>
* [.resolveService(query)](#CoreDocument+resolveService)[<code>CoreService</code>](#CoreService) \| <code>undefined</code>
* [.methods(scope)](#CoreDocument+methods)[<code>Array.&lt;CoreVerificationMethod&gt;</code>](#CoreVerificationMethod)
* [.verificationRelationships()](#CoreDocument+verificationRelationships) ⇒ <code>Array.&lt;(CoreDIDUrl\|CoreVerificationMethod)&gt;</code>
* [.insertMethod(method, scope)](#CoreDocument+insertMethod)
* [.removeMethod(did)](#CoreDocument+removeMethod)
* [.removeMethod(did)](#CoreDocument+removeMethod)[<code>CoreVerificationMethod</code>](#CoreVerificationMethod) \| <code>undefined</code>
* [.resolveMethod(query, scope)](#CoreDocument+resolveMethod)[<code>CoreVerificationMethod</code>](#CoreVerificationMethod) \| <code>undefined</code>
* [.attachMethodRelationship(didUrl, relationship)](#CoreDocument+attachMethodRelationship) ⇒ <code>boolean</code>
* [.detachMethodRelationship(didUrl, relationship)](#CoreDocument+detachMethodRelationship) ⇒ <code>boolean</code>
Expand Down Expand Up @@ -550,6 +550,12 @@ Returns a copy of the DID Document `id`.
### coreDocument.setId(id)
Sets the DID of the document.

### Warning

Changing the identifier can drastically alter the results of
[`Self::resolve_method`](CoreDocument::resolve_method()),
[`Self::resolve_service`](CoreDocument::resolve_service()) and the related [DID URL dereferencing](https://w3c-ccg.github.io/did-resolution/#dereferencing) algorithm.

**Kind**: instance method of [<code>CoreDocument</code>](#CoreDocument)

| Param | Type |
Expand Down Expand Up @@ -642,6 +648,7 @@ Sets a custom property in the DID Document.
If the value is set to `null`, the custom property will be removed.

### WARNING

This method can overwrite existing properties like `id` and result in an invalid document.

**Kind**: instance method of [<code>CoreDocument</code>](#CoreDocument)
Expand All @@ -659,10 +666,10 @@ Returns a set of all [CoreService](#CoreService) in the document.
**Kind**: instance method of [<code>CoreDocument</code>](#CoreDocument)
<a name="CoreDocument+insertService"></a>

### coreDocument.insertService(service) ⇒ <code>boolean</code>
### coreDocument.insertService(service)
Add a new [CoreService](#CoreService) to the document.

Returns `true` if the service was added.
Errors if there already exists a service or verification method with the same id.

**Kind**: instance method of [<code>CoreDocument</code>](#CoreDocument)

Expand All @@ -672,7 +679,7 @@ Returns `true` if the service was added.

<a name="CoreDocument+removeService"></a>

### coreDocument.removeService(didUrl) ⇒ <code>boolean</code>
### coreDocument.removeService(didUrl) ⇒ [<code>CoreService</code>](#CoreService) \| <code>undefined</code>
Remoce a [CoreService](#CoreService) identified by the given [CoreDIDUrl](#CoreDIDUrl) from the document.

Returns `true` if the service was removed.
Expand Down Expand Up @@ -729,7 +736,7 @@ Adds a new `method` to the document in the given `scope`.

<a name="CoreDocument+removeMethod"></a>

### coreDocument.removeMethod(did)
### coreDocument.removeMethod(did)[<code>CoreVerificationMethod</code>](#CoreVerificationMethod) \| <code>undefined</code>
Removes all references to the specified Verification Method.

**Kind**: instance method of [<code>CoreDocument</code>](#CoreDocument)
Expand Down Expand Up @@ -1980,12 +1987,12 @@ Deserializes an instance from a JSON object.
* [.properties()](#IotaDocument+properties) ⇒ <code>Map.&lt;string, any&gt;</code>
* [.setPropertyUnchecked(key, value)](#IotaDocument+setPropertyUnchecked)
* [.service()](#IotaDocument+service)[<code>Array.&lt;IotaService&gt;</code>](#IotaService)
* [.insertService(service)](#IotaDocument+insertService) ⇒ <code>boolean</code>
* [.removeService(did)](#IotaDocument+removeService) ⇒ <code>boolean</code>
* [.insertService(service)](#IotaDocument+insertService)
* [.removeService(did)](#IotaDocument+removeService)[<code>IotaService</code>](#IotaService) \| <code>undefined</code>
* [.resolveService(query)](#IotaDocument+resolveService)[<code>IotaService</code>](#IotaService) \| <code>undefined</code>
* [.methods(scope)](#IotaDocument+methods)[<code>Array.&lt;IotaVerificationMethod&gt;</code>](#IotaVerificationMethod)
* [.insertMethod(method, scope)](#IotaDocument+insertMethod)
* [.removeMethod(did)](#IotaDocument+removeMethod)
* [.removeMethod(did)](#IotaDocument+removeMethod)[<code>IotaVerificationMethod</code>](#IotaVerificationMethod) \| <code>undefined</code>
* [.resolveMethod(query, scope)](#IotaDocument+resolveMethod)[<code>IotaVerificationMethod</code>](#IotaVerificationMethod) \| <code>undefined</code>
* [.attachMethodRelationship(didUrl, relationship)](#IotaDocument+attachMethodRelationship) ⇒ <code>boolean</code>
* [.detachMethodRelationship(didUrl, relationship)](#IotaDocument+detachMethodRelationship) ⇒ <code>boolean</code>
Expand All @@ -2012,7 +2019,7 @@ Deserializes an instance from a JSON object.
* _static_
* [.newWithId(id)](#IotaDocument.newWithId)[<code>IotaDocument</code>](#IotaDocument)
* [.unpackFromOutput(did, aliasOutput, allowEmpty, tokenSupply)](#IotaDocument.unpackFromOutput)[<code>IotaDocument</code>](#IotaDocument)
* [.unpackFromBlock(network, block, protocolResponseJson)](#IotaDocument.unpackFromBlock)[<code>Array.&lt;IotaDocument&gt;</code>](#IotaDocument)
* [.unpackFromBlock(network, block, protocol_parameters)](#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 @@ -2071,6 +2078,7 @@ Sets a custom property in the DID Document.
If the value is set to `null`, the custom property will be removed.

### WARNING

This method can overwrite existing properties like `id` and result in an invalid document.

**Kind**: instance method of [<code>IotaDocument</code>](#IotaDocument)
Expand All @@ -2088,7 +2096,7 @@ Return a set of all [IotaService](#IotaService) in the document.
**Kind**: instance method of [<code>IotaDocument</code>](#IotaDocument)
<a name="IotaDocument+insertService"></a>

### iotaDocument.insertService(service) ⇒ <code>boolean</code>
### iotaDocument.insertService(service)
Add a new [IotaService](#IotaService) to the document.

Returns `true` if the service was added.
Expand All @@ -2101,7 +2109,7 @@ Returns `true` if the service was added.

<a name="IotaDocument+removeService"></a>

### iotaDocument.removeService(did) ⇒ <code>boolean</code>
### iotaDocument.removeService(did) ⇒ [<code>IotaService</code>](#IotaService) \| <code>undefined</code>
Remove a [IotaService](#IotaService) identified by the given [IotaDIDUrl](#IotaDIDUrl) from the document.

Returns `true` if a service was removed.
Expand Down Expand Up @@ -2152,7 +2160,7 @@ Adds a new `method` to the document in the given `scope`.

<a name="IotaDocument+removeMethod"></a>

### iotaDocument.removeMethod(did)
### iotaDocument.removeMethod(did)[<code>IotaVerificationMethod</code>](#IotaVerificationMethod) \| <code>undefined</code>
Removes all references to the specified Verification Method.

**Kind**: instance method of [<code>IotaDocument</code>](#IotaDocument)
Expand Down Expand Up @@ -2438,7 +2446,7 @@ encoded in the `AliasId` alone.

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

### IotaDocument.unpackFromBlock(network, block, protocolResponseJson) ⇒ [<code>Array.&lt;IotaDocument&gt;</code>](#IotaDocument)
### IotaDocument.unpackFromBlock(network, block, protocol_parameters) ⇒ [<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.

Expand All @@ -2452,7 +2460,7 @@ Errors if any Alias Output does not contain a valid or empty DID Document.
| --- | --- |
| network | <code>string</code> |
| block | <code>IBlock</code> |
| protocolResponseJson | <code>string</code> |
| protocol_parameters | <code>INodeInfoProtocol</code> |

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

Expand Down Expand Up @@ -4055,6 +4063,10 @@ This is possible because Ed25519 is birationally equivalent to Curve25519 used b
| --- | --- |
| publicKey | <code>Uint8Array</code> |

<a name="StateMetadataEncoding"></a>

## StateMetadataEncoding
**Kind**: global variable
<a name="StatusCheck"></a>

## StatusCheck
Expand Down Expand Up @@ -4141,10 +4153,6 @@ Return after the first error occurs.

## MethodRelationship
**Kind**: global variable
<a name="StateMetadataEncoding"></a>

## StateMetadataEncoding
**Kind**: global variable
<a name="start"></a>

## start()
Expand Down
2 changes: 1 addition & 1 deletion bindings/wasm/examples/src/0_basic/0_create_did.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export async function createIdentity(): Promise<{
walletAddressBech32: string;
did: IotaDID;
}> {
const client = await Client.new({
const client = new Client({
primaryNode: API_ENDPOINT,
localPow: true,
});
Expand Down
2 changes: 1 addition & 1 deletion bindings/wasm/examples/src/0_basic/1_update_did.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import { API_ENDPOINT, createDid } from "../util";

/** Demonstrates how to update a DID document in an existing Alias Output. */
export async function updateIdentity() {
const client = await Client.new({
const client = new Client({
primaryNode: API_ENDPOINT,
localPow: true,
});
Expand Down
2 changes: 1 addition & 1 deletion bindings/wasm/examples/src/0_basic/2_resolve_did.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { API_ENDPOINT, createDid } from "../util";

/** Demonstrates how to resolve an existing DID in an Alias Output. */
export async function resolveIdentity() {
const client = await Client.new({
const client = new Client({
primaryNode: API_ENDPOINT,
localPow: true,
});
Expand Down
2 changes: 1 addition & 1 deletion bindings/wasm/examples/src/0_basic/3_deactivate_did.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { API_ENDPOINT, createDid } from "../util";

/** Demonstrates how to deactivate a DID in an Alias Output. */
export async function deactivateIdentity() {
const client = await Client.new({
const client = new Client({
primaryNode: API_ENDPOINT,
localPow: true,
});
Expand Down
2 changes: 1 addition & 1 deletion bindings/wasm/examples/src/0_basic/4_delete_did.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ 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 = await Client.new({
const client = new Client({
primaryNode: API_ENDPOINT,
localPow: true,
});
Expand Down
2 changes: 1 addition & 1 deletion bindings/wasm/examples/src/0_basic/5_create_vc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import { API_ENDPOINT, createDid } from "../util";
* This Verifiable Credential can be verified by anyone, allowing Alice to take control of it and share it with whomever they please.
*/
export async function createVC() {
const client = await Client.new({
const client = new Client({
primaryNode: API_ENDPOINT,
localPow: true,
});
Expand Down
2 changes: 1 addition & 1 deletion bindings/wasm/examples/src/0_basic/6_create_vp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export async function createVP() {
// Step 1: Create identities for the issuer and the holder.
// ===========================================================================

const client = await Client.new({
const client = new Client({
primaryNode: API_ENDPOINT,
localPow: true,
});
Expand Down
2 changes: 1 addition & 1 deletion bindings/wasm/examples/src/0_basic/7_revoke_vc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export async function revokeVC() {
// Create a Verifiable Credential.
// ===========================================================================

const client = await Client.new({
const client = new Client({
primaryNode: API_ENDPOINT,
localPow: true,
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export async function didControlsDid() {
// ========================================================

// Create a new Client to interact with the IOTA ledger.
const client = await Client.new({
const client = new Client({
primaryNode: API_ENDPOINT,
localPow: true,
});
Expand Down
2 changes: 1 addition & 1 deletion bindings/wasm/examples/src/1_advanced/1_did_issues_nft.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export async function didIssuesNft() {
// ==============================================

// Create a new Client to interact with the IOTA ledger.
const client = await Client.new({
const client = new Client({
primaryNode: API_ENDPOINT,
localPow: true,
});
Expand Down
2 changes: 1 addition & 1 deletion bindings/wasm/examples/src/1_advanced/2_nft_owns_did.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export async function nftOwnsDid() {
// =============================

// Create a new Client to interact with the IOTA ledger.
const client = await Client.new({
const client = new Client({
primaryNode: API_ENDPOINT,
localPow: true,
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export async function didIssuesTokens() {
// ===========================================

// Create a new Client to interact with the IOTA ledger.
const client = await Client.new({
const client = new Client({
primaryNode: API_ENDPOINT,
localPow: true,
});
Expand Down
2 changes: 1 addition & 1 deletion bindings/wasm/examples/src/1_advanced/4_key_exchange.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export async function keyExchange() {
// ==============================

// Create a new Client to interact with the IOTA ledger.
const client = await Client.new({
const client = new Client({
primaryNode: API_ENDPOINT,
localPow: true,
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export async function customResolution() {
};

// Create a new Client to interact with the IOTA ledger.
const client = await Client.new({
const client = new Client({
primaryNode: API_ENDPOINT,
localPow: true,
});
Expand Down
15 changes: 11 additions & 4 deletions bindings/wasm/lib/iota_identity_client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
IUTXOInput,
TransactionHelper,
} from "@iota/iota.js";
import type { INodeInfoProtocol } from "@iota/types";
import type { Client, INodeInfoWrapper, SecretManager } from "~iota-client-wasm";

/** Provides operations for IOTA DID Documents with Alias Outputs. */
Expand Down Expand Up @@ -47,14 +48,22 @@ export class IotaIdentityClient implements IIotaIdentityClient {
return info.nodeInfo.protocol.rentStructure;
}

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

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

async getProtocolParameters(): Promise<INodeInfoProtocol> {
const protocolParameters: INodeInfoProtocol = await this.client.getProtocolParameters();
return protocolParameters;
}

/** 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 @@ -114,15 +123,13 @@ export class IotaIdentityClient implements IIotaIdentityClient {
*/
async publishDidOutput(secretManager: SecretManager, aliasOutput: IAliasOutput): Promise<IotaDocument> {
const networkHrp = await this.getNetworkHrp();

// Publish block.
const [blockId, block] = await this.client.buildAndPostBlock(secretManager, {
outputs: [aliasOutput],
});
await this.client.retryUntilIncluded(blockId);

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

const protocolParams = await this.client.getProtocolParameters();
// Extract document with computed AliasId.
const documents = IotaDocument.unpackFromBlock(networkHrp, block, protocolParams);
if (documents.length < 1) {
Expand Down
Loading

0 comments on commit c251d90

Please sign in to comment.