@dynamic-labs-wallet/btc 0.0.323 → 0.0.325

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/index.cjs.js CHANGED
@@ -755,7 +755,7 @@ class DynamicBtcWalletClient extends browser.DynamicWalletClient {
755
755
  * @returns The Bitcoin wallets
756
756
  */ async getBitcoinWallets() {
757
757
  const wallets = await this.getWallets();
758
- const btcWallets = wallets.filter((wallet)=>wallet.chainName === 'bitcoin');
758
+ const btcWallets = wallets.filter((wallet)=>wallet.chainName === 'BTC');
759
759
  return btcWallets;
760
760
  }
761
761
  /**
package/index.esm.js CHANGED
@@ -734,7 +734,7 @@ class DynamicBtcWalletClient extends DynamicWalletClient {
734
734
  * @returns The Bitcoin wallets
735
735
  */ async getBitcoinWallets() {
736
736
  const wallets = await this.getWallets();
737
- const btcWallets = wallets.filter((wallet)=>wallet.chainName === 'bitcoin');
737
+ const btcWallets = wallets.filter((wallet)=>wallet.chainName === 'BTC');
738
738
  return btcWallets;
739
739
  }
740
740
  /**
package/package.json CHANGED
@@ -1,13 +1,13 @@
1
1
  {
2
2
  "name": "@dynamic-labs-wallet/btc",
3
- "version": "0.0.323",
3
+ "version": "0.0.325",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "sideEffects": false,
7
7
  "dependencies": {
8
8
  "@dynamic-labs/sdk-api-core": "^0.0.900",
9
- "@dynamic-labs-wallet/browser": "0.0.323",
10
- "@dynamic-labs-wallet/btc-utils": "0.0.323",
9
+ "@dynamic-labs-wallet/browser": "0.0.325",
10
+ "@dynamic-labs-wallet/btc-utils": "0.0.325",
11
11
  "@bitcoinerlab/secp256k1": "^1.2.0",
12
12
  "bitcoinjs-lib": "^7.0.0"
13
13
  },
@@ -0,0 +1,182 @@
1
+ import { BitcoinAddressType, BitcoinNetwork, DynamicWalletClient, type BIP340KeygenResult, type BitcoinConfig, type DynamicWalletClientInternalOptions, type DynamicWalletClientProps, type EcdsaPublicKey, type ThresholdSignatureScheme, type RequestWithElevatedAccessToken } from '@dynamic-labs-wallet/browser';
2
+ import type { SignMessageContext } from '@dynamic-labs/sdk-api-core';
3
+ export declare class DynamicBtcWalletClient extends DynamicWalletClient {
4
+ readonly chainName = "BTC";
5
+ /**
6
+ * Creates a new instance of DynamicBtcWalletClient
7
+ * @param props - The client properties
8
+ */
9
+ constructor({ environmentId, authToken, baseApiUrl, baseMPCRelayApiUrl, storageKey, debug, featureFlags, authMode, sdkVersion, forwardMPCClient, logger, }: DynamicWalletClientProps, internalOptions?: DynamicWalletClientInternalOptions);
10
+ /**
11
+ * Creates a Bitcoin wallet account
12
+ * @param thresholdSignatureScheme - The threshold signature scheme to use for the wallet
13
+ * @param password - The password to use for the wallet
14
+ * @param onError - The function to call if an error occurs
15
+ * @param signedSessionId - The signed session ID to use for the wallet
16
+ * @param addressType - The type of address to use for the wallet
17
+ * @returns The account address, public key hex, and raw public key
18
+ */
19
+ createWalletAccount({ thresholdSignatureScheme, password, onError, signedSessionId, bitcoinConfig, }: {
20
+ thresholdSignatureScheme: ThresholdSignatureScheme;
21
+ password?: string;
22
+ onError?: (error: Error) => void;
23
+ signedSessionId: string;
24
+ bitcoinConfig: BitcoinConfig;
25
+ }): Promise<{
26
+ accountAddress: string;
27
+ publicKeyHex: string;
28
+ rawPublicKey: EcdsaPublicKey | BIP340KeygenResult | Uint8Array | string | undefined;
29
+ }>;
30
+ /**
31
+ * Derives the Bitcoin account address
32
+ * - BIP340 keys (32 bytes x-only): Only for Taproot addresses
33
+ * - ECDSA keys (33/65 bytes): For all other address types (Legacy, SegWit, Native SegWit)
34
+ * - Algorithm selection is automatic based on addressType
35
+ * @param rawPublicKey - The raw public key to derive the account address from
36
+ * @param addressType - The address type to derive the account address for
37
+ * @param network - The network to derive the account address for
38
+ * @returns The account address
39
+ */
40
+ deriveAccountAddress({ rawPublicKey, addressType, network, }: {
41
+ rawPublicKey: any;
42
+ addressType: BitcoinAddressType;
43
+ network: BitcoinNetwork;
44
+ }): {
45
+ accountAddress: string;
46
+ };
47
+ /**
48
+ * Signs a message (BIP-322)
49
+ * @param message - The message to sign
50
+ * @param accountAddress - The account address
51
+ * @param network - The network (mainnet/testnet)
52
+ * @param password - The wallet password (optional)
53
+ * @param signedSessionId - The signed session ID
54
+ * @param mfaToken - The MFA token (optional)
55
+ * @param context - Additional context
56
+ * @param onError - Error callback
57
+ * @returns The BIP-322 signature
58
+ */
59
+ signMessage({ message, accountAddress, network, password, signedSessionId, mfaToken, elevatedAccessToken, context, onError, }: {
60
+ message: string;
61
+ accountAddress: string;
62
+ network: BitcoinNetwork;
63
+ password?: string;
64
+ signedSessionId: string;
65
+ mfaToken?: string;
66
+ elevatedAccessToken?: string;
67
+ context?: SignMessageContext;
68
+ onError?: (error: Error) => void;
69
+ }): Promise<string>;
70
+ /**
71
+ * Verifies that the derived address matches the expected address
72
+ * @param rawPublicKey - The raw public key
73
+ * @param addressType - The address type
74
+ * @param network - The network
75
+ * @param expectedAddress - The expected address
76
+ */
77
+ private verifyWalletAddress;
78
+ /**
79
+ * Exports the private key for a given account
80
+ * @param accountAddress - The account address to export the private key for
81
+ * @param password - The password to use for the private key
82
+ * @param signedSessionId - The signed session ID to use for the private key
83
+ * @param mfaToken - The MFA token to use for the private key
84
+ * @param network - The network to use for the private key
85
+ * @returns The private key
86
+ */
87
+ exportPrivateKey({ accountAddress, password, signedSessionId, mfaToken, elevatedAccessToken, }: RequestWithElevatedAccessToken<{
88
+ accountAddress: string;
89
+ password?: string;
90
+ signedSessionId: string;
91
+ mfaToken?: string;
92
+ }>): Promise<string>;
93
+ /**
94
+ * Imports a private key and creates a Bitcoin wallet account
95
+ * @param privateKey - Private key in WIF format (Base58 encoded)
96
+ * @param chainName - Chain name ('BTC')
97
+ * @param thresholdSignatureScheme - The threshold signature scheme to use
98
+ * @param password - Optional password for encrypted backup
99
+ * @param onError - Optional error callback
100
+ * @param signedSessionId - The signed session ID
101
+ * @param publicAddressCheck - Optional address to validate against
102
+ * @param addressType - Bitcoin address type (NATIVE_SEGWIT or TAPROOT)
103
+ * @returns The account address, public key hex, and raw public key
104
+ */
105
+ importPrivateKey({ privateKey, chainName, thresholdSignatureScheme, password, onError, signedSessionId, publicAddressCheck, addressType, legacyWalletId, }: {
106
+ privateKey: string;
107
+ chainName: string;
108
+ thresholdSignatureScheme: ThresholdSignatureScheme;
109
+ password?: string;
110
+ onError?: (error: Error) => void;
111
+ signedSessionId: string;
112
+ publicAddressCheck?: string;
113
+ addressType?: string;
114
+ /** ID of the legacy embedded wallet being upgraded to v3 */
115
+ legacyWalletId?: string;
116
+ }): Promise<{
117
+ accountAddress: string;
118
+ publicKeyHex: string;
119
+ rawPublicKey: EcdsaPublicKey | BIP340KeygenResult | Uint8Array | string | undefined;
120
+ }>;
121
+ /**
122
+ * Converts MPC private key to Bitcoin WIF (Wallet Import Format)
123
+ * Uses the utility function from utils.ts for the core conversion logic
124
+ * @param privateKey - The private key to convert to a Bitcoin WIF format
125
+ * @param network - The network to convert the private key to a Bitcoin WIF format for
126
+ * @returns The Bitcoin WIF format
127
+ */
128
+ private convertPrivateKeyToBitcoinFormat;
129
+ /**
130
+ * Sign a Bitcoin Transaction (PSBT)
131
+ *
132
+ * @param transaction - The PSBT to sign in hex format
133
+ * @param senderAddress - The address of the sender
134
+ * @param password - The password to use for the transaction
135
+ * @param signedSessionId - The signed session ID to use for the transaction
136
+ * @param authToken - The auth token to use for the transaction
137
+ * @param mfaToken - The MFA token to use for the transaction
138
+ * @param context - The context to use for the transaction
139
+ * @param onError - The error handler
140
+ * @returns The signed PSBT
141
+ */
142
+ signTransaction({ transaction, senderAddress, network, password, signedSessionId, mfaToken, elevatedAccessToken, context, onError, }: {
143
+ transaction: string;
144
+ senderAddress: string;
145
+ network: BitcoinNetwork;
146
+ password?: string;
147
+ signedSessionId: string;
148
+ mfaToken?: string;
149
+ elevatedAccessToken?: string;
150
+ context?: SignMessageContext;
151
+ onError?: (error: Error) => void;
152
+ }): Promise<string>;
153
+ /**
154
+ * Creates a PSBT for a transaction
155
+ * @param receiverAddress - The address to send funds to
156
+ * @param amount - The amount to send in satoshis
157
+ * @param senderAddress - The address to send funds from
158
+ * @param network - The network to use (mainnet/testnet)
159
+ * @param feeRateLevel - The fee rate level to use (fast, medium, slow)
160
+ * @returns The PSBT in hex format
161
+ */
162
+ createTransaction({ receiverAddress, amount, senderAddress, network, feeRateLevel, }: {
163
+ receiverAddress: string;
164
+ amount: string;
165
+ senderAddress: string;
166
+ network: BitcoinNetwork;
167
+ feeRateLevel?: 'fast' | 'medium' | 'slow';
168
+ }): Promise<string>;
169
+ /**
170
+ * Fetches the raw transaction hex for a given transaction ID
171
+ * @param txid - The transaction ID
172
+ * @param network - The network
173
+ * @returns The transaction hex
174
+ */
175
+ private getTxHex;
176
+ /**
177
+ * Gets the Bitcoin wallets
178
+ * @returns The Bitcoin wallets
179
+ */
180
+ getBitcoinWallets(): Promise<any>;
181
+ }
182
+ //# sourceMappingURL=client.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/client/client.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,kBAAkB,EAClB,cAAc,EACd,mBAAmB,EAOnB,KAAK,kBAAkB,EACvB,KAAK,aAAa,EAClB,KAAK,kCAAkC,EACvC,KAAK,wBAAwB,EAC7B,KAAK,cAAc,EAEnB,KAAK,wBAAwB,EAC7B,KAAK,8BAA8B,EACpC,MAAM,8BAA8B,CAAC;AACtC,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAC;AA2BrE,qBAAa,sBAAuB,SAAQ,mBAAmB;IAC7D,QAAQ,CAAC,SAAS,SAAS;IAE3B;;;OAGG;gBAED,EACE,aAAa,EACb,SAAS,EACT,UAAU,EACV,kBAAkB,EAClB,UAAU,EACV,KAAK,EACL,YAAY,EACZ,QAA0B,EAC1B,UAAU,EACV,gBAAgB,EAChB,MAAM,GACP,EAAE,wBAAwB,EAC3B,eAAe,C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AO,EACP,OAAO,GACR,EAAE;QACD,WAAW,EAAE,MAAM,CAAC;QACpB,aAAa,EAAE,MAAM,CAAC;QACtB,OAAO,EAAE,cAAc,CAAC;QACxB,QAAQ,CAAC,EAAE,MAAM,CAAC;QAClB,eAAe,EAAE,MAAM,CAAC;QACxB,QAAQ,CAAC,EAAE,MAAM,CAAC;QAClB,mBAAmB,CAAC,EAAE,MAAM,CAAC;QAC7B,OAAO,CAAC,EAAE,kBAAkB,CAAC;QAC7B,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,CAAC;KAClC,GAAG,OAAO,CAAC,MAAM,CAAC;IA2MnB;;;;;;;;OAQG;IACG,iBAAiB,CAAC,EACtB,eAAe,EACf,MAAM,EACN,aAAa,EACb,OAAO,EACP,YAAuB,GACxB,EAAE;QACD,eAAe,EAAE,MAAM,CAAC;QACxB,MAAM,EAAE,MAAM,CAAC;QACf,aAAa,EAAE,MAAM,CAAC;QACtB,OAAO,EAAE,cAAc,CAAC;QACxB,YAAY,CAAC,EAAE,MAAM,GAAG,QAAQ,GAAG,MAAM,CAAC;KAC3C,GAAG,OAAO,CAAC,MAAM,CAAC;IAwGnB;;;;;OAKG;YACW,QAAQ;IAWtB;;;OAGG;IACG,iBAAiB;CAKxB"}
package/src/index.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ export * from './client/client.js';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../packages/src/index.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAC"}
@@ -0,0 +1,39 @@
1
+ /**
2
+ * Supported Bitcoin networks.
3
+ */
4
+ export type BitcoinNetwork = 'mainnet' | 'testnet';
5
+ /**
6
+ * Represents an Unspent Transaction Output (UTXO).
7
+ */
8
+ export type UTXO = {
9
+ /**
10
+ * The transaction ID where this output was created.
11
+ */
12
+ txid: string;
13
+ /**
14
+ * The index of the output in the transaction.
15
+ */
16
+ vout: number;
17
+ /**
18
+ * The value of the output in satoshis.
19
+ */
20
+ value: bigint;
21
+ /**
22
+ * The script public key of the output.
23
+ */
24
+ scriptPubKey?: Uint8Array;
25
+ /**
26
+ * The witness UTXO data, used for SegWit inputs.
27
+ */
28
+ witnessUtxo?: {
29
+ /**
30
+ * The script of the witness UTXO.
31
+ */
32
+ script: Uint8Array;
33
+ /**
34
+ * The amount of the witness UTXO in satoshis.
35
+ */
36
+ amount: bigint;
37
+ };
38
+ };
39
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,MAAM,cAAc,GAAG,SAAS,GAAG,SAAS,CAAC;AAEnD;;GAEG;AACH,MAAM,MAAM,IAAI,GAAG;IACjB;;OAEG;IACH,IAAI,EAAE,MAAM,CAAC;IACb;;OAEG;IACH,IAAI,EAAE,MAAM,CAAC;IACb;;OAEG;IACH,KAAK,EAAE,MAAM,CAAC;IACd;;OAEG;IACH,YAAY,CAAC,EAAE,UAAU,CAAC;IAC1B;;OAEG;IACH,WAAW,CAAC,EAAE;QACZ;;WAEG;QACH,MAAM,EAAE,UAAU,CAAC;QACnB;;WAEG;QACH,MAAM,EAAE,MAAM,CAAC;KAChB,CAAC;CACH,CAAC"}
@@ -0,0 +1,2 @@
1
+ export { parseDerivationPath } from './parseDerivationPath/index.js';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,gCAAgC,CAAC"}
@@ -0,0 +1,2 @@
1
+ export { parseDerivationPath } from './parseDerivationPath.js';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/utils/parseDerivationPath/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC"}
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Parses the derivation path string into a Uint32Array
3
+ * Handles empty strings and empty array strings by returning an empty Uint32Array
4
+ *
5
+ * @param derivationPath - The derivation path as a JSON string (e.g., '{"0":44,"1":0,"2":0}' or '[]' or '')
6
+ * @returns The derivation path as a Uint32Array
7
+ * @throws Error if the derivation path is invalid JSON
8
+ */
9
+ export declare const parseDerivationPath: (derivationPath: string) => Uint32Array;
10
+ //# sourceMappingURL=parseDerivationPath.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"parseDerivationPath.d.ts","sourceRoot":"","sources":["../../../src/utils/parseDerivationPath/parseDerivationPath.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,eAAO,MAAM,mBAAmB,mBAAoB,MAAM,KAAG,WAK5D,CAAC"}