@edgeandnode/graph-auth-kit 0.2.0

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 (57) hide show
  1. package/README.md +238 -0
  2. package/dist/Components/ConnectModal.d.ts +2 -0
  3. package/dist/Components/ConnectModal.d.ts.map +1 -0
  4. package/dist/Components/ConnectorOption.d.ts +13 -0
  5. package/dist/Components/ConnectorOption.d.ts.map +1 -0
  6. package/dist/Components/MultisigSignerOptions.d.ts +2 -0
  7. package/dist/Components/MultisigSignerOptions.d.ts.map +1 -0
  8. package/dist/Components/PrimaryConnectOptions.d.ts +2 -0
  9. package/dist/Components/PrimaryConnectOptions.d.ts.map +1 -0
  10. package/dist/Components/SafeInputForm.d.ts +2 -0
  11. package/dist/Components/SafeInputForm.d.ts.map +1 -0
  12. package/dist/Components/SafeSelection.d.ts +2 -0
  13. package/dist/Components/SafeSelection.d.ts.map +1 -0
  14. package/dist/GraphAuthKit.context-DBwb2jco.js +936 -0
  15. package/dist/GraphAuthKit.context.d.ts +80 -0
  16. package/dist/GraphAuthKit.context.d.ts.map +1 -0
  17. package/dist/GraphAuthKitInner.context.d.ts +109 -0
  18. package/dist/GraphAuthKitInner.context.d.ts.map +1 -0
  19. package/dist/client.d.ts +8612 -0
  20. package/dist/client.d.ts.map +1 -0
  21. package/dist/constants.d.ts +329 -0
  22. package/dist/constants.d.ts.map +1 -0
  23. package/dist/errors.d.ts +21 -0
  24. package/dist/errors.d.ts.map +1 -0
  25. package/dist/hooks.d.ts +74 -0
  26. package/dist/hooks.d.ts.map +1 -0
  27. package/dist/index.d.ts +8 -0
  28. package/dist/index.d.ts.map +1 -0
  29. package/dist/index.js +442 -0
  30. package/dist/safe/SafeEthersSigner.d.ts +37 -0
  31. package/dist/safe/SafeEthersSigner.d.ts.map +1 -0
  32. package/dist/safe/SafeMinimal.abi.d.ts +80 -0
  33. package/dist/safe/SafeMinimal.abi.d.ts.map +1 -0
  34. package/dist/safe/constants.d.ts +26 -0
  35. package/dist/safe/constants.d.ts.map +1 -0
  36. package/dist/safe/index.d.ts +3 -0
  37. package/dist/safe/index.d.ts.map +1 -0
  38. package/dist/safe/index.js +11 -0
  39. package/dist/safe/safeViemActions.d.ts +4 -0
  40. package/dist/safe/safeViemActions.d.ts.map +1 -0
  41. package/dist/safe/utils.d.ts +38 -0
  42. package/dist/safe/utils.d.ts.map +1 -0
  43. package/dist/safe/utils.test.d.ts +2 -0
  44. package/dist/safe/utils.test.d.ts.map +1 -0
  45. package/dist/test-harness/MockGraphAuthKit.context.d.ts +102 -0
  46. package/dist/test-harness/MockGraphAuthKit.context.d.ts.map +1 -0
  47. package/dist/test-harness/index.d.ts +2 -0
  48. package/dist/test-harness/index.d.ts.map +1 -0
  49. package/dist/test-harness/index.js +63 -0
  50. package/dist/types.d.ts +54 -0
  51. package/dist/types.d.ts.map +1 -0
  52. package/dist/utils-KuRu9vB-.js +218 -0
  53. package/dist/utils.d.ts +18 -0
  54. package/dist/utils.d.ts.map +1 -0
  55. package/dist/utils.test.d.ts +2 -0
  56. package/dist/utils.test.d.ts.map +1 -0
  57. package/package.json +93 -0
