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
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 5.0.3 to 5.0.4

3

lib/index.js

@@ -758,2 +758,3 @@ var basex = require('@ethersproject/basex');

const fromBlock = previousChange.toHexString() !== '0x00' ? previousChange.sub(1).toHexString() : previousChange.toHexString();
return Promise.resolve(provider.getLogs({

@@ -763,3 +764,3 @@ address: contract.address,

topics: [null, `0x000000000000000000000000${address.slice(2)}`],
fromBlock: previousChange.toHexString(),
fromBlock,
toBlock: previousChange.toHexString()

@@ -766,0 +767,0 @@ })).then(function (logs) {

@@ -478,2 +478,3 @@ import { Base58 } from '@ethersproject/basex';

const fromBlock = previousChange.toHexString() !== '0x00' ? previousChange.sub(1).toHexString() : previousChange.toHexString();
const logs = await provider.getLogs({

@@ -483,3 +484,3 @@ address: contract.address,

topics: [null, `0x000000000000000000000000${address.slice(2)}`],
fromBlock: previousChange.toHexString(),
fromBlock,
toBlock: previousChange.toHexString()

@@ -486,0 +487,0 @@ });

@@ -754,2 +754,3 @@ import { Base58 } from '@ethersproject/basex';

const fromBlock = previousChange.toHexString() !== '0x00' ? previousChange.sub(1).toHexString() : previousChange.toHexString();
return Promise.resolve(provider.getLogs({

@@ -759,3 +760,3 @@ address: contract.address,

topics: [null, `0x000000000000000000000000${address.slice(2)}`],
fromBlock: previousChange.toHexString(),
fromBlock,
toBlock: previousChange.toHexString()

@@ -762,0 +763,0 @@ })).then(function (logs) {

@@ -755,2 +755,3 @@ (function (global, factory) {

const fromBlock = previousChange.toHexString() !== '0x00' ? previousChange.sub(1).toHexString() : previousChange.toHexString();
return Promise.resolve(provider.getLogs({

@@ -760,3 +761,3 @@ address: contract.address,

topics: [null, `0x000000000000000000000000${address.slice(2)}`],
fromBlock: previousChange.toHexString(),
fromBlock,
toBlock: previousChange.toHexString()

@@ -763,0 +764,0 @@ })).then(function (logs) {

{
"name": "ethr-did-resolver",
"version": "5.0.3",
"version": "5.0.4",
"description": "Resolve DID documents for ethereum addresses and public keys",

@@ -46,7 +46,6 @@ "source": "src/index.ts",

"build:js": "microbundle --compress=false",
"build": "yarn lint && yarn build:js && yarn test",
"build": "yarn lint && yarn build:js",
"format": "prettier --write \"src/**/*.[jt]s\"",
"lint": "eslint --ignore-pattern \"src/**/*.test.[jt]s\" \"src/**/*.[jt]s\"",
"prepare": "yarn build",
"prepublishOnly": "yarn test:ci && yarn format && yarn lint",
"prepublishOnly": "yarn build:js && yarn test:ci && yarn format && yarn lint",
"release": "semantic-release --debug"

@@ -82,3 +81,3 @@ },

"eslint-plugin-prettier": "4.0.0",
"ganache-cli": "6.12.2",
"ganache-cli": "^6.12.2",
"jest": "27.4.5",

@@ -85,0 +84,0 @@ "microbundle": "0.14.2",

@@ -223,3 +223,74 @@ import { Resolver } from 'did-resolver'

})
it('resolves public keys and services on aurora when configured', async () => {
const did = 'did:ethr:aurora:0x036d148205e34a8591dcdcea34fb7fed760f5f1eca66d254830833f755ff359ef0'
const ethr = getResolver({
networks: [
{
name: 'aurora',
chainId: 1313161554,
rpcUrl: 'https://mainnet.aurora.dev',
registry: '0x63eD58B671EeD12Bc1652845ba5b2CDfBff198e0',
},
],
})
const resolver = new Resolver(ethr)
const doc = await resolver.resolve(did)
return expect(doc).toEqual({
didDocumentMetadata: {
updated: '2022-01-19T12:19:59Z',
versionId: '57702193',
},
didResolutionMetadata: { contentType: 'application/did+ld+json' },
didDocument: {
'@context': [
'https://www.w3.org/ns/did/v1',
'https://identity.foundation/EcdsaSecp256k1RecoverySignature2020/lds-ecdsa-secp256k1-recovery2020-0.0.jsonld',
],
id: did,
verificationMethod: [
{
id: `${did}#controller`,
type: 'EcdsaSecp256k1RecoveryMethod2020',
controller: did,
blockchainAccountId: '0x7a988202a04f00436f73972DF4dEfD80c3A6BD13@eip155:1313161554',
},
{
id: `${did}#controllerKey`,
type: 'EcdsaSecp256k1VerificationKey2019',
controller: did,
publicKeyHex: '036d148205e34a8591dcdcea34fb7fed760f5f1eca66d254830833f755ff359ef0',
},
{
controller: did,
id: `${did}#delegate-1`,
publicKeyHex: 'c4c323b4ba114591579d92591b26e92e59aa5529c6adbebb820da7ca407e9d34',
type: 'Ed25519VerificationKey2018',
},
{
controller: did,
id: `${did}#delegate-2`,
publicKeyHex:
'04ebafc30f377af345bb86c9269ed6432d6245b44f01dd410f8c0e73ab1801211c84b76fade77b4d6e27da82d051e3603b35c21072201e1a1c00073ab09d004ee4',
type: 'EcdsaSecp256k1VerificationKey2019',
},
],
authentication: [`${did}#controller`, `${did}#controllerKey`],
assertionMethod: [`${did}#controller`, `${did}#controllerKey`, `${did}#delegate-1`, `${did}#delegate-2`],
service: [
{
id: `${did}#service-1`,
serviceEndpoint: 'https://example.com/inbox',
type: 'DIDCommMessaging',
},
{
id: `${did}#service-2`,
serviceEndpoint: 'https://example.com/inbox2',
type: 'DIDCommMessaging',
},
],
},
})
})
})
})

@@ -15,3 +15,3 @@ import { Contract, ContractFactory } from '@ethersproject/contracts'

let registryContract: Contract,
accounts,
accounts: string[],
did: string,

@@ -112,7 +112,7 @@ identity: string,

expect.assertions(1)
const blockHeightBeforeChange = (await web3Provider.getBlock('latest')).number
await new EthrDidController(identity, registryContract).changeOwner(controller, { from: identity })
const result = await didResolver.resolve(did)
delete result.didDocumentMetadata.updated
expect(result).toEqual({
didDocumentMetadata: { versionId: '2' },
didDocumentMetadata: { versionId: `${blockHeightBeforeChange + 1}`, updated: expect.anything() },
didResolutionMetadata: { contentType: 'application/did+ld+json' },

@@ -170,2 +170,3 @@ didDocument: {

expect.assertions(1)
const blockHeightBeforeChange = (await web3Provider.getBlock('latest')).number
await new EthrDidController(identity, registryContract).addDelegate('veriKey', delegate1, 86401, {

@@ -175,5 +176,4 @@ from: controller,

const result = await didResolver.resolve(did)
delete result.didDocumentMetadata.updated
await expect(result).toEqual({
didDocumentMetadata: { versionId: '3' },
didDocumentMetadata: { versionId: `${blockHeightBeforeChange + 1}`, updated: expect.anything() },
didResolutionMetadata: { contentType: 'application/did+ld+json' },

@@ -210,2 +210,3 @@ didDocument: {

expect.assertions(1)
const blockHeightBeforeChange = (await web3Provider.getBlock('latest')).number
await new EthrDidController(identity, registryContract).addDelegate('sigAuth', delegate2, 1, {

@@ -215,6 +216,4 @@ from: controller,

const result = await didResolver.resolve(did)
//don't compare against hardcoded timestamps
delete result.didDocumentMetadata.updated
expect(result).toEqual({
didDocumentMetadata: { versionId: '4' },
didDocumentMetadata: { versionId: `${blockHeightBeforeChange + 1}`, updated: expect.anything() },
didResolutionMetadata: { contentType: 'application/did+ld+json' },

@@ -258,14 +257,9 @@ didDocument: {

//key validity was set to less than 2 seconds
await sleep(4)
await sleep(4000)
const result = await didResolver.resolve(did)
//don't compare against hardcoded timestamps
delete result.didDocumentMetadata.updated
expect(result).toEqual({
didDocumentMetadata: { versionId: '4' },
didResolutionMetadata: { contentType: 'application/did+ld+json' },
didDocumentMetadata: expect.anything(),
didResolutionMetadata: expect.anything(),
didDocument: {
'@context': [
'https://www.w3.org/ns/did/v1',
'https://identity.foundation/EcdsaSecp256k1RecoverySignature2020/lds-ecdsa-secp256k1-recovery2020-0.0.jsonld',
],
'@context': expect.anything(),
id: did,

@@ -296,17 +290,13 @@ verificationMethod: [

expect.assertions(1)
const blockHeightBeforeChange = (await web3Provider.getBlock('latest')).number
await new EthrDidController(identity, registryContract).revokeDelegate('veriKey', delegate1, {
from: controller,
})
await sleep(1)
await sleep(1000)
const result = await didResolver.resolve(did)
//don't compare against hardcoded timestamps
delete result.didDocumentMetadata.updated
expect(result).toEqual({
didDocumentMetadata: { versionId: '5' },
didResolutionMetadata: { contentType: 'application/did+ld+json' },
didDocumentMetadata: { versionId: `${blockHeightBeforeChange + 1}`, updated: expect.anything() },
didResolutionMetadata: expect.anything(),
didDocument: {
'@context': [
'https://www.w3.org/ns/did/v1',
'https://identity.foundation/EcdsaSecp256k1RecoverySignature2020/lds-ecdsa-secp256k1-recovery2020-0.0.jsonld',
],
'@context': expect.anything(),
id: did,

@@ -331,2 +321,3 @@ verificationMethod: [

expect.assertions(1)
const blockHeightBeforeChange = (await web3Provider.getBlock('latest')).number
await new EthrDidController(identity, registryContract).addDelegate('sigAuth', delegate2, 86402, {

@@ -336,12 +327,7 @@ from: controller,

const result = await didResolver.resolve(did)
//don't compare against hardcoded timestamps
delete result.didDocumentMetadata.updated
expect(result).toEqual({
didDocumentMetadata: { versionId: '6' },
didResolutionMetadata: { contentType: 'application/did+ld+json' },
didDocumentMetadata: { versionId: `${blockHeightBeforeChange + 1}`, updated: expect.anything() },
didResolutionMetadata: expect.anything(),
didDocument: {
'@context': [
'https://www.w3.org/ns/did/v1',
'https://identity.foundation/EcdsaSecp256k1RecoverySignature2020/lds-ecdsa-secp256k1-recovery2020-0.0.jsonld',
],
'@context': expect.anything(),
id: did,

@@ -382,6 +368,3 @@ verificationMethod: [

expect(didDocument).toEqual({
'@context': [
'https://www.w3.org/ns/did/v1',
'https://identity.foundation/EcdsaSecp256k1RecoverySignature2020/lds-ecdsa-secp256k1-recovery2020-0.0.jsonld',
],
'@context': expect.anything(),
id: did,

@@ -423,6 +406,3 @@ verificationMethod: [

expect(didDocument).toEqual({
'@context': [
'https://www.w3.org/ns/did/v1',
'https://identity.foundation/EcdsaSecp256k1RecoverySignature2020/lds-ecdsa-secp256k1-recovery2020-0.0.jsonld',
],
'@context': expect.anything(),
id: did,

@@ -473,6 +453,3 @@ verificationMethod: [

expect(didDocument).toEqual({
'@context': [
'https://www.w3.org/ns/did/v1',
'https://identity.foundation/EcdsaSecp256k1RecoverySignature2020/lds-ecdsa-secp256k1-recovery2020-0.0.jsonld',
],
'@context': expect.anything(),
id: did,

@@ -536,6 +513,3 @@ verificationMethod: [

expect(didDocument).toEqual({
'@context': [
'https://www.w3.org/ns/did/v1',
'https://identity.foundation/EcdsaSecp256k1RecoverySignature2020/lds-ecdsa-secp256k1-recovery2020-0.0.jsonld',
],
'@context': expect.anything(),
id: keyAgrDid,

@@ -574,6 +548,3 @@ verificationMethod: [

expect(didDocument).toEqual({
'@context': [
'https://www.w3.org/ns/did/v1',
'https://identity.foundation/EcdsaSecp256k1RecoverySignature2020/lds-ecdsa-secp256k1-recovery2020-0.0.jsonld',
],
'@context': expect.anything(),
id: did,

@@ -645,6 +616,3 @@ verificationMethod: [

expect(didDocument).toEqual({
'@context': [
'https://www.w3.org/ns/did/v1',
'https://identity.foundation/EcdsaSecp256k1RecoverySignature2020/lds-ecdsa-secp256k1-recovery2020-0.0.jsonld',
],
'@context': expect.anything(),
id: did,

@@ -701,6 +669,3 @@ verificationMethod: [

expect(didDocument).toEqual({
'@context': [
'https://www.w3.org/ns/did/v1',
'https://identity.foundation/EcdsaSecp256k1RecoverySignature2020/lds-ecdsa-secp256k1-recovery2020-0.0.jsonld',
],
'@context': expect.anything(),
id: did,

@@ -748,6 +713,3 @@ verificationMethod: [

expect(didDocument).toEqual({
'@context': [
'https://www.w3.org/ns/did/v1',
'https://identity.foundation/EcdsaSecp256k1RecoverySignature2020/lds-ecdsa-secp256k1-recovery2020-0.0.jsonld',
],
'@context': expect.anything(),
id: did,

@@ -790,6 +752,3 @@ verificationMethod: [

expect(didDocument).toEqual({
'@context': [
'https://www.w3.org/ns/did/v1',
'https://identity.foundation/EcdsaSecp256k1RecoverySignature2020/lds-ecdsa-secp256k1-recovery2020-0.0.jsonld',
],
'@context': expect.anything(),
id: did,

@@ -817,122 +776,2 @@ verificationMethod: [

describe('multiple events in one block', () => {
beforeAll(async () => {
const ethrDid = new EthrDidController(identity, registryContract)
await stopMining(web3Provider)
await Promise.all([
ethrDid.setAttribute(stringToBytes32('did/svc/TestService'), 'https://test.uport.me', 86406, {
from: controller,
}),
ethrDid.setAttribute(stringToBytes32('did/svc/TestService'), 'https://test.uport.me', 86407, {
from: controller,
}),
sleep(1).then(() => startMining(web3Provider)),
])
})
it('resolves document', async () => {
expect.assertions(1)
const result = await didResolver.resolve(did)
//don't compare against hardcoded timestamps
delete result.didDocumentMetadata.updated
expect(result).toEqual({
didDocumentMetadata: { versionId: '16' },
didResolutionMetadata: {
contentType: 'application/did+ld+json',
},
didDocument: {
'@context': [
'https://www.w3.org/ns/did/v1',
'https://identity.foundation/EcdsaSecp256k1RecoverySignature2020/lds-ecdsa-secp256k1-recovery2020-0.0.jsonld',
],
id: did,
verificationMethod: [
{
id: `${did}#controller`,
type: 'EcdsaSecp256k1RecoveryMethod2020',
controller: did,
blockchainAccountId: `${controller}@eip155:1337`,
},
{
id: `${did}#delegate-4`,
type: 'EcdsaSecp256k1RecoveryMethod2020',
controller: did,
blockchainAccountId: `${delegate2}@eip155:1337`,
},
],
authentication: [`${did}#controller`, `${did}#delegate-4`],
assertionMethod: [`${did}#controller`, `${did}#delegate-4`],
service: [
{
id: `${did}#service-4`,
type: 'TestService',
serviceEndpoint: 'https://test.uport.me',
},
],
},
})
})
})
describe('attribute revocation event in same block(-batch) as attribute creation', () => {
beforeAll(async () => {
const ethrDid = new EthrDidController(identity, registryContract)
await stopMining(web3Provider)
await Promise.all([
ethrDid.setAttribute(stringToBytes32('did/svc/TestService2'), 'https://test2.uport.me', 86408, {
from: controller,
}),
sleep(1).then(() =>
ethrDid.revokeAttribute(stringToBytes32('did/svc/TestService2'), 'https://test2.uport.me', {
from: controller,
})
),
sleep(1).then(() => startMining(web3Provider)),
])
})
it('resolves document', async () => {
expect.assertions(1)
const result = await didResolver.resolve(did)
//don't compare against hardcoded timestamps
delete result.didDocumentMetadata.updated
expect(result).toEqual({
didDocumentMetadata: { versionId: '18' },
didResolutionMetadata: {
contentType: 'application/did+ld+json',
},
didDocument: {
'@context': [
'https://www.w3.org/ns/did/v1',
'https://identity.foundation/EcdsaSecp256k1RecoverySignature2020/lds-ecdsa-secp256k1-recovery2020-0.0.jsonld',
],
id: did,
verificationMethod: [
{
id: `${did}#controller`,
type: 'EcdsaSecp256k1RecoveryMethod2020',
controller: did,
blockchainAccountId: `${controller}@eip155:1337`,
},
{
id: `${did}#delegate-4`,
type: 'EcdsaSecp256k1RecoveryMethod2020',
controller: did,
blockchainAccountId: `${delegate2}@eip155:1337`,
},
],
authentication: [`${did}#controller`, `${did}#delegate-4`],
assertionMethod: [`${did}#controller`, `${did}#delegate-4`],
service: [
{
id: `${did}#service-4`,
type: 'TestService',
serviceEndpoint: 'https://test.uport.me',
},
],
},
})
})
})
describe('regression', () => {

@@ -961,28 +800,25 @@ it('resolves same document with case sensitive eth address (https://github.com/decentralized-identity/ethr-did-resolver/issues/105)', async () => {

expect.assertions(1)
const identity = accounts[4]
const did = `did:ethr:dev:${identity}`
const address = accounts[4]
const identifier = `did:ethr:dev:${address}`
const authPubKey = `31303866356238393330623164633235386162353765386630646362363932353963363162316166`
await new EthrDidController(identity, registryContract).setAttribute(
await new EthrDidController(identifier, registryContract).setAttribute(
'did/pub/Ed25519/sigAuth/hex',
`0x${authPubKey}`,
86410,
{ from: identity }
{ from: address }
)
const { didDocument } = await didResolver.resolve(did)
const { didDocument } = await didResolver.resolve(identifier)
expect(didDocument).toEqual({
'@context': [
'https://www.w3.org/ns/did/v1',
'https://identity.foundation/EcdsaSecp256k1RecoverySignature2020/lds-ecdsa-secp256k1-recovery2020-0.0.jsonld',
],
id: did,
'@context': expect.anything(),
id: identifier,
verificationMethod: [
{
id: `${did}#controller`,
controller: did,
id: `${identifier}#controller`,
controller: identifier,
type: 'EcdsaSecp256k1RecoveryMethod2020',
blockchainAccountId: `${delegate2}@eip155:1337`,
blockchainAccountId: `${address}@eip155:1337`,
},
{
id: `${did}#delegate-1`,
controller: did,
id: `${identifier}#delegate-1`,
controller: identifier,
type: `Ed25519VerificationKey2018`,

@@ -992,4 +828,4 @@ publicKeyHex: authPubKey,

],
authentication: [`${did}#controller`, `${did}#delegate-1`],
assertionMethod: [`${did}#controller`, `${did}#delegate-1`],
authentication: [`${identifier}#controller`, `${identifier}#delegate-1`],
assertionMethod: [`${identifier}#controller`, `${identifier}#delegate-1`],
})

@@ -1001,42 +837,36 @@ })

expect.assertions(1)
const identity = accounts[3]
const did = `did:ethr:dev:${identity}`
const address = accounts[3]
const identifier = `did:ethr:dev:${address}`
const publicKeyHex = `b97c30de767f084ce3080168ee293053ba33b235d7116a3263d29f1450936b71`
const expectedPublicKeyBase58 = 'DV4G2kpBKjE6zxKor7Cj21iL9x9qyXb6emqjszBXcuhz'
await new EthrDidController(identity, registryContract).setAttribute(
const blockHeightBeforeChange = (await web3Provider.getBlock('latest')).number
await new EthrDidController(identifier, registryContract).setAttribute(
'did/pub/Ed25519/veriKey/base58',
`0x${publicKeyHex}`,
86411,
{ from: identity }
{ from: address }
)
const result = await didResolver.resolve(did)
//don't compare against hardcoded timestamps
delete result.didDocumentMetadata.updated
const result = await didResolver.resolve(identifier)
expect(result).toEqual({
didDocumentMetadata: { versionId: '21' },
didResolutionMetadata: {
contentType: 'application/did+ld+json',
},
didDocumentMetadata: { versionId: `${blockHeightBeforeChange + 1}`, updated: expect.anything() },
didResolutionMetadata: expect.anything(),
didDocument: {
'@context': [
'https://www.w3.org/ns/did/v1',
'https://identity.foundation/EcdsaSecp256k1RecoverySignature2020/lds-ecdsa-secp256k1-recovery2020-0.0.jsonld',
],
id: did,
'@context': expect.anything(),
id: identifier,
verificationMethod: [
{
id: `${did}#controller`,
id: `${identifier}#controller`,
type: 'EcdsaSecp256k1RecoveryMethod2020',
controller: did,
blockchainAccountId: `${identity}@eip155:1337`,
controller: identifier,
blockchainAccountId: `${address}@eip155:1337`,
},
{
id: `${did}#delegate-1`,
id: `${identifier}#delegate-1`,
type: 'Ed25519VerificationKey2018',
controller: did,
controller: identifier,
publicKeyBase58: expectedPublicKeyBase58,
},
],
authentication: [`${did}#controller`],
assertionMethod: [`${did}#controller`, `${did}#delegate-1`],
authentication: [`${identifier}#controller`],
assertionMethod: [`${identifier}#controller`, `${identifier}#delegate-1`],
},

@@ -1049,20 +879,18 @@ })

it('resolves deactivated document', async () => {
expect.assertions(2)
const identity = accounts[6]
const did = `did:ethr:dev:${identity}`
await new EthrDidController(identity, registryContract).changeOwner(nullAddress, { from: identity })
const result = await didResolver.resolve(did)
expect(result.didDocumentMetadata.updated).toBeDefined()
delete result.didDocumentMetadata.updated
expect.assertions(1)
const address = accounts[6]
const identifier = `did:ethr:dev:${address}`
const blockHeightBeforeChange = (await web3Provider.getBlock('latest')).number
await new EthrDidController(identifier, registryContract).changeOwner(nullAddress, { from: address })
const result = await didResolver.resolve(identifier)
expect(result).toEqual({
didDocumentMetadata: {
deactivated: true,
versionId: '22',
updated: expect.anything(),
versionId: `${blockHeightBeforeChange + 1}`,
},
didResolutionMetadata: {
contentType: 'application/did+ld+json',
},
didResolutionMetadata: expect.anything(),
didDocument: {
'@context': 'https://www.w3.org/ns/did/v1',
id: did,
id: identifier,
verificationMethod: [],

@@ -1107,14 +935,14 @@ authentication: [],

it('can resolve modified did with versionId=latest', async () => {
expect.assertions(2)
const identity = accounts[3]
const modifiedDid = `did:ethr:dev:${identity}`
const result = await didResolver.resolve(`${modifiedDid}?versionId=latest`)
expect(result.didDocumentMetadata.updated).toBeDefined()
delete result.didDocumentMetadata.updated
it('can resolve did with versionId before deactivation', async () => {
expect.assertions(1)
const deactivatedDid = `did:ethr:dev:${accounts[6]}`
const { didDocumentMetadata } = await didResolver.resolve(deactivatedDid)
const deactivationBlock = parseInt(didDocumentMetadata.versionId ?? '')
const result = await didResolver.resolve(`${deactivatedDid}?versionId=${deactivationBlock - 1}`)
expect(result).toEqual({
didDocumentMetadata: { versionId: '21' },
didResolutionMetadata: {
contentType: 'application/did+ld+json',
didDocumentMetadata: {
nextVersionId: `${deactivationBlock}`,
nextUpdate: didDocumentMetadata.updated,
},
didResolutionMetadata: { contentType: 'application/did+ld+json' },
didDocument: {

@@ -1125,19 +953,13 @@ '@context': [

],
id: modifiedDid,
id: deactivatedDid,
verificationMethod: [
{
id: `${modifiedDid}#controller`,
id: `${deactivatedDid}#controller`,
type: 'EcdsaSecp256k1RecoveryMethod2020',
controller: modifiedDid,
blockchainAccountId: `${identity}@eip155:1337`,
controller: deactivatedDid,
blockchainAccountId: `${accounts[6]}@eip155:1337`,
},
{
id: `${modifiedDid}#delegate-1`,
type: 'Ed25519VerificationKey2018',
controller: modifiedDid,
publicKeyBase58: 'DV4G2kpBKjE6zxKor7Cj21iL9x9qyXb6emqjszBXcuhz',
},
],
authentication: [`${modifiedDid}#controller`],
assertionMethod: [`${modifiedDid}#controller`, `${modifiedDid}#delegate-1`],
authentication: [`${deactivatedDid}#controller`],
assertionMethod: [`${deactivatedDid}#controller`],
},

@@ -1147,34 +969,26 @@ })

it('can resolve did with versionId before an attribute change', async () => {
expect.assertions(3)
const result = await didResolver.resolve(`${did}?versionId=6`)
expect(result.didDocumentMetadata.updated).toBeDefined()
delete result.didDocumentMetadata.updated
expect(result.didDocumentMetadata.nextUpdate).toBeDefined()
delete result.didDocumentMetadata.nextUpdate
it('can resolve modified did with versionId=latest', async () => {
expect.assertions(1)
const address = accounts[7]
const identifier = `did:ethr:dev:${address}`
const blockHeightBeforeChange = (await web3Provider.getBlock('latest')).number
// change owner to self
await new EthrDidController(identifier, registryContract).changeOwner(address, { from: address })
const result = await didResolver.resolve(`${identifier}?versionId=latest`)
expect(result).toEqual({
didDocumentMetadata: { versionId: '6', nextVersionId: '7' },
didResolutionMetadata: { contentType: 'application/did+ld+json' },
didDocumentMetadata: { versionId: `${blockHeightBeforeChange + 1}`, updated: expect.anything() },
didResolutionMetadata: expect.anything(),
didDocument: {
'@context': [
'https://www.w3.org/ns/did/v1',
'https://identity.foundation/EcdsaSecp256k1RecoverySignature2020/lds-ecdsa-secp256k1-recovery2020-0.0.jsonld',
],
id: did,
'@context': expect.anything(),
id: identifier,
verificationMethod: [
{
id: `${did}#controller`,
id: `${identifier}#controller`,
type: 'EcdsaSecp256k1RecoveryMethod2020',
controller: did,
blockchainAccountId: `${controller}@eip155:1337`,
controller: identifier,
blockchainAccountId: `${address}@eip155:1337`,
},
{
id: `${did}#delegate-4`,
type: 'EcdsaSecp256k1RecoveryMethod2020',
controller: did,
blockchainAccountId: `${delegate2}@eip155:1337`,
},
],
authentication: [`${did}#controller`, `${did}#delegate-4`],
assertionMethod: [`${did}#controller`, `${did}#delegate-4`],
authentication: [`${identifier}#controller`],
assertionMethod: [`${identifier}#controller`],
},

@@ -1184,28 +998,41 @@ })

it('can resolve did with versionId before a delegate change', async () => {
expect.assertions(3)
const result = await didResolver.resolve(`${did}?versionId=2`)
expect(result.didDocumentMetadata.updated).toBeDefined()
delete result.didDocumentMetadata.updated
expect(result.didDocumentMetadata.nextUpdate).toBeDefined()
delete result.didDocumentMetadata.nextUpdate
it('can resolve did with versionId before an attribute change', async () => {
expect.assertions(1)
const address = accounts[8]
const identifier = `did:ethr:dev:${address}`
const blockHeightBeforeChange = (await web3Provider.getBlock('latest')).number
const ethrDid = new EthrDidController(identifier, registryContract)
await ethrDid.setAttribute('did/pub/Ed25519/veriKey/hex', `0x11111111`, 86411, { from: address })
await ethrDid.setAttribute('did/pub/Ed25519/veriKey/hex', `0x22222222`, 86412, { from: address })
const result = await didResolver.resolve(`${identifier}?versionId=${blockHeightBeforeChange + 1}`)
expect(result).toEqual({
didDocumentMetadata: { versionId: '2', nextVersionId: '3' },
didDocumentMetadata: {
versionId: `${blockHeightBeforeChange + 1}`,
nextVersionId: `${blockHeightBeforeChange + 2}`,
updated: expect.anything(),
nextUpdate: expect.anything(),
},
didResolutionMetadata: { contentType: 'application/did+ld+json' },
didDocument: {
'@context': [
'https://www.w3.org/ns/did/v1',
'https://identity.foundation/EcdsaSecp256k1RecoverySignature2020/lds-ecdsa-secp256k1-recovery2020-0.0.jsonld',
],
id: did,
'@context': expect.anything(),
id: identifier,
verificationMethod: [
{
id: `${did}#controller`,
id: `${identifier}#controller`,
type: 'EcdsaSecp256k1RecoveryMethod2020',
controller: did,
blockchainAccountId: `${controller}@eip155:1337`,
controller: identifier,
blockchainAccountId: `${address}@eip155:1337`,
},
{
id: `${identifier}#delegate-1`,
type: 'Ed25519VerificationKey2018',
controller: identifier,
publicKeyHex: '11111111',
},
],
authentication: [`${did}#controller`],
assertionMethod: [`${did}#controller`],
authentication: [`${identifier}#controller`],
assertionMethod: [`${identifier}#controller`, `${identifier}#delegate-1`],
},

@@ -1215,28 +1042,42 @@ })

it('can resolve did with versionId before an owner change', async () => {
expect.assertions(2)
const result = await didResolver.resolve(`${did}?versionId=1`)
expect(result.didDocumentMetadata.nextUpdate).toBeDefined()
delete result.didDocumentMetadata.nextUpdate
it('can resolve did with versionId before a delegate change', async () => {
expect.assertions(1)
const delegateAddress1 = '0xde1E9a7e00000000000000000000000000000001'
const delegateAddress2 = '0xde1e9a7e00000000000000000000000000000002'
const address = accounts[9]
const identifier = `did:ethr:dev:${address}`
const ethrDid = new EthrDidController(identifier, registryContract)
const blockHeightBeforeChange = (await web3Provider.getBlock('latest')).number
await ethrDid.addDelegate('veriKey', delegateAddress1, 86401, { from: address })
await ethrDid.addDelegate('veriKey', delegateAddress2, 86402, { from: address })
const result = await didResolver.resolve(`${identifier}?versionId=${blockHeightBeforeChange + 1}`)
expect(result).toEqual({
didDocumentMetadata: {
nextVersionId: '2',
versionId: `${blockHeightBeforeChange + 1}`,
nextVersionId: `${blockHeightBeforeChange + 2}`,
updated: expect.anything(),
nextUpdate: expect.anything(),
},
didResolutionMetadata: { contentType: 'application/did+ld+json' },
didResolutionMetadata: expect.anything(),
didDocument: {
'@context': [
'https://www.w3.org/ns/did/v1',
'https://identity.foundation/EcdsaSecp256k1RecoverySignature2020/lds-ecdsa-secp256k1-recovery2020-0.0.jsonld',
],
id: did,
'@context': expect.anything(),
id: identifier,
verificationMethod: [
{
id: `${did}#controller`,
id: `${identifier}#controller`,
type: 'EcdsaSecp256k1RecoveryMethod2020',
controller: did,
blockchainAccountId: `${identity}@eip155:1337`,
controller: identifier,
blockchainAccountId: `${address}@eip155:1337`,
},
{
id: `${identifier}#delegate-1`,
type: 'EcdsaSecp256k1RecoveryMethod2020',
controller: identifier,
blockchainAccountId: `${delegateAddress1}@eip155:1337`,
},
],
authentication: [`${did}#controller`],
assertionMethod: [`${did}#controller`],
authentication: [`${identifier}#controller`],
assertionMethod: [`${identifier}#controller`, `${identifier}#delegate-1`],
},

@@ -1246,29 +1087,34 @@ })

it('can resolve did with versionId before deactivation', async () => {
expect.assertions(2)
const deactivatedDid = `did:ethr:dev:${accounts[6]}`
const result = await didResolver.resolve(`${deactivatedDid}?versionId=21`)
expect(result.didDocumentMetadata.nextUpdate).toBeDefined()
delete result.didDocumentMetadata.nextUpdate
it('can resolve did with versionId before an owner change', async () => {
expect.assertions(1)
const newOwner = '0xde1e9a7e00000000000000000000000000000003'
const address = accounts[10]
const identifier = `did:ethr:dev:${address}`
const ethrDid = new EthrDidController(identifier, registryContract)
const blockHeightBeforeChange = (await web3Provider.getBlock('latest')).number
await ethrDid.changeOwner(address, { from: address })
await ethrDid.changeOwner(newOwner, { from: address })
const result = await didResolver.resolve(`${identifier}?versionId=${blockHeightBeforeChange + 1}`)
expect(result).toEqual({
didDocumentMetadata: {
nextVersionId: '22',
versionId: `${blockHeightBeforeChange + 1}`,
nextVersionId: `${blockHeightBeforeChange + 2}`,
updated: expect.anything(),
nextUpdate: expect.anything(),
},
didResolutionMetadata: { contentType: 'application/did+ld+json' },
didResolutionMetadata: expect.anything(),
didDocument: {
'@context': [
'https://www.w3.org/ns/did/v1',
'https://identity.foundation/EcdsaSecp256k1RecoverySignature2020/lds-ecdsa-secp256k1-recovery2020-0.0.jsonld',
],
id: deactivatedDid,
'@context': expect.anything(),
id: identifier,
verificationMethod: [
{
id: `${deactivatedDid}#controller`,
id: `${identifier}#controller`,
type: 'EcdsaSecp256k1RecoveryMethod2020',
controller: deactivatedDid,
blockchainAccountId: `${accounts[6]}@eip155:1337`,
controller: identifier,
blockchainAccountId: `${address}@eip155:1337`,
},
],
authentication: [`${deactivatedDid}#controller`],
assertionMethod: [`${deactivatedDid}#controller`],
authentication: [`${identifier}#controller`],
assertionMethod: [`${identifier}#controller`],
},

@@ -1279,38 +1125,49 @@ })

it('can resolve did with versionId before an attribute expiration', async () => {
expect.assertions(1)
const result = await didResolver.resolve(`${did}?versionId=4`)
//don't compare against hardcoded timestamps
delete result.didDocumentMetadata.updated
delete result.didDocumentMetadata.nextUpdate
expect.assertions(3)
const delegate = '0xde1E9a7e00000000000000000000000000000001'
const address = accounts[11]
const identifier = `did:ethr:dev:${address}`
await new EthrDidController(identifier, registryContract).addDelegate('sigAuth', delegate, 1, {
from: address,
})
let result = await didResolver.resolve(identifier)
// confirm delegate exists
const versionBeforeExpiry = result.didDocumentMetadata.versionId
expect(result?.didDocument?.verificationMethod?.[1]).toEqual({
id: `${identifier}#delegate-1`,
type: 'EcdsaSecp256k1RecoveryMethod2020',
controller: identifier,
blockchainAccountId: `${delegate}@eip155:1337`,
})
// await expiry
await sleep(4000)
// confirm delegate was removed after expiry
result = await didResolver.resolve(identifier)
expect(result?.didDocument?.verificationMethod?.length).toEqual(1)
// resolve DID before expiry
result = await didResolver.resolve(`${identifier}?versionId=${versionBeforeExpiry}`)
expect(result).toEqual({
didDocumentMetadata: { versionId: '4', nextVersionId: '5' },
didResolutionMetadata: { contentType: 'application/did+ld+json' },
didDocumentMetadata: { versionId: `${versionBeforeExpiry}`, updated: expect.anything() },
didResolutionMetadata: expect.anything(),
didDocument: {
'@context': [
'https://www.w3.org/ns/did/v1',
'https://identity.foundation/EcdsaSecp256k1RecoverySignature2020/lds-ecdsa-secp256k1-recovery2020-0.0.jsonld',
],
id: did,
'@context': expect.anything(),
id: identifier,
verificationMethod: [
{
id: `${did}#controller`,
id: `${identifier}#controller`,
type: 'EcdsaSecp256k1RecoveryMethod2020',
controller: did,
blockchainAccountId: `${controller}@eip155:1337`,
controller: identifier,
blockchainAccountId: `${address}@eip155:1337`,
},
{
id: `${did}#delegate-1`,
id: `${identifier}#delegate-1`,
type: 'EcdsaSecp256k1RecoveryMethod2020',
controller: did,
blockchainAccountId: `${delegate1}@eip155:1337`,
controller: identifier,
blockchainAccountId: `${delegate}@eip155:1337`,
},
{
id: `${did}#delegate-2`,
type: 'EcdsaSecp256k1RecoveryMethod2020',
controller: did,
blockchainAccountId: `${delegate2}@eip155:1337`,
},
],
authentication: [`${did}#controller`, `${did}#delegate-2`],
assertionMethod: [`${did}#controller`, `${did}#delegate-1`, `${did}#delegate-2`],
authentication: [`${identifier}#controller`, `${identifier}#delegate-1`],
assertionMethod: [`${identifier}#controller`, `${identifier}#delegate-1`],
},

@@ -1321,2 +1178,202 @@ })

})
describe('overlapping events', () => {
it('adding the same service in the same block does not result in duplication', async () => {
expect.assertions(1)
const address = accounts[12]
const identifier = `did:ethr:dev:${address}`
const ethrDid = new EthrDidController(identifier, registryContract)
const blockHeightBeforeChange = (await web3Provider.getBlock('latest')).number
await stopMining(web3Provider)
const tx1 = ethrDid.setAttribute(stringToBytes32('did/svc/TestService'), 'https://test.uport.me', 86406, {
from: address,
})
const tx2 = ethrDid.setAttribute(stringToBytes32('did/svc/TestService'), 'https://test.uport.me', 86407, {
from: address,
})
await sleep(1000)
await startMining(web3Provider)
await tx1
await tx2
const result = await didResolver.resolve(identifier)
expect(result).toEqual({
didDocumentMetadata: { versionId: `${blockHeightBeforeChange + 1}`, updated: expect.anything() },
didResolutionMetadata: expect.anything(),
didDocument: {
'@context': expect.anything(),
id: identifier,
verificationMethod: expect.anything(),
authentication: expect.anything(),
assertionMethod: expect.anything(),
service: [
{
id: `${identifier}#service-2`,
type: 'TestService',
serviceEndpoint: 'https://test.uport.me',
},
],
},
})
})
it('adding 2 services in 2 consecutive blocks should result in only 2 services appearing in the DID doc (no duplication)', async () => {
expect.assertions(2)
const address = accounts[13]
const identifier = `did:ethr:dev:${address}`
const ethrDid = new EthrDidController(identifier, registryContract)
const blockHeightBeforeChange = (await web3Provider.getBlock('latest')).number
// await stopMining(web3Provider)
await ethrDid.setAttribute(stringToBytes32('did/svc/TestService1'), 'https://test1.uport.me', 86406, {
from: address,
})
// await startMining(web3Provider)
let result = await didResolver.resolve(identifier)
expect(result.didDocumentMetadata.versionId).toEqual(`${blockHeightBeforeChange + 1}`)
// await stopMining(web3Provider)
await ethrDid.setAttribute(stringToBytes32('did/svc/TestService2'), 'https://test2.uport.me', 86407, {
from: address,
})
// await startMining(web3Provider)
result = await didResolver.resolve(identifier)
expect(result).toEqual({
didDocumentMetadata: { versionId: `${blockHeightBeforeChange + 2}`, updated: expect.anything() },
didResolutionMetadata: expect.anything(),
didDocument: {
'@context': expect.anything(),
id: identifier,
verificationMethod: [expect.anything()],
authentication: [expect.anything()],
assertionMethod: [expect.anything()],
service: [
{
id: `${identifier}#service-1`,
type: 'TestService1',
serviceEndpoint: 'https://test1.uport.me',
},
{
id: `${identifier}#service-2`,
type: 'TestService2',
serviceEndpoint: 'https://test2.uport.me',
},
],
},
})
})
it('adding and removing a service in the same block should result in no change to the doc (correct order, same block)', async () => {
expect.assertions(2)
const address = accounts[14]
const identifier = `did:ethr:dev:${address}`
const ethrDid = new EthrDidController(identifier, registryContract)
const blockHeightBeforeChange = (await web3Provider.getBlock('latest')).number
await stopMining(web3Provider)
const tx1 = ethrDid.setAttribute(stringToBytes32('did/svc/TestService1'), 'https://test1.uport.me', 86406, {
from: address,
})
let result = await didResolver.resolve(identifier)
expect(result.didDocumentMetadata.versionId).not.toBeDefined()
const tx2 = ethrDid.revokeAttribute(stringToBytes32('did/svc/TestService1'), 'https://test1.uport.me', {
from: address,
})
await sleep(1000).then(() => startMining(web3Provider))
await tx1
await tx2
result = await didResolver.resolve(identifier)
expect(result).toEqual({
didDocumentMetadata: { versionId: `${blockHeightBeforeChange + 1}`, updated: expect.anything() },
didResolutionMetadata: expect.anything(),
didDocument: {
'@context': expect.anything(),
id: identifier,
verificationMethod: [expect.anything()],
authentication: [expect.anything()],
assertionMethod: [expect.anything()],
service: undefined,
},
})
})
it('adding and removing a service in 2 consecutive blocks should result in no change to the doc (correct order 2 blocks).', async () => {
expect.assertions(2)
const address = accounts[15]
const identifier = `did:ethr:dev:${address}`
const ethrDid = new EthrDidController(identifier, registryContract)
const blockHeightBeforeChange = (await web3Provider.getBlock('latest')).number
await ethrDid.setAttribute(stringToBytes32('did/svc/TestService1'), 'https://test1.uport.me', 86406, {
from: address,
})
let result = await didResolver.resolve(identifier)
expect(result.didDocumentMetadata.versionId).toEqual(`${blockHeightBeforeChange + 1}`)
await ethrDid.revokeAttribute(stringToBytes32('did/svc/TestService1'), 'https://test1.uport.me', {
from: address,
})
result = await didResolver.resolve(identifier)
expect(result).toEqual({
didDocumentMetadata: { versionId: `${blockHeightBeforeChange + 2}`, updated: expect.anything() },
didResolutionMetadata: expect.anything(),
didDocument: {
'@context': expect.anything(),
id: identifier,
verificationMethod: [expect.anything()],
authentication: [expect.anything()],
assertionMethod: [expect.anything()],
service: undefined,
},
})
})
it('removing a service and then adding it back in the next block should keep the service visible in the resolved doc (correct order 2 blocks, corner case)', async () => {
expect.assertions(2)
const address = accounts[16]
const identifier = `did:ethr:dev:${address}`
const ethrDid = new EthrDidController(identifier, registryContract)
const blockHeightBeforeChange = (await web3Provider.getBlock('latest')).number
await ethrDid.revokeAttribute(stringToBytes32('did/svc/TestService1'), 'https://test1.uport.me', {
from: address,
})
let result = await didResolver.resolve(identifier)
expect(result.didDocumentMetadata.versionId).toEqual(`${blockHeightBeforeChange + 1}`)
await ethrDid.setAttribute(stringToBytes32('did/svc/TestService1'), 'https://test1.uport.me', 86406, {
from: address,
})
result = await didResolver.resolve(identifier)
expect(result).toEqual({
didDocumentMetadata: { versionId: `${blockHeightBeforeChange + 2}`, updated: expect.anything() },
didResolutionMetadata: expect.anything(),
didDocument: {
'@context': expect.anything(),
id: identifier,
verificationMethod: [expect.anything()],
authentication: [expect.anything()],
assertionMethod: [expect.anything()],
service: [
{
id: `${identifier}#service-2`,
type: 'TestService1',
serviceEndpoint: 'https://test1.uport.me',
},
],
},
})
})
})
})

@@ -1,2 +0,2 @@

import { JsonRpcProvider, Web3Provider } from '@ethersproject/providers'
import { ExternalProvider, JsonRpcProvider, Web3Provider } from '@ethersproject/providers'
import ganache from 'ganache-cli'

@@ -48,9 +48,49 @@

},
{
secretKey: '0x0000000000000000000000000000000000000000000000000000000000000007',
balance: `0x1000000000000000000000`,
},
{
secretKey: '0x0000000000000000000000000000000000000000000000000000000000000008',
balance: `0x1000000000000000000000`,
},
{
secretKey: '0x0000000000000000000000000000000000000000000000000000000000000009',
balance: `0x1000000000000000000000`,
},
{
secretKey: '0x000000000000000000000000000000000000000000000000000000000000000a',
balance: `0x1000000000000000000000`,
},
{
secretKey: '0x000000000000000000000000000000000000000000000000000000000000000b',
balance: `0x1000000000000000000000`,
},
{
secretKey: '0x000000000000000000000000000000000000000000000000000000000000000c',
balance: `0x1000000000000000000000`,
},
{
secretKey: '0x000000000000000000000000000000000000000000000000000000000000000d',
balance: `0x1000000000000000000000`,
},
{
secretKey: '0x000000000000000000000000000000000000000000000000000000000000000e',
balance: `0x1000000000000000000000`,
},
{
secretKey: '0x000000000000000000000000000000000000000000000000000000000000000f',
balance: `0x1000000000000000000000`,
},
{
secretKey: '0x0000000000000000000000000000000000000000000000000000000000000010',
balance: `0x1000000000000000000000`,
},
],
})
}) as unknown as ExternalProvider
)
}
export async function sleep(seconds: number): Promise<void> {
return new Promise((resolve) => setTimeout(resolve, seconds * 1000))
export async function sleep(milliseconds: number): Promise<void> {
return new Promise((resolve) => setTimeout(resolve, milliseconds))
}

@@ -57,0 +97,0 @@ export async function stopMining(provider: JsonRpcProvider): Promise<unknown> {

@@ -92,2 +92,4 @@ import { Base58 } from '@ethersproject/basex'

// console.log(`gigel ${previousChange}`)
const fromBlock =
previousChange.toHexString() !== '0x00' ? previousChange.sub(1).toHexString() : previousChange.toHexString()
const logs = await provider.getLogs({

@@ -97,3 +99,3 @@ address: contract.address, // networks[networkId].registryAddress,

topics: [null as any, `0x000000000000000000000000${address.slice(2)}`],
fromBlock: previousChange.toHexString(),
fromBlock,
toBlock: previousChange.toHexString(),

@@ -100,0 +102,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

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