@babylonlabs-io/ts-sdk 0.72.1 → 0.73.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 (154) 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 +209 -205
  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 +1 -0
  87. package/dist/tbv/core/index.d.ts.map +1 -1
  88. package/dist/tbv/core/index.js +207 -203
  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/services/index.cjs +1 -1
  97. package/dist/tbv/core/services/index.js +2 -2
  98. package/dist/tbv/core/utils/eth/index.cjs +2 -0
  99. package/dist/tbv/core/utils/eth/index.cjs.map +1 -0
  100. package/dist/tbv/core/utils/eth/index.js +109 -0
  101. package/dist/tbv/core/utils/eth/index.js.map +1 -0
  102. package/dist/tbv/core/utils/index.cjs +1 -1
  103. package/dist/tbv/core/utils/index.js +41 -40
  104. package/dist/tbv/core/utils/index.js.map +1 -1
  105. package/dist/tbv/core/vault-secrets/index.cjs +1 -1
  106. package/dist/tbv/core/vault-secrets/index.js +1 -1
  107. package/dist/tbv/index.cjs +1 -1
  108. package/dist/tbv/index.js +207 -203
  109. package/dist/tbv/index.js.map +1 -1
  110. package/dist/testing/index.cjs +1 -1
  111. package/dist/testing/index.js +1 -1
  112. package/dist/{toRefundInputs-BG-qHCEu.js → toRefundInputs-BkcFhvDp.js} +5 -5
  113. package/dist/{toRefundInputs-BG-qHCEu.js.map → toRefundInputs-BkcFhvDp.js.map} +1 -1
  114. package/dist/{toRefundInputs-kVR-3EdD.cjs → toRefundInputs-CatCKniS.cjs} +2 -2
  115. package/dist/{toRefundInputs-kVR-3EdD.cjs.map → toRefundInputs-CatCKniS.cjs.map} +1 -1
  116. package/dist/types-CPDLZm3l.js +430 -0
  117. package/dist/types-CPDLZm3l.js.map +1 -0
  118. package/dist/types-DSlcXtog.cjs +2 -0
  119. package/dist/types-DSlcXtog.cjs.map +1 -0
  120. package/package.json +32 -3
  121. package/dist/BTCVaultRegistryKeyEpochs.abi-CXjhRZbm.js +0 -111
  122. package/dist/BTCVaultRegistryKeyEpochs.abi-CXjhRZbm.js.map +0 -1
  123. package/dist/BTCVaultRegistryKeyEpochs.abi-_NERAdc5.cjs +0 -2
  124. package/dist/BTCVaultRegistryKeyEpochs.abi-_NERAdc5.cjs.map +0 -1
  125. package/dist/PeginManager-Bwjqb0_6.cjs +0 -2
  126. package/dist/PeginManager-Bwjqb0_6.cjs.map +0 -1
  127. package/dist/PeginManager-DjatPUPS.js +0 -1503
  128. package/dist/PeginManager-DjatPUPS.js.map +0 -1
  129. package/dist/ProtocolParams.abi-C0TSRaHV.js +0 -486
  130. package/dist/ProtocolParams.abi-C0TSRaHV.js.map +0 -1
  131. package/dist/ProtocolParams.abi-CYZoV2EI.cjs +0 -2
  132. package/dist/ProtocolParams.abi-CYZoV2EI.cjs.map +0 -1
  133. package/dist/errors-Blc-JWnI.js +0 -121
  134. package/dist/errors-Blc-JWnI.js.map +0 -1
  135. package/dist/errors-CGcNP0rV.cjs +0 -2
  136. package/dist/errors-CGcNP0rV.cjs.map +0 -1
  137. package/dist/mempoolApi-BJvC9nPF.cjs +0 -2
  138. package/dist/mempoolApi-BJvC9nPF.cjs.map +0 -1
  139. package/dist/mempoolApi-_CoQH5vH.js +0 -612
  140. package/dist/mempoolApi-_CoQH5vH.js.map +0 -1
  141. package/dist/onChainBtcPubkey-B5ZvWCCF.cjs +0 -2
  142. package/dist/onChainBtcPubkey-B5ZvWCCF.cjs.map +0 -1
  143. package/dist/onChainBtcPubkey-DATNfAAl.js +0 -19
  144. package/dist/onChainBtcPubkey-DATNfAAl.js.map +0 -1
  145. package/dist/primeVpAuth-BI63kgdd.js +0 -1171
  146. package/dist/primeVpAuth-BI63kgdd.js.map +0 -1
  147. package/dist/primeVpAuth-D3xbar3j.cjs +0 -2
  148. package/dist/primeVpAuth-D3xbar3j.cjs.map +0 -1
  149. package/dist/sha2-BYVxyZzX.js +0 -274
  150. package/dist/sha2-DsrLC4NM.cjs +0 -2
  151. package/dist/waitForTransactionReceiptSmartAware-DpQ69ySe.cjs +0 -2
  152. package/dist/waitForTransactionReceiptSmartAware-DpQ69ySe.cjs.map +0 -1
  153. package/dist/waitForTransactionReceiptSmartAware-z3Xfmo44.js +0 -277
  154. package/dist/waitForTransactionReceiptSmartAware-z3Xfmo44.js.map +0 -1
