@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.
- package/README.md +238 -0
- package/dist/Components/ConnectModal.d.ts +2 -0
- package/dist/Components/ConnectModal.d.ts.map +1 -0
- package/dist/Components/ConnectorOption.d.ts +13 -0
- package/dist/Components/ConnectorOption.d.ts.map +1 -0
- package/dist/Components/MultisigSignerOptions.d.ts +2 -0
- package/dist/Components/MultisigSignerOptions.d.ts.map +1 -0
- package/dist/Components/PrimaryConnectOptions.d.ts +2 -0
- package/dist/Components/PrimaryConnectOptions.d.ts.map +1 -0
- package/dist/Components/SafeInputForm.d.ts +2 -0
- package/dist/Components/SafeInputForm.d.ts.map +1 -0
- package/dist/Components/SafeSelection.d.ts +2 -0
- package/dist/Components/SafeSelection.d.ts.map +1 -0
- package/dist/GraphAuthKit.context-DBwb2jco.js +936 -0
- package/dist/GraphAuthKit.context.d.ts +80 -0
- package/dist/GraphAuthKit.context.d.ts.map +1 -0
- package/dist/GraphAuthKitInner.context.d.ts +109 -0
- package/dist/GraphAuthKitInner.context.d.ts.map +1 -0
- package/dist/client.d.ts +8612 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/constants.d.ts +329 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/errors.d.ts +21 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/hooks.d.ts +74 -0
- package/dist/hooks.d.ts.map +1 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +442 -0
- package/dist/safe/SafeEthersSigner.d.ts +37 -0
- package/dist/safe/SafeEthersSigner.d.ts.map +1 -0
- package/dist/safe/SafeMinimal.abi.d.ts +80 -0
- package/dist/safe/SafeMinimal.abi.d.ts.map +1 -0
- package/dist/safe/constants.d.ts +26 -0
- package/dist/safe/constants.d.ts.map +1 -0
- package/dist/safe/index.d.ts +3 -0
- package/dist/safe/index.d.ts.map +1 -0
- package/dist/safe/index.js +11 -0
- package/dist/safe/safeViemActions.d.ts +4 -0
- package/dist/safe/safeViemActions.d.ts.map +1 -0
- package/dist/safe/utils.d.ts +38 -0
- package/dist/safe/utils.d.ts.map +1 -0
- package/dist/safe/utils.test.d.ts +2 -0
- package/dist/safe/utils.test.d.ts.map +1 -0
- package/dist/test-harness/MockGraphAuthKit.context.d.ts +102 -0
- package/dist/test-harness/MockGraphAuthKit.context.d.ts.map +1 -0
- package/dist/test-harness/index.d.ts +2 -0
- package/dist/test-harness/index.d.ts.map +1 -0
- package/dist/test-harness/index.js +63 -0
- package/dist/types.d.ts +54 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/utils-KuRu9vB-.js +218 -0
- package/dist/utils.d.ts +18 -0
- package/dist/utils.d.ts.map +1 -0
- package/dist/utils.test.d.ts +2 -0
- package/dist/utils.test.d.ts.map +1 -0
- package/package.json +93 -0
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { QueryClient } from '@tanstack/react-query';
|
|
2
|
+
import { type ReactNode } from 'react';
|
|
3
|
+
import { type GraphAuthKitProps } from './types';
|
|
4
|
+
export type GraphAuthKitState = {
|
|
5
|
+
/** Opens the GraphAuthKit connect modal to allow user to go through wallet connect flow */
|
|
6
|
+
openConnectModal(props?: {
|
|
7
|
+
title?: ReactNode;
|
|
8
|
+
subtitle?: ReactNode;
|
|
9
|
+
afterConnectUrl?: string;
|
|
10
|
+
}): void;
|
|
11
|
+
/** Closes the GraphAuthKit connect modal */
|
|
12
|
+
closeConnectModal(): void;
|
|
13
|
+
/** Disconnect the GraphAuthKit state. Wraps the disconnect from the useDisconnect() hook */
|
|
14
|
+
disconnect(): void | Promise<void>;
|
|
15
|
+
};
|
|
16
|
+
export declare const GraphAuthKitContext: import("react").Context<GraphAuthKitState>;
|
|
17
|
+
export declare function useGraphAuthKit(): GraphAuthKitState;
|
|
18
|
+
export type GraphAuthKitProviderProps = GraphAuthKitProps & {
|
|
19
|
+
/**
|
|
20
|
+
* [Optional]. An instantiated @tanstack/react-query `QueryClient` instance.
|
|
21
|
+
* If null, will instantiate a `QueryClient` and pass to the `QueryClientProvider`.
|
|
22
|
+
*/
|
|
23
|
+
queryClient?: QueryClient;
|
|
24
|
+
/**
|
|
25
|
+
* [Optional]. Get the wagmi initial state from a cookie in the browser/api from the app rendering the `GraphAuthKitProvider`
|
|
26
|
+
*/
|
|
27
|
+
initialStateCookie?: string | null;
|
|
28
|
+
} & Readonly<{
|
|
29
|
+
children: ReactNode;
|
|
30
|
+
}>;
|
|
31
|
+
/**
|
|
32
|
+
* Builds and renders a wagmi config instance wrapped in a `WagmiProvider` context.
|
|
33
|
+
* This then wraps the `GraphAuthKitContext.Provider` which provides the connect modal state for app users to connect their wallet.
|
|
34
|
+
*
|
|
35
|
+
* **NOTE** it does NOT wrap a react-query `QueryClientProvider` instance.
|
|
36
|
+
* The app _MUST_ do this instead.
|
|
37
|
+
* react-query is responsible for query context, which wagmi uses to store account/config information.
|
|
38
|
+
* But the react-query provider can be used for querying and other uses as well.
|
|
39
|
+
*
|
|
40
|
+
* @example <caption>Configure and render the GraphAuthKit for explorer</caption>
|
|
41
|
+
* ```tsx
|
|
42
|
+
* // _app.tsx
|
|
43
|
+
*
|
|
44
|
+
* import { QueryClient } from '@tanstack/react-query'
|
|
45
|
+
* import { AppProps } from 'next'
|
|
46
|
+
* import { useRef } from 'react'
|
|
47
|
+
*
|
|
48
|
+
* import { GraphAuthKitProvider } from '@edgeandnode/graph-auth-kit'
|
|
49
|
+
*
|
|
50
|
+
* const infuraKey = process.env.INFURA_KEY!
|
|
51
|
+
* const walletConnectProjectID = process.env.WALLETCONNECT_PROJECT_ID!
|
|
52
|
+
*
|
|
53
|
+
* export default function App({ Component, router, pageProps }: AppProps) {
|
|
54
|
+
* const queryClient = useRef<QueryClient>()
|
|
55
|
+
* if (!queryClient.current) {
|
|
56
|
+
* queryClient.current = new QueryClient({
|
|
57
|
+
* defaultOptions: {
|
|
58
|
+
* queries: {
|
|
59
|
+
* staleTime: 60 * 1000
|
|
60
|
+
* }
|
|
61
|
+
* }
|
|
62
|
+
* })
|
|
63
|
+
* }
|
|
64
|
+
*
|
|
65
|
+
* return (
|
|
66
|
+
* <GraphAuthKitProvider
|
|
67
|
+
* queryClient={queryClient.current}
|
|
68
|
+
* infuraKey={infuraKey}
|
|
69
|
+
* walletConnectProjectID={walletConnectProjectID}
|
|
70
|
+
* meta={{ name: 'Graph Explorer' }}
|
|
71
|
+
* chains="MAINNET"
|
|
72
|
+
* >
|
|
73
|
+
* <Component {...pageProps} />
|
|
74
|
+
* </GraphAuthKitProvider>
|
|
75
|
+
* )
|
|
76
|
+
* }
|
|
77
|
+
* ```
|
|
78
|
+
*/
|
|
79
|
+
export declare function GraphAuthKitProvider(props: GraphAuthKitProviderProps): import("react").JSX.Element;
|
|
80
|
+
//# sourceMappingURL=GraphAuthKit.context.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"GraphAuthKit.context.d.ts","sourceRoot":"","sources":["../src/GraphAuthKit.context.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAuB,MAAM,uBAAuB,CAAA;AACxE,OAAO,EAAiB,KAAK,SAAS,EAAc,MAAM,OAAO,CAAA;AASjE,OAAO,EAAE,KAAK,iBAAiB,EAAE,MAAM,SAAS,CAAA;AAGhD,MAAM,MAAM,iBAAiB,GAAG;IAC9B,2FAA2F;IAC3F,gBAAgB,CAAC,KAAK,CAAC,EAAE;QAAE,KAAK,CAAC,EAAE,SAAS,CAAC;QAAC,QAAQ,CAAC,EAAE,SAAS,CAAC;QAAC,eAAe,CAAC,EAAE,MAAM,CAAA;KAAE,GAAG,IAAI,CAAA;IACrG,4CAA4C;IAC5C,iBAAiB,IAAI,IAAI,CAAA;IACzB,4FAA4F;IAC5F,UAAU,IAAI,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;CACnC,CAAA;AAED,eAAO,MAAM,mBAAmB,4CAI9B,CAAA;AAEF,wBAAgB,eAAe,sBAE9B;AAED,MAAM,MAAM,yBAAyB,GAAG,iBAAiB,GAAG;IAC1D;;;OAGG;IACH,WAAW,CAAC,EAAE,WAAW,CAAA;IACzB;;OAEG;IACH,kBAAkB,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;CACnC,GAAG,QAAQ,CAAC;IAAE,QAAQ,EAAE,SAAS,CAAA;CAAE,CAAC,CAAA;AACrC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+CG;AACH,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,yBAAyB,+BAuEpE"}
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import { type Dispatch, type ReactNode } from 'react';
|
|
2
|
+
import { type Address } from 'viem';
|
|
3
|
+
import { z } from 'zod';
|
|
4
|
+
import { type SignerError } from './errors';
|
|
5
|
+
import { SafeSupportedNetworks } from './safe';
|
|
6
|
+
import { GraphAuthKitConnector, type RequiredInfuraKey } from './types';
|
|
7
|
+
export declare const GraphAuthKitModalState: readonly ["primary", "safe_entry", "safe_eoa_signer"];
|
|
8
|
+
export type GraphAuthKitModalState = (typeof GraphAuthKitModalState)[number];
|
|
9
|
+
export declare const MultisigSchema: z.ZodObject<{
|
|
10
|
+
network: z.ZodType<1 | 11155111 | 42161, z.ZodTypeDef, 1 | 11155111 | 42161>;
|
|
11
|
+
address: z.ZodString;
|
|
12
|
+
enteredSafeIsValid: z.ZodOptional<z.ZodBoolean>;
|
|
13
|
+
}, "strip", z.ZodTypeAny, {
|
|
14
|
+
address: string;
|
|
15
|
+
network: 1 | 11155111 | 42161;
|
|
16
|
+
enteredSafeIsValid?: boolean | undefined;
|
|
17
|
+
}, {
|
|
18
|
+
address: string;
|
|
19
|
+
network: 1 | 11155111 | 42161;
|
|
20
|
+
enteredSafeIsValid?: boolean | undefined;
|
|
21
|
+
}>;
|
|
22
|
+
export type MultisigSchema = z.infer<typeof MultisigSchema>;
|
|
23
|
+
export type GraphAuthKitInnerState = {
|
|
24
|
+
/** Infura key passed down from the top-level provider/app */
|
|
25
|
+
_infuraKey: RequiredInfuraKey['infuraKey'];
|
|
26
|
+
/** The ConnectModal open state */
|
|
27
|
+
_connectModalOpen: boolean;
|
|
28
|
+
/** Open/close the ConnectModal */
|
|
29
|
+
_setConnectModalOpen: Dispatch<boolean>;
|
|
30
|
+
/**
|
|
31
|
+
* The ConnectModal title to display.
|
|
32
|
+
* @default "Connect your wallet"
|
|
33
|
+
*/
|
|
34
|
+
_modalTitle: ReactNode;
|
|
35
|
+
_setModalTitle: Dispatch<ReactNode>;
|
|
36
|
+
/** The ConnectModal subtitle to display */
|
|
37
|
+
_modalSubtitle?: ReactNode;
|
|
38
|
+
_setModalSubtitle: Dispatch<ReactNode | undefined>;
|
|
39
|
+
/**
|
|
40
|
+
* Which Wallet connect options to display based off the current ConnectModal state.
|
|
41
|
+
* - 'primary' -> display the primary wallet connect options
|
|
42
|
+
* - 'safe_entry' -> the user selected to connect via their Safe multisig. Display the multisig entry form
|
|
43
|
+
* - 'safe_eoa_signer' -> let the user connect their EoA that is a signer on their entered safe
|
|
44
|
+
* @default primary
|
|
45
|
+
*/
|
|
46
|
+
_modalState: GraphAuthKitModalState;
|
|
47
|
+
/** Set the current modal state of which page in the modal to display */
|
|
48
|
+
_setModalState: Dispatch<GraphAuthKitModalState>;
|
|
49
|
+
/**
|
|
50
|
+
* If the user is authenticating with a Safe, this is the entered Safe information.
|
|
51
|
+
* @default null
|
|
52
|
+
*/
|
|
53
|
+
_enteredMultisigInfo?: MultisigSchema;
|
|
54
|
+
_setSafeInfo: Dispatch<MultisigSchema | undefined>;
|
|
55
|
+
/**
|
|
56
|
+
* The user has selected a Wallet connector option and is currently authenticating.
|
|
57
|
+
* If true, displays a loading indicator in the modal
|
|
58
|
+
*/
|
|
59
|
+
_authenticating: boolean;
|
|
60
|
+
_setAuthenticating: Dispatch<boolean>;
|
|
61
|
+
/** The user-selected Wallet connector. */
|
|
62
|
+
_connector?: GraphAuthKitConnector;
|
|
63
|
+
/** If the connection fails, display the error message */
|
|
64
|
+
_connectFailureMessage?: SignerError;
|
|
65
|
+
/** Takes the wallet connector the user selected in the modal and connects the user to the wagmi context */
|
|
66
|
+
_connect(connector: GraphAuthKitConnector): void | Promise<void>;
|
|
67
|
+
/**
|
|
68
|
+
* If the user is connecting via a Safe multisig, take their EoA signer, connect it,
|
|
69
|
+
* and connect the Safe instance to the wagmi context.
|
|
70
|
+
*/
|
|
71
|
+
_connectMultisig(params: {
|
|
72
|
+
connector: GraphAuthKitConnector;
|
|
73
|
+
network: SafeSupportedNetworks;
|
|
74
|
+
address: Address;
|
|
75
|
+
}): void | Promise<void>;
|
|
76
|
+
/** The user has disconnected their wallet. Reset the state. */
|
|
77
|
+
_reset(): void;
|
|
78
|
+
};
|
|
79
|
+
export declare const defInnerState: {
|
|
80
|
+
readonly _infuraKey: "";
|
|
81
|
+
readonly _connectModalOpen: false;
|
|
82
|
+
readonly _setConnectModalOpen: () => void;
|
|
83
|
+
readonly _modalTitle: "Connect your wallet";
|
|
84
|
+
readonly _setModalTitle: () => void;
|
|
85
|
+
readonly _setModalSubtitle: () => void;
|
|
86
|
+
readonly _modalState: "primary";
|
|
87
|
+
readonly _setModalState: () => void;
|
|
88
|
+
readonly _setSafeInfo: () => void;
|
|
89
|
+
readonly _authenticating: false;
|
|
90
|
+
readonly _setAuthenticating: () => void;
|
|
91
|
+
readonly _connect: () => void;
|
|
92
|
+
readonly _connectMultisig: () => void;
|
|
93
|
+
readonly _reset: () => void;
|
|
94
|
+
};
|
|
95
|
+
export declare const GraphAuthKitInnerContext: import("react").Context<GraphAuthKitInnerState>;
|
|
96
|
+
/**
|
|
97
|
+
* We expose a minimal GraphAuthKit context state exported from this library.
|
|
98
|
+
* That way the implementer only uses the `useGraphAuthKit` hook to open/close the connect modal.
|
|
99
|
+
* Wagmi hooks should be used for all other wagmi connected auth state.
|
|
100
|
+
* This hook is not exported from this library, but is used in the ConnectModal internals
|
|
101
|
+
* to control the state of the modal itself.
|
|
102
|
+
*/
|
|
103
|
+
export declare function useGraphAuthKitInnerContext(): GraphAuthKitInnerState;
|
|
104
|
+
export type GraphAuthKitInnerContextProviderProps = Readonly<{
|
|
105
|
+
infuraKey: RequiredInfuraKey['infuraKey'];
|
|
106
|
+
children: ReactNode;
|
|
107
|
+
}>;
|
|
108
|
+
export declare function GraphAuthKitInnerContextProvider({ infuraKey, children }: GraphAuthKitInnerContextProviderProps): import("react").JSX.Element;
|
|
109
|
+
//# sourceMappingURL=GraphAuthKitInner.context.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"GraphAuthKitInner.context.d.ts","sourceRoot":"","sources":["../src/GraphAuthKitInner.context.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAiB,KAAK,QAAQ,EAAE,KAAK,SAAS,EAAgC,MAAM,OAAO,CAAA;AAClG,OAAO,EAAE,KAAK,OAAO,EAAa,MAAM,MAAM,CAAA;AAG9C,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAIvB,OAAO,EAAoB,KAAK,WAAW,EAAE,MAAM,UAAU,CAAA;AAC7D,OAAO,EAAe,qBAAqB,EAAE,MAAM,QAAQ,CAAA;AAC3D,OAAO,EAAE,qBAAqB,EAAE,KAAK,iBAAiB,EAAE,MAAM,SAAS,CAAA;AAEvE,eAAO,MAAM,sBAAsB,uDAAwD,CAAA;AAC3F,MAAM,MAAM,sBAAsB,GAAG,CAAC,OAAO,sBAAsB,CAAC,CAAC,MAAM,CAAC,CAAA;AAE5E,eAAO,MAAM,cAAc;;;;;;;;;;;;EAMzB,CAAA;AACF,MAAM,MAAM,cAAc,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,cAAc,CAAC,CAAA;AAE3D,MAAM,MAAM,sBAAsB,GAAG;IACnC,6DAA6D;IAC7D,UAAU,EAAE,iBAAiB,CAAC,WAAW,CAAC,CAAA;IAC1C,kCAAkC;IAClC,iBAAiB,EAA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