decentralized-identity / ethr-did-resolver

DID resolver for Ethereum Addresses with support for key management

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

The code won't check for rpcUrl

royce777 opened this issue ยท comments

} else if (provider || signer?.provider) {

When the constructor of EthrDID is invoked it creates the DID Controller, and that is where this problem arise :

Error:  either a contract instance or a provider or rpcUrl is required to initialize
    at new K (/home/ruslan/coding/study-ethr-did/newDid/node_modules/ethr-did-resolver/lib/index.umd.js:1:3877)
    at new o (/home/ruslan/coding/study-ethr-did/newDid/node_modules/ethr-did/lib/index.js:1:1618)
    at createDid (file:///home/ruslan/coding/study-ethr-did/newDid/create_identity.js:48:18)
    at test (file:///home/ruslan/coding/study-ethr-did/newDid/create_identity.js:21:15)
    at file:///home/ruslan/coding/study-ethr-did/newDid/create_identity.js:58:2
    at processTicksAndRejections (internal/process/task_queues.js:93:5)

This is generated by the following code, with all of the packages it references being last version available

Web3.providers.HttpProvider.prototype.sendAsync = Web3.providers.HttpProvider.prototype.send
console.log('Connecting to provider...');
const provider = new Web3.providers.HttpProvider('http://localhost:9545');
const web3 = new Web3(provider);
console.log('Connected to the provider');
//contract address of the registry
const RegAddress = '0x1482aDFDC2A33983EE69F9F8e4F852c467688Ea0';

//function where the creation of an identity will be created
const test = async (accounts) => {
	const keyPair = EthrDID.createKeyPair();
	const did0 = createDid(RegAddress, keyPair);
	const ethrDidResolver = getResolver.getResolver(
		{
			name: 'test01',
			rpcUrl: 'http://localhost:9545',
			registry: RegAddress
		}
	);
	const didResolver = new Resolver.Resolver(ethrDidResolver);
	didResolver.resolve("did:ethr:test01:" + did0.address, ethrDidResolver).then((doc) => {
		console.log(doc);
		console.log(doc.didDocument.verificationMethod);
	});
}

//function to create and return the object used to manage a DID
const createDid = (RegAddress, keyPair) => {
	const provider = web3.currentProvider;
	const conf = { 
		...keyPair, 
		registry: RegAddress,
		chainNameOrId : 1337,
		rpcUrl: 'http://localhost:9545',
	};
	console.log(conf);
	const ethrDid = new EthrDID(conf);
	return ethrDid;
}

//actual function that starts executing and this will invoke all the other pieces of code
const networkId = await web3.eth.net.getId();
const chainId = await web3.eth.getChainId();
console.log('netID : ' + networkId);
console.log('chainID : ' + chainId);
web3.eth.getAccounts().then((accounts) => { 
	test(accounts).catch(error => console.log(error));
});

I guess this happens because inside the if statement of the mentioned code line, no check for rpcUrl is performed.
I fixed it by modifying the file : node_modules/ethr-did-resolver/lib/index.umd.js , so that it eventually generates the did with a controller using this " provider: [JsonRpcProvider] " as the provider. Thanks

Can you please clarify if the error is from this line: const ethrDid = new EthrDID(conf); or from this piece of code:

const ethrDidResolver = getResolver.getResolver({
			name: 'test01',
			rpcUrl: 'http://localhost:9545',
			registry: RegAddress
		});

?

const ethrDid = new EthrDID(conf);

Yes, it is from here : const ethrDid = new EthrDID(conf);
Commenting out the resolver stuff doesn't change anything, at least in my case.

๐ŸŽ‰ This issue has been resolved in version 4.3.2 ๐ŸŽ‰

The release is available on:

Your semantic-release bot ๐Ÿ“ฆ๐Ÿš€

@royce777 it should be fixed now, please update ethr-did and ethr-did-resolver to latest