@babylonlabs-io/ts-sdk 3.3.0 → 4.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.
Files changed (170) hide show
  1. package/dist/{BTCVaultRegistry.abi-BzNTa_EU.js → BTCVaultRegistry.abi-DnP4UkB5.js} +9 -140
  2. package/dist/BTCVaultRegistry.abi-DnP4UkB5.js.map +1 -0
  3. package/dist/{BTCVaultRegistry.abi-BH2-LHxN.cjs → BTCVaultRegistry.abi-DzbfZ9_s.cjs} +2 -2
  4. package/dist/BTCVaultRegistry.abi-DzbfZ9_s.cjs.map +1 -0
  5. package/dist/{PayoutManager-xEGvTbhL.js → PayoutManager-BUWP-H-q.js} +3 -3
  6. package/dist/PayoutManager-BUWP-H-q.js.map +1 -0
  7. package/dist/{PayoutManager-B1Ev0r7o.cjs → PayoutManager-Dopxq_Jv.cjs} +2 -2
  8. package/dist/PayoutManager-Dopxq_Jv.cjs.map +1 -0
  9. package/dist/PeginManager-CMbRRTnr.cjs +2 -0
  10. package/dist/{PeginManager-Co43rW_x.cjs.map → PeginManager-CMbRRTnr.cjs.map} +1 -1
  11. package/dist/{PeginManager-BJnUgW8C.js → PeginManager-Cas6_j7t.js} +118 -107
  12. package/dist/{PeginManager-BJnUgW8C.js.map → PeginManager-Cas6_j7t.js.map} +1 -1
  13. package/dist/{ProtocolParams.abi-Cv77fsUe.js → ProtocolParams.abi-CuDl7AuC.js} +3 -3
  14. package/dist/{ProtocolParams.abi-Cv77fsUe.js.map → ProtocolParams.abi-CuDl7AuC.js.map} +1 -1
  15. package/dist/{ProtocolParams.abi-BgEZaQ2I.cjs → ProtocolParams.abi-DWfIh6VH.cjs} +2 -2
  16. package/dist/{ProtocolParams.abi-BgEZaQ2I.cjs.map → ProtocolParams.abi-DWfIh6VH.cjs.map} +1 -1
  17. package/dist/VaultErrors.abi-Dc3UnB_h.js +5 -0
  18. package/dist/{VaultErrors.abi-Boz4w97c.js.map → VaultErrors.abi-Dc3UnB_h.js.map} +1 -1
  19. package/dist/VaultErrors.abi-Hjn1CdLs.cjs +2 -0
  20. package/dist/{VaultErrors.abi-DQ18kM0L.cjs.map → VaultErrors.abi-Hjn1CdLs.cjs.map} +1 -1
  21. package/dist/buildAndBroadcastReclaim-CVmG3ldA.cjs +2 -0
  22. package/dist/buildAndBroadcastReclaim-CVmG3ldA.cjs.map +1 -0
  23. package/dist/{buildAndBroadcastReclaim-CQANDXVJ.js → buildAndBroadcastReclaim-XRWuJWVL.js} +48 -50
  24. package/dist/buildAndBroadcastReclaim-XRWuJWVL.js.map +1 -0
  25. package/dist/{challengeAssert-C3eMcM5Y.cjs → challengeAssert-BE6Wm4x1.cjs} +2 -2
  26. package/dist/challengeAssert-BE6Wm4x1.cjs.map +1 -0
  27. package/dist/{challengeAssert-B2otuf7y.js → challengeAssert-DUKSjirl.js} +3 -3
  28. package/dist/challengeAssert-DUKSjirl.js.map +1 -0
  29. package/dist/constants-BCg6O0PX.cjs +2 -0
  30. package/dist/constants-BCg6O0PX.cjs.map +1 -0
  31. package/dist/constants-CmDDuM3L.js +50 -0
  32. package/dist/constants-CmDDuM3L.js.map +1 -0
  33. package/dist/{index-BRsWXDlv.js → index-B-9aXMxk.js} +6 -6
  34. package/dist/{index-BRsWXDlv.js.map → index-B-9aXMxk.js.map} +1 -1
  35. package/dist/{index-C6avwx1s.cjs → index-Dn7RlsKK.cjs} +2 -2
  36. package/dist/{index-C6avwx1s.cjs.map → index-Dn7RlsKK.cjs.map} +1 -1
  37. package/dist/index.cjs +1 -1
  38. package/dist/index.js +16 -16
  39. package/dist/pegin-registration-client-DLlaZbsZ.cjs +2 -0
  40. package/dist/pegin-registration-client-DLlaZbsZ.cjs.map +1 -0
  41. package/dist/{pegin-registration-client-Cvjk4ILq.js → pegin-registration-client-ZI0k10_3.js} +90 -96
  42. package/dist/pegin-registration-client-ZI0k10_3.js.map +1 -0
  43. package/dist/{primeVpAuth-D4UWXQ76.js → primeVpAuth-C-ET0XF4.js} +2 -2
  44. package/dist/{primeVpAuth-D4UWXQ76.js.map → primeVpAuth-C-ET0XF4.js.map} +1 -1
  45. package/dist/{primeVpAuth-CXNXYKrh.cjs → primeVpAuth-Ch-ig2My.cjs} +2 -2
  46. package/dist/{primeVpAuth-CXNXYKrh.cjs.map → primeVpAuth-Ch-ig2My.cjs.map} +1 -1
  47. package/dist/registration-records-CKc0OVuK.cjs +2 -0
  48. package/dist/registration-records-CKc0OVuK.cjs.map +1 -0
  49. package/dist/{registration-records-DJJC2NiO.js → registration-records-D39ApuHS.js} +141 -141
  50. package/dist/registration-records-D39ApuHS.js.map +1 -0
  51. package/dist/shared/index.cjs.map +1 -1
  52. package/dist/shared/index.js.map +1 -1
  53. package/dist/shared/wallets/interfaces/BitcoinWallet.d.ts +5 -0
  54. package/dist/shared/wallets/interfaces/BitcoinWallet.d.ts.map +1 -1
  55. package/dist/{signer-set-reader-GrFe_rsW.cjs → signer-set-reader-CJfV-GDz.cjs} +2 -2
  56. package/dist/{signer-set-reader-GrFe_rsW.cjs.map → signer-set-reader-CJfV-GDz.cjs.map} +1 -1
  57. package/dist/{signer-set-reader-CSUe92zE.js → signer-set-reader-DiwLeqik.js} +3 -3
  58. package/dist/{signer-set-reader-CSUe92zE.js.map → signer-set-reader-DiwLeqik.js.map} +1 -1
  59. package/dist/tbv/core/clients/eth/index.cjs +1 -1
  60. package/dist/tbv/core/clients/eth/index.js +4 -4
  61. package/dist/tbv/core/clients/eth/protocol-params-validation.d.ts.map +1 -1
  62. package/dist/tbv/core/clients/eth/registration-logs-error.d.ts +6 -6
  63. package/dist/tbv/core/clients/eth/registration-records.d.ts +1 -1
  64. package/dist/tbv/core/clients/eth/types.d.ts +12 -13
  65. package/dist/tbv/core/clients/eth/types.d.ts.map +1 -1
  66. package/dist/tbv/core/clients/eth/vault-registry-reader.d.ts +1 -1
  67. package/dist/tbv/core/clients/eth/vault-registry-reader.d.ts.map +1 -1
  68. package/dist/tbv/core/clients/index.cjs +1 -1
  69. package/dist/tbv/core/clients/index.js +6 -6
  70. package/dist/tbv/core/clients/vault-provider/status/index.cjs +1 -1
  71. package/dist/tbv/core/clients/vault-provider/status/index.js +1 -1
  72. package/dist/tbv/core/contracts/abis/BTCVaultRegistry.abi.d.ts +5 -111
  73. package/dist/tbv/core/contracts/abis/BTCVaultRegistry.abi.d.ts.map +1 -1
  74. package/dist/tbv/core/contracts/abis/ProtocolParams.abi.d.ts +2 -2
  75. package/dist/tbv/core/contracts/abis/vaultErrors.abi.json.d.ts +1 -1
  76. package/dist/tbv/core/contracts/index.cjs +1 -1
  77. package/dist/tbv/core/contracts/index.js +3 -3
  78. package/dist/tbv/core/deposit-terms/__tests__/rebuildDepositTermsCore.test.d.ts +1 -1
  79. package/dist/tbv/core/deposit-terms/commissionCeiling.d.ts +1 -1
  80. package/dist/tbv/core/deposit-terms/depositTerms.d.ts +5 -5
  81. package/dist/tbv/core/deposit-terms/rebuildDepositTermsCore.d.ts.map +1 -1
  82. package/dist/tbv/core/index.cjs +1 -1
  83. package/dist/tbv/core/index.js +16 -16
  84. package/dist/tbv/core/managers/PeginManager.d.ts +2 -1
  85. package/dist/tbv/core/managers/PeginManager.d.ts.map +1 -1
  86. package/dist/tbv/core/managers/index.cjs +1 -1
  87. package/dist/tbv/core/managers/index.js +2 -2
  88. package/dist/tbv/core/primitives/__tests__/vaultCoreVersion.test.d.ts +1 -1
  89. package/dist/tbv/core/primitives/index.cjs +1 -1
  90. package/dist/tbv/core/primitives/index.js +3 -3
  91. package/dist/tbv/core/primitives/psbt/__tests__/deriveExpectedPeginPayoutScriptPubKey.test.d.ts +1 -1
  92. package/dist/tbv/core/primitives/psbt/assertWasmPeginSizing.d.ts.map +1 -1
  93. package/dist/tbv/core/primitives/psbt/constants.d.ts +38 -13
  94. package/dist/tbv/core/primitives/psbt/constants.d.ts.map +1 -1
  95. package/dist/tbv/core/primitives/psbt/depositorClaim.d.ts +3 -6
  96. package/dist/tbv/core/primitives/psbt/depositorClaim.d.ts.map +1 -1
  97. package/dist/tbv/core/primitives/psbt/pegin.d.ts +3 -5
  98. package/dist/tbv/core/primitives/psbt/pegin.d.ts.map +1 -1
  99. package/dist/tbv/core/recovery/peginParamsCandidates.d.ts +1 -1
  100. package/dist/tbv/core/recovery/reconstructPeginParams.d.ts.map +1 -1
  101. package/dist/tbv/core/services/delegated-claim/__tests__/realWasmWatchtowerArtifacts.test.d.ts +2 -2
  102. package/dist/tbv/core/services/delegated-claim/assembleWatchtowerArtifacts.d.ts +2 -1
  103. package/dist/tbv/core/services/delegated-claim/assembleWatchtowerArtifacts.d.ts.map +1 -1
  104. package/dist/tbv/core/services/delegated-claim/deriveClaimerWotsKeypair.d.ts +1 -1
  105. package/dist/tbv/core/services/delegated-claim/deriveClaimerWotsKeypair.d.ts.map +1 -1
  106. package/dist/tbv/core/services/delegated-claim/planDelegatedClaimSigning.d.ts +2 -1
  107. package/dist/tbv/core/services/delegated-claim/planDelegatedClaimSigning.d.ts.map +1 -1
  108. package/dist/tbv/core/services/delegated-claim/readDelegatedClaimVaultContext.d.ts +1 -1
  109. package/dist/tbv/core/services/delegated-claim/readDelegatedClaimVaultContext.d.ts.map +1 -1
  110. package/dist/tbv/core/services/delegated-claim/readWatchtowerArtifacts.d.ts +3 -3
  111. package/dist/tbv/core/services/delegated-claim/readWatchtowerArtifacts.d.ts.map +1 -1
  112. package/dist/tbv/core/services/delegated-claim/types.d.ts +5 -6
  113. package/dist/tbv/core/services/delegated-claim/types.d.ts.map +1 -1
  114. package/dist/tbv/core/services/deposit/__tests__/signDepositorGraph.realGraph.test.d.ts +3 -3
  115. package/dist/tbv/core/services/deposit/signDepositorGraph.d.ts.map +1 -1
  116. package/dist/tbv/core/services/index.cjs +1 -1
  117. package/dist/tbv/core/services/index.js +2 -2
  118. package/dist/tbv/core/wasm/index.cjs.map +1 -1
  119. package/dist/tbv/core/wasm/index.d.ts +8 -11
  120. package/dist/tbv/core/wasm/index.d.ts.map +1 -1
  121. package/dist/tbv/core/wasm/index.js.map +1 -1
  122. package/dist/tbv/index.cjs +1 -1
  123. package/dist/tbv/index.js +16 -16
  124. package/dist/toRefundInputs-BSQjDOK9.cjs +2 -0
  125. package/dist/toRefundInputs-BSQjDOK9.cjs.map +1 -0
  126. package/dist/{toRefundInputs-Dzw1cteD.js → toRefundInputs-BbbvPb2A.js} +175 -173
  127. package/dist/toRefundInputs-BbbvPb2A.js.map +1 -0
  128. package/dist/{types-BC2TGzcp.cjs → types-BnZIbDHb.cjs} +2 -2
  129. package/dist/types-BnZIbDHb.cjs.map +1 -0
  130. package/dist/{types-24A9Qoxb.js → types-K_aM5GZO.js} +39 -39
  131. package/dist/types-K_aM5GZO.js.map +1 -0
  132. package/dist/{verifyKeyPathSchnorrSignature-IIj3Z2se.js → verifyKeyPathSchnorrSignature-DPXOFOol.js} +2 -2
  133. package/dist/{verifyKeyPathSchnorrSignature-IIj3Z2se.js.map → verifyKeyPathSchnorrSignature-DPXOFOol.js.map} +1 -1
  134. package/dist/{verifyKeyPathSchnorrSignature-BRTpEH9X.cjs → verifyKeyPathSchnorrSignature-DcxCojp0.cjs} +2 -2
  135. package/dist/{verifyKeyPathSchnorrSignature-BRTpEH9X.cjs.map → verifyKeyPathSchnorrSignature-DcxCojp0.cjs.map} +1 -1
  136. package/dist/verifyScriptPathSchnorrSignature-CgDa9Rcg.cjs +2 -0
  137. package/dist/verifyScriptPathSchnorrSignature-CgDa9Rcg.cjs.map +1 -0
  138. package/dist/{verifyScriptPathSchnorrSignature-owu3BfyT.js → verifyScriptPathSchnorrSignature-D-fdi-sG.js} +462 -459
  139. package/dist/verifyScriptPathSchnorrSignature-D-fdi-sG.js.map +1 -0
  140. package/package.json +3 -3
  141. package/dist/BTCVaultRegistry.abi-BH2-LHxN.cjs.map +0 -1
  142. package/dist/BTCVaultRegistry.abi-BzNTa_EU.js.map +0 -1
  143. package/dist/PayoutManager-B1Ev0r7o.cjs.map +0 -1
  144. package/dist/PayoutManager-xEGvTbhL.js.map +0 -1
  145. package/dist/PeginManager-Co43rW_x.cjs +0 -2
  146. package/dist/VaultErrors.abi-Boz4w97c.js +0 -5
  147. package/dist/VaultErrors.abi-DQ18kM0L.cjs +0 -2
  148. package/dist/buildAndBroadcastReclaim-CQANDXVJ.js.map +0 -1
  149. package/dist/buildAndBroadcastReclaim-DPk36Uhp.cjs +0 -2
  150. package/dist/buildAndBroadcastReclaim-DPk36Uhp.cjs.map +0 -1
  151. package/dist/challengeAssert-B2otuf7y.js.map +0 -1
  152. package/dist/challengeAssert-C3eMcM5Y.cjs.map +0 -1
  153. package/dist/constants-CAm10Qwp.cjs +0 -2
  154. package/dist/constants-CAm10Qwp.cjs.map +0 -1
  155. package/dist/constants-CvQZuxKv.js +0 -48
  156. package/dist/constants-CvQZuxKv.js.map +0 -1
  157. package/dist/pegin-registration-client-CdRyXP3j.cjs +0 -2
  158. package/dist/pegin-registration-client-CdRyXP3j.cjs.map +0 -1
  159. package/dist/pegin-registration-client-Cvjk4ILq.js.map +0 -1
  160. package/dist/registration-records-DJJC2NiO.js.map +0 -1
  161. package/dist/registration-records-XQMIKjGV.cjs +0 -2
  162. package/dist/registration-records-XQMIKjGV.cjs.map +0 -1
  163. package/dist/toRefundInputs-DTuWi--u.cjs +0 -2
  164. package/dist/toRefundInputs-DTuWi--u.cjs.map +0 -1
  165. package/dist/toRefundInputs-Dzw1cteD.js.map +0 -1
  166. package/dist/types-24A9Qoxb.js.map +0 -1
  167. package/dist/types-BC2TGzcp.cjs.map +0 -1
  168. package/dist/verifyScriptPathSchnorrSignature-CahYx5Td.cjs +0 -2
  169. package/dist/verifyScriptPathSchnorrSignature-CahYx5Td.cjs.map +0 -1
  170. package/dist/verifyScriptPathSchnorrSignature-owu3BfyT.js.map +0 -1
