ethr-did-resolver
Advanced tools
Comparing version 4.2.0 to 4.3.0
@@ -0,1 +1,8 @@ | ||
# [4.3.0](https://github.com/decentralized-identity/ethr-did-resolver/compare/4.2.0...4.3.0) (2021-04-20) | ||
### Features | ||
* add `assertionMethod` by default to didDocument ([#124](https://github.com/decentralized-identity/ethr-did-resolver/issues/124)) ([11b2096](https://github.com/decentralized-identity/ethr-did-resolver/commit/11b20967fae66b784a527d92c39cd29f6dbe6b10)), closes [#117](https://github.com/decentralized-identity/ethr-did-resolver/issues/117) [#115](https://github.com/decentralized-identity/ethr-did-resolver/issues/115) | ||
# [4.2.0](https://github.com/decentralized-identity/ethr-did-resolver/compare/4.1.0...4.2.0) (2021-04-16) | ||
@@ -2,0 +9,0 @@ |
@@ -1,2 +0,2 @@ | ||
var e=require("@ethersproject/basex"),t=require("@ethersproject/bignumber"),r=require("@ethersproject/contracts"),n=require("@ethersproject/providers"),o=require("ethr-did-registry"),i=require("@ethersproject/address"),c=require("@ethersproject/transactions"),s=require("querystring");function a(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var d=a(o);const u=/^(.*)?(0x[0-9a-fA-F]{40}|0x[0-9a-fA-F]{66})$/;var h,l;exports.verificationMethodTypes=void 0,(h=exports.verificationMethodTypes||(exports.verificationMethodTypes={})).EcdsaSecp256k1VerificationKey2019="EcdsaSecp256k1VerificationKey2019",h.EcdsaSecp256k1RecoveryMethod2020="EcdsaSecp256k1RecoveryMethod2020",h.Ed25519VerificationKey2018="Ed25519VerificationKey2018",h.RSAVerificationKey2018="RSAVerificationKey2018",h.X25519KeyAgreementKey2019="X25519KeyAgreementKey2019",function(e){e.DIDOwnerChanged="DIDOwnerChanged",e.DIDAttributeChanged="DIDAttributeChanged",e.DIDDelegateChanged="DIDDelegateChanged"}(l||(l={}));const f={sigAuth:"SignatureAuthentication2018",veriKey:"VerificationKey2018",enc:"KeyAgreementKey2019"},v={Secp256k1VerificationKey2018:exports.verificationMethodTypes.EcdsaSecp256k1VerificationKey2019,Ed25519SignatureAuthentication2018:exports.verificationMethodTypes.Ed25519VerificationKey2018,Secp256k1SignatureAuthentication2018:exports.verificationMethodTypes.EcdsaSecp256k1VerificationKey2019,RSAVerificationKey2018:exports.verificationMethodTypes.RSAVerificationKey2018,Ed25519VerificationKey2018:exports.verificationMethodTypes.Ed25519VerificationKey2018,X25519KeyAgreementKey2019:exports.verificationMethodTypes.X25519KeyAgreementKey2019};function m(e){return("string"==typeof e?Buffer.from(e.slice(2),"hex"):Buffer.from(e)).toString("utf8").replace(/\0+$/,"")}function p(e){const t="0x"+Buffer.from(e).slice(0,32).toString("hex");return t+"0".repeat(66-t.length)}function g(e){let t,r=e;if(r.startsWith("did:ethr")){const e=r.split(":");r=e[e.length-1],e.length>=4&&(t=e.splice(2,e.length-3).join(":"))}return r.length>42?{address:c.computeAddress(r),publicKey:r,network:t}:{address:i.getAddress(r),network:t}}const y={mainnet:"0x1",ropsten:"0x3",rinkeby:"0x4",goerli:"0x5",kovan:"0x2a"},b={...y,rsk:"0x1e","rsk:testnet":"0x1f",artis_t1:"0x03c401",artis_s1:"0x03c301",matic:"0x89",maticmum:"0x13881"};var x;function w(e){var o;let i=e.provider||(null==(o=e.web3)?void 0:o.currentProvider);if(!i){if(!e.rpcUrl)throw new Error(`invalid_config: No web3 provider could be determined for network ${e.name||e.chainId}`);{var c;const r=e.chainId?e.chainId:b[e.name||""],o=r?t.BigNumber.from(r).toNumber():r,s=y[e.name||""]?null==(c=e.name)?void 0:c.replace("mainnet","homestead"):"any";i=new n.JsonRpcProvider(e.rpcUrl,o||s)}}return r.ContractFactory.fromSolidity(d.default).attach(e.registry||"0xdca7ef03e98e0dc2b855be647c39abe984fcf21b").connect(i)}function k(e){const t={},r=e.chainId||b[e.name||""];return r?(e.name&&(t[e.name]=w(e)),t["number"==typeof r?`0x${r.toString(16)}`:r]=w(e)):(e.provider||e.web3||e.rpcUrl)&&(t[e.name||""]=w(e)),t}function D(e){var t;return{...k(e),...null==(t=e.networks)?void 0:t.reduce((e,t)=>({...e,...k(t)}),{})}}exports.Errors=void 0,(x=exports.Errors||(exports.Errors={})).notFound="notFound",x.invalidDid="invalidDid",x.unknownNetwork="unknownNetwork";class P{constructor(e,t,r,n="mainnet",o,i,c="0xdca7ef03e98e0dc2b855be647c39abe984fcf21b"){const{address:s,publicKey:a,network:d}=g(e),u=d||n;if(t)this.contract=t;else{if(!(o||null!=r&&r.provider))throw new Error(" either a contract instance or a provider or rpcUrl is required to initialize");this.contract=w({name:u,provider:o||(null==r?void 0:r.provider),registry:c,rpcUrl:i})}this.signer=r,this.address=s;let h=u?`${u}:`:"";h in["mainnet:","0x1:"]&&(h=""),this.did=a?`did:ethr:${h}${a}`:`did:ethr:${h}${s}`}getOwner(e,t){try{return Promise.resolve(this.contract.functions.identityOwner(e,{blockTag:t})).then(function(e){return e[0]})}catch(e){return Promise.reject(e)}}attachContract(e){try{const t=this;return Promise.resolve(e||t.getOwner(t.address,"latest")).then(function(e){const r=t.signer?t.signer:t.contract.provider.getSigner(e)||t.contract.signer;return t.contract.connect(r)})}catch(e){return Promise.reject(e)}}changeOwner(e,t={}){try{const r=this,n={gasLimit:123456,gasPrice:1e9,...t};return Promise.resolve(r.attachContract(n.from)).then(function(t){return delete n.from,Promise.resolve(t.functions.changeOwner(r.address,e,n)).then(function(e){return Promise.resolve(e.wait())})})}catch(e){return Promise.reject(e)}}addDelegate(e,t,r,n={}){try{const o=this,i={gasLimit:123456,gasPrice:1e9,...n};return Promise.resolve(o.attachContract(i.from)).then(function(n){delete i.from;const c=p(e);return Promise.resolve(n.functions.addDelegate(o.address,c,t,r,i)).then(function(e){return Promise.resolve(e.wait())})})}catch(e){return Promise.reject(e)}}revokeDelegate(e,t,r={}){try{const n=this,o={gasLimit:123456,gasPrice:1e9,...r};return e=e.startsWith("0x")?e:p(e),Promise.resolve(n.attachContract(o.from)).then(function(r){return delete o.from,Promise.resolve(r.functions.revokeDelegate(n.address,e,t,o)).then(function(e){return Promise.resolve(e.wait())})})}catch(e){return Promise.reject(e)}}setAttribute(e,t,r,n={}){try{const o=this,i={gasLimit:123456,gasPrice:1e9,controller:void 0,...n};return e=e.startsWith("0x")?e:p(e),t=t.startsWith("0x")?t:"0x"+Buffer.from(t,"utf-8").toString("hex"),Promise.resolve(o.attachContract(i.from)).then(function(n){return delete i.from,Promise.resolve(n.functions.setAttribute(o.address,e,t,r,i)).then(function(e){return Promise.resolve(e.wait())})})}catch(e){return Promise.reject(e)}}revokeAttribute(e,t,r={}){try{const n=this,o={gasLimit:123456,gasPrice:1e9,...r};return e=e.startsWith("0x")?e:p(e),t=t.startsWith("0x")?t:"0x"+Buffer.from(t,"utf-8").toString("hex"),Promise.resolve(n.attachContract(o.from)).then(function(r){return delete o.from,Promise.resolve(r.functions.revokeAttribute(n.address,e,t,o)).then(function(e){return Promise.resolve(e.wait())})})}catch(e){return Promise.reject(e)}}}function I(e,t,r){if(!e.s){if(r instanceof K){if(!r.s)return void(r.o=I.bind(null,e,t));1&t&&(t=r.s),r=r.v}if(r&&r.then)return void r.then(I.bind(null,e,t),I.bind(null,e,2));e.s=t,e.v=r;const n=e.o;n&&n(e)}}const K=function(){function e(){}return e.prototype.then=function(t,r){const n=new e,o=this.s;if(o){const e=1&o?t:r;if(e){try{I(n,1,e(this.v))}catch(e){I(n,2,e)}return n}return this}return this.o=function(e){try{const o=e.v;1&e.s?I(n,1,t?t(o):o):r?I(n,1,r(o)):I(n,2,o)}catch(e){I(n,2,e)}},n},e}();function S(e){return e instanceof K&&1&e.s}class N{constructor(e){this.contracts=function(e={}){const t={...(r=e.infuraProjectId,r?D({networks:[{name:"mainnet",chainId:"0x1",provider:new n.InfuraProvider("homestead",r)},{name:"ropsten",chainId:"0x3",provider:new n.InfuraProvider("ropsten",r)},{name:"rinkeby",chainId:"0x4",provider:new n.InfuraProvider("rinkeby",r)},{name:"goerli",chainId:"0x5",provider:new n.InfuraProvider("goerli",r)},{name:"kovan",chainId:"0x2a",provider:new n.InfuraProvider("kovan",r)}]}):{}),...D(e)};var r;if(0===Object.keys(t).length)throw new Error("invalid_config: Please make sure to have at least one network");return t}(e)}getOwner(e,t,r){try{return Promise.resolve(new P(e,this.contracts[t]).getOwner(e,r))}catch(e){return Promise.reject(e)}}previousChange(e,r,n){try{return Promise.resolve(this.contracts[r].functions.changed(e,{blockTag:n})).then(function(e){return t.BigNumber.from(e[0])})}catch(e){return Promise.reject(e)}}getBlockMetadata(e,t){try{return Promise.resolve(this.contracts[t].provider.getBlock(e)).then(function(e){return{height:e.number.toString(),isoDate:new Date(1e3*e.timestamp).toISOString()}})}catch(e){return Promise.reject(e)}}changeLog(e,r,n="latest"){try{const o=this,i=o.contracts[r],c=i.provider,s=r.startsWith("0x")?r:b[r];return Promise.resolve(c.getNetwork()).then(function(a){const d=a.chainId,u=s?t.BigNumber.from(s).toNumber():d,h=[],{address:l,publicKey:f}=g(e),v=f;return Promise.resolve(o.previousChange(l,r,n)).then(function(e){function r(){return{address:l,history:h,controllerKey:v,chainId:u}}const n=function(e,t,r){for(var n;;){var o=e();if(S(o)&&(o=o.v),!o)return i;if(o.then){n=0;break}var i=r();if(i&&i.then){if(!S(i)){n=1;break}i=i.s}}var c=new K,s=I.bind(null,c,2);return(0===n?o.then(d):1===n?i.then(a):(void 0).then(function(){(o=e())?o.then?o.then(d).then(void 0,s):d(o):I(c,1,i)})).then(void 0,s),c;function a(t){i=t;do{if(!(o=e())||S(o)&&!o.v)return void I(c,1,i);if(o.then)return void o.then(d).then(void 0,s);S(i=r())&&(i=i.v)}while(!i||!i.then);i.then(a).then(void 0,s)}function d(e){e?(i=r())&&i.then?i.then(a).then(void 0,s):a(i):I(c,1,i)}}(function(){return!!e},0,function(){const r=e;return Promise.resolve(c.getLogs({address:i.address,topics:[null,`0x000000000000000000000000${l.slice(2)}`],fromBlock:e.toHexString(),toBlock:e.toHexString()})).then(function(n){const o=function(e,r){return r.map(r=>function(e,r){const n={};if(e.eventFragment.inputs.length!==e.args.length)throw new TypeError("malformed event input. wrong number of arguments");return e.eventFragment.inputs.forEach((r,o)=>{let i=e.args[o];"object"==typeof i&&(i=t.BigNumber.from(i)),"bytes32"===r.type&&(i=m(i)),n[r.name]=i}),n._eventName=e.name,n.blockNumber=r,n}(e.interface.parseLog(r),r.blockNumber))}(i,n);o.reverse(),e=null;for(const t of o)h.unshift(t),t.previousChange.lt(r)&&(e=t.previousChange)})});return n&&n.then?n.then(r):r()})})}catch(e){return Promise.reject(e)}}wrapDidDocument(r,n,o,i,c,s,a){const d={"@context":["https://www.w3.org/ns/did/v1","https://identity.foundation/EcdsaSecp256k1RecoverySignature2020/lds-ecdsa-secp256k1-recovery2020-0.0.jsonld"],id:r,verificationMethod:[],authentication:[]};let u=n;const h=[`${r}#controller`];let m=0,p=Number.POSITIVE_INFINITY,g=!1,y=0,b=0;const x={},w={},k={};for(const n of i){if(-1!==s&&n.blockNumber>s){p>n.blockNumber&&(p=n.blockNumber);continue}m<n.blockNumber&&(m=n.blockNumber);const o=n.validTo||t.BigNumber.from(0),i=`${n._eventName}-${n.delegateType||n.name}-${n.delegate||n.value}`;if(o&&o.gte(a)){if(n._eventName===l.DIDDelegateChanged){const e=n;switch(y++,e.delegateType){case"sigAuth":x[i]=`${r}#delegate-${y}`;case"veriKey":w[i]={id:`${r}#delegate-${y}`,type:exports.verificationMethodTypes.EcdsaSecp256k1RecoveryMethod2020,controller:r,blockchainAccountId:`${e.delegate}@eip155:${c}`}}}else if(n._eventName===l.DIDAttributeChanged){const t=n,o=t.name.match(/^did\/(pub|svc)\/(\w+)(\/(\w+))?(\/(\w+))?$/);if(o){const n=o[2],c=f[o[4]]||o[4],s=o[6];switch(o[1]){case"pub":{y++;const a={id:`${r}#delegate-${y}`,type:`${n}${c}`,controller:r};switch(a.type=v[a.type]||n,s){case null:case void 0:case"hex":a.publicKeyHex=t.value.slice(2);break;case"base64":a.publicKeyBase64=Buffer.from(t.value.slice(2),"hex").toString("base64");break;case"base58":a.publicKeyBase58=e.Base58.encode(Buffer.from(t.value.slice(2),"hex"));break;case"pem":a.publicKeyPem=Buffer.from(t.value.slice(2),"hex").toString();break;default:a.value=t.value}w[i]=a,"sigAuth"===o[4]&&(x[i]=a.id);break}case"svc":b++,k[i]={id:`${r}#service-${b}`,type:n,serviceEndpoint:Buffer.from(t.value.slice(2),"hex").toString()}}}}}else if(n._eventName===l.DIDOwnerChanged){if(u=n.owner,"0x0000000000000000000000000000000000000000"===n.owner){g=!0;break}}else n._eventName===l.DIDDelegateChanged||n._eventName===l.DIDAttributeChanged&&n.name.match(/^did\/pub\//)?y++:n._eventName===l.DIDAttributeChanged&&n.name.match(/^did\/svc\//)&&b++,delete x[i],delete w[i],delete k[i]}const D=[{id:`${r}#controller`,type:exports.verificationMethodTypes.EcdsaSecp256k1RecoveryMethod2020,controller:r,blockchainAccountId:`${u}@eip155:${c}`}];o&&u==n&&(D.push({id:`${r}#controllerKey`,type:exports.verificationMethodTypes.EcdsaSecp256k1VerificationKey2019,controller:r,publicKeyHex:o}),h.push(`${r}#controllerKey`));const P={...d,verificationMethod:D.concat(Object.values(w)),authentication:h.concat(Object.values(x))};return Object.values(k).length>0&&(P.service=Object.values(k)),g?{didDocument:{...d,"@context":"https://www.w3.org/ns/did/v1"},deactivated:g,versionId:m,nextVersionId:p}:{didDocument:P,deactivated:g,versionId:m,nextVersionId:p}}resolve(e,r,n,o){try{const n=this;function i(){return Promise.resolve(n.changeLog(a,d,"latest")).then(function({address:t,history:r,controllerKey:o,chainId:i}){return function(c,s){try{var a=function(){function c(){function e(){return{didDocumentMetadata:{...v,...m,...p},didResolutionMetadata:{contentType:"application/did+ld+json"},didDocument:s}}const t=function(){if(f!==Number.POSITIVE_INFINITY)return Promise.resolve(n.getBlockMetadata(f,d)).then(function(e){p={nextVersionId:e.height,nextUpdate:e.isoDate}})}();return t&&t.then?t.then(e):e()}const{didDocument:s,deactivated:a,versionId:u,nextVersionId:f}=n.wrapDidDocument(e,t,o,r,i,h,l),v=a?{deactivated:!0}:{};let m={},p={};const g=function(){if(0!==u)return Promise.resolve(n.getBlockMetadata(u,d)).then(function(e){m={versionId:e.height,updated:e.isoDate}})}();return g&&g.then?g.then(c):c()}()}catch(e){return s(e)}return a&&a.then?a.then(void 0,s):a}(0,function(e){return{didResolutionMetadata:{error:exports.Errors.notFound,message:e.toString()},didDocumentMetadata:{},didDocument:null}})})}const c=r.id.match(u);if(!c)return Promise.resolve({didResolutionMetadata:{error:exports.Errors.invalidDid,message:`Not a valid did:ethr: ${r.id}`},didDocumentMetadata:{},didDocument:null});const a=c[2],d=c[1]?c[1].slice(0,-1):"mainnet";let h=o.blockTag||"latest";if("string"==typeof r.query){const e=s.decode(r.query);h="string"==typeof e.versionId?e.versionId:h;try{h=Number.parseInt(h)}catch(e){h="latest"}}if(!n.contracts[d])return Promise.resolve({didResolutionMetadata:{error:exports.Errors.unknownNetwork,message:`The DID resolver does not have a configuration for network: ${d}`},didDocumentMetadata:{},didDocument:null});let l=t.BigNumber.from(Math.floor((new Date).getTime()/1e3));const f=function(){if("number"==typeof h)return Promise.resolve(n.getBlockMetadata(h,d)).then(function(e){l=t.BigNumber.from(Date.parse(e.isoDate)/1e3)})}();return Promise.resolve(f&&f.then?f.then(i):i())}catch(e){return Promise.reject(e)}}build(){return{ethr:this.resolve.bind(this)}}}exports.EthrDidController=P,exports.REGISTRY="0xdca7ef03e98e0dc2b855be647c39abe984fcf21b",exports.attrTypes=f,exports.bytes32toString=m,exports.delegateTypes=v,exports.getResolver=function(e){return new N(e).build()},exports.identifierMatcher=u,exports.interpretIdentifier=g,exports.stringToBytes32=p; | ||
var e=require("@ethersproject/basex"),t=require("@ethersproject/bignumber"),r=require("@ethersproject/contracts"),n=require("@ethersproject/providers"),o=require("ethr-did-registry"),i=require("@ethersproject/address"),c=require("@ethersproject/transactions"),s=require("querystring");function a(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var d=a(o);const u=/^(.*)?(0x[0-9a-fA-F]{40}|0x[0-9a-fA-F]{66})$/;var h,l;exports.verificationMethodTypes=void 0,(h=exports.verificationMethodTypes||(exports.verificationMethodTypes={})).EcdsaSecp256k1VerificationKey2019="EcdsaSecp256k1VerificationKey2019",h.EcdsaSecp256k1RecoveryMethod2020="EcdsaSecp256k1RecoveryMethod2020",h.Ed25519VerificationKey2018="Ed25519VerificationKey2018",h.RSAVerificationKey2018="RSAVerificationKey2018",h.X25519KeyAgreementKey2019="X25519KeyAgreementKey2019",function(e){e.DIDOwnerChanged="DIDOwnerChanged",e.DIDAttributeChanged="DIDAttributeChanged",e.DIDDelegateChanged="DIDDelegateChanged"}(l||(l={}));const f={sigAuth:"SignatureAuthentication2018",veriKey:"VerificationKey2018",enc:"KeyAgreementKey2019"},v={Secp256k1VerificationKey2018:exports.verificationMethodTypes.EcdsaSecp256k1VerificationKey2019,Ed25519SignatureAuthentication2018:exports.verificationMethodTypes.Ed25519VerificationKey2018,Secp256k1SignatureAuthentication2018:exports.verificationMethodTypes.EcdsaSecp256k1VerificationKey2019,RSAVerificationKey2018:exports.verificationMethodTypes.RSAVerificationKey2018,Ed25519VerificationKey2018:exports.verificationMethodTypes.Ed25519VerificationKey2018,X25519KeyAgreementKey2019:exports.verificationMethodTypes.X25519KeyAgreementKey2019};function m(e){return("string"==typeof e?Buffer.from(e.slice(2),"hex"):Buffer.from(e)).toString("utf8").replace(/\0+$/,"")}function p(e){const t="0x"+Buffer.from(e).slice(0,32).toString("hex");return t+"0".repeat(66-t.length)}function g(e){let t,r=e;if(r.startsWith("did:ethr")){const e=r.split(":");r=e[e.length-1],e.length>=4&&(t=e.splice(2,e.length-3).join(":"))}return r.length>42?{address:c.computeAddress(r),publicKey:r,network:t}:{address:i.getAddress(r),network:t}}const y={mainnet:"0x1",ropsten:"0x3",rinkeby:"0x4",goerli:"0x5",kovan:"0x2a"},b={...y,rsk:"0x1e","rsk:testnet":"0x1f",artis_t1:"0x03c401",artis_s1:"0x03c301",matic:"0x89",maticmum:"0x13881"};var x;function w(e){var o;let i=e.provider||(null==(o=e.web3)?void 0:o.currentProvider);if(!i){if(!e.rpcUrl)throw new Error(`invalid_config: No web3 provider could be determined for network ${e.name||e.chainId}`);{var c;const r=e.chainId?e.chainId:b[e.name||""],o=r?t.BigNumber.from(r).toNumber():r,s=y[e.name||""]?null==(c=e.name)?void 0:c.replace("mainnet","homestead"):"any";i=new n.JsonRpcProvider(e.rpcUrl,o||s)}}return r.ContractFactory.fromSolidity(d.default).attach(e.registry||"0xdca7ef03e98e0dc2b855be647c39abe984fcf21b").connect(i)}function k(e){const t={},r=e.chainId||b[e.name||""];return r?(e.name&&(t[e.name]=w(e)),t["number"==typeof r?`0x${r.toString(16)}`:r]=w(e)):(e.provider||e.web3||e.rpcUrl)&&(t[e.name||""]=w(e)),t}function D(e){var t;return{...k(e),...null==(t=e.networks)?void 0:t.reduce((e,t)=>({...e,...k(t)}),{})}}exports.Errors=void 0,(x=exports.Errors||(exports.Errors={})).notFound="notFound",x.invalidDid="invalidDid",x.unknownNetwork="unknownNetwork";class P{constructor(e,t,r,n="mainnet",o,i,c="0xdca7ef03e98e0dc2b855be647c39abe984fcf21b"){const{address:s,publicKey:a,network:d}=g(e),u=d||n;if(t)this.contract=t;else{if(!(o||null!=r&&r.provider))throw new Error(" either a contract instance or a provider or rpcUrl is required to initialize");this.contract=w({name:u,provider:o||(null==r?void 0:r.provider),registry:c,rpcUrl:i})}this.signer=r,this.address=s;let h=u?`${u}:`:"";h in["mainnet:","0x1:"]&&(h=""),this.did=a?`did:ethr:${h}${a}`:`did:ethr:${h}${s}`}getOwner(e,t){try{return Promise.resolve(this.contract.functions.identityOwner(e,{blockTag:t})).then(function(e){return e[0]})}catch(e){return Promise.reject(e)}}attachContract(e){try{const t=this;return Promise.resolve(e||t.getOwner(t.address,"latest")).then(function(e){const r=t.signer?t.signer:t.contract.provider.getSigner(e)||t.contract.signer;return t.contract.connect(r)})}catch(e){return Promise.reject(e)}}changeOwner(e,t={}){try{const r=this,n={gasLimit:123456,gasPrice:1e9,...t};return Promise.resolve(r.attachContract(n.from)).then(function(t){return delete n.from,Promise.resolve(t.functions.changeOwner(r.address,e,n)).then(function(e){return Promise.resolve(e.wait())})})}catch(e){return Promise.reject(e)}}addDelegate(e,t,r,n={}){try{const o=this,i={gasLimit:123456,gasPrice:1e9,...n};return Promise.resolve(o.attachContract(i.from)).then(function(n){delete i.from;const c=p(e);return Promise.resolve(n.functions.addDelegate(o.address,c,t,r,i)).then(function(e){return Promise.resolve(e.wait())})})}catch(e){return Promise.reject(e)}}revokeDelegate(e,t,r={}){try{const n=this,o={gasLimit:123456,gasPrice:1e9,...r};return e=e.startsWith("0x")?e:p(e),Promise.resolve(n.attachContract(o.from)).then(function(r){return delete o.from,Promise.resolve(r.functions.revokeDelegate(n.address,e,t,o)).then(function(e){return Promise.resolve(e.wait())})})}catch(e){return Promise.reject(e)}}setAttribute(e,t,r,n={}){try{const o=this,i={gasLimit:123456,gasPrice:1e9,controller:void 0,...n};return e=e.startsWith("0x")?e:p(e),t=t.startsWith("0x")?t:"0x"+Buffer.from(t,"utf-8").toString("hex"),Promise.resolve(o.attachContract(i.from)).then(function(n){return delete i.from,Promise.resolve(n.functions.setAttribute(o.address,e,t,r,i)).then(function(e){return Promise.resolve(e.wait())})})}catch(e){return Promise.reject(e)}}revokeAttribute(e,t,r={}){try{const n=this,o={gasLimit:123456,gasPrice:1e9,...r};return e=e.startsWith("0x")?e:p(e),t=t.startsWith("0x")?t:"0x"+Buffer.from(t,"utf-8").toString("hex"),Promise.resolve(n.attachContract(o.from)).then(function(r){return delete o.from,Promise.resolve(r.functions.revokeAttribute(n.address,e,t,o)).then(function(e){return Promise.resolve(e.wait())})})}catch(e){return Promise.reject(e)}}}function I(e,t,r){if(!e.s){if(r instanceof K){if(!r.s)return void(r.o=I.bind(null,e,t));1&t&&(t=r.s),r=r.v}if(r&&r.then)return void r.then(I.bind(null,e,t),I.bind(null,e,2));e.s=t,e.v=r;const n=e.o;n&&n(e)}}const K=function(){function e(){}return e.prototype.then=function(t,r){const n=new e,o=this.s;if(o){const e=1&o?t:r;if(e){try{I(n,1,e(this.v))}catch(e){I(n,2,e)}return n}return this}return this.o=function(e){try{const o=e.v;1&e.s?I(n,1,t?t(o):o):r?I(n,1,r(o)):I(n,2,o)}catch(e){I(n,2,e)}},n},e}();function S(e){return e instanceof K&&1&e.s}class N{constructor(e){this.contracts=function(e={}){const t={...(r=e.infuraProjectId,r?D({networks:[{name:"mainnet",chainId:"0x1",provider:new n.InfuraProvider("homestead",r)},{name:"ropsten",chainId:"0x3",provider:new n.InfuraProvider("ropsten",r)},{name:"rinkeby",chainId:"0x4",provider:new n.InfuraProvider("rinkeby",r)},{name:"goerli",chainId:"0x5",provider:new n.InfuraProvider("goerli",r)},{name:"kovan",chainId:"0x2a",provider:new n.InfuraProvider("kovan",r)}]}):{}),...D(e)};var r;if(0===Object.keys(t).length)throw new Error("invalid_config: Please make sure to have at least one network");return t}(e)}getOwner(e,t,r){try{return Promise.resolve(new P(e,this.contracts[t]).getOwner(e,r))}catch(e){return Promise.reject(e)}}previousChange(e,r,n){try{return Promise.resolve(this.contracts[r].functions.changed(e,{blockTag:n})).then(function(e){return t.BigNumber.from(e[0])})}catch(e){return Promise.reject(e)}}getBlockMetadata(e,t){try{return Promise.resolve(this.contracts[t].provider.getBlock(e)).then(function(e){return{height:e.number.toString(),isoDate:new Date(1e3*e.timestamp).toISOString()}})}catch(e){return Promise.reject(e)}}changeLog(e,r,n="latest"){try{const o=this,i=o.contracts[r],c=i.provider,s=r.startsWith("0x")?r:b[r];return Promise.resolve(c.getNetwork()).then(function(a){const d=a.chainId,u=s?t.BigNumber.from(s).toNumber():d,h=[],{address:l,publicKey:f}=g(e),v=f;return Promise.resolve(o.previousChange(l,r,n)).then(function(e){function r(){return{address:l,history:h,controllerKey:v,chainId:u}}const n=function(e,t,r){for(var n;;){var o=e();if(S(o)&&(o=o.v),!o)return i;if(o.then){n=0;break}var i=r();if(i&&i.then){if(!S(i)){n=1;break}i=i.s}}var c=new K,s=I.bind(null,c,2);return(0===n?o.then(d):1===n?i.then(a):(void 0).then(function(){(o=e())?o.then?o.then(d).then(void 0,s):d(o):I(c,1,i)})).then(void 0,s),c;function a(t){i=t;do{if(!(o=e())||S(o)&&!o.v)return void I(c,1,i);if(o.then)return void o.then(d).then(void 0,s);S(i=r())&&(i=i.v)}while(!i||!i.then);i.then(a).then(void 0,s)}function d(e){e?(i=r())&&i.then?i.then(a).then(void 0,s):a(i):I(c,1,i)}}(function(){return!!e},0,function(){const r=e;return Promise.resolve(c.getLogs({address:i.address,topics:[null,`0x000000000000000000000000${l.slice(2)}`],fromBlock:e.toHexString(),toBlock:e.toHexString()})).then(function(n){const o=function(e,r){return r.map(r=>function(e,r){const n={};if(e.eventFragment.inputs.length!==e.args.length)throw new TypeError("malformed event input. wrong number of arguments");return e.eventFragment.inputs.forEach((r,o)=>{let i=e.args[o];"object"==typeof i&&(i=t.BigNumber.from(i)),"bytes32"===r.type&&(i=m(i)),n[r.name]=i}),n._eventName=e.name,n.blockNumber=r,n}(e.interface.parseLog(r),r.blockNumber))}(i,n);o.reverse(),e=null;for(const t of o)h.unshift(t),t.previousChange.lt(r)&&(e=t.previousChange)})});return n&&n.then?n.then(r):r()})})}catch(e){return Promise.reject(e)}}wrapDidDocument(r,n,o,i,c,s,a){var d;const u={"@context":["https://www.w3.org/ns/did/v1","https://identity.foundation/EcdsaSecp256k1RecoverySignature2020/lds-ecdsa-secp256k1-recovery2020-0.0.jsonld"],id:r,verificationMethod:[],authentication:[],assertionMethod:[]};let h=n;const m=[`${r}#controller`];let p=0,g=Number.POSITIVE_INFINITY,y=!1,b=0,x=0;const w={},k={},D={};for(const n of i){if(-1!==s&&n.blockNumber>s){g>n.blockNumber&&(g=n.blockNumber);continue}p<n.blockNumber&&(p=n.blockNumber);const o=n.validTo||t.BigNumber.from(0),i=`${n._eventName}-${n.delegateType||n.name}-${n.delegate||n.value}`;if(o&&o.gte(a)){if(n._eventName===l.DIDDelegateChanged){const e=n;switch(b++,e.delegateType){case"sigAuth":w[i]=`${r}#delegate-${b}`;case"veriKey":k[i]={id:`${r}#delegate-${b}`,type:exports.verificationMethodTypes.EcdsaSecp256k1RecoveryMethod2020,controller:r,blockchainAccountId:`${e.delegate}@eip155:${c}`}}}else if(n._eventName===l.DIDAttributeChanged){const t=n,o=t.name.match(/^did\/(pub|svc)\/(\w+)(\/(\w+))?(\/(\w+))?$/);if(o){const n=o[2],c=f[o[4]]||o[4],s=o[6];switch(o[1]){case"pub":{b++;const a={id:`${r}#delegate-${b}`,type:`${n}${c}`,controller:r};switch(a.type=v[a.type]||n,s){case null:case void 0:case"hex":a.publicKeyHex=t.value.slice(2);break;case"base64":a.publicKeyBase64=Buffer.from(t.value.slice(2),"hex").toString("base64");break;case"base58":a.publicKeyBase58=e.Base58.encode(Buffer.from(t.value.slice(2),"hex"));break;case"pem":a.publicKeyPem=Buffer.from(t.value.slice(2),"hex").toString();break;default:a.value=t.value}k[i]=a,"sigAuth"===o[4]&&(w[i]=a.id);break}case"svc":x++,D[i]={id:`${r}#service-${x}`,type:n,serviceEndpoint:Buffer.from(t.value.slice(2),"hex").toString()}}}}}else if(n._eventName===l.DIDOwnerChanged){if(h=n.owner,"0x0000000000000000000000000000000000000000"===n.owner){y=!0;break}}else n._eventName===l.DIDDelegateChanged||n._eventName===l.DIDAttributeChanged&&n.name.match(/^did\/pub\//)?b++:n._eventName===l.DIDAttributeChanged&&n.name.match(/^did\/svc\//)&&x++,delete w[i],delete k[i],delete D[i]}const P=[{id:`${r}#controller`,type:exports.verificationMethodTypes.EcdsaSecp256k1RecoveryMethod2020,controller:r,blockchainAccountId:`${h}@eip155:${c}`}];o&&h==n&&(P.push({id:`${r}#controllerKey`,type:exports.verificationMethodTypes.EcdsaSecp256k1VerificationKey2019,controller:r,publicKeyHex:o}),m.push(`${r}#controllerKey`));const I={...u,verificationMethod:P.concat(Object.values(k)),authentication:m.concat(Object.values(w))};return Object.values(D).length>0&&(I.service=Object.values(D)),I.assertionMethod=[...(null==(d=I.verificationMethod)?void 0:d.map(e=>e.id))||[]],y?{didDocument:{...u,"@context":"https://www.w3.org/ns/did/v1"},deactivated:y,versionId:p,nextVersionId:g}:{didDocument:I,deactivated:y,versionId:p,nextVersionId:g}}resolve(e,r,n,o){try{const n=this;function i(){return Promise.resolve(n.changeLog(a,d,"latest")).then(function({address:t,history:r,controllerKey:o,chainId:i}){return function(c,s){try{var a=function(){function c(){function e(){return{didDocumentMetadata:{...v,...m,...p},didResolutionMetadata:{contentType:"application/did+ld+json"},didDocument:s}}const t=function(){if(f!==Number.POSITIVE_INFINITY)return Promise.resolve(n.getBlockMetadata(f,d)).then(function(e){p={nextVersionId:e.height,nextUpdate:e.isoDate}})}();return t&&t.then?t.then(e):e()}const{didDocument:s,deactivated:a,versionId:u,nextVersionId:f}=n.wrapDidDocument(e,t,o,r,i,h,l),v=a?{deactivated:!0}:{};let m={},p={};const g=function(){if(0!==u)return Promise.resolve(n.getBlockMetadata(u,d)).then(function(e){m={versionId:e.height,updated:e.isoDate}})}();return g&&g.then?g.then(c):c()}()}catch(e){return s(e)}return a&&a.then?a.then(void 0,s):a}(0,function(e){return{didResolutionMetadata:{error:exports.Errors.notFound,message:e.toString()},didDocumentMetadata:{},didDocument:null}})})}const c=r.id.match(u);if(!c)return Promise.resolve({didResolutionMetadata:{error:exports.Errors.invalidDid,message:`Not a valid did:ethr: ${r.id}`},didDocumentMetadata:{},didDocument:null});const a=c[2],d=c[1]?c[1].slice(0,-1):"mainnet";let h=o.blockTag||"latest";if("string"==typeof r.query){const e=s.decode(r.query);h="string"==typeof e.versionId?e.versionId:h;try{h=Number.parseInt(h)}catch(e){h="latest"}}if(!n.contracts[d])return Promise.resolve({didResolutionMetadata:{error:exports.Errors.unknownNetwork,message:`The DID resolver does not have a configuration for network: ${d}`},didDocumentMetadata:{},didDocument:null});let l=t.BigNumber.from(Math.floor((new Date).getTime()/1e3));const f=function(){if("number"==typeof h)return Promise.resolve(n.getBlockMetadata(h,d)).then(function(e){l=t.BigNumber.from(Date.parse(e.isoDate)/1e3)})}();return Promise.resolve(f&&f.then?f.then(i):i())}catch(e){return Promise.reject(e)}}build(){return{ethr:this.resolve.bind(this)}}}exports.EthrDidController=P,exports.REGISTRY="0xdca7ef03e98e0dc2b855be647c39abe984fcf21b",exports.attrTypes=f,exports.bytes32toString=m,exports.delegateTypes=v,exports.getResolver=function(e){return new N(e).build()},exports.identifierMatcher=u,exports.interpretIdentifier=g,exports.stringToBytes32=p; | ||
//# sourceMappingURL=index.js.map |
@@ -1,2 +0,2 @@ | ||
import{Base58 as e}from"@ethersproject/basex";import{BigNumber as t}from"@ethersproject/bignumber";import{ContractFactory as r}from"@ethersproject/contracts";import{JsonRpcProvider as n,InfuraProvider as a}from"@ethersproject/providers";import i from"ethr-did-registry";import{getAddress as o}from"@ethersproject/address";import{computeAddress as c}from"@ethersproject/transactions";import{decode as s}from"querystring";function d(){return(d=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e}).apply(this,arguments)}const l=/^(.*)?(0x[0-9a-fA-F]{40}|0x[0-9a-fA-F]{66})$/,u="0xdca7ef03e98e0dc2b855be647c39abe984fcf21b";var h,f;!function(e){e.EcdsaSecp256k1VerificationKey2019="EcdsaSecp256k1VerificationKey2019",e.EcdsaSecp256k1RecoveryMethod2020="EcdsaSecp256k1RecoveryMethod2020",e.Ed25519VerificationKey2018="Ed25519VerificationKey2018",e.RSAVerificationKey2018="RSAVerificationKey2018",e.X25519KeyAgreementKey2019="X25519KeyAgreementKey2019"}(h||(h={})),function(e){e.DIDOwnerChanged="DIDOwnerChanged",e.DIDAttributeChanged="DIDAttributeChanged",e.DIDDelegateChanged="DIDDelegateChanged"}(f||(f={}));const m={sigAuth:"SignatureAuthentication2018",veriKey:"VerificationKey2018",enc:"KeyAgreementKey2019"},g={Secp256k1VerificationKey2018:h.EcdsaSecp256k1VerificationKey2019,Ed25519SignatureAuthentication2018:h.Ed25519VerificationKey2018,Secp256k1SignatureAuthentication2018:h.EcdsaSecp256k1VerificationKey2019,RSAVerificationKey2018:h.RSAVerificationKey2018,Ed25519VerificationKey2018:h.Ed25519VerificationKey2018,X25519KeyAgreementKey2019:h.X25519KeyAgreementKey2019};function p(e){return("string"==typeof e?Buffer.from(e.slice(2),"hex"):Buffer.from(e)).toString("utf8").replace(/\0+$/,"")}function v(e){const t="0x"+Buffer.from(e).slice(0,32).toString("hex");return t+"0".repeat(66-t.length)}function y(e){let t,r=e;if(r.startsWith("did:ethr")){const e=r.split(":");r=e[e.length-1],e.length>=4&&(t=e.splice(2,e.length-3).join(":"))}return r.length>42?{address:c(r),publicKey:r,network:t}:{address:o(r),network:t}}const w={mainnet:"0x1",ropsten:"0x3",rinkeby:"0x4",goerli:"0x5",kovan:"0x2a"},b=d({},w,{rsk:"0x1e","rsk:testnet":"0x1f",artis_t1:"0x03c401",artis_s1:"0x03c301",matic:"0x89",maticmum:"0x13881"});var k;function D(e){var a;let o=e.provider||(null==(a=e.web3)?void 0:a.currentProvider);if(!o){if(!e.rpcUrl)throw new Error(`invalid_config: No web3 provider could be determined for network ${e.name||e.chainId}`);{var c;const r=e.chainId?e.chainId:b[e.name||""],a=r?t.from(r).toNumber():r,i=w[e.name||""]?null==(c=e.name)?void 0:c.replace("mainnet","homestead"):"any";o=new n(e.rpcUrl,a||i)}}return r.fromSolidity(i).attach(e.registry||"0xdca7ef03e98e0dc2b855be647c39abe984fcf21b").connect(o)}function x(e){const t={},r=e.chainId||b[e.name||""];return r?(e.name&&(t[e.name]=D(e)),t["number"==typeof r?`0x${r.toString(16)}`:r]=D(e)):(e.provider||e.web3||e.rpcUrl)&&(t[e.name||""]=D(e)),t}function I(e){var t;return d({},x(e),null==(t=e.networks)?void 0:t.reduce((e,t)=>d({},e,x(t)),{}))}!function(e){e.notFound="notFound",e.invalidDid="invalidDid",e.unknownNetwork="unknownNetwork"}(k||(k={}));class K{constructor(e,t,r,n="mainnet",a,i,o="0xdca7ef03e98e0dc2b855be647c39abe984fcf21b"){const{address:c,publicKey:s,network:d}=y(e),l=d||n;if(t)this.contract=t;else{if(!(a||null!=r&&r.provider))throw new Error(" either a contract instance or a provider or rpcUrl is required to initialize");this.contract=D({name:l,provider:a||(null==r?void 0:r.provider),registry:o,rpcUrl:i})}this.signer=r,this.address=c;let u=l?`${l}:`:"";u in["mainnet:","0x1:"]&&(u=""),this.did=s?`did:ethr:${u}${s}`:`did:ethr:${u}${c}`}async getOwner(e,t){return(await this.contract.functions.identityOwner(e,{blockTag:t}))[0]}async attachContract(e){const t=e?await e:await this.getOwner(this.address,"latest"),r=this.signer?this.signer:this.contract.provider.getSigner(t)||this.contract.signer;return this.contract.connect(r)}async changeOwner(e,t={}){const r=d({gasLimit:123456,gasPrice:1e9},t),n=await this.attachContract(r.from);delete r.from;const a=await n.functions.changeOwner(this.address,e,r);return await a.wait()}async addDelegate(e,t,r,n={}){const a=d({gasLimit:123456,gasPrice:1e9},n),i=await this.attachContract(a.from);delete a.from;const o=v(e),c=await i.functions.addDelegate(this.address,o,t,r,a);return await c.wait()}async revokeDelegate(e,t,r={}){const n=d({gasLimit:123456,gasPrice:1e9},r);e=e.startsWith("0x")?e:v(e);const a=await this.attachContract(n.from);delete n.from;const i=await a.functions.revokeDelegate(this.address,e,t,n);return await i.wait()}async setAttribute(e,t,r,n={}){const a=d({gasLimit:123456,gasPrice:1e9,controller:void 0},n);e=e.startsWith("0x")?e:v(e),t=t.startsWith("0x")?t:"0x"+Buffer.from(t,"utf-8").toString("hex");const i=await this.attachContract(a.from);delete a.from;const o=await i.functions.setAttribute(this.address,e,t,r,a);return await o.wait()}async revokeAttribute(e,t,r={}){const n=d({gasLimit:123456,gasPrice:1e9},r);e=e.startsWith("0x")?e:v(e),t=t.startsWith("0x")?t:"0x"+Buffer.from(t,"utf-8").toString("hex");const a=await this.attachContract(n.from);delete n.from;const i=await a.functions.revokeAttribute(this.address,e,t,n);return await i.wait()}}function S(e,r){return r.map(r=>function(e,r){const n={};if(e.eventFragment.inputs.length!==e.args.length)throw new TypeError("malformed event input. wrong number of arguments");return e.eventFragment.inputs.forEach((r,a)=>{let i=e.args[a];"object"==typeof i&&(i=t.from(i)),"bytes32"===r.type&&(i=p(i)),n[r.name]=i}),n._eventName=e.name,n.blockNumber=r,n}(e.interface.parseLog(r),r.blockNumber))}function $(e){return new N(e).build()}class N{constructor(e){this.contracts=function(e={}){const t=d({},(r=e.infuraProjectId)?I({networks:[{name:"mainnet",chainId:"0x1",provider:new a("homestead",r)},{name:"ropsten",chainId:"0x3",provider:new a("ropsten",r)},{name:"rinkeby",chainId:"0x4",provider:new a("rinkeby",r)},{name:"goerli",chainId:"0x5",provider:new a("goerli",r)},{name:"kovan",chainId:"0x2a",provider:new a("kovan",r)}]}):{},I(e));var r;if(0===Object.keys(t).length)throw new Error("invalid_config: Please make sure to have at least one network");return t}(e)}async getOwner(e,t,r){return new K(e,this.contracts[t]).getOwner(e,r)}async previousChange(e,r,n){const a=await this.contracts[r].functions.changed(e,{blockTag:n});return t.from(a[0])}async getBlockMetadata(e,t){const r=await this.contracts[t].provider.getBlock(e);return{height:r.number.toString(),isoDate:new Date(1e3*r.timestamp).toISOString()}}async changeLog(e,r,n="latest"){const a=this.contracts[r],i=a.provider,o=r.startsWith("0x")?r:b[r],c=(await i.getNetwork()).chainId,s=o?t.from(o).toNumber():c,d=[],{address:l,publicKey:u}=y(e),h=u;let f=await this.previousChange(l,r,n);for(;f;){const e=f,t=S(a,await i.getLogs({address:a.address,topics:[null,`0x000000000000000000000000${l.slice(2)}`],fromBlock:f.toHexString(),toBlock:f.toHexString()}));t.reverse(),f=null;for(const r of t)d.unshift(r),r.previousChange.lt(e)&&(f=r.previousChange)}return{address:l,history:d,controllerKey:h,chainId:s}}wrapDidDocument(r,n,a,i,o,c,s){const l={"@context":["https://www.w3.org/ns/did/v1","https://identity.foundation/EcdsaSecp256k1RecoverySignature2020/lds-ecdsa-secp256k1-recovery2020-0.0.jsonld"],id:r,verificationMethod:[],authentication:[]};let u=n;const p=[`${r}#controller`];let v=0,y=Number.POSITIVE_INFINITY,w=!1,b=0,k=0;const D={},x={},I={};for(const n of i){if(-1!==c&&n.blockNumber>c){y>n.blockNumber&&(y=n.blockNumber);continue}v<n.blockNumber&&(v=n.blockNumber);const a=n.validTo||t.from(0),i=`${n._eventName}-${n.delegateType||n.name}-${n.delegate||n.value}`;if(a&&a.gte(s)){if(n._eventName===f.DIDDelegateChanged){const e=n;switch(b++,e.delegateType){case"sigAuth":D[i]=`${r}#delegate-${b}`;case"veriKey":x[i]={id:`${r}#delegate-${b}`,type:h.EcdsaSecp256k1RecoveryMethod2020,controller:r,blockchainAccountId:`${e.delegate}@eip155:${o}`}}}else if(n._eventName===f.DIDAttributeChanged){const t=n,a=t.name.match(/^did\/(pub|svc)\/(\w+)(\/(\w+))?(\/(\w+))?$/);if(a){const n=a[2],o=m[a[4]]||a[4],c=a[6];switch(a[1]){case"pub":{b++;const s={id:`${r}#delegate-${b}`,type:`${n}${o}`,controller:r};switch(s.type=g[s.type]||n,c){case null:case void 0:case"hex":s.publicKeyHex=t.value.slice(2);break;case"base64":s.publicKeyBase64=Buffer.from(t.value.slice(2),"hex").toString("base64");break;case"base58":s.publicKeyBase58=e.encode(Buffer.from(t.value.slice(2),"hex"));break;case"pem":s.publicKeyPem=Buffer.from(t.value.slice(2),"hex").toString();break;default:s.value=t.value}x[i]=s,"sigAuth"===a[4]&&(D[i]=s.id);break}case"svc":k++,I[i]={id:`${r}#service-${k}`,type:n,serviceEndpoint:Buffer.from(t.value.slice(2),"hex").toString()}}}}}else if(n._eventName===f.DIDOwnerChanged){if(u=n.owner,"0x0000000000000000000000000000000000000000"===n.owner){w=!0;break}}else n._eventName===f.DIDDelegateChanged||n._eventName===f.DIDAttributeChanged&&n.name.match(/^did\/pub\//)?b++:n._eventName===f.DIDAttributeChanged&&n.name.match(/^did\/svc\//)&&k++,delete D[i],delete x[i],delete I[i]}const K=[{id:`${r}#controller`,type:h.EcdsaSecp256k1RecoveryMethod2020,controller:r,blockchainAccountId:`${u}@eip155:${o}`}];a&&u==n&&(K.push({id:`${r}#controllerKey`,type:h.EcdsaSecp256k1VerificationKey2019,controller:r,publicKeyHex:a}),p.push(`${r}#controllerKey`));const S=d({},l,{verificationMethod:K.concat(Object.values(x)),authentication:p.concat(Object.values(D))});return Object.values(I).length>0&&(S.service=Object.values(I)),w?{didDocument:d({},l,{"@context":"https://www.w3.org/ns/did/v1"}),deactivated:w,versionId:v,nextVersionId:y}:{didDocument:S,deactivated:w,versionId:v,nextVersionId:y}}async resolve(e,r,n,a){const i=r.id.match(l);if(!i)return{didResolutionMetadata:{error:k.invalidDid,message:`Not a valid did:ethr: ${r.id}`},didDocumentMetadata:{},didDocument:null};const o=i[2],c=i[1]?i[1].slice(0,-1):"mainnet";let u=a.blockTag||"latest";if("string"==typeof r.query){const e=s(r.query);u="string"==typeof e.versionId?e.versionId:u;try{u=Number.parseInt(u)}catch(e){u="latest"}}if(!this.contracts[c])return{didResolutionMetadata:{error:k.unknownNetwork,message:`The DID resolver does not have a configuration for network: ${c}`},didDocumentMetadata:{},didDocument:null};let h=t.from(Math.floor((new Date).getTime()/1e3));if("number"==typeof u){const e=await this.getBlockMetadata(u,c);h=t.from(Date.parse(e.isoDate)/1e3)}const{address:f,history:m,controllerKey:g,chainId:p}=await this.changeLog(o,c,"latest");try{const{didDocument:t,deactivated:r,versionId:n,nextVersionId:a}=this.wrapDidDocument(e,f,g,m,p,u,h),i=r?{deactivated:!0}:{};let o={},s={};if(0!==n){const e=await this.getBlockMetadata(n,c);o={versionId:e.height,updated:e.isoDate}}if(a!==Number.POSITIVE_INFINITY){const e=await this.getBlockMetadata(a,c);s={nextVersionId:e.height,nextUpdate:e.isoDate}}return{didDocumentMetadata:d({},i,o,s),didResolutionMetadata:{contentType:"application/did+ld+json"},didDocument:t}}catch(e){return{didResolutionMetadata:{error:k.notFound,message:e.toString()},didDocumentMetadata:{},didDocument:null}}}build(){return{ethr:this.resolve.bind(this)}}}export{k as Errors,K as EthrDidController,u as REGISTRY,m as attrTypes,p as bytes32toString,g as delegateTypes,$ as getResolver,l as identifierMatcher,y as interpretIdentifier,v as stringToBytes32,h as verificationMethodTypes}; | ||
import{Base58 as e}from"@ethersproject/basex";import{BigNumber as t}from"@ethersproject/bignumber";import{ContractFactory as r}from"@ethersproject/contracts";import{JsonRpcProvider as n,InfuraProvider as i}from"@ethersproject/providers";import a from"ethr-did-registry";import{getAddress as o}from"@ethersproject/address";import{computeAddress as c}from"@ethersproject/transactions";import{decode as s}from"querystring";function d(){return(d=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e}).apply(this,arguments)}const l=/^(.*)?(0x[0-9a-fA-F]{40}|0x[0-9a-fA-F]{66})$/,u="0xdca7ef03e98e0dc2b855be647c39abe984fcf21b";var h,f;!function(e){e.EcdsaSecp256k1VerificationKey2019="EcdsaSecp256k1VerificationKey2019",e.EcdsaSecp256k1RecoveryMethod2020="EcdsaSecp256k1RecoveryMethod2020",e.Ed25519VerificationKey2018="Ed25519VerificationKey2018",e.RSAVerificationKey2018="RSAVerificationKey2018",e.X25519KeyAgreementKey2019="X25519KeyAgreementKey2019"}(h||(h={})),function(e){e.DIDOwnerChanged="DIDOwnerChanged",e.DIDAttributeChanged="DIDAttributeChanged",e.DIDDelegateChanged="DIDDelegateChanged"}(f||(f={}));const m={sigAuth:"SignatureAuthentication2018",veriKey:"VerificationKey2018",enc:"KeyAgreementKey2019"},g={Secp256k1VerificationKey2018:h.EcdsaSecp256k1VerificationKey2019,Ed25519SignatureAuthentication2018:h.Ed25519VerificationKey2018,Secp256k1SignatureAuthentication2018:h.EcdsaSecp256k1VerificationKey2019,RSAVerificationKey2018:h.RSAVerificationKey2018,Ed25519VerificationKey2018:h.Ed25519VerificationKey2018,X25519KeyAgreementKey2019:h.X25519KeyAgreementKey2019};function p(e){return("string"==typeof e?Buffer.from(e.slice(2),"hex"):Buffer.from(e)).toString("utf8").replace(/\0+$/,"")}function v(e){const t="0x"+Buffer.from(e).slice(0,32).toString("hex");return t+"0".repeat(66-t.length)}function y(e){let t,r=e;if(r.startsWith("did:ethr")){const e=r.split(":");r=e[e.length-1],e.length>=4&&(t=e.splice(2,e.length-3).join(":"))}return r.length>42?{address:c(r),publicKey:r,network:t}:{address:o(r),network:t}}const w={mainnet:"0x1",ropsten:"0x3",rinkeby:"0x4",goerli:"0x5",kovan:"0x2a"},b=d({},w,{rsk:"0x1e","rsk:testnet":"0x1f",artis_t1:"0x03c401",artis_s1:"0x03c301",matic:"0x89",maticmum:"0x13881"});var k;function D(e){var i;let o=e.provider||(null==(i=e.web3)?void 0:i.currentProvider);if(!o){if(!e.rpcUrl)throw new Error(`invalid_config: No web3 provider could be determined for network ${e.name||e.chainId}`);{var c;const r=e.chainId?e.chainId:b[e.name||""],i=r?t.from(r).toNumber():r,a=w[e.name||""]?null==(c=e.name)?void 0:c.replace("mainnet","homestead"):"any";o=new n(e.rpcUrl,i||a)}}return r.fromSolidity(a).attach(e.registry||"0xdca7ef03e98e0dc2b855be647c39abe984fcf21b").connect(o)}function x(e){const t={},r=e.chainId||b[e.name||""];return r?(e.name&&(t[e.name]=D(e)),t["number"==typeof r?`0x${r.toString(16)}`:r]=D(e)):(e.provider||e.web3||e.rpcUrl)&&(t[e.name||""]=D(e)),t}function I(e){var t;return d({},x(e),null==(t=e.networks)?void 0:t.reduce((e,t)=>d({},e,x(t)),{}))}!function(e){e.notFound="notFound",e.invalidDid="invalidDid",e.unknownNetwork="unknownNetwork"}(k||(k={}));class K{constructor(e,t,r,n="mainnet",i,a,o="0xdca7ef03e98e0dc2b855be647c39abe984fcf21b"){const{address:c,publicKey:s,network:d}=y(e),l=d||n;if(t)this.contract=t;else{if(!(i||null!=r&&r.provider))throw new Error(" either a contract instance or a provider or rpcUrl is required to initialize");this.contract=D({name:l,provider:i||(null==r?void 0:r.provider),registry:o,rpcUrl:a})}this.signer=r,this.address=c;let u=l?`${l}:`:"";u in["mainnet:","0x1:"]&&(u=""),this.did=s?`did:ethr:${u}${s}`:`did:ethr:${u}${c}`}async getOwner(e,t){return(await this.contract.functions.identityOwner(e,{blockTag:t}))[0]}async attachContract(e){const t=e?await e:await this.getOwner(this.address,"latest"),r=this.signer?this.signer:this.contract.provider.getSigner(t)||this.contract.signer;return this.contract.connect(r)}async changeOwner(e,t={}){const r=d({gasLimit:123456,gasPrice:1e9},t),n=await this.attachContract(r.from);delete r.from;const i=await n.functions.changeOwner(this.address,e,r);return await i.wait()}async addDelegate(e,t,r,n={}){const i=d({gasLimit:123456,gasPrice:1e9},n),a=await this.attachContract(i.from);delete i.from;const o=v(e),c=await a.functions.addDelegate(this.address,o,t,r,i);return await c.wait()}async revokeDelegate(e,t,r={}){const n=d({gasLimit:123456,gasPrice:1e9},r);e=e.startsWith("0x")?e:v(e);const i=await this.attachContract(n.from);delete n.from;const a=await i.functions.revokeDelegate(this.address,e,t,n);return await a.wait()}async setAttribute(e,t,r,n={}){const i=d({gasLimit:123456,gasPrice:1e9,controller:void 0},n);e=e.startsWith("0x")?e:v(e),t=t.startsWith("0x")?t:"0x"+Buffer.from(t,"utf-8").toString("hex");const a=await this.attachContract(i.from);delete i.from;const o=await a.functions.setAttribute(this.address,e,t,r,i);return await o.wait()}async revokeAttribute(e,t,r={}){const n=d({gasLimit:123456,gasPrice:1e9},r);e=e.startsWith("0x")?e:v(e),t=t.startsWith("0x")?t:"0x"+Buffer.from(t,"utf-8").toString("hex");const i=await this.attachContract(n.from);delete n.from;const a=await i.functions.revokeAttribute(this.address,e,t,n);return await a.wait()}}function S(e,r){return r.map(r=>function(e,r){const n={};if(e.eventFragment.inputs.length!==e.args.length)throw new TypeError("malformed event input. wrong number of arguments");return e.eventFragment.inputs.forEach((r,i)=>{let a=e.args[i];"object"==typeof a&&(a=t.from(a)),"bytes32"===r.type&&(a=p(a)),n[r.name]=a}),n._eventName=e.name,n.blockNumber=r,n}(e.interface.parseLog(r),r.blockNumber))}function $(e){return new N(e).build()}class N{constructor(e){this.contracts=function(e={}){const t=d({},(r=e.infuraProjectId)?I({networks:[{name:"mainnet",chainId:"0x1",provider:new i("homestead",r)},{name:"ropsten",chainId:"0x3",provider:new i("ropsten",r)},{name:"rinkeby",chainId:"0x4",provider:new i("rinkeby",r)},{name:"goerli",chainId:"0x5",provider:new i("goerli",r)},{name:"kovan",chainId:"0x2a",provider:new i("kovan",r)}]}):{},I(e));var r;if(0===Object.keys(t).length)throw new Error("invalid_config: Please make sure to have at least one network");return t}(e)}async getOwner(e,t,r){return new K(e,this.contracts[t]).getOwner(e,r)}async previousChange(e,r,n){const i=await this.contracts[r].functions.changed(e,{blockTag:n});return t.from(i[0])}async getBlockMetadata(e,t){const r=await this.contracts[t].provider.getBlock(e);return{height:r.number.toString(),isoDate:new Date(1e3*r.timestamp).toISOString()}}async changeLog(e,r,n="latest"){const i=this.contracts[r],a=i.provider,o=r.startsWith("0x")?r:b[r],c=(await a.getNetwork()).chainId,s=o?t.from(o).toNumber():c,d=[],{address:l,publicKey:u}=y(e),h=u;let f=await this.previousChange(l,r,n);for(;f;){const e=f,t=S(i,await a.getLogs({address:i.address,topics:[null,`0x000000000000000000000000${l.slice(2)}`],fromBlock:f.toHexString(),toBlock:f.toHexString()}));t.reverse(),f=null;for(const r of t)d.unshift(r),r.previousChange.lt(e)&&(f=r.previousChange)}return{address:l,history:d,controllerKey:h,chainId:s}}wrapDidDocument(r,n,i,a,o,c,s){var l;const u={"@context":["https://www.w3.org/ns/did/v1","https://identity.foundation/EcdsaSecp256k1RecoverySignature2020/lds-ecdsa-secp256k1-recovery2020-0.0.jsonld"],id:r,verificationMethod:[],authentication:[],assertionMethod:[]};let p=n;const v=[`${r}#controller`];let y=0,w=Number.POSITIVE_INFINITY,b=!1,k=0,D=0;const x={},I={},K={};for(const n of a){if(-1!==c&&n.blockNumber>c){w>n.blockNumber&&(w=n.blockNumber);continue}y<n.blockNumber&&(y=n.blockNumber);const i=n.validTo||t.from(0),a=`${n._eventName}-${n.delegateType||n.name}-${n.delegate||n.value}`;if(i&&i.gte(s)){if(n._eventName===f.DIDDelegateChanged){const e=n;switch(k++,e.delegateType){case"sigAuth":x[a]=`${r}#delegate-${k}`;case"veriKey":I[a]={id:`${r}#delegate-${k}`,type:h.EcdsaSecp256k1RecoveryMethod2020,controller:r,blockchainAccountId:`${e.delegate}@eip155:${o}`}}}else if(n._eventName===f.DIDAttributeChanged){const t=n,i=t.name.match(/^did\/(pub|svc)\/(\w+)(\/(\w+))?(\/(\w+))?$/);if(i){const n=i[2],o=m[i[4]]||i[4],c=i[6];switch(i[1]){case"pub":{k++;const s={id:`${r}#delegate-${k}`,type:`${n}${o}`,controller:r};switch(s.type=g[s.type]||n,c){case null:case void 0:case"hex":s.publicKeyHex=t.value.slice(2);break;case"base64":s.publicKeyBase64=Buffer.from(t.value.slice(2),"hex").toString("base64");break;case"base58":s.publicKeyBase58=e.encode(Buffer.from(t.value.slice(2),"hex"));break;case"pem":s.publicKeyPem=Buffer.from(t.value.slice(2),"hex").toString();break;default:s.value=t.value}I[a]=s,"sigAuth"===i[4]&&(x[a]=s.id);break}case"svc":D++,K[a]={id:`${r}#service-${D}`,type:n,serviceEndpoint:Buffer.from(t.value.slice(2),"hex").toString()}}}}}else if(n._eventName===f.DIDOwnerChanged){if(p=n.owner,"0x0000000000000000000000000000000000000000"===n.owner){b=!0;break}}else n._eventName===f.DIDDelegateChanged||n._eventName===f.DIDAttributeChanged&&n.name.match(/^did\/pub\//)?k++:n._eventName===f.DIDAttributeChanged&&n.name.match(/^did\/svc\//)&&D++,delete x[a],delete I[a],delete K[a]}const S=[{id:`${r}#controller`,type:h.EcdsaSecp256k1RecoveryMethod2020,controller:r,blockchainAccountId:`${p}@eip155:${o}`}];i&&p==n&&(S.push({id:`${r}#controllerKey`,type:h.EcdsaSecp256k1VerificationKey2019,controller:r,publicKeyHex:i}),v.push(`${r}#controllerKey`));const $=d({},u,{verificationMethod:S.concat(Object.values(I)),authentication:v.concat(Object.values(x))});return Object.values(K).length>0&&($.service=Object.values(K)),$.assertionMethod=[...(null==(l=$.verificationMethod)?void 0:l.map(e=>e.id))||[]],b?{didDocument:d({},u,{"@context":"https://www.w3.org/ns/did/v1"}),deactivated:b,versionId:y,nextVersionId:w}:{didDocument:$,deactivated:b,versionId:y,nextVersionId:w}}async resolve(e,r,n,i){const a=r.id.match(l);if(!a)return{didResolutionMetadata:{error:k.invalidDid,message:`Not a valid did:ethr: ${r.id}`},didDocumentMetadata:{},didDocument:null};const o=a[2],c=a[1]?a[1].slice(0,-1):"mainnet";let u=i.blockTag||"latest";if("string"==typeof r.query){const e=s(r.query);u="string"==typeof e.versionId?e.versionId:u;try{u=Number.parseInt(u)}catch(e){u="latest"}}if(!this.contracts[c])return{didResolutionMetadata:{error:k.unknownNetwork,message:`The DID resolver does not have a configuration for network: ${c}`},didDocumentMetadata:{},didDocument:null};let h=t.from(Math.floor((new Date).getTime()/1e3));if("number"==typeof u){const e=await this.getBlockMetadata(u,c);h=t.from(Date.parse(e.isoDate)/1e3)}const{address:f,history:m,controllerKey:g,chainId:p}=await this.changeLog(o,c,"latest");try{const{didDocument:t,deactivated:r,versionId:n,nextVersionId:i}=this.wrapDidDocument(e,f,g,m,p,u,h),a=r?{deactivated:!0}:{};let o={},s={};if(0!==n){const e=await this.getBlockMetadata(n,c);o={versionId:e.height,updated:e.isoDate}}if(i!==Number.POSITIVE_INFINITY){const e=await this.getBlockMetadata(i,c);s={nextVersionId:e.height,nextUpdate:e.isoDate}}return{didDocumentMetadata:d({},a,o,s),didResolutionMetadata:{contentType:"application/did+ld+json"},didDocument:t}}catch(e){return{didResolutionMetadata:{error:k.notFound,message:e.toString()},didDocumentMetadata:{},didDocument:null}}}build(){return{ethr:this.resolve.bind(this)}}}export{k as Errors,K as EthrDidController,u as REGISTRY,m as attrTypes,p as bytes32toString,g as delegateTypes,$ as getResolver,l as identifierMatcher,y as interpretIdentifier,v as stringToBytes32,h as verificationMethodTypes}; | ||
//# sourceMappingURL=index.modern.js.map |
@@ -1,2 +0,2 @@ | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("@ethersproject/basex"),require("@ethersproject/bignumber"),require("@ethersproject/contracts"),require("@ethersproject/providers"),require("ethr-did-registry"),require("@ethersproject/address"),require("@ethersproject/transactions"),require("querystring")):"function"==typeof define&&define.amd?define(["exports","@ethersproject/basex","@ethersproject/bignumber","@ethersproject/contracts","@ethersproject/providers","ethr-did-registry","@ethersproject/address","@ethersproject/transactions","querystring"],t):t((e||self).ethrDidResolver={},e.basex,e.bignumber,e.contracts,e.providers,e.ethrDidRegistry,e.address,e.transactions,e.querystring)}(this,function(e,t,r,n,i,o,c,s,a){function d(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var u=d(o);const h=/^(.*)?(0x[0-9a-fA-F]{40}|0x[0-9a-fA-F]{66})$/,l="0xdca7ef03e98e0dc2b855be647c39abe984fcf21b";var f,m;e.verificationMethodTypes=void 0,(f=e.verificationMethodTypes||(e.verificationMethodTypes={})).EcdsaSecp256k1VerificationKey2019="EcdsaSecp256k1VerificationKey2019",f.EcdsaSecp256k1RecoveryMethod2020="EcdsaSecp256k1RecoveryMethod2020",f.Ed25519VerificationKey2018="Ed25519VerificationKey2018",f.RSAVerificationKey2018="RSAVerificationKey2018",f.X25519KeyAgreementKey2019="X25519KeyAgreementKey2019",function(e){e.DIDOwnerChanged="DIDOwnerChanged",e.DIDAttributeChanged="DIDAttributeChanged",e.DIDDelegateChanged="DIDDelegateChanged"}(m||(m={}));const v={sigAuth:"SignatureAuthentication2018",veriKey:"VerificationKey2018",enc:"KeyAgreementKey2019"},g={Secp256k1VerificationKey2018:e.verificationMethodTypes.EcdsaSecp256k1VerificationKey2019,Ed25519SignatureAuthentication2018:e.verificationMethodTypes.Ed25519VerificationKey2018,Secp256k1SignatureAuthentication2018:e.verificationMethodTypes.EcdsaSecp256k1VerificationKey2019,RSAVerificationKey2018:e.verificationMethodTypes.RSAVerificationKey2018,Ed25519VerificationKey2018:e.verificationMethodTypes.Ed25519VerificationKey2018,X25519KeyAgreementKey2019:e.verificationMethodTypes.X25519KeyAgreementKey2019};function p(e){return("string"==typeof e?Buffer.from(e.slice(2),"hex"):Buffer.from(e)).toString("utf8").replace(/\0+$/,"")}function y(e){const t="0x"+Buffer.from(e).slice(0,32).toString("hex");return t+"0".repeat(66-t.length)}function b(e){let t,r=e;if(r.startsWith("did:ethr")){const e=r.split(":");r=e[e.length-1],e.length>=4&&(t=e.splice(2,e.length-3).join(":"))}return r.length>42?{address:s.computeAddress(r),publicKey:r,network:t}:{address:c.getAddress(r),network:t}}const w={mainnet:"0x1",ropsten:"0x3",rinkeby:"0x4",goerli:"0x5",kovan:"0x2a"},k={...w,rsk:"0x1e","rsk:testnet":"0x1f",artis_t1:"0x03c401",artis_s1:"0x03c301",matic:"0x89",maticmum:"0x13881"};var D;function P(e){var t;let o=e.provider||(null==(t=e.web3)?void 0:t.currentProvider);if(!o){if(!e.rpcUrl)throw new Error(`invalid_config: No web3 provider could be determined for network ${e.name||e.chainId}`);{var c;const t=e.chainId?e.chainId:k[e.name||""],n=t?r.BigNumber.from(t).toNumber():t,s=w[e.name||""]?null==(c=e.name)?void 0:c.replace("mainnet","homestead"):"any";o=new i.JsonRpcProvider(e.rpcUrl,n||s)}}return n.ContractFactory.fromSolidity(u.default).attach(e.registry||l).connect(o)}function x(e){const t={},r=e.chainId||k[e.name||""];return r?(e.name&&(t[e.name]=P(e)),t["number"==typeof r?`0x${r.toString(16)}`:r]=P(e)):(e.provider||e.web3||e.rpcUrl)&&(t[e.name||""]=P(e)),t}function I(e){var t;return{...x(e),...null==(t=e.networks)?void 0:t.reduce((e,t)=>({...e,...x(t)}),{})}}e.Errors=void 0,(D=e.Errors||(e.Errors={})).notFound="notFound",D.invalidDid="invalidDid",D.unknownNetwork="unknownNetwork";class K{constructor(e,t,r,n="mainnet",i,o,c=l){const{address:s,publicKey:a,network:d}=b(e),u=d||n;if(t)this.contract=t;else{if(!(i||null!=r&&r.provider))throw new Error(" either a contract instance or a provider or rpcUrl is required to initialize");this.contract=P({name:u,provider:i||(null==r?void 0:r.provider),registry:c,rpcUrl:o})}this.signer=r,this.address=s;let h=u?`${u}:`:"";h in["mainnet:","0x1:"]&&(h=""),this.did=a?`did:ethr:${h}${a}`:`did:ethr:${h}${s}`}getOwner(e,t){try{return Promise.resolve(this.contract.functions.identityOwner(e,{blockTag:t})).then(function(e){return e[0]})}catch(e){return Promise.reject(e)}}attachContract(e){try{const t=this;return Promise.resolve(e||t.getOwner(t.address,"latest")).then(function(e){const r=t.signer?t.signer:t.contract.provider.getSigner(e)||t.contract.signer;return t.contract.connect(r)})}catch(e){return Promise.reject(e)}}changeOwner(e,t={}){try{const r=this,n={gasLimit:123456,gasPrice:1e9,...t};return Promise.resolve(r.attachContract(n.from)).then(function(t){return delete n.from,Promise.resolve(t.functions.changeOwner(r.address,e,n)).then(function(e){return Promise.resolve(e.wait())})})}catch(e){return Promise.reject(e)}}addDelegate(e,t,r,n={}){try{const i=this,o={gasLimit:123456,gasPrice:1e9,...n};return Promise.resolve(i.attachContract(o.from)).then(function(n){delete o.from;const c=y(e);return Promise.resolve(n.functions.addDelegate(i.address,c,t,r,o)).then(function(e){return Promise.resolve(e.wait())})})}catch(e){return Promise.reject(e)}}revokeDelegate(e,t,r={}){try{const n=this,i={gasLimit:123456,gasPrice:1e9,...r};return e=e.startsWith("0x")?e:y(e),Promise.resolve(n.attachContract(i.from)).then(function(r){return delete i.from,Promise.resolve(r.functions.revokeDelegate(n.address,e,t,i)).then(function(e){return Promise.resolve(e.wait())})})}catch(e){return Promise.reject(e)}}setAttribute(e,t,r,n={}){try{const i=this,o={gasLimit:123456,gasPrice:1e9,controller:void 0,...n};return e=e.startsWith("0x")?e:y(e),t=t.startsWith("0x")?t:"0x"+Buffer.from(t,"utf-8").toString("hex"),Promise.resolve(i.attachContract(o.from)).then(function(n){return delete o.from,Promise.resolve(n.functions.setAttribute(i.address,e,t,r,o)).then(function(e){return Promise.resolve(e.wait())})})}catch(e){return Promise.reject(e)}}revokeAttribute(e,t,r={}){try{const n=this,i={gasLimit:123456,gasPrice:1e9,...r};return e=e.startsWith("0x")?e:y(e),t=t.startsWith("0x")?t:"0x"+Buffer.from(t,"utf-8").toString("hex"),Promise.resolve(n.attachContract(i.from)).then(function(r){return delete i.from,Promise.resolve(r.functions.revokeAttribute(n.address,e,t,i)).then(function(e){return Promise.resolve(e.wait())})})}catch(e){return Promise.reject(e)}}}function S(e,t,r){if(!e.s){if(r instanceof N){if(!r.s)return void(r.o=S.bind(null,e,t));1&t&&(t=r.s),r=r.v}if(r&&r.then)return void r.then(S.bind(null,e,t),S.bind(null,e,2));e.s=t,e.v=r;const n=e.o;n&&n(e)}}const N=function(){function e(){}return e.prototype.then=function(t,r){const n=new e,i=this.s;if(i){const e=1&i?t:r;if(e){try{S(n,1,e(this.v))}catch(e){S(n,2,e)}return n}return this}return this.o=function(e){try{const i=e.v;1&e.s?S(n,1,t?t(i):i):r?S(n,1,r(i)):S(n,2,i)}catch(e){S(n,2,e)}},n},e}();function j(e){return e instanceof N&&1&e.s}class ${constructor(e){this.contracts=function(e={}){const t={...(r=e.infuraProjectId,r?I({networks:[{name:"mainnet",chainId:"0x1",provider:new i.InfuraProvider("homestead",r)},{name:"ropsten",chainId:"0x3",provider:new i.InfuraProvider("ropsten",r)},{name:"rinkeby",chainId:"0x4",provider:new i.InfuraProvider("rinkeby",r)},{name:"goerli",chainId:"0x5",provider:new i.InfuraProvider("goerli",r)},{name:"kovan",chainId:"0x2a",provider:new i.InfuraProvider("kovan",r)}]}):{}),...I(e)};var r;if(0===Object.keys(t).length)throw new Error("invalid_config: Please make sure to have at least one network");return t}(e)}getOwner(e,t,r){try{return Promise.resolve(new K(e,this.contracts[t]).getOwner(e,r))}catch(e){return Promise.reject(e)}}previousChange(e,t,n){try{return Promise.resolve(this.contracts[t].functions.changed(e,{blockTag:n})).then(function(e){return r.BigNumber.from(e[0])})}catch(e){return Promise.reject(e)}}getBlockMetadata(e,t){try{return Promise.resolve(this.contracts[t].provider.getBlock(e)).then(function(e){return{height:e.number.toString(),isoDate:new Date(1e3*e.timestamp).toISOString()}})}catch(e){return Promise.reject(e)}}changeLog(e,t,n="latest"){try{const i=this,o=i.contracts[t],c=o.provider,s=t.startsWith("0x")?t:k[t];return Promise.resolve(c.getNetwork()).then(function(a){const d=a.chainId,u=s?r.BigNumber.from(s).toNumber():d,h=[],{address:l,publicKey:f}=b(e),m=f;return Promise.resolve(i.previousChange(l,t,n)).then(function(e){function t(){return{address:l,history:h,controllerKey:m,chainId:u}}const n=function(e,t,r){for(var n;;){var i=e();if(j(i)&&(i=i.v),!i)return o;if(i.then){n=0;break}var o=r();if(o&&o.then){if(!j(o)){n=1;break}o=o.s}}var c=new N,s=S.bind(null,c,2);return(0===n?i.then(d):1===n?o.then(a):(void 0).then(function(){(i=e())?i.then?i.then(d).then(void 0,s):d(i):S(c,1,o)})).then(void 0,s),c;function a(t){o=t;do{if(!(i=e())||j(i)&&!i.v)return void S(c,1,o);if(i.then)return void i.then(d).then(void 0,s);j(o=r())&&(o=o.v)}while(!o||!o.then);o.then(a).then(void 0,s)}function d(e){e?(o=r())&&o.then?o.then(a).then(void 0,s):a(o):S(c,1,o)}}(function(){return!!e},0,function(){const t=e;return Promise.resolve(c.getLogs({address:o.address,topics:[null,`0x000000000000000000000000${l.slice(2)}`],fromBlock:e.toHexString(),toBlock:e.toHexString()})).then(function(n){const i=function(e,t){return t.map(t=>function(e,t){const n={};if(e.eventFragment.inputs.length!==e.args.length)throw new TypeError("malformed event input. wrong number of arguments");return e.eventFragment.inputs.forEach((t,i)=>{let o=e.args[i];"object"==typeof o&&(o=r.BigNumber.from(o)),"bytes32"===t.type&&(o=p(o)),n[t.name]=o}),n._eventName=e.name,n.blockNumber=t,n}(e.interface.parseLog(t),t.blockNumber))}(o,n);i.reverse(),e=null;for(const r of i)h.unshift(r),r.previousChange.lt(t)&&(e=r.previousChange)})});return n&&n.then?n.then(t):t()})})}catch(e){return Promise.reject(e)}}wrapDidDocument(n,i,o,c,s,a,d){const u={"@context":["https://www.w3.org/ns/did/v1","https://identity.foundation/EcdsaSecp256k1RecoverySignature2020/lds-ecdsa-secp256k1-recovery2020-0.0.jsonld"],id:n,verificationMethod:[],authentication:[]};let h=i;const l=[`${n}#controller`];let f=0,p=Number.POSITIVE_INFINITY,y=!1,b=0,w=0;const k={},D={},P={};for(const i of c){if(-1!==a&&i.blockNumber>a){p>i.blockNumber&&(p=i.blockNumber);continue}f<i.blockNumber&&(f=i.blockNumber);const o=i.validTo||r.BigNumber.from(0),c=`${i._eventName}-${i.delegateType||i.name}-${i.delegate||i.value}`;if(o&&o.gte(d)){if(i._eventName===m.DIDDelegateChanged){const t=i;switch(b++,t.delegateType){case"sigAuth":k[c]=`${n}#delegate-${b}`;case"veriKey":D[c]={id:`${n}#delegate-${b}`,type:e.verificationMethodTypes.EcdsaSecp256k1RecoveryMethod2020,controller:n,blockchainAccountId:`${t.delegate}@eip155:${s}`}}}else if(i._eventName===m.DIDAttributeChanged){const e=i,r=e.name.match(/^did\/(pub|svc)\/(\w+)(\/(\w+))?(\/(\w+))?$/);if(r){const i=r[2],o=v[r[4]]||r[4],s=r[6];switch(r[1]){case"pub":{b++;const a={id:`${n}#delegate-${b}`,type:`${i}${o}`,controller:n};switch(a.type=g[a.type]||i,s){case null:case void 0:case"hex":a.publicKeyHex=e.value.slice(2);break;case"base64":a.publicKeyBase64=Buffer.from(e.value.slice(2),"hex").toString("base64");break;case"base58":a.publicKeyBase58=t.Base58.encode(Buffer.from(e.value.slice(2),"hex"));break;case"pem":a.publicKeyPem=Buffer.from(e.value.slice(2),"hex").toString();break;default:a.value=e.value}D[c]=a,"sigAuth"===r[4]&&(k[c]=a.id);break}case"svc":w++,P[c]={id:`${n}#service-${w}`,type:i,serviceEndpoint:Buffer.from(e.value.slice(2),"hex").toString()}}}}}else if(i._eventName===m.DIDOwnerChanged){if(h=i.owner,"0x0000000000000000000000000000000000000000"===i.owner){y=!0;break}}else i._eventName===m.DIDDelegateChanged||i._eventName===m.DIDAttributeChanged&&i.name.match(/^did\/pub\//)?b++:i._eventName===m.DIDAttributeChanged&&i.name.match(/^did\/svc\//)&&w++,delete k[c],delete D[c],delete P[c]}const x=[{id:`${n}#controller`,type:e.verificationMethodTypes.EcdsaSecp256k1RecoveryMethod2020,controller:n,blockchainAccountId:`${h}@eip155:${s}`}];o&&h==i&&(x.push({id:`${n}#controllerKey`,type:e.verificationMethodTypes.EcdsaSecp256k1VerificationKey2019,controller:n,publicKeyHex:o}),l.push(`${n}#controllerKey`));const I={...u,verificationMethod:x.concat(Object.values(D)),authentication:l.concat(Object.values(k))};return Object.values(P).length>0&&(I.service=Object.values(P)),y?{didDocument:{...u,"@context":"https://www.w3.org/ns/did/v1"},deactivated:y,versionId:f,nextVersionId:p}:{didDocument:I,deactivated:y,versionId:f,nextVersionId:p}}resolve(t,n,i,o){try{const i=this;function c(){return Promise.resolve(i.changeLog(d,u,"latest")).then(function({address:r,history:n,controllerKey:o,chainId:c}){return function(e,s){try{var a=function(){function e(){function e(){return{didDocumentMetadata:{...m,...v,...g},didResolutionMetadata:{contentType:"application/did+ld+json"},didDocument:s}}const t=function(){if(h!==Number.POSITIVE_INFINITY)return Promise.resolve(i.getBlockMetadata(h,u)).then(function(e){g={nextVersionId:e.height,nextUpdate:e.isoDate}})}();return t&&t.then?t.then(e):e()}const{didDocument:s,deactivated:a,versionId:d,nextVersionId:h}=i.wrapDidDocument(t,r,o,n,c,l,f),m=a?{deactivated:!0}:{};let v={},g={};const p=function(){if(0!==d)return Promise.resolve(i.getBlockMetadata(d,u)).then(function(e){v={versionId:e.height,updated:e.isoDate}})}();return p&&p.then?p.then(e):e()}()}catch(e){return s(e)}return a&&a.then?a.then(void 0,s):a}(0,function(t){return{didResolutionMetadata:{error:e.Errors.notFound,message:t.toString()},didDocumentMetadata:{},didDocument:null}})})}const s=n.id.match(h);if(!s)return Promise.resolve({didResolutionMetadata:{error:e.Errors.invalidDid,message:`Not a valid did:ethr: ${n.id}`},didDocumentMetadata:{},didDocument:null});const d=s[2],u=s[1]?s[1].slice(0,-1):"mainnet";let l=o.blockTag||"latest";if("string"==typeof n.query){const e=a.decode(n.query);l="string"==typeof e.versionId?e.versionId:l;try{l=Number.parseInt(l)}catch(e){l="latest"}}if(!i.contracts[u])return Promise.resolve({didResolutionMetadata:{error:e.Errors.unknownNetwork,message:`The DID resolver does not have a configuration for network: ${u}`},didDocumentMetadata:{},didDocument:null});let f=r.BigNumber.from(Math.floor((new Date).getTime()/1e3));const m=function(){if("number"==typeof l)return Promise.resolve(i.getBlockMetadata(l,u)).then(function(e){f=r.BigNumber.from(Date.parse(e.isoDate)/1e3)})}();return Promise.resolve(m&&m.then?m.then(c):c())}catch(e){return Promise.reject(e)}}build(){return{ethr:this.resolve.bind(this)}}}e.EthrDidController=K,e.REGISTRY=l,e.attrTypes=v,e.bytes32toString=p,e.delegateTypes=g,e.getResolver=function(e){return new $(e).build()},e.identifierMatcher=h,e.interpretIdentifier=b,e.stringToBytes32=y}); | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("@ethersproject/basex"),require("@ethersproject/bignumber"),require("@ethersproject/contracts"),require("@ethersproject/providers"),require("ethr-did-registry"),require("@ethersproject/address"),require("@ethersproject/transactions"),require("querystring")):"function"==typeof define&&define.amd?define(["exports","@ethersproject/basex","@ethersproject/bignumber","@ethersproject/contracts","@ethersproject/providers","ethr-did-registry","@ethersproject/address","@ethersproject/transactions","querystring"],t):t((e||self).ethrDidResolver={},e.basex,e.bignumber,e.contracts,e.providers,e.ethrDidRegistry,e.address,e.transactions,e.querystring)}(this,function(e,t,r,n,i,o,c,s,a){function d(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var u=d(o);const h=/^(.*)?(0x[0-9a-fA-F]{40}|0x[0-9a-fA-F]{66})$/,l="0xdca7ef03e98e0dc2b855be647c39abe984fcf21b";var f,v;e.verificationMethodTypes=void 0,(f=e.verificationMethodTypes||(e.verificationMethodTypes={})).EcdsaSecp256k1VerificationKey2019="EcdsaSecp256k1VerificationKey2019",f.EcdsaSecp256k1RecoveryMethod2020="EcdsaSecp256k1RecoveryMethod2020",f.Ed25519VerificationKey2018="Ed25519VerificationKey2018",f.RSAVerificationKey2018="RSAVerificationKey2018",f.X25519KeyAgreementKey2019="X25519KeyAgreementKey2019",function(e){e.DIDOwnerChanged="DIDOwnerChanged",e.DIDAttributeChanged="DIDAttributeChanged",e.DIDDelegateChanged="DIDDelegateChanged"}(v||(v={}));const m={sigAuth:"SignatureAuthentication2018",veriKey:"VerificationKey2018",enc:"KeyAgreementKey2019"},g={Secp256k1VerificationKey2018:e.verificationMethodTypes.EcdsaSecp256k1VerificationKey2019,Ed25519SignatureAuthentication2018:e.verificationMethodTypes.Ed25519VerificationKey2018,Secp256k1SignatureAuthentication2018:e.verificationMethodTypes.EcdsaSecp256k1VerificationKey2019,RSAVerificationKey2018:e.verificationMethodTypes.RSAVerificationKey2018,Ed25519VerificationKey2018:e.verificationMethodTypes.Ed25519VerificationKey2018,X25519KeyAgreementKey2019:e.verificationMethodTypes.X25519KeyAgreementKey2019};function p(e){return("string"==typeof e?Buffer.from(e.slice(2),"hex"):Buffer.from(e)).toString("utf8").replace(/\0+$/,"")}function y(e){const t="0x"+Buffer.from(e).slice(0,32).toString("hex");return t+"0".repeat(66-t.length)}function b(e){let t,r=e;if(r.startsWith("did:ethr")){const e=r.split(":");r=e[e.length-1],e.length>=4&&(t=e.splice(2,e.length-3).join(":"))}return r.length>42?{address:s.computeAddress(r),publicKey:r,network:t}:{address:c.getAddress(r),network:t}}const w={mainnet:"0x1",ropsten:"0x3",rinkeby:"0x4",goerli:"0x5",kovan:"0x2a"},k={...w,rsk:"0x1e","rsk:testnet":"0x1f",artis_t1:"0x03c401",artis_s1:"0x03c301",matic:"0x89",maticmum:"0x13881"};var D;function P(e){var t;let o=e.provider||(null==(t=e.web3)?void 0:t.currentProvider);if(!o){if(!e.rpcUrl)throw new Error(`invalid_config: No web3 provider could be determined for network ${e.name||e.chainId}`);{var c;const t=e.chainId?e.chainId:k[e.name||""],n=t?r.BigNumber.from(t).toNumber():t,s=w[e.name||""]?null==(c=e.name)?void 0:c.replace("mainnet","homestead"):"any";o=new i.JsonRpcProvider(e.rpcUrl,n||s)}}return n.ContractFactory.fromSolidity(u.default).attach(e.registry||l).connect(o)}function x(e){const t={},r=e.chainId||k[e.name||""];return r?(e.name&&(t[e.name]=P(e)),t["number"==typeof r?`0x${r.toString(16)}`:r]=P(e)):(e.provider||e.web3||e.rpcUrl)&&(t[e.name||""]=P(e)),t}function I(e){var t;return{...x(e),...null==(t=e.networks)?void 0:t.reduce((e,t)=>({...e,...x(t)}),{})}}e.Errors=void 0,(D=e.Errors||(e.Errors={})).notFound="notFound",D.invalidDid="invalidDid",D.unknownNetwork="unknownNetwork";class K{constructor(e,t,r,n="mainnet",i,o,c=l){const{address:s,publicKey:a,network:d}=b(e),u=d||n;if(t)this.contract=t;else{if(!(i||null!=r&&r.provider))throw new Error(" either a contract instance or a provider or rpcUrl is required to initialize");this.contract=P({name:u,provider:i||(null==r?void 0:r.provider),registry:c,rpcUrl:o})}this.signer=r,this.address=s;let h=u?`${u}:`:"";h in["mainnet:","0x1:"]&&(h=""),this.did=a?`did:ethr:${h}${a}`:`did:ethr:${h}${s}`}getOwner(e,t){try{return Promise.resolve(this.contract.functions.identityOwner(e,{blockTag:t})).then(function(e){return e[0]})}catch(e){return Promise.reject(e)}}attachContract(e){try{const t=this;return Promise.resolve(e||t.getOwner(t.address,"latest")).then(function(e){const r=t.signer?t.signer:t.contract.provider.getSigner(e)||t.contract.signer;return t.contract.connect(r)})}catch(e){return Promise.reject(e)}}changeOwner(e,t={}){try{const r=this,n={gasLimit:123456,gasPrice:1e9,...t};return Promise.resolve(r.attachContract(n.from)).then(function(t){return delete n.from,Promise.resolve(t.functions.changeOwner(r.address,e,n)).then(function(e){return Promise.resolve(e.wait())})})}catch(e){return Promise.reject(e)}}addDelegate(e,t,r,n={}){try{const i=this,o={gasLimit:123456,gasPrice:1e9,...n};return Promise.resolve(i.attachContract(o.from)).then(function(n){delete o.from;const c=y(e);return Promise.resolve(n.functions.addDelegate(i.address,c,t,r,o)).then(function(e){return Promise.resolve(e.wait())})})}catch(e){return Promise.reject(e)}}revokeDelegate(e,t,r={}){try{const n=this,i={gasLimit:123456,gasPrice:1e9,...r};return e=e.startsWith("0x")?e:y(e),Promise.resolve(n.attachContract(i.from)).then(function(r){return delete i.from,Promise.resolve(r.functions.revokeDelegate(n.address,e,t,i)).then(function(e){return Promise.resolve(e.wait())})})}catch(e){return Promise.reject(e)}}setAttribute(e,t,r,n={}){try{const i=this,o={gasLimit:123456,gasPrice:1e9,controller:void 0,...n};return e=e.startsWith("0x")?e:y(e),t=t.startsWith("0x")?t:"0x"+Buffer.from(t,"utf-8").toString("hex"),Promise.resolve(i.attachContract(o.from)).then(function(n){return delete o.from,Promise.resolve(n.functions.setAttribute(i.address,e,t,r,o)).then(function(e){return Promise.resolve(e.wait())})})}catch(e){return Promise.reject(e)}}revokeAttribute(e,t,r={}){try{const n=this,i={gasLimit:123456,gasPrice:1e9,...r};return e=e.startsWith("0x")?e:y(e),t=t.startsWith("0x")?t:"0x"+Buffer.from(t,"utf-8").toString("hex"),Promise.resolve(n.attachContract(i.from)).then(function(r){return delete i.from,Promise.resolve(r.functions.revokeAttribute(n.address,e,t,i)).then(function(e){return Promise.resolve(e.wait())})})}catch(e){return Promise.reject(e)}}}function S(e,t,r){if(!e.s){if(r instanceof N){if(!r.s)return void(r.o=S.bind(null,e,t));1&t&&(t=r.s),r=r.v}if(r&&r.then)return void r.then(S.bind(null,e,t),S.bind(null,e,2));e.s=t,e.v=r;const n=e.o;n&&n(e)}}const N=function(){function e(){}return e.prototype.then=function(t,r){const n=new e,i=this.s;if(i){const e=1&i?t:r;if(e){try{S(n,1,e(this.v))}catch(e){S(n,2,e)}return n}return this}return this.o=function(e){try{const i=e.v;1&e.s?S(n,1,t?t(i):i):r?S(n,1,r(i)):S(n,2,i)}catch(e){S(n,2,e)}},n},e}();function j(e){return e instanceof N&&1&e.s}class M{constructor(e){this.contracts=function(e={}){const t={...(r=e.infuraProjectId,r?I({networks:[{name:"mainnet",chainId:"0x1",provider:new i.InfuraProvider("homestead",r)},{name:"ropsten",chainId:"0x3",provider:new i.InfuraProvider("ropsten",r)},{name:"rinkeby",chainId:"0x4",provider:new i.InfuraProvider("rinkeby",r)},{name:"goerli",chainId:"0x5",provider:new i.InfuraProvider("goerli",r)},{name:"kovan",chainId:"0x2a",provider:new i.InfuraProvider("kovan",r)}]}):{}),...I(e)};var r;if(0===Object.keys(t).length)throw new Error("invalid_config: Please make sure to have at least one network");return t}(e)}getOwner(e,t,r){try{return Promise.resolve(new K(e,this.contracts[t]).getOwner(e,r))}catch(e){return Promise.reject(e)}}previousChange(e,t,n){try{return Promise.resolve(this.contracts[t].functions.changed(e,{blockTag:n})).then(function(e){return r.BigNumber.from(e[0])})}catch(e){return Promise.reject(e)}}getBlockMetadata(e,t){try{return Promise.resolve(this.contracts[t].provider.getBlock(e)).then(function(e){return{height:e.number.toString(),isoDate:new Date(1e3*e.timestamp).toISOString()}})}catch(e){return Promise.reject(e)}}changeLog(e,t,n="latest"){try{const i=this,o=i.contracts[t],c=o.provider,s=t.startsWith("0x")?t:k[t];return Promise.resolve(c.getNetwork()).then(function(a){const d=a.chainId,u=s?r.BigNumber.from(s).toNumber():d,h=[],{address:l,publicKey:f}=b(e),v=f;return Promise.resolve(i.previousChange(l,t,n)).then(function(e){function t(){return{address:l,history:h,controllerKey:v,chainId:u}}const n=function(e,t,r){for(var n;;){var i=e();if(j(i)&&(i=i.v),!i)return o;if(i.then){n=0;break}var o=r();if(o&&o.then){if(!j(o)){n=1;break}o=o.s}}var c=new N,s=S.bind(null,c,2);return(0===n?i.then(d):1===n?o.then(a):(void 0).then(function(){(i=e())?i.then?i.then(d).then(void 0,s):d(i):S(c,1,o)})).then(void 0,s),c;function a(t){o=t;do{if(!(i=e())||j(i)&&!i.v)return void S(c,1,o);if(i.then)return void i.then(d).then(void 0,s);j(o=r())&&(o=o.v)}while(!o||!o.then);o.then(a).then(void 0,s)}function d(e){e?(o=r())&&o.then?o.then(a).then(void 0,s):a(o):S(c,1,o)}}(function(){return!!e},0,function(){const t=e;return Promise.resolve(c.getLogs({address:o.address,topics:[null,`0x000000000000000000000000${l.slice(2)}`],fromBlock:e.toHexString(),toBlock:e.toHexString()})).then(function(n){const i=function(e,t){return t.map(t=>function(e,t){const n={};if(e.eventFragment.inputs.length!==e.args.length)throw new TypeError("malformed event input. wrong number of arguments");return e.eventFragment.inputs.forEach((t,i)=>{let o=e.args[i];"object"==typeof o&&(o=r.BigNumber.from(o)),"bytes32"===t.type&&(o=p(o)),n[t.name]=o}),n._eventName=e.name,n.blockNumber=t,n}(e.interface.parseLog(t),t.blockNumber))}(o,n);i.reverse(),e=null;for(const r of i)h.unshift(r),r.previousChange.lt(t)&&(e=r.previousChange)})});return n&&n.then?n.then(t):t()})})}catch(e){return Promise.reject(e)}}wrapDidDocument(n,i,o,c,s,a,d){var u;const h={"@context":["https://www.w3.org/ns/did/v1","https://identity.foundation/EcdsaSecp256k1RecoverySignature2020/lds-ecdsa-secp256k1-recovery2020-0.0.jsonld"],id:n,verificationMethod:[],authentication:[],assertionMethod:[]};let l=i;const f=[`${n}#controller`];let p=0,y=Number.POSITIVE_INFINITY,b=!1,w=0,k=0;const D={},P={},x={};for(const i of c){if(-1!==a&&i.blockNumber>a){y>i.blockNumber&&(y=i.blockNumber);continue}p<i.blockNumber&&(p=i.blockNumber);const o=i.validTo||r.BigNumber.from(0),c=`${i._eventName}-${i.delegateType||i.name}-${i.delegate||i.value}`;if(o&&o.gte(d)){if(i._eventName===v.DIDDelegateChanged){const t=i;switch(w++,t.delegateType){case"sigAuth":D[c]=`${n}#delegate-${w}`;case"veriKey":P[c]={id:`${n}#delegate-${w}`,type:e.verificationMethodTypes.EcdsaSecp256k1RecoveryMethod2020,controller:n,blockchainAccountId:`${t.delegate}@eip155:${s}`}}}else if(i._eventName===v.DIDAttributeChanged){const e=i,r=e.name.match(/^did\/(pub|svc)\/(\w+)(\/(\w+))?(\/(\w+))?$/);if(r){const i=r[2],o=m[r[4]]||r[4],s=r[6];switch(r[1]){case"pub":{w++;const a={id:`${n}#delegate-${w}`,type:`${i}${o}`,controller:n};switch(a.type=g[a.type]||i,s){case null:case void 0:case"hex":a.publicKeyHex=e.value.slice(2);break;case"base64":a.publicKeyBase64=Buffer.from(e.value.slice(2),"hex").toString("base64");break;case"base58":a.publicKeyBase58=t.Base58.encode(Buffer.from(e.value.slice(2),"hex"));break;case"pem":a.publicKeyPem=Buffer.from(e.value.slice(2),"hex").toString();break;default:a.value=e.value}P[c]=a,"sigAuth"===r[4]&&(D[c]=a.id);break}case"svc":k++,x[c]={id:`${n}#service-${k}`,type:i,serviceEndpoint:Buffer.from(e.value.slice(2),"hex").toString()}}}}}else if(i._eventName===v.DIDOwnerChanged){if(l=i.owner,"0x0000000000000000000000000000000000000000"===i.owner){b=!0;break}}else i._eventName===v.DIDDelegateChanged||i._eventName===v.DIDAttributeChanged&&i.name.match(/^did\/pub\//)?w++:i._eventName===v.DIDAttributeChanged&&i.name.match(/^did\/svc\//)&&k++,delete D[c],delete P[c],delete x[c]}const I=[{id:`${n}#controller`,type:e.verificationMethodTypes.EcdsaSecp256k1RecoveryMethod2020,controller:n,blockchainAccountId:`${l}@eip155:${s}`}];o&&l==i&&(I.push({id:`${n}#controllerKey`,type:e.verificationMethodTypes.EcdsaSecp256k1VerificationKey2019,controller:n,publicKeyHex:o}),f.push(`${n}#controllerKey`));const K={...h,verificationMethod:I.concat(Object.values(P)),authentication:f.concat(Object.values(D))};return Object.values(x).length>0&&(K.service=Object.values(x)),K.assertionMethod=[...(null==(u=K.verificationMethod)?void 0:u.map(e=>e.id))||[]],b?{didDocument:{...h,"@context":"https://www.w3.org/ns/did/v1"},deactivated:b,versionId:p,nextVersionId:y}:{didDocument:K,deactivated:b,versionId:p,nextVersionId:y}}resolve(t,n,i,o){try{const i=this;function c(){return Promise.resolve(i.changeLog(d,u,"latest")).then(function({address:r,history:n,controllerKey:o,chainId:c}){return function(e,s){try{var a=function(){function e(){function e(){return{didDocumentMetadata:{...v,...m,...g},didResolutionMetadata:{contentType:"application/did+ld+json"},didDocument:s}}const t=function(){if(h!==Number.POSITIVE_INFINITY)return Promise.resolve(i.getBlockMetadata(h,u)).then(function(e){g={nextVersionId:e.height,nextUpdate:e.isoDate}})}();return t&&t.then?t.then(e):e()}const{didDocument:s,deactivated:a,versionId:d,nextVersionId:h}=i.wrapDidDocument(t,r,o,n,c,l,f),v=a?{deactivated:!0}:{};let m={},g={};const p=function(){if(0!==d)return Promise.resolve(i.getBlockMetadata(d,u)).then(function(e){m={versionId:e.height,updated:e.isoDate}})}();return p&&p.then?p.then(e):e()}()}catch(e){return s(e)}return a&&a.then?a.then(void 0,s):a}(0,function(t){return{didResolutionMetadata:{error:e.Errors.notFound,message:t.toString()},didDocumentMetadata:{},didDocument:null}})})}const s=n.id.match(h);if(!s)return Promise.resolve({didResolutionMetadata:{error:e.Errors.invalidDid,message:`Not a valid did:ethr: ${n.id}`},didDocumentMetadata:{},didDocument:null});const d=s[2],u=s[1]?s[1].slice(0,-1):"mainnet";let l=o.blockTag||"latest";if("string"==typeof n.query){const e=a.decode(n.query);l="string"==typeof e.versionId?e.versionId:l;try{l=Number.parseInt(l)}catch(e){l="latest"}}if(!i.contracts[u])return Promise.resolve({didResolutionMetadata:{error:e.Errors.unknownNetwork,message:`The DID resolver does not have a configuration for network: ${u}`},didDocumentMetadata:{},didDocument:null});let f=r.BigNumber.from(Math.floor((new Date).getTime()/1e3));const v=function(){if("number"==typeof l)return Promise.resolve(i.getBlockMetadata(l,u)).then(function(e){f=r.BigNumber.from(Date.parse(e.isoDate)/1e3)})}();return Promise.resolve(v&&v.then?v.then(c):c())}catch(e){return Promise.reject(e)}}build(){return{ethr:this.resolve.bind(this)}}}e.EthrDidController=K,e.REGISTRY=l,e.attrTypes=m,e.bytes32toString=p,e.delegateTypes=g,e.getResolver=function(e){return new M(e).build()},e.identifierMatcher=h,e.interpretIdentifier=b,e.stringToBytes32=y}); | ||
//# sourceMappingURL=index.umd.js.map |
{ | ||
"name": "ethr-did-resolver", | ||
"version": "4.2.0", | ||
"version": "4.3.0", | ||
"description": "Resolve DID documents around ethereum addresses", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.umd.js", |
@@ -37,2 +37,3 @@ import { Resolver } from 'did-resolver' | ||
authentication: [`${did}#controller`], | ||
assertionMethod: [`${did}#controller`], | ||
}, | ||
@@ -66,2 +67,3 @@ }) | ||
authentication: [`${did}#controller`], | ||
assertionMethod: [`${did}#controller`], | ||
}, | ||
@@ -95,2 +97,3 @@ }) | ||
authentication: [`${did}#controller`], | ||
assertionMethod: [`${did}#controller`], | ||
}, | ||
@@ -122,2 +125,3 @@ }) | ||
authentication: [`${did}#controller`], | ||
assertionMethod: [`${did}#controller`], | ||
}, | ||
@@ -149,2 +153,3 @@ }) | ||
authentication: [`${did}#controller`], | ||
assertionMethod: [`${did}#controller`], | ||
}, | ||
@@ -183,2 +188,3 @@ }) | ||
authentication: [`${did}#controller`, `${did}#controllerKey`], | ||
assertionMethod: [`${did}#controller`, `${did}#controllerKey`], | ||
}, | ||
@@ -185,0 +191,0 @@ }) |
@@ -10,2 +10,4 @@ import { Contract, ContractFactory } from '@ethersproject/contracts' | ||
jest.setTimeout(30000) | ||
describe('ethrResolver', () => { | ||
@@ -68,2 +70,3 @@ // let registry, accounts, did, identity, controller, delegate1, delegate2, ethr, didResolver | ||
authentication: [`${did}#controller`], | ||
assertionMethod: [`${did}#controller`], | ||
}, | ||
@@ -101,2 +104,3 @@ }) | ||
authentication: [`${pubdid}#controller`, `${pubdid}#controllerKey`], | ||
assertionMethod: [`${pubdid}#controller`, `${pubdid}#controllerKey`], | ||
}, | ||
@@ -131,2 +135,3 @@ }) | ||
authentication: [`${did}#controller`], | ||
assertionMethod: [`${did}#controller`], | ||
}, | ||
@@ -156,2 +161,3 @@ }) | ||
authentication: [`${pubdid}#controller`], | ||
assertionMethod: [`${pubdid}#controller`], | ||
}) | ||
@@ -196,2 +202,3 @@ expect(didDocument?.verificationMethod?.length).toBe(1) | ||
authentication: [`${did}#controller`], | ||
assertionMethod: [`${did}#controller`, `${did}#delegate-1`], | ||
}, | ||
@@ -241,2 +248,3 @@ }) | ||
authentication: [`${did}#controller`, `${did}#delegate-2`], | ||
assertionMethod: [`${did}#controller`, `${did}#delegate-1`, `${did}#delegate-2`], | ||
}, | ||
@@ -279,2 +287,3 @@ }) | ||
authentication: [`${did}#controller`], | ||
assertionMethod: [`${did}#controller`, `${did}#delegate-1`], | ||
}, | ||
@@ -313,2 +322,3 @@ }) | ||
authentication: [`${did}#controller`], | ||
assertionMethod: [`${did}#controller`], | ||
}, | ||
@@ -352,2 +362,3 @@ }) | ||
authentication: [`${did}#controller`, `${did}#delegate-4`], | ||
assertionMethod: [`${did}#controller`, `${did}#delegate-4`], | ||
}, | ||
@@ -397,2 +408,3 @@ }) | ||
authentication: [`${did}#controller`, `${did}#delegate-4`], | ||
assertionMethod: [`${did}#controller`, `${did}#delegate-4`, `${did}#delegate-5`], | ||
}) | ||
@@ -446,2 +458,3 @@ }) | ||
authentication: [`${did}#controller`, `${did}#delegate-4`], | ||
assertionMethod: [`${did}#controller`, `${did}#delegate-4`, `${did}#delegate-5`, `${did}#delegate-6`], | ||
}) | ||
@@ -501,2 +514,9 @@ }) | ||
authentication: [`${did}#controller`, `${did}#delegate-4`], | ||
assertionMethod: [ | ||
`${did}#controller`, | ||
`${did}#delegate-4`, | ||
`${did}#delegate-5`, | ||
`${did}#delegate-6`, | ||
`${did}#delegate-7`, | ||
], | ||
}) | ||
@@ -536,2 +556,3 @@ }) | ||
authentication: [`${keyAgrDid}#controller`], | ||
assertionMethod: [`${keyAgrDid}#controller`, `${keyAgrDid}#delegate-1`], | ||
}) | ||
@@ -593,2 +614,9 @@ }) | ||
authentication: [`${did}#controller`, `${did}#delegate-4`], | ||
assertionMethod: [ | ||
`${did}#controller`, | ||
`${did}#delegate-4`, | ||
`${did}#delegate-5`, | ||
`${did}#delegate-6`, | ||
`${did}#delegate-7`, | ||
], | ||
service: [ | ||
@@ -651,2 +679,3 @@ { | ||
authentication: [`${did}#controller`, `${did}#delegate-4`], | ||
assertionMethod: [`${did}#controller`, `${did}#delegate-4`, `${did}#delegate-6`, `${did}#delegate-7`], | ||
service: [ | ||
@@ -697,2 +726,3 @@ { | ||
authentication: [`${did}#controller`, `${did}#delegate-4`], | ||
assertionMethod: [`${did}#controller`, `${did}#delegate-4`, `${did}#delegate-7`], | ||
service: [ | ||
@@ -737,2 +767,3 @@ { | ||
authentication: [`${did}#controller`, `${did}#delegate-4`], | ||
assertionMethod: [`${did}#controller`, `${did}#delegate-4`], | ||
service: [ | ||
@@ -778,2 +809,3 @@ { | ||
authentication: [`${did}#controller`, `${did}#delegate-4`], | ||
assertionMethod: [`${did}#controller`, `${did}#delegate-4`], | ||
}) | ||
@@ -830,2 +862,3 @@ }) | ||
authentication: [`${did}#controller`, `${did}#delegate-4`], | ||
assertionMethod: [`${did}#controller`, `${did}#delegate-4`], | ||
service: [ | ||
@@ -891,2 +924,3 @@ { | ||
authentication: [`${did}#controller`, `${did}#delegate-4`], | ||
assertionMethod: [`${did}#controller`, `${did}#delegate-4`], | ||
service: [ | ||
@@ -958,2 +992,3 @@ { | ||
authentication: [`${did}#controller`, `${did}#delegate-1`], | ||
assertionMethod: [`${did}#controller`, `${did}#delegate-1`], | ||
}) | ||
@@ -1004,2 +1039,3 @@ }) | ||
authentication: [`${did}#controller`], | ||
assertionMethod: [`${did}#controller`, `${did}#delegate-1`], | ||
}, | ||
@@ -1032,2 +1068,3 @@ }) | ||
authentication: [], | ||
assertionMethod: [], | ||
}, | ||
@@ -1064,2 +1101,3 @@ }) | ||
authentication: [`${virginDID}#controller`], | ||
assertionMethod: [`${virginDID}#controller`], | ||
}, | ||
@@ -1102,2 +1140,3 @@ }) | ||
authentication: [`${modifiedDid}#controller`], | ||
assertionMethod: [`${modifiedDid}#controller`, `${modifiedDid}#delegate-1`], | ||
}, | ||
@@ -1138,2 +1177,3 @@ }) | ||
authentication: [`${did}#controller`, `${did}#delegate-4`], | ||
assertionMethod: [`${did}#controller`, `${did}#delegate-4`], | ||
}, | ||
@@ -1168,2 +1208,3 @@ }) | ||
authentication: [`${did}#controller`], | ||
assertionMethod: [`${did}#controller`], | ||
}, | ||
@@ -1198,2 +1239,3 @@ }) | ||
authentication: [`${did}#controller`], | ||
assertionMethod: [`${did}#controller`], | ||
}, | ||
@@ -1229,2 +1271,3 @@ }) | ||
authentication: [`${deactivatedDid}#controller`], | ||
assertionMethod: [`${deactivatedDid}#controller`], | ||
}, | ||
@@ -1270,2 +1313,3 @@ }) | ||
authentication: [`${did}#controller`, `${did}#delegate-2`], | ||
assertionMethod: [`${did}#controller`, `${did}#delegate-1`, `${did}#delegate-2`], | ||
}, | ||
@@ -1272,0 +1316,0 @@ }) |
@@ -130,2 +130,3 @@ import { Base58 } from '@ethersproject/basex' | ||
authentication: [], | ||
assertionMethod: [], | ||
} | ||
@@ -276,3 +277,3 @@ | ||
const doc: DIDDocument = { | ||
const didDocument: DIDDocument = { | ||
...baseDIDDocument, | ||
@@ -283,4 +284,5 @@ verificationMethod: publicKeys.concat(Object.values(pks)), | ||
if (Object.values(services).length > 0) { | ||
doc.service = Object.values(services) | ||
didDocument.service = Object.values(services) | ||
} | ||
didDocument.assertionMethod = [...(didDocument.verificationMethod?.map((pk) => pk.id) || [])] | ||
@@ -294,3 +296,3 @@ return deactivated | ||
} | ||
: { didDocument: doc, deactivated, versionId, nextVersionId } | ||
: { didDocument, deactivated, versionId, nextVersionId } | ||
} | ||
@@ -319,3 +321,2 @@ | ||
let blockTag: string | number = options.blockTag || 'latest' | ||
// let versionAtMost: string | number = -1 | ||
if (typeof parsed.query === 'string') { | ||
@@ -322,0 +323,0 @@ const qParams = qs.decode(parsed.query) |
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
327240
2853