@dynamic-labs/bitcoin 3.0.0-alpha.6 → 3.0.0-alpha.60
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 +585 -0
- package/package.json +5 -5
- package/src/BitcoinLocalStorageCache.cjs +0 -16
- package/src/BitcoinLocalStorageCache.d.ts +0 -7
- package/src/BitcoinLocalStorageCache.js +0 -16
- package/src/connectors/BitcoinSatsConnectConnector/BitcoinSatsConnectConnector.cjs +70 -23
- package/src/connectors/BitcoinSatsConnectConnector/BitcoinSatsConnectConnector.d.ts +4 -2
- package/src/connectors/BitcoinSatsConnectConnector/BitcoinSatsConnectConnector.js +71 -24
- package/src/connectors/BitcoinWalletConnector.cjs +64 -31
- package/src/connectors/BitcoinWalletConnector.d.ts +13 -5
- package/src/connectors/BitcoinWalletConnector.js +65 -32
- 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 +13 -9
- package/src/connectors/PhantomConnector/PhantomConnector.d.ts +1 -1
- package/src/connectors/PhantomConnector/PhantomConnector.js +13 -9
- package/src/connectors/UnisatConnector/UnisatConnector.cjs +26 -1
- package/src/connectors/UnisatConnector/UnisatConnector.d.ts +2 -1
- package/src/connectors/UnisatConnector/UnisatConnector.js +26 -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/index.cjs +4 -0
- package/src/index.d.ts +3 -2
- package/src/index.js +2 -0
- package/src/utils/fetchSatsConnectConnectors/fetchSatsConnectConnectors.cjs +1 -1
- package/src/utils/fetchSatsConnectConnectors/fetchSatsConnectConnectors.js +1 -1
- package/src/utils/psbt/createSignPsbtOptions.cjs +17 -1
- package/src/utils/psbt/createSignPsbtOptions.d.ts +2 -0
- package/src/utils/psbt/createSignPsbtOptions.js +17 -2
- package/src/wallet/BitcoinWallet.cjs +54 -0
- package/src/wallet/BitcoinWallet.d.ts +27 -0
- package/src/wallet/BitcoinWallet.js +50 -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
|
@@ -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) {
|
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),
|
|
@@ -5,12 +5,12 @@ 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
16
|
|
|
@@ -1,12 +1,12 @@
|
|
|
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
12
|
|
|
@@ -4,8 +4,8 @@
|
|
|
4
4
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
5
5
|
|
|
6
6
|
var validatePsbt = require('./validator/validatePsbt.cjs');
|
|
7
|
+
var getSigHashType = require('./getSigHashType.cjs');
|
|
7
8
|
require('bitcoinjs-lib');
|
|
8
|
-
require('@dynamic-labs/wallet-connector-core');
|
|
9
9
|
require('sats-connect');
|
|
10
10
|
|
|
11
11
|
const createPsbtOptions = (psbt, request) => {
|
|
@@ -32,5 +32,21 @@ const createPsbtOptions = (psbt, request) => {
|
|
|
32
32
|
}
|
|
33
33
|
return psbtSignOptions;
|
|
34
34
|
};
|
|
35
|
+
const createSignPsbtOptionsForSatsConnect = (psbtFromBase64, request) => {
|
|
36
|
+
var _a, _b, _c;
|
|
37
|
+
if ((_a = request.signature) === null || _a === void 0 ? void 0 : _a.length) {
|
|
38
|
+
validatePsbt.validatePsbt(psbtFromBase64, request.allowedSighash, request.signature);
|
|
39
|
+
}
|
|
40
|
+
const inputsToSign = ((_c = (_b = request.signature) === null || _b === void 0 ? void 0 : _b.map((sig) => {
|
|
41
|
+
var _a;
|
|
42
|
+
return ((_a = sig.signingIndexes) !== null && _a !== void 0 ? _a : []).map((inputIndex) => ({
|
|
43
|
+
address: sig.address,
|
|
44
|
+
sigHash: getSigHashType.getSigHashType(psbtFromBase64.data.inputs[inputIndex]),
|
|
45
|
+
signingIndexes: [inputIndex],
|
|
46
|
+
}));
|
|
47
|
+
})) !== null && _c !== void 0 ? _c : []).flat();
|
|
48
|
+
return inputsToSign;
|
|
49
|
+
};
|
|
35
50
|
|
|
36
51
|
exports.createPsbtOptions = createPsbtOptions;
|
|
52
|
+
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) => InputToSign[];
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use client'
|
|
2
2
|
import { validatePsbt } from './validator/validatePsbt.js';
|
|
3
|
+
import { getSigHashType } from './getSigHashType.js';
|
|
3
4
|
import 'bitcoinjs-lib';
|
|
4
|
-
import '@dynamic-labs/wallet-connector-core';
|
|
5
5
|
import 'sats-connect';
|
|
6
6
|
|
|
7
7
|
const createPsbtOptions = (psbt, request) => {
|
|
@@ -28,5 +28,20 @@ const createPsbtOptions = (psbt, request) => {
|
|
|
28
28
|
}
|
|
29
29
|
return psbtSignOptions;
|
|
30
30
|
};
|
|
31
|
+
const createSignPsbtOptionsForSatsConnect = (psbtFromBase64, request) => {
|
|
32
|
+
var _a, _b, _c;
|
|
33
|
+
if ((_a = request.signature) === null || _a === void 0 ? void 0 : _a.length) {
|
|
34
|
+
validatePsbt(psbtFromBase64, request.allowedSighash, request.signature);
|
|
35
|
+
}
|
|
36
|
+
const inputsToSign = ((_c = (_b = request.signature) === null || _b === void 0 ? void 0 : _b.map((sig) => {
|
|
37
|
+
var _a;
|
|
38
|
+
return ((_a = sig.signingIndexes) !== null && _a !== void 0 ? _a : []).map((inputIndex) => ({
|
|
39
|
+
address: sig.address,
|
|
40
|
+
sigHash: getSigHashType(psbtFromBase64.data.inputs[inputIndex]),
|
|
41
|
+
signingIndexes: [inputIndex],
|
|
42
|
+
}));
|
|
43
|
+
})) !== null && _c !== void 0 ? _c : []).flat();
|
|
44
|
+
return inputsToSign;
|
|
45
|
+
};
|
|
31
46
|
|
|
32
|
-
export { createPsbtOptions };
|
|
47
|
+
export { createPsbtOptions, createSignPsbtOptionsForSatsConnect };
|
|
@@ -0,0 +1,54 @@
|
|
|
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
|
+
* Sings a PSBT
|
|
32
|
+
* @returns A promise that resolves to an object with the signed PSBT
|
|
33
|
+
* or undefined if no provider is available
|
|
34
|
+
*/
|
|
35
|
+
signPsbt(request) {
|
|
36
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
37
|
+
yield this.sync();
|
|
38
|
+
return this._connector.signPsbt(request);
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Sings multiple PSBTs
|
|
43
|
+
* @returns A promise that resolves to an array of signed PSBTs in base64
|
|
44
|
+
* or undefined if no provider is available
|
|
45
|
+
*/
|
|
46
|
+
signPsbts(requests) {
|
|
47
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
48
|
+
yield this.sync();
|
|
49
|
+
return this._connector.signPsbts(requests);
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
exports.BitcoinWallet = BitcoinWallet;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { Wallet } from '@dynamic-labs/wallet-connector-core';
|
|
2
|
+
import { BitcoinWalletConnector } from '../connectors';
|
|
3
|
+
import { BitcoinSignPsbtRequest, BitcoinSignPsbtResponse, BitcoinTransaction } from '../types';
|
|
4
|
+
export declare class BitcoinWallet extends Wallet<BitcoinWalletConnector> {
|
|
5
|
+
/**
|
|
6
|
+
* Sends a raw transaction
|
|
7
|
+
* @returns A promise that resolves to the transaction id
|
|
8
|
+
*/
|
|
9
|
+
sendRawTransaction(rawTransaction: string): Promise<string>;
|
|
10
|
+
/**
|
|
11
|
+
* Sends satoshis to a bitcoin address
|
|
12
|
+
* @returns A promise that resolves to the transaction id
|
|
13
|
+
*/
|
|
14
|
+
sendBitcoin(transaction: BitcoinTransaction): Promise<string | undefined>;
|
|
15
|
+
/**
|
|
16
|
+
* Sings a PSBT
|
|
17
|
+
* @returns A promise that resolves to an object with the signed PSBT
|
|
18
|
+
* or undefined if no provider is available
|
|
19
|
+
*/
|
|
20
|
+
signPsbt(request: BitcoinSignPsbtRequest): Promise<BitcoinSignPsbtResponse | undefined>;
|
|
21
|
+
/**
|
|
22
|
+
* Sings multiple PSBTs
|
|
23
|
+
* @returns A promise that resolves to an array of signed PSBTs in base64
|
|
24
|
+
* or undefined if no provider is available
|
|
25
|
+
*/
|
|
26
|
+
signPsbts(requests: BitcoinSignPsbtRequest[]): Promise<string[] | undefined>;
|
|
27
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
import { __awaiter } from '../../_virtual/_tslib.js';
|
|
3
|
+
import { Wallet } from '@dynamic-labs/wallet-connector-core';
|
|
4
|
+
|
|
5
|
+
class BitcoinWallet extends Wallet {
|
|
6
|
+
/**
|
|
7
|
+
* Sends a raw transaction
|
|
8
|
+
* @returns A promise that resolves to the transaction id
|
|
9
|
+
*/
|
|
10
|
+
sendRawTransaction(rawTransaction) {
|
|
11
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
12
|
+
yield this.sync();
|
|
13
|
+
return this._connector.sendRawTransaction(rawTransaction);
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Sends satoshis to a bitcoin address
|
|
18
|
+
* @returns A promise that resolves to the transaction id
|
|
19
|
+
*/
|
|
20
|
+
sendBitcoin(transaction) {
|
|
21
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
22
|
+
yield this.sync();
|
|
23
|
+
return this._connector.sendBitcoin(transaction);
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Sings a PSBT
|
|
28
|
+
* @returns A promise that resolves to an object with the signed PSBT
|
|
29
|
+
* or undefined if no provider is available
|
|
30
|
+
*/
|
|
31
|
+
signPsbt(request) {
|
|
32
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
33
|
+
yield this.sync();
|
|
34
|
+
return this._connector.signPsbt(request);
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Sings multiple PSBTs
|
|
39
|
+
* @returns A promise that resolves to an array of signed PSBTs in base64
|
|
40
|
+
* or undefined if no provider is available
|
|
41
|
+
*/
|
|
42
|
+
signPsbts(requests) {
|
|
43
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
44
|
+
yield this.sync();
|
|
45
|
+
return this._connector.signPsbts(requests);
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export { BitcoinWallet };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './isBitcoinWallet';
|