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

VDX-88 #54

Merged
merged 16 commits into from
Aug 12, 2022
69 changes: 41 additions & 28 deletions packages/wellknown-did-verifier/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,74 +12,87 @@

---

A `Sphereon SSI-SDK` plugin to verify relationships between the controller of an origin and a DID and to verify DID configuration resources.
A `Sphereon SSI-SDK` plugin to verify relationships between the controller of an origin and a DID conforming to the DIF [spec for well-known DID Configurations](https://identity.foundation/.well-known/resources/did-configuration/) It is written in Typescript and can be compiled to any target JavaScript version.

## Available functions
* registerSignatureValidation
* removeSignatureValidation
* verifyDomainLinkage
* verifyDidConfigurationResource

- registerSignatureValidation
- removeSignatureValidation
- verifyDomainLinkage
- verifyDidConfigurationResource

## Usage

### Adding the plugin to an agent:

```typescript
import {
IWellKnownDidVerifier,
WellKnownDidVerifier
} from '@sphereon/ssi-sdk-wellknown-did-verifier';
import { IWellKnownDidVerifier, WellKnownDidVerifier } from '@sphereon/ssi-sdk-wellknown-did-verifier'

const agent = createAgent<IWellKnownDidVerifier>({
plugins: [
new WellKnownDidVerifier({
signatureVerifications: {'verified': () => Promise.resolve({ verified: true })},
onlyVerifyServiceDids: true
signatureVerifications: { verified: () => Promise.resolve({ verified: true }) },
onlyVerifyServiceDids: true,
}),
],
})
```

### Register signature verification callback:

nklomp marked this conversation as resolved.
Show resolved Hide resolved
Registers a callback function to be called within the verification process, to verify the signature of the credentials within the DID configuration resource.

```typescript
agent.registerSignatureVerification({
key: 'example_key',
signatureVerification: () => Promise.resolve({ verified: true })
})
agent
.registerSignatureVerification({
signatureVerificationKey: 'example_key',
signatureVerification: () => Promise.resolve({ verified: true }),
})
.then(() => console.log('success'))
.catch(() => console.log('failed'))
```

### Remove signature verification callback:

nklomp marked this conversation as resolved.
Show resolved Hide resolved
Removes a registered callback function.

```typescript
agent.removeSignatureVerification({ key: 'example_key' })
agent
.removeSignatureVerification({ signatureVerificationKey: 'example_key' })
.then(() => console.log('success'))
.catch(() => console.log('failed'))
```

### Verify domain linkage:

nklomp marked this conversation as resolved.
Show resolved Hide resolved
Verifies the relationship between the controller of an origin and a given DID.
Option available to only verify the service DID.

```typescript
agent.verifyDomainLinkage({
didUrl: 'did:key:z6MkoTHsgNNrby8JzCNQ1iRLyW5QQ6R8Xuu6AA8igGrMVPUM#foo',
signatureVerification: 'verified',
onlyVerifyServiceDids: false
})
.then((result: IDomainLinkageValidation) => console.log(result.status))
agent
.verifyDomainLinkage({
didUrl: 'did:key:z6MkoTHsgNNrby8JzCNQ1iRLyW5QQ6R8Xuu6AA8igGrMVPUM#foo',
signatureVerification: 'verified',
onlyVerifyServiceDids: false,
})
.then((result: IDomainLinkageValidation) => console.log(result.status))
```

### Verify DID configuration resource:

You can either pass in a DID configuration resource or fetch it remotely by setting a secure well-known location (origin).
Verifies a DID configuration resource and domain linkage credentials it holds.

You can either pass in a DID configuration resource or fetch it remotely by setting a secure well-known location (origin).
Option available to only verify a given DID.

```typescript
agent.verifyDidConfigurationResource({
signatureVerification: () => Promise.resolve({ verified: true }),
origin: 'https://example.com'
})
.then((result: IResourceValidation) => console.log(result.status))
agent
.verifyDidConfigurationResource({
signatureVerification: () => Promise.resolve({ verified: true }),
origin: 'https://example.com',
did: 'did:key:z6MkoTHsgNNrby8JzCNQ1iRLyW5QQ6R8Xuu6AA8igGrMVPUM#foo',
})
.then((result: IResourceValidation) => console.log(result.status))
```

## Installation
Expand Down
22 changes: 11 additions & 11 deletions packages/wellknown-did-verifier/__tests__/localAgent.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,18 @@ const setup = async (): Promise<boolean> => {
const config = getConfig('packages/wellknown-did-verifier/agent.yml')
const { localAgent } = createObjects(config, { localAgent: '/agent' })

await localAgent.registerSignatureVerification({
key: 'verified',
signatureVerification: () => Promise.resolve({ verified: true })
}, null)
await localAgent.registerSignatureVerification(
{
signatureVerificationKey: 'verified',
signatureVerification: () => Promise.resolve({ verified: true }),
},
null
)

const DID = 'did:key:z6MkoTHsgNNrby8JzCNQ1iRLyW5QQ6R8Xuu6AA8igGrMVPUM';
const ORIGIN = 'https://example.com';
const DID = 'did:key:z6MkoTHsgNNrby8JzCNQ1iRLyW5QQ6R8Xuu6AA8igGrMVPUM'
const ORIGIN = 'https://example.com'
const DOCUMENT = {
'@context': [
'https://www.w3.org/ns/did/v1',
'https://identity.foundation/.well-known/did-configuration/v1'
],
'@context': ['https://www.w3.org/ns/did/v1', 'https://identity.foundation/.well-known/did-configuration/v1'],
id: DID,
verificationMethod: [
{
Expand Down Expand Up @@ -50,7 +50,7 @@ const setup = async (): Promise<boolean> => {
serviceEndpoint: ORIGIN,
},
],
};
}

localAgent.resolveDid = jest.fn().mockReturnValue(Promise.resolve({ didDocument: DOCUMENT }))

Expand Down
24 changes: 12 additions & 12 deletions packages/wellknown-did-verifier/__tests__/restAgent.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { AgentRestClient } from '@veramo/remote-client'
import { AgentRouter, RequestWithAgentRouter } from '@veramo/remote-server'
import { getConfig } from '@veramo/cli/build/setup'
import { createObjects } from '@veramo/cli/build/lib/objectCreator'
import { IWellKnownDidVerifier } from '../src/types/IWellKnownDidVerifier';
import { IWellKnownDidVerifier } from '../src/types/IWellKnownDidVerifier'
import { ServiceTypesEnum } from '@sphereon/wellknown-dids-client/dist/types'
import wellKnownDidVerifierAgentLogic from './shared/wellKnownDidVerifierAgentLogic'

Expand Down Expand Up @@ -35,18 +35,18 @@ const setup = async (): Promise<boolean> => {
const config = getConfig('packages/wellknown-did-verifier/agent.yml')
const { agent } = createObjects(config, { agent: '/agent' })

await agent.registerSignatureVerification({
key: 'verified',
signatureVerification: () => Promise.resolve({ verified: true })
}, null)
await agent.registerSignatureVerification(
{
signatureVerificationKey: 'verified',
signatureVerification: () => Promise.resolve({ verified: true }),
},
null
)

const DID = 'did:key:z6MkoTHsgNNrby8JzCNQ1iRLyW5QQ6R8Xuu6AA8igGrMVPUM';
const ORIGIN = 'https://example.com';
const DID = 'did:key:z6MkoTHsgNNrby8JzCNQ1iRLyW5QQ6R8Xuu6AA8igGrMVPUM'
const ORIGIN = 'https://example.com'
const DOCUMENT = {
'@context': [
'https://www.w3.org/ns/did/v1',
'https://identity.foundation/.well-known/did-configuration/v1'
],
'@context': ['https://www.w3.org/ns/did/v1', 'https://identity.foundation/.well-known/did-configuration/v1'],
id: DID,
verificationMethod: [
{
Expand Down Expand Up @@ -74,7 +74,7 @@ const setup = async (): Promise<boolean> => {
serviceEndpoint: ORIGIN,
},
],
};
}

agent.resolveDid = jest.fn().mockReturnValue(Promise.resolve({ didDocument: DOCUMENT }))
nklomp marked this conversation as resolved.
Show resolved Hide resolved

Expand Down
Loading