Skip to content

Commit

Permalink
refactor(did-resolver): rename dereferenceDidUri to `getDIDComponen…
Browse files Browse the repository at this point in the history
…tById`
  • Loading branch information
mirceanis committed Jun 22, 2021
1 parent 5f0eb7e commit 5ca3d15
Show file tree
Hide file tree
Showing 13 changed files with 159 additions and 171 deletions.
4 changes: 2 additions & 2 deletions __tests__/shared/documentationExamples.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ export default (testContext: {

//DO NOT EDIT MANUALLY START

it('core-IResolver-dereferenceDidUri example', async () => {
it('core-IResolver-getDIDComponentById example', async () => {
const did = 'did:ethr:rinkeby:0xb09b66026ba5909a7cfe99b76875431d2b8d5190'
const didFragment = `${did}#controller`
const fragment = await agent.dereferenceDidUri({
const fragment = await agent.getDIDComponentById({
didDocument: (await agent.resolveDid({ didUrl: did }))?.didDocument,
didURI: didFragment,
section: 'authentication',
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"test:watch": "yarn test --watch --verbose",
"veramo": "./packages/cli/bin/veramo.js",
"prettier": "prettier --write '{packages,__tests__, !build}/**/*.{ts,js,json,md,yml}'",
"build-clean": "rimraf ./packages/*/build ./packages/*/node_modules ./packages/*/tsconfig.tsbuildinfo && jest --clearCache",
"build-clean": "rimraf ./packages/*/build ./packages/*/api ./packages/*/node_modules ./packages/*/tsconfig.tsbuildinfo && jest --clearCache",
"publish:latest": "lerna publish --conventional-commits --include-merged-tags --create-release github --yes --dist-tag latest --registry https://registry.npmjs.org/:_authToken=${NPM_TOKEN}",
"publish:next": "lerna publish --conventional-prerelease --force-publish --canary --no-git-tag-version --include-merged-tags --preid next --pre-dist-tag next --yes --registry https://registry.npmjs.org/:_authToken=${NPM_TOKEN}",
"publish:unstable": "lerna publish --conventional-prerelease --force-publish --canary --no-git-tag-version --include-merged-tags --preid unstable --pre-dist-tag unstable --yes --registry https://registry.npmjs.org/:_authToken=${NPM_TOKEN}"
Expand Down
6 changes: 0 additions & 6 deletions packages/cli/src/dev.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,6 @@ function createSchema(generator: TJS.SchemaGenerator, symbol: string) {

const schema = generator.createSchema(fixedSymbol)

if (fixedSymbol === 'ICreateVerifiableCredentialArgs') {
//@ts-ignore
schema.definitions['W3CCredential']['properties']['credentialSubject']['additionalProperties'] = true
}
// console.dir({ fixedSymbol, schema }, {depth: 10})

const newSchema = {
components: {
schemas: schema.definitions,
Expand Down
12 changes: 6 additions & 6 deletions packages/core/src/types/IResolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,15 +67,15 @@ export interface IResolver extends IPluginMethodMap {
resolveDid(args: ResolveDidArgs): Promise<DIDResolutionResult>

/**
* Dereference a DID URI fragment and return the corresponding DID document entry.
* Dereferences a DID URI fragment and return the corresponding DID document entry.
*
* @example
* ```typescript
* const did = 'did:ethr:rinkeby:0xb09b66026ba5909a7cfe99b76875431d2b8d5190'
* const didFragment = `${did}#controller`
* const fragment = await agent.dereferenceDidUri({
* const fragment = await agent.getDIDComponentById({
* didDocument: (await agent.resolveDid({didUrl: did}))?.didDocument,
* didURI: didFragment,
* didUrl: didFragment,
* section: 'authentication'
* })
* expect(fragment).toEqual({
Expand All @@ -88,7 +88,7 @@ export interface IResolver extends IPluginMethodMap {
*
* @param args.didDocument - the DID document from which to extract the fragment.
* This MUST be the document resolved by {@link resolveDid}
* @param args.didURI - the DID URI that needs to be dereferenced
* @param args.didUrl - the DID URI that needs to be dereferenced
* @param args.section - Optional - the section of the DID Document to be used for dereferencing
*
* @returns a `Promise` containing the {@link did-resolver#VerificationMethod | VerificationMethod} or
Expand All @@ -98,15 +98,15 @@ export interface IResolver extends IPluginMethodMap {
*
* @beta
*/
dereferenceDidUri(args: {
getDIDComponentById(args: {
/**
* the DID document from which to extract the fragment. This MUST be the document resolved by {@link resolveDid}
*/
didDocument: DIDDocument
/**
* The DID URI that refers to the subsection by #fragment. Example: did:example:identifier#controller
*/
didURI: string
didUrl: string
/**
* The section of the DID document where to search for the fragment. Example 'keyAgreement'
*/
Expand Down
248 changes: 121 additions & 127 deletions packages/credential-w3c/plugin.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,92 +6,88 @@
"type": "object",
"properties": {
"credential": {
"$ref": "#/components/schemas/W3CCredential",
"description": "The json payload of the Credential according to the {@link https://www.w3.org/TR/vc-data-model/#credentials | canonical model}\n\nThe signer of the Credential is chosen based on the `issuer.id` property of the `credential`"
},
"save": {
"type": "boolean",
"description": "If this parameter is true, the resulting VerifiablePresentation is sent to the {@link @veramo/core#IDataStore | storage plugin} to be saved"
},
"proofFormat": {
"$ref": "#/components/schemas/EncodingFormat",
"description": "The desired format for the VerifiablePresentation to be created. Currently, only JWT is supported"
}
},
"required": [
"credential",
"proofFormat"
],
"description": "Encapsulates the parameters required to create a {@link https://www.w3.org/TR/vc-data-model/#credentials | W3C Verifiable Credential}"
},
"W3CCredential": {
"type": "object",
"properties": {
"@context": {
"type": "array",
"items": {
"type": "string"
}
},
"id": {
"type": "string"
},
"type": {
"type": "array",
"items": {
"type": "string"
}
},
"issuer": {
"type": "object",
"properties": {
"id": {
"type": "string"
}
},
"required": [
"id"
]
},
"issuanceDate": {
"type": "string"
},
"expirationDate": {
"type": "string"
},
"credentialSubject": {
"type": "object",
"properties": {
"id": {
"type": "string"
}
},
"additionalProperties": true
},
"credentialStatus": {
"type": "object",
"properties": {
"@context": {
"type": "array",
"items": {
"type": "string"
}
},
"id": {
"type": "string"
},
"type": {
"type": "array",
"items": {
"type": "string"
}
},
"issuer": {
"type": "object",
"properties": {
"id": {
"type": "string"
}
},
"required": [
"id"
]
},
"issuanceDate": {
"type": "string"
},
"expirationDate": {
"type": "string"
},
"credentialSubject": {
"type": "object",
"properties": {
"id": {
"type": "string"
}
}
},
"credentialStatus": {
"type": "object",
"properties": {
"id": {
"type": "string"
},
"type": {
"type": "string"
}
},
"required": [
"id",
"type"
]
}
},
"required": [
"id",
"type"
]
"issuer",
"credentialSubject"
],
"description": "The json payload of the Credential according to the\n {@link https://www.w3.org/TR/vc-data-model/#credentials | canonical model } \n\nThe signer of the Credential is chosen based on the `issuer.id` property of the `credential`\n\n'@context', 'type' and 'issuanceDate' will be added automatically if omitted"
},
"save": {
"type": "boolean",
"description": "If this parameter is true, the resulting VerifiablePresentation is sent to the\n {@link @veramo/core#IDataStore | storage plugin } to be saved"
},
"proofFormat": {
"$ref": "#/components/schemas/EncodingFormat",
"description": "The desired format for the VerifiablePresentation to be created. Currently, only JWT is supported"
},
"removeOriginalFields": {
"type": "boolean",
"description": "Remove payload members during JWT-JSON transformation. Defaults to `true`. See https://www.w3.org/TR/vc-data-model/#jwt-encoding"
}
},
"required": [
"@context",
"type",
"issuer",
"issuanceDate",
"credentialSubject"
"credential",
"proofFormat"
],
"description": "W3CCredential {@link https://github.com/decentralized-identifier/did-jwt-vc}"
"description": "Encapsulates the parameters required to create a\n {@link https://www.w3.org/TR/vc-data-model/#credentials | W3C Verifiable Credential }"
},
"EncodingFormat": {
"type": "string",
Expand Down Expand Up @@ -173,78 +169,76 @@
"credentialSubject",
"proof"
],
"description": "Verifiable Credential {@link https://github.com/decentralized-identifier/did-jwt-vc}"
"description": "Verifiable Credential {@link https://github.com/decentralized-identifier/did-jwt-vc }"
},
"ICreateVerifiablePresentationArgs": {
"type": "object",
"properties": {
"presentation": {
"$ref": "#/components/schemas/W3CPresentation",
"description": "The json payload of the Presentation according to the {@link https://www.w3.org/TR/vc-data-model/#presentations | canonical model}.\n\nThe signer of the Presentation is chosen based on the `holder` property of the `presentation`"
"type": "object",
"properties": {
"id": {
"type": "string"
},
"holder": {
"type": "string"
},
"issuanceDate": {
"type": "string"
},
"expirationDate": {
"type": "string"
},
"@context": {
"type": "array",
"items": {
"type": "string"
}
},
"type": {
"type": "array",
"items": {
"type": "string"
}
},
"verifier": {
"type": "array",
"items": {
"type": "string"
}
},
"verifiableCredential": {
"type": "array",
"items": {
"$ref": "#/components/schemas/VerifiableCredential"
}
}
},
"required": [
"holder",
"verifier",
"verifiableCredential"
],
"description": "The json payload of the Presentation according to the\n {@link https://www.w3.org/TR/vc-data-model/#presentations | canonical model } .\n\nThe signer of the Presentation is chosen based on the `holder` property of the `presentation`\n\n'@context', 'type' and 'issuanceDate' will be added automatically if omitted"
},
"save": {
"type": "boolean",
"description": "If this parameter is true, the resulting VerifiablePresentation is sent to the {@link @veramo/core#IDataStore | storage plugin} to be saved"
"description": "If this parameter is true, the resulting VerifiablePresentation is sent to the\n {@link @veramo/core#IDataStore | storage plugin } to be saved"
},
"proofFormat": {
"$ref": "#/components/schemas/EncodingFormat",
"description": "The desired format for the VerifiablePresentation to be created. Currently, only JWT is supported"
},
"removeOriginalFields": {
"type": "boolean",
"description": "Remove payload members during JWT-JSON transformation. Defaults to `true`. See https://www.w3.org/TR/vc-data-model/#jwt-encoding"
}
},
"required": [
"presentation",
"proofFormat"
],
"description": "Encapsulates the parameters required to create a {@link https://www.w3.org/TR/vc-data-model/#presentations | W3C Verifiable Presentation}"
},
"W3CPresentation": {
"type": "object",
"properties": {
"id": {
"type": "string"
},
"holder": {
"type": "string"
},
"issuanceDate": {
"type": "string"
},
"expirationDate": {
"type": "string"
},
"@context": {
"type": "array",
"items": {
"type": "string"
}
},
"type": {
"type": "array",
"items": {
"type": "string"
}
},
"verifier": {
"type": "array",
"items": {
"type": "string"
}
},
"verifiableCredential": {
"type": "array",
"items": {
"$ref": "#/components/schemas/VerifiableCredential"
}
}
},
"required": [
"holder",
"@context",
"type",
"verifier",
"verifiableCredential"
],
"description": "W3CPresentation {@link https://github.com/decentralized-identifier/did-jwt-vc}"
"description": "Encapsulates the parameters required to create a\n {@link https://www.w3.org/TR/vc-data-model/#presentations | W3C Verifiable Presentation }"
},
"VerifiablePresentation": {
"type": "object",
Expand Down Expand Up @@ -302,7 +296,7 @@
"verifiableCredential",
"proof"
],
"description": "Verifiable Presentation {@link https://github.com/decentralized-identifier/did-jwt-vc}"
"description": "Verifiable Presentation {@link https://github.com/decentralized-identifier/did-jwt-vc }"
}
},
"methods": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ let agent = {
execute: jest.fn(),
availableMethods: jest.fn(),
resolveDid: jest.fn(),
dereferenceDidUri: jest.fn(),
getDIDComponentById: jest.fn(),
emit: jest.fn(),
keyManagerSign: jest.fn().mockImplementation(async (args): Promise<string> => 'mockJWT'),
dataStoreSaveVerifiableCredential: jest.fn().mockImplementation(async (args): Promise<boolean> => true),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ describe('@veramo/credential-w3c', () => {
}
}
},
dereferenceDidUri: jest.fn()
getDIDComponentById: jest.fn()
}
}

Expand Down
Loading

0 comments on commit 5ca3d15

Please sign in to comment.