uport-credentials
Advanced tools
Comparing version 1.2.0-alpha1 to 1.2.0-alpha2
@@ -1,2 +0,2 @@ | ||
import{ec as e}from"elliptic";import r from"uport-did-resolver";import t from"ethr-did-resolver";import n from"https-did-resolver";import i from"uport-lite";import{isMNID as o,decode as a}from"mnid";import{createJWT as s,verifyJWT as c,SimpleSigner as u,toEthereumAddress as d}from"did-jwt";var l=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},p=function(e){return e.filter(function(e){return("function"===e.type||"event"===e.type)&&e.name.length>0})},f=function(e,r){for(var t=e.name+"(",n=0;n<e.inputs.length;n++){var i=e.inputs[n],o=i.type+" ";t+=o+="string"===i.type?'"'+r[n]+'"':""+r[n],e.inputs.length-1!==n&&(t+=", ")}return t+")"},v=function(e){return function(r){var t={at:function(t){return new function(){var n=this;n.abi=r||[],n.address=t||"0x",p(r).forEach(function(r){n[r.name]=function(){if(!0===r.constant)throw new Error("A call does not return the txobject, no transaction necessary.");if("event"===r.type)throw new Error("An event does not return the txobject, events not supported");var t={},i=[].slice.call(arguments),o=r.inputs.length;if("function"===r.type){l(i[o])&&(t=i.splice(o,1)[0]);var a=Object.assign({},t,{to:n.address,function:f(r,i)});if(!e)return a;var s=i.slice(o);return e.apply(void 0,[a].concat(s))}}})}}};return t}};var h=new e("secp256k1"),y={DISCLOSURE_REQUEST:"shareReq",DISCLOSURE_RESPONSE:"shareResp",TYPED_DATA_SIGNATURE_REQUEST:"eip712Req",VERIFICATION_SIGNATURE_REQUEST:"verReq",ETH_TX_REQUEST:"ethtx",PERSONAL_SIGN_REQUEST:"personalSigReq"},E=function(e){var a=this;void 0===e&&(e={});var c=e.did,l=e.address,p=e.privateKey,f=e.signer,v=e.networks,y=e.registry,E=e.ethrConfig;if(f?this.signer=f:p&&(this.signer=u(p)),c)this.did=c;else if(l)o(l)&&(this.did="did:uport:"+l),l.match("^0x[0-9a-fA-F]{40}$")&&(this.did="did:ethr:"+l);else if(p){var g=h.keyFromPrivate(p),b=d(g.getPublic("hex"));this.did="did:ethr:"+b}this.signJWT=function(e,r){return s(e,{issuer:a.did,signer:a.signer,alg:a.did.match("^did:uport:")||o(a.did)?"ES256K":"ES256K-R",expiresIn:r})},r(y||i({networks:v?m(v):{}})),t(E||{}),n()};E.createIdentity=function(){var e=h.genKeyPair(),r=e.getPublic("hex"),t=e.getPrivate("hex");return{did:"did:ethr:"+d(r),privateKey:t}},E.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.notifications&&(t.permissions=["notifications"]),e.callbackUrl&&(t.callback=e.callbackUrl),e.network_id&&(t.net=e.network_id),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:y.DISCLOSURE_REQUEST}),e.exp?void 0:r)},E.prototype.createVerification=function(e){return this.signJWT({sub:e.sub,claim:e.claim,exp:e.exp,vc:e.vc})},E.prototype.createVerificationSignatureRequest=function(e,r){return void 0===r&&(r={}),this.signJWT({unsignedClaim:e,sub:r.sub,riss:r.riss,aud:r.aud,vc:r.vc,callback:r.callbackUrl,type:y.VERIFICATION_SIGNATURE_REQUEST},r.expiresIn)},E.prototype.createTypedDataSignatureRequest=function(e,r){void 0===r&&(r={});for(var t=r.from,n=r.net,i=r.callback,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 this.signJWT({typedData:e,from:t,net:n,callback:i,type:y.TYPED_DATA_SIGNATURE_REQUEST})},E.prototype.createPersonalSignRequest=function(e,r){return void 0===r&&(r={}),this.signJWT({data:e,from:r.from,net:r.net,callback:r.callback,type:y.PERSONAL_SIGN_REQUEST})},E.prototype.createTxRequest=function(e,r){void 0===r&&(r={});var t=r.callbackUrl,n=r.exp;void 0===n&&(n=600);var i=r.networkId,o=r.label,a={};return t&&(a.callback=t),i&&(a.net=i),o&&(a.label=o),this.signJWT(Object.assign({},a,e,{type:y.ETH_TX_REQUEST}),n)},E.prototype.createDisclosureResponse=function(e,r){void 0===e&&(e={}),void 0===r&&(r=600);try{var t=this;function n(){return t.signJWT(Object.assign({},e,{type:y.DISCLOSURE_RESPONSE}),r)}var i=function(){if(e.req)return Promise.resolve(c(e.req)).then(function(r){r.issuer&&(e.aud=r.issuer)})}();return i&&i.then?i.then(n):n()}catch(e){return Promise.reject(e)}},E.prototype.processDisclosurePayload=function(e){var r=e.doc,t=e.payload;try{var n=this,i=t.own;void 0===i&&(i={});var o=t.capabilities;void 0===o&&(o=[]);var s=t.nad,u=t.dad,d=t.iss,l=t.boxPub,p=t.verified,f=function(e,r){var t={};for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&-1===r.indexOf(n)&&(t[n]=e[n]);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},i,v,f);u&&(h.deviceKey=u),s&&(h.mnid=s,h.address=a(s).address),1===o.length&&(h.pushToken=o[0]);var y=function(){if(p){var e=[],r=p.map(function(r){return c(r,{audience:n.did}).catch(function(){return e.push(r),Promise.resolve(null)})});return Promise.resolve(Promise.all(r)).then(function(r){h.verified=r.map(function(e){return e?Object.assign({},e.payload,{jwt:e.jwt}):null}).reduce(function(e,r){return r?e.concat([r]):e},[]),h.invalid=e})}}();return y&&y.then?y.then(function(){return h}):h}catch(e){return Promise.reject(e)}},E.prototype.authenticateDisclosureResponse=function(e,r){void 0===r&&(r=null);try{var t=this;return Promise.resolve(c(e,{audience:t.did,callbackUrl:r,auth:!0})).then(function(e){var r=e.payload,n=e.doc;if(r.req)return Promise.resolve(c(r.req)).then(function(e){if(e.payload.iss!==t.did)throw new Error("Challenge issuer does not match current identity: "+e.payload.iss+" !== "+t.did);if(e.payload.type!==y.DISCLOSURE_REQUEST)throw new Error("Challenge payload type invalid: "+e.payload.type);return t.processDisclosurePayload({payload:r,doc:n})});throw new Error("Challenge was not included in response")})}catch(e){return Promise.reject(e)}},E.prototype.verifyDisclosure=function(e){try{var r=this;return Promise.resolve(c(e,{audience:r.did})).then(function(e){return r.processDisclosurePayload({payload:e.payload,doc:e.doc})})}catch(e){return Promise.reject(e)}},E.prototype.contract=function(e){var r=this;return v(function(e,t){return e.function&&(e.fn=e.function),delete e.function,r.createTxRequest(e,t)}.bind(this))(e)};var m=function(e){return Object.keys(e).forEach(function(r){var t=e[r];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.")})}),e};module.exports={Credentials:E,SimpleSigner:u,ContractFactory:v}; | ||
import{ec as e}from"elliptic";import r from"uport-did-resolver";import t from"ethr-did-resolver";import n from"https-did-resolver";import i from"uport-lite";import{isMNID as o,decode as a}from"mnid";import{createJWT as c,verifyJWT as s,SimpleSigner as u,toEthereumAddress as d}from"did-jwt";var l=new e("secp256k1"),p={DISCLOSURE_REQUEST:"shareReq",DISCLOSURE_RESPONSE:"shareResp",TYPED_DATA_SIGNATURE_REQUEST:"eip712Req",VERIFICATION_SIGNATURE_REQUEST:"verReq",ETH_TX_REQUEST:"ethtx",PERSONAL_SIGN_REQUEST:"personalSigReq"},f=function(e){var a=this;void 0===e&&(e={});var s=e.did,p=e.address,f=e.privateKey,h=e.signer,y=e.networks,E=e.registry,m=e.ethrConfig;if(h?this.signer=h:f&&(this.signer=u(f)),s)this.did=s;else if(p)o(p)&&(this.did="did:uport:"+p),p.match("^0x[0-9a-fA-F]{40}$")&&(this.did="did:ethr:"+p);else if(f){var g=l.keyFromPrivate(f),b=d(g.getPublic("hex"));this.did="did:ethr:"+b}this.signJWT=function(e,r){return c(e,{issuer:a.did,signer:a.signer,alg:a.did.match("^did:uport:")||o(a.did)?"ES256K":"ES256K-R",expiresIn:r})},r(E||i({networks:y?v(y):{}})),t(m||{}),n()};f.createIdentity=function(){var e=l.genKeyPair(),r=e.getPublic("hex"),t=e.getPrivate("hex");return{did:"did:ethr:"+d(r),privateKey:t}},f.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.notifications&&(t.permissions=["notifications"]),e.callbackUrl&&(t.callback=e.callbackUrl),e.network_id&&(t.net=e.network_id),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:p.DISCLOSURE_REQUEST}),e.exp?void 0:r)},f.prototype.createVerification=function(e){return this.signJWT({sub:e.sub,claim:e.claim,exp:e.exp,vc:e.vc})},f.prototype.createVerificationSignatureRequest=function(e,r){return void 0===r&&(r={}),this.signJWT({unsignedClaim:e,sub:r.sub,riss:r.riss,aud:r.aud,vc:r.vc,callback:r.callbackUrl,type:p.VERIFICATION_SIGNATURE_REQUEST},r.expiresIn)},f.prototype.createTypedDataSignatureRequest=function(e,r){void 0===r&&(r={});for(var t=r.from,n=r.net,i=r.callback,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 this.signJWT({typedData:e,from:t,net:n,callback:i,type:p.TYPED_DATA_SIGNATURE_REQUEST})},f.prototype.createPersonalSignRequest=function(e,r){return void 0===r&&(r={}),this.signJWT({data:e,from:r.from,net:r.net,callback:r.callback,type:p.PERSONAL_SIGN_REQUEST})},f.prototype.createTxRequest=function(e,r){void 0===r&&(r={});var t=r.callbackUrl,n=r.exp;void 0===n&&(n=600);var i=r.networkId,o=r.label,a={};return t&&(a.callback=t),i&&(a.net=i),o&&(a.label=o),this.signJWT(Object.assign({},a,e,{type:p.ETH_TX_REQUEST}),n)},f.prototype.createDisclosureResponse=function(e,r){void 0===e&&(e={}),void 0===r&&(r=600);try{var t=this;function n(){return t.signJWT(Object.assign({},e,{type:p.DISCLOSURE_RESPONSE}),r)}var i=function(){if(e.req)return Promise.resolve(s(e.req)).then(function(r){r.issuer&&(e.aud=r.issuer)})}();return i&&i.then?i.then(n):n()}catch(e){return Promise.reject(e)}},f.prototype.processDisclosurePayload=function(e){var r=e.doc,t=e.payload;try{var n=this,i=t.own;void 0===i&&(i={});var o=t.capabilities;void 0===o&&(o=[]);var c=t.nad,u=t.dad,d=t.iss,l=t.boxPub,p=t.verified,f=function(e,r){var t={};for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&-1===r.indexOf(n)&&(t[n]=e[n]);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},i,v,f);u&&(h.deviceKey=u),c&&(h.mnid=c,h.address=a(c).address),1===o.length&&(h.pushToken=o[0]);var y=function(){if(p){var e=[],r=p.map(function(r){return s(r,{audience:n.did}).catch(function(){return e.push(r),Promise.resolve(null)})});return Promise.resolve(Promise.all(r)).then(function(r){h.verified=r.map(function(e){return e?Object.assign({},e.payload,{jwt:e.jwt}):null}).reduce(function(e,r){return r?e.concat([r]):e},[]),h.invalid=e})}}();return y&&y.then?y.then(function(){return h}):h}catch(e){return Promise.reject(e)}},f.prototype.authenticateDisclosureResponse=function(e,r){void 0===r&&(r=null);try{var t=this;return Promise.resolve(s(e,{audience:t.did,callbackUrl:r,auth:!0})).then(function(e){var r=e.payload,n=e.doc;if(r.req)return Promise.resolve(s(r.req)).then(function(e){if(e.payload.iss!==t.did)throw new Error("Challenge issuer does not match current identity: "+e.payload.iss+" !== "+t.did);if(e.payload.type!==p.DISCLOSURE_REQUEST)throw new Error("Challenge payload type invalid: "+e.payload.type);return t.processDisclosurePayload({payload:r,doc:n})});throw new Error("Challenge was not included in response")})}catch(e){return Promise.reject(e)}},f.prototype.verifyDisclosure=function(e){try{var r=this;return Promise.resolve(s(e,{audience:r.did})).then(function(e){return r.processDisclosurePayload({payload:e.payload,doc:e.doc})})}catch(e){return Promise.reject(e)}};var v=function(e){return Object.keys(e).forEach(function(r){var t=e[r];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.")})}),e},h=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},y=function(e){return e.filter(function(e){return("function"===e.type||"event"===e.type)&&e.name.length>0})},E=function(e,r){for(var t=e.name+"(",n=0;n<e.inputs.length;n++){var i=e.inputs[n],o=i.type+" ";t+=o+="string"===i.type?'"'+r[n]+'"':""+r[n],e.inputs.length-1!==n&&(t+=", ")}return t+")"},m=function(e){return function(r){var t={at:function(t){return new function(){var n=this;n.abi=r||[],n.address=t||"0x",y(r).forEach(function(r){n[r.name]=function(){if(!0===r.constant)throw new Error("A call does not return the txobject, no transaction necessary.");if("event"===r.type)throw new Error("An event does not return the txobject, events not supported");var t={},i=[].slice.call(arguments),o=r.inputs.length;if("function"===r.type){h(i[o])&&(t=i.splice(o,1)[0]);var a=Object.assign({},t,{to:n.address,function:E(r,i)});if(!e)return a;var c=i.slice(o);return e.apply(void 0,[a].concat(c))}}})}}};return t}};module.exports={Credentials:f,SimpleSigner:u,ContractFactory:m,createContract:function(e,r){return m(function(r,t){return r.function&&(r.fn=r.function),delete r.function,e.createTxRequest(r,t)})(r)}}; | ||
//# sourceMappingURL=index.esm.js.map |
@@ -1,2 +0,2 @@ | ||
function e(e){return e&&"object"==typeof e&&"default"in e?e.default:e}var r=require("elliptic"),t=e(require("uport-did-resolver")),i=e(require("ethr-did-resolver")),n=e(require("https-did-resolver")),o=e(require("uport-lite")),a=require("mnid"),s=require("did-jwt"),c=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},u=function(e){return e.filter(function(e){return("function"===e.type||"event"===e.type)&&e.name.length>0})},d=function(e,r){for(var t=e.name+"(",i=0;i<e.inputs.length;i++){var n=e.inputs[i],o=n.type+" ";t+=o+="string"===n.type?'"'+r[i]+'"':""+r[i],e.inputs.length-1!==i&&(t+=", ")}return t+")"},l=function(e){return function(r){var t={at:function(t){return new function(){var i=this;i.abi=r||[],i.address=t||"0x",u(r).forEach(function(r){i[r.name]=function(){if(!0===r.constant)throw new Error("A call does not return the txobject, no transaction necessary.");if("event"===r.type)throw new Error("An event does not return the txobject, events not supported");var t={},n=[].slice.call(arguments),o=r.inputs.length;if("function"===r.type){c(n[o])&&(t=n.splice(o,1)[0]);var a=Object.assign({},t,{to:i.address,function:d(r,n)});if(!e)return a;var s=n.slice(o);return e.apply(void 0,[a].concat(s))}}})}}};return t}};var p=new r.ec("secp256k1"),f={DISCLOSURE_REQUEST:"shareReq",DISCLOSURE_RESPONSE:"shareResp",TYPED_DATA_SIGNATURE_REQUEST:"eip712Req",VERIFICATION_SIGNATURE_REQUEST:"verReq",ETH_TX_REQUEST:"ethtx",PERSONAL_SIGN_REQUEST:"personalSigReq"},v=function(e){var r=this;void 0===e&&(e={});var c=e.did,u=e.address,d=e.privateKey,l=e.signer,f=e.networks,v=e.registry,y=e.ethrConfig;if(l?this.signer=l:d&&(this.signer=s.SimpleSigner(d)),c)this.did=c;else if(u)a.isMNID(u)&&(this.did="did:uport:"+u),u.match("^0x[0-9a-fA-F]{40}$")&&(this.did="did:ethr:"+u);else if(d){var E=p.keyFromPrivate(d),g=s.toEthereumAddress(E.getPublic("hex"));this.did="did:ethr:"+g}this.signJWT=function(e,t){return s.createJWT(e,{issuer:r.did,signer:r.signer,alg:r.did.match("^did:uport:")||a.isMNID(r.did)?"ES256K":"ES256K-R",expiresIn:t})},t(v||o({networks:f?h(f):{}})),i(y||{}),n()};v.createIdentity=function(){var e=p.genKeyPair(),r=e.getPublic("hex"),t=e.getPrivate("hex");return{did:"did:ethr:"+s.toEthereumAddress(r),privateKey:t}},v.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.notifications&&(t.permissions=["notifications"]),e.callbackUrl&&(t.callback=e.callbackUrl),e.network_id&&(t.net=e.network_id),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:f.DISCLOSURE_REQUEST}),e.exp?void 0:r)},v.prototype.createVerification=function(e){return this.signJWT({sub:e.sub,claim:e.claim,exp:e.exp,vc:e.vc})},v.prototype.createVerificationSignatureRequest=function(e,r){return void 0===r&&(r={}),this.signJWT({unsignedClaim:e,sub:r.sub,riss:r.riss,aud:r.aud,vc:r.vc,callback:r.callbackUrl,type:f.VERIFICATION_SIGNATURE_REQUEST},r.expiresIn)},v.prototype.createTypedDataSignatureRequest=function(e,r){void 0===r&&(r={});for(var t=r.from,i=r.net,n=r.callback,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 this.signJWT({typedData:e,from:t,net:i,callback:n,type:f.TYPED_DATA_SIGNATURE_REQUEST})},v.prototype.createPersonalSignRequest=function(e,r){return void 0===r&&(r={}),this.signJWT({data:e,from:r.from,net:r.net,callback:r.callback,type:f.PERSONAL_SIGN_REQUEST})},v.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:f.ETH_TX_REQUEST}),i)},v.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:f.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)}},v.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 c=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),c&&(h.mnid=c,h.address=a.decode(c).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(null)})});return Promise.resolve(Promise.all(r)).then(function(r){h.verified=r.map(function(e){return e?Object.assign({},e.payload,{jwt:e.jwt}):null}).reduce(function(e,r){return r?e.concat([r]):e},[]),h.invalid=e})}}();return y&&y.then?y.then(function(){return h}):h}catch(e){return Promise.reject(e)}},v.prototype.authenticateDisclosureResponse=function(e,r){void 0===r&&(r=null);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)).then(function(e){if(e.payload.iss!==t.did)throw new Error("Challenge issuer does not match current identity: "+e.payload.iss+" !== "+t.did);if(e.payload.type!==f.DISCLOSURE_REQUEST)throw new Error("Challenge payload type invalid: "+e.payload.type);return t.processDisclosurePayload({payload:r,doc:i})});throw new Error("Challenge was not included in response")})}catch(e){return Promise.reject(e)}},v.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)}},v.prototype.contract=function(e){var r=this;return l(function(e,t){return e.function&&(e.fn=e.function),delete e.function,r.createTxRequest(e,t)}.bind(this))(e)};var h=function(e){return Object.keys(e).forEach(function(r){var t=e[r];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.")})}),e};module.exports={Credentials:v,SimpleSigner:s.SimpleSigner,ContractFactory:l}; | ||
function e(e){return e&&"object"==typeof e&&"default"in e?e.default:e}var r=require("elliptic"),t=e(require("uport-did-resolver")),n=e(require("ethr-did-resolver")),i=e(require("https-did-resolver")),o=e(require("uport-lite")),a=require("mnid"),s=require("did-jwt");var c=new r.ec("secp256k1"),u={DISCLOSURE_REQUEST:"shareReq",DISCLOSURE_RESPONSE:"shareResp",TYPED_DATA_SIGNATURE_REQUEST:"eip712Req",VERIFICATION_SIGNATURE_REQUEST:"verReq",ETH_TX_REQUEST:"ethtx",PERSONAL_SIGN_REQUEST:"personalSigReq"},d=function(e){var r=this;void 0===e&&(e={});var u=e.did,d=e.address,p=e.privateKey,f=e.signer,v=e.networks,y=e.registry,h=e.ethrConfig;if(f?this.signer=f:p&&(this.signer=s.SimpleSigner(p)),u)this.did=u;else if(d)a.isMNID(d)&&(this.did="did:uport:"+d),d.match("^0x[0-9a-fA-F]{40}$")&&(this.did="did:ethr:"+d);else if(p){var E=c.keyFromPrivate(p),g=s.toEthereumAddress(E.getPublic("hex"));this.did="did:ethr:"+g}this.signJWT=function(e,t){return s.createJWT(e,{issuer:r.did,signer:r.signer,alg:r.did.match("^did:uport:")||a.isMNID(r.did)?"ES256K":"ES256K-R",expiresIn:t})},t(y||o({networks:v?l(v):{}})),n(h||{}),i()};d.createIdentity=function(){var e=c.genKeyPair(),r=e.getPublic("hex"),t=e.getPrivate("hex");return{did:"did:ethr:"+s.toEthereumAddress(r),privateKey:t}},d.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.notifications&&(t.permissions=["notifications"]),e.callbackUrl&&(t.callback=e.callbackUrl),e.network_id&&(t.net=e.network_id),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:u.DISCLOSURE_REQUEST}),e.exp?void 0:r)},d.prototype.createVerification=function(e){return this.signJWT({sub:e.sub,claim:e.claim,exp:e.exp,vc:e.vc})},d.prototype.createVerificationSignatureRequest=function(e,r){return void 0===r&&(r={}),this.signJWT({unsignedClaim:e,sub:r.sub,riss:r.riss,aud:r.aud,vc:r.vc,callback:r.callbackUrl,type:u.VERIFICATION_SIGNATURE_REQUEST},r.expiresIn)},d.prototype.createTypedDataSignatureRequest=function(e,r){void 0===r&&(r={});for(var t=r.from,n=r.net,i=r.callback,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 this.signJWT({typedData:e,from:t,net:n,callback:i,type:u.TYPED_DATA_SIGNATURE_REQUEST})},d.prototype.createPersonalSignRequest=function(e,r){return void 0===r&&(r={}),this.signJWT({data:e,from:r.from,net:r.net,callback:r.callback,type:u.PERSONAL_SIGN_REQUEST})},d.prototype.createTxRequest=function(e,r){void 0===r&&(r={});var t=r.callbackUrl,n=r.exp;void 0===n&&(n=600);var i=r.networkId,o=r.label,a={};return t&&(a.callback=t),i&&(a.net=i),o&&(a.label=o),this.signJWT(Object.assign({},a,e,{type:u.ETH_TX_REQUEST}),n)},d.prototype.createDisclosureResponse=function(e,r){void 0===e&&(e={}),void 0===r&&(r=600);try{var t=this;function n(){return t.signJWT(Object.assign({},e,{type:u.DISCLOSURE_RESPONSE}),r)}var i=function(){if(e.req)return Promise.resolve(s.verifyJWT(e.req)).then(function(r){r.issuer&&(e.aud=r.issuer)})}();return i&&i.then?i.then(n):n()}catch(e){return Promise.reject(e)}},d.prototype.processDisclosurePayload=function(e){var r=e.doc,t=e.payload;try{var n=this,i=t.own;void 0===i&&(i={});var o=t.capabilities;void 0===o&&(o=[]);var c=t.nad,u=t.dad,d=t.iss,l=t.boxPub,p=t.verified,f=function(e,r){var t={};for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&-1===r.indexOf(n)&&(t[n]=e[n]);return t}(t,["own","capabilities","aud","req","iat","exp","type","nad","dad","iss","boxPub","verified"]),v=r.uportProfile;void 0===v&&(v={});var y=Object.assign({},{did:d,boxPub:l},i,v,f);u&&(y.deviceKey=u),c&&(y.mnid=c,y.address=a.decode(c).address),1===o.length&&(y.pushToken=o[0]);var h=function(){if(p){var e=[],r=p.map(function(r){return s.verifyJWT(r,{audience:n.did}).catch(function(){return e.push(r),Promise.resolve(null)})});return Promise.resolve(Promise.all(r)).then(function(r){y.verified=r.map(function(e){return e?Object.assign({},e.payload,{jwt:e.jwt}):null}).reduce(function(e,r){return r?e.concat([r]):e},[]),y.invalid=e})}}();return h&&h.then?h.then(function(){return y}):y}catch(e){return Promise.reject(e)}},d.prototype.authenticateDisclosureResponse=function(e,r){void 0===r&&(r=null);try{var t=this;return Promise.resolve(s.verifyJWT(e,{audience:t.did,callbackUrl:r,auth:!0})).then(function(e){var r=e.payload,n=e.doc;if(r.req)return Promise.resolve(s.verifyJWT(r.req)).then(function(e){if(e.payload.iss!==t.did)throw new Error("Challenge issuer does not match current identity: "+e.payload.iss+" !== "+t.did);if(e.payload.type!==u.DISCLOSURE_REQUEST)throw new Error("Challenge payload type invalid: "+e.payload.type);return t.processDisclosurePayload({payload:r,doc:n})});throw new Error("Challenge was not included in response")})}catch(e){return Promise.reject(e)}},d.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)}};var l=function(e){return Object.keys(e).forEach(function(r){var t=e[r];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.")})}),e},p=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},f=function(e){return e.filter(function(e){return("function"===e.type||"event"===e.type)&&e.name.length>0})},v=function(e,r){for(var t=e.name+"(",n=0;n<e.inputs.length;n++){var i=e.inputs[n],o=i.type+" ";t+=o+="string"===i.type?'"'+r[n]+'"':""+r[n],e.inputs.length-1!==n&&(t+=", ")}return t+")"},y=function(e){return function(r){var t={at:function(t){return new function(){var n=this;n.abi=r||[],n.address=t||"0x",f(r).forEach(function(r){n[r.name]=function(){if(!0===r.constant)throw new Error("A call does not return the txobject, no transaction necessary.");if("event"===r.type)throw new Error("An event does not return the txobject, events not supported");var t={},i=[].slice.call(arguments),o=r.inputs.length;if("function"===r.type){p(i[o])&&(t=i.splice(o,1)[0]);var a=Object.assign({},t,{to:n.address,function:v(r,i)});if(!e)return a;var s=i.slice(o);return e.apply(void 0,[a].concat(s))}}})}}};return t}};module.exports={Credentials:d,SimpleSigner:s.SimpleSigner,ContractFactory:y,createContract:function(e,r){return y(function(r,t){return r.function&&(r.fn=r.function),delete r.function,e.createTxRequest(r,t)})(r)}}; | ||
//# sourceMappingURL=index.js.map |
@@ -1,2 +0,2 @@ | ||
!function(e,r){"object"==typeof exports&&"undefined"!=typeof module?r(require("elliptic"),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(["elliptic","uport-did-resolver","ethr-did-resolver","https-did-resolver","uport-lite","mnid","did-jwt"],r):r(e.elliptic,e.UportDIDResolver,e.EthrDIDResolver,e.HttpsDIDResolver,e.UportLite,e.mnid,e.didJwt)}(this,function(e,r,t,i,n,o,a){r=r&&r.hasOwnProperty("default")?r.default:r,t=t&&t.hasOwnProperty("default")?t.default:t,i=i&&i.hasOwnProperty("default")?i.default:i,n=n&&n.hasOwnProperty("default")?n.default:n;var s=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},c=function(e){return e.filter(function(e){return("function"===e.type||"event"===e.type)&&e.name.length>0})},u=function(e,r){for(var t=e.name+"(",i=0;i<e.inputs.length;i++){var n=e.inputs[i],o=n.type+" ";t+=o+="string"===n.type?'"'+r[i]+'"':""+r[i],e.inputs.length-1!==i&&(t+=", ")}return t+")"},d=function(e){return function(r){var t={at:function(t){return new function(){var i=this;i.abi=r||[],i.address=t||"0x",c(r).forEach(function(r){i[r.name]=function(){if(!0===r.constant)throw new Error("A call does not return the txobject, no transaction necessary.");if("event"===r.type)throw new Error("An event does not return the txobject, events not supported");var t={},n=[].slice.call(arguments),o=r.inputs.length;if("function"===r.type){s(n[o])&&(t=n.splice(o,1)[0]);var a=Object.assign({},t,{to:i.address,function:u(r,n)});if(!e)return a;var c=n.slice(o);return e.apply(void 0,[a].concat(c))}}})}}};return t}};var l=new e.ec("secp256k1"),p={DISCLOSURE_REQUEST:"shareReq",DISCLOSURE_RESPONSE:"shareResp",TYPED_DATA_SIGNATURE_REQUEST:"eip712Req",VERIFICATION_SIGNATURE_REQUEST:"verReq",ETH_TX_REQUEST:"ethtx",PERSONAL_SIGN_REQUEST:"personalSigReq"},f=function(e){var s=this;void 0===e&&(e={});var c=e.did,u=e.address,d=e.privateKey,p=e.signer,f=e.networks,h=e.registry,y=e.ethrConfig;if(p?this.signer=p:d&&(this.signer=a.SimpleSigner(d)),c)this.did=c;else if(u)o.isMNID(u)&&(this.did="did:uport:"+u),u.match("^0x[0-9a-fA-F]{40}$")&&(this.did="did:ethr:"+u);else if(d){var E=l.keyFromPrivate(d),g=a.toEthereumAddress(E.getPublic("hex"));this.did="did:ethr:"+g}this.signJWT=function(e,r){return a.createJWT(e,{issuer:s.did,signer:s.signer,alg:s.did.match("^did:uport:")||o.isMNID(s.did)?"ES256K":"ES256K-R",expiresIn:r})},r(h||n({networks:f?v(f):{}})),t(y||{}),i()};f.createIdentity=function(){var e=l.genKeyPair(),r=e.getPublic("hex"),t=e.getPrivate("hex");return{did:"did:ethr:"+a.toEthereumAddress(r),privateKey:t}},f.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.notifications&&(t.permissions=["notifications"]),e.callbackUrl&&(t.callback=e.callbackUrl),e.network_id&&(t.net=e.network_id),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:p.DISCLOSURE_REQUEST}),e.exp?void 0:r)},f.prototype.createVerification=function(e){return this.signJWT({sub:e.sub,claim:e.claim,exp:e.exp,vc:e.vc})},f.prototype.createVerificationSignatureRequest=function(e,r){return void 0===r&&(r={}),this.signJWT({unsignedClaim:e,sub:r.sub,riss:r.riss,aud:r.aud,vc:r.vc,callback:r.callbackUrl,type:p.VERIFICATION_SIGNATURE_REQUEST},r.expiresIn)},f.prototype.createTypedDataSignatureRequest=function(e,r){void 0===r&&(r={});for(var t=r.from,i=r.net,n=r.callback,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 this.signJWT({typedData:e,from:t,net:i,callback:n,type:p.TYPED_DATA_SIGNATURE_REQUEST})},f.prototype.createPersonalSignRequest=function(e,r){return void 0===r&&(r={}),this.signJWT({data:e,from:r.from,net:r.net,callback:r.callback,type:p.PERSONAL_SIGN_REQUEST})},f.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:p.ETH_TX_REQUEST}),i)},f.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:p.DISCLOSURE_RESPONSE}),r)}var n=function(){if(e.req)return Promise.resolve(a.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)}},f.prototype.processDisclosurePayload=function(e){var r=e.doc,t=e.payload;try{var i=this,n=t.own;void 0===n&&(n={});var s=t.capabilities;void 0===s&&(s=[]);var c=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),c&&(h.mnid=c,h.address=o.decode(c).address),1===s.length&&(h.pushToken=s[0]);var y=function(){if(p){var e=[],r=p.map(function(r){return a.verifyJWT(r,{audience:i.did}).catch(function(){return e.push(r),Promise.resolve(null)})});return Promise.resolve(Promise.all(r)).then(function(r){h.verified=r.map(function(e){return e?Object.assign({},e.payload,{jwt:e.jwt}):null}).reduce(function(e,r){return r?e.concat([r]):e},[]),h.invalid=e})}}();return y&&y.then?y.then(function(){return h}):h}catch(e){return Promise.reject(e)}},f.prototype.authenticateDisclosureResponse=function(e,r){void 0===r&&(r=null);try{var t=this;return Promise.resolve(a.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(a.verifyJWT(r.req)).then(function(e){if(e.payload.iss!==t.did)throw new Error("Challenge issuer does not match current identity: "+e.payload.iss+" !== "+t.did);if(e.payload.type!==p.DISCLOSURE_REQUEST)throw new Error("Challenge payload type invalid: "+e.payload.type);return t.processDisclosurePayload({payload:r,doc:i})});throw new Error("Challenge was not included in response")})}catch(e){return Promise.reject(e)}},f.prototype.verifyDisclosure=function(e){try{var r=this;return Promise.resolve(a.verifyJWT(e,{audience:r.did})).then(function(e){return r.processDisclosurePayload({payload:e.payload,doc:e.doc})})}catch(e){return Promise.reject(e)}},f.prototype.contract=function(e){var r=this;return d(function(e,t){return e.function&&(e.fn=e.function),delete e.function,r.createTxRequest(e,t)}.bind(this))(e)};var v=function(e){return Object.keys(e).forEach(function(r){var t=e[r];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.")})}),e};module.exports={Credentials:f,SimpleSigner:a.SimpleSigner,ContractFactory:d}}); | ||
!function(e,r){"object"==typeof exports&&"undefined"!=typeof module?r(require("elliptic"),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(["elliptic","uport-did-resolver","ethr-did-resolver","https-did-resolver","uport-lite","mnid","did-jwt"],r):r(e.elliptic,e.UportDIDResolver,e.EthrDIDResolver,e.HttpsDIDResolver,e.UportLite,e.mnid,e.didJwt)}(this,function(e,r,t,i,n,o,a){r=r&&r.hasOwnProperty("default")?r.default:r,t=t&&t.hasOwnProperty("default")?t.default:t,i=i&&i.hasOwnProperty("default")?i.default:i,n=n&&n.hasOwnProperty("default")?n.default:n;var s=new e.ec("secp256k1"),c={DISCLOSURE_REQUEST:"shareReq",DISCLOSURE_RESPONSE:"shareResp",TYPED_DATA_SIGNATURE_REQUEST:"eip712Req",VERIFICATION_SIGNATURE_REQUEST:"verReq",ETH_TX_REQUEST:"ethtx",PERSONAL_SIGN_REQUEST:"personalSigReq"},u=function(e){var c=this;void 0===e&&(e={});var u=e.did,l=e.address,p=e.privateKey,f=e.signer,v=e.networks,h=e.registry,y=e.ethrConfig;if(f?this.signer=f:p&&(this.signer=a.SimpleSigner(p)),u)this.did=u;else if(l)o.isMNID(l)&&(this.did="did:uport:"+l),l.match("^0x[0-9a-fA-F]{40}$")&&(this.did="did:ethr:"+l);else if(p){var E=s.keyFromPrivate(p),g=a.toEthereumAddress(E.getPublic("hex"));this.did="did:ethr:"+g}this.signJWT=function(e,r){return a.createJWT(e,{issuer:c.did,signer:c.signer,alg:c.did.match("^did:uport:")||o.isMNID(c.did)?"ES256K":"ES256K-R",expiresIn:r})},r(h||n({networks:v?d(v):{}})),t(y||{}),i()};u.createIdentity=function(){var e=s.genKeyPair(),r=e.getPublic("hex"),t=e.getPrivate("hex");return{did:"did:ethr:"+a.toEthereumAddress(r),privateKey:t}},u.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.notifications&&(t.permissions=["notifications"]),e.callbackUrl&&(t.callback=e.callbackUrl),e.network_id&&(t.net=e.network_id),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:c.DISCLOSURE_REQUEST}),e.exp?void 0:r)},u.prototype.createVerification=function(e){return this.signJWT({sub:e.sub,claim:e.claim,exp:e.exp,vc:e.vc})},u.prototype.createVerificationSignatureRequest=function(e,r){return void 0===r&&(r={}),this.signJWT({unsignedClaim:e,sub:r.sub,riss:r.riss,aud:r.aud,vc:r.vc,callback:r.callbackUrl,type:c.VERIFICATION_SIGNATURE_REQUEST},r.expiresIn)},u.prototype.createTypedDataSignatureRequest=function(e,r){void 0===r&&(r={});for(var t=r.from,i=r.net,n=r.callback,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 this.signJWT({typedData:e,from:t,net:i,callback:n,type:c.TYPED_DATA_SIGNATURE_REQUEST})},u.prototype.createPersonalSignRequest=function(e,r){return void 0===r&&(r={}),this.signJWT({data:e,from:r.from,net:r.net,callback:r.callback,type:c.PERSONAL_SIGN_REQUEST})},u.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:c.ETH_TX_REQUEST}),i)},u.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:c.DISCLOSURE_RESPONSE}),r)}var n=function(){if(e.req)return Promise.resolve(a.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)}},u.prototype.processDisclosurePayload=function(e){var r=e.doc,t=e.payload;try{var i=this,n=t.own;void 0===n&&(n={});var s=t.capabilities;void 0===s&&(s=[]);var c=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),c&&(h.mnid=c,h.address=o.decode(c).address),1===s.length&&(h.pushToken=s[0]);var y=function(){if(p){var e=[],r=p.map(function(r){return a.verifyJWT(r,{audience:i.did}).catch(function(){return e.push(r),Promise.resolve(null)})});return Promise.resolve(Promise.all(r)).then(function(r){h.verified=r.map(function(e){return e?Object.assign({},e.payload,{jwt:e.jwt}):null}).reduce(function(e,r){return r?e.concat([r]):e},[]),h.invalid=e})}}();return y&&y.then?y.then(function(){return h}):h}catch(e){return Promise.reject(e)}},u.prototype.authenticateDisclosureResponse=function(e,r){void 0===r&&(r=null);try{var t=this;return Promise.resolve(a.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(a.verifyJWT(r.req)).then(function(e){if(e.payload.iss!==t.did)throw new Error("Challenge issuer does not match current identity: "+e.payload.iss+" !== "+t.did);if(e.payload.type!==c.DISCLOSURE_REQUEST)throw new Error("Challenge payload type invalid: "+e.payload.type);return t.processDisclosurePayload({payload:r,doc:i})});throw new Error("Challenge was not included in response")})}catch(e){return Promise.reject(e)}},u.prototype.verifyDisclosure=function(e){try{var r=this;return Promise.resolve(a.verifyJWT(e,{audience:r.did})).then(function(e){return r.processDisclosurePayload({payload:e.payload,doc:e.doc})})}catch(e){return Promise.reject(e)}};var d=function(e){return Object.keys(e).forEach(function(r){var t=e[r];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.")})}),e},l=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},p=function(e){return e.filter(function(e){return("function"===e.type||"event"===e.type)&&e.name.length>0})},f=function(e,r){for(var t=e.name+"(",i=0;i<e.inputs.length;i++){var n=e.inputs[i],o=n.type+" ";t+=o+="string"===n.type?'"'+r[i]+'"':""+r[i],e.inputs.length-1!==i&&(t+=", ")}return t+")"},v=function(e){return function(r){var t={at:function(t){return new function(){var i=this;i.abi=r||[],i.address=t||"0x",p(r).forEach(function(r){i[r.name]=function(){if(!0===r.constant)throw new Error("A call does not return the txobject, no transaction necessary.");if("event"===r.type)throw new Error("An event does not return the txobject, events not supported");var t={},n=[].slice.call(arguments),o=r.inputs.length;if("function"===r.type){l(n[o])&&(t=n.splice(o,1)[0]);var a=Object.assign({},t,{to:i.address,function:f(r,n)});if(!e)return a;var s=n.slice(o);return e.apply(void 0,[a].concat(s))}}})}}};return t}};module.exports={Credentials:u,SimpleSigner:a.SimpleSigner,ContractFactory:v,createContract:function(e,r){return v(function(r,t){return r.function&&(r.fn=r.function),delete r.function,e.createTxRequest(r,t)})(r)}}}); | ||
//# sourceMappingURL=index.umd.js.map |
{ | ||
"name": "uport-credentials", | ||
"version": "1.2.0-alpha1", | ||
"version": "1.2.0-alpha2", | ||
"description": "Library for interacting with uport profiles and attestations", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
import Credentials from '../Credentials' | ||
import { createContract } from '../Contract' | ||
import { SimpleSigner, createJWT, verifyJWT, decodeJWT } from 'did-jwt' | ||
@@ -422,3 +423,3 @@ import MockDate from 'mockdate' | ||
const address = '0x70A804cCE17149deB6030039798701a38667ca3B' | ||
const statusContract = uport.contract(abi).at(address) | ||
const statusContract = createContract(uport, abi).at(address) | ||
@@ -425,0 +426,0 @@ it('creates a valid JWT for a request', async () => { |
@@ -47,3 +47,3 @@ | ||
const ContractFactory = (extend) => (contractABI) => { | ||
export const ContractFactory = (extend) => (contractABI) => { | ||
const output = {}; | ||
@@ -99,2 +99,19 @@ output.at = function atContract(address) { | ||
export { ContractFactory } | ||
/** | ||
* Builds and returns a contract object which can be used to interact with | ||
* a given contract. Similar to web3.eth.contract but with promises. Once specifying .at(address) | ||
* you can call the contract functions with this object. Each call will create a request. | ||
* | ||
* @param {Credentials} credentials Initialized Credentials object | ||
* @param {Object} abi contract ABI | ||
* @return {Object} contract object | ||
*/ | ||
export function createContract (credentials, abi) { | ||
const txObjHandler = (txObj, opts) => { | ||
if (txObj.function) txObj.fn = txObj.function | ||
delete txObj['function'] | ||
return credentials.createTxRequest(txObj, opts) | ||
} | ||
return ContractFactory(txObjHandler)(abi) | ||
} |
@@ -10,4 +10,2 @@ import { ec as EC } from 'elliptic' | ||
import { ContractFactory } from './Contract.js' | ||
const secp256k1 = new EC('secp256k1') | ||
@@ -516,19 +514,2 @@ | ||
} | ||
/** | ||
* Builds and returns a contract object which can be used to interact with | ||
* a given contract. Similar to web3.eth.contract but with promises. Once specifying .at(address) | ||
* you can call the contract functions with this object. Each call will create a request. | ||
* | ||
* @param {Object} abi contract ABI | ||
* @return {Object} contract object | ||
*/ | ||
contract(abi) { | ||
const txObjHandler = (txObj, opts) => { | ||
if (txObj.function) txObj.fn = txObj.function | ||
delete txObj['function'] | ||
return this.createTxRequest(txObj, opts) | ||
} | ||
return ContractFactory(txObjHandler.bind(this))(abi) | ||
} | ||
} | ||
@@ -535,0 +516,0 @@ |
import Credentials from './Credentials' | ||
import { SimpleSigner } from 'did-jwt' | ||
import { ContractFactory } from './Contract' | ||
module.exports = { Credentials, SimpleSigner, ContractFactory } | ||
import { ContractFactory, createContract } from './Contract' | ||
module.exports = { Credentials, SimpleSigner, ContractFactory, createContract } |
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
4
228182
1417