Skip to content

Commit

Permalink
Add build step for Wasm examples (#369)
Browse files Browse the repository at this point in the history
* added build step for examples

* enable more examples

* enabled more examples, cleaned up utils

* removed platform specific examples

* fixed node tests

* copy index.html to dist

* enable all examples

* changed example server root

* fixed browser test

* fixed wasm path

* enabled all node tests

* added example build to workflow

* renamed build step

* fixed tests

* added example build to README

* fixed example path

* added sourcemap option to build step

* removed redundant try catch

* added WASM example build to build and test

* fixed Readme links

* changed test command

* added signature for linkify method

* minor rework of resolution workflow
  • Loading branch information
eike-hass authored Sep 3, 2021
1 parent 821c12c commit ac28dbd
Show file tree
Hide file tree
Showing 38 changed files with 679 additions and 1,269 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/build-and-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
4 changes: 4 additions & 0 deletions .github/workflows/examples.yml
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,10 @@ jobs:
run: yarn build
working-directory: bindings/wasm

- name: Build Wasm examples
run: yarn build:examples
working-directory: bindings/wasm

- name: Test Wasm examples (node)
run: yarn run test:node
working-directory: bindings/wasm
Expand Down
58 changes: 25 additions & 33 deletions bindings/wasm/cypress/integration/browser_test.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,6 @@
import { defaultClientConfig, initIdentity } from "../../examples/browser/utils";
import { createIdentity } from "../../examples/browser/create_did.js";
import { createVC } from "../../examples/browser/create_vc.js";
import { manipulateIdentity } from "../../examples/browser/mainpulate_did.js";
import { resolveIdentity } from "../../examples/browser/resolve.js";
import { createVP } from "../../examples/browser/create_vp.js";
import { createDiff } from "../../examples/browser/diff_chain.js";
import { revoke } from "../../examples/browser/revoke_vc.js";
import { merkleKey } from "../../examples/browser/merkle_key.js";
import { createIdentityPrivateTangle } from "../../examples/browser/private_tangle";
import { resolveHistory } from "../../examples/browser/resolve_history";
import {
defaultClientConfig, initIdentity, createIdentity, createVC, manipulateIdentity, resolution, createVP, createDiff, revokeVC, merkleKey, createIdentityPrivateTangle, resolveHistory
} from '../../examples/dist/web'

// Test that the browser examples do not throw uncaught exceptions twice, including syntax errors etc.
describe(
Expand All @@ -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.
Expand All @@ -29,65 +21,65 @@ describe(
it("create identity", async function () {
let identityResult;
try {
identityResult = await createIdentity(defaultClientConfig(), false);
identityResult = await createIdentity(defaultClientConfig());
} catch (e) {
identityResult = await createIdentity(defaultClientConfig(), false);
identityResult = await createIdentity(defaultClientConfig());
}
// example of testing the output, can remove if needed
expect(identityResult).to.have.all.keys("key", "doc", "receipt", "explorerUrl");
expect(identityResult).to.have.all.keys("key", "doc", "receipt");
});

it("manipulate identity", async function () {
try {
await manipulateIdentity(defaultClientConfig(), false);
await manipulateIdentity(defaultClientConfig());
} catch (e) {
await manipulateIdentity(defaultClientConfig(), false);
await manipulateIdentity(defaultClientConfig());
}
});

it("resolve identity", async function () {
try {
await resolveIdentity(defaultClientConfig(), false, false);
await resolution(defaultClientConfig());
} catch (e) {
await resolveIdentity(defaultClientConfig(), false, false);
await resolution(defaultClientConfig());
}
});

it("create verifiable credential", async function () {
try {
await createVC(defaultClientConfig(), false);
await createVC(defaultClientConfig());
} catch (e) {
await createVC(defaultClientConfig(), false);
await createVC(defaultClientConfig());
}
});

it("revoke verifiable credential", async function () {
try {
await revoke(defaultClientConfig(), false);
await revokeVC(defaultClientConfig());
} catch (e) {
await revoke(defaultClientConfig(), false);
await revokeVC(defaultClientConfig());
}
});

it("create verifiable presentation", async function () {
try {
await createVP(defaultClientConfig(), false);
await createVP(defaultClientConfig());
} catch (e) {
await createVP(defaultClientConfig(), false);
await createVP(defaultClientConfig());
}
});

it("merkle key", async function () {
try {
await merkleKey(defaultClientConfig(), false);
await merkleKey(defaultClientConfig());
} catch (e) {
await merkleKey(defaultClientConfig(), false);
await merkleKey(defaultClientConfig());
}
});

it("private tangle", async function () {
try {
await createIdentityPrivateTangle(false, false)
await createIdentityPrivateTangle()
throw new Error("Did not throw.")
} catch (err) {
// Example is expected to throw an error because no private Tangle is running
Expand All @@ -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());
}
});
}
Expand Down
3 changes: 2 additions & 1 deletion bindings/wasm/examples/.gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
!*
!*
dist/
31 changes: 21 additions & 10 deletions bindings/wasm/examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

```
Expand All @@ -34,23 +40,28 @@ 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
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

```
Expand Down
49 changes: 0 additions & 49 deletions bindings/wasm/examples/browser/create_did.js

This file was deleted.

67 changes: 0 additions & 67 deletions bindings/wasm/examples/browser/create_vc.js

This file was deleted.

46 changes: 0 additions & 46 deletions bindings/wasm/examples/browser/create_vp.js

This file was deleted.

Loading

0 comments on commit ac28dbd

Please sign in to comment.