@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.
Files changed (44) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/package.cjs +1 -1
  3. package/package.js +1 -1
  4. package/package.json +11 -6
  5. package/src/connectors/BitcoinSatsConnectConnector/BitcoinSatsConnectConnector.js +1 -1
  6. package/src/connectors/BitcoinWalletConnector.cjs +8 -0
  7. package/src/connectors/BitcoinWalletConnector.d.ts +1 -0
  8. package/src/connectors/BitcoinWalletConnector.js +10 -2
  9. package/src/connectors/DynamicWaasBitcoinConnector/DynamicWaasBitcoinConnector.cjs +464 -0
  10. package/src/connectors/DynamicWaasBitcoinConnector/DynamicWaasBitcoinConnector.d.ts +314 -0
  11. package/src/connectors/DynamicWaasBitcoinConnector/DynamicWaasBitcoinConnector.js +460 -0
  12. package/src/connectors/DynamicWaasBitcoinConnector/index.d.ts +1 -0
  13. package/src/connectors/index.d.ts +1 -0
  14. package/src/const.cjs +13 -0
  15. package/src/const.d.ts +6 -0
  16. package/src/const.js +8 -1
  17. package/src/index.cjs +9 -0
  18. package/src/index.d.ts +2 -2
  19. package/src/index.js +6 -0
  20. package/src/services/MempoolApiService.cjs +127 -0
  21. package/src/services/MempoolApiService.d.ts +42 -0
  22. package/src/services/MempoolApiService.js +123 -0
  23. package/src/services/PsbtBuilderService.cjs +132 -0
  24. package/src/services/PsbtBuilderService.d.ts +27 -0
  25. package/src/services/PsbtBuilderService.js +124 -0
  26. package/src/types.d.ts +43 -0
  27. package/src/utils/btcToSatoshis/btcToSatoshis.cjs +24 -0
  28. package/src/utils/btcToSatoshis/btcToSatoshis.d.ts +7 -0
  29. package/src/utils/btcToSatoshis/btcToSatoshis.js +20 -0
  30. package/src/utils/btcToSatoshis/index.d.ts +1 -0
  31. package/src/utils/fetchSatsConnectConnectors/fetchSatsConnectConnectors.cjs +1 -0
  32. package/src/utils/fetchSatsConnectConnectors/fetchSatsConnectConnectors.js +1 -0
  33. package/src/utils/getBitcoinNetwork/getBitcoinNetwork.cjs +15 -0
  34. package/src/utils/getBitcoinNetwork/getBitcoinNetwork.d.ts +7 -0
  35. package/src/utils/getBitcoinNetwork/getBitcoinNetwork.js +11 -0
  36. package/src/utils/getBitcoinNetwork/index.d.ts +1 -0
  37. package/src/utils/index.d.ts +3 -0
  38. package/src/utils/psbtParser/PsbtParser.cjs +185 -0
  39. package/src/utils/psbtParser/PsbtParser.d.ts +63 -0
  40. package/src/utils/psbtParser/PsbtParser.js +181 -0
  41. package/src/utils/psbtParser/index.d.ts +1 -0
  42. package/src/wallet/BitcoinWallet.cjs +11 -0
  43. package/src/wallet/BitcoinWallet.d.ts +6 -0
  44. package/src/wallet/BitcoinWallet.js +11 -0
package/CHANGELOG.md CHANGED
@@ -1,4 +1,20 @@
1
1
 
