@babylonlabs-io/ts-sdk 0.26.2 → 0.27.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{bitcoin-nOOgeRyl.js → bitcoin-B-Y0DlqR.js} +63 -60
- package/dist/bitcoin-B-Y0DlqR.js.map +1 -0
- package/dist/bitcoin-DIN0OupO.cjs +2 -0
- package/dist/bitcoin-DIN0OupO.cjs.map +1 -0
- package/dist/buildAndBroadcastRefund-BEASMFsz.cjs +2 -0
- package/dist/buildAndBroadcastRefund-BEASMFsz.cjs.map +1 -0
- package/dist/buildAndBroadcastRefund-BzYJv-Fv.js +862 -0
- package/dist/buildAndBroadcastRefund-BzYJv-Fv.js.map +1 -0
- package/dist/challengeAssert-BM8m9gPM.cjs +2 -0
- package/dist/challengeAssert-BM8m9gPM.cjs.map +1 -0
- package/dist/{challengeAssert-CH32j5cZ.js → challengeAssert-j2Vwqo0-.js} +135 -120
- package/dist/challengeAssert-j2Vwqo0-.js.map +1 -0
- package/dist/context-BSdcD4J_.cjs +2 -0
- package/dist/context-BSdcD4J_.cjs.map +1 -0
- package/dist/{errors-CQjAF9QE.js → context-CClNOyD3.js} +442 -324
- package/dist/context-CClNOyD3.js.map +1 -0
- package/dist/fundPeginTransaction-DaWoYCgO.cjs +2 -0
- package/dist/fundPeginTransaction-DaWoYCgO.cjs.map +1 -0
- package/dist/fundPeginTransaction-oV-dNJOU.js +76 -0
- package/dist/fundPeginTransaction-oV-dNJOU.js.map +1 -0
- package/dist/index.cjs +1 -1
- package/dist/index.js +100 -91
- package/dist/{payout-DzGsAnhf.js → payout-B_fvQU3q.js} +2 -2
- package/dist/{payout-DzGsAnhf.js.map → payout-B_fvQU3q.js.map} +1 -1
- package/dist/{payout-RFIh7GLN.cjs → payout-DP6KMFP1.cjs} +2 -2
- package/dist/{payout-RFIh7GLN.cjs.map → payout-DP6KMFP1.cjs.map} +1 -1
- package/dist/psbtInputFields-C3dqKWjQ.js +258 -0
- package/dist/psbtInputFields-C3dqKWjQ.js.map +1 -0
- package/dist/psbtInputFields-DhGm77bP.cjs +2 -0
- package/dist/psbtInputFields-DhGm77bP.cjs.map +1 -0
- package/dist/sha2-1XZuToHP.cjs +2 -0
- package/dist/sha2-1XZuToHP.cjs.map +1 -0
- package/dist/sha2-ZzfZqQSw.js +1123 -0
- package/dist/sha2-ZzfZqQSw.js.map +1 -0
- package/dist/tbv/core/clients/index.cjs +1 -1
- package/dist/tbv/core/clients/index.js +27 -24
- package/dist/tbv/core/clients/vault-provider/auth/__tests__/bip322Verify.test.d.ts +17 -0
- package/dist/tbv/core/clients/vault-provider/auth/__tests__/bip322Verify.test.d.ts.map +1 -0
- package/dist/tbv/core/clients/vault-provider/auth/__tests__/cbor.test.d.ts +15 -0
- package/dist/tbv/core/clients/vault-provider/auth/__tests__/cbor.test.d.ts.map +1 -0
- package/dist/tbv/core/clients/vault-provider/auth/__tests__/goldenVectors.d.ts +44 -0
- package/dist/tbv/core/clients/vault-provider/auth/__tests__/goldenVectors.d.ts.map +1 -0
- package/dist/tbv/core/clients/vault-provider/auth/__tests__/serverIdentity.test.d.ts +2 -0
- package/dist/tbv/core/clients/vault-provider/auth/__tests__/serverIdentity.test.d.ts.map +1 -0
- package/dist/tbv/core/clients/vault-provider/auth/__tests__/tokenProvider.test.d.ts +2 -0
- package/dist/tbv/core/clients/vault-provider/auth/__tests__/tokenProvider.test.d.ts.map +1 -0
- package/dist/tbv/core/clients/vault-provider/auth/bip322Verify.d.ts +56 -0
- package/dist/tbv/core/clients/vault-provider/auth/bip322Verify.d.ts.map +1 -0
- package/dist/tbv/core/clients/vault-provider/auth/cbor.d.ts +44 -0
- package/dist/tbv/core/clients/vault-provider/auth/cbor.d.ts.map +1 -0
- package/dist/tbv/core/clients/vault-provider/auth/index.d.ts +10 -0
- package/dist/tbv/core/clients/vault-provider/auth/index.d.ts.map +1 -0
- package/dist/tbv/core/clients/vault-provider/auth/serverIdentity.d.ts +68 -0
- package/dist/tbv/core/clients/vault-provider/auth/serverIdentity.d.ts.map +1 -0
- package/dist/tbv/core/clients/vault-provider/auth/tokenProvider.d.ts +81 -0
- package/dist/tbv/core/clients/vault-provider/auth/tokenProvider.d.ts.map +1 -0
- package/dist/tbv/core/clients/vault-provider/index.d.ts +2 -1
- 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 +66 -1
- package/dist/tbv/core/clients/vault-provider/json-rpc-client.d.ts.map +1 -1
- 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.d.ts +3 -0
- package/dist/tbv/core/index.d.ts.map +1 -1
- package/dist/tbv/core/index.js +96 -87
- package/dist/tbv/core/managers/PeginManager.d.ts.map +1 -1
- package/dist/tbv/core/primitives/index.cjs +1 -1
- package/dist/tbv/core/primitives/index.js +3 -3
- package/dist/tbv/core/primitives/psbt/pegin.d.ts +17 -2
- package/dist/tbv/core/primitives/psbt/pegin.d.ts.map +1 -1
- package/dist/tbv/core/primitives/utils/bitcoin.d.ts +19 -0
- package/dist/tbv/core/primitives/utils/bitcoin.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/utils/fee/__tests__/constants.test.d.ts +2 -0
- package/dist/tbv/core/utils/fee/__tests__/constants.test.d.ts.map +1 -0
- package/dist/tbv/core/utils/fee/constants.d.ts +30 -9
- package/dist/tbv/core/utils/fee/constants.d.ts.map +1 -1
- package/dist/tbv/core/utils/index.cjs +1 -1
- package/dist/tbv/core/utils/index.js +28 -27
- package/dist/tbv/core/utils/utxo/availability.d.ts.map +1 -1
- package/dist/tbv/core/utils/utxo/selectUtxos.d.ts.map +1 -1
- package/dist/tbv/core/vault-secrets/__tests__/context.golden.test.d.ts +34 -0
- package/dist/tbv/core/vault-secrets/__tests__/context.golden.test.d.ts.map +1 -0
- package/dist/tbv/core/vault-secrets/__tests__/context.test.d.ts +6 -0
- package/dist/tbv/core/vault-secrets/__tests__/context.test.d.ts.map +1 -0
- package/dist/tbv/core/vault-secrets/__tests__/expand.test.d.ts +10 -0
- package/dist/tbv/core/vault-secrets/__tests__/expand.test.d.ts.map +1 -0
- package/dist/tbv/core/vault-secrets/__tests__/info.test.d.ts +8 -0
- package/dist/tbv/core/vault-secrets/__tests__/info.test.d.ts.map +1 -0
- package/dist/tbv/core/vault-secrets/context.d.ts +52 -0
- package/dist/tbv/core/vault-secrets/context.d.ts.map +1 -0
- package/dist/tbv/core/vault-secrets/expand.d.ts +43 -0
- package/dist/tbv/core/vault-secrets/expand.d.ts.map +1 -0
- package/dist/tbv/core/vault-secrets/index.d.ts +16 -0
- package/dist/tbv/core/vault-secrets/index.d.ts.map +1 -0
- package/dist/tbv/core/vault-secrets/info.d.ts +55 -0
- package/dist/tbv/core/vault-secrets/info.d.ts.map +1 -0
- package/dist/tbv/index.cjs +1 -1
- package/dist/tbv/index.js +96 -87
- package/dist/tbv/integrations/aave/index.cjs +1 -1
- package/dist/tbv/integrations/aave/index.cjs.map +1 -1
- package/dist/tbv/integrations/aave/index.js +164 -159
- package/dist/tbv/integrations/aave/index.js.map +1 -1
- package/dist/tbv/integrations/aave/utils/vaultSplit.d.ts.map +1 -1
- package/dist/vault-registry-reader-BizmBSBV.cjs +2 -0
- package/dist/vault-registry-reader-BizmBSBV.cjs.map +1 -0
- package/dist/{index-D7s2ilf8.js → vault-registry-reader-CpCOte7w.js} +522 -268
- package/dist/vault-registry-reader-CpCOte7w.js.map +1 -0
- package/package.json +8 -3
- package/dist/bitcoin-CNnPFU6Y.cjs +0 -2
- package/dist/bitcoin-CNnPFU6Y.cjs.map +0 -1
- package/dist/bitcoin-nOOgeRyl.js.map +0 -1
- package/dist/buildAndBroadcastRefund-Ccp-2GWW.js +0 -1334
- package/dist/buildAndBroadcastRefund-Ccp-2GWW.js.map +0 -1
- package/dist/buildAndBroadcastRefund-Mr3ck5ek.cjs +0 -2
- package/dist/buildAndBroadcastRefund-Mr3ck5ek.cjs.map +0 -1
- package/dist/challengeAssert-CH32j5cZ.js.map +0 -1
- package/dist/challengeAssert-X7V3Ik_Q.cjs +0 -2
- package/dist/challengeAssert-X7V3Ik_Q.cjs.map +0 -1
- package/dist/errors-BBrP8sLT.cjs +0 -2
- package/dist/errors-BBrP8sLT.cjs.map +0 -1
- package/dist/errors-CQjAF9QE.js.map +0 -1
- package/dist/fundPeginTransaction-BLYXxLBv.js +0 -70
- package/dist/fundPeginTransaction-BLYXxLBv.js.map +0 -1
- package/dist/fundPeginTransaction-DxNOeyNI.cjs +0 -2
- package/dist/fundPeginTransaction-DxNOeyNI.cjs.map +0 -1
- package/dist/index-CIuXb72l.cjs +0 -2
- package/dist/index-CIuXb72l.cjs.map +0 -1
- package/dist/index-D7s2ilf8.js.map +0 -1
- package/dist/psbtInputFields-1dXR4hLk.js +0 -237
- package/dist/psbtInputFields-1dXR4hLk.js.map +0 -1
- package/dist/psbtInputFields-tnAR8tG5.cjs +0 -2
- package/dist/psbtInputFields-tnAR8tG5.cjs.map +0 -1
- package/dist/types-WrGfwlJd.js +0 -608
- package/dist/types-WrGfwlJd.js.map +0 -1
- package/dist/types-xU3SBcpH.cjs +0 -2
- package/dist/types-xU3SBcpH.cjs.map +0 -1
|
@@ -1,21 +1,20 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var b = (e, t, n) =>
|
|
4
|
-
import * as
|
|
5
|
-
import { Transaction as
|
|
6
|
-
import { Buffer as
|
|
7
|
-
import { isAddressEqual as
|
|
8
|
-
import { c as
|
|
9
|
-
import { deriveVaultId as
|
|
10
|
-
import { b as
|
|
11
|
-
import { s as
|
|
12
|
-
import { M as
|
|
13
|
-
import { b as
|
|
14
|
-
import { p as
|
|
15
|
-
import { p as
|
|
16
|
-
import { B as
|
|
17
|
-
|
|
18
|
-
const S = {
|
|
1
|
+
var te = Object.defineProperty;
|
|
2
|
+
var ee = (e, t, n) => t in e ? te(e, t, { enumerable: !0, configurable: !0, writable: !0, value: n }) : e[t] = n;
|
|
3
|
+
var b = (e, t, n) => ee(e, typeof t != "symbol" ? t + "" : t, n);
|
|
4
|
+
import * as ne from "bitcoinjs-lib";
|
|
5
|
+
import { Transaction as se, Psbt as yt } from "bitcoinjs-lib";
|
|
6
|
+
import { Buffer as it } from "buffer";
|
|
7
|
+
import { isAddressEqual as bt, createPublicClient as q, http as Z, encodeFunctionData as xt, zeroAddress as oe } from "viem";
|
|
8
|
+
import { c as re } from "./signing-BZigafm0.js";
|
|
9
|
+
import { deriveVaultId as Pt } from "@babylonlabs-io/babylon-tbv-rust-wasm";
|
|
10
|
+
import { b as ie, a as ae, d as ce, e as le, f as ue } from "./challengeAssert-j2Vwqo0-.js";
|
|
11
|
+
import { s as v, g as kt, e as I, i as he, p as de } from "./bitcoin-B-Y0DlqR.js";
|
|
12
|
+
import { M as Et } from "./validation-CxqROCno.js";
|
|
13
|
+
import { b as fe, f as G, i as ge } from "./psbtInputFields-C3dqKWjQ.js";
|
|
14
|
+
import { p as pe, f as me } from "./fundPeginTransaction-oV-dNJOU.js";
|
|
15
|
+
import { p as we, f as ye } from "./vault-registry-reader-CpCOte7w.js";
|
|
16
|
+
import { B as O, e as ht, f as U, g as S, h as V, i as Ut, H as be, r as F, j as xe, k as C, u as Pe, l as Tt, m as ke, n as Ee, o as Te, p as Ie, q as _e, t as ve, v as Be, w as It, x as Wt, s as W } from "./sha2-ZzfZqQSw.js";
|
|
17
|
+
const H = {
|
|
19
18
|
// VaultAlreadyExists()
|
|
20
19
|
"0x04aabf33": "Vault already exists: This Bitcoin transaction has already been registered. Please select different UTXOs or use a different amount to create a unique transaction.",
|
|
21
20
|
// ScriptPubKeyMismatch() - taproot output doesn't match expected script
|
|
@@ -49,7 +48,7 @@ const S = {
|
|
|
49
48
|
// PeginTransactionAlreadyUsed()
|
|
50
49
|
"0x7ed061c9": "This pegin transaction has already been used to activate another vault."
|
|
51
50
|
};
|
|
52
|
-
function
|
|
51
|
+
function dt(e) {
|
|
53
52
|
if (!e || typeof e != "object") return;
|
|
54
53
|
const t = e;
|
|
55
54
|
if (typeof t.data == "string" && t.data.startsWith("0x"))
|
|
@@ -68,24 +67,24 @@ function nt(e) {
|
|
|
68
67
|
if (i)
|
|
69
68
|
return i[1];
|
|
70
69
|
}
|
|
71
|
-
function
|
|
72
|
-
const t =
|
|
70
|
+
function Fn(e) {
|
|
71
|
+
const t = dt(e);
|
|
73
72
|
if (t) {
|
|
74
73
|
const n = t.substring(0, 10);
|
|
75
|
-
return
|
|
74
|
+
return H[t] ?? H[n];
|
|
76
75
|
}
|
|
77
76
|
}
|
|
78
|
-
function
|
|
79
|
-
const t =
|
|
77
|
+
function Mn(e) {
|
|
78
|
+
const t = dt(e);
|
|
80
79
|
if (t === void 0) return !1;
|
|
81
80
|
const n = t.substring(0, 10);
|
|
82
|
-
return t in
|
|
81
|
+
return t in H || n in H;
|
|
83
82
|
}
|
|
84
|
-
function
|
|
83
|
+
function A(e) {
|
|
85
84
|
console.error("[Contract Error] Raw error:", e);
|
|
86
|
-
const t =
|
|
85
|
+
const t = dt(e);
|
|
87
86
|
if (console.error("[Contract Error] Extracted error data:", t), t) {
|
|
88
|
-
const s = t.substring(0, 10), o =
|
|
87
|
+
const s = t.substring(0, 10), o = H[t] ?? H[s];
|
|
89
88
|
if (o)
|
|
90
89
|
throw console.error("[Contract Error] Known error:", o), new Error(o);
|
|
91
90
|
}
|
|
@@ -103,43 +102,43 @@ function C(e) {
|
|
|
103
102
|
}
|
|
104
103
|
throw e instanceof Error ? (console.error("[Contract Error] Unhandled error:", e.message), e) : new Error(`Contract call failed: ${String(e)}`);
|
|
105
104
|
}
|
|
106
|
-
const
|
|
105
|
+
const Se = 0, Ae = /^0x[0-9a-f]+$/i, Ce = /^[0-9a-f]+$/i, He = /^[A-Za-z0-9+/]+={0,2}$/;
|
|
107
106
|
function $(e) {
|
|
108
107
|
if (typeof e != "string" || e.length === 0)
|
|
109
108
|
throw new Error("BTC wallet returned empty public key");
|
|
110
|
-
return
|
|
109
|
+
return de(e).toLowerCase();
|
|
111
110
|
}
|
|
112
|
-
function
|
|
111
|
+
function Oe(e) {
|
|
113
112
|
if (typeof e != "string" || e.length === 0)
|
|
114
113
|
throw new Error("BTC wallet returned empty BIP-322 signature");
|
|
115
114
|
if (e.startsWith("0x") || e.startsWith("0X")) {
|
|
116
|
-
if (!
|
|
115
|
+
if (!Ae.test(e) || e.length < 4 || e.length % 2 !== 0)
|
|
117
116
|
throw new Error("BTC wallet returned malformed hex BIP-322 signature");
|
|
118
117
|
return e.toLowerCase();
|
|
119
118
|
}
|
|
120
|
-
if (
|
|
119
|
+
if (Ce.test(e)) {
|
|
121
120
|
if (e.length % 2 !== 0)
|
|
122
121
|
throw new Error("BTC wallet returned malformed hex BIP-322 signature");
|
|
123
122
|
return `0x${e.toLowerCase()}`;
|
|
124
123
|
}
|
|
125
|
-
if (!
|
|
124
|
+
if (!He.test(e) || e.length % 4 !== 0)
|
|
126
125
|
throw new Error("BTC wallet returned malformed base64 BIP-322 signature");
|
|
127
|
-
const t =
|
|
126
|
+
const t = it.from(e, "base64");
|
|
128
127
|
if (t.length === 0 || t.toString("base64") !== e)
|
|
129
128
|
throw new Error("BTC wallet returned malformed base64 BIP-322 signature");
|
|
130
129
|
return `0x${t.toString("hex")}`;
|
|
131
130
|
}
|
|
132
|
-
function
|
|
131
|
+
function $e(e, t, n, s) {
|
|
133
132
|
const o = n == null ? void 0 : n[`${e}:${t}`];
|
|
134
133
|
return o ? Promise.resolve({
|
|
135
134
|
txid: e,
|
|
136
135
|
vout: t,
|
|
137
136
|
value: o.value,
|
|
138
137
|
scriptPubKey: o.scriptPubKey
|
|
139
|
-
}) :
|
|
138
|
+
}) : ye(e, t, s);
|
|
140
139
|
}
|
|
141
|
-
const
|
|
142
|
-
class
|
|
140
|
+
const _t = 12e4;
|
|
141
|
+
class Nn {
|
|
143
142
|
/**
|
|
144
143
|
* Creates a new PeginManager instance.
|
|
145
144
|
*
|
|
@@ -170,14 +169,14 @@ class pn {
|
|
|
170
169
|
* @throws Error if wallet operations fail or insufficient funds
|
|
171
170
|
*/
|
|
172
171
|
async preparePegin(t) {
|
|
173
|
-
const n = await this.config.btcWallet.getPublicKeyHex(), s = $(n), o =
|
|
172
|
+
const n = await this.config.btcWallet.getPublicKeyHex(), s = $(n), o = v(t.vaultProviderBtcPubkey), r = t.vaultKeeperBtcPubkeys.map(v), i = t.universalChallengerBtcPubkeys.map(v);
|
|
174
173
|
if (t.hashlocks.length !== t.amounts.length)
|
|
175
174
|
throw new Error(
|
|
176
175
|
`hashlocks.length (${t.hashlocks.length}) must equal amounts.length (${t.amounts.length})`
|
|
177
176
|
);
|
|
178
177
|
if (t.hashlocks.length === 0)
|
|
179
178
|
throw new Error("hashlocks must contain at least one entry");
|
|
180
|
-
const a = r.length,
|
|
179
|
+
const a = r.length, h = {
|
|
181
180
|
depositorPubkey: s,
|
|
182
181
|
vaultProviderPubkey: o,
|
|
183
182
|
vaultKeeperPubkeys: r,
|
|
@@ -190,25 +189,28 @@ class pn {
|
|
|
190
189
|
councilQuorum: t.councilQuorum,
|
|
191
190
|
councilSize: t.councilSize,
|
|
192
191
|
network: this.config.btcNetwork
|
|
193
|
-
},
|
|
192
|
+
}, u = await ie(h), c = fe(
|
|
194
193
|
[...t.availableUTXOs],
|
|
195
|
-
|
|
194
|
+
u.totalOutputValue,
|
|
196
195
|
t.mempoolFeeRate,
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
196
|
+
pe(
|
|
197
|
+
u.htlcValues.length,
|
|
198
|
+
h.authAnchorHash
|
|
199
|
+
)
|
|
200
|
+
), m = kt(this.config.btcNetwork), l = me({
|
|
201
|
+
unfundedTxHex: u.psbtHex,
|
|
200
202
|
selectedUTXOs: c.selectedUTXOs,
|
|
201
203
|
changeAddress: t.changeAddress,
|
|
202
204
|
changeAmount: c.changeAmount,
|
|
203
205
|
network: m
|
|
204
|
-
}), y =
|
|
206
|
+
}), y = v(G(l)), f = [], x = [], P = [];
|
|
205
207
|
for (let g = 0; g < t.hashlocks.length; g++) {
|
|
206
|
-
const p = await
|
|
207
|
-
prePeginParams:
|
|
208
|
+
const p = await ae({
|
|
209
|
+
prePeginParams: h,
|
|
208
210
|
timelockPegin: t.timelockPegin,
|
|
209
211
|
fundedPrePeginTxHex: l,
|
|
210
212
|
htlcVout: g
|
|
211
|
-
}),
|
|
213
|
+
}), E = await ce({
|
|
212
214
|
peginTxHex: p.txHex,
|
|
213
215
|
fundedPrePeginTxHex: l,
|
|
214
216
|
depositorPubkey: s,
|
|
@@ -219,32 +221,32 @@ class pn {
|
|
|
219
221
|
timelockRefund: t.timelockRefund,
|
|
220
222
|
network: this.config.btcNetwork
|
|
221
223
|
});
|
|
222
|
-
|
|
223
|
-
|
|
224
|
+
f.push(p), x.push(E.psbtHex), P.push(
|
|
225
|
+
re(n, 1)
|
|
224
226
|
);
|
|
225
227
|
}
|
|
226
228
|
const w = await this.signPsbtsWithFallback(
|
|
227
229
|
x,
|
|
228
230
|
P
|
|
229
|
-
),
|
|
231
|
+
), d = [];
|
|
230
232
|
for (let g = 0; g < w.length; g++) {
|
|
231
|
-
const p =
|
|
233
|
+
const p = le(
|
|
232
234
|
w[g],
|
|
233
235
|
s
|
|
234
|
-
),
|
|
235
|
-
|
|
236
|
+
), E = ue(w[g]);
|
|
237
|
+
d.push({
|
|
236
238
|
htlcVout: g,
|
|
237
|
-
htlcValue:
|
|
238
|
-
peginTxHex:
|
|
239
|
-
peginTxid:
|
|
239
|
+
htlcValue: u.htlcValues[g],
|
|
240
|
+
peginTxHex: E,
|
|
241
|
+
peginTxid: f[g].txid,
|
|
240
242
|
peginInputSignature: p,
|
|
241
|
-
vaultScriptPubKey:
|
|
243
|
+
vaultScriptPubKey: f[g].vaultScriptPubKey
|
|
242
244
|
});
|
|
243
245
|
}
|
|
244
246
|
return {
|
|
245
247
|
fundedPrePeginTxHex: l,
|
|
246
248
|
prePeginTxid: y,
|
|
247
|
-
perVault:
|
|
249
|
+
perVault: d,
|
|
248
250
|
selectedUTXOs: c.selectedUTXOs,
|
|
249
251
|
fee: c.fee,
|
|
250
252
|
changeAmount: c.changeAmount
|
|
@@ -295,24 +297,24 @@ class pn {
|
|
|
295
297
|
* @throws Error if signing or broadcasting fails
|
|
296
298
|
*/
|
|
297
299
|
async signAndBroadcast(t) {
|
|
298
|
-
const { fundedPrePeginTxHex: n, depositorBtcPubkey: s } = t, o = n.startsWith("0x") ? n.slice(2) : n, r =
|
|
300
|
+
const { fundedPrePeginTxHex: n, depositorBtcPubkey: s } = t, o = n.startsWith("0x") ? n.slice(2) : n, r = se.fromHex(o);
|
|
299
301
|
if (r.ins.length === 0)
|
|
300
302
|
throw new Error("Transaction has no inputs");
|
|
301
|
-
const i = new
|
|
303
|
+
const i = new yt();
|
|
302
304
|
i.setVersion(r.version), i.setLocktime(r.locktime);
|
|
303
|
-
const a =
|
|
305
|
+
const a = it.from(
|
|
304
306
|
$(s),
|
|
305
307
|
"hex"
|
|
306
|
-
),
|
|
307
|
-
const g =
|
|
308
|
-
return
|
|
309
|
-
(
|
|
308
|
+
), h = this.config.mempoolApiUrl, u = r.ins.map((d) => {
|
|
309
|
+
const g = it.from(d.hash).reverse().toString("hex"), p = d.index;
|
|
310
|
+
return $e(g, p, t.localPrevouts, h).then(
|
|
311
|
+
(E) => ({ input: d, utxoData: E, txid: g, vout: p })
|
|
310
312
|
);
|
|
311
|
-
}), c = await Promise.all(
|
|
312
|
-
(
|
|
313
|
+
}), c = await Promise.all(u), m = c.reduce(
|
|
314
|
+
(d, g) => d + BigInt(g.utxoData.value),
|
|
313
315
|
0n
|
|
314
316
|
), l = r.outs.reduce(
|
|
315
|
-
(
|
|
317
|
+
(d, g) => d + BigInt(g.value),
|
|
316
318
|
0n
|
|
317
319
|
);
|
|
318
320
|
if (m < l)
|
|
@@ -320,12 +322,12 @@ class pn {
|
|
|
320
322
|
`UTXO value mismatch: total input value (${m} sat) is less than total output value (${l} sat). This may indicate the mempool API returned manipulated UTXO data.`
|
|
321
323
|
);
|
|
322
324
|
const y = m - l;
|
|
323
|
-
if (y >
|
|
325
|
+
if (y > Et)
|
|
324
326
|
throw new Error(
|
|
325
|
-
`Implied transaction fee (${y} sat) exceeds maximum reasonable fee (${
|
|
327
|
+
`Implied transaction fee (${y} sat) exceeds maximum reasonable fee (${Et} sat). This may indicate manipulated UTXO data.`
|
|
326
328
|
);
|
|
327
|
-
for (const { input:
|
|
328
|
-
const k =
|
|
329
|
+
for (const { input: d, utxoData: g, txid: p, vout: E } of c) {
|
|
330
|
+
const k = ge(
|
|
329
331
|
{
|
|
330
332
|
value: g.value,
|
|
331
333
|
scriptPubKey: g.scriptPubKey
|
|
@@ -333,30 +335,30 @@ class pn {
|
|
|
333
335
|
a
|
|
334
336
|
);
|
|
335
337
|
i.addInput({
|
|
336
|
-
hash:
|
|
337
|
-
index:
|
|
338
|
-
sequence:
|
|
338
|
+
hash: d.hash,
|
|
339
|
+
index: d.index,
|
|
340
|
+
sequence: d.sequence,
|
|
339
341
|
...k
|
|
340
342
|
});
|
|
341
343
|
}
|
|
342
|
-
for (const
|
|
344
|
+
for (const d of r.outs)
|
|
343
345
|
i.addOutput({
|
|
344
|
-
script:
|
|
345
|
-
value:
|
|
346
|
+
script: d.script,
|
|
347
|
+
value: d.value
|
|
346
348
|
});
|
|
347
|
-
const
|
|
349
|
+
const f = await this.config.btcWallet.signPsbt(i.toHex()), x = yt.fromHex(f);
|
|
348
350
|
try {
|
|
349
351
|
x.finalizeAllInputs();
|
|
350
|
-
} catch (
|
|
352
|
+
} catch (d) {
|
|
351
353
|
if (!x.data.inputs.every(
|
|
352
354
|
(p) => p.finalScriptWitness || p.finalScriptSig
|
|
353
355
|
))
|
|
354
356
|
throw new Error(
|
|
355
|
-
`PSBT finalization failed and wallet did not auto-finalize: ${
|
|
357
|
+
`PSBT finalization failed and wallet did not auto-finalize: ${d}`
|
|
356
358
|
);
|
|
357
359
|
}
|
|
358
360
|
const P = x.extractTransaction().toHex();
|
|
359
|
-
return await
|
|
361
|
+
return await we(P, h);
|
|
360
362
|
}
|
|
361
363
|
/**
|
|
362
364
|
* Registers a peg-in on Ethereum by calling the BTCVaultRegistry contract.
|
|
@@ -390,36 +392,36 @@ class pn {
|
|
|
390
392
|
hashlock: r,
|
|
391
393
|
htlcVout: i,
|
|
392
394
|
depositorPayoutBtcAddress: a,
|
|
393
|
-
depositorWotsPkHash:
|
|
394
|
-
popSignature:
|
|
395
|
+
depositorWotsPkHash: h,
|
|
396
|
+
popSignature: u
|
|
395
397
|
} = t;
|
|
396
398
|
if (!this.config.ethWallet.account)
|
|
397
399
|
throw new Error("Ethereum wallet account not found");
|
|
398
400
|
const c = this.config.ethWallet.account.address;
|
|
399
|
-
if (!
|
|
401
|
+
if (!bt(u.depositorEthAddress, c))
|
|
400
402
|
throw new Error(
|
|
401
|
-
`Proof of possession was signed for ${
|
|
403
|
+
`Proof of possession was signed for ${u.depositorEthAddress} but the Ethereum wallet is currently connected to ${c}. Reconnect the original account or call signProofOfPossession() again.`
|
|
402
404
|
);
|
|
403
|
-
await this.assertPopMatchesBtcWallet(
|
|
404
|
-
const m =
|
|
405
|
+
await this.assertPopMatchesBtcWallet(u);
|
|
406
|
+
const m = u.btcPopSignature, l = I(u.depositorBtcPubkey), y = I(n), f = I(s), x = await this.resolvePayoutScriptPubKey(
|
|
405
407
|
a
|
|
406
|
-
), P =
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
),
|
|
410
|
-
if (await this.checkVaultExists(
|
|
408
|
+
), P = G(f), w = await Pt(
|
|
409
|
+
v(P),
|
|
410
|
+
v(c)
|
|
411
|
+
), d = I(w);
|
|
412
|
+
if (await this.checkVaultExists(d))
|
|
411
413
|
throw new Error(
|
|
412
|
-
`Vault already exists (ID: ${
|
|
414
|
+
`Vault already exists (ID: ${d}, peginTxHash: ${P}). Vault IDs are derived from the pegin transaction hash and depositor address. To create a new vault, use different UTXOs or a different amount to generate a unique transaction.`
|
|
413
415
|
);
|
|
414
|
-
const p =
|
|
416
|
+
const p = q({
|
|
415
417
|
chain: this.config.ethChain,
|
|
416
|
-
transport:
|
|
418
|
+
transport: Z()
|
|
417
419
|
});
|
|
418
|
-
let
|
|
420
|
+
let E;
|
|
419
421
|
try {
|
|
420
|
-
|
|
422
|
+
E = await p.readContract({
|
|
421
423
|
address: this.config.vaultContracts.btcVaultRegistry,
|
|
422
|
-
abi:
|
|
424
|
+
abi: O,
|
|
423
425
|
functionName: "getPegInFee",
|
|
424
426
|
args: [o]
|
|
425
427
|
});
|
|
@@ -428,57 +430,57 @@ class pn {
|
|
|
428
430
|
"Failed to query pegin fee from the contract. Please check your network connection and that the contract address is correct."
|
|
429
431
|
);
|
|
430
432
|
}
|
|
431
|
-
const k =
|
|
432
|
-
abi:
|
|
433
|
+
const k = xt({
|
|
434
|
+
abi: O,
|
|
433
435
|
functionName: "submitPeginRequest",
|
|
434
436
|
args: [
|
|
435
437
|
c,
|
|
436
438
|
l,
|
|
437
439
|
m,
|
|
438
440
|
y,
|
|
439
|
-
|
|
441
|
+
f,
|
|
440
442
|
o,
|
|
441
443
|
r,
|
|
442
444
|
i,
|
|
443
445
|
x,
|
|
444
|
-
|
|
446
|
+
h
|
|
445
447
|
]
|
|
446
448
|
});
|
|
447
|
-
let
|
|
449
|
+
let _;
|
|
448
450
|
try {
|
|
449
|
-
|
|
451
|
+
_ = await p.estimateGas({
|
|
450
452
|
to: this.config.vaultContracts.btcVaultRegistry,
|
|
451
453
|
data: k,
|
|
452
|
-
value:
|
|
454
|
+
value: E,
|
|
453
455
|
account: this.config.ethWallet.account.address
|
|
454
456
|
});
|
|
455
|
-
} catch (
|
|
456
|
-
|
|
457
|
+
} catch (j) {
|
|
458
|
+
A(j);
|
|
457
459
|
}
|
|
458
|
-
let
|
|
460
|
+
let B;
|
|
459
461
|
try {
|
|
460
|
-
|
|
462
|
+
B = await this.config.ethWallet.sendTransaction({
|
|
461
463
|
to: this.config.vaultContracts.btcVaultRegistry,
|
|
462
464
|
data: k,
|
|
463
|
-
value:
|
|
465
|
+
value: E,
|
|
464
466
|
account: this.config.ethWallet.account,
|
|
465
467
|
chain: this.config.ethChain,
|
|
466
|
-
gas:
|
|
468
|
+
gas: _
|
|
467
469
|
});
|
|
468
|
-
} catch (
|
|
469
|
-
|
|
470
|
+
} catch (j) {
|
|
471
|
+
A(j);
|
|
470
472
|
}
|
|
471
|
-
const
|
|
472
|
-
hash:
|
|
473
|
-
timeout:
|
|
473
|
+
const X = await p.waitForTransactionReceipt({
|
|
474
|
+
hash: B,
|
|
475
|
+
timeout: _t
|
|
474
476
|
});
|
|
475
|
-
return
|
|
477
|
+
return X.status === "reverted" && A(
|
|
476
478
|
new Error(
|
|
477
|
-
`Transaction reverted. Hash: ${
|
|
479
|
+
`Transaction reverted. Hash: ${B}. Check the transaction on block explorer for details.`
|
|
478
480
|
)
|
|
479
481
|
), {
|
|
480
|
-
ethTxHash:
|
|
481
|
-
vaultId:
|
|
482
|
+
ethTxHash: X.transactionHash,
|
|
483
|
+
vaultId: d,
|
|
482
484
|
peginTxHash: P
|
|
483
485
|
};
|
|
484
486
|
}
|
|
@@ -499,39 +501,39 @@ class pn {
|
|
|
499
501
|
if (!this.config.ethWallet.account)
|
|
500
502
|
throw new Error("Ethereum wallet account not found");
|
|
501
503
|
const i = this.config.ethWallet.account.address;
|
|
502
|
-
if (!
|
|
504
|
+
if (!bt(r.depositorEthAddress, i))
|
|
503
505
|
throw new Error(
|
|
504
506
|
`Proof of possession was signed for ${r.depositorEthAddress} but the Ethereum wallet is currently connected to ${i}. Reconnect the original account or call signProofOfPossession() again.`
|
|
505
507
|
);
|
|
506
508
|
await this.assertPopMatchesBtcWallet(r);
|
|
507
|
-
const a = r.btcPopSignature,
|
|
509
|
+
const a = r.btcPopSignature, h = [];
|
|
508
510
|
for (const p of o)
|
|
509
|
-
|
|
511
|
+
h.push(
|
|
510
512
|
await this.resolvePayoutScriptPubKey(p.depositorPayoutBtcAddress)
|
|
511
513
|
);
|
|
512
|
-
const
|
|
514
|
+
const u = [];
|
|
513
515
|
for (const p of o) {
|
|
514
|
-
const
|
|
516
|
+
const E = I(
|
|
515
517
|
p.depositorSignedPeginTx
|
|
516
|
-
), k =
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
),
|
|
520
|
-
if (await this.checkVaultExists(
|
|
518
|
+
), k = G(E), _ = await Pt(
|
|
519
|
+
v(k),
|
|
520
|
+
v(i)
|
|
521
|
+
), B = I(_);
|
|
522
|
+
if (await this.checkVaultExists(B))
|
|
521
523
|
throw new Error(
|
|
522
|
-
`Vault already exists (ID: ${
|
|
524
|
+
`Vault already exists (ID: ${B}, peginTxHash: ${k}). To create a new vault, use different UTXOs or a different amount.`
|
|
523
525
|
);
|
|
524
|
-
|
|
526
|
+
u.push({ vaultId: B, peginTxHash: k });
|
|
525
527
|
}
|
|
526
|
-
const c =
|
|
528
|
+
const c = q({
|
|
527
529
|
chain: this.config.ethChain,
|
|
528
|
-
transport:
|
|
530
|
+
transport: Z()
|
|
529
531
|
});
|
|
530
532
|
let m;
|
|
531
533
|
try {
|
|
532
534
|
m = await c.readContract({
|
|
533
535
|
address: this.config.vaultContracts.btcVaultRegistry,
|
|
534
|
-
abi:
|
|
536
|
+
abi: O,
|
|
535
537
|
functionName: "getPegInFee",
|
|
536
538
|
args: [n]
|
|
537
539
|
});
|
|
@@ -542,20 +544,20 @@ class pn {
|
|
|
542
544
|
}
|
|
543
545
|
const l = m * BigInt(o.length), y = I(
|
|
544
546
|
r.depositorBtcPubkey
|
|
545
|
-
),
|
|
547
|
+
), f = I(s), x = o.map((p, E) => ({
|
|
546
548
|
depositorBtcPubKey: y,
|
|
547
549
|
btcPopSignature: a,
|
|
548
|
-
unsignedPrePeginTx:
|
|
550
|
+
unsignedPrePeginTx: f,
|
|
549
551
|
depositorSignedPeginTx: I(
|
|
550
552
|
p.depositorSignedPeginTx
|
|
551
553
|
),
|
|
552
554
|
hashlock: p.hashlock,
|
|
553
555
|
htlcVout: p.htlcVout,
|
|
554
|
-
referralCode:
|
|
555
|
-
depositorPayoutBtcAddress:
|
|
556
|
+
referralCode: Se,
|
|
557
|
+
depositorPayoutBtcAddress: h[E],
|
|
556
558
|
depositorWotsPkHash: p.depositorWotsPkHash
|
|
557
|
-
})), P =
|
|
558
|
-
abi:
|
|
559
|
+
})), P = xt({
|
|
560
|
+
abi: O,
|
|
559
561
|
functionName: "submitPeginRequestBatch",
|
|
560
562
|
args: [i, n, x]
|
|
561
563
|
});
|
|
@@ -568,11 +570,11 @@ class pn {
|
|
|
568
570
|
account: this.config.ethWallet.account.address
|
|
569
571
|
});
|
|
570
572
|
} catch (p) {
|
|
571
|
-
|
|
573
|
+
A(p);
|
|
572
574
|
}
|
|
573
|
-
let
|
|
575
|
+
let d;
|
|
574
576
|
try {
|
|
575
|
-
|
|
577
|
+
d = await this.config.ethWallet.sendTransaction({
|
|
576
578
|
to: this.config.vaultContracts.btcVaultRegistry,
|
|
577
579
|
data: P,
|
|
578
580
|
value: l,
|
|
@@ -581,19 +583,19 @@ class pn {
|
|
|
581
583
|
gas: w
|
|
582
584
|
});
|
|
583
585
|
} catch (p) {
|
|
584
|
-
|
|
586
|
+
A(p);
|
|
585
587
|
}
|
|
586
588
|
const g = await c.waitForTransactionReceipt({
|
|
587
|
-
hash:
|
|
588
|
-
timeout:
|
|
589
|
+
hash: d,
|
|
590
|
+
timeout: _t
|
|
589
591
|
});
|
|
590
|
-
return g.status === "reverted" &&
|
|
592
|
+
return g.status === "reverted" && A(
|
|
591
593
|
new Error(
|
|
592
|
-
`Batch transaction reverted. Hash: ${
|
|
594
|
+
`Batch transaction reverted. Hash: ${d}. Check the transaction on block explorer for details.`
|
|
593
595
|
)
|
|
594
596
|
), {
|
|
595
597
|
ethTxHash: g.transactionHash,
|
|
596
|
-
vaults:
|
|
598
|
+
vaults: u
|
|
597
599
|
};
|
|
598
600
|
}
|
|
599
601
|
/**
|
|
@@ -604,15 +606,15 @@ class pn {
|
|
|
604
606
|
*/
|
|
605
607
|
async checkVaultExists(t) {
|
|
606
608
|
try {
|
|
607
|
-
return (await
|
|
609
|
+
return (await q({
|
|
608
610
|
chain: this.config.ethChain,
|
|
609
|
-
transport:
|
|
611
|
+
transport: Z()
|
|
610
612
|
}).readContract({
|
|
611
613
|
address: this.config.vaultContracts.btcVaultRegistry,
|
|
612
|
-
abi:
|
|
614
|
+
abi: O,
|
|
613
615
|
functionName: "getBtcVaultBasicInfo",
|
|
614
616
|
args: [t]
|
|
615
|
-
}))[0] !==
|
|
617
|
+
}))[0] !== oe;
|
|
616
618
|
} catch {
|
|
617
619
|
return !1;
|
|
618
620
|
}
|
|
@@ -631,7 +633,7 @@ class pn {
|
|
|
631
633
|
else {
|
|
632
634
|
n = await this.config.btcWallet.getAddress();
|
|
633
635
|
const o = await this.config.btcWallet.getPublicKeyHex();
|
|
634
|
-
if (!
|
|
636
|
+
if (!he(
|
|
635
637
|
n,
|
|
636
638
|
o,
|
|
637
639
|
this.config.btcNetwork
|
|
@@ -640,9 +642,9 @@ class pn {
|
|
|
640
642
|
"The BTC address from your wallet does not match the wallet's public key. Please ensure your wallet is using a supported address type (Taproot or Native SegWit)."
|
|
641
643
|
);
|
|
642
644
|
}
|
|
643
|
-
const s =
|
|
645
|
+
const s = kt(this.config.btcNetwork);
|
|
644
646
|
try {
|
|
645
|
-
return `0x${
|
|
647
|
+
return `0x${ne.address.toOutputScript(n, s).toString("hex")}`;
|
|
646
648
|
} catch {
|
|
647
649
|
throw new Error(
|
|
648
650
|
`Invalid BTC payout address: "${n}". Please provide a valid Bitcoin address for the ${this.config.btcNetwork} network.`
|
|
@@ -665,7 +667,7 @@ class pn {
|
|
|
665
667
|
"bip322-simple"
|
|
666
668
|
);
|
|
667
669
|
return {
|
|
668
|
-
btcPopSignature:
|
|
670
|
+
btcPopSignature: Oe(r),
|
|
669
671
|
depositorEthAddress: t,
|
|
670
672
|
depositorBtcPubkey: n
|
|
671
673
|
};
|
|
@@ -696,7 +698,7 @@ class pn {
|
|
|
696
698
|
return this.config.vaultContracts.btcVaultRegistry;
|
|
697
699
|
}
|
|
698
700
|
}
|
|
699
|
-
class
|
|
701
|
+
class Ft {
|
|
700
702
|
constructor(t, n) {
|
|
701
703
|
b(this, "oHash");
|
|
702
704
|
b(this, "iHash");
|
|
@@ -704,7 +706,7 @@ class kt {
|
|
|
704
706
|
b(this, "outputLen");
|
|
705
707
|
b(this, "finished", !1);
|
|
706
708
|
b(this, "destroyed", !1);
|
|
707
|
-
if (
|
|
709
|
+
if (ht(t), U(n, void 0, "key"), this.iHash = t.create(), typeof this.iHash.update != "function")
|
|
708
710
|
throw new Error("Expected instance of class which extends utils.Hash");
|
|
709
711
|
this.blockLen = this.iHash.blockLen, this.outputLen = this.iHash.outputLen;
|
|
710
712
|
const s = this.blockLen, o = new Uint8Array(s);
|
|
@@ -714,13 +716,13 @@ class kt {
|
|
|
714
716
|
this.iHash.update(o), this.oHash = t.create();
|
|
715
717
|
for (let r = 0; r < o.length; r++)
|
|
716
718
|
o[r] ^= 106;
|
|
717
|
-
this.oHash.update(o),
|
|
719
|
+
this.oHash.update(o), S(o);
|
|
718
720
|
}
|
|
719
721
|
update(t) {
|
|
720
722
|
return V(this), this.iHash.update(t), this;
|
|
721
723
|
}
|
|
722
724
|
digestInto(t) {
|
|
723
|
-
V(this),
|
|
725
|
+
V(this), U(t, this.outputLen, "output"), this.finished = !0, this.iHash.digestInto(t), this.oHash.update(t), this.oHash.digestInto(t), this.destroy();
|
|
724
726
|
}
|
|
725
727
|
digest() {
|
|
726
728
|
const t = new Uint8Array(this.oHash.outputLen);
|
|
@@ -738,9 +740,9 @@ class kt {
|
|
|
738
740
|
this.destroyed = !0, this.oHash.destroy(), this.iHash.destroy();
|
|
739
741
|
}
|
|
740
742
|
}
|
|
741
|
-
const
|
|
742
|
-
|
|
743
|
-
const
|
|
743
|
+
const K = (e, t, n) => new Ft(e, t).update(n).digest();
|
|
744
|
+
K.create = (e, t) => new Ft(e, t);
|
|
745
|
+
const Le = /* @__PURE__ */ Uint8Array.from([
|
|
744
746
|
7,
|
|
745
747
|
4,
|
|
746
748
|
13,
|
|
@@ -757,36 +759,36 @@ const we = /* @__PURE__ */ Uint8Array.from([
|
|
|
757
759
|
14,
|
|
758
760
|
11,
|
|
759
761
|
8
|
|
760
|
-
]),
|
|
761
|
-
const n = [[
|
|
762
|
+
]), Mt = Uint8Array.from(new Array(16).fill(0).map((e, t) => t)), Re = Mt.map((e) => (9 * e + 5) % 16), Nt = /* @__PURE__ */ (() => {
|
|
763
|
+
const n = [[Mt], [Re]];
|
|
762
764
|
for (let s = 0; s < 4; s++)
|
|
763
765
|
for (let o of n)
|
|
764
|
-
o.push(o[s].map((r) =>
|
|
766
|
+
o.push(o[s].map((r) => Le[r]));
|
|
765
767
|
return n;
|
|
766
|
-
})(),
|
|
768
|
+
})(), Vt = Nt[0], Dt = Nt[1], Kt = /* @__PURE__ */ [
|
|
767
769
|
[11, 14, 15, 12, 5, 8, 7, 9, 11, 13, 14, 15, 6, 7, 9, 8],
|
|
768
770
|
[12, 13, 11, 15, 6, 9, 9, 7, 12, 15, 11, 13, 7, 8, 7, 7],
|
|
769
771
|
[13, 15, 14, 11, 7, 7, 6, 8, 13, 14, 13, 12, 5, 5, 6, 9],
|
|
770
772
|
[14, 11, 12, 14, 8, 6, 5, 5, 15, 12, 15, 14, 9, 9, 8, 6],
|
|
771
773
|
[15, 12, 13, 13, 9, 5, 8, 6, 14, 11, 12, 11, 8, 6, 5, 5]
|
|
772
|
-
].map((e) => Uint8Array.from(e)),
|
|
774
|
+
].map((e) => Uint8Array.from(e)), Ue = /* @__PURE__ */ Vt.map((e, t) => e.map((n) => Kt[t][n])), We = /* @__PURE__ */ Dt.map((e, t) => e.map((n) => Kt[t][n])), Fe = /* @__PURE__ */ Uint32Array.from([
|
|
773
775
|
0,
|
|
774
776
|
1518500249,
|
|
775
777
|
1859775393,
|
|
776
778
|
2400959708,
|
|
777
779
|
2840853838
|
|
778
|
-
]),
|
|
780
|
+
]), Me = /* @__PURE__ */ Uint32Array.from([
|
|
779
781
|
1352829926,
|
|
780
782
|
1548603684,
|
|
781
783
|
1836072691,
|
|
782
784
|
2053994217,
|
|
783
785
|
0
|
|
784
786
|
]);
|
|
785
|
-
function
|
|
787
|
+
function vt(e, t, n, s) {
|
|
786
788
|
return e === 0 ? t ^ n ^ s : e === 1 ? t & n | ~t & s : e === 2 ? (t | ~n) ^ s : e === 3 ? t & s | n & ~s : t ^ (n | ~s);
|
|
787
789
|
}
|
|
788
|
-
const
|
|
789
|
-
class
|
|
790
|
+
const M = /* @__PURE__ */ new Uint32Array(16);
|
|
791
|
+
class Ne extends be {
|
|
790
792
|
constructor() {
|
|
791
793
|
super(64, 20, 8, !0);
|
|
792
794
|
b(this, "h0", 1732584193);
|
|
@@ -803,52 +805,52 @@ class Te extends te {
|
|
|
803
805
|
this.h0 = n | 0, this.h1 = s | 0, this.h2 = o | 0, this.h3 = r | 0, this.h4 = i | 0;
|
|
804
806
|
}
|
|
805
807
|
process(n, s) {
|
|
806
|
-
for (let
|
|
807
|
-
|
|
808
|
-
let o = this.h0 | 0, r = o, i = this.h1 | 0, a = i,
|
|
809
|
-
for (let
|
|
810
|
-
const x = 4 -
|
|
808
|
+
for (let f = 0; f < 16; f++, s += 4)
|
|
809
|
+
M[f] = n.getUint32(s, !0);
|
|
810
|
+
let o = this.h0 | 0, r = o, i = this.h1 | 0, a = i, h = this.h2 | 0, u = h, c = this.h3 | 0, m = c, l = this.h4 | 0, y = l;
|
|
811
|
+
for (let f = 0; f < 5; f++) {
|
|
812
|
+
const x = 4 - f, P = Fe[f], w = Me[f], d = Vt[f], g = Dt[f], p = Ue[f], E = We[f];
|
|
811
813
|
for (let k = 0; k < 16; k++) {
|
|
812
|
-
const
|
|
813
|
-
o = l, l = c, c =
|
|
814
|
+
const _ = F(o + vt(f, i, h, c) + M[d[k]] + P, p[k]) + l | 0;
|
|
815
|
+
o = l, l = c, c = F(h, 10) | 0, h = i, i = _;
|
|
814
816
|
}
|
|
815
817
|
for (let k = 0; k < 16; k++) {
|
|
816
|
-
const
|
|
817
|
-
r = y, y = m, m =
|
|
818
|
+
const _ = F(r + vt(x, a, u, m) + M[g[k]] + w, E[k]) + y | 0;
|
|
819
|
+
r = y, y = m, m = F(u, 10) | 0, u = a, a = _;
|
|
818
820
|
}
|
|
819
821
|
}
|
|
820
|
-
this.set(this.h1 +
|
|
822
|
+
this.set(this.h1 + h + m | 0, this.h2 + c + y | 0, this.h3 + l + r | 0, this.h4 + o + a | 0, this.h0 + i + u | 0);
|
|
821
823
|
}
|
|
822
824
|
roundClean() {
|
|
823
|
-
|
|
825
|
+
S(M);
|
|
824
826
|
}
|
|
825
827
|
destroy() {
|
|
826
|
-
this.destroyed = !0,
|
|
828
|
+
this.destroyed = !0, S(this.buffer), this.set(0, 0, 0, 0, 0);
|
|
827
829
|
}
|
|
828
830
|
}
|
|
829
|
-
const
|
|
830
|
-
for (let e = 0, t =
|
|
831
|
-
[n, s] = [s, (2 * n + 3 * s) % 5],
|
|
832
|
-
let o =
|
|
831
|
+
const Ve = /* @__PURE__ */ Ut(() => new Ne()), De = BigInt(0), L = BigInt(1), Ke = BigInt(2), Xe = BigInt(7), je = BigInt(256), qe = BigInt(113), Xt = [], jt = [], qt = [];
|
|
832
|
+
for (let e = 0, t = L, n = 1, s = 0; e < 24; e++) {
|
|
833
|
+
[n, s] = [s, (2 * n + 3 * s) % 5], Xt.push(2 * (5 * s + n)), jt.push((e + 1) * (e + 2) / 2 % 64);
|
|
834
|
+
let o = De;
|
|
833
835
|
for (let r = 0; r < 7; r++)
|
|
834
|
-
t = (t <<
|
|
835
|
-
|
|
836
|
+
t = (t << L ^ (t >> Xe) * qe) % je, t & Ke && (o ^= L << (L << BigInt(r)) - L);
|
|
837
|
+
qt.push(o);
|
|
836
838
|
}
|
|
837
|
-
const
|
|
838
|
-
function
|
|
839
|
+
const Zt = xe(qt, !0), Ze = Zt[0], Ge = Zt[1], Bt = (e, t, n) => n > 32 ? Ie(e, t, n) : Ee(e, t, n), St = (e, t, n) => n > 32 ? _e(e, t, n) : Te(e, t, n);
|
|
840
|
+
function ze(e, t = 24) {
|
|
839
841
|
const n = new Uint32Array(10);
|
|
840
842
|
for (let s = 24 - t; s < 24; s++) {
|
|
841
843
|
for (let i = 0; i < 10; i++)
|
|
842
844
|
n[i] = e[i] ^ e[i + 10] ^ e[i + 20] ^ e[i + 30] ^ e[i + 40];
|
|
843
845
|
for (let i = 0; i < 10; i += 2) {
|
|
844
|
-
const a = (i + 8) % 10,
|
|
846
|
+
const a = (i + 8) % 10, h = (i + 2) % 10, u = n[h], c = n[h + 1], m = Bt(u, c, 1) ^ n[a], l = St(u, c, 1) ^ n[a + 1];
|
|
845
847
|
for (let y = 0; y < 50; y += 10)
|
|
846
848
|
e[i + y] ^= m, e[i + y + 1] ^= l;
|
|
847
849
|
}
|
|
848
850
|
let o = e[2], r = e[3];
|
|
849
851
|
for (let i = 0; i < 24; i++) {
|
|
850
|
-
const a =
|
|
851
|
-
o = e[c], r = e[c + 1], e[c] =
|
|
852
|
+
const a = jt[i], h = Bt(o, r, a), u = St(o, r, a), c = Xt[i];
|
|
853
|
+
o = e[c], r = e[c + 1], e[c] = h, e[c + 1] = u;
|
|
852
854
|
}
|
|
853
855
|
for (let i = 0; i < 50; i += 10) {
|
|
854
856
|
for (let a = 0; a < 10; a++)
|
|
@@ -856,11 +858,11 @@ function Ae(e, t = 24) {
|
|
|
856
858
|
for (let a = 0; a < 10; a++)
|
|
857
859
|
e[i + a] ^= ~n[(a + 2) % 10] & n[(a + 4) % 10];
|
|
858
860
|
}
|
|
859
|
-
e[0] ^=
|
|
861
|
+
e[0] ^= Ze[s], e[1] ^= Ge[s];
|
|
860
862
|
}
|
|
861
|
-
|
|
863
|
+
S(n);
|
|
862
864
|
}
|
|
863
|
-
class
|
|
865
|
+
class ft {
|
|
864
866
|
// NOTE: we accept arguments in bytes instead of bits here.
|
|
865
867
|
constructor(t, n, s, o = !1, r = 24) {
|
|
866
868
|
b(this, "state");
|
|
@@ -874,18 +876,18 @@ class ot {
|
|
|
874
876
|
b(this, "outputLen");
|
|
875
877
|
b(this, "enableXOF", !1);
|
|
876
878
|
b(this, "rounds");
|
|
877
|
-
if (this.blockLen = t, this.suffix = n, this.outputLen = s, this.enableXOF = o, this.rounds = r,
|
|
879
|
+
if (this.blockLen = t, this.suffix = n, this.outputLen = s, this.enableXOF = o, this.rounds = r, C(s, "outputLen"), !(0 < t && t < 200))
|
|
878
880
|
throw new Error("only keccak-f1600 function is supported");
|
|
879
|
-
this.state = new Uint8Array(200), this.state32 =
|
|
881
|
+
this.state = new Uint8Array(200), this.state32 = Pe(this.state);
|
|
880
882
|
}
|
|
881
883
|
clone() {
|
|
882
884
|
return this._cloneInto();
|
|
883
885
|
}
|
|
884
886
|
keccak() {
|
|
885
|
-
|
|
887
|
+
Tt(this.state32), ze(this.state32, this.rounds), Tt(this.state32), this.posOut = 0, this.pos = 0;
|
|
886
888
|
}
|
|
887
889
|
update(t) {
|
|
888
|
-
V(this),
|
|
890
|
+
V(this), U(t);
|
|
889
891
|
const { blockLen: n, state: s } = this, o = t.length;
|
|
890
892
|
for (let r = 0; r < o; ) {
|
|
891
893
|
const i = Math.min(n - this.pos, o - r);
|
|
@@ -903,7 +905,7 @@ class ot {
|
|
|
903
905
|
t[s] ^= n, (n & 128) !== 0 && s === o - 1 && this.keccak(), t[o - 1] ^= 128, this.keccak();
|
|
904
906
|
}
|
|
905
907
|
writeInto(t) {
|
|
906
|
-
V(this, !1),
|
|
908
|
+
V(this, !1), U(t), this.finish();
|
|
907
909
|
const n = this.state, { blockLen: s } = this;
|
|
908
910
|
for (let o = 0, r = t.length; o < r; ) {
|
|
909
911
|
this.posOut >= s && this.keccak();
|
|
@@ -918,10 +920,10 @@ class ot {
|
|
|
918
920
|
return this.writeInto(t);
|
|
919
921
|
}
|
|
920
922
|
xof(t) {
|
|
921
|
-
return
|
|
923
|
+
return C(t), this.xofInto(new Uint8Array(t));
|
|
922
924
|
}
|
|
923
925
|
digestInto(t) {
|
|
924
|
-
if (
|
|
926
|
+
if (ke(t, this), this.finished)
|
|
925
927
|
throw new Error("digest() was already called");
|
|
926
928
|
return this.writeInto(t), this.destroy(), t;
|
|
927
929
|
}
|
|
@@ -929,93 +931,93 @@ class ot {
|
|
|
929
931
|
return this.digestInto(new Uint8Array(this.outputLen));
|
|
930
932
|
}
|
|
931
933
|
destroy() {
|
|
932
|
-
this.destroyed = !0,
|
|
934
|
+
this.destroyed = !0, S(this.state);
|
|
933
935
|
}
|
|
934
936
|
_cloneInto(t) {
|
|
935
937
|
const { blockLen: n, suffix: s, outputLen: o, rounds: r, enableXOF: i } = this;
|
|
936
|
-
return t || (t = new
|
|
938
|
+
return t || (t = new ft(n, s, o, i, r)), t.state32.set(this.state32), t.pos = this.pos, t.posOut = this.posOut, t.finished = this.finished, t.rounds = r, t.suffix = s, t.outputLen = o, t.enableXOF = i, t.destroyed = this.destroyed, t;
|
|
937
939
|
}
|
|
938
940
|
}
|
|
939
|
-
const
|
|
940
|
-
function
|
|
941
|
-
|
|
942
|
-
const o =
|
|
943
|
-
if (
|
|
941
|
+
const Ye = (e, t, n, s = {}) => Ut(() => new ft(t, e, n), s), Je = /* @__PURE__ */ Ye(1, 136, 32);
|
|
942
|
+
function Qe(e, t, n, s) {
|
|
943
|
+
ht(e);
|
|
944
|
+
const o = Be({ dkLen: 32, asyncTick: 10 }, s), { c: r, dkLen: i, asyncTick: a } = o;
|
|
945
|
+
if (C(r, "c"), C(i, "dkLen"), C(a, "asyncTick"), r < 1)
|
|
944
946
|
throw new Error("iterations (c) must be >= 1");
|
|
945
|
-
const
|
|
947
|
+
const h = It(t, "password"), u = It(n, "salt"), c = new Uint8Array(i), m = K.create(e, h), l = m._cloneInto().update(u);
|
|
946
948
|
return { c: r, dkLen: i, asyncTick: a, DK: c, PRF: m, PRFSalt: l };
|
|
947
949
|
}
|
|
948
|
-
function
|
|
949
|
-
return e.destroy(), t.destroy(), s && s.destroy(),
|
|
950
|
+
function tn(e, t, n, s, o) {
|
|
951
|
+
return e.destroy(), t.destroy(), s && s.destroy(), S(o), n;
|
|
950
952
|
}
|
|
951
|
-
function
|
|
952
|
-
const { c: o, dkLen: r, DK: i, PRF: a, PRFSalt:
|
|
953
|
-
let
|
|
954
|
-
const c = new Uint8Array(4), m =
|
|
955
|
-
for (let y = 1,
|
|
956
|
-
const x = i.subarray(
|
|
957
|
-
m.setInt32(0, y, !1), (
|
|
953
|
+
function en(e, t, n, s) {
|
|
954
|
+
const { c: o, dkLen: r, DK: i, PRF: a, PRFSalt: h } = Qe(e, t, n, s);
|
|
955
|
+
let u;
|
|
956
|
+
const c = new Uint8Array(4), m = ve(c), l = new Uint8Array(a.outputLen);
|
|
957
|
+
for (let y = 1, f = 0; f < r; y++, f += a.outputLen) {
|
|
958
|
+
const x = i.subarray(f, f + a.outputLen);
|
|
959
|
+
m.setInt32(0, y, !1), (u = h._cloneInto(u)).update(c).digestInto(l), x.set(l.subarray(0, x.length));
|
|
958
960
|
for (let P = 1; P < o; P++) {
|
|
959
|
-
a._cloneInto(
|
|
961
|
+
a._cloneInto(u).update(l).digestInto(l);
|
|
960
962
|
for (let w = 0; w < x.length; w++)
|
|
961
963
|
x[w] ^= l[w];
|
|
962
964
|
}
|
|
963
965
|
}
|
|
964
|
-
return
|
|
966
|
+
return tn(a, h, i, u, l);
|
|
965
967
|
}
|
|
966
|
-
function
|
|
968
|
+
function Gt(e) {
|
|
967
969
|
if (typeof e != "string")
|
|
968
970
|
throw new TypeError("invalid mnemonic type: " + typeof e);
|
|
969
971
|
return e.normalize("NFKD");
|
|
970
972
|
}
|
|
971
|
-
function
|
|
972
|
-
const t =
|
|
973
|
+
function nn(e) {
|
|
974
|
+
const t = Gt(e), n = t.split(" ");
|
|
973
975
|
if (![12, 15, 18, 21, 24].includes(n.length))
|
|
974
976
|
throw new Error("Invalid mnemonic");
|
|
975
977
|
return { nfkd: t, words: n };
|
|
976
978
|
}
|
|
977
|
-
const
|
|
978
|
-
function
|
|
979
|
-
return
|
|
979
|
+
const sn = (e) => Gt("mnemonic" + e);
|
|
980
|
+
function on(e, t = "") {
|
|
981
|
+
return en(Wt, nn(e).nfkd, sn(t), { c: 2048, dkLen: 64 });
|
|
980
982
|
}
|
|
981
|
-
const
|
|
982
|
-
function
|
|
983
|
+
const z = 32, Y = 64, rn = 4, T = 20, at = 4, zt = 2, an = 0, cn = 1, N = [64, 64];
|
|
984
|
+
function ct(...e) {
|
|
983
985
|
const t = e.reduce((o, r) => o + r.length, 0), n = new Uint8Array(t);
|
|
984
986
|
let s = 0;
|
|
985
987
|
for (const o of e)
|
|
986
988
|
n.set(o, s), s += o.length;
|
|
987
989
|
return n;
|
|
988
990
|
}
|
|
989
|
-
function
|
|
991
|
+
function J(e) {
|
|
990
992
|
return new TextEncoder().encode(e);
|
|
991
993
|
}
|
|
992
|
-
function
|
|
993
|
-
const t = new Uint8Array(
|
|
994
|
-
return new DataView(t.buffer).setUint32(0, e.length, !1),
|
|
994
|
+
function Q(e) {
|
|
995
|
+
const t = new Uint8Array(rn);
|
|
996
|
+
return new DataView(t.buffer).setUint32(0, e.length, !1), ct(t, e);
|
|
995
997
|
}
|
|
996
|
-
function
|
|
998
|
+
function At(e) {
|
|
997
999
|
return e.startsWith("0x") || e.startsWith("0X") ? e.slice(2) : e;
|
|
998
1000
|
}
|
|
999
|
-
const
|
|
1000
|
-
function
|
|
1001
|
-
return
|
|
1001
|
+
const ln = (e) => Array.from(e).map((t) => t.toString(16).padStart(2, "0")).join("");
|
|
1002
|
+
function un(e, t) {
|
|
1003
|
+
return K(Wt, e, t);
|
|
1002
1004
|
}
|
|
1003
|
-
function
|
|
1004
|
-
return
|
|
1005
|
+
function gt(e) {
|
|
1006
|
+
return Ve(W(e));
|
|
1005
1007
|
}
|
|
1006
|
-
function
|
|
1008
|
+
function Yt(e) {
|
|
1007
1009
|
return (1 << e) - 1;
|
|
1008
1010
|
}
|
|
1009
|
-
function
|
|
1011
|
+
function hn(e) {
|
|
1010
1012
|
let t = 1;
|
|
1011
1013
|
for (; t * t < e + 1; ) t++;
|
|
1012
1014
|
return Math.max(t, 2);
|
|
1013
1015
|
}
|
|
1014
|
-
function
|
|
1015
|
-
const t =
|
|
1016
|
-
return { d: t, n: e, checksum_radix:
|
|
1016
|
+
function dn(e) {
|
|
1017
|
+
const t = at, n = Yt(t), s = e * n;
|
|
1018
|
+
return { d: t, n: e, checksum_radix: hn(s) };
|
|
1017
1019
|
}
|
|
1018
|
-
function
|
|
1020
|
+
function tt(e, t) {
|
|
1019
1021
|
const n = [];
|
|
1020
1022
|
let s = t;
|
|
1021
1023
|
for (; s > 0; )
|
|
@@ -1024,96 +1026,96 @@ function Z(e, t) {
|
|
|
1024
1026
|
o.set(e);
|
|
1025
1027
|
for (let r = 0; r < n.length; r++)
|
|
1026
1028
|
o[e.length + r] = n[r];
|
|
1027
|
-
return
|
|
1029
|
+
return gt(o);
|
|
1028
1030
|
}
|
|
1029
|
-
function
|
|
1031
|
+
function et(e, t) {
|
|
1030
1032
|
let n = e;
|
|
1031
1033
|
for (let s = 0; s < t; s++)
|
|
1032
|
-
n =
|
|
1034
|
+
n = gt(n);
|
|
1033
1035
|
return n;
|
|
1034
1036
|
}
|
|
1035
|
-
function
|
|
1036
|
-
const n =
|
|
1037
|
+
function fn(e, t) {
|
|
1038
|
+
const n = Yt(t.d), s = t.checksum_radix - 1, o = Math.floor(t.n * n / t.checksum_radix), r = [];
|
|
1037
1039
|
for (let c = 0; c < t.n; c++) {
|
|
1038
|
-
const m =
|
|
1040
|
+
const m = tt(e, c + zt), l = et(m, n);
|
|
1039
1041
|
r.push(Array.from(l));
|
|
1040
1042
|
}
|
|
1041
|
-
const i =
|
|
1043
|
+
const i = tt(
|
|
1042
1044
|
e,
|
|
1043
|
-
|
|
1044
|
-
), a =
|
|
1045
|
+
an
|
|
1046
|
+
), a = et(
|
|
1045
1047
|
i,
|
|
1046
1048
|
s
|
|
1047
|
-
),
|
|
1049
|
+
), h = tt(
|
|
1048
1050
|
e,
|
|
1049
|
-
|
|
1050
|
-
),
|
|
1051
|
-
|
|
1051
|
+
cn
|
|
1052
|
+
), u = et(
|
|
1053
|
+
h,
|
|
1052
1054
|
o
|
|
1053
1055
|
);
|
|
1054
1056
|
return {
|
|
1055
1057
|
config: t,
|
|
1056
1058
|
message_terminals: r,
|
|
1057
|
-
checksum_major_terminal: Array.from(
|
|
1059
|
+
checksum_major_terminal: Array.from(u),
|
|
1058
1060
|
checksum_minor_terminal: Array.from(a)
|
|
1059
1061
|
};
|
|
1060
1062
|
}
|
|
1061
|
-
function
|
|
1062
|
-
const t =
|
|
1063
|
+
function gn(e) {
|
|
1064
|
+
const t = on(e), n = new Uint8Array(t);
|
|
1063
1065
|
return t.fill(0), n;
|
|
1064
1066
|
}
|
|
1065
|
-
async function
|
|
1066
|
-
if (e.length !==
|
|
1067
|
+
async function pn(e, t, n, s) {
|
|
1068
|
+
if (e.length !== Y)
|
|
1067
1069
|
throw new Error(
|
|
1068
|
-
`WOTS seed must be exactly ${
|
|
1070
|
+
`WOTS seed must be exactly ${Y} bytes, got ${e.length}`
|
|
1069
1071
|
);
|
|
1070
|
-
const o =
|
|
1072
|
+
const o = At(t).toLowerCase(), r = At(n).toLowerCase(), i = e.slice(z, Y), a = e.slice(0, z), h = ct(
|
|
1071
1073
|
a,
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1074
|
+
ct(
|
|
1075
|
+
Q(J(o)),
|
|
1076
|
+
Q(J(r)),
|
|
1077
|
+
Q(J(s.toLowerCase()))
|
|
1076
1078
|
)
|
|
1077
|
-
),
|
|
1079
|
+
), u = un(i, h), c = u.slice(0, z);
|
|
1078
1080
|
try {
|
|
1079
1081
|
const m = [];
|
|
1080
|
-
for (let l = 0; l <
|
|
1081
|
-
const y =
|
|
1082
|
+
for (let l = 0; l < N.length; l++) {
|
|
1083
|
+
const y = N[l], f = dn(y), x = new Uint8Array(c.length + 1);
|
|
1082
1084
|
x.set(c), x[c.length] = l;
|
|
1083
|
-
const P =
|
|
1085
|
+
const P = gt(x);
|
|
1084
1086
|
try {
|
|
1085
|
-
const w =
|
|
1086
|
-
if (w.config.d !==
|
|
1087
|
-
throw new Error(`Block ${l}: expected d=${
|
|
1087
|
+
const w = fn(P, f);
|
|
1088
|
+
if (w.config.d !== at)
|
|
1089
|
+
throw new Error(`Block ${l}: expected d=${at}, got d=${w.config.d}`);
|
|
1088
1090
|
if (w.config.n !== y)
|
|
1089
1091
|
throw new Error(`Block ${l}: expected n=${y}, got n=${w.config.n}`);
|
|
1090
1092
|
if (w.message_terminals.length !== y)
|
|
1091
1093
|
throw new Error(`Block ${l}: expected ${y} message terminals, got ${w.message_terminals.length}`);
|
|
1092
|
-
for (let
|
|
1093
|
-
if (w.message_terminals[
|
|
1094
|
-
throw new Error(`Block ${l} terminal ${
|
|
1095
|
-
if (w.checksum_minor_terminal.length !==
|
|
1096
|
-
throw new Error(`Block ${l} checksum_minor: expected ${
|
|
1097
|
-
if (w.checksum_major_terminal.length !==
|
|
1098
|
-
throw new Error(`Block ${l} checksum_major: expected ${
|
|
1094
|
+
for (let d = 0; d < w.message_terminals.length; d++)
|
|
1095
|
+
if (w.message_terminals[d].length !== T)
|
|
1096
|
+
throw new Error(`Block ${l} terminal ${d}: expected ${T} bytes, got ${w.message_terminals[d].length}`);
|
|
1097
|
+
if (w.checksum_minor_terminal.length !== T)
|
|
1098
|
+
throw new Error(`Block ${l} checksum_minor: expected ${T} bytes`);
|
|
1099
|
+
if (w.checksum_major_terminal.length !== T)
|
|
1100
|
+
throw new Error(`Block ${l} checksum_major: expected ${T} bytes`);
|
|
1099
1101
|
m.push(w);
|
|
1100
1102
|
} finally {
|
|
1101
1103
|
x.fill(0), P.fill(0);
|
|
1102
1104
|
}
|
|
1103
1105
|
}
|
|
1104
|
-
if (m.length !==
|
|
1106
|
+
if (m.length !== N.length)
|
|
1105
1107
|
throw new Error(
|
|
1106
|
-
`Expected ${
|
|
1108
|
+
`Expected ${N.length} blocks, got ${m.length}`
|
|
1107
1109
|
);
|
|
1108
1110
|
return m;
|
|
1109
1111
|
} finally {
|
|
1110
|
-
|
|
1112
|
+
h.fill(0), i.fill(0), a.fill(0), u.fill(0), c.fill(0), e.fill(0);
|
|
1111
1113
|
}
|
|
1112
1114
|
}
|
|
1113
|
-
function
|
|
1114
|
-
if (e.length !==
|
|
1115
|
+
function nt(e, t, n) {
|
|
1116
|
+
if (e.length !== T)
|
|
1115
1117
|
throw new Error(
|
|
1116
|
-
`Block ${t} ${n}: expected ${
|
|
1118
|
+
`Block ${t} ${n}: expected ${T} bytes, got ${e.length}`
|
|
1117
1119
|
);
|
|
1118
1120
|
for (let s = 0; s < e.length; s++) {
|
|
1119
1121
|
const o = e[s];
|
|
@@ -1123,57 +1125,173 @@ function Q(e, t, n) {
|
|
|
1123
1125
|
);
|
|
1124
1126
|
}
|
|
1125
1127
|
}
|
|
1126
|
-
function
|
|
1128
|
+
function mn(e) {
|
|
1127
1129
|
if (e.length === 0)
|
|
1128
1130
|
throw new Error("Public keys array must not be empty");
|
|
1129
1131
|
for (let r = 0; r < e.length; r++) {
|
|
1130
1132
|
const i = e[r];
|
|
1131
|
-
|
|
1133
|
+
nt(i.checksum_minor_terminal, r, "checksum_minor_terminal"), nt(i.checksum_major_terminal, r, "checksum_major_terminal");
|
|
1132
1134
|
for (let a = 0; a < i.message_terminals.length; a++)
|
|
1133
|
-
|
|
1135
|
+
nt(i.message_terminals[a], r, `message_terminal[${a}]`);
|
|
1134
1136
|
}
|
|
1135
1137
|
let t = 0;
|
|
1136
1138
|
for (const r of e)
|
|
1137
|
-
t +=
|
|
1138
|
-
const n = new Uint8Array(t *
|
|
1139
|
+
t += zt + r.message_terminals.length;
|
|
1140
|
+
const n = new Uint8Array(t * T);
|
|
1139
1141
|
let s = 0;
|
|
1140
1142
|
for (const r of e) {
|
|
1141
|
-
n.set(r.checksum_minor_terminal, s), s +=
|
|
1143
|
+
n.set(r.checksum_minor_terminal, s), s += T, n.set(r.checksum_major_terminal, s), s += T;
|
|
1142
1144
|
for (const i of r.message_terminals)
|
|
1143
|
-
n.set(i, s), s +=
|
|
1145
|
+
n.set(i, s), s += T;
|
|
1144
1146
|
}
|
|
1145
|
-
const o =
|
|
1146
|
-
return `0x${
|
|
1147
|
+
const o = Je(n);
|
|
1148
|
+
return `0x${ln(o)}`;
|
|
1147
1149
|
}
|
|
1148
|
-
async function
|
|
1149
|
-
const o =
|
|
1150
|
+
async function Vn(e, t, n, s) {
|
|
1151
|
+
const o = gn(e);
|
|
1150
1152
|
try {
|
|
1151
|
-
const r = await
|
|
1153
|
+
const r = await pn(
|
|
1152
1154
|
o,
|
|
1153
1155
|
t,
|
|
1154
1156
|
n,
|
|
1155
1157
|
s
|
|
1156
1158
|
);
|
|
1157
|
-
return
|
|
1159
|
+
return mn(r);
|
|
1158
1160
|
} finally {
|
|
1159
1161
|
o.fill(0);
|
|
1160
1162
|
}
|
|
1161
1163
|
}
|
|
1162
|
-
function
|
|
1164
|
+
function Dn(e) {
|
|
1163
1165
|
const t = (e instanceof Error ? e.message : typeof e == "string" ? e : "").toLowerCase();
|
|
1164
1166
|
return t.includes("wots") && t.includes("hash") && t.includes("does not match");
|
|
1165
1167
|
}
|
|
1168
|
+
const st = /* @__PURE__ */ Uint8Array.of(0), Ct = /* @__PURE__ */ Uint8Array.of();
|
|
1169
|
+
function pt(e, t, n, s = 32) {
|
|
1170
|
+
ht(e), C(s, "length");
|
|
1171
|
+
const o = e.outputLen;
|
|
1172
|
+
if (s > 255 * o)
|
|
1173
|
+
throw new Error("Length must be <= 255*HashLen");
|
|
1174
|
+
const r = Math.ceil(s / o);
|
|
1175
|
+
n === void 0 ? n = Ct : U(n, void 0, "info");
|
|
1176
|
+
const i = new Uint8Array(r * o), a = K.create(e, t), h = a._cloneInto(), u = new Uint8Array(a.outputLen);
|
|
1177
|
+
for (let c = 0; c < r; c++)
|
|
1178
|
+
st[0] = c + 1, h.update(c === 0 ? Ct : u).update(n).update(st).digestInto(u), i.set(u, o * c), a._cloneInto(h);
|
|
1179
|
+
return a.destroy(), h.destroy(), S(u, st), i.slice(0, s);
|
|
1180
|
+
}
|
|
1181
|
+
const ot = new TextEncoder().encode("babylonvault"), Ht = 255, Ot = 65535, $t = 2, wn = "hashlock", yn = "auth-anchor", bn = "wots-seed";
|
|
1182
|
+
function Jt(e) {
|
|
1183
|
+
if (!Number.isInteger(e) || e < 0 || e > 4294967295)
|
|
1184
|
+
throw new Error(`i2osp4: value must be a u32, got ${e}`);
|
|
1185
|
+
const t = new Uint8Array(4);
|
|
1186
|
+
return t[0] = e >>> 24 & 255, t[1] = e >>> 16 & 255, t[2] = e >>> 8 & 255, t[3] = e & 255, t;
|
|
1187
|
+
}
|
|
1188
|
+
function mt(e, t = new Uint8Array(0)) {
|
|
1189
|
+
const n = new TextEncoder().encode(e);
|
|
1190
|
+
if (n.length === 0 || n.length > Ht)
|
|
1191
|
+
throw new Error(
|
|
1192
|
+
`info: label length must be in [1, ${Ht}], got ${n.length}`
|
|
1193
|
+
);
|
|
1194
|
+
if (t.length > Ot)
|
|
1195
|
+
throw new Error(
|
|
1196
|
+
`info: ctx length must be in [0, ${Ot}], got ${t.length}`
|
|
1197
|
+
);
|
|
1198
|
+
const s = ot.length + 1 + n.length + $t + t.length, o = new Uint8Array(s);
|
|
1199
|
+
let r = 0;
|
|
1200
|
+
return o.set(ot, r), r += ot.length, o[r] = n.length, r += 1, o.set(n, r), r += n.length, o[r] = t.length >>> 8 & 255, o[r + 1] = t.length & 255, r += $t, o.set(t, r), o;
|
|
1201
|
+
}
|
|
1202
|
+
const Lt = 32, xn = 32, Pn = 32, kn = 64;
|
|
1203
|
+
function wt(e) {
|
|
1204
|
+
if (e.length !== Lt)
|
|
1205
|
+
throw new Error(
|
|
1206
|
+
`vault-secrets: root must be exactly ${Lt} bytes, got ${e.length}`
|
|
1207
|
+
);
|
|
1208
|
+
}
|
|
1209
|
+
function Kn(e) {
|
|
1210
|
+
return wt(e), pt(
|
|
1211
|
+
W,
|
|
1212
|
+
e,
|
|
1213
|
+
mt(yn),
|
|
1214
|
+
xn
|
|
1215
|
+
);
|
|
1216
|
+
}
|
|
1217
|
+
function Xn(e, t) {
|
|
1218
|
+
return wt(e), pt(
|
|
1219
|
+
W,
|
|
1220
|
+
e,
|
|
1221
|
+
mt(wn, Jt(t)),
|
|
1222
|
+
Pn
|
|
1223
|
+
);
|
|
1224
|
+
}
|
|
1225
|
+
function jn(e, t) {
|
|
1226
|
+
return wt(e), pt(
|
|
1227
|
+
W,
|
|
1228
|
+
e,
|
|
1229
|
+
mt(bn, Jt(t)),
|
|
1230
|
+
kn
|
|
1231
|
+
);
|
|
1232
|
+
}
|
|
1233
|
+
const R = 32, rt = 32, lt = 36, Qt = 32, D = 4, En = D + R + D + Qt;
|
|
1234
|
+
function ut(e, t, n) {
|
|
1235
|
+
e[t] = n >>> 24 & 255, e[t + 1] = n >>> 16 & 255, e[t + 2] = n >>> 8 & 255, e[t + 3] = n & 255;
|
|
1236
|
+
}
|
|
1237
|
+
function Tn(e) {
|
|
1238
|
+
if (e.txid.length !== rt)
|
|
1239
|
+
throw new Error(
|
|
1240
|
+
`outpoint.txid must be exactly ${rt} bytes, got ${e.txid.length}`
|
|
1241
|
+
);
|
|
1242
|
+
if (!Number.isInteger(e.vout) || e.vout < 0 || e.vout > 4294967295)
|
|
1243
|
+
throw new Error(`outpoint.vout must be a u32, got ${e.vout}`);
|
|
1244
|
+
const t = new Uint8Array(lt);
|
|
1245
|
+
return t.set(e.txid, 0), ut(t, rt, e.vout), t;
|
|
1246
|
+
}
|
|
1247
|
+
function Rt(e, t) {
|
|
1248
|
+
const n = Math.min(e.length, t.length);
|
|
1249
|
+
for (let s = 0; s < n; s++)
|
|
1250
|
+
if (e[s] !== t[s]) return e[s] - t[s];
|
|
1251
|
+
return e.length - t.length;
|
|
1252
|
+
}
|
|
1253
|
+
function In(e) {
|
|
1254
|
+
if (e.length === 0)
|
|
1255
|
+
throw new Error(
|
|
1256
|
+
"buildFundingOutpointsCommitment: outpoints must be non-empty"
|
|
1257
|
+
);
|
|
1258
|
+
const t = e.map(Tn);
|
|
1259
|
+
t.sort(Rt);
|
|
1260
|
+
for (let s = 1; s < t.length; s++)
|
|
1261
|
+
if (Rt(t[s - 1], t[s]) === 0)
|
|
1262
|
+
throw new Error(
|
|
1263
|
+
"buildFundingOutpointsCommitment: duplicate outpoint detected"
|
|
1264
|
+
);
|
|
1265
|
+
const n = new Uint8Array(t.length * lt);
|
|
1266
|
+
for (let s = 0; s < t.length; s++)
|
|
1267
|
+
n.set(t[s], s * lt);
|
|
1268
|
+
return W(n);
|
|
1269
|
+
}
|
|
1270
|
+
function qn(e) {
|
|
1271
|
+
if (e.depositorBtcPubkey.length !== R)
|
|
1272
|
+
throw new Error(
|
|
1273
|
+
`vaultContext: depositorBtcPubkey must be exactly ${R} bytes, got ${e.depositorBtcPubkey.length}`
|
|
1274
|
+
);
|
|
1275
|
+
const t = In(e.fundingOutpoints), n = new Uint8Array(En);
|
|
1276
|
+
let s = 0;
|
|
1277
|
+
return ut(n, s, R), s += D, n.set(e.depositorBtcPubkey, s), s += R, ut(n, s, Qt), s += D, n.set(t, s), n;
|
|
1278
|
+
}
|
|
1166
1279
|
export {
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1280
|
+
H as C,
|
|
1281
|
+
Nn as P,
|
|
1282
|
+
Vn as a,
|
|
1283
|
+
Dn as b,
|
|
1284
|
+
mn as c,
|
|
1285
|
+
pn as d,
|
|
1286
|
+
dt as e,
|
|
1287
|
+
Kn as f,
|
|
1288
|
+
Fn as g,
|
|
1289
|
+
A as h,
|
|
1290
|
+
Mn as i,
|
|
1291
|
+
Xn as j,
|
|
1292
|
+
jn as k,
|
|
1293
|
+
In as l,
|
|
1294
|
+
gn as m,
|
|
1295
|
+
qn as n
|
|
1178
1296
|
};
|
|
1179
|
-
//# sourceMappingURL=
|
|
1297
|
+
//# sourceMappingURL=context-CClNOyD3.js.map
|