iris-crypto WebAssembly Package
This package provides Nockchain cryptography primitives compiled to WebAssembly, allowing you to use derive_master_key and related functions from TypeScript/JavaScript.
Building
To build the WASM package:
Usage
In a Web Browser
iris-crypto Demo
In Node.js
import init from './pkg/iris_crypto.js';
import from 'fs';
;
TypeScript
The package includes full TypeScript definitions:
import init, {
deriveMasterKey,
deriveMasterKeyFromMnemonic,
WasmExtendedKey
} from './pkg/iris_crypto.js';
await init();
// Derive from mnemonic with TypeScript types
const mnemonic: string = "your mnemonic here";
const passphrase: string = "";
const masterKey: WasmExtendedKey = deriveMasterKeyFromMnemonic(mnemonic, passphrase);
// Type-safe access
const privateKey: Uint8Array | undefined = masterKey.private_key;
const publicKey: Uint8Array = masterKey.public_key;
const chainCode: Uint8Array = masterKey.chain_code;
// Derive child
const childKey: WasmExtendedKey = masterKey.deriveChild(0);
API
Functions
deriveMasterKey(seed: Uint8Array): WasmExtendedKey
Derives a master key from raw seed bytes using SLIP-10.
- Parameters:
seed: Raw seed bytes (typically 64 bytes from BIP39)
- Returns:
WasmExtendedKeycontaining the master private key, public key, and chain code
deriveMasterKeyFromMnemonic(mnemonic: string, passphrase?: string): WasmExtendedKey
Derives a master key from a BIP39 mnemonic phrase.
- Parameters:
mnemonic: BIP39 mnemonic phrase (12-24 words)passphrase: Optional BIP39 passphrase (defaults to empty string)
- Returns:
WasmExtendedKeycontaining the master private key, public key, and chain code
Classes
WasmExtendedKey
Represents an extended key with derivation capability.
Properties:
private_key: Uint8Array | undefined- Private key (32 bytes), undefined for public-only keyspublic_key: Uint8Array- Public key (97 bytes: 1 byte prefix + 12 belts × 8 bytes)chain_code: Uint8Array- Chain code for derivation (32 bytes)
Methods:
deriveChild(index: number): WasmExtendedKey- Derives a child key at the given index- For hardened derivation, use indices >= 2^31 (0x80000000)
- For non-hardened derivation, use indices < 2^31
free(): void- Frees the WebAssembly memory (important to prevent memory leaks)
Implementation Details
This package uses:
- SLIP-10 for hierarchical deterministic key derivation
- Cheetah curve arithmetic from Nockchain
- Custom field arithmetic optimized for the Cheetah curve
- TIP5 hash function for internal operations
The implementation is compatible with Nockchain's wallet derivation scheme.
License
See the main repository LICENSE file.