-
Notifications
You must be signed in to change notification settings - Fork 3
feat(wasm-utxo): expose v6 (Ironwood) PSBT flow via wasm + TS #343
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
+326
−0
Draft
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,78 @@ | ||
| import assert from "node:assert"; | ||
| import { createRequire } from "node:module"; | ||
| import { describe, it } from "mocha"; | ||
|
|
||
| // The bundler-target wasm sources CSPRNG bytes through getrandom, which — on detecting Node via | ||
| // `process` — calls `module.require("crypto")`. `module` is undefined under Node ESM (the mocha | ||
| // harness), so provide a working `require`. Production consumers (real bundlers, or the | ||
| // nodejs-target build the microservice uses) don't need this. Runs before the first wasm | ||
| // randomness call. | ||
| (globalThis as unknown as { module?: { require: NodeRequire } }).module ??= { | ||
| require: createRequire(import.meta.url), | ||
| }; | ||
|
|
||
| import { ZcashBitGoPsbt } from "../../js/fixedScriptWallet/ZcashBitGoPsbt.js"; | ||
| import { getWalletKeysForSeed } from "../../js/testutils/index.js"; | ||
|
|
||
| // NU6.3 (Ironwood) testnet activation height and version group id. | ||
| const NU6_3_TESTNET_HEIGHT = 4134000; | ||
| const IRONWOOD_VERSION_GROUP_ID = 0xd884b698; | ||
|
|
||
| // A valid raw Orchard/Ironwood receiver (43 bytes), derived in Rust from | ||
| // SpendingKey([7u8; 32]) → FullViewingKey → address_at(0, External). | ||
| const RECIPIENT = Buffer.from( | ||
| "4559029c0b5dbf941c5ad181a5fe8f45b34630f29d0c8dd8dc1cc3573386f416cb324133156d723df5e62d", | ||
| "hex", | ||
| ); | ||
|
|
||
| describe("ZcashBitGoPsbt v6 (Ironwood)", function () { | ||
| function buildShieldPsbt(): ZcashBitGoPsbt { | ||
| const walletKeys = getWalletKeysForSeed("ironwood-ts"); | ||
| const psbt = ZcashBitGoPsbt.createIronwood("zcashTest", walletKeys, { | ||
| blockHeight: NU6_3_TESTNET_HEIGHT, | ||
| }); | ||
| // One 2-of-3 P2SH transparent input (2 ZEC) and a transparent change output. | ||
| psbt.addWalletInput({ txid: "11".repeat(32), vout: 0, value: 200_000_000n }, walletKeys, { | ||
| scriptId: { chain: 0, index: 0 }, | ||
| signPath: { signer: "user", cosigner: "bitgo" }, | ||
| }); | ||
| psbt.addWalletOutput(walletKeys, { chain: 1, index: 0, value: 99_900_000n }); | ||
| // Shielded Ironwood output (1 ZEC). Any valid Pallas base element is a usable build-time | ||
| // anchor (validity against a real tree is a prover concern), so all-zeros works. | ||
| psbt.addIronwoodOutput(RECIPIENT, 100_000_000n, { anchor: new Uint8Array(32) }); | ||
| return psbt; | ||
| } | ||
|
|
||
| it("creates an Ironwood PSBT with the Ironwood version group id", function () { | ||
| const psbt = buildShieldPsbt(); | ||
| assert.strictEqual(psbt.versionGroupId, IRONWOOD_VERSION_GROUP_ID); | ||
| }); | ||
|
|
||
| it("computes a 32-byte v6 txid and per-input sighash that survive a serialize round-trip", function () { | ||
| const psbt = buildShieldPsbt(); | ||
| const txid = psbt.ironwoodTxid(); | ||
| assert.strictEqual(txid.length, 32); | ||
| const sighash = psbt.ironwoodTransparentSighash(0); | ||
| assert.strictEqual(sighash.length, 32); | ||
|
|
||
| // serialize → fromBytes preserves the v6 state (transparent skeleton + PCZT + params). | ||
| const bytes = psbt.serialize(); | ||
| const round = ZcashBitGoPsbt.fromBytes(bytes, "zcashTest"); | ||
| assert.strictEqual(round.versionGroupId, IRONWOOD_VERSION_GROUP_ID); | ||
| assert.deepStrictEqual(round.ironwoodTxid(), txid); | ||
| assert.deepStrictEqual(round.ironwoodTransparentSighash(0), sighash); | ||
| }); | ||
|
|
||
| it("rejects a signature that does not verify against the v6 sighash", function () { | ||
| const psbt = buildShieldPsbt(); | ||
| assert.throws(() => psbt.addIronwoodSignature(0, new Uint8Array(33), new Uint8Array(72))); | ||
| }); | ||
|
|
||
| it("rejects Ironwood operations on a non-Ironwood output shape", function () { | ||
| const psbt = buildShieldPsbt(); | ||
| // A bad recipient length is rejected before touching the orchard builder. | ||
| assert.throws(() => | ||
| psbt.addIronwoodOutput(new Uint8Array(10), 1n, { anchor: new Uint8Array(32) }), | ||
| ); | ||
| }); | ||
| }); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe we want to create a separate
ZcashIronwoodBitGoPsbt.tsinstead?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1 — I'd do this in two steps:
Now (this PR): TS-level split. New
ZcashIronwoodBitGoPsbt.ts extends ZcashBitGoPsbt, move the six v6 methods (addIronwoodOutput/ironwoodTxid/ironwoodTransparentSighash/addIronwoodSignature/combineIronwoodProof) onto it,createIronwoodreturns it, andfromBytesdetects theZecV6Paramsmarker and returns the subclass. This gives the type-safety win with no wasm change — the underlying wasm object is the same flatBitGoPsbt. The one thing to get right is thefromBytespolymorphism (deserialize needs to return the subclass when the v6 marker is present).Follow-up: wasm-level split. A genuinely separate
WasmZcashIronwoodPsbtstruct. Cheaper than I first thought — the generic PSBT ops come free viaimpl_wasm_psbt_ops!(WasmZcashIronwoodPsbt, psbt)(src/wasm/psbt.rs:782); only the wallet-construction surface (add_wallet_input/add_wallet_output±_at_index,serialize) is hand-written onBitGoPsbttoday and would need delegation — or a second macro arm to generate it. That step removes thezcash()/zcash_mut()runtime guards in favor of compile-time separation, so it's worth doing, just not blocking this PR.Doing the TS split first keeps the public API shape the follow-up will want (a distinct Ironwood type) without holding up the stack.
Generated by Claude Code