@dynamic-labs/bitcoin 4.0.0-alpha.4 → 4.0.0-alpha.40

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 +349 -0
  2. package/package.cjs +8 -0
  3. package/package.js +4 -0
  4. package/package.json +9 -15
  5. package/src/connectors/BitcoinSatsConnectConnector/BitcoinSatsConnectConnector.cjs +65 -15
  6. package/src/connectors/BitcoinSatsConnectConnector/BitcoinSatsConnectConnector.d.ts +8 -0
  7. package/src/connectors/BitcoinSatsConnectConnector/BitcoinSatsConnectConnector.js +67 -17
  8. package/src/connectors/BitcoinWalletConnector.cjs +11 -5
  9. package/src/connectors/BitcoinWalletConnector.d.ts +3 -2
  10. package/src/connectors/BitcoinWalletConnector.js +13 -7
  11. package/src/connectors/{BitcoinSatsConnectLegacyConnector/BitcoinSatsConnectLegacyConnector.cjs → MagicEdenConnector/MagicEdenConnector.cjs} +21 -57
  12. package/src/connectors/{BitcoinSatsConnectLegacyConnector/BitcoinSatsConnectLegacyConnector.d.ts → MagicEdenConnector/MagicEdenConnector.d.ts} +8 -1
  13. package/src/connectors/{BitcoinSatsConnectLegacyConnector/BitcoinSatsConnectLegacyConnector.js → MagicEdenConnector/MagicEdenConnector.js} +23 -59
  14. package/src/connectors/MagicEdenConnector/index.d.ts +1 -0
  15. package/src/connectors/OkxConnector/OkxConnector.cjs +3 -6
  16. package/src/connectors/OkxConnector/OkxConnector.d.ts +0 -1
  17. package/src/connectors/OkxConnector/OkxConnector.js +3 -6
  18. package/src/connectors/OylConnector/OylConnector.cjs +68 -0
  19. package/src/connectors/OylConnector/OylConnector.d.ts +10 -0
  20. package/src/connectors/OylConnector/OylConnector.js +64 -0
  21. package/src/connectors/OylConnector/index.d.ts +1 -0
  22. package/src/connectors/PhantomConnector/PhantomConnector.cjs +1 -7
  23. package/src/connectors/PhantomConnector/PhantomConnector.d.ts +1 -2
  24. package/src/connectors/PhantomConnector/PhantomConnector.js +1 -7
  25. package/src/connectors/index.d.ts +2 -2
  26. package/src/const.cjs +0 -2
  27. package/src/const.js +1 -2
  28. package/src/index.cjs +11 -9
  29. package/src/index.d.ts +2 -2
  30. package/src/index.js +11 -8
  31. package/src/utils/fetchSatsConnectConnectors/fetchSatsConnectConnectors.cjs +7 -17
  32. package/src/utils/fetchSatsConnectConnectors/fetchSatsConnectConnectors.d.ts +1 -1
  33. package/src/utils/fetchSatsConnectConnectors/fetchSatsConnectConnectors.js +7 -17
  34. package/src/utils/index.d.ts +0 -1
  35. package/src/connectors/BitcoinSatsConnectLegacyConnector/index.d.ts +0 -1
  36. package/src/connectors/UnknownInjected/UnknownInjected.cjs +0 -43
  37. package/src/connectors/UnknownInjected/UnknownInjected.d.ts +0 -11
  38. package/src/connectors/UnknownInjected/UnknownInjected.js +0 -39
  39. package/src/connectors/UnknownInjected/index.d.ts +0 -1
  40. package/src/utils/supportsSatsConnect.cjs +0 -32
  41. package/src/utils/supportsSatsConnect.d.ts +0 -2
  42. package/src/utils/supportsSatsConnect.js +0 -28
@@ -1,10 +1,9 @@
1
1
  'use client'
2
2
  import { __awaiter } from '../../../_virtual/_tslib.js';
3
3
  import { Psbt } from 'bitcoinjs-lib';
4
- import { BitcoinNetworkType, request, AddressPurpose, signMultipleTransactions } from 'sats-connect';
4
+ import { BitcoinNetworkType, request, AddressPurpose, signMultipleTransactions, addListener } from 'sats-connect';
5
5
  import { isMobile, template } from '@dynamic-labs/utils';
6
- import { findWalletBookWallet } from '@dynamic-labs/wallet-book';
7
- import { logger } from '@dynamic-labs/wallet-connector-core';
6
+ import { logger, eventListenerHandlers } from '@dynamic-labs/wallet-connector-core';
8
7
  import { convertNetworkTypeForPsbt } from '../../utils/psbt/bitcoinNetworkTypeToNetworks.js';
9
8
  import { BitcoinWalletConnector } from '../BitcoinWalletConnector.js';
10
9
  import { createSignPsbtOptionsForSatsConnect } from '../../utils/psbt/createSignPsbtOptions.js';
