Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Wasm Stardust Client #975

Merged
merged 35 commits into from
Aug 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
842e32c
Split StardustClientExt into StardustIdentityClient/Base traits
cycraig Aug 3, 2022
ebad080
Add network checks to StardustClientExt
cycraig Aug 3, 2022
7b36056
Add context to example errors, increase faucet timeout
cycraig Aug 3, 2022
8f9a32d
Fix compilation without `iota-client` feature, relax Send restriction
cycraig Aug 3, 2022
3874b0e
Re-export bee_block as the block module
cycraig Aug 3, 2022
d373ea7
Add IStardustIdentityClient, IStardustIdentityClientExt interfaces
cycraig Aug 3, 2022
bab7d7a
[WIP] TypeScript client extension attempt
cycraig Aug 4, 2022
013689b
Remove expect, make error messages more verbose
cycraig Aug 4, 2022
0dbb582
Fix AliasOutput serialization, update example
cycraig Aug 5, 2022
a395a70
Move deactivate_did_output to StardustIdentityClient
cycraig Aug 8, 2022
824cb33
Update Wasm bindings
cycraig Aug 8, 2022
c031d7f
Implement publishDidOutput for Wasm bindings
cycraig Aug 8, 2022
f80db4e
Clean Wasm ex0_create_did example
cycraig Aug 8, 2022
23f5280
Implement deleteDidOutput for Wasm bindings
cycraig Aug 8, 2022
8b6e326
Add ex1_update_did Wasm example, add examples-stardust directory
cycraig Aug 8, 2022
7f09eb2
Add ex2_resolve_did example for Wasm
cycraig Aug 8, 2022
5de2d5a
Add metadata deactivated field Wasm bindings
cycraig Aug 9, 2022
20157a9
Fix input commitment hash calculation for multiple inputs
cycraig Aug 9, 2022
4d0904a
Add ex4_delete_did Wasm example
cycraig Aug 9, 2022
8463da2
Fix StateMetadataDocument serialised fieldnames
cycraig Aug 9, 2022
4e65b02
Fix dust outputs when reclaiming Alias Output amount
cycraig Aug 9, 2022
d38a528
Update iota.js to latest version
cycraig Aug 9, 2022
a152cc1
Start iota.rs Node.js client intergration
cycraig Aug 12, 2022
f68d781
Use unofficia iota-client Wasm bindings
cycraig Aug 18, 2022
dd0dd4c
Merge branch 'dev' of https://github.com/iotaledger/identity.rs into …
cycraig Aug 18, 2022
e825516
Fix formatting
cycraig Aug 18, 2022
cdd82ae
Merge branch 'dev' into feat/wasm-shimmer-client
eike-hass Aug 19, 2022
7859065
Add StardustDocument::unpack_from_block, simplify TypeScript
cycraig Aug 20, 2022
5c2bfda
Apply suggestions from code review
cycraig Aug 20, 2022
8504582
Merge branch 'feat/wasm-shimmer-client' of https://github.com/iotaled…
cycraig Aug 20, 2022
b66132f
Wait for faucet in Wasm Stardust examples
cycraig Aug 20, 2022
7a4207b
Change TypeScript `import` to `import type`
cycraig Aug 20, 2022
250390a
Improve Wasm TypeScript build (#976)
eike-hass Aug 22, 2022
a85895f
Remove sleep in Wasm deactivate example
cycraig Aug 22, 2022
0a83839
Revert change to txm README.md example
cycraig Aug 22, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions bindings/wasm/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,10 @@ Cargo.lock
node_modules/

# Build artifacts
wasm-web/
wasm-node/
web/
node/
pkg/
**/dist/

# cypress
cypress/screenshots/
Expand Down
3 changes: 2 additions & 1 deletion bindings/wasm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ crate-type = ["cdylib", "rlib"]

[dependencies]
async-trait = { version = "0.1", default-features = false }
bee-block = { version = "1.0.0-beta.5", default-features = false, features = ["dto"] }
console_error_panic_hook = { version = "0.1" }
futures = { version = "0.3" }
js-sys = { version = "0.3" }
Expand All @@ -37,7 +38,7 @@ features = ["account", "storage-test-suite", "unstable-encryption", "revocation-
version = "=0.6.0"
path = "../../identity_stardust"
default-features = false
features = ["revocation-bitmap"]
features = ["client", "revocation-bitmap"]

[dev-dependencies]
wasm-bindgen-test = { version = "0.3" }
Expand Down
33 changes: 22 additions & 11 deletions bindings/wasm/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,19 @@

## Install the library:

Latest Release: this version matches the main branch of this repository, is stable and will have changelogs.
Latest Release: this version matches the `main` branch of this repository, is stable and will have changelogs.
```bash
npm install @iota/identity-wasm
```

Development Release: this version matches the dev branch of this repository, may see frequent breaking changes and has the latest code changes.
Development Release: this version usually matches the latest code changes from the `dev` branch and may see frequent breaking changes.
```bash
npm install @iota/identity-wasm@dev
```

## Build

Alternatively, you can build the bindings if you have Rust installed. If not, refer to [rustup.rs](https://rustup.rs) for the installation.
Alternatively, you can build the bindings yourself if you have Rust installed. If not, refer to [rustup.rs](https://rustup.rs) for the installation.

Install [`wasm-bindgen-cli`](https://github.com/rustwasm/wasm-bindgen). A manual installation is required because we use the [Weak References](https://rustwasm.github.io/wasm-bindgen/reference/weak-references.html) feature, which [`wasm-pack` does not expose](https://github.com/rustwasm/wasm-pack/issues/930).

Expand All @@ -48,7 +48,7 @@ npm run build:web

## Minimum Requirements

The minimum supported version for node is: `v16.0.0`
The minimum supported version for node is: `v16`

## NodeJS Usage
<!--
Expand All @@ -62,7 +62,7 @@ cat \
-->
<!-- !test check Nodejs Example -->
```javascript
const identity = require('@iota/identity-wasm/node')
const identity = require('@iota/identity-wasm/node');

async function main() {

Expand All @@ -84,7 +84,7 @@ async function main() {
console.log(`Explorer Url:`, identity.ExplorerUrl.mainnet().resolverUrl(did));
}

main()
main();
```

## Web Setup
Expand All @@ -107,7 +107,13 @@ import copy from 'rollup-plugin-copy'

// Add the copy plugin to the `plugins` array of your rollup config:
copy({
targets: [{
targets: [
{
src: 'node_modules/@cycraig/iota-client-wasm/web/wasm/client_wasm_bg.wasm',
dest: 'public',
rename: 'client_wasm_bg.wasm'
},
{
src: 'node_modules/@iota/identity-wasm/web/identity_wasm_bg.wasm',
dest: 'public',
rename: 'identity_wasm_bg.wasm'
Expand All @@ -131,6 +137,10 @@ const CopyWebPlugin= require('copy-webpack-plugin');

new CopyWebPlugin({
patterns: [
{
from: 'node_modules/@cycraig/iota-client-wasm/web/wasm/client_wasm_bg.wasm',
to: 'client_wasm_bg.wasm'
},
{
from: 'node_modules/@iota/identity-wasm/web/identity_wasm_bg.wasm',
to: 'identity_wasm_bg.wasm'
Expand All @@ -142,9 +152,10 @@ new CopyWebPlugin({
### Web Usage

```js
import * as client from "@cycraig/iota-client-wasm/web";
import * as identity from "@iota/identity-wasm/web";

identity.init().then(() => {
client.init().then(() => identity.init()).then(() => {

// The creation step generates a keypair, builds an identity
// and publishes it to the IOTA mainnet.
Expand All @@ -165,8 +176,8 @@ identity.init().then(() => {
// or

(async () => {

await identity.init()
await client.init();
await identity.init();

// The creation step generates a keypair, builds an identity
// and publishes it to the IOTA mainnet.
Expand All @@ -188,7 +199,7 @@ identity.init().then(() => {
await identity.init("./static/identity_wasm_bg.wasm");
```

`identity.init().then(<callback>)` or `await identity.init()` is required to load the wasm file (from the server if not available, because of that it will only be slow for the first time)
Calling `identity.init().then(<callback>)` or `await identity.init()` is required to load the Wasm file from the server if not available, because of that it will only be slow for the first time.

## Examples in the Wild

Expand Down
6 changes: 3 additions & 3 deletions bindings/wasm/build/node.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ fs.writeFileSync(
changedFileNode
);

// Generate `package.json`.
const newPackage = generatePackage({
main: 'identity_wasm.js',
types: 'identity_wasm.d.ts',
main: 'index.js',
types: 'index.d.ts',
});

fs.writeFileSync(path.join(RELEASE_FOLDER, 'package.json'), JSON.stringify(newPackage, null, 2));
6 changes: 3 additions & 3 deletions bindings/wasm/build/utils/generatePackage.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ module.exports = (options) => {
description: rootPackage.description,
version: rootPackage.version,
license: rootPackage.license,
homepage: rootPackage.homepage,
repository: rootPackage.repository,
main: options.main,
module: options.module,
homepage: rootPackage.homepage,
main: options.main,
types: options.types,
}

Expand All @@ -19,4 +19,4 @@ module.exports = (options) => {

return newPackage;

}
}
16 changes: 8 additions & 8 deletions bindings/wasm/build/web.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const path = require('path')
const fs = require('fs')
const { lintAll } = require('./lints')
const path = require('path');
const fs = require('fs');
const fse = require('fs-extra');
const { lintAll } = require('./lints');
const generatePackage = require('./utils/generatePackage');

const RELEASE_FOLDER = path.join(__dirname, '../web/');
Expand Down Expand Up @@ -47,10 +48,9 @@ fs.writeFileSync(
entryFilePathTs,
changedFileTs
);

// Generate `package.json`.
const newPackage = generatePackage({
module: 'identity_wasm.js',
types: 'identity_wasm.d.ts',
module: 'index.js',
types: 'index.d.ts',
});

fs.writeFileSync(path.join(RELEASE_FOLDER, 'package.json'), JSON.stringify(newPackage, null, 2));
fs.writeFileSync(path.join(RELEASE_FOLDER, 'package.json'), JSON.stringify(newPackage, null, 2));
Loading