@lit-protocol/vincent-app-sdk 1.0.2 → 1.0.3-beta.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/CONTRIBUTING.md +2 -2
- package/README.md +12 -11
- package/dist/CONTRIBUTING.md +2 -2
- package/dist/README.md +12 -11
- package/dist/package.json +31 -2
- package/dist/src/expressMiddleware/express.d.ts +63 -0
- package/dist/src/expressMiddleware/express.d.ts.map +1 -0
- package/dist/src/expressMiddleware/express.js +125 -0
- package/dist/src/expressMiddleware/express.js.map +1 -0
- package/dist/src/expressMiddleware/index.d.ts +14 -0
- package/dist/src/expressMiddleware/index.d.ts.map +1 -0
- package/dist/src/expressMiddleware/index.js +17 -0
- package/dist/src/expressMiddleware/index.js.map +1 -0
- package/dist/src/expressMiddleware/types.d.ts +31 -0
- package/dist/src/expressMiddleware/types.d.ts.map +1 -0
- package/dist/src/expressMiddleware/types.js.map +1 -0
- package/dist/src/index.d.ts +1 -19
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +0 -19
- package/dist/src/index.js.map +1 -1
- package/dist/src/internal/LitNodeClient/LitNodeClientInstance.d.ts +1 -1
- package/dist/src/internal/LitNodeClient/LitNodeClientInstance.d.ts.map +1 -1
- package/dist/src/internal/LitNodeClient/LitNodeClientInstance.js.map +1 -1
- package/dist/src/internal/LitNodeClient/getLitNodeClient.d.ts +2 -2
- package/dist/src/internal/LitNodeClient/getLitNodeClient.d.ts.map +1 -1
- package/dist/src/jwt/accessors.d.ts +8 -0
- package/dist/src/jwt/accessors.d.ts.map +1 -0
- package/dist/src/jwt/accessors.js +15 -0
- package/dist/src/jwt/accessors.js.map +1 -0
- package/dist/src/jwt/core/create.d.ts +2 -19
- package/dist/src/jwt/core/create.d.ts.map +1 -1
- package/dist/src/jwt/core/create.js +9 -28
- package/dist/src/jwt/core/create.js.map +1 -1
- package/dist/src/jwt/core/isExpired.d.ts +9 -0
- package/dist/src/jwt/core/isExpired.d.ts.map +1 -0
- package/dist/src/jwt/core/{utils/isJWTExpired.js → isExpired.js} +4 -3
- package/dist/src/jwt/core/isExpired.js.map +1 -0
- package/dist/src/jwt/core/utils/base64.d.ts +14 -0
- package/dist/src/jwt/core/utils/base64.d.ts.map +1 -0
- package/dist/src/jwt/core/utils/base64.js +54 -0
- package/dist/src/jwt/core/utils/base64.js.map +1 -0
- package/dist/src/jwt/core/utils/index.d.ts +0 -1
- package/dist/src/jwt/core/utils/index.d.ts.map +1 -1
- package/dist/src/jwt/core/utils/index.js +1 -3
- package/dist/src/jwt/core/utils/index.js.map +1 -1
- package/dist/src/jwt/core/utils/processJWTSignature.d.ts.map +1 -1
- package/dist/src/jwt/core/utils/processJWTSignature.js +2 -9
- package/dist/src/jwt/core/utils/processJWTSignature.js.map +1 -1
- package/dist/src/jwt/core/validate.d.ts +28 -22
- package/dist/src/jwt/core/validate.d.ts.map +1 -1
- package/dist/src/jwt/core/validate.js +82 -35
- package/dist/src/jwt/core/validate.js.map +1 -1
- package/dist/src/jwt/index.d.ts +15 -63
- package/dist/src/jwt/index.d.ts.map +1 -1
- package/dist/src/jwt/index.js +24 -64
- package/dist/src/jwt/index.js.map +1 -1
- package/dist/src/jwt/typeGuards.d.ts +14 -0
- package/dist/src/jwt/typeGuards.d.ts.map +1 -0
- package/dist/src/jwt/typeGuards.js +32 -0
- package/dist/src/jwt/typeGuards.js.map +1 -0
- package/dist/src/jwt/types.d.ts +32 -22
- package/dist/src/jwt/types.d.ts.map +1 -1
- package/dist/src/toolClient/constants.d.ts +2 -0
- package/dist/src/toolClient/constants.d.ts.map +1 -0
- package/dist/src/toolClient/constants.js +5 -0
- package/dist/src/toolClient/constants.js.map +1 -0
- package/dist/src/toolClient/execute/generateVincentToolSessionSigs.d.ts +1 -1
- package/dist/src/toolClient/execute/generateVincentToolSessionSigs.d.ts.map +1 -1
- package/dist/src/toolClient/execute/generateVincentToolSessionSigs.js.map +1 -1
- package/dist/src/toolClient/execute/resultCreators.d.ts +13 -11
- package/dist/src/toolClient/execute/resultCreators.d.ts.map +1 -1
- package/dist/src/toolClient/execute/resultCreators.js +4 -2
- package/dist/src/toolClient/execute/resultCreators.js.map +1 -1
- package/dist/src/toolClient/execute/types.d.ts +6 -3
- package/dist/src/toolClient/execute/types.d.ts.map +1 -1
- package/dist/src/toolClient/index.d.ts +13 -1
- package/dist/src/toolClient/index.d.ts.map +1 -1
- package/dist/src/toolClient/index.js +19 -2
- package/dist/src/toolClient/index.js.map +1 -1
- package/dist/src/toolClient/precheck/resultCreators.d.ts +13 -9
- package/dist/src/toolClient/precheck/resultCreators.d.ts.map +1 -1
- package/dist/src/toolClient/precheck/resultCreators.js +4 -2
- package/dist/src/toolClient/precheck/resultCreators.js.map +1 -1
- package/dist/src/toolClient/precheck/runPolicyPrechecks.d.ts +4 -3
- package/dist/src/toolClient/precheck/runPolicyPrechecks.d.ts.map +1 -1
- package/dist/src/toolClient/precheck/runPolicyPrechecks.js +29 -17
- package/dist/src/toolClient/precheck/runPolicyPrechecks.js.map +1 -1
- package/dist/src/toolClient/precheck/types.d.ts +8 -6
- package/dist/src/toolClient/precheck/types.d.ts.map +1 -1
- package/dist/src/toolClient/typeGuards.d.ts +22 -13
- package/dist/src/toolClient/typeGuards.d.ts.map +1 -1
- package/dist/src/toolClient/typeGuards.js +32 -13
- package/dist/src/toolClient/typeGuards.js.map +1 -1
- package/dist/src/toolClient/types.d.ts.map +1 -1
- package/dist/src/toolClient/vincentToolClient.d.ts +53 -5
- package/dist/src/toolClient/vincentToolClient.d.ts.map +1 -1
- package/dist/src/toolClient/vincentToolClient.js +124 -30
- package/dist/src/toolClient/vincentToolClient.js.map +1 -1
- package/dist/src/type-inference-verification/tool-client-inference.d.ts.map +1 -1
- package/dist/src/type-inference-verification/tool-client-inference.js +3 -1
- package/dist/src/type-inference-verification/tool-client-inference.js.map +1 -1
- package/dist/src/utils/delegation.d.ts +4 -18
- package/dist/src/utils/delegation.d.ts.map +1 -1
- package/dist/src/utils/delegation.js +10 -79
- package/dist/src/utils/delegation.js.map +1 -1
- package/dist/src/utils/index.d.ts +2 -2
- package/dist/src/utils/index.d.ts.map +1 -1
- package/dist/src/utils/index.js +1 -1
- package/dist/src/utils/index.js.map +1 -1
- package/dist/src/utils/typedocRoot.d.ts +7 -0
- package/dist/src/utils/typedocRoot.d.ts.map +1 -0
- package/dist/src/utils/typedocRoot.js +13 -0
- package/dist/src/utils/typedocRoot.js.map +1 -0
- package/dist/src/utils/types.d.ts +15 -0
- package/dist/src/utils/types.d.ts.map +1 -0
- package/dist/src/{app → utils}/types.js.map +1 -1
- package/dist/src/webAuthClient/app.d.ts +7 -0
- package/dist/src/webAuthClient/app.d.ts.map +1 -0
- package/dist/src/webAuthClient/app.js +39 -0
- package/dist/src/webAuthClient/app.js.map +1 -0
- package/dist/src/webAuthClient/constants.d.ts.map +1 -0
- package/dist/src/webAuthClient/constants.js.map +1 -0
- package/dist/src/webAuthClient/index.d.ts +13 -0
- package/dist/src/webAuthClient/index.d.ts.map +1 -0
- package/dist/src/webAuthClient/index.js +15 -0
- package/dist/src/webAuthClient/index.js.map +1 -0
- package/dist/src/webAuthClient/internal/index.d.ts.map +1 -0
- package/dist/src/webAuthClient/internal/index.js.map +1 -0
- package/dist/src/webAuthClient/internal/uriHelpers.d.ts +15 -0
- package/dist/src/webAuthClient/internal/uriHelpers.d.ts.map +1 -0
- package/dist/src/{app → webAuthClient}/internal/uriHelpers.js +12 -6
- package/dist/src/webAuthClient/internal/uriHelpers.js.map +1 -0
- package/dist/src/{app → webAuthClient}/types.d.ts +33 -41
- package/dist/src/webAuthClient/types.d.ts.map +1 -0
- package/dist/src/{types.js.map → webAuthClient/types.js.map} +1 -1
- package/package.json +30 -3
- package/dist/src/app/app.d.ts +0 -9
- package/dist/src/app/app.d.ts.map +0 -1
- package/dist/src/app/app.js +0 -33
- package/dist/src/app/app.js.map +0 -1
- package/dist/src/app/constants.d.ts.map +0 -1
- package/dist/src/app/constants.js.map +0 -1
- package/dist/src/app/index.d.ts +0 -3
- package/dist/src/app/index.d.ts.map +0 -1
- package/dist/src/app/index.js +0 -6
- package/dist/src/app/index.js.map +0 -1
- package/dist/src/app/internal/index.d.ts.map +0 -1
- package/dist/src/app/internal/index.js.map +0 -1
- package/dist/src/app/internal/uriHelpers.d.ts +0 -11
- package/dist/src/app/internal/uriHelpers.d.ts.map +0 -1
- package/dist/src/app/internal/uriHelpers.js.map +0 -1
- package/dist/src/app/types.d.ts.map +0 -1
- package/dist/src/express-authentication-middleware/express.d.ts +0 -79
- package/dist/src/express-authentication-middleware/express.d.ts.map +0 -1
- package/dist/src/express-authentication-middleware/express.js +0 -137
- package/dist/src/express-authentication-middleware/express.js.map +0 -1
- package/dist/src/express-authentication-middleware/index.d.ts +0 -43
- package/dist/src/express-authentication-middleware/index.d.ts.map +0 -1
- package/dist/src/express-authentication-middleware/index.js +0 -47
- package/dist/src/express-authentication-middleware/index.js.map +0 -1
- package/dist/src/express-authentication-middleware/types.d.ts +0 -25
- package/dist/src/express-authentication-middleware/types.d.ts.map +0 -1
- package/dist/src/express-authentication-middleware/types.js.map +0 -1
- package/dist/src/jwt/core/utils/isJWTExpired.d.ts +0 -8
- package/dist/src/jwt/core/utils/isJWTExpired.d.ts.map +0 -1
- package/dist/src/jwt/core/utils/isJWTExpired.js.map +0 -1
- package/dist/src/types.d.ts +0 -5
- package/dist/src/types.d.ts.map +0 -1
- package/dist/src/utils/contracts.d.ts +0 -49
- package/dist/src/utils/contracts.d.ts.map +0 -1
- package/dist/src/utils/contracts.js +0 -92
- package/dist/src/utils/contracts.js.map +0 -1
- package/dist/src/utils/pkp.d.ts +0 -12
- package/dist/src/utils/pkp.d.ts.map +0 -1
- package/dist/src/utils/pkp.js +0 -19
- package/dist/src/utils/pkp.js.map +0 -1
- /package/dist/src/{app → expressMiddleware}/types.js +0 -0
- /package/dist/src/{express-authentication-middleware → utils}/types.js +0 -0
- /package/dist/src/{app → webAuthClient}/constants.d.ts +0 -0
- /package/dist/src/{app → webAuthClient}/constants.js +0 -0
- /package/dist/src/{app → webAuthClient}/internal/index.d.ts +0 -0
- /package/dist/src/{app → webAuthClient}/internal/index.js +0 -0
- /package/dist/src/{types.js → webAuthClient/types.js} +0 -0
package/CONTRIBUTING.md
CHANGED
|
@@ -43,9 +43,9 @@ pnpm typedoc
|
|
|
43
43
|
|
|
44
44
|
## SDK Components
|
|
45
45
|
|
|
46
|
-
###
|
|
46
|
+
### WebAuthClient
|
|
47
47
|
|
|
48
|
-
The Vincent Web
|
|
48
|
+
The Vincent Web Auth Client provides methods for managing user authentication, JWT tokens, and consent flows in Vincent applications.
|
|
49
49
|
|
|
50
50
|
### VincentToolClient
|
|
51
51
|
|
package/README.md
CHANGED
|
@@ -10,9 +10,9 @@ npm install @lit-protocol/vincent-app-sdk
|
|
|
10
10
|
|
|
11
11
|
# Client (Web)
|
|
12
12
|
|
|
13
|
-
##
|
|
13
|
+
## WebAuthClient
|
|
14
14
|
|
|
15
|
-
The Vincent Web
|
|
15
|
+
The Vincent Web Auth Client provides methods for managing user authentication, JWT tokens, and consent flows in Vincent applications.
|
|
16
16
|
|
|
17
17
|
### Methods
|
|
18
18
|
|
|
@@ -44,11 +44,10 @@ Removes the login JWT parameter from the current URI. Call this after you have v
|
|
|
44
44
|
### Basic Usage
|
|
45
45
|
|
|
46
46
|
```typescript
|
|
47
|
-
import {
|
|
47
|
+
import { getWebAuthClient } from '@lit-protocol/vincent-app-sdk/webaAthClient';
|
|
48
|
+
import { isExpired } from '@lit-protocol/vincent-app-sdk/jwt';
|
|
48
49
|
|
|
49
|
-
const {
|
|
50
|
-
|
|
51
|
-
const vincentAppClient = getVincentWebAppClient({ appId: MY_APP_ID });
|
|
50
|
+
const vincentAppClient = getWebAuthClient({ appId: MY_APP_ID });
|
|
52
51
|
// ... In your app logic:
|
|
53
52
|
if (vincentAppClient.isLogin()) {
|
|
54
53
|
// Handle app logic for the user has just logged in
|
|
@@ -101,7 +100,7 @@ Executes a Vincent Tool with the provided parameters.
|
|
|
101
100
|
### Tool execution
|
|
102
101
|
|
|
103
102
|
```typescript
|
|
104
|
-
import { getVincentToolClient } from '@lit-protocol/vincent-app-sdk';
|
|
103
|
+
import { getVincentToolClient } from '@lit-protocol/vincent-app-sdk/toolClient';
|
|
105
104
|
// Import the tool you want to execute
|
|
106
105
|
import { bundledVincentTool as erc20BundledTool } from '@lit-protocol/vincent-tool-erc20-approval';
|
|
107
106
|
|
|
@@ -148,17 +147,19 @@ A basic Express authentication middleware factory function is provided with the
|
|
|
148
147
|
See getAuthenticateUserExpressHandler() documentation to see the source for the express authentication route handler
|
|
149
148
|
|
|
150
149
|
```typescript
|
|
151
|
-
import {
|
|
152
|
-
|
|
150
|
+
import {
|
|
151
|
+
authenticatedRequestHandler,
|
|
152
|
+
getAuthenticateUserExpressHandler,
|
|
153
|
+
} from '@lit-protocol/vincent-app-sdk/expressMiddleware';
|
|
153
154
|
|
|
154
|
-
import type {
|
|
155
|
+
import type { AuthenticatedRequest } from '@lit-protocol/vincent-app-sdk/expressMiddleware';
|
|
155
156
|
|
|
156
157
|
const { ALLOWED_AUDIENCE } = process.env;
|
|
157
158
|
|
|
158
159
|
const authenticateUserMiddleware = getAuthenticateUserExpressHandler(ALLOWED_AUDIENCE);
|
|
159
160
|
|
|
160
161
|
// Define an authenticated route handler
|
|
161
|
-
const getUserProfile = async (req:
|
|
162
|
+
const getUserProfile = async (req: AuthenticatedRequest, res: Response) => {
|
|
162
163
|
// Access authenticated user information
|
|
163
164
|
const { pkpAddress } = req.user;
|
|
164
165
|
|
package/dist/CONTRIBUTING.md
CHANGED
|
@@ -43,9 +43,9 @@ pnpm typedoc
|
|
|
43
43
|
|
|
44
44
|
## SDK Components
|
|
45
45
|
|
|
46
|
-
###
|
|
46
|
+
### WebAuthClient
|
|
47
47
|
|
|
48
|
-
The Vincent Web
|
|
48
|
+
The Vincent Web Auth Client provides methods for managing user authentication, JWT tokens, and consent flows in Vincent applications.
|
|
49
49
|
|
|
50
50
|
### VincentToolClient
|
|
51
51
|
|
package/dist/README.md
CHANGED
|
@@ -10,9 +10,9 @@ npm install @lit-protocol/vincent-app-sdk
|
|
|
10
10
|
|
|
11
11
|
# Client (Web)
|
|
12
12
|
|
|
13
|
-
##
|
|
13
|
+
## WebAuthClient
|
|
14
14
|
|
|
15
|
-
The Vincent Web
|
|
15
|
+
The Vincent Web Auth Client provides methods for managing user authentication, JWT tokens, and consent flows in Vincent applications.
|
|
16
16
|
|
|
17
17
|
### Methods
|
|
18
18
|
|
|
@@ -44,11 +44,10 @@ Removes the login JWT parameter from the current URI. Call this after you have v
|
|
|
44
44
|
### Basic Usage
|
|
45
45
|
|
|
46
46
|
```typescript
|
|
47
|
-
import {
|
|
47
|
+
import { getWebAuthClient } from '@lit-protocol/vincent-app-sdk/webaAthClient';
|
|
48
|
+
import { isExpired } from '@lit-protocol/vincent-app-sdk/jwt';
|
|
48
49
|
|
|
49
|
-
const {
|
|
50
|
-
|
|
51
|
-
const vincentAppClient = getVincentWebAppClient({ appId: MY_APP_ID });
|
|
50
|
+
const vincentAppClient = getWebAuthClient({ appId: MY_APP_ID });
|
|
52
51
|
// ... In your app logic:
|
|
53
52
|
if (vincentAppClient.isLogin()) {
|
|
54
53
|
// Handle app logic for the user has just logged in
|
|
@@ -101,7 +100,7 @@ Executes a Vincent Tool with the provided parameters.
|
|
|
101
100
|
### Tool execution
|
|
102
101
|
|
|
103
102
|
```typescript
|
|
104
|
-
import { getVincentToolClient } from '@lit-protocol/vincent-app-sdk';
|
|
103
|
+
import { getVincentToolClient } from '@lit-protocol/vincent-app-sdk/toolClient';
|
|
105
104
|
// Import the tool you want to execute
|
|
106
105
|
import { bundledVincentTool as erc20BundledTool } from '@lit-protocol/vincent-tool-erc20-approval';
|
|
107
106
|
|
|
@@ -148,17 +147,19 @@ A basic Express authentication middleware factory function is provided with the
|
|
|
148
147
|
See getAuthenticateUserExpressHandler() documentation to see the source for the express authentication route handler
|
|
149
148
|
|
|
150
149
|
```typescript
|
|
151
|
-
import {
|
|
152
|
-
|
|
150
|
+
import {
|
|
151
|
+
authenticatedRequestHandler,
|
|
152
|
+
getAuthenticateUserExpressHandler,
|
|
153
|
+
} from '@lit-protocol/vincent-app-sdk/expressMiddleware';
|
|
153
154
|
|
|
154
|
-
import type {
|
|
155
|
+
import type { AuthenticatedRequest } from '@lit-protocol/vincent-app-sdk/expressMiddleware';
|
|
155
156
|
|
|
156
157
|
const { ALLOWED_AUDIENCE } = process.env;
|
|
157
158
|
|
|
158
159
|
const authenticateUserMiddleware = getAuthenticateUserExpressHandler(ALLOWED_AUDIENCE);
|
|
159
160
|
|
|
160
161
|
// Define an authenticated route handler
|
|
161
|
-
const getUserProfile = async (req:
|
|
162
|
+
const getUserProfile = async (req: AuthenticatedRequest, res: Response) => {
|
|
162
163
|
// Access authenticated user information
|
|
163
164
|
const { pkpAddress } = req.user;
|
|
164
165
|
|
package/dist/package.json
CHANGED
|
@@ -13,8 +13,34 @@
|
|
|
13
13
|
"node": "^20.11.1",
|
|
14
14
|
"pnpm": "10.7.0"
|
|
15
15
|
},
|
|
16
|
-
"
|
|
17
|
-
|
|
16
|
+
"exports": {
|
|
17
|
+
"./package.json": "./package.json",
|
|
18
|
+
"./jwt": {
|
|
19
|
+
"import": "./dist/src/jwt/index.js",
|
|
20
|
+
"require": "./dist/src/jwt/index.js",
|
|
21
|
+
"types": "./dist/src/jwt/index.d.ts"
|
|
22
|
+
},
|
|
23
|
+
"./toolClient": {
|
|
24
|
+
"import": "./dist/src/toolClient/index.js",
|
|
25
|
+
"require": "./dist/src/toolClient/index.js",
|
|
26
|
+
"types": "./dist/src/toolClient/index.d.ts"
|
|
27
|
+
},
|
|
28
|
+
"./webAuthClient": {
|
|
29
|
+
"import": "./dist/src/webAuthClient/index.js",
|
|
30
|
+
"require": "./dist/src/webAuthClient/index.js",
|
|
31
|
+
"types": "./dist/src/webAuthClient/index.d.ts"
|
|
32
|
+
},
|
|
33
|
+
"./expressMiddleware": {
|
|
34
|
+
"import": "./dist/src/expressMiddleware/index.js",
|
|
35
|
+
"require": "./dist/src/expressMiddleware/index.js",
|
|
36
|
+
"types": "./dist/src/expressMiddleware/index.d.ts"
|
|
37
|
+
},
|
|
38
|
+
"./utils": {
|
|
39
|
+
"import": "./dist/src/utils/index.js",
|
|
40
|
+
"require": "./dist/src/utils/index.js",
|
|
41
|
+
"types": "./dist/src/utils/index.d.ts"
|
|
42
|
+
}
|
|
43
|
+
},
|
|
18
44
|
"keywords": [
|
|
19
45
|
"jwt",
|
|
20
46
|
"authentication",
|
|
@@ -29,6 +55,7 @@
|
|
|
29
55
|
"@lit-protocol/auth-helpers": "^7.0.9",
|
|
30
56
|
"@lit-protocol/constants": "^7.0.8",
|
|
31
57
|
"@lit-protocol/lit-node-client": "^7.0.8",
|
|
58
|
+
"@lit-protocol/vincent-contracts-sdk": "workspace:*",
|
|
32
59
|
"@lit-protocol/vincent-tool-sdk": "workspace:*",
|
|
33
60
|
"@noble/secp256k1": "^2.2.3",
|
|
34
61
|
"did-jwt": "^8.0.8",
|
|
@@ -53,5 +80,7 @@
|
|
|
53
80
|
"typedoc-plugin-zod": "^1.4.1",
|
|
54
81
|
"vercel": "^41.6.2"
|
|
55
82
|
},
|
|
83
|
+
"types": "./src/index.d.ts",
|
|
84
|
+
"main": "./src/index.js",
|
|
56
85
|
"type": "commonjs"
|
|
57
86
|
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import type { NextFunction, Request, Response } from 'express';
|
|
2
|
+
import type { AuthenticatedRequestHandler } from './types';
|
|
3
|
+
/** Returns an Express middleware function to authenticate a user using a JWT token, and a type-guard wrapper function
|
|
4
|
+
* for type-safe usage of route handlers guarded by the middleware.
|
|
5
|
+
*
|
|
6
|
+
* The `middleware()` function:
|
|
7
|
+
* - Checks the `Authorization` header for a Bearer token, verifies the token, and checks its audience.
|
|
8
|
+
* - If the token is valid, it attaches the user information (decoded JWT, and raw JWT string) to the request object
|
|
9
|
+
* - If the token is missing or invalid, it returns a 401 Unauthorized response with an error message.
|
|
10
|
+
*
|
|
11
|
+
* Designate what field on `req` should be set with the JWT with the `userKey` configuration option.
|
|
12
|
+
*
|
|
13
|
+
* The `handler()` function:
|
|
14
|
+
* - Provides a type-safe reference to `req` where the `userKey` you have provided is correctly inferred to the appropriate type
|
|
15
|
+
* - Note that it is still your responsibility to ensure you have attached the `middleware` somewhere in the chain before you use the `handler()`
|
|
16
|
+
* - If you forget, the `handler()` function will throw an error if the expected `req[userKey]` does not exist.
|
|
17
|
+
*
|
|
18
|
+
* See [express.js documentation](https://expressjs.com/en/guide/writing-middleware.html) for details on writing your route handler
|
|
19
|
+
* @category API
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* ```typescript
|
|
23
|
+
* import { createVincentUserMiddleware } from '@lit-protocol/vincent-app-sdk/expressMiddleware';
|
|
24
|
+
*
|
|
25
|
+
* // In your environment configuration
|
|
26
|
+
* const ALLOWED_AUDIENCE = 'https://yourapp.example.com';
|
|
27
|
+
* const VINCENT_APP_ID = 555; // Provided by the vincent app registry
|
|
28
|
+
*
|
|
29
|
+
* const { middleware, handler } = createVincentUserMiddleware({
|
|
30
|
+
* allowedAudience: ALLOWED_AUDIENCE,
|
|
31
|
+
* requiredAppId: VINCENT_APP_ID,
|
|
32
|
+
* userKey: 'vincentUser',
|
|
33
|
+
* });
|
|
34
|
+
*
|
|
35
|
+
* // Apply to routes that require authentication; req is guaranteed authenticated because it is wrapped in `handler()`
|
|
36
|
+
* app.get('/protected-resource', middleware, handler((req, res) => {
|
|
37
|
+
* // handler() gives you the correct inferred type of `req[userKey]`
|
|
38
|
+
* const pkpAddress = req.vincentUser.decodedJWT.payload.pkp.ethAddress;
|
|
39
|
+
* const appInfo = req.vincentUser.decodedJWT.payload.app;
|
|
40
|
+
*
|
|
41
|
+
* if(appInfo) {
|
|
42
|
+
* res.json({ message: `Hello, user with PKP address ${pkpAddress}. You are authenticated for app ${appInfo.id} @ v${appInfo.version}` });
|
|
43
|
+
* return;
|
|
44
|
+
* }
|
|
45
|
+
*
|
|
46
|
+
* res.json({ message: `Hello, user with PKP address ${pkpAddress}.` });
|
|
47
|
+
* })
|
|
48
|
+
* );
|
|
49
|
+
* ```
|
|
50
|
+
*
|
|
51
|
+
* See the code below for the implementation used by the `middleware` returned by this function. You can adapt this logic
|
|
52
|
+
* to the HTTP framework of your choice.
|
|
53
|
+
*
|
|
54
|
+
*/
|
|
55
|
+
export declare function createVincentUserMiddleware<const UserKey extends string>(config: {
|
|
56
|
+
allowedAudience: string;
|
|
57
|
+
userKey: UserKey;
|
|
58
|
+
requiredAppId: number | undefined;
|
|
59
|
+
}): {
|
|
60
|
+
middleware: (req: Request, res: Response, next: NextFunction) => Promise<void>;
|
|
61
|
+
handler: (handler: AuthenticatedRequestHandler<UserKey>) => (req: Request, res: Response, next: NextFunction) => void | Promise<void>;
|
|
62
|
+
};
|
|
63
|
+
//# sourceMappingURL=express.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"express.d.ts","sourceRoot":"","sources":["../../../src/expressMiddleware/express.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAE/D,OAAO,KAAK,EAAwB,2BAA2B,EAAkB,MAAM,SAAS,CAAC;AAwBjG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmDG;AACH,wBAAgB,2BAA2B,CAAC,KAAK,CAAC,OAAO,SAAS,MAAM,EAAE,MAAM,EAAE;IAChF,eAAe,EAAE,MAAM,CAAC;IACxB,OAAO,EAAE,OAAO,CAAC;IACjB,aAAa,EAAE,MAAM,GAAG,SAAS,CAAC;CACnC;sBA8BoB,OAAO,OAAO,QAAQ,QAAQ,YAAY;iEArBnD,KAAK,OAAO,EAAE,KAAK,QAAQ,EAAE,MAAM,YAAY;EAJ1D"}
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createVincentUserMiddleware = createVincentUserMiddleware;
|
|
4
|
+
const jwt_1 = require("../jwt");
|
|
5
|
+
const utils_1 = require("../jwt/core/utils");
|
|
6
|
+
function assertAuthenticatedRequest(req, userKey) {
|
|
7
|
+
// @ts-expect-error It's an assertion
|
|
8
|
+
if (!(userKey in req) || typeof req[userKey] !== 'object' || !req[userKey]) {
|
|
9
|
+
throw new Error('Request is not an AuthenticatedRequest: Missing or invalid "user" property');
|
|
10
|
+
}
|
|
11
|
+
// Cast with a type assertion
|
|
12
|
+
const user = req[userKey];
|
|
13
|
+
const { decodedJWT, rawJWT } = user;
|
|
14
|
+
if (typeof rawJWT !== 'string' || !(0, utils_1.isDefinedObject)(decodedJWT)) {
|
|
15
|
+
throw new Error('Request is not an AuthenticatedRequest: Invalid "user" properties');
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
/** Returns an Express middleware function to authenticate a user using a JWT token, and a type-guard wrapper function
|
|
19
|
+
* for type-safe usage of route handlers guarded by the middleware.
|
|
20
|
+
*
|
|
21
|
+
* The `middleware()` function:
|
|
22
|
+
* - Checks the `Authorization` header for a Bearer token, verifies the token, and checks its audience.
|
|
23
|
+
* - If the token is valid, it attaches the user information (decoded JWT, and raw JWT string) to the request object
|
|
24
|
+
* - If the token is missing or invalid, it returns a 401 Unauthorized response with an error message.
|
|
25
|
+
*
|
|
26
|
+
* Designate what field on `req` should be set with the JWT with the `userKey` configuration option.
|
|
27
|
+
*
|
|
28
|
+
* The `handler()` function:
|
|
29
|
+
* - Provides a type-safe reference to `req` where the `userKey` you have provided is correctly inferred to the appropriate type
|
|
30
|
+
* - Note that it is still your responsibility to ensure you have attached the `middleware` somewhere in the chain before you use the `handler()`
|
|
31
|
+
* - If you forget, the `handler()` function will throw an error if the expected `req[userKey]` does not exist.
|
|
32
|
+
*
|
|
33
|
+
* See [express.js documentation](https://expressjs.com/en/guide/writing-middleware.html) for details on writing your route handler
|
|
34
|
+
* @category API
|
|
35
|
+
*
|
|
36
|
+
* @example
|
|
37
|
+
* ```typescript
|
|
38
|
+
* import { createVincentUserMiddleware } from '@lit-protocol/vincent-app-sdk/expressMiddleware';
|
|
39
|
+
*
|
|
40
|
+
* // In your environment configuration
|
|
41
|
+
* const ALLOWED_AUDIENCE = 'https://yourapp.example.com';
|
|
42
|
+
* const VINCENT_APP_ID = 555; // Provided by the vincent app registry
|
|
43
|
+
*
|
|
44
|
+
* const { middleware, handler } = createVincentUserMiddleware({
|
|
45
|
+
* allowedAudience: ALLOWED_AUDIENCE,
|
|
46
|
+
* requiredAppId: VINCENT_APP_ID,
|
|
47
|
+
* userKey: 'vincentUser',
|
|
48
|
+
* });
|
|
49
|
+
*
|
|
50
|
+
* // Apply to routes that require authentication; req is guaranteed authenticated because it is wrapped in `handler()`
|
|
51
|
+
* app.get('/protected-resource', middleware, handler((req, res) => {
|
|
52
|
+
* // handler() gives you the correct inferred type of `req[userKey]`
|
|
53
|
+
* const pkpAddress = req.vincentUser.decodedJWT.payload.pkp.ethAddress;
|
|
54
|
+
* const appInfo = req.vincentUser.decodedJWT.payload.app;
|
|
55
|
+
*
|
|
56
|
+
* if(appInfo) {
|
|
57
|
+
* res.json({ message: `Hello, user with PKP address ${pkpAddress}. You are authenticated for app ${appInfo.id} @ v${appInfo.version}` });
|
|
58
|
+
* return;
|
|
59
|
+
* }
|
|
60
|
+
*
|
|
61
|
+
* res.json({ message: `Hello, user with PKP address ${pkpAddress}.` });
|
|
62
|
+
* })
|
|
63
|
+
* );
|
|
64
|
+
* ```
|
|
65
|
+
*
|
|
66
|
+
* See the code below for the implementation used by the `middleware` returned by this function. You can adapt this logic
|
|
67
|
+
* to the HTTP framework of your choice.
|
|
68
|
+
*
|
|
69
|
+
*/
|
|
70
|
+
function createVincentUserMiddleware(config) {
|
|
71
|
+
return {
|
|
72
|
+
middleware: getAuthenticateUserExpressHandler(config),
|
|
73
|
+
handler: authenticatedRequestHandler(config.userKey),
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
function authenticatedRequestHandler(userKey) {
|
|
77
|
+
return function (handler) {
|
|
78
|
+
return (req, res, next) => {
|
|
79
|
+
try {
|
|
80
|
+
assertAuthenticatedRequest(req, userKey);
|
|
81
|
+
return handler(req, res, next);
|
|
82
|
+
}
|
|
83
|
+
catch (_a) {
|
|
84
|
+
res.status(401).json({ error: 'Not authenticated' });
|
|
85
|
+
}
|
|
86
|
+
};
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
// #region expressHandlerTSDocExample
|
|
90
|
+
function getAuthenticateUserExpressHandler({ allowedAudience, requiredAppId, userKey, }) {
|
|
91
|
+
return async (req, res, next) => {
|
|
92
|
+
const authHeader = req.headers.authorization;
|
|
93
|
+
if (!authHeader) {
|
|
94
|
+
res.status(401).json({ error: 'No token provided' });
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
const parts = authHeader.split(' ');
|
|
98
|
+
if (parts.length !== 2) {
|
|
99
|
+
res.status(401).json({ error: `Invalid authorization header - expected "Bearer <token>"` });
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
const [scheme, rawJWT] = parts;
|
|
103
|
+
if (!/^Bearer$/i.test(scheme)) {
|
|
104
|
+
res.status(401).json({ error: `Expected "Bearer" scheme, got "${scheme}"` });
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
107
|
+
try {
|
|
108
|
+
const decodedJWT = (0, jwt_1.verify)({ jwt: rawJWT, expectedAudience: allowedAudience, requiredAppId });
|
|
109
|
+
if (!decodedJWT) {
|
|
110
|
+
res.status(401).json({ error: 'Invalid token' });
|
|
111
|
+
return;
|
|
112
|
+
}
|
|
113
|
+
req[userKey] = {
|
|
114
|
+
decodedJWT,
|
|
115
|
+
rawJWT,
|
|
116
|
+
};
|
|
117
|
+
next();
|
|
118
|
+
}
|
|
119
|
+
catch (e) {
|
|
120
|
+
res.status(401).json({ error: `Invalid token: ${e.message}` });
|
|
121
|
+
}
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
// #endregion expressHandlerTSDocExample
|
|
125
|
+
//# sourceMappingURL=express.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"express.js","sourceRoot":"","sources":["../../../src/expressMiddleware/express.ts"],"names":[],"mappings":"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"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/** Express middleware is used to add a VincentJWT-specific authentication to your Express.js server routes
|
|
2
|
+
*
|
|
3
|
+
* All functionality is encapsulated into a single factory function -- see {@link createVincentUserMiddleware} for details
|
|
4
|
+
*
|
|
5
|
+
* You can see the source for the Express authentication handler below; use this as a reference to implement
|
|
6
|
+
* your own midddleware/authentication for other frameworks! Pull requests are welcome.
|
|
7
|
+
* {@includeCode ./express.ts#expressHandlerTSDocExample}
|
|
8
|
+
*
|
|
9
|
+
* @packageDocumentation
|
|
10
|
+
* @module expressMiddleware
|
|
11
|
+
* */
|
|
12
|
+
export { createVincentUserMiddleware } from './express';
|
|
13
|
+
export type { AuthenticatedRequest, AuthenticatedRequestHandler, ExtractRequestHandlerParams, VincentJWTData, } from './types';
|
|
14
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/expressMiddleware/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;KAUK;AAEL,OAAO,EAAE,2BAA2B,EAAE,MAAM,WAAW,CAAC;AAExD,YAAY,EACV,oBAAoB,EACpB,2BAA2B,EAC3B,2BAA2B,EAC3B,cAAc,GACf,MAAM,SAAS,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/** Express middleware is used to add a VincentJWT-specific authentication to your Express.js server routes
|
|
3
|
+
*
|
|
4
|
+
* All functionality is encapsulated into a single factory function -- see {@link createVincentUserMiddleware} for details
|
|
5
|
+
*
|
|
6
|
+
* You can see the source for the Express authentication handler below; use this as a reference to implement
|
|
7
|
+
* your own midddleware/authentication for other frameworks! Pull requests are welcome.
|
|
8
|
+
* {@includeCode ./express.ts#expressHandlerTSDocExample}
|
|
9
|
+
*
|
|
10
|
+
* @packageDocumentation
|
|
11
|
+
* @module expressMiddleware
|
|
12
|
+
* */
|
|
13
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
|
+
exports.createVincentUserMiddleware = void 0;
|
|
15
|
+
var express_1 = require("./express");
|
|
16
|
+
Object.defineProperty(exports, "createVincentUserMiddleware", { enumerable: true, get: function () { return express_1.createVincentUserMiddleware; } });
|
|
17
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/expressMiddleware/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;KAUK;;;AAEL,qCAAwD;AAA/C,sHAAA,2BAA2B,OAAA"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { NextFunction, Request, RequestHandler, Response } from 'express';
|
|
2
|
+
import type { VincentJWT } from '../jwt/types';
|
|
3
|
+
/** Extract the params type from the original Express.js RequestHandler
|
|
4
|
+
*
|
|
5
|
+
* You probably don't need this type; see { @link createVincentUserMiddleware } for details
|
|
6
|
+
*
|
|
7
|
+
* @category Interfaces
|
|
8
|
+
* */
|
|
9
|
+
export type ExtractRequestHandlerParams<T> = T extends RequestHandler<infer P, infer ResBody, infer ReqBody, infer ReqQuery, infer Locals> ? [P, ResBody, ReqBody, ReqQuery, Locals] : never;
|
|
10
|
+
/**
|
|
11
|
+
* An Express.js RequestHandler that guarantees the request is authenticated with a PKP address
|
|
12
|
+
*
|
|
13
|
+
* You probably don't need this type; see { @link createVincentUserMiddleware } for details
|
|
14
|
+
*
|
|
15
|
+
* @category Interfaces
|
|
16
|
+
* */
|
|
17
|
+
export type AuthenticatedRequestHandler<UserKey extends string, P = ExtractRequestHandlerParams<RequestHandler>[0], ResBody = ExtractRequestHandlerParams<RequestHandler>[1], ReqBody = ExtractRequestHandlerParams<RequestHandler>[2], ReqQuery = ExtractRequestHandlerParams<RequestHandler>[3], Locals extends Record<string, any> = ExtractRequestHandlerParams<RequestHandler>[4]> = (req: AuthenticatedRequest<UserKey, P, ResBody, ReqBody, ReqQuery>, res: Response<ResBody, Locals>, next: NextFunction) => void | Promise<void>;
|
|
18
|
+
export interface VincentJWTData {
|
|
19
|
+
decodedJWT: VincentJWT;
|
|
20
|
+
rawJWT: string;
|
|
21
|
+
}
|
|
22
|
+
/** An interface that extends the Express.js Request interface to include authenticated user data
|
|
23
|
+
*
|
|
24
|
+
* You probably don't need this type; see { @link createVincentUserMiddleware } for details
|
|
25
|
+
*
|
|
26
|
+
* @category Interfaces
|
|
27
|
+
* */
|
|
28
|
+
export type AuthenticatedRequest<UserKey extends string, P = any, ResBody = any, ReqBody = any, ReqQuery = any> = Request<P, ResBody, ReqBody, ReqQuery> & {
|
|
29
|
+
[K in UserKey]: VincentJWTData;
|
|
30
|
+
};
|
|
31
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/expressMiddleware/types.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,OAAO,EAAE,cAAc,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAE/E,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAE/C;;;;;KAKK;AACL,MAAM,MAAM,2BAA2B,CAAC,CAAC,IACvC,CAAC,SAAS,cAAc,CAAC,MAAM,CAAC,EAAE,MAAM,OAAO,EAAE,MAAM,OAAO,EAAE,MAAM,QAAQ,EAAE,MAAM,MAAM,CAAC,GACzF,CAAC,CAAC,EAAE,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,CAAC,GACvC,KAAK,CAAC;AAEZ;;;;;;KAMK;AACL,MAAM,MAAM,2BAA2B,CACrC,OAAO,SAAS,MAAM,EACtB,CAAC,GAAG,2BAA2B,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC,EAClD,OAAO,GAAG,2BAA2B,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC,EACxD,OAAO,GAAG,2BAA2B,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC,EACxD,QAAQ,GAAG,2BAA2B,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC,EACzD,MAAM,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,2BAA2B,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC,IACjF,CACF,GAAG,EAAE,oBAAoB,CAAC,OAAO,EAAE,CAAC,EAAE,OAAO,EAAE,OAAO,EAAE,QAAQ,CAAC,EACjE,GAAG,EAAE,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC,EAC9B,IAAI,EAAE,YAAY,KACf,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;AAE1B,MAAM,WAAW,cAAc;IAC7B,UAAU,EAAE,UAAU,CAAC;IACvB,MAAM,EAAE,MAAM,CAAC;CAChB;AAED;;;;;KAKK;AACL,MAAM,MAAM,oBAAoB,CAC9B,OAAO,SAAS,MAAM,EACtB,CAAC,GAAG,GAAG,EACP,OAAO,GAAG,GAAG,EACb,OAAO,GAAG,GAAG,EACb,QAAQ,GAAG,GAAG,IACZ,OAAO,CAAC,CAAC,EAAE,OAAO,EAAE,OAAO,EAAE,QAAQ,CAAC,GAAG;KAC1C,CAAC,IAAI,OAAO,GAAG,cAAc;CAC/B,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/expressMiddleware/types.ts"],"names":[],"mappings":""}
|
package/dist/src/index.d.ts
CHANGED
|
@@ -1,20 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
export { jwt };
|
|
3
|
-
export type { JWTConfig, VincentJWT, VincentJWTPayload } from './jwt/types';
|
|
4
|
-
import { disconnectLitNodeClientInstance } from './internal/LitNodeClient/getLitNodeClient';
|
|
5
|
-
/** This method closes any registered event listeners maintained by Vincent Tool Clients, allowing your process to exit gracefully.
|
|
6
|
-
* @category API Methods
|
|
7
|
-
*/
|
|
8
|
-
declare const disconnectVincentToolClients: typeof disconnectLitNodeClientInstance;
|
|
9
|
-
export { disconnectVincentToolClients };
|
|
10
|
-
export { generateVincentToolSessionSigs, getVincentToolClient } from './toolClient';
|
|
11
|
-
export type { VincentToolClient, ToolClientContext, ToolExecuteResponse, ToolExecuteResponseFailure, ToolExecuteResponseFailureNoResult, ToolExecuteResponseSuccess, ToolExecuteResponseSuccessNoResult, ToolPrecheckResponse, ToolPrecheckResponseFailure, ToolPrecheckResponseFailureNoResult, ToolPrecheckResponseSuccess, ToolPrecheckResponseSuccessNoResult, } from './toolClient';
|
|
12
|
-
export { getVincentWebAppClient } from './app';
|
|
13
|
-
export type { VincentWebAppClient, VincentAppClientConfig, RedirectToVincentConsentPageParams, } from './types';
|
|
14
|
-
export type { BaseToolContext } from './toolClient';
|
|
15
|
-
import * as expressAuthHelpers from './express-authentication-middleware';
|
|
16
|
-
export { expressAuthHelpers };
|
|
17
|
-
export type { ExpressAuthHelpers } from './express-authentication-middleware/types';
|
|
18
|
-
import * as utils from './utils';
|
|
19
|
-
export { utils };
|
|
1
|
+
export {};
|
|
20
2
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/src/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,CAAC"}
|
package/dist/src/index.js
CHANGED
|
@@ -1,22 +1,3 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.utils = exports.expressAuthHelpers = exports.getVincentWebAppClient = exports.getVincentToolClient = exports.generateVincentToolSessionSigs = exports.disconnectVincentToolClients = exports.jwt = void 0;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
|
-
const jwt = tslib_1.__importStar(require("./jwt"));
|
|
6
|
-
exports.jwt = jwt;
|
|
7
|
-
const getLitNodeClient_1 = require("./internal/LitNodeClient/getLitNodeClient");
|
|
8
|
-
/** This method closes any registered event listeners maintained by Vincent Tool Clients, allowing your process to exit gracefully.
|
|
9
|
-
* @category API Methods
|
|
10
|
-
*/
|
|
11
|
-
const disconnectVincentToolClients = getLitNodeClient_1.disconnectLitNodeClientInstance;
|
|
12
|
-
exports.disconnectVincentToolClients = disconnectVincentToolClients;
|
|
13
|
-
var toolClient_1 = require("./toolClient");
|
|
14
|
-
Object.defineProperty(exports, "generateVincentToolSessionSigs", { enumerable: true, get: function () { return toolClient_1.generateVincentToolSessionSigs; } });
|
|
15
|
-
Object.defineProperty(exports, "getVincentToolClient", { enumerable: true, get: function () { return toolClient_1.getVincentToolClient; } });
|
|
16
|
-
var app_1 = require("./app");
|
|
17
|
-
Object.defineProperty(exports, "getVincentWebAppClient", { enumerable: true, get: function () { return app_1.getVincentWebAppClient; } });
|
|
18
|
-
const expressAuthHelpers = tslib_1.__importStar(require("./express-authentication-middleware"));
|
|
19
|
-
exports.expressAuthHelpers = expressAuthHelpers;
|
|
20
|
-
const utils = tslib_1.__importStar(require("./utils"));
|
|
21
|
-
exports.utils = utils;
|
|
22
3
|
//# sourceMappingURL=index.js.map
|
package/dist/src/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":""}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
+
import type { LIT_NETWORKS_KEYS } from '@lit-protocol/types';
|
|
1
2
|
import { LitNodeClient } from '@lit-protocol/lit-node-client';
|
|
2
|
-
import { LIT_NETWORKS_KEYS } from '@lit-protocol/types';
|
|
3
3
|
export declare class LitNodeClientInstance {
|
|
4
4
|
private readonly litNodeClientInstance;
|
|
5
5
|
private isConnected;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"LitNodeClientInstance.d.ts","sourceRoot":"","sources":["../../../../src/internal/LitNodeClient/LitNodeClientInstance.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"LitNodeClientInstance.d.ts","sourceRoot":"","sources":["../../../../src/internal/LitNodeClient/LitNodeClientInstance.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAE7D,OAAO,EAAE,aAAa,EAAE,MAAM,+BAA+B,CAAC;AAE9D,qBAAa,qBAAqB;IAChC,OAAO,CAAC,QAAQ,CAAC,qBAAqB,CAAgB;IAEtD,OAAO,CAAC,WAAW,CAAS;IAE5B,OAAO,CAAC,aAAa,CAAiC;gBAE1C,EAAE,OAAO,EAAE,EAAE;QAAE,OAAO,EAAE,iBAAiB,CAAA;KAAE;IAOjD,OAAO,IAAI,OAAO,CAAC,OAAO,CAAC;IA4B3B,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;IAqBjC,IAAI,aAAa,IAAI,aAAa,CAEjC;CACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"LitNodeClientInstance.js","sourceRoot":"","sources":["../../../../src/internal/LitNodeClient/LitNodeClientInstance.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"LitNodeClientInstance.js","sourceRoot":"","sources":["../../../../src/internal/LitNodeClient/LitNodeClientInstance.ts"],"names":[],"mappings":";;;AAEA,mEAA8D;AAE9D,MAAa,qBAAqB;IAOhC,YAAY,EAAE,OAAO,EAAkC;QAJ/C,gBAAW,GAAG,KAAK,CAAC;QAEpB,kBAAa,GAA4B,IAAI,CAAC;QAGpD,IAAI,CAAC,qBAAqB,GAAG,IAAI,+BAAa,CAAC;YAC7C,KAAK,EAAE,IAAI;YACX,UAAU,EAAE,OAAO;SACpB,CAAC,CAAC;IACL,CAAC;IAED,KAAK,CAAC,OAAO;QACX,IAAI,CAAC,IAAI,CAAC,WAAW,EAAE,CAAC;YACtB,4BAA4B;YAC5B,IAAI,IAAI,CAAC,aAAa,EAAE,CAAC;gBACvB,OAAO,IAAI,CAAC,aAAa,CAAC;YAC5B,CAAC;YAED,sEAAsE;YACtE,IAAI,CAAC,aAAa,GAAG,IAAI,CAAC,qBAAqB,CAAC,OAAO,EAAE,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,CAAC;YAE3E,IAAI,CAAC;gBACH,mEAAmE;gBACnE,MAAM,IAAI,CAAC,aAAa,CAAC;gBACzB,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC;YAC1B,CAAC;YAAC,OAAO,CAAC,EAAE,CAAC;gBACX,wFAAwF;gBACxF,0DAA0D;gBAC1D,IAAI,CAAC,WAAW,GAAG,KAAK,CAAC;gBACzB,MAAM,CAAC,CAAC;YACV,CAAC;oBAAS,CAAC;gBACT,IAAI,CAAC,aAAa,GAAG,IAAI,CAAC;YAC5B,CAAC;YACD,OAAO,IAAI,CAAC,WAAW,CAAC;QAC1B,CAAC;QAED,OAAO,IAAI,CAAC;IACd,CAAC;IAED,KAAK,CAAC,UAAU;QACd,IAAI,CAAC,IAAI,CAAC,WAAW,IAAI,IAAI,CAAC,aAAa,EAAE,CAAC;YAC5C,sGAAsG;YACtG,IAAI,CAAC;gBACH,MAAM,IAAI,CAAC,aAAa,CAAC;gBACzB,6DAA6D;YAC/D,CAAC;YAAC,OAAO,CAAC,EAAE,CAAC;gBACX,oDAAoD;YACtD,CAAC;QACH,CAAC;QAED,IAAI,CAAC;YACH,MAAM,IAAI,CAAC,qBAAqB,CAAC,UAAU,EAAE,CAAC;QAChD,CAAC;QAAC,OAAO,CAAC,EAAE,CAAC;YACX,qBAAqB;YACrB,OAAO,CAAC,GAAG,CAAC,kDAAkD,EAAG,CAAW,CAAC,OAAO,CAAC,CAAC;QACxF,CAAC;gBAAS,CAAC;YACT,IAAI,CAAC,WAAW,GAAG,KAAK,CAAC;QAC3B,CAAC;IACH,CAAC;IAED,IAAI,aAAa;QACf,OAAO,IAAI,CAAC,qBAAqB,CAAC;IACpC,CAAC;CACF;AAlED,sDAkEC"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { LitNodeClient } from '@lit-protocol/lit-node-client';
|
|
2
|
-
import { LIT_NETWORKS_KEYS } from '@lit-protocol/types';
|
|
1
|
+
import type { LitNodeClient } from '@lit-protocol/lit-node-client';
|
|
2
|
+
import type { LIT_NETWORKS_KEYS } from '@lit-protocol/types';
|
|
3
3
|
export declare function getLitNodeClientInstance({ network, }: {
|
|
4
4
|
network: LIT_NETWORKS_KEYS;
|
|
5
5
|
}): Promise<LitNodeClient>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getLitNodeClient.d.ts","sourceRoot":"","sources":["../../../../src/internal/LitNodeClient/getLitNodeClient.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,+BAA+B,CAAC;
|
|
1
|
+
{"version":3,"file":"getLitNodeClient.d.ts","sourceRoot":"","sources":["../../../../src/internal/LitNodeClient/getLitNodeClient.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,+BAA+B,CAAC;AACnE,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAM7D,wBAAsB,wBAAwB,CAAC,EAC7C,OAAO,GACR,EAAE;IACD,OAAO,EAAE,iBAAiB,CAAC;CAC5B,GAAG,OAAO,CAAC,aAAa,CAAC,CAYzB;AAED,wBAAsB,+BAA+B,qBAMpD"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { IRelayPKP } from '@lit-protocol/types';
|
|
2
|
+
import type { VincentJWT, VincentJWTAppSpecific } from './types';
|
|
3
|
+
export declare function getAppInfo(decodedJWT: VincentJWTAppSpecific): {
|
|
4
|
+
appId: number;
|
|
5
|
+
version: number;
|
|
6
|
+
};
|
|
7
|
+
export declare function getPKPInfo(decodedJWT: VincentJWT): IRelayPKP;
|
|
8
|
+
//# sourceMappingURL=accessors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"accessors.d.ts","sourceRoot":"","sources":["../../../src/jwt/accessors.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAErD,OAAO,KAAK,EAAE,UAAU,EAAE,qBAAqB,EAAE,MAAM,SAAS,CAAC;AAIjE,wBAAgB,UAAU,CAAC,UAAU,EAAE,qBAAqB,GAAG;IAC7D,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,MAAM,CAAC;CACjB,CAMA;AAED,wBAAgB,UAAU,CAAC,UAAU,EAAE,UAAU,GAAG,SAAS,CAE5D"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getAppInfo = getAppInfo;
|
|
4
|
+
exports.getPKPInfo = getPKPInfo;
|
|
5
|
+
const typeGuards_1 = require("./typeGuards");
|
|
6
|
+
function getAppInfo(decodedJWT) {
|
|
7
|
+
if (!(0, typeGuards_1.isAppSpecificJWT)(decodedJWT)) {
|
|
8
|
+
throw new Error('JWT is not app specific');
|
|
9
|
+
}
|
|
10
|
+
return { appId: decodedJWT.payload.app.id, version: decodedJWT.payload.app.version };
|
|
11
|
+
}
|
|
12
|
+
function getPKPInfo(decodedJWT) {
|
|
13
|
+
return decodedJWT.payload.pkp;
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=accessors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"accessors.js","sourceRoot":"","sources":["../../../src/jwt/accessors.ts"],"names":[],"mappings":";;AAMA,gCASC;AAED,gCAEC;AAfD,6CAAgD;AAEhD,SAAgB,UAAU,CAAC,UAAiC;IAI1D,IAAI,CAAC,IAAA,6BAAgB,EAAC,UAAU,CAAC,EAAE,CAAC;QAClC,MAAM,IAAI,KAAK,CAAC,yBAAyB,CAAC,CAAC;IAC7C,CAAC;IAED,OAAO,EAAE,KAAK,EAAE,UAAU,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE,EAAE,OAAO,EAAE,UAAU,CAAC,OAAO,CAAC,GAAG,CAAC,OAAO,EAAE,CAAC;AACvF,CAAC;AAED,SAAgB,UAAU,CAAC,UAAsB;IAC/C,OAAO,UAAU,CAAC,OAAO,CAAC,GAAG,CAAC;AAChC,CAAC"}
|