@dynamic-labs/bitcoin 0.0.0-exp20240808.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 +3746 -0
- package/LICENSE +21 -0
- package/README.md +0 -0
- package/_virtual/_tslib.cjs +36 -0
- package/_virtual/_tslib.js +32 -0
- package/package.json +41 -0
- package/src/BitcoinLocalStorageCache.cjs +67 -0
- package/src/BitcoinLocalStorageCache.d.ts +26 -0
- package/src/BitcoinLocalStorageCache.js +63 -0
- package/src/bitcoinProviderHelper.cjs +65 -0
- package/src/bitcoinProviderHelper.d.ts +29 -0
- package/src/bitcoinProviderHelper.js +61 -0
- package/src/bitcoinWalletStandardWallets.cjs +34 -0
- package/src/bitcoinWalletStandardWallets.d.ts +12 -0
- package/src/bitcoinWalletStandardWallets.js +29 -0
- package/src/connectors/BitcoinBtcKitConnector/BitcoinBtcKitConnector.cjs +124 -0
- package/src/connectors/BitcoinBtcKitConnector/BitcoinBtcKitConnector.d.ts +18 -0
- package/src/connectors/BitcoinBtcKitConnector/BitcoinBtcKitConnector.js +120 -0
- package/src/connectors/BitcoinBtcKitConnector/index.d.ts +2 -0
- package/src/connectors/BitcoinSatsConnectConnector/BitcoinSatsConnectConnector.cjs +223 -0
- package/src/connectors/BitcoinSatsConnectConnector/BitcoinSatsConnectConnector.d.ts +12 -0
- package/src/connectors/BitcoinSatsConnectConnector/BitcoinSatsConnectConnector.js +219 -0
- package/src/connectors/BitcoinSatsConnectConnector/index.d.ts +1 -0
- package/src/connectors/BitcoinWalletConnector.cjs +276 -0
- package/src/connectors/BitcoinWalletConnector.d.ts +50 -0
- package/src/connectors/BitcoinWalletConnector.js +272 -0
- package/src/connectors/FallbackBitcoinConnector/FallbackBitcoinConnector.cjs +37 -0
- package/src/connectors/FallbackBitcoinConnector/FallbackBitcoinConnector.d.ts +11 -0
- package/src/connectors/FallbackBitcoinConnector/FallbackBitcoinConnector.js +33 -0
- package/src/connectors/FallbackBitcoinConnector/index.d.ts +1 -0
- package/src/connectors/OkxConnector/OkxConnector.cjs +83 -0
- package/src/connectors/OkxConnector/OkxConnector.d.ts +11 -0
- package/src/connectors/OkxConnector/OkxConnector.js +79 -0
- package/src/connectors/OkxConnector/index.d.ts +1 -0
- package/src/connectors/PhantomConnector/PhantomConnector.cjs +146 -0
- package/src/connectors/PhantomConnector/PhantomConnector.d.ts +11 -0
- package/src/connectors/PhantomConnector/PhantomConnector.js +142 -0
- package/src/connectors/PhantomConnector/index.d.ts +1 -0
- package/src/connectors/UnisatConnector/UnisatConnector.cjs +78 -0
- package/src/connectors/UnisatConnector/UnisatConnector.d.ts +12 -0
- package/src/connectors/UnisatConnector/UnisatConnector.js +74 -0
- package/src/connectors/UnisatConnector/index.d.ts +1 -0
- package/src/connectors/UnknownInjected/UnknownInjected.cjs +36 -0
- package/src/connectors/UnknownInjected/UnknownInjected.d.ts +10 -0
- package/src/connectors/UnknownInjected/UnknownInjected.js +32 -0
- package/src/connectors/UnknownInjected/index.d.ts +1 -0
- package/src/connectors/index.d.ts +8 -0
- package/src/const.cjs +20 -0
- package/src/const.d.ts +7 -0
- package/src/const.js +10 -0
- package/src/index.cjs +44 -0
- package/src/index.d.ts +6 -0
- package/src/index.js +34 -0
- package/src/types.d.ts +129 -0
- package/src/utils/base64.cjs +10 -0
- package/src/utils/base64.d.ts +2 -0
- package/src/utils/base64.js +5 -0
- package/src/utils/fetchBtcKitConnectors/fetchBtcKitConnectors.cjs +30 -0
- package/src/utils/fetchBtcKitConnectors/fetchBtcKitConnectors.d.ts +5 -0
- package/src/utils/fetchBtcKitConnectors/fetchBtcKitConnectors.js +26 -0
- package/src/utils/fetchBtcKitConnectors/index.d.ts +1 -0
- package/src/utils/fetchSatsConnectConnectors/fetchSatsConnectConnectors.cjs +41 -0
- package/src/utils/fetchSatsConnectConnectors/fetchSatsConnectConnectors.d.ts +5 -0
- package/src/utils/fetchSatsConnectConnectors/fetchSatsConnectConnectors.js +37 -0
- package/src/utils/fetchSatsConnectConnectors/index.d.ts +1 -0
- package/src/utils/getMempoolApiUrl.cjs +10 -0
- package/src/utils/getMempoolApiUrl.d.ts +1 -0
- package/src/utils/getMempoolApiUrl.js +6 -0
- package/src/utils/hasSatsConnectFeature.cjs +10 -0
- package/src/utils/hasSatsConnectFeature.d.ts +2 -0
- package/src/utils/hasSatsConnectFeature.js +6 -0
- package/src/utils/index.d.ts +5 -0
- package/src/utils/psbt/bitcoinNetworkTypeToNetworks.cjs +14 -0
- package/src/utils/psbt/bitcoinNetworkTypeToNetworks.d.ts +3 -0
- package/src/utils/psbt/bitcoinNetworkTypeToNetworks.js +10 -0
- package/src/utils/psbt/createSignPsbtOptions.cjs +36 -0
- package/src/utils/psbt/createSignPsbtOptions.d.ts +3 -0
- package/src/utils/psbt/createSignPsbtOptions.js +32 -0
- package/src/utils/psbt/extractAddressFromInput.cjs +35 -0
- package/src/utils/psbt/extractAddressFromInput.d.ts +6 -0
- package/src/utils/psbt/extractAddressFromInput.js +31 -0
- package/src/utils/psbt/getSigHashType.cjs +36 -0
- package/src/utils/psbt/getSigHashType.d.ts +8 -0
- package/src/utils/psbt/getSigHashType.js +32 -0
- package/src/utils/psbt/index.d.ts +5 -0
- package/src/utils/psbt/sighashNumberToString.cjs +27 -0
- package/src/utils/psbt/sighashNumberToString.d.ts +2 -0
- package/src/utils/psbt/sighashNumberToString.js +23 -0
- package/src/utils/psbt/validator/index.d.ts +1 -0
- package/src/utils/psbt/validator/validateAddress.cjs +19 -0
- package/src/utils/psbt/validator/validateAddress.d.ts +2 -0
- package/src/utils/psbt/validator/validateAddress.js +15 -0
- package/src/utils/psbt/validator/validatePsbt.cjs +41 -0
- package/src/utils/psbt/validator/validatePsbt.d.ts +11 -0
- package/src/utils/psbt/validator/validatePsbt.js +37 -0
- package/src/utils/psbt/validator/validateSigHash.cjs +16 -0
- package/src/utils/psbt/validator/validateSigHash.d.ts +2 -0
- package/src/utils/psbt/validator/validateSigHash.js +12 -0
- package/src/utils/satoshisToBtc/index.d.ts +1 -0
- package/src/utils/satoshisToBtc/satoshisToBtc.cjs +8 -0
- package/src/utils/satoshisToBtc/satoshisToBtc.d.ts +1 -0
- package/src/utils/satoshisToBtc/satoshisToBtc.js +4 -0
- package/src/utils/supportsSatsConnect.cjs +27 -0
- package/src/utils/supportsSatsConnect.d.ts +2 -0
- package/src/utils/supportsSatsConnect.js +23 -0
- package/src/wallet/BitcoinWallet.cjs +43 -0
- package/src/wallet/BitcoinWallet.d.ts +21 -0
- package/src/wallet/BitcoinWallet.js +39 -0
- package/src/wallet/index.d.ts +2 -0
- package/src/wallet/isBitcoinWallet.cjs +8 -0
- package/src/wallet/isBitcoinWallet.d.ts +3 -0
- package/src/wallet/isBitcoinWallet.js +4 -0
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
import { __awaiter } from '../../../_virtual/_tslib.js';
|
|
3
|
+
import { BitcoinWalletConnector } from '../BitcoinWalletConnector.js';
|
|
4
|
+
|
|
5
|
+
class FallbackBitcoinConnector extends BitcoinWalletConnector {
|
|
6
|
+
constructor(opts) {
|
|
7
|
+
super(Object.assign(Object.assign({}, opts), { overrideKey: 'fallbackconnector' }));
|
|
8
|
+
this.name = 'Fallback Connector';
|
|
9
|
+
this.overrideKey = 'fallbackconnector';
|
|
10
|
+
this.isAvailable = false;
|
|
11
|
+
}
|
|
12
|
+
getAddress() {
|
|
13
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
14
|
+
return;
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
signPsbt(
|
|
18
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
19
|
+
_request) {
|
|
20
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
21
|
+
return;
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
sendBitcoin(
|
|
25
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
26
|
+
_transaction) {
|
|
27
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
28
|
+
return;
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export { FallbackBitcoinConnector };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { FallbackBitcoinConnector } from './FallbackBitcoinConnector';
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
5
|
+
|
|
6
|
+
var _tslib = require('../../../_virtual/_tslib.cjs');
|
|
7
|
+
var bitcoinjsLib = require('bitcoinjs-lib');
|
|
8
|
+
var utils = require('@dynamic-labs/utils');
|
|
9
|
+
var BitcoinWalletConnector = require('../BitcoinWalletConnector.cjs');
|
|
10
|
+
var createSignPsbtOptions = require('../../utils/psbt/createSignPsbtOptions.cjs');
|
|
11
|
+
|
|
12
|
+
class OkxConnector extends BitcoinWalletConnector.BitcoinWalletConnector {
|
|
13
|
+
constructor(opts) {
|
|
14
|
+
super(Object.assign(Object.assign({}, opts), { overrideKey: 'okxwalletbtc' }));
|
|
15
|
+
this.name = 'OKX Wallet';
|
|
16
|
+
}
|
|
17
|
+
get walletBookWallet() {
|
|
18
|
+
return this.walletBook.wallets[this.key];
|
|
19
|
+
}
|
|
20
|
+
getAddress() {
|
|
21
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
22
|
+
if (!this.isInstalledOnBrowser() &&
|
|
23
|
+
utils.isMobile() &&
|
|
24
|
+
this.walletBookWallet.mobile &&
|
|
25
|
+
this.walletBookWallet.mobile.inAppBrowser &&
|
|
26
|
+
this.mobileExperience === 'in-app-browser') {
|
|
27
|
+
const inAppBrowserCompiledTemplate = utils.template(this.walletBookWallet.mobile.inAppBrowser);
|
|
28
|
+
const deepLink = inAppBrowserCompiledTemplate({
|
|
29
|
+
encodedDappURI: encodeURIComponent(window.location.toString()),
|
|
30
|
+
});
|
|
31
|
+
window.location.assign(deepLink);
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
const provider = this.getProvider();
|
|
35
|
+
if (!provider) {
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
const { address, publicKey } = yield provider.connect();
|
|
39
|
+
const bitcoinAddress = {
|
|
40
|
+
address,
|
|
41
|
+
publicKey,
|
|
42
|
+
};
|
|
43
|
+
yield this.setConnectedAccountWithAddresses({
|
|
44
|
+
active: true,
|
|
45
|
+
mainAddress: address,
|
|
46
|
+
ordinalsAddress: bitcoinAddress,
|
|
47
|
+
});
|
|
48
|
+
return address;
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
signMessage(messageToSign) {
|
|
52
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
53
|
+
const provider = this.getProvider();
|
|
54
|
+
if (!provider) {
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
return provider.signMessage(messageToSign, 'bip322-simple');
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
sendBitcoin(transaction) {
|
|
61
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
62
|
+
const provider = this.getProvider();
|
|
63
|
+
const connectedAddress = yield this.getAddress();
|
|
64
|
+
if (!connectedAddress || !provider) {
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
return provider.sendBitcoin(transaction.recipientAddress, transaction.amount.toString());
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
signPsbt(request) {
|
|
71
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
72
|
+
const provider = this.getProvider();
|
|
73
|
+
if (!provider) {
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
const psbtFromBase64 = bitcoinjsLib.Psbt.fromBase64(request.unsignedPsbtBase64);
|
|
77
|
+
const signedPsbtHex = yield provider.signPsbt(psbtFromBase64.toHex(), createSignPsbtOptions.createPsbtOptions(psbtFromBase64, request));
|
|
78
|
+
return { signedPsbt: bitcoinjsLib.Psbt.fromHex(signedPsbtHex).toBase64() };
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
exports.OkxConnector = OkxConnector;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { BitcoinWalletConnector, BitcoinWalletConnectorOpts } from '../BitcoinWalletConnector';
|
|
2
|
+
import { BitcoinTransaction, BitcoinSignPsbtRequest, BitcoinSignPsbtResponse } from '../../types';
|
|
3
|
+
export declare class OkxConnector extends BitcoinWalletConnector {
|
|
4
|
+
name: string;
|
|
5
|
+
constructor(opts: BitcoinWalletConnectorOpts);
|
|
6
|
+
private get walletBookWallet();
|
|
7
|
+
getAddress(): Promise<string | undefined>;
|
|
8
|
+
signMessage(messageToSign: string): Promise<string | undefined>;
|
|
9
|
+
sendBitcoin(transaction: BitcoinTransaction): Promise<string | undefined>;
|
|
10
|
+
signPsbt(request: BitcoinSignPsbtRequest): Promise<BitcoinSignPsbtResponse | undefined>;
|
|
11
|
+
}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
import { __awaiter } from '../../../_virtual/_tslib.js';
|
|
3
|
+
import { Psbt } from 'bitcoinjs-lib';
|
|
4
|
+
import { isMobile, template } from '@dynamic-labs/utils';
|
|
5
|
+
import { BitcoinWalletConnector } from '../BitcoinWalletConnector.js';
|
|
6
|
+
import { createPsbtOptions } from '../../utils/psbt/createSignPsbtOptions.js';
|
|
7
|
+
|
|
8
|
+
class OkxConnector extends BitcoinWalletConnector {
|
|
9
|
+
constructor(opts) {
|
|
10
|
+
super(Object.assign(Object.assign({}, opts), { overrideKey: 'okxwalletbtc' }));
|
|
11
|
+
this.name = 'OKX Wallet';
|
|
12
|
+
}
|
|
13
|
+
get walletBookWallet() {
|
|
14
|
+
return this.walletBook.wallets[this.key];
|
|
15
|
+
}
|
|
16
|
+
getAddress() {
|
|
17
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
18
|
+
if (!this.isInstalledOnBrowser() &&
|
|
19
|
+
isMobile() &&
|
|
20
|
+
this.walletBookWallet.mobile &&
|
|
21
|
+
this.walletBookWallet.mobile.inAppBrowser &&
|
|
22
|
+
this.mobileExperience === 'in-app-browser') {
|
|
23
|
+
const inAppBrowserCompiledTemplate = template(this.walletBookWallet.mobile.inAppBrowser);
|
|
24
|
+
const deepLink = inAppBrowserCompiledTemplate({
|
|
25
|
+
encodedDappURI: encodeURIComponent(window.location.toString()),
|
|
26
|
+
});
|
|
27
|
+
window.location.assign(deepLink);
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
const provider = this.getProvider();
|
|
31
|
+
if (!provider) {
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
const { address, publicKey } = yield provider.connect();
|
|
35
|
+
const bitcoinAddress = {
|
|
36
|
+
address,
|
|
37
|
+
publicKey,
|
|
38
|
+
};
|
|
39
|
+
yield this.setConnectedAccountWithAddresses({
|
|
40
|
+
active: true,
|
|
41
|
+
mainAddress: address,
|
|
42
|
+
ordinalsAddress: bitcoinAddress,
|
|
43
|
+
});
|
|
44
|
+
return address;
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
signMessage(messageToSign) {
|
|
48
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
49
|
+
const provider = this.getProvider();
|
|
50
|
+
if (!provider) {
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
return provider.signMessage(messageToSign, 'bip322-simple');
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
sendBitcoin(transaction) {
|
|
57
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
58
|
+
const provider = this.getProvider();
|
|
59
|
+
const connectedAddress = yield this.getAddress();
|
|
60
|
+
if (!connectedAddress || !provider) {
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
return provider.sendBitcoin(transaction.recipientAddress, transaction.amount.toString());
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
signPsbt(request) {
|
|
67
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
68
|
+
const provider = this.getProvider();
|
|
69
|
+
if (!provider) {
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
const psbtFromBase64 = Psbt.fromBase64(request.unsignedPsbtBase64);
|
|
73
|
+
const signedPsbtHex = yield provider.signPsbt(psbtFromBase64.toHex(), createPsbtOptions(psbtFromBase64, request));
|
|
74
|
+
return { signedPsbt: Psbt.fromHex(signedPsbtHex).toBase64() };
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
export { OkxConnector };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { OkxConnector } from './OkxConnector';
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
5
|
+
|
|
6
|
+
var _tslib = require('../../../_virtual/_tslib.cjs');
|
|
7
|
+
var bitcoinjsLib = require('bitcoinjs-lib');
|
|
8
|
+
var walletConnectorCore = require('@dynamic-labs/wallet-connector-core');
|
|
9
|
+
var utils = require('@dynamic-labs/utils');
|
|
10
|
+
var BitcoinWalletConnector = require('../BitcoinWalletConnector.cjs');
|
|
11
|
+
var createSignPsbtOptions = require('../../utils/psbt/createSignPsbtOptions.cjs');
|
|
12
|
+
require('sats-connect');
|
|
13
|
+
var sighashNumberToString = require('../../utils/psbt/sighashNumberToString.cjs');
|
|
14
|
+
var base64 = require('../../utils/base64.cjs');
|
|
15
|
+
|
|
16
|
+
class PhantomConnector extends BitcoinWalletConnector.BitcoinWalletConnector {
|
|
17
|
+
constructor(opts) {
|
|
18
|
+
super(Object.assign(Object.assign({}, opts), { overrideKey: 'phantombtc' }));
|
|
19
|
+
this.name = 'Phantom';
|
|
20
|
+
}
|
|
21
|
+
connectWithInstalledExtension() {
|
|
22
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
23
|
+
var _a, _b;
|
|
24
|
+
let paymentAccount, ordinalsAccount;
|
|
25
|
+
if ((_a = this.walletMethods) === null || _a === void 0 ? void 0 : _a.connect) {
|
|
26
|
+
const { accounts } = yield this.walletMethods.connect();
|
|
27
|
+
const parsedAccounts = accounts.map((account) => ({
|
|
28
|
+
address: account.address,
|
|
29
|
+
publicKey: Buffer.from(account.publicKey).toString('hex'),
|
|
30
|
+
}));
|
|
31
|
+
[paymentAccount, ordinalsAccount] = parsedAccounts;
|
|
32
|
+
// in case it only returns one account, we will use it as both payment and ordinals
|
|
33
|
+
if (!ordinalsAccount) {
|
|
34
|
+
ordinalsAccount = paymentAccount;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
else {
|
|
38
|
+
const provider = this.getProvider();
|
|
39
|
+
if (!provider) {
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
const accounts = yield provider.requestAccounts();
|
|
43
|
+
ordinalsAccount = accounts === null || accounts === void 0 ? void 0 : accounts.find((address) => address.purpose === 'ordinals');
|
|
44
|
+
paymentAccount = accounts === null || accounts === void 0 ? void 0 : accounts.find((address) => address.purpose === 'payment');
|
|
45
|
+
}
|
|
46
|
+
const mainAddress = (_b = ordinalsAccount === null || ordinalsAccount === void 0 ? void 0 : ordinalsAccount.address) !== null && _b !== void 0 ? _b : paymentAccount === null || paymentAccount === void 0 ? void 0 : paymentAccount.address;
|
|
47
|
+
yield this.setConnectedAccountWithAddresses({
|
|
48
|
+
active: true,
|
|
49
|
+
mainAddress,
|
|
50
|
+
ordinalsAddress: ordinalsAccount,
|
|
51
|
+
paymentAddress: paymentAccount,
|
|
52
|
+
});
|
|
53
|
+
return mainAddress;
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
getAddress() {
|
|
57
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
58
|
+
if (this.isInstalledOnBrowser()) {
|
|
59
|
+
return this.connectWithInstalledExtension();
|
|
60
|
+
}
|
|
61
|
+
if (utils.isMobile()) {
|
|
62
|
+
utils.handleMobileWalletRedirect({
|
|
63
|
+
nativeLink: 'phantom://browse',
|
|
64
|
+
universalLink: 'https://phantom.app/ul/browse',
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
return undefined;
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
signMessage(messageToSign) {
|
|
71
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
72
|
+
var _a;
|
|
73
|
+
const [walletAddress] = yield this.getConnectedAccounts();
|
|
74
|
+
if (!walletAddress) {
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
if ((_a = this.walletMethods) === null || _a === void 0 ? void 0 : _a.signMessage) {
|
|
78
|
+
const [result] = yield this.walletMethods.signMessage({
|
|
79
|
+
// we need to sign with the ordinals account
|
|
80
|
+
account: { address: walletAddress },
|
|
81
|
+
message: new TextEncoder().encode(messageToSign),
|
|
82
|
+
});
|
|
83
|
+
return Buffer.from(result.signature).toString('base64');
|
|
84
|
+
}
|
|
85
|
+
else {
|
|
86
|
+
const provider = this.getProvider();
|
|
87
|
+
if (!provider) {
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
const result = yield provider.signMessage(walletAddress, new TextEncoder().encode(messageToSign));
|
|
91
|
+
return Buffer.from(result.signature).toString('base64');
|
|
92
|
+
}
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
sendBitcoin(transaction) {
|
|
96
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
97
|
+
walletConnectorCore.logger.debug('sendBitcoin - function not implemented', transaction);
|
|
98
|
+
return undefined;
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
signPsbt(request) {
|
|
102
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
103
|
+
var _a, _b, _c, _d, _e;
|
|
104
|
+
const [walletAddress] = yield this.getConnectedAccounts();
|
|
105
|
+
if (!walletAddress) {
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
const psbtFromBase64 = bitcoinjsLib.Psbt.fromBase64(request.unsignedPsbtBase64);
|
|
109
|
+
const psbtOptions = createSignPsbtOptions.createPsbtOptions(psbtFromBase64, request);
|
|
110
|
+
if ((_a = this.walletMethods) === null || _a === void 0 ? void 0 : _a.signTransaction) {
|
|
111
|
+
const [signedPsbtHex] = yield this.walletMethods.signTransaction({
|
|
112
|
+
inputsToSign: (_c = (_b = psbtOptions.toSignInputs) === null || _b === void 0 ? void 0 : _b.map((input) => ({
|
|
113
|
+
account: { address: input.address },
|
|
114
|
+
sigHash: input.sighashTypes &&
|
|
115
|
+
sighashNumberToString.sighashNumberToString(input.sighashTypes[0]),
|
|
116
|
+
signingIndexes: [input.index],
|
|
117
|
+
}))) !== null && _c !== void 0 ? _c : [],
|
|
118
|
+
psbt: base64.decodeBase64(request.unsignedPsbtBase64),
|
|
119
|
+
});
|
|
120
|
+
return {
|
|
121
|
+
signedPsbt: Buffer.from(signedPsbtHex.signedPsbt).toString('base64'),
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
else {
|
|
125
|
+
const provider = this.getProvider();
|
|
126
|
+
if (!provider) {
|
|
127
|
+
return;
|
|
128
|
+
}
|
|
129
|
+
const inputsToSign = (_e = (_d = request.signature) === null || _d === void 0 ? void 0 : _d.map((sig) => {
|
|
130
|
+
var _a;
|
|
131
|
+
return ({
|
|
132
|
+
address: sig.address,
|
|
133
|
+
sigHash: request.allowedSighash[0],
|
|
134
|
+
signingIndexes: (_a = sig.signingIndexes) !== null && _a !== void 0 ? _a : [],
|
|
135
|
+
});
|
|
136
|
+
})) !== null && _e !== void 0 ? _e : [];
|
|
137
|
+
const signedPsbt = yield provider.signPSBT(base64.decodeBase64(request.unsignedPsbtBase64), {
|
|
138
|
+
inputsToSign,
|
|
139
|
+
});
|
|
140
|
+
return { signedPsbt: base64.encodeBase64(Uint8Array.from(signedPsbt)) };
|
|
141
|
+
}
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
exports.PhantomConnector = PhantomConnector;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { BitcoinTransaction, BitcoinSignPsbtRequest, BitcoinSignPsbtResponse } from '../../types';
|
|
2
|
+
import { BitcoinWalletConnector, BitcoinWalletConnectorOpts } from '../BitcoinWalletConnector';
|
|
3
|
+
export declare class PhantomConnector extends BitcoinWalletConnector {
|
|
4
|
+
name: string;
|
|
5
|
+
constructor(opts: BitcoinWalletConnectorOpts);
|
|
6
|
+
private connectWithInstalledExtension;
|
|
7
|
+
getAddress(): Promise<string | undefined>;
|
|
8
|
+
signMessage(messageToSign: string): Promise<string | undefined>;
|
|
9
|
+
sendBitcoin(transaction: BitcoinTransaction): Promise<string | undefined>;
|
|
10
|
+
signPsbt(request: BitcoinSignPsbtRequest): Promise<BitcoinSignPsbtResponse | undefined>;
|
|
11
|
+
}
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
import { __awaiter } from '../../../_virtual/_tslib.js';
|
|
3
|
+
import { Psbt } from 'bitcoinjs-lib';
|
|
4
|
+
import { logger } from '@dynamic-labs/wallet-connector-core';
|
|
5
|
+
import { isMobile, handleMobileWalletRedirect } from '@dynamic-labs/utils';
|
|
6
|
+
import { BitcoinWalletConnector } from '../BitcoinWalletConnector.js';
|
|
7
|
+
import { createPsbtOptions } from '../../utils/psbt/createSignPsbtOptions.js';
|
|
8
|
+
import 'sats-connect';
|
|
9
|
+
import { sighashNumberToString } from '../../utils/psbt/sighashNumberToString.js';
|
|
10
|
+
import { decodeBase64, encodeBase64 } from '../../utils/base64.js';
|
|
11
|
+
|
|
12
|
+
class PhantomConnector extends BitcoinWalletConnector {
|
|
13
|
+
constructor(opts) {
|
|
14
|
+
super(Object.assign(Object.assign({}, opts), { overrideKey: 'phantombtc' }));
|
|
15
|
+
this.name = 'Phantom';
|
|
16
|
+
}
|
|
17
|
+
connectWithInstalledExtension() {
|
|
18
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
19
|
+
var _a, _b;
|
|
20
|
+
let paymentAccount, ordinalsAccount;
|
|
21
|
+
if ((_a = this.walletMethods) === null || _a === void 0 ? void 0 : _a.connect) {
|
|
22
|
+
const { accounts } = yield this.walletMethods.connect();
|
|
23
|
+
const parsedAccounts = accounts.map((account) => ({
|
|
24
|
+
address: account.address,
|
|
25
|
+
publicKey: Buffer.from(account.publicKey).toString('hex'),
|
|
26
|
+
}));
|
|
27
|
+
[paymentAccount, ordinalsAccount] = parsedAccounts;
|
|
28
|
+
// in case it only returns one account, we will use it as both payment and ordinals
|
|
29
|
+
if (!ordinalsAccount) {
|
|
30
|
+
ordinalsAccount = paymentAccount;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
else {
|
|
34
|
+
const provider = this.getProvider();
|
|
35
|
+
if (!provider) {
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
const accounts = yield provider.requestAccounts();
|
|
39
|
+
ordinalsAccount = accounts === null || accounts === void 0 ? void 0 : accounts.find((address) => address.purpose === 'ordinals');
|
|
40
|
+
paymentAccount = accounts === null || accounts === void 0 ? void 0 : accounts.find((address) => address.purpose === 'payment');
|
|
41
|
+
}
|
|
42
|
+
const mainAddress = (_b = ordinalsAccount === null || ordinalsAccount === void 0 ? void 0 : ordinalsAccount.address) !== null && _b !== void 0 ? _b : paymentAccount === null || paymentAccount === void 0 ? void 0 : paymentAccount.address;
|
|
43
|
+
yield this.setConnectedAccountWithAddresses({
|
|
44
|
+
active: true,
|
|
45
|
+
mainAddress,
|
|
46
|
+
ordinalsAddress: ordinalsAccount,
|
|
47
|
+
paymentAddress: paymentAccount,
|
|
48
|
+
});
|
|
49
|
+
return mainAddress;
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
getAddress() {
|
|
53
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
54
|
+
if (this.isInstalledOnBrowser()) {
|
|
55
|
+
return this.connectWithInstalledExtension();
|
|
56
|
+
}
|
|
57
|
+
if (isMobile()) {
|
|
58
|
+
handleMobileWalletRedirect({
|
|
59
|
+
nativeLink: 'phantom://browse',
|
|
60
|
+
universalLink: 'https://phantom.app/ul/browse',
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
return undefined;
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
signMessage(messageToSign) {
|
|
67
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
68
|
+
var _a;
|
|
69
|
+
const [walletAddress] = yield this.getConnectedAccounts();
|
|
70
|
+
if (!walletAddress) {
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
if ((_a = this.walletMethods) === null || _a === void 0 ? void 0 : _a.signMessage) {
|
|
74
|
+
const [result] = yield this.walletMethods.signMessage({
|
|
75
|
+
// we need to sign with the ordinals account
|
|
76
|
+
account: { address: walletAddress },
|
|
77
|
+
message: new TextEncoder().encode(messageToSign),
|
|
78
|
+
});
|
|
79
|
+
return Buffer.from(result.signature).toString('base64');
|
|
80
|
+
}
|
|
81
|
+
else {
|
|
82
|
+
const provider = this.getProvider();
|
|
83
|
+
if (!provider) {
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
const result = yield provider.signMessage(walletAddress, new TextEncoder().encode(messageToSign));
|
|
87
|
+
return Buffer.from(result.signature).toString('base64');
|
|
88
|
+
}
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
sendBitcoin(transaction) {
|
|
92
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
93
|
+
logger.debug('sendBitcoin - function not implemented', transaction);
|
|
94
|
+
return undefined;
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
signPsbt(request) {
|
|
98
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
99
|
+
var _a, _b, _c, _d, _e;
|
|
100
|
+
const [walletAddress] = yield this.getConnectedAccounts();
|
|
101
|
+
if (!walletAddress) {
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
104
|
+
const psbtFromBase64 = Psbt.fromBase64(request.unsignedPsbtBase64);
|
|
105
|
+
const psbtOptions = createPsbtOptions(psbtFromBase64, request);
|
|
106
|
+
if ((_a = this.walletMethods) === null || _a === void 0 ? void 0 : _a.signTransaction) {
|
|
107
|
+
const [signedPsbtHex] = yield this.walletMethods.signTransaction({
|
|
108
|
+
inputsToSign: (_c = (_b = psbtOptions.toSignInputs) === null || _b === void 0 ? void 0 : _b.map((input) => ({
|
|
109
|
+
account: { address: input.address },
|
|
110
|
+
sigHash: input.sighashTypes &&
|
|
111
|
+
sighashNumberToString(input.sighashTypes[0]),
|
|
112
|
+
signingIndexes: [input.index],
|
|
113
|
+
}))) !== null && _c !== void 0 ? _c : [],
|
|
114
|
+
psbt: decodeBase64(request.unsignedPsbtBase64),
|
|
115
|
+
});
|
|
116
|
+
return {
|
|
117
|
+
signedPsbt: Buffer.from(signedPsbtHex.signedPsbt).toString('base64'),
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
else {
|
|
121
|
+
const provider = this.getProvider();
|
|
122
|
+
if (!provider) {
|
|
123
|
+
return;
|
|
124
|
+
}
|
|
125
|
+
const inputsToSign = (_e = (_d = request.signature) === null || _d === void 0 ? void 0 : _d.map((sig) => {
|
|
126
|
+
var _a;
|
|
127
|
+
return ({
|
|
128
|
+
address: sig.address,
|
|
129
|
+
sigHash: request.allowedSighash[0],
|
|
130
|
+
signingIndexes: (_a = sig.signingIndexes) !== null && _a !== void 0 ? _a : [],
|
|
131
|
+
});
|
|
132
|
+
})) !== null && _e !== void 0 ? _e : [];
|
|
133
|
+
const signedPsbt = yield provider.signPSBT(decodeBase64(request.unsignedPsbtBase64), {
|
|
134
|
+
inputsToSign,
|
|
135
|
+
});
|
|
136
|
+
return { signedPsbt: encodeBase64(Uint8Array.from(signedPsbt)) };
|
|
137
|
+
}
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
export { PhantomConnector };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { PhantomConnector } from './PhantomConnector';
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
5
|
+
|
|
6
|
+
var _tslib = require('../../../_virtual/_tslib.cjs');
|
|
7
|
+
var bitcoinjsLib = require('bitcoinjs-lib');
|
|
8
|
+
var BitcoinWalletConnector = require('../BitcoinWalletConnector.cjs');
|
|
9
|
+
var createSignPsbtOptions = require('../../utils/psbt/createSignPsbtOptions.cjs');
|
|
10
|
+
|
|
11
|
+
class UnisatConnector extends BitcoinWalletConnector.BitcoinWalletConnector {
|
|
12
|
+
constructor(opts) {
|
|
13
|
+
super(Object.assign(Object.assign({}, opts), { overrideKey: 'unisat' }));
|
|
14
|
+
this.name = 'UniSat';
|
|
15
|
+
this.overrideKey = 'unisat';
|
|
16
|
+
}
|
|
17
|
+
getAddress() {
|
|
18
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
19
|
+
const provider = this.getProvider();
|
|
20
|
+
if (!provider) {
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
const [address] = yield provider.requestAccounts();
|
|
24
|
+
const publicKey = yield provider.getPublicKey();
|
|
25
|
+
const bitcoinAddress = {
|
|
26
|
+
address,
|
|
27
|
+
publicKey,
|
|
28
|
+
};
|
|
29
|
+
yield this.setConnectedAccountWithAddresses({
|
|
30
|
+
active: true,
|
|
31
|
+
mainAddress: address,
|
|
32
|
+
ordinalsAddress: bitcoinAddress,
|
|
33
|
+
});
|
|
34
|
+
return address;
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
signMessage(messageToSign) {
|
|
38
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
39
|
+
const provider = this.getProvider();
|
|
40
|
+
if (!provider) {
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
return provider.signMessage(messageToSign, 'bip322-simple');
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
sendBitcoin(transaction) {
|
|
47
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
48
|
+
const provider = this.getProvider();
|
|
49
|
+
const connectedAddress = yield this.getAddress();
|
|
50
|
+
if (!connectedAddress || !provider) {
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
return provider.sendBitcoin(transaction.recipientAddress, transaction.amount.toString());
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
signPsbt(request) {
|
|
57
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
58
|
+
const provider = this.getProvider();
|
|
59
|
+
if (!provider) {
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
const psbtFromBase64 = bitcoinjsLib.Psbt.fromBase64(request.unsignedPsbtBase64);
|
|
63
|
+
const signedPsbtHex = yield provider.signPsbt(psbtFromBase64.toHex(), createSignPsbtOptions.createPsbtOptions(psbtFromBase64, request));
|
|
64
|
+
return { signedPsbt: bitcoinjsLib.Psbt.fromHex(signedPsbtHex).toBase64() };
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
getConnectedAccounts() {
|
|
68
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
69
|
+
const provider = this.getProvider();
|
|
70
|
+
if (!provider) {
|
|
71
|
+
return [];
|
|
72
|
+
}
|
|
73
|
+
return provider.getAccounts();
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
exports.UnisatConnector = UnisatConnector;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { BitcoinWalletConnector, BitcoinWalletConnectorOpts } from '../BitcoinWalletConnector';
|
|
2
|
+
import { BitcoinTransaction, BitcoinSignPsbtRequest, BitcoinSignPsbtResponse } from '../../types';
|
|
3
|
+
export declare class UnisatConnector extends BitcoinWalletConnector {
|
|
4
|
+
name: string;
|
|
5
|
+
overrideKey: string;
|
|
6
|
+
constructor(opts: BitcoinWalletConnectorOpts);
|
|
7
|
+
getAddress(): Promise<string | undefined>;
|
|
8
|
+
signMessage(messageToSign: string): Promise<string | undefined>;
|
|
9
|
+
sendBitcoin(transaction: BitcoinTransaction): Promise<string | undefined>;
|
|
10
|
+
signPsbt(request: BitcoinSignPsbtRequest): Promise<BitcoinSignPsbtResponse | undefined>;
|
|
11
|
+
getConnectedAccounts(): Promise<string[]>;
|
|
12
|
+
}
|