@lit-protocol/vincent-app-sdk 0.0.7-mma → 0.0.9-mma

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (84) hide show
  1. package/README.md +1 -1
  2. package/dist/README.md +1 -1
  3. package/dist/package.json +1 -2
  4. package/dist/src/expressMiddleware/express.js +10 -1
  5. package/dist/src/expressMiddleware/express.js.map +1 -1
  6. package/dist/src/expressMiddleware/types.d.ts +2 -2
  7. package/dist/src/expressMiddleware/types.d.ts.map +1 -1
  8. package/dist/src/jwt/accessors.d.ts +36 -3
  9. package/dist/src/jwt/accessors.d.ts.map +1 -1
  10. package/dist/src/jwt/accessors.js +60 -2
  11. package/dist/src/jwt/accessors.js.map +1 -1
  12. package/dist/src/jwt/constants.d.ts +33 -0
  13. package/dist/src/jwt/constants.d.ts.map +1 -0
  14. package/dist/src/jwt/constants.js +36 -0
  15. package/dist/src/jwt/constants.js.map +1 -0
  16. package/dist/src/jwt/core/create.d.ts +14 -19
  17. package/dist/src/jwt/core/create.d.ts.map +1 -1
  18. package/dist/src/jwt/core/create.js +78 -78
  19. package/dist/src/jwt/core/create.js.map +1 -1
  20. package/dist/src/jwt/core/decode.d.ts +3 -0
  21. package/dist/src/jwt/core/decode.d.ts.map +1 -0
  22. package/dist/src/jwt/core/decode.js +27 -0
  23. package/dist/src/jwt/core/decode.js.map +1 -0
  24. package/dist/src/jwt/core/isExpired.d.ts +3 -3
  25. package/dist/src/jwt/core/isExpired.d.ts.map +1 -1
  26. package/dist/src/jwt/core/isExpired.js +1 -1
  27. package/dist/src/jwt/core/isExpired.js.map +1 -1
  28. package/dist/src/jwt/core/utils/base64.d.ts +1 -0
  29. package/dist/src/jwt/core/utils/base64.d.ts.map +1 -1
  30. package/dist/src/jwt/core/utils/base64.js +1 -0
  31. package/dist/src/jwt/core/utils/base64.js.map +1 -1
  32. package/dist/src/jwt/core/utils/decodeJWTStr.d.ts +3 -0
  33. package/dist/src/jwt/core/utils/decodeJWTStr.d.ts.map +1 -0
  34. package/dist/src/jwt/core/utils/decodeJWTStr.js +21 -0
  35. package/dist/src/jwt/core/utils/decodeJWTStr.js.map +1 -0
  36. package/dist/src/jwt/core/utils/index.d.ts +2 -2
  37. package/dist/src/jwt/core/utils/index.d.ts.map +1 -1
  38. package/dist/src/jwt/core/utils/index.js +6 -5
  39. package/dist/src/jwt/core/utils/index.js.map +1 -1
  40. package/dist/src/jwt/core/utils/validateJWTTime.js +3 -3
  41. package/dist/src/jwt/core/utils/validateJWTTime.js.map +1 -1
  42. package/dist/src/jwt/core/utils/verifyES256KSignature.d.ts +5 -0
  43. package/dist/src/jwt/core/utils/verifyES256KSignature.d.ts.map +1 -0
  44. package/dist/src/jwt/core/utils/verifyES256KSignature.js +33 -0
  45. package/dist/src/jwt/core/utils/verifyES256KSignature.js.map +1 -0
  46. package/dist/src/jwt/core/verify.d.ts +27 -0
  47. package/dist/src/jwt/core/verify.d.ts.map +1 -0
  48. package/dist/src/jwt/core/verify.js +84 -0
  49. package/dist/src/jwt/core/verify.js.map +1 -0
  50. package/dist/src/jwt/index.d.ts +7 -7
  51. package/dist/src/jwt/index.d.ts.map +1 -1
  52. package/dist/src/jwt/index.js +20 -10
  53. package/dist/src/jwt/index.js.map +1 -1
  54. package/dist/src/jwt/typeGuards.d.ts +28 -11
  55. package/dist/src/jwt/typeGuards.d.ts.map +1 -1
  56. package/dist/src/jwt/typeGuards.js +51 -20
  57. package/dist/src/jwt/typeGuards.js.map +1 -1
  58. package/dist/src/jwt/types.d.ts +123 -49
  59. package/dist/src/jwt/types.d.ts.map +1 -1
  60. package/dist/src/utils/delegation.js +2 -2
  61. package/dist/src/utils/delegation.js.map +1 -1
  62. package/dist/src/utils/types.d.ts +1 -4
  63. package/dist/src/utils/types.d.ts.map +1 -1
  64. package/dist/src/webAuthClient/app.js +1 -1
  65. package/dist/src/webAuthClient/app.js.map +1 -1
  66. package/dist/src/webAuthClient/internal/uriHelpers.d.ts +3 -3
  67. package/dist/src/webAuthClient/internal/uriHelpers.d.ts.map +1 -1
  68. package/dist/src/webAuthClient/internal/uriHelpers.js +6 -4
  69. package/dist/src/webAuthClient/internal/uriHelpers.js.map +1 -1
  70. package/dist/src/webAuthClient/types.d.ts +8 -8
  71. package/dist/src/webAuthClient/types.d.ts.map +1 -1
  72. package/package.json +3 -4
  73. package/dist/src/jwt/core/utils/processJWTSignature.d.ts +0 -8
  74. package/dist/src/jwt/core/utils/processJWTSignature.d.ts.map +0 -1
  75. package/dist/src/jwt/core/utils/processJWTSignature.js +0 -14
  76. package/dist/src/jwt/core/utils/processJWTSignature.js.map +0 -1
  77. package/dist/src/jwt/core/utils/splitJWT.d.ts +0 -11
  78. package/dist/src/jwt/core/utils/splitJWT.d.ts.map +0 -1
  79. package/dist/src/jwt/core/utils/splitJWT.js +0 -21
  80. package/dist/src/jwt/core/utils/splitJWT.js.map +0 -1
  81. package/dist/src/jwt/core/validate.d.ts +0 -29
  82. package/dist/src/jwt/core/validate.d.ts.map +0 -1
  83. package/dist/src/jwt/core/validate.js +0 -143
  84. package/dist/src/jwt/core/validate.js.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"base64.d.ts","sourceRoot":"","sources":["../../../../../src/jwt/core/utils/base64.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,wBAAgB,UAAU,CAAC,MAAM,EAAE,MAAM,GAAG,UAAU,CAuBrD;AAED;;;;GAIG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,UAAU,GAAG,MAAM,CAkBrD"}
