@dynamic-labs/solana 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 (104) hide show
  1. package/CHANGELOG.md +468 -0
  2. package/package.cjs +8 -0
  3. package/package.js +4 -0
  4. package/package.json +12 -18
  5. package/src/{CoinbaseSolana.cjs → CoinbaseSolana/CoinbaseSolana.cjs} +6 -14
  6. package/src/{CoinbaseSolana.d.ts → CoinbaseSolana/CoinbaseSolana.d.ts} +1 -3
  7. package/src/{CoinbaseSolana.js → CoinbaseSolana/CoinbaseSolana.js} +6 -14
  8. package/src/CoinbaseSolana/index.d.ts +1 -0
  9. package/src/{Phantom.cjs → Phantom/Phantom.cjs} +7 -9
  10. package/src/Phantom/Phantom.d.ts +9 -0
  11. package/src/{Phantom.js → Phantom/Phantom.js} +7 -9
  12. package/src/Phantom/index.d.ts +1 -0
  13. package/src/{solProviderHelper.cjs → SolProviderHelper/SolProviderHelper.cjs} +33 -22
  14. package/src/{solProviderHelper.d.ts → SolProviderHelper/SolProviderHelper.d.ts} +6 -5
  15. package/src/{solProviderHelper.js → SolProviderHelper/SolProviderHelper.js} +33 -22
  16. package/src/SolProviderHelper/index.d.ts +1 -0
  17. package/src/SolanaWalletConnectors.cjs +21 -0
  18. package/src/SolanaWalletConnectors.d.ts +2 -0
  19. package/src/SolanaWalletConnectors.js +17 -0
  20. package/src/SolanaWalletConnectorsWithConfig/SolanaWalletConnectorsWithConfig.cjs +26 -0
  21. package/src/SolanaWalletConnectorsWithConfig/SolanaWalletConnectorsWithConfig.d.ts +6 -0
  22. package/src/SolanaWalletConnectorsWithConfig/SolanaWalletConnectorsWithConfig.js +22 -0
  23. package/src/SolanaWalletConnectorsWithConfig/index.d.ts +1 -0
  24. package/src/{Solflare.cjs → Solflare/Solflare.cjs} +9 -10
  25. package/src/{Solflare.d.ts → Solflare/Solflare.d.ts} +1 -3
  26. package/src/{Solflare.js → Solflare/Solflare.js} +9 -10
  27. package/src/Solflare/index.d.ts +1 -0
  28. package/src/index.cjs +19 -18
  29. package/src/index.d.ts +7 -5
  30. package/src/index.js +9 -17
  31. package/src/injected/{BackpackSol.cjs → BackpackSol/BackpackSol.cjs} +5 -7
  32. package/src/injected/{BackpackSol.d.ts → BackpackSol/BackpackSol.d.ts} +1 -3
  33. package/src/injected/{BackpackSol.js → BackpackSol/BackpackSol.js} +5 -7
  34. package/src/injected/BackpackSol/index.d.ts +1 -0
  35. package/src/injected/{FallbackSolanaConnector.cjs → FallbackSolanaConnector/FallbackSolanaConnector.cjs} +3 -5
  36. package/src/injected/{FallbackSolanaConnector.d.ts → FallbackSolanaConnector/FallbackSolanaConnector.d.ts} +1 -3
  37. package/src/injected/{FallbackSolanaConnector.js → FallbackSolanaConnector/FallbackSolanaConnector.js} +3 -5
  38. package/src/injected/FallbackSolanaConnector/index.d.ts +1 -0
  39. package/src/injected/{InjectedWalletBase.cjs → InjectedWalletBase/InjectedWalletBase.cjs} +23 -27
  40. package/src/injected/{InjectedWalletBase.d.ts → InjectedWalletBase/InjectedWalletBase.d.ts} +6 -8
  41. package/src/injected/{InjectedWalletBase.js → InjectedWalletBase/InjectedWalletBase.js} +24 -28
  42. package/src/injected/InjectedWalletBase/index.d.ts +1 -0
  43. package/src/injected/{PhantomInjected.cjs → PhantomInjected/PhantomInjected.cjs} +5 -7
  44. package/src/injected/{PhantomInjected.d.ts → PhantomInjected/PhantomInjected.d.ts} +1 -3
  45. package/src/injected/{PhantomInjected.js → PhantomInjected/PhantomInjected.js} +5 -7
  46. package/src/injected/PhantomInjected/index.d.ts +1 -0
  47. package/src/injected/fetchInjectedWalletConnectors.cjs +43 -25
  48. package/src/injected/fetchInjectedWalletConnectors.js +43 -25
  49. package/src/injected/index.d.ts +0 -1
  50. package/src/{SolanaWalletStandardConnector/utils → injected/walletStandard}/createSolanaSignerFromWalletStandard/createSolanaSignerFromWalletStandard.cjs +72 -21
  51. package/src/injected/walletStandard/createSolanaSignerFromWalletStandard/createSolanaSignerFromWalletStandard.d.ts +4 -0
  52. package/src/{SolanaWalletStandardConnector/utils → injected/walletStandard}/createSolanaSignerFromWalletStandard/createSolanaSignerFromWalletStandard.js +71 -20
  53. package/src/injected/walletStandard/getConnectorConstructorForWalletStandardWallet/getConnectorConstructorForWalletStandardWallet.cjs +29 -0
  54. package/src/injected/walletStandard/getConnectorConstructorForWalletStandardWallet/getConnectorConstructorForWalletStandardWallet.d.ts +3 -0
  55. package/src/injected/walletStandard/getConnectorConstructorForWalletStandardWallet/getConnectorConstructorForWalletStandardWallet.js +25 -0
  56. package/src/injected/walletStandard/getConnectorConstructorForWalletStandardWallet/index.d.ts +1 -0
  57. package/src/injected/walletStandard/getWalletStandardWallets/getWalletStandardWallets.cjs +10 -0
  58. package/src/injected/walletStandard/getWalletStandardWallets/getWalletStandardWallets.d.ts +1 -0
  59. package/src/injected/walletStandard/getWalletStandardWallets/getWalletStandardWallets.js +6 -0
  60. package/src/injected/walletStandard/getWalletStandardWallets/index.d.ts +1 -0
  61. package/src/phantomRedirect/{PhantomRedirect.cjs → PhantomRedirect/PhantomRedirect.cjs} +28 -25
  62. package/src/phantomRedirect/{PhantomRedirect.d.ts → PhantomRedirect/PhantomRedirect.d.ts} +3 -3
  63. package/src/phantomRedirect/{PhantomRedirect.js → PhantomRedirect/PhantomRedirect.js} +10 -7
  64. package/src/phantomRedirect/PhantomRedirect/index.d.ts +1 -0
  65. package/src/phantomRedirect/buildUrl/buildUrl.cjs +8 -0
  66. package/src/phantomRedirect/buildUrl/buildUrl.d.ts +1 -0
  67. package/src/phantomRedirect/buildUrl/buildUrl.js +4 -0
  68. package/src/phantomRedirect/buildUrl/index.d.ts +1 -0
  69. package/src/phantomRedirect/decryptPayload/decryptPayload.cjs +34 -0
  70. package/src/phantomRedirect/decryptPayload/decryptPayload.d.ts +1 -0
  71. package/src/phantomRedirect/decryptPayload/decryptPayload.js +25 -0
  72. package/src/phantomRedirect/decryptPayload/index.d.ts +1 -0
  73. package/src/phantomRedirect/encryptPayload/encryptPayload.cjs +18 -0
  74. package/src/phantomRedirect/encryptPayload/encryptPayload.d.ts +1 -0
  75. package/src/phantomRedirect/encryptPayload/encryptPayload.js +10 -0
  76. package/src/phantomRedirect/encryptPayload/index.d.ts +1 -0
  77. package/src/phantomRedirect/fetchCluster/fetchCluster.cjs +33 -0
  78. package/src/phantomRedirect/fetchCluster/fetchCluster.d.ts +1 -0
  79. package/src/phantomRedirect/fetchCluster/fetchCluster.js +29 -0
  80. package/src/phantomRedirect/fetchCluster/index.d.ts +1 -0
  81. package/src/phantomRedirect/storage/index.d.ts +1 -0
  82. package/src/phantomRedirect/{storage.d.ts → storage/storage.d.ts} +1 -1
  83. package/src/utils/logger.cjs +10 -0
  84. package/src/utils/logger.d.ts +2 -0
  85. package/src/utils/logger.js +6 -0
  86. package/src/Phantom.d.ts +0 -12
  87. package/src/SolanaWalletStandardConnector/SolanaWalletStandardConnector.cjs +0 -100
  88. package/src/SolanaWalletStandardConnector/SolanaWalletStandardConnector.d.ts +0 -20
  89. package/src/SolanaWalletStandardConnector/SolanaWalletStandardConnector.js +0 -96
  90. package/src/SolanaWalletStandardConnector/index.d.ts +0 -1
  91. package/src/SolanaWalletStandardConnector/utils/createSolanaSignerFromWalletStandard/createSolanaSignerFromWalletStandard.d.ts +0 -3
  92. package/src/injected/UnknownInjected.cjs +0 -21
  93. package/src/injected/UnknownInjected.d.ts +0 -8
  94. package/src/injected/UnknownInjected.js +0 -17
  95. package/src/phantomRedirect/utils.cjs +0 -56
  96. package/src/phantomRedirect/utils.d.ts +0 -4
  97. package/src/phantomRedirect/utils.js +0 -44
  98. /package/src/{SolanaWalletStandardConnector/utils → injected/walletStandard}/createSolanaSignerFromWalletStandard/index.d.ts +0 -0
  99. /package/src/{utils → injected/walletStandard}/findWalletProviderFromWalletStandard/findWalletProviderFromWalletStandard.cjs +0 -0
  100. /package/src/{utils → injected/walletStandard}/findWalletProviderFromWalletStandard/findWalletProviderFromWalletStandard.d.ts +0 -0
  101. /package/src/{utils → injected/walletStandard}/findWalletProviderFromWalletStandard/findWalletProviderFromWalletStandard.js +0 -0
  102. /package/src/{utils → injected/walletStandard}/findWalletProviderFromWalletStandard/index.d.ts +0 -0
  103. /package/src/phantomRedirect/{storage.cjs → storage/storage.cjs} +0 -0
  104. /package/src/phantomRedirect/{storage.js → storage/storage.js} +0 -0
