Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(did-provider-ethr): use multiple networks per EthrDIDProvider #969

Merged
merged 3 commits into from
Jul 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/pull_request_template.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ A clear description of what this PR brings.
Check all that apply:
* [X] I want these changes to be integrated
* [ ] I successfully ran `yarn`, `yarn build`, `yarn test`, `yarn test:browser` locally.
* [ ] I allow my PR to be updated by the reviewers (to speed up the review process).
* [ ] I allow my PR to be updated by the reviewers (to speed up the review process).
* [ ] I added unit tests.
* [ ] I added integration tests.
* [ ] I did not add automated tests because _________, and I am aware that a PR without tests will likely get rejected.
Expand Down
1 change: 1 addition & 0 deletions __tests__/initial.migration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ describe('database initial migration tests', () => {
store: new DIDStore(dbConnection),
defaultProvider: 'did:ethr:goerli',
providers: {
// intentionally using deprecated config for backward compatibility checks
'did:ethr:goerli': new EthrDIDProvider({
defaultKms: 'local',
network: 'goerli',
Expand Down
49 changes: 24 additions & 25 deletions __tests__/localAgent.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ import didCommWithEthrDidFlow from './shared/didCommWithEthrDidFlow'
import utils from './shared/utils'
import web3 from './shared/web3'


jest.setTimeout(60000)

const infuraProjectId = '3586660d179141e3801c3895de1c2eba'
Expand Down Expand Up @@ -148,8 +147,8 @@ const setup = async (options?: IAgentOptions): Promise<boolean> => {
kms: {
local: new KeyManagementSystem(new PrivateKeyStore(dbConnection, new SecretBox(secretKey))),
web3: new Web3KeyManagementSystem({
'ethers': ethersProvider
})
ethers: ethersProvider,
}),
},
}),
new DIDManager({
Expand All @@ -158,29 +157,29 @@ const setup = async (options?: IAgentOptions): Promise<boolean> => {
providers: {
'did:ethr': new EthrDIDProvider({
defaultKms: 'local',
network: 'mainnet',
rpcUrl: 'https://mainnet.infura.io/v3/' + infuraProjectId,
gas: 1000001,
ttl: 60 * 60 * 24 * 30 * 12 + 1,
}),
'did:ethr:rinkeby': new EthrDIDProvider({
defaultKms: 'local',
network: 'rinkeby',
rpcUrl: 'https://rinkeby.infura.io/v3/' + infuraProjectId,
gas: 1000001,
ttl: 60 * 60 * 24 * 30 * 12 + 1,
}),
'did:ethr:421611': new EthrDIDProvider({
defaultKms: 'local',
network: 421611,
rpcUrl: 'https://arbitrum-rinkeby.infura.io/v3/' + infuraProjectId,
registry: '0x8f54f62CA28D481c3C30b1914b52ef935C1dF820',
}),
'did:ethr:ganache': new EthrDIDProvider({
defaultKms: 'local',
network: 1337,
web3Provider: provider,
registry,
networks: [
{
name: 'mainnet',
rpcUrl: 'https://mainnet.infura.io/v3/' + infuraProjectId,
},
{
name: 'rinkeby',
rpcUrl: 'https://rinkeby.infura.io/v3/' + infuraProjectId,
},
{
chainId: 421611,
name: 'arbitrum:rinkeby',
rpcUrl: 'https://arbitrum-rinkeby.infura.io/v3/' + infuraProjectId,
registry: '0x8f54f62CA28D481c3C30b1914b52ef935C1dF820',
},
{
chainId: 1337,
name: 'ganache',
provider,
registry,
},
],
}),
'did:web': new WebDIDProvider({
defaultKms: 'local',
Expand Down
33 changes: 16 additions & 17 deletions __tests__/localJsonStoreAgent.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ import messageHandler from './shared/messageHandler'
import utils from './shared/utils'
import { JsonFileStore } from './utils/json-file-store'


jest.setTimeout(60000)

const infuraProjectId = '3586660d179141e3801c3895de1c2eba'
Expand Down Expand Up @@ -132,23 +131,23 @@ const setup = async (options?: IAgentOptions): Promise<boolean> => {
providers: {
'did:ethr': new EthrDIDProvider({
defaultKms: 'local',
network: 'mainnet',
rpcUrl: 'https://mainnet.infura.io/v3/' + infuraProjectId,
gas: 1000001,
ttl: 60 * 60 * 24 * 30 * 12 + 1,
}),
'did:ethr:rinkeby': new EthrDIDProvider({
defaultKms: 'local',
network: 'rinkeby',
rpcUrl: 'https://rinkeby.infura.io/v3/' + infuraProjectId,
gas: 1000001,
ttl: 60 * 60 * 24 * 30 * 12 + 1,
}),
'did:ethr:421611': new EthrDIDProvider({
defaultKms: 'local',
network: 421611,
rpcUrl: 'https://arbitrum-rinkeby.infura.io/v3/' + infuraProjectId,
registry: '0x8f54f62CA28D481c3C30b1914b52ef935C1dF820',
networks: [
{
name: 'mainnet',
rpcUrl: 'https://mainnet.infura.io/v3/' + infuraProjectId,
},
{
name: 'rinkeby',
rpcUrl: 'https://rinkeby.infura.io/v3/' + infuraProjectId,
},
{
chainId: 421611,
name: 'arbitrum:rinkeby',
rpcUrl: 'https://arbitrum-rinkeby.infura.io/v3/' + infuraProjectId,
registry: '0x8f54f62CA28D481c3C30b1914b52ef935C1dF820',
},
],
}),
'did:web': new WebDIDProvider({
defaultKms: 'local',
Expand Down
74 changes: 37 additions & 37 deletions __tests__/localMemoryStoreAgent.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,16 +70,16 @@ const infuraProjectId = '3586660d179141e3801c3895de1c2eba'

let agent: TAgent<
IDIDManager &
IKeyManager &
IDataStore &
IDataStoreORM &
IResolver &
IMessageHandler &
IDIDComm &
ICredentialIssuer &
ICredentialIssuerLD &
ICredentialIssuerEIP712 &
ISelectiveDisclosure
IKeyManager &
IDataStore &
IDataStoreORM &
IResolver &
IMessageHandler &
IDIDComm &
ICredentialIssuer &
ICredentialIssuerLD &
ICredentialIssuerEIP712 &
ISelectiveDisclosure
>
let dbConnection: Promise<Connection>

Expand All @@ -97,16 +97,16 @@ const setup = async (options?: IAgentOptions): Promise<boolean> => {

agent = createAgent<
IDIDManager &
IKeyManager &
IDataStore &
IDataStoreORM &
IResolver &
IMessageHandler &
IDIDComm &
ICredentialIssuer &
ICredentialIssuerLD &
ICredentialIssuerEIP712 &
ISelectiveDisclosure
IKeyManager &
IDataStore &
IDataStoreORM &
IResolver &
IMessageHandler &
IDIDComm &
ICredentialIssuer &
ICredentialIssuerLD &
ICredentialIssuerEIP712 &
ISelectiveDisclosure
>({
...options,
context: {
Expand All @@ -117,7 +117,7 @@ const setup = async (options?: IAgentOptions): Promise<boolean> => {
store: new MemoryKeyStore(),
kms: {
local: new KeyManagementSystem(new MemoryPrivateKeyStore()),
web3: new Web3KeyManagementSystem({})
web3: new Web3KeyManagementSystem({}),
},
}),
new DIDManager({
Expand All @@ -126,23 +126,23 @@ const setup = async (options?: IAgentOptions): Promise<boolean> => {
providers: {
'did:ethr': new EthrDIDProvider({
defaultKms: 'local',
network: 'mainnet',
rpcUrl: 'https://mainnet.infura.io/v3/' + infuraProjectId,
gas: 1000001,
ttl: 60 * 60 * 24 * 30 * 12 + 1,
}),
'did:ethr:rinkeby': new EthrDIDProvider({
defaultKms: 'local',
network: 'rinkeby',
rpcUrl: 'https://rinkeby.infura.io/v3/' + infuraProjectId,
gas: 1000001,
ttl: 60 * 60 * 24 * 30 * 12 + 1,
}),
'did:ethr:421611': new EthrDIDProvider({
defaultKms: 'local',
network: 421611,
rpcUrl: 'https://arbitrum-rinkeby.infura.io/v3/' + infuraProjectId,
registry: '0x8f54f62CA28D481c3C30b1914b52ef935C1dF820',
networks: [
{
name: 'mainnet',
rpcUrl: 'https://mainnet.infura.io/v3/' + infuraProjectId,
},
{
name: 'rinkeby',
rpcUrl: 'https://rinkeby.infura.io/v3/' + infuraProjectId,
},
{
chainId: 421611,
name: 'arbitrum:rinkeby',
rpcUrl: 'https://arbitrum-rinkeby.infura.io/v3/' + infuraProjectId,
registry: '0x8f54f62CA28D481c3C30b1914b52ef935C1dF820',
},
],
}),
'did:web': new WebDIDProvider({
defaultKms: 'local',
Expand Down
32 changes: 16 additions & 16 deletions __tests__/restAgent.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,23 +149,23 @@ const setup = async (options?: IAgentOptions): Promise<boolean> => {
providers: {
'did:ethr': new EthrDIDProvider({
defaultKms: 'local',
network: 'mainnet',
rpcUrl: 'https://mainnet.infura.io/v3/' + infuraProjectId,
gas: 1000001,
ttl: 60 * 60 * 24 * 30 * 12 + 1,
}),
'did:ethr:rinkeby': new EthrDIDProvider({
defaultKms: 'local',
network: 'rinkeby',
rpcUrl: 'https://rinkeby.infura.io/v3/' + infuraProjectId,
gas: 1000001,
ttl: 60 * 60 * 24 * 30 * 12 + 1,
}),
'did:ethr:421611': new EthrDIDProvider({
defaultKms: 'local',
network: 421611,
rpcUrl: 'https://arbitrum-rinkeby.infura.io/v3/' + infuraProjectId,
registry: '0x8f54f62CA28D481c3C30b1914b52ef935C1dF820',
networks: [
{
name: 'mainnet',
rpcUrl: 'https://mainnet.infura.io/v3/' + infuraProjectId,
},
{
name: 'rinkeby',
rpcUrl: 'https://rinkeby.infura.io/v3/' + infuraProjectId,
},
{
chainId: 421611,
name: 'arbitrum:rinkeby',
rpcUrl: 'https://arbitrum-rinkeby.infura.io/v3/' + infuraProjectId,
registry: '0x8f54f62CA28D481c3C30b1914b52ef935C1dF820',
},
],
}),
'did:web': new WebDIDProvider({
defaultKms: 'local',
Expand Down
25 changes: 21 additions & 4 deletions __tests__/shared/didManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,29 @@ export default (testContext: {
expect(identifier.controllerKeyId).toEqual(identifier.keys[0].kid)
})

it('should create identifier using did:ethr:421611', async () => {
it('should create identifier using did:ethr:arbitrum:rinkeby provider', async () => {
identifier = await agent.didManagerCreate({
provider: 'did:ethr:421611',
// this expects the `did:ethr` provider to matchPrefix and use the `arbitrum:rinkeby` network specifier
provider: 'did:ethr:arbitrum:rinkeby',
})
expect(identifier.provider).toEqual('did:ethr:421611')
expect(identifier.did).toMatch(/^did:ethr:421611:0x.*$/)
expect(identifier.provider).toEqual('did:ethr:arbitrum:rinkeby')
expect(identifier.did).toMatch(/^did:ethr:arbitrum:rinkeby:0x.*$/)
expect(identifier.keys.length).toEqual(1)
expect(identifier.services.length).toEqual(0)
expect(identifier.controllerKeyId).toEqual(identifier.keys[0].kid)
})

it('should create identifier using chainId 421611', async () => {
identifier = await agent.didManagerCreate({
provider: 'did:ethr',
options: {
// this expects the `did:ethr` provider to matchPrefix and use the `arbitrum:rinkeby` network specifier
// because the configured network has that name
network: 421611
}
})
expect(identifier.provider).toEqual('did:ethr')
expect(identifier.did).toMatch(/^did:ethr:arbitrum:rinkeby:0x.*$/)
expect(identifier.keys.length).toEqual(1)
expect(identifier.services.length).toEqual(0)
expect(identifier.controllerKeyId).toEqual(identifier.keys[0].kid)
Expand Down
20 changes: 10 additions & 10 deletions packages/credential-ld/src/__tests__/issue-verify-flow.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ import { KeyManager, MemoryKeyStore, MemoryPrivateKeyStore } from '../../../key-
import { KeyManagementSystem } from '../../../kms-local/src'
import { getDidKeyResolver, KeyDIDProvider } from '../../../did-provider-key/src'
import { DIDResolverPlugin } from '../../../did-resolver/src'
import { EthrDIDProvider } from "../../../did-provider-ethr/src";
import { EthrDIDProvider } from '../../../did-provider-ethr/src'
import { ContextDoc } from '../types'
import { CredentialIssuerLD } from '../action-handler'
import { LdDefaultContexts } from '../ld-default-contexts'
import { VeramoEd25519Signature2018 } from '../suites/Ed25519Signature2018'
import { Resolver } from 'did-resolver'
import { getResolver as ethrDidResolver } from 'ethr-did-resolver'
import { VeramoEcdsaSecp256k1RecoverySignature2020 } from "../suites/EcdsaSecp256k1RecoverySignature2020";
import { VeramoEcdsaSecp256k1RecoverySignature2020 } from '../suites/EcdsaSecp256k1RecoverySignature2020'

jest.setTimeout(300000)

Expand Down Expand Up @@ -62,7 +62,7 @@ describe('credential-LD full flow', () => {
new DIDResolverPlugin({
resolver: new Resolver({
...getDidKeyResolver(),
...ethrDidResolver({ infuraProjectId, }),
...ethrDidResolver({ infuraProjectId }),
}),
}),
new CredentialIssuer(),
Expand All @@ -73,7 +73,7 @@ describe('credential-LD full flow', () => {
],
})
didKeyIdentifier = await agent.didManagerCreate()
didEthrIdentifier = await agent.didManagerCreate({ provider: "did:ethr:goerli" })
didEthrIdentifier = await agent.didManagerCreate({ provider: 'did:ethr:goerli' })
})

it('works with Ed25519Signature2018 credential', async () => {
Expand Down Expand Up @@ -136,17 +136,17 @@ describe('credential-LD full flow', () => {
const verifiablePresentation = await agent.createVerifiablePresentation({
presentation: {
verifiableCredential: [verifiableCredential1],
holder: didKeyIdentifier.did
holder: didKeyIdentifier.did,
},
challenge: "VERAMO",
challenge: 'VERAMO',
proofFormat: 'lds',
})

expect(verifiablePresentation).toBeDefined()

const verified = await agent.verifyPresentation({
presentation: verifiablePresentation,
challenge: "VERAMO",
challenge: 'VERAMO',
})

expect(verified).toBe(true)
Expand All @@ -171,17 +171,17 @@ describe('credential-LD full flow', () => {
const verifiablePresentation = await agent.createVerifiablePresentation({
presentation: {
verifiableCredential: [verifiableCredential1],
holder: didEthrIdentifier.did
holder: didEthrIdentifier.did,
},
challenge: "VERAMO",
challenge: 'VERAMO',
proofFormat: 'lds',
})

expect(verifiablePresentation).toBeDefined()

const verified = await agent.verifyPresentation({
presentation: verifiablePresentation,
challenge: "VERAMO",
challenge: 'VERAMO',
})

expect(verified).toBe(true)
Expand Down
Loading