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 committed Oct 25, 2023
1 parent 977662a commit 7e89ddd
Show file tree
Hide file tree
Showing 61 changed files with 9,308 additions and 6,305 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/build-and-test-on-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: Build and Test PR
on: [pull_request, workflow_dispatch]
jobs:
build-test:
runs-on: ubuntu-18.04
runs-on: ubuntu-latest
services:
postgres:
image: postgres:15.1
Expand All @@ -19,11 +19,11 @@ jobs:
fetch-depth: 0
- uses: pnpm/action-setup@v2
with:
version: 7
version: 8
- name: Use Node.js
uses: actions/setup-node@v3
with:
node-version: 14
node-version: 16
cache: 'pnpm'

- run: pnpm install
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/build-test-publish-on-push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
GH_TOKEN: ${{secrets.GH_TOKEN}}
GH_USER: ${{secrets.GH_USER}}
GH_EMAIL: ${{secrets.GH_EMAIL}}
runs-on: ubuntu-18.04
runs-on: ubuntu-latest
services:
postgres:
image: postgres:15.1
Expand All @@ -32,11 +32,11 @@ jobs:
token: ${{secrets.GH_TOKEN}}
- uses: pnpm/action-setup@v2
with:
version: 7
version: 8
- name: Use Node.js
uses: actions/setup-node@v3
with:
node-version: 14
node-version: 16
cache: 'pnpm'

- run: pnpm install --force
Expand All @@ -56,7 +56,7 @@ jobs:

- name: setup git coordinates
run: |
git remote set-url origin https://uport-project:$[email protected]/uport-project/veramo.git
git remote set-url origin https://${{secrets.GH_USER}}:${{secrets.GH_TOKEN}}@github.com/decentralized-identity/veramo.git
git config user.name $GH_USER
git config user.email $GH_EMAIL
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/sync-next-with-latest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ on:
- 'main'
jobs:
merge-branch:
runs-on: ubuntu-18.04
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: everlytic/[email protected]
Expand Down
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}`)
}
}
}
}
110 changes: 52 additions & 58 deletions __tests__/utils/ganache-provider.ts
Original file line number Diff line number Diff line change
@@ -1,70 +1,64 @@
import { Web3Provider } from '@ethersproject/providers'
import { Contract, ContractFactory } from '@ethersproject/contracts'
// @ts-ignore
import DidRegistryContract from 'ethr-did-registry'
import ganache from 'ganache'
import { Contract, ContractFactory, JsonRpcApiProvider } from 'ethers'
import { EthereumDIDRegistry } from 'ethr-did-resolver'
import { GanacheProvider } from '@ethers-ext/provider-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(
ganache.provider({
logging: { quiet: true },
accounts: [
{
secretKey: '0x278a5de700e29faae8e40e366ec5012b5ec63d36ec77e8a2417154cc1d25383f',
// address: '0xf3beac30c498d9e26865f34fcaa57dbb935b0d74',
// publicKey: '03fdd57adec3d438ea237fe46b33ee1e016eda6b585c3e27ea66686c2ea5358479'
balance: '0x1000000000000000000000',
},
{
secretKey: '0x0000000000000000000000000000000000000000000000000000000000000001',
// address: '0x7e5f4552091a69125d5dfcb7b8c2659029395bdf',
// publicKey: '0279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798'
balance: '0x1000000000000000000000',
},
{
secretKey: '0x0000000000000000000000000000000000000000000000000000000000000002',
// address: '0x2b5ad5c4795c026514f8317c7a215e218dccd6cf',
// publicKey: '02c6047f9441ed7d6d3045406e95c07cd85c778e4b8cef3ca7abac09b95c709ee5'
balance: '0x1000000000000000000000',
},
{
secretKey: '0x0000000000000000000000000000000000000000000000000000000000000003',
// address: '0x6813eb9362372eef6200f3b1dbc3f819671cba69',
// publicKey: '02f9308a019258c31049344f85f89d5229b531c845836f99b08601f113bce036f9'
balance: '0x1000000000000000000000',
},
{
secretKey: '0x0000000000000000000000000000000000000000000000000000000000000004',
// address: '0x1eff47bc3a10a45d4b230b5d10e37751fe6aa718',
// publicKey: '02e493dbf1c10d80f3581e4904930b1404cc6c13900ee0758474fa94abe8c4cd13'
balance: '0x1000000000000000000000',
},
{
secretKey: '0x0000000000000000000000000000000000000000000000000000000000000005',
// address: '0xe1ab8145f7e55dc933d51a18c793f901a3a0b276'
// publicKey: '022f8bde4d1a07209355b4a7250a5c5128e88b84bddc619ab7cba8d569b240efe4'
balance: '0x1000000000000000000000',
},
{
secretKey: '0x0000000000000000000000000000000000000000000000000000000000000006',
balance: `0x1000000000000000000000`,
},
],
}) as any
)
export async function createGanacheProvider(): Promise<{ provider: JsonRpcApiProvider; registry: string }> {
const provider = new GanacheProvider({
logging: { quiet: true },
accounts: [
{
secretKey: '0x278a5de700e29faae8e40e366ec5012b5ec63d36ec77e8a2417154cc1d25383f',
// address: '0xf3beac30c498d9e26865f34fcaa57dbb935b0d74',
// publicKey: '03fdd57adec3d438ea237fe46b33ee1e016eda6b585c3e27ea66686c2ea5358479'
balance: '0x1000000000000000000000',
},
{
secretKey: '0x0000000000000000000000000000000000000000000000000000000000000001',
// address: '0x7e5f4552091a69125d5dfcb7b8c2659029395bdf',
// publicKey: '0279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798'
balance: '0x1000000000000000000000',
},
{
secretKey: '0x0000000000000000000000000000000000000000000000000000000000000002',
// address: '0x2b5ad5c4795c026514f8317c7a215e218dccd6cf',
// publicKey: '02c6047f9441ed7d6d3045406e95c07cd85c778e4b8cef3ca7abac09b95c709ee5'
balance: '0x1000000000000000000000',
},
{
secretKey: '0x0000000000000000000000000000000000000000000000000000000000000003',
// address: '0x6813eb9362372eef6200f3b1dbc3f819671cba69',
// publicKey: '02f9308a019258c31049344f85f89d5229b531c845836f99b08601f113bce036f9'
balance: '0x1000000000000000000000',
},
{
secretKey: '0x0000000000000000000000000000000000000000000000000000000000000004',
// address: '0x1eff47bc3a10a45d4b230b5d10e37751fe6aa718',
// publicKey: '02e493dbf1c10d80f3581e4904930b1404cc6c13900ee0758474fa94abe8c4cd13'
balance: '0x1000000000000000000000',
},
{
secretKey: '0x0000000000000000000000000000000000000000000000000000000000000005',
// address: '0xe1ab8145f7e55dc933d51a18c793f901a3a0b276'
// publicKey: '022f8bde4d1a07209355b4a7250a5c5128e88b84bddc619ab7cba8d569b240efe4'
balance: '0x1000000000000000000000',
},
{
secretKey: '0x0000000000000000000000000000000000000000000000000000000000000006',
balance: `0x1000000000000000000000`,
},
],
} 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 }
}
Loading

0 comments on commit 7e89ddd

Please sign in to comment.