@babylonlabs-io/ts-sdk 0.79.1 → 1.0.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.
Files changed (90) hide show
  1. package/README.md +11 -5
  2. package/dist/{PeginManager-BuVSknB0.cjs → PeginManager-BCJWwV05.cjs} +2 -2
  3. package/dist/{PeginManager-BuVSknB0.cjs.map → PeginManager-BCJWwV05.cjs.map} +1 -1
  4. package/dist/{PeginManager-BXlh3ar0.js → PeginManager-BH_AKu4l.js} +5 -5
  5. package/dist/{PeginManager-BXlh3ar0.js.map → PeginManager-BH_AKu4l.js.map} +1 -1
  6. package/dist/{buildAndBroadcastReclaim-N9dXH9dm.cjs → buildAndBroadcastReclaim-DLsf5hjO.cjs} +2 -2
  7. package/dist/{buildAndBroadcastReclaim-N9dXH9dm.cjs.map → buildAndBroadcastReclaim-DLsf5hjO.cjs.map} +1 -1
  8. package/dist/{buildAndBroadcastReclaim-O6z9kvc4.js → buildAndBroadcastReclaim-OMvihzJg.js} +4 -4
  9. package/dist/{buildAndBroadcastReclaim-O6z9kvc4.js.map → buildAndBroadcastReclaim-OMvihzJg.js.map} +1 -1
  10. package/dist/index.cjs +1 -1
  11. package/dist/index.js +8 -8
  12. package/dist/noPayout-DAWBQ0eG.cjs +2 -0
  13. package/dist/noPayout-DAWBQ0eG.cjs.map +1 -0
  14. package/dist/{noPayout-DiGr4eas.js → noPayout-qBXWKwav.js} +3 -3
  15. package/dist/noPayout-qBXWKwav.js.map +1 -0
  16. package/dist/{parseFundingOutpoints-B4iQeX6q.cjs → parseFundingOutpoints-BwC3foxS.cjs} +2 -2
  17. package/dist/parseFundingOutpoints-BwC3foxS.cjs.map +1 -0
  18. package/dist/{parseFundingOutpoints-BQWvINfm.js → parseFundingOutpoints-CC4NKYz2.js} +19 -19
  19. package/dist/parseFundingOutpoints-CC4NKYz2.js.map +1 -0
  20. package/dist/shared/index.cjs.map +1 -1
  21. package/dist/shared/index.js.map +1 -1
  22. package/dist/shared/wallets/interfaces/BitcoinWallet.d.ts +6 -3
  23. package/dist/shared/wallets/interfaces/BitcoinWallet.d.ts.map +1 -1
  24. package/dist/{signPsbtsWithFallback-f7QLp0q8.js → signPsbtsWithFallback-DoRbHHua.js} +2 -2
  25. package/dist/{signPsbtsWithFallback-f7QLp0q8.js.map → signPsbtsWithFallback-DoRbHHua.js.map} +1 -1
  26. package/dist/{signPsbtsWithFallback-DtwzL5AA.cjs → signPsbtsWithFallback-FwrTYZS4.cjs} +2 -2
  27. package/dist/{signPsbtsWithFallback-DtwzL5AA.cjs.map → signPsbtsWithFallback-FwrTYZS4.cjs.map} +1 -1
  28. package/dist/tbv/core/index.cjs +1 -1
  29. package/dist/tbv/core/index.d.ts +1 -1
  30. package/dist/tbv/core/index.js +8 -8
  31. package/dist/tbv/core/managers/index.cjs +1 -1
  32. package/dist/tbv/core/managers/index.js +2 -2
  33. package/dist/tbv/core/primitives/index.cjs +1 -1
  34. package/dist/tbv/core/primitives/index.js +3 -3
  35. package/dist/tbv/core/primitives/psbt/__tests__/assertPeginTxShape.test.d.ts +5 -3
  36. package/dist/tbv/core/primitives/psbt/__tests__/assertPeginTxShape.test.d.ts.map +1 -1
  37. package/dist/tbv/core/primitives/psbt/__tests__/deriveExpectedPeginPayoutScriptPubKey.test.d.ts +8 -0
  38. package/dist/tbv/core/primitives/psbt/__tests__/deriveExpectedPeginPayoutScriptPubKey.test.d.ts.map +1 -0
  39. package/dist/tbv/core/primitives/psbt/assertWasmPeginSizing.d.ts +6 -0
  40. package/dist/tbv/core/primitives/psbt/assertWasmPeginSizing.d.ts.map +1 -1
  41. package/dist/tbv/core/primitives/psbt/pegin.d.ts +4 -1
  42. package/dist/tbv/core/primitives/psbt/pegin.d.ts.map +1 -1
  43. package/dist/tbv/core/recovery/recoveryErrors.d.ts +1 -1
  44. package/dist/tbv/core/services/index.cjs +1 -1
  45. package/dist/tbv/core/services/index.js +2 -2
  46. package/dist/tbv/core/vault-secrets/__tests__/context.golden.test.d.ts +4 -4
  47. package/dist/tbv/core/vault-secrets/__tests__/context.test.d.ts +1 -2
  48. package/dist/tbv/core/vault-secrets/__tests__/context.test.d.ts.map +1 -1
  49. package/dist/tbv/core/vault-secrets/__tests__/deriveContextHash.vectors.test.d.ts +40 -0
  50. package/dist/tbv/core/vault-secrets/__tests__/deriveContextHash.vectors.test.d.ts.map +1 -0
  51. package/dist/tbv/core/vault-secrets/context.d.ts +2 -2
  52. package/dist/tbv/core/vault-secrets/deriveVaultRoot.d.ts +5 -6
  53. package/dist/tbv/core/vault-secrets/deriveVaultRoot.d.ts.map +1 -1
  54. package/dist/tbv/core/vault-secrets/index.cjs +1 -1
  55. package/dist/tbv/core/vault-secrets/index.d.ts +2 -2
  56. package/dist/tbv/core/vault-secrets/index.js +1 -1
  57. package/dist/tbv/core/wasm/index.cjs +1 -1
  58. package/dist/tbv/core/wasm/index.cjs.map +1 -1
  59. package/dist/tbv/core/wasm/index.d.ts +11 -9
  60. package/dist/tbv/core/wasm/index.d.ts.map +1 -1
  61. package/dist/tbv/core/wasm/index.js +68 -79
  62. package/dist/tbv/core/wasm/index.js.map +1 -1
  63. package/dist/tbv/index.cjs +1 -1
  64. package/dist/tbv/index.js +8 -8
  65. package/dist/testing/MockBitcoinWallet.d.ts +1 -1
  66. package/dist/testing/index.cjs.map +1 -1
  67. package/dist/testing/index.js.map +1 -1
  68. package/dist/{toRefundInputs-9inv4Ai4.js → toRefundInputs-BEulLgN_.js} +5 -5
  69. package/dist/toRefundInputs-BEulLgN_.js.map +1 -0
  70. package/dist/{toRefundInputs-DitGWAnz.cjs → toRefundInputs-DEPXcrgO.cjs} +2 -2
  71. package/dist/toRefundInputs-DEPXcrgO.cjs.map +1 -0
  72. package/dist/{verifyKeyPathSchnorrSignature-BVtNwgK6.js → verifyKeyPathSchnorrSignature-BQHNhRj6.js} +2 -2
  73. package/dist/{verifyKeyPathSchnorrSignature-BVtNwgK6.js.map → verifyKeyPathSchnorrSignature-BQHNhRj6.js.map} +1 -1
  74. package/dist/{verifyKeyPathSchnorrSignature-BjB8Znly.cjs → verifyKeyPathSchnorrSignature-Gm9EmZkx.cjs} +2 -2
  75. package/dist/{verifyKeyPathSchnorrSignature-BjB8Znly.cjs.map → verifyKeyPathSchnorrSignature-Gm9EmZkx.cjs.map} +1 -1
  76. package/dist/verifyScriptPathSchnorrSignature-BKZihCjk.cjs +2 -0
  77. package/dist/verifyScriptPathSchnorrSignature-BKZihCjk.cjs.map +1 -0
  78. package/dist/{verifyScriptPathSchnorrSignature-D_epga4j.js → verifyScriptPathSchnorrSignature-CpjSTfMj.js} +371 -330
  79. package/dist/verifyScriptPathSchnorrSignature-CpjSTfMj.js.map +1 -0
  80. package/package.json +3 -3
  81. package/dist/noPayout-4RZB2g1e.cjs +0 -2
  82. package/dist/noPayout-4RZB2g1e.cjs.map +0 -1
  83. package/dist/noPayout-DiGr4eas.js.map +0 -1
  84. package/dist/parseFundingOutpoints-B4iQeX6q.cjs.map +0 -1
  85. package/dist/parseFundingOutpoints-BQWvINfm.js.map +0 -1
  86. package/dist/toRefundInputs-9inv4Ai4.js.map +0 -1
  87. package/dist/toRefundInputs-DitGWAnz.cjs.map +0 -1
  88. package/dist/verifyScriptPathSchnorrSignature-D_epga4j.js.map +0 -1
  89. package/dist/verifyScriptPathSchnorrSignature-DaRqvEgW.cjs +0 -2
  90. package/dist/verifyScriptPathSchnorrSignature-DaRqvEgW.cjs.map +0 -1
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const a=require("../verifyScriptPathSchnorrSignature-DaRqvEgW.cjs"),O=require("../secp256k1-DDHQ1_za.cjs"),P=require("./core/wasm/index.cjs"),R=require("../verifyKeyPathSchnorrSignature-BjB8Znly.cjs"),l=require("../noPayout-4RZB2g1e.cjs"),N=require("../challengeAssert-Z7_YULBb.cjs"),r=require("../bitcoin-D-O2GjbC.cjs"),h=require("../abortSignals-msbmbqFe.cjs"),I=require("../signing-BJ3X66b-.cjs"),c=require("../validation-C6XTfZak.cjs"),F=require("./core/utils/eth/index.cjs"),A=require("../PeginManager-BuVSknB0.cjs"),d=require("../signPsbtsWithFallback-DtwzL5AA.cjs"),o=require("./core/clients/mempool/index.cjs"),p=require("../types-C1tpDycc.cjs"),v=require("../onChainBtcPubkey-BbxRrbvg.cjs"),s=require("../pegin-registration-client-CZgcU2_0.cjs"),C=require("../ProtocolParams.abi-Db2USqQm.cjs"),y=require("../BTCVaultRegistry.abi-BQ5tFNSu.cjs"),E=require("../BTCVaultRegistryKeyEpochs.abi-DCJnzKer.cjs"),_=require("../parseFundingOutpoints-B4iQeX6q.cjs"),u=require("../psbtInputFields-BrV_ZfL_.cjs"),i=require("../fundPeginTransaction-54-Rwb2k.cjs"),T=require("../reservation-Dr2HLCxx.cjs"),m=require("../index-CK1Xvq4K.cjs"),n=require("../json-rpc-client-BiAmg_ho.cjs"),g=require("../primeVpAuth-BOGKniTl.cjs"),t=require("../toRefundInputs-DitGWAnz.cjs"),e=require("../buildAndBroadcastReclaim-N9dXH9dm.cjs"),S=require("../peginState-eaQ4IO_R.cjs");exports.PEGIN_DEPOSITOR_CLAIM_VOUT=a.PEGIN_DEPOSITOR_CLAIM_VOUT;exports.PsbtSubstitutionError=a.PsbtSubstitutionError;exports.assertPsbtUnsignedTxMatches=a.assertPsbtUnsignedTxMatches;exports.assertScriptPathSchnorrSignature=a.assertScriptPathSchnorrSignature;exports.buildPayoutPsbt=a.buildPayoutPsbt;exports.buildPeginTxFromFundedPrePegin=a.buildPeginTxFromFundedPrePegin;exports.buildPrePeginPsbt=a.buildPrePeginPsbt;exports.computeNumLocalChallengers=a.computeNumLocalChallengers;exports.createPayoutScript=a.createPayoutScript;exports.deriveDepositorClaimDescriptor=a.deriveDepositorClaimDescriptor;exports.deriveDepositorClaimScriptPubKey=a.deriveDepositorClaimScriptPubKey;exports.extractPayoutSignature=a.extractPayoutSignature;exports.assertValidVaultCoreVersion=O.assertValidVaultCoreVersion;exports.computeMinClaimValue=P.computeMinClaimValue;exports.computeMinPeginFee=P.computeMinPeginFee;exports.deriveVaultId=P.deriveVaultId;exports.expandAuthAnchor=P.expandAuthAnchor;exports.expandHashlockSecret=P.expandHashlockSecret;exports.expandWotsSeed=P.expandWotsSeed;exports.peginP2aAnchorOutput=P.peginP2aAnchorOutput;exports.supportedTxGraphVersions=P.supportedTxGraphVersions;exports.validatePeginP2aAnchor=P.validatePeginP2aAnchor;exports.assertKeyPathSchnorrSignature=R.assertKeyPathSchnorrSignature;exports.assertReturnedKeyPathSignatures=R.assertReturnedKeyPathSignatures;exports.buildPeginInputPsbt=R.buildPeginInputPsbt;exports.extractPeginInputSignature=R.extractPeginInputSignature;exports.finalizePeginInputPsbt=R.finalizePeginInputPsbt;exports.buildNoPayoutPsbt=l.buildNoPayoutPsbt;exports.buildReclaimPsbt=l.buildReclaimPsbt;exports.buildRefundPsbt=l.buildRefundPsbt;exports.estimateReclaimFeeSats=l.estimateReclaimFeeSats;exports.finalizeScriptPathWithSignatures=l.finalizeScriptPathWithSignatures;exports.reclaimVsize=l.reclaimVsize;exports.buildChallengeAssertPsbt=N.buildChallengeAssertPsbt;exports.canonicalizeBtcPubkey=r.canonicalizeBtcPubkey;exports.deriveBip86ScriptPubKeyHex=r.deriveBip86ScriptPubKeyHex;exports.deriveNativeSegwitAddress=r.deriveNativeSegwitAddress;exports.deriveTaprootAddress=r.deriveTaprootAddress;exports.ensureHexPrefix=r.ensureHexPrefix;exports.formatSatoshisToBtc=r.formatSatoshisToBtc;exports.getNetwork=r.getNetwork;exports.getSortedXOnlyPubkeys=r.getSortedXOnlyPubkeys;exports.hexToUint8Array=r.hexToUint8Array;exports.isAddressFromPublicKey=r.isAddressFromPublicKey;exports.isValidHex=r.isValidHex;exports.processPublicKeyToXOnly=r.processPublicKeyToXOnly;exports.stripHexPrefix=r.stripHexPrefix;exports.toXOnly=r.toXOnly;exports.uint8ArrayToHex=r.uint8ArrayToHex;exports.validateWalletPubkey=r.validateWalletPubkey;exports.combineAbortSignals=h.combineAbortSignals;exports.calculateBtcTxHash=I.calculateBtcTxHash;exports.createTaprootScriptPathSignOptions=I.createTaprootScriptPathSignOptions;exports.BITCOIN_ADDRESS_RE=c.BITCOIN_ADDRESS_RE;exports.COMPRESSED_PUBKEY_HEX_LEN=c.COMPRESSED_PUBKEY_HEX_LEN;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.X_ONLY_PUBKEY_HEX_LEN=c.X_ONLY_PUBKEY_HEX_LEN;exports.waitForTransactionReceiptSmartAware=F.waitForTransactionReceiptSmartAware;exports.PeginManager=A.PeginManager;exports.buildDepositTerms=A.buildDepositTerms;exports.computeWotsBlockPublicKeysHash=A.computeWotsBlockPublicKeysHash;exports.deriveWotsBlocksFromSeed=A.deriveWotsBlocksFromSeed;exports.ensurePrePeginTermsApproval=A.ensurePrePeginTermsApproval;exports.PayoutManager=d.PayoutManager;exports.computeHashlock=d.computeHashlock;exports.forwardDepositApproval=d.forwardDepositApproval;exports.requireChangeAddress=d.requireChangeAddress;exports.supportsDepositApproval=d.supportsDepositApproval;exports.validateSecretAgainstHashlock=d.validateSecretAgainstHashlock;exports.MEMPOOL_API_URLS=o.MEMPOOL_API_URLS;exports.getAddressTxs=o.getAddressTxs;exports.getAddressUtxos=o.getAddressUtxos;exports.getMempoolApiUrl=o.getMempoolApiUrl;exports.getNetworkFees=o.getNetworkFees;exports.getOutspend=o.getOutspend;exports.getTipHeight=o.getTipHeight;exports.getTxHex=o.getTxHex;exports.getTxInfo=o.getTxInfo;exports.getUtxoInfo=o.getUtxoInfo;exports.pushTx=o.pushTx;exports.OnChainBtcVaultStatus=p.OnChainBtcVaultStatus;exports.ViemOperationKeyReader=p.ViemOperationKeyReader;exports.ViemProtocolParamsReader=p.ViemProtocolParamsReader;exports.ViemUniversalChallengerReader=p.ViemUniversalChallengerReader;exports.ViemVaultKeeperReader=p.ViemVaultKeeperReader;exports.resolveProtocolAddresses=p.resolveProtocolAddresses;exports.assertOnChainBtcPubkey=v.assertOnChainBtcPubkey;exports.COMMISSION_BPS_HEADROOM=s.COMMISSION_BPS_HEADROOM;exports.MAX_ACCEPTABLE_COMMISSION_BPS_CAP=s.MAX_ACCEPTABLE_COMMISSION_BPS_CAP;exports.RegistrationLogsUnavailableError=s.RegistrationLogsUnavailableError;exports.ViemPeginRegistrationClient=s.ViemPeginRegistrationClient;exports.ViemVaultRegistryReader=s.ViemVaultRegistryReader;exports.capMaxAcceptableCommissionBps=s.capMaxAcceptableCommissionBps;exports.derivePeginVaultId=s.derivePeginVaultId;exports.isRegistrationLogsUnavailableError=s.isRegistrationLogsUnavailableError;exports.validateOffchainParams=s.validateOffchainParams;exports.validatePegInConfiguration=s.validatePegInConfiguration;exports.validateTBVProtocolParams=s.validateTBVProtocolParams;exports.ApplicationRegistryABI=C.ApplicationRegistryABI;exports.ProtocolParamsABI=C.ProtocolParamsABI;exports.BTCVaultRegistryABI=y.BTCVaultRegistryABI;exports.BTCVaultRegistryKeyEpochsABI=E.BTCVaultRegistryKeyEpochsABI;exports.CONTRACT_ERRORS=E.CONTRACT_ERRORS;exports.PEGIN_FINGERPRINT_CHANGED_SELECTOR=E.PEGIN_FINGERPRINT_CHANGED_SELECTOR;exports.PeginFingerprintChangedError=E.PeginFingerprintChangedError;exports.extractErrorData=E.extractErrorData;exports.getContractErrorMessage=E.getContractErrorMessage;exports.handleContractError=E.handleContractError;exports.isKnownContractError=E.isKnownContractError;exports.isPeginFingerprintChangedError=E.isPeginFingerprintChangedError;exports.VAULT_APP_NAME=_.VAULT_APP_NAME;exports.buildFundingOutpointsCommitment=_.buildFundingOutpointsCommitment;exports.buildVaultContext=_.buildVaultContext;exports.deriveVaultRoot=_.deriveVaultRoot;exports.forwardDeriveContextHash=_.forwardDeriveContextHash;exports.parseFundingOutpointsFromTx=_.parseFundingOutpointsFromTx;exports.BitcoinScriptType=u.BitcoinScriptType;exports.applyChangeOutputPolicy=u.applyChangeOutputPolicy;exports.computeChangeOutputFeeSats=u.computeChangeOutputFeeSats;exports.computeMaxDeposit=u.computeMaxDeposit;exports.computePeginBaseFeeSats=u.computePeginBaseFeeSats;exports.getDustThreshold=u.getDustThreshold;exports.getPsbtInputFields=u.getPsbtInputFields;exports.getScriptType=u.getScriptType;exports.selectUtxosForPegin=u.selectUtxosForPegin;exports.shouldAddChangeOutput=u.shouldAddChangeOutput;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=T.UtxoNotAvailableError;exports.assertUtxosAvailable=T.assertUtxosAvailable;exports.extractInputsFromTransaction=T.extractInputsFromTransaction;exports.findOverlappingPendingVaults=T.findOverlappingPendingVaults;exports.validateUtxosAvailable=T.validateUtxosAvailable;exports.VaultProviderRpcClient=m.VaultProviderRpcClient;exports.VpResponseValidationError=m.VpResponseValidationError;exports.batchPollByProvider=m.batchPollByProvider;exports.validateRequestDepositorClaimerArtifactsResponse=m.validateRequestDepositorClaimerArtifactsResponse;exports.AUTH_REJECTED_RPC_CODE=n.AUTH_REJECTED_RPC_CODE;exports.DaemonStatus=n.DaemonStatus;exports.JSON_RPC_ERROR_CODES=n.JSON_RPC_ERROR_CODES;exports.JsonRpcClient=n.JsonRpcClient;exports.JsonRpcError=n.JsonRpcError;exports.POST_WOTS_STATUSES=n.POST_WOTS_STATUSES;exports.PRE_DEPOSITOR_SIGNATURES_STATES=n.PRE_DEPOSITOR_SIGNATURES_STATES;exports.RpcErrorCode=n.RpcErrorCode;exports.VP_BATCH_MAX_SIZE=n.VP_BATCH_MAX_SIZE;exports.VP_TERMINAL_FAILURE_STATUSES=n.VP_TERMINAL_FAILURE_STATUSES;exports.VP_TRANSIENT_STATUSES=n.VP_TRANSIENT_STATUSES;exports.isAuthRejectedError=n.isAuthRejectedError;exports.ServerIdentityError=g.ServerIdentityError;exports.VpTokenRegistry=g.VpTokenRegistry;exports.createAuthenticatedVpClient=g.createAuthenticatedVpClient;exports.primeVpTokenRegistry=g.primeVpTokenRegistry;exports.verifyServerIdentity=g.verifyServerIdentity;exports.vpTokenRegistry=g.vpTokenRegistry;exports.DEPOSIT_TERMS_REJECTED_ERROR_NAME=t.DEPOSIT_TERMS_REJECTED_ERROR_NAME;exports.DepositTermsRejectedError=t.DepositTermsRejectedError;exports.PEGIN_FINGERPRINT_DOMAIN=t.PEGIN_FINGERPRINT_DOMAIN;exports.PEGIN_FINGERPRINT_DOMAIN_PREIMAGE=t.PEGIN_FINGERPRINT_DOMAIN_PREIMAGE;exports.PeginFingerprintInputError=t.PeginFingerprintInputError;exports.PeginParamsAmbiguousError=t.PeginParamsAmbiguousError;exports.PeginParamsIncompleteSpaceError=t.PeginParamsIncompleteSpaceError;exports.PeginParamsNotFoundError=t.PeginParamsNotFoundError;exports.PeginSizingIntegrityError=t.PeginSizingIntegrityError;exports.UnanchoredPrePeginError=t.UnanchoredPrePeginError;exports.VaultRootMismatchError=t.VaultRootMismatchError;exports.buildPeginParamsCandidates=t.buildPeginParamsCandidates;exports.computePeginFingerprint=t.computePeginFingerprint;exports.deriveHashlocksFromPrePegin=t.deriveHashlocksFromPrePegin;exports.describePeginParamsCandidate=t.describePeginParamsCandidate;exports.describeUnresolvedVersion=t.describeUnresolvedVersion;exports.encodePeginFingerprintPreimage=t.encodePeginFingerprintPreimage;exports.isDepositTermsRejectedError=t.isDepositTermsRejectedError;exports.isPeginFingerprintInputError=t.isPeginFingerprintInputError;exports.isWotsMismatchError=t.isWotsMismatchError;exports.rebuildDepositTermsCore=t.rebuildDepositTermsCore;exports.reconstructPeginParams=t.reconstructPeginParams;exports.toRefundInputs=t.toRefundInputs;exports.ApplicationEntryPointMismatchError=e.ApplicationEntryPointMismatchError;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.RECLAIM_MAX_FEE_FRACTION_DENOMINATOR=e.RECLAIM_MAX_FEE_FRACTION_DENOMINATOR;exports.RECLAIM_MAX_FEE_FRACTION_NUMERATOR=e.RECLAIM_MAX_FEE_FRACTION_NUMERATOR;exports.RECLAIM_MAX_FEE_RATE_SATS_VB=e.RECLAIM_MAX_FEE_RATE_SATS_VB;exports.RECLAIM_WARN_FEE_FRACTION_NUMERATOR=e.RECLAIM_WARN_FEE_FRACTION_NUMERATOR;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.ReclaimUneconomicalError=e.ReclaimUneconomicalError;exports.RegisteredVaultVersionMismatchError=e.RegisteredVaultVersionMismatchError;exports.activateVault=e.activateVault;exports.activateVaultAndRedeem=e.activateVaultAndRedeem;exports.assertVaultProviderHintAccepted=e.assertVaultProviderHintAccepted;exports.buildAndBroadcastReclaim=e.buildAndBroadcastReclaim;exports.buildAndBroadcastRefund=e.buildAndBroadcastRefund;exports.estimateRefundFeeSats=e.estimateRefundFeeSats;exports.isApplicationEntryPointMismatchError=e.isApplicationEntryPointMismatchError;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=S.ContractStatus;exports.PeginAction=S.PeginAction;exports.canPerformAction=S.canPerformAction;exports.getPeginProtocolState=S.getPeginProtocolState;exports.isActivationDeadlinePassedOnChain=S.isActivationDeadlinePassedOnChain;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const a=require("../verifyScriptPathSchnorrSignature-BKZihCjk.cjs"),O=require("../secp256k1-DDHQ1_za.cjs"),P=require("./core/wasm/index.cjs"),R=require("../verifyKeyPathSchnorrSignature-Gm9EmZkx.cjs"),l=require("../noPayout-DAWBQ0eG.cjs"),N=require("../challengeAssert-Z7_YULBb.cjs"),r=require("../bitcoin-D-O2GjbC.cjs"),h=require("../abortSignals-msbmbqFe.cjs"),I=require("../signing-BJ3X66b-.cjs"),c=require("../validation-C6XTfZak.cjs"),F=require("./core/utils/eth/index.cjs"),A=require("../PeginManager-BCJWwV05.cjs"),d=require("../signPsbtsWithFallback-FwrTYZS4.cjs"),o=require("./core/clients/mempool/index.cjs"),p=require("../types-C1tpDycc.cjs"),v=require("../onChainBtcPubkey-BbxRrbvg.cjs"),s=require("../pegin-registration-client-CZgcU2_0.cjs"),C=require("../ProtocolParams.abi-Db2USqQm.cjs"),y=require("../BTCVaultRegistry.abi-BQ5tFNSu.cjs"),E=require("../BTCVaultRegistryKeyEpochs.abi-DCJnzKer.cjs"),_=require("../parseFundingOutpoints-BwC3foxS.cjs"),u=require("../psbtInputFields-BrV_ZfL_.cjs"),i=require("../fundPeginTransaction-54-Rwb2k.cjs"),T=require("../reservation-Dr2HLCxx.cjs"),m=require("../index-CK1Xvq4K.cjs"),n=require("../json-rpc-client-BiAmg_ho.cjs"),g=require("../primeVpAuth-BOGKniTl.cjs"),t=require("../toRefundInputs-DEPXcrgO.cjs"),e=require("../buildAndBroadcastReclaim-DLsf5hjO.cjs"),S=require("../peginState-eaQ4IO_R.cjs");exports.PEGIN_DEPOSITOR_CLAIM_VOUT=a.PEGIN_DEPOSITOR_CLAIM_VOUT;exports.PsbtSubstitutionError=a.PsbtSubstitutionError;exports.assertPsbtUnsignedTxMatches=a.assertPsbtUnsignedTxMatches;exports.assertScriptPathSchnorrSignature=a.assertScriptPathSchnorrSignature;exports.buildPayoutPsbt=a.buildPayoutPsbt;exports.buildPeginTxFromFundedPrePegin=a.buildPeginTxFromFundedPrePegin;exports.buildPrePeginPsbt=a.buildPrePeginPsbt;exports.computeNumLocalChallengers=a.computeNumLocalChallengers;exports.createPayoutScript=a.createPayoutScript;exports.deriveDepositorClaimDescriptor=a.deriveDepositorClaimDescriptor;exports.deriveDepositorClaimScriptPubKey=a.deriveDepositorClaimScriptPubKey;exports.extractPayoutSignature=a.extractPayoutSignature;exports.assertValidVaultCoreVersion=O.assertValidVaultCoreVersion;exports.computeMinClaimValue=P.computeMinClaimValue;exports.computeMinPeginFee=P.computeMinPeginFee;exports.deriveVaultId=P.deriveVaultId;exports.expandAuthAnchor=P.expandAuthAnchor;exports.expandHashlockSecret=P.expandHashlockSecret;exports.expandWotsSeed=P.expandWotsSeed;exports.peginP2aAnchorOutput=P.peginP2aAnchorOutput;exports.supportedTxGraphVersions=P.supportedTxGraphVersions;exports.validatePeginP2aAnchor=P.validatePeginP2aAnchor;exports.assertKeyPathSchnorrSignature=R.assertKeyPathSchnorrSignature;exports.assertReturnedKeyPathSignatures=R.assertReturnedKeyPathSignatures;exports.buildPeginInputPsbt=R.buildPeginInputPsbt;exports.extractPeginInputSignature=R.extractPeginInputSignature;exports.finalizePeginInputPsbt=R.finalizePeginInputPsbt;exports.buildNoPayoutPsbt=l.buildNoPayoutPsbt;exports.buildReclaimPsbt=l.buildReclaimPsbt;exports.buildRefundPsbt=l.buildRefundPsbt;exports.estimateReclaimFeeSats=l.estimateReclaimFeeSats;exports.finalizeScriptPathWithSignatures=l.finalizeScriptPathWithSignatures;exports.reclaimVsize=l.reclaimVsize;exports.buildChallengeAssertPsbt=N.buildChallengeAssertPsbt;exports.canonicalizeBtcPubkey=r.canonicalizeBtcPubkey;exports.deriveBip86ScriptPubKeyHex=r.deriveBip86ScriptPubKeyHex;exports.deriveNativeSegwitAddress=r.deriveNativeSegwitAddress;exports.deriveTaprootAddress=r.deriveTaprootAddress;exports.ensureHexPrefix=r.ensureHexPrefix;exports.formatSatoshisToBtc=r.formatSatoshisToBtc;exports.getNetwork=r.getNetwork;exports.getSortedXOnlyPubkeys=r.getSortedXOnlyPubkeys;exports.hexToUint8Array=r.hexToUint8Array;exports.isAddressFromPublicKey=r.isAddressFromPublicKey;exports.isValidHex=r.isValidHex;exports.processPublicKeyToXOnly=r.processPublicKeyToXOnly;exports.stripHexPrefix=r.stripHexPrefix;exports.toXOnly=r.toXOnly;exports.uint8ArrayToHex=r.uint8ArrayToHex;exports.validateWalletPubkey=r.validateWalletPubkey;exports.combineAbortSignals=h.combineAbortSignals;exports.calculateBtcTxHash=I.calculateBtcTxHash;exports.createTaprootScriptPathSignOptions=I.createTaprootScriptPathSignOptions;exports.BITCOIN_ADDRESS_RE=c.BITCOIN_ADDRESS_RE;exports.COMPRESSED_PUBKEY_HEX_LEN=c.COMPRESSED_PUBKEY_HEX_LEN;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.X_ONLY_PUBKEY_HEX_LEN=c.X_ONLY_PUBKEY_HEX_LEN;exports.waitForTransactionReceiptSmartAware=F.waitForTransactionReceiptSmartAware;exports.PeginManager=A.PeginManager;exports.buildDepositTerms=A.buildDepositTerms;exports.computeWotsBlockPublicKeysHash=A.computeWotsBlockPublicKeysHash;exports.deriveWotsBlocksFromSeed=A.deriveWotsBlocksFromSeed;exports.ensurePrePeginTermsApproval=A.ensurePrePeginTermsApproval;exports.PayoutManager=d.PayoutManager;exports.computeHashlock=d.computeHashlock;exports.forwardDepositApproval=d.forwardDepositApproval;exports.requireChangeAddress=d.requireChangeAddress;exports.supportsDepositApproval=d.supportsDepositApproval;exports.validateSecretAgainstHashlock=d.validateSecretAgainstHashlock;exports.MEMPOOL_API_URLS=o.MEMPOOL_API_URLS;exports.getAddressTxs=o.getAddressTxs;exports.getAddressUtxos=o.getAddressUtxos;exports.getMempoolApiUrl=o.getMempoolApiUrl;exports.getNetworkFees=o.getNetworkFees;exports.getOutspend=o.getOutspend;exports.getTipHeight=o.getTipHeight;exports.getTxHex=o.getTxHex;exports.getTxInfo=o.getTxInfo;exports.getUtxoInfo=o.getUtxoInfo;exports.pushTx=o.pushTx;exports.OnChainBtcVaultStatus=p.OnChainBtcVaultStatus;exports.ViemOperationKeyReader=p.ViemOperationKeyReader;exports.ViemProtocolParamsReader=p.ViemProtocolParamsReader;exports.ViemUniversalChallengerReader=p.ViemUniversalChallengerReader;exports.ViemVaultKeeperReader=p.ViemVaultKeeperReader;exports.resolveProtocolAddresses=p.resolveProtocolAddresses;exports.assertOnChainBtcPubkey=v.assertOnChainBtcPubkey;exports.COMMISSION_BPS_HEADROOM=s.COMMISSION_BPS_HEADROOM;exports.MAX_ACCEPTABLE_COMMISSION_BPS_CAP=s.MAX_ACCEPTABLE_COMMISSION_BPS_CAP;exports.RegistrationLogsUnavailableError=s.RegistrationLogsUnavailableError;exports.ViemPeginRegistrationClient=s.ViemPeginRegistrationClient;exports.ViemVaultRegistryReader=s.ViemVaultRegistryReader;exports.capMaxAcceptableCommissionBps=s.capMaxAcceptableCommissionBps;exports.derivePeginVaultId=s.derivePeginVaultId;exports.isRegistrationLogsUnavailableError=s.isRegistrationLogsUnavailableError;exports.validateOffchainParams=s.validateOffchainParams;exports.validatePegInConfiguration=s.validatePegInConfiguration;exports.validateTBVProtocolParams=s.validateTBVProtocolParams;exports.ApplicationRegistryABI=C.ApplicationRegistryABI;exports.ProtocolParamsABI=C.ProtocolParamsABI;exports.BTCVaultRegistryABI=y.BTCVaultRegistryABI;exports.BTCVaultRegistryKeyEpochsABI=E.BTCVaultRegistryKeyEpochsABI;exports.CONTRACT_ERRORS=E.CONTRACT_ERRORS;exports.PEGIN_FINGERPRINT_CHANGED_SELECTOR=E.PEGIN_FINGERPRINT_CHANGED_SELECTOR;exports.PeginFingerprintChangedError=E.PeginFingerprintChangedError;exports.extractErrorData=E.extractErrorData;exports.getContractErrorMessage=E.getContractErrorMessage;exports.handleContractError=E.handleContractError;exports.isKnownContractError=E.isKnownContractError;exports.isPeginFingerprintChangedError=E.isPeginFingerprintChangedError;exports.VAULT_APP_NAME=_.VAULT_APP_NAME;exports.buildFundingOutpointsCommitment=_.buildFundingOutpointsCommitment;exports.buildVaultContext=_.buildVaultContext;exports.deriveVaultRoot=_.deriveVaultRoot;exports.forwardDeriveContextHash=_.forwardDeriveContextHash;exports.parseFundingOutpointsFromTx=_.parseFundingOutpointsFromTx;exports.BitcoinScriptType=u.BitcoinScriptType;exports.applyChangeOutputPolicy=u.applyChangeOutputPolicy;exports.computeChangeOutputFeeSats=u.computeChangeOutputFeeSats;exports.computeMaxDeposit=u.computeMaxDeposit;exports.computePeginBaseFeeSats=u.computePeginBaseFeeSats;exports.getDustThreshold=u.getDustThreshold;exports.getPsbtInputFields=u.getPsbtInputFields;exports.getScriptType=u.getScriptType;exports.selectUtxosForPegin=u.selectUtxosForPegin;exports.shouldAddChangeOutput=u.shouldAddChangeOutput;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=T.UtxoNotAvailableError;exports.assertUtxosAvailable=T.assertUtxosAvailable;exports.extractInputsFromTransaction=T.extractInputsFromTransaction;exports.findOverlappingPendingVaults=T.findOverlappingPendingVaults;exports.validateUtxosAvailable=T.validateUtxosAvailable;exports.VaultProviderRpcClient=m.VaultProviderRpcClient;exports.VpResponseValidationError=m.VpResponseValidationError;exports.batchPollByProvider=m.batchPollByProvider;exports.validateRequestDepositorClaimerArtifactsResponse=m.validateRequestDepositorClaimerArtifactsResponse;exports.AUTH_REJECTED_RPC_CODE=n.AUTH_REJECTED_RPC_CODE;exports.DaemonStatus=n.DaemonStatus;exports.JSON_RPC_ERROR_CODES=n.JSON_RPC_ERROR_CODES;exports.JsonRpcClient=n.JsonRpcClient;exports.JsonRpcError=n.JsonRpcError;exports.POST_WOTS_STATUSES=n.POST_WOTS_STATUSES;exports.PRE_DEPOSITOR_SIGNATURES_STATES=n.PRE_DEPOSITOR_SIGNATURES_STATES;exports.RpcErrorCode=n.RpcErrorCode;exports.VP_BATCH_MAX_SIZE=n.VP_BATCH_MAX_SIZE;exports.VP_TERMINAL_FAILURE_STATUSES=n.VP_TERMINAL_FAILURE_STATUSES;exports.VP_TRANSIENT_STATUSES=n.VP_TRANSIENT_STATUSES;exports.isAuthRejectedError=n.isAuthRejectedError;exports.ServerIdentityError=g.ServerIdentityError;exports.VpTokenRegistry=g.VpTokenRegistry;exports.createAuthenticatedVpClient=g.createAuthenticatedVpClient;exports.primeVpTokenRegistry=g.primeVpTokenRegistry;exports.verifyServerIdentity=g.verifyServerIdentity;exports.vpTokenRegistry=g.vpTokenRegistry;exports.DEPOSIT_TERMS_REJECTED_ERROR_NAME=t.DEPOSIT_TERMS_REJECTED_ERROR_NAME;exports.DepositTermsRejectedError=t.DepositTermsRejectedError;exports.PEGIN_FINGERPRINT_DOMAIN=t.PEGIN_FINGERPRINT_DOMAIN;exports.PEGIN_FINGERPRINT_DOMAIN_PREIMAGE=t.PEGIN_FINGERPRINT_DOMAIN_PREIMAGE;exports.PeginFingerprintInputError=t.PeginFingerprintInputError;exports.PeginParamsAmbiguousError=t.PeginParamsAmbiguousError;exports.PeginParamsIncompleteSpaceError=t.PeginParamsIncompleteSpaceError;exports.PeginParamsNotFoundError=t.PeginParamsNotFoundError;exports.PeginSizingIntegrityError=t.PeginSizingIntegrityError;exports.UnanchoredPrePeginError=t.UnanchoredPrePeginError;exports.VaultRootMismatchError=t.VaultRootMismatchError;exports.buildPeginParamsCandidates=t.buildPeginParamsCandidates;exports.computePeginFingerprint=t.computePeginFingerprint;exports.deriveHashlocksFromPrePegin=t.deriveHashlocksFromPrePegin;exports.describePeginParamsCandidate=t.describePeginParamsCandidate;exports.describeUnresolvedVersion=t.describeUnresolvedVersion;exports.encodePeginFingerprintPreimage=t.encodePeginFingerprintPreimage;exports.isDepositTermsRejectedError=t.isDepositTermsRejectedError;exports.isPeginFingerprintInputError=t.isPeginFingerprintInputError;exports.isWotsMismatchError=t.isWotsMismatchError;exports.rebuildDepositTermsCore=t.rebuildDepositTermsCore;exports.reconstructPeginParams=t.reconstructPeginParams;exports.toRefundInputs=t.toRefundInputs;exports.ApplicationEntryPointMismatchError=e.ApplicationEntryPointMismatchError;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.RECLAIM_MAX_FEE_FRACTION_DENOMINATOR=e.RECLAIM_MAX_FEE_FRACTION_DENOMINATOR;exports.RECLAIM_MAX_FEE_FRACTION_NUMERATOR=e.RECLAIM_MAX_FEE_FRACTION_NUMERATOR;exports.RECLAIM_MAX_FEE_RATE_SATS_VB=e.RECLAIM_MAX_FEE_RATE_SATS_VB;exports.RECLAIM_WARN_FEE_FRACTION_NUMERATOR=e.RECLAIM_WARN_FEE_FRACTION_NUMERATOR;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.ReclaimUneconomicalError=e.ReclaimUneconomicalError;exports.RegisteredVaultVersionMismatchError=e.RegisteredVaultVersionMismatchError;exports.activateVault=e.activateVault;exports.activateVaultAndRedeem=e.activateVaultAndRedeem;exports.assertVaultProviderHintAccepted=e.assertVaultProviderHintAccepted;exports.buildAndBroadcastReclaim=e.buildAndBroadcastReclaim;exports.buildAndBroadcastRefund=e.buildAndBroadcastRefund;exports.estimateRefundFeeSats=e.estimateRefundFeeSats;exports.isApplicationEntryPointMismatchError=e.isApplicationEntryPointMismatchError;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=S.ContractStatus;exports.PeginAction=S.PeginAction;exports.canPerformAction=S.canPerformAction;exports.getPeginProtocolState=S.getPeginProtocolState;exports.isActivationDeadlinePassedOnChain=S.isActivationDeadlinePassedOnChain;
2
2
  //# sourceMappingURL=index.cjs.map
