From 6e8afe5f90651c4b3b5d8f56d563b069050af8dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eike=20Ha=C3=9F?= Date: Wed, 25 Aug 2021 12:51:37 +0200 Subject: [PATCH 01/23] added build step for examples --- bindings/wasm/examples/.gitignore | 3 +- bindings/wasm/examples/src/config.js | 15 + bindings/wasm/examples/src/create_did.js | 40 +++ bindings/wasm/examples/src/create_vc.js | 59 ++++ bindings/wasm/examples/src/create_vp.js | 39 +++ bindings/wasm/examples/src/diff_chain.js | 51 +++ bindings/wasm/examples/src/manipulate_did.js | 67 ++++ bindings/wasm/examples/src/merkle_key.js | 96 ++++++ bindings/wasm/examples/src/node.js | 71 ++++ bindings/wasm/examples/src/private_tangle.js | 42 +++ bindings/wasm/examples/src/resolution.js | 26 ++ bindings/wasm/examples/src/resolve_history.js | 204 ++++++++++++ bindings/wasm/examples/src/revoke_vc.js | 50 +++ bindings/wasm/examples/src/test.js | 90 ++++++ bindings/wasm/examples/src/utils.js | 29 ++ bindings/wasm/examples/src/utils_web.js | 72 +++++ bindings/wasm/examples/src/web.js | 64 ++++ bindings/wasm/examples/webpack.config.js | 51 +++ bindings/wasm/package.json | 3 +- bindings/wasm/yarn.lock | 305 ++++++++++-------- 20 files changed, 1232 insertions(+), 145 deletions(-) create mode 100644 bindings/wasm/examples/src/config.js create mode 100644 bindings/wasm/examples/src/create_did.js create mode 100644 bindings/wasm/examples/src/create_vc.js create mode 100644 bindings/wasm/examples/src/create_vp.js create mode 100644 bindings/wasm/examples/src/diff_chain.js create mode 100644 bindings/wasm/examples/src/manipulate_did.js create mode 100644 bindings/wasm/examples/src/merkle_key.js create mode 100644 bindings/wasm/examples/src/node.js create mode 100644 bindings/wasm/examples/src/private_tangle.js create mode 100644 bindings/wasm/examples/src/resolution.js create mode 100644 bindings/wasm/examples/src/resolve_history.js create mode 100644 bindings/wasm/examples/src/revoke_vc.js create mode 100644 bindings/wasm/examples/src/test.js create mode 100644 bindings/wasm/examples/src/utils.js create mode 100644 bindings/wasm/examples/src/utils_web.js create mode 100644 bindings/wasm/examples/src/web.js create mode 100644 bindings/wasm/examples/webpack.config.js 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/src/config.js b/bindings/wasm/examples/src/config.js new file mode 100644 index 0000000000..37a935f94c --- /dev/null +++ b/bindings/wasm/examples/src/config.js @@ -0,0 +1,15 @@ +// Copyright 2020-2021 IOTA Stiftung +// SPDX-License-Identifier: Apache-2.0 + +import { Network } from '@iota/identity-wasm'; + +const MAINNET = Network.mainnet(); + +/* @type {{network: Network, defaultNodeURL: string, explorerURL: string}} */ +const CLIENT_CONFIG = { + network: MAINNET, + defaultNodeURL: MAINNET.defaultNodeURL, + explorerURL: MAINNET.explorerURL, +} + +export {CLIENT_CONFIG}; diff --git a/bindings/wasm/examples/src/create_did.js b/bindings/wasm/examples/src/create_did.js new file mode 100644 index 0000000000..ee9032d103 --- /dev/null +++ b/bindings/wasm/examples/src/create_did.js @@ -0,0 +1,40 @@ +// Copyright 2020-2021 IOTA Stiftung +// SPDX-License-Identifier: Apache-2.0 + +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. + 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 +**/ +async function createIdentity(clientConfig) { + + console.log(Client, Config, Document, KeyType); + // Create a DID Document (an identity). + const { doc, key } = new Document(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 = Config.fromNetwork(clientConfig.network); + + // Create a client instance 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()); + + // Log the results. + logExplorerUrl("Identity Creation:", clientConfig.network.toString(), receipt.messageId); + + // Return the results. + return {key, doc, receipt}; +} + +export {createIdentity}; \ No newline at end of file diff --git a/bindings/wasm/examples/src/create_vc.js b/bindings/wasm/examples/src/create_vc.js new file mode 100644 index 0000000000..5e24c1668f --- /dev/null +++ b/bindings/wasm/examples/src/create_vc.js @@ -0,0 +1,59 @@ +// 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'); + +/** + 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 + **/ +async function createVC(clientConfig) { + // Create a default client configuration from the parent config network. + const config = Config.fromNetwork(clientConfig.network); + + // Create a client instance to publish messages to the Tangle. + const client = Client.fromConfig(config); + + // Creates new identities (See "create_did" and "manipulate_did" examples) + const alice = await createIdentity(clientConfig); + const issuer = await manipulateIdentity(clientConfig); + + // 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 = VerifiableCredential.extend({ + id: "https://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, + }); + + // Check if the credential is verifiable. + const result = await client.checkCredential(signedVc.toString()); + + console.log(`VC verification result: ${result.verified}`); + + return {alice, issuer, signedVc}; +} + +exports.createVC = createVC; diff --git a/bindings/wasm/examples/src/create_vp.js b/bindings/wasm/examples/src/create_vp.js new file mode 100644 index 0000000000..7c9bdb25d1 --- /dev/null +++ b/bindings/wasm/examples/src/create_vp.js @@ -0,0 +1,39 @@ +// Copyright 2020-2021 IOTA Stiftung +// SPDX-License-Identifier: Apache-2.0 + +const { Client, Config, VerifiablePresentation } = require('../../node/identity_wasm') +const { createVC } = require('./create_vc'); + +/** + 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 +**/ +async function createVP(clientConfig) { + // Create a default client configuration from the parent config network. + const config = Config.fromNetwork(clientConfig.network); + + // Create a client instance to publish messages to the Tangle. + const client = Client.fromConfig(config); + + // Creates new identities (See "createVC" example) + const {alice, signedVc} = await createVC(clientConfig); + + // Create a Verifiable Presentation from the Credential - signed by Alice's key + // TODO: Sign with a challenge + const unsignedVp = new VerifiablePresentation(alice.doc, signedVc.toJSON()) + + const signedVp = alice.doc.signPresentation(unsignedVp, { + method: "#key", + secret: alice.key.secret, + }) + + // Check the validation status of the Verifiable Presentation + const result = await client.checkPresentation(signedVp.toString()); + + console.log(`VP verification result: ${result.verified}`); +} + +exports.createVP = createVP; diff --git a/bindings/wasm/examples/src/diff_chain.js b/bindings/wasm/examples/src/diff_chain.js new file mode 100644 index 0000000000..314a78ad2d --- /dev/null +++ b/bindings/wasm/examples/src/diff_chain.js @@ -0,0 +1,51 @@ +// 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"); + +/** + 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 + **/ +async function createDiff(clientConfig) { + // Create a default client configuration from the parent config network. + const config = Config.fromNetwork(clientConfig.network); + + // Create a client instance to publish messages to the Tangle. + const client = Client.fromConfig(config); + + // Create a new identity (see "create_did.js" example). + const {key, doc, receipt} = await createIdentity(clientConfig); + + // Clone the Document + const updatedDoc = Document.fromJSON(doc.toJSON()); + + // Add a Service + let serviceJSON = { + id: doc.id + "#new-linked-domain", + type: "LinkedDomains", + serviceEndpoint: "https://identity.iota.org", + }; + updatedDoc.insertService(Service.fromJSON(serviceJSON)); + console.log(updatedDoc); + + // Create diff + const diff = doc.diff(updatedDoc, receipt.messageId, key); + console.log(diff); + + // Publish diff to the Tangle + const diffReceipt = await client.publishDiff(receipt.messageId, diff); + console.log(diffReceipt); + logExplorerUrl("Diff Chain Transaction:", clientConfig.network.toString(), diffReceipt.messageId); + + return {updatedDoc, key, diffMessageId: diffReceipt.messageId}; +} + +exports.createDiff = createDiff; diff --git a/bindings/wasm/examples/src/manipulate_did.js b/bindings/wasm/examples/src/manipulate_did.js new file mode 100644 index 0000000000..660877c85d --- /dev/null +++ b/bindings/wasm/examples/src/manipulate_did.js @@ -0,0 +1,67 @@ +// Copyright 2020-2021 IOTA Stiftung +// SPDX-License-Identifier: Apache-2.0 + +const {Client, Config, KeyPair, KeyType, VerificationMethod, Service, Timestamp} = require("../../node/identity_wasm"); +const {createIdentity} = require("./create_did"); +const {logExplorerUrl} = require("./utils"); + +/** + 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 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 + **/ +async function manipulateIdentity(clientConfig) { + // Create a default client configuration from the parent config network. + const config = Config.fromNetwork(clientConfig.network); + + // Create a client instance to publish messages to the Tangle. + const client = Client.fromConfig(config); + + // Creates a new identity (see "create_did" example) + let {key, doc, receipt} = await createIdentity(clientConfig); + + // Add a new VerificationMethod with a new KeyPair + const newKey = new KeyPair(KeyType.Ed25519); + const method = VerificationMethod.fromDID(doc.id, newKey, "newKey"); + doc.insertMethod(method, "VerificationMethod"); + + // Add a new ServiceEndpoint + const serviceJSON = { + id: doc.id + "#linked-domain", + type: "LinkedDomains", + serviceEndpoint: "https://iota.org", + }; + doc.insertService(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 = 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()); + + // Log the results. + logExplorerUrl("Identity Update:", clientConfig.network.toString(), updateReceipt.messageId); + return { + key, + newKey, + doc, + originalMessageId: receipt.messageId, + updatedMessageId: updateReceipt.messageId, + }; +} + +exports.manipulateIdentity = manipulateIdentity; diff --git a/bindings/wasm/examples/src/merkle_key.js b/bindings/wasm/examples/src/merkle_key.js new file mode 100644 index 0000000000..32df457b3e --- /dev/null +++ b/bindings/wasm/examples/src/merkle_key.js @@ -0,0 +1,96 @@ +// Copyright 2020-2021 IOTA Stiftung +// SPDX-License-Identifier: Apache-2.0 + +const { + Client, + Config, + Digest, + KeyType, + Timestamp, + VerifiableCredential, + VerificationMethod, + KeyCollection +} = require('../../node/identity_wasm') +const {createIdentity} = require('./create_did'); +const {logExplorerUrl} = require('./utils') + +/** + 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 + **/ +async function merkleKey(clientConfig) { + // Create a default client configuration from the parent config network. + const config = Config.fromNetwork(clientConfig.network); + + // Create a client instance to publish messages to the Tangle. + const client = Client.fromConfig(config); + + // Creates new identities (See "create_did" example) + const alice = await createIdentity(clientConfig); + const issuer = await createIdentity(clientConfig); + + // Add a Merkle Key Collection Verification Method with 8 keys (Must be a power of 2) + const keys = new KeyCollection(KeyType.Ed25519, 8); + const method = VerificationMethod.createMerkleKey(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 = 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()); + logExplorerUrl("Identity Update:", clientConfig.network.toString(), receipt.messageId); + + // 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 = 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(Digest.Sha256, 0) + }); + + // Check the verifiable credential is valid + const result = await client.checkCredential(signedVc.toString()); + console.log(`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 = Timestamp.nowUTC(); + issuer.doc.sign(issuer.key); + const nextReceipt = await client.publishDocument(issuer.doc.toJSON()); + logExplorerUrl("Identity Update:", clientConfig.network.toString(), nextReceipt.messageId); + + // Check the verifiable credential is revoked + const newResult = await client.checkCredential(signedVc.toString()); + console.log(`VC verification result (false = revoked): ${newResult.verified}`); + if (newResult.verified) throw new Error("VC not revoked"); +} + +exports.merkleKey = merkleKey; diff --git a/bindings/wasm/examples/src/node.js b/bindings/wasm/examples/src/node.js new file mode 100644 index 0000000000..ba99862fb6 --- /dev/null +++ b/bindings/wasm/examples/src/node.js @@ -0,0 +1,71 @@ +// Copyright 2020-2021 IOTA Stiftung +// SPDX-License-Identifier: Apache-2.0 + +import {createIdentity} from "./create_did"; +// const {manipulateIdentity} = require("./manipulate_did"); +// const {createIdentityPrivateTangle} = require("./private_tangle"); +// const {resolution} = require("./resolution"); +// const {createVC} = require("./create_vc"); +// const {createVP} = require("./create_vp"); +// const {revokeVC} = require("./revoke_vc"); +// const {merkleKey} = require("./merkle_key"); +import {CLIENT_CONFIG} from "./config"; +// const {resolveHistory} = require("./resolve_history"); +// const {createDiff} = require("./diff_chain"); + +async function main() { + //Check if an example is mentioned + if (process.argv.length != 3) { + throw "Please provide one command line argument with the example name."; + } + + //Take out the argument + let argument = process.argv[2]; + switch (argument) { + case "create_did": + return await createIdentity(CLIENT_CONFIG); + case "manipulate_did": + return await manipulateIdentity(CLIENT_CONFIG); + case "resolution": + return await resolution(CLIENT_CONFIG); + case "create_vc": + return await createVC(CLIENT_CONFIG); + case "revoke_vc": + return await revokeVC(CLIENT_CONFIG); + case "create_vp": + return await createVP(CLIENT_CONFIG); + case "merkle_key": + return await merkleKey(CLIENT_CONFIG); + case "private_tangle": + return await createIdentityPrivateTangle(); + case "resolve_history": + return await resolveHistory(CLIENT_CONFIG); + case "diff_chain": + return await createDiff(CLIENT_CONFIG); + case "all": + console.log(">>> Run All Examples"); + + await createIdentity(CLIENT_CONFIG); + await manipulateIdentity(CLIENT_CONFIG); + await resolution(CLIENT_CONFIG); + await createVC(CLIENT_CONFIG); + await revokeVC(CLIENT_CONFIG); + await createVP(CLIENT_CONFIG); + await merkleKey(CLIENT_CONFIG); + await resolveHistory(CLIENT_CONFIG); + await createDiff(CLIENT_CONFIG); + + console.log(">>> End All Examples"); + return "all"; + default: + throw "Unknown example name"; + } +} + +main() + .then((output) => { + console.log("Ok >", output); + }) + .catch((error) => { + console.log("Err >", error); + }); diff --git a/bindings/wasm/examples/src/private_tangle.js b/bindings/wasm/examples/src/private_tangle.js new file mode 100644 index 0000000000..a148b43095 --- /dev/null +++ b/bindings/wasm/examples/src/private_tangle.js @@ -0,0 +1,42 @@ +// Copyright 2020-2021 IOTA Stiftung +// SPDX-License-Identifier: Apache-2.0 + +const { Client, Config, Document, KeyType, Network } = require('../../node/identity_wasm') + +/** + 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. +**/ +async function createIdentityPrivateTangle() { + // This is an arbitrarily defined network name + const network = Network.from_name("custom"); + + // 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 points to the REST API of the locally running hornet node. + config.setNode("http://127.0.0.1:14265/"); + + // 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()); + + // Make sure the DID can be resolved on the private tangle + const resolved = await client.resolve(doc.id.toString()); + + // Return the results. + return { key, resolved, receipt }; +} + +exports.createIdentityPrivateTangle = createIdentityPrivateTangle; diff --git a/bindings/wasm/examples/src/resolution.js b/bindings/wasm/examples/src/resolution.js new file mode 100644 index 0000000000..f4b74cb27d --- /dev/null +++ b/bindings/wasm/examples/src/resolution.js @@ -0,0 +1,26 @@ +// Copyright 2020-2021 IOTA Stiftung +// SPDX-License-Identifier: Apache-2.0 + +const {Client, Config} = require('../../node/identity_wasm') +const {manipulateIdentity} = require("./manipulate_did"); + +/** + A short example to show how to resolve a DID. This returns the latest DID Document. + + @param {{defaultNodeURL: string, explorerURL: string, network: Network}} clientConfig + **/ +async function resolution(clientConfig) { + // Create a default client configuration from the parent config network. + const config = Config.fromNetwork(clientConfig.network); + + // Create a client instance to publish messages to the Tangle. + const client = Client.fromConfig(config); + + // Creates a new identity, that also is updated (See "manipulate_did" example). + const result = await manipulateIdentity(clientConfig); + + // Resolve a DID. + return await client.resolve(result.doc.id.toString()); +} + +exports.resolution = resolution; diff --git a/bindings/wasm/examples/src/resolve_history.js b/bindings/wasm/examples/src/resolve_history.js new file mode 100644 index 0000000000..10e41233eb --- /dev/null +++ b/bindings/wasm/examples/src/resolve_history.js @@ -0,0 +1,204 @@ +// Copyright 2020-2021 IOTA Stiftung +// SPDX-License-Identifier: Apache-2.0 + +const {logExplorerUrl, prettyPrintJSON} = require("./utils"); +const { + Client, + Config, + Document, + Service, + KeyPair, + VerificationMethod, + KeyType, + Timestamp, DID +} = require("../../node/identity_wasm"); +const {createIdentity} = require("./create_did"); + +/** + 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 + **/ +async function resolveHistory(clientConfig) { + // Create a default client configuration from the parent config network. + const config = Config.fromNetwork(clientConfig.network); + + // Create a client instance to publish messages to the Tangle. + const client = Client.fromConfig(config); + + // =========================================================================== + // DID Creation + // =========================================================================== + + // Create a new identity (see "create_did.js" example). + const {doc, key, receipt: originalReceipt} = await createIdentity(clientConfig); + + // =========================================================================== + // 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 = Document.fromJSON(doc.toJSON()); // clone the Document + + // Add a new VerificationMethod with a new KeyPair, with the tag "keys-1" + const keys1 = new KeyPair(KeyType.Ed25519); + const method1 = 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 = 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. + logExplorerUrl("Int. Chain Update (1):", clientConfig.network.toString(), intReceipt1.messageId); + + // =========================================================================== + // Diff Chain Update 1 + // =========================================================================== + + // Prepare a diff chain DID Document update. + const diffDoc1 = 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(Service.fromJSON(serviceJSON1)); + diffDoc1.updated = 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); + logExplorerUrl("Diff Chain Transaction (1):", clientConfig.network.toString(), diffReceipt1.messageId); + + // =========================================================================== + // Diff Chain Update 2 + // =========================================================================== + + // Prepare another diff chain update. + const diffDoc2 = 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(Service.fromJSON(serviceJSON2)); + diffDoc2.updated = 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); + logExplorerUrl("Diff Chain Transaction (2):", clientConfig.network.toString(), 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 = 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. + prettyPrintJSON(history1, "History (1):"); + + // =========================================================================== + // Integration Chain Update 2 + // =========================================================================== + + // Publish a second integration chain update + let intDoc2 = Document.fromJSON(diffDoc2.toJSON()); + + // Remove the #keys-1 VerificationMethod + intDoc2.removeMethod(DID.parse(intDoc2.id.toString() + "#keys-1")); + + // Remove the #linked-domain-1 Service + intDoc2.removeService(DID.parse(intDoc2.id.toString() + "#linked-domain-1")); + + // Add a VerificationMethod with a new KeyPair, called "keys-2" + const keys2 = new KeyPair(KeyType.Ed25519); + const method2 = 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 = Timestamp.nowUTC(); + intDoc2.sign(key); + const intReceipt2 = await client.publishDocument(intDoc2.toJSON()); + + // Log the results. + logExplorerUrl("Int. Chain Update (2):", clientConfig.network.toString(), 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. + prettyPrintJSON(history2, "History (2):"); + + // =========================================================================== + // 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); + prettyPrintJSON(previousDiffHistory, "Previous Diff History:"); +} + +exports.resolveHistory = resolveHistory; diff --git a/bindings/wasm/examples/src/revoke_vc.js b/bindings/wasm/examples/src/revoke_vc.js new file mode 100644 index 0000000000..46ac430859 --- /dev/null +++ b/bindings/wasm/examples/src/revoke_vc.js @@ -0,0 +1,50 @@ +// Copyright 2020-2021 IOTA Stiftung +// SPDX-License-Identifier: Apache-2.0 + +const {Client, Config, DID, Timestamp} = require('../../node/identity_wasm') +const {createVC} = require('./create_vc'); +const {logExplorerUrl} = require('./utils') + +/** + 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 + **/ +async function revoke(clientConfig) { + // Create a default client configuration from the parent config network. + const config = Config.fromNetwork(clientConfig.network); + + // Create a client instance to publish messages to the Tangle. + const client = Client.fromConfig(config); + + // Creates new identities and a VC (see "create_vc" example) + const {alice, issuer, signedVc} = await createVC(clientConfig); + + // Remove the public key that signed the VC - effectively revoking the VC as it will no longer be able to verify + issuer.doc.removeMethod(DID.parse(issuer.doc.id.toString() + "#newKey")); + issuer.doc.previousMessageId = issuer.updatedMessageId; + issuer.doc.updated = 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 + logExplorerUrl("Issuer Identity Update:", clientConfig.network.toString(), messageId); + + // Check the verifiable credential + const result = await client.checkCredential(signedVc.toString()); + console.log(`VC verification result (false = revoked): ${result.verified}`); +} + +exports.revokeVC = revoke; diff --git a/bindings/wasm/examples/src/test.js b/bindings/wasm/examples/src/test.js new file mode 100644 index 0000000000..e557c6885b --- /dev/null +++ b/bindings/wasm/examples/src/test.js @@ -0,0 +1,90 @@ +const { createIdentity } = require("./create_did"); +const { manipulateIdentity } = require("./manipulate_did"); +const { resolution } = require("./resolution"); +const { createVC } = require("./create_vc"); +const { createVP } = require("./create_vp"); +const { createDiff } = require("./diff_chain"); +const { revokeVC } = require("./revoke_vc"); +const { merkleKey } = require("./merkle_key"); +const { resolveHistory } = require("./resolve_history"); +const { CLIENT_CONFIG } = require("./config"); +const { createIdentityPrivateTangle } = require("./private_tangle"); + +jest.setTimeout(180000); // 3 minutes to account for spurious network delays, most tests pass in a few seconds + +// Run all Node.js examples as jest tests in parallel. +// If a function throws an exception, it will run again to make the tests more consistent (less prone to network issues). +// Only verifies that no uncaught exceptions are thrown, including syntax errors etc. +test.concurrent("Create Identity", async () => { + try { + await createIdentity(CLIENT_CONFIG); + } catch (e) { + await createIdentity(CLIENT_CONFIG); + } +}); +test.concurrent("Manipulate Identity", async () => { + try { + await manipulateIdentity(CLIENT_CONFIG); + } catch (e) { + await manipulateIdentity(CLIENT_CONFIG); + } +}); +test.concurrent("Resolution", async () => { + try { + await resolution(CLIENT_CONFIG); + } catch (e) { + await resolution(CLIENT_CONFIG); + } +}); +test.concurrent("Create Verifiable Credential", async () => { + try { + await createVC(CLIENT_CONFIG); + } catch (e) { + await createVC(CLIENT_CONFIG); + } +}); +test.concurrent("Create Verifiable Presentation", async () => { + try { + await createVP(CLIENT_CONFIG); + } catch (e) { + await createVP(CLIENT_CONFIG); + } +}); +test.concurrent("Revoke Verifiable Credential", async () => { + try { + await revokeVC(CLIENT_CONFIG); + } catch (e) { + await revokeVC(CLIENT_CONFIG); + } +}); +test.concurrent("Merkle Key", async () => { + try { + await merkleKey(CLIENT_CONFIG); + } catch (e) { + await merkleKey(CLIENT_CONFIG); + } +}); +test.concurrent("Private Tangle", async () => { + try { + await createIdentityPrivateTangle() + throw new Error("Did not throw.") + } catch (err) { + // Example is expected to throw an error because no private Tangle is running + expect(err.name).toEqual("ClientError") + expect(err.message).toContain("error sending request") + } +}); +test.concurrent("Diff Chain", async () => { + try { + await createDiff(CLIENT_CONFIG); + } catch (e) { + await createDiff(CLIENT_CONFIG); + } +}); +test.concurrent("Resolve History", async () => { + try { + await resolveHistory(CLIENT_CONFIG); + } catch (e) { + await resolveHistory(CLIENT_CONFIG); + } +}); diff --git a/bindings/wasm/examples/src/utils.js b/bindings/wasm/examples/src/utils.js new file mode 100644 index 0000000000..1ed2dd99b4 --- /dev/null +++ b/bindings/wasm/examples/src/utils.js @@ -0,0 +1,29 @@ +// Copyright 2020-2021 IOTA Stiftung +// SPDX-License-Identifier: Apache-2.0 + +/** + Write out the Targle Explorer URL given the network and message ID, with the given preamble. + + @param {!string} preamble + @param {!string} network + @param {!string} messageId + **/ +function logExplorerUrl(preamble, network, messageId) { + console.log(`${preamble} https://explorer.iota.org/${network}net/transaction/${messageId}`); +} + +/** + Pretty-prints data to the console as a JSON string. This avoids nested fields being printed + as [Object], [Array] by converting it to a full JSON string first. + + @param {!Object} data + @param {!string | null} title + **/ +function prettyPrintJSON(data, title=null) { + if (title != null) { + console.log(title); + } + console.log(JSON.stringify(JSON.parse(data.toString()), null, 2)); +} + +export {logExplorerUrl, prettyPrintJSON} \ No newline at end of file diff --git a/bindings/wasm/examples/src/utils_web.js b/bindings/wasm/examples/src/utils_web.js new file mode 100644 index 0000000000..b1b72bc23a --- /dev/null +++ b/bindings/wasm/examples/src/utils_web.js @@ -0,0 +1,72 @@ +import * as identity from "@iota/identity-wasm"; + +/** + * 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/src/web.js b/bindings/wasm/examples/src/web.js new file mode 100644 index 0000000000..6d832c8607 --- /dev/null +++ b/bindings/wasm/examples/src/web.js @@ -0,0 +1,64 @@ +import { initIdentity, defaultClientConfig } from "./utils_web.js"; +import { createIdentity } from "./create_did.js"; +// import { createVC } from "./create_vc.js"; +// import { manipulateIdentity } from "./manipulate_did.js"; +// // import { resolveIdentity } from "./resolve.js"; +// import { createVP } from "./create_vp.js"; +// import { revokeVC } 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/webpack.config.js b/bindings/wasm/examples/webpack.config.js new file mode 100644 index 0000000000..0f20cfa5b0 --- /dev/null +++ b/bindings/wasm/examples/webpack.config.js @@ -0,0 +1,51 @@ +const path = require('path'); +const CopyWebPlugin = require('copy-webpack-plugin'); +const serverConfig = { + target: 'node', + entry: './examples/src/node.js', + output: { + path: path.resolve(__dirname, 'dist'), + filename: 'node.js', + }, + plugins: [ + new CopyWebPlugin({ + patterns: [ + { + from: path.resolve(__dirname, "../node/identity_wasm_bg.wasm"), + to: path.resolve(__dirname, "dist"), + } + ] + }), + ], + externals: [ + function ({ context, request }, callback) { + if (/^@iota\/identity-wasm$/.test(request)) { + console.log(request); + // Externalize to a commonjs module + return callback(null, 'commonjs ' + path.resolve(__dirname, '../node/identity_wasm.js')); + } + + // Continue without externalizing the import + callback(); + }, + ], +}; + +const clientConfig = { + target: 'web', + entry: './examples/src/web.js', + output: { + path: path.resolve(__dirname, 'dist'), + filename: 'web.js', + }, + experiments: { + topLevelAwait: true, + }, + resolve: { + alias: { + '@iota/identity-wasm': path.resolve(__dirname, '../web/identity_wasm.js'), + }, + }, +}; + +module.exports = [serverConfig, clientConfig]; \ No newline at end of file diff --git a/bindings/wasm/package.json b/bindings/wasm/package.json index 32e9bc3eb3..e5401658b1 100644 --- a/bindings/wasm/package.json +++ b/bindings/wasm/package.json @@ -13,6 +13,7 @@ "build:nodejs": "wasm-pack build --target nodejs --out-dir node && node ./build/node", "build:web": "wasm-pack build --target web --out-dir web && node ./build/web", "build:docs": "node ./build/docs", + "build:examples": "webpack --config ./examples/webpack.config.js --mode=production", "build": "npm run build:web && npm run build:nodejs && npm run build:docs", "pretest": "npm run build:nodejs", "prepublishOnly": "npm run build", @@ -51,7 +52,7 @@ "jest": "^27.0.6", "jsdoc-to-markdown": "^7.0.0", "wasm-pack": "^0.9.1", - "webpack": "^5.24.2", + "webpack": "^5.51.1", "webpack-cli": "^4.5.0", "webpack-dev-server": "^3.11.2" }, diff --git a/bindings/wasm/yarn.lock b/bindings/wasm/yarn.lock index 79ea99d555..524147646f 100644 --- a/bindings/wasm/yarn.lock +++ b/bindings/wasm/yarn.lock @@ -620,11 +620,16 @@ "@types/estree" "*" "@types/json-schema" "*" -"@types/estree@*", "@types/estree@^0.0.47": +"@types/estree@*": version "0.0.47" resolved "https://registry.yarnpkg.com/@types/estree/-/estree-0.0.47.tgz#d7a51db20f0650efec24cd04994f523d93172ed4" integrity sha512-c5ciR06jK8u9BstrmJyO97m+klJrrhCf9u3rLu3DEAJBirxRqSCvDQoYKmxuYwQI5SZChAWu+tq9oVlGRuzPAg== +"@types/estree@^0.0.50": + version "0.0.50" + resolved "https://registry.yarnpkg.com/@types/estree/-/estree-0.0.50.tgz#1e0caa9364d3fccd2931c3ed96fdbeaa5d4cca83" + integrity sha512-C6N5s2ZFtuZRj54k2/zyRhNDjJwwcViAM3Nbm8zjBpbqAdZ00mr0CFxvSKeO8Y/e03WVFLpQMdHYVfUd6SB+Hw== + "@types/glob@^7.1.1": version "7.1.3" resolved "https://registry.yarnpkg.com/@types/glob/-/glob-7.1.3.tgz#e6ba80f36b7daad2c685acd9266382e68985c183" @@ -664,6 +669,11 @@ resolved "https://registry.yarnpkg.com/@types/json-schema/-/json-schema-7.0.7.tgz#98a993516c859eb0d5c4c8f098317a9ea68db9ad" integrity sha512-cxWFQVseBm6O9Gbw1IWb8r6OS4OhSt3hPZLkFApLjM8TEXROBuQGLAH2i2gZpcXdLBIrpXuTDhH7Vbm1iXmNGA== +"@types/json-schema@^7.0.8": + version "7.0.9" + resolved "https://registry.yarnpkg.com/@types/json-schema/-/json-schema-7.0.9.tgz#97edc9037ea0c38585320b28964dde3b39e4660d" + integrity sha512-qcUXuemtEu+E5wZSJHNxUXeCZhAfXKQ41D+duX+VYPde7xyEVZci+/oXKJL13tnRs9lR2pr4fod59GT6/X1/yQ== + "@types/minimatch@*": version "3.0.4" resolved "https://registry.yarnpkg.com/@types/minimatch/-/minimatch-3.0.4.tgz#f0ec25dbf2f0e4b18647313ac031134ca5b24b21" @@ -728,125 +738,125 @@ watchpack "^1.6.0" which "^2.0.2" -"@webassemblyjs/ast@1.11.0": - version "1.11.0" - resolved "https://registry.yarnpkg.com/@webassemblyjs/ast/-/ast-1.11.0.tgz#a5aa679efdc9e51707a4207139da57920555961f" - integrity sha512-kX2W49LWsbthrmIRMbQZuQDhGtjyqXfEmmHyEi4XWnSZtPmxY0+3anPIzsnRb45VH/J55zlOfWvZuY47aJZTJg== +"@webassemblyjs/ast@1.11.1": + version "1.11.1" + resolved "https://registry.yarnpkg.com/@webassemblyjs/ast/-/ast-1.11.1.tgz#2bfd767eae1a6996f432ff7e8d7fc75679c0b6a7" + integrity sha512-ukBh14qFLjxTQNTXocdyksN5QdM28S1CxHt2rdskFyL+xFV7VremuBLVbmCePj+URalXBENx/9Lm7lnhihtCSw== dependencies: - "@webassemblyjs/helper-numbers" "1.11.0" - "@webassemblyjs/helper-wasm-bytecode" "1.11.0" + "@webassemblyjs/helper-numbers" "1.11.1" + "@webassemblyjs/helper-wasm-bytecode" "1.11.1" -"@webassemblyjs/floating-point-hex-parser@1.11.0": - version "1.11.0" - resolved "https://registry.yarnpkg.com/@webassemblyjs/floating-point-hex-parser/-/floating-point-hex-parser-1.11.0.tgz#34d62052f453cd43101d72eab4966a022587947c" - integrity sha512-Q/aVYs/VnPDVYvsCBL/gSgwmfjeCb4LW8+TMrO3cSzJImgv8lxxEPM2JA5jMrivE7LSz3V+PFqtMbls3m1exDA== +"@webassemblyjs/floating-point-hex-parser@1.11.1": + version "1.11.1" + resolved "https://registry.yarnpkg.com/@webassemblyjs/floating-point-hex-parser/-/floating-point-hex-parser-1.11.1.tgz#f6c61a705f0fd7a6aecaa4e8198f23d9dc179e4f" + integrity sha512-iGRfyc5Bq+NnNuX8b5hwBrRjzf0ocrJPI6GWFodBFzmFnyvrQ83SHKhmilCU/8Jv67i4GJZBMhEzltxzcNagtQ== -"@webassemblyjs/helper-api-error@1.11.0": - version "1.11.0" - resolved "https://registry.yarnpkg.com/@webassemblyjs/helper-api-error/-/helper-api-error-1.11.0.tgz#aaea8fb3b923f4aaa9b512ff541b013ffb68d2d4" - integrity sha512-baT/va95eXiXb2QflSx95QGT5ClzWpGaa8L7JnJbgzoYeaA27FCvuBXU758l+KXWRndEmUXjP0Q5fibhavIn8w== +"@webassemblyjs/helper-api-error@1.11.1": + version "1.11.1" + resolved "https://registry.yarnpkg.com/@webassemblyjs/helper-api-error/-/helper-api-error-1.11.1.tgz#1a63192d8788e5c012800ba6a7a46c705288fd16" + integrity sha512-RlhS8CBCXfRUR/cwo2ho9bkheSXG0+NwooXcc3PAILALf2QLdFyj7KGsKRbVc95hZnhnERon4kW/D3SZpp6Tcg== -"@webassemblyjs/helper-buffer@1.11.0": - version "1.11.0" - resolved "https://registry.yarnpkg.com/@webassemblyjs/helper-buffer/-/helper-buffer-1.11.0.tgz#d026c25d175e388a7dbda9694e91e743cbe9b642" - integrity sha512-u9HPBEl4DS+vA8qLQdEQ6N/eJQ7gT7aNvMIo8AAWvAl/xMrcOSiI2M0MAnMCy3jIFke7bEee/JwdX1nUpCtdyA== +"@webassemblyjs/helper-buffer@1.11.1": + version "1.11.1" + resolved "https://registry.yarnpkg.com/@webassemblyjs/helper-buffer/-/helper-buffer-1.11.1.tgz#832a900eb444884cde9a7cad467f81500f5e5ab5" + integrity sha512-gwikF65aDNeeXa8JxXa2BAk+REjSyhrNC9ZwdT0f8jc4dQQeDQ7G4m0f2QCLPJiMTTO6wfDmRmj/pW0PsUvIcA== -"@webassemblyjs/helper-numbers@1.11.0": - version "1.11.0" - resolved "https://registry.yarnpkg.com/@webassemblyjs/helper-numbers/-/helper-numbers-1.11.0.tgz#7ab04172d54e312cc6ea4286d7d9fa27c88cd4f9" - integrity sha512-DhRQKelIj01s5IgdsOJMKLppI+4zpmcMQ3XboFPLwCpSNH6Hqo1ritgHgD0nqHeSYqofA6aBN/NmXuGjM1jEfQ== +"@webassemblyjs/helper-numbers@1.11.1": + version "1.11.1" + resolved "https://registry.yarnpkg.com/@webassemblyjs/helper-numbers/-/helper-numbers-1.11.1.tgz#64d81da219fbbba1e3bd1bfc74f6e8c4e10a62ae" + integrity sha512-vDkbxiB8zfnPdNK9Rajcey5C0w+QJugEglN0of+kmO8l7lDb77AnlKYQF7aarZuCrv+l0UvqL+68gSDr3k9LPQ== dependencies: - "@webassemblyjs/floating-point-hex-parser" "1.11.0" - "@webassemblyjs/helper-api-error" "1.11.0" + "@webassemblyjs/floating-point-hex-parser" "1.11.1" + "@webassemblyjs/helper-api-error" "1.11.1" "@xtuc/long" "4.2.2" -"@webassemblyjs/helper-wasm-bytecode@1.11.0": - version "1.11.0" - resolved "https://registry.yarnpkg.com/@webassemblyjs/helper-wasm-bytecode/-/helper-wasm-bytecode-1.11.0.tgz#85fdcda4129902fe86f81abf7e7236953ec5a4e1" - integrity sha512-MbmhvxXExm542tWREgSFnOVo07fDpsBJg3sIl6fSp9xuu75eGz5lz31q7wTLffwL3Za7XNRCMZy210+tnsUSEA== +"@webassemblyjs/helper-wasm-bytecode@1.11.1": + version "1.11.1" + resolved "https://registry.yarnpkg.com/@webassemblyjs/helper-wasm-bytecode/-/helper-wasm-bytecode-1.11.1.tgz#f328241e41e7b199d0b20c18e88429c4433295e1" + integrity sha512-PvpoOGiJwXeTrSf/qfudJhwlvDQxFgelbMqtq52WWiXC6Xgg1IREdngmPN3bs4RoO83PnL/nFrxucXj1+BX62Q== -"@webassemblyjs/helper-wasm-section@1.11.0": - version "1.11.0" - resolved "https://registry.yarnpkg.com/@webassemblyjs/helper-wasm-section/-/helper-wasm-section-1.11.0.tgz#9ce2cc89300262509c801b4af113d1ca25c1a75b" - integrity sha512-3Eb88hcbfY/FCukrg6i3EH8H2UsD7x8Vy47iVJrP967A9JGqgBVL9aH71SETPx1JrGsOUVLo0c7vMCN22ytJew== +"@webassemblyjs/helper-wasm-section@1.11.1": + version "1.11.1" + resolved "https://registry.yarnpkg.com/@webassemblyjs/helper-wasm-section/-/helper-wasm-section-1.11.1.tgz#21ee065a7b635f319e738f0dd73bfbda281c097a" + integrity sha512-10P9No29rYX1j7F3EVPX3JvGPQPae+AomuSTPiF9eBQeChHI6iqjMIwR9JmOJXwpnn/oVGDk7I5IlskuMwU/pg== dependencies: - "@webassemblyjs/ast" "1.11.0" - "@webassemblyjs/helper-buffer" "1.11.0" - "@webassemblyjs/helper-wasm-bytecode" "1.11.0" - "@webassemblyjs/wasm-gen" "1.11.0" + "@webassemblyjs/ast" "1.11.1" + "@webassemblyjs/helper-buffer" "1.11.1" + "@webassemblyjs/helper-wasm-bytecode" "1.11.1" + "@webassemblyjs/wasm-gen" "1.11.1" -"@webassemblyjs/ieee754@1.11.0": - version "1.11.0" - resolved "https://registry.yarnpkg.com/@webassemblyjs/ieee754/-/ieee754-1.11.0.tgz#46975d583f9828f5d094ac210e219441c4e6f5cf" - integrity sha512-KXzOqpcYQwAfeQ6WbF6HXo+0udBNmw0iXDmEK5sFlmQdmND+tr773Ti8/5T/M6Tl/413ArSJErATd8In3B+WBA== +"@webassemblyjs/ieee754@1.11.1": + version "1.11.1" + resolved "https://registry.yarnpkg.com/@webassemblyjs/ieee754/-/ieee754-1.11.1.tgz#963929e9bbd05709e7e12243a099180812992614" + integrity sha512-hJ87QIPtAMKbFq6CGTkZYJivEwZDbQUgYd3qKSadTNOhVY7p+gfP6Sr0lLRVTaG1JjFj+r3YchoqRYxNH3M0GQ== dependencies: "@xtuc/ieee754" "^1.2.0" -"@webassemblyjs/leb128@1.11.0": - version "1.11.0" - resolved "https://registry.yarnpkg.com/@webassemblyjs/leb128/-/leb128-1.11.0.tgz#f7353de1df38aa201cba9fb88b43f41f75ff403b" - integrity sha512-aqbsHa1mSQAbeeNcl38un6qVY++hh8OpCOzxhixSYgbRfNWcxJNJQwe2rezK9XEcssJbbWIkblaJRwGMS9zp+g== +"@webassemblyjs/leb128@1.11.1": + version "1.11.1" + resolved "https://registry.yarnpkg.com/@webassemblyjs/leb128/-/leb128-1.11.1.tgz#ce814b45574e93d76bae1fb2644ab9cdd9527aa5" + integrity sha512-BJ2P0hNZ0u+Th1YZXJpzW6miwqQUGcIHT1G/sf72gLVD9DZ5AdYTqPNbHZh6K1M5VmKvFXwGSWZADz+qBWxeRw== dependencies: "@xtuc/long" "4.2.2" -"@webassemblyjs/utf8@1.11.0": - version "1.11.0" - resolved "https://registry.yarnpkg.com/@webassemblyjs/utf8/-/utf8-1.11.0.tgz#86e48f959cf49e0e5091f069a709b862f5a2cadf" - integrity sha512-A/lclGxH6SpSLSyFowMzO/+aDEPU4hvEiooCMXQPcQFPPJaYcPQNKGOCLUySJsYJ4trbpr+Fs08n4jelkVTGVw== - -"@webassemblyjs/wasm-edit@1.11.0": - version "1.11.0" - resolved "https://registry.yarnpkg.com/@webassemblyjs/wasm-edit/-/wasm-edit-1.11.0.tgz#ee4a5c9f677046a210542ae63897094c2027cb78" - integrity sha512-JHQ0damXy0G6J9ucyKVXO2j08JVJ2ntkdJlq1UTiUrIgfGMmA7Ik5VdC/L8hBK46kVJgujkBIoMtT8yVr+yVOQ== - dependencies: - "@webassemblyjs/ast" "1.11.0" - "@webassemblyjs/helper-buffer" "1.11.0" - "@webassemblyjs/helper-wasm-bytecode" "1.11.0" - "@webassemblyjs/helper-wasm-section" "1.11.0" - "@webassemblyjs/wasm-gen" "1.11.0" - "@webassemblyjs/wasm-opt" "1.11.0" - "@webassemblyjs/wasm-parser" "1.11.0" - "@webassemblyjs/wast-printer" "1.11.0" - -"@webassemblyjs/wasm-gen@1.11.0": - version "1.11.0" - resolved "https://registry.yarnpkg.com/@webassemblyjs/wasm-gen/-/wasm-gen-1.11.0.tgz#3cdb35e70082d42a35166988dda64f24ceb97abe" - integrity sha512-BEUv1aj0WptCZ9kIS30th5ILASUnAPEvE3tVMTrItnZRT9tXCLW2LEXT8ezLw59rqPP9klh9LPmpU+WmRQmCPQ== - dependencies: - "@webassemblyjs/ast" "1.11.0" - "@webassemblyjs/helper-wasm-bytecode" "1.11.0" - "@webassemblyjs/ieee754" "1.11.0" - "@webassemblyjs/leb128" "1.11.0" - "@webassemblyjs/utf8" "1.11.0" - -"@webassemblyjs/wasm-opt@1.11.0": - version "1.11.0" - resolved "https://registry.yarnpkg.com/@webassemblyjs/wasm-opt/-/wasm-opt-1.11.0.tgz#1638ae188137f4bb031f568a413cd24d32f92978" - integrity sha512-tHUSP5F4ywyh3hZ0+fDQuWxKx3mJiPeFufg+9gwTpYp324mPCQgnuVKwzLTZVqj0duRDovnPaZqDwoyhIO8kYg== - dependencies: - "@webassemblyjs/ast" "1.11.0" - "@webassemblyjs/helper-buffer" "1.11.0" - "@webassemblyjs/wasm-gen" "1.11.0" - "@webassemblyjs/wasm-parser" "1.11.0" - -"@webassemblyjs/wasm-parser@1.11.0": - version "1.11.0" - resolved "https://registry.yarnpkg.com/@webassemblyjs/wasm-parser/-/wasm-parser-1.11.0.tgz#3e680b8830d5b13d1ec86cc42f38f3d4a7700754" - integrity sha512-6L285Sgu9gphrcpDXINvm0M9BskznnzJTE7gYkjDbxET28shDqp27wpruyx3C2S/dvEwiigBwLA1cz7lNUi0kw== - dependencies: - "@webassemblyjs/ast" "1.11.0" - "@webassemblyjs/helper-api-error" "1.11.0" - "@webassemblyjs/helper-wasm-bytecode" "1.11.0" - "@webassemblyjs/ieee754" "1.11.0" - "@webassemblyjs/leb128" "1.11.0" - "@webassemblyjs/utf8" "1.11.0" - -"@webassemblyjs/wast-printer@1.11.0": - version "1.11.0" - resolved "https://registry.yarnpkg.com/@webassemblyjs/wast-printer/-/wast-printer-1.11.0.tgz#680d1f6a5365d6d401974a8e949e05474e1fab7e" - integrity sha512-Fg5OX46pRdTgB7rKIUojkh9vXaVN6sGYCnEiJN1GYkb0RPwShZXp6KTDqmoMdQPKhcroOXh3fEzmkWmCYaKYhQ== - dependencies: - "@webassemblyjs/ast" "1.11.0" +"@webassemblyjs/utf8@1.11.1": + version "1.11.1" + resolved "https://registry.yarnpkg.com/@webassemblyjs/utf8/-/utf8-1.11.1.tgz#d1f8b764369e7c6e6bae350e854dec9a59f0a3ff" + integrity sha512-9kqcxAEdMhiwQkHpkNiorZzqpGrodQQ2IGrHHxCy+Ozng0ofyMA0lTqiLkVs1uzTRejX+/O0EOT7KxqVPuXosQ== + +"@webassemblyjs/wasm-edit@1.11.1": + version "1.11.1" + resolved "https://registry.yarnpkg.com/@webassemblyjs/wasm-edit/-/wasm-edit-1.11.1.tgz#ad206ebf4bf95a058ce9880a8c092c5dec8193d6" + integrity sha512-g+RsupUC1aTHfR8CDgnsVRVZFJqdkFHpsHMfJuWQzWU3tvnLC07UqHICfP+4XyL2tnr1amvl1Sdp06TnYCmVkA== + dependencies: + "@webassemblyjs/ast" "1.11.1" + "@webassemblyjs/helper-buffer" "1.11.1" + "@webassemblyjs/helper-wasm-bytecode" "1.11.1" + "@webassemblyjs/helper-wasm-section" "1.11.1" + "@webassemblyjs/wasm-gen" "1.11.1" + "@webassemblyjs/wasm-opt" "1.11.1" + "@webassemblyjs/wasm-parser" "1.11.1" + "@webassemblyjs/wast-printer" "1.11.1" + +"@webassemblyjs/wasm-gen@1.11.1": + version "1.11.1" + resolved "https://registry.yarnpkg.com/@webassemblyjs/wasm-gen/-/wasm-gen-1.11.1.tgz#86c5ea304849759b7d88c47a32f4f039ae3c8f76" + integrity sha512-F7QqKXwwNlMmsulj6+O7r4mmtAlCWfO/0HdgOxSklZfQcDu0TpLiD1mRt/zF25Bk59FIjEuGAIyn5ei4yMfLhA== + dependencies: + "@webassemblyjs/ast" "1.11.1" + "@webassemblyjs/helper-wasm-bytecode" "1.11.1" + "@webassemblyjs/ieee754" "1.11.1" + "@webassemblyjs/leb128" "1.11.1" + "@webassemblyjs/utf8" "1.11.1" + +"@webassemblyjs/wasm-opt@1.11.1": + version "1.11.1" + resolved "https://registry.yarnpkg.com/@webassemblyjs/wasm-opt/-/wasm-opt-1.11.1.tgz#657b4c2202f4cf3b345f8a4c6461c8c2418985f2" + integrity sha512-VqnkNqnZlU5EB64pp1l7hdm3hmQw7Vgqa0KF/KCNO9sIpI6Fk6brDEiX+iCOYrvMuBWDws0NkTOxYEb85XQHHw== + dependencies: + "@webassemblyjs/ast" "1.11.1" + "@webassemblyjs/helper-buffer" "1.11.1" + "@webassemblyjs/wasm-gen" "1.11.1" + "@webassemblyjs/wasm-parser" "1.11.1" + +"@webassemblyjs/wasm-parser@1.11.1": + version "1.11.1" + resolved "https://registry.yarnpkg.com/@webassemblyjs/wasm-parser/-/wasm-parser-1.11.1.tgz#86ca734534f417e9bd3c67c7a1c75d8be41fb199" + integrity sha512-rrBujw+dJu32gYB7/Lup6UhdkPx9S9SnobZzRVL7VcBH9Bt9bCBLEuX/YXOOtBsOZ4NQrRykKhffRWHvigQvOA== + dependencies: + "@webassemblyjs/ast" "1.11.1" + "@webassemblyjs/helper-api-error" "1.11.1" + "@webassemblyjs/helper-wasm-bytecode" "1.11.1" + "@webassemblyjs/ieee754" "1.11.1" + "@webassemblyjs/leb128" "1.11.1" + "@webassemblyjs/utf8" "1.11.1" + +"@webassemblyjs/wast-printer@1.11.1": + version "1.11.1" + resolved "https://registry.yarnpkg.com/@webassemblyjs/wast-printer/-/wast-printer-1.11.1.tgz#d0c73beda8eec5426f10ae8ef55cee5e7084c2f0" + integrity sha512-IQboUWM4eKzWW+N/jij2sRatKMh99QEelo3Eb2q0qXkvPRISAj8Qxtmw5itwqK+TTkBuUIE45AxYPToqPtL5gg== + dependencies: + "@webassemblyjs/ast" "1.11.1" "@xtuc/long" "4.2.2" "@webpack-cli/configtest@^1.0.3": @@ -897,6 +907,11 @@ acorn-globals@^6.0.0: acorn "^7.1.1" acorn-walk "^7.1.1" +acorn-import-assertions@^1.7.6: + version "1.7.6" + resolved "https://registry.yarnpkg.com/acorn-import-assertions/-/acorn-import-assertions-1.7.6.tgz#580e3ffcae6770eebeec76c3b9723201e9d01f78" + integrity sha512-FlVvVFA1TX6l3lp8VjDnYYq7R1nyW6x3svAt4nDgrWQ9SBaSh9CnbwgSUTasgfNfOG5HlM1ehugCvM+hjo56LA== + acorn-walk@^7.1.1: version "7.2.0" resolved "https://registry.yarnpkg.com/acorn-walk/-/acorn-walk-7.2.0.tgz#0de889a601203909b0fbe07b8938dc21d2e967bc" @@ -907,12 +922,7 @@ acorn@^7.1.1: resolved "https://registry.yarnpkg.com/acorn/-/acorn-7.4.1.tgz#feaed255973d2e77555b83dbc08851a6c63520fa" integrity sha512-nQyp0o1/mNdbTO1PO6kHkwSrmgZ0MT/jCCpNiwbUjGoRN4dlBhqJtoQuCnEOKzgTVwg0ZWiCoQy6SxMebQVh8A== -acorn@^8.2.1: - version "8.3.0" - resolved "https://registry.yarnpkg.com/acorn/-/acorn-8.3.0.tgz#1193f9b96c4e8232f00b11a9edff81b2c8b98b88" - integrity sha512-tqPKHZ5CaBJw0Xmy0ZZvLs1qTV+BNFSyvn77ASXkpBNfIRk8ev26fKrD9iLGwGA9zedPao52GSHzq8lyZG0NUw== - -acorn@^8.2.4: +acorn@^8.2.4, acorn@^8.4.1: version "8.4.1" resolved "https://registry.yarnpkg.com/acorn/-/acorn-8.4.1.tgz#56c36251fc7cabc7096adc18f05afe814321a28c" integrity sha512-asabaBSkEKosYKMITunzX177CXxQ4Q8BSSzMTKD+FefUhipQC70gfW5SiUDhYQ3vk8G+81HqQk7Fv9OXwwn9KA== @@ -2324,10 +2334,10 @@ errno@^0.1.3: dependencies: prr "~1.0.1" -es-module-lexer@^0.4.0: - version "0.4.1" - resolved "https://registry.yarnpkg.com/es-module-lexer/-/es-module-lexer-0.4.1.tgz#dda8c6a14d8f340a24e34331e0fab0cb50438e0e" - integrity sha512-ooYciCUtfw6/d2w56UVeqHPcoCFAiJdz5XOkYpv/Txl1HMUozpXjz/2RIQgqwKdXNDPSF1W7mJCFse3G+HDyAA== +es-module-lexer@^0.7.1: + version "0.7.1" + resolved "https://registry.yarnpkg.com/es-module-lexer/-/es-module-lexer-0.7.1.tgz#c2c8e0f46f2df06274cdaf0dd3f3b33e0a0b267d" + integrity sha512-MgtWFl5No+4S3TmhDmCz2ObFGm6lEpTnzbQi+Dd+pw4mlTIZTmM2iAs5gRlmx5zS9luzobCSBSI90JM/1/JgOw== escalade@^3.1.1: version "3.1.1" @@ -5426,6 +5436,15 @@ schema-utils@^3.0.0: ajv "^6.12.5" ajv-keywords "^3.5.2" +schema-utils@^3.1.0: + version "3.1.1" + resolved "https://registry.yarnpkg.com/schema-utils/-/schema-utils-3.1.1.tgz#bc74c4b6b6995c1d88f76a8b77bea7219e0c8281" + integrity sha512-Y5PQxS4ITlC+EahLuXaY86TXfR7Dc5lw294alXOq86JAHCihAIZfqv8nNCWvaEJvaC51uN9hbLGeV0cFBdH+Fw== + dependencies: + "@types/json-schema" "^7.0.8" + ajv "^6.12.5" + ajv-keywords "^3.5.2" + secure-compare@3.0.1: version "3.0.1" resolved "https://registry.yarnpkg.com/secure-compare/-/secure-compare-3.0.1.tgz#f1a0329b308b221fae37b9974f3d578d0ca999e3" @@ -5486,6 +5505,13 @@ serialize-javascript@^5.0.1: dependencies: randombytes "^2.1.0" +serialize-javascript@^6.0.0: + version "6.0.0" + resolved "https://registry.yarnpkg.com/serialize-javascript/-/serialize-javascript-6.0.0.tgz#efae5d88f45d7924141da8b5c3a7a7e663fefeb8" + integrity sha512-Qr3TosvguFt8ePWqsvRfrKyQXIiW+nGbYpy8XK24NQHE83caxWt+mIymTT19DGFbNWNLfEwsrkSmN64lVWB9ag== + dependencies: + randombytes "^2.1.0" + serve-index@^1.9.1: version "1.9.1" resolved "https://registry.yarnpkg.com/serve-index/-/serve-index-1.9.1.tgz#d3768d69b1e7d82e5ce050fff5b453bea12a9239" @@ -5666,11 +5692,6 @@ sort-array@^4.1.3: array-back "^5.0.0" typical "^6.0.1" -source-list-map@^2.0.1: - version "2.0.1" - resolved "https://registry.yarnpkg.com/source-list-map/-/source-list-map-2.0.1.tgz#3993bd873bfc48479cca9ea3a547835c7c154b34" - integrity sha512-qnQ7gVMxGNxsiL4lEuJwe/To8UnK7fAnmbGEEH8RpLouuKbeEm0lhbQVFIrNSuB+G7tVrAlVsZgETT5nljf+Iw== - source-map-resolve@^0.5.0: version "0.5.3" resolved "https://registry.yarnpkg.com/source-map-resolve/-/source-map-resolve-0.5.3.tgz#190866bece7553e1f8f267a2ee82c606b5509a1a" @@ -5960,15 +5981,15 @@ terminal-link@^2.0.0: ansi-escapes "^4.2.1" supports-hyperlinks "^2.0.0" -terser-webpack-plugin@^5.1.1: - version "5.1.3" - resolved "https://registry.yarnpkg.com/terser-webpack-plugin/-/terser-webpack-plugin-5.1.3.tgz#30033e955ca28b55664f1e4b30a1347e61aa23af" - integrity sha512-cxGbMqr6+A2hrIB5ehFIF+F/iST5ZOxvOmy9zih9ySbP1C2oEWQSOUS+2SNBTjzx5xLKO4xnod9eywdfq1Nb9A== +terser-webpack-plugin@^5.1.3: + version "5.1.4" + resolved "https://registry.yarnpkg.com/terser-webpack-plugin/-/terser-webpack-plugin-5.1.4.tgz#c369cf8a47aa9922bd0d8a94fe3d3da11a7678a1" + integrity sha512-C2WkFwstHDhVEmsmlCxrXUtVklS+Ir1A7twrYzrDrQQOIMOaVAYykaoo/Aq1K0QRkMoY2hhvDQY1cm4jnIMFwA== dependencies: jest-worker "^27.0.2" p-limit "^3.1.0" schema-utils "^3.0.0" - serialize-javascript "^5.0.1" + serialize-javascript "^6.0.0" source-map "^0.6.1" terser "^5.7.0" @@ -6508,29 +6529,27 @@ webpack-merge@^5.7.3: clone-deep "^4.0.1" wildcard "^2.0.0" -webpack-sources@^2.3.0: - version "2.3.0" - resolved "https://registry.yarnpkg.com/webpack-sources/-/webpack-sources-2.3.0.tgz#9ed2de69b25143a4c18847586ad9eccb19278cfa" - integrity sha512-WyOdtwSvOML1kbgtXbTDnEW0jkJ7hZr/bDByIwszhWd/4XX1A3XMkrbFMsuH4+/MfLlZCUzlAdg4r7jaGKEIgQ== - dependencies: - source-list-map "^2.0.1" - source-map "^0.6.1" +webpack-sources@^3.2.0: + version "3.2.0" + resolved "https://registry.yarnpkg.com/webpack-sources/-/webpack-sources-3.2.0.tgz#b16973bcf844ebcdb3afde32eda1c04d0b90f89d" + integrity sha512-fahN08Et7P9trej8xz/Z7eRu8ltyiygEo/hnRi9KqBUs80KeDcnf96ZJo++ewWd84fEf3xSX9bp4ZS9hbw0OBw== -webpack@^5.24.2: - version "5.38.1" - resolved "https://registry.yarnpkg.com/webpack/-/webpack-5.38.1.tgz#5224c7f24c18e729268d3e3bc97240d6e880258e" - integrity sha512-OqRmYD1OJbHZph6RUMD93GcCZy4Z4wC0ele4FXyYF0J6AxO1vOSuIlU1hkS/lDlR9CDYBz64MZRmdbdnFFoT2g== +webpack@^5.51.1: + version "5.51.1" + resolved "https://registry.yarnpkg.com/webpack/-/webpack-5.51.1.tgz#41bebf38dccab9a89487b16dbe95c22e147aac57" + integrity sha512-xsn3lwqEKoFvqn4JQggPSRxE4dhsRcysWTqYABAZlmavcoTmwlOb9b1N36Inbt/eIispSkuHa80/FJkDTPos1A== dependencies: "@types/eslint-scope" "^3.7.0" - "@types/estree" "^0.0.47" - "@webassemblyjs/ast" "1.11.0" - "@webassemblyjs/wasm-edit" "1.11.0" - "@webassemblyjs/wasm-parser" "1.11.0" - acorn "^8.2.1" + "@types/estree" "^0.0.50" + "@webassemblyjs/ast" "1.11.1" + "@webassemblyjs/wasm-edit" "1.11.1" + "@webassemblyjs/wasm-parser" "1.11.1" + acorn "^8.4.1" + acorn-import-assertions "^1.7.6" browserslist "^4.14.5" chrome-trace-event "^1.0.2" enhanced-resolve "^5.8.0" - es-module-lexer "^0.4.0" + es-module-lexer "^0.7.1" eslint-scope "5.1.1" events "^3.2.0" glob-to-regexp "^0.4.1" @@ -6539,11 +6558,11 @@ webpack@^5.24.2: loader-runner "^4.2.0" mime-types "^2.1.27" neo-async "^2.6.2" - schema-utils "^3.0.0" + schema-utils "^3.1.0" tapable "^2.1.1" - terser-webpack-plugin "^5.1.1" + terser-webpack-plugin "^5.1.3" watchpack "^2.2.0" - webpack-sources "^2.3.0" + webpack-sources "^3.2.0" websocket-driver@>=0.5.1, websocket-driver@^0.7.4: version "0.7.4" From d531ac657cab0fb5f167ff10a99cd3c7460668e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eike=20Ha=C3=9F?= Date: Wed, 25 Aug 2021 17:28:11 +0200 Subject: [PATCH 02/23] enable more examples --- bindings/wasm/examples/src/create_did.js | 1 - bindings/wasm/examples/src/create_vc.js | 8 ++-- bindings/wasm/examples/src/manipulate_did.js | 8 ++-- bindings/wasm/examples/src/node.js | 4 +- bindings/wasm/examples/src/utils_web.js | 20 ++++----- bindings/wasm/examples/src/web.js | 47 +++++++++++++------- bindings/wasm/package.json | 2 +- 7 files changed, 53 insertions(+), 37 deletions(-) diff --git a/bindings/wasm/examples/src/create_did.js b/bindings/wasm/examples/src/create_did.js index ee9032d103..bfe086263f 100644 --- a/bindings/wasm/examples/src/create_did.js +++ b/bindings/wasm/examples/src/create_did.js @@ -14,7 +14,6 @@ import { logExplorerUrl } from './utils'; **/ async function createIdentity(clientConfig) { - console.log(Client, Config, Document, KeyType); // Create a DID Document (an identity). const { doc, key } = new Document(KeyType.Ed25519, clientConfig.network.toString()); diff --git a/bindings/wasm/examples/src/create_vc.js b/bindings/wasm/examples/src/create_vc.js index 5e24c1668f..5769ea7fa5 100644 --- a/bindings/wasm/examples/src/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/src/manipulate_did.js b/bindings/wasm/examples/src/manipulate_did.js index 660877c85d..e4702992d8 100644 --- a/bindings/wasm/examples/src/manipulate_did.js +++ b/bindings/wasm/examples/src/manipulate_did.js @@ -1,9 +1,9 @@ // Copyright 2020-2021 IOTA Stiftung // SPDX-License-Identifier: Apache-2.0 -const {Client, Config, KeyPair, KeyType, VerificationMethod, Service, Timestamp} = require("../../node/identity_wasm"); -const {createIdentity} = require("./create_did"); -const {logExplorerUrl} = require("./utils"); +import {Client, Config, KeyPair, KeyType, VerificationMethod, Service, Timestamp} from '@iota/identity-wasm'; +import {createIdentity} from "./create_did"; +import {logExplorerUrl} from "./utils"; /** This example shows how to add more to an existing DID Document. @@ -64,4 +64,4 @@ async function manipulateIdentity(clientConfig) { }; } -exports.manipulateIdentity = manipulateIdentity; +export {manipulateIdentity}; diff --git a/bindings/wasm/examples/src/node.js b/bindings/wasm/examples/src/node.js index ba99862fb6..4e0cd0b3d8 100644 --- a/bindings/wasm/examples/src/node.js +++ b/bindings/wasm/examples/src/node.js @@ -2,10 +2,10 @@ // SPDX-License-Identifier: Apache-2.0 import {createIdentity} from "./create_did"; -// const {manipulateIdentity} = require("./manipulate_did"); +import {manipulateIdentity} from "./manipulate_did"; // const {createIdentityPrivateTangle} = require("./private_tangle"); // const {resolution} = require("./resolution"); -// const {createVC} = require("./create_vc"); +import {createVC} from "./create_vc"; // const {createVP} = require("./create_vp"); // const {revokeVC} = require("./revoke_vc"); // const {merkleKey} = require("./merkle_key"); diff --git a/bindings/wasm/examples/src/utils_web.js b/bindings/wasm/examples/src/utils_web.js index b1b72bc23a..02df0440cf 100644 --- a/bindings/wasm/examples/src/utils_web.js +++ b/bindings/wasm/examples/src/utils_web.js @@ -1,17 +1,19 @@ import * as identity from "@iota/identity-wasm"; +export const LINK_REGEX = /(\b(https?|ftp):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/gim; + /** * Loads the identity wasm library. * * @returns {Promise} */ -export async function initIdentity(path = "../../web/identity_wasm_bg.wasm", log = true) { - if(log) logToScreen("Initialization started..."); +export async function initIdentity(path = "../../web/identity_wasm_bg.wasm") { + console.log("Initialization started..."); try { await identity.init(path); - if(log) logToScreen("Initialization success!"); + console.log("Initialization success!"); } catch (err) { - if(log) logToScreen(err); + console.error(err); } } @@ -55,12 +57,10 @@ export function logToScreen(message) { "
-------------------------------------
"; } -/** - * - * @param {string} url - */ -export function logExplorerUrlToScreen(url) { - logToScreen(`Explorer URL: ${url} `); +export function linkify(inputText) { + + return inputText.replace(LINK_REGEX, '$1'); + } /** diff --git a/bindings/wasm/examples/src/web.js b/bindings/wasm/examples/src/web.js index 6d832c8607..c6403e0427 100644 --- a/bindings/wasm/examples/src/web.js +++ b/bindings/wasm/examples/src/web.js @@ -1,6 +1,6 @@ -import { initIdentity, defaultClientConfig } from "./utils_web.js"; +import { initIdentity, defaultClientConfig, logToScreen, logObjectToScreen, linkify, LINK_REGEX } from "./utils_web.js"; import { createIdentity } from "./create_did.js"; -// import { createVC } from "./create_vc.js"; +import { createVC } from "./create_vc.js"; // import { manipulateIdentity } from "./manipulate_did.js"; // // import { resolveIdentity } from "./resolve.js"; // import { createVP } from "./create_vp.js"; @@ -11,42 +11,59 @@ import { createIdentity } from "./create_did.js"; // import { resolveHistory } from "./resolve_history.js"; await initIdentity(); -const clientConfig = defaultClientConfig(); +const CLIENT_CONFIG = defaultClientConfig(); + +var orig = console.log; + +console.log = function() { + + + Array.from(arguments).forEach(argument => { + if (typeof argument === 'object') { + return logObjectToScreen(argument); + } else if (typeof argument === 'string' && argument.match(LINK_REGEX)) { + return logToScreen(linkify(argument)); + } + logToScreen(argument); + }); + + orig.apply(console, arguments); +}; //handle create identity on click event document .querySelector("#create-identity-btn") - .addEventListener("click", () => createIdentity(clientConfig)); + .addEventListener("click", () => createIdentity(CLIENT_CONFIG)); // // //handle resolve DID on click event // // document // // .querySelector("#resolve-did-btn") -// // .addEventListener("click", () => resolveIdentity(clientConfig)); +// // .addEventListener("click", () => resolveIdentity(CLIENT_CONFIG)); // //handle manipulate DID on click event // document // .querySelector("#manipulate_did_btn") -// .addEventListener("click", () => manipulateIdentity(clientConfig)); +// .addEventListener("click", () => manipulateIdentity(CLIENT_CONFIG)); -// //handle create VC on click event -// document -// .querySelector("#create_vc_btn") -// .addEventListener("click", () => createVC(clientConfig)); +//handle create VC on click event +document + .querySelector("#create_vc_btn") + .addEventListener("click", () => createVC(CLIENT_CONFIG)); // //handle create VP on click event // document // .querySelector("#create_vp_btn") -// .addEventListener("click", () => createVP(clientConfig)); +// .addEventListener("click", () => createVP(CLIENT_CONFIG)); // //handle revoke VC on click event // document // .querySelector("#revoke_vc_btn") -// .addEventListener("click", () => revoke(clientConfig)); +// .addEventListener("click", () => revoke(CLIENT_CONFIG)); // //handle merkle key on click event // document // .querySelector("#merkle_key_btn") -// .addEventListener("click", () => merkleKey(clientConfig)); +// .addEventListener("click", () => merkleKey(CLIENT_CONFIG)); // //handle private tangle DID creation on click event // document @@ -56,9 +73,9 @@ document // //handle diff chain on click event // document // .querySelector("#diff_chain_btn") -// .addEventListener("click", () => createDiff(clientConfig)); +// .addEventListener("click", () => createDiff(CLIENT_CONFIG)); // //handle resolve history on click event // document // .querySelector("#did_history_btn") -// .addEventListener("click", () => resolveHistory(clientConfig)); +// .addEventListener("click", () => resolveHistory(CLIENT_CONFIG)); diff --git a/bindings/wasm/package.json b/bindings/wasm/package.json index e5401658b1..bba1aa831b 100644 --- a/bindings/wasm/package.json +++ b/bindings/wasm/package.json @@ -19,7 +19,7 @@ "prepublishOnly": "npm run build", "serve": "webpack serve", "example:node": "node examples/node/node.js", - "example:browser": "http-server -c-1 -o ./examples/browser/index.html", + "example:browser": "http-server -c-1 -o ./examples/dist/index.html", "test:node": "jest", "test:browser": "cypress run --headless", "test:readme": "txm README.md", From 0856120b4ad56230cd224aabcb2ea7c6eb401aaf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eike=20Ha=C3=9F?= Date: Thu, 26 Aug 2021 14:37:00 +0200 Subject: [PATCH 03/23] enabled more examples, cleaned up utils --- bindings/wasm/examples/src/create_vp.js | 6 +- bindings/wasm/examples/src/diff_chain.js | 8 +- bindings/wasm/examples/src/merkle_key.js | 10 +- bindings/wasm/examples/src/node.js | 12 +-- bindings/wasm/examples/src/resolve_history.js | 10 +- bindings/wasm/examples/src/revoke_vc.js | 10 +- bindings/wasm/examples/src/utils_web.js | 32 ++++--- bindings/wasm/examples/src/web.js | 91 ++++++++----------- 8 files changed, 86 insertions(+), 93 deletions(-) diff --git a/bindings/wasm/examples/src/create_vp.js b/bindings/wasm/examples/src/create_vp.js index 7c9bdb25d1..3b815523c4 100644 --- a/bindings/wasm/examples/src/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/src/diff_chain.js b/bindings/wasm/examples/src/diff_chain.js index 314a78ad2d..b73d1d6d6c 100644 --- a/bindings/wasm/examples/src/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/src/merkle_key.js b/bindings/wasm/examples/src/merkle_key.js index 32df457b3e..cf251308dc 100644 --- a/bindings/wasm/examples/src/merkle_key.js +++ b/bindings/wasm/examples/src/merkle_key.js @@ -1,7 +1,7 @@ // Copyright 2020-2021 IOTA Stiftung // SPDX-License-Identifier: Apache-2.0 -const { +import { Client, Config, Digest, @@ -10,9 +10,9 @@ const { VerifiableCredential, VerificationMethod, KeyCollection -} = require('../../node/identity_wasm') -const {createIdentity} = require('./create_did'); -const {logExplorerUrl} = require('./utils') +} from '@iota/identity-wasm'; +import {createIdentity} from './create_did'; +import {logExplorerUrl} from './utils'; /** This example shows how to sign/revoke verifiable credentials on scale. @@ -93,4 +93,4 @@ async function merkleKey(clientConfig) { if (newResult.verified) throw new Error("VC not revoked"); } -exports.merkleKey = merkleKey; +export {merkleKey}; diff --git a/bindings/wasm/examples/src/node.js b/bindings/wasm/examples/src/node.js index 4e0cd0b3d8..27c82c2922 100644 --- a/bindings/wasm/examples/src/node.js +++ b/bindings/wasm/examples/src/node.js @@ -3,15 +3,15 @@ import {createIdentity} from "./create_did"; import {manipulateIdentity} from "./manipulate_did"; -// const {createIdentityPrivateTangle} = require("./private_tangle"); +//const {createIdentityPrivateTangle} = require("./private_tangle"); // const {resolution} = require("./resolution"); import {createVC} from "./create_vc"; -// const {createVP} = require("./create_vp"); -// const {revokeVC} = require("./revoke_vc"); -// const {merkleKey} = require("./merkle_key"); +import {createVP} from "./create_vp"; +import {revokeVC} from "./revoke_vc"; +import {merkleKey} from "./merkle_key"; import {CLIENT_CONFIG} from "./config"; -// const {resolveHistory} = require("./resolve_history"); -// const {createDiff} = require("./diff_chain"); +import {resolveHistory} from "./resolve_history"; +import {createDiff} from "./diff_chain"; async function main() { //Check if an example is mentioned diff --git a/bindings/wasm/examples/src/resolve_history.js b/bindings/wasm/examples/src/resolve_history.js index 10e41233eb..5a41fc371e 100644 --- a/bindings/wasm/examples/src/resolve_history.js +++ b/bindings/wasm/examples/src/resolve_history.js @@ -1,8 +1,7 @@ // Copyright 2020-2021 IOTA Stiftung // SPDX-License-Identifier: Apache-2.0 -const {logExplorerUrl, prettyPrintJSON} = require("./utils"); -const { +import { Client, Config, Document, @@ -11,8 +10,9 @@ const { VerificationMethod, KeyType, Timestamp, DID -} = require("../../node/identity_wasm"); -const {createIdentity} = require("./create_did"); +} from '@iota/identity-wasm'; +import {logExplorerUrl, prettyPrintJSON} from "./utils"; +import {createIdentity} from "./create_did"; /** Advanced example that performs multiple diff chain and integration chain updates and @@ -201,4 +201,4 @@ async function resolveHistory(clientConfig) { prettyPrintJSON(previousDiffHistory, "Previous Diff History:"); } -exports.resolveHistory = resolveHistory; +export {resolveHistory}; diff --git a/bindings/wasm/examples/src/revoke_vc.js b/bindings/wasm/examples/src/revoke_vc.js index 46ac430859..b0755a6b68 100644 --- a/bindings/wasm/examples/src/revoke_vc.js +++ b/bindings/wasm/examples/src/revoke_vc.js @@ -1,9 +1,9 @@ // Copyright 2020-2021 IOTA Stiftung // SPDX-License-Identifier: Apache-2.0 -const {Client, Config, DID, Timestamp} = require('../../node/identity_wasm') -const {createVC} = require('./create_vc'); -const {logExplorerUrl} = require('./utils') +import {Client, Config, DID, Timestamp} from '@iota/identity-wasm'; +import {createVC} from './create_vc'; +import {logExplorerUrl} from './utils'; /** This example shows how to revoke a verifiable credential. @@ -21,7 +21,7 @@ const {logExplorerUrl} = require('./utils') @param {{defaultNodeURL: string, explorerURL: string, network: Network}} clientConfig **/ -async function revoke(clientConfig) { +async function revokeVC(clientConfig) { // Create a default client configuration from the parent config network. const config = Config.fromNetwork(clientConfig.network); @@ -47,4 +47,4 @@ async function revoke(clientConfig) { console.log(`VC verification result (false = revoked): ${result.verified}`); } -exports.revokeVC = revoke; +export {revokeVC}; diff --git a/bindings/wasm/examples/src/utils_web.js b/bindings/wasm/examples/src/utils_web.js index 02df0440cf..e4d99c8a50 100644 --- a/bindings/wasm/examples/src/utils_web.js +++ b/bindings/wasm/examples/src/utils_web.js @@ -33,18 +33,6 @@ export function defaultClientConfig() { } } -/** - * 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 * @@ -70,3 +58,23 @@ export function linkify(inputText) { export function logObjectToScreen(obj) { logToScreen("
" + JSON.stringify(obj, null, 4) + "
"); } + +export function setupDOMLog() { + var orig = console.log; + + console.log = function() { + + + Array.from(arguments).forEach(argument => { + if (typeof argument === 'object') { + return logObjectToScreen(argument); + } else if (typeof argument === 'string' && argument.match(LINK_REGEX)) { + return logToScreen(linkify(argument)); + } + logToScreen(argument); + }); + + orig.apply(console, arguments); + }; + +} \ No newline at end of file diff --git a/bindings/wasm/examples/src/web.js b/bindings/wasm/examples/src/web.js index c6403e0427..e9a5e3828a 100644 --- a/bindings/wasm/examples/src/web.js +++ b/bindings/wasm/examples/src/web.js @@ -1,81 +1,66 @@ -import { initIdentity, defaultClientConfig, logToScreen, logObjectToScreen, linkify, LINK_REGEX } from "./utils_web.js"; +import { initIdentity, defaultClientConfig, setupDOMLog } from "./utils_web.js"; import { createIdentity } from "./create_did.js"; import { createVC } from "./create_vc.js"; -// import { manipulateIdentity } from "./manipulate_did.js"; -// // import { resolveIdentity } from "./resolve.js"; -// import { createVP } from "./create_vp.js"; -// import { revokeVC } from "./revoke_vc.js"; -// import { merkleKey } from "./merkle_key.js"; +import { manipulateIdentity } from "./manipulate_did.js"; +//import { resolveIdentity } from "./resolve.js"; +import { createVP } from "./create_vp.js"; +import { revokeVC } 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"; +import { createDiff } from "./diff_chain.js"; +import { resolveHistory } from "./resolve_history.js"; + +setupDOMLog(); await initIdentity(); const CLIENT_CONFIG = defaultClientConfig(); -var orig = console.log; - -console.log = function() { - - - Array.from(arguments).forEach(argument => { - if (typeof argument === 'object') { - return logObjectToScreen(argument); - } else if (typeof argument === 'string' && argument.match(LINK_REGEX)) { - return logToScreen(linkify(argument)); - } - logToScreen(argument); - }); - - orig.apply(console, arguments); -}; - //handle create identity on click event document .querySelector("#create-identity-btn") .addEventListener("click", () => createIdentity(CLIENT_CONFIG)); -// // //handle resolve DID on click event -// // document -// // .querySelector("#resolve-did-btn") -// // .addEventListener("click", () => resolveIdentity(CLIENT_CONFIG)); - -// //handle manipulate DID on click event +// //handle resolve DID on click event // document -// .querySelector("#manipulate_did_btn") -// .addEventListener("click", () => manipulateIdentity(CLIENT_CONFIG)); +// .querySelector("#resolve-did-btn") +// .addEventListener("click", () => resolveIdentity(CLIENT_CONFIG)); + +//handle manipulate DID on click event +document + .querySelector("#manipulate_did_btn") + .addEventListener("click", () => manipulateIdentity(CLIENT_CONFIG)); //handle create VC on click event document .querySelector("#create_vc_btn") .addEventListener("click", () => createVC(CLIENT_CONFIG)); -// //handle create VP on click event -// document -// .querySelector("#create_vp_btn") -// .addEventListener("click", () => createVP(CLIENT_CONFIG)); +//handle create VP on click event +document + .querySelector("#create_vp_btn") + .addEventListener("click", () => createVP(CLIENT_CONFIG)); -// //handle revoke VC on click event -// document -// .querySelector("#revoke_vc_btn") -// .addEventListener("click", () => revoke(CLIENT_CONFIG)); +//handle revoke VC on click event +document + .querySelector("#revoke_vc_btn") + .addEventListener("click", () => revokeVC(CLIENT_CONFIG)); -// //handle merkle key on click event -// document -// .querySelector("#merkle_key_btn") -// .addEventListener("click", () => merkleKey(CLIENT_CONFIG)); +//handle merkle key on click event +document + .querySelector("#merkle_key_btn") + .addEventListener("click", () => merkleKey(CLIENT_CONFIG)); // //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(CLIENT_CONFIG)); +//handle diff chain on click event +document + .querySelector("#diff_chain_btn") + .addEventListener("click", () => createDiff(CLIENT_CONFIG)); -// //handle resolve history on click event -// document -// .querySelector("#did_history_btn") -// .addEventListener("click", () => resolveHistory(CLIENT_CONFIG)); +//handle resolve history on click event +document +.querySelector("#did_history_btn") +.addEventListener("click", () => resolveHistory(CLIENT_CONFIG)); From 776328ba7dc76201d9898deb68943c6355a81cf1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eike=20Ha=C3=9F?= Date: Thu, 26 Aug 2021 14:38:17 +0200 Subject: [PATCH 04/23] removed platform specific examples --- bindings/wasm/examples/browser/create_did.js | 48 ----- bindings/wasm/examples/browser/create_vc.js | 67 ------ bindings/wasm/examples/browser/create_vp.js | 46 ---- bindings/wasm/examples/browser/diff_chain.js | 49 ----- bindings/wasm/examples/browser/index.html | 76 ------- bindings/wasm/examples/browser/main.js | 64 ------ .../wasm/examples/browser/mainpulate_did.js | 70 ------ bindings/wasm/examples/browser/merkle_key.js | 98 --------- .../wasm/examples/browser/private_tangle.js | 64 ------ bindings/wasm/examples/browser/resolve.js | 32 --- .../wasm/examples/browser/resolve_history.js | 201 ----------------- bindings/wasm/examples/browser/revoke_vc.js | 48 ----- bindings/wasm/examples/browser/utils.js | 72 ------- bindings/wasm/examples/node/config.js | 15 -- bindings/wasm/examples/node/create_did.js | 38 ---- bindings/wasm/examples/node/create_vc.js | 59 ----- bindings/wasm/examples/node/create_vp.js | 39 ---- bindings/wasm/examples/node/diff_chain.js | 51 ----- bindings/wasm/examples/node/manipulate_did.js | 67 ------ bindings/wasm/examples/node/merkle_key.js | 96 --------- bindings/wasm/examples/node/node.js | 71 ------ bindings/wasm/examples/node/private_tangle.js | 42 ---- bindings/wasm/examples/node/resolution.js | 26 --- .../wasm/examples/node/resolve_history.js | 204 ------------------ bindings/wasm/examples/node/revoke_vc.js | 50 ----- bindings/wasm/examples/node/test.js | 90 -------- bindings/wasm/examples/node/utils.js | 30 --- 27 files changed, 1813 deletions(-) delete mode 100644 bindings/wasm/examples/browser/create_did.js delete mode 100644 bindings/wasm/examples/browser/create_vc.js delete mode 100644 bindings/wasm/examples/browser/create_vp.js delete mode 100644 bindings/wasm/examples/browser/diff_chain.js delete mode 100644 bindings/wasm/examples/browser/index.html delete mode 100644 bindings/wasm/examples/browser/main.js delete mode 100644 bindings/wasm/examples/browser/mainpulate_did.js delete mode 100644 bindings/wasm/examples/browser/merkle_key.js delete mode 100644 bindings/wasm/examples/browser/private_tangle.js delete mode 100644 bindings/wasm/examples/browser/resolve.js delete mode 100644 bindings/wasm/examples/browser/resolve_history.js delete mode 100644 bindings/wasm/examples/browser/revoke_vc.js delete mode 100644 bindings/wasm/examples/browser/utils.js delete mode 100644 bindings/wasm/examples/node/config.js delete mode 100644 bindings/wasm/examples/node/create_did.js delete mode 100644 bindings/wasm/examples/node/create_vc.js delete mode 100644 bindings/wasm/examples/node/create_vp.js delete mode 100644 bindings/wasm/examples/node/diff_chain.js delete mode 100644 bindings/wasm/examples/node/manipulate_did.js delete mode 100644 bindings/wasm/examples/node/merkle_key.js delete mode 100644 bindings/wasm/examples/node/node.js delete mode 100644 bindings/wasm/examples/node/private_tangle.js delete mode 100644 bindings/wasm/examples/node/resolution.js delete mode 100644 bindings/wasm/examples/node/resolve_history.js delete mode 100644 bindings/wasm/examples/node/revoke_vc.js delete mode 100644 bindings/wasm/examples/node/test.js delete mode 100644 bindings/wasm/examples/node/utils.js diff --git a/bindings/wasm/examples/browser/create_did.js b/bindings/wasm/examples/browser/create_did.js deleted file mode 100644 index 88a68ce3d4..0000000000 --- a/bindings/wasm/examples/browser/create_did.js +++ /dev/null @@ -1,48 +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()); - - 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/index.html b/bindings/wasm/examples/browser/index.html deleted file mode 100644 index 87d110d2f9..0000000000 --- a/bindings/wasm/examples/browser/index.html +++ /dev/null @@ -1,76 +0,0 @@ - - - - - - WASM Examples Browser - - - - - - - -
- - -
- - - - - - - - - - -
- - - -
- - - - - - - -