@@ -0,0 +1,102 @@
1
+ import { type ReactNode } from 'react';
2
+ import { type Chain } from 'viem';
3
+ import { type State } from 'wagmi';
4
+ import { type MockParameters } from 'wagmi/connectors';
5
+ import { type GraphAuthKitInnerState } from '../GraphAuthKitInner.context';
6
+ export type MockGraphAuthKitProviderProps<chains extends readonly [Chain, ...Chain[]] = readonly [Chain, ...Chain[]]> = {
7
+ infuraKey: string;
8
+ /**
9
+ * Provide an initial state to pass to the `WagmiConfig` that establishes if we have a connected (authenticated) user
10
+ * If a string, use the `cookieToInitialState` util to derive
11
+ * @see https://wagmi.sh/core/api/createConfig#state-1
12
+ */
13
+ initialState?: State<chains> | string;
14
+ /**
15
+ * Parameters that are passed to the `mock` connector constructor for building the mock connector.
16
+ * Includes:
17
+ * - accounts -> addresses to establish as connected for the user
18
+ *
19
+ * @see https://wagmi.sh/react/api/connectors/mock#parameters
20
+ */
21
+ mockConnectorParams: MockParameters;
22
+ /**
23
+ * Provide the default value for the inner context.
24
+ * Allows the mock to set the conntected state up with a safe, etc.
25
+ *
26
+ * @default {
27
+ * _infuraKey: '',
28
+ * _connectModalOpen: false,
29
+ * _setConnectModalOpen() {},
30
+ * _modalTitle: 'Connect your wallet',
31
+ * _setModalTitle() {},
32
+ * _setModalSubtitle() {},
33
+ * _modalState: 'primary',
34
+ * _setModalState() {},
35
+ * _setSafeInfo() {},
36
+ * _authenticating: false,
37
+ * _setAuthenticating() {},
38
+ * _connect() {},
39
+ * _connectMultisig() {},
40
+ * _reset() {},
41
+ * }
42
+ */
43
+ innerCtxState?: GraphAuthKitInnerState;
44
+ children: ReactNode;
45
+ };
46
+ /**
47
+ * Exposed mock `<GraphAuthKitProvider>` instance for testing components and hooks exposed
48
+ * by this library and wagmi.
49
+ *
50
+ * Allows for passing in addresses and information to establish an authenticated/connected `WagmiProvider` instance.
51
+ *
52
+ * @example <caption>User is not authenticated</caption>
53
+ * ```tsx
54
+ * import { MockGraphAuthKitProvider } from '@edgeandnode/graph-auth-kit/test-harness'
55
+ *
56
+ * <MockGraphAuthKitProvider infuraKey="abc123" mockConnectorParams={{ accounts: ['0x'] }}>
57
+ * <RendersAccount />
58
+ * </MockGraphAuthKitProvider>
59
+ * ```
60
+ *
61
+ * @example <caption>User is authenticated</caption>
62
+ * ```tsx
63
+ * import { MockGraphAuthKitProvider } from '@edgeandnode/graph-auth-kit/test-harness'
64
+ *
65
+ * <MockGraphAuthKitProvider
66
+ * infuraKey="abc123"
67
+ * mockConnectorParams={{ accounts: ['0x8c1b521970fDAB85d71260E08ee1dA5Dd878c60D'] }}
68
+ * initialState={{
69
+ * chainId: 42161,
70
+ * status: 'connected',
71
+ * current: null,
72
+ * connections: new Map<string, Connection>()
73
+ * }}
74
+ * innerCtxState={{...default, _connector: 'injected'}}
75
+ * >
76
+ * <RendersAccount />
77
+ * </MockGraphAuthKitProvider>
78
+ * ```
79
+ *
80
+ * @example <caption>User is authenticated with a Safe</caption>
81
+ * ```tsx
82
+ * import { MockGraphAuthKitProvider } from '@edgeandnode/graph-auth-kit/test-harness'
83
+ *
84
+ * <MockGraphAuthKitProvider
85
+ * infuraKey="abc123"
86
+ * mockConnectorParams={{ accounts: ['0x8c1b521970fDAB85d71260E08ee1dA5Dd878c60D'] }}
87
+ * initialState={{
88
+ * chainId: 42161,
89
+ * status: 'connected',
90
+ * current: null,
91
+ * connections: new Map<string, Connection>()
92
+ * }}
93
+ * innerCtxState={{...default, _connector: 'multisig', _enteredMultisigInfo: {address: '0x8c1b521970fDAB85d71260E08ee1dA5Dd878c60D',network:42161} }}
94
+ * >
95
+ * <RendersAccount />
96
+ * </MockGraphAuthKitProvider>
97
+ * ```
98
+ *
99
+ * @param props used to initialize the wagmi and inner context state
100
+ */
101
+ export declare function MockGraphAuthKitProvider(props: MockGraphAuthKitProviderProps): import("react").JSX.Element;
102
+ //# sourceMappingURL=MockGraphAuthKit.context.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"MockGraphAuthKit.context.d.ts","sourceRoot":"","sources":["../../src/test-harness/MockGraphAuthKit.context.tsx"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,SAAS,EAAE,MAAM,OAAO,CAAA;AACtC,OAAO,EAAE,KAAK,KAAK,EAAE,MAAM,MAAM,CAAA;AACjC,OAAO,EAKL,KAAK,KAAK,EAGX,MAAM,OAAO,CAAA;AACd,OAAO,EAAQ,KAAK,cAAc,EAAE,MAAM,kBAAkB,CAAA;AAK5D,OAAO,EAGL,KAAK,sBAAsB,EAE5B,MAAM,8BAA8B,CAAA;AAGrC,MAAM,MAAM,6BAA6B,CAAC,MAAM,SAAS,SAAS,CAAC,KAAK,EAAE,GAAG,KAAK,EAAE,CAAC,GAAG,SAAS,CAAC,KAAK,EAAE,GAAG,KAAK,EAAE,CAAC,IAClH;IACE,SAAS,EAAE,MAAM,CAAA;IAEjB;;;;OAIG;IACH,YAAY,CAAC,EAAE,KAAK,CAAC,MAAM,CAAC,GAAG,MAAM,CAAA;IACrC;;;;;;OAMG;IACH,mBAAmB,EAAE,cAAc,CAAA;IAEnC;;;;;;;;;;;;;;;;;;;;OAoBG;IACH,aAAa,CAAC,EAAE,sBAAsB,CAAA;IAEtC,QAAQ,EAAE,SAAS,CAAA;CACpB,CAAA;AACH;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsDG;AACH,wBAAgB,wBAAwB,CAAC,KAAK,EAAE,6BAA6B,+BAsC5E"}
@@ -0,0 +1,2 @@
1
+ export * from './MockGraphAuthKit.context';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/test-harness/index.ts"],"names":[],"mappings":"AAAA,cAAc,4BAA4B,CAAA"}
@@ -0,0 +1,63 @@
1
+ import { jsx } from "@theme-ui/core/jsx-runtime";
2
+ import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
3
+ import { createConfig, createStorage, cookieStorage, cookieToInitialState, WagmiProvider, useDisconnect } from "wagmi";
4
+ import { mock } from "wagmi/connectors";
5
+ import { c as chainIsSupportedChain, b as buildClient, G as GraphAuthKitInnerContext, d as defInnerState, u as useGraphAuthKitInnerContext, a as GraphAuthKitContext } from "../GraphAuthKit.context-DBwb2jco.js";
6
+ import { L as L2Chain, e as L2ChainTestnet, g as L1Chain, h as L1ChainTestnet, D as DefChain, j as AUTH_STORAGE_KEY } from "../utils-KuRu9vB-.js";
7
+ function MockGraphAuthKitProvider(props) {
8
+ const mockConfig = createConfig({
9
+ chains: [L2Chain, L2ChainTestnet, L1Chain, L1ChainTestnet],
10
+ connectors: [mock(props.mockConnectorParams)],
11
+ client(params) {
12
+ const chain = chainIsSupportedChain(params.chain) ? params.chain : DefChain;
13
+ return buildClient({ chain, infuraKey: props.infuraKey });
14
+ },
15
+ storage: createStorage({
16
+ storage: cookieStorage,
17
+ key: AUTH_STORAGE_KEY
18
+ })
19
+ });
20
+ const queryClient = new QueryClient({
21
+ defaultOptions: {
22
+ queries: {
23
+ retry: false
24
+ }
25
+ }
26
+ });
27
+ const initialState = props.initialState == null ? void 0 : typeof props.initialState === "string" ? cookieToInitialState(mockConfig, props.initialState) : props.initialState;
28
+ return /* @__PURE__ */ jsx(WagmiProvider, { config: mockConfig, initialState, children: /* @__PURE__ */ jsx(QueryClientProvider, { client: queryClient, children: /* @__PURE__ */ jsx(GraphAuthKitInnerContext.Provider, { value: props.innerCtxState ?? defInnerState, children: /* @__PURE__ */ jsx(MockGraphAuthKitContent, { children: props.children }) }) }) });
29
+ }
30
+ function MockGraphAuthKitContent({ children }) {
31
+ const { disconnect } = useDisconnect();
32
+ const innerContext = useGraphAuthKitInnerContext();
33
+ return /* @__PURE__ */ jsx(
34
+ GraphAuthKitContext.Provider,
35
+ {
36
+ value: {
37
+ openConnectModal(props) {
38
+ innerContext._setConnectModalOpen(true);
39
+ innerContext._setModalTitle((props == null ? void 0 : props.title) ?? "Connect your wallet");
40
+ innerContext._setModalSubtitle(props == null ? void 0 : props.subtitle);
41
+ },
42
+ closeConnectModal() {
43
+ innerContext._setConnectModalOpen(false);
44
+ innerContext._reset();
45
+ },
46
+ disconnect() {
47
+ disconnect(
48
+ {},
49
+ {
50
+ onSettled() {
51
+ innerContext._reset();
52
+ }
53
+ }
54
+ );
55
+ }
56
+ },
57
+ children
58
+ }
59
+ );
60
+ }
61
+ export {
62
+ MockGraphAuthKitProvider
63
+ };
@@ -0,0 +1,54 @@
1
+ import { z } from 'zod';
2
+ export declare const RequiredInfuraKey: z.ZodObject<{
3
+ infuraKey: z.ZodReadonly<z.ZodString>;
4
+ }, "strip", z.ZodTypeAny, {
5
+ infuraKey: string;
6
+ }, {
7
+ infuraKey: string;
8
+ }>;
9
+ export type RequiredInfuraKey = z.infer<typeof RequiredInfuraKey>;
10
+ export declare const RequiredWalletConnectProjectId: z.ZodObject<{
11
+ walletConnectProjectID: z.ZodReadonly<z.ZodString>;
12
+ }, "strip", z.ZodTypeAny, {
13
+ walletConnectProjectID: string;
14
+ }, {
15
+ walletConnectProjectID: string;
16
+ }>;
17
+ export type RequiredWalletConnectProjectId = z.infer<typeof RequiredWalletConnectProjectId>;
18
+ export declare const GraphAuthKitProps: z.ZodObject<z.objectUtil.extendShape<z.objectUtil.extendShape<{
19
+ infuraKey: z.ZodReadonly<z.ZodString>;
20
+ }, {
21
+ walletConnectProjectID: z.ZodReadonly<z.ZodString>;
22
+ }>, {
23
+ meta: z.ZodReadonly<z.ZodObject<{
24
+ name: z.ZodReadonly<z.ZodUnion<readonly [z.ZodLiteral<"Graph Explorer">, z.ZodLiteral<"Subgraph Studio">]>>;
25
+ url: z.ZodReadonly<z.ZodNullable<z.ZodOptional<z.ZodString>>>;
26
+ }, "strip", z.ZodTypeAny, {
27
+ name: "Graph Explorer" | "Subgraph Studio";
28
+ url?: string | null | undefined;
29
+ }, {
30
+ name: "Graph Explorer" | "Subgraph Studio";
31
+ url?: string | null | undefined;
32
+ }>>;
33
+ chains: z.ZodReadonly<z.ZodDefault<z.ZodUnion<readonly [z.ZodLiteral<"ALL">, z.ZodLiteral<"MAINNET">, z.ZodLiteral<"TESTNET">]>>>;
34
+ }>, "strip", z.ZodTypeAny, {
35
+ infuraKey: string;
36
+ walletConnectProjectID: string;
37
+ meta: Readonly<{
38
+ name: "Graph Explorer" | "Subgraph Studio";
39
+ url?: string | null | undefined;
40
+ }>;
41
+ chains: "ALL" | "MAINNET" | "TESTNET";
42
+ }, {
43
+ infuraKey: string;
44
+ walletConnectProjectID: string;
45
+ meta: Readonly<{
46
+ name: "Graph Explorer" | "Subgraph Studio";
47
+ url?: string | null | undefined;
48
+ }>;
49
+ chains?: "ALL" | "MAINNET" | "TESTNET" | undefined;
50
+ }>;
51
+ export type GraphAuthKitProps = z.infer<typeof GraphAuthKitProps>;
52
+ export declare const GraphAuthKitConnector: z.ZodReadonly<z.ZodUnion<readonly [z.ZodLiteral<"coinbaseWallet">, z.ZodLiteral<"injected">, z.ZodLiteral<"multisig">, z.ZodLiteral<"walletConnect">]>>;
53
+ export type GraphAuthKitConnector = z.infer<typeof GraphAuthKitConnector>;
54
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAEvB,eAAO,MAAM,iBAAiB;;;;;;EAE5B,CAAA;AACF,MAAM,MAAM,iBAAiB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,iBAAiB,CAAC,CAAA;AAEjE,eAAO,MAAM,8BAA8B;;;;;;EAEzC,CAAA;AACF,MAAM,MAAM,8BAA8B,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,8BAA8B,CAAC,CAAA;AAE3F,eAAO,MAAM,iBAAiB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAW5B,CAAA;AACF,MAAM,MAAM,iBAAiB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,iBAAiB,CAAC,CAAA;AAEjE,eAAO,MAAM,qBAAqB,yJAOrB,CAAA;AACb,MAAM,MAAM,qBAAqB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,qBAAqB,CAAC,CAAA"}
@@ -0,0 +1,218 @@
1
+ import { isAddress } from "viem";
2
+ import { z } from "zod";
3
+ import { mainnet, sepolia, arbitrum, arbitrumSepolia } from "viem/chains";
4
+ const AUTH_STORAGE_KEY = "thegraph__authstate";
5
+ const MULTISIG_AUTH_STORAGE_KEY = "multisig";
6
+ const L1Chain = mainnet;
7
+ const L1ChainTestnet = sepolia;
8
+ const L2Chain = arbitrum;
9
+ const L2ChainTestnet = arbitrumSepolia;
10
+ const DefChain = L2Chain;
11
+ const SupportedClientChainId = z.union([
12
+ z.literal(L1Chain.id),
13
+ z.literal(L1ChainTestnet.id),
14
+ z.literal(L2Chain.id),
15
+ z.literal(L2ChainTestnet.id)
16
+ ]).readonly();
17
+ const SupportedClientChains = [L2Chain, L2ChainTestnet, L1Chain, L1ChainTestnet];
18
+ const SafeSupportedNetworks = z.union([z.literal(L1Chain.id), z.literal(L1ChainTestnet.id), z.literal(L2Chain.id)]).readonly();
19
+ const SafeSupportedNetworkNames = {
20
+ [L2Chain.id]: { shortName: "arb1", name: L2Chain.name, id: L2Chain.id },
21
+ [L1Chain.id]: { shortName: "eth", name: L1Chain.name, id: L1Chain.id },
22
+ [L1ChainTestnet.id]: { shortName: "sep", name: L1ChainTestnet.name, id: L1ChainTestnet.id }
23
+ };
24
+ const ApiKitUrlMap = {
25
+ [L1Chain.id]: "https://safe-transaction-mainnet.safe.global/api",
26
+ [L1ChainTestnet.id]: "https://safe-transaction-sepolia.safe.global/api",
27
+ [L2Chain.id]: "https://safe-transaction-arbitrum.safe.global/api"
28
+ };
29
+ const SafeMinimalAbi = [
30
+ {
31
+ inputs: [],
32
+ payable: false,
33
+ stateMutability: "nonpayable",
34
+ type: "constructor"
35
+ },
36
+ {
37
+ constant: true,
38
+ inputs: [],
39
+ name: "getThreshold",
40
+ outputs: [
41
+ {
42
+ internalType: "uint256",
43
+ name: "",
44
+ type: "uint256"
45
+ }
46
+ ],
47
+ payable: false,
48
+ stateMutability: "view",
49
+ type: "function"
50
+ },
51
+ {
52
+ constant: true,
53
+ inputs: [],
54
+ name: "getOwners",
55
+ outputs: [
56
+ {
57
+ internalType: "address[]",
58
+ name: "",
59
+ type: "address[]"
60
+ }
61
+ ],
62
+ payable: false,
63
+ stateMutability: "view",
64
+ type: "function"
65
+ },
66
+ {
67
+ constant: false,
68
+ inputs: [
69
+ {
70
+ internalType: "bytes",
71
+ name: "_data",
72
+ type: "bytes"
73
+ },
74
+ {
75
+ internalType: "bytes",
76
+ name: "_signature",
77
+ type: "bytes"
78
+ }
79
+ ],
80
+ name: "isValidSignature",
81
+ outputs: [
82
+ {
83
+ internalType: "bytes4",
84
+ name: "",
85
+ type: "bytes4"
86
+ }
87
+ ],
88
+ payable: false,
89
+ stateMutability: "nonpayable",
90
+ type: "function"
91
+ },
92
+ {
93
+ constant: true,
94
+ inputs: [],
95
+ name: "nonce",
96
+ outputs: [
97
+ {
98
+ internalType: "uint256",
99
+ name: "",
100
+ type: "uint256"
101
+ }
102
+ ],
103
+ payable: false,
104
+ stateMutability: "view",
105
+ type: "function"
106
+ },
107
+ {
108
+ constant: true,
109
+ inputs: [
110
+ {
111
+ internalType: "address",
112
+ name: "owner",
113
+ type: "address"
114
+ }
115
+ ],
116
+ name: "isOwner",
117
+ outputs: [
118
+ {
119
+ internalType: "bool",
120
+ name: "",
121
+ type: "bool"
122
+ }
123
+ ],
124
+ payable: false,
125
+ stateMutability: "view",
126
+ type: "function"
127
+ }
128
+ ];
129
+ async function createApiKit(chainId) {
130
+ const { default: SafeApiKit } = await import("@safe-global/api-kit");
131
+ const SafeApiKitClass = typeof SafeApiKit === "function" ? SafeApiKit : SafeApiKit.default;
132
+ const apiKit = new SafeApiKitClass({
133
+ chainId: BigInt(chainId),
134
+ txServiceUrl: ApiKitUrlMap[chainId]
135
+ });
136
+ return apiKit;
137
+ }
138
+ async function createSafe(config) {
139
+ const { default: Safe } = await import("@safe-global/protocol-kit");
140
+ const SafeClass = typeof Safe === "function" ? Safe : Safe.default;
141
+ const protocolKit = await SafeClass.init(config);
142
+ return protocolKit;
143
+ }
144
+ async function isValidSafe(args) {
145
+ try {
146
+ await args.client.readContract({
147
+ address: args.safeAddress,
148
+ abi: SafeMinimalAbi,
149
+ functionName: "getThreshold"
150
+ });
151
+ return true;
152
+ } catch (err) {
153
+ console.warn("isValidSafe - failure checking safe", { err: err.message });
154
+ return false;
155
+ }
156
+ }
157
+ async function isSafeOwner(args) {
158
+ try {
159
+ return await args.client.readContract({
160
+ address: args.safeAddress,
161
+ abi: SafeMinimalAbi,
162
+ functionName: "isOwner",
163
+ args: [args.eoa]
164
+ });
165
+ } catch (err) {
166
+ console.warn("isSafeOwner - failure checking if EoA is Safe owner", { err: err.message });
167
+ return false;
168
+ }
169
+ }
170
+ async function fetchOwnedSafes(args) {
171
+ let safes = {};
172
+ for (const chain of args.chains ?? [L2Chain.id, L1Chain.id, L1ChainTestnet.id]) {
173
+ const chainSafes = await fetchSafesByChain(args.signer, chain);
174
+ safes = { ...safes, [chain]: chainSafes };
175
+ }
176
+ return safes;
177
+ }
178
+ const OwnerResponseSchema = z.object({
179
+ safes: z.array(z.custom((val) => val != null && typeof val === "string" && isAddress(val)))
180
+ });
181
+ async function fetchSafesByChain(signer, chain) {
182
+ const txServiceUrl = ApiKitUrlMap[chain];
183
+ const response = await fetch(`${txServiceUrl}/v1/owners/${signer}/safes/`, {
184
+ method: "get",
185
+ headers: {
186
+ Accept: "application/json",
187
+ "Content-Type": "application/json"
188
+ }
189
+ });
190
+ if (response.status !== 200) {
191
+ return [];
192
+ }
193
+ const json = await response.json();
194
+ const parsed = OwnerResponseSchema.safeParse(json);
195
+ if (!parsed.success) {
196
+ return [];
197
+ }
198
+ return parsed.data.safes;
199
+ }
200
+ export {
201
+ ApiKitUrlMap as A,
202
+ DefChain as D,
203
+ L2Chain as L,
204
+ MULTISIG_AUTH_STORAGE_KEY as M,
205
+ SafeSupportedNetworks as S,
206
+ SafeSupportedNetworkNames as a,
207
+ createSafe as b,
208
+ createApiKit as c,
209
+ isSafeOwner as d,
210
+ L2ChainTestnet as e,
211
+ fetchOwnedSafes as f,
212
+ L1Chain as g,
213
+ L1ChainTestnet as h,
214
+ isValidSafe as i,
215
+ AUTH_STORAGE_KEY as j,
216
+ SupportedClientChainId as k,
217
+ SupportedClientChains as l
218
+ };
@@ -0,0 +1,18 @@
1
+ import { providers } from 'ethers';
2
+ import type { Account, Address, Chain, Client, Transport } from 'viem';
3
+ import { type PublicClient } from './client';
4
+ import { type SupportedClientChains } from './constants';
5
+ export declare function chainIsSupportedChain(chain: Chain): chain is SupportedClientChains;
6
+ export declare function isChainL2(chain: number): boolean;
7
+ export declare function isChainL1(chain: number): boolean;
8
+ export declare function isChainMainnet(chain: number): boolean;
9
+ export declare function isChainTestnet(chain: number): boolean;
10
+ export declare function clientToProvider(client: Client<Transport, Chain, Account>): providers.Web3Provider;
11
+ /**
12
+ * Test whether the given wallet is a multisig or EoA
13
+ * @param client connected public client instance
14
+ * @param address the connected wallet to test
15
+ * @returns true if the connected wallet is an EoA, false if it is a multisig contract
16
+ */
17
+ export declare function connectedWalletIsEoA(client: PublicClient, address: Address): Promise<boolean>;
18
+ //# sourceMappingURL=utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAA;AAClC,OAAO,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,MAAM,CAAA;AAEtE,OAAO,EAAE,KAAK,YAAY,EAAE,MAAM,UAAU,CAAA;AAC5C,OAAO,EAML,KAAK,qBAAqB,EAC3B,MAAM,aAAa,CAAA;AAEpB,wBAAgB,qBAAqB,CAAC,KAAK,EAAE,KAAK,GAAG,KAAK,IAAI,qBAAqB,CAElF;AAED,wBAAgB,SAAS,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAEhD;AACD,wBAAgB,SAAS,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAEhD;AACD,wBAAgB,cAAc,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAErD;AACD,wBAAgB,cAAc,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAErD;AAED,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,MAAM,CAAC,SAAS,EAAE,KAAK,EAAE,OAAO,CAAC,0BASzE;AAED;;;;;GAKG;AACH,wBAAsB,oBAAoB,CAAC,MAAM,EAAE,YAAY,EAAE,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,CAInG"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=utils.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.test.d.ts","sourceRoot":"","sources":["../src/utils.test.ts"],"names":[],"mappings":""}
package/package.json ADDED
@@ -0,0 +1,93 @@
1
+ {
2
+ "name": "@edgeandnode/graph-auth-kit",
3
+ "version": "0.2.0",
4
+ "private": false,
5
+ "description": "Wallet authentication connect kit in The Graph suite of applications",
6
+ "author": "Edge & Node",
7
+ "license": "UNLICENSED",
8
+ "repository": {
9
+ "type": "git",
10
+ "url": "https://github.com/edgeandnode/components.git",
11
+ "directory": "packages/graph-auth-kit"
12
+ },
13
+ "type": "module",
14
+ "main": "./dist/index.js",
15
+ "types": "./dist/index.d.ts",
16
+ "exports": {
17
+ ".": {
18
+ "types": "./dist/index.d.ts",
19
+ "default": "./dist/index.js"
20
+ },
21
+ "./safe": {
22
+ "types": "./dist/safe/index.d.ts",
23
+ "default": "./dist/safe/index.js"
24
+ },
25
+ "./test-harness": {
26
+ "types": "./dist/test-harness/index.d.ts",
27
+ "default": "./dist/test-harness/index.js"
28
+ }
29
+ },
30
+ "files": [
31
+ "dist"
32
+ ],
33
+ "sideEffects": false,
34
+ "peerDependencies": {
35
+ "@emotion/react": "^11.13",
36
+ "@ethersproject/abstract-signer": "^5.7.0",
37
+ "@safe-global/api-kit": "2.4.3",
38
+ "@safe-global/protocol-kit": "4.0.3",
39
+ "@safe-global/safe-core-sdk-types": "5.0.3",
40
+ "@tanstack/react-query": "5.51.21",
41
+ "ethers": "5.7.2",
42
+ "react": "^18.3.1",
43
+ "react-dom": "^18.3.1",
44
+ "theme-ui": "^0.16",
45
+ "viem": "2.18.6",
46
+ "wagmi": "2.12.1",
47
+ "@edgeandnode/common": "^6.18.0",
48
+ "@edgeandnode/go": "^6.42.0",
49
+ "@edgeandnode/gds": "^5.27.0"
50
+ },
51
+ "devDependencies": {
52
+ "@emotion/react": "^11.13",
53
+ "@ethersproject/abstract-provider": "^5.7.0",
54
+ "@ethersproject/properties": "^5.7.0",
55
+ "@safe-global/api-kit": "2.4.3",
56
+ "@safe-global/protocol-kit": "4.0.3",
57
+ "@safe-global/safe-core-sdk-types": "5.0.3",
58
+ "@tanstack/react-query": "5.51.21",
59
+ "@types/react": "^18.3.3",
60
+ "@types/react-dom": "^18.3.0",
61
+ "@vitejs/plugin-react-swc": "^3.5.0",
62
+ "autoprefixer": "^10.4.19",
63
+ "ethers": "5.7.2",
64
+ "postcss": "^8.4.40",
65
+ "react": "^18.3.1",
66
+ "react-dom": "^18.3.1",
67
+ "tailwindcss": "^3.4.7",
68
+ "ts-node": "^10.9.2",
69
+ "viem": "2.18.6",
70
+ "wagmi": "2.12.2",
71
+ "@edgeandnode/common": "^6.18.0",
72
+ "@edgeandnode/test-utils": "^2.0.0",
73
+ "@edgeandnode/go": "^6.42.0",
74
+ "@edgeandnode/gds": "^5.27.0"
75
+ },
76
+ "dependencies": {
77
+ "zod": "^3.23.8"
78
+ },
79
+ "scripts": {
80
+ "build": "vite build && tsc -P ./tsconfig.build.json --emitDeclarationOnly",
81
+ "check": "pnpm typecheck && pnpm lint && pnpm prettier:check",
82
+ "check:fix": "pnpm typecheck; pnpm lint:fix",
83
+ "typecheck": "tsc --noEmit --pretty",
84
+ "lint": "eslint src --ext .js,.jsx,.ts,.tsx --max-warnings 0",
85
+ "lint:fix": "eslint src --ext .js,.jsx,.ts,.tsx --fix; pnpm prettier",
86
+ "prettier": "prettier . !CHANGELOG.md --ignore-path ../../.prettierignore --write --list-different",
87
+ "prettier:check": "prettier . !CHANGELOG.md --ignore-path ../../.prettierignore --check",
88
+ "test": "vitest run",
89
+ "test:coverage": "vitest run --coverage && jest-coverage-badges",
90
+ "test:watch": "vitest",
91
+ "npm:publish": "pnpm publish && git push"
92
+ }
93
+ }