@dynamic-labs/bitcoin 2.1.0-alpha.27 → 2.1.0-alpha.28

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 CHANGED
@@ -1,4 +1,16 @@
1
1
 
2
+ ## [2.1.0-alpha.28](https://github.com/dynamic-labs/DynamicAuth/compare/v2.1.0-alpha.27...v2.1.0-alpha.28) (2024-05-29)
3
+
4
+
5
+ ### Features
6
+
7
+ * adds solana standard wallet connector ([#5752](https://github.com/dynamic-labs/DynamicAuth/issues/5752)) ([0040940](https://github.com/dynamic-labs/DynamicAuth/commit/0040940fd1adb37ab3106bb0e4dfe79403bc41f2))
8
+
9
+
10
+ ### Bug Fixes
11
+
12
+ * farcaster fetch url fix ([#5767](https://github.com/dynamic-labs/DynamicAuth/issues/5767)) ([1408ba9](https://github.com/dynamic-labs/DynamicAuth/commit/1408ba92680363b9db7820a63d5e3d15dc26ad22))
13
+
2
14
  ## [2.1.0-alpha.27](https://github.com/dynamic-labs/DynamicAuth/compare/v2.1.0-alpha.26...v2.1.0-alpha.27) (2024-05-29)
3
15
 
4
16
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dynamic-labs/bitcoin",
3
- "version": "2.1.0-alpha.27",
3
+ "version": "2.1.0-alpha.28",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/dynamic-labs/dynamic-auth.git",
@@ -32,9 +32,9 @@
32
32
  "@wallet-standard/base": "1.0.1",
33
33
  "bitcoinjs-lib": "6.1.5",
34
34
  "sats-connect": "2.0.0",
35
- "@dynamic-labs/utils": "2.1.0-alpha.27",
36
- "@dynamic-labs/wallet-book": "2.1.0-alpha.27",
37
- "@dynamic-labs/wallet-connector-core": "2.1.0-alpha.27",
35
+ "@dynamic-labs/utils": "2.1.0-alpha.28",
36
+ "@dynamic-labs/wallet-book": "2.1.0-alpha.28",
37
+ "@dynamic-labs/wallet-connector-core": "2.1.0-alpha.28",
38
38
  "stream": "0.0.2"
39
39
  },
40
40
  "peerDependencies": {}
@@ -51,6 +51,15 @@ class BitcoinProviderHelper {
51
51
  findWallet() {
52
52
  return this.bitcoinWalletStandardLookup();
53
53
  }
54
+ getWalletMethods(wallet) {
55
+ var _a, _b, _c, _d;
56
+ return {
57
+ connect: (_a = wallet.features['bitcoin:connect']) === null || _a === void 0 ? void 0 : _a.connect,
58
+ signAndSendTransaction: (_b = wallet.features['bitcoin:signAndSendTransaction']) === null || _b === void 0 ? void 0 : _b.signAndSendTransaction,
59
+ signMessage: (_c = wallet.features['bitcoin:signMessage']) === null || _c === void 0 ? void 0 : _c.signMessage,
60
+ signTransaction: (_d = wallet.features['bitcoin:signTransaction']) === null || _d === void 0 ? void 0 : _d.signTransaction,
61
+ };
62
+ }
54
63
  }
55
64
 
56
65
  exports.BitcoinProviderHelper = BitcoinProviderHelper;
@@ -1,5 +1,6 @@
1
1
  import type { Wallet } from '@wallet-standard/base';
2
2
  import { WalletSchema } from '@dynamic-labs/wallet-book';
3
+ import { BitcoinWalletStandardMethods } from './types';
3
4
  export declare class BitcoinProviderHelper {
4
5
  private walletData;
5
6
  constructor(walletData: WalletSchema);
@@ -20,4 +21,5 @@ export declare class BitcoinProviderHelper {
20
21
  hasAllRequiredFeatures(wallet: Wallet): boolean;
21
22
  bitcoinWalletStandardLookup(): Wallet | undefined;
22
23
  findWallet(): Wallet | undefined;
24
+ getWalletMethods(wallet: Wallet): BitcoinWalletStandardMethods;
23
25
  }
@@ -47,6 +47,15 @@ class BitcoinProviderHelper {
47
47
  findWallet() {
48
48
  return this.bitcoinWalletStandardLookup();
49
49
  }
50
+ getWalletMethods(wallet) {
51
+ var _a, _b, _c, _d;
52
+ return {
53
+ connect: (_a = wallet.features['bitcoin:connect']) === null || _a === void 0 ? void 0 : _a.connect,
54
+ signAndSendTransaction: (_b = wallet.features['bitcoin:signAndSendTransaction']) === null || _b === void 0 ? void 0 : _b.signAndSendTransaction,
55
+ signMessage: (_c = wallet.features['bitcoin:signMessage']) === null || _c === void 0 ? void 0 : _c.signMessage,
56
+ signTransaction: (_d = wallet.features['bitcoin:signTransaction']) === null || _d === void 0 ? void 0 : _d.signTransaction,
57
+ };
58
+ }
50
59
  }
51
60
 
52
61
  export { BitcoinProviderHelper };
@@ -28,6 +28,9 @@ class BitcoinWalletConnector extends walletConnectorCore.WalletConnectorBase {
28
28
  this.overrideKey = (_a = opts.overrideKey) !== null && _a !== void 0 ? _a : this.key;
29
29
  this.bitcoinProviderHelper = new bitcoinProviderHelper.BitcoinProviderHelper(opts.walletData || walletBook.getWalletBookWallet(this.walletBook, this.key));
30
30
  this.wallet = this.bitcoinProviderHelper.findWallet();
31
+ if (this.wallet) {
32
+ this.walletMethods = this.bitcoinProviderHelper.getWalletMethods(this.wallet);
33
+ }
31
34
  this.cache = new BitcoinLocalStorageCache.BitcoinLocalStorageCache(this.overrideKey);
32
35
  }
33
36
  canConnectWithHardwareWallet() {
@@ -206,7 +209,23 @@ class BitcoinWalletConnector extends walletConnectorCore.WalletConnectorBase {
206
209
  return;
207
210
  }
208
211
  const { handleAccountChange, handleChainChange, handleDisconnect } = walletConnectorCore.eventListenerHandlers(this);
209
- provider.on('accountsChanged', handleAccountChange);
212
+ const handleBitcoinAccountChange = (accounts) => _tslib.__awaiter(this, void 0, void 0, function* () {
213
+ let connectedAccounts = accounts;
214
+ // if accounts is an array of objects, we need to parse them to return only addresses
215
+ // since ordinals is the main address we use, we should return it as the first address
216
+ if (typeof accounts[0] === 'object') {
217
+ connectedAccounts = accounts
218
+ .sort((account) => (account.purpose === 'ordinals' ? -1 : 1))
219
+ .map((account) => account.address);
220
+ }
221
+ const currentConnectedAccounts = yield this.getConnectedAccountsFromCache();
222
+ // don't do anything if the connected accounts haven't changed
223
+ if (currentConnectedAccounts[0] === connectedAccounts[0]) {
224
+ return;
225
+ }
226
+ handleAccountChange(connectedAccounts);
227
+ });
228
+ provider.on('accountsChanged', handleBitcoinAccountChange);
210
229
  provider.on('networkChanged', handleChainChange);
211
230
  provider.on('disconnect', handleDisconnect);
212
231
  const tearDownEventListeners = () => {
@@ -214,7 +233,7 @@ class BitcoinWalletConnector extends walletConnectorCore.WalletConnectorBase {
214
233
  if (!(provider === null || provider === void 0 ? void 0 : provider.removeListener)) {
215
234
  return;
216
235
  }
217
- provider.removeListener('accountsChanged', handleAccountChange);
236
+ provider.removeListener('accountsChanged', handleBitcoinAccountChange);
218
237
  provider.removeListener('networkChanged', handleChainChange);
219
238
  provider.removeListener('disconnect', handleDisconnect);
220
239
  };
@@ -6,7 +6,7 @@ import { Chain, IBitcoinWalletConnector, WalletConnectorBase } from '@dynamic-la
6
6
  import { WalletBookSchema, WalletSchema } from '@dynamic-labs/wallet-book';
7
7
  import { JwtVerifiedCredential, WalletAdditionalAddress } from '@dynamic-labs/sdk-api-core';
8
8
  import { IBitcoinSessionCache } from '../BitcoinLocalStorageCache';
9
- import { BitcoinAddress, BitcoinTransaction, BitcoinSignPsbtRequest, BitcoinSignPsbtResponse } from '../types';
9
+ import { BitcoinAddress, BitcoinTransaction, BitcoinSignPsbtRequest, BitcoinSignPsbtResponse, BitcoinWalletStandardMethods } from '../types';
10
10
  export type BitcoinWalletConnectorOpts = {
11
11
  walletBook: WalletBookSchema;
12
12
  walletData: WalletSchema;
@@ -19,6 +19,7 @@ export declare abstract class BitcoinWalletConnector extends WalletConnectorBase
19
19
  private getAddressPromise;
20
20
  private bitcoinProviderHelper;
21
21
  wallet: Wallet | undefined;
22
+ walletMethods: BitcoinWalletStandardMethods | undefined;
22
23
  canFetchConnectedAccounts: boolean;
23
24
  isHardwareWalletEnabled: boolean;
24
25
  verifiedCredentials: JwtVerifiedCredential[];
@@ -24,6 +24,9 @@ class BitcoinWalletConnector extends WalletConnectorBase {
24
24
  this.overrideKey = (_a = opts.overrideKey) !== null && _a !== void 0 ? _a : this.key;
25
25
  this.bitcoinProviderHelper = new BitcoinProviderHelper(opts.walletData || getWalletBookWallet(this.walletBook, this.key));
26
26
  this.wallet = this.bitcoinProviderHelper.findWallet();
27
+ if (this.wallet) {
28
+ this.walletMethods = this.bitcoinProviderHelper.getWalletMethods(this.wallet);
29
+ }
27
30
  this.cache = new BitcoinLocalStorageCache(this.overrideKey);
28
31
  }
29
32
  canConnectWithHardwareWallet() {
@@ -202,7 +205,23 @@ class BitcoinWalletConnector extends WalletConnectorBase {
202
205
  return;
203
206
  }
204
207
  const { handleAccountChange, handleChainChange, handleDisconnect } = eventListenerHandlers(this);
205
- provider.on('accountsChanged', handleAccountChange);
208
+ const handleBitcoinAccountChange = (accounts) => __awaiter(this, void 0, void 0, function* () {
209
+ let connectedAccounts = accounts;
210
+ // if accounts is an array of objects, we need to parse them to return only addresses
211
+ // since ordinals is the main address we use, we should return it as the first address
212
+ if (typeof accounts[0] === 'object') {
213
+ connectedAccounts = accounts
214
+ .sort((account) => (account.purpose === 'ordinals' ? -1 : 1))
215
+ .map((account) => account.address);
216
+ }
217
+ const currentConnectedAccounts = yield this.getConnectedAccountsFromCache();
218
+ // don't do anything if the connected accounts haven't changed
219
+ if (currentConnectedAccounts[0] === connectedAccounts[0]) {
220
+ return;
221
+ }
222
+ handleAccountChange(connectedAccounts);
223
+ });
224
+ provider.on('accountsChanged', handleBitcoinAccountChange);
206
225
  provider.on('networkChanged', handleChainChange);
207
226
  provider.on('disconnect', handleDisconnect);
208
227
  const tearDownEventListeners = () => {
@@ -210,7 +229,7 @@ class BitcoinWalletConnector extends WalletConnectorBase {
210
229
  if (!(provider === null || provider === void 0 ? void 0 : provider.removeListener)) {
211
230
  return;
212
231
  }
213
- provider.removeListener('accountsChanged', handleAccountChange);
232
+ provider.removeListener('accountsChanged', handleBitcoinAccountChange);
214
233
  provider.removeListener('networkChanged', handleChainChange);
215
234
  provider.removeListener('disconnect', handleDisconnect);
216
235
  };
package/src/types.d.ts CHANGED
@@ -1,5 +1,6 @@
1
- import { BitcoinProvider, InputToSign } from 'sats-connect';
1
+ import { BitcoinProvider, InputToSign as SatsConnectInputToSign } from 'sats-connect';
2
2
  import { SignPsbtResponse as BtcKitSignPsbtResponse } from '@btckit/types';
3
+ import { IdentifierString, WalletAccount } from '@wallet-standard/base';
3
4
  import type { WalletAdditionalAddress } from '@dynamic-labs/sdk-api-core';
4
5
  import { SATSCONNECT_FEATURE } from './const';
5
6
  export type ErrorWithCode = Error & {
@@ -44,7 +45,7 @@ export type BitcoinSignPsbtRequestSignature = {
44
45
  export type SatsConnectSignTransactionInput = {
45
46
  message?: string;
46
47
  psbtBase64: string;
47
- inputsToSign: InputToSign[];
48
+ inputsToSign: SatsConnectInputToSign[];
48
49
  broadcast?: boolean;
49
50
  };
50
51
  export type BtcKitSignPsbtResponseExtended = BtcKitSignPsbtResponse & {
@@ -55,3 +56,68 @@ export type BtcKitSignPsbtResponseExtended = BtcKitSignPsbtResponse & {
55
56
  export type BitcoinSignPsbtResponse = {
56
57
  signedPsbt: string;
57
58
  };
59
+ export type BitcoinAddressPurpose = 'ordinals' | 'payment';
60
+ export interface BitcoinConnectInput {
61
+ purposes: BitcoinAddressPurpose[];
62
+ }
63
+ export interface BitcoinConnectOutput {
64
+ /**
65
+ * The accounts will have addresses that correspond with the `purposes` in the {@link BitcoinConnectInput}, and will
66
+ * be returned in the same order.
67
+ */
68
+ accounts: WalletAccount[];
69
+ }
70
+ export type BitcoinConnectMethod = (input?: BitcoinConnectInput) => Promise<BitcoinConnectOutput>;
71
+ export type BitcoinSignMessageMethod = (...inputs: BitcoinSignMessageInput[]) => Promise<BitcoinSignMessageOutput[]>;
72
+ export interface BitcoinSignMessageInput {
73
+ /** Account to use. */
74
+ account: WalletAccount;
75
+ /** Message to sign, as raw bytes. */
76
+ message: Uint8Array;
77
+ }
78
+ export interface BitcoinSignMessageOutput {
79
+ /**
80
+ * Message bytes that were signed.
81
+ * The wallet may prefix or otherwise modify the message before signing it.
82
+ */
83
+ signedMessage: Uint8Array;
84
+ /** Message signature produced. */
85
+ signature: Uint8Array;
86
+ }
87
+ export type BitcoinSignTransactionMethod = (...inputs: BitcoinSignTransactionInput[]) => Promise<BitcoinSignTransactionOutput[]>;
88
+ export interface BitcoinSignTransactionInput {
89
+ /** Partially Signed Bitcoin Transaction (PSBT), as raw bytes. */
90
+ psbt: Uint8Array;
91
+ /** Transaction inputs to sign. */
92
+ inputsToSign: InputToSign[];
93
+ /** Chain to use. */
94
+ chain?: IdentifierString;
95
+ }
96
+ export interface InputToSign {
97
+ /** Account to use. */
98
+ account: WalletAccount;
99
+ /** List of input indexes that should be signed by the account. */
100
+ signingIndexes: number[];
101
+ /** A SIGHASH flag. */
102
+ sigHash?: BitcoinSigHashFlag;
103
+ }
104
+ export interface BitcoinSignTransactionOutput {
105
+ /** Signed Partially Signed Bitcoin Transaction (PSBT), as raw bytes. */
106
+ signedPsbt: Uint8Array;
107
+ }
108
+ /** SIGHASH flag. */
109
+ export type BitcoinSigHashFlag = 'ALL' | 'NONE' | 'SINGLE' | 'ALL|ANYONECANPAY' | 'NONE|ANYONECANPAY' | 'SINGLE|ANYONECANPAY';
110
+ export type BitcoinSignAndSendTransactionMethod = (...inputs: BitcoinSignAndSendTransactionInput[]) => Promise<BitcoinSignAndSendTransactionOutput[]>;
111
+ export interface BitcoinSignAndSendTransactionInput extends BitcoinSignTransactionInput {
112
+ chain: IdentifierString;
113
+ }
114
+ export interface BitcoinSignAndSendTransactionOutput {
115
+ /** Transaction ID (transaction hash). */
116
+ txId: string;
117
+ }
118
+ export type BitcoinWalletStandardMethods = {
119
+ connect?: BitcoinConnectMethod;
120
+ signMessage?: BitcoinSignMessageMethod;
121
+ signTransaction?: BitcoinSignTransactionMethod;
122
+ signAndSendTransaction?: BitcoinSignAndSendTransactionMethod;
123
+ };