@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,5 @@
|
|
|
1
|
+
export * from './fetchBtcKitConnectors';
|
|
2
|
+
export * from './fetchSatsConnectConnectors';
|
|
3
|
+
export { hasSatsConnectFeature } from './hasSatsConnectFeature';
|
|
4
|
+
export { supportsSatsConnect } from './supportsSatsConnect';
|
|
5
|
+
export { getMempoolApiUrl } from './getMempoolApiUrl';
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
5
|
+
|
|
6
|
+
var satsConnect = require('sats-connect');
|
|
7
|
+
var bitcoinjsLib = require('bitcoinjs-lib');
|
|
8
|
+
|
|
9
|
+
const convertNetworkTypeForPsbt = (network) => ({
|
|
10
|
+
[satsConnect.BitcoinNetworkType.Mainnet]: bitcoinjsLib.networks.bitcoin,
|
|
11
|
+
[satsConnect.BitcoinNetworkType.Testnet]: bitcoinjsLib.networks.testnet,
|
|
12
|
+
}[network]);
|
|
13
|
+
|
|
14
|
+
exports.convertNetworkTypeForPsbt = convertNetworkTypeForPsbt;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
import { BitcoinNetworkType } from 'sats-connect';
|
|
3
|
+
import { networks } from 'bitcoinjs-lib';
|
|
4
|
+
|
|
5
|
+
const convertNetworkTypeForPsbt = (network) => ({
|
|
6
|
+
[BitcoinNetworkType.Mainnet]: networks.bitcoin,
|
|
7
|
+
[BitcoinNetworkType.Testnet]: networks.testnet,
|
|
8
|
+
}[network]);
|
|
9
|
+
|
|
10
|
+
export { convertNetworkTypeForPsbt };
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
5
|
+
|
|
6
|
+
var validatePsbt = require('./validator/validatePsbt.cjs');
|
|
7
|
+
require('bitcoinjs-lib');
|
|
8
|
+
require('@dynamic-labs/wallet-connector-core');
|
|
9
|
+
require('sats-connect');
|
|
10
|
+
|
|
11
|
+
const createPsbtOptions = (psbt, request) => {
|
|
12
|
+
var _a;
|
|
13
|
+
const psbtSignOptions = {
|
|
14
|
+
autoFinalized: false,
|
|
15
|
+
};
|
|
16
|
+
if (request.signature) {
|
|
17
|
+
validatePsbt.validatePsbt(psbt, request.allowedSighash, request.signature);
|
|
18
|
+
const toSignInputs = [];
|
|
19
|
+
for (const signature of request.signature) {
|
|
20
|
+
if ((_a = signature.signingIndexes) === null || _a === void 0 ? void 0 : _a.length) {
|
|
21
|
+
for (const index of signature.signingIndexes) {
|
|
22
|
+
toSignInputs.push({
|
|
23
|
+
address: signature.address,
|
|
24
|
+
disableAddressValidation: signature.disableAddressValidation,
|
|
25
|
+
index,
|
|
26
|
+
sighashTypes: request.allowedSighash,
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
psbtSignOptions.toSignInputs = toSignInputs;
|
|
32
|
+
}
|
|
33
|
+
return psbtSignOptions;
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
exports.createPsbtOptions = createPsbtOptions;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
import { validatePsbt } from './validator/validatePsbt.js';
|
|
3
|
+
import 'bitcoinjs-lib';
|
|
4
|
+
import '@dynamic-labs/wallet-connector-core';
|
|
5
|
+
import 'sats-connect';
|
|
6
|
+
|
|
7
|
+
const createPsbtOptions = (psbt, request) => {
|
|
8
|
+
var _a;
|
|
9
|
+
const psbtSignOptions = {
|
|
10
|
+
autoFinalized: false,
|
|
11
|
+
};
|
|
12
|
+
if (request.signature) {
|
|
13
|
+
validatePsbt(psbt, request.allowedSighash, request.signature);
|
|
14
|
+
const toSignInputs = [];
|
|
15
|
+
for (const signature of request.signature) {
|
|
16
|
+
if ((_a = signature.signingIndexes) === null || _a === void 0 ? void 0 : _a.length) {
|
|
17
|
+
for (const index of signature.signingIndexes) {
|
|
18
|
+
toSignInputs.push({
|
|
19
|
+
address: signature.address,
|
|
20
|
+
disableAddressValidation: signature.disableAddressValidation,
|
|
21
|
+
index,
|
|
22
|
+
sighashTypes: request.allowedSighash,
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
psbtSignOptions.toSignInputs = toSignInputs;
|
|
28
|
+
}
|
|
29
|
+
return psbtSignOptions;
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
export { createPsbtOptions };
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
5
|
+
|
|
6
|
+
var bitcoinjsLib = require('bitcoinjs-lib');
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* This method extracts the address from the input data of the psbt.
|
|
10
|
+
* The address is stored as script (Buffer) in either the witnessUtxo or nonWitnessUtxo as an output
|
|
11
|
+
*/
|
|
12
|
+
const extractAddressFromInput = (psbt, index, input) => {
|
|
13
|
+
var _a;
|
|
14
|
+
let script;
|
|
15
|
+
if ((_a = input.witnessUtxo) === null || _a === void 0 ? void 0 : _a.script) {
|
|
16
|
+
// eslint-disable-next-line prefer-destructuring
|
|
17
|
+
script = input.witnessUtxo.script;
|
|
18
|
+
}
|
|
19
|
+
else if (input.nonWitnessUtxo) {
|
|
20
|
+
const nonWitnessTxn = bitcoinjsLib.Transaction.fromBuffer(input.nonWitnessUtxo);
|
|
21
|
+
const txOut = nonWitnessTxn.outs[psbt.txInputs[index].index];
|
|
22
|
+
// eslint-disable-next-line prefer-destructuring
|
|
23
|
+
script = txOut.script;
|
|
24
|
+
}
|
|
25
|
+
if (!script)
|
|
26
|
+
return;
|
|
27
|
+
try {
|
|
28
|
+
return bitcoinjsLib.address.fromOutputScript(script);
|
|
29
|
+
}
|
|
30
|
+
catch (e) {
|
|
31
|
+
throw new Error('address not found in output script');
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
exports.extractAddressFromInput = extractAddressFromInput;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { Psbt } from 'bitcoinjs-lib';
|
|
2
|
+
/**
|
|
3
|
+
* This method extracts the address from the input data of the psbt.
|
|
4
|
+
* The address is stored as script (Buffer) in either the witnessUtxo or nonWitnessUtxo as an output
|
|
5
|
+
*/
|
|
6
|
+
export declare const extractAddressFromInput: (psbt: Psbt, index: number, input: Psbt['data']['inputs'][0]) => string | undefined;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
import { Transaction, address } from 'bitcoinjs-lib';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* This method extracts the address from the input data of the psbt.
|
|
6
|
+
* The address is stored as script (Buffer) in either the witnessUtxo or nonWitnessUtxo as an output
|
|
7
|
+
*/
|
|
8
|
+
const extractAddressFromInput = (psbt, index, input) => {
|
|
9
|
+
var _a;
|
|
10
|
+
let script;
|
|
11
|
+
if ((_a = input.witnessUtxo) === null || _a === void 0 ? void 0 : _a.script) {
|
|
12
|
+
// eslint-disable-next-line prefer-destructuring
|
|
13
|
+
script = input.witnessUtxo.script;
|
|
14
|
+
}
|
|
15
|
+
else if (input.nonWitnessUtxo) {
|
|
16
|
+
const nonWitnessTxn = Transaction.fromBuffer(input.nonWitnessUtxo);
|
|
17
|
+
const txOut = nonWitnessTxn.outs[psbt.txInputs[index].index];
|
|
18
|
+
// eslint-disable-next-line prefer-destructuring
|
|
19
|
+
script = txOut.script;
|
|
20
|
+
}
|
|
21
|
+
if (!script)
|
|
22
|
+
return;
|
|
23
|
+
try {
|
|
24
|
+
return address.fromOutputScript(script);
|
|
25
|
+
}
|
|
26
|
+
catch (e) {
|
|
27
|
+
throw new Error('address not found in output script');
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
export { extractAddressFromInput };
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
5
|
+
|
|
6
|
+
var bitcoinjsLib = require('bitcoinjs-lib');
|
|
7
|
+
var walletConnectorCore = require('@dynamic-labs/wallet-connector-core');
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* This method will return the signature hash type for the current input.
|
|
11
|
+
* If there is a sighashType, it will return that
|
|
12
|
+
* If there is a witnessUtxo AND it is a taproot address, then it will return SIGHASH_DEFAULT
|
|
13
|
+
* Otherwise, it will return SIGHASH_ALL
|
|
14
|
+
*/
|
|
15
|
+
const getSigHashType = (input) => {
|
|
16
|
+
var _a;
|
|
17
|
+
if (input === null || input === void 0 ? void 0 : input.sighashType)
|
|
18
|
+
return input.sighashType;
|
|
19
|
+
let isTaprootAddress = false;
|
|
20
|
+
if ((_a = input.witnessUtxo) === null || _a === void 0 ? void 0 : _a.script) {
|
|
21
|
+
try {
|
|
22
|
+
bitcoinjsLib.payments.p2tr({
|
|
23
|
+
output: input.witnessUtxo.script,
|
|
24
|
+
});
|
|
25
|
+
isTaprootAddress = true;
|
|
26
|
+
}
|
|
27
|
+
catch (_) {
|
|
28
|
+
walletConnectorCore.logger.debug('address is not taproot');
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
return isTaprootAddress
|
|
32
|
+
? bitcoinjsLib.Transaction.SIGHASH_DEFAULT
|
|
33
|
+
: bitcoinjsLib.Transaction.SIGHASH_ALL;
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
exports.getSigHashType = getSigHashType;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { Psbt } from 'bitcoinjs-lib';
|
|
2
|
+
/**
|
|
3
|
+
* This method will return the signature hash type for the current input.
|
|
4
|
+
* If there is a sighashType, it will return that
|
|
5
|
+
* If there is a witnessUtxo AND it is a taproot address, then it will return SIGHASH_DEFAULT
|
|
6
|
+
* Otherwise, it will return SIGHASH_ALL
|
|
7
|
+
*/
|
|
8
|
+
export declare const getSigHashType: (input: Psbt['data']['inputs'][0]) => number;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
import { payments, Transaction } from 'bitcoinjs-lib';
|
|
3
|
+
import { logger } from '@dynamic-labs/wallet-connector-core';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* This method will return the signature hash type for the current input.
|
|
7
|
+
* If there is a sighashType, it will return that
|
|
8
|
+
* If there is a witnessUtxo AND it is a taproot address, then it will return SIGHASH_DEFAULT
|
|
9
|
+
* Otherwise, it will return SIGHASH_ALL
|
|
10
|
+
*/
|
|
11
|
+
const getSigHashType = (input) => {
|
|
12
|
+
var _a;
|
|
13
|
+
if (input === null || input === void 0 ? void 0 : input.sighashType)
|
|
14
|
+
return input.sighashType;
|
|
15
|
+
let isTaprootAddress = false;
|
|
16
|
+
if ((_a = input.witnessUtxo) === null || _a === void 0 ? void 0 : _a.script) {
|
|
17
|
+
try {
|
|
18
|
+
payments.p2tr({
|
|
19
|
+
output: input.witnessUtxo.script,
|
|
20
|
+
});
|
|
21
|
+
isTaprootAddress = true;
|
|
22
|
+
}
|
|
23
|
+
catch (_) {
|
|
24
|
+
logger.debug('address is not taproot');
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
return isTaprootAddress
|
|
28
|
+
? Transaction.SIGHASH_DEFAULT
|
|
29
|
+
: Transaction.SIGHASH_ALL;
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
export { getSigHashType };
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { validatePsbt } from './validator/validatePsbt';
|
|
2
|
+
export { getSigHashType } from './getSigHashType';
|
|
3
|
+
export { extractAddressFromInput } from './extractAddressFromInput';
|
|
4
|
+
export { convertNetworkTypeForPsbt } from './bitcoinNetworkTypeToNetworks';
|
|
5
|
+
export { sighashNumberToString } from './sighashNumberToString';
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
5
|
+
|
|
6
|
+
var bitcoinjsLib = require('bitcoinjs-lib');
|
|
7
|
+
|
|
8
|
+
const sighashNumberToString = (sighashType) => {
|
|
9
|
+
switch (sighashType) {
|
|
10
|
+
case bitcoinjsLib.Transaction.SIGHASH_ALL:
|
|
11
|
+
return 'ALL';
|
|
12
|
+
case bitcoinjsLib.Transaction.SIGHASH_NONE:
|
|
13
|
+
return 'NONE';
|
|
14
|
+
case bitcoinjsLib.Transaction.SIGHASH_SINGLE:
|
|
15
|
+
return 'SINGLE';
|
|
16
|
+
case bitcoinjsLib.Transaction.SIGHASH_ALL + bitcoinjsLib.Transaction.SIGHASH_ANYONECANPAY:
|
|
17
|
+
return 'ALL|ANYONECANPAY';
|
|
18
|
+
case bitcoinjsLib.Transaction.SIGHASH_NONE + bitcoinjsLib.Transaction.SIGHASH_ANYONECANPAY:
|
|
19
|
+
return 'NONE|ANYONECANPAY';
|
|
20
|
+
case bitcoinjsLib.Transaction.SIGHASH_SINGLE + bitcoinjsLib.Transaction.SIGHASH_ANYONECANPAY:
|
|
21
|
+
return 'SINGLE|ANYONECANPAY';
|
|
22
|
+
default:
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
exports.sighashNumberToString = sighashNumberToString;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
import { Transaction } from 'bitcoinjs-lib';
|
|
3
|
+
|
|
4
|
+
const sighashNumberToString = (sighashType) => {
|
|
5
|
+
switch (sighashType) {
|
|
6
|
+
case Transaction.SIGHASH_ALL:
|
|
7
|
+
return 'ALL';
|
|
8
|
+
case Transaction.SIGHASH_NONE:
|
|
9
|
+
return 'NONE';
|
|
10
|
+
case Transaction.SIGHASH_SINGLE:
|
|
11
|
+
return 'SINGLE';
|
|
12
|
+
case Transaction.SIGHASH_ALL + Transaction.SIGHASH_ANYONECANPAY:
|
|
13
|
+
return 'ALL|ANYONECANPAY';
|
|
14
|
+
case Transaction.SIGHASH_NONE + Transaction.SIGHASH_ANYONECANPAY:
|
|
15
|
+
return 'NONE|ANYONECANPAY';
|
|
16
|
+
case Transaction.SIGHASH_SINGLE + Transaction.SIGHASH_ANYONECANPAY:
|
|
17
|
+
return 'SINGLE|ANYONECANPAY';
|
|
18
|
+
default:
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
export { sighashNumberToString };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { validatePsbt } from './validatePsbt';
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
5
|
+
|
|
6
|
+
var utils = require('@dynamic-labs/utils');
|
|
7
|
+
var extractAddressFromInput = require('../extractAddressFromInput.cjs');
|
|
8
|
+
|
|
9
|
+
const validateAddress = (psbt, signingAddress, index, inputAtIndex) => {
|
|
10
|
+
// we need to extract the address from the input at the current signing index
|
|
11
|
+
// to be able to compare it to the address provided in the request for the current index
|
|
12
|
+
const extractedAddress = extractAddressFromInput.extractAddressFromInput(psbt, index, inputAtIndex);
|
|
13
|
+
if (!extractedAddress)
|
|
14
|
+
throw new utils.DynamicError(`validateAddress - input not found for the given address: ${signingAddress}`);
|
|
15
|
+
if (extractedAddress !== signingAddress)
|
|
16
|
+
throw new utils.DynamicError('validateAddress - address mismatch with index');
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
exports.validateAddress = validateAddress;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
import { DynamicError } from '@dynamic-labs/utils';
|
|
3
|
+
import { extractAddressFromInput } from '../extractAddressFromInput.js';
|
|
4
|
+
|
|
5
|
+
const validateAddress = (psbt, signingAddress, index, inputAtIndex) => {
|
|
6
|
+
// we need to extract the address from the input at the current signing index
|
|
7
|
+
// to be able to compare it to the address provided in the request for the current index
|
|
8
|
+
const extractedAddress = extractAddressFromInput(psbt, index, inputAtIndex);
|
|
9
|
+
if (!extractedAddress)
|
|
10
|
+
throw new DynamicError(`validateAddress - input not found for the given address: ${signingAddress}`);
|
|
11
|
+
if (extractedAddress !== signingAddress)
|
|
12
|
+
throw new DynamicError('validateAddress - address mismatch with index');
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
export { validateAddress };
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
5
|
+
|
|
6
|
+
var validateAddress = require('./validateAddress.cjs');
|
|
7
|
+
var validateSigHash = require('./validateSigHash.cjs');
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* This method will validate the psbt against the signature data provided in the request
|
|
11
|
+
* It checks 3 things:
|
|
12
|
+
* - That the signing index exists in the input
|
|
13
|
+
* - That the address provided in the request matches the address in the input,
|
|
14
|
+
* unless the disableAddressValidation flag is set
|
|
15
|
+
* - That the sigHashType of the input is a member of the allowedSigHashTypes array
|
|
16
|
+
*/
|
|
17
|
+
const validatePsbt = (psbt, allowedSigHashTypes, signatureData) => {
|
|
18
|
+
if (!(signatureData === null || signatureData === void 0 ? void 0 : signatureData.length))
|
|
19
|
+
return;
|
|
20
|
+
for (const input of signatureData) {
|
|
21
|
+
const { address: signingAddress, signingIndexes,
|
|
22
|
+
// request from ME in cases of multi-sig. Steven wanted this defaulted to true
|
|
23
|
+
disableAddressValidation = true, } = input;
|
|
24
|
+
if (!(signingIndexes === null || signingIndexes === void 0 ? void 0 : signingIndexes.length))
|
|
25
|
+
return;
|
|
26
|
+
// address is a required input
|
|
27
|
+
if (!signingAddress)
|
|
28
|
+
throw new Error('validatePsbt - address not provided');
|
|
29
|
+
for (const index of signingIndexes) {
|
|
30
|
+
const selectedInput = psbt.data.inputs[index];
|
|
31
|
+
if (!selectedInput)
|
|
32
|
+
throw new Error('validatePsbt - requested input not found');
|
|
33
|
+
if (!disableAddressValidation) {
|
|
34
|
+
validateAddress.validateAddress(psbt, signingAddress, index, selectedInput);
|
|
35
|
+
}
|
|
36
|
+
validateSigHash.validateSigHash(allowedSigHashTypes, selectedInput);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
exports.validatePsbt = validatePsbt;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Psbt } from 'bitcoinjs-lib';
|
|
2
|
+
import { BitcoinSignPsbtRequestSignature } from '../../../types';
|
|
3
|
+
/**
|
|
4
|
+
* This method will validate the psbt against the signature data provided in the request
|
|
5
|
+
* It checks 3 things:
|
|
6
|
+
* - That the signing index exists in the input
|
|
7
|
+
* - That the address provided in the request matches the address in the input,
|
|
8
|
+
* unless the disableAddressValidation flag is set
|
|
9
|
+
* - That the sigHashType of the input is a member of the allowedSigHashTypes array
|
|
10
|
+
*/
|
|
11
|
+
export declare const validatePsbt: (psbt: Psbt, allowedSigHashTypes: number[], signatureData?: BitcoinSignPsbtRequestSignature[]) => void;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
import { validateAddress } from './validateAddress.js';
|
|
3
|
+
import { validateSigHash } from './validateSigHash.js';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* This method will validate the psbt against the signature data provided in the request
|
|
7
|
+
* It checks 3 things:
|
|
8
|
+
* - That the signing index exists in the input
|
|
9
|
+
* - That the address provided in the request matches the address in the input,
|
|
10
|
+
* unless the disableAddressValidation flag is set
|
|
11
|
+
* - That the sigHashType of the input is a member of the allowedSigHashTypes array
|
|
12
|
+
*/
|
|
13
|
+
const validatePsbt = (psbt, allowedSigHashTypes, signatureData) => {
|
|
14
|
+
if (!(signatureData === null || signatureData === void 0 ? void 0 : signatureData.length))
|
|
15
|
+
return;
|
|
16
|
+
for (const input of signatureData) {
|
|
17
|
+
const { address: signingAddress, signingIndexes,
|
|
18
|
+
// request from ME in cases of multi-sig. Steven wanted this defaulted to true
|
|
19
|
+
disableAddressValidation = true, } = input;
|
|
20
|
+
if (!(signingIndexes === null || signingIndexes === void 0 ? void 0 : signingIndexes.length))
|
|
21
|
+
return;
|
|
22
|
+
// address is a required input
|
|
23
|
+
if (!signingAddress)
|
|
24
|
+
throw new Error('validatePsbt - address not provided');
|
|
25
|
+
for (const index of signingIndexes) {
|
|
26
|
+
const selectedInput = psbt.data.inputs[index];
|
|
27
|
+
if (!selectedInput)
|
|
28
|
+
throw new Error('validatePsbt - requested input not found');
|
|
29
|
+
if (!disableAddressValidation) {
|
|
30
|
+
validateAddress(psbt, signingAddress, index, selectedInput);
|
|
31
|
+
}
|
|
32
|
+
validateSigHash(allowedSigHashTypes, selectedInput);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
export { validatePsbt };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
5
|
+
|
|
6
|
+
var getSigHashType = require('../getSigHashType.cjs');
|
|
7
|
+
|
|
8
|
+
const validateSigHash = (allowedSigHashTypes, selectedInput) => {
|
|
9
|
+
const sigHashType = getSigHashType.getSigHashType(selectedInput);
|
|
10
|
+
// if the request has allowedSigHashTypes, then we need to make sure that the sigHashType
|
|
11
|
+
// is a member of that array before continuing
|
|
12
|
+
if ((allowedSigHashTypes === null || allowedSigHashTypes === void 0 ? void 0 : allowedSigHashTypes.length) && !allowedSigHashTypes.includes(sigHashType))
|
|
13
|
+
throw new Error(`validatePsbt - sigHashType ${sigHashType} not in allowed list`);
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
exports.validateSigHash = validateSigHash;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
import { getSigHashType } from '../getSigHashType.js';
|
|
3
|
+
|
|
4
|
+
const validateSigHash = (allowedSigHashTypes, selectedInput) => {
|
|
5
|
+
const sigHashType = getSigHashType(selectedInput);
|
|
6
|
+
// if the request has allowedSigHashTypes, then we need to make sure that the sigHashType
|
|
7
|
+
// is a member of that array before continuing
|
|
8
|
+
if ((allowedSigHashTypes === null || allowedSigHashTypes === void 0 ? void 0 : allowedSigHashTypes.length) && !allowedSigHashTypes.includes(sigHashType))
|
|
9
|
+
throw new Error(`validatePsbt - sigHashType ${sigHashType} not in allowed list`);
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
export { validateSigHash };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './satoshisToBtc';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const satoshisToBtc: (satoshis: number) => number;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
5
|
+
|
|
6
|
+
var _const = require('../const.cjs');
|
|
7
|
+
require('@dynamic-labs/utils');
|
|
8
|
+
require('../../_virtual/_tslib.cjs');
|
|
9
|
+
require('sats-connect');
|
|
10
|
+
require('bitcoinjs-lib');
|
|
11
|
+
require('@dynamic-labs/wallet-connector-core');
|
|
12
|
+
require('@dynamic-labs/wallet-book');
|
|
13
|
+
require('@dynamic-labs/sdk-api-core');
|
|
14
|
+
require('@wallet-standard/app');
|
|
15
|
+
var hasSatsConnectFeature = require('./hasSatsConnectFeature.cjs');
|
|
16
|
+
|
|
17
|
+
const supportsSatsConnect = (connector) => {
|
|
18
|
+
if (connector.key === _const.XVERSE_KEY) {
|
|
19
|
+
return true;
|
|
20
|
+
}
|
|
21
|
+
if (connector.wallet && hasSatsConnectFeature.hasSatsConnectFeature(connector.wallet.features)) {
|
|
22
|
+
return true;
|
|
23
|
+
}
|
|
24
|
+
return false;
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
exports.supportsSatsConnect = supportsSatsConnect;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
import { XVERSE_KEY } from '../const.js';
|
|
3
|
+
import '@dynamic-labs/utils';
|
|
4
|
+
import '../../_virtual/_tslib.js';
|
|
5
|
+
import 'sats-connect';
|
|
6
|
+
import 'bitcoinjs-lib';
|
|
7
|
+
import '@dynamic-labs/wallet-connector-core';
|
|
8
|
+
import '@dynamic-labs/wallet-book';
|
|
9
|
+
import '@dynamic-labs/sdk-api-core';
|
|
10
|
+
import '@wallet-standard/app';
|
|
11
|
+
import { hasSatsConnectFeature } from './hasSatsConnectFeature.js';
|
|
12
|
+
|
|
13
|
+
const supportsSatsConnect = (connector) => {
|
|
14
|
+
if (connector.key === XVERSE_KEY) {
|
|
15
|
+
return true;
|
|
16
|
+
}
|
|
17
|
+
if (connector.wallet && hasSatsConnectFeature(connector.wallet.features)) {
|
|
18
|
+
return true;
|
|
19
|
+
}
|
|
20
|
+
return false;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
export { supportsSatsConnect };
|
|
@@ -0,0 +1,43 @@
|
|
|
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
|
+
|
|
43
|
+
exports.BitcoinWallet = BitcoinWallet;
|