@lit-protocol/vincent-app-sdk 2.1.0 → 2.2.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.
- package/CHANGELOG.md +17 -0
- package/dist/CHANGELOG.md +10 -0
- package/dist/package.json +16 -1
- package/dist/src/jwt/types.d.ts +10 -8
- package/dist/src/jwt/types.d.ts.map +1 -1
- package/dist/src/react/index.d.ts +31 -0
- package/dist/src/react/index.d.ts.map +1 -0
- package/dist/src/react/index.js +34 -0
- package/dist/src/react/index.js.map +1 -0
- package/dist/src/react/jwtProvider.d.ts +166 -0
- package/dist/src/react/jwtProvider.d.ts.map +1 -0
- package/dist/src/react/jwtProvider.js +223 -0
- package/dist/src/react/jwtProvider.js.map +1 -0
- package/dist/src/react/useVincentWebAuthClient.d.ts +46 -0
- package/dist/src/react/useVincentWebAuthClient.d.ts.map +1 -0
- package/dist/src/react/useVincentWebAuthClient.js +54 -0
- package/dist/src/react/useVincentWebAuthClient.js.map +1 -0
- package/package.json +18 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,20 @@
|
|
|
1
|
+
## 2.2.1 (2025-09-25)
|
|
2
|
+
|
|
3
|
+
### 🧱 Updated Dependencies
|
|
4
|
+
|
|
5
|
+
- Updated ability-sdk to 2.2.0
|
|
6
|
+
- Updated contracts-sdk to 1.3.0
|
|
7
|
+
|
|
8
|
+
## 2.2.0 (2025-09-18)
|
|
9
|
+
|
|
10
|
+
### 🚀 Features
|
|
11
|
+
|
|
12
|
+
- Add React components implementing common patterns consumers will use for jwt management ([40e984ba](https://github.com/LIT-Protocol/Vincent/commit/40e984ba))
|
|
13
|
+
|
|
14
|
+
### ❤️ Thank You
|
|
15
|
+
|
|
16
|
+
- FedericoAmura @FedericoAmura
|
|
17
|
+
|
|
1
18
|
## 2.1.0 (2025-09-11)
|
|
2
19
|
|
|
3
20
|
### 🚀 Features
|
package/dist/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,13 @@
|
|
|
1
|
+
## 2.2.0 (2025-09-18)
|
|
2
|
+
|
|
3
|
+
### 🚀 Features
|
|
4
|
+
|
|
5
|
+
- Add React components implementing common patterns consumers will use for jwt management ([40e984ba](https://github.com/LIT-Protocol/Vincent/commit/40e984ba))
|
|
6
|
+
|
|
7
|
+
### ❤️ Thank You
|
|
8
|
+
|
|
9
|
+
- FedericoAmura @FedericoAmura
|
|
10
|
+
|
|
1
11
|
## 2.1.0 (2025-09-11)
|
|
2
12
|
|
|
3
13
|
### 🚀 Features
|
package/dist/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lit-protocol/vincent-app-sdk",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.2.0",
|
|
4
4
|
"description": "Vincent SDK for browser and backend",
|
|
5
5
|
"author": "Lit Protocol",
|
|
6
6
|
"license": "ISC",
|
|
@@ -39,6 +39,11 @@
|
|
|
39
39
|
"import": "./dist/src/utils/index.js",
|
|
40
40
|
"require": "./dist/src/utils/index.js",
|
|
41
41
|
"types": "./dist/src/utils/index.d.ts"
|
|
42
|
+
},
|
|
43
|
+
"./react": {
|
|
44
|
+
"import": "./dist/src/react/index.js",
|
|
45
|
+
"require": "./dist/src/react/index.js",
|
|
46
|
+
"types": "./dist/src/react/index.d.ts"
|
|
42
47
|
}
|
|
43
48
|
},
|
|
44
49
|
"keywords": [
|
|
@@ -62,6 +67,14 @@
|
|
|
62
67
|
"tslib": "^2.8.1",
|
|
63
68
|
"zod": "3.25.64"
|
|
64
69
|
},
|
|
70
|
+
"peerDependencies": {
|
|
71
|
+
"react": "^19.0.0"
|
|
72
|
+
},
|
|
73
|
+
"peerDependenciesMeta": {
|
|
74
|
+
"react": {
|
|
75
|
+
"optional": true
|
|
76
|
+
}
|
|
77
|
+
},
|
|
65
78
|
"sideEffects": false,
|
|
66
79
|
"files": [
|
|
67
80
|
"dist/**/*",
|
|
@@ -71,8 +84,10 @@
|
|
|
71
84
|
"@lit-protocol/pkp-ethers": "^7.2.3",
|
|
72
85
|
"@lit-protocol/types": "^7.2.3",
|
|
73
86
|
"@types/express": "^5.0.1",
|
|
87
|
+
"@types/react": "^19.0.10",
|
|
74
88
|
"chokidar-cli": "^3.0.0",
|
|
75
89
|
"live-server": "^1.2.2",
|
|
90
|
+
"react": "^19.0.0",
|
|
76
91
|
"typedoc": "0.27.9",
|
|
77
92
|
"typedoc-material-theme": "1.3.0",
|
|
78
93
|
"typedoc-plugin-extras": "^4.0.0",
|
package/dist/src/jwt/types.d.ts
CHANGED
|
@@ -69,6 +69,14 @@ export interface PKPAuthenticationMethod {
|
|
|
69
69
|
type: string;
|
|
70
70
|
value?: string;
|
|
71
71
|
}
|
|
72
|
+
/**
|
|
73
|
+
*
|
|
74
|
+
* @category Interfaces
|
|
75
|
+
*/
|
|
76
|
+
export interface AppInfo {
|
|
77
|
+
id: number;
|
|
78
|
+
version: number;
|
|
79
|
+
}
|
|
72
80
|
/** All valid Vincent JWT roles
|
|
73
81
|
*
|
|
74
82
|
* @category Interfaces
|
|
@@ -98,10 +106,7 @@ export interface VincentJWTPlatformUser extends DecodedJWT {
|
|
|
98
106
|
export interface VincentJWTAppUser extends DecodedJWT {
|
|
99
107
|
payload: VincentPKPPayload & {
|
|
100
108
|
role: 'app-user';
|
|
101
|
-
app:
|
|
102
|
-
id: number;
|
|
103
|
-
version: number;
|
|
104
|
-
};
|
|
109
|
+
app: AppInfo;
|
|
105
110
|
};
|
|
106
111
|
}
|
|
107
112
|
/**
|
|
@@ -139,10 +144,7 @@ export type CreatePlatformUserJWTParams = VincentPKPJWTParams;
|
|
|
139
144
|
* @category Interfaces
|
|
140
145
|
*/
|
|
141
146
|
export interface CreateAppUserJWTParams extends VincentPKPJWTParams {
|
|
142
|
-
app:
|
|
143
|
-
id: number;
|
|
144
|
-
version: number;
|
|
145
|
-
};
|
|
147
|
+
app: AppInfo;
|
|
146
148
|
}
|
|
147
149
|
/**
|
|
148
150
|
*
|
|
@@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pB,IAAI,EAAE,eAAe,CAAC;QACtB,GAAG,CAAC,EAAE,KAAK,MAAM,EAAE,CAAC;KACrB,CAAC;CACH;AAED;;;GAGG;AACH,MAAM,MAAM,aAAa,GAAG,sBAAsB,GAAG,iBAAiB,GAAG,mBAAmB,CAAC;AAE7F,UAAU,aAAa;IACrB,OAAO,CAAC,EAAE,+BAA+B,CAAC;IAC1C,QAAQ,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;IAC5B,gBAAgB,EAAE,MAAM,CAAC;CAC1B;AAED,UAAU,mBAAoB,SAAQ,aAAa;IACjD,SAAS,EAAE,eAAe,CAAC;IAC3B,OAAO,EAAE,SAAS,CAAC;IACnB,cAAc,EAAE,uBAAuB,CAAC;CACzC;AAED;;;GAGG;AACH,MAAM,MAAM,2BAA2B,GAAG,mBAAmB,CAAC;AAE9D;;;GAGG;AACH,MAAM,WAAW,sBAAuB,SAAQ,mBAAmB;IACjE,GAAG,EAAE,OAAO,CAAC;CACd;AAED;;;GAGG;AACH,MAAM,WAAW,wBAAyB,SAAQ,aAAa;IAC7D,YAAY,EAAE,MAAM,CAAC;IACrB,cAAc,EAAE,KAAK,MAAM,EAAE,CAAC;CAC/B"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The `react` module provides React-specific utilities and components for Vincent authentication.
|
|
3
|
+
*
|
|
4
|
+
* This module exports:
|
|
5
|
+
* - {@link JwtProvider}: A context provider that manages JWT authentication state
|
|
6
|
+
* - {@link useJwtContext}: A hook to access the JWT authentication context
|
|
7
|
+
* - {@link useVincentWebAuthClient}: A hook to get a memoized Vincent WebAuth client instance
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```tsx
|
|
11
|
+
* import { JwtProvider, useJwtContext } from '@lit-protocol/vincent-app-sdk/react';
|
|
12
|
+
*
|
|
13
|
+
* function App() {
|
|
14
|
+
* return (
|
|
15
|
+
* <JwtProvider appId="your-vincent-app-id">
|
|
16
|
+
* <YourAuthenticatedComponent />
|
|
17
|
+
* </JwtProvider>
|
|
18
|
+
* );
|
|
19
|
+
* }
|
|
20
|
+
*
|
|
21
|
+
* function YourAuthenticatedComponent() {
|
|
22
|
+
* const { authInfo, loading, loginWithJwt, logOut } = useJwtContext();
|
|
23
|
+
* // ... your component logic
|
|
24
|
+
* }
|
|
25
|
+
* ```
|
|
26
|
+
*
|
|
27
|
+
* @packageDocumentation
|
|
28
|
+
*/
|
|
29
|
+
export * from './jwtProvider';
|
|
30
|
+
export * from './useVincentWebAuthClient';
|
|
31
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/react/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AAEH,cAAc,eAAe,CAAC;AAC9B,cAAc,2BAA2B,CAAC"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* The `react` module provides React-specific utilities and components for Vincent authentication.
|
|
4
|
+
*
|
|
5
|
+
* This module exports:
|
|
6
|
+
* - {@link JwtProvider}: A context provider that manages JWT authentication state
|
|
7
|
+
* - {@link useJwtContext}: A hook to access the JWT authentication context
|
|
8
|
+
* - {@link useVincentWebAuthClient}: A hook to get a memoized Vincent WebAuth client instance
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```tsx
|
|
12
|
+
* import { JwtProvider, useJwtContext } from '@lit-protocol/vincent-app-sdk/react';
|
|
13
|
+
*
|
|
14
|
+
* function App() {
|
|
15
|
+
* return (
|
|
16
|
+
* <JwtProvider appId="your-vincent-app-id">
|
|
17
|
+
* <YourAuthenticatedComponent />
|
|
18
|
+
* </JwtProvider>
|
|
19
|
+
* );
|
|
20
|
+
* }
|
|
21
|
+
*
|
|
22
|
+
* function YourAuthenticatedComponent() {
|
|
23
|
+
* const { authInfo, loading, loginWithJwt, logOut } = useJwtContext();
|
|
24
|
+
* // ... your component logic
|
|
25
|
+
* }
|
|
26
|
+
* ```
|
|
27
|
+
*
|
|
28
|
+
* @packageDocumentation
|
|
29
|
+
*/
|
|
30
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
31
|
+
const tslib_1 = require("tslib");
|
|
32
|
+
tslib_1.__exportStar(require("./jwtProvider"), exports);
|
|
33
|
+
tslib_1.__exportStar(require("./useVincentWebAuthClient"), exports);
|
|
34
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/react/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;;;AAEH,wDAA8B;AAC9B,oEAA0C"}
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
import type { JSX, ReactNode } from 'react';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import type { IRelayPKP } from '@lit-protocol/types';
|
|
4
|
+
import type { AppInfo, PKPAuthenticationMethod } from '../jwt/types';
|
|
5
|
+
/**
|
|
6
|
+
* Interface representing the authenticated user information.
|
|
7
|
+
*
|
|
8
|
+
* Contains details about the application, authentication method, JWT token,
|
|
9
|
+
* and the PKP (Programmable Key Pair) associated with the authenticated user.
|
|
10
|
+
*/
|
|
11
|
+
export interface AuthInfo {
|
|
12
|
+
app: AppInfo;
|
|
13
|
+
authentication: PKPAuthenticationMethod;
|
|
14
|
+
jwt: string;
|
|
15
|
+
pkp: IRelayPKP;
|
|
16
|
+
}
|
|
17
|
+
interface JwtContextType {
|
|
18
|
+
authInfo: AuthInfo | null;
|
|
19
|
+
loading: boolean;
|
|
20
|
+
connect: (redirectUri: string) => void;
|
|
21
|
+
loginWithJwt: () => void;
|
|
22
|
+
logOut: () => void;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* React Context that exposes JWT authentication state and actions for Vincent apps.
|
|
26
|
+
*
|
|
27
|
+
* This context carries a value of type `JwtContextType` with:
|
|
28
|
+
* - `authInfo`: `AuthInfo | null` — Authenticated user/application information or `null` when not authenticated.
|
|
29
|
+
* - `loading`: `boolean` — Indicates whether an authentication operation (login/logout/validation) is in progress.
|
|
30
|
+
* - `connect(redirectUri: string)`: Redirects the user to the Vincent consent page to initiate authentication.
|
|
31
|
+
* - `loginWithJwt()`: Attempts to retrieve and validate a JWT from Vincent dashboard.
|
|
32
|
+
* - `logOut()`: Removes the stored JWT and resets the authentication state.
|
|
33
|
+
*
|
|
34
|
+
* The provider component `JwtProvider` must wrap your component tree for this context to be available and for
|
|
35
|
+
* `useJwtContext` to work in your components.
|
|
36
|
+
*
|
|
37
|
+
* @example
|
|
38
|
+
* ```tsx
|
|
39
|
+
* <JwtProvider appId={123}>
|
|
40
|
+
* <App />
|
|
41
|
+
* </JwtProvider>
|
|
42
|
+
* ```
|
|
43
|
+
*
|
|
44
|
+
* @see JwtProvider
|
|
45
|
+
* @see useJwtContext
|
|
46
|
+
*/
|
|
47
|
+
export declare const JwtContext: React.Context<JwtContextType>;
|
|
48
|
+
/**
|
|
49
|
+
* React hook to access the JWT authentication context.
|
|
50
|
+
*
|
|
51
|
+
* This hook provides access to authentication state and methods for managing JWT-based
|
|
52
|
+
* authentication in Vincent applications. It must be used within a component that is a
|
|
53
|
+
* descendant of JwtProvider.
|
|
54
|
+
*
|
|
55
|
+
* @example
|
|
56
|
+
* ```tsx
|
|
57
|
+
* import { useJwtContext } from '@lit-protocol/vincent-app-sdk/react';
|
|
58
|
+
*
|
|
59
|
+
* function AuthenticatedComponent() {
|
|
60
|
+
* const { authInfo, loading, loginWithJwt, logOut } = useJwtContext();
|
|
61
|
+
*
|
|
62
|
+
* if (loading) {
|
|
63
|
+
* return <div>Loading authentication...</div>;
|
|
64
|
+
* }
|
|
65
|
+
*
|
|
66
|
+
* if (!authInfo) {
|
|
67
|
+
* return (
|
|
68
|
+
* <button onClick={loginWithJwt}>
|
|
69
|
+
* Login
|
|
70
|
+
* </button>
|
|
71
|
+
* );
|
|
72
|
+
* }
|
|
73
|
+
*
|
|
74
|
+
* return (
|
|
75
|
+
* <div>
|
|
76
|
+
* <p>Logged in with PKP: {authInfo.pkp.ethAddress}</p>
|
|
77
|
+
* <button onClick={logOut}>Logout</button>
|
|
78
|
+
* </div>
|
|
79
|
+
* );
|
|
80
|
+
* }
|
|
81
|
+
* ```
|
|
82
|
+
*
|
|
83
|
+
* @returns The JWT context containing authentication state and methods
|
|
84
|
+
*
|
|
85
|
+
* @see JwtContext
|
|
86
|
+
* @see JwtProvider
|
|
87
|
+
*/
|
|
88
|
+
export declare function useJwtContext(): JwtContextType;
|
|
89
|
+
/**
|
|
90
|
+
* Interface for storage providers that can be used with JwtProvider.
|
|
91
|
+
*
|
|
92
|
+
* This allows you to use custom storage solutions (like AsyncStorage in React Native)
|
|
93
|
+
* instead of the default localStorage.
|
|
94
|
+
*/
|
|
95
|
+
export interface AsyncStorage {
|
|
96
|
+
getItem: (key: string) => Promise<string | null> | string | null;
|
|
97
|
+
setItem: (key: string, value: string) => Promise<void> | void;
|
|
98
|
+
removeItem: (key: string) => Promise<void> | void;
|
|
99
|
+
}
|
|
100
|
+
interface JwtProviderProps {
|
|
101
|
+
children: ReactNode;
|
|
102
|
+
appId: number;
|
|
103
|
+
storage?: AsyncStorage;
|
|
104
|
+
storageKeyBuilder?: (appId: number) => string;
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* React component that provides JWT authentication capabilities for Vincent applications.
|
|
108
|
+
*
|
|
109
|
+
* The JwtProvider handles JWT token management, including
|
|
110
|
+
* - Retrieving and validating JWTs from the Vincent consent page
|
|
111
|
+
* - Storing and retrieving JWTs from persistent storage
|
|
112
|
+
* - Providing authentication state and methods to child components
|
|
113
|
+
* - Managing login/logout flows
|
|
114
|
+
*
|
|
115
|
+
* It uses the Context API to make authentication information and methods available
|
|
116
|
+
* throughout your application without prop drilling.
|
|
117
|
+
*
|
|
118
|
+
* @example
|
|
119
|
+
* ```tsx
|
|
120
|
+
* import { JwtProvider } from '@lit-protocol/vincent-app-sdk/react';
|
|
121
|
+
*
|
|
122
|
+
* function App() {
|
|
123
|
+
* return (
|
|
124
|
+
* <JwtProvider appId=<YOUR_VINCENT_APP_ID>>
|
|
125
|
+
* <YourApplication />
|
|
126
|
+
* </JwtProvider>
|
|
127
|
+
* );
|
|
128
|
+
* }
|
|
129
|
+
*
|
|
130
|
+
* // In a child component:
|
|
131
|
+
* function LoginButton() {
|
|
132
|
+
* const { authInfo, loading, connect, logOut } = useJwtContext();
|
|
133
|
+
*
|
|
134
|
+
* if (loading) return <div>Loading...</div>;
|
|
135
|
+
*
|
|
136
|
+
* if (authInfo) {
|
|
137
|
+
* return (
|
|
138
|
+
* <div>
|
|
139
|
+
* <p>Logged in as: {authInfo.pkp.ethAddress}</p>
|
|
140
|
+
* <button onClick={logOut}>Log out</button>
|
|
141
|
+
* </div>
|
|
142
|
+
* );
|
|
143
|
+
* }
|
|
144
|
+
*
|
|
145
|
+
* return (
|
|
146
|
+
* <button
|
|
147
|
+
* onClick={() => connect(window.location.href)}
|
|
148
|
+
* >
|
|
149
|
+
* Login with Vincent
|
|
150
|
+
* </button>
|
|
151
|
+
* );
|
|
152
|
+
* }
|
|
153
|
+
* ```
|
|
154
|
+
*
|
|
155
|
+
* @param props - Props for the JwtProvider component
|
|
156
|
+
* @param props.children - Child components that will have access to the JWT context
|
|
157
|
+
* @param props.appId - Your Vincent App Id
|
|
158
|
+
* @param props.storage - Optional custom storage implementation (defaults to localStorage)
|
|
159
|
+
* @param props.storageKeyBuilder - Optional function to customize the storage key for JWT tokens
|
|
160
|
+
*
|
|
161
|
+
* @see JwtContext
|
|
162
|
+
* @see useJwtContext
|
|
163
|
+
*/
|
|
164
|
+
export declare const JwtProvider: ({ children, appId, storage, storageKeyBuilder, }: JwtProviderProps) => JSX.Element;
|
|
165
|
+
export {};
|
|
166
|
+
//# sourceMappingURL=jwtProvider.d.ts.map
|
|
@@ -0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CAAC,IAAI,CAAC,GAAG,IAAI,CAAC;CACnD;AAED,UAAU,gBAAgB;IACxB,QAAQ,EAAE,SAAS,CAAC;IACpB,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,CAAC,EAAE,YAAY,CAAC;IACvB,iBAAiB,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,MAAM,CAAC;CAC/C;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAyDG;AACH,eAAO,MAAM,WAAW,GAAI,kDAKzB,gBAAgB,KAAG,GAAG,CAAC,OAgGzB,CAAC"}
|
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.JwtProvider = exports.JwtContext = void 0;
|
|
4
|
+
exports.useJwtContext = useJwtContext;
|
|
5
|
+
const tslib_1 = require("tslib");
|
|
6
|
+
const react_1 = tslib_1.__importStar(require("react"));
|
|
7
|
+
const jwt_1 = require("../jwt");
|
|
8
|
+
const useVincentWebAuthClient_1 = require("./useVincentWebAuthClient");
|
|
9
|
+
function jwtContextNotInitialized() {
|
|
10
|
+
throw new Error('JwtContext must be used within an JwtProvider');
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* React Context that exposes JWT authentication state and actions for Vincent apps.
|
|
14
|
+
*
|
|
15
|
+
* This context carries a value of type `JwtContextType` with:
|
|
16
|
+
* - `authInfo`: `AuthInfo | null` — Authenticated user/application information or `null` when not authenticated.
|
|
17
|
+
* - `loading`: `boolean` — Indicates whether an authentication operation (login/logout/validation) is in progress.
|
|
18
|
+
* - `connect(redirectUri: string)`: Redirects the user to the Vincent consent page to initiate authentication.
|
|
19
|
+
* - `loginWithJwt()`: Attempts to retrieve and validate a JWT from Vincent dashboard.
|
|
20
|
+
* - `logOut()`: Removes the stored JWT and resets the authentication state.
|
|
21
|
+
*
|
|
22
|
+
* The provider component `JwtProvider` must wrap your component tree for this context to be available and for
|
|
23
|
+
* `useJwtContext` to work in your components.
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* ```tsx
|
|
27
|
+
* <JwtProvider appId={123}>
|
|
28
|
+
* <App />
|
|
29
|
+
* </JwtProvider>
|
|
30
|
+
* ```
|
|
31
|
+
*
|
|
32
|
+
* @see JwtProvider
|
|
33
|
+
* @see useJwtContext
|
|
34
|
+
*/
|
|
35
|
+
exports.JwtContext = (0, react_1.createContext)({
|
|
36
|
+
authInfo: null,
|
|
37
|
+
loading: false,
|
|
38
|
+
connect: jwtContextNotInitialized,
|
|
39
|
+
loginWithJwt: jwtContextNotInitialized,
|
|
40
|
+
logOut: jwtContextNotInitialized,
|
|
41
|
+
});
|
|
42
|
+
/**
|
|
43
|
+
* React hook to access the JWT authentication context.
|
|
44
|
+
*
|
|
45
|
+
* This hook provides access to authentication state and methods for managing JWT-based
|
|
46
|
+
* authentication in Vincent applications. It must be used within a component that is a
|
|
47
|
+
* descendant of JwtProvider.
|
|
48
|
+
*
|
|
49
|
+
* @example
|
|
50
|
+
* ```tsx
|
|
51
|
+
* import { useJwtContext } from '@lit-protocol/vincent-app-sdk/react';
|
|
52
|
+
*
|
|
53
|
+
* function AuthenticatedComponent() {
|
|
54
|
+
* const { authInfo, loading, loginWithJwt, logOut } = useJwtContext();
|
|
55
|
+
*
|
|
56
|
+
* if (loading) {
|
|
57
|
+
* return <div>Loading authentication...</div>;
|
|
58
|
+
* }
|
|
59
|
+
*
|
|
60
|
+
* if (!authInfo) {
|
|
61
|
+
* return (
|
|
62
|
+
* <button onClick={loginWithJwt}>
|
|
63
|
+
* Login
|
|
64
|
+
* </button>
|
|
65
|
+
* );
|
|
66
|
+
* }
|
|
67
|
+
*
|
|
68
|
+
* return (
|
|
69
|
+
* <div>
|
|
70
|
+
* <p>Logged in with PKP: {authInfo.pkp.ethAddress}</p>
|
|
71
|
+
* <button onClick={logOut}>Logout</button>
|
|
72
|
+
* </div>
|
|
73
|
+
* );
|
|
74
|
+
* }
|
|
75
|
+
* ```
|
|
76
|
+
*
|
|
77
|
+
* @returns The JWT context containing authentication state and methods
|
|
78
|
+
*
|
|
79
|
+
* @see JwtContext
|
|
80
|
+
* @see JwtProvider
|
|
81
|
+
*/
|
|
82
|
+
function useJwtContext() {
|
|
83
|
+
return (0, react_1.useContext)(exports.JwtContext);
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* React component that provides JWT authentication capabilities for Vincent applications.
|
|
87
|
+
*
|
|
88
|
+
* The JwtProvider handles JWT token management, including
|
|
89
|
+
* - Retrieving and validating JWTs from the Vincent consent page
|
|
90
|
+
* - Storing and retrieving JWTs from persistent storage
|
|
91
|
+
* - Providing authentication state and methods to child components
|
|
92
|
+
* - Managing login/logout flows
|
|
93
|
+
*
|
|
94
|
+
* It uses the Context API to make authentication information and methods available
|
|
95
|
+
* throughout your application without prop drilling.
|
|
96
|
+
*
|
|
97
|
+
* @example
|
|
98
|
+
* ```tsx
|
|
99
|
+
* import { JwtProvider } from '@lit-protocol/vincent-app-sdk/react';
|
|
100
|
+
*
|
|
101
|
+
* function App() {
|
|
102
|
+
* return (
|
|
103
|
+
* <JwtProvider appId=<YOUR_VINCENT_APP_ID>>
|
|
104
|
+
* <YourApplication />
|
|
105
|
+
* </JwtProvider>
|
|
106
|
+
* );
|
|
107
|
+
* }
|
|
108
|
+
*
|
|
109
|
+
* // In a child component:
|
|
110
|
+
* function LoginButton() {
|
|
111
|
+
* const { authInfo, loading, connect, logOut } = useJwtContext();
|
|
112
|
+
*
|
|
113
|
+
* if (loading) return <div>Loading...</div>;
|
|
114
|
+
*
|
|
115
|
+
* if (authInfo) {
|
|
116
|
+
* return (
|
|
117
|
+
* <div>
|
|
118
|
+
* <p>Logged in as: {authInfo.pkp.ethAddress}</p>
|
|
119
|
+
* <button onClick={logOut}>Log out</button>
|
|
120
|
+
* </div>
|
|
121
|
+
* );
|
|
122
|
+
* }
|
|
123
|
+
*
|
|
124
|
+
* return (
|
|
125
|
+
* <button
|
|
126
|
+
* onClick={() => connect(window.location.href)}
|
|
127
|
+
* >
|
|
128
|
+
* Login with Vincent
|
|
129
|
+
* </button>
|
|
130
|
+
* );
|
|
131
|
+
* }
|
|
132
|
+
* ```
|
|
133
|
+
*
|
|
134
|
+
* @param props - Props for the JwtProvider component
|
|
135
|
+
* @param props.children - Child components that will have access to the JWT context
|
|
136
|
+
* @param props.appId - Your Vincent App Id
|
|
137
|
+
* @param props.storage - Optional custom storage implementation (defaults to localStorage)
|
|
138
|
+
* @param props.storageKeyBuilder - Optional function to customize the storage key for JWT tokens
|
|
139
|
+
*
|
|
140
|
+
* @see JwtContext
|
|
141
|
+
* @see useJwtContext
|
|
142
|
+
*/
|
|
143
|
+
const JwtProvider = ({ children, appId, storage = localStorage, storageKeyBuilder = (appId) => `vincent-${appId}-jwt`, }) => {
|
|
144
|
+
const appJwtKey = storageKeyBuilder(appId);
|
|
145
|
+
const vincentWebAppClient = (0, useVincentWebAuthClient_1.useVincentWebAuthClient)(appId);
|
|
146
|
+
const [authInfo, setAuthInfo] = (0, react_1.useState)(null);
|
|
147
|
+
const [loading, setLoading] = (0, react_1.useState)(true);
|
|
148
|
+
const logOut = (0, react_1.useCallback)(async () => {
|
|
149
|
+
try {
|
|
150
|
+
setLoading(true);
|
|
151
|
+
await storage.removeItem(appJwtKey);
|
|
152
|
+
setAuthInfo(null);
|
|
153
|
+
}
|
|
154
|
+
finally {
|
|
155
|
+
setLoading(false);
|
|
156
|
+
}
|
|
157
|
+
}, [appJwtKey, storage]);
|
|
158
|
+
const connect = (0, react_1.useCallback)((redirectUri) => {
|
|
159
|
+
// Redirect to Vincent Auth consent page with appId and version
|
|
160
|
+
vincentWebAppClient.redirectToConnectPage({
|
|
161
|
+
// connectPageUrl: `http://localhost:5173/`,
|
|
162
|
+
redirectUri,
|
|
163
|
+
});
|
|
164
|
+
}, [vincentWebAppClient]);
|
|
165
|
+
const getJwt = (0, react_1.useCallback)(async () => {
|
|
166
|
+
if (vincentWebAppClient.uriContainsVincentJWT()) {
|
|
167
|
+
const jwtResult = await vincentWebAppClient.decodeVincentJWTFromUri(window.location.origin);
|
|
168
|
+
if (!jwtResult) {
|
|
169
|
+
return null;
|
|
170
|
+
}
|
|
171
|
+
const { decodedJWT, jwtStr } = jwtResult;
|
|
172
|
+
await storage.setItem(appJwtKey, jwtStr);
|
|
173
|
+
vincentWebAppClient.removeVincentJWTFromURI();
|
|
174
|
+
return { jwtStr, decodedJWT };
|
|
175
|
+
}
|
|
176
|
+
const existingJwtStr = await storage.getItem(appJwtKey);
|
|
177
|
+
if (!existingJwtStr) {
|
|
178
|
+
return null;
|
|
179
|
+
}
|
|
180
|
+
const decodedJWT = await (0, jwt_1.verifyVincentAppUserJWT)({
|
|
181
|
+
expectedAudience: window.location.origin,
|
|
182
|
+
jwt: existingJwtStr,
|
|
183
|
+
requiredAppId: appId,
|
|
184
|
+
});
|
|
185
|
+
return { jwtStr: existingJwtStr, decodedJWT };
|
|
186
|
+
}, [appJwtKey, storage, vincentWebAppClient]);
|
|
187
|
+
const loginWithJwt = (0, react_1.useCallback)(async () => {
|
|
188
|
+
try {
|
|
189
|
+
setLoading(true);
|
|
190
|
+
const jwtResult = await getJwt();
|
|
191
|
+
if (!jwtResult) {
|
|
192
|
+
throw new Error('Could not get JWT');
|
|
193
|
+
}
|
|
194
|
+
const { decodedJWT, jwtStr } = jwtResult;
|
|
195
|
+
setAuthInfo({
|
|
196
|
+
app: decodedJWT.payload.app,
|
|
197
|
+
authentication: decodedJWT.payload.authentication,
|
|
198
|
+
jwt: jwtStr,
|
|
199
|
+
pkp: decodedJWT.payload.pkpInfo,
|
|
200
|
+
});
|
|
201
|
+
}
|
|
202
|
+
catch (error) {
|
|
203
|
+
console.error(`Error logging in with JWT. Need to relogin: ${error.message}`);
|
|
204
|
+
await logOut();
|
|
205
|
+
}
|
|
206
|
+
finally {
|
|
207
|
+
setLoading(false);
|
|
208
|
+
}
|
|
209
|
+
}, [getJwt, logOut]);
|
|
210
|
+
const value = (0, react_1.useMemo)(() => ({
|
|
211
|
+
authInfo,
|
|
212
|
+
connect,
|
|
213
|
+
loading,
|
|
214
|
+
loginWithJwt,
|
|
215
|
+
logOut,
|
|
216
|
+
}), [authInfo, connect, loading, loginWithJwt, logOut]);
|
|
217
|
+
(0, react_1.useEffect)(() => {
|
|
218
|
+
void loginWithJwt();
|
|
219
|
+
}, [loginWithJwt]);
|
|
220
|
+
return react_1.default.createElement(exports.JwtContext.Provider, { value: value }, children);
|
|
221
|
+
};
|
|
222
|
+
exports.JwtProvider = JwtProvider;
|
|
223
|
+
//# sourceMappingURL=jwtProvider.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"jwtProvider.js","sourceRoot":"","sources":["../../../src/react/jwtProvider.tsx"],"names":[],"mappings":";;;AA2GA,sCAEC;;AA3GD,uDAAoG;AAMpG,gCAAiD;AACjD,uEAAoE;AAuBpE,SAAS,wBAAwB;IAC/B,MAAM,IAAI,KAAK,CAAC,+CAA+C,CAAC,CAAC;AACnE,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACU,QAAA,UAAU,GAAG,IAAA,qBAAa,EAAiB;IACtD,QAAQ,EAAE,IAAI;IACd,OAAO,EAAE,KAAK;IACd,OAAO,EAAE,wBAAwB;IACjC,YAAY,EAAE,wBAAwB;IACtC,MAAM,EAAE,wBAAwB;CACjC,CAAC,CAAC;AAEH;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuCG;AACH,SAAgB,aAAa;IAC3B,OAAO,IAAA,kBAAU,EAAC,kBAAU,CAAC,CAAC;AAChC,CAAC;AAqBD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAyDG;AACI,MAAM,WAAW,GAAG,CAAC,EAC1B,QAAQ,EACR,KAAK,EACL,OAAO,GAAG,YAAY,EACtB,iBAAiB,GAAG,CAAC,KAAK,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AC,+CAAgD,KAAe,CAAC,OAAO,EAAE,CAAC,CAAC;YACzF,MAAM,MAAM,EAAE,CAAC;QACjB,CAAC;gBAAS,CAAC;YACT,UAAU,CAAC,KAAK,CAAC,CAAC;QACpB,CAAC;IACH,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;IAErB,MAAM,KAAK,GAAG,IAAA,eAAO,EACnB,GAAG,EAAE,CAAC,CAAC;QACL,QAAQ;QACR,OAAO;QACP,OAAO;QACP,YAAY;QACZ,MAAM;KACP,CAAC,EACF,CAAC,QAAQ,EAAE,OAAO,EAAE,OAAO,EAAE,YAAY,EAAE,MAAM,CAAC,CACnD,CAAC;IAEF,IAAA,iBAAS,EAAC,GAAG,EAAE;QACb,KAAK,YAAY,EAAE,CAAC;IACtB,CAAC,EAAE,CAAC,YAAY,CAAC,CAAC,CAAC;IAEnB,OAAO,8BAAC,kBAAU,CAAC,QAAQ,IAAC,KAAK,EAAE,KAAK,IAAG,QAAQ,CAAuB,CAAC;AAC7E,CAAC,CAAC;AArGW,QAAA,WAAW,eAqGtB"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* React hook that provides a memoized VincentWebAppClient instance.
|
|
3
|
+
*
|
|
4
|
+
* This hook creates a VincentWebAppClient instance using the provided App ID and memoizes it
|
|
5
|
+
* to prevent unnecessary re-creation of the client on each render. The client is only
|
|
6
|
+
* re-created when the App ID changes.
|
|
7
|
+
*
|
|
8
|
+
* The VincentWebAppClient provides methods for authentication, JWT handling, and redirecting
|
|
9
|
+
* to consent pages in Vincent applications.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```typescript
|
|
13
|
+
* import { useVincentWebAuthClient } from '@lit-protocol/vincent-app-sdk/react';
|
|
14
|
+
*
|
|
15
|
+
* function MyComponent() {
|
|
16
|
+
* // Create a memoized Vincent Web App client
|
|
17
|
+
* const vincentClient = useVincentWebAuthClient('my-app-id');
|
|
18
|
+
*
|
|
19
|
+
* // Check if the user is logging in
|
|
20
|
+
* useEffect(() => {
|
|
21
|
+
* if (vincentClient.isLogin()) {
|
|
22
|
+
* const jwtResult = vincentClient.decodeVincentLoginJWT(window.location.origin);
|
|
23
|
+
* // Handle successful login
|
|
24
|
+
* console.log('User logged in with PKP address:', jwtResult.pkpAddress);
|
|
25
|
+
*
|
|
26
|
+
* // Remove JWT from URI to prevent issues with browser history
|
|
27
|
+
* vincentClient.removeLoginJWTFromURI();
|
|
28
|
+
* }
|
|
29
|
+
* }, [vincentClient]);
|
|
30
|
+
*
|
|
31
|
+
* // Function to handle the login button click
|
|
32
|
+
* const handleLogin = () => {
|
|
33
|
+
* vincentClient.redirectToConsentPage({
|
|
34
|
+
* redirectUri: window.location.href,
|
|
35
|
+
* });
|
|
36
|
+
* };
|
|
37
|
+
*
|
|
38
|
+
* return <button onClick={handleLogin}>Login with Vincent</button>;
|
|
39
|
+
* }
|
|
40
|
+
* ```
|
|
41
|
+
*
|
|
42
|
+
* @param appId - The unique identifier for your Vincent application
|
|
43
|
+
* @returns A memoized VincentWebAppClient instance
|
|
44
|
+
*/
|
|
45
|
+
export declare const useVincentWebAuthClient: (appId: number) => import("../webAuthClient").WebAuthClient;
|
|
46
|
+
//# sourceMappingURL=useVincentWebAuthClient.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useVincentWebAuthClient.d.ts","sourceRoot":"","sources":["../../../src/react/useVincentWebAuthClient.ts"],"names":[],"mappings":"AAIA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2CG;AACH,eAAO,MAAM,uBAAuB,GAAI,OAAO,MAAM,6CAEpD,CAAC"}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useVincentWebAuthClient = void 0;
|
|
4
|
+
const react_1 = require("react");
|
|
5
|
+
const webAuthClient_1 = require("../webAuthClient");
|
|
6
|
+
/**
|
|
7
|
+
* React hook that provides a memoized VincentWebAppClient instance.
|
|
8
|
+
*
|
|
9
|
+
* This hook creates a VincentWebAppClient instance using the provided App ID and memoizes it
|
|
10
|
+
* to prevent unnecessary re-creation of the client on each render. The client is only
|
|
11
|
+
* re-created when the App ID changes.
|
|
12
|
+
*
|
|
13
|
+
* The VincentWebAppClient provides methods for authentication, JWT handling, and redirecting
|
|
14
|
+
* to consent pages in Vincent applications.
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```typescript
|
|
18
|
+
* import { useVincentWebAuthClient } from '@lit-protocol/vincent-app-sdk/react';
|
|
19
|
+
*
|
|
20
|
+
* function MyComponent() {
|
|
21
|
+
* // Create a memoized Vincent Web App client
|
|
22
|
+
* const vincentClient = useVincentWebAuthClient('my-app-id');
|
|
23
|
+
*
|
|
24
|
+
* // Check if the user is logging in
|
|
25
|
+
* useEffect(() => {
|
|
26
|
+
* if (vincentClient.isLogin()) {
|
|
27
|
+
* const jwtResult = vincentClient.decodeVincentLoginJWT(window.location.origin);
|
|
28
|
+
* // Handle successful login
|
|
29
|
+
* console.log('User logged in with PKP address:', jwtResult.pkpAddress);
|
|
30
|
+
*
|
|
31
|
+
* // Remove JWT from URI to prevent issues with browser history
|
|
32
|
+
* vincentClient.removeLoginJWTFromURI();
|
|
33
|
+
* }
|
|
34
|
+
* }, [vincentClient]);
|
|
35
|
+
*
|
|
36
|
+
* // Function to handle the login button click
|
|
37
|
+
* const handleLogin = () => {
|
|
38
|
+
* vincentClient.redirectToConsentPage({
|
|
39
|
+
* redirectUri: window.location.href,
|
|
40
|
+
* });
|
|
41
|
+
* };
|
|
42
|
+
*
|
|
43
|
+
* return <button onClick={handleLogin}>Login with Vincent</button>;
|
|
44
|
+
* }
|
|
45
|
+
* ```
|
|
46
|
+
*
|
|
47
|
+
* @param appId - The unique identifier for your Vincent application
|
|
48
|
+
* @returns A memoized VincentWebAppClient instance
|
|
49
|
+
*/
|
|
50
|
+
const useVincentWebAuthClient = (appId) => {
|
|
51
|
+
return (0, react_1.useMemo)(() => (0, webAuthClient_1.getWebAuthClient)({ appId }), [appId]);
|
|
52
|
+
};
|
|
53
|
+
exports.useVincentWebAuthClient = useVincentWebAuthClient;
|
|
54
|
+
//# sourceMappingURL=useVincentWebAuthClient.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useVincentWebAuthClient.js","sourceRoot":"","sources":["../../../src/react/useVincentWebAuthClient.ts"],"names":[],"mappings":";;;AAAA,iCAAgC;AAEhC,oDAAoD;AAEpD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2CG;AACI,MAAM,uBAAuB,GAAG,CAAC,KAAa,EAAE,EAAE;IACvD,OAAO,IAAA,eAAO,EAAC,GAAG,EAAE,CAAC,IAAA,gCAAgB,EAAC,EAAE,KAAK,EAAE,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC;AAC7D,CAAC,CAAC;AAFW,QAAA,uBAAuB,2BAElC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lit-protocol/vincent-app-sdk",
|
|
3
|
-
"version": "2.1
|
|
3
|
+
"version": "2.2.1",
|
|
4
4
|
"description": "Vincent SDK for browser and backend",
|
|
5
5
|
"author": "Lit Protocol",
|
|
6
6
|
"license": "ISC",
|
|
@@ -38,6 +38,11 @@
|
|
|
38
38
|
"import": "./dist/src/utils/index.js",
|
|
39
39
|
"require": "./dist/src/utils/index.js",
|
|
40
40
|
"types": "./dist/src/utils/index.d.ts"
|
|
41
|
+
},
|
|
42
|
+
"./react": {
|
|
43
|
+
"import": "./dist/src/react/index.js",
|
|
44
|
+
"require": "./dist/src/react/index.js",
|
|
45
|
+
"types": "./dist/src/react/index.d.ts"
|
|
41
46
|
}
|
|
42
47
|
},
|
|
43
48
|
"keywords": [
|
|
@@ -53,8 +58,16 @@
|
|
|
53
58
|
"ethers": "5.8.0",
|
|
54
59
|
"tslib": "^2.8.1",
|
|
55
60
|
"zod": "3.25.64",
|
|
56
|
-
"@lit-protocol/vincent-ability-sdk": "2.
|
|
57
|
-
"@lit-protocol/vincent-contracts-sdk": "1.
|
|
61
|
+
"@lit-protocol/vincent-ability-sdk": "2.2.0",
|
|
62
|
+
"@lit-protocol/vincent-contracts-sdk": "1.3.0"
|
|
63
|
+
},
|
|
64
|
+
"peerDependencies": {
|
|
65
|
+
"react": "^19.0.0"
|
|
66
|
+
},
|
|
67
|
+
"peerDependenciesMeta": {
|
|
68
|
+
"react": {
|
|
69
|
+
"optional": true
|
|
70
|
+
}
|
|
58
71
|
},
|
|
59
72
|
"sideEffects": false,
|
|
60
73
|
"files": [
|
|
@@ -65,8 +78,10 @@
|
|
|
65
78
|
"@lit-protocol/pkp-ethers": "^7.2.3",
|
|
66
79
|
"@lit-protocol/types": "^7.2.3",
|
|
67
80
|
"@types/express": "^5.0.1",
|
|
81
|
+
"@types/react": "^19.0.10",
|
|
68
82
|
"chokidar-cli": "^3.0.0",
|
|
69
83
|
"live-server": "^1.2.2",
|
|
84
|
+
"react": "^19.0.0",
|
|
70
85
|
"typedoc": "0.27.9",
|
|
71
86
|
"typedoc-material-theme": "1.3.0",
|
|
72
87
|
"typedoc-plugin-extras": "^4.0.0",
|