@openfort/react 0.0.33 → 0.1.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/build/assets/icons.d.ts +3 -0
- package/build/components/Common/Loading/index.d.ts +1 -1
- package/build/components/Common/Modal/index.d.ts +0 -1
- package/build/components/Common/Modal/styles.d.ts +0 -1
- package/build/components/ConnectModal/ConnectWithInjector/index.d.ts +2 -0
- package/build/components/Openfort/context.d.ts +10 -14
- package/build/components/Openfort/types.d.ts +43 -3
- package/build/components/PageContent/index.d.ts +10 -0
- package/build/components/PageContent/styles.d.ts +1 -0
- package/build/components/Pages/Connected/index.d.ts +2 -0
- package/build/components/Pages/Connectors/index.d.ts +4 -3
- package/build/components/Pages/CreateGuestUserPage/index.d.ts +2 -0
- package/build/components/Pages/CreateWallet/index.d.ts +2 -0
- package/build/components/Pages/LoadWallets/index.d.ts +2 -0
- package/build/components/Pages/SelectWalletToRecover/index.d.ts +2 -0
- package/build/hooks/openfort/useConnectWithSiwe.d.ts +2 -1
- package/build/hooks/openfort/useExtendedWalletClient.d.ts +389 -0
- package/build/hooks/openfort/useGrantPermissions.d.ts +107 -0
- package/build/hooks/usePrevious.d.ts +1 -1
- package/build/hooks/useRouteProps.d.ts +35 -0
- package/build/index.d.ts +2 -1
- package/build/index.es.js +3514 -3092
- package/build/index.es.js.map +1 -1
- package/build/version.d.ts +1 -1
- package/package.json +2 -2
- /package/build/components/Pages/{Recover → CreateWallet}/styles.d.ts +0 -0
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import type { Hex } from 'viem';
|
|
2
|
+
import type { GrantPermissionsParameters, GrantPermissionsReturnType } from 'viem/experimental';
|
|
3
|
+
import { OpenfortError, type OpenfortHookOptions } from '../../types';
|
|
4
|
+
type GrantPermissionsRequest = {
|
|
5
|
+
request: GrantPermissionsParameters;
|
|
6
|
+
sessionKey: Hex;
|
|
7
|
+
};
|
|
8
|
+
type GrantPermissionsResult = {
|
|
9
|
+
address: `0x${string}`;
|
|
10
|
+
privateKey: `0x${string}`;
|
|
11
|
+
} & GrantPermissionsReturnType;
|
|
12
|
+
type GrantPermissionsHookResult = {
|
|
13
|
+
error?: OpenfortError;
|
|
14
|
+
} & Partial<GrantPermissionsResult>;
|
|
15
|
+
type GrantPermissionsHookOptions = OpenfortHookOptions<GrantPermissionsHookResult>;
|
|
16
|
+
/**
|
|
17
|
+
* Hook for granting permissions to session keys (EIP-7715)
|
|
18
|
+
*
|
|
19
|
+
* This hook manages the creation and authorization of session keys, allowing users to
|
|
20
|
+
* delegate permissions to specific accounts for a limited time. This enables use cases
|
|
21
|
+
* like session-based authentication and gasless transactions within defined scopes.
|
|
22
|
+
* The hook leverages EIP-7715 for permission granting.
|
|
23
|
+
*
|
|
24
|
+
* @param hookOptions - Optional configuration with callback functions
|
|
25
|
+
* @returns Current grant permissions state and actions
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
* ```tsx
|
|
29
|
+
* import { generatePrivateKey, privateKeyToAccount } from 'viem/accounts';
|
|
30
|
+
* import { useGrantPermissions } from '@openfort/openfort-react';
|
|
31
|
+
*
|
|
32
|
+
* const { grantPermissions, isLoading, isError, error } = useGrantPermissions({
|
|
33
|
+
* onSuccess: (result) => console.log('Permissions granted:', result),
|
|
34
|
+
* onError: (error) => console.error('Permission grant failed:', error),
|
|
35
|
+
* });
|
|
36
|
+
*
|
|
37
|
+
* // Grant permissions to a session key
|
|
38
|
+
* const handleGrantPermissions = async () => {
|
|
39
|
+
* try {
|
|
40
|
+
* // Generate a new session key
|
|
41
|
+
* const sessionKey = generatePrivateKey();
|
|
42
|
+
* const accountSession = privateKeyToAccount(sessionKey).address;
|
|
43
|
+
*
|
|
44
|
+
* const result = await grantPermissions({
|
|
45
|
+
* sessionKey,
|
|
46
|
+
* request: {
|
|
47
|
+
* signer: {
|
|
48
|
+
* type: 'account',
|
|
49
|
+
* data: {
|
|
50
|
+
* id: accountSession,
|
|
51
|
+
* },
|
|
52
|
+
* },
|
|
53
|
+
* expiry: 60 * 60 * 24, // 24 hours
|
|
54
|
+
* permissions: [
|
|
55
|
+
* {
|
|
56
|
+
* type: 'contract-call',
|
|
57
|
+
* data: {
|
|
58
|
+
* address: '0x2522f4fc9af2e1954a3d13f7a5b2683a00a4543a',
|
|
59
|
+
* },
|
|
60
|
+
* },
|
|
61
|
+
* ],
|
|
62
|
+
* },
|
|
63
|
+
* });
|
|
64
|
+
*
|
|
65
|
+
* if (result.address) {
|
|
66
|
+
* console.log('Session created with address:', result.address);
|
|
67
|
+
* console.log('Session private key:', result.privateKey);
|
|
68
|
+
* }
|
|
69
|
+
* } catch (error) {
|
|
70
|
+
* console.error('Failed to grant permissions:', error);
|
|
71
|
+
* }
|
|
72
|
+
* };
|
|
73
|
+
*
|
|
74
|
+
* // Check permission grant state
|
|
75
|
+
* if (isLoading) {
|
|
76
|
+
* console.log('Granting permissions...');
|
|
77
|
+
* } else if (isError) {
|
|
78
|
+
* console.error('Permission grant error:', error);
|
|
79
|
+
* }
|
|
80
|
+
*
|
|
81
|
+
* // Example usage in component
|
|
82
|
+
* return (
|
|
83
|
+
* <div>
|
|
84
|
+
* <button
|
|
85
|
+
* onClick={handleGrantPermissions}
|
|
86
|
+
* disabled={isLoading}
|
|
87
|
+
* >
|
|
88
|
+
* {isLoading ? 'Granting Permissions...' : 'Create Session'}
|
|
89
|
+
* </button>
|
|
90
|
+
*
|
|
91
|
+
* {isError && (
|
|
92
|
+
* <p>Error: {error?.message}</p>
|
|
93
|
+
* )}
|
|
94
|
+
* </div>
|
|
95
|
+
* );
|
|
96
|
+
* ```
|
|
97
|
+
*/
|
|
98
|
+
export declare const useGrantPermissions: (hookOptions?: GrantPermissionsHookOptions) => {
|
|
99
|
+
isLoading: boolean;
|
|
100
|
+
isError: boolean;
|
|
101
|
+
isSuccess: boolean;
|
|
102
|
+
error: OpenfortError | null | undefined;
|
|
103
|
+
grantPermissions: ({ request, sessionKey }: GrantPermissionsRequest, options?: GrantPermissionsHookOptions) => Promise<GrantPermissionsHookResult>;
|
|
104
|
+
data: GrantPermissionsResult | null;
|
|
105
|
+
reset: () => void;
|
|
106
|
+
};
|
|
107
|
+
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export default function usePrevious(value:
|
|
1
|
+
export default function usePrevious<T>(value: T, initial: T): T;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { RouteOptions } from '../components/Openfort/types';
|
|
2
|
+
export declare const useRouteProps: <T extends RouteOptions["route"]>(currentRoute: T) => Extract<import("../components/Openfort/types").RoutesWithoutOptions, {
|
|
3
|
+
route: T;
|
|
4
|
+
}> | Extract<{
|
|
5
|
+
route: "connectors";
|
|
6
|
+
} & {
|
|
7
|
+
connectType: "link" | "connect" | "linkIfUserConnectIfNoUser";
|
|
8
|
+
}, {
|
|
9
|
+
route: T;
|
|
10
|
+
}> | Extract<{
|
|
11
|
+
route: "connectors";
|
|
12
|
+
} & {
|
|
13
|
+
connectType: "recover";
|
|
14
|
+
wallet: import("..").UserWallet;
|
|
15
|
+
}, {
|
|
16
|
+
route: T;
|
|
17
|
+
}> | Extract<{
|
|
18
|
+
route: "connect";
|
|
19
|
+
} & {
|
|
20
|
+
connectType: "link" | "connect" | "linkIfUserConnectIfNoUser";
|
|
21
|
+
}, {
|
|
22
|
+
route: T;
|
|
23
|
+
}> | Extract<{
|
|
24
|
+
route: "connect";
|
|
25
|
+
} & {
|
|
26
|
+
connectType: "recover";
|
|
27
|
+
wallet: import("..").UserWallet;
|
|
28
|
+
}, {
|
|
29
|
+
route: T;
|
|
30
|
+
}> | Extract<{
|
|
31
|
+
route: "recoverWallets";
|
|
32
|
+
wallet: import("..").UserWallet;
|
|
33
|
+
}, {
|
|
34
|
+
route: T;
|
|
35
|
+
}>;
|
package/build/index.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ export { default as Avatar } from './components/Common/Avatar';
|
|
|
3
3
|
export { default as ChainIcon } from './components/Common/Chain';
|
|
4
4
|
export { OpenfortButton } from './components/ConnectButton';
|
|
5
5
|
export { OpenfortProvider } from './components/Openfort/OpenfortProvider';
|
|
6
|
-
export { UIAuthProvider as AuthProvider } from './components/Openfort/types';
|
|
6
|
+
export { LinkWalletOnSignUpOption, UIAuthProvider as AuthProvider } from './components/Openfort/types';
|
|
7
7
|
export { embeddedWalletId } from './constants/openfort';
|
|
8
8
|
export { default as getDefaultConfig } from './defaultConfig';
|
|
9
9
|
export { default as getDefaultConnectors } from './defaultConnectors';
|
|
@@ -15,6 +15,7 @@ export { useSignOut } from './hooks/openfort/auth/useSignOut';
|
|
|
15
15
|
export { useWalletAuth } from './hooks/openfort/auth/useWalletAuth';
|
|
16
16
|
export { type SignAuthorizationParameters, type SignAuthorizationReturnType, use7702Authorization, } from './hooks/openfort/use7702Authorization';
|
|
17
17
|
export { useConnectWithSiwe } from './hooks/openfort/useConnectWithSiwe';
|
|
18
|
+
export { useGrantPermissions } from './hooks/openfort/useGrantPermissions';
|
|
18
19
|
export { useUI } from './hooks/openfort/useUI';
|
|
19
20
|
export { useUser } from './hooks/openfort/useUser';
|
|
20
21
|
export { UserWallet, useWallets } from './hooks/openfort/useWallets';
|