@dynamic-labs/bitcoin 3.0.0-alpha.9 → 3.0.1
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 +628 -0
- package/package.json +7 -6
- package/src/BitcoinLocalStorageCache.cjs +0 -16
- package/src/BitcoinLocalStorageCache.d.ts +0 -7
- package/src/BitcoinLocalStorageCache.js +0 -16
- package/src/bitcoinProviderHelper.d.ts +1 -0
- package/src/connectors/BitcoinSatsConnectConnector/BitcoinSatsConnectConnector.cjs +170 -141
- package/src/connectors/BitcoinSatsConnectConnector/BitcoinSatsConnectConnector.d.ts +8 -3
- package/src/connectors/BitcoinSatsConnectConnector/BitcoinSatsConnectConnector.js +171 -142
- package/src/connectors/BitcoinSatsConnectLegacyConnector/BitcoinSatsConnectLegacyConnector.cjs +216 -0
- package/src/connectors/BitcoinSatsConnectLegacyConnector/BitcoinSatsConnectLegacyConnector.d.ts +11 -0
- package/src/connectors/BitcoinSatsConnectLegacyConnector/BitcoinSatsConnectLegacyConnector.js +212 -0
- package/src/connectors/BitcoinSatsConnectLegacyConnector/index.d.ts +1 -0
- package/src/connectors/BitcoinWalletConnector.cjs +44 -29
- package/src/connectors/BitcoinWalletConnector.d.ts +7 -3
- package/src/connectors/BitcoinWalletConnector.js +45 -30
- package/src/connectors/FallbackBitcoinConnector/FallbackBitcoinConnector.cjs +7 -1
- package/src/connectors/FallbackBitcoinConnector/FallbackBitcoinConnector.d.ts +1 -1
- package/src/connectors/FallbackBitcoinConnector/FallbackBitcoinConnector.js +7 -1
- package/src/connectors/OkxConnector/OkxConnector.cjs +19 -2
- package/src/connectors/OkxConnector/OkxConnector.d.ts +1 -1
- package/src/connectors/OkxConnector/OkxConnector.js +19 -2
- package/src/connectors/PhantomConnector/PhantomConnector.cjs +4 -9
- package/src/connectors/PhantomConnector/PhantomConnector.d.ts +1 -2
- package/src/connectors/PhantomConnector/PhantomConnector.js +4 -9
- package/src/connectors/UnisatConnector/UnisatConnector.cjs +17 -1
- package/src/connectors/UnisatConnector/UnisatConnector.d.ts +1 -1
- package/src/connectors/UnisatConnector/UnisatConnector.js +17 -1
- package/src/connectors/UnknownInjected/UnknownInjected.cjs +7 -1
- package/src/connectors/UnknownInjected/UnknownInjected.d.ts +1 -1
- package/src/connectors/UnknownInjected/UnknownInjected.js +7 -1
- package/src/connectors/index.d.ts +1 -0
- package/src/index.cjs +4 -0
- package/src/index.d.ts +3 -2
- package/src/index.js +2 -0
- package/src/types.d.ts +1 -0
- package/src/utils/fetchSatsConnectConnectors/fetchSatsConnectConnectors.cjs +15 -3
- package/src/utils/fetchSatsConnectConnectors/fetchSatsConnectConnectors.js +15 -3
- package/src/utils/psbt/bitcoinNetworkTypeToNetworks.cjs +1 -0
- package/src/utils/psbt/bitcoinNetworkTypeToNetworks.d.ts +1 -1
- package/src/utils/psbt/bitcoinNetworkTypeToNetworks.js +1 -0
- package/src/utils/psbt/createSignPsbtOptions.cjs +22 -1
- package/src/utils/psbt/createSignPsbtOptions.d.ts +2 -0
- package/src/utils/psbt/createSignPsbtOptions.js +22 -2
- package/src/wallet/BitcoinWallet.cjs +69 -0
- package/src/wallet/BitcoinWallet.d.ts +36 -0
- package/src/wallet/BitcoinWallet.js +65 -0
- package/src/wallet/index.d.ts +2 -0
- package/src/wallet/isBitcoinWallet/index.d.ts +1 -0
- package/src/wallet/isBitcoinWallet/isBitcoinWallet.cjs +8 -0
- package/src/wallet/isBitcoinWallet/isBitcoinWallet.d.ts +3 -0
- package/src/wallet/isBitcoinWallet/isBitcoinWallet.js +4 -0
|
@@ -13,7 +13,6 @@ class OkxConnector extends BitcoinWalletConnector.BitcoinWalletConnector {
|
|
|
13
13
|
constructor(opts) {
|
|
14
14
|
super(Object.assign(Object.assign({}, opts), { overrideKey: 'okxwalletbtc' }));
|
|
15
15
|
this.name = 'OKX Wallet';
|
|
16
|
-
this.canFetchConnectedAccounts = false;
|
|
17
16
|
}
|
|
18
17
|
get walletBookWallet() {
|
|
19
18
|
return this.walletBook.wallets[this.key];
|
|
@@ -23,7 +22,8 @@ class OkxConnector extends BitcoinWalletConnector.BitcoinWalletConnector {
|
|
|
23
22
|
if (!this.isInstalledOnBrowser() &&
|
|
24
23
|
utils.isMobile() &&
|
|
25
24
|
this.walletBookWallet.mobile &&
|
|
26
|
-
this.walletBookWallet.mobile.inAppBrowser
|
|
25
|
+
this.walletBookWallet.mobile.inAppBrowser &&
|
|
26
|
+
this.mobileExperience === 'in-app-browser') {
|
|
27
27
|
const inAppBrowserCompiledTemplate = utils.template(this.walletBookWallet.mobile.inAppBrowser);
|
|
28
28
|
const deepLink = inAppBrowserCompiledTemplate({
|
|
29
29
|
encodedDappURI: encodeURIComponent(window.location.toString()),
|
|
@@ -78,6 +78,23 @@ class OkxConnector extends BitcoinWalletConnector.BitcoinWalletConnector {
|
|
|
78
78
|
return { signedPsbt: bitcoinjsLib.Psbt.fromHex(signedPsbtHex).toBase64() };
|
|
79
79
|
});
|
|
80
80
|
}
|
|
81
|
+
signPsbts(requests) {
|
|
82
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
83
|
+
const provider = this.getProvider();
|
|
84
|
+
if (!provider) {
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
const psbtHexs = [];
|
|
88
|
+
const psbtOptions = [];
|
|
89
|
+
for (const request of requests) {
|
|
90
|
+
const psbt = bitcoinjsLib.Psbt.fromBase64(request.unsignedPsbtBase64);
|
|
91
|
+
psbtHexs.push(psbt.toHex());
|
|
92
|
+
psbtOptions.push(createSignPsbtOptions.createPsbtOptions(psbt, request));
|
|
93
|
+
}
|
|
94
|
+
const signedPsbtHexs = yield provider.signPsbts(psbtHexs, psbtOptions);
|
|
95
|
+
return signedPsbtHexs.map((signedPsbtHex) => bitcoinjsLib.Psbt.fromHex(signedPsbtHex).toBase64());
|
|
96
|
+
});
|
|
97
|
+
}
|
|
81
98
|
}
|
|
82
99
|
|
|
83
100
|
exports.OkxConnector = OkxConnector;
|
|
@@ -2,11 +2,11 @@ import { BitcoinWalletConnector, BitcoinWalletConnectorOpts } from '../BitcoinWa
|
|
|
2
2
|
import { BitcoinTransaction, BitcoinSignPsbtRequest, BitcoinSignPsbtResponse } from '../../types';
|
|
3
3
|
export declare class OkxConnector extends BitcoinWalletConnector {
|
|
4
4
|
name: string;
|
|
5
|
-
canFetchConnectedAccounts: boolean;
|
|
6
5
|
constructor(opts: BitcoinWalletConnectorOpts);
|
|
7
6
|
private get walletBookWallet();
|
|
8
7
|
getAddress(): Promise<string | undefined>;
|
|
9
8
|
signMessage(messageToSign: string): Promise<string | undefined>;
|
|
10
9
|
sendBitcoin(transaction: BitcoinTransaction): Promise<string | undefined>;
|
|
11
10
|
signPsbt(request: BitcoinSignPsbtRequest): Promise<BitcoinSignPsbtResponse | undefined>;
|
|
11
|
+
signPsbts(requests: BitcoinSignPsbtRequest[]): Promise<string[] | undefined>;
|
|
12
12
|
}
|
|
@@ -9,7 +9,6 @@ class OkxConnector extends BitcoinWalletConnector {
|
|
|
9
9
|
constructor(opts) {
|
|
10
10
|
super(Object.assign(Object.assign({}, opts), { overrideKey: 'okxwalletbtc' }));
|
|
11
11
|
this.name = 'OKX Wallet';
|
|
12
|
-
this.canFetchConnectedAccounts = false;
|
|
13
12
|
}
|
|
14
13
|
get walletBookWallet() {
|
|
15
14
|
return this.walletBook.wallets[this.key];
|
|
@@ -19,7 +18,8 @@ class OkxConnector extends BitcoinWalletConnector {
|
|
|
19
18
|
if (!this.isInstalledOnBrowser() &&
|
|
20
19
|
isMobile() &&
|
|
21
20
|
this.walletBookWallet.mobile &&
|
|
22
|
-
this.walletBookWallet.mobile.inAppBrowser
|
|
21
|
+
this.walletBookWallet.mobile.inAppBrowser &&
|
|
22
|
+
this.mobileExperience === 'in-app-browser') {
|
|
23
23
|
const inAppBrowserCompiledTemplate = template(this.walletBookWallet.mobile.inAppBrowser);
|
|
24
24
|
const deepLink = inAppBrowserCompiledTemplate({
|
|
25
25
|
encodedDappURI: encodeURIComponent(window.location.toString()),
|
|
@@ -74,6 +74,23 @@ class OkxConnector extends BitcoinWalletConnector {
|
|
|
74
74
|
return { signedPsbt: Psbt.fromHex(signedPsbtHex).toBase64() };
|
|
75
75
|
});
|
|
76
76
|
}
|
|
77
|
+
signPsbts(requests) {
|
|
78
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
79
|
+
const provider = this.getProvider();
|
|
80
|
+
if (!provider) {
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
const psbtHexs = [];
|
|
84
|
+
const psbtOptions = [];
|
|
85
|
+
for (const request of requests) {
|
|
86
|
+
const psbt = Psbt.fromBase64(request.unsignedPsbtBase64);
|
|
87
|
+
psbtHexs.push(psbt.toHex());
|
|
88
|
+
psbtOptions.push(createPsbtOptions(psbt, request));
|
|
89
|
+
}
|
|
90
|
+
const signedPsbtHexs = yield provider.signPsbts(psbtHexs, psbtOptions);
|
|
91
|
+
return signedPsbtHexs.map((signedPsbtHex) => Psbt.fromHex(signedPsbtHex).toBase64());
|
|
92
|
+
});
|
|
93
|
+
}
|
|
77
94
|
}
|
|
78
95
|
|
|
79
96
|
export { OkxConnector };
|
|
@@ -17,7 +17,6 @@ class PhantomConnector extends BitcoinWalletConnector.BitcoinWalletConnector {
|
|
|
17
17
|
constructor(opts) {
|
|
18
18
|
super(Object.assign(Object.assign({}, opts), { overrideKey: 'phantombtc' }));
|
|
19
19
|
this.name = 'Phantom';
|
|
20
|
-
this.canFetchConnectedAccounts = true;
|
|
21
20
|
}
|
|
22
21
|
connectWithInstalledExtension() {
|
|
23
22
|
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
@@ -27,7 +26,7 @@ class PhantomConnector extends BitcoinWalletConnector.BitcoinWalletConnector {
|
|
|
27
26
|
const { accounts } = yield this.walletMethods.connect();
|
|
28
27
|
const parsedAccounts = accounts.map((account) => ({
|
|
29
28
|
address: account.address,
|
|
30
|
-
publicKey: Buffer.from(account.publicKey).toString('
|
|
29
|
+
publicKey: Buffer.from(account.publicKey).toString('hex'),
|
|
31
30
|
}));
|
|
32
31
|
[paymentAccount, ordinalsAccount] = parsedAccounts;
|
|
33
32
|
// in case it only returns one account, we will use it as both payment and ordinals
|
|
@@ -68,17 +67,13 @@ class PhantomConnector extends BitcoinWalletConnector.BitcoinWalletConnector {
|
|
|
68
67
|
return undefined;
|
|
69
68
|
});
|
|
70
69
|
}
|
|
71
|
-
signMessage(messageToSign) {
|
|
70
|
+
signMessage(messageToSign, withAddress) {
|
|
72
71
|
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
73
72
|
var _a;
|
|
74
|
-
const [walletAddress] = yield this.getConnectedAccounts();
|
|
75
|
-
if (!walletAddress) {
|
|
76
|
-
return;
|
|
77
|
-
}
|
|
78
73
|
if ((_a = this.walletMethods) === null || _a === void 0 ? void 0 : _a.signMessage) {
|
|
79
74
|
const [result] = yield this.walletMethods.signMessage({
|
|
80
75
|
// we need to sign with the ordinals account
|
|
81
|
-
account: { address:
|
|
76
|
+
account: { address: withAddress },
|
|
82
77
|
message: new TextEncoder().encode(messageToSign),
|
|
83
78
|
});
|
|
84
79
|
return Buffer.from(result.signature).toString('base64');
|
|
@@ -88,7 +83,7 @@ class PhantomConnector extends BitcoinWalletConnector.BitcoinWalletConnector {
|
|
|
88
83
|
if (!provider) {
|
|
89
84
|
return;
|
|
90
85
|
}
|
|
91
|
-
const result = yield provider.signMessage(
|
|
86
|
+
const result = yield provider.signMessage(withAddress, new TextEncoder().encode(messageToSign));
|
|
92
87
|
return Buffer.from(result.signature).toString('base64');
|
|
93
88
|
}
|
|
94
89
|
});
|
|
@@ -2,11 +2,10 @@ import { BitcoinTransaction, BitcoinSignPsbtRequest, BitcoinSignPsbtResponse } f
|
|
|
2
2
|
import { BitcoinWalletConnector, BitcoinWalletConnectorOpts } from '../BitcoinWalletConnector';
|
|
3
3
|
export declare class PhantomConnector extends BitcoinWalletConnector {
|
|
4
4
|
name: string;
|
|
5
|
-
canFetchConnectedAccounts: boolean;
|
|
6
5
|
constructor(opts: BitcoinWalletConnectorOpts);
|
|
7
6
|
private connectWithInstalledExtension;
|
|
8
7
|
getAddress(): Promise<string | undefined>;
|
|
9
|
-
signMessage(messageToSign: string): Promise<string | undefined>;
|
|
8
|
+
signMessage(messageToSign: string, withAddress: string): Promise<string | undefined>;
|
|
10
9
|
sendBitcoin(transaction: BitcoinTransaction): Promise<string | undefined>;
|
|
11
10
|
signPsbt(request: BitcoinSignPsbtRequest): Promise<BitcoinSignPsbtResponse | undefined>;
|
|
12
11
|
}
|
|
@@ -13,7 +13,6 @@ class PhantomConnector extends BitcoinWalletConnector {
|
|
|
13
13
|
constructor(opts) {
|
|
14
14
|
super(Object.assign(Object.assign({}, opts), { overrideKey: 'phantombtc' }));
|
|
15
15
|
this.name = 'Phantom';
|
|
16
|
-
this.canFetchConnectedAccounts = true;
|
|
17
16
|
}
|
|
18
17
|
connectWithInstalledExtension() {
|
|
19
18
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -23,7 +22,7 @@ class PhantomConnector extends BitcoinWalletConnector {
|
|
|
23
22
|
const { accounts } = yield this.walletMethods.connect();
|
|
24
23
|
const parsedAccounts = accounts.map((account) => ({
|
|
25
24
|
address: account.address,
|
|
26
|
-
publicKey: Buffer.from(account.publicKey).toString('
|
|
25
|
+
publicKey: Buffer.from(account.publicKey).toString('hex'),
|
|
27
26
|
}));
|
|
28
27
|
[paymentAccount, ordinalsAccount] = parsedAccounts;
|
|
29
28
|
// in case it only returns one account, we will use it as both payment and ordinals
|
|
@@ -64,17 +63,13 @@ class PhantomConnector extends BitcoinWalletConnector {
|
|
|
64
63
|
return undefined;
|
|
65
64
|
});
|
|
66
65
|
}
|
|
67
|
-
signMessage(messageToSign) {
|
|
66
|
+
signMessage(messageToSign, withAddress) {
|
|
68
67
|
return __awaiter(this, void 0, void 0, function* () {
|
|
69
68
|
var _a;
|
|
70
|
-
const [walletAddress] = yield this.getConnectedAccounts();
|
|
71
|
-
if (!walletAddress) {
|
|
72
|
-
return;
|
|
73
|
-
}
|
|
74
69
|
if ((_a = this.walletMethods) === null || _a === void 0 ? void 0 : _a.signMessage) {
|
|
75
70
|
const [result] = yield this.walletMethods.signMessage({
|
|
76
71
|
// we need to sign with the ordinals account
|
|
77
|
-
account: { address:
|
|
72
|
+
account: { address: withAddress },
|
|
78
73
|
message: new TextEncoder().encode(messageToSign),
|
|
79
74
|
});
|
|
80
75
|
return Buffer.from(result.signature).toString('base64');
|
|
@@ -84,7 +79,7 @@ class PhantomConnector extends BitcoinWalletConnector {
|
|
|
84
79
|
if (!provider) {
|
|
85
80
|
return;
|
|
86
81
|
}
|
|
87
|
-
const result = yield provider.signMessage(
|
|
82
|
+
const result = yield provider.signMessage(withAddress, new TextEncoder().encode(messageToSign));
|
|
88
83
|
return Buffer.from(result.signature).toString('base64');
|
|
89
84
|
}
|
|
90
85
|
});
|
|
@@ -13,7 +13,6 @@ class UnisatConnector extends BitcoinWalletConnector.BitcoinWalletConnector {
|
|
|
13
13
|
super(Object.assign(Object.assign({}, opts), { overrideKey: 'unisat' }));
|
|
14
14
|
this.name = 'UniSat';
|
|
15
15
|
this.overrideKey = 'unisat';
|
|
16
|
-
this.canFetchConnectedAccounts = true;
|
|
17
16
|
}
|
|
18
17
|
getAddress() {
|
|
19
18
|
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
@@ -65,6 +64,23 @@ class UnisatConnector extends BitcoinWalletConnector.BitcoinWalletConnector {
|
|
|
65
64
|
return { signedPsbt: bitcoinjsLib.Psbt.fromHex(signedPsbtHex).toBase64() };
|
|
66
65
|
});
|
|
67
66
|
}
|
|
67
|
+
signPsbts(requests) {
|
|
68
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
69
|
+
const provider = this.getProvider();
|
|
70
|
+
if (!provider) {
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
const psbtHexs = [];
|
|
74
|
+
const psbtOptions = [];
|
|
75
|
+
for (const request of requests) {
|
|
76
|
+
const psbtFromBase64 = bitcoinjsLib.Psbt.fromBase64(request.unsignedPsbtBase64);
|
|
77
|
+
psbtHexs.push(psbtFromBase64.toHex());
|
|
78
|
+
psbtOptions.push(createSignPsbtOptions.createPsbtOptions(psbtFromBase64, request));
|
|
79
|
+
}
|
|
80
|
+
const signedPsbtHexs = yield provider.signPsbts(psbtHexs, psbtOptions);
|
|
81
|
+
return signedPsbtHexs.map((signedPsbtHex) => bitcoinjsLib.Psbt.fromHex(signedPsbtHex).toBase64());
|
|
82
|
+
});
|
|
83
|
+
}
|
|
68
84
|
getConnectedAccounts() {
|
|
69
85
|
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
70
86
|
const provider = this.getProvider();
|
|
@@ -3,11 +3,11 @@ import { BitcoinTransaction, BitcoinSignPsbtRequest, BitcoinSignPsbtResponse } f
|
|
|
3
3
|
export declare class UnisatConnector extends BitcoinWalletConnector {
|
|
4
4
|
name: string;
|
|
5
5
|
overrideKey: string;
|
|
6
|
-
canFetchConnectedAccounts: boolean;
|
|
7
6
|
constructor(opts: BitcoinWalletConnectorOpts);
|
|
8
7
|
getAddress(): Promise<string | undefined>;
|
|
9
8
|
signMessage(messageToSign: string): Promise<string | undefined>;
|
|
10
9
|
sendBitcoin(transaction: BitcoinTransaction): Promise<string | undefined>;
|
|
11
10
|
signPsbt(request: BitcoinSignPsbtRequest): Promise<BitcoinSignPsbtResponse | undefined>;
|
|
11
|
+
signPsbts(requests: BitcoinSignPsbtRequest[]): Promise<string[] | undefined>;
|
|
12
12
|
getConnectedAccounts(): Promise<string[]>;
|
|
13
13
|
}
|
|
@@ -9,7 +9,6 @@ class UnisatConnector extends BitcoinWalletConnector {
|
|
|
9
9
|
super(Object.assign(Object.assign({}, opts), { overrideKey: 'unisat' }));
|
|
10
10
|
this.name = 'UniSat';
|
|
11
11
|
this.overrideKey = 'unisat';
|
|
12
|
-
this.canFetchConnectedAccounts = true;
|
|
13
12
|
}
|
|
14
13
|
getAddress() {
|
|
15
14
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -61,6 +60,23 @@ class UnisatConnector extends BitcoinWalletConnector {
|
|
|
61
60
|
return { signedPsbt: Psbt.fromHex(signedPsbtHex).toBase64() };
|
|
62
61
|
});
|
|
63
62
|
}
|
|
63
|
+
signPsbts(requests) {
|
|
64
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
65
|
+
const provider = this.getProvider();
|
|
66
|
+
if (!provider) {
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
const psbtHexs = [];
|
|
70
|
+
const psbtOptions = [];
|
|
71
|
+
for (const request of requests) {
|
|
72
|
+
const psbtFromBase64 = Psbt.fromBase64(request.unsignedPsbtBase64);
|
|
73
|
+
psbtHexs.push(psbtFromBase64.toHex());
|
|
74
|
+
psbtOptions.push(createPsbtOptions(psbtFromBase64, request));
|
|
75
|
+
}
|
|
76
|
+
const signedPsbtHexs = yield provider.signPsbts(psbtHexs, psbtOptions);
|
|
77
|
+
return signedPsbtHexs.map((signedPsbtHex) => Psbt.fromHex(signedPsbtHex).toBase64());
|
|
78
|
+
});
|
|
79
|
+
}
|
|
64
80
|
getConnectedAccounts() {
|
|
65
81
|
return __awaiter(this, void 0, void 0, function* () {
|
|
66
82
|
const provider = this.getProvider();
|
|
@@ -11,7 +11,6 @@ class UnknownInjectedConnector extends BitcoinWalletConnector.BitcoinWalletConne
|
|
|
11
11
|
super(Object.assign(Object.assign({}, opts), { overrideKey: 'unknown' }));
|
|
12
12
|
this.name = 'Unknown';
|
|
13
13
|
this.overrideKey = 'unknown';
|
|
14
|
-
this.canFetchConnectedAccounts = false;
|
|
15
14
|
}
|
|
16
15
|
getAddress() {
|
|
17
16
|
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
@@ -25,6 +24,13 @@ class UnknownInjectedConnector extends BitcoinWalletConnector.BitcoinWalletConne
|
|
|
25
24
|
return;
|
|
26
25
|
});
|
|
27
26
|
}
|
|
27
|
+
signPsbts(
|
|
28
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
29
|
+
_requests) {
|
|
30
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
31
|
+
return;
|
|
32
|
+
});
|
|
33
|
+
}
|
|
28
34
|
sendBitcoin(
|
|
29
35
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
30
36
|
_transaction) {
|
|
@@ -3,9 +3,9 @@ import { BitcoinWalletConnector, BitcoinWalletConnectorOpts } from '../BitcoinWa
|
|
|
3
3
|
export declare class UnknownInjectedConnector extends BitcoinWalletConnector {
|
|
4
4
|
name: string;
|
|
5
5
|
overrideKey: string;
|
|
6
|
-
canFetchConnectedAccounts: boolean;
|
|
7
6
|
constructor(opts: BitcoinWalletConnectorOpts);
|
|
8
7
|
getAddress(): Promise<string | undefined>;
|
|
9
8
|
signPsbt(_request: BitcoinSignPsbtRequest): Promise<BitcoinSignPsbtResponse | undefined>;
|
|
9
|
+
signPsbts(_requests: BitcoinSignPsbtRequest[]): Promise<string[] | undefined>;
|
|
10
10
|
sendBitcoin(_transaction: BitcoinTransaction): Promise<string | undefined>;
|
|
11
11
|
}
|
|
@@ -7,7 +7,6 @@ class UnknownInjectedConnector extends BitcoinWalletConnector {
|
|
|
7
7
|
super(Object.assign(Object.assign({}, opts), { overrideKey: 'unknown' }));
|
|
8
8
|
this.name = 'Unknown';
|
|
9
9
|
this.overrideKey = 'unknown';
|
|
10
|
-
this.canFetchConnectedAccounts = false;
|
|
11
10
|
}
|
|
12
11
|
getAddress() {
|
|
13
12
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -21,6 +20,13 @@ class UnknownInjectedConnector extends BitcoinWalletConnector {
|
|
|
21
20
|
return;
|
|
22
21
|
});
|
|
23
22
|
}
|
|
23
|
+
signPsbts(
|
|
24
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
25
|
+
_requests) {
|
|
26
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
27
|
+
return;
|
|
28
|
+
});
|
|
29
|
+
}
|
|
24
30
|
sendBitcoin(
|
|
25
31
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
26
32
|
_transaction) {
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export * from './BitcoinWalletConnector';
|
|
2
2
|
export * from './BitcoinBtcKitConnector';
|
|
3
3
|
export * from './BitcoinSatsConnectConnector';
|
|
4
|
+
export * from './BitcoinSatsConnectLegacyConnector';
|
|
4
5
|
export * from './PhantomConnector';
|
|
5
6
|
export * from './OkxConnector';
|
|
6
7
|
export * from './UnisatConnector';
|
package/src/index.cjs
CHANGED
|
@@ -20,6 +20,8 @@ var OkxConnector = require('./connectors/OkxConnector/OkxConnector.cjs');
|
|
|
20
20
|
var UnisatConnector = require('./connectors/UnisatConnector/UnisatConnector.cjs');
|
|
21
21
|
var UnknownInjected = require('./connectors/UnknownInjected/UnknownInjected.cjs');
|
|
22
22
|
var FallbackBitcoinConnector = require('./connectors/FallbackBitcoinConnector/FallbackBitcoinConnector.cjs');
|
|
23
|
+
var BitcoinWallet = require('./wallet/BitcoinWallet.cjs');
|
|
24
|
+
var isBitcoinWallet = require('./wallet/isBitcoinWallet/isBitcoinWallet.cjs');
|
|
23
25
|
|
|
24
26
|
const BitcoinWalletConnectors = (props) => [
|
|
25
27
|
...fetchSatsConnectConnectors.fetchSatsConnectConnectors(props),
|
|
@@ -37,4 +39,6 @@ exports.fetchSatsConnectConnectors = fetchSatsConnectConnectors.fetchSatsConnect
|
|
|
37
39
|
exports.hasSatsConnectFeature = hasSatsConnectFeature.hasSatsConnectFeature;
|
|
38
40
|
exports.supportsSatsConnect = supportsSatsConnect.supportsSatsConnect;
|
|
39
41
|
exports.getMempoolApiUrl = getMempoolApiUrl.getMempoolApiUrl;
|
|
42
|
+
exports.BitcoinWallet = BitcoinWallet.BitcoinWallet;
|
|
43
|
+
exports.isBitcoinWallet = isBitcoinWallet.isBitcoinWallet;
|
|
40
44
|
exports.BitcoinWalletConnectors = BitcoinWalletConnectors;
|
package/src/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { OkxConnector,
|
|
1
|
+
import { OkxConnector, UnknownInjectedConnector, PhantomConnector } from './connectors';
|
|
2
2
|
export { BitcoinWalletConnector } from './connectors';
|
|
3
3
|
export type { BitcoinTransaction } from './types';
|
|
4
4
|
export * from './utils';
|
|
5
|
-
export
|
|
5
|
+
export * from './wallet';
|
|
6
|
+
export declare const BitcoinWalletConnectors: (props: any) => (import("dist/packages/wallet-connector-core/src").WalletConnectorConstructor | typeof PhantomConnector | typeof OkxConnector | typeof UnknownInjectedConnector)[];
|
package/src/index.js
CHANGED
|
@@ -18,6 +18,8 @@ import { OkxConnector } from './connectors/OkxConnector/OkxConnector.js';
|
|
|
18
18
|
import { UnisatConnector } from './connectors/UnisatConnector/UnisatConnector.js';
|
|
19
19
|
import { UnknownInjectedConnector } from './connectors/UnknownInjected/UnknownInjected.js';
|
|
20
20
|
import { FallbackBitcoinConnector } from './connectors/FallbackBitcoinConnector/FallbackBitcoinConnector.js';
|
|
21
|
+
export { BitcoinWallet } from './wallet/BitcoinWallet.js';
|
|
22
|
+
export { isBitcoinWallet } from './wallet/isBitcoinWallet/isBitcoinWallet.js';
|
|
21
23
|
|
|
22
24
|
const BitcoinWalletConnectors = (props) => [
|
|
23
25
|
...fetchSatsConnectConnectors(props),
|
package/src/types.d.ts
CHANGED
|
@@ -5,14 +5,15 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
5
5
|
|
|
6
6
|
var _const = require('../../const.cjs');
|
|
7
7
|
require('../../../_virtual/_tslib.cjs');
|
|
8
|
+
require('sats-connect');
|
|
8
9
|
require('@dynamic-labs/wallet-connector-core');
|
|
9
10
|
require('@dynamic-labs/wallet-book');
|
|
10
11
|
require('@dynamic-labs/utils');
|
|
11
12
|
require('@dynamic-labs/sdk-api-core');
|
|
12
13
|
require('@wallet-standard/app');
|
|
13
|
-
require('sats-connect');
|
|
14
14
|
require('bitcoinjs-lib');
|
|
15
15
|
var BitcoinSatsConnectConnector = require('../../connectors/BitcoinSatsConnectConnector/BitcoinSatsConnectConnector.cjs');
|
|
16
|
+
var BitcoinSatsConnectLegacyConnector = require('../../connectors/BitcoinSatsConnectLegacyConnector/BitcoinSatsConnectLegacyConnector.cjs');
|
|
16
17
|
|
|
17
18
|
const fetchSatsConnectConnectors = ({ walletBook, }) => {
|
|
18
19
|
var _a;
|
|
@@ -27,9 +28,20 @@ const fetchSatsConnectConnectors = ({ walletBook, }) => {
|
|
|
27
28
|
});
|
|
28
29
|
})
|
|
29
30
|
.map(([key, wallet]) => {
|
|
30
|
-
|
|
31
|
+
var _a;
|
|
32
|
+
const { shortName, injectedConfig } = wallet;
|
|
31
33
|
const name = shortName || wallet.name;
|
|
32
|
-
|
|
34
|
+
// if has providerId, use the new connector (xverse)
|
|
35
|
+
if ((_a = injectedConfig === null || injectedConfig === void 0 ? void 0 : injectedConfig[0].walletStandard) === null || _a === void 0 ? void 0 : _a.providerId) {
|
|
36
|
+
return class extends BitcoinSatsConnectConnector.BitcoinSatsConnectConnector {
|
|
37
|
+
constructor(props) {
|
|
38
|
+
super(Object.assign(Object.assign({}, props), { overrideKey: key, walletData: wallet }));
|
|
39
|
+
this.name = name;
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
// id doesn't have providerId, use the legacy connector (magiceden)
|
|
44
|
+
return class extends BitcoinSatsConnectLegacyConnector.BitcoinSatsConnectLegacyConnector {
|
|
33
45
|
constructor(props) {
|
|
34
46
|
super(Object.assign(Object.assign({}, props), { overrideKey: key, walletData: wallet }));
|
|
35
47
|
this.name = name;
|
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
'use client'
|
|
2
2
|
import { SATSCONNECT_FEATURE } from '../../const.js';
|
|
3
3
|
import '../../../_virtual/_tslib.js';
|
|
4
|
+
import 'sats-connect';
|
|
4
5
|
import '@dynamic-labs/wallet-connector-core';
|
|
5
6
|
import '@dynamic-labs/wallet-book';
|
|
6
7
|
import '@dynamic-labs/utils';
|
|
7
8
|
import '@dynamic-labs/sdk-api-core';
|
|
8
9
|
import '@wallet-standard/app';
|
|
9
|
-
import 'sats-connect';
|
|
10
10
|
import 'bitcoinjs-lib';
|
|
11
11
|
import { BitcoinSatsConnectConnector } from '../../connectors/BitcoinSatsConnectConnector/BitcoinSatsConnectConnector.js';
|
|
12
|
+
import { BitcoinSatsConnectLegacyConnector } from '../../connectors/BitcoinSatsConnectLegacyConnector/BitcoinSatsConnectLegacyConnector.js';
|
|
12
13
|
|
|
13
14
|
const fetchSatsConnectConnectors = ({ walletBook, }) => {
|
|
14
15
|
var _a;
|
|
@@ -23,9 +24,20 @@ const fetchSatsConnectConnectors = ({ walletBook, }) => {
|
|
|
23
24
|
});
|
|
24
25
|
})
|
|
25
26
|
.map(([key, wallet]) => {
|
|
26
|
-
|
|
27
|
+
var _a;
|
|
28
|
+
const { shortName, injectedConfig } = wallet;
|
|
27
29
|
const name = shortName || wallet.name;
|
|
28
|
-
|
|
30
|
+
// if has providerId, use the new connector (xverse)
|
|
31
|
+
if ((_a = injectedConfig === null || injectedConfig === void 0 ? void 0 : injectedConfig[0].walletStandard) === null || _a === void 0 ? void 0 : _a.providerId) {
|
|
32
|
+
return class extends BitcoinSatsConnectConnector {
|
|
33
|
+
constructor(props) {
|
|
34
|
+
super(Object.assign(Object.assign({}, props), { overrideKey: key, walletData: wallet }));
|
|
35
|
+
this.name = name;
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
// id doesn't have providerId, use the legacy connector (magiceden)
|
|
40
|
+
return class extends BitcoinSatsConnectLegacyConnector {
|
|
29
41
|
constructor(props) {
|
|
30
42
|
super(Object.assign(Object.assign({}, props), { overrideKey: key, walletData: wallet }));
|
|
31
43
|
this.name = name;
|
|
@@ -9,6 +9,7 @@ var bitcoinjsLib = require('bitcoinjs-lib');
|
|
|
9
9
|
const convertNetworkTypeForPsbt = (network) => ({
|
|
10
10
|
[satsConnect.BitcoinNetworkType.Mainnet]: bitcoinjsLib.networks.bitcoin,
|
|
11
11
|
[satsConnect.BitcoinNetworkType.Testnet]: bitcoinjsLib.networks.testnet,
|
|
12
|
+
[satsConnect.BitcoinNetworkType.Signet]: undefined,
|
|
12
13
|
}[network]);
|
|
13
14
|
|
|
14
15
|
exports.convertNetworkTypeForPsbt = convertNetworkTypeForPsbt;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { BitcoinNetworkType } from 'sats-connect';
|
|
2
2
|
import { networks } from 'bitcoinjs-lib';
|
|
3
|
-
export declare const convertNetworkTypeForPsbt: (network: BitcoinNetworkType) => networks.Network;
|
|
3
|
+
export declare const convertNetworkTypeForPsbt: (network: BitcoinNetworkType) => networks.Network | undefined;
|
|
@@ -5,6 +5,7 @@ import { networks } from 'bitcoinjs-lib';
|
|
|
5
5
|
const convertNetworkTypeForPsbt = (network) => ({
|
|
6
6
|
[BitcoinNetworkType.Mainnet]: networks.bitcoin,
|
|
7
7
|
[BitcoinNetworkType.Testnet]: networks.testnet,
|
|
8
|
+
[BitcoinNetworkType.Signet]: undefined,
|
|
8
9
|
}[network]);
|
|
9
10
|
|
|
10
11
|
export { convertNetworkTypeForPsbt };
|
|
@@ -3,9 +3,10 @@
|
|
|
3
3
|
|
|
4
4
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
5
5
|
|
|
6
|
+
var walletConnectorCore = require('@dynamic-labs/wallet-connector-core');
|
|
6
7
|
var validatePsbt = require('./validator/validatePsbt.cjs');
|
|
8
|
+
var getSigHashType = require('./getSigHashType.cjs');
|
|
7
9
|
require('bitcoinjs-lib');
|
|
8
|
-
require('@dynamic-labs/wallet-connector-core');
|
|
9
10
|
require('sats-connect');
|
|
10
11
|
|
|
11
12
|
const createPsbtOptions = (psbt, request) => {
|
|
@@ -32,5 +33,25 @@ const createPsbtOptions = (psbt, request) => {
|
|
|
32
33
|
}
|
|
33
34
|
return psbtSignOptions;
|
|
34
35
|
};
|
|
36
|
+
const createSignPsbtOptionsForSatsConnect = (psbtFromBase64, request, isLegacyConnector = false) => {
|
|
37
|
+
var _a, _b, _c;
|
|
38
|
+
if ((_a = request.signature) === null || _a === void 0 ? void 0 : _a.length) {
|
|
39
|
+
validatePsbt.validatePsbt(psbtFromBase64, request.allowedSighash, request.signature);
|
|
40
|
+
}
|
|
41
|
+
walletConnectorCore.logger.logVerboseTroubleshootingMessage('createSignPsbtOptionsForSatsConnect', { isLegacyConnector, psbtFromBase64, request });
|
|
42
|
+
const inputsToSign = ((_c = (_b = request.signature) === null || _b === void 0 ? void 0 : _b.map((sig) => {
|
|
43
|
+
var _a;
|
|
44
|
+
return ((_a = sig.signingIndexes) !== null && _a !== void 0 ? _a : []).map((inputIndex) => ({
|
|
45
|
+
address: sig.address,
|
|
46
|
+
sigHash: isLegacyConnector
|
|
47
|
+
? getSigHashType.getSigHashType(psbtFromBase64.data.inputs[inputIndex])
|
|
48
|
+
: request.allowedSighash[0],
|
|
49
|
+
signingIndexes: [inputIndex],
|
|
50
|
+
}));
|
|
51
|
+
})) !== null && _c !== void 0 ? _c : []).flat();
|
|
52
|
+
walletConnectorCore.logger.logVerboseTroubleshootingMessage('createSignPsbtOptionsForSatsConnect', { inputsToSign });
|
|
53
|
+
return inputsToSign;
|
|
54
|
+
};
|
|
35
55
|
|
|
36
56
|
exports.createPsbtOptions = createPsbtOptions;
|
|
57
|
+
exports.createSignPsbtOptionsForSatsConnect = createSignPsbtOptionsForSatsConnect;
|
|
@@ -1,3 +1,5 @@
|
|
|
1
1
|
import { Psbt } from 'bitcoinjs-lib';
|
|
2
|
+
import { InputToSign } from 'sats-connect';
|
|
2
3
|
import { BitcoinSignPsbtRequest, SignPsbtOptions } from '../../types';
|
|
3
4
|
export declare const createPsbtOptions: (psbt: Psbt, request: BitcoinSignPsbtRequest) => SignPsbtOptions;
|
|
5
|
+
export declare const createSignPsbtOptionsForSatsConnect: (psbtFromBase64: Psbt, request: BitcoinSignPsbtRequest, isLegacyConnector?: boolean) => InputToSign[];
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
'use client'
|
|
2
|
+
import { logger } from '@dynamic-labs/wallet-connector-core';
|
|
2
3
|
import { validatePsbt } from './validator/validatePsbt.js';
|
|
4
|
+
import { getSigHashType } from './getSigHashType.js';
|
|
3
5
|
import 'bitcoinjs-lib';
|
|
4
|
-
import '@dynamic-labs/wallet-connector-core';
|
|
5
6
|
import 'sats-connect';
|
|
6
7
|
|
|
7
8
|
const createPsbtOptions = (psbt, request) => {
|
|
@@ -28,5 +29,24 @@ const createPsbtOptions = (psbt, request) => {
|
|
|
28
29
|
}
|
|
29
30
|
return psbtSignOptions;
|
|
30
31
|
};
|
|
32
|
+
const createSignPsbtOptionsForSatsConnect = (psbtFromBase64, request, isLegacyConnector = false) => {
|
|
33
|
+
var _a, _b, _c;
|
|
34
|
+
if ((_a = request.signature) === null || _a === void 0 ? void 0 : _a.length) {
|
|
35
|
+
validatePsbt(psbtFromBase64, request.allowedSighash, request.signature);
|
|
36
|
+
}
|
|
37
|
+
logger.logVerboseTroubleshootingMessage('createSignPsbtOptionsForSatsConnect', { isLegacyConnector, psbtFromBase64, request });
|
|
38
|
+
const inputsToSign = ((_c = (_b = request.signature) === null || _b === void 0 ? void 0 : _b.map((sig) => {
|
|
39
|
+
var _a;
|
|
40
|
+
return ((_a = sig.signingIndexes) !== null && _a !== void 0 ? _a : []).map((inputIndex) => ({
|
|
41
|
+
address: sig.address,
|
|
42
|
+
sigHash: isLegacyConnector
|
|
43
|
+
? getSigHashType(psbtFromBase64.data.inputs[inputIndex])
|
|
44
|
+
: request.allowedSighash[0],
|
|
45
|
+
signingIndexes: [inputIndex],
|
|
46
|
+
}));
|
|
47
|
+
})) !== null && _c !== void 0 ? _c : []).flat();
|
|
48
|
+
logger.logVerboseTroubleshootingMessage('createSignPsbtOptionsForSatsConnect', { inputsToSign });
|
|
49
|
+
return inputsToSign;
|
|
50
|
+
};
|
|
31
51
|
|
|
32
|
-
export { createPsbtOptions };
|
|
52
|
+
export { createPsbtOptions, createSignPsbtOptionsForSatsConnect };
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
5
|
+
|
|
6
|
+
var _tslib = require('../../_virtual/_tslib.cjs');
|
|
7
|
+
var walletConnectorCore = require('@dynamic-labs/wallet-connector-core');
|
|
8
|
+
|
|
9
|
+
class BitcoinWallet extends walletConnectorCore.Wallet {
|
|
10
|
+
/**
|
|
11
|
+
* Sends a raw transaction
|
|
12
|
+
* @returns A promise that resolves to the transaction id
|
|
13
|
+
*/
|
|
14
|
+
sendRawTransaction(rawTransaction) {
|
|
15
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
16
|
+
yield this.sync();
|
|
17
|
+
return this._connector.sendRawTransaction(rawTransaction);
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Sends satoshis to a bitcoin address
|
|
22
|
+
* @returns A promise that resolves to the transaction id
|
|
23
|
+
*/
|
|
24
|
+
sendBitcoin(transaction) {
|
|
25
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
26
|
+
yield this.sync();
|
|
27
|
+
return this._connector.sendBitcoin(transaction);
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Signs a message using a specific address type (payment or ordinals).
|
|
32
|
+
* @param messageToSign - The message to sign.
|
|
33
|
+
* @param addressType - The type of address to sign the message with (payment or ordinals).
|
|
34
|
+
* @returns A promise that resolves to the signature of the message as a string,
|
|
35
|
+
* or undefined if the message cannot be signed.
|
|
36
|
+
*/
|
|
37
|
+
signMessageWithAddress(messageToSign, addressType) {
|
|
38
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
39
|
+
var _a;
|
|
40
|
+
yield this.sync();
|
|
41
|
+
const address = ((_a = this.additionalAddresses.find((addr) => addr.type === addressType)) === null || _a === void 0 ? void 0 : _a.address) || this.address;
|
|
42
|
+
return this._connector.signMessage(messageToSign, address);
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Sings a PSBT
|
|
47
|
+
* @returns A promise that resolves to an object with the signed PSBT
|
|
48
|
+
* or undefined if no provider is available
|
|
49
|
+
*/
|
|
50
|
+
signPsbt(request) {
|
|
51
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
52
|
+
yield this.sync();
|
|
53
|
+
return this._connector.signPsbt(request);
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Sings multiple PSBTs
|
|
58
|
+
* @returns A promise that resolves to an array of signed PSBTs in base64
|
|
59
|
+
* or undefined if no provider is available
|
|
60
|
+
*/
|
|
61
|
+
signPsbts(requests) {
|
|
62
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
63
|
+
yield this.sync();
|
|
64
|
+
return this._connector.signPsbts(requests);
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
exports.BitcoinWallet = BitcoinWallet;
|