Skip to content

Commit

Permalink
fix: tentative CJS build + ethers v6 (#1280)
Browse files Browse the repository at this point in the history
* chore(deps): bump ethers (#1242)

* fix(deps): patch tests and package.json files after the ethers bump

Co-authored-by: Dennis von der Bey <[email protected]>
  • Loading branch information
mirceanis and fermentfan authored Oct 24, 2023
1 parent 977662a commit c37ee8c
Show file tree
Hide file tree
Showing 56 changed files with 19,244 additions and 8,417 deletions.
4 changes: 2 additions & 2 deletions __tests__/localAgent.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ import didCommWithEthrDidFlow from './shared/didCommWithEthrDidFlow'
import utils from './shared/utils'
import web3 from './shared/web3'
import credentialStatus from './shared/credentialStatus'
import ethrDidFlowSigned from "./shared/ethrDidFlowSigned";
import ethrDidFlowSigned from './shared/ethrDidFlowSigned'

jest.setTimeout(60000)

Expand Down Expand Up @@ -207,7 +207,7 @@ const setup = async (options?: IAgentOptions): Promise<boolean> => {
{
name: 'ganache',
chainId: 1337,
provider,
provider: provider as any,
registry,
},
],
Expand Down
2 changes: 1 addition & 1 deletion __tests__/shared/didCommWithEthrDidFlow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ export default (testContext: {
const requestWithAgent = RequestWithAgentRouter({ agent })

await new Promise((resolve) => {
//setup a server to receive HTTP messages and forward them to this agent to be processed as DIDComm messages
// set up a server to receive HTTP messages and forward them to this agent to be processed as DIDComm messages
const app = express()
// app.use(requestWithAgent)
app.use(
Expand Down
2 changes: 1 addition & 1 deletion __tests__/shared/didManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export default (testContext: {
expect(identifier.controllerKeyId).toEqual(identifier.keys[0].kid)
})

it('should create identifier using chainId 3', async () => {
it('should translate identifier using chainId 421613 to arbitrum', async () => {
identifier = await agent.didManagerCreate({
provider: 'did:ethr',
options: {
Expand Down
45 changes: 35 additions & 10 deletions __tests__/shared/keyManager.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
// noinspection ES6PreferShortImport

import { IAgentOptions, IDIDManager, IKeyManager, IResolver, TAgent, TKeyType } from '../../packages/core/src'
import { computeAddress, serialize } from '@ethersproject/transactions'
import { mapIdentifierKeysToDoc } from '../../packages/utils/src'
import { recoverTypedSignature, SignTypedDataVersion } from '@metamask/eth-sig-util'
import {computeAddress, Transaction} from "ethers";

type ConfiguredAgent = TAgent<IDIDManager & IKeyManager & IResolver>

Expand Down Expand Up @@ -222,7 +222,7 @@ export default (testContext: {
const rawTx = await agent.keyManagerSignEthTX({
kid: key.kid,
transaction: {
to: '0xce31a19193d4b23f4e9d6163d7247243bAF801c3',
to: '0xcE31a19193D4b23F4E9D6163d7247243BAF801C3',
value: 300000,
gasLimit: 43092000,
gasPrice: 20000000000,
Expand All @@ -243,7 +243,7 @@ export default (testContext: {
const rawTx = await agent.keyManagerSignEthTX({
kid: key.kid,
transaction: {
to: '0xce31a19193d4b23f4e9d6163d7247243bAF801c3',
to: '0xcE31a19193D4b23F4E9D6163d7247243BAF801C3',
from: keyAddress,
value: 300000,
gasLimit: 43092000,
Expand All @@ -266,8 +266,8 @@ export default (testContext: {
agent.keyManagerSignEthTX({
kid: key.kid,
transaction: {
to: '0xce31a19193d4b23f4e9d6163d7247243bAF801c3',
from: '0xce31a19193d4b23f4e9d6163d7247243bAF801c3',
to: '0xcE31a19193D4b23F4E9D6163d7247243BAF801C3',
from: '0xcE31a19193D4b23F4E9D6163d7247243BAF801C3',
value: 300000,
gasLimit: 43092000,
gasPrice: 20000000000,
Expand Down Expand Up @@ -351,15 +351,15 @@ export default (testContext: {
const rawTx = await agent.keyManagerSignEthTX({
kid: importedKey.kid,
transaction: {
to: '0xce31a19193d4b23f4e9d6163d7247243bAF801c3',
to: '0xcE31a19193D4b23F4E9D6163d7247243BAF801C3',
value: 300000,
gasLimit: 43092000,
gasPrice: 20000000000,
nonce: 1,
},
})
expect(rawTx).toEqual(
'0xf869018504a817c800840291882094ce31a19193d4b23f4e9d6163d7247243baf801c3830493e0801ba0f16e2206290181c3feaa04051dad19089105c24339dbdf0d80147b48a59fa152a0770e8751ec77ccc78e8b207023f168444f7cfb67055c55c70ef75234458a3d51',
'0x01f86b80018504a817c800840291882094ce31a19193d4b23f4e9d6163d7247243baf801c3830493e080c001a05a46cdfe2102e81e90f89d8896ddaf32aee5473bad994bc1767f0d2af9afa160a01c028daaf737d69f6933d2dfef5e739f459cfb9e8ce1d9ba9ea7bb0c6006518c',
)
})

Expand All @@ -376,14 +376,39 @@ export default (testContext: {
})

it('should sign EthTX using generic signer', async () => {
const txData = serialize({
to: '0xce31a19193d4b23f4e9d6163d7247243bAF801c3',
const transaction = new Transaction()
transaction.to = '0xcE31a19193D4b23F4E9D6163d7247243BAF801C3'
transaction.value = 300000
transaction.gasLimit = 43092000
transaction.gasPrice = 20000000000
transaction.nonce = 1

const txData = transaction.unsignedSerialized

const rawTx = await agent.keyManagerSign({
algorithm: 'eth_signTransaction',
data: txData,
encoding: 'hex',
keyRef: importedKey.kid,
})

expect(rawTx).toEqual(
'0x01f86b80018504a817c800840291882094ce31a19193d4b23f4e9d6163d7247243baf801c3830493e080c001a05a46cdfe2102e81e90f89d8896ddaf32aee5473bad994bc1767f0d2af9afa160a01c028daaf737d69f6933d2dfef5e739f459cfb9e8ce1d9ba9ea7bb0c6006518c',
)
})

it('should sign EthTX using generic signer and specific type', async () => {
const transaction = Transaction.from({
to: '0xcE31a19193D4b23F4E9D6163d7247243BAF801C3',
value: 300000,
gasLimit: 43092000,
gasPrice: 20000000000,
nonce: 1,
type: 0, // enforce legacy serialization
})

const txData = transaction.unsignedSerialized

const rawTx = await agent.keyManagerSign({
algorithm: 'eth_signTransaction',
data: txData,
Expand All @@ -392,7 +417,7 @@ export default (testContext: {
})

expect(rawTx).toEqual(
'0xf869018504a817c800840291882094ce31a19193d4b23f4e9d6163d7247243baf801c3830493e0801ba0f16e2206290181c3feaa04051dad19089105c24339dbdf0d80147b48a59fa152a0770e8751ec77ccc78e8b207023f168444f7cfb67055c55c70ef75234458a3d51',
'0xf869018504a817c800840291882094ce31a19193d4b23f4e9d6163d7247243baf801c3830493e0801ba0f16e2206290181c3feaa04051dad19089105c24339dbdf0d80147b48a59fa152a0770e8751ec77ccc78e8b207023f168444f7cfb67055c55c70ef75234458a3d51',
)
})
})
Expand Down
27 changes: 14 additions & 13 deletions __tests__/utils/ethers-provider.ts
Original file line number Diff line number Diff line change
@@ -1,34 +1,35 @@
import { Web3Provider, ExternalProvider } from '@ethersproject/providers'
import { Wallet } from '@ethersproject/wallet'
import { BrowserProvider, Eip1193Provider, Wallet } from 'ethers'

export function createEthersProvider(): Web3Provider {
export function createEthersProvider(): BrowserProvider {
const privateKeyHex = '0x1da6847600b0ee25e9ad9a52abbd786dd2502fa4005dd5af9310b7cc7a3b25db'
const wallet = new Wallet(privateKeyHex)
const mockProvider = new MockWeb3Provider(wallet)
const provider = new Web3Provider(mockProvider)
const provider = new BrowserProvider(mockProvider)
return provider
}

class MockWeb3Provider implements Eip1193Provider {
constructor(private wallet: Wallet) {}

class MockWeb3Provider implements ExternalProvider {
constructor(private wallet: Wallet){

}
async request(request: { method: string; params?: any[] }): Promise<any> {

switch(request.method) {
case 'personal_sign':
//@ts-ignore
return this.wallet.signMessage(request.params[1])
break
case 'eth_signTypedData_v4':
//@ts-ignore
case 'eth_signTypedData_v4':
// @ts-ignore
const {domain, types, message} = JSON.parse(request.params[1])
delete(types.EIP712Domain)
return this.wallet._signTypedData(domain, types, message)
return this.wallet.signTypedData(domain, types, message)
case 'eth_accounts':
return [await this.wallet.getAddress()]
case 'eth_chainId':
return "1337"
break
default:
throw Error(`not_available: method ${request.method}`)
}
}
}
}
18 changes: 7 additions & 11 deletions __tests__/utils/ganache-provider.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
import { Web3Provider } from '@ethersproject/providers'
import { Contract, ContractFactory } from '@ethersproject/contracts'
// @ts-ignore
import DidRegistryContract from 'ethr-did-registry'
import { BrowserProvider, Contract, ContractFactory } from 'ethers'
import { EthereumDIDRegistry } from 'ethr-did-resolver'
import ganache from 'ganache'

/**
* Creates a Web3Provider that connects to a local ganache instance with a bunch of known keys and an ERC1056 contract.
*
* This provider can only be used in a single test suite, because of some concurrency issues with ganache.
*/
export async function createGanacheProvider(): Promise<{ provider: Web3Provider; registry: string }> {
const provider = new Web3Provider(
export async function createGanacheProvider(): Promise<{ provider: BrowserProvider; registry: string }> {
const provider = new BrowserProvider(
ganache.provider({
logging: { quiet: true },
accounts: [
Expand Down Expand Up @@ -58,13 +56,11 @@ export async function createGanacheProvider(): Promise<{ provider: Web3Provider;
}) as any
)
await provider.ready
const factory = ContractFactory.fromSolidity(DidRegistryContract).connect(provider.getSigner(0))
const factory = ContractFactory.fromSolidity(EthereumDIDRegistry).connect(await provider.getSigner(0))

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

await registryContract.deployTransaction.wait()

const registry = registryContract.address
const registry = await registryContract.getAddress()
return { provider, registry }
}
24 changes: 11 additions & 13 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,6 @@
"__browser_tests__/*"
],
"devDependencies": {
"@ethersproject/contracts": "^5.7.0",
"@ethersproject/providers": "^5.7.2",
"@ethersproject/transactions": "^5.7.0",
"@ethersproject/wallet": "^5.7.0",
"@metamask/eth-sig-util": "^5.0.0",
"@microsoft/api-documenter": "7.19.27",
"@microsoft/api-extractor": "7.33.7",
Expand All @@ -43,22 +39,23 @@
"@transmute/credentials-context": "^0.7.0-unstable.77",
"@types/express": "4.17.15",
"@types/fs-extra": "9.0.13",
"@types/jest": "28.1.8",
"@types/jest": "29.5.6",
"@types/node": "18.11.18",
"@types/uuid": "^9.0.0",
"caip": "^1.1.0",
"credential-status": "^2.0.5",
"cross-env": "7.0.3",
"did-jwt": "^6.11.0",
"did-jwt": "^6.11.6",
"did-jwt-vc": "^3.1.0",
"did-resolver": "^4.0.1",
"ethers": "^6.8.0",
"ethr-did-registry": "0.0.3",
"ethr-did-resolver": "^8.0.0",
"ethr-did-resolver": "^9.0.0",
"express": "^4.18.2",
"ganache": "7.4.4",
"jest": "28.1.3",
"jest-environment-jsdom": "28.1.3",
"jest-environment-node": "28.1.3",
"ganache": "7.9.1",
"jest": "29.7.0",
"jest-environment-jsdom": "29.7.0",
"jest-environment-node": "29.7.0",
"json-schema": "0.4.0",
"lerna": "5.1.1",
"lerna-changelog": "2.2.0",
Expand All @@ -68,7 +65,7 @@
"pretty-quick": "3.1.3",
"rimraf": "3.0.2",
"semantic-release": "19.0.5",
"ts-jest": "28.0.8",
"ts-jest": "29.1.1",
"ts-json-schema-generator": "1.1.2",
"ts-node": "10.9.1",
"typeorm": "^0.3.10",
Expand Down Expand Up @@ -96,7 +93,8 @@
"resolutions": {
"@types/react": "^18.0.21",
"@types/eslint": "^8.4.6",
"jsonld": "npm:@digitalcredentials/jsonld@^5.2.1"
"jsonld": "npm:@digitalcredentials/jsonld@^5.2.1",
"did-jwt": "6.11.6"
},
"engines": {
"node": ">= 14.0.0"
Expand Down
44 changes: 22 additions & 22 deletions packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,27 +18,27 @@
"@microsoft/api-extractor-model": "^7.25.2",
"@types/blessed": "^0.1.19",
"@types/swagger-ui-express": "^4.1.3",
"@veramo/core": "^4.3.0",
"@veramo/credential-eip712": "^4.3.0",
"@veramo/credential-ld": "^4.3.0",
"@veramo/credential-w3c": "^4.3.0",
"@veramo/data-store": "^4.3.0",
"@veramo/did-comm": "^4.3.0",
"@veramo/did-discovery": "^4.3.0",
"@veramo/did-jwt": "^4.3.0",
"@veramo/did-manager": "^4.3.0",
"@veramo/did-provider-ethr": "^4.3.0",
"@veramo/did-provider-key": "^4.3.0",
"@veramo/did-provider-web": "^4.3.0",
"@veramo/did-resolver": "^4.3.0",
"@veramo/key-manager": "^4.3.0",
"@veramo/kms-local": "^4.3.0",
"@veramo/message-handler": "^4.3.0",
"@veramo/remote-client": "^4.3.0",
"@veramo/remote-server": "^4.3.0",
"@veramo/selective-disclosure": "^4.3.0",
"@veramo/url-handler": "^4.3.0",
"@veramo/utils": "^4.3.0",
"@veramo/core": "workspace:^",
"@veramo/credential-eip712": "workspace:^",
"@veramo/credential-ld": "workspace:^",
"@veramo/credential-w3c": "workspace:^",
"@veramo/data-store": "workspace:^",
"@veramo/did-comm": "workspace:^",
"@veramo/did-discovery": "workspace:^",
"@veramo/did-jwt": "workspace:^",
"@veramo/did-manager": "workspace:^",
"@veramo/did-provider-ethr": "workspace:^",
"@veramo/did-provider-key": "workspace:^",
"@veramo/did-provider-web": "workspace:^",
"@veramo/did-resolver": "workspace:^",
"@veramo/key-manager": "workspace:^",
"@veramo/kms-local": "workspace:^",
"@veramo/message-handler": "workspace:^",
"@veramo/remote-client": "workspace:^",
"@veramo/remote-server": "workspace:^",
"@veramo/selective-disclosure": "workspace:^",
"@veramo/url-handler": "workspace:^",
"@veramo/utils": "workspace:^",
"blessed": "^0.1.81",
"commander": "^9.0.0",
"console-table-printer": "^2.10.0",
Expand All @@ -48,7 +48,7 @@
"debug": "^4.3.3",
"did-resolver": "^4.0.1",
"dotenv": "^16.0.0",
"ethr-did-resolver": "^8.0.0",
"ethr-did-resolver": "^9.0.0",
"express": "^4.18.2",
"express-handlebars": "^6.0.2",
"fuzzy": "^0.1.3",
Expand Down
4 changes: 2 additions & 2 deletions packages/credential-eip712/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
},
"dependencies": {
"@metamask/eth-sig-util": "^5.0.0",
"@veramo/core": "^4.3.0",
"@veramo/utils": "^4.3.0",
"@veramo/core": "workspace:^",
"@veramo/utils": "workspace:^",
"debug": "^4.3.3",
"eip-712-types-generation": "^0.1.6"
},
Expand Down
6 changes: 3 additions & 3 deletions packages/credential-ld/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@
"@transmute/ed25519-signature-2018": "^0.7.0-unstable.77",
"@transmute/json-web-signature": "^0.7.0-unstable.77",
"@veramo-community/lds-ecdsa-secp256k1-recovery2020": "uport-project/EcdsaSecp256k1RecoverySignature2020",
"@veramo/core": "^4.3.0",
"@veramo/did-resolver": "^4.3.0",
"@veramo/utils": "^4.3.0",
"@veramo/core": "workspace:^",
"@veramo/did-resolver": "workspace:^",
"@veramo/utils": "workspace:^",
"cross-fetch": "^3.1.5",
"debug": "^4.3.3",
"did-resolver": "^4.0.1",
Expand Down
6 changes: 3 additions & 3 deletions packages/credential-status/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@
"extract-api": "pnpm exec veramo dev extract-api"
},
"dependencies": {
"@veramo/core": "^4.3.0",
"@veramo/utils": "^4.3.0",
"@veramo/core": "workspace:^",
"@veramo/utils": "workspace:^",
"credential-status": "^2.0.5",
"did-jwt": "^6.9.0",
"did-jwt": "^6.11.6",
"did-resolver": "^4.0.1"
},
"devDependencies": {
Expand Down
Loading

0 comments on commit c37ee8c

Please sign in to comment.