@dynamic-labs/bitcoin 4.52.5 → 4.53.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/CHANGELOG.md +16 -0
- package/package.cjs +1 -1
- package/package.js +1 -1
- package/package.json +11 -6
- package/src/connectors/BitcoinSatsConnectConnector/BitcoinSatsConnectConnector.js +1 -1
- package/src/connectors/BitcoinWalletConnector.cjs +8 -0
- package/src/connectors/BitcoinWalletConnector.d.ts +1 -0
- package/src/connectors/BitcoinWalletConnector.js +10 -2
- package/src/connectors/DynamicWaasBitcoinConnector/DynamicWaasBitcoinConnector.cjs +464 -0
- package/src/connectors/DynamicWaasBitcoinConnector/DynamicWaasBitcoinConnector.d.ts +314 -0
- package/src/connectors/DynamicWaasBitcoinConnector/DynamicWaasBitcoinConnector.js +460 -0
- package/src/connectors/DynamicWaasBitcoinConnector/index.d.ts +1 -0
- package/src/connectors/index.d.ts +1 -0
- package/src/const.cjs +13 -0
- package/src/const.d.ts +6 -0
- package/src/const.js +8 -1
- package/src/index.cjs +9 -0
- package/src/index.d.ts +2 -2
- package/src/index.js +6 -0
- package/src/services/MempoolApiService.cjs +127 -0
- package/src/services/MempoolApiService.d.ts +42 -0
- package/src/services/MempoolApiService.js +123 -0
- package/src/services/PsbtBuilderService.cjs +132 -0
- package/src/services/PsbtBuilderService.d.ts +27 -0
- package/src/services/PsbtBuilderService.js +124 -0
- package/src/types.d.ts +43 -0
- package/src/utils/btcToSatoshis/btcToSatoshis.cjs +24 -0
- package/src/utils/btcToSatoshis/btcToSatoshis.d.ts +7 -0
- package/src/utils/btcToSatoshis/btcToSatoshis.js +20 -0
- package/src/utils/btcToSatoshis/index.d.ts +1 -0
- package/src/utils/fetchSatsConnectConnectors/fetchSatsConnectConnectors.cjs +1 -0
- package/src/utils/fetchSatsConnectConnectors/fetchSatsConnectConnectors.js +1 -0
- package/src/utils/getBitcoinNetwork/getBitcoinNetwork.cjs +15 -0
- package/src/utils/getBitcoinNetwork/getBitcoinNetwork.d.ts +7 -0
- package/src/utils/getBitcoinNetwork/getBitcoinNetwork.js +11 -0
- package/src/utils/getBitcoinNetwork/index.d.ts +1 -0
- package/src/utils/index.d.ts +3 -0
- package/src/utils/psbtParser/PsbtParser.cjs +185 -0
- package/src/utils/psbtParser/PsbtParser.d.ts +63 -0
- package/src/utils/psbtParser/PsbtParser.js +181 -0
- package/src/utils/psbtParser/index.d.ts +1 -0
- package/src/wallet/BitcoinWallet.cjs +11 -0
- package/src/wallet/BitcoinWallet.d.ts +6 -0
- package/src/wallet/BitcoinWallet.js +11 -0
|
@@ -0,0 +1,314 @@
|
|
|
1
|
+
import { BitcoinConfig, BitcoinNetwork } from '@dynamic-labs-wallet/browser-wallet-client';
|
|
2
|
+
import { JwtVerifiedCredential, MFAAction, SignMessageContext } from '@dynamic-labs/sdk-api-core';
|
|
3
|
+
import { Logger } from '@dynamic-labs/logger';
|
|
4
|
+
import { WalletUiUtils } from '@dynamic-labs/types';
|
|
5
|
+
import { IDynamicWaasConnector, InternalWalletConnector, Chain, BitcoinSignPsbtRequest, BitcoinSignPsbtResponse } from '@dynamic-labs/wallet-connector-core';
|
|
6
|
+
import { BitcoinTransaction } from '../../types';
|
|
7
|
+
import { BitcoinWalletConnector } from '../BitcoinWalletConnector';
|
|
8
|
+
import type { ParsedTransaction, DynamicWaasBitcoinConnectorProps } from '../../types';
|
|
9
|
+
declare const DynamicWaasBitcoinConnector_base: (abstract new (...args: any[]) => {
|
|
10
|
+
[x: string]: any;
|
|
11
|
+
name: string;
|
|
12
|
+
overrideKey: string;
|
|
13
|
+
isEmbeddedWallet: boolean;
|
|
14
|
+
getSignedSessionId?: (() => Promise<string>) | undefined;
|
|
15
|
+
getMfaToken?: ((props?: {
|
|
16
|
+
mfaAction?: MFAAction | undefined;
|
|
17
|
+
} | undefined) => Promise<string | undefined>) | undefined;
|
|
18
|
+
getAuthToken?: (() => string) | undefined;
|
|
19
|
+
environmentId?: string | undefined;
|
|
20
|
+
baseApiUrl?: string | undefined;
|
|
21
|
+
relayUrl?: string | undefined;
|
|
22
|
+
baseClientKeysharesRelayApiUrl?: string | undefined;
|
|
23
|
+
dynamicWaasClient: import("@dynamic-labs-wallet/browser-wallet-client").DynamicWalletClient | undefined;
|
|
24
|
+
chainName: string;
|
|
25
|
+
authMode: "cookie" | "header";
|
|
26
|
+
logger: Logger;
|
|
27
|
+
__exportHandler: import("@dynamic-labs/waas").WaasExportHandler;
|
|
28
|
+
validateActiveWallet(expectedAddress: string): Promise<void>;
|
|
29
|
+
setGetAuthTokenFunction(getAuthToken: () => string): void;
|
|
30
|
+
setWaasAuthMode(authMode: "cookie" | "header"): void;
|
|
31
|
+
setGetMfaTokenFunction(getMfaToken: (props?: {
|
|
32
|
+
mfaAction?: MFAAction | undefined;
|
|
33
|
+
} | undefined) => Promise<string | undefined>): void;
|
|
34
|
+
setEnvironmentId(environmentId: string): void;
|
|
35
|
+
setBaseApiUrl(baseApiUrl: string): void;
|
|
36
|
+
setBaseClientKeysharesRelayApiUrl(baseClientKeysharesRelayApiUrl?: string | undefined): void;
|
|
37
|
+
setRelayUrl(relayUrl: string): void;
|
|
38
|
+
setGetSignedSessionIdFunction(getSignedSessionId: () => Promise<string>): void;
|
|
39
|
+
delegateKeyShares({ accountAddress, password, }: {
|
|
40
|
+
accountAddress: string;
|
|
41
|
+
password?: string | undefined;
|
|
42
|
+
}): Promise<void>;
|
|
43
|
+
createDynamicWaasClient(traceContext?: import("dist/packages/waas/utils/instrumentation").TraceContext | undefined): Promise<import("@dynamic-labs-wallet/browser-wallet-client").DynamicWalletClient>;
|
|
44
|
+
getWaasWalletClient(traceContext?: import("dist/packages/waas/utils/instrumentation").TraceContext | undefined): Promise<import("@dynamic-labs-wallet/browser-wallet-client").DynamicWalletClient>;
|
|
45
|
+
createWalletAccount({ thresholdSignatureScheme, password, bitcoinConfig, }?: {
|
|
46
|
+
thresholdSignatureScheme?: string | undefined;
|
|
47
|
+
password?: string | undefined;
|
|
48
|
+
bitcoinConfig?: BitcoinConfig | undefined;
|
|
49
|
+
} | undefined): Promise<{
|
|
50
|
+
chainName: string;
|
|
51
|
+
accountAddress: string;
|
|
52
|
+
publicKeyHex: string;
|
|
53
|
+
rawPublicKey: string | Uint8Array | undefined;
|
|
54
|
+
}>;
|
|
55
|
+
importPrivateKey({ privateKey, thresholdSignatureScheme, publicAddressCheck, addressType, }: {
|
|
56
|
+
privateKey: string;
|
|
57
|
+
thresholdSignatureScheme?: string | undefined;
|
|
58
|
+
publicAddressCheck?: string | undefined;
|
|
59
|
+
addressType?: string | undefined;
|
|
60
|
+
}): Promise<void>;
|
|
61
|
+
exportPrivateKey({ accountAddress, displayContainer, password, }?: {
|
|
62
|
+
accountAddress?: string | undefined;
|
|
63
|
+
displayContainer?: HTMLIFrameElement | undefined;
|
|
64
|
+
password?: string | undefined;
|
|
65
|
+
} | undefined): Promise<void>;
|
|
66
|
+
getExportHandler(): {
|
|
67
|
+
clear: () => void;
|
|
68
|
+
};
|
|
69
|
+
exportClientKeyshares({ accountAddress, password, }: {
|
|
70
|
+
accountAddress: string;
|
|
71
|
+
password?: string | undefined;
|
|
72
|
+
}): Promise<void>;
|
|
73
|
+
backupKeySharesToGoogleDrive({ accountAddress, password, }: {
|
|
74
|
+
accountAddress: string;
|
|
75
|
+
password?: string | undefined;
|
|
76
|
+
}): Promise<void>;
|
|
77
|
+
exportClientKeysharesFromGoogleDrive({ accountAddress, password, }: {
|
|
78
|
+
accountAddress: string;
|
|
79
|
+
password?: string | undefined;
|
|
80
|
+
}): Promise<void>;
|
|
81
|
+
refreshWalletAccountShares({ accountAddress, password, }: {
|
|
82
|
+
accountAddress: string;
|
|
83
|
+
password?: string | undefined;
|
|
84
|
+
}): Promise<void>;
|
|
85
|
+
reshareWalletAccountShares({ accountAddress, thresholdSignatureScheme, password, }: {
|
|
86
|
+
accountAddress: string;
|
|
87
|
+
thresholdSignatureScheme: string;
|
|
88
|
+
password?: string | undefined;
|
|
89
|
+
}): Promise<void>;
|
|
90
|
+
revokeDelegation({ accountAddress, password, }: {
|
|
91
|
+
accountAddress: string;
|
|
92
|
+
password?: string | undefined;
|
|
93
|
+
}): Promise<void>;
|
|
94
|
+
updatePassword({ accountAddress, existingPassword, newPassword, }: {
|
|
95
|
+
accountAddress: string;
|
|
96
|
+
existingPassword: string;
|
|
97
|
+
newPassword: string;
|
|
98
|
+
}): Promise<void>;
|
|
99
|
+
signRawMessage({ accountAddress, message, password, }: {
|
|
100
|
+
accountAddress: string;
|
|
101
|
+
message: string;
|
|
102
|
+
password?: string | undefined;
|
|
103
|
+
}): Promise<string>;
|
|
104
|
+
endSession(): Promise<void>;
|
|
105
|
+
getActiveAccountAddress(): Promise<string | undefined>;
|
|
106
|
+
getConnectedAccounts(): Promise<string[]>;
|
|
107
|
+
generateTraceId(): string;
|
|
108
|
+
instrument(message: string, context: import("@dynamic-labs/logger").InstrumentOptions & import("dist/packages/waas/utils/instrumentation").InstrumentContext & Record<string, any>): void;
|
|
109
|
+
instrumentAsync<T_1>({ operation, resource, fn, context, }: {
|
|
110
|
+
operation: string;
|
|
111
|
+
resource: string;
|
|
112
|
+
fn: (timing: import("dist/packages/waas/utils/instrumentation").InstrumentationTimer) => Promise<T_1>;
|
|
113
|
+
context?: Record<string, any> | undefined;
|
|
114
|
+
}): Promise<T_1>;
|
|
115
|
+
}) & typeof BitcoinWalletConnector;
|
|
116
|
+
/**
|
|
117
|
+
* Bitcoin connector for Dynamic WaaS (Wallet as a Service)
|
|
118
|
+
* Extends BitcoinWalletConnector with WaaS functionality for Bitcoin transactions
|
|
119
|
+
*/
|
|
120
|
+
export declare class DynamicWaasBitcoinConnector extends DynamicWaasBitcoinConnector_base implements IDynamicWaasConnector {
|
|
121
|
+
name: string;
|
|
122
|
+
logger: Logger;
|
|
123
|
+
overrideKey: string;
|
|
124
|
+
isEmbeddedWallet: boolean;
|
|
125
|
+
connectedChain: Chain;
|
|
126
|
+
get key(): string;
|
|
127
|
+
activeAccountAddress: string | undefined;
|
|
128
|
+
protected walletUiUtils: WalletUiUtils<InternalWalletConnector>;
|
|
129
|
+
/**
|
|
130
|
+
* The primary/active verified credential (first from the filtered array)
|
|
131
|
+
* This is used for the active account address
|
|
132
|
+
*/
|
|
133
|
+
private _verifiedCredential;
|
|
134
|
+
private mempoolApiService;
|
|
135
|
+
private psbtBuilderService;
|
|
136
|
+
/**
|
|
137
|
+
* @param props - Constructor properties including walletUiUtils
|
|
138
|
+
*/
|
|
139
|
+
constructor(props: DynamicWaasBitcoinConnectorProps);
|
|
140
|
+
set verifiedCredential(verifiedCredential: JwtVerifiedCredential | undefined);
|
|
141
|
+
get verifiedCredential(): JwtVerifiedCredential | undefined;
|
|
142
|
+
/**
|
|
143
|
+
* Override setVerifiedCredentials to filter and set Bitcoin WaaS credentials
|
|
144
|
+
* Filters for credentials with walletName === 'dynamicwaas' and chain === 'bip122'
|
|
145
|
+
* The base class already has verifiedCredentials property, so we just filter and set it
|
|
146
|
+
*/
|
|
147
|
+
setVerifiedCredentials(verifiedCredentials: JwtVerifiedCredential[]): void;
|
|
148
|
+
/**
|
|
149
|
+
* Gets the active wallet address
|
|
150
|
+
* Falls back to verified credential address if no active account is set
|
|
151
|
+
* @returns The wallet address or undefined
|
|
152
|
+
* @throws {DynamicError} If no active wallet address is found
|
|
153
|
+
*/
|
|
154
|
+
getAddress(): Promise<string | undefined>;
|
|
155
|
+
/**
|
|
156
|
+
* Gets all connected account addresses
|
|
157
|
+
* @returns Array of connected account addresses (currently returns single active address)
|
|
158
|
+
*/
|
|
159
|
+
getConnectedAccounts(): Promise<string[]>;
|
|
160
|
+
/**
|
|
161
|
+
* Gets the current Bitcoin network
|
|
162
|
+
* @returns The network name ('mainnet' for Bitcoin)
|
|
163
|
+
*/
|
|
164
|
+
getNetwork(): Promise<BitcoinNetwork>;
|
|
165
|
+
/**
|
|
166
|
+
* Signs a message using the wallet UI utils for user interaction
|
|
167
|
+
* @param message - The message to sign
|
|
168
|
+
* @returns The signed message as a string
|
|
169
|
+
*/
|
|
170
|
+
signMessage(message: string): Promise<string>;
|
|
171
|
+
/**
|
|
172
|
+
* Signs a Partially Signed Bitcoin Transaction (PSBT)
|
|
173
|
+
* @param request - The PSBT signing request containing the unsigned PSBT
|
|
174
|
+
* @returns The signed PSBT response
|
|
175
|
+
* @throws {DynamicError} If active account address is not set
|
|
176
|
+
* @throws {DynamicError} If signed session ID is not available or signature is provided
|
|
177
|
+
*/
|
|
178
|
+
signPsbt(request: BitcoinSignPsbtRequest): Promise<BitcoinSignPsbtResponse>;
|
|
179
|
+
/**
|
|
180
|
+
* Sends a raw Bitcoin transaction to the mempool
|
|
181
|
+
* @param rawTransaction - The raw transaction in hex format
|
|
182
|
+
* @returns The transaction ID
|
|
183
|
+
* @throws {DynamicError} If no transaction is specified or sending fails
|
|
184
|
+
*/
|
|
185
|
+
sendRawTransaction(rawTransaction: string): Promise<string>;
|
|
186
|
+
/**
|
|
187
|
+
* Sends Bitcoin to a recipient address
|
|
188
|
+
* This method combines buildPsbt, signPsbt, and sendRawTransaction into a single flow
|
|
189
|
+
* @param transaction - The Bitcoin transaction containing recipient address and amount
|
|
190
|
+
* @returns The transaction ID
|
|
191
|
+
* @throws {DynamicError} If any step in the process fails
|
|
192
|
+
*/
|
|
193
|
+
sendBitcoin(transaction: BitcoinTransaction): Promise<string | undefined>;
|
|
194
|
+
/**
|
|
195
|
+
* Creates a new Bitcoin wallet account with Bitcoin-specific defaults
|
|
196
|
+
* @param thresholdSignatureScheme - The threshold signature scheme (default: 'TWO_OF_TWO')
|
|
197
|
+
* @param password - Optional password for the wallet
|
|
198
|
+
* @param bitcoinConfig - Bitcoin configuration (required for Bitcoin)
|
|
199
|
+
* @returns The created wallet account information
|
|
200
|
+
*/
|
|
201
|
+
createWalletAccount({ thresholdSignatureScheme, password, bitcoinConfig, }?: {
|
|
202
|
+
thresholdSignatureScheme?: string;
|
|
203
|
+
password?: string;
|
|
204
|
+
bitcoinConfig?: BitcoinConfig;
|
|
205
|
+
}): Promise<{
|
|
206
|
+
chainName: string;
|
|
207
|
+
accountAddress: string;
|
|
208
|
+
publicKeyHex: string;
|
|
209
|
+
rawPublicKey: string | Uint8Array | undefined;
|
|
210
|
+
}>;
|
|
211
|
+
/**
|
|
212
|
+
* Override importPrivateKey to require and validate addressType for Bitcoin
|
|
213
|
+
* @param privateKey - The private key to import (WIF format for Bitcoin)
|
|
214
|
+
* @param thresholdSignatureScheme - The threshold signature scheme (default: 'TWO_OF_TWO')
|
|
215
|
+
* @param publicAddressCheck - Optional public address to verify against
|
|
216
|
+
* @param addressType - Required address type for Bitcoin ('native_segwit' or 'taproot')
|
|
217
|
+
* @throws {DynamicError} If addressType is missing or invalid for BTC
|
|
218
|
+
*/
|
|
219
|
+
importPrivateKey({ privateKey, thresholdSignatureScheme, publicAddressCheck, addressType, }: {
|
|
220
|
+
privateKey: string;
|
|
221
|
+
thresholdSignatureScheme?: string;
|
|
222
|
+
publicAddressCheck?: string;
|
|
223
|
+
addressType?: string;
|
|
224
|
+
}): Promise<void>;
|
|
225
|
+
/**
|
|
226
|
+
* Gets the wallet client for a specific account address and sets it as active
|
|
227
|
+
* @param accountAddress - The Bitcoin account address
|
|
228
|
+
* @returns The WaaS wallet client instance
|
|
229
|
+
*/
|
|
230
|
+
getWalletClientByAddress({ accountAddress }: {
|
|
231
|
+
accountAddress: string;
|
|
232
|
+
}): Promise<import("@dynamic-labs-wallet/browser-wallet-client").DynamicWalletClient>;
|
|
233
|
+
/**
|
|
234
|
+
* Gets the currently active account address
|
|
235
|
+
* @returns The active account address or undefined if not set
|
|
236
|
+
*/
|
|
237
|
+
getActiveAccountAddress(): Promise<string | undefined>;
|
|
238
|
+
/**
|
|
239
|
+
* Validates that the expected wallet address matches the active wallet
|
|
240
|
+
* Updates the active account address if it doesn't match
|
|
241
|
+
* @param expectedAddress - The expected wallet address to validate
|
|
242
|
+
* @throws {DynamicError} If signed session ID is not available or account is not found
|
|
243
|
+
*/
|
|
244
|
+
validateActiveWallet(expectedAddress: string): Promise<void>;
|
|
245
|
+
/**
|
|
246
|
+
* Signs a message with additional context information
|
|
247
|
+
* @param message - The message to sign (string or object with raw property)
|
|
248
|
+
* @param context - Additional context for the message signing
|
|
249
|
+
* @returns The signed message as a string
|
|
250
|
+
* @throws {DynamicError} If active account address is not set
|
|
251
|
+
* @throws {DynamicError} If signed session ID is not available
|
|
252
|
+
*/
|
|
253
|
+
signMessageWithContext({ message, context, }: {
|
|
254
|
+
message: string | {
|
|
255
|
+
raw: string;
|
|
256
|
+
};
|
|
257
|
+
context: SignMessageContext;
|
|
258
|
+
}): Promise<string>;
|
|
259
|
+
/**
|
|
260
|
+
* Builds a PSBT for a Bitcoin transaction with real UTXOs
|
|
261
|
+
* @param transaction - The Bitcoin transaction containing recipient address and amount in satoshis to send
|
|
262
|
+
* @returns A PSBT in Base64 format
|
|
263
|
+
* @throws {DynamicError} If no active account address, insufficient funds, or other errors
|
|
264
|
+
*/
|
|
265
|
+
buildPsbt(transaction: BitcoinTransaction): Promise<string>;
|
|
266
|
+
/**
|
|
267
|
+
* Parse a PSBT or finalized transaction and extract transaction information
|
|
268
|
+
* Auto-detects format (hex/base64) and type (PSBT/finalized transaction)
|
|
269
|
+
* @param psbtInput - The PSBT or finalized transaction in Base64 or hex format
|
|
270
|
+
* @returns Parsed transaction data with inputs and outputs, or null if parsing fails
|
|
271
|
+
*/
|
|
272
|
+
parsePsbt(psbtInput: string): ParsedTransaction | null;
|
|
273
|
+
/**
|
|
274
|
+
* Parse a PSBT or finalized transaction from hex format
|
|
275
|
+
* @param psbtHex - The PSBT or finalized transaction in hex format
|
|
276
|
+
* @returns Parsed transaction data with inputs and outputs, or null if parsing fails
|
|
277
|
+
*/
|
|
278
|
+
parseHexPsbt(psbtHex: string): ParsedTransaction | null;
|
|
279
|
+
/**
|
|
280
|
+
* Parse a PSBT or finalized transaction from base64 format
|
|
281
|
+
* @param psbtBase64 - The PSBT or finalized transaction in base64 format
|
|
282
|
+
* @returns Parsed transaction data with inputs and outputs, or null if parsing fails
|
|
283
|
+
*/
|
|
284
|
+
parseBase64Psbt(psbtBase64: string): ParsedTransaction | null;
|
|
285
|
+
/**
|
|
286
|
+
* Gets the public key for the active account
|
|
287
|
+
* Falls back to the account address if public key retrieval fails
|
|
288
|
+
* @returns The public key or account address as fallback
|
|
289
|
+
* @throws {DynamicError} If no active account address is set
|
|
290
|
+
* @throws {DynamicError} If signed session ID is not available
|
|
291
|
+
*/
|
|
292
|
+
getPublicKey(): Promise<string>;
|
|
293
|
+
/**
|
|
294
|
+
* Helper function to convert BTC amount to satoshis
|
|
295
|
+
* @param btcAmount - The Bitcoin amount to convert (number)
|
|
296
|
+
* @returns The amount in satoshis as a BigInt
|
|
297
|
+
* @throws {DynamicError} If the amount is negative
|
|
298
|
+
*/
|
|
299
|
+
btcToSatoshis(btcAmount: number): bigint;
|
|
300
|
+
/**
|
|
301
|
+
* Sets the active account address for this connector
|
|
302
|
+
* @param accountAddress - The Bitcoin account address to set as active
|
|
303
|
+
*/
|
|
304
|
+
private setActiveAccountAddress;
|
|
305
|
+
/**
|
|
306
|
+
* Internal method to sign a message with MFA token
|
|
307
|
+
* @param message - The message to sign
|
|
308
|
+
* @returns The signed message as a string
|
|
309
|
+
* @throws {DynamicError} If active account address is not set
|
|
310
|
+
* @throws {DynamicError} If signed session ID is not available
|
|
311
|
+
*/
|
|
312
|
+
private internalSignMessage;
|
|
313
|
+
}
|
|
314
|
+
export {};
|