@dynamic-labs/bitcoin 4.0.0-alpha.8 → 4.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +496 -1
- package/package.cjs +1 -1
- package/package.js +1 -1
- package/package.json +8 -7
- 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 +10 -9
- package/src/index.d.ts +3 -3
- package/src/index.js +10 -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
|
@@ -1,45 +1,23 @@
|
|
|
1
1
|
'use client'
|
|
2
2
|
import { __awaiter } from '../../../_virtual/_tslib.js';
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
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 {
|
|
8
|
+
import { getSatsConnectSigningProtocol } from '../../utils/getSatsConnectSigningProtocol/getSatsConnectSigningProtocol.js';
|
|
13
9
|
|
|
14
|
-
class
|
|
15
|
-
constructor() {
|
|
16
|
-
super(
|
|
10
|
+
class MagicEdenConnector extends BitcoinSatsConnectConnector {
|
|
11
|
+
constructor(opts) {
|
|
12
|
+
super(Object.assign(Object.assign({}, opts), { overrideKey: 'magicedenbtc' }));
|
|
13
|
+
this.name = 'Magic Eden';
|
|
14
|
+
this.overrideKey = 'magicedenbtc';
|
|
17
15
|
this.isLegacy = true;
|
|
18
16
|
}
|
|
19
17
|
getAddress() {
|
|
20
18
|
return __awaiter(this, void 0, void 0, function* () {
|
|
21
|
-
|
|
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;
|
|
19
|
+
if (this.handleInAppBrowserGetAddress())
|
|
41
20
|
return;
|
|
42
|
-
}
|
|
43
21
|
return new Promise((resolve, reject) => {
|
|
44
22
|
getAddress({
|
|
45
23
|
getProvider: () => __awaiter(this, void 0, void 0, function* () {
|
|
@@ -76,11 +54,9 @@ class BitcoinSatsConnectLegacyConnector extends BitcoinSatsConnectConnector {
|
|
|
76
54
|
});
|
|
77
55
|
});
|
|
78
56
|
}
|
|
79
|
-
signMessage(messageToSign,
|
|
57
|
+
signMessage(messageToSign, options) {
|
|
80
58
|
return __awaiter(this, void 0, void 0, function* () {
|
|
81
|
-
|
|
82
|
-
return;
|
|
83
|
-
}
|
|
59
|
+
const { address, protocol } = options;
|
|
84
60
|
return new Promise((resolve, reject) => {
|
|
85
61
|
signMessage({
|
|
86
62
|
getProvider: () => __awaiter(this, void 0, void 0, function* () {
|
|
@@ -103,11 +79,12 @@ class BitcoinSatsConnectLegacyConnector extends BitcoinSatsConnectConnector {
|
|
|
103
79
|
resolve(response);
|
|
104
80
|
}),
|
|
105
81
|
payload: {
|
|
106
|
-
address
|
|
82
|
+
address,
|
|
107
83
|
message: messageToSign,
|
|
108
84
|
network: {
|
|
109
85
|
type: this.currentNetwork,
|
|
110
86
|
},
|
|
87
|
+
protocol: getSatsConnectSigningProtocol(protocol),
|
|
111
88
|
},
|
|
112
89
|
});
|
|
113
90
|
});
|
|
@@ -118,7 +95,7 @@ class BitcoinSatsConnectLegacyConnector extends BitcoinSatsConnectConnector {
|
|
|
118
95
|
var _a;
|
|
119
96
|
const mainAddress = yield this.getAddress();
|
|
120
97
|
const senderAddress = (_a = (yield this.getAdditionalAddresses(mainAddress)).find((address) => address.type === 'payment')) === null || _a === void 0 ? void 0 : _a.address;
|
|
121
|
-
if (!senderAddress
|
|
98
|
+
if (!senderAddress) {
|
|
122
99
|
return;
|
|
123
100
|
}
|
|
124
101
|
return new Promise((resolve, reject) => {
|
|
@@ -181,32 +158,22 @@ class BitcoinSatsConnectLegacyConnector extends BitcoinSatsConnectConnector {
|
|
|
181
158
|
});
|
|
182
159
|
});
|
|
183
160
|
}
|
|
161
|
+
/**
|
|
162
|
+
* Uses the custom Magic Eden signTransactions feature to sign multiple transactions
|
|
163
|
+
*/
|
|
184
164
|
signTransactions(transactions) {
|
|
185
165
|
return __awaiter(this, void 0, void 0, function* () {
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
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
|
-
});
|
|
166
|
+
var _a;
|
|
167
|
+
(_a = transactions.message) !== null && _a !== void 0 ? _a : (transactions.message = 'Sign Transaction');
|
|
168
|
+
const request = createUnsecuredToken(transactions);
|
|
169
|
+
// Magic Eden has implemented their own signTransactions feature, and have requested us
|
|
170
|
+
// to ensure we use it rather than the general Sats Connect API for this method
|
|
171
|
+
const provider = this.getProvider();
|
|
172
|
+
if (!provider)
|
|
173
|
+
throw new DynamicError('signTransactions failed: Magic Eden provider not found');
|
|
174
|
+
return provider.signMultipleTransactions(request);
|
|
208
175
|
});
|
|
209
176
|
}
|
|
210
177
|
}
|
|
211
178
|
|
|
212
|
-
export {
|
|
179
|
+
export { MagicEdenConnector };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { MagicEdenConnector } from './MagicEdenConnector';
|
|
@@ -6,6 +6,7 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
6
6
|
var _tslib = require('../../../_virtual/_tslib.cjs');
|
|
7
7
|
var bitcoinjsLib = require('bitcoinjs-lib');
|
|
8
8
|
var utils = require('@dynamic-labs/utils');
|
|
9
|
+
var walletConnectorCore = require('@dynamic-labs/wallet-connector-core');
|
|
9
10
|
var BitcoinWalletConnector = require('../BitcoinWalletConnector.cjs');
|
|
10
11
|
var createSignPsbtOptions = require('../../utils/psbt/createSignPsbtOptions.cjs');
|
|
11
12
|
|
|
@@ -14,17 +15,14 @@ class OkxConnector extends BitcoinWalletConnector.BitcoinWalletConnector {
|
|
|
14
15
|
super(Object.assign(Object.assign({}, opts), { overrideKey: 'okxwalletbtc' }));
|
|
15
16
|
this.name = 'OKX Wallet';
|
|
16
17
|
}
|
|
17
|
-
get walletBookWallet() {
|
|
18
|
-
return this.walletBook.wallets[this.key];
|
|
19
|
-
}
|
|
20
18
|
getAddress() {
|
|
21
19
|
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
20
|
+
var _a;
|
|
22
21
|
if (!this.isInstalledOnBrowser() &&
|
|
23
22
|
utils.isMobile() &&
|
|
24
|
-
this.
|
|
25
|
-
this.walletBookWallet.mobile.inAppBrowser &&
|
|
23
|
+
((_a = this.metadata) === null || _a === void 0 ? void 0 : _a.inAppBrowserUrl) &&
|
|
26
24
|
this.mobileExperience === 'in-app-browser') {
|
|
27
|
-
const inAppBrowserCompiledTemplate = utils.template(this.
|
|
25
|
+
const inAppBrowserCompiledTemplate = utils.template(this.metadata.inAppBrowserUrl);
|
|
28
26
|
const deepLink = inAppBrowserCompiledTemplate({
|
|
29
27
|
encodedDappURI: encodeURIComponent(window.location.toString()),
|
|
30
28
|
});
|
|
@@ -48,13 +46,22 @@ class OkxConnector extends BitcoinWalletConnector.BitcoinWalletConnector {
|
|
|
48
46
|
return address;
|
|
49
47
|
});
|
|
50
48
|
}
|
|
51
|
-
signMessage(messageToSign) {
|
|
49
|
+
signMessage(messageToSign, options) {
|
|
52
50
|
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
51
|
+
var _a;
|
|
53
52
|
const provider = this.getProvider();
|
|
54
53
|
if (!provider) {
|
|
55
54
|
return;
|
|
56
55
|
}
|
|
57
|
-
|
|
56
|
+
// default to bip322-simple
|
|
57
|
+
const protocol = (_a = options === null || options === void 0 ? void 0 : options.protocol) !== null && _a !== void 0 ? _a : 'bip322-simple';
|
|
58
|
+
if (options === null || options === void 0 ? void 0 : options.address) {
|
|
59
|
+
walletConnectorCore.logger.debug('[OkxConnector] signMessage - Not possible to specify address to sign with', {
|
|
60
|
+
address: options.address,
|
|
61
|
+
protocol,
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
return provider.signMessage(messageToSign, protocol);
|
|
58
65
|
});
|
|
59
66
|
}
|
|
60
67
|
sendBitcoin(transaction) {
|
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import { BitcoinWalletConnector, BitcoinWalletConnectorOpts } from '../BitcoinWalletConnector';
|
|
2
|
-
import { BitcoinTransaction, BitcoinSignPsbtRequest, BitcoinSignPsbtResponse } from '../../types';
|
|
2
|
+
import { BitcoinTransaction, BitcoinSignPsbtRequest, BitcoinSignPsbtResponse, BitcoinSignProtocol } from '../../types';
|
|
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
|
-
signMessage(messageToSign: string
|
|
7
|
+
signMessage(messageToSign: string, options?: {
|
|
8
|
+
address?: string;
|
|
9
|
+
protocol?: BitcoinSignProtocol;
|
|
10
|
+
}): Promise<string | undefined>;
|
|
9
11
|
sendBitcoin(transaction: BitcoinTransaction): Promise<string | undefined>;
|
|
10
12
|
signPsbt(request: BitcoinSignPsbtRequest): Promise<BitcoinSignPsbtResponse | undefined>;
|
|
11
13
|
signPsbts(requests: BitcoinSignPsbtRequest[]): Promise<string[] | undefined>;
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
import { __awaiter } from '../../../_virtual/_tslib.js';
|
|
3
3
|
import { Psbt } from 'bitcoinjs-lib';
|
|
4
4
|
import { isMobile, template } from '@dynamic-labs/utils';
|
|
5
|
+
import { logger } from '@dynamic-labs/wallet-connector-core';
|
|
5
6
|
import { BitcoinWalletConnector } from '../BitcoinWalletConnector.js';
|
|
6
7
|
import { createPsbtOptions } from '../../utils/psbt/createSignPsbtOptions.js';
|
|
7
8
|
|
|
@@ -10,17 +11,14 @@ class OkxConnector extends BitcoinWalletConnector {
|
|
|
10
11
|
super(Object.assign(Object.assign({}, opts), { overrideKey: 'okxwalletbtc' }));
|
|
11
12
|
this.name = 'OKX Wallet';
|
|
12
13
|
}
|
|
13
|
-
get walletBookWallet() {
|
|
14
|
-
return this.walletBook.wallets[this.key];
|
|
15
|
-
}
|
|
16
14
|
getAddress() {
|
|
17
15
|
return __awaiter(this, void 0, void 0, function* () {
|
|
16
|
+
var _a;
|
|
18
17
|
if (!this.isInstalledOnBrowser() &&
|
|
19
18
|
isMobile() &&
|
|
20
|
-
this.
|
|
21
|
-
this.walletBookWallet.mobile.inAppBrowser &&
|
|
19
|
+
((_a = this.metadata) === null || _a === void 0 ? void 0 : _a.inAppBrowserUrl) &&
|
|
22
20
|
this.mobileExperience === 'in-app-browser') {
|
|
23
|
-
const inAppBrowserCompiledTemplate = template(this.
|
|
21
|
+
const inAppBrowserCompiledTemplate = template(this.metadata.inAppBrowserUrl);
|
|
24
22
|
const deepLink = inAppBrowserCompiledTemplate({
|
|
25
23
|
encodedDappURI: encodeURIComponent(window.location.toString()),
|
|
26
24
|
});
|
|
@@ -44,13 +42,22 @@ class OkxConnector extends BitcoinWalletConnector {
|
|
|
44
42
|
return address;
|
|
45
43
|
});
|
|
46
44
|
}
|
|
47
|
-
signMessage(messageToSign) {
|
|
45
|
+
signMessage(messageToSign, options) {
|
|
48
46
|
return __awaiter(this, void 0, void 0, function* () {
|
|
47
|
+
var _a;
|
|
49
48
|
const provider = this.getProvider();
|
|
50
49
|
if (!provider) {
|
|
51
50
|
return;
|
|
52
51
|
}
|
|
53
|
-
|
|
52
|
+
// default to bip322-simple
|
|
53
|
+
const protocol = (_a = options === null || options === void 0 ? void 0 : options.protocol) !== null && _a !== void 0 ? _a : 'bip322-simple';
|
|
54
|
+
if (options === null || options === void 0 ? void 0 : options.address) {
|
|
55
|
+
logger.debug('[OkxConnector] signMessage - Not possible to specify address to sign with', {
|
|
56
|
+
address: options.address,
|
|
57
|
+
protocol,
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
return provider.signMessage(messageToSign, protocol);
|
|
54
61
|
});
|
|
55
62
|
}
|
|
56
63
|
sendBitcoin(transaction) {
|
|
@@ -0,0 +1,118 @@
|
|
|
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 utils = require('@dynamic-labs/utils');
|
|
9
|
+
var walletConnectorCore = require('@dynamic-labs/wallet-connector-core');
|
|
10
|
+
var BitcoinWalletConnector = require('../BitcoinWalletConnector.cjs');
|
|
11
|
+
var createSignPsbtOptions = require('../../utils/psbt/createSignPsbtOptions.cjs');
|
|
12
|
+
|
|
13
|
+
class OneKeyConnector extends BitcoinWalletConnector.BitcoinWalletConnector {
|
|
14
|
+
constructor(opts) {
|
|
15
|
+
super(Object.assign(Object.assign({}, opts), { overrideKey: 'onekeybtc' }));
|
|
16
|
+
this.name = 'OneKey';
|
|
17
|
+
}
|
|
18
|
+
getAddress() {
|
|
19
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
20
|
+
var _a;
|
|
21
|
+
if (!this.isInstalledOnBrowser() &&
|
|
22
|
+
utils.isMobile() &&
|
|
23
|
+
((_a = this.metadata) === null || _a === void 0 ? void 0 : _a.inAppBrowserUrl) &&
|
|
24
|
+
this.mobileExperience === 'in-app-browser') {
|
|
25
|
+
const inAppBrowserCompiledTemplate = utils.template(this.metadata.inAppBrowserUrl);
|
|
26
|
+
const deepLink = inAppBrowserCompiledTemplate({
|
|
27
|
+
encodedDappURI: encodeURIComponent(window.location.toString()),
|
|
28
|
+
});
|
|
29
|
+
window.location.assign(deepLink);
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
const provider = this.getProvider();
|
|
33
|
+
if (!provider) {
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
const [address] = yield provider.requestAccounts();
|
|
37
|
+
const bitcoinAddress = {
|
|
38
|
+
address,
|
|
39
|
+
publicKey: yield provider.getPublicKey(),
|
|
40
|
+
};
|
|
41
|
+
yield this.setConnectedAccountWithAddresses({
|
|
42
|
+
active: true,
|
|
43
|
+
mainAddress: address,
|
|
44
|
+
ordinalsAddress: bitcoinAddress,
|
|
45
|
+
});
|
|
46
|
+
return address;
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
getConnectedAccounts() {
|
|
50
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
51
|
+
const provider = this.getProvider();
|
|
52
|
+
if (!provider) {
|
|
53
|
+
return [];
|
|
54
|
+
}
|
|
55
|
+
return provider.getAccounts();
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
signMessage(messageToSign, options) {
|
|
59
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
60
|
+
var _a;
|
|
61
|
+
const provider = this.getProvider();
|
|
62
|
+
if (!provider) {
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
// default to ecdsa
|
|
66
|
+
const protocol = (_a = options === null || options === void 0 ? void 0 : options.protocol) !== null && _a !== void 0 ? _a : 'ecdsa';
|
|
67
|
+
if (options === null || options === void 0 ? void 0 : options.address) {
|
|
68
|
+
walletConnectorCore.logger.debug('[OneKeyConnector] signMessage - Not possible to specify address to sign with', {
|
|
69
|
+
address: options.address,
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
return provider.signMessage(messageToSign, protocol);
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
sendBitcoin(transaction) {
|
|
76
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
77
|
+
const provider = this.getProvider();
|
|
78
|
+
if (!provider) {
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
return provider.sendBitcoin(transaction.recipientAddress, transaction.amount.toString());
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
signPsbt(request) {
|
|
85
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
86
|
+
const provider = this.getProvider();
|
|
87
|
+
if (!provider) {
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
const psbtFromBase64 = bitcoinjsLib.Psbt.fromBase64(request.unsignedPsbtBase64);
|
|
91
|
+
const signedPsbtHex = yield provider.signPsbt(psbtFromBase64.toHex(), {
|
|
92
|
+
autoFinalized: false,
|
|
93
|
+
});
|
|
94
|
+
return { signedPsbt: bitcoinjsLib.Psbt.fromHex(signedPsbtHex).toBase64() };
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
signPsbts(requests) {
|
|
98
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
99
|
+
const provider = this.getProvider();
|
|
100
|
+
if (!provider) {
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
const psbtHexs = [];
|
|
104
|
+
const psbtOptions = [];
|
|
105
|
+
for (const request of requests) {
|
|
106
|
+
const psbt = bitcoinjsLib.Psbt.fromBase64(request.unsignedPsbtBase64);
|
|
107
|
+
psbtHexs.push(psbt.toHex());
|
|
108
|
+
psbtOptions.push(createSignPsbtOptions.createPsbtOptions(psbt, request));
|
|
109
|
+
}
|
|
110
|
+
const signedPsbtHexs = yield provider.signPsbts(psbtHexs, {
|
|
111
|
+
autoFinalized: false,
|
|
112
|
+
});
|
|
113
|
+
return signedPsbtHexs.map((signedPsbtHex) => bitcoinjsLib.Psbt.fromHex(signedPsbtHex).toBase64());
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
exports.OneKeyConnector = OneKeyConnector;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { BitcoinWalletConnector, BitcoinWalletConnectorOpts } from '../BitcoinWalletConnector';
|
|
2
|
+
import { BitcoinTransaction, BitcoinSignPsbtRequest, BitcoinSignPsbtResponse, BitcoinSignProtocol } from '../../types';
|
|
3
|
+
export declare class OneKeyConnector extends BitcoinWalletConnector {
|
|
4
|
+
name: string;
|
|
5
|
+
constructor(opts: BitcoinWalletConnectorOpts);
|
|
6
|
+
getAddress(): Promise<string | undefined>;
|
|
7
|
+
getConnectedAccounts(): Promise<string[]>;
|
|
8
|
+
signMessage(messageToSign: string, options?: {
|
|
9
|
+
address?: string;
|
|
10
|
+
protocol?: BitcoinSignProtocol;
|
|
11
|
+
}): Promise<string | undefined>;
|
|
12
|
+
sendBitcoin(transaction: BitcoinTransaction): Promise<string | undefined>;
|
|
13
|
+
signPsbt(request: BitcoinSignPsbtRequest): Promise<BitcoinSignPsbtResponse | undefined>;
|
|
14
|
+
signPsbts(requests: BitcoinSignPsbtRequest[]): Promise<string[] | undefined>;
|
|
15
|
+
}
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
import { __awaiter } from '../../../_virtual/_tslib.js';
|
|
3
|
+
import { Psbt } from 'bitcoinjs-lib';
|
|
4
|
+
import { isMobile, template } from '@dynamic-labs/utils';
|
|
5
|
+
import { logger } from '@dynamic-labs/wallet-connector-core';
|
|
6
|
+
import { BitcoinWalletConnector } from '../BitcoinWalletConnector.js';
|
|
7
|
+
import { createPsbtOptions } from '../../utils/psbt/createSignPsbtOptions.js';
|
|
8
|
+
|
|
9
|
+
class OneKeyConnector extends BitcoinWalletConnector {
|
|
10
|
+
constructor(opts) {
|
|
11
|
+
super(Object.assign(Object.assign({}, opts), { overrideKey: 'onekeybtc' }));
|
|
12
|
+
this.name = 'OneKey';
|
|
13
|
+
}
|
|
14
|
+
getAddress() {
|
|
15
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
16
|
+
var _a;
|
|
17
|
+
if (!this.isInstalledOnBrowser() &&
|
|
18
|
+
isMobile() &&
|
|
19
|
+
((_a = this.metadata) === null || _a === void 0 ? void 0 : _a.inAppBrowserUrl) &&
|
|
20
|
+
this.mobileExperience === 'in-app-browser') {
|
|
21
|
+
const inAppBrowserCompiledTemplate = template(this.metadata.inAppBrowserUrl);
|
|
22
|
+
const deepLink = inAppBrowserCompiledTemplate({
|
|
23
|
+
encodedDappURI: encodeURIComponent(window.location.toString()),
|
|
24
|
+
});
|
|
25
|
+
window.location.assign(deepLink);
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
const provider = this.getProvider();
|
|
29
|
+
if (!provider) {
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
const [address] = yield provider.requestAccounts();
|
|
33
|
+
const bitcoinAddress = {
|
|
34
|
+
address,
|
|
35
|
+
publicKey: yield provider.getPublicKey(),
|
|
36
|
+
};
|
|
37
|
+
yield this.setConnectedAccountWithAddresses({
|
|
38
|
+
active: true,
|
|
39
|
+
mainAddress: address,
|
|
40
|
+
ordinalsAddress: bitcoinAddress,
|
|
41
|
+
});
|
|
42
|
+
return address;
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
getConnectedAccounts() {
|
|
46
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
47
|
+
const provider = this.getProvider();
|
|
48
|
+
if (!provider) {
|
|
49
|
+
return [];
|
|
50
|
+
}
|
|
51
|
+
return provider.getAccounts();
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
signMessage(messageToSign, options) {
|
|
55
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
56
|
+
var _a;
|
|
57
|
+
const provider = this.getProvider();
|
|
58
|
+
if (!provider) {
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
// default to ecdsa
|
|
62
|
+
const protocol = (_a = options === null || options === void 0 ? void 0 : options.protocol) !== null && _a !== void 0 ? _a : 'ecdsa';
|
|
63
|
+
if (options === null || options === void 0 ? void 0 : options.address) {
|
|
64
|
+
logger.debug('[OneKeyConnector] signMessage - Not possible to specify address to sign with', {
|
|
65
|
+
address: options.address,
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
return provider.signMessage(messageToSign, protocol);
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
sendBitcoin(transaction) {
|
|
72
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
73
|
+
const provider = this.getProvider();
|
|
74
|
+
if (!provider) {
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
return provider.sendBitcoin(transaction.recipientAddress, transaction.amount.toString());
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
signPsbt(request) {
|
|
81
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
82
|
+
const provider = this.getProvider();
|
|
83
|
+
if (!provider) {
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
const psbtFromBase64 = Psbt.fromBase64(request.unsignedPsbtBase64);
|
|
87
|
+
const signedPsbtHex = yield provider.signPsbt(psbtFromBase64.toHex(), {
|
|
88
|
+
autoFinalized: false,
|
|
89
|
+
});
|
|
90
|
+
return { signedPsbt: Psbt.fromHex(signedPsbtHex).toBase64() };
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
signPsbts(requests) {
|
|
94
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
95
|
+
const provider = this.getProvider();
|
|
96
|
+
if (!provider) {
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
const psbtHexs = [];
|
|
100
|
+
const psbtOptions = [];
|
|
101
|
+
for (const request of requests) {
|
|
102
|
+
const psbt = Psbt.fromBase64(request.unsignedPsbtBase64);
|
|
103
|
+
psbtHexs.push(psbt.toHex());
|
|
104
|
+
psbtOptions.push(createPsbtOptions(psbt, request));
|
|
105
|
+
}
|
|
106
|
+
const signedPsbtHexs = yield provider.signPsbts(psbtHexs, {
|
|
107
|
+
autoFinalized: false,
|
|
108
|
+
});
|
|
109
|
+
return signedPsbtHexs.map((signedPsbtHex) => Psbt.fromHex(signedPsbtHex).toBase64());
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
export { OneKeyConnector };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { OneKeyConnector } from './OneKeyConnector';
|
|
@@ -0,0 +1,71 @@
|
|
|
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, options) {
|
|
38
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
39
|
+
const { address, protocol } = options;
|
|
40
|
+
const provider = this.getProvider();
|
|
41
|
+
if (!provider) {
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
const { signature } = yield provider.signMessage({
|
|
45
|
+
address,
|
|
46
|
+
message: messageToSign,
|
|
47
|
+
// Oyl Wallet calls it just bip322 instead of bip322-simple
|
|
48
|
+
protocol: protocol === 'bip322-simple' ? 'bip322' : protocol,
|
|
49
|
+
});
|
|
50
|
+
return signature;
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
signPsbt(request) {
|
|
54
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
55
|
+
const provider = this.getProvider();
|
|
56
|
+
if (!provider) {
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
const psbtFromBase64 = bitcoinjsLib.Psbt.fromBase64(request.unsignedPsbtBase64);
|
|
60
|
+
const options = createSignPsbtOptions.createPsbtOptions(psbtFromBase64, request);
|
|
61
|
+
const { psbt: signedPsbtHex } = yield provider.signPsbt({
|
|
62
|
+
broadcast: false,
|
|
63
|
+
finalize: options.autoFinalized,
|
|
64
|
+
psbt: psbtFromBase64.toHex(),
|
|
65
|
+
});
|
|
66
|
+
return { signedPsbt: bitcoinjsLib.Psbt.fromHex(signedPsbtHex).toBase64() };
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
exports.OylConnector = OylConnector;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { BitcoinWalletConnector, BitcoinWalletConnectorOpts } from '../BitcoinWalletConnector';
|
|
2
|
+
import { BitcoinSignPsbtRequest, BitcoinSignPsbtResponse, BitcoinSignProtocol } 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, options: {
|
|
9
|
+
address: string;
|
|
10
|
+
protocol?: BitcoinSignProtocol;
|
|
11
|
+
}): Promise<string | undefined>;
|
|
12
|
+
signPsbt(request: BitcoinSignPsbtRequest): Promise<BitcoinSignPsbtResponse | undefined>;
|
|
13
|
+
}
|