lib0 0.2.82 → 0.2.83

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/crypto/jwt.d.ts CHANGED
@@ -3,4 +3,8 @@ export function verifyJwt(publicKey: CryptoKey, jwt: string): Promise<{
3
3
  header: any;
4
4
  payload: any;
5
5
  }>;
6
+ export function unsafeDecode(jwt: string): {
7
+ header: any;
8
+ payload: any;
9
+ };
6
10
  //# sourceMappingURL=jwt.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"jwt.d.ts","sourceRoot":"","sources":["jwt.js"],"names":[],"mappings":"AAoBO,sCAHI,SAAS,WACT,MAAM,uBAgBhB;AAMM,qCAHI,SAAS,OACT,MAAM;;;GAahB"}
1
+ {"version":3,"file":"jwt.d.ts","sourceRoot":"","sources":["jwt.js"],"names":[],"mappings":"AAoBO,sCAHI,SAAS,WACT,MAAM,uBAgBhB;AAMM,qCAHI,SAAS,OACT,MAAM;;;GAahB;AAOM,kCAFI,MAAM;;;EAQhB"}
package/crypto/jwt.js CHANGED
@@ -50,3 +50,16 @@ export const verifyJwt = async (publicKey, jwt) => {
50
50
  payload: _parse(payloadBase64)
51
51
  }
52
52
  }
53
+
54
+ /**
55
+ * Decode a jwt without verifying it. Probably a bad idea to use this. Only use if you know the jwt was already verified!
56
+ *
57
+ * @param {string} jwt
58
+ */
59
+ export const unsafeDecode = jwt => {
60
+ const [headerBase64, payloadBase64] = jwt.split('.')
61
+ return {
62
+ header: _parse(headerBase64),
63
+ payload: _parse(payloadBase64)
64
+ }
65
+ }
@@ -1 +1 @@
1
- {"version":3,"file":"crypto.test.d.ts","sourceRoot":"","sources":["crypto.test.js"],"names":[],"mappings":"AAYO,6BAFI,EAAE,QAAQ,iBAgBpB;AAKM,mCAFI,EAAE,QAAQ,iBAoCpB;AAKM,0CAFI,EAAE,QAAQ,iBA8BpB;AAKM,qCAFI,EAAE,QAAQ,iBAgDpB;AAKM,8CAFI,EAAE,QAAQ,iBAwCpB;AAKM,iDAFI,EAAE,QAAQ,iBA0EpB;AAKM,gCAFI,EAAE,QAAQ,iBAapB;mBAzRkB,cAAc"}
1
+ {"version":3,"file":"crypto.test.d.ts","sourceRoot":"","sources":["crypto.test.js"],"names":[],"mappings":"AAYO,6BAFI,EAAE,QAAQ,iBAkBpB;AAKM,mCAFI,EAAE,QAAQ,iBAoCpB;AAKM,0CAFI,EAAE,QAAQ,iBA8BpB;AAKM,qCAFI,EAAE,QAAQ,iBAgDpB;AAKM,8CAFI,EAAE,QAAQ,iBAwCpB;AAKM,iDAFI,EAAE,QAAQ,iBA0EpB;AAKM,gCAFI,EAAE,QAAQ,iBAapB;mBA3RkB,cAAc"}
@@ -3,4 +3,8 @@ export function verifyJwt(publicKey: CryptoKey, jwt: string): Promise<{
3
3
  header: any;
4
4
  payload: any;
5
5
  }>;
6
+ export function unsafeDecode(jwt: string): {
7
+ header: any;
8
+ payload: any;
9
+ };
6
10
  //# sourceMappingURL=jwt.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"jwt.d.ts","sourceRoot":"","sources":["../../crypto/jwt.js"],"names":[],"mappings":"AAoBO,sCAHI,SAAS,WACT,MAAM,uBAgBhB;AAMM,qCAHI,SAAS,OACT,MAAM;;;GAahB"}
