@dynamic-labs/solana 1.1.0-alpha.9 → 1.1.0-phantom.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.
Files changed (48) hide show
  1. package/CHANGELOG.md +57 -0
  2. package/package.json +8 -6
  3. package/src/CoinbaseSolana.cjs +9 -33
  4. package/src/CoinbaseSolana.d.ts +5 -10
  5. package/src/CoinbaseSolana.js +9 -33
  6. package/src/PhantomMobileConnector.cjs +168 -0
  7. package/src/PhantomMobileConnector.d.ts +17 -0
  8. package/src/PhantomMobileConnector.js +159 -0
  9. package/src/Solflare.d.ts +4 -9
  10. package/src/index.cjs +3 -16
  11. package/src/index.d.ts +1 -4
  12. package/src/index.js +3 -14
  13. package/src/injected/BackpackSol.cjs +6 -21
  14. package/src/injected/BackpackSol.d.ts +3 -5
  15. package/src/injected/BackpackSol.js +6 -21
  16. package/src/injected/InjectedWalletBase.cjs +36 -16
  17. package/src/injected/InjectedWalletBase.d.ts +9 -2
  18. package/src/injected/InjectedWalletBase.js +36 -16
  19. package/src/injected/{Phantom.cjs → PhantomInjected.cjs} +6 -4
  20. package/src/injected/PhantomInjected.d.ts +7 -0
  21. package/src/injected/{Phantom.js → PhantomInjected.js} +6 -4
  22. package/src/injected/PhantomLedger.cjs +4 -2
  23. package/src/injected/PhantomLedger.d.ts +2 -0
  24. package/src/injected/PhantomLedger.js +4 -2
  25. package/src/injected/fetchInjectedWalletConnectors.cjs +50 -0
  26. package/src/injected/fetchInjectedWalletConnectors.d.ts +6 -0
  27. package/src/injected/fetchInjectedWalletConnectors.js +45 -0
  28. package/src/injected/index.d.ts +1 -2
  29. package/src/solProviderHelper.cjs +99 -114
  30. package/src/solProviderHelper.d.ts +28 -29
  31. package/src/solProviderHelper.js +99 -114
  32. package/src/Glow.cjs +0 -50
  33. package/src/Glow.d.ts +0 -12
  34. package/src/Glow.js +0 -46
  35. package/src/Solflare.cjs +0 -83
  36. package/src/Solflare.js +0 -79
  37. package/src/injected/BraveSol.cjs +0 -21
  38. package/src/injected/BraveSol.d.ts +0 -5
  39. package/src/injected/BraveSol.js +0 -17
  40. package/src/injected/ExodusSol.cjs +0 -14
  41. package/src/injected/ExodusSol.d.ts +0 -4
  42. package/src/injected/ExodusSol.js +0 -10
  43. package/src/injected/MagicEdenSol.cjs +0 -14
  44. package/src/injected/MagicEdenSol.d.ts +0 -4
  45. package/src/injected/MagicEdenSol.js +0 -10
  46. package/src/injected/Phantom.d.ts +0 -5
  47. package/src/injected/index.cjs +0 -21
  48. package/src/injected/index.js +0 -17
package/CHANGELOG.md CHANGED
@@ -1,4 +1,61 @@
1
1
 
