@getpara/solana-wallet-connectors 1.6.0 → 1.7.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/dist/index.js CHANGED
@@ -37,14 +37,14 @@ var __async = (__this, __arguments, generator) => {
37
37
  };
38
38
 
39
39
  // src/providers/SolanaExternalWalletContext.tsx
40
- import { createContext as createContext2, useEffect as useEffect2, useMemo as useMemo2 } from "react";
40
+ import { createContext as createContext2, useEffect as useEffect2, useMemo as useMemo2, useRef } from "react";
41
41
  import { useWallet } from "@solana/wallet-adapter-react";
42
42
  import { WalletReadyState } from "@solana/wallet-adapter-base";
43
43
 
44
44
  // src/providers/ParaSolanaProvider.tsx
45
45
  import { createContext, useContext, useEffect, useMemo, useState } from "react";
46
46
  import { ConnectionProvider, WalletProvider as SolanaWalletProvider } from "@solana/wallet-adapter-react";
47
- import { useExternalWalletProviderStore } from "@getpara/react-sdk";
47
+ import { useClient, useExternalWalletProviderStore } from "@getpara/react-sdk";
48
48
  import {
49
49
  createDefaultAddressSelector,
50
50
  createDefaultAuthorizationResultCache,
@@ -62,12 +62,14 @@ function ParaSolanaProvider({
62
62
  endpoint,
63
63
  appIdentity,
64
64
  chain,
65
- connectionConfig
65
+ connectionConfig,
66
+ para: _para
66
67
  }) {
67
68
  const updateExternalWalletProviderState = useExternalWalletProviderStore((state) => state.updateState);
68
69
  const SolanaProvider = useExternalWalletProviderStore((state) => state.SolanaProvider);
69
70
  const solanaContext = useExternalWalletProviderStore((state) => state.solanaContext);
70
71
  const [shouldAutoConnect, setShouldAutoConnect] = useState(true);
72
+ const para = _para != null ? _para : useClient();
71
73
  useEffect(() => {
72
74
  setShouldAutoConnect(false);
73
75
  }, []);
@@ -96,7 +98,19 @@ function ParaSolanaProvider({
96
98
  })
97
99
  ],
98
100
  localStorageKey: "paraSolanaExternal",
99
- autoConnect: shouldAutoConnect,
101
+ autoConnect: (adapter) => __async(this, null, function* () {
102
+ var _a;
103
+ const hasParaExternalWallet = (_a = Object.values(para.externalWallets)) == null ? void 0 : _a.find((w) => w.name === adapter.name);
104
+ if (shouldAutoConnect && hasParaExternalWallet) {
105
+ if (!para.isExternalWalletAuth) {
106
+ return true;
107
+ } else if (para.isExternalWalletAuth && (yield para.isFullyLoggedIn())) {
108
+ return true;
109
+ }
110
+ return false;
111
+ }
112
+ return false;
113
+ }),
100
114
  children: /* @__PURE__ */ jsx(ParaSolanaContext.Provider, { value, children })
101
115
  }
102
116
  ) });
@@ -105,10 +119,14 @@ var useParaSolana = () => useContext(ParaSolanaContext);
105
119
 
106
120
  // src/providers/SolanaExternalWalletContext.tsx
107
121
  import { WalletType } from "@getpara/web-sdk";
122
+ import { useExternalWalletProviderStore as useExternalWalletProviderStore2 } from "@getpara/react-sdk";
123
+ import bs58 from "bs58";
108
124
  import { jsx as jsx2 } from "react/jsx-runtime";
109
125
  var defaultSolanaExternalWallet = {
110
126
  wallets: [],
111
- disconnect: () => Promise.resolve()
127
+ disconnect: () => Promise.resolve(),
128
+ signMessage: () => Promise.resolve({}),
129
+ signVerificationMessage: () => Promise.resolve({})
112
130
  };
113
131
  var SolanaExternalWalletContext = createContext2(defaultSolanaExternalWallet);
