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

ethr-did-resolver

Package Overview
Dependencies
Maintainers
5
Versions
84
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 6.2.0 to 6.2.1

lib/config/deployments.d.ts

4

lib/configuration.d.ts
import { Contract } from '@ethersproject/contracts';
import { Provider } from '@ethersproject/providers';
import { EthrDidRegistryDeployment } from 'ethr-did-registry';
import { EthrDidRegistryDeployment } from './config/deployments';
/**

@@ -33,3 +33,3 @@ * A configuration entry for an ethereum network

* @returns a record of ERC1056 `Contract` instances
* @param conf configuration options for the resolver. An array of network details.
* @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`

@@ -36,0 +36,0 @@ * For convenience, you can also specify an `infuraProjectId` which will create a mapping for all the networks

@@ -10,6 +10,6 @@ import { Signer } from '@ethersproject/abstract-signer';

private contract;
private signer?;
private address;
did: string;
private legacyNonce;
private readonly signer?;
private readonly address;
readonly did: string;
private readonly legacyNonce;
/**

@@ -19,9 +19,14 @@ * 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 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'
* @param legacyNonce - optional - If the legacy nonce tracking method should be accounted for. If lesser version of did-ethr-registry contract v1.0.0 is used then this should be true.
* @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'
* @param legacyNonce - optional - If the legacy nonce tracking method should be accounted for. If lesser version of
* did-ethr-registry contract v1.0.0 is used then this should be true.
*/

@@ -45,6 +50,12 @@ constructor(identifier: string | address, contract?: Contract, signer?: Signer, chainNameOrId?: string, provider?: Provider, rpcUrl?: string, registry?: string, legacyNonce?: boolean);

createRevokeAttributeHash(attrName: string, attrValue: string): Promise<string>;
private getPaddedNonceCompatability;
private getPaddedNonce;
/**
* The legacy version of the ethr-did-registry contract tracks the nonce as a property of the original owner, and not
* as a property of the signer (current owner). That's why we need to differentiate between deployments here, or
* otherwise our signature will be computed wrong resulting in a failed TX.
*
* Not only that, but the nonce is loaded differently for [set/revoke]AttributeSigned methods.
*/
private getPaddedNonceCompatibility;
revokeAttributeSigned(attrName: string, attrValue: string, metaSignature: MetaSignature, options?: CallOverrides): Promise<TransactionReceipt>;
}
//# sourceMappingURL=controller.d.ts.map
import { getResolver } from './resolver';
import { EthrDidController } from './controller';
import { bytes32toString, DEFAULT_REGISTRY_ADDRESS, identifierMatcher, interpretIdentifier, legacyAlgoMap, legacyAttrTypes, stringToBytes32, verificationMethodTypes, Errors } from './helpers';
import { bytes32toString, DEFAULT_REGISTRY_ADDRESS, Errors, identifierMatcher, interpretIdentifier, legacyAlgoMap, legacyAttrTypes, stringToBytes32, verificationMethodTypes } from './helpers';
import { default as EthereumDIDRegistry } from './config/EthereumDIDRegistry.json';
export { DEFAULT_REGISTRY_ADDRESS as REGISTRY, getResolver, bytes32toString, stringToBytes32, EthrDidController,

@@ -8,3 +9,4 @@ /**@deprecated */

/**@deprecated */
legacyAttrTypes as attrTypes, verificationMethodTypes, identifierMatcher, interpretIdentifier, Errors, };
legacyAttrTypes as attrTypes, verificationMethodTypes, identifierMatcher, interpretIdentifier, Errors, EthereumDIDRegistry, };
export { deployments, EthrDidRegistryDeployment } from './config/deployments';
//# sourceMappingURL=index.d.ts.map
{
"name": "ethr-did-resolver",
"version": "6.2.0",
"version": "6.2.1",
"description": "Resolve DID documents for ethereum addresses and public keys",

@@ -15,5 +15,15 @@ "type": "module",

"require": "./lib/index.cjs",
"import": "./lib/index.module.js"
"import": "./lib/index.modern.js"
}
},
"typesVersions": {
"*": {
"lib/index.d.ts": [
"lib/index.d.ts"
],
"*": [
"./lib/index.d.js"
]
}
},
"repository": {

@@ -106,5 +116,4 @@ "type": "git",

"@ethersproject/transactions": "^5.6.2",
"did-resolver": "^4.0.0",
"ethr-did-registry": "^1.0.0"
"did-resolver": "^4.0.0"
}
}

