@graphprotocol/graph-auth-kit 7.8.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.
Files changed (85) hide show
  1. package/README.md +303 -0
  2. package/dist/Components/ConnectModal.d.ts +2 -0
  3. package/dist/Components/ConnectModal.d.ts.map +1 -0
  4. package/dist/Components/Connected.d.ts +33 -0
  5. package/dist/Components/Connected.d.ts.map +1 -0
  6. package/dist/Components/ConnectorOption.d.ts +7 -0
  7. package/dist/Components/ConnectorOption.d.ts.map +1 -0
  8. package/dist/Components/Disconnected.d.ts +28 -0
  9. package/dist/Components/Disconnected.d.ts.map +1 -0
  10. package/dist/Components/MultisigSignerOptions.d.ts +2 -0
  11. package/dist/Components/MultisigSignerOptions.d.ts.map +1 -0
  12. package/dist/Components/PrimaryConnectOptions.d.ts +2 -0
  13. package/dist/Components/PrimaryConnectOptions.d.ts.map +1 -0
  14. package/dist/Components/SafeInputForm.d.ts +2 -0
  15. package/dist/Components/SafeInputForm.d.ts.map +1 -0
  16. package/dist/Components/SafeSelection.d.ts +2 -0
  17. package/dist/Components/SafeSelection.d.ts.map +1 -0
  18. package/dist/Components/SwitchChain.d.ts +24 -0
  19. package/dist/Components/SwitchChain.d.ts.map +1 -0
  20. package/dist/Components/index.d.ts +4 -0
  21. package/dist/Components/index.d.ts.map +1 -0
  22. package/dist/GraphAuthKit.context.d.ts +130 -0
  23. package/dist/GraphAuthKit.context.d.ts.map +1 -0
  24. package/dist/GraphAuthKitInner.context-B3nCqd7x.js +629 -0
  25. package/dist/client.d.ts +12519 -0
  26. package/dist/client.d.ts.map +1 -0
  27. package/dist/constants.d.ts +366 -0
  28. package/dist/constants.d.ts.map +1 -0
  29. package/dist/ens/hooks/index.d.ts +5 -0
  30. package/dist/ens/hooks/index.d.ts.map +1 -0
  31. package/dist/ens/hooks/useGraphAuthKitAvatar.d.ts +55 -0
  32. package/dist/ens/hooks/useGraphAuthKitAvatar.d.ts.map +1 -0
  33. package/dist/ens/hooks/useGraphAuthKitAvatars.d.ts +29 -0
  34. package/dist/ens/hooks/useGraphAuthKitAvatars.d.ts.map +1 -0
  35. package/dist/ens/hooks/useGraphAuthKitEnsName.d.ts +52 -0
  36. package/dist/ens/hooks/useGraphAuthKitEnsName.d.ts.map +1 -0
  37. package/dist/ens/hooks/useGraphAuthKitEnsNames.d.ts +28 -0
  38. package/dist/ens/hooks/useGraphAuthKitEnsNames.d.ts.map +1 -0
  39. package/dist/ens/index.d.ts +2 -0
  40. package/dist/ens/index.d.ts.map +1 -0
  41. package/dist/ens/index.js +7 -0
  42. package/dist/errors.d.ts +21 -0
  43. package/dist/errors.d.ts.map +1 -0
  44. package/dist/hooks-D5Hw1GuR.js +511 -0
  45. package/dist/hooks.d.ts +125 -0
  46. package/dist/hooks.d.ts.map +1 -0
  47. package/dist/index.d.ts +11 -0
  48. package/dist/index.d.ts.map +1 -0
  49. package/dist/index.js +141 -0
  50. package/dist/inner/GraphAuthKitInner.context.d.ts +121 -0
  51. package/dist/inner/GraphAuthKitInner.context.d.ts.map +1 -0
  52. package/dist/inner/hooks.d.ts +13 -0
  53. package/dist/inner/hooks.d.ts.map +1 -0
  54. package/dist/inner/index.d.ts +3 -0
  55. package/dist/inner/index.d.ts.map +1 -0
  56. package/dist/safe/SafeEthersSigner.d.ts +39 -0
  57. package/dist/safe/SafeEthersSigner.d.ts.map +1 -0
  58. package/dist/safe/SafeMinimal.abi.d.ts +80 -0
  59. package/dist/safe/SafeMinimal.abi.d.ts.map +1 -0
  60. package/dist/safe/constants.d.ts +27 -0
  61. package/dist/safe/constants.d.ts.map +1 -0
  62. package/dist/safe/index.d.ts +5 -0
  63. package/dist/safe/index.d.ts.map +1 -0
  64. package/dist/safe/index.js +19 -0
  65. package/dist/safe/safeViemActions.d.ts +4 -0
  66. package/dist/safe/safeViemActions.d.ts.map +1 -0
  67. package/dist/safe/useWaitForSafeTransaction.d.ts +10 -0
  68. package/dist/safe/useWaitForSafeTransaction.d.ts.map +1 -0
  69. package/dist/safe/utils.d.ts +51 -0
  70. package/dist/safe/utils.d.ts.map +1 -0
  71. package/dist/test-harness/MockGraphAuthKit.context.d.ts +103 -0
  72. package/dist/test-harness/MockGraphAuthKit.context.d.ts.map +1 -0
  73. package/dist/test-harness/index.d.ts +3 -0
  74. package/dist/test-harness/index.d.ts.map +1 -0
  75. package/dist/test-harness/index.js +6 -0
  76. package/dist/test-harness/utils.d.ts +135 -0
  77. package/dist/test-harness/utils.d.ts.map +1 -0
  78. package/dist/types.d.ts +37 -0
  79. package/dist/types.d.ts.map +1 -0
  80. package/dist/useGraphAuthKitEnsNames-DHMYvwgX.js +211 -0
  81. package/dist/useWaitForSafeTransaction-YeFsJ9A5.js +46 -0
  82. package/dist/utils-Br1fBg8o.js +897 -0
  83. package/dist/utils.d.ts +20 -0
  84. package/dist/utils.d.ts.map +1 -0
  85. package/package.json +98 -0