2
+ ## [1.1.0-phantom.0](https://github.com/dynamic-labs/DynamicAuth/compare/v1.1.0-alpha.12...v1.1.0-phantom.0) (2024-01-22)
3
+
4
+
5
+ ### Features
6
+
7
+ * add createWalletClientFromWallet helper function ([#4416](https://github.com/dynamic-labs/DynamicAuth/issues/4416)) ([b384898](https://github.com/dynamic-labs/DynamicAuth/commit/b384898061bb3f9b38b2ed670b6650cfc1d4b429))
8
+ * add hardware wallets to wallet book ([#4445](https://github.com/dynamic-labs/DynamicAuth/issues/4445)) ([66c0f5b](https://github.com/dynamic-labs/DynamicAuth/commit/66c0f5b29a6a700099bb95a6f7622f6178e0bccf))
9
+ * add redirect based phantom deeplinking ([c40dfd2](https://github.com/dynamic-labs/DynamicAuth/commit/c40dfd21d0692b9d33593d564ae6879ab15547e2))
10
+
11
+
12
+ ### Bug Fixes
13
+
14
+ * breaking changes script ([#4440](https://github.com/dynamic-labs/DynamicAuth/issues/4440)) ([446173d](https://github.com/dynamic-labs/DynamicAuth/commit/446173d074d652d81856c6412e304b46b1565320))
15
+ * broken help icon in create passkey view ([#4428](https://github.com/dynamic-labs/DynamicAuth/issues/4428)) ([e0ffc02](https://github.com/dynamic-labs/DynamicAuth/commit/e0ffc02ffea34b7ac3198ff6e1baf7f9907acddd))
16
+
17
+ ## [1.1.0-alpha.12](https://github.com/dynamic-labs/DynamicAuth/compare/v1.1.0-alpha.11...v1.1.0-alpha.12) (2024-01-18)
18
+
19
+
20
+ ### Features
21
+
22
+ * expose setAuthMode method ([#4419](https://github.com/dynamic-labs/DynamicAuth/issues/4419)) ([7d156b3](https://github.com/dynamic-labs/DynamicAuth/commit/7d156b3e0eab9b9a80f70ff1c5201d90693ae755))
23
+
24
+
25
+ ### Bug Fixes
26
+
27
+ * call onUnlinkSuccess in headless mode too ([#4412](https://github.com/dynamic-labs/DynamicAuth/issues/4412)) ([4c76af9](https://github.com/dynamic-labs/DynamicAuth/commit/4c76af9ac7c7b43883742d1289558dfcb5d612ca))
28
+ * correctly map keplr chain ids from project settings ([#4418](https://github.com/dynamic-labs/DynamicAuth/issues/4418)) ([7046364](https://github.com/dynamic-labs/DynamicAuth/commit/7046364a316f7551f0b995eaae7afea13502eb9b))
29
+ * logging in with an email linked to a third party wallet gets stuck on otp view ([#4407](https://github.com/dynamic-labs/DynamicAuth/issues/4407)) ([35bf142](https://github.com/dynamic-labs/DynamicAuth/commit/35bf142e74efeef866dbd7b8157a049cd36eeccb))
30
+
31
+ ## [1.1.0-alpha.11](https://github.com/dynamic-labs/DynamicAuth/compare/v1.1.0-alpha.10...v1.1.0-alpha.11) (2024-01-17)
32
+
33
+
34
+ ### Features
35
+
36
+ * add Leather wallet and BtcKit connector ([#4335](https://github.com/dynamic-labs/DynamicAuth/issues/4335)) ([fe3316b](https://github.com/dynamic-labs/DynamicAuth/commit/fe3316b5be9ef17eea885e99cf925ccd0f271da7))
37
+ * add solana injected wallet configuration to walletbook ([#4375](https://github.com/dynamic-labs/DynamicAuth/issues/4375)) ([3677ce5](https://github.com/dynamic-labs/DynamicAuth/commit/3677ce5ff40d0c00bfaf0daa0d5d67bc40706ee0))
38
+ * add support for unisat wallet ([#4355](https://github.com/dynamic-labs/DynamicAuth/issues/4355)) ([5b7d6b0](https://github.com/dynamic-labs/DynamicAuth/commit/5b7d6b0a9ea84811a8252b3cdf30a3a8e410180c))
39
+ * add walletbook configurations for solana injected wallets ([#4360](https://github.com/dynamic-labs/DynamicAuth/issues/4360)) ([cdc8e5f](https://github.com/dynamic-labs/DynamicAuth/commit/cdc8e5f4878cb84e26e5b33299aa8547b84b6667))
40
+ * passkey renaming frontend ([#4331](https://github.com/dynamic-labs/DynamicAuth/issues/4331)) ([4551013](https://github.com/dynamic-labs/DynamicAuth/commit/4551013d577c914cb3aedfe458ab9eaa018aceb4))
41
+
42
+
43
+ ### Bug Fixes
44
+
45
+ * correctly update wallets connected flag after wallet switch ([#4397](https://github.com/dynamic-labs/DynamicAuth/issues/4397)) ([543a830](https://github.com/dynamic-labs/DynamicAuth/commit/543a830574f0d5a78fedbb9b18233e8dfbaddd86))
46
+ * export modal header ([#4401](https://github.com/dynamic-labs/DynamicAuth/issues/4401)) ([77cf016](https://github.com/dynamic-labs/DynamicAuth/commit/77cf016fc742458988864647870149a56e991ee4))
47
+ * trigger onAuthSuccess before embedded wallet creation ([4aa341a](https://github.com/dynamic-labs/DynamicAuth/commit/4aa341a1d08332a121daddb7c2dcb09a804a4de7))
48
+ * ui issues on react 17 ([#4373](https://github.com/dynamic-labs/DynamicAuth/issues/4373)) ([93096d6](https://github.com/dynamic-labs/DynamicAuth/commit/93096d6017816a4f0ed299bf618b130d90c81514))
49
+
50
+ ## [1.1.0-alpha.10](https://github.com/dynamic-labs/DynamicAuth/compare/v1.1.0-alpha.9...v1.1.0-alpha.10) (2024-01-06)
51
+
52
+
53
+ ### Bug Fixes
54
+
55
+ * pass flow network to magic client ([#4322](https://github.com/dynamic-labs/DynamicAuth/issues/4322)) ([f3adccf](https://github.com/dynamic-labs/DynamicAuth/commit/f3adccf9f8d835f6b04e4767acd0fbd2ac238379))
56
+ * prevent error message when mobile wallet app is open ([#4301](https://github.com/dynamic-labs/DynamicAuth/issues/4301)) ([2a66dcf](https://github.com/dynamic-labs/DynamicAuth/commit/2a66dcfaf8100b3d910c559d35d8b731b1cb380e))
57
+ * turnkeyWalletConnector is not an email otp connector and uses dynamic otp ([#4313](https://github.com/dynamic-labs/DynamicAuth/issues/4313)) ([e4ea56f](https://github.com/dynamic-labs/DynamicAuth/commit/e4ea56f40fdf97b3f5440b016ebd95501089cebe))
58
+
2
59
  ## [1.1.0-alpha.9](https://github.com/dynamic-labs/DynamicAuth/compare/v1.1.0-alpha.8...v1.1.0-alpha.9) (2024-01-04)
3
60
 
4
61
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dynamic-labs/solana",
3
- "version": "1.1.0-alpha.9",
3
+ "version": "1.1.0-phantom.0",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/dynamic-labs/DynamicAuth.git",
@@ -27,11 +27,13 @@
27
27
  },
28
28
  "dependencies": {
29
29
  "@solana/web3.js": "1.70.1",
30
- "@dynamic-labs/rpc-providers": "1.1.0-alpha.9",
31
- "@dynamic-labs/types": "1.1.0-alpha.9",
32
- "@dynamic-labs/utils": "1.1.0-alpha.9",
33
- "@dynamic-labs/wallet-book": "1.1.0-alpha.9",
34
- "@dynamic-labs/wallet-connector-core": "1.1.0-alpha.9",
30
+ "bs58": "^5.0.0",
31
+ "tweetnacl": "^1.0.3",
32
+ "@dynamic-labs/rpc-providers": "1.1.0-phantom.0",
33
+ "@dynamic-labs/types": "1.1.0-phantom.0",
34
+ "@dynamic-labs/utils": "1.1.0-phantom.0",
35
+ "@dynamic-labs/wallet-book": "1.1.0-phantom.0",
36
+ "@dynamic-labs/wallet-connector-core": "1.1.0-phantom.0",
35
37
  "eventemitter3": "5.0.1"
36
38
  },
37
39
  "peerDependencies": {}
@@ -4,43 +4,24 @@ Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var _tslib = require('../_virtual/_tslib.cjs');
6
6
  var utils = require('@dynamic-labs/utils');
7
- var solWalletConnector = require('./solWalletConnector.cjs');
8
- var solProviderHelper = require('./solProviderHelper.cjs');
7
+ var walletBook = require('@dynamic-labs/wallet-book');
8
+ var InjectedWalletBase = require('./injected/InjectedWalletBase.cjs');
9
9
  require('@solana/web3.js');
10
10
  require('@dynamic-labs/wallet-connector-core');
11
+ require('@dynamic-labs/rpc-providers');
11
12
  require('./injected/PhantomLedger.cjs');
12
13
  var isSignedMessage = require('./utils/isSignedMessage.cjs');
13
14
 
14
- class CoinbaseSolana extends solWalletConnector.SolWalletConnector {
15
- constructor() {
16
- super(...arguments);
15
+ class CoinbaseSolana extends InjectedWalletBase.InjectedWalletBase {
16
+ constructor(opts) {
17
+ super(opts);
17
18
  this.name = 'CoinbaseSolana';
18
- }
19
- setupEventListeners() {
20
- solProviderHelper.SolProviderHelper._setupEventListeners(this, solProviderHelper.SolProviderHelper.findProvider(this.key));
21
- }
22
- teardownEventListeners() {
23
- solProviderHelper.SolProviderHelper._teardownEventListeners(this.key);
24
- }
25
- connect() {
26
- return _tslib.__awaiter(this, void 0, void 0, function* () {
27
- yield solProviderHelper.SolProviderHelper.connectWithKey(this.key);
28
- });
19
+ this.wallet = walletBook.findWalletBookWallet(this.walletBook, this.key);
29
20
  }
30
21
  getSigner() {
22
+ var _a;
31
23
  return _tslib.__awaiter(this, void 0, void 0, function* () {
32
- return solProviderHelper.SolProviderHelper.connectWithKey(this.key);
33
- });
34
- }
35
- isInstalledOnBrowser() {
36
- return solProviderHelper.SolProviderHelper.isInstalledHelper(this.key);
37
- }
38
- fetchPublicAddress() {
39
- return _tslib.__awaiter(this, void 0, void 0, function* () {
40
- if (this.isInstalledOnBrowser()) {
41
- return solProviderHelper.SolProviderHelper.fetchPublicAddressWithKey(this.key);
42
- }
43
- return;
24
+ return (_a = this.getSolProviderHelper()) === null || _a === void 0 ? void 0 : _a.connect();
44
25
  });
45
26
  }
46
27
  signMessage(messageToSign) {
@@ -61,11 +42,6 @@ class CoinbaseSolana extends solWalletConnector.SolWalletConnector {
61
42
  return utils.bufferToBase64(isSignedMessage.isSignedMessage(signedMessage) ? signedMessage.signature : signedMessage);
62
43
  });
63
44
  }
64
- getConnectedAccounts() {
65
- return _tslib.__awaiter(this, void 0, void 0, function* () {
66
- return solProviderHelper.SolProviderHelper.getConnectedAccountsWithKey(this.key);
67
- });
68
- }
69
45
  }
70
46
 
71
47
  exports.CoinbaseSolana = CoinbaseSolana;
@@ -1,13 +1,8 @@
1
- import { SolWalletConnector } from './solWalletConnector';
2
- import { ICoinbaseSolanaSigner } from './types';
3
- export declare class CoinbaseSolana extends SolWalletConnector {
1
+ import { SolWalletConnectorOpts } from './solWalletConnector';
2
+ import { InjectedWalletBase } from './injected/InjectedWalletBase';
3
+ export declare class CoinbaseSolana extends InjectedWalletBase {
4
4
  name: string;
5
- setupEventListeners(): void;
6
- teardownEventListeners(): void;
7
- connect(): Promise<void>;
8
- getSigner(): Promise<ICoinbaseSolanaSigner | undefined>;
9
- isInstalledOnBrowser(): boolean;
10
- fetchPublicAddress(): Promise<string | undefined>;
5
+ constructor(opts: SolWalletConnectorOpts);
6
+ getSigner<ICoinbaseSolanaSigner>(): Promise<ICoinbaseSolanaSigner | undefined>;
11
7
  signMessage(messageToSign: string): Promise<string | undefined>;
12
- getConnectedAccounts(): Promise<string[]>;
13
8
  }
@@ -1,42 +1,23 @@
1
1
  import { __awaiter } from '../_virtual/_tslib.js';
2
2
  import { bufferToBase64 } from '@dynamic-labs/utils';
3
- import { SolWalletConnector } from './solWalletConnector.js';
4
- import { SolProviderHelper } from './solProviderHelper.js';
3
+ import { findWalletBookWallet } from '@dynamic-labs/wallet-book';
4
+ import { InjectedWalletBase } from './injected/InjectedWalletBase.js';
5
5
  import '@solana/web3.js';
6
6
  import '@dynamic-labs/wallet-connector-core';
7
+ import '@dynamic-labs/rpc-providers';
7
8
  import './injected/PhantomLedger.js';
8
9
  import { isSignedMessage } from './utils/isSignedMessage.js';
9
10
 
10
- class CoinbaseSolana extends SolWalletConnector {
11
- constructor() {
12
- super(...arguments);
11
+ class CoinbaseSolana extends InjectedWalletBase {
12
+ constructor(opts) {
13
+ super(opts);
13
14
  this.name = 'CoinbaseSolana';
14
- }
15
- setupEventListeners() {
16
- SolProviderHelper._setupEventListeners(this, SolProviderHelper.findProvider(this.key));
17
- }
18
- teardownEventListeners() {
19
- SolProviderHelper._teardownEventListeners(this.key);
20
- }
21
- connect() {
22
- return __awaiter(this, void 0, void 0, function* () {
23
- yield SolProviderHelper.connectWithKey(this.key);
24
- });
15
+ this.wallet = findWalletBookWallet(this.walletBook, this.key);
25
16
  }
26
17
  getSigner() {
18
+ var _a;
27
19
  return __awaiter(this, void 0, void 0, function* () {
28
- return SolProviderHelper.connectWithKey(this.key);
29
- });
30
- }
31
- isInstalledOnBrowser() {
32
- return SolProviderHelper.isInstalledHelper(this.key);
33
- }
34
- fetchPublicAddress() {
35
- return __awaiter(this, void 0, void 0, function* () {
36
- if (this.isInstalledOnBrowser()) {
37
- return SolProviderHelper.fetchPublicAddressWithKey(this.key);
38
- }
39
- return;
20
+ return (_a = this.getSolProviderHelper()) === null || _a === void 0 ? void 0 : _a.connect();
40
21
  });
41
22
  }
42
23
  signMessage(messageToSign) {
@@ -57,11 +38,6 @@ class CoinbaseSolana extends SolWalletConnector {
57
38
  return bufferToBase64(isSignedMessage(signedMessage) ? signedMessage.signature : signedMessage);
58
39
  });
59
40
  }
60
- getConnectedAccounts() {
61
- return __awaiter(this, void 0, void 0, function* () {
62
- return SolProviderHelper.getConnectedAccountsWithKey(this.key);
63
- });
64
- }
65
41
  }
66
42
 
67
43
  export { CoinbaseSolana };
@@ -0,0 +1,168 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var _tslib = require('../_virtual/_tslib.cjs');
6
+ var nacl = require('tweetnacl');
7
+ var bs58 = require('bs58');
8
+ var web3_js = require('@solana/web3.js');
9
+ var solWalletConnector = require('./solWalletConnector.cjs');
10
+
11
+ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
12
+
13
+ var nacl__default = /*#__PURE__*/_interopDefaultLegacy(nacl);
14
+ var bs58__default = /*#__PURE__*/_interopDefaultLegacy(bs58);
15
+
16
+ const buildUrl = (path, params) => `https://phantom.app/ul/v1/${path}?${params.toString()}`;
17
+ const decryptPayload = (data, nonce, sharedSecret) => {
18
+ if (!sharedSecret)
19
+ throw new Error('missing shared secret');
20
+ const decryptedData = nacl__default["default"].box.open.after(bs58__default["default"].decode(data), bs58__default["default"].decode(nonce), sharedSecret);
21
+ if (!decryptedData) {
22
+ throw new Error('Unable to decrypt data');
23
+ }
24
+ return JSON.parse(Buffer.from(decryptedData).toString('utf8'));
25
+ };
26
+ const encryptPayload = (payload, sharedSecret) => {
27
+ if (!sharedSecret)
28
+ throw new Error('missing shared secret');
29
+ const nonce = nacl__default["default"].randomBytes(24);
30
+ const encryptedPayload = nacl__default["default"].box.after(Buffer.from(JSON.stringify(payload)), nonce, sharedSecret);
31
+ return [nonce, encryptedPayload];
32
+ };
33
+ class PhantomMobileConnector extends solWalletConnector.SolWalletConnector {
34
+ constructor(props) {
35
+ super(Object.assign({}, props));
36
+ this.name = 'Phantom';
37
+ }
38
+ getSigner() {
39
+ return Promise.resolve(undefined);
40
+ }
41
+ connect() {
42
+ return _tslib.__awaiter(this, void 0, void 0, function* () {
43
+ // Generate a new key pair
44
+ const keyPair = nacl__default["default"].box.keyPair();
45
+ localStorage.setItem('dynamic_phantom_public_key', JSON.stringify([...keyPair.publicKey]));
46
+ localStorage.setItem('dynamic_phantom_secret_key', JSON.stringify([...keyPair.secretKey]));
47
+ const isLocalHost = window.location.href.includes('localhost') ||
48
+ window.location.href.includes('0.0.0.0') ||
49
+ window.location.href.includes('127.0.0.1');
50
+ const params = new URLSearchParams({
51
+ app_url: isLocalHost ? 'https://demo.dynamic.xyz' : window.location.href,
52
+ cluster: 'mainnet-beta',
53
+ dapp_encryption_public_key: bs58__default["default"].encode(keyPair.publicKey),
54
+ redirect_link: window.location.href,
55
+ });
56
+ const url = buildUrl('connect', params);
57
+ window.location.href = url;
58
+ });
59
+ }
60
+ getSession() {
61
+ return _tslib.__awaiter(this, void 0, void 0, function* () {
62
+ const params = new URLSearchParams(window.location.search);
63
+ const secretKey = new Uint8Array(JSON.parse(localStorage.getItem('dynamic_phantom_secret_key')));
64
+ const sharedSecretDapp = nacl__default["default"].box.before(bs58__default["default"].decode(params.get('phantom_encryption_public_key')), secretKey);
65
+ const connectData = decryptPayload(params.get('data'), params.get('nonce'), sharedSecretDapp);
66
+ localStorage.setItem('dynamic_phantom_shared_secret', JSON.stringify([...sharedSecretDapp]));
67
+ localStorage.setItem('dynamic_phantom_session', connectData.session);
68
+ localStorage.setItem('dynamic_phantom_wallet_address', JSON.stringify(new web3_js.PublicKey(connectData.public_key)));
69
+ params.delete('phantom_encryption_public_key');
70
+ params.delete('data');
71
+ params.delete('nonce');
72
+ history.replaceState(null, '', window.location.origin + '?' + params.toString());
73
+ return connectData.public_key;
74
+ });
75
+ }
76
+ endSession() {
77
+ return _tslib.__awaiter(this, void 0, void 0, function* () {
78
+ // for establishing the shared secret. NOT the wallet address
79
+ localStorage.removeItem('dynamic_phantom_public_key');
80
+ localStorage.removeItem('dynamic_phantom_secret_key');
81
+ localStorage.removeItem('dynamic_phantom_shared_secret');
82
+ localStorage.removeItem('dynamic_phantom_session');
83
+ localStorage.removeItem('dynamic_phantom_wallet_address');
84
+ localStorage.removeItem('dynamic_phantom_message_to_sign');
85
+ });
86
+ }
87
+ signMessage(messageToSign) {
88
+ return _tslib.__awaiter(this, void 0, void 0, function* () {
89
+ const session = localStorage.getItem('dynamic_phantom_session');
90
+ if (!session) {
91
+ throw new Error('[PhantomMobileConnector] signMessage called, but missing session from localstorage');
92
+ }
93
+ const sharedSecret = new Uint8Array(JSON.parse(localStorage.getItem('dynamic_phantom_shared_secret')));
94
+ if (!sharedSecret) {
95
+ throw new Error('[PhantomMobileConnector] signMessage called, but missing shared secret from localstorage');
96
+ }
97
+ const publicKey = new Uint8Array(JSON.parse(localStorage.getItem('dynamic_phantom_public_key')));
98
+ if (!publicKey) {
99
+ throw new Error('[PhantomMobileConnector] signMessage called, but missing public key from localstorage');
100
+ }
101
+ localStorage.setItem('dynamic_phantom_message_to_sign', messageToSign);
102
+ const payload = {
103
+ message: bs58__default["default"].encode(Buffer.from(messageToSign)),
104
+ session,
105
+ };
106
+ const [nonce, encryptedPayload] = encryptPayload(payload, sharedSecret);
107
+ const params = new URLSearchParams({
108
+ dapp_encryption_public_key: bs58__default["default"].encode(publicKey),
109
+ nonce: bs58__default["default"].encode(nonce),
110
+ payload: bs58__default["default"].encode(encryptedPayload),
111
+ redirect_link: window.location.href,
112
+ });
113
+ const url = buildUrl('signMessage', params);
114
+ window.location.href = url;
115
+ // throwing this to prevent local storage from being cleared.
116
+ // when verifying signature, the SDK calls endSession when no
117
+ // signature is returned. in the case of phantom mobile, a signature
118
+ // is not returned from signMessage, so an error will always be thrown.
119
+ // this is a workaround to prevent the SDK from clearing local storage
120
+ // ideally we would figure out how to:
121
+ // 1. kick off the sign message on one tab
122
+ // 2. resume the process on that tab after the user signs in phantom
123
+ throw new Error('ignore');
124
+ });
125
+ }
126
+ fetchPublicAddress() {
127
+ return _tslib.__awaiter(this, void 0, void 0, function* () {
128
+ const rawAddress = localStorage.getItem('dynamic_phantom_wallet_address');
129
+ if (rawAddress) {
130
+ return JSON.parse(rawAddress);
131
+ }
132
+ yield this.connect();
133
+ return undefined;
134
+ });
135
+ }
136
+ extractSignature() {
137
+ const params = new URLSearchParams(window.location.search);
138
+ const sharedSecret = new Uint8Array(JSON.parse(localStorage.getItem('dynamic_phantom_shared_secret')));
139
+ if (!sharedSecret) {
140
+ throw new Error('[PhantomMobileConnector] extractSignature called, but missing shared secret from localstorage');
141
+ }
142
+ const signMessageData = decryptPayload(params.get('data'), params.get('nonce'), sharedSecret);
143
+ const message = localStorage.getItem('dynamic_phantom_message_to_sign');
144
+ if (!message) {
145
+ throw new Error('[PhantomMobileConnector] extractSignature: missing message to sign');
146
+ }
147
+ params.delete('data');
148
+ params.delete('nonce');
149
+ history.replaceState(null, '', window.location.origin + '?' + params.toString());
150
+ return {
151
+ message,
152
+ signature: signMessageData.signature,
153
+ };
154
+ }
155
+ getConnectedAccounts() {
156
+ return _tslib.__awaiter(this, void 0, void 0, function* () {
157
+ const rawAddress = localStorage.getItem('dynamic_phantom_wallet_address');
158
+ if (rawAddress) {
159
+ return [JSON.parse(rawAddress)];
160
+ }
161
+ else {
162
+ return [];
163
+ }
164
+ });
165
+ }
166
+ }
167
+
168
+ exports.PhantomMobileConnector = PhantomMobileConnector;
@@ -0,0 +1,17 @@
1
+ import { SolWalletConnector } from './solWalletConnector';
2
+ import { ISolana } from '.';
3
+ export declare class PhantomMobileConnector extends SolWalletConnector {
4
+ name: string;
5
+ constructor(props: any);
6
+ getSigner(): Promise<ISolana | undefined>;
7
+ connect(): Promise<void>;
8
+ getSession(): Promise<string>;
9
+ endSession(): Promise<void>;
10
+ signMessage(messageToSign: string): Promise<string | undefined>;
11
+ fetchPublicAddress(): Promise<string | undefined>;
12
+ extractSignature(): {
13
+ signature: string;
14
+ message: string;
15
+ };
16
+ getConnectedAccounts(): Promise<string[]>;
17
+ }
@@ -0,0 +1,159 @@
1
+ import { __awaiter } from '../_virtual/_tslib.js';
2
+ import nacl from 'tweetnacl';
3
+ import bs58 from 'bs58';
4
+ import { PublicKey } from '@solana/web3.js';
5
+ import { SolWalletConnector } from './solWalletConnector.js';
6
+
7
+ const buildUrl = (path, params) => `https://phantom.app/ul/v1/${path}?${params.toString()}`;
8
+ const decryptPayload = (data, nonce, sharedSecret) => {
9
+ if (!sharedSecret)
10
+ throw new Error('missing shared secret');
11
+ const decryptedData = nacl.box.open.after(bs58.decode(data), bs58.decode(nonce), sharedSecret);
12
+ if (!decryptedData) {
13
+ throw new Error('Unable to decrypt data');
14
+ }
15
+ return JSON.parse(Buffer.from(decryptedData).toString('utf8'));
16
+ };
17
+ const encryptPayload = (payload, sharedSecret) => {
18
+ if (!sharedSecret)
19
+ throw new Error('missing shared secret');
20
+ const nonce = nacl.randomBytes(24);
21
+ const encryptedPayload = nacl.box.after(Buffer.from(JSON.stringify(payload)), nonce, sharedSecret);
22
+ return [nonce, encryptedPayload];
23
+ };
24
+ class PhantomMobileConnector extends SolWalletConnector {
25
+ constructor(props) {
26
+ super(Object.assign({}, props));
27
+ this.name = 'Phantom';
28
+ }
29
+ getSigner() {
30
+ return Promise.resolve(undefined);
31
+ }
32
+ connect() {
33
+ return __awaiter(this, void 0, void 0, function* () {
34
+ // Generate a new key pair
35
+ const keyPair = nacl.box.keyPair();
36
+ localStorage.setItem('dynamic_phantom_public_key', JSON.stringify([...keyPair.publicKey]));
37
+ localStorage.setItem('dynamic_phantom_secret_key', JSON.stringify([...keyPair.secretKey]));
38
+ const isLocalHost = window.location.href.includes('localhost') ||
39
+ window.location.href.includes('0.0.0.0') ||
40
+ window.location.href.includes('127.0.0.1');
41
+ const params = new URLSearchParams({
42
+ app_url: isLocalHost ? 'https://demo.dynamic.xyz' : window.location.href,
43
+ cluster: 'mainnet-beta',
44
+ dapp_encryption_public_key: bs58.encode(keyPair.publicKey),
45
+ redirect_link: window.location.href,
46
+ });
47
+ const url = buildUrl('connect', params);
48
+ window.location.href = url;
49
+ });
50
+ }
51
+ getSession() {
52
+ return __awaiter(this, void 0, void 0, function* () {
53
+ const params = new URLSearchParams(window.location.search);
54
+ const secretKey = new Uint8Array(JSON.parse(localStorage.getItem('dynamic_phantom_secret_key')));
55
+ const sharedSecretDapp = nacl.box.before(bs58.decode(params.get('phantom_encryption_public_key')), secretKey);
56
+ const connectData = decryptPayload(params.get('data'), params.get('nonce'), sharedSecretDapp);
57
+ localStorage.setItem('dynamic_phantom_shared_secret', JSON.stringify([...sharedSecretDapp]));
58
+ localStorage.setItem('dynamic_phantom_session', connectData.session);
59
+ localStorage.setItem('dynamic_phantom_wallet_address', JSON.stringify(new PublicKey(connectData.public_key)));
60
+ params.delete('phantom_encryption_public_key');
61
+ params.delete('data');
62
+ params.delete('nonce');
63
+ history.replaceState(null, '', window.location.origin + '?' + params.toString());
64
+ return connectData.public_key;
65
+ });
66
+ }
67
+ endSession() {
68
+ return __awaiter(this, void 0, void 0, function* () {
69
+ // for establishing the shared secret. NOT the wallet address
70
+ localStorage.removeItem('dynamic_phantom_public_key');
71
+ localStorage.removeItem('dynamic_phantom_secret_key');
72
+ localStorage.removeItem('dynamic_phantom_shared_secret');
73
+ localStorage.removeItem('dynamic_phantom_session');
74
+ localStorage.removeItem('dynamic_phantom_wallet_address');
75
+ localStorage.removeItem('dynamic_phantom_message_to_sign');
76
+ });
77
+ }
78
+ signMessage(messageToSign) {
79
+ return __awaiter(this, void 0, void 0, function* () {
80
+ const session = localStorage.getItem('dynamic_phantom_session');
81
+ if (!session) {
82
+ throw new Error('[PhantomMobileConnector] signMessage called, but missing session from localstorage');
83
+ }
84
+ const sharedSecret = new Uint8Array(JSON.parse(localStorage.getItem('dynamic_phantom_shared_secret')));
85
+ if (!sharedSecret) {
86
+ throw new Error('[PhantomMobileConnector] signMessage called, but missing shared secret from localstorage');
87
+ }
88
+ const publicKey = new Uint8Array(JSON.parse(localStorage.getItem('dynamic_phantom_public_key')));
89
+ if (!publicKey) {
90
+ throw new Error('[PhantomMobileConnector] signMessage called, but missing public key from localstorage');
91
+ }
92
+ localStorage.setItem('dynamic_phantom_message_to_sign', messageToSign);
93
+ const payload = {
94
+ message: bs58.encode(Buffer.from(messageToSign)),
95
+ session,
96
+ };
97
+ const [nonce, encryptedPayload] = encryptPayload(payload, sharedSecret);
98
+ const params = new URLSearchParams({
99
+ dapp_encryption_public_key: bs58.encode(publicKey),
100
+ nonce: bs58.encode(nonce),
101
+ payload: bs58.encode(encryptedPayload),
102
+ redirect_link: window.location.href,
103
+ });
104
+ const url = buildUrl('signMessage', params);
105
+ window.location.href = url;
106
+ // throwing this to prevent local storage from being cleared.
107
+ // when verifying signature, the SDK calls endSession when no
108
+ // signature is returned. in the case of phantom mobile, a signature
109
+ // is not returned from signMessage, so an error will always be thrown.
110
+ // this is a workaround to prevent the SDK from clearing local storage
111
+ // ideally we would figure out how to:
112
+ // 1. kick off the sign message on one tab
113
+ // 2. resume the process on that tab after the user signs in phantom
114
+ throw new Error('ignore');
115
+ });
116
+ }
117
+ fetchPublicAddress() {
118
+ return __awaiter(this, void 0, void 0, function* () {
119
+ const rawAddress = localStorage.getItem('dynamic_phantom_wallet_address');
120
+ if (rawAddress) {
121
+ return JSON.parse(rawAddress);
122
+ }
123
+ yield this.connect();
124
+ return undefined;
125
+ });
126
+ }
127
+ extractSignature() {
128
+ const params = new URLSearchParams(window.location.search);
129
+ const sharedSecret = new Uint8Array(JSON.parse(localStorage.getItem('dynamic_phantom_shared_secret')));
130
+ if (!sharedSecret) {
131
+ throw new Error('[PhantomMobileConnector] extractSignature called, but missing shared secret from localstorage');
132
+ }
133
+ const signMessageData = decryptPayload(params.get('data'), params.get('nonce'), sharedSecret);
134
+ const message = localStorage.getItem('dynamic_phantom_message_to_sign');
135
+ if (!message) {
136
+ throw new Error('[PhantomMobileConnector] extractSignature: missing message to sign');
137
+ }
138
+ params.delete('data');
139
+ params.delete('nonce');
140
+ history.replaceState(null, '', window.location.origin + '?' + params.toString());
141
+ return {
142
+ message,
143
+ signature: signMessageData.signature,
144
+ };
145
+ }
146
+ getConnectedAccounts() {
147
+ return __awaiter(this, void 0, void 0, function* () {
148
+ const rawAddress = localStorage.getItem('dynamic_phantom_wallet_address');
149
+ if (rawAddress) {
150
+ return [JSON.parse(rawAddress)];
151
+ }
152
+ else {
153
+ return [];
154
+ }
155
+ });
156
+ }
157
+ }
158
+
159
+ export { PhantomMobileConnector };
package/src/Solflare.d.ts CHANGED
@@ -1,13 +1,8 @@
1
- import { SolWalletConnector } from './solWalletConnector';
2
- import { ISolana } from './types';
3
- export declare class Solflare extends SolWalletConnector {
1
+ import { InjectedWalletBase } from './injected/InjectedWalletBase';
2
+ import { SolWalletConnectorOpts } from './solWalletConnector';
3
+ export declare class Solflare extends InjectedWalletBase {
4
4
  name: string;
5
- isInstalledOnBrowser(): boolean;
5
+ constructor(opts: SolWalletConnectorOpts);
6
6
  fetchPublicAddress(): Promise<string | undefined>;
7
- connect(): Promise<void>;
8
- getSigner(): Promise<ISolana | undefined>;
9
7
  signMessage(messageToSign: string): Promise<string | undefined>;
10
- getConnectedAccounts(): Promise<string[]>;
11
- setupEventListeners(): void;
12
- teardownEventListeners(): void;
13
8
  }
package/src/index.cjs CHANGED
@@ -2,28 +2,15 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var CoinbaseSolana = require('./CoinbaseSolana.cjs');
6
- var Glow = require('./Glow.cjs');
7
- var Slope = require('./Slope.cjs');
8
- var Solflare = require('./Solflare.cjs');
9
- var index = require('./injected/index.cjs');
10
- var solWalletConnector = require('./solWalletConnector.cjs');
11
- var solProviderHelper = require('./solProviderHelper.cjs');
5
+ var fetchInjectedWalletConnectors = require('./injected/fetchInjectedWalletConnectors.cjs');
12
6
  var isSignedMessage = require('./utils/isSignedMessage.cjs');
13
7
  var isBackpackSolanaSigner = require('./utils/isBackpackSolanaSigner.cjs');
14
8
 
15
- /* eslint-disable @typescript-eslint/no-unused-vars */
16
9
  const SolanaWalletConnectors = (props) => [
17
- ...index.injectedWallets,
18
- CoinbaseSolana.CoinbaseSolana,
19
- Glow.Glow,
20
- Slope.Slope,
21
- Solflare.Solflare,
10
+ ...fetchInjectedWalletConnectors.injectedWalletOverrides,
11
+ ...fetchInjectedWalletConnectors.fetchInjectedWalletConnectors(props),
22
12
  ];
23
13
 
24
- exports.Solflare = Solflare.Solflare;
25
- exports.SolWalletConnector = solWalletConnector.SolWalletConnector;
26
- exports.SolProviderHelper = solProviderHelper.SolProviderHelper;
27
14
  exports.isSignedMessage = isSignedMessage.isSignedMessage;
28
15
  exports.isBackpackSolanaSigner = isBackpackSolanaSigner.isBackpackSolanaSigner;
29
16
  exports.SolanaWalletConnectors = SolanaWalletConnectors;
package/src/index.d.ts CHANGED
@@ -1,7 +1,4 @@
1
- export * from './solWalletConnector';
2
- export * from './solProviderHelper';
3
- export * from './Solflare';
4
- export declare const SolanaWalletConnectors: (props: any) => typeof import("./injected/BraveSol").BraveSol[];
1
+ export declare const SolanaWalletConnectors: (props: any) => import("dist/packages/wallet-connector-core/src").WalletConnectorConstructor[];
5
2
  export { isSignedMessage } from './utils/isSignedMessage';
6
3
  export { isBackpackSolanaSigner } from './utils/isBackpackSolanaSigner';
7
4
  export type { ISolana, IBackpackSolanaSigner, ICoinbaseSolanaSigner, SignedMessage, ISolanaSigner, } from './types';