@@ -12,9 +11,14 @@ import { SATSCONNECT_FEATURE } from '../../const.js';
12
11
 
13
12
  class BitcoinSatsConnectConnector extends BitcoinWalletConnector {
14
13
  constructor(opts) {
14
+ var _a, _b, _c;
15
15
  super(opts);
16
16
  this.isLegacy = false;
17
17
  this.currentNetwork = BitcoinNetworkType.Mainnet;
18
+ if ((_b = (_a = opts.walletData) === null || _a === void 0 ? void 0 : _a.injectedConfig) === null || _b === void 0 ? void 0 : _b.length) {
19
+ this.providerId =
20
+ (_c = opts.walletData.injectedConfig[0].walletStandard) === null || _c === void 0 ? void 0 : _c.providerId;
21
+ }
18
22
  }
19
23
  getGenericUserCancelledError() {
20
24
  const error = new Error();
@@ -43,22 +47,29 @@ class BitcoinSatsConnectConnector extends BitcoinWalletConnector {
43
47
  return mainAddress;
44
48
  });
45
49
  }
50
+ /**
51
+ * If is inAppBrowser experience, redirects to the inAppBrowser template.
52
+ * Returns true if redirection was triggered.
53
+ */
54
+ handleInAppBrowserGetAddress() {
55
+ var _a;
56
+ const inAppBrowserUrl = (_a = this.metadata) === null || _a === void 0 ? void 0 : _a.inAppBrowserUrl;
57
+ if (!isMobile() ||
58
+ this.isInstalledOnBrowser() ||
59
+ !inAppBrowserUrl ||
60
+ this.mobileExperience !== 'in-app-browser')
61
+ return false;
62
+ const inAppBrowserTemplate = template(inAppBrowserUrl);
63
+ const deepLink = inAppBrowserTemplate({
64
+ encodedDappURI: encodeURIComponent(window.location.toString()),
65
+ });
66
+ window.location.href = deepLink;
67
+ return true;
68
+ }
46
69
  getAddress() {
47
70
  return __awaiter(this, void 0, void 0, function* () {
48
- var _a;
49
- const wallet = findWalletBookWallet(this.walletBook, this.key);
50
- const inAppBrowserUrl = (_a = wallet === null || wallet === void 0 ? void 0 : wallet.mobile) === null || _a === void 0 ? void 0 : _a.inAppBrowser;
51
- if (isMobile() &&
52
- !this.isInstalledOnBrowser() &&
53
- inAppBrowserUrl &&
54
- this.mobileExperience === 'in-app-browser') {
55
- const inAppBrowserTemplate = template(inAppBrowserUrl);
56
- const deepLink = inAppBrowserTemplate({
57
- encodedDappURI: encodeURIComponent(window.location.toString()),
58
- });
59
- window.location.href = deepLink;
71
+ if (this.handleInAppBrowserGetAddress())
60
72
  return;
61
- }
62
73
  try {
63
74
  // requesting permissions on initial connect will avoid connection prompt for other requests
64
75
  const permissionResponse = yield request('wallet_requestPermissions', undefined);
@@ -234,15 +245,54 @@ class BitcoinSatsConnectConnector extends BitcoinWalletConnector {
234
245
  });
235
246
  }
236
247
  validateActiveWallet(expectedAddress) {
248
+ const _super = Object.create(null, {
249
+ validateActiveWallet: { get: () => super.validateActiveWallet }
250
+ });
237
251
  return __awaiter(this, void 0, void 0, function* () {
238
252
  // TODO: this is a workaround to avoid extra connecting prompt for xverse
239
253
  // we should revisit it once xverse releases a new version with bug fixes
254
+ if (this.key !== 'xverse') {
255
+ yield _super.validateActiveWallet.call(this, expectedAddress);
256
+ return;
257
+ }
240
258
  logger.debug('validateActiveWallet - skipping validation for xverse', {
241
259
  expectedAddress,
242
260
  });
243
- return;
244
261
  });
245
262
  }
263
+ handleXverseAccountChange() {
264
+ return __awaiter(this, void 0, void 0, function* () {
265
+ const { handleAccountChange } = eventListenerHandlers(this);
266
+ // xverse doesn't return the new account address, so we need to get it manually
267
+ const accounts = yield this.getAddresses();
268
+ if (!accounts) {
269
+ return;
270
+ }
271
+ const connectedAccounts = [accounts];
272
+ handleAccountChange(connectedAccounts);
273
+ });
274
+ }
275
+ setupEventListeners() {
276
+ // even if we pass a providerId, to addListener, it doesn't work
277
+ // the event fires multiple times, so we're using the default implementation for non xverse wallets
278
+ if (this.key !== 'xverse') {
279
+ super.setupEventListeners();
280
+ return;
281
+ }
282
+ try {
283
+ const removeListener = addListener('accountChange', this.handleXverseAccountChange.bind(this));
284
+ this.teardownEventListeners = () => {
285
+ logger.debug('[BitcoinSatsConnectConnector] teardownEventListeners');
286
+ removeListener();
287
+ };
288
+ }
289
+ catch (error) {
290
+ logger.debug('[BitcoinSatsConnectConnector] setupEventListeners', {
291
+ connector: this.key,
292
+ error,
293
+ });
294
+ }
295
+ }
246
296
  }
247
297
 
248
298
  export { BitcoinSatsConnectConnector };
@@ -36,7 +36,7 @@ class BitcoinWalletConnector extends walletConnectorCore.WalletConnectorBase {
36
36
  this.walletMethods = this.bitcoinProviderHelper.getWalletMethods(this.wallet);
37
37
  }
38
38
  this.cache = new BitcoinLocalStorageCache.BitcoinLocalStorageCache(this.overrideKey);
39
- this.canFetchConnectedAccounts = walletBook.isWalletMethodSupported(walletBookWallet, 'getConnectedAccounts', 'browserExtension');
39
+ this.canFetchConnectedAccounts = walletConnectorCore.isConnectorMethodSupported(this, 'getConnectedAccounts', 'desktop');
40
40
  }
