@dynamic-labs/solana 4.0.0-alpha.9 → 4.0.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 +483 -1
- package/package.cjs +1 -1
- package/package.js +1 -1
- package/package.json +11 -11
- package/src/{CoinbaseSolana.cjs → CoinbaseSolana/CoinbaseSolana.cjs} +6 -9
- package/src/{CoinbaseSolana.d.ts → CoinbaseSolana/CoinbaseSolana.d.ts} +1 -3
- package/src/{CoinbaseSolana.js → CoinbaseSolana/CoinbaseSolana.js} +6 -9
- package/src/CoinbaseSolana/index.d.ts +1 -0
- package/src/{Phantom.cjs → Phantom/Phantom.cjs} +7 -9
- package/src/Phantom/Phantom.d.ts +9 -0
- package/src/{Phantom.js → Phantom/Phantom.js} +7 -9
- package/src/Phantom/index.d.ts +1 -0
- package/src/{solProviderHelper.cjs → SolProviderHelper/SolProviderHelper.cjs} +33 -22
- package/src/{solProviderHelper.d.ts → SolProviderHelper/SolProviderHelper.d.ts} +6 -5
- package/src/{solProviderHelper.js → SolProviderHelper/SolProviderHelper.js} +33 -22
- package/src/SolProviderHelper/index.d.ts +1 -0
- package/src/SolanaWalletConnectors.cjs +21 -0
- package/src/SolanaWalletConnectors.d.ts +2 -0
- package/src/SolanaWalletConnectors.js +17 -0
- package/src/SolanaWalletConnectorsWithConfig/SolanaWalletConnectorsWithConfig.cjs +26 -0
- package/src/SolanaWalletConnectorsWithConfig/SolanaWalletConnectorsWithConfig.d.ts +6 -0
- package/src/SolanaWalletConnectorsWithConfig/SolanaWalletConnectorsWithConfig.js +22 -0
- package/src/SolanaWalletConnectorsWithConfig/index.d.ts +1 -0
- package/src/{Solflare.cjs → Solflare/Solflare.cjs} +9 -10
- package/src/{Solflare.d.ts → Solflare/Solflare.d.ts} +1 -3
- package/src/{Solflare.js → Solflare/Solflare.js} +9 -10
- package/src/Solflare/index.d.ts +1 -0
- package/src/index.cjs +16 -18
- package/src/index.d.ts +7 -5
- package/src/index.js +6 -17
- package/src/injected/{BackpackSol.cjs → BackpackSol/BackpackSol.cjs} +5 -7
- package/src/injected/{BackpackSol.d.ts → BackpackSol/BackpackSol.d.ts} +1 -3
- package/src/injected/{BackpackSol.js → BackpackSol/BackpackSol.js} +5 -7
- package/src/injected/BackpackSol/index.d.ts +1 -0
- package/src/injected/{FallbackSolanaConnector.cjs → FallbackSolanaConnector/FallbackSolanaConnector.cjs} +3 -5
- package/src/injected/{FallbackSolanaConnector.d.ts → FallbackSolanaConnector/FallbackSolanaConnector.d.ts} +1 -3
- package/src/injected/{FallbackSolanaConnector.js → FallbackSolanaConnector/FallbackSolanaConnector.js} +3 -5
- package/src/injected/FallbackSolanaConnector/index.d.ts +1 -0
- package/src/injected/{InjectedWalletBase.cjs → InjectedWalletBase/InjectedWalletBase.cjs} +23 -27
- package/src/injected/{InjectedWalletBase.d.ts → InjectedWalletBase/InjectedWalletBase.d.ts} +6 -8
- package/src/injected/{InjectedWalletBase.js → InjectedWalletBase/InjectedWalletBase.js} +24 -28
- package/src/injected/InjectedWalletBase/index.d.ts +1 -0
- package/src/injected/{PhantomInjected.cjs → PhantomInjected/PhantomInjected.cjs} +5 -7
- package/src/injected/{PhantomInjected.d.ts → PhantomInjected/PhantomInjected.d.ts} +1 -3
- package/src/injected/{PhantomInjected.js → PhantomInjected/PhantomInjected.js} +5 -7
- package/src/injected/PhantomInjected/index.d.ts +1 -0
- package/src/injected/fetchInjectedWalletConnectors.cjs +55 -27
- package/src/injected/fetchInjectedWalletConnectors.js +55 -27
- package/src/injected/index.d.ts +0 -1
- package/src/{SolanaWalletStandardConnector/utils → injected/walletStandard}/createSolanaSignerFromWalletStandard/createSolanaSignerFromWalletStandard.cjs +70 -19
- package/src/injected/walletStandard/createSolanaSignerFromWalletStandard/createSolanaSignerFromWalletStandard.d.ts +4 -0
- package/src/{SolanaWalletStandardConnector/utils → injected/walletStandard}/createSolanaSignerFromWalletStandard/createSolanaSignerFromWalletStandard.js +70 -19
- package/src/injected/walletStandard/getConnectorConstructorForWalletStandardWallet/getConnectorConstructorForWalletStandardWallet.cjs +29 -0
- package/src/injected/walletStandard/getConnectorConstructorForWalletStandardWallet/getConnectorConstructorForWalletStandardWallet.d.ts +3 -0
- package/src/injected/walletStandard/getConnectorConstructorForWalletStandardWallet/getConnectorConstructorForWalletStandardWallet.js +25 -0
- package/src/injected/walletStandard/getConnectorConstructorForWalletStandardWallet/index.d.ts +1 -0
- package/src/injected/walletStandard/getWalletStandardWallets/getWalletStandardWallets.cjs +10 -0
- package/src/injected/walletStandard/getWalletStandardWallets/getWalletStandardWallets.d.ts +1 -0
- package/src/injected/walletStandard/getWalletStandardWallets/getWalletStandardWallets.js +6 -0
- package/src/injected/walletStandard/getWalletStandardWallets/index.d.ts +1 -0
- package/src/phantomRedirect/PhantomRedirect/PhantomRedirect.cjs +1 -1
- package/src/phantomRedirect/PhantomRedirect/PhantomRedirect.d.ts +2 -2
- package/src/phantomRedirect/PhantomRedirect/PhantomRedirect.js +2 -2
- package/src/Phantom.d.ts +0 -12
- package/src/SolanaWalletStandardConnector/SolanaWalletStandardConnector.cjs +0 -100
- package/src/SolanaWalletStandardConnector/SolanaWalletStandardConnector.d.ts +0 -20
- package/src/SolanaWalletStandardConnector/SolanaWalletStandardConnector.js +0 -96
- package/src/SolanaWalletStandardConnector/index.d.ts +0 -1
- package/src/SolanaWalletStandardConnector/utils/createSolanaSignerFromWalletStandard/createSolanaSignerFromWalletStandard.d.ts +0 -3
- package/src/injected/UnknownInjected.cjs +0 -21
- package/src/injected/UnknownInjected.d.ts +0 -8
- package/src/injected/UnknownInjected.js +0 -17
- /package/src/{SolanaWalletStandardConnector/utils → injected/walletStandard}/createSolanaSignerFromWalletStandard/index.d.ts +0 -0
- /package/src/{utils → injected/walletStandard}/findWalletProviderFromWalletStandard/findWalletProviderFromWalletStandard.cjs +0 -0
- /package/src/{utils → injected/walletStandard}/findWalletProviderFromWalletStandard/findWalletProviderFromWalletStandard.d.ts +0 -0
- /package/src/{utils → injected/walletStandard}/findWalletProviderFromWalletStandard/findWalletProviderFromWalletStandard.js +0 -0
- /package/src/{utils → injected/walletStandard}/findWalletProviderFromWalletStandard/index.d.ts +0 -0
|
@@ -1,58 +1,86 @@
|
|
|
1
1
|
'use client'
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
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
|
|
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 shouldHandleWalletFromWalletBook = ([key, wallet]) => {
|
|
30
|
+
var _a, _b, _c, _d, _e, _f;
|
|
31
|
+
const hasMatchingKey = key === connectorKey;
|
|
32
|
+
const needsCustomConnector = walletsWithCustomConnectors.includes(connectorKey);
|
|
33
|
+
const hasMatchingNameAndChain = wallet.name === name && ((_b = (_a = wallet.injectedConfig) === null || _a === void 0 ? void 0 : _a[0]) === null || _b === void 0 ? void 0 : _b.chain) === chain;
|
|
34
|
+
// if the wallet supports wallet standard, we want to add the wallet standard connector
|
|
35
|
+
// and not handle it as a default wallet-book wallet
|
|
36
|
+
const isNotWalletStandard = !((_f = (_e = (_d = (_c = wallet.injectedConfig) === null || _c === void 0 ? void 0 : _c[0]) === null || _d === void 0 ? void 0 : _d.walletStandard) === null || _e === void 0 ? void 0 : _e.features) === null || _f === void 0 ? void 0 : _f.length);
|
|
37
|
+
return ((hasMatchingKey || needsCustomConnector || hasMatchingNameAndChain) &&
|
|
38
|
+
isNotWalletStandard);
|
|
39
|
+
};
|
|
40
|
+
const shouldHandleFromWalletBook = Object.entries((_a = walletBook === null || walletBook === void 0 ? void 0 : walletBook.wallets) !== null && _a !== void 0 ? _a : {}).find(shouldHandleWalletFromWalletBook);
|
|
41
|
+
const hasAllFeatures = Boolean(((_b = wallet.features) === null || _b === void 0 ? void 0 : _b['standard:events']) &&
|
|
42
|
+
((_c = wallet.features) === null || _c === void 0 ? void 0 : _c['standard:connect']) &&
|
|
43
|
+
((_d = wallet.features) === null || _d === void 0 ? void 0 : _d['solana:signMessage']) &&
|
|
44
|
+
((_e = wallet.features) === null || _e === void 0 ? void 0 : _e['solana:signTransaction']) &&
|
|
45
|
+
((_f = wallet.features) === null || _f === void 0 ? void 0 : _f['solana:signAndSendTransaction']));
|
|
46
|
+
logger.logVerboseTroubleshootingMessage('[SOL shouldAddWalletStandardConnector]', {
|
|
47
|
+
hasAllFeatures,
|
|
48
|
+
shouldAdd: !shouldHandleFromWalletBook && hasAllFeatures,
|
|
49
|
+
shouldHandleFromWalletBook,
|
|
50
|
+
});
|
|
51
|
+
return !shouldHandleFromWalletBook && hasAllFeatures;
|
|
52
|
+
};
|
|
20
53
|
const fetchInjectedWalletConnectors = ({ walletBook, }) => {
|
|
21
54
|
var _a;
|
|
22
|
-
|
|
55
|
+
const walletBookConnectors = Object.entries((_a = walletBook === null || walletBook === void 0 ? void 0 : walletBook.wallets) !== null && _a !== void 0 ? _a : {})
|
|
23
56
|
.filter(([key, wallet]) => {
|
|
24
|
-
var _a;
|
|
25
|
-
const
|
|
26
|
-
const
|
|
57
|
+
var _a, _b, _c;
|
|
58
|
+
const injectedConfig = (_a = wallet.injectedConfig) === null || _a === void 0 ? void 0 : _a.find((config) => config.chain === 'sol');
|
|
59
|
+
const isSolanaWallet = Boolean(injectedConfig);
|
|
60
|
+
// should filter out wallets that require a custom connector or wallets that support wallet standard,
|
|
61
|
+
// since they are already handled automatically with the wallet standard connector
|
|
62
|
+
const shouldBeFiltered = walletsWithCustomConnectors.includes(key) ||
|
|
63
|
+
((_c = (_b = injectedConfig === null || injectedConfig === void 0 ? void 0 : injectedConfig.walletStandard) === null || _b === void 0 ? void 0 : _b.features) === null || _c === void 0 ? void 0 : _c.length);
|
|
27
64
|
return isSolanaWallet && !shouldBeFiltered;
|
|
28
65
|
})
|
|
29
66
|
.map(([key, wallet]) => {
|
|
30
|
-
var _a;
|
|
31
67
|
const { shortName } = wallet;
|
|
32
68
|
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
69
|
return class extends InjectedWalletBase {
|
|
47
|
-
constructor(
|
|
48
|
-
super(
|
|
70
|
+
constructor() {
|
|
71
|
+
super(...arguments);
|
|
49
72
|
this.name = name;
|
|
50
|
-
this.wallet = wallet;
|
|
51
73
|
// this is the key from the wallet book entry so that we don't purely rely on the normalized name
|
|
52
74
|
this.overrideKey = key;
|
|
53
75
|
}
|
|
54
76
|
};
|
|
55
77
|
});
|
|
78
|
+
const walletStandardWallets = getWalletStandardWallets();
|
|
79
|
+
const walletStandardConnectors = walletStandardWallets
|
|
80
|
+
.filter((wallet) => shouldAddWalletStandardConnector(wallet, walletBook))
|
|
81
|
+
.map((wallet) => getConnectorConstructorForWalletStandardWallet(wallet));
|
|
82
|
+
logger.logVerboseTroubleshootingMessage('[SOL fetchInjectedWalletConnectors] walletStandardConnectors', walletStandardConnectors.map((w) => w.name));
|
|
83
|
+
return [...walletBookConnectors, ...walletStandardConnectors];
|
|
56
84
|
};
|
|
57
85
|
|
|
58
86
|
export { fetchInjectedWalletConnectors, injectedWalletOverrides };
|
package/src/injected/index.d.ts
CHANGED
|
@@ -6,10 +6,37 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
6
6
|
var _tslib = require('../../../../_virtual/_tslib.cjs');
|
|
7
7
|
var web3_js = require('@solana/web3.js');
|
|
8
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,8 +46,8 @@ 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
|
|
23
|
-
const 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];
|
|
24
51
|
const cluster = yield fetchCluster.fetchCluster(rpc);
|
|
25
52
|
return `solana:${cluster}`;
|
|
26
53
|
});
|
|
@@ -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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
130
|
+
logger.logger.error('listenerCount - Not implemented');
|
|
131
|
+
return 0;
|
|
84
132
|
},
|
|
85
133
|
listeners: () => {
|
|
86
|
-
|
|
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;
|
|
@@ -2,10 +2,37 @@
|
|
|
2
2
|
import { __awaiter } from '../../../../_virtual/_tslib.js';
|
|
3
3
|
import { PublicKey, VersionedTransaction, Transaction } from '@solana/web3.js';
|
|
4
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
|
|
19
|
-
const rpc = (
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
126
|
+
logger.error('listenerCount - Not implemented');
|
|
127
|
+
return 0;
|
|
80
128
|
},
|
|
81
129
|
listeners: () => {
|
|
82
|
-
|
|
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,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 @@
|
|
|
1
|
+
export { getWalletStandardWallets } from './getWalletStandardWallets';
|
|
@@ -19,7 +19,7 @@ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'defau
|
|
|
19
19
|
var bs58__default = /*#__PURE__*/_interopDefaultLegacy(bs58);
|
|
20
20
|
var nacl__default = /*#__PURE__*/_interopDefaultLegacy(nacl);
|
|
21
21
|
|
|
22
|
-
class PhantomRedirect extends solanaCore.
|
|
22
|
+
class PhantomRedirect extends solanaCore.SolanaWalletConnector {
|
|
23
23
|
constructor(props) {
|
|
24
24
|
super(Object.assign({}, props));
|
|
25
25
|
this.name = 'Phantom';
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { Transaction } from '@solana/web3.js';
|
|
2
|
-
import {
|
|
2
|
+
import { SolanaWalletConnector, type ISolana } from '@dynamic-labs/solana-core';
|
|
3
3
|
import { IPhantomRedirectConnector } from '@dynamic-labs/wallet-connector-core';
|
|
4
4
|
import { Method } from '../types';
|
|
5
|
-
export declare class PhantomRedirect extends
|
|
5
|
+
export declare class PhantomRedirect extends SolanaWalletConnector implements IPhantomRedirectConnector {
|
|
6
6
|
name: string;
|
|
7
7
|
overrideKey: string;
|
|
8
8
|
constructor(props: any);
|
|
@@ -3,14 +3,14 @@ import { __awaiter } from '../../../_virtual/_tslib.js';
|
|
|
3
3
|
import { PublicKey, Transaction } from '@solana/web3.js';
|
|
4
4
|
import bs58 from 'bs58';
|
|
5
5
|
import nacl from 'tweetnacl';
|
|
6
|
-
import {
|
|
6
|
+
import { SolanaWalletConnector } from '@dynamic-labs/solana-core';
|
|
7
7
|
import { buildUrl } from '../buildUrl/buildUrl.js';
|
|
8
8
|
import { decryptPayload } from '../decryptPayload/decryptPayload.js';
|
|
9
9
|
import { encryptPayload } from '../encryptPayload/encryptPayload.js';
|
|
10
10
|
import { fetchCluster } from '../fetchCluster/fetchCluster.js';
|
|
11
11
|
import { storage, clearStorage } from '../storage/storage.js';
|
|
12
12
|
|
|
13
|
-
class PhantomRedirect extends
|
|
13
|
+
class PhantomRedirect extends SolanaWalletConnector {
|
|
14
14
|
constructor(props) {
|
|
15
15
|
super(Object.assign({}, props));
|
|
16
16
|
this.name = 'Phantom';
|
package/src/Phantom.d.ts
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { WalletSchema } from '@dynamic-labs/wallet-book';
|
|
2
|
-
import { WalletConnectorCore } from '@dynamic-labs/wallet-connector-core';
|
|
3
|
-
import { SolWalletConnector, SolWalletConnectorOpts, type ISolana } from '@dynamic-labs/solana-core';
|
|
4
|
-
export declare class Phantom extends SolWalletConnector {
|
|
5
|
-
name: string;
|
|
6
|
-
overrideKey: string;
|
|
7
|
-
wallet: WalletSchema | undefined;
|
|
8
|
-
constructor(opts: SolWalletConnectorOpts);
|
|
9
|
-
connect(): Promise<void>;
|
|
10
|
-
getSigner(): Promise<ISolana | undefined>;
|
|
11
|
-
getMobileOrInstalledWallet(): WalletConnectorCore.WalletConnector;
|
|
12
|
-
}
|
|
@@ -1,100 +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 app = require('@wallet-standard/app');
|
|
8
|
-
var solanaCore = require('@dynamic-labs/solana-core');
|
|
9
|
-
var createSolanaSignerFromWalletStandard = require('./utils/createSolanaSignerFromWalletStandard/createSolanaSignerFromWalletStandard.cjs');
|
|
10
|
-
|
|
11
|
-
const encoder = new TextEncoder();
|
|
12
|
-
class SolanaWalletStandardConnector extends solanaCore.SolWalletConnector {
|
|
13
|
-
constructor(props) {
|
|
14
|
-
super(props);
|
|
15
|
-
this.connectedChain = 'SOL';
|
|
16
|
-
this.supportedChains = ['SOL'];
|
|
17
|
-
}
|
|
18
|
-
get wallet() {
|
|
19
|
-
const walletStandard = SolanaWalletStandardConnector.getWallet(this.walletBook, this.key);
|
|
20
|
-
if (!walletStandard) {
|
|
21
|
-
throw new Error('Wallet not found');
|
|
22
|
-
}
|
|
23
|
-
return walletStandard;
|
|
24
|
-
}
|
|
25
|
-
get walletFeatures() {
|
|
26
|
-
return this.wallet.features;
|
|
27
|
-
}
|
|
28
|
-
connect() {
|
|
29
|
-
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
30
|
-
yield this.walletFeatures['standard:connect'].connect();
|
|
31
|
-
});
|
|
32
|
-
}
|
|
33
|
-
endSession() {
|
|
34
|
-
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
35
|
-
yield this.walletFeatures['standard:disconnect'].disconnect();
|
|
36
|
-
});
|
|
37
|
-
}
|
|
38
|
-
isInstalledOnBrowser() {
|
|
39
|
-
return true;
|
|
40
|
-
}
|
|
41
|
-
getAddress() {
|
|
42
|
-
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
43
|
-
yield this.connect();
|
|
44
|
-
const [address] = yield this.getConnectedAccounts();
|
|
45
|
-
return address;
|
|
46
|
-
});
|
|
47
|
-
}
|
|
48
|
-
getConnectedAccounts() {
|
|
49
|
-
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
50
|
-
const addresses = this.wallet.accounts.map((account) => account.address);
|
|
51
|
-
return addresses;
|
|
52
|
-
});
|
|
53
|
-
}
|
|
54
|
-
signMessage(messageToSign) {
|
|
55
|
-
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
56
|
-
const signer = yield this.getSigner();
|
|
57
|
-
if (!signer) {
|
|
58
|
-
throw new Error('Signer not found');
|
|
59
|
-
}
|
|
60
|
-
const message = encoder.encode(messageToSign);
|
|
61
|
-
const { signature } = yield signer.signMessage(message);
|
|
62
|
-
if (!(signature instanceof Uint8Array)) {
|
|
63
|
-
throw new Error('Signature not found');
|
|
64
|
-
}
|
|
65
|
-
return Buffer.from(signature).toString('base64');
|
|
66
|
-
});
|
|
67
|
-
}
|
|
68
|
-
getSigner() {
|
|
69
|
-
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
70
|
-
const { wallet } = this;
|
|
71
|
-
return createSolanaSignerFromWalletStandard.createSolanaSignerFromWalletStandard(wallet, this);
|
|
72
|
-
});
|
|
73
|
-
}
|
|
74
|
-
static getWallet(walletBook, walletKey) {
|
|
75
|
-
var _a, _b;
|
|
76
|
-
const wallets = app.getWallets().get();
|
|
77
|
-
const injectedConfig = (_a = walletBook.wallets[walletKey].injectedConfig) === null || _a === void 0 ? void 0 : _a.find((config) => config.chain === 'sol');
|
|
78
|
-
if (!injectedConfig)
|
|
79
|
-
return;
|
|
80
|
-
const { features } = (_b = injectedConfig.walletStandard) !== null && _b !== void 0 ? _b : {};
|
|
81
|
-
if (!features)
|
|
82
|
-
return;
|
|
83
|
-
const wallet = wallets.find((wallet) => {
|
|
84
|
-
var _a;
|
|
85
|
-
const isNameMatch = wallet.name === ((_a = injectedConfig.walletStandard) === null || _a === void 0 ? void 0 : _a.name);
|
|
86
|
-
if (!isNameMatch)
|
|
87
|
-
return false;
|
|
88
|
-
const hasFeatures = features.reduce((hasAllFeatures, key) => {
|
|
89
|
-
const walletFeatures = Object.keys(wallet.features);
|
|
90
|
-
if (!hasAllFeatures)
|
|
91
|
-
return false;
|
|
92
|
-
return walletFeatures.includes(key);
|
|
93
|
-
}, true);
|
|
94
|
-
return hasFeatures;
|
|
95
|
-
});
|
|
96
|
-
return wallet;
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
exports.SolanaWalletStandardConnector = SolanaWalletStandardConnector;
|