114
132
  function SolanaExternalWalletProvider({ children, para, onSwitchWallet }) {
@@ -118,16 +136,28 @@ function SolanaExternalWalletProvider({ children, para, onSwitchWallet }) {
118
136
  disconnect: _disconnect,
119
137
  publicKey: solanaAddress,
120
138
  wallet,
121
- connecting
139
+ connecting,
140
+ signMessage: solanaSignMessage,
141
+ connected
122
142
  } = useWallet();
123
143
  const { wallets: walletFns } = useParaSolana();
144
+ const fullAuthWallets = useExternalWalletProviderStore2((state) => state.fullAuthWallets);
145
+ const verificationMessage = useRef();
124
146
  const reset = () => __async(this, null, function* () {
125
147
  yield _disconnect();
126
148
  yield para.logout();
127
149
  });
128
150
  const login = (address, providerName) => __async(this, null, function* () {
151
+ var _a, _b;
129
152
  try {
130
- yield para.externalWalletLogin({ address, type: WalletType.SOLANA, provider: providerName });
153
+ return yield para.externalWalletLogin({
154
+ address,
155
+ type: WalletType.SOLANA,
156
+ provider: providerName,
157
+ withFullParaAuth: fullAuthWallets == null ? void 0 : fullAuthWallets.includes(
158
+ (_b = (_a = getWallet(providerName != null ? providerName : "")) == null ? void 0 : _a.id.toUpperCase()) != null ? _b : ""
159
+ )
160
+ });
131
161
  } catch (err) {
132
162
  yield reset();
133
163
  throw "Error logging you in. Please try again.";
@@ -160,21 +190,45 @@ function SolanaExternalWalletProvider({ children, para, onSwitchWallet }) {
160
190
  switchWallet(solanaAddress == null ? void 0 : solanaAddress.toString());
161
191
  }
162
192
  }, [solanaAddress, connecting]);
193
+ const signMessage = (message) => __async(this, null, function* () {
194
+ try {
195
+ const encodedMessage = new TextEncoder().encode(message);
196
+ const signature = yield solanaSignMessage(encodedMessage);
197
+ return {
198
+ address: solanaAddress.toString(),
199
+ signature: bs58.encode(signature)
200
+ };
201
+ } catch (e) {
202
+ if (e.message.includes("User rejected the request")) {
203
+ return { error: "Signature request rejected" };
204
+ }
205
+ return { error: "An unknown error occurred" };
206
+ }
207
+ });
208
+ const signVerificationMessage = () => __async(this, null, function* () {
209
+ const signature = yield signMessage(verificationMessage.current);
210
+ return signature;
211
+ });
163
212
  const connect = (adapter) => __async(this, null, function* () {
164
213
  yield _disconnect();
165
214
  if (!adapter) {
166
- return { address: void 0, error: "Adapter not found." };
215
+ return { address: void 0, error: "Adapter not found.", userExists: false, isVerified: false };
167
216
  }
168
217
  selectWallet(adapter.name);
169
218
  yield new Promise((resolve) => setTimeout(resolve, 100));
170
219
  let address;
171
220
  let error;
221
+ let userExists = false;
222
+ let isVerified = false;
172
223
  try {
173
224
  yield adapter.connect();
174
225
  address = adapter.publicKey.toString();
175
226
  if (address) {
176
227
  try {
177
- yield login(address, adapter.name);
228
+ const loginResp = yield login(address, adapter.name);
229
+ userExists = loginResp.userExists;
230
+ isVerified = loginResp.isVerified;
231
+ verificationMessage.current = loginResp.signatureVerificationMessage;
178
232
  } catch (err) {
179
233
  yield _disconnect();
180
234
  address = void 0;
@@ -195,7 +249,7 @@ function SolanaExternalWalletProvider({ children, para, onSwitchWallet }) {
195
249
  }
196
250
  }
197
251
  }
198
- return { address, error };
252
+ return { address, error, userExists, isVerified };
199
253
  });
200
254
  const getAdapter = (name) => {
201
255
  var _a;
@@ -212,11 +266,23 @@ function SolanaExternalWalletProvider({ children, para, onSwitchWallet }) {
212
266
  installed: adapter && ((adapter == null ? void 0 : adapter.readyState) === WalletReadyState.Installed || (adapter == null ? void 0 : adapter.readyState) === WalletReadyState.Loadable)
213
267
  }, metaData);
214
268
  });
269
+ const getWallet = (name) => wallets.find((w) => w.name === name);
215
270
  const disconnect = () => __async(this, null, function* () {
216
271
  yield _disconnect();
217
- typeof window !== void 0 && (window == null ? void 0 : window.location.reload());
272
+ if (connected) {
273
+ typeof window !== void 0 && (window == null ? void 0 : window.location.reload());
274
+ }
218
275
  });
219
- return /* @__PURE__ */ jsx2(SolanaExternalWalletContext.Provider, { value: useMemo2(() => ({ wallets, disconnect }), [wallets, disconnect]), children });
276
+ return /* @__PURE__ */ jsx2(
277
+ SolanaExternalWalletContext.Provider,
278
+ {
279
+ value: useMemo2(
280
+ () => ({ wallets, disconnect, signMessage, signVerificationMessage }),
281
+ [wallets, disconnect, signMessage, signVerificationMessage]
282
+ ),
283
+ children
284
+ }
285
+ );
220
286
  }
