@babylonlabs-io/ts-sdk 0.20.1 → 0.22.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 +14 -6
- package/dist/{errors-D_PI__IT.js → errors-CkkL1ztr.js} +338 -328
- package/dist/errors-CkkL1ztr.js.map +1 -0
- package/dist/errors-D2H46Yut.cjs +2 -0
- package/dist/errors-D2H46Yut.cjs.map +1 -0
- package/dist/index-BAECy2oz.cjs +2 -0
- package/dist/index-BAECy2oz.cjs.map +1 -0
- package/dist/{index-CFwoGJNQ.js → index-DLtpqdlu.js} +141 -115
- package/dist/index-DLtpqdlu.js.map +1 -0
- package/dist/index.cjs +1 -1
- package/dist/index.js +124 -117
- package/dist/index.js.map +1 -1
- package/dist/shared/wallets/index.d.ts +8 -0
- package/dist/shared/wallets/index.d.ts.map +1 -1
- package/dist/tbv/core/clients/index.cjs +1 -1
- package/dist/tbv/core/clients/index.d.ts +3 -2
- package/dist/tbv/core/clients/index.d.ts.map +1 -1
- package/dist/tbv/core/clients/index.js +16 -15
- package/dist/tbv/core/clients/mempool/mempoolApi.d.ts.map +1 -1
- package/dist/tbv/core/clients/vault-provider/index.d.ts +1 -1
- package/dist/tbv/core/clients/vault-provider/index.d.ts.map +1 -1
- package/dist/tbv/core/contracts/errors.d.ts.map +1 -1
- package/dist/tbv/core/index.cjs +1 -1
- package/dist/tbv/core/index.js +120 -113
- package/dist/tbv/core/index.js.map +1 -1
- package/dist/tbv/core/managers/PeginManager.d.ts.map +1 -1
- package/dist/tbv/core/managers/index.d.ts +15 -62
- package/dist/tbv/core/managers/index.d.ts.map +1 -1
- package/dist/tbv/core/services/index.d.ts +2 -4
- package/dist/tbv/core/services/index.d.ts.map +1 -1
- package/dist/tbv/core/utils/index.cjs +1 -1
- package/dist/tbv/core/utils/index.d.ts +2 -7
- package/dist/tbv/core/utils/index.d.ts.map +1 -1
- package/dist/tbv/core/utils/index.js +37 -31
- package/dist/tbv/core/utils/index.js.map +1 -1
- package/dist/tbv/core/utils/validation.d.ts +35 -0
- package/dist/tbv/core/utils/validation.d.ts.map +1 -0
- package/dist/tbv/index.cjs +1 -1
- package/dist/tbv/index.js +120 -113
- package/dist/tbv/index.js.map +1 -1
- package/dist/validation-CxqROCno.js +15 -0
- package/dist/validation-CxqROCno.js.map +1 -0
- package/dist/validation-u8W7Lp2x.cjs +2 -0
- package/dist/validation-u8W7Lp2x.cjs.map +1 -0
- package/package.json +1 -1
- package/dist/errors-D9EtjJoD.cjs +0 -2
- package/dist/errors-D9EtjJoD.cjs.map +0 -1
- package/dist/errors-D_PI__IT.js.map +0 -1
- package/dist/index-BpXpESWu.cjs +0 -2
- package/dist/index-BpXpESWu.cjs.map +0 -1
- package/dist/index-CFwoGJNQ.js.map +0 -1
|
@@ -1,36 +1,42 @@
|
|
|
1
1
|
import { c as t } from "../../../signing-DeWVBl7m.js";
|
|
2
|
-
import { B as
|
|
3
|
-
import { B as R,
|
|
4
|
-
import { g as b } from "../../../
|
|
2
|
+
import { B as E, H as T, K as _, M as o, T as r } from "../../../validation-CxqROCno.js";
|
|
3
|
+
import { B as A, D as R, F as i, L as p, M as n, P as I, a as U, S as c, T as F, W as l, f as x, b as O, p as P, r as u } from "../../../fundPeginTransaction-BLYXxLBv.js";
|
|
4
|
+
import { B as f, U as B, a as D, f as L, c as N, e as g, g as C, i as H, h as X, s as h, b as m, d as M, v as b } from "../../../psbtInputFields-r1ss6WLU.js";
|
|
5
|
+
import { g as W } from "../../../bitcoin-nOOgeRyl.js";
|
|
5
6
|
export {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
7
|
+
E as BITCOIN_ADDRESS_RE,
|
|
8
|
+
A as BTC_DUST_SAT,
|
|
9
|
+
f as BitcoinScriptType,
|
|
10
|
+
R as DUST_THRESHOLD,
|
|
11
|
+
i as FEE_SAFETY_MARGIN,
|
|
12
|
+
T as HEX_RE,
|
|
13
|
+
_ as KNOWN_SCRIPT_PREFIXES,
|
|
14
|
+
p as LOW_RATE_ESTIMATION_ACCURACY_BUFFER,
|
|
15
|
+
n as MAX_NON_LEGACY_OUTPUT_SIZE,
|
|
16
|
+
o as MAX_REASONABLE_FEE_SATS,
|
|
17
|
+
I as P2TR_INPUT_SIZE,
|
|
18
|
+
U as PEGIN_FIXED_OUTPUTS,
|
|
19
|
+
c as SPLIT_TX_FEE_SAFETY_MULTIPLIER,
|
|
20
|
+
r as TXID_RE,
|
|
21
|
+
F as TX_BUFFER_SIZE_OVERHEAD,
|
|
22
|
+
B as UtxoNotAvailableError,
|
|
23
|
+
l as WALLET_RELAY_FEE_RATE_THRESHOLD,
|
|
24
|
+
D as assertUtxosAvailable,
|
|
25
|
+
L as calculateBtcTxHash,
|
|
26
|
+
N as collectReservedUtxoRefs,
|
|
21
27
|
t as createTaprootScriptPathSignOptions,
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
28
|
+
g as extractInputsFromTransaction,
|
|
29
|
+
x as fundPeginTransaction,
|
|
30
|
+
C as getDustThreshold,
|
|
31
|
+
W as getNetwork,
|
|
32
|
+
H as getPsbtInputFields,
|
|
33
|
+
X as getScriptType,
|
|
34
|
+
O as parseUnfundedWasmTransaction,
|
|
35
|
+
P as peginOutputCount,
|
|
36
|
+
u as rateBasedTxBufferFee,
|
|
37
|
+
h as selectUtxosForDeposit,
|
|
38
|
+
m as selectUtxosForPegin,
|
|
39
|
+
M as shouldAddChangeOutput,
|
|
40
|
+
b as validateUtxosAvailable
|
|
35
41
|
};
|
|
36
42
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared validation constants for Bitcoin-related input sanitization.
|
|
3
|
+
*
|
|
4
|
+
* These are used across mempool API clients, broadcast services, and
|
|
5
|
+
* transaction construction to enforce consistent format checks.
|
|
6
|
+
*/
|
|
7
|
+
/** Non-empty string of hexadecimal characters (case-insensitive). */
|
|
8
|
+
export declare const HEX_RE: RegExp;
|
|
9
|
+
/** Bitcoin txid: exactly 64 hex characters (32 bytes). */
|
|
10
|
+
export declare const TXID_RE: RegExp;
|
|
11
|
+
/**
|
|
12
|
+
* Bitcoin address format gate: 25–90 alphanumeric characters.
|
|
13
|
+
* Covers legacy (P2PKH/P2SH), bech32 (P2WPKH/P2WSH), bech32m (P2TR),
|
|
14
|
+
* and regtest addresses (bcrt1... which are 62–64 chars for 32-byte witness programs).
|
|
15
|
+
* Upper bound of 90 provides headroom for future address formats.
|
|
16
|
+
* This is a format gate to prevent path-traversal — not full address validation.
|
|
17
|
+
*/
|
|
18
|
+
export declare const BITCOIN_ADDRESS_RE: RegExp;
|
|
19
|
+
/**
|
|
20
|
+
* Known Bitcoin scriptPubKey prefixes:
|
|
21
|
+
* - P2PKH: 76a914...88ac (25 bytes)
|
|
22
|
+
* - P2SH: a914...87 (23 bytes)
|
|
23
|
+
* - P2WPKH: 0014... (22 bytes)
|
|
24
|
+
* - P2WSH: 0020... (34 bytes)
|
|
25
|
+
* - P2TR: 5120... (34 bytes)
|
|
26
|
+
*/
|
|
27
|
+
export declare const KNOWN_SCRIPT_PREFIXES: readonly ["76a914", "a914", "0014", "0020", "5120"];
|
|
28
|
+
/**
|
|
29
|
+
* Upper bound on the implied miner fee (0.01 BTC = 1,000,000 sats).
|
|
30
|
+
* Catches inflated input values from a compromised mempool API — if inputs are
|
|
31
|
+
* grossly overstated the implied fee becomes unreasonably large. The April 2024
|
|
32
|
+
* Runes spike saw ~450 sat/vB; at 500 vB that's ~225k sats, well under this cap.
|
|
33
|
+
*/
|
|
34
|
+
export declare const MAX_REASONABLE_FEE_SATS = 1000000n;
|
|
35
|
+
//# sourceMappingURL=validation.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validation.d.ts","sourceRoot":"","sources":["../../../../src/tbv/core/utils/validation.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,qEAAqE;AACrE,eAAO,MAAM,MAAM,QAAmB,CAAC;AAEvC,0DAA0D;AAC1D,eAAO,MAAM,OAAO,QAAsB,CAAC;AAE3C;;;;;;GAMG;AACH,eAAO,MAAM,kBAAkB,QAAyB,CAAC;AAEzD;;;;;;;GAOG;AACH,eAAO,MAAM,qBAAqB,qDAMxB,CAAC;AAEX;;;;;GAKG;AACH,eAAO,MAAM,uBAAuB,WAAa,CAAC"}
|
package/dist/tbv/index.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=require("../challengeAssert-nYlgeAI8.cjs"),
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=require("../challengeAssert-nYlgeAI8.cjs"),c=require("@babylonlabs-io/babylon-tbv-rust-wasm"),P=require("../payout-RFIh7GLN.cjs"),o=require("../bitcoin-CNnPFU6Y.cjs"),l=require("../signing-cl-lowxV.cjs"),u=require("../validation-u8W7Lp2x.cjs"),e=require("../buildAndBroadcastRefund-DWEQvj9T.cjs"),r=require("../fundPeginTransaction-DxNOeyNI.cjs"),i=require("../psbtInputFields-05ZrwRzf.cjs"),a=require("../errors-D2H46Yut.cjs"),t=require("../index-BAECy2oz.cjs"),s=require("../types-B-p4dhEH.cjs");exports.buildChallengeAssertPsbt=n.buildChallengeAssertPsbt;exports.buildDepositorPayoutPsbt=n.buildDepositorPayoutPsbt;exports.buildNoPayoutPsbt=n.buildNoPayoutPsbt;exports.buildPeginInputPsbt=n.buildPeginInputPsbt;exports.buildPeginTxFromFundedPrePegin=n.buildPeginTxFromFundedPrePegin;exports.buildPrePeginPsbt=n.buildPrePeginPsbt;exports.computeNumLocalChallengers=n.computeNumLocalChallengers;exports.extractPeginInputSignature=n.extractPeginInputSignature;exports.finalizePeginInputPsbt=n.finalizePeginInputPsbt;Object.defineProperty(exports,"computeMinClaimValue",{enumerable:!0,get:()=>c.computeMinClaimValue});Object.defineProperty(exports,"deriveVaultId",{enumerable:!0,get:()=>c.deriveVaultId});exports.buildPayoutPsbt=P.buildPayoutPsbt;exports.buildRefundPsbt=P.buildRefundPsbt;exports.createPayoutScript=P.createPayoutScript;exports.extractPayoutSignature=P.extractPayoutSignature;exports.deriveNativeSegwitAddress=o.deriveNativeSegwitAddress;exports.deriveTaprootAddress=o.deriveTaprootAddress;exports.ensureHexPrefix=o.ensureHexPrefix;exports.formatSatoshisToBtc=o.formatSatoshisToBtc;exports.getNetwork=o.getNetwork;exports.hexToUint8Array=o.hexToUint8Array;exports.isAddressFromPublicKey=o.isAddressFromPublicKey;exports.isValidHex=o.isValidHex;exports.processPublicKeyToXOnly=o.processPublicKeyToXOnly;exports.stripHexPrefix=o.stripHexPrefix;exports.toXOnly=o.toXOnly;exports.uint8ArrayToHex=o.uint8ArrayToHex;exports.validateWalletPubkey=o.validateWalletPubkey;exports.ContractStatus=l.ContractStatus;exports.PeginAction=l.PeginAction;exports.canPerformAction=l.canPerformAction;exports.createTaprootScriptPathSignOptions=l.createTaprootScriptPathSignOptions;exports.getPeginProtocolState=l.getPeginProtocolState;exports.BITCOIN_ADDRESS_RE=u.BITCOIN_ADDRESS_RE;exports.HEX_RE=u.HEX_RE;exports.KNOWN_SCRIPT_PREFIXES=u.KNOWN_SCRIPT_PREFIXES;exports.MAX_REASONABLE_FEE_SATS=u.MAX_REASONABLE_FEE_SATS;exports.TXID_RE=u.TXID_RE;exports.BIP68NotMatureError=e.BIP68NotMatureError;exports.ClaimerPegoutStatusValue=e.ClaimerPegoutStatusValue;exports.PayoutManager=e.PayoutManager;exports.activateVault=e.activateVault;exports.buildAndBroadcastRefund=e.buildAndBroadcastRefund;exports.computeHashlock=e.computeHashlock;exports.isDepositAmountValid=e.isDepositAmountValid;exports.isPegoutTerminalStatus=e.isPegoutTerminalStatus;exports.isRecognizedPegoutStatus=e.isRecognizedPegoutStatus;exports.pollAndSignPayouts=e.pollAndSignPayouts;exports.signDepositorGraph=e.signDepositorGraph;exports.submitWotsPublicKey=e.submitWotsPublicKey;exports.validateDepositAmount=e.validateDepositAmount;exports.validateMultiVaultDepositInputs=e.validateMultiVaultDepositInputs;exports.validateProviderSelection=e.validateProviderSelection;exports.validateRemainingCapacity=e.validateRemainingCapacity;exports.validateSecretAgainstHashlock=e.validateSecretAgainstHashlock;exports.validateVaultAmounts=e.validateVaultAmounts;exports.validateVaultProviderPubkey=e.validateVaultProviderPubkey;exports.waitForPeginStatus=e.waitForPeginStatus;exports.BTC_DUST_SAT=r.BTC_DUST_SAT;exports.DUST_THRESHOLD=r.DUST_THRESHOLD;exports.FEE_SAFETY_MARGIN=r.FEE_SAFETY_MARGIN;exports.LOW_RATE_ESTIMATION_ACCURACY_BUFFER=r.LOW_RATE_ESTIMATION_ACCURACY_BUFFER;exports.MAX_NON_LEGACY_OUTPUT_SIZE=r.MAX_NON_LEGACY_OUTPUT_SIZE;exports.P2TR_INPUT_SIZE=r.P2TR_INPUT_SIZE;exports.PEGIN_FIXED_OUTPUTS=r.PEGIN_FIXED_OUTPUTS;exports.SPLIT_TX_FEE_SAFETY_MULTIPLIER=r.SPLIT_TX_FEE_SAFETY_MULTIPLIER;exports.TX_BUFFER_SIZE_OVERHEAD=r.TX_BUFFER_SIZE_OVERHEAD;exports.WALLET_RELAY_FEE_RATE_THRESHOLD=r.WALLET_RELAY_FEE_RATE_THRESHOLD;exports.fundPeginTransaction=r.fundPeginTransaction;exports.parseUnfundedWasmTransaction=r.parseUnfundedWasmTransaction;exports.peginOutputCount=r.peginOutputCount;exports.rateBasedTxBufferFee=r.rateBasedTxBufferFee;exports.BitcoinScriptType=i.BitcoinScriptType;exports.UtxoNotAvailableError=i.UtxoNotAvailableError;exports.assertUtxosAvailable=i.assertUtxosAvailable;exports.calculateBtcTxHash=i.calculateBtcTxHash;exports.collectReservedUtxoRefs=i.collectReservedUtxoRefs;exports.extractInputsFromTransaction=i.extractInputsFromTransaction;exports.getDustThreshold=i.getDustThreshold;exports.getPsbtInputFields=i.getPsbtInputFields;exports.getScriptType=i.getScriptType;exports.selectUtxosForDeposit=i.selectUtxosForDeposit;exports.selectUtxosForPegin=i.selectUtxosForPegin;exports.shouldAddChangeOutput=i.shouldAddChangeOutput;exports.validateUtxosAvailable=i.validateUtxosAvailable;exports.CONTRACT_ERRORS=a.CONTRACT_ERRORS;exports.PeginManager=a.PeginManager;exports.computeWotsBlockPublicKeysHash=a.computeWotsBlockPublicKeysHash;exports.computeWotsPkHash=a.computeWotsPkHash;exports.deriveWotsBlockPublicKeys=a.deriveWotsBlockPublicKeys;exports.deriveWotsKeypair=a.deriveWotsKeypair;exports.deriveWotsPkHash=a.deriveWotsPkHash;exports.extractErrorData=a.extractErrorData;exports.getContractErrorMessage=a.getContractErrorMessage;exports.handleContractError=a.handleContractError;exports.isKnownContractError=a.isKnownContractError;exports.isWotsMismatchError=a.isWotsMismatchError;exports.keypairToPublicKey=a.keypairToPublicKey;exports.mnemonicToWotsSeed=a.mnemonicToWotsSeed;exports.ApplicationRegistryABI=t.ApplicationRegistryABI;exports.MEMPOOL_API_URLS=t.MEMPOOL_API_URLS;exports.ProtocolParamsABI=t.ProtocolParamsABI;exports.VaultProviderRpcClient=t.VaultProviderRpcClient;exports.ViemProtocolParamsReader=t.ViemProtocolParamsReader;exports.ViemUniversalChallengerReader=t.ViemUniversalChallengerReader;exports.ViemVaultKeeperReader=t.ViemVaultKeeperReader;exports.ViemVaultRegistryReader=t.ViemVaultRegistryReader;exports.VpResponseValidationError=t.VpResponseValidationError;exports.getAddressTxs=t.getAddressTxs;exports.getAddressUtxos=t.getAddressUtxos;exports.getMempoolApiUrl=t.getMempoolApiUrl;exports.getNetworkFees=t.getNetworkFees;exports.getTxHex=t.getTxHex;exports.getTxInfo=t.getTxInfo;exports.getUtxoInfo=t.getUtxoInfo;exports.pushTx=t.pushTx;exports.resolveProtocolAddresses=t.resolveProtocolAddresses;exports.validateRequestDepositorClaimerArtifactsResponse=t.validateRequestDepositorClaimerArtifactsResponse;exports.BTCVaultRegistryABI=s.BTCVaultRegistryABI;exports.DaemonStatus=s.DaemonStatus;exports.JSON_RPC_ERROR_CODES=s.JSON_RPC_ERROR_CODES;exports.JsonRpcClient=s.JsonRpcClient;exports.JsonRpcError=s.JsonRpcError;exports.POST_WOTS_STATUSES=s.POST_WOTS_STATUSES;exports.PRE_DEPOSITOR_SIGNATURES_STATES=s.PRE_DEPOSITOR_SIGNATURES_STATES;exports.RpcErrorCode=s.RpcErrorCode;exports.VP_TERMINAL_STATUSES=s.VP_TERMINAL_STATUSES;exports.VP_TRANSIENT_STATUSES=s.VP_TRANSIENT_STATUSES;
|
|
2
2
|
//# sourceMappingURL=index.cjs.map
|
package/dist/tbv/index.js
CHANGED
|
@@ -1,136 +1,143 @@
|
|
|
1
1
|
import { i as e, g as t, h as o, d as r, a as i, b as l, c as n, e as u, f as P } from "../challengeAssert-D1lpvuMv.js";
|
|
2
|
-
import { computeMinClaimValue as c, deriveVaultId as
|
|
3
|
-
import { a as
|
|
4
|
-
import { d as
|
|
5
|
-
import { C as
|
|
6
|
-
import { B as
|
|
7
|
-
import { B as
|
|
8
|
-
import { B as
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
2
|
+
import { computeMinClaimValue as c, deriveVaultId as T } from "@babylonlabs-io/babylon-tbv-rust-wasm";
|
|
3
|
+
import { a as S, b as E, c as A, e as g } from "../payout-DzGsAnhf.js";
|
|
4
|
+
import { d as _, a as m, e as b, f as x, g as I, h as f, i as v, b as C, p as U, s as y, t as O, u as h, v as V } from "../bitcoin-nOOgeRyl.js";
|
|
5
|
+
import { C as D, P as F, a as N, c as M, g as H } from "../signing-DeWVBl7m.js";
|
|
6
|
+
import { B as W, H as k, K, M as X, T as w } from "../validation-CxqROCno.js";
|
|
7
|
+
import { B as Y, C as J, P as j, a as Z, m as z, h as q, i as Q, l as $, k as aa, p as sa, b as ea, s as ta, v as oa, g as ra, d as ia, c as la, j as na, e as ua, f as Pa, w as da } from "../buildAndBroadcastRefund-DnTQkCgG.js";
|
|
8
|
+
import { B as Ta, D as pa, F as Sa, L as Ea, M as Aa, P as ga, a as Ra, S as _a, T as ma, W as ba, f as xa, b as Ia, p as fa, r as va } from "../fundPeginTransaction-BLYXxLBv.js";
|
|
9
|
+
import { B as Ua, U as ya, a as Oa, f as ha, c as Va, e as Ba, g as Da, i as Fa, h as Na, s as Ma, b as Ha, d as La, v as Wa } from "../psbtInputFields-r1ss6WLU.js";
|
|
10
|
+
import { C as Ka, P as Xa, b as wa, c as Ga, a as Ya, d as Ja, f as ja, e as Za, g as za, h as qa, i as Qa, j as $a, k as as, m as ss } from "../errors-CkkL1ztr.js";
|
|
11
|
+
import { A as ts, M as os, P as rs, V as is, i as ls, j as ns, k as us, l as Ps, h as ds, g as cs, a as Ts, b as ps, c as Ss, d as Es, e as As, f as gs, p as Rs, r as _s, v as ms } from "../index-DLtpqdlu.js";
|
|
12
|
+
import { B as xs, D as Is, b as fs, J as vs, a as Cs, d as Us, P as ys, R as Os, c as hs, V as Vs } from "../types-DWjaqVfP.js";
|
|
12
13
|
export {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
14
|
+
ts as ApplicationRegistryABI,
|
|
15
|
+
Y as BIP68NotMatureError,
|
|
16
|
+
W as BITCOIN_ADDRESS_RE,
|
|
17
|
+
xs as BTCVaultRegistryABI,
|
|
18
|
+
Ta as BTC_DUST_SAT,
|
|
19
|
+
Ua as BitcoinScriptType,
|
|
20
|
+
Ka as CONTRACT_ERRORS,
|
|
21
|
+
J as ClaimerPegoutStatusValue,
|
|
22
|
+
D as ContractStatus,
|
|
23
|
+
pa as DUST_THRESHOLD,
|
|
24
|
+
Is as DaemonStatus,
|
|
25
|
+
Sa as FEE_SAFETY_MARGIN,
|
|
26
|
+
k as HEX_RE,
|
|
27
|
+
fs as JSON_RPC_ERROR_CODES,
|
|
28
|
+
vs as JsonRpcClient,
|
|
29
|
+
Cs as JsonRpcError,
|
|
30
|
+
K as KNOWN_SCRIPT_PREFIXES,
|
|
31
|
+
Ea as LOW_RATE_ESTIMATION_ACCURACY_BUFFER,
|
|
32
|
+
Aa as MAX_NON_LEGACY_OUTPUT_SIZE,
|
|
33
|
+
X as MAX_REASONABLE_FEE_SATS,
|
|
34
|
+
os as MEMPOOL_API_URLS,
|
|
35
|
+
ga as P2TR_INPUT_SIZE,
|
|
36
|
+
Ra as PEGIN_FIXED_OUTPUTS,
|
|
37
|
+
Us as POST_WOTS_STATUSES,
|
|
38
|
+
ys as PRE_DEPOSITOR_SIGNATURES_STATES,
|
|
39
|
+
j as PayoutManager,
|
|
40
|
+
F as PeginAction,
|
|
41
|
+
Xa as PeginManager,
|
|
42
|
+
rs as ProtocolParamsABI,
|
|
43
|
+
Os as RpcErrorCode,
|
|
44
|
+
_a as SPLIT_TX_FEE_SAFETY_MULTIPLIER,
|
|
45
|
+
w as TXID_RE,
|
|
46
|
+
ma as TX_BUFFER_SIZE_OVERHEAD,
|
|
47
|
+
ya as UtxoNotAvailableError,
|
|
48
|
+
hs as VP_TERMINAL_STATUSES,
|
|
49
|
+
Vs as VP_TRANSIENT_STATUSES,
|
|
50
|
+
is as VaultProviderRpcClient,
|
|
51
|
+
ls as ViemProtocolParamsReader,
|
|
52
|
+
ns as ViemUniversalChallengerReader,
|
|
53
|
+
us as ViemVaultKeeperReader,
|
|
54
|
+
Ps as ViemVaultRegistryReader,
|
|
55
|
+
ds as VpResponseValidationError,
|
|
56
|
+
ba as WALLET_RELAY_FEE_RATE_THRESHOLD,
|
|
57
|
+
Z as activateVault,
|
|
58
|
+
Oa as assertUtxosAvailable,
|
|
59
|
+
z as buildAndBroadcastRefund,
|
|
54
60
|
e as buildChallengeAssertPsbt,
|
|
55
61
|
t as buildDepositorPayoutPsbt,
|
|
56
62
|
o as buildNoPayoutPsbt,
|
|
57
|
-
|
|
63
|
+
S as buildPayoutPsbt,
|
|
58
64
|
r as buildPeginInputPsbt,
|
|
59
65
|
i as buildPeginTxFromFundedPrePegin,
|
|
60
66
|
l as buildPrePeginPsbt,
|
|
61
|
-
|
|
62
|
-
|
|
67
|
+
E as buildRefundPsbt,
|
|
68
|
+
ha as calculateBtcTxHash,
|
|
63
69
|
N as canPerformAction,
|
|
64
|
-
|
|
65
|
-
|
|
70
|
+
Va as collectReservedUtxoRefs,
|
|
71
|
+
q as computeHashlock,
|
|
66
72
|
c as computeMinClaimValue,
|
|
67
73
|
n as computeNumLocalChallengers,
|
|
68
|
-
|
|
69
|
-
|
|
74
|
+
wa as computeWotsBlockPublicKeysHash,
|
|
75
|
+
Ga as computeWotsPkHash,
|
|
70
76
|
A as createPayoutScript,
|
|
71
77
|
M as createTaprootScriptPathSignOptions,
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
+
_ as deriveNativeSegwitAddress,
|
|
79
|
+
m as deriveTaprootAddress,
|
|
80
|
+
T as deriveVaultId,
|
|
81
|
+
Ya as deriveWotsBlockPublicKeys,
|
|
82
|
+
Ja as deriveWotsKeypair,
|
|
83
|
+
ja as deriveWotsPkHash,
|
|
78
84
|
b as ensureHexPrefix,
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
85
|
+
Za as extractErrorData,
|
|
86
|
+
Ba as extractInputsFromTransaction,
|
|
87
|
+
g as extractPayoutSignature,
|
|
82
88
|
u as extractPeginInputSignature,
|
|
83
89
|
P as finalizePeginInputPsbt,
|
|
84
90
|
x as formatSatoshisToBtc,
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
91
|
+
xa as fundPeginTransaction,
|
|
92
|
+
cs as getAddressTxs,
|
|
93
|
+
Ts as getAddressUtxos,
|
|
94
|
+
za as getContractErrorMessage,
|
|
95
|
+
Da as getDustThreshold,
|
|
96
|
+
ps as getMempoolApiUrl,
|
|
97
|
+
I as getNetwork,
|
|
98
|
+
Ss as getNetworkFees,
|
|
93
99
|
H as getPeginProtocolState,
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
100
|
+
Fa as getPsbtInputFields,
|
|
101
|
+
Na as getScriptType,
|
|
102
|
+
Es as getTxHex,
|
|
103
|
+
As as getTxInfo,
|
|
104
|
+
gs as getUtxoInfo,
|
|
105
|
+
qa as handleContractError,
|
|
106
|
+
f as hexToUint8Array,
|
|
101
107
|
v as isAddressFromPublicKey,
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
108
|
+
Q as isDepositAmountValid,
|
|
109
|
+
Qa as isKnownContractError,
|
|
110
|
+
$ as isPegoutTerminalStatus,
|
|
111
|
+
aa as isRecognizedPegoutStatus,
|
|
112
|
+
C as isValidHex,
|
|
113
|
+
$a as isWotsMismatchError,
|
|
114
|
+
as as keypairToPublicKey,
|
|
115
|
+
ss as mnemonicToWotsSeed,
|
|
116
|
+
Ia as parseUnfundedWasmTransaction,
|
|
117
|
+
fa as peginOutputCount,
|
|
118
|
+
sa as pollAndSignPayouts,
|
|
119
|
+
U as processPublicKeyToXOnly,
|
|
120
|
+
Rs as pushTx,
|
|
121
|
+
va as rateBasedTxBufferFee,
|
|
122
|
+
_s as resolveProtocolAddresses,
|
|
123
|
+
Ma as selectUtxosForDeposit,
|
|
124
|
+
Ha as selectUtxosForPegin,
|
|
125
|
+
La as shouldAddChangeOutput,
|
|
126
|
+
ea as signDepositorGraph,
|
|
121
127
|
y as stripHexPrefix,
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
128
|
+
ta as submitWotsPublicKey,
|
|
129
|
+
O as toXOnly,
|
|
130
|
+
h as uint8ArrayToHex,
|
|
131
|
+
oa as validateDepositAmount,
|
|
132
|
+
ra as validateMultiVaultDepositInputs,
|
|
133
|
+
ia as validateProviderSelection,
|
|
134
|
+
la as validateRemainingCapacity,
|
|
135
|
+
ms as validateRequestDepositorClaimerArtifactsResponse,
|
|
136
|
+
na as validateSecretAgainstHashlock,
|
|
137
|
+
Wa as validateUtxosAvailable,
|
|
138
|
+
ua as validateVaultAmounts,
|
|
139
|
+
Pa as validateVaultProviderPubkey,
|
|
133
140
|
V as validateWalletPubkey,
|
|
134
|
-
|
|
141
|
+
da as waitForPeginStatus
|
|
135
142
|
};
|
|
136
143
|
//# sourceMappingURL=index.js.map
|
package/dist/tbv/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
const E = /^[0-9a-fA-F]+$/, a = /^[0-9a-fA-F]{64}$/, s = /^[a-zA-Z0-9]{25,90}$/, _ = [
|
|
2
|
+
"76a914",
|
|
3
|
+
"a914",
|
|
4
|
+
"0014",
|
|
5
|
+
"0020",
|
|
6
|
+
"5120"
|
|
7
|
+
], A = 1000000n;
|
|
8
|
+
export {
|
|
9
|
+
s as B,
|
|
10
|
+
E as H,
|
|
11
|
+
_ as K,
|
|
12
|
+
A as M,
|
|
13
|
+
a as T
|
|
14
|
+
};
|
|
15
|
+
//# sourceMappingURL=validation-CxqROCno.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validation-CxqROCno.js","sources":["../src/tbv/core/utils/validation.ts"],"sourcesContent":["/**\n * Shared validation constants for Bitcoin-related input sanitization.\n *\n * These are used across mempool API clients, broadcast services, and\n * transaction construction to enforce consistent format checks.\n */\n\n/** Non-empty string of hexadecimal characters (case-insensitive). */\nexport const HEX_RE = /^[0-9a-fA-F]+$/;\n\n/** Bitcoin txid: exactly 64 hex characters (32 bytes). */\nexport const TXID_RE = /^[0-9a-fA-F]{64}$/;\n\n/**\n * Bitcoin address format gate: 25–90 alphanumeric characters.\n * Covers legacy (P2PKH/P2SH), bech32 (P2WPKH/P2WSH), bech32m (P2TR),\n * and regtest addresses (bcrt1... which are 62–64 chars for 32-byte witness programs).\n * Upper bound of 90 provides headroom for future address formats.\n * This is a format gate to prevent path-traversal — not full address validation.\n */\nexport const BITCOIN_ADDRESS_RE = /^[a-zA-Z0-9]{25,90}$/;\n\n/**\n * Known Bitcoin scriptPubKey prefixes:\n * - P2PKH: 76a914...88ac (25 bytes)\n * - P2SH: a914...87 (23 bytes)\n * - P2WPKH: 0014... (22 bytes)\n * - P2WSH: 0020... (34 bytes)\n * - P2TR: 5120... (34 bytes)\n */\nexport const KNOWN_SCRIPT_PREFIXES = [\n \"76a914\",\n \"a914\",\n \"0014\",\n \"0020\",\n \"5120\",\n] as const;\n\n/**\n * Upper bound on the implied miner fee (0.01 BTC = 1,000,000 sats).\n * Catches inflated input values from a compromised mempool API — if inputs are\n * grossly overstated the implied fee becomes unreasonably large. The April 2024\n * Runes spike saw ~450 sat/vB; at 500 vB that's ~225k sats, well under this cap.\n */\nexport const MAX_REASONABLE_FEE_SATS = 1_000_000n;\n"],"names":["HEX_RE","TXID_RE","BITCOIN_ADDRESS_RE","KNOWN_SCRIPT_PREFIXES","MAX_REASONABLE_FEE_SATS"],"mappings":"AAQO,MAAMA,IAAS,kBAGTC,IAAU,qBASVC,IAAqB,wBAUrBC,IAAwB;AAAA,EACnC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,GAQaC,IAA0B;"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";const E=/^[0-9a-fA-F]+$/,_=/^[0-9a-fA-F]{64}$/,R=/^[a-zA-Z0-9]{25,90}$/,S=["76a914","a914","0014","0020","5120"],A=1000000n;exports.BITCOIN_ADDRESS_RE=R;exports.HEX_RE=E;exports.KNOWN_SCRIPT_PREFIXES=S;exports.MAX_REASONABLE_FEE_SATS=A;exports.TXID_RE=_;
|
|
2
|
+
//# sourceMappingURL=validation-u8W7Lp2x.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validation-u8W7Lp2x.cjs","sources":["../src/tbv/core/utils/validation.ts"],"sourcesContent":["/**\n * Shared validation constants for Bitcoin-related input sanitization.\n *\n * These are used across mempool API clients, broadcast services, and\n * transaction construction to enforce consistent format checks.\n */\n\n/** Non-empty string of hexadecimal characters (case-insensitive). */\nexport const HEX_RE = /^[0-9a-fA-F]+$/;\n\n/** Bitcoin txid: exactly 64 hex characters (32 bytes). */\nexport const TXID_RE = /^[0-9a-fA-F]{64}$/;\n\n/**\n * Bitcoin address format gate: 25–90 alphanumeric characters.\n * Covers legacy (P2PKH/P2SH), bech32 (P2WPKH/P2WSH), bech32m (P2TR),\n * and regtest addresses (bcrt1... which are 62–64 chars for 32-byte witness programs).\n * Upper bound of 90 provides headroom for future address formats.\n * This is a format gate to prevent path-traversal — not full address validation.\n */\nexport const BITCOIN_ADDRESS_RE = /^[a-zA-Z0-9]{25,90}$/;\n\n/**\n * Known Bitcoin scriptPubKey prefixes:\n * - P2PKH: 76a914...88ac (25 bytes)\n * - P2SH: a914...87 (23 bytes)\n * - P2WPKH: 0014... (22 bytes)\n * - P2WSH: 0020... (34 bytes)\n * - P2TR: 5120... (34 bytes)\n */\nexport const KNOWN_SCRIPT_PREFIXES = [\n \"76a914\",\n \"a914\",\n \"0014\",\n \"0020\",\n \"5120\",\n] as const;\n\n/**\n * Upper bound on the implied miner fee (0.01 BTC = 1,000,000 sats).\n * Catches inflated input values from a compromised mempool API — if inputs are\n * grossly overstated the implied fee becomes unreasonably large. The April 2024\n * Runes spike saw ~450 sat/vB; at 500 vB that's ~225k sats, well under this cap.\n */\nexport const MAX_REASONABLE_FEE_SATS = 1_000_000n;\n"],"names":["HEX_RE","TXID_RE","BITCOIN_ADDRESS_RE","KNOWN_SCRIPT_PREFIXES","MAX_REASONABLE_FEE_SATS"],"mappings":"aAQO,MAAMA,EAAS,iBAGTC,EAAU,oBASVC,EAAqB,uBAUrBC,EAAwB,CACnC,SACA,OACA,OACA,OACA,MACF,EAQaC,EAA0B"}
|
package/package.json
CHANGED
package/dist/errors-D9EtjJoD.cjs
DELETED
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
"use strict";var Vt=Object.defineProperty;var Ft=(e,t,n)=>t in e?Vt(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n;var P=(e,t,n)=>Ft(e,typeof t!="symbol"?t+"":t,n);const K=require("bitcoinjs-lib"),X=require("buffer"),_=require("viem"),Dt=require("./signing-cl-lowxV.cjs"),ht=require("@babylonlabs-io/babylon-tbv-rust-wasm"),$=require("./challengeAssert-nYlgeAI8.cjs"),I=require("./bitcoin-CNnPFU6Y.cjs"),R=require("./psbtInputFields-05ZrwRzf.cjs"),ft=require("./fundPeginTransaction-DxNOeyNI.cjs"),wt=require("./index-BpXpESWu.cjs"),O=require("./types-B-p4dhEH.cjs"),u=require("./buildAndBroadcastRefund-DWEQvj9T.cjs");function Kt(e){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const n in e)if(n!=="default"){const s=Object.getOwnPropertyDescriptor(e,n);Object.defineProperty(t,n,s.get?s:{enumerable:!0,get:()=>e[n]})}}return t.default=e,Object.freeze(t)}const Mt=Kt(K),S={"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.","0x4fec082d":"Script mismatch: The Bitcoin transaction's taproot output does not match the expected vault script. This may be caused by incorrect vault participants or key configuration.","0x6cc363a5":"Invalid BTC proof of possession: The signature could not be verified. Please ensure you're signing with the correct Bitcoin wallet.","0x6c3f2bf6":"Invalid BTC public key: The Bitcoin public key format is invalid.","0x2c5211c6":"Invalid amount: The deposit amount is invalid or below the minimum required.","0x0405f772":"Application not registered: The application controller is not registered in the system.","0x24e165cc":"Invalid provider status: The vault provider is not in a valid state to accept deposits.","0xd92e233d":"Zero address: One of the required addresses is the zero address.","0x65aa7007":"BTC key mismatch: The Bitcoin public key does not match the expected key.","0x82b42900":"Unauthorized: You must be the depositor or vault provider to submit this transaction.","0x8baa579f":"Invalid signature: The BTC proof of possession signature could not be verified.","0x2f9d01e9":"Invalid BTC transaction: The Bitcoin transaction format is invalid.","0x5a3c6b3e":"Vault provider not registered: The selected vault provider is not registered.","0x979f4518":"Invalid pegin fee: The ETH fee sent does not match the required amount. This may indicate a fee rate change during the transaction."};function M(e){if(!e||typeof e!="object")return;const t=e;if(typeof t.data=="string"&&t.data.startsWith("0x"))return t.data;if(typeof t.details=="string"&&t.details.startsWith("0x"))return t.details;let n=t.cause,s=0;const o=5;for(;n&&typeof n=="object"&&s<o;){const a=n;if(typeof a.data=="string"&&a.data.startsWith("0x"))return a.data;n=a.cause,s++}const i=(typeof t.message=="string"?t.message:"").match(/\b(0x[a-fA-F0-9]{8})\b/);if(i)return i[1]}function Nt(e){const t=M(e);if(t){const n=t.substring(0,10);return S[t]??S[n]}}function qt(e){const t=M(e);if(t===void 0)return!1;const n=t.substring(0,10);return t in S||n in S}function B(e){console.error("[Contract Error] Raw error:",e);const t=M(e);if(console.error("[Contract Error] Extracted error data:",t),t){const s=t.substring(0,10),o=S[t]??S[s];if(o)throw console.error("[Contract Error] Known error:",o),new Error(o)}const n=(e==null?void 0:e.message)||"";if(n.includes("gas limit too high")||n.includes("21000000")||n.includes("Internal JSON-RPC error")){const s=t?` (error code: ${t})`:"";throw console.error("[Contract Error] Transaction rejected. Error code:",t,"Message:",n),new Error(`Transaction failed: The contract rejected this transaction${s}. Possible causes: (1) Vault already exists for this transaction, (2) Invalid signature, (3) Unauthorized caller. Please check your transaction parameters and try again.`)}throw e instanceof Error?(console.error("[Contract Error] Unhandled error:",e.message),e):new Error(`Contract call failed: ${String(e)}`)}const jt=0;function Xt(e,t,n,s){const o=n==null?void 0:n[`${e}:${t}`];return o?Promise.resolve({txid:e,vout:t,value:o.value,scriptPubKey:o.scriptPubKey}):wt.getUtxoInfo(e,t,s)}const dt=12e4;class zt{constructor(t){P(this,"config");this.config=t}async preparePegin(t){const n=await this.config.btcWallet.getPublicKeyHex(),s=n.length===66?n.slice(2):n,o=I.stripHexPrefix(t.vaultProviderBtcPubkey),r=t.vaultKeeperBtcPubkeys.map(I.stripHexPrefix),i=t.universalChallengerBtcPubkeys.map(I.stripHexPrefix);if(t.hashlocks.length!==t.amounts.length)throw new Error(`hashlocks.length (${t.hashlocks.length}) must equal amounts.length (${t.amounts.length})`);if(t.hashlocks.length===0)throw new Error("hashlocks must contain at least one entry");const a=r.length,g={depositorPubkey:s,vaultProviderPubkey:o,vaultKeeperPubkeys:r,universalChallengerPubkeys:i,hashlocks:t.hashlocks,timelockRefund:t.timelockRefund,pegInAmounts:t.amounts,feeRate:t.protocolFeeRate,numLocalChallengers:a,councilQuorum:t.councilQuorum,councilSize:t.councilSize,network:this.config.btcNetwork},f=await $.buildPrePeginPsbt(g),h=R.selectUtxosForPegin([...t.availableUTXOs],f.totalOutputValue,t.mempoolFeeRate,ft.peginOutputCount(f.htlcValues.length)),x=I.getNetwork(this.config.btcNetwork),l=ft.fundPeginTransaction({unfundedTxHex:f.psbtHex,selectedUTXOs:h.selectedUTXOs,changeAddress:t.changeAddress,changeAmount:h.changeAmount,network:x}),y=I.stripHexPrefix(R.calculateBtcTxHash(l)),m=[],b=[],k=[];for(let p=0;p<t.hashlocks.length;p++){const w=await $.buildPeginTxFromFundedPrePegin({prePeginParams:g,timelockPegin:t.timelockPegin,fundedPrePeginTxHex:l,htlcVout:p}),v=await $.buildPeginInputPsbt({peginTxHex:w.txHex,fundedPrePeginTxHex:l,depositorPubkey:s,vaultProviderPubkey:o,vaultKeeperPubkeys:r,universalChallengerPubkeys:i,hashlock:t.hashlocks[p],timelockRefund:t.timelockRefund,network:this.config.btcNetwork});m.push(w),b.push(v.psbtHex),k.push(Dt.createTaprootScriptPathSignOptions(n,1))}const d=await this.signPsbtsWithFallback(b,k),c=[];for(let p=0;p<d.length;p++){const w=$.extractPeginInputSignature(d[p],s),v=$.finalizePeginInputPsbt(d[p]);c.push({htlcVout:p,htlcValue:f.htlcValues[p],peginTxHex:v,peginTxid:m[p].txid,peginInputSignature:w,vaultScriptPubKey:m[p].vaultScriptPubKey})}return{fundedPrePeginTxHex:l,prePeginTxid:y,unsignedPrePeginTxHex:f.psbtHex,perVault:c,selectedUTXOs:h.selectedUTXOs,fee:h.fee,changeAmount:h.changeAmount}}async signPsbtsWithFallback(t,n){if(typeof this.config.btcWallet.signPsbts=="function"){const o=await this.config.btcWallet.signPsbts(t,n);if(o.length!==t.length)throw new Error(`Expected ${t.length} signed PSBTs but received ${o.length}`);return o}const s=[];for(let o=0;o<t.length;o++){const r=await this.config.btcWallet.signPsbt(t[o],n[o]);s.push(r)}return s}async signAndBroadcast(t){const{fundedPrePeginTxHex:n,depositorBtcPubkey:s}=t,o=n.startsWith("0x")?n.slice(2):n,r=K.Transaction.fromHex(o);if(r.ins.length===0)throw new Error("Transaction has no inputs");const i=new K.Psbt;i.setVersion(r.version),i.setLocktime(r.locktime);const a=s.startsWith("0x")?s.slice(2):s;if(a.length!==64||!/^[0-9a-fA-F]+$/.test(a))throw new Error("Invalid depositorBtcPubkey: expected 64 hex characters (x-only pubkey)");const g=X.Buffer.from(a,"hex");if(g.length!==32)throw new Error(`Invalid depositorBtcPubkey length: expected 32 bytes, got ${g.length}`);const f=this.config.mempoolApiUrl,h=r.ins.map(c=>{const p=X.Buffer.from(c.hash).reverse().toString("hex"),w=c.index;return Xt(p,w,t.localPrevouts,f).then(v=>({input:c,utxoData:v,txid:p,vout:w}))}),x=await Promise.all(h),l=x.reduce((c,p)=>c+BigInt(p.utxoData.value),0n),y=r.outs.reduce((c,p)=>c+BigInt(p.value),0n);if(l<y)throw new Error(`UTXO value mismatch: total input value (${l} sat) is less than total output value (${y} sat). This may indicate the mempool API returned manipulated UTXO data.`);for(const{input:c,utxoData:p,txid:w,vout:v}of x){const T=R.getPsbtInputFields({value:p.value,scriptPubKey:p.scriptPubKey},g);i.addInput({hash:c.hash,index:c.index,sequence:c.sequence,...T})}for(const c of r.outs)i.addOutput({script:c.script,value:c.value});const m=await this.config.btcWallet.signPsbt(i.toHex()),b=K.Psbt.fromHex(m);try{b.finalizeAllInputs()}catch(c){if(!b.data.inputs.every(w=>w.finalScriptWitness||w.finalScriptSig))throw new Error(`PSBT finalization failed and wallet did not auto-finalize: ${c}`)}const k=b.extractTransaction().toHex();return await wt.pushTx(k,f)}async registerPeginOnChain(t){const{depositorBtcPubkey:n,unsignedPrePeginTx:s,depositorSignedPeginTx:o,vaultProvider:r,hashlock:i,htlcVout:a,onPopSigned:g,depositorPayoutBtcAddress:f,depositorWotsPkHash:h,preSignedBtcPopSignature:x}=t;if(!this.config.ethWallet.account)throw new Error("Ethereum wallet account not found");const l=this.config.ethWallet.account.address,y=await this.resolvePopSignature(l,x);g&&await g();const m=I.ensureHexPrefix(n),b=I.ensureHexPrefix(s),k=I.ensureHexPrefix(o),d=await this.resolvePayoutScriptPubKey(f),c=R.calculateBtcTxHash(k),p=await ht.deriveVaultId(I.stripHexPrefix(c),I.stripHexPrefix(l)),w=I.ensureHexPrefix(p);if(await this.checkVaultExists(w))throw new Error(`Vault already exists (ID: ${w}, peginTxHash: ${c}). 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.`);const T=_.createPublicClient({chain:this.config.ethChain,transport:_.http()});let E;try{E=await T.readContract({address:this.config.vaultContracts.btcVaultRegistry,abi:O.BTCVaultRegistryABI,functionName:"getPegInFee",args:[r]})}catch{throw new Error("Failed to query pegin fee from the contract. Please check your network connection and that the contract address is correct.")}const C=_.encodeFunctionData({abi:O.BTCVaultRegistryABI,functionName:"submitPeginRequest",args:[l,m,y,b,k,r,i,a,d,h]});let A;try{A=await T.estimateGas({to:this.config.vaultContracts.btcVaultRegistry,data:C,value:E,account:this.config.ethWallet.account.address})}catch(j){B(j)}let q;try{q=await this.config.ethWallet.sendTransaction({to:this.config.vaultContracts.btcVaultRegistry,data:C,value:E,account:this.config.ethWallet.account,chain:this.config.ethChain,gas:A})}catch(j){B(j)}const ut=await T.waitForTransactionReceipt({hash:q,timeout:dt});return ut.status==="reverted"&&B(new Error(`Transaction reverted. Hash: ${q}. Check the transaction on block explorer for details.`)),{ethTxHash:ut.transactionHash,vaultId:w,peginTxHash:c,btcPopSignature:y}}async registerPeginBatchOnChain(t){const{vaultProvider:n,requests:s,preSignedBtcPopSignature:o,onPopSigned:r}=t;if(s.length===0)throw new Error("Batch pegin requires at least one request");if(!this.config.ethWallet.account)throw new Error("Ethereum wallet account not found");const i=this.config.ethWallet.account.address,a=await this.resolvePopSignature(i,o);r&&await r();const g=[];for(const c of s)g.push(await this.resolvePayoutScriptPubKey(c.depositorPayoutBtcAddress));const f=[];for(const c of s){const p=I.ensureHexPrefix(c.depositorSignedPeginTx),w=R.calculateBtcTxHash(p),v=await ht.deriveVaultId(I.stripHexPrefix(w),I.stripHexPrefix(i)),T=I.ensureHexPrefix(v);if(await this.checkVaultExists(T))throw new Error(`Vault already exists (ID: ${T}, peginTxHash: ${w}). To create a new vault, use different UTXOs or a different amount.`);f.push({vaultId:T,peginTxHash:w})}const h=_.createPublicClient({chain:this.config.ethChain,transport:_.http()});let x;try{x=await h.readContract({address:this.config.vaultContracts.btcVaultRegistry,abi:O.BTCVaultRegistryABI,functionName:"getPegInFee",args:[n]})}catch{throw new Error("Failed to query pegin fee from the contract. Please check your network connection and that the contract address is correct.")}const l=x*BigInt(s.length),y=s.map((c,p)=>({depositorBtcPubKey:I.ensureHexPrefix(c.depositorBtcPubkey),btcPopSignature:a,unsignedPrePeginTx:I.ensureHexPrefix(c.unsignedPrePeginTx),depositorSignedPeginTx:I.ensureHexPrefix(c.depositorSignedPeginTx),hashlock:c.hashlock,htlcVout:c.htlcVout,referralCode:jt,depositorPayoutBtcAddress:g[p],depositorWotsPkHash:c.depositorWotsPkHash})),m=_.encodeFunctionData({abi:O.BTCVaultRegistryABI,functionName:"submitPeginRequestBatch",args:[i,n,y]});let b;try{b=await h.estimateGas({to:this.config.vaultContracts.btcVaultRegistry,data:m,value:l,account:this.config.ethWallet.account.address})}catch(c){B(c)}let k;try{k=await this.config.ethWallet.sendTransaction({to:this.config.vaultContracts.btcVaultRegistry,data:m,value:l,account:this.config.ethWallet.account,chain:this.config.ethChain,gas:b})}catch(c){B(c)}const d=await h.waitForTransactionReceipt({hash:k,timeout:dt});return d.status==="reverted"&&B(new Error(`Batch transaction reverted. Hash: ${k}. Check the transaction on block explorer for details.`)),{ethTxHash:d.transactionHash,vaults:f,btcPopSignature:a}}async checkVaultExists(t){try{return(await _.createPublicClient({chain:this.config.ethChain,transport:_.http()}).readContract({address:this.config.vaultContracts.btcVaultRegistry,abi:O.BTCVaultRegistryABI,functionName:"getBtcVaultBasicInfo",args:[t]}))[0]!==_.zeroAddress}catch{return!1}}async resolvePayoutScriptPubKey(t){let n;if(t)n=t;else{n=await this.config.btcWallet.getAddress();const o=await this.config.btcWallet.getPublicKeyHex();if(!I.isAddressFromPublicKey(n,o,this.config.btcNetwork))throw new Error("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).")}const s=I.getNetwork(this.config.btcNetwork);try{return`0x${Mt.address.toOutputScript(n,s).toString("hex")}`}catch{throw new Error(`Invalid BTC payout address: "${n}". Please provide a valid Bitcoin address for the ${this.config.btcNetwork} network.`)}}async resolvePopSignature(t,n){if(n)return n;const s=this.config.vaultContracts.btcVaultRegistry,o=`${t.toLowerCase()}:${this.config.ethChain.id}:pegin:${s.toLowerCase()}`,r=await this.config.btcWallet.signMessage(o,"bip322-simple");return r.startsWith("0x")?r:`0x${X.Buffer.from(r,"base64").toString("hex")}`}getNetwork(){return this.config.btcNetwork}getVaultContractAddress(){return this.config.vaultContracts.btcVaultRegistry}}class Pt{constructor(t,n){P(this,"oHash");P(this,"iHash");P(this,"blockLen");P(this,"outputLen");P(this,"finished",!1);P(this,"destroyed",!1);if(u.ahash(t),u.abytes(n,void 0,"key"),this.iHash=t.create(),typeof this.iHash.update!="function")throw new Error("Expected instance of class which extends utils.Hash");this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;const s=this.blockLen,o=new Uint8Array(s);o.set(n.length>s?t.create().update(n).digest():n);for(let r=0;r<o.length;r++)o[r]^=54;this.iHash.update(o),this.oHash=t.create();for(let r=0;r<o.length;r++)o[r]^=106;this.oHash.update(o),u.clean(o)}update(t){return u.aexists(this),this.iHash.update(t),this}digestInto(t){u.aexists(this),u.abytes(t,this.outputLen,"output"),this.finished=!0,this.iHash.digestInto(t),this.oHash.update(t),this.oHash.digestInto(t),this.destroy()}digest(){const t=new Uint8Array(this.oHash.outputLen);return this.digestInto(t),t}_cloneInto(t){t||(t=Object.create(Object.getPrototypeOf(this),{}));const{oHash:n,iHash:s,finished:o,destroyed:r,blockLen:i,outputLen:a}=this;return t=t,t.finished=o,t.destroyed=r,t.blockLen=i,t.outputLen=a,t.oHash=n._cloneInto(t.oHash),t.iHash=s._cloneInto(t.iHash),t}clone(){return this._cloneInto()}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}}const N=(e,t,n)=>new Pt(e,t).update(n).digest();N.create=(e,t)=>new Pt(e,t);const Gt=Uint8Array.from([7,4,13,1,10,6,15,3,12,0,9,5,2,14,11,8]),kt=Uint8Array.from(new Array(16).fill(0).map((e,t)=>t)),Zt=kt.map(e=>(9*e+5)%16),Tt=(()=>{const n=[[kt],[Zt]];for(let s=0;s<4;s++)for(let o of n)o.push(o[s].map(r=>Gt[r]));return n})(),It=Tt[0],vt=Tt[1],Ht=[[11,14,15,12,5,8,7,9,11,13,14,15,6,7,9,8],[12,13,11,15,6,9,9,7,12,15,11,13,7,8,7,7],[13,15,14,11,7,7,6,8,13,14,13,12,5,5,6,9],[14,11,12,14,8,6,5,5,15,12,15,14,9,9,8,6],[15,12,13,13,9,5,8,6,14,11,12,11,8,6,5,5]].map(e=>Uint8Array.from(e)),Yt=It.map((e,t)=>e.map(n=>Ht[t][n])),Jt=vt.map((e,t)=>e.map(n=>Ht[t][n])),Qt=Uint32Array.from([0,1518500249,1859775393,2400959708,2840853838]),te=Uint32Array.from([1352829926,1548603684,1836072691,2053994217,0]);function gt(e,t,n,s){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)}const W=new Uint32Array(16);class ee extends u.HashMD{constructor(){super(64,20,8,!0);P(this,"h0",1732584193);P(this,"h1",-271733879);P(this,"h2",-1732584194);P(this,"h3",271733878);P(this,"h4",-1009589776)}get(){const{h0:n,h1:s,h2:o,h3:r,h4:i}=this;return[n,s,o,r,i]}set(n,s,o,r,i){this.h0=n|0,this.h1=s|0,this.h2=o|0,this.h3=r|0,this.h4=i|0}process(n,s){for(let m=0;m<16;m++,s+=4)W[m]=n.getUint32(s,!0);let o=this.h0|0,r=o,i=this.h1|0,a=i,g=this.h2|0,f=g,h=this.h3|0,x=h,l=this.h4|0,y=l;for(let m=0;m<5;m++){const b=4-m,k=Qt[m],d=te[m],c=It[m],p=vt[m],w=Yt[m],v=Jt[m];for(let T=0;T<16;T++){const E=u.rotl(o+gt(m,i,g,h)+W[c[T]]+k,w[T])+l|0;o=l,l=h,h=u.rotl(g,10)|0,g=i,i=E}for(let T=0;T<16;T++){const E=u.rotl(r+gt(b,a,f,x)+W[p[T]]+d,v[T])+y|0;r=y,y=x,x=u.rotl(f,10)|0,f=a,a=E}}this.set(this.h1+g+x|0,this.h2+h+y|0,this.h3+l+r|0,this.h4+o+a|0,this.h0+i+f|0)}roundClean(){u.clean(W)}destroy(){this.destroyed=!0,u.clean(this.buffer),this.set(0,0,0,0,0)}}const Et=u.createHasher(()=>new ee),ne=BigInt(0),U=BigInt(1),se=BigInt(2),oe=BigInt(7),re=BigInt(256),ie=BigInt(113),_t=[],Bt=[],St=[];for(let e=0,t=U,n=1,s=0;e<24;e++){[n,s]=[s,(2*n+3*s)%5],_t.push(2*(5*s+n)),Bt.push((e+1)*(e+2)/2%64);let o=ne;for(let r=0;r<7;r++)t=(t<<U^(t>>oe)*ie)%re,t&se&&(o^=U<<(U<<BigInt(r))-U);St.push(o)}const Ct=u.split(St,!0),ae=Ct[0],ce=Ct[1],pt=(e,t,n)=>n>32?u.rotlBH(e,t,n):u.rotlSH(e,t,n),mt=(e,t,n)=>n>32?u.rotlBL(e,t,n):u.rotlSL(e,t,n);function le(e,t=24){const n=new Uint32Array(10);for(let s=24-t;s<24;s++){for(let i=0;i<10;i++)n[i]=e[i]^e[i+10]^e[i+20]^e[i+30]^e[i+40];for(let i=0;i<10;i+=2){const a=(i+8)%10,g=(i+2)%10,f=n[g],h=n[g+1],x=pt(f,h,1)^n[a],l=mt(f,h,1)^n[a+1];for(let y=0;y<50;y+=10)e[i+y]^=x,e[i+y+1]^=l}let o=e[2],r=e[3];for(let i=0;i<24;i++){const a=Bt[i],g=pt(o,r,a),f=mt(o,r,a),h=_t[i];o=e[h],r=e[h+1],e[h]=g,e[h+1]=f}for(let i=0;i<50;i+=10){for(let a=0;a<10;a++)n[a]=e[i+a];for(let a=0;a<10;a++)e[i+a]^=~n[(a+2)%10]&n[(a+4)%10]}e[0]^=ae[s],e[1]^=ce[s]}u.clean(n)}class ct{constructor(t,n,s,o=!1,r=24){P(this,"state");P(this,"pos",0);P(this,"posOut",0);P(this,"finished",!1);P(this,"state32");P(this,"destroyed",!1);P(this,"blockLen");P(this,"suffix");P(this,"outputLen");P(this,"enableXOF",!1);P(this,"rounds");if(this.blockLen=t,this.suffix=n,this.outputLen=s,this.enableXOF=o,this.rounds=r,u.anumber(s,"outputLen"),!(0<t&&t<200))throw new Error("only keccak-f1600 function is supported");this.state=new Uint8Array(200),this.state32=u.u32(this.state)}clone(){return this._cloneInto()}keccak(){u.swap32IfBE(this.state32),le(this.state32,this.rounds),u.swap32IfBE(this.state32),this.posOut=0,this.pos=0}update(t){u.aexists(this),u.abytes(t);const{blockLen:n,state:s}=this,o=t.length;for(let r=0;r<o;){const i=Math.min(n-this.pos,o-r);for(let a=0;a<i;a++)s[this.pos++]^=t[r++];this.pos===n&&this.keccak()}return this}finish(){if(this.finished)return;this.finished=!0;const{state:t,suffix:n,pos:s,blockLen:o}=this;t[s]^=n,(n&128)!==0&&s===o-1&&this.keccak(),t[o-1]^=128,this.keccak()}writeInto(t){u.aexists(this,!1),u.abytes(t),this.finish();const n=this.state,{blockLen:s}=this;for(let o=0,r=t.length;o<r;){this.posOut>=s&&this.keccak();const i=Math.min(s-this.posOut,r-o);t.set(n.subarray(this.posOut,this.posOut+i),o),this.posOut+=i,o+=i}return t}xofInto(t){if(!this.enableXOF)throw new Error("XOF is not possible for this instance");return this.writeInto(t)}xof(t){return u.anumber(t),this.xofInto(new Uint8Array(t))}digestInto(t){if(u.aoutput(t,this),this.finished)throw new Error("digest() was already called");return this.writeInto(t),this.destroy(),t}digest(){return this.digestInto(new Uint8Array(this.outputLen))}destroy(){this.destroyed=!0,u.clean(this.state)}_cloneInto(t){const{blockLen:n,suffix:s,outputLen:o,rounds:r,enableXOF:i}=this;return t||(t=new ct(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}}const ue=(e,t,n,s={})=>u.createHasher(()=>new ct(t,e,n),s),At=ue(1,136,32);function he(e,t,n,s){u.ahash(e);const o=u.checkOpts({dkLen:32,asyncTick:10},s),{c:r,dkLen:i,asyncTick:a}=o;if(u.anumber(r,"c"),u.anumber(i,"dkLen"),u.anumber(a,"asyncTick"),r<1)throw new Error("iterations (c) must be >= 1");const g=u.kdfInputToBytes(t,"password"),f=u.kdfInputToBytes(n,"salt"),h=new Uint8Array(i),x=N.create(e,g),l=x._cloneInto().update(f);return{c:r,dkLen:i,asyncTick:a,DK:h,PRF:x,PRFSalt:l}}function fe(e,t,n,s,o){return e.destroy(),t.destroy(),s&&s.destroy(),u.clean(o),n}function de(e,t,n,s){const{c:o,dkLen:r,DK:i,PRF:a,PRFSalt:g}=he(e,t,n,s);let f;const h=new Uint8Array(4),x=u.createView(h),l=new Uint8Array(a.outputLen);for(let y=1,m=0;m<r;y++,m+=a.outputLen){const b=i.subarray(m,m+a.outputLen);x.setInt32(0,y,!1),(f=g._cloneInto(f)).update(h).digestInto(l),b.set(l.subarray(0,b.length));for(let k=1;k<o;k++){a._cloneInto(f).update(l).digestInto(l);for(let d=0;d<b.length;d++)b[d]^=l[d]}}return fe(a,g,i,f,l)}function $t(e){if(typeof e!="string")throw new TypeError("invalid mnemonic type: "+typeof e);return e.normalize("NFKD")}function ge(e){const t=$t(e),n=t.split(" ");if(![12,15,18,21,24].includes(n.length))throw new Error("Invalid mnemonic");return{nfkd:t,words:n}}const pe=e=>$t("mnemonic"+e);function me(e,t=""){return de(u.sha512,ge(e).nfkd,pe(t),{c:2048,dkLen:64})}const xe=508,xt=16,V=32,F=64,yt=5,ye=4;function L(...e){const t=e.reduce((o,r)=>o+r.length,0),n=new Uint8Array(t);let s=0;for(const o of e)n.set(o,s),s+=o.length;return n}function z(e){return new TextEncoder().encode(e)}function G(e){const t=new Uint8Array(ye);return new DataView(t.buffer).setUint32(0,e.length,!1),L(t,e)}function Z(e,t){return N(u.sha512,e,t)}function bt(e){return Et(u.sha256(e))}const rt=e=>Array.from(e).map(t=>t.toString(16).padStart(2,"0")).join("");function Rt(e){const t=me(e),n=new Uint8Array(t);return t.fill(0),n}async function Ot(e,t,n,s){if(e.length!==F)throw new Error(`WOTS seed must be ${F} bytes, got ${e.length}`);t=I.stripHexPrefix(t),n=I.stripHexPrefix(n);const o=e.slice(V,F),r=e.slice(0,V),i=[o,r];try{const a=L(G(z(t)),G(z(n)),G(z(s))),g=L(r,a);i.push(g);const f=Z(o,g);i.push(f);const h=f.slice(0,V),x=f.slice(V,F);i.push(h,x);const l=[],y=[],m=[],b=[];let k=!1;try{for(let d=0;d<xe;d++){const c=new Uint8Array(yt);c[0]=0,new DataView(c.buffer).setUint32(1,d,!1);const p=new Uint8Array(yt);p[0]=1,new DataView(p.buffer).setUint32(1,d,!1);const w=L(h,c),v=L(h,p),T=Z(x,w),E=Z(x,v);try{const C=T.slice(0,xt),A=E.slice(0,xt);l.push(C),y.push(A),m.push(bt(C)),b.push(bt(A))}finally{w.fill(0),v.fill(0),T.fill(0),E.fill(0)}}return k=!0,{falsePreimages:l,truePreimages:y,falseHashes:m,trueHashes:b}}finally{if(!k){for(const d of l)d.fill(0);for(const d of y)d.fill(0)}}}finally{for(const a of i)a.fill(0)}}function be(e){return{false_list:e.falseHashes.map(rt),true_list:e.trueHashes.map(rt)}}function Ut(e){if(e.falseHashes.length===0||e.trueHashes.length===0)throw new Error("computeWotsPkHash: keypair hash arrays must not be empty");const t=e.falseHashes[0].length,n=(e.falseHashes.length+e.trueHashes.length)*t,s=new Uint8Array(n);let o=0;for(const i of e.falseHashes)s.set(i,o),o+=t;for(const i of e.trueHashes)s.set(i,o),o+=t;const r=At(s);return`0x${rt(r)}`}const Y=32,J=64,we=4,H=20,it=4,Lt=2,Pe=0,ke=1,D=[64,64];function at(...e){const t=e.reduce((o,r)=>o+r.length,0),n=new Uint8Array(t);let s=0;for(const o of e)n.set(o,s),s+=o.length;return n}function Q(e){return new TextEncoder().encode(e)}function tt(e){const t=new Uint8Array(we);return new DataView(t.buffer).setUint32(0,e.length,!1),at(t,e)}function et(e){return e.startsWith("0x")||e.startsWith("0X")?e.slice(2):e}const Te=e=>Array.from(e).map(t=>t.toString(16).padStart(2,"0")).join("");function Ie(e,t){return N(u.sha512,e,t)}function lt(e){return Et(u.sha256(e))}function Wt(e){return(1<<e)-1}function ve(e){let t=1;for(;t*t<e+1;)t++;return Math.max(t,2)}function He(e){const t=it,n=Wt(t),s=e*n;return{d:t,n:e,checksum_radix:ve(s)}}function nt(e,t){const n=[];let s=t;for(;s>0;)n.push(s&255),s>>>=8;const o=new Uint8Array(e.length+n.length);o.set(e);for(let r=0;r<n.length;r++)o[e.length+r]=n[r];return lt(o)}function st(e,t){let n=e;for(let s=0;s<t;s++)n=lt(n);return n}function Ee(e,t){const n=Wt(t.d),s=t.checksum_radix-1,o=Math.floor(t.n*n/t.checksum_radix),r=[];for(let h=0;h<t.n;h++){const x=nt(e,h+Lt),l=st(x,n);r.push(Array.from(l))}const i=nt(e,Pe),a=st(i,s),g=nt(e,ke),f=st(g,o);return{config:t,message_terminals:r,checksum_major_terminal:Array.from(f),checksum_minor_terminal:Array.from(a)}}async function _e(e,t,n,s){if(e.length!==J)throw new Error(`WOTS seed must be exactly ${J} bytes, got ${e.length}`);const o=et(t),r=et(n),i=e.slice(Y,J),a=e.slice(0,Y),g=at(a,at(tt(Q(o)),tt(Q(r)),tt(Q(et(s))))),f=Ie(i,g),h=f.slice(0,Y);try{const x=[];for(let l=0;l<D.length;l++){const y=D[l],m=He(y),b=new Uint8Array(h.length+1);b.set(h),b[h.length]=l;const k=lt(b);try{const d=Ee(k,m);if(d.config.d!==it)throw new Error(`Block ${l}: expected d=${it}, got d=${d.config.d}`);if(d.config.n!==y)throw new Error(`Block ${l}: expected n=${y}, got n=${d.config.n}`);if(d.message_terminals.length!==y)throw new Error(`Block ${l}: expected ${y} message terminals, got ${d.message_terminals.length}`);for(let c=0;c<d.message_terminals.length;c++)if(d.message_terminals[c].length!==H)throw new Error(`Block ${l} terminal ${c}: expected ${H} bytes, got ${d.message_terminals[c].length}`);if(d.checksum_minor_terminal.length!==H)throw new Error(`Block ${l} checksum_minor: expected ${H} bytes`);if(d.checksum_major_terminal.length!==H)throw new Error(`Block ${l} checksum_major: expected ${H} bytes`);x.push(d)}finally{b.fill(0),k.fill(0)}}if(x.length!==D.length)throw new Error(`Expected ${D.length} blocks, got ${x.length}`);return x}finally{g.fill(0),i.fill(0),a.fill(0),f.fill(0),h.fill(0),e.fill(0)}}function ot(e,t,n){if(e.length!==H)throw new Error(`Block ${t} ${n}: expected ${H} bytes, got ${e.length}`);for(let s=0;s<e.length;s++){const o=e[s];if(!Number.isInteger(o)||o<0||o>255)throw new Error(`Block ${t} ${n}[${s}]: invalid byte value ${o}`)}}function Be(e){if(e.length===0)throw new Error("Public keys array must not be empty");for(let r=0;r<e.length;r++){const i=e[r];ot(i.checksum_minor_terminal,r,"checksum_minor_terminal"),ot(i.checksum_major_terminal,r,"checksum_major_terminal");for(let a=0;a<i.message_terminals.length;a++)ot(i.message_terminals[a],r,`message_terminal[${a}]`)}let t=0;for(const r of e)t+=Lt+r.message_terminals.length;const n=new Uint8Array(t*H);let s=0;for(const r of e){n.set(r.checksum_minor_terminal,s),s+=H,n.set(r.checksum_major_terminal,s),s+=H;for(const i of r.message_terminals)n.set(i,s),s+=H}const o=At(n);return`0x${Te(o)}`}async function Se(e,t,n,s){const o=Rt(e);try{const r=await Ot(o,t,n,s);try{return Ut(r)}finally{for(const i of r.falsePreimages)i.fill(0);for(const i of r.truePreimages)i.fill(0)}}finally{o.fill(0)}}function Ce(e){const t=(e instanceof Error?e.message:typeof e=="string"?e:"").toLowerCase();return t.includes("wots")&&t.includes("hash")&&t.includes("does not match")}exports.CONTRACT_ERRORS=S;exports.PeginManager=zt;exports.computeWotsBlockPublicKeysHash=Be;exports.computeWotsPkHash=Ut;exports.deriveWotsBlockPublicKeys=_e;exports.deriveWotsKeypair=Ot;exports.deriveWotsPkHash=Se;exports.extractErrorData=M;exports.getContractErrorMessage=Nt;exports.handleContractError=B;exports.isKnownContractError=qt;exports.isWotsMismatchError=Ce;exports.keypairToPublicKey=be;exports.mnemonicToWotsSeed=Rt;
|
|
2
|
-
//# sourceMappingURL=errors-D9EtjJoD.cjs.map
|