diff --git a/.github/workflows/build-and-test.yml b/.github/workflows/build-and-test.yml index c441a9c216..80fa671897 100644 --- a/.github/workflows/build-and-test.yml +++ b/.github/workflows/build-and-test.yml @@ -353,6 +353,10 @@ jobs: run: yarn build working-directory: bindings/wasm + - name: Build Wasm examples + run: yarn build:examples + working-directory: bindings/wasm + - name: Run tests uses: actions-rs/cargo@v1 with: diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml index e7b3b0af35..e9de8e816d 100644 --- a/.github/workflows/examples.yml +++ b/.github/workflows/examples.yml @@ -114,6 +114,10 @@ jobs: run: yarn build working-directory: bindings/wasm + - name: Build Wasm examples + run: yarn build:examples + working-directory: bindings/wasm + - name: Test Wasm examples (node) run: yarn run test:node working-directory: bindings/wasm diff --git a/bindings/wasm/cypress/integration/browser_test.js b/bindings/wasm/cypress/integration/browser_test.js index 6e38f7db65..ea780a4983 100644 --- a/bindings/wasm/cypress/integration/browser_test.js +++ b/bindings/wasm/cypress/integration/browser_test.js @@ -1,14 +1,6 @@ -import { defaultClientConfig, initIdentity } from "../../examples/browser/utils"; -import { createIdentity } from "../../examples/browser/create_did.js"; -import { createVC } from "../../examples/browser/create_vc.js"; -import { manipulateIdentity } from "../../examples/browser/mainpulate_did.js"; -import { resolveIdentity } from "../../examples/browser/resolve.js"; -import { createVP } from "../../examples/browser/create_vp.js"; -import { createDiff } from "../../examples/browser/diff_chain.js"; -import { revoke } from "../../examples/browser/revoke_vc.js"; -import { merkleKey } from "../../examples/browser/merkle_key.js"; -import { createIdentityPrivateTangle } from "../../examples/browser/private_tangle"; -import { resolveHistory } from "../../examples/browser/resolve_history"; +import { + defaultClientConfig, initIdentity, createIdentity, createVC, manipulateIdentity, resolution, createVP, createDiff, revokeVC, merkleKey, createIdentityPrivateTangle, resolveHistory +} from '../../examples/dist/web' // Test that the browser examples do not throw uncaught exceptions twice, including syntax errors etc. describe( @@ -19,7 +11,7 @@ describe( () => { beforeEach(async () => { // The working directory is under __cypress at test runtime, so we need to go up one more level than usual - await initIdentity("../../../web/identity_wasm_bg.wasm", false); + await initIdentity('../../../examples/dist/identity_wasm_bg.wasm'); // NOTE: `cy.wrap(defaultClientConfig()).as('config')` does not always work to make the config available // from the shared context as `this.config` because it has a race condition with initializing the wasm. @@ -29,65 +21,65 @@ describe( it("create identity", async function () { let identityResult; try { - identityResult = await createIdentity(defaultClientConfig(), false); + identityResult = await createIdentity(defaultClientConfig()); } catch (e) { - identityResult = await createIdentity(defaultClientConfig(), false); + identityResult = await createIdentity(defaultClientConfig()); } // example of testing the output, can remove if needed - expect(identityResult).to.have.all.keys("key", "doc", "receipt", "explorerUrl"); + expect(identityResult).to.have.all.keys("key", "doc", "receipt"); }); it("manipulate identity", async function () { try { - await manipulateIdentity(defaultClientConfig(), false); + await manipulateIdentity(defaultClientConfig()); } catch (e) { - await manipulateIdentity(defaultClientConfig(), false); + await manipulateIdentity(defaultClientConfig()); } }); it("resolve identity", async function () { try { - await resolveIdentity(defaultClientConfig(), false, false); + await resolution(defaultClientConfig()); } catch (e) { - await resolveIdentity(defaultClientConfig(), false, false); + await resolution(defaultClientConfig()); } }); it("create verifiable credential", async function () { try { - await createVC(defaultClientConfig(), false); + await createVC(defaultClientConfig()); } catch (e) { - await createVC(defaultClientConfig(), false); + await createVC(defaultClientConfig()); } }); it("revoke verifiable credential", async function () { try { - await revoke(defaultClientConfig(), false); + await revokeVC(defaultClientConfig()); } catch (e) { - await revoke(defaultClientConfig(), false); + await revokeVC(defaultClientConfig()); } }); it("create verifiable presentation", async function () { try { - await createVP(defaultClientConfig(), false); + await createVP(defaultClientConfig()); } catch (e) { - await createVP(defaultClientConfig(), false); + await createVP(defaultClientConfig()); } }); - + it("merkle key", async function () { try { - await merkleKey(defaultClientConfig(), false); + await merkleKey(defaultClientConfig()); } catch (e) { - await merkleKey(defaultClientConfig(), false); + await merkleKey(defaultClientConfig()); } }); it("private tangle", async function () { try { - await createIdentityPrivateTangle(false, false) + await createIdentityPrivateTangle() throw new Error("Did not throw.") } catch (err) { // Example is expected to throw an error because no private Tangle is running @@ -98,17 +90,17 @@ describe( it("diff chain", async function () { try { - await createDiff(defaultClientConfig(), false); + await createDiff(defaultClientConfig()); } catch (e) { - await createDiff(defaultClientConfig(), false); + await createDiff(defaultClientConfig()); } }); it("resolve history", async function () { try { - await resolveHistory(defaultClientConfig(), false); + await resolveHistory(defaultClientConfig()); } catch (e) { - await resolveHistory(defaultClientConfig(), false); + await resolveHistory(defaultClientConfig()); } }); } diff --git a/bindings/wasm/examples/.gitignore b/bindings/wasm/examples/.gitignore index 74e5b1d3a9..331f36626e 100644 --- a/bindings/wasm/examples/.gitignore +++ b/bindings/wasm/examples/.gitignore @@ -1 +1,2 @@ -!* \ No newline at end of file +!* +dist/ diff --git a/bindings/wasm/examples/README.md b/bindings/wasm/examples/README.md index 26a0fc585c..1f6f90b860 100644 --- a/bindings/wasm/examples/README.md +++ b/bindings/wasm/examples/README.md @@ -18,6 +18,12 @@ that can be found in the `config.js` file for node and in `main.js` for the brow Before running the examples, make sure you have [built the bindings](../README.md#Build) for `node.js`. +To build the examples use + +``` +npm run build:examples +``` + You can run each example using ``` @@ -34,16 +40,16 @@ The following examples are currently available: | # | Name | Information | | :-: | :---------------------------------- | :----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -| 1 | [create_did](node/create_did.js) | Generates and publishes a DID Document, the fundamental building block for decentralized identity. | -| 2 | [manipulate_did](node/manipulate_did.js) | Add verification methods and service endpoints to a DID Document and update an already existing DID Document. | -| 3 | [diff_chain](node/diff_chain.js) | Creates a diff chain update for a DID Document and publishes it to the Tangle. | -| 4 | [resolve_history](node/resolve_history.js) | Advanced example that performs multiple diff chain and integration chain updates and demonstrates how to resolve the DID Document history to view these chains. | -| 5 | [create_vc](node/create_vc.js) | Generates and publishes subject and issuer DID Documents, then creates a Verifiable Credential (VC) specifying claims about the subject, and verifies it. | -| 6 | [create_vp](node/create_vp.js) | Create a Verifiable Presentation, the data model for sharing VCs, out of a Verifiable Credential and verifies it. | -| 7 | [revoke_vc](node/revoke_vc.js) | Remove a verification method from the Issuers DID Document, making the Verifiable Credential it signed unable to verify, effectively revoking the VC. | -| 8 | [resolution](node/resolution.js) | Resolves an existing DID to return the latest DID Document. | -| 9 | [merkle_key](node/merkle_key.js) | Adds a MerkleKeyCollection verification method to an Issuers DID Document and signs a Verifiable Credential with the key on index 0. Afterwards the key on index 0 is deactivated, making the Verifiable Credential fail its verification. | -| 10 | [private_tangle](node/private_tangle.js) | Showcases the same procedure as `create_did`, but on a private tangle - a locally running hornet node. | +| 1 | [create_did](src/create_did.js) | Generates and publishes a DID Document, the fundamental building block for decentralized identity. | +| 2 | [manipulate_did](src/manipulate_did.js) | Add verification methods and service endpoints to a DID Document and update an already existing DID Document. | +| 3 | [diff_chain](src/diff_chain.js) | Creates a diff chain update for a DID Document and publishes it to the Tangle. | +| 4 | [resolve_history](src/resolve_history.js) | Advanced example that performs multiple diff chain and integration chain updates and demonstrates how to resolve the DID Document history to view these chains. | +| 5 | [create_vc](src/create_vc.js) | Generates and publishes subject and issuer DID Documents, then creates a Verifiable Credential (VC) specifying claims about the subject, and verifies it. | +| 6 | [create_vp](src/create_vp.js) | Create a Verifiable Presentation, the data model for sharing VCs, out of a Verifiable Credential and verifies it. | +| 7 | [revoke_vc](src/revoke_vc.js) | Remove a verification method from the Issuers DID Document, making the Verifiable Credential it signed unable to verify, effectively revoking the VC. | +| 8 | [resolution](src/resolution.js) | Resolves an existing DID to return the latest DID Document. | +| 9 | [merkle_key](src/merkle_key.js) | Adds a MerkleKeyCollection verification method to an Issuers DID Document and signs a Verifiable Credential with the key on index 0. Afterwards the key on index 0 is deactivated, making the Verifiable Credential fail its verification. | +| 10 | [private_tangle](src/private_tangle.js) | Showcases the same procedure as `create_did`, but on a private tangle - a locally running hornet node. | ### Browser Examples @@ -51,6 +57,11 @@ All the Node.js examples are also available for the browser. Before running the examples, make sure you have [built the bindings](../README.md#Build) for `web`. +To build the examples use +``` +npm run build:examples +``` + You can run the browser examples using ``` diff --git a/bindings/wasm/examples/browser/create_did.js b/bindings/wasm/examples/browser/create_did.js deleted file mode 100644 index 242e155daa..0000000000 --- a/bindings/wasm/examples/browser/create_did.js +++ /dev/null @@ -1,49 +0,0 @@ -import * as identity from "../../web/identity_wasm.js"; -import { - logExplorerUrlToScreen, - logObjectToScreen, - logToScreen, - getExplorerUrl, -} from "./utils.js"; - -/** - This example shows a basic introduction on how to create a basic DID Document and upload it to the Tangle. - A ED25519 Keypair is generated, from which the public key is hashed, becoming the DID. - The keypair becomes part of the DID Document in order to prove a link between the DID and the published DID Document. - That same keypair should be used to sign the original DID Document. - - @param {{defaultNodeURL: string, explorerURL: string, network: Network}} clientConfig - @param {boolean} log log the events to the output window -**/ -export async function createIdentity(clientConfig, log = true) { - if (log) logToScreen("Identity creation started..."); - if (log) - logToScreen("This might take a few seconds to complete proof of work!"); - - // Create a DID Document (an identity). - const { doc, key } = new identity.Document( - identity.KeyType.Ed25519, - clientConfig.network.toString() - ); - - // Sign the DID Document with the generated key. - doc.sign(key); - - // Create a default client configuration from the parent config network. - const config = identity.Config.fromNetwork(clientConfig.network); - - // Create a client instance to publish messages to the Tangle. - const client = identity.Client.fromConfig(config); - - // Publish the Identity to the IOTA Network, this may take a few seconds to complete Proof-of-Work. - const receipt = await client.publishDocument(doc.toJSON()); - doc.messageId = receipt.messageId; - - const explorerUrl = getExplorerUrl(doc, receipt.messageId); - - if (log) logToScreen("Identity creation done!"); - if (log) logObjectToScreen(doc); - if (log) logExplorerUrlToScreen(explorerUrl); - - return { key, doc, receipt, explorerUrl }; -} diff --git a/bindings/wasm/examples/browser/create_vc.js b/bindings/wasm/examples/browser/create_vc.js deleted file mode 100644 index faca5dc606..0000000000 --- a/bindings/wasm/examples/browser/create_vc.js +++ /dev/null @@ -1,67 +0,0 @@ -import * as identity from "../../web/identity_wasm.js"; -import { manipulateIdentity } from "./mainpulate_did.js"; -import { createIdentity } from "./create_did.js"; -import { logObjectToScreen, logToScreen } from "./utils.js"; - -/** - This example shows how to create a Verifiable Credential and validate it. - In this example, alice takes the role of the subject, while we also have an issuer. - The issuer signs a UniversityDegreeCredential type verifiable credential with Alice's name and DID. - This Verifiable Credential can be verified by anyone, allowing Alice to take control of it and share it with whoever they please. - - @param {{defaultNodeURL: string, explorerURL: string, network: Network}} clientConfig - @param {boolean} log log the events to the output window -**/ -export async function createVC(clientConfig, log = true) { - if (log) logToScreen("Verifiable Credential creation started..."); - - // Create a default client configuration from mainNet. - const config = identity.Config.fromNetwork(clientConfig.network); - - // Create a client instance to publish messages to the Tangle. - const client = identity.Client.fromConfig(config); - - // Creates new identities (See "create_did" and "manipulate_did" examples) - const alice = await createIdentity(clientConfig, false); - const issuer = await manipulateIdentity(clientConfig, false); - - if (log) logToScreen("Holder (Alice):"); - if (log) logObjectToScreen(alice); - - if (log) logToScreen("Issuer:"); - if (log) logObjectToScreen(issuer); - - // Prepare a credential subject indicating the degree earned by Alice - let credentialSubject = { - id: alice.doc.id.toString(), - name: "Alice", - degreeName: "Bachelor of Science and Arts", - degreeType: "BachelorDegree", - GPA: "4.0", - }; - - // Create an unsigned `UniversityDegree` credential for Alice - const unsignedVc = identity.VerifiableCredential.extend({ - id: "http://example.edu/credentials/3732", - type: "UniversityDegreeCredential", - issuer: issuer.doc.id.toString(), - credentialSubject, - }); - - // Sign the credential with the Issuer's newKey - const signedVc = issuer.doc.signCredential(unsignedVc, { - method: issuer.doc.id.toString() + "#newKey", - public: issuer.newKey.public, - secret: issuer.newKey.secret, - }); - - if (log) logToScreen("VC:"); - if (log) logObjectToScreen(signedVc); - - // Check if the credential is verifiable. - const checkResult = await client.checkCredential(signedVc.toString()); - - if (log) logToScreen("Check credential result: " + checkResult.verified); - - return { alice, issuer, signedVc, checkResult }; -} diff --git a/bindings/wasm/examples/browser/create_vp.js b/bindings/wasm/examples/browser/create_vp.js deleted file mode 100644 index b26f6f4201..0000000000 --- a/bindings/wasm/examples/browser/create_vp.js +++ /dev/null @@ -1,46 +0,0 @@ -import * as identity from "../../web/identity_wasm.js"; -import { createVC } from "./create_vc.js"; -import { logObjectToScreen, logToScreen } from "./utils.js"; - -/** - This example shows how to create a Verifiable Presentation and validate it. - A Verifiable Presentation is the format in which a (collection of) Verifiable Credential(s) gets shared. - It is signed by the subject, to prove control over the Verifiable Credential with a nonce or timestamp. - - @param {{defaultNodeURL: string, explorerURL: string, network: Network}} clientConfig - @param {boolean} log log the events to the output window -**/ -export async function createVP(clientConfig, log = true) { - if (log) logToScreen("Creating Verifiable Presentation..."); - - // Create a default client configuration from mainNet. - const config = identity.Config.fromNetwork(clientConfig.network); - - // Create a client instance to publish messages to the Tangle. - const client = identity.Client.fromConfig(config); - - // Creates new identities (See "createVC" example) - const { alice, issuer, signedVc } = await createVC(clientConfig, false); - - // Create a Verifiable Presentation from the Credential - signed by Alice's key - // TODO: Sign with a challenge - const unsignedVp = new identity.VerifiablePresentation( - alice.doc, - signedVc.toJSON() - ); - - const signedVp = alice.doc.signPresentation(unsignedVp, { - method: "#key", - secret: alice.key.secret, - }); - - if (log) logToScreen("signed VP:"); - if (log) logObjectToScreen(signedVp); - - // Check the validation status of the Verifiable Presentation - const checkResult = await client.checkPresentation(signedVp.toString()); - - if (log) logToScreen(`VP verification result: ${checkResult.verified}`); - - return { alice, issuer, signedVc, signedVp, checkResult }; -} diff --git a/bindings/wasm/examples/browser/diff_chain.js b/bindings/wasm/examples/browser/diff_chain.js deleted file mode 100644 index 571cbafa03..0000000000 --- a/bindings/wasm/examples/browser/diff_chain.js +++ /dev/null @@ -1,49 +0,0 @@ -import {getExplorerUrl, logExplorerUrlToScreen, logObjectToScreen, logToScreen} from "./utils.js"; -import * as identity from "../../web/identity_wasm.js"; -import {createIdentity} from "./create_did.js"; - -/** - This example is a basic introduction to creating a diff message and publishing it to the tangle. - 1. A did document is created and published with one service. - 2. The document is cloned and another service is added. - 3. The difference between the two documents is created and published as a diff message. - 4. The final DID will contain both services. - - @param {{defaultNodeURL: string, explorerURL: string, network: Network}} clientConfig - @param {boolean} log log the events to the output window - **/ -export async function createDiff(clientConfig, log = true) { - if (log) logToScreen("Creating diff chain ..."); - - // Create a default client configuration from network. - const config = identity.Config.fromNetwork(clientConfig.network); - - // Create a client instance to publish messages to the Tangle. - const client = identity.Client.fromConfig(config); - - // Create a new identity (see "create_did.js" example). - const {key, doc, receipt} = await createIdentity(clientConfig, false); - - // Clone the Document - const updatedDoc = identity.Document.fromJSON(doc.toJSON()); - - // Add a Service - let serviceJSON = { - id: doc.id + "#new-linked-domain", - type: "LinkedDomains", - serviceEndpoint: "https://identity.iota.org", - }; - updatedDoc.insertService(identity.Service.fromJSON(serviceJSON)); - - // Create diff - const diff = doc.diff(updatedDoc, receipt.messageId, key); - - if (log) logToScreen("Diff:"); - if (log) logObjectToScreen(diff); - - // Publish the diff to the Tangle - const diffReceipt = await client.publishDiff(receipt.messageId, diff); - if (log) logExplorerUrlToScreen(getExplorerUrl(doc, diffReceipt.messageId)); - - return {updatedDoc, key, diffMessageId: diffReceipt.messageId}; -} diff --git a/bindings/wasm/examples/browser/main.js b/bindings/wasm/examples/browser/main.js deleted file mode 100644 index 39af06260c..0000000000 --- a/bindings/wasm/examples/browser/main.js +++ /dev/null @@ -1,64 +0,0 @@ -import { initIdentity, defaultClientConfig } from "./utils.js"; -import { createIdentity } from "./create_did.js"; -import { createVC } from "./create_vc.js"; -import { manipulateIdentity } from "./mainpulate_did.js"; -import { resolveIdentity } from "./resolve.js"; -import { createVP } from "./create_vp.js"; -import { revoke } from "./revoke_vc.js"; -import { merkleKey } from "./merkle_key.js"; -import { createIdentityPrivateTangle } from "./private_tangle.js"; -import { createDiff } from "./diff_chain.js"; -import { resolveHistory } from "./resolve_history.js"; - -await initIdentity(); -const clientConfig = defaultClientConfig(); - -//handle create identity on click event -document - .querySelector("#create-identity-btn") - .addEventListener("click", () => createIdentity(clientConfig)); - -//handle resolve DID on click event -document - .querySelector("#resolve-did-btn") - .addEventListener("click", () => resolveIdentity(clientConfig)); - -//handle manipulate DID on click event -document - .querySelector("#manipulate_did_btn") - .addEventListener("click", () => manipulateIdentity(clientConfig)); - -//handle create VC on click event -document - .querySelector("#create_vc_btn") - .addEventListener("click", () => createVC(clientConfig)); - -//handle create VP on click event -document - .querySelector("#create_vp_btn") - .addEventListener("click", () => createVP(clientConfig)); - -//handle revoke VC on click event -document - .querySelector("#revoke_vc_btn") - .addEventListener("click", () => revoke(clientConfig)); - -//handle merkle key on click event -document - .querySelector("#merkle_key_btn") - .addEventListener("click", () => merkleKey(clientConfig)); - -//handle private tangle DID creation on click event -document - .querySelector("#private_tangle_btn") - .addEventListener("click", () => createIdentityPrivateTangle()); - -//handle diff chain on click event -document - .querySelector("#diff_chain_btn") - .addEventListener("click", () => createDiff(clientConfig)); - -//handle resolve history on click event -document -.querySelector("#did_history_btn") -.addEventListener("click", () => resolveHistory(clientConfig)); diff --git a/bindings/wasm/examples/browser/mainpulate_did.js b/bindings/wasm/examples/browser/mainpulate_did.js deleted file mode 100644 index 96e2c700aa..0000000000 --- a/bindings/wasm/examples/browser/mainpulate_did.js +++ /dev/null @@ -1,70 +0,0 @@ -import {getExplorerUrl, logExplorerUrlToScreen, logObjectToScreen, logToScreen} from "./utils.js"; -import * as identity from "../../web/identity_wasm.js"; -import {createIdentity} from "./create_did.js"; - -/** - This example shows how to add more to an existing DID Document. - The two main things to add are Verification Methods and Services. - A verification method adds public keys, which can be used to digitally sign things as an identity. - The services provide metadata around the identity via URIs. These can be URLs, but can also be emails or IOTA indices. - An important detail to note is the previousMessageId. This is an important field as it links the new DID Document to the old DID Document, creating a chain. - Without setting this value, the new DID Document won't get used during resolution of the DID! - - @param {{defaultNodeURL: string, explorerURL: string, network: Network}} clientConfig - @param {boolean} log log the events to the output window - **/ -export async function manipulateIdentity(clientConfig, log = true) { - // Create a default client configuration from the parent config network. - const config = identity.Config.fromNetwork(clientConfig.network); - - // Create a client instance to publish messages to the Tangle. - const client = identity.Client.fromConfig(config); - - // Creates a new identity (see "create_did" example) - if (log) logToScreen("Creating identity..."); - let {key, doc, receipt} = await createIdentity(clientConfig, false); - if (log) logObjectToScreen(doc); - - if (log) logToScreen("Manipulating identity..."); - - // Add a new VerificationMethod with a new KeyPair - const newKey = new identity.KeyPair(identity.KeyType.Ed25519); - const method = identity.VerificationMethod.fromDID(doc.id, newKey, "newKey"); - doc.insertMethod(method, "VerificationMethod"); - - // Add a new Service - const serviceJSON = { - id: doc.id + "#linked-domain", - type: "LinkedDomains", - serviceEndpoint: "https://iota.org", - }; - doc.insertService(identity.Service.fromJSON(serviceJSON)); - - /* - Add the messageId of the previous message in the chain. - This is REQUIRED in order for the messages to form a chain. - Skipping / forgetting this will render the publication useless. - */ - doc.previousMessageId = receipt.messageId; - doc.updated = identity.Timestamp.nowUTC(); - - // Sign the DID Document with the appropriate key. - doc.sign(key); - - // Publish the Identity to the IOTA Network, this may take a few seconds to complete Proof-of-Work. - const updateReceipt = await client.publishDocument(doc.toJSON()); - - if (log) logObjectToScreen(doc); - - const explorerUrl = getExplorerUrl(doc, updateReceipt.messageId); - if (log) logExplorerUrlToScreen(explorerUrl); - - return { - key, - newKey, - doc, - originalMessageId: receipt.messageId, - updatedMessageId: updateReceipt.messageId, - explorerUrl, - }; -} diff --git a/bindings/wasm/examples/browser/merkle_key.js b/bindings/wasm/examples/browser/merkle_key.js deleted file mode 100644 index af2a6515e7..0000000000 --- a/bindings/wasm/examples/browser/merkle_key.js +++ /dev/null @@ -1,98 +0,0 @@ -import * as identity from "../../web/identity_wasm.js"; -import {createIdentity} from "./create_did.js"; -import {getExplorerUrl, logExplorerUrlToScreen, logObjectToScreen, logToScreen,} from "./utils.js"; - -/** - This example shows how to sign/revoke verifiable credentials on scale. - Instead of revoking the entire verification method, a single key can be revoked from a MerkleKeyCollection. - This MerkleKeyCollection can be created as a collection of a power of 2 amount of keys. - Every key should be used once by the issuer for signing a verifiable credential. - When the verifiable credential must be revoked, the issuer revokes the index of the revoked key. - - @param {{defaultNodeURL: string, explorerURL: string, network: Network}} clientConfig - @param {boolean} log log the events to the output window - **/ -export async function merkleKey(clientConfig, log = true) { - // Create a default client configuration from the parent config network. - const config = identity.Config.fromNetwork(clientConfig.network); - - // Create a client instance to publish messages to the Tangle. - const client = identity.Client.fromConfig(config); - - if (log) logToScreen("Creating identities.."); - - //Creates new identities (See "create_did" example) - const alice = await createIdentity(clientConfig, false); - const issuer = await createIdentity(clientConfig, false); - - if (log) logObjectToScreen(alice.doc); - if (log) logObjectToScreen(issuer.doc); - - //Add a Merkle Key Collection Verification Method with 8 keys (Must be a power of 2) - const keys = new identity.KeyCollection(identity.KeyType.Ed25519, 8); - const method = identity.VerificationMethod.createMerkleKey( - identity.Digest.Sha256, - issuer.doc.id, - keys, - "key-collection" - ); - - // Add to the DID Document as a general-purpose verification method - issuer.doc.insertMethod(method, "VerificationMethod"); - issuer.doc.previousMessageId = issuer.receipt.messageId; - issuer.doc.updated = identity.Timestamp.nowUTC(); - issuer.doc.sign(issuer.key); - - //Publish the Identity to the IOTA Network and log the results, this may take a few seconds to complete Proof-of-Work. - const receipt = await client.publishDocument(issuer.doc.toJSON()); - - //Log the resulting Identity update - const explorerUrl = getExplorerUrl(issuer.doc, receipt.messageId); - if (log) logExplorerUrlToScreen(explorerUrl); - - // Prepare a credential subject indicating the degree earned by Alice - let credentialSubject = { - id: alice.doc.id.toString(), - name: "Alice", - degreeName: "Bachelor of Science and Arts", - degreeType: "BachelorDegree", - GPA: "4.0", - }; - - // Create an unsigned `UniversityDegree` credential for Alice - const unsignedVc = identity.VerifiableCredential.extend({ - id: "http://example.edu/credentials/3732", - type: "UniversityDegreeCredential", - issuer: issuer.doc.id.toString(), - credentialSubject, - }); - - // Sign the credential with Issuer's Merkle Key Collection method, with key index 0 - const signedVc = issuer.doc.signCredential(unsignedVc, { - method: method.id.toString(), - public: keys.public(0), - secret: keys.secret(0), - proof: keys.merkleProof(identity.Digest.Sha256, 0), - }); - - // Check the verifiable credential is valid - const result = await client.checkCredential(signedVc.toString()); - if (log) logToScreen(`VC verification result: ${result.verified}`); - if (!result.verified) throw new Error("VC not valid"); - - // The Issuer would like to revoke the credential (and therefore revokes key 0) - issuer.doc.revokeMerkleKey(method.id.toString(), 0); - issuer.doc.previousMessageId = receipt.messageId; - issuer.doc.updated = identity.Timestamp.nowUTC(); - issuer.doc.sign(issuer.key); - const revokeReceipt = await client.publishDocument(issuer.doc.toJSON()); - - // Log the resulting Identity update - const revokeExplorerUrl = getExplorerUrl(issuer.doc, revokeReceipt.messageId); - if (log) logExplorerUrlToScreen(revokeExplorerUrl); - - // Check the verifiable credential is revoked - const newResult = await client.checkCredential(signedVc.toString()); - if (log) logToScreen(`VC verification result (false = revoked): ${newResult.verified}`); - if (newResult.verified) throw new Error("VC not revoked"); -} diff --git a/bindings/wasm/examples/browser/private_tangle.js b/bindings/wasm/examples/browser/private_tangle.js deleted file mode 100644 index 629103d79e..0000000000 --- a/bindings/wasm/examples/browser/private_tangle.js +++ /dev/null @@ -1,64 +0,0 @@ -// Copyright 2020-2021 IOTA Stiftung -// SPDX-License-Identifier: Apache-2.0 - -import { Client, Config, Document, KeyType, Network } from "../../web/identity_wasm.js"; -import { - logObjectToScreen, - logToScreen, -} from "./utils.js"; - -/** - This example shows how a DID document can be created on a private tangle. - It can be run together with a local hornet node. - Refer to https://github.com/iotaledger/one-click-tangle/tree/chrysalis/hornet-private-net - for setup instructions. -**/ -export async function createIdentityPrivateTangle(inBrowser = true, log = true) { - if (log) logToScreen("Identity creation started..."); - if (log) logToScreen("This might take a few seconds to complete proof of work!"); - - let restURL - let networkName - - if (inBrowser) { - // Get the required parameters from the input fields - restURL = document.querySelector("#create-private-rest-url").value; - networkName = document.querySelector("#create-private-network-name").value; - } else { - restURL = "http://127.0.0.1:14265/"; - networkName = "custom"; - } - - // This is an arbitrarily defined network name - const network = Network.try_from_name(networkName); - - // Create a DID Document (an identity). - const { doc, key } = new Document(KeyType.Ed25519, network.toString()); - - // Sign the DID Document with the generated key. - doc.sign(key); - - // Create a client configuration and set the custom network. - const config = new Config(); - config.setNetwork(network); - - // This URL should point to the REST API of a node. - config.setNode(restURL); - - // Create a client instance from the configuration to publish messages to the Tangle. - const client = Client.fromConfig(config); - - // Publish the Identity to the IOTA Network, this may take a few seconds to complete Proof-of-Work. - const receipt = await client.publishDocument(doc.toJSON()); - - if (log) logToScreen("Identity creation done!"); - - // Make sure the DID can be resolved on the private tangle - const resolved = await client.resolve(doc.id.toString()); - - if (log) logToScreen("Resolved DID document:"); - if (log) logObjectToScreen(resolved); - - // Return the results. - return { key, doc, receipt }; -} diff --git a/bindings/wasm/examples/browser/resolve.js b/bindings/wasm/examples/browser/resolve.js deleted file mode 100644 index 1b9bd509ae..0000000000 --- a/bindings/wasm/examples/browser/resolve.js +++ /dev/null @@ -1,32 +0,0 @@ -import * as identity from "../../web/identity_wasm.js"; -import {logObjectToScreen} from "./utils.js"; -import {createIdentity} from "./create_did.js"; - -/** - A short example to show how to resolve a DID. This returns the latest DID Document. - - @param {{defaultNodeURL: string, explorerURL: string, network: Network}} clientConfig - @param {boolean} inBrowser whether or not the function is running in the example browser - @param {boolean} log log the events to the output window - **/ -export async function resolveIdentity(clientConfig, inBrowser = true, log = true) { - let inputDid; - if (inBrowser) { - // Get the DID string from the input field - inputDid = document.querySelector("#resolve-did-input").value; - } else { - // Generate a new DID to resolve - const alice = await createIdentity(clientConfig, false); - inputDid = alice.doc.id.toString(); - } - - // Create a default client configuration from network. - const config = identity.Config.fromNetwork(clientConfig.network); - - // Create a client instance to publish messages to the Tangle. - const client = identity.Client.fromConfig(config); - - const res = await client.resolve(inputDid); - if (log) logObjectToScreen(res); - return res; -} diff --git a/bindings/wasm/examples/browser/resolve_history.js b/bindings/wasm/examples/browser/resolve_history.js deleted file mode 100644 index 9053f2fcf0..0000000000 --- a/bindings/wasm/examples/browser/resolve_history.js +++ /dev/null @@ -1,201 +0,0 @@ -import {getExplorerUrl, logExplorerUrlToScreen, logObjectToScreen, logToScreen} from "./utils.js"; -import {createIdentity} from "./create_did.js"; - -import * as identity from "../../web/identity_wasm.js"; - -/** - Advanced example that performs multiple diff chain and integration chain updates and - demonstrates how to resolve the DID Document history to view these chains. - - @param {{defaultNodeURL: string, explorerURL: string, network: Network}} clientConfig - @param {boolean} log log the events to the output window - **/ -export async function resolveHistory(clientConfig, log = true) { - if (log) logToScreen("Resolve History Example"); - - // Create a default client configuration from network. - const config = identity.Config.fromNetwork(clientConfig.network); - - // Create a client instance to publish messages to the Tangle. - const client = identity.Client.fromConfig(config); - - // =========================================================================== - // DID Creation - // =========================================================================== - - // Create a new identity (see "create_did.js" example). - const {doc, key, receipt: originalReceipt} = await createIdentity(clientConfig, false); - - // =========================================================================== - // Integration Chain Spam - // =========================================================================== - - // Publish several spam messages to the same index as the integration chain on the Tangle. - // These are not valid DID documents and are simply to demonstrate that invalid messages can be - // included in the history, potentially for debugging invalid DID documents. - const intIndex = doc.integrationIndex(); - await client.publishJSON(intIndex, {"intSpam:1": true}); - await client.publishJSON(intIndex, {"intSpam:2": true}); - await client.publishJSON(intIndex, {"intSpam:3": true}); - await client.publishJSON(intIndex, {"intSpam:4": true}); - await client.publishJSON(intIndex, {"intSpam:5": true}); - - // =========================================================================== - // Integration Chain Update 1 - // =========================================================================== - - // Prepare an integration chain update, which writes the full updated DID document to the Tangle. - const intDoc1 = identity.Document.fromJSON(doc.toJSON()); // clone the Document - - // Add a new VerificationMethod with a new KeyPair, with the tag "keys-1" - const keys1 = new identity.KeyPair(identity.KeyType.Ed25519); - const method1 = identity.VerificationMethod.fromDID(intDoc1.id, keys1, "keys-1"); - intDoc1.insertMethod(method1, "VerificationMethod"); - - // Add the `messageId` of the previous message in the chain. - // This is REQUIRED in order for the messages to form a chain. - // Skipping / forgetting this will render the publication useless. - intDoc1.previousMessageId = originalReceipt.messageId; - intDoc1.updated = identity.Timestamp.nowUTC(); - - // Sign the DID Document with the original private key. - intDoc1.sign(key); - - // Publish the updated DID Document to the Tangle, updating the integration chain. - // This may take a few seconds to complete proof-of-work. - const intReceipt1 = await client.publishDocument(intDoc1.toJSON()); - - // Log the results. - if (log) logToScreen("Int. Chain Update (1):"); - if (log) logExplorerUrlToScreen(getExplorerUrl(doc, intReceipt1.messageId)); - - // =========================================================================== - // Diff Chain Update 1 - // =========================================================================== - - // Prepare a diff chain DID Document update. - const diffDoc1 = identity.Document.fromJSON(intDoc1.toJSON()); // clone the Document - - // Add a new Service with the tag "linked-domain-1" - let serviceJSON1 = { - id: diffDoc1.id + "#linked-domain-1", - type: "LinkedDomains", - serviceEndpoint: "https://iota.org", - }; - diffDoc1.insertService(identity.Service.fromJSON(serviceJSON1)); - diffDoc1.updated = identity.Timestamp.nowUTC(); - - // Create a signed diff update. - // - // This is the first diff so the `previousMessageId` property is - // set to the last DID document published on the integration chain. - const diff1 = intDoc1.diff(diffDoc1, intReceipt1.messageId, key); - - // Publish the diff to the Tangle, starting a diff chain. - const diffReceipt1 = await client.publishDiff(intReceipt1.messageId, diff1); - if (log) logToScreen("Diff Chain Update (1):"); - if (log) logExplorerUrlToScreen(getExplorerUrl(doc, diffReceipt1.messageId)); - - // =========================================================================== - // Diff Chain Update 2 - // =========================================================================== - - // Prepare another diff chain update. - const diffDoc2 = identity.Document.fromJSON(diffDoc1.toJSON()); - - // Add a second Service with the tag "linked-domain-2" - let serviceJSON2 = { - id: diffDoc2.id + "#linked-domain-2", - type: "LinkedDomains", - serviceEndpoint: "https://example.com", - }; - diffDoc2.insertService(identity.Service.fromJSON(serviceJSON2)); - diffDoc2.updated = identity.Timestamp.nowUTC(); - - // This is the second diff therefore its `previousMessageId` property is - // set to the first published diff to extend the diff chain. - const diff2 = diffDoc1.diff(diffDoc2, diffReceipt1.messageId, key); - - // Publish the diff to the Tangle. - // Note that we still use the `messageId` from the last integration chain message here to link - // the current diff chain to that point on the integration chain. - const diffReceipt2 = await client.publishDiff(intReceipt1.messageId, diff2); - if (log) logToScreen("Diff Chain Update (2):"); - if (log) logExplorerUrlToScreen(getExplorerUrl(doc, diffReceipt2.messageId)); - - // =========================================================================== - // Diff Chain Spam - // =========================================================================== - - // Publish several spam messages to the same index as the new diff chain on the Tangle. - // These are not valid DID diffs and are simply to demonstrate that invalid messages - // can be included in the history for debugging invalid DID diffs. - let diffIndex = identity.Document.diffIndex(intReceipt1.messageId); - await client.publishJSON(diffIndex, {"diffSpam:1": true}); - await client.publishJSON(diffIndex, {"diffSpam:2": true}); - await client.publishJSON(diffIndex, {"diffSpam:3": true}); - - // =========================================================================== - // DID History 1 - // =========================================================================== - - // Retrieve the message history of the DID. - const history1 = await client.resolveHistory(doc.id.toString()); - - // The history shows two documents in the integration chain, and two diffs in the diff chain. - if (log) logToScreen("History (1):") - if (log) logObjectToScreen(history1); - - // =========================================================================== - // Integration Chain Update 2 - // =========================================================================== - - // Publish a second integration chain update - let intDoc2 = identity.Document.fromJSON(diffDoc2.toJSON()); - - // Remove the #keys-1 VerificationMethod - intDoc2.removeMethod(identity.DID.parse(intDoc2.id.toString() + "#keys-1")); - - // Remove the #linked-domain-1 Service - intDoc2.removeService(identity.DID.parse(intDoc2.id.toString() + "#linked-domain-1")); - - // Add a VerificationMethod with a new KeyPair, called "keys-2" - const keys2 = new identity.KeyPair(identity.KeyType.Ed25519); - const method2 = identity.VerificationMethod.fromDID(intDoc1.id, keys2, "keys-2"); - intDoc2.insertMethod(method2, "VerificationMethod"); - - // Note: the `previous_message_id` points to the `message_id` of the last integration chain - // update, NOT the last diff chain message. - intDoc2.previousMessageId = intReceipt1.messageId; - intDoc2.updated = identity.Timestamp.nowUTC(); - intDoc2.sign(key); - const intReceipt2 = await client.publishDocument(intDoc2.toJSON()); - - // Log the results. - if (log) logToScreen("Int. Chain Update (2):") - if (log) logExplorerUrlToScreen(getExplorerUrl(doc, intReceipt2.messageId)); - - // =========================================================================== - // DID History 2 - // =========================================================================== - - // Retrieve the updated message history of the DID. - const history2 = await client.resolveHistory(doc.id.toString()); - - // The history now shows three documents in the integration chain, and no diffs in the diff chain. - // This is because each integration chain document has its own diff chain but only the last one - // is used during resolution. - if (log) logToScreen("History (2):") - if (log) logObjectToScreen(history2); - - // =========================================================================== - // Diff Chain History - // =========================================================================== - - // Fetch the diff chain of the previous integration chain message. - // Old diff chains can be retrieved but they no longer affect DID resolution. - let previousIntegrationDocument = history2.integrationChainData()[1]; - let previousDiffHistory = await client.resolveDiffHistory(previousIntegrationDocument); - if (log) logToScreen("Previous Diff History:") - if (log) logObjectToScreen(previousDiffHistory); -} diff --git a/bindings/wasm/examples/browser/revoke_vc.js b/bindings/wasm/examples/browser/revoke_vc.js deleted file mode 100644 index 2657b2fba9..0000000000 --- a/bindings/wasm/examples/browser/revoke_vc.js +++ /dev/null @@ -1,48 +0,0 @@ -import * as identity from "../../web/identity_wasm.js"; -import {createVC} from "./create_vc.js"; -import {getExplorerUrl, logExplorerUrlToScreen, logToScreen,} from "./utils.js"; - -/** - This example shows how to revoke a verifiable credential. - The Verifiable Credential is revoked by actually removing a verification method (public key) from the DID Document of the Issuer. - As such, the Verifiable Credential can no longer be validated. - This would invalidate every Verifiable Credential signed with the same public key, therefore the issuer would have to sign every VC with a different key. - Have a look at the Merkle Key example on how to do that practically. - - Note that this example uses the "main" network, if you are writing code against the test network then most function - calls will need to include information about the network, since this is not automatically inferred from the - arguments in all cases currently. - - We recommend that you ALWAYS using a CLIENT_CONFIG parameter that you define when calling any functions that take a - ClientConfig object. This will ensure that all the API calls use a consistent node and network. - - @param {{defaultNodeURL: string, explorerURL: string, network: Network}} clientConfig - @param {boolean} log log the events to the output window - **/ -export async function revoke(clientConfig, log = true) { - // Create a default client configuration from the parent config network. - const config = identity.Config.fromNetwork(clientConfig.network); - - // Create a client instance to publish messages to the Tangle. - const client = identity.Client.fromConfig(config); - - // Creates new identities and a VC (see "create_did" and "manipulate_did" examples) - const {alice, issuer, signedVc} = await createVC(clientConfig, log); - - if (log) logToScreen("Revoking VC..."); - - // Remove the public key that signed the VC - effectively revoking the VC as it will no longer be able to verify - issuer.doc.removeMethod(identity.DID.parse(issuer.doc.id.toString() + "#newKey")); - issuer.doc.previousMessageId = issuer.updatedMessageId; - issuer.doc.updated = identity.Timestamp.nowUTC(); - issuer.doc.sign(issuer.key); - // This is an integration chain update, so we publish the full document. - const {messageId} = await client.publishDocument(issuer.doc.toJSON()); - - // Log the resulting Identity update - if (log) logExplorerUrlToScreen(getExplorerUrl(issuer.doc, messageId)); - - // Check the verifiable credential - const result = await client.checkCredential(signedVc.toString()); - if (log) logToScreen(`VC verification result: ${result.verified}`); -} diff --git a/bindings/wasm/examples/browser/utils.js b/bindings/wasm/examples/browser/utils.js deleted file mode 100644 index 06efd62133..0000000000 --- a/bindings/wasm/examples/browser/utils.js +++ /dev/null @@ -1,72 +0,0 @@ -import * as identity from "../../web/identity_wasm.js"; - -/** - * Loads the identity wasm library. - * - * @returns {Promise} - */ -export async function initIdentity(path = "../../web/identity_wasm_bg.wasm", log = true) { - if(log) logToScreen("Initialization started..."); - try { - await identity.init(path); - if(log) logToScreen("Initialization success!"); - } catch (err) { - if(log) logToScreen(err); - } -} - -/** - * Returns the default client configuration to connect to the IOTA mainnet. - * - * N.B. initIdentity() must be called prior to this function. - * - * @returns {{defaultNodeURL: string, explorerURL: string, network: Network}} - */ -export function defaultClientConfig() { - const mainNet = identity.Network.mainnet(); - return { - network: mainNet, - defaultNodeURL: mainNet.defaultNodeURL, - explorerURL: mainNet.explorerURL, - } -} - -/** - * Returns a URL to view a message published to the Tangle, depending on the network: - * https://explorer.iota.org//transaction/ - * - * @param doc - * @param messageId - * @returns {string} - */ -export function getExplorerUrl(doc, messageId) { - return doc.id.network.messageURL(messageId); -} - -/** - * logs a string to the output window - * - * @param {string} message - */ -export function logToScreen(message) { - document.querySelector("#content").innerHTML = - document.querySelector("#content").innerHTML + - message + - "
-------------------------------------
"; -} - -/** - * - * @param {string} url - */ -export function logExplorerUrlToScreen(url) { - logToScreen(`Explorer URL: ${url} `); -} - -/** - * - * @param {object} obj - */ -export function logObjectToScreen(obj) { - logToScreen("
" + JSON.stringify(obj, null, 4) + "
"); -} diff --git a/bindings/wasm/examples/node/config.js b/bindings/wasm/examples/src/config.js similarity index 77% rename from bindings/wasm/examples/node/config.js rename to bindings/wasm/examples/src/config.js index 34dce9a697..37a935f94c 100644 --- a/bindings/wasm/examples/node/config.js +++ b/bindings/wasm/examples/src/config.js @@ -1,7 +1,7 @@ // Copyright 2020-2021 IOTA Stiftung // SPDX-License-Identifier: Apache-2.0 -const { Network } = require('../../node/identity_wasm') +import { Network } from '@iota/identity-wasm'; const MAINNET = Network.mainnet(); @@ -12,4 +12,4 @@ const CLIENT_CONFIG = { explorerURL: MAINNET.explorerURL, } -exports.CLIENT_CONFIG = CLIENT_CONFIG; +export {CLIENT_CONFIG}; diff --git a/bindings/wasm/examples/node/create_did.js b/bindings/wasm/examples/src/create_did.js similarity index 89% rename from bindings/wasm/examples/node/create_did.js rename to bindings/wasm/examples/src/create_did.js index c2ed0e9a40..20405b322a 100644 --- a/bindings/wasm/examples/node/create_did.js +++ b/bindings/wasm/examples/src/create_did.js @@ -1,8 +1,8 @@ // Copyright 2020-2021 IOTA Stiftung // SPDX-License-Identifier: Apache-2.0 -const { Client, Config, Document, KeyType } = require('../../node/identity_wasm') -const { logExplorerUrl } = require('./utils') +import { Client, Config, Document, KeyType } from '@iota/identity-wasm'; +import { logExplorerUrl } from './utils'; /** This example shows a basic introduction on how to create a basic DID Document and upload it to the Tangle. @@ -13,6 +13,7 @@ const { logExplorerUrl } = require('./utils') @param {{defaultNodeURL: string, explorerURL: string, network: Network}} clientConfig **/ async function createIdentity(clientConfig) { + // Create a DID Document (an identity). const { doc, key } = new Document(KeyType.Ed25519, clientConfig.network.toString()); @@ -36,4 +37,4 @@ async function createIdentity(clientConfig) { return {key, doc, receipt}; } -exports.createIdentity = createIdentity; +export {createIdentity}; \ No newline at end of file diff --git a/bindings/wasm/examples/node/create_vc.js b/bindings/wasm/examples/src/create_vc.js similarity index 90% rename from bindings/wasm/examples/node/create_vc.js rename to bindings/wasm/examples/src/create_vc.js index 5e24c1668f..5769ea7fa5 100644 --- a/bindings/wasm/examples/node/create_vc.js +++ b/bindings/wasm/examples/src/create_vc.js @@ -1,9 +1,9 @@ // Copyright 2020-2021 IOTA Stiftung // SPDX-License-Identifier: Apache-2.0 -const {Client, Config, VerifiableCredential} = require('../../node/identity_wasm') -const {createIdentity} = require('./create_did'); -const {manipulateIdentity} = require('./manipulate_did'); +import {Client, Config, VerifiableCredential} from '@iota/identity-wasm'; +import {createIdentity} from './create_did'; +import {manipulateIdentity} from './manipulate_did'; /** This example shows how to create a Verifiable Credential and validate it. @@ -56,4 +56,4 @@ async function createVC(clientConfig) { return {alice, issuer, signedVc}; } -exports.createVC = createVC; +export {createVC}; diff --git a/bindings/wasm/examples/node/create_vp.js b/bindings/wasm/examples/src/create_vp.js similarity index 89% rename from bindings/wasm/examples/node/create_vp.js rename to bindings/wasm/examples/src/create_vp.js index 7c9bdb25d1..3b815523c4 100644 --- a/bindings/wasm/examples/node/create_vp.js +++ b/bindings/wasm/examples/src/create_vp.js @@ -1,8 +1,8 @@ // Copyright 2020-2021 IOTA Stiftung // SPDX-License-Identifier: Apache-2.0 -const { Client, Config, VerifiablePresentation } = require('../../node/identity_wasm') -const { createVC } = require('./create_vc'); +import { Client, Config, VerifiablePresentation } from '@iota/identity-wasm'; +import { createVC } from './create_vc'; /** This example shows how to create a Verifiable Presentation and validate it. @@ -36,4 +36,4 @@ async function createVP(clientConfig) { console.log(`VP verification result: ${result.verified}`); } -exports.createVP = createVP; +export {createVP}; diff --git a/bindings/wasm/examples/node/diff_chain.js b/bindings/wasm/examples/src/diff_chain.js similarity index 89% rename from bindings/wasm/examples/node/diff_chain.js rename to bindings/wasm/examples/src/diff_chain.js index 314a78ad2d..b73d1d6d6c 100644 --- a/bindings/wasm/examples/node/diff_chain.js +++ b/bindings/wasm/examples/src/diff_chain.js @@ -1,9 +1,9 @@ // Copyright 2020-2021 IOTA Stiftung // SPDX-License-Identifier: Apache-2.0 -const {logExplorerUrl} = require("./utils"); -const {Client, Config, Document, Service} = require("../../node/identity_wasm"); -const {createIdentity} = require("./create_did"); +import {Client, Config, Document, Service} from '@iota/identity-wasm'; +import {createIdentity} from "./create_did"; +import {logExplorerUrl} from "./utils"; /** This example is a basic introduction to creating a diff message and publishing it to the tangle. @@ -48,4 +48,4 @@ async function createDiff(clientConfig) { return {updatedDoc, key, diffMessageId: diffReceipt.messageId}; } -exports.createDiff = createDiff; +export {createDiff}; diff --git a/bindings/wasm/examples/browser/index.html b/bindings/wasm/examples/src/index.html similarity index 96% rename from bindings/wasm/examples/browser/index.html rename to bindings/wasm/examples/src/index.html index 87d110d2f9..d63620ad1b 100644 --- a/bindings/wasm/examples/browser/index.html +++ b/bindings/wasm/examples/src/index.html @@ -20,7 +20,7 @@ } - +