@babylonlabs-io/ts-sdk 0.72.1 → 0.74.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 (165) hide show
  1. package/README.md +56 -13
  2. package/dist/BTCVaultRegistryKeyEpochs.abi-CrQiTLfA.cjs +2 -0
  3. package/dist/BTCVaultRegistryKeyEpochs.abi-CrQiTLfA.cjs.map +1 -0
  4. package/dist/BTCVaultRegistryKeyEpochs.abi-D8cIbMtH.js +229 -0
  5. package/dist/BTCVaultRegistryKeyEpochs.abi-D8cIbMtH.js.map +1 -0
  6. package/dist/PeginManager-C9RPOd0L.js +1216 -0
  7. package/dist/PeginManager-C9RPOd0L.js.map +1 -0
  8. package/dist/PeginManager-E-UHA1un.cjs +2 -0
  9. package/dist/PeginManager-E-UHA1un.cjs.map +1 -0
  10. package/dist/bip322Verify-B7_gIhRk.cjs +2 -0
  11. package/dist/bip322Verify-B7_gIhRk.cjs.map +1 -0
  12. package/dist/bip322Verify-D6sBBUHE.js +79 -0
  13. package/dist/bip322Verify-D6sBBUHE.js.map +1 -0
  14. package/dist/{buildAndBroadcastReclaim-QIN8Mcwq.js → buildAndBroadcastReclaim-BXclIcu_.js} +3 -3
  15. package/dist/{buildAndBroadcastReclaim-QIN8Mcwq.js.map → buildAndBroadcastReclaim-BXclIcu_.js.map} +1 -1
  16. package/dist/{buildAndBroadcastReclaim-HX2xQlbM.cjs → buildAndBroadcastReclaim-U-PyFfDg.cjs} +2 -2
  17. package/dist/{buildAndBroadcastReclaim-HX2xQlbM.cjs.map → buildAndBroadcastReclaim-U-PyFfDg.cjs.map} +1 -1
  18. package/dist/index.cjs +1 -1
  19. package/dist/index.js +237 -228
  20. package/dist/index.js.map +1 -1
  21. package/dist/onChainBtcPubkey-BbxRrbvg.cjs +2 -0
  22. package/dist/onChainBtcPubkey-BbxRrbvg.cjs.map +1 -0
  23. package/dist/onChainBtcPubkey-C-6UWpD8.js +34 -0
  24. package/dist/onChainBtcPubkey-C-6UWpD8.js.map +1 -0
  25. package/dist/{parseFundingOutpoints-BkgGihaY.cjs → parseFundingOutpoints-B4iQeX6q.cjs} +2 -2
  26. package/dist/{parseFundingOutpoints-BkgGihaY.cjs.map → parseFundingOutpoints-B4iQeX6q.cjs.map} +1 -1
  27. package/dist/{parseFundingOutpoints-DlINgQ3X.js → parseFundingOutpoints-B67CoXpF.js} +2 -2
  28. package/dist/{parseFundingOutpoints-DlINgQ3X.js.map → parseFundingOutpoints-B67CoXpF.js.map} +1 -1
  29. package/dist/pegin-registration-client-6vLk2itL.cjs +2 -0
  30. package/dist/pegin-registration-client-6vLk2itL.cjs.map +1 -0
  31. package/dist/pegin-registration-client-BdRiR8br.js +2635 -0
  32. package/dist/pegin-registration-client-BdRiR8br.js.map +1 -0
  33. package/dist/primeVpAuth-DBHohVKM.cjs +2 -0
  34. package/dist/primeVpAuth-DBHohVKM.cjs.map +1 -0
  35. package/dist/primeVpAuth-DvaD45q_.js +745 -0
  36. package/dist/primeVpAuth-DvaD45q_.js.map +1 -0
  37. package/dist/psbtInputFields-B3e05Xe6.js +171 -0
  38. package/dist/psbtInputFields-B3e05Xe6.js.map +1 -0
  39. package/dist/psbtInputFields-BIxBpPj2.cjs +2 -0
  40. package/dist/psbtInputFields-BIxBpPj2.cjs.map +1 -0
  41. package/dist/sha2-CrlWM5S8.js +312 -0
  42. package/dist/{sha2-BYVxyZzX.js.map → sha2-CrlWM5S8.js.map} +1 -1
  43. package/dist/sha2-DI0-0SHr.cjs +2 -0
  44. package/dist/{sha2-DsrLC4NM.cjs.map → sha2-DI0-0SHr.cjs.map} +1 -1
  45. package/dist/{signPsbtsWithFallback-CCFTzE0o.js → signPsbtsWithFallback-0VBALhjS.js} +2 -2
  46. package/dist/{signPsbtsWithFallback-CCFTzE0o.js.map → signPsbtsWithFallback-0VBALhjS.js.map} +1 -1
  47. package/dist/{signPsbtsWithFallback-CrkvpSJz.cjs → signPsbtsWithFallback-DMSpIQWH.cjs} +2 -2
  48. package/dist/{signPsbtsWithFallback-CrkvpSJz.cjs.map → signPsbtsWithFallback-DMSpIQWH.cjs.map} +1 -1
  49. package/dist/tbv/core/clients/eth/__tests__/eth-import-boundary.test.d.ts +2 -0
  50. package/dist/tbv/core/clients/eth/__tests__/eth-import-boundary.test.d.ts.map +1 -0
  51. package/dist/tbv/core/clients/eth/__tests__/onChainBtcPubkey.test.d.ts +2 -0
  52. package/dist/tbv/core/clients/eth/__tests__/onChainBtcPubkey.test.d.ts.map +1 -0
  53. package/dist/tbv/core/clients/eth/__tests__/payout-script.test.d.ts +2 -0
  54. package/dist/tbv/core/clients/eth/__tests__/payout-script.test.d.ts.map +1 -0
  55. package/dist/tbv/core/clients/eth/__tests__/pegin-registration-calldata.test.d.ts +2 -0
  56. package/dist/tbv/core/clients/eth/__tests__/pegin-registration-calldata.test.d.ts.map +1 -0
  57. package/dist/tbv/core/clients/eth/__tests__/pegin-registration-client.test.d.ts +2 -0
  58. package/dist/tbv/core/clients/eth/__tests__/pegin-registration-client.test.d.ts.map +1 -0
  59. package/dist/tbv/core/clients/eth/__tests__/pegin-transaction.test.d.ts +2 -0
  60. package/dist/tbv/core/clients/eth/__tests__/pegin-transaction.test.d.ts.map +1 -0
  61. package/dist/tbv/core/clients/eth/index.cjs +2 -0
  62. package/dist/tbv/core/clients/eth/index.cjs.map +1 -0
  63. package/dist/tbv/core/clients/eth/index.d.ts +4 -0
  64. package/dist/tbv/core/clients/eth/index.d.ts.map +1 -1
  65. package/dist/tbv/core/clients/eth/index.js +22 -0
  66. package/dist/tbv/core/clients/eth/index.js.map +1 -0
  67. package/dist/tbv/core/clients/eth/onChainBtcPubkey.d.ts.map +1 -1
  68. package/dist/tbv/core/clients/eth/payout-script.d.ts +4 -0
  69. package/dist/tbv/core/clients/eth/payout-script.d.ts.map +1 -0
  70. package/dist/tbv/core/clients/eth/pegin-registration-client.d.ts +99 -0
  71. package/dist/tbv/core/clients/eth/pegin-registration-client.d.ts.map +1 -0
  72. package/dist/tbv/core/clients/eth/pegin-transaction.d.ts +14 -0
  73. package/dist/tbv/core/clients/eth/pegin-transaction.d.ts.map +1 -0
  74. package/dist/tbv/core/clients/index.cjs +1 -1
  75. package/dist/tbv/core/clients/index.js +55 -48
  76. package/dist/tbv/core/clients/index.js.map +1 -1
  77. package/dist/tbv/core/clients/mempool/index.cjs +2 -0
  78. package/dist/tbv/core/clients/mempool/index.cjs.map +1 -0
  79. package/dist/tbv/core/clients/mempool/index.js +222 -0
  80. package/dist/tbv/core/clients/mempool/index.js.map +1 -0
  81. package/dist/tbv/core/contracts/index.cjs +1 -1
  82. package/dist/tbv/core/contracts/index.cjs.map +1 -1
  83. package/dist/tbv/core/contracts/index.js +491 -12
  84. package/dist/tbv/core/contracts/index.js.map +1 -1
  85. package/dist/tbv/core/index.cjs +1 -1
  86. package/dist/tbv/core/index.d.ts +4 -0
  87. package/dist/tbv/core/index.d.ts.map +1 -1
  88. package/dist/tbv/core/index.js +235 -226
  89. package/dist/tbv/core/index.js.map +1 -1
  90. package/dist/tbv/core/managers/PeginManager.d.ts +38 -30
  91. package/dist/tbv/core/managers/PeginManager.d.ts.map +1 -1
  92. package/dist/tbv/core/managers/index.cjs +1 -1
  93. package/dist/tbv/core/managers/index.d.ts +2 -1
  94. package/dist/tbv/core/managers/index.d.ts.map +1 -1
  95. package/dist/tbv/core/managers/index.js +2 -2
  96. package/dist/tbv/core/pegin-fingerprint/__tests__/peginFingerprint.golden.test.d.ts +62 -0
  97. package/dist/tbv/core/pegin-fingerprint/__tests__/peginFingerprint.golden.test.d.ts.map +1 -0
  98. package/dist/tbv/core/pegin-fingerprint/__tests__/peginFingerprint.test.d.ts +15 -0
  99. package/dist/tbv/core/pegin-fingerprint/__tests__/peginFingerprint.test.d.ts.map +1 -0
  100. package/dist/tbv/core/pegin-fingerprint/index.d.ts +14 -0
  101. package/dist/tbv/core/pegin-fingerprint/index.d.ts.map +1 -0
  102. package/dist/tbv/core/pegin-fingerprint/peginFingerprint.d.ts +141 -0
  103. package/dist/tbv/core/pegin-fingerprint/peginFingerprint.d.ts.map +1 -0
  104. package/dist/tbv/core/services/index.cjs +1 -1
  105. package/dist/tbv/core/services/index.js +2 -2
  106. package/dist/tbv/core/utils/eth/index.cjs +2 -0
  107. package/dist/tbv/core/utils/eth/index.cjs.map +1 -0
  108. package/dist/tbv/core/utils/eth/index.js +109 -0
  109. package/dist/tbv/core/utils/eth/index.js.map +1 -0
  110. package/dist/tbv/core/utils/index.cjs +1 -1
  111. package/dist/tbv/core/utils/index.js +41 -40
  112. package/dist/tbv/core/utils/index.js.map +1 -1
  113. package/dist/tbv/core/vault-secrets/index.cjs +1 -1
  114. package/dist/tbv/core/vault-secrets/index.js +1 -1
  115. package/dist/tbv/index.cjs +1 -1
  116. package/dist/tbv/index.js +235 -226
  117. package/dist/tbv/index.js.map +1 -1
  118. package/dist/testing/index.cjs +1 -1
  119. package/dist/testing/index.js +1 -1
  120. package/dist/toRefundInputs-BwG6T0PP.cjs +2 -0
  121. package/dist/toRefundInputs-BwG6T0PP.cjs.map +1 -0
  122. package/dist/{toRefundInputs-BG-qHCEu.js → toRefundInputs-C3oIN0aW.js} +237 -139
  123. package/dist/toRefundInputs-C3oIN0aW.js.map +1 -0
  124. package/dist/types-CPDLZm3l.js +430 -0
  125. package/dist/types-CPDLZm3l.js.map +1 -0
  126. package/dist/types-DSlcXtog.cjs +2 -0
  127. package/dist/types-DSlcXtog.cjs.map +1 -0
  128. package/package.json +32 -3
  129. package/dist/BTCVaultRegistryKeyEpochs.abi-CXjhRZbm.js +0 -111
  130. package/dist/BTCVaultRegistryKeyEpochs.abi-CXjhRZbm.js.map +0 -1
  131. package/dist/BTCVaultRegistryKeyEpochs.abi-_NERAdc5.cjs +0 -2
  132. package/dist/BTCVaultRegistryKeyEpochs.abi-_NERAdc5.cjs.map +0 -1
  133. package/dist/PeginManager-Bwjqb0_6.cjs +0 -2
  134. package/dist/PeginManager-Bwjqb0_6.cjs.map +0 -1
  135. package/dist/PeginManager-DjatPUPS.js +0 -1503
  136. package/dist/PeginManager-DjatPUPS.js.map +0 -1
  137. package/dist/ProtocolParams.abi-C0TSRaHV.js +0 -486
  138. package/dist/ProtocolParams.abi-C0TSRaHV.js.map +0 -1
  139. package/dist/ProtocolParams.abi-CYZoV2EI.cjs +0 -2
  140. package/dist/ProtocolParams.abi-CYZoV2EI.cjs.map +0 -1
  141. package/dist/errors-Blc-JWnI.js +0 -121
  142. package/dist/errors-Blc-JWnI.js.map +0 -1
  143. package/dist/errors-CGcNP0rV.cjs +0 -2
  144. package/dist/errors-CGcNP0rV.cjs.map +0 -1
  145. package/dist/mempoolApi-BJvC9nPF.cjs +0 -2
  146. package/dist/mempoolApi-BJvC9nPF.cjs.map +0 -1
  147. package/dist/mempoolApi-_CoQH5vH.js +0 -612
  148. package/dist/mempoolApi-_CoQH5vH.js.map +0 -1
  149. package/dist/onChainBtcPubkey-B5ZvWCCF.cjs +0 -2
  150. package/dist/onChainBtcPubkey-B5ZvWCCF.cjs.map +0 -1
  151. package/dist/onChainBtcPubkey-DATNfAAl.js +0 -19
  152. package/dist/onChainBtcPubkey-DATNfAAl.js.map +0 -1
  153. package/dist/primeVpAuth-BI63kgdd.js +0 -1171
  154. package/dist/primeVpAuth-BI63kgdd.js.map +0 -1
  155. package/dist/primeVpAuth-D3xbar3j.cjs +0 -2
  156. package/dist/primeVpAuth-D3xbar3j.cjs.map +0 -1
  157. package/dist/sha2-BYVxyZzX.js +0 -274
  158. package/dist/sha2-DsrLC4NM.cjs +0 -2
  159. package/dist/toRefundInputs-BG-qHCEu.js.map +0 -1
  160. package/dist/toRefundInputs-kVR-3EdD.cjs +0 -2
  161. package/dist/toRefundInputs-kVR-3EdD.cjs.map +0 -1
  162. package/dist/waitForTransactionReceiptSmartAware-DpQ69ySe.cjs +0 -2
  163. package/dist/waitForTransactionReceiptSmartAware-DpQ69ySe.cjs.map +0 -1
  164. package/dist/waitForTransactionReceiptSmartAware-z3Xfmo44.js +0 -277
  165. package/dist/waitForTransactionReceiptSmartAware-z3Xfmo44.js.map +0 -1
