Skip to content

Commit

Permalink
Merge f64690c into 701b8ed
Browse files Browse the repository at this point in the history
  • Loading branch information
dchagastelles authored Nov 29, 2022
2 parents 701b8ed + f64690c commit 32336b2
Show file tree
Hide file tree
Showing 22 changed files with 614 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,5 @@ temp
agent.yml
data
.vscode-upload.json

local-database*.json
5 changes: 5 additions & 0 deletions __tests__/localAgent.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import {
import { EthrDIDProvider } from '../packages/did-provider-ethr/src'
import { WebDIDProvider } from '../packages/did-provider-web/src'
import { getDidKeyResolver, KeyDIDProvider } from '../packages/did-provider-key/src'
import { getDidPkhResolver, PkhDIDProvider } from '../packages/did-provider-pkh/src'
import { DIDComm, DIDCommHttpTransport, DIDCommMessageHandler, IDIDComm } from '../packages/did-comm/src'
import {
ISelectiveDisclosure,
Expand Down Expand Up @@ -193,6 +194,9 @@ const setup = async (options?: IAgentOptions): Promise<boolean> => {
'did:key': new KeyDIDProvider({
defaultKms: 'local',
}),
'did:pkh': new PkhDIDProvider({
defaultKms: 'local',
}),
'did:fake': new FakeDidProvider(),
},
}),
Expand All @@ -210,6 +214,7 @@ const setup = async (options?: IAgentOptions): Promise<boolean> => {
}),
...webDidResolver(),
...getDidKeyResolver(),
...getDidPkhResolver(),
...new FakeDidResolver(() => agent).getDidFakeResolver(),
}),
new DataStore(dbConnection),
Expand Down
5 changes: 5 additions & 0 deletions __tests__/localJsonStoreAgent.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import {
import { EthrDIDProvider } from '../packages/did-provider-ethr/src'
import { WebDIDProvider } from '../packages/did-provider-web/src'
import { getDidKeyResolver, KeyDIDProvider } from '../packages/did-provider-key/src'
import { getDidPkhResolver, PkhDIDProvider } from '../packages/did-provider-pkh/src'
import { DIDComm, DIDCommMessageHandler, IDIDComm } from '../packages/did-comm/src'
import {
ISelectiveDisclosure,
Expand Down Expand Up @@ -157,6 +158,9 @@ const setup = async (options?: IAgentOptions): Promise<boolean> => {
'did:key': new KeyDIDProvider({
defaultKms: 'local',
}),
'did:pkh': new PkhDIDProvider({
defaultKms: 'local',
}),
'did:fake': new FakeDidProvider(),
},
}),
Expand All @@ -165,6 +169,7 @@ const setup = async (options?: IAgentOptions): Promise<boolean> => {
...ethrDidResolver({ infuraProjectId }),
...webDidResolver(),
...getDidKeyResolver(),
...getDidPkhResolver(),
...new FakeDidResolver(() => agent).getDidFakeResolver(),
}),
}),
Expand Down
5 changes: 5 additions & 0 deletions __tests__/localMemoryStoreAgent.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import {
import { EthrDIDProvider } from '../packages/did-provider-ethr/src'
import { WebDIDProvider } from '../packages/did-provider-web/src'
import { getDidKeyResolver, KeyDIDProvider } from '../packages/did-provider-key/src'
import { getDidPkhResolver, PkhDIDProvider } from '../packages/did-provider-pkh/src'
import { DIDComm, DIDCommMessageHandler, IDIDComm } from '../packages/did-comm/src'
import {
ISelectiveDisclosure,
Expand Down Expand Up @@ -155,6 +156,9 @@ const setup = async (options?: IAgentOptions): Promise<boolean> => {
'did:key': new KeyDIDProvider({
defaultKms: 'local',
}),
'did:pkh': new PkhDIDProvider({
defaultKms: 'local',
}),
'did:fake': new FakeDidProvider(),
},
}),
Expand All @@ -163,6 +167,7 @@ const setup = async (options?: IAgentOptions): Promise<boolean> => {
...ethrDidResolver({ infuraProjectId }),
...webDidResolver(),
...getDidKeyResolver(),
...getDidPkhResolver(),
...new FakeDidResolver(() => agent).getDidFakeResolver(),
}),
}),
Expand Down
5 changes: 5 additions & 0 deletions __tests__/restAgent.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ import {
import { EthrDIDProvider } from '../packages/did-provider-ethr/src'
import { WebDIDProvider } from '../packages/did-provider-web/src'
import { getDidKeyResolver, KeyDIDProvider } from '../packages/did-provider-key/src'
import { getDidPkhResolver, PkhDIDProvider } from '../packages/did-provider-pkh/src'
import { DIDComm, DIDCommHttpTransport, DIDCommMessageHandler, IDIDComm } from '../packages/did-comm/src'
import {
ISelectiveDisclosure,
Expand Down Expand Up @@ -184,6 +185,9 @@ const setup = async (options?: IAgentOptions): Promise<boolean> => {
'did:key': new KeyDIDProvider({
defaultKms: 'local',
}),
'did:pkh': new PkhDIDProvider({
defaultKms: 'local',
}),
'did:fake': new FakeDidProvider(),
},
}),
Expand All @@ -193,6 +197,7 @@ const setup = async (options?: IAgentOptions): Promise<boolean> => {
...webDidResolver(),
// key: getUniversalResolver(), // resolve using remote resolver... when uniresolver becomes more stable,
...getDidKeyResolver(),
...getDidPkhResolver(),
...new FakeDidResolver(() => serverAgent as TAgent<IDIDManager>).getDidFakeResolver(),
}),
}),
Expand Down
13 changes: 13 additions & 0 deletions __tests__/shared/didManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,19 @@ export default (testContext: {
expect(identifier.controllerKeyId).toEqual(identifier.keys[0].kid)
})