@@ -1,55 +1,55 @@
1
- import { script as x, opcodes as E, payments as L, Transaction as k, crypto as U, Psbt as H } from "bitcoinjs-lib";
2
- import { computeMinClaimValue as ye, peginP2aAnchorOutput as me, computeMinPeginFee as Ie, tapInternalPubkey as _, buildPeginTxFromPrePegin as Ae, createPrePeginTransaction as Te, validatePeginP2aAnchor as Oe, createPayoutConnector as Ve, computePayoutFeeFloor as Le, getAssertPayoutScriptInfo as Re } from "./tbv/core/wasm/index.js";
3
- import { c as q, p as Ke, d as He } from "./fundPeginTransaction-CwhRbCQC.js";
4
- import { p as Ne, s as f, d as $e, m as Se, T as y, h as C, u as M, j as Ue, S as W } from "./bitcoin-C-TuHb-v.js";
5
- import { b as Be } from "./secp256k1-BuxBFUHm.js";
6
- import { Buffer as c } from "buffer";
7
- import { P as X, k as G, l as z, m as Y, n as Me, o as D, p as Fe, q as qe, r as Q, s as Z, t as j, u as J, v as ee, w as te, M as oe, j as ne, x as We, A as xe, B as Xe, V as Ge, y as re } from "./constants-CvQZuxKv.js";
8
- import * as Ce from "@bitcoin-js/tiny-secp256k1-asmjs";
9
- import { X as ie } from "./validation-OSC0xTHB.js";
1
+ import { script as x, opcodes as w, payments as L, Transaction as k, crypto as U, Psbt as H } from "bitcoinjs-lib";
2
+ import { computeMinClaimValue as Se, peginP2aAnchorOutput as Te, computeMinPeginFee as Oe, tapInternalPubkey as I, buildPeginTxFromPrePegin as Ve, createPrePeginTransaction as Le, validatePeginP2aAnchor as Re, createPayoutConnector as Ke, computePayoutFeeFloor as He, getAssertPayoutScriptInfo as Ne } from "./tbv/core/wasm/index.js";
3
+ import { c as q, p as Ue, d as Be } from "./fundPeginTransaction-CwhRbCQC.js";
4
+ import { p as Me, s as f, d as xe, m as Ce, T as y, h as C, u as M, j as Fe, S as W } from "./bitcoin-C-TuHb-v.js";
5
+ import { b as qe } from "./secp256k1-BuxBFUHm.js";
6
+ import { Buffer as a } from "buffer";
7
+ import { P as X, l as G, m as z, n as Y, o as We, p as D, q as Q, r as Z, s as j, t as J, u as ee, v as te, w as oe, x as ne, y as re, M as ie, j as se, z as Xe, A as be, B as Ge, V as ze, E as ue } from "./constants-CmDDuM3L.js";
8
+ import * as ke from "@bitcoin-js/tiny-secp256k1-asmjs";
9
+ import { X as ce } from "./validation-OSC0xTHB.js";
10
10
  function b(e) {
11
- return Ne(e).toLowerCase();
11
+ return Me(e).toLowerCase();
12
12
  }
13
13
  function Qt(e, t, o) {
14
14
  const n = /* @__PURE__ */ new Set();
15
15
  n.add(b(e));
16
- for (const i of t)
17
- n.add(b(i));
16
+ for (const r of t)
17
+ n.add(b(r));
18
18
  return n.delete(b(o)), n.size;
19
19
  }