package/dist/tbv/index.js CHANGED
@@ -1,16 +1,16 @@
1
- import { P as s, h as r, i as t, j as i, f as o, b as n, a as P, c as p, k as E, d as c, e as l, g as d } from "../verifyScriptPathSchnorrSignature-D_epga4j.js";
1
+ import { P as s, h as r, i as t, j as i, f as o, b as n, a as P, c as p, k as E, d as c, e as l, g as d } from "../verifyScriptPathSchnorrSignature-CpjSTfMj.js";
2
2
  import { a as g } from "../secp256k1-D-H9jmd7.js";
3
3
  import { computeMinClaimValue as A, computeMinPeginFee as _, deriveVaultId as T, expandAuthAnchor as m, expandHashlockSecret as S, expandWotsSeed as I, peginP2aAnchorOutput as C, supportedTxGraphVersions as O, validatePeginP2aAnchor as N } from "./core/wasm/index.js";
4
- import { a as b, c as x, b as h, e as V, f as F } from "../verifyKeyPathSchnorrSignature-BVtNwgK6.js";
5
- import { c as M, a as y, b as D, e as U, f as B, r as H } from "../noPayout-DiGr4eas.js";
4
+ import { a as b, c as x, b as h, e as V, f as F } from "../verifyKeyPathSchnorrSignature-BQHNhRj6.js";
5
+ import { c as M, a as y, b as D, e as U, f as B, r as H } from "../noPayout-qBXWKwav.js";
6
6
  import { b as K } from "../challengeAssert-Cp_GeRg8.js";
