@dynamic-labs/solana 1.3.0 → 1.4.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 CHANGED
@@ -1,4 +1,29 @@
1
1
 
2
+ ## [1.4.0](https://github.com/dynamic-labs/DynamicAuth/compare/v1.3.1...v1.4.0) (2024-03-21)
3
+
4
+
5
+ ### Features
6
+
7
+ * add sign-in with farcaster ([#5059](https://github.com/dynamic-labs/DynamicAuth/issues/5059)) ([83245aa](https://github.com/dynamic-labs/DynamicAuth/commit/83245aa9f973ca349abcbaccf5d150b4a31beb0e)), closes [#4947](https://github.com/dynamic-labs/DynamicAuth/issues/4947)
8
+ * add prop to hide embedded wallet transaction UIs ([#4928](https://github.com/dynamic-labs/DynamicAuth/issues/4928)) ([b0ad954](https://github.com/dynamic-labs/DynamicAuth/commit/b0ad95494ebf991e61f09a23999c3526498f2db9)), closes [#4924](https://github.com/dynamic-labs/DynamicAuth/issues/4924)
9
+
10
+
11
+ ### Bug Fixes
12
+
13
+ * multiple wallet improvements
14
+ * multiple ui/ux improvements
15
+ * miscellaneous copy and localization updates
16
+ * add missing css variables for DynamicConnectButton
17
+
18
+ ### [1.3.1](https://github.com/dynamic-labs/DynamicAuth/compare/v1.3.0...v1.3.1) (2024-03-08)
19
+
20
+
21
+ ### Bug Fixes
22
+
23
+ * pass account and chain to walletClient ([#4865](https://github.com/dynamic-labs/DynamicAuth/issues/4865)) ([#4905](https://github.com/dynamic-labs/DynamicAuth/issues/4905)) ([0f4e79f](https://github.com/dynamic-labs/DynamicAuth/commit/0f4e79ff36f8a3ef63c59bb9f80429cdefbe7307))
24
+ * update btckit network conversion for signpsbt to use correct network ([#4882](https://github.com/dynamic-labs/DynamicAuth/issues/4882)) ([3c14f55](https://github.com/dynamic-labs/DynamicAuth/commit/3c14f55f6e37718a095752d0e04bfbac45fee75c))
25
+ * better auth state handling when logged in with disabled wallets ([#4862](https://github.com/dynamic-labs/DynamicAuth/issues/4862)) ([8cc2a1c](https://github.com/dynamic-labs/DynamicAuth/commit/8cc2a1c4f31cf6acb61d814a3410c5e77da21c50))
26
+
2
27
  ## [1.3.0](https://github.com/dynamic-labs/DynamicAuth/compare/v1.2.0...v1.3.0) (2024-03-05)
3
28
 
4
29
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dynamic-labs/solana",
3
- "version": "1.3.0",
3
+ "version": "1.4.0",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/dynamic-labs/DynamicAuth.git",
@@ -27,15 +27,15 @@
27
27
  },
28
28
  "dependencies": {
29
29
  "@solana/web3.js": "1.70.1",
30
- "@dynamic-labs/sdk-api": "0.0.363",
30
+ "@dynamic-labs/sdk-api": "0.0.387",
31
31
  "bs58": "^5.0.0",
32
32
  "tweetnacl": "^1.0.3",
33
- "@dynamic-labs/rpc-providers": "1.3.0",
34
- "@dynamic-labs/turnkey": "1.3.0",
35
- "@dynamic-labs/types": "1.3.0",
36
- "@dynamic-labs/utils": "1.3.0",
37
- "@dynamic-labs/wallet-book": "1.3.0",
38
- "@dynamic-labs/wallet-connector-core": "1.3.0",
33
+ "@dynamic-labs/rpc-providers": "1.4.0",
34
+ "@dynamic-labs/turnkey": "1.4.0",
35
+ "@dynamic-labs/types": "1.4.0",
36
+ "@dynamic-labs/utils": "1.4.0",
37
+ "@dynamic-labs/wallet-book": "1.4.0",
38
+ "@dynamic-labs/wallet-connector-core": "1.4.0",
39
39
  "eventemitter3": "5.0.1"
40
40
  },
41
41
  "peerDependencies": {}
@@ -6,7 +6,6 @@ var _tslib = require('../_virtual/_tslib.cjs');
6
6
  var utils = require('@dynamic-labs/utils');
7
7
  var walletBook = require('@dynamic-labs/wallet-book');
8
8
  require('@dynamic-labs/turnkey');
9
- require('@dynamic-labs/sdk-api');
10
9
  require('./solWalletConnector.cjs');
11
10
  require('tweetnacl');
12
11
  require('bs58');
@@ -2,7 +2,6 @@ import { __awaiter } from '../_virtual/_tslib.js';
2
2
  import { bufferToBase64 } from '@dynamic-labs/utils';
3
3
  import { findWalletBookWallet } from '@dynamic-labs/wallet-book';
4
4
  import '@dynamic-labs/turnkey';
5
- import '@dynamic-labs/sdk-api';
6
5
  import './solWalletConnector.js';
7
6
  import 'tweetnacl';
8
7
  import 'bs58';
@@ -0,0 +1,73 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var _tslib = require('../_virtual/_tslib.cjs');
6
+ var utils = require('@dynamic-labs/utils');
7
+ var walletBook = require('@dynamic-labs/wallet-book');
8
+ var InjectedWalletBase = require('./injected/InjectedWalletBase.cjs');
9
+
10
+ class Solflare extends InjectedWalletBase.InjectedWalletBase {
11
+ constructor(opts) {
12
+ super(opts);
13
+ this.name = 'Solflare';
14
+ this.wallet = walletBook.findWalletBookWallet(this.walletBook, this.key);
15
+ }
16
+ fetchPublicAddress() {
17
+ var _a, _b, _c, _d, _e;
18
+ return _tslib.__awaiter(this, void 0, void 0, function* () {
19
+ /**
20
+ * It should redirect to in-app browser if on mobile and if not in the in-app browser,
21
+ * this checks if it is not in the in-app browser by checking if the provider is not available.
22
+ */
23
+ if (utils.isMobile() && !this.isInstalledOnBrowser()) {
24
+ utils.handleMobileWalletRedirect({
25
+ nativeLink: ((_b = (_a = this.wallet) === null || _a === void 0 ? void 0 : _a.mobile) === null || _b === void 0 ? void 0 : _b.native) || 'solflare://ul/v1/browse',
26
+ universalLink: ((_d = (_c = this.wallet) === null || _c === void 0 ? void 0 : _c.mobile) === null || _d === void 0 ? void 0 : _d.universal) || 'https://solflare.com/ul/v1/browse',
27
+ });
28
+ return;
29
+ }
30
+ return (_e = this.getSolProviderHelper()) === null || _e === void 0 ? void 0 : _e.fetchPublicAddress();
31
+ });
32
+ }
33
+ signMessage(messageToSign) {
34
+ return _tslib.__awaiter(this, void 0, void 0, function* () {
35
+ const walletAddress = yield this.fetchPublicAddress();
36
+ if (!walletAddress) {
37
+ return undefined;
38
+ }
39
+ const provider = yield this.getSigner();
40
+ if (!provider) {
41
+ return undefined;
42
+ }
43
+ const encodedMessage = new TextEncoder().encode(messageToSign);
44
+ const isSignedMessage = (value) => value.signature !== undefined;
45
+ yield provider.connect();
46
+ /**
47
+ * TODO: Remove the sleep once problem is fixed on Solflare's extension.
48
+ * Tracked in DYN-442
49
+ */
50
+ yield new Promise((resolve) => {
51
+ setTimeout(resolve, 100);
52
+ });
53
+ const rawMessage = yield provider.signMessage(encodedMessage, 'utf8');
54
+ return isSignedMessage(rawMessage)
55
+ ? utils.bufferToBase64(rawMessage.signature)
56
+ : undefined;
57
+ });
58
+ }
59
+ getConnectedAccounts() {
60
+ var _a;
61
+ return _tslib.__awaiter(this, void 0, void 0, function* () {
62
+ const provider = yield this.getSigner();
63
+ if (!provider)
64
+ return [];
65
+ const publicKey = (_a = provider.publicKey) === null || _a === void 0 ? void 0 : _a.toString();
66
+ if (publicKey)
67
+ return [publicKey];
68
+ return [];
69
+ });
70
+ }
71
+ }
72
+
73
+ exports.Solflare = Solflare;
package/src/Solflare.d.ts CHANGED
@@ -5,4 +5,5 @@ export declare class Solflare extends InjectedWalletBase {
5
5
  constructor(opts: SolWalletConnectorOpts);
6
6
  fetchPublicAddress(): Promise<string | undefined>;
7
7
  signMessage(messageToSign: string): Promise<string | undefined>;
8
+ getConnectedAccounts(): Promise<string[]>;
8
9
  }
@@ -0,0 +1,69 @@
1
+ import { __awaiter } from '../_virtual/_tslib.js';
2
+ import { isMobile, handleMobileWalletRedirect, bufferToBase64 } from '@dynamic-labs/utils';
3
+ import { findWalletBookWallet } from '@dynamic-labs/wallet-book';
4
+ import { InjectedWalletBase } from './injected/InjectedWalletBase.js';
5
+
6
+ class Solflare extends InjectedWalletBase {
7
+ constructor(opts) {
8
+ super(opts);
9
+ this.name = 'Solflare';
10
+ this.wallet = findWalletBookWallet(this.walletBook, this.key);
11
+ }
12
+ fetchPublicAddress() {
13
+ var _a, _b, _c, _d, _e;
14
+ return __awaiter(this, void 0, void 0, function* () {
15
+ /**
16
+ * It should redirect to in-app browser if on mobile and if not in the in-app browser,
17
+ * this checks if it is not in the in-app browser by checking if the provider is not available.
18
+ */
19
+ if (isMobile() && !this.isInstalledOnBrowser()) {
20
+ handleMobileWalletRedirect({
21
+ nativeLink: ((_b = (_a = this.wallet) === null || _a === void 0 ? void 0 : _a.mobile) === null || _b === void 0 ? void 0 : _b.native) || 'solflare://ul/v1/browse',
22
+ universalLink: ((_d = (_c = this.wallet) === null || _c === void 0 ? void 0 : _c.mobile) === null || _d === void 0 ? void 0 : _d.universal) || 'https://solflare.com/ul/v1/browse',
23
+ });
24
+ return;
25
+ }
26
+ return (_e = this.getSolProviderHelper()) === null || _e === void 0 ? void 0 : _e.fetchPublicAddress();
27
+ });
28
+ }
29
+ signMessage(messageToSign) {
30
+ return __awaiter(this, void 0, void 0, function* () {
31
+ const walletAddress = yield this.fetchPublicAddress();
32
+ if (!walletAddress) {
33
+ return undefined;
34
+ }
35
+ const provider = yield this.getSigner();
36
+ if (!provider) {
37
+ return undefined;
38
+ }
39
+ const encodedMessage = new TextEncoder().encode(messageToSign);
40
+ const isSignedMessage = (value) => value.signature !== undefined;
41
+ yield provider.connect();
42
+ /**
43
+ * TODO: Remove the sleep once problem is fixed on Solflare's extension.
44
+ * Tracked in DYN-442
45
+ */
46
+ yield new Promise((resolve) => {
47
+ setTimeout(resolve, 100);
48
+ });
49
+ const rawMessage = yield provider.signMessage(encodedMessage, 'utf8');
50
+ return isSignedMessage(rawMessage)
51
+ ? bufferToBase64(rawMessage.signature)
52
+ : undefined;
53
+ });
54
+ }
55
+ getConnectedAccounts() {
56
+ var _a;
57
+ return __awaiter(this, void 0, void 0, function* () {
58
+ const provider = yield this.getSigner();
59
+ if (!provider)
60
+ return [];
61
+ const publicKey = (_a = provider.publicKey) === null || _a === void 0 ? void 0 : _a.toString();
62
+ if (publicKey)
63
+ return [publicKey];
64
+ return [];
65
+ });
66
+ }
67
+ }
68
+
69
+ export { Solflare };
package/src/index.cjs CHANGED
@@ -3,7 +3,6 @@
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var turnkey = require('@dynamic-labs/turnkey');
6
- var sdkApi = require('@dynamic-labs/sdk-api');
7
6
  var Phantom = require('./Phantom.cjs');
8
7
  var fetchInjectedWalletConnectors = require('./injected/fetchInjectedWalletConnectors.cjs');
9
8
  var isSignedMessage = require('./utils/isSignedMessage.cjs');
@@ -13,7 +12,7 @@ var isBackpackSolanaSigner = require('./utils/isBackpackSolanaSigner.cjs');
13
12
  const SolanaWalletConnectors = (props) => [
14
13
  ...fetchInjectedWalletConnectors.injectedWalletOverrides,
15
14
  ...fetchInjectedWalletConnectors.fetchInjectedWalletConnectors(props),
16
- ...turnkey.TurnkeyWalletConnectors(props, sdkApi.ChainEnum.Sol),
15
+ ...turnkey.TurnkeySolanaWalletConnectors(props),
17
16
  Phantom.Phantom,
18
17
  ];
19
18
 
package/src/index.js CHANGED
@@ -1,5 +1,4 @@
1
- import { TurnkeyWalletConnectors } from '@dynamic-labs/turnkey';
2
- import { ChainEnum } from '@dynamic-labs/sdk-api';
1
+ import { TurnkeySolanaWalletConnectors } from '@dynamic-labs/turnkey';
3
2
  import { Phantom } from './Phantom.js';
4
3
  import { injectedWalletOverrides, fetchInjectedWalletConnectors } from './injected/fetchInjectedWalletConnectors.js';
5
4
  export { isSignedMessage } from './utils/isSignedMessage.js';
@@ -9,7 +8,7 @@ export { isBackpackSolanaSigner } from './utils/isBackpackSolanaSigner.js';
9
8
  const SolanaWalletConnectors = (props) => [
10
9
  ...injectedWalletOverrides,
11
10
  ...fetchInjectedWalletConnectors(props),
12
- ...TurnkeyWalletConnectors(props, ChainEnum.Sol),
11
+ ...TurnkeySolanaWalletConnectors(props),
13
12
  Phantom,
14
13
  ];
15
14
 
@@ -4,6 +4,7 @@ Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var CoinbaseSolana = require('../CoinbaseSolana.cjs');
6
6
  var Slope = require('../Slope.cjs');
7
+ var Solflare = require('../Solflare.cjs');
7
8
  var InjectedWalletBase = require('./InjectedWalletBase.cjs');
8
9
  var BackpackSol = require('./BackpackSol.cjs');
9
10
 
@@ -11,6 +12,7 @@ const injectedWalletOverrides = [
11
12
  CoinbaseSolana.CoinbaseSolana,
12
13
  Slope.Slope,
13
14
  BackpackSol.BackpackSol,
15
+ Solflare.Solflare,
14
16
  ];
15
17
  const filteredInjectedWalletKeysOverrides = [
16
18
  'coinbasesolana',
@@ -18,6 +20,7 @@ const filteredInjectedWalletKeysOverrides = [
18
20
  'phantom',
19
21
  'phantomledger',
20
22
  'backpacksol',
23
+ 'solflare',
21
24
  ];
22
25
  const fetchInjectedWalletConnectors = ({ walletBook, }) => {
23
26
  var _a;
@@ -1,5 +1,6 @@
1
1
  import { CoinbaseSolana } from '../CoinbaseSolana.js';
2
2
  import { Slope } from '../Slope.js';
3
+ import { Solflare } from '../Solflare.js';
3
4
  import { InjectedWalletBase } from './InjectedWalletBase.js';
4
5
  import { BackpackSol } from './BackpackSol.js';
5
6
 
@@ -7,6 +8,7 @@ const injectedWalletOverrides = [
7
8
  CoinbaseSolana,
8
9
  Slope,
9
10
  BackpackSol,
11
+ Solflare,
10
12
  ];
11
13
  const filteredInjectedWalletKeysOverrides = [
12
14
  'coinbasesolana',
@@ -14,6 +16,7 @@ const filteredInjectedWalletKeysOverrides = [
14
16
  'phantom',
15
17
  'phantomledger',
16
18
  'backpacksol',
19
+ 'solflare',
17
20
  ];
18
21
  const fetchInjectedWalletConnectors = ({ walletBook, }) => {
19
22
  var _a;
@@ -116,13 +116,25 @@ class PhantomRedirect extends solWalletConnector.SolWalletConnector {
116
116
  }
117
117
  endSession() {
118
118
  return _tslib.__awaiter(this, void 0, void 0, function* () {
119
- // for establishing the shared secret. NOT the wallet address
120
- storage.storage.address.remove();
121
- storage.storage.encryptionPublicKey.remove();
122
- storage.storage.encryptionSecretKey.remove();
123
- storage.storage.message.remove();
124
- storage.storage.session.remove();
125
- storage.storage.sharedSecret.remove();
119
+ const address = storage.storage.address.get();
120
+ const session = storage.storage.session.get();
121
+ const sharedSecret = storage.storage.sharedSecret.get();
122
+ const encryptionPublicKey = storage.storage.encryptionPublicKey.get();
123
+ // Clear all local storage in case of any stale state
124
+ storage.clearStorage();
125
+ // if there is no session/encrytion keys, then we don't need to disconnect
126
+ if (!address || !session || !encryptionPublicKey || !sharedSecret)
127
+ return;
128
+ const payload = { session };
129
+ const [nonce, encryptedPayload] = utils.encryptPayload(payload, sharedSecret);
130
+ const params = new URLSearchParams({
131
+ dapp_encryption_public_key: bs58__default["default"].encode(encryptionPublicKey),
132
+ nonce: bs58__default["default"].encode(nonce),
133
+ payload: bs58__default["default"].encode(encryptedPayload),
134
+ redirect_link: window.location.href,
135
+ });
136
+ const url = utils.buildUrl('disconnect', params);
137
+ window.location.href = url;
126
138
  });
127
139
  }
128
140
  /**
@@ -4,7 +4,7 @@ import bs58 from 'bs58';
4
4
  import { PublicKey } from '@solana/web3.js';
5
5
  import { SolWalletConnector } from '../solWalletConnector.js';
6
6
  import { buildUrl, decryptPayload, encryptPayload } from './utils.js';
7
- import { storage } from './storage.js';
7
+ import { storage, clearStorage } from './storage.js';
8
8
 
9
9
  class PhantomRedirect extends SolWalletConnector {
10
10
  constructor(props) {
@@ -107,13 +107,25 @@ class PhantomRedirect extends SolWalletConnector {
107
107
  }
108
108
  endSession() {
109
109
  return __awaiter(this, void 0, void 0, function* () {
110
- // for establishing the shared secret. NOT the wallet address
111
- storage.address.remove();
112
- storage.encryptionPublicKey.remove();
113
- storage.encryptionSecretKey.remove();
114
- storage.message.remove();
115
- storage.session.remove();
116
- storage.sharedSecret.remove();
110
+ const address = storage.address.get();
111
+ const session = storage.session.get();
112
+ const sharedSecret = storage.sharedSecret.get();
113
+ const encryptionPublicKey = storage.encryptionPublicKey.get();
114
+ // Clear all local storage in case of any stale state
115
+ clearStorage();
116
+ // if there is no session/encrytion keys, then we don't need to disconnect
117
+ if (!address || !session || !encryptionPublicKey || !sharedSecret)
118
+ return;
119
+ const payload = { session };
120
+ const [nonce, encryptedPayload] = encryptPayload(payload, sharedSecret);
121
+ const params = new URLSearchParams({
122
+ dapp_encryption_public_key: bs58.encode(encryptionPublicKey),
123
+ nonce: bs58.encode(nonce),
124
+ payload: bs58.encode(encryptedPayload),
125
+ redirect_link: window.location.href,
126
+ });
127
+ const url = buildUrl('disconnect', params);
128
+ window.location.href = url;
117
129
  });
118
130
  }
119
131
  /**
@@ -76,5 +76,11 @@ const storage = {
76
76
  },
77
77
  },
78
78
  };
79
+ const clearStorage = () => {
80
+ for (const key in storage) {
81
+ storage[key].remove();
82
+ }
83
+ };
79
84
 
85
+ exports.clearStorage = clearStorage;
80
86
  exports.storage = storage;
@@ -31,3 +31,4 @@ export declare const storage: {
31
31
  set: (sharedSecret: Uint8Array) => void;
32
32
  };
33
33
  };
34
+ export declare const clearStorage: () => void;
@@ -72,5 +72,10 @@ const storage = {
72
72
  },
73
73
  },
74
74
  };
75
+ const clearStorage = () => {
76
+ for (const key in storage) {
77
+ storage[key].remove();
78
+ }
79
+ };
75
80
 
76
- export { storage };
81
+ export { clearStorage, storage };