Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

ethr-did-resolver

Package Overview
Dependencies
Maintainers
7
Versions
85
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ethr-did-resolver - npm Package Compare versions

Comparing version 4.0.1 to 4.1.0

7

CHANGELOG.md

@@ -0,1 +1,8 @@

# [4.1.0](https://github.com/decentralized-identity/ethr-did-resolver/compare/4.0.1...4.1.0) (2021-04-14)
### Features
* export `EthrDidController` helper class ([#120](https://github.com/decentralized-identity/ethr-did-resolver/issues/120)) ([745100d](https://github.com/decentralized-identity/ethr-did-resolver/commit/745100d6cbfd1170af483efb2bdd93784f8fd7a6))
## [4.0.1](https://github.com/decentralized-identity/ethr-did-resolver/compare/4.0.0...4.0.1) (2021-03-26)

@@ -2,0 +9,0 @@

1

lib/configuration.d.ts

@@ -31,2 +31,3 @@ import { Contract } from '@ethersproject/contracts';

export declare type ConfiguredNetworks = Record<string, Contract>;
export declare function getContractForNetwork(conf: ProviderConfiguration): Contract;
/**

@@ -33,0 +34,0 @@ * Generates a configuration that maps ethereum network names and chainIDs to the respective ERC1056 contracts deployed on them.

import { Signer } from '@ethersproject/abstract-signer';
import { CallOverrides, Contract } from '@ethersproject/contracts';
import { BlockTag, TransactionReceipt } from '@ethersproject/providers';
import { BlockTag, Provider, TransactionReceipt } from '@ethersproject/providers';
import { address } from './helpers';
/**
* A class that can be used to interact with the ERC1056 contract on behalf of a local controller key-pair
*/
export declare class EthrDidController {

@@ -9,3 +12,15 @@ private contract;

private address;
constructor(identifier: string | address, contract: Contract, signer?: Signer);
did: string;
/**
* Creates an EthrDidController instance.
*
* @param identifier - required - a `did:ethr` string or a publicKeyHex or an ethereum address
* @param signer - optional - a Signer that represents the current controller key (owner) of the identifier. If a 'signer' is not provided, then a 'contract' with an attached signer can be used.
* @param contract - optional - a Contract instance representing a ERC1056 contract. At least one of `contract`, `provider`, or `rpcUrl` is required
* @param chainNameOrId - optional - the network name or chainID, defaults to 'mainnet'
* @param provider - optional - a web3 Provider. At least one of `contract`, `provider`, or `rpcUrl` is required
* @param rpcUrl - optional - a JSON-RPC URL that can be used to connect to an ethereum network. At least one of `contract`, `provider`, or `rpcUrl` is required
* @param registry - optional - The ERC1056 registry address. Defaults to '0xdca7ef03e98e0dc2b855be647c39abe984fcf21b'. Only used with 'provider' or 'rpcUrl'
*/
constructor(identifier: string | address, contract?: Contract, signer?: Signer, chainNameOrId?: string, provider?: Provider, rpcUrl?: string, registry?: string);
getOwner(address: address, blockTag?: BlockTag): Promise<string>;

@@ -12,0 +27,0 @@ attachContract(controller?: address | Promise<address>): Promise<Contract>;

@@ -58,2 +58,3 @@ import { BigNumber } from '@ethersproject/bignumber';

publicKey?: string;
network?: string;
};

@@ -60,0 +61,0 @@ export declare const knownInfuraNetworks: Record<string, string>;

3

lib/index.d.ts
import { getResolver } from './resolver';
import { EthrDidController } from './controller';
import { bytes32toString, DEFAULT_REGISTRY_ADDRESS, identifierMatcher, legacyAlgoMap, legacyAttrTypes, stringToBytes32, verificationMethodTypes, Errors } from './helpers';
export { DEFAULT_REGISTRY_ADDRESS as REGISTRY, getResolver, bytes32toString, stringToBytes32,
export { DEFAULT_REGISTRY_ADDRESS as REGISTRY, getResolver, bytes32toString, stringToBytes32, EthrDidController,
/**@deprecated */

@@ -5,0 +6,0 @@ legacyAlgoMap as delegateTypes,

@@ -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");function s(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var a=s(o);const d=/^(.*)?(0x[0-9a-fA-F]{40}|0x[0-9a-fA-F]{66})$/;var u,h;exports.verificationMethodTypes=void 0,(u=exports.verificationMethodTypes||(exports.verificationMethodTypes={})).EcdsaSecp256k1VerificationKey2019="EcdsaSecp256k1VerificationKey2019",u.EcdsaSecp256k1RecoveryMethod2020="EcdsaSecp256k1RecoveryMethod2020",u.Ed25519VerificationKey2018="Ed25519VerificationKey2018",u.RSAVerificationKey2018="RSAVerificationKey2018",u.X25519KeyAgreementKey2019="X25519KeyAgreementKey2019",function(e){e.DIDOwnerChanged="DIDOwnerChanged",e.DIDAttributeChanged="DIDAttributeChanged",e.DIDDelegateChanged="DIDDelegateChanged"}(h||(h={}));const f={sigAuth:"SignatureAuthentication2018",veriKey:"VerificationKey2018",enc:"KeyAgreementKey2019"},l={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 v(e){return("string"==typeof e?Buffer.from(e.slice(2),"hex"):Buffer.from(e)).toString("utf8").replace(/\0+$/,"")}function m(e){const t="0x"+Buffer.from(e).slice(0,32).toString("hex");return t+"0".repeat(66-t.length)}function p(e){return e.length>42?{address:c.computeAddress(e),publicKey:e}:{address:i.getAddress(e)}}const g={mainnet:"0x1",ropsten:"0x3",rinkeby:"0x4",goerli:"0x5",kovan:"0x2a"},y={...g,rsk:"0x1e","rsk:testnet":"0x1f",artis_t1:"0x03c401",artis_s1:"0x03c301",matic:"0x89",maticmum:"0x13881"};var b;function x(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:y[e.name||""],o=r?t.BigNumber.from(r).toNumber():r,s=g[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(a.default).attach(e.registry||"0xdca7ef03e98e0dc2b855be647c39abe984fcf21b").connect(i)}function w(e){const t={},r=e.chainId||y[e.name||""];return r?(e.name&&(t[e.name]=x(e)),t["number"==typeof r?`0x${r.toString(16)}`:r]=x(e)):(e.provider||e.web3||e.rpcUrl)&&(t[e.name||""]=x(e)),t}function k(e){var t;return{...w(e),...null==(t=e.networks)?void 0:t.reduce((e,t)=>({...e,...w(t)}),{})}}exports.Errors=void 0,(b=exports.Errors||(exports.Errors={})).notFound="notFound",b.invalidDid="invalidDid",b.unknownNetwork="unknownNetwork";class D{constructor(e,t,r){this.contract=t,this.signer=r;const{address:n}=p(e);this.address=n}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=m(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:m(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:m(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:m(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 P(e,t,r){if(!e.s){if(r instanceof K){if(!r.s)return void(r.o=P.bind(null,e,t));1&t&&(t=r.s),r=r.v}if(r&&r.then)return void r.then(P.bind(null,e,t),P.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{P(n,1,e(this.v))}catch(e){P(n,2,e)}return n}return this}return this.o=function(e){try{const o=e.v;1&e.s?P(n,1,t?t(o):o):r?P(n,1,r(o)):P(n,2,o)}catch(e){P(n,2,e)}},n},e}();function S(e){return e instanceof K&&1&e.s}class I{constructor(e){this.contracts=function(e={}){const t={...(r=e.infuraProjectId,r?k({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)}]}):{}),...k(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 D(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)}}changeLog(e,r,n="latest"){try{const o=this,i=o.contracts[r],c=i.provider,s=r.startsWith("0x")?r:y[r];return Promise.resolve(c.getNetwork()).then(function(a){const d=a.chainId,u=s?t.BigNumber.from(s).toNumber():d,h=[],{address:f,publicKey:l}=p(e);let m=l,g=f;return Promise.resolve(o.previousChange(f,r,n)).then(function(e){function s(){function r(){return{controller:g,history:h,controllerKey:m,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=P.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):P(c,1,i)})).then(void 0,s),c;function a(t){i=t;do{if(!(o=e())||S(o)&&!o.v)return void P(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):P(c,1,i)}}(function(){return!!e},0,function(){const r=e;return Promise.resolve(c.getLogs({address:i.address,topics:[null,`0x000000000000000000000000${f.slice(2)}`],fromBlock:e.toHexString(),toBlock:e.toHexString()})).then(function(n){const o=function(e,r){return r.map(r=>function(e){const r={};if(e.eventFragment.inputs.length!==e.args.length)throw new TypeError("malformed event input. wrong number of arguments");return e.eventFragment.inputs.forEach((n,o)=>{let i=e.args[o];"object"==typeof i&&(i=t.BigNumber.from(i)),"bytes32"===n.type&&(i=v(i)),r[n.name]=i}),r._eventName=e.name,r}(e.interface.parseLog(r)))}(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()}const a=function(){if(e)return Promise.resolve(o.getOwner(f,r,n)).then(function(e){e.toLowerCase()!==g.toLowerCase()&&(m=void 0),g=e})}();return a&&a.then?a.then(s):s()})})}catch(e){return Promise.reject(e)}}wrapDidDocument(r,n,o,i,c){const s={"@context":["https://www.w3.org/ns/did/v1","https://identity.foundation/EcdsaSecp256k1RecoverySignature2020/lds-ecdsa-secp256k1-recovery2020-0.0.jsonld"],id:r,verificationMethod:[],authentication:[]},a=t.BigNumber.from(Math.floor((new Date).getTime()/1e3)),d=[{id:`${r}#controller`,type:exports.verificationMethodTypes.EcdsaSecp256k1RecoveryMethod2020,controller:r,blockchainAccountId:`${n}@eip155:${c}`}],u=[`${r}#controller`];o&&(d.push({id:`${r}#controllerKey`,type:exports.verificationMethodTypes.EcdsaSecp256k1VerificationKey2019,controller:r,publicKeyHex:o}),u.push(`${r}#controllerKey`));let v=!1,m=0,p=0;const g={},y={},b={};for(const n of i){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===h.DIDDelegateChanged){const e=n;switch(m++,e.delegateType){case"sigAuth":g[i]=`${r}#delegate-${m}`;case"veriKey":y[i]={id:`${r}#delegate-${m}`,type:exports.verificationMethodTypes.EcdsaSecp256k1RecoveryMethod2020,controller:r,blockchainAccountId:`${e.delegate}@eip155:${c}`}}}else if(n._eventName===h.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":{m++;const a={id:`${r}#delegate-${m}`,type:`${n}${c}`,controller:r};switch(a.type=l[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}y[i]=a,"sigAuth"===o[4]&&(g[i]=a.id);break}case"svc":p++,b[i]={id:`${r}#service-${p}`,type:n,serviceEndpoint:Buffer.from(t.value.slice(2),"hex").toString()}}}}}else if(n._eventName===h.DIDDelegateChanged||n._eventName===h.DIDAttributeChanged&&n.name.match(/^did\/pub\//)?m++:n._eventName===h.DIDAttributeChanged&&n.name.match(/^did\/svc\//)&&p++,delete g[i],delete y[i],delete b[i],n._eventName===h.DIDOwnerChanged&&"0x0000000000000000000000000000000000000000"===n.owner){v=!0;break}}const x={...s,verificationMethod:d.concat(Object.values(y)),authentication:u.concat(Object.values(g))};return Object.values(b).length>0&&(x.service=Object.values(b)),v?{didDocument:{...s,"@context":"https://www.w3.org/ns/did/v1"},deactivated:v}:{didDocument:x,deactivated:v}}resolve(e,t,r,n){try{const r=this,o=t.id.match(d);if(!o)return Promise.resolve({didResolutionMetadata:{error:exports.Errors.invalidDid,message:`Not a valid did:ethr: ${t.id}`},didDocumentMetadata:{},didDocument:null});const i=o[2],c=o[1]?o[1].slice(0,-1):"mainnet";return r.contracts[c]?Promise.resolve(r.changeLog(i,c,n.blockTag)).then(function({controller:t,history:n,controllerKey:o,chainId:i}){try{const{didDocument:c,deactivated:s}=r.wrapDidDocument(e,t,o,n,i);return{didDocumentMetadata:{...s?{deactivated:!0}:{}},didResolutionMetadata:{contentType:"application/did+ld+json"},didDocument:c}}catch(e){return{didResolutionMetadata:{error:exports.Errors.notFound,message:e.toString()},didDocumentMetadata:{},didDocument:null}}}):Promise.resolve({didResolutionMetadata:{error:exports.Errors.unknownNetwork,message:`The DID resolver does not have a configuration for network: ${c}`},didDocumentMetadata:{},didDocument:null})}catch(e){return Promise.reject(e)}}build(){return{ethr:this.resolve.bind(this)}}}exports.REGISTRY="0xdca7ef03e98e0dc2b855be647c39abe984fcf21b",exports.attrTypes=f,exports.bytes32toString=v,exports.delegateTypes=l,exports.getResolver=function(e){return new I(e).build()},exports.identifierMatcher=d,exports.stringToBytes32=m;
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");function s(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var a=s(o);const d=/^(.*)?(0x[0-9a-fA-F]{40}|0x[0-9a-fA-F]{66})$/;var u,h;exports.verificationMethodTypes=void 0,(u=exports.verificationMethodTypes||(exports.verificationMethodTypes={})).EcdsaSecp256k1VerificationKey2019="EcdsaSecp256k1VerificationKey2019",u.EcdsaSecp256k1RecoveryMethod2020="EcdsaSecp256k1RecoveryMethod2020",u.Ed25519VerificationKey2018="Ed25519VerificationKey2018",u.RSAVerificationKey2018="RSAVerificationKey2018",u.X25519KeyAgreementKey2019="X25519KeyAgreementKey2019",function(e){e.DIDOwnerChanged="DIDOwnerChanged",e.DIDAttributeChanged="DIDAttributeChanged",e.DIDDelegateChanged="DIDDelegateChanged"}(h||(h={}));const l={sigAuth:"SignatureAuthentication2018",veriKey:"VerificationKey2018",enc:"KeyAgreementKey2019"},f={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 v(e){return("string"==typeof e?Buffer.from(e.slice(2),"hex"):Buffer.from(e)).toString("utf8").replace(/\0+$/,"")}function m(e){const t="0x"+Buffer.from(e).slice(0,32).toString("hex");return t+"0".repeat(66-t.length)}function p(e){let t,r=e;if(r.startsWith("did:ethr")){const e=r.split(":");r=e[e.length-1],4===e.length&&(t=e[2])}return r.length>42?{address:c.computeAddress(r),publicKey:r,network:t}:{address:i.getAddress(r),network:t}}const g={mainnet:"0x1",ropsten:"0x3",rinkeby:"0x4",goerli:"0x5",kovan:"0x2a"},y={...g,rsk:"0x1e","rsk:testnet":"0x1f",artis_t1:"0x03c401",artis_s1:"0x03c301",matic:"0x89",maticmum:"0x13881"};var b;function x(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:y[e.name||""],o=r?t.BigNumber.from(r).toNumber():r,s=g[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(a.default).attach(e.registry||"0xdca7ef03e98e0dc2b855be647c39abe984fcf21b").connect(i)}function w(e){const t={},r=e.chainId||y[e.name||""];return r?(e.name&&(t[e.name]=x(e)),t["number"==typeof r?`0x${r.toString(16)}`:r]=x(e)):(e.provider||e.web3||e.rpcUrl)&&(t[e.name||""]=x(e)),t}function k(e){var t;return{...w(e),...null==(t=e.networks)?void 0:t.reduce((e,t)=>({...e,...w(t)}),{})}}exports.Errors=void 0,(b=exports.Errors||(exports.Errors={})).notFound="notFound",b.invalidDid="invalidDid",b.unknownNetwork="unknownNetwork";class D{constructor(e,t,r,n="mainnet",o,i,c="0xdca7ef03e98e0dc2b855be647c39abe984fcf21b"){const{address:s,publicKey:a,network:d}=p(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=x({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=m(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:m(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:m(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:m(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 P(e,t,r){if(!e.s){if(r instanceof K){if(!r.s)return void(r.o=P.bind(null,e,t));1&t&&(t=r.s),r=r.v}if(r&&r.then)return void r.then(P.bind(null,e,t),P.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{P(n,1,e(this.v))}catch(e){P(n,2,e)}return n}return this}return this.o=function(e){try{const o=e.v;1&e.s?P(n,1,t?t(o):o):r?P(n,1,r(o)):P(n,2,o)}catch(e){P(n,2,e)}},n},e}();function S(e){return e instanceof K&&1&e.s}class I{constructor(e){this.contracts=function(e={}){const t={...(r=e.infuraProjectId,r?k({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)}]}):{}),...k(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 D(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)}}changeLog(e,r,n="latest"){try{const o=this,i=o.contracts[r],c=i.provider,s=r.startsWith("0x")?r:y[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}=p(e);let m=f,g=l;return Promise.resolve(o.previousChange(l,r,n)).then(function(e){function s(){function r(){return{controller:g,history:h,controllerKey:m,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=P.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):P(c,1,i)})).then(void 0,s),c;function a(t){i=t;do{if(!(o=e())||S(o)&&!o.v)return void P(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):P(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){const r={};if(e.eventFragment.inputs.length!==e.args.length)throw new TypeError("malformed event input. wrong number of arguments");return e.eventFragment.inputs.forEach((n,o)=>{let i=e.args[o];"object"==typeof i&&(i=t.BigNumber.from(i)),"bytes32"===n.type&&(i=v(i)),r[n.name]=i}),r._eventName=e.name,r}(e.interface.parseLog(r)))}(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()}const a=function(){if(e)return Promise.resolve(o.getOwner(l,r,n)).then(function(e){e.toLowerCase()!==g.toLowerCase()&&(m=void 0),g=e})}();return a&&a.then?a.then(s):s()})})}catch(e){return Promise.reject(e)}}wrapDidDocument(r,n,o,i,c){const s={"@context":["https://www.w3.org/ns/did/v1","https://identity.foundation/EcdsaSecp256k1RecoverySignature2020/lds-ecdsa-secp256k1-recovery2020-0.0.jsonld"],id:r,verificationMethod:[],authentication:[]},a=t.BigNumber.from(Math.floor((new Date).getTime()/1e3)),d=[{id:`${r}#controller`,type:exports.verificationMethodTypes.EcdsaSecp256k1RecoveryMethod2020,controller:r,blockchainAccountId:`${n}@eip155:${c}`}],u=[`${r}#controller`];o&&(d.push({id:`${r}#controllerKey`,type:exports.verificationMethodTypes.EcdsaSecp256k1VerificationKey2019,controller:r,publicKeyHex:o}),u.push(`${r}#controllerKey`));let v=!1,m=0,p=0;const g={},y={},b={};for(const n of i){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===h.DIDDelegateChanged){const e=n;switch(m++,e.delegateType){case"sigAuth":g[i]=`${r}#delegate-${m}`;case"veriKey":y[i]={id:`${r}#delegate-${m}`,type:exports.verificationMethodTypes.EcdsaSecp256k1RecoveryMethod2020,controller:r,blockchainAccountId:`${e.delegate}@eip155:${c}`}}}else if(n._eventName===h.DIDAttributeChanged){const t=n,o=t.name.match(/^did\/(pub|svc)\/(\w+)(\/(\w+))?(\/(\w+))?$/);if(o){const n=o[2],c=l[o[4]]||o[4],s=o[6];switch(o[1]){case"pub":{m++;const a={id:`${r}#delegate-${m}`,type:`${n}${c}`,controller:r};switch(a.type=f[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}y[i]=a,"sigAuth"===o[4]&&(g[i]=a.id);break}case"svc":p++,b[i]={id:`${r}#service-${p}`,type:n,serviceEndpoint:Buffer.from(t.value.slice(2),"hex").toString()}}}}}else if(n._eventName===h.DIDDelegateChanged||n._eventName===h.DIDAttributeChanged&&n.name.match(/^did\/pub\//)?m++:n._eventName===h.DIDAttributeChanged&&n.name.match(/^did\/svc\//)&&p++,delete g[i],delete y[i],delete b[i],n._eventName===h.DIDOwnerChanged&&"0x0000000000000000000000000000000000000000"===n.owner){v=!0;break}}const x={...s,verificationMethod:d.concat(Object.values(y)),authentication:u.concat(Object.values(g))};return Object.values(b).length>0&&(x.service=Object.values(b)),v?{didDocument:{...s,"@context":"https://www.w3.org/ns/did/v1"},deactivated:v}:{didDocument:x,deactivated:v}}resolve(e,t,r,n){try{const r=this,o=t.id.match(d);if(!o)return Promise.resolve({didResolutionMetadata:{error:exports.Errors.invalidDid,message:`Not a valid did:ethr: ${t.id}`},didDocumentMetadata:{},didDocument:null});const i=o[2],c=o[1]?o[1].slice(0,-1):"mainnet";return r.contracts[c]?Promise.resolve(r.changeLog(i,c,n.blockTag)).then(function({controller:t,history:n,controllerKey:o,chainId:i}){try{const{didDocument:c,deactivated:s}=r.wrapDidDocument(e,t,o,n,i);return{didDocumentMetadata:{...s?{deactivated:!0}:{}},didResolutionMetadata:{contentType:"application/did+ld+json"},didDocument:c}}catch(e){return{didResolutionMetadata:{error:exports.Errors.notFound,message:e.toString()},didDocumentMetadata:{},didDocument:null}}}):Promise.resolve({didResolutionMetadata:{error:exports.Errors.unknownNetwork,message:`The DID resolver does not have a configuration for network: ${c}`},didDocumentMetadata:{},didDocument:null})}catch(e){return Promise.reject(e)}}build(){return{ethr:this.resolve.bind(this)}}}exports.EthrDidController=D,exports.REGISTRY="0xdca7ef03e98e0dc2b855be647c39abe984fcf21b",exports.attrTypes=l,exports.bytes32toString=v,exports.delegateTypes=f,exports.getResolver=function(e){return new I(e).build()},exports.identifierMatcher=d,exports.stringToBytes32=m;
//# 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 n}from"@ethersproject/contracts";import{InfuraProvider as r,JsonRpcProvider 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";function s(){return(s=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e}).apply(this,arguments)}const d=/^(.*)?(0x[0-9a-fA-F]{40}|0x[0-9a-fA-F]{66})$/,u="0xdca7ef03e98e0dc2b855be647c39abe984fcf21b";var l,h;!function(e){e.EcdsaSecp256k1VerificationKey2019="EcdsaSecp256k1VerificationKey2019",e.EcdsaSecp256k1RecoveryMethod2020="EcdsaSecp256k1RecoveryMethod2020",e.Ed25519VerificationKey2018="Ed25519VerificationKey2018",e.RSAVerificationKey2018="RSAVerificationKey2018",e.X25519KeyAgreementKey2019="X25519KeyAgreementKey2019"}(l||(l={})),function(e){e.DIDOwnerChanged="DIDOwnerChanged",e.DIDAttributeChanged="DIDAttributeChanged",e.DIDDelegateChanged="DIDDelegateChanged"}(h||(h={}));const f={sigAuth:"SignatureAuthentication2018",veriKey:"VerificationKey2018",enc:"KeyAgreementKey2019"},m={Secp256k1VerificationKey2018:l.EcdsaSecp256k1VerificationKey2019,Ed25519SignatureAuthentication2018:l.Ed25519VerificationKey2018,Secp256k1SignatureAuthentication2018:l.EcdsaSecp256k1VerificationKey2019,RSAVerificationKey2018:l.RSAVerificationKey2018,Ed25519VerificationKey2018:l.Ed25519VerificationKey2018,X25519KeyAgreementKey2019:l.X25519KeyAgreementKey2019};function g(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 v(e){return e.length>42?{address:c(e),publicKey:e}:{address:o(e)}}const w={mainnet:"0x1",ropsten:"0x3",rinkeby:"0x4",goerli:"0x5",kovan:"0x2a"},y=s({},w,{rsk:"0x1e","rsk:testnet":"0x1f",artis_t1:"0x03c401",artis_s1:"0x03c301",matic:"0x89",maticmum:"0x13881"});var b;function D(e){var r;let o=e.provider||(null==(r=e.web3)?void 0:r.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 n=e.chainId?e.chainId:y[e.name||""],r=n?t.from(n).toNumber():n,i=w[e.name||""]?null==(c=e.name)?void 0:c.replace("mainnet","homestead"):"any";o=new a(e.rpcUrl,r||i)}}return n.fromSolidity(i).attach(e.registry||"0xdca7ef03e98e0dc2b855be647c39abe984fcf21b").connect(o)}function k(e){const t={},n=e.chainId||y[e.name||""];return n?(e.name&&(t[e.name]=D(e)),t["number"==typeof n?`0x${n.toString(16)}`:n]=D(e)):(e.provider||e.web3||e.rpcUrl)&&(t[e.name||""]=D(e)),t}function x(e){var t;return s({},k(e),null==(t=e.networks)?void 0:t.reduce((e,t)=>s({},e,k(t)),{}))}!function(e){e.notFound="notFound",e.invalidDid="invalidDid",e.unknownNetwork="unknownNetwork"}(b||(b={}));class K{constructor(e,t,n){this.contract=t,this.signer=n;const{address:r}=v(e);this.address=r}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"),n=this.signer?this.signer:this.contract.provider.getSigner(t)||this.contract.signer;return this.contract.connect(n)}async changeOwner(e,t={}){const n=s({gasLimit:123456,gasPrice:1e9},t),r=await this.attachContract(n.from);delete n.from;const a=await r.functions.changeOwner(this.address,e,n);return await a.wait()}async addDelegate(e,t,n,r={}){const a=s({gasLimit:123456,gasPrice:1e9},r),i=await this.attachContract(a.from);delete a.from;const o=p(e),c=await i.functions.addDelegate(this.address,o,t,n,a);return await c.wait()}async revokeDelegate(e,t,n={}){const r=s({gasLimit:123456,gasPrice:1e9},n);e=e.startsWith("0x")?e:p(e);const a=await this.attachContract(r.from);delete r.from;const i=await a.functions.revokeDelegate(this.address,e,t,r);return await i.wait()}async setAttribute(e,t,n,r={}){const a=s({gasLimit:123456,gasPrice:1e9,controller:void 0},r);e=e.startsWith("0x")?e:p(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,n,a);return await o.wait()}async revokeAttribute(e,t,n={}){const r=s({gasLimit:123456,gasPrice:1e9},n);e=e.startsWith("0x")?e:p(e),t=t.startsWith("0x")?t:"0x"+Buffer.from(t,"utf-8").toString("hex");const a=await this.attachContract(r.from);delete r.from;const i=await a.functions.revokeAttribute(this.address,e,t,r);return await i.wait()}}function S(e,n){return n.map(n=>function(e){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=g(i)),n[r.name]=i}),n._eventName=e.name,n}(e.interface.parseLog(n)))}function I(e){return new $(e).build()}class ${constructor(e){this.contracts=function(e={}){const t=s({},(n=e.infuraProjectId)?x({networks:[{name:"mainnet",chainId:"0x1",provider:new r("homestead",n)},{name:"ropsten",chainId:"0x3",provider:new r("ropsten",n)},{name:"rinkeby",chainId:"0x4",provider:new r("rinkeby",n)},{name:"goerli",chainId:"0x5",provider:new r("goerli",n)},{name:"kovan",chainId:"0x2a",provider:new r("kovan",n)}]}):{},x(e));var n;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,n){return new K(e,this.contracts[t]).getOwner(e,n)}async previousChange(e,n,r){const a=await this.contracts[n].functions.changed(e,{blockTag:r});return t.from(a[0])}async changeLog(e,n,r="latest"){const a=this.contracts[n],i=a.provider,o=n.startsWith("0x")?n:y[n],c=(await i.getNetwork()).chainId,s=o?t.from(o).toNumber():c,d=[],{address:u,publicKey:l}=v(e);let h=l,f=u,m=await this.previousChange(u,n,r);if(m){const e=await this.getOwner(u,n,r);e.toLowerCase()!==f.toLowerCase()&&(h=void 0),f=e}for(;m;){const e=m,t=S(a,await i.getLogs({address:a.address,topics:[null,`0x000000000000000000000000${u.slice(2)}`],fromBlock:m.toHexString(),toBlock:m.toHexString()}));t.reverse(),m=null;for(const n of t)d.unshift(n),n.previousChange.lt(e)&&(m=n.previousChange)}return{controller:f,history:d,controllerKey:h,chainId:s}}wrapDidDocument(n,r,a,i,o){const c={"@context":["https://www.w3.org/ns/did/v1","https://identity.foundation/EcdsaSecp256k1RecoverySignature2020/lds-ecdsa-secp256k1-recovery2020-0.0.jsonld"],id:n,verificationMethod:[],authentication:[]},d=t.from(Math.floor((new Date).getTime()/1e3)),u=[{id:`${n}#controller`,type:l.EcdsaSecp256k1RecoveryMethod2020,controller:n,blockchainAccountId:`${r}@eip155:${o}`}],g=[`${n}#controller`];a&&(u.push({id:`${n}#controllerKey`,type:l.EcdsaSecp256k1VerificationKey2019,controller:n,publicKeyHex:a}),g.push(`${n}#controllerKey`));let p=!1,v=0,w=0;const y={},b={},D={};for(const r of i){const a=r.validTo||t.from(0),i=`${r._eventName}-${r.delegateType||r.name}-${r.delegate||r.value}`;if(a&&a.gte(d)){if(r._eventName===h.DIDDelegateChanged){const e=r;switch(v++,e.delegateType){case"sigAuth":y[i]=`${n}#delegate-${v}`;case"veriKey":b[i]={id:`${n}#delegate-${v}`,type:l.EcdsaSecp256k1RecoveryMethod2020,controller:n,blockchainAccountId:`${e.delegate}@eip155:${o}`}}}else if(r._eventName===h.DIDAttributeChanged){const t=r,a=t.name.match(/^did\/(pub|svc)\/(\w+)(\/(\w+))?(\/(\w+))?$/);if(a){const r=a[2],o=f[a[4]]||a[4],c=a[6];switch(a[1]){case"pub":{v++;const s={id:`${n}#delegate-${v}`,type:`${r}${o}`,controller:n};switch(s.type=m[s.type]||r,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}b[i]=s,"sigAuth"===a[4]&&(y[i]=s.id);break}case"svc":w++,D[i]={id:`${n}#service-${w}`,type:r,serviceEndpoint:Buffer.from(t.value.slice(2),"hex").toString()}}}}}else if(r._eventName===h.DIDDelegateChanged||r._eventName===h.DIDAttributeChanged&&r.name.match(/^did\/pub\//)?v++:r._eventName===h.DIDAttributeChanged&&r.name.match(/^did\/svc\//)&&w++,delete y[i],delete b[i],delete D[i],r._eventName===h.DIDOwnerChanged&&"0x0000000000000000000000000000000000000000"===r.owner){p=!0;break}}const k=s({},c,{verificationMethod:u.concat(Object.values(b)),authentication:g.concat(Object.values(y))});return Object.values(D).length>0&&(k.service=Object.values(D)),p?{didDocument:s({},c,{"@context":"https://www.w3.org/ns/did/v1"}),deactivated:p}:{didDocument:k,deactivated:p}}async resolve(e,t,n,r){const a=t.id.match(d);if(!a)return{didResolutionMetadata:{error:b.invalidDid,message:`Not a valid did:ethr: ${t.id}`},didDocumentMetadata:{},didDocument:null};const i=a[2],o=a[1]?a[1].slice(0,-1):"mainnet";if(!this.contracts[o])return{didResolutionMetadata:{error:b.unknownNetwork,message:`The DID resolver does not have a configuration for network: ${o}`},didDocumentMetadata:{},didDocument:null};const{controller:c,history:u,controllerKey:l,chainId:h}=await this.changeLog(i,o,r.blockTag);try{const{didDocument:t,deactivated:n}=this.wrapDidDocument(e,c,l,u,h);return{didDocumentMetadata:s({},n?{deactivated:!0}:{}),didResolutionMetadata:{contentType:"application/did+ld+json"},didDocument:t}}catch(e){return{didResolutionMetadata:{error:b.notFound,message:e.toString()},didDocumentMetadata:{},didDocument:null}}}build(){return{ethr:this.resolve.bind(this)}}}export{b as Errors,u as REGISTRY,f as attrTypes,g as bytes32toString,m as delegateTypes,I as getResolver,d as identifierMatcher,p as stringToBytes32,l 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 a}from"@ethersproject/providers";import i from"ethr-did-registry";import{getAddress as o}from"@ethersproject/address";import{computeAddress as c}from"@ethersproject/transactions";function s(){return(s=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 d=/^(.*)?(0x[0-9a-fA-F]{40}|0x[0-9a-fA-F]{66})$/,l="0xdca7ef03e98e0dc2b855be647c39abe984fcf21b";var u,h;!function(e){e.EcdsaSecp256k1VerificationKey2019="EcdsaSecp256k1VerificationKey2019",e.EcdsaSecp256k1RecoveryMethod2020="EcdsaSecp256k1RecoveryMethod2020",e.Ed25519VerificationKey2018="Ed25519VerificationKey2018",e.RSAVerificationKey2018="RSAVerificationKey2018",e.X25519KeyAgreementKey2019="X25519KeyAgreementKey2019"}(u||(u={})),function(e){e.DIDOwnerChanged="DIDOwnerChanged",e.DIDAttributeChanged="DIDAttributeChanged",e.DIDDelegateChanged="DIDDelegateChanged"}(h||(h={}));const f={sigAuth:"SignatureAuthentication2018",veriKey:"VerificationKey2018",enc:"KeyAgreementKey2019"},m={Secp256k1VerificationKey2018:u.EcdsaSecp256k1VerificationKey2019,Ed25519SignatureAuthentication2018:u.Ed25519VerificationKey2018,Secp256k1SignatureAuthentication2018:u.EcdsaSecp256k1VerificationKey2019,RSAVerificationKey2018:u.RSAVerificationKey2018,Ed25519VerificationKey2018:u.Ed25519VerificationKey2018,X25519KeyAgreementKey2019:u.X25519KeyAgreementKey2019};function g(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 v(e){let t,r=e;if(r.startsWith("did:ethr")){const e=r.split(":");r=e[e.length-1],4===e.length&&(t=e[2])}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"},y=s({},w,{rsk:"0x1e","rsk:testnet":"0x1f",artis_t1:"0x03c401",artis_s1:"0x03c301",matic:"0x89",maticmum:"0x13881"});var b;function k(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:y[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 D(e){const t={},r=e.chainId||y[e.name||""];return r?(e.name&&(t[e.name]=k(e)),t["number"==typeof r?`0x${r.toString(16)}`:r]=k(e)):(e.provider||e.web3||e.rpcUrl)&&(t[e.name||""]=k(e)),t}function x(e){var t;return s({},D(e),null==(t=e.networks)?void 0:t.reduce((e,t)=>s({},e,D(t)),{}))}!function(e){e.notFound="notFound",e.invalidDid="invalidDid",e.unknownNetwork="unknownNetwork"}(b||(b={}));class K{constructor(e,t,r,n="mainnet",a,i,o="0xdca7ef03e98e0dc2b855be647c39abe984fcf21b"){const{address:c,publicKey:s,network:d}=v(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=k({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=s({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=s({gasLimit:123456,gasPrice:1e9},n),i=await this.attachContract(a.from);delete a.from;const o=p(e),c=await i.functions.addDelegate(this.address,o,t,r,a);return await c.wait()}async revokeDelegate(e,t,r={}){const n=s({gasLimit:123456,gasPrice:1e9},r);e=e.startsWith("0x")?e:p(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=s({gasLimit:123456,gasPrice:1e9,controller:void 0},n);e=e.startsWith("0x")?e:p(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=s({gasLimit:123456,gasPrice:1e9},r);e=e.startsWith("0x")?e:p(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){const r={};if(e.eventFragment.inputs.length!==e.args.length)throw new TypeError("malformed event input. wrong number of arguments");return e.eventFragment.inputs.forEach((n,a)=>{let i=e.args[a];"object"==typeof i&&(i=t.from(i)),"bytes32"===n.type&&(i=g(i)),r[n.name]=i}),r._eventName=e.name,r}(e.interface.parseLog(r)))}function $(e){return new I(e).build()}class I{constructor(e){this.contracts=function(e={}){const t=s({},(r=e.infuraProjectId)?x({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)}]}):{},x(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 changeLog(e,r,n="latest"){const a=this.contracts[r],i=a.provider,o=r.startsWith("0x")?r:y[r],c=(await i.getNetwork()).chainId,s=o?t.from(o).toNumber():c,d=[],{address:l,publicKey:u}=v(e);let h=u,f=l,m=await this.previousChange(l,r,n);if(m){const e=await this.getOwner(l,r,n);e.toLowerCase()!==f.toLowerCase()&&(h=void 0),f=e}for(;m;){const e=m,t=S(a,await i.getLogs({address:a.address,topics:[null,`0x000000000000000000000000${l.slice(2)}`],fromBlock:m.toHexString(),toBlock:m.toHexString()}));t.reverse(),m=null;for(const r of t)d.unshift(r),r.previousChange.lt(e)&&(m=r.previousChange)}return{controller:f,history:d,controllerKey:h,chainId:s}}wrapDidDocument(r,n,a,i,o){const c={"@context":["https://www.w3.org/ns/did/v1","https://identity.foundation/EcdsaSecp256k1RecoverySignature2020/lds-ecdsa-secp256k1-recovery2020-0.0.jsonld"],id:r,verificationMethod:[],authentication:[]},d=t.from(Math.floor((new Date).getTime()/1e3)),l=[{id:`${r}#controller`,type:u.EcdsaSecp256k1RecoveryMethod2020,controller:r,blockchainAccountId:`${n}@eip155:${o}`}],g=[`${r}#controller`];a&&(l.push({id:`${r}#controllerKey`,type:u.EcdsaSecp256k1VerificationKey2019,controller:r,publicKeyHex:a}),g.push(`${r}#controllerKey`));let p=!1,v=0,w=0;const y={},b={},k={};for(const n of i){const a=n.validTo||t.from(0),i=`${n._eventName}-${n.delegateType||n.name}-${n.delegate||n.value}`;if(a&&a.gte(d)){if(n._eventName===h.DIDDelegateChanged){const e=n;switch(v++,e.delegateType){case"sigAuth":y[i]=`${r}#delegate-${v}`;case"veriKey":b[i]={id:`${r}#delegate-${v}`,type:u.EcdsaSecp256k1RecoveryMethod2020,controller:r,blockchainAccountId:`${e.delegate}@eip155:${o}`}}}else if(n._eventName===h.DIDAttributeChanged){const t=n,a=t.name.match(/^did\/(pub|svc)\/(\w+)(\/(\w+))?(\/(\w+))?$/);if(a){const n=a[2],o=f[a[4]]||a[4],c=a[6];switch(a[1]){case"pub":{v++;const s={id:`${r}#delegate-${v}`,type:`${n}${o}`,controller:r};switch(s.type=m[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}b[i]=s,"sigAuth"===a[4]&&(y[i]=s.id);break}case"svc":w++,k[i]={id:`${r}#service-${w}`,type:n,serviceEndpoint:Buffer.from(t.value.slice(2),"hex").toString()}}}}}else if(n._eventName===h.DIDDelegateChanged||n._eventName===h.DIDAttributeChanged&&n.name.match(/^did\/pub\//)?v++:n._eventName===h.DIDAttributeChanged&&n.name.match(/^did\/svc\//)&&w++,delete y[i],delete b[i],delete k[i],n._eventName===h.DIDOwnerChanged&&"0x0000000000000000000000000000000000000000"===n.owner){p=!0;break}}const D=s({},c,{verificationMethod:l.concat(Object.values(b)),authentication:g.concat(Object.values(y))});return Object.values(k).length>0&&(D.service=Object.values(k)),p?{didDocument:s({},c,{"@context":"https://www.w3.org/ns/did/v1"}),deactivated:p}:{didDocument:D,deactivated:p}}async resolve(e,t,r,n){const a=t.id.match(d);if(!a)return{didResolutionMetadata:{error:b.invalidDid,message:`Not a valid did:ethr: ${t.id}`},didDocumentMetadata:{},didDocument:null};const i=a[2],o=a[1]?a[1].slice(0,-1):"mainnet";if(!this.contracts[o])return{didResolutionMetadata:{error:b.unknownNetwork,message:`The DID resolver does not have a configuration for network: ${o}`},didDocumentMetadata:{},didDocument:null};const{controller:c,history:l,controllerKey:u,chainId:h}=await this.changeLog(i,o,n.blockTag);try{const{didDocument:t,deactivated:r}=this.wrapDidDocument(e,c,u,l,h);return{didDocumentMetadata:s({},r?{deactivated:!0}:{}),didResolutionMetadata:{contentType:"application/did+ld+json"},didDocument:t}}catch(e){return{didResolutionMetadata:{error:b.notFound,message:e.toString()},didDocumentMetadata:{},didDocument:null}}}build(){return{ethr:this.resolve.bind(this)}}}export{b as Errors,K as EthrDidController,l as REGISTRY,f as attrTypes,g as bytes32toString,m as delegateTypes,$ as getResolver,d as identifierMatcher,p as stringToBytes32,u 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")):"function"==typeof define&&define.amd?define(["exports","@ethersproject/basex","@ethersproject/bignumber","@ethersproject/contracts","@ethersproject/providers","ethr-did-registry","@ethersproject/address","@ethersproject/transactions"],t):t((e||self).ethrDidResolver={},e.basex,e.bignumber,e.contracts,e.providers,e.ethrDidRegistry,e.address,e.transactions)}(this,function(e,t,r,n,o,i,c,s){function a(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var d=a(i);const u=/^(.*)?(0x[0-9a-fA-F]{40}|0x[0-9a-fA-F]{66})$/,h="0xdca7ef03e98e0dc2b855be647c39abe984fcf21b";var f,l;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"}(l||(l={}));const v={sigAuth:"SignatureAuthentication2018",veriKey:"VerificationKey2018",enc:"KeyAgreementKey2019"},m={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 g(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 y(e){return e.length>42?{address:s.computeAddress(e),publicKey:e}:{address:c.getAddress(e)}}const b={mainnet:"0x1",ropsten:"0x3",rinkeby:"0x4",goerli:"0x5",kovan:"0x2a"},w={...b,rsk:"0x1e","rsk:testnet":"0x1f",artis_t1:"0x03c401",artis_s1:"0x03c301",matic:"0x89",maticmum:"0x13881"};var D;function k(e){var t;let i=e.provider||(null==(t=e.web3)?void 0:t.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 t=e.chainId?e.chainId:w[e.name||""],n=t?r.BigNumber.from(t).toNumber():t,s=b[e.name||""]?null==(c=e.name)?void 0:c.replace("mainnet","homestead"):"any";i=new o.JsonRpcProvider(e.rpcUrl,n||s)}}return n.ContractFactory.fromSolidity(d.default).attach(e.registry||h).connect(i)}function x(e){const t={},r=e.chainId||w[e.name||""];return r?(e.name&&(t[e.name]=k(e)),t["number"==typeof r?`0x${r.toString(16)}`:r]=k(e)):(e.provider||e.web3||e.rpcUrl)&&(t[e.name||""]=k(e)),t}function P(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){this.contract=t,this.signer=r;const{address:n}=y(e);this.address=n}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 S(e,t,r){if(!e.s){if(r instanceof j){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 j=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{S(n,1,e(this.v))}catch(e){S(n,2,e)}return n}return this}return this.o=function(e){try{const o=e.v;1&e.s?S(n,1,t?t(o):o):r?S(n,1,r(o)):S(n,2,o)}catch(e){S(n,2,e)}},n},e}();function I(e){return e instanceof j&&1&e.s}class A{constructor(e){this.contracts=function(e={}){const t={...(r=e.infuraProjectId,r?P({networks:[{name:"mainnet",chainId:"0x1",provider:new o.InfuraProvider("homestead",r)},{name:"ropsten",chainId:"0x3",provider:new o.InfuraProvider("ropsten",r)},{name:"rinkeby",chainId:"0x4",provider:new o.InfuraProvider("rinkeby",r)},{name:"goerli",chainId:"0x5",provider:new o.InfuraProvider("goerli",r)},{name:"kovan",chainId:"0x2a",provider:new o.InfuraProvider("kovan",r)}]}):{}),...P(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)}}changeLog(e,t,n="latest"){try{const o=this,i=o.contracts[t],c=i.provider,s=t.startsWith("0x")?t:w[t];return Promise.resolve(c.getNetwork()).then(function(a){const d=a.chainId,u=s?r.BigNumber.from(s).toNumber():d,h=[],{address:f,publicKey:l}=y(e);let v=l,m=f;return Promise.resolve(o.previousChange(f,t,n)).then(function(e){function s(){function t(){return{controller:m,history:h,controllerKey:v,chainId:u}}const n=function(e,t,r){for(var n;;){var o=e();if(I(o)&&(o=o.v),!o)return i;if(o.then){n=0;break}var i=r();if(i&&i.then){if(!I(i)){n=1;break}i=i.s}}var c=new j,s=S.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):S(c,1,i)})).then(void 0,s),c;function a(t){i=t;do{if(!(o=e())||I(o)&&!o.v)return void S(c,1,i);if(o.then)return void o.then(d).then(void 0,s);I(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):S(c,1,i)}}(function(){return!!e},0,function(){const t=e;return Promise.resolve(c.getLogs({address:i.address,topics:[null,`0x000000000000000000000000${f.slice(2)}`],fromBlock:e.toHexString(),toBlock:e.toHexString()})).then(function(n){const o=function(e,t){return t.map(t=>function(e){const t={};if(e.eventFragment.inputs.length!==e.args.length)throw new TypeError("malformed event input. wrong number of arguments");return e.eventFragment.inputs.forEach((n,o)=>{let i=e.args[o];"object"==typeof i&&(i=r.BigNumber.from(i)),"bytes32"===n.type&&(i=g(i)),t[n.name]=i}),t._eventName=e.name,t}(e.interface.parseLog(t)))}(i,n);o.reverse(),e=null;for(const r of o)h.unshift(r),r.previousChange.lt(t)&&(e=r.previousChange)})});return n&&n.then?n.then(t):t()}const a=function(){if(e)return Promise.resolve(o.getOwner(f,t,n)).then(function(e){e.toLowerCase()!==m.toLowerCase()&&(v=void 0),m=e})}();return a&&a.then?a.then(s):s()})})}catch(e){return Promise.reject(e)}}wrapDidDocument(n,o,i,c,s){const a={"@context":["https://www.w3.org/ns/did/v1","https://identity.foundation/EcdsaSecp256k1RecoverySignature2020/lds-ecdsa-secp256k1-recovery2020-0.0.jsonld"],id:n,verificationMethod:[],authentication:[]},d=r.BigNumber.from(Math.floor((new Date).getTime()/1e3)),u=[{id:`${n}#controller`,type:e.verificationMethodTypes.EcdsaSecp256k1RecoveryMethod2020,controller:n,blockchainAccountId:`${o}@eip155:${s}`}],h=[`${n}#controller`];i&&(u.push({id:`${n}#controllerKey`,type:e.verificationMethodTypes.EcdsaSecp256k1VerificationKey2019,controller:n,publicKeyHex:i}),h.push(`${n}#controllerKey`));let f=!1,g=0,p=0;const y={},b={},w={};for(const o of c){const i=o.validTo||r.BigNumber.from(0),c=`${o._eventName}-${o.delegateType||o.name}-${o.delegate||o.value}`;if(i&&i.gte(d)){if(o._eventName===l.DIDDelegateChanged){const t=o;switch(g++,t.delegateType){case"sigAuth":y[c]=`${n}#delegate-${g}`;case"veriKey":b[c]={id:`${n}#delegate-${g}`,type:e.verificationMethodTypes.EcdsaSecp256k1RecoveryMethod2020,controller:n,blockchainAccountId:`${t.delegate}@eip155:${s}`}}}else if(o._eventName===l.DIDAttributeChanged){const e=o,r=e.name.match(/^did\/(pub|svc)\/(\w+)(\/(\w+))?(\/(\w+))?$/);if(r){const o=r[2],i=v[r[4]]||r[4],s=r[6];switch(r[1]){case"pub":{g++;const a={id:`${n}#delegate-${g}`,type:`${o}${i}`,controller:n};switch(a.type=m[a.type]||o,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}b[c]=a,"sigAuth"===r[4]&&(y[c]=a.id);break}case"svc":p++,w[c]={id:`${n}#service-${p}`,type:o,serviceEndpoint:Buffer.from(e.value.slice(2),"hex").toString()}}}}}else if(o._eventName===l.DIDDelegateChanged||o._eventName===l.DIDAttributeChanged&&o.name.match(/^did\/pub\//)?g++:o._eventName===l.DIDAttributeChanged&&o.name.match(/^did\/svc\//)&&p++,delete y[c],delete b[c],delete w[c],o._eventName===l.DIDOwnerChanged&&"0x0000000000000000000000000000000000000000"===o.owner){f=!0;break}}const D={...a,verificationMethod:u.concat(Object.values(b)),authentication:h.concat(Object.values(y))};return Object.values(w).length>0&&(D.service=Object.values(w)),f?{didDocument:{...a,"@context":"https://www.w3.org/ns/did/v1"},deactivated:f}:{didDocument:D,deactivated:f}}resolve(t,r,n,o){try{const n=this,i=r.id.match(u);if(!i)return Promise.resolve({didResolutionMetadata:{error:e.Errors.invalidDid,message:`Not a valid did:ethr: ${r.id}`},didDocumentMetadata:{},didDocument:null});const c=i[2],s=i[1]?i[1].slice(0,-1):"mainnet";return n.contracts[s]?Promise.resolve(n.changeLog(c,s,o.blockTag)).then(function({controller:r,history:o,controllerKey:i,chainId:c}){try{const{didDocument:e,deactivated:s}=n.wrapDidDocument(t,r,i,o,c);return{didDocumentMetadata:{...s?{deactivated:!0}:{}},didResolutionMetadata:{contentType:"application/did+ld+json"},didDocument:e}}catch(t){return{didResolutionMetadata:{error:e.Errors.notFound,message:t.toString()},didDocumentMetadata:{},didDocument:null}}}):Promise.resolve({didResolutionMetadata:{error:e.Errors.unknownNetwork,message:`The DID resolver does not have a configuration for network: ${s}`},didDocumentMetadata:{},didDocument:null})}catch(e){return Promise.reject(e)}}build(){return{ethr:this.resolve.bind(this)}}}e.REGISTRY=h,e.attrTypes=v,e.bytes32toString=g,e.delegateTypes=m,e.getResolver=function(e){return new A(e).build()},e.identifierMatcher=u,e.stringToBytes32=p});
!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")):"function"==typeof define&&define.amd?define(["exports","@ethersproject/basex","@ethersproject/bignumber","@ethersproject/contracts","@ethersproject/providers","ethr-did-registry","@ethersproject/address","@ethersproject/transactions"],t):t((e||self).ethrDidResolver={},e.basex,e.bignumber,e.contracts,e.providers,e.ethrDidRegistry,e.address,e.transactions)}(this,function(e,t,r,n,i,o,c,s){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})$/,h="0xdca7ef03e98e0dc2b855be647c39abe984fcf21b";var l,f;e.verificationMethodTypes=void 0,(l=e.verificationMethodTypes||(e.verificationMethodTypes={})).EcdsaSecp256k1VerificationKey2019="EcdsaSecp256k1VerificationKey2019",l.EcdsaSecp256k1RecoveryMethod2020="EcdsaSecp256k1RecoveryMethod2020",l.Ed25519VerificationKey2018="Ed25519VerificationKey2018",l.RSAVerificationKey2018="RSAVerificationKey2018",l.X25519KeyAgreementKey2019="X25519KeyAgreementKey2019",function(e){e.DIDOwnerChanged="DIDOwnerChanged",e.DIDAttributeChanged="DIDAttributeChanged",e.DIDDelegateChanged="DIDDelegateChanged"}(f||(f={}));const v={sigAuth:"SignatureAuthentication2018",veriKey:"VerificationKey2018",enc:"KeyAgreementKey2019"},m={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 g(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 y(e){let t,r=e;if(r.startsWith("did:ethr")){const e=r.split(":");r=e[e.length-1],4===e.length&&(t=e[2])}return r.length>42?{address:s.computeAddress(r),publicKey:r,network:t}:{address:c.getAddress(r),network:t}}const b={mainnet:"0x1",ropsten:"0x3",rinkeby:"0x4",goerli:"0x5",kovan:"0x2a"},w={...b,rsk:"0x1e","rsk:testnet":"0x1f",artis_t1:"0x03c401",artis_s1:"0x03c301",matic:"0x89",maticmum:"0x13881"};var k;function D(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:w[e.name||""],n=t?r.BigNumber.from(t).toNumber():t,s=b[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(d.default).attach(e.registry||h).connect(o)}function x(e){const t={},r=e.chainId||w[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 P(e){var t;return{...x(e),...null==(t=e.networks)?void 0:t.reduce((e,t)=>({...e,...x(t)}),{})}}e.Errors=void 0,(k=e.Errors||(e.Errors={})).notFound="notFound",k.invalidDid="invalidDid",k.unknownNetwork="unknownNetwork";class K{constructor(e,t,r,n="mainnet",i,o,c=h){const{address:s,publicKey:a,network:d}=y(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=D({name:u,provider:i||(null==r?void 0:r.provider),registry:c,rpcUrl:o})}this.signer=r,this.address=s;let l=u?`${u}:`:"";l in["mainnet:","0x1:"]&&(l=""),this.did=a?`did:ethr:${l}${a}`:`did:ethr:${l}${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=p(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:p(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:p(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:p(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 j){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 j=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 I(e){return e instanceof j&&1&e.s}class ${constructor(e){this.contracts=function(e={}){const t={...(r=e.infuraProjectId,r?P({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)}]}):{}),...P(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)}}changeLog(e,t,n="latest"){try{const i=this,o=i.contracts[t],c=o.provider,s=t.startsWith("0x")?t:w[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}=y(e);let v=f,m=l;return Promise.resolve(i.previousChange(l,t,n)).then(function(e){function s(){function t(){return{controller:m,history:h,controllerKey:v,chainId:u}}const n=function(e,t,r){for(var n;;){var i=e();if(I(i)&&(i=i.v),!i)return o;if(i.then){n=0;break}var o=r();if(o&&o.then){if(!I(o)){n=1;break}o=o.s}}var c=new j,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())||I(i)&&!i.v)return void S(c,1,o);if(i.then)return void i.then(d).then(void 0,s);I(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){const t={};if(e.eventFragment.inputs.length!==e.args.length)throw new TypeError("malformed event input. wrong number of arguments");return e.eventFragment.inputs.forEach((n,i)=>{let o=e.args[i];"object"==typeof o&&(o=r.BigNumber.from(o)),"bytes32"===n.type&&(o=g(o)),t[n.name]=o}),t._eventName=e.name,t}(e.interface.parseLog(t)))}(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()}const a=function(){if(e)return Promise.resolve(i.getOwner(l,t,n)).then(function(e){e.toLowerCase()!==m.toLowerCase()&&(v=void 0),m=e})}();return a&&a.then?a.then(s):s()})})}catch(e){return Promise.reject(e)}}wrapDidDocument(n,i,o,c,s){const a={"@context":["https://www.w3.org/ns/did/v1","https://identity.foundation/EcdsaSecp256k1RecoverySignature2020/lds-ecdsa-secp256k1-recovery2020-0.0.jsonld"],id:n,verificationMethod:[],authentication:[]},d=r.BigNumber.from(Math.floor((new Date).getTime()/1e3)),u=[{id:`${n}#controller`,type:e.verificationMethodTypes.EcdsaSecp256k1RecoveryMethod2020,controller:n,blockchainAccountId:`${i}@eip155:${s}`}],h=[`${n}#controller`];o&&(u.push({id:`${n}#controllerKey`,type:e.verificationMethodTypes.EcdsaSecp256k1VerificationKey2019,controller:n,publicKeyHex:o}),h.push(`${n}#controllerKey`));let l=!1,g=0,p=0;const y={},b={},w={};for(const i of c){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===f.DIDDelegateChanged){const t=i;switch(g++,t.delegateType){case"sigAuth":y[c]=`${n}#delegate-${g}`;case"veriKey":b[c]={id:`${n}#delegate-${g}`,type:e.verificationMethodTypes.EcdsaSecp256k1RecoveryMethod2020,controller:n,blockchainAccountId:`${t.delegate}@eip155:${s}`}}}else if(i._eventName===f.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":{g++;const a={id:`${n}#delegate-${g}`,type:`${i}${o}`,controller:n};switch(a.type=m[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}b[c]=a,"sigAuth"===r[4]&&(y[c]=a.id);break}case"svc":p++,w[c]={id:`${n}#service-${p}`,type:i,serviceEndpoint:Buffer.from(e.value.slice(2),"hex").toString()}}}}}else if(i._eventName===f.DIDDelegateChanged||i._eventName===f.DIDAttributeChanged&&i.name.match(/^did\/pub\//)?g++:i._eventName===f.DIDAttributeChanged&&i.name.match(/^did\/svc\//)&&p++,delete y[c],delete b[c],delete w[c],i._eventName===f.DIDOwnerChanged&&"0x0000000000000000000000000000000000000000"===i.owner){l=!0;break}}const k={...a,verificationMethod:u.concat(Object.values(b)),authentication:h.concat(Object.values(y))};return Object.values(w).length>0&&(k.service=Object.values(w)),l?{didDocument:{...a,"@context":"https://www.w3.org/ns/did/v1"},deactivated:l}:{didDocument:k,deactivated:l}}resolve(t,r,n,i){try{const n=this,o=r.id.match(u);if(!o)return Promise.resolve({didResolutionMetadata:{error:e.Errors.invalidDid,message:`Not a valid did:ethr: ${r.id}`},didDocumentMetadata:{},didDocument:null});const c=o[2],s=o[1]?o[1].slice(0,-1):"mainnet";return n.contracts[s]?Promise.resolve(n.changeLog(c,s,i.blockTag)).then(function({controller:r,history:i,controllerKey:o,chainId:c}){try{const{didDocument:e,deactivated:s}=n.wrapDidDocument(t,r,o,i,c);return{didDocumentMetadata:{...s?{deactivated:!0}:{}},didResolutionMetadata:{contentType:"application/did+ld+json"},didDocument:e}}catch(t){return{didResolutionMetadata:{error:e.Errors.notFound,message:t.toString()},didDocumentMetadata:{},didDocument:null}}}):Promise.resolve({didResolutionMetadata:{error:e.Errors.unknownNetwork,message:`The DID resolver does not have a configuration for network: ${s}`},didDocumentMetadata:{},didDocument:null})}catch(e){return Promise.reject(e)}}build(){return{ethr:this.resolve.bind(this)}}}e.EthrDidController=K,e.REGISTRY=h,e.attrTypes=v,e.bytes32toString=g,e.delegateTypes=m,e.getResolver=function(e){return new $(e).build()},e.identifierMatcher=u,e.stringToBytes32=p});
//# sourceMappingURL=index.umd.js.map
{
"name": "ethr-did-resolver",
"version": "4.0.1",
"version": "4.1.0",
"description": "Resolve DID documents around ethereum addresses",

@@ -56,3 +56,3 @@ "main": "lib/index.umd.js",

"devDependencies": {
"@babel/core": "7.13.10",
"@babel/core": "7.13.14",
"@babel/preset-env": "7.13.12",

@@ -63,7 +63,7 @@ "@babel/preset-typescript": "7.13.0",

"@types/jest": "26.0.22",
"@typescript-eslint/eslint-plugin": "4.19.0",
"@typescript-eslint/parser": "4.19.0",
"@typescript-eslint/eslint-plugin": "4.21.0",
"@typescript-eslint/parser": "4.21.0",
"babel-jest": "26.6.3",
"codecov": "3.8.1",
"eslint": "7.22.0",
"eslint": "7.23.0",
"eslint-config-prettier": "8.1.0",

@@ -70,0 +70,0 @@ "ganache-cli": "6.12.2",

@@ -56,3 +56,3 @@ import { BigNumber } from '@ethersproject/bignumber'

function getContractForNetwork(conf: ProviderConfiguration): Contract {
export function getContractForNetwork(conf: ProviderConfiguration): Contract {
let provider: Provider = conf.provider || conf.web3?.currentProvider

@@ -59,0 +59,0 @@ if (!provider) {

import { Signer } from '@ethersproject/abstract-signer'
import { CallOverrides, Contract } from '@ethersproject/contracts'
import { BlockTag, JsonRpcProvider, TransactionReceipt } from '@ethersproject/providers'
import { address, interpretIdentifier, stringToBytes32 } from './helpers'
import { BlockTag, JsonRpcProvider, Provider, TransactionReceipt } from '@ethersproject/providers'
import { getContractForNetwork } from './configuration'
import { address, DEFAULT_REGISTRY_ADDRESS, interpretIdentifier, stringToBytes32 } from './helpers'
/**
* A class that can be used to interact with the ERC1056 contract on behalf of a local controller key-pair
*/
export class EthrDidController {

@@ -10,8 +14,43 @@ private contract: Contract

private address: string
public did: string
constructor(identifier: string | address, contract: Contract, signer?: Signer) {
this.contract = contract
/**
* Creates an EthrDidController instance.
*
* @param identifier - required - a `did:ethr` string or a publicKeyHex or an ethereum address
* @param signer - optional - a Signer that represents the current controller key (owner) of the identifier. If a 'signer' is not provided, then a 'contract' with an attached signer can be used.
* @param contract - optional - a Contract instance representing a ERC1056 contract. At least one of `contract`, `provider`, or `rpcUrl` is required
* @param chainNameOrId - optional - the network name or chainID, defaults to 'mainnet'
* @param provider - optional - a web3 Provider. At least one of `contract`, `provider`, or `rpcUrl` is required
* @param rpcUrl - optional - a JSON-RPC URL that can be used to connect to an ethereum network. At least one of `contract`, `provider`, or `rpcUrl` is required
* @param registry - optional - The ERC1056 registry address. Defaults to '0xdca7ef03e98e0dc2b855be647c39abe984fcf21b'. Only used with 'provider' or 'rpcUrl'
*/
constructor(
identifier: string | address,
contract?: Contract,
signer?: Signer,
chainNameOrId = 'mainnet',
provider?: Provider,
rpcUrl?: string,
registry: string = DEFAULT_REGISTRY_ADDRESS
) {
// initialize identifier
const { address, publicKey, network } = interpretIdentifier(identifier)
const net = network || chainNameOrId
// initialize contract connection
if (contract) {
this.contract = contract
} else if (provider || signer?.provider) {
const prov = provider || signer?.provider
this.contract = getContractForNetwork({ name: net, provider: prov, registry, rpcUrl })
} else {
throw new Error(' either a contract instance or a provider or rpcUrl is required to initialize')
}
this.signer = signer
const { address } = interpretIdentifier(identifier)
this.address = address
let networkString = net ? `${net}:` : ''
if (networkString in ['mainnet:', '0x1:']) {
networkString = ''
}
this.did = publicKey ? `did:ethr:${networkString}${publicKey}` : `did:ethr:${networkString}${address}`
}

@@ -18,0 +57,0 @@

@@ -93,7 +93,16 @@ import { getAddress } from '@ethersproject/address'

export function interpretIdentifier(identifier: string): { address: string; publicKey?: string } {
if (identifier.length > 42) {
return { address: computeAddress(identifier), publicKey: identifier }
export function interpretIdentifier(identifier: string): { address: string; publicKey?: string; network?: string } {
let input = identifier
let network = undefined
if (input.startsWith('did:ethr')) {
const components = input.split(':')
input = components[components.length - 1]
if (components.length === 4) {
network = components[2]
}
}
if (input.length > 42) {
return { address: computeAddress(input), publicKey: input, network }
} else {
return { address: getAddress(identifier) } // checksum address
return { address: getAddress(input), network } // checksum address
}

@@ -100,0 +109,0 @@ }

import { getResolver } from './resolver'
import { EthrDidController } from './controller'
import {

@@ -18,2 +19,3 @@ bytes32toString,

stringToBytes32,
EthrDidController,
/**@deprecated */

@@ -20,0 +22,0 @@ legacyAlgoMap as delegateTypes,

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc