@dynamic-labs/bitcoin 3.0.0-alpha.6 → 3.0.0-alpha.60

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 (42) hide show
  1. package/CHANGELOG.md +585 -0
  2. package/package.json +5 -5
  3. package/src/BitcoinLocalStorageCache.cjs +0 -16
  4. package/src/BitcoinLocalStorageCache.d.ts +0 -7
  5. package/src/BitcoinLocalStorageCache.js +0 -16
  6. package/src/connectors/BitcoinSatsConnectConnector/BitcoinSatsConnectConnector.cjs +70 -23
  7. package/src/connectors/BitcoinSatsConnectConnector/BitcoinSatsConnectConnector.d.ts +4 -2
  8. package/src/connectors/BitcoinSatsConnectConnector/BitcoinSatsConnectConnector.js +71 -24
  9. package/src/connectors/BitcoinWalletConnector.cjs +64 -31
  10. package/src/connectors/BitcoinWalletConnector.d.ts +13 -5
  11. package/src/connectors/BitcoinWalletConnector.js +65 -32
  12. package/src/connectors/FallbackBitcoinConnector/FallbackBitcoinConnector.cjs +7 -1
  13. package/src/connectors/FallbackBitcoinConnector/FallbackBitcoinConnector.d.ts +1 -1
  14. package/src/connectors/FallbackBitcoinConnector/FallbackBitcoinConnector.js +7 -1
  15. package/src/connectors/OkxConnector/OkxConnector.cjs +19 -2
  16. package/src/connectors/OkxConnector/OkxConnector.d.ts +1 -1
  17. package/src/connectors/OkxConnector/OkxConnector.js +19 -2
  18. package/src/connectors/PhantomConnector/PhantomConnector.cjs +13 -9
  19. package/src/connectors/PhantomConnector/PhantomConnector.d.ts +1 -1
  20. package/src/connectors/PhantomConnector/PhantomConnector.js +13 -9
  21. package/src/connectors/UnisatConnector/UnisatConnector.cjs +26 -1
  22. package/src/connectors/UnisatConnector/UnisatConnector.d.ts +2 -1
  23. package/src/connectors/UnisatConnector/UnisatConnector.js +26 -1
  24. package/src/connectors/UnknownInjected/UnknownInjected.cjs +7 -1
  25. package/src/connectors/UnknownInjected/UnknownInjected.d.ts +1 -1
  26. package/src/connectors/UnknownInjected/UnknownInjected.js +7 -1
  27. package/src/index.cjs +4 -0
  28. package/src/index.d.ts +3 -2
  29. package/src/index.js +2 -0
  30. package/src/utils/fetchSatsConnectConnectors/fetchSatsConnectConnectors.cjs +1 -1
  31. package/src/utils/fetchSatsConnectConnectors/fetchSatsConnectConnectors.js +1 -1
  32. package/src/utils/psbt/createSignPsbtOptions.cjs +17 -1
  33. package/src/utils/psbt/createSignPsbtOptions.d.ts +2 -0
  34. package/src/utils/psbt/createSignPsbtOptions.js +17 -2
  35. package/src/wallet/BitcoinWallet.cjs +54 -0
  36. package/src/wallet/BitcoinWallet.d.ts +27 -0
  37. package/src/wallet/BitcoinWallet.js +50 -0
  38. package/src/wallet/index.d.ts +2 -0
  39. package/src/wallet/isBitcoinWallet/index.d.ts +1 -0
  40. package/src/wallet/isBitcoinWallet/isBitcoinWallet.cjs +8 -0
  41. package/src/wallet/isBitcoinWallet/isBitcoinWallet.d.ts +3 -0
  42. package/src/wallet/isBitcoinWallet/isBitcoinWallet.js +4 -0
@@ -2,18 +2,20 @@
2
2
  /// <reference types="node" />
3
3
  import { EventEmitter } from 'stream';
4
4
  import type { Wallet } from '@wallet-standard/base';
5
- import { Chain, IBitcoinWalletConnector, WalletConnectorBase } from '@dynamic-labs/wallet-connector-core';
5
+ import { Chain, IBitcoinWalletConnector, WalletConnectorBase, GetConnectedAccountsOpts } from '@dynamic-labs/wallet-connector-core';
6
6
  import { WalletBookSchema, WalletSchema } from '@dynamic-labs/wallet-book';
7
7
  import { JwtVerifiedCredential, WalletAdditionalAddress } from '@dynamic-labs/sdk-api-core';
8
8
  import { IBitcoinSessionCache } from '../BitcoinLocalStorageCache';
9
9
  import { BitcoinTransaction, BitcoinSignPsbtRequest, BitcoinSignPsbtResponse, BitcoinWalletStandardMethods, ConnectedAccountWithAddressesProps } from '../types';
10
+ import { BitcoinWallet } from '../wallet';
10
11
  export type BitcoinWalletConnectorOpts = {
11
12
  walletBook: WalletBookSchema;
12
13
  walletData: WalletSchema;
13
14
  overrideKey?: string;
14
15
  };
