@dynamic-labs/bitcoin 3.0.0-alpha.9 → 3.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 +620 -0
- package/package.json +7 -6
- package/src/BitcoinLocalStorageCache.cjs +0 -16
- package/src/BitcoinLocalStorageCache.d.ts +0 -7
- package/src/BitcoinLocalStorageCache.js +0 -16
- package/src/bitcoinProviderHelper.d.ts +1 -0
- package/src/connectors/BitcoinSatsConnectConnector/BitcoinSatsConnectConnector.cjs +170 -141
- package/src/connectors/BitcoinSatsConnectConnector/BitcoinSatsConnectConnector.d.ts +8 -3
- package/src/connectors/BitcoinSatsConnectConnector/BitcoinSatsConnectConnector.js +171 -142
- package/src/connectors/BitcoinSatsConnectLegacyConnector/BitcoinSatsConnectLegacyConnector.cjs +216 -0
- package/src/connectors/BitcoinSatsConnectLegacyConnector/BitcoinSatsConnectLegacyConnector.d.ts +11 -0
- package/src/connectors/BitcoinSatsConnectLegacyConnector/BitcoinSatsConnectLegacyConnector.js +212 -0
- package/src/connectors/BitcoinSatsConnectLegacyConnector/index.d.ts +1 -0
- package/src/connectors/BitcoinWalletConnector.cjs +44 -29
- package/src/connectors/BitcoinWalletConnector.d.ts +7 -3
- package/src/connectors/BitcoinWalletConnector.js +45 -30
- package/src/connectors/FallbackBitcoinConnector/FallbackBitcoinConnector.cjs +7 -1
- package/src/connectors/FallbackBitcoinConnector/FallbackBitcoinConnector.d.ts +1 -1
- package/src/connectors/FallbackBitcoinConnector/FallbackBitcoinConnector.js +7 -1
- package/src/connectors/OkxConnector/OkxConnector.cjs +19 -2
- package/src/connectors/OkxConnector/OkxConnector.d.ts +1 -1
- package/src/connectors/OkxConnector/OkxConnector.js +19 -2
- package/src/connectors/PhantomConnector/PhantomConnector.cjs +4 -9
- package/src/connectors/PhantomConnector/PhantomConnector.d.ts +1 -2
- package/src/connectors/PhantomConnector/PhantomConnector.js +4 -9
- package/src/connectors/UnisatConnector/UnisatConnector.cjs +17 -1
- package/src/connectors/UnisatConnector/UnisatConnector.d.ts +1 -1
- package/src/connectors/UnisatConnector/UnisatConnector.js +17 -1
- package/src/connectors/UnknownInjected/UnknownInjected.cjs +7 -1
- package/src/connectors/UnknownInjected/UnknownInjected.d.ts +1 -1
- package/src/connectors/UnknownInjected/UnknownInjected.js +7 -1
- package/src/connectors/index.d.ts +1 -0
- package/src/index.cjs +4 -0
- package/src/index.d.ts +3 -2
- package/src/index.js +2 -0
- package/src/types.d.ts +1 -0
- package/src/utils/fetchSatsConnectConnectors/fetchSatsConnectConnectors.cjs +15 -3
- package/src/utils/fetchSatsConnectConnectors/fetchSatsConnectConnectors.js +15 -3
- package/src/utils/psbt/bitcoinNetworkTypeToNetworks.cjs +1 -0
- package/src/utils/psbt/bitcoinNetworkTypeToNetworks.d.ts +1 -1
- package/src/utils/psbt/bitcoinNetworkTypeToNetworks.js +1 -0
- package/src/utils/psbt/createSignPsbtOptions.cjs +22 -1
- package/src/utils/psbt/createSignPsbtOptions.d.ts +2 -0
- package/src/utils/psbt/createSignPsbtOptions.js +22 -2
- package/src/wallet/BitcoinWallet.cjs +69 -0
- package/src/wallet/BitcoinWallet.d.ts +36 -0
- package/src/wallet/BitcoinWallet.js +65 -0
- package/src/wallet/index.d.ts +2 -0
- package/src/wallet/isBitcoinWallet/index.d.ts +1 -0
- package/src/wallet/isBitcoinWallet/isBitcoinWallet.cjs +8 -0
- package/src/wallet/isBitcoinWallet/isBitcoinWallet.d.ts +3 -0
- package/src/wallet/isBitcoinWallet/isBitcoinWallet.js +4 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dynamic-labs/bitcoin",
|
|
3
|
-
"version": "3.0.0
|
|
3
|
+
"version": "3.0.0",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "git+https://github.com/dynamic-labs/dynamic-auth.git",
|
|
@@ -27,14 +27,15 @@
|
|
|
27
27
|
},
|
|
28
28
|
"dependencies": {
|
|
29
29
|
"@btckit/types": "0.0.19",
|
|
30
|
-
"@dynamic-labs/sdk-api-core": "0.0.
|
|
30
|
+
"@dynamic-labs/sdk-api-core": "0.0.529",
|
|
31
31
|
"@wallet-standard/app": "1.0.1",
|
|
32
32
|
"@wallet-standard/base": "1.0.1",
|
|
33
33
|
"bitcoinjs-lib": "6.1.5",
|
|
34
|
-
"sats-connect": "2.
|
|
35
|
-
"@dynamic-labs/
|
|
36
|
-
"@dynamic-labs/
|
|
37
|
-
"@dynamic-labs/wallet-
|
|
34
|
+
"sats-connect": "2.8.0",
|
|
35
|
+
"@dynamic-labs/types": "3.0.0",
|
|
36
|
+
"@dynamic-labs/utils": "3.0.0",
|
|
37
|
+
"@dynamic-labs/wallet-book": "3.0.0",
|
|
38
|
+
"@dynamic-labs/wallet-connector-core": "3.0.0",
|
|
38
39
|
"stream": "0.0.2"
|
|
39
40
|
},
|
|
40
41
|
"peerDependencies": {}
|
|
@@ -9,7 +9,6 @@ var utils = require('@dynamic-labs/utils');
|
|
|
9
9
|
class BitcoinLocalStorageCache {
|
|
10
10
|
constructor(key) {
|
|
11
11
|
this.CONNECTED_ACCOUNTS_KEY = `bitcoin_${key}_connectedAccounts`;
|
|
12
|
-
this.LAST_BALANCE_KEY = `bitcoin_${key}_lastBalance`;
|
|
13
12
|
}
|
|
14
13
|
getActiveAccount() {
|
|
15
14
|
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
@@ -63,21 +62,6 @@ class BitcoinLocalStorageCache {
|
|
|
63
62
|
return utils.removeItemAsync(this.CONNECTED_ACCOUNTS_KEY);
|
|
64
63
|
});
|
|
65
64
|
}
|
|
66
|
-
getLastBalance() {
|
|
67
|
-
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
68
|
-
return utils.getItemAsync(this.LAST_BALANCE_KEY);
|
|
69
|
-
});
|
|
70
|
-
}
|
|
71
|
-
setLastBalance(balance) {
|
|
72
|
-
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
73
|
-
return utils.setItemAsync(this.LAST_BALANCE_KEY, balance);
|
|
74
|
-
});
|
|
75
|
-
}
|
|
76
|
-
clearLastBalance() {
|
|
77
|
-
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
78
|
-
return utils.removeItemAsync(this.LAST_BALANCE_KEY);
|
|
79
|
-
});
|
|
80
|
-
}
|
|
81
65
|
}
|
|
82
66
|
|
|
83
67
|
exports.BitcoinLocalStorageCache = BitcoinLocalStorageCache;
|
|
@@ -9,16 +9,12 @@ type BitcoinActiveAccount = {
|
|
|
9
9
|
};
|
|
10
10
|
export declare class BitcoinLocalStorageCache implements IBitcoinSessionCache {
|
|
11
11
|
private readonly CONNECTED_ACCOUNTS_KEY;
|
|
12
|
-
private readonly LAST_BALANCE_KEY;
|
|
13
12
|
constructor(key: string);
|
|
14
13
|
getActiveAccount(): Promise<BitcoinActiveAccount | undefined>;
|
|
15
14
|
getConnectedAccounts(): Promise<BitcoinConnectedAccounts | undefined>;
|
|
16
15
|
getConnectedAccount(address: string): Promise<BitcoinConnectedAccount | undefined>;
|
|
17
16
|
setConnectedAccount(addess: string, account: BitcoinConnectedAccount): Promise<void>;
|
|
18
17
|
clearConnectedAcccounts(): Promise<void>;
|
|
19
|
-
getLastBalance(): Promise<string | undefined>;
|
|
20
|
-
setLastBalance(balance: string): Promise<void>;
|
|
21
|
-
clearLastBalance(): Promise<void>;
|
|
22
18
|
}
|
|
23
19
|
export interface IBitcoinSessionCache {
|
|
24
20
|
clearConnectedAcccounts(): Promise<void>;
|
|
@@ -26,8 +22,5 @@ export interface IBitcoinSessionCache {
|
|
|
26
22
|
getConnectedAccount(address: string): Promise<BitcoinConnectedAccount | undefined>;
|
|
27
23
|
getConnectedAccounts(): Promise<BitcoinConnectedAccounts | undefined>;
|
|
28
24
|
setConnectedAccount(addess: string, account: BitcoinConnectedAccount): Promise<void>;
|
|
29
|
-
clearLastBalance(): Promise<void>;
|
|
30
|
-
getLastBalance(): Promise<string | undefined>;
|
|
31
|
-
setLastBalance(balance: string): Promise<void>;
|
|
32
25
|
}
|
|
33
26
|
export {};
|
|
@@ -5,7 +5,6 @@ import { getItemAsync, setItemAsync, removeItemAsync } from '@dynamic-labs/utils
|
|
|
5
5
|
class BitcoinLocalStorageCache {
|
|
6
6
|
constructor(key) {
|
|
7
7
|
this.CONNECTED_ACCOUNTS_KEY = `bitcoin_${key}_connectedAccounts`;
|
|
8
|
-
this.LAST_BALANCE_KEY = `bitcoin_${key}_lastBalance`;
|
|
9
8
|
}
|
|
10
9
|
getActiveAccount() {
|
|
11
10
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -59,21 +58,6 @@ class BitcoinLocalStorageCache {
|
|
|
59
58
|
return removeItemAsync(this.CONNECTED_ACCOUNTS_KEY);
|
|
60
59
|
});
|
|
61
60
|
}
|
|
62
|
-
getLastBalance() {
|
|
63
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
64
|
-
return getItemAsync(this.LAST_BALANCE_KEY);
|
|
65
|
-
});
|
|
66
|
-
}
|
|
67
|
-
setLastBalance(balance) {
|
|
68
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
69
|
-
return setItemAsync(this.LAST_BALANCE_KEY, balance);
|
|
70
|
-
});
|
|
71
|
-
}
|
|
72
|
-
clearLastBalance() {
|
|
73
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
74
|
-
return removeItemAsync(this.LAST_BALANCE_KEY);
|
|
75
|
-
});
|
|
76
|
-
}
|
|
77
61
|
}
|
|
78
62
|
|
|
79
63
|
export { BitcoinLocalStorageCache };
|
|
@@ -8,36 +8,54 @@ var bitcoinjsLib = require('bitcoinjs-lib');
|
|
|
8
8
|
var satsConnect = require('sats-connect');
|
|
9
9
|
var utils = require('@dynamic-labs/utils');
|
|
10
10
|
var walletBook = require('@dynamic-labs/wallet-book');
|
|
11
|
-
var
|
|
12
|
-
require('@dynamic-labs/wallet-connector-core');
|
|
13
|
-
var BitcoinWalletConnector = require('../BitcoinWalletConnector.cjs');
|
|
14
|
-
var validatePsbt = require('../../utils/psbt/validator/validatePsbt.cjs');
|
|
15
|
-
var getSigHashType = require('../../utils/psbt/getSigHashType.cjs');
|
|
11
|
+
var walletConnectorCore = require('@dynamic-labs/wallet-connector-core');
|
|
16
12
|
var bitcoinNetworkTypeToNetworks = require('../../utils/psbt/bitcoinNetworkTypeToNetworks.cjs');
|
|
17
|
-
var
|
|
13
|
+
var BitcoinWalletConnector = require('../BitcoinWalletConnector.cjs');
|
|
14
|
+
var createSignPsbtOptions = require('../../utils/psbt/createSignPsbtOptions.cjs');
|
|
15
|
+
var _const = require('../../const.cjs');
|
|
18
16
|
|
|
19
17
|
class BitcoinSatsConnectConnector extends BitcoinWalletConnector.BitcoinWalletConnector {
|
|
20
18
|
constructor(opts) {
|
|
21
19
|
super(opts);
|
|
20
|
+
this.isLegacy = false;
|
|
22
21
|
this.currentNetwork = satsConnect.BitcoinNetworkType.Mainnet;
|
|
23
|
-
// satsconnect wallets don't support fetching connected accounts without prompting
|
|
24
|
-
// for a connection, so we handle getConnectedAccounts differently.
|
|
25
|
-
this.canFetchConnectedAccounts = false;
|
|
26
22
|
}
|
|
27
|
-
|
|
23
|
+
getGenericUserCancelledError() {
|
|
24
|
+
const error = new Error();
|
|
25
|
+
error.code = '-32000'; // error code for user cancelled
|
|
26
|
+
return error;
|
|
27
|
+
}
|
|
28
|
+
getAddresses() {
|
|
28
29
|
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
29
30
|
var _a;
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
if (!supportsSatsConnect.supportsSatsConnect(this)) {
|
|
36
|
-
return;
|
|
31
|
+
const getAddressResponse = yield satsConnect.request('getAddresses', {
|
|
32
|
+
purposes: [satsConnect.AddressPurpose.Payment, satsConnect.AddressPurpose.Ordinals],
|
|
33
|
+
});
|
|
34
|
+
if (getAddressResponse.status !== 'success') {
|
|
35
|
+
throw getAddressResponse.error;
|
|
37
36
|
}
|
|
37
|
+
const { addresses } = getAddressResponse.result;
|
|
38
|
+
const ordinalsAccount = addresses === null || addresses === void 0 ? void 0 : addresses.find((address) => address.purpose === satsConnect.AddressPurpose.Ordinals);
|
|
39
|
+
const paymentAccount = addresses === null || addresses === void 0 ? void 0 : addresses.find((address) => address.purpose === satsConnect.AddressPurpose.Payment);
|
|
40
|
+
const mainAddress = (_a = ordinalsAccount === null || ordinalsAccount === void 0 ? void 0 : ordinalsAccount.address) !== null && _a !== void 0 ? _a : paymentAccount === null || paymentAccount === void 0 ? void 0 : paymentAccount.address;
|
|
41
|
+
yield this.setConnectedAccountWithAddresses({
|
|
42
|
+
active: true,
|
|
43
|
+
mainAddress,
|
|
44
|
+
ordinalsAddress: ordinalsAccount,
|
|
45
|
+
paymentAddress: paymentAccount,
|
|
46
|
+
});
|
|
47
|
+
return mainAddress;
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
getAddress() {
|
|
51
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
52
|
+
var _a;
|
|
38
53
|
const wallet = walletBook.findWalletBookWallet(this.walletBook, this.key);
|
|
39
54
|
const inAppBrowserUrl = (_a = wallet === null || wallet === void 0 ? void 0 : wallet.mobile) === null || _a === void 0 ? void 0 : _a.inAppBrowser;
|
|
40
|
-
if (utils.isMobile() &&
|
|
55
|
+
if (utils.isMobile() &&
|
|
56
|
+
!this.isInstalledOnBrowser() &&
|
|
57
|
+
inAppBrowserUrl &&
|
|
58
|
+
this.mobileExperience === 'in-app-browser') {
|
|
41
59
|
const inAppBrowserTemplate = utils.template(inAppBrowserUrl);
|
|
42
60
|
const deepLink = inAppBrowserTemplate({
|
|
43
61
|
encodedDappURI: encodeURIComponent(window.location.toString()),
|
|
@@ -45,143 +63,123 @@ class BitcoinSatsConnectConnector extends BitcoinWalletConnector.BitcoinWalletCo
|
|
|
45
63
|
window.location.href = deepLink;
|
|
46
64
|
return;
|
|
47
65
|
}
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
const { addresses } = response;
|
|
62
|
-
const ordinalsAccount = addresses === null || addresses === void 0 ? void 0 : addresses.find((address) => address.purpose === satsConnect.AddressPurpose.Ordinals);
|
|
63
|
-
const paymentAccount = addresses === null || addresses === void 0 ? void 0 : addresses.find((address) => address.purpose === satsConnect.AddressPurpose.Payment);
|
|
64
|
-
const mainAddress = (_c = ordinalsAccount === null || ordinalsAccount === void 0 ? void 0 : ordinalsAccount.address) !== null && _c !== void 0 ? _c : paymentAccount === null || paymentAccount === void 0 ? void 0 : paymentAccount.address;
|
|
65
|
-
yield this.setConnectedAccountWithAddresses({
|
|
66
|
-
active: true,
|
|
67
|
-
mainAddress,
|
|
68
|
-
ordinalsAddress: ordinalsAccount,
|
|
69
|
-
paymentAddress: paymentAccount,
|
|
70
|
-
});
|
|
71
|
-
resolve(mainAddress);
|
|
72
|
-
}),
|
|
73
|
-
payload: {
|
|
74
|
-
message: 'Address for receiving Ordinals and payments',
|
|
75
|
-
network: {
|
|
76
|
-
type: this.currentNetwork,
|
|
77
|
-
},
|
|
78
|
-
purposes: [satsConnect.AddressPurpose.Ordinals, satsConnect.AddressPurpose.Payment],
|
|
79
|
-
},
|
|
80
|
-
});
|
|
81
|
-
});
|
|
66
|
+
try {
|
|
67
|
+
// requesting permissions on initial connect will avoid connection prompt for other requests
|
|
68
|
+
const permissionResponse = yield satsConnect.request('wallet_requestPermissions', undefined);
|
|
69
|
+
if (permissionResponse.status !== 'success') {
|
|
70
|
+
throw permissionResponse.error;
|
|
71
|
+
}
|
|
72
|
+
const address = yield this.getAddresses();
|
|
73
|
+
return address;
|
|
74
|
+
}
|
|
75
|
+
catch (_) {
|
|
76
|
+
const error = this.getGenericUserCancelledError();
|
|
77
|
+
throw error;
|
|
78
|
+
}
|
|
82
79
|
});
|
|
83
80
|
}
|
|
84
|
-
signMessage(messageToSign) {
|
|
81
|
+
signMessage(messageToSign, withAddress) {
|
|
85
82
|
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
return new Promise((resolve, reject) => {
|
|
91
|
-
satsConnect.signMessage({
|
|
92
|
-
getProvider: () => _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
93
|
-
var _a, _b;
|
|
94
|
-
return (_b = (_a = this.wallet) === null || _a === void 0 ? void 0 : _a.features[_const.SATSCONNECT_FEATURE]) === null || _b === void 0 ? void 0 : _b.provider;
|
|
95
|
-
}),
|
|
96
|
-
onCancel: () => {
|
|
97
|
-
const error = new Error();
|
|
98
|
-
error.code = '-32000'; // error code for user cancelled
|
|
99
|
-
reject(error);
|
|
100
|
-
},
|
|
101
|
-
onFinish: (response) => _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
102
|
-
if (this.isHardwareWalletEnabled) {
|
|
103
|
-
return resolve(JSON.stringify({
|
|
104
|
-
signedTransaction: {
|
|
105
|
-
data: response,
|
|
106
|
-
},
|
|
107
|
-
}));
|
|
108
|
-
}
|
|
109
|
-
resolve(response);
|
|
110
|
-
}),
|
|
111
|
-
payload: {
|
|
112
|
-
address: walletAddress,
|
|
113
|
-
message: messageToSign,
|
|
114
|
-
network: {
|
|
115
|
-
type: this.currentNetwork,
|
|
116
|
-
},
|
|
117
|
-
},
|
|
83
|
+
try {
|
|
84
|
+
const response = yield satsConnect.request('signMessage', {
|
|
85
|
+
address: withAddress,
|
|
86
|
+
message: messageToSign,
|
|
118
87
|
});
|
|
119
|
-
|
|
88
|
+
if (response.status !== 'success') {
|
|
89
|
+
throw response.error;
|
|
90
|
+
}
|
|
91
|
+
if (this.isHardwareWalletEnabled) {
|
|
92
|
+
return JSON.stringify({
|
|
93
|
+
signedTransaction: {
|
|
94
|
+
data: response.result.signature,
|
|
95
|
+
},
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
return response.result.signature;
|
|
99
|
+
}
|
|
100
|
+
catch (_) {
|
|
101
|
+
const error = this.getGenericUserCancelledError();
|
|
102
|
+
throw error;
|
|
103
|
+
}
|
|
120
104
|
});
|
|
121
105
|
}
|
|
122
106
|
sendBitcoin(transaction) {
|
|
123
107
|
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
return new Promise((resolve, reject) => {
|
|
131
|
-
satsConnect.sendBtcTransaction({
|
|
132
|
-
getProvider: () => _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
133
|
-
var _a, _b;
|
|
134
|
-
return (_b = (_a = this.wallet) === null || _a === void 0 ? void 0 : _a.features[_const.SATSCONNECT_FEATURE]) === null || _b === void 0 ? void 0 : _b.provider;
|
|
135
|
-
}),
|
|
136
|
-
onCancel: () => {
|
|
137
|
-
const error = new Error();
|
|
138
|
-
error.code = '-32000'; // error code for user cancelled
|
|
139
|
-
reject(error);
|
|
140
|
-
},
|
|
141
|
-
onFinish: (response) => {
|
|
142
|
-
resolve(response);
|
|
143
|
-
},
|
|
144
|
-
payload: {
|
|
145
|
-
network: {
|
|
146
|
-
type: this.currentNetwork,
|
|
108
|
+
try {
|
|
109
|
+
const response = yield satsConnect.request('sendTransfer', {
|
|
110
|
+
recipients: [
|
|
111
|
+
{
|
|
112
|
+
address: transaction.recipientAddress,
|
|
113
|
+
amount: Number(transaction.amount),
|
|
147
114
|
},
|
|
148
|
-
|
|
149
|
-
{
|
|
150
|
-
address: transaction.recipientAddress,
|
|
151
|
-
amountSats: transaction.amount,
|
|
152
|
-
},
|
|
153
|
-
],
|
|
154
|
-
senderAddress,
|
|
155
|
-
},
|
|
115
|
+
],
|
|
156
116
|
});
|
|
157
|
-
|
|
117
|
+
if (response.status !== 'success') {
|
|
118
|
+
throw response.error;
|
|
119
|
+
}
|
|
120
|
+
return response.result.txid;
|
|
121
|
+
}
|
|
122
|
+
catch (_) {
|
|
123
|
+
const error = this.getGenericUserCancelledError();
|
|
124
|
+
throw error;
|
|
125
|
+
}
|
|
158
126
|
});
|
|
159
127
|
}
|
|
160
128
|
signTransaction(params) {
|
|
161
129
|
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
162
|
-
const {
|
|
130
|
+
const { allowedSignHash, psbtBase64, broadcast, inputsToSign } = params;
|
|
131
|
+
const signPbstPayload = {
|
|
132
|
+
allowedSignHash,
|
|
133
|
+
broadcast,
|
|
134
|
+
psbt: psbtBase64,
|
|
135
|
+
// we have to combine signing indexes for like addresses
|
|
136
|
+
signInputs: inputsToSign.reduce((accum, curr) => {
|
|
137
|
+
if (!accum[curr.address]) {
|
|
138
|
+
accum[curr.address] = [];
|
|
139
|
+
}
|
|
140
|
+
accum[curr.address].push(...curr.signingIndexes);
|
|
141
|
+
return accum;
|
|
142
|
+
}, {}),
|
|
143
|
+
};
|
|
144
|
+
walletConnectorCore.logger.logVerboseTroubleshootingMessage('[BitcoinSatsConnectConnector] signTransaction', {
|
|
145
|
+
signPbstPayload,
|
|
146
|
+
});
|
|
147
|
+
try {
|
|
148
|
+
const response = yield satsConnect.request('signPsbt', signPbstPayload);
|
|
149
|
+
if (response.status !== 'success') {
|
|
150
|
+
throw response.error;
|
|
151
|
+
}
|
|
152
|
+
return { psbtBase64: response.result.psbt, txId: response.result.txid };
|
|
153
|
+
}
|
|
154
|
+
catch (_) {
|
|
155
|
+
const error = this.getGenericUserCancelledError();
|
|
156
|
+
throw error;
|
|
157
|
+
}
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
signTransactions(transactions) {
|
|
161
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
162
|
+
const { message, psbts, network } = transactions;
|
|
163
|
+
walletConnectorCore.logger.logVerboseTroubleshootingMessage('[BitcoinSatsConnectConnector] signTransactions', {
|
|
164
|
+
transactions,
|
|
165
|
+
});
|
|
163
166
|
return new Promise((resolve, reject) => {
|
|
164
|
-
satsConnect.
|
|
167
|
+
satsConnect.signMultipleTransactions({
|
|
165
168
|
getProvider: () => _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
166
169
|
var _a, _b;
|
|
167
170
|
return (_b = (_a = this.wallet) === null || _a === void 0 ? void 0 : _a.features[_const.SATSCONNECT_FEATURE]) === null || _b === void 0 ? void 0 : _b.provider;
|
|
168
171
|
}),
|
|
169
172
|
onCancel: () => {
|
|
170
|
-
const error =
|
|
171
|
-
error.code = '-32000'; // error code for user cancelled
|
|
173
|
+
const error = this.getGenericUserCancelledError();
|
|
172
174
|
reject(error);
|
|
173
175
|
},
|
|
174
176
|
onFinish: (response) => {
|
|
175
177
|
resolve(response);
|
|
176
178
|
},
|
|
177
179
|
payload: {
|
|
178
|
-
broadcast,
|
|
179
|
-
inputsToSign,
|
|
180
180
|
message: message || 'Sign Transaction',
|
|
181
|
-
network
|
|
182
|
-
|
|
183
|
-
},
|
|
184
|
-
psbtBase64,
|
|
181
|
+
network,
|
|
182
|
+
psbts,
|
|
185
183
|
},
|
|
186
184
|
});
|
|
187
185
|
});
|
|
@@ -189,27 +187,22 @@ class BitcoinSatsConnectConnector extends BitcoinWalletConnector.BitcoinWalletCo
|
|
|
189
187
|
}
|
|
190
188
|
signPsbt(request) {
|
|
191
189
|
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
192
|
-
var _a
|
|
190
|
+
var _a;
|
|
193
191
|
if (!((_a = request.allowedSighash) === null || _a === void 0 ? void 0 : _a.length))
|
|
194
192
|
throw new Error('allowedSighash cannot be an empty array');
|
|
195
193
|
const network = bitcoinNetworkTypeToNetworks.convertNetworkTypeForPsbt(this.currentNetwork);
|
|
196
194
|
const psbtFromBase64 = bitcoinjsLib.Psbt.fromBase64(request.unsignedPsbtBase64, {
|
|
197
195
|
network,
|
|
198
196
|
});
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
return ((_a = sig.signingIndexes) !== null && _a !== void 0 ? _a : []).map((inputIndex) => ({
|
|
205
|
-
address: sig.address,
|
|
206
|
-
sigHash: getSigHashType.getSigHashType(psbtFromBase64.data.inputs[inputIndex]),
|
|
207
|
-
signingIndexes: [inputIndex],
|
|
208
|
-
}));
|
|
209
|
-
})) !== null && _d !== void 0 ? _d : []).flat();
|
|
197
|
+
walletConnectorCore.logger.logVerboseTroubleshootingMessage('signPsbt', {
|
|
198
|
+
isLegacy: this.isLegacy,
|
|
199
|
+
psbtFromBase64,
|
|
200
|
+
request,
|
|
201
|
+
});
|
|
210
202
|
const signedPsbt = yield this.signTransaction({
|
|
203
|
+
allowedSignHash: request.allowedSighash[0],
|
|
211
204
|
broadcast: false,
|
|
212
|
-
inputsToSign,
|
|
205
|
+
inputsToSign: createSignPsbtOptions.createSignPsbtOptionsForSatsConnect(psbtFromBase64, request, this.isLegacy),
|
|
213
206
|
psbtBase64: request.unsignedPsbtBase64,
|
|
214
207
|
});
|
|
215
208
|
if (!signedPsbt) {
|
|
@@ -218,6 +211,42 @@ class BitcoinSatsConnectConnector extends BitcoinWalletConnector.BitcoinWalletCo
|
|
|
218
211
|
return { signedPsbt: signedPsbt.psbtBase64 };
|
|
219
212
|
});
|
|
220
213
|
}
|
|
214
|
+
signPsbts(requests) {
|
|
215
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
216
|
+
var _a;
|
|
217
|
+
const network = bitcoinNetworkTypeToNetworks.convertNetworkTypeForPsbt(this.currentNetwork);
|
|
218
|
+
const signMultipleTransactionPayload = {
|
|
219
|
+
message: 'Sign Transaction',
|
|
220
|
+
network: {
|
|
221
|
+
type: this.currentNetwork,
|
|
222
|
+
},
|
|
223
|
+
psbts: [],
|
|
224
|
+
};
|
|
225
|
+
for (const request of requests) {
|
|
226
|
+
const psbtFromBase64 = bitcoinjsLib.Psbt.fromBase64(request.unsignedPsbtBase64, {
|
|
227
|
+
network,
|
|
228
|
+
});
|
|
229
|
+
const inputsToSign = createSignPsbtOptions.createSignPsbtOptionsForSatsConnect(psbtFromBase64, request, this.isLegacy);
|
|
230
|
+
signMultipleTransactionPayload.psbts.push({
|
|
231
|
+
inputsToSign,
|
|
232
|
+
psbtBase64: request.unsignedPsbtBase64,
|
|
233
|
+
});
|
|
234
|
+
}
|
|
235
|
+
walletConnectorCore.logger.logVerboseTroubleshootingMessage('signPsbts', signMultipleTransactionPayload);
|
|
236
|
+
const signedPsbts = yield this.signTransactions(signMultipleTransactionPayload);
|
|
237
|
+
return (_a = signedPsbts === null || signedPsbts === void 0 ? void 0 : signedPsbts.map((signedPsbts) => signedPsbts.psbtBase64)) !== null && _a !== void 0 ? _a : [];
|
|
238
|
+
});
|
|
239
|
+
}
|
|
240
|
+
validateActiveWallet(expectedAddress) {
|
|
241
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
242
|
+
// TODO: this is a workaround to avoid extra connecting prompt for xverse
|
|
243
|
+
// we should revisit it once xverse releases a new version with bug fixes
|
|
244
|
+
walletConnectorCore.logger.debug('validateActiveWallet - skipping validation for xverse', {
|
|
245
|
+
expectedAddress,
|
|
246
|
+
});
|
|
247
|
+
return;
|
|
248
|
+
});
|
|
249
|
+
}
|
|
221
250
|
}
|
|
222
251
|
|
|
223
252
|
exports.BitcoinSatsConnectConnector = BitcoinSatsConnectConnector;
|
|
@@ -1,13 +1,18 @@
|
|
|
1
|
-
import { BitcoinNetworkType, SignTransactionResponse } from 'sats-connect';
|
|
1
|
+
import { BitcoinNetworkType, SignMultipleTransactionsPayload, SignTransactionResponse } from 'sats-connect';
|
|
2
2
|
import { BitcoinSignPsbtRequest, BitcoinSignPsbtResponse, BitcoinTransaction, SatsConnectSignTransactionInput } from '../../types';
|
|
3
3
|
import { BitcoinWalletConnector, BitcoinWalletConnectorOpts } from '../BitcoinWalletConnector';
|
|
4
4
|
export declare abstract class BitcoinSatsConnectConnector extends BitcoinWalletConnector {
|
|
5
|
+
isLegacy: boolean;
|
|
5
6
|
currentNetwork: BitcoinNetworkType;
|
|
6
|
-
canFetchConnectedAccounts: boolean;
|
|
7
7
|
constructor(opts: BitcoinWalletConnectorOpts);
|
|
8
|
+
private getGenericUserCancelledError;
|
|
9
|
+
private getAddresses;
|
|
8
10
|
getAddress(): Promise<string | undefined>;
|
|
9
|
-
signMessage(messageToSign: string): Promise<string | undefined>;
|
|
11
|
+
signMessage(messageToSign: string, withAddress: string): Promise<string | undefined>;
|
|
10
12
|
sendBitcoin(transaction: BitcoinTransaction): Promise<string | undefined>;
|
|
11
13
|
signTransaction(params: SatsConnectSignTransactionInput): Promise<SignTransactionResponse | undefined>;
|
|
14
|
+
signTransactions(transactions: SignMultipleTransactionsPayload): Promise<SignTransactionResponse[] | undefined>;
|
|
12
15
|
signPsbt(request: BitcoinSignPsbtRequest): Promise<BitcoinSignPsbtResponse | undefined>;
|
|
16
|
+
signPsbts(requests: BitcoinSignPsbtRequest[]): Promise<string[] | undefined>;
|
|
17
|
+
validateActiveWallet(expectedAddress: string): Promise<void>;
|
|
13
18
|
}
|