@lit-protocol/vincent-app-sdk 1.0.0-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.
Files changed (124) hide show
  1. package/CHANGELOG.md +53 -0
  2. package/CONTRIBUTING.md +115 -0
  3. package/README.md +215 -0
  4. package/dist/CHANGELOG.md +53 -0
  5. package/dist/CONTRIBUTING.md +115 -0
  6. package/dist/README.md +215 -0
  7. package/dist/package.json +54 -0
  8. package/dist/src/app/app.d.ts +9 -0
  9. package/dist/src/app/app.d.ts.map +1 -0
  10. package/dist/src/app/app.js +33 -0
  11. package/dist/src/app/app.js.map +1 -0
  12. package/dist/src/app/constants.d.ts +3 -0
  13. package/dist/src/app/constants.d.ts.map +1 -0
  14. package/dist/src/app/constants.js +6 -0
  15. package/dist/src/app/constants.js.map +1 -0
  16. package/dist/src/app/index.d.ts +3 -0
  17. package/dist/src/app/index.d.ts.map +1 -0
  18. package/dist/src/app/index.js +6 -0
  19. package/dist/src/app/index.js.map +1 -0
  20. package/dist/src/app/internal/index.d.ts +3 -0
  21. package/dist/src/app/internal/index.d.ts.map +1 -0
  22. package/dist/src/app/internal/index.js +7 -0
  23. package/dist/src/app/internal/index.js.map +1 -0
  24. package/dist/src/app/internal/uriHelpers.d.ts +11 -0
  25. package/dist/src/app/internal/uriHelpers.d.ts.map +1 -0
  26. package/dist/src/app/internal/uriHelpers.js +32 -0
  27. package/dist/src/app/internal/uriHelpers.js.map +1 -0
  28. package/dist/src/app/types.d.ts +119 -0
  29. package/dist/src/app/types.d.ts.map +1 -0
  30. package/dist/src/app/types.js +3 -0
  31. package/dist/src/app/types.js.map +1 -0
  32. package/dist/src/express-authentication-middleware/express.d.ts +79 -0
  33. package/dist/src/express-authentication-middleware/express.d.ts.map +1 -0
  34. package/dist/src/express-authentication-middleware/express.js +137 -0
  35. package/dist/src/express-authentication-middleware/express.js.map +1 -0
  36. package/dist/src/express-authentication-middleware/index.d.ts +43 -0
  37. package/dist/src/express-authentication-middleware/index.d.ts.map +1 -0
  38. package/dist/src/express-authentication-middleware/index.js +47 -0
  39. package/dist/src/express-authentication-middleware/index.js.map +1 -0
  40. package/dist/src/express-authentication-middleware/types.d.ts +22 -0
  41. package/dist/src/express-authentication-middleware/types.d.ts.map +1 -0
  42. package/dist/src/express-authentication-middleware/types.js +3 -0
  43. package/dist/src/express-authentication-middleware/types.js.map +1 -0
  44. package/dist/src/index.d.ts +12 -0
  45. package/dist/src/index.d.ts.map +1 -0
  46. package/dist/src/index.js +15 -0
  47. package/dist/src/index.js.map +1 -0
  48. package/dist/src/internal/LitNodeClient/LitNodeClientInstance.d.ts +14 -0
  49. package/dist/src/internal/LitNodeClient/LitNodeClientInstance.d.ts.map +1 -0
  50. package/dist/src/internal/LitNodeClient/LitNodeClientInstance.js +67 -0
  51. package/dist/src/internal/LitNodeClient/LitNodeClientInstance.js.map +1 -0
  52. package/dist/src/internal/LitNodeClient/getLitNodeClient.d.ts +7 -0
  53. package/dist/src/internal/LitNodeClient/getLitNodeClient.d.ts.map +1 -0
  54. package/dist/src/internal/LitNodeClient/getLitNodeClient.js +25 -0
  55. package/dist/src/internal/LitNodeClient/getLitNodeClient.js.map +1 -0
  56. package/dist/src/jwt/core/create.d.ts +41 -0
  57. package/dist/src/jwt/core/create.d.ts.map +1 -0
  58. package/dist/src/jwt/core/create.js +114 -0
  59. package/dist/src/jwt/core/create.js.map +1 -0
  60. package/dist/src/jwt/core/utils/definedObject.d.ts +2 -0
  61. package/dist/src/jwt/core/utils/definedObject.d.ts.map +1 -0
  62. package/dist/src/jwt/core/utils/definedObject.js +7 -0
  63. package/dist/src/jwt/core/utils/definedObject.js.map +1 -0
  64. package/dist/src/jwt/core/utils/index.d.ts +6 -0
  65. package/dist/src/jwt/core/utils/index.d.ts.map +1 -0
  66. package/dist/src/jwt/core/utils/index.js +14 -0
  67. package/dist/src/jwt/core/utils/index.js.map +1 -0
  68. package/dist/src/jwt/core/utils/isJWTExpired.d.ts +8 -0
  69. package/dist/src/jwt/core/utils/isJWTExpired.d.ts.map +1 -0
  70. package/dist/src/jwt/core/utils/isJWTExpired.js +19 -0
  71. package/dist/src/jwt/core/utils/isJWTExpired.js.map +1 -0
  72. package/dist/src/jwt/core/utils/processJWTSignature.d.ts +8 -0
  73. package/dist/src/jwt/core/utils/processJWTSignature.d.ts.map +1 -0
  74. package/dist/src/jwt/core/utils/processJWTSignature.js +21 -0
  75. package/dist/src/jwt/core/utils/processJWTSignature.js.map +1 -0
  76. package/dist/src/jwt/core/utils/splitJWT.d.ts +11 -0
  77. package/dist/src/jwt/core/utils/splitJWT.d.ts.map +1 -0
  78. package/dist/src/jwt/core/utils/splitJWT.js +21 -0
  79. package/dist/src/jwt/core/utils/splitJWT.js.map +1 -0
  80. package/dist/src/jwt/core/utils/validateJWTTime.d.ts +12 -0
  81. package/dist/src/jwt/core/utils/validateJWTTime.d.ts.map +1 -0
  82. package/dist/src/jwt/core/utils/validateJWTTime.js +24 -0
  83. package/dist/src/jwt/core/utils/validateJWTTime.js.map +1 -0
  84. package/dist/src/jwt/core/validate.d.ts +23 -0
  85. package/dist/src/jwt/core/validate.d.ts.map +1 -0
  86. package/dist/src/jwt/core/validate.js +96 -0
  87. package/dist/src/jwt/core/validate.js.map +1 -0
  88. package/dist/src/jwt/index.d.ts +69 -0
  89. package/dist/src/jwt/index.d.ts.map +1 -0
  90. package/dist/src/jwt/index.js +72 -0
  91. package/dist/src/jwt/index.js.map +1 -0
  92. package/dist/src/jwt/types.d.ts +68 -0
  93. package/dist/src/jwt/types.d.ts.map +1 -0
  94. package/dist/src/jwt/types.js +3 -0
  95. package/dist/src/jwt/types.js.map +1 -0
  96. package/dist/src/toolClient/index.d.ts +2 -0
  97. package/dist/src/toolClient/index.d.ts.map +1 -0
  98. package/dist/src/toolClient/index.js +6 -0
  99. package/dist/src/toolClient/index.js.map +1 -0
  100. package/dist/src/toolClient/resultCreators.d.ts +69 -0
  101. package/dist/src/toolClient/resultCreators.d.ts.map +1 -0
  102. package/dist/src/toolClient/resultCreators.js +55 -0
  103. package/dist/src/toolClient/resultCreators.js.map +1 -0
  104. package/dist/src/toolClient/typeGuards.d.ts +19 -0
  105. package/dist/src/toolClient/typeGuards.d.ts.map +1 -0
  106. package/dist/src/toolClient/typeGuards.js +48 -0
  107. package/dist/src/toolClient/typeGuards.js.map +1 -0
  108. package/dist/src/toolClient/types.d.ts +33 -0
  109. package/dist/src/toolClient/types.d.ts.map +1 -0
  110. package/dist/src/toolClient/types.js +3 -0
  111. package/dist/src/toolClient/types.js.map +1 -0
  112. package/dist/src/toolClient/vincentToolClient.d.ts +15 -0
  113. package/dist/src/toolClient/vincentToolClient.d.ts.map +1 -0
  114. package/dist/src/toolClient/vincentToolClient.js +256 -0
  115. package/dist/src/toolClient/vincentToolClient.js.map +1 -0
  116. package/dist/src/type-inference-verification/tool-client-inference.d.ts +3 -0
  117. package/dist/src/type-inference-verification/tool-client-inference.d.ts.map +1 -0
  118. package/dist/src/type-inference-verification/tool-client-inference.js +214 -0
  119. package/dist/src/type-inference-verification/tool-client-inference.js.map +1 -0
  120. package/dist/src/types.d.ts +4 -0
  121. package/dist/src/types.d.ts.map +1 -0
  122. package/dist/src/types.js +3 -0
  123. package/dist/src/types.js.map +1 -0
  124. package/package.json +55 -0
