@dynamic-labs/bitcoin 4.0.0-alpha.5 → 4.0.0-alpha.51

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.
Files changed (62) hide show
  1. package/CHANGELOG.md +468 -0
  2. package/package.cjs +8 -0
  3. package/package.js +4 -0
  4. package/package.json +9 -15
  5. package/src/connectors/BitcoinSatsConnectConnector/BitcoinSatsConnectConnector.cjs +70 -17
  6. package/src/connectors/BitcoinSatsConnectConnector/BitcoinSatsConnectConnector.d.ts +13 -2
  7. package/src/connectors/BitcoinSatsConnectConnector/BitcoinSatsConnectConnector.js +72 -19
  8. package/src/connectors/BitcoinWalletConnector.cjs +29 -6
  9. package/src/connectors/BitcoinWalletConnector.d.ts +8 -3
  10. package/src/connectors/BitcoinWalletConnector.js +31 -8
  11. package/src/connectors/{BitcoinSatsConnectLegacyConnector/BitcoinSatsConnectLegacyConnector.cjs → MagicEdenConnector/MagicEdenConnector.cjs} +26 -59
  12. package/src/connectors/MagicEdenConnector/MagicEdenConnector.d.ts +21 -0
  13. package/src/connectors/{BitcoinSatsConnectLegacyConnector/BitcoinSatsConnectLegacyConnector.js → MagicEdenConnector/MagicEdenConnector.js} +28 -61
  14. package/src/connectors/MagicEdenConnector/index.d.ts +1 -0
  15. package/src/connectors/OkxConnector/OkxConnector.cjs +15 -8
  16. package/src/connectors/OkxConnector/OkxConnector.d.ts +5 -3
  17. package/src/connectors/OkxConnector/OkxConnector.js +15 -8
  18. package/src/connectors/OneKeyConnector/OneKeyConnector.cjs +118 -0
  19. package/src/connectors/OneKeyConnector/OneKeyConnector.d.ts +15 -0
  20. package/src/connectors/OneKeyConnector/OneKeyConnector.js +114 -0
  21. package/src/connectors/OneKeyConnector/index.d.ts +1 -0
  22. package/src/connectors/OylConnector/OylConnector.cjs +71 -0
  23. package/src/connectors/OylConnector/OylConnector.d.ts +13 -0
  24. package/src/connectors/OylConnector/OylConnector.js +67 -0
  25. package/src/connectors/OylConnector/index.d.ts +1 -0
  26. package/src/connectors/PhantomConnector/PhantomConnector.cjs +5 -10
  27. package/src/connectors/PhantomConnector/PhantomConnector.d.ts +5 -3
  28. package/src/connectors/PhantomConnector/PhantomConnector.js +5 -10
  29. package/src/connectors/UnisatConnector/UnisatConnector.cjs +9 -2
  30. package/src/connectors/UnisatConnector/UnisatConnector.d.ts +5 -2
  31. package/src/connectors/UnisatConnector/UnisatConnector.js +9 -2
  32. package/src/connectors/index.d.ts +3 -2
  33. package/src/const.cjs +0 -2
  34. package/src/const.js +1 -2
  35. package/src/index.cjs +13 -9
  36. package/src/index.d.ts +3 -3
  37. package/src/index.js +13 -8
  38. package/src/types.d.ts +1 -0
  39. package/src/utils/fetchSatsConnectConnectors/fetchSatsConnectConnectors.cjs +7 -17
  40. package/src/utils/fetchSatsConnectConnectors/fetchSatsConnectConnectors.d.ts +1 -1
  41. package/src/utils/fetchSatsConnectConnectors/fetchSatsConnectConnectors.js +7 -17
  42. package/src/utils/getAddressByType/getAddressByType.cjs +11 -0
  43. package/src/utils/getAddressByType/getAddressByType.d.ts +3 -0
  44. package/src/utils/getAddressByType/getAddressByType.js +7 -0
  45. package/src/utils/getAddressByType/index.d.ts +1 -0
  46. package/src/utils/getSatsConnectSigningProtocol/getSatsConnectSigningProtocol.cjs +17 -0
  47. package/src/utils/getSatsConnectSigningProtocol/getSatsConnectSigningProtocol.d.ts +3 -0
  48. package/src/utils/getSatsConnectSigningProtocol/getSatsConnectSigningProtocol.js +13 -0
  49. package/src/utils/getSatsConnectSigningProtocol/index.d.ts +1 -0
  50. package/src/utils/index.d.ts +0 -1
  51. package/src/wallet/BitcoinWallet.cjs +26 -5
  52. package/src/wallet/BitcoinWallet.d.ts +18 -3
  53. package/src/wallet/BitcoinWallet.js +26 -5
  54. package/src/connectors/BitcoinSatsConnectLegacyConnector/BitcoinSatsConnectLegacyConnector.d.ts +0 -11
  55. package/src/connectors/BitcoinSatsConnectLegacyConnector/index.d.ts +0 -1
  56. package/src/connectors/UnknownInjected/UnknownInjected.cjs +0 -43
  57. package/src/connectors/UnknownInjected/UnknownInjected.d.ts +0 -11
  58. package/src/connectors/UnknownInjected/UnknownInjected.js +0 -39
  59. package/src/connectors/UnknownInjected/index.d.ts +0 -1
  60. package/src/utils/supportsSatsConnect.cjs +0 -32
  61. package/src/utils/supportsSatsConnect.d.ts +0 -2
  62. package/src/utils/supportsSatsConnect.js +0 -28
