@babylonlabs-io/ts-sdk 0.62.0 → 0.63.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{BTCVaultRegistry.abi-B3BLhpJ4.js → BTCVaultRegistry.abi-CJwWI2EO.js} +5 -1
- package/dist/{BTCVaultRegistry.abi-B3BLhpJ4.js.map → BTCVaultRegistry.abi-CJwWI2EO.js.map} +1 -1
- package/dist/{BTCVaultRegistry.abi-3VLWva2x.cjs → BTCVaultRegistry.abi-z7d_eP22.cjs} +2 -2
- package/dist/{BTCVaultRegistry.abi-3VLWva2x.cjs.map → BTCVaultRegistry.abi-z7d_eP22.cjs.map} +1 -1
- package/dist/{PeginManager-BLBB_vMl.cjs → PeginManager-n__EsW8a.cjs} +2 -2
- package/dist/{PeginManager-BLBB_vMl.cjs.map → PeginManager-n__EsW8a.cjs.map} +1 -1
- package/dist/{PeginManager-Dj6_tWRA.js → PeginManager-ozwQaRwj.js} +3 -3
- package/dist/{PeginManager-Dj6_tWRA.js.map → PeginManager-ozwQaRwj.js.map} +1 -1
- package/dist/{ProtocolParams.abi-CV938AYZ.js → ProtocolParams.abi-C0TSRaHV.js} +17 -1
- package/dist/{ProtocolParams.abi-CV938AYZ.js.map → ProtocolParams.abi-C0TSRaHV.js.map} +1 -1
- package/dist/{ProtocolParams.abi-C8U7BHCS.cjs → ProtocolParams.abi-CYZoV2EI.cjs} +2 -2
- package/dist/{ProtocolParams.abi-C8U7BHCS.cjs.map → ProtocolParams.abi-CYZoV2EI.cjs.map} +1 -1
- package/dist/batchPoll-6L5oToGr.cjs +2 -0
- package/dist/batchPoll-6L5oToGr.cjs.map +1 -0
- package/dist/{batchPoll-C3eKPYOC.js → batchPoll-cIxrSLLJ.js} +43 -21
- package/dist/batchPoll-cIxrSLLJ.js.map +1 -0
- package/dist/{buildAndBroadcastRefund-CH2awK6h.js → buildAndBroadcastRefund-DpfBZfLw.js} +2 -2
- package/dist/{buildAndBroadcastRefund-CH2awK6h.js.map → buildAndBroadcastRefund-DpfBZfLw.js.map} +1 -1
- package/dist/{buildAndBroadcastRefund-CYzhA_B8.cjs → buildAndBroadcastRefund-DsCd90qJ.cjs} +2 -2
- package/dist/{buildAndBroadcastRefund-CYzhA_B8.cjs.map → buildAndBroadcastRefund-DsCd90qJ.cjs.map} +1 -1
- package/dist/{errors-lMX8Q6zb.js → errors-BXzrXswV.js} +2 -2
- package/dist/{errors-lMX8Q6zb.js.map → errors-BXzrXswV.js.map} +1 -1
- package/dist/{errors-D2zp7Vzk.cjs → errors-BzBVottO.cjs} +2 -2
- package/dist/{errors-D2zp7Vzk.cjs.map → errors-BzBVottO.cjs.map} +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.js +7 -7
- package/dist/{mempoolApi-DC7pID6B.js → mempoolApi-BxSINXIB.js} +30 -54
- package/dist/mempoolApi-BxSINXIB.js.map +1 -0
- package/dist/mempoolApi-CXfr-L6x.cjs +2 -0
- package/dist/mempoolApi-CXfr-L6x.cjs.map +1 -0
- package/dist/tbv/core/clients/eth/protocol-params-reader.d.ts +11 -0
- package/dist/tbv/core/clients/eth/protocol-params-reader.d.ts.map +1 -1
- package/dist/tbv/core/clients/eth/types.d.ts +18 -6
- package/dist/tbv/core/clients/eth/types.d.ts.map +1 -1
- package/dist/tbv/core/clients/eth/vault-registry-reader.d.ts +0 -6
- package/dist/tbv/core/clients/eth/vault-registry-reader.d.ts.map +1 -1
- package/dist/tbv/core/clients/index.cjs +1 -1
- package/dist/tbv/core/clients/index.js +2 -2
- package/dist/tbv/core/contracts/abis/BTCVaultRegistry.abi.d.ts +4 -0
- package/dist/tbv/core/contracts/abis/BTCVaultRegistry.abi.d.ts.map +1 -1
- package/dist/tbv/core/contracts/abis/ProtocolParams.abi.d.ts +10 -0
- package/dist/tbv/core/contracts/abis/ProtocolParams.abi.d.ts.map +1 -1
- package/dist/tbv/core/contracts/index.cjs +1 -1
- package/dist/tbv/core/contracts/index.js +2 -2
- package/dist/tbv/core/index.cjs +1 -1
- package/dist/tbv/core/index.js +7 -7
- package/dist/tbv/core/managers/index.cjs +1 -1
- package/dist/tbv/core/managers/index.js +1 -1
- package/dist/tbv/core/services/index.cjs +1 -1
- package/dist/tbv/core/services/index.js +1 -1
- package/dist/tbv/index.cjs +1 -1
- package/dist/tbv/index.js +7 -7
- package/package.json +1 -1
- package/dist/batchPoll-C3eKPYOC.js.map +0 -1
- package/dist/batchPoll-CbbCcNZP.cjs +0 -2
- package/dist/batchPoll-CbbCcNZP.cjs.map +0 -1
- package/dist/mempoolApi-BxhMqJ4f.cjs +0 -2
- package/dist/mempoolApi-BxhMqJ4f.cjs.map +0 -1
- package/dist/mempoolApi-DC7pID6B.js.map +0 -1
|
@@ -8,7 +8,7 @@ import { h as B } from "./verifyScriptPathSchnorrSignature-XsICweGG.js";
|
|
|
8
8
|
import { s as n } from "./bitcoin-d9eaaZB_.js";
|
|
9
9
|
import { c as v } from "./fundPeginTransaction-B2wyjqp0.js";
|
|
10
10
|
import { f as F } from "./waitForTransactionReceiptSmartAware-lobLm0q0.js";
|
|
11
|
-
import { b as V } from "./PeginManager-
|
|
11
|
+
import { b as V } from "./PeginManager-ozwQaRwj.js";
|
|
12
12
|
const P = "DepositTermsRejectedError";
|
|
13
13
|
class $ extends Error {
|
|
14
14
|
constructor(s, i = "device-envelope") {
|
|
@@ -134,4 +134,4 @@ export {
|
|
|
134
134
|
U as i,
|
|
135
135
|
j as r
|
|
136
136
|
};
|
|
137
|
-
//# sourceMappingURL=errors-
|
|
137
|
+
//# sourceMappingURL=errors-BXzrXswV.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors-lMX8Q6zb.js","sources":["../src/tbv/core/deposit-terms/depositTermsErrors.ts","../src/tbv/core/deposit-terms/rebuildDepositTermsCore.ts","../src/tbv/core/wots/errors.ts"],"sourcesContent":["/**\n * Typed rejection contract for deposit-terms approval. Providers cannot import\n * this class (no dependency edge between the packages), so the cross-package\n * contract is the error SHAPE on {@link DepositTermsApprover}. Consumers land\n * with the first provider (#2109) and its app error mapping (#2110).\n *\n * @module deposit-terms/depositTermsErrors\n */\n\n/** The `name` value providers must set on envelope rejections (the wire contract). */\nexport const DEPOSIT_TERMS_REJECTED_ERROR_NAME = \"DepositTermsRejectedError\";\n\n/** Why the terms were rejected before approval. */\nexport type DepositTermsRejectionReason = \"device-envelope\";\n\n/** SDK-owned typed rejection thrown when deposit terms fail pre-approval validation. */\nexport class DepositTermsRejectedError extends Error {\n readonly reason: DepositTermsRejectionReason;\n\n constructor(\n message: string,\n reason: DepositTermsRejectionReason = \"device-envelope\",\n ) {\n super(message);\n this.name = DEPOSIT_TERMS_REJECTED_ERROR_NAME;\n this.reason = reason;\n }\n}\n\n/**\n * Guard for app-side error mapping. Matches `instanceof` OR the documented\n * `name` — providers and foreign realms throw structurally-conforming plain\n * errors that `instanceof` cannot see.\n */\nexport function isDepositTermsRejectedError(\n err: unknown,\n): err is DepositTermsRejectedError {\n if (err instanceof DepositTermsRejectedError) return true;\n if (typeof err !== \"object\" || err === null) return false;\n const shaped = err as { name?: unknown; reason?: unknown };\n // The documented provider shape REQUIRES the reason; a name-only match is\n // a contract violation and propagates unnormalized.\n return (\n shaped.name === DEPOSIT_TERMS_REJECTED_ERROR_NAME &&\n shaped.reason === \"device-envelope\"\n );\n}\n","/**\n * Pure core of the resume-broadcast DepositTerms rebuild (#2220 Part 2).\n *\n * Takes plain chain-derived data (the app orchestrator does the chain reads +\n * sibling discovery) and: (1) asserts sibling completeness against the funded\n * tx's auth-anchor OP_RETURN, (2) recomputes the amount-independent sizing\n * (depositorClaimValue, peginMaxFee, anchor) via WASM, (3) byte-matches each\n * HTLC output's value + scriptPubKey against the funded tx (Gate 1), then (4)\n * projects into DepositTerms. No chain access, no browser state — unit-testable.\n *\n * btc-vault is the protocol source of truth (`compute_min_htlc_value`,\n * `derive_challengers_for`).\n */\n\nimport {\n computeMinClaimValue,\n computeMinPeginFee,\n getPrePeginHtlcConnectorInfo,\n peginP2aAnchorOutput,\n} from \"@babylonlabs-io/babylon-tbv-rust-wasm\";\nimport { Transaction } from \"bitcoinjs-lib\";\n\nimport { findAuthAnchorOpReturn } from \"../managers/pegin/assertAuthAnchorOpReturn\";\nimport { assertEncodedHtlcOutputsMatch } from \"../primitives/psbt/assertWasmPeginSizing\";\nimport { stripHexPrefix } from \"../primitives/utils/bitcoin\";\nimport { MAX_REASONABLE_PEGIN_VBYTES } from \"../utils/fee/constants\";\nimport { calculateBtcTxHash } from \"../utils/transaction/btcTxHash\";\n\nimport { buildDepositTerms } from \"./buildDepositTerms\";\nimport type { DepositTerms } from \"./depositTerms\";\n\n/** One HTLC in the shared Pre-PegIn tx, ordered by (and contiguous in) htlcVout. */\nexport interface RebuildSibling {\n /** 32-byte hex hashlock (0x prefix optional), per-vault (feeds the HTLC scriptPubKey). */\n hashlock: string;\n /** btc-vault `pegin_amount` for this sibling (satoshis). */\n amount: bigint;\n}\n\nexport interface RebuildDepositTermsCoreInput {\n /** Stamped tx-graph version (NOT chain-active). */\n vaultCoreVersion: number;\n /** Sibling HTLCs ordered by htlcVout; index === htlcVout (asserted by the app). */\n siblings: readonly RebuildSibling[];\n /** Funded Pre-PegIn tx hex. Gate 0 (hash vs prepeginTxid) is SELF-verified below — callers need not pre-verify. */\n fundedPrePeginTxHex: string;\n\n // Stamped-version participant data (already resolved + sorted by the app).\n depositorBtcPubkey: string;\n vaultProviderBtcPubkey: string;\n vaultKeeperBtcPubkeys: readonly string[];\n universalChallengerBtcPubkeys: readonly string[];\n\n // Version-locked scalars.\n protocolFeeRate: bigint;\n minPeginFeeRate: bigint;\n councilQuorum: number;\n councilSize: number;\n timelockPegin: number;\n timelockAssert: number;\n timelockRefund: number;\n\n // Pass-through into DepositTerms.\n prepeginTxid: string;\n /** Funded-tx fee (Σin − Σout), computed by the app; the device's `prepegin_max_fee` bound. */\n prepeginMaxFee: bigint;\n maxAcceptableCommissionBps: number;\n\n /** WASM network descriptor for scriptPubKey derivation. */\n network: Parameters<typeof getPrePeginHtlcConnectorInfo>[0][\"network\"];\n}\n\nexport async function rebuildDepositTermsCore(\n input: RebuildDepositTermsCoreInput,\n): Promise<DepositTerms> {\n const siblingCount = input.siblings.length;\n if (siblingCount === 0) {\n throw new Error(\n \"rebuildDepositTermsCore: at least one sibling is required\",\n );\n }\n for (const [i, sibling] of input.siblings.entries()) {\n if (sibling.amount <= 0n) {\n throw new Error(\n `rebuildDepositTermsCore: sibling[${i}] has non-positive on-chain pegin ` +\n `amount ${sibling.amount}; the chain-read vault record is invalid. Resume refused.`,\n );\n }\n }\n if (input.prepeginMaxFee <= 0n) {\n throw new Error(\n `rebuildDepositTermsCore: prepeginMaxFee must be > 0, got ${input.prepeginMaxFee}`,\n );\n }\n\n // Gate 0, self-verified: everything below trusts these bytes, and a\n // substituted tx replicating the HTLC outputs would pass Gate 1 with a\n // different fee/txid.\n const expectedTxid = stripHexPrefix(input.prepeginTxid).toLowerCase();\n const actualTxid = stripHexPrefix(\n calculateBtcTxHash(input.fundedPrePeginTxHex),\n ).toLowerCase();\n if (actualTxid !== expectedTxid) {\n throw new Error(\n `Funded Pre-PegIn tx hashes to ${actualTxid}, expected ${expectedTxid} ` +\n `(on-chain prepeginTxid). Resume refused.`,\n );\n }\n\n // Completeness anchor: the single auth-anchor OP_RETURN sits at vout === HTLC\n // count — the only guard against an indexer-lagged partial sibling set.\n const found = findAuthAnchorOpReturn(\n stripHexPrefix(input.fundedPrePeginTxHex),\n );\n if (found === undefined) {\n throw new Error(\n `Funded Pre-PegIn carries no single, unambiguous auth-anchor OP_RETURN ` +\n `commitment — it either predates auth anchoring or is malformed. The ` +\n `intent resume path requires the anchor to prove sibling completeness. ` +\n `Resume refused.`,\n );\n }\n if (found.vout !== siblingCount) {\n throw new Error(\n `Auth-anchor OP_RETURN at vout ${found.vout} does not match the ` +\n `discovered sibling count ${siblingCount}; the discovered sibling set ` +\n `does not cover this transaction's HTLC outputs (a lagging index can ` +\n `cause this — retry later). Resume refused.`,\n );\n }\n\n // Amount-independent sizing. Depositor-as-claimer: numLocalChallengers ===\n // numVks (VP excluded) — btc-vault graph.rs derive_challengers_for.\n const numVks = input.vaultKeeperBtcPubkeys.length;\n const numUcs = input.universalChallengerBtcPubkeys.length;\n const depositorClaimValue = await computeMinClaimValue(\n input.vaultCoreVersion,\n numVks,\n numUcs,\n input.councilQuorum,\n input.councilSize,\n input.protocolFeeRate,\n );\n const peginMaxFee = await computeMinPeginFee(\n input.vaultCoreVersion,\n numVks,\n numUcs,\n input.minPeginFeeRate,\n );\n const anchor = await peginP2aAnchorOutput(input.vaultCoreVersion);\n const anchorValue = anchor?.value ?? 0n;\n\n // Independent bounds on the WASM outputs (mirrors assertWasmPeginSizing):\n // Gate 1 only proves the DCV+fee+anchor SUM — these constrain the\n // decomposition the device is shown.\n if (depositorClaimValue <= 0n) {\n throw new Error(\n `WASM returned non-positive depositorClaimValue ${depositorClaimValue}; ` +\n `expected > 0. Resume refused.`,\n );\n }\n if (peginMaxFee <= 0n) {\n throw new Error(\n `WASM returned non-positive peginMaxFee ${peginMaxFee}; expected > 0. ` +\n `Resume refused.`,\n );\n }\n // Explicit anchor check: the sum bound alone would let a negative anchor\n // offset an inflated peginMaxFee (kept local, not inherited from the facade).\n if (anchorValue < 0n) {\n throw new Error(\n `WASM returned negative P2A anchor value ${anchorValue}. Resume refused.`,\n );\n }\n const impliedReserve = peginMaxFee + anchorValue;\n const maxImpliedReserve = input.minPeginFeeRate * MAX_REASONABLE_PEGIN_VBYTES;\n if (impliedReserve <= 0n || impliedReserve > maxImpliedReserve) {\n throw new Error(\n `WASM implied PegIn reserve ${impliedReserve} sat is outside ` +\n `(0, ${maxImpliedReserve}] (minPeginFeeRate=${input.minPeginFeeRate} × ` +\n `${MAX_REASONABLE_PEGIN_VBYTES} vbytes). Resume refused.`,\n );\n }\n\n // Gate 1: per sibling, value = amount + DCV + peginMaxFee + anchor (btc-vault\n // compute_min_htlc_value) + scriptPubKey from the on-chain hashlock,\n // byte-matched against outputs 0..N-1.\n const expectedHtlcValues = input.siblings.map(\n (s) => s.amount + depositorClaimValue + peginMaxFee + anchorValue,\n );\n const expectedHtlcScriptPubKeys = await Promise.all(\n input.siblings.map(async (s) => {\n const connector = await getPrePeginHtlcConnectorInfo({\n txGraphVersion: input.vaultCoreVersion,\n depositorPubkey: input.depositorBtcPubkey,\n vaultProviderPubkey: input.vaultProviderBtcPubkey,\n vaultKeeperPubkeys: [...input.vaultKeeperBtcPubkeys],\n universalChallengerPubkeys: [...input.universalChallengerBtcPubkeys],\n hashlock: stripHexPrefix(s.hashlock),\n timelockRefund: input.timelockRefund,\n network: input.network,\n });\n return connector.scriptPubKey;\n }),\n );\n const fundedOutputs = Transaction.fromHex(\n stripHexPrefix(input.fundedPrePeginTxHex),\n ).outs.map((o) => ({ value: o.value, script: o.script }));\n assertEncodedHtlcOutputsMatch(\n fundedOutputs,\n expectedHtlcValues,\n expectedHtlcScriptPubKeys,\n );\n\n return buildDepositTerms({\n vaultCoreVersion: input.vaultCoreVersion,\n protocolFeeRate: input.protocolFeeRate,\n timelockPegin: input.timelockPegin,\n timelockAssert: input.timelockAssert,\n timelockRefund: input.timelockRefund,\n prepeginTxid: input.prepeginTxid,\n prepeginMaxFee: input.prepeginMaxFee,\n vaultProviderBtcPubkey: input.vaultProviderBtcPubkey,\n vaultKeeperBtcPubkeys: input.vaultKeeperBtcPubkeys,\n universalChallengerBtcPubkeys: input.universalChallengerBtcPubkeys,\n maxAcceptableCommissionBps: input.maxAcceptableCommissionBps,\n peginAmounts: input.siblings.map((s) => s.amount),\n depositorClaimValue,\n peginMaxFee,\n });\n}\n","/**\n * Check whether an error from the vault provider indicates that the\n * submitted WOTS public key hash does not match the on-chain\n * commitment. This signals that the wrong wallet is connected (its\n * `deriveContextHash` produces a different vault root and therefore\n * different WOTS keys).\n */\nexport function isWotsMismatchError(error: unknown): boolean {\n const msg = (\n error instanceof Error\n ? error.message\n : typeof error === \"string\"\n ? error\n : \"\"\n ).toLowerCase();\n\n return (\n msg.includes(\"wots\") &&\n msg.includes(\"hash\") &&\n msg.includes(\"does not match\")\n );\n}\n"],"names":["DEPOSIT_TERMS_REJECTED_ERROR_NAME","DepositTermsRejectedError","message","reason","__publicField","isDepositTermsRejectedError","err","shaped","rebuildDepositTermsCore","input","siblingCount","i","sibling","expectedTxid","stripHexPrefix","actualTxid","calculateBtcTxHash","found","findAuthAnchorOpReturn","numVks","numUcs","depositorClaimValue","computeMinClaimValue","peginMaxFee","computeMinPeginFee","anchor","peginP2aAnchorOutput","anchorValue","impliedReserve","maxImpliedReserve","MAX_REASONABLE_PEGIN_VBYTES","expectedHtlcValues","s","expectedHtlcScriptPubKeys","getPrePeginHtlcConnectorInfo","fundedOutputs","Transaction","assertEncodedHtlcOutputsMatch","buildDepositTerms","isWotsMismatchError","error","msg"],"mappings":";;;;;;;;;;;AAUO,MAAMA,IAAoC;AAM1C,MAAMC,UAAkC,MAAM;AAAA,EAGnD,YACEC,GACAC,IAAsC,mBACtC;AACA,UAAMD,CAAO;AANN,IAAAE,EAAA;AAOP,SAAK,OAAOJ,GACZ,KAAK,SAASG;AAAA,EAChB;AACF;AAOO,SAASE,EACdC,GACkC;AAClC,MAAIA,aAAeL,EAA2B,QAAO;AACrD,MAAI,OAAOK,KAAQ,YAAYA,MAAQ,KAAM,QAAO;AACpD,QAAMC,IAASD;AAGf,SACEC,EAAO,SAASP,KAChBO,EAAO,WAAW;AAEtB;AC0BA,eAAsBC,EACpBC,GACuB;AACvB,QAAMC,IAAeD,EAAM,SAAS;AACpC,MAAIC,MAAiB;AACnB,UAAM,IAAI;AAAA,MACR;AAAA,IAAA;AAGJ,aAAW,CAACC,GAAGC,CAAO,KAAKH,EAAM,SAAS;AACxC,QAAIG,EAAQ,UAAU;AACpB,YAAM,IAAI;AAAA,QACR,oCAAoCD,CAAC,4CACzBC,EAAQ,MAAM;AAAA,MAAA;AAIhC,MAAIH,EAAM,kBAAkB;AAC1B,UAAM,IAAI;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AAA,EAAA,CACD;AACH;AC/NO,SAASgB,EAAoBC,GAAyB;AAC3D,QAAMC,KACJD,aAAiB,QACbA,EAAM,UACN,OAAOA,KAAU,WACfA,IACA,IACN,YAAA;AAEF,SACEC,EAAI,SAAS,MAAM,KACnBA,EAAI,SAAS,MAAM,KACnBA,EAAI,SAAS,gBAAgB;AAEjC;"}
|
|
1
|
+
{"version":3,"file":"errors-BXzrXswV.js","sources":["../src/tbv/core/deposit-terms/depositTermsErrors.ts","../src/tbv/core/deposit-terms/rebuildDepositTermsCore.ts","../src/tbv/core/wots/errors.ts"],"sourcesContent":["/**\n * Typed rejection contract for deposit-terms approval. Providers cannot import\n * this class (no dependency edge between the packages), so the cross-package\n * contract is the error SHAPE on {@link DepositTermsApprover}. Consumers land\n * with the first provider (#2109) and its app error mapping (#2110).\n *\n * @module deposit-terms/depositTermsErrors\n */\n\n/** The `name` value providers must set on envelope rejections (the wire contract). */\nexport const DEPOSIT_TERMS_REJECTED_ERROR_NAME = \"DepositTermsRejectedError\";\n\n/** Why the terms were rejected before approval. */\nexport type DepositTermsRejectionReason = \"device-envelope\";\n\n/** SDK-owned typed rejection thrown when deposit terms fail pre-approval validation. */\nexport class DepositTermsRejectedError extends Error {\n readonly reason: DepositTermsRejectionReason;\n\n constructor(\n message: string,\n reason: DepositTermsRejectionReason = \"device-envelope\",\n ) {\n super(message);\n this.name = DEPOSIT_TERMS_REJECTED_ERROR_NAME;\n this.reason = reason;\n }\n}\n\n/**\n * Guard for app-side error mapping. Matches `instanceof` OR the documented\n * `name` — providers and foreign realms throw structurally-conforming plain\n * errors that `instanceof` cannot see.\n */\nexport function isDepositTermsRejectedError(\n err: unknown,\n): err is DepositTermsRejectedError {\n if (err instanceof DepositTermsRejectedError) return true;\n if (typeof err !== \"object\" || err === null) return false;\n const shaped = err as { name?: unknown; reason?: unknown };\n // The documented provider shape REQUIRES the reason; a name-only match is\n // a contract violation and propagates unnormalized.\n return (\n shaped.name === DEPOSIT_TERMS_REJECTED_ERROR_NAME &&\n shaped.reason === \"device-envelope\"\n );\n}\n","/**\n * Pure core of the resume-broadcast DepositTerms rebuild (#2220 Part 2).\n *\n * Takes plain chain-derived data (the app orchestrator does the chain reads +\n * sibling discovery) and: (1) asserts sibling completeness against the funded\n * tx's auth-anchor OP_RETURN, (2) recomputes the amount-independent sizing\n * (depositorClaimValue, peginMaxFee, anchor) via WASM, (3) byte-matches each\n * HTLC output's value + scriptPubKey against the funded tx (Gate 1), then (4)\n * projects into DepositTerms. No chain access, no browser state — unit-testable.\n *\n * btc-vault is the protocol source of truth (`compute_min_htlc_value`,\n * `derive_challengers_for`).\n */\n\nimport {\n computeMinClaimValue,\n computeMinPeginFee,\n getPrePeginHtlcConnectorInfo,\n peginP2aAnchorOutput,\n} from \"@babylonlabs-io/babylon-tbv-rust-wasm\";\nimport { Transaction } from \"bitcoinjs-lib\";\n\nimport { findAuthAnchorOpReturn } from \"../managers/pegin/assertAuthAnchorOpReturn\";\nimport { assertEncodedHtlcOutputsMatch } from \"../primitives/psbt/assertWasmPeginSizing\";\nimport { stripHexPrefix } from \"../primitives/utils/bitcoin\";\nimport { MAX_REASONABLE_PEGIN_VBYTES } from \"../utils/fee/constants\";\nimport { calculateBtcTxHash } from \"../utils/transaction/btcTxHash\";\n\nimport { buildDepositTerms } from \"./buildDepositTerms\";\nimport type { DepositTerms } from \"./depositTerms\";\n\n/** One HTLC in the shared Pre-PegIn tx, ordered by (and contiguous in) htlcVout. */\nexport interface RebuildSibling {\n /** 32-byte hex hashlock (0x prefix optional), per-vault (feeds the HTLC scriptPubKey). */\n hashlock: string;\n /** btc-vault `pegin_amount` for this sibling (satoshis). */\n amount: bigint;\n}\n\nexport interface RebuildDepositTermsCoreInput {\n /** Stamped tx-graph version (NOT chain-active). */\n vaultCoreVersion: number;\n /** Sibling HTLCs ordered by htlcVout; index === htlcVout (asserted by the app). */\n siblings: readonly RebuildSibling[];\n /** Funded Pre-PegIn tx hex. Gate 0 (hash vs prepeginTxid) is SELF-verified below — callers need not pre-verify. */\n fundedPrePeginTxHex: string;\n\n // Stamped-version participant data (already resolved + sorted by the app).\n depositorBtcPubkey: string;\n vaultProviderBtcPubkey: string;\n vaultKeeperBtcPubkeys: readonly string[];\n universalChallengerBtcPubkeys: readonly string[];\n\n // Version-locked scalars.\n protocolFeeRate: bigint;\n minPeginFeeRate: bigint;\n councilQuorum: number;\n councilSize: number;\n timelockPegin: number;\n timelockAssert: number;\n timelockRefund: number;\n\n // Pass-through into DepositTerms.\n prepeginTxid: string;\n /** Funded-tx fee (Σin − Σout), computed by the app; the device's `prepegin_max_fee` bound. */\n prepeginMaxFee: bigint;\n maxAcceptableCommissionBps: number;\n\n /** WASM network descriptor for scriptPubKey derivation. */\n network: Parameters<typeof getPrePeginHtlcConnectorInfo>[0][\"network\"];\n}\n\nexport async function rebuildDepositTermsCore(\n input: RebuildDepositTermsCoreInput,\n): Promise<DepositTerms> {\n const siblingCount = input.siblings.length;\n if (siblingCount === 0) {\n throw new Error(\n \"rebuildDepositTermsCore: at least one sibling is required\",\n );\n }\n for (const [i, sibling] of input.siblings.entries()) {\n if (sibling.amount <= 0n) {\n throw new Error(\n `rebuildDepositTermsCore: sibling[${i}] has non-positive on-chain pegin ` +\n `amount ${sibling.amount}; the chain-read vault record is invalid. Resume refused.`,\n );\n }\n }\n if (input.prepeginMaxFee <= 0n) {\n throw new Error(\n `rebuildDepositTermsCore: prepeginMaxFee must be > 0, got ${input.prepeginMaxFee}`,\n );\n }\n\n // Gate 0, self-verified: everything below trusts these bytes, and a\n // substituted tx replicating the HTLC outputs would pass Gate 1 with a\n // different fee/txid.\n const expectedTxid = stripHexPrefix(input.prepeginTxid).toLowerCase();\n const actualTxid = stripHexPrefix(\n calculateBtcTxHash(input.fundedPrePeginTxHex),\n ).toLowerCase();\n if (actualTxid !== expectedTxid) {\n throw new Error(\n `Funded Pre-PegIn tx hashes to ${actualTxid}, expected ${expectedTxid} ` +\n `(on-chain prepeginTxid). Resume refused.`,\n );\n }\n\n // Completeness anchor: the single auth-anchor OP_RETURN sits at vout === HTLC\n // count — the only guard against an indexer-lagged partial sibling set.\n const found = findAuthAnchorOpReturn(\n stripHexPrefix(input.fundedPrePeginTxHex),\n );\n if (found === undefined) {\n throw new Error(\n `Funded Pre-PegIn carries no single, unambiguous auth-anchor OP_RETURN ` +\n `commitment — it either predates auth anchoring or is malformed. The ` +\n `intent resume path requires the anchor to prove sibling completeness. ` +\n `Resume refused.`,\n );\n }\n if (found.vout !== siblingCount) {\n throw new Error(\n `Auth-anchor OP_RETURN at vout ${found.vout} does not match the ` +\n `discovered sibling count ${siblingCount}; the discovered sibling set ` +\n `does not cover this transaction's HTLC outputs (a lagging index can ` +\n `cause this — retry later). Resume refused.`,\n );\n }\n\n // Amount-independent sizing. Depositor-as-claimer: numLocalChallengers ===\n // numVks (VP excluded) — btc-vault graph.rs derive_challengers_for.\n const numVks = input.vaultKeeperBtcPubkeys.length;\n const numUcs = input.universalChallengerBtcPubkeys.length;\n const depositorClaimValue = await computeMinClaimValue(\n input.vaultCoreVersion,\n numVks,\n numUcs,\n input.councilQuorum,\n input.councilSize,\n input.protocolFeeRate,\n );\n const peginMaxFee = await computeMinPeginFee(\n input.vaultCoreVersion,\n numVks,\n numUcs,\n input.minPeginFeeRate,\n );\n const anchor = await peginP2aAnchorOutput(input.vaultCoreVersion);\n const anchorValue = anchor?.value ?? 0n;\n\n // Independent bounds on the WASM outputs (mirrors assertWasmPeginSizing):\n // Gate 1 only proves the DCV+fee+anchor SUM — these constrain the\n // decomposition the device is shown.\n if (depositorClaimValue <= 0n) {\n throw new Error(\n `WASM returned non-positive depositorClaimValue ${depositorClaimValue}; ` +\n `expected > 0. Resume refused.`,\n );\n }\n if (peginMaxFee <= 0n) {\n throw new Error(\n `WASM returned non-positive peginMaxFee ${peginMaxFee}; expected > 0. ` +\n `Resume refused.`,\n );\n }\n // Explicit anchor check: the sum bound alone would let a negative anchor\n // offset an inflated peginMaxFee (kept local, not inherited from the facade).\n if (anchorValue < 0n) {\n throw new Error(\n `WASM returned negative P2A anchor value ${anchorValue}. Resume refused.`,\n );\n }\n const impliedReserve = peginMaxFee + anchorValue;\n const maxImpliedReserve = input.minPeginFeeRate * MAX_REASONABLE_PEGIN_VBYTES;\n if (impliedReserve <= 0n || impliedReserve > maxImpliedReserve) {\n throw new Error(\n `WASM implied PegIn reserve ${impliedReserve} sat is outside ` +\n `(0, ${maxImpliedReserve}] (minPeginFeeRate=${input.minPeginFeeRate} × ` +\n `${MAX_REASONABLE_PEGIN_VBYTES} vbytes). Resume refused.`,\n );\n }\n\n // Gate 1: per sibling, value = amount + DCV + peginMaxFee + anchor (btc-vault\n // compute_min_htlc_value) + scriptPubKey from the on-chain hashlock,\n // byte-matched against outputs 0..N-1.\n const expectedHtlcValues = input.siblings.map(\n (s) => s.amount + depositorClaimValue + peginMaxFee + anchorValue,\n );\n const expectedHtlcScriptPubKeys = await Promise.all(\n input.siblings.map(async (s) => {\n const connector = await getPrePeginHtlcConnectorInfo({\n txGraphVersion: input.vaultCoreVersion,\n depositorPubkey: input.depositorBtcPubkey,\n vaultProviderPubkey: input.vaultProviderBtcPubkey,\n vaultKeeperPubkeys: [...input.vaultKeeperBtcPubkeys],\n universalChallengerPubkeys: [...input.universalChallengerBtcPubkeys],\n hashlock: stripHexPrefix(s.hashlock),\n timelockRefund: input.timelockRefund,\n network: input.network,\n });\n return connector.scriptPubKey;\n }),\n );\n const fundedOutputs = Transaction.fromHex(\n stripHexPrefix(input.fundedPrePeginTxHex),\n ).outs.map((o) => ({ value: o.value, script: o.script }));\n assertEncodedHtlcOutputsMatch(\n fundedOutputs,\n expectedHtlcValues,\n expectedHtlcScriptPubKeys,\n );\n\n return buildDepositTerms({\n vaultCoreVersion: input.vaultCoreVersion,\n protocolFeeRate: input.protocolFeeRate,\n timelockPegin: input.timelockPegin,\n timelockAssert: input.timelockAssert,\n timelockRefund: input.timelockRefund,\n prepeginTxid: input.prepeginTxid,\n prepeginMaxFee: input.prepeginMaxFee,\n vaultProviderBtcPubkey: input.vaultProviderBtcPubkey,\n vaultKeeperBtcPubkeys: input.vaultKeeperBtcPubkeys,\n universalChallengerBtcPubkeys: input.universalChallengerBtcPubkeys,\n maxAcceptableCommissionBps: input.maxAcceptableCommissionBps,\n peginAmounts: input.siblings.map((s) => s.amount),\n depositorClaimValue,\n peginMaxFee,\n });\n}\n","/**\n * Check whether an error from the vault provider indicates that the\n * submitted WOTS public key hash does not match the on-chain\n * commitment. This signals that the wrong wallet is connected (its\n * `deriveContextHash` produces a different vault root and therefore\n * different WOTS keys).\n */\nexport function isWotsMismatchError(error: unknown): boolean {\n const msg = (\n error instanceof Error\n ? error.message\n : typeof error === \"string\"\n ? error\n : \"\"\n ).toLowerCase();\n\n return (\n msg.includes(\"wots\") &&\n msg.includes(\"hash\") &&\n msg.includes(\"does not match\")\n );\n}\n"],"names":["DEPOSIT_TERMS_REJECTED_ERROR_NAME","DepositTermsRejectedError","message","reason","__publicField","isDepositTermsRejectedError","err","shaped","rebuildDepositTermsCore","input","siblingCount","i","sibling","expectedTxid","stripHexPrefix","actualTxid","calculateBtcTxHash","found","findAuthAnchorOpReturn","numVks","numUcs","depositorClaimValue","computeMinClaimValue","peginMaxFee","computeMinPeginFee","anchor","peginP2aAnchorOutput","anchorValue","impliedReserve","maxImpliedReserve","MAX_REASONABLE_PEGIN_VBYTES","expectedHtlcValues","s","expectedHtlcScriptPubKeys","getPrePeginHtlcConnectorInfo","fundedOutputs","Transaction","assertEncodedHtlcOutputsMatch","buildDepositTerms","isWotsMismatchError","error","msg"],"mappings":";;;;;;;;;;;AAUO,MAAMA,IAAoC;AAM1C,MAAMC,UAAkC,MAAM;AAAA,EAGnD,YACEC,GACAC,IAAsC,mBACtC;AACA,UAAMD,CAAO;AANN,IAAAE,EAAA;AAOP,SAAK,OAAOJ,GACZ,KAAK,SAASG;AAAA,EAChB;AACF;AAOO,SAASE,EACdC,GACkC;AAClC,MAAIA,aAAeL,EAA2B,QAAO;AACrD,MAA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,IACAE;AAAA,EAAA,GAGKK,EAAkB;AAAA,IACvB,kBAAkB7B,EAAM;AAAA,IACxB,iBAAiBA,EAAM;AAAA,IACvB,eAAeA,EAAM;AAAA,IACrB,gBAAgBA,EAAM;AAAA,IACtB,gBAAgBA,EAAM;AAAA,IACtB,cAAcA,EAAM;AAAA,IACpB,gBAAgBA,EAAM;AAAA,IACtB,wBAAwBA,EAAM;AAAA,IAC9B,uBAAuBA,EAAM;AAAA,IAC7B,+BAA+BA,EAAM;AAAA,IACrC,4BAA4BA,EAAM;AAAA,IAClC,cAAcA,EAAM,SAAS,IAAI,CAACuB,MAAMA,EAAE,MAAM;AAAA,IAChD,qBAAAX;AAAA,IACA,aAAAE;AAAA,EAAA,CACD;AACH;AC/NO,SAASgB,EAAoBC,GAAyB;AAC3D,QAAMC,KACJD,aAAiB,QACbA,EAAM,UACN,OAAOA,KAAU,WACfA,IACA,IACN,YAAA;AAEF,SACEC,EAAI,SAAS,MAAM,KACnBA,EAAI,SAAS,MAAM,KACnBA,EAAI,SAAS,gBAAgB;AAEjC;"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var w=Object.defineProperty;var k=(e,r,t)=>r in e?w(e,r,{enumerable:!0,configurable:!0,writable:!0,value:t}):e[r]=t;var f=(e,r,t)=>k(e,typeof r!="symbol"?r+"":r,t);const u=require("@babylonlabs-io/babylon-tbv-rust-wasm"),C=require("bitcoinjs-lib"),y=require("./signPsbtsWithFallback-DbOmw8Ou.cjs"),A=require("./verifyScriptPathSchnorrSignature-B8zK1ctE.cjs"),n=require("./bitcoin-m84N5a8o.cjs"),b=require("./fundPeginTransaction-BLD8FRL9.cjs"),M=require("./waitForTransactionReceiptSmartAware-AgZ-3WV_.cjs"),B=require("./PeginManager-
|
|
2
|
-
//# sourceMappingURL=errors-
|
|
1
|
+
"use strict";var w=Object.defineProperty;var k=(e,r,t)=>r in e?w(e,r,{enumerable:!0,configurable:!0,writable:!0,value:t}):e[r]=t;var f=(e,r,t)=>k(e,typeof r!="symbol"?r+"":r,t);const u=require("@babylonlabs-io/babylon-tbv-rust-wasm"),C=require("bitcoinjs-lib"),y=require("./signPsbtsWithFallback-DbOmw8Ou.cjs"),A=require("./verifyScriptPathSchnorrSignature-B8zK1ctE.cjs"),n=require("./bitcoin-m84N5a8o.cjs"),b=require("./fundPeginTransaction-BLD8FRL9.cjs"),M=require("./waitForTransactionReceiptSmartAware-AgZ-3WV_.cjs"),B=require("./PeginManager-n__EsW8a.cjs"),h="DepositTermsRejectedError";class R extends Error{constructor(t,i="device-envelope"){super(t);f(this,"reason");this.name=h,this.reason=i}}function F(e){if(e instanceof R)return!0;if(typeof e!="object"||e===null)return!1;const r=e;return r.name===h&&r.reason==="device-envelope"}async function S(e){const r=e.siblings.length;if(r===0)throw new Error("rebuildDepositTermsCore: at least one sibling is required");for(const[s,g]of e.siblings.entries())if(g.amount<=0n)throw new Error(`rebuildDepositTermsCore: sibling[${s}] has non-positive on-chain pegin amount ${g.amount}; the chain-read vault record is invalid. Resume refused.`);if(e.prepeginMaxFee<=0n)throw new Error(`rebuildDepositTermsCore: prepeginMaxFee must be > 0, got ${e.prepeginMaxFee}`);const t=n.stripHexPrefix(e.prepeginTxid).toLowerCase(),i=n.stripHexPrefix(M.calculateBtcTxHash(e.fundedPrePeginTxHex)).toLowerCase();if(i!==t)throw new Error(`Funded Pre-PegIn tx hashes to ${i}, expected ${t} (on-chain prepeginTxid). Resume refused.`);const l=y.findAuthAnchorOpReturn(n.stripHexPrefix(e.fundedPrePeginTxHex));if(l===void 0)throw new Error("Funded Pre-PegIn carries no single, unambiguous auth-anchor OP_RETURN commitment — it either predates auth anchoring or is malformed. The intent resume path requires the anchor to prove sibling completeness. Resume refused.");if(l.vout!==r)throw new Error(`Auth-anchor OP_RETURN at vout ${l.vout} does not match the discovered sibling count ${r}; the discovered sibling set does not cover this transaction's HTLC outputs (a lagging index can cause this — retry later). Resume refused.`);const P=e.vaultKeeperBtcPubkeys.length,p=e.universalChallengerBtcPubkeys.length,a=await u.computeMinClaimValue(e.vaultCoreVersion,P,p,e.councilQuorum,e.councilSize,e.protocolFeeRate),o=await u.computeMinPeginFee(e.vaultCoreVersion,P,p,e.minPeginFeeRate),d=await u.peginP2aAnchorOutput(e.vaultCoreVersion),c=(d==null?void 0:d.value)??0n;if(a<=0n)throw new Error(`WASM returned non-positive depositorClaimValue ${a}; expected > 0. Resume refused.`);if(o<=0n)throw new Error(`WASM returned non-positive peginMaxFee ${o}; expected > 0. Resume refused.`);if(c<0n)throw new Error(`WASM returned negative P2A anchor value ${c}. Resume refused.`);const m=o+c,v=e.minPeginFeeRate*b.MAX_REASONABLE_PEGIN_VBYTES;if(m<=0n||m>v)throw new Error(`WASM implied PegIn reserve ${m} sat is outside (0, ${v}] (minPeginFeeRate=${e.minPeginFeeRate} × ${b.MAX_REASONABLE_PEGIN_VBYTES} vbytes). Resume refused.`);const x=e.siblings.map(s=>s.amount+a+o+c),E=await Promise.all(e.siblings.map(async s=>(await u.getPrePeginHtlcConnectorInfo({txGraphVersion:e.vaultCoreVersion,depositorPubkey:e.depositorBtcPubkey,vaultProviderPubkey:e.vaultProviderBtcPubkey,vaultKeeperPubkeys:[...e.vaultKeeperBtcPubkeys],universalChallengerPubkeys:[...e.universalChallengerBtcPubkeys],hashlock:n.stripHexPrefix(s.hashlock),timelockRefund:e.timelockRefund,network:e.network})).scriptPubKey)),T=C.Transaction.fromHex(n.stripHexPrefix(e.fundedPrePeginTxHex)).outs.map(s=>({value:s.value,script:s.script}));return A.assertEncodedHtlcOutputsMatch(T,x,E),B.buildDepositTerms({vaultCoreVersion:e.vaultCoreVersion,protocolFeeRate:e.protocolFeeRate,timelockPegin:e.timelockPegin,timelockAssert:e.timelockAssert,timelockRefund:e.timelockRefund,prepeginTxid:e.prepeginTxid,prepeginMaxFee:e.prepeginMaxFee,vaultProviderBtcPubkey:e.vaultProviderBtcPubkey,vaultKeeperBtcPubkeys:e.vaultKeeperBtcPubkeys,universalChallengerBtcPubkeys:e.universalChallengerBtcPubkeys,maxAcceptableCommissionBps:e.maxAcceptableCommissionBps,peginAmounts:e.siblings.map(s=>s.amount),depositorClaimValue:a,peginMaxFee:o})}function _(e){const r=(e instanceof Error?e.message:typeof e=="string"?e:"").toLowerCase();return r.includes("wots")&&r.includes("hash")&&r.includes("does not match")}exports.DEPOSIT_TERMS_REJECTED_ERROR_NAME=h;exports.DepositTermsRejectedError=R;exports.isDepositTermsRejectedError=F;exports.isWotsMismatchError=_;exports.rebuildDepositTermsCore=S;
|
|
2
|
+
//# sourceMappingURL=errors-BzBVottO.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors-D2zp7Vzk.cjs","sources":["../src/tbv/core/deposit-terms/depositTermsErrors.ts","../src/tbv/core/deposit-terms/rebuildDepositTermsCore.ts","../src/tbv/core/wots/errors.ts"],"sourcesContent":["/**\n * Typed rejection contract for deposit-terms approval. Providers cannot import\n * this class (no dependency edge between the packages), so the cross-package\n * contract is the error SHAPE on {@link DepositTermsApprover}. Consumers land\n * with the first provider (#2109) and its app error mapping (#2110).\n *\n * @module deposit-terms/depositTermsErrors\n */\n\n/** The `name` value providers must set on envelope rejections (the wire contract). */\nexport const DEPOSIT_TERMS_REJECTED_ERROR_NAME = \"DepositTermsRejectedError\";\n\n/** Why the terms were rejected before approval. */\nexport type DepositTermsRejectionReason = \"device-envelope\";\n\n/** SDK-owned typed rejection thrown when deposit terms fail pre-approval validation. */\nexport class DepositTermsRejectedError extends Error {\n readonly reason: DepositTermsRejectionReason;\n\n constructor(\n message: string,\n reason: DepositTermsRejectionReason = \"device-envelope\",\n ) {\n super(message);\n this.name = DEPOSIT_TERMS_REJECTED_ERROR_NAME;\n this.reason = reason;\n }\n}\n\n/**\n * Guard for app-side error mapping. Matches `instanceof` OR the documented\n * `name` — providers and foreign realms throw structurally-conforming plain\n * errors that `instanceof` cannot see.\n */\nexport function isDepositTermsRejectedError(\n err: unknown,\n): err is DepositTermsRejectedError {\n if (err instanceof DepositTermsRejectedError) return true;\n if (typeof err !== \"object\" || err === null) return false;\n const shaped = err as { name?: unknown; reason?: unknown };\n // The documented provider shape REQUIRES the reason; a name-only match is\n // a contract violation and propagates unnormalized.\n return (\n shaped.name === DEPOSIT_TERMS_REJECTED_ERROR_NAME &&\n shaped.reason === \"device-envelope\"\n );\n}\n","/**\n * Pure core of the resume-broadcast DepositTerms rebuild (#2220 Part 2).\n *\n * Takes plain chain-derived data (the app orchestrator does the chain reads +\n * sibling discovery) and: (1) asserts sibling completeness against the funded\n * tx's auth-anchor OP_RETURN, (2) recomputes the amount-independent sizing\n * (depositorClaimValue, peginMaxFee, anchor) via WASM, (3) byte-matches each\n * HTLC output's value + scriptPubKey against the funded tx (Gate 1), then (4)\n * projects into DepositTerms. No chain access, no browser state — unit-testable.\n *\n * btc-vault is the protocol source of truth (`compute_min_htlc_value`,\n * `derive_challengers_for`).\n */\n\nimport {\n computeMinClaimValue,\n computeMinPeginFee,\n getPrePeginHtlcConnectorInfo,\n peginP2aAnchorOutput,\n} from \"@babylonlabs-io/babylon-tbv-rust-wasm\";\nimport { Transaction } from \"bitcoinjs-lib\";\n\nimport { findAuthAnchorOpReturn } from \"../managers/pegin/assertAuthAnchorOpReturn\";\nimport { assertEncodedHtlcOutputsMatch } from \"../primitives/psbt/assertWasmPeginSizing\";\nimport { stripHexPrefix } from \"../primitives/utils/bitcoin\";\nimport { MAX_REASONABLE_PEGIN_VBYTES } from \"../utils/fee/constants\";\nimport { calculateBtcTxHash } from \"../utils/transaction/btcTxHash\";\n\nimport { buildDepositTerms } from \"./buildDepositTerms\";\nimport type { DepositTerms } from \"./depositTerms\";\n\n/** One HTLC in the shared Pre-PegIn tx, ordered by (and contiguous in) htlcVout. */\nexport interface RebuildSibling {\n /** 32-byte hex hashlock (0x prefix optional), per-vault (feeds the HTLC scriptPubKey). */\n hashlock: string;\n /** btc-vault `pegin_amount` for this sibling (satoshis). */\n amount: bigint;\n}\n\nexport interface RebuildDepositTermsCoreInput {\n /** Stamped tx-graph version (NOT chain-active). */\n vaultCoreVersion: number;\n /** Sibling HTLCs ordered by htlcVout; index === htlcVout (asserted by the app). */\n siblings: readonly RebuildSibling[];\n /** Funded Pre-PegIn tx hex. Gate 0 (hash vs prepeginTxid) is SELF-verified below — callers need not pre-verify. */\n fundedPrePeginTxHex: string;\n\n // Stamped-version participant data (already resolved + sorted by the app).\n depositorBtcPubkey: string;\n vaultProviderBtcPubkey: string;\n vaultKeeperBtcPubkeys: readonly string[];\n universalChallengerBtcPubkeys: readonly string[];\n\n // Version-locked scalars.\n protocolFeeRate: bigint;\n minPeginFeeRate: bigint;\n councilQuorum: number;\n councilSize: number;\n timelockPegin: number;\n timelockAssert: number;\n timelockRefund: number;\n\n // Pass-through into DepositTerms.\n prepeginTxid: string;\n /** Funded-tx fee (Σin − Σout), computed by the app; the device's `prepegin_max_fee` bound. */\n prepeginMaxFee: bigint;\n maxAcceptableCommissionBps: number;\n\n /** WASM network descriptor for scriptPubKey derivation. */\n network: Parameters<typeof getPrePeginHtlcConnectorInfo>[0][\"network\"];\n}\n\nexport async function rebuildDepositTermsCore(\n input: RebuildDepositTermsCoreInput,\n): Promise<DepositTerms> {\n const siblingCount = input.siblings.length;\n if (siblingCount === 0) {\n throw new Error(\n \"rebuildDepositTermsCore: at least one sibling is required\",\n );\n }\n for (const [i, sibling] of input.siblings.entries()) {\n if (sibling.amount <= 0n) {\n throw new Error(\n `rebuildDepositTermsCore: sibling[${i}] has non-positive on-chain pegin ` +\n `amount ${sibling.amount}; the chain-read vault record is invalid. Resume refused.`,\n );\n }\n }\n if (input.prepeginMaxFee <= 0n) {\n throw new Error(\n `rebuildDepositTermsCore: prepeginMaxFee must be > 0, got ${input.prepeginMaxFee}`,\n );\n }\n\n // Gate 0, self-verified: everything below trusts these bytes, and a\n // substituted tx replicating the HTLC outputs would pass Gate 1 with a\n // different fee/txid.\n const expectedTxid = stripHexPrefix(input.prepeginTxid).toLowerCase();\n const actualTxid = stripHexPrefix(\n calculateBtcTxHash(input.fundedPrePeginTxHex),\n ).toLowerCase();\n if (actualTxid !== expectedTxid) {\n throw new Error(\n `Funded Pre-PegIn tx hashes to ${actualTxid}, expected ${expectedTxid} ` +\n `(on-chain prepeginTxid). Resume refused.`,\n );\n }\n\n // Completeness anchor: the single auth-anchor OP_RETURN sits at vout === HTLC\n // count — the only guard against an indexer-lagged partial sibling set.\n const found = findAuthAnchorOpReturn(\n stripHexPrefix(input.fundedPrePeginTxHex),\n );\n if (found === undefined) {\n throw new Error(\n `Funded Pre-PegIn carries no single, unambiguous auth-anchor OP_RETURN ` +\n `commitment — it either predates auth anchoring or is malformed. The ` +\n `intent resume path requires the anchor to prove sibling completeness. ` +\n `Resume refused.`,\n );\n }\n if (found.vout !== siblingCount) {\n throw new Error(\n `Auth-anchor OP_RETURN at vout ${found.vout} does not match the ` +\n `discovered sibling count ${siblingCount}; the discovered sibling set ` +\n `does not cover this transaction's HTLC outputs (a lagging index can ` +\n `cause this — retry later). Resume refused.`,\n );\n }\n\n // Amount-independent sizing. Depositor-as-claimer: numLocalChallengers ===\n // numVks (VP excluded) — btc-vault graph.rs derive_challengers_for.\n const numVks = input.vaultKeeperBtcPubkeys.length;\n const numUcs = input.universalChallengerBtcPubkeys.length;\n const depositorClaimValue = await computeMinClaimValue(\n input.vaultCoreVersion,\n numVks,\n numUcs,\n input.councilQuorum,\n input.councilSize,\n input.protocolFeeRate,\n );\n const peginMaxFee = await computeMinPeginFee(\n input.vaultCoreVersion,\n numVks,\n numUcs,\n input.minPeginFeeRate,\n );\n const anchor = await peginP2aAnchorOutput(input.vaultCoreVersion);\n const anchorValue = anchor?.value ?? 0n;\n\n // Independent bounds on the WASM outputs (mirrors assertWasmPeginSizing):\n // Gate 1 only proves the DCV+fee+anchor SUM — these constrain the\n // decomposition the device is shown.\n if (depositorClaimValue <= 0n) {\n throw new Error(\n `WASM returned non-positive depositorClaimValue ${depositorClaimValue}; ` +\n `expected > 0. Resume refused.`,\n );\n }\n if (peginMaxFee <= 0n) {\n throw new Error(\n `WASM returned non-positive peginMaxFee ${peginMaxFee}; expected > 0. ` +\n `Resume refused.`,\n );\n }\n // Explicit anchor check: the sum bound alone would let a negative anchor\n // offset an inflated peginMaxFee (kept local, not inherited from the facade).\n if (anchorValue < 0n) {\n throw new Error(\n `WASM returned negative P2A anchor value ${anchorValue}. Resume refused.`,\n );\n }\n const impliedReserve = peginMaxFee + anchorValue;\n const maxImpliedReserve = input.minPeginFeeRate * MAX_REASONABLE_PEGIN_VBYTES;\n if (impliedReserve <= 0n || impliedReserve > maxImpliedReserve) {\n throw new Error(\n `WASM implied PegIn reserve ${impliedReserve} sat is outside ` +\n `(0, ${maxImpliedReserve}] (minPeginFeeRate=${input.minPeginFeeRate} × ` +\n `${MAX_REASONABLE_PEGIN_VBYTES} vbytes). Resume refused.`,\n );\n }\n\n // Gate 1: per sibling, value = amount + DCV + peginMaxFee + anchor (btc-vault\n // compute_min_htlc_value) + scriptPubKey from the on-chain hashlock,\n // byte-matched against outputs 0..N-1.\n const expectedHtlcValues = input.siblings.map(\n (s) => s.amount + depositorClaimValue + peginMaxFee + anchorValue,\n );\n const expectedHtlcScriptPubKeys = await Promise.all(\n input.siblings.map(async (s) => {\n const connector = await getPrePeginHtlcConnectorInfo({\n txGraphVersion: input.vaultCoreVersion,\n depositorPubkey: input.depositorBtcPubkey,\n vaultProviderPubkey: input.vaultProviderBtcPubkey,\n vaultKeeperPubkeys: [...input.vaultKeeperBtcPubkeys],\n universalChallengerPubkeys: [...input.universalChallengerBtcPubkeys],\n hashlock: stripHexPrefix(s.hashlock),\n timelockRefund: input.timelockRefund,\n network: input.network,\n });\n return connector.scriptPubKey;\n }),\n );\n const fundedOutputs = Transaction.fromHex(\n stripHexPrefix(input.fundedPrePeginTxHex),\n ).outs.map((o) => ({ value: o.value, script: o.script }));\n assertEncodedHtlcOutputsMatch(\n fundedOutputs,\n expectedHtlcValues,\n expectedHtlcScriptPubKeys,\n );\n\n return buildDepositTerms({\n vaultCoreVersion: input.vaultCoreVersion,\n protocolFeeRate: input.protocolFeeRate,\n timelockPegin: input.timelockPegin,\n timelockAssert: input.timelockAssert,\n timelockRefund: input.timelockRefund,\n prepeginTxid: input.prepeginTxid,\n prepeginMaxFee: input.prepeginMaxFee,\n vaultProviderBtcPubkey: input.vaultProviderBtcPubkey,\n vaultKeeperBtcPubkeys: input.vaultKeeperBtcPubkeys,\n universalChallengerBtcPubkeys: input.universalChallengerBtcPubkeys,\n maxAcceptableCommissionBps: input.maxAcceptableCommissionBps,\n peginAmounts: input.siblings.map((s) => s.amount),\n depositorClaimValue,\n peginMaxFee,\n });\n}\n","/**\n * Check whether an error from the vault provider indicates that the\n * submitted WOTS public key hash does not match the on-chain\n * commitment. This signals that the wrong wallet is connected (its\n * `deriveContextHash` produces a different vault root and therefore\n * different WOTS keys).\n */\nexport function isWotsMismatchError(error: unknown): boolean {\n const msg = (\n error instanceof Error\n ? error.message\n : typeof error === \"string\"\n ? error\n : \"\"\n ).toLowerCase();\n\n return (\n msg.includes(\"wots\") &&\n msg.includes(\"hash\") &&\n msg.includes(\"does not match\")\n );\n}\n"],"names":["DEPOSIT_TERMS_REJECTED_ERROR_NAME","DepositTermsRejectedError","message","reason","__publicField","isDepositTermsRejectedError","err","shaped","rebuildDepositTermsCore","input","siblingCount","i","sibling","expectedTxid","stripHexPrefix","actualTxid","calculateBtcTxHash","found","findAuthAnchorOpReturn","numVks","numUcs","depositorClaimValue","computeMinClaimValue","peginMaxFee","computeMinPeginFee","anchor","peginP2aAnchorOutput","anchorValue","impliedReserve","maxImpliedReserve","MAX_REASONABLE_PEGIN_VBYTES","expectedHtlcValues","expectedHtlcScriptPubKeys","getPrePeginHtlcConnectorInfo","fundedOutputs","Transaction","o","assertEncodedHtlcOutputsMatch","buildDepositTerms","isWotsMismatchError","error","msg"],"mappings":"kjBAUaA,EAAoC,4BAM1C,MAAMC,UAAkC,KAAM,CAGnD,YACEC,EACAC,EAAsC,kBACtC,CACA,M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B,cAAeA,EAAM,cACrB,eAAgBA,EAAM,eACtB,eAAgBA,EAAM,eACtB,aAAcA,EAAM,aACpB,eAAgBA,EAAM,eACtB,uBAAwBA,EAAM,uBAC9B,sBAAuBA,EAAM,sBAC7B,8BAA+BA,EAAM,8BACrC,2BAA4BA,EAAM,2BAClC,aAAcA,EAAM,SAAS,IAAK,GAAM,EAAE,MAAM,EAChD,oBAAAY,EACA,YAAAE,CAAA,CACD,CACH,CC/NO,SAASgB,EAAoBC,EAAyB,CAC3D,MAAMC,GACJD,aAAiB,MACbA,EAAM,QACN,OAAOA,GAAU,SACfA,EACA,IACN,YAAA,EAEF,OACEC,EAAI,SAAS,MAAM,GACnBA,EAAI,SAAS,MAAM,GACnBA,EAAI,SAAS,gBAAgB,CAEjC"}
|
|
1
|
+
{"version":3,"file":"errors-BzBVottO.cjs","sources":["../src/tbv/core/deposit-terms/depositTermsErrors.ts","../src/tbv/core/deposit-terms/rebuildDepositTermsCore.ts","../src/tbv/core/wots/errors.ts"],"sourcesContent":["/**\n * Typed rejection contract for deposit-terms approval. Providers cannot import\n * this class (no dependency edge between the packages), so the cross-package\n * contract is the error SHAPE on {@link DepositTermsApprover}. Consumers land\n * with the first provider (#2109) and its app error mapping (#2110).\n *\n * @module deposit-terms/depositTermsErrors\n */\n\n/** The `name` value providers must set on envelope rejections (the wire contract). */\nexport const DEPOSIT_TERMS_REJECTED_ERROR_NAME = \"DepositTermsRejectedError\";\n\n/** Why the terms were rejected before approval. */\nexport type DepositTermsRejectionReason = \"device-envelope\";\n\n/** SDK-owned typed rejection thrown when deposit terms fail pre-approval validation. */\nexport class DepositTermsRejectedError extends Error {\n readonly reason: DepositTermsRejectionReason;\n\n constructor(\n message: string,\n reason: DepositTermsRejectionReason = \"device-envelope\",\n ) {\n super(message);\n this.name = DEPOSIT_TERMS_REJECTED_ERROR_NAME;\n this.reason = reason;\n }\n}\n\n/**\n * Guard for app-side error mapping. Matches `instanceof` OR the documented\n * `name` — providers and foreign realms throw structurally-conforming plain\n * errors that `instanceof` cannot see.\n */\nexport function isDepositTermsRejectedError(\n err: unknown,\n): err is DepositTermsRejectedError {\n if (err instanceof DepositTermsRejectedError) return true;\n if (typeof err !== \"object\" || err === null) return false;\n const shaped = err as { name?: unknown; reason?: unknown };\n // The documented provider shape REQUIRES the reason; a name-only match is\n // a contract violation and propagates unnormalized.\n return (\n shaped.name === DEPOSIT_TERMS_REJECTED_ERROR_NAME &&\n shaped.reason === \"device-envelope\"\n );\n}\n","/**\n * Pure core of the resume-broadcast DepositTerms rebuild (#2220 Part 2).\n *\n * Takes plain chain-derived data (the app orchestrator does the chain reads +\n * sibling discovery) and: (1) asserts sibling completeness against the funded\n * tx's auth-anchor OP_RETURN, (2) recomputes the amount-independent sizing\n * (depositorClaimValue, peginMaxFee, anchor) via WASM, (3) byte-matches each\n * HTLC output's value + scriptPubKey against the funded tx (Gate 1), then (4)\n * projects into DepositTerms. No chain access, no browser state — unit-testable.\n *\n * btc-vault is the protocol source of truth (`compute_min_htlc_value`,\n * `derive_challengers_for`).\n */\n\nimport {\n computeMinClaimValue,\n computeMinPeginFee,\n getPrePeginHtlcConnectorInfo,\n peginP2aAnchorOutput,\n} from \"@babylonlabs-io/babylon-tbv-rust-wasm\";\nimport { Transaction } from \"bitcoinjs-lib\";\n\nimport { findAuthAnchorOpReturn } from \"../managers/pegin/assertAuthAnchorOpReturn\";\nimport { assertEncodedHtlcOutputsMatch } from \"../primitives/psbt/assertWasmPeginSizing\";\nimport { stripHexPrefix } from \"../primitives/utils/bitcoin\";\nimport { MAX_REASONABLE_PEGIN_VBYTES } from \"../utils/fee/constants\";\nimport { calculateBtcTxHash } from \"../utils/transaction/btcTxHash\";\n\nimport { buildDepositTerms } from \"./buildDepositTerms\";\nimport type { DepositTerms } from \"./depositTerms\";\n\n/** One HTLC in the shared Pre-PegIn tx, ordered by (and contiguous in) htlcVout. */\nexport interface RebuildSibling {\n /** 32-byte hex hashlock (0x prefix optional), per-vault (feeds the HTLC scriptPubKey). */\n hashlock: string;\n /** btc-vault `pegin_amount` for this sibling (satoshis). */\n amount: bigint;\n}\n\nexport interface RebuildDepositTermsCoreInput {\n /** Stamped tx-graph version (NOT chain-active). */\n vaultCoreVersion: number;\n /** Sibling HTLCs ordered by htlcVout; index === htlcVout (asserted by the app). */\n siblings: readonly RebuildSibling[];\n /** Funded Pre-PegIn tx hex. Gate 0 (hash vs prepeginTxid) is SELF-verified below — callers need not pre-verify. */\n fundedPrePeginTxHex: string;\n\n // Stamped-version participant data (already resolved + sorted by the app).\n depositorBtcPubkey: string;\n vaultProviderBtcPubkey: string;\n vaultKeeperBtcPubkeys: readonly string[];\n universalChallengerBtcPubkeys: readonly string[];\n\n // Version-locked scalars.\n protocolFeeRate: bigint;\n minPeginFeeRate: bigint;\n councilQuorum: number;\n councilSize: number;\n timelockPegin: number;\n timelockAssert: number;\n timelockRefund: number;\n\n // Pass-through into DepositTerms.\n prepeginTxid: string;\n /** Funded-tx fee (Σin − Σout), computed by the app; the device's `prepegin_max_fee` bound. */\n prepeginMaxFee: bigint;\n maxAcceptableCommissionBps: number;\n\n /** WASM network descriptor for scriptPubKey derivation. */\n network: Parameters<typeof getPrePeginHtlcConnectorInfo>[0][\"network\"];\n}\n\nexport async function rebuildDepositTermsCore(\n input: RebuildDepositTermsCoreInput,\n): Promise<DepositTerms> {\n const siblingCount = input.siblings.length;\n if (siblingCount === 0) {\n throw new Error(\n \"rebuildDepositTermsCore: at least one sibling is required\",\n );\n }\n for (const [i, sibling] of input.siblings.entries()) {\n if (sibling.amount <= 0n) {\n throw new Error(\n `rebuildDepositTermsCore: sibling[${i}] has non-positive on-chain pegin ` +\n `amount ${sibling.amount}; the chain-read vault record is invalid. Resume refused.`,\n );\n }\n }\n if (input.prepeginMaxFee <= 0n) {\n throw new Error(\n `rebuildDepositTermsCore: prepeginMaxFee must be > 0, got ${input.prepeginMaxFee}`,\n );\n }\n\n // Gate 0, self-verified: everything below trusts these bytes, and a\n // substituted tx replicating the HTLC outputs would pass Gate 1 with a\n // different fee/txid.\n const expectedTxid = stripHexPrefix(input.prepeginTxid).toLowerCase();\n const actualTxid = stripHexPrefix(\n calculateBtcTxHash(input.fundedPrePeginTxHex),\n ).toLowerCase();\n if (actualTxid !== expectedTxid) {\n throw new Error(\n `Funded Pre-PegIn tx hashes to ${actualTxid}, expected ${expectedTxid} ` +\n `(on-chain prepeginTxid). Resume refused.`,\n );\n }\n\n // Completeness anchor: the single auth-anchor OP_RETURN sits at vout === HTLC\n // count — the only guard against an indexer-lagged partial sibling set.\n const found = findAuthAnchorOpReturn(\n stripHexPrefix(input.fundedPrePeginTxHex),\n );\n if (found === undefined) {\n throw new Error(\n `Funded Pre-PegIn carries no single, unambiguous auth-anchor OP_RETURN ` +\n `commitment — it either predates auth anchoring or is malformed. The ` +\n `intent resume path requires the anchor to prove sibling completeness. ` +\n `Resume refused.`,\n );\n }\n if (found.vout !== siblingCount) {\n throw new Error(\n `Auth-anchor OP_RETURN at vout ${found.vout} does not match the ` +\n `discovered sibling count ${siblingCount}; the discovered sibling set ` +\n `does not cover this transaction's HTLC outputs (a lagging index can ` +\n `cause this — retry later). Resume refused.`,\n );\n }\n\n // Amount-independent sizing. Depositor-as-claimer: numLocalChallengers ===\n // numVks (VP excluded) — btc-vault graph.rs derive_challengers_for.\n const numVks = input.vaultKeeperBtcPubkeys.length;\n const numUcs = input.universalChallengerBtcPubkeys.length;\n const depositorClaimValue = await computeMinClaimValue(\n input.vaultCoreVersion,\n numVks,\n numUcs,\n input.councilQuorum,\n input.councilSize,\n input.protocolFeeRate,\n );\n const peginMaxFee = await computeMinPeginFee(\n input.vaultCoreVersion,\n numVks,\n numUcs,\n input.minPeginFeeRate,\n );\n const anchor = await peginP2aAnchorOutput(input.vaultCoreVersion);\n const anchorValue = anchor?.value ?? 0n;\n\n // Independent bounds on the WASM outputs (mirrors assertWasmPeginSizing):\n // Gate 1 only proves the DCV+fee+anchor SUM — these constrain the\n // decomposition the device is shown.\n if (depositorClaimValue <= 0n) {\n throw new Error(\n `WASM returned non-positive depositorClaimValue ${depositorClaimValue}; ` +\n `expected > 0. Resume refused.`,\n );\n }\n if (peginMaxFee <= 0n) {\n throw new Error(\n `WASM returned non-positive peginMaxFee ${peginMaxFee}; expected > 0. ` +\n `Resume refused.`,\n );\n }\n // Explicit anchor check: the sum bound alone would let a negative anchor\n // offset an inflated peginMaxFee (kept local, not inherited from the facade).\n if (anchorValue < 0n) {\n throw new Error(\n `WASM returned negative P2A anchor value ${anchorValue}. Resume refused.`,\n );\n }\n const impliedReserve = peginMaxFee + anchorValue;\n const maxImpliedReserve = input.minPeginFeeRate * MAX_REASONABLE_PEGIN_VBYTES;\n if (impliedReserve <= 0n || impliedReserve > maxImpliedReserve) {\n throw new Error(\n `WASM implied PegIn reserve ${impliedReserve} sat is outside ` +\n `(0, ${maxImpliedReserve}] (minPeginFeeRate=${input.minPeginFeeRate} × ` +\n `${MAX_REASONABLE_PEGIN_VBYTES} vbytes). Resume refused.`,\n );\n }\n\n // Gate 1: per sibling, value = amount + DCV + peginMaxFee + anchor (btc-vault\n // compute_min_htlc_value) + scriptPubKey from the on-chain hashlock,\n // byte-matched against outputs 0..N-1.\n const expectedHtlcValues = input.siblings.map(\n (s) => s.amount + depositorClaimValue + peginMaxFee + anchorValue,\n );\n const expectedHtlcScriptPubKeys = await Promise.all(\n input.siblings.map(async (s) => {\n const connector = await getPrePeginHtlcConnectorInfo({\n txGraphVersion: input.vaultCoreVersion,\n depositorPubkey: input.depositorBtcPubkey,\n vaultProviderPubkey: input.vaultProviderBtcPubkey,\n vaultKeeperPubkeys: [...input.vaultKeeperBtcPubkeys],\n universalChallengerPubkeys: [...input.universalChallengerBtcPubkeys],\n hashlock: stripHexPrefix(s.hashlock),\n timelockRefund: input.timelockRefund,\n network: input.network,\n });\n return connector.scriptPubKey;\n }),\n );\n const fundedOutputs = Transaction.fromHex(\n stripHexPrefix(input.fundedPrePeginTxHex),\n ).outs.map((o) => ({ value: o.value, script: o.script }));\n assertEncodedHtlcOutputsMatch(\n fundedOutputs,\n expectedHtlcValues,\n expectedHtlcScriptPubKeys,\n );\n\n return buildDepositTerms({\n vaultCoreVersion: input.vaultCoreVersion,\n protocolFeeRate: input.protocolFeeRate,\n timelockPegin: input.timelockPegin,\n timelockAssert: input.timelockAssert,\n timelockRefund: input.timelockRefund,\n prepeginTxid: input.prepeginTxid,\n prepeginMaxFee: input.prepeginMaxFee,\n vaultProviderBtcPubkey: input.vaultProviderBtcPubkey,\n vaultKeeperBtcPubkeys: input.vaultKeeperBtcPubkeys,\n universalChallengerBtcPubkeys: input.universalChallengerBtcPubkeys,\n maxAcceptableCommissionBps: input.maxAcceptableCommissionBps,\n peginAmounts: input.siblings.map((s) => s.amount),\n depositorClaimValue,\n peginMaxFee,\n });\n}\n","/**\n * Check whether an error from the vault provider indicates that the\n * submitted WOTS public key hash does not match the on-chain\n * commitment. This signals that the wrong wallet is connected (its\n * `deriveContextHash` produces a different vault root and therefore\n * different WOTS keys).\n */\nexport function isWotsMismatchError(error: unknown): boolean {\n const msg = (\n error instanceof Error\n ? error.message\n : typeof error === \"string\"\n ? error\n : \"\"\n ).toLowerCase();\n\n return (\n msg.includes(\"wots\") &&\n msg.includes(\"hash\") &&\n msg.includes(\"does not match\")\n );\n}\n"],"names":["DEPOSIT_TERMS_REJECTED_ERROR_NAME","DepositTermsRejectedError","message","reason","__publicField","isDepositTermsRejectedError","err","shaped","rebuildDepositTermsCore","input","siblingCount","i","sibling","expectedTxid","stripHexPrefix","actualTxid","calculateBtcTxHash","found","findAuthAnchorOpReturn","numVks","numUcs","depositorClaimValue","computeMinClaimValue","peginMaxFee","computeMinPeginFee","anchor","peginP2aAnchorOutput","anchorValue","impliedReserve","maxImpliedReserve","MAX_REASONABLE_PEGIN_VBYTES","expectedHtlcValues","expectedHtlcScriptPubKeys","getPrePeginHtlcConnectorInfo","fundedOutputs","Transaction","o","assertEncodedHtlcOutputsMatch","buildDepositTerms","isWotsMismatchError","error","msg"],"mappings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EH,EACAH,EACAC,CAAA,EAGKM,oBAAkB,CACvB,iBAAkB7B,EAAM,iBACxB,gBAAiBA,EAAM,gBACvB,cAAeA,EAAM,cACrB,eAAgBA,EAAM,eACtB,eAAgBA,EAAM,eACtB,aAAcA,EAAM,aACpB,eAAgBA,EAAM,eACtB,uBAAwBA,EAAM,uBAC9B,sBAAuBA,EAAM,sBAC7B,8BAA+BA,EAAM,8BACrC,2BAA4BA,EAAM,2BAClC,aAAcA,EAAM,SAAS,IAAK,GAAM,EAAE,MAAM,EAChD,oBAAAY,EACA,YAAAE,CAAA,CACD,CACH,CC/NO,SAASgB,EAAoBC,EAAyB,CAC3D,MAAMC,GACJD,aAAiB,MACbA,EAAM,QACN,OAAOA,GAAU,SACfA,EACA,IACN,YAAA,EAEF,OACEC,EAAI,SAAS,MAAM,GACnBA,EAAI,SAAS,MAAM,GACnBA,EAAI,SAAS,gBAAgB,CAEjC"}
|
package/dist/index.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const R=require("./challengeAssert-BFRE2DM-.cjs"),m=require("./constants-DU5CGcqO.cjs"),n=require("@babylonlabs-io/babylon-tbv-rust-wasm"),l=require("./verifyScriptPathSchnorrSignature-B8zK1ctE.cjs"),A=require("./peginInput-Ci921gTl.cjs"),S=require("./noPayout-CbxQqBw1.cjs"),t=require("./bitcoin-m84N5a8o.cjs"),c=require("./validation-CDbOaDj7.cjs"),O=require("./signing-Bnsro0hE.cjs"),u=require("./PeginManager-BLBB_vMl.cjs"),d=require("./signPsbtsWithFallback-DbOmw8Ou.cjs"),_=require("./ProtocolParams.abi-C8U7BHCS.cjs"),C=require("./BTCVaultRegistry.abi-3VLWva2x.cjs"),b=require("./BTCVaultRegistryKeyEpochs.abi-_NERAdc5.cjs"),p=require("./errors-CGcNP0rV.cjs"),P=require("./parseFundingOutpoints-CIO9Ok1L.cjs"),y=require("./shared/index.cjs"),o=require("./waitForTransactionReceiptSmartAware-AgZ-3WV_.cjs"),i=require("./fundPeginTransaction-BLD8FRL9.cjs"),E=require("./reservation-CDbInVw0.cjs"),a=require("./mempoolApi-BxhMqJ4f.cjs"),r=require("./batchPoll-CbbCcNZP.cjs"),s=require("./json-rpc-client-BiAmg_ho.cjs"),I=require("./onChainBtcPubkey-C_a2L3kL.cjs"),T=require("./errors-D2zp7Vzk.cjs"),e=require("./buildAndBroadcastRefund-CYzhA_B8.cjs"),g=require("./peginState-eaQ4IO_R.cjs");exports.buildChallengeAssertPsbt=R.buildChallengeAssertPsbt;exports.computeNumLocalChallengers=R.computeNumLocalChallengers;exports.assertValidVaultCoreVersion=m.assertValidVaultCoreVersion;Object.defineProperty(exports,"computeMinClaimValue",{enumerable:!0,get:()=>n.computeMinClaimValue});Object.defineProperty(exports,"computeMinPeginFee",{enumerable:!0,get:()=>n.computeMinPeginFee});Object.defineProperty(exports,"deriveVaultId",{enumerable:!0,get:()=>n.deriveVaultId});Object.defineProperty(exports,"expandAuthAnchor",{enumerable:!0,get:()=>n.expandAuthAnchor});Object.defineProperty(exports,"expandHashlockSecret",{enumerable:!0,get:()=>n.expandHashlockSecret});Object.defineProperty(exports,"expandWotsSeed",{enumerable:!0,get:()=>n.expandWotsSeed});Object.defineProperty(exports,"peginP2aAnchorOutput",{enumerable:!0,get:()=>n.peginP2aAnchorOutput});Object.defineProperty(exports,"supportedTxGraphVersions",{enumerable:!0,get:()=>n.supportedTxGraphVersions});Object.defineProperty(exports,"validatePeginP2aAnchor",{enumerable:!0,get:()=>n.validatePeginP2aAnchor});exports.PsbtSubstitutionError=l.PsbtSubstitutionError;exports.assertPsbtUnsignedTxMatches=l.assertPsbtUnsignedTxMatches;exports.assertScriptPathSchnorrSignature=l.assertScriptPathSchnorrSignature;exports.buildPayoutPsbt=l.buildPayoutPsbt;exports.buildPeginTxFromFundedPrePegin=l.buildPeginTxFromFundedPrePegin;exports.buildPrePeginPsbt=l.buildPrePeginPsbt;exports.createPayoutScript=l.createPayoutScript;exports.extractPayoutSignature=l.extractPayoutSignature;exports.buildPeginInputPsbt=A.buildPeginInputPsbt;exports.extractPeginInputSignature=A.extractPeginInputSignature;exports.finalizePeginInputPsbt=A.finalizePeginInputPsbt;exports.buildNoPayoutPsbt=S.buildNoPayoutPsbt;exports.buildRefundPsbt=S.buildRefundPsbt;exports.canonicalizeBtcPubkey=t.canonicalizeBtcPubkey;exports.deriveBip86ScriptPubKeyHex=t.deriveBip86ScriptPubKeyHex;exports.deriveNativeSegwitAddress=t.deriveNativeSegwitAddress;exports.deriveTaprootAddress=t.deriveTaprootAddress;exports.ensureHexPrefix=t.ensureHexPrefix;exports.formatSatoshisToBtc=t.formatSatoshisToBtc;exports.getNetwork=t.getNetwork;exports.getSortedXOnlyPubkeys=t.getSortedXOnlyPubkeys;exports.hexToUint8Array=t.hexToUint8Array;exports.isAddressFromPublicKey=t.isAddressFromPublicKey;exports.isValidHex=t.isValidHex;exports.processPublicKeyToXOnly=t.processPublicKeyToXOnly;exports.stripHexPrefix=t.stripHexPrefix;exports.toXOnly=t.toXOnly;exports.uint8ArrayToHex=t.uint8ArrayToHex;exports.validateWalletPubkey=t.validateWalletPubkey;exports.BITCOIN_ADDRESS_RE=c.BITCOIN_ADDRESS_RE;exports.HEX_RE=c.HEX_RE;exports.KNOWN_SCRIPT_PREFIXES=c.KNOWN_SCRIPT_PREFIXES;exports.MAX_REASONABLE_FEE_SATS=c.MAX_REASONABLE_FEE_SATS;exports.TXID_RE=c.TXID_RE;exports.combineAbortSignals=c.combineAbortSignals;exports.createTaprootScriptPathSignOptions=O.createTaprootScriptPathSignOptions;exports.COMMISSION_BPS_HEADROOM=u.COMMISSION_BPS_HEADROOM;exports.MAX_ACCEPTABLE_COMMISSION_BPS_CAP=u.MAX_ACCEPTABLE_COMMISSION_BPS_CAP;exports.PeginManager=u.PeginManager;exports.buildDepositTerms=u.buildDepositTerms;exports.capMaxAcceptableCommissionBps=u.capMaxAcceptableCommissionBps;exports.computeWotsBlockPublicKeysHash=u.computeWotsBlockPublicKeysHash;exports.deriveWotsBlocksFromSeed=u.deriveWotsBlocksFromSeed;exports.ensurePrePeginTermsApproval=u.ensurePrePeginTermsApproval;exports.estimateSubmitPeginRequestBatchGas=u.estimateSubmitPeginRequestBatchGas;exports.PayoutManager=d.PayoutManager;exports.computeHashlock=d.computeHashlock;exports.forwardDepositApproval=d.forwardDepositApproval;exports.supportsDepositApproval=d.supportsDepositApproval;exports.validateSecretAgainstHashlock=d.validateSecretAgainstHashlock;exports.ApplicationRegistryABI=_.ApplicationRegistryABI;exports.ProtocolParamsABI=_.ProtocolParamsABI;exports.BTCVaultRegistryABI=C.BTCVaultRegistryABI;exports.BTCVaultRegistryKeyEpochsABI=b.BTCVaultRegistryKeyEpochsABI;exports.CONTRACT_ERRORS=p.CONTRACT_ERRORS;exports.extractErrorData=p.extractErrorData;exports.getContractErrorMessage=p.getContractErrorMessage;exports.handleContractError=p.handleContractError;exports.isKnownContractError=p.isKnownContractError;exports.VAULT_APP_NAME=P.VAULT_APP_NAME;exports.buildFundingOutpointsCommitment=P.buildFundingOutpointsCommitment;exports.buildVaultContext=P.buildVaultContext;exports.deriveVaultRoot=P.deriveVaultRoot;exports.forwardDeriveContextHash=P.forwardDeriveContextHash;exports.parseFundingOutpointsFromTx=P.parseFundingOutpointsFromTx;exports.BitcoinNetworks=y.BitcoinNetworks;exports.BitcoinScriptType=o.BitcoinScriptType;exports.applyChangeOutputPolicy=o.applyChangeOutputPolicy;exports.calculateBtcTxHash=o.calculateBtcTxHash;exports.computeChangeOutputFeeSats=o.computeChangeOutputFeeSats;exports.computeMaxDeposit=o.computeMaxDeposit;exports.computePeginBaseFeeSats=o.computePeginBaseFeeSats;exports.getDustThreshold=o.getDustThreshold;exports.getPsbtInputFields=o.getPsbtInputFields;exports.getScriptType=o.getScriptType;exports.selectUtxosForPegin=o.selectUtxosForPegin;exports.shouldAddChangeOutput=o.shouldAddChangeOutput;exports.waitForTransactionReceiptSmartAware=o.waitForTransactionReceiptSmartAware;exports.BTC_DUST_SAT=i.BTC_DUST_SAT;exports.DUST_THRESHOLD=i.DUST_THRESHOLD;exports.LOW_RATE_ESTIMATION_ACCURACY_BUFFER=i.LOW_RATE_ESTIMATION_ACCURACY_BUFFER;exports.MAX_NON_LEGACY_OUTPUT_SIZE=i.MAX_NON_LEGACY_OUTPUT_SIZE;exports.MAX_REASONABLE_PEGIN_VBYTES=i.MAX_REASONABLE_PEGIN_VBYTES;exports.P2TR_INPUT_SIZE=i.P2TR_INPUT_SIZE;exports.PEGIN_AUTH_ANCHOR_OUTPUTS=i.PEGIN_AUTH_ANCHOR_OUTPUTS;exports.PEGIN_FIXED_OUTPUTS=i.PEGIN_FIXED_OUTPUTS;exports.SPLIT_TX_FEE_SAFETY_MULTIPLIER=i.SPLIT_TX_FEE_SAFETY_MULTIPLIER;exports.TX_BUFFER_SIZE_OVERHEAD=i.TX_BUFFER_SIZE_OVERHEAD;exports.WALLET_RELAY_FEE_RATE_THRESHOLD=i.WALLET_RELAY_FEE_RATE_THRESHOLD;exports.fundPeginTransaction=i.fundPeginTransaction;exports.parseUnfundedWasmTransaction=i.parseUnfundedWasmTransaction;exports.peginOutputCount=i.peginOutputCount;exports.rateBasedTxBufferFee=i.rateBasedTxBufferFee;exports.UtxoNotAvailableError=E.UtxoNotAvailableError;exports.assertUtxosAvailable=E.assertUtxosAvailable;exports.extractInputsFromTransaction=E.extractInputsFromTransaction;exports.findOverlappingPendingVaults=E.findOverlappingPendingVaults;exports.validateUtxosAvailable=E.validateUtxosAvailable;exports.MEMPOOL_API_URLS=a.MEMPOOL_API_URLS;exports.ViemVaultRegistryReader=a.ViemVaultRegistryReader;exports.getAddressTxs=a.getAddressTxs;exports.getAddressUtxos=a.getAddressUtxos;exports.getMempoolApiUrl=a.getMempoolApiUrl;exports.getNetworkFees=a.getNetworkFees;exports.getOutspend=a.getOutspend;exports.getTipHeight=a.getTipHeight;exports.getTxHex=a.getTxHex;exports.getTxInfo=a.getTxInfo;exports.getUtxoInfo=a.getUtxoInfo;exports.pushTx=a.pushTx;exports.validateOffchainParams=a.validateOffchainParams;exports.validatePegInConfiguration=a.validatePegInConfiguration;exports.validateTBVProtocolParams=a.validateTBVProtocolParams;exports.OnChainBtcVaultStatus=r.OnChainBtcVaultStatus;exports.ServerIdentityError=r.ServerIdentityError;exports.VaultProviderRpcClient=r.VaultProviderRpcClient;exports.ViemOperationKeyReader=r.ViemOperationKeyReader;exports.ViemProtocolParamsReader=r.ViemProtocolParamsReader;exports.ViemUniversalChallengerReader=r.ViemUniversalChallengerReader;exports.ViemVaultKeeperReader=r.ViemVaultKeeperReader;exports.VpResponseValidationError=r.VpResponseValidationError;exports.VpTokenRegistry=r.VpTokenRegistry;exports.batchPollByProvider=r.batchPollByProvider;exports.createAuthenticatedVpClient=r.createAuthenticatedVpClient;exports.primeVpTokenRegistry=r.primeVpTokenRegistry;exports.resolveProtocolAddresses=r.resolveProtocolAddresses;exports.validateRequestDepositorClaimerArtifactsResponse=r.validateRequestDepositorClaimerArtifactsResponse;exports.verifyServerIdentity=r.verifyServerIdentity;exports.vpTokenRegistry=r.vpTokenRegistry;exports.AUTH_REJECTED_RPC_CODE=s.AUTH_REJECTED_RPC_CODE;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_BATCH_MAX_SIZE=s.VP_BATCH_MAX_SIZE;exports.VP_TERMINAL_FAILURE_STATUSES=s.VP_TERMINAL_FAILURE_STATUSES;exports.VP_TRANSIENT_STATUSES=s.VP_TRANSIENT_STATUSES;exports.isAuthRejectedError=s.isAuthRejectedError;exports.assertOnChainBtcPubkey=I.assertOnChainBtcPubkey;exports.DEPOSIT_TERMS_REJECTED_ERROR_NAME=T.DEPOSIT_TERMS_REJECTED_ERROR_NAME;exports.DepositTermsRejectedError=T.DepositTermsRejectedError;exports.isDepositTermsRejectedError=T.isDepositTermsRejectedError;exports.isWotsMismatchError=T.isWotsMismatchError;exports.rebuildDepositTermsCore=T.rebuildDepositTermsCore;exports.BIP68NotMatureError=e.BIP68NotMatureError;exports.ClaimerPegoutStatusValue=e.ClaimerPegoutStatusValue;exports.PEGIN_ETH_CONFIRMATIONS=e.PEGIN_ETH_CONFIRMATIONS;exports.ParticipantKeyDriftError=e.ParticipantKeyDriftError;exports.PeginRegistrationMissingError=e.PeginRegistrationMissingError;exports.PeginRegistrationNotFinalError=e.PeginRegistrationNotFinalError;exports.REFUND_MAX_FEE_FRACTION_DENOMINATOR=e.REFUND_MAX_FEE_FRACTION_DENOMINATOR;exports.REFUND_MAX_FEE_FRACTION_NUMERATOR=e.REFUND_MAX_FEE_FRACTION_NUMERATOR;exports.REFUND_MAX_FEE_RATE_SATS_VB=e.REFUND_MAX_FEE_RATE_SATS_VB;exports.REFUND_VSIZE=e.REFUND_VSIZE;exports.RegisteredVaultVersionMismatchError=e.RegisteredVaultVersionMismatchError;exports.activateVault=e.activateVault;exports.activateVaultAndRedeem=e.activateVaultAndRedeem;exports.assertVaultProviderHintAccepted=e.assertVaultProviderHintAccepted;exports.buildAndBroadcastRefund=e.buildAndBroadcastRefund;exports.estimateRefundFeeSats=e.estimateRefundFeeSats;exports.isDepositAmountValid=e.isDepositAmountValid;exports.isHintAccepted=e.isHintAccepted;exports.isParticipantKeyDriftError=e.isParticipantKeyDriftError;exports.isPeginRegistrationMissingError=e.isPeginRegistrationMissingError;exports.isPeginRegistrationNotFinalError=e.isPeginRegistrationNotFinalError;exports.isPegoutTerminalStatus=e.isPegoutTerminalStatus;exports.isRecognizedPegoutStatus=e.isRecognizedPegoutStatus;exports.isRegisteredVaultVersionMismatchError=e.isRegisteredVaultVersionMismatchError;exports.matchKeyHint=e.matchKeyHint;exports.matchKeySetHint=e.matchKeySetHint;exports.resolveCurrentParticipantKeys=e.resolveCurrentParticipantKeys;exports.resolveParticipantKeysAtEpochs=e.resolveParticipantKeysAtEpochs;exports.runDepositorPresignFlow=e.runDepositorPresignFlow;exports.signDepositorGraph=e.signDepositorGraph;exports.submitWotsPublicKey=e.submitWotsPublicKey;exports.validateDepositAmount=e.validateDepositAmount;exports.validateMultiVaultDepositInputs=e.validateMultiVaultDepositInputs;exports.validateOnChainParticipantKeys=e.validateOnChainParticipantKeys;exports.validateProviderSelection=e.validateProviderSelection;exports.validateRemainingCapacity=e.validateRemainingCapacity;exports.validateVaultAmounts=e.validateVaultAmounts;exports.validateVaultProviderPubkey=e.validateVaultProviderPubkey;exports.verifyRegisteredParticipantKeys=e.verifyRegisteredParticipantKeys;exports.verifyRegisteredVaultVersions=e.verifyRegisteredVaultVersions;exports.waitForPeginRegistrationDepth=e.waitForPeginRegistrationDepth;exports.waitForPeginStatus=e.waitForPeginStatus;exports.ContractStatus=g.ContractStatus;exports.PeginAction=g.PeginAction;exports.canPerformAction=g.canPerformAction;exports.getPeginProtocolState=g.getPeginProtocolState;exports.isActivationDeadlinePassedOnChain=g.isActivationDeadlinePassedOnChain;
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const R=require("./challengeAssert-BFRE2DM-.cjs"),m=require("./constants-DU5CGcqO.cjs"),n=require("@babylonlabs-io/babylon-tbv-rust-wasm"),l=require("./verifyScriptPathSchnorrSignature-B8zK1ctE.cjs"),A=require("./peginInput-Ci921gTl.cjs"),S=require("./noPayout-CbxQqBw1.cjs"),t=require("./bitcoin-m84N5a8o.cjs"),c=require("./validation-CDbOaDj7.cjs"),O=require("./signing-Bnsro0hE.cjs"),u=require("./PeginManager-n__EsW8a.cjs"),d=require("./signPsbtsWithFallback-DbOmw8Ou.cjs"),_=require("./ProtocolParams.abi-CYZoV2EI.cjs"),C=require("./BTCVaultRegistry.abi-z7d_eP22.cjs"),b=require("./BTCVaultRegistryKeyEpochs.abi-_NERAdc5.cjs"),p=require("./errors-CGcNP0rV.cjs"),P=require("./parseFundingOutpoints-CIO9Ok1L.cjs"),y=require("./shared/index.cjs"),o=require("./waitForTransactionReceiptSmartAware-AgZ-3WV_.cjs"),i=require("./fundPeginTransaction-BLD8FRL9.cjs"),E=require("./reservation-CDbInVw0.cjs"),a=require("./mempoolApi-CXfr-L6x.cjs"),r=require("./batchPoll-6L5oToGr.cjs"),s=require("./json-rpc-client-BiAmg_ho.cjs"),I=require("./onChainBtcPubkey-C_a2L3kL.cjs"),T=require("./errors-BzBVottO.cjs"),e=require("./buildAndBroadcastRefund-DsCd90qJ.cjs"),g=require("./peginState-eaQ4IO_R.cjs");exports.buildChallengeAssertPsbt=R.buildChallengeAssertPsbt;exports.computeNumLocalChallengers=R.computeNumLocalChallengers;exports.assertValidVaultCoreVersion=m.assertValidVaultCoreVersion;Object.defineProperty(exports,"computeMinClaimValue",{enumerable:!0,get:()=>n.computeMinClaimValue});Object.defineProperty(exports,"computeMinPeginFee",{enumerable:!0,get:()=>n.computeMinPeginFee});Object.defineProperty(exports,"deriveVaultId",{enumerable:!0,get:()=>n.deriveVaultId});Object.defineProperty(exports,"expandAuthAnchor",{enumerable:!0,get:()=>n.expandAuthAnchor});Object.defineProperty(exports,"expandHashlockSecret",{enumerable:!0,get:()=>n.expandHashlockSecret});Object.defineProperty(exports,"expandWotsSeed",{enumerable:!0,get:()=>n.expandWotsSeed});Object.defineProperty(exports,"peginP2aAnchorOutput",{enumerable:!0,get:()=>n.peginP2aAnchorOutput});Object.defineProperty(exports,"supportedTxGraphVersions",{enumerable:!0,get:()=>n.supportedTxGraphVersions});Object.defineProperty(exports,"validatePeginP2aAnchor",{enumerable:!0,get:()=>n.validatePeginP2aAnchor});exports.PsbtSubstitutionError=l.PsbtSubstitutionError;exports.assertPsbtUnsignedTxMatches=l.assertPsbtUnsignedTxMatches;exports.assertScriptPathSchnorrSignature=l.assertScriptPathSchnorrSignature;exports.buildPayoutPsbt=l.buildPayoutPsbt;exports.buildPeginTxFromFundedPrePegin=l.buildPeginTxFromFundedPrePegin;exports.buildPrePeginPsbt=l.buildPrePeginPsbt;exports.createPayoutScript=l.createPayoutScript;exports.extractPayoutSignature=l.extractPayoutSignature;exports.buildPeginInputPsbt=A.buildPeginInputPsbt;exports.extractPeginInputSignature=A.extractPeginInputSignature;exports.finalizePeginInputPsbt=A.finalizePeginInputPsbt;exports.buildNoPayoutPsbt=S.buildNoPayoutPsbt;exports.buildRefundPsbt=S.buildRefundPsbt;exports.canonicalizeBtcPubkey=t.canonicalizeBtcPubkey;exports.deriveBip86ScriptPubKeyHex=t.deriveBip86ScriptPubKeyHex;exports.deriveNativeSegwitAddress=t.deriveNativeSegwitAddress;exports.deriveTaprootAddress=t.deriveTaprootAddress;exports.ensureHexPrefix=t.ensureHexPrefix;exports.formatSatoshisToBtc=t.formatSatoshisToBtc;exports.getNetwork=t.getNetwork;exports.getSortedXOnlyPubkeys=t.getSortedXOnlyPubkeys;exports.hexToUint8Array=t.hexToUint8Array;exports.isAddressFromPublicKey=t.isAddressFromPublicKey;exports.isValidHex=t.isValidHex;exports.processPublicKeyToXOnly=t.processPublicKeyToXOnly;exports.stripHexPrefix=t.stripHexPrefix;exports.toXOnly=t.toXOnly;exports.uint8ArrayToHex=t.uint8ArrayToHex;exports.validateWalletPubkey=t.validateWalletPubkey;exports.BITCOIN_ADDRESS_RE=c.BITCOIN_ADDRESS_RE;exports.HEX_RE=c.HEX_RE;exports.KNOWN_SCRIPT_PREFIXES=c.KNOWN_SCRIPT_PREFIXES;exports.MAX_REASONABLE_FEE_SATS=c.MAX_REASONABLE_FEE_SATS;exports.TXID_RE=c.TXID_RE;exports.combineAbortSignals=c.combineAbortSignals;exports.createTaprootScriptPathSignOptions=O.createTaprootScriptPathSignOptions;exports.COMMISSION_BPS_HEADROOM=u.COMMISSION_BPS_HEADROOM;exports.MAX_ACCEPTABLE_COMMISSION_BPS_CAP=u.MAX_ACCEPTABLE_COMMISSION_BPS_CAP;exports.PeginManager=u.PeginManager;exports.buildDepositTerms=u.buildDepositTerms;exports.capMaxAcceptableCommissionBps=u.capMaxAcceptableCommissionBps;exports.computeWotsBlockPublicKeysHash=u.computeWotsBlockPublicKeysHash;exports.deriveWotsBlocksFromSeed=u.deriveWotsBlocksFromSeed;exports.ensurePrePeginTermsApproval=u.ensurePrePeginTermsApproval;exports.estimateSubmitPeginRequestBatchGas=u.estimateSubmitPeginRequestBatchGas;exports.PayoutManager=d.PayoutManager;exports.computeHashlock=d.computeHashlock;exports.forwardDepositApproval=d.forwardDepositApproval;exports.supportsDepositApproval=d.supportsDepositApproval;exports.validateSecretAgainstHashlock=d.validateSecretAgainstHashlock;exports.ApplicationRegistryABI=_.ApplicationRegistryABI;exports.ProtocolParamsABI=_.ProtocolParamsABI;exports.BTCVaultRegistryABI=C.BTCVaultRegistryABI;exports.BTCVaultRegistryKeyEpochsABI=b.BTCVaultRegistryKeyEpochsABI;exports.CONTRACT_ERRORS=p.CONTRACT_ERRORS;exports.extractErrorData=p.extractErrorData;exports.getContractErrorMessage=p.getContractErrorMessage;exports.handleContractError=p.handleContractError;exports.isKnownContractError=p.isKnownContractError;exports.VAULT_APP_NAME=P.VAULT_APP_NAME;exports.buildFundingOutpointsCommitment=P.buildFundingOutpointsCommitment;exports.buildVaultContext=P.buildVaultContext;exports.deriveVaultRoot=P.deriveVaultRoot;exports.forwardDeriveContextHash=P.forwardDeriveContextHash;exports.parseFundingOutpointsFromTx=P.parseFundingOutpointsFromTx;exports.BitcoinNetworks=y.BitcoinNetworks;exports.BitcoinScriptType=o.BitcoinScriptType;exports.applyChangeOutputPolicy=o.applyChangeOutputPolicy;exports.calculateBtcTxHash=o.calculateBtcTxHash;exports.computeChangeOutputFeeSats=o.computeChangeOutputFeeSats;exports.computeMaxDeposit=o.computeMaxDeposit;exports.computePeginBaseFeeSats=o.computePeginBaseFeeSats;exports.getDustThreshold=o.getDustThreshold;exports.getPsbtInputFields=o.getPsbtInputFields;exports.getScriptType=o.getScriptType;exports.selectUtxosForPegin=o.selectUtxosForPegin;exports.shouldAddChangeOutput=o.shouldAddChangeOutput;exports.waitForTransactionReceiptSmartAware=o.waitForTransactionReceiptSmartAware;exports.BTC_DUST_SAT=i.BTC_DUST_SAT;exports.DUST_THRESHOLD=i.DUST_THRESHOLD;exports.LOW_RATE_ESTIMATION_ACCURACY_BUFFER=i.LOW_RATE_ESTIMATION_ACCURACY_BUFFER;exports.MAX_NON_LEGACY_OUTPUT_SIZE=i.MAX_NON_LEGACY_OUTPUT_SIZE;exports.MAX_REASONABLE_PEGIN_VBYTES=i.MAX_REASONABLE_PEGIN_VBYTES;exports.P2TR_INPUT_SIZE=i.P2TR_INPUT_SIZE;exports.PEGIN_AUTH_ANCHOR_OUTPUTS=i.PEGIN_AUTH_ANCHOR_OUTPUTS;exports.PEGIN_FIXED_OUTPUTS=i.PEGIN_FIXED_OUTPUTS;exports.SPLIT_TX_FEE_SAFETY_MULTIPLIER=i.SPLIT_TX_FEE_SAFETY_MULTIPLIER;exports.TX_BUFFER_SIZE_OVERHEAD=i.TX_BUFFER_SIZE_OVERHEAD;exports.WALLET_RELAY_FEE_RATE_THRESHOLD=i.WALLET_RELAY_FEE_RATE_THRESHOLD;exports.fundPeginTransaction=i.fundPeginTransaction;exports.parseUnfundedWasmTransaction=i.parseUnfundedWasmTransaction;exports.peginOutputCount=i.peginOutputCount;exports.rateBasedTxBufferFee=i.rateBasedTxBufferFee;exports.UtxoNotAvailableError=E.UtxoNotAvailableError;exports.assertUtxosAvailable=E.assertUtxosAvailable;exports.extractInputsFromTransaction=E.extractInputsFromTransaction;exports.findOverlappingPendingVaults=E.findOverlappingPendingVaults;exports.validateUtxosAvailable=E.validateUtxosAvailable;exports.MEMPOOL_API_URLS=a.MEMPOOL_API_URLS;exports.ViemVaultRegistryReader=a.ViemVaultRegistryReader;exports.getAddressTxs=a.getAddressTxs;exports.getAddressUtxos=a.getAddressUtxos;exports.getMempoolApiUrl=a.getMempoolApiUrl;exports.getNetworkFees=a.getNetworkFees;exports.getOutspend=a.getOutspend;exports.getTipHeight=a.getTipHeight;exports.getTxHex=a.getTxHex;exports.getTxInfo=a.getTxInfo;exports.getUtxoInfo=a.getUtxoInfo;exports.pushTx=a.pushTx;exports.validateOffchainParams=a.validateOffchainParams;exports.validatePegInConfiguration=a.validatePegInConfiguration;exports.validateTBVProtocolParams=a.validateTBVProtocolParams;exports.OnChainBtcVaultStatus=r.OnChainBtcVaultStatus;exports.ServerIdentityError=r.ServerIdentityError;exports.VaultProviderRpcClient=r.VaultProviderRpcClient;exports.ViemOperationKeyReader=r.ViemOperationKeyReader;exports.ViemProtocolParamsReader=r.ViemProtocolParamsReader;exports.ViemUniversalChallengerReader=r.ViemUniversalChallengerReader;exports.ViemVaultKeeperReader=r.ViemVaultKeeperReader;exports.VpResponseValidationError=r.VpResponseValidationError;exports.VpTokenRegistry=r.VpTokenRegistry;exports.batchPollByProvider=r.batchPollByProvider;exports.createAuthenticatedVpClient=r.createAuthenticatedVpClient;exports.primeVpTokenRegistry=r.primeVpTokenRegistry;exports.resolveProtocolAddresses=r.resolveProtocolAddresses;exports.validateRequestDepositorClaimerArtifactsResponse=r.validateRequestDepositorClaimerArtifactsResponse;exports.verifyServerIdentity=r.verifyServerIdentity;exports.vpTokenRegistry=r.vpTokenRegistry;exports.AUTH_REJECTED_RPC_CODE=s.AUTH_REJECTED_RPC_CODE;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_BATCH_MAX_SIZE=s.VP_BATCH_MAX_SIZE;exports.VP_TERMINAL_FAILURE_STATUSES=s.VP_TERMINAL_FAILURE_STATUSES;exports.VP_TRANSIENT_STATUSES=s.VP_TRANSIENT_STATUSES;exports.isAuthRejectedError=s.isAuthRejectedError;exports.assertOnChainBtcPubkey=I.assertOnChainBtcPubkey;exports.DEPOSIT_TERMS_REJECTED_ERROR_NAME=T.DEPOSIT_TERMS_REJECTED_ERROR_NAME;exports.DepositTermsRejectedError=T.DepositTermsRejectedError;exports.isDepositTermsRejectedError=T.isDepositTermsRejectedError;exports.isWotsMismatchError=T.isWotsMismatchError;exports.rebuildDepositTermsCore=T.rebuildDepositTermsCore;exports.BIP68NotMatureError=e.BIP68NotMatureError;exports.ClaimerPegoutStatusValue=e.ClaimerPegoutStatusValue;exports.PEGIN_ETH_CONFIRMATIONS=e.PEGIN_ETH_CONFIRMATIONS;exports.ParticipantKeyDriftError=e.ParticipantKeyDriftError;exports.PeginRegistrationMissingError=e.PeginRegistrationMissingError;exports.PeginRegistrationNotFinalError=e.PeginRegistrationNotFinalError;exports.REFUND_MAX_FEE_FRACTION_DENOMINATOR=e.REFUND_MAX_FEE_FRACTION_DENOMINATOR;exports.REFUND_MAX_FEE_FRACTION_NUMERATOR=e.REFUND_MAX_FEE_FRACTION_NUMERATOR;exports.REFUND_MAX_FEE_RATE_SATS_VB=e.REFUND_MAX_FEE_RATE_SATS_VB;exports.REFUND_VSIZE=e.REFUND_VSIZE;exports.RegisteredVaultVersionMismatchError=e.RegisteredVaultVersionMismatchError;exports.activateVault=e.activateVault;exports.activateVaultAndRedeem=e.activateVaultAndRedeem;exports.assertVaultProviderHintAccepted=e.assertVaultProviderHintAccepted;exports.buildAndBroadcastRefund=e.buildAndBroadcastRefund;exports.estimateRefundFeeSats=e.estimateRefundFeeSats;exports.isDepositAmountValid=e.isDepositAmountValid;exports.isHintAccepted=e.isHintAccepted;exports.isParticipantKeyDriftError=e.isParticipantKeyDriftError;exports.isPeginRegistrationMissingError=e.isPeginRegistrationMissingError;exports.isPeginRegistrationNotFinalError=e.isPeginRegistrationNotFinalError;exports.isPegoutTerminalStatus=e.isPegoutTerminalStatus;exports.isRecognizedPegoutStatus=e.isRecognizedPegoutStatus;exports.isRegisteredVaultVersionMismatchError=e.isRegisteredVaultVersionMismatchError;exports.matchKeyHint=e.matchKeyHint;exports.matchKeySetHint=e.matchKeySetHint;exports.resolveCurrentParticipantKeys=e.resolveCurrentParticipantKeys;exports.resolveParticipantKeysAtEpochs=e.resolveParticipantKeysAtEpochs;exports.runDepositorPresignFlow=e.runDepositorPresignFlow;exports.signDepositorGraph=e.signDepositorGraph;exports.submitWotsPublicKey=e.submitWotsPublicKey;exports.validateDepositAmount=e.validateDepositAmount;exports.validateMultiVaultDepositInputs=e.validateMultiVaultDepositInputs;exports.validateOnChainParticipantKeys=e.validateOnChainParticipantKeys;exports.validateProviderSelection=e.validateProviderSelection;exports.validateRemainingCapacity=e.validateRemainingCapacity;exports.validateVaultAmounts=e.validateVaultAmounts;exports.validateVaultProviderPubkey=e.validateVaultProviderPubkey;exports.verifyRegisteredParticipantKeys=e.verifyRegisteredParticipantKeys;exports.verifyRegisteredVaultVersions=e.verifyRegisteredVaultVersions;exports.waitForPeginRegistrationDepth=e.waitForPeginRegistrationDepth;exports.waitForPeginStatus=e.waitForPeginStatus;exports.ContractStatus=g.ContractStatus;exports.PeginAction=g.PeginAction;exports.canPerformAction=g.canPerformAction;exports.getPeginProtocolState=g.getPeginProtocolState;exports.isActivationDeadlinePassedOnChain=g.isActivationDeadlinePassedOnChain;
|
|
2
2
|
//# sourceMappingURL=index.cjs.map
|
package/dist/index.js
CHANGED
|
@@ -7,10 +7,10 @@ import { a as V, b as y } from "./noPayout-oaUVsEjk.js";
|
|
|
7
7
|
import { c as N, d as M, a as F, b as B, e as U, f as H, k as L, g as K, h as k, i as X, j as w, p as W, s as G, t as j, u as J, v as Y } from "./bitcoin-d9eaaZB_.js";
|
|
8
8
|
import { B as z, H as q, K as Q, M as $, T as aa, c as ea } from "./validation-Dj3dqYtl.js";
|
|
9
9
|
import { c as ta } from "./signing-DaLvGwQe.js";
|
|
10
|
-
import { C as ia, M as oa, P as na, b as pa, a as ua, c as la, d as Pa, f as ca, e as da } from "./PeginManager-
|
|
10
|
+
import { C as ia, M as oa, P as na, b as pa, a as ua, c as la, d as Pa, f as ca, e as da } from "./PeginManager-ozwQaRwj.js";
|
|
11
11
|
import { P as Aa, c as Ta, f as ga, s as Ra, v as Sa } from "./signPsbtsWithFallback-DC4rUCsy.js";
|
|
12
|
-
import { A as ma, P as fa } from "./ProtocolParams.abi-
|
|
13
|
-
import { B as Ca } from "./BTCVaultRegistry.abi-
|
|
12
|
+
import { A as ma, P as fa } from "./ProtocolParams.abi-C0TSRaHV.js";
|
|
13
|
+
import { B as Ca } from "./BTCVaultRegistry.abi-CJwWI2EO.js";
|
|
14
14
|
import { B as ba } from "./BTCVaultRegistryKeyEpochs.abi-CXjhRZbm.js";
|
|
15
15
|
import { C as va, e as ha, g as Va, h as ya, i as Da } from "./errors-Blc-JWnI.js";
|
|
16
16
|
import { V as Ma, b as Fa, a as Ba, d as Ua, f as Ha, p as La } from "./parseFundingOutpoints-pBRE11Hr.js";
|
|
@@ -18,12 +18,12 @@ import { BitcoinNetworks as ka } from "./shared/index.js";
|
|
|
18
18
|
import { B as wa, a as Wa, f as Ga, c as ja, b as Ja, d as Ya, g as Za, i as za, h as qa, s as Qa, e as $a, w as ae } from "./waitForTransactionReceiptSmartAware-lobLm0q0.js";
|
|
19
19
|
import { B as se, D as te, L as re, M as ie, c as oe, P as ne, b as pe, a as ue, S as le, T as Pe, W as ce, f as de, d as Ee, p as Ae, r as Te } from "./fundPeginTransaction-B2wyjqp0.js";
|
|
20
20
|
import { U as Re, a as Se, e as _e, f as me, v as fe } from "./reservation-B4i_PQhY.js";
|
|
21
|
-
import { M as Ce, V as Oe, g as be, a as Ie, b as ve, c as he, d as Ve, e as ye, f as De, h as Ne, i as Me, p as Fe, v as Be, j as Ue, k as He } from "./mempoolApi-
|
|
22
|
-
import { O as Ke, S as ke, V as Xe, g as we, h as We, i as Ge, j as je, a as Je, d as Ye, b as Ze, f as ze, p as qe, r as Qe, v as $e, c as as, e as es } from "./batchPoll-
|
|
21
|
+
import { M as Ce, V as Oe, g as be, a as Ie, b as ve, c as he, d as Ve, e as ye, f as De, h as Ne, i as Me, p as Fe, v as Be, j as Ue, k as He } from "./mempoolApi-BxSINXIB.js";
|
|
22
|
+
import { O as Ke, S as ke, V as Xe, g as we, h as We, i as Ge, j as je, a as Je, d as Ye, b as Ze, f as ze, p as qe, r as Qe, v as $e, c as as, e as es } from "./batchPoll-cIxrSLLJ.js";
|
|
23
23
|
import { A as ts, D as rs, J as is, a as os, b as ns, d as ps, P as us, R as ls, e as Ps, c as cs, V as ds, i as Es } from "./json-rpc-client-DuUARJvV.js";
|
|
24
24
|
import { a as Ts } from "./onChainBtcPubkey-DeF4cKoO.js";
|
|
25
|
-
import { D as Rs, a as Ss, b as _s, i as ms, r as fs } from "./errors-
|
|
26
|
-
import { H as Cs, E as Os, P as bs, o as Is, c as vs, d as hs, K as Vs, L as ys, M as Ds, N as Ns, R as Ms, a as Fs, b as Bs, y as Us, I as Hs, J as Ls, g as Ks, z as ks, p as Xs, i as ws, e as Ws, G as Gs, F as js, t as Js, A as Ys, B as Zs, C as zs, D as qs, r as Qs, s as $s, f as at, h as et, j as st, v as tt, k as rt, l as it, m as ot, n as nt, q as pt, u as ut, w as lt, x as Pt } from "./buildAndBroadcastRefund-
|
|
25
|
+
import { D as Rs, a as Ss, b as _s, i as ms, r as fs } from "./errors-BXzrXswV.js";
|
|
26
|
+
import { H as Cs, E as Os, P as bs, o as Is, c as vs, d as hs, K as Vs, L as ys, M as Ds, N as Ns, R as Ms, a as Fs, b as Bs, y as Us, I as Hs, J as Ls, g as Ks, z as ks, p as Xs, i as ws, e as Ws, G as Gs, F as js, t as Js, A as Ys, B as Zs, C as zs, D as qs, r as Qs, s as $s, f as at, h as et, j as st, v as tt, k as rt, l as it, m as ot, n as nt, q as pt, u as ut, w as lt, x as Pt } from "./buildAndBroadcastRefund-DpfBZfLw.js";
|
|
27
27
|
import { C as dt, P as Et, c as At, g as Tt, i as gt } from "./peginState-CxDiaKuk.js";
|
|
28
28
|
export {
|
|
29
29
|
ts as AUTH_REJECTED_RPC_CODE,
|
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
import { B as a } from "./BTCVaultRegistry.abi-
|
|
1
|
+
import { B as a } from "./BTCVaultRegistry.abi-CJwWI2EO.js";
|
|
2
2
|
import { B as d } from "./BTCVaultRegistryKeyEpochs.abi-CXjhRZbm.js";
|
|
3
3
|
import { a as w } from "./onChainBtcPubkey-DeF4cKoO.js";
|
|
4
|
-
import { a as
|
|
5
|
-
import { B as F, H as
|
|
4
|
+
import { a as x } from "./constants-GjWXdaqV.js";
|
|
5
|
+
import { B as F, H as B, K, T as k, c as N } from "./validation-Dj3dqYtl.js";
|
|
6
6
|
const h = 65535, b = 1e4, l = 4294967295, $ = 255;
|
|
7
|
-
function
|
|
7
|
+
function O(t) {
|
|
8
8
|
if (!Number.isInteger(t) || t < 0 || t > l)
|
|
9
9
|
throw new Error(
|
|
10
10
|
`Invalid offchainParamsVersion from contract: must be a uint32, got ${t}`
|
|
11
11
|
);
|
|
12
12
|
}
|
|
13
|
-
function
|
|
13
|
+
function S(t) {
|
|
14
14
|
const e = [];
|
|
15
15
|
if (t.timelockAssert <= 0n && e.push(
|
|
16
16
|
`timelockAssert must be positive, got ${t.timelockAssert}`
|
|
@@ -57,17 +57,17 @@ function R(t) {
|
|
|
57
57
|
throw new Error(`Invalid TBV protocol parameters: ${e.join("; ")}`);
|
|
58
58
|
}
|
|
59
59
|
function L(t) {
|
|
60
|
-
if (R(t),
|
|
60
|
+
if (R(t), S(t.offchainParams), !Number.isInteger(t.offchainParamsVersion) || t.offchainParamsVersion < 0 || t.offchainParamsVersion > l)
|
|
61
61
|
throw new Error(
|
|
62
62
|
`Invalid peg-in configuration: offchainParamsVersion must be a uint32, got ${t.offchainParamsVersion}`
|
|
63
63
|
);
|
|
64
|
-
|
|
64
|
+
x(
|
|
65
65
|
t.activeVaultCoreVersion,
|
|
66
66
|
"ProtocolParams.activeVaultCoreVersion()"
|
|
67
67
|
);
|
|
68
68
|
}
|
|
69
|
-
const
|
|
70
|
-
function
|
|
69
|
+
const I = 9999;
|
|
70
|
+
function P(t) {
|
|
71
71
|
return {
|
|
72
72
|
depositor: t.depositor,
|
|
73
73
|
depositorBtcPubKey: t.depositorBtcPubKey,
|
|
@@ -80,7 +80,7 @@ function I(t) {
|
|
|
80
80
|
}
|
|
81
81
|
function m(t) {
|
|
82
82
|
const e = Number(t.offchainParamsVersion);
|
|
83
|
-
return
|
|
83
|
+
return O(e), {
|
|
84
84
|
depositorSignedPeginTx: t.depositorSignedPeginTx,
|
|
85
85
|
universalChallengersVersion: t.universalChallengersVersion,
|
|
86
86
|
appVaultKeepersVersion: t.appVaultKeepersVersion,
|
|
@@ -222,7 +222,7 @@ class W {
|
|
|
222
222
|
functionName: "getBtcVaultBasicInfo",
|
|
223
223
|
args: [e]
|
|
224
224
|
});
|
|
225
|
-
return
|
|
225
|
+
return P(o);
|
|
226
226
|
}
|
|
227
227
|
async getVaultProtocolInfo(e) {
|
|
228
228
|
const o = await this.publicClient.readContract({
|
|
@@ -277,9 +277,9 @@ class W {
|
|
|
277
277
|
functionName: "getVaultProviderCommission",
|
|
278
278
|
args: [e]
|
|
279
279
|
});
|
|
280
|
-
if (!Number.isInteger(o) || o < 0 || o >
|
|
280
|
+
if (!Number.isInteger(o) || o < 0 || o > I)
|
|
281
281
|
throw new Error(
|
|
282
|
-
`getVaultProviderCommission returned ${o} bps for ${e}, outside the protocol range [0, ${
|
|
282
|
+
`getVaultProviderCommission returned ${o} bps for ${e}, outside the protocol range [0, ${I}]`
|
|
283
283
|
);
|
|
284
284
|
return o;
|
|
285
285
|
}
|
|
@@ -300,37 +300,13 @@ class W {
|
|
|
300
300
|
}
|
|
301
301
|
],
|
|
302
302
|
allowFailure: !1
|
|
303
|
-
}), i =
|
|
303
|
+
}), i = P(o), r = m(n);
|
|
304
304
|
if (!r.depositorSignedPeginTx || r.depositorSignedPeginTx === "0x")
|
|
305
305
|
throw new Error(
|
|
306
306
|
`Vault ${e} not found on-chain or has no pegin transaction`
|
|
307
307
|
);
|
|
308
308
|
return { basic: i, protocol: r };
|
|
309
309
|
}
|
|
310
|
-
/**
|
|
311
|
-
* Read `offchainParamsVersion` for many vaults in a single multicall.
|
|
312
|
-
* Reads only `getBtcVaultProtocolInfo` (one read per vault), so an N-vault
|
|
313
|
-
* batch costs one RPC round-trip instead of 2N parallel `eth_call`s.
|
|
314
|
-
*/
|
|
315
|
-
async getOffchainParamsVersionsByVaultIds(e) {
|
|
316
|
-
return e.length === 0 ? [] : (await this.publicClient.multicall({
|
|
317
|
-
contracts: e.map((n) => ({
|
|
318
|
-
address: this.contractAddress,
|
|
319
|
-
abi: a,
|
|
320
|
-
functionName: "getBtcVaultProtocolInfo",
|
|
321
|
-
args: [n]
|
|
322
|
-
})),
|
|
323
|
-
allowFailure: !1
|
|
324
|
-
})).map((n) => {
|
|
325
|
-
const i = n;
|
|
326
|
-
if (!i.depositorSignedPeginTx || i.depositorSignedPeginTx === "0x")
|
|
327
|
-
throw new Error(
|
|
328
|
-
"Vault not found on-chain or has no pegin transaction while reading offchain params version"
|
|
329
|
-
);
|
|
330
|
-
const r = Number(i.offchainParamsVersion);
|
|
331
|
-
return T(r), r;
|
|
332
|
-
});
|
|
333
|
-
}
|
|
334
310
|
}
|
|
335
311
|
const U = 21e6 * 1e8, V = 3e4;
|
|
336
312
|
async function f(t, e) {
|
|
@@ -339,7 +315,7 @@ async function f(t, e) {
|
|
|
339
315
|
V
|
|
340
316
|
), i = [o.signal, e == null ? void 0 : e.signal].filter(
|
|
341
317
|
Boolean
|
|
342
|
-
), r =
|
|
318
|
+
), r = N(i);
|
|
343
319
|
try {
|
|
344
320
|
return await fetch(t, {
|
|
345
321
|
...e,
|
|
@@ -352,7 +328,7 @@ async function f(t, e) {
|
|
|
352
328
|
}
|
|
353
329
|
}
|
|
354
330
|
const A = 1e4;
|
|
355
|
-
function
|
|
331
|
+
function T(t) {
|
|
356
332
|
return Number.isInteger(t) && t > 0 && t <= U;
|
|
357
333
|
}
|
|
358
334
|
function M(t) {
|
|
@@ -362,19 +338,19 @@ function g(t, e) {
|
|
|
362
338
|
return !Number.isInteger(t) || t < 0 ? !1 : e === void 0 || t < e;
|
|
363
339
|
}
|
|
364
340
|
function u(t) {
|
|
365
|
-
if (!
|
|
341
|
+
if (!k.test(t))
|
|
366
342
|
throw new Error(`Invalid transaction ID format: ${t}`);
|
|
367
343
|
}
|
|
368
|
-
function
|
|
344
|
+
function C(t) {
|
|
369
345
|
if (!F.test(t))
|
|
370
346
|
throw new Error(`Invalid Bitcoin address format: ${t}`);
|
|
371
347
|
}
|
|
372
|
-
function
|
|
373
|
-
if (!
|
|
348
|
+
function v(t, e) {
|
|
349
|
+
if (!B.test(t))
|
|
374
350
|
throw new Error(
|
|
375
351
|
`Invalid scriptPubKey: not valid hex for ${e}`
|
|
376
352
|
);
|
|
377
|
-
if (!
|
|
353
|
+
if (!K.some(
|
|
378
354
|
(n) => t.toLowerCase().startsWith(n)
|
|
379
355
|
))
|
|
380
356
|
throw new Error(
|
|
@@ -467,9 +443,9 @@ async function tt(t, e, o) {
|
|
|
467
443
|
`Invalid vout ${e} for transaction ${t} (has ${n.vout.length} outputs)`
|
|
468
444
|
);
|
|
469
445
|
const i = n.vout[e];
|
|
470
|
-
if (!
|
|
446
|
+
if (!T(i.value))
|
|
471
447
|
throw new Error(`Invalid UTXO value ${i.value} for ${t}:${e}`);
|
|
472
|
-
return
|
|
448
|
+
return v(i.scriptpubkey, `${t}:${e}`), {
|
|
473
449
|
txid: t,
|
|
474
450
|
vout: e,
|
|
475
451
|
value: i.value,
|
|
@@ -477,18 +453,18 @@ async function tt(t, e, o) {
|
|
|
477
453
|
};
|
|
478
454
|
}
|
|
479
455
|
async function et(t, e) {
|
|
480
|
-
|
|
456
|
+
C(t);
|
|
481
457
|
try {
|
|
482
458
|
const o = await c(`${e}/address/${t}/utxo`), n = await c(`${e}/v1/validate-address/${t}`);
|
|
483
459
|
if (!n.isvalid)
|
|
484
460
|
throw new Error(
|
|
485
461
|
`Invalid Bitcoin address: ${t}. Mempool API validation failed.`
|
|
486
462
|
);
|
|
487
|
-
|
|
463
|
+
v(n.scriptPubKey, t);
|
|
488
464
|
for (const r of o) {
|
|
489
465
|
if (u(r.txid), !g(r.vout))
|
|
490
466
|
throw new Error(`Invalid vout ${r.vout} for ${r.txid}`);
|
|
491
|
-
if (!
|
|
467
|
+
if (!T(r.value))
|
|
492
468
|
throw new Error(
|
|
493
469
|
`Invalid UTXO value ${r.value} for ${r.txid}:${r.vout}`
|
|
494
470
|
);
|
|
@@ -512,7 +488,7 @@ function ot(t) {
|
|
|
512
488
|
return H[t];
|
|
513
489
|
}
|
|
514
490
|
async function nt(t, e) {
|
|
515
|
-
return
|
|
491
|
+
return C(t), c(`${e}/address/${t}/txs`);
|
|
516
492
|
}
|
|
517
493
|
async function rt(t) {
|
|
518
494
|
const e = await f(`${t}/v1/fees/recommended`);
|
|
@@ -552,8 +528,8 @@ export {
|
|
|
552
528
|
tt as i,
|
|
553
529
|
L as j,
|
|
554
530
|
R as k,
|
|
555
|
-
|
|
531
|
+
O as l,
|
|
556
532
|
J as p,
|
|
557
|
-
|
|
533
|
+
S as v
|
|
558
534
|
};
|
|
559
|
-
//# sourceMappingURL=mempoolApi-
|
|
535
|
+
//# sourceMappingURL=mempoolApi-BxSINXIB.js.map
|