package/dist/README.md ADDED
@@ -0,0 +1,215 @@
1
+ # Vincent SDK
2
+
3
+ ## Installation
4
+
5
+ ```
6
+ npm install @lit-protocol/vincent-app-sdk
7
+ ```
8
+
9
+ ## Usage
10
+
11
+ # Client (Web)
12
+
13
+ ## VincentWebAppClient
14
+
15
+ The Vincent Web App Client provides methods for managing user authentication, JWT tokens, and consent flows in Vincent applications.
16
+
17
+ ### Methods
18
+
19
+ #### redirectToConsentPage()
20
+
21
+ Redirects the user to the Vincent consent page to obtain authorization. Once the user has completed the vincent consent flow
22
+ they will be redirected back to your app with a signed JWT that you can use to authenticate requests against your backend APIs
23
+
24
+ - When a JWT is expired, you need to use this method to get a new JWT
25
+
26
+ #### isLoginUri()
27
+
28
+ Checks if the current window location contains a Vincent login JWT. You can use this method to know that you should update login state with the newly provided JWT
29
+
30
+ - Returns: Boolean indicating if the URI contains a login JWT
31
+
32
+ #### decodeVincentLoginJWT(expectedAudience)
33
+
34
+ Decodes a Vincent login JWT. Performs basic sanity check but does not perform full verify() logic. You will want to run `verify()` from the jwt tools to verify the JWT is fully valid and not expired etc.
35
+
36
+ - The expected audience is typically your app's domain -- it should be one of your valid redirectUri values from your Vincent app configuration
37
+
38
+ - Returns: An object containing both the original JWT string and the decoded JWT object
39
+
40
+ #### removeLoginJWTFromURI()
41
+
42
+ Removes the login JWT parameter from the current URI. Call this after you have verified and stored the JWT for later usage.
43
+
44
+ ### Basic Usage
45
+
46
+ ```typescript
47
+ import { getVincentWebAppClient, jwt } from '@lit-protocol/vincent-app-sdk';
48
+
49
+ const { isExpired } = jwt;
50
+
51
+ const vincentAppClient = getVincentWebAppClient({ appId: MY_APP_ID });
52
+ // ... In your app logic:
53
+ if (vincentAppClient.isLogin()) {
54
+ // Handle app logic for the user has just logged in
55
+ const { decoded, jwt } = vincentAppClient.decodeVincentLoginJWT(window.location.origin);
56
+ // Store `jwt` for later usage; the user is now logged in.
57
+ } else {
58
+ // Handle app logic for the user is _already logged in_ (check for stored & unexpired JWT)
59
+
60
+ const jwt = localStorage.getItem('VINCENT_AUTH_JWT');
61
+ if (jwt && isExpired(jwt)) {
62
+ // User must re-log in
63
+ vincentAppClient.redirectToConsentPage({ redirectUri: window.location.href });
64
+ }
65
+
66
+ if (!jwt) {
67
+ // Handle app logic for the user is not yet logged in
68
+ vincentAppClient.redirectToConsentPage({ redirectUri: window.location.href });
69
+ }
70
+ }
71
+ ```
72
+
73
+ # Backend
74
+
75
+ In your backend, you will have to verify the JWT to make sure the user has granted you the required permissions to act on their behalf.
76
+
77
+ ## VincentToolClient
78
+
79
+ The Vincent Tool Client uses an ethers signer for your delegatee account to run Vincent Tools on behalf of your app users.
80
+
81
+ This client will typically be used by an AI agent or your app backend service, as it requires a signer that conforms to the ethers v5 signer API, and with access to your delegatee account's private key to authenticate with the LIT network when executing the Vincent Tool.
82
+
83
+ ### Configuration
84
+
85
+ ```typescript
86
+ interface VincentToolClientConfig {
87
+ ethersSigner: ethers.Signer; // An ethers v5 compatible signer
88
+ vincentToolCid: string; // The CID of the Vincent Tool to execute
89
+ }
90
+ ```
91
+
92
+ ### Methods
93
+
94
+ #### execute(params: VincentToolParams): Promise<ExecuteJsResponse>
95
+
96
+ Executes a Vincent Tool with the provided parameters.
97
+
98
+ - `params`: Record<string, unknown> - Parameters to pass to the Vincent Tool
99
+ - Returns: Promise resolving to an ExecuteJsResponse from the LIT network
100
+
101
+ ### Tool execution
102
+
103
+ ```typescript
104
+ import { getVincentToolClient } from '@lit-protocol/vincent-app-sdk';
105
+ // Import the tool you want to execute
106
+ import { bundledVincentTool as erc20BundledTool } from '@lit-protocol/vincent-tool-erc20-approval';
107
+
108
+ // One of delegatee signers from your app's Vincent Dashboard
109
+ const delegateeSigner = new ethers.Wallet('YOUR_DELEGATEE_PRIVATE_KEY');
110
+
111
+ // Initialize the Vincent Tool Client
112
+ const toolClient = getVincentToolClient({
113
+ ethersSigner: delegateeSigner,
114
+ bundledVincentTool: erc20BundledTool,
115
+ });
116
+ const delegatorPkpEthAddress = '0x09182301238';
117
+
118
+ const toolParams = {
119
+ // Fill with the params your tool needs
120
+ };
121
+
122
+ // Run precheck to see if tool should be executed
123
+ const precheckResult = await client.precheck(toolParams, {
124
+ delegatorPkpEthAddress,
125
+ });
126
+
127
+ if (precheckResult.success === true) {
128
+ // Execute the Vincent Tool
129
+ const executeResult = await client.execute(toolParams, {
130
+ delegatorPkpEthAddress,
131
+ });
132
+
133
+ // ...tool has executed, you can check `executeResult` for details
134
+ }
135
+ ```
136
+
137
+ ### Usage
138
+
139
+ ### Authentication
140
+
141
+ A basic Express authentication middleware factory function is provided with the SDK.
142
+
143
+ - Create an express middleware using `getAuthenticateUserExpressHandler()`
144
+ - Once you have added the middleware to your route, use `authenticatedRequestHandler()` to provide
145
+ type-safe access to `req.user` in your downstream RequestHandler functions.
146
+ - When defining your authenticated routes, use the `ExpressAuthHelpers` type to type your functions and function arguments.
147
+
148
+ See getAuthenticateUserExpressHandler() documentation to see the source for the express authentication route handler
149
+
150
+ ```typescript
151
+ import { expressAuthHelpers } from '@lit-protocol/vincent-app-sdk';
152
+ const { authenticatedRequestHandler, getAuthenticateUserExpressHandler } = expressAuthHelpers;
153
+
154
+ import type { ExpressAuthHelpers } from '@lit-protocol/vincent-app-sdk';
155
+
156
+ const { ALLOWED_AUDIENCE } = process.env;
157
+
158
+ const authenticateUserMiddleware = getAuthenticateUserExpressHandler(ALLOWED_AUDIENCE);
159
+
160
+ // Define an authenticated route handler
161
+ const getUserProfile = async (req: ExpressAuthHelpers['AuthenticatedRequest'], res: Response) => {
162
+ // Access authenticated user information
163
+ const { pkpAddress } = req.user;
164
+
165
+ // Fetch and return user data
166
+ const userData = await userRepository.findByAddress(pkpAddress);
167
+ res.json(userData);
168
+ };
169
+
170
+ // Use in Express route with authentication
171
+ app.get('/profile', authenticateUser, authenticatedRequestHandler(getUserProfile));
172
+ ```
173
+
174
+ ## JWT Authentication
175
+
176
+ ### Overview
177
+
178
+ The JWT authentication system in Vincent SDK allows for secure communication between user applications and Vincent Tools. JWTs are used to verify user consent and authorize tool executions.
179
+
180
+ ### Authentication Flow
181
+
182
+ 1. User initiates an action requiring Vincent Tool access
183
+ 2. Application redirects to the Vincent consent page using `VincentWebAppClient.redirectToConsentPage()`
184
+ 3. User provides consent for the requested tools/policies
185
+ 4. User is redirected back to the application with a JWT in the URL
186
+ 5. Application validates and stores the JWT using `VincentWebAppClient` methods
187
+ 6. JWT is used to authenticate with the app backend
188
+
189
+ ### JWT Structure
190
+
191
+ Vincent JWTs contain:
192
+
193
+ - User account identity information (pkpAddress and pkpPublicKey)
194
+ - Expiration timestamp
195
+ - Signature from the Vincent authorization service
196
+
197
+ ### Error Handling
198
+
199
+ When JWT validation fails, descriptive error messages are thrown to help with troubleshooting.
200
+
201
+ ### Usage Notes
202
+
203
+ - JWTs have an expiration time after which they are no longer valid
204
+ - When a JWT expires, redirect the user to the consent page to obtain a new one using the `VincentWebAppClient`
205
+
206
+ ## Release
207
+
208
+ Pre-requisites:
209
+
210
+ - You will need a valid npm account with access to the `@lit-protocol` organization.
211
+ - Run `pnpm vercel login` at sdk root to get a authentication token for vercel
212
+ - Also you will need to fill the `.env` file with the vercel project and org ids for the [vincent-docs](https://vercel.com/lit-protocol/vincent-docs) project.
213
+
214
+ Then run `pnpm release` on the repository root. It will prompt you to update the Vincent SDK version and then ask you to confirm the release.
215
+ This process will also generate a `CHANGELOG.md` record with the changes for the release and update typedoc in vercel after publishing the SDK.
@@ -0,0 +1,54 @@
1
+ {
2
+ "name": "@lit-protocol/vincent-app-sdk",
3
+ "version": "0.0.7",
4
+ "description": "Vincent SDK for browser and backend",
5
+ "author": "Lit Protocol",
6
+ "license": "ISC",
7
+ "access": "public",
8
+ "packageManager": "pnpm@10.7.0",
9
+ "engines": {
10
+ "node": "^20.11.1",
11
+ "pnpm": "10.7.0"
12
+ },
13
+ "main": "./dist/src/index.js",
14
+ "types": "./dist/src/index.d.ts",
15
+ "keywords": [
16
+ "jwt",
17
+ "authentication",
18
+ "sdk"
19
+ ],
20
+ "scripts": {
21
+ "type-tests": "./scripts/run-typecheck.sh",
22
+ "watch:type-tests": "chokidar 'src/**/*' --initial --await-write-finish --delay 100 --silent -c './scripts/run-typecheck.sh'",
23
+ "typecheck": "./scripts/precommit-check.sh"
24
+ },
25
+ "dependencies": {
26
+ "@lit-protocol/auth-helpers": "^7.0.9",
27
+ "@lit-protocol/constants": "^7.0.8",
28
+ "@lit-protocol/lit-node-client": "^7.0.8",
29
+ "@lit-protocol/vincent-tool-sdk": "workspace:*",
30
+ "@noble/secp256k1": "^2.2.3",
31
+ "did-jwt": "^8.0.8",
32
+ "ethers": "5.8.0",
33
+ "tslib": "^2.8.1",
34
+ "zod": "3.25.64"
35
+ },
36
+ "sideEffects": false,
37
+ "files": [
38
+ "dist/**/*",
39
+ "*.md"
40
+ ],
41
+ "devDependencies": {
42
+ "@lit-protocol/pkp-ethers": "^7.2.0",
43
+ "@lit-protocol/types": "^7.0.8",
44
+ "@types/express": "^5.0.1",
45
+ "chokidar-cli": "^3.0.0",
46
+ "live-server": "^1.2.2",
47
+ "typedoc": "0.27.9",
48
+ "typedoc-material-theme": "1.3.0",
49
+ "typedoc-plugin-extras": "^4.0.0",
50
+ "typedoc-plugin-zod": "^1.4.1",
51
+ "vercel": "^41.6.2"
52
+ },
53
+ "type": "commonjs"
54
+ }
@@ -0,0 +1,9 @@
1
+ import { VincentAppClientConfig, VincentWebAppClient } from './types';
2
+ /** Create a new {@link VincentWebAppClient} instance.
3
+ *
4
+ * - `appId` is the numeric app ID displayed for your app on the Vincent Dashboard
5
+ *
6
+ * @category Vincent SDK API
7
+ * */
8
+ export declare const getVincentWebAppClient: (appClientConfig: VincentAppClientConfig) => VincentWebAppClient;
9
+ //# sourceMappingURL=app.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"app.d.ts","sourceRoot":"","sources":["../../../src/app/app.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,sBAAsB,EACtB,mBAAmB,EACpB,MAAM,SAAS,CAAC;AAgBjB;;;;;KAKK;AACL,eAAO,MAAM,sBAAsB,GACjC,iBAAiB,sBAAsB,KACtC,mBAmBF,CAAC"}
@@ -0,0 +1,33 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getVincentWebAppClient = void 0;
4
+ const internal_1 = require("./internal");
5
+ const constants_1 = require("./constants");
6
+ const { isLoginUri, composeConsentUrl, removeSearchParam, decodeVincentJWTFromUri } = internal_1.uriHelpers;
7
+ const redirectToConsentPage = ({ appId, redirectUri, consentPageUrl, }) => window.open(composeConsentUrl(appId, redirectUri, consentPageUrl).toString(), '_self');
8
+ /** Create a new {@link VincentWebAppClient} instance.
9
+ *
10
+ * - `appId` is the numeric app ID displayed for your app on the Vincent Dashboard
11
+ *
12
+ * @category Vincent SDK API
13
+ * */
14
+ const getVincentWebAppClient = (appClientConfig) => {
15
+ const { appId } = appClientConfig;
16
+ return {
17
+ redirectToConsentPage: (redirectConsentPageConfig) => {
18
+ const { consentPageUrl, redirectUri } = redirectConsentPageConfig;
19
+ redirectToConsentPage({ appId, consentPageUrl, redirectUri });
20
+ },
21
+ isLogin: () => isLoginUri(window.location.href),
22
+ decodeVincentLoginJWT: (expectedAudience) => decodeVincentJWTFromUri(window.location.href, expectedAudience),
23
+ removeLoginJWTFromURI: () => {
24
+ const urlWithoutJWTSearchParam = removeSearchParam({
25
+ paramName: constants_1.JWT_URL_KEY,
26
+ uri: window.location.href,
27
+ });
28
+ window.history.replaceState({}, document.title, urlWithoutJWTSearchParam);
29
+ },
30
+ };
31
+ };
32
+ exports.getVincentWebAppClient = getVincentWebAppClient;
33
+ //# sourceMappingURL=app.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"app.js","sourceRoot":"","sources":["../../../src/app/app.ts"],"names":[],"mappings":";;;AAKA,yCAAwC;AACxC,2CAA0C;AAE1C,MAAM,EAAE,UAAU,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,uBAAuB,EAAE,GAAG,qBAAU,CAAC;AAEjG,MAAM,qBAAqB,GAAG,CAAC,EAC7B,KAAK,EACL,WAAW,EACX,cAAc,GAKf,EAAE,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,iBAAiB,CAAC,KAAK,EAAE,WAAW,EAAE,cAAc,CAAC,CAAC,QAAQ,EAAE,EAAE,OAAO,CAAC,CAAC;AAE7F;;;;;KAKK;AACE,MAAM,sBAAsB,GAAG,CACpC,eAAuC,EAClB,EAAE;IACvB,MAAM,EAAE,KAAK,EAAE,GAAG,eAAe,CAAC;IAElC,OAAO;QACL,qBAAqB,EAAE,CAAC,yBAA6D,EAAE,EAAE;YACvF,MAAM,EAAE,cAAc,EAAE,WAAW,EAAE,GAAG,yBAAyB,CAAC;YAClE,qBAAqB,CAAC,EAAE,KAAK,EAAE,cAAc,EAAE,WAAW,EAAE,CAAC,CAAC;QAChE,CAAC;QACD,OAAO,EAAE,GAAG,EAAE,CAAC,UAAU,CAAC,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC;QAC/C,qBAAqB,EAAE,CAAC,gBAAwB,EAAE,EAAE,CAClD,uBAAuB,CAAC,MAAM,CAAC,QAAQ,CAAC,IAAI,EAAE,gBAAgB,CAAC;QACjE,qBAAqB,EAAE,GAAG,EAAE;YAC1B,MAAM,wBAAwB,GAAG,iBAAiB,CAAC;gBACjD,SAAS,EAAE,uBAAW;gBACtB,GAAG,EAAE,MAAM,CAAC,QAAQ,CAAC,IAAI;aAC1B,CAAC,CAAC;YACH,MAAM,CAAC,OAAO,CAAC,YAAY,CAAC,EAAE,EAAE,QAAQ,CAAC,KAAK,EAAE,wBAAwB,CAAC,CAAC;QAC5E,CAAC;KACF,CAAC;AACJ,CAAC,CAAC;AArBW,QAAA,sBAAsB,0BAqBjC"}
@@ -0,0 +1,3 @@
1
+ export declare const PRODUCTION_VINCENT_DASHBOARD_URL = "https://dashboard.heyvincent.ai/";
2
+ export declare const JWT_URL_KEY = "jwt";
3
+ //# sourceMappingURL=constants.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../../src/app/constants.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,gCAAgC,qCAAqC,CAAC;AACnF,eAAO,MAAM,WAAW,QAAQ,CAAC"}
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.JWT_URL_KEY = exports.PRODUCTION_VINCENT_DASHBOARD_URL = void 0;
4
+ exports.PRODUCTION_VINCENT_DASHBOARD_URL = 'https://dashboard.heyvincent.ai/';
5
+ exports.JWT_URL_KEY = 'jwt';
6
+ //# sourceMappingURL=constants.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.js","sourceRoot":"","sources":["../../../src/app/constants.ts"],"names":[],"mappings":";;;AAAa,QAAA,gCAAgC,GAAG,kCAAkC,CAAC;AACtE,QAAA,WAAW,GAAG,KAAK,CAAC"}
@@ -0,0 +1,3 @@
1
+ import { getVincentWebAppClient } from './app';
2
+ export { getVincentWebAppClient };
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/app/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,MAAM,OAAO,CAAC;AAE/C,OAAO,EAAE,sBAAsB,EAAE,CAAC"}
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getVincentWebAppClient = void 0;
4
+ const app_1 = require("./app");
5
+ Object.defineProperty(exports, "getVincentWebAppClient", { enumerable: true, get: function () { return app_1.getVincentWebAppClient; } });
6
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/app/index.ts"],"names":[],"mappings":";;;AAAA,+BAA+C;AAEtC,uGAFA,4BAAsB,OAEA"}
@@ -0,0 +1,3 @@
1
+ import * as uriHelpers from './uriHelpers';
2
+ export { uriHelpers };
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/app/internal/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,UAAU,MAAM,cAAc,CAAC;AAE3C,OAAO,EAAE,UAAU,EAAE,CAAC"}
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.uriHelpers = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const uriHelpers = tslib_1.__importStar(require("./uriHelpers"));
6
+ exports.uriHelpers = uriHelpers;
7
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/app/internal/index.ts"],"names":[],"mappings":";;;;AAAA,iEAA2C;AAElC,gCAAU"}
@@ -0,0 +1,11 @@
1
+ export declare const decodeVincentJWTFromUri: (uri: string, expectedAudience: string) => {
2
+ decodedJWT: import("../..").VincentJWT;
3
+ jwtStr: string;
4
+ } | null;
5
+ export declare const isLoginUri: (uri: string) => boolean;
6
+ export declare function composeConsentUrl(appId: string, redirectUri: string, consentPageUrl?: string): URL;
7
+ export declare const removeSearchParam: ({ paramName, uri, }: {
8
+ paramName: string;
9
+ uri: string;
10
+ }) => string;
11
+ //# sourceMappingURL=uriHelpers.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"uriHelpers.d.ts","sourceRoot":"","sources":["../../../../src/app/internal/uriHelpers.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,uBAAuB,GAAI,KAAK,MAAM,EAAE,kBAAkB,MAAM;;;QAS5E,CAAC;AAEF,eAAO,MAAM,UAAU,GAAI,KAAK,MAAM,YAKrC,CAAC;AAEF,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,EAAE,cAAc,CAAC,EAAE,MAAM,OAK5F;AAED,eAAO,MAAM,iBAAiB,GAAI,qBAG/B;IACD,SAAS,EAAE,MAAM,CAAC;IAClB,GAAG,EAAE,MAAM,CAAC;CACb,KAAG,MAKH,CAAC"}
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.removeSearchParam = exports.isLoginUri = exports.decodeVincentJWTFromUri = void 0;
4
+ exports.composeConsentUrl = composeConsentUrl;
5
+ const constants_1 = require("../constants");
6
+ const validate_1 = require("../../jwt/core/validate");
7
+ const decodeVincentJWTFromUri = (uri, expectedAudience) => {
8
+ const url = new URL(uri);
9
+ const jwt = url.searchParams.get(constants_1.JWT_URL_KEY);
10
+ if (!jwt) {
11
+ return null;
12
+ }
13
+ return { decodedJWT: (0, validate_1.verifyJWT)(jwt, expectedAudience), jwtStr: jwt };
14
+ };
15
+ exports.decodeVincentJWTFromUri = decodeVincentJWTFromUri;
16
+ const isLoginUri = (uri) => {
17
+ const url = new URL(uri);
18
+ const loginJwt = url.searchParams.get(constants_1.JWT_URL_KEY);
19
+ return !!loginJwt;
20
+ };
21
+ exports.isLoginUri = isLoginUri;
22
+ function composeConsentUrl(appId, redirectUri, consentPageUrl) {
23
+ return new URL(`/appId/${appId}/consent?redirectUri=${redirectUri}`, consentPageUrl || constants_1.PRODUCTION_VINCENT_DASHBOARD_URL);
24
+ }
25
+ const removeSearchParam = ({ paramName, uri, }) => {
26
+ const url = new URL(uri);
27
+ url.searchParams.delete(paramName);
28
+ // Update the browser's history without reloading the page
29
+ return url.toString();
30
+ };
31
+ exports.removeSearchParam = removeSearchParam;
32
+ //# sourceMappingURL=uriHelpers.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"uriHelpers.js","sourceRoot":"","sources":["../../../../src/app/internal/uriHelpers.ts"],"names":[],"mappings":";;;AAqBA,8CAKC;AA1BD,4CAA6E;AAC7E,sDAAoD;AAE7C,MAAM,uBAAuB,GAAG,CAAC,GAAW,EAAE,gBAAwB,EAAE,EAAE;IAC/E,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,GAAG,CAAC,CAAC;IACzB,MAAM,GAAG,GAAG,GAAG,CAAC,YAAY,CAAC,GAAG,CAAC,uBAAW,CAAC,CAAC;IAE9C,IAAI,CAAC,GAAG,EAAE,CAAC;QACT,OAAO,IAAI,CAAC;IACd,CAAC;IAED,OAAO,EAAE,UAAU,EAAE,IAAA,oBAAS,EAAC,GAAG,EAAE,gBAAgB,CAAC,EAAE,MAAM,EAAE,GAAG,EAAE,CAAC;AACvE,CAAC,CAAC;AATW,QAAA,uBAAuB,2BASlC;AAEK,MAAM,UAAU,GAAG,CAAC,GAAW,EAAE,EAAE;IACxC,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,GAAG,CAAC,CAAC;IACzB,MAAM,QAAQ,GAAG,GAAG,CAAC,YAAY,CAAC,GAAG,CAAC,uBAAW,CAAC,CAAC;IAEnD,OAAO,CAAC,CAAC,QAAQ,CAAC;AACpB,CAAC,CAAC;AALW,QAAA,UAAU,cAKrB;AAEF,SAAgB,iBAAiB,CAAC,KAAa,EAAE,WAAmB,EAAE,cAAuB;IAC3F,OAAO,IAAI,GAAG,CACZ,UAAU,KAAK,wBAAwB,WAAW,EAAE,EACpD,cAAc,IAAI,4CAAgC,CACnD,CAAC;AACJ,CAAC;AAEM,MAAM,iBAAiB,GAAG,CAAC,EAChC,SAAS,EACT,GAAG,GAIJ,EAAU,EAAE;IACX,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,GAAG,CAAC,CAAC;IACzB,GAAG,CAAC,YAAY,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC;IACnC,0DAA0D;IAC1D,OAAO,GAAG,CAAC,QAAQ,EAAE,CAAC;AACxB,CAAC,CAAC;AAXW,QAAA,iBAAiB,qBAW5B"}
@@ -0,0 +1,119 @@
1
+ import { VincentJWT } from '../jwt/types';
2
+ /**
3
+ * @inline
4
+ * @hidden
5
+ */
6
+ export interface VincentAppClientConfig {
7
+ appId: string;
8
+ }
9
+ /**
10
+ * @inline
11
+ * @hidden
12
+ */
13
+ export interface RedirectToVincentConsentPageParams {
14
+ redirectUri: string;
15
+ /** This only needs to be provided for local development with the entire stack
16
+ * @hidden
17
+ * */
18
+ consentPageUrl?: string;
19
+ }
20
+ /**
21
+ * The Vincent Web Application Client is used in web apps to handle interactions with the Vincent app portal.
22
+ *
23
+ * - Consent page redirection
24
+ * - Authentication helpers that are browser specific
25
+ *
26
+ * @category Vincent Web App
27
+ */
28
+ export interface VincentWebAppClient {
29
+ /**
30
+ * Redirects the user to the Vincent consent page.
31
+ *
32
+ * If the user approves your app permissions, they will be redirected back to the `redirectUri`.
33
+ *
34
+ * Use {@link VincentWebAppClient.isLogin} to detect if a user has just opened your app via the consent page
35
+ *
36
+ * Use {@link VincentWebAppClient.decodeVincentLoginJWT} to decode and verify the {@link VincentJWT} from the page URI, and store it for later usage
37
+ *
38
+ * NOTE: You must register the `redirectUri` on your Vincent app for it to be considered a valid redirect target
39
+ *
40
+ * @example
41
+ * ```typescript
42
+ * import { getVincentWebAppClient } from '@lit-protocol/vincent-app-sdk';
43
+ *
44
+ * const vincentAppClient = getVincentWebAppClient({ appId: MY_APP_ID });
45
+ * // ... In your app logic:
46
+ * if(vincentAppClient.isLogin()) {
47
+ * // Handle app logic for the user has just logged in
48
+ * const { decoded, jwt } = vincentAppClient.decodeVincentLoginJWT(EXPECTED_AUDIENCE);
49
+ * // Store `jwt` for later usage; the user is now logged in.
50
+ * } else {
51
+ * // Handle app logic for the user is already logged in (check for stored & unexpired JWT)
52
+ * // ...
53
+ *
54
+ * // Handle app logic for the user is not yet logged in
55
+ * vincentAppClient.redirectToConsentPage({ redirectUri: window.location.href });
56
+ * }
57
+ * ```
58
+ * @function
59
+ * @inline
60
+ */
61
+ redirectToConsentPage: (redirectConfig: RedirectToVincentConsentPageParams) => void;
62
+ /**
63
+ * Determines whether the current window location is a login URI associated with Vincent
64
+
65
+ * You can use this to detect if a user is loading your app as a result of approving permissions
66
+ * on the Vincent consent page -- e.g. they just logged in
67
+ *
68
+ * See: {@link VincentWebAppClient.redirectToConsentPage} for example usage
69
+ *
70
+ * @function
71
+ * @inline
72
+ * @returns `true` if the current window URI is a login URI, otherwise `false`.
73
+ */
74
+ isLogin: () => boolean;
75
+ /**
76
+ * Extracts a decoded/parsed Vincent JWT (JSON Web Token) from the current window location
77
+ *
78
+ * The token is verified as part of this process; if the token is invalid or expired, this method will throw.
79
+ *
80
+ * See: {@link VincentWebAppClient.redirectToConsentPage} for example usage
81
+ *
82
+ * @param { string } expectedAudience Provide a valid `redirectUri` for your app; this is typically your app's origin
83
+ * @function
84
+ * @inline
85
+ * @returns {decodedJWT: VincentJWT; jwtStr: string | null} `null` if no JWT is found, otherwise both the decoded jwt and the original JWT string is returned
86
+ * @throws {Error} If there was a JWT in the page URL, but it was invalid / could not be verified
87
+ */
88
+ decodeVincentLoginJWT: (expectedAudience: string) => {
89
+ decodedJWT: VincentJWT;
90
+ jwtStr: string;
91
+ } | null;
92
+ /**
93
+ * Removes the Vincent login JWT from the current window URI.
94
+ *
95
+ * This is useful for cleaning up the URL after decoding and storing the JWT,
96
+ * ensuring the redirect URL looks clean for the user and no sensitive information
97
+ * is exposed in the URI.
98
+ *
99
+ * @example
100
+ * ```typescript
101
+ * import { getVincentWebAppClient } from '@lit-protocol/vincent-app-sdk';
102
+ *
103
+ * const vincentAppClient = getVincentWebAppClient({ appId: MY_APP_ID });
104
+ *
105
+ * if (vincentAppClient.isLogin()) {
106
+ * const { decodedJWT, jwtStr } = vincentAppClient.decodeVincentLoginJWT();
107
+ * // Store the JWT and use it for authentication
108
+ *
109
+ * // Now we can remove the JWT from the URL searchParams
110
+ * vincentAppClient.removeLoginJWTFromURI();
111
+ * }
112
+ * ```
113
+ *
114
+ * @function
115
+ * @inline
116
+ */
117
+ removeLoginJWTFromURI: () => void;
118
+ }
119
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/app/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAE1C;;;GAGG;AACH,MAAM,WAAW,sBAAsB;IACrC,KAAK,EAAE,MAAM,CAAC;CACf;AAED;;;GAGG;AACH,MAAM,WAAW,kCAAkC;IACjD,WAAW,EAAE,MAAM,CAAC;IACpB;;SAEK;IACL,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB;AAED;;;;;;;GAOG;AACH,MAAM,WAAW,mBAAmB;IAClC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA+BG;IACH,qBAAqB,EAAE,CAAC,cAAc,EAAE,kCAAkC,KAAK,IAAI,CAAC;IAEpF;;;;;;;;;;;OAWG;IACH,OAAO,EAAE,MAAM,OAAO,CAAC;IAEvB;;;;;;;;;;;;OAYG;IACH,qBAAqB,EAAE,CACrB,gBAAgB,EAAE,MAAM,KACrB;QAAE,UAAU,EAAE,UAAU,CAAC;QAAC,MAAM,EAAE,MAAM,CAAA;KAAE,GAAG,IAAI,CAAC;IAEvD;;;;;;;;;;;;;;;;;;;;;;;;OAwBG;IACH,qBAAqB,EAAE,MAAM,IAAI,CAAC;CACnC"}
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/app/types.ts"],"names":[],"mappings":""}
@@ -0,0 +1,79 @@
1
+ import type { NextFunction, Request, Response } from 'express';
2
+ import { AuthenticatedRequestHandler } from './types';
3
+ /**
4
+ * Higher-order helper function to enforce authentication on a request handler and assert the type of `Request` that is
5
+ * passed into your authenticated Express routes.
6
+ *
7
+ * This function takes an `AuthenticatedRequestHandler` and returns a new request handler
8
+ * that verifies that the request has a 'user' property with the correct shape on it before calling the original handler.
9
+ * If the `req.user` property isn't the correct shape, it sends a `401 Unauthorized` response to the client.
10
+ *
11
+ * NOTE: This does not verify signatures or any other content -- use `getAuthenticateUserExpressHandler` to create a
12
+ * middleware that does those things and ensure that your routes use it.
13
+ *
14
+ * See [express.js documentation](https://expressjs.com/en/guide/writing-middleware.html) for details on writing your route handler
15
+ * @example
16
+ * ```typescript
17
+ * import { expressAuthHelpers } from '@lit-protocol/vincent-app-sdk';
18
+ * const { authenticatedRequestHandler, getAuthenticateUserExpressHandler } = expressAuthHelpers;
19
+ *
20
+ * import type { ExpressAuthHelpers } from '@lit-protocol/vincent-app-sdk';
21
+ *
22
+ * // Define an authenticated route handler
23
+ * const getUserProfile = async (req: ExpressAuthHelpers['AuthenticatedRequest'], res: Response) => {
24
+ * // Access authenticated user information
25
+ * const { pkpAddress } = req.user;
26
+ *
27
+ * // Fetch and return user data
28
+ * const userData = await userRepository.findByAddress(pkpAddress);
29
+ * res.json(userData);
30
+ * };
31
+ *
32
+ * // Use in Express route with authentication
33
+ * app.get('/profile', authenticateUser, authenticatedRequestHandler(getUserProfile));
34
+ * ```
35
+ */
36
+ export declare const authenticatedRequestHandler: (handler: AuthenticatedRequestHandler) => (req: Request, res: Response, next: NextFunction) => void | Promise<void>;
37
+ /**
38
+ * Creates an Express middleware function to authenticate a user using a JWT token.
39
+ *
40
+ * This middleware checks the `Authorization` header for a Bearer token, verifies the token, and checks its audience.
41
+ * If the token is valid, it attaches the user information (decoded JWT, raw token, and PKP address) to the request object as `req.user`.
42
+ * If the token is missing or invalid, it returns a 401 Unauthorized response with an error message.
43
+ *
44
+ * NOTE: Wrap your route handler functions with `authenticatedRequestHandler()` to assert the type of `Request` and to
45
+ * ensure that `req.user` was correctly set before your route handler is run.
46
+ *
47
+ * See [express.js documentation](https://expressjs.com/en/guide/writing-middleware.html) for details on writing your route handler
48
+ *
49
+ * @example
50
+ * ```typescript
51
+ * import { expressAuthHelpers } from '@lit-protocol/vincent-app-sdk';
52
+ * const { authenticatedRequestHandler, getAuthenticateUserExpressHandler } = expressAuthHelpers;
53
+ *
54
+ * import type { ExpressAuthHelpers } from '@lit-protocol/vincent-app-sdk';
55
+ *
56
+ * // In your environment configuration
57
+ * const ALLOWED_AUDIENCE = 'https://yourapp.example.com';
58
+ *
59
+ * // Create the authentication middleware
60
+ * const authenticateUser = getAuthenticateUserExpressHandler(ALLOWED_AUDIENCE);
61
+ *
62
+ * // Define a handler that requires authentication
63
+ * const getProtectedResource = (req: ExpressAuthHelpers['AuthenticatedRequest'], res: Response) => {
64
+ * // The request is now authenticated
65
+ * // No need for type casting as the handler is properly typed
66
+ * const { pkpAddress } = req.user;
67
+ * res.json({ message: `Hello, user with PKP address ${pkpAddress}` });
68
+ * };
69
+ *
70
+ * // Apply to routes that require authentication by using authenticatedRequestHandler
71
+ * app.get('/protected-resource', authenticateUser, authenticatedRequestHandler(getProtectedResource));
72
+ * ```
73
+ *
74
+ * You can see the source for `getAuthenticateUserExpressHandler()` below; use this as a reference to implement
75
+ * your own midddleware/authentication for other frameworks! Pull requests are welcome.
76
+ * {@includeCode ./express.ts#expressHandlerTSDocExample}
77
+ */
78
+ export declare const getAuthenticateUserExpressHandler: (allowedAudience: string) => (req: Request, res: Response, next: NextFunction) => Promise<void>;
79
+ //# sourceMappingURL=express.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"express.d.ts","sourceRoot":"","sources":["../../../src/express-authentication-middleware/express.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAK/D,OAAO,EAAwB,2BAA2B,EAAE,MAAM,SAAS,CAAC;AAsB5E;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AACH,eAAO,MAAM,2BAA2B,GACrC,SAAS,2BAA2B,MAAM,KAAK,OAAO,EAAE,KAAK,QAAQ,EAAE,MAAM,YAAY,yBAOzF,CAAC;AAEJ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwCG;AAEH,eAAO,MAAM,iCAAiC,GAC3C,iBAAiB,MAAM,MAAY,KAAK,OAAO,EAAE,KAAK,QAAQ,EAAE,MAAM,YAAY,kBAmClF,CAAC"}