@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,143 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.verify = verify;
4
- exports.decode = decode;
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("ethers/lib/utils");
11
- const typeGuards_1 = require("../typeGuards");
12
- const isExpired_1 = require("./isExpired");
13
- const utils_2 = require("./utils");
14
- /**
15
- * Decodes and verifies an {@link VincentJWT} token in string form
16
- *
17
- * This function returns the decoded {@link VincentJWT} object only if:
18
- * 1. The JWT signature is valid
19
- * 2. The JWT is not expired
20
- * 3. All time claims (nbf, iat) are valid
21
- * 4. The JWT has an audience claim that includes the expected audience
22
- *
23
- * @param params
24
- * @param jwt - The JWT string to verify
25
- * @param expectedAudience - String that should be in the audience claim(s)
26
- * @param requiredAppId - The appId that should be in the payload of the JWT. If app is not defined, or app.id is different, this method will throw.
27
- *
28
- * @returns {VincentJWT} The decoded VincentJWT object if it was verified successfully
29
- *
30
- * @category API
31
- * @inline
32
- * @expand
33
- * @function
34
- *
35
- * @example
36
- * ```typescript
37
- * import { verify } from '@lit-protocol/vincent-app-sdk/jwt';
38
- *
39
- * try {
40
- * const decodedAndVerifiedVincentJWT = verify({ jwt, expectedAudience: 'https://myapp.com', requiredAppId: 555 });
41
- * } catch(e) {
42
- * // Handle invalid/expired JWT casew
43
- * }
44
- * ```
45
- */
46
- function verify({ jwt, expectedAudience, requiredAppId, }) {
47
- if (!expectedAudience) {
48
- throw new Error(`You must provide an expectedAudience`);
49
- }
50
- const decoded = decode({ jwt, requiredAppId });
51
- const { aud, exp, pkp } = decoded.payload;
52
- if (!exp) {
53
- throw new Error(`${did_jwt_1.JWT_ERROR.INVALID_JWT}: JWT does not contain an expiration claim (exp)`);
54
- }
55
- const expired = (0, isExpired_1.isExpired)(decoded);
56
- if (expired) {
57
- throw new Error(`${did_jwt_1.JWT_ERROR.INVALID_JWT}: JWT expired at ${exp}`);
58
- }
59
- (0, utils_2.validateJWTTime)(decoded.payload, Math.floor(Date.now() / 1000));
60
- // Always validate audience - reject if no audience claim or expected audience isn't included
61
- if (!aud) {
62
- throw new Error(`${did_jwt_1.JWT_ERROR.INVALID_JWT}: JWT does not contain an audience claim (aud)`);
63
- }
64
- const audiences = Array.isArray(aud) ? aud : [aud];
65
- if (!audiences.includes(expectedAudience)) {
66
- throw new Error(`${did_jwt_1.JWT_ERROR.INVALID_AUDIENCE}: Expected audience ${expectedAudience} not found in aud claim`);
67
- }
68
- try {
69
- const { signedData, signature } = (0, utils_2.splitJWT)(jwt);
70
- // Process signature from base64url to binary
71
- const signatureBytes = (0, utils_2.processJWTSignature)(signature);
72
- // Extract r and s values from the signature
73
- const r = signatureBytes.slice(0, 32);
74
- const s = signatureBytes.slice(32, 64);
75
- const publicKeyBytes = (0, utils_1.arrayify)(pkp.publicKey);
76
- // PKPEthersWallet.signMessage() adds Ethereum prefix, so we need to add it here too
77
- const ethPrefixedMessage = '\x19Ethereum Signed Message:\n' + signedData.length + signedData;
78
- const messageHash = ethers_1.ethers.utils.keccak256((0, utils_1.toUtf8Bytes)(ethPrefixedMessage));
79
- const messageHashBytes = (0, utils_1.arrayify)(messageHash);
80
- const signatureForSecp = new Uint8Array([...r, ...s]);
81
- // Verify the signature against the public key
82
- const isVerified = secp256k1.verify(signatureForSecp, messageHashBytes, publicKeyBytes);
83
- if (!isVerified) {
84
- throw new Error(`Signature verify() did not pass for ${signature}`);
85
- }
86
- return decoded;
87
- }
88
- catch (error) {
89
- throw new Error(`${did_jwt_1.JWT_ERROR.INVALID_SIGNATURE}: Invalid signature: ${error.message}`);
90
- }
91
- }
92
- /** Decodes a Vincent JWT in string form and returns an {@link VincentJWT} decoded object for your use
93
- *
94
- * @param jwt - The jwt in string form. It will be decoded and checked to be sure it is not malformed.
95
- * @param requiredAppId - The appId that should be in the payload of the JWT. If app is not defined, or app.id is different, this method will throw.
96
- *
97
- * <div class="box info-box">
98
- * <p class="box-title info-box-title">
99
- * <span class="box-icon info-icon">Info</span> Note
100
- * </p>
101
- * This method only <i><b>decodes</b></i> the JWT_ -- you still need to {@link verify} the JWT to be sure it is valid!
102
- * If the JWT is expired, you need to use a {@link webAuthClient.WebAuthClient | WebAuthClient} to get a new JWT.
103
- *
104
- * See {@link webAuthClient.getWebAuthClient | getWebAuthClient}
105
- *
106
- * </div>
107
- * @inline
108
- * @expand
109
- * @function
110
- * @category API
111
- *
112
- * @example
113
- * ```typescript
114
- * import { decode, isExpired } from '@lit-protocol/vincent-app-sdk/jwt';
115
- *
116
- * const decodedVincentJWT = decode({ jwt, requiredAppId: 555 });
117
- * const isJWTExpired = isExpired(decodedVincentJWT);
118
- *
119
- * if(!isJWTExpired) {
120
- * // User is logged in
121
- * // You still need to verify the JWT!
122
- * } else {
123
- * // User needs to get a new JWT
124
- * webAuthClient.redirectToConnectPage({redirectUri: window.location.href });
125
- * }
126
- *
127
- * ```
128
- * */
129
- function decode({ jwt, requiredAppId, }) {
130
- const decodedJwt = didJWT.decodeJWT(jwt);
131
- (0, typeGuards_1.assertIsVincentJWT)(decodedJwt);
132
- if (requiredAppId) {
133
- if (!(0, typeGuards_1.isAppSpecificJWT)(decodedJwt)) {
134
- throw new Error(`${did_jwt_1.JWT_ERROR.INVALID_JWT}: JWT is not app specific; cannot verify requiredAppId`);
135
- }
136
- const { app } = decodedJwt.payload;
137
- if (requiredAppId !== app.id) {
138
- throw new Error(`${did_jwt_1.JWT_ERROR.INVALID_JWT}: appId in JWT does not match requiredAppId. Expected ${requiredAppId}, got ${app.id} `);
139
- }
140
- }
141
- return decodedJwt;
142
- }
143
- //# sourceMappingURL=validate.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"validate.js","sourceRoot":"","sources":["../../../../src/jwt/core/validate.ts"],"names":[],"mappings":";;AAyEA,wBAwEC;AA+DD,wBA2BC;;AA3OD,oEAA8C;AAC9C,wDAAkC;AAClC,qCAAoC;AACpC,mCAAgC;AAChC,4CAAyD;AAIzD,8CAAqE;AACrE,2CAAwC;AACxC,mCAAyE;AA+BzE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,SAAgB,MAAM,CAAC,EACrB,GAAG,EACH,gBAAgB,EAChB,aAAa,GAKd;IACC,IAAI,CAAC,gBAAgB,EAAE,CAAC;QACtB,MAAM,IAAI,KAAK,CAAC,sCAAsC,CAAC,CAAC;IAC1D,CAAC;IAED,MAAM,OAAO,GAAG,MAAM,CAAC,EAAE,GAAG,EAAE,aAAa,EAAE,CAAC,CAAC;IAC/C,MAAM,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,OAAO,CAAC,OAAO,CAAC;IAE1C,IAAI,CAAC,GAAG,EAAE,CAAC;QAC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