Get up and running with Polymesh DART WASM bindings in minutes!
This library generates zero-knowledge proofs for confidential transactions. You have flexibility in how you submit these proofs to the blockchain:
- With Polkadot.js (Recommended): Lightweight, flexible, minimal dependencies
- With PolymeshClient (Testing/Development only): Requires
./build_with_rust_client.shscript - Your own chain client: Use any solution that works for you
The core WASM APIs (proof generation, key management) work independently and don't require PolymeshClient.
npm install @polymesh/dart-wasmThis installs the default build with core proof generation APIs.
If you want to use PolymeshClient and PolymeshSigner for testing:
cd polymesh-dart-wasm
./build_with_rust_client.shcd polymesh-dart-wasm
./build.shCreate an HTML file:
<!DOCTYPE html>
<html>
<head>
<title>My First DART App</title>
</head>
<body>
<h1>Polymesh DART Demo</h1>
<button id="createKeys">Create Keys</button>
<pre id="output"></pre>
<script type="module">
import init, { AccountKeys, generateRandomSeed }
from './pkg-web/polymesh_dart_wasm.js';
// Initialize WASM
await init();
document.getElementById('createKeys').onclick = () => {
// Generate keys
const seed = generateRandomSeed();
const keys = new AccountKeys(seed);
const pubKeys = keys.publicKeys();
// Display results
document.getElementById('output').textContent =
'Seed: ' + seed + '\n\n' +
'Public Keys:\n' + JSON.stringify({
accountKey: pubKeys.accountPublicKey().toJson(),
encryptionKey: pubKeys.encryptionPublicKey().toJson()
}, null, 2);
};
</script>
</body>
</html>Serve with a local server:
python3 -m http.server 8000
# Visit http://localhost:8000Create app.js:
const { AccountKeys, generateRandomSeed } =
require('./pkg-node/polymesh_dart_wasm.js');
// Generate account keys
const seed = generateRandomSeed();
console.log('Seed:', seed);
const keys = new AccountKeys(seed);
const pubKeys = keys.publicKeys();
console.log('Account public key:', pubKeys.accountPublicKey().toJson());
console.log('Encryption public key:', pubKeys.encryptionPublicKey().toJson());Run it:
node app.jsCreate app.ts:
import init, {
AccountKeys,
AccountPublicKeys,
AssetState,
generateRandomSeed
} from '@polymesh/dart-wasm';
async function main() {
// Initialize WASM
await init();
// Generate keys
const seed: string = generateRandomSeed();
const keys: AccountKeys = new AccountKeys(seed);
const pubKeys: AccountPublicKeys = keys.publicKeys();
console.log('Seed:', seed);
console.log('Account key:', pubKeys.accountPublicKey().toJson());
console.log('Encryption key:', pubKeys.encryptionPublicKey().toJson());
}
main().catch(console.error);Compile and run:
tsc app.ts
node app.jsimport { AccountKeys, generateRandomSeed } from '@polymesh/dart-wasm';
// Generate new keys
const seed = generateRandomSeed();
const keys = new AccountKeys(seed);
// Export for storage (encrypt before storing!)
const keyBytes = keys.toBytes();
localStorage.setItem('dartKeys', JSON.stringify(Array.from(keyBytes)));
localStorage.setItem('dartSeed', seed);
// Later: Restore from storage
const storedBytes = JSON.parse(localStorage.getItem('dartKeys'));
const restoredKeys = AccountKeys.fromBytes(new Uint8Array(storedBytes));// Get public keys to share
const pubKeys = keys.publicKeys();
const accountPubKey = pubKeys.accountPublicKey();
const encryptionPubKey = pubKeys.encryptionPublicKey();
// Export as JSON for display
console.log('Share these public keys:');
console.log({
account: accountPubKey.toJson(),
encryption: encryptionPubKey.toJson()
});import { AccountKeys } from '@polymesh/dart-wasm';
// Your keys and DID
const keys = new AccountKeys(seed);
const myDid = '0x1234...'; // Your identity
// Generate registration proof (without submitting to chain)
const proof = keys.registerAccountProof(myDid);
const proofBytes = proof.toBytes();
const proofHex = proof.toHex();
console.log('Generated proof - ready to submit to chain');
// Now use your chain client (Polkadot.js, PolymeshClient, etc.)
// to submit this proofimport { AssetState, EncryptionPublicKey } from '@polymesh/dart-wasm';
// Option A: From Polkadot.js chain query
const assetId = 42;
const assetDetail = await api.query.confidentialAssets.dartAssetDetails(assetId);
const assetState = new AssetState(assetId, assetDetail.mediators, assetDetail.auditors);
// Option B: From raw hex strings
const mediatorKey = new EncryptionPublicKey('0xabcd...');
const auditorKey = new EncryptionPublicKey('0x5678...');
const assetState = new AssetState(assetId, [mediatorKey], [auditorKey]);
console.log('Asset ID:', assetState.assetId());
console.log('Mediators:', assetState.mediatorCount());
console.log('Auditors:', assetState.auditorCount());
// Export asset state
const assetBytes = assetState.toBytes();// Same seed always produces same keys
const keys1 = AccountKeys.fromSeed('my-password');
const keys2 = AccountKeys.fromSeed('my-password');
// These will be identical
console.assert(
keys1.publicKeys().accountPublicKey().toJson() ===
keys2.publicKeys().accountPublicKey().toJson()
);- Read the Full Documentation: See README.md for complete API reference
- Explore Examples: Check the
examples/directory for more complex scenarios - Development Guide: Read DEVELOPMENT.md for integration patterns
- Learn DART: Review the P-DART paper for protocol details
- Chain Integration:
- See README.md - Using with Polkadot.js for examples
- See DEVELOPMENT.md for PolymeshClient integration (optional)
Make sure you've built the package or installed it via npm:
cd polymesh-dart-wasm
./build.shAlways call init() before using other functions:
await init(); // Important!
const keys = new AccountKeys(seed); // Now this worksUpdate your bundler config to support WASM modules. See DEVELOPMENT.md for specific bundler configurations.
Ensure your input data is valid:
- DIDs should be 32 bytes (64 hex characters)
- Asset IDs should be valid numbers
- Keys should come from the same seed generation
- AssetState mediators/auditors should match chain data
- Issues: GitHub Issues
- Discussions: GitHub Discussions
- Documentation: Full API Docs
Use Polkadot.js if you:
- Are building production applications
- Want minimal dependencies
- Are already using Polkadot.js in your project
- Want maximum flexibility with chain interactions
- Want the smallest bundle size (recommended)
Use PolymeshClient if you:
- Are testing or developing proof generation
- Want convenience Polymesh-specific operations
- Are building desktop or Node.js applications (not browser)
- Don't mind the extra build step (
./build_with_rust_client.sh) - Don't mind the larger bundle size
To use PolymeshClient, you must build with:
./build_with_rust_client.shThis is NOT the default build. The default ./build.sh creates a minimal bundle with just proof generation APIs.
Both approaches work equally well with the core WASM proof generation!
Happy building! 🚀