1
+ {"version":3,"file":"jwt.d.ts","sourceRoot":"","sources":["../../crypto/jwt.js"],"names":[],"mappings":"AAoBO,sCAHI,SAAS,WACT,MAAM,uBAgBhB;AAMM,qCAHI,SAAS,OACT,MAAM;;;GAahB;AAOM,kCAFI,MAAM;;;EAQhB"}
@@ -1 +1 @@
1
- {"version":3,"file":"crypto.test.d.ts","sourceRoot":"","sources":["../crypto.test.js"],"names":[],"mappings":"AAYO,6BAFI,EAAE,QAAQ,iBAgBpB;AAKM,mCAFI,EAAE,QAAQ,iBAoCpB;AAKM,0CAFI,EAAE,QAAQ,iBA8BpB;AAKM,qCAFI,EAAE,QAAQ,iBAgDpB;AAKM,8CAFI,EAAE,QAAQ,iBAwCpB;AAKM,iDAFI,EAAE,QAAQ,iBA0EpB;AAKM,gCAFI,EAAE,QAAQ,iBAapB;mBAzRkB,cAAc"}
1
+ {"version":3,"file":"crypto.test.d.ts","sourceRoot":"","sources":["../crypto.test.js"],"names":[],"mappings":"AAYO,6BAFI,EAAE,QAAQ,iBAkBpB;AAKM,mCAFI,EAAE,QAAQ,iBAoCpB;AAKM,0CAFI,EAAE,QAAQ,iBA8BpB;AAKM,qCAFI,EAAE,QAAQ,iBAgDpB;AAKM,8CAFI,EAAE,QAAQ,iBAwCpB;AAKM,iDAFI,EAAE,QAAQ,iBA0EpB;AAKM,gCAFI,EAAE,QAAQ,iBAapB;mBA3RkB,cAAc"}
package/dist/jwt.cjs CHANGED
@@ -68,6 +68,20 @@ const verifyJwt = async (publicKey, jwt) => {
68
68
  }
69
69
  };
70
70
 
71
+ /**
72
+ * Decode a jwt without verifying it. Probably a bad idea to use this. Only use if you know the jwt was already verified!
73
+ *
74
+ * @param {string} jwt
75
+ */
76
+ const unsafeDecode = jwt => {
77
+ const [headerBase64, payloadBase64] = jwt.split('.');
78
+ return {
79
+ header: _parse(headerBase64),
80
+ payload: _parse(payloadBase64)
81
+ }
82
+ };
83
+
71
84
  exports.encodeJwt = encodeJwt;
85
+ exports.unsafeDecode = unsafeDecode;
72
86
  exports.verifyJwt = verifyJwt;
73
87
  //# sourceMappingURL=jwt.cjs.map