7
7
  import { c as k, d as G, a as W, b as w, e as Y, f as j, k as z, g as J, h as Z, i as q, j as Q, p as $, s as aa, t as ea, u as sa, v as ra } from "../bitcoin-C-TuHb-v.js";
8
8
  import { c as ia } from "../abortSignals-BPpAUL1Z.js";
9
9
  import { c as na, a as Pa } from "../signing-Cm-McVR2.js";
10
10
  import { B as Ea, C as ca, H as la, K as da, M as ua, T as ga, X as Ra } from "../validation-OSC0xTHB.js";
11
11
  import { waitForTransactionReceiptSmartAware as _a } from "./core/utils/eth/index.js";
12
- import { P as ma, b as Sa, c as Ia, d as Ca, e as Oa } from "../PeginManager-BXlh3ar0.js";
13
- import { P as fa, c as ba, f as xa, r as ha, s as Va, v as Fa } from "../signPsbtsWithFallback-f7QLp0q8.js";
12
+ import { P as ma, b as Sa, c as Ia, d as Ca, e as Oa } from "../PeginManager-BH_AKu4l.js";
13
+ import { P as fa, c as ba, f as xa, r as ha, s as Va, v as Fa } from "../signPsbtsWithFallback-DoRbHHua.js";
14
14
  import { MEMPOOL_API_URLS as Ma, getAddressTxs as ya, getAddressUtxos as Da, getMempoolApiUrl as Ua, getNetworkFees as Ba, getOutspend as Ha, getTipHeight as La, getTxHex as Ka, getTxInfo as Xa, getUtxoInfo as ka, pushTx as Ga } from "./core/clients/mempool/index.js";
15
15
  import { O as wa, V as Ya, a as ja, b as za, c as Ja, r as Za } from "../types-B9YhlXe8.js";
16
16
  import { a as Qa } from "../onChainBtcPubkey-C-6UWpD8.js";