@@ -1,58 +1,76 @@
1
1
  'use client'
2
- import { CoinbaseSolana } from '../CoinbaseSolana.js';
3
- import { Solflare } from '../Solflare.js';
4
- import { SolanaWalletStandardConnector } from '../SolanaWalletStandardConnector/SolanaWalletStandardConnector.js';
5
- import { InjectedWalletBase } from './InjectedWalletBase.js';
6
- import { BackpackSol } from './BackpackSol.js';
2
+ import { sanitizeName } from '@dynamic-labs/utils';
3
+ import { CoinbaseSolana } from '../CoinbaseSolana/CoinbaseSolana.js';
4
+ import { Solflare } from '../Solflare/Solflare.js';
5
+ import { logger } from '../utils/logger.js';
6
+ import { InjectedWalletBase } from './InjectedWalletBase/InjectedWalletBase.js';
7
+ import { BackpackSol } from './BackpackSol/BackpackSol.js';
8
+ import { getConnectorConstructorForWalletStandardWallet } from './walletStandard/getConnectorConstructorForWalletStandardWallet/getConnectorConstructorForWalletStandardWallet.js';
9
+ import { getWalletStandardWallets } from './walletStandard/getWalletStandardWallets/getWalletStandardWallets.js';
7
10
 
8
11
  const injectedWalletOverrides = [
9
12
  CoinbaseSolana,
10
13
  BackpackSol,
11
14
  Solflare,
12
15
  ];