Output:

-
- - 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 79e8a21588..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.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/node/config.js deleted file mode 100644 index 34dce9a697..0000000000 --- a/bindings/wasm/examples/node/config.js +++ /dev/null @@ -1,15 +0,0 @@ -// Copyright 2020-2021 IOTA Stiftung -// SPDX-License-Identifier: Apache-2.0 - -const { Network } = require('../../node/identity_wasm') - -const MAINNET = Network.mainnet(); - -/* @type {{network: Network, defaultNodeURL: string, explorerURL: string}} */ -const CLIENT_CONFIG = { - network: MAINNET, - defaultNodeURL: MAINNET.defaultNodeURL, - explorerURL: MAINNET.explorerURL, -} - -exports.CLIENT_CONFIG = CLIENT_CONFIG; diff --git a/bindings/wasm/examples/node/create_did.js b/bindings/wasm/examples/node/create_did.js deleted file mode 100644 index 85f7604444..0000000000 --- a/bindings/wasm/examples/node/create_did.js +++ /dev/null @@ -1,38 +0,0 @@ -// Copyright 2020-2021 IOTA Stiftung -// SPDX-License-Identifier: Apache-2.0 - -const { Client, Config, Document, KeyType } = require('../../node/identity_wasm') -const { logExplorerUrl } = require('./utils') - -/** - 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 -**/ -async function createIdentity(clientConfig) { - // Create a DID Document (an identity). - const { doc, key } = new Document(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 = Config.fromNetwork(clientConfig.network); - - // Create a client instance 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()); - - // Log the results. - logExplorerUrl("Identity Creation:", clientConfig.network.toString(), receipt.messageId); - - // Return the results. - return {key, doc, receipt}; -} - -exports.createIdentity = createIdentity; diff --git a/bindings/wasm/examples/node/create_vc.js b/bindings/wasm/examples/node/create_vc.js deleted file mode 100644 index 5e24c1668f..0000000000 --- a/bindings/wasm/examples/node/create_vc.js +++ /dev/null @@ -1,59 +0,0 @@ -// 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'); - -/** - 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 - **/ -async function createVC(clientConfig) { - // Create a default client configuration from the parent config network. - const config = Config.fromNetwork(clientConfig.network); - - // Create a client instance to publish messages to the Tangle. - const client = Client.fromConfig(config); - - // Creates new identities (See "create_did" and "manipulate_did" examples) - const alice = await createIdentity(clientConfig); - const issuer = await manipulateIdentity(clientConfig); - - // 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 = VerifiableCredential.extend({ - id: "https://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, - }); - - // Check if the credential is verifiable. - const result = await client.checkCredential(signedVc.toString()); - - console.log(`VC verification result: ${result.verified}`); - - return {alice, issuer, signedVc}; -} - -exports.createVC = createVC; diff --git a/bindings/wasm/examples/node/create_vp.js b/bindings/wasm/examples/node/create_vp.js deleted file mode 100644 index 7c9bdb25d1..0000000000 --- a/bindings/wasm/examples/node/create_vp.js +++ /dev/null @@ -1,39 +0,0 @@ -// Copyright 2020-2021 IOTA Stiftung -// SPDX-License-Identifier: Apache-2.0 - -const { Client, Config, VerifiablePresentation } = require('../../node/identity_wasm') -const { createVC } = require('./create_vc'); - -/** - 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 -**/ -async function createVP(clientConfig) { - // Create a default client configuration from the parent config network. - const config = Config.fromNetwork(clientConfig.network); - - // Create a client instance to publish messages to the Tangle. - const client = Client.fromConfig(config); - - // Creates new identities (See "createVC" example) - const {alice, signedVc} = await createVC(clientConfig); - - // Create a Verifiable Presentation from the Credential - signed by Alice's key - // TODO: Sign with a challenge - const unsignedVp = new VerifiablePresentation(alice.doc, signedVc.toJSON()) - - const signedVp = alice.doc.signPresentation(unsignedVp, { - method: "#key", - secret: alice.key.secret, - }) - - // Check the validation status of the Verifiable Presentation - const result = await client.checkPresentation(signedVp.toString()); - - console.log(`VP verification result: ${result.verified}`); -} - -exports.createVP = createVP; diff --git a/bindings/wasm/examples/node/diff_chain.js b/bindings/wasm/examples/node/diff_chain.js deleted file mode 100644 index 314a78ad2d..0000000000 --- a/bindings/wasm/examples/node/diff_chain.js +++ /dev/null @@ -1,51 +0,0 @@ -// 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"); - -/** - 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 - **/ -async function createDiff(clientConfig) { - // Create a default client configuration from the parent config network. - const config = Config.fromNetwork(clientConfig.network); - - // Create a client instance to publish messages to the Tangle. - const client = Client.fromConfig(config); - - // Create a new identity (see "create_did.js" example). - const {key, doc, receipt} = await createIdentity(clientConfig); - - // Clone the Document - const updatedDoc = Document.fromJSON(doc.toJSON()); - - // Add a Service - let serviceJSON = { - id: doc.id + "#new-linked-domain", - type: "LinkedDomains", - serviceEndpoint: "https://identity.iota.org", - }; - updatedDoc.insertService(Service.fromJSON(serviceJSON)); - console.log(updatedDoc); - - // Create diff - const diff = doc.diff(updatedDoc, receipt.messageId, key); - console.log(diff); - - // Publish diff to the Tangle - const diffReceipt = await client.publishDiff(receipt.messageId, diff); - console.log(diffReceipt); - logExplorerUrl("Diff Chain Transaction:", clientConfig.network.toString(), diffReceipt.messageId); - - return {updatedDoc, key, diffMessageId: diffReceipt.messageId}; -} - -exports.createDiff = createDiff; diff --git a/bindings/wasm/examples/node/manipulate_did.js b/bindings/wasm/examples/node/manipulate_did.js deleted file mode 100644 index 660877c85d..0000000000 --- a/bindings/wasm/examples/node/manipulate_did.js +++ /dev/null @@ -1,67 +0,0 @@ -// Copyright 2020-2021 IOTA Stiftung -// SPDX-License-Identifier: Apache-2.0 - -const {Client, Config, KeyPair, KeyType, VerificationMethod, Service, Timestamp} = require("../../node/identity_wasm"); -const {createIdentity} = require("./create_did"); -const {logExplorerUrl} = require("./utils"); - -/** - 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 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 - **/ -async function manipulateIdentity(clientConfig) { - // Create a default client configuration from the parent config network. - const config = Config.fromNetwork(clientConfig.network); - - // Create a client instance to publish messages to the Tangle. - const client = Client.fromConfig(config); - - // Creates a new identity (see "create_did" example) - let {key, doc, receipt} = await createIdentity(clientConfig); - - // Add a new VerificationMethod with a new KeyPair - const newKey = new KeyPair(KeyType.Ed25519); - const method = VerificationMethod.fromDID(doc.id, newKey, "newKey"); - doc.insertMethod(method, "VerificationMethod"); - - // Add a new ServiceEndpoint - const serviceJSON = { - id: doc.id + "#linked-domain", - type: "LinkedDomains", - serviceEndpoint: "https://iota.org", - }; - doc.insertService(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 = 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()); - - // Log the results. - logExplorerUrl("Identity Update:", clientConfig.network.toString(), updateReceipt.messageId); - return { - key, - newKey, - doc, - originalMessageId: receipt.messageId, - updatedMessageId: updateReceipt.messageId, - }; -} - -exports.manipulateIdentity = manipulateIdentity; diff --git a/bindings/wasm/examples/node/merkle_key.js b/bindings/wasm/examples/node/merkle_key.js deleted file mode 100644 index 32df457b3e..0000000000 --- a/bindings/wasm/examples/node/merkle_key.js +++ /dev/null @@ -1,96 +0,0 @@ -// Copyright 2020-2021 IOTA Stiftung -// SPDX-License-Identifier: Apache-2.0 - -const { - Client, - Config, - Digest, - KeyType, - Timestamp, - VerifiableCredential, - VerificationMethod, - KeyCollection -} = require('../../node/identity_wasm') -const {createIdentity} = require('./create_did'); -const {logExplorerUrl} = require('./utils') - -/** - 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 - **/ -async function merkleKey(clientConfig) { - // Create a default client configuration from the parent config network. - const config = Config.fromNetwork(clientConfig.network); - - // Create a client instance to publish messages to the Tangle. - const client = Client.fromConfig(config); - - // Creates new identities (See "create_did" example) - const alice = await createIdentity(clientConfig); - const issuer = await createIdentity(clientConfig); - - // Add a Merkle Key Collection Verification Method with 8 keys (Must be a power of 2) - const keys = new KeyCollection(KeyType.Ed25519, 8); - const method = VerificationMethod.createMerkleKey(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 = 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()); - logExplorerUrl("Identity Update:", clientConfig.network.toString(), receipt.messageId); - - // 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 = 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(Digest.Sha256, 0) - }); - - // Check the verifiable credential is valid - const result = await client.checkCredential(signedVc.toString()); - console.log(`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 = Timestamp.nowUTC(); - issuer.doc.sign(issuer.key); - const nextReceipt = await client.publishDocument(issuer.doc.toJSON()); - logExplorerUrl("Identity Update:", clientConfig.network.toString(), nextReceipt.messageId); - - // Check the verifiable credential is revoked - const newResult = await client.checkCredential(signedVc.toString()); - console.log(`VC verification result (false = revoked): ${newResult.verified}`); - if (newResult.verified) throw new Error("VC not revoked"); -} - -exports.merkleKey = merkleKey; diff --git a/bindings/wasm/examples/node/node.js b/bindings/wasm/examples/node/node.js deleted file mode 100644 index d1e4b39935..0000000000 --- a/bindings/wasm/examples/node/node.js +++ /dev/null @@ -1,71 +0,0 @@ -// Copyright 2020-2021 IOTA Stiftung -// SPDX-License-Identifier: Apache-2.0 - -const {createIdentity} = require("./create_did"); -const {manipulateIdentity} = require("./manipulate_did"); -const {createIdentityPrivateTangle} = require("./private_tangle"); -const {resolution} = require("./resolution"); -const {createVC} = require("./create_vc"); -const {createVP} = require("./create_vp"); -const {revokeVC} = require("./revoke_vc"); -const {merkleKey} = require("./merkle_key"); -const {CLIENT_CONFIG} = require("./config"); -const {resolveHistory} = require("./resolve_history"); -const {createDiff} = require("./diff_chain"); - -async function main() { - //Check if an example is mentioned - if (process.argv.length != 3) { - throw "Please provide one command line argument with the example name."; - } - - //Take out the argument - let argument = process.argv[2]; - switch (argument) { - case "create_did": - return await createIdentity(CLIENT_CONFIG); - case "manipulate_did": - return await manipulateIdentity(CLIENT_CONFIG); - case "resolution": - return await resolution(CLIENT_CONFIG); - case "create_vc": - return await createVC(CLIENT_CONFIG); - case "revoke_vc": - return await revokeVC(CLIENT_CONFIG); - case "create_vp": - return await createVP(CLIENT_CONFIG); - case "merkle_key": - return await merkleKey(CLIENT_CONFIG); - case "private_tangle": - return await createIdentityPrivateTangle(); - case "resolve_history": - return await resolveHistory(CLIENT_CONFIG); - case "diff_chain": - return await createDiff(CLIENT_CONFIG); - case "all": - console.log(">>> Run All Examples"); - - await createIdentity(CLIENT_CONFIG); - await manipulateIdentity(CLIENT_CONFIG); - await resolution(CLIENT_CONFIG); - await createVC(CLIENT_CONFIG); - await revokeVC(CLIENT_CONFIG); - await createVP(CLIENT_CONFIG); - await merkleKey(CLIENT_CONFIG); - await resolveHistory(CLIENT_CONFIG); - await createDiff(CLIENT_CONFIG); - - console.log(">>> End All Examples"); - return "all"; - default: - throw "Unknown example name"; - } -} - -main() - .then((output) => { - console.log("Ok >", output); - }) - .catch((error) => { - console.log("Err >", error); - }); diff --git a/bindings/wasm/examples/node/private_tangle.js b/bindings/wasm/examples/node/private_tangle.js deleted file mode 100644 index a148b43095..0000000000 --- a/bindings/wasm/examples/node/private_tangle.js +++ /dev/null @@ -1,42 +0,0 @@ -// Copyright 2020-2021 IOTA Stiftung -// SPDX-License-Identifier: Apache-2.0 - -const { Client, Config, Document, KeyType, Network } = require('../../node/identity_wasm') - -/** - 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. -**/ -async function createIdentityPrivateTangle() { - // This is an arbitrarily defined network name - const network = Network.from_name("custom"); - - // 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 points to the REST API of the locally running hornet node. - config.setNode("http://127.0.0.1:14265/"); - - // 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()); - - // Make sure the DID can be resolved on the private tangle - const resolved = await client.resolve(doc.id.toString()); - - // Return the results. - return { key, resolved, receipt }; -} - -exports.createIdentityPrivateTangle = createIdentityPrivateTangle; diff --git a/bindings/wasm/examples/node/resolution.js b/bindings/wasm/examples/node/resolution.js deleted file mode 100644 index f4b74cb27d..0000000000 --- a/bindings/wasm/examples/node/resolution.js +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright 2020-2021 IOTA Stiftung -// SPDX-License-Identifier: Apache-2.0 - -const {Client, Config} = require('../../node/identity_wasm') -const {manipulateIdentity} = require("./manipulate_did"); - -/** - A short example to show how to resolve a DID. This returns the latest DID Document. - - @param {{defaultNodeURL: string, explorerURL: string, network: Network}} clientConfig - **/ -async function resolution(clientConfig) { - // Create a default client configuration from the parent config network. - const config = Config.fromNetwork(clientConfig.network); - - // Create a client instance to publish messages to the Tangle. - const client = Client.fromConfig(config); - - // Creates a new identity, that also is updated (See "manipulate_did" example). - const result = await manipulateIdentity(clientConfig); - - // Resolve a DID. - return await client.resolve(result.doc.id.toString()); -} - -exports.resolution = resolution; diff --git a/bindings/wasm/examples/node/resolve_history.js b/bindings/wasm/examples/node/resolve_history.js deleted file mode 100644 index 10e41233eb..0000000000 --- a/bindings/wasm/examples/node/resolve_history.js +++ /dev/null @@ -1,204 +0,0 @@ -// Copyright 2020-2021 IOTA Stiftung -// SPDX-License-Identifier: Apache-2.0 - -const {logExplorerUrl, prettyPrintJSON} = require("./utils"); -const { - Client, - Config, - Document, - Service, - KeyPair, - VerificationMethod, - KeyType, - Timestamp, DID -} = require("../../node/identity_wasm"); -const {createIdentity} = require("./create_did"); - -/** - 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 - **/ -async function resolveHistory(clientConfig) { - // Create a default client configuration from the parent config network. - const config = Config.fromNetwork(clientConfig.network); - - // Create a client instance to publish messages to the Tangle. - const client = Client.fromConfig(config); - - // =========================================================================== - // DID Creation - // =========================================================================== - - // Create a new identity (see "create_did.js" example). - const {doc, key, receipt: originalReceipt} = await createIdentity(clientConfig); - - // =========================================================================== - // 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 = Document.fromJSON(doc.toJSON()); // clone the Document - - // Add a new VerificationMethod with a new KeyPair, with the tag "keys-1" - const keys1 = new KeyPair(KeyType.Ed25519); - const method1 = 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 = 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. - logExplorerUrl("Int. Chain Update (1):", clientConfig.network.toString(), intReceipt1.messageId); - - // =========================================================================== - // Diff Chain Update 1 - // =========================================================================== - - // Prepare a diff chain DID Document update. - const diffDoc1 = 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(Service.fromJSON(serviceJSON1)); - diffDoc1.updated = 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); - logExplorerUrl("Diff Chain Transaction (1):", clientConfig.network.toString(), diffReceipt1.messageId); - - // =========================================================================== - // Diff Chain Update 2 - // =========================================================================== - - // Prepare another diff chain update. - const diffDoc2 = 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(Service.fromJSON(serviceJSON2)); - diffDoc2.updated = 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); - logExplorerUrl("Diff Chain Transaction (2):", clientConfig.network.toString(), 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 = 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. - prettyPrintJSON(history1, "History (1):"); - - // =========================================================================== - // Integration Chain Update 2 - // =========================================================================== - - // Publish a second integration chain update - let intDoc2 = Document.fromJSON(diffDoc2.toJSON()); - - // Remove the #keys-1 VerificationMethod - intDoc2.removeMethod(DID.parse(intDoc2.id.toString() + "#keys-1")); - - // Remove the #linked-domain-1 Service - intDoc2.removeService(DID.parse(intDoc2.id.toString() + "#linked-domain-1")); - - // Add a VerificationMethod with a new KeyPair, called "keys-2" - const keys2 = new KeyPair(KeyType.Ed25519); - const method2 = 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 = Timestamp.nowUTC(); - intDoc2.sign(key); - const intReceipt2 = await client.publishDocument(intDoc2.toJSON()); - - // Log the results. - logExplorerUrl("Int. Chain Update (2):", clientConfig.network.toString(), 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. - prettyPrintJSON(history2, "History (2):"); - - // =========================================================================== - // 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); - prettyPrintJSON(previousDiffHistory, "Previous Diff History:"); -} - -exports.resolveHistory = resolveHistory; diff --git a/bindings/wasm/examples/node/revoke_vc.js b/bindings/wasm/examples/node/revoke_vc.js deleted file mode 100644 index 46ac430859..0000000000 --- a/bindings/wasm/examples/node/revoke_vc.js +++ /dev/null @@ -1,50 +0,0 @@ -// Copyright 2020-2021 IOTA Stiftung -// SPDX-License-Identifier: Apache-2.0 - -const {Client, Config, DID, Timestamp} = require('../../node/identity_wasm') -const {createVC} = require('./create_vc'); -const {logExplorerUrl} = require('./utils') - -/** - 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 - **/ -async function revoke(clientConfig) { - // Create a default client configuration from the parent config network. - const config = Config.fromNetwork(clientConfig.network); - - // Create a client instance to publish messages to the Tangle. - const client = Client.fromConfig(config); - - // Creates new identities and a VC (see "create_vc" example) - const {alice, issuer, signedVc} = await createVC(clientConfig); - - // Remove the public key that signed the VC - effectively revoking the VC as it will no longer be able to verify - issuer.doc.removeMethod(DID.parse(issuer.doc.id.toString() + "#newKey")); - issuer.doc.previousMessageId = issuer.updatedMessageId; - issuer.doc.updated = 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 - logExplorerUrl("Issuer Identity Update:", clientConfig.network.toString(), messageId); - - // Check the verifiable credential - const result = await client.checkCredential(signedVc.toString()); - console.log(`VC verification result (false = revoked): ${result.verified}`); -} - -exports.revokeVC = revoke; diff --git a/bindings/wasm/examples/node/test.js b/bindings/wasm/examples/node/test.js deleted file mode 100644 index e557c6885b..0000000000 --- a/bindings/wasm/examples/node/test.js +++ /dev/null @@ -1,90 +0,0 @@ -const { createIdentity } = require("./create_did"); -const { manipulateIdentity } = require("./manipulate_did"); -const { resolution } = require("./resolution"); -const { createVC } = require("./create_vc"); -const { createVP } = require("./create_vp"); -const { createDiff } = require("./diff_chain"); -const { revokeVC } = require("./revoke_vc"); -const { merkleKey } = require("./merkle_key"); -const { resolveHistory } = require("./resolve_history"); -const { CLIENT_CONFIG } = require("./config"); -const { createIdentityPrivateTangle } = require("./private_tangle"); - -jest.setTimeout(180000); // 3 minutes to account for spurious network delays, most tests pass in a few seconds - -// Run all Node.js examples as jest tests in parallel. -// If a function throws an exception, it will run again to make the tests more consistent (less prone to network issues). -// Only verifies that no uncaught exceptions are thrown, including syntax errors etc. -test.concurrent("Create Identity", async () => { - try { - await createIdentity(CLIENT_CONFIG); - } catch (e) { - await createIdentity(CLIENT_CONFIG); - } -}); -test.concurrent("Manipulate Identity", async () => { - try { - await manipulateIdentity(CLIENT_CONFIG); - } catch (e) { - await manipulateIdentity(CLIENT_CONFIG); - } -}); -test.concurrent("Resolution", async () => { - try { - await resolution(CLIENT_CONFIG); - } catch (e) { - await resolution(CLIENT_CONFIG); - } -}); -test.concurrent("Create Verifiable Credential", async () => { - try { - await createVC(CLIENT_CONFIG); - } catch (e) { - await createVC(CLIENT_CONFIG); - } -}); -test.concurrent("Create Verifiable Presentation", async () => { - try { - await createVP(CLIENT_CONFIG); - } catch (e) { - await createVP(CLIENT_CONFIG); - } -}); -test.concurrent("Revoke Verifiable Credential", async () => { - try { - await revokeVC(CLIENT_CONFIG); - } catch (e) { - await revokeVC(CLIENT_CONFIG); - } -}); -test.concurrent("Merkle Key", async () => { - try { - await merkleKey(CLIENT_CONFIG); - } catch (e) { - await merkleKey(CLIENT_CONFIG); - } -}); -test.concurrent("Private Tangle", async () => { - try { - await createIdentityPrivateTangle() - throw new Error("Did not throw.") - } catch (err) { - // Example is expected to throw an error because no private Tangle is running - expect(err.name).toEqual("ClientError") - expect(err.message).toContain("error sending request") - } -}); -test.concurrent("Diff Chain", async () => { - try { - await createDiff(CLIENT_CONFIG); - } catch (e) { - await createDiff(CLIENT_CONFIG); - } -}); -test.concurrent("Resolve History", async () => { - try { - await resolveHistory(CLIENT_CONFIG); - } catch (e) { - await resolveHistory(CLIENT_CONFIG); - } -}); diff --git a/bindings/wasm/examples/node/utils.js b/bindings/wasm/examples/node/utils.js deleted file mode 100644 index 25362edd13..0000000000 --- a/bindings/wasm/examples/node/utils.js +++ /dev/null @@ -1,30 +0,0 @@ -// Copyright 2020-2021 IOTA Stiftung -// SPDX-License-Identifier: Apache-2.0 - -/** - Write out the Targle Explorer URL given the network and message ID, with the given preamble. - - @param {!string} preamble - @param {!string} network - @param {!string} messageId - **/ -function logExplorerUrl(preamble, network, messageId) { - console.log(`${preamble} https://explorer.iota.org/${network}net/transaction/${messageId}`); -} - -/** - Pretty-prints data to the console as a JSON string. This avoids nested fields being printed - as [Object], [Array] by converting it to a full JSON string first. - - @param {!Object} data - @param {!string | null} title - **/ -function prettyPrintJSON(data, title=null) { - if (title != null) { - console.log(title); - } - console.log(JSON.stringify(JSON.parse(data.toString()), null, 2)); -} - -exports.logExplorerUrl = logExplorerUrl; -exports.prettyPrintJSON = prettyPrintJSON; From 92d66f44294fa012c0d802ee2a0fb2b4365f53de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eike=20Ha=C3=9F?= Date: Thu, 26 Aug 2021 15:01:06 +0200 Subject: [PATCH 05/23] fixed node tests --- bindings/wasm/examples/src/test.js | 56 ++++++++++++------------ bindings/wasm/examples/webpack.config.js | 23 +++++++++- bindings/wasm/package.json | 2 +- 3 files changed, 50 insertions(+), 31 deletions(-) diff --git a/bindings/wasm/examples/src/test.js b/bindings/wasm/examples/src/test.js index e557c6885b..2d2c992eb6 100644 --- a/bindings/wasm/examples/src/test.js +++ b/bindings/wasm/examples/src/test.js @@ -1,14 +1,14 @@ -const { createIdentity } = require("./create_did"); -const { manipulateIdentity } = require("./manipulate_did"); -const { resolution } = require("./resolution"); -const { createVC } = require("./create_vc"); -const { createVP } = require("./create_vp"); -const { createDiff } = require("./diff_chain"); -const { revokeVC } = require("./revoke_vc"); -const { merkleKey } = require("./merkle_key"); -const { resolveHistory } = require("./resolve_history"); -const { CLIENT_CONFIG } = require("./config"); -const { createIdentityPrivateTangle } = require("./private_tangle"); +import { createIdentity } from "./create_did"; +import { manipulateIdentity } from "./manipulate_did"; +// import { resolution } from "./resolution"; +import { createVC } from "./create_vc"; +import { createVP } from "./create_vp"; +import { createDiff } from "./diff_chain"; +import { revokeVC } from "./revoke_vc"; +import { merkleKey } from "./merkle_key"; +import { resolveHistory } from "./resolve_history"; +import { CLIENT_CONFIG } from "./config"; +// import { createIdentityPrivateTangle } from "./private_tangle"; jest.setTimeout(180000); // 3 minutes to account for spurious network delays, most tests pass in a few seconds @@ -29,13 +29,13 @@ test.concurrent("Manipulate Identity", async () => { await manipulateIdentity(CLIENT_CONFIG); } }); -test.concurrent("Resolution", async () => { - try { - await resolution(CLIENT_CONFIG); - } catch (e) { - await resolution(CLIENT_CONFIG); - } -}); +// test.concurrent("Resolution", async () => { +// try { +// await resolution(CLIENT_CONFIG); +// } catch (e) { +// await resolution(CLIENT_CONFIG); +// } +// }); test.concurrent("Create Verifiable Credential", async () => { try { await createVC(CLIENT_CONFIG); @@ -64,16 +64,16 @@ test.concurrent("Merkle Key", async () => { await merkleKey(CLIENT_CONFIG); } }); -test.concurrent("Private Tangle", async () => { - try { - await createIdentityPrivateTangle() - throw new Error("Did not throw.") - } catch (err) { - // Example is expected to throw an error because no private Tangle is running - expect(err.name).toEqual("ClientError") - expect(err.message).toContain("error sending request") - } -}); +// test.concurrent("Private Tangle", async () => { +// try { +// await createIdentityPrivateTangle() +// throw new Error("Did not throw.") +// } catch (err) { +// // Example is expected to throw an error because no private Tangle is running +// expect(err.name).toEqual("ClientError") +// expect(err.message).toContain("error sending request") +// } +// }); test.concurrent("Diff Chain", async () => { try { await createDiff(CLIENT_CONFIG); diff --git a/bindings/wasm/examples/webpack.config.js b/bindings/wasm/examples/webpack.config.js index 0f20cfa5b0..d0c023c4f7 100644 --- a/bindings/wasm/examples/webpack.config.js +++ b/bindings/wasm/examples/webpack.config.js @@ -20,7 +20,26 @@ const serverConfig = { externals: [ function ({ context, request }, callback) { if (/^@iota\/identity-wasm$/.test(request)) { - console.log(request); + // Externalize to a commonjs module + return callback(null, 'commonjs ' + path.resolve(__dirname, '../node/identity_wasm.js')); + } + + // Continue without externalizing the import + callback(); + }, + ], +}; + +const serverTestConfig = { + target: 'node', + entry: './examples/src/test.js', + output: { + path: path.resolve(__dirname, 'dist'), + filename: 'test.js', + }, + externals: [ + function ({ context, request }, callback) { + if (/^@iota\/identity-wasm$/.test(request)) { // Externalize to a commonjs module return callback(null, 'commonjs ' + path.resolve(__dirname, '../node/identity_wasm.js')); } @@ -48,4 +67,4 @@ const clientConfig = { }, }; -module.exports = [serverConfig, clientConfig]; \ No newline at end of file +module.exports = [serverConfig, serverTestConfig, clientConfig]; \ No newline at end of file diff --git a/bindings/wasm/package.json b/bindings/wasm/package.json index e537aefd19..e88a5bb2c1 100644 --- a/bindings/wasm/package.json +++ b/bindings/wasm/package.json @@ -20,7 +20,7 @@ "serve": "webpack serve", "example:node": "node examples/node/node.js", "example:browser": "http-server -c-1 -o ./examples/dist/index.html", - "test:node": "jest", + "test:node": "jest dist/test.js", "test:browser": "cypress run --headless", "test:readme": "txm README.md", "cypress": "cypress open" From e4ee6771badd2fa2eade97c985b18f6306d7aa1b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eike=20Ha=C3=9F?= Date: Thu, 26 Aug 2021 16:19:29 +0200 Subject: [PATCH 06/23] copy index.html to dist --- bindings/wasm/examples/src/index.html | 76 ++++++++++++++++++++++++ bindings/wasm/examples/webpack.config.js | 10 ++++ 2 files changed, 86 insertions(+) create mode 100644 bindings/wasm/examples/src/index.html diff --git a/bindings/wasm/examples/src/index.html b/bindings/wasm/examples/src/index.html new file mode 100644 index 0000000000..d63620ad1b --- /dev/null +++ b/bindings/wasm/examples/src/index.html @@ -0,0 +1,76 @@ + + + + + + WASM Examples Browser + + + + + + + +
+ + +
+ + + + + + + + + + +
+ + + +
+ + + + + + + +