@@ -1,1171 +0,0 @@
1
- var ce = Object.defineProperty;
2
- var le = (r, e, t) => e in r ? ce(r, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : r[e] = t;
3
- var h = (r, e, t) => le(r, typeof e != "symbol" ? e + "" : e, t);
4
- import { B as v } from "./BTCVaultRegistry.abi-CJwWI2EO.js";
5
- import { A as _, P as g } from "./ProtocolParams.abi-C0TSRaHV.js";
6
- import { k as ue, v as O, o as de, j as he, l as pe } from "./mempoolApi-_CoQH5vH.js";
7
- import { s as A, S as ge, h as me, p as Z } from "./bitcoin-C-TuHb-v.js";
8
- import { V as fe } from "./index-LgmJhdEN.js";
9
- import { a as ye } from "./json-rpc-client-DuUARJvV.js";
10
- import * as q from "@bitcoin-js/tiny-secp256k1-asmjs";
11
- import { X as C, H as b, C as ee } from "./validation-OSC0xTHB.js";
12
- import { s as be } from "./sha2-BYVxyZzX.js";
13
- async function At(r, e) {
14
- const [t, n] = await r.multicall({
15
- contracts: [
16
- {
17
- address: e,
18
- abi: v,
19
- functionName: "protocolParams"
20
- },
21
- {
22
- address: e,
23
- abi: v,
24
- functionName: "applicationRegistry"
25
- }
26
- ],
27
- allowFailure: !1
28
- });
29
- return {
30
- protocolParams: t,
31
- applicationRegistry: n
32
- };
33
- }
34
- function K(r, e, t) {
35
- if (r !== e)
36
- throw new Error(
37
- `${t}: multicall returned ${r} results for ${e} calls, so the results are not roster-aligned; refusing to use them`
38
- );
39
- }
40
- function Ae(r, e) {
41
- return {
42
- vaultProvider: r[0],
43
- vaultKeepers: r.slice(1, 1 + e),
44
- universalChallengers: r.slice(1 + e)
45
- };
46
- }
47
- class _t {
48
- constructor(e, t) {
49
- this.publicClient = e, this.contracts = t;
50
- }
51
- /**
52
- * One multicall, `allowFailure: false`, so every key in the set is read at
53
- * the same block. A rotation landing between two separate `eth_call`s would
54
- * otherwise produce a mixed-epoch key set and a lock no counterparty agrees
55
- * with.
56
- */
57
- async readAll(e, t, n, i, s) {
58
- const a = await this.publicClient.multicall({
59
- contracts: e,
60
- allowFailure: !1,
61
- blockNumber: s
62
- });
63
- return K(
64
- a.length,
65
- 1 + t + n,
66
- i
67
- ), Ae(a, t);
68
- }
69
- async getCurrentOperationKeys(e, t) {
70
- const n = [
71
- {
72
- address: this.contracts.btcVaultRegistry,
73
- abi: v,
74
- functionName: "getCurrentOperationBtcKey",
75
- args: [e.vaultProviderEthAddress]
76
- },
77
- ...e.vaultKeepers.map((i) => ({
78
- address: this.contracts.applicationRegistry,
79
- abi: _,
80
- functionName: "getCurrentOperationBtcKey",
81
- args: [e.applicationEntryPoint, i.ethAddress]
82
- })),
83
- ...e.universalChallengers.map((i) => ({
84
- address: this.contracts.protocolParams,
85
- abi: g,
86
- functionName: "getCurrentOperationBtcKey",
87
- args: [i.ethAddress]
88
- }))
89
- ];
90
- return this.readAll(
91
- n,
92
- e.vaultKeepers.length,
93
- e.universalChallengers.length,
94
- "getCurrentOperationKeys",
95
- t
96
- );
97
- }
98
- async getOperationKeysAtEpochs(e, t) {
99
- const n = [
100
- // The VP takes the plain `AtEpoch` variant: it has no membership
101
- // version, so its genesis (the registration key at version 0) is
102
- // unambiguous and the contract resolves it internally.
103
- {
104
- address: this.contracts.btcVaultRegistry,
105
- abi: v,
106
- functionName: "getOperationBtcKeyAtEpoch",
107
- args: [e.vaultProviderEthAddress, t.vpKeyEpoch]
108
- },
109
- // Keepers and challengers take `...OrGenesis` with their roster key
110
- // passed explicitly, because the correct genesis for them is their key
111
- // in *this vault's frozen membership version*. An operator dropped from
112
- // the current roster, or listed under a different key in an older
113
- // version, would otherwise resolve against the wrong genesis.
114
- ...e.vaultKeepers.map((i) => ({
115
- address: this.contracts.applicationRegistry,
116
- abi: _,
117
- functionName: "getOperationBtcKeyAtEpochOrGenesis",
118
- args: [
119
- e.applicationEntryPoint,
120
- i.ethAddress,
121
- t.appKeeperKeyEpoch,
122
- i.btcPubKey
123
- ]
124
- })),
125
- ...e.universalChallengers.map((i) => ({
126
- address: this.contracts.protocolParams,
127
- abi: g,
128
- functionName: "getOperationBtcKeyAtEpochOrGenesis",
129
- args: [i.ethAddress, t.ucKeyEpoch, i.btcPubKey]
130
- }))
131
- ];
132
- return this.readAll(
133
- n,
134
- e.vaultKeepers.length,
135
- e.universalChallengers.length,
136
- "getOperationKeysAtEpochs"
137
- );
138
- }
139
- async getPayoutScriptsAtEpochs(e, t) {
140
- const n = await this.publicClient.multicall({
141
- contracts: [
142
- {
143
- address: this.contracts.btcVaultRegistry,
144
- abi: v,
145
- functionName: "getPayoutScriptAtEpoch",
146
- args: [e.vaultProviderEthAddress, t.vpKeyEpoch]
147
- },
148
- ...e.vaultKeepers.map((i) => ({
149
- address: this.contracts.applicationRegistry,
150
- abi: _,
151
- functionName: "getPayoutScriptAtEpoch",
152
- args: [
153
- e.applicationEntryPoint,
154
- i.ethAddress,
155
- t.appKeeperKeyEpoch
156
- ]
157
- }))
158
- ],
159
- allowFailure: !1
160
- });
161
- return K(
162
- n.length,
163
- 1 + e.vaultKeepers.length,
164
- "getPayoutScriptsAtEpochs"
165
- ), {
166
- vaultProvider: n[0],
167
- vaultKeepers: [...n.slice(1)]
168
- };
169
- }
170
- }
171
- const H = 65535;
172
- function P(r) {
173
- return {
174
- timelockAssert: r.timelockAssert,
175
- timelockChallengeAssert: r.timelockChallengeAssert,
176
- securityCouncilKeys: [...r.securityCouncilKeys],
177
- councilQuorum: r.councilQuorum,
178
- feeRate: r.feeRate,
179
- babeTotalInstances: r.babeTotalInstances,
180
- babeInstancesToFinalize: r.babeInstancesToFinalize,
181
- minVpCommissionBps: r.minVpCommissionBps,
182
- tRefund: r.tRefund,
183
- tStale: r.tStale,
184
- minPeginFeeRate: r.minPeginFeeRate,
185
- proverCircuitVersion: r.proverCircuitVersion,
186
- minPrepeginDepth: r.minPrepeginDepth
187
- };
188
- }
189
- function L(r) {
190
- return {
191
- minimumPegInAmount: r.minimumPegInAmount,
192
- maxPegInAmount: r.maxPegInAmount,
193
- pegInAckTimeout: r.pegInAckTimeout,
194
- pegInActivationTimeout: r.pegInActivationTimeout,
195
- maxHtlcOutputCount: r.maxHtlcOutputCount,
196
- expiredPegInGraceBlocks: r.expiredPegInGraceBlocks
197
- };
198
- }
199
- function U(r) {
200
- if (r > BigInt(H))
201
- throw new Error(
202
- `timelockAssert value ${r} exceeds uint16 max (${H})`
203
- );
204
- return Number(r);
205
- }
206
- class wt {
207
- constructor(e, t) {
208
- this.publicClient = e, this.contractAddress = t;
209
- }
210
- async getTBVProtocolParams() {
211
- const e = await this.publicClient.readContract({
212
- address: this.contractAddress,
213
- abi: g,
214
- functionName: "getTBVProtocolParams"
215
- }), t = L(e);
216
- return ue(t), t;
217
- }
218
- async getLatestOffchainParams() {
219
- const e = await this.publicClient.readContract({
220
- address: this.contractAddress,
221
- abi: g,
222
- functionName: "getLatestOffchainParams"
223
- }), t = P(e);
224
- return O(t), t;
225
- }
226
- async getOffchainParamsByVersion(e) {
227
- const t = await this.publicClient.readContract({
228
- address: this.contractAddress,
229
- abi: g,
230
- functionName: "getOffchainParamsByVersion",
231
- args: [e]
232
- }), n = P(t);
233
- return O(n), n;
234
- }
235
- async getLatestOffchainParamsVersion() {
236
- const e = await this.publicClient.readContract({
237
- address: this.contractAddress,
238
- abi: g,
239
- functionName: "latestOffchainParamsVersion"
240
- }), t = Number(e);
241
- return de(t), t;
242
- }
243
- async getTimelockPeginByVersion(e) {
244
- const t = await this.getOffchainParamsByVersion(e);
245
- return U(t.timelockAssert);
246
- }
247
- /**
248
- * Returned as `bigint` with no `Number` narrowing: the registry compares it
249
- * against `block.number`, so callers must do the same arithmetic the
250
- * contract does. `0` is the documented "disabled" case and is returned as
251
- * `0n`. A missing getter or a non-bigint payload throws — never coerced to
252
- * `0`, which would fail open and skip the observation window.
253
- *
254
- * @throws If the deployment does not expose `peginActivationDelay()`, or
255
- * the decoded payload is not a `bigint`.
256
- */
257
- async getPeginActivationDelay() {
258
- const e = await this.publicClient.readContract({
259
- address: this.contractAddress,
260
- abi: g,
261
- functionName: "peginActivationDelay"
262
- });
263
- if (typeof e != "bigint")
264
- throw new Error(
265
- `Invalid peginActivationDelay from contract: must be a bigint, got ${typeof e}`
266
- );
267
- return e;
268
- }
269
- /**
270
- * Read TBV protocol params, latest offchain params, and the latest version
271
- * label atomically via multicall. The version is paired with the params so
272
- * that a governance update between separate reads cannot let JS build BTC
273
- * scripts with version N params while the contract registers the vault
274
- * under version N+1.
275
- *
276
- * That guarantee holds only within this multicall. A caller that also reads
277
- * participant keys — every fresh peg-in build does — must pass the same
278
- * `blockNumber` here and to those reads, or the two describe different
279
- * blocks and the pairing above buys nothing across the seam.
280
- */
281
- async getPegInConfiguration(e) {
282
- const t = await this.publicClient.multicall({
283
- blockNumber: e,
284
- contracts: [
285
- {
286
- address: this.contractAddress,
287
- abi: g,
288
- functionName: "getTBVProtocolParams"
289
- },
290
- {
291
- address: this.contractAddress,
292
- abi: g,
293
- functionName: "getLatestOffchainParams"
294
- },
295
- {
296
- address: this.contractAddress,
297
- abi: g,
298
- functionName: "latestOffchainParamsVersion"
299
- },
300
- {
301
- address: this.contractAddress,
302
- abi: g,
303
- functionName: "activeVaultCoreVersion"
304
- }
305
- ],
306
- allowFailure: !1
307
- }), n = L(t[0]), i = P(t[1]), s = Number(t[2]), a = Number(t[3]), o = {
308
- minimumPegInAmount: n.minimumPegInAmount,
309
- maxPegInAmount: n.maxPegInAmount,
310
- pegInAckTimeout: n.pegInAckTimeout,
311
- pegInActivationTimeout: n.pegInActivationTimeout,
312
- maxHtlcOutputCount: n.maxHtlcOutputCount,
313
- expiredPegInGraceBlocks: n.expiredPegInGraceBlocks,
314
- timelockPegin: U(i.timelockAssert),
315
- timelockRefund: i.tRefund,
316
- minVpCommissionBps: i.minVpCommissionBps,
317
- offchainParams: i,
318
- offchainParamsVersion: s,
319
- activeVaultCoreVersion: a
320
- };
321
- return he(o), o;
322
- }
323
- /**
324
- * Fetch every historical offchain params version in a single multicall.
325
- * Iterates 1..latestVersion and calls `getOffchainParamsByVersion` for each.
326
- * Versions whose payload fails validation are skipped (not included in the
327
- * returned map) so a single bad historical version doesn't block the
328
- * lookup of the rest.
329
- *
330
- * @param onSkippedVersion - optional observer invoked once per skipped
331
- * version. Use to log/telemeter without coupling the SDK to a logger.
332
- */
333
- async fetchAllOffchainParams(e) {
334
- const t = await this.getLatestOffchainParamsVersion();
335
- if (t === 0)
336
- return { byVersion: /* @__PURE__ */ new Map(), latestVersion: 0 };
337
- const n = Array.from({ length: t }, (o, u) => u + 1), i = n.map((o) => ({
338
- address: this.contractAddress,
339
- abi: g,
340
- functionName: "getOffchainParamsByVersion",
341
- args: [o]
342
- })), s = await this.publicClient.multicall({
343
- contracts: i,
344
- allowFailure: !1
345
- }), a = /* @__PURE__ */ new Map();
346
- for (let o = 0; o < n.length; o++) {
347
- const u = P(s[o]);
348
- try {
349
- O(u), a.set(n[o], u);
350
- } catch (d) {
351
- e == null || e(
352
- n[o],
353
- d instanceof Error ? d : new Error(String(d))
354
- );
355
- }
356
- }
357
- return { byVersion: a, latestVersion: t };
358
- }
359
- }
360
- function k(r) {
361
- return r.map((e) => ({
362
- ethAddress: e.ethAddress,
363
- btcPubKey: e.btcPubKey
364
- }));
365
- }
366
- class xt {
367
- constructor(e, t) {
368
- this.publicClient = e, this.contractAddress = t;
369
- }
370
- async getVaultKeepersByVersion(e, t, n) {
371
- const i = await this.publicClient.readContract({
372
- address: this.contractAddress,
373
- abi: _,
374
- functionName: "getVaultKeepersByVersion",
375
- args: [e, t],
376
- blockNumber: n
377
- });
378
- return k(i);
379
- }
380
- async getCurrentVaultKeepers(e) {
381
- const t = await this.publicClient.readContract({
382
- address: this.contractAddress,
383
- abi: _,
384
- functionName: "getCurrentVaultKeepers",
385
- args: [e]
386
- });
387
- return k(t);
388
- }
389
- async getCurrentVaultKeepersVersion(e, t) {
390
- return await this.publicClient.readContract({
391
- address: this.contractAddress,
392
- abi: _,
393
- functionName: "getCurrentVaultKeepersVersion",
394
- args: [e],
395
- blockNumber: t
396
- });
397
- }
398
- }
399
- class vt {
400
- constructor(e, t) {
401
- this.publicClient = e, this.contractAddress = t;
402
- }
403
- async getUniversalChallengersByVersion(e, t) {
404
- const n = await this.publicClient.readContract({
405
- address: this.contractAddress,
406
- abi: g,
407
- functionName: "getUniversalChallengersByVersion",
408
- args: [e],
409
- blockNumber: t
410
- });
411
- return k(n);
412
- }
413
- async getCurrentUniversalChallengers() {
414
- const e = await this.publicClient.readContract({
415
- address: this.contractAddress,
416
- abi: g,
417
- functionName: "getCurrentUniversalChallengers"
418
- });
419
- return k(e);
420
- }
421
- async getLatestUniversalChallengersVersion(e) {
422
- return await this.publicClient.readContract({
423
- address: this.contractAddress,
424
- abi: g,
425
- functionName: "latestUniversalChallengersVersion",
426
- blockNumber: e
427
- });
428
- }
429
- }
430
- var _e = /* @__PURE__ */ ((r) => (r[r.PENDING = 0] = "PENDING", r[r.VERIFIED = 1] = "VERIFIED", r[r.ACTIVE = 2] = "ACTIVE", r[r.REDEEMED = 3] = "REDEEMED", r[r.EXPIRED = 4] = "EXPIRED", r))(_e || {});
431
- function S(r, e) {
432
- const t = (r & 7) << 5, n = typeof e == "bigint" ? e : BigInt(e);
433
- if (n < 0n) throw new Error("cborHead: negative argument");
434
- if (n < 24n) return new Uint8Array([t | Number(n)]);
435
- if (n < 0x100n) return new Uint8Array([t | 24, Number(n)]);
436
- if (n < 0x10000n) {
437
- const s = Number(n);
438
- return new Uint8Array([t | 25, s >>> 8 & 255, s & 255]);
439
- }
440
- if (n < 0x100000000n) {
441
- const s = Number(n);
442
- return new Uint8Array([
443
- t | 26,
444
- s >>> 24 & 255,
445
- s >>> 16 & 255,
446
- s >>> 8 & 255,
447
- s & 255
448
- ]);
449
- }
450
- const i = new Uint8Array(9);
451
- i[0] = t | 27;
452
- for (let s = 7; s >= 0; s--)
453
- i[1 + s] = Number(n >> BigInt((7 - s) * 8)) & 255;
454
- return i;
455
- }
456
- function te(...r) {
457
- const e = r.reduce((i, s) => i + s.length, 0), t = new Uint8Array(e);
458
- let n = 0;
459
- for (const i of r)
460
- t.set(i, n), n += i.length;
461
- return t;
462
- }
463
- function D(r) {
464
- const t = [S(4, r.length)];
465
- for (const n of r)
466
- t.push(S(0, n));
467
- return te(...t);
468
- }
469
- function we(r, e, t) {
470
- if (!Number.isSafeInteger(t) || t < 0)
471
- throw new Error(
472
- `encodeServerIdentityPayload: expires_at must be a non-negative safe integer, got ${t}`
473
- );
474
- const n = S(4, 3), i = D(r), s = D(e), a = S(0, t);
475
- return te(n, i, s, a);
476
- }
477
- const xe = new TextEncoder().encode(
478
- "btc-auth.server-identity.v1"
479
- ), ve = 2 * 3600;
480
- class m extends Error {
481
- constructor(e, t) {
482
- super(e), this.reason = t, this.name = "ServerIdentityError";
483
- }
484
- }
485
- function E(r) {
486
- const e = new Uint8Array(r.length / 2);
487
- for (let t = 0; t < e.length; t++)
488
- e[t] = parseInt(r.slice(t * 2, t * 2 + 2), 16);
489
- return e;
490
- }
491
- function Pe(r) {
492
- const { proof: e, pinnedServerPubkey: t, now: n } = r, i = r.maxLifetimeSecs ?? ve, s = A(t).toLowerCase();
493
- if (s.length !== C || !b.test(s))
494
- throw new m(
495
- `pinnedServerPubkey must be 32-byte hex; got ${s.length} chars`,
496
- "invalid_pubkey_encoding"
497
- );
498
- const a = A(e.server_pubkey).toLowerCase();
499
- if (a.length !== C || !b.test(a))
500
- throw new m(
501
- `server_pubkey must be 32-byte hex; got ${a.length} chars`,
502
- "invalid_pubkey_encoding"
503
- );
504
- if (a !== s)
505
- throw new m(
506
- `server_pubkey does not match pinned value: expected ${s}, got ${a}`,
507
- "pinned_pubkey_mismatch"
508
- );
509
- if (!Number.isSafeInteger(e.expires_at))
510
- throw new m(
511
- `expires_at must be a finite integer; got ${JSON.stringify(e.expires_at)}`,
512
- "invalid_expires_at"
513
- );
514
- if (!Number.isSafeInteger(n))
515
- throw new m(
516
- `now must be a finite integer; got ${JSON.stringify(n)}`,
517
- "invalid_expires_at"
518
- );
519
- if (e.expires_at <= n)
520
- throw new m(
521
- `server identity proof expired at ${e.expires_at}, now ${n}`,
522
- "expired"
523
- );
524
- if (!Number.isSafeInteger(i) || i <= 0)
525
- throw new m(
526
- `maxLifetimeSecs must be a positive safe integer; got ${JSON.stringify(i)}`,
527
- "invalid_max_lifetime"
528
- );
529
- if (e.expires_at - n > i)
530
- throw new m(
531
- `server identity proof expires too far in the future: expires_at=${e.expires_at}, now=${n}, max lifetime=${i}s`,
532
- "expires_too_far"
533
- );
534
- const o = A(e.ephemeral_pubkey).toLowerCase();
535
- if (o.length !== ee || !b.test(o))
536
- throw new m(
537
- `ephemeral_pubkey must be 33-byte compressed hex; got ${o.length} chars`,
538
- "invalid_ephemeral_pubkey"
539
- );
540
- const u = o.slice(0, 2);
541
- if (u !== "02" && u !== "03")
542
- throw new m(
543
- `ephemeral_pubkey must be compressed (prefix 02/03); got ${u}`,
544
- "invalid_ephemeral_pubkey"
545
- );
546
- const d = E(o);
547
- if (!q.isPoint(d))
548
- throw new m(
549
- "ephemeral_pubkey is not a valid secp256k1 point",
550
- "invalid_ephemeral_pubkey"
551
- );
552
- const p = A(e.signature).toLowerCase();
553
- if (p.length !== ge || !b.test(p))
554
- throw new m(
555
- `signature must be 64-byte Schnorr hex; got ${p.length} chars`,
556
- "invalid_signature_encoding"
557
- );
558
- const y = we(
559
- xe,
560
- E(o),
561
- e.expires_at
562
- );
563
- if (!pe(
564
- y,
565
- E(a),
566
- E(p)
567
- ))
568
- throw new m(
569
- "BIP-322 signature verification failed — ephemeral key is not attested by pinned server pubkey",
570
- "signature_verification_failed"
571
- );
572
- }
573
- const Ee = /* @__PURE__ */ new Set([
574
- "vaultProvider_submitDepositorWotsKey",
575
- "vaultProvider_submitDepositorPresignatures",
576
- "vaultProvider_requestDepositorPresignTransactions"
577
- ]), Ce = /* @__PURE__ */ new Set([
578
- "vaultProvider_requestDepositorClaimerArtifacts"
579
- ]), ke = 6e4, V = "auth_createDepositorToken", $ = "auth_createDepositorTokenGrpc";
580
- function re(r, e) {
581
- return new ye({
582
- baseUrl: r,
583
- timeout: ke,
584
- headers: e,
585
- retryableFor: (t) => t === V || t === $
586
- });
587
- }
588
- const Se = 0, Te = 1, R = 2, Ie = 3, Oe = 4, Re = 5, Ne = 6, Be = 7, X = 24, Ve = 28, $e = 20, Me = 21, Ge = 22, F = 256;
589
- class f extends Error {
590
- constructor(e) {
591
- super(`CBOR decode: ${e}`), this.name = "CborDecodeError";
592
- }
593
- }
594
- class ne {
595
- constructor(e) {
596
- h(this, "buf");
597
- /** Current read offset. Public so callers can slice encoded sub-ranges. */
598
- h(this, "pos", 0);
599
- this.buf = e;
600
- }
601
- nextByte() {
602
- if (this.pos >= this.buf.length)
603
- throw new f("unexpected end of input");
604
- return this.buf[this.pos++];
605
- }
606
- /**
607
- * Read an initial byte and its argument. Rejects indefinite-length
608
- * and reserved additional-info encodings. Arguments wider than
609
- * {@link Number.MAX_SAFE_INTEGER} are rejected — none of the token's
610
- * lengths, tags, or timestamps approach that bound.
611
- */
612
- readHead() {
613
- const e = this.nextByte(), t = e >> 5, n = e & 31;
614
- if (n < X)
615
- return { major: t, arg: n };
616
- if (n >= Ve)
617
- throw new f(
618
- `unsupported additional info ${n} (indefinite-length or reserved)`
619
- );
620
- const i = 1 << n - X;
621
- let s = 0n;
622
- for (let a = 0; a < i; a++)
623
- s = s << 8n | BigInt(this.nextByte());
624
- if (s > BigInt(Number.MAX_SAFE_INTEGER))
625
- throw new f(`argument ${s} exceeds safe integer range`);
626
- return { major: t, arg: Number(s) };
627
- }
628
- /** Read `length` raw bytes as a sub-array view into the backing buffer. */
629
- readBytes(e) {
630
- if (this.pos + e > this.buf.length)
631
- throw new f("length overruns end of input");
632
- const t = this.buf.subarray(this.pos, this.pos + e);
633
- return this.pos += e, t;
634
- }
635
- /**
636
- * Read a byte string (major type 2), returning its content bytes.
637
- * Throws if the next item is not a byte string.
638
- */
639
- readByteString() {
640
- const e = this.readHead();
641
- if (e.major !== R)
642
- throw new f(
643
- `expected byte string (major ${R}), got major ${e.major}`
644
- );
645
- return this.readBytes(e.arg);
646
- }
647
- /**
648
- * Read the next complete data item as a decoded {@link CborValue}.
649
- *
650
- * `depth` tracks the current nesting level so a deeply-nested blob is
651
- * rejected with a {@link CborDecodeError} rather than overflowing the
652
- * native call stack (see {@link MAX_NESTING_DEPTH}).
653
- */
654
- readValue(e = 0) {
655
- if (e > F)
656
- throw new f(
657
- `nesting exceeds maximum depth ${F}`
658
- );
659
- const t = this.readHead();
660
- switch (t.major) {
661
- case Se:
662
- return t.arg;
663
- case Te:
664
- return -1 - t.arg;
665
- case R:
666
- return this.readBytes(t.arg);
667
- case Ie:
668
- return new TextDecoder("utf-8", { fatal: !0 }).decode(
669
- this.readBytes(t.arg)
670
- );
671
- case Oe: {
672
- const n = [];
673
- for (let i = 0; i < t.arg; i++)
674
- n.push(this.readValue(e + 1));
675
- return n;
676
- }
677
- case Re: {
678
- const n = /* @__PURE__ */ new Map();
679
- for (let i = 0; i < t.arg; i++) {
680
- const s = this.readValue(e + 1), a = this.readValue(e + 1);
681
- n.set(s, a);
682
- }
683
- return n;
684
- }
685
- case Ne:
686
- return { tag: t.arg, value: this.readValue(e + 1) };
687
- case Be:
688
- if (t.arg === $e) return !1;
689
- if (t.arg === Me) return !0;
690
- if (t.arg === Ge) return null;
691
- throw new f(
692
- `unsupported simple/float value ${t.arg}`
693
- );
694
- default:
695
- throw new f(`unsupported major type ${t.major}`);
696
- }
697
- }
698
- }
699
- function se(r) {
700
- const e = new ne(r), t = e.readValue();
701
- if (e.pos !== r.length)
702
- throw new f("trailing bytes after top-level item");
703
- return t;
704
- }
705
- const Ke = "vaultd-jsonrpc", He = "vaultd-grpc", J = 18, M = 4, j = -47, Le = 1, W = 64, Ue = 128, De = 96, Xe = 64, Fe = 1, Je = 2, je = 3, We = 4, Ye = 5, ze = 6, Qe = 7, Y = new TextEncoder().encode("Signature1");
706
- class c extends Error {
707
- constructor(e, t) {
708
- super(e), this.reason = t, this.name = "CwtVerificationError";
709
- }
710
- }
711
- function Ze(r) {
712
- const e = z(
713
- r.expectedIssuerXOnlyPubkey,
714
- "expectedIssuerXOnlyPubkey"
715
- ), t = z(
716
- r.expectedAudienceXOnlyPubkey,
717
- "expectedAudienceXOnlyPubkey"
718
- ), n = nt(r.ephemeralPubkeyHex), i = it(r.token), s = new ne(i), a = s.readHead();
719
- if (a.major !== 6 || a.arg !== J)
720
- throw new c(
721
- `token is not a COSE Sign1 tagged value (tag ${J})`,
722
- "invalid_token_structure"
723
- );
724
- const o = s.readHead();
725
- if (o.major !== 4 || o.arg !== M)
726
- throw new c(
727
- `COSE Sign1 must be a ${M}-element array`,
728
- "invalid_token_structure"
729
- );
730
- const u = s.pos, d = s.readByteString(), p = i.subarray(u, s.pos);
731
- s.readValue();
732
- const y = s.pos, w = s.readByteString(), T = i.subarray(y, s.pos), I = s.readByteString();
733
- if (I.length !== W)
734
- throw new c(
735
- `COSE signature must be ${W} bytes, got ${I.length}`,
736
- "invalid_token_structure"
737
- );
738
- if (s.pos !== i.length)
739
- throw new c(
740
- "COSE Sign1 token has trailing bytes after the signature",
741
- "invalid_token_structure"
742
- );
743
- const G = qe(d);
744
- if (G !== j)
745
- throw new c(
746
- `unexpected COSE algorithm ${G} (expected ES256K ${j})`,
747
- "unexpected_algorithm"
748
- );
749
- const ae = et(p, T), oe = be(ae);
750
- if (!q.verify(oe, n, I, !0))
751
- throw new c(
752
- "COSE signature does not verify against the server's ephemeral key",
753
- "signature_verification_failed"
754
- );
755
- const l = tt(w), x = l.audience.toLowerCase();
756
- if (x.length !== C || !b.test(x))
757
- throw new c(
758
- "token `aud` is not a 32-byte x-only pubkey hex",
759
- "invalid_claims"
760
- );
761
- if (l.issuedAt > l.expiresAt)
762
- throw new c(
763
- `token iat (${l.issuedAt}) is after exp (${l.expiresAt})`,
764
- "invalid_claims"
765
- );
766
- if (l.issuer.toLowerCase() !== e)
767
- throw new c(
768
- `token issuer does not match pinned server pubkey: expected ${e}, got ${l.issuer.toLowerCase()}`,
769
- "issuer_mismatch"
770
- );
771
- if (l.subject !== r.expectedSubject)
772
- throw new c(
773
- `token subject mismatch: expected ${r.expectedSubject}, got ${l.subject}`,
774
- "subject_mismatch"
775
- );
776
- if (x !== t)
777
- throw new c(
778
- `token audience does not match depositor pubkey: expected ${t}, got ${x}`,
779
- "audience_mismatch"
780
- );
781
- if (l.expiresAt <= r.now)
782
- throw new c(
783
- `token expired: exp ${l.expiresAt} <= now ${r.now}`,
784
- "token_expired"
785
- );
786
- if (r.responseExpiresAt !== l.expiresAt)
787
- throw new c(
788
- `response expires_at (${r.responseExpiresAt}) does not equal token exp (${l.expiresAt})`,
789
- "expiry_mismatch"
790
- );
791
- if (r.serverIdentityExpiresAt < l.expiresAt)
792
- throw new c(
793
- `server identity expires (${r.serverIdentityExpiresAt}) before token exp (${l.expiresAt})`,
794
- "server_identity_expires_before_token"
795
- );
796
- return {
797
- issuer: l.issuer,
798
- subject: l.subject,
799
- audience: x,
800
- expiresAt: l.expiresAt,
801
- notBefore: l.notBefore,
802
- issuedAt: l.issuedAt
803
- };
804
- }
805
- function qe(r) {
806
- if (r.length === 0)
807
- throw new c(
808
- "empty COSE protected header (no algorithm)",
809
- "unexpected_algorithm"
810
- );
811
- const e = se(r);
812
- if (!(e instanceof Map))
813
- throw new c(
814
- "COSE protected header is not a map",
815
- "invalid_token_structure"
816
- );
817
- const t = e.get(Le);
818
- if (typeof t != "number")
819
- throw new c(
820
- "COSE protected header missing integer algorithm label",
821
- "unexpected_algorithm"
822
- );
823
- return t;
824
- }
825
- function et(r, e) {
826
- return at(
827
- Uint8Array.of(Ue | M),
828
- Uint8Array.of(De | Y.length),
829
- Y,
830
- r,
831
- Uint8Array.of(Xe),
832
- e
833
- );
834
- }
835
- function tt(r) {
836
- const e = se(r);
837
- if (!(e instanceof Map))
838
- throw new c(
839
- "CWT claims root is not a map",
840
- "invalid_claims"
841
- );
842
- if (rt(e, Qe, "cti").length === 0)
843
- throw new c("token cti is empty", "invalid_claims");
844
- return {
845
- issuer: N(e, Fe, "iss"),
846
- subject: N(e, Je, "sub"),
847
- audience: N(e, je, "aud"),
848
- expiresAt: B(e, We, "exp"),
849
- notBefore: B(e, Ye, "nbf"),
850
- issuedAt: B(e, ze, "iat")
851
- };
852
- }
853
- function N(r, e, t) {
854
- const n = r.get(e);
855
- if (typeof n != "string")
856
- throw new c(
857
- `token claim ${t} is missing or not a text string`,
858
- "invalid_claims"
859
- );
860
- return n;
861
- }
862
- function rt(r, e, t) {
863
- const n = r.get(e);
864
- if (!(n instanceof Uint8Array))
865
- throw new c(
866
- `token claim ${t} is missing or not a byte string`,
867
- "invalid_claims"
868
- );
869
- return n;
870
- }
871
- function B(r, e, t) {
872
- const n = r.get(e);
873
- if (typeof n != "number" || !Number.isSafeInteger(n) || n < 0)
874
- throw new c(
875
- `token claim ${t} is missing or not a non-negative integer timestamp`,
876
- "invalid_claims"
877
- );
878
- return n;
879
- }
880
- function z(r, e) {
881
- const t = A(r).toLowerCase();
882
- if (t.length !== C || !b.test(t))
883
- throw new c(
884
- `${e} must be 32-byte x-only hex; got ${t.length} chars`,
885
- "invalid_input"
886
- );
887
- return t;
888
- }
889
- function nt(r) {
890
- const e = A(r).toLowerCase(), t = e.slice(0, 2);
891
- if (e.length !== ee || !b.test(e) || t !== "02" && t !== "03")
892
- throw new c(
893
- "ephemeralPubkeyHex must be 33-byte compressed pubkey hex (prefix 02/03)",
894
- "invalid_input"
895
- );
896
- return me(e);
897
- }
898
- const st = (() => {
899
- const r = new Int16Array(128).fill(-1), e = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_";
900
- for (let t = 0; t < e.length; t++)
901
- r[e.charCodeAt(t)] = t;
902
- return r;
903
- })();
904
- function it(r) {
905
- const e = r.length, t = Math.floor(e / 4), n = e % 4;
906
- if (n === 1)
907
- throw new c(
908
- "invalid base64url length",
909
- "invalid_token_structure"
910
- );
911
- const i = t * 3 + (n === 0 ? 0 : n - 1), s = new Uint8Array(i), a = (d) => {
912
- const p = d < 128 ? st[d] : -1;
913
- if (p < 0)
914
- throw new c(
915
- "invalid base64url character",
916
- "invalid_token_structure"
917
- );
918
- return p;
919
- };
920
- let o = 0, u = 0;
921
- for (let d = 0; d < t; d++) {
922
- const p = a(r.charCodeAt(o++)), y = a(r.charCodeAt(o++)), w = a(r.charCodeAt(o++)), T = a(r.charCodeAt(o++));
923
- s[u++] = p << 2 | y >> 4, s[u++] = (y & 15) << 4 | w >> 2, s[u++] = (w & 3) << 6 | T;
924
- }
925
- if (n === 2) {
926
- const d = a(r.charCodeAt(o++)), p = a(r.charCodeAt(o++));
927
- s[u++] = d << 2 | p >> 4;
928
- } else if (n === 3) {
929
- const d = a(r.charCodeAt(o++)), p = a(r.charCodeAt(o++)), y = a(r.charCodeAt(o++));
930
- s[u++] = d << 2 | p >> 4, s[u++] = (p & 15) << 4 | y >> 2;
931
- }
932
- return s;
933
- }
934
- function at(...r) {
935
- const e = r.reduce((i, s) => i + s.length, 0), t = new Uint8Array(e);
936
- let n = 0;
937
- for (const i of r)
938
- t.set(i, n), n += i.length;
939
- return t;
940
- }
941
- const Q = 4102444800, ot = 30;
942
- class ct {
943
- constructor(e) {
944
- // `client` is the only mutable field — see `setClient`. The
945
- // identity-bearing fields (peginTxid/authAnchorHex/pinnedServerPubkey)
946
- // remain readonly and are checked against re-registration in the
947
- // registry's `getOrCreate`.
948
- h(this, "client");
949
- h(this, "peginTxid");
950
- h(this, "authAnchorHex");
951
- h(this, "pinnedServerPubkey");
952
- h(this, "expectedAudienceXOnlyPubkey");
953
- h(this, "authGatedMethods");
954
- h(this, "grpcGatedMethods");
955
- h(this, "refreshSkewSecs");
956
- h(this, "now");
957
- /** Cached JSON-RPC-subject bearer (auth_createDepositorToken). */
958
- h(this, "cachedJsonRpc", null);
959
- h(this, "inFlightJsonRpc", null);
960
- /** Cached gRPC-subject bearer (auth_createDepositorTokenGrpc). */
961
- h(this, "cachedGrpc", null);
962
- h(this, "inFlightGrpc", null);
963
- this.client = e.client, this.peginTxid = e.peginTxid, this.authAnchorHex = e.authAnchorHex, this.pinnedServerPubkey = e.pinnedServerPubkey, this.expectedAudienceXOnlyPubkey = e.expectedAudienceXOnlyPubkey, this.authGatedMethods = e.authGatedMethods, this.grpcGatedMethods = e.grpcGatedMethods, this.refreshSkewSecs = e.refreshSkewSecs ?? ot, this.now = e.now ?? (() => Math.floor(Date.now() / 1e3));
964
- }
965
- /**
966
- * Return a bearer token for `method`, or `null` if `method` is not
967
- * auth-gated.
968
- *
969
- * Routes by subject: `authGatedMethods` → JSON-RPC bearer (issued via
970
- * `auth_createDepositorToken`); `grpcGatedMethods` → gRPC bearer
971
- * (`auth_createDepositorTokenGrpc`). Either path acquires lazily and
972
- * single-flights concurrent callers; the two cache slots are
973
- * independent.
974
- *
975
- * Both token-issuing methods are hard-exempted from the gate — if
976
- * either were ever included in the gated sets (caller misconfiguration)
977
- * the provider would recurse into `acquireSingleFlight` from inside the
978
- * JSON-RPC header builder before `inFlight` is assigned, defeating the
979
- * single-flight guard. Returning `null` here breaks that recursion
980
- * deterministically.
981
- */
982
- async getToken(e) {
983
- return e === V || e === $ ? null : this.grpcGatedMethods.has(e) ? this.getTokenForSubject("grpc") : this.authGatedMethods.has(e) ? this.getTokenForSubject("jsonrpc") : null;
984
- }
985
- /**
986
- * Drop both cached tokens. Next `getToken` call re-acquires the slot
987
- * that's actually needed. Called by `JsonRpcClient` on wire
988
- * `auth_expired` responses; the client doesn't tell us which subject
989
- * expired, so we evict both to stay correct under either.
990
- *
991
- * Worst case is one extra round-trip on the slot that was still fresh,
992
- * which is cheaper than carrying a `Subject` argument through
993
- * `BearerTokenProvider`.
994
- */
995
- invalidate() {
996
- this.cachedJsonRpc = null, this.cachedGrpc = null;
997
- }
998
- async getTokenForSubject(e) {
999
- const t = e === "grpc" ? this.cachedGrpc : this.cachedJsonRpc;
1000
- return t && this.now() + this.refreshSkewSecs < t.expiresAt ? t.token : (await this.acquireSingleFlight(e)).token;
1001
- }
1002
- /**
1003
- * Swap in a different transport for subsequent token-issuing calls.
1004
- * Used by the registry when a later caller registers the same
1005
- * `peginTxid` against a different `baseUrl` — the cached token
1006
- * (bound to identity, not transport) stays valid, but future
1007
- * refreshes hit the new URL. An in-flight acquire keeps using the
1008
- * old client (it captured the reference); next call uses the new.
1009
- */
1010
- setClient(e) {
1011
- this.client = e;
1012
- }
1013
- acquireSingleFlight(e) {
1014
- const t = e === "grpc" ? this.inFlightGrpc : this.inFlightJsonRpc;
1015
- if (t) return t;
1016
- const n = e === "grpc" ? $ : V, i = (async () => {
1017
- try {
1018
- const s = await this.client.call(n, {
1019
- pegin_txid: this.peginTxid,
1020
- auth_anchor: this.authAnchorHex
1021
- });
1022
- if (Pe({
1023
- proof: s.server_identity,
1024
- pinnedServerPubkey: this.pinnedServerPubkey,
1025
- now: this.now()
1026
- }), typeof s.token != "string" || s.token.length === 0)
1027
- throw new Error(
1028
- `VpTokenProvider: invalid token in acquire response (expected non-empty string, got ${typeof s.token})`
1029
- );
1030
- const a = this.now();
1031
- if (!Number.isSafeInteger(s.expires_at) || s.expires_at <= a || s.expires_at > Q)
1032
- throw new Error(
1033
- `VpTokenProvider: invalid expires_at in acquire response (got ${JSON.stringify(s.expires_at)}; must be a safe integer in (${a}, ${Q}])`
1034
- );
1035
- Ze({
1036
- token: s.token,
1037
- ephemeralPubkeyHex: s.server_identity.ephemeral_pubkey,
1038
- expectedIssuerXOnlyPubkey: this.pinnedServerPubkey,
1039
- expectedSubject: e === "grpc" ? He : Ke,
1040
- expectedAudienceXOnlyPubkey: this.expectedAudienceXOnlyPubkey,
1041
- responseExpiresAt: s.expires_at,
1042
- serverIdentityExpiresAt: s.server_identity.expires_at,
1043
- now: a
1044
- });
1045
- const o = {
1046
- token: s.token,
1047
- expiresAt: s.expires_at
1048
- };
1049
- return e === "grpc" ? this.cachedGrpc = o : this.cachedJsonRpc = o, o;
1050
- } finally {
1051
- e === "grpc" ? this.inFlightGrpc = null : this.inFlightJsonRpc = null;
1052
- }
1053
- })();
1054
- return e === "grpc" ? this.inFlightGrpc = i : this.inFlightJsonRpc = i, i;
1055
- }
1056
- }
1057
- class lt {
1058
- constructor() {
1059
- h(this, "entries", /* @__PURE__ */ new Map());
1060
- }
1061
- /**
1062
- * Return the cached `VpTokenProvider` for `peginTxid` if one exists
1063
- * with matching `authAnchorHex` and `pinnedServerPubkey`, otherwise
1064
- * construct and cache a fresh provider. A mismatch on either throws —
1065
- * silent overwrite would mask derivation drift or VP pubkey rotation.
1066
- */
1067
- getOrCreate(e) {
1068
- const t = this.entries.get(e.peginTxid);
1069
- if (t) {
1070
- if (t.authAnchorHex !== e.authAnchorHex)
1071
- throw new Error(
1072
- `VpTokenRegistry: peginTxid ${e.peginTxid} already bound to authAnchorHex ${t.authAnchorHex.slice(0, 8)}…; got ${e.authAnchorHex.slice(0, 8)}…`
1073
- );
1074
- if (t.pinnedServerPubkey !== e.pinnedServerPubkey)
1075
- throw new Error(
1076
- `VpTokenRegistry: peginTxid ${e.peginTxid} already bound to pinnedServerPubkey ${t.pinnedServerPubkey.slice(0, 8)}…; got ${e.pinnedServerPubkey.slice(0, 8)}…`
1077
- );
1078
- if (t.expectedAudienceXOnlyPubkey !== e.expectedAudienceXOnlyPubkey)
1079
- throw new Error(
1080
- `VpTokenRegistry: peginTxid ${e.peginTxid} already bound to expectedAudienceXOnlyPubkey ${t.expectedAudienceXOnlyPubkey.slice(0, 8)}…; got ${e.expectedAudienceXOnlyPubkey.slice(0, 8)}…`
1081
- );
1082
- return t.provider.setClient(e.client), t.provider;
1083
- }
1084
- const n = new ct({
1085
- client: e.client,
1086
- peginTxid: e.peginTxid,
1087
- authAnchorHex: e.authAnchorHex,
1088
- pinnedServerPubkey: e.pinnedServerPubkey,
1089
- expectedAudienceXOnlyPubkey: e.expectedAudienceXOnlyPubkey,
1090
- authGatedMethods: Ee,
1091
- grpcGatedMethods: Ce
1092
- });
1093
- return this.entries.set(e.peginTxid, {
1094
- provider: n,
1095
- authAnchorHex: e.authAnchorHex,
1096
- pinnedServerPubkey: e.pinnedServerPubkey,
1097
- expectedAudienceXOnlyPubkey: e.expectedAudienceXOnlyPubkey
1098
- }), n;
1099
- }
1100
- /** Return the cached provider, or `undefined` if none. */
1101
- peek(e) {
1102
- var t;
1103
- return (t = this.entries.get(e)) == null ? void 0 : t.provider;
1104
- }
1105
- /**
1106
- * Evict the entry for `peginTxid`. Idempotent. Called on terminal
1107
- * paths — activation success, user-cancel, or component unmount —
1108
- * so `authAnchorHex` doesn't outlive the deposit session.
1109
- */
1110
- release(e) {
1111
- this.entries.delete(e);
1112
- }
1113
- /**
1114
- * Wipe every cached entry. Test-only escape hatch — not exposed on
1115
- * the public {@link VpTokenRegistryPublic} singleton type.
1116
- *
1117
- * @internal
1118
- */
1119
- clear() {
1120
- this.entries.clear();
1121
- }
1122
- get size() {
1123
- return this.entries.size;
1124
- }
1125
- }
1126
- const ie = new lt();
1127
- function Pt(r) {
1128
- var n;
1129
- const e = re(
1130
- r.baseUrl,
1131
- (n = r.options) == null ? void 0 : n.headers
1132
- ), t = ie.getOrCreate({
1133
- client: e,
1134
- peginTxid: r.peginTxid,
1135
- authAnchorHex: r.authAnchorHex,
1136
- pinnedServerPubkey: r.pinnedServerPubkey,
1137
- expectedAudienceXOnlyPubkey: Z(
1138
- r.depositorBtcPubkey
1139
- )
1140
- });
1141
- return new fe(r.baseUrl, {
1142
- ...r.options,
1143
- tokenProvider: t
1144
- });
1145
- }
1146
- function Et(r) {
1147
- ie.getOrCreate({
1148
- client: re(r.baseUrl, r.headers),
1149
- peginTxid: r.peginTxid,
1150
- authAnchorHex: r.authAnchorHex,
1151
- pinnedServerPubkey: r.pinnedServerPubkey,
1152
- expectedAudienceXOnlyPubkey: Z(
1153
- r.depositorBtcPubkey
1154
- )
1155
- });
1156
- }
1157
- export {
1158
- _e as O,
1159
- m as S,
1160
- lt as V,
1161
- ie as a,
1162
- _t as b,
1163
- Pt as c,
1164
- wt as d,
1165
- vt as e,
1166
- xt as f,
1167
- Et as p,
1168
- At as r,
1169
- Pe as v
1170
- };
1171
- //# sourceMappingURL=primeVpAuth-BI63kgdd.js.map