Skip to content

Commit

Permalink
chorr(deps): update ethers (#117)
Browse files Browse the repository at this point in the history
BREAKING CHANGE: now using ethers v6 which may cause dependency conflicts when upgrading
  • Loading branch information
fermentfan authored Oct 3, 2023
1 parent 0177c95 commit 74031f6
Show file tree
Hide file tree
Showing 7 changed files with 2,609 additions and 4,197 deletions.
8 changes: 6 additions & 2 deletions jest.config.mjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {defaults} from 'jest-config'
import { defaults } from 'jest-config'

const config = {
moduleFileExtensions: [...defaults.moduleFileExtensions, 'mts'],
Expand All @@ -19,7 +19,11 @@ const config = {
extensionsToTreatAsEsm: ['.ts'],
testMatch: ['**/__tests__/**/*.test.ts'],
testEnvironment: 'node',
coverageProvider: 'v8'
coverageProvider: 'v8',
coveragePathIgnorePatterns: [
'<rootDir>/node_modules/',
'<rootDir>/src/__tests__/util'
],
}

export default config
13 changes: 2 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
"@babel/core": "7.22.10",
"@babel/preset-env": "7.22.10",
"@babel/preset-typescript": "7.22.5",
"@ethersproject/contracts": "5.7.0",
"@semantic-release/changelog": "6.0.3",
"@semantic-release/git": "10.0.1",
"@types/jest": "29.5.3",
Expand All @@ -62,17 +61,9 @@
"typescript": "5.1.6"
},
"dependencies": {
"@ethersproject/abstract-signer": "^5.7.0",
"@ethersproject/base64": "^5.7.0",
"@ethersproject/basex": "^5.7.0",
"@ethersproject/bytes": "^5.7.0",
"@ethersproject/providers": "^5.7.1",
"@ethersproject/signing-key": "^5.7.0",
"@ethersproject/strings": "^5.7.0",
"@ethersproject/transactions": "^5.7.0",
"@ethersproject/wallet": "^5.7.0",
"did-jwt": "^7.2.0",
"did-resolver": "^4.1.0",
"ethr-did-resolver": "^8.0.0"
"ethers": "^6.7.1",
"ethr-did-resolver": "9.0.0"
}
}
58 changes: 26 additions & 32 deletions src/__tests__/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
import { Resolvable, Resolver } from 'did-resolver'
import { Contract, ContractFactory } from '@ethersproject/contracts'
import { JsonRpcProvider } from '@ethersproject/providers'
import { getResolver, EthereumDIDRegistry } from 'ethr-did-resolver'
import { Contract, ContractFactory, getBytes, SigningKey } from 'ethers'
import { EthereumDIDRegistry, getResolver } from 'ethr-did-resolver'
import { DelegateTypes, EthrDID, KeyPair } from '../index'
import { createProvider, sleep } from './testUtils'
import { createProvider, sleep } from './util/testUtils'
import { verifyJWT } from 'did-jwt'
import { arrayify } from '@ethersproject/bytes'
import { SigningKey } from '@ethersproject/signing-key'

import { jest } from '@jest/globals'