@@ -18,15 +18,15 @@ import { C as ae, M as ee, R as se, V as re, c as te, e as ie, d as oe, i as ne,
18
18
  import { A as le, P as de } from "../ProtocolParams.abi-q0AidvYX.js";
19
19
  import { B as ge } from "../BTCVaultRegistry.abi-B0x9_Bza.js";
20
20
  import { B as Ae, C as _e, P as Te, a as me, e as Se, g as Ie, h as Ce, i as Oe, b as Ne } from "../BTCVaultRegistryKeyEpochs.abi-BWoxwPQv.js";
21
- import { V as be, b as xe, a as he, d as Ve, f as Fe, p as ve } from "../parseFundingOutpoints-BQWvINfm.js";
21
+ import { V as be, b as xe, a as he, d as Ve, f as Fe, p as ve } from "../parseFundingOutpoints-CC4NKYz2.js";
22
22
  import { B as ye, a as De, c as Ue, b as Be, d as He, g as Le, h as Ke, f as Xe, s as ke, e as Ge } from "../psbtInputFields-CCVyaQMi.js";
23
23
  import { B as we, D as Ye, L as je, M as ze, c as Je, P as Ze, b as qe, a as Qe, S as $e, T as as, W as es, f as ss, d as rs, p as ts, r as is } from "../fundPeginTransaction-CwhRbCQC.js";
24
24
  import { U as ns, a as Ps, e as ps, f as Es, v as cs } from "../reservation-Cj9F0rP9.js";
25
25
  import { V as ds, a as us, b as gs, v as Rs } from "../index-DQ5bfoT3.js";
26
26
  import { A as _s, D as Ts, J as ms, a as Ss, b as Is, d as Cs, P as Os, R as Ns, e as fs, c as bs, V as xs, i as hs } from "../json-rpc-client-DuUARJvV.js";
27
27
  import { S as Fs, V as vs, c as Ms, p as ys, v as Ds, a as Us } from "../primeVpAuth-DdfHSC53.js";
28
- import { D as Hs, f as Ls, P as Ks, a as Xs, b as ks, o as Gs, p as Ws, n as ws, q as Ys, U as js, V as zs, j as Js, c as Zs, h as qs, l as Qs, k as $s, e as ar, g as er, d as sr, i as rr, r as tr, m as ir, t as or } from "../toRefundInputs-9inv4Ai4.js";
29
- import { A as Pr, J as pr, G as Er, P as cr, p as lr, c as dr, d as ur, U as gr, V as Rr, W as Ar, X as _r, M as Tr, N as mr, O as Sr, Q as Ir, S as Cr, R as Or, a as Nr, b as fr, z as br, T as xr, K as hr, L as Vr, g as Fr, h as vr, B as Mr, q as yr, i as Dr, e as Ur, I as Br, H as Hr, u as Lr, C as Kr, D as Xr, E as kr, F as Gr, r as Wr, s as wr, f as Yr, j as jr, k as zr, v as Jr, l as Zr, m as qr, n as Qr, o as $r, t as at, x as et, w as st, y as rt } from "../buildAndBroadcastReclaim-O6z9kvc4.js";
28
+ import { D as Hs, f as Ls, P as Ks, a as Xs, b as ks, o as Gs, p as Ws, n as ws, q as Ys, U as js, V as zs, j as Js, c as Zs, h as qs, l as Qs, k as $s, e as ar, g as er, d as sr, i as rr, r as tr, m as ir, t as or } from "../toRefundInputs-BEulLgN_.js";
29
+ import { A as Pr, J as pr, G as Er, P as cr, p as lr, c as dr, d as ur, U as gr, V as Rr, W as Ar, X as _r, M as Tr, N as mr, O as Sr, Q as Ir, S as Cr, R as Or, a as Nr, b as fr, z as br, T as xr, K as hr, L as Vr, g as Fr, h as vr, B as Mr, q as yr, i as Dr, e as Ur, I as Br, H as Hr, u as Lr, C as Kr, D as Xr, E as kr, F as Gr, r as Wr, s as wr, f as Yr, j as jr, k as zr, v as Jr, l as Zr, m as qr, n as Qr, o as $r, t as at, x as et, w as st, y as rt } from "../buildAndBroadcastReclaim-OMvihzJg.js";
30
30
  import { C as it, P as ot, c as nt, g as Pt, i as pt } from "../peginState-CxDiaKuk.js";
31
31
  export {
32
32
  _s as AUTH_REJECTED_RPC_CODE,
@@ -21,7 +21,7 @@ export interface MockBitcoinWalletConfig {
21
21
  * Optional override for `deriveContextHash`. When omitted the mock
22
22
  * returns a deterministic 64-char lowercase hex string derived from
23
23
  * `(appName, context)` so tests can assert pass-through wiring
24
- * without pinning a specific value. Override to inject spec test
24
+ * without pinning a specific value. Override to inject conformance test
25
25
  * vectors or to simulate failure modes.
26
26
  */
27
27
  deriveContextHash?: (appName: string, context: string) => Promise<string>;
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","sources":["../../src/testing/signBip322P2wpkhWitness.ts","../../src/testing/MockBitcoinWallet.ts","../../src/testing/MockEthereumWallet.ts"],"sourcesContent":["/**\n * Test-support BIP-322 \"simple\" P2WPKH signer.\n *\n * Produces the consensus-encoded two-item witness `[DER sig ‖ 0x01,\n * compressed pubkey]` that a Native SegWit software wallet returns for\n * `signMessage(..., \"bip322-simple\")`. The virtual to_spend/to_sign\n * construction follows the `bip322` crate 0.0.10 (`util.rs:18-85`) — the\n * same reference the production verifier\n * (`tbv/core/clients/vault-provider/auth/bip322Verify.ts`) mirrors, and\n * the BIP-322 official vectors pin.\n *\n * Conscious call: `./testing` deliberately depends on the Bitcoin stack\n * (bitcoinjs-lib was already in this entry's graph via MockBitcoinWallet;\n * tiny-secp256k1-asmjs is new here) — out of scope for the CLAUDE.md §9\n * optional-BTC split.\n *\n * Test-only: never feed real key material to this module.\n */\n\nimport * as ecc from \"@bitcoin-js/tiny-secp256k1-asmjs\";\nimport { sha256 } from \"@noble/hashes/sha2.js\";\nimport { script as bscript, payments, Transaction } from \"bitcoinjs-lib\";\nimport { Buffer } from \"buffer\";\n\n/** BIP-322 message tag (BIP-340 tagged-hash style). */\nconst BIP322_TAG = \"BIP0322-signed-message\";\nconst SIGHASH_ALL = 0x01;\nconst ZERO_SATS = 0;\n/**\n * vaultd accepts only 71/72-byte encoded signatures (`bip322` crate 0.0.10\n * `verify.rs:141-153`); a short-DER signature (~0.4% of draws) is ground\n * away by re-signing with fresh entropy. 100 attempts bounds the failure\n * probability around 0.004^100.\n */\nconst MIN_ENCODED_SIG_BYTES = 71;\nconst MAX_SIGN_GRIND_ATTEMPTS = 100;\n\n// Wire fields of the virtual to_spend/to_sign transactions (`bip322`\n// crate 0.0.10 `util.rs:18-85`).\nconst BIP322_TX_VERSION = 0;\nconst BIP322_TX_LOCKTIME = 0;\nconst BIP322_INPUT_SEQUENCE = 0;\n/** to_spend prevout: all-zero 32-byte txid at index 0xFFFFFFFF (`util.rs:18-85`). */\nconst TO_SPEND_PREVOUT_TXID_BYTES = 32;\nconst TO_SPEND_PREVOUT_INDEX = 0xffffffff;\n/** to_sign spends to_spend's only output (`util.rs:18-85`). */\nconst TO_SPEND_OUTPUT_INDEX = 0;\nconst OP_0 = 0x00;\n/** Direct push of the 32-byte tagged message hash. */\nconst OP_PUSHBYTES_32 = 0x20;\nconst OP_RETURN = 0x6a;\n/** Consensus P2WPKH witness: exactly [signature, pubkey]. */\nconst P2WPKH_WITNESS_ITEMS = 2;\n/** Grinding: 32-byte extra-entropy buffer, attempt counter at offset 0. */\nconst GRIND_ENTROPY_BYTES = 32;\nconst GRIND_COUNTER_OFFSET = 0;\n\n/**\n * Sign `messageBytes` as a BIP-322 \"simple\" P2WPKH proof with `privateKey`\n * and return the consensus-encoded two-item witness\n * (`0x02 ‖ len ‖ sig ‖ 0x21 ‖ pubkey`).\n */\nexport function signBip322P2wpkhWitness(\n messageBytes: Uint8Array,\n privateKey: Uint8Array,\n): Uint8Array {\n const pubkey = ecc.pointFromScalar(privateKey, true);\n if (!pubkey) {\n throw new Error(\"signBip322P2wpkhWitness: invalid private key\");\n }\n\n // m_hash = SHA256( SHA256(tag) ‖ SHA256(tag) ‖ message )\n const tagHash = sha256(new TextEncoder().encode(BIP322_TAG));\n const messageHash = sha256(\n Buffer.concat([tagHash, tagHash, Buffer.from(messageBytes)]),\n );\n\n const p2wpkh = payments.p2wpkh({ pubkey: Buffer.from(pubkey) });\n if (!p2wpkh.output || !p2wpkh.hash) {\n throw new Error(\"signBip322P2wpkhWitness: could not derive P2WPKH script\");\n }\n\n // to_spend / to_sign per bip322 crate util.rs:18-85.\n const toSpend = new Transaction();\n toSpend.version = BIP322_TX_VERSION;\n toSpend.locktime = BIP322_TX_LOCKTIME;\n toSpend.addInput(\n Buffer.alloc(TO_SPEND_PREVOUT_TXID_BYTES, 0),\n TO_SPEND_PREVOUT_INDEX,\n BIP322_INPUT_SEQUENCE,\n Buffer.concat([\n Buffer.from([OP_0, OP_PUSHBYTES_32]),\n Buffer.from(messageHash),\n ]),\n );\n toSpend.addOutput(p2wpkh.output, ZERO_SATS);\n const toSign = new Transaction();\n toSign.version = BIP322_TX_VERSION;\n toSign.locktime = BIP322_TX_LOCKTIME;\n toSign.addInput(\n toSpend.getHash(),\n TO_SPEND_OUTPUT_INDEX,\n BIP322_INPUT_SEQUENCE,\n );\n toSign.addOutput(Buffer.from([OP_RETURN]), ZERO_SATS);\n\n // BIP-143 sighash with the standard P2WPKH scriptCode, value 0\n // (bip322 crate verify.rs:163-173).\n const scriptCode = payments.p2pkh({ hash: p2wpkh.hash }).output;\n if (!scriptCode) {\n throw new Error(\"signBip322P2wpkhWitness: could not build scriptCode\");\n }\n const sighash = toSign.hashForWitnessV0(\n 0,\n scriptCode,\n ZERO_SATS,\n SIGHASH_ALL,\n );\n\n let encodedSignature: Buffer | undefined;\n for (let attempt = 0; attempt < MAX_SIGN_GRIND_ATTEMPTS; attempt++) {\n const entropy = Buffer.alloc(GRIND_ENTROPY_BYTES, 0);\n entropy.writeUInt32LE(attempt, GRIND_COUNTER_OFFSET);\n // ecc.sign emits low-S (libsecp256k1), so 73-byte encodings can't occur.\n const candidate = bscript.signature.encode(\n Buffer.from(ecc.sign(sighash, privateKey, entropy)),\n SIGHASH_ALL,\n );\n if (candidate.length >= MIN_ENCODED_SIG_BYTES) {\n encodedSignature = candidate;\n break;\n }\n }\n if (!encodedSignature) {\n throw new Error(\n \"signBip322P2wpkhWitness: could not grind a 71/72-byte signature\",\n );\n }\n\n return Uint8Array.from([\n P2WPKH_WITNESS_ITEMS,\n encodedSignature.length,\n ...encodedSignature,\n pubkey.length,\n ...pubkey,\n ]);\n}\n","import * as ecc from \"@bitcoin-js/tiny-secp256k1-asmjs\";\nimport { sha256 } from \"@noble/hashes/sha2.js\";\nimport { Buffer } from \"buffer\";\n\nimport {\n BitcoinNetworks,\n type BitcoinNetwork,\n} from \"../shared/wallets/interfaces\";\nimport type {\n BitcoinWallet,\n SignPsbtOptions,\n} from \"../shared/wallets/interfaces/BitcoinWallet\";\nimport {\n canonicalizeBtcPubkey,\n uint8ArrayToHex,\n} from \"../tbv/core/primitives/utils/bitcoin\";\nimport { signBip322P2wpkhWitness } from \"./signBip322P2wpkhWitness\";\n\n/**\n * Configuration for MockBitcoinWallet.\n */\nexport interface MockBitcoinWalletConfig {\n publicKeyHex?: string;\n address?: string;\n network?: BitcoinNetwork;\n shouldFailSigning?: boolean;\n /**\n * 32-byte hex key `signMessage` signs BIP-322 proofs with. Defaults to\n * the privkey-1 test key, whose x-only pubkey is the default\n * `publicKeyHex` (the secp256k1 generator's x coordinate). PoP flows\n * verify the witness against `publicKeyHex`: overriding only this key\n * derives the matching `publicKeyHex`, and a divergent pair throws at\n * sign time. Test material only — never a real key.\n */\n privateKeyHex?: string;\n /**\n * Optional override for `deriveContextHash`. When omitted the mock\n * returns a deterministic 64-char lowercase hex string derived from\n * `(appName, context)` so tests can assert pass-through wiring\n * without pinning a specific value. Override to inject spec test\n * vectors or to simulate failure modes.\n */\n deriveContextHash?: (appName: string, context: string) => Promise<string>;\n}\n\n/**\n * Default `deriveContextHash` implementation: deterministic and\n * collision-resistant via SHA-256, so tests that assert pass-through\n * wiring (different `(appName, context)` → different output) hold\n * without flakes. Domain-separates the two inputs by length-prefixing\n * each as `len(name) || name || len(ctx) || ctx`, preventing\n * `(\"ab\", \"cd\")` from colliding with `(\"abc\", \"d\")`.\n */\nconst defaultDeriveContextHash = async (\n appName: string,\n context: string,\n): Promise<string> => {\n const enc = new TextEncoder();\n const nameBytes = enc.encode(appName);\n const ctxBytes = enc.encode(context);\n const buf = new Uint8Array(4 + nameBytes.length + 4 + ctxBytes.length);\n const view = new DataView(buf.buffer);\n view.setUint32(0, nameBytes.length);\n buf.set(nameBytes, 4);\n view.setUint32(4 + nameBytes.length, ctxBytes.length);\n buf.set(ctxBytes, 4 + nameBytes.length + 4);\n return uint8ArrayToHex(sha256(buf));\n};\n\n/** Privkey 1 — the test key `signMessage` signs with by default. */\nconst DEFAULT_PRIVATE_KEY_HEX = `${\"00\".repeat(31)}01`;\n\n/** Lowercase x-only pubkey of a 32-byte private key. */\nfunction xOnlyPubkeyHexOf(privateKeyHex: string): string {\n return uint8ArrayToHex(\n ecc.xOnlyPointFromScalar(\n Uint8Array.from(Buffer.from(privateKeyHex, \"hex\")),\n ),\n );\n}\n\nconst DEFAULT_CONFIG: Required<MockBitcoinWalletConfig> = {\n // x-only pubkey of DEFAULT_PRIVATE_KEY_HEX (the secp256k1 generator's x\n // coordinate), so the default wallet's PoP witnesses verify against it.\n publicKeyHex:\n \"79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798\",\n address: \"tb1pqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqkx6jks\",\n network: BitcoinNetworks.SIGNET,\n shouldFailSigning: false,\n privateKeyHex: DEFAULT_PRIVATE_KEY_HEX,\n deriveContextHash: defaultDeriveContextHash,\n};\n\n/** Mock Bitcoin wallet for testing. */\nexport class MockBitcoinWallet implements BitcoinWallet {\n private config: Required<MockBitcoinWalletConfig>;\n\n constructor(config: MockBitcoinWalletConfig = {}) {\n this.config = {\n ...DEFAULT_CONFIG,\n ...(config.publicKeyHex ? { publicKeyHex: config.publicKeyHex } : {}),\n ...(config.address ? { address: config.address } : {}),\n ...(config.network !== undefined ? { network: config.network } : {}),\n ...(config.shouldFailSigning !== undefined\n ? { shouldFailSigning: config.shouldFailSigning }\n : {}),\n ...(config.privateKeyHex ? { privateKeyHex: config.privateKeyHex } : {}),\n ...(config.deriveContextHash\n ? { deriveContextHash: config.deriveContextHash }\n : {}),\n };\n // A private-key override without a public key would otherwise sign\n // against the DEFAULT pubkey — derive the matching one instead.\n if (config.privateKeyHex && !config.publicKeyHex) {\n this.config.publicKeyHex = xOnlyPubkeyHexOf(config.privateKeyHex);\n }\n }\n\n async getPublicKeyHex(): Promise<string> {\n return this.config.publicKeyHex;\n }\n\n async getAddress(): Promise<string> {\n return this.config.address;\n }\n\n async signPsbt(psbtHex: string, _options?: SignPsbtOptions): Promise<string> {\n if (this.config.shouldFailSigning) {\n throw new Error(\"Mock signing failed\");\n }\n\n if (!psbtHex || psbtHex.length === 0) {\n throw new Error(\"Invalid PSBT: empty hex string\");\n }\n\n // In a real implementation, this would actually sign the PSBT\n // For the mock, we just return the input with a mock signature appended\n return psbtHex + \"deadbeef\";\n }\n\n async signPsbts(\n psbtsHexes: string[],\n _options?: SignPsbtOptions[],\n ): Promise<string[]> {\n const signedPsbts: string[] = [];\n for (const psbtHex of psbtsHexes) {\n const signedPsbt = await this.signPsbt(psbtHex);\n signedPsbts.push(signedPsbt);\n }\n return signedPsbts;\n }\n\n async signMessage(\n message: string,\n type: \"bip322-simple\" | \"ecdsa\",\n ): Promise<string> {\n // Only BIP-322 witnesses are implemented; returning one for \"ecdsa\"\n // would hand a future ECDSA-flow test the wrong artifact silently.\n if (type !== \"bip322-simple\") {\n throw new Error(\n \"MockBitcoinWallet.signMessage: only bip322-simple is implemented\",\n );\n }\n if (this.config.shouldFailSigning) {\n throw new Error(\"Mock signing failed\");\n }\n\n if (!message || message.length === 0) {\n throw new Error(\"Invalid message: empty string\");\n }\n\n // PoP flows verify the witness against `publicKeyHex`, so a divergent\n // key pair must fail loudly here, not as a confusing verify mismatch.\n const signingXOnlyHex = xOnlyPubkeyHexOf(this.config.privateKeyHex);\n let configuredXOnlyHex: string | undefined;\n try {\n configuredXOnlyHex = canonicalizeBtcPubkey(this.config.publicKeyHex);\n } catch {\n configuredXOnlyHex = undefined; // an unparseable key cannot match\n }\n if (configuredXOnlyHex !== signingXOnlyHex) {\n throw new Error(\n `MockBitcoinWallet.signMessage: privateKeyHex signs as x-only pubkey ` +\n `${signingXOnlyHex}, but publicKeyHex is ${this.config.publicKeyHex}. ` +\n `Pass a matching publicKeyHex/privateKeyHex pair.`,\n );\n }\n\n // The SDK cryptographically verifies what a wallet returns\n // (`verifyPopWitness`), so the mock signs a REAL BIP-322 P2WPKH witness\n // with its private key.\n const witness = signBip322P2wpkhWitness(\n new TextEncoder().encode(message),\n Uint8Array.from(Buffer.from(this.config.privateKeyHex, \"hex\")),\n );\n return `0x${uint8ArrayToHex(witness)}`;\n }\n\n async getNetwork(): Promise<BitcoinNetwork> {\n return this.config.network;\n }\n\n async deriveContextHash(appName: string, context: string): Promise<string> {\n return this.config.deriveContextHash(appName, context);\n }\n\n /** Updates configuration for testing different scenarios. */\n updateConfig(updates: Partial<MockBitcoinWalletConfig>): void {\n this.config = {\n ...this.config,\n ...updates,\n };\n // Mirror the constructor: a private-key-only update re-derives the\n // matching pubkey; an explicit publicKeyHex still wins.\n if (updates.privateKeyHex && !updates.publicKeyHex) {\n this.config.publicKeyHex = xOnlyPubkeyHexOf(updates.privateKeyHex);\n }\n }\n\n /** Resets to default configuration. */\n reset(): void {\n this.config = { ...DEFAULT_CONFIG };\n }\n}\n","import { Buffer } from \"buffer\";\nimport type { Address, Hex } from \"viem\";\n\n/**\n * Configuration for MockEthereumWallet.\n */\nexport interface MockEthereumWalletConfig {\n address?: Address;\n chainId?: number;\n shouldFailOperations?: boolean;\n transactionDelay?: number;\n}\n\n/**\n * Mock Ethereum wallet for testing.\n *\n * Provides the subset of viem's WalletClient methods used by the SDK.\n * Can be passed to functions expecting a WalletClient for testing purposes.\n */\nexport class MockEthereumWallet {\n // Public properties matching viem's WalletClient structure\n account: { address: Address };\n chain: { id: number };\n\n private shouldFailOperations: boolean;\n private transactionDelay: number;\n private nonce: number = 0;\n\n constructor(config: MockEthereumWalletConfig = {}) {\n // Use lowercase addresses to avoid EIP-55 checksum validation issues\n this.account = {\n address:\n config.address ||\n (\"0x742d35cc6634c0532925a3b844bc9e7595f0beb0\" as Address),\n };\n\n this.chain = {\n id: config.chainId ?? 11155111, // Sepolia by default\n };\n\n this.shouldFailOperations = config.shouldFailOperations ?? false;\n this.transactionDelay = config.transactionDelay ?? 0;\n\n // Bind methods to preserve 'this' context when called\n this.signMessage = this.signMessage.bind(this);\n this.sendTransaction = this.sendTransaction.bind(this);\n }\n\n async signMessage(args: { message: string; account?: Address }): Promise<Hex> {\n const message = args.message;\n const account = args.account || this.account.address;\n\n if (this.shouldFailOperations) {\n throw new Error(\"Mock signing failed\");\n }\n\n if (!message || message.length === 0) {\n throw new Error(\"Invalid message: empty string\");\n }\n\n // Generate a deterministic mock signature\n const signatureData = `personal_sign:${message}-${account}-${this.chain.id}`;\n const signature = `0x${Buffer.from(signatureData)\n .toString(\"hex\")\n .slice(0, 130)\n .padEnd(130, \"0\")}` as Hex;\n return signature;\n }\n\n async sendTransaction(tx: {\n to: Address;\n data?: Hex;\n value?: bigint;\n gas?: bigint;\n account?: { address: Address };\n chain?: { id: number };\n }): Promise<Hex> {\n if (this.shouldFailOperations) {\n throw new Error(\"Mock transaction failed\");\n }\n\n if (!tx.to) {\n throw new Error(\"Invalid transaction: missing 'to' address\");\n }\n\n // Simulate network delay if configured\n if (this.transactionDelay > 0) {\n await new Promise((resolve) =>\n setTimeout(resolve, this.transactionDelay),\n );\n }\n\n // Generate a deterministic mock transaction hash\n this.nonce++;\n const txData = JSON.stringify({\n from: this.account.address,\n to: tx.to,\n value: tx.value?.toString() || \"0\",\n nonce: this.nonce,\n chainId: this.chain.id,\n });\n\n const hash = `0x${Buffer.from(txData)\n .toString(\"hex\")\n .slice(0, 64)\n .padEnd(64, \"0\")}` as Hex;\n return hash;\n }\n\n /** Updates configuration for testing different scenarios. */\n updateConfig(updates: Partial<MockEthereumWalletConfig>): void {\n if (updates.address !== undefined) {\n this.account.address = updates.address;\n }\n if (updates.chainId !== undefined) {\n this.chain.id = updates.chainId;\n }\n if (updates.shouldFailOperations !== undefined) {\n this.shouldFailOperations = updates.shouldFailOperations;\n }\n if (updates.transactionDelay !== undefined) {\n this.transactionDelay = updates.transactionDelay;\n }\n }\n\n /** Resets to default configuration and nonce. */\n reset(): void {\n this.account.address =\n \"0x742d35cc6634c0532925a3b844bc9e7595f0beb0\" as Address;\n this.chain.id = 11155111;\n this.shouldFailOperations = false;\n this.transactionDelay = 0;\n this.nonce = 0;\n }\n\n /** Returns current nonce for testing. */\n getCurrentNonce(): number {\n return this.nonce;\n }\n}\n"],"names":["BIP322_TAG","SIGHASH_ALL","ZERO_SATS","MIN_ENCODED_SIG_BYTES","MAX_SIGN_GRIND_ATTEMPTS","BIP322_TX_VERSION","BIP322_TX_LOCKTIME","BIP322_INPUT_SEQUENCE","TO_SPEND_PREVOUT_TXID_BYTES","TO_SPEND_PREVOUT_INDEX","TO_SPEND_OUTPUT_INDEX","OP_0","OP_PUSHBYTES_32","OP_RETURN","P2WPKH_WITNESS_ITEMS","GRIND_ENTROPY_BYTES","GRIND_COUNTER_OFFSET","signBip322P2wpkhWitness","messageBytes","privateKey","pubkey","ecc","tagHash","sha256","messageHash","Buffer","p2wpkh","payments","toSpend","Transaction","toSign","scriptCode","sighash","encodedSignature","attempt","entropy","candidate","bscript","defaultDeriveContextHash","appName","context","enc","nameBytes","ctxBytes","buf","view","uint8ArrayToHex","DEFAULT_PRIVATE_KEY_HEX","xOnlyPubkeyHexOf","privateKeyHex","DEFAULT_CONFIG","BitcoinNetworks","MockBitcoinWallet","config","__publicField","psbtHex","_options","psbtsHexes","signedPsbts","signedPsbt","message","type","signingXOnlyHex","configuredXOnlyHex","canonicalizeBtcPubkey","witness","updates","MockEthereumWallet","args","account","signatureData","tx","resolve","txData","_a"],"mappings":"ytBAyBMA,EAAa,yBACbC,EAAc,EACdC,EAAY,EAOZC,EAAwB,GACxBC,EAA0B,IAI1BC,EAAoB,EACpBC,EAAqB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AAqB,SAC/B,KAAK,iBAAmBA,EAAQ,iBAEpC,CAGA,OAAc,CACZ,KAAK,QAAQ,QACX,6CACF,KAAK,MAAM,GAAK,SAChB,KAAK,qBAAuB,GAC5B,KAAK,iBAAmB,EACxB,KAAK,MAAQ,CACf,CAGA,iBAA0B,CACxB,OAAO,KAAK,KACd,CACF"}
1
+ {"version":3,"file":"index.cjs","sources":["../../src/testing/signBip322P2wpkhWitness.ts","../../src/testing/MockBitcoinWallet.ts","../../src/testing/MockEthereumWallet.ts"],"sourcesContent":["/**\n * Test-support BIP-322 \"simple\" P2WPKH signer.\n *\n * Produces the consensus-encoded two-item witness `[DER sig ‖ 0x01,\n * compressed pubkey]` that a Native SegWit software wallet returns for\n * `signMessage(..., \"bip322-simple\")`. The virtual to_spend/to_sign\n * construction follows the `bip322` crate 0.0.10 (`util.rs:18-85`) — the\n * same reference the production verifier\n * (`tbv/core/clients/vault-provider/auth/bip322Verify.ts`) mirrors, and\n * the BIP-322 official vectors pin.\n *\n * Conscious call: `./testing` deliberately depends on the Bitcoin stack\n * (bitcoinjs-lib was already in this entry's graph via MockBitcoinWallet;\n * tiny-secp256k1-asmjs is new here) — out of scope for the CLAUDE.md §9\n * optional-BTC split.\n *\n * Test-only: never feed real key material to this module.\n */\n\nimport * as ecc from \"@bitcoin-js/tiny-secp256k1-asmjs\";\nimport { sha256 } from \"@noble/hashes/sha2.js\";\nimport { script as bscript, payments, Transaction } from \"bitcoinjs-lib\";\nimport { Buffer } from \"buffer\";\n\n/** BIP-322 message tag (BIP-340 tagged-hash style). */\nconst BIP322_TAG = \"BIP0322-signed-message\";\nconst SIGHASH_ALL = 0x01;\nconst ZERO_SATS = 0;\n/**\n * vaultd accepts only 71/72-byte encoded signatures (`bip322` crate 0.0.10\n * `verify.rs:141-153`); a short-DER signature (~0.4% of draws) is ground\n * away by re-signing with fresh entropy. 100 attempts bounds the failure\n * probability around 0.004^100.\n */\nconst MIN_ENCODED_SIG_BYTES = 71;\nconst MAX_SIGN_GRIND_ATTEMPTS = 100;\n\n// Wire fields of the virtual to_spend/to_sign transactions (`bip322`\n// crate 0.0.10 `util.rs:18-85`).\nconst BIP322_TX_VERSION = 0;\nconst BIP322_TX_LOCKTIME = 0;\nconst BIP322_INPUT_SEQUENCE = 0;\n/** to_spend prevout: all-zero 32-byte txid at index 0xFFFFFFFF (`util.rs:18-85`). */\nconst TO_SPEND_PREVOUT_TXID_BYTES = 32;\nconst TO_SPEND_PREVOUT_INDEX = 0xffffffff;\n/** to_sign spends to_spend's only output (`util.rs:18-85`). */\nconst TO_SPEND_OUTPUT_INDEX = 0;\nconst OP_0 = 0x00;\n/** Direct push of the 32-byte tagged message hash. */\nconst OP_PUSHBYTES_32 = 0x20;\nconst OP_RETURN = 0x6a;\n/** Consensus P2WPKH witness: exactly [signature, pubkey]. */\nconst P2WPKH_WITNESS_ITEMS = 2;\n/** Grinding: 32-byte extra-entropy buffer, attempt counter at offset 0. */\nconst GRIND_ENTROPY_BYTES = 32;\nconst GRIND_COUNTER_OFFSET = 0;\n\n/**\n * Sign `messageBytes` as a BIP-322 \"simple\" P2WPKH proof with `privateKey`\n * and return the consensus-encoded two-item witness\n * (`0x02 ‖ len ‖ sig ‖ 0x21 ‖ pubkey`).\n */\nexport function signBip322P2wpkhWitness(\n messageBytes: Uint8Array,\n privateKey: Uint8Array,\n): Uint8Array {\n const pubkey = ecc.pointFromScalar(privateKey, true);\n if (!pubkey) {\n throw new Error(\"signBip322P2wpkhWitness: invalid private key\");\n }\n\n // m_hash = SHA256( SHA256(tag) ‖ SHA256(tag) ‖ message )\n const tagHash = sha256(new TextEncoder().encode(BIP322_TAG));\n const messageHash = sha256(\n Buffer.concat([tagHash, tagHash, Buffer.from(messageBytes)]),\n );\n\n const p2wpkh = payments.p2wpkh({ pubkey: Buffer.from(pubkey) });\n if (!p2wpkh.output || !p2wpkh.hash) {\n throw new Error(\"signBip322P2wpkhWitness: could not derive P2WPKH script\");\n }\n\n // to_spend / to_sign per bip322 crate util.rs:18-85.\n const toSpend = new Transaction();\n toSpend.version = BIP322_TX_VERSION;\n toSpend.locktime = BIP322_TX_LOCKTIME;\n toSpend.addInput(\n Buffer.alloc(TO_SPEND_PREVOUT_TXID_BYTES, 0),\n TO_SPEND_PREVOUT_INDEX,\n BIP322_INPUT_SEQUENCE,\n Buffer.concat([\n Buffer.from([OP_0, OP_PUSHBYTES_32]),\n Buffer.from(messageHash),\n ]),\n );\n toSpend.addOutput(p2wpkh.output, ZERO_SATS);\n const toSign = new Transaction();\n toSign.version = BIP322_TX_VERSION;\n toSign.locktime = BIP322_TX_LOCKTIME;\n toSign.addInput(\n toSpend.getHash(),\n TO_SPEND_OUTPUT_INDEX,\n BIP322_INPUT_SEQUENCE,\n );\n toSign.addOutput(Buffer.from([OP_RETURN]), ZERO_SATS);\n\n // BIP-143 sighash with the standard P2WPKH scriptCode, value 0\n // (bip322 crate verify.rs:163-173).\n const scriptCode = payments.p2pkh({ hash: p2wpkh.hash }).output;\n if (!scriptCode) {\n throw new Error(\"signBip322P2wpkhWitness: could not build scriptCode\");\n }\n const sighash = toSign.hashForWitnessV0(\n 0,\n scriptCode,\n ZERO_SATS,\n SIGHASH_ALL,\n );\n\n let encodedSignature: Buffer | undefined;\n for (let attempt = 0; attempt < MAX_SIGN_GRIND_ATTEMPTS; attempt++) {\n const entropy = Buffer.alloc(GRIND_ENTROPY_BYTES, 0);\n entropy.writeUInt32LE(attempt, GRIND_COUNTER_OFFSET);\n // ecc.sign emits low-S (libsecp256k1), so 73-byte encodings can't occur.\n const candidate = bscript.signature.encode(\n Buffer.from(ecc.sign(sighash, privateKey, entropy)),\n SIGHASH_ALL,\n );\n if (candidate.length >= MIN_ENCODED_SIG_BYTES) {\n encodedSignature = candidate;\n break;\n }\n }\n if (!encodedSignature) {\n throw new Error(\n \"signBip322P2wpkhWitness: could not grind a 71/72-byte signature\",\n );\n }\n\n return Uint8Array.from([\n P2WPKH_WITNESS_ITEMS,\n encodedSignature.length,\n ...encodedSignature,\n pubkey.length,\n ...pubkey,\n ]);\n}\n","import * as ecc from \"@bitcoin-js/tiny-secp256k1-asmjs\";\nimport { sha256 } from \"@noble/hashes/sha2.js\";\nimport { Buffer } from \"buffer\";\n\nimport {\n BitcoinNetworks,\n type BitcoinNetwork,\n} from \"../shared/wallets/interfaces\";\nimport type {\n BitcoinWallet,\n SignPsbtOptions,\n} from \"../shared/wallets/interfaces/BitcoinWallet\";\nimport {\n canonicalizeBtcPubkey,\n uint8ArrayToHex,\n} from \"../tbv/core/primitives/utils/bitcoin\";\nimport { signBip322P2wpkhWitness } from \"./signBip322P2wpkhWitness\";\n\n/**\n * Configuration for MockBitcoinWallet.\n */\nexport interface MockBitcoinWalletConfig {\n publicKeyHex?: string;\n address?: string;\n network?: BitcoinNetwork;\n shouldFailSigning?: boolean;\n /**\n * 32-byte hex key `signMessage` signs BIP-322 proofs with. Defaults to\n * the privkey-1 test key, whose x-only pubkey is the default\n * `publicKeyHex` (the secp256k1 generator's x coordinate). PoP flows\n * verify the witness against `publicKeyHex`: overriding only this key\n * derives the matching `publicKeyHex`, and a divergent pair throws at\n * sign time. Test material only — never a real key.\n */\n privateKeyHex?: string;\n /**\n * Optional override for `deriveContextHash`. When omitted the mock\n * returns a deterministic 64-char lowercase hex string derived from\n * `(appName, context)` so tests can assert pass-through wiring\n * without pinning a specific value. Override to inject conformance test\n * vectors or to simulate failure modes.\n */\n deriveContextHash?: (appName: string, context: string) => Promise<string>;\n}\n\n/**\n * Default `deriveContextHash` implementation: deterministic and\n * collision-resistant via SHA-256, so tests that assert pass-through\n * wiring (different `(appName, context)` → different output) hold\n * without flakes. Domain-separates the two inputs by length-prefixing\n * each as `len(name) || name || len(ctx) || ctx`, preventing\n * `(\"ab\", \"cd\")` from colliding with `(\"abc\", \"d\")`.\n */\nconst defaultDeriveContextHash = async (\n appName: string,\n context: string,\n): Promise<string> => {\n const enc = new TextEncoder();\n const nameBytes = enc.encode(appName);\n const ctxBytes = enc.encode(context);\n const buf = new Uint8Array(4 + nameBytes.length + 4 + ctxBytes.length);\n const view = new DataView(buf.buffer);\n view.setUint32(0, nameBytes.length);\n buf.set(nameBytes, 4);\n view.setUint32(4 + nameBytes.length, ctxBytes.length);\n buf.set(ctxBytes, 4 + nameBytes.length + 4);\n return uint8ArrayToHex(sha256(buf));\n};\n\n/** Privkey 1 — the test key `signMessage` signs with by default. */\nconst DEFAULT_PRIVATE_KEY_HEX = `${\"00\".repeat(31)}01`;\n\n/** Lowercase x-only pubkey of a 32-byte private key. */\nfunction xOnlyPubkeyHexOf(privateKeyHex: string): string {\n return uint8ArrayToHex(\n ecc.xOnlyPointFromScalar(\n Uint8Array.from(Buffer.from(privateKeyHex, \"hex\")),\n ),\n );\n}\n\nconst DEFAULT_CONFIG: Required<MockBitcoinWalletConfig> = {\n // x-only pubkey of DEFAULT_PRIVATE_KEY_HEX (the secp256k1 generator's x\n // coordinate), so the default wallet's PoP witnesses verify against it.\n publicKeyHex:\n \"79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798\",\n address: \"tb1pqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqkx6jks\",\n network: BitcoinNetworks.SIGNET,\n shouldFailSigning: false,\n privateKeyHex: DEFAULT_PRIVATE_KEY_HEX,\n deriveContextHash: defaultDeriveContextHash,\n};\n\n/** Mock Bitcoin wallet for testing. */\nexport class MockBitcoinWallet implements BitcoinWallet {\n private config: Required<MockBitcoinWalletConfig>;\n\n constructor(config: MockBitcoinWalletConfig = {}) {\n this.config = {\n ...DEFAULT_CONFIG,\n ...(config.publicKeyHex ? { publicKeyHex: config.publicKeyHex } : {}),\n ...(config.address ? { address: config.address } : {}),\n ...(config.network !== undefined ? { network: config.network } : {}),\n ...(config.shouldFailSigning !== undefined\n ? { shouldFailSigning: config.shouldFailSigning }\n : {}),\n ...(config.privateKeyHex ? { privateKeyHex: config.privateKeyHex } : {}),\n ...(config.deriveContextHash\n ? { deriveContextHash: config.deriveContextHash }\n : {}),\n };\n // A private-key override without a public key would otherwise sign\n // against the DEFAULT pubkey — derive the matching one instead.\n if (config.privateKeyHex && !config.publicKeyHex) {\n this.config.publicKeyHex = xOnlyPubkeyHexOf(config.privateKeyHex);\n }\n }\n\n async getPublicKeyHex(): Promise<string> {\n return this.config.publicKeyHex;\n }\n\n async getAddress(): Promise<string> {\n return this.config.address;\n }\n\n async signPsbt(psbtHex: string, _options?: SignPsbtOptions): Promise<string> {\n if (this.config.shouldFailSigning) {\n throw new Error(\"Mock signing failed\");\n }\n\n if (!psbtHex || psbtHex.length === 0) {\n throw new Error(\"Invalid PSBT: empty hex string\");\n }\n\n // In a real implementation, this would actually sign the PSBT\n // For the mock, we just return the input with a mock signature appended\n return psbtHex + \"deadbeef\";\n }\n\n async signPsbts(\n psbtsHexes: string[],\n _options?: SignPsbtOptions[],\n ): Promise<string[]> {\n const signedPsbts: string[] = [];\n for (const psbtHex of psbtsHexes) {\n const signedPsbt = await this.signPsbt(psbtHex);\n signedPsbts.push(signedPsbt);\n }\n return signedPsbts;\n }\n\n async signMessage(\n message: string,\n type: \"bip322-simple\" | \"ecdsa\",\n ): Promise<string> {\n // Only BIP-322 witnesses are implemented; returning one for \"ecdsa\"\n // would hand a future ECDSA-flow test the wrong artifact silently.\n if (type !== \"bip322-simple\") {\n throw new Error(\n \"MockBitcoinWallet.signMessage: only bip322-simple is implemented\",\n );\n }\n if (this.config.shouldFailSigning) {\n throw new Error(\"Mock signing failed\");\n }\n\n if (!message || message.length === 0) {\n throw new Error(\"Invalid message: empty string\");\n }\n\n // PoP flows verify the witness against `publicKeyHex`, so a divergent\n // key pair must fail loudly here, not as a confusing verify mismatch.\n const signingXOnlyHex = xOnlyPubkeyHexOf(this.config.privateKeyHex);\n let configuredXOnlyHex: string | undefined;\n try {\n configuredXOnlyHex = canonicalizeBtcPubkey(this.config.publicKeyHex);\n } catch {\n configuredXOnlyHex = undefined; // an unparseable key cannot match\n }\n if (configuredXOnlyHex !== signingXOnlyHex) {\n throw new Error(\n `MockBitcoinWallet.signMessage: privateKeyHex signs as x-only pubkey ` +\n `${signingXOnlyHex}, but publicKeyHex is ${this.config.publicKeyHex}. ` +\n `Pass a matching publicKeyHex/privateKeyHex pair.`,\n );\n }\n\n // The SDK cryptographically verifies what a wallet returns\n // (`verifyPopWitness`), so the mock signs a REAL BIP-322 P2WPKH witness\n // with its private key.\n const witness = signBip322P2wpkhWitness(\n new TextEncoder().encode(message),\n Uint8Array.from(Buffer.from(this.config.privateKeyHex, \"hex\")),\n );\n return `0x${uint8ArrayToHex(witness)}`;\n }\n\n async getNetwork(): Promise<BitcoinNetwork> {\n return this.config.network;\n }\n\n async deriveContextHash(appName: string, context: string): Promise<string> {\n return this.config.deriveContextHash(appName, context);\n }\n\n /** Updates configuration for testing different scenarios. */\n updateConfig(updates: Partial<MockBitcoinWalletConfig>): void {\n this.config = {\n ...this.config,\n ...updates,\n };\n // Mirror the constructor: a private-key-only update re-derives the\n // matching pubkey; an explicit publicKeyHex still wins.\n if (updates.privateKeyHex && !updates.publicKeyHex) {\n this.config.publicKeyHex = xOnlyPubkeyHexOf(updates.privateKeyHex);\n }\n }\n\n /** Resets to default configuration. */\n reset(): void {\n this.config = { ...DEFAULT_CONFIG };\n }\n}\n","import { Buffer } from \"buffer\";\nimport type { Address, Hex } from \"viem\";\n\n/**\n * Configuration for MockEthereumWallet.\n */\nexport interface MockEthereumWalletConfig {\n address?: Address;\n chainId?: number;\n shouldFailOperations?: boolean;\n transactionDelay?: number;\n}\n\n/**\n * Mock Ethereum wallet for testing.\n *\n * Provides the subset of viem's WalletClient methods used by the SDK.\n * Can be passed to functions expecting a WalletClient for testing purposes.\n */\nexport class MockEthereumWallet {\n // Public properties matching viem's WalletClient structure\n account: { address: Address };\n chain: { id: number };\n\n private shouldFailOperations: boolean;\n private transactionDelay: number;\n private nonce: number = 0;\n\n constructor(config: MockEthereumWalletConfig = {}) {\n // Use lowercase addresses to avoid EIP-55 checksum validation issues\n this.account = {\n address:\n config.address ||\n (\"0x742d35cc6634c0532925a3b844bc9e7595f0beb0\" as Address),\n };\n\n this.chain = {\n id: config.chainId ?? 11155111, // Sepolia by default\n };\n\n this.shouldFailOperations = config.shouldFailOperations ?? false;\n this.transactionDelay = config.transactionDelay ?? 0;\n\n // Bind methods to preserve 'this' context when called\n this.signMessage = this.signMessage.bind(this);\n this.sendTransaction = this.sendTransaction.bind(this);\n }\n\n async signMessage(args: { message: string; account?: Address }): Promise<Hex> {\n const message = args.message;\n const account = args.account || this.account.address;\n\n if (this.shouldFailOperations) {\n throw new Error(\"Mock signing failed\");\n }\n\n if (!message || message.length === 0) {\n throw new Error(\"Invalid message: empty string\");\n }\n\n // Generate a deterministic mock signature\n const signatureData = `personal_sign:${message}-${account}-${this.chain.id}`;\n const signature = `0x${Buffer.from(signatureData)\n .toString(\"hex\")\n .slice(0, 130)\n .padEnd(130, \"0\")}` as Hex;\n return signature;\n }\n\n async sendTransaction(tx: {\n to: Address;\n data?: Hex;\n value?: bigint;\n gas?: bigint;\n account?: { address: Address };\n chain?: { id: number };\n }): Promise<Hex> {\n if (this.shouldFailOperations) {\n throw new Error(\"Mock transaction failed\");\n }\n\n if (!tx.to) {\n throw new Error(\"Invalid transaction: missing 'to' address\");\n }\n\n // Simulate network delay if configured\n if (this.transactionDelay > 0) {\n await new Promise((resolve) =>\n setTimeout(resolve, this.transactionDelay),\n );\n }\n\n // Generate a deterministic mock transaction hash\n this.nonce++;\n const txData = JSON.stringify({\n from: this.account.address,\n to: tx.to,\n value: tx.value?.toString() || \"0\",\n nonce: this.nonce,\n chainId: this.chain.id,\n });\n\n const hash = `0x${Buffer.from(txData)\n .toString(\"hex\")\n .slice(0, 64)\n .padEnd(64, \"0\")}` as Hex;\n return hash;\n }\n\n /** Updates configuration for testing different scenarios. */\n updateConfig(updates: Partial<MockEthereumWalletConfig>): void {\n if (updates.address !== undefined) {\n this.account.address = updates.address;\n }\n if (updates.chainId !== undefined) {\n this.chain.id = updates.chainId;\n }\n if (updates.shouldFailOperations !== undefined) {\n this.shouldFailOperations = updates.shouldFailOperations;\n }\n if (updates.transactionDelay !== undefined) {\n this.transactionDelay = updates.transactionDelay;\n }\n }\n\n /** Resets to default configuration and nonce. */\n reset(): void {\n this.account.address =\n \"0x742d35cc6634c0532925a3b844bc9e7595f0beb0\" as Address;\n this.chain.id = 11155111;\n this.shouldFailOperations = false;\n this.transactionDelay = 0;\n this.nonce = 0;\n }\n\n /** Returns current nonce for testing. */\n getCurrentNonce(): number {\n return this.nonce;\n }\n}\n"],"names":["BIP322_TAG","SIGHASH_ALL","ZERO_SATS","MIN_ENCODED_SIG_BYTES","MAX_SIGN_GRIND_ATTEMPTS","BIP322_TX_VERSION","BIP322_TX_LOCKTIME","BIP322_INPUT_SEQUENCE","TO_SPEND_PREVOUT_TXID_BYTES","TO_SPEND_PREVOUT_INDEX","TO_SPEND_OUTPUT_INDEX","OP_0","OP_PUSHBYTES_32","OP_RETURN","P2WPKH_WITNESS_ITEMS","GRIND_ENTROPY_BYTES","GRIND_COUNTER_OFFSET","signBip322P2wpkhWitness","messageBytes","privateKey","pubkey","ecc","tagHash","sha256","messageHash","Buffer","p2wpkh","payments","toSpend","Transaction","toSign","scriptCode","sighash","encodedSignature","attempt","entropy","candidate","bscript","defaultDeriveContextHash","appName","context","enc","nameBytes","ctxBytes","buf","view","uint8ArrayToHex","DEFAULT_PRIVATE_KEY_HEX","xOnlyPubkeyHexOf","privateKeyHex","DEFAULT_CONFIG","BitcoinNetworks","MockBitcoinWallet","config","__publicField","psbtHex","_options","psbtsHexes","signedPsbts","signedPsbt","message","type","signingXOnlyHex","configuredXOnlyHex","canonicalizeBtcPubkey","witness","updates","MockEthereumWallet","args","account","signatureData","tx","resolve","txData","_a"],"mappings":"ytBAyBMA,EAAa,yBACbC,EAAc,EACdC,EAAY,EAOZC,EAAwB,GACxBC,EAA0B,IAI1BC,EAAoB,EACpBC,EAAqB,EACrBC,EAAwB,EAExBC,EAA8B,GAC9BC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BAEpC,CAGA,OAAc,CACZ,KAAK,QAAQ,QACX,6CACF,KAAK,MAAM,GAAK,SAChB,KAAK,qBAAuB,GAC5B,KAAK,iBAAmB,EACxB,KAAK,MAAQ,CACf,CAGA,iBAA0B,CACxB,OAAO,KAAK,KACd,CACF"}
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":["../../src/testing/signBip322P2wpkhWitness.ts","../../src/testing/MockBitcoinWallet.ts","../../src/testing/MockEthereumWallet.ts"],"sourcesContent":["/**\n * Test-support BIP-322 \"simple\" P2WPKH signer.\n *\n * Produces the consensus-encoded two-item witness `[DER sig ‖ 0x01,\n * compressed pubkey]` that a Native SegWit software wallet returns for\n * `signMessage(..., \"bip322-simple\")`. The virtual to_spend/to_sign\n * construction follows the `bip322` crate 0.0.10 (`util.rs:18-85`) — the\n * same reference the production verifier\n * (`tbv/core/clients/vault-provider/auth/bip322Verify.ts`) mirrors, and\n * the BIP-322 official vectors pin.\n *\n * Conscious call: `./testing` deliberately depends on the Bitcoin stack\n * (bitcoinjs-lib was already in this entry's graph via MockBitcoinWallet;\n * tiny-secp256k1-asmjs is new here) — out of scope for the CLAUDE.md §9\n * optional-BTC split.\n *\n * Test-only: never feed real key material to this module.\n */\n\nimport * as ecc from \"@bitcoin-js/tiny-secp256k1-asmjs\";\nimport { sha256 } from \"@noble/hashes/sha2.js\";\nimport { script as bscript, payments, Transaction } from \"bitcoinjs-lib\";\nimport { Buffer } from \"buffer\";\n\n/** BIP-322 message tag (BIP-340 tagged-hash style). */\nconst BIP322_TAG = \"BIP0322-signed-message\";\nconst SIGHASH_ALL = 0x01;\nconst ZERO_SATS = 0;\n/**\n * vaultd accepts only 71/72-byte encoded signatures (`bip322` crate 0.0.10\n * `verify.rs:141-153`); a short-DER signature (~0.4% of draws) is ground\n * away by re-signing with fresh entropy. 100 attempts bounds the failure\n * probability around 0.004^100.\n */\nconst MIN_ENCODED_SIG_BYTES = 71;\nconst MAX_SIGN_GRIND_ATTEMPTS = 100;\n\n// Wire fields of the virtual to_spend/to_sign transactions (`bip322`\n// crate 0.0.10 `util.rs:18-85`).\nconst BIP322_TX_VERSION = 0;\nconst BIP322_TX_LOCKTIME = 0;\nconst BIP322_INPUT_SEQUENCE = 0;\n/** to_spend prevout: all-zero 32-byte txid at index 0xFFFFFFFF (`util.rs:18-85`). */\nconst TO_SPEND_PREVOUT_TXID_BYTES = 32;\nconst TO_SPEND_PREVOUT_INDEX = 0xffffffff;\n/** to_sign spends to_spend's only output (`util.rs:18-85`). */\nconst TO_SPEND_OUTPUT_INDEX = 0;\nconst OP_0 = 0x00;\n/** Direct push of the 32-byte tagged message hash. */\nconst OP_PUSHBYTES_32 = 0x20;\nconst OP_RETURN = 0x6a;\n/** Consensus P2WPKH witness: exactly [signature, pubkey]. */\nconst P2WPKH_WITNESS_ITEMS = 2;\n/** Grinding: 32-byte extra-entropy buffer, attempt counter at offset 0. */\nconst GRIND_ENTROPY_BYTES = 32;\nconst GRIND_COUNTER_OFFSET = 0;\n\n/**\n * Sign `messageBytes` as a BIP-322 \"simple\" P2WPKH proof with `privateKey`\n * and return the consensus-encoded two-item witness\n * (`0x02 ‖ len ‖ sig ‖ 0x21 ‖ pubkey`).\n */\nexport function signBip322P2wpkhWitness(\n messageBytes: Uint8Array,\n privateKey: Uint8Array,\n): Uint8Array {\n const pubkey = ecc.pointFromScalar(privateKey, true);\n if (!pubkey) {\n throw new Error(\"signBip322P2wpkhWitness: invalid private key\");\n }\n\n // m_hash = SHA256( SHA256(tag) ‖ SHA256(tag) ‖ message )\n const tagHash = sha256(new TextEncoder().encode(BIP322_TAG));\n const messageHash = sha256(\n Buffer.concat([tagHash, tagHash, Buffer.from(messageBytes)]),\n );\n\n const p2wpkh = payments.p2wpkh({ pubkey: Buffer.from(pubkey) });\n if (!p2wpkh.output || !p2wpkh.hash) {\n throw new Error(\"signBip322P2wpkhWitness: could not derive P2WPKH script\");\n }\n\n // to_spend / to_sign per bip322 crate util.rs:18-85.\n const toSpend = new Transaction();\n toSpend.version = BIP322_TX_VERSION;\n toSpend.locktime = BIP322_TX_LOCKTIME;\n toSpend.addInput(\n Buffer.alloc(TO_SPEND_PREVOUT_TXID_BYTES, 0),\n TO_SPEND_PREVOUT_INDEX,\n BIP322_INPUT_SEQUENCE,\n Buffer.concat([\n Buffer.from([OP_0, OP_PUSHBYTES_32]),\n Buffer.from(messageHash),\n ]),\n );\n toSpend.addOutput(p2wpkh.output, ZERO_SATS);\n const toSign = new Transaction();\n toSign.version = BIP322_TX_VERSION;\n toSign.locktime = BIP322_TX_LOCKTIME;\n toSign.addInput(\n toSpend.getHash(),\n TO_SPEND_OUTPUT_INDEX,\n BIP322_INPUT_SEQUENCE,\n );\n toSign.addOutput(Buffer.from([OP_RETURN]), ZERO_SATS);\n\n // BIP-143 sighash with the standard P2WPKH scriptCode, value 0\n // (bip322 crate verify.rs:163-173).\n const scriptCode = payments.p2pkh({ hash: p2wpkh.hash }).output;\n if (!scriptCode) {\n throw new Error(\"signBip322P2wpkhWitness: could not build scriptCode\");\n }\n const sighash = toSign.hashForWitnessV0(\n 0,\n scriptCode,\n ZERO_SATS,\n SIGHASH_ALL,\n );\n\n let encodedSignature: Buffer | undefined;\n for (let attempt = 0; attempt < MAX_SIGN_GRIND_ATTEMPTS; attempt++) {\n const entropy = Buffer.alloc(GRIND_ENTROPY_BYTES, 0);\n entropy.writeUInt32LE(attempt, GRIND_COUNTER_OFFSET);\n // ecc.sign emits low-S (libsecp256k1), so 73-byte encodings can't occur.\n const candidate = bscript.signature.encode(\n Buffer.from(ecc.sign(sighash, privateKey, entropy)),\n SIGHASH_ALL,\n );\n if (candidate.length >= MIN_ENCODED_SIG_BYTES) {\n encodedSignature = candidate;\n break;\n }\n }\n if (!encodedSignature) {\n throw new Error(\n \"signBip322P2wpkhWitness: could not grind a 71/72-byte signature\",\n );\n }\n\n return Uint8Array.from([\n P2WPKH_WITNESS_ITEMS,\n encodedSignature.length,\n ...encodedSignature,\n pubkey.length,\n ...pubkey,\n ]);\n}\n","import * as ecc from \"@bitcoin-js/tiny-secp256k1-asmjs\";\nimport { sha256 } from \"@noble/hashes/sha2.js\";\nimport { Buffer } from \"buffer\";\n\nimport {\n BitcoinNetworks,\n type BitcoinNetwork,\n} from \"../shared/wallets/interfaces\";\nimport type {\n BitcoinWallet,\n SignPsbtOptions,\n} from \"../shared/wallets/interfaces/BitcoinWallet\";\nimport {\n canonicalizeBtcPubkey,\n uint8ArrayToHex,\n} from \"../tbv/core/primitives/utils/bitcoin\";\nimport { signBip322P2wpkhWitness } from \"./signBip322P2wpkhWitness\";\n\n/**\n * Configuration for MockBitcoinWallet.\n */\nexport interface MockBitcoinWalletConfig {\n publicKeyHex?: string;\n address?: string;\n network?: BitcoinNetwork;\n shouldFailSigning?: boolean;\n /**\n * 32-byte hex key `signMessage` signs BIP-322 proofs with. Defaults to\n * the privkey-1 test key, whose x-only pubkey is the default\n * `publicKeyHex` (the secp256k1 generator's x coordinate). PoP flows\n * verify the witness against `publicKeyHex`: overriding only this key\n * derives the matching `publicKeyHex`, and a divergent pair throws at\n * sign time. Test material only — never a real key.\n */\n privateKeyHex?: string;\n /**\n * Optional override for `deriveContextHash`. When omitted the mock\n * returns a deterministic 64-char lowercase hex string derived from\n * `(appName, context)` so tests can assert pass-through wiring\n * without pinning a specific value. Override to inject spec test\n * vectors or to simulate failure modes.\n */\n deriveContextHash?: (appName: string, context: string) => Promise<string>;\n}\n\n/**\n * Default `deriveContextHash` implementation: deterministic and\n * collision-resistant via SHA-256, so tests that assert pass-through\n * wiring (different `(appName, context)` → different output) hold\n * without flakes. Domain-separates the two inputs by length-prefixing\n * each as `len(name) || name || len(ctx) || ctx`, preventing\n * `(\"ab\", \"cd\")` from colliding with `(\"abc\", \"d\")`.\n */\nconst defaultDeriveContextHash = async (\n appName: string,\n context: string,\n): Promise<string> => {\n const enc = new TextEncoder();\n const nameBytes = enc.encode(appName);\n const ctxBytes = enc.encode(context);\n const buf = new Uint8Array(4 + nameBytes.length + 4 + ctxBytes.length);\n const view = new DataView(buf.buffer);\n view.setUint32(0, nameBytes.length);\n buf.set(nameBytes, 4);\n view.setUint32(4 + nameBytes.length, ctxBytes.length);\n buf.set(ctxBytes, 4 + nameBytes.length + 4);\n return uint8ArrayToHex(sha256(buf));\n};\n\n/** Privkey 1 — the test key `signMessage` signs with by default. */\nconst DEFAULT_PRIVATE_KEY_HEX = `${\"00\".repeat(31)}01`;\n\n/** Lowercase x-only pubkey of a 32-byte private key. */\nfunction xOnlyPubkeyHexOf(privateKeyHex: string): string {\n return uint8ArrayToHex(\n ecc.xOnlyPointFromScalar(\n Uint8Array.from(Buffer.from(privateKeyHex, \"hex\")),\n ),\n );\n}\n\nconst DEFAULT_CONFIG: Required<MockBitcoinWalletConfig> = {\n // x-only pubkey of DEFAULT_PRIVATE_KEY_HEX (the secp256k1 generator's x\n // coordinate), so the default wallet's PoP witnesses verify against it.\n publicKeyHex:\n \"79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798\",\n address: \"tb1pqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqkx6jks\",\n network: BitcoinNetworks.SIGNET,\n shouldFailSigning: false,\n privateKeyHex: DEFAULT_PRIVATE_KEY_HEX,\n deriveContextHash: defaultDeriveContextHash,\n};\n\n/** Mock Bitcoin wallet for testing. */\nexport class MockBitcoinWallet implements BitcoinWallet {\n private config: Required<MockBitcoinWalletConfig>;\n\n constructor(config: MockBitcoinWalletConfig = {}) {\n this.config = {\n ...DEFAULT_CONFIG,\n ...(config.publicKeyHex ? { publicKeyHex: config.publicKeyHex } : {}),\n ...(config.address ? { address: config.address } : {}),\n ...(config.network !== undefined ? { network: config.network } : {}),\n ...(config.shouldFailSigning !== undefined\n ? { shouldFailSigning: config.shouldFailSigning }\n : {}),\n ...(config.privateKeyHex ? { privateKeyHex: config.privateKeyHex } : {}),\n ...(config.deriveContextHash\n ? { deriveContextHash: config.deriveContextHash }\n : {}),\n };\n // A private-key override without a public key would otherwise sign\n // against the DEFAULT pubkey — derive the matching one instead.\n if (config.privateKeyHex && !config.publicKeyHex) {\n this.config.publicKeyHex = xOnlyPubkeyHexOf(config.privateKeyHex);\n }\n }\n\n async getPublicKeyHex(): Promise<string> {\n return this.config.publicKeyHex;\n }\n\n async getAddress(): Promise<string> {\n return this.config.address;\n }\n\n async signPsbt(psbtHex: string, _options?: SignPsbtOptions): Promise<string> {\n if (this.config.shouldFailSigning) {\n throw new Error(\"Mock signing failed\");\n }\n\n if (!psbtHex || psbtHex.length === 0) {\n throw new Error(\"Invalid PSBT: empty hex string\");\n }\n\n // In a real implementation, this would actually sign the PSBT\n // For the mock, we just return the input with a mock signature appended\n return psbtHex + \"deadbeef\";\n }\n\n async signPsbts(\n psbtsHexes: string[],\n _options?: SignPsbtOptions[],\n ): Promise<string[]> {\n const signedPsbts: string[] = [];\n for (const psbtHex of psbtsHexes) {\n const signedPsbt = await this.signPsbt(psbtHex);\n signedPsbts.push(signedPsbt);\n }\n return signedPsbts;\n }\n\n async signMessage(\n message: string,\n type: \"bip322-simple\" | \"ecdsa\",\n ): Promise<string> {\n // Only BIP-322 witnesses are implemented; returning one for \"ecdsa\"\n // would hand a future ECDSA-flow test the wrong artifact silently.\n if (type !== \"bip322-simple\") {\n throw new Error(\n \"MockBitcoinWallet.signMessage: only bip322-simple is implemented\",\n );\n }\n if (this.config.shouldFailSigning) {\n throw new Error(\"Mock signing failed\");\n }\n\n if (!message || message.length === 0) {\n throw new Error(\"Invalid message: empty string\");\n }\n\n // PoP flows verify the witness against `publicKeyHex`, so a divergent\n // key pair must fail loudly here, not as a confusing verify mismatch.\n const signingXOnlyHex = xOnlyPubkeyHexOf(this.config.privateKeyHex);\n let configuredXOnlyHex: string | undefined;\n try {\n configuredXOnlyHex = canonicalizeBtcPubkey(this.config.publicKeyHex);\n } catch {\n configuredXOnlyHex = undefined; // an unparseable key cannot match\n }\n if (configuredXOnlyHex !== signingXOnlyHex) {\n throw new Error(\n `MockBitcoinWallet.signMessage: privateKeyHex signs as x-only pubkey ` +\n `${signingXOnlyHex}, but publicKeyHex is ${this.config.publicKeyHex}. ` +\n `Pass a matching publicKeyHex/privateKeyHex pair.`,\n );\n }\n\n // The SDK cryptographically verifies what a wallet returns\n // (`verifyPopWitness`), so the mock signs a REAL BIP-322 P2WPKH witness\n // with its private key.\n const witness = signBip322P2wpkhWitness(\n new TextEncoder().encode(message),\n Uint8Array.from(Buffer.from(this.config.privateKeyHex, \"hex\")),\n );\n return `0x${uint8ArrayToHex(witness)}`;\n }\n\n async getNetwork(): Promise<BitcoinNetwork> {\n return this.config.network;\n }\n\n async deriveContextHash(appName: string, context: string): Promise<string> {\n return this.config.deriveContextHash(appName, context);\n }\n\n /** Updates configuration for testing different scenarios. */\n updateConfig(updates: Partial<MockBitcoinWalletConfig>): void {\n this.config = {\n ...this.config,\n ...updates,\n };\n // Mirror the constructor: a private-key-only update re-derives the\n // matching pubkey; an explicit publicKeyHex still wins.\n if (updates.privateKeyHex && !updates.publicKeyHex) {\n this.config.publicKeyHex = xOnlyPubkeyHexOf(updates.privateKeyHex);\n }\n }\n\n /** Resets to default configuration. */\n reset(): void {\n this.config = { ...DEFAULT_CONFIG };\n }\n}\n","import { Buffer } from \"buffer\";\nimport type { Address, Hex } from \"viem\";\n\n/**\n * Configuration for MockEthereumWallet.\n */\nexport interface MockEthereumWalletConfig {\n address?: Address;\n chainId?: number;\n shouldFailOperations?: boolean;\n transactionDelay?: number;\n}\n\n/**\n * Mock Ethereum wallet for testing.\n *\n * Provides the subset of viem's WalletClient methods used by the SDK.\n * Can be passed to functions expecting a WalletClient for testing purposes.\n */\nexport class MockEthereumWallet {\n // Public properties matching viem's WalletClient structure\n account: { address: Address };\n chain: { id: number };\n\n private shouldFailOperations: boolean;\n private transactionDelay: number;\n private nonce: number = 0;\n\n constructor(config: MockEthereumWalletConfig = {}) {\n // Use lowercase addresses to avoid EIP-55 checksum validation issues\n this.account = {\n address:\n config.address ||\n (\"0x742d35cc6634c0532925a3b844bc9e7595f0beb0\" as Address),\n };\n\n this.chain = {\n id: config.chainId ?? 11155111, // Sepolia by default\n };\n\n this.shouldFailOperations = config.shouldFailOperations ?? false;\n this.transactionDelay = config.transactionDelay ?? 0;\n\n // Bind methods to preserve 'this' context when called\n this.signMessage = this.signMessage.bind(this);\n this.sendTransaction = this.sendTransaction.bind(this);\n }\n\n async signMessage(args: { message: string; account?: Address }): Promise<Hex> {\n const message = args.message;\n const account = args.account || this.account.address;\n\n if (this.shouldFailOperations) {\n throw new Error(\"Mock signing failed\");\n }\n\n if (!message || message.length === 0) {\n throw new Error(\"Invalid message: empty string\");\n }\n\n // Generate a deterministic mock signature\n const signatureData = `personal_sign:${message}-${account}-${this.chain.id}`;\n const signature = `0x${Buffer.from(signatureData)\n .toString(\"hex\")\n .slice(0, 130)\n .padEnd(130, \"0\")}` as Hex;\n return signature;\n }\n\n async sendTransaction(tx: {\n to: Address;\n data?: Hex;\n value?: bigint;\n gas?: bigint;\n account?: { address: Address };\n chain?: { id: number };\n }): Promise<Hex> {\n if (this.shouldFailOperations) {\n throw new Error(\"Mock transaction failed\");\n }\n\n if (!tx.to) {\n throw new Error(\"Invalid transaction: missing 'to' address\");\n }\n\n // Simulate network delay if configured\n if (this.transactionDelay > 0) {\n await new Promise((resolve) =>\n setTimeout(resolve, this.transactionDelay),\n );\n }\n\n // Generate a deterministic mock transaction hash\n this.nonce++;\n const txData = JSON.stringify({\n from: this.account.address,\n to: tx.to,\n value: tx.value?.toString() || \"0\",\n nonce: this.nonce,\n chainId: this.chain.id,\n });\n\n const hash = `0x${Buffer.from(txData)\n .toString(\"hex\")\n .slice(0, 64)\n .padEnd(64, \"0\")}` as Hex;\n return hash;\n }\n\n /** Updates configuration for testing different scenarios. */\n updateConfig(updates: Partial<MockEthereumWalletConfig>): void {\n if (updates.address !== undefined) {\n this.account.address = updates.address;\n }\n if (updates.chainId !== undefined) {\n this.chain.id = updates.chainId;\n }\n if (updates.shouldFailOperations !== undefined) {\n this.shouldFailOperations = updates.shouldFailOperations;\n }\n if (updates.transactionDelay !== undefined) {\n this.transactionDelay = updates.transactionDelay;\n }\n }\n\n /** Resets to default configuration and nonce. */\n reset(): void {\n this.account.address =\n \"0x742d35cc6634c0532925a3b844bc9e7595f0beb0\" as Address;\n this.chain.id = 11155111;\n this.shouldFailOperations = false;\n this.transactionDelay = 0;\n this.nonce = 0;\n }\n\n /** Returns current nonce for testing. */\n getCurrentNonce(): number {\n return this.nonce;\n }\n}\n"],"names":["BIP322_TAG","SIGHASH_ALL","ZERO_SATS","MIN_ENCODED_SIG_BYTES","MAX_SIGN_GRIND_ATTEMPTS","BIP322_TX_VERSION","BIP322_TX_LOCKTIME","BIP322_INPUT_SEQUENCE","TO_SPEND_PREVOUT_TXID_BYTES","TO_SPEND_PREVOUT_INDEX","TO_SPEND_OUTPUT_INDEX","OP_0","OP_PUSHBYTES_32","OP_RETURN","P2WPKH_WITNESS_ITEMS","GRIND_ENTROPY_BYTES","GRIND_COUNTER_OFFSET","signBip322P2wpkhWitness","messageBytes","privateKey","pubkey","ecc","tagHash","sha256","messageHash","Buffer","p2wpkh","payments","toSpend","Transaction","toSign","scriptCode","sighash","encodedSignature","attempt","entropy","candidate","bscript","defaultDeriveContextHash","appName","context","enc","nameBytes","ctxBytes","buf","view","uint8ArrayToHex","DEFAULT_PRIVATE_KEY_HEX","xOnlyPubkeyHexOf","privateKeyHex","DEFAULT_CONFIG","BitcoinNetworks","MockBitcoinWallet","config","__publicField","psbtHex","_options","psbtsHexes","signedPsbts","signedPsbt","message","type","signingXOnlyHex","configuredXOnlyHex","canonicalizeBtcPubkey","witness","updates","MockEthereumWallet","args","account","signatureData","tx","resolve","txData","_a"],"mappings":";;;;;;;;;AAyBA,MAAMA,IAAa,0BACbC,IAAc,GACdC,IAAY,GAOZC,IAAwB,IACxBC,IAA0B,KAI1BC,IAAoB,GACpBC,IAAqB,GACrBC,IAAwB,GAExBC,IAA8B,IAC9BC,IAAyB,YAEzB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A,IAAA,GAK7C,KAAK;AACL,UAAMC,IAAS,KAAK,UAAU;AAAA,MAC5B,MAAM,KAAK,QAAQ;AAAA,MACnB,IAAIF,EAAG;AAAA,MACP,SAAOG,IAAAH,EAAG,UAAH,gBAAAG,EAAU,eAAc;AAAA,MAC/B,OAAO,KAAK;AAAA,MACZ,SAAS,KAAK,MAAM;AAAA,IAAA,CACrB;AAMD,WAJa,KAAKjD,EAAO,KAAKgD,CAAM,EACjC,SAAS,KAAK,EACd,MAAM,GAAG,EAAE,EACX,OAAO,IAAI,GAAG,CAAC;AAAA,EAEpB;AAAA;AAAA,EAGA,aAAaP,GAAkD;AAC7D,IAAIA,EAAQ,YAAY,WACtB,KAAK,QAAQ,UAAUA,EAAQ,UAE7BA,EAAQ,YAAY,WACtB,KAAK,MAAM,KAAKA,EAAQ,UAEtBA,EAAQ,yBAAyB,WACnC,KAAK,uBAAuBA,EAAQ,uBAElCA,EAAQ,qBAAqB,WAC/B,KAAK,mBAAmBA,EAAQ;AAAA,EAEpC;AAAA;AAAA,EAGA,QAAc;AACZ,SAAK,QAAQ,UACX,8CACF,KAAK,MAAM,KAAK,UAChB,KAAK,uBAAuB,IAC5B,KAAK,mBAAmB,GACxB,KAAK,QAAQ;AAAA,EACf;AAAA;AAAA,EAGA,kBAA0B;AACxB,WAAO,KAAK;AAAA,EACd;AACF;"}
1
+ {"version":3,"file":"index.js","sources":["../../src/testing/signBip322P2wpkhWitness.ts","../../src/testing/MockBitcoinWallet.ts","../../src/testing/MockEthereumWallet.ts"],"sourcesContent":["/**\n * Test-support BIP-322 \"simple\" P2WPKH signer.\n *\n * Produces the consensus-encoded two-item witness `[DER sig ‖ 0x01,\n * compressed pubkey]` that a Native SegWit software wallet returns for\n * `signMessage(..., \"bip322-simple\")`. The virtual to_spend/to_sign\n * construction follows the `bip322` crate 0.0.10 (`util.rs:18-85`) — the\n * same reference the production verifier\n * (`tbv/core/clients/vault-provider/auth/bip322Verify.ts`) mirrors, and\n * the BIP-322 official vectors pin.\n *\n * Conscious call: `./testing` deliberately depends on the Bitcoin stack\n * (bitcoinjs-lib was already in this entry's graph via MockBitcoinWallet;\n * tiny-secp256k1-asmjs is new here) — out of scope for the CLAUDE.md §9\n * optional-BTC split.\n *\n * Test-only: never feed real key material to this module.\n */\n\nimport * as ecc from \"@bitcoin-js/tiny-secp256k1-asmjs\";\nimport { sha256 } from \"@noble/hashes/sha2.js\";\nimport { script as bscript, payments, Transaction } from \"bitcoinjs-lib\";\nimport { Buffer } from \"buffer\";\n\n/** BIP-322 message tag (BIP-340 tagged-hash style). */\nconst BIP322_TAG = \"BIP0322-signed-message\";\nconst SIGHASH_ALL = 0x01;\nconst ZERO_SATS = 0;\n/**\n * vaultd accepts only 71/72-byte encoded signatures (`bip322` crate 0.0.10\n * `verify.rs:141-153`); a short-DER signature (~0.4% of draws) is ground\n * away by re-signing with fresh entropy. 100 attempts bounds the failure\n * probability around 0.004^100.\n */\nconst MIN_ENCODED_SIG_BYTES = 71;\nconst MAX_SIGN_GRIND_ATTEMPTS = 100;\n\n// Wire fields of the virtual to_spend/to_sign transactions (`bip322`\n// crate 0.0.10 `util.rs:18-85`).\nconst BIP322_TX_VERSION = 0;\nconst BIP322_TX_LOCKTIME = 0;\nconst BIP322_INPUT_SEQUENCE = 0;\n/** to_spend prevout: all-zero 32-byte txid at index 0xFFFFFFFF (`util.rs:18-85`). */\nconst TO_SPEND_PREVOUT_TXID_BYTES = 32;\nconst TO_SPEND_PREVOUT_INDEX = 0xffffffff;\n/** to_sign spends to_spend's only output (`util.rs:18-85`). */\nconst TO_SPEND_OUTPUT_INDEX = 0;\nconst OP_0 = 0x00;\n/** Direct push of the 32-byte tagged message hash. */\nconst OP_PUSHBYTES_32 = 0x20;\nconst OP_RETURN = 0x6a;\n/** Consensus P2WPKH witness: exactly [signature, pubkey]. */\nconst P2WPKH_WITNESS_ITEMS = 2;\n/** Grinding: 32-byte extra-entropy buffer, attempt counter at offset 0. */\nconst GRIND_ENTROPY_BYTES = 32;\nconst GRIND_COUNTER_OFFSET = 0;\n\n/**\n * Sign `messageBytes` as a BIP-322 \"simple\" P2WPKH proof with `privateKey`\n * and return the consensus-encoded two-item witness\n * (`0x02 ‖ len ‖ sig ‖ 0x21 ‖ pubkey`).\n */\nexport function signBip322P2wpkhWitness(\n messageBytes: Uint8Array,\n privateKey: Uint8Array,\n): Uint8Array {\n const pubkey = ecc.pointFromScalar(privateKey, true);\n if (!pubkey) {\n throw new Error(\"signBip322P2wpkhWitness: invalid private key\");\n }\n\n // m_hash = SHA256( SHA256(tag) ‖ SHA256(tag) ‖ message )\n const tagHash = sha256(new TextEncoder().encode(BIP322_TAG));\n const messageHash = sha256(\n Buffer.concat([tagHash, tagHash, Buffer.from(messageBytes)]),\n );\n\n const p2wpkh = payments.p2wpkh({ pubkey: Buffer.from(pubkey) });\n if (!p2wpkh.output || !p2wpkh.hash) {\n throw new Error(\"signBip322P2wpkhWitness: could not derive P2WPKH script\");\n }\n\n // to_spend / to_sign per bip322 crate util.rs:18-85.\n const toSpend = new Transaction();\n toSpend.version = BIP322_TX_VERSION;\n toSpend.locktime = BIP322_TX_LOCKTIME;\n toSpend.addInput(\n Buffer.alloc(TO_SPEND_PREVOUT_TXID_BYTES, 0),\n TO_SPEND_PREVOUT_INDEX,\n BIP322_INPUT_SEQUENCE,\n Buffer.concat([\n Buffer.from([OP_0, OP_PUSHBYTES_32]),\n Buffer.from(messageHash),\n ]),\n );\n toSpend.addOutput(p2wpkh.output, ZERO_SATS);\n const toSign = new Transaction();\n toSign.version = BIP322_TX_VERSION;\n toSign.locktime = BIP322_TX_LOCKTIME;\n toSign.addInput(\n toSpend.getHash(),\n TO_SPEND_OUTPUT_INDEX,\n BIP322_INPUT_SEQUENCE,\n );\n toSign.addOutput(Buffer.from([OP_RETURN]), ZERO_SATS);\n\n // BIP-143 sighash with the standard P2WPKH scriptCode, value 0\n // (bip322 crate verify.rs:163-173).\n const scriptCode = payments.p2pkh({ hash: p2wpkh.hash }).output;\n if (!scriptCode) {\n throw new Error(\"signBip322P2wpkhWitness: could not build scriptCode\");\n }\n const sighash = toSign.hashForWitnessV0(\n 0,\n scriptCode,\n ZERO_SATS,\n SIGHASH_ALL,\n );\n\n let encodedSignature: Buffer | undefined;\n for (let attempt = 0; attempt < MAX_SIGN_GRIND_ATTEMPTS; attempt++) {\n const entropy = Buffer.alloc(GRIND_ENTROPY_BYTES, 0);\n entropy.writeUInt32LE(attempt, GRIND_COUNTER_OFFSET);\n // ecc.sign emits low-S (libsecp256k1), so 73-byte encodings can't occur.\n const candidate = bscript.signature.encode(\n Buffer.from(ecc.sign(sighash, privateKey, entropy)),\n SIGHASH_ALL,\n );\n if (candidate.length >= MIN_ENCODED_SIG_BYTES) {\n encodedSignature = candidate;\n break;\n }\n }\n if (!encodedSignature) {\n throw new Error(\n \"signBip322P2wpkhWitness: could not grind a 71/72-byte signature\",\n );\n }\n\n return Uint8Array.from([\n P2WPKH_WITNESS_ITEMS,\n encodedSignature.length,\n ...encodedSignature,\n pubkey.length,\n ...pubkey,\n ]);\n}\n","import * as ecc from \"@bitcoin-js/tiny-secp256k1-asmjs\";\nimport { sha256 } from \"@noble/hashes/sha2.js\";\nimport { Buffer } from \"buffer\";\n\nimport {\n BitcoinNetworks,\n type BitcoinNetwork,\n} from \"../shared/wallets/interfaces\";\nimport type {\n BitcoinWallet,\n SignPsbtOptions,\n} from \"../shared/wallets/interfaces/BitcoinWallet\";\nimport {\n canonicalizeBtcPubkey,\n uint8ArrayToHex,\n} from \"../tbv/core/primitives/utils/bitcoin\";\nimport { signBip322P2wpkhWitness } from \"./signBip322P2wpkhWitness\";\n\n/**\n * Configuration for MockBitcoinWallet.\n */\nexport interface MockBitcoinWalletConfig {\n publicKeyHex?: string;\n address?: string;\n network?: BitcoinNetwork;\n shouldFailSigning?: boolean;\n /**\n * 32-byte hex key `signMessage` signs BIP-322 proofs with. Defaults to\n * the privkey-1 test key, whose x-only pubkey is the default\n * `publicKeyHex` (the secp256k1 generator's x coordinate). PoP flows\n * verify the witness against `publicKeyHex`: overriding only this key\n * derives the matching `publicKeyHex`, and a divergent pair throws at\n * sign time. Test material only — never a real key.\n */\n privateKeyHex?: string;\n /**\n * Optional override for `deriveContextHash`. When omitted the mock\n * returns a deterministic 64-char lowercase hex string derived from\n * `(appName, context)` so tests can assert pass-through wiring\n * without pinning a specific value. Override to inject conformance test\n * vectors or to simulate failure modes.\n */\n deriveContextHash?: (appName: string, context: string) => Promise<string>;\n}\n\n/**\n * Default `deriveContextHash` implementation: deterministic and\n * collision-resistant via SHA-256, so tests that assert pass-through\n * wiring (different `(appName, context)` → different output) hold\n * without flakes. Domain-separates the two inputs by length-prefixing\n * each as `len(name) || name || len(ctx) || ctx`, preventing\n * `(\"ab\", \"cd\")` from colliding with `(\"abc\", \"d\")`.\n */\nconst defaultDeriveContextHash = async (\n appName: string,\n context: string,\n): Promise<string> => {\n const enc = new TextEncoder();\n const nameBytes = enc.encode(appName);\n const ctxBytes = enc.encode(context);\n const buf = new Uint8Array(4 + nameBytes.length + 4 + ctxBytes.length);\n const view = new DataView(buf.buffer);\n view.setUint32(0, nameBytes.length);\n buf.set(nameBytes, 4);\n view.setUint32(4 + nameBytes.length, ctxBytes.length);\n buf.set(ctxBytes, 4 + nameBytes.length + 4);\n return uint8ArrayToHex(sha256(buf));\n};\n\n/** Privkey 1 — the test key `signMessage` signs with by default. */\nconst DEFAULT_PRIVATE_KEY_HEX = `${\"00\".repeat(31)}01`;\n\n/** Lowercase x-only pubkey of a 32-byte private key. */\nfunction xOnlyPubkeyHexOf(privateKeyHex: string): string {\n return uint8ArrayToHex(\n ecc.xOnlyPointFromScalar(\n Uint8Array.from(Buffer.from(privateKeyHex, \"hex\")),\n ),\n );\n}\n\nconst DEFAULT_CONFIG: Required<MockBitcoinWalletConfig> = {\n // x-only pubkey of DEFAULT_PRIVATE_KEY_HEX (the secp256k1 generator's x\n // coordinate), so the default wallet's PoP witnesses verify against it.\n publicKeyHex:\n \"79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798\",\n address: \"tb1pqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqkx6jks\",\n network: BitcoinNetworks.SIGNET,\n shouldFailSigning: false,\n privateKeyHex: DEFAULT_PRIVATE_KEY_HEX,\n deriveContextHash: defaultDeriveContextHash,\n};\n\n/** Mock Bitcoin wallet for testing. */\nexport class MockBitcoinWallet implements BitcoinWallet {\n private config: Required<MockBitcoinWalletConfig>;\n\n constructor(config: MockBitcoinWalletConfig = {}) {\n this.config = {\n ...DEFAULT_CONFIG,\n ...(config.publicKeyHex ? { publicKeyHex: config.publicKeyHex } : {}),\n ...(config.address ? { address: config.address } : {}),\n ...(config.network !== undefined ? { network: config.network } : {}),\n ...(config.shouldFailSigning !== undefined\n ? { shouldFailSigning: config.shouldFailSigning }\n : {}),\n ...(config.privateKeyHex ? { privateKeyHex: config.privateKeyHex } : {}),\n ...(config.deriveContextHash\n ? { deriveContextHash: config.deriveContextHash }\n : {}),\n };\n // A private-key override without a public key would otherwise sign\n // against the DEFAULT pubkey — derive the matching one instead.\n if (config.privateKeyHex && !config.publicKeyHex) {\n this.config.publicKeyHex = xOnlyPubkeyHexOf(config.privateKeyHex);\n }\n }\n\n async getPublicKeyHex(): Promise<string> {\n return this.config.publicKeyHex;\n }\n\n async getAddress(): Promise<string> {\n return this.config.address;\n }\n\n async signPsbt(psbtHex: string, _options?: SignPsbtOptions): Promise<string> {\n if (this.config.shouldFailSigning) {\n throw new Error(\"Mock signing failed\");\n }\n\n if (!psbtHex || psbtHex.length === 0) {\n throw new Error(\"Invalid PSBT: empty hex string\");\n }\n\n // In a real implementation, this would actually sign the PSBT\n // For the mock, we just return the input with a mock signature appended\n return psbtHex + \"deadbeef\";\n }\n\n async signPsbts(\n psbtsHexes: string[],\n _options?: SignPsbtOptions[],\n ): Promise<string[]> {\n const signedPsbts: string[] = [];\n for (const psbtHex of psbtsHexes) {\n const signedPsbt = await this.signPsbt(psbtHex);\n signedPsbts.push(signedPsbt);\n }\n return signedPsbts;\n }\n\n async signMessage(\n message: string,\n type: \"bip322-simple\" | \"ecdsa\",\n ): Promise<string> {\n // Only BIP-322 witnesses are implemented; returning one for \"ecdsa\"\n // would hand a future ECDSA-flow test the wrong artifact silently.\n if (type !== \"bip322-simple\") {\n throw new Error(\n \"MockBitcoinWallet.signMessage: only bip322-simple is implemented\",\n );\n }\n if (this.config.shouldFailSigning) {\n throw new Error(\"Mock signing failed\");\n }\n\n if (!message || message.length === 0) {\n throw new Error(\"Invalid message: empty string\");\n }\n\n // PoP flows verify the witness against `publicKeyHex`, so a divergent\n // key pair must fail loudly here, not as a confusing verify mismatch.\n const signingXOnlyHex = xOnlyPubkeyHexOf(this.config.privateKeyHex);\n let configuredXOnlyHex: string | undefined;\n try {\n configuredXOnlyHex = canonicalizeBtcPubkey(this.config.publicKeyHex);\n } catch {\n configuredXOnlyHex = undefined; // an unparseable key cannot match\n }\n if (configuredXOnlyHex !== signingXOnlyHex) {\n throw new Error(\n `MockBitcoinWallet.signMessage: privateKeyHex signs as x-only pubkey ` +\n `${signingXOnlyHex}, but publicKeyHex is ${this.config.publicKeyHex}. ` +\n `Pass a matching publicKeyHex/privateKeyHex pair.`,\n );\n }\n\n // The SDK cryptographically verifies what a wallet returns\n // (`verifyPopWitness`), so the mock signs a REAL BIP-322 P2WPKH witness\n // with its private key.\n const witness = signBip322P2wpkhWitness(\n new TextEncoder().encode(message),\n Uint8Array.from(Buffer.from(this.config.privateKeyHex, \"hex\")),\n );\n return `0x${uint8ArrayToHex(witness)}`;\n }\n\n async getNetwork(): Promise<BitcoinNetwork> {\n return this.config.network;\n }\n\n async deriveContextHash(appName: string, context: string): Promise<string> {\n return this.config.deriveContextHash(appName, context);\n }\n\n /** Updates configuration for testing different scenarios. */\n updateConfig(updates: Partial<MockBitcoinWalletConfig>): void {\n this.config = {\n ...this.config,\n ...updates,\n };\n // Mirror the constructor: a private-key-only update re-derives the\n // matching pubkey; an explicit publicKeyHex still wins.\n if (updates.privateKeyHex && !updates.publicKeyHex) {\n this.config.publicKeyHex = xOnlyPubkeyHexOf(updates.privateKeyHex);\n }\n }\n\n /** Resets to default configuration. */\n reset(): void {\n this.config = { ...DEFAULT_CONFIG };\n }\n}\n","import { Buffer } from \"buffer\";\nimport type { Address, Hex } from \"viem\";\n\n/**\n * Configuration for MockEthereumWallet.\n */\nexport interface MockEthereumWalletConfig {\n address?: Address;\n chainId?: number;\n shouldFailOperations?: boolean;\n transactionDelay?: number;\n}\n\n/**\n * Mock Ethereum wallet for testing.\n *\n * Provides the subset of viem's WalletClient methods used by the SDK.\n * Can be passed to functions expecting a WalletClient for testing purposes.\n */\nexport class MockEthereumWallet {\n // Public properties matching viem's WalletClient structure\n account: { address: Address };\n chain: { id: number };\n\n private shouldFailOperations: boolean;\n private transactionDelay: number;\n private nonce: number = 0;\n\n constructor(config: MockEthereumWalletConfig = {}) {\n // Use lowercase addresses to avoid EIP-55 checksum validation issues\n this.account = {\n address:\n config.address ||\n (\"0x742d35cc6634c0532925a3b844bc9e7595f0beb0\" as Address),\n };\n\n this.chain = {\n id: config.chainId ?? 11155111, // Sepolia by default\n };\n\n this.shouldFailOperations = config.shouldFailOperations ?? false;\n this.transactionDelay = config.transactionDelay ?? 0;\n\n // Bind methods to preserve 'this' context when called\n this.signMessage = this.signMessage.bind(this);\n this.sendTransaction = this.sendTransaction.bind(this);\n }\n\n async signMessage(args: { message: string; account?: Address }): Promise<Hex> {\n const message = args.message;\n const account = args.account || this.account.address;\n\n if (this.shouldFailOperations) {\n throw new Error(\"Mock signing failed\");\n }\n\n if (!message || message.length === 0) {\n throw new Error(\"Invalid message: empty string\");\n }\n\n // Generate a deterministic mock signature\n const signatureData = `personal_sign:${message}-${account}-${this.chain.id}`;\n const signature = `0x${Buffer.from(signatureData)\n .toString(\"hex\")\n .slice(0, 130)\n .padEnd(130, \"0\")}` as Hex;\n return signature;\n }\n\n async sendTransaction(tx: {\n to: Address;\n data?: Hex;\n value?: bigint;\n gas?: bigint;\n account?: { address: Address };\n chain?: { id: number };\n }): Promise<Hex> {\n if (this.shouldFailOperations) {\n throw new Error(\"Mock transaction failed\");\n }\n\n if (!tx.to) {\n throw new Error(\"Invalid transaction: missing 'to' address\");\n }\n\n // Simulate network delay if configured\n if (this.transactionDelay > 0) {\n await new Promise((resolve) =>\n setTimeout(resolve, this.transactionDelay),\n );\n }\n\n // Generate a deterministic mock transaction hash\n this.nonce++;\n const txData = JSON.stringify({\n from: this.account.address,\n to: tx.to,\n value: tx.value?.toString() || \"0\",\n nonce: this.nonce,\n chainId: this.chain.id,\n });\n\n const hash = `0x${Buffer.from(txData)\n .toString(\"hex\")\n .slice(0, 64)\n .padEnd(64, \"0\")}` as Hex;\n return hash;\n }\n\n /** Updates configuration for testing different scenarios. */\n updateConfig(updates: Partial<MockEthereumWalletConfig>): void {\n if (updates.address !== undefined) {\n this.account.address = updates.address;\n }\n if (updates.chainId !== undefined) {\n this.chain.id = updates.chainId;\n }\n if (updates.shouldFailOperations !== undefined) {\n this.shouldFailOperations = updates.shouldFailOperations;\n }\n if (updates.transactionDelay !== undefined) {\n this.transactionDelay = updates.transactionDelay;\n }\n }\n\n /** Resets to default configuration and nonce. */\n reset(): void {\n this.account.address =\n \"0x742d35cc6634c0532925a3b844bc9e7595f0beb0\" as Address;\n this.chain.id = 11155111;\n this.shouldFailOperations = false;\n this.transactionDelay = 0;\n this.nonce = 0;\n }\n\n /** Returns current nonce for testing. */\n getCurrentNonce(): number {\n return this.nonce;\n }\n}\n"],"names":["BIP322_TAG","SIGHASH_ALL","ZERO_SATS","MIN_ENCODED_SIG_BYTES","MAX_SIGN_GRIND_ATTEMPTS","BIP322_TX_VERSION","BIP322_TX_LOCKTIME","BIP322_INPUT_SEQUENCE","TO_SPEND_PREVOUT_TXID_BYTES","TO_SPEND_PREVOUT_INDEX","TO_SPEND_OUTPUT_INDEX","OP_0","OP_PUSHBYTES_32","OP_RETURN","P2WPKH_WITNESS_ITEMS","GRIND_ENTROPY_BYTES","GRIND_COUNTER_OFFSET","signBip322P2wpkhWitness","messageBytes","privateKey","pubkey","ecc","tagHash","sha256","messageHash","Buffer","p2wpkh","payments","toSpend","Transaction","toSign","scriptCode","sighash","encodedSignature","attempt","entropy","candidate","bscript","defaultDeriveContextHash","appName","context","enc","nameBytes","ctxBytes","buf","view","uint8ArrayToHex","DEFAULT_PRIVATE_KEY_HEX","xOnlyPubkeyHexOf","privateKeyHex","DEFAULT_CONFIG","BitcoinNetworks","MockBitcoinWallet","config","__publicField","psbtHex","_options","psbtsHexes","signedPsbts","signedPsbt","message","type","signingXOnlyHex","configuredXOnlyHex","canonicalizeBtcPubkey","witness","updates","MockEthereumWallet","args","account","signatureData","tx","resolve","txData","_a"],"mappings":";;;;;;;;;AAyBA,MAAMA,IAAa,0BACbC,IAAc,GACdC,IAAY,GAOZC,IAAwB,IACxBC,IAA0B,KAI1BC,IAAoB,GACpBC,IAAqB,GACrBC,IAAwB,GAExBC,IAA8B,IAC9BC,IAAyB,YAEzBC,IAAwB,GACxBC,IAAO,GAEPC,IAAkB,IAClBC,IAAY,KAEZC,IAAuB,GAEvBC,IAAsB,IACtBC,IAAuB;AAOtB,SAASC,EACdC,GACAC,GACY;AACZ,QAAMC,IAASC,EAAI,gBAAgBF,GAAY,EAAI;AACnD,MAAI,CAACC;AACH,UAAM,IAAI,MAAM,8CAA8C;AAIhE,QAAME,IAAUC,EAAO,IAAI,cAAc,OAAOvB,CAAU,CAAC,GACrDwB,IAAcD;AAAA,IAClBE,EAAO,OAAO,CAACH,GAASA,GAASG,EAAO,KAAKP,CAAY,CAAC,CAAC;AAAA,EAAA,GAGvDQ,IAASC,EAAS,OAAO,EAAE,QAAQF,EAAO,KAAKL,CAAM,GAAG;AAC9D,MAAI,CAACM,EAAO,UAAU,CAACA,EAAO;AAC5B,UAAM,IAAI,MAAM,yDAAyD;AAI3E,QAAME,IAAU,IAAIC,EAAA;AACpB,EAAAD,EAAQ,UA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qBAAqB,WAC/B,KAAK,mBAAmBA,EAAQ;AAAA,EAEpC;AAAA;AAAA,EAGA,QAAc;AACZ,SAAK,QAAQ,UACX,8CACF,KAAK,MAAM,KAAK,UAChB,KAAK,uBAAuB,IAC5B,KAAK,mBAAmB,GACxB,KAAK,QAAQ;AAAA,EACf;AAAA;AAAA,EAGA,kBAA0B;AACxB,WAAO,KAAK;AAAA,EACd;AACF;"}
@@ -3,13 +3,13 @@ var ne = (e, t, r) => t in e ? re(e, t, { enumerable: !0, configurable: !0, writ
3
3
  var _ = (e, t, r) => ne(e, typeof t != "symbol" ? t + "" : t, r);
4
4
  import { keccak256 as G, toHex as oe, encodeAbiParameters as se, isAddress as ie, zeroAddress as ae } from "viem";
5
5
  import { s as ce } from "./sha2-CLpQd0Rd.js";
6
- import { a as M } from "./signPsbtsWithFallback-f7QLp0q8.js";
7
- import { b as ue, a as le } from "./PeginManager-BXlh3ar0.js";
6
+ import { a as M } from "./signPsbtsWithFallback-DoRbHHua.js";
7
+ import { b as ue, a as le } from "./PeginManager-BH_AKu4l.js";
8
8
  import { s as f, h as he, p as W, u as de, e as me } from "./bitcoin-C-TuHb-v.js";
9
9
  import { computeMinClaimValue as Q, computeMinPeginFee as q, peginP2aAnchorOutput as X, getPrePeginHtlcConnectorInfo as pe, expandAuthAnchor as ge } from "./tbv/core/wasm/index.js";
10
- import { p as Pe, d as fe } from "./parseFundingOutpoints-BQWvINfm.js";
10
+ import { p as Pe, d as fe } from "./parseFundingOutpoints-CC4NKYz2.js";
11
11
  import { Transaction as J } from "bitcoinjs-lib";
12
- import { o as ve, H as z } from "./verifyScriptPathSchnorrSignature-D_epga4j.js";
12
+ import { o as ve, H as z } from "./verifyScriptPathSchnorrSignature-CpjSTfMj.js";
13
13
  import { c as O } from "./fundPeginTransaction-CwhRbCQC.js";
14
14
  import { c as Y } from "./signing-Cm-McVR2.js";
15
15
  const Z = "DepositTermsRejectedError";
@@ -555,4 +555,4 @@ export {
555
555
  ye as r,
556
556
  nt as t
557
557
  };
558
- //# sourceMappingURL=toRefundInputs-9inv4Ai4.js.map
558
+ //# sourceMappingURL=toRefundInputs-BEulLgN_.js.map