Output:

+
+ + \ No newline at end of file diff --git a/bindings/wasm/examples/webpack.config.js b/bindings/wasm/examples/webpack.config.js index d0c023c4f7..887c8b3753 100644 --- a/bindings/wasm/examples/webpack.config.js +++ b/bindings/wasm/examples/webpack.config.js @@ -65,6 +65,16 @@ const clientConfig = { '@iota/identity-wasm': path.resolve(__dirname, '../web/identity_wasm.js'), }, }, + plugins: [ + new CopyWebPlugin({ + patterns: [ + { + from: path.resolve(__dirname, "./src/index.html"), + to: path.resolve(__dirname, "dist"), + } + ] + }), + ], }; module.exports = [serverConfig, serverTestConfig, clientConfig]; \ No newline at end of file From 8c314069aae3f422ebfc7599de1014b1d75caf3a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eike=20Ha=C3=9F?= Date: Thu, 26 Aug 2021 17:19:31 +0200 Subject: [PATCH 07/23] enable all examples --- bindings/wasm/examples/src/node.js | 4 +-- bindings/wasm/examples/src/private_tangle.js | 11 ++++---- bindings/wasm/examples/src/resolution.js | 19 ++++++++----- bindings/wasm/examples/src/web.js | 28 +++++++++++++------- 4 files changed, 38 insertions(+), 24 deletions(-) diff --git a/bindings/wasm/examples/src/node.js b/bindings/wasm/examples/src/node.js index 27c82c2922..629da0cc58 100644 --- a/bindings/wasm/examples/src/node.js +++ b/bindings/wasm/examples/src/node.js @@ -3,8 +3,8 @@ import {createIdentity} from "./create_did"; import {manipulateIdentity} from "./manipulate_did"; -//const {createIdentityPrivateTangle} = require("./private_tangle"); -// const {resolution} = require("./resolution"); +import {createIdentityPrivateTangle} from "./private_tangle"; +import {resolution} from "./resolution"; import {createVC} from "./create_vc"; import {createVP} from "./create_vp"; import {revokeVC} from "./revoke_vc"; diff --git a/bindings/wasm/examples/src/private_tangle.js b/bindings/wasm/examples/src/private_tangle.js index a148b43095..973d1cbe2c 100644 --- a/bindings/wasm/examples/src/private_tangle.js +++ b/bindings/wasm/examples/src/private_tangle.js @@ -1,7 +1,7 @@ // Copyright 2020-2021 IOTA Stiftung // SPDX-License-Identifier: Apache-2.0 -const { Client, Config, Document, KeyType, Network } = require('../../node/identity_wasm') +import { Client, Config, Document, KeyType, Network } from '@iota/identity-wasm'; /** This example shows how a DID document can be created on a private tangle. @@ -9,9 +9,10 @@ const { Client, Config, Document, KeyType, Network } = require('../../node/ident Refer to https://github.com/iotaledger/one-click-tangle/tree/chrysalis/hornet-private-net for setup instructions. **/ -async function createIdentityPrivateTangle() { +async function createIdentityPrivateTangle(restURL, networkName) { + // This is an arbitrarily defined network name - const network = Network.from_name("custom"); + const network = Network.from_name(networkName ?? "custom"); // Create a DID Document (an identity). const { doc, key } = new Document(KeyType.Ed25519, network.toString()); @@ -24,7 +25,7 @@ async function createIdentityPrivateTangle() { config.setNetwork(network); // This URL points to the REST API of the locally running hornet node. - config.setNode("http://127.0.0.1:14265/"); + config.setNode(restURL ?? "http://127.0.0.1:14265/"); // Create a client instance from the configuration to publish messages to the Tangle. const client = Client.fromConfig(config); @@ -39,4 +40,4 @@ async function createIdentityPrivateTangle() { return { key, resolved, receipt }; } -exports.createIdentityPrivateTangle = createIdentityPrivateTangle; +export {createIdentityPrivateTangle}; diff --git a/bindings/wasm/examples/src/resolution.js b/bindings/wasm/examples/src/resolution.js index f4b74cb27d..995cdffbe6 100644 --- a/bindings/wasm/examples/src/resolution.js +++ b/bindings/wasm/examples/src/resolution.js @@ -1,26 +1,31 @@ // Copyright 2020-2021 IOTA Stiftung // SPDX-License-Identifier: Apache-2.0 -const {Client, Config} = require('../../node/identity_wasm') -const {manipulateIdentity} = require("./manipulate_did"); +import {Client, Config} from '@iota/identity-wasm'; +import {manipulateIdentity} from "./manipulate_did"; /** 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 {string} did **/ -async function resolution(clientConfig) { +async function resolution(clientConfig, did) { // Create a default client configuration from the parent config network. const config = Config.fromNetwork(clientConfig.network); // Create a client instance to publish messages to the Tangle. const client = Client.fromConfig(config); - // Creates a new identity, that also is updated (See "manipulate_did" example). - const result = await manipulateIdentity(clientConfig); + let newDid; + if(!did) { + // Creates a new identity, that also is updated (See "manipulate_did" example). + newDid = await manipulateIdentity(clientConfig); + } + // Resolve a DID. - return await client.resolve(result.doc.id.toString()); + return await client.resolve(did ?? newDid.doc.id.toString()); } -exports.resolution = resolution; +export {resolution}; diff --git a/bindings/wasm/examples/src/web.js b/bindings/wasm/examples/src/web.js index e9a5e3828a..b4240b7af7 100644 --- a/bindings/wasm/examples/src/web.js +++ b/bindings/wasm/examples/src/web.js @@ -2,11 +2,11 @@ import { initIdentity, defaultClientConfig, setupDOMLog } from "./utils_web.js"; import { createIdentity } from "./create_did.js"; import { createVC } from "./create_vc.js"; import { manipulateIdentity } from "./manipulate_did.js"; -//import { resolveIdentity } from "./resolve.js"; +import { resolution } from "./resolution.js"; import { createVP } from "./create_vp.js"; import { revokeVC } from "./revoke_vc.js"; import { merkleKey } from "./merkle_key.js"; -// import { createIdentityPrivateTangle } from "./private_tangle.js"; +import { createIdentityPrivateTangle } from "./private_tangle.js"; import { createDiff } from "./diff_chain.js"; import { resolveHistory } from "./resolve_history.js"; @@ -20,10 +20,14 @@ document .querySelector("#create-identity-btn") .addEventListener("click", () => createIdentity(CLIENT_CONFIG)); -// //handle resolve DID on click event -// document -// .querySelector("#resolve-did-btn") -// .addEventListener("click", () => resolveIdentity(CLIENT_CONFIG)); +//handle resolve DID on click event +document + .querySelector("#resolve-did-btn") + .addEventListener("click", async () => { + const inputDid = document.querySelector("#resolve-did-input").value; + const result = await resolution(CLIENT_CONFIG, inputDid); + console.log(result); + }); //handle manipulate DID on click event document @@ -50,10 +54,14 @@ document .querySelector("#merkle_key_btn") .addEventListener("click", () => merkleKey(CLIENT_CONFIG)); -// //handle private tangle DID creation on click event -// document -// .querySelector("#private_tangle_btn") -// .addEventListener("click", () => createIdentityPrivateTangle()); +//handle private tangle DID creation on click event +document + .querySelector("#private_tangle_btn") + .addEventListener("click", () => { + const restURL = document.querySelector("#create-private-rest-url").value; + const networkName = document.querySelector("#create-private-network-name").value; + createIdentityPrivateTangle(restURL, networkName); + }); //handle diff chain on click event document From 4e3f49d3a81a67ee569c104b82d5dcbcbb8eb9e8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eike=20Ha=C3=9F?= Date: Thu, 26 Aug 2021 17:25:42 +0200 Subject: [PATCH 08/23] changed example server root --- bindings/wasm/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bindings/wasm/package.json b/bindings/wasm/package.json index e88a5bb2c1..dacfcdce70 100644 --- a/bindings/wasm/package.json +++ b/bindings/wasm/package.json @@ -19,7 +19,7 @@ "prepublishOnly": "npm run build", "serve": "webpack serve", "example:node": "node examples/node/node.js", - "example:browser": "http-server -c-1 -o ./examples/dist/index.html", + "example:browser": "http-server ./examples/dist/ -c-1 -o ", "test:node": "jest dist/test.js", "test:browser": "cypress run --headless", "test:readme": "txm README.md", From 4ef4095555f545c5a4d0928a10e030ed7650fb41 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eike=20Ha=C3=9F?= Date: Tue, 31 Aug 2021 11:52:09 +0200 Subject: [PATCH 09/23] fixed browser test --- .../wasm/cypress/integration/browser_test.js | 56 ++-- bindings/wasm/examples/src/utils_web.js | 4 +- bindings/wasm/examples/src/web.js | 108 +++---- bindings/wasm/examples/webpack.config.js | 52 ++-- bindings/wasm/package-lock.json | 276 +++++++++--------- bindings/wasm/package.json | 2 +- 6 files changed, 242 insertions(+), 256 deletions(-) diff --git a/bindings/wasm/cypress/integration/browser_test.js b/bindings/wasm/cypress/integration/browser_test.js index 6e38f7db65..ce0d0098af 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, resolveIdentity, createVP, createDiff, revoke, 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,9 +21,9 @@ 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"); @@ -39,55 +31,55 @@ describe( 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 resolveIdentity(defaultClientConfig()); } catch (e) { - await resolveIdentity(defaultClientConfig(), false, false); + await resolveIdentity(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 revoke(defaultClientConfig()); } catch (e) { - await revoke(defaultClientConfig(), false); + await revoke(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/src/utils_web.js b/bindings/wasm/examples/src/utils_web.js index e4d99c8a50..62f68a56d2 100644 --- a/bindings/wasm/examples/src/utils_web.js +++ b/bindings/wasm/examples/src/utils_web.js @@ -7,13 +7,13 @@ export const LINK_REGEX = /(\b(https?|ftp):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0 * * @returns {Promise} */ -export async function initIdentity(path = "../../web/identity_wasm_bg.wasm") { +export async function initIdentity(path = "./../something/identity_wasm_bg.wasm") { console.log("Initialization started..."); try { await identity.init(path); console.log("Initialization success!"); } catch (err) { - console.error(err); + throw new Error(err); } } diff --git a/bindings/wasm/examples/src/web.js b/bindings/wasm/examples/src/web.js index b4240b7af7..90a9a31aa2 100644 --- a/bindings/wasm/examples/src/web.js +++ b/bindings/wasm/examples/src/web.js @@ -10,65 +10,71 @@ import { createIdentityPrivateTangle } from "./private_tangle.js"; import { createDiff } from "./diff_chain.js"; import { resolveHistory } from "./resolve_history.js"; -setupDOMLog(); +export { initIdentity, defaultClientConfig, createIdentity, createVC, manipulateIdentity, resolution, createVP, revokeVC, merkleKey, createIdentityPrivateTangle, createDiff, resolveHistory }; -await initIdentity(); -const CLIENT_CONFIG = defaultClientConfig(); +window.onload = async() => { -//handle create identity on click event -document - .querySelector("#create-identity-btn") - .addEventListener("click", () => createIdentity(CLIENT_CONFIG)); + setupDOMLog(); -//handle resolve DID on click event -document - .querySelector("#resolve-did-btn") - .addEventListener("click", async () => { - const inputDid = document.querySelector("#resolve-did-input").value; - const result = await resolution(CLIENT_CONFIG, inputDid); - console.log(result); - }); + await initIdentity(); + const CLIENT_CONFIG = defaultClientConfig(); -//handle manipulate DID on click event -document - .querySelector("#manipulate_did_btn") - .addEventListener("click", () => manipulateIdentity(CLIENT_CONFIG)); + //handle create identity on click event + document + .querySelector("#create-identity-btn") + .addEventListener("click", () => createIdentity(CLIENT_CONFIG)); -//handle create VC on click event -document - .querySelector("#create_vc_btn") - .addEventListener("click", () => createVC(CLIENT_CONFIG)); + //handle resolve DID on click event + document + .querySelector("#resolve-did-btn") + .addEventListener("click", async () => { + const inputDid = document.querySelector("#resolve-did-input").value; + const result = await resolution(CLIENT_CONFIG, inputDid); + console.log(result); + }); -//handle create VP on click event -document - .querySelector("#create_vp_btn") - .addEventListener("click", () => createVP(CLIENT_CONFIG)); + //handle manipulate DID on click event + document + .querySelector("#manipulate_did_btn") + .addEventListener("click", () => manipulateIdentity(CLIENT_CONFIG)); -//handle revoke VC on click event -document - .querySelector("#revoke_vc_btn") - .addEventListener("click", () => revokeVC(CLIENT_CONFIG)); + //handle create VC on click event + document + .querySelector("#create_vc_btn") + .addEventListener("click", () => createVC(CLIENT_CONFIG)); -//handle merkle key on click event -document - .querySelector("#merkle_key_btn") - .addEventListener("click", () => merkleKey(CLIENT_CONFIG)); + //handle create VP on click event + document + .querySelector("#create_vp_btn") + .addEventListener("click", () => createVP(CLIENT_CONFIG)); -//handle private tangle DID creation on click event -document - .querySelector("#private_tangle_btn") - .addEventListener("click", () => { - const restURL = document.querySelector("#create-private-rest-url").value; - const networkName = document.querySelector("#create-private-network-name").value; - createIdentityPrivateTangle(restURL, networkName); - }); + //handle revoke VC on click event + document + .querySelector("#revoke_vc_btn") + .addEventListener("click", () => revokeVC(CLIENT_CONFIG)); -//handle diff chain on click event -document - .querySelector("#diff_chain_btn") - .addEventListener("click", () => createDiff(CLIENT_CONFIG)); + //handle merkle key on click event + document + .querySelector("#merkle_key_btn") + .addEventListener("click", () => merkleKey(CLIENT_CONFIG)); -//handle resolve history on click event -document -.querySelector("#did_history_btn") -.addEventListener("click", () => resolveHistory(CLIENT_CONFIG)); + //handle private tangle DID creation on click event + document + .querySelector("#private_tangle_btn") + .addEventListener("click", () => { + const restURL = document.querySelector("#create-private-rest-url").value; + const networkName = document.querySelector("#create-private-network-name").value; + createIdentityPrivateTangle(restURL, networkName); + }); + + //handle diff chain on click event + document + .querySelector("#diff_chain_btn") + .addEventListener("click", () => createDiff(CLIENT_CONFIG)); + + //handle resolve history on click event + document + .querySelector("#did_history_btn") + .addEventListener("click", () => resolveHistory(CLIENT_CONFIG)); + +}; \ No newline at end of file diff --git a/bindings/wasm/examples/webpack.config.js b/bindings/wasm/examples/webpack.config.js index 887c8b3753..75bdf9b766 100644 --- a/bindings/wasm/examples/webpack.config.js +++ b/bindings/wasm/examples/webpack.config.js @@ -7,27 +7,17 @@ const serverConfig = { path: path.resolve(__dirname, 'dist'), filename: 'node.js', }, - plugins: [ - new CopyWebPlugin({ - patterns: [ - { - from: path.resolve(__dirname, "../node/identity_wasm_bg.wasm"), - to: path.resolve(__dirname, "dist"), - } - ] - }), - ], externals: [ function ({ context, request }, callback) { - if (/^@iota\/identity-wasm$/.test(request)) { - // Externalize to a commonjs module - return callback(null, 'commonjs ' + path.resolve(__dirname, '../node/identity_wasm.js')); - } - - // Continue without externalizing the import - callback(); + if (/^@iota\/identity-wasm$/.test(request)) { + // Externalize to a commonjs module + return callback(null, 'commonjs ' + path.resolve(__dirname, '../node/identity_wasm.js')); + } + + // Continue without externalizing the import + callback(); }, - ], + ], }; const serverTestConfig = { @@ -39,15 +29,15 @@ const serverTestConfig = { }, externals: [ function ({ context, request }, callback) { - if (/^@iota\/identity-wasm$/.test(request)) { - // Externalize to a commonjs module - return callback(null, 'commonjs ' + path.resolve(__dirname, '../node/identity_wasm.js')); - } - - // Continue without externalizing the import - callback(); + if (/^@iota\/identity-wasm$/.test(request)) { + // Externalize to a commonjs module + return callback(null, 'commonjs ' + path.resolve(__dirname, '../node/identity_wasm.js')); + } + + // Continue without externalizing the import + callback(); }, - ], + ], }; const clientConfig = { @@ -56,9 +46,13 @@ const clientConfig = { output: { path: path.resolve(__dirname, 'dist'), filename: 'web.js', + library: { + type: 'module', + }, }, experiments: { topLevelAwait: true, + outputModule: true, }, resolve: { alias: { @@ -71,8 +65,14 @@ const clientConfig = { { from: path.resolve(__dirname, "./src/index.html"), to: path.resolve(__dirname, "dist"), + }, + + { + from: path.resolve(__dirname, "../web/identity_wasm_bg.wasm"), + to: path.resolve(__dirname, "dist"), } ] + }), ], }; diff --git a/bindings/wasm/package-lock.json b/bindings/wasm/package-lock.json index 25a3e47c10..724cc7f6f2 100644 --- a/bindings/wasm/package-lock.json +++ b/bindings/wasm/package-lock.json @@ -421,9 +421,9 @@ "dev": true }, "@cypress/request": { - "version": "2.88.5", - "resolved": "https://registry.npmjs.org/@cypress/request/-/request-2.88.5.tgz", - "integrity": "sha512-TzEC1XMi1hJkywWpRfD2clreTa/Z+lOrXDCxxBTBPEcY5azdPi56A6Xw+O4tWJnaJH3iIE7G5aDXZC6JgRZLcA==", + "version": "2.88.6", + "resolved": "https://registry.npmjs.org/@cypress/request/-/request-2.88.6.tgz", + "integrity": "sha512-z0UxBE/+qaESAHY9p9sM2h8Y4XqtsbDCt0/DPOrqA/RZgKi4PkxdpXyK4wCCnSk1xHqWHZZAE+gV6aDAR6+caQ==", "dev": true, "requires": { "aws-sign2": "~0.7.0", @@ -439,13 +439,12 @@ "isstream": "~0.1.2", "json-stringify-safe": "~5.0.1", "mime-types": "~2.1.19", - "oauth-sign": "~0.9.0", "performance-now": "^2.1.0", "qs": "~6.5.2", "safe-buffer": "^5.1.2", "tough-cookie": "~2.5.0", "tunnel-agent": "^0.6.0", - "uuid": "^3.3.2" + "uuid": "^8.3.2" }, "dependencies": { "qs": { @@ -453,6 +452,12 @@ "resolved": "https://registry.npmjs.org/qs/-/qs-6.5.2.tgz", "integrity": "sha512-N5ZAX4/LxJmF+7wN74pUD6qAh9/wnvdQcjq9TZjevvXzSUo7bfmw91saqMjzGS2xq91/odN2dW/WOl7qQHNDGA==", "dev": true + }, + "uuid": { + "version": "8.3.2", + "resolved": "https://registry.npmjs.org/uuid/-/uuid-8.3.2.tgz", + "integrity": "sha512-+NYs2QeMWy+GWFOEm9xnn6HCDp0l7QBD7ml8zLUmJ+93Q5NF0NocErnwkTkXVFNiX3/fpC6afS8Dhb/gz7R7eg==", + "dev": true } } }, @@ -1101,9 +1106,9 @@ } }, "@types/eslint": { - "version": "7.2.13", - "resolved": "https://registry.npmjs.org/@types/eslint/-/eslint-7.2.13.tgz", - "integrity": "sha512-LKmQCWAlnVHvvXq4oasNUMTJJb2GwSyTY8+1C7OH5ILR8mPLaljv1jxL1bXW3xB3jFbQxTKxJAvI8PyjB09aBg==", + "version": "7.28.0", + "resolved": "https://registry.npmjs.org/@types/eslint/-/eslint-7.28.0.tgz", + "integrity": "sha512-07XlgzX0YJUn4iG1ocY4IX9DzKSmMGUs6ESKlxWhZRaa0fatIWaHWUVapcuGa8r5HFnTqzj+4OCjd5f7EZ/i/A==", "dev": true, "requires": { "@types/estree": "*", @@ -1111,9 +1116,9 @@ } }, "@types/eslint-scope": { - "version": "3.7.0", - "resolved": "https://registry.npmjs.org/@types/eslint-scope/-/eslint-scope-3.7.0.tgz", - "integrity": "sha512-O/ql2+rrCUe2W2rs7wMR+GqPRcgB6UiqN5RhrR5xruFlY7l9YLMn0ZkDzjoHLeiFkR8MCQZVudUuuvQ2BLC9Qw==", + "version": "3.7.1", + "resolved": "https://registry.npmjs.org/@types/eslint-scope/-/eslint-scope-3.7.1.tgz", + "integrity": "sha512-SCFeogqiptms4Fg29WpOTk5nHIzfpKCemSN63ksBQYKTcXoJEmJagV+DhVmbapZzY4/5YaOV1nZwrsU79fFm1g==", "dev": true, "requires": { "@types/eslint": "*", @@ -1121,9 +1126,9 @@ } }, "@types/estree": { - "version": "0.0.48", - "resolved": "https://registry.npmjs.org/@types/estree/-/estree-0.0.48.tgz", - "integrity": "sha512-LfZwXoGUDo0C3me81HXgkBg5CTQYb6xzEl+fNmbO4JdRiSKQ8A0GD1OBBvKAIsbCUgoyAty7m99GqqMQe784ew==", + "version": "0.0.50", + "resolved": "https://registry.npmjs.org/@types/estree/-/estree-0.0.50.tgz", + "integrity": "sha512-C6N5s2ZFtuZRj54k2/zyRhNDjJwwcViAM3Nbm8zjBpbqAdZ00mr0CFxvSKeO8Y/e03WVFLpQMdHYVfUd6SB+Hw==", "dev": true }, "@types/glob": { @@ -1249,148 +1254,148 @@ } }, "@webassemblyjs/ast": { - "version": "1.11.0", - "resolved": "https://registry.npmjs.org/@webassemblyjs/ast/-/ast-1.11.0.tgz", - "integrity": "sha512-kX2W49LWsbthrmIRMbQZuQDhGtjyqXfEmmHyEi4XWnSZtPmxY0+3anPIzsnRb45VH/J55zlOfWvZuY47aJZTJg==", + "version": "1.11.1", + "resolved": "https://registry.npmjs.org/@webassemblyjs/ast/-/ast-1.11.1.tgz", + "integrity": "sha512-ukBh14qFLjxTQNTXocdyksN5QdM28S1CxHt2rdskFyL+xFV7VremuBLVbmCePj+URalXBENx/9Lm7lnhihtCSw==", "dev": true, "requires": { - "@webassemblyjs/helper-numbers": "1.11.0", - "@webassemblyjs/helper-wasm-bytecode": "1.11.0" + "@webassemblyjs/helper-numbers": "1.11.1", + "@webassemblyjs/helper-wasm-bytecode": "1.11.1" } }, "@webassemblyjs/floating-point-hex-parser": { - "version": "1.11.0", - "resolved": "https://registry.npmjs.org/@webassemblyjs/floating-point-hex-parser/-/floating-point-hex-parser-1.11.0.tgz", - "integrity": "sha512-Q/aVYs/VnPDVYvsCBL/gSgwmfjeCb4LW8+TMrO3cSzJImgv8lxxEPM2JA5jMrivE7LSz3V+PFqtMbls3m1exDA==", + "version": "1.11.1", + "resolved": "https://registry.npmjs.org/@webassemblyjs/floating-point-hex-parser/-/floating-point-hex-parser-1.11.1.tgz", + "integrity": "sha512-iGRfyc5Bq+NnNuX8b5hwBrRjzf0ocrJPI6GWFodBFzmFnyvrQ83SHKhmilCU/8Jv67i4GJZBMhEzltxzcNagtQ==", "dev": true }, "@webassemblyjs/helper-api-error": { - "version": "1.11.0", - "resolved": "https://registry.npmjs.org/@webassemblyjs/helper-api-error/-/helper-api-error-1.11.0.tgz", - "integrity": "sha512-baT/va95eXiXb2QflSx95QGT5ClzWpGaa8L7JnJbgzoYeaA27FCvuBXU758l+KXWRndEmUXjP0Q5fibhavIn8w==", + "version": "1.11.1", + "resolved": "https://registry.npmjs.org/@webassemblyjs/helper-api-error/-/helper-api-error-1.11.1.tgz", + "integrity": "sha512-RlhS8CBCXfRUR/cwo2ho9bkheSXG0+NwooXcc3PAILALf2QLdFyj7KGsKRbVc95hZnhnERon4kW/D3SZpp6Tcg==", "dev": true }, "@webassemblyjs/helper-buffer": { - "version": "1.11.0", - "resolved": "https://registry.npmjs.org/@webassemblyjs/helper-buffer/-/helper-buffer-1.11.0.tgz", - "integrity": "sha512-u9HPBEl4DS+vA8qLQdEQ6N/eJQ7gT7aNvMIo8AAWvAl/xMrcOSiI2M0MAnMCy3jIFke7bEee/JwdX1nUpCtdyA==", + "version": "1.11.1", + "resolved": "https://registry.npmjs.org/@webassemblyjs/helper-buffer/-/helper-buffer-1.11.1.tgz", + "integrity": "sha512-gwikF65aDNeeXa8JxXa2BAk+REjSyhrNC9ZwdT0f8jc4dQQeDQ7G4m0f2QCLPJiMTTO6wfDmRmj/pW0PsUvIcA==", "dev": true }, "@webassemblyjs/helper-numbers": { - "version": "1.11.0", - "resolved": "https://registry.npmjs.org/@webassemblyjs/helper-numbers/-/helper-numbers-1.11.0.tgz", - "integrity": "sha512-DhRQKelIj01s5IgdsOJMKLppI+4zpmcMQ3XboFPLwCpSNH6Hqo1ritgHgD0nqHeSYqofA6aBN/NmXuGjM1jEfQ==", + "version": "1.11.1", + "resolved": "https://registry.npmjs.org/@webassemblyjs/helper-numbers/-/helper-numbers-1.11.1.tgz", + "integrity": "sha512-vDkbxiB8zfnPdNK9Rajcey5C0w+QJugEglN0of+kmO8l7lDb77AnlKYQF7aarZuCrv+l0UvqL+68gSDr3k9LPQ==", "dev": true, "requires": { - "@webassemblyjs/floating-point-hex-parser": "1.11.0", - "@webassemblyjs/helper-api-error": "1.11.0", + "@webassemblyjs/floating-point-hex-parser": "1.11.1", + "@webassemblyjs/helper-api-error": "1.11.1", "@xtuc/long": "4.2.2" } }, "@webassemblyjs/helper-wasm-bytecode": { - "version": "1.11.0", - "resolved": "https://registry.npmjs.org/@webassemblyjs/helper-wasm-bytecode/-/helper-wasm-bytecode-1.11.0.tgz", - "integrity": "sha512-MbmhvxXExm542tWREgSFnOVo07fDpsBJg3sIl6fSp9xuu75eGz5lz31q7wTLffwL3Za7XNRCMZy210+tnsUSEA==", + "version": "1.11.1", + "resolved": "https://registry.npmjs.org/@webassemblyjs/helper-wasm-bytecode/-/helper-wasm-bytecode-1.11.1.tgz", + "integrity": "sha512-PvpoOGiJwXeTrSf/qfudJhwlvDQxFgelbMqtq52WWiXC6Xgg1IREdngmPN3bs4RoO83PnL/nFrxucXj1+BX62Q==", "dev": true }, "@webassemblyjs/helper-wasm-section": { - "version": "1.11.0", - "resolved": "https://registry.npmjs.org/@webassemblyjs/helper-wasm-section/-/helper-wasm-section-1.11.0.tgz", - "integrity": "sha512-3Eb88hcbfY/FCukrg6i3EH8H2UsD7x8Vy47iVJrP967A9JGqgBVL9aH71SETPx1JrGsOUVLo0c7vMCN22ytJew==", + "version": "1.11.1", + "resolved": "https://registry.npmjs.org/@webassemblyjs/helper-wasm-section/-/helper-wasm-section-1.11.1.tgz", + "integrity": "sha512-10P9No29rYX1j7F3EVPX3JvGPQPae+AomuSTPiF9eBQeChHI6iqjMIwR9JmOJXwpnn/oVGDk7I5IlskuMwU/pg==", "dev": true, "requires": { - "@webassemblyjs/ast": "1.11.0", - "@webassemblyjs/helper-buffer": "1.11.0", - "@webassemblyjs/helper-wasm-bytecode": "1.11.0", - "@webassemblyjs/wasm-gen": "1.11.0" + "@webassemblyjs/ast": "1.11.1", + "@webassemblyjs/helper-buffer": "1.11.1", + "@webassemblyjs/helper-wasm-bytecode": "1.11.1", + "@webassemblyjs/wasm-gen": "1.11.1" } }, "@webassemblyjs/ieee754": { - "version": "1.11.0", - "resolved": "https://registry.npmjs.org/@webassemblyjs/ieee754/-/ieee754-1.11.0.tgz", - "integrity": "sha512-KXzOqpcYQwAfeQ6WbF6HXo+0udBNmw0iXDmEK5sFlmQdmND+tr773Ti8/5T/M6Tl/413ArSJErATd8In3B+WBA==", + "version": "1.11.1", + "resolved": "https://registry.npmjs.org/@webassemblyjs/ieee754/-/ieee754-1.11.1.tgz", + "integrity": "sha512-hJ87QIPtAMKbFq6CGTkZYJivEwZDbQUgYd3qKSadTNOhVY7p+gfP6Sr0lLRVTaG1JjFj+r3YchoqRYxNH3M0GQ==", "dev": true, "requires": { "@xtuc/ieee754": "^1.2.0" } }, "@webassemblyjs/leb128": { - "version": "1.11.0", - "resolved": "https://registry.npmjs.org/@webassemblyjs/leb128/-/leb128-1.11.0.tgz", - "integrity": "sha512-aqbsHa1mSQAbeeNcl38un6qVY++hh8OpCOzxhixSYgbRfNWcxJNJQwe2rezK9XEcssJbbWIkblaJRwGMS9zp+g==", + "version": "1.11.1", + "resolved": "https://registry.npmjs.org/@webassemblyjs/leb128/-/leb128-1.11.1.tgz", + "integrity": "sha512-BJ2P0hNZ0u+Th1YZXJpzW6miwqQUGcIHT1G/sf72gLVD9DZ5AdYTqPNbHZh6K1M5VmKvFXwGSWZADz+qBWxeRw==", "dev": true, "requires": { "@xtuc/long": "4.2.2" } }, "@webassemblyjs/utf8": { - "version": "1.11.0", - "resolved": "https://registry.npmjs.org/@webassemblyjs/utf8/-/utf8-1.11.0.tgz", - "integrity": "sha512-A/lclGxH6SpSLSyFowMzO/+aDEPU4hvEiooCMXQPcQFPPJaYcPQNKGOCLUySJsYJ4trbpr+Fs08n4jelkVTGVw==", + "version": "1.11.1", + "resolved": "https://registry.npmjs.org/@webassemblyjs/utf8/-/utf8-1.11.1.tgz", + "integrity": "sha512-9kqcxAEdMhiwQkHpkNiorZzqpGrodQQ2IGrHHxCy+Ozng0ofyMA0lTqiLkVs1uzTRejX+/O0EOT7KxqVPuXosQ==", "dev": true }, "@webassemblyjs/wasm-edit": { - "version": "1.11.0", - "resolved": "https://registry.npmjs.org/@webassemblyjs/wasm-edit/-/wasm-edit-1.11.0.tgz", - "integrity": "sha512-JHQ0damXy0G6J9ucyKVXO2j08JVJ2ntkdJlq1UTiUrIgfGMmA7Ik5VdC/L8hBK46kVJgujkBIoMtT8yVr+yVOQ==", + "version": "1.11.1", + "resolved": "https://registry.npmjs.org/@webassemblyjs/wasm-edit/-/wasm-edit-1.11.1.tgz", + "integrity": "sha512-g+RsupUC1aTHfR8CDgnsVRVZFJqdkFHpsHMfJuWQzWU3tvnLC07UqHICfP+4XyL2tnr1amvl1Sdp06TnYCmVkA==", "dev": true, "requires": { - "@webassemblyjs/ast": "1.11.0", - "@webassemblyjs/helper-buffer": "1.11.0", - "@webassemblyjs/helper-wasm-bytecode": "1.11.0", - "@webassemblyjs/helper-wasm-section": "1.11.0", - "@webassemblyjs/wasm-gen": "1.11.0", - "@webassemblyjs/wasm-opt": "1.11.0", - "@webassemblyjs/wasm-parser": "1.11.0", - "@webassemblyjs/wast-printer": "1.11.0" + "@webassemblyjs/ast": "1.11.1", + "@webassemblyjs/helper-buffer": "1.11.1", + "@webassemblyjs/helper-wasm-bytecode": "1.11.1", + "@webassemblyjs/helper-wasm-section": "1.11.1", + "@webassemblyjs/wasm-gen": "1.11.1", + "@webassemblyjs/wasm-opt": "1.11.1", + "@webassemblyjs/wasm-parser": "1.11.1", + "@webassemblyjs/wast-printer": "1.11.1" } }, "@webassemblyjs/wasm-gen": { - "version": "1.11.0", - "resolved": "https://registry.npmjs.org/@webassemblyjs/wasm-gen/-/wasm-gen-1.11.0.tgz", - "integrity": "sha512-BEUv1aj0WptCZ9kIS30th5ILASUnAPEvE3tVMTrItnZRT9tXCLW2LEXT8ezLw59rqPP9klh9LPmpU+WmRQmCPQ==", + "version": "1.11.1", + "resolved": "https://registry.npmjs.org/@webassemblyjs/wasm-gen/-/wasm-gen-1.11.1.tgz", + "integrity": "sha512-F7QqKXwwNlMmsulj6+O7r4mmtAlCWfO/0HdgOxSklZfQcDu0TpLiD1mRt/zF25Bk59FIjEuGAIyn5ei4yMfLhA==", "dev": true, "requires": { - "@webassemblyjs/ast": "1.11.0", - "@webassemblyjs/helper-wasm-bytecode": "1.11.0", - "@webassemblyjs/ieee754": "1.11.0", - "@webassemblyjs/leb128": "1.11.0", - "@webassemblyjs/utf8": "1.11.0" + "@webassemblyjs/ast": "1.11.1", + "@webassemblyjs/helper-wasm-bytecode": "1.11.1", + "@webassemblyjs/ieee754": "1.11.1", + "@webassemblyjs/leb128": "1.11.1", + "@webassemblyjs/utf8": "1.11.1" } }, "@webassemblyjs/wasm-opt": { - "version": "1.11.0", - "resolved": "https://registry.npmjs.org/@webassemblyjs/wasm-opt/-/wasm-opt-1.11.0.tgz", - "integrity": "sha512-tHUSP5F4ywyh3hZ0+fDQuWxKx3mJiPeFufg+9gwTpYp324mPCQgnuVKwzLTZVqj0duRDovnPaZqDwoyhIO8kYg==", + "version": "1.11.1", + "resolved": "https://registry.npmjs.org/@webassemblyjs/wasm-opt/-/wasm-opt-1.11.1.tgz", + "integrity": "sha512-VqnkNqnZlU5EB64pp1l7hdm3hmQw7Vgqa0KF/KCNO9sIpI6Fk6brDEiX+iCOYrvMuBWDws0NkTOxYEb85XQHHw==", "dev": true, "requires": { - "@webassemblyjs/ast": "1.11.0", - "@webassemblyjs/helper-buffer": "1.11.0", - "@webassemblyjs/wasm-gen": "1.11.0", - "@webassemblyjs/wasm-parser": "1.11.0" + "@webassemblyjs/ast": "1.11.1", + "@webassemblyjs/helper-buffer": "1.11.1", + "@webassemblyjs/wasm-gen": "1.11.1", + "@webassemblyjs/wasm-parser": "1.11.1" } }, "@webassemblyjs/wasm-parser": { - "version": "1.11.0", - "resolved": "https://registry.npmjs.org/@webassemblyjs/wasm-parser/-/wasm-parser-1.11.0.tgz", - "integrity": "sha512-6L285Sgu9gphrcpDXINvm0M9BskznnzJTE7gYkjDbxET28shDqp27wpruyx3C2S/dvEwiigBwLA1cz7lNUi0kw==", + "version": "1.11.1", + "resolved": "https://registry.npmjs.org/@webassemblyjs/wasm-parser/-/wasm-parser-1.11.1.tgz", + "integrity": "sha512-rrBujw+dJu32gYB7/Lup6UhdkPx9S9SnobZzRVL7VcBH9Bt9bCBLEuX/YXOOtBsOZ4NQrRykKhffRWHvigQvOA==", "dev": true, "requires": { - "@webassemblyjs/ast": "1.11.0", - "@webassemblyjs/helper-api-error": "1.11.0", - "@webassemblyjs/helper-wasm-bytecode": "1.11.0", - "@webassemblyjs/ieee754": "1.11.0", - "@webassemblyjs/leb128": "1.11.0", - "@webassemblyjs/utf8": "1.11.0" + "@webassemblyjs/ast": "1.11.1", + "@webassemblyjs/helper-api-error": "1.11.1", + "@webassemblyjs/helper-wasm-bytecode": "1.11.1", + "@webassemblyjs/ieee754": "1.11.1", + "@webassemblyjs/leb128": "1.11.1", + "@webassemblyjs/utf8": "1.11.1" } }, "@webassemblyjs/wast-printer": { - "version": "1.11.0", - "resolved": "https://registry.npmjs.org/@webassemblyjs/wast-printer/-/wast-printer-1.11.0.tgz", - "integrity": "sha512-Fg5OX46pRdTgB7rKIUojkh9vXaVN6sGYCnEiJN1GYkb0RPwShZXp6KTDqmoMdQPKhcroOXh3fEzmkWmCYaKYhQ==", + "version": "1.11.1", + "resolved": "https://registry.npmjs.org/@webassemblyjs/wast-printer/-/wast-printer-1.11.1.tgz", + "integrity": "sha512-IQboUWM4eKzWW+N/jij2sRatKMh99QEelo3Eb2q0qXkvPRISAj8Qxtmw5itwqK+TTkBuUIE45AxYPToqPtL5gg==", "dev": true, "requires": { - "@webassemblyjs/ast": "1.11.0", + "@webassemblyjs/ast": "1.11.1", "@xtuc/long": "4.2.2" } }, @@ -1467,6 +1472,12 @@ } } }, + "acorn-import-assertions": { + "version": "1.7.6", + "resolved": "https://registry.npmjs.org/acorn-import-assertions/-/acorn-import-assertions-1.7.6.tgz", + "integrity": "sha512-FlVvVFA1TX6l3lp8VjDnYYq7R1nyW6x3svAt4nDgrWQ9SBaSh9CnbwgSUTasgfNfOG5HlM1ehugCvM+hjo56LA==", + "dev": true + }, "acorn-walk": { "version": "7.2.0", "resolved": "https://registry.npmjs.org/acorn-walk/-/acorn-walk-7.2.0.tgz", @@ -2767,9 +2778,9 @@ } }, "cypress": { - "version": "8.2.0", - "resolved": "https://registry.npmjs.org/cypress/-/cypress-8.2.0.tgz", - "integrity": "sha512-jg7S5VxxslwsgEyAkCE9ZCkFADxOUY1bSWScp1cWnga88K0TZgFQ0zdxyG9Mw/4spLGuvkriIZ62am+TR6C04w==", + "version": "8.3.0", + "resolved": "https://registry.npmjs.org/cypress/-/cypress-8.3.0.tgz", + "integrity": "sha512-zA5Rcq8AZIfRfPXU0CCcauofF+YpaU9HYbfqkunFTmFV0Kdlo14tNjH2E3++MkjXKFnv3/pXq+HgxWtw8CSe8Q==", "dev": true, "requires": { "@cypress/request": "^2.88.5", @@ -2816,9 +2827,9 @@ }, "dependencies": { "@types/node": { - "version": "14.17.9", - "resolved": "https://registry.npmjs.org/@types/node/-/node-14.17.9.tgz", - "integrity": "sha512-CMjgRNsks27IDwI785YMY0KLt3co/c0cQ5foxHYv/shC2w8oOnVwz5Ubq1QG5KzrcW+AXk6gzdnxIkDnTvzu3g==", + "version": "14.17.12", + "resolved": "https://registry.npmjs.org/@types/node/-/node-14.17.12.tgz", + "integrity": "sha512-vhUqgjJR1qxwTWV5Ps5txuy2XMdf7Fw+OrdChRboy8BmWUPkckOhphaohzFG6b8DW7CrxaBMdrdJ47SYFq1okw==", "dev": true }, "ansi-styles": { @@ -3498,9 +3509,9 @@ } }, "es-module-lexer": { - "version": "0.6.0", - "resolved": "https://registry.npmjs.org/es-module-lexer/-/es-module-lexer-0.6.0.tgz", - "integrity": "sha512-f8kcHX1ArhllUtb/wVSyvygoKCznIjnxhLxy7TCvIiMdT7fL4ZDTIKaadMe6eLvOXg6Wk02UeoFgUoZ2EKZZUA==", + "version": "0.7.1", + "resolved": "https://registry.npmjs.org/es-module-lexer/-/es-module-lexer-0.7.1.tgz", + "integrity": "sha512-MgtWFl5No+4S3TmhDmCz2ObFGm6lEpTnzbQi+Dd+pw4mlTIZTmM2iAs5gRlmx5zS9luzobCSBSI90JM/1/JgOw==", "dev": true }, "escalade": { @@ -4222,9 +4233,9 @@ }, "dependencies": { "async": { - "version": "3.2.0", - "resolved": "https://registry.npmjs.org/async/-/async-3.2.0.tgz", - "integrity": "sha512-TR2mEZFVOj2pLStYxLht7TyfuRzaydfpxr3k9RpHIzMgw7A64dzsdqCxH1WJyQdoe8T10nDXd9wnEigmiuHIZw==", + "version": "3.2.1", + "resolved": "https://registry.npmjs.org/async/-/async-3.2.1.tgz", + "integrity": "sha512-XdD5lRO/87udXCMC9meWdYiR+Nq6ZjUfXidViUZGu2F1MO4T3XwZ1et0hb2++BgLfhyJwy44BGB/yx80ABx8hg==", "dev": true } } @@ -7634,12 +7645,6 @@ "integrity": "sha512-h2AatdwYH+JHiZpv7pt/gSX1XoRGb7L/qSIeuqA6GwYoF9w1vP1cw42TO0aI2pNyshRK5893hNSl+1//vHK7hQ==", "dev": true }, - "oauth-sign": { - "version": "0.9.0", - "resolved": "https://registry.npmjs.org/oauth-sign/-/oauth-sign-0.9.0.tgz", - "integrity": "sha512-fexhUFFPTGV8ybAtSIGbV6gOkSv8UtRbDBnAyLQw4QPKkgNlsH2ByPGtMUqdWkos6YCRmAqViwgZrJc/mRDzZQ==", - "dev": true - }, "object-assign": { "version": "4.1.1", "resolved": "https://registry.npmjs.org/object-assign/-/object-assign-4.1.1.tgz", @@ -8909,12 +8914,6 @@ } } }, - "source-list-map": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/source-list-map/-/source-list-map-2.0.1.tgz", - "integrity": "sha512-qnQ7gVMxGNxsiL4lEuJwe/To8UnK7fAnmbGEEH8RpLouuKbeEm0lhbQVFIrNSuB+G7tVrAlVsZgETT5nljf+Iw==", - "dev": true - }, "source-map": { "version": "0.5.7", "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.5.7.tgz", @@ -9349,9 +9348,9 @@ } }, "terser": { - "version": "5.7.1", - "resolved": "https://registry.npmjs.org/terser/-/terser-5.7.1.tgz", - "integrity": "sha512-b3e+d5JbHAe/JSjwsC3Zn55wsBIM7AsHLjKxT31kGCldgbpFePaFo+PiddtO6uwRZWRw7sPXmAN8dTW61xmnSg==", + "version": "5.7.2", + "resolved": "https://registry.npmjs.org/terser/-/terser-5.7.2.tgz", + "integrity": "sha512-0Omye+RD4X7X69O0eql3lC4Heh/5iLj3ggxR/B5ketZLOtLiOqukUgjw3q4PDnNQbsrkKr3UMypqStQG3XKRvw==", "dev": true, "requires": { "commander": "^2.20.0", @@ -10095,21 +10094,22 @@ "dev": true }, "webpack": { - "version": "5.42.1", - "resolved": "https://registry.npmjs.org/webpack/-/webpack-5.42.1.tgz", - "integrity": "sha512-msikozzXrG2Hdx+dElq0fyNvxPFsaM2dKLc/l+xkMmhO/1qwVJ9K9gY+fi/49MYWcpSP7alnK5Q78Evrd1LiqQ==", + "version": "5.51.1", + "resolved": "https://registry.npmjs.org/webpack/-/webpack-5.51.1.tgz", + "integrity": "sha512-xsn3lwqEKoFvqn4JQggPSRxE4dhsRcysWTqYABAZlmavcoTmwlOb9b1N36Inbt/eIispSkuHa80/FJkDTPos1A==", "dev": true, "requires": { "@types/eslint-scope": "^3.7.0", - "@types/estree": "^0.0.48", - "@webassemblyjs/ast": "1.11.0", - "@webassemblyjs/wasm-edit": "1.11.0", - "@webassemblyjs/wasm-parser": "1.11.0", + "@types/estree": "^0.0.50", + "@webassemblyjs/ast": "1.11.1", + "@webassemblyjs/wasm-edit": "1.11.1", + "@webassemblyjs/wasm-parser": "1.11.1", "acorn": "^8.4.1", + "acorn-import-assertions": "^1.7.6", "browserslist": "^4.14.5", "chrome-trace-event": "^1.0.2", "enhanced-resolve": "^5.8.0", - "es-module-lexer": "^0.6.0", + "es-module-lexer": "^0.7.1", "eslint-scope": "5.1.1", "events": "^3.2.0", "glob-to-regexp": "^0.4.1", @@ -10118,11 +10118,11 @@ "loader-runner": "^4.2.0", "mime-types": "^2.1.27", "neo-async": "^2.6.2", - "schema-utils": "^3.0.0", + "schema-utils": "^3.1.0", "tapable": "^2.1.1", "terser-webpack-plugin": "^5.1.3", "watchpack": "^2.2.0", - "webpack-sources": "^2.3.0" + "webpack-sources": "^3.2.0" }, "dependencies": { "watchpack": { @@ -10534,22 +10534,10 @@ } }, "webpack-sources": { - "version": "2.3.0", - "resolved": "https://registry.npmjs.org/webpack-sources/-/webpack-sources-2.3.0.tgz", - "integrity": "sha512-WyOdtwSvOML1kbgtXbTDnEW0jkJ7hZr/bDByIwszhWd/4XX1A3XMkrbFMsuH4+/MfLlZCUzlAdg4r7jaGKEIgQ==", - "dev": true, - "requires": { - "source-list-map": "^2.0.1", - "source-map": "^0.6.1" - }, - "dependencies": { - "source-map": { - "version": "0.6.1", - "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.6.1.tgz", - "integrity": "sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g==", - "dev": true - } - } + "version": "3.2.0", + "resolved": "https://registry.npmjs.org/webpack-sources/-/webpack-sources-3.2.0.tgz", + "integrity": "sha512-fahN08Et7P9trej8xz/Z7eRu8ltyiygEo/hnRi9KqBUs80KeDcnf96ZJo++ewWd84fEf3xSX9bp4ZS9hbw0OBw==", + "dev": true }, "websocket-driver": { "version": "0.7.4", diff --git a/bindings/wasm/package.json b/bindings/wasm/package.json index dacfcdce70..be446ecf52 100644 --- a/bindings/wasm/package.json +++ b/bindings/wasm/package.json @@ -47,7 +47,7 @@ "devDependencies": { "@wasm-tool/wasm-pack-plugin": "^1.3.3", "copy-webpack-plugin": "^7.0.0", - "cypress": "^8.1.0", + "cypress": "^8.3.0", "http-server": "^0.12.3", "jest": "^27.0.6", "jsdoc-to-markdown": "^7.0.0", From 20d05153909c45e570074fb48646dd2ea3b63770 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eike=20Ha=C3=9F?= Date: Tue, 31 Aug 2021 12:00:44 +0200 Subject: [PATCH 10/23] fixed wasm path --- bindings/wasm/examples/src/utils_web.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bindings/wasm/examples/src/utils_web.js b/bindings/wasm/examples/src/utils_web.js index 62f68a56d2..fb9bde3dc5 100644 --- a/bindings/wasm/examples/src/utils_web.js +++ b/bindings/wasm/examples/src/utils_web.js @@ -7,7 +7,7 @@ export const LINK_REGEX = /(\b(https?|ftp):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0 * * @returns {Promise} */ -export async function initIdentity(path = "./../something/identity_wasm_bg.wasm") { +export async function initIdentity(path = "../../web/identity_wasm_bg.wasm") { console.log("Initialization started..."); try { await identity.init(path); From 3a630269ccd6002dca21fa6177c3684ac27490ed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eike=20Ha=C3=9F?= Date: Tue, 31 Aug 2021 12:01:01 +0200 Subject: [PATCH 11/23] enabled all node tests --- bindings/wasm/examples/src/test.js | 38 +++++++++++++++--------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/bindings/wasm/examples/src/test.js b/bindings/wasm/examples/src/test.js index 2d2c992eb6..5860b5cc68 100644 --- a/bindings/wasm/examples/src/test.js +++ b/bindings/wasm/examples/src/test.js @@ -1,6 +1,6 @@ import { createIdentity } from "./create_did"; import { manipulateIdentity } from "./manipulate_did"; -// import { resolution } from "./resolution"; +import { resolution } from "./resolution"; import { createVC } from "./create_vc"; import { createVP } from "./create_vp"; import { createDiff } from "./diff_chain"; @@ -8,7 +8,7 @@ import { revokeVC } from "./revoke_vc"; import { merkleKey } from "./merkle_key"; import { resolveHistory } from "./resolve_history"; import { CLIENT_CONFIG } from "./config"; -// import { createIdentityPrivateTangle } from "./private_tangle"; +import { createIdentityPrivateTangle } from "./private_tangle"; jest.setTimeout(180000); // 3 minutes to account for spurious network delays, most tests pass in a few seconds @@ -29,13 +29,13 @@ test.concurrent("Manipulate Identity", async () => { await manipulateIdentity(CLIENT_CONFIG); } }); -// test.concurrent("Resolution", async () => { -// try { -// await resolution(CLIENT_CONFIG); -// } catch (e) { -// await resolution(CLIENT_CONFIG); -// } -// }); +test.concurrent("Resolution", async () => { + try { + await resolution(CLIENT_CONFIG); + } catch (e) { + await resolution(CLIENT_CONFIG); + } +}); test.concurrent("Create Verifiable Credential", async () => { try { await createVC(CLIENT_CONFIG); @@ -64,16 +64,16 @@ test.concurrent("Merkle Key", async () => { await merkleKey(CLIENT_CONFIG); } }); -// test.concurrent("Private Tangle", async () => { -// try { -// await createIdentityPrivateTangle() -// throw new Error("Did not throw.") -// } catch (err) { -// // Example is expected to throw an error because no private Tangle is running -// expect(err.name).toEqual("ClientError") -// expect(err.message).toContain("error sending request") -// } -// }); +test.concurrent("Private Tangle", async () => { + try { + await createIdentityPrivateTangle() + throw new Error("Did not throw.") + } catch (err) { + // Example is expected to throw an error because no private Tangle is running + expect(err.name).toEqual("ClientError") + expect(err.message).toContain("error sending request") + } +}); test.concurrent("Diff Chain", async () => { try { await createDiff(CLIENT_CONFIG); From 1bd053dfcabe80dab364227b6df9d7f3f6a4cad7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eike=20Ha=C3=9F?= Date: Tue, 31 Aug 2021 12:08:37 +0200 Subject: [PATCH 12/23] added example build to workflow --- .github/workflows/examples.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml index e7b3b0af35..6ca00becd3 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 bindings + run: yarn build:examples + working-directory: bindings/wasm + - name: Test Wasm examples (node) run: yarn run test:node working-directory: bindings/wasm From 507e5b622bbf32f6ccc41e3e91ee8240d9a0d88d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eike=20Ha=C3=9F?= Date: Tue, 31 Aug 2021 12:28:36 +0200 Subject: [PATCH 13/23] renamed build step --- .github/workflows/examples.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml index 6ca00becd3..e9de8e816d 100644 --- a/.github/workflows/examples.yml +++ b/.github/workflows/examples.yml @@ -114,7 +114,7 @@ jobs: run: yarn build working-directory: bindings/wasm - - name: Build Wasm bindings + - name: Build Wasm examples run: yarn build:examples working-directory: bindings/wasm From 9586c8ea4900bea3ddd43e35d2eb65c26237b4fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eike=20Ha=C3=9F?= Date: Tue, 31 Aug 2021 13:06:36 +0200 Subject: [PATCH 14/23] fixed tests --- bindings/wasm/cypress/integration/browser_test.js | 12 ++++++------ bindings/wasm/examples/src/utils_web.js | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/bindings/wasm/cypress/integration/browser_test.js b/bindings/wasm/cypress/integration/browser_test.js index ce0d0098af..ea780a4983 100644 --- a/bindings/wasm/cypress/integration/browser_test.js +++ b/bindings/wasm/cypress/integration/browser_test.js @@ -1,5 +1,5 @@ import { - defaultClientConfig, initIdentity, createIdentity, createVC, manipulateIdentity, resolveIdentity, createVP, createDiff, revoke, merkleKey, createIdentityPrivateTangle, resolveHistory + 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. @@ -26,7 +26,7 @@ describe( 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 () { @@ -39,9 +39,9 @@ describe( it("resolve identity", async function () { try { - await resolveIdentity(defaultClientConfig()); + await resolution(defaultClientConfig()); } catch (e) { - await resolveIdentity(defaultClientConfig()); + await resolution(defaultClientConfig()); } }); @@ -55,9 +55,9 @@ describe( it("revoke verifiable credential", async function () { try { - await revoke(defaultClientConfig()); + await revokeVC(defaultClientConfig()); } catch (e) { - await revoke(defaultClientConfig()); + await revokeVC(defaultClientConfig()); } }); diff --git a/bindings/wasm/examples/src/utils_web.js b/bindings/wasm/examples/src/utils_web.js index fb9bde3dc5..04b31cd157 100644 --- a/bindings/wasm/examples/src/utils_web.js +++ b/bindings/wasm/examples/src/utils_web.js @@ -7,7 +7,7 @@ export const LINK_REGEX = /(\b(https?|ftp):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0 * * @returns {Promise} */ -export async function initIdentity(path = "../../web/identity_wasm_bg.wasm") { +export async function initIdentity(path = "./identity_wasm_bg.wasm") { console.log("Initialization started..."); try { await identity.init(path); From cac32bd4df656615fbc54545c580da374ba96687 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eike=20Ha=C3=9F?= Date: Tue, 31 Aug 2021 16:02:44 +0200 Subject: [PATCH 15/23] added example build to README --- bindings/wasm/examples/README.md | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/bindings/wasm/examples/README.md b/bindings/wasm/examples/README.md index 26a0fc585c..c85c4da262 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 ``` @@ -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 ``` From 7bc2543acd9fddfe2034e6ff7ecfd88e0835e8a5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eike=20Ha=C3=9F?= Date: Thu, 2 Sep 2021 09:54:22 +0200 Subject: [PATCH 16/23] fixed example path --- bindings/wasm/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bindings/wasm/package.json b/bindings/wasm/package.json index 7a0286daec..5e330fd30d 100644 --- a/bindings/wasm/package.json +++ b/bindings/wasm/package.json @@ -18,7 +18,7 @@ "pretest": "npm run build:nodejs", "prepublishOnly": "npm run build", "serve": "webpack serve", - "example:node": "node examples/node/node.js", + "example:node": "node examples/dist/node.js", "example:browser": "http-server ./examples/dist/ -c-1 -o ", "test:node": "jest dist/test.js", "test:browser": "cypress run --headless", From 8dbd8390c7ec6d8b600a1521773bf537ca8e5d1c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eike=20Ha=C3=9F?= Date: Thu, 2 Sep 2021 09:54:49 +0200 Subject: [PATCH 17/23] added sourcemap option to build step --- bindings/wasm/examples/webpack.config.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/bindings/wasm/examples/webpack.config.js b/bindings/wasm/examples/webpack.config.js index 75bdf9b766..11b0840d8b 100644 --- a/bindings/wasm/examples/webpack.config.js +++ b/bindings/wasm/examples/webpack.config.js @@ -3,6 +3,7 @@ const CopyWebPlugin = require('copy-webpack-plugin'); const serverConfig = { target: 'node', entry: './examples/src/node.js', + devtool: "source-map", output: { path: path.resolve(__dirname, 'dist'), filename: 'node.js', @@ -23,6 +24,7 @@ const serverConfig = { const serverTestConfig = { target: 'node', entry: './examples/src/test.js', + devtool: "source-map", output: { path: path.resolve(__dirname, 'dist'), filename: 'test.js', @@ -43,6 +45,7 @@ const serverTestConfig = { const clientConfig = { target: 'web', entry: './examples/src/web.js', + devtool: "source-map", output: { path: path.resolve(__dirname, 'dist'), filename: 'web.js', From eb37257b2f3e62bd92e2374fe5fe1ec1810ace9e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eike=20Ha=C3=9F?= Date: Thu, 2 Sep 2021 09:55:25 +0200 Subject: [PATCH 18/23] removed redundant try catch --- bindings/wasm/examples/src/utils_web.js | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/bindings/wasm/examples/src/utils_web.js b/bindings/wasm/examples/src/utils_web.js index 04b31cd157..98011e990d 100644 --- a/bindings/wasm/examples/src/utils_web.js +++ b/bindings/wasm/examples/src/utils_web.js @@ -9,12 +9,8 @@ export const LINK_REGEX = /(\b(https?|ftp):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0 */ export async function initIdentity(path = "./identity_wasm_bg.wasm") { console.log("Initialization started..."); - try { - await identity.init(path); - console.log("Initialization success!"); - } catch (err) { - throw new Error(err); - } + await identity.init(path); + console.log("Initialization success!"); } /** From f94d80453f5cda8d6363612f86b77a28eb08b1c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eike=20Ha=C3=9F?= Date: Fri, 3 Sep 2021 13:58:46 +0200 Subject: [PATCH 19/23] added WASM example build to build and test --- .github/workflows/build-and-test.yml | 4 ++++ 1 file changed, 4 insertions(+) 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: From 6f1641f3d657d4715703676613a636853d30ce42 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eike=20Ha=C3=9F?= Date: Fri, 3 Sep 2021 13:59:04 +0200 Subject: [PATCH 20/23] fixed Readme links --- bindings/wasm/examples/README.md | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/bindings/wasm/examples/README.md b/bindings/wasm/examples/README.md index c85c4da262..1f6f90b860 100644 --- a/bindings/wasm/examples/README.md +++ b/bindings/wasm/examples/README.md @@ -40,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 From cc8c3b5eb92425018bfaff38cec40c1d6048467a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eike=20Ha=C3=9F?= Date: Fri, 3 Sep 2021 15:27:29 +0200 Subject: [PATCH 21/23] changed test command --- bindings/wasm/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bindings/wasm/package.json b/bindings/wasm/package.json index 5e330fd30d..ca63062b7e 100644 --- a/bindings/wasm/package.json +++ b/bindings/wasm/package.json @@ -20,7 +20,7 @@ "serve": "webpack serve", "example:node": "node examples/dist/node.js", "example:browser": "http-server ./examples/dist/ -c-1 -o ", - "test:node": "jest dist/test.js", + "test:node": "jest examples/dist/test.js", "test:browser": "cypress run --headless", "test:readme": "txm README.md", "cypress": "cypress open" From a03df8f770e213fd36d6d312f17de3c5f4112c87 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eike=20Ha=C3=9F?= Date: Fri, 3 Sep 2021 15:28:16 +0200 Subject: [PATCH 22/23] added signature for linkify method --- bindings/wasm/examples/src/utils_web.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/bindings/wasm/examples/src/utils_web.js b/bindings/wasm/examples/src/utils_web.js index 98011e990d..de5678145d 100644 --- a/bindings/wasm/examples/src/utils_web.js +++ b/bindings/wasm/examples/src/utils_web.js @@ -41,6 +41,12 @@ export function logToScreen(message) { "
-------------------------------------
"; } +/** + * parses a string for urls and wraps them with link tags + * + * @param {string} inputText + * @returns {string} + */ export function linkify(inputText) { return inputText.replace(LINK_REGEX, '$1'); From 3876cd468dc16df0ceca89cbde44fe840c0654cb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eike=20Ha=C3=9F?= Date: Fri, 3 Sep 2021 15:43:28 +0200 Subject: [PATCH 23/23] minor rework of resolution workflow --- bindings/wasm/examples/src/resolution.js | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/bindings/wasm/examples/src/resolution.js b/bindings/wasm/examples/src/resolution.js index 995cdffbe6..8efa5dd47e 100644 --- a/bindings/wasm/examples/src/resolution.js +++ b/bindings/wasm/examples/src/resolution.js @@ -17,15 +17,14 @@ async function resolution(clientConfig, did) { // Create a client instance to publish messages to the Tangle. const client = Client.fromConfig(config); - let newDid; - if(!did) { + if (!did) { // Creates a new identity, that also is updated (See "manipulate_did" example). - newDid = await manipulateIdentity(clientConfig); + let {doc} = await manipulateIdentity(clientConfig); + did = doc.id.toString(); } - // Resolve a DID. - return await client.resolve(did ?? newDid.doc.id.toString()); + return await client.resolve(did); } export {resolution};