@getpara/cosmos-wallet-connectors 2.0.0-alpha.6 → 2.0.0-alpha.61
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.d.ts +2 -1
- package/dist/providers/CosmosExternalWalletContext.d.ts +10 -38
- package/dist/providers/CosmosExternalWalletContext.js +199 -96
- package/dist/providers/externalHooks.d.ts +8 -0
- package/dist/providers/externalHooks.js +7 -0
- package/dist/types/ExternalHooks.d.ts +8 -0
- package/dist/types/ExternalHooks.js +1 -0
- package/dist/utils/formatEthHexAddress.d.ts +1 -0
- package/dist/utils/formatEthHexAddress.js +8 -0
- package/dist/wallets/connectors/cosmostation/cosmostation.d.ts +2 -0
- package/dist/wallets/connectors/cosmostation/cosmostation.js +21 -0
- package/dist/wallets/connectors/cosmostation/cosmostationIcon.d.ts +1 -0
- package/dist/wallets/connectors/cosmostation/cosmostationIcon.js +6 -0
- package/dist/wallets/connectors/index.d.ts +2 -1
- package/dist/wallets/connectors/index.js +3 -1
- package/dist/wallets/connectors/keplr/keplr.js +1 -0
- package/dist/wallets/connectors/leap/leap.js +1 -0
- package/package.json +23 -26
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export { CosmosExternalWalletContext } from './providers/CosmosExternalWalletContext.js';
|
|
2
|
-
export type
|
|
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
|
|
5
|
-
import
|
|
6
|
-
export type
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
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
|
|
31
|
-
|
|
32
|
-
|
|
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,19 +15,16 @@ import {
|
|
|
15
15
|
useDisconnect,
|
|
16
16
|
useSuggestChainAndConnect,
|
|
17
17
|
getChainInfo,
|
|
18
|
-
getWallet as grazGetWallet
|
|
18
|
+
getWallet as grazGetWallet,
|
|
19
|
+
WALLET_TYPES
|
|
19
20
|
} from "@getpara/graz";
|
|
20
21
|
import { useExternalWalletStore } from "../stores/useStore.js";
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
connectParaEmbedded: () => Promise.resolve({}),
|
|
28
|
-
signMessage: () => Promise.resolve({}),
|
|
29
|
-
signVerificationMessage: () => Promise.resolve({})
|
|
30
|
-
};
|
|
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";
|
|
31
28
|
const CosmosExternalWalletContext = createContext(defaultCosmosExternalWallet);
|
|
32
29
|
function CosmosExternalWalletProvider({
|
|
33
30
|
children,
|
|
@@ -40,9 +37,11 @@ function CosmosExternalWalletProvider({
|
|
|
40
37
|
onSwitchChain,
|
|
41
38
|
para,
|
|
42
39
|
walletsWithFullAuth,
|
|
43
|
-
connectedWallet
|
|
40
|
+
connectedWallet: connectedWalletProp,
|
|
41
|
+
includeWalletVerification,
|
|
42
|
+
connectionOnly
|
|
44
43
|
}) {
|
|
45
|
-
var _a, _b;
|
|
44
|
+
var _a, _b, _c, _d;
|
|
46
45
|
const { suggestAndConnectAsync } = useSuggestChainAndConnect();
|
|
47
46
|
const {
|
|
48
47
|
data: account,
|
|
@@ -50,7 +49,7 @@ function CosmosExternalWalletProvider({
|
|
|
50
49
|
isReconnecting,
|
|
51
50
|
isConnected
|
|
52
51
|
} = useAccount({
|
|
53
|
-
chainId: multiChain ? chains.map((c) => c.chainId) : selectedChainId,
|
|
52
|
+
chainId: multiChain ? chains.map((c) => c.chainId) : selectedChainId != null ? selectedChainId : "",
|
|
54
53
|
multiChain
|
|
55
54
|
});
|
|
56
55
|
const { connectAsync } = useConnect();
|
|
@@ -58,8 +57,11 @@ function CosmosExternalWalletProvider({
|
|
|
58
57
|
const { walletType } = useActiveWalletType();
|
|
59
58
|
const isLocalConnecting = useExternalWalletStore((state) => state.isConnecting);
|
|
60
59
|
const updateExternalWalletState = useExternalWalletStore((state) => state.updateState);
|
|
61
|
-
const
|
|
62
|
-
const
|
|
60
|
+
const isConnectError = useRef(false);
|
|
61
|
+
const connectedWallet = connectedWalletProp ? para.findWallet(connectedWalletProp.id, connectedWalletProp.type) : null;
|
|
62
|
+
const ethAddress = multiChain ? (_b = (_a = account == null ? void 0 : account[selectedChainId]) == null ? void 0 : _a.ethereumHexAddress) == null ? void 0 : _b.toLowerCase() : (_c = account == null ? void 0 : account.ethereumHexAddress) == null ? void 0 : _c.toLowerCase();
|
|
63
|
+
const address = multiChain ? (_d = account == null ? void 0 : account[selectedChainId]) == null ? void 0 : _d.bech32Address : account == null ? void 0 : account.bech32Address;
|
|
64
|
+
const isLinkingAccount = useRef(false);
|
|
63
65
|
const verificationMessage = useRef();
|
|
64
66
|
const reset = () => __async(this, null, function* () {
|
|
65
67
|
yield disconnectAsync();
|
|
@@ -80,7 +82,7 @@ function CosmosExternalWalletProvider({
|
|
|
80
82
|
}
|
|
81
83
|
const connectedWallet2 = yield shouldUseSuggestChainAndConnect ? suggestAndConnectAsync({ walletType, chainInfo }) : connectAsync({ walletType, chainId });
|
|
82
84
|
changeResp.address = connectedWallet2.accounts[chainId].bech32Address;
|
|
83
|
-
changeResp.
|
|
85
|
+
changeResp.ethAddress = formatEthHexAddress(connectedWallet2.accounts[chainId].address);
|
|
84
86
|
} catch (err) {
|
|
85
87
|
if (err.message === "No wallet exists") {
|
|
86
88
|
changeResp.error = err.message;
|
|
@@ -92,26 +94,41 @@ function CosmosExternalWalletProvider({
|
|
|
92
94
|
onSwitchWallet(changeResp);
|
|
93
95
|
if (!changeResp.error) {
|
|
94
96
|
onSwitchChain(chainId);
|
|
95
|
-
const storedExternalWallet = para.externalWallets[(_a2 = changeResp.
|
|
97
|
+
const storedExternalWallet = para.externalWallets[(_a2 = changeResp.ethAddress) != null ? _a2 : ""];
|
|
98
|
+
const { provider, providerId } = getProvider(walletType);
|
|
96
99
|
para.setExternalWallet({
|
|
97
|
-
|
|
100
|
+
partnerId: para.partnerId,
|
|
101
|
+
address: changeResp.ethAddress,
|
|
98
102
|
type: "COSMOS",
|
|
99
|
-
provider
|
|
103
|
+
provider,
|
|
104
|
+
providerId,
|
|
100
105
|
addressBech32: changeResp.address,
|
|
101
|
-
withFullParaAuth: storedExternalWallet.isExternalWithParaAuth
|
|
106
|
+
withFullParaAuth: storedExternalWallet.isExternalWithParaAuth,
|
|
107
|
+
withVerification: includeWalletVerification,
|
|
108
|
+
isConnectionOnly: connectionOnly
|
|
102
109
|
});
|
|
103
110
|
}
|
|
104
111
|
return { error };
|
|
105
112
|
});
|
|
106
|
-
const login = (
|
|
113
|
+
const login = (_0) => __async(this, [_0], function* ({
|
|
114
|
+
address: address2,
|
|
115
|
+
addressBech32,
|
|
116
|
+
withFullParaAuth,
|
|
117
|
+
providerId,
|
|
118
|
+
provider
|
|
119
|
+
}) {
|
|
107
120
|
try {
|
|
108
121
|
return yield para.loginExternalWallet({
|
|
109
122
|
externalWallet: {
|
|
110
|
-
|
|
123
|
+
partnerId: para.partnerId,
|
|
124
|
+
address: address2,
|
|
111
125
|
type: "COSMOS",
|
|
112
|
-
provider
|
|
113
|
-
|
|
114
|
-
|
|
126
|
+
provider,
|
|
127
|
+
providerId,
|
|
128
|
+
addressBech32,
|
|
129
|
+
withFullParaAuth,
|
|
130
|
+
withVerification: includeWalletVerification,
|
|
131
|
+
isConnectionOnly: connectionOnly
|
|
115
132
|
}
|
|
116
133
|
});
|
|
117
134
|
} catch (err) {
|
|
@@ -120,41 +137,57 @@ function CosmosExternalWalletProvider({
|
|
|
120
137
|
}
|
|
121
138
|
});
|
|
122
139
|
useEffect(() => {
|
|
123
|
-
const storedExternalWallet = para.externalWallets[
|
|
124
|
-
if (isConnected && !isConnecting && !isReconnecting && !isLocalConnecting && !!
|
|
140
|
+
const storedExternalWallet = para.externalWallets[ethAddress != null ? ethAddress : ""];
|
|
141
|
+
if (isConnected && !isConnecting && !isReconnecting && !isLocalConnecting && !!ethAddress && !storedExternalWallet && walletType !== GrazWalletType.PARA && !isLinkingAccount.current) {
|
|
125
142
|
reset();
|
|
126
143
|
}
|
|
127
144
|
}, [isConnecting, isLocalConnecting, isReconnecting, isConnected]);
|
|
128
145
|
useEffect(() => {
|
|
129
146
|
const connect2 = () => __async(this, null, function* () {
|
|
130
147
|
var _a2;
|
|
131
|
-
if (!isLocalConnecting && !isConnecting && !isReconnecting && connectedWallet && connectedWallet.type === "COSMOS" && (connectedWallet.isExternal ? walletType !== ((_a2 = connectedWallet.name) == null ? void 0 : _a2.toLowerCase()) : walletType !== "para")) {
|
|
148
|
+
if (!isLocalConnecting && !isConnecting && !isReconnecting && connectedWallet && connectedWallet.type === "COSMOS" && (connectedWallet.isExternal ? walletType !== ((_a2 = connectedWallet.name) == null ? void 0 : _a2.toLowerCase()) : walletType !== "para") && !isLinkingAccount.current && !isConnectError.current) {
|
|
132
149
|
const isLoggedIn = yield para.isFullyLoggedIn();
|
|
133
150
|
if (!isLoggedIn) {
|
|
134
151
|
return;
|
|
135
152
|
}
|
|
136
153
|
const chainId = multiChain ? chains.map((c) => c.chainId) : selectedChainId;
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
154
|
+
const targetWalletType = connectedWallet.isExternal ? connectedWallet.name.toLowerCase() : GrazWalletType.PARA;
|
|
155
|
+
try {
|
|
156
|
+
yield connectAsync({
|
|
157
|
+
walletType: targetWalletType,
|
|
158
|
+
chainId
|
|
159
|
+
});
|
|
160
|
+
} catch (e) {
|
|
161
|
+
isConnectError.current = true;
|
|
162
|
+
}
|
|
141
163
|
}
|
|
142
164
|
});
|
|
143
165
|
connect2();
|
|
144
166
|
}, [isLocalConnecting, isConnecting, isReconnecting, walletType, connectedWallet]);
|
|
145
|
-
const signMessage = (
|
|
146
|
-
|
|
167
|
+
const signMessage = (_0) => __async(this, [_0], function* ({ message, externalWallet }) {
|
|
168
|
+
let wallet, signAddress, signEthAddress;
|
|
169
|
+
if (externalWallet) {
|
|
170
|
+
const commonWallet = wallets.find((w) => w.id === externalWallet.providerId);
|
|
171
|
+
wallet = grazGetWallet(commonWallet == null ? void 0 : commonWallet.grazType);
|
|
172
|
+
signAddress = externalWallet.addressBech32;
|
|
173
|
+
signEthAddress = externalWallet.address;
|
|
174
|
+
} else {
|
|
175
|
+
wallet = grazGetWallet(walletType);
|
|
176
|
+
signAddress = address;
|
|
177
|
+
signEthAddress = ethAddress;
|
|
178
|
+
}
|
|
147
179
|
if (!wallet) {
|
|
148
180
|
return { error: "Connected wallet not found" };
|
|
149
181
|
}
|
|
150
182
|
try {
|
|
151
183
|
const publicKey = (yield wallet.getKey(selectedChainId)).pubKey;
|
|
152
|
-
const signature = yield wallet.signArbitrary(selectedChainId,
|
|
184
|
+
const signature = yield wallet.signArbitrary(selectedChainId, signAddress, message);
|
|
153
185
|
return {
|
|
154
|
-
address:
|
|
186
|
+
address: signEthAddress,
|
|
187
|
+
addressBech32: signAddress,
|
|
155
188
|
signature: signature.signature,
|
|
156
189
|
cosmosPublicKeyHex: Buffer.from(publicKey).toString("hex"),
|
|
157
|
-
cosmosSigner:
|
|
190
|
+
cosmosSigner: signAddress
|
|
158
191
|
};
|
|
159
192
|
} catch (e) {
|
|
160
193
|
if (e.message.includes("Request rejected")) {
|
|
@@ -164,82 +197,120 @@ function CosmosExternalWalletProvider({
|
|
|
164
197
|
}
|
|
165
198
|
});
|
|
166
199
|
const signVerificationMessage = () => __async(this, null, function* () {
|
|
167
|
-
const signature = yield signMessage(verificationMessage.current);
|
|
200
|
+
const signature = yield signMessage({ message: verificationMessage.current });
|
|
168
201
|
return signature;
|
|
169
202
|
});
|
|
170
|
-
const
|
|
203
|
+
const connectBase = (walletType2, chainId) => __async(this, null, function* () {
|
|
171
204
|
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
205
|
if (!chainId) {
|
|
176
206
|
yield disconnectAsync();
|
|
177
207
|
}
|
|
178
208
|
const _chainId = chainId != null ? chainId : multiChain ? chains.map((c) => c.chainId) : selectedChainId;
|
|
179
209
|
if (!_chainId) {
|
|
180
|
-
|
|
181
|
-
return;
|
|
210
|
+
throw new Error("Chain id not provided.");
|
|
182
211
|
}
|
|
183
|
-
let address2;
|
|
184
|
-
let bufferAddress2;
|
|
185
|
-
let error;
|
|
186
|
-
let authState;
|
|
187
212
|
if (!walletType2) {
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
if (
|
|
194
|
-
|
|
195
|
-
|
|
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
|
-
}
|
|
213
|
+
throw new Error("Graz wallet type not provided.");
|
|
214
|
+
}
|
|
215
|
+
try {
|
|
216
|
+
let chainInfo;
|
|
217
|
+
if (shouldUseSuggestChainAndConnect) {
|
|
218
|
+
if (typeof _chainId !== "string") {
|
|
219
|
+
console.error("multiChain is not compatible with shouldUseSuggestChainAndConnect.");
|
|
220
|
+
return;
|
|
218
221
|
}
|
|
219
|
-
|
|
220
|
-
if (
|
|
221
|
-
error
|
|
222
|
-
|
|
223
|
-
console.error("Graz connection error:", err);
|
|
224
|
-
error = "An unknown error occurred.";
|
|
222
|
+
chainInfo = getChainInfo({ chainId: _chainId });
|
|
223
|
+
if (!chainInfo) {
|
|
224
|
+
console.error("Chain not found.");
|
|
225
|
+
return;
|
|
225
226
|
}
|
|
226
227
|
}
|
|
228
|
+
const connectedWallet2 = yield shouldUseSuggestChainAndConnect ? suggestAndConnectAsync({ walletType: walletType2, chainInfo }) : connectAsync({ walletType: walletType2, chainId: _chainId });
|
|
229
|
+
const firstChain = !chainId ? selectedChainId : typeof _chainId === "string" ? _chainId : _chainId[0];
|
|
230
|
+
const addressBech32 = connectedWallet2.accounts[firstChain].bech32Address;
|
|
231
|
+
let rawAddress;
|
|
232
|
+
const accountAddress = connectedWallet2.accounts[firstChain].address;
|
|
233
|
+
if (!accountAddress || accountAddress.length === 0 || accountAddress.byteLength === 0) {
|
|
234
|
+
const pubKey = connectedWallet2.accounts[firstChain].pubKey;
|
|
235
|
+
rawAddress = rawSecp256k1PubkeyToRawAddress(pubKey);
|
|
236
|
+
} else {
|
|
237
|
+
rawAddress = accountAddress;
|
|
238
|
+
}
|
|
239
|
+
const address2 = formatEthHexAddress(rawAddress);
|
|
240
|
+
const { provider, providerId } = getProvider(walletType2);
|
|
241
|
+
return {
|
|
242
|
+
partnerId: para.partnerId,
|
|
243
|
+
type: "COSMOS",
|
|
244
|
+
address: address2,
|
|
245
|
+
addressBech32,
|
|
246
|
+
provider,
|
|
247
|
+
providerId
|
|
248
|
+
};
|
|
249
|
+
} catch (e) {
|
|
250
|
+
let error;
|
|
251
|
+
if (e.message === "No wallet exists") {
|
|
252
|
+
error = e.message;
|
|
253
|
+
} else {
|
|
254
|
+
error = `Graz connection error: ${(_a2 = e == null ? void 0 : e.message) != null ? _a2 : e}`;
|
|
255
|
+
}
|
|
256
|
+
throw error;
|
|
227
257
|
}
|
|
228
|
-
updateExternalWalletState({ isConnecting: false });
|
|
229
|
-
return { authState, address: address2, bufferAddress: bufferAddress2, error };
|
|
230
258
|
});
|
|
231
|
-
const
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
259
|
+
const connect = (walletType2, chainId) => __async(this, null, function* () {
|
|
260
|
+
var _a2, _b2;
|
|
261
|
+
updateExternalWalletState({ isConnecting: true });
|
|
262
|
+
const walletId = (_a2 = getWallet(walletType2)) == null ? void 0 : _a2.id;
|
|
263
|
+
const isFullAuthWallet = walletsWithFullAuth === "ALL" || walletsWithFullAuth.includes(walletId.toUpperCase());
|
|
264
|
+
try {
|
|
265
|
+
const externalWallet = yield connectBase(walletType2, chainId);
|
|
266
|
+
const authState = yield login(__spreadProps(__spreadValues({}, externalWallet), {
|
|
267
|
+
withFullParaAuth: isFullAuthWallet
|
|
268
|
+
}));
|
|
269
|
+
verificationMessage.current = authState.stage === "verify" ? authState.signatureVerificationMessage : void 0;
|
|
270
|
+
return {
|
|
271
|
+
address: externalWallet.address,
|
|
272
|
+
authState
|
|
273
|
+
};
|
|
274
|
+
} catch (e) {
|
|
275
|
+
return {
|
|
276
|
+
error: (_b2 = e == null ? void 0 : e.message) != null ? _b2 : e
|
|
277
|
+
};
|
|
278
|
+
} finally {
|
|
279
|
+
updateExternalWalletState({ isConnecting: false });
|
|
280
|
+
}
|
|
281
|
+
});
|
|
282
|
+
const injectedWallets = WALLET_TYPES.filter((w) => !incompleteWallets.some((iw) => iw.grazType === w) && checkWallet(w)).map((w) => {
|
|
283
|
+
const wallet = grazGetWallet(w);
|
|
284
|
+
if (!wallet.eip6963ProviderInfo) {
|
|
285
|
+
return void 0;
|
|
286
|
+
}
|
|
287
|
+
const eipInfo = wallet.eip6963ProviderInfo;
|
|
288
|
+
return __spreadValues({
|
|
289
|
+
grazType: w,
|
|
290
|
+
// Using name here for the injected connector since that's the only common id across the networks
|
|
291
|
+
id: eipInfo.name,
|
|
292
|
+
internalId: eipInfo.name,
|
|
293
|
+
iconUrl: eipInfo.icon
|
|
294
|
+
}, eipInfo);
|
|
295
|
+
}).filter((w) => !!w);
|
|
296
|
+
const allWallets = [...incompleteWallets, ...injectedWallets];
|
|
297
|
+
const getWallet = (walletType2) => allWallets.find((w) => w.grazType === walletType2 || w.grazMobileType === walletType2);
|
|
298
|
+
const getProvider = (walletType2) => {
|
|
299
|
+
const wallet = getWallet(walletType2);
|
|
300
|
+
return {
|
|
301
|
+
provider: wallet == null ? void 0 : wallet.name,
|
|
302
|
+
providerId: wallet == null ? void 0 : wallet.id
|
|
303
|
+
};
|
|
235
304
|
};
|
|
236
|
-
const wallets =
|
|
305
|
+
const wallets = allWallets.map((wallet) => {
|
|
237
306
|
return __spreadProps(__spreadValues({
|
|
238
307
|
connect: () => connect(wallet.grazType),
|
|
239
308
|
connectMobile: () => connect(wallet.grazType),
|
|
240
309
|
getQrUri: () => "",
|
|
241
310
|
type: "COSMOS"
|
|
242
311
|
}, wallet), {
|
|
312
|
+
// Using name here since that's the only common id across the networks
|
|
313
|
+
id: wallet.name,
|
|
243
314
|
installed: checkWallet(wallet.grazType)
|
|
244
315
|
});
|
|
245
316
|
}).filter((w) => !!w);
|
|
@@ -262,11 +333,39 @@ function CosmosExternalWalletProvider({
|
|
|
262
333
|
return { error };
|
|
263
334
|
}
|
|
264
335
|
}), [para, multiChain, chains, selectedChainId]);
|
|
336
|
+
const requestInfo = (providerId) => __async(this, null, function* () {
|
|
337
|
+
var _a2;
|
|
338
|
+
const wallet = wallets.find((w) => w.id === providerId);
|
|
339
|
+
if (!wallet) {
|
|
340
|
+
throw new Error(`Wallet for provider ${providerId} not found`);
|
|
341
|
+
}
|
|
342
|
+
isLinkingAccount.current = true;
|
|
343
|
+
try {
|
|
344
|
+
const externalWallet = yield connectBase(
|
|
345
|
+
wallet.grazType,
|
|
346
|
+
multiChain ? chains.map((c) => c.chainId) : selectedChainId
|
|
347
|
+
);
|
|
348
|
+
return externalWallet;
|
|
349
|
+
} catch (e) {
|
|
350
|
+
console.error("Error linking account:", e);
|
|
351
|
+
throw new Error((_a2 = e == null ? void 0 : e.message) != null ? _a2 : e);
|
|
352
|
+
}
|
|
353
|
+
});
|
|
354
|
+
const disconnectBase = () => __async(this, null, function* () {
|
|
355
|
+
var _a2;
|
|
356
|
+
isLinkingAccount.current = true;
|
|
357
|
+
try {
|
|
358
|
+
yield disconnectAsync();
|
|
359
|
+
} catch (e) {
|
|
360
|
+
console.error("Error linking account:", e);
|
|
361
|
+
throw new Error((_a2 = e == null ? void 0 : e.message) != null ? _a2 : e);
|
|
362
|
+
}
|
|
363
|
+
});
|
|
265
364
|
return /* @__PURE__ */ jsx(
|
|
266
365
|
CosmosExternalWalletContext.Provider,
|
|
267
366
|
{
|
|
268
367
|
value: useMemo(
|
|
269
|
-
() => ({
|
|
368
|
+
() => __spreadValues({
|
|
270
369
|
wallets,
|
|
271
370
|
chains: formattedChains,
|
|
272
371
|
chainId: selectedChainId,
|
|
@@ -274,8 +373,10 @@ function CosmosExternalWalletProvider({
|
|
|
274
373
|
switchChain,
|
|
275
374
|
connectParaEmbedded,
|
|
276
375
|
signMessage,
|
|
277
|
-
signVerificationMessage
|
|
278
|
-
|
|
376
|
+
signVerificationMessage,
|
|
377
|
+
requestInfo,
|
|
378
|
+
disconnectBase
|
|
379
|
+
}, externalHooks),
|
|
279
380
|
[
|
|
280
381
|
wallets,
|
|
281
382
|
formattedChains,
|
|
@@ -284,7 +385,9 @@ function CosmosExternalWalletProvider({
|
|
|
284
385
|
switchChain,
|
|
285
386
|
connectParaEmbedded,
|
|
286
387
|
signMessage,
|
|
287
|
-
signVerificationMessage
|
|
388
|
+
signVerificationMessage,
|
|
389
|
+
requestInfo,
|
|
390
|
+
disconnectBase
|
|
288
391
|
]
|
|
289
392
|
),
|
|
290
393
|
children
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { useAccount } from '@getpara/graz';
|
|
2
|
+
import { MultiChainHookArgs } from '../types/ExternalHooks.js';
|
|
3
|
+
export type TExternalHooks = {
|
|
4
|
+
useAccount: typeof useAccount<MultiChainHookArgs>;
|
|
5
|
+
};
|
|
6
|
+
export declare const externalHooks: {
|
|
7
|
+
useAccount: typeof useAccount;
|
|
8
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use client";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function formatEthHexAddress(address: Uint8Array): string;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import "../../../chunk-IV3L3JVM.js";
|
|
3
|
+
import { icon } from "./cosmostationIcon.js";
|
|
4
|
+
import { WalletType } from "@getpara/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+CjxwYXRoIGQ9Ik0xNy4zNDI5IDIuNzE1ODJIOS42NDc3QzkuNDU1OTggMi43MTYgOS4yNjc2NyAyLjc2NjU0IDkuMTAxNjIgMi44NjIzOEM4LjkzNTU2I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i44NjE5OEMxNy43MjMxIDIuNzY2MTEgMTcuNTM0NyAyLjcxNTcgMTcuMzQyOSAyLjcxNTgyWiIgZmlsbD0iIzlDNkNGRiIvPgo8cGF0aCBkPSJNMTUuMjc0OSA2LjMzNjkxTDEzLjM4MjggNy40MjkxTDE2LjkxNiAxMy41NDY4TDEzLjcgMTkuMTE4M0g3LjI2NTE2TDMuNzMxOTUgMTMuMDAwNkwxLjgzOTg0IDE0LjA5MjlMNS42ODc0OCAyMC43NTY2QzUuNzgzMzYgMjAuOTIyNyA1LjkyMTI3IDIxLjA2MDYgNi4wODczNCAyMS4xNTY0QzYuMjUzNDEgMjEuMjUyMyA2LjQ0MTc5IDIxLjMwMjggNi42MzM1NCAyMS4zMDI3SDE0LjMyODhDMTQuNTIwNSAyMS4zMDI1IDE0LjcwODggMjEuMjUyIDE0Ljg3NDkgMjEuMTU2MUMxNS4wNDA5IDIxLjA2MDMgMTUuMTc4OCAyMC45MjI1IDE1LjI3NDkgMjAuNzU2NkwxOS4xMjI1IDE0LjA5MjlDMTkuMjE4NyAxMy45MjcgMTkuMjY5NCAxMy43Mzg2IDE5LjI2OTQgMTMuNTQ2OEMxOS4yNjk0IDEzLjM1NSAxOS4yMTg3IDEzLjE2NjYgMTkuMTIyNSAxMy4wMDA3TDE1LjI3NDkgNi4zMzY5MVoiIGZpbGw9IiMwNUQyREQiLz4KPC9nPgo8ZGVmcz4KPGNsaXBQYXRoIGlkPSJjbGlwMF8zMDVfMiI+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
|
-
|
|
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
|
-
|
|
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
|
};
|
package/package.json
CHANGED
|
@@ -1,43 +1,40 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@getpara/cosmos-wallet-connectors",
|
|
3
|
-
"version": "2.0.0-alpha.
|
|
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.61",
|
|
16
4
|
"dependencies": {
|
|
17
|
-
"@
|
|
18
|
-
"@
|
|
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.6",
|
|
5
|
+
"@getpara/react-common": "2.0.0-alpha.61",
|
|
6
|
+
"@getpara/web-sdk": "2.0.0-alpha.61",
|
|
24
7
|
"@leapwallet/cosmos-social-login-capsule-provider": "^0.0.41",
|
|
8
|
+
"starknet": "^6.11.0",
|
|
25
9
|
"zustand": "^4.5.2",
|
|
26
10
|
"zustand-sync-tabs": "^0.2.2"
|
|
27
11
|
},
|
|
28
12
|
"devDependencies": {
|
|
29
|
-
"@getpara/
|
|
13
|
+
"@getpara/graz": "2.0.0-alpha.5",
|
|
30
14
|
"@types/react": "^18.0.31",
|
|
31
15
|
"@types/react-dom": "^18.2.7",
|
|
32
|
-
"typescript": "^5.
|
|
16
|
+
"typescript": "^5.8.3"
|
|
33
17
|
},
|
|
34
|
-
"
|
|
35
|
-
"
|
|
36
|
-
"
|
|
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": "
|
|
26
|
+
"gitHead": "3a84954ff65c95d95fa96794bf0b0d4dc646c624",
|
|
27
|
+
"main": "dist/index.js",
|
|
28
|
+
"peerDependencies": {
|
|
29
|
+
"@getpara/graz": ">=2.0.0-alpha.5",
|
|
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
|
}
|