@lit-protocol/vincent-app-sdk 2.0.1 → 2.0.2-mma

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 CHANGED
@@ -1,3 +1,18 @@
1
+ ## 2.1.0 (2025-09-11)
2
+
3
+ ### 🚀 Features
4
+
5
+ - Refactor the Uniswap Swap Ability to utilize a prepare step which uses a Lit Action to generate and sign a Uniswap route generated by the V3 Alpha Router. The Swap Ability now intakes the signed route, validates it was signed by the expected PKP (which can only be used to sign the generated Uniswap routes within the prepare Lit Action), then uses the provided route to create and sign the Uniswap Swap transaction with the Agent Wallet PKP. The Uniswap Swap Ability was also updated to no longer support the Spending Limit Policy, and currently doesn't support any Policies. ([8bbb1c07](https://github.com/LIT-Protocol/Vincent/commit/8bbb1c07))
6
+
7
+ ### 🧱 Updated Dependencies
8
+
9
+ - Updated ability-sdk to 2.1.0
10
+ - Updated contracts-sdk to 1.2.0
11
+
12
+ ### ❤️ Thank You
13
+
14
+ - Wyatt Barnes @spacesailor24
15
+
1
16
  ## 2.0.1 (2025-09-03)
2
17
 
3
18
  ### 🧱 Updated Dependencies
@@ -13,7 +28,6 @@
13
28
  - ### Implement supported Vincent Ability API range ([14f0ece1](https://github.com/LIT-Protocol/Vincent/commit/14f0ece1))
14
29
 
15
30
  Added basic Ability API handling to ensure abilities & policies are only used by compatible abilities and policies, and with the correct version of the vincentAbilityClient / app-sdk
16
-
17
31
  - Added a new jsParam when VincentAbilityClient calls an ability, `vincentAbilityApiVersion`
18
32
  - LIT action wrappers for abilities + policies compare `vincentAbilityApiVersion` to match the major semver range the handler was built with from the ability-sdk
19
33
  - vincentAbilityHandler() is responsible for passing along the value when it evaluates supported policies
@@ -21,7 +35,6 @@
21
35
  ### 🩹 Fixes
22
36
 
23
37
  - ### Fix ability failure response cases ([e2be50d9](https://github.com/LIT-Protocol/Vincent/commit/e2be50d9))
24
-
25
38
  - Ensures that policy denial disables checking the ability result against its fail schema in the abilityClient, because it will always be undefined :)
26
39
  - Ensures that `context` is returned in the response from the abilityClient.execute() method in cases where the ability response was a runtime or schemaValidationError
27
40
 
@@ -29,7 +42,6 @@
29
42
 
