-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: implement vc api verifier router
Signed-off-by: toanNgo <toan.ngo@gosource.com.au>
- Loading branch information
toanNgo
committed
Jun 23, 2023
1 parent
100b35d
commit c0617b9
Showing
12 changed files
with
494 additions
and
147 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,90 @@ | ||
# vc-api agent router | ||
# vc-api | ||
|
||
- This agent router conform to vc-api standard that to achieve interoperability's goal between various parties. | ||
- This agent router conform to vc-api standard that to achieve interoperbaility’s goal between various parties. | ||
|
||
## Usage | ||
|
||
- This plugin follow the `veramo` architecture , so you can configure it with `agent.yml` | ||
- This plugin follow the `veramo` architecture , so you can configure it with `agent.yml` . For example: | ||
|
||
```jsx | ||
# API base path | ||
- - /issuer | ||
- $require: '@vckit/vc-api-issuer?t=function#AgentRouter' | ||
|
||
- - /vc-api | ||
- $require: '@vckit/vc-api?t=function#IssuerRouter' | ||
$args: | ||
- createCredential: createVerifiableCredential | ||
updateCredentialStatus: updateVerifiableCredentialStatus | ||
config: | ||
proofFormat: OpenAttestationMerkleProofSignature2018 | ||
save: false | ||
- $require: '@vckit/vc-api?t=function#VerifierRouter' | ||
$args: | ||
- verifyCredential: verifyCredential | ||
verifyPresentation: verifyPresentation | ||
``` | ||
|
||
## Test with test-suite | ||
|
||
- Clone the test suite: https://github.com/w3c-ccg/vc-api-issuer-test-suite | ||
- Go to `node_modules/vc-api-test-suite-implementations/implementations` , create files except the index file | ||
- Clone the test suite: https://github.com/w3c-ccg/vc-api-issuer-test-suite and https://github.com/w3c-ccg/vc-api-verifier-test-suite | ||
|
||
```jsx | ||
{ | ||
"name": "GoSource", | ||
"implementation": "GoSource Verifiable Credentials", | ||
"issuers": [{ | ||
"id": "YOUR_DID_MANAGED_BY_YOUR_MKS", | ||
"endpoint": "http://localhost:3332/issuer/credentials/issue", | ||
"tags": ["vc-api", "Ed25519Signature2020"] | ||
}], | ||
"verifiers": [{ | ||
"id": "YOUR_DID_MANAGED_BY_YOUR_MKS", | ||
"endpoint": "http://localhost:3332/verifier/credentials/verify", | ||
"method": "POST", | ||
"tags": ["vc-api"] | ||
}] | ||
} | ||
``` | ||
|
||
- Create new implementation file: | ||
|
||
```jsx | ||
{ | ||
"name": "GoSource", | ||
"implementation": "GoSource Verifiable Credentials", | ||
"issuers": [{ | ||
"id": "YOUR_DID_MANAGED_BY_YOUR_KMS", | ||
"endpoint": "http://localhost:3332/agent/credentials/issue", | ||
"options": { | ||
"type": "Ed25519Signature2020" | ||
}, | ||
"tags": ["vc-api", "Ed25519Signature2020"] | ||
}] | ||
} | ||
``` | ||
|
||
- Run the test command `npm run test` | ||
- Test result | ||
- Issuer test result | ||
|
||
```jsx | ||
✓ MUST successfully issue a credential. | ||
✓ Request body MUST have property "credential". | ||
✓ credential MUST have property "@context". | ||
✓ credential "@context" MUST be an array. | ||
✓ credential "@context" items MUST be strings. | ||
✓ credential MUST have property "type" | ||
✓ "credential.type" MUST be an array. | ||
✓ "credential.type" items MUST be strings | ||
✓ credential MUST have property "issuer" | ||
✓ "credential.issuer" MUST be a string or an object | ||
✓ credential MUST have property "credentialSubject" | ||
✓ "credential.credentialSubject" MUST be an object | ||
✓ credential MAY have property "expirationDate" | ||
``` | ||
|
||
- Verifier test result | ||
|
||
```jsx | ||
✓ MUST verify a valid VC. | ||
✓ MUST not verify if "@context" property is missing. | ||
✓ MUST not verify if "type" property is missing. | ||
✓ MUST not verify if "issuer" property is missing. | ||
✓ MUST not verify if "credentialSubject" property is missing. | ||
✓ MUST not verify if "proof" property is missing. | ||
✓ MUST not verify if "proof.type" property is missing. | ||
✓ MUST not verify if "proof.created" property is missing. | ||
✓ MUST not verify if "proof.verificationMethod" property is missing. | ||
✓ MUST not verify if "proof.proofValue" property is missing. | ||
✓ MUST not verify if "proof.proofPurpose" property is missing. | ||
✓ MUST not verify if "@context" is not an array. | ||
✓ MUST not verify if "@context" items are not strings. | ||
✓ MUST not verify if "type" is not an array. | ||
✓ MUST not verify if "type" items are not strings. | ||
✓ MUST not verify if "issuer" is not an object or a string. | ||
✓ MUST not verify if "credentialSubject" is not an object. | ||
✓ MUST not verify if "proof" is not an object. | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
export { IssuerRouter, IssuerRouterOptions } from './issuer-router.js' | ||
export { VerifierRouter, VerifierRouterOptions } from './verifier-router.js' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
export * from './issuer.js' | ||
export * from './verifier.js' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,160 @@ | ||
import { check, oneOf } from 'express-validator'; | ||
|
||
/** | ||
* Validate the input for verifying credential that use vc-kit. | ||
*/ | ||
|
||
export const validateVerifyCredentialRequest = () => { | ||
return [ | ||
check('verifiableCredential').isObject().notEmpty(), | ||
...validateContext(), | ||
...validateIssuer(), | ||
...validateCredentialSubject(), | ||
...validateType(), | ||
...validateProof(), | ||
...validateOptions(), | ||
]; | ||
}; | ||
|
||
export const validateVerifyPresentationRequest = () => { | ||
return [ | ||
check('verifiablePresentation').isObject().notEmpty(), | ||
...validateOptions(), | ||
check('options.verificationMethod', 'options.domain must be a string') | ||
.isString() | ||
.notEmpty(), | ||
check('options.proofPurpose', 'options.domain must be a string') | ||
.isString() | ||
.notEmpty(), | ||
]; | ||
}; | ||
|
||
const validateProof = () => { | ||
return [ | ||
check('verifiableCredential.proof').isObject().notEmpty(), | ||
check( | ||
'verifiableCredential.proof.type', | ||
'verifiableCredential.proof.type must be a string' | ||
) | ||
.isString() | ||
.notEmpty(), | ||
check( | ||
'verifiableCredential.proof.created', | ||
'verifiableCredential.proof.created must be a string' | ||
) | ||
.isString() | ||
.notEmpty(), | ||
check( | ||
'verifiableCredential.proof.challenge', | ||
'verifiableCredential.proof.challenge must be a string' | ||
) | ||
.optional() | ||
.isString() | ||
.notEmpty(), | ||
check( | ||
'verifiableCredential.proof.domain', | ||
'verifiableCredential.proof.domain must be a string' | ||
) | ||
.optional() | ||
.isString() | ||
.notEmpty(), | ||
check( | ||
'verifiableCredential.proof.nonce', | ||
'verifiableCredential.proof.nonce must be a string' | ||
) | ||
.optional() | ||
.isString() | ||
.notEmpty(), | ||
check( | ||
'verifiableCredential.proof.verificationMethod', | ||
'verifiableCredential.proof.verificationMethod must be a string' | ||
) | ||
.isString() | ||
.notEmpty(), | ||
check( | ||
'verifiableCredential.proof.proofPurpose', | ||
'verifiableCredential.proof.proofPurpose must be a string' | ||
) | ||
.isString() | ||
.notEmpty(), | ||
check( | ||
'verifiableCredential.proof.jws', | ||
'verifiableCredential.proof.jws must be a string' | ||
) | ||
.optional() | ||
.isString() | ||
.notEmpty(), | ||
check( | ||
'verifiableCredential.proof.proofValue', | ||
'verifiableCredential.proof.proofValue must be a string' | ||
) | ||
.isString() | ||
.notEmpty(), | ||
]; | ||
}; | ||
|
||
const validateContext = () => { | ||
return [ | ||
check( | ||
'verifiableCredential.@context', | ||
'verifiableCredential.@context must be an array' | ||
).isArray({ min: 1 }), | ||
check( | ||
'verifiableCredential.@context.*', | ||
'verifiableCredential.@context item must be string' | ||
) | ||
.isString() | ||
.notEmpty(), | ||
]; | ||
}; | ||
|
||
const validateIssuer = () => { | ||
return [ | ||
oneOf( | ||
[ | ||
check('verifiableCredential.issuer').isObject().notEmpty(), | ||
check('verifiableCredential.issuer').isString().notEmpty(), | ||
], | ||
{ message: 'verifiableCredential.issuer must be string or an object' } | ||
), | ||
]; | ||
}; | ||
|
||
const validateCredentialSubject = () => { | ||
return [ | ||
check( | ||
'verifiableCredential.credentialSubject', | ||
'verifiableCredential.credentialSubject must be an object' | ||
) | ||
.isObject() | ||
.notEmpty(), | ||
]; | ||
}; | ||
|
||
const validateType = () => { | ||
return [ | ||
check( | ||
'verifiableCredential.type', | ||
'verifiableCredential.@type must be an array' | ||
).isArray({ min: 1 }), | ||
check( | ||
'verifiableCredential.type.*', | ||
'verifiableCredential.@type item must be string' | ||
) | ||
.isString() | ||
.notEmpty(), | ||
]; | ||
}; | ||
|
||
const validateOptions = () => { | ||
return [ | ||
check('options.domain', 'options.domain must be a string') | ||
.optional() | ||
.isString() | ||
.notEmpty(), | ||
check('options.challenge', 'options.created must be a string') | ||
.optional() | ||
.isString() | ||
.notEmpty(), | ||
]; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.