41
41
  isSameAccountChangeRequest(to) {
42
42
  return this.lastAccountChange === to;
@@ -50,10 +50,8 @@ class BitcoinWalletConnector extends walletConnectorCore.WalletConnectorBase {
50
50
  });
51
51
  }
52
52
  canConnectWithHardwareWallet() {
53
- const wallet = walletBook.findWalletBookWallet(this.walletBook, this.key);
54
- if (!wallet || !wallet.hardwareWallets)
55
- return false;
56
- return wallet.hardwareWallets.includes('ledger');
53
+ var _a;
54
+ return Boolean((_a = this.metadata.supportedHardwareWallets) === null || _a === void 0 ? void 0 : _a.includes('ledger'));
57
55
  }
58
56
  isInstalledOnBrowser() {
59
57
  var _a;
@@ -184,6 +182,14 @@ class BitcoinWalletConnector extends walletConnectorCore.WalletConnectorBase {
184
182
  return response.text();
185
183
  });
186
184
  }
185
+ // not all wallets support sendBitcoin method
186
+ // so we have a default implementation that returns undefined
187
+ sendBitcoin(transaction) {
188
+ return _tslib.__awaiter(this, void 0, void 0, function* () {
189
+ walletConnectorCore.logger.debug('sendBitcoin - function not implemented', transaction);
190
+ return undefined;
191
+ });
192
+ }
187
193
  getProvider() {
188
194
  var _a;
189
195
  return (_a = this.bitcoinProviderHelper) === null || _a === void 0 ? void 0 : _a.getProvider();
@@ -1,6 +1,6 @@
1
1
  import { type EventEmitter } from 'eventemitter3';
2
2
  import type { Wallet } from '@wallet-standard/base';
3
- import { Chain, IBitcoinWalletConnector, WalletConnectorBase } from '@dynamic-labs/wallet-connector-core';
3
+ import { Chain, IBitcoinWalletConnector, WalletConnectorBase, WalletMetadata } from '@dynamic-labs/wallet-connector-core';
4
4
  import { WalletBookSchema, WalletSchema } from '@dynamic-labs/wallet-book';
5
5
  import { JwtVerifiedCredential, WalletAdditionalAddress } from '@dynamic-labs/sdk-api-core';
6
6
  import { IBitcoinSessionCache } from '../BitcoinLocalStorageCache';
@@ -10,6 +10,7 @@ export type BitcoinWalletConnectorOpts = {
10
10
  walletBook: WalletBookSchema;
11
11
  walletData: WalletSchema;
12
12
  overrideKey?: string;
13
+ metadata?: WalletMetadata;
13
14
  };
14
15
  export declare abstract class BitcoinWalletConnector extends WalletConnectorBase<typeof BitcoinWallet> implements IBitcoinWalletConnector {
15
16
  cache: IBitcoinSessionCache;
@@ -38,7 +39,7 @@ export declare abstract class BitcoinWalletConnector extends WalletConnectorBase
38
39
  getAdditionalAddresses(mainAddress?: string): Promise<WalletAdditionalAddress[]>;
39
40
  setAdditionalAddresses(mainAddress: string, additionalAddresses: WalletAdditionalAddress[]): Promise<void>;
40
41
  sendRawTransaction(rawTransaction: string): Promise<string>;
41
- abstract sendBitcoin(transaction: BitcoinTransaction): Promise<string | undefined>;
42
+ sendBitcoin(transaction: BitcoinTransaction): Promise<string | undefined>;
42
43
  getProvider<T>(): T & EventEmitter<string | symbol, any>;
43
44
  abstract signPsbt(request: BitcoinSignPsbtRequest): Promise<BitcoinSignPsbtResponse | undefined>;
44
45
  signPsbts(requests: BitcoinSignPsbtRequest[]): Promise<string[] | undefined>;
@@ -1,8 +1,8 @@
1
1
  'use client'
2
2
  import { __awaiter } from '../../_virtual/_tslib.js';
3
3
  import { AddressPurpose } from 'sats-connect';
4
- import { WalletConnectorBase, eventListenerHandlers, logger } from '@dynamic-labs/wallet-connector-core';
5
- import { getWalletBookWallet, isWalletMethodSupported, findWalletBookWallet } from '@dynamic-labs/wallet-book';
4
+ import { WalletConnectorBase, isConnectorMethodSupported, eventListenerHandlers, logger } from '@dynamic-labs/wallet-connector-core';
5
+ import { getWalletBookWallet } from '@dynamic-labs/wallet-book';
6
6
  import { isLedgerAddressViaVerifiedCredentials, DynamicError } from '@dynamic-labs/utils';
7
7
  import { WalletAddressType } from '@dynamic-labs/sdk-api-core';
8
8
  import { BitcoinLocalStorageCache } from '../BitcoinLocalStorageCache.js';
@@ -32,7 +32,7 @@ class BitcoinWalletConnector extends WalletConnectorBase {
32
32
  this.walletMethods = this.bitcoinProviderHelper.getWalletMethods(this.wallet);
33
33
  }
34
34
  this.cache = new BitcoinLocalStorageCache(this.overrideKey);
35
- this.canFetchConnectedAccounts = isWalletMethodSupported(walletBookWallet, 'getConnectedAccounts', 'browserExtension');
35
+ this.canFetchConnectedAccounts = isConnectorMethodSupported(this, 'getConnectedAccounts', 'desktop');
36
36
  }
37
37
  isSameAccountChangeRequest(to) {
38
38
  return this.lastAccountChange === to;
@@ -46,10 +46,8 @@ class BitcoinWalletConnector extends WalletConnectorBase {
46
46
  });
47
47
  }
