uport-credentials
Advanced tools
Comparing version 1.2.1 to 1.2.2-alpha.0
@@ -243,3 +243,3 @@ import { DIDDocument } from 'did-jwt'; | ||
constructor({ did, address, privateKey, signer, networks, registry, ethrConfig }: Settings); | ||
signJWT(payload: object, expiresIn?: number): Promise<string>; | ||
signJWT(payload: object, expiresIn?: number): any; | ||
/** | ||
@@ -302,3 +302,3 @@ * Creates a [Selective Disclosure Request JWT](https://github.com/uport-project/specs/blob/develop/messages/sharereq.md) | ||
*/ | ||
createDisclosureRequest(params?: DisclosureRequestParams, expiresIn?: number): Promise<string>; | ||
createDisclosureRequest(params?: DisclosureRequestParams, expiresIn?: number): any; | ||
/** | ||
@@ -323,3 +323,3 @@ * Create a credential (a signed JSON Web Token) | ||
*/ | ||
createVerification({ sub, claim, exp, vc, callbackUrl }: VerificationParam): Promise<string>; | ||
createVerification({ sub, claim, exp, vc, callbackUrl }: VerificationParam): any; | ||
/** | ||
@@ -357,3 +357,3 @@ * Creates a request a for a DID to [sign a verification](https://github.com/uport-project/specs/blob/develop/messages/verificationreq.md) | ||
*/ | ||
createVerificationSignatureRequest(unsignedClaim: object, { aud, sub, riss, callbackUrl, vc, rexp, expiresIn }: VerificationRequest): Promise<string>; | ||
createVerificationSignatureRequest(unsignedClaim: object, { aud, sub, riss, callbackUrl, vc, rexp, expiresIn }: VerificationRequest): any; | ||
/** | ||
@@ -407,3 +407,3 @@ * Create a JWT requesting a signature on a piece of structured/typed data conforming to | ||
*/ | ||
createTypedDataSignatureRequest(typedData: EIP712Object, { from, net, callback }?: NetworkRequest): Promise<string>; | ||
createTypedDataSignatureRequest(typedData: EIP712Object, { from, net, callback }?: NetworkRequest): Promise<any>; | ||
/** | ||
@@ -415,3 +415,3 @@ * Create a JWT requesting an eth_sign/personal_sign from a user. | ||
*/ | ||
createPersonalSignRequest(data: string, { from, net, callback }?: NetworkRequest): Promise<string>; | ||
createPersonalSignRequest(data: string, { from, net, callback }?: NetworkRequest): any; | ||
/** | ||
@@ -440,3 +440,3 @@ * Given a transaction object, similarly defined as the web3 transaction object, | ||
*/ | ||
createTxRequest(txObj: TransactionRequest, { callbackUrl, exp, networkId, label }?: TxReqOptions): Promise<string>; | ||
createTxRequest(txObj: TransactionRequest, { callbackUrl, exp, networkId, label }?: TxReqOptions): any; | ||
/** | ||
@@ -463,3 +463,3 @@ * Creates a [Selective Disclosure Response JWT](https://github.com/uport-project/specs/blob/develop/messages/shareresp.md). | ||
*/ | ||
createDisclosureResponse(payload?: DisclosureResponsePayload, expiresIn?: number): Promise<string>; | ||
createDisclosureResponse(payload?: DisclosureResponsePayload, expiresIn?: number): Promise<any>; | ||
/** | ||
@@ -466,0 +466,0 @@ * Parse a selective disclosure response, and verify signatures on each signed claim ("verification") included. |
import Creds from './Credentials'; | ||
import { SimpleSigner as S } from 'did-jwt'; | ||
export declare const Credentials: typeof Creds; | ||
export declare const SimpleSigner: typeof S; | ||
export declare const SimpleSigner: any; | ||
export declare const ContractFactory: (encoder?: (tx: any, params?: any) => any) => (contractABI: (import("./Contract").AbiEvent | import("./Contract").AbiFunction)[]) => import("./Contract").Factory; | ||
declare const _default: { | ||
Credentials: typeof Creds; | ||
SimpleSigner: typeof S; | ||
SimpleSigner: any; | ||
ContractFactory: (encoder?: (tx: any, params?: any) => any) => (contractABI: (import("./Contract").AbiEvent | import("./Contract").AbiFunction)[]) => import("./Contract").Factory; | ||
@@ -10,0 +9,0 @@ }; |
@@ -1,2 +0,2 @@ | ||
function e(e){return e&&"object"==typeof e&&"default"in e?e.default:e}var r,t,i=require("elliptic"),n=require("did-jwt/lib/Digest"),o=e(require("uport-did-resolver")),a=e(require("ethr-did-resolver")),c=e(require("https-did-resolver")),s=e(require("uport-lite")),u=require("mnid"),d=require("did-jwt");!function(e){e.Function="function",e.Event="event",e.Constructor="constructor",e.Fallback="fallback"}(r||(r={})),function(e){e.Pure="pure",e.View="view",e.NonPayable="nonpayable",e.Payable="payable"}(t||(t={}));var l,p=function(e,r){for(var t=e.name+"(",i=e.inputs||[],n=0;n<i.length;n++){var o=i[n],a=o.type+" ";t+=a+="string"===o.type?'"'+r[n]+'"':""+r[n],i.length-1!==n&&(t+=", ")}return t+")"},f=function(e){return function(t){return{at:function(i){var n={};return function(e){return e.filter(function(e){return e.type===r.Function&&e.name&&!e.constant})}(t).forEach(function(r){r.name&&(n[r.name]=function(){var t={},n=[].slice.call(arguments),o=(r.inputs||[]).length;(function(e){if("object"!=typeof e)return!1;if(0===Object.keys(e).length)return!0;for(var r=0,t=["from","to","data","value","gasPrice","gas"];r<t.length;r+=1)if(t[r]in e)return!0;return!1})(n[o])&&(t=n.splice(o,1)[0]);var a=Object.assign({},t,{to:i,function:p(r,n)});return e?e(a,n[n.length-1]):a})}),Object.assign({},n,{abi:t,address:i})}}}},v=new i.ec("secp256k1");!function(e){e.DISCLOSURE_REQUEST="shareReq",e.DISCLOSURE_RESPONSE="shareResp",e.TYPED_DATA_SIGNATURE_REQUEST="eip712Req",e.VERIFICATION_SIGNATURE_REQUEST="verReq",e.ETH_TX_REQUEST="ethtx",e.PERSONAL_SIGN_REQUEST="personalSigReq"}(l||(l={}));var h=function(e){var r,t=e.did,i=e.address,l=e.privateKey,p=e.signer,f=e.networks,h=e.registry,y=e.ethrConfig;if(p?this.signer=p:l&&(this.signer=d.SimpleSigner(l)),t)this.did=t;else if(i)u.isMNID(i)&&(this.did="did:uport:"+i),i.match("^0x[0-9a-fA-F]{40}$")&&(this.did="did:ethr:"+i);else if(l){var g=v.keyFromPrivate(l),E=n.toEthereumAddress(g.getPublic("hex"));this.did="did:ethr:"+E}o(h||s({networks:f?(r=f,Object.keys(r).forEach(function(e){var t=r[e];if("object"!=typeof t)throw new Error("Network configuration object required");["registry","rpcUrl"].forEach(function(e){if(!t.hasOwnProperty(e))throw new Error("Malformed network config object, object must have '"+e+"' key specified.")})}),r):{}})),a(y||{}),c()};h.createIdentity=function(){var e=v.genKeyPair(),r=e.getPublic("hex"),t=e.getPrivate("hex");return{did:"did:ethr:"+n.toEthereumAddress(r),privateKey:t}},h.prototype.signJWT=function(e,r){return this.did&&this.signer?d.createJWT(e,{issuer:this.did,signer:this.signer,alg:this.did.match("^did:uport:")||u.isMNID(this.did)?"ES256K":"ES256K-R",expiresIn:r}):Promise.reject(new Error("No Signing Identity configured"))},h.prototype.createDisclosureRequest=function(e,r){void 0===e&&(e={}),void 0===r&&(r=600);var t={};if(e.requested&&(t.requested=e.requested),e.verified&&(t.verified=e.verified),e.claims&&(t.claims=e.claims),e.notifications&&(t.permissions=["notifications"]),e.callbackUrl&&(t.callback=e.callbackUrl),e.networkId&&(t.net=e.networkId),e.rpcUrl){if(!e.networkId)return Promise.reject(new Error("rpcUrl was specified but no networkId"));t.rpc=e.rpcUrl}if(e.vc&&(t.vc=e.vc),e.exp&&(t.exp=e.exp),e.accountType){if(!(["general","segregated","keypair","none"].indexOf(e.accountType)>=0))return Promise.reject(new Error("Unsupported accountType "+e.accountType));t.act=e.accountType}return this.signJWT(Object.assign({},t,{type:l.DISCLOSURE_REQUEST}),e.exp?void 0:r)},h.prototype.createVerification=function(e){return this.signJWT({sub:e.sub,claim:e.claim,exp:e.exp,vc:e.vc,callbackUrl:e.callbackUrl})},h.prototype.createVerificationSignatureRequest=function(e,r){return this.signJWT({unsignedClaim:e,sub:r.sub,riss:r.riss,aud:r.aud,vc:r.vc,callback:r.callbackUrl,type:l.VERIFICATION_SIGNATURE_REQUEST,rexp:r.rexp},r.expiresIn)},h.prototype.createTypedDataSignatureRequest=function(e,r){void 0===r&&(r={});var t=r.from,i=r.net,n=r.callback;try{for(var o=0,a=["types","primaryType","message","domain"];o<a.length;o+=1){var c=a[o];if(!e[c])throw new Error("Invalid EIP712 Request, must include '"+c+"'")}return Promise.resolve(this.signJWT({typedData:e,from:t,net:i,callback:n,type:l.TYPED_DATA_SIGNATURE_REQUEST}))}catch(e){return Promise.reject(e)}},h.prototype.createPersonalSignRequest=function(e,r){return void 0===r&&(r={}),this.signJWT({data:e,from:r.from,net:r.net,callback:r.callback,type:l.PERSONAL_SIGN_REQUEST})},h.prototype.createTxRequest=function(e,r){void 0===r&&(r={});var t=r.callbackUrl,i=r.exp;void 0===i&&(i=600);var n=r.networkId,o=r.label,a={};return t&&(a.callback=t),n&&(a.net=n),o&&(a.label=o),this.signJWT(Object.assign({},a,e,{type:l.ETH_TX_REQUEST}),i)},h.prototype.createDisclosureResponse=function(e,r){void 0===e&&(e={}),void 0===r&&(r=600);try{var t=this;function i(){return t.signJWT(Object.assign({},e,{type:l.DISCLOSURE_RESPONSE}),r)}var n=function(){if(e.req)return Promise.resolve(d.verifyJWT(e.req)).then(function(r){r.issuer&&(e.aud=r.issuer)})}();return n&&n.then?n.then(i):i()}catch(e){return Promise.reject(e)}},h.prototype.processDisclosurePayload=function(e){var r=e.doc,t=e.payload;try{var i=this,n=t.own;void 0===n&&(n={});var o=t.capabilities;void 0===o&&(o=[]);var a=t.nad,c=t.dad,s=t.iss,l=t.boxPub,p=t.verified,f=function(e,r){var t={};for(var i in e)Object.prototype.hasOwnProperty.call(e,i)&&-1===r.indexOf(i)&&(t[i]=e[i]);return t}(t,["own","capabilities","aud","req","iat","exp","type","nad","dad","iss","boxPub","verified"]),v=r.uportProfile;void 0===v&&(v={});var h=Object.assign({},{did:s,boxPub:l},n,v,f);c&&(h.deviceKey=c),a&&(h.mnid=a,h.address=u.decode(a).address),1===o.length&&(h.pushToken=o[0]);var y=function(){if(p){var e=[],r=p.map(function(r){return d.verifyJWT(r,{audience:i.did}).catch(function(){return e.push(r),Promise.resolve(void 0)})});return Promise.resolve(Promise.all(r)).then(function(r){var t=[];r.forEach(function(e){e&&t.push(Object.assign({},e.payload,{jwt:e.jwt}))}),h.verified=t,h.invalid=e})}}();return y&&y.then?y.then(function(){return h}):h}catch(e){return Promise.reject(e)}},h.prototype.authenticateDisclosureResponse=function(e,r){try{var t=this;return Promise.resolve(d.verifyJWT(e,{audience:t.did,callbackUrl:r,auth:!0})).then(function(e){var r=e.payload,i=e.doc;if(r.req)return Promise.resolve(d.verifyJWT(r.req,{audience:t.did})).then(function(e){var n=e.payload;if(n.type!==l.DISCLOSURE_REQUEST)throw new Error("Challenge payload type invalid: "+n.type);return t.processDisclosurePayload({payload:r,doc:i})});throw new Error("Challenge was not included in response")})}catch(e){return Promise.reject(e)}},h.prototype.verifyDisclosure=function(e){try{var r=this;return Promise.resolve(d.verifyJWT(e,{audience:r.did})).then(function(e){return r.processDisclosurePayload({payload:e.payload,doc:e.doc})})}catch(e){return Promise.reject(e)}},h.prototype.contract=function(e){var r=this;return f(function(e,t){return e.function&&(e.fn=e.function),delete e.function,r.createTxRequest(e,t)}.bind(this))(e)};var y=d.SimpleSigner,g=f,E={Credentials:h,SimpleSigner:y,ContractFactory:g};exports.Credentials=h,exports.SimpleSigner=y,exports.ContractFactory=g,exports.default=E; | ||
function e(e){return e&&"object"==typeof e&&"default"in e?e.default:e}var r,t,i=require("elliptic"),n=require("did-jwt/lib/index"),o=e(require("uport-did-resolver")),a=e(require("ethr-did-resolver")),c=e(require("https-did-resolver")),s=e(require("uport-lite")),u=require("mnid"),d=require("did-jwt");!function(e){e.Function="function",e.Event="event",e.Constructor="constructor",e.Fallback="fallback"}(r||(r={})),function(e){e.Pure="pure",e.View="view",e.NonPayable="nonpayable",e.Payable="payable"}(t||(t={}));var l,p=function(e,r){for(var t=e.name+"(",i=e.inputs||[],n=0;n<i.length;n++){var o=i[n],a=o.type+" ";t+=a+="string"===o.type?'"'+r[n]+'"':""+r[n],i.length-1!==n&&(t+=", ")}return t+")"},f=function(e){return function(t){return{at:function(i){var n={};return function(e){return e.filter(function(e){return e.type===r.Function&&e.name&&!e.constant})}(t).forEach(function(r){r.name&&(n[r.name]=function(){var t={},n=[].slice.call(arguments),o=(r.inputs||[]).length;(function(e){if("object"!=typeof e)return!1;if(0===Object.keys(e).length)return!0;for(var r=0,t=["from","to","data","value","gasPrice","gas"];r<t.length;r+=1)if(t[r]in e)return!0;return!1})(n[o])&&(t=n.splice(o,1)[0]);var a=Object.assign({},t,{to:i,function:p(r,n)});return e?e(a,n[n.length-1]):a})}),Object.assign({},n,{abi:t,address:i})}}}},v=new i.ec("secp256k1");!function(e){e.DISCLOSURE_REQUEST="shareReq",e.DISCLOSURE_RESPONSE="shareResp",e.TYPED_DATA_SIGNATURE_REQUEST="eip712Req",e.VERIFICATION_SIGNATURE_REQUEST="verReq",e.ETH_TX_REQUEST="ethtx",e.PERSONAL_SIGN_REQUEST="personalSigReq"}(l||(l={}));var h=function(e){var r,t=e.did,i=e.address,l=e.privateKey,p=e.signer,f=e.networks,h=e.registry,y=e.ethrConfig;if(p?this.signer=p:l&&(this.signer=d.SimpleSigner(l)),t)this.did=t;else if(i)u.isMNID(i)&&(this.did="did:uport:"+i),i.match("^0x[0-9a-fA-F]{40}$")&&(this.did="did:ethr:"+i);else if(l){var E=v.keyFromPrivate(l),g=n.toEthereumAddress(E.getPublic("hex"));this.did="did:ethr:"+g}o(h||s({networks:f?(r=f,Object.keys(r).forEach(function(e){var t=r[e];if("object"!=typeof t)throw new Error("Network configuration object required");["registry","rpcUrl"].forEach(function(e){if(!t.hasOwnProperty(e))throw new Error("Malformed network config object, object must have '"+e+"' key specified.")})}),r):{}})),a(y||{}),c()};h.createIdentity=function(){var e=v.genKeyPair(),r=e.getPublic("hex"),t=e.getPrivate("hex");return{did:"did:ethr:"+n.toEthereumAddress(r),privateKey:t}},h.prototype.signJWT=function(e,r){return this.did&&this.signer?d.createJWT(e,{issuer:this.did,signer:this.signer,alg:this.did.match("^did:uport:")||u.isMNID(this.did)?"ES256K":"ES256K-R",expiresIn:r}):Promise.reject(new Error("No Signing Identity configured"))},h.prototype.createDisclosureRequest=function(e,r){void 0===e&&(e={}),void 0===r&&(r=600);var t={};if(e.requested&&(t.requested=e.requested),e.verified&&(t.verified=e.verified),e.claims&&(t.claims=e.claims),e.notifications&&(t.permissions=["notifications"]),e.callbackUrl&&(t.callback=e.callbackUrl),e.networkId&&(t.net=e.networkId),e.rpcUrl){if(!e.networkId)return Promise.reject(new Error("rpcUrl was specified but no networkId"));t.rpc=e.rpcUrl}if(e.vc&&(t.vc=e.vc),e.exp&&(t.exp=e.exp),e.accountType){if(!(["general","segregated","keypair","none"].indexOf(e.accountType)>=0))return Promise.reject(new Error("Unsupported accountType "+e.accountType));t.act=e.accountType}return this.signJWT(Object.assign({},t,{type:l.DISCLOSURE_REQUEST}),e.exp?void 0:r)},h.prototype.createVerification=function(e){return this.signJWT({sub:e.sub,claim:e.claim,exp:e.exp,vc:e.vc,callbackUrl:e.callbackUrl})},h.prototype.createVerificationSignatureRequest=function(e,r){return this.signJWT({unsignedClaim:e,sub:r.sub,riss:r.riss,aud:r.aud,vc:r.vc,callback:r.callbackUrl,type:l.VERIFICATION_SIGNATURE_REQUEST,rexp:r.rexp},r.expiresIn)},h.prototype.createTypedDataSignatureRequest=function(e,r){void 0===r&&(r={});var t=r.from,i=r.net,n=r.callback;try{for(var o=0,a=["types","primaryType","message","domain"];o<a.length;o+=1){var c=a[o];if(!e[c])throw new Error("Invalid EIP712 Request, must include '"+c+"'")}return Promise.resolve(this.signJWT({typedData:e,from:t,net:i,callback:n,type:l.TYPED_DATA_SIGNATURE_REQUEST}))}catch(e){return Promise.reject(e)}},h.prototype.createPersonalSignRequest=function(e,r){return void 0===r&&(r={}),this.signJWT({data:e,from:r.from,net:r.net,callback:r.callback,type:l.PERSONAL_SIGN_REQUEST})},h.prototype.createTxRequest=function(e,r){void 0===r&&(r={});var t=r.callbackUrl,i=r.exp;void 0===i&&(i=600);var n=r.networkId,o=r.label,a={};return t&&(a.callback=t),n&&(a.net=n),o&&(a.label=o),this.signJWT(Object.assign({},a,e,{type:l.ETH_TX_REQUEST}),i)},h.prototype.createDisclosureResponse=function(e,r){void 0===e&&(e={}),void 0===r&&(r=600);try{var t=this;function i(){return t.signJWT(Object.assign({},e,{type:l.DISCLOSURE_RESPONSE}),r)}var n=function(){if(e.req)return Promise.resolve(d.verifyJWT(e.req)).then(function(r){r.issuer&&(e.aud=r.issuer)})}();return n&&n.then?n.then(i):i()}catch(e){return Promise.reject(e)}},h.prototype.processDisclosurePayload=function(e){var r=e.doc,t=e.payload;try{var i=this,n=t.own;void 0===n&&(n={});var o=t.capabilities;void 0===o&&(o=[]);var a=t.nad,c=t.dad,s=t.iss,l=t.boxPub,p=t.verified,f=function(e,r){var t={};for(var i in e)Object.prototype.hasOwnProperty.call(e,i)&&-1===r.indexOf(i)&&(t[i]=e[i]);return t}(t,["own","capabilities","aud","req","iat","exp","type","nad","dad","iss","boxPub","verified"]),v=r.uportProfile;void 0===v&&(v={});var h=Object.assign({},{did:s,boxPub:l},n,v,f);c&&(h.deviceKey=c),a&&(h.mnid=a,h.address=u.decode(a).address),1===o.length&&(h.pushToken=o[0]);var y=function(){if(p){var e=[],r=p.map(function(r){return d.verifyJWT(r,{audience:i.did}).catch(function(){return e.push(r),Promise.resolve(void 0)})});return Promise.resolve(Promise.all(r)).then(function(r){var t=[];r.forEach(function(e){e&&t.push(Object.assign({},e.payload,{jwt:e.jwt}))}),h.verified=t,h.invalid=e})}}();return y&&y.then?y.then(function(){return h}):h}catch(e){return Promise.reject(e)}},h.prototype.authenticateDisclosureResponse=function(e,r){try{var t=this;return Promise.resolve(d.verifyJWT(e,{audience:t.did,callbackUrl:r,auth:!0})).then(function(e){var r=e.payload,i=e.doc;if(r.req)return Promise.resolve(d.verifyJWT(r.req,{audience:t.did})).then(function(e){var n=e.payload;if(n.type!==l.DISCLOSURE_REQUEST)throw new Error("Challenge payload type invalid: "+n.type);return t.processDisclosurePayload({payload:r,doc:i})});throw new Error("Challenge was not included in response")})}catch(e){return Promise.reject(e)}},h.prototype.verifyDisclosure=function(e){try{var r=this;return Promise.resolve(d.verifyJWT(e,{audience:r.did})).then(function(e){return r.processDisclosurePayload({payload:e.payload,doc:e.doc})})}catch(e){return Promise.reject(e)}},h.prototype.contract=function(e){var r=this;return f(function(e,t){return e.function&&(e.fn=e.function),delete e.function,r.createTxRequest(e,t)}.bind(this))(e)};var y=d.SimpleSigner,E=f,g={Credentials:h,SimpleSigner:y,ContractFactory:E};exports.Credentials=h,exports.SimpleSigner=y,exports.ContractFactory=E,exports.default=g; | ||
//# sourceMappingURL=index.js.map |
@@ -1,2 +0,2 @@ | ||
!function(e,r){"object"==typeof exports&&"undefined"!=typeof module?r(exports,require("elliptic"),require("did-jwt/lib/Digest"),require("uport-did-resolver"),require("ethr-did-resolver"),require("https-did-resolver"),require("uport-lite"),require("mnid"),require("did-jwt")):"function"==typeof define&&define.amd?define(["exports","elliptic","did-jwt/lib/Digest","uport-did-resolver","ethr-did-resolver","https-did-resolver","uport-lite","mnid","did-jwt"],r):r(e.uportCredentials={},e.elliptic,e.Digest,e.UportDIDResolver,e.EthrDIDResolver,e.HttpsDIDResolver,e.UportLite,e.mnid,e.didJwt)}(this,function(e,r,t,i,n,o,a,s,c){var u,d;i=i&&i.hasOwnProperty("default")?i.default:i,n=n&&n.hasOwnProperty("default")?n.default:n,o=o&&o.hasOwnProperty("default")?o.default:o,a=a&&a.hasOwnProperty("default")?a.default:a,function(e){e.Function="function",e.Event="event",e.Constructor="constructor",e.Fallback="fallback"}(u||(u={})),function(e){e.Pure="pure",e.View="view",e.NonPayable="nonpayable",e.Payable="payable"}(d||(d={}));var l,p=function(e,r){for(var t=e.name+"(",i=e.inputs||[],n=0;n<i.length;n++){var o=i[n],a=o.type+" ";t+=a+="string"===o.type?'"'+r[n]+'"':""+r[n],i.length-1!==n&&(t+=", ")}return t+")"},f=function(e){return function(r){return{at:function(t){var i={};return function(e){return e.filter(function(e){return e.type===u.Function&&e.name&&!e.constant})}(r).forEach(function(r){r.name&&(i[r.name]=function(){var i={},n=[].slice.call(arguments),o=(r.inputs||[]).length;(function(e){if("object"!=typeof e)return!1;if(0===Object.keys(e).length)return!0;for(var r=0,t=["from","to","data","value","gasPrice","gas"];r<t.length;r+=1)if(t[r]in e)return!0;return!1})(n[o])&&(i=n.splice(o,1)[0]);var a=Object.assign({},i,{to:t,function:p(r,n)});return e?e(a,n[n.length-1]):a})}),Object.assign({},i,{abi:r,address:t})}}}},v=new r.ec("secp256k1");!function(e){e.DISCLOSURE_REQUEST="shareReq",e.DISCLOSURE_RESPONSE="shareResp",e.TYPED_DATA_SIGNATURE_REQUEST="eip712Req",e.VERIFICATION_SIGNATURE_REQUEST="verReq",e.ETH_TX_REQUEST="ethtx",e.PERSONAL_SIGN_REQUEST="personalSigReq"}(l||(l={}));var h=function(e){var r,u=e.did,d=e.address,l=e.privateKey,p=e.signer,f=e.networks,h=e.registry,y=e.ethrConfig;if(p?this.signer=p:l&&(this.signer=c.SimpleSigner(l)),u)this.did=u;else if(d)s.isMNID(d)&&(this.did="did:uport:"+d),d.match("^0x[0-9a-fA-F]{40}$")&&(this.did="did:ethr:"+d);else if(l){var g=v.keyFromPrivate(l),E=t.toEthereumAddress(g.getPublic("hex"));this.did="did:ethr:"+E}i(h||a({networks:f?(r=f,Object.keys(r).forEach(function(e){var t=r[e];if("object"!=typeof t)throw new Error("Network configuration object required");["registry","rpcUrl"].forEach(function(e){if(!t.hasOwnProperty(e))throw new Error("Malformed network config object, object must have '"+e+"' key specified.")})}),r):{}})),n(y||{}),o()};h.createIdentity=function(){var e=v.genKeyPair(),r=e.getPublic("hex"),i=e.getPrivate("hex");return{did:"did:ethr:"+t.toEthereumAddress(r),privateKey:i}},h.prototype.signJWT=function(e,r){return this.did&&this.signer?c.createJWT(e,{issuer:this.did,signer:this.signer,alg:this.did.match("^did:uport:")||s.isMNID(this.did)?"ES256K":"ES256K-R",expiresIn:r}):Promise.reject(new Error("No Signing Identity configured"))},h.prototype.createDisclosureRequest=function(e,r){void 0===e&&(e={}),void 0===r&&(r=600);var t={};if(e.requested&&(t.requested=e.requested),e.verified&&(t.verified=e.verified),e.claims&&(t.claims=e.claims),e.notifications&&(t.permissions=["notifications"]),e.callbackUrl&&(t.callback=e.callbackUrl),e.networkId&&(t.net=e.networkId),e.rpcUrl){if(!e.networkId)return Promise.reject(new Error("rpcUrl was specified but no networkId"));t.rpc=e.rpcUrl}if(e.vc&&(t.vc=e.vc),e.exp&&(t.exp=e.exp),e.accountType){if(!(["general","segregated","keypair","none"].indexOf(e.accountType)>=0))return Promise.reject(new Error("Unsupported accountType "+e.accountType));t.act=e.accountType}return this.signJWT(Object.assign({},t,{type:l.DISCLOSURE_REQUEST}),e.exp?void 0:r)},h.prototype.createVerification=function(e){return this.signJWT({sub:e.sub,claim:e.claim,exp:e.exp,vc:e.vc,callbackUrl:e.callbackUrl})},h.prototype.createVerificationSignatureRequest=function(e,r){return this.signJWT({unsignedClaim:e,sub:r.sub,riss:r.riss,aud:r.aud,vc:r.vc,callback:r.callbackUrl,type:l.VERIFICATION_SIGNATURE_REQUEST,rexp:r.rexp},r.expiresIn)},h.prototype.createTypedDataSignatureRequest=function(e,r){void 0===r&&(r={});var t=r.from,i=r.net,n=r.callback;try{for(var o=0,a=["types","primaryType","message","domain"];o<a.length;o+=1){var s=a[o];if(!e[s])throw new Error("Invalid EIP712 Request, must include '"+s+"'")}return Promise.resolve(this.signJWT({typedData:e,from:t,net:i,callback:n,type:l.TYPED_DATA_SIGNATURE_REQUEST}))}catch(e){return Promise.reject(e)}},h.prototype.createPersonalSignRequest=function(e,r){return void 0===r&&(r={}),this.signJWT({data:e,from:r.from,net:r.net,callback:r.callback,type:l.PERSONAL_SIGN_REQUEST})},h.prototype.createTxRequest=function(e,r){void 0===r&&(r={});var t=r.callbackUrl,i=r.exp;void 0===i&&(i=600);var n=r.networkId,o=r.label,a={};return t&&(a.callback=t),n&&(a.net=n),o&&(a.label=o),this.signJWT(Object.assign({},a,e,{type:l.ETH_TX_REQUEST}),i)},h.prototype.createDisclosureResponse=function(e,r){void 0===e&&(e={}),void 0===r&&(r=600);try{var t=this;function i(){return t.signJWT(Object.assign({},e,{type:l.DISCLOSURE_RESPONSE}),r)}var n=function(){if(e.req)return Promise.resolve(c.verifyJWT(e.req)).then(function(r){r.issuer&&(e.aud=r.issuer)})}();return n&&n.then?n.then(i):i()}catch(e){return Promise.reject(e)}},h.prototype.processDisclosurePayload=function(e){var r=e.doc,t=e.payload;try{var i=this,n=t.own;void 0===n&&(n={});var o=t.capabilities;void 0===o&&(o=[]);var a=t.nad,u=t.dad,d=t.iss,l=t.boxPub,p=t.verified,f=function(e,r){var t={};for(var i in e)Object.prototype.hasOwnProperty.call(e,i)&&-1===r.indexOf(i)&&(t[i]=e[i]);return t}(t,["own","capabilities","aud","req","iat","exp","type","nad","dad","iss","boxPub","verified"]),v=r.uportProfile;void 0===v&&(v={});var h=Object.assign({},{did:d,boxPub:l},n,v,f);u&&(h.deviceKey=u),a&&(h.mnid=a,h.address=s.decode(a).address),1===o.length&&(h.pushToken=o[0]);var y=function(){if(p){var e=[],r=p.map(function(r){return c.verifyJWT(r,{audience:i.did}).catch(function(){return e.push(r),Promise.resolve(void 0)})});return Promise.resolve(Promise.all(r)).then(function(r){var t=[];r.forEach(function(e){e&&t.push(Object.assign({},e.payload,{jwt:e.jwt}))}),h.verified=t,h.invalid=e})}}();return y&&y.then?y.then(function(){return h}):h}catch(e){return Promise.reject(e)}},h.prototype.authenticateDisclosureResponse=function(e,r){try{var t=this;return Promise.resolve(c.verifyJWT(e,{audience:t.did,callbackUrl:r,auth:!0})).then(function(e){var r=e.payload,i=e.doc;if(r.req)return Promise.resolve(c.verifyJWT(r.req,{audience:t.did})).then(function(e){var n=e.payload;if(n.type!==l.DISCLOSURE_REQUEST)throw new Error("Challenge payload type invalid: "+n.type);return t.processDisclosurePayload({payload:r,doc:i})});throw new Error("Challenge was not included in response")})}catch(e){return Promise.reject(e)}},h.prototype.verifyDisclosure=function(e){try{var r=this;return Promise.resolve(c.verifyJWT(e,{audience:r.did})).then(function(e){return r.processDisclosurePayload({payload:e.payload,doc:e.doc})})}catch(e){return Promise.reject(e)}},h.prototype.contract=function(e){var r=this;return f(function(e,t){return e.function&&(e.fn=e.function),delete e.function,r.createTxRequest(e,t)}.bind(this))(e)};var y=c.SimpleSigner,g=f,E={Credentials:h,SimpleSigner:y,ContractFactory:g};e.Credentials=h,e.SimpleSigner=y,e.ContractFactory=g,e.default=E}); | ||
!function(e,r){"object"==typeof exports&&"undefined"!=typeof module?r(exports,require("elliptic"),require("did-jwt/lib/index"),require("uport-did-resolver"),require("ethr-did-resolver"),require("https-did-resolver"),require("uport-lite"),require("mnid"),require("did-jwt")):"function"==typeof define&&define.amd?define(["exports","elliptic","did-jwt/lib/index","uport-did-resolver","ethr-did-resolver","https-did-resolver","uport-lite","mnid","did-jwt"],r):r(e.uportCredentials={},e.elliptic,e.index,e.UportDIDResolver,e.EthrDIDResolver,e.HttpsDIDResolver,e.UportLite,e.mnid,e.didJwt)}(this,function(e,r,t,i,n,o,a,c,s){var u,d;i=i&&i.hasOwnProperty("default")?i.default:i,n=n&&n.hasOwnProperty("default")?n.default:n,o=o&&o.hasOwnProperty("default")?o.default:o,a=a&&a.hasOwnProperty("default")?a.default:a,function(e){e.Function="function",e.Event="event",e.Constructor="constructor",e.Fallback="fallback"}(u||(u={})),function(e){e.Pure="pure",e.View="view",e.NonPayable="nonpayable",e.Payable="payable"}(d||(d={}));var l,p=function(e,r){for(var t=e.name+"(",i=e.inputs||[],n=0;n<i.length;n++){var o=i[n],a=o.type+" ";t+=a+="string"===o.type?'"'+r[n]+'"':""+r[n],i.length-1!==n&&(t+=", ")}return t+")"},f=function(e){return function(r){return{at:function(t){var i={};return function(e){return e.filter(function(e){return e.type===u.Function&&e.name&&!e.constant})}(r).forEach(function(r){r.name&&(i[r.name]=function(){var i={},n=[].slice.call(arguments),o=(r.inputs||[]).length;(function(e){if("object"!=typeof e)return!1;if(0===Object.keys(e).length)return!0;for(var r=0,t=["from","to","data","value","gasPrice","gas"];r<t.length;r+=1)if(t[r]in e)return!0;return!1})(n[o])&&(i=n.splice(o,1)[0]);var a=Object.assign({},i,{to:t,function:p(r,n)});return e?e(a,n[n.length-1]):a})}),Object.assign({},i,{abi:r,address:t})}}}},v=new r.ec("secp256k1");!function(e){e.DISCLOSURE_REQUEST="shareReq",e.DISCLOSURE_RESPONSE="shareResp",e.TYPED_DATA_SIGNATURE_REQUEST="eip712Req",e.VERIFICATION_SIGNATURE_REQUEST="verReq",e.ETH_TX_REQUEST="ethtx",e.PERSONAL_SIGN_REQUEST="personalSigReq"}(l||(l={}));var h=function(e){var r,u=e.did,d=e.address,l=e.privateKey,p=e.signer,f=e.networks,h=e.registry,y=e.ethrConfig;if(p?this.signer=p:l&&(this.signer=s.SimpleSigner(l)),u)this.did=u;else if(d)c.isMNID(d)&&(this.did="did:uport:"+d),d.match("^0x[0-9a-fA-F]{40}$")&&(this.did="did:ethr:"+d);else if(l){var E=v.keyFromPrivate(l),g=t.toEthereumAddress(E.getPublic("hex"));this.did="did:ethr:"+g}i(h||a({networks:f?(r=f,Object.keys(r).forEach(function(e){var t=r[e];if("object"!=typeof t)throw new Error("Network configuration object required");["registry","rpcUrl"].forEach(function(e){if(!t.hasOwnProperty(e))throw new Error("Malformed network config object, object must have '"+e+"' key specified.")})}),r):{}})),n(y||{}),o()};h.createIdentity=function(){var e=v.genKeyPair(),r=e.getPublic("hex"),i=e.getPrivate("hex");return{did:"did:ethr:"+t.toEthereumAddress(r),privateKey:i}},h.prototype.signJWT=function(e,r){return this.did&&this.signer?s.createJWT(e,{issuer:this.did,signer:this.signer,alg:this.did.match("^did:uport:")||c.isMNID(this.did)?"ES256K":"ES256K-R",expiresIn:r}):Promise.reject(new Error("No Signing Identity configured"))},h.prototype.createDisclosureRequest=function(e,r){void 0===e&&(e={}),void 0===r&&(r=600);var t={};if(e.requested&&(t.requested=e.requested),e.verified&&(t.verified=e.verified),e.claims&&(t.claims=e.claims),e.notifications&&(t.permissions=["notifications"]),e.callbackUrl&&(t.callback=e.callbackUrl),e.networkId&&(t.net=e.networkId),e.rpcUrl){if(!e.networkId)return Promise.reject(new Error("rpcUrl was specified but no networkId"));t.rpc=e.rpcUrl}if(e.vc&&(t.vc=e.vc),e.exp&&(t.exp=e.exp),e.accountType){if(!(["general","segregated","keypair","none"].indexOf(e.accountType)>=0))return Promise.reject(new Error("Unsupported accountType "+e.accountType));t.act=e.accountType}return this.signJWT(Object.assign({},t,{type:l.DISCLOSURE_REQUEST}),e.exp?void 0:r)},h.prototype.createVerification=function(e){return this.signJWT({sub:e.sub,claim:e.claim,exp:e.exp,vc:e.vc,callbackUrl:e.callbackUrl})},h.prototype.createVerificationSignatureRequest=function(e,r){return this.signJWT({unsignedClaim:e,sub:r.sub,riss:r.riss,aud:r.aud,vc:r.vc,callback:r.callbackUrl,type:l.VERIFICATION_SIGNATURE_REQUEST,rexp:r.rexp},r.expiresIn)},h.prototype.createTypedDataSignatureRequest=function(e,r){void 0===r&&(r={});var t=r.from,i=r.net,n=r.callback;try{for(var o=0,a=["types","primaryType","message","domain"];o<a.length;o+=1){var c=a[o];if(!e[c])throw new Error("Invalid EIP712 Request, must include '"+c+"'")}return Promise.resolve(this.signJWT({typedData:e,from:t,net:i,callback:n,type:l.TYPED_DATA_SIGNATURE_REQUEST}))}catch(e){return Promise.reject(e)}},h.prototype.createPersonalSignRequest=function(e,r){return void 0===r&&(r={}),this.signJWT({data:e,from:r.from,net:r.net,callback:r.callback,type:l.PERSONAL_SIGN_REQUEST})},h.prototype.createTxRequest=function(e,r){void 0===r&&(r={});var t=r.callbackUrl,i=r.exp;void 0===i&&(i=600);var n=r.networkId,o=r.label,a={};return t&&(a.callback=t),n&&(a.net=n),o&&(a.label=o),this.signJWT(Object.assign({},a,e,{type:l.ETH_TX_REQUEST}),i)},h.prototype.createDisclosureResponse=function(e,r){void 0===e&&(e={}),void 0===r&&(r=600);try{var t=this;function i(){return t.signJWT(Object.assign({},e,{type:l.DISCLOSURE_RESPONSE}),r)}var n=function(){if(e.req)return Promise.resolve(s.verifyJWT(e.req)).then(function(r){r.issuer&&(e.aud=r.issuer)})}();return n&&n.then?n.then(i):i()}catch(e){return Promise.reject(e)}},h.prototype.processDisclosurePayload=function(e){var r=e.doc,t=e.payload;try{var i=this,n=t.own;void 0===n&&(n={});var o=t.capabilities;void 0===o&&(o=[]);var a=t.nad,u=t.dad,d=t.iss,l=t.boxPub,p=t.verified,f=function(e,r){var t={};for(var i in e)Object.prototype.hasOwnProperty.call(e,i)&&-1===r.indexOf(i)&&(t[i]=e[i]);return t}(t,["own","capabilities","aud","req","iat","exp","type","nad","dad","iss","boxPub","verified"]),v=r.uportProfile;void 0===v&&(v={});var h=Object.assign({},{did:d,boxPub:l},n,v,f);u&&(h.deviceKey=u),a&&(h.mnid=a,h.address=c.decode(a).address),1===o.length&&(h.pushToken=o[0]);var y=function(){if(p){var e=[],r=p.map(function(r){return s.verifyJWT(r,{audience:i.did}).catch(function(){return e.push(r),Promise.resolve(void 0)})});return Promise.resolve(Promise.all(r)).then(function(r){var t=[];r.forEach(function(e){e&&t.push(Object.assign({},e.payload,{jwt:e.jwt}))}),h.verified=t,h.invalid=e})}}();return y&&y.then?y.then(function(){return h}):h}catch(e){return Promise.reject(e)}},h.prototype.authenticateDisclosureResponse=function(e,r){try{var t=this;return Promise.resolve(s.verifyJWT(e,{audience:t.did,callbackUrl:r,auth:!0})).then(function(e){var r=e.payload,i=e.doc;if(r.req)return Promise.resolve(s.verifyJWT(r.req,{audience:t.did})).then(function(e){var n=e.payload;if(n.type!==l.DISCLOSURE_REQUEST)throw new Error("Challenge payload type invalid: "+n.type);return t.processDisclosurePayload({payload:r,doc:i})});throw new Error("Challenge was not included in response")})}catch(e){return Promise.reject(e)}},h.prototype.verifyDisclosure=function(e){try{var r=this;return Promise.resolve(s.verifyJWT(e,{audience:r.did})).then(function(e){return r.processDisclosurePayload({payload:e.payload,doc:e.doc})})}catch(e){return Promise.reject(e)}},h.prototype.contract=function(e){var r=this;return f(function(e,t){return e.function&&(e.fn=e.function),delete e.function,r.createTxRequest(e,t)}.bind(this))(e)};var y=s.SimpleSigner,E=f,g={Credentials:h,SimpleSigner:y,ContractFactory:E};e.Credentials=h,e.SimpleSigner=y,e.ContractFactory=E,e.default=g}); | ||
//# sourceMappingURL=index.umd.js.map |
{ | ||
"name": "uport-credentials", | ||
"version": "1.2.1", | ||
"version": "1.2.2-alpha.0", | ||
"description": "Library for interacting with uport profiles and attestations", | ||
@@ -32,3 +32,3 @@ "main": "lib/index.js", | ||
"dependencies": { | ||
"did-jwt": "^0.1.3", | ||
"did-jwt": "^0.2.0-alpha.0", | ||
"did-resolver": "^0.0.6", | ||
@@ -89,2 +89,2 @@ "elliptic": "^6.4.1", | ||
} | ||
} | ||
} |
import { ec as EC } from 'elliptic' | ||
import { createJWT, verifyJWT, SimpleSigner, DIDDocument } from 'did-jwt' | ||
import { toEthereumAddress } from 'did-jwt/lib/Digest' | ||
import { toEthereumAddress } from 'did-jwt/lib/index' | ||
import UportDIDResolver from 'uport-did-resolver' | ||
@@ -6,0 +6,0 @@ import EthrDIDResolver from 'ethr-did-resolver' |
@@ -1,87 +0,1 @@ | ||
declare module 'did-jwt' { | ||
export interface DIDDocument { | ||
'@context': 'https://w3id.org/did/v1'; | ||
id: string; | ||
publicKey: PublicKey[]; | ||
authentication?: Authentication[]; | ||
uportProfile?: any; | ||
service?: ServiceEndpoint[]; | ||
} | ||
export interface ServiceEndpoint { | ||
id: string; | ||
type: string; | ||
serviceEndpoint: string; | ||
description?: string; | ||
} | ||
export interface PublicKey { | ||
id: string; | ||
type: string; | ||
owner: string; | ||
ethereumAddress?: string; | ||
publicKeyBase64?: string; | ||
publicKeyBase58?: string; | ||
publicKeyHex?: string; | ||
publicKeyPem?: string; | ||
} | ||
export interface Authentication { | ||
type: string; | ||
publicKey: string; | ||
} | ||
interface EcdsaSignature { | ||
r: string, | ||
s: string, | ||
recoveryParam: number | ||
} | ||
interface JWTOptions { | ||
issuer: string, | ||
signer: (data: string) => Promise<EcdsaSignature>, | ||
alg?: string, | ||
expiresIn?: number | ||
} | ||
interface JWTVerifyOptions { | ||
auth?: boolean, | ||
audience?: string, | ||
callbackUrl?: string | ||
} | ||
interface Verified { | ||
payload: any, | ||
doc: DIDDocument, | ||
issuer: string, | ||
signer: object, | ||
jwt: string | ||
} | ||
interface JWTPayload { | ||
iss?: string | ||
sub?: string | ||
aud?: string | ||
iat?: number | ||
type?: string | ||
exp?: number | ||
rexp?: number | ||
} | ||
interface JWTHeader { | ||
alg: string | ||
type: 'JWT' | ||
} | ||
interface JWTDecoded { | ||
header: JWTHeader | ||
payload: JWTPayload | ||
signature: string | ||
data: string | ||
} | ||
export function SimpleSigner(hexPrivateKey: string): (data: string) => Promise<EcdsaSignature> | ||
export function createJWT(payload: object, options: JWTOptions): Promise<string> | ||
export function verifyJWT(jwt: string, options?: JWTVerifyOptions): Promise<Verified> | ||
export function decodeJWT(jwt: string): JWTDecoded | ||
} | ||
declare module 'did-jwt/lib/Digest' { | ||
export function toEthereumAddress( hexPublicKey: string ): string | ||
} | ||
declare module 'mnid' { | ||
@@ -88,0 +2,0 @@ interface NetworkAddress { |
Sorry, the diff of this file is too big to display
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
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
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
888986
35
5866
4
4
+ Added@stablelib/utf8@0.10.1(transitive)
+ Addeddid-jwt@0.2.0(transitive)
+ Addeduport-base64url@3.0.2-alpha.0(transitive)
- Removedbase64url@3.0.1(transitive)
- Removeddid-jwt@0.1.3(transitive)
- Removedtweetnacl-util@0.15.1(transitive)
Updateddid-jwt@^0.2.0-alpha.0