Comparing version 4.4.0 to 4.4.1
@@ -0,1 +1,9 @@ | ||
## [4.4.1](https://github.com/decentralized-identity/did-jwt/compare/4.4.0...4.4.1) (2020-08-18) | ||
### Bug Fixes | ||
* export interfaces used for JWT verification ([#123](https://github.com/decentralized-identity/did-jwt/issues/123)) ([76229c5](https://github.com/decentralized-identity/did-jwt/commit/76229c5e7d567db95d842e44649c3f58fa7f1b1a)) | ||
* export more JWT interfaces ([#121](https://github.com/decentralized-identity/did-jwt/issues/121)) ([2fd049c](https://github.com/decentralized-identity/did-jwt/commit/2fd049ca38d39c33941bad7ae4383776618bbdbd)) | ||
# [4.4.0](https://github.com/decentralized-identity/did-jwt/compare/4.3.4...4.4.0) (2020-06-18) | ||
@@ -2,0 +10,0 @@ |
import SimpleSigner from './SimpleSigner'; | ||
import EllipticSigner from './EllipticSigner'; | ||
import NaclSigner from './NaclSigner'; | ||
import { verifyJWT, createJWT, decodeJWT, verifyJWS, createJWS, Signer } from './JWT'; | ||
import { verifyJWT, createJWT, decodeJWT, verifyJWS, createJWS, Signer, JWTHeader, JWTPayload, JWTVerified, Resolvable } from './JWT'; | ||
import { toEthereumAddress } from './Digest'; | ||
export { SimpleSigner, EllipticSigner, NaclSigner, verifyJWT, createJWT, decodeJWT, verifyJWS, createJWS, toEthereumAddress, Signer }; | ||
export { SimpleSigner, EllipticSigner, NaclSigner, verifyJWT, createJWT, decodeJWT, verifyJWS, createJWS, toEthereumAddress, Signer, JWTHeader, JWTPayload, JWTVerified, Resolvable }; | ||
//# sourceMappingURL=index.d.ts.map |
@@ -1,2 +0,2 @@ | ||
!function(r,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("elliptic"),require("js-sha256"),require("js-sha3"),require("buffer"),require("uport-base64url"),require("tweetnacl"),require("@stablelib/utf8")):"function"==typeof define&&define.amd?define(["exports","elliptic","js-sha256","js-sha3","buffer","uport-base64url","tweetnacl","@stablelib/utf8"],e):e((r=r||self).didJwt={},r.elliptic,r.jsSha256,r.jsSha3,r.buffer,r.base64url,r.tweetnacl,r.utf8)}(this,function(r,e,t,n,o,i,a,u){function c(r){return o.Buffer.from(t.sha256.arrayBuffer(r))}function f(r){return"0x"+(e=o.Buffer.from(r.slice(2),"hex"),o.Buffer.from(n.keccak_256.arrayBuffer(e))).slice(-20).toString("hex");var e}i=i&&Object.prototype.hasOwnProperty.call(i,"default")?i.default:i,a=a&&Object.prototype.hasOwnProperty.call(a,"default")?a.default:a;var s=new e.ec("secp256k1");function l(r,e){return void 0===e&&(e=64),r.length===e?r:"0".repeat(e-r.length)+r}function d(r){r.startsWith("0x")&&(r=r.substring(2));var e=s.keyFromPrivate(r);return function(r){try{var t=e.sign(c(r)),n=t.s,o=t.recoveryParam;return Promise.resolve({r:l(t.r.toString("hex")),s:l(n.toString("hex")),recoveryParam:o})}catch(r){return Promise.reject(r)}}}function h(r){return new Uint8Array(Array.prototype.slice.call(Buffer.from(r,"base64"),0))}function v(r,e){var t=r.r,n=r.s,o=r.recoveryParam,a=Buffer.alloc(e?65:64);if(Buffer.from(t,"hex").copy(a,0),Buffer.from(n,"hex").copy(a,32),e){if(void 0===o)throw new Error("Signer did not return a recoveryParam");a[64]=o}return i.encode(a)}function p(){return(p=Object.assign||function(r){for(var e=1;e<arguments.length;e++){var t=arguments[e];for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(r[n]=t[n])}return r}).apply(this,arguments)}var y=new e.ec("secp256k1");function g(r,e){void 0===e&&(e=!1);var t=i.toBuffer(r);if(t.length!==(e?65:64))throw new Error("wrong signature length");var n={r:t.slice(0,32).toString("hex"),s:t.slice(32,64).toString("hex")};return e&&(n.recoveryParam=t[64]),n}function w(r,e,t){var n;if(e.length>86)n=[g(e,!0)];else{var o=g(e,!1);n=[p({},o,{recoveryParam:0}),p({},o,{recoveryParam:1})]}var i=n.map(function(e){var n=c(r),o=y.recoverPubKey(n,e,e.recoveryParam),i=o.encode("hex"),a=o.encode("hex",!0),u=f(i);return t.find(function(r){var e=r.publicKeyHex;return e===i||e===a||r.ethereumAddress===u})}).filter(function(r){return null!=r});if(0===i.length)throw new Error("Signature invalid for JWT");return i[0]}var m={ES256K:function(r,e,t){var n=c(r),o=g(e),i=t.filter(function(r){return void 0!==r.publicKeyHex}),a=t.filter(function(r){return void 0!==r.ethereumAddress}),u=i.find(function(r){var e=r.publicKeyHex;try{return y.keyFromPublic(e,"hex").verify(n,o)}catch(r){return!1}});if(!u&&a.length>0&&(u=w(r,e,a)),!u)throw new Error("Signature invalid for JWT");return u},"ES256K-R":w,Ed25519:function(r,e,t){var n=u.encode(r),o=h(i.toBase64(e)),c=t.find(function(r){return a.sign.detached.verify(n,o,h(r.publicKeyBase64))});if(!c)throw new Error("Signature invalid for JWT");return c}};function b(r){var e=m[r];if(!e)throw new Error("Unsupported algorithm "+r);return e}function E(r){return"object"==typeof r&&"r"in r&&"s"in r}function S(r){return function(e,t){try{return Promise.resolve(t(e)).then(function(e){if(E(e))return v(e,r);if(r)throw new Error("ES256K-R not supported when signer function returns string");return e})}catch(r){return Promise.reject(r)}}}b.toSignatureObject=g;var P={ES256K:S(),"ES256K-R":S(!0),Ed25519:function(r,e){try{return Promise.resolve(e(r)).then(function(r){if(E(r))throw new Error("expected a signer function that returns a string instead of signature object");return r})}catch(r){return Promise.reject(r)}}},x=function(r,e,t){void 0===t&&(t={});try{t.alg||(t.alg=J);var n=[K(t),K(r)].join("."),o=function(r){var e=P[r];if(!e)throw new Error("Unsupported algorithm "+r);return e}(t.alg);return Promise.resolve(o(n,e)).then(function(r){return[n,r].join(".")})}catch(r){return Promise.reject(r)}},j={ES256K:["Secp256k1VerificationKey2018","Secp256k1SignatureVerificationKey2018","EcdsaPublicKeySecp256k1"],"ES256K-R":["Secp256k1VerificationKey2018","Secp256k1SignatureVerificationKey2018","EcdsaPublicKeySecp256k1"],Ed25519:["ED25519SignatureVerification"]},J="ES256K";function K(r){return i.encode(JSON.stringify(r))}function W(r){if(!r)throw new Error("no JWT passed into decodeJWT");var e=r.match(/^([a-zA-Z0-9_-]+)\.([a-zA-Z0-9_-]+)\.([a-zA-Z0-9_-]+)$/);if(e)return{header:JSON.parse(i.decode(e[1])),payload:JSON.parse(i.decode(e[2])),signature:e[3],data:e[1]+"."+e[2]};throw new Error("Incorrect format JWT")}function k(r,e){var t=r.header,n=r.data,o=r.signature;return Array.isArray(e)||(e=[e]),b(t.alg)(n,o,e)}r.EllipticSigner=function(r){var e=d(r);return function(r){try{return Promise.resolve(e(r)).then(function(r){return v(r)})}catch(r){return Promise.reject(r)}}},r.NaclSigner=function(r){var e=h(r);return function(r){try{var t=u.encode(r),n=a.sign.detached(t,e),c=i.encode(o.Buffer.from(n));return Promise.resolve(c)}catch(r){return Promise.reject(r)}}},r.SimpleSigner=d,r.createJWS=x,r.createJWT=function(r,e,t){var n=e.issuer,o=e.signer,i=e.alg,a=e.expiresIn;void 0===t&&(t={});try{if(!o)throw new Error("No Signer functionality has been configured");if(!n)throw new Error("No issuing DID has been configured");t.typ||(t.typ="JWT"),t.alg||(t.alg=i);var u={iat:Math.floor(Date.now()/1e3),exp:void 0};if(a){if("number"!=typeof a)throw new Error("JWT expiresIn is not a number");u.exp=(r.nbf||u.iat)+Math.floor(a)}var c=p({},u,r,{iss:n});return x(c,o,t)}catch(r){return Promise.reject(r)}},r.decodeJWT=W,r.toEthereumAddress=f,r.verifyJWS=function(r,e){return k(W(r),e)},r.verifyJWT=function(r,e){void 0===e&&(e={resolver:null,auth:null,audience:null,callbackUrl:null});try{if(!e.resolver)throw new Error("No DID resolver has been configured");var t=W(r),n=t.payload,o=t.header,i=t.signature,a=t.data;return Promise.resolve(function(r,e,t,n){try{var o=j[e];if(!o||0===o.length)throw new Error("No supported signature types for algorithm "+e);return Promise.resolve(r.resolve(t)).then(function(r){if(!r)throw new Error("Unable to resolve DID document for "+t);var i=!n||(r.authentication||[]).map(function(r){return r.publicKey}),a=(r.publicKey||[]).filter(function(r){var e=r.type,t=r.id;return o.find(function(r){return r===e&&(!n||Array.isArray(i)&&i.indexOf(t)>=0)})});if(n&&(!a||0===a.length))throw new Error("DID document for "+t+" does not have public keys suitable for authenticationg user");if(!a||0===a.length)throw new Error("DID document for "+t+" does not have public keys for "+e);return{authenticators:a,issuer:t,doc:r}})}catch(r){return Promise.reject(r)}}(e.resolver,o.alg,n.iss,e.auth)).then(function(t){var u=t.doc,c=t.issuer;return Promise.resolve(k({header:o,data:a,signature:i},t.authenticators)).then(function(t){var o=Math.floor(Date.now()/1e3);if(t){var i=o+300;if(n.nbf){if(n.nbf>i)throw new Error("JWT not valid before nbf: "+n.nbf)}else if(n.iat&&n.iat>i)throw new Error("JWT not valid yet (issued in the future) iat: "+n.iat);if(n.exp&&n.exp<=o-300)throw new Error("JWT has expired: exp: "+n.exp+" < now: "+o);if(n.aud){if(!e.audience&&!e.callbackUrl)throw new Error("JWT audience is required but your app address has not been configured");if(void 0===(Array.isArray(n.aud)?n.aud:[n.aud]).find(function(r){return e.audience===r||e.callbackUrl===r}))throw new Error("JWT audience does not match your DID or callback url")}return{payload:n,doc:u,issuer:c,signer:t,jwt:r}}})})}catch(r){return Promise.reject(r)}}}); | ||
!function(r,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("elliptic"),require("js-sha256"),require("js-sha3"),require("buffer"),require("uport-base64url"),require("tweetnacl"),require("@stablelib/utf8")):"function"==typeof define&&define.amd?define(["exports","elliptic","js-sha256","js-sha3","buffer","uport-base64url","tweetnacl","@stablelib/utf8"],e):e((r=r||self).didJwt={},r.elliptic,r.jsSha256,r.jsSha3,r.buffer,r.uportBase64Url,r.tweetnacl,r.utf8)}(this,function(r,e,t,n,o,i,a,u){function c(r){return o.Buffer.from(t.sha256.arrayBuffer(r))}function f(r){return"0x"+(e=o.Buffer.from(r.slice(2),"hex"),o.Buffer.from(n.keccak_256.arrayBuffer(e))).slice(-20).toString("hex");var e}i=i&&Object.prototype.hasOwnProperty.call(i,"default")?i.default:i,a=a&&Object.prototype.hasOwnProperty.call(a,"default")?a.default:a;var s=new e.ec("secp256k1");function l(r,e){return void 0===e&&(e=64),r.length===e?r:"0".repeat(e-r.length)+r}function d(r){r.startsWith("0x")&&(r=r.substring(2));var e=s.keyFromPrivate(r);return function(r){try{var t=e.sign(c(r)),n=t.s,o=t.recoveryParam;return Promise.resolve({r:l(t.r.toString("hex")),s:l(n.toString("hex")),recoveryParam:o})}catch(r){return Promise.reject(r)}}}function h(r){return new Uint8Array(Array.prototype.slice.call(Buffer.from(r,"base64"),0))}function v(r,e){var t=r.r,n=r.s,o=r.recoveryParam,a=Buffer.alloc(e?65:64);if(Buffer.from(t,"hex").copy(a,0),Buffer.from(n,"hex").copy(a,32),e){if(void 0===o)throw new Error("Signer did not return a recoveryParam");a[64]=o}return i.encode(a)}function p(){return(p=Object.assign||function(r){for(var e=1;e<arguments.length;e++){var t=arguments[e];for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(r[n]=t[n])}return r}).apply(this,arguments)}var y=new e.ec("secp256k1");function g(r,e){void 0===e&&(e=!1);var t=i.toBuffer(r);if(t.length!==(e?65:64))throw new Error("wrong signature length");var n={r:t.slice(0,32).toString("hex"),s:t.slice(32,64).toString("hex")};return e&&(n.recoveryParam=t[64]),n}function w(r,e,t){var n;if(e.length>86)n=[g(e,!0)];else{var o=g(e,!1);n=[p({},o,{recoveryParam:0}),p({},o,{recoveryParam:1})]}var i=n.map(function(e){var n=c(r),o=y.recoverPubKey(n,e,e.recoveryParam),i=o.encode("hex"),a=o.encode("hex",!0),u=f(i);return t.find(function(r){var e=r.publicKeyHex;return e===i||e===a||r.ethereumAddress===u})}).filter(function(r){return null!=r});if(0===i.length)throw new Error("Signature invalid for JWT");return i[0]}var m={ES256K:function(r,e,t){var n=c(r),o=g(e),i=t.filter(function(r){return void 0!==r.publicKeyHex}),a=t.filter(function(r){return void 0!==r.ethereumAddress}),u=i.find(function(r){var e=r.publicKeyHex;try{return y.keyFromPublic(e,"hex").verify(n,o)}catch(r){return!1}});if(!u&&a.length>0&&(u=w(r,e,a)),!u)throw new Error("Signature invalid for JWT");return u},"ES256K-R":w,Ed25519:function(r,e,t){var n=u.encode(r),o=h(i.toBase64(e)),c=t.find(function(r){return a.sign.detached.verify(n,o,h(r.publicKeyBase64))});if(!c)throw new Error("Signature invalid for JWT");return c}};function b(r){var e=m[r];if(!e)throw new Error("Unsupported algorithm "+r);return e}function E(r){return"object"==typeof r&&"r"in r&&"s"in r}function S(r){return function(e,t){try{return Promise.resolve(t(e)).then(function(e){if(E(e))return v(e,r);if(r)throw new Error("ES256K-R not supported when signer function returns string");return e})}catch(r){return Promise.reject(r)}}}b.toSignatureObject=g;var P={ES256K:S(),"ES256K-R":S(!0),Ed25519:function(r,e){try{return Promise.resolve(e(r)).then(function(r){if(E(r))throw new Error("expected a signer function that returns a string instead of signature object");return r})}catch(r){return Promise.reject(r)}}},x=function(r,e,t){void 0===t&&(t={});try{t.alg||(t.alg=J);var n=[K(t),K(r)].join("."),o=function(r){var e=P[r];if(!e)throw new Error("Unsupported algorithm "+r);return e}(t.alg);return Promise.resolve(o(n,e)).then(function(r){return[n,r].join(".")})}catch(r){return Promise.reject(r)}},j={ES256K:["Secp256k1VerificationKey2018","Secp256k1SignatureVerificationKey2018","EcdsaPublicKeySecp256k1"],"ES256K-R":["Secp256k1VerificationKey2018","Secp256k1SignatureVerificationKey2018","EcdsaPublicKeySecp256k1"],Ed25519:["ED25519SignatureVerification"]},J="ES256K";function K(r){return i.encode(JSON.stringify(r))}function W(r){if(!r)throw new Error("no JWT passed into decodeJWT");var e=r.match(/^([a-zA-Z0-9_-]+)\.([a-zA-Z0-9_-]+)\.([a-zA-Z0-9_-]+)$/);if(e)return{header:JSON.parse(i.decode(e[1])),payload:JSON.parse(i.decode(e[2])),signature:e[3],data:e[1]+"."+e[2]};throw new Error("Incorrect format JWT")}function k(r,e){var t=r.header,n=r.data,o=r.signature;return Array.isArray(e)||(e=[e]),b(t.alg)(n,o,e)}r.EllipticSigner=function(r){var e=d(r);return function(r){try{return Promise.resolve(e(r)).then(function(r){return v(r)})}catch(r){return Promise.reject(r)}}},r.NaclSigner=function(r){var e=h(r);return function(r){try{var t=u.encode(r),n=a.sign.detached(t,e),c=i.encode(o.Buffer.from(n));return Promise.resolve(c)}catch(r){return Promise.reject(r)}}},r.SimpleSigner=d,r.createJWS=x,r.createJWT=function(r,e,t){var n=e.issuer,o=e.signer,i=e.alg,a=e.expiresIn;void 0===t&&(t={});try{if(!o)throw new Error("No Signer functionality has been configured");if(!n)throw new Error("No issuing DID has been configured");t.typ||(t.typ="JWT"),t.alg||(t.alg=i);var u={iat:Math.floor(Date.now()/1e3),exp:void 0};if(a){if("number"!=typeof a)throw new Error("JWT expiresIn is not a number");u.exp=(r.nbf||u.iat)+Math.floor(a)}var c=p({},u,r,{iss:n});return x(c,o,t)}catch(r){return Promise.reject(r)}},r.decodeJWT=W,r.toEthereumAddress=f,r.verifyJWS=function(r,e){return k(W(r),e)},r.verifyJWT=function(r,e){void 0===e&&(e={resolver:null,auth:null,audience:null,callbackUrl:null});try{if(!e.resolver)throw new Error("No DID resolver has been configured");var t=W(r),n=t.payload,o=t.header,i=t.signature,a=t.data;return Promise.resolve(function(r,e,t,n){try{var o=j[e];if(!o||0===o.length)throw new Error("No supported signature types for algorithm "+e);return Promise.resolve(r.resolve(t)).then(function(r){if(!r)throw new Error("Unable to resolve DID document for "+t);var i=!n||(r.authentication||[]).map(function(r){return r.publicKey}),a=(r.publicKey||[]).filter(function(r){var e=r.type,t=r.id;return o.find(function(r){return r===e&&(!n||Array.isArray(i)&&i.indexOf(t)>=0)})});if(n&&(!a||0===a.length))throw new Error("DID document for "+t+" does not have public keys suitable for authenticationg user");if(!a||0===a.length)throw new Error("DID document for "+t+" does not have public keys for "+e);return{authenticators:a,issuer:t,doc:r}})}catch(r){return Promise.reject(r)}}(e.resolver,o.alg,n.iss,e.auth)).then(function(t){var u=t.doc,c=t.issuer;return Promise.resolve(k({header:o,data:a,signature:i},t.authenticators)).then(function(t){var o=Math.floor(Date.now()/1e3);if(t){var i=o+300;if(n.nbf){if(n.nbf>i)throw new Error("JWT not valid before nbf: "+n.nbf)}else if(n.iat&&n.iat>i)throw new Error("JWT not valid yet (issued in the future) iat: "+n.iat);if(n.exp&&n.exp<=o-300)throw new Error("JWT has expired: exp: "+n.exp+" < now: "+o);if(n.aud){if(!e.audience&&!e.callbackUrl)throw new Error("JWT audience is required but your app address has not been configured");if(void 0===(Array.isArray(n.aud)?n.aud:[n.aud]).find(function(r){return e.audience===r||e.callbackUrl===r}))throw new Error("JWT audience does not match your DID or callback url")}return{payload:n,doc:u,issuer:c,signer:t,jwt:r}}})})}catch(r){return Promise.reject(r)}}}); | ||
//# sourceMappingURL=index.umd.js.map |
@@ -9,3 +9,3 @@ import { DIDDocument, PublicKey } from 'did-resolver'; | ||
export declare type SignerAlgorithm = (payload: string, signer: Signer) => Promise<string>; | ||
interface JWTOptions { | ||
export interface JWTOptions { | ||
issuer: string; | ||
@@ -16,6 +16,6 @@ signer: Signer; | ||
} | ||
interface Resolvable { | ||
export interface Resolvable { | ||
resolve: (did: string) => Promise<DIDDocument | null>; | ||
} | ||
interface JWTVerifyOptions { | ||
export interface JWTVerifyOptions { | ||
auth?: boolean; | ||
@@ -26,3 +26,3 @@ audience?: string; | ||
} | ||
interface DIDAuthenticator { | ||
export interface DIDAuthenticator { | ||
authenticators: PublicKey[]; | ||
@@ -32,3 +32,3 @@ issuer: string; | ||
} | ||
interface JWTHeader { | ||
export interface JWTHeader { | ||
typ: 'JWT'; | ||
@@ -38,3 +38,3 @@ alg: string; | ||
} | ||
interface JWTPayload { | ||
export interface JWTPayload { | ||
iss?: string; | ||
@@ -50,3 +50,3 @@ sub?: string; | ||
} | ||
interface JWTDecoded { | ||
export interface JWTDecoded { | ||
header: JWTHeader; | ||
@@ -57,3 +57,3 @@ payload: JWTPayload; | ||
} | ||
interface Verified { | ||
export interface JWTVerified { | ||
payload: any; | ||
@@ -65,2 +65,6 @@ doc: DIDDocument; | ||
} | ||
export interface PublicKeyTypes { | ||
[name: string]: string[]; | ||
} | ||
export declare const SUPPORTED_PUBLIC_KEY_TYPES: PublicKeyTypes; | ||
export declare const NBF_SKEW: number; | ||
@@ -143,3 +147,3 @@ /** @module did-jwt/JWT */ | ||
*/ | ||
export declare function verifyJWT(jwt: string, options?: JWTVerifyOptions): Promise<Verified>; | ||
export declare function verifyJWT(jwt: string, options?: JWTVerifyOptions): Promise<JWTVerified>; | ||
/** | ||
@@ -162,3 +166,2 @@ * Resolves relevant public keys or other authenticating material used to verify signature from the DID document of provided DID | ||
export declare function resolveAuthenticator(resolver: Resolvable, alg: string, issuer: string, auth?: boolean): Promise<DIDAuthenticator>; | ||
export {}; | ||
//# sourceMappingURL=JWT.d.ts.map |
{ | ||
"name": "did-jwt", | ||
"version": "4.4.0", | ||
"version": "4.4.1", | ||
"description": "Library for Signing and Verifying JWTs compatible uPort and DID standards", | ||
@@ -64,29 +64,29 @@ "main": "lib/index.js", | ||
"@types/elliptic": "6.4.12", | ||
"@types/jest": "26.0.0", | ||
"codecov": "3.7.0", | ||
"eslint": "7.2.0", | ||
"@types/jest": "26.0.10", | ||
"codecov": "3.7.2", | ||
"eslint": "7.7.0", | ||
"eslint-config-standard": "14.1.1", | ||
"eslint-plugin-import": "2.21.2", | ||
"eslint-plugin-jest": "23.13.2", | ||
"eslint-plugin-import": "2.22.0", | ||
"eslint-plugin-jest": "23.20.0", | ||
"eslint-plugin-node": "11.1.0", | ||
"eslint-plugin-promise": "4.2.1", | ||
"eslint-plugin-standard": "4.0.1", | ||
"jest": "26.0.1", | ||
"jest": "26.4.0", | ||
"jsdoc-to-markdown": "6.0.1", | ||
"jsontokens": "3.0.0", | ||
"microbundle": "0.12.1", | ||
"microbundle": "0.12.3", | ||
"mockdate": "3.0.2", | ||
"nacl-did": "1.0.1", | ||
"prettier": "2.0.5", | ||
"regenerator-runtime": "0.13.5", | ||
"semantic-release": "17.0.8", | ||
"sinon": "9.0.2", | ||
"regenerator-runtime": "0.13.7", | ||
"semantic-release": "17.1.1", | ||
"sinon": "9.0.3", | ||
"standard": "14.3.4", | ||
"ts-jest": "26.1.0", | ||
"tslint": "5.20.1", | ||
"ts-jest": "26.2.0", | ||
"tslint": "6.1.3", | ||
"tslint-config-prettier": "1.18.0", | ||
"tslint-eslint-rules": "5.4.0", | ||
"typescript": "3.9.5", | ||
"webpack": "4.43.0", | ||
"webpack-cli": "3.3.11" | ||
"typescript": "3.9.7", | ||
"webpack": "4.44.1", | ||
"webpack-cli": "3.3.12" | ||
}, | ||
@@ -93,0 +93,0 @@ "dependencies": { |
@@ -13,3 +13,2 @@ # did-jwt | ||
## DID methods | ||
We currently support the following DID methods: | ||
@@ -53,7 +52,4 @@ | ||
let jwt = ''; | ||
didJWT.createJWT({aud: 'did:ethr:0xf3beac30c498d9e26865f34fcaa57dbb935b0d74', exp: 1957463421, name: 'uPort Developer'}, | ||
{alg: 'ES256K-R', issuer: 'did:ethr:0xf3beac30c498d9e26865f34fcaa57dbb935b0d74', signer}).then( response => | ||
{ jwt = response }); | ||
let jwt = await didJWT.createJWT({aud: 'did:ethr:0xf3beac30c498d9e26865f34fcaa57dbb935b0d74', exp: 1957463421, name: 'uPort Developer'}, | ||
{alg: 'ES256K', issuer: 'did:ethr:0xf3beac30c498d9e26865f34fcaa57dbb935b0d74', signer}) | ||
console.log(jwt); | ||
@@ -77,3 +73,3 @@ ``` | ||
{ | ||
header: { typ: 'JWT', alg: 'ES256K-R' }, | ||
header: { typ: 'JWT', alg: 'ES256K' }, | ||
payload: { | ||
@@ -92,3 +88,2 @@ iat: 1571692233, | ||
### 3. Verify a did-JWT | ||
[verifyJWT](/docs/reference/index.md#did-jwtjwtverifyjwtjwt-config--promiseobject-error) | ||
@@ -104,11 +99,8 @@ | ||
const Resolver = require('did-resolver') | ||
const ethrDid = require('ethr-did-resolver').getResolver() | ||
const ethrDid = require('ethr-did-resolver').getResolver({rpcUrl: 'https://mainnet.infura.io/v3/...'}) | ||
let resolver = new Resolver.Resolver(ethrDid) | ||
let verifiedRespone = {}; | ||
// pass the JWT from step 1 & 2 | ||
didJWT.verifyJWT(jwt, {resolver: resolver, audience: 'did:ethr:0xf3beac30c498d9e26865f34fcaa57dbb935b0d74'}).then((response) => | ||
{ verifiedRespone = response }); | ||
let verifiedRespone = await didJWT.verifyJWT(jwt, {resolver: resolver, audience: 'did:ethr:0xf3beac30c498d9e26865f34fcaa57dbb935b0d74'}) | ||
console.log(verifiedRespone); | ||
@@ -115,0 +107,0 @@ ``` |
@@ -123,5 +123,5 @@ import { createJWT, verifyJWT, decodeJWT, resolveAuthenticator, NBF_SKEW } from '../JWT' | ||
it('throws an error if unsupported algorithm is passed in', async () => { | ||
await expect(createJWT({ requested: ['name', 'phone'] }, { issuer: did, signer, alg: 'BADALGO' })).rejects.toThrow( | ||
'Unsupported algorithm BADALGO' | ||
) | ||
await expect( | ||
createJWT({ requested: ['name', 'phone'] }, { issuer: did, signer, alg: 'BADALGO' }) | ||
).rejects.toThrow('Unsupported algorithm BADALGO') | ||
}) | ||
@@ -308,3 +308,5 @@ }) | ||
const jwt = await createJWT({ aud }, { issuer: did, signer }) | ||
await expect(verifyJWT(jwt, { resolver, audience: did })).rejects.toThrow(/JWT audience does not match your DID or callback url/) | ||
await expect(verifyJWT(jwt, { resolver, audience: did })).rejects.toThrow( | ||
/JWT audience does not match your DID or callback url/ | ||
) | ||
}) | ||
@@ -325,3 +327,3 @@ | ||
await expect(verifyJWT(jwt, { resolver })).rejects.toThrow( | ||
"JWT audience is required but your app address has not been configured" | ||
'JWT audience is required but your app address has not been configured' | ||
) | ||
@@ -332,3 +334,5 @@ }) | ||
const jwt = await createJWT({ aud }, { issuer: did, signer }) | ||
await expect(verifyJWT(jwt, { resolver })).rejects.toThrow(/JWT audience is required but your app address has not been configured/) | ||
await expect(verifyJWT(jwt, { resolver })).rejects.toThrow( | ||
/JWT audience is required but your app address has not been configured/ | ||
) | ||
}) | ||
@@ -335,0 +339,0 @@ }) |
import SimpleSigner from './SimpleSigner' | ||
import EllipticSigner from './EllipticSigner' | ||
import NaclSigner from './NaclSigner' | ||
import { verifyJWT, createJWT, decodeJWT, verifyJWS, createJWS, Signer } from './JWT' | ||
import { | ||
verifyJWT, | ||
createJWT, | ||
decodeJWT, | ||
verifyJWS, | ||
createJWS, | ||
Signer, | ||
JWTHeader, | ||
JWTPayload, | ||
JWTVerified, | ||
Resolvable | ||
} from './JWT' | ||
import { toEthereumAddress } from './Digest' | ||
export { SimpleSigner, EllipticSigner, NaclSigner, verifyJWT, createJWT, decodeJWT, verifyJWS, createJWS, toEthereumAddress, Signer } | ||
export { | ||
SimpleSigner, | ||
EllipticSigner, | ||
NaclSigner, | ||
verifyJWT, | ||
createJWT, | ||
decodeJWT, | ||
verifyJWS, | ||
createJWS, | ||
toEthereumAddress, | ||
Signer, | ||
JWTHeader, | ||
JWTPayload, | ||
JWTVerified, | ||
Resolvable | ||
} |
@@ -15,3 +15,3 @@ import VerifierAlgorithm from './VerifierAlgorithm' | ||
interface JWTOptions { | ||
export interface JWTOptions { | ||
issuer: string | ||
@@ -23,7 +23,7 @@ signer: Signer | ||
interface Resolvable { | ||
export interface Resolvable { | ||
resolve: (did: string) => Promise<DIDDocument | null> | ||
} | ||
interface JWTVerifyOptions { | ||
export interface JWTVerifyOptions { | ||
auth?: boolean | ||
@@ -35,3 +35,3 @@ audience?: string | ||
interface DIDAuthenticator { | ||
export interface DIDAuthenticator { | ||
authenticators: PublicKey[] | ||
@@ -42,3 +42,3 @@ issuer: string | ||
interface JWTHeader { | ||
export interface JWTHeader { | ||
typ: 'JWT' | ||
@@ -49,3 +49,3 @@ alg: string | ||
interface JWTPayload { | ||
export interface JWTPayload { | ||
iss?: string | ||
@@ -62,3 +62,3 @@ sub?: string | ||
interface JWTDecoded { | ||
export interface JWTDecoded { | ||
header: JWTHeader | ||
@@ -70,3 +70,3 @@ payload: JWTPayload | ||
interface Verified { | ||
export interface JWTVerified { | ||
payload: any | ||
@@ -79,6 +79,6 @@ doc: DIDDocument | ||
interface PublicKeyTypes { | ||
export interface PublicKeyTypes { | ||
[name: string]: string[] | ||
} | ||
const SUPPORTED_PUBLIC_KEY_TYPES: PublicKeyTypes = { | ||
export const SUPPORTED_PUBLIC_KEY_TYPES: PublicKeyTypes = { | ||
ES256K: ['Secp256k1VerificationKey2018', 'Secp256k1SignatureVerificationKey2018', 'EcdsaPublicKeySecp256k1'], | ||
@@ -185,6 +185,3 @@ 'ES256K-R': ['Secp256k1VerificationKey2018', 'Secp256k1SignatureVerificationKey2018', 'EcdsaPublicKeySecp256k1'], | ||
function verifyJWSDecoded( | ||
{ header, data, signature }: JWTDecoded, | ||
pubkeys: PublicKey | PublicKey[] | ||
): PublicKey { | ||
function verifyJWSDecoded({ header, data, signature }: JWTDecoded, pubkeys: PublicKey | PublicKey[]): PublicKey { | ||
if (!Array.isArray(pubkeys)) pubkeys = [pubkeys] | ||
@@ -240,3 +237,3 @@ const signer: PublicKey = VerifierAlgorithm(header.alg)(data, signature, pubkeys) | ||
} | ||
): Promise<Verified> { | ||
): Promise<JWTVerified> { | ||
if (!options.resolver) throw new Error('No DID resolver has been configured') | ||
@@ -243,0 +240,0 @@ const { payload, header, signature, data }: JWTDecoded = decodeJWT(jwt) |
@@ -59,3 +59,6 @@ import { ec as EC } from 'elliptic' | ||
const so = toSignatureObject(signature, false) | ||
signatures = [{ ...so, recoveryParam: 0 }, { ...so, recoveryParam: 1 }] | ||
signatures = [ | ||
{ ...so, recoveryParam: 0 }, | ||
{ ...so, recoveryParam: 1 } | ||
] | ||
} | ||
@@ -62,0 +65,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
474217
2415
131