48
48
  canConnectWithHardwareWallet() {
49
- const wallet = findWalletBookWallet(this.walletBook, this.key);
50
- if (!wallet || !wallet.hardwareWallets)
51
- return false;
52
- return wallet.hardwareWallets.includes('ledger');
49
+ var _a;
50
+ return Boolean((_a = this.metadata.supportedHardwareWallets) === null || _a === void 0 ? void 0 : _a.includes('ledger'));
53
51
  }
54
52
  isInstalledOnBrowser() {
55
53
  var _a;
@@ -180,6 +178,14 @@ class BitcoinWalletConnector extends WalletConnectorBase {
180
178
  return response.text();
181
179
  });
182
180
  }
181
+ // not all wallets support sendBitcoin method
182
+ // so we have a default implementation that returns undefined
183
+ sendBitcoin(transaction) {
184
+ return __awaiter(this, void 0, void 0, function* () {
185
+ logger.debug('sendBitcoin - function not implemented', transaction);
186
+ return undefined;
187
+ });
188
+ }
183
189
  getProvider() {
184
190
  var _a;
185
191
  return (_a = this.bitcoinProviderHelper) === null || _a === void 0 ? void 0 : _a.getProvider();
@@ -4,46 +4,23 @@
4
4
  Object.defineProperty(exports, '__esModule', { value: true });
5
5
 
6
6
  var _tslib = require('../../../_virtual/_tslib.cjs');
7
+ var jsontokens = require('jsontokens');
7
8
  var satsConnect = require('sats-connect');
8
9
  var utils = require('@dynamic-labs/utils');
9
- var walletBook = require('@dynamic-labs/wallet-book');
10
10
  var _const = require('../../const.cjs');
11
- require('bitcoinjs-lib');
12
- require('@dynamic-labs/wallet-connector-core');
13
- require('@dynamic-labs/sdk-api-core');
14
- require('@wallet-standard/app');
15
11
  var BitcoinSatsConnectConnector = require('../BitcoinSatsConnectConnector/BitcoinSatsConnectConnector.cjs');
16
- var supportsSatsConnect = require('../../utils/supportsSatsConnect.cjs');
17
12
 
18
- class BitcoinSatsConnectLegacyConnector extends BitcoinSatsConnectConnector.BitcoinSatsConnectConnector {
19
- constructor() {
20
- super(...arguments);
13
+ class MagicEdenConnector extends BitcoinSatsConnectConnector.BitcoinSatsConnectConnector {
14
+ constructor(opts) {
15
+ super(Object.assign(Object.assign({}, opts), { overrideKey: 'magicedenbtc' }));
16
+ this.name = 'Magic Eden';
17
+ this.overrideKey = 'magicedenbtc';
21
18
  this.isLegacy = true;
22
19
  }
23
20
  getAddress() {
24
21
  return _tslib.__awaiter(this, void 0, void 0, function* () {
25
- var _a;
26
- // xverse doesn't support wallet standard, so we won't have a wallet object,
27
- // but it's already the default provider for sats-connect, so it's ok
28
- // for getProvider in getAddress to return undefined
29
- // if we're not using xverse, we need to check if there is a wallet and
30
- // that it has the satsconnect feature to return the correct provider to use
31
- if (!supportsSatsConnect.supportsSatsConnect(this)) {
32
- return;
33
- }
34
- const wallet = walletBook.findWalletBookWallet(this.walletBook, this.key);
35
- const inAppBrowserUrl = (_a = wallet === null || wallet === void 0 ? void 0 : wallet.mobile) === null || _a === void 0 ? void 0 : _a.inAppBrowser;
36
- if (utils.isMobile() &&
37
- !this.isInstalledOnBrowser() &&
38
- inAppBrowserUrl &&
39
- this.mobileExperience === 'in-app-browser') {
40
- const inAppBrowserTemplate = utils.template(inAppBrowserUrl);
41
- const deepLink = inAppBrowserTemplate({
42
- encodedDappURI: encodeURIComponent(window.location.toString()),
43
- });
44
- window.location.href = deepLink;
22
+ if (this.handleInAppBrowserGetAddress())
45
23
  return;
46
- }
47
24
  return new Promise((resolve, reject) => {
48
25
  satsConnect.getAddress({
49
26
  getProvider: () => _tslib.__awaiter(this, void 0, void 0, function* () {
@@ -82,9 +59,6 @@ class BitcoinSatsConnectLegacyConnector extends BitcoinSatsConnectConnector.Bitc
82
59
  }
83
60
  signMessage(messageToSign, withAddress) {
84
61
  return _tslib.__awaiter(this, void 0, void 0, function* () {
85
- if (!supportsSatsConnect.supportsSatsConnect(this)) {
86
- return;
87
- }
88
62
  return new Promise((resolve, reject) => {
89
63
  satsConnect.signMessage({
90
64
  getProvider: () => _tslib.__awaiter(this, void 0, void 0, function* () {
@@ -122,7 +96,7 @@ class BitcoinSatsConnectLegacyConnector extends BitcoinSatsConnectConnector.Bitc
122
96
  var _a;
123
97
  const mainAddress = yield this.getAddress();
124
98
  const senderAddress = (_a = (yield this.getAdditionalAddresses(mainAddress)).find((address) => address.type === 'payment')) === null || _a === void 0 ? void 0 : _a.address;
125
- if (!senderAddress || !supportsSatsConnect.supportsSatsConnect(this)) {
99
+ if (!senderAddress) {
126
100
  return;
127
101
  }
128
102
  return new Promise((resolve, reject) => {
@@ -185,32 +159,22 @@ class BitcoinSatsConnectLegacyConnector extends BitcoinSatsConnectConnector.Bitc
185
159
  });
186
160
  });
187
161
  }
162
+ /**
163
+ * Uses the custom Magic Eden signTransactions feature to sign multiple transactions
164
+ */
188
165
  signTransactions(transactions) {
189
166
  return _tslib.__awaiter(this, void 0, void 0, function* () {
190
- const { message, psbts, network } = transactions;
191
- return new Promise((resolve, reject) => {
192
- satsConnect.signMultipleTransactions({
193
- getProvider: () => _tslib.__awaiter(this, void 0, void 0, function* () {
194
- var _a, _b;
195
- return (_b = (_a = this.wallet) === null || _a === void 0 ? void 0 : _a.features[_const.SATSCONNECT_FEATURE]) === null || _b === void 0 ? void 0 : _b.provider;
196
- }),
197
- onCancel: () => {
198
- const error = new Error();
199
- error.code = '-32000'; // error code for user cancelled
200
- reject(error);
201
- },
202
- onFinish: (response) => {
203
- resolve(response);
204
- },
205
- payload: {
206
- message: message || 'Sign Transaction',
207
- network,
208
- psbts,
209
- },
210
- });
211
- });
167
+ var _a;
168
+ (_a = transactions.message) !== null && _a !== void 0 ? _a : (transactions.message = 'Sign Transaction');
169
+ const request = jsontokens.createUnsecuredToken(transactions);
170
+ // Magic Eden has implemented their own signTransactions feature, and have requested us
171
+ // to ensure we use it rather than the general Sats Connect API for this method
172
+ const provider = this.getProvider();
173
+ if (!provider)
174
+ throw new utils.DynamicError('signTransactions failed: Magic Eden provider not found');
175
+ return provider.signMultipleTransactions(request);
212
176
  });
213
177
  }
214
178
  }
215
179
 
216
- exports.BitcoinSatsConnectLegacyConnector = BitcoinSatsConnectLegacyConnector;
180
+ exports.MagicEdenConnector = MagicEdenConnector;
@@ -1,11 +1,18 @@
1
1
  import { SignMultipleTransactionsPayload, SignTransactionResponse } from 'sats-connect';
2
2
  import { BitcoinTransaction, SatsConnectSignTransactionInput } from '../../types';
3
3
  import { BitcoinSatsConnectConnector } from '../BitcoinSatsConnectConnector';
4
- export declare abstract class BitcoinSatsConnectLegacyConnector extends BitcoinSatsConnectConnector {
4
+ import { BitcoinWalletConnectorOpts } from '../BitcoinWalletConnector';
5
+ export declare class MagicEdenConnector extends BitcoinSatsConnectConnector {
6
+ name: string;
7
+ overrideKey: string;
5
8
  isLegacy: boolean;
9
+ constructor(opts: BitcoinWalletConnectorOpts);
6
10
  getAddress(): Promise<string | undefined>;
7
11
  signMessage(messageToSign: string, withAddress: string): Promise<string | undefined>;
8
12
  sendBitcoin(transaction: BitcoinTransaction): Promise<string | undefined>;
9
13
  signTransaction(params: SatsConnectSignTransactionInput): Promise<SignTransactionResponse | undefined>;
14
+ /**
15
+ * Uses the custom Magic Eden signTransactions feature to sign multiple transactions
16
+ */
10
17
  signTransactions(transactions: SignMultipleTransactionsPayload): Promise<SignTransactionResponse[] | undefined>;
11
18
  }
@@ -1,45 +1,22 @@
1
1
  'use client'
2
2
  import { __awaiter } from '../../../_virtual/_tslib.js';
3
- import { getAddress, AddressPurpose, signMessage, sendBtcTransaction, signTransaction, signMultipleTransactions } from 'sats-connect';
4
- import { isMobile, template } from '@dynamic-labs/utils';
5
- import { findWalletBookWallet } from '@dynamic-labs/wallet-book';
3
+ import { createUnsecuredToken } from 'jsontokens';
4
+ import { getAddress, AddressPurpose, signMessage, sendBtcTransaction, signTransaction } from 'sats-connect';
5
+ import { DynamicError } from '@dynamic-labs/utils';
6
6
  import { SATSCONNECT_FEATURE } from '../../const.js';
7
- import 'bitcoinjs-lib';
8
- import '@dynamic-labs/wallet-connector-core';
9
- import '@dynamic-labs/sdk-api-core';
10
- import '@wallet-standard/app';
11
7
  import { BitcoinSatsConnectConnector } from '../BitcoinSatsConnectConnector/BitcoinSatsConnectConnector.js';
12
- import { supportsSatsConnect } from '../../utils/supportsSatsConnect.js';
13
8
 
14
- class BitcoinSatsConnectLegacyConnector extends BitcoinSatsConnectConnector {
15
- constructor() {
16
- super(...arguments);
9
+ class MagicEdenConnector extends BitcoinSatsConnectConnector {
10
+ constructor(opts) {
11
+ super(Object.assign(Object.assign({}, opts), { overrideKey: 'magicedenbtc' }));
12
+ this.name = 'Magic Eden';
13
+ this.overrideKey = 'magicedenbtc';
17
14
  this.isLegacy = true;
18
15
  }
19
16
  getAddress() {
20
17
  return __awaiter(this, void 0, void 0, function* () {
21
- var _a;
22
- // xverse doesn't support wallet standard, so we won't have a wallet object,
23
- // but it's already the default provider for sats-connect, so it's ok
24
- // for getProvider in getAddress to return undefined
25
- // if we're not using xverse, we need to check if there is a wallet and
26
- // that it has the satsconnect feature to return the correct provider to use
27
- if (!supportsSatsConnect(this)) {
28
- return;
29
- }
30
- const wallet = findWalletBookWallet(this.walletBook, this.key);
31
- const inAppBrowserUrl = (_a = wallet === null || wallet === void 0 ? void 0 : wallet.mobile) === null || _a === void 0 ? void 0 : _a.inAppBrowser;
32
- if (isMobile() &&
33
- !this.isInstalledOnBrowser() &&
34
- inAppBrowserUrl &&
35
- this.mobileExperience === 'in-app-browser') {
36
- const inAppBrowserTemplate = template(inAppBrowserUrl);
37
- const deepLink = inAppBrowserTemplate({
38
- encodedDappURI: encodeURIComponent(window.location.toString()),
39
- });
40
- window.location.href = deepLink;
18
+ if (this.handleInAppBrowserGetAddress())
41
19
  return;
42
- }
43
20
  return new Promise((resolve, reject) => {
44
21
  getAddress({
45
22
  getProvider: () => __awaiter(this, void 0, void 0, function* () {
@@ -78,9 +55,6 @@ class BitcoinSatsConnectLegacyConnector extends BitcoinSatsConnectConnector {
78
55
  }
79
56
  signMessage(messageToSign, withAddress) {
80
57
  return __awaiter(this, void 0, void 0, function* () {
81
- if (!supportsSatsConnect(this)) {
82
- return;
83
- }
84
58
  return new Promise((resolve, reject) => {
85
59
  signMessage({
86
60
  getProvider: () => __awaiter(this, void 0, void 0, function* () {
@@ -118,7 +92,7 @@ class BitcoinSatsConnectLegacyConnector extends BitcoinSatsConnectConnector {
118
92
  var _a;
119
93
  const mainAddress = yield this.getAddress();
120
94
  const senderAddress = (_a = (yield this.getAdditionalAddresses(mainAddress)).find((address) => address.type === 'payment')) === null || _a === void 0 ? void 0 : _a.address;
121
- if (!senderAddress || !supportsSatsConnect(this)) {
95
+ if (!senderAddress) {
122
96
  return;
123
97
  }
124
98
  return new Promise((resolve, reject) => {
@@ -181,32 +155,22 @@ class BitcoinSatsConnectLegacyConnector extends BitcoinSatsConnectConnector {
181
155
  });
182
156
  });
183
157
  }
158
+ /**
159
+ * Uses the custom Magic Eden signTransactions feature to sign multiple transactions
160
+ */
184
161
  signTransactions(transactions) {
185
162
  return __awaiter(this, void 0, void 0, function* () {
186
- const { message, psbts, network } = transactions;
187
- return new Promise((resolve, reject) => {
188
- signMultipleTransactions({
189
- getProvider: () => __awaiter(this, void 0, void 0, function* () {
190
- var _a, _b;
191
- return (_b = (_a = this.wallet) === null || _a === void 0 ? void 0 : _a.features[SATSCONNECT_FEATURE]) === null || _b === void 0 ? void 0 : _b.provider;
192
- }),
193
- onCancel: () => {
194
- const error = new Error();
195
- error.code = '-32000'; // error code for user cancelled
196
- reject(error);
197
- },
198
- onFinish: (response) => {
199
- resolve(response);
200
- },
201
- payload: {
202
- message: message || 'Sign Transaction',
203
- network,
204
- psbts,
205
- },
206
- });
207
- });
163
+ var _a;
164
+ (_a = transactions.message) !== null && _a !== void 0 ? _a : (transactions.message = 'Sign Transaction');
165
+ const request = createUnsecuredToken(transactions);
166
+ // Magic Eden has implemented their own signTransactions feature, and have requested us
167
+ // to ensure we use it rather than the general Sats Connect API for this method
168
+ const provider = this.getProvider();
169
+ if (!provider)
170
+ throw new DynamicError('signTransactions failed: Magic Eden provider not found');
171
+ return provider.signMultipleTransactions(request);
208
172
  });
209
173
  }
210
174
  }
211
175
 
212
- export { BitcoinSatsConnectLegacyConnector };
176
+ export { MagicEdenConnector };
@@ -0,0 +1 @@
1
+ export { MagicEdenConnector } from './MagicEdenConnector';
@@ -14,17 +14,14 @@ class OkxConnector extends BitcoinWalletConnector.BitcoinWalletConnector {
14
14
  super(Object.assign(Object.assign({}, opts), { overrideKey: 'okxwalletbtc' }));
15
15
  this.name = 'OKX Wallet';
16
16
  }
17
- get walletBookWallet() {
18
- return this.walletBook.wallets[this.key];
19
- }
20
17
  getAddress() {
21
18
  return _tslib.__awaiter(this, void 0, void 0, function* () {
19
+ var _a;
22
20
  if (!this.isInstalledOnBrowser() &&
23
21
  utils.isMobile() &&
24
- this.walletBookWallet.mobile &&
25
- this.walletBookWallet.mobile.inAppBrowser &&
22
+ ((_a = this.metadata) === null || _a === void 0 ? void 0 : _a.inAppBrowserUrl) &&
26
23
  this.mobileExperience === 'in-app-browser') {
27
- const inAppBrowserCompiledTemplate = utils.template(this.walletBookWallet.mobile.inAppBrowser);
24
+ const inAppBrowserCompiledTemplate = utils.template(this.metadata.inAppBrowserUrl);
28
25
  const deepLink = inAppBrowserCompiledTemplate({
29
26
  encodedDappURI: encodeURIComponent(window.location.toString()),
30
27
  });
@@ -3,7 +3,6 @@ import { BitcoinTransaction, BitcoinSignPsbtRequest, BitcoinSignPsbtResponse } f
3
3
  export declare class OkxConnector extends BitcoinWalletConnector {
4
4
  name: string;
5
5
  constructor(opts: BitcoinWalletConnectorOpts);
6
- private get walletBookWallet();
7
6
  getAddress(): Promise<string | undefined>;
8
7
  signMessage(messageToSign: string): Promise<string | undefined>;
9
8
  sendBitcoin(transaction: BitcoinTransaction): Promise<string | undefined>;
@@ -10,17 +10,14 @@ class OkxConnector extends BitcoinWalletConnector {
10
10
  super(Object.assign(Object.assign({}, opts), { overrideKey: 'okxwalletbtc' }));
11
11
  this.name = 'OKX Wallet';
12
12
  }
13
- get walletBookWallet() {
14
- return this.walletBook.wallets[this.key];
15
- }
16
13
  getAddress() {
17
14
  return __awaiter(this, void 0, void 0, function* () {
15
+ var _a;
18
16
  if (!this.isInstalledOnBrowser() &&
19
17
  isMobile() &&
20
- this.walletBookWallet.mobile &&
21
- this.walletBookWallet.mobile.inAppBrowser &&
18
+ ((_a = this.metadata) === null || _a === void 0 ? void 0 : _a.inAppBrowserUrl) &&
22
19
  this.mobileExperience === 'in-app-browser') {
23
- const inAppBrowserCompiledTemplate = template(this.walletBookWallet.mobile.inAppBrowser);
20
+ const inAppBrowserCompiledTemplate = template(this.metadata.inAppBrowserUrl);
24
21
  const deepLink = inAppBrowserCompiledTemplate({
25
22
  encodedDappURI: encodeURIComponent(window.location.toString()),
26
23
  });
@@ -0,0 +1,68 @@
1
+ 'use client'
2
+ 'use strict';
3
+
4
+ Object.defineProperty(exports, '__esModule', { value: true });
5
+
6
+ var _tslib = require('../../../_virtual/_tslib.cjs');
7
+ var bitcoinjsLib = require('bitcoinjs-lib');
8
+ var BitcoinWalletConnector = require('../BitcoinWalletConnector.cjs');
9
+ var createSignPsbtOptions = require('../../utils/psbt/createSignPsbtOptions.cjs');
10
+
11
+ class OylConnector extends BitcoinWalletConnector.BitcoinWalletConnector {
12
+ constructor(opts) {
13
+ super(Object.assign(Object.assign({}, opts), { overrideKey: 'oylwallet' }));
14
+ this.name = 'Oyl Wallet';
15
+ this.overrideKey = 'oylwallet';
16
+ }
17
+ getAddress() {
18
+ return _tslib.__awaiter(this, void 0, void 0, function* () {
19
+ var _a;
20
+ const provider = this.getProvider();
21
+ if (!provider) {
22
+ return;
23
+ }
24
+ const addresses = yield provider.getAddresses();
25
+ const ordinalsAddress = addresses.taproot;
26
+ const paymentAddress = addresses.nativeSegwit;
27
+ const mainAddress = (_a = ordinalsAddress === null || ordinalsAddress === void 0 ? void 0 : ordinalsAddress.address) !== null && _a !== void 0 ? _a : paymentAddress === null || paymentAddress === void 0 ? void 0 : paymentAddress.address;
28
+ yield this.setConnectedAccountWithAddresses({
29
+ active: true,
30
+ mainAddress,
31
+ ordinalsAddress,
32
+ paymentAddress,
33
+ });
34
+ return mainAddress;
35
+ });
36
+ }
37
+ signMessage(messageToSign, withAddress) {
38
+ return _tslib.__awaiter(this, void 0, void 0, function* () {
39
+ const provider = this.getProvider();
40
+ if (!provider) {
41
+ return;
42
+ }
43
+ const { signature } = yield provider.signMessage({
44
+ address: withAddress,
45
+ message: messageToSign,
46
+ });
47
+ return signature;
48
+ });
49
+ }
50
+ signPsbt(request) {
51
+ return _tslib.__awaiter(this, void 0, void 0, function* () {
52
+ const provider = this.getProvider();
53
+ if (!provider) {
54
+ return;
55
+ }
56
+ const psbtFromBase64 = bitcoinjsLib.Psbt.fromBase64(request.unsignedPsbtBase64);
57
+ const options = createSignPsbtOptions.createPsbtOptions(psbtFromBase64, request);
58
+ const { psbt: signedPsbtHex } = yield provider.signPsbt({
59
+ broadcast: false,
60
+ finalize: options.autoFinalized,
61
+ psbt: psbtFromBase64.toHex(),
62
+ });
63
+ return { signedPsbt: bitcoinjsLib.Psbt.fromHex(signedPsbtHex).toBase64() };
64
+ });
65
+ }
66
+ }
67
+
68
+ exports.OylConnector = OylConnector;
@@ -0,0 +1,10 @@
1
+ import { BitcoinWalletConnector, BitcoinWalletConnectorOpts } from '../BitcoinWalletConnector';
2
+ import { BitcoinSignPsbtRequest, BitcoinSignPsbtResponse } from '../../types';
3
+ export declare class OylConnector extends BitcoinWalletConnector {
4
+ name: string;
5
+ overrideKey: string;
6
+ constructor(opts: BitcoinWalletConnectorOpts);
7
+ getAddress(): Promise<string | undefined>;
8
+ signMessage(messageToSign: string, withAddress: string): Promise<string | undefined>;
9
+ signPsbt(request: BitcoinSignPsbtRequest): Promise<BitcoinSignPsbtResponse | undefined>;
10
+ }