@dynamic-labs/solana 2.0.0-alpha.21 → 2.0.0-alpha.23

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,4 +1,67 @@
1
1
 
2
+ ## [2.0.0-alpha.23](https://github.com/dynamic-labs/DynamicAuth/compare/v2.0.0-alpha.22...v2.0.0-alpha.23) (2024-04-01)
3
+
4
+
5
+ ### ⚠ BREAKING CHANGES
6
+
7
+ * implement proper solana embedded wallet signer (#5092)
8
+ * prevent adding temporary wallet connection to userWallets (#5104)
9
+
10
+ ### Bug Fixes
11
+
12
+ * Multiple WC bug fixes ([#5142](https://github.com/dynamic-labs/DynamicAuth/issues/5142)) ([92236e6](https://github.com/dynamic-labs/DynamicAuth/commit/92236e6d74c28516403f6df79c539406ece3d6d0)) ([#5132](https://github.com/dynamic-labs/DynamicAuth/issues/5132)) ([99f564a](https://github.com/dynamic-labs/DynamicAuth/commit/99f564a39e35e28af0be2a03617f12aa19cbeb7f))
13
+
14
+ * Better handling of empty callback queue([#5147](https://github.com/dynamic-labs/DynamicAuth/issues/5147)) ([e2d6bf2](https://github.com/dynamic-labs/DynamicAuth/commit/e2d6bf2444ca01199796ead4136f34b81b6c9b61))
15
+
16
+ * multiple improvements to the wallet list ([#5112](https://github.com/dynamic-labs/DynamicAuth/issues/5112)) ([00eec5f](https://github.com/dynamic-labs/DynamicAuth/commit/00eec5fde70548c3d771260f3d86e5365e73878d))
17
+
18
+ * Improved scroll experience on ios ([#5152](https://github.com/dynamic-labs/DynamicAuth/issues/5152)) ([341704f](https://github.com/dynamic-labs/DynamicAuth/commit/341704f99cb6e06f253309f3a8afb1684bb8ae2a))
19
+
20
+ * better handling of multiwallet state([#5146](https://github.com/dynamic-labs/DynamicAuth/issues/5146)) ([403267b](https://github.com/dynamic-labs/DynamicAuth/commit/403267b3c268d648aba155e0b6fea31d7fdc1b56))
21
+
22
+ * show correct OTP error message ([#5135](https://github.com/dynamic-labs/DynamicAuth/issues/5135)) ([e7494ce](https://github.com/dynamic-labs/DynamicAuth/commit/e7494cee4a1b5132af91058cbcb2dae0b7eac44b))
23
+
24
+ * implement proper solana embedded wallet signer ([#5092](https://github.com/dynamic-labs/DynamicAuth/issues/5092)) ([7749b97](https://github.com/dynamic-labs/DynamicAuth/commit/7749b97db49fb9af8ae0668172f478e1f0c29665))
25
+
26
+ * prevent adding temporary wallet connection to userWallets ([#5104](https://github.com/dynamic-labs/DynamicAuth/issues/5104)) ([3c02b78](https://github.com/dynamic-labs/DynamicAuth/commit/3c02b781c997c63ff11a7f1c255b92d10962327f))
27
+
28
+
29
+ ## [2.0.0-alpha.22](https://github.com/dynamic-labs/DynamicAuth/compare/v2.0.0-alpha.21...v2.0.0-alpha.22) (2024-03-27)
30
+
31
+
32
+ ### ⚠ BREAKING CHANGES
33
+
34
+ * remove isFullyConnected (#5066)
35
+ * remove and deprecated exported methods (#5065)
36
+ * remove emailOnly provider
37
+
38
+ ### Features
39
+
40
+ * add method property to track which phantom connector function was called ([#5044](https://github.com/dynamic-labs/DynamicAuth/issues/5044)) ([f820cd4](https://github.com/dynamic-labs/DynamicAuth/commit/f820cd4c7e047fd5181115b4d388e54df682e5c8))
41
+ * add signAndSendTransaction to phantom redirect connector ([#5054](https://github.com/dynamic-labs/DynamicAuth/issues/5054)) ([694a300](https://github.com/dynamic-labs/DynamicAuth/commit/694a3003c8765098878a5c95174be5eba4509fc2))
42
+ * implement remaining signer methods on phantom redirect connector ([#5060](https://github.com/dynamic-labs/DynamicAuth/issues/5060)) ([29db446](https://github.com/dynamic-labs/DynamicAuth/commit/29db4464de6eea11c92a8080fed1eb3e7588b2b8))
43
+
44
+
45
+ ### Bug Fixes
46
+
47
+ * add recommended wallet tags to the WalletSimpleSignIn component ([#5041](https://github.com/dynamic-labs/DynamicAuth/issues/5041)) ([aefde4d](https://github.com/dynamic-labs/DynamicAuth/commit/aefde4d927427c131dce4402eb3c705527c64e8f))
48
+ * display invalid phone number error ([#5103](https://github.com/dynamic-labs/DynamicAuth/issues/5103)) ([842c0ba](https://github.com/dynamic-labs/DynamicAuth/commit/842c0ba3cfe1120c166f12410efbc346d8e30ed0))
49
+ * ensure the user field modals uses the base widget context ([#5105](https://github.com/dynamic-labs/DynamicAuth/issues/5105)) ([aa2a545](https://github.com/dynamic-labs/DynamicAuth/commit/aa2a545bdbf6f38f4131ccdde61142389dbf5480))
50
+ * force aspect ratio for social icon pfps ([#5072](https://github.com/dynamic-labs/DynamicAuth/issues/5072)) ([6f611a7](https://github.com/dynamic-labs/DynamicAuth/commit/6f611a7cbe41d66796449b28af919bc93a7bae42))
51
+ * handle too many email verifications error ([#5051](https://github.com/dynamic-labs/DynamicAuth/issues/5051)) ([7af96df](https://github.com/dynamic-labs/DynamicAuth/commit/7af96dfb85cdc68577fdb8cc880e2fd09bcff5af))
52
+ * hardcode zerion provider and update walletbook to prevent showing up as metamask when not installed ([#5071](https://github.com/dynamic-labs/DynamicAuth/issues/5071)) ([3ab6c37](https://github.com/dynamic-labs/DynamicAuth/commit/3ab6c3772efe2c2e3259ca7a9dbb92e924314029))
53
+ * issue where ethereum is tree shaken ([#5028](https://github.com/dynamic-labs/DynamicAuth/issues/5028)) ([fda542d](https://github.com/dynamic-labs/DynamicAuth/commit/fda542db2b65a437004fe809a0ea9f90fde47b13))
54
+ * not clearing the loading when creating an embedded wallet ([323086f](https://github.com/dynamic-labs/DynamicAuth/commit/323086f673fb8a2108b8262181511987d0bc1d09))
55
+ * solflare double connection on page refresh ([#5083](https://github.com/dynamic-labs/DynamicAuth/issues/5083)) ([ef76005](https://github.com/dynamic-labs/DynamicAuth/commit/ef7600564b646cf45396287a0d6b6f1420473b04))
56
+ * swap out findProvider for getSigner on solflare ([#5057](https://github.com/dynamic-labs/DynamicAuth/issues/5057)) ([b78827f](https://github.com/dynamic-labs/DynamicAuth/commit/b78827f8fd87a594114908d890f58b8771123383))
57
+ * validate user session whenever user is connected/authenticated ([#5082](https://github.com/dynamic-labs/DynamicAuth/issues/5082)) ([432faa0](https://github.com/dynamic-labs/DynamicAuth/commit/432faa0a69b43cb7324a252a2450db3cbd3b4b12))
58
+ * walletconnect improvements and fixes ([#5085](https://github.com/dynamic-labs/DynamicAuth/issues/5085)) ([bb42566](https://github.com/dynamic-labs/DynamicAuth/commit/bb425666aef5071b7827ef0aa167a328493f1ae7))
59
+
60
+
61
+ * remove and deprecated exported methods ([#5065](https://github.com/dynamic-labs/DynamicAuth/issues/5065)) ([63af7ea](https://github.com/dynamic-labs/DynamicAuth/commit/63af7ea691b2112032de332f2b3558ac6260a38d))
62
+ * remove emailOnly provider ([60a30bc](https://github.com/dynamic-labs/DynamicAuth/commit/60a30bc2f242de19d9c6167279fc44b7f9395ac8))
63
+ * remove isFullyConnected ([#5066](https://github.com/dynamic-labs/DynamicAuth/issues/5066)) ([0a662d9](https://github.com/dynamic-labs/DynamicAuth/commit/0a662d9eda19045f13c21ad1b5238ca11594fde5))
64
+
2
65
  ## [2.0.0-alpha.21](https://github.com/dynamic-labs/DynamicAuth/compare/v2.0.0-alpha.20...v2.0.0-alpha.21) (2024-03-20)
3
66
 
4
67
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dynamic-labs/solana",
3
- "version": "2.0.0-alpha.21",
3
+ "version": "2.0.0-alpha.23",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/dynamic-labs/DynamicAuth.git",
@@ -27,16 +27,16 @@
27
27
  },
28
28
  "dependencies": {
29
29
  "@solana/web3.js": "1.70.1",
30
- "@dynamic-labs/sdk-api": "0.0.389",
30
+ "@dynamic-labs/sdk-api": "0.0.397",
31
31
  "bs58": "5.0.0",
32
32
  "tweetnacl": "1.0.3",
33
- "@dynamic-labs/rpc-provider-solana": "2.0.0-alpha.21",
34
- "@dynamic-labs/rpc-providers": "2.0.0-alpha.21",
35
- "@dynamic-labs/turnkey": "2.0.0-alpha.21",
36
- "@dynamic-labs/types": "2.0.0-alpha.21",
37
- "@dynamic-labs/utils": "2.0.0-alpha.21",
38
- "@dynamic-labs/wallet-book": "2.0.0-alpha.21",
39
- "@dynamic-labs/wallet-connector-core": "2.0.0-alpha.21",
33
+ "@dynamic-labs/rpc-provider-solana": "2.0.0-alpha.23",
34
+ "@dynamic-labs/rpc-providers": "2.0.0-alpha.23",
35
+ "@dynamic-labs/turnkey": "2.0.0-alpha.23",
36
+ "@dynamic-labs/types": "2.0.0-alpha.23",
37
+ "@dynamic-labs/utils": "2.0.0-alpha.23",
38
+ "@dynamic-labs/wallet-book": "2.0.0-alpha.23",
39
+ "@dynamic-labs/wallet-connector-core": "2.0.0-alpha.23",
40
40
  "eventemitter3": "5.0.1"
41
41
  },
42
42
  "peerDependencies": {}
@@ -11,7 +11,6 @@ require('tweetnacl');
11
11
  require('bs58');
12
12
  require('@solana/web3.js');
13
13
  var InjectedWalletBase = require('./injected/InjectedWalletBase.cjs');
14
- require('@dynamic-labs/wallet-connector-core');
15
14
  var isSignedMessage = require('./utils/isSignedMessage.cjs');
16
15
 
17
16
  class CoinbaseSolana extends InjectedWalletBase.InjectedWalletBase {
@@ -7,7 +7,6 @@ import 'tweetnacl';
7
7
  import 'bs58';
8
8
  import '@solana/web3.js';
9
9
  import { InjectedWalletBase } from './injected/InjectedWalletBase.js';
10
- import '@dynamic-labs/wallet-connector-core';
11
10
  import { isSignedMessage } from './utils/isSignedMessage.js';
12
11
 
13
12
  class CoinbaseSolana extends InjectedWalletBase {
package/src/Solflare.cjs CHANGED
@@ -58,12 +58,12 @@ class Solflare extends InjectedWalletBase.InjectedWalletBase {
58
58
  });
59
59
  }
60
60
  getConnectedAccounts() {
61
- var _a, _b;
61
+ var _a;
62
62
  return _tslib.__awaiter(this, void 0, void 0, function* () {
63
- const provider = (_a = this.getSolProviderHelper()) === null || _a === void 0 ? void 0 : _a.findProvider();
63
+ const provider = this.getProvider();
64
64
  if (!provider)
65
65
  return [];
66
- const publicKey = (_b = provider.publicKey) === null || _b === void 0 ? void 0 : _b.toString();
66
+ const publicKey = (_a = provider.publicKey) === null || _a === void 0 ? void 0 : _a.toString();
67
67
  if (publicKey)
68
68
  return [publicKey];
69
69
  return [];
package/src/Solflare.js CHANGED
@@ -54,12 +54,12 @@ class Solflare extends InjectedWalletBase {
54
54
  });
55
55
  }
56
56
  getConnectedAccounts() {
57
- var _a, _b;
57
+ var _a;
58
58
  return __awaiter(this, void 0, void 0, function* () {
59
- const provider = (_a = this.getSolProviderHelper()) === null || _a === void 0 ? void 0 : _a.findProvider();
59
+ const provider = this.getProvider();
60
60
  if (!provider)
61
61
  return [];
62
- const publicKey = (_b = provider.publicKey) === null || _b === void 0 ? void 0 : _b.toString();
62
+ const publicKey = (_a = provider.publicKey) === null || _a === void 0 ? void 0 : _a.toString();
63
63
  if (publicKey)
64
64
  return [publicKey];
65
65
  return [];
@@ -18,6 +18,10 @@ class InjectedWalletBase extends solWalletConnector.SolWalletConnector {
18
18
  }
19
19
  return this.solProviderHelper;
20
20
  }
21
+ getProvider() {
22
+ var _a;
23
+ return (_a = this.getSolProviderHelper()) === null || _a === void 0 ? void 0 : _a.getInstalledProvider();
24
+ }
21
25
  setupEventListeners() {
22
26
  var _a;
23
27
  (_a = this.getSolProviderHelper()) === null || _a === void 0 ? void 0 : _a._setupEventListeners(this);
@@ -6,6 +6,7 @@ export declare abstract class InjectedWalletBase extends SolWalletConnector {
6
6
  solProviderHelper: SolProviderHelper | undefined;
7
7
  wallet: WalletSchema | undefined;
8
8
  getSolProviderHelper(): SolProviderHelper | undefined;
9
+ getProvider(): ISolana | undefined;
9
10
  setupEventListeners(): void;
10
11
  teardownEventListeners(): void;
11
12
  connect(): Promise<void>;
@@ -14,6 +14,10 @@ class InjectedWalletBase extends SolWalletConnector {
14
14
  }
15
15
  return this.solProviderHelper;
16
16
  }
17
+ getProvider() {
18
+ var _a;
19
+ return (_a = this.getSolProviderHelper()) === null || _a === void 0 ? void 0 : _a.getInstalledProvider();
20
+ }
17
21
  setupEventListeners() {
18
22
  var _a;
19
23
  (_a = this.getSolProviderHelper()) === null || _a === void 0 ? void 0 : _a._setupEventListeners(this);
@@ -3,20 +3,17 @@
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var CoinbaseSolana = require('../CoinbaseSolana.cjs');
6
- var Slope = require('../Slope.cjs');
7
6
  var Solflare = require('../Solflare.cjs');
8
7
  var InjectedWalletBase = require('./InjectedWalletBase.cjs');
9
8
  var BackpackSol = require('./BackpackSol.cjs');
10
9
 
11
10
  const injectedWalletOverrides = [
12
11
  CoinbaseSolana.CoinbaseSolana,
13
- Slope.Slope,
14
12
  BackpackSol.BackpackSol,
15
13
  Solflare.Solflare,
16
14
  ];
17
15
  const filteredInjectedWalletKeysOverrides = [
18
16
  'coinbasesolana',
19
- 'slope',
20
17
  'phantom',
21
18
  'phantomledger',
22
19
  'backpacksol',
@@ -1,18 +1,15 @@
1
1
  import { CoinbaseSolana } from '../CoinbaseSolana.js';
2
- import { Slope } from '../Slope.js';
3
2
  import { Solflare } from '../Solflare.js';
4
3
  import { InjectedWalletBase } from './InjectedWalletBase.js';
5
4
  import { BackpackSol } from './BackpackSol.js';
6
5
 
7
6
  const injectedWalletOverrides = [
8
7
  CoinbaseSolana,
9
- Slope,
10
8
  BackpackSol,
11
9
  Solflare,
12
10
  ];
13
11
  const filteredInjectedWalletKeysOverrides = [
14
12
  'coinbasesolana',
15
- 'slope',
16
13
  'phantom',
17
14
  'phantomledger',
18
15
  'backpacksol',
@@ -21,6 +21,9 @@ class PhantomRedirect extends solWalletConnector.SolWalletConnector {
21
21
  this.name = 'Phantom';
22
22
  this.overrideKey = 'phantom';
23
23
  }
24
+ getMethod() {
25
+ throw new Error('Method not implemented.');
26
+ }
24
27
  getAddress() {
25
28
  return _tslib.__awaiter(this, void 0, void 0, function* () {
26
29
  const address = storage.storage.address.get();
@@ -84,6 +87,7 @@ class PhantomRedirect extends solWalletConnector.SolWalletConnector {
84
87
  redirect_link: window.location.href,
85
88
  });
86
89
  const url = utils.buildUrl('signMessage', params);
90
+ storage.storage.method.set('signMessage');
87
91
  window.location.href = url;
88
92
  // throwing this to prevent local storage from being cleared.
89
93
  // when verifying signature, the SDK calls endSession when no
@@ -108,6 +112,31 @@ class PhantomRedirect extends solWalletConnector.SolWalletConnector {
108
112
  signature: signMessageData.signature,
109
113
  };
110
114
  }
115
+ extractTransactions() {
116
+ const params = new URLSearchParams(window.location.search);
117
+ const { data, nonce, sharedSecret } = this.getInputsOrThrow('extractTransactions', ['data', 'nonce'], ['sharedSecret']);
118
+ const signAllTransactionsData = utils.decryptPayload(data, nonce, sharedSecret);
119
+ const decodedTransactions = signAllTransactionsData.transactions.map((t) => web3_js.Transaction.from(bs58__default["default"].decode(t)));
120
+ params.delete('data');
121
+ params.delete('nonce');
122
+ history.replaceState(null, '', `${window.location.origin}${window.location.pathname}?${params.toString()}`);
123
+ return decodedTransactions;
124
+ }
125
+ extractTransaction() {
126
+ const params = new URLSearchParams(window.location.search);
127
+ const { data, nonce, sharedSecret } = this.getInputsOrThrow('extractTransaction', ['data', 'nonce'], ['sharedSecret']);
128
+ const signTransactionData = utils.decryptPayload(data, nonce, sharedSecret);
129
+ const decodedTransaction = web3_js.Transaction.from(bs58__default["default"].decode(signTransactionData.transaction));
130
+ params.delete('data');
131
+ params.delete('nonce');
132
+ history.replaceState(null, '', `${window.location.origin}${window.location.pathname}?${params.toString()}`);
133
+ return decodedTransaction;
134
+ }
135
+ consumeMethod() {
136
+ const method = storage.storage.method.get();
137
+ storage.storage.method.remove();
138
+ return method;
139
+ }
111
140
  getSigner() {
112
141
  return _tslib.__awaiter(this, void 0, void 0, function* () {
113
142
  const address = storage.storage.address.get();
@@ -161,18 +190,85 @@ class PhantomRedirect extends solWalletConnector.SolWalletConnector {
161
190
  removeListener: () => {
162
191
  throw new Error('Not implemented');
163
192
  },
164
- signAllTransactions: () => {
165
- throw new Error('Not implemented');
166
- },
167
- signAndSendTransaction: () => {
168
- throw new Error('Not implemented');
169
- },
170
- signMessage: () => {
171
- throw new Error('Not implemented');
172
- },
173
- signTransaction: () => {
174
- throw new Error('Not implemented');
175
- },
193
+ signAllTransactions: (transactions) => _tslib.__awaiter(this, void 0, void 0, function* () {
194
+ const serializedTransactions = transactions.map((t) => bs58__default["default"].encode(t.serialize({
195
+ requireAllSignatures: false,
196
+ })));
197
+ const { session, sharedSecret, encryptionPublicKey } = this.getInputsOrThrow('signAllTransactions', [], ['session', 'sharedSecret', 'encryptionPublicKey']);
198
+ const payload = {
199
+ session,
200
+ transactions: serializedTransactions,
201
+ };
202
+ const [nonce, encryptedPayload] = utils.encryptPayload(payload, sharedSecret);
203
+ const params = new URLSearchParams({
204
+ dapp_encryption_public_key: bs58__default["default"].encode(encryptionPublicKey),
205
+ nonce: bs58__default["default"].encode(nonce),
206
+ payload: bs58__default["default"].encode(encryptedPayload),
207
+ redirect_link: window.location.href,
208
+ });
209
+ const url = utils.buildUrl('signAllTransactions', params);
210
+ window.location.href = url;
211
+ // actual signatures will be retrieved upon redirect back to dapp
212
+ return [];
213
+ }),
214
+ signAndSendTransaction: (transaction, options) => _tslib.__awaiter(this, void 0, void 0, function* () {
215
+ const { session, sharedSecret, encryptionPublicKey } = this.getInputsOrThrow('signAndSendTransaction', [], ['session', 'sharedSecret', 'encryptionPublicKey']);
216
+ const payload = {
217
+ options,
218
+ session,
219
+ transaction: bs58__default["default"].encode(transaction.serialize({ requireAllSignatures: false })),
220
+ };
221
+ const [nonce, encryptedPayload] = utils.encryptPayload(payload, sharedSecret);
222
+ const params = new URLSearchParams({
223
+ dapp_encryption_public_key: bs58__default["default"].encode(encryptionPublicKey),
224
+ nonce: bs58__default["default"].encode(nonce),
225
+ payload: bs58__default["default"].encode(encryptedPayload),
226
+ redirect_link: window.location.href,
227
+ });
228
+ const url = utils.buildUrl('signAndSendTransaction', params);
229
+ storage.storage.method.set('signAndSendTransaction');
230
+ window.location.href = url;
231
+ // actual signature will be retrived upon redirect back to dapp
232
+ return { signature: '' };
233
+ }),
234
+ signMessage: (message) => _tslib.__awaiter(this, void 0, void 0, function* () {
235
+ const { session, sharedSecret, encryptionPublicKey } = this.getInputsOrThrow('signMessage', [], ['session', 'sharedSecret', 'encryptionPublicKey']);
236
+ const payload = {
237
+ message: bs58__default["default"].encode(Buffer.from(message)),
238
+ session,
239
+ };
240
+ const [nonce, encryptedPayload] = utils.encryptPayload(payload, sharedSecret);
241
+ const params = new URLSearchParams({
242
+ dapp_encryption_public_key: bs58__default["default"].encode(encryptionPublicKey),
243
+ nonce: bs58__default["default"].encode(nonce),
244
+ payload: bs58__default["default"].encode(encryptedPayload),
245
+ redirect_link: window.location.href,
246
+ });
247
+ const url = utils.buildUrl('signMessage', params);
248
+ window.location.href = url;
249
+ // actual signature will be retrived upon redirect back to dapp
250
+ return Buffer.from('');
251
+ }),
252
+ signTransaction: (transaction) => _tslib.__awaiter(this, void 0, void 0, function* () {
253
+ const serializedTransaction = bs58__default["default"].encode(transaction.serialize({
254
+ requireAllSignatures: false,
255
+ }));
256
+ const { session, sharedSecret, encryptionPublicKey } = this.getInputsOrThrow('signTransaction', [], ['session', 'sharedSecret', 'encryptionPublicKey']);
257
+ const payload = {
258
+ session,
259
+ transaction: serializedTransaction,
260
+ };
261
+ const [nonce, encryptedPayload] = utils.encryptPayload(payload, sharedSecret);
262
+ const params = new URLSearchParams({
263
+ dapp_encryption_public_key: bs58__default["default"].encode(encryptionPublicKey),
264
+ nonce: bs58__default["default"].encode(nonce),
265
+ payload: bs58__default["default"].encode(encryptedPayload),
266
+ redirect_link: window.location.href,
267
+ });
268
+ const url = utils.buildUrl('signTransaction', params);
269
+ window.location.href = url;
270
+ return transaction;
271
+ }),
176
272
  };
177
273
  });
178
274
  }
@@ -1,10 +1,13 @@
1
+ import { Transaction } from '@solana/web3.js';
1
2
  import { IPhantomRedirectConnector } from '@dynamic-labs/wallet-connector-core';
2
3
  import { SolWalletConnector } from '../solWalletConnector';
3
4
  import { ISolana } from '..';
5
+ import { Method } from './types';
4
6
  export declare class PhantomRedirect extends SolWalletConnector implements IPhantomRedirectConnector {
5
7
  name: string;
6
8
  overrideKey: string;
7
9
  constructor(props: any);
10
+ getMethod(): 'signMessage' | 'signAndSendTransaction' | undefined;
8
11
  getAddress(): Promise<string | undefined>;
9
12
  connect(): Promise<void>;
10
13
  getSession(): Promise<string>;
@@ -13,6 +16,9 @@ export declare class PhantomRedirect extends SolWalletConnector implements IPhan
13
16
  signature: string;
14
17
  message: string;
15
18
  };
19
+ extractTransactions(): Transaction[];
20
+ extractTransaction(): Transaction;
21
+ consumeMethod(): Method | undefined;
16
22
  getSigner(): Promise<ISolana | undefined>;
17
23
  getConnectedAccounts(): Promise<string[]>;
18
24
  endSession(): Promise<void>;
@@ -1,7 +1,7 @@
1
1
  import { __awaiter } from '../../_virtual/_tslib.js';
2
2
  import nacl from 'tweetnacl';
3
3
  import bs58 from 'bs58';
4
- import { PublicKey } from '@solana/web3.js';
4
+ import { PublicKey, Transaction } from '@solana/web3.js';
5
5
  import { SolWalletConnector } from '../solWalletConnector.js';
6
6
  import { fetchCluster, buildUrl, decryptPayload, encryptPayload } from './utils.js';
7
7
  import { storage, clearStorage } from './storage.js';
@@ -12,6 +12,9 @@ class PhantomRedirect extends SolWalletConnector {
12
12
  this.name = 'Phantom';
13
13
  this.overrideKey = 'phantom';
14
14
  }
15
+ getMethod() {
16
+ throw new Error('Method not implemented.');
17
+ }
15
18
  getAddress() {
16
19
  return __awaiter(this, void 0, void 0, function* () {
17
20
  const address = storage.address.get();
@@ -75,6 +78,7 @@ class PhantomRedirect extends SolWalletConnector {
75
78
  redirect_link: window.location.href,
76
79
  });
77
80
  const url = buildUrl('signMessage', params);
81
+ storage.method.set('signMessage');
78
82
  window.location.href = url;
79
83
  // throwing this to prevent local storage from being cleared.
80
84
  // when verifying signature, the SDK calls endSession when no
@@ -99,6 +103,31 @@ class PhantomRedirect extends SolWalletConnector {
99
103
  signature: signMessageData.signature,
100
104
  };
101
105
  }
106
+ extractTransactions() {
107
+ const params = new URLSearchParams(window.location.search);
108
+ const { data, nonce, sharedSecret } = this.getInputsOrThrow('extractTransactions', ['data', 'nonce'], ['sharedSecret']);
109
+ const signAllTransactionsData = decryptPayload(data, nonce, sharedSecret);
110
+ const decodedTransactions = signAllTransactionsData.transactions.map((t) => Transaction.from(bs58.decode(t)));
111
+ params.delete('data');
112
+ params.delete('nonce');
113
+ history.replaceState(null, '', `${window.location.origin}${window.location.pathname}?${params.toString()}`);
114
+ return decodedTransactions;
115
+ }
116
+ extractTransaction() {
117
+ const params = new URLSearchParams(window.location.search);
118
+ const { data, nonce, sharedSecret } = this.getInputsOrThrow('extractTransaction', ['data', 'nonce'], ['sharedSecret']);
119
+ const signTransactionData = decryptPayload(data, nonce, sharedSecret);
120
+ const decodedTransaction = Transaction.from(bs58.decode(signTransactionData.transaction));
121
+ params.delete('data');
122
+ params.delete('nonce');
123
+ history.replaceState(null, '', `${window.location.origin}${window.location.pathname}?${params.toString()}`);
124
+ return decodedTransaction;
125
+ }
126
+ consumeMethod() {
127
+ const method = storage.method.get();
128
+ storage.method.remove();
129
+ return method;
130
+ }
102
131
  getSigner() {
103
132
  return __awaiter(this, void 0, void 0, function* () {
104
133
  const address = storage.address.get();
@@ -152,18 +181,85 @@ class PhantomRedirect extends SolWalletConnector {
152
181
  removeListener: () => {
153
182
  throw new Error('Not implemented');
154
183
  },
155
- signAllTransactions: () => {
156
- throw new Error('Not implemented');
157
- },
158
- signAndSendTransaction: () => {
159
- throw new Error('Not implemented');
160
- },
161
- signMessage: () => {
162
- throw new Error('Not implemented');
163
- },
164
- signTransaction: () => {
165
- throw new Error('Not implemented');
166
- },
184
+ signAllTransactions: (transactions) => __awaiter(this, void 0, void 0, function* () {
185
+ const serializedTransactions = transactions.map((t) => bs58.encode(t.serialize({
186
+ requireAllSignatures: false,
187
+ })));
188
+ const { session, sharedSecret, encryptionPublicKey } = this.getInputsOrThrow('signAllTransactions', [], ['session', 'sharedSecret', 'encryptionPublicKey']);
189
+ const payload = {
190
+ session,
191
+ transactions: serializedTransactions,
192
+ };
193
+ const [nonce, encryptedPayload] = encryptPayload(payload, sharedSecret);
194
+ const params = new URLSearchParams({
195
+ dapp_encryption_public_key: bs58.encode(encryptionPublicKey),
196
+ nonce: bs58.encode(nonce),
197
+ payload: bs58.encode(encryptedPayload),
198
+ redirect_link: window.location.href,
199
+ });
200
+ const url = buildUrl('signAllTransactions', params);
201
+ window.location.href = url;
202
+ // actual signatures will be retrieved upon redirect back to dapp
203
+ return [];
204
+ }),
205
+ signAndSendTransaction: (transaction, options) => __awaiter(this, void 0, void 0, function* () {
206
+ const { session, sharedSecret, encryptionPublicKey } = this.getInputsOrThrow('signAndSendTransaction', [], ['session', 'sharedSecret', 'encryptionPublicKey']);
207
+ const payload = {
208
+ options,
209
+ session,
210
+ transaction: bs58.encode(transaction.serialize({ requireAllSignatures: false })),
211
+ };
212
+ const [nonce, encryptedPayload] = encryptPayload(payload, sharedSecret);
213
+ const params = new URLSearchParams({
214
+ dapp_encryption_public_key: bs58.encode(encryptionPublicKey),
215
+ nonce: bs58.encode(nonce),
216
+ payload: bs58.encode(encryptedPayload),
217
+ redirect_link: window.location.href,
218
+ });
219
+ const url = buildUrl('signAndSendTransaction', params);
220
+ storage.method.set('signAndSendTransaction');
221
+ window.location.href = url;
222
+ // actual signature will be retrived upon redirect back to dapp
223
+ return { signature: '' };
224
+ }),
225
+ signMessage: (message) => __awaiter(this, void 0, void 0, function* () {
226
+ const { session, sharedSecret, encryptionPublicKey } = this.getInputsOrThrow('signMessage', [], ['session', 'sharedSecret', 'encryptionPublicKey']);
227
+ const payload = {
228
+ message: bs58.encode(Buffer.from(message)),
229
+ session,
230
+ };
231
+ const [nonce, encryptedPayload] = encryptPayload(payload, sharedSecret);
232
+ const params = new URLSearchParams({
233
+ dapp_encryption_public_key: bs58.encode(encryptionPublicKey),
234
+ nonce: bs58.encode(nonce),
235
+ payload: bs58.encode(encryptedPayload),
236
+ redirect_link: window.location.href,
237
+ });
238
+ const url = buildUrl('signMessage', params);
239
+ window.location.href = url;
240
+ // actual signature will be retrived upon redirect back to dapp
241
+ return Buffer.from('');
242
+ }),
243
+ signTransaction: (transaction) => __awaiter(this, void 0, void 0, function* () {
244
+ const serializedTransaction = bs58.encode(transaction.serialize({
245
+ requireAllSignatures: false,
246
+ }));
247
+ const { session, sharedSecret, encryptionPublicKey } = this.getInputsOrThrow('signTransaction', [], ['session', 'sharedSecret', 'encryptionPublicKey']);
248
+ const payload = {
249
+ session,
250
+ transaction: serializedTransaction,
251
+ };
252
+ const [nonce, encryptedPayload] = encryptPayload(payload, sharedSecret);
253
+ const params = new URLSearchParams({
254
+ dapp_encryption_public_key: bs58.encode(encryptionPublicKey),
255
+ nonce: bs58.encode(nonce),
256
+ payload: bs58.encode(encryptedPayload),
257
+ redirect_link: window.location.href,
258
+ });
259
+ const url = buildUrl('signTransaction', params);
260
+ window.location.href = url;
261
+ return transaction;
262
+ }),
167
263
  };
168
264
  });
169
265
  }
@@ -51,6 +51,15 @@ const storage = {
51
51
  localStorage.setItem('dynamic_phantom_message_to_sign', message);
52
52
  },
53
53
  },
54
+ method: {
55
+ get: () => { var _a; return (_a = localStorage.getItem('dynamic_phantom_method')) !== null && _a !== void 0 ? _a : undefined; },
56
+ remove: () => {
57
+ localStorage.removeItem('dynamic_phantom_method');
58
+ },
59
+ set: (method) => {
60
+ localStorage.setItem('dynamic_phantom_method', method);
61
+ },
62
+ },
54
63
  session: {
55
64
  get: () => { var _a; return (_a = localStorage.getItem('dynamic_phantom_session')) !== null && _a !== void 0 ? _a : undefined; },
56
65
  remove: () => {
@@ -1,4 +1,5 @@
1
1
  import { PublicKey } from '@solana/web3.js';
2
+ import { Method } from './types';
2
3
  export declare const storage: {
3
4
  address: {
4
5
  get: () => string | undefined;
@@ -20,6 +21,11 @@ export declare const storage: {
20
21
  remove: () => void;
21
22
  set: (message: string) => void;
22
23
  };
24
+ method: {
25
+ get: () => Method | undefined;
26
+ remove: () => void;
27
+ set: (method: Method) => void;
28
+ };
23
29
  session: {
24
30
  get: () => string | undefined;
25
31
  remove: () => void;
@@ -47,6 +47,15 @@ const storage = {
47
47
  localStorage.setItem('dynamic_phantom_message_to_sign', message);
48
48
  },
49
49
  },
50
+ method: {
51
+ get: () => { var _a; return (_a = localStorage.getItem('dynamic_phantom_method')) !== null && _a !== void 0 ? _a : undefined; },
52
+ remove: () => {
53
+ localStorage.removeItem('dynamic_phantom_method');
54
+ },
55
+ set: (method) => {
56
+ localStorage.setItem('dynamic_phantom_method', method);
57
+ },
58
+ },
50
59
  session: {
51
60
  get: () => { var _a; return (_a = localStorage.getItem('dynamic_phantom_session')) !== null && _a !== void 0 ? _a : undefined; },
52
61
  remove: () => {
@@ -0,0 +1 @@
1
+ export type Method = 'signMessage' | 'signAndSendTransaction';
package/src/types.d.ts CHANGED
@@ -6,9 +6,6 @@ declare global {
6
6
  solana: ISolana;
7
7
  }
8
8
  interface Window {
9
- Slope?: {
10
- new (): ISolana;
11
- };
12
9
  coinbaseSolana?: ICoinbaseSolanaSigner;
13
10
  glowSolana?: ISolana;
14
11
  phantom?: IWindowPhantom;
package/src/Slope.cjs DELETED
@@ -1,99 +0,0 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
- var _tslib = require('../_virtual/_tslib.cjs');
6
- var web3_js = require('@solana/web3.js');
7
- var walletConnectorCore = require('@dynamic-labs/wallet-connector-core');
8
- var solWalletConnector = require('./solWalletConnector.cjs');
9
-
10
- class Slope extends solWalletConnector.SolWalletConnector {
11
- constructor() {
12
- super(...arguments);
13
- this.name = 'Slope';
14
- this.overrideKey = 'slope';
15
- this.isConnectData = (value) => { var _a; return ((_a = value.data) === null || _a === void 0 ? void 0 : _a.publicKey) !== undefined; };
16
- this.isSignatureData = (value) => { var _a; return ((_a = value.data) === null || _a === void 0 ? void 0 : _a.signature) !== undefined; };
17
- }
18
- get wallet() {
19
- if (!window.Slope) {
20
- return undefined;
21
- }
22
- if (!Slope._wallet) {
23
- Slope._wallet = new window.Slope();
24
- }
25
- return Slope._wallet;
26
- }
27
- connect() {
28
- return _tslib.__awaiter(this, void 0, void 0, function* () {
29
- if (this.wallet === undefined)
30
- return;
31
- yield this.wallet.connect();
32
- });
33
- }
34
- getSigner() {
35
- return _tslib.__awaiter(this, void 0, void 0, function* () {
36
- return undefined;
37
- });
38
- }
39
- getBalance() {
40
- return _tslib.__awaiter(this, void 0, void 0, function* () {
41
- try {
42
- if (this.wallet === undefined)
43
- return undefined;
44
- const response = yield this.wallet.connect();
45
- const publicKey = new web3_js.PublicKey(this.isConnectData(response) && response.data.publicKey);
46
- const balance = this.lamportsToSol(yield this.getWalletClient().getBalance(publicKey));
47
- return balance.toString();
48
- }
49
- catch (e) {
50
- walletConnectorCore.logger.debug(e);
51
- return undefined;
52
- }
53
- });
54
- }
55
- isInstalledOnBrowser() {
56
- return typeof window.Slope === 'function';
57
- }
58
- getAddress() {
59
- return _tslib.__awaiter(this, void 0, void 0, function* () {
60
- try {
61
- if (this.wallet === undefined)
62
- return undefined;
63
- const response = yield this.wallet.connect();
64
- return this.isConnectData(response) ? response.data.publicKey : undefined;
65
- }
66
- catch (e) {
67
- walletConnectorCore.logger.debug(e);
68
- return undefined;
69
- }
70
- });
71
- }
72
- signMessage(messageToSign) {
73
- return _tslib.__awaiter(this, void 0, void 0, function* () {
74
- const encodedMessage = new TextEncoder().encode(messageToSign);
75
- try {
76
- if (this.wallet === undefined)
77
- return undefined;
78
- const response = yield this.wallet.signMessage(encodedMessage);
79
- return this.isSignatureData(response)
80
- ? response.data.signature
81
- : undefined;
82
- }
83
- catch (e) {
84
- walletConnectorCore.logger.debug(e);
85
- return undefined;
86
- }
87
- });
88
- }
89
- getConnectedAccounts() {
90
- return _tslib.__awaiter(this, void 0, void 0, function* () {
91
- if (this.wallet === undefined)
92
- return [];
93
- const response = yield this.wallet.connect();
94
- return this.isConnectData(response) ? [response.data.publicKey] : [];
95
- });
96
- }
97
- }
98
-
99
- exports.Slope = Slope;
package/src/Slope.d.ts DELETED
@@ -1,28 +0,0 @@
1
- import { SolWalletConnector } from './solWalletConnector';
2
- import { ISolana } from './types';
3
- interface ConnectData {
4
- data: {
5
- publicKey: string;
6
- };
7
- }
8
- interface SignatureData {
9
- data: {
10
- signature: string;
11
- };
12
- }
13
- export declare class Slope extends SolWalletConnector {
14
- name: string;
15
- overrideKey: string;
16
- private static _wallet;
17
- get wallet(): ISolana | undefined;
18
- connect(): Promise<void>;
19
- getSigner(): Promise<undefined>;
20
- getBalance(): Promise<string | undefined>;
21
- isInstalledOnBrowser(): boolean;
22
- isConnectData: (value: unknown) => value is ConnectData;
23
- isSignatureData: (value: unknown) => value is SignatureData;
24
- getAddress(): Promise<string | undefined>;
25
- signMessage(messageToSign: string): Promise<string | undefined>;
26
- getConnectedAccounts(): Promise<string[]>;
27
- }
28
- export {};
package/src/Slope.js DELETED
@@ -1,95 +0,0 @@
1
- import { __awaiter } from '../_virtual/_tslib.js';
2
- import { PublicKey } from '@solana/web3.js';
3
- import { logger } from '@dynamic-labs/wallet-connector-core';
4
- import { SolWalletConnector } from './solWalletConnector.js';
5
-
6
- class Slope extends SolWalletConnector {
7
- constructor() {
8
- super(...arguments);
9
- this.name = 'Slope';
10
- this.overrideKey = 'slope';
11
- this.isConnectData = (value) => { var _a; return ((_a = value.data) === null || _a === void 0 ? void 0 : _a.publicKey) !== undefined; };
12
- this.isSignatureData = (value) => { var _a; return ((_a = value.data) === null || _a === void 0 ? void 0 : _a.signature) !== undefined; };
13
- }
14
- get wallet() {
15
- if (!window.Slope) {
16
- return undefined;
17
- }
18
- if (!Slope._wallet) {
19
- Slope._wallet = new window.Slope();
20
- }
21
- return Slope._wallet;
22
- }
23
- connect() {
24
- return __awaiter(this, void 0, void 0, function* () {
25
- if (this.wallet === undefined)
26
- return;
27
- yield this.wallet.connect();
28
- });
29
- }
30
- getSigner() {
31
- return __awaiter(this, void 0, void 0, function* () {
32
- return undefined;
33
- });
34
- }
35
- getBalance() {
36
- return __awaiter(this, void 0, void 0, function* () {
37
- try {
38
- if (this.wallet === undefined)
39
- return undefined;
40
- const response = yield this.wallet.connect();
41
- const publicKey = new PublicKey(this.isConnectData(response) && response.data.publicKey);
42
- const balance = this.lamportsToSol(yield this.getWalletClient().getBalance(publicKey));
43
- return balance.toString();
44
- }
45
- catch (e) {
46
- logger.debug(e);
47
- return undefined;
48
- }
49
- });
50
- }
51
- isInstalledOnBrowser() {
52
- return typeof window.Slope === 'function';
53
- }
54
- getAddress() {
55
- return __awaiter(this, void 0, void 0, function* () {
56
- try {
57
- if (this.wallet === undefined)
58
- return undefined;
59
- const response = yield this.wallet.connect();
60
- return this.isConnectData(response) ? response.data.publicKey : undefined;
61
- }
62
- catch (e) {
63
- logger.debug(e);
64
- return undefined;
65
- }
66
- });
67
- }
68
- signMessage(messageToSign) {
69
- return __awaiter(this, void 0, void 0, function* () {
70
- const encodedMessage = new TextEncoder().encode(messageToSign);
71
- try {
72
- if (this.wallet === undefined)
73
- return undefined;
74
- const response = yield this.wallet.signMessage(encodedMessage);
75
- return this.isSignatureData(response)
76
- ? response.data.signature
77
- : undefined;
78
- }
79
- catch (e) {
80
- logger.debug(e);
81
- return undefined;
82
- }
83
- });
84
- }
85
- getConnectedAccounts() {
86
- return __awaiter(this, void 0, void 0, function* () {
87
- if (this.wallet === undefined)
88
- return [];
89
- const response = yield this.wallet.connect();
90
- return this.isConnectData(response) ? [response.data.publicKey] : [];
91
- });
92
- }
93
- }
94
-
95
- export { Slope };