@@ -1,612 +0,0 @@
1
- import * as p from "@bitcoin-js/tiny-secp256k1-asmjs";
2
- import { Transaction as u, payments as E, script as T } from "bitcoinjs-lib";
3
- import { s as y } from "./sha2-BYVxyZzX.js";
4
- import { Buffer as c } from "buffer";
5
- import { B as a } from "./BTCVaultRegistry.abi-CJwWI2EO.js";
6
- import { B as A } from "./BTCVaultRegistryKeyEpochs.abi-CXjhRZbm.js";
7
- import { a as V } from "./onChainBtcPubkey-DATNfAAl.js";
8
- import { a as G } from "./vaultCoreVersion-D_fP9P3C.js";
9
- import { c as L } from "./abortSignals-BPpAUL1Z.js";
10
- import { B as W, H as Q, K as j, T as z } from "./validation-OSC0xTHB.js";
11
- const Y = "BIP0322-signed-message", Z = "TapTweak", k = 32, q = 64, J = 33, tt = 71, et = 72, g = 0, C = 0, v = 0, S = 0, ot = 32, nt = 4294967295, rt = 0, it = 0, st = 32, at = 106;
12
- function R(t, e) {
13
- const o = new TextEncoder().encode(t), n = y(o), i = new Uint8Array(n.length * 2 + e.length);
14
- return i.set(n, 0), i.set(n, n.length), i.set(e, n.length * 2), y(i);
15
- }
16
- function ct(t) {
17
- if (t.length !== k) return null;
18
- const e = R(Z, t), o = p.xOnlyPointAddTweak(t, e);
19
- return o ? o.xOnlyPubkey : null;
20
- }
21
- function H(t, e) {
22
- const o = R(Y, t), n = new u();
23
- n.version = C, n.locktime = v;
24
- const i = c.concat([
25
- c.from([it, st]),
26
- c.from(o)
27
- ]);
28
- n.addInput(
29
- c.alloc(ot, 0),
30
- nt,
31
- S,
32
- i
33
- ), n.addOutput(e, g);
34
- const r = new u();
35
- return r.version = C, r.locktime = v, r.addInput(
36
- n.getHash(),
37
- rt,
38
- S
39
- ), r.addOutput(c.from([at]), g), r;
40
- }
41
- function Vt(t, e, o, n = u.SIGHASH_DEFAULT) {
42
- if (e.length !== k || o.length !== q || n !== u.SIGHASH_DEFAULT && n !== u.SIGHASH_ALL)
43
- return !1;
44
- try {
45
- const i = E.p2tr({
46
- internalPubkey: c.from(e)
47
- });
48
- if (!i.output) return !1;
49
- const r = i.output, h = H(t, r).hashForWitnessV1(
50
- 0,
51
- [r],
52
- [g],
53
- n
54
- ), m = ct(e);
55
- return m ? p.verifySchnorr(h, m, o) : !1;
56
- } catch {
57
- return !1;
58
- }
59
- }
60
- function Ct(t, e, o) {
61
- if (e.length !== J || o.length < tt || o.length > et)
62
- return !1;
63
- try {
64
- if (!p.isPointCompressed(e)) return !1;
65
- const { signature: n, hashType: i } = T.signature.decode(
66
- c.from(o)
67
- );
68
- if (!T.signature.encode(n, i).equals(c.from(o)) || i !== u.SIGHASH_ALL) return !1;
69
- const r = E.p2wpkh({ pubkey: c.from(e) });
70
- if (!r.output || !r.hash) return !1;
71
- const s = H(t, r.output), h = E.p2pkh({ hash: r.hash }).output;
72
- if (!h) return !1;
73
- const m = s.hashForWitnessV0(0, h, g, i);
74
- return p.verify(m, e, n, !0);
75
- } catch {
76
- return !1;
77
- }
78
- }
79
- const w = 65535, _ = 1e4, d = 4294967295, B = 255;
80
- function ut(t) {
81
- if (!Number.isInteger(t) || t < 0 || t > d)
82
- throw new Error(
83
- `Invalid offchainParamsVersion from contract: must be a uint32, got ${t}`
84
- );
85
- }
86
- function lt(t) {
87
- const e = [];
88
- if (t.timelockAssert <= 0n && e.push(
89
- `timelockAssert must be positive, got ${t.timelockAssert}`
90
- ), t.timelockAssert > BigInt(w) && e.push(
91
- `timelockAssert ${t.timelockAssert} exceeds uint16 max (${w})`
92
- ), t.timelockChallengeAssert <= 0n && e.push(
93
- `timelockChallengeAssert must be positive, got ${t.timelockChallengeAssert}`
94
- ), t.tRefund <= 0 && e.push(`tRefund must be positive, got ${t.tRefund}`), t.tStale <= 0 && e.push(`tStale must be positive, got ${t.tStale}`), t.securityCouncilKeys.length === 0 && e.push("securityCouncilKeys must not be empty"), t.councilQuorum <= 0 && e.push(`councilQuorum must be positive, got ${t.councilQuorum}`), t.councilQuorum > t.securityCouncilKeys.length && e.push(
95
- `councilQuorum (${t.councilQuorum}) exceeds securityCouncilKeys count (${t.securityCouncilKeys.length})`
96
- ), t.feeRate <= 0n && e.push(`feeRate must be positive, got ${t.feeRate}`), t.minPeginFeeRate <= 0n && e.push(
97
- `minPeginFeeRate must be positive, got ${t.minPeginFeeRate}`
98
- ), (!Number.isInteger(t.proverCircuitVersion) || t.proverCircuitVersion < 0 || t.proverCircuitVersion > w) && e.push(
99
- `proverCircuitVersion must be a uint16, got ${t.proverCircuitVersion}`
100
- ), (!Number.isInteger(t.minPrepeginDepth) || t.minPrepeginDepth <= 0 || t.minPrepeginDepth > d) && e.push(
101
- `minPrepeginDepth must be a uint32 in [1, ${d}], got ${t.minPrepeginDepth}`
102
- ), t.babeTotalInstances <= 0 && e.push(
103
- `babeTotalInstances must be positive, got ${t.babeTotalInstances}`
104
- ), t.babeInstancesToFinalize <= 0 && e.push(
105
- `babeInstancesToFinalize must be positive, got ${t.babeInstancesToFinalize}`
106
- ), t.babeInstancesToFinalize > t.babeTotalInstances && e.push(
107
- `babeInstancesToFinalize (${t.babeInstancesToFinalize}) exceeds babeTotalInstances (${t.babeTotalInstances})`
108
- ), (t.minVpCommissionBps < 0 || t.minVpCommissionBps > _) && e.push(
109
- `minVpCommissionBps must be in [0, ${_}], got ${t.minVpCommissionBps}`
110
- ), e.length > 0)
111
- throw new Error(
112
- `Invalid offchain protocol parameters: ${e.join("; ")}`
113
- );
114
- }
115
- function ft(t) {
116
- const e = [];
117
- if (t.minimumPegInAmount <= 0n && e.push(
118
- `minimumPegInAmount must be positive, got ${t.minimumPegInAmount}`
119
- ), t.maxPegInAmount < t.minimumPegInAmount && e.push(
120
- `maxPegInAmount (${t.maxPegInAmount}) must be >= minimumPegInAmount (${t.minimumPegInAmount})`
121
- ), t.pegInAckTimeout <= 0n && e.push(
122
- `pegInAckTimeout must be positive, got ${t.pegInAckTimeout}`
123
- ), t.pegInActivationTimeout <= 0n && e.push(
124
- `pegInActivationTimeout must be positive, got ${t.pegInActivationTimeout}`
125
- ), (!Number.isInteger(t.maxHtlcOutputCount) || t.maxHtlcOutputCount <= 0 || t.maxHtlcOutputCount > B) && e.push(
126
- `maxHtlcOutputCount must be an integer in [1, ${B}], got ${t.maxHtlcOutputCount}`
127
- ), (typeof t.expiredPegInGraceBlocks != "bigint" || t.expiredPegInGraceBlocks <= 0n) && e.push(
128
- `expiredPegInGraceBlocks must be a positive bigint, got ${t.expiredPegInGraceBlocks}`
129
- ), e.length > 0)
130
- throw new Error(`Invalid TBV protocol parameters: ${e.join("; ")}`);
131
- }
132
- function vt(t) {
133
- if (ft(t), lt(t.offchainParams), !Number.isInteger(t.offchainParamsVersion) || t.offchainParamsVersion < 0 || t.offchainParamsVersion > d)
134
- throw new Error(
135
- `Invalid peg-in configuration: offchainParamsVersion must be a uint32, got ${t.offchainParamsVersion}`
136
- );
137
- G(
138
- t.activeVaultCoreVersion,
139
- "ProtocolParams.activeVaultCoreVersion()"
140
- );
141
- }
142
- const F = 9999;
143
- function x(t) {
144
- return {
145
- depositor: t.depositor,
146
- depositorBtcPubKey: t.depositorBtcPubKey,
147
- amount: t.amount,
148
- vaultProvider: t.vaultProvider,
149
- status: t.status,
150
- applicationEntryPoint: t.applicationEntryPoint,
151
- createdAt: t.createdAt
152
- };
153
- }
154
- function I(t) {
155
- const e = Number(t.offchainParamsVersion);
156
- return ut(e), {
157
- depositorSignedPeginTx: t.depositorSignedPeginTx,
158
- universalChallengersVersion: t.universalChallengersVersion,
159
- appVaultKeepersVersion: t.appVaultKeepersVersion,
160
- offchainParamsVersion: e,
161
- verifiedAt: t.verifiedAt,
162
- depositorWotsPkHash: t.depositorWotsPkHash,
163
- hashlock: t.hashlock,
164
- htlcVout: t.htlcVout,
165
- depositorPopSignature: t.depositorPopSignature,
166
- prePeginTxHash: t.prePeginTxHash,
167
- vaultProviderCommissionBps: t.vaultProviderCommissionBps,
168
- vaultCoreVersion: t.vaultCoreVersion
169
- };
170
- }
171
- const ht = 1n << 64n, O = 0n;
172
- function b(t, e, o) {
173
- if (t < 0n || t >= ht)
174
- throw new Error(
175
- `getBtcVaultProtocolInfo returned ${e}=${t} for vault ${o}, outside the uint64 range — the registry may predate RFC-006`
176
- );
177
- return t;
178
- }
179
- function N(t, e) {
180
- return {
181
- vpKeyEpoch: b(t.vpKeyEpoch, "vpKeyEpoch", e),
182
- appKeeperKeyEpoch: b(
183
- t.appKeeperKeyEpoch,
184
- "appKeeperKeyEpoch",
185
- e
186
- ),
187
- ucKeyEpoch: b(t.ucKeyEpoch, "ucKeyEpoch", e)
188
- };
189
- }
190
- class St {
191
- constructor(e, o) {
192
- this.publicClient = e, this.contractAddress = o;
193
- }
194
- /**
195
- * Read the VP's **genesis** (registration) x-only BTC pubkey — the key bonded
196
- * at version 0, which never moves when the operator rotates.
197
- *
198
- * Resolved as "the operation key at epoch 0" rather than through the
199
- * dedicated `getVaultProviderBTCKey` getter, which
200
- * https://github.com/babylonlabs-io/vault-contracts-aave-v4/pull/539 removes.
201
- * Epoch 0 predates any rotation — appended versions are stamped at epoch 1 or
202
- * later — so it resolves to the registration key, and the contracts team has
203
- * confirmed that is a property we can rely on rather than an implementation
204
- * detail. The devnet comparison behind that claim — both getters returning the
205
- * identical key for a provider that *has* rotated, while
206
- * `getCurrentOperationBtcKey` differed — is recorded in
207
- * https://github.com/babylonlabs-io/babylon-toolkit/issues/2188.
208
- *
209
- * This makes the read RFC-006-only, where the removed getter also existed on a
210
- * legacy registry. That costs nothing: every caller of this method already
211
- * resolves participant keys through `OperationKeyReader`, so all of them
212
- * require an RFC-006 registry regardless.
213
- *
214
- * Validates length, hex form, and secp256k1 curve membership before minting
215
- * the brand. Returns 64-char lowercase hex without the `0x` prefix.
216
- */
217
- async getVaultProviderGenesisBtcPubKey(e, o) {
218
- const n = await this.publicClient.readContract({
219
- address: this.contractAddress,
220
- abi: a,
221
- functionName: "getOperationBtcKeyAtEpoch",
222
- args: [e, O],
223
- blockNumber: o
224
- });
225
- return V(
226
- n,
227
- `getOperationBtcKeyAtEpoch (vp=${e}, epoch=${O})`
228
- );
229
- }
230
- /**
231
- * Read a vault provider's *current* RFC-006 operation BTC key.
232
- *
233
- * Falls back on-chain to the registration key when the provider has never
234
- * rotated, so this returns the same value as
235
- * `getVaultProviderGenesisBtcPubKey` until the first rotation.
236
- *
237
- * This is the key the VP's server signs its BIP-322 auth tokens with — a
238
- * live per-operator identity, not a per-vault binding, so the auth pin uses
239
- * the current key rather than any vault's frozen epoch.
240
- */
241
- async getCurrentVaultProviderOperationBtcKey(e) {
242
- const o = await this.publicClient.readContract({
243
- address: this.contractAddress,
244
- abi: a,
245
- functionName: "getCurrentOperationBtcKey",
246
- args: [e]
247
- });
248
- return V(
249
- o,
250
- `getCurrentOperationBtcKey (vp=${e})`
251
- );
252
- }
253
- /**
254
- * Read a vault's frozen RFC-006 operation-key epochs.
255
- *
256
- * Reads `getBtcVaultProtocolInfo` through the **extended** ABI, which is only
257
- * valid against an RFC-006 registry: against one whose `BTCVaultProtocolInfo`
258
- * struct is not extended this call does not fail for a populated vault, it
259
- * silently returns three words of tail data as epochs. Nothing here can detect
260
- * that, so the guarantee is a deployment one — every network this ships to has
261
- * the RFC-006 getters, and mainnet is a fresh RFC-006 deploy.
262
- *
263
- * A registry missing the operation-key getters entirely is the *safer* of the
264
- * two cases: `resolveParticipantKeysAtEpochs` reverts downstream and these
265
- * epochs never reach key resolution. See {@link UINT64_EXCLUSIVE_UPPER_BOUND}
266
- * for which state the range check actually guards, and
267
- * `BTCVaultRegistryKeyEpochs.abi.ts` for the decode hazard.
268
- */
269
- async getVaultKeyEpochs(e) {
270
- const o = await this.publicClient.readContract({
271
- address: this.contractAddress,
272
- abi: A,
273
- functionName: "getBtcVaultProtocolInfo",
274
- args: [e]
275
- });
276
- return N(o, e);
277
- }
278
- async getVaultKeyEpochsBatch(e) {
279
- return e.length === 0 ? [] : (await this.publicClient.multicall({
280
- contracts: e.map((n) => ({
281
- address: this.contractAddress,
282
- abi: A,
283
- functionName: "getBtcVaultProtocolInfo",
284
- args: [n]
285
- })),
286
- allowFailure: !1
287
- })).map(
288
- (n, i) => N(n, e[i])
289
- );
290
- }
291
- async getVaultBasicInfo(e) {
292
- const o = await this.publicClient.readContract({
293
- address: this.contractAddress,
294
- abi: a,
295
- functionName: "getBtcVaultBasicInfo",
296
- args: [e]
297
- });
298
- return x(o);
299
- }
300
- async getVaultProtocolInfo(e) {
301
- const o = await this.publicClient.readContract({
302
- address: this.contractAddress,
303
- abi: a,
304
- functionName: "getBtcVaultProtocolInfo",
305
- args: [e]
306
- });
307
- return I(o);
308
- }
309
- async getProtocolInfoBatch(e) {
310
- return e.length === 0 ? [] : (await this.publicClient.multicall({
311
- contracts: e.map((n) => ({
312
- address: this.contractAddress,
313
- abi: a,
314
- functionName: "getBtcVaultProtocolInfo",
315
- args: [n]
316
- })),
317
- allowFailure: !1
318
- })).map((n, i) => {
319
- const r = n;
320
- if (!r.depositorSignedPeginTx || r.depositorSignedPeginTx === "0x")
321
- throw new Error(
322
- `Vault ${e[i]} not found on-chain or has no pegin transaction`
323
- );
324
- return I(r);
325
- });
326
- }
327
- /**
328
- * Read the protocol pegin fee (in wei) for a given vault provider.
329
- * Mirrors the `getPegInFee(address)` view on BTCVaultRegistry.
330
- */
331
- async getPegInFee(e) {
332
- return await this.publicClient.readContract({
333
- address: this.contractAddress,
334
- abi: a,
335
- functionName: "getPegInFee",
336
- args: [e]
337
- });
338
- }
339
- /**
340
- * Read a vault provider's current commission in basis points from
341
- * BTCVaultRegistry. The contract enforces `commissionBps < 10000`, so the
342
- * legitimate range is `[0, 9999]`; anything outside indicates a wrong
343
- * contract address or ABI drift and is surfaced as an error rather than
344
- * trusted.
345
- */
346
- async getVaultProviderCommission(e) {
347
- const o = await this.publicClient.readContract({
348
- address: this.contractAddress,
349
- abi: a,
350
- functionName: "getVaultProviderCommission",
351
- args: [e]
352
- });
353
- if (!Number.isInteger(o) || o < 0 || o > F)
354
- throw new Error(
355
- `getVaultProviderCommission returned ${o} bps for ${e}, outside the protocol range [0, ${F}]`
356
- );
357
- return o;
358
- }
359
- async getVaultData(e) {
360
- const [o, n] = await this.publicClient.multicall({
361
- contracts: [
362
- {
363
- address: this.contractAddress,
364
- abi: a,
365
- functionName: "getBtcVaultBasicInfo",
366
- args: [e]
367
- },
368
- {
369
- address: this.contractAddress,
370
- abi: a,
371
- functionName: "getBtcVaultProtocolInfo",
372
- args: [e]
373
- }
374
- ],
375
- allowFailure: !1
376
- }), i = x(o), r = I(n);
377
- if (!r.depositorSignedPeginTx || r.depositorSignedPeginTx === "0x")
378
- throw new Error(
379
- `Vault ${e} not found on-chain or has no pegin transaction`
380
- );
381
- return { basic: i, protocol: r };
382
- }
383
- }
384
- const mt = 21e6 * 1e8, K = 3e4;
385
- async function P(t, e) {
386
- const o = new AbortController(), n = setTimeout(
387
- () => o.abort(),
388
- K
389
- ), i = [o.signal, e == null ? void 0 : e.signal].filter(
390
- Boolean
391
- ), r = L(i);
392
- try {
393
- return await fetch(t, {
394
- ...e,
395
- signal: r.signal
396
- });
397
- } catch (s) {
398
- throw clearTimeout(n), r.cleanup(), s != null && typeof s == "object" && "name" in s && s.name === "AbortError" ? new Error(
399
- `Mempool API request timed out after ${K}ms: ${t}`
400
- ) : s;
401
- }
402
- }
403
- const U = 1e4;
404
- function M(t) {
405
- return Number.isInteger(t) && t > 0 && t <= mt;
406
- }
407
- function pt(t) {
408
- return Number.isInteger(t) && t > 0 && t <= U;
409
- }
410
- function $(t, e) {
411
- return !Number.isInteger(t) || t < 0 ? !1 : e === void 0 || t < e;
412
- }
413
- function f(t) {
414
- if (!z.test(t))
415
- throw new Error(`Invalid transaction ID format: ${t}`);
416
- }
417
- function X(t) {
418
- if (!W.test(t))
419
- throw new Error(`Invalid Bitcoin address format: ${t}`);
420
- }
421
- function D(t, e) {
422
- if (!Q.test(t))
423
- throw new Error(
424
- `Invalid scriptPubKey: not valid hex for ${e}`
425
- );
426
- if (!j.some(
427
- (n) => t.toLowerCase().startsWith(n)
428
- ))
429
- throw new Error(
430
- `Unrecognized scriptPubKey type for ${e}: prefix ${t.slice(0, 6)} does not match any known Bitcoin script type`
431
- );
432
- }
433
- const gt = {
434
- mainnet: "https://mempool.space/api",
435
- testnet: "https://mempool.space/testnet/api",
436
- signet: "https://mempool.space/signet/api"
437
- };
438
- async function l(t, e) {
439
- try {
440
- const o = await P(t, e);
441
- if (!o.ok) {
442
- const i = await o.text();
443
- throw new Error(
444
- `Mempool API error (${o.status}): ${i || o.statusText}`
445
- );
446
- }
447
- const n = o.headers.get("content-type");
448
- return n != null && n.includes("application/json") ? await o.json() : await o.text();
449
- } catch (o) {
450
- throw o instanceof Error ? new Error(`Failed to fetch from mempool API: ${o.message}`) : new Error("Failed to fetch from mempool API: Unknown error");
451
- }
452
- }
453
- async function _t(t, e) {
454
- try {
455
- const o = await P(`${e}/tx`, {
456
- method: "POST",
457
- body: t,
458
- headers: {
459
- "Content-Type": "text/plain"
460
- }
461
- });
462
- if (!o.ok) {
463
- const i = await o.text();
464
- let r;
465
- try {
466
- const s = JSON.parse(i);
467
- r = s.message ?? s.error;
468
- } catch {
469
- r = i;
470
- }
471
- throw new Error(
472
- r || `Failed to broadcast transaction: ${o.statusText}`
473
- );
474
- }
475
- return await o.text();
476
- } catch (o) {
477
- throw o instanceof Error ? new Error(`Failed to broadcast BTC transaction: ${o.message}`) : new Error("Failed to broadcast BTC transaction: Unknown error");
478
- }
479
- }
480
- async function dt(t, e) {
481
- return f(t), l(`${e}/tx/${t}`);
482
- }
483
- async function Bt(t) {
484
- const e = await l(`${t}/blocks/tip/height`), o = e.trim(), n = /^\d+$/.test(o) ? Number.parseInt(o, 10) : NaN;
485
- if (!Number.isSafeInteger(n) || n < 0)
486
- throw new Error(
487
- `Mempool API returned an invalid block tip height: "${e}"`
488
- );
489
- return n;
490
- }
491
- async function Ft(t, e, o) {
492
- if (f(t), !$(e))
493
- throw new Error(`Invalid vout ${e} for transaction ${t}`);
494
- return l(`${o}/tx/${t}/outspend/${e}`);
495
- }
496
- async function xt(t, e) {
497
- f(t);
498
- try {
499
- const o = await P(`${e}/tx/${t}/hex`);
500
- if (!o.ok) {
501
- const n = await o.text();
502
- throw new Error(
503
- `Mempool API error (${o.status}): ${n || o.statusText}`
504
- );
505
- }
506
- return await o.text();
507
- } catch (o) {
508
- throw o instanceof Error ? new Error(`Failed to get transaction hex for ${t}: ${o.message}`) : new Error(`Failed to get transaction hex for ${t}: Unknown error`);
509
- }
510
- }
511
- async function Ot(t, e, o) {
512
- f(t);
513
- const n = await dt(t, o);
514
- if (!$(e, n.vout.length))
515
- throw new Error(
516
- `Invalid vout ${e} for transaction ${t} (has ${n.vout.length} outputs)`
517
- );
518
- const i = n.vout[e];
519
- if (!M(i.value))
520
- throw new Error(`Invalid UTXO value ${i.value} for ${t}:${e}`);
521
- return D(i.scriptpubkey, `${t}:${e}`), {
522
- txid: t,
523
- vout: e,
524
- value: i.value,
525
- scriptPubKey: i.scriptpubkey
526
- };
527
- }
528
- async function Nt(t, e) {
529
- X(t);
530
- try {
531
- const o = await l(`${e}/address/${t}/utxo`), n = await l(`${e}/v1/validate-address/${t}`);
532
- if (!n.isvalid)
533
- throw new Error(
534
- `Invalid Bitcoin address: ${t}. Mempool API validation failed.`
535
- );
536
- D(n.scriptPubKey, t);
537
- for (const r of o) {
538
- if (f(r.txid), !$(r.vout))
539
- throw new Error(`Invalid vout ${r.vout} for ${r.txid}`);
540
- if (!M(r.value))
541
- throw new Error(
542
- `Invalid UTXO value ${r.value} for ${r.txid}:${r.vout}`
543
- );
544
- }
545
- return o.sort((r, s) => s.value - r.value).map((r) => ({
546
- txid: r.txid,
547
- vout: r.vout,
548
- value: r.value,
549
- scriptPubKey: n.scriptPubKey,
550
- confirmed: r.status.confirmed
551
- }));
552
- } catch (o) {
553
- throw o instanceof Error ? new Error(
554
- `Failed to get UTXOs for address ${t}: ${o.message}`
555
- ) : new Error(
556
- `Failed to get UTXOs for address ${t}: Unknown error`
557
- );
558
- }
559
- }
560
- function Kt(t) {
561
- return gt[t];
562
- }
563
- async function kt(t, e) {
564
- return X(t), l(`${e}/address/${t}/txs`);
565
- }
566
- async function Rt(t) {
567
- const e = await P(`${t}/v1/fees/recommended`);
568
- if (!e.ok)
569
- throw new Error(
570
- `Failed to fetch network fees: ${e.status} ${e.statusText}`
571
- );
572
- const o = await e.json(), n = [
573
- "fastestFee",
574
- "halfHourFee",
575
- "hourFee",
576
- "economyFee",
577
- "minimumFee"
578
- ];
579
- for (const i of n)
580
- if (!pt(o[i]))
581
- throw new Error(
582
- `Invalid fee rate ${i}=${o[i]} from mempool API: expected a positive number ≤ ${U}`
583
- );
584
- if (o.minimumFee > o.economyFee || o.economyFee > o.hourFee || o.hourFee > o.halfHourFee || o.halfHourFee > o.fastestFee)
585
- throw new Error(
586
- `Fee rate ordering violation from mempool API: expected minimumFee (${o.minimumFee}) <= economyFee (${o.economyFee}) <= hourFee (${o.hourFee}) <= halfHourFee (${o.halfHourFee}) <= fastestFee (${o.fastestFee}).`
587
- );
588
- return o;
589
- }
590
- export {
591
- gt as M,
592
- tt as P,
593
- St as V,
594
- Nt as a,
595
- Kt as b,
596
- Rt as c,
597
- Ft as d,
598
- Bt as e,
599
- xt as f,
600
- kt as g,
601
- dt as h,
602
- Ot as i,
603
- vt as j,
604
- ft as k,
605
- Vt as l,
606
- et as m,
607
- Ct as n,
608
- ut as o,
609
- _t as p,
610
- lt as v
611
- };
612
- //# sourceMappingURL=mempoolApi-_CoQH5vH.js.map