@babylonlabs-io/ts-sdk 0.33.4 → 0.33.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/buildAndBroadcastRefund-B332dykQ.cjs +2 -0
- package/dist/buildAndBroadcastRefund-B332dykQ.cjs.map +1 -0
- package/dist/{buildAndBroadcastRefund-D_QlvCsw.js → buildAndBroadcastRefund-CPjXNaMi.js} +126 -121
- package/dist/buildAndBroadcastRefund-CPjXNaMi.js.map +1 -0
- package/dist/index.cjs +1 -1
- package/dist/index.js +89 -87
- package/dist/tbv/core/clients/index.cjs +1 -1
- package/dist/tbv/core/clients/index.js +23 -21
- package/dist/tbv/core/clients/vault-provider/__tests__/batchAttribution.test.d.ts +2 -0
- package/dist/tbv/core/clients/vault-provider/__tests__/batchAttribution.test.d.ts.map +1 -0
- package/dist/tbv/core/clients/vault-provider/__tests__/batchPoll.test.d.ts +2 -0
- package/dist/tbv/core/clients/vault-provider/__tests__/batchPoll.test.d.ts.map +1 -0
- package/dist/tbv/core/clients/vault-provider/api.d.ts +13 -4
- package/dist/tbv/core/clients/vault-provider/api.d.ts.map +1 -1
- package/dist/tbv/core/clients/vault-provider/auth/serverIdentity.d.ts +12 -3
- package/dist/tbv/core/clients/vault-provider/auth/serverIdentity.d.ts.map +1 -1
- package/dist/tbv/core/clients/vault-provider/batchAttribution.d.ts +45 -0
- package/dist/tbv/core/clients/vault-provider/batchAttribution.d.ts.map +1 -0
- package/dist/tbv/core/clients/vault-provider/batchPoll.d.ts +55 -0
- package/dist/tbv/core/clients/vault-provider/batchPoll.d.ts.map +1 -0
- package/dist/tbv/core/clients/vault-provider/index.d.ts +2 -0
- package/dist/tbv/core/clients/vault-provider/index.d.ts.map +1 -1
- package/dist/tbv/core/clients/vault-provider/json-rpc-client.d.ts +3 -3
- package/dist/tbv/core/clients/vault-provider/json-rpc-client.d.ts.map +1 -1
- package/dist/tbv/core/clients/vault-provider/types.d.ts +68 -24
- package/dist/tbv/core/clients/vault-provider/types.d.ts.map +1 -1
- package/dist/tbv/core/clients/vault-provider/validators.d.ts +12 -2
- package/dist/tbv/core/clients/vault-provider/validators.d.ts.map +1 -1
- package/dist/tbv/core/index.cjs +1 -1
- package/dist/tbv/core/index.js +73 -71
- package/dist/tbv/core/services/deposit/waitForPeginStatus.d.ts.map +1 -1
- package/dist/tbv/core/services/index.cjs +1 -1
- package/dist/tbv/core/services/index.js +1 -1
- package/dist/tbv/core/services/pegout/state.d.ts +1 -1
- package/dist/tbv/index.cjs +1 -1
- package/dist/tbv/index.js +73 -71
- package/dist/types-DnyyBNcC.cjs +2 -0
- package/dist/types-DnyyBNcC.cjs.map +1 -0
- package/dist/{types-ByW6nSLj.js → types-TiIjyo2b.js} +32 -30
- package/dist/types-TiIjyo2b.js.map +1 -0
- package/dist/vault-registry-reader-DNiXOSYM.cjs +2 -0
- package/dist/vault-registry-reader-DNiXOSYM.cjs.map +1 -0
- package/dist/{vault-registry-reader-WiNVOsnD.js → vault-registry-reader-PsSxB0JZ.js} +439 -267
- package/dist/vault-registry-reader-PsSxB0JZ.js.map +1 -0
- package/package.json +1 -1
- package/dist/buildAndBroadcastRefund-CIPPpchL.cjs +0 -2
- package/dist/buildAndBroadcastRefund-CIPPpchL.cjs.map +0 -1
- package/dist/buildAndBroadcastRefund-D_QlvCsw.js.map +0 -1
- package/dist/types-ByW6nSLj.js.map +0 -1
- package/dist/types-CfCZyfid.cjs +0 -2
- package/dist/types-CfCZyfid.cjs.map +0 -1
- package/dist/vault-registry-reader-OK2V08tk.cjs +0 -2
- package/dist/vault-registry-reader-OK2V08tk.cjs.map +0 -1
- package/dist/vault-registry-reader-WiNVOsnD.js.map +0 -1
|
@@ -1,54 +1,54 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var
|
|
4
|
-
import { D as
|
|
5
|
-
import { X as
|
|
6
|
-
import { H as
|
|
7
|
-
import * as
|
|
8
|
-
import { payments as
|
|
9
|
-
import { Buffer as
|
|
10
|
-
import { s as
|
|
11
|
-
import { B as
|
|
12
|
-
import { P as
|
|
13
|
-
const
|
|
14
|
-
function
|
|
1
|
+
var ce = Object.defineProperty;
|
|
2
|
+
var le = (n, e, t) => e in n ? ce(n, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : n[e] = t;
|
|
3
|
+
var h = (n, e, t) => le(n, typeof e != "symbol" ? e + "" : e, t);
|
|
4
|
+
import { D as ue, J as Y, e as de } from "./types-TiIjyo2b.js";
|
|
5
|
+
import { X as B, C as K, s as C, S as pe, h as he } from "./bitcoin-B0S8SHCX.js";
|
|
6
|
+
import { H as S } from "./validation-CxqROCno.js";
|
|
7
|
+
import * as N from "@bitcoin-js/tiny-secp256k1-asmjs";
|
|
8
|
+
import { payments as ge, Transaction as O } from "bitcoinjs-lib";
|
|
9
|
+
import { Buffer as V } from "buffer";
|
|
10
|
+
import { s as F } from "./sha2-6wN58S6R.js";
|
|
11
|
+
import { B as k } from "./BTCVaultRegistry.abi-DbJ5lsFJ.js";
|
|
12
|
+
import { P as b, A as D } from "./ProtocolParams.abi-DXu8L0Fn.js";
|
|
13
|
+
const G = new Set(Object.values(ue)), fe = 200;
|
|
14
|
+
function c(n) {
|
|
15
15
|
var e;
|
|
16
|
-
return ((e = JSON.stringify(n)) == null ? void 0 : e.slice(0,
|
|
16
|
+
return ((e = JSON.stringify(n)) == null ? void 0 : e.slice(0, fe)) ?? "undefined";
|
|
17
17
|
}
|
|
18
|
-
const
|
|
18
|
+
const _e = "The vault provider returned an unexpected response. Please try again or contact support.";
|
|
19
19
|
class s extends Error {
|
|
20
20
|
constructor(t) {
|
|
21
|
-
super(
|
|
22
|
-
|
|
21
|
+
super(_e);
|
|
22
|
+
h(this, "detail");
|
|
23
23
|
this.name = "VpResponseValidationError", this.detail = t;
|
|
24
24
|
}
|
|
25
25
|
}
|
|
26
|
-
const
|
|
27
|
-
function
|
|
28
|
-
return typeof n == "string" && n.length > 0 &&
|
|
26
|
+
const A = 64;
|
|
27
|
+
function P(n) {
|
|
28
|
+
return typeof n == "string" && n.length > 0 && S.test(n);
|
|
29
29
|
}
|
|
30
|
-
function
|
|
30
|
+
function Z(n) {
|
|
31
31
|
return typeof n == "string" && n.length > 0;
|
|
32
32
|
}
|
|
33
|
-
function
|
|
34
|
-
if (!
|
|
33
|
+
function Q(n, e) {
|
|
34
|
+
if (!P(n))
|
|
35
35
|
throw new s(
|
|
36
|
-
`VP response validation failed: "${e}" must be a non-empty hex string, got ${
|
|
36
|
+
`VP response validation failed: "${e}" must be a non-empty hex string, got ${c(n)}`
|
|
37
37
|
);
|
|
38
38
|
}
|
|
39
|
-
function
|
|
40
|
-
if (!
|
|
39
|
+
function _(n, e) {
|
|
40
|
+
if (!Z(n))
|
|
41
41
|
throw new s(
|
|
42
|
-
`VP response validation failed: "${e}" must be a non-empty string, got ${
|
|
42
|
+
`VP response validation failed: "${e}" must be a non-empty string, got ${c(n)}`
|
|
43
43
|
);
|
|
44
44
|
}
|
|
45
|
-
function
|
|
46
|
-
if (!
|
|
45
|
+
function ee(n, e) {
|
|
46
|
+
if (!P(n) || n.length !== B && n.length !== K)
|
|
47
47
|
throw new s(
|
|
48
|
-
`VP response validation failed: "${e}" must be a ${
|
|
48
|
+
`VP response validation failed: "${e}" must be a ${B} or ${K}-char hex string (BTC pubkey), got ${c(n)}`
|
|
49
49
|
);
|
|
50
50
|
}
|
|
51
|
-
function
|
|
51
|
+
function me(n) {
|
|
52
52
|
const e = n.presigning;
|
|
53
53
|
if (e == null) return;
|
|
54
54
|
if (typeof e != "object" || Array.isArray(e))
|
|
@@ -58,49 +58,49 @@ function ae(n) {
|
|
|
58
58
|
const t = e;
|
|
59
59
|
if (t.depositor_graph_created !== void 0 && typeof t.depositor_graph_created != "boolean")
|
|
60
60
|
throw new s(
|
|
61
|
-
`VP response validation failed: "progress.presigning.depositor_graph_created" must be a boolean if present, got ${
|
|
61
|
+
`VP response validation failed: "progress.presigning.depositor_graph_created" must be a boolean if present, got ${c(t.depositor_graph_created)}`
|
|
62
62
|
);
|
|
63
63
|
if (t.vk_challenger_presigning_completed !== void 0 && typeof t.vk_challenger_presigning_completed != "number")
|
|
64
64
|
throw new s(
|
|
65
|
-
`VP response validation failed: "progress.presigning.vk_challenger_presigning_completed" must be a number if present, got ${
|
|
65
|
+
`VP response validation failed: "progress.presigning.vk_challenger_presigning_completed" must be a number if present, got ${c(t.vk_challenger_presigning_completed)}`
|
|
66
66
|
);
|
|
67
67
|
if (t.vk_challenger_presigning_total !== void 0 && typeof t.vk_challenger_presigning_total != "number")
|
|
68
68
|
throw new s(
|
|
69
|
-
`VP response validation failed: "progress.presigning.vk_challenger_presigning_total" must be a number if present, got ${
|
|
69
|
+
`VP response validation failed: "progress.presigning.vk_challenger_presigning_total" must be a number if present, got ${c(t.vk_challenger_presigning_total)}`
|
|
70
70
|
);
|
|
71
71
|
}
|
|
72
|
-
function
|
|
72
|
+
function te(n) {
|
|
73
73
|
if (n === null || typeof n != "object")
|
|
74
74
|
throw new s(
|
|
75
75
|
"VP response validation failed: getPeginStatus response is not an object"
|
|
76
76
|
);
|
|
77
77
|
const e = n;
|
|
78
|
-
if (!
|
|
78
|
+
if (!P(e.pegin_txid) || e.pegin_txid.length !== A)
|
|
79
79
|
throw new s(
|
|
80
|
-
`VP response validation failed: "pegin_txid" must be a ${
|
|
80
|
+
`VP response validation failed: "pegin_txid" must be a ${A}-char hex string (txid), got ${c(e.pegin_txid)}`
|
|
81
81
|
);
|
|
82
82
|
if (typeof e.status != "string")
|
|
83
83
|
throw new s(
|
|
84
84
|
'VP response validation failed: "status" must be a string'
|
|
85
85
|
);
|
|
86
|
-
if (!
|
|
86
|
+
if (!G.has(e.status))
|
|
87
87
|
throw new s(
|
|
88
|
-
`VP response validation failed: unrecognized status "${e.status}". Expected one of: ${[...
|
|
88
|
+
`VP response validation failed: unrecognized status "${e.status}". Expected one of: ${[...G].join(", ")}`
|
|
89
89
|
);
|
|
90
90
|
if (e.progress === null || typeof e.progress != "object" || Array.isArray(e.progress))
|
|
91
91
|
throw new s(
|
|
92
92
|
'VP response validation failed: "progress" must be an object'
|
|
93
93
|
);
|
|
94
|
-
if (
|
|
94
|
+
if (me(e.progress), typeof e.health_info != "string")
|
|
95
95
|
throw new s(
|
|
96
96
|
'VP response validation failed: "health_info" must be a string'
|
|
97
97
|
);
|
|
98
98
|
if (e.last_error !== void 0 && typeof e.last_error != "string")
|
|
99
99
|
throw new s(
|
|
100
|
-
`VP response validation failed: "last_error" must be a string if present, got ${
|
|
100
|
+
`VP response validation failed: "last_error" must be a string if present, got ${c(e.last_error)}`
|
|
101
101
|
);
|
|
102
102
|
}
|
|
103
|
-
function
|
|
103
|
+
function be(n) {
|
|
104
104
|
if (n === null || typeof n != "object")
|
|
105
105
|
throw new s(
|
|
106
106
|
"VP response validation failed: requestDepositorPresignTransactions response is not an object"
|
|
@@ -111,56 +111,56 @@ function ce(n) {
|
|
|
111
111
|
'VP response validation failed: "txs" must be an array'
|
|
112
112
|
);
|
|
113
113
|
for (let t = 0; t < e.txs.length; t++)
|
|
114
|
-
|
|
114
|
+
ye(e.txs[t], `txs[${t}]`);
|
|
115
115
|
if (e.depositor_graph === null || typeof e.depositor_graph != "object")
|
|
116
116
|
throw new s(
|
|
117
117
|
'VP response validation failed: "depositor_graph" must be an object'
|
|
118
118
|
);
|
|
119
|
-
|
|
119
|
+
$e(
|
|
120
120
|
e.depositor_graph
|
|
121
121
|
);
|
|
122
122
|
}
|
|
123
|
-
function
|
|
123
|
+
function y(n, e) {
|
|
124
124
|
if (n === null || typeof n != "object")
|
|
125
125
|
throw new s(
|
|
126
126
|
`VP response validation failed: "${e}" must be an object`
|
|
127
127
|
);
|
|
128
|
-
|
|
128
|
+
Q(n.tx_hex, `${e}.tx_hex`);
|
|
129
129
|
}
|
|
130
|
-
function
|
|
130
|
+
function ye(n, e) {
|
|
131
131
|
if (n === null || typeof n != "object")
|
|
132
132
|
throw new s(
|
|
133
133
|
`VP response validation failed: "${e}" must be an object`
|
|
134
134
|
);
|
|
135
135
|
const t = n;
|
|
136
|
-
|
|
136
|
+
ee(t.claimer_pubkey, `${e}.claimer_pubkey`), y(t.claim_tx, `${e}.claim_tx`), y(t.assert_tx, `${e}.assert_tx`), y(t.payout_tx, `${e}.payout_tx`), _(t.payout_psbt, `${e}.payout_psbt`);
|
|
137
137
|
}
|
|
138
|
-
function
|
|
138
|
+
function we(n, e) {
|
|
139
139
|
if (n === null || typeof n != "object")
|
|
140
140
|
throw new s(
|
|
141
141
|
`VP response validation failed: "${e}" must be an object`
|
|
142
142
|
);
|
|
143
143
|
const t = n;
|
|
144
|
-
|
|
144
|
+
_(t.wots_pks_json, `${e}.wots_pks_json`), _(t.gc_wots_keys_json, `${e}.gc_wots_keys_json`);
|
|
145
145
|
}
|
|
146
|
-
function
|
|
146
|
+
function Pe(n, e) {
|
|
147
147
|
if (n === null || typeof n != "object")
|
|
148
148
|
throw new s(
|
|
149
149
|
`VP response validation failed: "${e}" must be an object`
|
|
150
150
|
);
|
|
151
151
|
const t = n;
|
|
152
|
-
if (
|
|
152
|
+
if (ee(t.challenger_pubkey, `${e}.challenger_pubkey`), y(
|
|
153
153
|
t.challenge_assert_x_tx,
|
|
154
154
|
`${e}.challenge_assert_x_tx`
|
|
155
|
-
),
|
|
155
|
+
), y(
|
|
156
156
|
t.challenge_assert_y_tx,
|
|
157
157
|
`${e}.challenge_assert_y_tx`
|
|
158
|
-
),
|
|
158
|
+
), y(t.nopayout_tx, `${e}.nopayout_tx`), _(t.nopayout_psbt, `${e}.nopayout_psbt`), !Array.isArray(t.challenge_assert_connectors))
|
|
159
159
|
throw new s(
|
|
160
160
|
`VP response validation failed: "${e}.challenge_assert_connectors" must be an array`
|
|
161
161
|
);
|
|
162
162
|
for (let r = 0; r < t.challenge_assert_connectors.length; r++)
|
|
163
|
-
|
|
163
|
+
we(
|
|
164
164
|
t.challenge_assert_connectors[r],
|
|
165
165
|
`${e}.challenge_assert_connectors[${r}]`
|
|
166
166
|
);
|
|
@@ -169,24 +169,24 @@ function de(n, e) {
|
|
|
169
169
|
`VP response validation failed: "${e}.output_label_hashes" must be an array`
|
|
170
170
|
);
|
|
171
171
|
for (let r = 0; r < t.output_label_hashes.length; r++)
|
|
172
|
-
|
|
172
|
+
Q(
|
|
173
173
|
t.output_label_hashes[r],
|
|
174
174
|
`${e}.output_label_hashes[${r}]`
|
|
175
175
|
);
|
|
176
176
|
}
|
|
177
|
-
function
|
|
177
|
+
function xe(n) {
|
|
178
178
|
if (n === null || typeof n != "object")
|
|
179
179
|
throw new s(
|
|
180
180
|
"VP response validation failed: requestDepositorClaimerArtifacts response is not an object"
|
|
181
181
|
);
|
|
182
182
|
const e = n;
|
|
183
|
-
if (!
|
|
183
|
+
if (!Z(e.tx_graph_json))
|
|
184
184
|
throw new s(
|
|
185
|
-
`VP response validation failed: "tx_graph_json" must be a non-empty string, got ${
|
|
185
|
+
`VP response validation failed: "tx_graph_json" must be a non-empty string, got ${c(e.tx_graph_json)}`
|
|
186
186
|
);
|
|
187
|
-
if (!
|
|
187
|
+
if (!P(e.verifying_key_hex))
|
|
188
188
|
throw new s(
|
|
189
|
-
`VP response validation failed: "verifying_key_hex" must be a non-empty hex string, got ${
|
|
189
|
+
`VP response validation failed: "verifying_key_hex" must be a non-empty hex string, got ${c(e.verifying_key_hex)}`
|
|
190
190
|
);
|
|
191
191
|
if (e.babe_sessions === null || typeof e.babe_sessions != "object")
|
|
192
192
|
throw new s(
|
|
@@ -200,60 +200,138 @@ function pe(n) {
|
|
|
200
200
|
`VP response validation failed: "babe_sessions.${t}" must be an object`
|
|
201
201
|
);
|
|
202
202
|
const i = r;
|
|
203
|
-
if (!
|
|
203
|
+
if (!P(i.decryptor_artifacts_hex))
|
|
204
204
|
throw new s(
|
|
205
|
-
`VP response validation failed: "babe_sessions.${t}.decryptor_artifacts_hex" must be a non-empty hex string, got ${
|
|
205
|
+
`VP response validation failed: "babe_sessions.${t}.decryptor_artifacts_hex" must be a non-empty hex string, got ${c(i.decryptor_artifacts_hex)}`
|
|
206
206
|
);
|
|
207
207
|
}
|
|
208
208
|
}
|
|
209
|
-
function
|
|
209
|
+
function ve(n) {
|
|
210
210
|
if (n === null || typeof n != "object")
|
|
211
211
|
throw new s(
|
|
212
|
-
"VP response validation failed:
|
|
212
|
+
"VP response validation failed: pegout status payload is not an object"
|
|
213
213
|
);
|
|
214
214
|
const e = n;
|
|
215
|
-
if (!
|
|
215
|
+
if (!P(e.pegin_txid) || e.pegin_txid.length !== A)
|
|
216
216
|
throw new s(
|
|
217
|
-
`VP response validation failed: "pegin_txid" must be a ${
|
|
217
|
+
`VP response validation failed: "pegin_txid" must be a ${A}-char hex string (txid), got ${c(e.pegin_txid)}`
|
|
218
218
|
);
|
|
219
219
|
if (typeof e.found != "boolean")
|
|
220
220
|
throw new s(
|
|
221
|
-
`VP response validation failed: "found" must be a boolean, got ${
|
|
221
|
+
`VP response validation failed: "found" must be a boolean, got ${c(e.found)}`
|
|
222
222
|
);
|
|
223
|
-
if (e.claimer !==
|
|
224
|
-
if (
|
|
223
|
+
if (e.claimer !== null) {
|
|
224
|
+
if (typeof e.claimer != "object")
|
|
225
225
|
throw new s(
|
|
226
|
-
|
|
226
|
+
`VP response validation failed: "claimer" must be an object or null, got ${c(e.claimer)}`
|
|
227
227
|
);
|
|
228
|
-
|
|
229
|
-
|
|
228
|
+
Ve(e.claimer);
|
|
229
|
+
}
|
|
230
|
+
if (!Array.isArray(e.challengers))
|
|
231
|
+
throw new s(
|
|
232
|
+
`VP response validation failed: "challengers" must be an array, got ${c(e.challengers)}`
|
|
233
|
+
);
|
|
234
|
+
for (let t = 0; t < e.challengers.length; t++)
|
|
235
|
+
Ae(e.challengers[t], t);
|
|
236
|
+
}
|
|
237
|
+
function Ve(n) {
|
|
238
|
+
if (_(n.status, "claimer.status"), typeof n.failed != "boolean")
|
|
239
|
+
throw new s(
|
|
240
|
+
`VP response validation failed: "claimer.failed" must be a boolean, got ${c(n.failed)}`
|
|
241
|
+
);
|
|
242
|
+
if (_(n.claim_txid, "claimer.claim_txid"), _(n.claimer_pubkey, "claimer.claimer_pubkey"), _(n.assert_txid, "claimer.assert_txid"), n.challenger_pubkey !== null && typeof n.challenger_pubkey != "string")
|
|
243
|
+
throw new s(
|
|
244
|
+
`VP response validation failed: "claimer.challenger_pubkey" must be a string or null, got ${c(n.challenger_pubkey)}`
|
|
245
|
+
);
|
|
246
|
+
if (typeof n.created_at != "number")
|
|
247
|
+
throw new s(
|
|
248
|
+
`VP response validation failed: "claimer.created_at" must be a number, got ${c(n.created_at)}`
|
|
249
|
+
);
|
|
250
|
+
if (typeof n.updated_at != "number")
|
|
251
|
+
throw new s(
|
|
252
|
+
`VP response validation failed: "claimer.updated_at" must be a number, got ${c(n.updated_at)}`
|
|
253
|
+
);
|
|
254
|
+
}
|
|
255
|
+
function Ae(n, e) {
|
|
256
|
+
if (n === null || typeof n != "object")
|
|
257
|
+
throw new s(
|
|
258
|
+
`VP response validation failed: "challengers[${e}]" must be an object, got ${c(n)}`
|
|
259
|
+
);
|
|
260
|
+
const t = n;
|
|
261
|
+
if (_(t.status, `challengers[${e}].status`), _(t.claim_txid, `challengers[${e}].claim_txid`), _(t.claimer_pubkey, `challengers[${e}].claimer_pubkey`), E(t.assert_txid, `challengers[${e}].assert_txid`), E(
|
|
262
|
+
t.challenge_assert_x_txid,
|
|
263
|
+
`challengers[${e}].challenge_assert_x_txid`
|
|
264
|
+
), E(
|
|
265
|
+
t.challenge_assert_y_txid,
|
|
266
|
+
`challengers[${e}].challenge_assert_y_txid`
|
|
267
|
+
), E(t.nopayout_txid, `challengers[${e}].nopayout_txid`), typeof t.created_at != "number")
|
|
268
|
+
throw new s(
|
|
269
|
+
`VP response validation failed: "challengers[${e}].created_at" must be a number, got ${c(t.created_at)}`
|
|
270
|
+
);
|
|
271
|
+
if (typeof t.updated_at != "number")
|
|
272
|
+
throw new s(
|
|
273
|
+
`VP response validation failed: "challengers[${e}].updated_at" must be a number, got ${c(t.updated_at)}`
|
|
274
|
+
);
|
|
275
|
+
}
|
|
276
|
+
function E(n, e) {
|
|
277
|
+
if (n !== null && typeof n != "string")
|
|
278
|
+
throw new s(
|
|
279
|
+
`VP response validation failed: "${e}" must be a string or null, got ${c(n)}`
|
|
280
|
+
);
|
|
281
|
+
}
|
|
282
|
+
function Se(n) {
|
|
283
|
+
ne(n, "batchGetPeginStatus", (e) => {
|
|
284
|
+
e.result !== null && te(e.result);
|
|
285
|
+
});
|
|
286
|
+
}
|
|
287
|
+
function ke(n) {
|
|
288
|
+
ne(n, "batchGetPegoutStatus", (e) => {
|
|
289
|
+
e.result !== null && ve(e.result);
|
|
290
|
+
});
|
|
291
|
+
}
|
|
292
|
+
function ne(n, e, t) {
|
|
293
|
+
if (n === null || typeof n != "object")
|
|
294
|
+
throw new s(
|
|
295
|
+
`VP response validation failed: ${e} response is not an object`
|
|
296
|
+
);
|
|
297
|
+
const r = n;
|
|
298
|
+
if (!Array.isArray(r.results))
|
|
299
|
+
throw new s(
|
|
300
|
+
`VP response validation failed: "${e}.results" must be an array, got ${c(r.results)}`
|
|
301
|
+
);
|
|
302
|
+
for (let i = 0; i < r.results.length; i++) {
|
|
303
|
+
const a = r.results[i];
|
|
304
|
+
if (a === null || typeof a != "object")
|
|
230
305
|
throw new s(
|
|
231
|
-
`VP response validation failed: "
|
|
306
|
+
`VP response validation failed: "${e}.results[${i}]" must be an object, got ${c(a)}`
|
|
232
307
|
);
|
|
233
|
-
|
|
308
|
+
const o = a;
|
|
309
|
+
if (!P(o.pegin_txid) || o.pegin_txid.length !== A)
|
|
234
310
|
throw new s(
|
|
235
|
-
`VP response validation failed: "
|
|
311
|
+
`VP response validation failed: "${e}.results[${i}].pegin_txid" must be a ${A}-char hex string, got ${c(o.pegin_txid)}`
|
|
236
312
|
);
|
|
237
|
-
|
|
238
|
-
if (e.challenger !== void 0) {
|
|
239
|
-
if (e.challenger === null || typeof e.challenger != "object")
|
|
313
|
+
if (o.error !== null && typeof o.error != "string")
|
|
240
314
|
throw new s(
|
|
241
|
-
|
|
315
|
+
`VP response validation failed: "${e}.results[${i}].error" must be a string or null, got ${c(o.error)}`
|
|
242
316
|
);
|
|
243
|
-
|
|
244
|
-
if (typeof t.status != "string")
|
|
317
|
+
if (o.result === null && o.error === null)
|
|
245
318
|
throw new s(
|
|
246
|
-
`VP response validation failed: "
|
|
319
|
+
`VP response validation failed: "${e}.results[${i}]" has neither "result" nor "error" populated`
|
|
247
320
|
);
|
|
321
|
+
if (o.result !== null && o.error !== null)
|
|
322
|
+
throw new s(
|
|
323
|
+
`VP response validation failed: "${e}.results[${i}]" has both "result" and "error" populated`
|
|
324
|
+
);
|
|
325
|
+
t(o, i);
|
|
248
326
|
}
|
|
249
327
|
}
|
|
250
|
-
function
|
|
251
|
-
if (
|
|
328
|
+
function $e(n) {
|
|
329
|
+
if (y(n.claim_tx, "depositor_graph.claim_tx"), y(n.assert_tx, "depositor_graph.assert_tx"), y(n.payout_tx, "depositor_graph.payout_tx"), _(n.payout_psbt, "depositor_graph.payout_psbt"), !Array.isArray(n.challenger_presign_data))
|
|
252
330
|
throw new s(
|
|
253
331
|
'VP response validation failed: "depositor_graph.challenger_presign_data" must be an array'
|
|
254
332
|
);
|
|
255
333
|
for (let e = 0; e < n.challenger_presign_data.length; e++)
|
|
256
|
-
|
|
334
|
+
Pe(
|
|
257
335
|
n.challenger_presign_data[e],
|
|
258
336
|
`depositor_graph.challenger_presign_data[${e}]`
|
|
259
337
|
);
|
|
@@ -262,13 +340,13 @@ function ge(n) {
|
|
|
262
340
|
'VP response validation failed: "depositor_graph.offchain_params_version" must be a number'
|
|
263
341
|
);
|
|
264
342
|
}
|
|
265
|
-
const
|
|
266
|
-
class
|
|
343
|
+
const Te = 6e4;
|
|
344
|
+
class Ce {
|
|
267
345
|
constructor(e, t) {
|
|
268
|
-
|
|
346
|
+
h(this, "client");
|
|
269
347
|
const r = {
|
|
270
348
|
baseUrl: e,
|
|
271
|
-
timeout: (t == null ? void 0 : t.timeout) ??
|
|
349
|
+
timeout: (t == null ? void 0 : t.timeout) ?? Te,
|
|
272
350
|
retries: t == null ? void 0 : t.retries,
|
|
273
351
|
retryDelay: t == null ? void 0 : t.retryDelay,
|
|
274
352
|
retryableFor: t == null ? void 0 : t.retryableFor,
|
|
@@ -276,7 +354,7 @@ class me {
|
|
|
276
354
|
tokenProvider: t == null ? void 0 : t.tokenProvider,
|
|
277
355
|
maxResponseBytes: t == null ? void 0 : t.maxResponseBytes
|
|
278
356
|
};
|
|
279
|
-
this.client = new
|
|
357
|
+
this.client = new Y(r);
|
|
280
358
|
}
|
|
281
359
|
/**
|
|
282
360
|
* Request the payout/claim/assert transactions that the depositor
|
|
@@ -284,7 +362,7 @@ class me {
|
|
|
284
362
|
*/
|
|
285
363
|
async requestDepositorPresignTransactions(e, t) {
|
|
286
364
|
const r = await this.client.call("vaultProvider_requestDepositorPresignTransactions", e, t);
|
|
287
|
-
return
|
|
365
|
+
return be(r), r;
|
|
288
366
|
}
|
|
289
367
|
/**
|
|
290
368
|
* Submit the depositor's pre-signatures for the payout transactions
|
|
@@ -315,7 +393,7 @@ class me {
|
|
|
315
393
|
*/
|
|
316
394
|
async requestDepositorClaimerArtifacts(e, t) {
|
|
317
395
|
const r = await this.client.call("vaultProvider_requestDepositorClaimerArtifacts", e, t);
|
|
318
|
-
return
|
|
396
|
+
return xe(r), r;
|
|
319
397
|
}
|
|
320
398
|
/** Get the current pegin status from the vault provider daemon. */
|
|
321
399
|
async getPeginStatus(e, t) {
|
|
@@ -324,66 +402,149 @@ class me {
|
|
|
324
402
|
e,
|
|
325
403
|
t
|
|
326
404
|
);
|
|
327
|
-
return
|
|
405
|
+
return te(r), r;
|
|
328
406
|
}
|
|
329
|
-
/**
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
407
|
+
/**
|
|
408
|
+
* Get pegin status for many txids in one round trip. Per-result envelope
|
|
409
|
+
* isolates per-pegin failures from the overall RPC. Caller must chunk
|
|
410
|
+
* inputs at `VP_BATCH_MAX_SIZE`.
|
|
411
|
+
*/
|
|
412
|
+
async batchGetPeginStatus(e, t) {
|
|
413
|
+
const r = await this.client.call("vaultProvider_batchGetPeginStatus", e, t);
|
|
414
|
+
return Se(r), r;
|
|
415
|
+
}
|
|
416
|
+
/**
|
|
417
|
+
* Get pegout status for many txids in one round trip. Same per-result
|
|
418
|
+
* envelope semantics as `batchGetPeginStatus`.
|
|
419
|
+
*/
|
|
420
|
+
async batchGetPegoutStatus(e, t) {
|
|
421
|
+
const r = await this.client.call("vaultProvider_batchGetPegoutStatus", e, t);
|
|
422
|
+
return ke(r), r;
|
|
423
|
+
}
|
|
424
|
+
}
|
|
425
|
+
function Ee(n, e) {
|
|
426
|
+
const t = /* @__PURE__ */ new Set();
|
|
427
|
+
for (const d of n)
|
|
428
|
+
t.add(d.toLowerCase());
|
|
429
|
+
const r = /* @__PURE__ */ new Map(), i = /* @__PURE__ */ new Set(), a = [], o = [];
|
|
430
|
+
for (const d of e) {
|
|
431
|
+
const u = d.pegin_txid.toLowerCase();
|
|
432
|
+
if (!t.has(u)) {
|
|
433
|
+
o.push(u);
|
|
434
|
+
continue;
|
|
435
|
+
}
|
|
436
|
+
if (i.has(u)) {
|
|
437
|
+
a.push(u);
|
|
438
|
+
continue;
|
|
439
|
+
}
|
|
440
|
+
i.add(u), r.set(u, { result: d.result, error: d.error });
|
|
441
|
+
}
|
|
442
|
+
const l = [];
|
|
443
|
+
for (const d of t)
|
|
444
|
+
i.has(d) || l.push(d);
|
|
445
|
+
return { byTxid: r, missing: l, unexpected: o, duplicate: a };
|
|
446
|
+
}
|
|
447
|
+
async function tt(n) {
|
|
448
|
+
const {
|
|
449
|
+
items: e,
|
|
450
|
+
getTxid: t,
|
|
451
|
+
batchCall: r,
|
|
452
|
+
onItem: i,
|
|
453
|
+
onMissing: a,
|
|
454
|
+
onDuplicate: o,
|
|
455
|
+
onDuplicateBatch: l,
|
|
456
|
+
onWholeBatchError: d,
|
|
457
|
+
onUnexpected: u,
|
|
458
|
+
batchSize: f = de
|
|
459
|
+
} = n;
|
|
460
|
+
if (!Number.isInteger(f) || f <= 0)
|
|
461
|
+
throw new Error(
|
|
462
|
+
`batchPollByProvider: batchSize must be a positive integer, got ${f}`
|
|
335
463
|
);
|
|
336
|
-
|
|
464
|
+
for (let w = 0; w < e.length; w += f) {
|
|
465
|
+
const x = e.slice(w, w + f), $ = /* @__PURE__ */ new Map(), j = [];
|
|
466
|
+
for (const p of x) {
|
|
467
|
+
const m = t(p).toLowerCase();
|
|
468
|
+
$.set(m, p), j.push(m);
|
|
469
|
+
}
|
|
470
|
+
let v;
|
|
471
|
+
try {
|
|
472
|
+
const p = await r(j);
|
|
473
|
+
v = Ee(j, p.results);
|
|
474
|
+
} catch (p) {
|
|
475
|
+
d(x, p);
|
|
476
|
+
continue;
|
|
477
|
+
}
|
|
478
|
+
u && v.unexpected.length > 0 && u(v.unexpected);
|
|
479
|
+
const T = new Set(v.duplicate);
|
|
480
|
+
for (const p of T) {
|
|
481
|
+
const m = $.get(p);
|
|
482
|
+
m && o(m);
|
|
483
|
+
}
|
|
484
|
+
l && T.size > 0 && l(T.size);
|
|
485
|
+
for (const p of v.missing) {
|
|
486
|
+
const m = $.get(p);
|
|
487
|
+
m && a(m);
|
|
488
|
+
}
|
|
489
|
+
for (const [p, m] of v.byTxid) {
|
|
490
|
+
if (T.has(p)) continue;
|
|
491
|
+
const M = $.get(p);
|
|
492
|
+
M && i(M, {
|
|
493
|
+
pegin_txid: p,
|
|
494
|
+
result: m.result,
|
|
495
|
+
error: m.error
|
|
496
|
+
});
|
|
497
|
+
}
|
|
337
498
|
}
|
|
338
499
|
}
|
|
339
|
-
const
|
|
340
|
-
function
|
|
341
|
-
const t = new TextEncoder().encode(n), r =
|
|
342
|
-
return i.set(r, 0), i.set(r, r.length), i.set(e, r.length * 2),
|
|
500
|
+
const Ie = "BIP0322-signed-message", Be = "TapTweak", re = 32, Re = 64;
|
|
501
|
+
function se(n, e) {
|
|
502
|
+
const t = new TextEncoder().encode(n), r = F(t), i = new Uint8Array(r.length * 2 + e.length);
|
|
503
|
+
return i.set(r, 0), i.set(r, r.length), i.set(e, r.length * 2), F(i);
|
|
343
504
|
}
|
|
344
|
-
function
|
|
345
|
-
if (n.length !==
|
|
346
|
-
const e =
|
|
505
|
+
function He(n) {
|
|
506
|
+
if (n.length !== re) return null;
|
|
507
|
+
const e = se(Be, n), t = N.xOnlyPointAddTweak(n, e);
|
|
347
508
|
return t ? t.xOnlyPubkey : null;
|
|
348
509
|
}
|
|
349
|
-
function
|
|
350
|
-
if (e.length !==
|
|
510
|
+
function Ne(n, e, t) {
|
|
511
|
+
if (e.length !== re || t.length !== Re) return !1;
|
|
351
512
|
try {
|
|
352
|
-
const r =
|
|
353
|
-
internalPubkey:
|
|
513
|
+
const r = se(Ie, n), i = ge.p2tr({
|
|
514
|
+
internalPubkey: V.from(e)
|
|
354
515
|
});
|
|
355
516
|
if (!i.output) return !1;
|
|
356
|
-
const a = i.output,
|
|
357
|
-
|
|
358
|
-
const
|
|
359
|
-
|
|
360
|
-
|
|
517
|
+
const a = i.output, o = 0, l = new O();
|
|
518
|
+
l.version = 0, l.locktime = 0;
|
|
519
|
+
const d = V.concat([
|
|
520
|
+
V.from([0, 32]),
|
|
521
|
+
V.from(r)
|
|
361
522
|
]);
|
|
362
|
-
|
|
363
|
-
|
|
523
|
+
l.addInput(
|
|
524
|
+
V.alloc(32, 0),
|
|
364
525
|
// prev_txid = 0x0000...0000
|
|
365
526
|
4294967295,
|
|
366
527
|
// prev_vout = 0xFFFFFFFF
|
|
367
528
|
0,
|
|
368
529
|
// sequence = 0
|
|
369
|
-
|
|
370
|
-
),
|
|
371
|
-
const
|
|
372
|
-
|
|
373
|
-
const
|
|
374
|
-
|
|
375
|
-
const
|
|
530
|
+
d
|
|
531
|
+
), l.addOutput(a, o);
|
|
532
|
+
const u = new O();
|
|
533
|
+
u.version = 0, u.locktime = 0;
|
|
534
|
+
const f = l.getHash();
|
|
535
|
+
u.addInput(f, 0, 0), u.addOutput(V.from([106]), o);
|
|
536
|
+
const w = u.hashForWitnessV1(
|
|
376
537
|
0,
|
|
377
538
|
[a],
|
|
378
|
-
[
|
|
379
|
-
|
|
380
|
-
),
|
|
381
|
-
return
|
|
539
|
+
[o],
|
|
540
|
+
O.SIGHASH_DEFAULT
|
|
541
|
+
), x = He(e);
|
|
542
|
+
return x ? N.verifySchnorr(w, x, t) : !1;
|
|
382
543
|
} catch {
|
|
383
544
|
return !1;
|
|
384
545
|
}
|
|
385
546
|
}
|
|
386
|
-
function
|
|
547
|
+
function R(n, e) {
|
|
387
548
|
const t = (n & 7) << 5, r = typeof e == "bigint" ? e : BigInt(e);
|
|
388
549
|
if (r < 0n) throw new Error("cborHead: negative argument");
|
|
389
550
|
if (r < 24n) return new Uint8Array([t | Number(r)]);
|
|
@@ -408,139 +569,149 @@ function A(n, e) {
|
|
|
408
569
|
i[1 + a] = Number(r >> BigInt((7 - a) * 8)) & 255;
|
|
409
570
|
return i;
|
|
410
571
|
}
|
|
411
|
-
function
|
|
572
|
+
function ie(...n) {
|
|
412
573
|
const e = n.reduce((i, a) => i + a.length, 0), t = new Uint8Array(e);
|
|
413
574
|
let r = 0;
|
|
414
575
|
for (const i of n)
|
|
415
576
|
t.set(i, r), r += i.length;
|
|
416
577
|
return t;
|
|
417
578
|
}
|
|
418
|
-
function
|
|
419
|
-
const t = [
|
|
579
|
+
function X(n) {
|
|
580
|
+
const t = [R(4, n.length)];
|
|
420
581
|
for (const r of n)
|
|
421
|
-
t.push(
|
|
422
|
-
return
|
|
582
|
+
t.push(R(0, r));
|
|
583
|
+
return ie(...t);
|
|
423
584
|
}
|
|
424
|
-
function
|
|
585
|
+
function je(n, e, t) {
|
|
425
586
|
if (!Number.isSafeInteger(t) || t < 0)
|
|
426
587
|
throw new Error(
|
|
427
588
|
`encodeServerIdentityPayload: expires_at must be a non-negative safe integer, got ${t}`
|
|
428
589
|
);
|
|
429
|
-
const r =
|
|
430
|
-
return
|
|
590
|
+
const r = R(4, 3), i = X(n), a = X(e), o = R(0, t);
|
|
591
|
+
return ie(r, i, a, o);
|
|
431
592
|
}
|
|
432
|
-
const
|
|
593
|
+
const Oe = new TextEncoder().encode(
|
|
433
594
|
"btc-auth.server-identity.v1"
|
|
434
|
-
);
|
|
435
|
-
class
|
|
595
|
+
), De = 2 * 3600;
|
|
596
|
+
class g extends Error {
|
|
436
597
|
constructor(e, t) {
|
|
437
598
|
super(e), this.reason = t, this.name = "ServerIdentityError";
|
|
438
599
|
}
|
|
439
600
|
}
|
|
440
|
-
function
|
|
601
|
+
function I(n) {
|
|
441
602
|
const e = new Uint8Array(n.length / 2);
|
|
442
603
|
for (let t = 0; t < e.length; t++)
|
|
443
604
|
e[t] = parseInt(n.slice(t * 2, t * 2 + 2), 16);
|
|
444
605
|
return e;
|
|
445
606
|
}
|
|
446
|
-
function
|
|
447
|
-
const { proof: e, pinnedServerPubkey: t, now: r } = n, i =
|
|
448
|
-
if (
|
|
449
|
-
throw new
|
|
450
|
-
`pinnedServerPubkey must be 32-byte hex; got ${
|
|
607
|
+
function Ue(n) {
|
|
608
|
+
const { proof: e, pinnedServerPubkey: t, now: r } = n, i = n.maxLifetimeSecs ?? De, a = C(t).toLowerCase();
|
|
609
|
+
if (a.length !== B || !S.test(a))
|
|
610
|
+
throw new g(
|
|
611
|
+
`pinnedServerPubkey must be 32-byte hex; got ${a.length} chars`,
|
|
451
612
|
"invalid_pubkey_encoding"
|
|
452
613
|
);
|
|
453
|
-
const
|
|
454
|
-
if (
|
|
455
|
-
throw new
|
|
456
|
-
`server_pubkey must be 32-byte hex; got ${
|
|
614
|
+
const o = C(e.server_pubkey).toLowerCase();
|
|
615
|
+
if (o.length !== B || !S.test(o))
|
|
616
|
+
throw new g(
|
|
617
|
+
`server_pubkey must be 32-byte hex; got ${o.length} chars`,
|
|
457
618
|
"invalid_pubkey_encoding"
|
|
458
619
|
);
|
|
459
|
-
if (
|
|
460
|
-
throw new
|
|
461
|
-
`server_pubkey does not match pinned value: expected ${
|
|
620
|
+
if (o !== a)
|
|
621
|
+
throw new g(
|
|
622
|
+
`server_pubkey does not match pinned value: expected ${a}, got ${o}`,
|
|
462
623
|
"pinned_pubkey_mismatch"
|
|
463
624
|
);
|
|
464
625
|
if (!Number.isSafeInteger(e.expires_at))
|
|
465
|
-
throw new
|
|
626
|
+
throw new g(
|
|
466
627
|
`expires_at must be a finite integer; got ${JSON.stringify(e.expires_at)}`,
|
|
467
628
|
"invalid_expires_at"
|
|
468
629
|
);
|
|
469
630
|
if (!Number.isSafeInteger(r))
|
|
470
|
-
throw new
|
|
631
|
+
throw new g(
|
|
471
632
|
`now must be a finite integer; got ${JSON.stringify(r)}`,
|
|
472
633
|
"invalid_expires_at"
|
|
473
634
|
);
|
|
474
635
|
if (e.expires_at <= r)
|
|
475
|
-
throw new
|
|
636
|
+
throw new g(
|
|
476
637
|
`server identity proof expired at ${e.expires_at}, now ${r}`,
|
|
477
638
|
"expired"
|
|
478
639
|
);
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
640
|
+
if (!Number.isSafeInteger(i) || i <= 0)
|
|
641
|
+
throw new g(
|
|
642
|
+
`maxLifetimeSecs must be a positive safe integer; got ${JSON.stringify(i)}`,
|
|
643
|
+
"invalid_max_lifetime"
|
|
644
|
+
);
|
|
645
|
+
if (e.expires_at - r > i)
|
|
646
|
+
throw new g(
|
|
647
|
+
`server identity proof expires too far in the future: expires_at=${e.expires_at}, now=${r}, max lifetime=${i}s`,
|
|
648
|
+
"expires_too_far"
|
|
649
|
+
);
|
|
650
|
+
const l = C(e.ephemeral_pubkey).toLowerCase();
|
|
651
|
+
if (l.length !== K || !S.test(l))
|
|
652
|
+
throw new g(
|
|
482
653
|
`ephemeral_pubkey must be 33-byte compressed hex; got ${l.length} chars`,
|
|
483
654
|
"invalid_ephemeral_pubkey"
|
|
484
655
|
);
|
|
485
|
-
const
|
|
486
|
-
if (
|
|
487
|
-
throw new
|
|
488
|
-
`ephemeral_pubkey must be compressed (prefix 02/03); got ${
|
|
656
|
+
const d = l.slice(0, 2);
|
|
657
|
+
if (d !== "02" && d !== "03")
|
|
658
|
+
throw new g(
|
|
659
|
+
`ephemeral_pubkey must be compressed (prefix 02/03); got ${d}`,
|
|
489
660
|
"invalid_ephemeral_pubkey"
|
|
490
661
|
);
|
|
491
|
-
const
|
|
492
|
-
if (!
|
|
493
|
-
throw new
|
|
662
|
+
const u = I(l);
|
|
663
|
+
if (!N.isPoint(u))
|
|
664
|
+
throw new g(
|
|
494
665
|
"ephemeral_pubkey is not a valid secp256k1 point",
|
|
495
666
|
"invalid_ephemeral_pubkey"
|
|
496
667
|
);
|
|
497
|
-
const
|
|
498
|
-
if (
|
|
499
|
-
throw new
|
|
500
|
-
`signature must be 64-byte Schnorr hex; got ${
|
|
668
|
+
const f = C(e.signature).toLowerCase();
|
|
669
|
+
if (f.length !== pe || !S.test(f))
|
|
670
|
+
throw new g(
|
|
671
|
+
`signature must be 64-byte Schnorr hex; got ${f.length} chars`,
|
|
501
672
|
"invalid_signature_encoding"
|
|
502
673
|
);
|
|
503
|
-
const
|
|
504
|
-
|
|
505
|
-
|
|
674
|
+
const w = je(
|
|
675
|
+
Oe,
|
|
676
|
+
I(l),
|
|
506
677
|
e.expires_at
|
|
507
678
|
);
|
|
508
|
-
if (!
|
|
509
|
-
throw new
|
|
679
|
+
if (!Ne(w, I(o), I(f)))
|
|
680
|
+
throw new g(
|
|
510
681
|
"BIP-322 signature verification failed — ephemeral key is not attested by pinned server pubkey",
|
|
511
682
|
"signature_verification_failed"
|
|
512
683
|
);
|
|
513
684
|
}
|
|
514
|
-
const
|
|
685
|
+
const Ke = /* @__PURE__ */ new Set([
|
|
515
686
|
"vaultProvider_submitDepositorWotsKey",
|
|
516
687
|
"vaultProvider_submitDepositorPresignatures",
|
|
517
688
|
"vaultProvider_requestDepositorPresignTransactions"
|
|
518
|
-
]),
|
|
519
|
-
function
|
|
520
|
-
return new
|
|
689
|
+
]), Le = 6e4, L = "auth_createDepositorToken";
|
|
690
|
+
function ae(n, e) {
|
|
691
|
+
return new Y({
|
|
521
692
|
baseUrl: n,
|
|
522
|
-
timeout:
|
|
693
|
+
timeout: Le,
|
|
523
694
|
headers: e,
|
|
524
|
-
retryableFor: (t) => t ===
|
|
695
|
+
retryableFor: (t) => t === L
|
|
525
696
|
});
|
|
526
697
|
}
|
|
527
|
-
const
|
|
528
|
-
class
|
|
698
|
+
const q = 4102444800, Me = 30;
|
|
699
|
+
class Fe {
|
|
529
700
|
constructor(e) {
|
|
530
701
|
// `client` is the only mutable field — see `setClient`. The
|
|
531
702
|
// identity-bearing fields (peginTxid/authAnchorHex/pinnedServerPubkey)
|
|
532
703
|
// remain readonly and are checked against re-registration in the
|
|
533
704
|
// registry's `getOrCreate`.
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
this.client = e.client, this.peginTxid = e.peginTxid, this.authAnchorHex = e.authAnchorHex, this.pinnedServerPubkey = e.pinnedServerPubkey, this.authGatedMethods = e.authGatedMethods, this.refreshSkewSecs = e.refreshSkewSecs ??
|
|
705
|
+
h(this, "client");
|
|
706
|
+
h(this, "peginTxid");
|
|
707
|
+
h(this, "authAnchorHex");
|
|
708
|
+
h(this, "pinnedServerPubkey");
|
|
709
|
+
h(this, "authGatedMethods");
|
|
710
|
+
h(this, "refreshSkewSecs");
|
|
711
|
+
h(this, "now");
|
|
712
|
+
h(this, "cached", null);
|
|
713
|
+
h(this, "inFlight", null);
|
|
714
|
+
this.client = e.client, this.peginTxid = e.peginTxid, this.authAnchorHex = e.authAnchorHex, this.pinnedServerPubkey = e.pinnedServerPubkey, this.authGatedMethods = e.authGatedMethods, this.refreshSkewSecs = e.refreshSkewSecs ?? Me, this.now = e.now ?? (() => Math.floor(Date.now() / 1e3));
|
|
544
715
|
}
|
|
545
716
|
/**
|
|
546
717
|
* Return a bearer token for `method`, or `null` if `method` is not
|
|
@@ -555,7 +726,7 @@ class Te {
|
|
|
555
726
|
* guard. Returning `null` here breaks that recursion deterministically.
|
|
556
727
|
*/
|
|
557
728
|
async getToken(e) {
|
|
558
|
-
if (e ===
|
|
729
|
+
if (e === L || !this.authGatedMethods.has(e)) return null;
|
|
559
730
|
const t = this.cached;
|
|
560
731
|
return t && this.now() + this.refreshSkewSecs < t.expiresAt ? t.token : (await this.acquireSingleFlight()).token;
|
|
561
732
|
}
|
|
@@ -582,11 +753,11 @@ class Te {
|
|
|
582
753
|
if (e) return e;
|
|
583
754
|
const t = (async () => {
|
|
584
755
|
try {
|
|
585
|
-
const r = await this.client.call(
|
|
756
|
+
const r = await this.client.call(L, {
|
|
586
757
|
pegin_txid: this.peginTxid,
|
|
587
758
|
auth_anchor: this.authAnchorHex
|
|
588
759
|
});
|
|
589
|
-
if (
|
|
760
|
+
if (Ue({
|
|
590
761
|
proof: r.server_identity,
|
|
591
762
|
pinnedServerPubkey: this.pinnedServerPubkey,
|
|
592
763
|
now: this.now()
|
|
@@ -595,9 +766,9 @@ class Te {
|
|
|
595
766
|
`VpTokenProvider: invalid token in acquire response (expected non-empty string, got ${typeof r.token})`
|
|
596
767
|
);
|
|
597
768
|
const i = this.now();
|
|
598
|
-
if (!Number.isSafeInteger(r.expires_at) || r.expires_at <= i || r.expires_at >
|
|
769
|
+
if (!Number.isSafeInteger(r.expires_at) || r.expires_at <= i || r.expires_at > q)
|
|
599
770
|
throw new Error(
|
|
600
|
-
`VpTokenProvider: invalid expires_at in acquire response (got ${JSON.stringify(r.expires_at)}; must be a safe integer in (${i}, ${
|
|
771
|
+
`VpTokenProvider: invalid expires_at in acquire response (got ${JSON.stringify(r.expires_at)}; must be a safe integer in (${i}, ${q}])`
|
|
601
772
|
);
|
|
602
773
|
const a = {
|
|
603
774
|
token: r.token,
|
|
@@ -611,9 +782,9 @@ class Te {
|
|
|
611
782
|
return this.inFlight = t, t;
|
|
612
783
|
}
|
|
613
784
|
}
|
|
614
|
-
class
|
|
785
|
+
class Ge {
|
|
615
786
|
constructor() {
|
|
616
|
-
|
|
787
|
+
h(this, "entries", /* @__PURE__ */ new Map());
|
|
617
788
|
}
|
|
618
789
|
/**
|
|
619
790
|
* Return the cached `VpTokenProvider` for `peginTxid` if one exists
|
|
@@ -635,12 +806,12 @@ class Ce {
|
|
|
635
806
|
);
|
|
636
807
|
return t.provider.setClient(e.client), t.provider;
|
|
637
808
|
}
|
|
638
|
-
const r = new
|
|
809
|
+
const r = new Fe({
|
|
639
810
|
client: e.client,
|
|
640
811
|
peginTxid: e.peginTxid,
|
|
641
812
|
authAnchorHex: e.authAnchorHex,
|
|
642
813
|
pinnedServerPubkey: e.pinnedServerPubkey,
|
|
643
|
-
authGatedMethods:
|
|
814
|
+
authGatedMethods: Ke
|
|
644
815
|
});
|
|
645
816
|
return this.entries.set(e.peginTxid, {
|
|
646
817
|
provider: r,
|
|
@@ -674,42 +845,42 @@ class Ce {
|
|
|
674
845
|
return this.entries.size;
|
|
675
846
|
}
|
|
676
847
|
}
|
|
677
|
-
const
|
|
678
|
-
function
|
|
848
|
+
const oe = new Ge();
|
|
849
|
+
function nt(n) {
|
|
679
850
|
var r;
|
|
680
|
-
const e =
|
|
851
|
+
const e = ae(
|
|
681
852
|
n.baseUrl,
|
|
682
853
|
(r = n.options) == null ? void 0 : r.headers
|
|
683
|
-
), t =
|
|
854
|
+
), t = oe.getOrCreate({
|
|
684
855
|
client: e,
|
|
685
856
|
peginTxid: n.peginTxid,
|
|
686
857
|
authAnchorHex: n.authAnchorHex,
|
|
687
858
|
pinnedServerPubkey: n.pinnedServerPubkey
|
|
688
859
|
});
|
|
689
|
-
return new
|
|
860
|
+
return new Ce(n.baseUrl, {
|
|
690
861
|
...n.options,
|
|
691
862
|
tokenProvider: t
|
|
692
863
|
});
|
|
693
864
|
}
|
|
694
|
-
function
|
|
695
|
-
|
|
696
|
-
client:
|
|
865
|
+
function rt(n) {
|
|
866
|
+
oe.getOrCreate({
|
|
867
|
+
client: ae(n.baseUrl, n.headers),
|
|
697
868
|
peginTxid: n.peginTxid,
|
|
698
869
|
authAnchorHex: n.authAnchorHex,
|
|
699
870
|
pinnedServerPubkey: n.pinnedServerPubkey
|
|
700
871
|
});
|
|
701
872
|
}
|
|
702
|
-
async function
|
|
873
|
+
async function st(n, e) {
|
|
703
874
|
const [t, r] = await n.multicall({
|
|
704
875
|
contracts: [
|
|
705
876
|
{
|
|
706
877
|
address: e,
|
|
707
|
-
abi:
|
|
878
|
+
abi: k,
|
|
708
879
|
functionName: "protocolParams"
|
|
709
880
|
},
|
|
710
881
|
{
|
|
711
882
|
address: e,
|
|
712
|
-
abi:
|
|
883
|
+
abi: k,
|
|
713
884
|
functionName: "applicationRegistry"
|
|
714
885
|
}
|
|
715
886
|
],
|
|
@@ -720,8 +891,8 @@ async function Ke(n, e) {
|
|
|
720
891
|
applicationRegistry: r
|
|
721
892
|
};
|
|
722
893
|
}
|
|
723
|
-
const
|
|
724
|
-
function
|
|
894
|
+
const W = 65535;
|
|
895
|
+
function U(n) {
|
|
725
896
|
return {
|
|
726
897
|
timelockAssert: n.timelockAssert,
|
|
727
898
|
timelockChallengeAssert: n.timelockChallengeAssert,
|
|
@@ -738,7 +909,7 @@ function E(n) {
|
|
|
738
909
|
minPrepeginDepth: n.minPrepeginDepth
|
|
739
910
|
};
|
|
740
911
|
}
|
|
741
|
-
function
|
|
912
|
+
function z(n) {
|
|
742
913
|
return {
|
|
743
914
|
minimumPegInAmount: n.minimumPegInAmount,
|
|
744
915
|
maxPegInAmount: n.maxPegInAmount,
|
|
@@ -747,52 +918,52 @@ function K(n) {
|
|
|
747
918
|
maxHtlcOutputCount: n.maxHtlcOutputCount
|
|
748
919
|
};
|
|
749
920
|
}
|
|
750
|
-
function
|
|
751
|
-
if (n > BigInt(
|
|
921
|
+
function J(n) {
|
|
922
|
+
if (n > BigInt(W))
|
|
752
923
|
throw new Error(
|
|
753
|
-
`timelockAssert value ${n} exceeds uint16 max (${
|
|
924
|
+
`timelockAssert value ${n} exceeds uint16 max (${W})`
|
|
754
925
|
);
|
|
755
926
|
return Number(n);
|
|
756
927
|
}
|
|
757
|
-
class
|
|
928
|
+
class it {
|
|
758
929
|
constructor(e, t) {
|
|
759
930
|
this.publicClient = e, this.contractAddress = t;
|
|
760
931
|
}
|
|
761
932
|
async getTBVProtocolParams() {
|
|
762
933
|
const e = await this.publicClient.readContract({
|
|
763
934
|
address: this.contractAddress,
|
|
764
|
-
abi:
|
|
935
|
+
abi: b,
|
|
765
936
|
functionName: "getTBVProtocolParams"
|
|
766
937
|
});
|
|
767
|
-
return
|
|
938
|
+
return z(e);
|
|
768
939
|
}
|
|
769
940
|
async getLatestOffchainParams() {
|
|
770
941
|
const e = await this.publicClient.readContract({
|
|
771
942
|
address: this.contractAddress,
|
|
772
|
-
abi:
|
|
943
|
+
abi: b,
|
|
773
944
|
functionName: "getLatestOffchainParams"
|
|
774
945
|
});
|
|
775
|
-
return
|
|
946
|
+
return U(e);
|
|
776
947
|
}
|
|
777
948
|
async getOffchainParamsByVersion(e) {
|
|
778
949
|
const t = await this.publicClient.readContract({
|
|
779
950
|
address: this.contractAddress,
|
|
780
|
-
abi:
|
|
951
|
+
abi: b,
|
|
781
952
|
functionName: "getOffchainParamsByVersion",
|
|
782
953
|
args: [e]
|
|
783
954
|
});
|
|
784
|
-
return
|
|
955
|
+
return U(t);
|
|
785
956
|
}
|
|
786
957
|
async getLatestOffchainParamsVersion() {
|
|
787
958
|
return await this.publicClient.readContract({
|
|
788
959
|
address: this.contractAddress,
|
|
789
|
-
abi:
|
|
960
|
+
abi: b,
|
|
790
961
|
functionName: "latestOffchainParamsVersion"
|
|
791
962
|
});
|
|
792
963
|
}
|
|
793
964
|
async getTimelockPeginByVersion(e) {
|
|
794
965
|
const t = await this.getOffchainParamsByVersion(e);
|
|
795
|
-
return
|
|
966
|
+
return J(t.timelockAssert);
|
|
796
967
|
}
|
|
797
968
|
/**
|
|
798
969
|
* Read TBV protocol params and latest offchain params atomically via multicall.
|
|
@@ -803,97 +974,97 @@ class Le {
|
|
|
803
974
|
contracts: [
|
|
804
975
|
{
|
|
805
976
|
address: this.contractAddress,
|
|
806
|
-
abi:
|
|
977
|
+
abi: b,
|
|
807
978
|
functionName: "getTBVProtocolParams"
|
|
808
979
|
},
|
|
809
980
|
{
|
|
810
981
|
address: this.contractAddress,
|
|
811
|
-
abi:
|
|
982
|
+
abi: b,
|
|
812
983
|
functionName: "getLatestOffchainParams"
|
|
813
984
|
}
|
|
814
985
|
],
|
|
815
986
|
allowFailure: !1
|
|
816
|
-
}), t =
|
|
987
|
+
}), t = z(e[0]), r = U(e[1]);
|
|
817
988
|
return {
|
|
818
989
|
minimumPegInAmount: t.minimumPegInAmount,
|
|
819
990
|
maxPegInAmount: t.maxPegInAmount,
|
|
820
991
|
pegInAckTimeout: t.pegInAckTimeout,
|
|
821
992
|
pegInActivationTimeout: t.pegInActivationTimeout,
|
|
822
993
|
maxHtlcOutputCount: t.maxHtlcOutputCount,
|
|
823
|
-
timelockPegin:
|
|
994
|
+
timelockPegin: J(r.timelockAssert),
|
|
824
995
|
timelockRefund: r.tRefund,
|
|
825
996
|
minVpCommissionBps: r.minVpCommissionBps,
|
|
826
997
|
offchainParams: r
|
|
827
998
|
};
|
|
828
999
|
}
|
|
829
1000
|
}
|
|
830
|
-
function
|
|
1001
|
+
function H(n) {
|
|
831
1002
|
return n.map((e) => ({
|
|
832
1003
|
ethAddress: e.ethAddress,
|
|
833
1004
|
btcPubKey: e.btcPubKey
|
|
834
1005
|
}));
|
|
835
1006
|
}
|
|
836
|
-
class
|
|
1007
|
+
class at {
|
|
837
1008
|
constructor(e, t) {
|
|
838
1009
|
this.publicClient = e, this.contractAddress = t;
|
|
839
1010
|
}
|
|
840
1011
|
async getVaultKeepersByVersion(e, t) {
|
|
841
1012
|
const r = await this.publicClient.readContract({
|
|
842
1013
|
address: this.contractAddress,
|
|
843
|
-
abi:
|
|
1014
|
+
abi: D,
|
|
844
1015
|
functionName: "getVaultKeepersByVersion",
|
|
845
1016
|
args: [e, t]
|
|
846
1017
|
});
|
|
847
|
-
return
|
|
1018
|
+
return H(r);
|
|
848
1019
|
}
|
|
849
1020
|
async getCurrentVaultKeepers(e) {
|
|
850
1021
|
const t = await this.publicClient.readContract({
|
|
851
1022
|
address: this.contractAddress,
|
|
852
|
-
abi:
|
|
1023
|
+
abi: D,
|
|
853
1024
|
functionName: "getCurrentVaultKeepers",
|
|
854
1025
|
args: [e]
|
|
855
1026
|
});
|
|
856
|
-
return
|
|
1027
|
+
return H(t);
|
|
857
1028
|
}
|
|
858
1029
|
async getCurrentVaultKeepersVersion(e) {
|
|
859
1030
|
return await this.publicClient.readContract({
|
|
860
1031
|
address: this.contractAddress,
|
|
861
|
-
abi:
|
|
1032
|
+
abi: D,
|
|
862
1033
|
functionName: "getCurrentVaultKeepersVersion",
|
|
863
1034
|
args: [e]
|
|
864
1035
|
});
|
|
865
1036
|
}
|
|
866
1037
|
}
|
|
867
|
-
class
|
|
1038
|
+
class ot {
|
|
868
1039
|
constructor(e, t) {
|
|
869
1040
|
this.publicClient = e, this.contractAddress = t;
|
|
870
1041
|
}
|
|
871
1042
|
async getUniversalChallengersByVersion(e) {
|
|
872
1043
|
const t = await this.publicClient.readContract({
|
|
873
1044
|
address: this.contractAddress,
|
|
874
|
-
abi:
|
|
1045
|
+
abi: b,
|
|
875
1046
|
functionName: "getUniversalChallengersByVersion",
|
|
876
1047
|
args: [e]
|
|
877
1048
|
});
|
|
878
|
-
return
|
|
1049
|
+
return H(t);
|
|
879
1050
|
}
|
|
880
1051
|
async getCurrentUniversalChallengers() {
|
|
881
1052
|
const e = await this.publicClient.readContract({
|
|
882
1053
|
address: this.contractAddress,
|
|
883
|
-
abi:
|
|
1054
|
+
abi: b,
|
|
884
1055
|
functionName: "getCurrentUniversalChallengers"
|
|
885
1056
|
});
|
|
886
|
-
return
|
|
1057
|
+
return H(e);
|
|
887
1058
|
}
|
|
888
1059
|
async getLatestUniversalChallengersVersion() {
|
|
889
1060
|
return await this.publicClient.readContract({
|
|
890
1061
|
address: this.contractAddress,
|
|
891
|
-
abi:
|
|
1062
|
+
abi: b,
|
|
892
1063
|
functionName: "latestUniversalChallengersVersion"
|
|
893
1064
|
});
|
|
894
1065
|
}
|
|
895
1066
|
}
|
|
896
|
-
class
|
|
1067
|
+
class ct {
|
|
897
1068
|
constructor(e, t) {
|
|
898
1069
|
this.publicClient = e, this.contractAddress = t;
|
|
899
1070
|
}
|
|
@@ -906,7 +1077,7 @@ class Xe {
|
|
|
906
1077
|
async getVaultProviderBtcPubKey(e) {
|
|
907
1078
|
const r = (await this.publicClient.readContract({
|
|
908
1079
|
address: this.contractAddress,
|
|
909
|
-
abi:
|
|
1080
|
+
abi: k,
|
|
910
1081
|
functionName: "getVaultProviderBTCKey",
|
|
911
1082
|
args: [e]
|
|
912
1083
|
})).toLowerCase();
|
|
@@ -915,7 +1086,7 @@ class Xe {
|
|
|
915
1086
|
`getVaultProviderBTCKey returned an unexpected value (vp=${e}, length ${r.length}, prefix "${r.slice(0, 2)}")`
|
|
916
1087
|
);
|
|
917
1088
|
const i = r.slice(2);
|
|
918
|
-
if (!
|
|
1089
|
+
if (!N.isXOnlyPoint(he(i)))
|
|
919
1090
|
throw new Error(
|
|
920
1091
|
`getVaultProviderBTCKey returned a value that is not on the secp256k1 curve (vp=${e})`
|
|
921
1092
|
);
|
|
@@ -924,7 +1095,7 @@ class Xe {
|
|
|
924
1095
|
async getVaultBasicInfo(e) {
|
|
925
1096
|
const t = await this.publicClient.readContract({
|
|
926
1097
|
address: this.contractAddress,
|
|
927
|
-
abi:
|
|
1098
|
+
abi: k,
|
|
928
1099
|
functionName: "getBtcVaultBasicInfo",
|
|
929
1100
|
args: [e]
|
|
930
1101
|
});
|
|
@@ -941,7 +1112,7 @@ class Xe {
|
|
|
941
1112
|
async getVaultProtocolInfo(e) {
|
|
942
1113
|
const t = await this.publicClient.readContract({
|
|
943
1114
|
address: this.contractAddress,
|
|
944
|
-
abi:
|
|
1115
|
+
abi: k,
|
|
945
1116
|
functionName: "getBtcVaultProtocolInfo",
|
|
946
1117
|
args: [e]
|
|
947
1118
|
});
|
|
@@ -972,19 +1143,20 @@ class Xe {
|
|
|
972
1143
|
}
|
|
973
1144
|
}
|
|
974
1145
|
export {
|
|
975
|
-
|
|
976
|
-
|
|
1146
|
+
g as S,
|
|
1147
|
+
Ce as V,
|
|
977
1148
|
s as a,
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
1149
|
+
tt as b,
|
|
1150
|
+
Ue as c,
|
|
1151
|
+
Ge as d,
|
|
1152
|
+
oe as e,
|
|
1153
|
+
nt as f,
|
|
1154
|
+
it as g,
|
|
1155
|
+
ot as h,
|
|
1156
|
+
at as i,
|
|
1157
|
+
ct as j,
|
|
1158
|
+
rt as p,
|
|
1159
|
+
st as r,
|
|
1160
|
+
xe as v
|
|
989
1161
|
};
|
|
990
|
-
//# sourceMappingURL=vault-registry-reader-
|
|
1162
|
+
//# sourceMappingURL=vault-registry-reader-PsSxB0JZ.js.map
|