@@ -8,11 +8,14 @@ import { Contract, ContractFactory } from '@ethersproject/contracts'

import { SigningKey } from '@ethersproject/signing-key'
import { default as EthereumDIDRegistry } from './EthereumDIDRegistry-Legacy/LegacyEthereumDIDRegistry.json'
import { default as LegacyEthereumDIDRegistry } from './EthereumDIDRegistry-Legacy/LegacyEthereumDIDRegistry.json'
import { default as EthereumDIDRegistry } from '../config/EthereumDIDRegistry.json'
jest.setTimeout(30000)
describe('nonce tracking compatability', () => {
describe('nonce tracking', () => {
// let registry, accounts, did, identity, controller, delegate1, delegate2, ethr, didResolver
let registryContract: Contract,
let legacyRegistryContract: Contract,
registryContract: Contract,
accounts: string[],
did: string,
legacyDid: string,
identity: string,

@@ -28,11 +31,13 @@ controller: string,

beforeAll(async () => {
const legacyFactory = ContractFactory.fromSolidity(LegacyEthereumDIDRegistry).connect(web3Provider.getSigner(0))
legacyRegistryContract = await legacyFactory.deploy()
legacyRegistryContract = await legacyRegistryContract.deployed()
await legacyRegistryContract.deployTransaction.wait()
const legacyRegistryAddress = legacyRegistryContract.address
const factory = ContractFactory.fromSolidity(EthereumDIDRegistry).connect(web3Provider.getSigner(0))
registryContract = await factory.deploy()
registryContract = await registryContract.deployed()
registryContract = await (await factory.deploy()).deployed()
await registryContract.deployTransaction.wait()
const registryAddress = registryContract.address
const registry = registryContract.address
accounts = await web3Provider.listAccounts()

@@ -45,9 +50,16 @@

keyAgreementController = accounts[5]
legacyDid = `did:ethr:legacy:${identity}`
did = `did:ethr:dev:${identity}`
didResolver = new Resolver(getResolver({ name: 'dev', provider: web3Provider, registry }))
didResolver = new Resolver(
getResolver({
networks: [
{ name: 'legacy', provider: web3Provider, registry: legacyRegistryAddress },
{ name: 'dev', provider: web3Provider, registry: registryAddress },
],
})
)
})
describe('nonce compatability', () => {
it('changing owner two times should result in original owner wallet nonce increase', async () => {
describe('new contract', () => {
it('changing owner two times should result in original owner wallet nonce increase only once', async () => {
// Wallet signing the transaction

@@ -67,8 +79,107 @@ const signer = accounts[1]

console.log(await registryContract.functions.nonce(originalOwner))
const ethrController = new EthrDidController(
identifier,
registryContract,
web3Provider.getSigner(signer),
undefined,
undefined,
undefined,
undefined,
false
)
const hash = await new EthrDidController(identifier, registryContract).createChangeOwnerHash(nextOwner)
const hash = await ethrController.createChangeOwnerHash(nextOwner)
const signature = new SigningKey(originalOwnerPrivateKey).signDigest(hash)
await new EthrDidController(identifier, registryContract, web3Provider.getSigner(signer)).changeOwnerSigned(
await ethrController.changeOwnerSigned(nextOwner, {
sigV: signature.v,
sigR: signature.r,
sigS: signature.s,
})
const hash2 = await ethrController.createChangeOwnerHash(finalOwner)
const signature2 = new SigningKey(nextOwnerPrivateKey).signDigest(hash2)
await ethrController.changeOwnerSigned(finalOwner, {
sigV: signature2.v,
sigR: signature2.r,
sigS: signature2.s,
})
const originalNonce = await registryContract.functions.nonce(originalOwner)
const signerNonce = await registryContract.functions.nonce(nextOwner)
expect(originalNonce[0]._hex).toEqual('0x01')
expect(signerNonce[0]._hex).toEqual('0x01')
})
it('set attribute after owner change should result in original owner wallet nonce increase', async () => {
const signer = accounts[1]
const originalOwner = accounts[5]
const nextOwner = accounts[6]
const serviceEndpointParams = { uri: 'https://didcomm.example.com', transportType: 'http' }
const attributeName = 'did/svc/testService'
const attributeValue = JSON.stringify(serviceEndpointParams)
const attributeExpiration = 86400
const identifier = `did:ethr:dev:${originalOwner}`
const originalOwnerPrivateKey = arrayify('0x0000000000000000000000000000000000000000000000000000000000000005')
const nextOwnerPrivateKey = arrayify('0x0000000000000000000000000000000000000000000000000000000000000006')
const ethrController = new EthrDidController(
identifier,
registryContract,
web3Provider.getSigner(signer),
undefined,
undefined,
undefined,
undefined,
false
)
const hash = await ethrController.createChangeOwnerHash(nextOwner)
const signature = new SigningKey(originalOwnerPrivateKey).signDigest(hash)
await ethrController.changeOwnerSigned(nextOwner, {
sigV: signature.v,
sigR: signature.r,
sigS: signature.s,
})
const hash2 = await ethrController.createSetAttributeHash(attributeName, attributeValue, attributeExpiration)
const signature2 = new SigningKey(nextOwnerPrivateKey).signDigest(hash2)
await ethrController.setAttributeSigned(attributeName, attributeValue, attributeExpiration, {
sigV: signature2.v,
sigR: signature2.r,
sigS: signature2.s,
})
const originalNonce = await registryContract.functions.nonce(originalOwner)
const signerNonce = await registryContract.functions.nonce(nextOwner)
expect(originalNonce[0]._hex).toEqual('0x01')
expect(signerNonce[0]._hex).toEqual('0x01')
})
})
describe('legacy contract', () => {
it('changing owner two times should result in original owner wallet nonce increase', async () => {
// Wallet signing the transaction
const signer = accounts[1]
// Current Owner of the Identity
const originalOwner = accounts[2]
// New owner of the Identity after change
const nextOwner = accounts[3]
// Final owner of the Identity
const finalOwner = accounts[4]
const identifier = `did:ethr:legacy:${originalOwner}`
const originalOwnerPrivateKey = arrayify('0x0000000000000000000000000000000000000000000000000000000000000002')
const nextOwnerPrivateKey = arrayify('0x0000000000000000000000000000000000000000000000000000000000000003')
const hash = await new EthrDidController(identifier, legacyRegistryContract).createChangeOwnerHash(nextOwner)
const signature = new SigningKey(originalOwnerPrivateKey).signDigest(hash)
await new EthrDidController(identifier, legacyRegistryContract, web3Provider.getSigner(signer)).changeOwnerSigned(
nextOwner,

@@ -82,8 +193,6 @@ {

console.log(await registryContract.functions.nonce(originalOwner))
const hash2 = await new EthrDidController(identifier, registryContract).createChangeOwnerHash(finalOwner)
const hash2 = await new EthrDidController(identifier, legacyRegistryContract).createChangeOwnerHash(finalOwner)
const signature2 = new SigningKey(nextOwnerPrivateKey).signDigest(hash2)
await new EthrDidController(identifier, registryContract, web3Provider.getSigner(signer)).changeOwnerSigned(
await new EthrDidController(identifier, legacyRegistryContract, web3Provider.getSigner(signer)).changeOwnerSigned(
finalOwner,

@@ -97,8 +206,8 @@ {

console.log(await registryContract.functions.nonce(originalOwner))
const nonce = await registryContract.functions.nonce(originalOwner)
// Expect the nonce of the original identity to equal 2 as the nonce tracking in the legacy contract is
// done on an identity basis
expect(nonce[0]._hex).toEqual('0x02')
const originalNonce = await legacyRegistryContract.functions.nonce(originalOwner)
const signerNonce = await legacyRegistryContract.functions.nonce(nextOwner)
expect(originalNonce[0]._hex).toEqual('0x02')
expect(signerNonce[0]._hex).toEqual('0x00')
})

@@ -116,3 +225,3 @@

const identifier = `did:ethr:dev:${originalOwner}`
const identifier = `did:ethr:legacy:${originalOwner}`

@@ -122,6 +231,6 @@ const originalOwnerPrivateKey = arrayify('0x0000000000000000000000000000000000000000000000000000000000000005')

const hash = await new EthrDidController(identifier, registryContract).createChangeOwnerHash(nextOwner)
const hash = await new EthrDidController(identifier, legacyRegistryContract).createChangeOwnerHash(nextOwner)
const signature = new SigningKey(originalOwnerPrivateKey).signDigest(hash)
await new EthrDidController(identifier, registryContract, web3Provider.getSigner(signer)).changeOwnerSigned(
await new EthrDidController(identifier, legacyRegistryContract, web3Provider.getSigner(signer)).changeOwnerSigned(
nextOwner,

@@ -135,3 +244,3 @@ {

const hash2 = await new EthrDidController(identifier, registryContract).createSetAttributeHash(
const hash2 = await new EthrDidController(identifier, legacyRegistryContract).createSetAttributeHash(
attributeName,

@@ -143,14 +252,13 @@ attributeValue,

await new EthrDidController(identifier, registryContract, web3Provider.getSigner(signer)).setAttributeSigned(
attributeName,
attributeValue,
attributeExpiration,
{
sigV: signature2.v,
sigR: signature2.r,
sigS: signature2.s,
}
)
await new EthrDidController(
identifier,
legacyRegistryContract,
web3Provider.getSigner(signer)
).setAttributeSigned(attributeName, attributeValue, attributeExpiration, {
sigV: signature2.v,
sigR: signature2.r,
sigS: signature2.s,
})
const nonce = await registryContract.functions.nonce(originalOwner)
const nonce = await legacyRegistryContract.functions.nonce(originalOwner)

@@ -157,0 +265,0 @@ expect(nonce[0]._hex).toEqual('0x02')

import { BigNumber } from '@ethersproject/bignumber'
import { Contract, ContractFactory } from '@ethersproject/contracts'
import { JsonRpcProvider, Provider } from '@ethersproject/providers'
import { EthereumDIDRegistry, deployments, EthrDidRegistryDeployment } from 'ethr-did-registry'
import { DEFAULT_REGISTRY_ADDRESS } from './helpers'
import { deployments, EthrDidRegistryDeployment } from './config/deployments'
import { default as EthereumDIDRegistry } from './config/EthereumDIDRegistry.json'

@@ -110,3 +111,3 @@ const infuraNames: Record<string, string> = {

* @returns a record of ERC1056 `Contract` instances
* @param conf configuration options for the resolver. An array of network details.
* @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`

@@ -113,0 +114,0 @@ * For convenience, you can also specify an `infuraProjectId` which will create a mapping for all the networks

@@ -22,6 +22,6 @@ import { Signer } from '@ethersproject/abstract-signer'

private contract: Contract
private signer?: Signer
private address: string
public did: string
private legacyNonce: boolean
private readonly signer?: Signer
private readonly address: string
public readonly did: string
private readonly legacyNonce: boolean

@@ -32,9 +32,14 @@ /**

* @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 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'
* @param legacyNonce - optional - If the legacy nonce tracking method should be accounted for. If lesser version of did-ethr-registry contract v1.0.0 is used then this should be true.
* @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'
* @param legacyNonce - optional - If the legacy nonce tracking method should be accounted for. If lesser version of
* did-ethr-registry contract v1.0.0 is used then this should be true.
*/

@@ -102,3 +107,3 @@ constructor(

async createChangeOwnerHash(newOwner: address) {
const paddedNonce = await this.getPaddedNonceCompatability()
const paddedNonce = await this.getPaddedNonceCompatibility()

@@ -162,3 +167,2 @@ const dataToHash = hexConcat([

)
addDelegateTx
return await addDelegateTx.wait()

@@ -168,3 +172,3 @@ }

async createAddDelegateHash(delegateType: string, delegateAddress: address, exp: number) {
const paddedNonce = await this.getPaddedNonceCompatability()
const paddedNonce = await this.getPaddedNonceCompatibility()

@@ -212,3 +216,2 @@ const dataToHash = hexConcat([

)
addDelegateTx
return await addDelegateTx.wait()

@@ -240,3 +243,3 @@ }

async createRevokeDelegateHash(delegateType: string, delegateAddress: address) {
const paddedNonce = await this.getPaddedNonceCompatability()
const paddedNonce = await this.getPaddedNonceCompatibility()

@@ -300,3 +303,3 @@ const dataToHash = hexConcat([

async createSetAttributeHash(attrName: string, attrValue: string, exp: number) {
const paddedNonce = await this.getPaddedNonce()
const paddedNonce = await this.getPaddedNonceCompatibility(true)

@@ -364,3 +367,3 @@ const dataToHash = hexConcat([

async createRevokeAttributeHash(attrName: string, attrValue: string) {
const paddedNonce = await this.getPaddedNonce()
const paddedNonce = await this.getPaddedNonceCompatibility(true)

@@ -377,24 +380,19 @@ const dataToHash = hexConcat([

/*
The current version of the ethr-did-registry contract tracks the nonce as a property
of the original owner, and not as a property of the signer (current owner).
That's why we need to differentiate between deployments here, or otherwise our signature will be
computed wrong resulting in a failed TX
*/
private async getPaddedNonceCompatability() {
let nonce
if (this.legacyNonce) {
const currentOwner = await this.getOwner(this.address)
nonce = await this.contract.nonce(currentOwner)
return zeroPad(arrayify(nonce), 32)
/**
* The legacy version of the ethr-did-registry contract tracks the nonce as a property of the original owner, and not
* as a property of the signer (current owner). That's why we need to differentiate between deployments here, or
* otherwise our signature will be computed wrong resulting in a failed TX.
*
* Not only that, but the nonce is loaded differently for [set/revoke]AttributeSigned methods.
*/
private async getPaddedNonceCompatibility(attribute = false) {
let nonceKey
if (this.legacyNonce && attribute) {
nonceKey = this.address
} else {
return this.getPaddedNonce()
nonceKey = await this.getOwner(this.address)
}
return zeroPad(arrayify(await this.contract.nonce(nonceKey)), 32)
}
private async getPaddedNonce() {
const nonce = await this.contract.nonce(this.address)
return zeroPad(arrayify(nonce), 32)
}
async revokeAttributeSigned(

@@ -401,0 +399,0 @@ attrName: string,

@@ -6,2 +6,3 @@ import { getResolver } from './resolver'

DEFAULT_REGISTRY_ADDRESS,
Errors,
identifierMatcher,

@@ -13,5 +14,6 @@ interpretIdentifier,

verificationMethodTypes,
Errors,
} from './helpers'
import { default as EthereumDIDRegistry } from './config/EthereumDIDRegistry.json'
export {

@@ -31,2 +33,5 @@ DEFAULT_REGISTRY_ADDRESS as REGISTRY,

Errors,
EthereumDIDRegistry,
}
export { deployments, EthrDidRegistryDeployment } from './config/deployments'

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 too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

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