@dynamic-labs/bitcoin 2.2.0 → 2.2.2
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 +15 -0
- package/package.json +4 -4
- package/src/connectors/BitcoinSatsConnectConnector/BitcoinSatsConnectConnector.cjs +4 -12
- package/src/connectors/BitcoinSatsConnectConnector/BitcoinSatsConnectConnector.js +4 -12
- package/src/connectors/BitcoinWalletConnector.cjs +16 -2
- package/src/connectors/BitcoinWalletConnector.d.ts +3 -0
- package/src/connectors/BitcoinWalletConnector.js +16 -2
- package/src/index.cjs +0 -1
- package/src/index.js +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,4 +1,19 @@
|
|
|
1
1
|
|
|
2
|
+
### [2.2.2](https://github.com/dynamic-labs/DynamicAuth/compare/v2.2.1...v2.2.2) (2024-06-18)
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
### Bug Fixes
|
|
6
|
+
|
|
7
|
+
* make account change idemopotent ([#6062](https://github.com/dynamic-labs/DynamicAuth/issues/6062)) ([2308d32](https://github.com/dynamic-labs/DynamicAuth/commit/2308d32d18627f2673c8f4c9b5623a9c731e4752))
|
|
8
|
+
|
|
9
|
+
### [2.2.1](https://github.com/dynamic-labs/DynamicAuth/compare/v2.2.0...v2.2.1) (2024-06-17)
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
### Bug Fixes
|
|
13
|
+
|
|
14
|
+
* improve handling of bitcoin connected accounts ([#6049](https://github.com/dynamic-labs/DynamicAuth/issues/6049)) ([08cb8ba](https://github.com/dynamic-labs/DynamicAuth/commit/08cb8bae2b1521367234cbe2bb55a8c3766df3c1))
|
|
15
|
+
* improve wagmi hooks with embedded wallets ([#6044](https://github.com/dynamic-labs/DynamicAuth/issues/6044)) ([#6052](https://github.com/dynamic-labs/DynamicAuth/issues/6052)) ([28654e8](https://github.com/dynamic-labs/DynamicAuth/commit/28654e8a45b25c4fc3bb3abfa89b453808a55053))
|
|
16
|
+
|
|
2
17
|
## [2.2.0](https://github.com/dynamic-labs/DynamicAuth/compare/v2.1.5...v2.2.0) (2024-06-16)
|
|
3
18
|
|
|
4
19
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dynamic-labs/bitcoin",
|
|
3
|
-
"version": "2.2.
|
|
3
|
+
"version": "2.2.2",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "git+https://github.com/dynamic-labs/dynamic-auth.git",
|
|
@@ -32,9 +32,9 @@
|
|
|
32
32
|
"@wallet-standard/base": "1.0.1",
|
|
33
33
|
"bitcoinjs-lib": "6.1.5",
|
|
34
34
|
"sats-connect": "2.0.0",
|
|
35
|
-
"@dynamic-labs/utils": "2.2.
|
|
36
|
-
"@dynamic-labs/wallet-book": "2.2.
|
|
37
|
-
"@dynamic-labs/wallet-connector-core": "2.2.
|
|
35
|
+
"@dynamic-labs/utils": "2.2.2",
|
|
36
|
+
"@dynamic-labs/wallet-book": "2.2.2",
|
|
37
|
+
"@dynamic-labs/wallet-connector-core": "2.2.2",
|
|
38
38
|
"stream": "0.0.2"
|
|
39
39
|
},
|
|
40
40
|
"peerDependencies": {}
|
|
@@ -6,7 +6,6 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
6
6
|
var _tslib = require('../../../_virtual/_tslib.cjs');
|
|
7
7
|
var bitcoinjsLib = require('bitcoinjs-lib');
|
|
8
8
|
var satsConnect = require('sats-connect');
|
|
9
|
-
var sdkApiCore = require('@dynamic-labs/sdk-api-core');
|
|
10
9
|
var utils = require('@dynamic-labs/utils');
|
|
11
10
|
var walletBook = require('@dynamic-labs/wallet-book');
|
|
12
11
|
var _const = require('../../const.cjs');
|
|
@@ -21,14 +20,13 @@ class BitcoinSatsConnectConnector extends BitcoinWalletConnector.BitcoinWalletCo
|
|
|
21
20
|
constructor(opts) {
|
|
22
21
|
super(opts);
|
|
23
22
|
this.currentNetwork = satsConnect.BitcoinNetworkType.Mainnet;
|
|
24
|
-
|
|
25
|
-
//
|
|
26
|
-
|
|
27
|
-
this.canFetchConnectedAccounts = this.key !== 'xverse';
|
|
23
|
+
// satsconnect wallets don't support fetching connected accounts without prompting
|
|
24
|
+
// for a connection, so we handle getConnectedAccounts differently.
|
|
25
|
+
this.canFetchConnectedAccounts = false;
|
|
28
26
|
}
|
|
29
27
|
getAddress() {
|
|
30
28
|
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
31
|
-
var _a
|
|
29
|
+
var _a;
|
|
32
30
|
// xverse doesn't support wallet standard, so we won't have a wallet object,
|
|
33
31
|
// but it's already the default provider for sats-connect, so it's ok
|
|
34
32
|
// for getProvider in getAddress to return undefined
|
|
@@ -47,12 +45,6 @@ class BitcoinSatsConnectConnector extends BitcoinWalletConnector.BitcoinWalletCo
|
|
|
47
45
|
window.location.href = deepLink;
|
|
48
46
|
return;
|
|
49
47
|
}
|
|
50
|
-
const cachedActiveAccount = yield this.cache.getActiveAccount();
|
|
51
|
-
if (cachedActiveAccount) {
|
|
52
|
-
const ordinalsAddress = cachedActiveAccount.additionalAddresses.find((address) => address.type === sdkApiCore.WalletAddressType.Ordinals);
|
|
53
|
-
const paymentAddress = cachedActiveAccount.additionalAddresses.find((address) => address.type === sdkApiCore.WalletAddressType.Payment);
|
|
54
|
-
return (_b = ordinalsAddress === null || ordinalsAddress === void 0 ? void 0 : ordinalsAddress.address) !== null && _b !== void 0 ? _b : paymentAddress === null || paymentAddress === void 0 ? void 0 : paymentAddress.address;
|
|
55
|
-
}
|
|
56
48
|
return new Promise((resolve, reject) => {
|
|
57
49
|
satsConnect.getAddress({
|
|
58
50
|
getProvider: () => _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
import { __awaiter } from '../../../_virtual/_tslib.js';
|
|
3
3
|
import { Psbt } from 'bitcoinjs-lib';
|
|
4
4
|
import { BitcoinNetworkType, getAddress, AddressPurpose, signMessage, sendBtcTransaction, signTransaction } from 'sats-connect';
|
|
5
|
-
import { WalletAddressType } from '@dynamic-labs/sdk-api-core';
|
|
6
5
|
import { isMobile, template } from '@dynamic-labs/utils';
|
|
7
6
|
import { findWalletBookWallet } from '@dynamic-labs/wallet-book';
|
|
8
7
|
import { SATSCONNECT_FEATURE } from '../../const.js';
|
|
@@ -17,14 +16,13 @@ class BitcoinSatsConnectConnector extends BitcoinWalletConnector {
|
|
|
17
16
|
constructor(opts) {
|
|
18
17
|
super(opts);
|
|
19
18
|
this.currentNetwork = BitcoinNetworkType.Mainnet;
|
|
20
|
-
|
|
21
|
-
//
|
|
22
|
-
|
|
23
|
-
this.canFetchConnectedAccounts = this.key !== 'xverse';
|
|
19
|
+
// satsconnect wallets don't support fetching connected accounts without prompting
|
|
20
|
+
// for a connection, so we handle getConnectedAccounts differently.
|
|
21
|
+
this.canFetchConnectedAccounts = false;
|
|
24
22
|
}
|
|
25
23
|
getAddress() {
|
|
26
24
|
return __awaiter(this, void 0, void 0, function* () {
|
|
27
|
-
var _a
|
|
25
|
+
var _a;
|
|
28
26
|
// xverse doesn't support wallet standard, so we won't have a wallet object,
|
|
29
27
|
// but it's already the default provider for sats-connect, so it's ok
|
|
30
28
|
// for getProvider in getAddress to return undefined
|
|
@@ -43,12 +41,6 @@ class BitcoinSatsConnectConnector extends BitcoinWalletConnector {
|
|
|
43
41
|
window.location.href = deepLink;
|
|
44
42
|
return;
|
|
45
43
|
}
|
|
46
|
-
const cachedActiveAccount = yield this.cache.getActiveAccount();
|
|
47
|
-
if (cachedActiveAccount) {
|
|
48
|
-
const ordinalsAddress = cachedActiveAccount.additionalAddresses.find((address) => address.type === WalletAddressType.Ordinals);
|
|
49
|
-
const paymentAddress = cachedActiveAccount.additionalAddresses.find((address) => address.type === WalletAddressType.Payment);
|
|
50
|
-
return (_b = ordinalsAddress === null || ordinalsAddress === void 0 ? void 0 : ordinalsAddress.address) !== null && _b !== void 0 ? _b : paymentAddress === null || paymentAddress === void 0 ? void 0 : paymentAddress.address;
|
|
51
|
-
}
|
|
52
44
|
return new Promise((resolve, reject) => {
|
|
53
45
|
getAddress({
|
|
54
46
|
getProvider: () => __awaiter(this, void 0, void 0, function* () {
|
|
@@ -33,6 +33,12 @@ class BitcoinWalletConnector extends walletConnectorCore.WalletConnectorBase {
|
|
|
33
33
|
}
|
|
34
34
|
this.cache = new BitcoinLocalStorageCache.BitcoinLocalStorageCache(this.overrideKey);
|
|
35
35
|
}
|
|
36
|
+
isSameAccountChangeRequest(to) {
|
|
37
|
+
return this.lastAccountChange === to;
|
|
38
|
+
}
|
|
39
|
+
setLastAccountChangeRequest(to) {
|
|
40
|
+
this.lastAccountChange = to;
|
|
41
|
+
}
|
|
36
42
|
clearConnectedAccounts() {
|
|
37
43
|
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
38
44
|
yield this.cache.clearConnectedAcccounts();
|
|
@@ -53,7 +59,10 @@ class BitcoinWalletConnector extends walletConnectorCore.WalletConnectorBase {
|
|
|
53
59
|
}
|
|
54
60
|
endSession() {
|
|
55
61
|
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
56
|
-
yield
|
|
62
|
+
yield Promise.all([
|
|
63
|
+
this.cache.clearConnectedAcccounts(),
|
|
64
|
+
this.cache.clearLastBalance(),
|
|
65
|
+
]);
|
|
57
66
|
});
|
|
58
67
|
}
|
|
59
68
|
getBalance() {
|
|
@@ -234,9 +243,14 @@ class BitcoinWalletConnector extends walletConnectorCore.WalletConnectorBase {
|
|
|
234
243
|
}
|
|
235
244
|
const currentConnectedAccounts = yield this.getConnectedAccountsFromCache();
|
|
236
245
|
// don't do anything if the connected accounts haven't changed
|
|
237
|
-
if
|
|
246
|
+
// or if the account change request is the same as previous request
|
|
247
|
+
if (currentConnectedAccounts[0] === connectedAccounts[0] ||
|
|
248
|
+
this.isSameAccountChangeRequest(connectedAccounts[0])) {
|
|
238
249
|
return;
|
|
239
250
|
}
|
|
251
|
+
// set the last account change request with the from and to addresses
|
|
252
|
+
// to ensure that the requests are not duplicated
|
|
253
|
+
this.setLastAccountChangeRequest(connectedAccounts[0]);
|
|
240
254
|
handleAccountChange(connectedAccounts);
|
|
241
255
|
});
|
|
242
256
|
provider.on('accountsChanged', handleBitcoinAccountChange);
|
|
@@ -23,7 +23,10 @@ export declare abstract class BitcoinWalletConnector extends WalletConnectorBase
|
|
|
23
23
|
canFetchConnectedAccounts: boolean;
|
|
24
24
|
isHardwareWalletEnabled: boolean;
|
|
25
25
|
verifiedCredentials: JwtVerifiedCredential[];
|
|
26
|
+
private lastAccountChange;
|
|
26
27
|
constructor(opts: BitcoinWalletConnectorOpts);
|
|
28
|
+
private isSameAccountChangeRequest;
|
|
29
|
+
private setLastAccountChangeRequest;
|
|
27
30
|
clearConnectedAccounts(): Promise<void>;
|
|
28
31
|
canConnectWithHardwareWallet(): boolean;
|
|
29
32
|
isInstalledOnBrowser(): boolean;
|
|
@@ -29,6 +29,12 @@ class BitcoinWalletConnector extends WalletConnectorBase {
|
|
|
29
29
|
}
|
|
30
30
|
this.cache = new BitcoinLocalStorageCache(this.overrideKey);
|
|
31
31
|
}
|
|
32
|
+
isSameAccountChangeRequest(to) {
|
|
33
|
+
return this.lastAccountChange === to;
|
|
34
|
+
}
|
|
35
|
+
setLastAccountChangeRequest(to) {
|
|
36
|
+
this.lastAccountChange = to;
|
|
37
|
+
}
|
|
32
38
|
clearConnectedAccounts() {
|
|
33
39
|
return __awaiter(this, void 0, void 0, function* () {
|
|
34
40
|
yield this.cache.clearConnectedAcccounts();
|
|
@@ -49,7 +55,10 @@ class BitcoinWalletConnector extends WalletConnectorBase {
|
|
|
49
55
|
}
|
|
50
56
|
endSession() {
|
|
51
57
|
return __awaiter(this, void 0, void 0, function* () {
|
|
52
|
-
yield
|
|
58
|
+
yield Promise.all([
|
|
59
|
+
this.cache.clearConnectedAcccounts(),
|
|
60
|
+
this.cache.clearLastBalance(),
|
|
61
|
+
]);
|
|
53
62
|
});
|
|
54
63
|
}
|
|
55
64
|
getBalance() {
|
|
@@ -230,9 +239,14 @@ class BitcoinWalletConnector extends WalletConnectorBase {
|
|
|
230
239
|
}
|
|
231
240
|
const currentConnectedAccounts = yield this.getConnectedAccountsFromCache();
|
|
232
241
|
// don't do anything if the connected accounts haven't changed
|
|
233
|
-
if
|
|
242
|
+
// or if the account change request is the same as previous request
|
|
243
|
+
if (currentConnectedAccounts[0] === connectedAccounts[0] ||
|
|
244
|
+
this.isSameAccountChangeRequest(connectedAccounts[0])) {
|
|
234
245
|
return;
|
|
235
246
|
}
|
|
247
|
+
// set the last account change request with the from and to addresses
|
|
248
|
+
// to ensure that the requests are not duplicated
|
|
249
|
+
this.setLastAccountChangeRequest(connectedAccounts[0]);
|
|
236
250
|
handleAccountChange(connectedAccounts);
|
|
237
251
|
});
|
|
238
252
|
provider.on('accountsChanged', handleBitcoinAccountChange);
|
package/src/index.cjs
CHANGED
|
@@ -9,7 +9,6 @@ require('sats-connect');
|
|
|
9
9
|
require('bitcoinjs-lib');
|
|
10
10
|
require('@dynamic-labs/wallet-connector-core');
|
|
11
11
|
require('@dynamic-labs/utils');
|
|
12
|
-
require('@dynamic-labs/sdk-api-core');
|
|
13
12
|
require('@dynamic-labs/wallet-book');
|
|
14
13
|
var fetchBtcKitConnectors = require('./utils/fetchBtcKitConnectors/fetchBtcKitConnectors.cjs');
|
|
15
14
|
var fetchSatsConnectConnectors = require('./utils/fetchSatsConnectConnectors/fetchSatsConnectConnectors.cjs');
|
package/src/index.js
CHANGED
|
@@ -5,7 +5,6 @@ import 'sats-connect';
|
|
|
5
5
|
import 'bitcoinjs-lib';
|
|
6
6
|
import '@dynamic-labs/wallet-connector-core';
|
|
7
7
|
import '@dynamic-labs/utils';
|
|
8
|
-
import '@dynamic-labs/sdk-api-core';
|
|
9
8
|
import '@dynamic-labs/wallet-book';
|
|
10
9
|
import { fetchBtcKitConnectors } from './utils/fetchBtcKitConnectors/fetchBtcKitConnectors.js';
|
|
11
10
|
export { fetchBtcKitConnectors } from './utils/fetchBtcKitConnectors/fetchBtcKitConnectors.js';
|