@babylonlabs-io/ts-sdk 0.79.0 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +11 -5
- package/dist/{PeginManager-BuVSknB0.cjs → PeginManager-BCJWwV05.cjs} +2 -2
- package/dist/{PeginManager-BuVSknB0.cjs.map → PeginManager-BCJWwV05.cjs.map} +1 -1
- package/dist/{PeginManager-BXlh3ar0.js → PeginManager-BH_AKu4l.js} +5 -5
- package/dist/{PeginManager-BXlh3ar0.js.map → PeginManager-BH_AKu4l.js.map} +1 -1
- package/dist/{buildAndBroadcastReclaim-N9dXH9dm.cjs → buildAndBroadcastReclaim-DLsf5hjO.cjs} +2 -2
- package/dist/{buildAndBroadcastReclaim-N9dXH9dm.cjs.map → buildAndBroadcastReclaim-DLsf5hjO.cjs.map} +1 -1
- package/dist/{buildAndBroadcastReclaim-O6z9kvc4.js → buildAndBroadcastReclaim-OMvihzJg.js} +4 -4
- package/dist/{buildAndBroadcastReclaim-O6z9kvc4.js.map → buildAndBroadcastReclaim-OMvihzJg.js.map} +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.js +8 -8
- package/dist/noPayout-DAWBQ0eG.cjs +2 -0
- package/dist/noPayout-DAWBQ0eG.cjs.map +1 -0
- package/dist/{noPayout-DiGr4eas.js → noPayout-qBXWKwav.js} +3 -3
- package/dist/noPayout-qBXWKwav.js.map +1 -0
- package/dist/{parseFundingOutpoints-B4iQeX6q.cjs → parseFundingOutpoints-BwC3foxS.cjs} +2 -2
- package/dist/parseFundingOutpoints-BwC3foxS.cjs.map +1 -0
- package/dist/{parseFundingOutpoints-BQWvINfm.js → parseFundingOutpoints-CC4NKYz2.js} +19 -19
- package/dist/parseFundingOutpoints-CC4NKYz2.js.map +1 -0
- package/dist/shared/index.cjs.map +1 -1
- package/dist/shared/index.js.map +1 -1
- package/dist/shared/wallets/interfaces/BitcoinWallet.d.ts +6 -3
- package/dist/shared/wallets/interfaces/BitcoinWallet.d.ts.map +1 -1
- package/dist/{signPsbtsWithFallback-f7QLp0q8.js → signPsbtsWithFallback-DoRbHHua.js} +2 -2
- package/dist/{signPsbtsWithFallback-f7QLp0q8.js.map → signPsbtsWithFallback-DoRbHHua.js.map} +1 -1
- package/dist/{signPsbtsWithFallback-DtwzL5AA.cjs → signPsbtsWithFallback-FwrTYZS4.cjs} +2 -2
- package/dist/{signPsbtsWithFallback-DtwzL5AA.cjs.map → signPsbtsWithFallback-FwrTYZS4.cjs.map} +1 -1
- package/dist/tbv/core/index.cjs +1 -1
- package/dist/tbv/core/index.d.ts +1 -1
- package/dist/tbv/core/index.js +8 -8
- package/dist/tbv/core/managers/index.cjs +1 -1
- package/dist/tbv/core/managers/index.js +2 -2
- package/dist/tbv/core/primitives/index.cjs +1 -1
- package/dist/tbv/core/primitives/index.js +3 -3
- package/dist/tbv/core/primitives/psbt/__tests__/assertPeginTxShape.test.d.ts +5 -3
- package/dist/tbv/core/primitives/psbt/__tests__/assertPeginTxShape.test.d.ts.map +1 -1
- package/dist/tbv/core/primitives/psbt/__tests__/deriveExpectedPeginPayoutScriptPubKey.test.d.ts +8 -0
- package/dist/tbv/core/primitives/psbt/__tests__/deriveExpectedPeginPayoutScriptPubKey.test.d.ts.map +1 -0
- package/dist/tbv/core/primitives/psbt/assertWasmPeginSizing.d.ts +6 -0
- package/dist/tbv/core/primitives/psbt/assertWasmPeginSizing.d.ts.map +1 -1
- package/dist/tbv/core/primitives/psbt/pegin.d.ts +4 -1
- package/dist/tbv/core/primitives/psbt/pegin.d.ts.map +1 -1
- package/dist/tbv/core/recovery/recoveryErrors.d.ts +1 -1
- package/dist/tbv/core/services/index.cjs +1 -1
- package/dist/tbv/core/services/index.js +2 -2
- package/dist/tbv/core/vault-secrets/__tests__/context.golden.test.d.ts +4 -4
- package/dist/tbv/core/vault-secrets/__tests__/context.test.d.ts +1 -2
- package/dist/tbv/core/vault-secrets/__tests__/context.test.d.ts.map +1 -1
- package/dist/tbv/core/vault-secrets/__tests__/deriveContextHash.vectors.test.d.ts +40 -0
- package/dist/tbv/core/vault-secrets/__tests__/deriveContextHash.vectors.test.d.ts.map +1 -0
- package/dist/tbv/core/vault-secrets/context.d.ts +2 -2
- package/dist/tbv/core/vault-secrets/deriveVaultRoot.d.ts +5 -6
- package/dist/tbv/core/vault-secrets/deriveVaultRoot.d.ts.map +1 -1
- package/dist/tbv/core/vault-secrets/index.cjs +1 -1
- package/dist/tbv/core/vault-secrets/index.d.ts +2 -2
- package/dist/tbv/core/vault-secrets/index.js +1 -1
- package/dist/tbv/core/wasm/index.cjs +1 -1
- package/dist/tbv/core/wasm/index.cjs.map +1 -1
- package/dist/tbv/core/wasm/index.d.ts +11 -9
- package/dist/tbv/core/wasm/index.d.ts.map +1 -1
- package/dist/tbv/core/wasm/index.js +68 -79
- package/dist/tbv/core/wasm/index.js.map +1 -1
- package/dist/tbv/index.cjs +1 -1
- package/dist/tbv/index.js +8 -8
- package/dist/tbv/integrations/aave/clients/index.d.ts +1 -1
- package/dist/tbv/integrations/aave/clients/index.d.ts.map +1 -1
- package/dist/tbv/integrations/aave/clients/spoke.d.ts +13 -0
- package/dist/tbv/integrations/aave/clients/spoke.d.ts.map +1 -1
- package/dist/tbv/integrations/aave/index.cjs +1 -1
- package/dist/tbv/integrations/aave/index.cjs.map +1 -1
- package/dist/tbv/integrations/aave/index.d.ts +1 -1
- package/dist/tbv/integrations/aave/index.d.ts.map +1 -1
- package/dist/tbv/integrations/aave/index.js +137 -125
- package/dist/tbv/integrations/aave/index.js.map +1 -1
- package/dist/testing/MockBitcoinWallet.d.ts +1 -1
- package/dist/testing/index.cjs.map +1 -1
- package/dist/testing/index.js.map +1 -1
- package/dist/{toRefundInputs-9inv4Ai4.js → toRefundInputs-BEulLgN_.js} +5 -5
- package/dist/toRefundInputs-BEulLgN_.js.map +1 -0
- package/dist/{toRefundInputs-DitGWAnz.cjs → toRefundInputs-DEPXcrgO.cjs} +2 -2
- package/dist/toRefundInputs-DEPXcrgO.cjs.map +1 -0
- package/dist/{verifyKeyPathSchnorrSignature-BVtNwgK6.js → verifyKeyPathSchnorrSignature-BQHNhRj6.js} +2 -2
- package/dist/{verifyKeyPathSchnorrSignature-BVtNwgK6.js.map → verifyKeyPathSchnorrSignature-BQHNhRj6.js.map} +1 -1
- package/dist/{verifyKeyPathSchnorrSignature-BjB8Znly.cjs → verifyKeyPathSchnorrSignature-Gm9EmZkx.cjs} +2 -2
- package/dist/{verifyKeyPathSchnorrSignature-BjB8Znly.cjs.map → verifyKeyPathSchnorrSignature-Gm9EmZkx.cjs.map} +1 -1
- package/dist/verifyScriptPathSchnorrSignature-BKZihCjk.cjs +2 -0
- package/dist/verifyScriptPathSchnorrSignature-BKZihCjk.cjs.map +1 -0
- package/dist/{verifyScriptPathSchnorrSignature-D_epga4j.js → verifyScriptPathSchnorrSignature-CpjSTfMj.js} +371 -330
- package/dist/verifyScriptPathSchnorrSignature-CpjSTfMj.js.map +1 -0
- package/package.json +4 -4
- package/dist/noPayout-4RZB2g1e.cjs +0 -2
- package/dist/noPayout-4RZB2g1e.cjs.map +0 -1
- package/dist/noPayout-DiGr4eas.js.map +0 -1
- package/dist/parseFundingOutpoints-B4iQeX6q.cjs.map +0 -1
- package/dist/parseFundingOutpoints-BQWvINfm.js.map +0 -1
- package/dist/toRefundInputs-9inv4Ai4.js.map +0 -1
- package/dist/toRefundInputs-DitGWAnz.cjs.map +0 -1
- package/dist/verifyScriptPathSchnorrSignature-D_epga4j.js.map +0 -1
- package/dist/verifyScriptPathSchnorrSignature-DaRqvEgW.cjs +0 -2
- package/dist/verifyScriptPathSchnorrSignature-DaRqvEgW.cjs.map +0 -1
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Conformance vectors for the wallet-side `deriveContextHash` API that
|
|
3
|
+
* `deriveVaultRoot` consumes.
|
|
4
|
+
*
|
|
5
|
+
* No adapter in this repository runs the derivation; it runs inside the
|
|
6
|
+
* wallet (the Ledger vault app, the Keystone firmware, OneKey, UniSat).
|
|
7
|
+
* This file therefore carries a reference implementation and pins its
|
|
8
|
+
* outputs. Every conforming wallet MUST reproduce them. Any change here
|
|
9
|
+
* is a hard fork (CLAUDE.md, "Critical paths", section 4).
|
|
10
|
+
*
|
|
11
|
+
* ```
|
|
12
|
+
* ikm = BIP-32 private key at path m/73681862'
|
|
13
|
+
* salt = "derive-context-hash" (UTF-8)
|
|
14
|
+
* info = SHA-256(UTF8(appName)) (32 bytes)
|
|
15
|
+
* || SHA-256(UTF8(canonicalNetworkName)) (32 bytes)
|
|
16
|
+
* || connectedPubkey (33 bytes, compressed SEC1)
|
|
17
|
+
* || context (raw bytes, decoded from hex)
|
|
18
|
+
* output = HKDF-SHA-256(ikm, salt, info, 32) (64 lowercase hex chars)
|
|
19
|
+
* ```
|
|
20
|
+
*
|
|
21
|
+
* `canonicalNetworkName` is one of `bitcoin-mainnet`, `bitcoin-testnet`
|
|
22
|
+
* (testnet3 and testnet4 share it), `bitcoin-signet`, `bitcoin-regtest`.
|
|
23
|
+
* `appName` matches `[a-z0-9-]{1,64}`; `context` is non-empty lowercase hex
|
|
24
|
+
* of even length, no `0x` prefix, at most 1024 bytes.
|
|
25
|
+
*
|
|
26
|
+
* The purpose index 73681862 is `trunc31_be(SHA-256("derive-context-hash"))`.
|
|
27
|
+
* `ikm` is the raw 32-byte big-endian private-key scalar at that path (no
|
|
28
|
+
* chain code, no serialization prefix); an invalid BIP-32 child is an error,
|
|
29
|
+
* not a skip to the next index, and the path is never used for signing or
|
|
30
|
+
* any other derivation. `connectedPubkey` is the compressed SEC1 form of the
|
|
31
|
+
* key the wallet returned to the dApp as the active connected key for this
|
|
32
|
+
* request (the BIP-44 leaf below is only the fixture for this vector).
|
|
33
|
+
* Imported (non-HD) keys use the raw private key as `ikm`; MPC and other
|
|
34
|
+
* non-HD wallets may use their own deterministic derivation, as long as the
|
|
35
|
+
* output is 32 bytes, depends on the key material and on all four inputs,
|
|
36
|
+
* and stays stable across share refreshes that keep the same public key.
|
|
37
|
+
* Neither is portable to an HD wallet restored from the same phrase.
|
|
38
|
+
*/
|
|
39
|
+
export {};
|
|
40
|
+
//# sourceMappingURL=deriveContextHash.vectors.test.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"deriveContextHash.vectors.test.d.ts","sourceRoot":"","sources":["../../../../../src/tbv/core/vault-secrets/__tests__/deriveContextHash.vectors.test.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqCG"}
|
|
@@ -2,8 +2,7 @@ import { VaultContextInput } from './context';
|
|
|
2
2
|
/**
|
|
3
3
|
* The fixed `appName` passed to the wallet's `deriveContextHash` for
|
|
4
4
|
* Babylon vault derivations. The wallet displays this in its approval
|
|
5
|
-
* dialog.
|
|
6
|
-
* changed without coordinating a spec revision and a downstream
|
|
5
|
+
* dialog. Frozen — must not be changed without a downstream
|
|
7
6
|
* migration plan, as it provides app-level domain separation across
|
|
8
7
|
* applications using the same wallet.
|
|
9
8
|
*/
|
|
@@ -28,13 +27,13 @@ export declare function forwardDeriveContextHash(wallet: Partial<DeriveContextHa
|
|
|
28
27
|
* `wallet.deriveContextHash`.
|
|
29
28
|
*
|
|
30
29
|
* Validates the wallet's output strictly: must be exactly 64
|
|
31
|
-
* lowercase hex characters
|
|
30
|
+
* lowercase hex characters, as the `deriveContextHash` contract requires. A
|
|
32
31
|
* conformant wallet always satisfies this, but we re-check at the
|
|
33
32
|
* SDK boundary so a non-conformant wallet (or a wallet returning a
|
|
34
33
|
* malformed value through a buggy adapter) fails loud here rather
|
|
35
34
|
* than producing silently-wrong derived secrets downstream.
|
|
36
35
|
*
|
|
37
|
-
* The helper itself produces only valid
|
|
36
|
+
* The helper itself produces only valid `deriveContextHash` inputs (`appName` is
|
|
38
37
|
* the hardcoded `VAULT_APP_NAME`; `context` is hex of the 72-byte
|
|
39
38
|
* `vaultContext`, always 144 chars lowercase), so input-side
|
|
40
39
|
* validation is unnecessary.
|
|
@@ -47,8 +46,8 @@ export declare function forwardDeriveContextHash(wallet: Partial<DeriveContextHa
|
|
|
47
46
|
* @stability frozen — on-chain-binding. The pair (`VAULT_APP_NAME`,
|
|
48
47
|
* `vaultContext` encoding) is the wallet's input space; changing
|
|
49
48
|
* either rotates the root and invalidates every secret derived from
|
|
50
|
-
* it. `VAULT_APP_NAME` is
|
|
51
|
-
*
|
|
49
|
+
* it. `VAULT_APP_NAME` is frozen and must never change without a
|
|
50
|
+
* downstream migration plan.
|
|
52
51
|
*
|
|
53
52
|
* @returns 32-byte root suitable for {@link expandAuthAnchor},
|
|
54
53
|
* {@link expandHashlockSecret}, {@link expandWotsSeed}.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"deriveVaultRoot.d.ts","sourceRoot":"","sources":["../../../../src/tbv/core/vault-secrets/deriveVaultRoot.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"deriveVaultRoot.d.ts","sourceRoot":"","sources":["../../../../src/tbv/core/vault-secrets/deriveVaultRoot.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAIH,OAAO,EAAqB,KAAK,iBAAiB,EAAE,MAAM,WAAW,CAAC;AAEtE;;;;;;GAMG;AACH,eAAO,MAAM,cAAc,sBAAsB,CAAC;AAUlD;;;;;;GAMG;AACH,MAAM,WAAW,8BAA8B;IAC7C,iBAAiB,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;CACtE;AAED;;kCAEkC;AAClC,wBAAgB,wBAAwB,CACtC,MAAM,EAAE,OAAO,CAAC,8BAA8B,CAAC,GAC9C,OAAO,CAAC,8BAA8B,CAAC,CAWzC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AACH,wBAAsB,eAAe,CACnC,MAAM,EAAE,8BAA8B,EACtC,KAAK,EAAE,iBAAiB,GACvB,OAAO,CAAC,UAAU,CAAC,CAuBrB"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("../wasm/index.cjs"),e=require("../../../parseFundingOutpoints-
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("../wasm/index.cjs"),e=require("../../../parseFundingOutpoints-BwC3foxS.cjs");exports.expandAuthAnchor=t.expandAuthAnchor;exports.expandHashlockSecret=t.expandHashlockSecret;exports.expandWotsSeed=t.expandWotsSeed;exports.VAULT_APP_NAME=e.VAULT_APP_NAME;exports.buildFundingOutpointsCommitment=e.buildFundingOutpointsCommitment;exports.buildVaultContext=e.buildVaultContext;exports.deriveVaultRoot=e.deriveVaultRoot;exports.forwardDeriveContextHash=e.forwardDeriveContextHash;exports.parseFundingOutpointsFromTx=e.parseFundingOutpointsFromTx;
|
|
2
2
|
//# sourceMappingURL=index.cjs.map
|
|
@@ -3,8 +3,8 @@
|
|
|
3
3
|
* secrets (HTLC hashlock preimage, depositor auth anchor, WOTS seed)
|
|
4
4
|
* from a single 32-byte root.
|
|
5
5
|
*
|
|
6
|
-
* Implements
|
|
7
|
-
*
|
|
6
|
+
* Implements the root-to-leaf expansion pinned by `__tests__/expand.test.ts`.
|
|
7
|
+
* The root is opaque to the expanders — callers produce it from `wallet.deriveContextHash` via
|
|
8
8
|
* {@link deriveVaultRoot} (canonical path), or from any other source
|
|
9
9
|
* that yields 32 bytes. The SDK is provenance-agnostic and only
|
|
10
10
|
* consumes the 32 bytes.
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { expandAuthAnchor as a, expandHashlockSecret as o, expandWotsSeed as n } from "../wasm/index.js";
|
|
2
|
-
import { V as s, b as d, a as i, d as p, f as u, p as x } from "../../../parseFundingOutpoints-
|
|
2
|
+
import { V as s, b as d, a as i, d as p, f as u, p as x } from "../../../parseFundingOutpoints-CC4NKYz2.js";
|
|
3
3
|
export {
|
|
4
4
|
s as VAULT_APP_NAME,
|
|
5
5
|
d as buildFundingOutpointsCommitment,
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var d=Object.create;var l=Object.defineProperty;var p=Object.getOwnPropertyDescriptor;var y=Object.getOwnPropertyNames;var f=Object.getPrototypeOf,h=Object.prototype.hasOwnProperty;var b=(e,t,a,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of y(t))!h.call(e,o)&&o!==a&&l(e,o,{get:()=>t[o],enumerable:!(r=p(t,o))||r.enumerable});return e};var m=(e,t,a)=>(a=e!=null?d(f(e)):{},b(t||!e||!e.__esModule?l(a,"default",{value:e,enumerable:!0}):a,e));Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s="50929b74c1a04954b78b4b6035e97a5e078a5a0f28ec96d547bfee9ace803ac0",i=2,A=Uint8Array.from({length:s.length/i},(e,t)=>Number.parseInt(s.slice(t*i,t*i+i),16));let c;function n(){return c??(c=import("@babylonlabs-io/babylon-tbv-rust-wasm").catch(e=>{throw c=void 0,new Error("The vault-WASM engine @babylonlabs-io/babylon-tbv-rust-wasm failed to load. The module could not be resolved, or it threw while evaluating, commonly a missing or stale generated WASM build. See the cause for the underlying error.",{cause:e})}).then(async e=>{try{await e.initWasm()}catch(t){throw c=void 0,new Error("The vault-WASM engine @babylonlabs-io/babylon-tbv-rust-wasm resolved, but its WebAssembly binary failed to initialize, commonly a missing or stale generated WASM build. See the cause for the underlying error.",{cause:t})}return e})),c}async function w(e){return(await n()).createPrePeginTransaction(e)}async function S(e,t,a,r){return(await n()).buildPeginTxFromPrePegin(e,t,a,r)}async function I(e){return(await n()).getPrePeginHtlcConnectorInfo(e)}async function T(e,t,a,r,o,u){return(await n()).computeMinClaimValue(e,t,a,r,o,u)}async function v(e,t,a,r){return(await n()).computeMinPeginFee(e,t,a,r)}async function x(e,t,a,r,o,u,P,g){return(await n()).computePayoutFeeFloor(e,t,a,r,o,u,P,g)}async function C(){return(await n()).supportedTxGraphVersions()}async function F(e){return(await n()).peginP2aAnchorOutput(e)}async function M(e,t){return(await n()).validatePeginP2aAnchor(e,t)}async function W(e,t){return(await n()).createPayoutConnector(e,t)}async function E(e){return(await n()).getAssertPayoutScriptInfo(e)}async function V(e,t){return(await n()).getAssertNoPayoutScriptInfo(e,t)}async function H(e){return(await n()).getChallengeAssertScriptInfo(e)}async function N(e){return(await n()).expandAuthAnchor(e)}async function _(e,t){return(await n()).expandHashlockSecret(e,t)}async function k(e,t){return(await n()).expandWotsSeed(e,t)}async function O(e,t){return(await n()).deriveVaultId(e,t)}exports.TAP_INTERNAL_KEY=s;exports.buildPeginTxFromPrePegin=S;exports.computeMinClaimValue=T;exports.computeMinPeginFee=v;exports.computePayoutFeeFloor=x;exports.createPayoutConnector=W;exports.createPrePeginTransaction=w;exports.deriveVaultId=O;exports.expandAuthAnchor=N;exports.expandHashlockSecret=_;exports.expandWotsSeed=k;exports.getAssertNoPayoutScriptInfo=V;exports.getAssertPayoutScriptInfo=E;exports.getChallengeAssertScriptInfo=H;exports.getPrePeginHtlcConnectorInfo=I;exports.loadTbvWasm=n;exports.peginP2aAnchorOutput=F;exports.supportedTxGraphVersions=C;exports.tapInternalPubkey=A;exports.validatePeginP2aAnchor=M;
|
|
2
2
|
//# sourceMappingURL=index.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","sources":["../../../../src/tbv/core/wasm/constants.ts","../../../../src/tbv/core/wasm/index.ts"],"sourcesContent":["/**\n * Protocol constants that do not require loading the vault WASM module.\n *\n * Keeping these values local lets Bitcoin builders construct PSBT metadata\n * without resolving or evaluating the WASM engine at module-import\n * time. The hex value is the BIP-341 nothing-up-my-sleeve internal key and is\n * pinned by the vault protocol.\n */\nexport const TAP_INTERNAL_KEY =\n \"50929b74c1a04954b78b4b6035e97a5e078a5a0f28ec96d547bfee9ace803ac0\";\n\nconst HEX_CHARS_PER_BYTE = 2;\n\nexport const tapInternalPubkey = Uint8Array.from(\n { length: TAP_INTERNAL_KEY.length / HEX_CHARS_PER_BYTE },\n (_, index) =>\n Number.parseInt(\n TAP_INTERNAL_KEY.slice(\n index * HEX_CHARS_PER_BYTE,\n index * HEX_CHARS_PER_BYTE + HEX_CHARS_PER_BYTE,\n ),\n 16,\n ),\n);\n","/**\n * Explicit lazy boundary around the vault-WASM engine package.\n *\n * Importing the SDK (including its legacy root barrels) does not resolve the\n * WASM package or generated binary. The engine is loaded only when a caller\n * invokes an operation that actually needs the Bitcoin transaction graph.\n * ETH-only entry points never import this module.\n *\n * @module tbv/core/wasm\n */\n\nimport type {\n AssertNoPayoutScriptInfo,\n AssertPayoutNoPayoutConnectorParams,\n AssertPayoutScriptInfo,\n ChallengeAssertConnectorParams,\n ChallengeAssertScriptInfo,\n HtlcConnectorInfo,\n HtlcConnectorParams,\n Network,\n PayoutConnectorInfo,\n PayoutConnectorParams,\n PeginP2aAnchorInfo,\n PeginTxResult,\n PrePeginParams,\n PrePeginResult,\n} from \"@babylonlabs-io/babylon-tbv-rust-wasm\";\n\nexport { TAP_INTERNAL_KEY, tapInternalPubkey } from \"./constants\";\n\ntype TbvWasmModule = typeof import(\"@babylonlabs-io/babylon-tbv-rust-wasm\");\n\nlet wasmModulePromise: Promise<TbvWasmModule> | undefined;\ntype RawTbvWasmModule =\n typeof import(\"@babylonlabs-io/babylon-tbv-rust-wasm/raw\");\nlet rawWasmModulePromise: Promise<RawTbvWasmModule> | undefined;\n\n/** Load the WASM engine on first use and share the in-flight import. */\nexport function loadTbvWasm(): Promise<TbvWasmModule> {\n wasmModulePromise ??= import(\"@babylonlabs-io/babylon-tbv-rust-wasm\").catch(\n (error: unknown) => {\n wasmModulePromise = undefined;\n throw new Error(\n \"The vault-WASM engine @babylonlabs-io/babylon-tbv-rust-wasm failed \" +\n \"to load. The module could not be resolved, or it threw while \" +\n \"evaluating, commonly a missing or stale generated WASM build. \" +\n \"See the cause for the underlying error.\",\n { cause: error },\n );\n },\n );\n return wasmModulePromise;\n}\n\n/**\n * Load and initialize the raw engine classes. This bypasses SDK value checks.\n * The internal refund builder applies equivalent checks at its call site.\n *\n * @deprecated Use buildPrePeginPsbt, buildPeginTxFromFundedPrePegin, or\n * buildRefundPsbt from @babylonlabs-io/ts-sdk/tbv/core/primitives.\n * Raw callers must independently check transaction values and signing data.\n */\nexport function loadRawTbvWasm(): Promise<RawTbvWasmModule> {\n rawWasmModulePromise ??= import(\"@babylonlabs-io/babylon-tbv-rust-wasm/raw\")\n .catch((error: unknown) => {\n rawWasmModulePromise = undefined;\n throw new Error(\n \"The raw vault-WASM entry @babylonlabs-io/babylon-tbv-rust-wasm/raw \" +\n \"failed to load. The module could not be resolved, or it threw \" +\n \"while evaluating. See the cause for the underlying error.\",\n { cause: error },\n );\n })\n .then(async (wasm) => {\n try {\n await wasm.initWasm();\n } catch (error: unknown) {\n rawWasmModulePromise = undefined;\n throw new Error(\n \"The raw vault-WASM entry resolved but its WebAssembly \" +\n \"binary failed to initialize.\",\n { cause: error },\n );\n }\n return wasm;\n });\n return rawWasmModulePromise;\n}\n\n/**\n * Creates an unfunded Pre-PegIn transaction with no inputs and HTLC output(s).\n *\n * The HTLC output value (htlcValue) covers the peg-in amount, depositor claim value,\n * and minimum pegin fee — all computed internally from the provided contract parameters.\n *\n * After building the Pre-PegIn transaction, the caller must:\n * 1. Select UTXOs covering htlcValue + network fees\n * 2. Fund the transaction (add inputs and change output)\n * 3. Call reconstructFromFundedTx() with the funded tx hex\n * 4. Call buildPeginTx() to derive the PegIn transaction\n * 5. Sign the PegIn input using the HTLC hashlock leaf (leaf 0)\n *\n * @param params - Pre-PegIn parameters from contract and depositor wallet\n * @returns Unfunded transaction details with HTLC output information\n */\nexport async function createPrePeginTransaction(\n params: PrePeginParams,\n): Promise<PrePeginResult> {\n return (await loadTbvWasm()).createPrePeginTransaction(params);\n}\n\n/**\n * Derives the PegIn transaction from a funded Pre-PegIn transaction.\n *\n * The PegIn transaction has a single input spending the Pre-PegIn HTLC output\n * at `htlcVout` via the hashlock + all-party script (leaf 0).\n *\n * @param params - Same PrePeginParams used to create the Pre-PegIn transaction\n * @param timelockPegin - CSV timelock in blocks for the PegIn vault output\n * @param fundedPrePeginTxHex - Hex-encoded funded Pre-PegIn transaction\n * @param htlcVout - Index of the HTLC output to spend\n * @returns PegIn transaction details including vault output information\n */\nexport async function buildPeginTxFromPrePegin(\n params: PrePeginParams,\n timelockPegin: number,\n fundedPrePeginTxHex: string,\n htlcVout: number,\n): Promise<PeginTxResult> {\n return (await loadTbvWasm()).buildPeginTxFromPrePegin(\n params,\n timelockPegin,\n fundedPrePeginTxHex,\n htlcVout,\n );\n}\n\n/**\n * Returns HTLC connector script info for signing the PegIn transaction input.\n *\n * The depositor signs PegIn input 0 using the hashlock leaf (leaf 0) of the\n * Pre-PegIn HTLC output. Use getHashlockScript() and getHashlockControlBlock()\n * to construct the tapLeafScript entry in the PSBT.\n *\n * @param params - HTLC connector parameters (subset of PrePeginParams)\n * @returns Hashlock and refund script info for PSBT construction\n */\nexport async function getPrePeginHtlcConnectorInfo(\n params: HtlcConnectorParams,\n): Promise<HtlcConnectorInfo> {\n return (await loadTbvWasm()).getPrePeginHtlcConnectorInfo(params);\n}\n\n/**\n * Compute the minimum depositor claim value (PegIn output 1) in satoshis.\n *\n * This covers the full downstream tx graph cost (Claim → Assert → Payout)\n * based on the protocol parameters.\n */\nexport async function computeMinClaimValue(\n txGraphVersion: number,\n numLocalChallengers: number,\n numUniversalChallengers: number,\n councilQuorum: number,\n councilSize: number,\n feeRate: bigint,\n): Promise<bigint> {\n return (await loadTbvWasm()).computeMinClaimValue(\n txGraphVersion,\n numLocalChallengers,\n numUniversalChallengers,\n councilQuorum,\n councilSize,\n feeRate,\n );\n}\n\n/**\n * Compute the minimum PegIn (activation) transaction fee in satoshis.\n *\n * `minPeginFee = peginTxVsize(numVks, numUcs) × minPeginFeeRate`. Each HTLC\n * the depositor funds in the Pre-PegIn tx must reserve at least this fee\n * inside its value (`htlcValue = peginAmount + depositorClaimValue +\n * minPeginFee`), otherwise the VP cannot afford to broadcast the PegIn at\n * activation. The vsize comes from a Taproot script-path-spend weight\n * prediction whose witness shape depends on the VK + UC signer count.\n */\nexport async function computeMinPeginFee(\n txGraphVersion: number,\n numVks: number,\n numUcs: number,\n minPeginFeeRate: bigint,\n): Promise<bigint> {\n return (await loadTbvWasm()).computeMinPeginFee(\n txGraphVersion,\n numVks,\n numUcs,\n minPeginFeeRate,\n );\n}\n\n/**\n * Floor of the Payout transaction fee under `txGraphVersion`: the minimum of\n * `estimatedVsize * feeRate` across every output-sizing model a deployed\n * vault provider is known to have used (fixed-34, intermediate,\n * script-aware). A VP-built payout paying less than this is provably not\n * produced by any known VP build. `out0Len` must be the TRUSTED length of the\n * pinned outs[0] script (1..=128); `out1Len` is the measured, UNTRUSTED\n * commission-script length — safe here because padding cannot raise the floor\n * (the fixed-34 model saturates the minimum) and shortening only lowers it.\n * Pass `undefined` for `out1Len` on 2-output (non-VP-claimer) payouts.\n * `feeRate` is the vault's version-locked `offchainParams.feeRate`.\n */\nexport async function computePayoutFeeFloor(\n txGraphVersion: number,\n numVaultKeepers: number,\n numUniversalChallengers: number,\n numLocalChallengers: number,\n councilSize: number,\n out0Len: number,\n out1Len: number | null | undefined,\n feeRate: bigint,\n): Promise<bigint> {\n return (await loadTbvWasm()).computePayoutFeeFloor(\n txGraphVersion,\n numVaultKeepers,\n numUniversalChallengers,\n numLocalChallengers,\n councilSize,\n out0Len,\n out1Len,\n feeRate,\n );\n}\n\n/**\n * Tx graph versions the shipped vault-wasm binary can build. Callers must\n * preflight the required version (fresh: active; resume: stamped) against\n * this list and fail closed instead of hitting per-call errors mid-flow.\n *\n * Note: the facade constructors themselves fail closed on unsupported\n * versions, and derived objects carry the version they were built with —\n * value-level cross-checks live in `assertWasmPeginSizing` and the golden\n * byte-parity tests, not in a per-call version echo.\n */\nexport async function supportedTxGraphVersions(): Promise<number[]> {\n return (await loadTbvWasm()).supportedTxGraphVersions();\n}\n\n/**\n * The PegIn transaction's P2A (pay-to-anchor) output for a graph version, or\n * `null` when that version's PegIn carries no anchor (v1). The facade returns\n * one record per version — never a zero-valued placeholder — so an absent\n * anchor can't be mistaken for a real output. For v2/v3: 240 sats at vout 2,\n * script `51024e73`.\n */\nexport async function peginP2aAnchorOutput(\n txGraphVersion: number,\n): Promise<PeginP2aAnchorInfo | null> {\n return (await loadTbvWasm()).peginP2aAnchorOutput(txGraphVersion);\n}\n\n/**\n * Validate a PegIn transaction's P2A anchor against a graph version's rules:\n * v2 and v3 require the exact anchor (240 sats, vout 2, P2A script) and v1\n * requires that NO output carries the P2A script. Throws on any mismatch — a\n * v2 PegIn checked as v1 fails closed, and vice versa.\n */\nexport async function validatePeginP2aAnchor(\n txGraphVersion: number,\n txHex: string,\n): Promise<void> {\n return (await loadTbvWasm()).validatePeginP2aAnchor(txGraphVersion, txHex);\n}\n\n/**\n * Creates a payout connector for vault transactions.\n *\n * The payout connector generates the necessary taproot scripts and information\n * required for signing payout transactions (both optimistic and regular payout paths).\n *\n * @param params - Parameters for creating the payout connector\n * @param network - Bitcoin network\n * @returns Payout connector information including scripts, hashes, and address\n */\nexport async function createPayoutConnector(\n params: PayoutConnectorParams,\n network: Network,\n): Promise<PayoutConnectorInfo> {\n return (await loadTbvWasm()).createPayoutConnector(params, network);\n}\n\n/**\n * Get the Payout script and control block for the depositor's Assert output.\n *\n * Used to build the depositor's Payout PSBT (depositor-as-claimer path).\n *\n * @param params - Assert Payout/NoPayout connector parameters\n * @returns Payout script and control block (hex encoded)\n */\nexport async function getAssertPayoutScriptInfo(\n params: AssertPayoutNoPayoutConnectorParams,\n): Promise<AssertPayoutScriptInfo> {\n return (await loadTbvWasm()).getAssertPayoutScriptInfo(params);\n}\n\n/**\n * Get the NoPayout script and control block for a specific challenger.\n *\n * Used to build the depositor's NoPayout PSBT (depositor-as-claimer path).\n * Each challenger has a distinct NoPayout script.\n *\n * @param params - Assert Payout/NoPayout connector parameters\n * @param challengerPubkey - The challenger's x-only public key (hex encoded)\n * @returns NoPayout script and control block (hex encoded)\n */\nexport async function getAssertNoPayoutScriptInfo(\n params: AssertPayoutNoPayoutConnectorParams,\n challengerPubkey: string,\n): Promise<AssertNoPayoutScriptInfo> {\n return (await loadTbvWasm()).getAssertNoPayoutScriptInfo(\n params,\n challengerPubkey,\n );\n}\n\n/**\n * Get the ChallengeAssert script and control block.\n *\n * Used to build ChallengeAssert PSBTs for the depositor-as-claimer path.\n * Each challenger has 3 ChallengeAssert transactions, and this connector\n * generates the spending scripts using WOTS public keys from the VP.\n *\n * @param params - ChallengeAssert connector parameters\n * @returns Script and control block (hex encoded)\n */\nexport async function getChallengeAssertScriptInfo(\n params: ChallengeAssertConnectorParams,\n): Promise<ChallengeAssertScriptInfo> {\n return (await loadTbvWasm()).getChallengeAssertScriptInfo(params);\n}\n\n/**\n * Derive 32-byte `authAnchor` (OP_RETURN preimage → VP bearer token).\n * @stability frozen - btc-vault Rust owns this API through the vault-wasm pin (`VAULT_WASM_COMMIT`).\n * Changing the derived bytes breaks VP auth for existing deposits. See CLAUDE.md §4.\n */\nexport async function expandAuthAnchor(root: Uint8Array): Promise<Uint8Array> {\n return (await loadTbvWasm()).expandAuthAnchor(root);\n}\n\n/**\n * Derive 32-byte `hashlockSecret` for HTLC `htlcVout` (preimage → `activateVaultWithSecret`).\n * @stability frozen - btc-vault Rust owns this API.\n * Changing the derived bytes means affected vaults can never activate. See CLAUDE.md §4.\n */\nexport async function expandHashlockSecret(\n root: Uint8Array,\n htlcVout: number,\n): Promise<Uint8Array> {\n return (await loadTbvWasm()).expandHashlockSecret(root, htlcVout);\n}\n\n/**\n * Derive 64-byte `wotsSeed` for HTLC `htlcVout` (→ WOTS keys, hashed as `depositorWotsPkHash`).\n * @stability frozen - btc-vault Rust owns this API.\n * Changing the derived bytes breaks existing `depositorWotsPkHash` values. No claim path remains. See CLAUDE.md §4.\n */\nexport async function expandWotsSeed(\n root: Uint8Array,\n htlcVout: number,\n): Promise<Uint8Array> {\n return (await loadTbvWasm()).expandWotsSeed(root, htlcVout);\n}\n\n/**\n * Derives the vault ID from a PegIn transaction hash and depositor ETH address.\n *\n * Vault ID = keccak256(abi.encode(peginTxHash, depositor))\n * This matches the Solidity-side derivation in BTCVaultRegistry.\n *\n * @param peginTxHash - 32-byte PegIn tx hash in display order (big-endian), hex encoded\n * @param depositor - 20-byte Ethereum address of the depositor, hex encoded\n * @returns Hex-encoded vault ID (32 bytes)\n */\nexport async function deriveVaultId(\n peginTxHash: string,\n depositor: string,\n): Promise<string> {\n return (await loadTbvWasm()).deriveVaultId(peginTxHash, depositor);\n}\n\nexport type {\n AssertNoPayoutScriptInfo,\n AssertPayoutNoPayoutConnectorParams,\n AssertPayoutScriptInfo,\n ChallengeAssertConnectorParams,\n ChallengeAssertScriptInfo,\n HtlcConnectorInfo,\n HtlcConnectorParams,\n Network,\n PayoutConnectorInfo,\n PayoutConnectorParams,\n PeginP2aAnchorInfo,\n PeginTxResult,\n PrePeginParams,\n PrePeginResult,\n};\n"],"names":["TAP_INTERNAL_KEY","HEX_CHARS_PER_BYTE","tapInternalPubkey","_","index","wasmModulePromise","rawWasmModulePromise","loadTbvWasm","error","loadRawTbvWasm","wasm","createPrePeginTransaction","params","buildPeginTxFromPrePegin","timelockPegin","fundedPrePeginTxHex","htlcVout","getPrePeginHtlcConnectorInfo","computeMinClaimValue","txGraphVersion","numLocalChallengers","numUniversalChallengers","councilQuorum","councilSize","feeRate","computeMinPeginFee","numVks","numUcs","minPeginFeeRate","computePayoutFeeFloor","numVaultKeepers","out0Len","out1Len","supportedTxGraphVersions","peginP2aAnchorOutput","validatePeginP2aAnchor","txHex","createPayoutConnector","network","getAssertPayoutScriptInfo","getAssertNoPayoutScriptInfo","challengerPubkey","getChallengeAssertScriptInfo","expandAuthAnchor","root","expandHashlockSecret","expandWotsSeed","deriveVaultId","peginTxHash","depositor"],"mappings":"2hBAQO,MAAMA,EACX,mEAEIC,EAAqB,EAEdC,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BV,EACAW,EACAT,EACAD,EACAG,EACAQ,EACAC,EACAR,EACiB,CACjB,OAAQ,MAAMjB,KAAe,sBAC3BY,EACAW,EACAT,EACAD,EACAG,EACAQ,EACAC,EACAR,CAAA,CAEJ,CAYA,eAAsBS,GAA8C,CAClE,OAAQ,MAAM1B,EAAA,GAAe,yBAAA,CAC/B,CASA,eAAsB2B,EACpBf,EACoC,CACpC,OAAQ,MAAMZ,KAAe,qBAAqBY,CAAc,CAClE,CAQA,eAAsBgB,EACpBhB,EACAiB,EACe,CACf,OAAQ,MAAM7B,EAAA,GAAe,uBAAuBY,EAAgBiB,CAAK,CAC3E,CAYA,eAAsBC,EACpBzB,EACA0B,EAC8B,CAC9B,OAAQ,MAAM/B,EAAA,GAAe,sBAAsBK,EAAQ0B,CAAO,CACpE,CAUA,eAAsBC,EACpB3B,EACiC,CACjC,OAAQ,MAAML,KAAe,0BAA0BK,CAAM,CAC/D,CAYA,eAAsB4B,EACpB5B,EACA6B,EACmC,CACnC,OAAQ,MAAMlC,KAAe,4BAC3BK,EACA6B,CAAA,CAEJ,CAYA,eAAsBC,EACpB9B,EACoC,CACpC,OAAQ,MAAML,KAAe,6BAA6BK,CAAM,CAClE,CAOA,eAAsB+B,EAAiBC,EAAuC,CAC5E,OAAQ,MAAMrC,KAAe,iBAAiBqC,CAAI,CACpD,CAOA,eAAsBC,EACpBD,EACA5B,EACqB,CACrB,OAAQ,MAAMT,EAAA,GAAe,qBAAqBqC,EAAM5B,CAAQ,CAClE,CAOA,eAAsB8B,EACpBF,EACA5B,EACqB,CACrB,OAAQ,MAAMT,EAAA,GAAe,eAAeqC,EAAM5B,CAAQ,CAC5D,CAYA,eAAsB+B,EACpBC,EACAC,EACiB,CACjB,OAAQ,MAAM1C,EAAA,GAAe,cAAcyC,EAAaC,CAAS,CACnE"}
|
|
1
|
+
{"version":3,"file":"index.cjs","sources":["../../../../src/tbv/core/wasm/constants.ts","../../../../src/tbv/core/wasm/index.ts"],"sourcesContent":["/**\n * Protocol constants that do not require loading the vault WASM module.\n *\n * Keeping these values local lets Bitcoin builders construct PSBT metadata\n * without resolving or evaluating the WASM engine at module-import\n * time. The hex value is the BIP-341 nothing-up-my-sleeve internal key and is\n * pinned by the vault protocol.\n */\nexport const TAP_INTERNAL_KEY =\n \"50929b74c1a04954b78b4b6035e97a5e078a5a0f28ec96d547bfee9ace803ac0\";\n\nconst HEX_CHARS_PER_BYTE = 2;\n\nexport const tapInternalPubkey = Uint8Array.from(\n { length: TAP_INTERNAL_KEY.length / HEX_CHARS_PER_BYTE },\n (_, index) =>\n Number.parseInt(\n TAP_INTERNAL_KEY.slice(\n index * HEX_CHARS_PER_BYTE,\n index * HEX_CHARS_PER_BYTE + HEX_CHARS_PER_BYTE,\n ),\n 16,\n ),\n);\n","/**\n * Explicit lazy boundary around the vault-WASM engine package.\n *\n * Importing the SDK (including its legacy root barrels) does not resolve the\n * WASM package or generated binary. The engine is loaded only when a caller\n * invokes an operation that actually needs the Bitcoin transaction graph.\n * ETH-only entry points never import this module.\n *\n * @module tbv/core/wasm\n */\n\nimport type {\n AssertNoPayoutScriptInfo,\n AssertPayoutNoPayoutConnectorParams,\n AssertPayoutScriptInfo,\n ChallengeAssertConnectorParams,\n ChallengeAssertScriptInfo,\n HtlcConnectorInfo,\n HtlcConnectorParams,\n Network,\n PayoutConnectorInfo,\n PayoutConnectorParams,\n PeginP2aAnchorInfo,\n PeginTxResult,\n PrePeginParams,\n PrePeginResult,\n} from \"@babylonlabs-io/babylon-tbv-rust-wasm\";\n\nexport { TAP_INTERNAL_KEY, tapInternalPubkey } from \"./constants\";\n\ntype TbvWasmModule = typeof import(\"@babylonlabs-io/babylon-tbv-rust-wasm\");\n\nlet wasmModulePromise: Promise<TbvWasmModule> | undefined;\n\n/**\n * Load and initialize the WASM engine on first use. Concurrent callers share\n * one load. The returned module is already initialized, so a caller does not\n * call `initWasm()`. A load or initialization failure rejects with an error\n * that names the engine package. The original error is its cause. A failure\n * clears this cache, so the next call loads again. The engine keeps a failed\n * binary initialization rejected, so only a failed import or binary read can\n * succeed on a later call.\n *\n * The module also contains the wasm-bindgen classes. The classes have no value\n * guards. A caller that uses a class must cross-check its output at the call\n * site.\n */\nexport function loadTbvWasm(): Promise<TbvWasmModule> {\n wasmModulePromise ??= import(\"@babylonlabs-io/babylon-tbv-rust-wasm\")\n .catch((error: unknown) => {\n wasmModulePromise = undefined;\n throw new Error(\n \"The vault-WASM engine @babylonlabs-io/babylon-tbv-rust-wasm failed \" +\n \"to load. The module could not be resolved, or it threw while \" +\n \"evaluating, commonly a missing or stale generated WASM build. \" +\n \"See the cause for the underlying error.\",\n { cause: error },\n );\n })\n .then(async (wasm) => {\n try {\n await wasm.initWasm();\n } catch (error: unknown) {\n wasmModulePromise = undefined;\n throw new Error(\n \"The vault-WASM engine @babylonlabs-io/babylon-tbv-rust-wasm \" +\n \"resolved, but its WebAssembly binary failed to initialize, \" +\n \"commonly a missing or stale generated WASM build. See the \" +\n \"cause for the underlying error.\",\n { cause: error },\n );\n }\n return wasm;\n });\n return wasmModulePromise;\n}\n\n/**\n * Creates an unfunded Pre-PegIn transaction with no inputs and HTLC output(s).\n *\n * The HTLC output value (htlcValue) covers the peg-in amount, depositor claim value,\n * and minimum pegin fee — all computed internally from the provided contract parameters.\n *\n * After building the Pre-PegIn transaction, the caller must:\n * 1. Select UTXOs covering htlcValue + network fees\n * 2. Fund the transaction (add inputs and change output)\n * 3. Call reconstructFromFundedTx() with the funded tx hex\n * 4. Call buildPeginTx() to derive the PegIn transaction\n * 5. Sign the PegIn input using the HTLC hashlock leaf (leaf 0)\n *\n * @param params - Pre-PegIn parameters from contract and depositor wallet\n * @returns Unfunded transaction details with HTLC output information\n */\nexport async function createPrePeginTransaction(\n params: PrePeginParams,\n): Promise<PrePeginResult> {\n return (await loadTbvWasm()).createPrePeginTransaction(params);\n}\n\n/**\n * Derives the PegIn transaction from a funded Pre-PegIn transaction.\n *\n * The PegIn transaction has a single input spending the Pre-PegIn HTLC output\n * at `htlcVout` via the hashlock + all-party script (leaf 0).\n *\n * @param params - Same PrePeginParams used to create the Pre-PegIn transaction\n * @param timelockPegin - CSV timelock in blocks for the PegIn vault output\n * @param fundedPrePeginTxHex - Hex-encoded funded Pre-PegIn transaction\n * @param htlcVout - Index of the HTLC output to spend\n * @returns PegIn transaction details including vault output information\n */\nexport async function buildPeginTxFromPrePegin(\n params: PrePeginParams,\n timelockPegin: number,\n fundedPrePeginTxHex: string,\n htlcVout: number,\n): Promise<PeginTxResult> {\n return (await loadTbvWasm()).buildPeginTxFromPrePegin(\n params,\n timelockPegin,\n fundedPrePeginTxHex,\n htlcVout,\n );\n}\n\n/**\n * Returns HTLC connector script info for signing the PegIn transaction input.\n *\n * The depositor signs PegIn input 0 using the hashlock leaf (leaf 0) of the\n * Pre-PegIn HTLC output. Use getHashlockScript() and getHashlockControlBlock()\n * to construct the tapLeafScript entry in the PSBT.\n *\n * @param params - HTLC connector parameters (subset of PrePeginParams)\n * @returns Hashlock and refund script info for PSBT construction\n */\nexport async function getPrePeginHtlcConnectorInfo(\n params: HtlcConnectorParams,\n): Promise<HtlcConnectorInfo> {\n return (await loadTbvWasm()).getPrePeginHtlcConnectorInfo(params);\n}\n\n/**\n * Compute the minimum depositor claim value (PegIn output 1) in satoshis.\n *\n * This covers the full downstream tx graph cost (Claim → Assert → Payout)\n * based on the protocol parameters.\n */\nexport async function computeMinClaimValue(\n txGraphVersion: number,\n numLocalChallengers: number,\n numUniversalChallengers: number,\n councilQuorum: number,\n councilSize: number,\n feeRate: bigint,\n): Promise<bigint> {\n return (await loadTbvWasm()).computeMinClaimValue(\n txGraphVersion,\n numLocalChallengers,\n numUniversalChallengers,\n councilQuorum,\n councilSize,\n feeRate,\n );\n}\n\n/**\n * Compute the minimum PegIn (activation) transaction fee in satoshis.\n *\n * `minPeginFee = peginTxVsize(numVks, numUcs) × minPeginFeeRate`. Each HTLC\n * the depositor funds in the Pre-PegIn tx must reserve at least this fee\n * inside its value (`htlcValue = peginAmount + depositorClaimValue +\n * minPeginFee`), otherwise the VP cannot afford to broadcast the PegIn at\n * activation. The vsize comes from a Taproot script-path-spend weight\n * prediction whose witness shape depends on the VK + UC signer count.\n */\nexport async function computeMinPeginFee(\n txGraphVersion: number,\n numVks: number,\n numUcs: number,\n minPeginFeeRate: bigint,\n): Promise<bigint> {\n return (await loadTbvWasm()).computeMinPeginFee(\n txGraphVersion,\n numVks,\n numUcs,\n minPeginFeeRate,\n );\n}\n\n/**\n * Floor of the Payout transaction fee under `txGraphVersion`: the minimum of\n * `estimatedVsize * feeRate` across every output-sizing model a deployed\n * vault provider is known to have used (fixed-34, intermediate,\n * script-aware). A VP-built payout paying less than this is provably not\n * produced by any known VP build. `out0Len` must be the TRUSTED length of the\n * pinned outs[0] script (1..=128); `out1Len` is the measured, UNTRUSTED\n * commission-script length — safe here because padding cannot raise the floor\n * (the fixed-34 model saturates the minimum) and shortening only lowers it.\n * Pass `undefined` for `out1Len` on 2-output (non-VP-claimer) payouts.\n * `feeRate` is the vault's version-locked `offchainParams.feeRate`.\n */\nexport async function computePayoutFeeFloor(\n txGraphVersion: number,\n numVaultKeepers: number,\n numUniversalChallengers: number,\n numLocalChallengers: number,\n councilSize: number,\n out0Len: number,\n out1Len: number | null | undefined,\n feeRate: bigint,\n): Promise<bigint> {\n return (await loadTbvWasm()).computePayoutFeeFloor(\n txGraphVersion,\n numVaultKeepers,\n numUniversalChallengers,\n numLocalChallengers,\n councilSize,\n out0Len,\n out1Len,\n feeRate,\n );\n}\n\n/**\n * Tx graph versions the shipped vault-wasm binary can build. Callers must\n * preflight the required version (fresh: active; resume: stamped) against\n * this list and fail closed instead of hitting per-call errors mid-flow.\n *\n * Note: the facade constructors themselves fail closed on unsupported\n * versions, and derived objects carry the version they were built with —\n * value-level cross-checks live in `assertWasmPeginSizing` and the golden\n * byte-parity tests, not in a per-call version echo.\n */\nexport async function supportedTxGraphVersions(): Promise<number[]> {\n return (await loadTbvWasm()).supportedTxGraphVersions();\n}\n\n/**\n * The PegIn transaction's P2A (pay-to-anchor) output for a graph version, or\n * `null` when that version's PegIn carries no anchor (v1). The facade returns\n * one record per version — never a zero-valued placeholder — so an absent\n * anchor can't be mistaken for a real output. For v2/v3: 240 sats at vout 2,\n * script `51024e73`.\n */\nexport async function peginP2aAnchorOutput(\n txGraphVersion: number,\n): Promise<PeginP2aAnchorInfo | null> {\n return (await loadTbvWasm()).peginP2aAnchorOutput(txGraphVersion);\n}\n\n/**\n * Validate a PegIn transaction's P2A anchor against a graph version's rules:\n * v2 and v3 require the exact anchor (240 sats, vout 2, P2A script) and v1\n * requires that NO output carries the P2A script. Throws on any mismatch — a\n * v2 PegIn checked as v1 fails closed, and vice versa.\n */\nexport async function validatePeginP2aAnchor(\n txGraphVersion: number,\n txHex: string,\n): Promise<void> {\n return (await loadTbvWasm()).validatePeginP2aAnchor(txGraphVersion, txHex);\n}\n\n/**\n * Creates a payout connector for vault transactions.\n *\n * The payout connector generates the necessary taproot scripts and information\n * required for signing payout transactions (both optimistic and regular payout paths).\n *\n * @param params - Parameters for creating the payout connector\n * @param network - Bitcoin network\n * @returns Payout connector information including scripts, hashes, and address\n */\nexport async function createPayoutConnector(\n params: PayoutConnectorParams,\n network: Network,\n): Promise<PayoutConnectorInfo> {\n return (await loadTbvWasm()).createPayoutConnector(params, network);\n}\n\n/**\n * Get the Payout script and control block for the depositor's Assert output.\n *\n * Used to build the depositor's Payout PSBT (depositor-as-claimer path).\n *\n * @param params - Assert Payout/NoPayout connector parameters\n * @returns Payout script and control block (hex encoded)\n */\nexport async function getAssertPayoutScriptInfo(\n params: AssertPayoutNoPayoutConnectorParams,\n): Promise<AssertPayoutScriptInfo> {\n return (await loadTbvWasm()).getAssertPayoutScriptInfo(params);\n}\n\n/**\n * Get the NoPayout script and control block for a specific challenger.\n *\n * Used to build the depositor's NoPayout PSBT (depositor-as-claimer path).\n * Each challenger has a distinct NoPayout script.\n *\n * @param params - Assert Payout/NoPayout connector parameters\n * @param challengerPubkey - The challenger's x-only public key (hex encoded)\n * @returns NoPayout script and control block (hex encoded)\n */\nexport async function getAssertNoPayoutScriptInfo(\n params: AssertPayoutNoPayoutConnectorParams,\n challengerPubkey: string,\n): Promise<AssertNoPayoutScriptInfo> {\n return (await loadTbvWasm()).getAssertNoPayoutScriptInfo(\n params,\n challengerPubkey,\n );\n}\n\n/**\n * Get the ChallengeAssert script and control block.\n *\n * Used to build ChallengeAssert PSBTs for the depositor-as-claimer path.\n * Each challenger has 3 ChallengeAssert transactions, and this connector\n * generates the spending scripts using WOTS public keys from the VP.\n *\n * @param params - ChallengeAssert connector parameters\n * @returns Script and control block (hex encoded)\n */\nexport async function getChallengeAssertScriptInfo(\n params: ChallengeAssertConnectorParams,\n): Promise<ChallengeAssertScriptInfo> {\n return (await loadTbvWasm()).getChallengeAssertScriptInfo(params);\n}\n\n/**\n * Derive 32-byte `authAnchor` (OP_RETURN preimage → VP bearer token).\n * @stability frozen - btc-vault Rust owns this API through the vault-wasm pin (`VAULT_WASM_COMMIT`).\n * Changing the derived bytes breaks VP auth for existing deposits. See CLAUDE.md §4.\n */\nexport async function expandAuthAnchor(root: Uint8Array): Promise<Uint8Array> {\n return (await loadTbvWasm()).expandAuthAnchor(root);\n}\n\n/**\n * Derive 32-byte `hashlockSecret` for HTLC `htlcVout` (preimage → `activateVaultWithSecret`).\n * @stability frozen - btc-vault Rust owns this API.\n * Changing the derived bytes means affected vaults can never activate. See CLAUDE.md §4.\n */\nexport async function expandHashlockSecret(\n root: Uint8Array,\n htlcVout: number,\n): Promise<Uint8Array> {\n return (await loadTbvWasm()).expandHashlockSecret(root, htlcVout);\n}\n\n/**\n * Derive 64-byte `wotsSeed` for HTLC `htlcVout` (→ WOTS keys, hashed as `depositorWotsPkHash`).\n * @stability frozen - btc-vault Rust owns this API.\n * Changing the derived bytes breaks existing `depositorWotsPkHash` values. No claim path remains. See CLAUDE.md §4.\n */\nexport async function expandWotsSeed(\n root: Uint8Array,\n htlcVout: number,\n): Promise<Uint8Array> {\n return (await loadTbvWasm()).expandWotsSeed(root, htlcVout);\n}\n\n/**\n * Derives the vault ID from a PegIn transaction hash and depositor ETH address.\n *\n * Vault ID = keccak256(abi.encode(peginTxHash, depositor))\n * This matches the Solidity-side derivation in BTCVaultRegistry.\n *\n * @param peginTxHash - 32-byte PegIn tx hash in display order (big-endian), hex encoded\n * @param depositor - 20-byte Ethereum address of the depositor, hex encoded\n * @returns Hex-encoded vault ID (32 bytes)\n */\nexport async function deriveVaultId(\n peginTxHash: string,\n depositor: string,\n): Promise<string> {\n return (await loadTbvWasm()).deriveVaultId(peginTxHash, depositor);\n}\n\nexport type {\n AssertNoPayoutScriptInfo,\n AssertPayoutNoPayoutConnectorParams,\n AssertPayoutScriptInfo,\n ChallengeAssertConnectorParams,\n ChallengeAssertScriptInfo,\n HtlcConnectorInfo,\n HtlcConnectorParams,\n Network,\n PayoutConnectorInfo,\n PayoutConnectorParams,\n PeginP2aAnchorInfo,\n PeginTxResult,\n PrePeginParams,\n PrePeginResult,\n};\n"],"names":["TAP_INTERNAL_KEY","HEX_CHARS_PER_BYTE","tapInternalPubkey","_","index","wasmModulePromise","loadTbvWasm","error","wasm","createPrePeginTransaction","params","buildPeginTxFromPrePegin","timelockPegin","fundedPrePeginTxHex","htlcVout","getPrePeginHtlcConnectorInfo","computeMinClaimValue","txGraphVersion","numLocalChallengers","numUniversalChallengers","councilQuorum","councilSize","feeRate","computeMinPeginFee","numVks","numUcs","minPeginFeeRate","computePayoutFeeFloor","numVaultKeepers","out0Len","out1Len","supportedTxGraphVersions","peginP2aAnchorOutput","validatePeginP2aAnchor","txHex","createPayoutConnector","network","getAssertPayoutScriptInfo","getAssertNoPayoutScriptInfo","challengerPubkey","getChallengeAssertScriptInfo","expandAuthAnchor","root","expandHashlockSecret","expandWotsSeed","deriveVaultId","peginTxHash","depositor"],"mappings":"2hBAQO,MAAMA,EACX,mEAEIC,EAAqB,EAEdC,EAAoB,WAAW,KAC1C,CAAE,OAAQF,EAAiB,OAASC,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AAsB0B,EACpBf,EACoC,CACpC,OAAQ,MAAMX,KAAe,qBAAqBW,CAAc,CAClE,CAQA,eAAsBgB,EACpBhB,EACAiB,EACe,CACf,OAAQ,MAAM5B,EAAA,GAAe,uBAAuBW,EAAgBiB,CAAK,CAC3E,CAYA,eAAsBC,EACpBzB,EACA0B,EAC8B,CAC9B,OAAQ,MAAM9B,EAAA,GAAe,sBAAsBI,EAAQ0B,CAAO,CACpE,CAUA,eAAsBC,EACpB3B,EACiC,CACjC,OAAQ,MAAMJ,KAAe,0BAA0BI,CAAM,CAC/D,CAYA,eAAsB4B,EACpB5B,EACA6B,EACmC,CACnC,OAAQ,MAAMjC,KAAe,4BAC3BI,EACA6B,CAAA,CAEJ,CAYA,eAAsBC,EACpB9B,EACoC,CACpC,OAAQ,MAAMJ,KAAe,6BAA6BI,CAAM,CAClE,CAOA,eAAsB+B,EAAiBC,EAAuC,CAC5E,OAAQ,MAAMpC,KAAe,iBAAiBoC,CAAI,CACpD,CAOA,eAAsBC,EACpBD,EACA5B,EACqB,CACrB,OAAQ,MAAMR,EAAA,GAAe,qBAAqBoC,EAAM5B,CAAQ,CAClE,CAOA,eAAsB8B,EACpBF,EACA5B,EACqB,CACrB,OAAQ,MAAMR,EAAA,GAAe,eAAeoC,EAAM5B,CAAQ,CAC5D,CAYA,eAAsB+B,EACpBC,EACAC,EACiB,CACjB,OAAQ,MAAMzC,EAAA,GAAe,cAAcwC,EAAaC,CAAS,CACnE"}
|
|
@@ -1,18 +1,20 @@
|
|
|
1
1
|
import { AssertNoPayoutScriptInfo, AssertPayoutNoPayoutConnectorParams, AssertPayoutScriptInfo, ChallengeAssertConnectorParams, ChallengeAssertScriptInfo, HtlcConnectorInfo, HtlcConnectorParams, Network, PayoutConnectorInfo, PayoutConnectorParams, PeginP2aAnchorInfo, PeginTxResult, PrePeginParams, PrePeginResult } from '@babylonlabs-io/babylon-tbv-rust-wasm';
|
|
2
2
|
export { TAP_INTERNAL_KEY, tapInternalPubkey } from './constants';
|
|
3
3
|
type TbvWasmModule = typeof import("@babylonlabs-io/babylon-tbv-rust-wasm");
|
|
4
|
-
type RawTbvWasmModule = typeof import("@babylonlabs-io/babylon-tbv-rust-wasm/raw");
|
|
5
|
-
/** Load the WASM engine on first use and share the in-flight import. */
|
|
6
|
-
export declare function loadTbvWasm(): Promise<TbvWasmModule>;
|
|
7
4
|
/**
|
|
8
|
-
* Load and initialize the
|
|
9
|
-
* The
|
|
5
|
+
* Load and initialize the WASM engine on first use. Concurrent callers share
|
|
6
|
+
* one load. The returned module is already initialized, so a caller does not
|
|
7
|
+
* call `initWasm()`. A load or initialization failure rejects with an error
|
|
8
|
+
* that names the engine package. The original error is its cause. A failure
|
|
9
|
+
* clears this cache, so the next call loads again. The engine keeps a failed
|
|
10
|
+
* binary initialization rejected, so only a failed import or binary read can
|
|
11
|
+
* succeed on a later call.
|
|
10
12
|
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
13
|
+
* The module also contains the wasm-bindgen classes. The classes have no value
|
|
14
|
+
* guards. A caller that uses a class must cross-check its output at the call
|
|
15
|
+
* site.
|
|
14
16
|
*/
|
|
15
|
-
export declare function
|
|
17
|
+
export declare function loadTbvWasm(): Promise<TbvWasmModule>;
|
|
16
18
|
/**
|
|
17
19
|
* Creates an unfunded Pre-PegIn transaction with no inputs and HTLC output(s).
|
|
18
20
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/tbv/core/wasm/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,KAAK,EACV,wBAAwB,EACxB,mCAAmC,EACnC,sBAAsB,EACtB,8BAA8B,EAC9B,yBAAyB,EACzB,iBAAiB,EACjB,mBAAmB,EACnB,OAAO,EACP,mBAAmB,EACnB,qBAAqB,EACrB,kBAAkB,EAClB,aAAa,EACb,cAAc,EACd,cAAc,EACf,MAAM,uCAAuC,CAAC;AAE/C,OAA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;AACH,wBAAsB,4BAA4B,CAChD,MAAM,EAAE,8BAA8B,GACrC,OAAO,CAAC,yBAAyB,CAAC,CAEpC;AAED;;;;GAIG;AACH,wBAAsB,gBAAgB,CAAC,IAAI,EAAE,UAAU,GAAG,OAAO,CAAC,UAAU,CAAC,CAE5E;AAED;;;;GAIG;AACH,wBAAsB,oBAAoB,CACxC,IAAI,EAAE,UAAU,EAChB,QAAQ,EAAE,MAAM,GACf,OAAO,CAAC,UAAU,CAAC,CAErB;AAED;;;;GAIG;AACH,wBAAsB,cAAc,CAClC,IAAI,EAAE,UAAU,EAChB,QAAQ,EAAE,MAAM,GACf,OAAO,CAAC,UAAU,CAAC,CAErB;AAED;;;;;;;;;GASG;AACH,wBAAsB,aAAa,CACjC,WAAW,EAAE,MAAM,EACnB,SAAS,EAAE,MAAM,GAChB,OAAO,CAAC,MAAM,CAAC,CAEjB;AAED,YAAY,EACV,wBAAwB,EACxB,mCAAmC,EACnC,sBAAsB,EACtB,8BAA8B,EAC9B,yBAAyB,EACzB,iBAAiB,EACjB,mBAAmB,EACnB,OAAO,EACP,mBAAmB,EACnB,qBAAqB,EACrB,kBAAkB,EAClB,aAAa,EACb,cAAc,EACd,cAAc,GACf,CAAC"}
|
|
@@ -1,144 +1,133 @@
|
|
|
1
|
-
const
|
|
1
|
+
const u = "50929b74c1a04954b78b4b6035e97a5e078a5a0f28ec96d547bfee9ace803ac0";
|
|
2
2
|
const y = Uint8Array.from(
|
|
3
|
-
{ length:
|
|
4
|
-
(e,
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
3
|
+
{ length: u.length / 2 },
|
|
4
|
+
(e, n) => Number.parseInt(
|
|
5
|
+
u.slice(
|
|
6
|
+
n * 2,
|
|
7
|
+
n * 2 + 2
|
|
8
8
|
),
|
|
9
9
|
16
|
|
10
10
|
)
|
|
11
11
|
);
|
|
12
|
-
let
|
|
13
|
-
function
|
|
14
|
-
return
|
|
15
|
-
(e) => {
|
|
16
|
-
throw u = void 0, new Error(
|
|
17
|
-
"The vault-WASM engine @babylonlabs-io/babylon-tbv-rust-wasm failed to load. The module could not be resolved, or it threw while evaluating, commonly a missing or stale generated WASM build. See the cause for the underlying error.",
|
|
18
|
-
{ cause: e }
|
|
19
|
-
);
|
|
20
|
-
}
|
|
21
|
-
)), u;
|
|
22
|
-
}
|
|
23
|
-
function P() {
|
|
24
|
-
return o ?? (o = import("@babylonlabs-io/babylon-tbv-rust-wasm/raw").catch((e) => {
|
|
12
|
+
let o;
|
|
13
|
+
function t() {
|
|
14
|
+
return o ?? (o = import("@babylonlabs-io/babylon-tbv-rust-wasm").catch((e) => {
|
|
25
15
|
throw o = void 0, new Error(
|
|
26
|
-
"The
|
|
16
|
+
"The vault-WASM engine @babylonlabs-io/babylon-tbv-rust-wasm failed to load. The module could not be resolved, or it threw while evaluating, commonly a missing or stale generated WASM build. See the cause for the underlying error.",
|
|
27
17
|
{ cause: e }
|
|
28
18
|
);
|
|
29
19
|
}).then(async (e) => {
|
|
30
20
|
try {
|
|
31
21
|
await e.initWasm();
|
|
32
|
-
} catch (
|
|
22
|
+
} catch (n) {
|
|
33
23
|
throw o = void 0, new Error(
|
|
34
|
-
"The
|
|
35
|
-
{ cause:
|
|
24
|
+
"The vault-WASM engine @babylonlabs-io/babylon-tbv-rust-wasm resolved, but its WebAssembly binary failed to initialize, commonly a missing or stale generated WASM build. See the cause for the underlying error.",
|
|
25
|
+
{ cause: n }
|
|
36
26
|
);
|
|
37
27
|
}
|
|
38
28
|
return e;
|
|
39
29
|
})), o;
|
|
40
30
|
}
|
|
41
|
-
async function
|
|
42
|
-
return (await
|
|
31
|
+
async function P(e) {
|
|
32
|
+
return (await t()).createPrePeginTransaction(e);
|
|
43
33
|
}
|
|
44
|
-
async function
|
|
45
|
-
return (await
|
|
34
|
+
async function d(e, n, a, r) {
|
|
35
|
+
return (await t()).buildPeginTxFromPrePegin(
|
|
46
36
|
e,
|
|
47
|
-
|
|
37
|
+
n,
|
|
48
38
|
a,
|
|
49
39
|
r
|
|
50
40
|
);
|
|
51
41
|
}
|
|
52
|
-
async function
|
|
53
|
-
return (await
|
|
42
|
+
async function g(e) {
|
|
43
|
+
return (await t()).getPrePeginHtlcConnectorInfo(e);
|
|
54
44
|
}
|
|
55
|
-
async function
|
|
56
|
-
return (await
|
|
45
|
+
async function f(e, n, a, r, i, c) {
|
|
46
|
+
return (await t()).computeMinClaimValue(
|
|
57
47
|
e,
|
|
58
|
-
|
|
48
|
+
n,
|
|
59
49
|
a,
|
|
60
50
|
r,
|
|
61
51
|
i,
|
|
62
52
|
c
|
|
63
53
|
);
|
|
64
54
|
}
|
|
65
|
-
async function p(e,
|
|
66
|
-
return (await
|
|
55
|
+
async function p(e, n, a, r) {
|
|
56
|
+
return (await t()).computeMinPeginFee(
|
|
67
57
|
e,
|
|
68
|
-
|
|
58
|
+
n,
|
|
69
59
|
a,
|
|
70
60
|
r
|
|
71
61
|
);
|
|
72
62
|
}
|
|
73
|
-
async function
|
|
74
|
-
return (await
|
|
63
|
+
async function h(e, n, a, r, i, c, s, l) {
|
|
64
|
+
return (await t()).computePayoutFeeFloor(
|
|
75
65
|
e,
|
|
76
|
-
|
|
66
|
+
n,
|
|
77
67
|
a,
|
|
78
68
|
r,
|
|
79
69
|
i,
|
|
80
70
|
c,
|
|
81
|
-
|
|
82
|
-
|
|
71
|
+
s,
|
|
72
|
+
l
|
|
83
73
|
);
|
|
84
74
|
}
|
|
85
|
-
async function
|
|
86
|
-
return (await
|
|
75
|
+
async function b() {
|
|
76
|
+
return (await t()).supportedTxGraphVersions();
|
|
87
77
|
}
|
|
88
78
|
async function A(e) {
|
|
89
|
-
return (await
|
|
79
|
+
return (await t()).peginP2aAnchorOutput(e);
|
|
90
80
|
}
|
|
91
|
-
async function
|
|
92
|
-
return (await
|
|
81
|
+
async function m(e, n) {
|
|
82
|
+
return (await t()).validatePeginP2aAnchor(e, n);
|
|
93
83
|
}
|
|
94
|
-
async function
|
|
95
|
-
return (await
|
|
84
|
+
async function w(e, n) {
|
|
85
|
+
return (await t()).createPayoutConnector(e, n);
|
|
96
86
|
}
|
|
97
|
-
async function
|
|
98
|
-
return (await
|
|
87
|
+
async function S(e) {
|
|
88
|
+
return (await t()).getAssertPayoutScriptInfo(e);
|
|
99
89
|
}
|
|
100
|
-
async function
|
|
101
|
-
return (await
|
|
90
|
+
async function E(e, n) {
|
|
91
|
+
return (await t()).getAssertNoPayoutScriptInfo(
|
|
102
92
|
e,
|
|
103
|
-
|
|
93
|
+
n
|
|
104
94
|
);
|
|
105
95
|
}
|
|
106
96
|
async function _(e) {
|
|
107
|
-
return (await
|
|
97
|
+
return (await t()).getChallengeAssertScriptInfo(e);
|
|
108
98
|
}
|
|
109
|
-
async function
|
|
110
|
-
return (await
|
|
99
|
+
async function T(e) {
|
|
100
|
+
return (await t()).expandAuthAnchor(e);
|
|
111
101
|
}
|
|
112
|
-
async function
|
|
113
|
-
return (await
|
|
102
|
+
async function v(e, n) {
|
|
103
|
+
return (await t()).expandHashlockSecret(e, n);
|
|
114
104
|
}
|
|
115
|
-
async function
|
|
116
|
-
return (await
|
|
105
|
+
async function H(e, n) {
|
|
106
|
+
return (await t()).expandWotsSeed(e, n);
|
|
117
107
|
}
|
|
118
|
-
async function
|
|
119
|
-
return (await
|
|
108
|
+
async function C(e, n) {
|
|
109
|
+
return (await t()).deriveVaultId(e, n);
|
|
120
110
|
}
|
|
121
111
|
export {
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
112
|
+
u as TAP_INTERNAL_KEY,
|
|
113
|
+
d as buildPeginTxFromPrePegin,
|
|
114
|
+
f as computeMinClaimValue,
|
|
125
115
|
p as computeMinPeginFee,
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
116
|
+
h as computePayoutFeeFloor,
|
|
117
|
+
w as createPayoutConnector,
|
|
118
|
+
P as createPrePeginTransaction,
|
|
119
|
+
C as deriveVaultId,
|
|
120
|
+
T as expandAuthAnchor,
|
|
121
|
+
v as expandHashlockSecret,
|
|
122
|
+
H as expandWotsSeed,
|
|
123
|
+
E as getAssertNoPayoutScriptInfo,
|
|
124
|
+
S as getAssertPayoutScriptInfo,
|
|
135
125
|
_ as getChallengeAssertScriptInfo,
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
n as loadTbvWasm,
|
|
126
|
+
g as getPrePeginHtlcConnectorInfo,
|
|
127
|
+
t as loadTbvWasm,
|
|
139
128
|
A as peginP2aAnchorOutput,
|
|
140
|
-
|
|
129
|
+
b as supportedTxGraphVersions,
|
|
141
130
|
y as tapInternalPubkey,
|
|
142
|
-
|
|
131
|
+
m as validatePeginP2aAnchor
|
|
143
132
|
};
|
|
144
133
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../../../src/tbv/core/wasm/constants.ts","../../../../src/tbv/core/wasm/index.ts"],"sourcesContent":["/**\n * Protocol constants that do not require loading the vault WASM module.\n *\n * Keeping these values local lets Bitcoin builders construct PSBT metadata\n * without resolving or evaluating the WASM engine at module-import\n * time. The hex value is the BIP-341 nothing-up-my-sleeve internal key and is\n * pinned by the vault protocol.\n */\nexport const TAP_INTERNAL_KEY =\n \"50929b74c1a04954b78b4b6035e97a5e078a5a0f28ec96d547bfee9ace803ac0\";\n\nconst HEX_CHARS_PER_BYTE = 2;\n\nexport const tapInternalPubkey = Uint8Array.from(\n { length: TAP_INTERNAL_KEY.length / HEX_CHARS_PER_BYTE },\n (_, index) =>\n Number.parseInt(\n TAP_INTERNAL_KEY.slice(\n index * HEX_CHARS_PER_BYTE,\n index * HEX_CHARS_PER_BYTE + HEX_CHARS_PER_BYTE,\n ),\n 16,\n ),\n);\n","/**\n * Explicit lazy boundary around the vault-WASM engine package.\n *\n * Importing the SDK (including its legacy root barrels) does not resolve the\n * WASM package or generated binary. The engine is loaded only when a caller\n * invokes an operation that actually needs the Bitcoin transaction graph.\n * ETH-only entry points never import this module.\n *\n * @module tbv/core/wasm\n */\n\nimport type {\n AssertNoPayoutScriptInfo,\n AssertPayoutNoPayoutConnectorParams,\n AssertPayoutScriptInfo,\n ChallengeAssertConnectorParams,\n ChallengeAssertScriptInfo,\n HtlcConnectorInfo,\n HtlcConnectorParams,\n Network,\n PayoutConnectorInfo,\n PayoutConnectorParams,\n PeginP2aAnchorInfo,\n PeginTxResult,\n PrePeginParams,\n PrePeginResult,\n} from \"@babylonlabs-io/babylon-tbv-rust-wasm\";\n\nexport { TAP_INTERNAL_KEY, tapInternalPubkey } from \"./constants\";\n\ntype TbvWasmModule = typeof import(\"@babylonlabs-io/babylon-tbv-rust-wasm\");\n\nlet wasmModulePromise: Promise<TbvWasmModule> | undefined;\ntype RawTbvWasmModule =\n typeof import(\"@babylonlabs-io/babylon-tbv-rust-wasm/raw\");\nlet rawWasmModulePromise: Promise<RawTbvWasmModule> | undefined;\n\n/** Load the WASM engine on first use and share the in-flight import. */\nexport function loadTbvWasm(): Promise<TbvWasmModule> {\n wasmModulePromise ??= import(\"@babylonlabs-io/babylon-tbv-rust-wasm\").catch(\n (error: unknown) => {\n wasmModulePromise = undefined;\n throw new Error(\n \"The vault-WASM engine @babylonlabs-io/babylon-tbv-rust-wasm failed \" +\n \"to load. The module could not be resolved, or it threw while \" +\n \"evaluating, commonly a missing or stale generated WASM build. \" +\n \"See the cause for the underlying error.\",\n { cause: error },\n );\n },\n );\n return wasmModulePromise;\n}\n\n/**\n * Load and initialize the raw engine classes. This bypasses SDK value checks.\n * The internal refund builder applies equivalent checks at its call site.\n *\n * @deprecated Use buildPrePeginPsbt, buildPeginTxFromFundedPrePegin, or\n * buildRefundPsbt from @babylonlabs-io/ts-sdk/tbv/core/primitives.\n * Raw callers must independently check transaction values and signing data.\n */\nexport function loadRawTbvWasm(): Promise<RawTbvWasmModule> {\n rawWasmModulePromise ??= import(\"@babylonlabs-io/babylon-tbv-rust-wasm/raw\")\n .catch((error: unknown) => {\n rawWasmModulePromise = undefined;\n throw new Error(\n \"The raw vault-WASM entry @babylonlabs-io/babylon-tbv-rust-wasm/raw \" +\n \"failed to load. The module could not be resolved, or it threw \" +\n \"while evaluating. See the cause for the underlying error.\",\n { cause: error },\n );\n })\n .then(async (wasm) => {\n try {\n await wasm.initWasm();\n } catch (error: unknown) {\n rawWasmModulePromise = undefined;\n throw new Error(\n \"The raw vault-WASM entry resolved but its WebAssembly \" +\n \"binary failed to initialize.\",\n { cause: error },\n );\n }\n return wasm;\n });\n return rawWasmModulePromise;\n}\n\n/**\n * Creates an unfunded Pre-PegIn transaction with no inputs and HTLC output(s).\n *\n * The HTLC output value (htlcValue) covers the peg-in amount, depositor claim value,\n * and minimum pegin fee — all computed internally from the provided contract parameters.\n *\n * After building the Pre-PegIn transaction, the caller must:\n * 1. Select UTXOs covering htlcValue + network fees\n * 2. Fund the transaction (add inputs and change output)\n * 3. Call reconstructFromFundedTx() with the funded tx hex\n * 4. Call buildPeginTx() to derive the PegIn transaction\n * 5. Sign the PegIn input using the HTLC hashlock leaf (leaf 0)\n *\n * @param params - Pre-PegIn parameters from contract and depositor wallet\n * @returns Unfunded transaction details with HTLC output information\n */\nexport async function createPrePeginTransaction(\n params: PrePeginParams,\n): Promise<PrePeginResult> {\n return (await loadTbvWasm()).createPrePeginTransaction(params);\n}\n\n/**\n * Derives the PegIn transaction from a funded Pre-PegIn transaction.\n *\n * The PegIn transaction has a single input spending the Pre-PegIn HTLC output\n * at `htlcVout` via the hashlock + all-party script (leaf 0).\n *\n * @param params - Same PrePeginParams used to create the Pre-PegIn transaction\n * @param timelockPegin - CSV timelock in blocks for the PegIn vault output\n * @param fundedPrePeginTxHex - Hex-encoded funded Pre-PegIn transaction\n * @param htlcVout - Index of the HTLC output to spend\n * @returns PegIn transaction details including vault output information\n */\nexport async function buildPeginTxFromPrePegin(\n params: PrePeginParams,\n timelockPegin: number,\n fundedPrePeginTxHex: string,\n htlcVout: number,\n): Promise<PeginTxResult> {\n return (await loadTbvWasm()).buildPeginTxFromPrePegin(\n params,\n timelockPegin,\n fundedPrePeginTxHex,\n htlcVout,\n );\n}\n\n/**\n * Returns HTLC connector script info for signing the PegIn transaction input.\n *\n * The depositor signs PegIn input 0 using the hashlock leaf (leaf 0) of the\n * Pre-PegIn HTLC output. Use getHashlockScript() and getHashlockControlBlock()\n * to construct the tapLeafScript entry in the PSBT.\n *\n * @param params - HTLC connector parameters (subset of PrePeginParams)\n * @returns Hashlock and refund script info for PSBT construction\n */\nexport async function getPrePeginHtlcConnectorInfo(\n params: HtlcConnectorParams,\n): Promise<HtlcConnectorInfo> {\n return (await loadTbvWasm()).getPrePeginHtlcConnectorInfo(params);\n}\n\n/**\n * Compute the minimum depositor claim value (PegIn output 1) in satoshis.\n *\n * This covers the full downstream tx graph cost (Claim → Assert → Payout)\n * based on the protocol parameters.\n */\nexport async function computeMinClaimValue(\n txGraphVersion: number,\n numLocalChallengers: number,\n numUniversalChallengers: number,\n councilQuorum: number,\n councilSize: number,\n feeRate: bigint,\n): Promise<bigint> {\n return (await loadTbvWasm()).computeMinClaimValue(\n txGraphVersion,\n numLocalChallengers,\n numUniversalChallengers,\n councilQuorum,\n councilSize,\n feeRate,\n );\n}\n\n/**\n * Compute the minimum PegIn (activation) transaction fee in satoshis.\n *\n * `minPeginFee = peginTxVsize(numVks, numUcs) × minPeginFeeRate`. Each HTLC\n * the depositor funds in the Pre-PegIn tx must reserve at least this fee\n * inside its value (`htlcValue = peginAmount + depositorClaimValue +\n * minPeginFee`), otherwise the VP cannot afford to broadcast the PegIn at\n * activation. The vsize comes from a Taproot script-path-spend weight\n * prediction whose witness shape depends on the VK + UC signer count.\n */\nexport async function computeMinPeginFee(\n txGraphVersion: number,\n numVks: number,\n numUcs: number,\n minPeginFeeRate: bigint,\n): Promise<bigint> {\n return (await loadTbvWasm()).computeMinPeginFee(\n txGraphVersion,\n numVks,\n numUcs,\n minPeginFeeRate,\n );\n}\n\n/**\n * Floor of the Payout transaction fee under `txGraphVersion`: the minimum of\n * `estimatedVsize * feeRate` across every output-sizing model a deployed\n * vault provider is known to have used (fixed-34, intermediate,\n * script-aware). A VP-built payout paying less than this is provably not\n * produced by any known VP build. `out0Len` must be the TRUSTED length of the\n * pinned outs[0] script (1..=128); `out1Len` is the measured, UNTRUSTED\n * commission-script length — safe here because padding cannot raise the floor\n * (the fixed-34 model saturates the minimum) and shortening only lowers it.\n * Pass `undefined` for `out1Len` on 2-output (non-VP-claimer) payouts.\n * `feeRate` is the vault's version-locked `offchainParams.feeRate`.\n */\nexport async function computePayoutFeeFloor(\n txGraphVersion: number,\n numVaultKeepers: number,\n numUniversalChallengers: number,\n numLocalChallengers: number,\n councilSize: number,\n out0Len: number,\n out1Len: number | null | undefined,\n feeRate: bigint,\n): Promise<bigint> {\n return (await loadTbvWasm()).computePayoutFeeFloor(\n txGraphVersion,\n numVaultKeepers,\n numUniversalChallengers,\n numLocalChallengers,\n councilSize,\n out0Len,\n out1Len,\n feeRate,\n );\n}\n\n/**\n * Tx graph versions the shipped vault-wasm binary can build. Callers must\n * preflight the required version (fresh: active; resume: stamped) against\n * this list and fail closed instead of hitting per-call errors mid-flow.\n *\n * Note: the facade constructors themselves fail closed on unsupported\n * versions, and derived objects carry the version they were built with —\n * value-level cross-checks live in `assertWasmPeginSizing` and the golden\n * byte-parity tests, not in a per-call version echo.\n */\nexport async function supportedTxGraphVersions(): Promise<number[]> {\n return (await loadTbvWasm()).supportedTxGraphVersions();\n}\n\n/**\n * The PegIn transaction's P2A (pay-to-anchor) output for a graph version, or\n * `null` when that version's PegIn carries no anchor (v1). The facade returns\n * one record per version — never a zero-valued placeholder — so an absent\n * anchor can't be mistaken for a real output. For v2/v3: 240 sats at vout 2,\n * script `51024e73`.\n */\nexport async function peginP2aAnchorOutput(\n txGraphVersion: number,\n): Promise<PeginP2aAnchorInfo | null> {\n return (await loadTbvWasm()).peginP2aAnchorOutput(txGraphVersion);\n}\n\n/**\n * Validate a PegIn transaction's P2A anchor against a graph version's rules:\n * v2 and v3 require the exact anchor (240 sats, vout 2, P2A script) and v1\n * requires that NO output carries the P2A script. Throws on any mismatch — a\n * v2 PegIn checked as v1 fails closed, and vice versa.\n */\nexport async function validatePeginP2aAnchor(\n txGraphVersion: number,\n txHex: string,\n): Promise<void> {\n return (await loadTbvWasm()).validatePeginP2aAnchor(txGraphVersion, txHex);\n}\n\n/**\n * Creates a payout connector for vault transactions.\n *\n * The payout connector generates the necessary taproot scripts and information\n * required for signing payout transactions (both optimistic and regular payout paths).\n *\n * @param params - Parameters for creating the payout connector\n * @param network - Bitcoin network\n * @returns Payout connector information including scripts, hashes, and address\n */\nexport async function createPayoutConnector(\n params: PayoutConnectorParams,\n network: Network,\n): Promise<PayoutConnectorInfo> {\n return (await loadTbvWasm()).createPayoutConnector(params, network);\n}\n\n/**\n * Get the Payout script and control block for the depositor's Assert output.\n *\n * Used to build the depositor's Payout PSBT (depositor-as-claimer path).\n *\n * @param params - Assert Payout/NoPayout connector parameters\n * @returns Payout script and control block (hex encoded)\n */\nexport async function getAssertPayoutScriptInfo(\n params: AssertPayoutNoPayoutConnectorParams,\n): Promise<AssertPayoutScriptInfo> {\n return (await loadTbvWasm()).getAssertPayoutScriptInfo(params);\n}\n\n/**\n * Get the NoPayout script and control block for a specific challenger.\n *\n * Used to build the depositor's NoPayout PSBT (depositor-as-claimer path).\n * Each challenger has a distinct NoPayout script.\n *\n * @param params - Assert Payout/NoPayout connector parameters\n * @param challengerPubkey - The challenger's x-only public key (hex encoded)\n * @returns NoPayout script and control block (hex encoded)\n */\nexport async function getAssertNoPayoutScriptInfo(\n params: AssertPayoutNoPayoutConnectorParams,\n challengerPubkey: string,\n): Promise<AssertNoPayoutScriptInfo> {\n return (await loadTbvWasm()).getAssertNoPayoutScriptInfo(\n params,\n challengerPubkey,\n );\n}\n\n/**\n * Get the ChallengeAssert script and control block.\n *\n * Used to build ChallengeAssert PSBTs for the depositor-as-claimer path.\n * Each challenger has 3 ChallengeAssert transactions, and this connector\n * generates the spending scripts using WOTS public keys from the VP.\n *\n * @param params - ChallengeAssert connector parameters\n * @returns Script and control block (hex encoded)\n */\nexport async function getChallengeAssertScriptInfo(\n params: ChallengeAssertConnectorParams,\n): Promise<ChallengeAssertScriptInfo> {\n return (await loadTbvWasm()).getChallengeAssertScriptInfo(params);\n}\n\n/**\n * Derive 32-byte `authAnchor` (OP_RETURN preimage → VP bearer token).\n * @stability frozen - btc-vault Rust owns this API through the vault-wasm pin (`VAULT_WASM_COMMIT`).\n * Changing the derived bytes breaks VP auth for existing deposits. See CLAUDE.md §4.\n */\nexport async function expandAuthAnchor(root: Uint8Array): Promise<Uint8Array> {\n return (await loadTbvWasm()).expandAuthAnchor(root);\n}\n\n/**\n * Derive 32-byte `hashlockSecret` for HTLC `htlcVout` (preimage → `activateVaultWithSecret`).\n * @stability frozen - btc-vault Rust owns this API.\n * Changing the derived bytes means affected vaults can never activate. See CLAUDE.md §4.\n */\nexport async function expandHashlockSecret(\n root: Uint8Array,\n htlcVout: number,\n): Promise<Uint8Array> {\n return (await loadTbvWasm()).expandHashlockSecret(root, htlcVout);\n}\n\n/**\n * Derive 64-byte `wotsSeed` for HTLC `htlcVout` (→ WOTS keys, hashed as `depositorWotsPkHash`).\n * @stability frozen - btc-vault Rust owns this API.\n * Changing the derived bytes breaks existing `depositorWotsPkHash` values. No claim path remains. See CLAUDE.md §4.\n */\nexport async function expandWotsSeed(\n root: Uint8Array,\n htlcVout: number,\n): Promise<Uint8Array> {\n return (await loadTbvWasm()).expandWotsSeed(root, htlcVout);\n}\n\n/**\n * Derives the vault ID from a PegIn transaction hash and depositor ETH address.\n *\n * Vault ID = keccak256(abi.encode(peginTxHash, depositor))\n * This matches the Solidity-side derivation in BTCVaultRegistry.\n *\n * @param peginTxHash - 32-byte PegIn tx hash in display order (big-endian), hex encoded\n * @param depositor - 20-byte Ethereum address of the depositor, hex encoded\n * @returns Hex-encoded vault ID (32 bytes)\n */\nexport async function deriveVaultId(\n peginTxHash: string,\n depositor: string,\n): Promise<string> {\n return (await loadTbvWasm()).deriveVaultId(peginTxHash, depositor);\n}\n\nexport type {\n AssertNoPayoutScriptInfo,\n AssertPayoutNoPayoutConnectorParams,\n AssertPayoutScriptInfo,\n ChallengeAssertConnectorParams,\n ChallengeAssertScriptInfo,\n HtlcConnectorInfo,\n HtlcConnectorParams,\n Network,\n PayoutConnectorInfo,\n PayoutConnectorParams,\n PeginP2aAnchorInfo,\n PeginTxResult,\n PrePeginParams,\n PrePeginResult,\n};\n"],"names":["TAP_INTERNAL_KEY","tapInternalPubkey","_","index","wasmModulePromise","rawWasmModulePromise","loadTbvWasm","error","loadRawTbvWasm","wasm","createPrePeginTransaction","params","buildPeginTxFromPrePegin","timelockPegin","fundedPrePeginTxHex","htlcVout","getPrePeginHtlcConnectorInfo","computeMinClaimValue","txGraphVersion","numLocalChallengers","numUniversalChallengers","councilQuorum","councilSize","feeRate","computeMinPeginFee","numVks","numUcs","minPeginFeeRate","computePayoutFeeFloor","numVaultKeepers","out0Len","out1Len","supportedTxGraphVersions","peginP2aAnchorOutput","validatePeginP2aAnchor","txHex","createPayoutConnector","network","getAssertPayoutScriptInfo","getAssertNoPayoutScriptInfo","challengerPubkey","getChallengeAssertScriptInfo","expandAuthAnchor","root","expandHashlockSecret","expandWotsSeed","deriveVaultId","peginTxHash","depositor"],"mappings":"AAQO,MAAMA,IACX;AAIK,MAAMC,IAAoB,WAAW;AAAA,EAC1C,EAAE,QAAQD,EAAiB,SAAS,EAAA;AAAA,EACpC,CAACE,GAAGC,MACF,OAAO;AAAA,IACLH,EAAiB;AAAA,MACfG,IAAQ;AAAA,MACRA,IAAQ,IAAqB;AAAA,IAAA;AAAA,IAE/B;AAAA,EAAA;AAEN;ACSA,IAAIC,GAGAC;AAGG,SAASC,IAAsC;AACpD,SAAAF,UAAsB,OAAO,uCAAuC,EAAE;AAAA,IACpE,CAACG,MAAmB;AAClB,YAAAH,IAAoB,QACd,IAAI;AAAA,QACR;AAAA,Q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A,IACAT;AAAA,IACAD;AAAA,IACAG;AAAA,IACAQ;AAAA,IACAC;AAAA,IACAR;AAAA,EAAA;AAEJ;AAYA,eAAsBS,IAA8C;AAClE,UAAQ,MAAM1B,EAAA,GAAe,yBAAA;AAC/B;AASA,eAAsB2B,EACpBf,GACoC;AACpC,UAAQ,MAAMZ,KAAe,qBAAqBY,CAAc;AAClE;AAQA,eAAsBgB,EACpBhB,GACAiB,GACe;AACf,UAAQ,MAAM7B,EAAA,GAAe,uBAAuBY,GAAgBiB,CAAK;AAC3E;AAYA,eAAsBC,EACpBzB,GACA0B,GAC8B;AAC9B,UAAQ,MAAM/B,EAAA,GAAe,sBAAsBK,GAAQ0B,CAAO;AACpE;AAUA,eAAsBC,EACpB3B,GACiC;AACjC,UAAQ,MAAML,KAAe,0BAA0BK,CAAM;AAC/D;AAYA,eAAsB4B,EACpB5B,GACA6B,GACmC;AACnC,UAAQ,MAAMlC,KAAe;AAAA,IAC3BK;AAAA,IACA6B;AAAA,EAAA;AAEJ;AAYA,eAAsBC,EACpB9B,GACoC;AACpC,UAAQ,MAAML,KAAe,6BAA6BK,CAAM;AAClE;AAOA,eAAsB+B,EAAiBC,GAAuC;AAC5E,UAAQ,MAAMrC,KAAe,iBAAiBqC,CAAI;AACpD;AAOA,eAAsBC,EACpBD,GACA5B,GACqB;AACrB,UAAQ,MAAMT,EAAA,GAAe,qBAAqBqC,GAAM5B,CAAQ;AAClE;AAOA,eAAsB8B,EACpBF,GACA5B,GACqB;AACrB,UAAQ,MAAMT,EAAA,GAAe,eAAeqC,GAAM5B,CAAQ;AAC5D;AAYA,eAAsB+B,EACpBC,GACAC,GACiB;AACjB,UAAQ,MAAM1C,EAAA,GAAe,cAAcyC,GAAaC,CAAS;AACnE;"}
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../../../src/tbv/core/wasm/constants.ts","../../../../src/tbv/core/wasm/index.ts"],"sourcesContent":["/**\n * Protocol constants that do not require loading the vault WASM module.\n *\n * Keeping these values local lets Bitcoin builders construct PSBT metadata\n * without resolving or evaluating the WASM engine at module-import\n * time. The hex value is the BIP-341 nothing-up-my-sleeve internal key and is\n * pinned by the vault protocol.\n */\nexport const TAP_INTERNAL_KEY =\n \"50929b74c1a04954b78b4b6035e97a5e078a5a0f28ec96d547bfee9ace803ac0\";\n\nconst HEX_CHARS_PER_BYTE = 2;\n\nexport const tapInternalPubkey = Uint8Array.from(\n { length: TAP_INTERNAL_KEY.length / HEX_CHARS_PER_BYTE },\n (_, index) =>\n Number.parseInt(\n TAP_INTERNAL_KEY.slice(\n index * HEX_CHARS_PER_BYTE,\n index * HEX_CHARS_PER_BYTE + HEX_CHARS_PER_BYTE,\n ),\n 16,\n ),\n);\n","/**\n * Explicit lazy boundary around the vault-WASM engine package.\n *\n * Importing the SDK (including its legacy root barrels) does not resolve the\n * WASM package or generated binary. The engine is loaded only when a caller\n * invokes an operation that actually needs the Bitcoin transaction graph.\n * ETH-only entry points never import this module.\n *\n * @module tbv/core/wasm\n */\n\nimport type {\n AssertNoPayoutScriptInfo,\n AssertPayoutNoPayoutConnectorParams,\n AssertPayoutScriptInfo,\n ChallengeAssertConnectorParams,\n ChallengeAssertScriptInfo,\n HtlcConnectorInfo,\n HtlcConnectorParams,\n Network,\n PayoutConnectorInfo,\n PayoutConnectorParams,\n PeginP2aAnchorInfo,\n PeginTxResult,\n PrePeginParams,\n PrePeginResult,\n} from \"@babylonlabs-io/babylon-tbv-rust-wasm\";\n\nexport { TAP_INTERNAL_KEY, tapInternalPubkey } from \"./constants\";\n\ntype TbvWasmModule = typeof import(\"@babylonlabs-io/babylon-tbv-rust-wasm\");\n\nlet wasmModulePromise: Promise<TbvWasmModule> | undefined;\n\n/**\n * Load and initialize the WASM engine on first use. Concurrent callers share\n * one load. The returned module is already initialized, so a caller does not\n * call `initWasm()`. A load or initialization failure rejects with an error\n * that names the engine package. The original error is its cause. A failure\n * clears this cache, so the next call loads again. The engine keeps a failed\n * binary initialization rejected, so only a failed import or binary read can\n * succeed on a later call.\n *\n * The module also contains the wasm-bindgen classes. The classes have no value\n * guards. A caller that uses a class must cross-check its output at the call\n * site.\n */\nexport function loadTbvWasm(): Promise<TbvWasmModule> {\n wasmModulePromise ??= import(\"@babylonlabs-io/babylon-tbv-rust-wasm\")\n .catch((error: unknown) => {\n wasmModulePromise = undefined;\n throw new Error(\n \"The vault-WASM engine @babylonlabs-io/babylon-tbv-rust-wasm failed \" +\n \"to load. The module could not be resolved, or it threw while \" +\n \"evaluating, commonly a missing or stale generated WASM build. \" +\n \"See the cause for the underlying error.\",\n { cause: error },\n );\n })\n .then(async (wasm) => {\n try {\n await wasm.initWasm();\n } catch (error: unknown) {\n wasmModulePromise = undefined;\n throw new Error(\n \"The vault-WASM engine @babylonlabs-io/babylon-tbv-rust-wasm \" +\n \"resolved, but its WebAssembly binary failed to initialize, \" +\n \"commonly a missing or stale generated WASM build. See the \" +\n \"cause for the underlying error.\",\n { cause: error },\n );\n }\n return wasm;\n });\n return wasmModulePromise;\n}\n\n/**\n * Creates an unfunded Pre-PegIn transaction with no inputs and HTLC output(s).\n *\n * The HTLC output value (htlcValue) covers the peg-in amount, depositor claim value,\n * and minimum pegin fee — all computed internally from the provided contract parameters.\n *\n * After building the Pre-PegIn transaction, the caller must:\n * 1. Select UTXOs covering htlcValue + network fees\n * 2. Fund the transaction (add inputs and change output)\n * 3. Call reconstructFromFundedTx() with the funded tx hex\n * 4. Call buildPeginTx() to derive the PegIn transaction\n * 5. Sign the PegIn input using the HTLC hashlock leaf (leaf 0)\n *\n * @param params - Pre-PegIn parameters from contract and depositor wallet\n * @returns Unfunded transaction details with HTLC output information\n */\nexport async function createPrePeginTransaction(\n params: PrePeginParams,\n): Promise<PrePeginResult> {\n return (await loadTbvWasm()).createPrePeginTransaction(params);\n}\n\n/**\n * Derives the PegIn transaction from a funded Pre-PegIn transaction.\n *\n * The PegIn transaction has a single input spending the Pre-PegIn HTLC output\n * at `htlcVout` via the hashlock + all-party script (leaf 0).\n *\n * @param params - Same PrePeginParams used to create the Pre-PegIn transaction\n * @param timelockPegin - CSV timelock in blocks for the PegIn vault output\n * @param fundedPrePeginTxHex - Hex-encoded funded Pre-PegIn transaction\n * @param htlcVout - Index of the HTLC output to spend\n * @returns PegIn transaction details including vault output information\n */\nexport async function buildPeginTxFromPrePegin(\n params: PrePeginParams,\n timelockPegin: number,\n fundedPrePeginTxHex: string,\n htlcVout: number,\n): Promise<PeginTxResult> {\n return (await loadTbvWasm()).buildPeginTxFromPrePegin(\n params,\n timelockPegin,\n fundedPrePeginTxHex,\n htlcVout,\n );\n}\n\n/**\n * Returns HTLC connector script info for signing the PegIn transaction input.\n *\n * The depositor signs PegIn input 0 using the hashlock leaf (leaf 0) of the\n * Pre-PegIn HTLC output. Use getHashlockScript() and getHashlockControlBlock()\n * to construct the tapLeafScript entry in the PSBT.\n *\n * @param params - HTLC connector parameters (subset of PrePeginParams)\n * @returns Hashlock and refund script info for PSBT construction\n */\nexport async function getPrePeginHtlcConnectorInfo(\n params: HtlcConnectorParams,\n): Promise<HtlcConnectorInfo> {\n return (await loadTbvWasm()).getPrePeginHtlcConnectorInfo(params);\n}\n\n/**\n * Compute the minimum depositor claim value (PegIn output 1) in satoshis.\n *\n * This covers the full downstream tx graph cost (Claim → Assert → Payout)\n * based on the protocol parameters.\n */\nexport async function computeMinClaimValue(\n txGraphVersion: number,\n numLocalChallengers: number,\n numUniversalChallengers: number,\n councilQuorum: number,\n councilSize: number,\n feeRate: bigint,\n): Promise<bigint> {\n return (await loadTbvWasm()).computeMinClaimValue(\n txGraphVersion,\n numLocalChallengers,\n numUniversalChallengers,\n councilQuorum,\n councilSize,\n feeRate,\n );\n}\n\n/**\n * Compute the minimum PegIn (activation) transaction fee in satoshis.\n *\n * `minPeginFee = peginTxVsize(numVks, numUcs) × minPeginFeeRate`. Each HTLC\n * the depositor funds in the Pre-PegIn tx must reserve at least this fee\n * inside its value (`htlcValue = peginAmount + depositorClaimValue +\n * minPeginFee`), otherwise the VP cannot afford to broadcast the PegIn at\n * activation. The vsize comes from a Taproot script-path-spend weight\n * prediction whose witness shape depends on the VK + UC signer count.\n */\nexport async function computeMinPeginFee(\n txGraphVersion: number,\n numVks: number,\n numUcs: number,\n minPeginFeeRate: bigint,\n): Promise<bigint> {\n return (await loadTbvWasm()).computeMinPeginFee(\n txGraphVersion,\n numVks,\n numUcs,\n minPeginFeeRate,\n );\n}\n\n/**\n * Floor of the Payout transaction fee under `txGraphVersion`: the minimum of\n * `estimatedVsize * feeRate` across every output-sizing model a deployed\n * vault provider is known to have used (fixed-34, intermediate,\n * script-aware). A VP-built payout paying less than this is provably not\n * produced by any known VP build. `out0Len` must be the TRUSTED length of the\n * pinned outs[0] script (1..=128); `out1Len` is the measured, UNTRUSTED\n * commission-script length — safe here because padding cannot raise the floor\n * (the fixed-34 model saturates the minimum) and shortening only lowers it.\n * Pass `undefined` for `out1Len` on 2-output (non-VP-claimer) payouts.\n * `feeRate` is the vault's version-locked `offchainParams.feeRate`.\n */\nexport async function computePayoutFeeFloor(\n txGraphVersion: number,\n numVaultKeepers: number,\n numUniversalChallengers: number,\n numLocalChallengers: number,\n councilSize: number,\n out0Len: number,\n out1Len: number | null | undefined,\n feeRate: bigint,\n): Promise<bigint> {\n return (await loadTbvWasm()).computePayoutFeeFloor(\n txGraphVersion,\n numVaultKeepers,\n numUniversalChallengers,\n numLocalChallengers,\n councilSize,\n out0Len,\n out1Len,\n feeRate,\n );\n}\n\n/**\n * Tx graph versions the shipped vault-wasm binary can build. Callers must\n * preflight the required version (fresh: active; resume: stamped) against\n * this list and fail closed instead of hitting per-call errors mid-flow.\n *\n * Note: the facade constructors themselves fail closed on unsupported\n * versions, and derived objects carry the version they were built with —\n * value-level cross-checks live in `assertWasmPeginSizing` and the golden\n * byte-parity tests, not in a per-call version echo.\n */\nexport async function supportedTxGraphVersions(): Promise<number[]> {\n return (await loadTbvWasm()).supportedTxGraphVersions();\n}\n\n/**\n * The PegIn transaction's P2A (pay-to-anchor) output for a graph version, or\n * `null` when that version's PegIn carries no anchor (v1). The facade returns\n * one record per version — never a zero-valued placeholder — so an absent\n * anchor can't be mistaken for a real output. For v2/v3: 240 sats at vout 2,\n * script `51024e73`.\n */\nexport async function peginP2aAnchorOutput(\n txGraphVersion: number,\n): Promise<PeginP2aAnchorInfo | null> {\n return (await loadTbvWasm()).peginP2aAnchorOutput(txGraphVersion);\n}\n\n/**\n * Validate a PegIn transaction's P2A anchor against a graph version's rules:\n * v2 and v3 require the exact anchor (240 sats, vout 2, P2A script) and v1\n * requires that NO output carries the P2A script. Throws on any mismatch — a\n * v2 PegIn checked as v1 fails closed, and vice versa.\n */\nexport async function validatePeginP2aAnchor(\n txGraphVersion: number,\n txHex: string,\n): Promise<void> {\n return (await loadTbvWasm()).validatePeginP2aAnchor(txGraphVersion, txHex);\n}\n\n/**\n * Creates a payout connector for vault transactions.\n *\n * The payout connector generates the necessary taproot scripts and information\n * required for signing payout transactions (both optimistic and regular payout paths).\n *\n * @param params - Parameters for creating the payout connector\n * @param network - Bitcoin network\n * @returns Payout connector information including scripts, hashes, and address\n */\nexport async function createPayoutConnector(\n params: PayoutConnectorParams,\n network: Network,\n): Promise<PayoutConnectorInfo> {\n return (await loadTbvWasm()).createPayoutConnector(params, network);\n}\n\n/**\n * Get the Payout script and control block for the depositor's Assert output.\n *\n * Used to build the depositor's Payout PSBT (depositor-as-claimer path).\n *\n * @param params - Assert Payout/NoPayout connector parameters\n * @returns Payout script and control block (hex encoded)\n */\nexport async function getAssertPayoutScriptInfo(\n params: AssertPayoutNoPayoutConnectorParams,\n): Promise<AssertPayoutScriptInfo> {\n return (await loadTbvWasm()).getAssertPayoutScriptInfo(params);\n}\n\n/**\n * Get the NoPayout script and control block for a specific challenger.\n *\n * Used to build the depositor's NoPayout PSBT (depositor-as-claimer path).\n * Each challenger has a distinct NoPayout script.\n *\n * @param params - Assert Payout/NoPayout connector parameters\n * @param challengerPubkey - The challenger's x-only public key (hex encoded)\n * @returns NoPayout script and control block (hex encoded)\n */\nexport async function getAssertNoPayoutScriptInfo(\n params: AssertPayoutNoPayoutConnectorParams,\n challengerPubkey: string,\n): Promise<AssertNoPayoutScriptInfo> {\n return (await loadTbvWasm()).getAssertNoPayoutScriptInfo(\n params,\n challengerPubkey,\n );\n}\n\n/**\n * Get the ChallengeAssert script and control block.\n *\n * Used to build ChallengeAssert PSBTs for the depositor-as-claimer path.\n * Each challenger has 3 ChallengeAssert transactions, and this connector\n * generates the spending scripts using WOTS public keys from the VP.\n *\n * @param params - ChallengeAssert connector parameters\n * @returns Script and control block (hex encoded)\n */\nexport async function getChallengeAssertScriptInfo(\n params: ChallengeAssertConnectorParams,\n): Promise<ChallengeAssertScriptInfo> {\n return (await loadTbvWasm()).getChallengeAssertScriptInfo(params);\n}\n\n/**\n * Derive 32-byte `authAnchor` (OP_RETURN preimage → VP bearer token).\n * @stability frozen - btc-vault Rust owns this API through the vault-wasm pin (`VAULT_WASM_COMMIT`).\n * Changing the derived bytes breaks VP auth for existing deposits. See CLAUDE.md §4.\n */\nexport async function expandAuthAnchor(root: Uint8Array): Promise<Uint8Array> {\n return (await loadTbvWasm()).expandAuthAnchor(root);\n}\n\n/**\n * Derive 32-byte `hashlockSecret` for HTLC `htlcVout` (preimage → `activateVaultWithSecret`).\n * @stability frozen - btc-vault Rust owns this API.\n * Changing the derived bytes means affected vaults can never activate. See CLAUDE.md §4.\n */\nexport async function expandHashlockSecret(\n root: Uint8Array,\n htlcVout: number,\n): Promise<Uint8Array> {\n return (await loadTbvWasm()).expandHashlockSecret(root, htlcVout);\n}\n\n/**\n * Derive 64-byte `wotsSeed` for HTLC `htlcVout` (→ WOTS keys, hashed as `depositorWotsPkHash`).\n * @stability frozen - btc-vault Rust owns this API.\n * Changing the derived bytes breaks existing `depositorWotsPkHash` values. No claim path remains. See CLAUDE.md §4.\n */\nexport async function expandWotsSeed(\n root: Uint8Array,\n htlcVout: number,\n): Promise<Uint8Array> {\n return (await loadTbvWasm()).expandWotsSeed(root, htlcVout);\n}\n\n/**\n * Derives the vault ID from a PegIn transaction hash and depositor ETH address.\n *\n * Vault ID = keccak256(abi.encode(peginTxHash, depositor))\n * This matches the Solidity-side derivation in BTCVaultRegistry.\n *\n * @param peginTxHash - 32-byte PegIn tx hash in display order (big-endian), hex encoded\n * @param depositor - 20-byte Ethereum address of the depositor, hex encoded\n * @returns Hex-encoded vault ID (32 bytes)\n */\nexport async function deriveVaultId(\n peginTxHash: string,\n depositor: string,\n): Promise<string> {\n return (await loadTbvWasm()).deriveVaultId(peginTxHash, depositor);\n}\n\nexport type {\n AssertNoPayoutScriptInfo,\n AssertPayoutNoPayoutConnectorParams,\n AssertPayoutScriptInfo,\n ChallengeAssertConnectorParams,\n ChallengeAssertScriptInfo,\n HtlcConnectorInfo,\n HtlcConnectorParams,\n Network,\n PayoutConnectorInfo,\n PayoutConnectorParams,\n PeginP2aAnchorInfo,\n PeginTxResult,\n PrePeginParams,\n PrePeginResult,\n};\n"],"names":["TAP_INTERNAL_KEY","tapInternalPubkey","_","index","wasmModulePromise","loadTbvWasm","error","wasm","createPrePeginTransaction","params","buildPeginTxFromPrePegin","timelockPegin","fundedPrePeginTxHex","htlcVout","getPrePeginHtlcConnectorInfo","computeMinClaimValue","txGraphVersion","numLocalChallengers","numUniversalChallengers","councilQuorum","councilSize","feeRate","computeMinPeginFee","numVks","numUcs","minPeginFeeRate","computePayoutFeeFloor","numVaultKeepers","out0Len","out1Len","supportedTxGraphVersions","peginP2aAnchorOutput","validatePeginP2aAnchor","txHex","createPayoutConnector","network","getAssertPayoutScriptInfo","getAssertNoPayoutScriptInfo","challengerPubkey","getChallengeAssertScriptInfo","expandAuthAnchor","root","expandHashlockSecret","expandWotsSeed","deriveVaultId","peginTxHash","depositor"],"mappings":"AAQO,MAAMA,IACX;AAIK,MAAMC,IAAoB,WAAW;AAAA,EAC1C,EAAE,QAAQD,EAAiB,SAAS,EAAA;AAAA,EACpC,CAACE,GAAGC,MACF,OAAO;AAAA,IACLH,EAAiB;AAAA,M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