@dynamic-labs-wallet/node-btc 0.0.0 → 0.0.255

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.
@@ -0,0 +1,165 @@
1
+ import { DynamicWalletClient, type DynamicWalletClientProps, type ServerKeyShare, type ThresholdSignatureScheme, type EcdsaPublicKey, type BIP340KeygenResult, type EcdsaKeygenResult, type WalletProperties } from '@dynamic-labs-wallet/node';
2
+ import type { SignMessageContext } from '@dynamic-labs/sdk-api-core';
3
+ import { BitcoinAddressType, BitcoinNetwork, type BitcoinConfig } from '@dynamic-labs-wallet/core';
4
+ export declare class DynamicBtcWalletClient extends DynamicWalletClient {
5
+ readonly chainName = "BTC";
6
+ constructor({ environmentId, baseApiUrl, baseMPCRelayApiUrl, enableMPCAccelerator, }: DynamicWalletClientProps);
7
+ /**
8
+ * Derives the Bitcoin account address
9
+ * - BIP340 keys (32 bytes x-only): Only for Taproot addresses
10
+ * - ECDSA keys (33/65 bytes): For all other address types (Legacy, SegWit, Native SegWit)
11
+ * - Algorithm selection is automatic based on addressType
12
+ * @param rawPublicKey - The raw public key to derive the account address from
13
+ * @param addressType - The address type to derive the account address for
14
+ * @param network - The network to derive the account address for
15
+ * @returns The account address
16
+ */
17
+ deriveAccountAddress({ rawPublicKey, addressType, network, }: {
18
+ rawPublicKey: any;
19
+ addressType: BitcoinAddressType;
20
+ network: BitcoinNetwork;
21
+ }): {
22
+ accountAddress: string;
23
+ };
24
+ /**
25
+ * Gets wallet properties and derivation info for a given account address
26
+ * @param accountAddress - The account address
27
+ * @returns The wallet properties, derivation path, and address type
28
+ */
29
+ private getWalletDerivationInfo;
30
+ /**
31
+ * Verifies that the derived address matches the expected address
32
+ * @param rawPublicKey - The raw public key
33
+ * @param addressType - The address type
34
+ * @param network - The network
35
+ * @param expectedAddress - The expected address
36
+ */
37
+ private verifyWalletAddress;
38
+ /**
39
+ * Creates a new wallet account and stores the key shares in the wallet map.
40
+ * @param thresholdSignatureScheme - The threshold signature scheme to use for the wallet.
41
+ * @param password - The password to use for the wallet.
42
+ * @param onError - The function to call if an error occurs.
43
+ * @param backUpToClientShareService - Whether to back up the external server key shares to the client share service. By default, it is false.
44
+ * @param bitcoinConfig - Bitcoin configuration (addressType, network)
45
+ * @returns The account address, public key, raw public key, external server key shares, and wallet id.
46
+ */
47
+ createWalletAccount({ thresholdSignatureScheme, password, onError, backUpToClientShareService, bitcoinConfig, }: {
48
+ thresholdSignatureScheme: ThresholdSignatureScheme;
49
+ password?: string;
50
+ onError?: (error: Error) => void;
51
+ backUpToClientShareService?: boolean;
52
+ bitcoinConfig: BitcoinConfig;
53
+ }): Promise<{
54
+ accountAddress: string;
55
+ publicKeyHex: string;
56
+ rawPublicKey: EcdsaPublicKey | Uint8Array | string | undefined;
57
+ externalServerKeyShares: ServerKeyShare[];
58
+ }>;
59
+ /**
60
+ * Signs a message for BTC using BIP-322 format
61
+ *
62
+ * The address type is automatically derived from the wallet's derivation path.
63
+ * Supports both TAPROOT (BIP-86) and NATIVE_SEGWIT (BIP-84) address types.
64
+ *
65
+ * @param message - The message to sign
66
+ * @param accountAddress - The account address
67
+ * @param network - The Bitcoin network (MAINNET or TESTNET)
68
+ * @param password - Optional password for encrypted backup shares
69
+ * @param externalServerKeyShares - Optional external server key shares
70
+ * @param context - Optional. Sign message context for API tracking
71
+ * @param onError - Optional. Error callback function
72
+ * @returns Promise resolving to the BIP-322 signature as a base64 string
73
+ * @throws Error if required parameters are missing, derivation path is invalid, or signing fails
74
+ */
75
+ signMessage({ message, accountAddress, network, password, externalServerKeyShares, context, onError, }: {
76
+ message: string;
77
+ accountAddress: string;
78
+ network: BitcoinNetwork;
79
+ password?: string;
80
+ externalServerKeyShares?: ServerKeyShare[];
81
+ context?: SignMessageContext;
82
+ onError?: (error: Error) => void;
83
+ }): Promise<string>;
84
+ /**
85
+ * Signs a Bitcoin transaction (PSBT)
86
+ *
87
+ * The address type is automatically derived from the wallet's derivation path.
88
+ * Only inputs belonging to the sender address are signed. Supports both TAPROOT
89
+ * (BIP-341) and Native SegWit (BIP-143) signing methods.
90
+ *
91
+ * @param transaction - The PSBT to sign as a base64 string
92
+ * @param senderAddress - The sender address (must match inputs to be signed)
93
+ * @param network - The Bitcoin network (MAINNET or TESTNET)
94
+ * @param password - Optional password for encrypted backup shares
95
+ * @param externalServerKeyShares - Optional external server key shares
96
+ * @param context - Optional. Sign message context for API tracking
97
+ * @param onError - Optional. Error callback function
98
+ * @returns Promise resolving to the signed PSBT as a base64 string
99
+ * @throws Error if required parameters are missing, no inputs belong to sender address, or signing fails
100
+ */
101
+ signTransaction({ transaction, senderAddress, network, password, externalServerKeyShares, context, onError, }: {
102
+ transaction: string;
103
+ senderAddress: string;
104
+ network: BitcoinNetwork;
105
+ password?: string;
106
+ externalServerKeyShares?: ServerKeyShare[];
107
+ context?: SignMessageContext;
108
+ onError?: (error: Error) => void;
109
+ }): Promise<string>;
110
+ /**
111
+ * Exports the private key for a wallet
112
+ * @param accountAddress - The account address to export the private key for
113
+ * @param password - The password for encrypted backup shares
114
+ * @param externalServerKeyShares - Optional external server key shares
115
+ * @returns The private key in WIF format
116
+ */
117
+ exportPrivateKey({ accountAddress, password, externalServerKeyShares, }: {
118
+ accountAddress: string;
119
+ password?: string;
120
+ externalServerKeyShares?: ServerKeyShare[];
121
+ }): Promise<string>;
122
+ /**
123
+ * Exports the private key for a given account address offline using key shares
124
+ * @param keyShares - The key shares to export the private key for
125
+ * @param derivationPath - Optional derivation path
126
+ * @param bitcoinConfig - Bitcoin configuration (address type, network)
127
+ * @returns The private key in WIF format
128
+ */
129
+ offlineExportPrivateKey({ keyShares, derivationPath, bitcoinConfig, }: {
130
+ keyShares: (EcdsaKeygenResult | BIP340KeygenResult)[];
131
+ derivationPath?: string;
132
+ bitcoinConfig?: BitcoinConfig;
133
+ }): Promise<string>;
134
+ /**
135
+ * Imports a private key and stores the key shares in the wallet map.
136
+ * @param privateKey - The private key to import (WIF format)
137
+ * @param chainName - The chain name to use for the wallet
138
+ * @param thresholdSignatureScheme - The threshold signature scheme to use for the wallet
139
+ * @param password - The password to use for the wallet
140
+ * @param onError - The function to call if an error occurs
141
+ * @param backUpToClientShareService - Whether to back up the external server key shares to the client share service. By default, it is false.
142
+ * @param bitcoinConfig - Bitcoin configuration (addressType, network)
143
+ * @returns The account address, public key, raw public key, external server key shares
144
+ */
145
+ importPrivateKey({ privateKey, chainName, thresholdSignatureScheme, password, backUpToClientShareService, onError, bitcoinConfig, }: {
146
+ privateKey: string;
147
+ chainName: string;
148
+ thresholdSignatureScheme: ThresholdSignatureScheme;
149
+ password?: string;
150
+ backUpToClientShareService?: boolean;
151
+ onError?: (error: Error) => void;
152
+ bitcoinConfig: BitcoinConfig;
153
+ }): Promise<{
154
+ accountAddress: string;
155
+ publicKeyHex: string;
156
+ rawPublicKey: EcdsaPublicKey | Uint8Array | string | undefined;
157
+ externalServerKeyShares: ServerKeyShare[];
158
+ }>;
159
+ /**
160
+ * Gets the Bitcoin wallets
161
+ * @returns The Bitcoin wallets
162
+ */
163
+ getBitcoinWallets(): Promise<WalletProperties[]>;
164
+ }
165
+ //# 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,EACL,mBAAmB,EACnB,KAAK,wBAAwB,EAC7B,KAAK,cAAc,EACnB,KAAK,wBAAwB,EAC7B,KAAK,cAAc,EAEnB,KAAK,kBAAkB,EACvB,KAAK,iBAAiB,EACtB,KAAK,gBAAgB,EAItB,MAAM,2BAA2B,CAAC;AACnC,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAC;AACrE,OAAO,EACL,kBAAkB,EAClB,cAAc,EACd,KAAK,aAAa,EACnB,MAAM,2BAA2B,CAAC;AAkCnC,qBAAa,sBAAuB,SAAQ,mBAAmB;IAC7D,QAAQ,CAAC,SAAS,SAAS;gBAEf,EACV,aAAa,EAC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E,MAAM,CAAC;QACnB,SAAS,EAAE,MAAM,CAAC;QAClB,wBAAwB,EAAE,wBAAwB,CAAC;QACnD,QAAQ,CAAC,EAAE,MAAM,CAAC;QAClB,0BAA0B,CAAC,EAAE,OAAO,CAAC;QACrC,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,CAAC;QACjC,aAAa,EAAE,aAAa,CAAC;KAC9B,GAAG,OAAO,CAAC;QACV,cAAc,EAAE,MAAM,CAAC;QACvB,YAAY,EAAE,MAAM,CAAC;QACrB,YAAY,EAAE,cAAc,GAAG,UAAU,GAAG,MAAM,GAAG,SAAS,CAAC;QAC/D,uBAAuB,EAAE,cAAc,EAAE,CAAC;KAC3C,CAAC;IAkIF;;;OAGG;IACG,iBAAiB,IAAI,OAAO,CAAC,gBAAgB,EAAE,CAAC;CAQvD"}
@@ -0,0 +1,7 @@
1
+ export declare const ERROR_CREATE_WALLET_ACCOUNT = "Error creating wallet account";
2
+ export declare const ERROR_ACCOUNT_ADDRESS_REQUIRED = "Account address is required";
3
+ export declare const ERROR_SIGN_MESSAGE = "Error signing message";
4
+ export declare const ERROR_SIGN_TRANSACTION = "Error signing transaction";
5
+ export declare const ERROR_IMPORT_PRIVATE_KEY = "Error importing private key";
6
+ export declare const ERROR_KEYGEN_FAILED = "Error with keygen";
7
+ //# sourceMappingURL=constants.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../src/client/constants.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,2BAA2B,kCAAkC,CAAC;AAC3E,eAAO,MAAM,8BAA8B,gCAAgC,CAAC;AAC5E,eAAO,MAAM,kBAAkB,0BAA0B,CAAC;AAC1D,eAAO,MAAM,sBAAsB,8BAA8B,CAAC;AAClE,eAAO,MAAM,wBAAwB,gCAAgC,CAAC;AACtE,eAAO,MAAM,mBAAmB,sBAAsB,CAAC"}
@@ -0,0 +1,3 @@
1
+ export * from './client.js';
2
+ export * from './constants.js';
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/client/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC;AAC5B,cAAc,gBAAgB,CAAC"}
package/src/index.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ export * from './client/index.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,mBAAmB,CAAC"}
@@ -0,0 +1,10 @@
1
+ import { Logger } from '@dynamic-labs/logger';
2
+ export declare const logger: Logger;
3
+ declare const logError: ({ message, error, context, }: {
4
+ message: string;
5
+ error: Error;
6
+ context: Record<string, unknown>;
7
+ }) => void;
8
+ export { Logger } from '@dynamic-labs/logger';
9
+ export { logError };
10
+ //# sourceMappingURL=logger.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../../src/services/logger.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAC;AAI9C,eAAO,MAAM,MAAM,QAAwC,CAAC;AAE5D,QAAA,MAAM,QAAQ,iCAIX;IACD,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,EAAE,KAAK,CAAC;IACb,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAClC,KAAG,IAQH,CAAC;AAEF,OAAO,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAC;AAC9C,OAAO,EAAE,QAAQ,EAAE,CAAC"}