Expand All @@ -24,20 +21,19 @@ describe('EthrDID', () => {
delegate2: string,
resolver: Resolvable

const provider: JsonRpcProvider = createProvider()
const provider = createProvider()

beforeAll(async () => {
const factory = ContractFactory.fromSolidity(EthereumDIDRegistry).connect(provider.getSigner(0))
const factory = ContractFactory.fromSolidity(EthereumDIDRegistry).connect(await provider.getSigner(0))

let registryContract: Contract
registryContract = await factory.deploy()
registryContract = await registryContract.deployed()
registryContract = await registryContract.waitForDeployment()

await registryContract.deployTransaction.wait()
registry = await registryContract.getAddress()

registry = registryContract.address

accounts = await provider.listAccounts()
const accountSigners = await provider.listAccounts()
accounts = accountSigners.map((signer) => signer.address)

identity = accounts[1]
owner = accounts[2]
Expand Down Expand Up @@ -134,7 +130,7 @@ describe('EthrDID', () => {
beforeAll(async () => {
const txHash = await ethrDid.addDelegate(delegate2, {
delegateType: DelegateTypes.sigAuth,
expiresIn: 2,
expiresIn: 5,
})
await provider.waitForTransaction(txHash)
})
Expand Down Expand Up @@ -775,28 +771,25 @@ describe('EthrDID (Meta Transactions)', () => {
accounts: string[],
did: string,
identity: string,
owner: string,
delegate1: string,
delegate2: string,
walletIdentity: string,
resolver: Resolvable

const provider: JsonRpcProvider = createProvider()
const provider = createProvider()

beforeAll(async () => {
const factory = ContractFactory.fromSolidity(EthereumDIDRegistry).connect(provider.getSigner(0))
const factory = ContractFactory.fromSolidity(EthereumDIDRegistry).connect(await provider.getSigner(0))

registryContract = await factory.deploy()
registryContract = await registryContract.deployed()

await registryContract.deployTransaction.wait()
registryContract = await registryContract.waitForDeployment()

registry = registryContract.address
registry = await registryContract.getAddress()

accounts = await provider.listAccounts()
const accountSigners = await provider.listAccounts()
accounts = accountSigners.map((signer) => signer.address)

identity = accounts[1]
owner = accounts[2]
delegate1 = accounts[3]
delegate2 = accounts[4]
walletIdentity = accounts[5]
Expand All @@ -813,19 +806,19 @@ describe('EthrDID (Meta Transactions)', () => {
provider,
registry,
identifier: identity,
txSigner: provider.getSigner(walletIdentity),
txSigner: await provider.getSigner(walletIdentity),
chainNameOrId: 'dev',
})
})

const currentOwnerPrivateKey = arrayify('0x0000000000000000000000000000000000000000000000000000000000000001')
const currentOwnerPrivateKey = getBytes('0x0000000000000000000000000000000000000000000000000000000000000001')

it('add delegates via meta transaction', async () => {
// Add first delegate
const delegateType = DelegateTypes.sigAuth
const exp = 86400
const hash1 = await ethrDid.createAddDelegateHash(delegateType, delegate1, exp)
const signature1 = new SigningKey(currentOwnerPrivateKey).signDigest(hash1)
const signature1 = new SigningKey(currentOwnerPrivateKey).sign(hash1)

await walletSigner.addDelegateSigned(
delegate1,
Expand Down Expand Up @@ -857,7 +850,7 @@ describe('EthrDID (Meta Transactions)', () => {

// Add second delegate
const hash2 = await ethrDid.createAddDelegateHash(delegateType, delegate2, exp)
const signature2 = new SigningKey(currentOwnerPrivateKey).signDigest(hash2)
const signature2 = new SigningKey(currentOwnerPrivateKey).sign(hash2)

await walletSigner.addDelegateSigned(
delegate2,
Expand Down Expand Up @@ -895,7 +888,7 @@ describe('EthrDID (Meta Transactions)', () => {
it('remove delegate1 via meta transaction', async () => {
const delegateType = DelegateTypes.sigAuth
const hash = await ethrDid.createRevokeDelegateHash(delegateType, delegate1)
const signature = new SigningKey(currentOwnerPrivateKey).signDigest(hash)
const signature = new SigningKey(currentOwnerPrivateKey).sign(hash)

await walletSigner.revokeDelegateSigned(delegate1, DelegateTypes.sigAuth, {
sigV: signature.v,
Expand Down Expand Up @@ -933,7 +926,7 @@ describe('EthrDID (Meta Transactions)', () => {
const attributeValue = JSON.stringify(serviceEndpointParams)
const attributeExpiration = 86400
const hash1 = await ethrDid.createSetAttributeHash(attributeName, attributeValue, attributeExpiration)
const signature1 = new SigningKey(currentOwnerPrivateKey).signDigest(hash1)
const signature1 = new SigningKey(currentOwnerPrivateKey).sign(hash1)

await walletSigner.setAttributeSigned(attributeName, attributeValue, attributeExpiration, {
sigV: signature1.v,
Expand Down Expand Up @@ -972,7 +965,7 @@ describe('EthrDID (Meta Transactions)', () => {
// Add second attribute
const attributeName2 = 'did/svc/test2Service'
const hash2 = await ethrDid.createSetAttributeHash(attributeName2, attributeValue, attributeExpiration)
const signature2 = new SigningKey(currentOwnerPrivateKey).signDigest(hash2)
const signature2 = new SigningKey(currentOwnerPrivateKey).sign(hash2)

await walletSigner.setAttributeSigned(attributeName2, attributeValue, attributeExpiration, {
sigV: signature2.v,
Expand Down Expand Up @@ -1022,7 +1015,7 @@ describe('EthrDID (Meta Transactions)', () => {
const serviceEndpointParams = { uri: 'https://didcomm.example.com', transportType: 'http' }
const attributeValue = JSON.stringify(serviceEndpointParams)
const hash = await ethrDid.createRevokeAttributeHash(attributeName, attributeValue)
const signature = new SigningKey(currentOwnerPrivateKey).signDigest(hash)
const signature = new SigningKey(currentOwnerPrivateKey).sign(hash)

await walletSigner.revokeAttributeSigned(attributeName, attributeValue, {
sigV: signature.v,
Expand Down Expand Up @@ -1062,13 +1055,14 @@ describe('EthrDID (Meta Transactions)', () => {
it('change owner via meta transaction', async () => {
const nextOwner = accounts[2]
const hash = await ethrDid.createChangeOwnerHash(nextOwner)
const signature = new SigningKey(currentOwnerPrivateKey).signDigest(hash)
const signature = new SigningKey(currentOwnerPrivateKey).sign(hash)

await walletSigner.changeOwnerSigned(nextOwner, {
sigV: signature.v,
sigR: signature.r,
sigS: signature.s,
})

const resolved = await resolver.resolve(did)
expect(resolved.didDocument).toEqual({
'@context': expect.anything(),
Expand Down
13 changes: 5 additions & 8 deletions src/__tests__/testUtils.ts → src/__tests__/util/testUtils.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import { ExternalProvider, JsonRpcProvider, Web3Provider } from '@ethersproject/providers'
import ganache from 'ganache'
import { BrowserProvider, JsonRpcProvider } from 'ethers'

export function createProvider(): JsonRpcProvider {
return new Web3Provider(
export function createProvider(): BrowserProvider {
return new BrowserProvider(
ganache.provider({
logging: {
quiet: true,
},
logging: { quiet: true },
accounts: [
{
secretKey: '0x278a5de700e29faae8e40e366ec5012b5ec63d36ec77e8a2417154cc1d25383f',
Expand Down Expand Up @@ -49,8 +47,7 @@ export function createProvider(): JsonRpcProvider {
balance: `0x1000000000000000000000`,
},
],
// eslint-disable-next-line @typescript-eslint/no-explicit-any
}) as any as ExternalProvider
})
)
}

Expand Down
Loading

0 comments on commit 74031f6

Please sign in to comment.