Skip to content

Commit

Permalink
feat(cli): export new agent methods and request LD DIDDocument by def…
Browse files Browse the repository at this point in the history
…ault (#617)

* refactor(core): fix param & return types for getDIDComponentById

* feat(cli): export new agent methods by default
  * `getDIDComponentById` from did-resolver
  * `packDIDCommMessage` from did-comm
  * `unpackDIDCommMessage` from did-comm
  * `sendDIDCommMessage` from did-comm

* fix(deps): update builders-and-testers

* fix(did-resolver): request LD DIDDocument by default
  • Loading branch information
mirceanis authored Jul 14, 2021
1 parent 3c33265 commit 26d088b
Show file tree
Hide file tree
Showing 12 changed files with 2,200 additions and 4,104 deletions.
2 changes: 1 addition & 1 deletion __tests__/localAgent.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ const setup = async (options?: IAgentOptions): Promise<boolean> => {
new DIDDiscovery({
providers: [new AliasDiscoveryProvider(), new ProfileDiscoveryProvider()],
}),
...options?.plugins || [],
...(options?.plugins || []),
],
})
return true
Expand Down
2 changes: 1 addition & 1 deletion __tests__/localMemoryStoreAgent.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ const setup = async (options?: IAgentOptions): Promise<boolean> => {
new DIDComm(),
new CredentialIssuer(),
new SelectiveDisclosure(),
...options?.plugins || [],
...(options?.plugins || []),
],
})
return true
Expand Down
2 changes: 1 addition & 1 deletion __tests__/restAgent.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ const setup = async (options?: IAgentOptions): Promise<boolean> => {
new DIDDiscovery({
providers: [new AliasDiscoveryProvider(), new ProfileDiscoveryProvider()],
}),
...options?.plugins || [],
...(options?.plugins || []),
],
})

Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@
"devDependencies": {
"@commitlint/cli": "12.1.4",
"@commitlint/config-conventional": "12.1.4",
"@microsoft/api-documenter": "7.13.30",
"@microsoft/api-extractor": "7.18.1",
"@microsoft/api-extractor-model": "7.13.3",
"@microsoft/api-documenter": "7.13.31",
"@microsoft/api-extractor": "7.18.2",
"@microsoft/api-extractor-model": "7.13.4",
"@types/jest": "26.0.24",
"codecov": "3.8.2",
"cross-fetch": "3.1.4",
Expand Down
5 changes: 5 additions & 0 deletions packages/cli/default/default.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ version: 2.0
constants:
baseUrl: http://localhost:3332
port: 3332
# please use your own X25519 key, this is only an example
secretKey: 29739248cad1bd1a0fc4d9b75cd4d2990de535baf5caadfdf8d8f86664aa830c
databaseFile: ./database.sqlite
methods:
Expand All @@ -28,6 +29,7 @@ constants:
- didManagerAddService
- didManagerRemoveService
- resolveDid
- getDIDComponentById
- discoverDid
- dataStoreGetMessage
- dataStoreSaveMessage
Expand All @@ -46,6 +48,9 @@ constants:
- dataStoreORMGetVerifiablePresentations
- dataStoreORMGetVerifiablePresentationsCount
- handleMessage
- packDIDCommMessage
- unpackDIDCommMessage
- sendDIDCommMessage
- sendMessageDIDCommAlpha1
- createVerifiablePresentation
- createVerifiableCredential
Expand Down
5 changes: 2 additions & 3 deletions packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
"update-veramo-latest": "yarn add @veramo/core@latest @veramo/discovery@latest @veramo/remote-client@latest @veramo/remote-server@latest @veramo/did-provider-key@latest @veramo/did-resolver@latest @veramo/did-jwt@latest @veramo/credential-w3c@latest @veramo/did-provider-ethr@latest @veramo/did-provider-web@latest @veramo/did-comm@latest @veramo/kms-local@latest @veramo/selective-disclosure@latest @veramo/data-store@latest @veramo/key-manager@latest @veramo/message-handler@latest @veramo/did-manager@latest @veramo/url-handler@latest"
},
"dependencies": {
"@microsoft/api-extractor": "7.18.1",
"@microsoft/api-extractor-model": "7.13.3",
"@microsoft/api-extractor": "7.18.2",
"@microsoft/api-extractor-model": "7.13.4",
"@types/blessed": "^0.1.17",
"@types/swagger-ui-express": "^4.1.2",
"@veramo/core": "^1.2.0",
Expand Down Expand Up @@ -54,7 +54,6 @@
"inquirer-autocomplete-prompt": "^1.2.0",
"json-schema": "^0.3.0",
"jsonpointer": "^4.1.0",
"ngrok": "^4.0.0",
"oas-resolver": "^2.5.3",
"openapi-types": "^9.0.0",
"passport": "^0.4.1",
Expand Down
159 changes: 107 additions & 52 deletions packages/core/plugin.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,67 +2,27 @@
"IResolver": {
"components": {
"schemas": {
"ResolveDidArgs": {
"GetDIDComponentArgs": {
"type": "object",
"properties": {
"didDocument": {
"$ref": "#/components/schemas/DIDDocument",
"description": "the DID document from which to extract the fragment. This MUST be the document resolved by {@link resolveDid }"
},
"didUrl": {
"type": "string",
"description": "DID URL"
"description": "The DID URI that refers to the subsection by #fragment. Example: did:example:identifier#controller"
},
"options": {
"$ref": "#/components/schemas/DIDResolutionOptions",
"description": "DID resolution options that will be passed to the method specific resolver. See: https://w3c.github.io/did-spec-registries/#did-resolution-input-metadata See: https://www.w3.org/TR/did-core/#did-resolution-options"
"section": {
"$ref": "#/components/schemas/DIDDocumentSection",
"description": "The section of the DID document where to search for the fragment. Example 'keyAgreement', or 'assertionMethod', or 'authentication', etc"
}
},
"required": [
"didDocument",
"didUrl"
],
"description": "Input arguments for {@link IResolver.resolveDid | resolveDid }"
},
"DIDResolutionOptions": {
"type": "object",
"properties": {
"accept": {
"type": "string"
}
}
},
"DIDResolutionResult": {
"type": "object",
"properties": {
"didResolutionMetadata": {
"$ref": "#/components/schemas/DIDResolutionMetadata"
},
"didDocument": {
"anyOf": [
{
"$ref": "#/components/schemas/DIDDocument"
},
{
"type": "null"
}
]
},
"didDocumentMetadata": {
"$ref": "#/components/schemas/DIDDocumentMetadata"
}
},
"required": [
"didResolutionMetadata",
"didDocument",
"didDocumentMetadata"
]
},
"DIDResolutionMetadata": {
"type": "object",
"properties": {
"contentType": {
"type": "string"
},
"error": {
"type": "string"
}
}
"description": "Input arguments for {@link IResolver.getDIDComponentById | getDIDComponentById }"
},
"DIDDocument": {
"type": "object",
Expand Down Expand Up @@ -291,6 +251,92 @@
"serviceEndpoint"
]
},
"DIDDocumentSection": {
"type": "string",
"enum": [
"verificationMethod",
"publicKey",
"service",
"authentication",
"assertionMethod",
"keyAgreement",
"capabilityInvocation",
"capabilityDelegation"
]
},
"DIDDocComponent": {
"anyOf": [
{
"$ref": "#/components/schemas/VerificationMethod"
},
{
"$ref": "#/components/schemas/ServiceEndpoint"
}
],
"description": "Return type of {@link IResolver.getDIDComponentById | getDIDComponentById } \nrepresents a `VerificationMethod` or a `ServiceEndpoint` entry from a {@link did-resolver#DIDDocument | DIDDocument }"
},
"ResolveDidArgs": {
"type": "object",
"properties": {
"didUrl": {
"type": "string",
"description": "DID URL"
},
"options": {
"$ref": "#/components/schemas/DIDResolutionOptions",
"description": "DID resolution options that will be passed to the method specific resolver. See: https://w3c.github.io/did-spec-registries/#did-resolution-input-metadata See: https://www.w3.org/TR/did-core/#did-resolution-options"
}
},
"required": [
"didUrl"
],
"description": "Input arguments for {@link IResolver.resolveDid | resolveDid }"
},
"DIDResolutionOptions": {
"type": "object",
"properties": {
"accept": {
"type": "string"
}
}
},
"DIDResolutionResult": {
"type": "object",
"properties": {
"didResolutionMetadata": {
"$ref": "#/components/schemas/DIDResolutionMetadata"
},
"didDocument": {
"anyOf": [
{
"$ref": "#/components/schemas/DIDDocument"
},
{
"type": "null"
}
]
},
"didDocumentMetadata": {
"$ref": "#/components/schemas/DIDDocumentMetadata"
}
},
"required": [
"didResolutionMetadata",
"didDocument",
"didDocumentMetadata"
]
},
"DIDResolutionMetadata": {
"type": "object",
"properties": {
"contentType": {
"type": "string"
},
"error": {
"type": "string"
}
}
},
"DIDDocumentMetadata": {
"type": "object",
"properties": {
Expand Down Expand Up @@ -322,8 +368,17 @@
}
},
"methods": {
"getDIDComponentById": {
"description": "Dereferences a DID URL fragment and returns the corresponding DID document entry.",
"arguments": {
"$ref": "#/components/schemas/GetDIDComponentArgs"
},
"returnType": {
"$ref": "#/components/schemas/DIDDocComponent"
}
},
"resolveDid": {
"description": "Resolves DID and returns DID Document",
"description": "Resolves DID and returns DID Resolution Result",
"arguments": {
"$ref": "#/components/schemas/ResolveDidArgs"
},
Expand Down
42 changes: 28 additions & 14 deletions packages/core/src/types/IResolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,33 @@ export interface ResolveDidArgs {
options?: DIDResolutionOptions
}

/**
* Input arguments for {@link IResolver.getDIDComponentById | getDIDComponentById}
* @beta
*/
export interface GetDIDComponentArgs {
/**
* 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
*/
didUrl: string
/**
* The section of the DID document where to search for the fragment. Example 'keyAgreement', or 'assertionMethod',
* or 'authentication', etc
*/
section?: DIDDocumentSection
}

/**
* Return type of {@link IResolver.getDIDComponentById | getDIDComponentById}
* represents a `VerificationMethod` or a `ServiceEndpoint` entry from a {@link did-resolver#DIDDocument | DIDDocument}
* @beta
*/
export type DIDDocComponent = VerificationMethod | ServiceEndpoint

/**
* DID Resolver interface
* @public
Expand Down Expand Up @@ -98,20 +125,7 @@ export interface IResolver extends IPluginMethodMap {
*
* @beta
*/
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
*/
didUrl: string
/**
* The section of the DID document where to search for the fragment. Example 'keyAgreement'
*/
section?: DIDDocumentSection
}): Promise<VerificationMethod | ServiceEndpoint>
getDIDComponentById(args: GetDIDComponentArgs): Promise<DIDDocComponent>
}

export type DIDDocumentSection =
Expand Down
2 changes: 1 addition & 1 deletion packages/did-provider-key/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"extract-api": "yarn veramo dev extract-api"
},
"dependencies": {
"@transmute/did-key.js": "^0.2.1-unstable",
"@transmute/did-key.js": "^0.3.0-unstable",
"@veramo/core": "^1.2.0",
"@veramo/did-manager": "^1.2.0",
"debug": "^4.1.1",
Expand Down
8 changes: 4 additions & 4 deletions packages/did-provider-key/src/resolver.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { resolver } from '@transmute/did-key.js'
import { resolve } from '@transmute/did-key.js'
import { DIDResolutionOptions, DIDResolutionResult, DIDResolver, ParsedDID, Resolvable } from 'did-resolver'

const resolve: DIDResolver = async (
const resolveDidKey: DIDResolver = async (
didUrl: string,
_parsed: ParsedDID,
_resolver: Resolvable,
options: DIDResolutionOptions,
): Promise<DIDResolutionResult> => {
try {
const didResolution = (await resolver.resolve(didUrl, options)) as DIDResolutionResult
const didResolution = (await resolve(didUrl, options as any)) as DIDResolutionResult
return didResolution
} catch (err) {
return {
Expand All @@ -20,5 +20,5 @@ const resolve: DIDResolver = async (
}

export function getDidKeyResolver() {
return { key: resolve }
return { key: resolveDidKey }
}
6 changes: 5 additions & 1 deletion packages/did-resolver/src/resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,11 @@ export class DIDResolverPlugin implements IAgentPlugin {
options?: DIDResolutionOptions
}): Promise<DIDResolutionResult> {
debug('Resolving %s', didUrl)
return this.didResolver.resolve(didUrl, options)
const resolverOptions = {
accept: 'application/did+ld+json',
...options,
}
return this.didResolver.resolve(didUrl, resolverOptions)
}

/** {@inheritDoc @veramo/core#IResolver.getDIDComponentById} */
Expand Down
Loading

0 comments on commit 26d088b

Please sign in to comment.