@babylonlabs-io/ts-sdk 0.19.0 → 0.20.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/README.md +56 -12
- package/dist/bitcoin-CNnPFU6Y.cjs +2 -0
- package/dist/bitcoin-CNnPFU6Y.cjs.map +1 -0
- package/dist/{constants-Q7v2O7Ps.js → bitcoin-nOOgeRyl.js} +64 -76
- package/dist/bitcoin-nOOgeRyl.js.map +1 -0
- package/dist/buildAndBroadcastRefund-DWEQvj9T.cjs +2 -0
- package/dist/buildAndBroadcastRefund-DWEQvj9T.cjs.map +1 -0
- package/dist/buildAndBroadcastRefund-DnTQkCgG.js +1331 -0
- package/dist/buildAndBroadcastRefund-DnTQkCgG.js.map +1 -0
- package/dist/challengeAssert-D1lpvuMv.js +283 -0
- package/dist/challengeAssert-D1lpvuMv.js.map +1 -0
- package/dist/challengeAssert-nYlgeAI8.cjs +2 -0
- package/dist/challengeAssert-nYlgeAI8.cjs.map +1 -0
- package/dist/errors-BZON3Wmn.cjs +2 -0
- package/dist/errors-BZON3Wmn.cjs.map +1 -0
- package/dist/{errors-aMocmFr-.js → errors-CHY4WNi-.js} +98 -97
- package/dist/errors-CHY4WNi-.js.map +1 -0
- package/dist/fundPeginTransaction-BLYXxLBv.js +70 -0
- package/dist/fundPeginTransaction-BLYXxLBv.js.map +1 -0
- package/dist/fundPeginTransaction-DxNOeyNI.cjs +2 -0
- package/dist/fundPeginTransaction-DxNOeyNI.cjs.map +1 -0
- package/dist/index-BpXpESWu.cjs +2 -0
- package/dist/index-BpXpESWu.cjs.map +1 -0
- package/dist/{index-BvFLf3vm.js → index-CFwoGJNQ.js} +146 -518
- package/dist/index-CFwoGJNQ.js.map +1 -0
- package/dist/index.cjs +1 -1
- package/dist/index.js +133 -109
- package/dist/payout-DzGsAnhf.js +261 -0
- package/dist/payout-DzGsAnhf.js.map +1 -0
- package/dist/payout-RFIh7GLN.cjs +2 -0
- package/dist/payout-RFIh7GLN.cjs.map +1 -0
- package/dist/psbtInputFields-C-zYR1z7.cjs +2 -0
- package/dist/psbtInputFields-C-zYR1z7.cjs.map +1 -0
- package/dist/psbtInputFields-Dx41_IoI.js +229 -0
- package/dist/psbtInputFields-Dx41_IoI.js.map +1 -0
- package/dist/signing-DeWVBl7m.js +64 -0
- package/dist/signing-DeWVBl7m.js.map +1 -0
- package/dist/signing-cl-lowxV.cjs +2 -0
- package/dist/signing-cl-lowxV.cjs.map +1 -0
- package/dist/tbv/core/clients/index.cjs +1 -1
- package/dist/tbv/core/clients/index.js +2 -2
- package/dist/tbv/core/index.cjs +1 -1
- package/dist/tbv/core/index.d.ts +3 -1
- package/dist/tbv/core/index.d.ts.map +1 -1
- package/dist/tbv/core/index.js +130 -106
- package/dist/tbv/core/managers/PeginManager.d.ts +1 -1
- package/dist/tbv/core/primitives/index.cjs +1 -1
- package/dist/tbv/core/primitives/index.d.ts +3 -2
- package/dist/tbv/core/primitives/index.d.ts.map +1 -1
- package/dist/tbv/core/primitives/index.js +24 -23
- package/dist/tbv/core/primitives/psbt/__tests__/helpers.d.ts +1 -1
- package/dist/tbv/core/primitives/psbt/index.d.ts +1 -1
- package/dist/tbv/core/primitives/psbt/payout.d.ts.map +1 -1
- package/dist/tbv/core/primitives/psbt/pegin.d.ts +2 -3
- package/dist/tbv/core/primitives/psbt/pegin.d.ts.map +1 -1
- package/dist/tbv/core/primitives/utils/bitcoin.d.ts +4 -0
- package/dist/tbv/core/primitives/utils/bitcoin.d.ts.map +1 -1
- package/dist/tbv/core/primitives/utils/index.d.ts +1 -1
- package/dist/tbv/core/primitives/utils/index.d.ts.map +1 -1
- package/dist/tbv/core/services/activation/__tests__/activateVault.test.d.ts +2 -0
- package/dist/tbv/core/services/activation/__tests__/activateVault.test.d.ts.map +1 -0
- package/dist/tbv/core/services/activation/activateVault.d.ts +77 -0
- package/dist/tbv/core/services/activation/activateVault.d.ts.map +1 -0
- package/dist/tbv/core/services/activation/index.d.ts +7 -0
- package/dist/tbv/core/services/activation/index.d.ts.map +1 -0
- package/dist/tbv/core/services/deposit/__tests__/peginState.test.d.ts +2 -0
- package/dist/tbv/core/services/deposit/__tests__/peginState.test.d.ts.map +1 -0
- package/dist/tbv/core/services/deposit/__tests__/validation.test.d.ts +5 -0
- package/dist/tbv/core/services/deposit/__tests__/validation.test.d.ts.map +1 -0
- package/dist/tbv/core/services/deposit/index.d.ts +4 -0
- package/dist/tbv/core/services/deposit/index.d.ts.map +1 -1
- package/dist/tbv/core/services/deposit/peginState.d.ts +93 -0
- package/dist/tbv/core/services/deposit/peginState.d.ts.map +1 -0
- package/dist/tbv/core/services/deposit/validation.d.ts +114 -0
- package/dist/tbv/core/services/deposit/validation.d.ts.map +1 -0
- package/dist/tbv/core/services/index.cjs +1 -1
- package/dist/tbv/core/services/index.d.ts +3 -0
- package/dist/tbv/core/services/index.d.ts.map +1 -1
- package/dist/tbv/core/services/index.js +25 -7
- package/dist/tbv/core/services/index.js.map +1 -1
- package/dist/tbv/core/services/pegout/__tests__/state.test.d.ts +2 -0
- package/dist/tbv/core/services/pegout/__tests__/state.test.d.ts.map +1 -0
- package/dist/tbv/core/services/pegout/index.d.ts +2 -0
- package/dist/tbv/core/services/pegout/index.d.ts.map +1 -0
- package/dist/tbv/core/services/pegout/state.d.ts +30 -0
- package/dist/tbv/core/services/pegout/state.d.ts.map +1 -0
- package/dist/tbv/core/services/refund/__tests__/buildAndBroadcastRefund.test.d.ts +2 -0
- package/dist/tbv/core/services/refund/__tests__/buildAndBroadcastRefund.test.d.ts.map +1 -0
- package/dist/tbv/core/services/refund/buildAndBroadcastRefund.d.ts +103 -0
- package/dist/tbv/core/services/refund/buildAndBroadcastRefund.d.ts.map +1 -0
- package/dist/tbv/core/services/refund/errors.d.ts +13 -0
- package/dist/tbv/core/services/refund/errors.d.ts.map +1 -0
- package/dist/tbv/core/services/refund/index.d.ts +8 -0
- package/dist/tbv/core/services/refund/index.d.ts.map +1 -0
- package/dist/tbv/core/utils/index.cjs +1 -1
- package/dist/tbv/core/utils/index.js +30 -24
- package/dist/tbv/core/utils/transaction/fundPeginTransaction.d.ts +1 -1
- package/dist/tbv/core/utils/utxo/__tests__/availability.test.d.ts +3 -0
- package/dist/tbv/core/utils/utxo/__tests__/availability.test.d.ts.map +1 -0
- package/dist/tbv/core/utils/utxo/__tests__/reservation.test.d.ts +3 -0
- package/dist/tbv/core/utils/utxo/__tests__/reservation.test.d.ts.map +1 -0
- package/dist/tbv/core/utils/utxo/availability.d.ts +62 -0
- package/dist/tbv/core/utils/utxo/availability.d.ts.map +1 -0
- package/dist/tbv/core/utils/utxo/index.d.ts +2 -0
- package/dist/tbv/core/utils/utxo/index.d.ts.map +1 -1
- package/dist/tbv/core/utils/utxo/reservation.d.ts +65 -0
- package/dist/tbv/core/utils/utxo/reservation.d.ts.map +1 -0
- package/dist/tbv/index.cjs +1 -1
- package/dist/tbv/index.js +130 -106
- 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.d.ts +3 -3
- package/dist/tbv/integrations/aave/index.d.ts.map +1 -1
- package/dist/tbv/integrations/aave/index.js +145 -169
- package/dist/tbv/integrations/aave/index.js.map +1 -1
- package/dist/tbv/integrations/aave/utils/healthFactor.d.ts +0 -30
- package/dist/tbv/integrations/aave/utils/healthFactor.d.ts.map +1 -1
- package/dist/tbv/integrations/aave/utils/index.d.ts +2 -2
- package/dist/tbv/integrations/aave/utils/index.d.ts.map +1 -1
- package/dist/types-B-p4dhEH.cjs +2 -0
- package/dist/types-B-p4dhEH.cjs.map +1 -0
- package/dist/types-DWjaqVfP.js +608 -0
- package/dist/types-DWjaqVfP.js.map +1 -0
- package/package.json +5 -1
- package/dist/challengeAssert-D_k_ADgP.cjs +0 -2
- package/dist/challengeAssert-D_k_ADgP.cjs.map +0 -1
- package/dist/challengeAssert-k5_LWUtO.js +0 -362
- package/dist/challengeAssert-k5_LWUtO.js.map +0 -1
- package/dist/constants-EiyZkXce.cjs +0 -2
- package/dist/constants-EiyZkXce.cjs.map +0 -1
- package/dist/constants-Q7v2O7Ps.js.map +0 -1
- package/dist/errors-DVNYib5y.cjs +0 -2
- package/dist/errors-DVNYib5y.cjs.map +0 -1
- package/dist/errors-aMocmFr-.js.map +0 -1
- package/dist/fundPeginTransaction-DpwnDslW.js +0 -50
- package/dist/fundPeginTransaction-DpwnDslW.js.map +0 -1
- package/dist/fundPeginTransaction-EbrZzlrh.cjs +0 -2
- package/dist/fundPeginTransaction-EbrZzlrh.cjs.map +0 -1
- package/dist/index-BX-V3C9t.js +0 -995
- package/dist/index-BX-V3C9t.js.map +0 -1
- package/dist/index-BgnxXV5G.cjs +0 -2
- package/dist/index-BgnxXV5G.cjs.map +0 -1
- package/dist/index-BvFLf3vm.js.map +0 -1
- package/dist/index-DpKhuCta.cjs +0 -2
- package/dist/index-DpKhuCta.cjs.map +0 -1
- package/dist/payout-Ce9vSs9e.js +0 -164
- package/dist/payout-Ce9vSs9e.js.map +0 -1
- package/dist/payout-CfsDnjKI.cjs +0 -2
- package/dist/payout-CfsDnjKI.cjs.map +0 -1
- package/dist/psbtInputFields-C0nKn_GD.cjs +0 -2
- package/dist/psbtInputFields-C0nKn_GD.cjs.map +0 -1
- package/dist/psbtInputFields-DO0ELwiv.js +0 -116
- package/dist/psbtInputFields-DO0ELwiv.js.map +0 -1
- package/dist/signing-Deg5lCoC.cjs +0 -2
- package/dist/signing-Deg5lCoC.cjs.map +0 -1
- package/dist/signing-Drwr3bXB.js +0 -16
- package/dist/signing-Drwr3bXB.js.map +0 -1
- package/dist/types-D1rYwwCu.js +0 -235
- package/dist/types-D1rYwwCu.js.map +0 -1
- package/dist/types-DEWiqXYp.cjs +0 -2
- package/dist/types-DEWiqXYp.cjs.map +0 -1
package/dist/index-BX-V3C9t.js
DELETED
|
@@ -1,995 +0,0 @@
|
|
|
1
|
-
var wt = Object.defineProperty;
|
|
2
|
-
var St = (e, t, s) => t in e ? wt(e, t, { enumerable: !0, configurable: !0, writable: !0, value: s }) : e[t] = s;
|
|
3
|
-
var h = (e, t, s) => St(e, typeof t != "symbol" ? t + "" : t, s);
|
|
4
|
-
import { c as Tt, a as Ht, R as mt, D as U, d as ut } from "./types-D1rYwwCu.js";
|
|
5
|
-
import * as kt from "bitcoinjs-lib";
|
|
6
|
-
import { Transaction as _t, Psbt as ft } from "bitcoinjs-lib";
|
|
7
|
-
import { Buffer as ht } from "buffer";
|
|
8
|
-
import { c as X } from "./signing-Drwr3bXB.js";
|
|
9
|
-
import { v as Z, b as At, s as S, p as q } from "./constants-Q7v2O7Ps.js";
|
|
10
|
-
import "@babylonlabs-io/babylon-tbv-rust-wasm";
|
|
11
|
-
import { b as tt, e as F } from "./payout-Ce9vSs9e.js";
|
|
12
|
-
class Et {
|
|
13
|
-
/**
|
|
14
|
-
* Creates a new PayoutManager instance.
|
|
15
|
-
*
|
|
16
|
-
* @param config - Manager configuration including wallet
|
|
17
|
-
*/
|
|
18
|
-
constructor(t) {
|
|
19
|
-
h(this, "config");
|
|
20
|
-
this.config = t;
|
|
21
|
-
}
|
|
22
|
-
/**
|
|
23
|
-
* Signs a Payout transaction and extracts the Schnorr signature.
|
|
24
|
-
*
|
|
25
|
-
* Flow:
|
|
26
|
-
* 1. Vault provider submits Claim transaction
|
|
27
|
-
* 2. Claimer submits Assert transaction to prove validity
|
|
28
|
-
* 3. Payout can be executed (references Assert tx)
|
|
29
|
-
*
|
|
30
|
-
* This method orchestrates the following steps:
|
|
31
|
-
* 1. Get wallet's public key and convert to x-only format
|
|
32
|
-
* 2. Validate wallet pubkey matches on-chain depositor pubkey (if provided)
|
|
33
|
-
* 3. Build unsigned PSBT using primitives
|
|
34
|
-
* 4. Sign PSBT via btcWallet.signPsbt()
|
|
35
|
-
* 5. Extract 64-byte Schnorr signature using primitives
|
|
36
|
-
*
|
|
37
|
-
* The returned signature can be submitted to the vault provider API.
|
|
38
|
-
*
|
|
39
|
-
* @param params - Payout signing parameters
|
|
40
|
-
* @returns Signature result with 64-byte Schnorr signature and depositor pubkey
|
|
41
|
-
* @throws Error if wallet pubkey doesn't match depositor pubkey
|
|
42
|
-
* @throws Error if wallet operations fail or signature extraction fails
|
|
43
|
-
*/
|
|
44
|
-
async signPayoutTransaction(t) {
|
|
45
|
-
this.validatePayoutOutputs(
|
|
46
|
-
t.payoutTxHex,
|
|
47
|
-
t.registeredPayoutScriptPubKey
|
|
48
|
-
);
|
|
49
|
-
const s = await this.config.btcWallet.getPublicKeyHex(), { depositorPubkey: n } = Z(
|
|
50
|
-
s,
|
|
51
|
-
t.depositorBtcPubkey
|
|
52
|
-
), o = await tt({
|
|
53
|
-
payoutTxHex: t.payoutTxHex,
|
|
54
|
-
peginTxHex: t.peginTxHex,
|
|
55
|
-
assertTxHex: t.assertTxHex,
|
|
56
|
-
depositorBtcPubkey: n,
|
|
57
|
-
vaultProviderBtcPubkey: t.vaultProviderBtcPubkey,
|
|
58
|
-
vaultKeeperBtcPubkeys: t.vaultKeeperBtcPubkeys,
|
|
59
|
-
universalChallengerBtcPubkeys: t.universalChallengerBtcPubkeys,
|
|
60
|
-
timelockPegin: t.timelockPegin,
|
|
61
|
-
network: this.config.network
|
|
62
|
-
}), c = await this.config.btcWallet.signPsbt(
|
|
63
|
-
o.psbtHex,
|
|
64
|
-
X(s, 1)
|
|
65
|
-
);
|
|
66
|
-
return {
|
|
67
|
-
signature: F(c, n),
|
|
68
|
-
depositorBtcPubkey: n
|
|
69
|
-
};
|
|
70
|
-
}
|
|
71
|
-
/**
|
|
72
|
-
* Gets the configured Bitcoin network.
|
|
73
|
-
*
|
|
74
|
-
* @returns The Bitcoin network (mainnet, testnet, signet, regtest)
|
|
75
|
-
*/
|
|
76
|
-
getNetwork() {
|
|
77
|
-
return this.config.network;
|
|
78
|
-
}
|
|
79
|
-
/**
|
|
80
|
-
* Checks if the wallet supports batch signing (signPsbts).
|
|
81
|
-
*
|
|
82
|
-
* @returns true if batch signing is supported
|
|
83
|
-
*/
|
|
84
|
-
supportsBatchSigning() {
|
|
85
|
-
return typeof this.config.btcWallet.signPsbts == "function";
|
|
86
|
-
}
|
|
87
|
-
/**
|
|
88
|
-
* Batch signs multiple payout transactions (1 per claimer).
|
|
89
|
-
* This allows signing all transactions with a single wallet interaction.
|
|
90
|
-
*
|
|
91
|
-
* @param transactions - Array of payout params to sign
|
|
92
|
-
* @returns Array of signature results matching input order
|
|
93
|
-
* @throws Error if wallet doesn't support batch signing
|
|
94
|
-
* @throws Error if any signing operation fails
|
|
95
|
-
*/
|
|
96
|
-
async signPayoutTransactionsBatch(t) {
|
|
97
|
-
if (!this.supportsBatchSigning())
|
|
98
|
-
throw new Error(
|
|
99
|
-
"Wallet does not support batch signing (signPsbts method not available)"
|
|
100
|
-
);
|
|
101
|
-
const s = await this.config.btcWallet.getPublicKeyHex(), n = [], o = [], c = [];
|
|
102
|
-
for (const r of t) {
|
|
103
|
-
this.validatePayoutOutputs(
|
|
104
|
-
r.payoutTxHex,
|
|
105
|
-
r.registeredPayoutScriptPubKey
|
|
106
|
-
);
|
|
107
|
-
const { depositorPubkey: u } = Z(
|
|
108
|
-
s,
|
|
109
|
-
r.depositorBtcPubkey
|
|
110
|
-
);
|
|
111
|
-
c.push(u);
|
|
112
|
-
const l = await tt({
|
|
113
|
-
payoutTxHex: r.payoutTxHex,
|
|
114
|
-
peginTxHex: r.peginTxHex,
|
|
115
|
-
assertTxHex: r.assertTxHex,
|
|
116
|
-
depositorBtcPubkey: u,
|
|
117
|
-
vaultProviderBtcPubkey: r.vaultProviderBtcPubkey,
|
|
118
|
-
vaultKeeperBtcPubkeys: r.vaultKeeperBtcPubkeys,
|
|
119
|
-
universalChallengerBtcPubkeys: r.universalChallengerBtcPubkeys,
|
|
120
|
-
timelockPegin: r.timelockPegin,
|
|
121
|
-
network: this.config.network
|
|
122
|
-
});
|
|
123
|
-
n.push(l.psbtHex), o.push(X(s, 1));
|
|
124
|
-
}
|
|
125
|
-
const i = await this.config.btcWallet.signPsbts(
|
|
126
|
-
n,
|
|
127
|
-
o
|
|
128
|
-
);
|
|
129
|
-
if (i.length !== t.length)
|
|
130
|
-
throw new Error(
|
|
131
|
-
`Expected ${t.length} signed PSBTs but received ${i.length}`
|
|
132
|
-
);
|
|
133
|
-
const a = [];
|
|
134
|
-
for (let r = 0; r < t.length; r++) {
|
|
135
|
-
const u = c[r], l = F(
|
|
136
|
-
i[r],
|
|
137
|
-
u
|
|
138
|
-
);
|
|
139
|
-
a.push({
|
|
140
|
-
payoutSignature: l,
|
|
141
|
-
depositorBtcPubkey: u
|
|
142
|
-
});
|
|
143
|
-
}
|
|
144
|
-
return a;
|
|
145
|
-
}
|
|
146
|
-
/**
|
|
147
|
-
* Validates that the payout transaction's largest output pays to the
|
|
148
|
-
* registered depositor payout address (scriptPubKey).
|
|
149
|
-
*
|
|
150
|
-
* This prevents two attack vectors from a malicious vault provider:
|
|
151
|
-
* 1. Substituting a completely different payout address
|
|
152
|
-
* 2. Including a dust output to the correct address while routing
|
|
153
|
-
* the actual funds to an attacker-controlled address
|
|
154
|
-
*
|
|
155
|
-
* @param payoutTxHex - Raw payout transaction hex
|
|
156
|
-
* @param registeredPayoutScriptPubKey - On-chain registered scriptPubKey (hex, with or without 0x prefix)
|
|
157
|
-
* @throws Error if scriptPubKey is invalid hex
|
|
158
|
-
* @throws Error if the largest output does not pay to the registered address
|
|
159
|
-
*/
|
|
160
|
-
validatePayoutOutputs(t, s) {
|
|
161
|
-
if (!At(s))
|
|
162
|
-
throw new Error(
|
|
163
|
-
"Invalid registeredPayoutScriptPubKey: not valid hex"
|
|
164
|
-
);
|
|
165
|
-
const n = ht.from(
|
|
166
|
-
S(s),
|
|
167
|
-
"hex"
|
|
168
|
-
), o = _t.fromHex(S(t));
|
|
169
|
-
if (o.outs.length === 0)
|
|
170
|
-
throw new Error("Payout transaction has no outputs");
|
|
171
|
-
if (!o.outs.reduce(
|
|
172
|
-
(i, a) => a.value > i.value ? a : i
|
|
173
|
-
).script.equals(n))
|
|
174
|
-
throw new Error(
|
|
175
|
-
"Payout transaction does not pay to the registered depositor payout address"
|
|
176
|
-
);
|
|
177
|
-
}
|
|
178
|
-
}
|
|
179
|
-
function Bt(e) {
|
|
180
|
-
return e instanceof Uint8Array || ArrayBuffer.isView(e) && e.constructor.name === "Uint8Array";
|
|
181
|
-
}
|
|
182
|
-
function et(e, t = "") {
|
|
183
|
-
if (!Number.isSafeInteger(e) || e < 0) {
|
|
184
|
-
const s = t && `"${t}" `;
|
|
185
|
-
throw new Error(`${s}expected integer >= 0, got ${e}`);
|
|
186
|
-
}
|
|
187
|
-
}
|
|
188
|
-
function Y(e, t, s = "") {
|
|
189
|
-
const n = Bt(e), o = e == null ? void 0 : e.length, c = t !== void 0;
|
|
190
|
-
if (!n || c && o !== t) {
|
|
191
|
-
const i = s && `"${s}" `, a = c ? ` of length ${t}` : "", r = n ? `length=${o}` : `type=${typeof e}`;
|
|
192
|
-
throw new Error(i + "expected Uint8Array" + a + ", got " + r);
|
|
193
|
-
}
|
|
194
|
-
return e;
|
|
195
|
-
}
|
|
196
|
-
function ke(e) {
|
|
197
|
-
if (typeof e != "function" || typeof e.create != "function")
|
|
198
|
-
throw new Error("Hash must wrapped by utils.createHasher");
|
|
199
|
-
et(e.outputLen), et(e.blockLen);
|
|
200
|
-
}
|
|
201
|
-
function st(e, t = !0) {
|
|
202
|
-
if (e.destroyed)
|
|
203
|
-
throw new Error("Hash instance has been destroyed");
|
|
204
|
-
if (t && e.finished)
|
|
205
|
-
throw new Error("Hash#digest() has already been called");
|
|
206
|
-
}
|
|
207
|
-
function Lt(e, t) {
|
|
208
|
-
Y(e, void 0, "digestInto() output");
|
|
209
|
-
const s = t.outputLen;
|
|
210
|
-
if (e.length < s)
|
|
211
|
-
throw new Error('"digestInto() output" expected to be of length >=' + s);
|
|
212
|
-
}
|
|
213
|
-
function _e(e) {
|
|
214
|
-
return new Uint32Array(e.buffer, e.byteOffset, Math.floor(e.byteLength / 4));
|
|
215
|
-
}
|
|
216
|
-
function D(...e) {
|
|
217
|
-
for (let t = 0; t < e.length; t++)
|
|
218
|
-
e[t].fill(0);
|
|
219
|
-
}
|
|
220
|
-
function z(e) {
|
|
221
|
-
return new DataView(e.buffer, e.byteOffset, e.byteLength);
|
|
222
|
-
}
|
|
223
|
-
function w(e, t) {
|
|
224
|
-
return e << 32 - t | e >>> t;
|
|
225
|
-
}
|
|
226
|
-
function Ae(e, t) {
|
|
227
|
-
return e << t | e >>> 32 - t >>> 0;
|
|
228
|
-
}
|
|
229
|
-
const It = new Uint8Array(new Uint32Array([287454020]).buffer)[0] === 68;
|
|
230
|
-
function vt(e) {
|
|
231
|
-
return e << 24 & 4278190080 | e << 8 & 16711680 | e >>> 8 & 65280 | e >>> 24 & 255;
|
|
232
|
-
}
|
|
233
|
-
function Ct(e) {
|
|
234
|
-
for (let t = 0; t < e.length; t++)
|
|
235
|
-
e[t] = vt(e[t]);
|
|
236
|
-
return e;
|
|
237
|
-
}
|
|
238
|
-
const Ee = It ? (e) => e : Ct;
|
|
239
|
-
function Ot(e) {
|
|
240
|
-
if (typeof e != "string")
|
|
241
|
-
throw new Error("string expected");
|
|
242
|
-
return new Uint8Array(new TextEncoder().encode(e));
|
|
243
|
-
}
|
|
244
|
-
function Be(e, t = "") {
|
|
245
|
-
return typeof e == "string" ? Ot(e) : Y(e, void 0, t);
|
|
246
|
-
}
|
|
247
|
-
function Le(e, t) {
|
|
248
|
-
if (t !== void 0 && {}.toString.call(t) !== "[object Object]")
|
|
249
|
-
throw new Error("options must be object or undefined");
|
|
250
|
-
return Object.assign(e, t);
|
|
251
|
-
}
|
|
252
|
-
function lt(e, t = {}) {
|
|
253
|
-
const s = (o, c) => e(c).update(o).digest(), n = e(void 0);
|
|
254
|
-
return s.outputLen = n.outputLen, s.blockLen = n.blockLen, s.create = (o) => e(o), Object.assign(s, t), Object.freeze(s);
|
|
255
|
-
}
|
|
256
|
-
const bt = (e) => ({
|
|
257
|
-
oid: Uint8Array.from([6, 9, 96, 134, 72, 1, 101, 3, 4, 2, e])
|
|
258
|
-
});
|
|
259
|
-
function Ut(e, t, s) {
|
|
260
|
-
return e & t ^ ~e & s;
|
|
261
|
-
}
|
|
262
|
-
function Dt(e, t, s) {
|
|
263
|
-
return e & t ^ e & s ^ t & s;
|
|
264
|
-
}
|
|
265
|
-
class xt {
|
|
266
|
-
constructor(t, s, n, o) {
|
|
267
|
-
h(this, "blockLen");
|
|
268
|
-
h(this, "outputLen");
|
|
269
|
-
h(this, "padOffset");
|
|
270
|
-
h(this, "isLE");
|
|
271
|
-
// For partial updates less than block size
|
|
272
|
-
h(this, "buffer");
|
|
273
|
-
h(this, "view");
|
|
274
|
-
h(this, "finished", !1);
|
|
275
|
-
h(this, "length", 0);
|
|
276
|
-
h(this, "pos", 0);
|
|
277
|
-
h(this, "destroyed", !1);
|
|
278
|
-
this.blockLen = t, this.outputLen = s, this.padOffset = n, this.isLE = o, this.buffer = new Uint8Array(t), this.view = z(this.buffer);
|
|
279
|
-
}
|
|
280
|
-
update(t) {
|
|
281
|
-
st(this), Y(t);
|
|
282
|
-
const { view: s, buffer: n, blockLen: o } = this, c = t.length;
|
|
283
|
-
for (let i = 0; i < c; ) {
|
|
284
|
-
const a = Math.min(o - this.pos, c - i);
|
|
285
|
-
if (a === o) {
|
|
286
|
-
const r = z(t);
|
|
287
|
-
for (; o <= c - i; i += o)
|
|
288
|
-
this.process(r, i);
|
|
289
|
-
continue;
|
|
290
|
-
}
|
|
291
|
-
n.set(t.subarray(i, i + a), this.pos), this.pos += a, i += a, this.pos === o && (this.process(s, 0), this.pos = 0);
|
|
292
|
-
}
|
|
293
|
-
return this.length += t.length, this.roundClean(), this;
|
|
294
|
-
}
|
|
295
|
-
digestInto(t) {
|
|
296
|
-
st(this), Lt(t, this), this.finished = !0;
|
|
297
|
-
const { buffer: s, view: n, blockLen: o, isLE: c } = this;
|
|
298
|
-
let { pos: i } = this;
|
|
299
|
-
s[i++] = 128, D(this.buffer.subarray(i)), this.padOffset > o - i && (this.process(n, 0), i = 0);
|
|
300
|
-
for (let f = i; f < o; f++)
|
|
301
|
-
s[f] = 0;
|
|
302
|
-
n.setBigUint64(o - 8, BigInt(this.length * 8), c), this.process(n, 0);
|
|
303
|
-
const a = z(t), r = this.outputLen;
|
|
304
|
-
if (r % 4)
|
|
305
|
-
throw new Error("_sha2: outputLen must be aligned to 32bit");
|
|
306
|
-
const u = r / 4, l = this.get();
|
|
307
|
-
if (u > l.length)
|
|
308
|
-
throw new Error("_sha2: outputLen bigger than state");
|
|
309
|
-
for (let f = 0; f < u; f++)
|
|
310
|
-
a.setUint32(4 * f, l[f], c);
|
|
311
|
-
}
|
|
312
|
-
digest() {
|
|
313
|
-
const { buffer: t, outputLen: s } = this;
|
|
314
|
-
this.digestInto(t);
|
|
315
|
-
const n = t.slice(0, s);
|
|
316
|
-
return this.destroy(), n;
|
|
317
|
-
}
|
|
318
|
-
_cloneInto(t) {
|
|
319
|
-
t || (t = new this.constructor()), t.set(...this.get());
|
|
320
|
-
const { blockLen: s, buffer: n, length: o, finished: c, destroyed: i, pos: a } = this;
|
|
321
|
-
return t.destroyed = i, t.finished = c, t.length = o, t.pos = a, o % s && t.buffer.set(n), t;
|
|
322
|
-
}
|
|
323
|
-
clone() {
|
|
324
|
-
return this._cloneInto();
|
|
325
|
-
}
|
|
326
|
-
}
|
|
327
|
-
const E = /* @__PURE__ */ Uint32Array.from([
|
|
328
|
-
1779033703,
|
|
329
|
-
3144134277,
|
|
330
|
-
1013904242,
|
|
331
|
-
2773480762,
|
|
332
|
-
1359893119,
|
|
333
|
-
2600822924,
|
|
334
|
-
528734635,
|
|
335
|
-
1541459225
|
|
336
|
-
]), g = /* @__PURE__ */ Uint32Array.from([
|
|
337
|
-
1779033703,
|
|
338
|
-
4089235720,
|
|
339
|
-
3144134277,
|
|
340
|
-
2227873595,
|
|
341
|
-
1013904242,
|
|
342
|
-
4271175723,
|
|
343
|
-
2773480762,
|
|
344
|
-
1595750129,
|
|
345
|
-
1359893119,
|
|
346
|
-
2917565137,
|
|
347
|
-
2600822924,
|
|
348
|
-
725511199,
|
|
349
|
-
528734635,
|
|
350
|
-
4215389547,
|
|
351
|
-
1541459225,
|
|
352
|
-
327033209
|
|
353
|
-
]), N = /* @__PURE__ */ BigInt(2 ** 32 - 1), nt = /* @__PURE__ */ BigInt(32);
|
|
354
|
-
function Kt(e, t = !1) {
|
|
355
|
-
return t ? { h: Number(e & N), l: Number(e >> nt & N) } : { h: Number(e >> nt & N) | 0, l: Number(e & N) | 0 };
|
|
356
|
-
}
|
|
357
|
-
function $t(e, t = !1) {
|
|
358
|
-
const s = e.length;
|
|
359
|
-
let n = new Uint32Array(s), o = new Uint32Array(s);
|
|
360
|
-
for (let c = 0; c < s; c++) {
|
|
361
|
-
const { h: i, l: a } = Kt(e[c], t);
|
|
362
|
-
[n[c], o[c]] = [i, a];
|
|
363
|
-
}
|
|
364
|
-
return [n, o];
|
|
365
|
-
}
|
|
366
|
-
const ot = (e, t, s) => e >>> s, rt = (e, t, s) => e << 32 - s | t >>> s, C = (e, t, s) => e >>> s | t << 32 - s, O = (e, t, s) => e << 32 - s | t >>> s, G = (e, t, s) => e << 64 - s | t >>> s - 32, W = (e, t, s) => e >>> s - 32 | t << 64 - s, Ie = (e, t, s) => e << s | t >>> 32 - s, ve = (e, t, s) => t << s | e >>> 32 - s, Ce = (e, t, s) => t << s - 32 | e >>> 64 - s, Oe = (e, t, s) => e << s - 32 | t >>> 64 - s;
|
|
367
|
-
function m(e, t, s, n) {
|
|
368
|
-
const o = (t >>> 0) + (n >>> 0);
|
|
369
|
-
return { h: e + s + (o / 2 ** 32 | 0) | 0, l: o | 0 };
|
|
370
|
-
}
|
|
371
|
-
const Nt = (e, t, s) => (e >>> 0) + (t >>> 0) + (s >>> 0), Gt = (e, t, s, n) => t + s + n + (e / 2 ** 32 | 0) | 0, Wt = (e, t, s, n) => (e >>> 0) + (t >>> 0) + (s >>> 0) + (n >>> 0), Ft = (e, t, s, n, o) => t + s + n + o + (e / 2 ** 32 | 0) | 0, Mt = (e, t, s, n, o) => (e >>> 0) + (t >>> 0) + (s >>> 0) + (n >>> 0) + (o >>> 0), Rt = (e, t, s, n, o, c) => t + s + n + o + c + (e / 2 ** 32 | 0) | 0, Vt = /* @__PURE__ */ Uint32Array.from([
|
|
372
|
-
1116352408,
|
|
373
|
-
1899447441,
|
|
374
|
-
3049323471,
|
|
375
|
-
3921009573,
|
|
376
|
-
961987163,
|
|
377
|
-
1508970993,
|
|
378
|
-
2453635748,
|
|
379
|
-
2870763221,
|
|
380
|
-
3624381080,
|
|
381
|
-
310598401,
|
|
382
|
-
607225278,
|
|
383
|
-
1426881987,
|
|
384
|
-
1925078388,
|
|
385
|
-
2162078206,
|
|
386
|
-
2614888103,
|
|
387
|
-
3248222580,
|
|
388
|
-
3835390401,
|
|
389
|
-
4022224774,
|
|
390
|
-
264347078,
|
|
391
|
-
604807628,
|
|
392
|
-
770255983,
|
|
393
|
-
1249150122,
|
|
394
|
-
1555081692,
|
|
395
|
-
1996064986,
|
|
396
|
-
2554220882,
|
|
397
|
-
2821834349,
|
|
398
|
-
2952996808,
|
|
399
|
-
3210313671,
|
|
400
|
-
3336571891,
|
|
401
|
-
3584528711,
|
|
402
|
-
113926993,
|
|
403
|
-
338241895,
|
|
404
|
-
666307205,
|
|
405
|
-
773529912,
|
|
406
|
-
1294757372,
|
|
407
|
-
1396182291,
|
|
408
|
-
1695183700,
|
|
409
|
-
1986661051,
|
|
410
|
-
2177026350,
|
|
411
|
-
2456956037,
|
|
412
|
-
2730485921,
|
|
413
|
-
2820302411,
|
|
414
|
-
3259730800,
|
|
415
|
-
3345764771,
|
|
416
|
-
3516065817,
|
|
417
|
-
3600352804,
|
|
418
|
-
4094571909,
|
|
419
|
-
275423344,
|
|
420
|
-
430227734,
|
|
421
|
-
506948616,
|
|
422
|
-
659060556,
|
|
423
|
-
883997877,
|
|
424
|
-
958139571,
|
|
425
|
-
1322822218,
|
|
426
|
-
1537002063,
|
|
427
|
-
1747873779,
|
|
428
|
-
1955562222,
|
|
429
|
-
2024104815,
|
|
430
|
-
2227730452,
|
|
431
|
-
2361852424,
|
|
432
|
-
2428436474,
|
|
433
|
-
2756734187,
|
|
434
|
-
3204031479,
|
|
435
|
-
3329325298
|
|
436
|
-
]), B = /* @__PURE__ */ new Uint32Array(64);
|
|
437
|
-
class jt extends xt {
|
|
438
|
-
constructor(t) {
|
|
439
|
-
super(64, t, 8, !1);
|
|
440
|
-
}
|
|
441
|
-
get() {
|
|
442
|
-
const { A: t, B: s, C: n, D: o, E: c, F: i, G: a, H: r } = this;
|
|
443
|
-
return [t, s, n, o, c, i, a, r];
|
|
444
|
-
}
|
|
445
|
-
// prettier-ignore
|
|
446
|
-
set(t, s, n, o, c, i, a, r) {
|
|
447
|
-
this.A = t | 0, this.B = s | 0, this.C = n | 0, this.D = o | 0, this.E = c | 0, this.F = i | 0, this.G = a | 0, this.H = r | 0;
|
|
448
|
-
}
|
|
449
|
-
process(t, s) {
|
|
450
|
-
for (let f = 0; f < 16; f++, s += 4)
|
|
451
|
-
B[f] = t.getUint32(s, !1);
|
|
452
|
-
for (let f = 16; f < 64; f++) {
|
|
453
|
-
const b = B[f - 15], d = B[f - 2], y = w(b, 7) ^ w(b, 18) ^ b >>> 3, p = w(d, 17) ^ w(d, 19) ^ d >>> 10;
|
|
454
|
-
B[f] = p + B[f - 7] + y + B[f - 16] | 0;
|
|
455
|
-
}
|
|
456
|
-
let { A: n, B: o, C: c, D: i, E: a, F: r, G: u, H: l } = this;
|
|
457
|
-
for (let f = 0; f < 64; f++) {
|
|
458
|
-
const b = w(a, 6) ^ w(a, 11) ^ w(a, 25), d = l + b + Ut(a, r, u) + Vt[f] + B[f] | 0, p = (w(n, 2) ^ w(n, 13) ^ w(n, 22)) + Dt(n, o, c) | 0;
|
|
459
|
-
l = u, u = r, r = a, a = i + d | 0, i = c, c = o, o = n, n = d + p | 0;
|
|
460
|
-
}
|
|
461
|
-
n = n + this.A | 0, o = o + this.B | 0, c = c + this.C | 0, i = i + this.D | 0, a = a + this.E | 0, r = r + this.F | 0, u = u + this.G | 0, l = l + this.H | 0, this.set(n, o, c, i, a, r, u, l);
|
|
462
|
-
}
|
|
463
|
-
roundClean() {
|
|
464
|
-
D(B);
|
|
465
|
-
}
|
|
466
|
-
destroy() {
|
|
467
|
-
this.set(0, 0, 0, 0, 0, 0, 0, 0), D(this.buffer);
|
|
468
|
-
}
|
|
469
|
-
}
|
|
470
|
-
class zt extends jt {
|
|
471
|
-
constructor() {
|
|
472
|
-
super(32);
|
|
473
|
-
// We cannot use array here since array allows indexing by variable
|
|
474
|
-
// which means optimizer/compiler cannot use registers.
|
|
475
|
-
h(this, "A", E[0] | 0);
|
|
476
|
-
h(this, "B", E[1] | 0);
|
|
477
|
-
h(this, "C", E[2] | 0);
|
|
478
|
-
h(this, "D", E[3] | 0);
|
|
479
|
-
h(this, "E", E[4] | 0);
|
|
480
|
-
h(this, "F", E[5] | 0);
|
|
481
|
-
h(this, "G", E[6] | 0);
|
|
482
|
-
h(this, "H", E[7] | 0);
|
|
483
|
-
}
|
|
484
|
-
}
|
|
485
|
-
const dt = $t([
|
|
486
|
-
"0x428a2f98d728ae22",
|
|
487
|
-
"0x7137449123ef65cd",
|
|
488
|
-
"0xb5c0fbcfec4d3b2f",
|
|
489
|
-
"0xe9b5dba58189dbbc",
|
|
490
|
-
"0x3956c25bf348b538",
|
|
491
|
-
"0x59f111f1b605d019",
|
|
492
|
-
"0x923f82a4af194f9b",
|
|
493
|
-
"0xab1c5ed5da6d8118",
|
|
494
|
-
"0xd807aa98a3030242",
|
|
495
|
-
"0x12835b0145706fbe",
|
|
496
|
-
"0x243185be4ee4b28c",
|
|
497
|
-
"0x550c7dc3d5ffb4e2",
|
|
498
|
-
"0x72be5d74f27b896f",
|
|
499
|
-
"0x80deb1fe3b1696b1",
|
|
500
|
-
"0x9bdc06a725c71235",
|
|
501
|
-
"0xc19bf174cf692694",
|
|
502
|
-
"0xe49b69c19ef14ad2",
|
|
503
|
-
"0xefbe4786384f25e3",
|
|
504
|
-
"0x0fc19dc68b8cd5b5",
|
|
505
|
-
"0x240ca1cc77ac9c65",
|
|
506
|
-
"0x2de92c6f592b0275",
|
|
507
|
-
"0x4a7484aa6ea6e483",
|
|
508
|
-
"0x5cb0a9dcbd41fbd4",
|
|
509
|
-
"0x76f988da831153b5",
|
|
510
|
-
"0x983e5152ee66dfab",
|
|
511
|
-
"0xa831c66d2db43210",
|
|
512
|
-
"0xb00327c898fb213f",
|
|
513
|
-
"0xbf597fc7beef0ee4",
|
|
514
|
-
"0xc6e00bf33da88fc2",
|
|
515
|
-
"0xd5a79147930aa725",
|
|
516
|
-
"0x06ca6351e003826f",
|
|
517
|
-
"0x142929670a0e6e70",
|
|
518
|
-
"0x27b70a8546d22ffc",
|
|
519
|
-
"0x2e1b21385c26c926",
|
|
520
|
-
"0x4d2c6dfc5ac42aed",
|
|
521
|
-
"0x53380d139d95b3df",
|
|
522
|
-
"0x650a73548baf63de",
|
|
523
|
-
"0x766a0abb3c77b2a8",
|
|
524
|
-
"0x81c2c92e47edaee6",
|
|
525
|
-
"0x92722c851482353b",
|
|
526
|
-
"0xa2bfe8a14cf10364",
|
|
527
|
-
"0xa81a664bbc423001",
|
|
528
|
-
"0xc24b8b70d0f89791",
|
|
529
|
-
"0xc76c51a30654be30",
|
|
530
|
-
"0xd192e819d6ef5218",
|
|
531
|
-
"0xd69906245565a910",
|
|
532
|
-
"0xf40e35855771202a",
|
|
533
|
-
"0x106aa07032bbd1b8",
|
|
534
|
-
"0x19a4c116b8d2d0c8",
|
|
535
|
-
"0x1e376c085141ab53",
|
|
536
|
-
"0x2748774cdf8eeb99",
|
|
537
|
-
"0x34b0bcb5e19b48a8",
|
|
538
|
-
"0x391c0cb3c5c95a63",
|
|
539
|
-
"0x4ed8aa4ae3418acb",
|
|
540
|
-
"0x5b9cca4f7763e373",
|
|
541
|
-
"0x682e6ff3d6b2b8a3",
|
|
542
|
-
"0x748f82ee5defb2fc",
|
|
543
|
-
"0x78a5636f43172f60",
|
|
544
|
-
"0x84c87814a1f0ab72",
|
|
545
|
-
"0x8cc702081a6439ec",
|
|
546
|
-
"0x90befffa23631e28",
|
|
547
|
-
"0xa4506cebde82bde9",
|
|
548
|
-
"0xbef9a3f7b2c67915",
|
|
549
|
-
"0xc67178f2e372532b",
|
|
550
|
-
"0xca273eceea26619c",
|
|
551
|
-
"0xd186b8c721c0c207",
|
|
552
|
-
"0xeada7dd6cde0eb1e",
|
|
553
|
-
"0xf57d4f7fee6ed178",
|
|
554
|
-
"0x06f067aa72176fba",
|
|
555
|
-
"0x0a637dc5a2c898a6",
|
|
556
|
-
"0x113f9804bef90dae",
|
|
557
|
-
"0x1b710b35131c471b",
|
|
558
|
-
"0x28db77f523047d84",
|
|
559
|
-
"0x32caab7b40c72493",
|
|
560
|
-
"0x3c9ebe0a15c9bebc",
|
|
561
|
-
"0x431d67c49c100d4c",
|
|
562
|
-
"0x4cc5d4becb3e42b6",
|
|
563
|
-
"0x597f299cfc657e2a",
|
|
564
|
-
"0x5fcb6fab3ad6faec",
|
|
565
|
-
"0x6c44198c4a475817"
|
|
566
|
-
].map((e) => BigInt(e))), Xt = dt[0], qt = dt[1], L = /* @__PURE__ */ new Uint32Array(80), I = /* @__PURE__ */ new Uint32Array(80);
|
|
567
|
-
class Jt extends xt {
|
|
568
|
-
constructor(t) {
|
|
569
|
-
super(128, t, 16, !1);
|
|
570
|
-
}
|
|
571
|
-
// prettier-ignore
|
|
572
|
-
get() {
|
|
573
|
-
const { Ah: t, Al: s, Bh: n, Bl: o, Ch: c, Cl: i, Dh: a, Dl: r, Eh: u, El: l, Fh: f, Fl: b, Gh: d, Gl: y, Hh: p, Hl: P } = this;
|
|
574
|
-
return [t, s, n, o, c, i, a, r, u, l, f, b, d, y, p, P];
|
|
575
|
-
}
|
|
576
|
-
// prettier-ignore
|
|
577
|
-
set(t, s, n, o, c, i, a, r, u, l, f, b, d, y, p, P) {
|
|
578
|
-
this.Ah = t | 0, this.Al = s | 0, this.Bh = n | 0, this.Bl = o | 0, this.Ch = c | 0, this.Cl = i | 0, this.Dh = a | 0, this.Dl = r | 0, this.Eh = u | 0, this.El = l | 0, this.Fh = f | 0, this.Fl = b | 0, this.Gh = d | 0, this.Gl = y | 0, this.Hh = p | 0, this.Hl = P | 0;
|
|
579
|
-
}
|
|
580
|
-
process(t, s) {
|
|
581
|
-
for (let x = 0; x < 16; x++, s += 4)
|
|
582
|
-
L[x] = t.getUint32(s), I[x] = t.getUint32(s += 4);
|
|
583
|
-
for (let x = 16; x < 80; x++) {
|
|
584
|
-
const _ = L[x - 15] | 0, A = I[x - 15] | 0, M = C(_, A, 1) ^ C(_, A, 8) ^ ot(_, A, 7), R = O(_, A, 1) ^ O(_, A, 8) ^ rt(_, A, 7), T = L[x - 2] | 0, H = I[x - 2] | 0, K = C(T, H, 19) ^ G(T, H, 61) ^ ot(T, H, 6), V = O(T, H, 19) ^ W(T, H, 61) ^ rt(T, H, 6), $ = Wt(R, V, I[x - 7], I[x - 16]), j = Ft($, M, K, L[x - 7], L[x - 16]);
|
|
585
|
-
L[x] = j | 0, I[x] = $ | 0;
|
|
586
|
-
}
|
|
587
|
-
let { Ah: n, Al: o, Bh: c, Bl: i, Ch: a, Cl: r, Dh: u, Dl: l, Eh: f, El: b, Fh: d, Fl: y, Gh: p, Gl: P, Hh: k, Hl: v } = this;
|
|
588
|
-
for (let x = 0; x < 80; x++) {
|
|
589
|
-
const _ = C(f, b, 14) ^ C(f, b, 18) ^ G(f, b, 41), A = O(f, b, 14) ^ O(f, b, 18) ^ W(f, b, 41), M = f & d ^ ~f & p, R = b & y ^ ~b & P, T = Mt(v, A, R, qt[x], I[x]), H = Rt(T, k, _, M, Xt[x], L[x]), K = T | 0, V = C(n, o, 28) ^ G(n, o, 34) ^ G(n, o, 39), $ = O(n, o, 28) ^ W(n, o, 34) ^ W(n, o, 39), j = n & c ^ n & a ^ c & a, Pt = o & i ^ o & r ^ i & r;
|
|
590
|
-
k = p | 0, v = P | 0, p = d | 0, P = y | 0, d = f | 0, y = b | 0, { h: f, l: b } = m(u | 0, l | 0, H | 0, K | 0), u = a | 0, l = r | 0, a = c | 0, r = i | 0, c = n | 0, i = o | 0;
|
|
591
|
-
const Q = Nt(K, $, Pt);
|
|
592
|
-
n = Gt(Q, H, V, j), o = Q | 0;
|
|
593
|
-
}
|
|
594
|
-
({ h: n, l: o } = m(this.Ah | 0, this.Al | 0, n | 0, o | 0)), { h: c, l: i } = m(this.Bh | 0, this.Bl | 0, c | 0, i | 0), { h: a, l: r } = m(this.Ch | 0, this.Cl | 0, a | 0, r | 0), { h: u, l } = m(this.Dh | 0, this.Dl | 0, u | 0, l | 0), { h: f, l: b } = m(this.Eh | 0, this.El | 0, f | 0, b | 0), { h: d, l: y } = m(this.Fh | 0, this.Fl | 0, d | 0, y | 0), { h: p, l: P } = m(this.Gh | 0, this.Gl | 0, p | 0, P | 0), { h: k, l: v } = m(this.Hh | 0, this.Hl | 0, k | 0, v | 0), this.set(n, o, c, i, a, r, u, l, f, b, d, y, p, P, k, v);
|
|
595
|
-
}
|
|
596
|
-
roundClean() {
|
|
597
|
-
D(L, I);
|
|
598
|
-
}
|
|
599
|
-
destroy() {
|
|
600
|
-
D(this.buffer), this.set(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
|
|
601
|
-
}
|
|
602
|
-
}
|
|
603
|
-
class Yt extends Jt {
|
|
604
|
-
constructor() {
|
|
605
|
-
super(64);
|
|
606
|
-
h(this, "Ah", g[0] | 0);
|
|
607
|
-
h(this, "Al", g[1] | 0);
|
|
608
|
-
h(this, "Bh", g[2] | 0);
|
|
609
|
-
h(this, "Bl", g[3] | 0);
|
|
610
|
-
h(this, "Ch", g[4] | 0);
|
|
611
|
-
h(this, "Cl", g[5] | 0);
|
|
612
|
-
h(this, "Dh", g[6] | 0);
|
|
613
|
-
h(this, "Dl", g[7] | 0);
|
|
614
|
-
h(this, "Eh", g[8] | 0);
|
|
615
|
-
h(this, "El", g[9] | 0);
|
|
616
|
-
h(this, "Fh", g[10] | 0);
|
|
617
|
-
h(this, "Fl", g[11] | 0);
|
|
618
|
-
h(this, "Gh", g[12] | 0);
|
|
619
|
-
h(this, "Gl", g[13] | 0);
|
|
620
|
-
h(this, "Hh", g[14] | 0);
|
|
621
|
-
h(this, "Hl", g[15] | 0);
|
|
622
|
-
}
|
|
623
|
-
}
|
|
624
|
-
const Qt = /* @__PURE__ */ lt(
|
|
625
|
-
() => new zt(),
|
|
626
|
-
/* @__PURE__ */ bt(1)
|
|
627
|
-
), Ue = /* @__PURE__ */ lt(
|
|
628
|
-
() => new Yt(),
|
|
629
|
-
/* @__PURE__ */ bt(3)
|
|
630
|
-
), Zt = 1e4;
|
|
631
|
-
async function pt(e) {
|
|
632
|
-
const {
|
|
633
|
-
statusReader: t,
|
|
634
|
-
peginTxid: s,
|
|
635
|
-
targetStatuses: n,
|
|
636
|
-
timeoutMs: o,
|
|
637
|
-
pollIntervalMs: c = Zt,
|
|
638
|
-
signal: i
|
|
639
|
-
} = e, a = Date.now();
|
|
640
|
-
for (; ; ) {
|
|
641
|
-
if (i != null && i.aborted)
|
|
642
|
-
throw new Error(
|
|
643
|
-
`Polling aborted for pegin ${s.slice(0, 8)}… (target: ${[...n].join(", ")})`
|
|
644
|
-
);
|
|
645
|
-
if (Date.now() - a >= o)
|
|
646
|
-
throw new Error(
|
|
647
|
-
`Polling timeout after ${o}ms for pegin ${s.slice(0, 8)}… (target: ${[...n].join(", ")})`
|
|
648
|
-
);
|
|
649
|
-
try {
|
|
650
|
-
const u = (await t.getPeginStatus(
|
|
651
|
-
{ pegin_txid: s },
|
|
652
|
-
i
|
|
653
|
-
)).status;
|
|
654
|
-
if (n.has(u))
|
|
655
|
-
return u;
|
|
656
|
-
if (Tt.has(u) && !n.has(u))
|
|
657
|
-
throw new Error(
|
|
658
|
-
`Pegin ${s.slice(0, 8)}… reached terminal status "${u}" while waiting for ${[...n].join(", ")}`
|
|
659
|
-
);
|
|
660
|
-
} catch (r) {
|
|
661
|
-
if (!(r instanceof Ht && r.code === mt.NOT_FOUND || r instanceof Error && r.message.includes("PegIn not found")))
|
|
662
|
-
throw r;
|
|
663
|
-
}
|
|
664
|
-
await new Promise((r, u) => {
|
|
665
|
-
const l = () => {
|
|
666
|
-
clearTimeout(f), u(
|
|
667
|
-
new Error(
|
|
668
|
-
`Polling aborted for pegin ${s.slice(0, 8)}… (target: ${[...n].join(", ")})`
|
|
669
|
-
)
|
|
670
|
-
);
|
|
671
|
-
}, f = setTimeout(() => {
|
|
672
|
-
i == null || i.removeEventListener("abort", l), r();
|
|
673
|
-
}, c);
|
|
674
|
-
i == null || i.addEventListener("abort", l, { once: !0 });
|
|
675
|
-
});
|
|
676
|
-
}
|
|
677
|
-
}
|
|
678
|
-
const te = 300 * 1e3, ee = /* @__PURE__ */ new Set([
|
|
679
|
-
U.PENDING_DEPOSITOR_WOTS_PK,
|
|
680
|
-
...ut
|
|
681
|
-
]);
|
|
682
|
-
async function De(e) {
|
|
683
|
-
const {
|
|
684
|
-
statusReader: t,
|
|
685
|
-
wotsSubmitter: s,
|
|
686
|
-
peginTxid: n,
|
|
687
|
-
depositorPk: o,
|
|
688
|
-
wotsPublicKeys: c,
|
|
689
|
-
timeoutMs: i = te,
|
|
690
|
-
signal: a
|
|
691
|
-
} = e;
|
|
692
|
-
a == null || a.throwIfAborted();
|
|
693
|
-
const r = await pt({
|
|
694
|
-
statusReader: t,
|
|
695
|
-
peginTxid: n,
|
|
696
|
-
targetStatuses: ee,
|
|
697
|
-
timeoutMs: i,
|
|
698
|
-
signal: a
|
|
699
|
-
});
|
|
700
|
-
ut.has(r) || (a == null || a.throwIfAborted(), await s.submitDepositorWotsKey(
|
|
701
|
-
{
|
|
702
|
-
pegin_txid: n,
|
|
703
|
-
depositor_pk: o,
|
|
704
|
-
wots_public_keys: c
|
|
705
|
-
},
|
|
706
|
-
a
|
|
707
|
-
));
|
|
708
|
-
}
|
|
709
|
-
const se = 1;
|
|
710
|
-
function ne(e, t, s) {
|
|
711
|
-
const n = ft.fromBase64(e), o = n.data.getTransaction().toString("hex").toLowerCase(), c = S(t).toLowerCase();
|
|
712
|
-
if (o !== c)
|
|
713
|
-
throw new Error(
|
|
714
|
-
`PSBT integrity check failed for ${s}: unsigned transaction does not match tx_hex`
|
|
715
|
-
);
|
|
716
|
-
return n;
|
|
717
|
-
}
|
|
718
|
-
function oe(e) {
|
|
719
|
-
const t = ft.fromHex(e.toHex());
|
|
720
|
-
for (const s of t.data.inputs)
|
|
721
|
-
delete s.tapBip32Derivation, delete s.tapMerkleRoot;
|
|
722
|
-
return t;
|
|
723
|
-
}
|
|
724
|
-
function it(e, t, s) {
|
|
725
|
-
if (!e)
|
|
726
|
-
throw new Error(`Missing ${s} PSBT`);
|
|
727
|
-
const n = ne(e, t, s);
|
|
728
|
-
return oe(n).toHex();
|
|
729
|
-
}
|
|
730
|
-
function re(e, t) {
|
|
731
|
-
const s = [], n = [], o = [], c = X(
|
|
732
|
-
t,
|
|
733
|
-
se
|
|
734
|
-
), i = it(
|
|
735
|
-
e.payout_psbt,
|
|
736
|
-
e.payout_tx.tx_hex,
|
|
737
|
-
"depositor payout"
|
|
738
|
-
);
|
|
739
|
-
s.push(i), n.push(c);
|
|
740
|
-
for (const a of e.challenger_presign_data) {
|
|
741
|
-
const r = S(a.challenger_pubkey), u = s.length, l = it(
|
|
742
|
-
a.nopayout_psbt,
|
|
743
|
-
a.nopayout_tx.tx_hex,
|
|
744
|
-
`nopayout (challenger ${r})`
|
|
745
|
-
);
|
|
746
|
-
s.push(l), n.push(c), o.push({
|
|
747
|
-
challengerPubkey: r,
|
|
748
|
-
noPayoutIdx: u
|
|
749
|
-
});
|
|
750
|
-
}
|
|
751
|
-
return { psbtHexes: s, signOptions: n, challengerEntries: o };
|
|
752
|
-
}
|
|
753
|
-
function ie(e, t, s) {
|
|
754
|
-
const n = F(
|
|
755
|
-
e[0],
|
|
756
|
-
s
|
|
757
|
-
), o = {};
|
|
758
|
-
for (const c of t)
|
|
759
|
-
o[c.challengerPubkey] = {
|
|
760
|
-
nopayout_signature: F(
|
|
761
|
-
e[c.noPayoutIdx],
|
|
762
|
-
s
|
|
763
|
-
)
|
|
764
|
-
};
|
|
765
|
-
return {
|
|
766
|
-
payout_signatures: {
|
|
767
|
-
payout_signature: n
|
|
768
|
-
},
|
|
769
|
-
per_challenger: o
|
|
770
|
-
};
|
|
771
|
-
}
|
|
772
|
-
async function ce(e, t, s) {
|
|
773
|
-
if (typeof e.signPsbts == "function")
|
|
774
|
-
return e.signPsbts(t, s);
|
|
775
|
-
const n = [];
|
|
776
|
-
for (let o = 0; o < t.length; o++)
|
|
777
|
-
n.push(await e.signPsbt(t[o], s == null ? void 0 : s[o]));
|
|
778
|
-
return n;
|
|
779
|
-
}
|
|
780
|
-
async function ae(e) {
|
|
781
|
-
const { depositorGraph: t, depositorBtcPubkey: s, btcWallet: n } = e, o = S(s), c = await n.getPublicKeyHex(), { psbtHexes: i, signOptions: a, challengerEntries: r } = re(t, c), u = await ce(
|
|
782
|
-
n,
|
|
783
|
-
i,
|
|
784
|
-
a
|
|
785
|
-
);
|
|
786
|
-
if (u.length !== i.length)
|
|
787
|
-
throw new Error(
|
|
788
|
-
`Wallet returned ${u.length} signed PSBTs, expected ${i.length}`
|
|
789
|
-
);
|
|
790
|
-
return ie(
|
|
791
|
-
u,
|
|
792
|
-
r,
|
|
793
|
-
o
|
|
794
|
-
);
|
|
795
|
-
}
|
|
796
|
-
const ue = 1200 * 1e3, gt = /* @__PURE__ */ new Set([
|
|
797
|
-
U.PENDING_ACKS,
|
|
798
|
-
U.PENDING_ACTIVATION,
|
|
799
|
-
U.ACTIVATED
|
|
800
|
-
]), fe = /* @__PURE__ */ new Set([
|
|
801
|
-
U.PENDING_DEPOSITOR_SIGNATURES,
|
|
802
|
-
...gt
|
|
803
|
-
]);
|
|
804
|
-
function he(e) {
|
|
805
|
-
return e.map((t) => ({
|
|
806
|
-
claimerPubkeyXOnly: q(t.claimer_pubkey),
|
|
807
|
-
payoutTxHex: t.payout_tx.tx_hex,
|
|
808
|
-
assertTxHex: t.assert_tx.tx_hex
|
|
809
|
-
}));
|
|
810
|
-
}
|
|
811
|
-
function le(e) {
|
|
812
|
-
const { output: t } = kt.payments.p2tr({
|
|
813
|
-
internalPubkey: ht.from(e, "hex")
|
|
814
|
-
});
|
|
815
|
-
if (!t)
|
|
816
|
-
throw new Error("Failed to derive BIP-86 P2TR scriptPubKey");
|
|
817
|
-
return t.toString("hex");
|
|
818
|
-
}
|
|
819
|
-
function be(e, t) {
|
|
820
|
-
const s = S(e).toLowerCase(), n = S(
|
|
821
|
-
t.vaultProviderBtcPubkey
|
|
822
|
-
).toLowerCase(), o = S(
|
|
823
|
-
t.depositorBtcPubkey
|
|
824
|
-
).toLowerCase();
|
|
825
|
-
if (s === n || s === o)
|
|
826
|
-
return t.registeredPayoutScriptPubKey;
|
|
827
|
-
if (!t.vaultKeeperBtcPubkeys.some(
|
|
828
|
-
(a) => S(a).toLowerCase() === s
|
|
829
|
-
))
|
|
830
|
-
throw new Error(
|
|
831
|
-
`Unknown claimer pubkey ${s}: not VP, depositor, or a registered vault keeper`
|
|
832
|
-
);
|
|
833
|
-
return `0x${le(s)}`;
|
|
834
|
-
}
|
|
835
|
-
function ct(e, t) {
|
|
836
|
-
return {
|
|
837
|
-
payoutTxHex: e.payoutTxHex,
|
|
838
|
-
peginTxHex: t.peginTxHex,
|
|
839
|
-
assertTxHex: e.assertTxHex,
|
|
840
|
-
vaultProviderBtcPubkey: t.vaultProviderBtcPubkey,
|
|
841
|
-
vaultKeeperBtcPubkeys: t.vaultKeeperBtcPubkeys,
|
|
842
|
-
universalChallengerBtcPubkeys: t.universalChallengerBtcPubkeys,
|
|
843
|
-
depositorBtcPubkey: t.depositorBtcPubkey,
|
|
844
|
-
timelockPegin: t.timelockPegin,
|
|
845
|
-
registeredPayoutScriptPubKey: be(
|
|
846
|
-
e.claimerPubkeyXOnly,
|
|
847
|
-
t
|
|
848
|
-
)
|
|
849
|
-
};
|
|
850
|
-
}
|
|
851
|
-
async function xe(e, t, s, n) {
|
|
852
|
-
const o = new Et({
|
|
853
|
-
network: t.network,
|
|
854
|
-
btcWallet: e
|
|
855
|
-
}), c = s.length;
|
|
856
|
-
n == null || n(0, c);
|
|
857
|
-
let i;
|
|
858
|
-
if (o.supportsBatchSigning())
|
|
859
|
-
i = (await o.signPayoutTransactionsBatch(
|
|
860
|
-
s.map((u) => ct(u, t))
|
|
861
|
-
)).map((u) => u.payoutSignature);
|
|
862
|
-
else {
|
|
863
|
-
i = [];
|
|
864
|
-
for (let r = 0; r < s.length; r++) {
|
|
865
|
-
n == null || n(r, c);
|
|
866
|
-
const u = await o.signPayoutTransaction(
|
|
867
|
-
ct(s[r], t)
|
|
868
|
-
);
|
|
869
|
-
i.push(u.signature);
|
|
870
|
-
}
|
|
871
|
-
}
|
|
872
|
-
const a = {};
|
|
873
|
-
for (let r = 0; r < s.length; r++)
|
|
874
|
-
a[s[r].claimerPubkeyXOnly] = {
|
|
875
|
-
payout_signature: i[r]
|
|
876
|
-
};
|
|
877
|
-
return n == null || n(c, c), a;
|
|
878
|
-
}
|
|
879
|
-
async function Ke(e) {
|
|
880
|
-
const {
|
|
881
|
-
statusReader: t,
|
|
882
|
-
presignClient: s,
|
|
883
|
-
btcWallet: n,
|
|
884
|
-
peginTxid: o,
|
|
885
|
-
depositorPk: c,
|
|
886
|
-
signingContext: i,
|
|
887
|
-
timeoutMs: a = ue,
|
|
888
|
-
signal: r,
|
|
889
|
-
onProgress: u
|
|
890
|
-
} = e, l = await pt({
|
|
891
|
-
statusReader: t,
|
|
892
|
-
peginTxid: o,
|
|
893
|
-
targetStatuses: fe,
|
|
894
|
-
timeoutMs: a,
|
|
895
|
-
signal: r
|
|
896
|
-
});
|
|
897
|
-
if (gt.has(l))
|
|
898
|
-
return;
|
|
899
|
-
r == null || r.throwIfAborted();
|
|
900
|
-
const f = await s.requestDepositorPresignTransactions(
|
|
901
|
-
{
|
|
902
|
-
pegin_txid: o,
|
|
903
|
-
depositor_pk: c
|
|
904
|
-
},
|
|
905
|
-
r
|
|
906
|
-
);
|
|
907
|
-
r == null || r.throwIfAborted();
|
|
908
|
-
const b = q(c), d = f.txs.filter(
|
|
909
|
-
(v) => q(v.claimer_pubkey) !== b
|
|
910
|
-
), y = he(d), p = await xe(
|
|
911
|
-
n,
|
|
912
|
-
i,
|
|
913
|
-
y,
|
|
914
|
-
u
|
|
915
|
-
);
|
|
916
|
-
r == null || r.throwIfAborted();
|
|
917
|
-
const P = await ae({
|
|
918
|
-
depositorGraph: f.depositor_graph,
|
|
919
|
-
depositorBtcPubkey: c,
|
|
920
|
-
btcWallet: n
|
|
921
|
-
});
|
|
922
|
-
r == null || r.throwIfAborted();
|
|
923
|
-
const k = { ...p };
|
|
924
|
-
k[S(c)] = P.payout_signatures, await s.submitDepositorPresignatures(
|
|
925
|
-
{
|
|
926
|
-
pegin_txid: o,
|
|
927
|
-
depositor_pk: c,
|
|
928
|
-
signatures: k,
|
|
929
|
-
depositor_claimer_presignatures: P
|
|
930
|
-
},
|
|
931
|
-
r
|
|
932
|
-
);
|
|
933
|
-
}
|
|
934
|
-
const at = 66;
|
|
935
|
-
function yt(e) {
|
|
936
|
-
if (!e.startsWith("0x") && !e.startsWith("0X"))
|
|
937
|
-
throw new Error("Expected 0x-prefixed hex string");
|
|
938
|
-
const t = e.slice(2);
|
|
939
|
-
if (t.length % 2 !== 0)
|
|
940
|
-
throw new Error(`Hex string has odd length: ${t.length}`);
|
|
941
|
-
if (!/^[0-9a-fA-F]*$/.test(t))
|
|
942
|
-
throw new Error("Hex string contains non-hex characters");
|
|
943
|
-
const s = new Uint8Array(t.length / 2);
|
|
944
|
-
for (let n = 0; n < s.length; n++)
|
|
945
|
-
s[n] = parseInt(t.slice(n * 2, n * 2 + 2), 16);
|
|
946
|
-
return s;
|
|
947
|
-
}
|
|
948
|
-
function de(e) {
|
|
949
|
-
return `0x${Array.from(e).map((t) => t.toString(16).padStart(2, "0")).join("")}`;
|
|
950
|
-
}
|
|
951
|
-
function J(e, t) {
|
|
952
|
-
if (e.length !== at)
|
|
953
|
-
throw new Error(
|
|
954
|
-
`${t} must be exactly 32 bytes (${at} hex chars with 0x prefix), got ${e.length}`
|
|
955
|
-
);
|
|
956
|
-
}
|
|
957
|
-
function pe(e) {
|
|
958
|
-
J(e, "Secret");
|
|
959
|
-
const t = yt(e), s = Qt(t);
|
|
960
|
-
return de(s);
|
|
961
|
-
}
|
|
962
|
-
function $e(e, t) {
|
|
963
|
-
return J(e, "Secret"), J(t, "Hashlock"), yt(t), pe(e).toLowerCase() === t.toLowerCase();
|
|
964
|
-
}
|
|
965
|
-
export {
|
|
966
|
-
xt as H,
|
|
967
|
-
Et as P,
|
|
968
|
-
ae as a,
|
|
969
|
-
ke as b,
|
|
970
|
-
pe as c,
|
|
971
|
-
Y as d,
|
|
972
|
-
D as e,
|
|
973
|
-
st as f,
|
|
974
|
-
lt as g,
|
|
975
|
-
$t as h,
|
|
976
|
-
et as i,
|
|
977
|
-
Ee as j,
|
|
978
|
-
Lt as k,
|
|
979
|
-
Ie as l,
|
|
980
|
-
ve as m,
|
|
981
|
-
Ce as n,
|
|
982
|
-
Oe as o,
|
|
983
|
-
Ke as p,
|
|
984
|
-
z as q,
|
|
985
|
-
Ae as r,
|
|
986
|
-
De as s,
|
|
987
|
-
Le as t,
|
|
988
|
-
_e as u,
|
|
989
|
-
$e as v,
|
|
990
|
-
pt as w,
|
|
991
|
-
Be as x,
|
|
992
|
-
Ue as y,
|
|
993
|
-
Qt as z
|
|
994
|
-
};
|
|
995
|
-
//# sourceMappingURL=index-BX-V3C9t.js.map
|