@dynamic-labs-wallet/node-btc 0.0.354 → 0.1.0-request-signing
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 +209 -177
- package/index.esm.js +212 -180
- package/package.json +6 -6
- package/src/client/client.d.ts +49 -30
- package/src/client/client.d.ts.map +1 -1
package/package.json
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dynamic-labs-wallet/node-btc",
|
|
3
|
-
"version": "0.0
|
|
3
|
+
"version": "0.1.0-request-signing",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"dependencies": {
|
|
7
|
-
"@dynamic-labs-wallet/core": "0.0
|
|
8
|
-
"@dynamic-labs-wallet/node": "0.0
|
|
9
|
-
"@dynamic-labs-wallet/btc-utils": "0.0
|
|
10
|
-
"@dynamic-labs/sdk-api-core": "
|
|
11
|
-
"bitcoinjs-lib": "^7.0.
|
|
7
|
+
"@dynamic-labs-wallet/core": "0.1.0-request-signing",
|
|
8
|
+
"@dynamic-labs-wallet/node": "0.1.0-request-signing",
|
|
9
|
+
"@dynamic-labs-wallet/btc-utils": "0.1.0-request-signing",
|
|
10
|
+
"@dynamic-labs/sdk-api-core": "0.193.0",
|
|
11
|
+
"bitcoinjs-lib": "^7.0.2",
|
|
12
12
|
"tiny-secp256k1": "^2.2.3"
|
|
13
13
|
},
|
|
14
14
|
"publishConfig": {
|
package/src/client/client.d.ts
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
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
|
|
3
|
-
import { BitcoinAddressType, BitcoinNetwork, type BitcoinConfig } from '@dynamic-labs-wallet/core';
|
|
1
|
+
import { DynamicWalletClient, type DynamicWalletClientProps, type ServerKeyShare, type ThresholdSignatureScheme, type EcdsaPublicKey, type BIP340KeygenResult, type EcdsaKeygenResult, type WalletMetadata, type WalletProperties, type WalletApiKeyCreationResult } from '@dynamic-labs-wallet/node';
|
|
2
|
+
import { BitcoinAddressType, BitcoinNetwork, type BitcoinConfig, type SignMessageContext } from '@dynamic-labs-wallet/core';
|
|
4
3
|
export declare class DynamicBtcWalletClient extends DynamicWalletClient {
|
|
5
4
|
readonly chainName = "BTC";
|
|
6
|
-
constructor({ environmentId, baseApiUrl, baseMPCRelayApiUrl, enableMPCAccelerator, logger, debug, }: DynamicWalletClientProps);
|
|
5
|
+
constructor({ environmentId, baseApiUrl, baseMPCRelayApiUrl, enableMPCAccelerator, logger, requestSigning, debug, }: DynamicWalletClientProps);
|
|
7
6
|
/**
|
|
8
7
|
* Derives the Bitcoin account address
|
|
9
8
|
* - BIP340 keys (32 bytes x-only): Only for Taproot addresses
|
|
@@ -22,11 +21,12 @@ export declare class DynamicBtcWalletClient extends DynamicWalletClient {
|
|
|
22
21
|
accountAddress: string;
|
|
23
22
|
};
|
|
24
23
|
/**
|
|
25
|
-
*
|
|
26
|
-
* @param
|
|
27
|
-
* @returns The
|
|
24
|
+
* Extracts derivation path and address type from walletMetadata.
|
|
25
|
+
* @param walletMetadata - The wallet metadata
|
|
26
|
+
* @returns The derivation path and derived address type
|
|
28
27
|
*/
|
|
29
|
-
private
|
|
28
|
+
private getDerivationInfoFromMetadata;
|
|
29
|
+
private buildWalletMetadata;
|
|
30
30
|
/**
|
|
31
31
|
* Verifies that the derived address matches the expected address
|
|
32
32
|
* @param rawPublicKey - The raw public key
|
|
@@ -40,27 +40,26 @@ export declare class DynamicBtcWalletClient extends DynamicWalletClient {
|
|
|
40
40
|
* @param thresholdSignatureScheme - The threshold signature scheme to use for the wallet.
|
|
41
41
|
* @param password - The password to use for the wallet.
|
|
42
42
|
* @param onError - The function to call if an error occurs.
|
|
43
|
-
* @param
|
|
43
|
+
* @param backUpToDynamic - Whether to back up the external server key shares to the client share service. By default, it is false.
|
|
44
44
|
* @param bitcoinConfig - Bitcoin configuration (addressType, network)
|
|
45
45
|
* @returns The account address, public key, raw public key, external server key shares, and wallet id.
|
|
46
46
|
*/
|
|
47
|
-
createWalletAccount({ thresholdSignatureScheme, password, onError,
|
|
47
|
+
createWalletAccount({ thresholdSignatureScheme, password, onError, backUpToDynamic, bitcoinConfig, }: {
|
|
48
48
|
thresholdSignatureScheme: ThresholdSignatureScheme;
|
|
49
49
|
password?: string;
|
|
50
50
|
onError?: (error: Error) => void;
|
|
51
|
-
|
|
51
|
+
backUpToDynamic?: boolean;
|
|
52
52
|
bitcoinConfig?: BitcoinConfig;
|
|
53
53
|
}): Promise<{
|
|
54
|
-
|
|
54
|
+
walletMetadata: WalletMetadata;
|
|
55
55
|
publicKeyHex: string;
|
|
56
56
|
rawPublicKey: EcdsaPublicKey | Uint8Array | string | undefined;
|
|
57
|
-
/** @deprecated Use externalKeySharesWithBackupStatus instead */
|
|
58
57
|
externalServerKeyShares: ServerKeyShare[];
|
|
59
58
|
externalKeySharesWithBackupStatus: Array<{
|
|
60
59
|
share: ServerKeyShare;
|
|
61
60
|
backedUpToClientKeyShareService: boolean;
|
|
62
61
|
}>;
|
|
63
|
-
}>;
|
|
62
|
+
} & WalletApiKeyCreationResult>;
|
|
64
63
|
/**
|
|
65
64
|
* Signs a message for BTC using BIP-322 format
|
|
66
65
|
*
|
|
@@ -77,9 +76,9 @@ export declare class DynamicBtcWalletClient extends DynamicWalletClient {
|
|
|
77
76
|
* @returns Promise resolving to the BIP-322 signature as a base64 string
|
|
78
77
|
* @throws Error if required parameters are missing, derivation path is invalid, or signing fails
|
|
79
78
|
*/
|
|
80
|
-
signMessage({ message,
|
|
79
|
+
signMessage({ message, walletMetadata, network, password, externalServerKeyShares, context, onError, }: {
|
|
81
80
|
message: string;
|
|
82
|
-
|
|
81
|
+
walletMetadata: WalletMetadata;
|
|
83
82
|
network: BitcoinNetwork;
|
|
84
83
|
password?: string;
|
|
85
84
|
externalServerKeyShares?: ServerKeyShare[];
|
|
@@ -90,51 +89,72 @@ export declare class DynamicBtcWalletClient extends DynamicWalletClient {
|
|
|
90
89
|
* Signs a Bitcoin transaction (PSBT)
|
|
91
90
|
*
|
|
92
91
|
* The address type is automatically derived from the wallet's derivation path.
|
|
93
|
-
* Only inputs belonging to the
|
|
92
|
+
* Only inputs belonging to the account address are signed. Supports both TAPROOT
|
|
94
93
|
* (BIP-341) and Native SegWit (BIP-143) signing methods.
|
|
95
94
|
*
|
|
95
|
+
* ECDSA wallets can also co-sign P2WSH multisig inputs, but only opt-in: pass the
|
|
96
|
+
* hex-encoded witnessScripts you constructed via `allowedWitnessScripts`. An input
|
|
97
|
+
* is signed when its witnessScript is allowlisted, hashes to the scriptPubKey
|
|
98
|
+
* commitment, and is a canonical multisig containing this wallet's public key.
|
|
99
|
+
* Omitting `allowedWitnessScripts` disables P2WSH signing entirely. The returned
|
|
100
|
+
* PSBT carries this wallet's partialSig and is NOT finalized — remaining
|
|
101
|
+
* co-signers add their signatures before finalizing.
|
|
102
|
+
*
|
|
96
103
|
* @param transaction - The PSBT to sign as a base64 string
|
|
97
|
-
* @param
|
|
104
|
+
* @param accountAddress - The account address (must match inputs to be signed)
|
|
98
105
|
* @param network - The Bitcoin network (MAINNET or TESTNET)
|
|
99
106
|
* @param password - Optional password for encrypted backup shares
|
|
100
107
|
* @param externalServerKeyShares - Optional external server key shares
|
|
101
108
|
* @param context - Optional. Sign message context for API tracking
|
|
102
109
|
* @param onError - Optional. Error callback function
|
|
103
110
|
* @returns Promise resolving to the signed PSBT as a base64 string
|
|
104
|
-
* @throws Error if required parameters are missing, no inputs belong to
|
|
111
|
+
* @throws Error if required parameters are missing, no inputs belong to account address, or signing fails
|
|
105
112
|
*/
|
|
106
|
-
signTransaction({ transaction,
|
|
113
|
+
signTransaction({ transaction, walletMetadata, network, password, externalServerKeyShares, context, onError, signingIndexes, allowedSighash, allowedWitnessScripts, }: {
|
|
107
114
|
transaction: string;
|
|
108
|
-
|
|
115
|
+
walletMetadata: WalletMetadata;
|
|
109
116
|
network: BitcoinNetwork;
|
|
110
117
|
password?: string;
|
|
111
118
|
externalServerKeyShares?: ServerKeyShare[];
|
|
112
119
|
context?: SignMessageContext;
|
|
113
120
|
onError?: (error: Error) => void;
|
|
121
|
+
signingIndexes?: number[];
|
|
122
|
+
allowedSighash?: number[];
|
|
123
|
+
/** Hex-encoded witnessScripts the wallet may co-sign (P2WSH opt-in). */
|
|
124
|
+
allowedWitnessScripts?: string[];
|
|
114
125
|
}): Promise<string>;
|
|
115
126
|
/**
|
|
116
127
|
* Exports the private key for a wallet
|
|
117
|
-
* @param
|
|
128
|
+
* @param walletMetadata - The wallet metadata of the wallet to export
|
|
118
129
|
* @param password - The password for encrypted backup shares
|
|
119
130
|
* @param externalServerKeyShares - Optional external server key shares
|
|
131
|
+
* @param network - Network the WIF is encoded for. Defaults to mainnet. `walletMetadata` does not record a network, so pass `BitcoinNetwork.TESTNET` for a wallet you use on testnet
|
|
120
132
|
* @returns The private key in WIF format
|
|
121
133
|
*/
|
|
122
|
-
exportPrivateKey({
|
|
123
|
-
|
|
134
|
+
exportPrivateKey({ walletMetadata, password, externalServerKeyShares, network, }: {
|
|
135
|
+
walletMetadata: WalletMetadata;
|
|
124
136
|
password?: string;
|
|
125
137
|
externalServerKeyShares?: ServerKeyShare[];
|
|
138
|
+
network?: BitcoinNetwork;
|
|
126
139
|
}): Promise<string>;
|
|
127
140
|
/**
|
|
128
141
|
* Exports the private key for a given account address offline using key shares
|
|
129
142
|
* @param keyShares - The key shares to export the private key for
|
|
130
143
|
* @param derivationPath - Optional derivation path
|
|
131
144
|
* @param bitcoinConfig - Bitcoin configuration (address type, network)
|
|
145
|
+
* @param thresholdSignatureScheme - The wallet's scheme. When given, at least that scheme's threshold of shares is required (2 for TWO_OF_TWO and TWO_OF_THREE, 3 for THREE_OF_FIVE). A TWO_OF_TWO wallet cannot be exported offline from the external server's shares alone, because it holds only one of the two
|
|
132
146
|
* @returns The private key in WIF format
|
|
147
|
+
*
|
|
148
|
+
* `derivationPath` is the JSON-serialized index map that
|
|
149
|
+
* `walletMetadata.derivationPath` carries (e.g. `'{"0":44,"1":60,"2":0,"3":0,"4":0}'`
|
|
150
|
+
* or `'[44,60,0,0,0]'`). BIP-32 strings such as `"m/44'/60'/0'/0/0"` are rejected.
|
|
151
|
+
* Omit it to export without path derivation.
|
|
133
152
|
*/
|
|
134
|
-
offlineExportPrivateKey({ keyShares, derivationPath, bitcoinConfig, }: {
|
|
153
|
+
offlineExportPrivateKey({ keyShares, derivationPath, bitcoinConfig, thresholdSignatureScheme, }: {
|
|
135
154
|
keyShares: (EcdsaKeygenResult | BIP340KeygenResult)[];
|
|
136
155
|
derivationPath?: string;
|
|
137
156
|
bitcoinConfig?: BitcoinConfig;
|
|
157
|
+
thresholdSignatureScheme?: ThresholdSignatureScheme;
|
|
138
158
|
}): Promise<string>;
|
|
139
159
|
/**
|
|
140
160
|
* Imports a private key and stores the key shares in the wallet map.
|
|
@@ -143,23 +163,22 @@ export declare class DynamicBtcWalletClient extends DynamicWalletClient {
|
|
|
143
163
|
* @param thresholdSignatureScheme - The threshold signature scheme to use for the wallet
|
|
144
164
|
* @param password - The password to use for the wallet
|
|
145
165
|
* @param onError - The function to call if an error occurs
|
|
146
|
-
* @param
|
|
166
|
+
* @param backUpToDynamic - Whether to back up the external server key shares to the client share service. By default, it is false.
|
|
147
167
|
* @param bitcoinConfig - Bitcoin configuration (addressType, network)
|
|
148
168
|
* @returns The account address, public key, raw public key, external server key shares
|
|
149
169
|
*/
|
|
150
|
-
importPrivateKey({ privateKey, chainName, thresholdSignatureScheme, password,
|
|
170
|
+
importPrivateKey({ privateKey, chainName, thresholdSignatureScheme, password, backUpToDynamic, onError, bitcoinConfig, }: {
|
|
151
171
|
privateKey: string;
|
|
152
172
|
chainName: string;
|
|
153
173
|
thresholdSignatureScheme: ThresholdSignatureScheme;
|
|
154
174
|
password?: string;
|
|
155
|
-
|
|
175
|
+
backUpToDynamic?: boolean;
|
|
156
176
|
onError?: (error: Error) => void;
|
|
157
177
|
bitcoinConfig: BitcoinConfig;
|
|
158
178
|
}): Promise<{
|
|
159
|
-
|
|
179
|
+
walletMetadata: WalletMetadata;
|
|
160
180
|
publicKeyHex: string;
|
|
161
181
|
rawPublicKey: EcdsaPublicKey | Uint8Array | string | undefined;
|
|
162
|
-
/** @deprecated Use externalKeySharesWithBackupStatus instead */
|
|
163
182
|
externalServerKeyShares: ServerKeyShare[];
|
|
164
183
|
externalKeySharesWithBackupStatus: Array<{
|
|
165
184
|
share: ServerKeyShare;
|
|
@@ -1 +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,
|
|
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,cAAc,EACnB,KAAK,gBAAgB,EACrB,KAAK,0BAA0B,EAIhC,MAAM,2BAA2B,CAAC;AAEnC,OAAO,EACL,kBAAkB,EAClB,cAAc,EACd,KAAK,aAAa,EAClB,KAAK,kBAAkB,EACxB,MAAM,2BAA2B,CAAC;AAuCnC,qBAAa,sBAAuB,SAAQ,mBAAmB;IAC7D,QAAQ,CAAC,SAAS,SAAS;gBAEf,EACV,aAAa,EACb,UAAU,EACV,kBAAkB,EAClB,oBAAoB,EACpB,MAAM,EACN,cAAc,EACd,KAAK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