Wallet SDK reference #
Generated from @tensorchain/wallet-kit 0.2.0's own doc comments: every exported name is here, and an exported name with no doc comment fails the docs build. Sui testnet only.
vault.js #
| Name | What it does |
|---|---|
FORMAT | The stored vault's format name; a vault with another format is refused (vault_corrupt). |
ITERATIONS | PBKDF2-HMAC-SHA256 iterations used to derive the key that encrypts the recovery phrase. |
MAX_FAILS | Wrong passphrases in a row before the vault waits LOCKOUT_MS (locked_out). |
LOCKOUT_MS | How long the vault refuses unlocks after MAX_FAILS wrong passphrases, in milliseconds. |
IDLE_MS | The unlocked key is dropped after this long with no use (15 minutes), in milliseconds. |
class VaultError extends Error | A refusal from the vault; code is one of vault_exists, weak_passphrase, no_vault, bad_phrase, wrong_passphrase, locked_out, vault_corrupt, locked. |
createVault({ sui, storage, now = () => Date.now(), idleMs = IDLE_MS, crypto = globalThis.crypto }) | A wallet vault over storage ({get, set, remove}); sui is the SDK helpers from sui-sdk.js. Returns {exists, create(passphrase) -> {address, phrase}, restore(phrase, passphrase), unlock, lock, isUnlocked, address, publicKey, signPersonalMessage(bytes), signTransaction(bytes)}. Only the encrypted phrase is ever stored. |
kit.js #
| Name | What it does |
|---|---|
b2h(b) | Bytes to lowercase hex. |
h2b(h) | Lowercase hex to bytes. |
enc(t) | A string to UTF-8 bytes. |
async treeCall(base, token, method, path, body) | One call to the TensorChain service: {ok: true, result} or {ok: false, code}; a session token goes in X-Tree-Session. |
extensionWallet() | The TC Verify extension's wallet (Wallet Standard): { publicKey hex, signPersonalMessage(bytes) -> signature hex }. |
async treeConnect(owner, tid, wallet, hours) | Sign in to a tree area: a session key the browser makes and cannot export; the wallet signs the service's challenge and the delegation once; after that every edit is signed by the session key. |
async appSend(base, token, kp, body) | Send an app screen or an answer into a team tree: prepare on the service, sign the exact line with the session key, commit. |
delegationText(sessionHex, expiryMs) | The text a wallet signs to let a session key act for it until expiryMs (SPEC.md): tc-tree.delegate.v1. |
signinChallengeText(owner, area, nonce, sessionHex) | The text a wallet signs to sign in to a team tree area (SPEC.md): tc-tree.signin.v1. |
nameText(kind, name, walletHex, timeMs) | The text a wallet signs to claim or release a #name (SPEC.md): tc-name.<kind>.v1. |
canonical(v) | canonical JSON exactly as Python's json.dumps(v, sort_keys=True, separators=(",", ":")) (ensure_ascii: \uXXXX) |
appText(type, payload) | The text a session key signs for an app screen or an answer (SPEC.md): the type line, then canonical(payload). |
passCore(where) | where: the folder holding tc-pass.mjs and tc-pass.wasm (default: this site's /app/; the extension passes its own) |
async passWallet(wallet, hours, opts) | A wallet session for passes: a session key the browser cannot export, delegated once by the wallet; after that the session key signs every pass and every answer. wallet: { publicKey hex, signPersonalMessage(bytes) -> sig hex }. opts (WX2): { service: "https://tensorchain.io" (default: this site), core: the folder of tc-pass.mjs/.wasm } |
policy.js #
| Name | What it does |
|---|---|
DEFAULTS | The lock-down's starting settings: per_send and per_day limits in sata, the allowed recipients, lock_on_close. Placeholders until set in the wallet. |
class PolicyRefused extends Error | A refusal before any approval window opens; code is invalid_request, limit_per_send, limit_per_day or settings_invalid. |
dayOf(ms) | The UTC day number of a time in milliseconds (the daily limit resets at 00:00 UTC). |
settingsOf(stored) | The wallet's settings: the stored ones over DEFAULTS, checked (whole sata, a list of recipients); there is no auto-approve. |
spentToday(ledger, now) | The sends that count toward today: only the approved ones (a refused or rejected send counts for nothing). |
checkSend(settings, ledger, send, now) | Check a send before any window opens. Returns the summary the approval window shows; throws PolicyRefused. |
SETTINGS_OPS | What the wallet's own pages may change. A page (any site) may change none of it. |
sui.js #
| Name | What it does |
|---|---|
TESTNET | The pinned testnet deployment (S2, docs/SUI-S0.md). The wallet will use no other package, Mint or vault. |
SUI_TYPE | The SUI coin type, in Sui's long form. |
GAS_BUDGET | The default gas budget for one wallet transaction, in MIST (0.01 SUI); the unused part is refunded by Sui. |
class SuiRefused extends Error | A refusal before anything is signed: code names why (see the refusals table in the docs). |
graphqlClient(url, fetchFn = globalThis.fetch) | A GraphQL query function over fetch for an endpoint (testnet's, or a stub in tests). |
M_EXECUTE | The execute mutation (Sui GraphQL). One constant, so a schema change is one line. |
async readVault(query, ids = TESTNET) | Read a reserve vault from chain: its fixed rate (sata per MIST), reserve, staked, issued, treasury and whether the proof of reserves holds (ok: reserve + staked ≥ issued ÷ rate, the vault's own invariant). |
async buildSwap({ Transaction, query, sender, amount, ids = TESTNET, gasBudget = GAS_BUDGET }) | Build a swap of amount MIST of SUI into TNZR through the pinned vault: tnzr::deposit<SUI>(Mint, Vault<SUI>, coin). Returns { bytes, summary }: the transaction bytes to sign and what they do (see summarize). |
async buildSend({ Transaction, query, sender, to, amount, coin, ids = TESTNET, gasBudget = GAS_BUDGET }) | Build a send of amount (MIST for SUI, sata for TNZR) to to, a 32-byte hex Sui address. coin is "SUI" or "TNZR". TNZR coins are merged as needed and split to exactly the amount; gas is paid in SUI. |
summarize(Transaction, bytes, { ids = TESTNET, rate } = {}) | Decode what a wallet transaction does, from its bytes alone. Only the two shapes this kit builds are accepted: a swap {kind: "swap", sui, tnzr, gas_budget} and a send {kind: "send", coin, amount, to, gas_budget}. Anything else is refused not_a_wallet_transaction, so the approval never shows a guess. |
async execute(query, bytesB64, signatureB64) | Execute signed transaction bytes (base64) with the wallet's signature (base64). Returns { digest, status }. |
lens/kit.mjs #
| Name | What it does |
|---|---|
class LensRefused extends Error | A refusal from the lens kit; code is not_badged, bad_spec, bad_effect, missing_model, changed, not_in_manifest, no_manifest, fetch_failed or no_file_for_tier. |
async sha256(bytes) | The SHA-256 of bytes, as lowercase hex (WebCrypto). |
async loadManifest(base, pinned) | The manifest: base + "manifest.json" for a folder; in the bucket (WL2), base + "latest.json" names the manifest by its sha256, and the manifest itself is checked against that name before it is used. pinned (WX2): a manifest name "manifest-<sha256>.json" to use instead of latest.json (an extension pins the one it was built with; the bucket keeps every manifest, so the pin never goes stale). |
urlOf(base, manifest, name) | Where a manifest file is: its name in a folder, or "<sha256>.<ext>" in the bucket (content-addressed). |
async fetchVerified(base, manifest, name, stats) | The bytes of one manifest file, verified. Cache key: the sha256, so a changed file can never answer for another. |
EFFECTS | The five effects a lens can use, each with the models it needs and its checked parameters: background_blur, background_replace, color_grade, hair_tint, sticker. |
normalize(spec) | v1 (the first lens) becomes the same thing as v2: blur by depth, then a sticker. |
checkSpec(spec, manifest) | Check a lens spec (v1 or v2) against a manifest and return it as v2: every model badged, every effect known, every parameter in range, every needed model named. Throws LensRefused. |
makeSpec(parts, manifest) | A spec, built: TCLens.makeSpec({ models: {...}, effects: [...] }) -> a checked lens.spec.v2 (data only). |
async tier(store) | The tier, once: no WebGPU -> T0; otherwise by adapter limits and a 1-2 s micro benchmark. Only the number is kept. |
filesFor(spec, manifest, t, opts) | The files a tier needs for a lens: each named model's file for that tier. opts.f16 === false (the adapter lacks WebGPU's shader-f16): an fp16 file is never chosen; the model's non-fp16 file for the nearest lower tier is used instead (V2c), and opts.notes says so. |
lens/view.mjs #
| Name | What it does |
|---|---|
makeSpec | re-exported from lens/kit.mjs |
EFFECTS | re-exported from lens/kit.mjs |
newState() | A fresh measurement object for a running lens: frames, faces, samples, shots, stats (fetched, cacheHits, cacheRefused), ready. |
startLens(opts) | Run a lens on this device's camera: {base, video, canvas, spec?, status?, S?, runtimeBase?, manifest?}. Returns the live state at once; models are fetched by sha256 and checked; S.error is set on a refusal. |