@getpara/cosmos-wallet-connectors 1.6.0 → 1.7.1
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
|
@@ -52,7 +52,7 @@ var __async = (__this, __arguments, generator) => {
|
|
|
52
52
|
};
|
|
53
53
|
|
|
54
54
|
// src/providers/CosmosExternalWalletContext.tsx
|
|
55
|
-
import { createContext as createContext2, useEffect as useEffect2, useMemo as useMemo2 } from "react";
|
|
55
|
+
import { createContext as createContext2, useEffect as useEffect2, useMemo as useMemo2, useRef } from "react";
|
|
56
56
|
|
|
57
57
|
// src/providers/ParaCosmosContext.tsx
|
|
58
58
|
import { createContext, useCallback, useContext, useEffect, useMemo } from "react";
|
|
@@ -134,7 +134,10 @@ function ParaCosmosProvider(_a) {
|
|
|
134
134
|
var useParaCosmos = () => useContext(ParaCosmosContext);
|
|
135
135
|
|
|
136
136
|
// src/providers/CosmosExternalWalletContext.tsx
|
|
137
|
-
import {
|
|
137
|
+
import {
|
|
138
|
+
useExternalWalletProviderStore as useExternalWalletProviderStore2,
|
|
139
|
+
WalletType as WalletType2
|
|
140
|
+
} from "@getpara/react-sdk";
|
|
138
141
|
import {
|
|
139
142
|
checkWallet,
|
|
140
143
|
WalletType as GrazWalletType,
|
|
@@ -144,7 +147,8 @@ import {
|
|
|
144
147
|
useConnect,
|
|
145
148
|
useDisconnect,
|
|
146
149
|
useSuggestChainAndConnect,
|
|
147
|
-
getChainInfo
|
|
150
|
+
getChainInfo,
|
|
151
|
+
getWallet as grazGetWallet
|
|
148
152
|
} from "@getpara/graz";
|
|
149
153
|
|
|
150
154
|
// src/stores/useStore.ts
|
|
@@ -171,7 +175,9 @@ var defaultCosmosExternalWallet = {
|
|
|
171
175
|
chains: [],
|
|
172
176
|
chainId: void 0,
|
|
173
177
|
disconnect: () => Promise.resolve(),
|
|
174
|
-
switchChain: () => Promise.resolve({})
|
|
178
|
+
switchChain: () => Promise.resolve({}),
|
|
179
|
+
signMessage: () => Promise.resolve({}),
|
|
180
|
+
signVerificationMessage: () => Promise.resolve({})
|
|
175
181
|
};
|
|
176
182
|
var CosmosExternalWalletContext = createContext2(defaultCosmosExternalWallet);
|
|
177
183
|
function CosmosExternalWalletProvider({ children, para, onSwitchWallet }) {
|
|
@@ -199,8 +205,10 @@ function CosmosExternalWalletProvider({ children, para, onSwitchWallet }) {
|
|
|
199
205
|
const { walletType } = useActiveWalletType();
|
|
200
206
|
const isLocalConnecting = useExternalWalletStore((state) => state.isConnecting);
|
|
201
207
|
const updateExternalWalletState = useExternalWalletStore((state) => state.updateState);
|
|
208
|
+
const fullAuthWallets = useExternalWalletProviderStore2((state) => state.fullAuthWallets);
|
|
202
209
|
const bufferAddress = multiChain ? (_a = account == null ? void 0 : account[selectedChainId]) == null ? void 0 : _a.address.toString() : account == null ? void 0 : account.address.toString();
|
|
203
210
|
const address = multiChain ? (_b = account == null ? void 0 : account[selectedChainId]) == null ? void 0 : _b.bech32Address : account == null ? void 0 : account.bech32Address;
|
|
211
|
+
const verificationMessage = useRef();
|
|
204
212
|
const reset = () => __async(this, null, function* () {
|
|
205
213
|
yield disconnectAsync();
|
|
206
214
|
yield para.logout();
|
|
@@ -223,13 +231,14 @@ function CosmosExternalWalletProvider({ children, para, onSwitchWallet }) {
|
|
|
223
231
|
}
|
|
224
232
|
return { error };
|
|
225
233
|
});
|
|
226
|
-
const login = (bufferAddress2, address2, providerName) => __async(this, null, function* () {
|
|
234
|
+
const login = (bufferAddress2, address2, grazWalletType, providerName) => __async(this, null, function* () {
|
|
227
235
|
try {
|
|
228
|
-
yield para.externalWalletLogin({
|
|
236
|
+
return yield para.externalWalletLogin({
|
|
229
237
|
address: bufferAddress2,
|
|
230
238
|
type: WalletType2.COSMOS,
|
|
231
239
|
provider: providerName,
|
|
232
|
-
addressBech32: address2
|
|
240
|
+
addressBech32: address2,
|
|
241
|
+
withFullParaAuth: fullAuthWallets == null ? void 0 : fullAuthWallets.includes(getWalletId(grazWalletType).toUpperCase())
|
|
233
242
|
});
|
|
234
243
|
} catch (err) {
|
|
235
244
|
yield reset();
|
|
@@ -243,7 +252,8 @@ function CosmosExternalWalletProvider({ children, para, onSwitchWallet }) {
|
|
|
243
252
|
address: bufferAddress,
|
|
244
253
|
type: WalletType2.COSMOS,
|
|
245
254
|
provider: getProviderName(walletType),
|
|
246
|
-
addressBech32: address
|
|
255
|
+
addressBech32: address,
|
|
256
|
+
withFullParaAuth: fullAuthWallets == null ? void 0 : fullAuthWallets.includes(getWalletId(walletType).toUpperCase())
|
|
247
257
|
});
|
|
248
258
|
}
|
|
249
259
|
}, [isConnecting, isReconnecting, address]);
|
|
@@ -253,6 +263,31 @@ function CosmosExternalWalletProvider({ children, para, onSwitchWallet }) {
|
|
|
253
263
|
reset();
|
|
254
264
|
}
|
|
255
265
|
}, [isConnecting, isReconnecting]);
|
|
266
|
+
const signMessage = (message) => __async(this, null, function* () {
|
|
267
|
+
const wallet = grazGetWallet(walletType);
|
|
268
|
+
if (!wallet) {
|
|
269
|
+
return { error: "Connected wallet not found" };
|
|
270
|
+
}
|
|
271
|
+
try {
|
|
272
|
+
const publicKey = (yield wallet.getKey(selectedChainId)).pubKey;
|
|
273
|
+
const signature = yield wallet.signArbitrary(selectedChainId, address, message);
|
|
274
|
+
return {
|
|
275
|
+
address: bufferAddress,
|
|
276
|
+
signature: signature.signature,
|
|
277
|
+
cosmosPublicKeyHex: Buffer.from(publicKey).toString("hex"),
|
|
278
|
+
cosmosSigner: address
|
|
279
|
+
};
|
|
280
|
+
} catch (e) {
|
|
281
|
+
if (e.message.includes("Request rejected")) {
|
|
282
|
+
return { error: "Signature request rejected" };
|
|
283
|
+
}
|
|
284
|
+
return { error: "An unknown error occurred" };
|
|
285
|
+
}
|
|
286
|
+
});
|
|
287
|
+
const signVerificationMessage = () => __async(this, null, function* () {
|
|
288
|
+
const signature = yield signMessage(verificationMessage.current);
|
|
289
|
+
return signature;
|
|
290
|
+
});
|
|
256
291
|
const connect2 = (walletType2, chainId) => __async(this, null, function* () {
|
|
257
292
|
updateExternalWalletState({ isConnecting: true });
|
|
258
293
|
if (!chainId) {
|
|
@@ -266,6 +301,8 @@ function CosmosExternalWalletProvider({ children, para, onSwitchWallet }) {
|
|
|
266
301
|
let address2;
|
|
267
302
|
let bufferAddress2;
|
|
268
303
|
let error;
|
|
304
|
+
let userExists = false;
|
|
305
|
+
let isVerified = false;
|
|
269
306
|
if (!walletType2) {
|
|
270
307
|
console.error("Graz wallet type not provided.");
|
|
271
308
|
return;
|
|
@@ -289,7 +326,10 @@ function CosmosExternalWalletProvider({ children, para, onSwitchWallet }) {
|
|
|
289
326
|
bufferAddress2 = connectedWallet.accounts[firstChain].address.toString();
|
|
290
327
|
if (connectedWallet.accounts[firstChain]) {
|
|
291
328
|
try {
|
|
292
|
-
yield login(bufferAddress2, address2, getProviderName(walletType2));
|
|
329
|
+
const loginResp = yield login(bufferAddress2, address2, walletType2, getProviderName(walletType2));
|
|
330
|
+
userExists = loginResp.userExists;
|
|
331
|
+
isVerified = loginResp.isVerified;
|
|
332
|
+
verificationMessage.current = loginResp.signatureVerificationMessage;
|
|
293
333
|
} catch (err) {
|
|
294
334
|
bufferAddress2 = void 0;
|
|
295
335
|
address2 = void 0;
|
|
@@ -306,16 +346,21 @@ function CosmosExternalWalletProvider({ children, para, onSwitchWallet }) {
|
|
|
306
346
|
}
|
|
307
347
|
}
|
|
308
348
|
updateExternalWalletState({ isConnecting: false });
|
|
309
|
-
return { address: address2, bufferAddress: bufferAddress2, error };
|
|
349
|
+
return { address: address2, bufferAddress: bufferAddress2, error, userExists, isVerified };
|
|
310
350
|
});
|
|
351
|
+
const getWallet = (walletType2) => incompleteWallets.find((w) => w.grazType === walletType2 || w.grazMobileType === walletType2);
|
|
311
352
|
const getProviderName = (walletType2) => {
|
|
312
353
|
var _a2;
|
|
313
|
-
return (_a2 =
|
|
354
|
+
return (_a2 = getWallet(walletType2)) == null ? void 0 : _a2.name;
|
|
355
|
+
};
|
|
356
|
+
const getWalletId = (walletType2) => {
|
|
357
|
+
var _a2;
|
|
358
|
+
return (_a2 = getWallet(walletType2)) == null ? void 0 : _a2.id;
|
|
314
359
|
};
|
|
315
360
|
const wallets = incompleteWallets.map((wallet) => {
|
|
316
361
|
return __spreadProps(__spreadValues({
|
|
317
362
|
connect: () => connect2(wallet.grazType),
|
|
318
|
-
connectMobile: () => connect2(wallet.
|
|
363
|
+
connectMobile: () => connect2(wallet.grazType),
|
|
319
364
|
getQrUri: () => "",
|
|
320
365
|
type: WalletType2.COSMOS
|
|
321
366
|
}, wallet), {
|
|
@@ -332,8 +377,16 @@ function CosmosExternalWalletProvider({ children, para, onSwitchWallet }) {
|
|
|
332
377
|
CosmosExternalWalletContext.Provider,
|
|
333
378
|
{
|
|
334
379
|
value: useMemo2(
|
|
335
|
-
() => ({
|
|
336
|
-
|
|
380
|
+
() => ({
|
|
381
|
+
wallets,
|
|
382
|
+
chains: formattedChains,
|
|
383
|
+
chainId: selectedChainId,
|
|
384
|
+
disconnect: disconnectAsync,
|
|
385
|
+
switchChain,
|
|
386
|
+
signMessage,
|
|
387
|
+
signVerificationMessage
|
|
388
|
+
}),
|
|
389
|
+
[wallets, formattedChains, selectedChainId, disconnectAsync, switchChain, signMessage, signVerificationMessage]
|
|
337
390
|
),
|
|
338
391
|
children
|
|
339
392
|
}
|
package/dist/index.js.br
CHANGED
|
Binary file
|
package/dist/index.js.gz
CHANGED
|
Binary file
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import { ReactNode } from 'react';
|
|
2
|
-
import { CommonChain, CommonWallet } from '
|
|
3
|
-
import ParaWeb from '@getpara/react-sdk';
|
|
2
|
+
import ParaWeb, { CommonChain, CommonWallet } from '@getpara/react-sdk';
|
|
4
3
|
export declare const defaultCosmosExternalWallet: {
|
|
5
4
|
wallets: any[];
|
|
6
5
|
chains: any[];
|
|
7
6
|
chainId: any;
|
|
8
7
|
disconnect: () => Promise<void>;
|
|
9
8
|
switchChain: () => Promise<{}>;
|
|
9
|
+
signMessage: () => Promise<{}>;
|
|
10
|
+
signVerificationMessage: () => Promise<{}>;
|
|
10
11
|
};
|
|
11
12
|
export declare const CosmosExternalWalletContext: import("react").Context<{
|
|
12
13
|
wallets: CommonWallet[];
|
|
@@ -16,6 +17,17 @@ export declare const CosmosExternalWalletContext: import("react").Context<{
|
|
|
16
17
|
switchChain: (chainId: string) => Promise<{
|
|
17
18
|
error?: string[];
|
|
18
19
|
}>;
|
|
20
|
+
signMessage: (message: string) => Promise<{
|
|
21
|
+
signature?: string;
|
|
22
|
+
error?: string;
|
|
23
|
+
}>;
|
|
24
|
+
signVerificationMessage: () => Promise<{
|
|
25
|
+
address?: string;
|
|
26
|
+
signature?: string;
|
|
27
|
+
cosmosPublicKeyHex?: string;
|
|
28
|
+
cosmosSigner?: string;
|
|
29
|
+
error?: string;
|
|
30
|
+
}>;
|
|
19
31
|
}>;
|
|
20
32
|
interface CosmosExternalWalletProviderProps {
|
|
21
33
|
children: ReactNode;
|
package/dist/types/Wallet.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@getpara/cosmos-wallet-connectors",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.7.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
"./connectors": "./dist/wallets/connectors/index.js"
|
|
10
10
|
},
|
|
11
11
|
"dependencies": {
|
|
12
|
-
"@getpara/react-sdk": "1.
|
|
12
|
+
"@getpara/react-sdk": "1.7.1",
|
|
13
13
|
"zustand": "^4.5.2",
|
|
14
14
|
"zustand-sync-tabs": "^0.2.2"
|
|
15
15
|
},
|
|
@@ -39,5 +39,5 @@
|
|
|
39
39
|
"dist",
|
|
40
40
|
"package.json"
|
|
41
41
|
],
|
|
42
|
-
"gitHead": "
|
|
42
|
+
"gitHead": "767395af96d4a724946a092de760e9137a73369a"
|
|
43
43
|
}
|
|
@@ -1,26 +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;
|
|
23
|
-
export type CommonChain = {
|
|
24
|
-
id: string | number;
|
|
25
|
-
name: string;
|
|
26
|
-
};
|