@dynamic-labs/solana 4.0.0-alpha.5 → 4.0.0-alpha.50
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 +460 -0
- package/package.cjs +8 -0
- package/package.js +4 -0
- package/package.json +12 -18
- package/src/{CoinbaseSolana.cjs → CoinbaseSolana/CoinbaseSolana.cjs} +6 -14
- package/src/{CoinbaseSolana.d.ts → CoinbaseSolana/CoinbaseSolana.d.ts} +1 -3
- package/src/{CoinbaseSolana.js → CoinbaseSolana/CoinbaseSolana.js} +6 -14
- 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 +19 -18
- package/src/index.d.ts +7 -5
- package/src/index.js +9 -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 +43 -25
- package/src/injected/fetchInjectedWalletConnectors.js +43 -25
- package/src/injected/index.d.ts +0 -1
- package/src/{SolanaWalletStandardConnector/utils → injected/walletStandard}/createSolanaSignerFromWalletStandard/createSolanaSignerFromWalletStandard.cjs +72 -21
- package/src/injected/walletStandard/createSolanaSignerFromWalletStandard/createSolanaSignerFromWalletStandard.d.ts +4 -0
- package/src/{SolanaWalletStandardConnector/utils → injected/walletStandard}/createSolanaSignerFromWalletStandard/createSolanaSignerFromWalletStandard.js +71 -20
- 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.cjs → PhantomRedirect/PhantomRedirect.cjs} +28 -25
- package/src/phantomRedirect/{PhantomRedirect.d.ts → PhantomRedirect/PhantomRedirect.d.ts} +3 -3
- package/src/phantomRedirect/{PhantomRedirect.js → PhantomRedirect/PhantomRedirect.js} +10 -7
- package/src/phantomRedirect/PhantomRedirect/index.d.ts +1 -0
- package/src/phantomRedirect/buildUrl/buildUrl.cjs +8 -0
- package/src/phantomRedirect/buildUrl/buildUrl.d.ts +1 -0
- package/src/phantomRedirect/buildUrl/buildUrl.js +4 -0
- package/src/phantomRedirect/buildUrl/index.d.ts +1 -0
- package/src/phantomRedirect/decryptPayload/decryptPayload.cjs +34 -0
- package/src/phantomRedirect/decryptPayload/decryptPayload.d.ts +1 -0
- package/src/phantomRedirect/decryptPayload/decryptPayload.js +25 -0
- package/src/phantomRedirect/decryptPayload/index.d.ts +1 -0
- package/src/phantomRedirect/encryptPayload/encryptPayload.cjs +18 -0
- package/src/phantomRedirect/encryptPayload/encryptPayload.d.ts +1 -0
- package/src/phantomRedirect/encryptPayload/encryptPayload.js +10 -0
- package/src/phantomRedirect/encryptPayload/index.d.ts +1 -0
- package/src/phantomRedirect/fetchCluster/fetchCluster.cjs +33 -0
- package/src/phantomRedirect/fetchCluster/fetchCluster.d.ts +1 -0
- package/src/phantomRedirect/fetchCluster/fetchCluster.js +29 -0
- package/src/phantomRedirect/fetchCluster/index.d.ts +1 -0
- package/src/phantomRedirect/storage/index.d.ts +1 -0
- package/src/phantomRedirect/{storage.d.ts → storage/storage.d.ts} +1 -1
- package/src/utils/logger.cjs +10 -0
- package/src/utils/logger.d.ts +2 -0
- package/src/utils/logger.js +6 -0
- 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/phantomRedirect/utils.cjs +0 -56
- package/src/phantomRedirect/utils.d.ts +0 -4
- package/src/phantomRedirect/utils.js +0 -44
- /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
- /package/src/phantomRedirect/{storage.cjs → storage/storage.cjs} +0 -0
- /package/src/phantomRedirect/{storage.js → storage/storage.js} +0 -0
|
@@ -3,20 +3,23 @@
|
|
|
3
3
|
|
|
4
4
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
5
5
|
|
|
6
|
-
var _tslib = require('
|
|
7
|
-
var nacl = require('tweetnacl');
|
|
8
|
-
var bs58 = require('bs58');
|
|
6
|
+
var _tslib = require('../../../_virtual/_tslib.cjs');
|
|
9
7
|
var web3_js = require('@solana/web3.js');
|
|
8
|
+
var bs58 = require('bs58');
|
|
9
|
+
var nacl = require('tweetnacl');
|
|
10
10
|
var solanaCore = require('@dynamic-labs/solana-core');
|
|
11
|
-
var
|
|
12
|
-
var
|
|
11
|
+
var buildUrl = require('../buildUrl/buildUrl.cjs');
|
|
12
|
+
var decryptPayload = require('../decryptPayload/decryptPayload.cjs');
|
|
13
|
+
var encryptPayload = require('../encryptPayload/encryptPayload.cjs');
|
|
14
|
+
var fetchCluster = require('../fetchCluster/fetchCluster.cjs');
|
|
15
|
+
var storage = require('../storage/storage.cjs');
|
|
13
16
|
|
|
14
17
|
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
15
18
|
|
|
16
|
-
var nacl__default = /*#__PURE__*/_interopDefaultLegacy(nacl);
|
|
17
19
|
var bs58__default = /*#__PURE__*/_interopDefaultLegacy(bs58);
|
|
20
|
+
var nacl__default = /*#__PURE__*/_interopDefaultLegacy(nacl);
|
|
18
21
|
|
|
19
|
-
class PhantomRedirect extends solanaCore.
|
|
22
|
+
class PhantomRedirect extends solanaCore.SolanaWalletConnector {
|
|
20
23
|
constructor(props) {
|
|
21
24
|
super(Object.assign({}, props));
|
|
22
25
|
this.name = 'Phantom';
|
|
@@ -48,11 +51,11 @@ class PhantomRedirect extends solanaCore.SolWalletConnector {
|
|
|
48
51
|
const rpc = (_b = (_a = this.solNetworks[0].privateCustomerRpcUrls) === null || _a === void 0 ? void 0 : _a[0]) !== null && _b !== void 0 ? _b : this.solNetworks[0].rpcUrls[0];
|
|
49
52
|
const params = new URLSearchParams({
|
|
50
53
|
app_url: isLocalHost ? 'https://demo.dynamic.xyz' : window.location.href,
|
|
51
|
-
cluster: yield
|
|
54
|
+
cluster: yield fetchCluster.fetchCluster(rpc),
|
|
52
55
|
dapp_encryption_public_key: bs58__default["default"].encode(keyPair.publicKey),
|
|
53
56
|
redirect_link: window.location.href,
|
|
54
57
|
});
|
|
55
|
-
const url =
|
|
58
|
+
const url = buildUrl.buildUrl('connect', params);
|
|
56
59
|
window.location.href = url;
|
|
57
60
|
});
|
|
58
61
|
}
|
|
@@ -62,7 +65,7 @@ class PhantomRedirect extends solanaCore.SolWalletConnector {
|
|
|
62
65
|
const { data, nonce, phantom_encryption_public_key: phantomEncryptionPublicKey, encryptionSecretKey, } = this.getInputsOrThrow('getSession', ['data', 'nonce', 'phantom_encryption_public_key'], ['encryptionSecretKey']);
|
|
63
66
|
const sharedSecret = nacl__default["default"].box.before(bs58__default["default"].decode(phantomEncryptionPublicKey), encryptionSecretKey);
|
|
64
67
|
storage.storage.sharedSecret.set(sharedSecret);
|
|
65
|
-
const connectData =
|
|
68
|
+
const connectData = decryptPayload.decryptPayload(data, nonce, sharedSecret);
|
|
66
69
|
storage.storage.session.set(connectData.session);
|
|
67
70
|
storage.storage.address.set(new web3_js.PublicKey(connectData.public_key));
|
|
68
71
|
params.delete('phantom_encryption_public_key');
|
|
@@ -80,14 +83,14 @@ class PhantomRedirect extends solanaCore.SolWalletConnector {
|
|
|
80
83
|
message: bs58__default["default"].encode(Buffer.from(messageToSign)),
|
|
81
84
|
session,
|
|
82
85
|
};
|
|
83
|
-
const [nonce, encryptedPayload] =
|
|
86
|
+
const [nonce, encryptedPayload] = encryptPayload.encryptPayload(payload, sharedSecret);
|
|
84
87
|
const params = new URLSearchParams({
|
|
85
88
|
dapp_encryption_public_key: bs58__default["default"].encode(encryptionPublicKey),
|
|
86
89
|
nonce: bs58__default["default"].encode(nonce),
|
|
87
90
|
payload: bs58__default["default"].encode(encryptedPayload),
|
|
88
91
|
redirect_link: window.location.href,
|
|
89
92
|
});
|
|
90
|
-
const url =
|
|
93
|
+
const url = buildUrl.buildUrl('signMessage', params);
|
|
91
94
|
storage.storage.method.set('signMessage');
|
|
92
95
|
window.location.href = url;
|
|
93
96
|
// throwing this to prevent local storage from being cleared.
|
|
@@ -104,7 +107,7 @@ class PhantomRedirect extends solanaCore.SolWalletConnector {
|
|
|
104
107
|
extractSignature() {
|
|
105
108
|
const params = new URLSearchParams(window.location.search);
|
|
106
109
|
const { data, nonce, sharedSecret, message } = this.getInputsOrThrow('extractSignature', ['data', 'nonce'], ['sharedSecret', 'message']);
|
|
107
|
-
const signMessageData =
|
|
110
|
+
const signMessageData = decryptPayload.decryptPayload(data, nonce, sharedSecret);
|
|
108
111
|
params.delete('data');
|
|
109
112
|
params.delete('nonce');
|
|
110
113
|
history.replaceState(null, '', `${window.location.origin}${window.location.pathname}?${params.toString()}`);
|
|
@@ -116,7 +119,7 @@ class PhantomRedirect extends solanaCore.SolWalletConnector {
|
|
|
116
119
|
extractTransactions() {
|
|
117
120
|
const params = new URLSearchParams(window.location.search);
|
|
118
121
|
const { data, nonce, sharedSecret } = this.getInputsOrThrow('extractTransactions', ['data', 'nonce'], ['sharedSecret']);
|
|
119
|
-
const signAllTransactionsData =
|
|
122
|
+
const signAllTransactionsData = decryptPayload.decryptPayload(data, nonce, sharedSecret);
|
|
120
123
|
const decodedTransactions = signAllTransactionsData.transactions.map((t) => web3_js.Transaction.from(bs58__default["default"].decode(t)));
|
|
121
124
|
params.delete('data');
|
|
122
125
|
params.delete('nonce');
|
|
@@ -126,7 +129,7 @@ class PhantomRedirect extends solanaCore.SolWalletConnector {
|
|
|
126
129
|
extractTransaction() {
|
|
127
130
|
const params = new URLSearchParams(window.location.search);
|
|
128
131
|
const { data, nonce, sharedSecret } = this.getInputsOrThrow('extractTransaction', ['data', 'nonce'], ['sharedSecret']);
|
|
129
|
-
const signTransactionData =
|
|
132
|
+
const signTransactionData = decryptPayload.decryptPayload(data, nonce, sharedSecret);
|
|
130
133
|
const decodedTransaction = web3_js.Transaction.from(bs58__default["default"].decode(signTransactionData.transaction));
|
|
131
134
|
params.delete('data');
|
|
132
135
|
params.delete('nonce');
|
|
@@ -200,14 +203,14 @@ class PhantomRedirect extends solanaCore.SolWalletConnector {
|
|
|
200
203
|
session,
|
|
201
204
|
transactions: serializedTransactions,
|
|
202
205
|
};
|
|
203
|
-
const [nonce, encryptedPayload] =
|
|
206
|
+
const [nonce, encryptedPayload] = encryptPayload.encryptPayload(payload, sharedSecret);
|
|
204
207
|
const params = new URLSearchParams({
|
|
205
208
|
dapp_encryption_public_key: bs58__default["default"].encode(encryptionPublicKey),
|
|
206
209
|
nonce: bs58__default["default"].encode(nonce),
|
|
207
210
|
payload: bs58__default["default"].encode(encryptedPayload),
|
|
208
211
|
redirect_link: window.location.href,
|
|
209
212
|
});
|
|
210
|
-
const url =
|
|
213
|
+
const url = buildUrl.buildUrl('signAllTransactions', params);
|
|
211
214
|
window.location.href = url;
|
|
212
215
|
// actual signatures will be retrieved upon redirect back to dapp
|
|
213
216
|
return [];
|
|
@@ -219,14 +222,14 @@ class PhantomRedirect extends solanaCore.SolWalletConnector {
|
|
|
219
222
|
session,
|
|
220
223
|
transaction: bs58__default["default"].encode(transaction.serialize({ requireAllSignatures: false })),
|
|
221
224
|
};
|
|
222
|
-
const [nonce, encryptedPayload] =
|
|
225
|
+
const [nonce, encryptedPayload] = encryptPayload.encryptPayload(payload, sharedSecret);
|
|
223
226
|
const params = new URLSearchParams({
|
|
224
227
|
dapp_encryption_public_key: bs58__default["default"].encode(encryptionPublicKey),
|
|
225
228
|
nonce: bs58__default["default"].encode(nonce),
|
|
226
229
|
payload: bs58__default["default"].encode(encryptedPayload),
|
|
227
230
|
redirect_link: window.location.href,
|
|
228
231
|
});
|
|
229
|
-
const url =
|
|
232
|
+
const url = buildUrl.buildUrl('signAndSendTransaction', params);
|
|
230
233
|
storage.storage.method.set('signAndSendTransaction');
|
|
231
234
|
window.location.href = url;
|
|
232
235
|
// actual signature will be retrived upon redirect back to dapp
|
|
@@ -238,14 +241,14 @@ class PhantomRedirect extends solanaCore.SolWalletConnector {
|
|
|
238
241
|
message: bs58__default["default"].encode(Buffer.from(message)),
|
|
239
242
|
session,
|
|
240
243
|
};
|
|
241
|
-
const [nonce, encryptedPayload] =
|
|
244
|
+
const [nonce, encryptedPayload] = encryptPayload.encryptPayload(payload, sharedSecret);
|
|
242
245
|
const params = new URLSearchParams({
|
|
243
246
|
dapp_encryption_public_key: bs58__default["default"].encode(encryptionPublicKey),
|
|
244
247
|
nonce: bs58__default["default"].encode(nonce),
|
|
245
248
|
payload: bs58__default["default"].encode(encryptedPayload),
|
|
246
249
|
redirect_link: window.location.href,
|
|
247
250
|
});
|
|
248
|
-
const url =
|
|
251
|
+
const url = buildUrl.buildUrl('signMessage', params);
|
|
249
252
|
window.location.href = url;
|
|
250
253
|
// actual signature will be retrived upon redirect back to dapp
|
|
251
254
|
return { signature: Buffer.from('') };
|
|
@@ -259,14 +262,14 @@ class PhantomRedirect extends solanaCore.SolWalletConnector {
|
|
|
259
262
|
session,
|
|
260
263
|
transaction: serializedTransaction,
|
|
261
264
|
};
|
|
262
|
-
const [nonce, encryptedPayload] =
|
|
265
|
+
const [nonce, encryptedPayload] = encryptPayload.encryptPayload(payload, sharedSecret);
|
|
263
266
|
const params = new URLSearchParams({
|
|
264
267
|
dapp_encryption_public_key: bs58__default["default"].encode(encryptionPublicKey),
|
|
265
268
|
nonce: bs58__default["default"].encode(nonce),
|
|
266
269
|
payload: bs58__default["default"].encode(encryptedPayload),
|
|
267
270
|
redirect_link: window.location.href,
|
|
268
271
|
});
|
|
269
|
-
const url =
|
|
272
|
+
const url = buildUrl.buildUrl('signTransaction', params);
|
|
270
273
|
window.location.href = url;
|
|
271
274
|
return transaction;
|
|
272
275
|
}),
|
|
@@ -291,14 +294,14 @@ class PhantomRedirect extends solanaCore.SolWalletConnector {
|
|
|
291
294
|
if (!address || !session || !encryptionPublicKey || !sharedSecret)
|
|
292
295
|
return;
|
|
293
296
|
const payload = { session };
|
|
294
|
-
const [nonce, encryptedPayload] =
|
|
297
|
+
const [nonce, encryptedPayload] = encryptPayload.encryptPayload(payload, sharedSecret);
|
|
295
298
|
const params = new URLSearchParams({
|
|
296
299
|
dapp_encryption_public_key: bs58__default["default"].encode(encryptionPublicKey),
|
|
297
300
|
nonce: bs58__default["default"].encode(nonce),
|
|
298
301
|
payload: bs58__default["default"].encode(encryptedPayload),
|
|
299
302
|
redirect_link: window.location.href,
|
|
300
303
|
});
|
|
301
|
-
const url =
|
|
304
|
+
const url = buildUrl.buildUrl('disconnect', params);
|
|
302
305
|
window.location.href = url;
|
|
303
306
|
});
|
|
304
307
|
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { Transaction } from '@solana/web3.js';
|
|
2
|
+
import { SolanaWalletConnector, type ISolana } from '@dynamic-labs/solana-core';
|
|
2
3
|
import { IPhantomRedirectConnector } from '@dynamic-labs/wallet-connector-core';
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
export declare class PhantomRedirect extends SolWalletConnector implements IPhantomRedirectConnector {
|
|
4
|
+
import { Method } from '../types';
|
|
5
|
+
export declare class PhantomRedirect extends SolanaWalletConnector implements IPhantomRedirectConnector {
|
|
6
6
|
name: string;
|
|
7
7
|
overrideKey: string;
|
|
8
8
|
constructor(props: any);
|
|
@@ -1,13 +1,16 @@
|
|
|
1
1
|
'use client'
|
|
2
|
-
import { __awaiter } from '
|
|
3
|
-
import nacl from 'tweetnacl';
|
|
4
|
-
import bs58 from 'bs58';
|
|
2
|
+
import { __awaiter } from '../../../_virtual/_tslib.js';
|
|
5
3
|
import { PublicKey, Transaction } from '@solana/web3.js';
|
|
6
|
-
import
|
|
7
|
-
import
|
|
8
|
-
import {
|
|
4
|
+
import bs58 from 'bs58';
|
|
5
|
+
import nacl from 'tweetnacl';
|
|
6
|
+
import { SolanaWalletConnector } from '@dynamic-labs/solana-core';
|
|
7
|
+
import { buildUrl } from '../buildUrl/buildUrl.js';
|
|
8
|
+
import { decryptPayload } from '../decryptPayload/decryptPayload.js';
|
|
9
|
+
import { encryptPayload } from '../encryptPayload/encryptPayload.js';
|
|
10
|
+
import { fetchCluster } from '../fetchCluster/fetchCluster.js';
|
|
11
|
+
import { storage, clearStorage } from '../storage/storage.js';
|
|
9
12
|
|
|
10
|
-
class PhantomRedirect extends
|
|
13
|
+
class PhantomRedirect extends SolanaWalletConnector {
|
|
11
14
|
constructor(props) {
|
|
12
15
|
super(Object.assign({}, props));
|
|
13
16
|
this.name = 'Phantom';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './PhantomRedirect';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const buildUrl: (path: string, params: URLSearchParams) => string;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './buildUrl';
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
5
|
+
|
|
6
|
+
var bs58 = require('bs58');
|
|
7
|
+
var nacl = require('tweetnacl');
|
|
8
|
+
var logger = require('../../utils/logger.cjs');
|
|
9
|
+
|
|
10
|
+
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
11
|
+
|
|
12
|
+
var bs58__default = /*#__PURE__*/_interopDefaultLegacy(bs58);
|
|
13
|
+
var nacl__default = /*#__PURE__*/_interopDefaultLegacy(nacl);
|
|
14
|
+
|
|
15
|
+
const failForMissingParam = (paramName, param) => {
|
|
16
|
+
const message = `Failed to decrypt phantom redirect payload: ${paramName} was invalid (${param})`;
|
|
17
|
+
logger.logger.error(message);
|
|
18
|
+
throw new Error(message);
|
|
19
|
+
};
|
|
20
|
+
const decryptPayload = (data, nonce, sharedSecret) => {
|
|
21
|
+
if (!data)
|
|
22
|
+
failForMissingParam('data', data);
|
|
23
|
+
if (!nonce)
|
|
24
|
+
failForMissingParam('nonce', nonce);
|
|
25
|
+
if (!sharedSecret)
|
|
26
|
+
failForMissingParam('sharedSecret', sharedSecret);
|
|
27
|
+
const decryptedData = nacl__default["default"].box.open.after(bs58__default["default"].decode(data), bs58__default["default"].decode(nonce), sharedSecret);
|
|
28
|
+
if (!decryptedData) {
|
|
29
|
+
throw new Error('Unable to decrypt data');
|
|
30
|
+
}
|
|
31
|
+
return JSON.parse(Buffer.from(decryptedData).toString('utf8'));
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
exports.decryptPayload = decryptPayload;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const decryptPayload: (data: string, nonce: string, sharedSecret: Uint8Array) => any;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
import bs58 from 'bs58';
|
|
3
|
+
import nacl from 'tweetnacl';
|
|
4
|
+
import { logger } from '../../utils/logger.js';
|
|
5
|
+
|
|
6
|
+
const failForMissingParam = (paramName, param) => {
|
|
7
|
+
const message = `Failed to decrypt phantom redirect payload: ${paramName} was invalid (${param})`;
|
|
8
|
+
logger.error(message);
|
|
9
|
+
throw new Error(message);
|
|
10
|
+
};
|
|
11
|
+
const decryptPayload = (data, nonce, sharedSecret) => {
|
|
12
|
+
if (!data)
|
|
13
|
+
failForMissingParam('data', data);
|
|
14
|
+
if (!nonce)
|
|
15
|
+
failForMissingParam('nonce', nonce);
|
|
16
|
+
if (!sharedSecret)
|
|
17
|
+
failForMissingParam('sharedSecret', sharedSecret);
|
|
18
|
+
const decryptedData = nacl.box.open.after(bs58.decode(data), bs58.decode(nonce), sharedSecret);
|
|
19
|
+
if (!decryptedData) {
|
|
20
|
+
throw new Error('Unable to decrypt data');
|
|
21
|
+
}
|
|
22
|
+
return JSON.parse(Buffer.from(decryptedData).toString('utf8'));
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
export { decryptPayload };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './decryptPayload';
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
5
|
+
|
|
6
|
+
var nacl = require('tweetnacl');
|
|
7
|
+
|
|
8
|
+
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
9
|
+
|
|
10
|
+
var nacl__default = /*#__PURE__*/_interopDefaultLegacy(nacl);
|
|
11
|
+
|
|
12
|
+
const encryptPayload = (payload, sharedSecret) => {
|
|
13
|
+
const nonce = nacl__default["default"].randomBytes(24);
|
|
14
|
+
const encryptedPayload = nacl__default["default"].box.after(Buffer.from(JSON.stringify(payload)), nonce, sharedSecret);
|
|
15
|
+
return [nonce, encryptedPayload];
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
exports.encryptPayload = encryptPayload;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const encryptPayload: (payload: any, sharedSecret: Uint8Array) => Uint8Array[];
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
import nacl from 'tweetnacl';
|
|
3
|
+
|
|
4
|
+
const encryptPayload = (payload, sharedSecret) => {
|
|
5
|
+
const nonce = nacl.randomBytes(24);
|
|
6
|
+
const encryptedPayload = nacl.box.after(Buffer.from(JSON.stringify(payload)), nonce, sharedSecret);
|
|
7
|
+
return [nonce, encryptedPayload];
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
export { encryptPayload };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './encryptPayload';
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
5
|
+
|
|
6
|
+
var _tslib = require('../../../_virtual/_tslib.cjs');
|
|
7
|
+
|
|
8
|
+
const GENESIS_HASHES = {
|
|
9
|
+
'4uhcVJyU9pJkvQyS88uRDiswHXSCkY3zQawwpjk2NsNY': 'testnet',
|
|
10
|
+
'5eykt4UsFv8P8NJdTREpY1vzqKqZKvdpKuc147dw2N9d': 'mainnet-beta',
|
|
11
|
+
EtWTRABZaYq6iMfeYKouRu166VU2xqa1wcaWoxPkrZBG: 'devnet',
|
|
12
|
+
};
|
|
13
|
+
const fetchCluster = (rpc) => _tslib.__awaiter(void 0, void 0, void 0, function* () {
|
|
14
|
+
try {
|
|
15
|
+
const { result } = yield (yield fetch(rpc, {
|
|
16
|
+
body: JSON.stringify({
|
|
17
|
+
id: 1,
|
|
18
|
+
jsonrpc: '2.0',
|
|
19
|
+
method: 'getGenesisHash',
|
|
20
|
+
}),
|
|
21
|
+
headers: {
|
|
22
|
+
'Content-Type': 'application/json',
|
|
23
|
+
},
|
|
24
|
+
method: 'POST',
|
|
25
|
+
})).json();
|
|
26
|
+
return GENESIS_HASHES[result];
|
|
27
|
+
}
|
|
28
|
+
catch (err) {
|
|
29
|
+
return 'mainnet-beta';
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
exports.fetchCluster = fetchCluster;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const fetchCluster: (rpc: string) => Promise<string>;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
import { __awaiter } from '../../../_virtual/_tslib.js';
|
|
3
|
+
|
|
4
|
+
const GENESIS_HASHES = {
|
|
5
|
+
'4uhcVJyU9pJkvQyS88uRDiswHXSCkY3zQawwpjk2NsNY': 'testnet',
|
|
6
|
+
'5eykt4UsFv8P8NJdTREpY1vzqKqZKvdpKuc147dw2N9d': 'mainnet-beta',
|
|
7
|
+
EtWTRABZaYq6iMfeYKouRu166VU2xqa1wcaWoxPkrZBG: 'devnet',
|
|
8
|
+
};
|
|
9
|
+
const fetchCluster = (rpc) => __awaiter(void 0, void 0, void 0, function* () {
|
|
10
|
+
try {
|
|
11
|
+
const { result } = yield (yield fetch(rpc, {
|
|
12
|
+
body: JSON.stringify({
|
|
13
|
+
id: 1,
|
|
14
|
+
jsonrpc: '2.0',
|
|
15
|
+
method: 'getGenesisHash',
|
|
16
|
+
}),
|
|
17
|
+
headers: {
|
|
18
|
+
'Content-Type': 'application/json',
|
|
19
|
+
},
|
|
20
|
+
method: 'POST',
|
|
21
|
+
})).json();
|
|
22
|
+
return GENESIS_HASHES[result];
|
|
23
|
+
}
|
|
24
|
+
catch (err) {
|
|
25
|
+
return 'mainnet-beta';
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
export { fetchCluster };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './fetchCluster';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './storage';
|
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;
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { Wallet } from '@wallet-standard/base';
|
|
2
|
-
import { StandardConnectFeature, StandardDisconnectFeature } from '@wallet-standard/features';
|
|
3
|
-
import { Chain } from '@dynamic-labs/wallet-connector-core';
|
|
4
|
-
import { WalletBookSchema } from '@dynamic-labs/wallet-book';
|
|
5
|
-
import { SolWalletConnector, SolWalletConnectorOpts, type ISolana } from '@dynamic-labs/solana-core';
|
|
6
|
-
export declare abstract class SolanaWalletStandardConnector extends SolWalletConnector {
|
|
7
|
-
connectedChain: Chain;
|
|
8
|
-
supportedChains: Chain[];
|
|
9
|
-
constructor(props: SolWalletConnectorOpts);
|
|
10
|
-
get wallet(): Wallet;
|
|
11
|
-
get walletFeatures(): StandardConnectFeature & StandardDisconnectFeature;
|
|
12
|
-
connect(): Promise<void>;
|
|
13
|
-
endSession(): Promise<void>;
|
|
14
|
-
isInstalledOnBrowser(): boolean;
|
|
15
|
-
getAddress(): Promise<string | undefined>;
|
|
16
|
-
getConnectedAccounts(): Promise<string[]>;
|
|
17
|
-
signMessage(messageToSign: string): Promise<string | undefined>;
|
|
18
|
-
getSigner(): Promise<ISolana | undefined>;
|
|
19
|
-
static getWallet(walletBook: WalletBookSchema, walletKey: string): Wallet | undefined;
|
|
20
|
-
}
|