ootle-wasm
Client-side WebAssembly crypto for Tari Ootle L2. Handles BOR encoding, transaction hashing, Schnorr signing, and key management — with output byte-identical to the native Rust implementation.
Installation
npm install @tari-project/ootle-wasm
API
All keys and signatures are Uint8Array (raw 32-byte values).
generateKeypair()
Generate a new random Ristretto255 keypair.
import { generateKeypair } from "@tari-project/ootle-wasm";
const { secret_key, public_key } = generateKeypair();
// secret_key: Uint8Array (32 bytes)
// public_key: Uint8Array (32 bytes)
publicKeyFromSecretKey(secretKey)
Derive the public key from a secret key.
import { publicKeyFromSecretKey } from "@tari-project/ootle-wasm";
const publicKey = publicKeyFromSecretKey(secretKey);
// publicKey: Uint8Array (32 bytes)
hashUnsignedTransaction(unsignedTxJson, sealSignerPublicKey, authorizerPublicKeys)
Hash a transaction for an authorization signature. Returns the 64-byte Uint8Array an external signer signs (see External signers). The hash excludes attached signatures, so it is the same before and after attachTransactionSignature.
unsignedTxJson — JSON-serialised UnsignedTransactionV1 or UnsealedTransactionV1
sealSignerPublicKey — raw public key bytes of the account owner (seal signer)
authorizerPublicKeys — the 32-byte public keys of every authorizer, concatenated in any order
Every authorizer signs over the same set of authorizer keys, so decide the set before anyone signs. The sealed transaction verifies only with an authorization from each key in the set and no other.
import { hashUnsignedTransaction } from "@tari-project/ootle-wasm";
const hash = hashUnsignedTransaction(
JSON.stringify(unsignedTransaction),
sealSignerPublicKey,
authorizerPublicKeys,
);
addTransactionSigner(txJson, signerSecretKey, sealSignerPublicKey, authorizerPublicKeys)
Hash the transaction and add an authorization signature by signerSecretKey, committing to the seal signer sealSignerPublicKey and the authorizer set authorizerPublicKeys, which must include the signer's own key. Accepts unsigned or unsealed transaction JSON and returns the unsealed transaction JSON.
sealTransaction(txJson, sealSignerSecretKey)
Hash the transaction and seal it with sealSignerSecretKey. Accepts unsigned or unsealed transaction JSON and returns the sealed Transaction JSON. The seal covers every authorization signature, so add them all first.
import { addTransactionSigner, sealTransaction } from "@tari-project/ootle-wasm";
let txJson = JSON.stringify(unsignedTransaction);
// Optional: authorizations from other keys, each over the set of all of them
txJson = addTransactionSigner(txJson, authorizerSecretKey, sealSignerPublicKey, authorizerPublicKeys);
const transactionJson = sealTransaction(txJson, sealSignerSecretKey);
These functions sign only messages they hash from the transaction themselves. Signing a hash computed elsewhere is the external-signer path below.
External signers (HSM, MPC)
These functions sign a transaction without passing a secret key to the binding. The external signer signs a 64-byte hash and returns its 64-byte signature; the binding verifies it and attaches it.
The signature must be a standard sr25519 (schnorrkel) signature under the default substrate signing context, with the sr25519 marker bit set in its last byte. Any sr25519 signer, such as a Polkadot signing library, produces this form. The signer must sign the 64 bytes exactly as given: a signer that hashes, prefixes or wraps the message (for example in <Bytes>…</Bytes>) produces a signature that fails verification.
Key isolation
An Ootle signing key is single-purpose: it signs Ootle transaction messages and nothing else.
Every Ootle authorization is a substrate-context sr25519 signature over a 64-byte message. Any path that signs caller-supplied bytes under substrate with the same key, such as a "sign message" endpoint, a login or proof-of-ownership challenge, or a raw-signing API another service can call, can be handed an Ootle transaction message, and the signature it returns authorizes that transaction. The network cannot tell such a signature from one your integration produced.
- Give each Ootle account its own key (or derivation path), used by no Substrate chain and no other application.
- Let only the component that builds Ootle transactions request signatures from that key.
- Sign only hashes you computed with
hashUnsignedTransaction or hashUnsealedTransaction from a transaction you built or inspected.
- Sign proofs of ownership and other application messages with a different key.
hashUnsealedTransaction(txJson)
Hash a transaction for sealing. Returns the 64-byte seal message for the seal signer (the account owner). Accepts unsigned or unsealed transaction JSON. The seal message covers every authorization signature, so attach them all before hashing.
attachSealSignature(txJson, sealSignerPublicKey, signature)
Seal a transaction with the seal signer's signature over the hashUnsealedTransaction hash. Returns the sealed Transaction JSON. Throws if the seal signature, or any authorization signature already attached, does not verify.
attachTransactionSignature(txJson, signerPublicKey, signature, sealSignerPublicKey, authorizerPublicKeys)
Add an authorization signature from an additional authorizer key. The signature is over the hashUnsignedTransaction hash for sealSignerPublicKey and authorizerPublicKeys, which must include signerPublicKey. Returns the unsealed transaction JSON. Throws if the signature does not verify.
import {
hashUnsignedTransaction,
hashUnsealedTransaction,
attachTransactionSignature,
attachSealSignature,
borEncodeTransaction,
} from "@tari-project/ootle-wasm";
let txJson = JSON.stringify(unsignedTransaction);
// Optional: authorizations from other keys (repeat per authorizer, each over the same set)
const authHash = hashUnsignedTransaction(txJson, sealSignerPublicKey, authorizerPublicKeys);
const authSig = await externalSigner.sign(authorizerKeyId, authHash);
txJson = attachTransactionSignature(txJson, authorizerPublicKey, authSig, sealSignerPublicKey, authorizerPublicKeys);
// Seal last
const sealHash = hashUnsealedTransaction(txJson);
const sealSig = await externalSigner.sign(sealSignerKeyId, sealHash);
const transactionJson = attachSealSignature(txJson, sealSignerPublicKey, sealSig);
const envelope = borEncodeTransaction(transactionJson);
borEncodeTransaction(transactionJson)
BOR-encode a signed Transaction into a base64 TransactionEnvelope string, ready to submit to the network.
import { borEncodeTransaction } from "@tari-project/ootle-wasm";
const envelope = borEncodeTransaction(JSON.stringify(transaction));
Working with keys
Keys and signatures are raw Uint8Array bytes. Convert to and from hex strings using the built-in methods (Node 22+, modern browsers):
import { generateKeypair, publicKeyFromSecretKey } from "@tari-project/ootle-wasm";
// Generate a keypair and display as hex
const { secret_key, public_key } = generateKeypair();
console.log("Public key:", public_key.toHex());
// Load a key from a hex string
const restored = Uint8Array.fromHex("a1b2c3...");
const derivedPublicKey = publicKeyFromSecretKey(restored);
Full example
import {
generateKeypair,
sealTransaction,
borEncodeTransaction,
} from "@tari-project/ootle-wasm";
// 1. Generate or load a keypair
const { secret_key, public_key } = generateKeypair();
// 2. Build an unsigned transaction (application-specific)
const unsignedTx = {
/* ... UnsignedTransactionV1 fields ... */
};
// 3. Seal with the account key
const transactionJson = sealTransaction(JSON.stringify(unsignedTx), secret_key);
// 4. BOR-encode
const envelope = borEncodeTransaction(transactionJson);
// 5. Submit envelope to the Ootle network
License
BSD-3-Clause