221
287
 
222
288
  // src/wallets/connectors/phantom/phantomIcon.ts
package/dist/index.js.br CHANGED
Binary file
package/dist/index.js.gz CHANGED
Binary file
@@ -1,5 +1,6 @@
1
1
  import { ReactNode } from 'react';
2
2
  import { WalletList } from '../types/Wallet.js';
3
+ import ParaWeb from '@getpara/react-sdk';
3
4
  import { type ConnectionConfig } from '@solana/web3.js';
4
5
  import { Chain } from '@solana-mobile/mobile-wallet-adapter-protocol';
5
6
  export declare const defaultWallet: {
@@ -31,8 +32,9 @@ interface ParaSolanaProviderProps {
31
32
  * Ref: https://docs.solanamobile.com/reference/typescript/mobile-wallet-adapter#web3mobilewalletauthorize
32
33
  */
33
34
  chain: Chain;
35
+ para?: ParaWeb;
34
36
  }
35
- export declare function ParaSolanaProvider({ children, wallets: walletFns, endpoint, appIdentity, chain, connectionConfig, }: ParaSolanaProviderProps): import("react/jsx-runtime").JSX.Element;
37
+ export declare function ParaSolanaProvider({ children, wallets: walletFns, endpoint, appIdentity, chain, connectionConfig, para: _para, }: ParaSolanaProviderProps): import("react/jsx-runtime").JSX.Element;
36
38
  export declare const useParaSolana: () => {
37
39
  wallets: WalletList;
38
40
  };
@@ -1,13 +1,24 @@
1
1
  import { ReactNode } from 'react';
2
- import { CommonWallet } from '../types/CommonTypes.js';
3
2
  import ParaWeb from '@getpara/web-sdk';
3
+ import { CommonWallet } from '@getpara/react-sdk';
4
4
  export declare const defaultSolanaExternalWallet: {
5
5
  wallets: any[];
6
6
  disconnect: () => Promise<void>;
7
+ signMessage: () => Promise<{}>;
8
+ signVerificationMessage: () => Promise<{}>;
7
9
  };
8
10
  export declare const SolanaExternalWalletContext: import("react").Context<{
9
11
  wallets: CommonWallet[];
10
12
  disconnect: () => Promise<void>;
13
+ signMessage: (message: string) => Promise<{
14
+ signature?: string;
15
+ error?: string;
16
+ }>;
17
+ signVerificationMessage: () => Promise<{
18
+ address?: string;
19
+ signature?: string;
20
+ error?: string;
21
+ }>;
11
22
  }>;
12
23
  interface SolanaExternalWalletProviderProps {
13
24
  children: ReactNode;
@@ -1,4 +1,4 @@
1
- import { WalletMetadata } from './CommonTypes.js';
1
+ import { WalletMetadata } from '@getpara/react-sdk';
2
2
  export type Wallet = {
3
3
  getUri?: (uri: string) => string;
4
4
  } & WalletMetadata;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@getpara/solana-wallet-connectors",
3
- "version": "1.6.0",
3
+ "version": "1.7.0",
4
4
  "type": "module",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -9,7 +9,8 @@
9
9
  "./connectors": "./dist/wallets/connectors/index.js"
10
10
  },
11
11
  "dependencies": {
12
- "@getpara/react-sdk": "1.6.0"
12
+ "@getpara/react-sdk": "1.7.0",
13
+ "bs58": "6.0.0"
13
14
  },
14
15
  "scripts": {
15
16
  "build": "rm -rf dist && yarn typegen && node ./scripts/build.mjs",
@@ -37,5 +38,5 @@
37
38
  "dist",
38
39
  "package.json"
39
40
  ],
40
- "gitHead": "2dd6c8ea893d72d693804e5c5b0856d2ea6c3a7a"
41
+ "gitHead": "241b03ee3d3502af3b8d702dabd615b266da10ae"
41
42
  }
@@ -1,22 +0,0 @@
1
- export type WalletMetadata = {
2
- id: string;
3
- name: string;
4
- iconUrl: string;
5
- installed?: boolean;
6
- isExtension?: boolean;
7
- isMobile?: boolean;
8
- isWeb?: boolean;
9
- downloadUrl?: string;
10
- getQrUri?: () => Promise<string>;
11
- };
12
- export type CommonWallet = {
13
- connect: () => Promise<{
14
- address?: string;
15
- error?: string;
16
- }>;
17
- connectMobile: (isManualWalletConnect?: boolean) => Promise<{
18
- address?: string;
19
- error?: string;
20
- }>;
21
- type: 'EVM' | 'SOLANA' | 'COSMOS';
22
- } & WalletMetadata;