20
- function ze(e) {
20
+ function Ye(e) {
21
21
  const t = b(e.claimerBtcPubkey), o = b(e.depositorBtcPubkey), n = e.vaultKeeperBtcPubkeys.map(b);
22
22
  if (t === o) {
23
- const r = n.filter((u) => u !== o);
24
- if (r.length === 0)
23
+ const s = n.filter((u) => u !== o);
24
+ if (s.length === 0)
25
25
  throw new Error(
26
26
  "Cannot derive localChallengers: vault keeper set is empty (or contains only the depositor)"
27
27
  );
28
- if (new Set(r).size !== r.length)
28
+ if (new Set(s).size !== s.length)
29
29
  throw new Error(
30
30
  "Cannot derive localChallengers: duplicate vaultKeeper key — signing context is misconfigured"
31
31
  );
32
- return r;
32
+ return s;
33
33
  }
34
- const s = [
34
+ const i = [
35
35
  .../* @__PURE__ */ new Set([b(e.vaultProviderBtcPubkey), ...n])
36
- ].sort().filter((r) => r !== t);
37
- if (s.length === 0)
36
+ ].sort().filter((s) => s !== t);
37
+ if (i.length === 0)
38
38
  throw new Error(
39
39
  `Cannot derive localChallengers: no vault provider or vault keeper remains after excluding claimer ${t}`
40
40
  );
41
- return s;
41
+ return i;
42
42
  }
43
- const Ye = 32, De = 65535, Qe = 2;
44
- function I(e, t) {
43
+ const De = 32, Qe = 65535, Ze = 2;
44
+ function _(e, t) {
45
45
  const o = f(e).toLowerCase();
46
46
  if (!/^[0-9a-f]{64}$/.test(o))
47
47
  throw new Error(`${t} must be a 32-byte x-only public key.`);
48
48
  try {
49
- Be.Point.fromBytes(
50
- c.concat([
51
- c.from([Qe]),
52
- c.from(o, "hex")
49
+ qe.Point.fromBytes(
50
+ a.concat([
51
+ a.from([Ze]),
52
+ a.from(o, "hex")
53
53
  ])
54
54
  );
55
55
  } catch {
@@ -60,122 +60,122 @@ function I(e, t) {
60
60
  function R(e, t) {
61
61
  if (e.length === 0)
62
62
  throw new Error(`${t} must not be empty.`);
63
- const o = e.map((n, i) => I(n, `${t}[${i}]`)).sort();
63
+ const o = e.map((n, r) => _(n, `${t}[${r}]`)).sort();
64
64
  if (new Set(o).size !== o.length)
65
65
  throw new Error(`${t} must not contain duplicate keys.`);
66
66
  return o;
67
67
  }
68
68
  function K(e, t) {
69
69
  const o = [];
70
- return e.forEach((n, i) => {
70
+ return e.forEach((n, r) => {
71
71
  o.push(
72
- c.from(n, "hex"),
73
- i === 0 ? E.OP_CHECKSIG : E.OP_CHECKSIGADD
72
+ a.from(n, "hex"),
73
+ r === 0 ? w.OP_CHECKSIG : w.OP_CHECKSIGADD
74
74
  );
75
75
  }), o.push(
76
76
  x.number.encode(e.length),
77
- t ? E.OP_NUMEQUALVERIFY : E.OP_NUMEQUAL
77
+ t ? w.OP_NUMEQUALVERIFY : w.OP_NUMEQUAL
78
78
  ), o;
79
79
  }
80
- function Ze(e, t) {
80
+ function je(e, t) {
81
81
  var g;
82
- Se();
83
- const o = I(
82
+ Ce();
83
+ const o = _(
84
84
  e.depositorPubkey,
85
85
  "depositorPubkey"
86
- ), n = I(
86
+ ), n = _(
87
87
  e.vaultProviderPubkey,
88
88
  "vaultProviderPubkey"
89
- ), i = R(
89
+ ), r = R(
90
90
  e.vaultKeeperPubkeys,
91
91
  "vaultKeeperPubkeys"
92
- ), s = R(
92
+ ), i = R(
93
93
  e.universalChallengerPubkeys,
94
94
  "universalChallengerPubkeys"
95
- ), r = f(t).toLowerCase();
96
- if (!/^[0-9a-f]{64}$/.test(r))
95
+ ), s = f(t).toLowerCase();
96
+ if (!/^[0-9a-f]{64}$/.test(s))
97
97
  throw new Error("hashlock must be 32 bytes.");
98
- if (!Number.isInteger(e.timelockRefund) || e.timelockRefund < 1 || e.timelockRefund > De)
98
+ if (!Number.isInteger(e.timelockRefund) || e.timelockRefund < 1 || e.timelockRefund > Qe)
99
99
  throw new Error("timelockRefund must be an integer from 1 to 65535.");
100
100
  const u = x.compile([
101
- E.OP_SIZE,
102
- x.number.encode(Ye),
103
- E.OP_EQUALVERIFY,
104
- E.OP_SHA256,
105
- c.from(r, "hex"),
106
- E.OP_EQUALVERIFY,
107
- c.from(o, "hex"),
108
- E.OP_CHECKSIGVERIFY,
109
- c.from(n, "hex"),
110
- E.OP_CHECKSIGVERIFY,
111
- ...K(i, !0),
112
- ...K(s, !1)
113
- ]), h = x.compile([
114
- c.from(o, "hex"),
115
- E.OP_CHECKSIGVERIFY,
101
+ w.OP_SIZE,
102
+ x.number.encode(De),
103
+ w.OP_EQUALVERIFY,
104
+ w.OP_SHA256,
105
+ a.from(s, "hex"),
106
+ w.OP_EQUALVERIFY,
107
+ a.from(o, "hex"),
108
+ w.OP_CHECKSIGVERIFY,
109
+ a.from(n, "hex"),
110
+ w.OP_CHECKSIGVERIFY,
111
+ ...K(r, !0),
112
+ ...K(i, !1)
113
+ ]), c = x.compile([
114
+ a.from(o, "hex"),
115
+ w.OP_CHECKSIGVERIFY,
116
116
  x.number.encode(e.timelockRefund),
117
- E.OP_CHECKSEQUENCEVERIFY
118
- ]), l = [
117
+ w.OP_CHECKSEQUENCEVERIFY
118
+ ]), p = [
119
119
  { output: u, version: y },
120
- { output: h, version: y }
121
- ], { hash: d, output: a, witness: P } = L.p2tr({
122
- internalPubkey: c.from(_),
123
- scriptTree: l,
120
+ { output: c, version: y }
121
+ ], { hash: l, output: h, witness: d } = L.p2tr({
122
+ internalPubkey: a.from(I),
123
+ scriptTree: p,
124
124
  redeem: {
125
125
  output: u,
126
126
  redeemVersion: y
127
127
  }
128
- }), p = P == null ? void 0 : P[P.length - 1], v = L.p2tr({
129
- internalPubkey: c.from(_),
130
- scriptTree: l,
128
+ }), P = d == null ? void 0 : d[d.length - 1], E = L.p2tr({
129
+ internalPubkey: a.from(I),
130
+ scriptTree: p,
131
131
  redeem: {
132
- output: h,
132
+ output: c,
133
133
  redeemVersion: y
134
134
  }
135
- }), w = (g = v.witness) == null ? void 0 : g[v.witness.length - 1];
136
- if (!d || !a || !p || !w)
135
+ }), v = (g = E.witness) == null ? void 0 : g[E.witness.length - 1];
136
+ if (!l || !h || !P || !v)
137
137
  throw new Error("Failed to derive the expected Pre-PegIn HTLC output.");
138
138
  return {
139
139
  hashlockScript: u,
140
- hashlockControlBlock: p,
141
- refundScript: h,
142
- refundControlBlock: w,
143
- scriptPubKey: a,
144
- tapMerkleRoot: d
140
+ hashlockControlBlock: P,
141
+ refundScript: c,
142
+ refundControlBlock: v,
143
+ scriptPubKey: h,
144
+ tapMerkleRoot: l
145
145
  };
146
146
  }
147
- function je(e, t) {
148
- Se();
149
- const o = I(
147
+ function Je(e, t) {
148
+ Ce();
149
+ const o = _(
150
150
  e.depositorPubkey,
151
151
  "depositorPubkey"
152
- ), n = I(
152
+ ), n = _(
153
153
  e.vaultProviderPubkey,
154
154
  "vaultProviderPubkey"
155
- ), i = R(
155
+ ), r = R(
156
156
  e.vaultKeeperPubkeys,
157
157
  "vaultKeeperPubkeys"
158
- ), s = R(
158
+ ), i = R(
159
159
  e.universalChallengerPubkeys,
160
160
  "universalChallengerPubkeys"
161
- ), r = x.compile([
162
- c.from(o, "hex"),
163
- E.OP_CHECKSIGVERIFY,
164
- c.from(n, "hex"),
165
- E.OP_CHECKSIGVERIFY,
161
+ ), s = x.compile([
162
+ a.from(o, "hex"),
163
+ w.OP_CHECKSIGVERIFY,
164
+ a.from(n, "hex"),
165
+ w.OP_CHECKSIGVERIFY,
166
+ ...K(r, !0),
166
167
  ...K(i, !0),
167
- ...K(s, !0),
168
168
  x.number.encode(t),
169
- E.OP_CHECKSEQUENCEVERIFY
169
+ w.OP_CHECKSEQUENCEVERIFY
170
170
  ]), { output: u } = L.p2tr({
171
- internalPubkey: c.from(_),
172
- scriptTree: { output: r, version: y }
171
+ internalPubkey: a.from(I),
172
+ scriptTree: { output: s, version: y }
173
173
  });
174
174
  if (!u)
175
175
  throw new Error("Failed to derive the expected PegIn payout output.");
176
176
  return u;
177
177
  }
178
- async function Je(e, t) {
178
+ async function et(e, t) {
179
179
  const o = t.pegInAmounts.length;
180
180
  if (t.hashlocks.length !== o)
181
181
  throw new Error(
@@ -193,7 +193,7 @@ async function Je(e, t) {
193
193
  throw new Error(
194
194
  `WASM Pre-PegIn returned non-positive depositorClaimValue ${e.depositorClaimValue}; expected > 0.`
195
195
  );
196
- const n = await ye(
196
+ const n = await Se(
197
197
  // Must price the same graph version the builder constructed.
198
198
  t.vaultCoreVersion,
199
199
  t.numLocalChallengers,
@@ -206,154 +206,156 @@ async function Je(e, t) {
206
206
  throw new Error(
207
207
  `WASM Pre-PegIn depositorClaimValue ${e.depositorClaimValue} does not match the independently computed minimum claim value ${n} (vaultCoreVersion=${t.vaultCoreVersion}, numLocalChallengers=${t.numLocalChallengers}, numUniversalChallengers=${t.universalChallengerPubkeys.length}, councilQuorum=${t.councilQuorum}, councilSize=${t.councilSize}, feeRate=${t.feeRate}).`
208
208
  );
209
- const i = await me(t.vaultCoreVersion), s = (i == null ? void 0 : i.value) ?? 0n, r = await Ie(
209
+ const { value: r } = await Te(
210
+ t.vaultCoreVersion
211
+ ), i = await Oe(
210
212
  t.vaultCoreVersion,
211
213
  t.vaultKeeperPubkeys.length,
212
214
  t.universalChallengerPubkeys.length,
213
215
  t.minPeginFeeRate
214
- ), u = r + s, h = t.minPeginFeeRate * q;
215
- for (let l = 0; l < o; l++) {
216
- const d = t.pegInAmounts[l], a = e.peginAmounts[l], P = e.htlcValues[l];
217
- if (a !== d)
216
+ ), s = i + r, u = t.minPeginFeeRate * q;
217
+ for (let c = 0; c < o; c++) {
218
+ const p = t.pegInAmounts[c], l = e.peginAmounts[c], h = e.htlcValues[c];
219
+ if (l !== p)
218
220
  throw new Error(
219
- `WASM Pre-PegIn peginAmount[${l}] ${a} does not match the requested amount ${d}; refusing to build a tx whose recorded amount differs from the depositor's request.`
221
+ `WASM Pre-PegIn peginAmount[${c}] ${l} does not match the requested amount ${p}; refusing to build a tx whose recorded amount differs from the depositor's request.`
220
222
  );
221
- if (a <= 0n)
223
+ if (l <= 0n)
222
224
  throw new Error(
223
- `WASM Pre-PegIn peginAmount[${l}] is non-positive (${a}); expected > 0.`
225
+ `WASM Pre-PegIn peginAmount[${c}] is non-positive (${l}); expected > 0.`
224
226
  );
225
- if (P <= 0n)
227
+ if (h <= 0n)
226
228
  throw new Error(
227
- `WASM Pre-PegIn htlcValue[${l}] is non-positive (${P}); expected > 0.`
229
+ `WASM Pre-PegIn htlcValue[${c}] is non-positive (${h}); expected > 0.`
228
230
  );
229
- const p = P - a - e.depositorClaimValue;
230
- if (p <= 0n)
231
+ const d = h - l - e.depositorClaimValue;
232
+ if (d <= 0n)
231
233
  throw new Error(
232
- `WASM Pre-PegIn htlcValue[${l}] ${P} does not strictly cover peginAmount ${a} + depositorClaimValue ${e.depositorClaimValue} + a PegIn reserve (implied reserve ${p}).`
234
+ `WASM Pre-PegIn htlcValue[${c}] ${h} does not strictly cover peginAmount ${l} + depositorClaimValue ${e.depositorClaimValue} + a PegIn reserve (implied reserve ${d}).`
233
235
  );
234
- if (p > h)
236
+ if (d > u)
235
237
  throw new Error(
236
- `WASM Pre-PegIn implied reserve for HTLC[${l}] (${p} sat) exceeds the plausibility cap ${h} sat (minPeginFeeRate=${t.minPeginFeeRate} × ${q} vbytes); htlcValue ${P} appears grossly inflated.`
238
+ `WASM Pre-PegIn implied reserve for HTLC[${c}] (${d} sat) exceeds the plausibility cap ${u} sat (minPeginFeeRate=${t.minPeginFeeRate} × ${q} vbytes); htlcValue ${h} appears grossly inflated.`
237
239
  );
238
- if (p !== u)
240
+ if (d !== s)
239
241
  throw new Error(
240
- `WASM Pre-PegIn htlcValue[${l}] ${P} implies a PegIn fee+anchor reserve of ${p} sat, expected exactly ${u} sat (minPeginFee ${r} + p2aAnchor ${s} for vaultCoreVersion ${t.vaultCoreVersion}, vaultKeepers=${t.vaultKeeperPubkeys.length}, universalChallengers=${t.universalChallengerPubkeys.length}, minPeginFeeRate=${t.minPeginFeeRate}).`
242
+ `WASM Pre-PegIn htlcValue[${c}] ${h} implies a PegIn fee+anchor reserve of ${d} sat, expected exactly ${s} sat (minPeginFee ${i} + p2aAnchor ${r} for vaultCoreVersion ${t.vaultCoreVersion}, vaultKeepers=${t.vaultKeeperPubkeys.length}, universalChallengers=${t.universalChallengerPubkeys.length}, minPeginFeeRate=${t.minPeginFeeRate}).`
241
243
  );
242
244
  }
243
- return r;
245
+ return i;
244
246
  }
245
247
  class V extends Error {
246
248
  constructor(t) {
247
249
  super(t), this.name = "HtlcOutputMismatchError";
248
250
  }
249
251
  }
250
- function et(e, t, o) {
252
+ function tt(e, t, o) {
251
253
  if (e.length < t.length)
252
254
  throw new V(
253
255
  `Encoded Pre-PegIn tx has ${e.length} output(s), fewer than the ${t.length} HTLC output(s) the cross-check validated.`
254
256
  );
255
257
  for (let n = 0; n < t.length; n++) {
256
- const i = BigInt(e[n].value);
257
- if (i !== t[n])
258
+ const r = BigInt(e[n].value);
259
+ if (r !== t[n])
258
260
  throw new V(
259
- `Encoded Pre-PegIn HTLC output[${n}] value ${i} does not match the cross-checked htlcValue ${t[n]}; the funded/signed tx would not pay the validated amount.`
261
+ `Encoded Pre-PegIn HTLC output[${n}] value ${r} does not match the cross-checked htlcValue ${t[n]}; the funded/signed tx would not pay the validated amount.`
260
262
  );
261
- const s = e[n].script.toString("hex").toLowerCase(), r = o[n].toLowerCase();
262
- if (s !== r)
263
+ const i = e[n].script.toString("hex").toLowerCase(), s = o[n].toLowerCase();
264
+ if (i !== s)
263
265
  throw new V(
264
- `Encoded Pre-PegIn HTLC output[${n}] scriptPubKey ${s} does not match the cross-checked htlcScriptPubKey ${r}.`
266
+ `Encoded Pre-PegIn HTLC output[${n}] scriptPubKey ${i} does not match the cross-checked htlcScriptPubKey ${s}.`
265
267
  );
266
268
  }
267
269
  }
268
- function tt(e, t, o, n, i, s, r) {
269
- if (s !== X)
270
+ function ot(e, t, o, n, r, i, s) {
271
+ if (i !== X)
270
272
  throw new Error(
271
- `WASM Pre-PegIn transaction version ${s}; expected ${X}.`
273
+ `WASM Pre-PegIn transaction version ${i}; expected ${X}.`
272
274
  );
273
- if (r !== G)
275
+ if (s !== G)
274
276
  throw new Error(
275
- `WASM Pre-PegIn transaction locktime ${r}; expected ${G}.`
277
+ `WASM Pre-PegIn transaction locktime ${s}; expected ${G}.`
276
278
  );
277
279
  if (t.length < z)
278
280
  throw new Error(
279
281
  `WASM Pre-PegIn output layout has ${t.length} HTLC output(s); expected at least ${z}.`
280
282
  );
281
- const u = t.length, h = u + +(i !== void 0), l = Ke(
283
+ const u = t.length, c = u + +(r !== void 0), p = Ue(
282
284
  t.length,
283
- i !== void 0
285
+ r !== void 0
284
286
  );
285
- if (e.length !== l)
287
+ if (e.length !== p)
286
288
  throw new Error(
287
- `WASM Pre-PegIn output layout has ${e.length} output(s); expected exactly ${l}.`
289
+ `WASM Pre-PegIn output layout has ${e.length} output(s); expected exactly ${p}.`
288
290
  );
289
- et(e, t, o);
290
- for (let p = 0; p < t.length; p++) {
291
- const v = Ze(
291
+ tt(e, t, o);
292
+ for (let P = 0; P < t.length; P++) {
293
+ const E = je(
292
294
  n,
293
- n.hashlocks[p]
295
+ n.hashlocks[P]
294
296
  ).scriptPubKey;
295
- if (!e[p].script.equals(v))
297
+ if (!e[P].script.equals(E))
296
298
  throw new V(
297
- `Pre-PegIn HTLC output[${p}] does not match the independently derived scriptPubKey.`
299
+ `Pre-PegIn HTLC output[${P}] does not match the independently derived scriptPubKey.`
298
300
  );
299
301
  }
300
- if (i !== void 0) {
301
- const p = e[u];
302
- if (p.value !== Y)
302
+ if (r !== void 0) {
303
+ const P = e[u];
304
+ if (P.value !== Y)
303
305
  throw new Error(
304
- `WASM Pre-PegIn auth output[${u}] value ${p.value} sat; expected exactly ${Y} sat.`
306
+ `WASM Pre-PegIn auth output[${u}] value ${P.value} sat; expected exactly ${Y} sat.`
305
307
  );
306
- const v = p.script.toString("hex").toLowerCase(), w = Me + i.toLowerCase();
307
- if (v !== w)
308
+ const E = P.script.toString("hex").toLowerCase(), v = We + r.toLowerCase();
309
+ if (E !== v)
308
310
  throw new Error(
309
- `WASM Pre-PegIn auth output[${u}] scriptPubKey ${v}; expected ${w}.`
311
+ `WASM Pre-PegIn auth output[${u}] scriptPubKey ${E}; expected ${v}.`
310
312
  );
311
313
  }
312
- const d = e[h];
313
- if (d.value !== D)
314
+ const l = e[c];
315
+ if (l.value !== D)
314
316
  throw new Error(
315
- `WASM Pre-PegIn CPFP output[${h}] value ${d.value} sat; expected exactly ${D} sat.`
317
+ `WASM Pre-PegIn CPFP output[${c}] value ${l.value} sat; expected exactly ${D} sat.`
316
318
  );
317
- const a = d.script.toString("hex").toLowerCase(), P = f(
318
- $e(n.depositorPubkey)
319
+ const h = l.script.toString("hex").toLowerCase(), d = f(
320
+ xe(n.depositorPubkey)
319
321
  ).toLowerCase();
320
- if (a !== P)
322
+ if (h !== d)
321
323
  throw new Error(
322
- `WASM Pre-PegIn CPFP output[${h}] scriptPubKey ${a}; expected depositor BIP-86 script ${P}.`
324
+ `WASM Pre-PegIn CPFP output[${c}] scriptPubKey ${h}; expected depositor BIP-86 script ${d}.`
323
325
  );
324
326
  }
325
- const ot = 1;
326
- function nt(e) {
327
+ const nt = 1;
328
+ function rt(e) {
327
329
  const t = f(e);
328
330
  if (!/^[0-9a-fA-F]{64}$/.test(t))
329
331
  throw new Error(
330
332
  "Invalid depositor pubkey for the depositor-claim script: must be an x-only key of 64 hex characters (32 bytes)."
331
333
  );
332
334
  const o = x.compile([
333
- c.from(C(t)),
334
- E.OP_CHECKSIG
335
- ]), n = c.from(_), i = { output: o, redeemVersion: y }, { output: s, witness: r } = L.p2tr({
335
+ a.from(C(t)),
336
+ w.OP_CHECKSIG
337
+ ]), n = a.from(I), r = { output: o, redeemVersion: y }, { output: i, witness: s } = L.p2tr({
336
338
  internalPubkey: n,
337
339
  scriptTree: { output: o },
338
- redeem: i
340
+ redeem: r
339
341
  });
340
- if (!s)
342
+ if (!i)
341
343
  throw new Error(
342
344
  "Failed to derive the depositor-claim P2TR scriptPubKey for PegIn output validation"
343
345
  );
344
- const u = r == null ? void 0 : r[r.length - 1];
346
+ const u = s == null ? void 0 : s[s.length - 1];
345
347
  if (!u)
346
348
  throw new Error(
347
349
  "Failed to derive the depositor-claim tapleaf control block; refusing to build an unspendable input"
348
350
  );
349
- return { scriptPubKey: s, leafScript: o, controlBlock: u, internalKey: n };
351
+ return { scriptPubKey: i, leafScript: o, controlBlock: u, internalKey: n };
350
352
  }
351
- function rt(e) {
352
- return nt(e).scriptPubKey;
353
+ function it(e) {
354
+ return rt(e).scriptPubKey;
353
355
  }
354
- const se = 64, it = /^[0-9a-fA-F]+$/, ue = 65535;
356
+ const ae = 64, st = /^[0-9a-fA-F]+$/, le = 65535;
355
357
  async function Zt(e) {
356
- const t = be(e.authAnchorHash), o = await Te({
358
+ const t = Ie(e.authAnchorHash), o = await Le({
357
359
  txGraphVersion: e.vaultCoreVersion,
358
360
  depositorPubkey: e.depositorPubkey,
359
361
  vaultProviderPubkey: e.vaultProviderPubkey,
@@ -369,47 +371,47 @@ async function Zt(e) {
369
371
  councilSize: e.councilSize,
370
372
  network: e.network,
371
373
  authAnchorHash: t
372
- }), n = await Je(o, e), i = He(o.txHex);
373
- tt(
374
- i.outputs,
374
+ }), n = await et(o, e), r = Be(o.txHex);
375
+ ot(
376
+ r.outputs,
375
377
  o.htlcValues,
376
378
  o.htlcScriptPubKeys,
377
379
  e,
378
380
  t,
379
- i.version,
380
- i.locktime
381
+ r.version,
382
+ r.locktime
381
383
  );
382
- const s = i.outputs.reduce(
383
- (u, h) => u + BigInt(h.value),
384
+ const i = r.outputs.reduce(
385
+ (u, c) => u + BigInt(c.value),
384
386
  0n
385
- ), r = t !== void 0 ? o.htlcValues.length : null;
387
+ ), s = t !== void 0 ? o.htlcValues.length : null;
386
388
  return {
387
389
  psbtHex: o.txHex,
388
- totalOutputValue: s,
390
+ totalOutputValue: i,
389
391
  htlcValues: o.htlcValues,
390
392
  htlcScriptPubKeys: o.htlcScriptPubKeys,
391
393
  htlcAddresses: o.htlcAddresses,
392
394
  peginAmounts: o.peginAmounts,
393
395
  depositorClaimValue: o.depositorClaimValue,
394
- authAnchorVout: r,
396
+ authAnchorVout: s,
395
397
  minPeginFee: n
396
398
  };
397
399
  }
398
- function be(e) {
400
+ function Ie(e) {
399
401
  if (e === void 0) return;
400
402
  const t = e.startsWith("0x") || e.startsWith("0X") ? e.slice(2) : e;
401
- if (t.length !== se || !it.test(t))
403
+ if (t.length !== ae || !st.test(t))
402
404
  throw new Error(
403
- `authAnchorHash must be 32-byte hex (${se} chars, no 0x prefix); got length ${t.length}`
405
+ `authAnchorHash must be 32-byte hex (${ae} chars, no 0x prefix); got length ${t.length}`
404
406
  );
405
407
  return t.toLowerCase();
406
408
  }
407
409
  async function jt(e) {
408
- if (!Number.isInteger(e.timelockPegin) || e.timelockPegin < 1 || e.timelockPegin > ue)
410
+ if (!Number.isInteger(e.timelockPegin) || e.timelockPegin < 1 || e.timelockPegin > le)
409
411
  throw new Error(
410
- `PegIn timelock ${e.timelockPegin} must be a whole number of blocks from 1 to ${ue}.`
412
+ `PegIn timelock ${e.timelockPegin} must be a whole number of blocks from 1 to ${le}.`
411
413
  );
412
- const t = await Ae(
414
+ const t = await Ve(
413
415
  {
414
416
  txGraphVersion: e.prePeginParams.vaultCoreVersion,
415
417
  depositorPubkey: e.prePeginParams.depositorPubkey,
@@ -425,7 +427,7 @@ async function jt(e) {
425
427
  councilQuorum: e.prePeginParams.councilQuorum,
426
428
  councilSize: e.prePeginParams.councilSize,
427
429
  network: e.prePeginParams.network,
428
- authAnchorHash: be(
430
+ authAnchorHash: Ie(
429
431
  e.prePeginParams.authAnchorHash
430
432
  )
431
433
  },
@@ -440,100 +442,101 @@ async function jt(e) {
440
442
  vaultValue: t.vaultValue
441
443
  };
442
444
  }
443
- const st = 2;
444
445
  async function ut(e, t) {
445
- const o = t.prePeginParams.vaultCoreVersion, n = o === 1 ? Fe : o === 2 || o === 3 ? qe : void 0;
446
- if (n === void 0)
447
- throw new Error(`Unsupported vaultCoreVersion ${o} for PegIn tx.`);
448
- await Oe(o, e.txHex);
449
- const i = await me(o), s = st + (i ? 1 : 0), r = k.fromHex(f(e.txHex));
450
- if (r.version !== n)
446
+ const o = t.prePeginParams.vaultCoreVersion;
447
+ if (o !== Q)
448
+ throw new Error(
449
+ `Unsupported vaultCoreVersion ${o} for PegIn tx; only ${Q} has a PegIn shape.`
450
+ );
451
+ await Re(o, e.txHex);
452
+ const n = k.fromHex(f(e.txHex));
453
+ if (n.version !== Z)
451
454
  throw new Error(
452
- `PegIn tx version ${r.version} does not match vaultCoreVersion ${o}; expected ${n}.`
455
+ `PegIn tx version ${n.version} does not match vaultCoreVersion ${o}; expected ${Z}.`
453
456
  );
454
- if (r.locktime !== Q)
457
+ if (n.locktime !== j)
455
458
  throw new Error(
456
- `PegIn tx locktime ${r.locktime} does not match the canonical locktime ${Q}.`
459
+ `PegIn tx locktime ${n.locktime} does not match the canonical locktime ${j}.`
457
460
  );
458
- if (r.ins.length !== 1)
461
+ if (n.ins.length !== 1)
459
462
  throw new Error(
460
- `PegIn tx has ${r.ins.length} input(s), expected exactly 1 (the Pre-PegIn HTLC outpoint).`
463
+ `PegIn tx has ${n.ins.length} input(s), expected exactly 1 (the Pre-PegIn HTLC outpoint).`
461
464
  );
462
- const u = k.fromHex(
465
+ const r = k.fromHex(
463
466
  f(t.fundedPrePeginTxHex)
464
- ).getId(), h = M(
465
- new Uint8Array(r.ins[0].hash).slice().reverse()
467
+ ).getId(), i = M(
468
+ new Uint8Array(n.ins[0].hash).slice().reverse()
466
469
  );
467
- if (h !== u)
470
+ if (i !== r)
468
471
  throw new Error(
469
- `PegIn input spends txid ${h}, expected the funded Pre-PegIn ${u}.`
472
+ `PegIn input spends txid ${i}, expected the funded Pre-PegIn ${r}.`
470
473
  );
471
- if (r.ins[0].index !== t.htlcVout)
474
+ if (n.ins[0].index !== t.htlcVout)
472
475
  throw new Error(
473
- `PegIn input spends Pre-PegIn output ${r.ins[0].index}, expected the requested HTLC vout ${t.htlcVout}.`
476
+ `PegIn input spends Pre-PegIn output ${n.ins[0].index}, expected the requested HTLC vout ${t.htlcVout}.`
474
477
  );
475
- if (r.ins[0].sequence !== Z)
478
+ if (n.ins[0].sequence !== J)
476
479
  throw new Error(
477
- `PegIn input sequence ${r.ins[0].sequence} does not match the canonical sequence ${Z}.`
480
+ `PegIn input sequence ${n.ins[0].sequence} does not match the canonical sequence ${J}.`
478
481
  );
479
- if (r.ins[0].script.length !== 0)
482
+ if (n.ins[0].script.length !== 0)
480
483
  throw new Error("PegIn input scriptSig must be empty.");
481
- if (r.ins[0].witness.length !== 0)
484
+ if (n.ins[0].witness.length !== 0)
482
485
  throw new Error("PegIn input witness must be empty before signing.");
483
- if (r.outs.length !== s)
486
+ if (n.outs.length !== ee)
484
487
  throw new Error(
485
- `PegIn tx has ${r.outs.length} output(s), expected exactly ${s} for vaultCoreVersion ${o} (vault + depositor claim${i ? " + P2A anchor" : ""}).`
488
+ `PegIn tx has ${n.outs.length} output(s), expected exactly ${ee} for vaultCoreVersion ${o} (vault + depositor claim + P2A anchor).`
486
489
  );
487
- const l = t.prePeginParams.pegInAmounts[t.htlcVout];
488
- if (e.vaultValue !== l)
490
+ const s = t.prePeginParams.pegInAmounts[t.htlcVout];
491
+ if (e.vaultValue !== s)
489
492
  throw new Error(
490
- `PegIn vault output value ${e.vaultValue} does not match the requested peg-in amount ${l} for HTLC ${t.htlcVout}; refusing to sign a vault that locks a different amount than requested.`
493
+ `PegIn vault output value ${e.vaultValue} does not match the requested peg-in amount ${s} for HTLC ${t.htlcVout}; refusing to sign a vault that locks a different amount than requested.`
491
494
  );
492
- const d = r.outs[0];
493
- if (BigInt(d.value) !== e.vaultValue)
495
+ const u = n.outs[0];
496
+ if (BigInt(u.value) !== e.vaultValue)
494
497
  throw new Error(
495
- `Encoded PegIn vault output value ${d.value} does not match the WASM-reported vaultValue ${e.vaultValue}.`
498
+ `Encoded PegIn vault output value ${u.value} does not match the WASM-reported vaultValue ${e.vaultValue}.`
496
499
  );
497
- const a = je(
500
+ const c = Je(
498
501
  t.prePeginParams,
499
502
  t.timelockPegin
500
503
  ).toString("hex");
501
- if (f(e.vaultScriptPubKey).toLowerCase() !== a)
504
+ if (f(e.vaultScriptPubKey).toLowerCase() !== c)
502
505
  throw new Error(
503
- `WASM-reported PegIn vaultScriptPubKey ${e.vaultScriptPubKey} does not match the independently derived payout scriptPubKey ${a}.`
506
+ `WASM-reported PegIn vaultScriptPubKey ${e.vaultScriptPubKey} does not match the independently derived payout scriptPubKey ${c}.`
504
507
  );
505
- const P = d.script.toString("hex");
506
- if (P !== a)
508
+ const p = u.script.toString("hex");
509
+ if (p !== c)
507
510
  throw new Error(
508
- `Encoded PegIn vault output scriptPubKey ${P} does not match the independently derived payout scriptPubKey ${a}.`
511
+ `Encoded PegIn vault output scriptPubKey ${p} does not match the independently derived payout scriptPubKey ${c}.`
509
512
  );
510
- const p = r.getId();
511
- if (p !== f(e.txid).toLowerCase())
513
+ const l = n.getId();
514
+ if (l !== f(e.txid).toLowerCase())
512
515
  throw new Error(
513
- `Encoded PegIn txid ${p} does not match the WASM-reported txid ${e.txid}.`
516
+ `Encoded PegIn txid ${l} does not match the WASM-reported txid ${e.txid}.`
514
517
  );
515
- const v = await ye(
518
+ const h = await Se(
516
519
  o,
517
520
  t.prePeginParams.numLocalChallengers,
518
521
  t.prePeginParams.universalChallengerPubkeys.length,
519
522
  t.prePeginParams.councilQuorum,
520
523
  t.prePeginParams.councilSize,
521
524
  t.prePeginParams.feeRate
522
- ), w = r.outs[ot];
523
- if (BigInt(w.value) !== v)
525
+ ), d = n.outs[nt];
526
+ if (BigInt(d.value) !== h)
524
527
  throw new Error(
525
- `Encoded PegIn depositor-claim output value ${w.value} does not match the independently computed claim value ${v} for vaultCoreVersion ${o}.`
528
+ `Encoded PegIn depositor-claim output value ${d.value} does not match the independently computed claim value ${h} for vaultCoreVersion ${o}.`
526
529
  );
527
- const g = rt(
530
+ const P = it(
528
531
  t.prePeginParams.depositorPubkey
529
532
  );
530
- if (!w.script.equals(g))
533
+ if (!d.script.equals(P))
531
534
  throw new Error(
532
- `Encoded PegIn depositor-claim output scriptPubKey ${w.script.toString("hex")} does not pay to the depositor's claim script (expected ${g.toString("hex")}).`
535
+ `Encoded PegIn depositor-claim output scriptPubKey ${d.script.toString("hex")} does not pay to the depositor's claim script (expected ${P.toString("hex")}).`
533
536
  );
534
537
  }
535
538
  async function ct(e) {
536
- const t = await Ve(
539
+ const t = await Ke(
537
540
  {
538
541
  txGraphVersion: e.vaultCoreVersion,
539
542
  depositor: e.depositor,
@@ -552,77 +555,77 @@ async function ct(e) {
552
555
  payoutControlBlock: t.payoutControlBlock
553
556
  };
554
557
  }
555
- const ce = 253, at = 254, lt = 65535, ht = 4294967295, dt = "TapLeaf", pt = "TapBranch", Pt = "TapTweak", T = 33, O = 32, ae = 128, ft = 1, gt = 254, wt = c.from([81, 32]);
558
+ const he = 253, at = 254, lt = 65535, ht = 4294967295, dt = "TapLeaf", pt = "TapBranch", Pt = "TapTweak", T = 33, O = 32, de = 128, ft = 1, gt = 254, wt = a.from([81, 32]);
556
559
  function vt(e) {
557
- if (e < ce)
558
- return c.from([e]);
560
+ if (e < he)
561
+ return a.from([e]);
559
562
  if (e <= lt) {
560
- const t = c.alloc(2);
561
- return t.writeUInt16LE(e), c.concat([c.from([ce]), t]);
563
+ const t = a.alloc(2);
564
+ return t.writeUInt16LE(e), a.concat([a.from([he]), t]);
562
565
  }
563
566
  if (e <= ht) {
564
- const t = c.alloc(4);
565
- return t.writeUInt32LE(e), c.concat([c.from([at]), t]);
567
+ const t = a.alloc(4);
568
+ return t.writeUInt32LE(e), a.concat([a.from([at]), t]);
566
569
  }
567
570
  throw new Error(`Script too large to encode as CompactSize: ${e} bytes`);
568
571
  }
569
- function ke(e, t) {
570
- const o = c.concat([
571
- c.from([e]),
572
+ function _e(e, t) {
573
+ const o = a.concat([
574
+ a.from([e]),
572
575
  vt(t.length),
573
- c.from(t)
576
+ a.from(t)
574
577
  ]);
575
578
  return U.taggedHash(dt, o);
576
579
  }
577
580
  function Et(e) {
578
- const { leafVersion: t, script: o, controlBlock: n } = e, i = n.length - T;
579
- if (i < 0 || i % O !== 0 || i / O > ae)
581
+ const { leafVersion: t, script: o, controlBlock: n } = e, r = n.length - T;
582
+ if (r < 0 || r % O !== 0 || r / O > de)
580
583
  throw new Error(
581
- `Malformed Taproot control block: length ${n.length} must be ${T} + 32*m with 0 <= m <= ${ae}`
584
+ `Malformed Taproot control block: length ${n.length} must be ${T} + 32*m with 0 <= m <= ${de}`
582
585
  );
583
- const s = n[0] & gt;
584
- if (s !== t)
586
+ const i = n[0] & gt;
587
+ if (i !== t)
585
588
  throw new Error(
586
- `Taproot control block leaf version 0x${s.toString(16)} does not match the tapLeafScript leaf version 0x${t.toString(16)}`
589
+ `Taproot control block leaf version 0x${i.toString(16)} does not match the tapLeafScript leaf version 0x${t.toString(16)}`
587
590
  );
588
- const r = c.from(
591
+ const s = a.from(
589
592
  n.subarray(1, T)
590
593
  );
591
- let u = ke(t, o);
592
- for (let a = T; a < n.length; a += O) {
593
- const P = c.from(
594
- n.subarray(a, a + O)
594
+ let u = _e(t, o);
595
+ for (let h = T; h < n.length; h += O) {
596
+ const d = a.from(
597
+ n.subarray(h, h + O)
595
598
  );
596
599
  u = U.taggedHash(
597
600
  pt,
598
- c.compare(u, P) <= 0 ? c.concat([u, P]) : c.concat([P, u])
601
+ a.compare(u, d) <= 0 ? a.concat([u, d]) : a.concat([d, u])
599
602
  );
600
603
  }
601
- const h = U.taggedHash(
604
+ const c = U.taggedHash(
602
605
  Pt,
603
- c.concat([r, u])
604
- ), l = Ce.xOnlyPointAddTweak(r, h);
605
- if (l === null)
606
+ a.concat([s, u])
607
+ ), p = ke.xOnlyPointAddTweak(s, c);
608
+ if (p === null)
606
609
  throw new Error(
607
610
  "Taproot control block does not yield a valid output key (tweak is off-curve)"
608
611
  );
609
- const d = n[0] & ft;
610
- if (l.parity !== d)
612
+ const l = n[0] & ft;
613
+ if (p.parity !== l)
611
614
  throw new Error(
612
- `Taproot output key parity ${l.parity} contradicts the control block's parity bit ${d}`
615
+ `Taproot output key parity ${p.parity} contradicts the control block's parity bit ${l}`
613
616
  );
614
- return c.concat([
617
+ return a.concat([
615
618
  wt,
616
- c.from(l.xOnlyPubkey)
619
+ a.from(p.xOnlyPubkey)
617
620
  ]);
618
621
  }
619
- const yt = 256, mt = 1500, le = 256, he = 0xffffffffn, $t = 500, St = 55, xt = 34;
622
+ const yt = 256, mt = 1500, pe = 256, Pe = 0xffffffffn, $t = 500, St = 55, xt = 34;
620
623
  function Ct(e) {
621
- if (typeof e.protocolFeeRate != "bigint" || e.protocolFeeRate <= 0n || e.protocolFeeRate > he)
624
+ if (typeof e.protocolFeeRate != "bigint" || e.protocolFeeRate <= 0n || e.protocolFeeRate > Pe)
622
625
  throw new Error(
623
- `protocolFeeRate must be in [1, ${he}] sat/vB, got ${e.protocolFeeRate}`
626
+ `protocolFeeRate must be in [1, ${Pe}] sat/vB, got ${e.protocolFeeRate}`
624
627
  );
625
- for (const [t, o, n, i] of [
628
+ for (const [t, o, n, r] of [
626
629
  [
627
630
  "keepers",
628
631
  e.numVaultKeepers,
@@ -638,43 +641,43 @@ function Ct(e) {
638
641
  ])
639
642
  if (!Number.isInteger(o) || o < 1 || o > n)
640
643
  throw new Error(
641
- `Participant count for ${t} (${o}) is outside the supported range [1, ${n}]${o > n ? ` (${i})` : ""}.`
644
+ `Participant count for ${t} (${o}) is outside the supported range [1, ${n}]${o > n ? ` (${r})` : ""}.`
642
645
  );
643
- if (!Number.isInteger(e.councilSize) || e.councilSize < 1 || e.councilSize > le)
646
+ if (!Number.isInteger(e.councilSize) || e.councilSize < 1 || e.councilSize > pe)
644
647
  throw new Error(
645
- `councilSize must be an integer in [1, ${le}], got ${e.councilSize}`
648
+ `councilSize must be an integer in [1, ${pe}], got ${e.councilSize}`
646
649
  );
647
650
  }
648
651
  async function bt(e, t) {
649
- const { implicitFeeSats: o, out0Len: n, out1Len: i } = t, s = e.numVaultKeepers + e.numUniversalChallengers, r = BigInt(o), u = Math.max(0, n - xt), h = $t + St * s + u, l = e.protocolFeeRate * BigInt(h);
650
- if (r > l)
652
+ const { implicitFeeSats: o, out0Len: n, out1Len: r } = t, i = e.numVaultKeepers + e.numUniversalChallengers, s = BigInt(o), u = Math.max(0, n - xt), c = $t + St * i + u, p = e.protocolFeeRate * BigInt(c);
653
+ if (s > p)
651
654
  throw new Error(
652
- `Payout implicit fee ${o} sats exceeds the safety cap of ${l} sats (${e.protocolFeeRate} sat/vB x ${h} vB for ${s} participants); refusing to sign payout.`
655
+ `Payout implicit fee ${o} sats exceeds the safety cap of ${p} sats (${e.protocolFeeRate} sat/vB x ${c} vB for ${i} participants); refusing to sign payout.`
653
656
  );
654
- const d = await Le(
657
+ const l = await He(
655
658
  e.vaultCoreVersion,
656
659
  e.numVaultKeepers,
657
660
  e.numUniversalChallengers,
658
661
  e.numVaultKeepers,
659
662
  e.councilSize,
660
663
  n,
661
- i,
664
+ r,
662
665
  e.protocolFeeRate
663
666
  );
664
- if (r < d)
667
+ if (s < l)
665
668
  throw new Error(
666
- `Payout implicit fee ${o} sats is below the floor of ${d} sats (the smallest fee any known vault-provider build produces for this shape); refusing to sign payout.`
669
+ `Payout implicit fee ${o} sats is below the floor of ${l} sats (the smallest fee any known vault-provider build produces for this shape); refusing to sign payout.`
667
670
  );
668
671
  }
669
- const kt = 22, _t = 34, It = 34, At = 25, Tt = 23;
672
+ const kt = 22, It = 34, _t = 34, At = 25, Tt = 23;
670
673
  function Ot(e) {
671
674
  return e.length === kt * 2 && e.startsWith("0014");
672
675
  }
673
676
  function Vt(e) {
674
- return e.length === _t * 2 && e.startsWith("0020");
677
+ return e.length === It * 2 && e.startsWith("0020");
675
678
  }
676
679
  function Lt(e) {
677
- return e.length === It * 2 && e.startsWith("5120");
680
+ return e.length === _t * 2 && e.startsWith("5120");
678
681
  }
679
682
  function Rt(e) {
680
683
  return e.length === At * 2 && e.startsWith("76a914") && e.endsWith("88ac");
@@ -682,7 +685,7 @@ function Rt(e) {
682
685
  function Kt(e) {
683
686
  return e.length === Tt * 2 && e.startsWith("a914") && e.endsWith("87");
684
687
  }
685
- function de(e, t) {
688
+ function fe(e, t) {
686
689
  const o = f(e).toLowerCase();
687
690
  if (o.length === 0)
688
691
  throw new Error(`${t} is empty`);
@@ -697,7 +700,7 @@ function de(e, t) {
697
700
  `${t} is not a standard scriptPubKey (expected P2TR, P2WPKH, P2WSH, P2PKH, or P2SH; got ${o.length / 2} bytes: ${o})`
698
701
  );
699
702
  }
700
- const pe = 3;
703
+ const ge = 3;
701
704
  async function Jt(e) {
702
705
  const t = {
703
706
  vaultCoreVersion: e.vaultCoreVersion,
@@ -707,59 +710,59 @@ async function Jt(e) {
707
710
  protocolFeeRate: e.protocolFeeRate
708
711
  };
709
712
  Ct(t);
710
- const o = k.fromHex(f(e.payoutTxHex)), n = k.fromHex(f(e.peginTxHex)), i = k.fromHex(f(e.assertTxHex));
711
- if (o.ins.length !== j)
713
+ const o = k.fromHex(f(e.payoutTxHex)), n = k.fromHex(f(e.peginTxHex)), r = k.fromHex(f(e.assertTxHex));
714
+ if (o.ins.length !== te)
712
715
  throw new Error(
713
- `Payout transaction must have exactly ${j} inputs, got ${o.ins.length}`
716
+ `Payout transaction must have exactly ${te} inputs, got ${o.ins.length}`
714
717
  );
715
- if (o.version !== J)
718
+ if (o.version !== oe)
716
719
  throw new Error(
717
- `Payout transaction version ${o.version} must be ${J}; refusing to sign payout.`
720
+ `Payout transaction version ${o.version} must be ${oe}; refusing to sign payout.`
718
721
  );
719
- if (o.locktime !== ee)
722
+ if (o.locktime !== ne)
720
723
  throw new Error(
721
- `Payout transaction locktime ${o.locktime} must be ${ee}; refusing to sign payout.`
724
+ `Payout transaction locktime ${o.locktime} must be ${ne}; refusing to sign payout.`
722
725
  );
723
- const s = Pe(
726
+ const i = we(
724
727
  o.ins[0],
725
728
  0,
726
729
  n,
727
730
  "PegIn",
728
- We
731
+ Xe
729
732
  );
730
733
  if (o.ins[0].sequence !== e.timelockPegin)
731
734
  throw new Error(
732
735
  `Payout input 0 sequence ${o.ins[0].sequence} must equal the PegIn CSV timelock ${e.timelockPegin}; refusing to sign payout.`
733
736
  );
734
- const r = Pe(
737
+ const s = we(
735
738
  o.ins[1],
736
739
  1,
737
- i,
740
+ r,
738
741
  "Assert",
739
- xe
742
+ be
740
743
  );
741
744
  if (o.ins[1].sequence !== e.timelockAssert)
742
745
  throw new Error(
743
746
  `Payout input 1 sequence ${o.ins[1].sequence} must equal the Assert CSV timelock ${e.timelockAssert}; refusing to sign payout.`
744
747
  );
745
- const { out0Len: u, out1Len: h } = Ut(
748
+ const { out0Len: u, out1Len: c } = Ut(
746
749
  o,
747
- s.value,
750
+ i.value,
748
751
  e
749
- ), l = s.value + r.value;
750
- let d = 0;
751
- for (const v of o.outs) d += v.value;
752
- if (d > l)
752
+ ), p = i.value + s.value;
753
+ let l = 0;
754
+ for (const E of o.outs) l += E.value;
755
+ if (l > p)
753
756
  throw new Error(
754
- `Payout outputs (${d} sats) exceed inputs (${l} sats); invalid transaction.`
757
+ `Payout outputs (${l} sats) exceed inputs (${p} sats); invalid transaction.`
755
758
  );
756
- const a = l - d;
759
+ const h = p - l;
757
760
  await bt(t, {
758
- implicitFeeSats: a,
761
+ implicitFeeSats: h,
759
762
  out0Len: u,
760
- out1Len: h
763
+ out1Len: c
761
764
  });
762
- const P = await ct({
765
+ const d = await ct({
763
766
  vaultCoreVersion: e.vaultCoreVersion,
764
767
  depositor: e.depositorBtcPubkey,
765
768
  vaultProvider: e.vaultProviderBtcPubkey,
@@ -767,22 +770,22 @@ async function Jt(e) {
767
770
  universalChallengers: e.universalChallengerBtcPubkeys,
768
771
  timelockPegin: e.timelockPegin,
769
772
  network: e.network
770
- }), p = await Ht(e, r);
773
+ }), P = await Ht(e, s);
771
774
  return {
772
775
  psbtHex: Nt(
773
776
  o,
777
+ i,
774
778
  s,
775
- r,
776
- P,
777
- p
779
+ d,
780
+ P
778
781
  )
779
782
  };
780
783
  }
781
784
  async function Ht(e, t) {
782
- const { payoutScript: o, payoutControlBlock: n } = await Re({
785
+ const { payoutScript: o, payoutControlBlock: n } = await Ne({
783
786
  txGraphVersion: e.vaultCoreVersion,
784
787
  claimer: f(e.claimerBtcPubkey).toLowerCase(),
785
- localChallengers: ze({
788
+ localChallengers: Ye({
786
789
  claimerBtcPubkey: e.claimerBtcPubkey,
787
790
  depositorBtcPubkey: e.depositorBtcPubkey,
788
791
  vaultProviderBtcPubkey: e.vaultProviderBtcPubkey,
@@ -796,40 +799,40 @@ async function Ht(e, t) {
796
799
  (u) => f(u).toLowerCase()
797
800
  ),
798
801
  councilQuorum: e.councilQuorum
799
- }), i = C(o), s = C(n), r = Et({
802
+ }), r = C(o), i = C(n), s = Et({
800
803
  leafVersion: y,
801
- script: i,
802
- controlBlock: s
804
+ script: r,
805
+ controlBlock: i
803
806
  });
804
- if (!t.script.equals(r))
807
+ if (!t.script.equals(s))
805
808
  throw new Error(
806
- `Rebuilt Assert:0 payout leaf does not spend the Assert output being referenced: leaf binds to ${r.toString("hex")}, Assert:${xe} pays ${t.script.toString("hex")}; refusing to sign payout.`
809
+ `Rebuilt Assert:0 payout leaf does not spend the Assert output being referenced: leaf binds to ${s.toString("hex")}, Assert:${be} pays ${t.script.toString("hex")}; refusing to sign payout.`
807
810
  );
808
- return { script: i, controlBlock: s };
811
+ return { script: r, controlBlock: i };
809
812
  }
810
- function Pe(e, t, o, n, i) {
811
- const s = M(
813
+ function we(e, t, o, n, r) {
814
+ const i = M(
812
815
  new Uint8Array(e.hash).slice().reverse()
813
- ), r = o.getId();
814
- if (s !== r || e.index !== i)
816
+ ), s = o.getId();
817
+ if (i !== s || e.index !== r)
815
818
  throw new Error(
816
- `Input ${t} must spend ${n}:${i}. Expected ${r}:${i}, got ${s}:${e.index}`
819
+ `Input ${t} must spend ${n}:${r}. Expected ${s}:${r}, got ${i}:${e.index}`
817
820
  );
818
821
  const u = o.outs[e.index];
819
822
  if (!u)
820
823
  throw new Error(
821
- `Previous output not found for input ${t} (txid: ${s}, index: ${e.index})`
824
+ `Previous output not found for input ${t} (txid: ${i}, index: ${e.index})`
822
825
  );
823
826
  return u;
824
827
  }
825
- function Nt(e, t, o, n, i) {
826
- const s = new H();
827
- s.setVersion(e.version), s.setLocktime(e.locktime);
828
- const [r, u] = e.ins;
829
- s.addInput({
830
- hash: r.hash,
831
- index: r.index,
832
- sequence: r.sequence,
828
+ function Nt(e, t, o, n, r) {
829
+ const i = new H();
830
+ i.setVersion(e.version), i.setLocktime(e.locktime);
831
+ const [s, u] = e.ins;
832
+ i.addInput({
833
+ hash: s.hash,
834
+ index: s.index,
835
+ sequence: s.sequence,
833
836
  witnessUtxo: {
834
837
  script: t.script,
835
838
  value: t.value
@@ -837,15 +840,15 @@ function Nt(e, t, o, n, i) {
837
840
  tapLeafScript: [
838
841
  {
839
842
  leafVersion: y,
840
- script: c.from(C(n.payoutScript)),
841
- controlBlock: c.from(
843
+ script: a.from(C(n.payoutScript)),
844
+ controlBlock: a.from(
842
845
  C(n.payoutControlBlock)
843
846
  )
844
847
  }
845
848
  ],
846
- tapInternalKey: c.from(_)
849
+ tapInternalKey: a.from(I)
847
850
  // sighashType omitted - defaults to SIGHASH_DEFAULT (0x00) for Taproot
848
- }), s.addInput({
851
+ }), i.addInput({
849
852
  hash: u.hash,
850
853
  index: u.index,
851
854
  sequence: u.sequence,
@@ -856,109 +859,109 @@ function Nt(e, t, o, n, i) {
856
859
  tapLeafScript: [
857
860
  {
858
861
  leafVersion: y,
859
- script: c.from(i.script),
860
- controlBlock: c.from(i.controlBlock)
862
+ script: a.from(r.script),
863
+ controlBlock: a.from(r.controlBlock)
861
864
  }
862
865
  ],
863
- tapInternalKey: c.from(_)
866
+ tapInternalKey: a.from(I)
864
867
  });
865
- for (const h of e.outs)
866
- s.addOutput({
867
- script: h.script,
868
- value: h.value
868
+ for (const c of e.outs)
869
+ i.addOutput({
870
+ script: c.script,
871
+ value: c.value
869
872
  });
870
- return s.toHex();
873
+ return i.toHex();
871
874
  }
872
- function fe(e, t) {
875
+ function ve(e, t) {
873
876
  const o = f(e).toLowerCase(), n = f(
874
- $e(t)
877
+ xe(t)
875
878
  ).toLowerCase();
876
879
  return o === n ? [o] : [o, n];
877
880
  }
878
- function ge(e, t) {
879
- return t.some((o) => e.equals(c.from(o, "hex")));
881
+ function Ee(e, t) {
882
+ return t.some((o) => e.equals(a.from(o, "hex")));
880
883
  }
881
884
  function Ut(e, t, o) {
882
885
  const {
883
886
  claimerBtcPubkey: n,
884
- vaultProviderBtcPubkey: i,
885
- depositorBtcPubkey: s,
886
- vaultKeeperBtcPubkeys: r,
887
+ vaultProviderBtcPubkey: r,
888
+ depositorBtcPubkey: i,
889
+ vaultKeeperBtcPubkeys: s,
887
890
  registeredPayoutScriptPubKey: u,
888
- commissionBps: h,
889
- vkClaimerPayoutScriptPubKeys: l,
890
- vpCommissionScriptPubKey: d
891
+ commissionBps: c,
892
+ vkClaimerPayoutScriptPubKeys: p,
893
+ vpCommissionScriptPubKey: l
891
894
  } = o;
892
- if (!Ue(u))
895
+ if (!Fe(u))
893
896
  throw new Error("Invalid registeredPayoutScriptPubKey: not valid hex");
894
- const a = f(n).toLowerCase(), P = f(i).toLowerCase(), p = f(s).toLowerCase(), v = r.map(
897
+ const h = f(n).toLowerCase(), d = f(r).toLowerCase(), P = f(i).toLowerCase(), E = s.map(
895
898
  (S) => f(S).toLowerCase()
896
899
  );
897
- let w, g, m;
898
- if (a === P)
899
- w = "vp-claimer", g = Ge, m = [f(u)];
900
- else if (a === p)
901
- w = "depositor-as-claimer", g = re, m = [f(u)];
902
- else if (v.includes(a)) {
903
- w = "vk-claimer", g = re;
904
- const S = l[a];
900
+ let v, g, m;
901
+ if (h === d)
902
+ v = "vp-claimer", g = ze, m = [f(u)];
903
+ else if (h === P)
904
+ v = "depositor-as-claimer", g = ue, m = [f(u)];
905
+ else if (E.includes(h)) {
906
+ v = "vk-claimer", g = ue;
907
+ const S = p[h];
905
908
  if (S === void 0)
906
909
  throw new Error(
907
- `No registered payout script resolved for vault keeper claimer ${a}`
910
+ `No registered payout script resolved for vault keeper claimer ${h}`
908
911
  );
909
- de(
912
+ fe(
910
913
  S,
911
- `Vault keeper payout script for claimer ${a}`
912
- ), m = fe(S, a);
914
+ `Vault keeper payout script for claimer ${h}`
915
+ ), m = ve(S, h);
913
916
  } else
914
917
  throw new Error(
915
- `Unknown claimer pubkey ${a}: not VP, depositor, or a registered vault keeper`
918
+ `Unknown claimer pubkey ${h}: not VP, depositor, or a registered vault keeper`
916
919
  );
917
920
  if (e.outs.length !== g)
918
921
  throw new Error(
919
- `Payout transaction has ${e.outs.length} output(s), expected exactly ${g} for role ${w}.`
922
+ `Payout transaction has ${e.outs.length} output(s), expected exactly ${g} for role ${v}.`
920
923
  );
921
- if (!ge(e.outs[0].script, m))
924
+ if (!Ee(e.outs[0].script, m))
922
925
  throw new Error(
923
- `Payout transaction output 0 does not pay the expected scriptPubKey for role ${w}. Accepted: ${m.join(" or ")}; got ${e.outs[0].script.toString("hex")}`
926
+ `Payout transaction output 0 does not pay the expected scriptPubKey for role ${v}. Accepted: ${m.join(" or ")}; got ${e.outs[0].script.toString("hex")}`
924
927
  );
925
928
  const N = g - 1;
926
- if (e.outs[N].value !== te)
929
+ if (e.outs[N].value !== re)
927
930
  throw new Error(
928
- `Payout CPFP anchor (out ${N}) value ${e.outs[N].value} sats must equal ${te} sats`
931
+ `Payout CPFP anchor (out ${N}) value ${e.outs[N].value} sats must equal ${re} sats`
929
932
  );
930
- if (w === "vp-claimer") {
931
- de(
932
- d,
933
+ if (v === "vp-claimer") {
934
+ fe(
935
+ l,
933
936
  "Vault provider commission payout script"
934
937
  );
935
- const S = fe(
936
- d,
937
- P
938
+ const S = ve(
939
+ l,
940
+ d
938
941
  );
939
- if (!ge(e.outs[1].script, S))
942
+ if (!Ee(e.outs[1].script, S))
940
943
  throw new Error(
941
944
  `Payout transaction output 1 does not pay the vault provider's commission scriptPubKey. Accepted: ${S.join(" or ")}; got ${e.outs[1].script.toString("hex")}`
942
945
  );
943
- if (!Number.isInteger(h) || h < 0 || h >= oe)
946
+ if (!Number.isInteger(c) || c < 0 || c >= ie)
944
947
  throw new Error(
945
- `commissionBps must be an integer in [0, ${oe}), got ${h}`
948
+ `commissionBps must be an integer in [0, ${ie}), got ${c}`
946
949
  );
947
950
  const F = Math.floor(
948
- t * h / Xe
951
+ t * c / Ge
949
952
  );
950
953
  if (e.outs[1].value > F)
951
954
  throw new Error(
952
- `Payout VP commission (out 1) value ${e.outs[1].value} sats exceeds cap ${F} sats (${h} bps of peginValue=${t})`
955
+ `Payout VP commission (out 1) value ${e.outs[1].value} sats exceeds cap ${F} sats (${c} bps of peginValue=${t})`
953
956
  );
954
957
  }
955
958
  const A = e.outs[0].script.length;
956
- if (A === 0 || A > ne)
959
+ if (A === 0 || A > se)
957
960
  throw new Error(
958
- `Payout receiver scriptPubKey length ${A} is outside the contract's registration cap [1, ${ne}]; refusing to sign payout.`
961
+ `Payout receiver scriptPubKey length ${A} is outside the contract's registration cap [1, ${se}]; refusing to sign payout.`
959
962
  );
960
- const _e = w === "vp-claimer" ? e.outs[1].script.length : void 0;
961
- return { out0Len: A, out1Len: _e };
963
+ const Ae = v === "vp-claimer" ? e.outs[1].script.length : void 0;
964
+ return { out0Len: A, out1Len: Ae };
962
965
  }
963
966
  function eo(e, t, o = 0) {
964
967
  const n = H.fromHex(e);
@@ -966,29 +969,29 @@ function eo(e, t, o = 0) {
966
969
  throw new Error(
967
970
  `Input index ${o} out of range (${n.data.inputs.length} inputs)`
968
971
  );
969
- const i = n.data.inputs[o];
970
- if (i.tapScriptSig && i.tapScriptSig.length > 0) {
971
- const s = C(t);
972
- for (const r of i.tapScriptSig)
973
- if (r.pubkey.equals(c.from(s)))
974
- return we(r.signature, o);
972
+ const r = n.data.inputs[o];
973
+ if (r.tapScriptSig && r.tapScriptSig.length > 0) {
974
+ const i = C(t);
975
+ for (const s of r.tapScriptSig)
976
+ if (s.pubkey.equals(a.from(i)))
977
+ return ye(s.signature, o);
975
978
  throw new Error(
976
979
  `No signature found for depositor pubkey: ${t} at input ${o}`
977
980
  );
978
981
  }
979
- if (i.finalScriptWitness && i.finalScriptWitness.length > 0) {
980
- const s = Bt(i.finalScriptWitness);
981
- if (s.length !== pe)
982
+ if (r.finalScriptWitness && r.finalScriptWitness.length > 0) {
983
+ const i = Bt(r.finalScriptWitness);
984
+ if (i.length !== ge)
982
985
  throw new Error(
983
- `Unexpected finalized witness stack size at input ${o}: expected ${pe} items (signature, script, controlBlock), got ${s.length}`
986
+ `Unexpected finalized witness stack size at input ${o}: expected ${ge} items (signature, script, controlBlock), got ${i.length}`
984
987
  );
985
- return we(s[0], o);
988
+ return ye(i[0], o);
986
989
  }
987
990
  throw new Error(
988
991
  `No tapScriptSig or finalScriptWitness found in signed PSBT at input ${o}`
989
992
  );
990
993
  }
991
- function we(e, t) {
994
+ function ye(e, t) {
992
995
  if (e.length === 64)
993
996
  return M(new Uint8Array(e));
994
997
  throw e.length === 65 ? new Error(
@@ -1000,21 +1003,21 @@ function we(e, t) {
1000
1003
  function Bt(e) {
1001
1004
  const t = [];
1002
1005
  let o = 0;
1003
- const n = (r) => {
1004
- if (o + r > e.length)
1006
+ const n = (s) => {
1007
+ if (o + s > e.length)
1005
1008
  throw new Error(
1006
- `Malformed witness data: need ${r} byte(s) at offset ${o}, only ${e.length - o} remaining`
1009
+ `Malformed witness data: need ${s} byte(s) at offset ${o}, only ${e.length - o} remaining`
1007
1010
  );
1008
- }, i = () => {
1011
+ }, r = () => {
1009
1012
  n(1);
1010
- const r = e[o++];
1011
- if (r < 253) return r;
1012
- if (r === 253) {
1013
+ const s = e[o++];
1014
+ if (s < 253) return s;
1015
+ if (s === 253) {
1013
1016
  n(2);
1014
1017
  const u = (e[o] | e[o + 1] << 8) >>> 0;
1015
1018
  return o += 2, u;
1016
1019
  }
1017
- if (r === 254) {
1020
+ if (s === 254) {
1018
1021
  n(4);
1019
1022
  const u = (e[o] | e[o + 1] << 8 | e[o + 2] << 16 | e[o + 3] << 24) >>> 0;
1020
1023
  return o += 4, u;
@@ -1022,14 +1025,14 @@ function Bt(e) {
1022
1025
  throw new Error(
1023
1026
  `Malformed witness data: 8-byte varint (0xff) not supported at offset ${o - 1}`
1024
1027
  );
1025
- }, s = i();
1026
- for (let r = 0; r < s; r++) {
1027
- const u = i();
1028
- n(u), t.push(c.from(e.subarray(o, o + u))), o += u;
1028
+ }, i = r();
1029
+ for (let s = 0; s < i; s++) {
1030
+ const u = r();
1031
+ n(u), t.push(a.from(e.subarray(o, o + u))), o += u;
1029
1032
  }
1030
1033
  if (o !== e.length)
1031
1034
  throw new Error(
1032
- `Malformed witness data: ${e.length - o} trailing byte(s) after parsing ${s} item(s)`
1035
+ `Malformed witness data: ${e.length - o} trailing byte(s) after parsing ${i} item(s)`
1033
1036
  );
1034
1037
  return t;
1035
1038
  }
@@ -1040,7 +1043,7 @@ class $ extends Error {
1040
1043
  ), this.name = "PsbtSubstitutionError";
1041
1044
  }
1042
1045
  }
1043
- function ve(e, t) {
1046
+ function me(e, t) {
1044
1047
  try {
1045
1048
  return H.fromHex(t);
1046
1049
  } catch (o) {
@@ -1052,12 +1055,12 @@ const Mt = 8;
1052
1055
  function B(e) {
1053
1056
  return `${e.toString("hex").slice(0, Mt)}…`;
1054
1057
  }
1055
- function Ee(e) {
1056
- const t = c.from(e).reverse();
1058
+ function $e(e) {
1059
+ const t = a.from(e).reverse();
1057
1060
  return B(t);
1058
1061
  }
1059
1062
  function to(e) {
1060
- const t = ve("requested", e.requestedPsbtHex), o = ve("returned", e.returnedPsbtHex);
1063
+ const t = me("requested", e.requestedPsbtHex), o = me("returned", e.returnedPsbtHex);
1061
1064
  if (t.version !== o.version)
1062
1065
  throw new $(
1063
1066
  `tx version differs (requested=${t.version}, returned=${o.version})`
@@ -1075,109 +1078,109 @@ function to(e) {
1075
1078
  `output count differs (requested=${t.txOutputs.length}, returned=${o.txOutputs.length})`
1076
1079
  );
1077
1080
  for (let n = 0; n < t.txInputs.length; n++) {
1078
- const i = t.txInputs[n], s = o.txInputs[n];
1079
- if (!i.hash.equals(s.hash))
1081
+ const r = t.txInputs[n], i = o.txInputs[n];
1082
+ if (!r.hash.equals(i.hash))
1080
1083
  throw new $(
1081
- `input ${n} prevout txid differs (requested=${Ee(i.hash)}, returned=${Ee(s.hash)})`
1084
+ `input ${n} prevout txid differs (requested=${$e(r.hash)}, returned=${$e(i.hash)})`
1082
1085
  );
1083
- if (i.index !== s.index)
1086
+ if (r.index !== i.index)
1084
1087
  throw new $(
1085
- `input ${n} prevout vout differs (requested=${i.index}, returned=${s.index})`
1088
+ `input ${n} prevout vout differs (requested=${r.index}, returned=${i.index})`
1086
1089
  );
1087
- if (i.sequence !== s.sequence)
1090
+ if (r.sequence !== i.sequence)
1088
1091
  throw new $(
1089
- `input ${n} sequence differs (requested=${i.sequence}, returned=${s.sequence})`
1092
+ `input ${n} sequence differs (requested=${r.sequence}, returned=${i.sequence})`
1090
1093
  );
1091
1094
  }
1092
1095
  for (let n = 0; n < t.txOutputs.length; n++) {
1093
- const i = t.txOutputs[n], s = o.txOutputs[n];
1094
- if (!i.script.equals(s.script))
1096
+ const r = t.txOutputs[n], i = o.txOutputs[n];
1097
+ if (!r.script.equals(i.script))
1095
1098
  throw new $(
1096
- `output ${n} scriptPubKey differs (requested=${B(i.script)}, returned=${B(s.script)})`
1099
+ `output ${n} scriptPubKey differs (requested=${B(r.script)}, returned=${B(i.script)})`
1097
1100
  );
1098
- if (i.value !== s.value)
1101
+ if (r.value !== i.value)
1099
1102
  throw new $(
1100
- `output ${n} value differs (requested=${i.value}, returned=${s.value})`
1103
+ `output ${n} value differs (requested=${r.value}, returned=${i.value})`
1101
1104
  );
1102
1105
  }
1103
1106
  }
1104
1107
  function oo(e) {
1105
- const { requestedPsbtHex: t, signatureHex: o, signerXOnlyPubkeyHex: n, inputIndex: i } = e, s = f(o);
1106
- if (s.length !== W)
1108
+ const { requestedPsbtHex: t, signatureHex: o, signerXOnlyPubkeyHex: n, inputIndex: r } = e, i = f(o);
1109
+ if (i.length !== W)
1107
1110
  throw new Error(
1108
- `Schnorr signature for input ${i} must be ${W} hex chars (64 bytes), got ${s.length}.`
1111
+ `Schnorr signature for input ${r} must be ${W} hex chars (64 bytes), got ${i.length}.`
1109
1112
  );
1110
- const r = f(n);
1111
- if (r.length !== ie)
1113
+ const s = f(n);
1114
+ if (s.length !== ce)
1112
1115
  throw new Error(
1113
- `Signer x-only pubkey for input ${i} must be ${ie} hex chars (32 bytes), got ${r.length}.`
1116
+ `Signer x-only pubkey for input ${r} must be ${ce} hex chars (32 bytes), got ${s.length}.`
1114
1117
  );
1115
1118
  const u = H.fromHex(t);
1116
- if (i < 0 || i >= u.data.inputs.length)
1119
+ if (r < 0 || r >= u.data.inputs.length)
1117
1120
  throw new Error(
1118
- `Input index ${i} out of range (${u.data.inputs.length} inputs).`
1121
+ `Input index ${r} out of range (${u.data.inputs.length} inputs).`
1119
1122
  );
1120
- const h = [], l = [];
1123
+ const c = [], p = [];
1121
1124
  for (let g = 0; g < u.data.inputs.length; g++) {
1122
1125
  const m = u.data.inputs[g].witnessUtxo;
1123
1126
  if (!m)
1124
1127
  throw new Error(
1125
1128
  `Cannot verify signature: input ${g} of the requested PSBT has no witnessUtxo (required to recompute the Taproot sighash).`
1126
1129
  );
1127
- h.push(m.script), l.push(m.value);
1130
+ c.push(m.script), p.push(m.value);
1128
1131
  }
1129
- const d = u.data.inputs[i].tapLeafScript;
1130
- if (!d || d.length !== 1)
1132
+ const l = u.data.inputs[r].tapLeafScript;
1133
+ if (!l || l.length !== 1)
1131
1134
  throw new Error(
1132
- `Cannot verify signature: input ${i} of the requested PSBT must have exactly one tapLeafScript, got ${(d == null ? void 0 : d.length) ?? 0}.`
1135
+ `Cannot verify signature: input ${r} of the requested PSBT must have exactly one tapLeafScript, got ${(l == null ? void 0 : l.length) ?? 0}.`
1133
1136
  );
1134
- const a = d[0];
1135
- if (a.leafVersion !== y)
1137
+ const h = l[0];
1138
+ if (h.leafVersion !== y)
1136
1139
  throw new Error(
1137
- `Cannot verify signature: input ${i} tapLeafScript has leaf version 0x${a.leafVersion.toString(16)}, expected 0x${y.toString(16)}.`
1140
+ `Cannot verify signature: input ${r} tapLeafScript has leaf version 0x${h.leafVersion.toString(16)}, expected 0x${y.toString(16)}.`
1138
1141
  );
1139
- const P = ke(a.leafVersion, a.script), p = new k();
1140
- p.version = u.version, p.locktime = u.locktime;
1142
+ const d = _e(h.leafVersion, h.script), P = new k();
1143
+ P.version = u.version, P.locktime = u.locktime;
1141
1144
  for (const g of u.txInputs)
1142
- p.addInput(g.hash, g.index, g.sequence);
1145
+ P.addInput(g.hash, g.index, g.sequence);
1143
1146
  for (const g of u.txOutputs)
1144
- p.addOutput(g.script, g.value);
1145
- const v = p.hashForWitnessV1(
1146
- i,
1147
- h,
1148
- l,
1147
+ P.addOutput(g.script, g.value);
1148
+ const E = P.hashForWitnessV1(
1149
+ r,
1150
+ c,
1151
+ p,
1149
1152
  k.SIGHASH_DEFAULT,
1150
- P
1153
+ d
1151
1154
  );
1152
- if (!Ce.verifySchnorr(
1153
- v,
1154
- C(r),
1155
- C(s)
1155
+ if (!ke.verifySchnorr(
1156
+ E,
1157
+ C(s),
1158
+ C(i)
1156
1159
  ))
1157
1160
  throw new Error(
1158
- `Schnorr signature for input ${i} (signer ${r}) does not verify against the expected Taproot script-path sighash. The wallet may have signed with the tweaked key, signed a different transaction, or returned an invalid signature.`
1161
+ `Schnorr signature for input ${r} (signer ${s}) does not verify against the expected Taproot script-path sighash. The wallet may have signed with the tweaked key, signed a different transaction, or returned an invalid signature.`
1159
1162
  );
1160
1163
  }
1161
1164
  export {
1162
1165
  V as H,
1163
- ot as P,
1166
+ nt as P,
1164
1167
  Zt as a,
1165
1168
  jt as b,
1166
1169
  Qt as c,
1167
- nt as d,
1168
- rt as e,
1170
+ rt as d,
1171
+ it as e,
1169
1172
  Jt as f,
1170
1173
  eo as g,
1171
1174
  $ as h,
1172
1175
  to as i,
1173
1176
  oo as j,
1174
1177
  ct as k,
1175
- Ze as l,
1176
- ke as m,
1177
- be as n,
1178
- et as o,
1178
+ je as l,
1179
+ _e as m,
1180
+ Ie as n,
1181
+ tt as o,
1179
1182
  Ct as p,
1180
1183
  bt as q,
1181
- ze as r
1184
+ Ye as r
1182
1185
  };
1183
- //# sourceMappingURL=verifyScriptPathSchnorrSignature-owu3BfyT.js.map
1186
+ //# sourceMappingURL=verifyScriptPathSchnorrSignature-D-fdi-sG.js.map