2
+ ## [4.53.0](https://github.com/dynamic-labs/dynamic-auth/compare/v4.52.5...v4.53.0) (2026-01-13)
3
+
4
+
5
+ ### Features
6
+
7
+ * add contract deployment bundle into first transaction ([#10089](https://github.com/dynamic-labs/dynamic-auth/issues/10089)) ([1291f2a](https://github.com/dynamic-labs/dynamic-auth/commit/1291f2ae2d4881c047a3e6e4e6cf4281a868f626))
8
+ * add ton balance to wallet connector ([#10186](https://github.com/dynamic-labs/dynamic-auth/issues/10186)) ([7b1bdf3](https://github.com/dynamic-labs/dynamic-auth/commit/7b1bdf38f9685cb74974de0592e0e824146d343d))
9
+ * add waas btc support in demo ([#10192](https://github.com/dynamic-labs/dynamic-auth/issues/10192)) ([36aedd6](https://github.com/dynamic-labs/dynamic-auth/commit/36aedd614b7fe781c7150efb4c1a77a5fe55a1ae))
10
+ * merge waas-bitcoin to existing bitcoin package ([#10190](https://github.com/dynamic-labs/dynamic-auth/issues/10190)) ([70dfc6b](https://github.com/dynamic-labs/dynamic-auth/commit/70dfc6baca4f69af56a10ad29faca0fb361ec17b))
11
+ * update sdk-react-core to support btc from waas ([#10191](https://github.com/dynamic-labs/dynamic-auth/issues/10191)) ([c39a99c](https://github.com/dynamic-labs/dynamic-auth/commit/c39a99c544e567a75f43e9b83d4969b70d3c01d1))
12
+
13
+
14
+ ### Bug Fixes
15
+
16
+ * udpate ESM compatibility issues in build scripts for iconic ([#10201](https://github.com/dynamic-labs/dynamic-auth/issues/10201)) ([55059ad](https://github.com/dynamic-labs/dynamic-auth/commit/55059ad8c874b7f04699c277467242783f5d6eff))
17
+
2
18
  ### [4.52.5](https://github.com/dynamic-labs/dynamic-auth/compare/v4.52.4...v4.52.5) (2026-01-08)
3
19
 
4
20
 
package/package.cjs CHANGED
@@ -3,6 +3,6 @@
3
3
 
4
4
  Object.defineProperty(exports, '__esModule', { value: true });
5
5
 
6
- var version = "4.52.5";
6
+ var version = "4.53.0";
7
7
 
8
8
  exports.version = version;
package/package.js CHANGED
@@ -1,4 +1,4 @@
1
1
  'use client'
2
- var version = "4.52.5";
2
+ var version = "4.53.0";
3
3
 
4
4
  export { version };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dynamic-labs/bitcoin",
3
- "version": "4.52.5",
3
+ "version": "4.53.0",
4
4
  "description": "A React SDK for implementing wallet web3 authentication and authorization to your website.",
5
5
  "author": "Dynamic Labs, Inc.",
6
6
  "license": "MIT",
@@ -18,18 +18,23 @@
18
18
  },
19
19
  "homepage": "https://www.dynamic.xyz/",
20
20
  "dependencies": {
21
+ "@dynamic-labs-wallet/browser-wallet-client": "0.0.237",
22
+ "@bitcoinerlab/secp256k1": "1.1.1",
21
23
  "@btckit/types": "0.0.19",
22
24
  "@dynamic-labs/sdk-api-core": "0.0.843",
23
25
  "@wallet-standard/app": "1.0.1",
24
26
  "@wallet-standard/base": "1.0.1",
25
27
  "bitcoinjs-lib": "6.1.5",
28
+ "ecpair": "2.1.0",
26
29
  "sats-connect": "4.2.0",
27
30
  "jsontokens": "4.0.1",
28
- "@dynamic-labs/assert-package-version": "4.52.5",
29
- "@dynamic-labs/types": "4.52.5",
30
- "@dynamic-labs/utils": "4.52.5",
31
- "@dynamic-labs/wallet-book": "4.52.5",
32
- "@dynamic-labs/wallet-connector-core": "4.52.5",
31
+ "@dynamic-labs/assert-package-version": "4.53.0",
32
+ "@dynamic-labs/logger": "4.53.0",
33
+ "@dynamic-labs/types": "4.53.0",
34
+ "@dynamic-labs/utils": "4.53.0",
35
+ "@dynamic-labs/waas": "4.53.0",
36
+ "@dynamic-labs/wallet-book": "4.53.0",
37
+ "@dynamic-labs/wallet-connector-core": "4.53.0",
33
38
  "eventemitter3": "5.0.1"
34
39
  },
35
40
  "peerDependencies": {}
@@ -1,7 +1,7 @@
1
1
  'use client'
2
2
  import { __awaiter } from '../../../_virtual/_tslib.js';
3
3
  import { Psbt } from 'bitcoinjs-lib';
4
- import { BitcoinNetworkType, addListener, request, AddressPurpose, signMultipleTransactions } from 'sats-connect';
4
+ import { BitcoinNetworkType, request, AddressPurpose, signMultipleTransactions, addListener } from 'sats-connect';
5
5
  import { isMobile, template, PlatformService } from '@dynamic-labs/utils';
6
6
  import { logger, eventListenerHandlers } from '@dynamic-labs/wallet-connector-core';
7
7
  import { convertNetworkTypeForPsbt } from '../../utils/psbt/bitcoinNetworkTypeToNetworks.js';
@@ -201,6 +201,14 @@ class BitcoinWalletConnector extends walletConnectorCore.WalletConnectorBase {
201
201
  return undefined;
202
202
  });
203
203
  }
204
+ // not all wallets support buildPsbt method
205
+ // so we have a default implementation that returns undefined
206
+ buildPsbt(transaction) {
207
+ return _tslib.__awaiter(this, void 0, void 0, function* () {
208
+ walletConnectorCore.logger.debug('buildPsbt - function not implemented', transaction);
209
+ return undefined;
210
+ });
211
+ }
204
212
  getProvider() {
205
213
  var _a;
206
214
  return (_a = this.bitcoinProviderHelper) === null || _a === void 0 ? void 0 : _a.getProvider();
@@ -41,6 +41,7 @@ export declare abstract class BitcoinWalletConnector extends WalletConnectorBase
41
41
  setAdditionalAddresses(mainAddress: string, additionalAddresses: WalletAdditionalAddress[]): Promise<void>;
42
42
  sendRawTransaction(rawTransaction: string): Promise<string>;
43
43
  sendBitcoin(transaction: BitcoinTransaction): Promise<string | undefined>;
44
+ buildPsbt(transaction: BitcoinTransaction): Promise<string | undefined>;
44
45
  getProvider<T>(): T & EventEmitter<string | symbol, any>;
45
46
  abstract signPsbt(request: BitcoinSignPsbtRequest): Promise<BitcoinSignPsbtResponse | undefined>;
46
47
  signPsbts(requests: BitcoinSignPsbtRequest[]): Promise<string[] | undefined>;
@@ -1,9 +1,9 @@
1
1
  'use client'
2
2
  import { __awaiter } from '../../_virtual/_tslib.js';
3
3
  import { AddressPurpose } from 'sats-connect';
4
- import { WalletConnectorBase, isConnectorMethodSupported, eventListenerHandlers, logger } from '@dynamic-labs/wallet-connector-core';
4
+ import { WalletConnectorBase, isConnectorMethodSupported, logger, eventListenerHandlers } from '@dynamic-labs/wallet-connector-core';
5
5
  import { getWalletBookWallet } from '@dynamic-labs/wallet-book';
6
- import { isLedgerAddressViaVerifiedCredentials, DynamicError } from '@dynamic-labs/utils';
6
+ import { DynamicError, isLedgerAddressViaVerifiedCredentials } from '@dynamic-labs/utils';
7
7
  import { WalletAddressType } from '@dynamic-labs/sdk-api-core';
8
8
  import { BitcoinLocalStorageCache } from '../BitcoinLocalStorageCache.js';
9
9
  import { BitcoinProviderHelper } from '../bitcoinProviderHelper.js';
@@ -197,6 +197,14 @@ class BitcoinWalletConnector extends WalletConnectorBase {
197
197
  return undefined;
198
198
  });
199
199
  }
200
+ // not all wallets support buildPsbt method
201
+ // so we have a default implementation that returns undefined
202
+ buildPsbt(transaction) {
203
+ return __awaiter(this, void 0, void 0, function* () {
204
+ logger.debug('buildPsbt - function not implemented', transaction);
205
+ return undefined;
206
+ });
207
+ }
200
208
  getProvider() {
201
209
  var _a;
202
210
  return (_a = this.bitcoinProviderHelper) === null || _a === void 0 ? void 0 : _a.getProvider();
@@ -0,0 +1,464 @@
1
+ 'use client'
2
+ 'use strict';
3
+
4
+ Object.defineProperty(exports, '__esModule', { value: true });
5
+
6
+ var _tslib = require('../../../_virtual/_tslib.cjs');
7
+ var sdkApiCore = require('@dynamic-labs/sdk-api-core');
8
+ var logger$1 = require('@dynamic-labs/logger');
9
+ var utils = require('@dynamic-labs/utils');
10
+ var waas = require('@dynamic-labs/waas');
11
+ var walletConnectorCore = require('@dynamic-labs/wallet-connector-core');
12
+ var BitcoinWalletConnector = require('../BitcoinWalletConnector.cjs');
13
+ var MempoolApiService = require('../../services/MempoolApiService.cjs');
14
+ var PsbtBuilderService = require('../../services/PsbtBuilderService.cjs');
15
+ var PsbtParser = require('../../utils/psbtParser/PsbtParser.cjs');
16
+ require('sats-connect');
17
+ require('bitcoinjs-lib');
18
+ require('jsontokens');
19
+ var btcToSatoshis = require('../../utils/btcToSatoshis/btcToSatoshis.cjs');
20
+
21
+ const logger = new logger$1.Logger('DynamicWaasConnector');
22
+ /**
23
+ * Bitcoin connector for Dynamic WaaS (Wallet as a Service)
24
+ * Extends BitcoinWalletConnector with WaaS functionality for Bitcoin transactions
25
+ */
26
+ class DynamicWaasBitcoinConnector extends waas.withDynamicWaas(BitcoinWalletConnector.BitcoinWalletConnector) {
27
+ // Override the key getter to avoid undefined name issues
28
+ get key() {
29
+ return this.overrideKey || 'dynamicwaas';
30
+ }
31
+ /**
32
+ * @param props - Constructor properties including walletUiUtils
33
+ */
34
+ constructor(props) {
35
+ super(props);
36
+ this.name = 'Dynamic Waas';
37
+ this.logger = logger;
38
+ this.overrideKey = 'dynamicwaas';
39
+ this.isEmbeddedWallet = true;
40
+ this.connectedChain = 'BTC';
41
+ this.walletUiUtils = props.walletUiUtils;
42
+ this.mempoolApiService = new MempoolApiService.MempoolApiService();
43
+ this.psbtBuilderService = new PsbtBuilderService.PsbtBuilderService(this.mempoolApiService);
44
+ }
45
+ set verifiedCredential(verifiedCredential) {
46
+ this._verifiedCredential = verifiedCredential;
47
+ }
48
+ get verifiedCredential() {
49
+ return this._verifiedCredential;
50
+ }
51
+ /**
52
+ * Override setVerifiedCredentials to filter and set Bitcoin WaaS credentials
53
+ * Filters for credentials with walletName === 'dynamicwaas' and chain === 'bip122'
54
+ * The base class already has verifiedCredentials property, so we just filter and set it
55
+ */
56
+ setVerifiedCredentials(verifiedCredentials) {
57
+ const dynamicWaasBitcoinVerifiedCredentials = verifiedCredentials === null || verifiedCredentials === void 0 ? void 0 : verifiedCredentials.reduce((acc, vc) => {
58
+ if (vc.walletName === 'dynamicwaas' && vc.chain === 'bip122') {
59
+ acc.push(vc);
60
+ }
61
+ return acc;
62
+ }, []);
63
+ const [dynamicWaasBitcoinVerifiedCredential] = dynamicWaasBitcoinVerifiedCredentials;
64
+ const didDynamicWaasBitcoinVerifiedCredentialsChanged = JSON.stringify(this.verifiedCredentials) !==
65
+ JSON.stringify(dynamicWaasBitcoinVerifiedCredentials);
66
+ if (!didDynamicWaasBitcoinVerifiedCredentialsChanged) {
67
+ return;
68
+ }
69
+ // Set the filtered credentials using the base class property
70
+ this.verifiedCredentials = dynamicWaasBitcoinVerifiedCredentials;
71
+ // Set the primary credential
72
+ this.verifiedCredential = dynamicWaasBitcoinVerifiedCredential;
73
+ }
74
+ /**
75
+ * Gets the active wallet address
76
+ * Falls back to verified credential address if no active account is set
77
+ * @returns The wallet address or undefined
78
+ * @throws {DynamicError} If no active wallet address is found
79
+ */
80
+ getAddress() {
81
+ return _tslib.__awaiter(this, void 0, void 0, function* () {
82
+ var _a;
83
+ const activeAccount = this.getActiveAccount();
84
+ if (!activeAccount || !activeAccount.address) {
85
+ if ((_a = this.verifiedCredential) === null || _a === void 0 ? void 0 : _a.address) {
86
+ const { address } = this.verifiedCredential;
87
+ this.setActiveAccount(address);
88
+ return address;
89
+ }
90
+ throw new utils.DynamicError('No active wallet address found');
91
+ }
92
+ return activeAccount.address;
93
+ });
94
+ }
95
+ /**
96
+ * Gets all connected account addresses
97
+ * @returns Array of connected account addresses (currently returns single active address)
98
+ */
99
+ getConnectedAccounts() {
100
+ return _tslib.__awaiter(this, void 0, void 0, function* () {
101
+ if (!this.activeAccountAddress) {
102
+ return [];
103
+ }
104
+ return [this.activeAccountAddress];
105
+ });
106
+ }
107
+ /**
108
+ * Gets the current Bitcoin network
109
+ * @returns The network name ('mainnet' for Bitcoin)
110
+ */
111
+ getNetwork() {
112
+ return _tslib.__awaiter(this, void 0, void 0, function* () {
113
+ return 'mainnet';
114
+ });
115
+ }
116
+ /**
117
+ * Signs a message using the wallet UI utils for user interaction
118
+ * @param message - The message to sign
119
+ * @returns The signed message as a string
120
+ */
121
+ signMessage(message) {
122
+ return _tslib.__awaiter(this, void 0, void 0, function* () {
123
+ return this.walletUiUtils.signMessage({
124
+ handler: () => _tslib.__awaiter(this, void 0, void 0, function* () { return this.internalSignMessage(message); }),
125
+ message,
126
+ walletConnector: this,
127
+ });
128
+ });
129
+ }
130
+ /**
131
+ * Signs a Partially Signed Bitcoin Transaction (PSBT)
132
+ * @param request - The PSBT signing request containing the unsigned PSBT
133
+ * @returns The signed PSBT response
134
+ * @throws {DynamicError} If active account address is not set
135
+ * @throws {DynamicError} If signed session ID is not available or signature is provided
136
+ */
137
+ signPsbt(request) {
138
+ return _tslib.__awaiter(this, void 0, void 0, function* () {
139
+ var _a, _b, _c;
140
+ const walletClient = yield this.getWaasWalletClient();
141
+ if (!this.activeAccountAddress) {
142
+ throw new utils.DynamicError('Active account address is required');
143
+ }
144
+ const signedSessionId = yield ((_a = this.getSignedSessionId) === null || _a === void 0 ? void 0 : _a.call(this));
145
+ if (!signedSessionId) {
146
+ throw new utils.DynamicError('Signed session ID is required');
147
+ }
148
+ const mfaToken = yield ((_b = this.getMfaToken) === null || _b === void 0 ? void 0 : _b.call(this, {
149
+ mfaAction: sdkApiCore.MFAAction.WalletWaasSign,
150
+ }));
151
+ if (request.signature && request.signature.length > 0) {
152
+ throw new utils.DynamicError('Signature is not supported for waas at the moment');
153
+ }
154
+ const signedTransaction = yield walletClient.signTransaction({
155
+ authToken: (_c = this.getAuthToken) === null || _c === void 0 ? void 0 : _c.call(this),
156
+ mfaToken,
157
+ senderAddress: this.activeAccountAddress,
158
+ signedSessionId,
159
+ transaction: request.unsignedPsbtBase64,
160
+ });
161
+ return {
162
+ signedPsbt: signedTransaction,
163
+ };
164
+ });
165
+ }
166
+ /**
167
+ * Sends a raw Bitcoin transaction to the mempool
168
+ * @param rawTransaction - The raw transaction in hex format
169
+ * @returns The transaction ID
170
+ * @throws {DynamicError} If no transaction is specified or sending fails
171
+ */
172
+ sendRawTransaction(rawTransaction) {
173
+ return _tslib.__awaiter(this, void 0, void 0, function* () {
174
+ if (!this.activeAccountAddress) {
175
+ throw new utils.DynamicError('Active account address is required');
176
+ }
177
+ return this.mempoolApiService.sendRawTransaction(this.activeAccountAddress, rawTransaction);
178
+ });
179
+ }
180
+ /**
181
+ * Sends Bitcoin to a recipient address
182
+ * This method combines buildPsbt, signPsbt, and sendRawTransaction into a single flow
183
+ * @param transaction - The Bitcoin transaction containing recipient address and amount
184
+ * @returns The transaction ID
185
+ * @throws {DynamicError} If any step in the process fails
186
+ */
187
+ sendBitcoin(transaction) {
188
+ return _tslib.__awaiter(this, void 0, void 0, function* () {
189
+ if (!this.activeAccountAddress) {
190
+ throw new utils.DynamicError('Active account address is required');
191
+ }
192
+ // Step 1: Build the PSBT
193
+ const unsignedPsbt = yield this.buildPsbt(transaction);
194
+ // Step 2: Sign the PSBT
195
+ // SIGHASH_ALL (0x01) is the most common sighash type for Bitcoin transactions (Eventually can be configurable)
196
+ const signedPsbtResponse = yield this.signPsbt({
197
+ allowedSighash: [0x01],
198
+ unsignedPsbtBase64: unsignedPsbt,
199
+ });
200
+ if (!signedPsbtResponse) {
201
+ throw new utils.DynamicError('Failed to sign PSBT');
202
+ }
203
+ // Step 3: Convert signed PSBT to raw transaction
204
+ const signedTransactionHex = signedPsbtResponse.signedPsbt;
205
+ // Step 4: Send the raw transaction
206
+ return this.sendRawTransaction(signedTransactionHex);
207
+ });
208
+ }
209
+ /**
210
+ * Creates a new Bitcoin wallet account with Bitcoin-specific defaults
211
+ * @param thresholdSignatureScheme - The threshold signature scheme (default: 'TWO_OF_TWO')
212
+ * @param password - Optional password for the wallet
213
+ * @param bitcoinConfig - Bitcoin configuration (required for Bitcoin)
214
+ * @returns The created wallet account information
215
+ */
216
+ createWalletAccount() {
217
+ const _super = Object.create(null, {
218
+ createWalletAccount: { get: () => super.createWalletAccount }
219
+ });
220
+ return _tslib.__awaiter(this, arguments, void 0, function* ({ thresholdSignatureScheme = 'TWO_OF_TWO', password, bitcoinConfig, } = {}) {
221
+ if (!bitcoinConfig || !bitcoinConfig.addressType) {
222
+ throw new utils.DynamicError('Bitcoin config with address type is required for Bitcoin');
223
+ }
224
+ const finalBitcoinConfig = {
225
+ addressType: bitcoinConfig.addressType,
226
+ network: yield this.getNetwork(),
227
+ };
228
+ return _super.createWalletAccount.call(this, {
229
+ bitcoinConfig: finalBitcoinConfig,
230
+ password,
231
+ thresholdSignatureScheme,
232
+ });
233
+ });
234
+ }
235
+ /**
236
+ * Override importPrivateKey to require and validate addressType for Bitcoin
237
+ * @param privateKey - The private key to import (WIF format for Bitcoin)
238
+ * @param thresholdSignatureScheme - The threshold signature scheme (default: 'TWO_OF_TWO')
239
+ * @param publicAddressCheck - Optional public address to verify against
240
+ * @param addressType - Required address type for Bitcoin ('native_segwit' or 'taproot')
241
+ * @throws {DynamicError} If addressType is missing or invalid for BTC
242
+ */
243
+ importPrivateKey(_a) {
244
+ const _super = Object.create(null, {
245
+ importPrivateKey: { get: () => super.importPrivateKey }
246
+ });
247
+ return _tslib.__awaiter(this, arguments, void 0, function* ({ privateKey, thresholdSignatureScheme = 'TWO_OF_TWO', publicAddressCheck, addressType, }) {
248
+ if (!addressType) {
249
+ throw new utils.DynamicError('addressType is required for BTC importPrivateKey');
250
+ }
251
+ const validAddressTypes = ['native_segwit', 'taproot'];
252
+ if (!validAddressTypes.includes(addressType)) {
253
+ throw new utils.DynamicError(`Invalid addressType: ${addressType}. Must be one of: ${validAddressTypes.join(', ')}`);
254
+ }
255
+ return _super.importPrivateKey.call(this, {
256
+ addressType,
257
+ privateKey,
258
+ publicAddressCheck,
259
+ thresholdSignatureScheme,
260
+ });
261
+ });
262
+ }
263
+ /**
264
+ * Gets the wallet client for a specific account address and sets it as active
265
+ * @param accountAddress - The Bitcoin account address
266
+ * @returns The WaaS wallet client instance
267
+ */
268
+ getWalletClientByAddress({ accountAddress }) {
269
+ this.setActiveAccountAddress(accountAddress);
270
+ return this.getWaasWalletClient();
271
+ }
272
+ /**
273
+ * Gets the currently active account address
274
+ * @returns The active account address or undefined if not set
275
+ */
276
+ getActiveAccountAddress() {
277
+ return _tslib.__awaiter(this, void 0, void 0, function* () {
278
+ return this.activeAccountAddress;
279
+ });
280
+ }
281
+ /**
282
+ * Validates that the expected wallet address matches the active wallet
283
+ * Updates the active account address if it doesn't match
284
+ * @param expectedAddress - The expected wallet address to validate
285
+ * @throws {DynamicError} If signed session ID is not available or account is not found
286
+ */
287
+ validateActiveWallet(expectedAddress) {
288
+ return _tslib.__awaiter(this, void 0, void 0, function* () {
289
+ var _a, _b;
290
+ const walletClient = yield this.getWaasWalletClient();
291
+ const signedSessionId = yield ((_a = this.getSignedSessionId) === null || _a === void 0 ? void 0 : _a.call(this));
292
+ if (!signedSessionId) {
293
+ throw new utils.DynamicError('Signed session ID is required');
294
+ }
295
+ const targetWallet = yield walletClient.getWallet({
296
+ accountAddress: expectedAddress,
297
+ authToken: (_b = this.getAuthToken) === null || _b === void 0 ? void 0 : _b.call(this),
298
+ signedSessionId,
299
+ });
300
+ if (!targetWallet) {
301
+ throw new utils.DynamicError('Account not found');
302
+ }
303
+ const isWalletActive = walletConnectorCore.isSameAddress(targetWallet.accountAddress, this.activeAccountAddress || '', this.connectedChain);
304
+ if (!isWalletActive) {
305
+ this.activeAccountAddress = targetWallet.accountAddress;
306
+ }
307
+ });
308
+ }
309
+ /**
310
+ * Signs a message with additional context information
311
+ * @param message - The message to sign (string or object with raw property)
312
+ * @param context - Additional context for the message signing
313
+ * @returns The signed message as a string
314
+ * @throws {DynamicError} If active account address is not set
315
+ * @throws {DynamicError} If signed session ID is not available
316
+ */
317
+ signMessageWithContext(_a) {
318
+ return _tslib.__awaiter(this, arguments, void 0, function* ({ message, context, }) {
319
+ var _b, _c;
320
+ const walletClient = yield this.getWaasWalletClient();
321
+ if (!this.activeAccountAddress) {
322
+ throw new utils.DynamicError('Active account address is required');
323
+ }
324
+ const signedSessionId = yield ((_b = this.getSignedSessionId) === null || _b === void 0 ? void 0 : _b.call(this));
325
+ if (!signedSessionId) {
326
+ throw new utils.DynamicError('Signed session ID is required');
327
+ }
328
+ const messageString = typeof message === 'string' ? message : message.raw;
329
+ return walletClient.signMessage({
330
+ accountAddress: this.activeAccountAddress,
331
+ authToken: (_c = this.getAuthToken) === null || _c === void 0 ? void 0 : _c.call(this),
332
+ context,
333
+ message: messageString,
334
+ signedSessionId,
335
+ });
336
+ });
337
+ }
338
+ /**
339
+ * Builds a PSBT for a Bitcoin transaction with real UTXOs
340
+ * @param transaction - The Bitcoin transaction containing recipient address and amount in satoshis to send
341
+ * @returns A PSBT in Base64 format
342
+ * @throws {DynamicError} If no active account address, insufficient funds, or other errors
343
+ */
344
+ buildPsbt(transaction) {
345
+ return _tslib.__awaiter(this, void 0, void 0, function* () {
346
+ if (!this.activeAccountAddress) {
347
+ throw new utils.DynamicError('Active account address is required');
348
+ }
349
+ const publicKeyHex = yield this.getPublicKey();
350
+ const buildOptions = PsbtBuilderService.PsbtBuilderService.createBuildOptions(this.activeAccountAddress, transaction, publicKeyHex);
351
+ return this.psbtBuilderService.buildPsbt(buildOptions);
352
+ });
353
+ }
354
+ /**
355
+ * Parse a PSBT or finalized transaction and extract transaction information
356
+ * Auto-detects format (hex/base64) and type (PSBT/finalized transaction)
357
+ * @param psbtInput - The PSBT or finalized transaction in Base64 or hex format
358
+ * @returns Parsed transaction data with inputs and outputs, or null if parsing fails
359
+ */
360
+ parsePsbt(psbtInput) {
361
+ return PsbtParser.PsbtParser.parsePsbt(psbtInput);
362
+ }
363
+ /**
364
+ * Parse a PSBT or finalized transaction from hex format
365
+ * @param psbtHex - The PSBT or finalized transaction in hex format
366
+ * @returns Parsed transaction data with inputs and outputs, or null if parsing fails
367
+ */
368
+ parseHexPsbt(psbtHex) {
369
+ return PsbtParser.PsbtParser.parseHexPsbt(psbtHex);
370
+ }
371
+ /**
372
+ * Parse a PSBT or finalized transaction from base64 format
373
+ * @param psbtBase64 - The PSBT or finalized transaction in base64 format
374
+ * @returns Parsed transaction data with inputs and outputs, or null if parsing fails
375
+ */
376
+ parseBase64Psbt(psbtBase64) {
377
+ return PsbtParser.PsbtParser.parseBase64Psbt(psbtBase64);
378
+ }
379
+ /**
380
+ * Gets the public key for the active account
381
+ * Falls back to the account address if public key retrieval fails
382
+ * @returns The public key or account address as fallback
383
+ * @throws {DynamicError} If no active account address is set
384
+ * @throws {DynamicError} If signed session ID is not available
385
+ */
386
+ getPublicKey() {
387
+ return _tslib.__awaiter(this, void 0, void 0, function* () {
388
+ var _a;
389
+ if (!this.activeAccountAddress) {
390
+ throw new utils.DynamicError('No active account address');
391
+ }
392
+ const allCredentials = (_a = this.verifiedCredentials) !== null && _a !== void 0 ? _a : [];
393
+ if (allCredentials.length === 0) {
394
+ throw new utils.DynamicError(`No verified credentials found. The address ${this.activeAccountAddress} may not be properly registered.`);
395
+ }
396
+ for (const credential of allCredentials) {
397
+ const { walletAdditionalAddresses } = credential !== null && credential !== void 0 ? credential : {};
398
+ if (!walletAdditionalAddresses) {
399
+ continue;
400
+ }
401
+ const additionalAddress = walletAdditionalAddresses.find((address) => address.address === this.activeAccountAddress);
402
+ if (additionalAddress === null || additionalAddress === void 0 ? void 0 : additionalAddress.publicKey) {
403
+ return additionalAddress.publicKey;
404
+ }
405
+ }
406
+ const allAvailableAddresses = allCredentials
407
+ .flatMap((cred) => { var _a; return (_a = cred.walletAdditionalAddresses) !== null && _a !== void 0 ? _a : []; })
408
+ .map((addr) => addr.address)
409
+ .join(', ');
410
+ throw new utils.DynamicError(`No additional address found for ${this.activeAccountAddress}. Available addresses: ${allAvailableAddresses || 'none'}`);
411
+ });
412
+ }
413
+ /**
414
+ * Helper function to convert BTC amount to satoshis
415
+ * @param btcAmount - The Bitcoin amount to convert (number)
416
+ * @returns The amount in satoshis as a BigInt
417
+ * @throws {DynamicError} If the amount is negative
418
+ */
419
+ btcToSatoshis(btcAmount) {
420
+ return btcToSatoshis.btcToSatoshis(btcAmount);
421
+ }
422
+ /**
423
+ * Sets the active account address for this connector
424
+ * @param accountAddress - The Bitcoin account address to set as active
425
+ */
426
+ setActiveAccountAddress(accountAddress) {
427
+ this.activeAccountAddress = accountAddress;
428
+ }
429
+ /**
430
+ * Internal method to sign a message with MFA token
431
+ * @param message - The message to sign
432
+ * @returns The signed message as a string
433
+ * @throws {DynamicError} If active account address is not set
434
+ * @throws {DynamicError} If signed session ID is not available
435
+ */
436
+ internalSignMessage(message) {
437
+ return _tslib.__awaiter(this, void 0, void 0, function* () {
438
+ var _a, _b, _c;
439
+ const walletClient = yield this.getWaasWalletClient();
440
+ if (!this.activeAccountAddress) {
441
+ throw new utils.DynamicError('Active account address is required');
442
+ }
443
+ const signedSessionId = yield ((_a = this.getSignedSessionId) === null || _a === void 0 ? void 0 : _a.call(this));
444
+ if (!signedSessionId) {
445
+ throw new utils.DynamicError('Signed session ID is required');
446
+ }
447
+ const mfaToken = yield ((_b = this.getMfaToken) === null || _b === void 0 ? void 0 : _b.call(this, {
448
+ mfaAction: sdkApiCore.MFAAction.WalletWaasSign,
449
+ }));
450
+ return walletClient.signMessage({
451
+ accountAddress: this.activeAccountAddress,
452
+ authToken: (_c = this.getAuthToken) === null || _c === void 0 ? void 0 : _c.call(this),
453
+ bitcoinConfig: {
454
+ network: yield this.getNetwork(),
455
+ },
456
+ message,
457
+ mfaToken,
458
+ signedSessionId,
459
+ });
460
+ });
461
+ }
462
+ }
463
+
464
+ exports.DynamicWaasBitcoinConnector = DynamicWaasBitcoinConnector;