@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,511 @@
1
+ "use client";
2
+ var __defProp = Object.defineProperty;
3
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
4
+ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
5
+ import { useMutation } from "@tanstack/react-query";
6
+ import { watchAccount } from "@wagmi/core";
7
+ import { useMemo, useState, useEffect } from "react";
8
+ import { encodeFunctionData, getAddress, isAddress } from "viem";
9
+ import { useChainId, useConnectorClient, useAccount, useConfig, useAccountEffect, useWalletClient } from "wagmi";
10
+ import { writeContractMutationOptions } from "wagmi/query";
11
+ import { b as createSafe, c as createApiKit, K as useGraphAuthKitInnerContext, I as clientToProvider, w as GraphAuthKitConnector, M as MULTISIG_AUTH_STORAGE_KEY, N as MultisigSchema } from "./GraphAuthKitInner.context-B3nCqd7x.js";
12
+ import { VoidSigner } from "@ethersproject/abstract-signer";
13
+ import "@safe-global/protocol-kit";
14
+ import { OperationType } from "@safe-global/types-kit";
15
+ import { BigNumber, utils } from "ethers";
16
+ const createLibAddress = "0x7cbB62EaA69F79e6873cD1ecB2392971036cFAa4";
17
+ const createLibInterface = new utils.Interface([
18
+ {
19
+ anonymous: false,
20
+ inputs: [
21
+ {
22
+ indexed: false,
23
+ internalType: "address",
24
+ name: "newContract",
25
+ type: "address"
26
+ }
27
+ ],
28
+ name: "ContractCreation",
29
+ type: "event"
30
+ },
31
+ {
32
+ inputs: [
33
+ {
34
+ internalType: "uint256",
35
+ name: "value",
36
+ type: "uint256"
37
+ },
38
+ {
39
+ internalType: "bytes",
40
+ name: "deploymentData",
41
+ type: "bytes"
42
+ }
43
+ ],
44
+ name: "performCreate",
45
+ outputs: [
46
+ {
47
+ internalType: "address",
48
+ name: "newContract",
49
+ type: "address"
50
+ }
51
+ ],
52
+ stateMutability: "nonpayable",
53
+ type: "function"
54
+ },
55
+ {
56
+ inputs: [
57
+ {
58
+ internalType: "uint256",
59
+ name: "value",
60
+ type: "uint256"
61
+ },
62
+ {
63
+ internalType: "bytes",
64
+ name: "deploymentData",
65
+ type: "bytes"
66
+ },
67
+ {
68
+ internalType: "bytes32",
69
+ name: "salt",
70
+ type: "bytes32"
71
+ }
72
+ ],
73
+ name: "performCreate2",
74
+ outputs: [
75
+ {
76
+ internalType: "address",
77
+ name: "newContract",
78
+ type: "address"
79
+ }
80
+ ],
81
+ stateMutability: "nonpayable",
82
+ type: "function"
83
+ }
84
+ ]);
85
+ const mapStatus = (receipt) => {
86
+ const success = receipt.logs.find(
87
+ (log) => log.topics[0] === "0x442e715f626346e8c54381002da614f62bee8d27386535b2521ec8540898556e"
88
+ );
89
+ return success ? 1 : 0;
90
+ };
91
+ const mapContractAddress = (receipt, safeTx) => {
92
+ if (safeTx.to.toLowerCase() === createLibAddress.toLowerCase()) {
93
+ const creationLog = receipt.logs.find(
94
+ (log) => log.topics[0] === "0x4db17dd5e4732fb6da34a148104a592783ca119a1e7bb8829eba6cbadef0b511"
95
+ );
96
+ if (creationLog) return utils.getAddress("0x" + creationLog.data.slice(creationLog.data.length - 40));
97
+ }
98
+ return receipt.contractAddress;
99
+ };
100
+ const mapReceipt = (receipt, safeTx) => {
101
+ receipt.status = mapStatus(receipt);
102
+ receipt.contractAddress = mapContractAddress(receipt, safeTx);
103
+ return receipt;
104
+ };
105
+ const sleep = (duration) => new Promise((resolve) => setTimeout(resolve, duration));
106
+ class SafeEthersSigner extends VoidSigner {
107
+ constructor(safeAddress, provider, signerAddress, chainId, options) {
108
+ super(safeAddress, provider);
109
+ __publicField(this, "safeAddress");
110
+ __publicField(this, "signerAddress");
111
+ __publicField(this, "chainId");
112
+ __publicField(this, "options");
113
+ __publicField(this, "safe");
114
+ __publicField(this, "apiKit");
115
+ this.signerAddress = signerAddress;
116
+ this.safeAddress = safeAddress;
117
+ this.chainId = chainId;
118
+ this.options = options;
119
+ }
120
+ async createSafeInstance() {
121
+ const eip1193Provider = {
122
+ request: async (args) => {
123
+ var _a;
124
+ return (_a = this.provider) == null ? void 0 : _a.send(args.method, args.params);
125
+ }
126
+ };
127
+ return createSafe({
128
+ provider: eip1193Provider,
129
+ signer: this.signerAddress,
130
+ safeAddress: this.safeAddress
131
+ });
132
+ }
133
+ async getSafeInstance() {
134
+ if (!this.safe) {
135
+ this.safe = await this.createSafeInstance();
136
+ }
137
+ return this.safe;
138
+ }
139
+ createApiKitInstance() {
140
+ var _a;
141
+ return createApiKit(this.chainId, (_a = this.options) == null ? void 0 : _a.apiKey);
142
+ }
143
+ async getApiKitInstance() {
144
+ if (!this.apiKit) {
145
+ this.apiKit = await this.createApiKitInstance();
146
+ }
147
+ return this.apiKit;
148
+ }
149
+ async getNextNonce() {
150
+ try {
151
+ const apiKit = await this.getApiKitInstance();
152
+ const nonce = await apiKit.getNextNonce(this.safeAddress);
153
+ return parseInt(nonce, 10);
154
+ } catch (error) {
155
+ throw new Error(`Failed to get next nonce: ${error instanceof Error ? error.message : String(error)}`);
156
+ }
157
+ }
158
+ async buildTransactionResponse(safeTxHash, safeTx) {
159
+ const connectedSafe = await this.getSafeInstance();
160
+ const connectedService = await this.getApiKitInstance();
161
+ const chainIdBigInt = await connectedSafe.getChainId();
162
+ return {
163
+ to: safeTx.to,
164
+ value: BigNumber.from(safeTx.value),
165
+ data: safeTx.data,
166
+ operation: safeTx.operation,
167
+ gasLimit: BigNumber.from(safeTx.safeTxGas),
168
+ gasPrice: BigNumber.from(0),
169
+ nonce: safeTx.nonce,
170
+ chainId: parseInt(chainIdBigInt.toString()),
171
+ hash: safeTxHash,
172
+ from: this.address,
173
+ confirmations: 0,
174
+ wait: async (confirmations) => {
175
+ var _a, _b;
176
+ while (true) {
177
+ try {
178
+ const txDetails = await connectedService.getTransaction(safeTxHash);
179
+ if (txDetails.transactionHash) {
180
+ this._checkProvider("sendTransaction");
181
+ const receipt = await ((_a = this.provider) == null ? void 0 : _a.waitForTransaction(
182
+ txDetails.transactionHash,
183
+ confirmations
184
+ ));
185
+ return mapReceipt(receipt, safeTx);
186
+ }
187
+ } catch (_e) {
188
+ }
189
+ await sleep(((_b = this.options) == null ? void 0 : _b.pollingDelay) ?? 5e3);
190
+ }
191
+ }
192
+ };
193
+ }
194
+ /**
195
+ * Populates all fields in a transaction, signs it and sends it to the Safe transaction service
196
+ *
197
+ * @param transaction - The transaction what should be send
198
+ * @returns A promise that resolves to a SafeTransactionReponse, that contains all the information of the transaction.
199
+ */
200
+ async sendTransaction(transaction) {
201
+ var _a;
202
+ const tx = await transaction;
203
+ let operation = OperationType.Call;
204
+ let to = await tx.to;
205
+ let data = ((_a = await tx.data) == null ? void 0 : _a.toString()) ?? "0x";
206
+ let value = BigNumber.from(await tx.value ?? 0);
207
+ if (!to) {
208
+ to = createLibAddress;
209
+ data = createLibInterface.encodeFunctionData("performCreate", [value, data]);
210
+ value = BigNumber.from(0);
211
+ operation = OperationType.DelegateCall;
212
+ }
213
+ const apiKit = await this.getApiKitInstance();
214
+ const nonce = await this.getNextNonce();
215
+ const safeTransactionData = {
216
+ to,
217
+ data,
218
+ value: value.toString(),
219
+ operation,
220
+ nonce
221
+ };
222
+ const estimateTx = await apiKit.estimateSafeTransaction(this.safeAddress, safeTransactionData);
223
+ safeTransactionData.safeTxGas = estimateTx.safeTxGas;
224
+ const connectedSafe = await this.getSafeInstance();
225
+ const safeTransaction = await connectedSafe.createTransaction({ transactions: [safeTransactionData] });
226
+ const safeTxHash = await connectedSafe.getTransactionHash(safeTransaction);
227
+ const senderSignature = await connectedSafe.signHash(safeTxHash);
228
+ await apiKit.proposeTransaction({
229
+ safeAddress: this.safeAddress,
230
+ safeTransactionData: safeTransaction.data,
231
+ safeTxHash,
232
+ senderAddress: this.signerAddress,
233
+ senderSignature: senderSignature.data
234
+ });
235
+ return this.buildTransactionResponse(safeTxHash, safeTransaction.data);
236
+ }
237
+ }
238
+ function safeViemActions(safeAddress, chainId, safeApiKey) {
239
+ return (client) => {
240
+ return {
241
+ async writeContract(parameters) {
242
+ const eip1193Provider = {
243
+ async request({ method, params }) {
244
+ if (method === "eth_requestAccounts") {
245
+ return client.requestAddresses();
246
+ }
247
+ if (method === "eth_accounts") {
248
+ return client.getAddresses();
249
+ }
250
+ if (method === "eth_signTypedData_v4") {
251
+ const arg = params && Array.isArray(params) ? params[1] : void 0;
252
+ const json = JSON.parse(arg);
253
+ return client.signTypedData(json);
254
+ }
255
+ if (method === "eth_sendTransaction") {
256
+ const tx = params && Array.isArray(params) ? params[0] : void 0;
257
+ return client.sendTransaction({
258
+ account: client.account,
259
+ chain: client.chain,
260
+ to: (tx == null ? void 0 : tx.to) || "0x",
261
+ value: tx == null ? void 0 : tx.value,
262
+ data: tx == null ? void 0 : tx.data,
263
+ nonce: tx == null ? void 0 : tx.nonce
264
+ });
265
+ }
266
+ return client.request({ method, params });
267
+ }
268
+ };
269
+ const apiKit = await createApiKit(chainId, safeApiKey);
270
+ const signerAddresses = await client.getAddresses();
271
+ const signerAddress = signerAddresses[0];
272
+ const protocolKit = await createSafe({ provider: eip1193Provider, signer: signerAddress, safeAddress });
273
+ const { abi, address, args, dataSuffix, functionName, value } = parameters;
274
+ const data = encodeFunctionData({
275
+ abi,
276
+ args,
277
+ functionName
278
+ });
279
+ const dataWithSuffix = `${data}${dataSuffix ? dataSuffix.replace("0x", "") : ""}`;
280
+ const operation = OperationType.Call;
281
+ let nonce;
282
+ try {
283
+ nonce = parseInt(await apiKit.getNextNonce(safeAddress), 10);
284
+ } catch (error) {
285
+ throw new Error(`Failed to get next nonce: ${error instanceof Error ? error.message : String(error)}`);
286
+ }
287
+ const safeTransactionData = {
288
+ to: address,
289
+ data: dataWithSuffix,
290
+ value: value ? value.toString() : "0",
291
+ operation,
292
+ nonce
293
+ };
294
+ const estimateTx = await apiKit.estimateSafeTransaction(safeAddress, safeTransactionData);
295
+ safeTransactionData.safeTxGas = estimateTx.safeTxGas;
296
+ const safeTransaction = await protocolKit.createTransaction({ transactions: [safeTransactionData] });
297
+ const safeTxHash = await protocolKit.getTransactionHash(safeTransaction);
298
+ const senderSignature = await protocolKit.signHash(safeTxHash);
299
+ await apiKit.proposeTransaction({
300
+ safeAddress,
301
+ safeTransactionData: safeTransaction.data,
302
+ safeTxHash,
303
+ senderAddress: signerAddress,
304
+ senderSignature: senderSignature.data
305
+ });
306
+ return safeTxHash;
307
+ }
308
+ };
309
+ };
310
+ }
311
+ function useClientToEthersSigner() {
312
+ const chainId = useChainId();
313
+ const { data: client, ...rest } = useConnectorClient({ chainId });
314
+ const { _enteredMultisigInfo, _safeApiKey } = useGraphAuthKitInnerContext();
315
+ return useMemo(() => {
316
+ if (rest.error) {
317
+ return { signer: void 0, ...rest };
318
+ }
319
+ if (rest.status === "pending" && !client) {
320
+ return { signer: void 0, ...rest };
321
+ }
322
+ if (!client) return { signer: null, ...rest };
323
+ const provider = clientToProvider(client);
324
+ if (_enteredMultisigInfo != null) {
325
+ const safeAddress = getAddress(_enteredMultisigInfo.address);
326
+ const safeEthersSigner = new SafeEthersSigner(
327
+ safeAddress,
328
+ provider,
329
+ client.account.address,
330
+ chainId,
331
+ { apiKey: _safeApiKey }
332
+ );
333
+ return { signer: safeEthersSigner, type: "multisig", ...rest };
334
+ }
335
+ return { signer: provider.getSigner(), type: "eoa", ...rest };
336
+ }, [chainId, client, rest.status, rest.error, _enteredMultisigInfo, _safeApiKey]);
337
+ }
338
+ function useGraphAuthKitConnector() {
339
+ const account = useGraphAuthKitAccount();
340
+ const { _enteredMultisigInfo } = useGraphAuthKitInnerContext();
341
+ if (account.connector == null) {
342
+ return null;
343
+ }
344
+ if ((_enteredMultisigInfo == null ? void 0 : _enteredMultisigInfo.address) != null || account.connectedWithMultisig) {
345
+ return "multisig";
346
+ }
347
+ const parsed = GraphAuthKitConnector.safeParse(account.connector.type);
348
+ return parsed.success ? parsed.data : null;
349
+ }
350
+ function useGraphAuthKitAccount() {
351
+ const data = useAccount();
352
+ const _enteredMultisigInfo = useMultisigInfo();
353
+ return useMemo(() => {
354
+ if (_enteredMultisigInfo != null && data.address != null) {
355
+ const address = getAddress(_enteredMultisigInfo.address);
356
+ const [, ...rest] = data.addresses ?? [];
357
+ return {
358
+ ...data,
359
+ address,
360
+ addresses: [address, data.address, ...rest],
361
+ eoa: data.address,
362
+ connectedWithMultisig: true
363
+ };
364
+ }
365
+ return {
366
+ ...data,
367
+ address: data.address,
368
+ addresses: data.addresses,
369
+ connector: data.connector,
370
+ eoa: void 0,
371
+ connectedWithMultisig: false
372
+ };
373
+ }, [data, _enteredMultisigInfo]);
374
+ }
375
+ function useAuthAccount() {
376
+ const auth = useGraphAuthKitAccount();
377
+ if (auth.address == null) {
378
+ throw new Error("Wallet is not connected");
379
+ }
380
+ return {
381
+ address: auth.address,
382
+ addresses: auth.addresses,
383
+ // not sure why this type assertion is necessary. but addresses comes across as [string, ...string[]]
384
+ chain: auth.chain,
385
+ chainId: auth.chainId,
386
+ connector: auth.connector,
387
+ eoa: auth.eoa,
388
+ connectedWithMultisig: auth.eoa != null
389
+ };
390
+ }
391
+ function useMultisigInfo({
392
+ config
393
+ } = {}) {
394
+ const conf = useConfig({ config });
395
+ const { _enteredMultisigInfo } = useGraphAuthKitInnerContext();
396
+ const [multisigInfo, setMultisigInfo] = useState(null);
397
+ useAccountEffect({
398
+ onDisconnect() {
399
+ setMultisigInfo(null);
400
+ }
401
+ });
402
+ useEffect(() => {
403
+ async function retrieveFromStorage() {
404
+ var _a;
405
+ const multisigCookie = await ((_a = conf.storage) == null ? void 0 : _a.getItem(MULTISIG_AUTH_STORAGE_KEY));
406
+ if (multisigCookie) {
407
+ const parsedMultisigSchema = MultisigSchema.safeParse(
408
+ typeof multisigCookie === "string" ? JSON.parse(multisigCookie) : multisigCookie
409
+ );
410
+ if (parsedMultisigSchema.success && isAddress(parsedMultisigSchema.data.address)) {
411
+ setMultisigInfo(parsedMultisigSchema.data);
412
+ }
413
+ }
414
+ }
415
+ if (_enteredMultisigInfo != null) {
416
+ setMultisigInfo(_enteredMultisigInfo);
417
+ } else {
418
+ void retrieveFromStorage();
419
+ }
420
+ }, [conf, _enteredMultisigInfo]);
421
+ return multisigInfo;
422
+ }
423
+ function useGraphAuthKitAccountEffect(args = {}) {
424
+ const { onConnect, onDisconnect } = args;
425
+ const conf = useConfig(args);
426
+ const _enteredMultisigInfo = useMultisigInfo(args);
427
+ useEffect(() => {
428
+ return watchAccount(conf, {
429
+ onChange(account, prevAccount) {
430
+ if ((prevAccount.status === "reconnecting" || prevAccount.status === "connecting" && prevAccount.address === void 0) && account.status === "connected" || account.status === "connected" && account.address !== prevAccount.address) {
431
+ const { chain, chainId, connector } = account;
432
+ let { address, addresses } = account;
433
+ let eoa = void 0;
434
+ let connectedWithMultisig = false;
435
+ if (_enteredMultisigInfo != null) {
436
+ const [, ...rest] = addresses;
437
+ const multisigAddress = getAddress(_enteredMultisigInfo.address);
438
+ eoa = address;
439
+ address = multisigAddress;
440
+ addresses = [multisigAddress, eoa, ...rest];
441
+ connectedWithMultisig = true;
442
+ }
443
+ const isReconnected = prevAccount.status === "reconnecting" || // if `previousAccount.status` is `undefined`, the connector connected immediately.
444
+ prevAccount.status === void 0;
445
+ onConnect == null ? void 0 : onConnect({
446
+ address,
447
+ addresses,
448
+ eoa,
449
+ chain,
450
+ chainId,
451
+ connector,
452
+ isReconnected,
453
+ connectedWithMultisig
454
+ });
455
+ } else if (prevAccount.status === "connected" && account.status === "disconnected") {
456
+ onDisconnect == null ? void 0 : onDisconnect();
457
+ }
458
+ }
459
+ });
460
+ }, [conf, _enteredMultisigInfo, onConnect, onDisconnect]);
461
+ }
462
+ function useGraphAuthKitWalletClient() {
463
+ const walletClient = useWalletClient();
464
+ const _enteredMultisigInfo = useMultisigInfo();
465
+ const { _safeApiKey } = useGraphAuthKitInnerContext();
466
+ if (!walletClient.data) {
467
+ return walletClient;
468
+ }
469
+ if (_enteredMultisigInfo != null && _safeApiKey != null) {
470
+ const safeAddress = getAddress(_enteredMultisigInfo.address);
471
+ const safeWalletClient = walletClient.data.extend(
472
+ safeViemActions(safeAddress, _enteredMultisigInfo.network, _safeApiKey)
473
+ );
474
+ return { ...walletClient, data: safeWalletClient };
475
+ }
476
+ return walletClient;
477
+ }
478
+ function useGraphAuthKitWriteContract(parameters = {}) {
479
+ const { data: walletClient } = useGraphAuthKitWalletClient();
480
+ const { mutation } = parameters;
481
+ const conf = useConfig(parameters);
482
+ const mutationOptions = writeContractMutationOptions(conf);
483
+ const customMutationFn = (variables) => {
484
+ if (!walletClient) {
485
+ throw new Error("WalletClient is not available");
486
+ }
487
+ return walletClient.writeContract(variables);
488
+ };
489
+ const { mutate, mutateAsync, ...result } = useMutation({
490
+ ...mutation,
491
+ ...mutationOptions,
492
+ mutationFn: customMutationFn
493
+ });
494
+ return {
495
+ ...result,
496
+ writeContract: mutate,
497
+ writeContractAsync: mutateAsync
498
+ };
499
+ }
500
+ export {
501
+ SafeEthersSigner as S,
502
+ useGraphAuthKitAccount as a,
503
+ useGraphAuthKitConnector as b,
504
+ useClientToEthersSigner as c,
505
+ useAuthAccount as d,
506
+ useGraphAuthKitAccountEffect as e,
507
+ useGraphAuthKitWalletClient as f,
508
+ useGraphAuthKitWriteContract as g,
509
+ mapReceipt as m,
510
+ useMultisigInfo as u
511
+ };
@@ -0,0 +1,125 @@
1
+ import { Compute } from '@wagmi/core/internal';
2
+ import { providers } from 'ethers';
3
+ import { Address, Chain } from 'viem';
4
+ import { Config, Connector, ResolvedRegister, UseAccountReturnType, UseConnectorClientReturnType, UseWalletClientReturnType, UseWriteContractParameters, UseWriteContractReturnType } from 'wagmi';
5
+ import { MultisigSchema } from './inner/GraphAuthKitInner.context';
6
+ import { SafeEthersSigner } from './safe/SafeEthersSigner';
7
+ import { GraphAuthKitConnector } from './types';
8
+ /**
9
+ * Hook to to convert a Viem Client to an ethers.js Signer:
10
+ * - if a multisig wallet is connected return an instance of SafeEthersSigner
11
+ * - if an EoA wallet is connected return the Signer from `clientToProvider`
12
+ */
13
+ export declare function useClientToEthersSigner<const config extends Config = ResolvedRegister['config']>(): Omit<UseConnectorClientReturnType, "data"> & {
14
+ signer: providers.JsonRpcSigner | SafeEthersSigner | undefined | null;
15
+ };
16
+ export declare function useGraphAuthKitConnector<const config extends Config = ResolvedRegister['config']>(): GraphAuthKitConnector | null;
17
+ export type UseGraphAuthKitAccountReturnType<config extends Config = ResolvedRegister['config']> = UseAccountReturnType<config> & Readonly<{
18
+ /** If the user is connected to a multisig, this is the EoA signer address the user is connected with */
19
+ eoa?: Address | null;
20
+ /** Flag on if the user is connected via a multisig */
21
+ connectedWithMultisig: boolean;
22
+ }>;
23
+ /**
24
+ * Override hook of wagmi `useAccount`.
25
+ * The GraphAuthKit lets users connect to a Safe by entering the Safe information in,
26
+ * and then connecting their EoA account through the other EoA wallet options.
27
+ *
28
+ * However, in this use-case, the connected account according to wagmi is still the EoA.
29
+ * This hook checks the inner context and if the user is connected via a multisig,
30
+ * returns the multisig address as the `address` return from the hook.
31
+ *
32
+ * Otherwise, returns the connected wallet state.
33
+ *
34
+ * @see https://wagmi.sh/react/api/hooks/useAccount
35
+ */
36
+ export declare function useGraphAuthKitAccount<const config extends Config = ResolvedRegister['config']>(): UseGraphAuthKitAccountReturnType<config>;
37
+ export type UseAuthAccountReturnType<config extends Config = Config, chain = Config extends config ? Chain : config['chains'][number]> = {
38
+ address: Address;
39
+ addresses: readonly [Address, ...Address[]];
40
+ chain: chain | undefined;
41
+ chainId: number;
42
+ connector: Connector;
43
+ } & Readonly<{
44
+ /** If the user is connected to a multisig, this is the EoA signer address the user is connected with */
45
+ eoa?: Address | null;
46
+ /** Flag on if the user is connected via a multisig */
47
+ connectedWithMultisig: boolean;
48
+ }>;
49
+ /**
50
+ * Hook that returns the authenticated account information.
51
+ * If the wallet is not connected, an error is thrown.
52
+ * This hooks is useful to render where you _know_ the wallet is connected,
53
+ * preventing checks if the `address` is null further down the tree.
54
+ */
55
+ export declare function useAuthAccount<const config extends Config = ResolvedRegister['config']>(): UseAuthAccountReturnType<config>;
56
+ /**
57
+ * Retrieve the entered multisig info from:
58
+ * - the innter context object
59
+ * - if not in the inner context, check if found in storage
60
+ */
61
+ export declare function useMultisigInfo<const config extends Config = ResolvedRegister['config']>({ config, }?: Readonly<{
62
+ config?: config;
63
+ }>): MultisigSchema | null;
64
+ export type UseGraphAuthKitAccountEffectArgs<config extends Config = ResolvedRegister['config']> = Compute<{
65
+ config?: config | undefined;
66
+ onConnect?(data: Compute<Pick<Extract<UseGraphAuthKitAccountReturnType<config>, {
67
+ status: 'connected';
68
+ }>, 'address' | 'addresses' | 'chain' | 'chainId' | 'connector' | 'eoa' | 'connectedWithMultisig'> & {
69
+ isReconnected: boolean;
70
+ }>): void;
71
+ onDisconnect?(): void;
72
+ }>;
73
+ /**
74
+ * Override hook of the wagmi `useAccountEffect` that listens to changes derived from the `useGraphAuthKitAccount` hook.
75
+ * Listening to the `useAccountEffect` hook does not work when the user connects via a multisig in the graph-auth-kit
76
+ * as the connected account is the EoA and not the Safe address.
77
+ * This hooks listens on account changes, but checks if the user has connected through a multisig.
78
+ *
79
+ * @see https://wagmi.sh/react/api/hooks/useAccountEffect
80
+ */
81
+ export declare function useGraphAuthKitAccountEffect<const config extends Config = ResolvedRegister['config']>(args?: UseGraphAuthKitAccountEffectArgs<config>): void;
82
+ /**
83
+ * Override hook of wagmi `useWalletClient`.
84
+ * The GraphAuthKit lets users connect to a Safe by entering the Safe information in,
85
+ * and then connecting their EoA account through the other EoA wallet options.
86
+ *
87
+ * However, in this use-case, the connected account according to wagmi is still the EoA.
88
+ * This hook checks the inner context and if the user is connected via a multisig,
89
+ * it returns the an extended version of the walletClient overriding the `writeContract` method.
90
+ *
91
+ * Otherwise, it returns the walletClient as is.
92
+ *
93
+ * @see https://wagmi.sh/react/api/hooks/useWalletClient
94
+ */
95
+ export declare function useGraphAuthKitWalletClient<const config extends Config = ResolvedRegister['config']>(): UseWalletClientReturnType<config>;
96
+ /**
97
+ * Override hook of wagmi `useWriteContract`.
98
+ * The GraphAuthKit lets users connect to a Safe by entering the Safe information in,
99
+ * and then connecting their EoA account through the other EoA wallet options.
100
+ *
101
+ * However, in this use-case, the connected account according to wagmi is still the EoA.
102
+ * This hook gets the WalletClient that could be the original EOA or the Safe's WalletClient,
103
+ * and then it calls the `writeContract` method on the client itself with the passed arguments.
104
+ * The returned values are the results of `useMutation` hook just like in wagmi's `useWriteContract`.
105
+ *
106
+ * @example
107
+ *
108
+ * function ComponentWithContractCall() {
109
+ * const { data: walletClient } = useGraphAuthKitWalletClient()
110
+ * const { writeContractAsync } = useGraphAuthKitWriteContract();
111
+ *
112
+ * return (
113
+ * <button
114
+ * disabled={!walletClient}
115
+ * onClick={() => writeContractAsync({ address: '0x...', abi: [], functionName: 'mint', args: [1] })}
116
+ * >
117
+ * {!walletClient ? "Loading..." : "Mint"}
118
+ * </button>
119
+ * )
120
+ * }
121
+ *
122
+ * @see https://wagmi.sh/react/api/hooks/useWriteContract
123
+ */
124
+ export declare function useGraphAuthKitWriteContract<const config extends Config = ResolvedRegister['config'], context = unknown>(parameters?: UseWriteContractParameters<config, context>): UseWriteContractReturnType<config, context>;
125
+ //# sourceMappingURL=hooks.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AAO,CAAC,gCAAgC,CAAC,MAAM,CAAC,EAAE;QAAE,MAAM,EAAE,WAAW,CAAA;KAAE,CAAC,EAC1E,SAAS,GAAG,WAAW,GAAG,OAAO,GAAG,SAAS,GAAG,WAAW,GAAG,KAAK,GAAG,uBAAuB,CAC9F,GAAG;QACF,aAAa,EAAE,OAAO,CAAA;KACvB,CACF,GACA,IAAI,CAAA;IACP,YAAY,CAAC,IAAI,IAAI,CAAA;CACtB,CAAC,CAAA;AACF;;;;;;;GAOG;AACH,wBAAgB,4BAA4B,CAAC,KAAK,CAAC,MAAM,SAAS,MAAM,GAAG,gBAAgB,CAAC,QAAQ,CAAC,EACnG,IAAI,GAAE,gCAAgC,CAAC,MAAM,CAAM,QAmDpD;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,2BAA2B,CACzC,KAAK,CAAC,MAAM,SAAS,MAAM,GAAG,gBAAgB,CAAC,QAAQ,CAAC,KACrD,yBAAyB,CAAC,MAAM,CAAC,CAoBrC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,wBAAgB,4BAA4B,CAC1C,KAAK,CAAC,MAAM,SAAS,MAAM,GAAG,gBAAgB,CAAC,QAAQ,CAAC,EACxD,OAAO,GAAG,OAAO,EACjB,UAAU,GAAE,0BAA0B,CAAC,MAAM,EAAE,OAAO,CAAM,GAAG,0BAA0B,CAAC,MAAM,EAAE,OAAO,CAAC,CA8B3G"}
@@ -0,0 +1,11 @@
1
+ export * from './client';
2
+ export * from './Components';
3
+ export * from './constants';
4
+ export * from './ens';
5
+ export * from './GraphAuthKit.context';
6
+ export * from './hooks';
7
+ export * from './safe';
8
+ export * from './test-harness';
9
+ export * from './types';
10
+ export * from './utils';
11
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAA;AACxB,cAAc,cAAc,CAAA;AAC5B,cAAc,aAAa,CAAA;AAC3B,cAAc,OAAO,CAAA;AACrB,cAAc,wBAAwB,CAAA;AACtC,cAAc,SAAS,CAAA;AACvB,cAAc,QAAQ,CAAA;AACtB,cAAc,gBAAgB,CAAA;AAC9B,cAAc,SAAS,CAAA;AACvB,cAAc,SAAS,CAAA"}