@@ -5,8 +5,23 @@ Object.defineProperty(exports, '__esModule', { value: true });
5
5
 
6
6
  var _tslib = require('../../_virtual/_tslib.cjs');
7
7
  var walletConnectorCore = require('@dynamic-labs/wallet-connector-core');
8
+ var getAddressByType = require('../utils/getAddressByType/getAddressByType.cjs');
8
9
 
9
10
  class BitcoinWallet extends walletConnectorCore.Wallet {
11
+ /**
12
+ * Sends the native balance of the wallet to the given address.
13
+ * @param amount - The amount of balance to send (in satoshis).
14
+ * @param toAddress - The address to send the balance to.
15
+ * @returns The signature of the sent transaction.
16
+ */
17
+ sendBalance(_a) {
18
+ return _tslib.__awaiter(this, arguments, void 0, function* ({ amount, toAddress, }) {
19
+ return this.sendBitcoin({
20
+ amount: BigInt(amount),
21
+ recipientAddress: toAddress,
22
+ });
23
+ });
24
+ }
10
25
  /**
11
26
  * Sends a raw transaction
12
27
  * @returns A promise that resolves to the transaction id
@@ -30,16 +45,22 @@ class BitcoinWallet extends walletConnectorCore.Wallet {
30
45
  /**
31
46
  * Signs a message using a specific address type (payment or ordinals).
32
47
  * @param messageToSign - The message to sign.
33
- * @param addressType - The type of address to sign the message with (payment or ordinals).
48
+ * @param options - Optional configuration for signing
49
+ * @param options.addressType - The type of address to sign with (e.g. 'payment' or 'ordinals')
50
+ * @param options.protocol - The signing protocol to use (e.g. 'ecdsa' or 'bip322-simple')
34
51
  * @returns A promise that resolves to the signature of the message as a string,
35
52
  * or undefined if the message cannot be signed.
36
53
  */
37
- signMessageWithAddress(messageToSign, addressType) {
54
+ signMessage(messageToSign, options) {
38
55
  return _tslib.__awaiter(this, void 0, void 0, function* () {
39
- var _a;
40
56
  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);
57
+ const address = (options === null || options === void 0 ? void 0 : options.addressType)
58
+ ? getAddressByType.getAddressByType(this, options.addressType)
59
+ : this.address;
60
+ return this._connector.signMessage(messageToSign, {
61
+ address,
62
+ protocol: options === null || options === void 0 ? void 0 : options.protocol,
63
+ });
43
64
  });
44
65
  }
45
66
  /**
@@ -1,8 +1,18 @@
1
1
  import { Wallet } from '@dynamic-labs/wallet-connector-core';
2
2
  import type { WalletAddressType } from '@dynamic-labs/types';
3
3
  import { BitcoinWalletConnector } from '../connectors';
4
- import { BitcoinSignPsbtRequest, BitcoinSignPsbtResponse, BitcoinTransaction } from '../types';
4
+ import { BitcoinSignProtocol, BitcoinSignPsbtRequest, BitcoinSignPsbtResponse, BitcoinTransaction } from '../types';
5
5
  export declare class BitcoinWallet extends Wallet<BitcoinWalletConnector> {
6
+ /**
7
+ * Sends the native balance of the wallet to the given address.
8
+ * @param amount - The amount of balance to send (in satoshis).
9
+ * @param toAddress - The address to send the balance to.
10
+ * @returns The signature of the sent transaction.
11
+ */
12
+ sendBalance({ amount, toAddress, }: {
13
+ amount: string;
14
+ toAddress: string;
15
+ }): Promise<string | undefined>;
6
16
  /**
7
17
  * Sends a raw transaction
8
18
  * @returns A promise that resolves to the transaction id
@@ -16,11 +26,16 @@ export declare class BitcoinWallet extends Wallet<BitcoinWalletConnector> {
16
26
  /**
17
27
  * Signs a message using a specific address type (payment or ordinals).
18
28
  * @param messageToSign - The message to sign.
19
- * @param addressType - The type of address to sign the message with (payment or ordinals).
29
+ * @param options - Optional configuration for signing
30
+ * @param options.addressType - The type of address to sign with (e.g. 'payment' or 'ordinals')
31
+ * @param options.protocol - The signing protocol to use (e.g. 'ecdsa' or 'bip322-simple')
20
32
  * @returns A promise that resolves to the signature of the message as a string,
21
33
  * or undefined if the message cannot be signed.
22
34
  */
23
- signMessageWithAddress(messageToSign: string, addressType: WalletAddressType): Promise<string | undefined>;
35
+ signMessage(messageToSign: string, options?: {
36
+ addressType?: WalletAddressType;
37
+ protocol?: BitcoinSignProtocol;
38
+ }): Promise<string | undefined>;
24
39
  /**
25
40
  * Sings a PSBT
26
41
  * @returns A promise that resolves to an object with the signed PSBT
@@ -1,8 +1,23 @@
1
1
  'use client'
2
2
  import { __awaiter } from '../../_virtual/_tslib.js';
3
3
  import { Wallet } from '@dynamic-labs/wallet-connector-core';
4
+ import { getAddressByType } from '../utils/getAddressByType/getAddressByType.js';
4
5
 
5
6
  class BitcoinWallet extends Wallet {
7
+ /**
8
+ * Sends the native balance of the wallet to the given address.
9
+ * @param amount - The amount of balance to send (in satoshis).
10
+ * @param toAddress - The address to send the balance to.
11
+ * @returns The signature of the sent transaction.
12
+ */
13
+ sendBalance(_a) {
14
+ return __awaiter(this, arguments, void 0, function* ({ amount, toAddress, }) {
15
+ return this.sendBitcoin({
16
+ amount: BigInt(amount),
17
+ recipientAddress: toAddress,
18
+ });
19
+ });
20
+ }
6
21
  /**
7
22
  * Sends a raw transaction
8
23
  * @returns A promise that resolves to the transaction id
@@ -26,16 +41,22 @@ class BitcoinWallet extends Wallet {
26
41
  /**
27
42
  * Signs a message using a specific address type (payment or ordinals).
28
43
  * @param messageToSign - The message to sign.
29
- * @param addressType - The type of address to sign the message with (payment or ordinals).
44
+ * @param options - Optional configuration for signing
45
+ * @param options.addressType - The type of address to sign with (e.g. 'payment' or 'ordinals')
46
+ * @param options.protocol - The signing protocol to use (e.g. 'ecdsa' or 'bip322-simple')
30
47
  * @returns A promise that resolves to the signature of the message as a string,
31
48
  * or undefined if the message cannot be signed.
32
49
  */
33
- signMessageWithAddress(messageToSign, addressType) {
50
+ signMessage(messageToSign, options) {
34
51
  return __awaiter(this, void 0, void 0, function* () {
35
- var _a;
36
52
  yield this.sync();
37
- const address = ((_a = this.additionalAddresses.find((addr) => addr.type === addressType)) === null || _a === void 0 ? void 0 : _a.address) || this.address;
38
- return this._connector.signMessage(messageToSign, address);
53
+ const address = (options === null || options === void 0 ? void 0 : options.addressType)
54
+ ? getAddressByType(this, options.addressType)
55
+ : this.address;
56
+ return this._connector.signMessage(messageToSign, {
57
+ address,
58
+ protocol: options === null || options === void 0 ? void 0 : options.protocol,
59
+ });
39
60
  });
40
61
  }
41
62
  /**
@@ -1,11 +0,0 @@
1
- import { SignMultipleTransactionsPayload, SignTransactionResponse } from 'sats-connect';
2
- import { BitcoinTransaction, SatsConnectSignTransactionInput } from '../../types';
3
- import { BitcoinSatsConnectConnector } from '../BitcoinSatsConnectConnector';
4
- export declare abstract class BitcoinSatsConnectLegacyConnector extends BitcoinSatsConnectConnector {
5
- isLegacy: boolean;
6
- getAddress(): Promise<string | undefined>;
7
- signMessage(messageToSign: string, withAddress: string): Promise<string | undefined>;
8
- sendBitcoin(transaction: BitcoinTransaction): Promise<string | undefined>;
9
- signTransaction(params: SatsConnectSignTransactionInput): Promise<SignTransactionResponse | undefined>;
10
- signTransactions(transactions: SignMultipleTransactionsPayload): Promise<SignTransactionResponse[] | undefined>;
11
- }
@@ -1 +0,0 @@
1
- export { BitcoinSatsConnectLegacyConnector } from './BitcoinSatsConnectLegacyConnector';
@@ -1,43 +0,0 @@
1
- 'use client'
2
- 'use strict';
3
-
4
- Object.defineProperty(exports, '__esModule', { value: true });
5
-
6
- var _tslib = require('../../../_virtual/_tslib.cjs');
7
- var BitcoinWalletConnector = require('../BitcoinWalletConnector.cjs');
8
-
9
- class UnknownInjectedConnector extends BitcoinWalletConnector.BitcoinWalletConnector {
10
- constructor(opts) {
11
- super(Object.assign(Object.assign({}, opts), { overrideKey: 'unknown' }));
12
- this.name = 'Unknown';
13
- this.overrideKey = 'unknown';
14
- }
15
- getAddress() {
16
- return _tslib.__awaiter(this, void 0, void 0, function* () {
17
- return;
18
- });
19
- }
20
- signPsbt(
21
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
22
- _request) {
23
- return _tslib.__awaiter(this, void 0, void 0, function* () {
24
- return;
25
- });
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
- }
34
- sendBitcoin(
35
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
36
- _transaction) {
37
- return _tslib.__awaiter(this, void 0, void 0, function* () {
38
- return;
39
- });
40
- }
41
- }
42
-
43
- exports.UnknownInjectedConnector = UnknownInjectedConnector;
@@ -1,11 +0,0 @@
1
- import { BitcoinSignPsbtRequest, BitcoinSignPsbtResponse, BitcoinTransaction } from '../../types';
2
- import { BitcoinWalletConnector, BitcoinWalletConnectorOpts } from '../BitcoinWalletConnector';
3
- export declare class UnknownInjectedConnector extends BitcoinWalletConnector {
4
- name: string;
5
- overrideKey: string;
6
- constructor(opts: BitcoinWalletConnectorOpts);
7
- getAddress(): Promise<string | undefined>;
8
- signPsbt(_request: BitcoinSignPsbtRequest): Promise<BitcoinSignPsbtResponse | undefined>;
9
- signPsbts(_requests: BitcoinSignPsbtRequest[]): Promise<string[] | undefined>;
10
- sendBitcoin(_transaction: BitcoinTransaction): Promise<string | undefined>;
11
- }
@@ -1,39 +0,0 @@
1
- 'use client'
2
- import { __awaiter } from '../../../_virtual/_tslib.js';
3
- import { BitcoinWalletConnector } from '../BitcoinWalletConnector.js';
4
-
5
- class UnknownInjectedConnector extends BitcoinWalletConnector {
6
- constructor(opts) {
7
- super(Object.assign(Object.assign({}, opts), { overrideKey: 'unknown' }));
8
- this.name = 'Unknown';
9
- this.overrideKey = 'unknown';
10
- }
11
- getAddress() {
12
- return __awaiter(this, void 0, void 0, function* () {
13
- return;
14
- });
15
- }
16
- signPsbt(
17
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
18
- _request) {
19
- return __awaiter(this, void 0, void 0, function* () {
20
- return;
21
- });
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
- }
30
- sendBitcoin(
31
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
32
- _transaction) {
33
- return __awaiter(this, void 0, void 0, function* () {
34
- return;
35
- });
36
- }
37
- }
38
-
39
- export { UnknownInjectedConnector };
@@ -1 +0,0 @@
1
- export { UnknownInjectedConnector } from './UnknownInjected';
@@ -1,32 +0,0 @@
1
- 'use client'
2
- 'use strict';
3
-
4
- Object.defineProperty(exports, '__esModule', { value: true });
5
-
6
- var walletBook = require('@dynamic-labs/wallet-book');
7
- var _const = require('../const.cjs');
8
- require('@dynamic-labs/utils');
9
- require('../../_virtual/_tslib.cjs');
10
- require('sats-connect');
11
- require('bitcoinjs-lib');
12
- require('@dynamic-labs/wallet-connector-core');
13
- require('@dynamic-labs/sdk-api-core');
14
- require('@wallet-standard/app');
15
- var hasSatsConnectFeature = require('./hasSatsConnectFeature.cjs');
16
-
17
- const supportsSatsConnect = (connector) => {
18
- var _a, _b, _c, _d;
19
- if (connector.key === _const.XVERSE_KEY) {
20
- return true;
21
- }
22
- // Grabbing the wallet standard from the fallback wallet
23
- // due to wallet standard not being available on mobile
24
- const fallbackWalletWalletStandard = (_c = (_b = (_a = walletBook.findWalletBookWallet(connector.walletBook, connector.key)) === null || _a === void 0 ? void 0 : _a.injectedConfig) === null || _b === void 0 ? void 0 : _b.find((config) => config.chain === 'btc')) === null || _c === void 0 ? void 0 : _c.walletStandard;
25
- if ((connector.wallet && hasSatsConnectFeature.hasSatsConnectFeature(connector.wallet.features)) ||
26
- ((_d = fallbackWalletWalletStandard === null || fallbackWalletWalletStandard === void 0 ? void 0 : fallbackWalletWalletStandard.features) === null || _d === void 0 ? void 0 : _d.includes(_const.SATSCONNECT_FEATURE))) {
27
- return true;
28
- }
29
- return false;
30
- };
31
-
32
- exports.supportsSatsConnect = supportsSatsConnect;
@@ -1,2 +0,0 @@
1
- import { BitcoinWalletConnector } from '../connectors';
2
- export declare const supportsSatsConnect: (connector: BitcoinWalletConnector) => boolean;
@@ -1,28 +0,0 @@
1
- 'use client'
2
- import { findWalletBookWallet } from '@dynamic-labs/wallet-book';
3
- import { XVERSE_KEY, SATSCONNECT_FEATURE } from '../const.js';
4
- import '@dynamic-labs/utils';
5
- import '../../_virtual/_tslib.js';
6
- import 'sats-connect';
7
- import 'bitcoinjs-lib';
8
- import '@dynamic-labs/wallet-connector-core';
9
- import '@dynamic-labs/sdk-api-core';
10
- import '@wallet-standard/app';
11
- import { hasSatsConnectFeature } from './hasSatsConnectFeature.js';
12
-
13
- const supportsSatsConnect = (connector) => {
14
- var _a, _b, _c, _d;
15
- if (connector.key === XVERSE_KEY) {
16
- return true;
17
- }
18
- // Grabbing the wallet standard from the fallback wallet
19
- // due to wallet standard not being available on mobile
20
- const fallbackWalletWalletStandard = (_c = (_b = (_a = findWalletBookWallet(connector.walletBook, connector.key)) === null || _a === void 0 ? void 0 : _a.injectedConfig) === null || _b === void 0 ? void 0 : _b.find((config) => config.chain === 'btc')) === null || _c === void 0 ? void 0 : _c.walletStandard;
21
- if ((connector.wallet && hasSatsConnectFeature(connector.wallet.features)) ||
22
- ((_d = fallbackWalletWalletStandard === null || fallbackWalletWalletStandard === void 0 ? void 0 : fallbackWalletWalletStandard.features) === null || _d === void 0 ? void 0 : _d.includes(SATSCONNECT_FEATURE))) {
23
- return true;
24
- }
25
- return false;
26
- };
27
-
28
- export { supportsSatsConnect };