package/dist/jwt.cjs.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"jwt.cjs","sources":["../crypto/jwt.js"],"sourcesContent":["import * as error from '../error.js'\nimport * as buffer from '../buffer.js'\nimport * as string from '../string.js'\nimport * as json from '../json.js'\nimport * as ecdsa from '../crypto/ecdsa.js'\n\n/**\n * @param {Object} data\n */\nconst _stringify = data => buffer.toBase64UrlEncoded(string.encodeUtf8(json.stringify(data)))\n\n/**\n * @param {string} base64url\n */\nconst _parse = base64url => json.parse(string.decodeUtf8(buffer.fromBase64UrlEncoded(base64url)))\n\n/**\n * @param {CryptoKey} privateKey\n * @param {Object} payload\n */\nexport const encodeJwt = (privateKey, payload) => {\n const { name: algName, namedCurve: algCurve } = /** @type {any} */ (privateKey.algorithm)\n /* c8 ignore next 3 */\n if (algName !== 'ECDSA' || algCurve !== 'P-384') {\n error.unexpectedCase()\n }\n const header = {\n alg: 'ES384',\n typ: 'JWT'\n }\n const jwt = _stringify(header) + '.' + _stringify(payload)\n return ecdsa.sign(privateKey, string.encodeUtf8(jwt)).then(signature =>\n jwt + '.' + buffer.toBase64UrlEncoded(signature)\n )\n}\n\n/**\n * @param {CryptoKey} publicKey\n * @param {string} jwt\n */\nexport const verifyJwt = async (publicKey, jwt) => {\n const [headerBase64, payloadBase64, signatureBase64] = jwt.split('.')\n const verified = await ecdsa.verify(publicKey, buffer.fromBase64UrlEncoded(signatureBase64), string.encodeUtf8(headerBase64 + '.' + payloadBase64))\n /* c8 ignore next 3 */\n if (!verified) {\n throw new Error('Invalid JWT')\n }\n return {\n header: _parse(headerBase64),\n payload: _parse(payloadBase64)\n }\n}\n"],"names":["buffer.toBase64UrlEncoded","string.encodeUtf8","json.stringify","json.parse","string.decodeUtf8","buffer.fromBase64UrlEncoded","error.unexpectedCase","ecdsa.sign","ecdsa.verify"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAMA;AACA;AACA;AACA,MAAM,UAAU,GAAG,IAAI,IAAIA,2BAAyB,CAACC,iBAAiB,CAACC,cAAc,CAAC,IAAI,CAAC,CAAC,EAAC;AAC7F;AACA;AACA;AACA;AACA,MAAM,MAAM,GAAG,SAAS,IAAIC,UAAU,CAACC,iBAAiB,CAACC,6BAA2B,CAAC,SAAS,CAAC,CAAC,EAAC;AACjG;AACA;AACA;AACA;AACA;AACY,MAAC,SAAS,GAAG,CAAC,UAAU,EAAE,OAAO,KAAK;AAClD,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,uBAAuB,UAAU,CAAC,SAAS,EAAC;AAC3F;AACA,EAAE,IAAI,OAAO,KAAK,OAAO,IAAI,QAAQ,KAAK,OAAO,EAAE;AACnD,IAAIC,oBAAoB,GAAE;AAC1B,GAAG;AACH,EAAE,MAAM,MAAM,GAAG;AACjB,IAAI,GAAG,EAAE,OAAO;AAChB,IAAI,GAAG,EAAE,KAAK;AACd,IAAG;AACH,EAAE,MAAM,GAAG,GAAG,UAAU,CAAC,MAAM,CAAC,GAAG,GAAG,GAAG,UAAU,CAAC,OAAO,EAAC;AAC5D,EAAE,OAAOC,UAAU,CAAC,UAAU,EAAEN,iBAAiB,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS;AACtE,IAAI,GAAG,GAAG,GAAG,GAAGD,2BAAyB,CAAC,SAAS,CAAC;AACpD,GAAG;AACH,EAAC;AACD;AACA;AACA;AACA;AACA;AACY,MAAC,SAAS,GAAG,OAAO,SAAS,EAAE,GAAG,KAAK;AACnD,EAAE,MAAM,CAAC,YAAY,EAAE,aAAa,EAAE,eAAe,CAAC,GAAG,GAAG,CAAC,KAAK,CAAC,GAAG,EAAC;AACvE,EAAE,MAAM,QAAQ,GAAG,MAAMQ,YAAY,CAAC,SAAS,EAAEH,6BAA2B,CAAC,eAAe,CAAC,EAAEJ,iBAAiB,CAAC,YAAY,GAAG,GAAG,GAAG,aAAa,CAAC,EAAC;AACrJ;AACA,EAAE,IAAI,CAAC,QAAQ,EAAE;AACjB,IAAI,MAAM,IAAI,KAAK,CAAC,aAAa,CAAC;AAClC,GAAG;AACH,EAAE,OAAO;AACT,IAAI,MAAM,EAAE,MAAM,CAAC,YAAY,CAAC;AAChC,IAAI,OAAO,EAAE,MAAM,CAAC,aAAa,CAAC;AAClC,GAAG;AACH;;;;;"}
1
+ {"version":3,"file":"jwt.cjs","sources":["../crypto/jwt.js"],"sourcesContent":["import * as error from '../error.js'\nimport * as buffer from '../buffer.js'\nimport * as string from '../string.js'\nimport * as json from '../json.js'\nimport * as ecdsa from '../crypto/ecdsa.js'\n\n/**\n * @param {Object} data\n */\nconst _stringify = data => buffer.toBase64UrlEncoded(string.encodeUtf8(json.stringify(data)))\n\n/**\n * @param {string} base64url\n */\nconst _parse = base64url => json.parse(string.decodeUtf8(buffer.fromBase64UrlEncoded(base64url)))\n\n/**\n * @param {CryptoKey} privateKey\n * @param {Object} payload\n */\nexport const encodeJwt = (privateKey, payload) => {\n const { name: algName, namedCurve: algCurve } = /** @type {any} */ (privateKey.algorithm)\n /* c8 ignore next 3 */\n if (algName !== 'ECDSA' || algCurve !== 'P-384') {\n error.unexpectedCase()\n }\n const header = {\n alg: 'ES384',\n typ: 'JWT'\n }\n const jwt = _stringify(header) + '.' + _stringify(payload)\n return ecdsa.sign(privateKey, string.encodeUtf8(jwt)).then(signature =>\n jwt + '.' + buffer.toBase64UrlEncoded(signature)\n )\n}\n\n/**\n * @param {CryptoKey} publicKey\n * @param {string} jwt\n */\nexport const verifyJwt = async (publicKey, jwt) => {\n const [headerBase64, payloadBase64, signatureBase64] = jwt.split('.')\n const verified = await ecdsa.verify(publicKey, buffer.fromBase64UrlEncoded(signatureBase64), string.encodeUtf8(headerBase64 + '.' + payloadBase64))\n /* c8 ignore next 3 */\n if (!verified) {\n throw new Error('Invalid JWT')\n }\n return {\n header: _parse(headerBase64),\n payload: _parse(payloadBase64)\n }\n}\n\n/**\n * Decode a jwt without verifying it. Probably a bad idea to use this. Only use if you know the jwt was already verified!\n *\n * @param {string} jwt\n */\nexport const unsafeDecode = jwt => {\n const [headerBase64, payloadBase64] = jwt.split('.')\n return {\n header: _parse(headerBase64),\n payload: _parse(payloadBase64)\n }\n}\n"],"names":["buffer.toBase64UrlEncoded","string.encodeUtf8","json.stringify","json.parse","string.decodeUtf8","buffer.fromBase64UrlEncoded","error.unexpectedCase","ecdsa.sign","ecdsa.verify"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAMA;AACA;AACA;AACA,MAAM,UAAU,GAAG,IAAI,IAAIA,2BAAyB,CAACC,iBAAiB,CAACC,cAAc,CAAC,IAA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K,CAAC,aAAa,CAAC;AAClC,GAAG;AACH,EAAE,OAAO;AACT,IAAI,MAAM,EAAE,MAAM,CAAC,YAAY,CAAC;AAChC,IAAI,OAAO,EAAE,MAAM,CAAC,aAAa,CAAC;AAClC,GAAG;AACH,EAAC;AACD;AACA;AACA;AACA;AACA;AACA;AACY,MAAC,YAAY,GAAG,GAAG,IAAI;AACnC,EAAE,MAAM,CAAC,YAAY,EAAE,aAAa,CAAC,GAAG,GAAG,CAAC,KAAK,CAAC,GAAG,EAAC;AACtD,EAAE,OAAO;AACT,IAAI,MAAM,EAAE,MAAM,CAAC,YAAY,CAAC;AAChC,IAAI,OAAO,EAAE,MAAM,CAAC,aAAa,CAAC;AAClC,GAAG;AACH;;;;;;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lib0",
3
- "version": "0.2.82",
3
+ "version": "0.2.83",
4
4
  "description": "",
5
5
  "sideEffects": false,
6
6
  "type": "module",