13
- const filteredInjectedWalletKeysOverrides = [
16
+ const walletsWithCustomConnectors = [
14
17
  'coinbasesolana',
15
18
  'phantom',
16
19
  'phantomledger',
17
20
  'backpacksol',
18
21
  'solflare',
19
22
  ];
23
+ const shouldAddWalletStandardConnector = (wallet, walletBook) => {
24
+ var _a, _b, _c, _d, _e, _f;
25
+ const { name } = wallet;
26
+ const chain = 'sol';
27
+ const connectorKey = `${sanitizeName(name)}${chain}`;
28
+ logger.logVerboseTroubleshootingMessage('[SOL shouldAddWalletStandardConnector]', name, chain, connectorKey, wallet.features);
29
+ const existingWallet = Object.entries((_a = walletBook === null || walletBook === void 0 ? void 0 : walletBook.wallets) !== null && _a !== void 0 ? _a : {}).find(([key, wallet]) => {
30
+ var _a;
31
+ return key === connectorKey ||
32
+ walletsWithCustomConnectors.includes(connectorKey) ||
33
+ (wallet.name === name && ((_a = wallet.injectedConfig) === null || _a === void 0 ? void 0 : _a[0].chain) === chain);
34
+ });
35
+ const hasAllFeatures = Boolean(((_b = wallet.features) === null || _b === void 0 ? void 0 : _b['standard:events']) &&
36
+ ((_c = wallet.features) === null || _c === void 0 ? void 0 : _c['standard:connect']) &&
37
+ ((_d = wallet.features) === null || _d === void 0 ? void 0 : _d['solana:signMessage']) &&
38
+ ((_e = wallet.features) === null || _e === void 0 ? void 0 : _e['solana:signTransaction']) &&
39
+ ((_f = wallet.features) === null || _f === void 0 ? void 0 : _f['solana:signAndSendTransaction']));
40
+ logger.logVerboseTroubleshootingMessage('[SOL shouldAddWalletStandardConnector]', {
41
+ existingWallet,
42
+ hasAllFeatures,
43
+ shouldAdd: !existingWallet && hasAllFeatures,
44
+ });
45
+ return !existingWallet && hasAllFeatures;
46
+ };
20
47
  const fetchInjectedWalletConnectors = ({ walletBook, }) => {
21
48
  var _a;
22
- return Object.entries((_a = walletBook === null || walletBook === void 0 ? void 0 : walletBook.wallets) !== null && _a !== void 0 ? _a : {})
49
+ const walletBookConnectors = Object.entries((_a = walletBook === null || walletBook === void 0 ? void 0 : walletBook.wallets) !== null && _a !== void 0 ? _a : {})
23
50
  .filter(([key, wallet]) => {
24
51
  var _a;
25
52
  const isSolanaWallet = Boolean((_a = wallet.injectedConfig) === null || _a === void 0 ? void 0 : _a.find((config) => config.chain === 'sol'));
26
- const shouldBeFiltered = filteredInjectedWalletKeysOverrides.includes(key);
53
+ const shouldBeFiltered = walletsWithCustomConnectors.includes(key);
27
54
  return isSolanaWallet && !shouldBeFiltered;
28
55
  })
29
56
  .map(([key, wallet]) => {
30
- var _a;
31
57
  const { shortName } = wallet;
32
58
  const name = shortName || wallet.name;
33
- const hasWalletStandard = Boolean((_a = wallet.injectedConfig) === null || _a === void 0 ? void 0 : _a.find((config) => config.walletStandard));
34
- if (hasWalletStandard) {
35
- const isWalletStandardPresent = Boolean(SolanaWalletStandardConnector.getWallet(walletBook, key));
36
- if (isWalletStandardPresent) {
37
- return class extends SolanaWalletStandardConnector {
38
- constructor(props) {
39
- super(Object.assign({}, props));
40
- this.name = name;
41
- this.overrideKey = key;
42
- }
43
- };
44
- }
45
- }
46
59
  return class extends InjectedWalletBase {
47
- constructor(props) {
48
- super(Object.assign({}, props));
60
+ constructor() {
61
+ super(...arguments);
49
62
  this.name = name;
50
- this.wallet = wallet;
51
63
  // this is the key from the wallet book entry so that we don't purely rely on the normalized name
52
64
  this.overrideKey = key;
53
65
  }
54
66
  };
55
67
  });
68
+ const walletStandardWallets = getWalletStandardWallets();
69
+ const walletStandardConnectors = walletStandardWallets
70
+ .filter((wallet) => shouldAddWalletStandardConnector(wallet, walletBook))
71
+ .map((wallet) => getConnectorConstructorForWalletStandardWallet(wallet));
72
+ logger.logVerboseTroubleshootingMessage('[SOL fetchInjectedWalletConnectors] walletStandardConnectors', walletStandardConnectors.map((w) => w.name));
73
+ return [...walletBookConnectors, ...walletStandardConnectors];
56
74
  };
57
75
 
58
76
  export { fetchInjectedWalletConnectors, injectedWalletOverrides };
@@ -1,3 +1,2 @@
1
1
  export * from './fetchInjectedWalletConnectors';
2
- export * from './UnknownInjected';
3
2
  export * from './FallbackSolanaConnector';
@@ -5,11 +5,38 @@ Object.defineProperty(exports, '__esModule', { value: true });
5
5
 
6
6
  var _tslib = require('../../../../_virtual/_tslib.cjs');
7
7
  var web3_js = require('@solana/web3.js');
8
- var utils = require('../../../phantomRedirect/utils.cjs');
8
+ var fetchCluster = require('../../../phantomRedirect/fetchCluster/fetchCluster.cjs');
9
+ var logger = require('../../../utils/logger.cjs');
9
10
 
10
11
  const isVersionedTransaction = (transaction) => !('instructions' in transaction);
11
12
  const createSolanaSignerFromWalletStandard = (wallet, walletConnector) => {
12
13
  const features = wallet.features;
14
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
15
+ const connect = (args) => _tslib.__awaiter(void 0, void 0, void 0, function* () {
16
+ var _a;
17
+ const connectMethod = (_a = features['standard:connect']) === null || _a === void 0 ? void 0 : _a.connect;
18
+ if (!connectMethod) {
19
+ logger.logger.error('connect - Not implemented');
20
+ return;
21
+ }
22
+ const result = yield connectMethod({ silent: false });
23
+ if (!result.accounts[0]) {
24
+ return;
25
+ }
26
+ return {
27
+ address: result.accounts[0].address,
28
+ publicKey: result.accounts[0].publicKey,
29
+ };
30
+ });
31
+ const disconnect = () => _tslib.__awaiter(void 0, void 0, void 0, function* () {
32
+ var _b;
33
+ const disconnectMethod = (_b = features['standard:disconnect']) === null || _b === void 0 ? void 0 : _b.disconnect;
34
+ if (!disconnectMethod) {
35
+ logger.logger.debug('disconnect - Not implemented');
36
+ return;
37
+ }
38
+ yield disconnectMethod();
39
+ });
13
40
  const getCurrentAccount = () => _tslib.__awaiter(void 0, void 0, void 0, function* () {
14
41
  const address = yield walletConnector.getAddress();
15
42
  const account = wallet.accounts.find((account) => account.address === address);
@@ -19,9 +46,9 @@ const createSolanaSignerFromWalletStandard = (wallet, walletConnector) => {
19
46
  return account;
20
47
  });
21
48
  const getChain = () => _tslib.__awaiter(void 0, void 0, void 0, function* () {
22
- var _a, _b;
23
- const rpc = (_b = (_a = walletConnector.solNetworks[0].privateCustomerRpcUrls) === null || _a === void 0 ? void 0 : _a[0]) !== null && _b !== void 0 ? _b : walletConnector.solNetworks[0].rpcUrls[0];
24
- const cluster = yield utils.fetchCluster(rpc);
49
+ var _c, _d;
50
+ const rpc = (_d = (_c = walletConnector.solNetworks[0].privateCustomerRpcUrls) === null || _c === void 0 ? void 0 : _c[0]) !== null && _d !== void 0 ? _d : walletConnector.solNetworks[0].rpcUrls[0];
51
+ const cluster = yield fetchCluster.fetchCluster(rpc);
25
52
  return `solana:${cluster}`;
26
53
  });
27
54
  const signTransaction = (transaction) => _tslib.__awaiter(void 0, void 0, void 0, function* () {
@@ -57,19 +84,39 @@ const createSolanaSignerFromWalletStandard = (wallet, walletConnector) => {
57
84
  });
58
85
  return { signature: messages[0].signature };
59
86
  });
87
+ const on = (event, listener) => {
88
+ var _a;
89
+ const onMethod = (_a = features['standard:events']) === null || _a === void 0 ? void 0 : _a.on;
90
+ if (!onMethod) {
91
+ logger.logger.error('on - Not implemented');
92
+ return;
93
+ }
94
+ if (event !== 'accountChanged') {
95
+ logger.logger.debug(`on - Not implemented for event: ${event}`);
96
+ return;
97
+ }
98
+ const wrappedListener = (prop) => {
99
+ var _a;
100
+ const publicKey = (_a = prop.accounts) === null || _a === void 0 ? void 0 : _a[0].publicKey;
101
+ if (publicKey) {
102
+ listener(new TextDecoder().decode(publicKey));
103
+ }
104
+ };
105
+ // 'change' is the only event that is supported by the wallet standard
106
+ return onMethod('change', wrappedListener);
107
+ };
60
108
  return {
61
109
  addListener: () => {
62
- throw new Error('Not implemented');
110
+ throw new Error('addListener - Not implemented');
63
111
  },
64
- connect: () => {
65
- throw new Error('Not implemented');
66
- },
67
- disconnect: () => walletConnector.endSession(),
112
+ connect,
113
+ disconnect,
68
114
  emit: () => {
69
- throw new Error('Not implemented');
115
+ throw new Error('emit - Not implemented');
70
116
  },
71
117
  eventNames: () => {
72
- throw new Error('Not implemented');
118
+ logger.logger.error('eventNames - Not implemented');
119
+ return [];
73
120
  },
74
121
  isBackpack: false,
75
122
  isBraveWallet: false,
@@ -80,32 +127,36 @@ const createSolanaSignerFromWalletStandard = (wallet, walletConnector) => {
80
127
  isPhantom: false,
81
128
  isSolflare: false,
82
129
  listenerCount: () => {
83
- throw new Error('Not implemented');
130
+ logger.logger.error('listenerCount - Not implemented');
131
+ return 0;
84
132
  },
85
133
  listeners: () => {
86
- throw new Error('Not implemented');
134
+ logger.logger.error('listeners - Not implemented');
135
+ return [];
87
136
  },
88
137
  off: () => {
89
- throw new Error('Not implemented');
90
- },
91
- on: () => {
92
- throw new Error('Not implemented');
138
+ throw new Error('off - Not implemented');
93
139
  },
140
+ on,
94
141
  once: () => {
95
- throw new Error('Not implemented');
142
+ throw new Error('once - Not implemented');
96
143
  },
97
144
  providers: [],
98
145
  get publicKey() {
146
+ var _a;
147
+ if (!((_a = wallet.accounts) === null || _a === void 0 ? void 0 : _a[0].publicKey)) {
148
+ return undefined;
149
+ }
99
150
  return new web3_js.PublicKey(wallet.accounts[0].publicKey);
100
151
  },
101
152
  removeAllListeners: () => {
102
- throw new Error('Not implemented');
153
+ throw new Error('removeAllListeners - Not implemented');
103
154
  },
104
155
  removeListener: () => {
105
- throw new Error('Not implemented');
156
+ throw new Error('removeListener - Not implemented');
106
157
  },
107
158
  send: () => {
108
- throw new Error('Not implemented');
159
+ throw new Error('send - Not implemented');
109
160
  },
110
161
  signAllTransactions,
111
162
  signAndSendTransaction,
@@ -0,0 +1,4 @@
1
+ import { Wallet } from '@wallet-standard/base';
2
+ import { ISolana } from '@dynamic-labs/solana-core';
3
+ import { InjectedWalletBase } from '../../InjectedWalletBase';
4
+ export declare const createSolanaSignerFromWalletStandard: (wallet: Wallet, walletConnector: InjectedWalletBase) => ISolana;
@@ -1,11 +1,38 @@
1
1
  'use client'
2
2
  import { __awaiter } from '../../../../_virtual/_tslib.js';
3
3
  import { PublicKey, VersionedTransaction, Transaction } from '@solana/web3.js';
4
- import { fetchCluster } from '../../../phantomRedirect/utils.js';
4
+ import { fetchCluster } from '../../../phantomRedirect/fetchCluster/fetchCluster.js';
5
+ import { logger } from '../../../utils/logger.js';
5
6
 
6
7
  const isVersionedTransaction = (transaction) => !('instructions' in transaction);
7
8
  const createSolanaSignerFromWalletStandard = (wallet, walletConnector) => {
8
9
  const features = wallet.features;
10
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
11
+ const connect = (args) => __awaiter(void 0, void 0, void 0, function* () {
12
+ var _a;
13
+ const connectMethod = (_a = features['standard:connect']) === null || _a === void 0 ? void 0 : _a.connect;
14
+ if (!connectMethod) {
15
+ logger.error('connect - Not implemented');
16
+ return;
17
+ }
18
+ const result = yield connectMethod({ silent: false });
19
+ if (!result.accounts[0]) {
20
+ return;
21
+ }
22
+ return {
23
+ address: result.accounts[0].address,
24
+ publicKey: result.accounts[0].publicKey,
25
+ };
26
+ });
27
+ const disconnect = () => __awaiter(void 0, void 0, void 0, function* () {
28
+ var _b;
29
+ const disconnectMethod = (_b = features['standard:disconnect']) === null || _b === void 0 ? void 0 : _b.disconnect;
30
+ if (!disconnectMethod) {
31
+ logger.debug('disconnect - Not implemented');
32
+ return;
33
+ }
34
+ yield disconnectMethod();
35
+ });
9
36
  const getCurrentAccount = () => __awaiter(void 0, void 0, void 0, function* () {
10
37
  const address = yield walletConnector.getAddress();
11
38
  const account = wallet.accounts.find((account) => account.address === address);
@@ -15,8 +42,8 @@ const createSolanaSignerFromWalletStandard = (wallet, walletConnector) => {
15
42
  return account;
16
43
  });
17
44
  const getChain = () => __awaiter(void 0, void 0, void 0, function* () {
18
- var _a, _b;
19
- const rpc = (_b = (_a = walletConnector.solNetworks[0].privateCustomerRpcUrls) === null || _a === void 0 ? void 0 : _a[0]) !== null && _b !== void 0 ? _b : walletConnector.solNetworks[0].rpcUrls[0];
45
+ var _c, _d;
46
+ const rpc = (_d = (_c = walletConnector.solNetworks[0].privateCustomerRpcUrls) === null || _c === void 0 ? void 0 : _c[0]) !== null && _d !== void 0 ? _d : walletConnector.solNetworks[0].rpcUrls[0];
20
47
  const cluster = yield fetchCluster(rpc);
21
48
  return `solana:${cluster}`;
22
49
  });
@@ -53,19 +80,39 @@ const createSolanaSignerFromWalletStandard = (wallet, walletConnector) => {
53
80
  });
54
81
  return { signature: messages[0].signature };
55
82
  });
83
+ const on = (event, listener) => {
84
+ var _a;
85
+ const onMethod = (_a = features['standard:events']) === null || _a === void 0 ? void 0 : _a.on;
86
+ if (!onMethod) {
87
+ logger.error('on - Not implemented');
88
+ return;
89
+ }
90
+ if (event !== 'accountChanged') {
91
+ logger.debug(`on - Not implemented for event: ${event}`);
92
+ return;
93
+ }
94
+ const wrappedListener = (prop) => {
95
+ var _a;
96
+ const publicKey = (_a = prop.accounts) === null || _a === void 0 ? void 0 : _a[0].publicKey;
97
+ if (publicKey) {
98
+ listener(new TextDecoder().decode(publicKey));
99
+ }
100
+ };
101
+ // 'change' is the only event that is supported by the wallet standard
102
+ return onMethod('change', wrappedListener);
103
+ };
56
104
  return {
57
105
  addListener: () => {
58
- throw new Error('Not implemented');
106
+ throw new Error('addListener - Not implemented');
59
107
  },
60
- connect: () => {
61
- throw new Error('Not implemented');
62
- },
63
- disconnect: () => walletConnector.endSession(),
108
+ connect,
109
+ disconnect,
64
110
  emit: () => {
65
- throw new Error('Not implemented');
111
+ throw new Error('emit - Not implemented');
66
112
  },
67
113
  eventNames: () => {
68
- throw new Error('Not implemented');
114
+ logger.error('eventNames - Not implemented');
115
+ return [];
69
116
  },
70
117
  isBackpack: false,
71
118
  isBraveWallet: false,
@@ -76,32 +123,36 @@ const createSolanaSignerFromWalletStandard = (wallet, walletConnector) => {
76
123
  isPhantom: false,
77
124
  isSolflare: false,
78
125
  listenerCount: () => {
79
- throw new Error('Not implemented');
126
+ logger.error('listenerCount - Not implemented');
127
+ return 0;
80
128
  },
81
129
  listeners: () => {
82
- throw new Error('Not implemented');
130
+ logger.error('listeners - Not implemented');
131
+ return [];
83
132
  },
84
133
  off: () => {
85
- throw new Error('Not implemented');
86
- },
87
- on: () => {
88
- throw new Error('Not implemented');
134
+ throw new Error('off - Not implemented');
89
135
  },
136
+ on,
90
137
  once: () => {
91
- throw new Error('Not implemented');
138
+ throw new Error('once - Not implemented');
92
139
  },
93
140
  providers: [],
94
141
  get publicKey() {
142
+ var _a;
143
+ if (!((_a = wallet.accounts) === null || _a === void 0 ? void 0 : _a[0].publicKey)) {
144
+ return undefined;
145
+ }
95
146
  return new PublicKey(wallet.accounts[0].publicKey);
96
147
  },
97
148
  removeAllListeners: () => {
98
- throw new Error('Not implemented');
149
+ throw new Error('removeAllListeners - Not implemented');
99
150
  },
100
151
  removeListener: () => {
101
- throw new Error('Not implemented');
152
+ throw new Error('removeListener - Not implemented');
102
153
  },
103
154
  send: () => {
104
- throw new Error('Not implemented');
155
+ throw new Error('send - Not implemented');
105
156
  },
106
157
  signAllTransactions,
107
158
  signAndSendTransaction,
@@ -0,0 +1,29 @@
1
+ 'use client'
2
+ 'use strict';
3
+
4
+ Object.defineProperty(exports, '__esModule', { value: true });
5
+
6
+ var utils = require('@dynamic-labs/utils');
7
+ var InjectedWalletBase = require('../../InjectedWalletBase/InjectedWalletBase.cjs');
8
+ var createSolanaSignerFromWalletStandard = require('../createSolanaSignerFromWalletStandard/createSolanaSignerFromWalletStandard.cjs');
9
+
10
+ const getConnectorConstructorForWalletStandardWallet = (wallet) => {
11
+ const sanitizedName = utils.sanitizeName(wallet.name);
12
+ return class extends InjectedWalletBase.InjectedWalletBase {
13
+ constructor(props) {
14
+ super(Object.assign(Object.assign({}, props), { metadata: {
15
+ groupKey: sanitizedName,
16
+ icon: wallet.icon,
17
+ id: sanitizedName,
18
+ name: wallet.name,
19
+ } }));
20
+ this.name = wallet.name;
21
+ this.overrideKey = `${sanitizedName}sol`;
22
+ }
23
+ findProvider() {
24
+ return createSolanaSignerFromWalletStandard.createSolanaSignerFromWalletStandard(wallet, this);
25
+ }
26
+ };
27
+ };
28
+
29
+ exports.getConnectorConstructorForWalletStandardWallet = getConnectorConstructorForWalletStandardWallet;
@@ -0,0 +1,3 @@
1
+ import { Wallet } from '@wallet-standard/base';
2
+ import { WalletConnectorConstructor } from '@dynamic-labs/wallet-connector-core';
3
+ export declare const getConnectorConstructorForWalletStandardWallet: (wallet: Wallet) => WalletConnectorConstructor;
@@ -0,0 +1,25 @@
1
+ 'use client'
2
+ import { sanitizeName } from '@dynamic-labs/utils';
3
+ import { InjectedWalletBase } from '../../InjectedWalletBase/InjectedWalletBase.js';
4
+ import { createSolanaSignerFromWalletStandard } from '../createSolanaSignerFromWalletStandard/createSolanaSignerFromWalletStandard.js';
5
+
6
+ const getConnectorConstructorForWalletStandardWallet = (wallet) => {
7
+ const sanitizedName = sanitizeName(wallet.name);
8
+ return class extends InjectedWalletBase {
9
+ constructor(props) {
10
+ super(Object.assign(Object.assign({}, props), { metadata: {
11
+ groupKey: sanitizedName,
12
+ icon: wallet.icon,
13
+ id: sanitizedName,
14
+ name: wallet.name,
15
+ } }));
16
+ this.name = wallet.name;
17
+ this.overrideKey = `${sanitizedName}sol`;
18
+ }
19
+ findProvider() {
20
+ return createSolanaSignerFromWalletStandard(wallet, this);
21
+ }
22
+ };
23
+ };
24
+
25
+ export { getConnectorConstructorForWalletStandardWallet };
@@ -0,0 +1 @@
1
+ export { getConnectorConstructorForWalletStandardWallet } from './getConnectorConstructorForWalletStandardWallet';
@@ -0,0 +1,10 @@
1
+ 'use client'
2
+ 'use strict';
3
+
4
+ Object.defineProperty(exports, '__esModule', { value: true });
5
+
6
+ var app = require('@wallet-standard/app');
7
+
8
+ const getWalletStandardWallets = () => app.getWallets().get();
9
+
10
+ exports.getWalletStandardWallets = getWalletStandardWallets;
@@ -0,0 +1 @@
1
+ export declare const getWalletStandardWallets: () => readonly import("@wallet-standard/base").Wallet[];
@@ -0,0 +1,6 @@
1
+ 'use client'
2
+ import { getWallets } from '@wallet-standard/app';
3
+
4
+ const getWalletStandardWallets = () => getWallets().get();
5
+
6
+ export { getWalletStandardWallets };
@@ -0,0 +1 @@
1
+ export { getWalletStandardWallets } from './getWalletStandardWallets';