1
+ {"version":3,"file":"base64.d.ts","sourceRoot":"","sources":["../../../../../src/jwt/core/utils/base64.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,wBAAgB,UAAU,CAAC,MAAM,EAAE,MAAM,GAAG,UAAU,CAuBrD;AAED;;;;;GAKG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,UAAU,GAAG,MAAM,CAkBrD"}
@@ -32,6 +32,7 @@ function fromBase64(base64) {
32
32
  /**
33
33
  * Converts a Uint8Array to a base64url-encoded string.
34
34
  * Works in all JS environments (Node.js, Deno, browser, Web Workers).
35
+ *
35
36
  * No Buffer polyfill requirement.
36
37
  */
37
38
  function toBase64Url(bytes) {
@@ -1 +1 @@
1
- {"version":3,"file":"base64.js","sourceRoot":"","sources":["../../../../../src/jwt/core/utils/base64.ts"],"names":[],"mappings":";;AAMA,gCAuBC;AAOD,kCAkBC;AAtDD;;;;;GAKG;AACH,SAAgB,UAAU,CAAC,MAAc;IACvC,+BAA+B;IAC/B,MAAM,UAAU,GAAG,MAAM;SACtB,OAAO,CAAC,IAAI,EAAE,GAAG,CAAC;SAClB,OAAO,CAAC,IAAI,EAAE,GAAG,CAAC;SAClB,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,CAAC,GAAG,CAAC,EAAE,GAAG,CAAC,CAAC;IAEjD,UAAU;IACV,IAAI,OAAO,MAAM,KAAK,WAAW,IAAI,OAAO,MAAM,CAAC,IAAI,KAAK,UAAU,EAAE,CAAC;QACvE,OAAO,IAAI,UAAU,CAAC,MAAM,CAAC,IAAI,CAAC,UAAU,EAAE,QAAQ,CAAC,CAAC,CAAC;IAC3D,CAAC;IAED,8BAA8B;IAC9B,IAAI,OAAO,IAAI,KAAK,WAAW,EAAE,CAAC;QAChC,MAAM,MAAM,GAAG,IAAI,CAAC,UAAU,CAAC,CAAC;QAChC,MAAM,KAAK,GAAG,IAAI,UAAU,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;QAC5C,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;YACvC,KAAK,CAAC,CAAC,CAAC,GAAG,MAAM,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC;QAClC,CAAC;QACD,OAAO,KAAK,CAAC;IACf,CAAC;IAED,MAAM,IAAI,KAAK,CAAC,0DAA0D,CAAC,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C/B,OAAO,MAAM,CAAC,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;IAC3E,CAAC;IAED,MAAM,IAAI,KAAK,CAAC,0DAA0D,CAAC,CAAC;AAC9E,CAAC"}
@@ -0,0 +1,3 @@
1
+ import type { DecodedJWT } from '../../types';
2
+ export declare function decodeJWT(jws: string): DecodedJWT;
3
+ //# sourceMappingURL=decodeJWTStr.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"decodeJWTStr.d.ts","sourceRoot":"","sources":["../../../../../src/jwt/core/utils/decodeJWTStr.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAK9C,wBAAgB,SAAS,CAAC,GAAG,EAAE,MAAM,GAAG,UAAU,CAejD"}
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.decodeJWT = decodeJWT;
4
+ const utils_1 = require("ethers/lib/utils");
5
+ const typeGuards_1 = require("../../typeGuards");
6
+ const base64_1 = require("./base64");
7
+ function decodeJWT(jws) {
8
+ const parts = jws.match(/^([a-zA-Z0-9_-]+)\.([a-zA-Z0-9_-]+)\.([a-zA-Z0-9_-]+)$/);
9
+ if (parts) {
10
+ const payload = JSON.parse((0, utils_1.toUtf8String)((0, base64_1.fromBase64)(parts[2])));
11
+ (0, typeGuards_1.assertJWTAPIVersion)(payload.__vincentJWTApiVersion);
12
+ return {
13
+ header: JSON.parse((0, utils_1.toUtf8String)((0, base64_1.fromBase64)(parts[1]))),
14
+ payload,
15
+ signature: parts[3],
16
+ data: `${parts[1]}.${parts[2]}`,
17
+ };
18
+ }
19
+ throw new Error('invalid_argument: Incorrect format JWS');
20
+ }
21
+ //# sourceMappingURL=decodeJWTStr.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"decodeJWTStr.js","sourceRoot":"","sources":["../../../../../src/jwt/core/utils/decodeJWTStr.ts"],"names":[],"mappings":";;AAOA,8BAeC;AAtBD,4CAAgD;AAIhD,iDAAuD;AACvD,qCAAsC;AAEtC,SAAgB,SAAS,CAAC,GAAW;IACnC,MAAM,KAAK,GAAG,GAAG,CAAC,KAAK,CAAC,wDAAwD,CAAC,CAAC;IAClF,IAAI,KAAK,EAAE,CAAC;QACV,MAAM,OAAO,GAAG,IAAI,CAAC,KAAK,CAAC,IAAA,oBAAY,EAAC,IAAA,mBAAU,EAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;QAC/D,IAAA,gCAAmB,EAAC,OAAO,CAAC,sBAAsB,CAAC,CAAC;QAEpD,OAAO;YACL,MAAM,EAAE,IAAI,CAAC,KAAK,CAAC,IAAA,oBAAY,EAAC,IAAA,mBAAU,EAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;YACtD,OAAO;YACP,SAAS,EAAE,KAAK,CAAC,CAAC,CAAC;YACnB,IAAI,EAAE,GAAG,KAAK,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,CAAC,CAAC,EAAE;SAChC,CAAC;IACJ,CAAC;IAED,MAAM,IAAI,KAAK,CAAC,wCAAwC,CAAC,CAAC;AAC5D,CAAC"}
@@ -1,5 +1,5 @@
1
1
  export { isDefinedObject } from './definedObject';
2
2
  export { validateJWTTime } from './validateJWTTime';
3
- export { splitJWT } from './splitJWT';
4
- export { processJWTSignature } from './processJWTSignature';
3
+ export { fromBase64, toBase64Url } from './base64';
4
+ export { verifyES256KSignature } from './verifyES256KSignature';
5
5
  //# sourceMappingURL=index.d.ts.map
@@ -1 +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,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACtC,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC"}
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,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AACnD,OAAO,EAAE,qBAAqB,EAAE,MAAM,yBAAyB,CAAC"}
@@ -1,12 +1,13 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.processJWTSignature = exports.splitJWT = exports.validateJWTTime = exports.isDefinedObject = void 0;
3
+ exports.verifyES256KSignature = exports.toBase64Url = exports.fromBase64 = exports.validateJWTTime = exports.isDefinedObject = void 0;
4
4
  var definedObject_1 = require("./definedObject");
5
5
  Object.defineProperty(exports, "isDefinedObject", { enumerable: true, get: function () { return definedObject_1.isDefinedObject; } });
6
6
  var validateJWTTime_1 = require("./validateJWTTime");
7
7
  Object.defineProperty(exports, "validateJWTTime", { enumerable: true, get: function () { return validateJWTTime_1.validateJWTTime; } });
8
- var splitJWT_1 = require("./splitJWT");
9
- Object.defineProperty(exports, "splitJWT", { enumerable: true, get: function () { return splitJWT_1.splitJWT; } });
10
- var processJWTSignature_1 = require("./processJWTSignature");
11
- Object.defineProperty(exports, "processJWTSignature", { enumerable: true, get: function () { return processJWTSignature_1.processJWTSignature; } });
8
+ var base64_1 = require("./base64");
9
+ Object.defineProperty(exports, "fromBase64", { enumerable: true, get: function () { return base64_1.fromBase64; } });
10
+ Object.defineProperty(exports, "toBase64Url", { enumerable: true, get: function () { return base64_1.toBase64Url; } });
11
+ var verifyES256KSignature_1 = require("./verifyES256KSignature");
12
+ Object.defineProperty(exports, "verifyES256KSignature", { enumerable: true, get: function () { return verifyES256KSignature_1.verifyES256KSignature; } });
12
13
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../src/jwt/core/utils/index.ts"],"names":[],"mappings":";;;AAAA,iDAAkD;AAAzC,gHAAA,eAAe,OAAA;AACxB,qDAAoD;AAA3C,kHAAA,eAAe,OAAA;AACxB,uCAAsC;AAA7B,oGAAA,QAAQ,OAAA;AACjB,6DAA4D;AAAnD,0HAAA,mBAAmB,OAAA"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../src/jwt/core/utils/index.ts"],"names":[],"mappings":";;;AAAA,iDAAkD;AAAzC,gHAAA,eAAe,OAAA;AACxB,qDAAoD;AAA3C,kHAAA,eAAe,OAAA;AACxB,mCAAmD;AAA1C,oGAAA,UAAU,OAAA;AAAE,qGAAA,WAAW,OAAA;AAChC,iEAAgE;AAAvD,8HAAA,qBAAqB,OAAA"}
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.validateJWTTime = validateJWTTime;
4
- const did_jwt_1 = require("did-jwt");
4
+ const constants_1 = require("../../constants");
5
5
  /** Validates JWT time claims (iat and nbf)
6
6
  * @ignore
7
7
  *
@@ -12,12 +12,12 @@ const did_jwt_1 = require("did-jwt");
12
12
  function validateJWTTime(payload, currentTime) {
13
13
  // Check 'not before' claim if present
14
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)`);
15
+ throw new Error(`${constants_1.JWT_ERROR.INVALID_JWT}: Token not yet valid (nbf claim is in the future)`);
16
16
  }
17
17
  // Check 'issued at' claim if present
18
18
  // Allow a small leeway (30 seconds) for clock skew
19
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)`);
20
+ throw new Error(`${constants_1.JWT_ERROR.INVALID_JWT}: Token issued in the future (iat claim is ahead of current time)`);
21
21
  }
22
22
  return true;
23
23
  }
@@ -1 +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"}
1
+ {"version":3,"file":"validateJWTTime.js","sourceRoot":"","sources":["../../../../../src/jwt/core/utils/validateJWTTime.ts"],"names":[],"mappings":";;AASA,0CAkBC;AA3BD,+CAA4C;AAE5C;;;;;;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,qBAAS,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,qBAAS,CAAC,WAAW,mEAAmE,CAC5F,CAAC;IACJ,CAAC;IAED,OAAO,IAAI,CAAC;AACd,CAAC"}
@@ -0,0 +1,5 @@
1
+ import type { AnyVincentJWT } from '../../types';
2
+ export declare function verifyES256KSignature({ decoded }: {
3
+ decoded: AnyVincentJWT;
4
+ }): Promise<void>;
5
+ //# sourceMappingURL=verifyES256KSignature.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"verifyES256KSignature.d.ts","sourceRoot":"","sources":["../../../../../src/jwt/core/utils/verifyES256KSignature.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAKjD,wBAAsB,qBAAqB,CAAC,EAAE,OAAO,EAAE,EAAE;IAAE,OAAO,EAAE,aAAa,CAAA;CAAE,iBA8BlF"}
@@ -0,0 +1,33 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.verifyES256KSignature = verifyES256KSignature;
4
+ const tslib_1 = require("tslib");
5
+ const secp256k1 = tslib_1.__importStar(require("@noble/secp256k1"));
6
+ const ethers_1 = require("ethers");
7
+ const utils_1 = require("ethers/lib/utils");
8
+ const constants_1 = require("../../constants");
9
+ const base64_1 = require("./base64");
10
+ async function verifyES256KSignature({ decoded }) {
11
+ try {
12
+ const { data, signature } = decoded;
13
+ // Process signature from base64url to binary
14
+ const signatureBytes = (0, base64_1.fromBase64)(signature);
15
+ // Extract r and s values from the signature
16
+ const r = signatureBytes.slice(0, 32);
17
+ const s = signatureBytes.slice(32, 64);
18
+ const publicKeyBytes = (0, utils_1.arrayify)(decoded.payload.publicKey, { allowMissingPrefix: true });
19
+ // PKPEthersWallet.signMessage() adds Ethereum prefix, so we need to add it here too
20
+ const ethPrefixedMessage = '\x19Ethereum Signed Message:\n' + data.length + data;
21
+ const messageHashBytes = (0, utils_1.arrayify)(ethers_1.ethers.utils.keccak256((0, utils_1.toUtf8Bytes)(ethPrefixedMessage)));
22
+ const signatureForSecp = new Uint8Array([...r, ...s]);
23
+ // Verify the signature against the public key
24
+ const isVerified = secp256k1.verify(signatureForSecp, messageHashBytes, publicKeyBytes);
25
+ if (!isVerified) {
26
+ throw new Error(`Signature verify() did not pass for ${signature}`);
27
+ }
28
+ }
29
+ catch (error) {
30
+ throw new Error(`${constants_1.JWT_ERROR.INVALID_SIGNATURE}: Invalid signature: ${error.message}`);
31
+ }
32
+ }
33
+ //# sourceMappingURL=verifyES256KSignature.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"verifyES256KSignature.js","sourceRoot":"","sources":["../../../../../src/jwt/core/utils/verifyES256KSignature.ts"],"names":[],"mappings":";;AASA,sDA8BC;;AAvCD,oEAA8C;AAC9C,mCAAgC;AAChC,4CAAyD;AAIzD,+CAA4C;AAC5C,qCAAsC;AAE/B,KAAK,UAAU,qBAAqB,CAAC,EAAE,OAAO,EAA8B;IACjF,IAAI,CAAC;QACH,MAAM,EAAE,IAAI,EAAE,SAAS,EAAE,GAAG,OAAO,CAAC;QAEpC,6CAA6C;QAC7C,MAAM,cAAc,GAAG,IAAA,mBAAU,EAAC,SAAS,CAAC,CAAC;QAE7C,4CAA4C;QAC5C,MAAM,CAAC,GAAG,cAAc,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;QACtC,MAAM,CAAC,GAAG,cAAc,CAAC,KAAK,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC;QAEvC,MAAM,cAAc,GAAG,IAAA,gBAAQ,EAAC,OAAO,CAAC,OAAO,CAAC,SAAS,EAAE,EAAE,kBAAkB,EAAE,IAAI,EAAE,CAAC,CAAC;QAEzF,oFAAoF;QACpF,MAAM,kBAAkB,GAAG,gCAAgC,GAAG,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC;QACjF,MAAM,gBAAgB,GAAG,IAAA,gBAAQ,EAAC,eAAM,CAAC,KAAK,CAAC,SAAS,CAAC,IAAA,mBAAW,EAAC,kBAAkB,CAAC,CAAC,CAAC,CAAC;QAE3F,MAAM,gBAAgB,GAAG,IAAI,UAAU,CAAC,CAAC,GAAG,CAAC,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC;QAEtD,8CAA8C;QAC9C,MAAM,UAAU,GAAG,SAAS,CAAC,MAAM,CAAC,gBAAgB,EAAE,gBAAgB,EAAE,cAAc,CAAC,CAAC;QAExF,IAAI,CAAC,UAAU,EAAE,CAAC;YAChB,MAAM,IAAI,KAAK,CAAC,uCAAuC,SAAS,EAAE,CAAC,CAAC;QACtE,CAAC;IACH,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,IAAI,KAAK,CACb,GAAG,qBAAS,CAAC,iBAAiB,wBAAyB,KAAe,CAAC,OAAO,EAAE,CACjF,CAAC;IACJ,CAAC;AACH,CAAC"}
@@ -0,0 +1,27 @@
1
+ import type { VincentJWTAppUser, VincentJWTPlatformUser, VincentJWTDelegatee } from '../types';
2
+ /** Verify a JWT that must decode to a VincentAppUserJWT
3
+ *
4
+ * @category API > Verify
5
+ */
6
+ export declare function verifyVincentAppUserJWT({ jwt, expectedAudience, requiredAppId, }: {
7
+ jwt: string;
8
+ expectedAudience: string;
9
+ requiredAppId: number;
10
+ }): Promise<VincentJWTAppUser>;
11
+ /**
12
+ *
13
+ * @category API > Verify
14
+ */
15
+ export declare function verifyVincentPlatformJWT({ jwt, expectedAudience, }: {
16
+ jwt: string;
17
+ expectedAudience: string;
18
+ }): Promise<VincentJWTPlatformUser>;
19
+ /**
20
+ *
21
+ * @category API > Verify
22
+ */
23
+ export declare function verifyVincentDelegateeJWT({ jwt, expectedAudience, }: {
24
+ jwt: string;
25
+ expectedAudience: string;
26
+ }): Promise<VincentJWTDelegatee>;
27
+ //# sourceMappingURL=verify.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"verify.d.ts","sourceRoot":"","sources":["../../../../src/jwt/core/verify.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,iBAAiB,EAEjB,sBAAsB,EACtB,mBAAmB,EACpB,MAAM,UAAU,CAAC;AA6DlB;;;GAGG;AACH,wBAAsB,uBAAuB,CAAC,EAC5C,GAAG,EACH,gBAAgB,EAChB,aAAa,GACd,EAAE;IACD,GAAG,EAAE,MAAM,CAAC;IACZ,gBAAgB,EAAE,MAAM,CAAC;IACzB,aAAa,EAAE,MAAM,CAAC;CACvB,GAAG,OAAO,CAAC,iBAAiB,CAAC,CAgB7B;AAED;;;GAGG;AACH,wBAAsB,wBAAwB,CAAC,EAC7C,GAAG,EACH,gBAAgB,GACjB,EAAE;IACD,GAAG,EAAE,MAAM,CAAC;IACZ,gBAAgB,EAAE,MAAM,CAAC;CAC1B,GAAG,OAAO,CAAC,sBAAsB,CAAC,CAQlC;AAED;;;GAGG;AACH,wBAAsB,yBAAyB,CAAC,EAC9C,GAAG,EACH,gBAAgB,GACjB,EAAE;IACD,GAAG,EAAE,MAAM,CAAC;IACZ,gBAAgB,EAAE,MAAM,CAAC;CAC1B,GAAG,OAAO,CAAC,mBAAmB,CAAC,CAQ/B"}
@@ -0,0 +1,84 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.verifyVincentAppUserJWT = verifyVincentAppUserJWT;
4
+ exports.verifyVincentPlatformJWT = verifyVincentPlatformJWT;
5
+ exports.verifyVincentDelegateeJWT = verifyVincentDelegateeJWT;
6
+ const accessors_1 = require("../accessors");
7
+ const constants_1 = require("../constants");
8
+ const typeGuards_1 = require("../typeGuards");
9
+ const decode_1 = require("./decode");
10
+ const isExpired_1 = require("./isExpired");
11
+ const utils_1 = require("./utils");
12
+ const verifyES256KSignature_1 = require("./utils/verifyES256KSignature");
13
+ /**
14
+ * Verifies a Vincent JWT's:
15
+ * - signature using `publicKey`
16
+ * - expiration, not-before, issued-at
17
+ * - audience against `expectedAudience`
18
+ *
19
+ * This method is called internally from the type-specific JWT verify methods and is not end-user facing
20
+ *
21
+ * @internal
22
+ */
23
+ async function verifyAnyVincentJWT({ jwt, expectedAudience, }) {
24
+ if (!expectedAudience) {
25
+ throw new Error(`You must provide an expectedAudience`);
26
+ }
27
+ const decoded = (0, decode_1.decodeVincentJWT)(jwt);
28
+ const { payload } = decoded;
29
+ const { exp, publicKey } = payload;
30
+ if (!exp) {
31
+ throw new Error(`${constants_1.JWT_ERROR.INVALID_JWT}: Missing expiration (exp)`);
32
+ }
33
+ if ((0, isExpired_1.isExpired)(decoded)) {
34
+ throw new Error(`${constants_1.JWT_ERROR.INVALID_JWT}: JWT expired at ${exp}`);
35
+ }
36
+ (0, utils_1.validateJWTTime)(payload, Math.floor(Date.now() / 1000));
37
+ const audiences = (0, accessors_1.getAudience)(decoded);
38
+ if (!audiences.includes(expectedAudience)) {
39
+ throw new Error(`${constants_1.JWT_ERROR.INVALID_AUDIENCE}: Expected audience ${expectedAudience} not found in aud claim`);
40
+ }
41
+ if (!publicKey) {
42
+ throw new Error(`${constants_1.JWT_ERROR.INVALID_JWT}: Missing publicKey in payload`);
43
+ }
44
+ await (0, verifyES256KSignature_1.verifyES256KSignature)({ decoded });
45
+ return decoded;
46
+ }
47
+ /** Verify a JWT that must decode to a VincentAppUserJWT
48
+ *
49
+ * @category API > Verify
50
+ */
51
+ async function verifyVincentAppUserJWT({ jwt, expectedAudience, requiredAppId, }) {
52
+ const decoded = await verifyAnyVincentJWT({ jwt, expectedAudience });
53
+ if (!(0, typeGuards_1.isAppUser)(decoded)) {
54
+ throw new Error(`${constants_1.JWT_ERROR.INVALID_JWT}: JWT is not an app-user token`);
55
+ }
56
+ const { app } = decoded.payload;
57
+ if (!app || app.id !== requiredAppId) {
58
+ throw new Error(`${constants_1.JWT_ERROR.INVALID_JWT}: appId mismatch; expected ${requiredAppId}, got ${app === null || app === void 0 ? void 0 : app.id}`);
59
+ }
60
+ return decoded;
61
+ }
62
+ /**
63
+ *
64
+ * @category API > Verify
65
+ */
66
+ async function verifyVincentPlatformJWT({ jwt, expectedAudience, }) {
67
+ const decoded = await verifyAnyVincentJWT({ jwt, expectedAudience });
68
+ if (!(0, typeGuards_1.isPlatformUser)(decoded)) {
69
+ throw new Error(`${constants_1.JWT_ERROR.INVALID_JWT}: JWT is not a platform token`);
70
+ }
71
+ return decoded;
72
+ }
73
+ /**
74
+ *
75
+ * @category API > Verify
76
+ */
77
+ async function verifyVincentDelegateeJWT({ jwt, expectedAudience, }) {
78
+ const decoded = await verifyAnyVincentJWT({ jwt, expectedAudience });
79
+ if (!(0, typeGuards_1.isDelegatee)(decoded)) {
80
+ throw new Error(`${constants_1.JWT_ERROR.INVALID_JWT}: JWT is not a delegatee token`);
81
+ }
82
+ return decoded;
83
+ }
84
+ //# sourceMappingURL=verify.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"verify.js","sourceRoot":"","sources":["../../../../src/jwt/core/verify.ts"],"names":[],"mappings":";;AAsEA,0DAwBC;AAMD,4DAcC;AAMD,8DAcC;AA/HD,4CAA2C;AAC3C,4CAAyC;AACzC,8CAAuE;AACvE,qCAA4C;AAC5C,2CAAwC;AACxC,mCAA0C;AAC1C,yEAAsE;AAEtE;;;;;;;;;GASG;AAEH,KAAK,UAAU,mBAAmB,CAAC,EACjC,GAAG,EACH,gBAAgB,GAIjB;IACC,IAAI,CAAC,gBAAgB,EAAE,CAAC;QACtB,MAAM,IAAI,KAAK,CAAC,sCAAsC,CAAC,CAAC;IAC1D,CAAC;IAED,MAAM,OAAO,GAAG,IAAA,yBAAgB,EAAC,GAAG,CAAC,CAAC;IACtC,MAAM,EAAE,OAAO,EAAE,GAAG,OAAO,CAAC;IAC5B,MAAM,EAAE,GAAG,EAAE,SAAS,EAAE,GAAG,OAAO,CAAC;IAEnC,IAAI,CAAC,GAAG,EAAE,CAAC;QACT,MAAM,IAAI,KAAK,CAAC,GAAG,qBAAS,CAAC,WAAW,4BAA4B,CAAC,CAAC;IACxE,CAAC;IAED,IAAI,IAAA,qBAAS,EAAC,OAAO,CAAC,EAAE,CAAC;QACvB,M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CAAE,EAAE,EAAE,CACtF,CAAC;IACJ,CAAC;IAED,OAAO,OAAO,CAAC;AACjB,CAAC;AAED;;;GAGG;AACI,KAAK,UAAU,wBAAwB,CAAC,EAC7C,GAAG,EACH,gBAAgB,GAIjB;IACC,MAAM,OAAO,GAAG,MAAM,mBAAmB,CAAC,EAAE,GAAG,EAAE,gBAAgB,EAAE,CAAC,CAAC;IAErE,IAAI,CAAC,IAAA,2BAAc,EAAC,OAAO,CAAC,EAAE,CAAC;QAC7B,MAAM,IAAI,KAAK,CAAC,GAAG,qBAAS,CAAC,WAAW,+BAA+B,CAAC,CAAC;IAC3E,CAAC;IAED,OAAO,OAAO,CAAC;AACjB,CAAC;AAED;;;GAGG;AACI,KAAK,UAAU,yBAAyB,CAAC,EAC9C,GAAG,EACH,gBAAgB,GAIjB;IACC,MAAM,OAAO,GAAG,MAAM,mBAAmB,CAAC,EAAE,GAAG,EAAE,gBAAgB,EAAE,CAAC,CAAC;IAErE,IAAI,CAAC,IAAA,wBAAW,EAAC,OAAO,CAAC,EAAE,CAAC;QAC1B,MAAM,IAAI,KAAK,CAAC,GAAG,qBAAS,CAAC,WAAW,gCAAgC,CAAC,CAAC;IAC5E,CAAC;IAED,OAAO,OAAO,CAAC;AACjB,CAAC"}
@@ -1,7 +1,7 @@
1
1
  /** The `jwt` module provides helper methods that allow you to decode and validate Vincent-specific JWTs.
2
2
  *
3
- * Vincent JWTs are composed using the `did-jwt` library, but have a custom `alg` of `ES256K`, and are signed using
4
- * PKP ethereum keys.
3
+ * Vincent JWTs are signed using `alg: ES256K`. The signed data is EIP191 compliant.
4
+ *
5
5
  *
6
6
  * Vincent JWTs are issued by the Vincent Dashboard when a user provides delegation permission for your app to their agent PKP.
7
7
  * They are passed to your web app using a redirectUri which you configure on your app.
@@ -12,10 +12,10 @@
12
12
  * @packageDocumentation
13
13
  *
14
14
  */
15
- export { create } from './core/create';
15
+ export { createPlatformUserJWT, createDelegateeJWT, createAppUserJWT } from './core/create';
16
16
  export { isExpired } from './core/isExpired';
17
- export { decode, verify } from './core/validate';
18
- export { isGeneralJWT, isAppSpecificJWT, assertIsVincentJWT } from './typeGuards';
19
- export type { JWTConfig, VincentJWT, VincentJWTAppSpecific } from './types';
20
- export { getAppInfo, getPKPInfo } from './accessors';
17
+ export { verifyVincentAppUserJWT, verifyVincentPlatformJWT, verifyVincentDelegateeJWT, } from './core/verify';
18
+ export { isAppUser, isPlatformUser, isAnyVincentJWT, isDelegatee } from './typeGuards';
19
+ export type { DecodedJWT, AnyVincentJWT, VincentJWTPlatformUser, VincentJWTAppUser, VincentJWTDelegatee, VincentJWTRole, CreatePlatformUserJWTParams, CreateAppUserJWTParams, CreateDelegateeJWTParams, PKPAuthenticationMethod, PayloadWithoutInternallySetKeys, InternallySetPayloadKeys, } from './types';
20
+ export { getAppInfo, getPKPInfo, getRole, getSubjectAddress, getIssuerAddress, getAudience, getPublicKey, getAuthentication, } from './accessors';
21
21
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/jwt/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AACH,OAAO,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AACvC,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC7C,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AACjD,OAAO,EAAE,YAAY,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AAElF,YAAY,EAAE,SAAS,EAAE,UAAU,EAAE,qBAAqB,EAAE,MAAM,SAAS,CAAC;AAC5E,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/jwt/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AACH,OAAO,EAAE,qBAAqB,EAAE,kBAAkB,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AAC5F,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC7C,OAAO,EACL,uBAAuB,EACvB,wBAAwB,EACxB,yBAAyB,GAC1B,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,SAAS,EAAE,cAAc,EAAE,eAAe,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAEvF,YAAY,EACV,UAAU,EACV,aAAa,EACb,sBAAsB,EACtB,iBAAiB,EACjB,mBAAmB,EACnB,cAAc,EACd,2BAA2B,EAC3B,sBAAsB,EACtB,wBAAwB,EACxB,uBAAuB,EACvB,+BAA+B,EAC/B,wBAAwB,GACzB,MAAM,SAAS,CAAC;AACjB,OAAO,EACL,UAAU,EACV,UAAU,EACV,OAAO,EACP,iBAAiB,EACjB,gBAAgB,EAChB,WAAW,EACX,YAAY,EACZ,iBAAiB,GAClB,MAAM,aAAa,CAAC"}
@@ -1,10 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getPKPInfo = exports.getAppInfo = exports.assertIsVincentJWT = exports.isAppSpecificJWT = exports.isGeneralJWT = exports.verify = exports.decode = exports.isExpired = exports.create = void 0;
3
+ exports.getAuthentication = exports.getPublicKey = exports.getAudience = exports.getIssuerAddress = exports.getSubjectAddress = exports.getRole = exports.getPKPInfo = exports.getAppInfo = exports.isDelegatee = exports.isAnyVincentJWT = exports.isPlatformUser = exports.isAppUser = exports.verifyVincentDelegateeJWT = exports.verifyVincentPlatformJWT = exports.verifyVincentAppUserJWT = exports.isExpired = exports.createAppUserJWT = exports.createDelegateeJWT = exports.createPlatformUserJWT = void 0;
4
4
  /** The `jwt` module provides helper methods that allow you to decode and validate Vincent-specific JWTs.
5
5
  *
6
- * Vincent JWTs are composed using the `did-jwt` library, but have a custom `alg` of `ES256K`, and are signed using
7
- * PKP ethereum keys.
6
+ * Vincent JWTs are signed using `alg: ES256K`. The signed data is EIP191 compliant.
7
+ *
8
8
  *
9
9
  * Vincent JWTs are issued by the Vincent Dashboard when a user provides delegation permission for your app to their agent PKP.
10
10
  * They are passed to your web app using a redirectUri which you configure on your app.
@@ -16,17 +16,27 @@ exports.getPKPInfo = exports.getAppInfo = exports.assertIsVincentJWT = exports.i
16
16
  *
17
17
  */
18
18
  var create_1 = require("./core/create");
19
- Object.defineProperty(exports, "create", { enumerable: true, get: function () { return create_1.create; } });
19
+ Object.defineProperty(exports, "createPlatformUserJWT", { enumerable: true, get: function () { return create_1.createPlatformUserJWT; } });
20
+ Object.defineProperty(exports, "createDelegateeJWT", { enumerable: true, get: function () { return create_1.createDelegateeJWT; } });
21
+ Object.defineProperty(exports, "createAppUserJWT", { enumerable: true, get: function () { return create_1.createAppUserJWT; } });
20
22
  var isExpired_1 = require("./core/isExpired");
21
23
  Object.defineProperty(exports, "isExpired", { enumerable: true, get: function () { return isExpired_1.isExpired; } });
22
- var validate_1 = require("./core/validate");
23
- Object.defineProperty(exports, "decode", { enumerable: true, get: function () { return validate_1.decode; } });
24
- Object.defineProperty(exports, "verify", { enumerable: true, get: function () { return validate_1.verify; } });
24
+ var verify_1 = require("./core/verify");
25
+ Object.defineProperty(exports, "verifyVincentAppUserJWT", { enumerable: true, get: function () { return verify_1.verifyVincentAppUserJWT; } });
26
+ Object.defineProperty(exports, "verifyVincentPlatformJWT", { enumerable: true, get: function () { return verify_1.verifyVincentPlatformJWT; } });
27
+ Object.defineProperty(exports, "verifyVincentDelegateeJWT", { enumerable: true, get: function () { return verify_1.verifyVincentDelegateeJWT; } });
25
28
  var typeGuards_1 = require("./typeGuards");
26
- Object.defineProperty(exports, "isGeneralJWT", { enumerable: true, get: function () { return typeGuards_1.isGeneralJWT; } });
27
- Object.defineProperty(exports, "isAppSpecificJWT", { enumerable: true, get: function () { return typeGuards_1.isAppSpecificJWT; } });
28
- Object.defineProperty(exports, "assertIsVincentJWT", { enumerable: true, get: function () { return typeGuards_1.assertIsVincentJWT; } });
29
+ Object.defineProperty(exports, "isAppUser", { enumerable: true, get: function () { return typeGuards_1.isAppUser; } });
30
+ Object.defineProperty(exports, "isPlatformUser", { enumerable: true, get: function () { return typeGuards_1.isPlatformUser; } });
31
+ Object.defineProperty(exports, "isAnyVincentJWT", { enumerable: true, get: function () { return typeGuards_1.isAnyVincentJWT; } });
32
+ Object.defineProperty(exports, "isDelegatee", { enumerable: true, get: function () { return typeGuards_1.isDelegatee; } });
29
33
  var accessors_1 = require("./accessors");
30
34
  Object.defineProperty(exports, "getAppInfo", { enumerable: true, get: function () { return accessors_1.getAppInfo; } });
31
35
  Object.defineProperty(exports, "getPKPInfo", { enumerable: true, get: function () { return accessors_1.getPKPInfo; } });
36
+ Object.defineProperty(exports, "getRole", { enumerable: true, get: function () { return accessors_1.getRole; } });
37
+ Object.defineProperty(exports, "getSubjectAddress", { enumerable: true, get: function () { return accessors_1.getSubjectAddress; } });
38
+ Object.defineProperty(exports, "getIssuerAddress", { enumerable: true, get: function () { return accessors_1.getIssuerAddress; } });
39
+ Object.defineProperty(exports, "getAudience", { enumerable: true, get: function () { return accessors_1.getAudience; } });
40
+ Object.defineProperty(exports, "getPublicKey", { enumerable: true, get: function () { return accessors_1.getPublicKey; } });
41
+ Object.defineProperty(exports, "getAuthentication", { enumerable: true, get: function () { return accessors_1.getAuthentication; } });
32
42
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/jwt/index.ts"],"names":[],"mappings":";;;AAAA;;;;;;;;;;;;;GAaG;AACH,wCAAuC;AAA9B,gGAAA,MAAM,OAAA;AACf,8CAA6C;AAApC,sGAAA,SAAS,OAAA;AAClB,4CAAiD;AAAxC,kGAAA,MAAM,OAAA;AAAE,kGAAA,MAAM,OAAA;AACvB,2CAAkF;AAAzE,0GAAA,YAAY,OAAA;AAAE,8GAAA,gBAAgB,OAAA;AAAE,gHAAA,kBAAkB,OAAA;AAG3D,yCAAqD;AAA5C,uGAAA,UAAU,OAAA;AAAE,uGAAA,UAAU,OAAA"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/jwt/index.ts"],"names":[],"mappings":";;;AAAA;;;;;;;;;;;;;GAaG;AACH,wCAA4F;AAAnF,+GAAA,qBAAqB,OAAA;AAAE,4GAAA,kBAAkB,OAAA;AAAE,0GAAA,gBAAgB,OAAA;AACpE,8CAA6C;AAApC,sGAAA,SAAS,OAAA;AAClB,wCAIuB;AAHrB,iHAAA,uBAAuB,OAAA;AACvB,kHAAA,wBAAwB,OAAA;AACxB,mHAAA,yBAAyB,OAAA;AAE3B,2CAAuF;AAA9E,uGAAA,SAAS,OAAA;AAAE,4GAAA,cAAc,OAAA;AAAE,6GAAA,eAAe,OAAA;AAAE,yGAAA,WAAW,OAAA;AAgBhE,yCASqB;AARnB,uGAAA,UAAU,OAAA;AACV,uGAAA,UAAU,OAAA;AACV,oGAAA,OAAO,OAAA;AACP,8GAAA,iBAAiB,OAAA;AACjB,6GAAA,gBAAgB,OAAA;AAChB,wGAAA,WAAW,OAAA;AACX,yGAAA,YAAY,OAAA;AACZ,8GAAA,iBAAiB,OAAA"}
@@ -1,14 +1,31 @@
1
- import type { JWTDecoded, VincentJWT, VincentJWTAppSpecific } from './types';
2
- /** Use this typeguard function to identify if the JWT is appId specific and make subsequent type-safe
3
- * references into the payload of the JWT
4
- */
5
- export declare function isAppSpecificJWT(decodedJWT: VincentJWT): decodedJWT is VincentJWTAppSpecific;
6
- /** Use this typeguard function to identify if the JWT is a general authentication JWT that has no specific app target */
7
- export declare function isGeneralJWT(decodedJWT: VincentJWT): decodedJWT is VincentJWT;
8
- /** This assert function is used internally to throw if decoding a JWT that is expected to be a VincentJWT gives a malformed response.
9
- * You probably don't need it -- use `decode()` and `verify()`
1
+ import type { VincentJWTPlatformUser, VincentJWTAppUser, VincentJWTDelegatee, AnyVincentJWT, DecodedJWT } from './types';
2
+ /**
3
+ * Check if a decoded JWT is an app-specific JWT (role === 'app-user')
4
+ *
5
+ * @category API > Type Guards
6
+ * */
7
+ export declare function isAppUser(decodedJWT: DecodedJWT): decodedJWT is VincentJWTAppUser;
8
+ /** Check if a decoded JWT is a general platform-user JWT
9
+ *
10
+ * @category API > Type Guards
11
+ * */
12
+ export declare function isPlatformUser(decodedJWT: DecodedJWT): decodedJWT is VincentJWTPlatformUser;
13
+ /** Check if a decoded JWT is a delegatee token (role === 'app-delegatee')
14
+ *
15
+ * @category API > Type Guards
16
+ * */
17
+ export declare function isDelegatee(decodedJWT: DecodedJWT): decodedJWT is VincentJWTDelegatee;
18
+ /** Check if the decoded JWT matches any known Vincent JWT variant
19
+ *
20
+ * @category API > Type Guards
21
+ * */
22
+ export declare function isAnyVincentJWT(decodedJWT: DecodedJWT): decodedJWT is AnyVincentJWT;
23
+ /**
24
+ * Assert that the JWT contains expected fields for a PKP-authenticated JWT.
25
+ * Used to validate `VincentJWT` and `VincentJWTAppSpecific` before accessing `.payload.pkp` or `.authentication`.
10
26
  *
11
- * @hidden
27
+ * @internal
12
28
  */
