@dynamic-labs/solana 0.0.0-exp20240808.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 +3746 -0
- package/LICENSE +21 -0
- package/README.md +0 -0
- package/_virtual/_tslib.cjs +36 -0
- package/_virtual/_tslib.js +32 -0
- package/package.json +48 -0
- package/src/CoinbaseSolana.cjs +52 -0
- package/src/CoinbaseSolana.d.ts +9 -0
- package/src/CoinbaseSolana.js +48 -0
- package/src/Phantom.cjs +44 -0
- package/src/Phantom.d.ts +13 -0
- package/src/Phantom.js +40 -0
- package/src/SolanaWalletStandardConnector/SolanaWalletStandardConnector.cjs +100 -0
- package/src/SolanaWalletStandardConnector/SolanaWalletStandardConnector.d.ts +21 -0
- package/src/SolanaWalletStandardConnector/SolanaWalletStandardConnector.js +96 -0
- package/src/SolanaWalletStandardConnector/index.d.ts +1 -0
- package/src/SolanaWalletStandardConnector/utils/createSolanaSignerFromWalletStandard/createSolanaSignerFromWalletStandard.cjs +117 -0
- package/src/SolanaWalletStandardConnector/utils/createSolanaSignerFromWalletStandard/createSolanaSignerFromWalletStandard.d.ts +4 -0
- package/src/SolanaWalletStandardConnector/utils/createSolanaSignerFromWalletStandard/createSolanaSignerFromWalletStandard.js +113 -0
- package/src/SolanaWalletStandardConnector/utils/createSolanaSignerFromWalletStandard/index.d.ts +1 -0
- package/src/Solflare.cjs +63 -0
- package/src/Solflare.d.ts +9 -0
- package/src/Solflare.js +59 -0
- package/src/contants.cjs +8 -0
- package/src/contants.d.ts +1 -0
- package/src/contants.js +4 -0
- package/src/errors/SignMessageNotSupportedError.cjs +17 -0
- package/src/errors/SignMessageNotSupportedError.d.ts +4 -0
- package/src/errors/SignMessageNotSupportedError.js +13 -0
- package/src/index.cjs +30 -0
- package/src/index.d.ts +7 -0
- package/src/index.js +22 -0
- package/src/injected/BackpackSol.cjs +46 -0
- package/src/injected/BackpackSol.d.ts +9 -0
- package/src/injected/BackpackSol.js +42 -0
- package/src/injected/FallbackSolanaConnector.cjs +22 -0
- package/src/injected/FallbackSolanaConnector.d.ts +9 -0
- package/src/injected/FallbackSolanaConnector.js +18 -0
- package/src/injected/InjectedWalletBase.cjs +118 -0
- package/src/injected/InjectedWalletBase.d.ts +21 -0
- package/src/injected/InjectedWalletBase.js +114 -0
- package/src/injected/PhantomInjected.cjs +37 -0
- package/src/injected/PhantomInjected.d.ts +8 -0
- package/src/injected/PhantomInjected.js +33 -0
- package/src/injected/UnknownInjected.cjs +21 -0
- package/src/injected/UnknownInjected.d.ts +8 -0
- package/src/injected/UnknownInjected.js +17 -0
- package/src/injected/fetchInjectedWalletConnectors.cjs +63 -0
- package/src/injected/fetchInjectedWalletConnectors.d.ts +6 -0
- package/src/injected/fetchInjectedWalletConnectors.js +58 -0
- package/src/injected/index.d.ts +3 -0
- package/src/phantomRedirect/PhantomRedirect.cjs +337 -0
- package/src/phantomRedirect/PhantomRedirect.d.ts +37 -0
- package/src/phantomRedirect/PhantomRedirect.js +328 -0
- package/src/phantomRedirect/storage.cjs +96 -0
- package/src/phantomRedirect/storage.d.ts +40 -0
- package/src/phantomRedirect/storage.js +91 -0
- package/src/phantomRedirect/types.d.ts +1 -0
- package/src/phantomRedirect/utils.cjs +56 -0
- package/src/phantomRedirect/utils.d.ts +4 -0
- package/src/phantomRedirect/utils.js +44 -0
- package/src/solProviderHelper.cjs +173 -0
- package/src/solProviderHelper.d.ts +36 -0
- package/src/solProviderHelper.js +169 -0
- package/src/solWalletConnector.cjs +174 -0
- package/src/solWalletConnector.d.ts +37 -0
- package/src/solWalletConnector.js +170 -0
- package/src/types.d.ts +68 -0
- package/src/utils/extractNonce.cjs +14 -0
- package/src/utils/extractNonce.d.ts +1 -0
- package/src/utils/extractNonce.js +10 -0
- package/src/utils/findWalletProviderFromWalletStandard/findWalletProviderFromWalletStandard.cjs +29 -0
- package/src/utils/findWalletProviderFromWalletStandard/findWalletProviderFromWalletStandard.d.ts +3 -0
- package/src/utils/findWalletProviderFromWalletStandard/findWalletProviderFromWalletStandard.js +25 -0
- package/src/utils/findWalletProviderFromWalletStandard/index.d.ts +1 -0
- package/src/utils/getGenesisHashLSKey.cjs +10 -0
- package/src/utils/getGenesisHashLSKey.d.ts +1 -0
- package/src/utils/getGenesisHashLSKey.js +6 -0
- package/src/utils/isBackpackSolanaSigner.cjs +8 -0
- package/src/utils/isBackpackSolanaSigner.d.ts +2 -0
- package/src/utils/isBackpackSolanaSigner.js +4 -0
- package/src/utils/isSignedMessage.cjs +8 -0
- package/src/utils/isSignedMessage.d.ts +2 -0
- package/src/utils/isSignedMessage.js +4 -0
- package/src/wallet/SolanaWallet.cjs +33 -0
- package/src/wallet/SolanaWallet.d.ts +17 -0
- package/src/wallet/SolanaWallet.js +29 -0
- package/src/wallet/index.d.ts +2 -0
- package/src/wallet/isSolanaWallet.cjs +8 -0
- package/src/wallet/isSolanaWallet.d.ts +3 -0
- package/src/wallet/isSolanaWallet.js +4 -0
|
@@ -0,0 +1,337 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
5
|
+
|
|
6
|
+
var _tslib = require('../../_virtual/_tslib.cjs');
|
|
7
|
+
var nacl = require('tweetnacl');
|
|
8
|
+
var bs58 = require('bs58');
|
|
9
|
+
var web3_js = require('@solana/web3.js');
|
|
10
|
+
var solWalletConnector = require('../solWalletConnector.cjs');
|
|
11
|
+
var utils = require('./utils.cjs');
|
|
12
|
+
var storage = require('./storage.cjs');
|
|
13
|
+
|
|
14
|
+
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
15
|
+
|
|
16
|
+
var nacl__default = /*#__PURE__*/_interopDefaultLegacy(nacl);
|
|
17
|
+
var bs58__default = /*#__PURE__*/_interopDefaultLegacy(bs58);
|
|
18
|
+
|
|
19
|
+
class PhantomRedirect extends solWalletConnector.SolWalletConnector {
|
|
20
|
+
constructor(props) {
|
|
21
|
+
super(Object.assign({}, props));
|
|
22
|
+
this.name = 'Phantom';
|
|
23
|
+
this.overrideKey = 'phantom';
|
|
24
|
+
}
|
|
25
|
+
getMethod() {
|
|
26
|
+
throw new Error('Method not implemented.');
|
|
27
|
+
}
|
|
28
|
+
getAddress() {
|
|
29
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
30
|
+
const address = storage.storage.address.get();
|
|
31
|
+
if (address) {
|
|
32
|
+
return address;
|
|
33
|
+
}
|
|
34
|
+
yield this.connect();
|
|
35
|
+
return undefined;
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
connect() {
|
|
39
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
40
|
+
var _a, _b;
|
|
41
|
+
// Generate a new key pair
|
|
42
|
+
const keyPair = nacl__default["default"].box.keyPair();
|
|
43
|
+
storage.storage.encryptionPublicKey.set(keyPair.publicKey);
|
|
44
|
+
storage.storage.encryptionSecretKey.set(keyPair.secretKey);
|
|
45
|
+
const isLocalHost = window.location.href.includes('localhost') ||
|
|
46
|
+
window.location.href.includes('0.0.0.0') ||
|
|
47
|
+
window.location.href.includes('127.0.0.1');
|
|
48
|
+
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
|
+
const params = new URLSearchParams({
|
|
50
|
+
app_url: isLocalHost ? 'https://demo.dynamic.xyz' : window.location.href,
|
|
51
|
+
cluster: yield utils.fetchCluster(rpc),
|
|
52
|
+
dapp_encryption_public_key: bs58__default["default"].encode(keyPair.publicKey),
|
|
53
|
+
redirect_link: window.location.href,
|
|
54
|
+
});
|
|
55
|
+
const url = utils.buildUrl('connect', params);
|
|
56
|
+
window.location.href = url;
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
getSession() {
|
|
60
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
61
|
+
const params = new URLSearchParams(window.location.search);
|
|
62
|
+
const { data, nonce, phantom_encryption_public_key: phantomEncryptionPublicKey, encryptionSecretKey, } = this.getInputsOrThrow('getSession', ['data', 'nonce', 'phantom_encryption_public_key'], ['encryptionSecretKey']);
|
|
63
|
+
const sharedSecret = nacl__default["default"].box.before(bs58__default["default"].decode(phantomEncryptionPublicKey), encryptionSecretKey);
|
|
64
|
+
storage.storage.sharedSecret.set(sharedSecret);
|
|
65
|
+
const connectData = utils.decryptPayload(data, nonce, sharedSecret);
|
|
66
|
+
storage.storage.session.set(connectData.session);
|
|
67
|
+
storage.storage.address.set(new web3_js.PublicKey(connectData.public_key));
|
|
68
|
+
params.delete('phantom_encryption_public_key');
|
|
69
|
+
params.delete('data');
|
|
70
|
+
params.delete('nonce');
|
|
71
|
+
history.replaceState(null, '', `${window.location.origin}${window.location.pathname}?${params.toString()}`);
|
|
72
|
+
return connectData.public_key;
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
signMessage(messageToSign) {
|
|
76
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
77
|
+
const { session, sharedSecret, encryptionPublicKey } = this.getInputsOrThrow('signMessage', [], ['session', 'sharedSecret', 'encryptionPublicKey']);
|
|
78
|
+
storage.storage.message.set(messageToSign);
|
|
79
|
+
const payload = {
|
|
80
|
+
message: bs58__default["default"].encode(Buffer.from(messageToSign)),
|
|
81
|
+
session,
|
|
82
|
+
};
|
|
83
|
+
const [nonce, encryptedPayload] = utils.encryptPayload(payload, sharedSecret);
|
|
84
|
+
const params = new URLSearchParams({
|
|
85
|
+
dapp_encryption_public_key: bs58__default["default"].encode(encryptionPublicKey),
|
|
86
|
+
nonce: bs58__default["default"].encode(nonce),
|
|
87
|
+
payload: bs58__default["default"].encode(encryptedPayload),
|
|
88
|
+
redirect_link: window.location.href,
|
|
89
|
+
});
|
|
90
|
+
const url = utils.buildUrl('signMessage', params);
|
|
91
|
+
storage.storage.method.set('signMessage');
|
|
92
|
+
window.location.href = url;
|
|
93
|
+
// throwing this to prevent local storage from being cleared.
|
|
94
|
+
// when verifying signature, the SDK calls endSession when no
|
|
95
|
+
// signature is returned. in the case of phantom mobile, a signature
|
|
96
|
+
// is not returned from signMessage, so an error will always be thrown.
|
|
97
|
+
// this is a workaround to prevent the SDK from clearing local storage
|
|
98
|
+
// ideally we would figure out how to:
|
|
99
|
+
// 1. kick off the sign message on one tab
|
|
100
|
+
// 2. resume the process on that tab after the user signs in phantom
|
|
101
|
+
throw new Error('ignore');
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
extractSignature() {
|
|
105
|
+
const params = new URLSearchParams(window.location.search);
|
|
106
|
+
const { data, nonce, sharedSecret, message } = this.getInputsOrThrow('extractSignature', ['data', 'nonce'], ['sharedSecret', 'message']);
|
|
107
|
+
const signMessageData = utils.decryptPayload(data, nonce, sharedSecret);
|
|
108
|
+
params.delete('data');
|
|
109
|
+
params.delete('nonce');
|
|
110
|
+
history.replaceState(null, '', `${window.location.origin}${window.location.pathname}?${params.toString()}`);
|
|
111
|
+
return {
|
|
112
|
+
message,
|
|
113
|
+
signature: signMessageData.signature,
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
extractTransactions() {
|
|
117
|
+
const params = new URLSearchParams(window.location.search);
|
|
118
|
+
const { data, nonce, sharedSecret } = this.getInputsOrThrow('extractTransactions', ['data', 'nonce'], ['sharedSecret']);
|
|
119
|
+
const signAllTransactionsData = utils.decryptPayload(data, nonce, sharedSecret);
|
|
120
|
+
const decodedTransactions = signAllTransactionsData.transactions.map((t) => web3_js.Transaction.from(bs58__default["default"].decode(t)));
|
|
121
|
+
params.delete('data');
|
|
122
|
+
params.delete('nonce');
|
|
123
|
+
history.replaceState(null, '', `${window.location.origin}${window.location.pathname}?${params.toString()}`);
|
|
124
|
+
return decodedTransactions;
|
|
125
|
+
}
|
|
126
|
+
extractTransaction() {
|
|
127
|
+
const params = new URLSearchParams(window.location.search);
|
|
128
|
+
const { data, nonce, sharedSecret } = this.getInputsOrThrow('extractTransaction', ['data', 'nonce'], ['sharedSecret']);
|
|
129
|
+
const signTransactionData = utils.decryptPayload(data, nonce, sharedSecret);
|
|
130
|
+
const decodedTransaction = web3_js.Transaction.from(bs58__default["default"].decode(signTransactionData.transaction));
|
|
131
|
+
params.delete('data');
|
|
132
|
+
params.delete('nonce');
|
|
133
|
+
history.replaceState(null, '', `${window.location.origin}${window.location.pathname}?${params.toString()}`);
|
|
134
|
+
return decodedTransaction;
|
|
135
|
+
}
|
|
136
|
+
consumeMethod() {
|
|
137
|
+
const method = storage.storage.method.get();
|
|
138
|
+
storage.storage.method.remove();
|
|
139
|
+
return method;
|
|
140
|
+
}
|
|
141
|
+
getSigner() {
|
|
142
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
143
|
+
const address = storage.storage.address.get();
|
|
144
|
+
if (!address) {
|
|
145
|
+
return undefined;
|
|
146
|
+
}
|
|
147
|
+
return {
|
|
148
|
+
addListener: () => {
|
|
149
|
+
throw new Error('Not implemented');
|
|
150
|
+
},
|
|
151
|
+
connect: () => {
|
|
152
|
+
throw new Error('Not implemented');
|
|
153
|
+
},
|
|
154
|
+
disconnect: () => {
|
|
155
|
+
throw new Error('Not implemented');
|
|
156
|
+
},
|
|
157
|
+
emit: () => {
|
|
158
|
+
throw new Error('Not implemented');
|
|
159
|
+
},
|
|
160
|
+
eventNames: () => {
|
|
161
|
+
throw new Error('Not implemented');
|
|
162
|
+
},
|
|
163
|
+
isBackpack: false,
|
|
164
|
+
isBraveWallet: false,
|
|
165
|
+
isConnected: true,
|
|
166
|
+
isExodus: false,
|
|
167
|
+
isGlow: false,
|
|
168
|
+
isMagicEden: false,
|
|
169
|
+
isPhantom: true,
|
|
170
|
+
isSolflare: false,
|
|
171
|
+
listenerCount: () => {
|
|
172
|
+
throw new Error('Not implemented');
|
|
173
|
+
},
|
|
174
|
+
listeners: () => {
|
|
175
|
+
throw new Error('Not implemented');
|
|
176
|
+
},
|
|
177
|
+
off: () => {
|
|
178
|
+
throw new Error('Not implemented');
|
|
179
|
+
},
|
|
180
|
+
on: () => {
|
|
181
|
+
throw new Error('Not implemented');
|
|
182
|
+
},
|
|
183
|
+
once: () => {
|
|
184
|
+
throw new Error('Not implemented');
|
|
185
|
+
},
|
|
186
|
+
providers: [],
|
|
187
|
+
publicKey: new web3_js.PublicKey(address),
|
|
188
|
+
removeAllListeners: () => {
|
|
189
|
+
throw new Error('Not implemented');
|
|
190
|
+
},
|
|
191
|
+
removeListener: () => {
|
|
192
|
+
throw new Error('Not implemented');
|
|
193
|
+
},
|
|
194
|
+
signAllTransactions: (transactions) => _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
195
|
+
const serializedTransactions = transactions.map((t) => bs58__default["default"].encode(t.serialize({
|
|
196
|
+
requireAllSignatures: false,
|
|
197
|
+
})));
|
|
198
|
+
const { session, sharedSecret, encryptionPublicKey } = this.getInputsOrThrow('signAllTransactions', [], ['session', 'sharedSecret', 'encryptionPublicKey']);
|
|
199
|
+
const payload = {
|
|
200
|
+
session,
|
|
201
|
+
transactions: serializedTransactions,
|
|
202
|
+
};
|
|
203
|
+
const [nonce, encryptedPayload] = utils.encryptPayload(payload, sharedSecret);
|
|
204
|
+
const params = new URLSearchParams({
|
|
205
|
+
dapp_encryption_public_key: bs58__default["default"].encode(encryptionPublicKey),
|
|
206
|
+
nonce: bs58__default["default"].encode(nonce),
|
|
207
|
+
payload: bs58__default["default"].encode(encryptedPayload),
|
|
208
|
+
redirect_link: window.location.href,
|
|
209
|
+
});
|
|
210
|
+
const url = utils.buildUrl('signAllTransactions', params);
|
|
211
|
+
window.location.href = url;
|
|
212
|
+
// actual signatures will be retrieved upon redirect back to dapp
|
|
213
|
+
return [];
|
|
214
|
+
}),
|
|
215
|
+
signAndSendTransaction: (transaction, options) => _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
216
|
+
const { session, sharedSecret, encryptionPublicKey } = this.getInputsOrThrow('signAndSendTransaction', [], ['session', 'sharedSecret', 'encryptionPublicKey']);
|
|
217
|
+
const payload = {
|
|
218
|
+
options,
|
|
219
|
+
session,
|
|
220
|
+
transaction: bs58__default["default"].encode(transaction.serialize({ requireAllSignatures: false })),
|
|
221
|
+
};
|
|
222
|
+
const [nonce, encryptedPayload] = utils.encryptPayload(payload, sharedSecret);
|
|
223
|
+
const params = new URLSearchParams({
|
|
224
|
+
dapp_encryption_public_key: bs58__default["default"].encode(encryptionPublicKey),
|
|
225
|
+
nonce: bs58__default["default"].encode(nonce),
|
|
226
|
+
payload: bs58__default["default"].encode(encryptedPayload),
|
|
227
|
+
redirect_link: window.location.href,
|
|
228
|
+
});
|
|
229
|
+
const url = utils.buildUrl('signAndSendTransaction', params);
|
|
230
|
+
storage.storage.method.set('signAndSendTransaction');
|
|
231
|
+
window.location.href = url;
|
|
232
|
+
// actual signature will be retrived upon redirect back to dapp
|
|
233
|
+
return { signature: '' };
|
|
234
|
+
}),
|
|
235
|
+
signMessage: (message) => _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
236
|
+
const { session, sharedSecret, encryptionPublicKey } = this.getInputsOrThrow('signMessage', [], ['session', 'sharedSecret', 'encryptionPublicKey']);
|
|
237
|
+
const payload = {
|
|
238
|
+
message: bs58__default["default"].encode(Buffer.from(message)),
|
|
239
|
+
session,
|
|
240
|
+
};
|
|
241
|
+
const [nonce, encryptedPayload] = utils.encryptPayload(payload, sharedSecret);
|
|
242
|
+
const params = new URLSearchParams({
|
|
243
|
+
dapp_encryption_public_key: bs58__default["default"].encode(encryptionPublicKey),
|
|
244
|
+
nonce: bs58__default["default"].encode(nonce),
|
|
245
|
+
payload: bs58__default["default"].encode(encryptedPayload),
|
|
246
|
+
redirect_link: window.location.href,
|
|
247
|
+
});
|
|
248
|
+
const url = utils.buildUrl('signMessage', params);
|
|
249
|
+
window.location.href = url;
|
|
250
|
+
// actual signature will be retrived upon redirect back to dapp
|
|
251
|
+
return Buffer.from('');
|
|
252
|
+
}),
|
|
253
|
+
signTransaction: (transaction) => _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
254
|
+
const serializedTransaction = bs58__default["default"].encode(transaction.serialize({
|
|
255
|
+
requireAllSignatures: false,
|
|
256
|
+
}));
|
|
257
|
+
const { session, sharedSecret, encryptionPublicKey } = this.getInputsOrThrow('signTransaction', [], ['session', 'sharedSecret', 'encryptionPublicKey']);
|
|
258
|
+
const payload = {
|
|
259
|
+
session,
|
|
260
|
+
transaction: serializedTransaction,
|
|
261
|
+
};
|
|
262
|
+
const [nonce, encryptedPayload] = utils.encryptPayload(payload, sharedSecret);
|
|
263
|
+
const params = new URLSearchParams({
|
|
264
|
+
dapp_encryption_public_key: bs58__default["default"].encode(encryptionPublicKey),
|
|
265
|
+
nonce: bs58__default["default"].encode(nonce),
|
|
266
|
+
payload: bs58__default["default"].encode(encryptedPayload),
|
|
267
|
+
redirect_link: window.location.href,
|
|
268
|
+
});
|
|
269
|
+
const url = utils.buildUrl('signTransaction', params);
|
|
270
|
+
window.location.href = url;
|
|
271
|
+
return transaction;
|
|
272
|
+
}),
|
|
273
|
+
};
|
|
274
|
+
});
|
|
275
|
+
}
|
|
276
|
+
getConnectedAccounts() {
|
|
277
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
278
|
+
const address = storage.storage.address.get();
|
|
279
|
+
return address ? [address] : [];
|
|
280
|
+
});
|
|
281
|
+
}
|
|
282
|
+
endSession() {
|
|
283
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
284
|
+
const address = storage.storage.address.get();
|
|
285
|
+
const session = storage.storage.session.get();
|
|
286
|
+
const sharedSecret = storage.storage.sharedSecret.get();
|
|
287
|
+
const encryptionPublicKey = storage.storage.encryptionPublicKey.get();
|
|
288
|
+
// Clear all local storage in case of any stale state
|
|
289
|
+
storage.clearStorage();
|
|
290
|
+
// if there is no session/encrytion keys, then we don't need to disconnect
|
|
291
|
+
if (!address || !session || !encryptionPublicKey || !sharedSecret)
|
|
292
|
+
return;
|
|
293
|
+
const payload = { session };
|
|
294
|
+
const [nonce, encryptedPayload] = utils.encryptPayload(payload, sharedSecret);
|
|
295
|
+
const params = new URLSearchParams({
|
|
296
|
+
dapp_encryption_public_key: bs58__default["default"].encode(encryptionPublicKey),
|
|
297
|
+
nonce: bs58__default["default"].encode(nonce),
|
|
298
|
+
payload: bs58__default["default"].encode(encryptedPayload),
|
|
299
|
+
redirect_link: window.location.href,
|
|
300
|
+
});
|
|
301
|
+
const url = utils.buildUrl('disconnect', params);
|
|
302
|
+
window.location.href = url;
|
|
303
|
+
});
|
|
304
|
+
}
|
|
305
|
+
/**
|
|
306
|
+
* Helper method to get inputs from query params and localstorage
|
|
307
|
+
*
|
|
308
|
+
* The second argument is used to read values from the query string
|
|
309
|
+
* e.g. ['data', 'nonce'] -> params.get('data') and params.get('nonce')
|
|
310
|
+
*
|
|
311
|
+
* The third argument is used to read values from local storage
|
|
312
|
+
* e.g. ['address', 'message'] -> storage.address.get() and storage.message.get()
|
|
313
|
+
*
|
|
314
|
+
* Throws an error if any of the inputs are unable to be found in their respective locations
|
|
315
|
+
*/
|
|
316
|
+
getInputsOrThrow(methodName, queryParams, storageParams) {
|
|
317
|
+
const inputs = {};
|
|
318
|
+
const queryString = new URLSearchParams(window.location.search);
|
|
319
|
+
queryParams.forEach((param) => {
|
|
320
|
+
const value = queryString.get(param);
|
|
321
|
+
if (!value) {
|
|
322
|
+
throw new Error(`[PhantomRedirect] ${methodName} called, but required input '${param}' not found in query params`);
|
|
323
|
+
}
|
|
324
|
+
inputs[param] = value;
|
|
325
|
+
});
|
|
326
|
+
storageParams.forEach((storageParam) => {
|
|
327
|
+
const value = storage.storage[storageParam].get();
|
|
328
|
+
if (!value) {
|
|
329
|
+
throw new Error(`[PhantomRedirect] ${methodName} called, but required input '${storageParam}' not found in local storage`);
|
|
330
|
+
}
|
|
331
|
+
inputs[storageParam] = value;
|
|
332
|
+
});
|
|
333
|
+
return inputs;
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
exports.PhantomRedirect = PhantomRedirect;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { Transaction } from '@solana/web3.js';
|
|
2
|
+
import { IPhantomRedirectConnector } from '@dynamic-labs/wallet-connector-core';
|
|
3
|
+
import { SolWalletConnector } from '../solWalletConnector';
|
|
4
|
+
import { ISolana } from '..';
|
|
5
|
+
import { Method } from './types';
|
|
6
|
+
export declare class PhantomRedirect extends SolWalletConnector implements IPhantomRedirectConnector {
|
|
7
|
+
name: string;
|
|
8
|
+
overrideKey: string;
|
|
9
|
+
constructor(props: any);
|
|
10
|
+
getMethod(): 'signMessage' | 'signAndSendTransaction' | undefined;
|
|
11
|
+
getAddress(): Promise<string | undefined>;
|
|
12
|
+
connect(): Promise<void>;
|
|
13
|
+
getSession(): Promise<string>;
|
|
14
|
+
signMessage(messageToSign: string): Promise<string | undefined>;
|
|
15
|
+
extractSignature(): {
|
|
16
|
+
signature: string;
|
|
17
|
+
message: string;
|
|
18
|
+
};
|
|
19
|
+
extractTransactions(): Transaction[];
|
|
20
|
+
extractTransaction(): Transaction;
|
|
21
|
+
consumeMethod(): Method | undefined;
|
|
22
|
+
getSigner(): Promise<ISolana | undefined>;
|
|
23
|
+
getConnectedAccounts(): Promise<string[]>;
|
|
24
|
+
endSession(): Promise<void>;
|
|
25
|
+
/**
|
|
26
|
+
* Helper method to get inputs from query params and localstorage
|
|
27
|
+
*
|
|
28
|
+
* The second argument is used to read values from the query string
|
|
29
|
+
* e.g. ['data', 'nonce'] -> params.get('data') and params.get('nonce')
|
|
30
|
+
*
|
|
31
|
+
* The third argument is used to read values from local storage
|
|
32
|
+
* e.g. ['address', 'message'] -> storage.address.get() and storage.message.get()
|
|
33
|
+
*
|
|
34
|
+
* Throws an error if any of the inputs are unable to be found in their respective locations
|
|
35
|
+
*/
|
|
36
|
+
private getInputsOrThrow;
|
|
37
|
+
}
|