ethr-did-resolver
Advanced tools
Comparing version 6.0.1 to 6.0.2
import { Contract } from '@ethersproject/contracts'; | ||
import { Provider } from '@ethersproject/providers'; | ||
import { EthrDidRegistryDeployment } from 'ethr-did-registry'; | ||
/** | ||
@@ -14,10 +15,6 @@ * A configuration entry for an ethereum network | ||
*/ | ||
export interface ProviderConfiguration { | ||
name?: string; | ||
export interface ProviderConfiguration extends Omit<EthrDidRegistryDeployment, 'chainId'> { | ||
provider?: Provider; | ||
rpcUrl?: string; | ||
registry?: string; | ||
chainId?: string | number; | ||
web3?: any; | ||
[index: string]: any; | ||
} | ||
@@ -34,7 +31,9 @@ export interface MultiProviderConfiguration extends ProviderConfiguration { | ||
/** | ||
* Generates a configuration that maps ethereum network names and chainIDs to the respective ERC1056 contracts deployed on them. | ||
* Generates a configuration that maps ethereum network names and chainIDs to the respective ERC1056 contracts deployed | ||
* on them. | ||
* @returns a record of ERC1056 `Contract` instances | ||
* @param conf configuration options for the resolver. An array of network details. | ||
* Each network entry should contain at least one of `name` or `chainId` AND one of `provider`, `web3`, or `rpcUrl` | ||
* For convenience, you can also specify an `infuraProjectId` which will create a mapping for all the networks supported by https://infura.io. | ||
* For convenience, you can also specify an `infuraProjectId` which will create a mapping for all the networks | ||
* supported by https://infura.io. | ||
* @example ```js | ||
@@ -41,0 +40,0 @@ * [ |
@@ -62,4 +62,2 @@ import { BigNumber } from '@ethersproject/bignumber'; | ||
}; | ||
export declare const knownInfuraNetworks: Record<string, string>; | ||
export declare const knownNetworks: Record<string, string>; | ||
export declare enum Errors { | ||
@@ -66,0 +64,0 @@ /** |
import { Base58 } from '@ethersproject/basex'; | ||
import { BigNumber } from '@ethersproject/bignumber'; | ||
import { ContractFactory } from '@ethersproject/contracts'; | ||
import { JsonRpcProvider, InfuraProvider } from '@ethersproject/providers'; | ||
import DidRegistryContract from 'ethr-did-registry'; | ||
import { JsonRpcProvider } from '@ethersproject/providers'; | ||
import { deployments, EthereumDIDRegistry } from 'ethr-did-registry'; | ||
import { getAddress } from '@ethersproject/address'; | ||
@@ -104,17 +104,2 @@ import { computeAddress } from '@ethersproject/transactions'; | ||
} | ||
const knownInfuraNetworks = { | ||
mainnet: '0x1', | ||
ropsten: '0x3', | ||
rinkeby: '0x4', | ||
goerli: '0x5', | ||
kovan: '0x2a' | ||
}; | ||
const knownNetworks = _extends({}, knownInfuraNetworks, { | ||
rsk: '0x1e', | ||
'rsk:testnet': '0x1f', | ||
artis_t1: '0x03c401', | ||
artis_s1: '0x03c301', | ||
matic: '0x89', | ||
maticmum: '0x13881' | ||
}); | ||
var Errors; | ||
@@ -141,2 +126,9 @@ | ||
const infuraNames = { | ||
polygon: 'matic', | ||
'polygon:test': 'maticmum', | ||
aurora: 'aurora-mainnet' | ||
}; | ||
const knownInfuraNames = ['mainnet', 'ropsten', 'rinkeby', 'goerli', 'kovan', 'aurora']; | ||
function configureNetworksWithInfura(projectId) { | ||
@@ -147,23 +139,13 @@ if (!projectId) { | ||
const networks = [{ | ||
name: 'mainnet', | ||
chainId: '0x1', | ||
provider: new InfuraProvider('homestead', projectId) | ||
}, { | ||
name: 'ropsten', | ||
chainId: '0x3', | ||
provider: new InfuraProvider('ropsten', projectId) | ||
}, { | ||
name: 'rinkeby', | ||
chainId: '0x4', | ||
provider: new InfuraProvider('rinkeby', projectId) | ||
}, { | ||
name: 'goerli', | ||
chainId: '0x5', | ||
provider: new InfuraProvider('goerli', projectId) | ||
}, { | ||
name: 'kovan', | ||
chainId: '0x2a', | ||
provider: new InfuraProvider('kovan', projectId) | ||
}]; | ||
const networks = knownInfuraNames.map(n => { | ||
const existingDeployment = deployments.find(d => d.name === n); | ||
if (existingDeployment && existingDeployment.name) { | ||
const infuraName = infuraNames[existingDeployment.name] || existingDeployment.name; | ||
const rpcUrl = `https://${infuraName}.infura.io/v3/${projectId}`; | ||
return _extends({}, existingDeployment, { | ||
rpcUrl | ||
}); | ||
} | ||
}).filter(conf => !!conf); | ||
return configureNetworks({ | ||
@@ -181,8 +163,7 @@ networks | ||
if (conf.rpcUrl) { | ||
var _conf$name; | ||
var _deployments$find; | ||
const chainIdRaw = conf.chainId ? conf.chainId : knownNetworks[conf.name || '']; | ||
const chainIdRaw = conf.chainId ? conf.chainId : (_deployments$find = deployments.find(d => d.name === conf.name)) == null ? void 0 : _deployments$find.chainId; | ||
const chainId = chainIdRaw ? BigNumber.from(chainIdRaw).toNumber() : chainIdRaw; | ||
const networkName = knownInfuraNetworks[conf.name || ''] ? (_conf$name = conf.name) == null ? void 0 : _conf$name.replace('mainnet', 'homestead') : 'any'; | ||
provider = new JsonRpcProvider(conf.rpcUrl, chainId || networkName); | ||
provider = new JsonRpcProvider(conf.rpcUrl, chainId || 'any'); | ||
} else { | ||
@@ -193,3 +174,3 @@ throw new Error(`invalid_config: No web3 provider could be determined for network ${conf.name || conf.chainId}`); | ||
const contract = ContractFactory.fromSolidity(DidRegistryContract).attach(conf.registry || DEFAULT_REGISTRY_ADDRESS).connect(provider); | ||
const contract = ContractFactory.fromSolidity(EthereumDIDRegistry).attach(conf.registry || DEFAULT_REGISTRY_ADDRESS).connect(provider); | ||
return contract; | ||
@@ -199,4 +180,6 @@ } | ||
function configureNetwork(net) { | ||
var _deployments$find2; | ||
const networks = {}; | ||
const chainId = net.chainId || knownNetworks[net.name || '']; | ||
const chainId = net.chainId || ((_deployments$find2 = deployments.find(d => net.name && (d.name === net.name || d.description === net.name))) == null ? void 0 : _deployments$find2.chainId); | ||
@@ -225,7 +208,9 @@ if (chainId) { | ||
/** | ||
* Generates a configuration that maps ethereum network names and chainIDs to the respective ERC1056 contracts deployed on them. | ||
* Generates a configuration that maps ethereum network names and chainIDs to the respective ERC1056 contracts deployed | ||
* on them. | ||
* @returns a record of ERC1056 `Contract` instances | ||
* @param conf configuration options for the resolver. An array of network details. | ||
* Each network entry should contain at least one of `name` or `chainId` AND one of `provider`, `web3`, or `rpcUrl` | ||
* For convenience, you can also specify an `infuraProjectId` which will create a mapping for all the networks supported by https://infura.io. | ||
* For convenience, you can also specify an `infuraProjectId` which will create a mapping for all the networks | ||
* supported by https://infura.io. | ||
* @example ```js | ||
@@ -470,3 +455,3 @@ * [ | ||
const provider = contract.provider; | ||
const hexChainId = networkId.startsWith('0x') ? networkId : knownNetworks[networkId]; //TODO: this can be used to check if the configuration is ok | ||
const hexChainId = networkId.startsWith('0x') ? networkId : undefined; //TODO: this can be used to check if the configuration is ok | ||
@@ -483,5 +468,3 @@ const chainId = hexChainId ? BigNumber.from(hexChainId).toNumber() : (await provider.getNetwork()).chainId; | ||
while (previousChange) { | ||
const blockNumber = previousChange; // console.log(`gigel ${previousChange}`) | ||
const fromBlock = previousChange.toHexString() !== '0x00' ? previousChange.sub(1).toHexString() : previousChange.toHexString(); | ||
const blockNumber = previousChange; | ||
const logs = await provider.getLogs({ | ||
@@ -491,3 +474,3 @@ address: contract.address, | ||
topics: [null, `0x000000000000000000000000${address.slice(2)}`], | ||
fromBlock, | ||
fromBlock: previousChange.toHexString(), | ||
toBlock: previousChange.toHexString() | ||
@@ -494,0 +477,0 @@ }); |
import { Base58 } from '@ethersproject/basex'; | ||
import { BigNumber } from '@ethersproject/bignumber'; | ||
import { ContractFactory } from '@ethersproject/contracts'; | ||
import { JsonRpcProvider, InfuraProvider } from '@ethersproject/providers'; | ||
import DidRegistryContract from 'ethr-did-registry'; | ||
import { JsonRpcProvider } from '@ethersproject/providers'; | ||
import { deployments, EthereumDIDRegistry } from 'ethr-did-registry'; | ||
import { getAddress } from '@ethersproject/address'; | ||
@@ -87,17 +87,2 @@ import { computeAddress } from '@ethersproject/transactions'; | ||
} | ||
const knownInfuraNetworks = { | ||
mainnet: '0x1', | ||
ropsten: '0x3', | ||
rinkeby: '0x4', | ||
goerli: '0x5', | ||
kovan: '0x2a' | ||
}; | ||
const knownNetworks = { ...knownInfuraNetworks, | ||
rsk: '0x1e', | ||
'rsk:testnet': '0x1f', | ||
artis_t1: '0x03c401', | ||
artis_s1: '0x03c301', | ||
matic: '0x89', | ||
maticmum: '0x13881' | ||
}; | ||
var Errors; | ||
@@ -124,2 +109,9 @@ | ||
const infuraNames = { | ||
polygon: 'matic', | ||
'polygon:test': 'maticmum', | ||
aurora: 'aurora-mainnet' | ||
}; | ||
const knownInfuraNames = ['mainnet', 'ropsten', 'rinkeby', 'goerli', 'kovan', 'aurora']; | ||
function configureNetworksWithInfura(projectId) { | ||
@@ -130,23 +122,13 @@ if (!projectId) { | ||
const networks = [{ | ||
name: 'mainnet', | ||
chainId: '0x1', | ||
provider: new InfuraProvider('homestead', projectId) | ||
}, { | ||
name: 'ropsten', | ||
chainId: '0x3', | ||
provider: new InfuraProvider('ropsten', projectId) | ||
}, { | ||
name: 'rinkeby', | ||
chainId: '0x4', | ||
provider: new InfuraProvider('rinkeby', projectId) | ||
}, { | ||
name: 'goerli', | ||
chainId: '0x5', | ||
provider: new InfuraProvider('goerli', projectId) | ||
}, { | ||
name: 'kovan', | ||
chainId: '0x2a', | ||
provider: new InfuraProvider('kovan', projectId) | ||
}]; | ||
const networks = knownInfuraNames.map(n => { | ||
const existingDeployment = deployments.find(d => d.name === n); | ||
if (existingDeployment && existingDeployment.name) { | ||
const infuraName = infuraNames[existingDeployment.name] || existingDeployment.name; | ||
const rpcUrl = `https://${infuraName}.infura.io/v3/${projectId}`; | ||
return { ...existingDeployment, | ||
rpcUrl | ||
}; | ||
} | ||
}).filter(conf => !!conf); | ||
return configureNetworks({ | ||
@@ -164,8 +146,7 @@ networks | ||
if (conf.rpcUrl) { | ||
var _conf$name; | ||
var _deployments$find; | ||
const chainIdRaw = conf.chainId ? conf.chainId : knownNetworks[conf.name || '']; | ||
const chainIdRaw = conf.chainId ? conf.chainId : (_deployments$find = deployments.find(d => d.name === conf.name)) == null ? void 0 : _deployments$find.chainId; | ||
const chainId = chainIdRaw ? BigNumber.from(chainIdRaw).toNumber() : chainIdRaw; | ||
const networkName = knownInfuraNetworks[conf.name || ''] ? (_conf$name = conf.name) == null ? void 0 : _conf$name.replace('mainnet', 'homestead') : 'any'; | ||
provider = new JsonRpcProvider(conf.rpcUrl, chainId || networkName); | ||
provider = new JsonRpcProvider(conf.rpcUrl, chainId || 'any'); | ||
} else { | ||
@@ -176,3 +157,3 @@ throw new Error(`invalid_config: No web3 provider could be determined for network ${conf.name || conf.chainId}`); | ||
const contract = ContractFactory.fromSolidity(DidRegistryContract).attach(conf.registry || DEFAULT_REGISTRY_ADDRESS).connect(provider); | ||
const contract = ContractFactory.fromSolidity(EthereumDIDRegistry).attach(conf.registry || DEFAULT_REGISTRY_ADDRESS).connect(provider); | ||
return contract; | ||
@@ -182,4 +163,6 @@ } | ||
function configureNetwork(net) { | ||
var _deployments$find2; | ||
const networks = {}; | ||
const chainId = net.chainId || knownNetworks[net.name || '']; | ||
const chainId = net.chainId || ((_deployments$find2 = deployments.find(d => net.name && (d.name === net.name || d.description === net.name))) == null ? void 0 : _deployments$find2.chainId); | ||
@@ -212,7 +195,9 @@ if (chainId) { | ||
/** | ||
* Generates a configuration that maps ethereum network names and chainIDs to the respective ERC1056 contracts deployed on them. | ||
* Generates a configuration that maps ethereum network names and chainIDs to the respective ERC1056 contracts deployed | ||
* on them. | ||
* @returns a record of ERC1056 `Contract` instances | ||
* @param conf configuration options for the resolver. An array of network details. | ||
* Each network entry should contain at least one of `name` or `chainId` AND one of `provider`, `web3`, or `rpcUrl` | ||
* For convenience, you can also specify an `infuraProjectId` which will create a mapping for all the networks supported by https://infura.io. | ||
* For convenience, you can also specify an `infuraProjectId` which will create a mapping for all the networks | ||
* supported by https://infura.io. | ||
* @example ```js | ||
@@ -759,5 +744,3 @@ * [ | ||
}, void 0, function () { | ||
const blockNumber = previousChange; // console.log(`gigel ${previousChange}`) | ||
const fromBlock = previousChange.toHexString() !== '0x00' ? previousChange.sub(1).toHexString() : previousChange.toHexString(); | ||
const blockNumber = previousChange; | ||
return Promise.resolve(provider.getLogs({ | ||
@@ -767,3 +750,3 @@ address: contract.address, | ||
topics: [null, `0x000000000000000000000000${address.slice(2)}`], | ||
fromBlock, | ||
fromBlock: previousChange.toHexString(), | ||
toBlock: previousChange.toHexString() | ||
@@ -791,3 +774,3 @@ })).then(function (logs) { | ||
const provider = contract.provider; | ||
const hexChainId = networkId.startsWith('0x') ? networkId : knownNetworks[networkId]; //TODO: this can be used to check if the configuration is ok | ||
const hexChainId = networkId.startsWith('0x') ? networkId : undefined; //TODO: this can be used to check if the configuration is ok | ||
@@ -794,0 +777,0 @@ return Promise.resolve(hexChainId ? _temp3(BigNumber.from(hexChainId).toNumber()) : Promise.resolve(provider.getNetwork()).then(_temp3)); |
@@ -5,7 +5,3 @@ (function (global, factory) { | ||
(global = global || self, factory(global.ethrDidResolver = {}, global.basex, global.bignumber, global.contracts, global.providers, global.ethrDidRegistry, global.address, global.transactions)); | ||
})(this, (function (exports, basex, bignumber, contracts, providers, DidRegistryContract, address, transactions) { | ||
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; } | ||
var DidRegistryContract__default = /*#__PURE__*/_interopDefaultLegacy(DidRegistryContract); | ||
})(this, (function (exports, basex, bignumber, contracts, providers, ethrDidRegistry, address, transactions) { | ||
const identifierMatcher = /^(.*)?(0x[0-9a-fA-F]{40}|0x[0-9a-fA-F]{66})$/; | ||
@@ -89,17 +85,2 @@ const nullAddress = '0x0000000000000000000000000000000000000000'; | ||
} | ||
const knownInfuraNetworks = { | ||
mainnet: '0x1', | ||
ropsten: '0x3', | ||
rinkeby: '0x4', | ||
goerli: '0x5', | ||
kovan: '0x2a' | ||
}; | ||
const knownNetworks = { ...knownInfuraNetworks, | ||
rsk: '0x1e', | ||
'rsk:testnet': '0x1f', | ||
artis_t1: '0x03c401', | ||
artis_s1: '0x03c301', | ||
matic: '0x89', | ||
maticmum: '0x13881' | ||
}; | ||
exports.Errors = void 0; | ||
@@ -126,2 +107,9 @@ | ||
const infuraNames = { | ||
polygon: 'matic', | ||
'polygon:test': 'maticmum', | ||
aurora: 'aurora-mainnet' | ||
}; | ||
const knownInfuraNames = ['mainnet', 'ropsten', 'rinkeby', 'goerli', 'kovan', 'aurora']; | ||
function configureNetworksWithInfura(projectId) { | ||
@@ -132,23 +120,13 @@ if (!projectId) { | ||
const networks = [{ | ||
name: 'mainnet', | ||
chainId: '0x1', | ||
provider: new providers.InfuraProvider('homestead', projectId) | ||
}, { | ||
name: 'ropsten', | ||
chainId: '0x3', | ||
provider: new providers.InfuraProvider('ropsten', projectId) | ||
}, { | ||
name: 'rinkeby', | ||
chainId: '0x4', | ||
provider: new providers.InfuraProvider('rinkeby', projectId) | ||
}, { | ||
name: 'goerli', | ||
chainId: '0x5', | ||
provider: new providers.InfuraProvider('goerli', projectId) | ||
}, { | ||
name: 'kovan', | ||
chainId: '0x2a', | ||
provider: new providers.InfuraProvider('kovan', projectId) | ||
}]; | ||
const networks = knownInfuraNames.map(n => { | ||
const existingDeployment = ethrDidRegistry.deployments.find(d => d.name === n); | ||
if (existingDeployment && existingDeployment.name) { | ||
const infuraName = infuraNames[existingDeployment.name] || existingDeployment.name; | ||
const rpcUrl = `https://${infuraName}.infura.io/v3/${projectId}`; | ||
return { ...existingDeployment, | ||
rpcUrl | ||
}; | ||
} | ||
}).filter(conf => !!conf); | ||
return configureNetworks({ | ||
@@ -166,8 +144,7 @@ networks | ||
if (conf.rpcUrl) { | ||
var _conf$name; | ||
var _deployments$find; | ||
const chainIdRaw = conf.chainId ? conf.chainId : knownNetworks[conf.name || '']; | ||
const chainIdRaw = conf.chainId ? conf.chainId : (_deployments$find = ethrDidRegistry.deployments.find(d => d.name === conf.name)) == null ? void 0 : _deployments$find.chainId; | ||
const chainId = chainIdRaw ? bignumber.BigNumber.from(chainIdRaw).toNumber() : chainIdRaw; | ||
const networkName = knownInfuraNetworks[conf.name || ''] ? (_conf$name = conf.name) == null ? void 0 : _conf$name.replace('mainnet', 'homestead') : 'any'; | ||
provider = new providers.JsonRpcProvider(conf.rpcUrl, chainId || networkName); | ||
provider = new providers.JsonRpcProvider(conf.rpcUrl, chainId || 'any'); | ||
} else { | ||
@@ -178,3 +155,3 @@ throw new Error(`invalid_config: No web3 provider could be determined for network ${conf.name || conf.chainId}`); | ||
const contract = contracts.ContractFactory.fromSolidity(DidRegistryContract__default["default"]).attach(conf.registry || DEFAULT_REGISTRY_ADDRESS).connect(provider); | ||
const contract = contracts.ContractFactory.fromSolidity(ethrDidRegistry.EthereumDIDRegistry).attach(conf.registry || DEFAULT_REGISTRY_ADDRESS).connect(provider); | ||
return contract; | ||
@@ -184,4 +161,6 @@ } | ||
function configureNetwork(net) { | ||
var _deployments$find2; | ||
const networks = {}; | ||
const chainId = net.chainId || knownNetworks[net.name || '']; | ||
const chainId = net.chainId || ((_deployments$find2 = ethrDidRegistry.deployments.find(d => net.name && (d.name === net.name || d.description === net.name))) == null ? void 0 : _deployments$find2.chainId); | ||
@@ -214,7 +193,9 @@ if (chainId) { | ||
/** | ||
* Generates a configuration that maps ethereum network names and chainIDs to the respective ERC1056 contracts deployed on them. | ||
* Generates a configuration that maps ethereum network names and chainIDs to the respective ERC1056 contracts deployed | ||
* on them. | ||
* @returns a record of ERC1056 `Contract` instances | ||
* @param conf configuration options for the resolver. An array of network details. | ||
* Each network entry should contain at least one of `name` or `chainId` AND one of `provider`, `web3`, or `rpcUrl` | ||
* For convenience, you can also specify an `infuraProjectId` which will create a mapping for all the networks supported by https://infura.io. | ||
* For convenience, you can also specify an `infuraProjectId` which will create a mapping for all the networks | ||
* supported by https://infura.io. | ||
* @example ```js | ||
@@ -761,5 +742,3 @@ * [ | ||
}, void 0, function () { | ||
const blockNumber = previousChange; // console.log(`gigel ${previousChange}`) | ||
const fromBlock = previousChange.toHexString() !== '0x00' ? previousChange.sub(1).toHexString() : previousChange.toHexString(); | ||
const blockNumber = previousChange; | ||
return Promise.resolve(provider.getLogs({ | ||
@@ -769,3 +748,3 @@ address: contract.address, | ||
topics: [null, `0x000000000000000000000000${address.slice(2)}`], | ||
fromBlock, | ||
fromBlock: previousChange.toHexString(), | ||
toBlock: previousChange.toHexString() | ||
@@ -793,3 +772,3 @@ })).then(function (logs) { | ||
const provider = contract.provider; | ||
const hexChainId = networkId.startsWith('0x') ? networkId : knownNetworks[networkId]; //TODO: this can be used to check if the configuration is ok | ||
const hexChainId = networkId.startsWith('0x') ? networkId : undefined; //TODO: this can be used to check if the configuration is ok | ||
@@ -796,0 +775,0 @@ return Promise.resolve(hexChainId ? _temp3(bignumber.BigNumber.from(hexChainId).toNumber()) : Promise.resolve(provider.getNetwork()).then(_temp3)); |
{ | ||
"name": "ethr-did-resolver", | ||
"version": "6.0.1", | ||
"version": "6.0.2", | ||
"description": "Resolve DID documents for ethereum addresses and public keys", | ||
@@ -78,5 +78,5 @@ "type": "module", | ||
"@types/jest": "28.1.1", | ||
"@typescript-eslint/eslint-plugin": "5.27.0", | ||
"@typescript-eslint/parser": "5.27.0", | ||
"babel-jest": "28.1.0", | ||
"@typescript-eslint/eslint-plugin": "5.27.1", | ||
"@typescript-eslint/parser": "5.27.1", | ||
"babel-jest": "28.1.1", | ||
"eslint": "8.17.0", | ||
@@ -86,7 +86,7 @@ "eslint-config-prettier": "8.5.0", | ||
"eslint-plugin-prettier": "4.0.0", | ||
"ganache": "7.2.0", | ||
"jest": "28.1.0", | ||
"ganache": "7.3.0", | ||
"jest": "28.1.1", | ||
"microbundle": "0.15.0", | ||
"prettier": "2.6.2", | ||
"semantic-release": "19.0.2", | ||
"semantic-release": "19.0.3", | ||
"typescript": "4.7.3" | ||
@@ -104,4 +104,4 @@ }, | ||
"did-resolver": "^3.2.2", | ||
"ethr-did-registry": "^0.0.3" | ||
"ethr-did-registry": "^1.0.0" | ||
} | ||
} |
@@ -219,4 +219,4 @@ import { Resolver } from 'did-resolver' | ||
didDocumentMetadata: { | ||
updated: '2022-01-19T12:19:59Z', | ||
versionId: '57702193', | ||
updated: '2022-01-19T12:20:00Z', | ||
versionId: '57702194', | ||
}, | ||
@@ -223,0 +223,0 @@ didResolutionMetadata: { contentType: 'application/did+ld+json' }, |
@@ -5,3 +5,3 @@ import { Contract, ContractFactory } from '@ethersproject/contracts' | ||
import { EthrDidController } from '../controller' | ||
import DidRegistryContract from 'ethr-did-registry' | ||
import { EthereumDIDRegistry } from 'ethr-did-registry' | ||
import { interpretIdentifier, stringToBytes32 } from '../helpers' | ||
@@ -28,3 +28,3 @@ import { createProvider, sleep, startMining, stopMining } from './testUtils' | ||
beforeAll(async () => { | ||
const factory = ContractFactory.fromSolidity(DidRegistryContract).connect(web3Provider.getSigner(0)) | ||
const factory = ContractFactory.fromSolidity(EthereumDIDRegistry).connect(web3Provider.getSigner(0)) | ||
@@ -31,0 +31,0 @@ registryContract = await factory.deploy() |
import { BigNumber } from '@ethersproject/bignumber' | ||
import { Contract, ContractFactory } from '@ethersproject/contracts' | ||
import { InfuraProvider, JsonRpcProvider, Provider } from '@ethersproject/providers' | ||
import DidRegistryContract from 'ethr-did-registry' | ||
import { DEFAULT_REGISTRY_ADDRESS, knownInfuraNetworks, knownNetworks } from './helpers' | ||
import { JsonRpcProvider, Provider } from '@ethersproject/providers' | ||
import { EthereumDIDRegistry, deployments, EthrDidRegistryDeployment } from 'ethr-did-registry' | ||
import { DEFAULT_REGISTRY_ADDRESS } from './helpers' | ||
const infuraNames: Record<string, string> = { | ||
polygon: 'matic', | ||
'polygon:test': 'maticmum', | ||
aurora: 'aurora-mainnet', | ||
} | ||
const knownInfuraNames = ['mainnet', 'ropsten', 'rinkeby', 'goerli', 'kovan', 'aurora'] | ||
/** | ||
@@ -18,12 +26,7 @@ * A configuration entry for an ethereum network | ||
*/ | ||
export interface ProviderConfiguration { | ||
name?: string | ||
export interface ProviderConfiguration extends Omit<EthrDidRegistryDeployment, 'chainId'> { | ||
provider?: Provider | ||
rpcUrl?: string | ||
registry?: string | ||
chainId?: string | number | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
web3?: any | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
[index: string]: any | ||
} | ||
@@ -47,9 +50,14 @@ | ||
} | ||
const networks: ProviderConfiguration[] = [ | ||
{ name: 'mainnet', chainId: '0x1', provider: new InfuraProvider('homestead', projectId) }, | ||
{ name: 'ropsten', chainId: '0x3', provider: new InfuraProvider('ropsten', projectId) }, | ||
{ name: 'rinkeby', chainId: '0x4', provider: new InfuraProvider('rinkeby', projectId) }, | ||
{ name: 'goerli', chainId: '0x5', provider: new InfuraProvider('goerli', projectId) }, | ||
{ name: 'kovan', chainId: '0x2a', provider: new InfuraProvider('kovan', projectId) }, | ||
] | ||
const networks = knownInfuraNames | ||
.map((n) => { | ||
const existingDeployment = deployments.find((d) => d.name === n) | ||
if (existingDeployment && existingDeployment.name) { | ||
const infuraName = infuraNames[existingDeployment.name] || existingDeployment.name | ||
const rpcUrl = `https://${infuraName}.infura.io/v3/${projectId}` | ||
return { ...existingDeployment, rpcUrl } | ||
} | ||
}) | ||
.filter((conf) => !!conf) as ProviderConfiguration[] | ||
return configureNetworks({ networks }) | ||
@@ -62,6 +70,5 @@ } | ||
if (conf.rpcUrl) { | ||
const chainIdRaw = conf.chainId ? conf.chainId : knownNetworks[conf.name || ''] | ||
const chainIdRaw = conf.chainId ? conf.chainId : deployments.find((d) => d.name === conf.name)?.chainId | ||
const chainId = chainIdRaw ? BigNumber.from(chainIdRaw).toNumber() : chainIdRaw | ||
const networkName = knownInfuraNetworks[conf.name || ''] ? conf.name?.replace('mainnet', 'homestead') : 'any' | ||
provider = new JsonRpcProvider(conf.rpcUrl, chainId || networkName) | ||
provider = new JsonRpcProvider(conf.rpcUrl, chainId || 'any') | ||
} else { | ||
@@ -71,3 +78,3 @@ throw new Error(`invalid_config: No web3 provider could be determined for network ${conf.name || conf.chainId}`) | ||
} | ||
const contract: Contract = ContractFactory.fromSolidity(DidRegistryContract) | ||
const contract: Contract = ContractFactory.fromSolidity(EthereumDIDRegistry) | ||
.attach(conf.registry || DEFAULT_REGISTRY_ADDRESS) | ||
@@ -80,3 +87,4 @@ .connect(provider) | ||
const networks: ConfiguredNetworks = {} | ||
const chainId = net.chainId || knownNetworks[net.name || ''] | ||
const chainId = | ||
net.chainId || deployments.find((d) => net.name && (d.name === net.name || d.description === net.name))?.chainId | ||
if (chainId) { | ||
@@ -104,7 +112,9 @@ if (net.name) { | ||
/** | ||
* Generates a configuration that maps ethereum network names and chainIDs to the respective ERC1056 contracts deployed on them. | ||
* Generates a configuration that maps ethereum network names and chainIDs to the respective ERC1056 contracts deployed | ||
* on them. | ||
* @returns a record of ERC1056 `Contract` instances | ||
* @param conf configuration options for the resolver. An array of network details. | ||
* Each network entry should contain at least one of `name` or `chainId` AND one of `provider`, `web3`, or `rpcUrl` | ||
* For convenience, you can also specify an `infuraProjectId` which will create a mapping for all the networks supported by https://infura.io. | ||
* For convenience, you can also specify an `infuraProjectId` which will create a mapping for all the networks | ||
* supported by https://infura.io. | ||
* @example ```js | ||
@@ -111,0 +121,0 @@ * [ |
@@ -116,20 +116,2 @@ import { getAddress } from '@ethersproject/address' | ||
export const knownInfuraNetworks: Record<string, string> = { | ||
mainnet: '0x1', | ||
ropsten: '0x3', | ||
rinkeby: '0x4', | ||
goerli: '0x5', | ||
kovan: '0x2a', | ||
} | ||
export const knownNetworks: Record<string, string> = { | ||
...knownInfuraNetworks, | ||
rsk: '0x1e', | ||
'rsk:testnet': '0x1f', | ||
artis_t1: '0x03c401', | ||
artis_s1: '0x03c301', | ||
matic: '0x89', | ||
maticmum: '0x13881', | ||
} | ||
export enum Errors { | ||
@@ -136,0 +118,0 @@ /** |
@@ -29,3 +29,2 @@ import { Base58 } from '@ethersproject/basex' | ||
DIDOwnerChanged, | ||
knownNetworks, | ||
Errors, | ||
@@ -83,3 +82,3 @@ strip0x, | ||
const provider = contract.provider | ||
const hexChainId = networkId.startsWith('0x') ? networkId : knownNetworks[networkId] | ||
const hexChainId = networkId.startsWith('0x') ? networkId : undefined | ||
//TODO: this can be used to check if the configuration is ok | ||
@@ -93,5 +92,2 @@ const chainId = hexChainId ? BigNumber.from(hexChainId).toNumber() : (await provider.getNetwork()).chainId | ||
const blockNumber = previousChange | ||
// console.log(`gigel ${previousChange}`) | ||
const fromBlock = | ||
previousChange.toHexString() !== '0x00' ? previousChange.sub(1).toHexString() : previousChange.toHexString() | ||
const logs = await provider.getLogs({ | ||
@@ -101,3 +97,3 @@ address: contract.address, // networks[networkId].registryAddress, | ||
topics: [null as any, `0x000000000000000000000000${address.slice(2)}`], | ||
fromBlock, | ||
fromBlock: previousChange.toHexString(), | ||
toBlock: previousChange.toHexString(), | ||
@@ -104,0 +100,0 @@ }) |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
553241
36
6398
+ Addedethr-did-registry@1.3.0(transitive)
- Removedethr-did-registry@0.0.3(transitive)
Updatedethr-did-registry@^1.0.0