@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.
- package/CHANGELOG.md +53 -0
- package/CONTRIBUTING.md +115 -0
- package/README.md +215 -0
- package/dist/CHANGELOG.md +53 -0
- package/dist/CONTRIBUTING.md +115 -0
- package/dist/README.md +215 -0
- package/dist/package.json +54 -0
- package/dist/src/app/app.d.ts +9 -0
- package/dist/src/app/app.d.ts.map +1 -0
- package/dist/src/app/app.js +33 -0
- package/dist/src/app/app.js.map +1 -0
- package/dist/src/app/constants.d.ts +3 -0
- package/dist/src/app/constants.d.ts.map +1 -0
- package/dist/src/app/constants.js +6 -0
- package/dist/src/app/constants.js.map +1 -0
- package/dist/src/app/index.d.ts +3 -0
- package/dist/src/app/index.d.ts.map +1 -0
- package/dist/src/app/index.js +6 -0
- package/dist/src/app/index.js.map +1 -0
- package/dist/src/app/internal/index.d.ts +3 -0
- package/dist/src/app/internal/index.d.ts.map +1 -0
- package/dist/src/app/internal/index.js +7 -0
- package/dist/src/app/internal/index.js.map +1 -0
- package/dist/src/app/internal/uriHelpers.d.ts +11 -0
- package/dist/src/app/internal/uriHelpers.d.ts.map +1 -0
- package/dist/src/app/internal/uriHelpers.js +32 -0
- package/dist/src/app/internal/uriHelpers.js.map +1 -0
- package/dist/src/app/types.d.ts +119 -0
- package/dist/src/app/types.d.ts.map +1 -0
- package/dist/src/app/types.js +3 -0
- package/dist/src/app/types.js.map +1 -0
- package/dist/src/express-authentication-middleware/express.d.ts +79 -0
- package/dist/src/express-authentication-middleware/express.d.ts.map +1 -0
- package/dist/src/express-authentication-middleware/express.js +137 -0
- package/dist/src/express-authentication-middleware/express.js.map +1 -0
- package/dist/src/express-authentication-middleware/index.d.ts +43 -0
- package/dist/src/express-authentication-middleware/index.d.ts.map +1 -0
- package/dist/src/express-authentication-middleware/index.js +47 -0
- package/dist/src/express-authentication-middleware/index.js.map +1 -0
- package/dist/src/express-authentication-middleware/types.d.ts +22 -0
- package/dist/src/express-authentication-middleware/types.d.ts.map +1 -0
- package/dist/src/express-authentication-middleware/types.js +3 -0
- package/dist/src/express-authentication-middleware/types.js.map +1 -0
- package/dist/src/index.d.ts +12 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/index.js +15 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/internal/LitNodeClient/LitNodeClientInstance.d.ts +14 -0
- package/dist/src/internal/LitNodeClient/LitNodeClientInstance.d.ts.map +1 -0
- package/dist/src/internal/LitNodeClient/LitNodeClientInstance.js +67 -0
- package/dist/src/internal/LitNodeClient/LitNodeClientInstance.js.map +1 -0
- package/dist/src/internal/LitNodeClient/getLitNodeClient.d.ts +7 -0
- package/dist/src/internal/LitNodeClient/getLitNodeClient.d.ts.map +1 -0
- package/dist/src/internal/LitNodeClient/getLitNodeClient.js +25 -0
- package/dist/src/internal/LitNodeClient/getLitNodeClient.js.map +1 -0
- package/dist/src/jwt/core/create.d.ts +41 -0
- package/dist/src/jwt/core/create.d.ts.map +1 -0
- package/dist/src/jwt/core/create.js +114 -0
- package/dist/src/jwt/core/create.js.map +1 -0
- package/dist/src/jwt/core/utils/definedObject.d.ts +2 -0
- package/dist/src/jwt/core/utils/definedObject.d.ts.map +1 -0
- package/dist/src/jwt/core/utils/definedObject.js +7 -0
- package/dist/src/jwt/core/utils/definedObject.js.map +1 -0
- package/dist/src/jwt/core/utils/index.d.ts +6 -0
- package/dist/src/jwt/core/utils/index.d.ts.map +1 -0
- package/dist/src/jwt/core/utils/index.js +14 -0
- package/dist/src/jwt/core/utils/index.js.map +1 -0
- package/dist/src/jwt/core/utils/isJWTExpired.d.ts +8 -0
- package/dist/src/jwt/core/utils/isJWTExpired.d.ts.map +1 -0
- package/dist/src/jwt/core/utils/isJWTExpired.js +19 -0
- package/dist/src/jwt/core/utils/isJWTExpired.js.map +1 -0
- package/dist/src/jwt/core/utils/processJWTSignature.d.ts +8 -0
- package/dist/src/jwt/core/utils/processJWTSignature.d.ts.map +1 -0
- package/dist/src/jwt/core/utils/processJWTSignature.js +21 -0
- package/dist/src/jwt/core/utils/processJWTSignature.js.map +1 -0
- package/dist/src/jwt/core/utils/splitJWT.d.ts +11 -0
- package/dist/src/jwt/core/utils/splitJWT.d.ts.map +1 -0
- package/dist/src/jwt/core/utils/splitJWT.js +21 -0
- package/dist/src/jwt/core/utils/splitJWT.js.map +1 -0
- package/dist/src/jwt/core/utils/validateJWTTime.d.ts +12 -0
- package/dist/src/jwt/core/utils/validateJWTTime.d.ts.map +1 -0
- package/dist/src/jwt/core/utils/validateJWTTime.js +24 -0
- package/dist/src/jwt/core/utils/validateJWTTime.js.map +1 -0
- package/dist/src/jwt/core/validate.d.ts +23 -0
- package/dist/src/jwt/core/validate.d.ts.map +1 -0
- package/dist/src/jwt/core/validate.js +96 -0
- package/dist/src/jwt/core/validate.js.map +1 -0
- package/dist/src/jwt/index.d.ts +69 -0
- package/dist/src/jwt/index.d.ts.map +1 -0
- package/dist/src/jwt/index.js +72 -0
- package/dist/src/jwt/index.js.map +1 -0
- package/dist/src/jwt/types.d.ts +68 -0
- package/dist/src/jwt/types.d.ts.map +1 -0
- package/dist/src/jwt/types.js +3 -0
- package/dist/src/jwt/types.js.map +1 -0
- package/dist/src/toolClient/index.d.ts +2 -0
- package/dist/src/toolClient/index.d.ts.map +1 -0
- package/dist/src/toolClient/index.js +6 -0
- package/dist/src/toolClient/index.js.map +1 -0
- package/dist/src/toolClient/resultCreators.d.ts +69 -0
- package/dist/src/toolClient/resultCreators.d.ts.map +1 -0
- package/dist/src/toolClient/resultCreators.js +55 -0
- package/dist/src/toolClient/resultCreators.js.map +1 -0
- package/dist/src/toolClient/typeGuards.d.ts +19 -0
- package/dist/src/toolClient/typeGuards.d.ts.map +1 -0
- package/dist/src/toolClient/typeGuards.js +48 -0
- package/dist/src/toolClient/typeGuards.js.map +1 -0
- package/dist/src/toolClient/types.d.ts +33 -0
- package/dist/src/toolClient/types.d.ts.map +1 -0
- package/dist/src/toolClient/types.js +3 -0
- package/dist/src/toolClient/types.js.map +1 -0
- package/dist/src/toolClient/vincentToolClient.d.ts +15 -0
- package/dist/src/toolClient/vincentToolClient.d.ts.map +1 -0
- package/dist/src/toolClient/vincentToolClient.js +256 -0
- package/dist/src/toolClient/vincentToolClient.js.map +1 -0
- package/dist/src/type-inference-verification/tool-client-inference.d.ts +3 -0
- package/dist/src/type-inference-verification/tool-client-inference.d.ts.map +1 -0
- package/dist/src/type-inference-verification/tool-client-inference.js +214 -0
- package/dist/src/type-inference-verification/tool-client-inference.js.map +1 -0
- package/dist/src/types.d.ts +4 -0
- package/dist/src/types.d.ts.map +1 -0
- package/dist/src/types.js +3 -0
- package/dist/src/types.js.map +1 -0
- package/package.json +55 -0
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { isDefinedObject } from './definedObject';
|
|
2
|
+
export { isJWTExpired } from './isJWTExpired';
|
|
3
|
+
export { validateJWTTime } from './validateJWTTime';
|
|
4
|
+
export { splitJWT } from './splitJWT';
|
|
5
|
+
export { processJWTSignature } from './processJWTSignature';
|
|
6
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/jwt/core/utils/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAClD,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACtC,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.processJWTSignature = exports.splitJWT = exports.validateJWTTime = exports.isJWTExpired = exports.isDefinedObject = void 0;
|
|
4
|
+
var definedObject_1 = require("./definedObject");
|
|
5
|
+
Object.defineProperty(exports, "isDefinedObject", { enumerable: true, get: function () { return definedObject_1.isDefinedObject; } });
|
|
6
|
+
var isJWTExpired_1 = require("./isJWTExpired");
|
|
7
|
+
Object.defineProperty(exports, "isJWTExpired", { enumerable: true, get: function () { return isJWTExpired_1.isJWTExpired; } });
|
|
8
|
+
var validateJWTTime_1 = require("./validateJWTTime");
|
|
9
|
+
Object.defineProperty(exports, "validateJWTTime", { enumerable: true, get: function () { return validateJWTTime_1.validateJWTTime; } });
|
|
10
|
+
var splitJWT_1 = require("./splitJWT");
|
|
11
|
+
Object.defineProperty(exports, "splitJWT", { enumerable: true, get: function () { return splitJWT_1.splitJWT; } });
|
|
12
|
+
var processJWTSignature_1 = require("./processJWTSignature");
|
|
13
|
+
Object.defineProperty(exports, "processJWTSignature", { enumerable: true, get: function () { return processJWTSignature_1.processJWTSignature; } });
|
|
14
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../src/jwt/core/utils/index.ts"],"names":[],"mappings":";;;AAAA,iDAAkD;AAAzC,gHAAA,eAAe,OAAA;AACxB,+CAA8C;AAArC,4GAAA,YAAY,OAAA;AACrB,qDAAoD;AAA3C,kHAAA,eAAe,OAAA;AACxB,uCAAsC;AAA7B,oGAAA,QAAQ,OAAA;AACjB,6DAA4D;AAAnD,0HAAA,mBAAmB,OAAA"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { VincentJWT } from '../../types';
|
|
2
|
+
/** Checks if a JWT is expired based on its 'exp' claim
|
|
3
|
+
*
|
|
4
|
+
* @returns true if expired, false otherwise
|
|
5
|
+
* @param decodedJWT
|
|
6
|
+
*/
|
|
7
|
+
export declare function isJWTExpired(decodedJWT: VincentJWT): boolean;
|
|
8
|
+
//# sourceMappingURL=isJWTExpired.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"isJWTExpired.d.ts","sourceRoot":"","sources":["../../../../../src/jwt/core/utils/isJWTExpired.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAEzC;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,UAAU,EAAE,UAAU,GAAG,OAAO,CAW5D"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isJWTExpired = isJWTExpired;
|
|
4
|
+
/** Checks if a JWT is expired based on its 'exp' claim
|
|
5
|
+
*
|
|
6
|
+
* @returns true if expired, false otherwise
|
|
7
|
+
* @param decodedJWT
|
|
8
|
+
*/
|
|
9
|
+
function isJWTExpired(decodedJWT) {
|
|
10
|
+
const { payload } = decodedJWT;
|
|
11
|
+
// Tokens that never expire are treated as expired for security.
|
|
12
|
+
if (!payload.exp) {
|
|
13
|
+
return true;
|
|
14
|
+
}
|
|
15
|
+
// JWT exp is in seconds, Date.now() is in milliseconds
|
|
16
|
+
const currentTime = Math.floor(Date.now() / 1000);
|
|
17
|
+
return currentTime >= payload.exp;
|
|
18
|
+
}
|
|
19
|
+
//# sourceMappingURL=isJWTExpired.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"isJWTExpired.js","sourceRoot":"","sources":["../../../../../src/jwt/core/utils/isJWTExpired.ts"],"names":[],"mappings":";;AAOA,oCAWC;AAhBD;;;;GAIG;AACH,SAAgB,YAAY,CAAC,UAAsB;IACjD,MAAM,EAAE,OAAO,EAAE,GAAG,UAAU,CAAC;IAE/B,gEAAgE;IAChE,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC;QACjB,OAAO,IAAI,CAAC;IACd,CAAC;IAED,uDAAuD;IACvD,MAAM,WAAW,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC,CAAC;IAClD,OAAO,WAAW,IAAI,OAAO,CAAC,GAAG,CAAC;AACpC,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/** Processes a JWT signature from base64url to binary
|
|
2
|
+
* @ignore
|
|
3
|
+
*
|
|
4
|
+
* @param signature - The base64url encoded signature string
|
|
5
|
+
* @returns A Uint8Array of the binary signature
|
|
6
|
+
*/
|
|
7
|
+
export declare function processJWTSignature(signature: string): Uint8Array;
|
|
8
|
+
//# sourceMappingURL=processJWTSignature.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"processJWTSignature.d.ts","sourceRoot":"","sources":["../../../../../src/jwt/core/utils/processJWTSignature.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,wBAAgB,mBAAmB,CAAC,SAAS,EAAE,MAAM,GAAG,UAAU,CAYjE"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.processJWTSignature = processJWTSignature;
|
|
4
|
+
/** Processes a JWT signature from base64url to binary
|
|
5
|
+
* @ignore
|
|
6
|
+
*
|
|
7
|
+
* @param signature - The base64url encoded signature string
|
|
8
|
+
* @returns A Uint8Array of the binary signature
|
|
9
|
+
*/
|
|
10
|
+
function processJWTSignature(signature) {
|
|
11
|
+
// Convert base64url to base64
|
|
12
|
+
let base64 = signature.replace(/-/g, '+').replace(/_/g, '/');
|
|
13
|
+
// Pad with '=' if needed
|
|
14
|
+
while (base64.length % 4) {
|
|
15
|
+
base64 += '=';
|
|
16
|
+
}
|
|
17
|
+
// Decode base64 to binary
|
|
18
|
+
const binary = Buffer.from(base64, 'base64');
|
|
19
|
+
return new Uint8Array(binary);
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=processJWTSignature.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"processJWTSignature.js","sourceRoot":"","sources":["../../../../../src/jwt/core/utils/processJWTSignature.ts"],"names":[],"mappings":";;AAMA,kDAYC;AAlBD;;;;;GAKG;AACH,SAAgB,mBAAmB,CAAC,SAAiB;IACnD,8BAA8B;IAC9B,IAAI,MAAM,GAAG,SAAS,CAAC,OAAO,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC,OAAO,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC;IAE7D,yBAAyB;IACzB,OAAO,MAAM,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QACzB,MAAM,IAAI,GAAG,CAAC;IAChB,CAAC;IAED,0BAA0B;IAC1B,MAAM,MAAM,GAAG,MAAM,CAAC,IAAI,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;IAC7C,OAAO,IAAI,UAAU,CAAC,MAAM,CAAC,CAAC;AAChC,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/** Splits a JWT into its signed data portion and signature
|
|
2
|
+
* @ignore
|
|
3
|
+
*
|
|
4
|
+
* @param jwt - The JWT string
|
|
5
|
+
* @returns An object with signedData and signature
|
|
6
|
+
*/
|
|
7
|
+
export declare function splitJWT(jwt: string): {
|
|
8
|
+
signedData: string;
|
|
9
|
+
signature: string;
|
|
10
|
+
};
|
|
11
|
+
//# sourceMappingURL=splitJWT.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"splitJWT.d.ts","sourceRoot":"","sources":["../../../../../src/jwt/core/utils/splitJWT.ts"],"names":[],"mappings":"AAEA;;;;;GAKG;AACH,wBAAgB,QAAQ,CAAC,GAAG,EAAE,MAAM,GAAG;IAAE,UAAU,EAAE,MAAM,CAAC;IAAC,SAAS,EAAE,MAAM,CAAA;CAAE,CAU/E"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.splitJWT = splitJWT;
|
|
4
|
+
const did_jwt_1 = require("did-jwt");
|
|
5
|
+
/** Splits a JWT into its signed data portion and signature
|
|
6
|
+
* @ignore
|
|
7
|
+
*
|
|
8
|
+
* @param jwt - The JWT string
|
|
9
|
+
* @returns An object with signedData and signature
|
|
10
|
+
*/
|
|
11
|
+
function splitJWT(jwt) {
|
|
12
|
+
const parts = jwt.split('.');
|
|
13
|
+
if (parts.length !== 3) {
|
|
14
|
+
throw new Error(`${did_jwt_1.JWT_ERROR.INVALID_JWT}: JWT format: must contain 3 parts separated by "."`);
|
|
15
|
+
}
|
|
16
|
+
return {
|
|
17
|
+
signedData: `${parts[0]}.${parts[1]}`,
|
|
18
|
+
signature: parts[2],
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=splitJWT.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"splitJWT.js","sourceRoot":"","sources":["../../../../../src/jwt/core/utils/splitJWT.ts"],"names":[],"mappings":";;AAQA,4BAUC;AAlBD,qCAAoC;AAEpC;;;;;GAKG;AACH,SAAgB,QAAQ,CAAC,GAAW;IAClC,MAAM,KAAK,GAAG,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IAC7B,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACvB,MAAM,IAAI,KAAK,CAAC,GAAG,mBAAS,CAAC,WAAW,qDAAqD,CAAC,CAAC;IACjG,CAAC;IAED,OAAO;QACL,UAAU,EAAE,GAAG,KAAK,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,CAAC,CAAC,EAAE;QACrC,SAAS,EAAE,KAAK,CAAC,CAAC,CAAC;KACpB,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/** Validates JWT time claims (iat and nbf)
|
|
2
|
+
* @ignore
|
|
3
|
+
*
|
|
4
|
+
* @param payload - The decoded JWT payload
|
|
5
|
+
* @param currentTime The time to compare the claims against
|
|
6
|
+
* @returns true if time claims are valid, false otherwise
|
|
7
|
+
*/
|
|
8
|
+
export declare function validateJWTTime(payload: {
|
|
9
|
+
nbf?: number;
|
|
10
|
+
iat?: number;
|
|
11
|
+
}, currentTime: number): boolean;
|
|
12
|
+
//# sourceMappingURL=validateJWTTime.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validateJWTTime.d.ts","sourceRoot":"","sources":["../../../../../src/jwt/core/utils/validateJWTTime.ts"],"names":[],"mappings":"AAEA;;;;;;GAMG;AACH,wBAAgB,eAAe,CAC7B,OAAO,EAAE;IAAE,GAAG,CAAC,EAAE,MAAM,CAAC;IAAC,GAAG,CAAC,EAAE,MAAM,CAAA;CAAE,EACvC,WAAW,EAAE,MAAM,GAClB,OAAO,CAeT"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.validateJWTTime = validateJWTTime;
|
|
4
|
+
const did_jwt_1 = require("did-jwt");
|
|
5
|
+
/** Validates JWT time claims (iat and nbf)
|
|
6
|
+
* @ignore
|
|
7
|
+
*
|
|
8
|
+
* @param payload - The decoded JWT payload
|
|
9
|
+
* @param currentTime The time to compare the claims against
|
|
10
|
+
* @returns true if time claims are valid, false otherwise
|
|
11
|
+
*/
|
|
12
|
+
function validateJWTTime(payload, currentTime) {
|
|
13
|
+
// Check 'not before' claim if present
|
|
14
|
+
if (payload.nbf && currentTime < payload.nbf) {
|
|
15
|
+
throw new Error(`${did_jwt_1.JWT_ERROR.INVALID_JWT}: Token not yet valid (nbf claim is in the future)`);
|
|
16
|
+
}
|
|
17
|
+
// Check 'issued at' claim if present
|
|
18
|
+
// Allow a small leeway (30 seconds) for clock skew
|
|
19
|
+
if (payload.iat && currentTime < payload.iat - 30) {
|
|
20
|
+
throw new Error(`${did_jwt_1.JWT_ERROR.INVALID_JWT}: Token issued in the future (iat claim is ahead of current time)`);
|
|
21
|
+
}
|
|
22
|
+
return true;
|
|
23
|
+
}
|
|
24
|
+
//# sourceMappingURL=validateJWTTime.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validateJWTTime.js","sourceRoot":"","sources":["../../../../../src/jwt/core/utils/validateJWTTime.ts"],"names":[],"mappings":";;AASA,0CAkBC;AA3BD,qCAAoC;AAEpC;;;;;;GAMG;AACH,SAAgB,eAAe,CAC7B,OAAuC,EACvC,WAAmB;IAEnB,sCAAsC;IACtC,IAAI,OAAO,CAAC,GAAG,IAAI,WAAW,GAAG,OAAO,CAAC,GAAG,EAAE,CAAC;QAC7C,MAAM,IAAI,KAAK,CAAC,GAAG,mBAAS,CAAC,WAAW,oDAAoD,CAAC,CAAC;IAChG,CAAC;IAED,qCAAqC;IACrC,mDAAmD;IACnD,IAAI,OAAO,CAAC,GAAG,IAAI,WAAW,GAAG,OAAO,CAAC,GAAG,GAAG,EAAE,EAAE,CAAC;QAClD,MAAM,IAAI,KAAK,CACb,GAAG,mBAAS,CAAC,WAAW,mEAAmE,CAC5F,CAAC;IACJ,CAAC;IAED,OAAO,IAAI,CAAC;AACd,CAAC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { VincentJWT } from '../types';
|
|
2
|
+
/**
|
|
3
|
+
* Decodes and verifies an {@link VincentJWT} token in string form
|
|
4
|
+
*
|
|
5
|
+
* This function returns the decoded {@link VincentJWT} object only if:
|
|
6
|
+
* 1. The JWT signature is valid
|
|
7
|
+
* 2. The JWT is not expired
|
|
8
|
+
* 3. All time claims (nbf, iat) are valid
|
|
9
|
+
* 4. The JWT has an audience claim that includes the expected audience
|
|
10
|
+
*
|
|
11
|
+
* @param {string} jwt - The JWT string to verify
|
|
12
|
+
* @param {string} expectedAudience - String that should be in the audience claim(s)
|
|
13
|
+
*
|
|
14
|
+
* @returns {VincentJWT} The decoded VincentJWT object if it was verified successfully
|
|
15
|
+
*/
|
|
16
|
+
export declare function verifyJWT(jwt: string, expectedAudience: string): VincentJWT;
|
|
17
|
+
/** This function uses the did-jwt library to decode a JWT string into its payload adding any extra Vincent fields
|
|
18
|
+
*
|
|
19
|
+
* @param {string} jwt - The JWT string to decode
|
|
20
|
+
* @returns The decoded Vincent JWT fields
|
|
21
|
+
*/
|
|
22
|
+
export declare function decodeJWT(jwt: string): VincentJWT;
|
|
23
|
+
//# sourceMappingURL=validate.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validate.d.ts","sourceRoot":"","sources":["../../../../src/jwt/core/validate.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAStC;;;;;;;;;;;;;GAaG;AACH,wBAAgB,SAAS,CAAC,GAAG,EAAE,MAAM,EAAE,gBAAgB,EAAE,MAAM,GAAG,UAAU,CAwE3E;AAED;;;;GAIG;AACH,wBAAgB,SAAS,CAAC,GAAG,EAAE,MAAM,GAAG,UAAU,CAgBjD"}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.verifyJWT = verifyJWT;
|
|
4
|
+
exports.decodeJWT = decodeJWT;
|
|
5
|
+
const tslib_1 = require("tslib");
|
|
6
|
+
const secp256k1 = tslib_1.__importStar(require("@noble/secp256k1"));
|
|
7
|
+
const didJWT = tslib_1.__importStar(require("did-jwt"));
|
|
8
|
+
const did_jwt_1 = require("did-jwt");
|
|
9
|
+
const ethers_1 = require("ethers");
|
|
10
|
+
const utils_1 = require("./utils");
|
|
11
|
+
/**
|
|
12
|
+
* Decodes and verifies an {@link VincentJWT} token in string form
|
|
13
|
+
*
|
|
14
|
+
* This function returns the decoded {@link VincentJWT} object only if:
|
|
15
|
+
* 1. The JWT signature is valid
|
|
16
|
+
* 2. The JWT is not expired
|
|
17
|
+
* 3. All time claims (nbf, iat) are valid
|
|
18
|
+
* 4. The JWT has an audience claim that includes the expected audience
|
|
19
|
+
*
|
|
20
|
+
* @param {string} jwt - The JWT string to verify
|
|
21
|
+
* @param {string} expectedAudience - String that should be in the audience claim(s)
|
|
22
|
+
*
|
|
23
|
+
* @returns {VincentJWT} The decoded VincentJWT object if it was verified successfully
|
|
24
|
+
*/
|
|
25
|
+
function verifyJWT(jwt, expectedAudience) {
|
|
26
|
+
if (!expectedAudience) {
|
|
27
|
+
throw new Error(`You must provide an expectedAudience`);
|
|
28
|
+
}
|
|
29
|
+
const decoded = decodeJWT(jwt);
|
|
30
|
+
const { aud, exp, pkp } = decoded.payload;
|
|
31
|
+
if (!exp) {
|
|
32
|
+
throw new Error(`${did_jwt_1.JWT_ERROR.INVALID_JWT}: JWT does not contain an expiration claim (exp)`);
|
|
33
|
+
}
|
|
34
|
+
const isExpired = (0, utils_1.isJWTExpired)(decoded);
|
|
35
|
+
if (isExpired) {
|
|
36
|
+
throw new Error(`${did_jwt_1.JWT_ERROR.INVALID_JWT}: JWT expired at ${exp}`);
|
|
37
|
+
}
|
|
38
|
+
(0, utils_1.validateJWTTime)(decoded.payload, Math.floor(Date.now() / 1000));
|
|
39
|
+
// Always validate audience - reject if no audience claim or expected audience isn't included
|
|
40
|
+
if (!aud) {
|
|
41
|
+
throw new Error(`${did_jwt_1.JWT_ERROR.INVALID_JWT}: JWT does not contain an audience claim (aud)`);
|
|
42
|
+
}
|
|
43
|
+
const audiences = Array.isArray(aud) ? aud : [aud];
|
|
44
|
+
if (!audiences.includes(expectedAudience)) {
|
|
45
|
+
throw new Error(`${did_jwt_1.JWT_ERROR.INVALID_AUDIENCE}: Expected audience ${expectedAudience} not found in aud claim`);
|
|
46
|
+
}
|
|
47
|
+
try {
|
|
48
|
+
const { signedData, signature } = (0, utils_1.splitJWT)(jwt);
|
|
49
|
+
// Process signature from base64url to binary
|
|
50
|
+
const signatureBytes = (0, utils_1.processJWTSignature)(signature);
|
|
51
|
+
// Extract r and s values from the signature
|
|
52
|
+
const r = signatureBytes.slice(0, 32);
|
|
53
|
+
const s = signatureBytes.slice(32, 64);
|
|
54
|
+
// Process public key
|
|
55
|
+
let publicKey = pkp.publicKey;
|
|
56
|
+
if (publicKey.startsWith('0x')) {
|
|
57
|
+
publicKey = publicKey.substring(2);
|
|
58
|
+
}
|
|
59
|
+
const publicKeyBytes = Buffer.from(publicKey, 'hex');
|
|
60
|
+
// PKPEthersWallet.signMessage() adds Ethereum prefix, so we need to add it here too
|
|
61
|
+
const ethPrefixedMessage = '\x19Ethereum Signed Message:\n' + signedData.length + signedData;
|
|
62
|
+
const messageBuffer = Buffer.from(ethPrefixedMessage, 'utf8');
|
|
63
|
+
const messageHash = ethers_1.ethers.utils.keccak256(messageBuffer);
|
|
64
|
+
const messageHashBytes = Buffer.from(messageHash.substring(2), 'hex');
|
|
65
|
+
const signatureForSecp = new Uint8Array([...r, ...s]);
|
|
66
|
+
// Verify the signature against the public key
|
|
67
|
+
const isVerified = secp256k1.verify(signatureForSecp, messageHashBytes, publicKeyBytes);
|
|
68
|
+
if (!isVerified) {
|
|
69
|
+
throw new Error(`Signature verify() did not pass for ${signature}`);
|
|
70
|
+
}
|
|
71
|
+
return decoded;
|
|
72
|
+
}
|
|
73
|
+
catch (error) {
|
|
74
|
+
throw new Error(`${did_jwt_1.JWT_ERROR.INVALID_SIGNATURE}: Invalid signature: ${error.message}`);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
/** This function uses the did-jwt library to decode a JWT string into its payload adding any extra Vincent fields
|
|
78
|
+
*
|
|
79
|
+
* @param {string} jwt - The JWT string to decode
|
|
80
|
+
* @returns The decoded Vincent JWT fields
|
|
81
|
+
*/
|
|
82
|
+
function decodeJWT(jwt) {
|
|
83
|
+
const decodedJwt = didJWT.decodeJWT(jwt);
|
|
84
|
+
const { app, authentication, pkp } = decodedJwt.payload;
|
|
85
|
+
if (!(0, utils_1.isDefinedObject)(app)) {
|
|
86
|
+
throw new Error(`${did_jwt_1.JWT_ERROR.INVALID_JWT}: Missing "app" field in JWT payload.`);
|
|
87
|
+
}
|
|
88
|
+
if (!(0, utils_1.isDefinedObject)(authentication)) {
|
|
89
|
+
throw new Error(`${did_jwt_1.JWT_ERROR.INVALID_JWT}: Missing "authentication" field in JWT payload.`);
|
|
90
|
+
}
|
|
91
|
+
if (!(0, utils_1.isDefinedObject)(pkp)) {
|
|
92
|
+
throw new Error(`${did_jwt_1.JWT_ERROR.INVALID_JWT}: Missing "pkp" field in JWT payload.`);
|
|
93
|
+
}
|
|
94
|
+
return decodedJwt;
|
|
95
|
+
}
|
|
96
|
+
//# sourceMappingURL=validate.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validate.js","sourceRoot":"","sources":["../../../../src/jwt/core/validate.ts"],"names":[],"mappings":"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"}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/** Helper methods for working with Vincent-issues JWTs.
|
|
2
|
+
*
|
|
3
|
+
* @module jwt
|
|
4
|
+
* @namespace
|
|
5
|
+
* @inline
|
|
6
|
+
* @category Vincent SDK API
|
|
7
|
+
*/
|
|
8
|
+
import { createPKPSignedJWT } from './core/create';
|
|
9
|
+
import { decodeJWT, verifyJWT } from './core/validate';
|
|
10
|
+
import { isJWTExpired } from './core/utils';
|
|
11
|
+
/** @function
|
|
12
|
+
* @hidden
|
|
13
|
+
* */
|
|
14
|
+
export declare const create: typeof createPKPSignedJWT;
|
|
15
|
+
/** Decodes a Vincent JWT in string form and returns an {@link VincentJWT} decoded object for your use
|
|
16
|
+
*
|
|
17
|
+
* @function
|
|
18
|
+
* @example
|
|
19
|
+
* ```typescript
|
|
20
|
+
* try {
|
|
21
|
+
* const decodedVincentJWT = decode(jwt);
|
|
22
|
+
* } catch(e) {
|
|
23
|
+
* // Handle malformed JWT string case
|
|
24
|
+
* }
|
|
25
|
+
*
|
|
26
|
+
* // You still need to verify the JWT!
|
|
27
|
+
* ```
|
|
28
|
+
* */
|
|
29
|
+
export declare const decode: typeof decodeJWT;
|
|
30
|
+
/**
|
|
31
|
+
* @inline
|
|
32
|
+
* @expand
|
|
33
|
+
* @function
|
|
34
|
+
*
|
|
35
|
+
* @example
|
|
36
|
+
* ```typescript
|
|
37
|
+
* try {
|
|
38
|
+
* const decodedAndVerifiedVincentJWT = verify(jwt, 'https://myapp.com');
|
|
39
|
+
* } catch(e) {
|
|
40
|
+
* // Handle invalid/expired JWT casew
|
|
41
|
+
* }
|
|
42
|
+
* ```
|
|
43
|
+
* */
|
|
44
|
+
export declare const verify: typeof verifyJWT;
|
|
45
|
+
/**
|
|
46
|
+
* When a JWT is expired, you need to use {@link VincentWebAppClient.redirectToConsentPage} to get a new JWT
|
|
47
|
+
* @inline
|
|
48
|
+
* @expand
|
|
49
|
+
* @function
|
|
50
|
+
*
|
|
51
|
+
* @example
|
|
52
|
+
* ```typescript
|
|
53
|
+
* import { jwt } from '@lit-protocol/vincent-app-sdk';
|
|
54
|
+
*
|
|
55
|
+
* const { decode, isExpired } = jwt;
|
|
56
|
+
*
|
|
57
|
+
* const decodedVincentJWT = decode(jwt);
|
|
58
|
+
* const isJWTExpired = isExpired(decodedVincentJWT);
|
|
59
|
+
*
|
|
60
|
+
* if(!isJWTExpired) {
|
|
61
|
+
* // User is logged in
|
|
62
|
+
* } else {
|
|
63
|
+
* // User needs to get a new JWT
|
|
64
|
+
* vincentWebAppClient.redirectToConsentPage({redirectUri: window.location.href });
|
|
65
|
+
* }
|
|
66
|
+
* ```
|
|
67
|
+
* */
|
|
68
|
+
export declare const isExpired: typeof isJWTExpired;
|
|
69
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/jwt/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AACnD,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AACvD,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAE5C;;KAEK;AACL,eAAO,MAAM,MAAM,2BAAqB,CAAC;AAEzC;;;;;;;;;;;;;KAaK;AACL,eAAO,MAAM,MAAM,kBAAY,CAAC;AAEhC;;;;;;;;;;;;;KAaK;AACL,eAAO,MAAM,MAAM,kBAAY,CAAC;AAEhC;;;;;;;;;;;;;;;;;;;;;;KAsBK;AACL,eAAO,MAAM,SAAS,qBAAe,CAAC"}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/** Helper methods for working with Vincent-issues JWTs.
|
|
3
|
+
*
|
|
4
|
+
* @module jwt
|
|
5
|
+
* @namespace
|
|
6
|
+
* @inline
|
|
7
|
+
* @category Vincent SDK API
|
|
8
|
+
*/
|
|
9
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
+
exports.isExpired = exports.verify = exports.decode = exports.create = void 0;
|
|
11
|
+
const create_1 = require("./core/create");
|
|
12
|
+
const validate_1 = require("./core/validate");
|
|
13
|
+
const utils_1 = require("./core/utils");
|
|
14
|
+
/** @function
|
|
15
|
+
* @hidden
|
|
16
|
+
* */
|
|
17
|
+
exports.create = create_1.createPKPSignedJWT;
|
|
18
|
+
/** Decodes a Vincent JWT in string form and returns an {@link VincentJWT} decoded object for your use
|
|
19
|
+
*
|
|
20
|
+
* @function
|
|
21
|
+
* @example
|
|
22
|
+
* ```typescript
|
|
23
|
+
* try {
|
|
24
|
+
* const decodedVincentJWT = decode(jwt);
|
|
25
|
+
* } catch(e) {
|
|
26
|
+
* // Handle malformed JWT string case
|
|
27
|
+
* }
|
|
28
|
+
*
|
|
29
|
+
* // You still need to verify the JWT!
|
|
30
|
+
* ```
|
|
31
|
+
* */
|
|
32
|
+
exports.decode = validate_1.decodeJWT;
|
|
33
|
+
/**
|
|
34
|
+
* @inline
|
|
35
|
+
* @expand
|
|
36
|
+
* @function
|
|
37
|
+
*
|
|
38
|
+
* @example
|
|
39
|
+
* ```typescript
|
|
40
|
+
* try {
|
|
41
|
+
* const decodedAndVerifiedVincentJWT = verify(jwt, 'https://myapp.com');
|
|
42
|
+
* } catch(e) {
|
|
43
|
+
* // Handle invalid/expired JWT casew
|
|
44
|
+
* }
|
|
45
|
+
* ```
|
|
46
|
+
* */
|
|
47
|
+
exports.verify = validate_1.verifyJWT;
|
|
48
|
+
/**
|
|
49
|
+
* When a JWT is expired, you need to use {@link VincentWebAppClient.redirectToConsentPage} to get a new JWT
|
|
50
|
+
* @inline
|
|
51
|
+
* @expand
|
|
52
|
+
* @function
|
|
53
|
+
*
|
|
54
|
+
* @example
|
|
55
|
+
* ```typescript
|
|
56
|
+
* import { jwt } from '@lit-protocol/vincent-app-sdk';
|
|
57
|
+
*
|
|
58
|
+
* const { decode, isExpired } = jwt;
|
|
59
|
+
*
|
|
60
|
+
* const decodedVincentJWT = decode(jwt);
|
|
61
|
+
* const isJWTExpired = isExpired(decodedVincentJWT);
|
|
62
|
+
*
|
|
63
|
+
* if(!isJWTExpired) {
|
|
64
|
+
* // User is logged in
|
|
65
|
+
* } else {
|
|
66
|
+
* // User needs to get a new JWT
|
|
67
|
+
* vincentWebAppClient.redirectToConsentPage({redirectUri: window.location.href });
|
|
68
|
+
* }
|
|
69
|
+
* ```
|
|
70
|
+
* */
|
|
71
|
+
exports.isExpired = utils_1.isJWTExpired;
|
|
72
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/jwt/index.ts"],"names":[],"mappings":";AAAA;;;;;;GAMG;;;AAEH,0CAAmD;AACnD,8CAAuD;AACvD,wCAA4C;AAE5C;;KAEK;AACQ,QAAA,MAAM,GAAG,2BAAkB,CAAC;AAEzC;;;;;;;;;;;;;KAaK;AACQ,QAAA,MAAM,GAAG,oBAAS,CAAC;AAEhC;;;;;;;;;;;;;KAaK;AACQ,QAAA,MAAM,GAAG,oBAAS,CAAC;AAEhC;;;;;;;;;;;;;;;;;;;;;;KAsBK;AACQ,QAAA,SAAS,GAAG,oBAAY,CAAC"}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import type { PKPEthersWallet } from '@lit-protocol/pkp-ethers';
|
|
2
|
+
import type { IRelayPKP } from '@lit-protocol/types';
|
|
3
|
+
import type { JWTHeader, JWTPayload } from 'did-jwt';
|
|
4
|
+
interface JWTDecoded {
|
|
5
|
+
header: JWTHeader;
|
|
6
|
+
payload: JWTPayload;
|
|
7
|
+
signature: string;
|
|
8
|
+
data: string;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Configuration interface for creating a JWT (JSON Web Token) signed by a PKP wallet.
|
|
12
|
+
* Vincent App developers will likely never need this function, as the provider of the JWT is the Vincent consent page frontend
|
|
13
|
+
*
|
|
14
|
+
* @interface JWTConfig
|
|
15
|
+
* @hidden
|
|
16
|
+
* @property {PKPEthersWallet} pkpWallet - The PKP Ethers wallet instance used for signing the JWT
|
|
17
|
+
* @property {IRelayPKP} pkp - The PKP object
|
|
18
|
+
* @property {Record<string, unknown>} payload - Custom claims to include in the JWT payload
|
|
19
|
+
* @property {number} expiresInMinutes - Token expiration time in minutes from current time
|
|
20
|
+
* @property {string} audience - The domain(s) this token is intended for (aud claim)
|
|
21
|
+
*/
|
|
22
|
+
export interface JWTConfig {
|
|
23
|
+
pkpWallet: PKPEthersWallet;
|
|
24
|
+
pkp: IRelayPKP;
|
|
25
|
+
payload: Record<string, unknown>;
|
|
26
|
+
expiresInMinutes: number;
|
|
27
|
+
audience: string | string[];
|
|
28
|
+
app: {
|
|
29
|
+
id: string;
|
|
30
|
+
version: number;
|
|
31
|
+
};
|
|
32
|
+
authentication: {
|
|
33
|
+
type: string;
|
|
34
|
+
value?: string;
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Extended payload interface for Vincent-specific JWTs.
|
|
39
|
+
*
|
|
40
|
+
* @interface VincentJWTPayload
|
|
41
|
+
* @extends {JWTPayload} Extends the JWTPayload type from `did-jwt` with Vincent-specific properties
|
|
42
|
+
* @property {string} app - The app associated with the JWT.
|
|
43
|
+
* @property {string} pkp - The PKP associated with the JWT.
|
|
44
|
+
* @property {string} authentication - The authentication method used to generate the JWT.
|
|
45
|
+
*/
|
|
46
|
+
export interface VincentJWTPayload extends JWTPayload {
|
|
47
|
+
pkp: IRelayPKP;
|
|
48
|
+
app: {
|
|
49
|
+
id: string;
|
|
50
|
+
version: number;
|
|
51
|
+
};
|
|
52
|
+
authentication: {
|
|
53
|
+
type: string;
|
|
54
|
+
value?: string;
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Interface representing a decoded Vincent JWT
|
|
59
|
+
*
|
|
60
|
+
* @interface VincentJWT
|
|
61
|
+
* @extends { JWTDecoded } Extends the payload provided by the JWTDecoded type from `did-jwt` with Vincent-specific properties
|
|
62
|
+
* @property {VincentJWTPayload} payload - The payload of the JWT
|
|
63
|
+
*/
|
|
64
|
+
export interface VincentJWT extends JWTDecoded {
|
|
65
|
+
payload: VincentJWTPayload;
|
|
66
|
+
}
|
|
67
|
+
export {};
|
|
68
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/jwt/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAC;AAChE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,KAAK,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAGrD,UAAU,UAAU;IAClB,MAAM,EAAE,SAAS,CAAC;IAClB,OAAO,EAAE,UAAU,CAAC;IACpB,SAAS,EAAE,MAAM,CAAC;IAClB,IAAI,EAAE,MAAM,CAAC;CACd;AAED;;;;;;;;;;;GAWG;AACH,MAAM,WAAW,SAAS;IACxB,SAAS,EAAE,eAAe,CAAC;IAC3B,GAAG,EAAE,SAAS,CAAC;IACf,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACjC,gBAAgB,EAAE,MAAM,CAAC;IACzB,QAAQ,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;IAC5B,GAAG,EAAE;QACH,EAAE,EAAE,MAAM,CAAC;QACX,OAAO,EAAE,MAAM,CAAC;KACjB,CAAC;IACF,cAAc,EAAE;QACd,IAAI,EAAE,MAAM,CAAC;QACb,KAAK,CAAC,EAAE,MAAM,CAAC;KAChB,CAAC;CACH;AAED;;;;;;;;GAQG;AACH,MAAM,WAAW,iBAAkB,SAAQ,UAAU;IACnD,GAAG,EAAE,SAAS,CAAC;IACf,GAAG,EAAE;QACH,EAAE,EAAE,MAAM,CAAC;QACX,OAAO,EAAE,MAAM,CAAC;KACjB,CAAC;IACF,cAAc,EAAE;QACd,IAAI,EAAE,MAAM,CAAC;QACb,KAAK,CAAC,EAAE,MAAM,CAAC;KAChB,CAAC;CACH;AAED;;;;;;GAMG;AACH,MAAM,WAAW,UAAW,SAAQ,UAAU;IAC5C,OAAO,EAAE,iBAAiB,CAAC;CAC5B"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/jwt/types.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/toolClient/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getVincentToolClient = void 0;
|
|
4
|
+
var vincentToolClient_1 = require("./vincentToolClient");
|
|
5
|
+
Object.defineProperty(exports, "getVincentToolClient", { enumerable: true, get: function () { return vincentToolClient_1.getVincentToolClient; } });
|
|
6
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/toolClient/index.ts"],"names":[],"mappings":";;;AAAA,yDAA2D;AAAlD,yHAAA,oBAAoB,OAAA"}
|