30
43
  - Add support for CBOR2 encoded policy parameters using the new vincent-contracts-sdk ([868c6c2a](https://github.com/LIT-Protocol/Vincent/commit/868c6c2a))
31
44
  - ### Add support for explicit `schemaValidationError` ([337a4bde](https://github.com/LIT-Protocol/Vincent/commit/337a4bde))
32
-
33
45
  - Previously, a failure to validate either input or results of lifecycle method would result in `result: { zodError }` being returned
34
46
  - Now, `result` will be `undefined` and there will be an explicit `schemaValidationError` in the result of the ability / policy
35
47
 
@@ -42,7 +54,6 @@
42
54
  ```
43
55
 
44
56
  - ### `error` is now `runtimeError` and can only be set by `throw ...` ([337a4bde](https://github.com/LIT-Protocol/Vincent/commit/337a4bde))
45
-
46
57
  - Previously, if you had not defined a `deny` or `fail` schema, you could call `deny()` or `fail()` with a string
47
58
  - That string would end up in the ability/policy response as the `error` property instead of `result`
48
59
  - This was problematic because there was no consistent way to identify _un-handled_ error vs. _explicitly returned fail/deny results_
@@ -70,11 +81,9 @@
70
81
  - #### Renamed `consent page` to `delegation auth page` ([b94ca569](https://github.com/LIT-Protocol/Vincent/commit/b94ca569))
71
82
  - #### Move utils exports to `@lit-protocol/vincent-app-sdk/utils` ([b94ca569](https://github.com/LIT-Protocol/Vincent/commit/b94ca569))
72
83
  - #### Moved jwt exports to `@lit-protocol/vincent-app-sdk/jwt` ([b94ca569](https://github.com/LIT-Protocol/Vincent/commit/b94ca569))
73
-
74
84
  - Enhanced typedocs for all methods and removed type aliases for core functions
75
85
 
76
86
  - #### Move `VincentWebAppClient` exports to `@lit-protocol/vincent-app-sdk/webAppClient` ([b94ca569](https://github.com/LIT-Protocol/Vincent/commit/b94ca569))
77
-
78
87
  - Renamed `VincentWebAppClient` to `WebAuthClient`
79
88
  - Renamed `VincentAppClientConfig` to `WebAuthClientConfig`
80
89
  - Renamed `RedirectToVincentConsentPageParams` to `RedirectToVincentDelegationPageParams`
@@ -82,16 +91,13 @@
82
91
  - Renamed `getVincentWebAppClient()` to `getWebAuthClient()`
83
92
 
84
93
  - #### Move express-authentication-middleware exports to `@lit-protocol/vincent-app-sdk/expressMiddleware` ([b94ca569](https://github.com/LIT-Protocol/Vincent/commit/b94ca569))
85
-
86
94
  - Removed `ExpressAuthHelpers` interface - its types are now directly exported from the `expressMiddleware` package sub-path
87
95
 
88
96
  - #### Moved abilityClient exports to `@lit-protocol/vincent-app-sdk/abilityClient` ([b94ca569](https://github.com/LIT-Protocol/Vincent/commit/b94ca569))
89
97
  - ### Update express middleware to support non-app-specific JWTs ([9dd1cd26](https://github.com/LIT-Protocol/Vincent/commit/9dd1cd26))
90
-
91
98
  - Replaced individual function exports of `authenticatedRequestHandler()` and `getAuthenticateUserExpressHandler()` with a single `createVincentUserMiddleware()` function
92
99
 
93
100
  #### createVincentUserMiddleware({ allowedAudience, userKey, requiredAppId? }) -> { middleware(), handler() }
94
-
95
101
  - You can now configure the property on `req` where the vincent user JWT data will be placed using `userKey`
96
102
  - You can now configure the authentication middleware to throw if `requiredAppId` does not match a specific appId you provide
97
103
  - `allowedAudience` behaviour remains unchanged
@@ -106,7 +112,6 @@
106
112
  This release adds support for general authentication JWTs that are not tied to a specific app. This is a breaking change that requires updates to code that uses the JWT validation functions.
107
113
 
108
114
  #### API Changes
109
-
110
115
  - `verify` and `decode` functions now accept object parameters instead of separate parameters
111
116
  - Their return values are strongly typed based on whether `requiredAppId` is provided.
112
117
  - They throw if `requiredAppId` is provided but the jwt is either not app-specific or the app id on the token doesn't match the `requiredAppId`
@@ -114,7 +119,6 @@
114
119
  - WebAuthClient now throws an error if the `appId` it was configured with isn't in the JWT it decodes
115
120
 
116
121
  #### New Functions
117
-
118
122
  - `isGeneralJWT`: Type guard to check if a JWT is Vincent JWT that has no app associated
119
123
  - `isAppSpecificJWT`: Type guard to check if a JWT is a vincent JWT that is app-specific
120
124
  - `assertIsVincentJWT`: Assertion function to validate if a decoded JWT is a valid Vincent JWT
@@ -122,7 +126,6 @@
122
126
  - `getPKPInfo`: Convenience method that returns PKP information from any Vincent JWT's payload
123
127
 
124
128
  #### New Types
125
-
126
129
  - `VincentJWT`: Interface for a decoded Vincent JWT without app-specific details (general authentication)
127
130
  - `VincentJWTAppSpecific`: Interface for a decoded app-specific Vincent JWT
128
131
  - `BaseVincentJWTPayload`: Payload that contains always-present properties on all Vincent JWTs
@@ -131,12 +134,10 @@
131
134
  - ## JWT Refactor ([c21bc3c3](https://github.com/LIT-Protocol/Vincent/commit/c21bc3c3))
132
135
 
133
136
  #### Refactored our JWT structure, composition, and verification logic.
134
-
135
137
  - Removed dependency on `did-jwt`; since we are signing using EIP-191 compliant signatures, the presence of `did:ethr` was misleading.
136
138
  - Added support for Delegatee JWTs
137
139
 
138
140
  #### We now support 3 types of JWT:
139
-
140
141
  - `VincentJWTAppUser`
141
142
  - `role` claim in the JWT payload is `app-user`
142
143
  - Contains PKP info
@@ -155,7 +156,6 @@
155
156
  - Used to authenticate with services that require proof that they are being used by a specific delegatee who has permissions to act on behalf of a delegator (app user) account.
156
157
 
157
158
  ### API Changes
158
-
159
159
  - Many classes and interfaces were renamed to clearly indicate which type of JWT that they apply to.
160
160
  - Added `publicKey` to the `payload` of all JWTs for signature verification convenience
161
161
  - `iss` and `sub` are now raw hex-formatted ethers addresses, without `did:ethr` prefixes
@@ -196,7 +196,6 @@
196
196
  ### 🩹 Fixes
197
197
 
198
198
  - #### VincentAbilityClient Precheck fixes ([8da32df2](https://github.com/LIT-Protocol/Vincent/commit/8da32df2))
199
-
200
199
  - Fix a case where deny results from `precheck()` were not correctly bubbled to the caller
201
200
  - Fixed incorrect return type shape - `error` is a sibling of `result` in the policiesContext- Ensured `error` is bubbled up to the caller when provided
202
201
 
package/dist/CHANGELOG.md CHANGED
@@ -1,3 +1,18 @@
1
+ ## 2.1.0 (2025-09-11)
2
+
3
+ ### 🚀 Features
4
+
5
+ - Refactor the Uniswap Swap Ability to utilize a prepare step which uses a Lit Action to generate and sign a Uniswap route generated by the V3 Alpha Router. The Swap Ability now intakes the signed route, validates it was signed by the expected PKP (which can only be used to sign the generated Uniswap routes within the prepare Lit Action), then uses the provided route to create and sign the Uniswap Swap transaction with the Agent Wallet PKP. The Uniswap Swap Ability was also updated to no longer support the Spending Limit Policy, and currently doesn't support any Policies. ([8bbb1c07](https://github.com/LIT-Protocol/Vincent/commit/8bbb1c07))
6
+
7
+ ### 🧱 Updated Dependencies
8
+
9
+ - Updated ability-sdk to 2.1.0
10
+ - Updated contracts-sdk to 1.2.0
11
+
12
+ ### ❤️ Thank You
13
+
14
+ - Wyatt Barnes @spacesailor24
15
+
1
16
  ## 2.0.1 (2025-09-03)
2
17
 
3
18
  ### 🧱 Updated Dependencies
@@ -13,7 +28,6 @@
13
28
  - ### Implement supported Vincent Ability API range ([14f0ece1](https://github.com/LIT-Protocol/Vincent/commit/14f0ece1))
14
29
 
15
30
  Added basic Ability API handling to ensure abilities & policies are only used by compatible abilities and policies, and with the correct version of the vincentAbilityClient / app-sdk
16
-
17
31
  - Added a new jsParam when VincentAbilityClient calls an ability, `vincentAbilityApiVersion`
18
32
  - LIT action wrappers for abilities + policies compare `vincentAbilityApiVersion` to match the major semver range the handler was built with from the ability-sdk
19
33
  - vincentAbilityHandler() is responsible for passing along the value when it evaluates supported policies
@@ -21,7 +35,6 @@
21
35
  ### 🩹 Fixes
22
36
 
23
37
  - ### Fix ability failure response cases ([e2be50d9](https://github.com/LIT-Protocol/Vincent/commit/e2be50d9))
24
-
25
38
  - Ensures that policy denial disables checking the ability result against its fail schema in the abilityClient, because it will always be undefined :)
26
39
  - Ensures that `context` is returned in the response from the abilityClient.execute() method in cases where the ability response was a runtime or schemaValidationError
27
40
 
@@ -29,7 +42,6 @@
29
42
 
30
43
  - Add support for CBOR2 encoded policy parameters using the new vincent-contracts-sdk ([868c6c2a](https://github.com/LIT-Protocol/Vincent/commit/868c6c2a))
31
44
  - ### Add support for explicit `schemaValidationError` ([337a4bde](https://github.com/LIT-Protocol/Vincent/commit/337a4bde))
32
-
33
45
  - Previously, a failure to validate either input or results of lifecycle method would result in `result: { zodError }` being returned
34
46
  - Now, `result` will be `undefined` and there will be an explicit `schemaValidationError` in the result of the ability / policy
35
47
 
@@ -42,7 +54,6 @@
42
54
  ```
43
55
 
44
56
  - ### `error` is now `runtimeError` and can only be set by `throw ...` ([337a4bde](https://github.com/LIT-Protocol/Vincent/commit/337a4bde))
45
-
46
57
  - Previously, if you had not defined a `deny` or `fail` schema, you could call `deny()` or `fail()` with a string
47
58
  - That string would end up in the ability/policy response as the `error` property instead of `result`
48
59
  - This was problematic because there was no consistent way to identify _un-handled_ error vs. _explicitly returned fail/deny results_
@@ -70,11 +81,9 @@
70
81
  - #### Renamed `consent page` to `delegation auth page` ([b94ca569](https://github.com/LIT-Protocol/Vincent/commit/b94ca569))
71
82
  - #### Move utils exports to `@lit-protocol/vincent-app-sdk/utils` ([b94ca569](https://github.com/LIT-Protocol/Vincent/commit/b94ca569))
72
83
  - #### Moved jwt exports to `@lit-protocol/vincent-app-sdk/jwt` ([b94ca569](https://github.com/LIT-Protocol/Vincent/commit/b94ca569))
73
-
74
84
  - Enhanced typedocs for all methods and removed type aliases for core functions
75
85
 
76
86
  - #### Move `VincentWebAppClient` exports to `@lit-protocol/vincent-app-sdk/webAppClient` ([b94ca569](https://github.com/LIT-Protocol/Vincent/commit/b94ca569))
77
-
78
87
  - Renamed `VincentWebAppClient` to `WebAuthClient`
79
88
  - Renamed `VincentAppClientConfig` to `WebAuthClientConfig`
80
89
  - Renamed `RedirectToVincentConsentPageParams` to `RedirectToVincentDelegationPageParams`
@@ -82,16 +91,13 @@
82
91
  - Renamed `getVincentWebAppClient()` to `getWebAuthClient()`
83
92
 
84
93
  - #### Move express-authentication-middleware exports to `@lit-protocol/vincent-app-sdk/expressMiddleware` ([b94ca569](https://github.com/LIT-Protocol/Vincent/commit/b94ca569))
85
-
86
94
  - Removed `ExpressAuthHelpers` interface - its types are now directly exported from the `expressMiddleware` package sub-path
87
95
 
88
96
  - #### Moved abilityClient exports to `@lit-protocol/vincent-app-sdk/abilityClient` ([b94ca569](https://github.com/LIT-Protocol/Vincent/commit/b94ca569))
89
97
  - ### Update express middleware to support non-app-specific JWTs ([9dd1cd26](https://github.com/LIT-Protocol/Vincent/commit/9dd1cd26))
90
-
91
98
  - Replaced individual function exports of `authenticatedRequestHandler()` and `getAuthenticateUserExpressHandler()` with a single `createVincentUserMiddleware()` function
92
99
 
93
100
  #### createVincentUserMiddleware({ allowedAudience, userKey, requiredAppId? }) -> { middleware(), handler() }
94
-
95
101
  - You can now configure the property on `req` where the vincent user JWT data will be placed using `userKey`
96
102
  - You can now configure the authentication middleware to throw if `requiredAppId` does not match a specific appId you provide
97
103
  - `allowedAudience` behaviour remains unchanged
@@ -106,7 +112,6 @@
106
112
  This release adds support for general authentication JWTs that are not tied to a specific app. This is a breaking change that requires updates to code that uses the JWT validation functions.
107
113
 
108
114
  #### API Changes
109
-
110
115
  - `verify` and `decode` functions now accept object parameters instead of separate parameters
111
116
  - Their return values are strongly typed based on whether `requiredAppId` is provided.
112
117
  - They throw if `requiredAppId` is provided but the jwt is either not app-specific or the app id on the token doesn't match the `requiredAppId`
@@ -114,7 +119,6 @@
114
119
  - WebAuthClient now throws an error if the `appId` it was configured with isn't in the JWT it decodes
115
120
 
116
121
  #### New Functions
117
-
118
122
  - `isGeneralJWT`: Type guard to check if a JWT is Vincent JWT that has no app associated
119
123
  - `isAppSpecificJWT`: Type guard to check if a JWT is a vincent JWT that is app-specific
120
124
  - `assertIsVincentJWT`: Assertion function to validate if a decoded JWT is a valid Vincent JWT
@@ -122,7 +126,6 @@
122
126
  - `getPKPInfo`: Convenience method that returns PKP information from any Vincent JWT's payload
123
127
 
124
128
  #### New Types
125
-
126
129
  - `VincentJWT`: Interface for a decoded Vincent JWT without app-specific details (general authentication)
127
130
  - `VincentJWTAppSpecific`: Interface for a decoded app-specific Vincent JWT
128
131
  - `BaseVincentJWTPayload`: Payload that contains always-present properties on all Vincent JWTs
@@ -131,12 +134,10 @@
131
134
  - ## JWT Refactor ([c21bc3c3](https://github.com/LIT-Protocol/Vincent/commit/c21bc3c3))
132
135
 
133
136
  #### Refactored our JWT structure, composition, and verification logic.
134
-
135
137
  - Removed dependency on `did-jwt`; since we are signing using EIP-191 compliant signatures, the presence of `did:ethr` was misleading.
136
138
  - Added support for Delegatee JWTs
137
139
 
138
140
  #### We now support 3 types of JWT:
139
-
140
141
  - `VincentJWTAppUser`
141
142
  - `role` claim in the JWT payload is `app-user`
142
143
  - Contains PKP info
@@ -155,7 +156,6 @@
155
156
  - Used to authenticate with services that require proof that they are being used by a specific delegatee who has permissions to act on behalf of a delegator (app user) account.
156
157
 
157
158
  ### API Changes
158
-
159
159
  - Many classes and interfaces were renamed to clearly indicate which type of JWT that they apply to.
160
160
  - Added `publicKey` to the `payload` of all JWTs for signature verification convenience
161
161
  - `iss` and `sub` are now raw hex-formatted ethers addresses, without `did:ethr` prefixes
@@ -196,7 +196,6 @@
196
196
  ### 🩹 Fixes
197
197
 
198
198
  - #### VincentAbilityClient Precheck fixes ([8da32df2](https://github.com/LIT-Protocol/Vincent/commit/8da32df2))
199
-
200
199
  - Fix a case where deny results from `precheck()` were not correctly bubbled to the caller
201
200
  - Fixed incorrect return type shape - `error` is a sibling of `result` in the policiesContext- Ensured `error` is bubbled up to the caller when provided
202
201
 
package/dist/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lit-protocol/vincent-app-sdk",
3
- "version": "2.0.1",
3
+ "version": "2.1.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",
@@ -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
  *
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceR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C;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,0 +1 @@
1
+ {"version":3,"file":"jwtProvider.d.ts","sourceRoot":"","sources":["../../../src/react/jwtProvider.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAE5C,OAAO,KAA+E,MAAM,OAAO,CAAC;AAEpG,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAErD,OAAO,KAAK,EAAE,OAAO,EAAE,uBAAuB,EAAE,MAAM,cAAc,CAAC;AAKrE;;;;;GAKG;AACH,MAAM,WAAW,QAAQ;IACvB,GAAG,EAAE,OAAO,CAAC;IACb,cAAc,EAAE,uBAAuB,CAAC;IACxC,GAAG,EAAE,MAAM,CAAC;IACZ,GAAG,EAAE,SAAS,CAAC;CAChB;AAED,UAAU,cAAc;IACtB,QAAQ,EAAE,QAAQ,GAAG,IAAI,CAAC;IAC1B,OAAO,EAAE,OAAO,CAAC;IACjB,OAAO,EAAE,CAAC,WAAW,EAAE,MAAM,KAAK,IAAI,CAAC;IACvC,YAAY,EAAE,MAAM,IAAI,CAAC;IACzB,MAAM,EAAE,MAAM,IAAI,CAAC;CACpB;AAMD;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,eAAO,MAAM,UAAU,+BAMrB,CAAC;AAEH;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuCG;AACH,wBAAgB,aAAa,IAAI,cAAc,CAE9C;AAED;;;;;GAKG;AACH,MAAM,WAAW,YAAY;IAC3B,OAAO,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,GAAG,MAAM,GAAG,IAAI,CAAC;IACjE,OAAO,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC;IAC9D,UAAU,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,OAAO,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,OAoGzB,CAAC"}
@@ -0,0 +1,226 @@
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
+ catch (error) {
155
+ console.error(`Error logging out. Could not remove your JWT from storage: ${error.message}`);
156
+ }
157
+ finally {
158
+ setLoading(false);
159
+ }
160
+ }, [appJwtKey, storage]);
161
+ const connect = (0, react_1.useCallback)((redirectUri) => {
162
+ // Redirect to Vincent Auth consent page with appId and version
163
+ vincentWebAppClient.redirectToConnectPage({
164
+ // connectPageUrl: `http://localhost:5173/`,
165
+ redirectUri,
166
+ });
167
+ }, [vincentWebAppClient]);
168
+ const getJwt = (0, react_1.useCallback)(async () => {
169
+ if (vincentWebAppClient.uriContainsVincentJWT()) {
170
+ const jwtResult = await vincentWebAppClient.decodeVincentJWTFromUri(window.location.origin);
171
+ if (!jwtResult) {
172
+ return null;
173
+ }
174
+ const { decodedJWT, jwtStr } = jwtResult;
175
+ await storage.setItem(appJwtKey, jwtStr);
176
+ vincentWebAppClient.removeVincentJWTFromURI();
177
+ return { jwtStr, decodedJWT };
178
+ }
179
+ const existingJwtStr = await storage.getItem(appJwtKey);
180
+ if (!existingJwtStr) {
181
+ return null;
182
+ }
183
+ const decodedJWT = await (0, jwt_1.verifyVincentAppUserJWT)({
184
+ expectedAudience: window.location.origin,
185
+ jwt: existingJwtStr,
186
+ requiredAppId: appId,
187
+ });
188
+ return { jwtStr: existingJwtStr, decodedJWT };
189
+ }, [appJwtKey, storage, vincentWebAppClient]);
190
+ const loginWithJwt = (0, react_1.useCallback)(async () => {
191
+ try {
192
+ setLoading(true);
193
+ const jwtResult = await getJwt();
194
+ if (!jwtResult) {
195
+ throw new Error('Could not get JWT');
196
+ }
197
+ const { decodedJWT, jwtStr } = jwtResult;
198
+ setAuthInfo({
199
+ app: decodedJWT.payload.app,
200
+ authentication: decodedJWT.payload.authentication,
201
+ jwt: jwtStr,
202
+ pkp: decodedJWT.payload.pkpInfo,
203
+ });
204
+ }
205
+ catch (error) {
206
+ console.error(`Error logging in with JWT. Need to relogin: ${error.message}`);
207
+ await logOut();
208
+ }
209
+ finally {
210
+ setLoading(false);
211
+ }
212
+ }, [getJwt, logOut]);
213
+ const value = (0, react_1.useMemo)(() => ({
214
+ authInfo,
215
+ connect,
216
+ loading,
217
+ loginWithJwt,
218
+ logOut,
219
+ }), [authInfo, connect, loading, loginWithJwt, logOut]);
220
+ (0, react_1.useEffect)(() => {
221
+ void loginWithJwt();
222
+ }, [loginWithJwt]);
223
+ return react_1.default.createElement(exports.JwtContext.Provider, { value: value }, children);
224
+ };
225
+ exports.JwtProvider = JwtProvider;
226
+ //# 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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CAAC,OAAO,CAAC,cAAc;gBACjD,GAAG,EAAE,MAAM;gBACX,GAAG,EAAE,UAAU,CAAC,OAAO,CAAC,OAAO;aAChC,CAAC,CAAC;QACL,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,OAAO,CAAC,KAAK,CAAC,+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;AAzGW,QAAA,WAAW,eAyGtB"}
@@ -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.0.1",
3
+ "version": "2.0.2-mma",
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.0.1",
57
- "@lit-protocol/vincent-contracts-sdk": "1.1.0"
61
+ "@lit-protocol/vincent-ability-sdk": "2.1.0",
62
+ "@lit-protocol/vincent-contracts-sdk": "1.2.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",