@dynamic-labs/solana 1.0.2 → 1.0.4

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.0.4](https://github.com/dynamic-labs/DynamicAuth/compare/v1.0.3...v1.0.4) (2024-01-04)
3
+
4
+
5
+ ### Bug Fixes
6
+
7
+ * edge case with unlinking wallet ([#4285](https://github.com/dynamic-labs/DynamicAuth/issues/4285)) ([#4293](https://github.com/dynamic-labs/DynamicAuth/issues/4293)) ([85eb4ea](https://github.com/dynamic-labs/DynamicAuth/commit/85eb4ea0fa4521d37ee3901dbb1fa6d88a8cf8f7))
8
+ * phantom solana not connecting on mobile ([#4287](https://github.com/dynamic-labs/DynamicAuth/issues/4287)) ([0d85e24](https://github.com/dynamic-labs/DynamicAuth/commit/0d85e2429f2dc0a92c293cf57dc0e241c4b948be))
9
+ * prevent error message when mobile wallet app is open ([#4301](https://github.com/dynamic-labs/DynamicAuth/issues/4301)) ([#4303](https://github.com/dynamic-labs/DynamicAuth/issues/4303)) ([0ba145e](https://github.com/dynamic-labs/DynamicAuth/commit/0ba145e6d1145fecc3e7bc2e60d127106be9aa54))
10
+ * **useFetchBalance:** ensure the latest wallet balance is fetched ([#4288](https://github.com/dynamic-labs/DynamicAuth/issues/4288)) ([#4294](https://github.com/dynamic-labs/DynamicAuth/issues/4294)) ([3fa0d60](https://github.com/dynamic-labs/DynamicAuth/commit/3fa0d60552082dffd032317368d20b87cdab9c6d))
11
+
12
+ ### [1.0.3](https://github.com/dynamic-labs/DynamicAuth/compare/v1.0.2...v1.0.3) (2023-12-28)
13
+
14
+
15
+ ### Features
16
+
17
+ * add default footer to wallet list when tos and pp not enabled ([#4229](https://github.com/dynamic-labs/DynamicAuth/issues/4229)) ([a6d90a7](https://github.com/dynamic-labs/DynamicAuth/commit/a6d90a7276cafeaffcb21c5362837d020fc10215)), closes [#4224](https://github.com/dynamic-labs/DynamicAuth/issues/4224)
18
+ * add starknet support for sopelia ([#4268](https://github.com/dynamic-labs/DynamicAuth/issues/4268)) ([53d4ce4](https://github.com/dynamic-labs/DynamicAuth/commit/53d4ce400070adfb32021b01b9c748b9a7d90577))
19
+ * delay setting user to after pregenerated wallet flow ([#4244](https://github.com/dynamic-labs/DynamicAuth/issues/4244)) ([503d34d](https://github.com/dynamic-labs/DynamicAuth/commit/503d34d9d6f5edd55b009f1f63c049ac6dfb1fb7))
20
+
21
+
22
+ ### Bug Fixes
23
+
24
+ * coinbase solana signMessage ([#4261](https://github.com/dynamic-labs/DynamicAuth/issues/4261)) ([7e0e69c](https://github.com/dynamic-labs/DynamicAuth/commit/7e0e69c0ad9f9c9778ff9255909dd2314e16fa06))
25
+ * solflare connect ([#4215](https://github.com/dynamic-labs/DynamicAuth/issues/4215)) ([#4219](https://github.com/dynamic-labs/DynamicAuth/issues/4219)) ([df39306](https://github.com/dynamic-labs/DynamicAuth/commit/df393069b9a9859052b2d55db8dfc3399d85f2a9))
26
+
2
27
  ### [1.0.2](https://github.com/dynamic-labs/DynamicAuth/compare/v1.0.1...v1.0.2) (2023-12-18)
3
28
 
4
29
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dynamic-labs/solana",
3
- "version": "1.0.2",
3
+ "version": "1.0.4",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/dynamic-labs/DynamicAuth.git",
@@ -27,11 +27,11 @@
27
27
  },
28
28
  "dependencies": {
29
29
  "@solana/web3.js": "1.70.1",
30
- "@dynamic-labs/rpc-providers": "1.0.2",
31
- "@dynamic-labs/types": "1.0.2",
32
- "@dynamic-labs/utils": "1.0.2",
33
- "@dynamic-labs/wallet-book": "1.0.2",
34
- "@dynamic-labs/wallet-connector-core": "1.0.2",
30
+ "@dynamic-labs/rpc-providers": "1.0.4",
31
+ "@dynamic-labs/types": "1.0.4",
32
+ "@dynamic-labs/utils": "1.0.4",
33
+ "@dynamic-labs/wallet-book": "1.0.4",
34
+ "@dynamic-labs/wallet-connector-core": "1.0.4",
35
35
  "eventemitter3": "5.0.1"
36
36
  },
37
37
  "peerDependencies": {}
@@ -3,8 +3,13 @@
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var _tslib = require('../_virtual/_tslib.cjs');
6
+ var utils = require('@dynamic-labs/utils');
6
7
  var solWalletConnector = require('./solWalletConnector.cjs');
7
8
  var solProviderHelper = require('./solProviderHelper.cjs');
9
+ require('@solana/web3.js');
10
+ require('@dynamic-labs/wallet-connector-core');
11
+ require('./injected/PhantomLedger.cjs');
12
+ var isSignedMessage = require('./utils/isSignedMessage.cjs');
8
13
 
9
14
  class CoinbaseSolana extends solWalletConnector.SolWalletConnector {
10
15
  constructor() {
@@ -40,7 +45,20 @@ class CoinbaseSolana extends solWalletConnector.SolWalletConnector {
40
45
  }
41
46
  signMessage(messageToSign) {
42
47
  return _tslib.__awaiter(this, void 0, void 0, function* () {
43
- return solProviderHelper.SolProviderHelper.signMessageWithName(messageToSign, this.name);
48
+ const walletAddress = yield this.fetchPublicAddress();
49
+ if (!walletAddress) {
50
+ return undefined;
51
+ }
52
+ const provider = yield this.getSigner();
53
+ if (!provider) {
54
+ return undefined;
55
+ }
56
+ const encodedMessage = new TextEncoder().encode(messageToSign);
57
+ const signedMessage = yield provider.signMessage(encodedMessage, walletAddress);
58
+ if (!signedMessage) {
59
+ return undefined;
60
+ }
61
+ return utils.bufferToBase64(isSignedMessage.isSignedMessage(signedMessage) ? signedMessage.signature : signedMessage);
44
62
  });
45
63
  }
46
64
  getConnectedAccounts() {
@@ -1,11 +1,11 @@
1
1
  import { SolWalletConnector } from './solWalletConnector';
2
- import { ISolana } from './types';
2
+ import { ICoinbaseSolanaSigner } from './types';
3
3
  export declare class CoinbaseSolana extends SolWalletConnector {
4
4
  name: string;
5
5
  setupEventListeners(): void;
6
6
  teardownEventListeners(): void;
7
7
  connect(): Promise<void>;
8
- getSigner(): Promise<ISolana | undefined>;
8
+ getSigner(): Promise<ICoinbaseSolanaSigner | undefined>;
9
9
  isInstalledOnBrowser(): boolean;
10
10
  fetchPublicAddress(): Promise<string | undefined>;
11
11
  signMessage(messageToSign: string): Promise<string | undefined>;
@@ -1,6 +1,11 @@
1
1
  import { __awaiter } from '../_virtual/_tslib.js';
2
+ import { bufferToBase64 } from '@dynamic-labs/utils';
2
3
  import { SolWalletConnector } from './solWalletConnector.js';
3
4
  import { SolProviderHelper } from './solProviderHelper.js';
5
+ import '@solana/web3.js';
6
+ import '@dynamic-labs/wallet-connector-core';
7
+ import './injected/PhantomLedger.js';
8
+ import { isSignedMessage } from './utils/isSignedMessage.js';
4
9
 
5
10
  class CoinbaseSolana extends SolWalletConnector {
6
11
  constructor() {
@@ -36,7 +41,20 @@ class CoinbaseSolana extends SolWalletConnector {
36
41
  }
37
42
  signMessage(messageToSign) {
38
43
  return __awaiter(this, void 0, void 0, function* () {
39
- return SolProviderHelper.signMessageWithName(messageToSign, this.name);
44
+ const walletAddress = yield this.fetchPublicAddress();
45
+ if (!walletAddress) {
46
+ return undefined;
47
+ }
48
+ const provider = yield this.getSigner();
49
+ if (!provider) {
50
+ return undefined;
51
+ }
52
+ const encodedMessage = new TextEncoder().encode(messageToSign);
53
+ const signedMessage = yield provider.signMessage(encodedMessage, walletAddress);
54
+ if (!signedMessage) {
55
+ return undefined;
56
+ }
57
+ return bufferToBase64(isSignedMessage(signedMessage) ? signedMessage.signature : signedMessage);
40
58
  });
41
59
  }
42
60
  getConnectedAccounts() {
package/src/Solflare.cjs CHANGED
@@ -17,15 +17,15 @@ class Solflare extends solWalletConnector.SolWalletConnector {
17
17
  }
18
18
  fetchPublicAddress() {
19
19
  return _tslib.__awaiter(this, void 0, void 0, function* () {
20
- if (utils.isMobile()) {
21
- const url = encodeURIComponent(window.location.toString());
22
- const ref = encodeURIComponent(window.location.origin);
23
- if (utils.isSamsungBrowser()) {
24
- window.location.assign(`solflare://ul/v1/browse/${url}?ref=${ref}`);
25
- }
26
- else {
27
- window.location.assign(`https://solflare.com/ul/v1/browse/${url}?ref=${ref}`);
28
- }
20
+ /**
21
+ * It should redirect to in-app browser if on mobile and if not in the in-app browser,
22
+ * this checks if it is not in the in-app browser by checking if the provider is not available.
23
+ */
24
+ if (utils.isMobile() && !this.isInstalledOnBrowser()) {
25
+ utils.handleMobileWalletRedirect({
26
+ nativeLink: 'solflare://ul/v1/browse',
27
+ universalLink: 'https://solflare.com/ul/v1/browse',
28
+ });
29
29
  return;
30
30
  }
31
31
  return solProviderHelper.SolProviderHelper.fetchPublicAddressWithName(this.name);
package/src/Solflare.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { __awaiter } from '../_virtual/_tslib.js';
2
- import { isMobile, isSamsungBrowser, bufferToBase64 } from '@dynamic-labs/utils';
2
+ import { isMobile, handleMobileWalletRedirect, bufferToBase64 } from '@dynamic-labs/utils';
3
3
  import { SolWalletConnector } from './solWalletConnector.js';
4
4
  import { SolProviderHelper } from './solProviderHelper.js';
5
5
 
@@ -13,15 +13,15 @@ class Solflare extends SolWalletConnector {
13
13
  }
14
14
  fetchPublicAddress() {
15
15
  return __awaiter(this, void 0, void 0, function* () {
16
- if (isMobile()) {
17
- const url = encodeURIComponent(window.location.toString());
18
- const ref = encodeURIComponent(window.location.origin);
19
- if (isSamsungBrowser()) {
20
- window.location.assign(`solflare://ul/v1/browse/${url}?ref=${ref}`);
21
- }
22
- else {
23
- window.location.assign(`https://solflare.com/ul/v1/browse/${url}?ref=${ref}`);
24
- }
16
+ /**
17
+ * It should redirect to in-app browser if on mobile and if not in the in-app browser,
18
+ * this checks if it is not in the in-app browser by checking if the provider is not available.
19
+ */
20
+ if (isMobile() && !this.isInstalledOnBrowser()) {
21
+ handleMobileWalletRedirect({
22
+ nativeLink: 'solflare://ul/v1/browse',
23
+ universalLink: 'https://solflare.com/ul/v1/browse',
24
+ });
25
25
  return;
26
26
  }
27
27
  return SolProviderHelper.fetchPublicAddressWithName(this.name);
package/src/index.d.ts CHANGED
@@ -4,4 +4,4 @@ export * from './Solflare';
4
4
  export declare const SolanaWalletConnectors: (props: any) => typeof import("./injected/BraveSol").BraveSol[];
5
5
  export { isSignedMessage } from './utils/isSignedMessage';
6
6
  export { isBackpackSolanaSigner } from './utils/isBackpackSolanaSigner';
7
- export type { ISolana, IBackpackSolanaSigner, SignedMessage, ISolanaSigner, } from './types';
7
+ export type { ISolana, IBackpackSolanaSigner, ICoinbaseSolanaSigner, SignedMessage, ISolanaSigner, } from './types';
@@ -2,6 +2,8 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
+ var _tslib = require('../../_virtual/_tslib.cjs');
6
+ var utils = require('@dynamic-labs/utils');
5
7
  var InjectedWalletBase = require('./InjectedWalletBase.cjs');
6
8
 
7
9
  class Phantom extends InjectedWalletBase.InjectedWalletBase {
@@ -9,6 +11,23 @@ class Phantom extends InjectedWalletBase.InjectedWalletBase {
9
11
  super(...arguments);
10
12
  this.name = 'Phantom';
11
13
  }
14
+ fetchPublicAddress() {
15
+ const _super = Object.create(null, {
16
+ fetchPublicAddress: { get: () => super.fetchPublicAddress }
17
+ });
18
+ return _tslib.__awaiter(this, void 0, void 0, function* () {
19
+ if (this.isInstalledOnBrowser()) {
20
+ return _super.fetchPublicAddress.call(this);
21
+ }
22
+ if (utils.isMobile()) {
23
+ utils.handleMobileWalletRedirect({
24
+ nativeLink: 'phantom://browse',
25
+ universalLink: 'https://phantom.app/ul/browse',
26
+ });
27
+ }
28
+ return undefined;
29
+ });
30
+ }
12
31
  }
13
32
 
14
33
  exports.Phantom = Phantom;
@@ -1,4 +1,5 @@
1
1
  import { InjectedWalletBase } from './InjectedWalletBase';
2
2
  export declare class Phantom extends InjectedWalletBase {
3
3
  name: string;
4
+ fetchPublicAddress(): Promise<string | undefined>;
4
5
  }
@@ -1,3 +1,5 @@
1
+ import { __awaiter } from '../../_virtual/_tslib.js';
2
+ import { isMobile, handleMobileWalletRedirect } from '@dynamic-labs/utils';
1
3
  import { InjectedWalletBase } from './InjectedWalletBase.js';
2
4
 
3
5
  class Phantom extends InjectedWalletBase {
@@ -5,6 +7,23 @@ class Phantom extends InjectedWalletBase {
5
7
  super(...arguments);
6
8
  this.name = 'Phantom';
7
9
  }
10
+ fetchPublicAddress() {
11
+ const _super = Object.create(null, {
12
+ fetchPublicAddress: { get: () => super.fetchPublicAddress }
13
+ });
14
+ return __awaiter(this, void 0, void 0, function* () {
15
+ if (this.isInstalledOnBrowser()) {
16
+ return _super.fetchPublicAddress.call(this);
17
+ }
18
+ if (isMobile()) {
19
+ handleMobileWalletRedirect({
20
+ nativeLink: 'phantom://browse',
21
+ universalLink: 'https://phantom.app/ul/browse',
22
+ });
23
+ }
24
+ return undefined;
25
+ });
26
+ }
8
27
  }
9
28
 
10
29
  export { Phantom };
package/src/types.d.ts CHANGED
@@ -9,7 +9,7 @@ declare global {
9
9
  Slope?: {
10
10
  new (): ISolana;
11
11
  };
12
- coinbaseSolana?: ISolana;
12
+ coinbaseSolana?: ICoinbaseSolanaSigner;
13
13
  glowSolana?: ISolana;
14
14
  phantom?: IWindowPhantom;
15
15
  solana?: ISolana;
@@ -59,7 +59,10 @@ export type IBackpackSolanaSigner = Omit<ISolanaSigner, 'signMessage'> & {
59
59
  signMessage: (message: Uint8Array, encoding?: string) => Promise<void | Uint8Array>;
60
60
  send: (transaction: Transaction, signers?: Signer[], options?: SendOptions, connection?: Connection, publicKey?: PublicKey) => Promise<TransactionSignature>;
61
61
  };
62
- export type ISolana = ISolanaSigner | IBackpackSolanaSigner;
62
+ export type ICoinbaseSolanaSigner = Omit<ISolanaSigner, 'signMessage'> & {
63
+ signMessage: (message: Uint8Array, publicKey?: string) => Promise<void | Uint8Array>;
64
+ };
65
+ export type ISolana = ISolanaSigner | IBackpackSolanaSigner | ICoinbaseSolanaSigner;
63
66
  export type ProviderFlag = 'isBraveWallet' | 'isGlow' | 'isPhantom' | 'isSolflare' | 'isExodus' | 'isBackpack' | 'isMagicEden';
64
67
  export type EthProviderCondition = ProviderCondition<ProviderFlag>;
65
68
  export {};