@getpara/cosmos-wallet-connectors 2.0.0-alpha.7 → 2.0.0-alpha.71

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/README.md ADDED
@@ -0,0 +1,13 @@
1
+ https://www.npmjs.com/package/@getpara/cosmos-wallet-connectors
2
+
3
+ `@getpara/cosmos-wallet-connectors` is a package that provides wallet connectors for Cosmos-based blockchains when using Para's React SDK Lite.
4
+ This package enables integration with Cosmos wallets like Keplr, Leap, and Cosmostation in Para applications. After installation, you can configure it in your ParaProvider to support external Cosmos wallet connections.
5
+ ###Prerequisites
6
+
7
+ To use Para, you need an API key. This key authenticates your requests to Para services and is essential for integration.
8
+
9
+ Don't have an API key yet? Request access to the [Developer Portal](https://developer.getpara.com/) to create API keys, manage billing, teams, and more.
10
+
11
+ ###Learn more
12
+
13
+ For more information on Para’s Cosmos wallet connection visit the [Para Docs](https://docs.getpara.com/v2/react/guides/external-wallets/cosmos-lite#cosmos-wallets-with-react-sdk-lite)
package/dist/index.d.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  export { CosmosExternalWalletContext } from './providers/CosmosExternalWalletContext.js';
2
- export type { CosmosExternalWalletContextType } from './providers/CosmosExternalWalletContext.js';
2
+ export { type CosmosExternalWalletContextType, type CosmosSignResult } from './providers/CosmosExternalWalletContext.js';
3
3
  export { ParaCosmosProvider } from './providers/ParaCosmosContext.js';
4
4
  export type { ParaCosmosProviderProps, ParaGrazProviderProps, ParaCosmosProviderConfig, } from './providers/ParaCosmosContext.js';
5
5
  export * from './wallets/connectors/index.js';
6
6
  export type { WalletList } from './types/Wallet.js';
7
+ export type * from './types/ExternalHooks.js';
@@ -1,43 +1,15 @@
1
1
  import { PropsWithChildren } from 'react';
2
2
  import { ParaCosmosProviderConfig } from './ParaCosmosContext.js';
3
3
  import { WalletWithType } from '../types/Wallet.js';
4
- import ParaWeb, { Wallet } from '@getpara/web-sdk';
5
- import type { CommonChain, CommonWallet, TExternalWallet } from '@getpara/react-common';
6
- export type CosmosExternalWalletContextType = {
7
- wallets: CommonWallet[];
8
- chains: CommonChain[];
9
- chainId?: string;
10
- disconnect: () => Promise<void>;
11
- switchChain: (chainId: string) => Promise<{
12
- error?: string[];
13
- }>;
14
- connectParaEmbedded: () => Promise<{
15
- result?: unknown;
16
- error?: string;
17
- }>;
18
- signMessage: (message: string) => Promise<{
19
- signature?: string;
20
- error?: string;
21
- }>;
22
- signVerificationMessage: () => Promise<{
23
- address?: string;
24
- signature?: string;
25
- cosmosPublicKeyHex?: string;
26
- cosmosSigner?: string;
27
- error?: string;
28
- }>;
4
+ import { type ChainManagement, type ConnectParaEmbedded, type ExternalWalletContextType, type ExternalWalletProviderConfig, type ExternalWalletProviderConfigBase, type SignResult } from '@getpara/react-common';
5
+ import { TExternalHooks } from './externalHooks.js';
6
+ export type CosmosSignResult = SignResult & {
7
+ cosmosPublicKeyHex?: string;
8
+ cosmosSigner?: string;
9
+ addressBech32?: string;
29
10
  };
30
- export type CosmosExternalWalletProviderConfig = {
31
- onSwitchWallet?: (args: {
32
- address?: string;
33
- error?: string;
34
- }) => void;
35
- para: ParaWeb;
36
- walletsWithFullAuth: TExternalWallet[];
37
- connectedWallet?: Omit<Wallet, 'signer'> | null;
38
- };
39
- export type CosmosExternalWalletProviderConfigFull = {
40
- wallets: WalletWithType[];
41
- } & Omit<ParaCosmosProviderConfig, 'wallets'> & CosmosExternalWalletProviderConfig;
11
+ export type CosmosExternalWalletContextType = ExternalWalletContextType<CosmosSignResult> & ChainManagement<string> & TExternalHooks & ConnectParaEmbedded;
12
+ export type CosmosExternalWalletProviderConfig = ExternalWalletProviderConfigBase;
13
+ export type CosmosExternalWalletProviderConfigFull = ExternalWalletProviderConfig<WalletWithType, Omit<ParaCosmosProviderConfig, 'wallets'>>;
42
14
  export declare const CosmosExternalWalletContext: import("react").Context<CosmosExternalWalletContextType>;
43
- export declare function CosmosExternalWalletProvider({ children, onSwitchWallet, selectedChainId, wallets: incompleteWallets, chains, multiChain, shouldUseSuggestChainAndConnect, onSwitchChain, para, walletsWithFullAuth, connectedWallet, }: CosmosExternalWalletProviderConfigFull & PropsWithChildren): import("react/jsx-runtime").JSX.Element;
15
+ export declare function CosmosExternalWalletProvider({ children, onSwitchWallet, selectedChainId, wallets: incompleteWallets, chains, multiChain, shouldUseSuggestChainAndConnect, onSwitchChain, para, walletsWithFullAuth, connectedWallet: connectedWalletProp, includeWalletVerification, connectionOnly, }: CosmosExternalWalletProviderConfigFull & PropsWithChildren): import("react/jsx-runtime").JSX.Element;
@@ -15,20 +15,19 @@ import {
15
15
  useDisconnect,
16
16
  useSuggestChainAndConnect,
17
17
  getChainInfo,
18
- getWallet as grazGetWallet
19
- } from "@getpara/graz";
18
+ getWallet as grazGetWallet,
19
+ WALLET_TYPES
20
+ } from "graz";
20
21
  import { useExternalWalletStore } from "../stores/useStore.js";
21
- const defaultCosmosExternalWallet = {
22
- wallets: [],
23
- chains: [],
24
- chainId: void 0,
25
- disconnect: () => Promise.resolve(),
26
- switchChain: () => Promise.resolve({}),
27
- connectParaEmbedded: () => Promise.resolve({}),
28
- signMessage: () => Promise.resolve({}),
29
- signVerificationMessage: () => Promise.resolve({})
30
- };
31
- const CosmosExternalWalletContext = createContext(defaultCosmosExternalWallet);
22
+ import { rawSecp256k1PubkeyToRawAddress } from "@getpara/web-sdk";
23
+ import {
24
+ defaultCosmosExternalWallet
25
+ } from "@getpara/react-common";
26
+ import { formatEthHexAddress } from "../utils/formatEthHexAddress.js";
27
+ import { externalHooks } from "./externalHooks.js";
28
+ const CosmosExternalWalletContext = createContext(
29
+ defaultCosmosExternalWallet
30
+ );
32
31
  function CosmosExternalWalletProvider({
33
32
  children,
34
33
  onSwitchWallet,
@@ -40,26 +39,34 @@ function CosmosExternalWalletProvider({
40
39
  onSwitchChain,
41
40
  para,
42
41
  walletsWithFullAuth,
43
- connectedWallet
42
+ connectedWallet: connectedWalletProp,
43
+ includeWalletVerification,
44
+ connectionOnly
44
45
  }) {
45
- var _a, _b;
46
+ var _a, _b, _c;
46
47
  const { suggestAndConnectAsync } = useSuggestChainAndConnect();
47
48
  const {
48
49
  data: account,
49
50
  isConnecting,
50
51
  isReconnecting,
51
52
  isConnected
52
- } = useAccount({
53
- chainId: multiChain ? chains.map((c) => c.chainId) : selectedChainId,
54
- multiChain
55
- });
53
+ } = useAccount(
54
+ multiChain ? {
55
+ chainId: chains.map((c) => c.chainId)
56
+ } : selectedChainId ? {
57
+ chainId: [selectedChainId]
58
+ } : void 0
59
+ );
56
60
  const { connectAsync } = useConnect();
57
- const { disconnectAsync } = useDisconnect();
61
+ const { disconnectAsync, status: disconnectStatus } = useDisconnect();
58
62
  const { walletType } = useActiveWalletType();
59
63
  const isLocalConnecting = useExternalWalletStore((state) => state.isConnecting);
60
64
  const updateExternalWalletState = useExternalWalletStore((state) => state.updateState);
61
- const bufferAddress = multiChain ? (_a = account == null ? void 0 : account[selectedChainId]) == null ? void 0 : _a.address.toString() : account == null ? void 0 : account.address.toString();
62
- const address = multiChain ? (_b = account == null ? void 0 : account[selectedChainId]) == null ? void 0 : _b.bech32Address : account == null ? void 0 : account.bech32Address;
65
+ const isConnectError = useRef(false);
66
+ const connectedWallet = connectedWalletProp ? para.findWallet(connectedWalletProp.id, connectedWalletProp.type) : null;
67
+ const ethAddress = (_b = (_a = account == null ? void 0 : account[selectedChainId]) == null ? void 0 : _a.ethereumHexAddress) == null ? void 0 : _b.toLowerCase();
68
+ const address = (_c = account == null ? void 0 : account[selectedChainId]) == null ? void 0 : _c.bech32Address;
69
+ const disconnectTypeRef = useRef();
63
70
  const verificationMessage = useRef();
64
71
  const reset = () => __async(this, null, function* () {
65
72
  yield disconnectAsync();
@@ -80,7 +87,7 @@ function CosmosExternalWalletProvider({
80
87
  }
81
88
  const connectedWallet2 = yield shouldUseSuggestChainAndConnect ? suggestAndConnectAsync({ walletType, chainInfo }) : connectAsync({ walletType, chainId });
82
89
  changeResp.address = connectedWallet2.accounts[chainId].bech32Address;
83
- changeResp.bufferAddress = connectedWallet2.accounts[chainId].address.toString();
90
+ changeResp.ethAddress = formatEthHexAddress(connectedWallet2.accounts[chainId].address);
84
91
  } catch (err) {
85
92
  if (err.message === "No wallet exists") {
86
93
  changeResp.error = err.message;
@@ -92,69 +99,102 @@ function CosmosExternalWalletProvider({
92
99
  onSwitchWallet(changeResp);
93
100
  if (!changeResp.error) {
94
101
  onSwitchChain(chainId);
95
- const storedExternalWallet = para.externalWallets[(_a2 = changeResp.bufferAddress) != null ? _a2 : ""];
102
+ const storedExternalWallet = para.externalWallets[(_a2 = changeResp.ethAddress) != null ? _a2 : ""];
103
+ const { provider, providerId } = getProvider(walletType);
96
104
  para.setExternalWallet({
97
- address: changeResp.bufferAddress,
105
+ partnerId: para.partnerId,
106
+ address: changeResp.ethAddress,
98
107
  type: "COSMOS",
99
- provider: getProviderName(walletType),
108
+ provider,
109
+ providerId,
100
110
  addressBech32: changeResp.address,
101
- withFullParaAuth: storedExternalWallet.isExternalWithParaAuth
111
+ withFullParaAuth: storedExternalWallet.isExternalWithParaAuth,
112
+ withVerification: includeWalletVerification,
113
+ isConnectionOnly: connectionOnly
102
114
  });
103
115
  }
104
116
  return { error };
105
117
  });
106
- const login = (bufferAddress2, address2, isFullAuthWallet, providerName) => __async(this, null, function* () {
118
+ const login = (_0) => __async(this, [_0], function* ({
119
+ address: address2,
120
+ addressBech32,
121
+ withFullParaAuth,
122
+ providerId,
123
+ provider
124
+ }) {
107
125
  try {
108
126
  return yield para.loginExternalWallet({
109
127
  externalWallet: {
110
- address: bufferAddress2,
128
+ partnerId: para.partnerId,
129
+ address: address2,
111
130
  type: "COSMOS",
112
- provider: providerName,
113
- addressBech32: address2,
114
- withFullParaAuth: isFullAuthWallet
115
- }
131
+ provider,
132
+ providerId,
133
+ addressBech32,
134
+ withFullParaAuth,
135
+ withVerification: includeWalletVerification,
136
+ isConnectionOnly: connectionOnly
137
+ },
138
+ uri: window == null ? void 0 : window.location.origin,
139
+ chainId: selectedChainId
116
140
  });
117
- } catch (err) {
141
+ } catch (e) {
118
142
  yield reset();
119
143
  throw "Error logging you in. Please try again.";
120
144
  }
121
145
  });
122
146
  useEffect(() => {
123
- const storedExternalWallet = para.externalWallets[bufferAddress != null ? bufferAddress : ""];
124
- if (isConnected && !isConnecting && !isReconnecting && !isLocalConnecting && !!bufferAddress && !storedExternalWallet && walletType !== GrazWalletType.PARA) {
147
+ const storedExternalWallet = para.externalWallets[ethAddress != null ? ethAddress : ""];
148
+ if (isConnected && !isConnecting && !isReconnecting && !isLocalConnecting && !!ethAddress && !storedExternalWallet && walletType !== GrazWalletType.PARA && !disconnectTypeRef.current) {
125
149
  reset();
126
150
  }
127
151
  }, [isConnecting, isLocalConnecting, isReconnecting, isConnected]);
128
152
  useEffect(() => {
129
153
  const connect2 = () => __async(this, null, function* () {
130
154
  var _a2;
131
- if (!isLocalConnecting && !isConnecting && !isReconnecting && connectedWallet && connectedWallet.type === "COSMOS" && (connectedWallet.isExternal ? walletType !== ((_a2 = connectedWallet.name) == null ? void 0 : _a2.toLowerCase()) : walletType !== "para")) {
155
+ if (!isLocalConnecting && !isConnecting && !isReconnecting && connectedWallet && connectedWallet.type === "COSMOS" && (connectedWallet.isExternal ? walletType !== ((_a2 = connectedWallet.name) == null ? void 0 : _a2.toLowerCase()) : walletType !== "para") && !disconnectTypeRef.current && !isConnectError.current) {
132
156
  const isLoggedIn = yield para.isFullyLoggedIn();
133
157
  if (!isLoggedIn) {
134
158
  return;
135
159
  }
136
160
  const chainId = multiChain ? chains.map((c) => c.chainId) : selectedChainId;
137
- yield connectAsync({
138
- walletType: connectedWallet.isExternal ? connectedWallet.name.toLowerCase() : GrazWalletType.PARA,
139
- chainId
140
- });
161
+ const targetWalletType = connectedWallet.isExternal ? connectedWallet.name.toLowerCase() : GrazWalletType.PARA;
162
+ try {
163
+ yield connectAsync({
164
+ walletType: targetWalletType,
165
+ chainId
166
+ });
167
+ } catch (e) {
168
+ isConnectError.current = true;
169
+ }
141
170
  }
142
171
  });
143
172
  connect2();
144
173
  }, [isLocalConnecting, isConnecting, isReconnecting, walletType, connectedWallet]);
145
- const signMessage = (message) => __async(this, null, function* () {
146
- const wallet = grazGetWallet(walletType);
174
+ const signMessage = (_0) => __async(this, [_0], function* ({ message, externalWallet }) {
175
+ let wallet, signAddress, signEthAddress;
176
+ if (externalWallet) {
177
+ const commonWallet = wallets.find((w) => w.id === externalWallet.providerId);
178
+ wallet = grazGetWallet(commonWallet == null ? void 0 : commonWallet.grazType);
179
+ signAddress = externalWallet.addressBech32;
180
+ signEthAddress = externalWallet.address;
181
+ } else {
182
+ wallet = grazGetWallet(walletType);
183
+ signAddress = address;
184
+ signEthAddress = ethAddress;
185
+ }
147
186
  if (!wallet) {
148
187
  return { error: "Connected wallet not found" };
149
188
  }
150
189
  try {
151
190
  const publicKey = (yield wallet.getKey(selectedChainId)).pubKey;
152
- const signature = yield wallet.signArbitrary(selectedChainId, address, message);
191
+ const signature = yield wallet.signArbitrary(selectedChainId, signAddress, message);
153
192
  return {
154
- address: bufferAddress,
193
+ address: signEthAddress,
194
+ addressBech32: signAddress,
155
195
  signature: signature.signature,
156
196
  cosmosPublicKeyHex: Buffer.from(publicKey).toString("hex"),
157
- cosmosSigner: address
197
+ cosmosSigner: signAddress
158
198
  };
159
199
  } catch (e) {
160
200
  if (e.message.includes("Request rejected")) {
@@ -164,82 +204,119 @@ function CosmosExternalWalletProvider({
164
204
  }
165
205
  });
166
206
  const signVerificationMessage = () => __async(this, null, function* () {
167
- const signature = yield signMessage(verificationMessage.current);
207
+ const signature = yield signMessage({ message: verificationMessage.current });
168
208
  return signature;
169
209
  });
170
- const connect = (walletType2, chainId) => __async(this, null, function* () {
210
+ const connectBase = (walletType2, chainId) => __async(this, null, function* () {
171
211
  var _a2;
172
- updateExternalWalletState({ isConnecting: true });
173
- const walletId = (_a2 = getWallet(walletType2)) == null ? void 0 : _a2.id;
174
- const isFullAuthWallet = walletsWithFullAuth.includes(walletId.toUpperCase());
175
212
  if (!chainId) {
176
213
  yield disconnectAsync();
177
214
  }
178
215
  const _chainId = chainId != null ? chainId : multiChain ? chains.map((c) => c.chainId) : selectedChainId;
179
216
  if (!_chainId) {
180
- console.error("Chain id not provided.");
181
- return;
217
+ throw new Error("Chain id not provided.");
182
218
  }
183
- let address2;
184
- let bufferAddress2;
185
- let error;
186
- let authState;
187
219
  if (!walletType2) {
188
- console.error("Graz wallet type not provided.");
189
- return;
190
- } else {
191
- try {
192
- let chainInfo;
193
- if (shouldUseSuggestChainAndConnect) {
194
- if (typeof _chainId !== "string") {
195
- console.error("multiChain is not compatible with shouldUseSuggestChainAndConnect.");
196
- return;
197
- }
198
- chainInfo = getChainInfo({ chainId: _chainId });
199
- if (!chainInfo) {
200
- console.error("Chain not found.");
201
- return;
202
- }
203
- }
204
- const connectedWallet2 = yield shouldUseSuggestChainAndConnect ? suggestAndConnectAsync({ walletType: walletType2, chainInfo }) : connectAsync({ walletType: walletType2, chainId: _chainId });
205
- const firstChain = !chainId ? selectedChainId : typeof _chainId === "string" ? _chainId : _chainId[0];
206
- address2 = connectedWallet2.accounts[firstChain].bech32Address;
207
- bufferAddress2 = connectedWallet2.accounts[firstChain].address.toString();
208
- if (connectedWallet2.accounts[firstChain]) {
209
- try {
210
- authState = yield login(bufferAddress2, address2, isFullAuthWallet, getProviderName(walletType2));
211
- verificationMessage.current = authState.stage === "verify" ? authState.signatureVerificationMessage : void 0;
212
- } catch (err) {
213
- authState = void 0;
214
- bufferAddress2 = void 0;
215
- address2 = void 0;
216
- error = err;
217
- }
220
+ throw new Error("Graz wallet type not provided.");
221
+ }
222
+ try {
223
+ let chainInfo;
224
+ if (shouldUseSuggestChainAndConnect) {
225
+ if (typeof _chainId !== "string") {
226
+ console.error("multiChain is not compatible with shouldUseSuggestChainAndConnect.");
227
+ return;
218
228
  }
219
- } catch (err) {
220
- if (err.message === "No wallet exists") {
221
- error = err.message;
222
- } else {
223
- console.error("Graz connection error:", err);
224
- error = "An unknown error occurred.";
229
+ chainInfo = getChainInfo({ chainId: _chainId });
230
+ if (!chainInfo) {
231
+ console.error("Chain not found.");
232
+ return;
225
233
  }
226
234
  }
235
+ const connectedWallet2 = yield shouldUseSuggestChainAndConnect ? suggestAndConnectAsync({ walletType: walletType2, chainInfo }) : connectAsync({ walletType: walletType2, chainId: _chainId });
236
+ const firstChain = !chainId ? selectedChainId : typeof _chainId === "string" ? _chainId : _chainId[0];
237
+ const addressBech32 = connectedWallet2.accounts[firstChain].bech32Address;
238
+ let rawAddress;
239
+ const accountAddress = connectedWallet2.accounts[firstChain].address;
240
+ if (!accountAddress || accountAddress.length === 0 || accountAddress.byteLength === 0) {
241
+ const pubKey = connectedWallet2.accounts[firstChain].pubKey;
242
+ rawAddress = rawSecp256k1PubkeyToRawAddress(pubKey);
243
+ } else {
244
+ rawAddress = accountAddress;
245
+ }
246
+ const address2 = formatEthHexAddress(rawAddress);
247
+ const { provider, providerId } = getProvider(walletType2);
248
+ return {
249
+ partnerId: para.partnerId,
250
+ type: "COSMOS",
251
+ address: address2,
252
+ addressBech32,
253
+ provider,
254
+ providerId
255
+ };
256
+ } catch (e) {
257
+ let error;
258
+ if (e.message === "No wallet exists") {
259
+ error = e.message;
260
+ } else {
261
+ error = `Graz connection error: ${(_a2 = e == null ? void 0 : e.message) != null ? _a2 : e}`;
262
+ }
263
+ throw error;
227
264
  }
228
- updateExternalWalletState({ isConnecting: false });
229
- return { authState, address: address2, bufferAddress: bufferAddress2, error };
230
265
  });
231
- const getWallet = (walletType2) => incompleteWallets.find((w) => w.grazType === walletType2 || w.grazMobileType === walletType2);
232
- const getProviderName = (walletType2) => {
233
- var _a2;
234
- return (_a2 = getWallet(walletType2)) == null ? void 0 : _a2.name;
266
+ const connect = (walletType2, chainId) => __async(this, null, function* () {
267
+ var _a2, _b2;
268
+ updateExternalWalletState({ isConnecting: true });
269
+ const walletId = (_a2 = getWallet(walletType2)) == null ? void 0 : _a2.id;
270
+ const isFullAuthWallet = walletsWithFullAuth === "ALL" || walletsWithFullAuth.includes(walletId.toUpperCase());
271
+ try {
272
+ const externalWallet = yield connectBase(walletType2, chainId);
273
+ const authState = yield login(__spreadProps(__spreadValues({}, externalWallet), {
274
+ withFullParaAuth: isFullAuthWallet
275
+ }));
276
+ verificationMessage.current = authState.stage === "verify" ? authState.signatureVerificationMessage : void 0;
277
+ return {
278
+ address: externalWallet.address,
279
+ authState
280
+ };
281
+ } catch (e) {
282
+ return {
283
+ error: (_b2 = e == null ? void 0 : e.message) != null ? _b2 : e
284
+ };
285
+ } finally {
286
+ updateExternalWalletState({ isConnecting: false });
287
+ }
288
+ });
289
+ const injectedWallets = WALLET_TYPES.filter((w) => !incompleteWallets.some((iw) => iw.grazType === w) && checkWallet(w)).map((w) => {
290
+ const wallet = grazGetWallet(w);
291
+ if (!wallet.eip6963ProviderInfo) {
292
+ return void 0;
293
+ }
294
+ const eipInfo = wallet.eip6963ProviderInfo;
295
+ return __spreadValues({
296
+ grazType: w,
297
+ // Using name here for the injected connector since that's the only common id across the networks
298
+ id: eipInfo.name,
299
+ internalId: eipInfo.name,
300
+ iconUrl: eipInfo.icon
301
+ }, eipInfo);
302
+ }).filter((w) => !!w);
303
+ const allWallets = [...incompleteWallets, ...injectedWallets];
304
+ const getWallet = (walletType2) => allWallets.find((w) => w.grazType === walletType2 || w.grazMobileType === walletType2);
305
+ const getProvider = (walletType2) => {
306
+ const wallet = getWallet(walletType2);
307
+ return {
308
+ provider: wallet == null ? void 0 : wallet.name,
309
+ providerId: wallet == null ? void 0 : wallet.id
310
+ };
235
311
  };
236
- const wallets = incompleteWallets.map((wallet) => {
312
+ const wallets = allWallets.map((wallet) => {
237
313
  return __spreadProps(__spreadValues({
238
314
  connect: () => connect(wallet.grazType),
239
315
  connectMobile: () => connect(wallet.grazType),
240
- getQrUri: () => "",
241
316
  type: "COSMOS"
242
317
  }, wallet), {
318
+ // Using name here since that's the only common id across the networks
319
+ id: wallet.name,
243
320
  installed: checkWallet(wallet.grazType)
244
321
  });
245
322
  }).filter((w) => !!w);
@@ -262,20 +339,55 @@ function CosmosExternalWalletProvider({
262
339
  return { error };
263
340
  }
264
341
  }), [para, multiChain, chains, selectedChainId]);
342
+ const requestInfo = (providerId) => __async(this, null, function* () {
343
+ var _a2;
344
+ const wallet = wallets.find((w) => w.id === providerId);
345
+ if (!wallet) {
346
+ throw new Error(`Wallet for provider ${providerId} not found`);
347
+ }
348
+ disconnectTypeRef.current = "ACCOUNT_LINKING";
349
+ try {
350
+ const externalWallet = yield connectBase(
351
+ wallet.grazType,
352
+ multiChain ? chains.map((c) => c.chainId) : selectedChainId
353
+ );
354
+ return externalWallet;
355
+ } catch (e) {
356
+ console.error("Error linking account:", e);
357
+ throw new Error((_a2 = e == null ? void 0 : e.message) != null ? _a2 : e);
358
+ }
359
+ });
360
+ const disconnectBase = (_0, ..._1) => __async(this, [_0, ..._1], function* (_, { disconnectType } = {}) {
361
+ var _a2;
362
+ if (disconnectType) {
363
+ disconnectTypeRef.current = disconnectType;
364
+ }
365
+ try {
366
+ yield disconnectAsync();
367
+ } catch (e) {
368
+ console.error("Error linking account:", e);
369
+ throw new Error((_a2 = e == null ? void 0 : e.message) != null ? _a2 : e);
370
+ } finally {
371
+ disconnectTypeRef.current = void 0;
372
+ }
373
+ });
265
374
  return /* @__PURE__ */ jsx(
266
375
  CosmosExternalWalletContext.Provider,
267
376
  {
268
377
  value: useMemo(
269
- () => ({
378
+ () => __spreadValues({
270
379
  wallets,
271
380
  chains: formattedChains,
272
381
  chainId: selectedChainId,
273
382
  disconnect: disconnectAsync,
383
+ disconnectStatus,
274
384
  switchChain,
275
385
  connectParaEmbedded,
276
386
  signMessage,
277
- signVerificationMessage
278
- }),
387
+ signVerificationMessage,
388
+ requestInfo,
389
+ disconnectBase
390
+ }, externalHooks),
279
391
  [
280
392
  wallets,
281
393
  formattedChains,
@@ -284,7 +396,9 @@ function CosmosExternalWalletProvider({
284
396
  switchChain,
285
397
  connectParaEmbedded,
286
398
  signMessage,
287
- signVerificationMessage
399
+ signVerificationMessage,
400
+ requestInfo,
401
+ disconnectBase
288
402
  ]
289
403
  ),
290
404
  children
@@ -2,7 +2,7 @@ import { PropsWithChildren } from 'react';
2
2
  import { WalletList } from '../types/Wallet.js';
3
3
  import { CosmosExternalWalletProviderConfig } from './CosmosExternalWalletContext.js';
4
4
  import { ChainInfo } from '@keplr-wallet/types';
5
- import { ConfigureGrazArgs } from '@getpara/graz';
5
+ import { ConfigureGrazArgs } from 'graz';
6
6
  export type ParaCosmosProviderConfig = {
7
7
  wallets: WalletList;
8
8
  chains: ChainInfo[];
@@ -6,7 +6,8 @@ import {
6
6
  import { jsx } from "react/jsx-runtime";
7
7
  import { useMemo } from "react";
8
8
  import { CosmosExternalWalletProvider } from "./CosmosExternalWalletContext.js";
9
- import { GrazProvider } from "@getpara/graz";
9
+ import { ParaGrazConnector } from "@getpara/graz-connector";
10
+ import { GrazProvider } from "graz";
10
11
  function ParaCosmosProvider({
11
12
  children,
12
13
  config,
@@ -26,10 +27,26 @@ function ParaCosmosProvider({
26
27
  }),
27
28
  [walletsWithType, config, internalConfig]
28
29
  );
30
+ const paraConfig = useMemo(
31
+ () => ({
32
+ paraWeb: para
33
+ }),
34
+ [para]
35
+ );
29
36
  return (
30
37
  // Casting Para as any here to avoid ts errors due to the graz version being behind.
31
38
  // TODO: update graz para sdk to current version
32
- /* @__PURE__ */ jsx(GrazProvider, { grazOptions: __spreadValues({ chains, autoReconnect: true, para }, grazProviderProps), children: /* @__PURE__ */ jsx(CosmosExternalWalletProvider, __spreadProps(__spreadValues({}, cosmosExternalWalletProviderProps), { children })) })
39
+ /* @__PURE__ */ jsx(
40
+ GrazProvider,
41
+ {
42
+ grazOptions: __spreadValues({
43
+ chains,
44
+ autoReconnect: true,
45
+ paraConfig: __spreadProps(__spreadValues({}, paraConfig), { connectorClass: ParaGrazConnector })
46
+ }, grazProviderProps),
47
+ children: /* @__PURE__ */ jsx(CosmosExternalWalletProvider, __spreadProps(__spreadValues({}, cosmosExternalWalletProviderProps), { children }))
48
+ }
49
+ )
33
50
  );
34
51
  }
35
52
  export {
@@ -0,0 +1,7 @@
1
+ import { useAccount } from 'graz';
2
+ export type TExternalHooks = {
3
+ useAccount: typeof useAccount;
4
+ };
5
+ export declare const externalHooks: {
6
+ useAccount: typeof useAccount;
7
+ };
@@ -0,0 +1,7 @@
1
+ "use client";
2
+ import "../chunk-IV3L3JVM.js";
3
+ import { useAccount } from "graz";
4
+ const externalHooks = { useAccount };
5
+ export {
6
+ externalHooks
7
+ };
@@ -0,0 +1,8 @@
1
+ import { UseAccountArgs } from 'graz';
2
+ type ChainId$1 = string | string[];
3
+ export interface MultiChainHookArgs {
4
+ chainId?: ChainId$1;
5
+ multiChain?: boolean;
6
+ }
7
+ export type UseAccountParameters = UseAccountArgs & MultiChainHookArgs;
8
+ export {};
@@ -0,0 +1 @@
1
+ "use client";
@@ -1,4 +1,4 @@
1
- import { WalletType } from '@getpara/graz';
1
+ import { WalletType } from 'graz';
2
2
  import { type WalletMetadata } from '@getpara/react-common';
3
3
  export type WalletList = (() => WalletWithType)[];
4
4
  export type WalletWithType = {
@@ -0,0 +1 @@
1
+ export declare function formatEthHexAddress(address: Uint8Array): string;
@@ -0,0 +1,8 @@
1
+ "use client";
2
+ import "../chunk-IV3L3JVM.js";
3
+ function formatEthHexAddress(address) {
4
+ return `0x${Buffer.from(address).toString("hex")}`.toLowerCase();
5
+ }
6
+ export {
7
+ formatEthHexAddress
8
+ };
@@ -0,0 +1,2 @@
1
+ import { WalletWithType } from '../../../types/Wallet.js';
2
+ export declare const cosmostationWallet: () => WalletWithType;
@@ -0,0 +1,21 @@
1
+ "use client";
2
+ import "../../../chunk-IV3L3JVM.js";
3
+ import { icon } from "./cosmostationIcon.js";
4
+ import { WalletType } from "graz";
5
+ import { isMobile } from "@getpara/web-sdk";
6
+ const cosmostationWallet = () => {
7
+ return {
8
+ id: "cosmostation",
9
+ internalId: "COSMOSTATION",
10
+ name: "Cosmostation",
11
+ iconUrl: icon,
12
+ isExtension: true,
13
+ isMobile: isMobile() && true,
14
+ downloadUrl: "https://www.cosmostation.io/products/cosmostation_extension",
15
+ grazType: WalletType.COSMOSTATION,
16
+ grazMobileType: WalletType.WC_COSMOSTATION_MOBILE
17
+ };
18
+ };
19
+ export {
20
+ cosmostationWallet
21
+ };
@@ -0,0 +1 @@
1
+ export declare const icon = "data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMjQiIGhlaWdodD0iMjQiIHZpZXdCb3g9IjAgMCAyNCAyNCIgZmlsbD0ibm9uZSIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIj4KPGcgY2xpcC1wYXRoPSJ1cmwoI2NsaXAwXzMwNV8yKSI+CjxwYXRoIGQ9Ik0xNy4zNDI5IDIuNzE1ODJIOS42NDc3QzkuNDU1OTggMi43MTYgOS4yNjc2NyAyLjc2NjU0IDkuMTAxNjIgMi44NjIzOEM4LjkzNTU2IDIuOTU4MjIgOC43OTc2IDMuMDk1OTkgOC43MDE1MyAzLjI2MTkxTDQuODUzODkgOS45MjU2NkM0Ljc1NzY5IDEwLjA5MTYgNC43MDcwMyAxMC4yOCA0LjcwNzAzIDEwLjQ3MThDNC43MDcwMyAxMC42NjM1IDQuNzU3NjkgMTAuODUxOSA0Ljg1Mzg5IDExLjAxNzlMOC43MDE1MyAxNy42ODE2TDEwLjU5MzYgMTYuNTg5NUw3LjA2MzE4IDEwLjQ3MThMMTAuMjc5MiA0LjkwMDJIMTYuNzE0MUwyMC4yNDczIDExLjAxNzhMMjIuMTM5NCA5LjkyNTYyTDE4LjI4ODkgMy4yNjE5MUMxOC4xOTMxIDMuMDk1NzkgMTguMDU1MiAyLjk1Nzg1IDE3Ljg4OTIgMi44NjE5OEMxNy43MjMxIDIuNzY2MTEgMTcuNTM0NyAyLjcxNTcgMTcuMzQyOSAyLjcxNTgyWiIgZmlsbD0iIzlDNkNGRiIvPgo8cGF0aCBkPSJNMTUuMjc0OSA2LjMzNjkxT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gMTkuMjY5NCAxMy43Mzg2IDE5LjI2OTQgMTMuNTQ2OEMxOS4yNjk0IDEzLjM1NSAxOS4yMTg3IDEzLjE2NjYgMTkuMTIyNSAxMy4wMDA3TDE1LjI3NDkgNi4zMzY5MVoiIGZpbGw9IiMwNUQyREQiLz4KPC9nPgo8ZGVmcz4KPGNsaXBQYXRoIGlkPSJjbGlwMF8zMDVfMiI+CjxyZWN0IHdpZHRoPSIyNCIgaGVpZ2h0PSIyNCIgZmlsbD0id2hpdGUiLz4KPC9jbGlwUGF0aD4KPC9kZWZzPgo8L3N2Zz4K";
4
+ export {
5
+ icon
6
+ };
@@ -1,4 +1,5 @@
1
1
  import { keplrWallet } from './keplr/keplr.js';
2
2
  import { leapWallet } from './leap/leap.js';
3
- export { keplrWallet, leapWallet };
3
+ import { cosmostationWallet } from './cosmostation/cosmostation.js';
4
+ export { keplrWallet, leapWallet, cosmostationWallet };
4
5
  export declare const allWallets: (() => import("../../types/Wallet.js").WalletWithType)[];
@@ -2,9 +2,11 @@
2
2
  import "../../chunk-IV3L3JVM.js";
3
3
  import { keplrWallet } from "./keplr/keplr.js";
4
4
  import { leapWallet } from "./leap/leap.js";
5
- const allWallets = [keplrWallet, leapWallet];
5
+ import { cosmostationWallet } from "./cosmostation/cosmostation.js";
6
+ const allWallets = [keplrWallet, leapWallet, cosmostationWallet];
6
7
  export {
7
8
  allWallets,
9
+ cosmostationWallet,
8
10
  keplrWallet,
9
11
  leapWallet
10
12
  };
@@ -1,11 +1,12 @@
1
1
  "use client";
2
2
  import "../../../chunk-IV3L3JVM.js";
3
3
  import { icon } from "./keplrIcon.js";
4
- import { WalletType } from "@getpara/graz";
4
+ import { WalletType } from "graz";
5
5
  import { isMobile } from "@getpara/web-sdk";
6
6
  const keplrWallet = () => {
7
7
  return {
8
8
  id: "keplr",
9
+ internalId: "KEPLR",
9
10
  name: "Keplr",
10
11
  iconUrl: icon,
11
12
  isExtension: true,
@@ -1,11 +1,12 @@
1
1
  "use client";
2
2
  import "../../../chunk-IV3L3JVM.js";
3
3
  import { icon } from "./leapIcon.js";
4
- import { WalletType } from "@getpara/graz";
4
+ import { WalletType } from "graz";
5
5
  import { isMobile } from "@getpara/web-sdk";
6
6
  const leapWallet = () => {
7
7
  return {
8
8
  id: "leap",
9
+ internalId: "LEAP",
9
10
  name: "Leap",
10
11
  iconUrl: icon,
11
12
  isExtension: true,
package/package.json CHANGED
@@ -1,43 +1,40 @@
1
1
  {
2
2
  "name": "@getpara/cosmos-wallet-connectors",
3
- "version": "2.0.0-alpha.7",
4
- "type": "module",
5
- "main": "dist/index.js",
6
- "types": "dist/index.d.ts",
7
- "exports": {
8
- ".": "./dist/index.js",
9
- "./connectors": "./dist/wallets/connectors/index.js"
10
- },
11
- "scripts": {
12
- "build": "rm -rf dist && yarn typegen && node ./scripts/build.mjs",
13
- "typegen": "tsc --emitDeclarationOnly",
14
- "test": "vitest run --coverage"
15
- },
3
+ "version": "2.0.0-alpha.71",
16
4
  "dependencies": {
17
- "@cosmjs/cosmwasm-stargate": "<=0.31.3",
18
- "@cosmjs/launchpad": "*",
19
- "@cosmjs/proto-signing": "<=0.31.3",
20
- "@cosmjs/stargate": "<=0.33.1",
21
- "@cosmjs/tendermint-rpc": "<=0.31.3",
22
- "@getpara/graz": "^1.0.0-dev.2",
23
- "@getpara/web-sdk": "2.0.0-alpha.7",
5
+ "@getpara/graz-connector": "2.0.0-alpha.71",
6
+ "@getpara/react-common": "2.0.0-alpha.71",
7
+ "@getpara/web-sdk": "2.0.0-alpha.71",
24
8
  "@leapwallet/cosmos-social-login-capsule-provider": "^0.0.41",
25
9
  "zustand": "^4.5.2",
26
10
  "zustand-sync-tabs": "^0.2.2"
27
11
  },
28
12
  "devDependencies": {
29
- "@getpara/react-common": "2.0.0-alpha.7",
30
13
  "@types/react": "^18.0.31",
31
14
  "@types/react-dom": "^18.2.7",
32
- "typescript": "^5.4.3"
15
+ "graz": "^0.4.1",
16
+ "typescript": "^5.8.3"
33
17
  },
34
- "peerDependencies": {
35
- "react": ">=18",
36
- "react-dom": ">=18"
18
+ "exports": {
19
+ ".": "./dist/index.js",
20
+ "./connectors": "./dist/wallets/connectors/index.js"
37
21
  },
38
22
  "files": [
39
23
  "dist",
40
24
  "package.json"
41
25
  ],
42
- "gitHead": "0a6b297b70c7f9b7b93381944e3f5314252ad6a5"
26
+ "gitHead": "30e5bad6a141f1b56959432f11aaf1536b84dece",
27
+ "main": "dist/index.js",
28
+ "peerDependencies": {
29
+ "graz": ">=0.4.1",
30
+ "react": ">=18",
31
+ "react-dom": ">=18"
32
+ },
33
+ "scripts": {
34
+ "build": "rm -rf dist && yarn typegen && node ./scripts/build.mjs",
35
+ "test": "vitest run --coverage",
36
+ "typegen": "tsc --emitDeclarationOnly"
37
+ },
38
+ "type": "module",
39
+ "types": "dist/index.d.ts"
43
40
  }