The wallet SDK #
@tensorchain/wallet-kit is the code inside the TensorChain wallet, as one package: the keys, the swap and send on Sui, the passes, the lock-down and the camera filters. The TC Verify extension and the web app are both built from it, so what you build with it behaves exactly as the wallet does.
Sui testnet only. The package holds no mainnet address. TNZR is prepaid data and compute, and it is not for sale.
Every example on this page ran when the page was built, against the package itself; the output under each one is what it printed.
What is in the package #
| Module | What it does |
|---|---|
vault.js | makes a wallet key, keeps its recovery phrase encrypted, unlocks, locks and signs |
sui.js | swaps SUI for TNZR through the reserve vault, sends SUI or TNZR, reads the vault's proof of reserves |
policy.js | the lock-down: a limit per send and per day, and a mark on a first send to someone new |
kit.js | passes (send, accept, refuse, train), #names, team trees and app screens, and the texts each party signs |
sui-sdk.js | the pinned Sui SDK the wallet uses (Mysten's @mysten/sui and @scure/bip39, MIT licence) |
lens/kit.mjs, lens/view.mjs | camera filters: see Make a camera filter |
Every exported name is listed in the reference, generated from the package's own doc comments.
Get the package #
The package is not on npm yet. It ships inside TC Verify and the web app, and you build it from the TensorChain repository:
python3 packages/wallet-kit/build.py dist/wallet-kit # byte-identical every time; manifest.json lists each file's sha256
Then import it as @tensorchain/wallet-kit/<module>. It is plain JavaScript modules with no build step, for browsers and Node 20 or later.
Keys #
A vault keeps one wallet. It stores only the recovery phrase, encrypted with AES-256-GCM under a key derived from your passphrase (PBKDF2, 600,000 iterations). The unlocked key lives in memory, and it is dropped when you lock the vault or after 15 minutes with no use. storage is anything with get, set and remove: the extension uses its own storage, and this example uses a Map.
import assert from "node:assert/strict";
import { sui, Transaction } from "@tensorchain/wallet-kit/sui-sdk.js";
import { createVault, VaultError } from "@tensorchain/wallet-kit/vault.js";
const kept = new Map();
const storage = { get: async (k) => kept.get(k), set: async (k, v) => { kept.set(k, v); }, remove: async (k) => { kept.delete(k); } };
const vault = createVault({ sui, storage });
const { address, phrase } = await vault.create("a long passphrase");
assert.equal(phrase.split(" ").length, 12); // shown once: write it down
assert.ok(!JSON.stringify(kept.get("vault")).includes(phrase.split(" ")[0] + " ")); // never stored in the clear
await vault.unlock("a long passphrase");
const signed = await vault.signPersonalMessage(new TextEncoder().encode("hello"));
assert.equal(await sui.verifyPersonalMessage(new TextEncoder().encode("hello"), signed.signature), address);
vault.lock();
assert.match(address, /^0x[0-9a-f]{64}$/); // a new Sui address (different every run)
console.log("a Sui address | stored fields:", Object.keys(kept.get("vault")).sort().join(", "));
a Sui address | stored fields: address, ciphertext, format, iterations, iv, salt
A wrong passphrase is refused, and after five in a row the vault waits 30 seconds:
let refused;
try { await vault.unlock("not the passphrase"); } catch (e) { refused = e instanceof VaultError ? e.code : String(e); }
assert.equal(refused, "wrong_passphrase");
console.log("refused:", refused);
refused: wrong_passphrase
Swap SUI for TNZR #
TNZR is minted only by the reserve vault on Sui testnet: you deposit SUI and receive TNZR at the vault's fixed rate. buildSwap builds the whole transaction from chain reads (your gas coins, the gas price and the vault's shared versions), so nothing is left for a node to fill in. What you approve comes from the built bytes, never from a form: summarize decodes them back.
In the wallet, query talks to Sui testnet:
import { graphqlClient } from "@tensorchain/wallet-kit/sui.js";
const query = graphqlClient("https://graphql.testnet.sui.io/graphql");
So that this page builds without the network, the example below answers the same reads from a recording of the vault.
import { buildSwap, buildSend, readVault, summarize, TESTNET, SuiRefused } from "@tensorchain/wallet-kit/sui.js";
const DIGEST = "5mAf2Nvz7iqD9Ws9NYqDDgee71hihr1mGo7QTxfAaU8t";
const coin = (id, balance) => ({ address: id, version: "7", digest: DIGEST, contents: { json: { balance: String(balance) } } });
const recorded = async (q, v) => { // the answers Sui testnet gives for these reads
if (q.includes("referenceGasPrice")) return { epoch: { referenceGasPrice: "1000" } };
if (q.includes("object(address")) return { object: { address: v.id, version: "11", digest: DIGEST,
owner: { __typename: "Shared", initialSharedVersion: v.id === TESTNET.mint ? "349180001" : "349180002" },
asMoveObject: { contents: { type: { repr: v.id === TESTNET.mint ? TESTNET.package + "::tnzr::Mint" : TESTNET.package + "::tnzr::Vault<0x2::sui::SUI>" },
json: { rate: "1", reserve: { value: "70000000" }, staked: "1000000000", issued: "1070000000", treasury: { value: "30000000" } } } } } };
return { address: { objects: { nodes: v.t.includes("TNZR") ? [coin("0x" + "d1".repeat(32), 4000000)] : [coin("0x" + "c1".repeat(32), 600000000)] } } };
};
const me = await vault.unlock("a long passphrase").then(() => vault.address());
const proof = await readVault(recorded);
assert.equal(proof.ok, true); // reserve + staked covers everything issued
const { bytes, summary } = await buildSwap({ Transaction, query: recorded, sender: me, amount: 10_000_000 }); // 0.01 SUI
assert.deepEqual(summary, { kind: "swap", sui: 10000000, tnzr: 10000000, rate: 1, gas_budget: 10000000 });
assert.deepEqual(summarize(Transaction, bytes, { rate: 1 }), summary);
console.log("proof of reserves:", proof);
console.log("you approve:", summary);
proof of reserves: {
rate: 1,
reserve: 70000000,
staked: 1000000000,
issued: 1070000000,
treasury: 30000000,
ok: true
}
you approve: {
kind: 'swap',
sui: 10000000,
tnzr: 10000000,
rate: 1,
gas_budget: 10000000
}Then the wallet signs the bytes and sends them to Sui with execute:
const { signature } = await vault.signTransaction(bytes);
const { digest, status } = await execute(query, Buffer.from(bytes).toString("base64"), signature);
The swap is refused before anything is signed when it would not do what it says:
const why = async (p) => { try { await p; return "built"; } catch (e) { return e.code; } };
assert.equal(await why(buildSwap({ Transaction, query: recorded, sender: me, amount: 0 })), "invalid_amount");
assert.equal(await why(buildSwap({ Transaction, query: recorded, sender: me, amount: 595_000_000 })), "insufficient_sui"); // gas counted
assert.equal(await why(buildSwap({ Transaction, query: recorded, sender: me, amount: 5,
ids: { ...TESTNET, vaultSui: "0x" + "99".repeat(32) } })), "not_pinned");
assert.equal(await why(buildSwap({ Transaction, query: recorded, sender: me, amount: 5, ids: { ...TESTNET, chain: "sui:mainnet" } })), "chain_not_allowed");
console.log("refused: invalid_amount, insufficient_sui, not_pinned, chain_not_allowed");
refused: invalid_amount, insufficient_sui, not_pinned, chain_not_allowed
Send SUI or TNZR #
buildSend sends exactly the amount to a 32-byte Sui address (the wallet resolves a #name to its address first). A TNZR send merges your TNZR coins as needed and splits off exactly the amount; gas is paid in SUI.
const you = "0x" + "7a".repeat(32);
const sent = await buildSend({ Transaction, query: recorded, sender: me, to: you, amount: 1_000_000, coin: "TNZR" });
assert.deepEqual(sent.summary, { kind: "send", coin: "TNZR", amount: 1000000, to: you, gas_budget: 10000000 });
console.log("you approve:", sent.summary);
you approve: {
kind: 'send',
coin: 'TNZR',
amount: 1000000,
to: '0x7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a',
gas_budget: 10000000
}The lock-down #
Before any approval window opens, the wallet checks the send against its limits, in sata. A swap or a SUI send counts at its TNZR value under the vault's rate, so one daily limit covers everything that leaves the wallet. There is no auto-approve: the policy only refuses, and every send is still decided by a person.
import { checkSend, DEFAULTS } from "@tensorchain/wallet-kit/policy.js";
const now = Date.UTC(2026, 10, 26, 12);
assert.equal(checkSend({}, [], { to: you, amount: 1000 }, now).recipient_unknown, true); // someone new is marked
let limit;
try { checkSend({}, [], { to: you, amount: DEFAULTS.per_send + 1 }, now); } catch (e) { limit = e.code; }
assert.equal(limit, "limit_per_send");
console.log("defaults:", DEFAULTS, "| over the limit:", limit);
defaults: {
per_send: 1000000,
per_day: 5000000,
allowed: [],
lock_on_close: true
} | over the limit: limit_per_sendPasses #
A pass is one signed envelope: a file, an app, a prompt, a filter, a training job. In a browser the wallet makes a session key the page cannot export and delegates it once, for at most 8 hours; the session key then signs every pass and every answer. The texts each party signs are fixed (see SPEC.md):
import "@tensorchain/wallet-kit/kit.js"; // a classic script: it sets globalThis.TCWalletKit
const K = globalThis.TCWalletKit;
const session = "ab".repeat(32);
assert.equal(K.delegationText(session, 1795700000000), "tc-tree.delegate.v1\n" + session + "\n1795700000000\n");
assert.equal(K.canonical({ b: 1, a: "é" }), '{"a":"\\u00e9","b":1}');
console.log(JSON.stringify(K.nameText("claim", "bob", session, 1)));
"tc-name.claim.v1\nbob\nabababababababababababababababababababababababababababababababab\n1\n"
In a page, passWallet does the rest (the Pass SDK core, compiled from Rust to WebAssembly, builds each envelope):
const w = await TCWalletKit.passWallet(wallet, 8, { service: "https://tensorchain.io" });
await w.result.send("filter", "#bob", 0, JSON.stringify(lens)); // a camera filter, as a pass
await w.result.accept(passId); // or refuse(passId)
Refusals #
| Code | When |
|---|---|
invalid_amount | an amount that is not a whole number above 0 |
insufficient_sui, insufficient_tnzr | not enough to cover the amount and the gas |
not_pinned, not_the_vault | a package, Mint or vault other than the pinned testnet ones |
chain_not_allowed | any chain but sui:testnet |
invalid_address, invalid_coin | a receiver that is not a 32-byte address; a coin other than SUI or TNZR |
not_a_wallet_transaction | bytes this kit did not build: the approval never shows a guess |
limit_per_send, limit_per_day | the lock-down |
wrong_passphrase, locked_out, locked | the vault |