rootchain-wasm
v1.0.2
Published
WebAssembly primitives for RootChain: transaction signing, account derivation, and cryptography.
Downloads
21
Maintainers
Readme
rootchain-wasm
WebAssembly Cryptographic Primitives for the RootChain Ecosystem
rootchain-wasm provides the core cryptographic and transaction-processing logic for RootChain, compiled to highly-optimized WebAssembly. It is designed to be used in performance-critical environments like the rootchain-sdk to handle secure key derivation and offline transaction signing.
⚡ Core Functions
1. Account Derivation
Derive Ed25519 accounts deterministically from BIP-39 mnemonics.
import { derive_account } from 'rootchain-wasm';
const mnemonic = "abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about";
const account = derive_account(mnemonic, 0);
console.log(`Address: ${account.address}`);
console.log(`Secret Key: ${account.private_key}`);2. Transaction Signing
Serialize and sign RootChain transactions safely within the WASM sandbox.
import { sign_transaction } from 'rootchain-wasm';
const tx = {
tx_type: "Transfer",
from: Array(32).fill(0), // Automatically filled by signer
to: Array(32).fill(1),
amount: "1000",
fee: "10",
nonce: 1,
payload: [],
signature: Array(64).fill(0)
};
const signedTxJson = sign_transaction(JSON.stringify(tx), privateKeyHex);3. Utility Primitives
generate_mnemonic(): Generate new 12-word English recovery phrases.get_address_from_key(privKey): Resolve a public address from a raw secret key.get_contract_address(from, nonce): Deterministically calculate the address for the next deployed smart contract.
🛠️ Build Requirements
To rebuild the package from source, you will need wasm-pack:
cargo install wasm-pack
wasm-pack build --target bundler📄 License
This project is licensed under the MIT License.