13
- export declare function assertIsVincentJWT(decodedJWT: JWTDecoded): asserts decodedJWT is VincentJWT | VincentJWTAppSpecific;
29
+ export declare function assertIsPKPSignedVincentJWT(decodedJWT: DecodedJWT): asserts decodedJWT is VincentJWTPlatformUser | VincentJWTAppUser;
30
+ export declare function assertJWTAPIVersion(apiVersion: number): void;
14
31
  //# sourceMappingURL=typeGuards.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"typeGuards.d.ts","sourceRoot":"","sources":["../../../src/jwt/typeGuards.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,UAAU,EAAE,UAAU,EAAE,qBAAqB,EAAE,MAAM,SAAS,CAAC;AAI7E;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,UAAU,EAAE,UAAU,GAAG,UAAU,IAAI,qBAAqB,CAE5F;AAED,yHAAyH;AACzH,wBAAgB,YAAY,CAAC,UAAU,EAAE,UAAU,GAAG,UAAU,IAAI,UAAU,CAE7E;AAED;;;;GAIG;AACH,wBAAgB,kBAAkB,CAChC,UAAU,EAAE,UAAU,GACrB,OAAO,CAAC,UAAU,IAAI,UAAU,GAAG,qBAAqB,CAU1D"}
1
+ {"version":3,"file":"typeGuards.d.ts","sourceRoot":"","sources":["../../../src/jwt/typeGuards.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,sBAAsB,EACtB,iBAAiB,EACjB,mBAAmB,EACnB,aAAa,EACb,UAAU,EACX,MAAM,SAAS,CAAC;AAKjB;;;;KAIK;AACL,wBAAgB,SAAS,CAAC,UAAU,EAAE,UAAU,GAAG,UAAU,IAAI,iBAAiB,CAEjF;AAED;;;KAGK;AACL,wBAAgB,cAAc,CAAC,UAAU,EAAE,UAAU,GAAG,UAAU,IAAI,sBAAsB,CAE3F;AAED;;;KAGK;AACL,wBAAgB,WAAW,CAAC,UAAU,EAAE,UAAU,GAAG,UAAU,IAAI,mBAAmB,CAErF;AAED;;;KAGK;AACL,wBAAgB,eAAe,CAAC,UAAU,EAAE,UAAU,GAAG,UAAU,IAAI,aAAa,CAEnF;AAED;;;;;GAKG;AACH,wBAAgB,2BAA2B,CACzC,UAAU,EAAE,UAAU,GACrB,OAAO,CAAC,UAAU,IAAI,sBAAsB,GAAG,iBAAiB,CAUlE;AAED,wBAAgB,mBAAmB,CAAC,UAAU,EAAE,MAAM,QAMrD"}
@@ -1,32 +1,63 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.isAppSpecificJWT = isAppSpecificJWT;
4
- exports.isGeneralJWT = isGeneralJWT;
5
- exports.assertIsVincentJWT = assertIsVincentJWT;
6
- const did_jwt_1 = require("did-jwt");
3
+ exports.isAppUser = isAppUser;
4
+ exports.isPlatformUser = isPlatformUser;
5
+ exports.isDelegatee = isDelegatee;
6
+ exports.isAnyVincentJWT = isAnyVincentJWT;
7
+ exports.assertIsPKPSignedVincentJWT = assertIsPKPSignedVincentJWT;
8
+ exports.assertJWTAPIVersion = assertJWTAPIVersion;
9
+ const constants_1 = require("./constants");
7
10
  const index_1 = require("./core/utils/index");
8
- /** Use this typeguard function to identify if the JWT is appId specific and make subsequent type-safe
9
- * references into the payload of the JWT
10
- */
11
- function isAppSpecificJWT(decodedJWT) {
12
- return decodedJWT.payload.app && decodedJWT.payload.app.id;
11
+ /**
12
+ * Check if a decoded JWT is an app-specific JWT (role === 'app-user')
13
+ *
14
+ * @category API > Type Guards
15
+ * */
16
+ function isAppUser(decodedJWT) {
17
+ var _a;
18
+ return ((_a = decodedJWT.payload) === null || _a === void 0 ? void 0 : _a.role) === 'app-user';
13
19
  }
14
- /** Use this typeguard function to identify if the JWT is a general authentication JWT that has no specific app target */
15
- function isGeneralJWT(decodedJWT) {
16
- return !isAppSpecificJWT(decodedJWT);
20
+ /** Check if a decoded JWT is a general platform-user JWT
21
+ *
22
+ * @category API > Type Guards
23
+ * */
24
+ function isPlatformUser(decodedJWT) {
25
+ var _a;
26
+ return ((_a = decodedJWT.payload) === null || _a === void 0 ? void 0 : _a.role) === 'platform-user';
27
+ }
28
+ /** Check if a decoded JWT is a delegatee token (role === 'app-delegatee')
29
+ *
30
+ * @category API > Type Guards
31
+ * */
32
+ function isDelegatee(decodedJWT) {
33
+ var _a;
34
+ return ((_a = decodedJWT.payload) === null || _a === void 0 ? void 0 : _a.role) === 'app-delegatee';
17
35
  }
18
- /** This assert function is used internally to throw if decoding a JWT that is expected to be a VincentJWT gives a malformed response.
19
- * You probably don't need it -- use `decode()` and `verify()`
36
+ /** Check if the decoded JWT matches any known Vincent JWT variant
20
37
  *
21
- * @hidden
38
+ * @category API > Type Guards
39
+ * */
40
+ function isAnyVincentJWT(decodedJWT) {
41
+ return isPlatformUser(decodedJWT) || isAppUser(decodedJWT) || isDelegatee(decodedJWT);
42
+ }
43
+ /**
44
+ * Assert that the JWT contains expected fields for a PKP-authenticated JWT.
45
+ * Used to validate `VincentJWT` and `VincentJWTAppSpecific` before accessing `.payload.pkp` or `.authentication`.
46
+ *
47
+ * @internal
22
48
  */
23
- function assertIsVincentJWT(decodedJWT) {
24
- const { authentication, pkp } = decodedJWT.payload;
49
+ function assertIsPKPSignedVincentJWT(decodedJWT) {
50
+ const { authentication, pkpInfo } = decodedJWT.payload;
25
51
  if (!(0, index_1.isDefinedObject)(authentication)) {
26
- throw new Error(`${did_jwt_1.JWT_ERROR.INVALID_JWT}: Missing "authentication" field in JWT payload.`);
52
+ throw new Error(`${constants_1.JWT_ERROR.INVALID_JWT}: Missing "authentication" field in JWT payload.`);
27
53
  }
28
- if (!(0, index_1.isDefinedObject)(pkp)) {
29
- throw new Error(`${did_jwt_1.JWT_ERROR.INVALID_JWT}: Missing "pkp" field in JWT payload.`);
54
+ if (!(0, index_1.isDefinedObject)(pkpInfo)) {
55
+ throw new Error(`${constants_1.JWT_ERROR.INVALID_JWT}: Missing "pkpInfo" field in JWT payload.`);
56
+ }
57
+ }
58
+ function assertJWTAPIVersion(apiVersion) {
59
+ if (constants_1.VINCENT_JWT_API_VERSION !== apiVersion) {
60
+ throw new Error(`Invalid JWT API version. Expected ${constants_1.VINCENT_JWT_API_VERSION}, got ${apiVersion}`);
30
61
  }
31
62
  }
32
63
  //# sourceMappingURL=typeGuards.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"typeGuards.js","sourceRoot":"","sources":["../../../src/jwt/typeGuards.ts"],"names":[],"mappings":";;AASA,4CAEC;AAGD,oCAEC;AAOD,gDAYC;AAnCD,qCAAoC;AAIpC,8CAAqD;AAErD;;GAEG;AACH,SAAgB,gBAAgB,CAAC,UAAsB;IACrD,OAAO,UAAU,CAAC,OAAO,CAAC,GAAG,IAAI,UAAU,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC;AAC7D,CAAC;AAED,yHAAyH;AACzH,SAAgB,YAAY,CAAC,UAAsB;IACjD,OAAO,CAAC,gBAAgB,CAAC,UAAU,CAAC,CAAC;AACvC,CAAC;AAED;;;;GAIG;AACH,SAAgB,kBAAkB,CAChC,UAA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