@dynamic-labs/bitcoin 1.1.0-alpha.3 → 1.1.0-alpha.5
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 +17 -0
- package/_virtual/_tslib.cjs +30 -0
- package/_virtual/_tslib.js +26 -0
- package/package.json +11 -2
- package/src/BitcoinLocalStorageCache.cjs +50 -0
- package/src/BitcoinLocalStorageCache.d.ts +20 -0
- package/src/BitcoinLocalStorageCache.js +46 -0
- package/src/BitcoinSatsConnectConnector.cjs +127 -0
- package/src/BitcoinSatsConnectConnector.d.ts +10 -0
- package/src/BitcoinSatsConnectConnector.js +123 -0
- package/src/BitcoinWalletConnectorBase.cjs +108 -0
- package/src/BitcoinWalletConnectorBase.d.ts +26 -0
- package/src/BitcoinWalletConnectorBase.js +104 -0
- package/src/bitcoinProviderHelper.cjs +60 -0
- package/src/bitcoinProviderHelper.d.ts +22 -0
- package/src/bitcoinProviderHelper.js +56 -0
- package/src/bitcoinWalletStandardWallets.cjs +33 -0
- package/src/bitcoinWalletStandardWallets.d.ts +12 -0
- package/src/bitcoinWalletStandardWallets.js +28 -0
- package/src/const.cjs +15 -0
- package/src/const.d.ts +6 -0
- package/src/const.js +7 -0
- package/src/fetchSatsConnectConnectors.cjs +32 -0
- package/src/fetchSatsConnectConnectors.d.ts +5 -0
- package/src/fetchSatsConnectConnectors.js +28 -0
- package/src/index.cjs +5 -1
- package/src/index.d.ts +1 -1
- package/src/index.js +5 -1
- package/src/types.d.ts +18 -0
- package/src/utils/hasSatsConnectFeature.cjs +9 -0
- package/src/utils/hasSatsConnectFeature.d.ts +2 -0
- package/src/utils/hasSatsConnectFeature.js +5 -0
- package/src/utils/index.d.ts +3 -0
- package/src/utils/isBitcoinConnector.d.ts +3 -0
- package/src/utils/supportsSatsConnect.cjs +18 -0
- package/src/utils/supportsSatsConnect.d.ts +2 -0
- package/src/utils/supportsSatsConnect.js +14 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,4 +1,21 @@
|
|
|
1
1
|
|
|
2
|
+
## [1.1.0-alpha.5](https://github.com/dynamic-labs/DynamicAuth/compare/v1.1.0-alpha.4...v1.1.0-alpha.5) (2023-12-21)
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
### Features
|
|
6
|
+
|
|
7
|
+
* add support for xverse wallet ([#4245](https://github.com/dynamic-labs/DynamicAuth/issues/4245)) ([7b68546](https://github.com/dynamic-labs/DynamicAuth/commit/7b6854684412007bcb33896555900936395176df))
|
|
8
|
+
* **gvty-526:** add embedded reveal ([#4233](https://github.com/dynamic-labs/DynamicAuth/issues/4233)) ([c2d0f90](https://github.com/dynamic-labs/DynamicAuth/commit/c2d0f903f4a4646f86c71834540fd49d51a4a7ae))
|
|
9
|
+
|
|
10
|
+
## [1.1.0-alpha.4](https://github.com/dynamic-labs/DynamicAuth/compare/v1.1.0-alpha.3...v1.1.0-alpha.4) (2023-12-21)
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
### Features
|
|
14
|
+
|
|
15
|
+
* add bitcoin integration ([#4216](https://github.com/dynamic-labs/DynamicAuth/issues/4216)) ([9584f1c](https://github.com/dynamic-labs/DynamicAuth/commit/9584f1cc3133835049ad1c53da980192263b8f21))
|
|
16
|
+
* add default footer to wallet list when tos and pp not enabled ([#4224](https://github.com/dynamic-labs/DynamicAuth/issues/4224)) ([0ad81c4](https://github.com/dynamic-labs/DynamicAuth/commit/0ad81c409bcb4aafb0dc565685525d620a95efce))
|
|
17
|
+
* adds useConnectWithEmailOtp ([#4234](https://github.com/dynamic-labs/DynamicAuth/issues/4234)) ([4a4e50a](https://github.com/dynamic-labs/DynamicAuth/commit/4a4e50ac8651c2a249d5125ae6bcf49aaf49be8c))
|
|
18
|
+
|
|
2
19
|
## [1.1.0-alpha.3](https://github.com/dynamic-labs/DynamicAuth/compare/v1.1.0-alpha.2...v1.1.0-alpha.3) (2023-12-19)
|
|
3
20
|
|
|
4
21
|
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
/******************************************************************************
|
|
6
|
+
Copyright (c) Microsoft Corporation.
|
|
7
|
+
|
|
8
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
|
9
|
+
purpose with or without fee is hereby granted.
|
|
10
|
+
|
|
11
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
12
|
+
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
13
|
+
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
14
|
+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
15
|
+
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
16
|
+
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
17
|
+
PERFORMANCE OF THIS SOFTWARE.
|
|
18
|
+
***************************************************************************** */
|
|
19
|
+
|
|
20
|
+
function __awaiter(thisArg, _arguments, P, generator) {
|
|
21
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
22
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
23
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
24
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
25
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
26
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
exports.__awaiter = __awaiter;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/******************************************************************************
|
|
2
|
+
Copyright (c) Microsoft Corporation.
|
|
3
|
+
|
|
4
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
|
5
|
+
purpose with or without fee is hereby granted.
|
|
6
|
+
|
|
7
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
8
|
+
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
9
|
+
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
10
|
+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
11
|
+
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
12
|
+
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
13
|
+
PERFORMANCE OF THIS SOFTWARE.
|
|
14
|
+
***************************************************************************** */
|
|
15
|
+
|
|
16
|
+
function __awaiter(thisArg, _arguments, P, generator) {
|
|
17
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
18
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
19
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
20
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
21
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
22
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export { __awaiter };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dynamic-labs/bitcoin",
|
|
3
|
-
"version": "1.1.0-alpha.
|
|
3
|
+
"version": "1.1.0-alpha.5",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "https://github.com/dynamic-labs/DynamicAuth.git",
|
|
@@ -24,5 +24,14 @@
|
|
|
24
24
|
"require": "./src/index.cjs"
|
|
25
25
|
},
|
|
26
26
|
"./package.json": "./package.json"
|
|
27
|
-
}
|
|
27
|
+
},
|
|
28
|
+
"dependencies": {
|
|
29
|
+
"@wallet-standard/app": "^1.0.1",
|
|
30
|
+
"@wallet-standard/base": "^1.0.1",
|
|
31
|
+
"sats-connect": "^1.1.2",
|
|
32
|
+
"@dynamic-labs/utils": "1.1.0-alpha.5",
|
|
33
|
+
"@dynamic-labs/wallet-book": "1.1.0-alpha.5",
|
|
34
|
+
"@dynamic-labs/wallet-connector-core": "1.1.0-alpha.5"
|
|
35
|
+
},
|
|
36
|
+
"peerDependencies": {}
|
|
28
37
|
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var _tslib = require('../_virtual/_tslib.cjs');
|
|
6
|
+
var utils = require('@dynamic-labs/utils');
|
|
7
|
+
|
|
8
|
+
class BitcoinLocalStorageCache {
|
|
9
|
+
constructor(key) {
|
|
10
|
+
this.CONNECTED_ACCOUNT_KEY = `bitcoin_${key}_connectedAccount`;
|
|
11
|
+
this.LAST_BALANCE_KEY = `bitcoin_${key}_lastBalance`;
|
|
12
|
+
}
|
|
13
|
+
getCurrentAccount() {
|
|
14
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
15
|
+
const account = yield utils.getItemAsync(this.CONNECTED_ACCOUNT_KEY);
|
|
16
|
+
return account;
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
setCurrentAccount(account) {
|
|
20
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
21
|
+
return utils.setItemAsync(this.CONNECTED_ACCOUNT_KEY, account);
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
clearCurrentAcccount() {
|
|
25
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
26
|
+
return utils.removeItemAsync(this.CONNECTED_ACCOUNT_KEY);
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
getLastBalance() {
|
|
30
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
31
|
+
const balance = yield utils.getItemAsync(this.LAST_BALANCE_KEY);
|
|
32
|
+
if (!balance) {
|
|
33
|
+
return undefined;
|
|
34
|
+
}
|
|
35
|
+
return balance;
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
setLastBalance(balance) {
|
|
39
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
40
|
+
return utils.setItemAsync(this.LAST_BALANCE_KEY, balance);
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
clearLastBalance() {
|
|
44
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
45
|
+
return utils.removeItemAsync(this.LAST_BALANCE_KEY);
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
exports.BitcoinLocalStorageCache = BitcoinLocalStorageCache;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { BitcoinAccount } from './types';
|
|
2
|
+
export declare class BitcoinLocalStorageCache implements IBitcoinSessionCache {
|
|
3
|
+
private readonly CONNECTED_ACCOUNT_KEY;
|
|
4
|
+
private readonly LAST_BALANCE_KEY;
|
|
5
|
+
constructor(key: string);
|
|
6
|
+
getCurrentAccount(): Promise<BitcoinAccount | undefined>;
|
|
7
|
+
setCurrentAccount(account: BitcoinAccount): Promise<void>;
|
|
8
|
+
clearCurrentAcccount(): Promise<void>;
|
|
9
|
+
getLastBalance(): Promise<string | undefined>;
|
|
10
|
+
setLastBalance(balance: string): Promise<void>;
|
|
11
|
+
clearLastBalance(): Promise<void>;
|
|
12
|
+
}
|
|
13
|
+
export interface IBitcoinSessionCache {
|
|
14
|
+
clearCurrentAcccount(): Promise<void>;
|
|
15
|
+
getCurrentAccount(): Promise<BitcoinAccount | undefined>;
|
|
16
|
+
setCurrentAccount(account: BitcoinAccount): Promise<void>;
|
|
17
|
+
clearLastBalance(): Promise<void>;
|
|
18
|
+
getLastBalance(): Promise<string | undefined>;
|
|
19
|
+
setLastBalance(balance: string): Promise<void>;
|
|
20
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { __awaiter } from '../_virtual/_tslib.js';
|
|
2
|
+
import { getItemAsync, setItemAsync, removeItemAsync } from '@dynamic-labs/utils';
|
|
3
|
+
|
|
4
|
+
class BitcoinLocalStorageCache {
|
|
5
|
+
constructor(key) {
|
|
6
|
+
this.CONNECTED_ACCOUNT_KEY = `bitcoin_${key}_connectedAccount`;
|
|
7
|
+
this.LAST_BALANCE_KEY = `bitcoin_${key}_lastBalance`;
|
|
8
|
+
}
|
|
9
|
+
getCurrentAccount() {
|
|
10
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
11
|
+
const account = yield getItemAsync(this.CONNECTED_ACCOUNT_KEY);
|
|
12
|
+
return account;
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
setCurrentAccount(account) {
|
|
16
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
17
|
+
return setItemAsync(this.CONNECTED_ACCOUNT_KEY, account);
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
clearCurrentAcccount() {
|
|
21
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
22
|
+
return removeItemAsync(this.CONNECTED_ACCOUNT_KEY);
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
getLastBalance() {
|
|
26
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
27
|
+
const balance = yield getItemAsync(this.LAST_BALANCE_KEY);
|
|
28
|
+
if (!balance) {
|
|
29
|
+
return undefined;
|
|
30
|
+
}
|
|
31
|
+
return balance;
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
setLastBalance(balance) {
|
|
35
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
36
|
+
return setItemAsync(this.LAST_BALANCE_KEY, balance);
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
clearLastBalance() {
|
|
40
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
41
|
+
return removeItemAsync(this.LAST_BALANCE_KEY);
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export { BitcoinLocalStorageCache };
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var _tslib = require('../_virtual/_tslib.cjs');
|
|
6
|
+
var satsConnect = require('sats-connect');
|
|
7
|
+
var BitcoinWalletConnectorBase = require('./BitcoinWalletConnectorBase.cjs');
|
|
8
|
+
var _const = require('./const.cjs');
|
|
9
|
+
var supportsSatsConnect = require('./utils/supportsSatsConnect.cjs');
|
|
10
|
+
|
|
11
|
+
class BitcoinSatsConnectConnector extends BitcoinWalletConnectorBase.BitcoinWalletConnectorBase {
|
|
12
|
+
constructor(opts) {
|
|
13
|
+
super(opts);
|
|
14
|
+
this.currentNetwork = satsConnect.BitcoinNetworkType.Mainnet;
|
|
15
|
+
}
|
|
16
|
+
fetchPublicAddress() {
|
|
17
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
18
|
+
// xverse doesn't support wallet standard, so we won't have a wallet object,
|
|
19
|
+
// but it's already the default provider for sats-connect, so it's ok
|
|
20
|
+
// for getProvider in getAddress to return undefined
|
|
21
|
+
// if we're not using xverse, we need to check if there is a wallet and
|
|
22
|
+
// that it has the satsconnect feature to return the correct provider to use
|
|
23
|
+
if (!supportsSatsConnect.supportsSatsConnect(this)) {
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
return new Promise((resolve, reject) => {
|
|
27
|
+
satsConnect.getAddress({
|
|
28
|
+
getProvider: () => _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
29
|
+
var _a, _b;
|
|
30
|
+
return (_b = (_a = this.wallet) === null || _a === void 0 ? void 0 : _a.features[_const.SATSCONNECT_FEATURE]) === null || _b === void 0 ? void 0 : _b.provider;
|
|
31
|
+
}),
|
|
32
|
+
onCancel: () => {
|
|
33
|
+
const error = new Error();
|
|
34
|
+
error.code = '-32000'; // error code for user cancelled
|
|
35
|
+
reject(error);
|
|
36
|
+
},
|
|
37
|
+
onFinish: (response) => _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
38
|
+
var _c, _d, _e;
|
|
39
|
+
const { addresses } = response;
|
|
40
|
+
const bitcoinAccount = {
|
|
41
|
+
ordinalsAddress: (_c = addresses === null || addresses === void 0 ? void 0 : addresses.find((address) => address.purpose === satsConnect.AddressPurpose.Ordinals)) === null || _c === void 0 ? void 0 : _c.address,
|
|
42
|
+
paymentAddress: (_d = addresses === null || addresses === void 0 ? void 0 : addresses.find((address) => address.purpose === satsConnect.AddressPurpose.Payment)) === null || _d === void 0 ? void 0 : _d.address,
|
|
43
|
+
};
|
|
44
|
+
yield this.cache.setCurrentAccount(bitcoinAccount);
|
|
45
|
+
resolve((_e = bitcoinAccount.ordinalsAddress) !== null && _e !== void 0 ? _e : bitcoinAccount.paymentAddress);
|
|
46
|
+
}),
|
|
47
|
+
payload: {
|
|
48
|
+
message: 'Address for receiving Ordinals and payments',
|
|
49
|
+
network: {
|
|
50
|
+
type: this.currentNetwork,
|
|
51
|
+
},
|
|
52
|
+
purposes: [satsConnect.AddressPurpose.Ordinals, satsConnect.AddressPurpose.Payment],
|
|
53
|
+
},
|
|
54
|
+
});
|
|
55
|
+
});
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
signMessage(messageToSign) {
|
|
59
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
60
|
+
const [walletAddress] = yield this.getConnectedAccounts();
|
|
61
|
+
if (!walletAddress || !supportsSatsConnect.supportsSatsConnect(this)) {
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
return new Promise((resolve, reject) => {
|
|
65
|
+
satsConnect.signMessage({
|
|
66
|
+
getProvider: () => _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
67
|
+
var _a, _b;
|
|
68
|
+
return (_b = (_a = this.wallet) === null || _a === void 0 ? void 0 : _a.features[_const.SATSCONNECT_FEATURE]) === null || _b === void 0 ? void 0 : _b.provider;
|
|
69
|
+
}),
|
|
70
|
+
onCancel: () => {
|
|
71
|
+
const error = new Error();
|
|
72
|
+
error.code = '-32000'; // error code for user cancelled
|
|
73
|
+
reject(error);
|
|
74
|
+
},
|
|
75
|
+
onFinish: (response) => _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
76
|
+
resolve(response);
|
|
77
|
+
}),
|
|
78
|
+
payload: {
|
|
79
|
+
address: walletAddress,
|
|
80
|
+
message: messageToSign,
|
|
81
|
+
network: {
|
|
82
|
+
type: this.currentNetwork,
|
|
83
|
+
},
|
|
84
|
+
},
|
|
85
|
+
});
|
|
86
|
+
});
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
sendTransaction(transaction) {
|
|
90
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
91
|
+
const paymentAddress = yield this.getPaymentAddress();
|
|
92
|
+
if (!paymentAddress || !supportsSatsConnect.supportsSatsConnect(this)) {
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
return new Promise((resolve, reject) => {
|
|
96
|
+
satsConnect.sendBtcTransaction({
|
|
97
|
+
getProvider: () => _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
98
|
+
var _a, _b;
|
|
99
|
+
return (_b = (_a = this.wallet) === null || _a === void 0 ? void 0 : _a.features[_const.SATSCONNECT_FEATURE]) === null || _b === void 0 ? void 0 : _b.provider;
|
|
100
|
+
}),
|
|
101
|
+
onCancel: () => {
|
|
102
|
+
const error = new Error();
|
|
103
|
+
error.code = '-32000'; // error code for user cancelled
|
|
104
|
+
reject(error);
|
|
105
|
+
},
|
|
106
|
+
onFinish: (response) => {
|
|
107
|
+
resolve(response);
|
|
108
|
+
},
|
|
109
|
+
payload: {
|
|
110
|
+
network: {
|
|
111
|
+
type: this.currentNetwork,
|
|
112
|
+
},
|
|
113
|
+
recipients: [
|
|
114
|
+
{
|
|
115
|
+
address: transaction.recipientAddress,
|
|
116
|
+
amountSats: transaction.amount,
|
|
117
|
+
},
|
|
118
|
+
],
|
|
119
|
+
senderAddress: paymentAddress,
|
|
120
|
+
},
|
|
121
|
+
});
|
|
122
|
+
});
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
exports.BitcoinSatsConnectConnector = BitcoinSatsConnectConnector;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { BitcoinNetworkType } from 'sats-connect';
|
|
2
|
+
import { BitcoinWalletConnectorBase, BitcoinWalletConnectorBaseOpts } from './BitcoinWalletConnectorBase';
|
|
3
|
+
import { BitcoinTransaction } from './types';
|
|
4
|
+
export declare abstract class BitcoinSatsConnectConnector extends BitcoinWalletConnectorBase {
|
|
5
|
+
currentNetwork: BitcoinNetworkType;
|
|
6
|
+
constructor(opts: BitcoinWalletConnectorBaseOpts);
|
|
7
|
+
fetchPublicAddress(): Promise<string | undefined>;
|
|
8
|
+
signMessage(messageToSign: string): Promise<string | undefined>;
|
|
9
|
+
sendTransaction(transaction: BitcoinTransaction): Promise<string | undefined>;
|
|
10
|
+
}
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import { __awaiter } from '../_virtual/_tslib.js';
|
|
2
|
+
import { BitcoinNetworkType, getAddress, AddressPurpose, signMessage, sendBtcTransaction } from 'sats-connect';
|
|
3
|
+
import { BitcoinWalletConnectorBase } from './BitcoinWalletConnectorBase.js';
|
|
4
|
+
import { SATSCONNECT_FEATURE } from './const.js';
|
|
5
|
+
import { supportsSatsConnect } from './utils/supportsSatsConnect.js';
|
|
6
|
+
|
|
7
|
+
class BitcoinSatsConnectConnector extends BitcoinWalletConnectorBase {
|
|
8
|
+
constructor(opts) {
|
|
9
|
+
super(opts);
|
|
10
|
+
this.currentNetwork = BitcoinNetworkType.Mainnet;
|
|
11
|
+
}
|
|
12
|
+
fetchPublicAddress() {
|
|
13
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
14
|
+
// xverse doesn't support wallet standard, so we won't have a wallet object,
|
|
15
|
+
// but it's already the default provider for sats-connect, so it's ok
|
|
16
|
+
// for getProvider in getAddress to return undefined
|
|
17
|
+
// if we're not using xverse, we need to check if there is a wallet and
|
|
18
|
+
// that it has the satsconnect feature to return the correct provider to use
|
|
19
|
+
if (!supportsSatsConnect(this)) {
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
return new Promise((resolve, reject) => {
|
|
23
|
+
getAddress({
|
|
24
|
+
getProvider: () => __awaiter(this, void 0, void 0, function* () {
|
|
25
|
+
var _a, _b;
|
|
26
|
+
return (_b = (_a = this.wallet) === null || _a === void 0 ? void 0 : _a.features[SATSCONNECT_FEATURE]) === null || _b === void 0 ? void 0 : _b.provider;
|
|
27
|
+
}),
|
|
28
|
+
onCancel: () => {
|
|
29
|
+
const error = new Error();
|
|
30
|
+
error.code = '-32000'; // error code for user cancelled
|
|
31
|
+
reject(error);
|
|
32
|
+
},
|
|
33
|
+
onFinish: (response) => __awaiter(this, void 0, void 0, function* () {
|
|
34
|
+
var _c, _d, _e;
|
|
35
|
+
const { addresses } = response;
|
|
36
|
+
const bitcoinAccount = {
|
|
37
|
+
ordinalsAddress: (_c = addresses === null || addresses === void 0 ? void 0 : addresses.find((address) => address.purpose === AddressPurpose.Ordinals)) === null || _c === void 0 ? void 0 : _c.address,
|
|
38
|
+
paymentAddress: (_d = addresses === null || addresses === void 0 ? void 0 : addresses.find((address) => address.purpose === AddressPurpose.Payment)) === null || _d === void 0 ? void 0 : _d.address,
|
|
39
|
+
};
|
|
40
|
+
yield this.cache.setCurrentAccount(bitcoinAccount);
|
|
41
|
+
resolve((_e = bitcoinAccount.ordinalsAddress) !== null && _e !== void 0 ? _e : bitcoinAccount.paymentAddress);
|
|
42
|
+
}),
|
|
43
|
+
payload: {
|
|
44
|
+
message: 'Address for receiving Ordinals and payments',
|
|
45
|
+
network: {
|
|
46
|
+
type: this.currentNetwork,
|
|
47
|
+
},
|
|
48
|
+
purposes: [AddressPurpose.Ordinals, AddressPurpose.Payment],
|
|
49
|
+
},
|
|
50
|
+
});
|
|
51
|
+
});
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
signMessage(messageToSign) {
|
|
55
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
56
|
+
const [walletAddress] = yield this.getConnectedAccounts();
|
|
57
|
+
if (!walletAddress || !supportsSatsConnect(this)) {
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
return new Promise((resolve, reject) => {
|
|
61
|
+
signMessage({
|
|
62
|
+
getProvider: () => __awaiter(this, void 0, void 0, function* () {
|
|
63
|
+
var _a, _b;
|
|
64
|
+
return (_b = (_a = this.wallet) === null || _a === void 0 ? void 0 : _a.features[SATSCONNECT_FEATURE]) === null || _b === void 0 ? void 0 : _b.provider;
|
|
65
|
+
}),
|
|
66
|
+
onCancel: () => {
|
|
67
|
+
const error = new Error();
|
|
68
|
+
error.code = '-32000'; // error code for user cancelled
|
|
69
|
+
reject(error);
|
|
70
|
+
},
|
|
71
|
+
onFinish: (response) => __awaiter(this, void 0, void 0, function* () {
|
|
72
|
+
resolve(response);
|
|
73
|
+
}),
|
|
74
|
+
payload: {
|
|
75
|
+
address: walletAddress,
|
|
76
|
+
message: messageToSign,
|
|
77
|
+
network: {
|
|
78
|
+
type: this.currentNetwork,
|
|
79
|
+
},
|
|
80
|
+
},
|
|
81
|
+
});
|
|
82
|
+
});
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
sendTransaction(transaction) {
|
|
86
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
87
|
+
const paymentAddress = yield this.getPaymentAddress();
|
|
88
|
+
if (!paymentAddress || !supportsSatsConnect(this)) {
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
return new Promise((resolve, reject) => {
|
|
92
|
+
sendBtcTransaction({
|
|
93
|
+
getProvider: () => __awaiter(this, void 0, void 0, function* () {
|
|
94
|
+
var _a, _b;
|
|
95
|
+
return (_b = (_a = this.wallet) === null || _a === void 0 ? void 0 : _a.features[SATSCONNECT_FEATURE]) === null || _b === void 0 ? void 0 : _b.provider;
|
|
96
|
+
}),
|
|
97
|
+
onCancel: () => {
|
|
98
|
+
const error = new Error();
|
|
99
|
+
error.code = '-32000'; // error code for user cancelled
|
|
100
|
+
reject(error);
|
|
101
|
+
},
|
|
102
|
+
onFinish: (response) => {
|
|
103
|
+
resolve(response);
|
|
104
|
+
},
|
|
105
|
+
payload: {
|
|
106
|
+
network: {
|
|
107
|
+
type: this.currentNetwork,
|
|
108
|
+
},
|
|
109
|
+
recipients: [
|
|
110
|
+
{
|
|
111
|
+
address: transaction.recipientAddress,
|
|
112
|
+
amountSats: transaction.amount,
|
|
113
|
+
},
|
|
114
|
+
],
|
|
115
|
+
senderAddress: paymentAddress,
|
|
116
|
+
},
|
|
117
|
+
});
|
|
118
|
+
});
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
export { BitcoinSatsConnectConnector };
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var _tslib = require('../_virtual/_tslib.cjs');
|
|
6
|
+
var walletConnectorCore = require('@dynamic-labs/wallet-connector-core');
|
|
7
|
+
var walletBook = require('@dynamic-labs/wallet-book');
|
|
8
|
+
var utils = require('@dynamic-labs/utils');
|
|
9
|
+
var bitcoinProviderHelper = require('./bitcoinProviderHelper.cjs');
|
|
10
|
+
var BitcoinLocalStorageCache = require('./BitcoinLocalStorageCache.cjs');
|
|
11
|
+
var _const = require('./const.cjs');
|
|
12
|
+
|
|
13
|
+
class BitcoinWalletConnectorBase extends walletConnectorCore.WalletConnectorBase {
|
|
14
|
+
constructor(opts) {
|
|
15
|
+
var _a;
|
|
16
|
+
super(opts);
|
|
17
|
+
this.connectedChain = 'BTC';
|
|
18
|
+
this.supportedChains = ['BTC'];
|
|
19
|
+
// this is the key from the wallet book entry so that we don't purely rely on the normalized name
|
|
20
|
+
this.overrideKey = (_a = opts.overrideKey) !== null && _a !== void 0 ? _a : this.key;
|
|
21
|
+
this.bitcoinProviderHelper = new bitcoinProviderHelper.BitcoinProviderHelper(opts.walletData || walletBook.getWalletBookWallet(this.walletBook, this.key));
|
|
22
|
+
this.wallet = this.bitcoinProviderHelper.findWallet();
|
|
23
|
+
this.cache = new BitcoinLocalStorageCache.BitcoinLocalStorageCache(this.overrideKey);
|
|
24
|
+
}
|
|
25
|
+
isInstalledOnBrowser() {
|
|
26
|
+
var _a, _b;
|
|
27
|
+
return (Boolean(this.wallet) ||
|
|
28
|
+
Boolean((_b = (_a = this.bitcoinProviderHelper) === null || _a === void 0 ? void 0 : _a.installedProviders()) === null || _b === void 0 ? void 0 : _b.length));
|
|
29
|
+
}
|
|
30
|
+
getDeepLink() {
|
|
31
|
+
return undefined;
|
|
32
|
+
}
|
|
33
|
+
getBalance() {
|
|
34
|
+
var _a;
|
|
35
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
36
|
+
const addresses = yield Promise.all([
|
|
37
|
+
this.getPaymentAddress(),
|
|
38
|
+
this.getOrdinalsAddress(),
|
|
39
|
+
]);
|
|
40
|
+
if (!addresses[0] && !addresses[1]) {
|
|
41
|
+
throw new utils.DynamicError('getBalance - No connected address found!');
|
|
42
|
+
}
|
|
43
|
+
const fetchAddress = (_a = addresses[0]) !== null && _a !== void 0 ? _a : addresses[1];
|
|
44
|
+
const response = yield fetch(`${_const.BALANCE_API_URL}${fetchAddress}`);
|
|
45
|
+
if (!response.ok) {
|
|
46
|
+
// if the request fails due to rate limits, return cached value
|
|
47
|
+
if (response.status === _const.HTTP_STATUS_TOO_MANY_REQUESTS) {
|
|
48
|
+
return this.cache.getLastBalance();
|
|
49
|
+
}
|
|
50
|
+
// new accounts not yet indexed will return a 404
|
|
51
|
+
if (response.status === _const.HTTP_STATUS_NOT_FOUND) {
|
|
52
|
+
return '0';
|
|
53
|
+
}
|
|
54
|
+
return undefined;
|
|
55
|
+
}
|
|
56
|
+
const addressInfo = yield response.json();
|
|
57
|
+
if (!(addressInfo === null || addressInfo === void 0 ? void 0 : addressInfo.chain_stats)) {
|
|
58
|
+
return undefined;
|
|
59
|
+
}
|
|
60
|
+
const balance = (Number(addressInfo.chain_stats.funded_txo_sum) -
|
|
61
|
+
Number(addressInfo.chain_stats.spent_txo_sum)) /
|
|
62
|
+
100000000;
|
|
63
|
+
yield this.cache.setLastBalance(balance.toString());
|
|
64
|
+
return balance.toString();
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
endSession() {
|
|
68
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
69
|
+
yield Promise.all([
|
|
70
|
+
this.cache.clearCurrentAcccount(),
|
|
71
|
+
this.cache.clearLastBalance(),
|
|
72
|
+
]);
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
getConnectedAccounts() {
|
|
76
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
77
|
+
const currentAccount = yield this.cache.getCurrentAccount();
|
|
78
|
+
// ordinals address is the preferred address
|
|
79
|
+
if (currentAccount === null || currentAccount === void 0 ? void 0 : currentAccount.ordinalsAddress) {
|
|
80
|
+
return [currentAccount === null || currentAccount === void 0 ? void 0 : currentAccount.ordinalsAddress];
|
|
81
|
+
}
|
|
82
|
+
if (currentAccount === null || currentAccount === void 0 ? void 0 : currentAccount.paymentAddress) {
|
|
83
|
+
return [currentAccount === null || currentAccount === void 0 ? void 0 : currentAccount.paymentAddress];
|
|
84
|
+
}
|
|
85
|
+
return [];
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
getPaymentAddress() {
|
|
89
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
90
|
+
const currentAccount = yield this.cache.getCurrentAccount();
|
|
91
|
+
if (!currentAccount) {
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
return currentAccount.paymentAddress;
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
getOrdinalsAddress() {
|
|
98
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
99
|
+
const currentAccount = yield this.cache.getCurrentAccount();
|
|
100
|
+
if (!currentAccount) {
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
return currentAccount.ordinalsAddress;
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
exports.BitcoinWalletConnectorBase = BitcoinWalletConnectorBase;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { Wallet } from '@wallet-standard/base';
|
|
2
|
+
import { Chain, WalletConnectorBase } from '@dynamic-labs/wallet-connector-core';
|
|
3
|
+
import { WalletBookSchema, WalletSchema } from '@dynamic-labs/wallet-book';
|
|
4
|
+
import { IBitcoinSessionCache } from './BitcoinLocalStorageCache';
|
|
5
|
+
import { BitcoinTransaction } from './types';
|
|
6
|
+
export type BitcoinWalletConnectorBaseOpts = {
|
|
7
|
+
walletBook: WalletBookSchema;
|
|
8
|
+
walletData: WalletSchema;
|
|
9
|
+
overrideKey?: string;
|
|
10
|
+
};
|
|
11
|
+
export declare abstract class BitcoinWalletConnectorBase extends WalletConnectorBase {
|
|
12
|
+
cache: IBitcoinSessionCache;
|
|
13
|
+
connectedChain: Chain;
|
|
14
|
+
supportedChains: Chain[];
|
|
15
|
+
private bitcoinProviderHelper;
|
|
16
|
+
wallet: Wallet | undefined;
|
|
17
|
+
constructor(opts: BitcoinWalletConnectorBaseOpts);
|
|
18
|
+
isInstalledOnBrowser(): boolean;
|
|
19
|
+
getDeepLink(): string | undefined;
|
|
20
|
+
getBalance(): Promise<string | undefined>;
|
|
21
|
+
endSession(): Promise<void>;
|
|
22
|
+
getConnectedAccounts(): Promise<string[]>;
|
|
23
|
+
getPaymentAddress(): Promise<string | undefined>;
|
|
24
|
+
getOrdinalsAddress(): Promise<string | undefined>;
|
|
25
|
+
abstract sendTransaction(transaction: BitcoinTransaction): Promise<string | undefined>;
|
|
26
|
+
}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import { __awaiter } from '../_virtual/_tslib.js';
|
|
2
|
+
import { WalletConnectorBase } from '@dynamic-labs/wallet-connector-core';
|
|
3
|
+
import { getWalletBookWallet } from '@dynamic-labs/wallet-book';
|
|
4
|
+
import { DynamicError } from '@dynamic-labs/utils';
|
|
5
|
+
import { BitcoinProviderHelper } from './bitcoinProviderHelper.js';
|
|
6
|
+
import { BitcoinLocalStorageCache } from './BitcoinLocalStorageCache.js';
|
|
7
|
+
import { BALANCE_API_URL, HTTP_STATUS_TOO_MANY_REQUESTS, HTTP_STATUS_NOT_FOUND } from './const.js';
|
|
8
|
+
|
|
9
|
+
class BitcoinWalletConnectorBase extends WalletConnectorBase {
|
|
10
|
+
constructor(opts) {
|
|
11
|
+
var _a;
|
|
12
|
+
super(opts);
|
|
13
|
+
this.connectedChain = 'BTC';
|
|
14
|
+
this.supportedChains = ['BTC'];
|
|
15
|
+
// this is the key from the wallet book entry so that we don't purely rely on the normalized name
|
|
16
|
+
this.overrideKey = (_a = opts.overrideKey) !== null && _a !== void 0 ? _a : this.key;
|
|
17
|
+
this.bitcoinProviderHelper = new BitcoinProviderHelper(opts.walletData || getWalletBookWallet(this.walletBook, this.key));
|
|
18
|
+
this.wallet = this.bitcoinProviderHelper.findWallet();
|
|
19
|
+
this.cache = new BitcoinLocalStorageCache(this.overrideKey);
|
|
20
|
+
}
|
|
21
|
+
isInstalledOnBrowser() {
|
|
22
|
+
var _a, _b;
|
|
23
|
+
return (Boolean(this.wallet) ||
|
|
24
|
+
Boolean((_b = (_a = this.bitcoinProviderHelper) === null || _a === void 0 ? void 0 : _a.installedProviders()) === null || _b === void 0 ? void 0 : _b.length));
|
|
25
|
+
}
|
|
26
|
+
getDeepLink() {
|
|
27
|
+
return undefined;
|
|
28
|
+
}
|
|
29
|
+
getBalance() {
|
|
30
|
+
var _a;
|
|
31
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
32
|
+
const addresses = yield Promise.all([
|
|
33
|
+
this.getPaymentAddress(),
|
|
34
|
+
this.getOrdinalsAddress(),
|
|
35
|
+
]);
|
|
36
|
+
if (!addresses[0] && !addresses[1]) {
|
|
37
|
+
throw new DynamicError('getBalance - No connected address found!');
|
|
38
|
+
}
|
|
39
|
+
const fetchAddress = (_a = addresses[0]) !== null && _a !== void 0 ? _a : addresses[1];
|
|
40
|
+
const response = yield fetch(`${BALANCE_API_URL}${fetchAddress}`);
|
|
41
|
+
if (!response.ok) {
|
|
42
|
+
// if the request fails due to rate limits, return cached value
|
|
43
|
+
if (response.status === HTTP_STATUS_TOO_MANY_REQUESTS) {
|
|
44
|
+
return this.cache.getLastBalance();
|
|
45
|
+
}
|
|
46
|
+
// new accounts not yet indexed will return a 404
|
|
47
|
+
if (response.status === HTTP_STATUS_NOT_FOUND) {
|
|
48
|
+
return '0';
|
|
49
|
+
}
|
|
50
|
+
return undefined;
|
|
51
|
+
}
|
|
52
|
+
const addressInfo = yield response.json();
|
|
53
|
+
if (!(addressInfo === null || addressInfo === void 0 ? void 0 : addressInfo.chain_stats)) {
|
|
54
|
+
return undefined;
|
|
55
|
+
}
|
|
56
|
+
const balance = (Number(addressInfo.chain_stats.funded_txo_sum) -
|
|
57
|
+
Number(addressInfo.chain_stats.spent_txo_sum)) /
|
|
58
|
+
100000000;
|
|
59
|
+
yield this.cache.setLastBalance(balance.toString());
|
|
60
|
+
return balance.toString();
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
endSession() {
|
|
64
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
65
|
+
yield Promise.all([
|
|
66
|
+
this.cache.clearCurrentAcccount(),
|
|
67
|
+
this.cache.clearLastBalance(),
|
|
68
|
+
]);
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
getConnectedAccounts() {
|
|
72
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
73
|
+
const currentAccount = yield this.cache.getCurrentAccount();
|
|
74
|
+
// ordinals address is the preferred address
|
|
75
|
+
if (currentAccount === null || currentAccount === void 0 ? void 0 : currentAccount.ordinalsAddress) {
|
|
76
|
+
return [currentAccount === null || currentAccount === void 0 ? void 0 : currentAccount.ordinalsAddress];
|
|
77
|
+
}
|
|
78
|
+
if (currentAccount === null || currentAccount === void 0 ? void 0 : currentAccount.paymentAddress) {
|
|
79
|
+
return [currentAccount === null || currentAccount === void 0 ? void 0 : currentAccount.paymentAddress];
|
|
80
|
+
}
|
|
81
|
+
return [];
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
getPaymentAddress() {
|
|
85
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
86
|
+
const currentAccount = yield this.cache.getCurrentAccount();
|
|
87
|
+
if (!currentAccount) {
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
return currentAccount.paymentAddress;
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
getOrdinalsAddress() {
|
|
94
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
95
|
+
const currentAccount = yield this.cache.getCurrentAccount();
|
|
96
|
+
if (!currentAccount) {
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
return currentAccount.ordinalsAddress;
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
export { BitcoinWalletConnectorBase };
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var utils = require('@dynamic-labs/utils');
|
|
6
|
+
var bitcoinWalletStandardWallets = require('./bitcoinWalletStandardWallets.cjs');
|
|
7
|
+
|
|
8
|
+
class BitcoinProviderHelper {
|
|
9
|
+
constructor(walletData) {
|
|
10
|
+
this.walletData = walletData;
|
|
11
|
+
}
|
|
12
|
+
getInjectedConfig() {
|
|
13
|
+
if (!this.walletData || !this.walletData.injectedConfig)
|
|
14
|
+
return;
|
|
15
|
+
const { injectedConfig } = this.walletData;
|
|
16
|
+
return injectedConfig.find((c) => c.chain === 'btc');
|
|
17
|
+
}
|
|
18
|
+
installedProviders() {
|
|
19
|
+
const config = this.getInjectedConfig();
|
|
20
|
+
if (!config)
|
|
21
|
+
return [];
|
|
22
|
+
const providers = [];
|
|
23
|
+
if (config.windowLocations) {
|
|
24
|
+
for (const windowLocation of config.windowLocations) {
|
|
25
|
+
const foundProviders = utils.getProvidersFromWindow(windowLocation);
|
|
26
|
+
if (foundProviders && foundProviders.length)
|
|
27
|
+
providers.push(...foundProviders);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
return providers;
|
|
31
|
+
}
|
|
32
|
+
hasAllRequiredFeatures(wallet) {
|
|
33
|
+
const injectedConfig = this.getInjectedConfig();
|
|
34
|
+
if (!(injectedConfig === null || injectedConfig === void 0 ? void 0 : injectedConfig.walletStandard) || !wallet) {
|
|
35
|
+
return false;
|
|
36
|
+
}
|
|
37
|
+
const { walletStandard } = injectedConfig;
|
|
38
|
+
for (const feature of walletStandard.features) {
|
|
39
|
+
if (!(feature in wallet.features)) {
|
|
40
|
+
return false;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
return true;
|
|
44
|
+
}
|
|
45
|
+
bitcoinWalletStandardLookup() {
|
|
46
|
+
const wallets = bitcoinWalletStandardWallets.BitcoinWalletStandardWalletsSingleton.getWallets();
|
|
47
|
+
const walletStandardWallet = wallets === null || wallets === void 0 ? void 0 : wallets.find((wallet) => {
|
|
48
|
+
var _a, _b;
|
|
49
|
+
return ((_b = (_a = this.getInjectedConfig()) === null || _a === void 0 ? void 0 : _a.walletStandard) === null || _b === void 0 ? void 0 : _b.name) === wallet.name &&
|
|
50
|
+
this.hasAllRequiredFeatures(wallet);
|
|
51
|
+
});
|
|
52
|
+
return walletStandardWallet;
|
|
53
|
+
}
|
|
54
|
+
findWallet() {
|
|
55
|
+
const bitcoinProvider = this.bitcoinWalletStandardLookup();
|
|
56
|
+
return bitcoinProvider;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
exports.BitcoinProviderHelper = BitcoinProviderHelper;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { Wallet } from '@wallet-standard/base';
|
|
2
|
+
import { WalletSchema } from '@dynamic-labs/wallet-book';
|
|
3
|
+
export declare class BitcoinProviderHelper {
|
|
4
|
+
private walletData;
|
|
5
|
+
constructor(walletData: WalletSchema);
|
|
6
|
+
getInjectedConfig(): {
|
|
7
|
+
chain: string;
|
|
8
|
+
extensionLocators: {
|
|
9
|
+
value: boolean;
|
|
10
|
+
flag: string;
|
|
11
|
+
}[];
|
|
12
|
+
walletStandard?: {
|
|
13
|
+
features: string[];
|
|
14
|
+
name: string;
|
|
15
|
+
} | undefined;
|
|
16
|
+
windowLocations?: string[] | undefined;
|
|
17
|
+
} | undefined;
|
|
18
|
+
installedProviders(): any[];
|
|
19
|
+
hasAllRequiredFeatures(wallet: Wallet): boolean;
|
|
20
|
+
bitcoinWalletStandardLookup(): Wallet | undefined;
|
|
21
|
+
findWallet(): Wallet | undefined;
|
|
22
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { getProvidersFromWindow } from '@dynamic-labs/utils';
|
|
2
|
+
import { BitcoinWalletStandardWalletsSingleton } from './bitcoinWalletStandardWallets.js';
|
|
3
|
+
|
|
4
|
+
class BitcoinProviderHelper {
|
|
5
|
+
constructor(walletData) {
|
|
6
|
+
this.walletData = walletData;
|
|
7
|
+
}
|
|
8
|
+
getInjectedConfig() {
|
|
9
|
+
if (!this.walletData || !this.walletData.injectedConfig)
|
|
10
|
+
return;
|
|
11
|
+
const { injectedConfig } = this.walletData;
|
|
12
|
+
return injectedConfig.find((c) => c.chain === 'btc');
|
|
13
|
+
}
|
|
14
|
+
installedProviders() {
|
|
15
|
+
const config = this.getInjectedConfig();
|
|
16
|
+
if (!config)
|
|
17
|
+
return [];
|
|
18
|
+
const providers = [];
|
|
19
|
+
if (config.windowLocations) {
|
|
20
|
+
for (const windowLocation of config.windowLocations) {
|
|
21
|
+
const foundProviders = getProvidersFromWindow(windowLocation);
|
|
22
|
+
if (foundProviders && foundProviders.length)
|
|
23
|
+
providers.push(...foundProviders);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
return providers;
|
|
27
|
+
}
|
|
28
|
+
hasAllRequiredFeatures(wallet) {
|
|
29
|
+
const injectedConfig = this.getInjectedConfig();
|
|
30
|
+
if (!(injectedConfig === null || injectedConfig === void 0 ? void 0 : injectedConfig.walletStandard) || !wallet) {
|
|
31
|
+
return false;
|
|
32
|
+
}
|
|
33
|
+
const { walletStandard } = injectedConfig;
|
|
34
|
+
for (const feature of walletStandard.features) {
|
|
35
|
+
if (!(feature in wallet.features)) {
|
|
36
|
+
return false;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
return true;
|
|
40
|
+
}
|
|
41
|
+
bitcoinWalletStandardLookup() {
|
|
42
|
+
const wallets = BitcoinWalletStandardWalletsSingleton.getWallets();
|
|
43
|
+
const walletStandardWallet = wallets === null || wallets === void 0 ? void 0 : wallets.find((wallet) => {
|
|
44
|
+
var _a, _b;
|
|
45
|
+
return ((_b = (_a = this.getInjectedConfig()) === null || _a === void 0 ? void 0 : _a.walletStandard) === null || _b === void 0 ? void 0 : _b.name) === wallet.name &&
|
|
46
|
+
this.hasAllRequiredFeatures(wallet);
|
|
47
|
+
});
|
|
48
|
+
return walletStandardWallet;
|
|
49
|
+
}
|
|
50
|
+
findWallet() {
|
|
51
|
+
const bitcoinProvider = this.bitcoinWalletStandardLookup();
|
|
52
|
+
return bitcoinProvider;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export { BitcoinProviderHelper };
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var app = require('@wallet-standard/app');
|
|
6
|
+
|
|
7
|
+
class BitcoinWalletStandardWallets {
|
|
8
|
+
registerWallets() {
|
|
9
|
+
this.wallets = app.getWallets();
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
class BitcoinWalletStandardWalletsSingleton {
|
|
13
|
+
constructor() {
|
|
14
|
+
this.bitcoinWalletStandardWallets = new BitcoinWalletStandardWallets();
|
|
15
|
+
}
|
|
16
|
+
static get() {
|
|
17
|
+
var _a;
|
|
18
|
+
if (!((_a = BitcoinWalletStandardWalletsSingleton.instance) === null || _a === void 0 ? void 0 : _a.bitcoinWalletStandardWallets)) {
|
|
19
|
+
BitcoinWalletStandardWalletsSingleton.instance =
|
|
20
|
+
new BitcoinWalletStandardWalletsSingleton();
|
|
21
|
+
BitcoinWalletStandardWalletsSingleton.instance.bitcoinWalletStandardWallets.registerWallets();
|
|
22
|
+
}
|
|
23
|
+
return BitcoinWalletStandardWalletsSingleton.instance
|
|
24
|
+
.bitcoinWalletStandardWallets;
|
|
25
|
+
}
|
|
26
|
+
static getWallets() {
|
|
27
|
+
var _a;
|
|
28
|
+
return (_a = BitcoinWalletStandardWalletsSingleton.get().wallets) === null || _a === void 0 ? void 0 : _a.get();
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
exports.BitcoinWalletStandardWallets = BitcoinWalletStandardWallets;
|
|
33
|
+
exports.BitcoinWalletStandardWalletsSingleton = BitcoinWalletStandardWalletsSingleton;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Wallets } from '@wallet-standard/app';
|
|
2
|
+
export declare class BitcoinWalletStandardWallets {
|
|
3
|
+
wallets: Wallets | undefined;
|
|
4
|
+
registerWallets(): void;
|
|
5
|
+
}
|
|
6
|
+
export declare class BitcoinWalletStandardWalletsSingleton {
|
|
7
|
+
readonly bitcoinWalletStandardWallets: BitcoinWalletStandardWallets;
|
|
8
|
+
private constructor();
|
|
9
|
+
private static instance;
|
|
10
|
+
static get(): BitcoinWalletStandardWallets;
|
|
11
|
+
static getWallets(): readonly import("@wallet-standard/base").Wallet[] | undefined;
|
|
12
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { getWallets } from '@wallet-standard/app';
|
|
2
|
+
|
|
3
|
+
class BitcoinWalletStandardWallets {
|
|
4
|
+
registerWallets() {
|
|
5
|
+
this.wallets = getWallets();
|
|
6
|
+
}
|
|
7
|
+
}
|
|
8
|
+
class BitcoinWalletStandardWalletsSingleton {
|
|
9
|
+
constructor() {
|
|
10
|
+
this.bitcoinWalletStandardWallets = new BitcoinWalletStandardWallets();
|
|
11
|
+
}
|
|
12
|
+
static get() {
|
|
13
|
+
var _a;
|
|
14
|
+
if (!((_a = BitcoinWalletStandardWalletsSingleton.instance) === null || _a === void 0 ? void 0 : _a.bitcoinWalletStandardWallets)) {
|
|
15
|
+
BitcoinWalletStandardWalletsSingleton.instance =
|
|
16
|
+
new BitcoinWalletStandardWalletsSingleton();
|
|
17
|
+
BitcoinWalletStandardWalletsSingleton.instance.bitcoinWalletStandardWallets.registerWallets();
|
|
18
|
+
}
|
|
19
|
+
return BitcoinWalletStandardWalletsSingleton.instance
|
|
20
|
+
.bitcoinWalletStandardWallets;
|
|
21
|
+
}
|
|
22
|
+
static getWallets() {
|
|
23
|
+
var _a;
|
|
24
|
+
return (_a = BitcoinWalletStandardWalletsSingleton.get().wallets) === null || _a === void 0 ? void 0 : _a.get();
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export { BitcoinWalletStandardWallets, BitcoinWalletStandardWalletsSingleton };
|
package/src/const.cjs
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
const XVERSE_KEY = 'xverse';
|
|
6
|
+
const SATSCONNECT_FEATURE = 'sats-connect:';
|
|
7
|
+
const HTTP_STATUS_TOO_MANY_REQUESTS = 429;
|
|
8
|
+
const HTTP_STATUS_NOT_FOUND = 404;
|
|
9
|
+
const BALANCE_API_URL = 'https://mempool.space/api/address/';
|
|
10
|
+
|
|
11
|
+
exports.BALANCE_API_URL = BALANCE_API_URL;
|
|
12
|
+
exports.HTTP_STATUS_NOT_FOUND = HTTP_STATUS_NOT_FOUND;
|
|
13
|
+
exports.HTTP_STATUS_TOO_MANY_REQUESTS = HTTP_STATUS_TOO_MANY_REQUESTS;
|
|
14
|
+
exports.SATSCONNECT_FEATURE = SATSCONNECT_FEATURE;
|
|
15
|
+
exports.XVERSE_KEY = XVERSE_KEY;
|
package/src/const.d.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export declare const XVERSE_KEY = "xverse";
|
|
2
|
+
export declare const SATSCONNECT_FEATURE = "sats-connect:";
|
|
3
|
+
export declare const HTTP_STATUS_TOO_MANY_REQUESTS = 429;
|
|
4
|
+
export declare const HTTP_STATUS_NOT_FOUND = 404;
|
|
5
|
+
export declare const BALANCE_API_URL = "https://mempool.space/api/address/";
|
|
6
|
+
export declare const BALANCE_API_URL_TESTNET = "https://mempool.space/testnet/api/address/";
|
package/src/const.js
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
const XVERSE_KEY = 'xverse';
|
|
2
|
+
const SATSCONNECT_FEATURE = 'sats-connect:';
|
|
3
|
+
const HTTP_STATUS_TOO_MANY_REQUESTS = 429;
|
|
4
|
+
const HTTP_STATUS_NOT_FOUND = 404;
|
|
5
|
+
const BALANCE_API_URL = 'https://mempool.space/api/address/';
|
|
6
|
+
|
|
7
|
+
export { BALANCE_API_URL, HTTP_STATUS_NOT_FOUND, HTTP_STATUS_TOO_MANY_REQUESTS, SATSCONNECT_FEATURE, XVERSE_KEY };
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var _const = require('./const.cjs');
|
|
6
|
+
var BitcoinSatsConnectConnector = require('./BitcoinSatsConnectConnector.cjs');
|
|
7
|
+
|
|
8
|
+
const fetchSatsConnectConnectors = ({ walletBook, }) => {
|
|
9
|
+
var _a;
|
|
10
|
+
return Object.entries((_a = walletBook === null || walletBook === void 0 ? void 0 : walletBook.wallets) !== null && _a !== void 0 ? _a : {})
|
|
11
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
12
|
+
.filter(([_, wallet]) => {
|
|
13
|
+
var _a;
|
|
14
|
+
return (_a = wallet.injectedConfig) === null || _a === void 0 ? void 0 : _a.find((config) => {
|
|
15
|
+
var _a;
|
|
16
|
+
return config.chain === 'btc' &&
|
|
17
|
+
Boolean((_a = config.walletStandard) === null || _a === void 0 ? void 0 : _a.features.includes(_const.SATSCONNECT_FEATURE));
|
|
18
|
+
});
|
|
19
|
+
})
|
|
20
|
+
.map(([key, wallet]) => {
|
|
21
|
+
const { shortName } = wallet;
|
|
22
|
+
const name = shortName || wallet.name;
|
|
23
|
+
return class extends BitcoinSatsConnectConnector.BitcoinSatsConnectConnector {
|
|
24
|
+
constructor(props) {
|
|
25
|
+
super(Object.assign(Object.assign({}, props), { overrideKey: key, walletData: wallet }));
|
|
26
|
+
this.name = name;
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
});
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
exports.fetchSatsConnectConnectors = fetchSatsConnectConnectors;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { WalletConnectorConstructor } from '@dynamic-labs/wallet-connector-core';
|
|
2
|
+
import { WalletBookSchema } from '@dynamic-labs/wallet-book';
|
|
3
|
+
export declare const fetchSatsConnectConnectors: ({ walletBook, }: {
|
|
4
|
+
walletBook: WalletBookSchema;
|
|
5
|
+
}) => WalletConnectorConstructor[];
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { SATSCONNECT_FEATURE } from './const.js';
|
|
2
|
+
import { BitcoinSatsConnectConnector } from './BitcoinSatsConnectConnector.js';
|
|
3
|
+
|
|
4
|
+
const fetchSatsConnectConnectors = ({ walletBook, }) => {
|
|
5
|
+
var _a;
|
|
6
|
+
return Object.entries((_a = walletBook === null || walletBook === void 0 ? void 0 : walletBook.wallets) !== null && _a !== void 0 ? _a : {})
|
|
7
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
8
|
+
.filter(([_, wallet]) => {
|
|
9
|
+
var _a;
|
|
10
|
+
return (_a = wallet.injectedConfig) === null || _a === void 0 ? void 0 : _a.find((config) => {
|
|
11
|
+
var _a;
|
|
12
|
+
return config.chain === 'btc' &&
|
|
13
|
+
Boolean((_a = config.walletStandard) === null || _a === void 0 ? void 0 : _a.features.includes(SATSCONNECT_FEATURE));
|
|
14
|
+
});
|
|
15
|
+
})
|
|
16
|
+
.map(([key, wallet]) => {
|
|
17
|
+
const { shortName } = wallet;
|
|
18
|
+
const name = shortName || wallet.name;
|
|
19
|
+
return class extends BitcoinSatsConnectConnector {
|
|
20
|
+
constructor(props) {
|
|
21
|
+
super(Object.assign(Object.assign({}, props), { overrideKey: key, walletData: wallet }));
|
|
22
|
+
this.name = name;
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
});
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
export { fetchSatsConnectConnectors };
|
package/src/index.cjs
CHANGED
|
@@ -2,6 +2,10 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
var fetchSatsConnectConnectors = require('./fetchSatsConnectConnectors.cjs');
|
|
6
|
+
|
|
7
|
+
const BitcoinWalletConnectors = (props) => [
|
|
8
|
+
...fetchSatsConnectConnectors.fetchSatsConnectConnectors(props),
|
|
9
|
+
];
|
|
6
10
|
|
|
7
11
|
exports.BitcoinWalletConnectors = BitcoinWalletConnectors;
|
package/src/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const BitcoinWalletConnectors: () =>
|
|
1
|
+
export declare const BitcoinWalletConnectors: (props: any) => import("dist/packages/wallet-connector-core/src").WalletConnectorConstructor[];
|
package/src/index.js
CHANGED
package/src/types.d.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { BitcoinProvider } from 'sats-connect';
|
|
2
|
+
import { SATSCONNECT_FEATURE } from './const';
|
|
3
|
+
export type ErrorWithCode = Error & {
|
|
4
|
+
code: string;
|
|
5
|
+
};
|
|
6
|
+
export type SatsConnectFeature = {
|
|
7
|
+
[SATSCONNECT_FEATURE]: {
|
|
8
|
+
provider: BitcoinProvider;
|
|
9
|
+
};
|
|
10
|
+
};
|
|
11
|
+
export type BitcoinAccount = {
|
|
12
|
+
ordinalsAddress?: string;
|
|
13
|
+
paymentAddress?: string;
|
|
14
|
+
};
|
|
15
|
+
export type BitcoinTransaction = {
|
|
16
|
+
amount: bigint;
|
|
17
|
+
recipientAddress: string;
|
|
18
|
+
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var _const = require('../const.cjs');
|
|
6
|
+
|
|
7
|
+
const hasSatsConnectFeature = (features) => _const.SATSCONNECT_FEATURE in features;
|
|
8
|
+
|
|
9
|
+
exports.hasSatsConnectFeature = hasSatsConnectFeature;
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { WalletConnector } from '@dynamic-labs/wallet-connector-core';
|
|
2
|
+
import { BitcoinWalletConnectorBase } from '../BitcoinWalletConnectorBase';
|
|
3
|
+
export declare const isBitcoinConnector: (connector: BitcoinWalletConnectorBase | WalletConnector) => connector is BitcoinWalletConnectorBase;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var _const = require('../const.cjs');
|
|
6
|
+
var hasSatsConnectFeature = require('./hasSatsConnectFeature.cjs');
|
|
7
|
+
|
|
8
|
+
const supportsSatsConnect = (connector) => {
|
|
9
|
+
if (connector.key === _const.XVERSE_KEY) {
|
|
10
|
+
return true;
|
|
11
|
+
}
|
|
12
|
+
if (connector.wallet && hasSatsConnectFeature.hasSatsConnectFeature(connector.wallet.features)) {
|
|
13
|
+
return true;
|
|
14
|
+
}
|
|
15
|
+
return false;
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
exports.supportsSatsConnect = supportsSatsConnect;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { XVERSE_KEY } from '../const.js';
|
|
2
|
+
import { hasSatsConnectFeature } from './hasSatsConnectFeature.js';
|
|
3
|
+
|
|
4
|
+
const supportsSatsConnect = (connector) => {
|
|
5
|
+
if (connector.key === XVERSE_KEY) {
|
|
6
|
+
return true;
|
|
7
|
+
}
|
|
8
|
+
if (connector.wallet && hasSatsConnectFeature(connector.wallet.features)) {
|
|
9
|
+
return true;
|
|
10
|
+
}
|
|
11
|
+
return false;
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
export { supportsSatsConnect };
|