@@ -0,0 +1,629 @@
1
+ "use client";
2
+ import { jsx } from "react/jsx-runtime";
3
+ import { buildEnsResolver } from "@graphprotocol/ens";
4
+ import { createContext, useContext, useRef, useState } from "react";
5
+ import { http, createPublicClient, createClient, isAddress } from "viem";
6
+ import { useConnect, useDisconnect, useAccountEffect } from "wagmi";
7
+ import { z } from "zod";
8
+ import { l1Mainnet, l1Testnet, l2Mainnet, l2Testnet } from "@graphprotocol/common";
9
+ import { mainnet, sepolia, arbitrum, arbitrumSepolia } from "viem/chains";
10
+ import { injected, coinbaseWallet, walletConnect } from "wagmi/connectors";
11
+ import "@safe-global/protocol-kit";
12
+ import { providers } from "ethers";
13
+ const AUTH_STORAGE_KEY = "thegraph__authstate";
14
+ const MULTISIG_AUTH_STORAGE_KEY = "multisig";
15
+ const L1Chain = { ...mainnet, graphCliName: l1Mainnet.id, caip2Id: l1Mainnet.caip2Id };
16
+ const L1ChainTestnet = { ...sepolia, graphCliName: l1Testnet.id, caip2Id: l1Testnet.caip2Id };
17
+ const L2Chain = { ...arbitrum, graphCliName: l2Mainnet.id, caip2Id: l2Mainnet.caip2Id };
18
+ const L2ChainTestnet = { ...arbitrumSepolia, graphCliName: l2Testnet.id, caip2Id: l2Testnet.caip2Id };
19
+ const DefChain = L2Chain;
20
+ const SupportedClientChainId = z.union([
21
+ z.literal(L1Chain.id),
22
+ z.literal(L1ChainTestnet.id),
23
+ z.literal(L2Chain.id),
24
+ z.literal(L2ChainTestnet.id)
25
+ ]).readonly();
26
+ const SupportedClientChains = [L2Chain, L2ChainTestnet, L1Chain, L1ChainTestnet];
27
+ const SupportedL1ClientChainId = z.union([z.literal(L1Chain.id), z.literal(L1ChainTestnet.id)]).readonly();
28
+ const SupportedL2ClientChainId = z.union([z.literal(L2Chain.id), z.literal(L2ChainTestnet.id)]).readonly();
29
+ const RequiredInfuraKey = z.object({
30
+ infuraKey: z.string({ error: "The Infura Key is required" }).min(1).readonly()
31
+ });
32
+ const RequiredWalletConnectProjectId = z.object({
33
+ walletConnectProjectID: z.string({ error: "The WalletConnect Project ID is required" }).min(1).readonly()
34
+ });
35
+ const OptionalGatewayApiKey = z.object({
36
+ gatewayApiKey: z.string().min(32).max(32).optional().nullable().describe("The Graph Gateway API Key used to query Subgraphs published on The Graph Network")
37
+ });
38
+ const OptionalSafeApiKey = z.object({
39
+ safeApiKey: z.string().min(1).optional().describe("The Safe Transaction Service API Key")
40
+ });
41
+ const GraphAuthKitProps = RequiredInfuraKey.merge(OptionalGatewayApiKey).merge(OptionalSafeApiKey);
42
+ const GraphAuthKitConnector = z.union([
43
+ z.literal(injected.type),
44
+ z.literal(coinbaseWallet.type),
45
+ z.literal(walletConnect.type),
46
+ z.literal("multisig")
47
+ ]);
48
+ RequiredInfuraKey.extend({
49
+ chain: SupportedClientChainId.optional().nullable().default(DefChain.id)
50
+ });
51
+ function buildInfuraHttpTransport({
52
+ chain = DefChain.id,
53
+ infuraKey
54
+ }) {
55
+ switch (chain) {
56
+ case L1Chain.id: {
57
+ return http(`https://mainnet.infura.io/v3/${infuraKey}`);
58
+ }
59
+ case L1ChainTestnet.id: {
60
+ return http(`https://sepolia.infura.io/v3/${infuraKey}`);
61
+ }
62
+ case L2ChainTestnet.id: {
63
+ return http(`https://arbitrum-sepolia.infura.io/v3/${infuraKey}`);
64
+ }
65
+ default: {
66
+ return http(`https://arbitrum-mainnet.infura.io/v3/${infuraKey}`);
67
+ }
68
+ }
69
+ }
70
+ const BuildPublicClientArgs = RequiredInfuraKey.extend({
71
+ chain: z.custom().optional().default(DefChain)
72
+ });
73
+ function isBuildPublicClientArgs(args) {
74
+ return args != null && typeof args === "object" && typeof args.infuraKey === "string";
75
+ }
76
+ function buildPublicClient({ chain = DefChain, infuraKey }) {
77
+ const transport = buildInfuraHttpTransport({
78
+ chain: chain.id,
79
+ infuraKey
80
+ });
81
+ return createPublicClient({
82
+ chain,
83
+ transport
84
+ });
85
+ }
86
+ const BuildClientArgs = RequiredInfuraKey.extend({
87
+ chain: z.custom().optional().default(DefChain)
88
+ });
89
+ function buildClient({ chain = DefChain, infuraKey }) {
90
+ const transport = buildInfuraHttpTransport({
91
+ chain: chain.id,
92
+ infuraKey
93
+ });
94
+ return createClient({
95
+ chain,
96
+ transport
97
+ });
98
+ }
99
+ const MultisigErrorMap = {
100
+ INVALID_SIGNER: {
101
+ title: "Signer Wallet is Invalid",
102
+ description: "This wallet is not a valid signing wallet for the Multisig. You can try again with a different wallet using the options below."
103
+ },
104
+ INVALID_NETWORK: {
105
+ title: "Invalid network",
106
+ description: "The signing wallet must be connected to the same network as the Multisig."
107
+ }
108
+ };
109
+ const SafeSupportedNetworks = z.union([z.literal(L1Chain.id), z.literal(L1ChainTestnet.id), z.literal(L2Chain.id)]).readonly();
110
+ function isSafeSupportedNetwork(network) {
111
+ return SafeSupportedNetworks.safeParse(network).success;
112
+ }
113
+ const SafeSupportedNetworkNames = {
114
+ [L2Chain.id]: { shortName: "arb1", name: L2Chain.name, id: L2Chain.id },
115
+ [L1Chain.id]: { shortName: "eth", name: L1Chain.name, id: L1Chain.id },
116
+ [L1ChainTestnet.id]: { shortName: "sep", name: L1ChainTestnet.name, id: L1ChainTestnet.id }
117
+ };
118
+ const ApiKitUrlMap = {
119
+ [L1Chain.id]: "https://api.safe.global/tx-service/eth/api",
120
+ [L1ChainTestnet.id]: "https://api.safe.global/tx-service/sep/api",
121
+ [L2Chain.id]: "https://api.safe.global/tx-service/arb1/api"
122
+ };
123
+ const SafeMinimalAbi = [
124
+ {
125
+ inputs: [],
126
+ payable: false,
127
+ stateMutability: "nonpayable",
128
+ type: "constructor"
129
+ },
130
+ {
131
+ constant: true,
132
+ inputs: [],
133
+ name: "getThreshold",
134
+ outputs: [
135
+ {
136
+ internalType: "uint256",
137
+ name: "",
138
+ type: "uint256"
139
+ }
140
+ ],
141
+ payable: false,
142
+ stateMutability: "view",
143
+ type: "function"
144
+ },
145
+ {
146
+ constant: true,
147
+ inputs: [],
148
+ name: "getOwners",
149
+ outputs: [
150
+ {
151
+ internalType: "address[]",
152
+ name: "",
153
+ type: "address[]"
154
+ }
155
+ ],
156
+ payable: false,
157
+ stateMutability: "view",
158
+ type: "function"
159
+ },
160
+ {
161
+ constant: false,
162
+ inputs: [
163
+ {
164
+ internalType: "bytes",
165
+ name: "_data",
166
+ type: "bytes"
167
+ },
168
+ {
169
+ internalType: "bytes",
170
+ name: "_signature",
171
+ type: "bytes"
172
+ }
173
+ ],
174
+ name: "isValidSignature",
175
+ outputs: [
176
+ {
177
+ internalType: "bytes4",
178
+ name: "",
179
+ type: "bytes4"
180
+ }
181
+ ],
182
+ payable: false,
183
+ stateMutability: "nonpayable",
184
+ type: "function"
185
+ },
186
+ {
187
+ constant: true,
188
+ inputs: [],
189
+ name: "nonce",
190
+ outputs: [
191
+ {
192
+ internalType: "uint256",
193
+ name: "",
194
+ type: "uint256"
195
+ }
196
+ ],
197
+ payable: false,
198
+ stateMutability: "view",
199
+ type: "function"
200
+ },
201
+ {
202
+ constant: true,
203
+ inputs: [
204
+ {
205
+ internalType: "address",
206
+ name: "owner",
207
+ type: "address"
208
+ }
209
+ ],
210
+ name: "isOwner",
211
+ outputs: [
212
+ {
213
+ internalType: "bool",
214
+ name: "",
215
+ type: "bool"
216
+ }
217
+ ],
218
+ payable: false,
219
+ stateMutability: "view",
220
+ type: "function"
221
+ }
222
+ ];
223
+ async function createApiKit(chainId, apiKey) {
224
+ const { default: SafeApiKit } = await import("@safe-global/api-kit");
225
+ const SafeApiKitClass = typeof SafeApiKit === "function" ? SafeApiKit : SafeApiKit.default;
226
+ const apiKit = new SafeApiKitClass({
227
+ chainId: BigInt(chainId),
228
+ apiKey
229
+ });
230
+ return apiKit;
231
+ }
232
+ async function createSafe(config) {
233
+ const { default: Safe2 } = await import("@safe-global/protocol-kit");
234
+ const SafeClass = typeof Safe2 === "function" ? Safe2 : Safe2.default;
235
+ return await SafeClass.init(config);
236
+ }
237
+ async function isValidSafe(args) {
238
+ try {
239
+ const client = isBuildPublicClientArgs(args.clientOrBuildClientArgs) ? buildPublicClient(args.clientOrBuildClientArgs) : args.clientOrBuildClientArgs;
240
+ await client.readContract({
241
+ address: args.safeAddress,
242
+ abi: SafeMinimalAbi,
243
+ functionName: "getThreshold"
244
+ });
245
+ return true;
246
+ } catch (err) {
247
+ console.warn("isValidSafe - failure checking safe", { err: err.message });
248
+ return false;
249
+ }
250
+ }
251
+ async function isSafeOwner(args) {
252
+ try {
253
+ const client = isBuildPublicClientArgs(args.clientOrBuildClientArgs) ? buildPublicClient(args.clientOrBuildClientArgs) : args.clientOrBuildClientArgs;
254
+ return await client.readContract({
255
+ address: args.safeAddress,
256
+ abi: SafeMinimalAbi,
257
+ functionName: "isOwner",
258
+ args: [args.eoa]
259
+ });
260
+ } catch (err) {
261
+ console.warn("isSafeOwner - failure checking if EoA is Safe owner", { err: err.message });
262
+ return false;
263
+ }
264
+ }
265
+ async function fetchOwnedSafes(args) {
266
+ let safes = {};
267
+ for (const chain of args.chains ?? [L2Chain.id, L1Chain.id, L1ChainTestnet.id]) {
268
+ const chainSafes = await fetchSafesByChain(args.signer, chain);
269
+ safes = { ...safes, [chain]: chainSafes };
270
+ }
271
+ return safes;
272
+ }
273
+ const OwnerResponseSchema = z.object({
274
+ safes: z.array(z.custom((val) => val != null && typeof val === "string" && isAddress(val)))
275
+ });
276
+ async function fetchSafesByChain(signer, chain) {
277
+ const txServiceUrl = ApiKitUrlMap[chain];
278
+ const response = await fetch(`${txServiceUrl}/v1/owners/${signer}/safes/`, {
279
+ method: "get",
280
+ headers: {
281
+ Accept: "application/json",
282
+ "Content-Type": "application/json"
283
+ }
284
+ });
285
+ if (response.status !== 200) {
286
+ return [];
287
+ }
288
+ const json = await response.json();
289
+ const parsed = OwnerResponseSchema.safeParse(json);
290
+ if (!parsed.success) {
291
+ return [];
292
+ }
293
+ return parsed.data.safes;
294
+ }
295
+ function chainIsSupportedChain(chain) {
296
+ return SupportedClientChainId.safeParse(chain.id).success;
297
+ }
298
+ function isSupportedChainId(chainId) {
299
+ return SupportedClientChainId.safeParse(chainId).success;
300
+ }
301
+ function mapChainIdToChain(chainId) {
302
+ const _chainId = isSupportedChainId(chainId) ? chainId : DefChain.id;
303
+ switch (_chainId) {
304
+ case L1Chain.id: {
305
+ return L1Chain;
306
+ }
307
+ case L1ChainTestnet.id: {
308
+ return L1ChainTestnet;
309
+ }
310
+ case L2ChainTestnet.id: {
311
+ return L2ChainTestnet;
312
+ }
313
+ default: {
314
+ return L2Chain;
315
+ }
316
+ }
317
+ }
318
+ function isChainL2(chain) {
319
+ return chain === L2Chain.id || chain === L2ChainTestnet.id;
320
+ }
321
+ function isChainL1(chain) {
322
+ return chain === L1Chain.id || chain === L1ChainTestnet.id;
323
+ }
324
+ function isChainMainnet(chain) {
325
+ return chain === L1Chain.id || chain === L2Chain.id;
326
+ }
327
+ function isChainTestnet(chain) {
328
+ return chain === L1ChainTestnet.id || chain === L2ChainTestnet.id;
329
+ }
330
+ function clientToProvider(client) {
331
+ var _a, _b;
332
+ const { chain, transport } = client;
333
+ const network = {
334
+ chainId: chain.id,
335
+ name: chain.name,
336
+ ensAddress: (_b = (_a = chain.contracts) == null ? void 0 : _a.ensRegistry) == null ? void 0 : _b.address
337
+ };
338
+ const provider = new providers.Web3Provider(transport, network);
339
+ return provider;
340
+ }
341
+ async function connectedWalletIsEoA(client, address) {
342
+ const code = await client.getCode({ address });
343
+ return code == null || code === "0x";
344
+ }
345
+ const MultisigSchema = z.object({
346
+ network: z.custom(
347
+ (val) => val != null && typeof val === "number" && SafeSupportedNetworks.safeParse(val).success
348
+ ),
349
+ address: z.string().min(42),
350
+ enteredSafeIsValid: z.boolean().optional()
351
+ });
352
+ const defInnerState = {
353
+ _infuraKey: "",
354
+ _gatewayApiKey: null,
355
+ _safeApiKey: void 0,
356
+ // just a default value so that the context can be initialized. overridden in the provider
357
+ _ensResolver: {
358
+ async resolveEnsName() {
359
+ return null;
360
+ },
361
+ async resolveEnsNamesBatch() {
362
+ return {};
363
+ },
364
+ async resolveAvatar() {
365
+ return null;
366
+ },
367
+ async resolveAvatarsBatch() {
368
+ return {};
369
+ }
370
+ },
371
+ _connectModalOpen: false,
372
+ _setConnectModalOpen() {
373
+ },
374
+ _modalTitle: "Connect your wallet",
375
+ _setModalTitle() {
376
+ },
377
+ _setModalSubtitle() {
378
+ },
379
+ _setAfterConnectUrl() {
380
+ },
381
+ _modalState: "primary",
382
+ _setModalState() {
383
+ },
384
+ _setSafeInfo() {
385
+ },
386
+ _authenticating: false,
387
+ _setAuthenticating() {
388
+ },
389
+ _connect() {
390
+ },
391
+ _connectMultisig() {
392
+ },
393
+ _reset() {
394
+ }
395
+ };
396
+ const GraphAuthKitInnerContext = createContext(defInnerState);
397
+ function useGraphAuthKitInnerContext() {
398
+ return useContext(GraphAuthKitInnerContext);
399
+ }
400
+ function GraphAuthKitInnerContextProvider({
401
+ config,
402
+ infuraKey,
403
+ gatewayApiKey,
404
+ safeApiKey,
405
+ children
406
+ }) {
407
+ const { connect } = useConnect({ config });
408
+ const { disconnect } = useDisconnect({ config });
409
+ const firstConnectCheckRef = useRef();
410
+ const [_connectModalOpen, setConnectModalOpen] = useState(false);
411
+ const [_modalTitle, setModalTitle] = useState();
412
+ const [_modalSubtitle, setModalSubtitle] = useState();
413
+ const [_afterConnectUrl, setAfterConnectUrl] = useState();
414
+ const [_authenticating, setAuthenticating] = useState(false);
415
+ const [_connectFailureMessage, setConnectFailureMessage] = useState();
416
+ const [_modalState, setModalState] = useState("primary");
417
+ const [_enteredMultisigInfo, setEnteredMultisigInfo] = useState();
418
+ useAccountEffect({
419
+ async onConnect() {
420
+ var _a;
421
+ if (!firstConnectCheckRef.current) {
422
+ const multisigCookie = await ((_a = config.storage) == null ? void 0 : _a.getItem(MULTISIG_AUTH_STORAGE_KEY));
423
+ if (multisigCookie) {
424
+ const parsedMultisigSchema = MultisigSchema.safeParse(
425
+ typeof multisigCookie === "string" ? JSON.parse(multisigCookie) : multisigCookie
426
+ );
427
+ if (parsedMultisigSchema.success && isAddress(parsedMultisigSchema.data.address)) {
428
+ setEnteredMultisigInfo(parsedMultisigSchema.data);
429
+ }
430
+ }
431
+ firstConnectCheckRef.current = true;
432
+ }
433
+ },
434
+ async onDisconnect() {
435
+ var _a;
436
+ await ((_a = config.storage) == null ? void 0 : _a.removeItem(`${AUTH_STORAGE_KEY}.store`));
437
+ }
438
+ });
439
+ const _connect = (connector) => {
440
+ setAuthenticating(true);
441
+ setConnectFailureMessage(void 0);
442
+ setEnteredMultisigInfo(void 0);
443
+ disconnect();
444
+ connect(
445
+ { connector },
446
+ {
447
+ onSuccess() {
448
+ setConnectModalOpen(false);
449
+ setModalTitle("Connect your wallet");
450
+ setModalSubtitle(void 0);
451
+ setModalState("primary");
452
+ if (_afterConnectUrl != null && typeof window !== "undefined") {
453
+ window.location.href = _afterConnectUrl;
454
+ setAfterConnectUrl(void 0);
455
+ }
456
+ },
457
+ onError(err) {
458
+ if (err.code === 4001) {
459
+ return;
460
+ }
461
+ console.error("GraphAuthKit.connect - failure connecting wallet", { err });
462
+ setConnectFailureMessage({ title: err.name, description: err.message });
463
+ },
464
+ onSettled() {
465
+ setAuthenticating(false);
466
+ }
467
+ }
468
+ );
469
+ };
470
+ const _connectMultisig = async (params) => {
471
+ var _a;
472
+ setAuthenticating(true);
473
+ setConnectFailureMessage(void 0);
474
+ disconnect();
475
+ const connectorChainId = await params.connector.getChainId();
476
+ if (connectorChainId !== params.network) {
477
+ void ((_a = config.storage) == null ? void 0 : _a.removeItem(MULTISIG_AUTH_STORAGE_KEY));
478
+ setConnectFailureMessage(MultisigErrorMap["INVALID_NETWORK"]);
479
+ setAuthenticating(false);
480
+ return;
481
+ }
482
+ connect(
483
+ { connector: params.connector },
484
+ {
485
+ async onSuccess(data) {
486
+ var _a2;
487
+ const [eoa] = data.accounts;
488
+ const client = buildPublicClient({
489
+ infuraKey,
490
+ chain: mapChainIdToChain(params.network)
491
+ });
492
+ const eoaIsSafeOwner = await isSafeOwner({
493
+ clientOrBuildClientArgs: client,
494
+ chain: params.network,
495
+ safeAddress: params.address,
496
+ eoa
497
+ });
498
+ if (!eoaIsSafeOwner) {
499
+ disconnect(
500
+ { connector: params.connector },
501
+ {
502
+ onSettled() {
503
+ var _a3;
504
+ void ((_a3 = config.storage) == null ? void 0 : _a3.removeItem(MULTISIG_AUTH_STORAGE_KEY));
505
+ setConnectFailureMessage(MultisigErrorMap["INVALID_SIGNER"]);
506
+ setAuthenticating(false);
507
+ }
508
+ }
509
+ );
510
+ return;
511
+ }
512
+ void ((_a2 = config.storage) == null ? void 0 : _a2.setItem(MULTISIG_AUTH_STORAGE_KEY, _enteredMultisigInfo));
513
+ setEnteredMultisigInfo({ address: params.address, network: params.network, enteredSafeIsValid: true });
514
+ setConnectModalOpen(false);
515
+ setModalTitle("Connect your wallet");
516
+ setModalSubtitle(void 0);
517
+ setModalState("primary");
518
+ if (_afterConnectUrl != null && typeof window !== "undefined") {
519
+ window.location.href = _afterConnectUrl;
520
+ setAfterConnectUrl(void 0);
521
+ }
522
+ },
523
+ onError(err) {
524
+ var _a2;
525
+ if (err.code === 4001) {
526
+ return;
527
+ }
528
+ void ((_a2 = config.storage) == null ? void 0 : _a2.removeItem(MULTISIG_AUTH_STORAGE_KEY));
529
+ setConnectFailureMessage({ title: err.name, description: err.message });
530
+ },
531
+ onSettled() {
532
+ setAuthenticating(false);
533
+ }
534
+ }
535
+ );
536
+ };
537
+ return /* @__PURE__ */ jsx(
538
+ GraphAuthKitInnerContext.Provider,
539
+ {
540
+ value: {
541
+ _infuraKey: infuraKey,
542
+ _gatewayApiKey: gatewayApiKey,
543
+ _safeApiKey: safeApiKey,
544
+ _ensResolver: buildEnsResolver({ infuraKey, gatewayApiKey }),
545
+ _connectModalOpen,
546
+ _setConnectModalOpen: setConnectModalOpen,
547
+ _modalTitle,
548
+ _setModalTitle: setModalTitle,
549
+ _modalSubtitle,
550
+ _setModalSubtitle: setModalSubtitle,
551
+ _setAfterConnectUrl: setAfterConnectUrl,
552
+ _modalState,
553
+ _setModalState(modalState) {
554
+ if (_modalState === "safe_eoa_signer" && modalState === "safe_entry") {
555
+ setConnectFailureMessage(void 0);
556
+ }
557
+ return setModalState(modalState);
558
+ },
559
+ _enteredMultisigInfo,
560
+ _setSafeInfo: setEnteredMultisigInfo,
561
+ _authenticating,
562
+ _setAuthenticating: setAuthenticating,
563
+ _connectFailureMessage,
564
+ _connect,
565
+ _connectMultisig,
566
+ _reset() {
567
+ var _a;
568
+ setAuthenticating(false);
569
+ setConnectFailureMessage(void 0);
570
+ setModalTitle("Connect your wallet");
571
+ setModalSubtitle(void 0);
572
+ setAfterConnectUrl(void 0);
573
+ setEnteredMultisigInfo(void 0);
574
+ setModalState("primary");
575
+ void ((_a = config.storage) == null ? void 0 : _a.removeItem(MULTISIG_AUTH_STORAGE_KEY));
576
+ }
577
+ },
578
+ children
579
+ }
580
+ );
581
+ }
582
+ export {
583
+ ApiKitUrlMap as A,
584
+ BuildPublicClientArgs as B,
585
+ isChainL2 as C,
586
+ DefChain as D,
587
+ isChainL1 as E,
588
+ isChainMainnet as F,
589
+ GraphAuthKitProps as G,
590
+ isChainTestnet as H,
591
+ clientToProvider as I,
592
+ connectedWalletIsEoA as J,
593
+ useGraphAuthKitInnerContext as K,
594
+ L1Chain as L,
595
+ MULTISIG_AUTH_STORAGE_KEY as M,
596
+ MultisigSchema as N,
597
+ OptionalGatewayApiKey as O,
598
+ GraphAuthKitInnerContextProvider as P,
599
+ GraphAuthKitInnerContext as Q,
600
+ RequiredInfuraKey as R,
601
+ SafeSupportedNetworks as S,
602
+ defInnerState as T,
603
+ SafeSupportedNetworkNames as a,
604
+ createSafe as b,
605
+ createApiKit as c,
606
+ isValidSafe as d,
607
+ isSafeOwner as e,
608
+ fetchOwnedSafes as f,
609
+ buildInfuraHttpTransport as g,
610
+ isBuildPublicClientArgs as h,
611
+ isSafeSupportedNetwork as i,
612
+ buildPublicClient as j,
613
+ BuildClientArgs as k,
614
+ buildClient as l,
615
+ AUTH_STORAGE_KEY as m,
616
+ L1ChainTestnet as n,
617
+ L2Chain as o,
618
+ L2ChainTestnet as p,
619
+ SupportedClientChainId as q,
620
+ SupportedClientChains as r,
621
+ SupportedL1ClientChainId as s,
622
+ SupportedL2ClientChainId as t,
623
+ RequiredWalletConnectProjectId as u,
624
+ OptionalSafeApiKey as v,
625
+ GraphAuthKitConnector as w,
626
+ chainIsSupportedChain as x,
627
+ isSupportedChainId as y,
628
+ mapChainIdToChain as z
629
+ };