@dynamic-labs/bitcoin 4.0.0-alpha.5 → 4.0.0-alpha.51
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +468 -0
- package/package.cjs +8 -0
- package/package.js +4 -0
- package/package.json +9 -15
- package/src/connectors/BitcoinSatsConnectConnector/BitcoinSatsConnectConnector.cjs +70 -17
- package/src/connectors/BitcoinSatsConnectConnector/BitcoinSatsConnectConnector.d.ts +13 -2
- package/src/connectors/BitcoinSatsConnectConnector/BitcoinSatsConnectConnector.js +72 -19
- package/src/connectors/BitcoinWalletConnector.cjs +29 -6
- package/src/connectors/BitcoinWalletConnector.d.ts +8 -3
- package/src/connectors/BitcoinWalletConnector.js +31 -8
- package/src/connectors/{BitcoinSatsConnectLegacyConnector/BitcoinSatsConnectLegacyConnector.cjs → MagicEdenConnector/MagicEdenConnector.cjs} +26 -59
- package/src/connectors/MagicEdenConnector/MagicEdenConnector.d.ts +21 -0
- package/src/connectors/{BitcoinSatsConnectLegacyConnector/BitcoinSatsConnectLegacyConnector.js → MagicEdenConnector/MagicEdenConnector.js} +28 -61
- package/src/connectors/MagicEdenConnector/index.d.ts +1 -0
- package/src/connectors/OkxConnector/OkxConnector.cjs +15 -8
- package/src/connectors/OkxConnector/OkxConnector.d.ts +5 -3
- package/src/connectors/OkxConnector/OkxConnector.js +15 -8
- package/src/connectors/OneKeyConnector/OneKeyConnector.cjs +118 -0
- package/src/connectors/OneKeyConnector/OneKeyConnector.d.ts +15 -0
- package/src/connectors/OneKeyConnector/OneKeyConnector.js +114 -0
- package/src/connectors/OneKeyConnector/index.d.ts +1 -0
- package/src/connectors/OylConnector/OylConnector.cjs +71 -0
- package/src/connectors/OylConnector/OylConnector.d.ts +13 -0
- package/src/connectors/OylConnector/OylConnector.js +67 -0
- package/src/connectors/OylConnector/index.d.ts +1 -0
- package/src/connectors/PhantomConnector/PhantomConnector.cjs +5 -10
- package/src/connectors/PhantomConnector/PhantomConnector.d.ts +5 -3
- package/src/connectors/PhantomConnector/PhantomConnector.js +5 -10
- package/src/connectors/UnisatConnector/UnisatConnector.cjs +9 -2
- package/src/connectors/UnisatConnector/UnisatConnector.d.ts +5 -2
- package/src/connectors/UnisatConnector/UnisatConnector.js +9 -2
- package/src/connectors/index.d.ts +3 -2
- package/src/const.cjs +0 -2
- package/src/const.js +1 -2
- package/src/index.cjs +13 -9
- package/src/index.d.ts +3 -3
- package/src/index.js +13 -8
- package/src/types.d.ts +1 -0
- package/src/utils/fetchSatsConnectConnectors/fetchSatsConnectConnectors.cjs +7 -17
- package/src/utils/fetchSatsConnectConnectors/fetchSatsConnectConnectors.d.ts +1 -1
- package/src/utils/fetchSatsConnectConnectors/fetchSatsConnectConnectors.js +7 -17
- package/src/utils/getAddressByType/getAddressByType.cjs +11 -0
- package/src/utils/getAddressByType/getAddressByType.d.ts +3 -0
- package/src/utils/getAddressByType/getAddressByType.js +7 -0
- package/src/utils/getAddressByType/index.d.ts +1 -0
- package/src/utils/getSatsConnectSigningProtocol/getSatsConnectSigningProtocol.cjs +17 -0
- package/src/utils/getSatsConnectSigningProtocol/getSatsConnectSigningProtocol.d.ts +3 -0
- package/src/utils/getSatsConnectSigningProtocol/getSatsConnectSigningProtocol.js +13 -0
- package/src/utils/getSatsConnectSigningProtocol/index.d.ts +1 -0
- package/src/utils/index.d.ts +0 -1
- package/src/wallet/BitcoinWallet.cjs +26 -5
- package/src/wallet/BitcoinWallet.d.ts +18 -3
- package/src/wallet/BitcoinWallet.js +26 -5
- package/src/connectors/BitcoinSatsConnectLegacyConnector/BitcoinSatsConnectLegacyConnector.d.ts +0 -11
- package/src/connectors/BitcoinSatsConnectLegacyConnector/index.d.ts +0 -1
- package/src/connectors/UnknownInjected/UnknownInjected.cjs +0 -43
- package/src/connectors/UnknownInjected/UnknownInjected.d.ts +0 -11
- package/src/connectors/UnknownInjected/UnknownInjected.js +0 -39
- package/src/connectors/UnknownInjected/index.d.ts +0 -1
- package/src/utils/supportsSatsConnect.cjs +0 -32
- package/src/utils/supportsSatsConnect.d.ts +0 -2
- package/src/utils/supportsSatsConnect.js +0 -28
|
@@ -7,18 +7,23 @@ var _tslib = require('../../../_virtual/_tslib.cjs');
|
|
|
7
7
|
var bitcoinjsLib = require('bitcoinjs-lib');
|
|
8
8
|
var satsConnect = require('sats-connect');
|
|
9
9
|
var utils = require('@dynamic-labs/utils');
|
|
10
|
-
var walletBook = require('@dynamic-labs/wallet-book');
|
|
11
10
|
var walletConnectorCore = require('@dynamic-labs/wallet-connector-core');
|
|
12
11
|
var bitcoinNetworkTypeToNetworks = require('../../utils/psbt/bitcoinNetworkTypeToNetworks.cjs');
|
|
13
12
|
var BitcoinWalletConnector = require('../BitcoinWalletConnector.cjs');
|
|
14
13
|
var createSignPsbtOptions = require('../../utils/psbt/createSignPsbtOptions.cjs');
|
|
15
14
|
var _const = require('../../const.cjs');
|
|
15
|
+
var getSatsConnectSigningProtocol = require('../../utils/getSatsConnectSigningProtocol/getSatsConnectSigningProtocol.cjs');
|
|
16
16
|
|
|
17
17
|
class BitcoinSatsConnectConnector extends BitcoinWalletConnector.BitcoinWalletConnector {
|
|
18
18
|
constructor(opts) {
|
|
19
|
+
var _a, _b, _c;
|
|
19
20
|
super(opts);
|
|
20
21
|
this.isLegacy = false;
|
|
21
22
|
this.currentNetwork = satsConnect.BitcoinNetworkType.Mainnet;
|
|
23
|
+
if ((_b = (_a = opts.walletData) === null || _a === void 0 ? void 0 : _a.injectedConfig) === null || _b === void 0 ? void 0 : _b.length) {
|
|
24
|
+
this.providerId =
|
|
25
|
+
(_c = opts.walletData.injectedConfig[0].walletStandard) === null || _c === void 0 ? void 0 : _c.providerId;
|
|
26
|
+
}
|
|
22
27
|
}
|
|
23
28
|
getGenericUserCancelledError() {
|
|
24
29
|
const error = new Error();
|
|
@@ -47,22 +52,29 @@ class BitcoinSatsConnectConnector extends BitcoinWalletConnector.BitcoinWalletCo
|
|
|
47
52
|
return mainAddress;
|
|
48
53
|
});
|
|
49
54
|
}
|
|
55
|
+
/**
|
|
56
|
+
* If is inAppBrowser experience, redirects to the inAppBrowser template.
|
|
57
|
+
* Returns true if redirection was triggered.
|
|
58
|
+
*/
|
|
59
|
+
handleInAppBrowserGetAddress() {
|
|
60
|
+
var _a;
|
|
61
|
+
const inAppBrowserUrl = (_a = this.metadata) === null || _a === void 0 ? void 0 : _a.inAppBrowserUrl;
|
|
62
|
+
if (!utils.isMobile() ||
|
|
63
|
+
this.isInstalledOnBrowser() ||
|
|
64
|
+
!inAppBrowserUrl ||
|
|
65
|
+
this.mobileExperience !== 'in-app-browser')
|
|
66
|
+
return false;
|
|
67
|
+
const inAppBrowserTemplate = utils.template(inAppBrowserUrl);
|
|
68
|
+
const deepLink = inAppBrowserTemplate({
|
|
69
|
+
encodedDappURI: encodeURIComponent(window.location.toString()),
|
|
70
|
+
});
|
|
71
|
+
window.location.href = deepLink;
|
|
72
|
+
return true;
|
|
73
|
+
}
|
|
50
74
|
getAddress() {
|
|
51
75
|
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
52
|
-
|
|
53
|
-
const wallet = walletBook.findWalletBookWallet(this.walletBook, this.key);
|
|
54
|
-
const inAppBrowserUrl = (_a = wallet === null || wallet === void 0 ? void 0 : wallet.mobile) === null || _a === void 0 ? void 0 : _a.inAppBrowser;
|
|
55
|
-
if (utils.isMobile() &&
|
|
56
|
-
!this.isInstalledOnBrowser() &&
|
|
57
|
-
inAppBrowserUrl &&
|
|
58
|
-
this.mobileExperience === 'in-app-browser') {
|
|
59
|
-
const inAppBrowserTemplate = utils.template(inAppBrowserUrl);
|
|
60
|
-
const deepLink = inAppBrowserTemplate({
|
|
61
|
-
encodedDappURI: encodeURIComponent(window.location.toString()),
|
|
62
|
-
});
|
|
63
|
-
window.location.href = deepLink;
|
|
76
|
+
if (this.handleInAppBrowserGetAddress())
|
|
64
77
|
return;
|
|
65
|
-
}
|
|
66
78
|
try {
|
|
67
79
|
// requesting permissions on initial connect will avoid connection prompt for other requests
|
|
68
80
|
const permissionResponse = yield satsConnect.request('wallet_requestPermissions', undefined);
|
|
@@ -78,12 +90,14 @@ class BitcoinSatsConnectConnector extends BitcoinWalletConnector.BitcoinWalletCo
|
|
|
78
90
|
}
|
|
79
91
|
});
|
|
80
92
|
}
|
|
81
|
-
signMessage(messageToSign,
|
|
93
|
+
signMessage(messageToSign, options) {
|
|
82
94
|
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
95
|
+
const { address, protocol } = options;
|
|
83
96
|
try {
|
|
84
97
|
const response = yield satsConnect.request('signMessage', {
|
|
85
|
-
address
|
|
98
|
+
address,
|
|
86
99
|
message: messageToSign,
|
|
100
|
+
protocol: getSatsConnectSigningProtocol.getSatsConnectSigningProtocol(protocol),
|
|
87
101
|
});
|
|
88
102
|
if (response.status !== 'success') {
|
|
89
103
|
throw response.error;
|
|
@@ -238,15 +252,54 @@ class BitcoinSatsConnectConnector extends BitcoinWalletConnector.BitcoinWalletCo
|
|
|
238
252
|
});
|
|
239
253
|
}
|
|
240
254
|
validateActiveWallet(expectedAddress) {
|
|
255
|
+
const _super = Object.create(null, {
|
|
256
|
+
validateActiveWallet: { get: () => super.validateActiveWallet }
|
|
257
|
+
});
|
|
241
258
|
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
242
259
|
// TODO: this is a workaround to avoid extra connecting prompt for xverse
|
|
243
260
|
// we should revisit it once xverse releases a new version with bug fixes
|
|
261
|
+
if (this.key !== 'xverse') {
|
|
262
|
+
yield _super.validateActiveWallet.call(this, expectedAddress);
|
|
263
|
+
return;
|
|
264
|
+
}
|
|
244
265
|
walletConnectorCore.logger.debug('validateActiveWallet - skipping validation for xverse', {
|
|
245
266
|
expectedAddress,
|
|
246
267
|
});
|
|
247
|
-
return;
|
|
248
268
|
});
|
|
249
269
|
}
|
|
270
|
+
handleXverseAccountChange() {
|
|
271
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
272
|
+
const { handleAccountChange } = walletConnectorCore.eventListenerHandlers(this);
|
|
273
|
+
// xverse doesn't return the new account address, so we need to get it manually
|
|
274
|
+
const accounts = yield this.getAddresses();
|
|
275
|
+
if (!accounts) {
|
|
276
|
+
return;
|
|
277
|
+
}
|
|
278
|
+
const connectedAccounts = [accounts];
|
|
279
|
+
handleAccountChange(connectedAccounts);
|
|
280
|
+
});
|
|
281
|
+
}
|
|
282
|
+
setupEventListeners() {
|
|
283
|
+
// even if we pass a providerId, to addListener, it doesn't work
|
|
284
|
+
// the event fires multiple times, so we're using the default implementation for non xverse wallets
|
|
285
|
+
if (this.key !== 'xverse') {
|
|
286
|
+
super.setupEventListeners();
|
|
287
|
+
return;
|
|
288
|
+
}
|
|
289
|
+
try {
|
|
290
|
+
const removeListener = satsConnect.addListener('accountChange', this.handleXverseAccountChange.bind(this));
|
|
291
|
+
this.teardownEventListeners = () => {
|
|
292
|
+
walletConnectorCore.logger.debug('[BitcoinSatsConnectConnector] teardownEventListeners');
|
|
293
|
+
removeListener();
|
|
294
|
+
};
|
|
295
|
+
}
|
|
296
|
+
catch (error) {
|
|
297
|
+
walletConnectorCore.logger.debug('[BitcoinSatsConnectConnector] setupEventListeners', {
|
|
298
|
+
connector: this.key,
|
|
299
|
+
error,
|
|
300
|
+
});
|
|
301
|
+
}
|
|
302
|
+
}
|
|
250
303
|
}
|
|
251
304
|
|
|
252
305
|
exports.BitcoinSatsConnectConnector = BitcoinSatsConnectConnector;
|
|
@@ -1,18 +1,29 @@
|
|
|
1
1
|
import { BitcoinNetworkType, SignMultipleTransactionsPayload, SignTransactionResponse } from 'sats-connect';
|
|
2
|
-
import { BitcoinSignPsbtRequest, BitcoinSignPsbtResponse, BitcoinTransaction, SatsConnectSignTransactionInput } from '../../types';
|
|
2
|
+
import { BitcoinSignProtocol, BitcoinSignPsbtRequest, BitcoinSignPsbtResponse, BitcoinTransaction, SatsConnectSignTransactionInput } from '../../types';
|
|
3
3
|
import { BitcoinWalletConnector, BitcoinWalletConnectorOpts } from '../BitcoinWalletConnector';
|
|
4
4
|
export declare abstract class BitcoinSatsConnectConnector extends BitcoinWalletConnector {
|
|
5
5
|
isLegacy: boolean;
|
|
6
6
|
currentNetwork: BitcoinNetworkType;
|
|
7
|
+
providerId: string | undefined;
|
|
7
8
|
constructor(opts: BitcoinWalletConnectorOpts);
|
|
8
9
|
private getGenericUserCancelledError;
|
|
9
10
|
private getAddresses;
|
|
11
|
+
/**
|
|
12
|
+
* If is inAppBrowser experience, redirects to the inAppBrowser template.
|
|
13
|
+
* Returns true if redirection was triggered.
|
|
14
|
+
*/
|
|
15
|
+
protected handleInAppBrowserGetAddress(): boolean;
|
|
10
16
|
getAddress(): Promise<string | undefined>;
|
|
11
|
-
signMessage(messageToSign: string,
|
|
17
|
+
signMessage(messageToSign: string, options: {
|
|
18
|
+
address: string;
|
|
19
|
+
protocol?: BitcoinSignProtocol;
|
|
20
|
+
}): Promise<string | undefined>;
|
|
12
21
|
sendBitcoin(transaction: BitcoinTransaction): Promise<string | undefined>;
|
|
13
22
|
signTransaction(params: SatsConnectSignTransactionInput): Promise<SignTransactionResponse | undefined>;
|
|
14
23
|
signTransactions(transactions: SignMultipleTransactionsPayload): Promise<SignTransactionResponse[] | undefined>;
|
|
15
24
|
signPsbt(request: BitcoinSignPsbtRequest): Promise<BitcoinSignPsbtResponse | undefined>;
|
|
16
25
|
signPsbts(requests: BitcoinSignPsbtRequest[]): Promise<string[] | undefined>;
|
|
17
26
|
validateActiveWallet(expectedAddress: string): Promise<void>;
|
|
27
|
+
private handleXverseAccountChange;
|
|
28
|
+
setupEventListeners(): void;
|
|
18
29
|
}
|
|
@@ -1,20 +1,25 @@
|
|
|
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 {
|
|
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';
|
|
11
10
|
import { SATSCONNECT_FEATURE } from '../../const.js';
|
|
11
|
+
import { getSatsConnectSigningProtocol } from '../../utils/getSatsConnectSigningProtocol/getSatsConnectSigningProtocol.js';
|
|
12
12
|
|
|
13
13
|
class BitcoinSatsConnectConnector extends BitcoinWalletConnector {
|
|
14
14
|
constructor(opts) {
|
|
15
|
+
var _a, _b, _c;
|
|
15
16
|
super(opts);
|
|
16
17
|
this.isLegacy = false;
|
|
17
18
|
this.currentNetwork = BitcoinNetworkType.Mainnet;
|
|
19
|
+
if ((_b = (_a = opts.walletData) === null || _a === void 0 ? void 0 : _a.injectedConfig) === null || _b === void 0 ? void 0 : _b.length) {
|
|
20
|
+
this.providerId =
|
|
21
|
+
(_c = opts.walletData.injectedConfig[0].walletStandard) === null || _c === void 0 ? void 0 : _c.providerId;
|
|
22
|
+
}
|
|
18
23
|
}
|
|
19
24
|
getGenericUserCancelledError() {
|
|
20
25
|
const error = new Error();
|
|
@@ -43,22 +48,29 @@ class BitcoinSatsConnectConnector extends BitcoinWalletConnector {
|
|
|
43
48
|
return mainAddress;
|
|
44
49
|
});
|
|
45
50
|
}
|
|
51
|
+
/**
|
|
52
|
+
* If is inAppBrowser experience, redirects to the inAppBrowser template.
|
|
53
|
+
* Returns true if redirection was triggered.
|
|
54
|
+
*/
|
|
55
|
+
handleInAppBrowserGetAddress() {
|
|
56
|
+
var _a;
|
|
57
|
+
const inAppBrowserUrl = (_a = this.metadata) === null || _a === void 0 ? void 0 : _a.inAppBrowserUrl;
|
|
58
|
+
if (!isMobile() ||
|
|
59
|
+
this.isInstalledOnBrowser() ||
|
|
60
|
+
!inAppBrowserUrl ||
|
|
61
|
+
this.mobileExperience !== 'in-app-browser')
|
|
62
|
+
return false;
|
|
63
|
+
const inAppBrowserTemplate = template(inAppBrowserUrl);
|
|
64
|
+
const deepLink = inAppBrowserTemplate({
|
|
65
|
+
encodedDappURI: encodeURIComponent(window.location.toString()),
|
|
66
|
+
});
|
|
67
|
+
window.location.href = deepLink;
|
|
68
|
+
return true;
|
|
69
|
+
}
|
|
46
70
|
getAddress() {
|
|
47
71
|
return __awaiter(this, void 0, void 0, function* () {
|
|
48
|
-
|
|
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;
|
|
72
|
+
if (this.handleInAppBrowserGetAddress())
|
|
60
73
|
return;
|
|
61
|
-
}
|
|
62
74
|
try {
|
|
63
75
|
// requesting permissions on initial connect will avoid connection prompt for other requests
|
|
64
76
|
const permissionResponse = yield request('wallet_requestPermissions', undefined);
|
|
@@ -74,12 +86,14 @@ class BitcoinSatsConnectConnector extends BitcoinWalletConnector {
|
|
|
74
86
|
}
|
|
75
87
|
});
|
|
76
88
|
}
|
|
77
|
-
signMessage(messageToSign,
|
|
89
|
+
signMessage(messageToSign, options) {
|
|
78
90
|
return __awaiter(this, void 0, void 0, function* () {
|
|
91
|
+
const { address, protocol } = options;
|
|
79
92
|
try {
|
|
80
93
|
const response = yield request('signMessage', {
|
|
81
|
-
address
|
|
94
|
+
address,
|
|
82
95
|
message: messageToSign,
|
|
96
|
+
protocol: getSatsConnectSigningProtocol(protocol),
|
|
83
97
|
});
|
|
84
98
|
if (response.status !== 'success') {
|
|
85
99
|
throw response.error;
|
|
@@ -234,15 +248,54 @@ class BitcoinSatsConnectConnector extends BitcoinWalletConnector {
|
|
|
234
248
|
});
|
|
235
249
|
}
|
|
236
250
|
validateActiveWallet(expectedAddress) {
|
|
251
|
+
const _super = Object.create(null, {
|
|
252
|
+
validateActiveWallet: { get: () => super.validateActiveWallet }
|
|
253
|
+
});
|
|
237
254
|
return __awaiter(this, void 0, void 0, function* () {
|
|
238
255
|
// TODO: this is a workaround to avoid extra connecting prompt for xverse
|
|
239
256
|
// we should revisit it once xverse releases a new version with bug fixes
|
|
257
|
+
if (this.key !== 'xverse') {
|
|
258
|
+
yield _super.validateActiveWallet.call(this, expectedAddress);
|
|
259
|
+
return;
|
|
260
|
+
}
|
|
240
261
|
logger.debug('validateActiveWallet - skipping validation for xverse', {
|
|
241
262
|
expectedAddress,
|
|
242
263
|
});
|
|
243
|
-
return;
|
|
244
264
|
});
|
|
245
265
|
}
|
|
266
|
+
handleXverseAccountChange() {
|
|
267
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
268
|
+
const { handleAccountChange } = eventListenerHandlers(this);
|
|
269
|
+
// xverse doesn't return the new account address, so we need to get it manually
|
|
270
|
+
const accounts = yield this.getAddresses();
|
|
271
|
+
if (!accounts) {
|
|
272
|
+
return;
|
|
273
|
+
}
|
|
274
|
+
const connectedAccounts = [accounts];
|
|
275
|
+
handleAccountChange(connectedAccounts);
|
|
276
|
+
});
|
|
277
|
+
}
|
|
278
|
+
setupEventListeners() {
|
|
279
|
+
// even if we pass a providerId, to addListener, it doesn't work
|
|
280
|
+
// the event fires multiple times, so we're using the default implementation for non xverse wallets
|
|
281
|
+
if (this.key !== 'xverse') {
|
|
282
|
+
super.setupEventListeners();
|
|
283
|
+
return;
|
|
284
|
+
}
|
|
285
|
+
try {
|
|
286
|
+
const removeListener = addListener('accountChange', this.handleXverseAccountChange.bind(this));
|
|
287
|
+
this.teardownEventListeners = () => {
|
|
288
|
+
logger.debug('[BitcoinSatsConnectConnector] teardownEventListeners');
|
|
289
|
+
removeListener();
|
|
290
|
+
};
|
|
291
|
+
}
|
|
292
|
+
catch (error) {
|
|
293
|
+
logger.debug('[BitcoinSatsConnectConnector] setupEventListeners', {
|
|
294
|
+
connector: this.key,
|
|
295
|
+
error,
|
|
296
|
+
});
|
|
297
|
+
}
|
|
298
|
+
}
|
|
246
299
|
}
|
|
247
300
|
|
|
248
301
|
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 =
|
|
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
|
-
|
|
54
|
-
|
|
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();
|
|
@@ -283,9 +289,26 @@ class BitcoinWalletConnector extends walletConnectorCore.WalletConnectorBase {
|
|
|
283
289
|
isLedgerAddress(address) {
|
|
284
290
|
return utils.isLedgerAddressViaVerifiedCredentials(address, this.verifiedCredentials);
|
|
285
291
|
}
|
|
292
|
+
// Each wallet has a different supported protocol
|
|
293
|
+
// So we should override this method in each connector
|
|
294
|
+
// and define how to handle the protocol
|
|
295
|
+
signMessage(messageToSign, options) {
|
|
296
|
+
const _super = Object.create(null, {
|
|
297
|
+
signMessage: { get: () => super.signMessage }
|
|
298
|
+
});
|
|
299
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
300
|
+
if (options) {
|
|
301
|
+
walletConnectorCore.logger.debug('[BitcoinWalletConnector] signMessage - Not possible to specify address and/or protocol to sign with', {
|
|
302
|
+
address: options.address,
|
|
303
|
+
protocol: options.protocol,
|
|
304
|
+
});
|
|
305
|
+
}
|
|
306
|
+
return _super.signMessage.call(this, messageToSign);
|
|
307
|
+
});
|
|
308
|
+
}
|
|
286
309
|
proveOwnership(address, messageToSign) {
|
|
287
310
|
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
288
|
-
return this.signMessage(messageToSign, address);
|
|
311
|
+
return this.signMessage(messageToSign, { address });
|
|
289
312
|
});
|
|
290
313
|
}
|
|
291
314
|
}
|
|
@@ -1,15 +1,16 @@
|
|
|
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';
|
|
7
|
-
import { BitcoinTransaction, BitcoinSignPsbtRequest, BitcoinSignPsbtResponse, BitcoinWalletStandardMethods, ConnectedAccountWithAddressesProps } from '../types';
|
|
7
|
+
import { BitcoinTransaction, BitcoinSignPsbtRequest, BitcoinSignPsbtResponse, BitcoinWalletStandardMethods, ConnectedAccountWithAddressesProps, BitcoinSignProtocol } from '../types';
|
|
8
8
|
import { BitcoinWallet } from '../wallet';
|
|
9
9
|
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
|
-
|
|
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>;
|
|
@@ -46,5 +47,9 @@ export declare abstract class BitcoinWalletConnector extends WalletConnectorBase
|
|
|
46
47
|
setupEventListeners(): void;
|
|
47
48
|
setVerifiedCredentials(verifiedCredentials: JwtVerifiedCredential[]): void;
|
|
48
49
|
isLedgerAddress(address: string): boolean;
|
|
50
|
+
signMessage(messageToSign: string, options?: {
|
|
51
|
+
address?: string;
|
|
52
|
+
protocol?: BitcoinSignProtocol;
|
|
53
|
+
}): Promise<string | undefined>;
|
|
49
54
|
proveOwnership(address: string, messageToSign: string): Promise<string | undefined>;
|
|
50
55
|
}
|
|
@@ -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
|
|
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 =
|
|
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
|
-
|
|
50
|
-
|
|
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();
|
|
@@ -279,9 +285,26 @@ class BitcoinWalletConnector extends WalletConnectorBase {
|
|
|
279
285
|
isLedgerAddress(address) {
|
|
280
286
|
return isLedgerAddressViaVerifiedCredentials(address, this.verifiedCredentials);
|
|
281
287
|
}
|
|
288
|
+
// Each wallet has a different supported protocol
|
|
289
|
+
// So we should override this method in each connector
|
|
290
|
+
// and define how to handle the protocol
|
|
291
|
+
signMessage(messageToSign, options) {
|
|
292
|
+
const _super = Object.create(null, {
|
|
293
|
+
signMessage: { get: () => super.signMessage }
|
|
294
|
+
});
|
|
295
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
296
|
+
if (options) {
|
|
297
|
+
logger.debug('[BitcoinWalletConnector] signMessage - Not possible to specify address and/or protocol to sign with', {
|
|
298
|
+
address: options.address,
|
|
299
|
+
protocol: options.protocol,
|
|
300
|
+
});
|
|
301
|
+
}
|
|
302
|
+
return _super.signMessage.call(this, messageToSign);
|
|
303
|
+
});
|
|
304
|
+
}
|
|
282
305
|
proveOwnership(address, messageToSign) {
|
|
283
306
|
return __awaiter(this, void 0, void 0, function* () {
|
|
284
|
-
return this.signMessage(messageToSign, address);
|
|
307
|
+
return this.signMessage(messageToSign, { address });
|
|
285
308
|
});
|
|
286
309
|
}
|
|
287
310
|
}
|
|
@@ -4,46 +4,24 @@
|
|
|
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
|
|
12
|
+
var getSatsConnectSigningProtocol = require('../../utils/getSatsConnectSigningProtocol/getSatsConnectSigningProtocol.cjs');
|
|
17
13
|
|
|
18
|
-
class
|
|
19
|
-
constructor() {
|
|
20
|
-
super(
|
|
14
|
+
class MagicEdenConnector extends BitcoinSatsConnectConnector.BitcoinSatsConnectConnector {
|
|
15
|
+
constructor(opts) {
|
|
16
|
+
super(Object.assign(Object.assign({}, opts), { overrideKey: 'magicedenbtc' }));
|
|
17
|
+
this.name = 'Magic Eden';
|
|
18
|
+
this.overrideKey = 'magicedenbtc';
|
|
21
19
|
this.isLegacy = true;
|
|
22
20
|
}
|
|
23
21
|
getAddress() {
|
|
24
22
|
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
25
|
-
|
|
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;
|
|
23
|
+
if (this.handleInAppBrowserGetAddress())
|
|
45
24
|
return;
|
|
46
|
-
}
|
|
47
25
|
return new Promise((resolve, reject) => {
|
|
48
26
|
satsConnect.getAddress({
|
|
49
27
|
getProvider: () => _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
@@ -80,11 +58,9 @@ class BitcoinSatsConnectLegacyConnector extends BitcoinSatsConnectConnector.Bitc
|
|
|
80
58
|
});
|
|
81
59
|
});
|
|
82
60
|
}
|
|
83
|
-
signMessage(messageToSign,
|
|
61
|
+
signMessage(messageToSign, options) {
|
|
84
62
|
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
85
|
-
|
|
86
|
-
return;
|
|
87
|
-
}
|
|
63
|
+
const { address, protocol } = options;
|
|
88
64
|
return new Promise((resolve, reject) => {
|
|
89
65
|
satsConnect.signMessage({
|
|
90
66
|
getProvider: () => _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
@@ -107,11 +83,12 @@ class BitcoinSatsConnectLegacyConnector extends BitcoinSatsConnectConnector.Bitc
|
|
|
107
83
|
resolve(response);
|
|
108
84
|
}),
|
|
109
85
|
payload: {
|
|
110
|
-
address
|
|
86
|
+
address,
|
|
111
87
|
message: messageToSign,
|
|
112
88
|
network: {
|
|
113
89
|
type: this.currentNetwork,
|
|
114
90
|
},
|
|
91
|
+
protocol: getSatsConnectSigningProtocol.getSatsConnectSigningProtocol(protocol),
|
|
115
92
|
},
|
|
116
93
|
});
|
|
117
94
|
});
|
|
@@ -122,7 +99,7 @@ class BitcoinSatsConnectLegacyConnector extends BitcoinSatsConnectConnector.Bitc
|
|
|
122
99
|
var _a;
|
|
123
100
|
const mainAddress = yield this.getAddress();
|
|
124
101
|
const senderAddress = (_a = (yield this.getAdditionalAddresses(mainAddress)).find((address) => address.type === 'payment')) === null || _a === void 0 ? void 0 : _a.address;
|
|
125
|
-
if (!senderAddress
|
|
102
|
+
if (!senderAddress) {
|
|
126
103
|
return;
|
|
127
104
|
}
|
|
128
105
|
return new Promise((resolve, reject) => {
|
|
@@ -185,32 +162,22 @@ class BitcoinSatsConnectLegacyConnector extends BitcoinSatsConnectConnector.Bitc
|
|
|
185
162
|
});
|
|
186
163
|
});
|
|
187
164
|
}
|
|
165
|
+
/**
|
|
166
|
+
* Uses the custom Magic Eden signTransactions feature to sign multiple transactions
|
|
167
|
+
*/
|
|
188
168
|
signTransactions(transactions) {
|
|
189
169
|
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
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
|
-
});
|
|
170
|
+
var _a;
|
|
171
|
+
(_a = transactions.message) !== null && _a !== void 0 ? _a : (transactions.message = 'Sign Transaction');
|
|
172
|
+
const request = jsontokens.createUnsecuredToken(transactions);
|
|
173
|
+
// Magic Eden has implemented their own signTransactions feature, and have requested us
|
|
174
|
+
// to ensure we use it rather than the general Sats Connect API for this method
|
|
175
|
+
const provider = this.getProvider();
|
|
176
|
+
if (!provider)
|
|
177
|
+
throw new utils.DynamicError('signTransactions failed: Magic Eden provider not found');
|
|
178
|
+
return provider.signMultipleTransactions(request);
|
|
212
179
|
});
|
|
213
180
|
}
|
|
214
181
|
}
|
|
215
182
|
|
|
216
|
-
exports.
|
|
183
|
+
exports.MagicEdenConnector = MagicEdenConnector;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { SignMultipleTransactionsPayload, SignTransactionResponse } from 'sats-connect';
|
|
2
|
+
import { BitcoinSignProtocol, BitcoinTransaction, SatsConnectSignTransactionInput } from '../../types';
|
|
3
|
+
import { BitcoinSatsConnectConnector } from '../BitcoinSatsConnectConnector';
|
|
4
|
+
import { BitcoinWalletConnectorOpts } from '../BitcoinWalletConnector';
|
|
5
|
+
export declare class MagicEdenConnector extends BitcoinSatsConnectConnector {
|
|
6
|
+
name: string;
|
|
7
|
+
overrideKey: string;
|
|
8
|
+
isLegacy: boolean;
|
|
9
|
+
constructor(opts: BitcoinWalletConnectorOpts);
|
|
10
|
+
getAddress(): Promise<string | undefined>;
|
|
11
|
+
signMessage(messageToSign: string, options: {
|
|
12
|
+
address: string;
|
|
13
|
+
protocol?: BitcoinSignProtocol;
|
|
14
|
+
}): Promise<string | undefined>;
|
|
15
|
+
sendBitcoin(transaction: BitcoinTransaction): Promise<string | undefined>;
|
|
16
|
+
signTransaction(params: SatsConnectSignTransactionInput): Promise<SignTransactionResponse | undefined>;
|
|
17
|
+
/**
|
|
18
|
+
* Uses the custom Magic Eden signTransactions feature to sign multiple transactions
|
|
19
|
+
*/
|
|
20
|
+
signTransactions(transactions: SignMultipleTransactionsPayload): Promise<SignTransactionResponse[] | undefined>;
|
|
21
|
+
}
|