@babylonlabs-io/ts-sdk 0.33.2 → 0.33.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{PeginManager-BtXhdqkm.js → PeginManager-C-L3huRO.js} +330 -334
- package/dist/PeginManager-C-L3huRO.js.map +1 -0
- package/dist/{PeginManager-ztgWQqza.cjs → PeginManager-DmPmzPHz.cjs} +2 -2
- package/dist/PeginManager-DmPmzPHz.cjs.map +1 -0
- package/dist/{bitcoin-0_T6KJON.js → bitcoin-B0S8SHCX.js} +24 -20
- package/dist/bitcoin-B0S8SHCX.js.map +1 -0
- package/dist/bitcoin-B3aqjuMP.cjs +2 -0
- package/dist/bitcoin-B3aqjuMP.cjs.map +1 -0
- package/dist/{buildAndBroadcastRefund-Ci_pVTNu.js → buildAndBroadcastRefund-Dx09Zbla.js} +3 -3
- package/dist/buildAndBroadcastRefund-Dx09Zbla.js.map +1 -0
- package/dist/{buildAndBroadcastRefund-DKr9hbDn.cjs → buildAndBroadcastRefund-PmJMNrhO.cjs} +2 -2
- package/dist/buildAndBroadcastRefund-PmJMNrhO.cjs.map +1 -0
- package/dist/{challengeAssert-KGVKQh0J.js → challengeAssert-D3tHnLWb.js} +2 -2
- package/dist/{challengeAssert-KGVKQh0J.js.map → challengeAssert-D3tHnLWb.js.map} +1 -1
- package/dist/{challengeAssert-06GLZtV8.cjs → challengeAssert-Dp9d1bg1.cjs} +2 -2
- package/dist/{challengeAssert-06GLZtV8.cjs.map → challengeAssert-Dp9d1bg1.cjs.map} +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.js +7 -7
- package/dist/{noPayout-BmMd4NNH.js → noPayout-BnsetBKW.js} +2 -2
- package/dist/{noPayout-BmMd4NNH.js.map → noPayout-BnsetBKW.js.map} +1 -1
- package/dist/{noPayout-Bp2TYA_X.cjs → noPayout-DWaCtpMU.cjs} +2 -2
- package/dist/{noPayout-Bp2TYA_X.cjs.map → noPayout-DWaCtpMU.cjs.map} +1 -1
- package/dist/{psbtInputFields-BLi7Ta-T.cjs → psbtInputFields-6sRcZqdb.cjs} +2 -2
- package/dist/{psbtInputFields-BLi7Ta-T.cjs.map → psbtInputFields-6sRcZqdb.cjs.map} +1 -1
- package/dist/{psbtInputFields-DPCFHgGd.js → psbtInputFields-C5QPn1YK.js} +2 -2
- package/dist/{psbtInputFields-DPCFHgGd.js.map → psbtInputFields-C5QPn1YK.js.map} +1 -1
- package/dist/tbv/core/clients/index.cjs +1 -1
- package/dist/tbv/core/clients/index.js +1 -1
- package/dist/tbv/core/index.cjs +1 -1
- package/dist/tbv/core/index.js +7 -7
- package/dist/tbv/core/managers/PayoutManager.d.ts +8 -4
- package/dist/tbv/core/managers/PayoutManager.d.ts.map +1 -1
- package/dist/tbv/core/managers/PeginManager.d.ts +15 -1
- package/dist/tbv/core/managers/PeginManager.d.ts.map +1 -1
- package/dist/tbv/core/primitives/index.cjs +1 -1
- package/dist/tbv/core/primitives/index.js +3 -3
- package/dist/tbv/core/primitives/utils/bitcoin.d.ts +6 -4
- package/dist/tbv/core/primitives/utils/bitcoin.d.ts.map +1 -1
- package/dist/tbv/core/services/index.cjs +1 -1
- package/dist/tbv/core/services/index.js +1 -1
- package/dist/tbv/core/utils/index.cjs +1 -1
- package/dist/tbv/core/utils/index.js +2 -2
- package/dist/tbv/index.cjs +1 -1
- package/dist/tbv/index.js +7 -7
- package/dist/testing/index.cjs +1 -1
- package/dist/testing/index.js +1 -1
- package/dist/{vault-registry-reader-CmDdymw4.cjs → vault-registry-reader-CKe9TbX6.cjs} +2 -2
- package/dist/{vault-registry-reader-CmDdymw4.cjs.map → vault-registry-reader-CKe9TbX6.cjs.map} +1 -1
- package/dist/{vault-registry-reader-eiBfG4uQ.js → vault-registry-reader-CWGbw_wZ.js} +2 -2
- package/dist/{vault-registry-reader-eiBfG4uQ.js.map → vault-registry-reader-CWGbw_wZ.js.map} +1 -1
- package/package.json +1 -1
- package/dist/PeginManager-BtXhdqkm.js.map +0 -1
- package/dist/PeginManager-ztgWQqza.cjs.map +0 -1
- package/dist/bitcoin-0_T6KJON.js.map +0 -1
- package/dist/bitcoin-EYBKDtEW.cjs +0 -2
- package/dist/bitcoin-EYBKDtEW.cjs.map +0 -1
- package/dist/buildAndBroadcastRefund-Ci_pVTNu.js.map +0 -1
- package/dist/buildAndBroadcastRefund-DKr9hbDn.cjs.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bitcoin.d.ts","sourceRoot":"","sources":["../../../../../src/tbv/core/primitives/utils/bitcoin.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChC,OAAO,EAAE,QAAQ,EAAY,MAAM,eAAe,CAAC;AAEnD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,uCAAuC,CAAC;AACrE,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,MAAM,CAAC;AAEhC;;;;GAIG;AACH,eAAO,MAAM,sBAAsB,MAAO,CAAC;AAE3C;;;GAGG;AACH,eAAO,MAAM,qBAAqB,KAAK,CAAC;AAExC;;;GAGG;AACH,eAAO,MAAM,yBAAyB,KAAK,CAAC;AAE5C;;;GAGG;AACH,eAAO,MAAM,2BAA2B,MAAM,CAAC;AAE/C;;GAEG;AACH,eAAO,MAAM,mBAAmB,MAAM,CAAC;AAEvC;;;;;;;;GAQG;AACH,wBAAgB,cAAc,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAElD;AAED;;;;;;;;GAQG;AACH,wBAAgB,eAAe,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAIhD;AAED;;;;;;GAMG;AACH,wBAAgB,eAAe,CAAC,GAAG,EAAE,MAAM,GAAG,UAAU,CAUvD;AAED;;;;;GAKG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,UAAU,GAAG,MAAM,CAIzD;AAED;;;;;;;;GAQG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE;IAClC,IAAI,EAAE,MAAM,GAAG,UAAU,CAAC;CAC3B,GAAG,MAAM,CAET;AAED;;;;;;;;GAQG;AACH,wBAAgB,OAAO,CAAC,MAAM,EAAE,UAAU,GAAG,UAAU,CAEtD;AAaD;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,uBAAuB,CAAC,YAAY,EAAE,MAAM,GAAG,MAAM,CA0BpE;AAED;;;;;;;;GAQG;AACH,wBAAgB,UAAU,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAG/C;AAED;;GAEG;AACH,MAAM,WAAW,4BAA4B;IAC3C,yEAAyE;IACzE,eAAe,EAAE,MAAM,CAAC;IACxB,oEAAoE;IACpE,iBAAiB,EAAE,MAAM,CAAC;IAC1B,yDAAyD;IACzD,eAAe,EAAE,MAAM,CAAC;CACzB;AAED
|
|
1
|
+
{"version":3,"file":"bitcoin.d.ts","sourceRoot":"","sources":["../../../../../src/tbv/core/primitives/utils/bitcoin.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChC,OAAO,EAAE,QAAQ,EAAY,MAAM,eAAe,CAAC;AAEnD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,uCAAuC,CAAC;AACrE,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,MAAM,CAAC;AAEhC;;;;GAIG;AACH,eAAO,MAAM,sBAAsB,MAAO,CAAC;AAE3C;;;GAGG;AACH,eAAO,MAAM,qBAAqB,KAAK,CAAC;AAExC;;;GAGG;AACH,eAAO,MAAM,yBAAyB,KAAK,CAAC;AAE5C;;;GAGG;AACH,eAAO,MAAM,2BAA2B,MAAM,CAAC;AAE/C;;GAEG;AACH,eAAO,MAAM,mBAAmB,MAAM,CAAC;AAEvC;;;;;;;;GAQG;AACH,wBAAgB,cAAc,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAElD;AAED;;;;;;;;GAQG;AACH,wBAAgB,eAAe,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAIhD;AAED;;;;;;GAMG;AACH,wBAAgB,eAAe,CAAC,GAAG,EAAE,MAAM,GAAG,UAAU,CAUvD;AAED;;;;;GAKG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,UAAU,GAAG,MAAM,CAIzD;AAED;;;;;;;;GAQG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE;IAClC,IAAI,EAAE,MAAM,GAAG,UAAU,CAAC;CAC3B,GAAG,MAAM,CAET;AAED;;;;;;;;GAQG;AACH,wBAAgB,OAAO,CAAC,MAAM,EAAE,UAAU,GAAG,UAAU,CAEtD;AAaD;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,uBAAuB,CAAC,YAAY,EAAE,MAAM,GAAG,MAAM,CA0BpE;AAED;;;;;;;;GAQG;AACH,wBAAgB,UAAU,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAG/C;AAED;;GAEG;AACH,MAAM,WAAW,4BAA4B;IAC3C,yEAAyE;IACzE,eAAe,EAAE,MAAM,CAAC;IACxB,oEAAoE;IACpE,iBAAiB,EAAE,MAAM,CAAC;IAC1B,yDAAyD;IACzD,eAAe,EAAE,MAAM,CAAC;CACzB;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,oBAAoB,CAClC,eAAe,EAAE,MAAM,EACvB,uBAAuB,EAAE,MAAM,GAC9B,4BAA4B,CAmB9B;AAQD;;GAEG;AACH,wBAAgB,mBAAmB,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAS5D;AA8BD;;;;;GAKG;AACH,wBAAgB,UAAU,CAAC,OAAO,EAAE,OAAO,GAAG,QAAQ,CAAC,OAAO,CAY7D;AAED;;;;;;GAMG;AACH,wBAAgB,oBAAoB,CAClC,YAAY,EAAE,MAAM,EACpB,OAAO,EAAE,OAAO,GACf,MAAM,CAWR;AAED;;;;;;;GAOG;AACH,wBAAgB,yBAAyB,CACvC,YAAY,EAAE,MAAM,EACpB,OAAO,EAAE,OAAO,GACf,MAAM,CAiBR;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,sBAAsB,CACpC,OAAO,EAAE,MAAM,EACf,YAAY,EAAE,MAAM,EACpB,OAAO,EAAE,OAAO,GACf,OAAO,CAgCT"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("../../../buildAndBroadcastRefund-
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("../../../buildAndBroadcastRefund-PmJMNrhO.cjs"),e=require("../../../signing-DHSXjhLM.cjs");exports.BIP68NotMatureError=t.BIP68NotMatureError;exports.ClaimerPegoutStatusValue=t.ClaimerPegoutStatusValue;exports.REFUND_VSIZE=t.REFUND_VSIZE;exports.activateVault=t.activateVault;exports.buildAndBroadcastRefund=t.buildAndBroadcastRefund;exports.computeHashlock=t.computeHashlock;exports.estimateRefundFeeSats=t.estimateRefundFeeSats;exports.isDepositAmountValid=t.isDepositAmountValid;exports.isPegoutTerminalStatus=t.isPegoutTerminalStatus;exports.isRecognizedPegoutStatus=t.isRecognizedPegoutStatus;exports.runDepositorPresignFlow=t.runDepositorPresignFlow;exports.signDepositorGraph=t.signDepositorGraph;exports.submitWotsPublicKey=t.submitWotsPublicKey;exports.validateDepositAmount=t.validateDepositAmount;exports.validateMultiVaultDepositInputs=t.validateMultiVaultDepositInputs;exports.validateProviderSelection=t.validateProviderSelection;exports.validateRemainingCapacity=t.validateRemainingCapacity;exports.validateSecretAgainstHashlock=t.validateSecretAgainstHashlock;exports.validateVaultAmounts=t.validateVaultAmounts;exports.validateVaultProviderPubkey=t.validateVaultProviderPubkey;exports.waitForPeginStatus=t.waitForPeginStatus;exports.ContractStatus=e.ContractStatus;exports.PeginAction=e.PeginAction;exports.canPerformAction=e.canPerformAction;exports.getPeginProtocolState=e.getPeginProtocolState;
|
|
2
2
|
//# sourceMappingURL=index.cjs.map
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { B as s, C as e, R as i, a as o, m as r, h as u, n as l, i as n, l as d, k as c, r as P, b as g, s as m, v as p, g as v, d as S, c as A, j as V, e as f, f as D, w as R } from "../../../buildAndBroadcastRefund-
|
|
1
|
+
import { B as s, C as e, R as i, a as o, m as r, h as u, n as l, i as n, l as d, k as c, r as P, b as g, s as m, v as p, g as v, d as S, c as A, j as V, e as f, f as D, w as R } from "../../../buildAndBroadcastRefund-Dx09Zbla.js";
|
|
2
2
|
import { C, P as h, a as k, g as F } from "../../../signing-BZigafm0.js";
|
|
3
3
|
export {
|
|
4
4
|
s as BIP68NotMatureError,
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const _=require("../../../signing-DHSXjhLM.cjs"),T=require("../../../validation-u8W7Lp2x.cjs"),t=require("../../../fundPeginTransaction-DaWoYCgO.cjs"),e=require("../../../psbtInputFields-
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const _=require("../../../signing-DHSXjhLM.cjs"),T=require("../../../validation-u8W7Lp2x.cjs"),t=require("../../../fundPeginTransaction-DaWoYCgO.cjs"),e=require("../../../psbtInputFields-6sRcZqdb.cjs"),E=require("../../../bitcoin-B3aqjuMP.cjs");exports.createTaprootScriptPathSignOptions=_.createTaprootScriptPathSignOptions;exports.BITCOIN_ADDRESS_RE=T.BITCOIN_ADDRESS_RE;exports.HEX_RE=T.HEX_RE;exports.KNOWN_SCRIPT_PREFIXES=T.KNOWN_SCRIPT_PREFIXES;exports.MAX_REASONABLE_FEE_SATS=T.MAX_REASONABLE_FEE_SATS;exports.TXID_RE=T.TXID_RE;exports.BTC_DUST_SAT=t.BTC_DUST_SAT;exports.DUST_THRESHOLD=t.DUST_THRESHOLD;exports.FEE_SAFETY_MARGIN=t.FEE_SAFETY_MARGIN;exports.LOW_RATE_ESTIMATION_ACCURACY_BUFFER=t.LOW_RATE_ESTIMATION_ACCURACY_BUFFER;exports.MAX_NON_LEGACY_OUTPUT_SIZE=t.MAX_NON_LEGACY_OUTPUT_SIZE;exports.P2TR_INPUT_SIZE=t.P2TR_INPUT_SIZE;exports.PEGIN_AUTH_ANCHOR_OUTPUTS=t.PEGIN_AUTH_ANCHOR_OUTPUTS;exports.PEGIN_FIXED_OUTPUTS=t.PEGIN_FIXED_OUTPUTS;exports.SPLIT_TX_FEE_SAFETY_MULTIPLIER=t.SPLIT_TX_FEE_SAFETY_MULTIPLIER;exports.TX_BUFFER_SIZE_OVERHEAD=t.TX_BUFFER_SIZE_OVERHEAD;exports.WALLET_RELAY_FEE_RATE_THRESHOLD=t.WALLET_RELAY_FEE_RATE_THRESHOLD;exports.fundPeginTransaction=t.fundPeginTransaction;exports.parseUnfundedWasmTransaction=t.parseUnfundedWasmTransaction;exports.peginOutputCount=t.peginOutputCount;exports.rateBasedTxBufferFee=t.rateBasedTxBufferFee;exports.BitcoinScriptType=e.BitcoinScriptType;exports.UtxoNotAvailableError=e.UtxoNotAvailableError;exports.assertUtxosAvailable=e.assertUtxosAvailable;exports.calculateBtcTxHash=e.calculateBtcTxHash;exports.collectReservedUtxoRefs=e.collectReservedUtxoRefs;exports.extractInputsFromTransaction=e.extractInputsFromTransaction;exports.getDustThreshold=e.getDustThreshold;exports.getPsbtInputFields=e.getPsbtInputFields;exports.getScriptType=e.getScriptType;exports.selectUtxosForDeposit=e.selectUtxosForDeposit;exports.selectUtxosForPegin=e.selectUtxosForPegin;exports.shouldAddChangeOutput=e.shouldAddChangeOutput;exports.validateUtxosAvailable=e.validateUtxosAvailable;exports.getNetwork=E.getNetwork;
|
|
2
2
|
//# sourceMappingURL=index.cjs.map
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { c as t } from "../../../signing-BZigafm0.js";
|
|
2
2
|
import { B as T, H as _, K as E, M as o, T as r } from "../../../validation-CxqROCno.js";
|
|
3
3
|
import { B as A, D as R, F as U, L as i, M as p, P as I, b as c, a as n, S as F, T as l, W as O, f as P, c as x, p as N, r as u } from "../../../fundPeginTransaction-oV-dNJOU.js";
|
|
4
|
-
import { B as f, U as B, a as D, f as L, c as g, e as C, g as H, i as X, h, s as m, b as M, d as b, v } from "../../../psbtInputFields-
|
|
5
|
-
import { g as Y } from "../../../bitcoin-
|
|
4
|
+
import { B as f, U as B, a as D, f as L, c as g, e as C, g as H, i as X, h, s as m, b as M, d as b, v } from "../../../psbtInputFields-C5QPn1YK.js";
|
|
5
|
+
import { g as Y } from "../../../bitcoin-B0S8SHCX.js";
|
|
6
6
|
export {
|
|
7
7
|
T as BITCOIN_ADDRESS_RE,
|
|
8
8
|
A as BTC_DUST_SAT,
|
package/dist/tbv/index.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=require("../challengeAssert-
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=require("../challengeAssert-Dp9d1bg1.cjs"),P=require("@babylonlabs-io/babylon-tbv-rust-wasm"),u=require("../noPayout-DWaCtpMU.cjs"),i=require("../bitcoin-B3aqjuMP.cjs"),l=require("../signing-DHSXjhLM.cjs"),d=require("../validation-u8W7Lp2x.cjs"),t=require("../buildAndBroadcastRefund-PmJMNrhO.cjs"),a=require("../fundPeginTransaction-DaWoYCgO.cjs"),o=require("../psbtInputFields-6sRcZqdb.cjs"),r=require("../PeginManager-DmPmzPHz.cjs"),e=require("../vault-registry-reader-CKe9TbX6.cjs"),s=require("../types-PthVHz5q.cjs");exports.buildChallengeAssertPsbt=n.buildChallengeAssertPsbt;exports.buildDepositorPayoutPsbt=n.buildDepositorPayoutPsbt;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:()=>P.computeMinClaimValue});Object.defineProperty(exports,"deriveVaultId",{enumerable:!0,get:()=>P.deriveVaultId});exports.assertPayoutOutputMatchesRegistered=u.assertPayoutOutputMatchesRegistered;exports.buildNoPayoutPsbt=u.buildNoPayoutPsbt;exports.buildPayoutPsbt=u.buildPayoutPsbt;exports.buildRefundPsbt=u.buildRefundPsbt;exports.createPayoutScript=u.createPayoutScript;exports.extractPayoutSignature=u.extractPayoutSignature;exports.deriveNativeSegwitAddress=i.deriveNativeSegwitAddress;exports.deriveTaprootAddress=i.deriveTaprootAddress;exports.ensureHexPrefix=i.ensureHexPrefix;exports.formatSatoshisToBtc=i.formatSatoshisToBtc;exports.getNetwork=i.getNetwork;exports.hexToUint8Array=i.hexToUint8Array;exports.isAddressFromPublicKey=i.isAddressFromPublicKey;exports.isValidHex=i.isValidHex;exports.processPublicKeyToXOnly=i.processPublicKeyToXOnly;exports.stripHexPrefix=i.stripHexPrefix;exports.toXOnly=i.toXOnly;exports.uint8ArrayToHex=i.uint8ArrayToHex;exports.validateWalletPubkey=i.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=d.BITCOIN_ADDRESS_RE;exports.HEX_RE=d.HEX_RE;exports.KNOWN_SCRIPT_PREFIXES=d.KNOWN_SCRIPT_PREFIXES;exports.MAX_REASONABLE_FEE_SATS=d.MAX_REASONABLE_FEE_SATS;exports.TXID_RE=d.TXID_RE;exports.BIP68NotMatureError=t.BIP68NotMatureError;exports.ClaimerPegoutStatusValue=t.ClaimerPegoutStatusValue;exports.PayoutManager=t.PayoutManager;exports.REFUND_VSIZE=t.REFUND_VSIZE;exports.activateVault=t.activateVault;exports.buildAndBroadcastRefund=t.buildAndBroadcastRefund;exports.computeHashlock=t.computeHashlock;exports.estimateRefundFeeSats=t.estimateRefundFeeSats;exports.isDepositAmountValid=t.isDepositAmountValid;exports.isPegoutTerminalStatus=t.isPegoutTerminalStatus;exports.isRecognizedPegoutStatus=t.isRecognizedPegoutStatus;exports.runDepositorPresignFlow=t.runDepositorPresignFlow;exports.signDepositorGraph=t.signDepositorGraph;exports.submitWotsPublicKey=t.submitWotsPublicKey;exports.validateDepositAmount=t.validateDepositAmount;exports.validateMultiVaultDepositInputs=t.validateMultiVaultDepositInputs;exports.validateProviderSelection=t.validateProviderSelection;exports.validateRemainingCapacity=t.validateRemainingCapacity;exports.validateSecretAgainstHashlock=t.validateSecretAgainstHashlock;exports.validateVaultAmounts=t.validateVaultAmounts;exports.validateVaultProviderPubkey=t.validateVaultProviderPubkey;exports.waitForPeginStatus=t.waitForPeginStatus;exports.BTC_DUST_SAT=a.BTC_DUST_SAT;exports.DUST_THRESHOLD=a.DUST_THRESHOLD;exports.FEE_SAFETY_MARGIN=a.FEE_SAFETY_MARGIN;exports.LOW_RATE_ESTIMATION_ACCURACY_BUFFER=a.LOW_RATE_ESTIMATION_ACCURACY_BUFFER;exports.MAX_NON_LEGACY_OUTPUT_SIZE=a.MAX_NON_LEGACY_OUTPUT_SIZE;exports.P2TR_INPUT_SIZE=a.P2TR_INPUT_SIZE;exports.PEGIN_AUTH_ANCHOR_OUTPUTS=a.PEGIN_AUTH_ANCHOR_OUTPUTS;exports.PEGIN_FIXED_OUTPUTS=a.PEGIN_FIXED_OUTPUTS;exports.SPLIT_TX_FEE_SAFETY_MULTIPLIER=a.SPLIT_TX_FEE_SAFETY_MULTIPLIER;exports.TX_BUFFER_SIZE_OVERHEAD=a.TX_BUFFER_SIZE_OVERHEAD;exports.WALLET_RELAY_FEE_RATE_THRESHOLD=a.WALLET_RELAY_FEE_RATE_THRESHOLD;exports.fundPeginTransaction=a.fundPeginTransaction;exports.parseUnfundedWasmTransaction=a.parseUnfundedWasmTransaction;exports.peginOutputCount=a.peginOutputCount;exports.rateBasedTxBufferFee=a.rateBasedTxBufferFee;exports.BitcoinScriptType=o.BitcoinScriptType;exports.UtxoNotAvailableError=o.UtxoNotAvailableError;exports.assertUtxosAvailable=o.assertUtxosAvailable;exports.calculateBtcTxHash=o.calculateBtcTxHash;exports.collectReservedUtxoRefs=o.collectReservedUtxoRefs;exports.extractInputsFromTransaction=o.extractInputsFromTransaction;exports.getDustThreshold=o.getDustThreshold;exports.getPsbtInputFields=o.getPsbtInputFields;exports.getScriptType=o.getScriptType;exports.selectUtxosForDeposit=o.selectUtxosForDeposit;exports.selectUtxosForPegin=o.selectUtxosForPegin;exports.shouldAddChangeOutput=o.shouldAddChangeOutput;exports.validateUtxosAvailable=o.validateUtxosAvailable;exports.CONTRACT_ERRORS=r.CONTRACT_ERRORS;exports.PeginManager=r.PeginManager;exports.VAULT_APP_NAME=r.VAULT_APP_NAME;exports.buildFundingOutpointsCommitment=r.buildFundingOutpointsCommitment;exports.buildVaultContext=r.buildVaultContext;exports.computeWotsBlockPublicKeysHash=r.computeWotsBlockPublicKeysHash;exports.deriveVaultRoot=r.deriveVaultRoot;exports.deriveWotsBlocksFromSeed=r.deriveWotsBlocksFromSeed;exports.expandAuthAnchor=r.expandAuthAnchor;exports.expandHashlockSecret=r.expandHashlockSecret;exports.expandWotsSeed=r.expandWotsSeed;exports.extractErrorData=r.extractErrorData;exports.getContractErrorMessage=r.getContractErrorMessage;exports.handleContractError=r.handleContractError;exports.isKnownContractError=r.isKnownContractError;exports.isWotsMismatchError=r.isWotsMismatchError;exports.parseFundingOutpointsFromTx=r.parseFundingOutpointsFromTx;exports.ApplicationRegistryABI=e.ApplicationRegistryABI;exports.MEMPOOL_API_URLS=e.MEMPOOL_API_URLS;exports.ProtocolParamsABI=e.ProtocolParamsABI;exports.ServerIdentityError=e.ServerIdentityError;exports.VaultProviderRpcClient=e.VaultProviderRpcClient;exports.ViemProtocolParamsReader=e.ViemProtocolParamsReader;exports.ViemUniversalChallengerReader=e.ViemUniversalChallengerReader;exports.ViemVaultKeeperReader=e.ViemVaultKeeperReader;exports.ViemVaultRegistryReader=e.ViemVaultRegistryReader;exports.VpResponseValidationError=e.VpResponseValidationError;exports.VpTokenRegistry=e.VpTokenRegistry;exports.createAuthenticatedVpClient=e.createAuthenticatedVpClient;exports.getAddressTxs=e.getAddressTxs;exports.getAddressUtxos=e.getAddressUtxos;exports.getMempoolApiUrl=e.getMempoolApiUrl;exports.getNetworkFees=e.getNetworkFees;exports.getTxHex=e.getTxHex;exports.getTxInfo=e.getTxInfo;exports.getUtxoInfo=e.getUtxoInfo;exports.primeVpTokenRegistry=e.primeVpTokenRegistry;exports.pushTx=e.pushTx;exports.resolveProtocolAddresses=e.resolveProtocolAddresses;exports.validateRequestDepositorClaimerArtifactsResponse=e.validateRequestDepositorClaimerArtifactsResponse;exports.verifyServerIdentity=e.verifyServerIdentity;exports.vpTokenRegistry=e.vpTokenRegistry;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,14 +1,14 @@
|
|
|
1
|
-
import { h as e, g as t, d as r, a as o, b as i, c as n, e as l, f as u } from "../challengeAssert-
|
|
1
|
+
import { h as e, g as t, d as r, a as o, b as i, c as n, e as l, f as u } from "../challengeAssert-D3tHnLWb.js";
|
|
2
2
|
import { computeMinClaimValue as P, deriveVaultId as p } from "@babylonlabs-io/babylon-tbv-rust-wasm";
|
|
3
|
-
import { a as T, d as S, c as E, b as A, f as R, e as g } from "../noPayout-
|
|
4
|
-
import { d as m, a as x, e as b, f as I, g as f, h as C, i as v, b as U, p as O, s as V, t as F, u as h, v as y } from "../bitcoin-
|
|
3
|
+
import { a as T, d as S, c as E, b as A, f as R, e as g } from "../noPayout-BnsetBKW.js";
|
|
4
|
+
import { d as m, a as x, e as b, f as I, g as f, h as C, i as v, b as U, p as O, s as V, t as F, u as h, v as y } from "../bitcoin-B0S8SHCX.js";
|
|
5
5
|
import { C as D, P as B, a as M, c as H, g as L } from "../signing-BZigafm0.js";
|
|
6
6
|
import { B as W, H as X, K, M as w, T as G } from "../validation-CxqROCno.js";
|
|
7
|
-
import { B as J, C as Z, P as j, R as q, a as z, m as Q, h as $, n as aa, i as sa, l as ea, k as ta, r as ra, b as oa, s as ia, v as na, g as la, d as ua, c as da, j as Pa, e as pa, f as ca, w as Ta } from "../buildAndBroadcastRefund-
|
|
7
|
+
import { B as J, C as Z, P as j, R as q, a as z, m as Q, h as $, n as aa, i as sa, l as ea, k as ta, r as ra, b as oa, s as ia, v as na, g as la, d as ua, c as da, j as Pa, e as pa, f as ca, w as Ta } from "../buildAndBroadcastRefund-Dx09Zbla.js";
|
|
8
8
|
import { B as Ea, D as Aa, F as Ra, L as ga, M as _a, P as ma, b as xa, a as ba, S as Ia, T as fa, W as Ca, f as va, c as Ua, p as Oa, r as Va } from "../fundPeginTransaction-oV-dNJOU.js";
|
|
9
|
-
import { B as ha, U as ya, a as Na, f as Da, c as Ba, e as Ma, g as Ha, i as La, h as ka, s as Wa, b as Xa, d as Ka, v as wa } from "../psbtInputFields-
|
|
10
|
-
import { C as Ya, P as Ja, V as Za, k as ja, l as qa, c as za, m as Qa, d as $a, b as as, f as ss, j as es, e as ts, g as rs, h as os, i as is, a as ns, p as ls } from "../PeginManager-
|
|
11
|
-
import { A as ds, M as Ps, P as ps, S as cs, V as Ts, n as Ss, o as Es, q as As, s as Rs, h as gs, j as _s, l as ms, g as xs, a as bs, b as Is, c as fs, d as Cs, e as vs, f as Us, m as Os, p as Vs, r as Fs, v as hs, i as ys, k as Ns } from "../vault-registry-reader-
|
|
9
|
+
import { B as ha, U as ya, a as Na, f as Da, c as Ba, e as Ma, g as Ha, i as La, h as ka, s as Wa, b as Xa, d as Ka, v as wa } from "../psbtInputFields-C5QPn1YK.js";
|
|
10
|
+
import { C as Ya, P as Ja, V as Za, k as ja, l as qa, c as za, m as Qa, d as $a, b as as, f as ss, j as es, e as ts, g as rs, h as os, i as is, a as ns, p as ls } from "../PeginManager-C-L3huRO.js";
|
|
11
|
+
import { A as ds, M as Ps, P as ps, S as cs, V as Ts, n as Ss, o as Es, q as As, s as Rs, h as gs, j as _s, l as ms, g as xs, a as bs, b as Is, c as fs, d as Cs, e as vs, f as Us, m as Os, p as Vs, r as Fs, v as hs, i as ys, k as Ns } from "../vault-registry-reader-CWGbw_wZ.js";
|
|
12
12
|
import { B as Bs, D as Ms, b as Hs, J as Ls, a as ks, d as Ws, P as Xs, R as Ks, c as ws, V as Gs } from "../types-SYvSQWnc.js";
|
|
13
13
|
export {
|
|
14
14
|
ds as ApplicationRegistryABI,
|
package/dist/testing/index.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var d=Object.defineProperty;var l=(i,t,e)=>t in i?d(i,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):i[t]=e;var r=(i,t,e)=>l(i,typeof t!="symbol"?t+"":t,e);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const u=require("../sha2-CsTynrfJ.cjs"),o=require("buffer"),g=require("../bitcoin-
|
|
1
|
+
"use strict";var d=Object.defineProperty;var l=(i,t,e)=>t in i?d(i,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):i[t]=e;var r=(i,t,e)=>l(i,typeof t!="symbol"?t+"":t,e);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const u=require("../sha2-CsTynrfJ.cjs"),o=require("buffer"),g=require("../bitcoin-B3aqjuMP.cjs"),q=require("../shared/index.cjs"),f=async(i,t)=>{const e=new TextEncoder,n=e.encode(i),s=e.encode(t),a=new Uint8Array(4+n.length+4+s.length),c=new DataView(a.buffer);return c.setUint32(0,n.length),a.set(n,4),c.setUint32(4+n.length,s.length),a.set(s,4+n.length+4),g.uint8ArrayToHex(u.sha256(a))},h={publicKeyHex:"a1b2c3d4e5f6a7b8c9d0e1f2a3b4c5d6e7f8a9b0c1d2e3f4a5b6c7d8e9f0a1b2",address:"tb1pqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqkx6jks",network:q.BitcoinNetworks.SIGNET,shouldFailSigning:!1,deriveContextHash:f};class b{constructor(t={}){r(this,"config");this.config={...h,...t.publicKeyHex?{publicKeyHex:t.publicKeyHex}:{},...t.address?{address:t.address}:{},...t.network!==void 0?{network:t.network}:{},...t.shouldFailSigning!==void 0?{shouldFailSigning:t.shouldFailSigning}:{},...t.deriveContextHash?{deriveContextHash:t.deriveContextHash}:{}}}async getPublicKeyHex(){return this.config.publicKeyHex}async getAddress(){return this.config.address}async signPsbt(t){if(this.config.shouldFailSigning)throw new Error("Mock signing failed");if(!t||t.length===0)throw new Error("Invalid PSBT: empty hex string");return t+"deadbeef"}async signPsbts(t,e){const n=[];for(const s of t){const a=await this.signPsbt(s);n.push(a)}return n}async signMessage(t,e){if(this.config.shouldFailSigning)throw new Error("Mock signing failed");if(!t||t.length===0)throw new Error("Invalid message: empty string");return o.Buffer.from(`mock-signature-${e}-${t}-${this.config.publicKeyHex}`).toString("base64")}async getNetwork(){return this.config.network}async deriveContextHash(t,e){return this.config.deriveContextHash(t,e)}updateConfig(t){this.config={...this.config,...t}}reset(){this.config={...h}}}class y{constructor(t={}){r(this,"account");r(this,"chain");r(this,"shouldFailOperations");r(this,"transactionDelay");r(this,"nonce",0);this.account={address:t.address||"0x742d35cc6634c0532925a3b844bc9e7595f0beb0"},this.chain={id:t.chainId??11155111},this.shouldFailOperations=t.shouldFailOperations??!1,this.transactionDelay=t.transactionDelay??0,this.signMessage=this.signMessage.bind(this),this.sendTransaction=this.sendTransaction.bind(this)}async signMessage(t){const e=t.message,n=t.account||this.account.address;if(this.shouldFailOperations)throw new Error("Mock signing failed");if(!e||e.length===0)throw new Error("Invalid message: empty string");const s=`personal_sign:${e}-${n}-${this.chain.id}`;return`0x${o.Buffer.from(s).toString("hex").slice(0,130).padEnd(130,"0")}`}async sendTransaction(t){var s;if(this.shouldFailOperations)throw new Error("Mock transaction failed");if(!t.to)throw new Error("Invalid transaction: missing 'to' address");this.transactionDelay>0&&await new Promise(a=>setTimeout(a,this.transactionDelay)),this.nonce++;const e=JSON.stringify({from:this.account.address,to:t.to,value:((s=t.value)==null?void 0:s.toString())||"0",nonce:this.nonce,chainId:this.chain.id});return`0x${o.Buffer.from(e).toString("hex").slice(0,64).padEnd(64,"0")}`}updateConfig(t){t.address!==void 0&&(this.account.address=t.address),t.chainId!==void 0&&(this.chain.id=t.chainId),t.shouldFailOperations!==void 0&&(this.shouldFailOperations=t.shouldFailOperations),t.transactionDelay!==void 0&&(this.transactionDelay=t.transactionDelay)}reset(){this.account.address="0x742d35cc6634c0532925a3b844bc9e7595f0beb0",this.chain.id=11155111,this.shouldFailOperations=!1,this.transactionDelay=0,this.nonce=0}getCurrentNonce(){return this.nonce}}exports.MockBitcoinWallet=b;exports.MockEthereumWallet=y;
|
|
2
2
|
//# sourceMappingURL=index.cjs.map
|
package/dist/testing/index.js
CHANGED
|
@@ -3,7 +3,7 @@ var l = (e, t, s) => t in e ? d(e, t, { enumerable: !0, configurable: !0, writab
|
|
|
3
3
|
var o = (e, t, s) => l(e, typeof t != "symbol" ? t + "" : t, s);
|
|
4
4
|
import { s as g } from "../sha2-6wN58S6R.js";
|
|
5
5
|
import { Buffer as r } from "buffer";
|
|
6
|
-
import { u } from "../bitcoin-
|
|
6
|
+
import { u } from "../bitcoin-B0S8SHCX.js";
|
|
7
7
|
import { BitcoinNetworks as q } from "../shared/index.js";
|
|
8
8
|
const f = async (e, t) => {
|
|
9
9
|
const s = new TextEncoder(), n = s.encode(e), i = s.encode(t), a = new Uint8Array(4 + n.length + 4 + i.length), c = new DataView(a.buffer);
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var ue=Object.defineProperty;var pe=(n,e,t)=>e in n?ue(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t;var l=(n,e,t)=>pe(n,typeof e!="symbol"?e+"":e,t);const g=require("./validation-u8W7Lp2x.cjs"),f=require("./types-PthVHz5q.cjs"),u=require("./bitcoin-EYBKDtEW.cjs"),de=require("@bitcoin-js/tiny-secp256k1-asmjs"),P=require("bitcoinjs-lib"),b=require("buffer"),F=require("./sha2-CsTynrfJ.cjs");function he(n){const e=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(n){for(const t in n)if(t!=="default"){const r=Object.getOwnPropertyDescriptor(n,t);Object.defineProperty(e,t,r.get?r:{enumerable:!0,get:()=>n[t]})}}return e.default=n,Object.freeze(e)}const $=he(de),ye=21e6*1e8,U=3e4;async function k(n,e){const t=new AbortController,r=setTimeout(()=>t.abort(),U),s=[t.signal,e==null?void 0:e.signal].filter(Boolean);try{return await fetch(n,{...e,signal:AbortSignal.any(s)})}catch(i){throw clearTimeout(r),i!=null&&typeof i=="object"&&"name"in i&&i.name==="AbortError"?new Error(`Mempool API request timed out after ${U}ms: ${n}`):i}}const q=1e4;function G(n){return Number.isInteger(n)&&n>0&&n<=ye}function ge(n){return Number.isInteger(n)&&n>0&&n<=q}function Y(n,e){return!Number.isInteger(n)||n<0?!1:e===void 0||n<e}function C(n){if(!g.TXID_RE.test(n))throw new Error(`Invalid transaction ID format: ${n}`)}function W(n){if(!g.BITCOIN_ADDRESS_RE.test(n))throw new Error(`Invalid Bitcoin address format: ${n}`)}function z(n,e){if(!g.HEX_RE.test(n))throw new Error(`Invalid scriptPubKey: not valid hex for ${e}`);if(!g.KNOWN_SCRIPT_PREFIXES.some(r=>n.toLowerCase().startsWith(r)))throw new Error(`Unrecognized scriptPubKey type for ${e}: prefix ${n.slice(0,6)} does not match any known Bitcoin script type`)}const J={mainnet:"https://mempool.space/api",testnet:"https://mempool.space/testnet/api",signet:"https://mempool.space/signet/api"};async function x(n,e){try{const t=await k(n,e);if(!t.ok){const s=await t.text();throw new Error(`Mempool API error (${t.status}): ${s||t.statusText}`)}const r=t.headers.get("content-type");return r!=null&&r.includes("application/json")?await t.json():await t.text()}catch(t){throw t instanceof Error?new Error(`Failed to fetch from mempool API: ${t.message}`):new Error("Failed to fetch from mempool API: Unknown error")}}async function me(n,e){try{const t=await k(`${e}/tx`,{method:"POST",body:n,headers:{"Content-Type":"text/plain"}});if(!t.ok){const s=await t.text();let i;try{i=JSON.parse(s).message}catch{i=s}throw new Error(i||`Failed to broadcast transaction: ${t.statusText}`)}return await t.text()}catch(t){throw t instanceof Error?new Error(`Failed to broadcast BTC transaction: ${t.message}`):new Error("Failed to broadcast BTC transaction: Unknown error")}}async function Q(n,e){return C(n),x(`${e}/tx/${n}`)}async function fe(n,e){C(n);try{const t=await k(`${e}/tx/${n}/hex`);if(!t.ok){const r=await t.text();throw new Error(`Mempool API error (${t.status}): ${r||t.statusText}`)}return await t.text()}catch(t){throw t instanceof Error?new Error(`Failed to get transaction hex for ${n}: ${t.message}`):new Error(`Failed to get transaction hex for ${n}: Unknown error`)}}async function be(n,e,t){C(n);const r=await Q(n,t);if(!Y(e,r.vout.length))throw new Error(`Invalid vout ${e} for transaction ${n} (has ${r.vout.length} outputs)`);const s=r.vout[e];if(!G(s.value))throw new Error(`Invalid UTXO value ${s.value} for ${n}:${e}`);return z(s.scriptpubkey,`${n}:${e}`),{txid:n,vout:e,value:s.value,scriptPubKey:s.scriptpubkey}}async function _e(n,e){W(n);try{const t=await x(`${e}/address/${n}/utxo`),r=await x(`${e}/v1/validate-address/${n}`);if(!r.isvalid)throw new Error(`Invalid Bitcoin address: ${n}. Mempool API validation failed.`);z(r.scriptPubKey,n);for(const i of t){if(C(i.txid),!Y(i.vout))throw new Error(`Invalid vout ${i.vout} for ${i.txid}`);if(!G(i.value))throw new Error(`Invalid UTXO value ${i.value} for ${i.txid}:${i.vout}`)}return t.sort((i,c)=>c.value-i.value).map(i=>({txid:i.txid,vout:i.vout,value:i.value,scriptPubKey:r.scriptPubKey,confirmed:i.status.confirmed}))}catch(t){throw t instanceof Error?new Error(`Failed to get UTXOs for address ${n}: ${t.message}`):new Error(`Failed to get UTXOs for address ${n}: Unknown error`)}}function we(n){return J[n]}async function Pe(n,e){return W(n),x(`${e}/address/${n}/txs`)}async function ve(n){const e=await k(`${n}/v1/fees/recommended`);if(!e.ok)throw new Error(`Failed to fetch network fees: ${e.status} ${e.statusText}`);const t=await e.json(),r=["fastestFee","halfHourFee","hourFee","economyFee","minimumFee"];for(const s of r)if(!ge(t[s]))throw new Error(`Invalid fee rate ${s}=${t[s]} from mempool API: expected a positive number ≤ ${q}`);if(t.minimumFee>t.economyFee||t.economyFee>t.hourFee||t.hourFee>t.halfHourFee||t.halfHourFee>t.fastestFee)throw new Error(`Fee rate ordering violation from mempool API: expected minimumFee (${t.minimumFee}) <= economyFee (${t.economyFee}) <= hourFee (${t.hourFee}) <= halfHourFee (${t.halfHourFee}) <= fastestFee (${t.fastestFee}).`);return t}const T=[{type:"function",name:"getVaultKeepersByVersion",inputs:[{name:"appEntryPoint",type:"address",internalType:"address"},{name:"versionNumber",type:"uint16",internalType:"uint16"}],outputs:[{name:"",type:"tuple[]",internalType:"struct BTCVaultTypes.AddressBTCKeyPair[]",components:[{name:"ethAddress",type:"address",internalType:"address"},{name:"btcPubKey",type:"bytes32",internalType:"bytes32"}]}],stateMutability:"view"},{type:"function",name:"getCurrentVaultKeepers",inputs:[{name:"appEntryPoint",type:"address",internalType:"address"}],outputs:[{name:"",type:"tuple[]",internalType:"struct BTCVaultTypes.AddressBTCKeyPair[]",components:[{name:"ethAddress",type:"address",internalType:"address"},{name:"btcPubKey",type:"bytes32",internalType:"bytes32"}]}],stateMutability:"view"},{type:"function",name:"getCurrentVaultKeepersVersion",inputs:[{name:"appEntryPoint",type:"address",internalType:"address"}],outputs:[{name:"",type:"uint16",internalType:"uint16"}],stateMutability:"view"}],h=[{type:"function",name:"getTBVProtocolParams",inputs:[],outputs:[{name:"",type:"tuple",internalType:"struct IProtocolParams.TBVProtocolParams",components:[{name:"minimumPegInAmount",type:"uint64",internalType:"uint64"},{name:"maxPegInAmount",type:"uint64",internalType:"uint64"},{name:"pegInAckTimeout",type:"uint64",internalType:"uint64"},{name:"pegInActivationTimeout",type:"uint64",internalType:"uint64"},{name:"maxHtlcOutputCount",type:"uint8",internalType:"uint8"}]}],stateMutability:"view"},{type:"function",name:"getLatestOffchainParams",inputs:[],outputs:[{name:"",type:"tuple",internalType:"struct IProtocolParams.VersionedOffchainParams",components:[{name:"timelockAssert",type:"uint256",internalType:"uint256"},{name:"timelockChallengeAssert",type:"uint256",internalType:"uint256"},{name:"securityCouncilKeys",type:"bytes32[]",internalType:"bytes32[]"},{name:"councilQuorum",type:"uint8",internalType:"uint8"},{name:"feeRate",type:"uint64",internalType:"uint64"},{name:"babeTotalInstances",type:"uint16",internalType:"uint16"},{name:"babeInstancesToFinalize",type:"uint8",internalType:"uint8"},{name:"minVpCommissionBps",type:"uint16",internalType:"uint16"},{name:"tRefund",type:"uint32",internalType:"uint32"},{name:"tStale",type:"uint32",internalType:"uint32"},{name:"minPeginFeeRate",type:"uint64",internalType:"uint64"},{name:"proverProgramVersion",type:"uint16",internalType:"uint16"},{name:"minPrepeginDepth",type:"uint32",internalType:"uint32"}]}],stateMutability:"view"},{type:"function",name:"getOffchainParamsByVersion",inputs:[{name:"versionNumber",type:"uint16",internalType:"uint16"}],outputs:[{name:"",type:"tuple",internalType:"struct IProtocolParams.VersionedOffchainParams",components:[{name:"timelockAssert",type:"uint256",internalType:"uint256"},{name:"timelockChallengeAssert",type:"uint256",internalType:"uint256"},{name:"securityCouncilKeys",type:"bytes32[]",internalType:"bytes32[]"},{name:"councilQuorum",type:"uint8",internalType:"uint8"},{name:"feeRate",type:"uint64",internalType:"uint64"},{name:"babeTotalInstances",type:"uint16",internalType:"uint16"},{name:"babeInstancesToFinalize",type:"uint8",internalType:"uint8"},{name:"minVpCommissionBps",type:"uint16",internalType:"uint16"},{name:"tRefund",type:"uint32",internalType:"uint32"},{name:"tStale",type:"uint32",internalType:"uint32"},{name:"minPeginFeeRate",type:"uint64",internalType:"uint64"},{name:"proverProgramVersion",type:"uint16",internalType:"uint16"},{name:"minPrepeginDepth",type:"uint32",internalType:"uint32"}]}],stateMutability:"view"},{type:"function",name:"latestOffchainParamsVersion",inputs:[],outputs:[{name:"",type:"uint16",internalType:"uint16"}],stateMutability:"view"},{type:"function",name:"getUniversalChallengersByVersion",inputs:[{name:"versionNumber",type:"uint16",internalType:"uint16"}],outputs:[{name:"",type:"tuple[]",internalType:"struct BTCVaultTypes.AddressBTCKeyPair[]",components:[{name:"ethAddress",type:"address",internalType:"address"},{name:"btcPubKey",type:"bytes32",internalType:"bytes32"}]}],stateMutability:"view"},{type:"function",name:"getCurrentUniversalChallengers",inputs:[],outputs:[{name:"",type:"tuple[]",internalType:"struct BTCVaultTypes.AddressBTCKeyPair[]",components:[{name:"ethAddress",type:"address",internalType:"address"},{name:"btcPubKey",type:"bytes32",internalType:"bytes32"}]}],stateMutability:"view"},{type:"function",name:"latestUniversalChallengersVersion",inputs:[],outputs:[{name:"",type:"uint16",internalType:"uint16"}],stateMutability:"view"}],K=new Set(Object.values(f.DaemonStatus)),Te=200;function o(n){var e;return((e=JSON.stringify(n))==null?void 0:e.slice(0,Te))??"undefined"}const xe="The vault provider returned an unexpected response. Please try again or contact support.";class a extends Error{constructor(t){super(xe);l(this,"detail");this.name="VpResponseValidationError",this.detail=t}}const A=64;function _(n){return typeof n=="string"&&n.length>0&&g.HEX_RE.test(n)}function Z(n){return typeof n=="string"&&n.length>0}function ee(n,e){if(!_(n))throw new a(`VP response validation failed: "${e}" must be a non-empty hex string, got ${o(n)}`)}function w(n,e){if(!Z(n))throw new a(`VP response validation failed: "${e}" must be a non-empty string, got ${o(n)}`)}function te(n,e){if(!_(n)||n.length!==u.X_ONLY_PUBKEY_HEX_LEN&&n.length!==u.COMPRESSED_PUBKEY_HEX_LEN)throw new a(`VP response validation failed: "${e}" must be a ${u.X_ONLY_PUBKEY_HEX_LEN} or ${u.COMPRESSED_PUBKEY_HEX_LEN}-char hex string (BTC pubkey), got ${o(n)}`)}function Ae(n){const e=n.presigning;if(e==null)return;if(typeof e!="object"||Array.isArray(e))throw new a('VP response validation failed: "progress.presigning" must be an object if present');const t=e;if(t.depositor_graph_created!==void 0&&typeof t.depositor_graph_created!="boolean")throw new a(`VP response validation failed: "progress.presigning.depositor_graph_created" must be a boolean if present, got ${o(t.depositor_graph_created)}`);if(t.vk_challenger_presigning_completed!==void 0&&typeof t.vk_challenger_presigning_completed!="number")throw new a(`VP response validation failed: "progress.presigning.vk_challenger_presigning_completed" must be a number if present, got ${o(t.vk_challenger_presigning_completed)}`);if(t.vk_challenger_presigning_total!==void 0&&typeof t.vk_challenger_presigning_total!="number")throw new a(`VP response validation failed: "progress.presigning.vk_challenger_presigning_total" must be a number if present, got ${o(t.vk_challenger_presigning_total)}`)}function Ve(n){if(n===null||typeof n!="object")throw new a("VP response validation failed: getPeginStatus response is not an object");const e=n;if(!_(e.pegin_txid)||e.pegin_txid.length!==A)throw new a(`VP response validation failed: "pegin_txid" must be a ${A}-char hex string (txid), got ${o(e.pegin_txid)}`);if(typeof e.status!="string")throw new a('VP response validation failed: "status" must be a string');if(!K.has(e.status))throw new a(`VP response validation failed: unrecognized status "${e.status}". Expected one of: ${[...K].join(", ")}`);if(e.progress===null||typeof e.progress!="object"||Array.isArray(e.progress))throw new a('VP response validation failed: "progress" must be an object');if(Ae(e.progress),typeof e.health_info!="string")throw new a('VP response validation failed: "health_info" must be a string');if(e.last_error!==void 0&&typeof e.last_error!="string")throw new a(`VP response validation failed: "last_error" must be a string if present, got ${o(e.last_error)}`)}function Ee(n){if(n===null||typeof n!="object")throw new a("VP response validation failed: requestDepositorPresignTransactions response is not an object");const e=n;if(!Array.isArray(e.txs))throw new a('VP response validation failed: "txs" must be an array');for(let t=0;t<e.txs.length;t++)$e(e.txs[t],`txs[${t}]`);if(e.depositor_graph===null||typeof e.depositor_graph!="object")throw new a('VP response validation failed: "depositor_graph" must be an object');Ie(e.depositor_graph)}function m(n,e){if(n===null||typeof n!="object")throw new a(`VP response validation failed: "${e}" must be an object`);ee(n.tx_hex,`${e}.tx_hex`)}function $e(n,e){if(n===null||typeof n!="object")throw new a(`VP response validation failed: "${e}" must be an object`);const t=n;te(t.claimer_pubkey,`${e}.claimer_pubkey`),m(t.claim_tx,`${e}.claim_tx`),m(t.assert_tx,`${e}.assert_tx`),m(t.payout_tx,`${e}.payout_tx`),w(t.payout_psbt,`${e}.payout_psbt`)}function ke(n,e){if(n===null||typeof n!="object")throw new a(`VP response validation failed: "${e}" must be an object`);const t=n;w(t.wots_pks_json,`${e}.wots_pks_json`),w(t.gc_wots_keys_json,`${e}.gc_wots_keys_json`)}function Ce(n,e){if(n===null||typeof n!="object")throw new a(`VP response validation failed: "${e}" must be an object`);const t=n;if(te(t.challenger_pubkey,`${e}.challenger_pubkey`),m(t.challenge_assert_x_tx,`${e}.challenge_assert_x_tx`),m(t.challenge_assert_y_tx,`${e}.challenge_assert_y_tx`),m(t.nopayout_tx,`${e}.nopayout_tx`),w(t.nopayout_psbt,`${e}.nopayout_psbt`),!Array.isArray(t.challenge_assert_connectors))throw new a(`VP response validation failed: "${e}.challenge_assert_connectors" must be an array`);for(let r=0;r<t.challenge_assert_connectors.length;r++)ke(t.challenge_assert_connectors[r],`${e}.challenge_assert_connectors[${r}]`);if(!Array.isArray(t.output_label_hashes))throw new a(`VP response validation failed: "${e}.output_label_hashes" must be an array`);for(let r=0;r<t.output_label_hashes.length;r++)ee(t.output_label_hashes[r],`${e}.output_label_hashes[${r}]`)}function ne(n){if(n===null||typeof n!="object")throw new a("VP response validation failed: requestDepositorClaimerArtifacts response is not an object");const e=n;if(!Z(e.tx_graph_json))throw new a(`VP response validation failed: "tx_graph_json" must be a non-empty string, got ${o(e.tx_graph_json)}`);if(!_(e.verifying_key_hex))throw new a(`VP response validation failed: "verifying_key_hex" must be a non-empty hex string, got ${o(e.verifying_key_hex)}`);if(e.babe_sessions===null||typeof e.babe_sessions!="object")throw new a('VP response validation failed: "babe_sessions" must be an object');for(const[t,r]of Object.entries(e.babe_sessions)){if(r===null||typeof r!="object")throw new a(`VP response validation failed: "babe_sessions.${t}" must be an object`);const s=r;if(!_(s.decryptor_artifacts_hex))throw new a(`VP response validation failed: "babe_sessions.${t}.decryptor_artifacts_hex" must be a non-empty hex string, got ${o(s.decryptor_artifacts_hex)}`)}}function Se(n){if(n===null||typeof n!="object")throw new a("VP response validation failed: getPegoutStatus response is not an object");const e=n;if(!_(e.pegin_txid)||e.pegin_txid.length!==A)throw new a(`VP response validation failed: "pegin_txid" must be a ${A}-char hex string (txid), got ${o(e.pegin_txid)}`);if(typeof e.found!="boolean")throw new a(`VP response validation failed: "found" must be a boolean, got ${o(e.found)}`);if(e.claimer!==void 0){if(e.claimer===null||typeof e.claimer!="object")throw new a('VP response validation failed: "claimer" must be an object if present');const t=e.claimer;if(typeof t.status!="string")throw new a(`VP response validation failed: "claimer.status" must be a string, got ${o(t.status)}`);if(typeof t.failed!="boolean")throw new a(`VP response validation failed: "claimer.failed" must be a boolean, got ${o(t.failed)}`)}if(e.challenger!==void 0){if(e.challenger===null||typeof e.challenger!="object")throw new a('VP response validation failed: "challenger" must be an object if present');const t=e.challenger;if(typeof t.status!="string")throw new a(`VP response validation failed: "challenger.status" must be a string, got ${o(t.status)}`)}}function Ie(n){if(m(n.claim_tx,"depositor_graph.claim_tx"),m(n.assert_tx,"depositor_graph.assert_tx"),m(n.payout_tx,"depositor_graph.payout_tx"),w(n.payout_psbt,"depositor_graph.payout_psbt"),!Array.isArray(n.challenger_presign_data))throw new a('VP response validation failed: "depositor_graph.challenger_presign_data" must be an array');for(let e=0;e<n.challenger_presign_data.length;e++)Ce(n.challenger_presign_data[e],`depositor_graph.challenger_presign_data[${e}]`);if(typeof n.offchain_params_version!="number")throw new a('VP response validation failed: "depositor_graph.offchain_params_version" must be a number')}const Be=6e4;class re{constructor(e,t){l(this,"client");const r={baseUrl:e,timeout:(t==null?void 0:t.timeout)??Be,retries:t==null?void 0:t.retries,retryDelay:t==null?void 0:t.retryDelay,retryableFor:t==null?void 0:t.retryableFor,headers:t==null?void 0:t.headers,tokenProvider:t==null?void 0:t.tokenProvider,maxResponseBytes:t==null?void 0:t.maxResponseBytes};this.client=new f.JsonRpcClient(r)}async requestDepositorPresignTransactions(e,t){const r=await this.client.call("vaultProvider_requestDepositorPresignTransactions",e,t);return Ee(r),r}async submitDepositorPresignatures(e,t){return this.client.call("vaultProvider_submitDepositorPresignatures",e,t)}async submitDepositorWotsKey(e,t){return this.client.call("vaultProvider_submitDepositorWotsKey",e,t)}async requestDepositorClaimerArtifacts(e,t){const r=await this.client.call("vaultProvider_requestDepositorClaimerArtifacts",e,t);return ne(r),r}async getPeginStatus(e,t){const r=await this.client.call("vaultProvider_getPeginStatus",e,t);return Ve(r),r}async getPegoutStatus(e,t){const r=await this.client.call("vaultProvider_getPegoutStatus",e,t);return Se(r),r}}const Re="BIP0322-signed-message",Oe="TapTweak",ie=32,Ne=64;function se(n,e){const t=new TextEncoder().encode(n),r=F.sha256(t),s=new Uint8Array(r.length*2+e.length);return s.set(r,0),s.set(r,r.length),s.set(e,r.length*2),F.sha256(s)}function He(n){if(n.length!==ie)return null;const e=se(Oe,n),t=$.xOnlyPointAddTweak(n,e);return t?t.xOnlyPubkey:null}function Fe(n,e,t){if(e.length!==ie||t.length!==Ne)return!1;try{const r=se(Re,n),s=P.payments.p2tr({internalPubkey:b.Buffer.from(e)});if(!s.output)return!1;const i=s.output,c=0,y=new P.Transaction;y.version=0,y.locktime=0;const S=b.Buffer.concat([b.Buffer.from([0,32]),b.Buffer.from(r)]);y.addInput(b.Buffer.alloc(32,0),4294967295,0,S),y.addOutput(i,c);const d=new P.Transaction;d.version=0,d.locktime=0;const I=y.getHash();d.addInput(I,0,0),d.addOutput(b.Buffer.from([106]),c);const N=d.hashForWitnessV1(0,[i],[c],P.Transaction.SIGHASH_DEFAULT),H=He(e);return H?$.verifySchnorr(N,H,t):!1}catch{return!1}}function V(n,e){const t=(n&7)<<5,r=typeof e=="bigint"?e:BigInt(e);if(r<0n)throw new Error("cborHead: negative argument");if(r<24n)return new Uint8Array([t|Number(r)]);if(r<0x100n)return new Uint8Array([t|24,Number(r)]);if(r<0x10000n){const i=Number(r);return new Uint8Array([t|25,i>>>8&255,i&255])}if(r<0x100000000n){const i=Number(r);return new Uint8Array([t|26,i>>>24&255,i>>>16&255,i>>>8&255,i&255])}const s=new Uint8Array(9);s[0]=t|27;for(let i=7;i>=0;i--)s[1+i]=Number(r>>BigInt((7-i)*8))&255;return s}function ae(...n){const e=n.reduce((s,i)=>s+i.length,0),t=new Uint8Array(e);let r=0;for(const s of n)t.set(s,r),r+=s.length;return t}function D(n){const t=[V(4,n.length)];for(const r of n)t.push(V(0,r));return ae(...t)}function Ue(n,e,t){if(!Number.isSafeInteger(t)||t<0)throw new Error(`encodeServerIdentityPayload: expires_at must be a non-negative safe integer, got ${t}`);const r=V(4,3),s=D(n),i=D(e),c=V(0,t);return ae(r,s,i,c)}const Ke=new TextEncoder().encode("btc-auth.server-identity.v1");class p extends Error{constructor(e,t){super(e),this.reason=t,this.name="ServerIdentityError"}}function v(n){const e=new Uint8Array(n.length/2);for(let t=0;t<e.length;t++)e[t]=parseInt(n.slice(t*2,t*2+2),16);return e}function oe(n){const{proof:e,pinnedServerPubkey:t,now:r}=n,s=u.stripHexPrefix(t).toLowerCase();if(s.length!==u.X_ONLY_PUBKEY_HEX_LEN||!g.HEX_RE.test(s))throw new p(`pinnedServerPubkey must be 32-byte hex; got ${s.length} chars`,"invalid_pubkey_encoding");const i=u.stripHexPrefix(e.server_pubkey).toLowerCase();if(i.length!==u.X_ONLY_PUBKEY_HEX_LEN||!g.HEX_RE.test(i))throw new p(`server_pubkey must be 32-byte hex; got ${i.length} chars`,"invalid_pubkey_encoding");if(i!==s)throw new p(`server_pubkey does not match pinned value: expected ${s}, got ${i}`,"pinned_pubkey_mismatch");if(!Number.isSafeInteger(e.expires_at))throw new p(`expires_at must be a finite integer; got ${JSON.stringify(e.expires_at)}`,"invalid_expires_at");if(!Number.isSafeInteger(r))throw new p(`now must be a finite integer; got ${JSON.stringify(r)}`,"invalid_expires_at");if(e.expires_at<=r)throw new p(`server identity proof expired at ${e.expires_at}, now ${r}`,"expired");const c=u.stripHexPrefix(e.ephemeral_pubkey).toLowerCase();if(c.length!==u.COMPRESSED_PUBKEY_HEX_LEN||!g.HEX_RE.test(c))throw new p(`ephemeral_pubkey must be 33-byte compressed hex; got ${c.length} chars`,"invalid_ephemeral_pubkey");const y=c.slice(0,2);if(y!=="02"&&y!=="03")throw new p(`ephemeral_pubkey must be compressed (prefix 02/03); got ${y}`,"invalid_ephemeral_pubkey");const S=v(c);if(!$.isPoint(S))throw new p("ephemeral_pubkey is not a valid secp256k1 point","invalid_ephemeral_pubkey");const d=u.stripHexPrefix(e.signature).toLowerCase();if(d.length!==u.SCHNORR_SIG_HEX_LEN||!g.HEX_RE.test(d))throw new p(`signature must be 64-byte Schnorr hex; got ${d.length} chars`,"invalid_signature_encoding");const I=Ue(Ke,v(c),e.expires_at);if(!Fe(I,v(i),v(d)))throw new p("BIP-322 signature verification failed — ephemeral key is not attested by pinned server pubkey","signature_verification_failed")}const De=new Set(["vaultProvider_submitDepositorWotsKey","vaultProvider_submitDepositorPresignatures","vaultProvider_requestDepositorPresignTransactions"]),Me=6e4,R="auth_createDepositorToken";function ce(n,e){return new f.JsonRpcClient({baseUrl:n,timeout:Me,headers:e,retryableFor:t=>t===R})}const M=4102444800,je=30;class Xe{constructor(e){l(this,"client");l(this,"peginTxid");l(this,"authAnchorHex");l(this,"pinnedServerPubkey");l(this,"authGatedMethods");l(this,"refreshSkewSecs");l(this,"now");l(this,"cached",null);l(this,"inFlight",null);this.client=e.client,this.peginTxid=e.peginTxid,this.authAnchorHex=e.authAnchorHex,this.pinnedServerPubkey=e.pinnedServerPubkey,this.authGatedMethods=e.authGatedMethods,this.refreshSkewSecs=e.refreshSkewSecs??je,this.now=e.now??(()=>Math.floor(Date.now()/1e3))}async getToken(e){if(e===R||!this.authGatedMethods.has(e))return null;const t=this.cached;return t&&this.now()+this.refreshSkewSecs<t.expiresAt?t.token:(await this.acquireSingleFlight()).token}invalidate(){this.cached=null}setClient(e){this.client=e}acquireSingleFlight(){const e=this.inFlight;if(e)return e;const t=(async()=>{try{const r=await this.client.call(R,{pegin_txid:this.peginTxid,auth_anchor:this.authAnchorHex});if(oe({proof:r.server_identity,pinnedServerPubkey:this.pinnedServerPubkey,now:this.now()}),typeof r.token!="string"||r.token.length===0)throw new Error(`VpTokenProvider: invalid token in acquire response (expected non-empty string, got ${typeof r.token})`);const s=this.now();if(!Number.isSafeInteger(r.expires_at)||r.expires_at<=s||r.expires_at>M)throw new Error(`VpTokenProvider: invalid expires_at in acquire response (got ${JSON.stringify(r.expires_at)}; must be a safe integer in (${s}, ${M}])`);const i={token:r.token,expiresAt:r.expires_at};return this.cached=i,i}finally{this.inFlight=null}})();return this.inFlight=t,t}}class le{constructor(){l(this,"entries",new Map)}getOrCreate(e){const t=this.entries.get(e.peginTxid);if(t){if(t.authAnchorHex!==e.authAnchorHex)throw new Error(`VpTokenRegistry: peginTxid ${e.peginTxid} already bound to authAnchorHex ${t.authAnchorHex.slice(0,8)}…; got ${e.authAnchorHex.slice(0,8)}…`);if(t.pinnedServerPubkey!==e.pinnedServerPubkey)throw new Error(`VpTokenRegistry: peginTxid ${e.peginTxid} already bound to pinnedServerPubkey ${t.pinnedServerPubkey.slice(0,8)}…; got ${e.pinnedServerPubkey.slice(0,8)}…`);return t.provider.setClient(e.client),t.provider}const r=new Xe({client:e.client,peginTxid:e.peginTxid,authAnchorHex:e.authAnchorHex,pinnedServerPubkey:e.pinnedServerPubkey,authGatedMethods:De});return this.entries.set(e.peginTxid,{provider:r,authAnchorHex:e.authAnchorHex,pinnedServerPubkey:e.pinnedServerPubkey}),r}peek(e){var t;return(t=this.entries.get(e))==null?void 0:t.provider}release(e){this.entries.delete(e)}clear(){this.entries.clear()}get size(){return this.entries.size}}const O=new le;function Le(n){var r;const e=ce(n.baseUrl,(r=n.options)==null?void 0:r.headers),t=O.getOrCreate({client:e,peginTxid:n.peginTxid,authAnchorHex:n.authAnchorHex,pinnedServerPubkey:n.pinnedServerPubkey});return new re(n.baseUrl,{...n.options,tokenProvider:t})}function qe(n){O.getOrCreate({client:ce(n.baseUrl,n.headers),peginTxid:n.peginTxid,authAnchorHex:n.authAnchorHex,pinnedServerPubkey:n.pinnedServerPubkey})}async function Ge(n,e){const[t,r]=await n.multicall({contracts:[{address:e,abi:f.BTCVaultRegistryABI,functionName:"protocolParams"},{address:e,abi:f.BTCVaultRegistryABI,functionName:"applicationRegistry"}],allowFailure:!1});return{protocolParams:t,applicationRegistry:r}}const j=65535;function B(n){return{timelockAssert:n.timelockAssert,timelockChallengeAssert:n.timelockChallengeAssert,securityCouncilKeys:[...n.securityCouncilKeys],councilQuorum:n.councilQuorum,feeRate:n.feeRate,babeTotalInstances:n.babeTotalInstances,babeInstancesToFinalize:n.babeInstancesToFinalize,minVpCommissionBps:n.minVpCommissionBps,tRefund:n.tRefund,tStale:n.tStale,minPeginFeeRate:n.minPeginFeeRate,proverProgramVersion:n.proverProgramVersion,minPrepeginDepth:n.minPrepeginDepth}}function X(n){return{minimumPegInAmount:n.minimumPegInAmount,maxPegInAmount:n.maxPegInAmount,pegInAckTimeout:n.pegInAckTimeout,pegInActivationTimeout:n.pegInActivationTimeout,maxHtlcOutputCount:n.maxHtlcOutputCount}}function L(n){if(n>BigInt(j))throw new Error(`timelockAssert value ${n} exceeds uint16 max (${j})`);return Number(n)}class Ye{constructor(e,t){this.publicClient=e,this.contractAddress=t}async getTBVProtocolParams(){const e=await this.publicClient.readContract({address:this.contractAddress,abi:h,functionName:"getTBVProtocolParams"});return X(e)}async getLatestOffchainParams(){const e=await this.publicClient.readContract({address:this.contractAddress,abi:h,functionName:"getLatestOffchainParams"});return B(e)}async getOffchainParamsByVersion(e){const t=await this.publicClient.readContract({address:this.contractAddress,abi:h,functionName:"getOffchainParamsByVersion",args:[e]});return B(t)}async getLatestOffchainParamsVersion(){return await this.publicClient.readContract({address:this.contractAddress,abi:h,functionName:"latestOffchainParamsVersion"})}async getTimelockPeginByVersion(e){const t=await this.getOffchainParamsByVersion(e);return L(t.timelockAssert)}async getPegInConfiguration(){const e=await this.publicClient.multicall({contracts:[{address:this.contractAddress,abi:h,functionName:"getTBVProtocolParams"},{address:this.contractAddress,abi:h,functionName:"getLatestOffchainParams"}],allowFailure:!1}),t=X(e[0]),r=B(e[1]);return{minimumPegInAmount:t.minimumPegInAmount,maxPegInAmount:t.maxPegInAmount,pegInAckTimeout:t.pegInAckTimeout,pegInActivationTimeout:t.pegInActivationTimeout,maxHtlcOutputCount:t.maxHtlcOutputCount,timelockPegin:L(r.timelockAssert),timelockRefund:r.tRefund,minVpCommissionBps:r.minVpCommissionBps,offchainParams:r}}}function E(n){return n.map(e=>({ethAddress:e.ethAddress,btcPubKey:e.btcPubKey}))}class We{constructor(e,t){this.publicClient=e,this.contractAddress=t}async getVaultKeepersByVersion(e,t){const r=await this.publicClient.readContract({address:this.contractAddress,abi:T,functionName:"getVaultKeepersByVersion",args:[e,t]});return E(r)}async getCurrentVaultKeepers(e){const t=await this.publicClient.readContract({address:this.contractAddress,abi:T,functionName:"getCurrentVaultKeepers",args:[e]});return E(t)}async getCurrentVaultKeepersVersion(e){return await this.publicClient.readContract({address:this.contractAddress,abi:T,functionName:"getCurrentVaultKeepersVersion",args:[e]})}}class ze{constructor(e,t){this.publicClient=e,this.contractAddress=t}async getUniversalChallengersByVersion(e){const t=await this.publicClient.readContract({address:this.contractAddress,abi:h,functionName:"getUniversalChallengersByVersion",args:[e]});return E(t)}async getCurrentUniversalChallengers(){const e=await this.publicClient.readContract({address:this.contractAddress,abi:h,functionName:"getCurrentUniversalChallengers"});return E(e)}async getLatestUniversalChallengersVersion(){return await this.publicClient.readContract({address:this.contractAddress,abi:h,functionName:"latestUniversalChallengersVersion"})}}class Je{constructor(e,t){this.publicClient=e,this.contractAddress=t}async getVaultProviderBtcPubKey(e){const r=(await this.publicClient.readContract({address:this.contractAddress,abi:f.BTCVaultRegistryABI,functionName:"getVaultProviderBTCKey",args:[e]})).toLowerCase();if(!/^0x[0-9a-f]{64}$/.test(r))throw new Error(`getVaultProviderBTCKey returned an unexpected value (vp=${e}, length ${r.length}, prefix "${r.slice(0,2)}")`);const s=r.slice(2);if(!$.isXOnlyPoint(u.hexToUint8Array(s)))throw new Error(`getVaultProviderBTCKey returned a value that is not on the secp256k1 curve (vp=${e})`);return s}async getVaultBasicInfo(e){const t=await this.publicClient.readContract({address:this.contractAddress,abi:f.BTCVaultRegistryABI,functionName:"getBtcVaultBasicInfo",args:[e]});return{depositor:t.depositor,depositorBtcPubKey:t.depositorBtcPubKey,amount:t.amount,vaultProvider:t.vaultProvider,status:t.status,applicationEntryPoint:t.applicationEntryPoint,createdAt:t.createdAt}}async getVaultProtocolInfo(e){const t=await this.publicClient.readContract({address:this.contractAddress,abi:f.BTCVaultRegistryABI,functionName:"getBtcVaultProtocolInfo",args:[e]});return{depositorSignedPeginTx:t.depositorSignedPeginTx,universalChallengersVersion:t.universalChallengersVersion,appVaultKeepersVersion:t.appVaultKeepersVersion,offchainParamsVersion:t.offchainParamsVersion,verifiedAt:t.verifiedAt,depositorWotsPkHash:t.depositorWotsPkHash,hashlock:t.hashlock,htlcVout:t.htlcVout,depositorPopSignature:t.depositorPopSignature,prePeginTxHash:t.prePeginTxHash,vaultProviderCommissionBps:t.vaultProviderCommissionBps}}async getVaultData(e){const[t,r]=await Promise.all([this.getVaultBasicInfo(e),this.getVaultProtocolInfo(e)]);if(!r.depositorSignedPeginTx||r.depositorSignedPeginTx==="0x")throw new Error(`Vault ${e} not found on-chain or has no pegin transaction`);return{basic:t,protocol:r}}}exports.ApplicationRegistryABI=T;exports.MEMPOOL_API_URLS=J;exports.ProtocolParamsABI=h;exports.ServerIdentityError=p;exports.VaultProviderRpcClient=re;exports.ViemProtocolParamsReader=Ye;exports.ViemUniversalChallengerReader=ze;exports.ViemVaultKeeperReader=We;exports.ViemVaultRegistryReader=Je;exports.VpResponseValidationError=a;exports.VpTokenRegistry=le;exports.createAuthenticatedVpClient=Le;exports.getAddressTxs=Pe;exports.getAddressUtxos=_e;exports.getMempoolApiUrl=we;exports.getNetworkFees=ve;exports.getTxHex=fe;exports.getTxInfo=Q;exports.getUtxoInfo=be;exports.primeVpTokenRegistry=qe;exports.pushTx=me;exports.resolveProtocolAddresses=Ge;exports.validateRequestDepositorClaimerArtifactsResponse=ne;exports.verifyServerIdentity=oe;exports.vpTokenRegistry=O;
|
|
2
|
-
//# sourceMappingURL=vault-registry-reader-
|
|
1
|
+
"use strict";var ue=Object.defineProperty;var pe=(n,e,t)=>e in n?ue(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t;var l=(n,e,t)=>pe(n,typeof e!="symbol"?e+"":e,t);const g=require("./validation-u8W7Lp2x.cjs"),f=require("./types-PthVHz5q.cjs"),u=require("./bitcoin-B3aqjuMP.cjs"),de=require("@bitcoin-js/tiny-secp256k1-asmjs"),P=require("bitcoinjs-lib"),b=require("buffer"),F=require("./sha2-CsTynrfJ.cjs");function he(n){const e=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(n){for(const t in n)if(t!=="default"){const r=Object.getOwnPropertyDescriptor(n,t);Object.defineProperty(e,t,r.get?r:{enumerable:!0,get:()=>n[t]})}}return e.default=n,Object.freeze(e)}const $=he(de),ye=21e6*1e8,U=3e4;async function k(n,e){const t=new AbortController,r=setTimeout(()=>t.abort(),U),s=[t.signal,e==null?void 0:e.signal].filter(Boolean);try{return await fetch(n,{...e,signal:AbortSignal.any(s)})}catch(i){throw clearTimeout(r),i!=null&&typeof i=="object"&&"name"in i&&i.name==="AbortError"?new Error(`Mempool API request timed out after ${U}ms: ${n}`):i}}const q=1e4;function G(n){return Number.isInteger(n)&&n>0&&n<=ye}function ge(n){return Number.isInteger(n)&&n>0&&n<=q}function Y(n,e){return!Number.isInteger(n)||n<0?!1:e===void 0||n<e}function C(n){if(!g.TXID_RE.test(n))throw new Error(`Invalid transaction ID format: ${n}`)}function W(n){if(!g.BITCOIN_ADDRESS_RE.test(n))throw new Error(`Invalid Bitcoin address format: ${n}`)}function z(n,e){if(!g.HEX_RE.test(n))throw new Error(`Invalid scriptPubKey: not valid hex for ${e}`);if(!g.KNOWN_SCRIPT_PREFIXES.some(r=>n.toLowerCase().startsWith(r)))throw new Error(`Unrecognized scriptPubKey type for ${e}: prefix ${n.slice(0,6)} does not match any known Bitcoin script type`)}const J={mainnet:"https://mempool.space/api",testnet:"https://mempool.space/testnet/api",signet:"https://mempool.space/signet/api"};async function x(n,e){try{const t=await k(n,e);if(!t.ok){const s=await t.text();throw new Error(`Mempool API error (${t.status}): ${s||t.statusText}`)}const r=t.headers.get("content-type");return r!=null&&r.includes("application/json")?await t.json():await t.text()}catch(t){throw t instanceof Error?new Error(`Failed to fetch from mempool API: ${t.message}`):new Error("Failed to fetch from mempool API: Unknown error")}}async function me(n,e){try{const t=await k(`${e}/tx`,{method:"POST",body:n,headers:{"Content-Type":"text/plain"}});if(!t.ok){const s=await t.text();let i;try{i=JSON.parse(s).message}catch{i=s}throw new Error(i||`Failed to broadcast transaction: ${t.statusText}`)}return await t.text()}catch(t){throw t instanceof Error?new Error(`Failed to broadcast BTC transaction: ${t.message}`):new Error("Failed to broadcast BTC transaction: Unknown error")}}async function Q(n,e){return C(n),x(`${e}/tx/${n}`)}async function fe(n,e){C(n);try{const t=await k(`${e}/tx/${n}/hex`);if(!t.ok){const r=await t.text();throw new Error(`Mempool API error (${t.status}): ${r||t.statusText}`)}return await t.text()}catch(t){throw t instanceof Error?new Error(`Failed to get transaction hex for ${n}: ${t.message}`):new Error(`Failed to get transaction hex for ${n}: Unknown error`)}}async function be(n,e,t){C(n);const r=await Q(n,t);if(!Y(e,r.vout.length))throw new Error(`Invalid vout ${e} for transaction ${n} (has ${r.vout.length} outputs)`);const s=r.vout[e];if(!G(s.value))throw new Error(`Invalid UTXO value ${s.value} for ${n}:${e}`);return z(s.scriptpubkey,`${n}:${e}`),{txid:n,vout:e,value:s.value,scriptPubKey:s.scriptpubkey}}async function _e(n,e){W(n);try{const t=await x(`${e}/address/${n}/utxo`),r=await x(`${e}/v1/validate-address/${n}`);if(!r.isvalid)throw new Error(`Invalid Bitcoin address: ${n}. Mempool API validation failed.`);z(r.scriptPubKey,n);for(const i of t){if(C(i.txid),!Y(i.vout))throw new Error(`Invalid vout ${i.vout} for ${i.txid}`);if(!G(i.value))throw new Error(`Invalid UTXO value ${i.value} for ${i.txid}:${i.vout}`)}return t.sort((i,c)=>c.value-i.value).map(i=>({txid:i.txid,vout:i.vout,value:i.value,scriptPubKey:r.scriptPubKey,confirmed:i.status.confirmed}))}catch(t){throw t instanceof Error?new Error(`Failed to get UTXOs for address ${n}: ${t.message}`):new Error(`Failed to get UTXOs for address ${n}: Unknown error`)}}function we(n){return J[n]}async function Pe(n,e){return W(n),x(`${e}/address/${n}/txs`)}async function ve(n){const e=await k(`${n}/v1/fees/recommended`);if(!e.ok)throw new Error(`Failed to fetch network fees: ${e.status} ${e.statusText}`);const t=await e.json(),r=["fastestFee","halfHourFee","hourFee","economyFee","minimumFee"];for(const s of r)if(!ge(t[s]))throw new Error(`Invalid fee rate ${s}=${t[s]} from mempool API: expected a positive number ≤ ${q}`);if(t.minimumFee>t.economyFee||t.economyFee>t.hourFee||t.hourFee>t.halfHourFee||t.halfHourFee>t.fastestFee)throw new Error(`Fee rate ordering violation from mempool API: expected minimumFee (${t.minimumFee}) <= economyFee (${t.economyFee}) <= hourFee (${t.hourFee}) <= halfHourFee (${t.halfHourFee}) <= fastestFee (${t.fastestFee}).`);return t}const T=[{type:"function",name:"getVaultKeepersByVersion",inputs:[{name:"appEntryPoint",type:"address",internalType:"address"},{name:"versionNumber",type:"uint16",internalType:"uint16"}],outputs:[{name:"",type:"tuple[]",internalType:"struct BTCVaultTypes.AddressBTCKeyPair[]",components:[{name:"ethAddress",type:"address",internalType:"address"},{name:"btcPubKey",type:"bytes32",internalType:"bytes32"}]}],stateMutability:"view"},{type:"function",name:"getCurrentVaultKeepers",inputs:[{name:"appEntryPoint",type:"address",internalType:"address"}],outputs:[{name:"",type:"tuple[]",internalType:"struct BTCVaultTypes.AddressBTCKeyPair[]",components:[{name:"ethAddress",type:"address",internalType:"address"},{name:"btcPubKey",type:"bytes32",internalType:"bytes32"}]}],stateMutability:"view"},{type:"function",name:"getCurrentVaultKeepersVersion",inputs:[{name:"appEntryPoint",type:"address",internalType:"address"}],outputs:[{name:"",type:"uint16",internalType:"uint16"}],stateMutability:"view"}],h=[{type:"function",name:"getTBVProtocolParams",inputs:[],outputs:[{name:"",type:"tuple",internalType:"struct IProtocolParams.TBVProtocolParams",components:[{name:"minimumPegInAmount",type:"uint64",internalType:"uint64"},{name:"maxPegInAmount",type:"uint64",internalType:"uint64"},{name:"pegInAckTimeout",type:"uint64",internalType:"uint64"},{name:"pegInActivationTimeout",type:"uint64",internalType:"uint64"},{name:"maxHtlcOutputCount",type:"uint8",internalType:"uint8"}]}],stateMutability:"view"},{type:"function",name:"getLatestOffchainParams",inputs:[],outputs:[{name:"",type:"tuple",internalType:"struct IProtocolParams.VersionedOffchainParams",components:[{name:"timelockAssert",type:"uint256",internalType:"uint256"},{name:"timelockChallengeAssert",type:"uint256",internalType:"uint256"},{name:"securityCouncilKeys",type:"bytes32[]",internalType:"bytes32[]"},{name:"councilQuorum",type:"uint8",internalType:"uint8"},{name:"feeRate",type:"uint64",internalType:"uint64"},{name:"babeTotalInstances",type:"uint16",internalType:"uint16"},{name:"babeInstancesToFinalize",type:"uint8",internalType:"uint8"},{name:"minVpCommissionBps",type:"uint16",internalType:"uint16"},{name:"tRefund",type:"uint32",internalType:"uint32"},{name:"tStale",type:"uint32",internalType:"uint32"},{name:"minPeginFeeRate",type:"uint64",internalType:"uint64"},{name:"proverProgramVersion",type:"uint16",internalType:"uint16"},{name:"minPrepeginDepth",type:"uint32",internalType:"uint32"}]}],stateMutability:"view"},{type:"function",name:"getOffchainParamsByVersion",inputs:[{name:"versionNumber",type:"uint16",internalType:"uint16"}],outputs:[{name:"",type:"tuple",internalType:"struct IProtocolParams.VersionedOffchainParams",components:[{name:"timelockAssert",type:"uint256",internalType:"uint256"},{name:"timelockChallengeAssert",type:"uint256",internalType:"uint256"},{name:"securityCouncilKeys",type:"bytes32[]",internalType:"bytes32[]"},{name:"councilQuorum",type:"uint8",internalType:"uint8"},{name:"feeRate",type:"uint64",internalType:"uint64"},{name:"babeTotalInstances",type:"uint16",internalType:"uint16"},{name:"babeInstancesToFinalize",type:"uint8",internalType:"uint8"},{name:"minVpCommissionBps",type:"uint16",internalType:"uint16"},{name:"tRefund",type:"uint32",internalType:"uint32"},{name:"tStale",type:"uint32",internalType:"uint32"},{name:"minPeginFeeRate",type:"uint64",internalType:"uint64"},{name:"proverProgramVersion",type:"uint16",internalType:"uint16"},{name:"minPrepeginDepth",type:"uint32",internalType:"uint32"}]}],stateMutability:"view"},{type:"function",name:"latestOffchainParamsVersion",inputs:[],outputs:[{name:"",type:"uint16",internalType:"uint16"}],stateMutability:"view"},{type:"function",name:"getUniversalChallengersByVersion",inputs:[{name:"versionNumber",type:"uint16",internalType:"uint16"}],outputs:[{name:"",type:"tuple[]",internalType:"struct BTCVaultTypes.AddressBTCKeyPair[]",components:[{name:"ethAddress",type:"address",internalType:"address"},{name:"btcPubKey",type:"bytes32",internalType:"bytes32"}]}],stateMutability:"view"},{type:"function",name:"getCurrentUniversalChallengers",inputs:[],outputs:[{name:"",type:"tuple[]",internalType:"struct BTCVaultTypes.AddressBTCKeyPair[]",components:[{name:"ethAddress",type:"address",internalType:"address"},{name:"btcPubKey",type:"bytes32",internalType:"bytes32"}]}],stateMutability:"view"},{type:"function",name:"latestUniversalChallengersVersion",inputs:[],outputs:[{name:"",type:"uint16",internalType:"uint16"}],stateMutability:"view"}],K=new Set(Object.values(f.DaemonStatus)),Te=200;function o(n){var e;return((e=JSON.stringify(n))==null?void 0:e.slice(0,Te))??"undefined"}const xe="The vault provider returned an unexpected response. Please try again or contact support.";class a extends Error{constructor(t){super(xe);l(this,"detail");this.name="VpResponseValidationError",this.detail=t}}const A=64;function _(n){return typeof n=="string"&&n.length>0&&g.HEX_RE.test(n)}function Z(n){return typeof n=="string"&&n.length>0}function ee(n,e){if(!_(n))throw new a(`VP response validation failed: "${e}" must be a non-empty hex string, got ${o(n)}`)}function w(n,e){if(!Z(n))throw new a(`VP response validation failed: "${e}" must be a non-empty string, got ${o(n)}`)}function te(n,e){if(!_(n)||n.length!==u.X_ONLY_PUBKEY_HEX_LEN&&n.length!==u.COMPRESSED_PUBKEY_HEX_LEN)throw new a(`VP response validation failed: "${e}" must be a ${u.X_ONLY_PUBKEY_HEX_LEN} or ${u.COMPRESSED_PUBKEY_HEX_LEN}-char hex string (BTC pubkey), got ${o(n)}`)}function Ae(n){const e=n.presigning;if(e==null)return;if(typeof e!="object"||Array.isArray(e))throw new a('VP response validation failed: "progress.presigning" must be an object if present');const t=e;if(t.depositor_graph_created!==void 0&&typeof t.depositor_graph_created!="boolean")throw new a(`VP response validation failed: "progress.presigning.depositor_graph_created" must be a boolean if present, got ${o(t.depositor_graph_created)}`);if(t.vk_challenger_presigning_completed!==void 0&&typeof t.vk_challenger_presigning_completed!="number")throw new a(`VP response validation failed: "progress.presigning.vk_challenger_presigning_completed" must be a number if present, got ${o(t.vk_challenger_presigning_completed)}`);if(t.vk_challenger_presigning_total!==void 0&&typeof t.vk_challenger_presigning_total!="number")throw new a(`VP response validation failed: "progress.presigning.vk_challenger_presigning_total" must be a number if present, got ${o(t.vk_challenger_presigning_total)}`)}function Ve(n){if(n===null||typeof n!="object")throw new a("VP response validation failed: getPeginStatus response is not an object");const e=n;if(!_(e.pegin_txid)||e.pegin_txid.length!==A)throw new a(`VP response validation failed: "pegin_txid" must be a ${A}-char hex string (txid), got ${o(e.pegin_txid)}`);if(typeof e.status!="string")throw new a('VP response validation failed: "status" must be a string');if(!K.has(e.status))throw new a(`VP response validation failed: unrecognized status "${e.status}". Expected one of: ${[...K].join(", ")}`);if(e.progress===null||typeof e.progress!="object"||Array.isArray(e.progress))throw new a('VP response validation failed: "progress" must be an object');if(Ae(e.progress),typeof e.health_info!="string")throw new a('VP response validation failed: "health_info" must be a string');if(e.last_error!==void 0&&typeof e.last_error!="string")throw new a(`VP response validation failed: "last_error" must be a string if present, got ${o(e.last_error)}`)}function Ee(n){if(n===null||typeof n!="object")throw new a("VP response validation failed: requestDepositorPresignTransactions response is not an object");const e=n;if(!Array.isArray(e.txs))throw new a('VP response validation failed: "txs" must be an array');for(let t=0;t<e.txs.length;t++)$e(e.txs[t],`txs[${t}]`);if(e.depositor_graph===null||typeof e.depositor_graph!="object")throw new a('VP response validation failed: "depositor_graph" must be an object');Ie(e.depositor_graph)}function m(n,e){if(n===null||typeof n!="object")throw new a(`VP response validation failed: "${e}" must be an object`);ee(n.tx_hex,`${e}.tx_hex`)}function $e(n,e){if(n===null||typeof n!="object")throw new a(`VP response validation failed: "${e}" must be an object`);const t=n;te(t.claimer_pubkey,`${e}.claimer_pubkey`),m(t.claim_tx,`${e}.claim_tx`),m(t.assert_tx,`${e}.assert_tx`),m(t.payout_tx,`${e}.payout_tx`),w(t.payout_psbt,`${e}.payout_psbt`)}function ke(n,e){if(n===null||typeof n!="object")throw new a(`VP response validation failed: "${e}" must be an object`);const t=n;w(t.wots_pks_json,`${e}.wots_pks_json`),w(t.gc_wots_keys_json,`${e}.gc_wots_keys_json`)}function Ce(n,e){if(n===null||typeof n!="object")throw new a(`VP response validation failed: "${e}" must be an object`);const t=n;if(te(t.challenger_pubkey,`${e}.challenger_pubkey`),m(t.challenge_assert_x_tx,`${e}.challenge_assert_x_tx`),m(t.challenge_assert_y_tx,`${e}.challenge_assert_y_tx`),m(t.nopayout_tx,`${e}.nopayout_tx`),w(t.nopayout_psbt,`${e}.nopayout_psbt`),!Array.isArray(t.challenge_assert_connectors))throw new a(`VP response validation failed: "${e}.challenge_assert_connectors" must be an array`);for(let r=0;r<t.challenge_assert_connectors.length;r++)ke(t.challenge_assert_connectors[r],`${e}.challenge_assert_connectors[${r}]`);if(!Array.isArray(t.output_label_hashes))throw new a(`VP response validation failed: "${e}.output_label_hashes" must be an array`);for(let r=0;r<t.output_label_hashes.length;r++)ee(t.output_label_hashes[r],`${e}.output_label_hashes[${r}]`)}function ne(n){if(n===null||typeof n!="object")throw new a("VP response validation failed: requestDepositorClaimerArtifacts response is not an object");const e=n;if(!Z(e.tx_graph_json))throw new a(`VP response validation failed: "tx_graph_json" must be a non-empty string, got ${o(e.tx_graph_json)}`);if(!_(e.verifying_key_hex))throw new a(`VP response validation failed: "verifying_key_hex" must be a non-empty hex string, got ${o(e.verifying_key_hex)}`);if(e.babe_sessions===null||typeof e.babe_sessions!="object")throw new a('VP response validation failed: "babe_sessions" must be an object');for(const[t,r]of Object.entries(e.babe_sessions)){if(r===null||typeof r!="object")throw new a(`VP response validation failed: "babe_sessions.${t}" must be an object`);const s=r;if(!_(s.decryptor_artifacts_hex))throw new a(`VP response validation failed: "babe_sessions.${t}.decryptor_artifacts_hex" must be a non-empty hex string, got ${o(s.decryptor_artifacts_hex)}`)}}function Se(n){if(n===null||typeof n!="object")throw new a("VP response validation failed: getPegoutStatus response is not an object");const e=n;if(!_(e.pegin_txid)||e.pegin_txid.length!==A)throw new a(`VP response validation failed: "pegin_txid" must be a ${A}-char hex string (txid), got ${o(e.pegin_txid)}`);if(typeof e.found!="boolean")throw new a(`VP response validation failed: "found" must be a boolean, got ${o(e.found)}`);if(e.claimer!==void 0){if(e.claimer===null||typeof e.claimer!="object")throw new a('VP response validation failed: "claimer" must be an object if present');const t=e.claimer;if(typeof t.status!="string")throw new a(`VP response validation failed: "claimer.status" must be a string, got ${o(t.status)}`);if(typeof t.failed!="boolean")throw new a(`VP response validation failed: "claimer.failed" must be a boolean, got ${o(t.failed)}`)}if(e.challenger!==void 0){if(e.challenger===null||typeof e.challenger!="object")throw new a('VP response validation failed: "challenger" must be an object if present');const t=e.challenger;if(typeof t.status!="string")throw new a(`VP response validation failed: "challenger.status" must be a string, got ${o(t.status)}`)}}function Ie(n){if(m(n.claim_tx,"depositor_graph.claim_tx"),m(n.assert_tx,"depositor_graph.assert_tx"),m(n.payout_tx,"depositor_graph.payout_tx"),w(n.payout_psbt,"depositor_graph.payout_psbt"),!Array.isArray(n.challenger_presign_data))throw new a('VP response validation failed: "depositor_graph.challenger_presign_data" must be an array');for(let e=0;e<n.challenger_presign_data.length;e++)Ce(n.challenger_presign_data[e],`depositor_graph.challenger_presign_data[${e}]`);if(typeof n.offchain_params_version!="number")throw new a('VP response validation failed: "depositor_graph.offchain_params_version" must be a number')}const Be=6e4;class re{constructor(e,t){l(this,"client");const r={baseUrl:e,timeout:(t==null?void 0:t.timeout)??Be,retries:t==null?void 0:t.retries,retryDelay:t==null?void 0:t.retryDelay,retryableFor:t==null?void 0:t.retryableFor,headers:t==null?void 0:t.headers,tokenProvider:t==null?void 0:t.tokenProvider,maxResponseBytes:t==null?void 0:t.maxResponseBytes};this.client=new f.JsonRpcClient(r)}async requestDepositorPresignTransactions(e,t){const r=await this.client.call("vaultProvider_requestDepositorPresignTransactions",e,t);return Ee(r),r}async submitDepositorPresignatures(e,t){return this.client.call("vaultProvider_submitDepositorPresignatures",e,t)}async submitDepositorWotsKey(e,t){return this.client.call("vaultProvider_submitDepositorWotsKey",e,t)}async requestDepositorClaimerArtifacts(e,t){const r=await this.client.call("vaultProvider_requestDepositorClaimerArtifacts",e,t);return ne(r),r}async getPeginStatus(e,t){const r=await this.client.call("vaultProvider_getPeginStatus",e,t);return Ve(r),r}async getPegoutStatus(e,t){const r=await this.client.call("vaultProvider_getPegoutStatus",e,t);return Se(r),r}}const Re="BIP0322-signed-message",Oe="TapTweak",ie=32,Ne=64;function se(n,e){const t=new TextEncoder().encode(n),r=F.sha256(t),s=new Uint8Array(r.length*2+e.length);return s.set(r,0),s.set(r,r.length),s.set(e,r.length*2),F.sha256(s)}function He(n){if(n.length!==ie)return null;const e=se(Oe,n),t=$.xOnlyPointAddTweak(n,e);return t?t.xOnlyPubkey:null}function Fe(n,e,t){if(e.length!==ie||t.length!==Ne)return!1;try{const r=se(Re,n),s=P.payments.p2tr({internalPubkey:b.Buffer.from(e)});if(!s.output)return!1;const i=s.output,c=0,y=new P.Transaction;y.version=0,y.locktime=0;const S=b.Buffer.concat([b.Buffer.from([0,32]),b.Buffer.from(r)]);y.addInput(b.Buffer.alloc(32,0),4294967295,0,S),y.addOutput(i,c);const d=new P.Transaction;d.version=0,d.locktime=0;const I=y.getHash();d.addInput(I,0,0),d.addOutput(b.Buffer.from([106]),c);const N=d.hashForWitnessV1(0,[i],[c],P.Transaction.SIGHASH_DEFAULT),H=He(e);return H?$.verifySchnorr(N,H,t):!1}catch{return!1}}function V(n,e){const t=(n&7)<<5,r=typeof e=="bigint"?e:BigInt(e);if(r<0n)throw new Error("cborHead: negative argument");if(r<24n)return new Uint8Array([t|Number(r)]);if(r<0x100n)return new Uint8Array([t|24,Number(r)]);if(r<0x10000n){const i=Number(r);return new Uint8Array([t|25,i>>>8&255,i&255])}if(r<0x100000000n){const i=Number(r);return new Uint8Array([t|26,i>>>24&255,i>>>16&255,i>>>8&255,i&255])}const s=new Uint8Array(9);s[0]=t|27;for(let i=7;i>=0;i--)s[1+i]=Number(r>>BigInt((7-i)*8))&255;return s}function ae(...n){const e=n.reduce((s,i)=>s+i.length,0),t=new Uint8Array(e);let r=0;for(const s of n)t.set(s,r),r+=s.length;return t}function D(n){const t=[V(4,n.length)];for(const r of n)t.push(V(0,r));return ae(...t)}function Ue(n,e,t){if(!Number.isSafeInteger(t)||t<0)throw new Error(`encodeServerIdentityPayload: expires_at must be a non-negative safe integer, got ${t}`);const r=V(4,3),s=D(n),i=D(e),c=V(0,t);return ae(r,s,i,c)}const Ke=new TextEncoder().encode("btc-auth.server-identity.v1");class p extends Error{constructor(e,t){super(e),this.reason=t,this.name="ServerIdentityError"}}function v(n){const e=new Uint8Array(n.length/2);for(let t=0;t<e.length;t++)e[t]=parseInt(n.slice(t*2,t*2+2),16);return e}function oe(n){const{proof:e,pinnedServerPubkey:t,now:r}=n,s=u.stripHexPrefix(t).toLowerCase();if(s.length!==u.X_ONLY_PUBKEY_HEX_LEN||!g.HEX_RE.test(s))throw new p(`pinnedServerPubkey must be 32-byte hex; got ${s.length} chars`,"invalid_pubkey_encoding");const i=u.stripHexPrefix(e.server_pubkey).toLowerCase();if(i.length!==u.X_ONLY_PUBKEY_HEX_LEN||!g.HEX_RE.test(i))throw new p(`server_pubkey must be 32-byte hex; got ${i.length} chars`,"invalid_pubkey_encoding");if(i!==s)throw new p(`server_pubkey does not match pinned value: expected ${s}, got ${i}`,"pinned_pubkey_mismatch");if(!Number.isSafeInteger(e.expires_at))throw new p(`expires_at must be a finite integer; got ${JSON.stringify(e.expires_at)}`,"invalid_expires_at");if(!Number.isSafeInteger(r))throw new p(`now must be a finite integer; got ${JSON.stringify(r)}`,"invalid_expires_at");if(e.expires_at<=r)throw new p(`server identity proof expired at ${e.expires_at}, now ${r}`,"expired");const c=u.stripHexPrefix(e.ephemeral_pubkey).toLowerCase();if(c.length!==u.COMPRESSED_PUBKEY_HEX_LEN||!g.HEX_RE.test(c))throw new p(`ephemeral_pubkey must be 33-byte compressed hex; got ${c.length} chars`,"invalid_ephemeral_pubkey");const y=c.slice(0,2);if(y!=="02"&&y!=="03")throw new p(`ephemeral_pubkey must be compressed (prefix 02/03); got ${y}`,"invalid_ephemeral_pubkey");const S=v(c);if(!$.isPoint(S))throw new p("ephemeral_pubkey is not a valid secp256k1 point","invalid_ephemeral_pubkey");const d=u.stripHexPrefix(e.signature).toLowerCase();if(d.length!==u.SCHNORR_SIG_HEX_LEN||!g.HEX_RE.test(d))throw new p(`signature must be 64-byte Schnorr hex; got ${d.length} chars`,"invalid_signature_encoding");const I=Ue(Ke,v(c),e.expires_at);if(!Fe(I,v(i),v(d)))throw new p("BIP-322 signature verification failed — ephemeral key is not attested by pinned server pubkey","signature_verification_failed")}const De=new Set(["vaultProvider_submitDepositorWotsKey","vaultProvider_submitDepositorPresignatures","vaultProvider_requestDepositorPresignTransactions"]),Me=6e4,R="auth_createDepositorToken";function ce(n,e){return new f.JsonRpcClient({baseUrl:n,timeout:Me,headers:e,retryableFor:t=>t===R})}const M=4102444800,je=30;class Xe{constructor(e){l(this,"client");l(this,"peginTxid");l(this,"authAnchorHex");l(this,"pinnedServerPubkey");l(this,"authGatedMethods");l(this,"refreshSkewSecs");l(this,"now");l(this,"cached",null);l(this,"inFlight",null);this.client=e.client,this.peginTxid=e.peginTxid,this.authAnchorHex=e.authAnchorHex,this.pinnedServerPubkey=e.pinnedServerPubkey,this.authGatedMethods=e.authGatedMethods,this.refreshSkewSecs=e.refreshSkewSecs??je,this.now=e.now??(()=>Math.floor(Date.now()/1e3))}async getToken(e){if(e===R||!this.authGatedMethods.has(e))return null;const t=this.cached;return t&&this.now()+this.refreshSkewSecs<t.expiresAt?t.token:(await this.acquireSingleFlight()).token}invalidate(){this.cached=null}setClient(e){this.client=e}acquireSingleFlight(){const e=this.inFlight;if(e)return e;const t=(async()=>{try{const r=await this.client.call(R,{pegin_txid:this.peginTxid,auth_anchor:this.authAnchorHex});if(oe({proof:r.server_identity,pinnedServerPubkey:this.pinnedServerPubkey,now:this.now()}),typeof r.token!="string"||r.token.length===0)throw new Error(`VpTokenProvider: invalid token in acquire response (expected non-empty string, got ${typeof r.token})`);const s=this.now();if(!Number.isSafeInteger(r.expires_at)||r.expires_at<=s||r.expires_at>M)throw new Error(`VpTokenProvider: invalid expires_at in acquire response (got ${JSON.stringify(r.expires_at)}; must be a safe integer in (${s}, ${M}])`);const i={token:r.token,expiresAt:r.expires_at};return this.cached=i,i}finally{this.inFlight=null}})();return this.inFlight=t,t}}class le{constructor(){l(this,"entries",new Map)}getOrCreate(e){const t=this.entries.get(e.peginTxid);if(t){if(t.authAnchorHex!==e.authAnchorHex)throw new Error(`VpTokenRegistry: peginTxid ${e.peginTxid} already bound to authAnchorHex ${t.authAnchorHex.slice(0,8)}…; got ${e.authAnchorHex.slice(0,8)}…`);if(t.pinnedServerPubkey!==e.pinnedServerPubkey)throw new Error(`VpTokenRegistry: peginTxid ${e.peginTxid} already bound to pinnedServerPubkey ${t.pinnedServerPubkey.slice(0,8)}…; got ${e.pinnedServerPubkey.slice(0,8)}…`);return t.provider.setClient(e.client),t.provider}const r=new Xe({client:e.client,peginTxid:e.peginTxid,authAnchorHex:e.authAnchorHex,pinnedServerPubkey:e.pinnedServerPubkey,authGatedMethods:De});return this.entries.set(e.peginTxid,{provider:r,authAnchorHex:e.authAnchorHex,pinnedServerPubkey:e.pinnedServerPubkey}),r}peek(e){var t;return(t=this.entries.get(e))==null?void 0:t.provider}release(e){this.entries.delete(e)}clear(){this.entries.clear()}get size(){return this.entries.size}}const O=new le;function Le(n){var r;const e=ce(n.baseUrl,(r=n.options)==null?void 0:r.headers),t=O.getOrCreate({client:e,peginTxid:n.peginTxid,authAnchorHex:n.authAnchorHex,pinnedServerPubkey:n.pinnedServerPubkey});return new re(n.baseUrl,{...n.options,tokenProvider:t})}function qe(n){O.getOrCreate({client:ce(n.baseUrl,n.headers),peginTxid:n.peginTxid,authAnchorHex:n.authAnchorHex,pinnedServerPubkey:n.pinnedServerPubkey})}async function Ge(n,e){const[t,r]=await n.multicall({contracts:[{address:e,abi:f.BTCVaultRegistryABI,functionName:"protocolParams"},{address:e,abi:f.BTCVaultRegistryABI,functionName:"applicationRegistry"}],allowFailure:!1});return{protocolParams:t,applicationRegistry:r}}const j=65535;function B(n){return{timelockAssert:n.timelockAssert,timelockChallengeAssert:n.timelockChallengeAssert,securityCouncilKeys:[...n.securityCouncilKeys],councilQuorum:n.councilQuorum,feeRate:n.feeRate,babeTotalInstances:n.babeTotalInstances,babeInstancesToFinalize:n.babeInstancesToFinalize,minVpCommissionBps:n.minVpCommissionBps,tRefund:n.tRefund,tStale:n.tStale,minPeginFeeRate:n.minPeginFeeRate,proverProgramVersion:n.proverProgramVersion,minPrepeginDepth:n.minPrepeginDepth}}function X(n){return{minimumPegInAmount:n.minimumPegInAmount,maxPegInAmount:n.maxPegInAmount,pegInAckTimeout:n.pegInAckTimeout,pegInActivationTimeout:n.pegInActivationTimeout,maxHtlcOutputCount:n.maxHtlcOutputCount}}function L(n){if(n>BigInt(j))throw new Error(`timelockAssert value ${n} exceeds uint16 max (${j})`);return Number(n)}class Ye{constructor(e,t){this.publicClient=e,this.contractAddress=t}async getTBVProtocolParams(){const e=await this.publicClient.readContract({address:this.contractAddress,abi:h,functionName:"getTBVProtocolParams"});return X(e)}async getLatestOffchainParams(){const e=await this.publicClient.readContract({address:this.contractAddress,abi:h,functionName:"getLatestOffchainParams"});return B(e)}async getOffchainParamsByVersion(e){const t=await this.publicClient.readContract({address:this.contractAddress,abi:h,functionName:"getOffchainParamsByVersion",args:[e]});return B(t)}async getLatestOffchainParamsVersion(){return await this.publicClient.readContract({address:this.contractAddress,abi:h,functionName:"latestOffchainParamsVersion"})}async getTimelockPeginByVersion(e){const t=await this.getOffchainParamsByVersion(e);return L(t.timelockAssert)}async getPegInConfiguration(){const e=await this.publicClient.multicall({contracts:[{address:this.contractAddress,abi:h,functionName:"getTBVProtocolParams"},{address:this.contractAddress,abi:h,functionName:"getLatestOffchainParams"}],allowFailure:!1}),t=X(e[0]),r=B(e[1]);return{minimumPegInAmount:t.minimumPegInAmount,maxPegInAmount:t.maxPegInAmount,pegInAckTimeout:t.pegInAckTimeout,pegInActivationTimeout:t.pegInActivationTimeout,maxHtlcOutputCount:t.maxHtlcOutputCount,timelockPegin:L(r.timelockAssert),timelockRefund:r.tRefund,minVpCommissionBps:r.minVpCommissionBps,offchainParams:r}}}function E(n){return n.map(e=>({ethAddress:e.ethAddress,btcPubKey:e.btcPubKey}))}class We{constructor(e,t){this.publicClient=e,this.contractAddress=t}async getVaultKeepersByVersion(e,t){const r=await this.publicClient.readContract({address:this.contractAddress,abi:T,functionName:"getVaultKeepersByVersion",args:[e,t]});return E(r)}async getCurrentVaultKeepers(e){const t=await this.publicClient.readContract({address:this.contractAddress,abi:T,functionName:"getCurrentVaultKeepers",args:[e]});return E(t)}async getCurrentVaultKeepersVersion(e){return await this.publicClient.readContract({address:this.contractAddress,abi:T,functionName:"getCurrentVaultKeepersVersion",args:[e]})}}class ze{constructor(e,t){this.publicClient=e,this.contractAddress=t}async getUniversalChallengersByVersion(e){const t=await this.publicClient.readContract({address:this.contractAddress,abi:h,functionName:"getUniversalChallengersByVersion",args:[e]});return E(t)}async getCurrentUniversalChallengers(){const e=await this.publicClient.readContract({address:this.contractAddress,abi:h,functionName:"getCurrentUniversalChallengers"});return E(e)}async getLatestUniversalChallengersVersion(){return await this.publicClient.readContract({address:this.contractAddress,abi:h,functionName:"latestUniversalChallengersVersion"})}}class Je{constructor(e,t){this.publicClient=e,this.contractAddress=t}async getVaultProviderBtcPubKey(e){const r=(await this.publicClient.readContract({address:this.contractAddress,abi:f.BTCVaultRegistryABI,functionName:"getVaultProviderBTCKey",args:[e]})).toLowerCase();if(!/^0x[0-9a-f]{64}$/.test(r))throw new Error(`getVaultProviderBTCKey returned an unexpected value (vp=${e}, length ${r.length}, prefix "${r.slice(0,2)}")`);const s=r.slice(2);if(!$.isXOnlyPoint(u.hexToUint8Array(s)))throw new Error(`getVaultProviderBTCKey returned a value that is not on the secp256k1 curve (vp=${e})`);return s}async getVaultBasicInfo(e){const t=await this.publicClient.readContract({address:this.contractAddress,abi:f.BTCVaultRegistryABI,functionName:"getBtcVaultBasicInfo",args:[e]});return{depositor:t.depositor,depositorBtcPubKey:t.depositorBtcPubKey,amount:t.amount,vaultProvider:t.vaultProvider,status:t.status,applicationEntryPoint:t.applicationEntryPoint,createdAt:t.createdAt}}async getVaultProtocolInfo(e){const t=await this.publicClient.readContract({address:this.contractAddress,abi:f.BTCVaultRegistryABI,functionName:"getBtcVaultProtocolInfo",args:[e]});return{depositorSignedPeginTx:t.depositorSignedPeginTx,universalChallengersVersion:t.universalChallengersVersion,appVaultKeepersVersion:t.appVaultKeepersVersion,offchainParamsVersion:t.offchainParamsVersion,verifiedAt:t.verifiedAt,depositorWotsPkHash:t.depositorWotsPkHash,hashlock:t.hashlock,htlcVout:t.htlcVout,depositorPopSignature:t.depositorPopSignature,prePeginTxHash:t.prePeginTxHash,vaultProviderCommissionBps:t.vaultProviderCommissionBps}}async getVaultData(e){const[t,r]=await Promise.all([this.getVaultBasicInfo(e),this.getVaultProtocolInfo(e)]);if(!r.depositorSignedPeginTx||r.depositorSignedPeginTx==="0x")throw new Error(`Vault ${e} not found on-chain or has no pegin transaction`);return{basic:t,protocol:r}}}exports.ApplicationRegistryABI=T;exports.MEMPOOL_API_URLS=J;exports.ProtocolParamsABI=h;exports.ServerIdentityError=p;exports.VaultProviderRpcClient=re;exports.ViemProtocolParamsReader=Ye;exports.ViemUniversalChallengerReader=ze;exports.ViemVaultKeeperReader=We;exports.ViemVaultRegistryReader=Je;exports.VpResponseValidationError=a;exports.VpTokenRegistry=le;exports.createAuthenticatedVpClient=Le;exports.getAddressTxs=Pe;exports.getAddressUtxos=_e;exports.getMempoolApiUrl=we;exports.getNetworkFees=ve;exports.getTxHex=fe;exports.getTxInfo=Q;exports.getUtxoInfo=be;exports.primeVpTokenRegistry=qe;exports.pushTx=me;exports.resolveProtocolAddresses=Ge;exports.validateRequestDepositorClaimerArtifactsResponse=ne;exports.verifyServerIdentity=oe;exports.vpTokenRegistry=O;
|
|
2
|
+
//# sourceMappingURL=vault-registry-reader-CKe9TbX6.cjs.map
|