@terlos/stacks-wallet
v0.5.0
Published
Stacks Shield wallet core: keys, shielded receiving addresses, HPKE note encryption, scanning, coin selection, fresh withdraw addresses
Maintainers
Readme
@terlos/stacks-wallet
Part of Terlos: private payments on Stacks with ZK-STARKs verified on chain. Architecture · Integration guide · Security
The wallet core of Terlos:
- keys and shielded addresses;
- encrypted note memos;
- note scanning, coin selection and operation planning;
- relayed submission with automatic re-proving.
It is framework-free and holds no network state. @terlos/stacks-client builds the full wallet
experience (storage, sync, relayers) on top of it.
Status: 0.x, testnet, unaudited.
npm install @terlos/stacks-walletKeys and addresses
| Item | How it is made |
| --- | --- |
| Backup | One BIP-39 mnemonic (24 words) per wallet |
| Spending key | 4 Goldilocks limbs from HKDF-SHA256 (label spend); the owner key is pk = RPO(KEY, sk), hash-based |
| View key | X25519, from HKDF (label view). It only decrypts incoming memos, so it can be shared with an auditor without spend power |
| Addresses | zst1… (testnet) / zsp1… (mainnet), bech32m with a checksum. KeyRing derives any number of unlinkable receiving addresses per account. |
| Network separation | Keys are derived per network: mainnet uses its own HKDF salt (stacks-shield/wallet/v1/mainnet), testnet the original one (stacks-shield/wallet/v1). The same words give unrelated keys on each network, so testnet and mainnet addresses can't be linked. A wallet refuses keys derived for another network. |
import { KeyRing, ShieldedWallet, newMnemonic } from "@terlos/stacks-wallet";
const ring = KeyRing.fromMnemonic(newMnemonic(), { network: "testnet" }); // or "mainnet"
const wallet = new ShieldedWallet(ring, "testnet"); // must match
wallet.address; // primary address
const fresh = wallet.newAddress(); // a new address for one counterparty
wallet.watchKey(fresh.index); // view-only access to that address (for @terlos/stacks-pay)Notes and memos
Each new note carries a 98-byte memo: its opening (amount, blinding, asset) encrypted with HPKE (RFC 9180), using DHKEM(X25519, HKDF-SHA256) and ChaCha20-Poly1305, with the note commitment as AAD. A decrypted note is only accepted if it recomputes to the on-chain commitment, so a forged memo can never create a balance.
Planning and submitting
wallet.ingest(events, tree): scans events, but only for leaves the root-checked tree confirms.balances()/notes(asset): spendable notes and totals, from that scan.- Planning:
planShield,planPayment(to, amount, asset, relay)(merges and splits as needed),planWithdraw,planSendNote,planSplit,planMerge. wallet.request(action, tree, deployer): turns a plan into a proof request plus memos, for@terlos/stacks-sdk.submitWithReprove: sync, prove, submit and wait. It retries automatically when another transaction moved the root first.
License: Apache-2.0.