15
- export declare abstract class BitcoinWalletConnector extends WalletConnectorBase implements IBitcoinWalletConnector {
16
+ export declare abstract class BitcoinWalletConnector extends WalletConnectorBase<typeof BitcoinWallet> implements IBitcoinWalletConnector {
16
17
  cache: IBitcoinSessionCache;
18
+ ChainWallet: typeof BitcoinWallet;
17
19
  connectedChain: Chain;
18
20
  supportedChains: Chain[];
19
21
  private getAddressPromise;
@@ -23,23 +25,29 @@ export declare abstract class BitcoinWalletConnector extends WalletConnectorBase
23
25
  canFetchConnectedAccounts: boolean;
24
26
  isHardwareWalletEnabled: boolean;
25
27
  verifiedCredentials: JwtVerifiedCredential[];
28
+ private lastAccountChange;
26
29
  constructor(opts: BitcoinWalletConnectorOpts);
30
+ private isSameAccountChangeRequest;
31
+ private setLastAccountChangeRequest;
27
32
  clearConnectedAccounts(): Promise<void>;
28
33
  canConnectWithHardwareWallet(): boolean;
29
34
  isInstalledOnBrowser(): boolean;
30
35
  getDeepLink(): string | undefined;
31
36
  endSession(): Promise<void>;
32
- getBalance(): Promise<string | undefined>;
37
+ getBalance(address: string): Promise<string | undefined>;
33
38
  getConnectedAccountsFromCache(): Promise<string[]>;
34
- getConnectedAccounts(): Promise<string[]>;
39
+ getConnectedAccounts(options?: GetConnectedAccountsOpts): Promise<string[]>;
35
40
  getAdditionalAddresses(mainAddress?: string): Promise<WalletAdditionalAddress[]>;
36
41
  setAdditionalAddresses(mainAddress: string, additionalAddresses: WalletAdditionalAddress[]): Promise<void>;
37
- sendRawTransaction(rawTransaction: string): Promise<string | undefined>;
42
+ sendRawTransaction(rawTransaction: string): Promise<string>;
38
43
  abstract sendBitcoin(transaction: BitcoinTransaction): Promise<string | undefined>;
39
44
  getProvider<T>(): T & EventEmitter;
40
45
  abstract signPsbt(request: BitcoinSignPsbtRequest): Promise<BitcoinSignPsbtResponse | undefined>;
46
+ signPsbts(requests: BitcoinSignPsbtRequest[]): Promise<string[] | undefined>;
41
47
  setConnectedAccountWithAddresses({ mainAddress, ordinalsAddress, paymentAddress, active, }: ConnectedAccountWithAddressesProps): Promise<void>;
42
48
  setupEventListeners(): void;
43
49
  setVerifiedCredentials(verifiedCredentials: JwtVerifiedCredential[]): void;
44
50
  isLedgerAddress(address: string): boolean;
51
+ proveOwnership(address: string, messageToSign: string): Promise<string | undefined>;
52
+ signMessageWithAddress(messageToSign: string, _address: string): Promise<string | undefined>;
45
53
  }
@@ -1,7 +1,8 @@
1
1
  'use client'
2
2
  import { __awaiter } from '../../_virtual/_tslib.js';
3
+ import { AddressPurpose } from 'sats-connect';
3
4
  import { WalletConnectorBase, eventListenerHandlers, logger } from '@dynamic-labs/wallet-connector-core';
4
- import { getWalletBookWallet, findWalletBookWallet } from '@dynamic-labs/wallet-book';
5
+ import { getWalletBookWallet, isWalletMethodSupported, findWalletBookWallet } from '@dynamic-labs/wallet-book';
5
6
  import { isLedgerAddressViaVerifiedCredentials, DynamicError } from '@dynamic-labs/utils';
6
7
  import { WalletAddressType } from '@dynamic-labs/sdk-api-core';
7
8
  import { BitcoinLocalStorageCache } from '../BitcoinLocalStorageCache.js';
@@ -9,11 +10,13 @@ import { BitcoinProviderHelper } from '../bitcoinProviderHelper.js';
9
10
  import { getMempoolApiUrl } from '../utils/getMempoolApiUrl.js';
10
11
  import { HTTP_STATUS_TOO_MANY_REQUESTS, HTTP_STATUS_NOT_FOUND } from '../const.js';
11
12
  import { satoshisToBtc } from '../utils/satoshisToBtc/satoshisToBtc.js';
13
+ import { BitcoinWallet } from '../wallet/BitcoinWallet.js';
12
14
 
13
15
  class BitcoinWalletConnector extends WalletConnectorBase {
14
16
  constructor(opts) {
15
17
  var _a;
16
18
  super(opts);
19
+ this.ChainWallet = BitcoinWallet;
17
20
  this.connectedChain = 'BTC';
18
21
  this.supportedChains = ['BTC'];
19
22
  // some wallets don't support fetching connected accounts without prompting for a connection
@@ -22,12 +25,20 @@ class BitcoinWalletConnector extends WalletConnectorBase {
22
25
  this.verifiedCredentials = [];
23
26
  // this is the key from the wallet book entry so that we don't purely rely on the normalized name
24
27
  this.overrideKey = (_a = opts.overrideKey) !== null && _a !== void 0 ? _a : this.key;
25
- this.bitcoinProviderHelper = new BitcoinProviderHelper(opts.walletData || getWalletBookWallet(this.walletBook, this.key));
28
+ const walletBookWallet = opts.walletData || getWalletBookWallet(this.walletBook, this.key);
29
+ this.bitcoinProviderHelper = new BitcoinProviderHelper(walletBookWallet);
26
30
  this.wallet = this.bitcoinProviderHelper.findWallet();
27
31
  if (this.wallet) {
28
32
  this.walletMethods = this.bitcoinProviderHelper.getWalletMethods(this.wallet);
29
33
  }
30
34
  this.cache = new BitcoinLocalStorageCache(this.overrideKey);
35
+ this.canFetchConnectedAccounts = isWalletMethodSupported(walletBookWallet, 'getConnectedAccounts', 'browserExtension');
36
+ }
37
+ isSameAccountChangeRequest(to) {
38
+ return this.lastAccountChange === to;
39
+ }
40
+ setLastAccountChangeRequest(to) {
41
+ this.lastAccountChange = to;
31
42
  }
32
43
  clearConnectedAccounts() {
33
44
  return __awaiter(this, void 0, void 0, function* () {
@@ -49,34 +60,17 @@ class BitcoinWalletConnector extends WalletConnectorBase {
49
60
  }
50
61
  endSession() {
51
62
  return __awaiter(this, void 0, void 0, function* () {
52
- yield Promise.all([
53
- this.cache.clearConnectedAcccounts(),
54
- this.cache.clearLastBalance(),
55
- ]);
63
+ yield this.cache.clearConnectedAcccounts();
56
64
  });
57
65
  }
58
- getBalance() {
66
+ getBalance(address) {
59
67
  return __awaiter(this, void 0, void 0, function* () {
60
- var _a, _b;
61
- const [connectedAddress] = yield this.getConnectedAccounts();
62
- if (!connectedAddress) {
63
- throw new DynamicError('getBalance - No connected address found!');
64
- }
65
- const additionalAddresses = yield this.getAdditionalAddresses(connectedAddress);
66
- const ordinalsAdditionalAddress = (_a = additionalAddresses.find((address) => address.type === WalletAddressType.Ordinals)) === null || _a === void 0 ? void 0 : _a.address;
67
- const paymentAdditionalAddress = (_b = additionalAddresses.find((address) => address.type === WalletAddressType.Payment)) === null || _b === void 0 ? void 0 : _b.address;
68
- // Some BTC wallet connectors only have 1 address type. when this is the case, it would always be `ordinals`
69
- // if a BTC walletConnector does NOT have a payment address, just use the ordinal address
70
- const paymentAddress = paymentAdditionalAddress !== null && paymentAdditionalAddress !== void 0 ? paymentAdditionalAddress : ordinalsAdditionalAddress;
71
- if (!paymentAddress) {
72
- throw new DynamicError('getBalance - No payment address found!');
73
- }
74
- const API_URL = getMempoolApiUrl(paymentAddress);
75
- const response = yield fetch(`${API_URL}/address/${paymentAddress}`);
68
+ const API_URL = getMempoolApiUrl(address);
69
+ const response = yield fetch(`${API_URL}/address/${address}`);
76
70
  if (!response.ok) {
77
71
  // if the request fails due to rate limits, return cached value
78
72
  if (response.status === HTTP_STATUS_TOO_MANY_REQUESTS) {
79
- return this.cache.getLastBalance();
73
+ return '0';
80
74
  }
81
75
  // new accounts not yet indexed will return a 404
82
76
  if (response.status === HTTP_STATUS_NOT_FOUND) {
@@ -93,7 +87,6 @@ class BitcoinWalletConnector extends WalletConnectorBase {
93
87
  const unconfirmedBalanceInSats = Number(addressInfo.mempool_stats.funded_txo_sum) -
94
88
  Number(addressInfo.mempool_stats.spent_txo_sum);
95
89
  const balance = satoshisToBtc(confirmedBalanceInSats + unconfirmedBalanceInSats);
96
- yield this.cache.setLastBalance(balance.toString());
97
90
  return balance.toString();
98
91
  });
99
92
  }
@@ -113,12 +106,12 @@ class BitcoinWalletConnector extends WalletConnectorBase {
113
106
  ];
114
107
  });
115
108
  }
116
- getConnectedAccounts() {
109
+ getConnectedAccounts(options) {
117
110
  return __awaiter(this, void 0, void 0, function* () {
118
111
  // some wallets like xverse don't support fetching connected accounts
119
112
  // without prompting for a connection
120
113
  // to avoid this behavior, we cache the connected accounts
121
- if (!this.canFetchConnectedAccounts) {
114
+ if (!this.canFetchConnectedAccounts && !(options === null || options === void 0 ? void 0 : options.forceFetch)) {
122
115
  return this.getConnectedAccountsFromCache();
123
116
  }
124
117
  // if we decide that is ok to prompt for a connection when fetching connected accounts
@@ -160,11 +153,12 @@ class BitcoinWalletConnector extends WalletConnectorBase {
160
153
  }
161
154
  sendRawTransaction(rawTransaction) {
162
155
  return __awaiter(this, void 0, void 0, function* () {
163
- if (!rawTransaction)
164
- return;
156
+ if (!rawTransaction) {
157
+ throw new DynamicError('No transaction specified!');
158
+ }
165
159
  const [connectedAddress] = yield this.getConnectedAccounts();
166
160
  if (!connectedAddress) {
167
- throw new DynamicError('sendRawTransaction - No connected address found!');
161
+ throw new DynamicError('No connected address found!');
168
162
  }
169
163
  const API_URL = getMempoolApiUrl(connectedAddress);
170
164
  const response = yield fetch(`${API_URL}/tx`, {
@@ -190,6 +184,18 @@ class BitcoinWalletConnector extends WalletConnectorBase {
190
184
  var _a;
191
185
  return (_a = this.bitcoinProviderHelper) === null || _a === void 0 ? void 0 : _a.getProvider();
192
186
  }
187
+ signPsbts(requests) {
188
+ return __awaiter(this, void 0, void 0, function* () {
189
+ const signedPsbtResponses = [];
190
+ for (const request of requests) {
191
+ const signedPsbtResponse = yield this.signPsbt(request);
192
+ if (signedPsbtResponse) {
193
+ signedPsbtResponses.push(signedPsbtResponse);
194
+ }
195
+ }
196
+ return signedPsbtResponses.map((response) => response.signedPsbt);
197
+ });
198
+ }
193
199
  setConnectedAccountWithAddresses(_a) {
194
200
  return __awaiter(this, arguments, void 0, function* ({ mainAddress, ordinalsAddress, paymentAddress, active, }) {
195
201
  if (!mainAddress) {
@@ -224,18 +230,33 @@ class BitcoinWalletConnector extends WalletConnectorBase {
224
230
  const { handleAccountChange, handleChainChange, handleDisconnect } = eventListenerHandlers(this);
225
231
  const handleBitcoinAccountChange = (accounts) => __awaiter(this, void 0, void 0, function* () {
226
232
  let connectedAccounts = accounts;
233
+ let ordinalsAccount, paymentAccount;
227
234
  // if accounts is an array of objects, we need to parse them to return only addresses
228
235
  // since ordinals is the main address we use, we should return it as the first address
229
236
  if (typeof accounts[0] === 'object') {
230
237
  connectedAccounts = accounts
231
- .sort((account) => (account.purpose === 'ordinals' ? -1 : 1))
238
+ .sort((account) => account.purpose === AddressPurpose.Ordinals ? -1 : 1)
232
239
  .map((account) => account.address);
240
+ [ordinalsAccount, paymentAccount] = connectedAccounts;
233
241
  }
234
242
  const currentConnectedAccounts = yield this.getConnectedAccountsFromCache();
235
243
  // don't do anything if the connected accounts haven't changed
236
- if (currentConnectedAccounts[0] === connectedAccounts[0]) {
244
+ // or if the account change request is the same as previous request
245
+ if (currentConnectedAccounts[0] === connectedAccounts[0] ||
246
+ this.isSameAccountChangeRequest(connectedAccounts[0])) {
237
247
  return;
238
248
  }
249
+ // set the last account change request with the from and to addresses
250
+ // to ensure that the requests are not duplicated
251
+ this.setLastAccountChangeRequest(connectedAccounts[0]);
252
+ if (ordinalsAccount || paymentAccount) {
253
+ this.setConnectedAccountWithAddresses({
254
+ active: true,
255
+ mainAddress: ordinalsAccount !== null && ordinalsAccount !== void 0 ? ordinalsAccount : paymentAccount,
256
+ ordinalsAddress: ordinalsAccount,
257
+ paymentAddress: paymentAccount,
258
+ });
259
+ }
239
260
  handleAccountChange(connectedAccounts);
240
261
  });
241
262
  provider.on('accountsChanged', handleBitcoinAccountChange);
@@ -258,6 +279,18 @@ class BitcoinWalletConnector extends WalletConnectorBase {
258
279
  isLedgerAddress(address) {
259
280
  return isLedgerAddressViaVerifiedCredentials(address, this.verifiedCredentials);
260
281
  }
282
+ proveOwnership(address, messageToSign) {
283
+ return __awaiter(this, void 0, void 0, function* () {
284
+ return this.signMessageWithAddress(messageToSign, address);
285
+ });
286
+ }
287
+ signMessageWithAddress(messageToSign,
288
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
289
+ _address) {
290
+ return __awaiter(this, void 0, void 0, function* () {
291
+ return this.signMessage(messageToSign);
292
+ });
293
+ }
261
294
  }
262
295
 
263
296
  export { BitcoinWalletConnector };
@@ -12,7 +12,6 @@ class FallbackBitcoinConnector extends BitcoinWalletConnector.BitcoinWalletConne
12
12
  this.name = 'Fallback Connector';
13
13
  this.overrideKey = 'fallbackconnector';
14
14
  this.isAvailable = false;
15
- this.canFetchConnectedAccounts = false;
16
15
  }
17
16
  getAddress() {
18
17
  return _tslib.__awaiter(this, void 0, void 0, function* () {
@@ -26,6 +25,13 @@ class FallbackBitcoinConnector extends BitcoinWalletConnector.BitcoinWalletConne
26
25
  return;
27
26
  });
28
27
  }
28
+ signPsbts(
29
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
30
+ _requests) {
31
+ return _tslib.__awaiter(this, void 0, void 0, function* () {
32
+ return;
33
+ });
34
+ }
29
35
  sendBitcoin(
30
36
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
31
37
  _transaction) {
@@ -4,9 +4,9 @@ export declare class FallbackBitcoinConnector extends BitcoinWalletConnector {
4
4
  name: string;
5
5
  overrideKey: string;
6
6
  isAvailable: boolean;
7
- canFetchConnectedAccounts: boolean;
8
7
  constructor(opts: BitcoinWalletConnectorOpts);
9
8
  getAddress(): Promise<string | undefined>;
10
9
  signPsbt(_request: BitcoinSignPsbtRequest): Promise<BitcoinSignPsbtResponse | undefined>;
10
+ signPsbts(_requests: BitcoinSignPsbtRequest[]): Promise<string[] | undefined>;
11
11
  sendBitcoin(_transaction: BitcoinTransaction): Promise<string | undefined>;
12
12
  }
@@ -8,7 +8,6 @@ class FallbackBitcoinConnector extends BitcoinWalletConnector {
8
8
  this.name = 'Fallback Connector';
9
9
  this.overrideKey = 'fallbackconnector';
10
10
  this.isAvailable = false;
11
- this.canFetchConnectedAccounts = false;
12
11
  }
13
12
  getAddress() {
14
13
  return __awaiter(this, void 0, void 0, function* () {
@@ -22,6 +21,13 @@ class FallbackBitcoinConnector extends BitcoinWalletConnector {
22
21
  return;
23
22
  });
24
23
  }
24
+ signPsbts(
25
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
26
+ _requests) {
27
+ return __awaiter(this, void 0, void 0, function* () {
28
+ return;
29
+ });
30
+ }
25
31
  sendBitcoin(
26
32
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
27
33
  _transaction) {
@@ -13,7 +13,6 @@ class OkxConnector extends BitcoinWalletConnector.BitcoinWalletConnector {
13
13
  constructor(opts) {
14
14
  super(Object.assign(Object.assign({}, opts), { overrideKey: 'okxwalletbtc' }));
15
15
  this.name = 'OKX Wallet';
16
- this.canFetchConnectedAccounts = true;
17
16
  }
18
17
  get walletBookWallet() {
19
18
  return this.walletBook.wallets[this.key];
@@ -23,7 +22,8 @@ class OkxConnector extends BitcoinWalletConnector.BitcoinWalletConnector {
23
22
  if (!this.isInstalledOnBrowser() &&
24
23
  utils.isMobile() &&
25
24
  this.walletBookWallet.mobile &&
26
- this.walletBookWallet.mobile.inAppBrowser) {
25
+ this.walletBookWallet.mobile.inAppBrowser &&
26
+ this.mobileExperience === 'in-app-browser') {
27
27
  const inAppBrowserCompiledTemplate = utils.template(this.walletBookWallet.mobile.inAppBrowser);
28
28
  const deepLink = inAppBrowserCompiledTemplate({
29
29
  encodedDappURI: encodeURIComponent(window.location.toString()),
@@ -78,6 +78,23 @@ class OkxConnector extends BitcoinWalletConnector.BitcoinWalletConnector {
78
78
  return { signedPsbt: bitcoinjsLib.Psbt.fromHex(signedPsbtHex).toBase64() };
79
79
  });
80
80
  }
81
+ signPsbts(requests) {
82
+ return _tslib.__awaiter(this, void 0, void 0, function* () {
83
+ const provider = this.getProvider();
84
+ if (!provider) {
85
+ return;
86
+ }
87
+ const psbtHexs = [];
88
+ const psbtOptions = [];
89
+ for (const request of requests) {
90
+ const psbt = bitcoinjsLib.Psbt.fromBase64(request.unsignedPsbtBase64);
91
+ psbtHexs.push(psbt.toHex());
92
+ psbtOptions.push(createSignPsbtOptions.createPsbtOptions(psbt, request));
93
+ }
94
+ const signedPsbtHexs = yield provider.signPsbts(psbtHexs, psbtOptions);
95
+ return signedPsbtHexs.map((signedPsbtHex) => bitcoinjsLib.Psbt.fromHex(signedPsbtHex).toBase64());
96
+ });
97
+ }
81
98
  }
82
99
 
83
100
  exports.OkxConnector = OkxConnector;
@@ -2,11 +2,11 @@ import { BitcoinWalletConnector, BitcoinWalletConnectorOpts } from '../BitcoinWa
2
2
  import { BitcoinTransaction, BitcoinSignPsbtRequest, BitcoinSignPsbtResponse } from '../../types';
3
3
  export declare class OkxConnector extends BitcoinWalletConnector {
4
4
  name: string;
5
- canFetchConnectedAccounts: boolean;
6
5
  constructor(opts: BitcoinWalletConnectorOpts);
7
6
  private get walletBookWallet();
8
7
  getAddress(): Promise<string | undefined>;
9
8
  signMessage(messageToSign: string): Promise<string | undefined>;
10
9
  sendBitcoin(transaction: BitcoinTransaction): Promise<string | undefined>;
11
10
  signPsbt(request: BitcoinSignPsbtRequest): Promise<BitcoinSignPsbtResponse | undefined>;
11
+ signPsbts(requests: BitcoinSignPsbtRequest[]): Promise<string[] | undefined>;
12
12
  }
@@ -9,7 +9,6 @@ class OkxConnector extends BitcoinWalletConnector {
9
9
  constructor(opts) {
10
10
  super(Object.assign(Object.assign({}, opts), { overrideKey: 'okxwalletbtc' }));
11
11
  this.name = 'OKX Wallet';
12
- this.canFetchConnectedAccounts = true;
13
12
  }
14
13
  get walletBookWallet() {
15
14
  return this.walletBook.wallets[this.key];
@@ -19,7 +18,8 @@ class OkxConnector extends BitcoinWalletConnector {
19
18
  if (!this.isInstalledOnBrowser() &&
20
19
  isMobile() &&
21
20
  this.walletBookWallet.mobile &&
22
- this.walletBookWallet.mobile.inAppBrowser) {
21
+ this.walletBookWallet.mobile.inAppBrowser &&
22
+ this.mobileExperience === 'in-app-browser') {
23
23
  const inAppBrowserCompiledTemplate = template(this.walletBookWallet.mobile.inAppBrowser);
24
24
  const deepLink = inAppBrowserCompiledTemplate({
25
25
  encodedDappURI: encodeURIComponent(window.location.toString()),
@@ -74,6 +74,23 @@ class OkxConnector extends BitcoinWalletConnector {
74
74
  return { signedPsbt: Psbt.fromHex(signedPsbtHex).toBase64() };
75
75
  });
76
76
  }
77
+ signPsbts(requests) {
78
+ return __awaiter(this, void 0, void 0, function* () {
79
+ const provider = this.getProvider();
80
+ if (!provider) {
81
+ return;
82
+ }
83
+ const psbtHexs = [];
84
+ const psbtOptions = [];
85
+ for (const request of requests) {
86
+ const psbt = Psbt.fromBase64(request.unsignedPsbtBase64);
87
+ psbtHexs.push(psbt.toHex());
88
+ psbtOptions.push(createPsbtOptions(psbt, request));
89
+ }
90
+ const signedPsbtHexs = yield provider.signPsbts(psbtHexs, psbtOptions);
91
+ return signedPsbtHexs.map((signedPsbtHex) => Psbt.fromHex(signedPsbtHex).toBase64());
92
+ });
93
+ }
77
94
  }
78
95
 
79
96
  export { OkxConnector };
@@ -17,7 +17,6 @@ class PhantomConnector extends BitcoinWalletConnector.BitcoinWalletConnector {
17
17
  constructor(opts) {
18
18
  super(Object.assign(Object.assign({}, opts), { overrideKey: 'phantombtc' }));
19
19
  this.name = 'Phantom';
20
- this.canFetchConnectedAccounts = true;
21
20
  }
22
21
  connectWithInstalledExtension() {
23
22
  return _tslib.__awaiter(this, void 0, void 0, function* () {
@@ -27,7 +26,7 @@ class PhantomConnector extends BitcoinWalletConnector.BitcoinWalletConnector {
27
26
  const { accounts } = yield this.walletMethods.connect();
28
27
  const parsedAccounts = accounts.map((account) => ({
29
28
  address: account.address,
30
- publicKey: Buffer.from(account.publicKey).toString('base64'),
29
+ publicKey: Buffer.from(account.publicKey).toString('hex'),
31
30
  }));
32
31
  [paymentAccount, ordinalsAccount] = parsedAccounts;
33
32
  // in case it only returns one account, we will use it as both payment and ordinals
@@ -68,17 +67,13 @@ class PhantomConnector extends BitcoinWalletConnector.BitcoinWalletConnector {
68
67
  return undefined;
69
68
  });
70
69
  }
71
- signMessage(messageToSign) {
70
+ signMessageWithAddress(messageToSign, address) {
72
71
  return _tslib.__awaiter(this, void 0, void 0, function* () {
73
72
  var _a;
74
- const [walletAddress] = yield this.getConnectedAccounts();
75
- if (!walletAddress) {
76
- return;
77
- }
78
73
  if ((_a = this.walletMethods) === null || _a === void 0 ? void 0 : _a.signMessage) {
79
74
  const [result] = yield this.walletMethods.signMessage({
80
75
  // we need to sign with the ordinals account
81
- account: { address: walletAddress },
76
+ account: { address },
82
77
  message: new TextEncoder().encode(messageToSign),
83
78
  });
84
79
  return Buffer.from(result.signature).toString('base64');
@@ -88,11 +83,20 @@ class PhantomConnector extends BitcoinWalletConnector.BitcoinWalletConnector {
88
83
  if (!provider) {
89
84
  return;
90
85
  }
91
- const result = yield provider.signMessage(walletAddress, new TextEncoder().encode(messageToSign));
86
+ const result = yield provider.signMessage(address, new TextEncoder().encode(messageToSign));
92
87
  return Buffer.from(result.signature).toString('base64');
93
88
  }
94
89
  });
95
90
  }
91
+ signMessage(messageToSign) {
92
+ return _tslib.__awaiter(this, void 0, void 0, function* () {
93
+ const [walletAddress] = yield this.getConnectedAccounts();
94
+ if (!walletAddress) {
95
+ return;
96
+ }
97
+ return this.signMessageWithAddress(messageToSign, walletAddress);
98
+ });
99
+ }
96
100
  sendBitcoin(transaction) {
97
101
  return _tslib.__awaiter(this, void 0, void 0, function* () {
98
102
  walletConnectorCore.logger.debug('sendBitcoin - function not implemented', transaction);
@@ -2,10 +2,10 @@ import { BitcoinTransaction, BitcoinSignPsbtRequest, BitcoinSignPsbtResponse } f
2
2
  import { BitcoinWalletConnector, BitcoinWalletConnectorOpts } from '../BitcoinWalletConnector';
3
3
  export declare class PhantomConnector extends BitcoinWalletConnector {
4
4
  name: string;
5
- canFetchConnectedAccounts: boolean;
6
5
  constructor(opts: BitcoinWalletConnectorOpts);
7
6
  private connectWithInstalledExtension;
8
7
  getAddress(): Promise<string | undefined>;
8
+ signMessageWithAddress(messageToSign: string, address: string): Promise<string | undefined>;
9
9
  signMessage(messageToSign: string): Promise<string | undefined>;
10
10
  sendBitcoin(transaction: BitcoinTransaction): Promise<string | undefined>;
11
11
  signPsbt(request: BitcoinSignPsbtRequest): Promise<BitcoinSignPsbtResponse | undefined>;
@@ -13,7 +13,6 @@ class PhantomConnector extends BitcoinWalletConnector {
13
13
  constructor(opts) {
14
14
  super(Object.assign(Object.assign({}, opts), { overrideKey: 'phantombtc' }));
15
15
  this.name = 'Phantom';
16
- this.canFetchConnectedAccounts = true;
17
16
  }
18
17
  connectWithInstalledExtension() {
19
18
  return __awaiter(this, void 0, void 0, function* () {
@@ -23,7 +22,7 @@ class PhantomConnector extends BitcoinWalletConnector {
23
22
  const { accounts } = yield this.walletMethods.connect();
24
23
  const parsedAccounts = accounts.map((account) => ({
25
24
  address: account.address,
26
- publicKey: Buffer.from(account.publicKey).toString('base64'),
25
+ publicKey: Buffer.from(account.publicKey).toString('hex'),
27
26
  }));
28
27
  [paymentAccount, ordinalsAccount] = parsedAccounts;
29
28
  // in case it only returns one account, we will use it as both payment and ordinals
@@ -64,17 +63,13 @@ class PhantomConnector extends BitcoinWalletConnector {
64
63
  return undefined;
65
64
  });
66
65
  }
67
- signMessage(messageToSign) {
66
+ signMessageWithAddress(messageToSign, address) {
68
67
  return __awaiter(this, void 0, void 0, function* () {
69
68
  var _a;
70
- const [walletAddress] = yield this.getConnectedAccounts();
71
- if (!walletAddress) {
72
- return;
73
- }
74
69
  if ((_a = this.walletMethods) === null || _a === void 0 ? void 0 : _a.signMessage) {
75
70
  const [result] = yield this.walletMethods.signMessage({
76
71
  // we need to sign with the ordinals account
77
- account: { address: walletAddress },
72
+ account: { address },
78
73
  message: new TextEncoder().encode(messageToSign),
79
74
  });
80
75
  return Buffer.from(result.signature).toString('base64');
@@ -84,11 +79,20 @@ class PhantomConnector extends BitcoinWalletConnector {
84
79
  if (!provider) {
85
80
  return;
86
81
  }
87
- const result = yield provider.signMessage(walletAddress, new TextEncoder().encode(messageToSign));
82
+ const result = yield provider.signMessage(address, new TextEncoder().encode(messageToSign));
88
83
  return Buffer.from(result.signature).toString('base64');
89
84
  }
90
85
  });
91
86
  }
87
+ signMessage(messageToSign) {
88
+ return __awaiter(this, void 0, void 0, function* () {
89
+ const [walletAddress] = yield this.getConnectedAccounts();
90
+ if (!walletAddress) {
91
+ return;
92
+ }
93
+ return this.signMessageWithAddress(messageToSign, walletAddress);
94
+ });
95
+ }
92
96
  sendBitcoin(transaction) {
93
97
  return __awaiter(this, void 0, void 0, function* () {
94
98
  logger.debug('sendBitcoin - function not implemented', transaction);
@@ -13,7 +13,6 @@ class UnisatConnector extends BitcoinWalletConnector.BitcoinWalletConnector {
13
13
  super(Object.assign(Object.assign({}, opts), { overrideKey: 'unisat' }));
14
14
  this.name = 'UniSat';
15
15
  this.overrideKey = 'unisat';
16
- this.canFetchConnectedAccounts = true;
17
16
  }
18
17
  getAddress() {
19
18
  return _tslib.__awaiter(this, void 0, void 0, function* () {
@@ -65,6 +64,32 @@ class UnisatConnector extends BitcoinWalletConnector.BitcoinWalletConnector {
65
64
  return { signedPsbt: bitcoinjsLib.Psbt.fromHex(signedPsbtHex).toBase64() };
66
65
  });
67
66
  }
67
+ signPsbts(requests) {
68
+ return _tslib.__awaiter(this, void 0, void 0, function* () {
69
+ const provider = this.getProvider();
70
+ if (!provider) {
71
+ return;
72
+ }
73
+ const psbtHexs = [];
74
+ const psbtOptions = [];
75
+ for (const request of requests) {
76
+ const psbtFromBase64 = bitcoinjsLib.Psbt.fromBase64(request.unsignedPsbtBase64);
77
+ psbtHexs.push(psbtFromBase64.toHex());
78
+ psbtOptions.push(createSignPsbtOptions.createPsbtOptions(psbtFromBase64, request));
79
+ }
80
+ const signedPsbtHexs = yield provider.signPsbts(psbtHexs, psbtOptions);
81
+ return signedPsbtHexs.map((signedPsbtHex) => bitcoinjsLib.Psbt.fromHex(signedPsbtHex).toBase64());
82
+ });
83
+ }
84
+ getConnectedAccounts() {
85
+ return _tslib.__awaiter(this, void 0, void 0, function* () {
86
+ const provider = this.getProvider();
87
+ if (!provider) {
88
+ return [];
89
+ }
90
+ return provider.getAccounts();
91
+ });
92
+ }
68
93
  }
69
94
 
70
95
  exports.UnisatConnector = UnisatConnector;
@@ -3,10 +3,11 @@ import { BitcoinTransaction, BitcoinSignPsbtRequest, BitcoinSignPsbtResponse } f
3
3
  export declare class UnisatConnector extends BitcoinWalletConnector {
4
4
  name: string;
5
5
  overrideKey: string;
6
- canFetchConnectedAccounts: boolean;
7
6
  constructor(opts: BitcoinWalletConnectorOpts);
8
7
  getAddress(): Promise<string | undefined>;
9
8
  signMessage(messageToSign: string): Promise<string | undefined>;
10
9
  sendBitcoin(transaction: BitcoinTransaction): Promise<string | undefined>;
11
10
  signPsbt(request: BitcoinSignPsbtRequest): Promise<BitcoinSignPsbtResponse | undefined>;
11
+ signPsbts(requests: BitcoinSignPsbtRequest[]): Promise<string[] | undefined>;
12
+ getConnectedAccounts(): Promise<string[]>;
12
13
  }
@@ -9,7 +9,6 @@ class UnisatConnector extends BitcoinWalletConnector {
9
9
  super(Object.assign(Object.assign({}, opts), { overrideKey: 'unisat' }));
10
10
  this.name = 'UniSat';
11
11
  this.overrideKey = 'unisat';
12
- this.canFetchConnectedAccounts = true;
13
12
  }
14
13
  getAddress() {
15
14
  return __awaiter(this, void 0, void 0, function* () {
@@ -61,6 +60,32 @@ class UnisatConnector extends BitcoinWalletConnector {
61
60
  return { signedPsbt: Psbt.fromHex(signedPsbtHex).toBase64() };
62
61
  });
63
62
  }
63
+ signPsbts(requests) {
64
+ return __awaiter(this, void 0, void 0, function* () {
65
+ const provider = this.getProvider();
66
+ if (!provider) {
67
+ return;
68
+ }
69
+ const psbtHexs = [];
70
+ const psbtOptions = [];
71
+ for (const request of requests) {
72
+ const psbtFromBase64 = Psbt.fromBase64(request.unsignedPsbtBase64);
73
+ psbtHexs.push(psbtFromBase64.toHex());
74
+ psbtOptions.push(createPsbtOptions(psbtFromBase64, request));
75
+ }
76
+ const signedPsbtHexs = yield provider.signPsbts(psbtHexs, psbtOptions);
77
+ return signedPsbtHexs.map((signedPsbtHex) => Psbt.fromHex(signedPsbtHex).toBase64());
78
+ });
79
+ }
80
+ getConnectedAccounts() {
81
+ return __awaiter(this, void 0, void 0, function* () {
82
+ const provider = this.getProvider();
83
+ if (!provider) {
84
+ return [];
85
+ }
86
+ return provider.getAccounts();
87
+ });
88
+ }
64
89
  }
65
90
 
66
91
  export { UnisatConnector };
@@ -11,7 +11,6 @@ class UnknownInjectedConnector extends BitcoinWalletConnector.BitcoinWalletConne
11
11
  super(Object.assign(Object.assign({}, opts), { overrideKey: 'unknown' }));
12
12
  this.name = 'Unknown';
13
13
  this.overrideKey = 'unknown';
14
- this.canFetchConnectedAccounts = false;
15
14
  }
16
15
  getAddress() {
17
16
  return _tslib.__awaiter(this, void 0, void 0, function* () {
@@ -25,6 +24,13 @@ class UnknownInjectedConnector extends BitcoinWalletConnector.BitcoinWalletConne
25
24
  return;
26
25
  });
27
26
  }
27
+ signPsbts(
28
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
29
+ _requests) {
30
+ return _tslib.__awaiter(this, void 0, void 0, function* () {
31
+ return;
32
+ });
33
+ }
28
34
  sendBitcoin(
29
35
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
30
36
  _transaction) {