@babylonlabs-io/ts-sdk 0.22.0 → 0.23.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{buildAndBroadcastRefund-DWEQvj9T.cjs → buildAndBroadcastRefund-BDGGbGeK.cjs} +2 -2
- package/dist/buildAndBroadcastRefund-BDGGbGeK.cjs.map +1 -0
- package/dist/{buildAndBroadcastRefund-DnTQkCgG.js → buildAndBroadcastRefund-D7NCbgtv.js} +79 -77
- package/dist/buildAndBroadcastRefund-D7NCbgtv.js.map +1 -0
- package/dist/errors-BcpQEG62.cjs +2 -0
- package/dist/errors-BcpQEG62.cjs.map +1 -0
- package/dist/errors-D3a9XcIX.js +1275 -0
- package/dist/errors-D3a9XcIX.js.map +1 -0
- package/dist/index.cjs +1 -1
- package/dist/index.js +2 -2
- package/dist/tbv/core/index.cjs +1 -1
- package/dist/tbv/core/index.js +2 -2
- package/dist/tbv/core/managers/PayoutManager.d.ts +1 -1
- package/dist/tbv/core/managers/PeginManager.d.ts +57 -51
- package/dist/tbv/core/managers/PeginManager.d.ts.map +1 -1
- package/dist/tbv/core/managers/index.d.ts +7 -6
- package/dist/tbv/core/managers/index.d.ts.map +1 -1
- package/dist/tbv/core/services/index.cjs +1 -1
- package/dist/tbv/core/services/index.js +1 -1
- package/dist/tbv/core/services/refund/buildAndBroadcastRefund.d.ts +5 -1
- package/dist/tbv/core/services/refund/buildAndBroadcastRefund.d.ts.map +1 -1
- package/dist/tbv/index.cjs +1 -1
- package/dist/tbv/index.js +2 -2
- package/dist/testing/MockBitcoinWallet.d.ts +2 -2
- package/dist/testing/MockBitcoinWallet.d.ts.map +1 -1
- package/dist/testing/index.cjs +1 -1
- package/dist/testing/index.cjs.map +1 -1
- package/dist/testing/index.js +14 -14
- package/dist/testing/index.js.map +1 -1
- package/package.json +1 -1
- package/dist/buildAndBroadcastRefund-DWEQvj9T.cjs.map +0 -1
- package/dist/buildAndBroadcastRefund-DnTQkCgG.js.map +0 -1
- package/dist/errors-CkkL1ztr.js +0 -1236
- package/dist/errors-CkkL1ztr.js.map +0 -1
- package/dist/errors-D2H46Yut.cjs +0 -2
- package/dist/errors-D2H46Yut.cjs.map +0 -1
|
@@ -125,12 +125,14 @@ export interface PerVaultPeginData {
|
|
|
125
125
|
vaultScriptPubKey: string;
|
|
126
126
|
}
|
|
127
127
|
export interface PreparePeginResult {
|
|
128
|
-
/**
|
|
128
|
+
/**
|
|
129
|
+
* Funded, pre-witness Pre-PegIn tx hex. Pass this for register calls'
|
|
130
|
+
* `unsignedPrePeginTx` — despite the contract-side name, the registry
|
|
131
|
+
* stores the funded form so indexers can rebuild refund PSBTs.
|
|
132
|
+
*/
|
|
129
133
|
fundedPrePeginTxHex: string;
|
|
130
134
|
/** Funded Pre-PegIn transaction ID */
|
|
131
135
|
prePeginTxid: string;
|
|
132
|
-
/** Unfunded Pre-PegIn transaction hex (for contract DA submission) */
|
|
133
|
-
unsignedPrePeginTxHex: string;
|
|
134
136
|
/** Per-vault PegIn data — one entry per hashlock/amount */
|
|
135
137
|
perVault: PerVaultPeginData[];
|
|
136
138
|
/** UTXOs selected to fund the Pre-PegIn transaction */
|
|
@@ -165,17 +167,28 @@ export interface SignAndBroadcastParams {
|
|
|
165
167
|
value: number;
|
|
166
168
|
}>;
|
|
167
169
|
}
|
|
170
|
+
/**
|
|
171
|
+
* BIP-322 BTC Proof-of-Possession binding a depositor's BTC key to their
|
|
172
|
+
* Ethereum account. Produced by {@link PeginManager.signProofOfPossession}
|
|
173
|
+
* and reusable across every register call in the same session — the
|
|
174
|
+
* embedded identities are re-checked at register time.
|
|
175
|
+
*/
|
|
176
|
+
export interface PopSignature {
|
|
177
|
+
/** BIP-322 signature over the PoP message (0x-prefixed hex). */
|
|
178
|
+
btcPopSignature: Hex;
|
|
179
|
+
/** Ethereum address the PoP was signed for. */
|
|
180
|
+
depositorEthAddress: Address;
|
|
181
|
+
/** BTC x-only public key (64-char hex, no 0x prefix). */
|
|
182
|
+
depositorBtcPubkey: string;
|
|
183
|
+
}
|
|
168
184
|
/**
|
|
169
185
|
* Parameters for registering a peg-in on Ethereum.
|
|
170
186
|
*/
|
|
171
187
|
export interface RegisterPeginParams {
|
|
172
188
|
/**
|
|
173
|
-
*
|
|
174
|
-
*
|
|
175
|
-
|
|
176
|
-
depositorBtcPubkey: string;
|
|
177
|
-
/**
|
|
178
|
-
* Unsigned Pre-PegIn transaction hex (submitted to contract for data availability).
|
|
189
|
+
* Funded, pre-witness Pre-PegIn tx hex — pass
|
|
190
|
+
* {@link PreparePeginResult.fundedPrePeginTxHex}. The contract-side
|
|
191
|
+
* parameter is named `unsignedPrePeginTx` but it stores the funded form.
|
|
179
192
|
*/
|
|
180
193
|
unsignedPrePeginTx: string;
|
|
181
194
|
/**
|
|
@@ -190,10 +203,6 @@ export interface RegisterPeginParams {
|
|
|
190
203
|
* SHA256 hashlock for HTLC activation (bytes32 hex with 0x prefix).
|
|
191
204
|
*/
|
|
192
205
|
hashlock: Hex;
|
|
193
|
-
/**
|
|
194
|
-
* Optional callback invoked after PoP signing completes but before ETH transaction.
|
|
195
|
-
*/
|
|
196
|
-
onPopSigned?: () => void | Promise<void>;
|
|
197
206
|
/**
|
|
198
207
|
* Depositor's BTC payout address (e.g. bc1p..., bc1q...).
|
|
199
208
|
* Converted to scriptPubKey internally via bitcoinjs-lib.
|
|
@@ -204,12 +213,8 @@ export interface RegisterPeginParams {
|
|
|
204
213
|
depositorPayoutBtcAddress?: string;
|
|
205
214
|
/** Keccak256 hash of the depositor's WOTS public key (bytes32) */
|
|
206
215
|
depositorWotsPkHash: Hex;
|
|
207
|
-
/**
|
|
208
|
-
|
|
209
|
-
* When provided, the BTC wallet signing step is skipped and this signature is used directly.
|
|
210
|
-
* Useful for multi-vault deposits where PoP only needs to be signed once.
|
|
211
|
-
*/
|
|
212
|
-
preSignedBtcPopSignature?: Hex;
|
|
216
|
+
/** Proof of possession from {@link PeginManager.signProofOfPossession}. */
|
|
217
|
+
popSignature: PopSignature;
|
|
213
218
|
/**
|
|
214
219
|
* Zero-based index of the HTLC output in the Pre-PegIn transaction that
|
|
215
220
|
* this PegIn spends. In a batch Pre-PegIn with N HTLC outputs, each vault
|
|
@@ -235,26 +240,18 @@ export interface RegisterPeginResult {
|
|
|
235
240
|
* Used for VP RPC operations which key on the BTC transaction ID.
|
|
236
241
|
*/
|
|
237
242
|
peginTxHash: Hex;
|
|
238
|
-
/**
|
|
239
|
-
* The BTC PoP signature used for this registration (hex with 0x prefix).
|
|
240
|
-
* Returned so callers can reuse it for subsequent pegins without re-signing.
|
|
241
|
-
*/
|
|
242
|
-
btcPopSignature: Hex;
|
|
243
243
|
}
|
|
244
244
|
/**
|
|
245
245
|
* Single request in a batch pegin registration.
|
|
246
|
-
* All requests in a batch share the same vault provider
|
|
246
|
+
* All requests in a batch share the same vault provider, depositor BTC
|
|
247
|
+
* pubkey, and Pre-PegIn transaction.
|
|
247
248
|
*/
|
|
248
249
|
export interface BatchPeginRequestItem {
|
|
249
|
-
/** Depositor's BTC public key (x-only, 64-char hex or with 0x prefix) */
|
|
250
|
-
depositorBtcPubkey: string;
|
|
251
|
-
/** Unsigned Pre-PegIn tx hex (same for all vaults in batch) */
|
|
252
|
-
unsignedPrePeginTx: string;
|
|
253
250
|
/** Signed PegIn tx hex for this vault */
|
|
254
251
|
depositorSignedPeginTx: string;
|
|
255
252
|
/** SHA256 hashlock for HTLC activation (bytes32 hex) */
|
|
256
253
|
hashlock: Hex;
|
|
257
|
-
/** Zero-based HTLC output index in the Pre-PegIn tx */
|
|
254
|
+
/** Zero-based HTLC output index in the Pre-PegIn tx (unique per request) */
|
|
258
255
|
htlcVout: number;
|
|
259
256
|
/** Depositor's BTC payout address (required — funds are sent here on payout) */
|
|
260
257
|
depositorPayoutBtcAddress: string;
|
|
@@ -267,12 +264,15 @@ export interface BatchPeginRequestItem {
|
|
|
267
264
|
export interface RegisterPeginBatchParams {
|
|
268
265
|
/** Vault provider address (shared across all vaults in batch) */
|
|
269
266
|
vaultProvider: Address;
|
|
267
|
+
/**
|
|
268
|
+
* Funded, pre-witness Pre-PegIn tx hex — shared across every request in
|
|
269
|
+
* the batch. See {@link RegisterPeginParams.unsignedPrePeginTx}.
|
|
270
|
+
*/
|
|
271
|
+
unsignedPrePeginTx: string;
|
|
270
272
|
/** Individual pegin requests (one per vault) */
|
|
271
273
|
requests: BatchPeginRequestItem[];
|
|
272
|
-
/**
|
|
273
|
-
|
|
274
|
-
/** Called after PoP is signed (before ETH tx) */
|
|
275
|
-
onPopSigned?: () => void | Promise<void>;
|
|
274
|
+
/** Proof of possession from {@link PeginManager.signProofOfPossession}. */
|
|
275
|
+
popSignature: PopSignature;
|
|
276
276
|
}
|
|
277
277
|
/**
|
|
278
278
|
* Per-vault result from a batch pegin registration.
|
|
@@ -291,8 +291,6 @@ export interface RegisterPeginBatchResult {
|
|
|
291
291
|
ethTxHash: Hex;
|
|
292
292
|
/** Per-vault results (same order as input requests) */
|
|
293
293
|
vaults: BatchPeginResultItem[];
|
|
294
|
-
/** The BTC PoP signature used (for reference) */
|
|
295
|
-
btcPopSignature: Hex;
|
|
296
294
|
}
|
|
297
295
|
export declare class PeginManager {
|
|
298
296
|
private readonly config;
|
|
@@ -351,18 +349,25 @@ export declare class PeginManager {
|
|
|
351
349
|
* Registers a peg-in on Ethereum by calling the BTCVaultRegistry contract.
|
|
352
350
|
*
|
|
353
351
|
* This method:
|
|
354
|
-
* 1.
|
|
355
|
-
*
|
|
356
|
-
*
|
|
357
|
-
*
|
|
358
|
-
*
|
|
359
|
-
*
|
|
352
|
+
* 1. Re-verifies the PopSignature against the currently connected ETH
|
|
353
|
+
* and BTC wallets — refuses to proceed if either has changed
|
|
354
|
+
* 2. Derives vault ID and checks if it already exists (pre-flight)
|
|
355
|
+
* 3. Encodes the contract call using viem
|
|
356
|
+
* 4. Estimates gas (catches contract errors early with proper revert
|
|
357
|
+
* reasons)
|
|
358
|
+
* 5. Sends transaction with pre-estimated gas via
|
|
359
|
+
* ethWallet.sendTransaction()
|
|
360
|
+
*
|
|
361
|
+
* The PopSignature must be obtained via
|
|
362
|
+
* {@link signProofOfPossession} before this call.
|
|
360
363
|
*
|
|
361
|
-
* @param params - Registration parameters including
|
|
364
|
+
* @param params - Registration parameters including the PopSignature
|
|
365
|
+
* and the prepared Pre-PegIn / PegIn transactions
|
|
362
366
|
* @returns Result containing Ethereum transaction hash and vault ID
|
|
363
|
-
* @throws Error if
|
|
364
|
-
* @throws Error if vault already exists
|
|
365
|
-
* @throws Error if contract simulation fails (e.g., invalid signature,
|
|
367
|
+
* @throws Error if the PopSignature does not match the connected wallets
|
|
368
|
+
* @throws Error if the vault already exists
|
|
369
|
+
* @throws Error if contract simulation fails (e.g., invalid signature,
|
|
370
|
+
* unauthorized)
|
|
366
371
|
*/
|
|
367
372
|
registerPeginOnChain(params: RegisterPeginParams): Promise<RegisterPeginResult>;
|
|
368
373
|
/**
|
|
@@ -392,12 +397,13 @@ export declare class PeginManager {
|
|
|
392
397
|
*/
|
|
393
398
|
private resolvePayoutScriptPubKey;
|
|
394
399
|
/**
|
|
395
|
-
*
|
|
396
|
-
*
|
|
397
|
-
*
|
|
398
|
-
*
|
|
400
|
+
* Sign a BIP-322 BTC Proof-of-Possession binding the connected BTC
|
|
401
|
+
* wallet to the connected ETH account for this chain and vault
|
|
402
|
+
* registry. The returned {@link PopSignature} can be reused across
|
|
403
|
+
* every register call in the same session.
|
|
399
404
|
*/
|
|
400
|
-
|
|
405
|
+
signProofOfPossession(): Promise<PopSignature>;
|
|
406
|
+
private assertPopMatchesBtcWallet;
|
|
401
407
|
/**
|
|
402
408
|
* Gets the configured Bitcoin network.
|
|
403
409
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PeginManager.d.ts","sourceRoot":"","sources":["../../../../src/tbv/core/managers/PeginManager.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"PeginManager.d.ts","sourceRoot":"","sources":["../../../../src/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G,CAAC;IACb,qCAAqC;IACrC,WAAW,EAAE,GAAG,CAAC;CAClB;AAED;;GAEG;AACH,MAAM,WAAW,wBAAwB;IACvC,gCAAgC;IAChC,SAAS,EAAE,GAAG,CAAC;IACf,uDAAuD;IACvD,MAAM,EAAE,oBAAoB,EAAE,CAAC;CAChC;AAmED,qBAAa,YAAY;IACvB,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAqB;IAE5C;;;;OAIG;gBACS,MAAM,EAAE,kBAAkB;IAItC;;;;;;;;;;;;;;;;;;;OAmBG;IACG,YAAY,CAChB,MAAM,EAAE,kBAAkB,GACzB,OAAO,CAAC,kBAAkB,CAAC;IAuI9B;;;;;;OAMG;YACW,qBAAqB;IA6BnC;;;;;;;;;;;;;;OAcG;IACG,gBAAgB,CAAC,MAAM,EAAE,sBAAsB,GAAG,OAAO,CAAC,MAAM,CAAC;IAuHvE;;;;;;;;;;;;;;;;;;;;;;;OAuBG;IACG,oBAAoB,CACxB,MAAM,EAAE,mBAAmB,GAC1B,OAAO,CAAC,mBAAmB,CAAC;IAqJ/B;;;;;;;;;OASG;IACG,yBAAyB,CAC7B,MAAM,EAAE,wBAAwB,GAC/B,OAAO,CAAC,wBAAwB,CAAC;IAuJpC;;;;;OAKG;YACW,gBAAgB;IAuB9B;;;;;;OAMG;YACW,yBAAyB;IAmCvC;;;;;OAKG;IACG,qBAAqB,IAAI,OAAO,CAAC,YAAY,CAAC;YAyBtC,yBAAyB;IAkBvC;;;;OAIG;IACH,UAAU,IAAI,OAAO;IAIrB;;;;OAIG;IACH,uBAAuB,IAAI,OAAO;CAGnC"}
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* @packageDocumentation
|
|
3
3
|
*
|
|
4
4
|
* Wallet-owning orchestration for the vault lifecycle. A vault goes from creation
|
|
5
|
-
* to `ACTIVE` through
|
|
5
|
+
* to `ACTIVE` through six phases — {@link https://github.com/babylonlabs-io/babylon-toolkit/blob/main/packages/babylon-ts-sdk/docs/quickstart/managers.md | Managers Quickstart}
|
|
6
6
|
* walks through them. A vault at `VERIFIED` is not done: the depositor must
|
|
7
7
|
* reveal the HTLC secret via `activateVault()` (services layer) or the vault
|
|
8
8
|
* expires.
|
|
@@ -10,17 +10,18 @@
|
|
|
10
10
|
* | # | Phase | SDK entry point | Contract status after |
|
|
11
11
|
* |---|-------|-----------------|-----------------------|
|
|
12
12
|
* | 1 | Prepare Pre-PegIn + PegIn txs | `PeginManager.preparePegin()` | n/a (off-chain) |
|
|
13
|
-
* | 2 |
|
|
14
|
-
* | 3 |
|
|
15
|
-
* | 4 |
|
|
16
|
-
* | 5 |
|
|
13
|
+
* | 2 | Sign BTC proof-of-possession | `PeginManager.signProofOfPossession()` | n/a (off-chain, once per session) |
|
|
14
|
+
* | 3 | Register on Ethereum | `PeginManager.registerPeginOnChain()` | `PENDING` |
|
|
15
|
+
* | 4 | Broadcast Pre-PegIn on Bitcoin | `PeginManager.signAndBroadcast()` | still `PENDING` until VP observes the tx |
|
|
16
|
+
* | 5 | Sign payout authorisations | `pollAndSignPayouts()` (services, delegates to `PayoutManager`) | `PENDING` → `VERIFIED` |
|
|
17
|
+
* | 6 | Activate by revealing HTLC secret | `activateVault()` (services) | `VERIFIED` → `ACTIVE` |
|
|
17
18
|
*
|
|
18
19
|
* Optional exit after the CSV timelock expires: `buildAndBroadcastRefund()` (services).
|
|
19
20
|
*
|
|
20
21
|
* @module managers
|
|
21
22
|
*/
|
|
22
23
|
export { PeginManager } from './PeginManager';
|
|
23
|
-
export type { PreparePeginResult, PreparePeginParams, PeginManagerConfig, RegisterPeginParams, RegisterPeginResult, SignAndBroadcastParams, BatchPeginRequestItem, RegisterPeginBatchParams, BatchPeginResultItem, RegisterPeginBatchResult, } from './PeginManager';
|
|
24
|
+
export type { PopSignature, PreparePeginResult, PreparePeginParams, PeginManagerConfig, RegisterPeginParams, RegisterPeginResult, SignAndBroadcastParams, BatchPeginRequestItem, RegisterPeginBatchParams, BatchPeginResultItem, RegisterPeginBatchResult, } from './PeginManager';
|
|
24
25
|
export { PayoutManager } from './PayoutManager';
|
|
25
26
|
export type { PayoutManagerConfig, PayoutSignatureResult, SignPayoutParams, } from './PayoutManager';
|
|
26
27
|
export type { UTXO } from '../utils/utxo/selectUtxos';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/tbv/core/managers/index.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/tbv/core/managers/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,YAAY,EACV,YAAY,EACZ,kBAAkB,EAClB,kBAAkB,EAClB,kBAAkB,EAClB,mBAAmB,EACnB,mBAAmB,EACnB,sBAAsB,EACtB,qBAAqB,EACrB,wBAAwB,EACxB,oBAAoB,EACpB,wBAAwB,GACzB,MAAM,gBAAgB,CAAC;AAExB,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,YAAY,EACV,mBAAmB,EACnB,qBAAqB,EACrB,gBAAgB,GACjB,MAAM,iBAAiB,CAAC;AAGzB,YAAY,EAAE,IAAI,EAAE,MAAM,2BAA2B,CAAC;AACtD,YAAY,EACV,cAAc,EACd,aAAa,EACb,gBAAgB,EAChB,eAAe,GAChB,MAAM,kDAAkD,CAAC"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("../../../buildAndBroadcastRefund-
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("../../../buildAndBroadcastRefund-BDGGbGeK.cjs"),a=require("../../../signing-cl-lowxV.cjs");exports.BIP68NotMatureError=t.BIP68NotMatureError;exports.ClaimerPegoutStatusValue=t.ClaimerPegoutStatusValue;exports.activateVault=t.activateVault;exports.buildAndBroadcastRefund=t.buildAndBroadcastRefund;exports.computeHashlock=t.computeHashlock;exports.isDepositAmountValid=t.isDepositAmountValid;exports.isPegoutTerminalStatus=t.isPegoutTerminalStatus;exports.isRecognizedPegoutStatus=t.isRecognizedPegoutStatus;exports.pollAndSignPayouts=t.pollAndSignPayouts;exports.signDepositorGraph=t.signDepositorGraph;exports.submitWotsPublicKey=t.submitWotsPublicKey;exports.validateDepositAmount=t.validateDepositAmount;exports.validateMultiVaultDepositInputs=t.validateMultiVaultDepositInputs;exports.validateProviderSelection=t.validateProviderSelection;exports.validateRemainingCapacity=t.validateRemainingCapacity;exports.validateSecretAgainstHashlock=t.validateSecretAgainstHashlock;exports.validateVaultAmounts=t.validateVaultAmounts;exports.validateVaultProviderPubkey=t.validateVaultProviderPubkey;exports.waitForPeginStatus=t.waitForPeginStatus;exports.ContractStatus=a.ContractStatus;exports.PeginAction=a.PeginAction;exports.canPerformAction=a.canPerformAction;exports.getPeginProtocolState=a.getPeginProtocolState;
|
|
2
2
|
//# sourceMappingURL=index.cjs.map
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { B as s, C as e, a as i, m as o, h as u, i as l, l as r, k as n, p as d, b as c, s as P, v as g, g as m, d as p, c as v, j as S, e as A, f as V, w as b } from "../../../buildAndBroadcastRefund-
|
|
1
|
+
import { B as s, C as e, a as i, m as o, h as u, i as l, l as r, k as n, p as d, b as c, s as P, v as g, g as m, d as p, c as v, j as S, e as A, f as V, w as b } from "../../../buildAndBroadcastRefund-D7NCbgtv.js";
|
|
2
2
|
import { C, P as h, a as k, g as y } from "../../../signing-DeWVBl7m.js";
|
|
3
3
|
export {
|
|
4
4
|
s as BIP68NotMatureError,
|
|
@@ -18,7 +18,11 @@ export interface VaultRefundData {
|
|
|
18
18
|
applicationEntryPoint: Address;
|
|
19
19
|
/** Pre-PegIn HTLC output value in satoshis. */
|
|
20
20
|
amount: bigint;
|
|
21
|
-
/**
|
|
21
|
+
/**
|
|
22
|
+
* Funded, pre-witness Pre-PegIn transaction hex. 0x prefix optional.
|
|
23
|
+
* The name mirrors the contract/indexer schema; the bytes are the
|
|
24
|
+
* funded form (refund construction needs real outpoints).
|
|
25
|
+
*/
|
|
22
26
|
unsignedPrePeginTxHex: string;
|
|
23
27
|
/** Depositor's BTC public key (x-only or compressed hex; 0x prefix optional). */
|
|
24
28
|
depositorBtcPubkey: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"buildAndBroadcastRefund.d.ts","sourceRoot":"","sources":["../../../../../src/tbv/core/services/refund/buildAndBroadcastRefund.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,uCAAuC,CAAC;AAErE,OAAO,KAAK,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,MAAM,CAAC;AAEzC,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,qDAAqD,CAAC;
|
|
1
|
+
{"version":3,"file":"buildAndBroadcastRefund.d.ts","sourceRoot":"","sources":["../../../../../src/tbv/core/services/refund/buildAndBroadcastRefund.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,uCAAuC,CAAC;AAErE,OAAO,KAAK,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,MAAM,CAAC;AAEzC,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,qDAAqD,CAAC;AA+C3F;;;;;;GAMG;AACH,MAAM,WAAW,eAAe;IAC9B,QAAQ,EAAE,GAAG,CAAC;IACd,QAAQ,EAAE,MAAM,CAAC;IACjB,qBAAqB,EAAE,MAAM,CAAC;IAC9B,sBAAsB,EAAE,MAAM,CAAC;IAC/B,2BAA2B,EAAE,MAAM,CAAC;IACpC,aAAa,EAAE,OAAO,CAAC;IACvB,qBAAqB,EAAE,OAAO,CAAC;IAC/B,+CAA+C;IAC/C,MAAM,EAAE,MAAM,CAAC;IACf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AAC,EAAE,WAAW,CAAC;CACtB;AAqGD;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAsB,uBAAuB,CAC3C,CAAC,SAAS,kBAAkB,GAAG,kBAAkB,EACjD,KAAK,EAAE,WAAW,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CA8EnC"}
|
package/dist/tbv/index.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=require("../challengeAssert-nYlgeAI8.cjs"),c=require("@babylonlabs-io/babylon-tbv-rust-wasm"),P=require("../payout-RFIh7GLN.cjs"),o=require("../bitcoin-CNnPFU6Y.cjs"),l=require("../signing-cl-lowxV.cjs"),u=require("../validation-u8W7Lp2x.cjs"),e=require("../buildAndBroadcastRefund-
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=require("../challengeAssert-nYlgeAI8.cjs"),c=require("@babylonlabs-io/babylon-tbv-rust-wasm"),P=require("../payout-RFIh7GLN.cjs"),o=require("../bitcoin-CNnPFU6Y.cjs"),l=require("../signing-cl-lowxV.cjs"),u=require("../validation-u8W7Lp2x.cjs"),e=require("../buildAndBroadcastRefund-BDGGbGeK.cjs"),r=require("../fundPeginTransaction-DxNOeyNI.cjs"),i=require("../psbtInputFields-05ZrwRzf.cjs"),a=require("../errors-BcpQEG62.cjs"),t=require("../index-BAECy2oz.cjs"),s=require("../types-B-p4dhEH.cjs");exports.buildChallengeAssertPsbt=n.buildChallengeAssertPsbt;exports.buildDepositorPayoutPsbt=n.buildDepositorPayoutPsbt;exports.buildNoPayoutPsbt=n.buildNoPayoutPsbt;exports.buildPeginInputPsbt=n.buildPeginInputPsbt;exports.buildPeginTxFromFundedPrePegin=n.buildPeginTxFromFundedPrePegin;exports.buildPrePeginPsbt=n.buildPrePeginPsbt;exports.computeNumLocalChallengers=n.computeNumLocalChallengers;exports.extractPeginInputSignature=n.extractPeginInputSignature;exports.finalizePeginInputPsbt=n.finalizePeginInputPsbt;Object.defineProperty(exports,"computeMinClaimValue",{enumerable:!0,get:()=>c.computeMinClaimValue});Object.defineProperty(exports,"deriveVaultId",{enumerable:!0,get:()=>c.deriveVaultId});exports.buildPayoutPsbt=P.buildPayoutPsbt;exports.buildRefundPsbt=P.buildRefundPsbt;exports.createPayoutScript=P.createPayoutScript;exports.extractPayoutSignature=P.extractPayoutSignature;exports.deriveNativeSegwitAddress=o.deriveNativeSegwitAddress;exports.deriveTaprootAddress=o.deriveTaprootAddress;exports.ensureHexPrefix=o.ensureHexPrefix;exports.formatSatoshisToBtc=o.formatSatoshisToBtc;exports.getNetwork=o.getNetwork;exports.hexToUint8Array=o.hexToUint8Array;exports.isAddressFromPublicKey=o.isAddressFromPublicKey;exports.isValidHex=o.isValidHex;exports.processPublicKeyToXOnly=o.processPublicKeyToXOnly;exports.stripHexPrefix=o.stripHexPrefix;exports.toXOnly=o.toXOnly;exports.uint8ArrayToHex=o.uint8ArrayToHex;exports.validateWalletPubkey=o.validateWalletPubkey;exports.ContractStatus=l.ContractStatus;exports.PeginAction=l.PeginAction;exports.canPerformAction=l.canPerformAction;exports.createTaprootScriptPathSignOptions=l.createTaprootScriptPathSignOptions;exports.getPeginProtocolState=l.getPeginProtocolState;exports.BITCOIN_ADDRESS_RE=u.BITCOIN_ADDRESS_RE;exports.HEX_RE=u.HEX_RE;exports.KNOWN_SCRIPT_PREFIXES=u.KNOWN_SCRIPT_PREFIXES;exports.MAX_REASONABLE_FEE_SATS=u.MAX_REASONABLE_FEE_SATS;exports.TXID_RE=u.TXID_RE;exports.BIP68NotMatureError=e.BIP68NotMatureError;exports.ClaimerPegoutStatusValue=e.ClaimerPegoutStatusValue;exports.PayoutManager=e.PayoutManager;exports.activateVault=e.activateVault;exports.buildAndBroadcastRefund=e.buildAndBroadcastRefund;exports.computeHashlock=e.computeHashlock;exports.isDepositAmountValid=e.isDepositAmountValid;exports.isPegoutTerminalStatus=e.isPegoutTerminalStatus;exports.isRecognizedPegoutStatus=e.isRecognizedPegoutStatus;exports.pollAndSignPayouts=e.pollAndSignPayouts;exports.signDepositorGraph=e.signDepositorGraph;exports.submitWotsPublicKey=e.submitWotsPublicKey;exports.validateDepositAmount=e.validateDepositAmount;exports.validateMultiVaultDepositInputs=e.validateMultiVaultDepositInputs;exports.validateProviderSelection=e.validateProviderSelection;exports.validateRemainingCapacity=e.validateRemainingCapacity;exports.validateSecretAgainstHashlock=e.validateSecretAgainstHashlock;exports.validateVaultAmounts=e.validateVaultAmounts;exports.validateVaultProviderPubkey=e.validateVaultProviderPubkey;exports.waitForPeginStatus=e.waitForPeginStatus;exports.BTC_DUST_SAT=r.BTC_DUST_SAT;exports.DUST_THRESHOLD=r.DUST_THRESHOLD;exports.FEE_SAFETY_MARGIN=r.FEE_SAFETY_MARGIN;exports.LOW_RATE_ESTIMATION_ACCURACY_BUFFER=r.LOW_RATE_ESTIMATION_ACCURACY_BUFFER;exports.MAX_NON_LEGACY_OUTPUT_SIZE=r.MAX_NON_LEGACY_OUTPUT_SIZE;exports.P2TR_INPUT_SIZE=r.P2TR_INPUT_SIZE;exports.PEGIN_FIXED_OUTPUTS=r.PEGIN_FIXED_OUTPUTS;exports.SPLIT_TX_FEE_SAFETY_MULTIPLIER=r.SPLIT_TX_FEE_SAFETY_MULTIPLIER;exports.TX_BUFFER_SIZE_OVERHEAD=r.TX_BUFFER_SIZE_OVERHEAD;exports.WALLET_RELAY_FEE_RATE_THRESHOLD=r.WALLET_RELAY_FEE_RATE_THRESHOLD;exports.fundPeginTransaction=r.fundPeginTransaction;exports.parseUnfundedWasmTransaction=r.parseUnfundedWasmTransaction;exports.peginOutputCount=r.peginOutputCount;exports.rateBasedTxBufferFee=r.rateBasedTxBufferFee;exports.BitcoinScriptType=i.BitcoinScriptType;exports.UtxoNotAvailableError=i.UtxoNotAvailableError;exports.assertUtxosAvailable=i.assertUtxosAvailable;exports.calculateBtcTxHash=i.calculateBtcTxHash;exports.collectReservedUtxoRefs=i.collectReservedUtxoRefs;exports.extractInputsFromTransaction=i.extractInputsFromTransaction;exports.getDustThreshold=i.getDustThreshold;exports.getPsbtInputFields=i.getPsbtInputFields;exports.getScriptType=i.getScriptType;exports.selectUtxosForDeposit=i.selectUtxosForDeposit;exports.selectUtxosForPegin=i.selectUtxosForPegin;exports.shouldAddChangeOutput=i.shouldAddChangeOutput;exports.validateUtxosAvailable=i.validateUtxosAvailable;exports.CONTRACT_ERRORS=a.CONTRACT_ERRORS;exports.PeginManager=a.PeginManager;exports.computeWotsBlockPublicKeysHash=a.computeWotsBlockPublicKeysHash;exports.computeWotsPkHash=a.computeWotsPkHash;exports.deriveWotsBlockPublicKeys=a.deriveWotsBlockPublicKeys;exports.deriveWotsKeypair=a.deriveWotsKeypair;exports.deriveWotsPkHash=a.deriveWotsPkHash;exports.extractErrorData=a.extractErrorData;exports.getContractErrorMessage=a.getContractErrorMessage;exports.handleContractError=a.handleContractError;exports.isKnownContractError=a.isKnownContractError;exports.isWotsMismatchError=a.isWotsMismatchError;exports.keypairToPublicKey=a.keypairToPublicKey;exports.mnemonicToWotsSeed=a.mnemonicToWotsSeed;exports.ApplicationRegistryABI=t.ApplicationRegistryABI;exports.MEMPOOL_API_URLS=t.MEMPOOL_API_URLS;exports.ProtocolParamsABI=t.ProtocolParamsABI;exports.VaultProviderRpcClient=t.VaultProviderRpcClient;exports.ViemProtocolParamsReader=t.ViemProtocolParamsReader;exports.ViemUniversalChallengerReader=t.ViemUniversalChallengerReader;exports.ViemVaultKeeperReader=t.ViemVaultKeeperReader;exports.ViemVaultRegistryReader=t.ViemVaultRegistryReader;exports.VpResponseValidationError=t.VpResponseValidationError;exports.getAddressTxs=t.getAddressTxs;exports.getAddressUtxos=t.getAddressUtxos;exports.getMempoolApiUrl=t.getMempoolApiUrl;exports.getNetworkFees=t.getNetworkFees;exports.getTxHex=t.getTxHex;exports.getTxInfo=t.getTxInfo;exports.getUtxoInfo=t.getUtxoInfo;exports.pushTx=t.pushTx;exports.resolveProtocolAddresses=t.resolveProtocolAddresses;exports.validateRequestDepositorClaimerArtifactsResponse=t.validateRequestDepositorClaimerArtifactsResponse;exports.BTCVaultRegistryABI=s.BTCVaultRegistryABI;exports.DaemonStatus=s.DaemonStatus;exports.JSON_RPC_ERROR_CODES=s.JSON_RPC_ERROR_CODES;exports.JsonRpcClient=s.JsonRpcClient;exports.JsonRpcError=s.JsonRpcError;exports.POST_WOTS_STATUSES=s.POST_WOTS_STATUSES;exports.PRE_DEPOSITOR_SIGNATURES_STATES=s.PRE_DEPOSITOR_SIGNATURES_STATES;exports.RpcErrorCode=s.RpcErrorCode;exports.VP_TERMINAL_STATUSES=s.VP_TERMINAL_STATUSES;exports.VP_TRANSIENT_STATUSES=s.VP_TRANSIENT_STATUSES;
|
|
2
2
|
//# sourceMappingURL=index.cjs.map
|
package/dist/tbv/index.js
CHANGED
|
@@ -4,10 +4,10 @@ import { a as S, b as E, c as A, e as g } from "../payout-DzGsAnhf.js";
|
|
|
4
4
|
import { d as _, a as m, e as b, f as x, g as I, h as f, i as v, b as C, p as U, s as y, t as O, u as h, v as V } from "../bitcoin-nOOgeRyl.js";
|
|
5
5
|
import { C as D, P as F, a as N, c as M, g as H } from "../signing-DeWVBl7m.js";
|
|
6
6
|
import { B as W, H as k, K, M as X, T as w } from "../validation-CxqROCno.js";
|
|
7
|
-
import { B as Y, C as J, P as j, a as Z, m as z, h as q, i as Q, l as $, k as aa, p as sa, b as ea, s as ta, v as oa, g as ra, d as ia, c as la, j as na, e as ua, f as Pa, w as da } from "../buildAndBroadcastRefund-
|
|
7
|
+
import { B as Y, C as J, P as j, a as Z, m as z, h as q, i as Q, l as $, k as aa, p as sa, b as ea, s as ta, v as oa, g as ra, d as ia, c as la, j as na, e as ua, f as Pa, w as da } from "../buildAndBroadcastRefund-D7NCbgtv.js";
|
|
8
8
|
import { B as Ta, D as pa, F as Sa, L as Ea, M as Aa, P as ga, a as Ra, S as _a, T as ma, W as ba, f as xa, b as Ia, p as fa, r as va } from "../fundPeginTransaction-BLYXxLBv.js";
|
|
9
9
|
import { B as Ua, U as ya, a as Oa, f as ha, c as Va, e as Ba, g as Da, i as Fa, h as Na, s as Ma, b as Ha, d as La, v as Wa } from "../psbtInputFields-r1ss6WLU.js";
|
|
10
|
-
import { C as Ka, P as Xa, b as wa, c as Ga, a as Ya, d as Ja, f as ja, e as Za, g as za, h as qa, i as Qa, j as $a, k as as, m as ss } from "../errors-
|
|
10
|
+
import { C as Ka, P as Xa, b as wa, c as Ga, a as Ya, d as Ja, f as ja, e as Za, g as za, h as qa, i as Qa, j as $a, k as as, m as ss } from "../errors-D3a9XcIX.js";
|
|
11
11
|
import { A as ts, M as os, P as rs, V as is, i as ls, j as ns, k as us, l as Ps, h as ds, g as cs, a as Ts, b as ps, c as Ss, d as Es, e as As, f as gs, p as Rs, r as _s, v as ms } from "../index-DLtpqdlu.js";
|
|
12
12
|
import { B as xs, D as Is, b as fs, J as vs, a as Cs, d as Us, P as ys, R as Os, c as hs, V as Vs } from "../types-DWjaqVfP.js";
|
|
13
13
|
export {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { BitcoinNetwork } from '../shared/wallets/interfaces';
|
|
2
|
-
import { BitcoinWallet } from '../shared/wallets/interfaces/BitcoinWallet';
|
|
2
|
+
import { BitcoinWallet, SignPsbtOptions } from '../shared/wallets/interfaces/BitcoinWallet';
|
|
3
3
|
/**
|
|
4
4
|
* Configuration for MockBitcoinWallet.
|
|
5
5
|
*/
|
|
@@ -18,7 +18,7 @@ export declare class MockBitcoinWallet implements BitcoinWallet {
|
|
|
18
18
|
getPublicKeyHex(): Promise<string>;
|
|
19
19
|
getAddress(): Promise<string>;
|
|
20
20
|
signPsbt(psbtHex: string): Promise<string>;
|
|
21
|
-
signPsbts(psbtsHexes: string[]): Promise<string[]>;
|
|
21
|
+
signPsbts(psbtsHexes: string[], _options?: SignPsbtOptions[]): Promise<string[]>;
|
|
22
22
|
signMessage(message: string, type: "bip322-simple" | "ecdsa"): Promise<string>;
|
|
23
23
|
getNetwork(): Promise<BitcoinNetwork>;
|
|
24
24
|
/** Updates configuration for testing different scenarios. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MockBitcoinWallet.d.ts","sourceRoot":"","sources":["../../src/testing/MockBitcoinWallet.ts"],"names":[],"mappings":"AAEA,OAAO,EAAmB,KAAK,cAAc,EAAE,MAAM,8BAA8B,CAAC;AACpF,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"MockBitcoinWallet.d.ts","sourceRoot":"","sources":["../../src/testing/MockBitcoinWallet.ts"],"names":[],"mappings":"AAEA,OAAO,EAAmB,KAAK,cAAc,EAAE,MAAM,8BAA8B,CAAC;AACpF,OAAO,KAAK,EACV,aAAa,EACb,eAAe,EAChB,MAAM,4CAA4C,CAAC;AAEpD;;GAEG;AACH,MAAM,WAAW,uBAAuB;IACtC,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,cAAc,CAAC;IACzB,iBAAiB,CAAC,EAAE,OAAO,CAAC;CAC7B;AAED;;GAEG;AACH,qBAAa,iBAAkB,YAAW,aAAa;IACrD,OAAO,CAAC,MAAM,CAAoC;gBAEtC,MAAM,GAAE,uBAA4B;IAa1C,eAAe,IAAI,OAAO,CAAC,MAAM,CAAC;IAIlC,UAAU,IAAI,OAAO,CAAC,MAAM,CAAC;IAI7B,QAAQ,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAc1C,SAAS,CACb,UAAU,EAAE,MAAM,EAAE,EACpB,QAAQ,CAAC,EAAE,eAAe,EAAE,GAC3B,OAAO,CAAC,MAAM,EAAE,CAAC;IASd,WAAW,CACf,OAAO,EAAE,MAAM,EACf,IAAI,EAAE,eAAe,GAAG,OAAO,GAC9B,OAAO,CAAC,MAAM,CAAC;IAiBZ,UAAU,IAAI,OAAO,CAAC,cAAc,CAAC;IAI3C,6DAA6D;IAC7D,YAAY,CAAC,OAAO,EAAE,OAAO,CAAC,uBAAuB,CAAC,GAAG,IAAI;IAO7D,uCAAuC;IACvC,KAAK,IAAI,IAAI;CASd"}
|
package/dist/testing/index.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var q=Object.defineProperty;var d=(n,i,s)=>i in n?q(n,i,{enumerable:!0,configurable:!0,writable:!0,value:s}):n[i]=s;var t=(n,i,s)=>d(n,typeof i!="symbol"?i+"":i,s);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
1
|
+
"use strict";var q=Object.defineProperty;var d=(n,i,s)=>i in n?q(n,i,{enumerable:!0,configurable:!0,writable:!0,value:s}):n[i]=s;var t=(n,i,s)=>d(n,typeof i!="symbol"?i+"":i,s);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=require("buffer"),c=require("../shared/index.cjs");class h{constructor(i={}){t(this,"config");this.config={publicKeyHex:i.publicKeyHex||"a1b2c3d4e5f6a7b8c9d0e1f2a3b4c5d6e7f8a9b0c1d2e3f4a5b6c7d8e9f0a1b2",address:i.address||"tb1pqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqkx6jks",network:i.network??c.BitcoinNetworks.SIGNET,shouldFailSigning:i.shouldFailSigning??!1}}async getPublicKeyHex(){return this.config.publicKeyHex}async getAddress(){return this.config.address}async signPsbt(i){if(this.config.shouldFailSigning)throw new Error("Mock signing failed");if(!i||i.length===0)throw new Error("Invalid PSBT: empty hex string");return i+"deadbeef"}async signPsbts(i,s){const e=[];for(const a of i){const o=await this.signPsbt(a);e.push(o)}return e}async signMessage(i,s){if(this.config.shouldFailSigning)throw new Error("Mock signing failed");if(!i||i.length===0)throw new Error("Invalid message: empty string");return r.Buffer.from(`mock-signature-${s}-${i}-${this.config.publicKeyHex}`).toString("base64")}async getNetwork(){return this.config.network}updateConfig(i){this.config={...this.config,...i}}reset(){this.config={publicKeyHex:"a1b2c3d4e5f6a7b8c9d0e1f2a3b4c5d6e7f8a9b0c1d2e3f4a5b6c7d8e9f0a1b2",address:"tb1pqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqkx6jks",network:c.BitcoinNetworks.SIGNET,shouldFailSigning:!1}}}class l{constructor(i={}){t(this,"account");t(this,"chain");t(this,"shouldFailOperations");t(this,"transactionDelay");t(this,"nonce",0);this.account={address:i.address||"0x742d35cc6634c0532925a3b844bc9e7595f0beb0"},this.chain={id:i.chainId??11155111},this.shouldFailOperations=i.shouldFailOperations??!1,this.transactionDelay=i.transactionDelay??0,this.signMessage=this.signMessage.bind(this),this.sendTransaction=this.sendTransaction.bind(this)}async signMessage(i){const s=i.message,e=i.account||this.account.address;if(this.shouldFailOperations)throw new Error("Mock signing failed");if(!s||s.length===0)throw new Error("Invalid message: empty string");const a=`personal_sign:${s}-${e}-${this.chain.id}`;return`0x${r.Buffer.from(a).toString("hex").slice(0,130).padEnd(130,"0")}`}async sendTransaction(i){var a;if(this.shouldFailOperations)throw new Error("Mock transaction failed");if(!i.to)throw new Error("Invalid transaction: missing 'to' address");this.transactionDelay>0&&await new Promise(o=>setTimeout(o,this.transactionDelay)),this.nonce++;const s=JSON.stringify({from:this.account.address,to:i.to,value:((a=i.value)==null?void 0:a.toString())||"0",nonce:this.nonce,chainId:this.chain.id});return`0x${r.Buffer.from(s).toString("hex").slice(0,64).padEnd(64,"0")}`}updateConfig(i){i.address!==void 0&&(this.account.address=i.address),i.chainId!==void 0&&(this.chain.id=i.chainId),i.shouldFailOperations!==void 0&&(this.shouldFailOperations=i.shouldFailOperations),i.transactionDelay!==void 0&&(this.transactionDelay=i.transactionDelay)}reset(){this.account.address="0x742d35cc6634c0532925a3b844bc9e7595f0beb0",this.chain.id=11155111,this.shouldFailOperations=!1,this.transactionDelay=0,this.nonce=0}getCurrentNonce(){return this.nonce}}exports.MockBitcoinWallet=h;exports.MockEthereumWallet=l;
|
|
2
2
|
//# sourceMappingURL=index.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","sources":["../../src/testing/MockBitcoinWallet.ts","../../src/testing/MockEthereumWallet.ts"],"sourcesContent":["import { Buffer } from \"buffer\";\n\nimport { BitcoinNetworks, type BitcoinNetwork } from \"../shared/wallets/interfaces\";\nimport type { BitcoinWallet } from \"../shared/wallets/interfaces/BitcoinWallet\";\n\n/**\n * Configuration for MockBitcoinWallet.\n */\nexport interface MockBitcoinWalletConfig {\n publicKeyHex?: string;\n address?: string;\n network?: BitcoinNetwork;\n shouldFailSigning?: boolean;\n}\n\n/**\n * Mock Bitcoin wallet for testing.\n */\nexport class MockBitcoinWallet implements BitcoinWallet {\n private config: Required<MockBitcoinWalletConfig>;\n\n constructor(config: MockBitcoinWalletConfig = {}) {\n this.config = {\n publicKeyHex:\n config.publicKeyHex ||\n \"a1b2c3d4e5f6a7b8c9d0e1f2a3b4c5d6e7f8a9b0c1d2e3f4a5b6c7d8e9f0a1b2\",\n address:\n config.address ||\n \"tb1pqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqkx6jks\",\n network: config.network ?? BitcoinNetworks.SIGNET,\n shouldFailSigning: config.shouldFailSigning ?? false,\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): 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(psbtsHexes: string[]): 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 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 // In a real implementation, this would create a proper signature\n // For the mock, we return a base64-like mock signature\n const mockSignature = Buffer.from(\n `mock-signature-${type}-${message}-${this.config.publicKeyHex}`,\n ).toString(\"base64\");\n return mockSignature;\n }\n\n async getNetwork(): Promise<BitcoinNetwork> {\n return this.config.network;\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 }\n\n /** Resets to default configuration. */\n reset(): void {\n this.config = {\n publicKeyHex:\n \"a1b2c3d4e5f6a7b8c9d0e1f2a3b4c5d6e7f8a9b0c1d2e3f4a5b6c7d8e9f0a1b2\",\n address: \"tb1pqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqkx6jks\",\n network: BitcoinNetworks.SIGNET,\n shouldFailSigning: false,\n };\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":["MockBitcoinWallet","config","__publicField","BitcoinNetworks","psbtHex","psbtsHexes","signedPsbts","signedPsbt","message","type","Buffer","updates","MockEthereumWallet","args","account","signatureData","tx","resolve","txData","_a"],"mappings":"+SAkBO,MAAMA,CAA2C,CAGtD,YAAYC,EAAkC,GAAI,CAF1CC,EAAA,eAGN,KAAK,OAAS,CACZ,aACED,EAAO,cACP,mEACF,QACEA,EAAO,SACP,iEACF,QAASA,EAAO,SAAWE,EAAAA,gBAAgB,OAC3C,kBAAmBF,EAAO,mBAAqB,EAAA,CAEnD,CAEA,MAAM,iBAAmC,CACvC,OAAO,KAAK,OAAO,YACrB,CAEA,MAAM,YAA8B,CAClC,OAAO,KAAK,OAAO,OACrB,CAEA,MAAM,SAASG,EAAkC,CAC/C,GAAI,KAAK,OAAO,kBACd,MAAM,IAAI,MAAM,qBAAqB,EAGvC,GAAI,CAACA,GAAWA,EAAQ,SAAW,EACjC,MAAM,IAAI,MAAM,gCAAgC,EAKlD,OAAOA,EAAU,UACnB,CAEA,MAAM,UAAUC,EAAyC,CACvD,MAAMC,EAAwB,CAAA,EAC9B,UAAWF,KAAWC,EAAY,CAChC,MAAME,EAAa,MAAM,KAAK,SAASH,CAAO,EAC9CE,EAAY,KAAKC,CAAU,CAC7B,CACA,OAAOD,CACT,CAEA,MAAM,YACJE,EACAC,EACiB,CACjB,GAAI,KAAK,OAAO,kBACd,MAAM,IAAI,MAAM,qBAAqB,EAGvC,GAAI,CAACD,GAAWA,EAAQ,S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,EAOL,OACf,GAAI,KAAK,qBACP,MAAM,IAAI,MAAM,yBAAyB,EAG3C,GAAI,CAACA,EAAG,GACN,MAAM,IAAI,MAAM,2CAA2C,EAIzD,KAAK,iBAAmB,GAC1B,MAAM,IAAI,QAASC,GACjB,WAAWA,EAAS,KAAK,gBAAgB,CAAA,EAK7C,KAAK,QACL,MAAMC,EAAS,KAAK,UAAU,CAC5B,KAAM,KAAK,QAAQ,QACnB,GAAIF,EAAG,GACP,QAAOG,EAAAH,EAAG,QAAH,YAAAG,EAAU,aAAc,IAC/B,MAAO,KAAK,MACZ,QAAS,KAAK,MAAM,EAAA,CACrB,EAMD,MAJa,KAAKT,EAAAA,OAAO,KAAKQ,CAAM,EACjC,SAAS,KAAK,EACd,MAAM,EAAG,EAAE,EACX,OAAO,GAAI,GAAG,CAAC,EAEpB,CAGA,aAAaP,EAAkD,CACzDA,EAAQ,UAAY,SACtB,KAAK,QAAQ,QAAUA,EAAQ,SAE7BA,EAAQ,UAAY,SACtB,KAAK,MAAM,GAAKA,EAAQ,SAEtBA,EAAQ,uBAAyB,SACnC,KAAK,qBAAuBA,EAAQ,sBAElCA,EAAQ,mBAAqB,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/MockBitcoinWallet.ts","../../src/testing/MockEthereumWallet.ts"],"sourcesContent":["import { Buffer } from \"buffer\";\n\nimport { BitcoinNetworks, type BitcoinNetwork } from \"../shared/wallets/interfaces\";\nimport type {\n BitcoinWallet,\n SignPsbtOptions,\n} from \"../shared/wallets/interfaces/BitcoinWallet\";\n\n/**\n * Configuration for MockBitcoinWallet.\n */\nexport interface MockBitcoinWalletConfig {\n publicKeyHex?: string;\n address?: string;\n network?: BitcoinNetwork;\n shouldFailSigning?: boolean;\n}\n\n/**\n * Mock Bitcoin wallet for testing.\n */\nexport class MockBitcoinWallet implements BitcoinWallet {\n private config: Required<MockBitcoinWalletConfig>;\n\n constructor(config: MockBitcoinWalletConfig = {}) {\n this.config = {\n publicKeyHex:\n config.publicKeyHex ||\n \"a1b2c3d4e5f6a7b8c9d0e1f2a3b4c5d6e7f8a9b0c1d2e3f4a5b6c7d8e9f0a1b2\",\n address:\n config.address ||\n \"tb1pqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqkx6jks\",\n network: config.network ?? BitcoinNetworks.SIGNET,\n shouldFailSigning: config.shouldFailSigning ?? false,\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): 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 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 // In a real implementation, this would create a proper signature\n // For the mock, we return a base64-like mock signature\n const mockSignature = Buffer.from(\n `mock-signature-${type}-${message}-${this.config.publicKeyHex}`,\n ).toString(\"base64\");\n return mockSignature;\n }\n\n async getNetwork(): Promise<BitcoinNetwork> {\n return this.config.network;\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 }\n\n /** Resets to default configuration. */\n reset(): void {\n this.config = {\n publicKeyHex:\n \"a1b2c3d4e5f6a7b8c9d0e1f2a3b4c5d6e7f8a9b0c1d2e3f4a5b6c7d8e9f0a1b2\",\n address: \"tb1pqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqkx6jks\",\n network: BitcoinNetworks.SIGNET,\n shouldFailSigning: false,\n };\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":["MockBitcoinWallet","config","__publicField","BitcoinNetworks","psbtHex","psbtsHexes","_options","signedPsbts","signedPsbt","message","type","Buffer","updates","MockEthereumWallet","args","account","signatureData","tx","resolve","txData","_a"],"mappings":"+SAqBO,MAAMA,CAA2C,CAGtD,YAAYC,EAAkC,GAAI,CAF1CC,EAAA,eAGN,KAAK,OAAS,CACZ,aACED,EAAO,cACP,mEACF,QACEA,EAAO,SACP,iEACF,QAASA,EAAO,SAAWE,EAAAA,gBAAgB,OAC3C,kBAAmBF,EAAO,mBAAqB,EAAA,CAEnD,CAEA,MAAM,iBAAmC,CACvC,OAAO,KAAK,OAAO,YACrB,CAEA,MAAM,YAA8B,CAClC,OAAO,KAAK,OAAO,OACrB,CAEA,MAAM,SAASG,EAAkC,CAC/C,GAAI,KAAK,OAAO,kBACd,MAAM,IAAI,MAAM,qBAAqB,EAGvC,GAAI,CAACA,GAAWA,EAAQ,SAAW,EACjC,MAAM,IAAI,MAAM,gCAAgC,EAKlD,OAAOA,EAAU,UACnB,CAEA,MAAM,UACJC,EACAC,EACmB,CACnB,MAAMC,EAAwB,CAAA,EAC9B,UAAWH,KAAWC,EAAY,CAChC,MAAMG,EAAa,MAAM,KAAK,SAASJ,CAAO,EAC9CG,EAAY,KAAKC,CAAU,CAC7B,CACA,OAAOD,CACT,CAEA,MAAM,YACJE,EACAC,EACiB,CACjB,GAAI,KAAK,OAAO,kBACd,MAAM,IAAI,MAAM,qBAAqB,EAGvC,GAAI,CAACD,GAAWA,EAAQ,SAAW,EACjC,MAAM,IAAI,MAAM,+BAA+B,EAQjD,OAHsBE,EAAAA,OAAO,KAC3B,kBAAkBD,CAAI,IAAID,CAAO,IAAI,KAAK,OAAO,YAAY,EAAA,EAC7D,SAAS,QAAQ,CAErB,CAEA,MAAM,YAAsC,CAC1C,OAAO,KAAK,OAAO,OACrB,CAGA,aAAaG,EAAiD,CAC5D,KAAK,OAAS,CACZ,GAAG,KAAK,OACR,GAAGA,CAAA,CAEP,CAGA,OAAc,CACZ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AH,EAAG,QAAH,YAAAG,EAAU,aAAc,IAC/B,MAAO,KAAK,MACZ,QAAS,KAAK,MAAM,EAAA,CACrB,EAMD,MAJa,KAAKT,EAAAA,OAAO,KAAKQ,CAAM,EACjC,SAAS,KAAK,EACd,MAAM,EAAG,EAAE,EACX,OAAO,GAAI,GAAG,CAAC,EAEpB,CAGA,aAAaP,EAAkD,CACzDA,EAAQ,UAAY,SACtB,KAAK,QAAQ,QAAUA,EAAQ,SAE7BA,EAAQ,UAAY,SACtB,KAAK,MAAM,GAAKA,EAAQ,SAEtBA,EAAQ,uBAAyB,SACnC,KAAK,qBAAuBA,EAAQ,sBAElCA,EAAQ,mBAAqB,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"}
|
package/dist/testing/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
var q = Object.defineProperty;
|
|
2
2
|
var h = (n, i, s) => i in n ? q(n, i, { enumerable: !0, configurable: !0, writable: !0, value: s }) : n[i] = s;
|
|
3
3
|
var t = (n, i, s) => h(n, typeof i != "symbol" ? i + "" : i, s);
|
|
4
|
-
import { Buffer as
|
|
4
|
+
import { Buffer as r } from "buffer";
|
|
5
5
|
import { BitcoinNetworks as c } from "../shared/index.js";
|
|
6
6
|
class f {
|
|
7
7
|
constructor(i = {}) {
|
|
@@ -26,20 +26,20 @@ class f {
|
|
|
26
26
|
throw new Error("Invalid PSBT: empty hex string");
|
|
27
27
|
return i + "deadbeef";
|
|
28
28
|
}
|
|
29
|
-
async signPsbts(i) {
|
|
30
|
-
const
|
|
29
|
+
async signPsbts(i, s) {
|
|
30
|
+
const a = [];
|
|
31
31
|
for (const e of i) {
|
|
32
|
-
const
|
|
33
|
-
|
|
32
|
+
const o = await this.signPsbt(e);
|
|
33
|
+
a.push(o);
|
|
34
34
|
}
|
|
35
|
-
return
|
|
35
|
+
return a;
|
|
36
36
|
}
|
|
37
37
|
async signMessage(i, s) {
|
|
38
38
|
if (this.config.shouldFailSigning)
|
|
39
39
|
throw new Error("Mock signing failed");
|
|
40
40
|
if (!i || i.length === 0)
|
|
41
41
|
throw new Error("Invalid message: empty string");
|
|
42
|
-
return
|
|
42
|
+
return r.from(
|
|
43
43
|
`mock-signature-${s}-${i}-${this.config.publicKeyHex}`
|
|
44
44
|
).toString("base64");
|
|
45
45
|
}
|
|
@@ -79,31 +79,31 @@ class u {
|
|
|
79
79
|
}, this.shouldFailOperations = i.shouldFailOperations ?? !1, this.transactionDelay = i.transactionDelay ?? 0, this.signMessage = this.signMessage.bind(this), this.sendTransaction = this.sendTransaction.bind(this);
|
|
80
80
|
}
|
|
81
81
|
async signMessage(i) {
|
|
82
|
-
const s = i.message,
|
|
82
|
+
const s = i.message, a = i.account || this.account.address;
|
|
83
83
|
if (this.shouldFailOperations)
|
|
84
84
|
throw new Error("Mock signing failed");
|
|
85
85
|
if (!s || s.length === 0)
|
|
86
86
|
throw new Error("Invalid message: empty string");
|
|
87
|
-
const
|
|
88
|
-
return `0x${
|
|
87
|
+
const e = `personal_sign:${s}-${a}-${this.chain.id}`;
|
|
88
|
+
return `0x${r.from(e).toString("hex").slice(0, 130).padEnd(130, "0")}`;
|
|
89
89
|
}
|
|
90
90
|
async sendTransaction(i) {
|
|
91
|
-
var
|
|
91
|
+
var e;
|
|
92
92
|
if (this.shouldFailOperations)
|
|
93
93
|
throw new Error("Mock transaction failed");
|
|
94
94
|
if (!i.to)
|
|
95
95
|
throw new Error("Invalid transaction: missing 'to' address");
|
|
96
96
|
this.transactionDelay > 0 && await new Promise(
|
|
97
|
-
(
|
|
97
|
+
(o) => setTimeout(o, this.transactionDelay)
|
|
98
98
|
), this.nonce++;
|
|
99
99
|
const s = JSON.stringify({
|
|
100
100
|
from: this.account.address,
|
|
101
101
|
to: i.to,
|
|
102
|
-
value: ((
|
|
102
|
+
value: ((e = i.value) == null ? void 0 : e.toString()) || "0",
|
|
103
103
|
nonce: this.nonce,
|
|
104
104
|
chainId: this.chain.id
|
|
105
105
|
});
|
|
106
|
-
return `0x${
|
|
106
|
+
return `0x${r.from(s).toString("hex").slice(0, 64).padEnd(64, "0")}`;
|
|
107
107
|
}
|
|
108
108
|
/** Updates configuration for testing different scenarios. */
|
|
109
109
|
updateConfig(i) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../src/testing/MockBitcoinWallet.ts","../../src/testing/MockEthereumWallet.ts"],"sourcesContent":["import { Buffer } from \"buffer\";\n\nimport { BitcoinNetworks, type BitcoinNetwork } from \"../shared/wallets/interfaces\";\nimport type { BitcoinWallet } from \"../shared/wallets/interfaces/BitcoinWallet\";\n\n/**\n * Configuration for MockBitcoinWallet.\n */\nexport interface MockBitcoinWalletConfig {\n publicKeyHex?: string;\n address?: string;\n network?: BitcoinNetwork;\n shouldFailSigning?: boolean;\n}\n\n/**\n * Mock Bitcoin wallet for testing.\n */\nexport class MockBitcoinWallet implements BitcoinWallet {\n private config: Required<MockBitcoinWalletConfig>;\n\n constructor(config: MockBitcoinWalletConfig = {}) {\n this.config = {\n publicKeyHex:\n config.publicKeyHex ||\n \"a1b2c3d4e5f6a7b8c9d0e1f2a3b4c5d6e7f8a9b0c1d2e3f4a5b6c7d8e9f0a1b2\",\n address:\n config.address ||\n \"tb1pqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqkx6jks\",\n network: config.network ?? BitcoinNetworks.SIGNET,\n shouldFailSigning: config.shouldFailSigning ?? false,\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): 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(psbtsHexes: string[]): 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 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 // In a real implementation, this would create a proper signature\n // For the mock, we return a base64-like mock signature\n const mockSignature = Buffer.from(\n `mock-signature-${type}-${message}-${this.config.publicKeyHex}`,\n ).toString(\"base64\");\n return mockSignature;\n }\n\n async getNetwork(): Promise<BitcoinNetwork> {\n return this.config.network;\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 }\n\n /** Resets to default configuration. */\n reset(): void {\n this.config = {\n publicKeyHex:\n \"a1b2c3d4e5f6a7b8c9d0e1f2a3b4c5d6e7f8a9b0c1d2e3f4a5b6c7d8e9f0a1b2\",\n address: \"tb1pqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqkx6jks\",\n network: BitcoinNetworks.SIGNET,\n shouldFailSigning: false,\n };\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":["MockBitcoinWallet","config","__publicField","BitcoinNetworks","psbtHex","psbtsHexes","signedPsbts","signedPsbt","message","type","Buffer","updates","MockEthereumWallet","args","account","signatureData","tx","resolve","txData","_a"],"mappings":";;;;;AAkBO,MAAMA,EAA2C;AAAA,EAGtD,YAAYC,IAAkC,IAAI;AAF1C,IAAAC,EAAA;AAGN,SAAK,SAAS;AAAA,MACZ,cACED,EAAO,gBACP;AAAA,MACF,SACEA,EAAO,WACP;AAAA,MACF,SAASA,EAAO,WAAWE,EAAgB;AAAA,MAC3C,mBAAmBF,EAAO,qBAAqB;AAAA,IAAA;AAAA,EAEnD;AAAA,EAEA,MAAM,kBAAmC;AACvC,WAAO,KAAK,OAAO;AAAA,EACrB;AAAA,EAEA,MAAM,aAA8B;AAClC,WAAO,KAAK,OAAO;AAAA,EACrB;AAAA,EAEA,MAAM,SAASG,GAAkC;AAC/C,QAAI,KAAK,OAAO;AACd,YAAM,IAAI,MAAM,qBAAqB;AAGvC,QAAI,CAACA,KAAWA,EAAQ,WAAW;AACjC,YAAM,IAAI,M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,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/MockBitcoinWallet.ts","../../src/testing/MockEthereumWallet.ts"],"sourcesContent":["import { Buffer } from \"buffer\";\n\nimport { BitcoinNetworks, type BitcoinNetwork } from \"../shared/wallets/interfaces\";\nimport type {\n BitcoinWallet,\n SignPsbtOptions,\n} from \"../shared/wallets/interfaces/BitcoinWallet\";\n\n/**\n * Configuration for MockBitcoinWallet.\n */\nexport interface MockBitcoinWalletConfig {\n publicKeyHex?: string;\n address?: string;\n network?: BitcoinNetwork;\n shouldFailSigning?: boolean;\n}\n\n/**\n * Mock Bitcoin wallet for testing.\n */\nexport class MockBitcoinWallet implements BitcoinWallet {\n private config: Required<MockBitcoinWalletConfig>;\n\n constructor(config: MockBitcoinWalletConfig = {}) {\n this.config = {\n publicKeyHex:\n config.publicKeyHex ||\n \"a1b2c3d4e5f6a7b8c9d0e1f2a3b4c5d6e7f8a9b0c1d2e3f4a5b6c7d8e9f0a1b2\",\n address:\n config.address ||\n \"tb1pqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqkx6jks\",\n network: config.network ?? BitcoinNetworks.SIGNET,\n shouldFailSigning: config.shouldFailSigning ?? false,\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): 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 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 // In a real implementation, this would create a proper signature\n // For the mock, we return a base64-like mock signature\n const mockSignature = Buffer.from(\n `mock-signature-${type}-${message}-${this.config.publicKeyHex}`,\n ).toString(\"base64\");\n return mockSignature;\n }\n\n async getNetwork(): Promise<BitcoinNetwork> {\n return this.config.network;\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 }\n\n /** Resets to default configuration. */\n reset(): void {\n this.config = {\n publicKeyHex:\n \"a1b2c3d4e5f6a7b8c9d0e1f2a3b4c5d6e7f8a9b0c1d2e3f4a5b6c7d8e9f0a1b2\",\n address: \"tb1pqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqkx6jks\",\n network: BitcoinNetworks.SIGNET,\n shouldFailSigning: false,\n };\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":["MockBitcoinWallet","config","__publicField","BitcoinNetworks","psbtHex","psbtsHexes","_options","signedPsbts","signedPsbt","message","type","Buffer","updates","MockEthereumWallet","args","account","signatureData","tx","resolve","txData","_a"],"mappings":";;;;;AAqBO,MAAMA,EAA2C;AAAA,EAGtD,YAAYC,IAAkC,IAAI;AAF1C,IAAAC,EAAA;AAGN,SAAK,SAAS;AAAA,MACZ,cACED,EAAO,gBACP;AAAA,MACF,SACEA,EAAO,WACP;AAAA,MACF,SAASA,EAAO,WAAWE,EAAgB;AAAA,MAC3C,mBAAmBF,EAAO,qBAAqB;AAAA,IAAA;AAAA,EAEnD;AAAA,EAEA,MAAM,kBAAmC;AACvC,WAAO,KAAK,OAAO;AAAA,EACrB;AAAA,EAEA,MAAM,aAA8B;AAClC,WAAO,KAAK,OAAO;AAAA,EACrB;AAAA,EAEA,MAAM,SAASG,GAAkC;AAC/C,QAAI,KAAK,O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