it('should create pkh identifier using did:pkh provider', async () => {
identifier = await agent.didManagerCreate({
// this expects the `did:ethr` provider to matchPrefix and use the `arbitrum:goerli` network specifier
provider: 'did:pkh',
options: { chainId: "1"}
})
expect(identifier.provider).toEqual('did:pkh')
//expect(identifier.did).toMatch(/^did:pkh:eip155:*$/)
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 did:ethr:arbitrum:goerli provider', async () => {
identifier = await agent.didManagerCreate({
// this expects the `did:ethr` provider to matchPrefix and use the `arbitrum:goerli` network specifier
Expand Down
17 changes: 17 additions & 0 deletions __tests__/shared/resolveDid.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// noinspection ES6PreferShortImport

import { IIdentifier } from '@veramo/core'
import { IAgentOptions, IDIDManager, IResolver, TAgent } from '../../packages/core/src'

type ConfiguredAgent = TAgent<IResolver & IDIDManager>
Expand Down Expand Up @@ -34,6 +35,22 @@ export default (testContext: {
expect(result).toHaveProperty('didResolutionMetadata')
})

it('should resolve did:pkh', async () => {
let identifier: IIdentifier = await agent.didManagerCreate({
// this expects the `did:ethr` provider to matchPrefix and use the `arbitrum:goerli` network specifier
provider: 'did:pkh',
options: { chainId: "1"}
});

const result = await agent.resolveDid({ didUrl: identifier.did});
const didDoc = result.didDocument
expect(didDoc?.id).toEqual(identifier.did)
expect(result).toHaveProperty('didDocumentMetadata')
expect(result).toHaveProperty('didResolutionMetadata')

//let cred = await agent.createVerifiableCredential()
});

it('should resolve imported fake did', async () => {
const did = 'did:fake:myfakedid'
await agent.didManagerImport({
Expand Down
32 changes: 32 additions & 0 deletions __tests__/shared/verifiableDataLD.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ export default (testContext: {
let agent: ConfiguredAgent
let didEthrIdentifier: IIdentifier
let didKeyIdentifier: IIdentifier
let pkhIdentifier: IIdentifier
let storedCredentialHash: string
let storedPkhCredentialHash: string
let challenge: string

beforeAll(async () => {
Expand All @@ -35,6 +37,7 @@ export default (testContext: {
challenge = 'TEST_CHALLENGE_STRING'
didEthrIdentifier = await agent.didManagerCreate({ kms: 'local', provider: 'did:ethr' })
didKeyIdentifier = await agent.didManagerCreate({ kms: 'local', provider: 'did:key' })
pkhIdentifier = await agent.didManagerCreate({ kms: 'local', provider: "did:pkh", options: { chainId: "1"} })
})
afterAll(testContext.tearDown)

Expand Down Expand Up @@ -257,6 +260,35 @@ export default (testContext: {
expect(result.verified).toEqual(true)
})

it('should create verifiable credential in LD with did:pkh', async () => {
const verifiableCredential = await agent.createVerifiableCredential({
credential: {
issuer: { id: pkhIdentifier.did },
'@context': ['https://www.w3.org/2018/credentials/v1', 'https://veramo.io/contexts/profile/v1'],
type: ['VerifiableCredential', 'Profile'],
issuanceDate: new Date().toISOString(),
credentialSubject: {
id: pkhIdentifier.did,
name: 'Martin, the great',
},
},
proofFormat: 'lds',
})

// Check credential:
expect(verifiableCredential).toHaveProperty('proof')
expect(verifiableCredential).toHaveProperty('proof.jws')
expect(verifiableCredential['type']).toEqual(['VerifiableCredential', 'Profile'])

storedPkhCredentialHash = await agent.dataStoreSaveVerifiableCredential({ verifiableCredential })
expect(typeof storedPkhCredentialHash).toEqual('string')

const verifiableCredential2 = await agent.dataStoreGetVerifiableCredential({
hash: storedPkhCredentialHash,
})
expect(verifiableCredential).toEqual(verifiableCredential2)
})

describe('credential verification policies', () => {
it('can verify credential at a particular time', async () => {
const issuanceDate = '2019-08-19T09:15:20.000Z' // 1566206120
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
"rimraf": "3.0.2",
"semantic-release": "19.0.3",
"ts-jest": "28.0.4",
"caip": "^1.1.0",
"ts-json-schema-generator": "1.1.2",
"ts-node": "10.9.1",
"typescript": "4.9.3"
Expand Down
1 change: 1 addition & 0 deletions packages/credential-ld/src/action-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,7 @@ export class CredentialIssuerLD implements IAgentPlugin {
signingKey = extendedKeys.find((k) => supportedTypes.includes(k.meta.verificationMethod.type))
}


if (!signingKey) throw Error(`key_not_found: No suitable signing key found for ${identifier.did}`)
verificationMethodId = signingKey.meta.verificationMethod.id
return { signingKey, verificationMethodId }
Expand Down
Loading

0 comments on commit 32336b2

Please sign in to comment.