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

feat(credential-w3c): list usable proof formats for an IIdentifier #1268

Merged
merged 1 commit into from
Oct 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 6 additions & 7 deletions __tests__/localAgent.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@
* This suite also runs a ganache local blockchain to run through some examples of DIDComm using did:ethr identifiers.
*/

import {
createAgent,
} from '../packages/core/src'
import { createAgent } from '../packages/core/src'
import {
IAgentOptions,
ICredentialPlugin,
Expand Down Expand Up @@ -91,8 +89,9 @@ import didCommWithEthrDidFlow from './shared/didCommWithEthrDidFlow'
import utils from './shared/utils'
import web3 from './shared/web3'
import credentialStatus from './shared/credentialStatus'
import ethrDidFlowSigned from "./shared/ethrDidFlowSigned";
import ethrDidFlowSigned from './shared/ethrDidFlowSigned'
import didCommWithPeerDidFlow from './shared/didCommWithPeerDidFlow.js'
import credentialPluginTests from './shared/credentialPluginTests.js'

jest.setTimeout(120000)

Expand All @@ -117,8 +116,7 @@ let dbConnection: Promise<DataSource>
let databaseFile: string

const setup = async (options?: IAgentOptions): Promise<boolean> => {
databaseFile =
options?.context?.databaseFile || ':memory:'
databaseFile = options?.context?.databaseFile || ':memory:'
dbConnection = new DataSource({
name: options?.context?.['dbName'] || 'test',
type: 'sqlite',
Expand Down Expand Up @@ -202,7 +200,7 @@ const setup = async (options?: IAgentOptions): Promise<boolean> => {
defaultKms: 'local',
}),
'did:peer': new PeerDIDProvider({
defaultKms: 'local'
defaultKms: 'local',
}),
'did:pkh': new PkhDIDProvider({
defaultKms: 'local',
Expand Down Expand Up @@ -303,4 +301,5 @@ describe('Local integration tests', () => {
didCommWithPeerDidFlow(testContext)
credentialStatus(testContext)
ethrDidFlowSigned(testContext)
credentialPluginTests(testContext)
})
2 changes: 2 additions & 0 deletions __tests__/localJsonStoreAgent.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ import messageHandler from './shared/messageHandler'
import utils from './shared/utils'
import { JsonFileStore } from './utils/json-file-store'
import credentialStatus from './shared/credentialStatus'
import credentialPluginTests from './shared/credentialPluginTests'

jest.setTimeout(120000)

Expand Down Expand Up @@ -241,4 +242,5 @@ describe('Local json-data-store integration tests', () => {
didCommPacking(testContext)
utils(testContext)
credentialStatus(testContext)
credentialPluginTests(testContext)
})
2 changes: 2 additions & 0 deletions __tests__/localMemoryStoreAgent.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ import messageHandler from './shared/messageHandler.js'
import utils from './shared/utils.js'
import credentialStatus from './shared/credentialStatus.js'
import credentialInterop from './shared/credentialInterop.js'
import credentialPluginTests from "./shared/credentialPluginTests.js";

jest.setTimeout(120000)

Expand Down Expand Up @@ -239,4 +240,5 @@ describe('Local in-memory integration tests', () => {
utils(testContext)
credentialStatus(testContext)
credentialInterop(testContext)
credentialPluginTests(testContext)
})
2 changes: 2 additions & 0 deletions __tests__/restAgent.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ import messageHandler from './shared/messageHandler'
import didDiscovery from './shared/didDiscovery'
import utils from './shared/utils'
import credentialStatus from './shared/credentialStatus'
import credentialPluginTests from "./shared/credentialPluginTests";

jest.setTimeout(120000)

Expand Down Expand Up @@ -303,4 +304,5 @@ describe('REST integration tests', () => {
didDiscovery(testContext)
utils(testContext)
credentialStatus(testContext)
credentialPluginTests(testContext)
})
88 changes: 88 additions & 0 deletions __tests__/shared/credentialPluginTests.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
// noinspection ES6PreferShortImport

import { IAgentOptions, ICredentialPlugin, MinimalImportableKey, TAgent } from '../../packages/core-types/src'

type ConfiguredAgent = TAgent<ICredentialPlugin>
export default (testContext: {
getAgent: (options?: IAgentOptions) => ConfiguredAgent
setup: (options?: IAgentOptions) => Promise<boolean>
tearDown: () => Promise<boolean>
}) => {
describe('credential plugin options', () => {
let agent: ConfiguredAgent

beforeAll(async () => {
await testContext.setup()
agent = testContext.getAgent()
return true
})
afterAll(testContext.tearDown)

it('should list signing options for did:key with Ed25519 key', async () => {
const iid = await agent.didManagerCreate({
provider: 'did:key',
kms: 'local',
options: {
keyType: 'Ed25519',
},
})

const options = await agent.listUsableProofFormats(iid)
expect(options).toEqual(['jwt', 'lds'])
})

it('should list signing options for did:key with Secp256k1 key', async () => {
const iid = await agent.didManagerCreate({
provider: 'did:key',
kms: 'local',
options: {
keyType: 'Secp256k1',
},
})

const options = await agent.listUsableProofFormats(iid)
expect(options).toEqual(['jwt', 'lds', 'EthereumEip712Signature2021'])
})

it('should list signing options for did:key with X25519 key', async () => {
const iid = await agent.didManagerCreate({
provider: 'did:key',
kms: 'local',
options: {
keyType: 'X25519',
},
})

const options = await agent.listUsableProofFormats(iid)
expect(options).toEqual([])
})

it('should list signing options for did:ethr with web3 backed keys', async () => {
const account = `0x71CB05EE1b1F506fF321Da3dac38f25c0c9ce6E1`
const did = `did:ethr:${account}`
const controllerKeyId = `ethers-${account}`
const iid = await agent.didManagerImport({
did,
provider: 'did:ethr',
controllerKeyId,
keys: [
{
kid: controllerKeyId,
type: 'Secp256k1',
kms: 'web3',
privateKeyHex: '',
publicKeyHex: '',
meta: {
account,
provider: 'ethers',
algorithms: ['eth_signMessage', 'eth_signTypedData'],
},
} as MinimalImportableKey,
],
})

const options = await agent.listUsableProofFormats(iid)
expect(options).toEqual(['EthereumEip712Signature2021'])
})
})
}
177 changes: 175 additions & 2 deletions packages/core-types/src/plugin.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -4208,7 +4208,7 @@
"save": {
"type": "boolean",
"description": "If this parameter is true, the resulting VerifiablePresentation is sent to the\n {@link @veramo/core-types#IDataStore | storage plugin } to be saved.",
"deprecated": "Please call\n{@link @veramo/core-types#IDataStore.dataStoreSaveVerifiableCredential | dataStoreSaveVerifiableCredential()} to save\nthe credential after creating it."
"deprecated": "Please call\n{@link @veramo/core-types#IDataStore.dataStoreSaveVerifiableCredential | dataStoreSaveVerifiableCredential()} to\nsave the credential after creating it."
},
"proofFormat": {
"$ref": "#/components/schemas/ProofFormat",
Expand Down Expand Up @@ -4422,7 +4422,7 @@
"save": {
"type": "boolean",
"description": "If this parameter is true, the resulting VerifiablePresentation is sent to the\n {@link @veramo/core-types#IDataStore | storage plugin } to be saved. <p/><p/>",
"deprecated": "Please call\n{@link @veramo/core-types#IDataStore.dataStoreSaveVerifiablePresentation | dataStoreSaveVerifiablePresentation()} to\nsave the credential after creating it."
"deprecated": "Please call\n{@link @veramo/core-types#IDataStore.dataStoreSaveVerifiablePresentation |} * dataStoreSaveVerifiablePresentation()} to save the credential after creating it."
},
"challenge": {
"type": "string",
Expand Down Expand Up @@ -4568,6 +4568,167 @@
"proof"
],
"description": "Represents a signed Verifiable Presentation (includes proof), using a JSON representation. See {@link https://www.w3.org/TR/vc-data-model/#presentations | VP data model }"
},
"IIdentifier": {
"type": "object",
"properties": {
"did": {
"type": "string",
"description": "Decentralized identifier"
},
"alias": {
"type": "string",
"description": "Optional. Identifier alias. Can be used to reference an object in an external system"
},
"provider": {
"type": "string",
"description": "Identifier provider name"
},
"controllerKeyId": {
"type": "string",
"description": "Controller key id"
},
"keys": {
"type": "array",
"items": {
"$ref": "#/components/schemas/IKey"
},
"description": "Array of managed keys"
},
"services": {
"type": "array",
"items": {
"$ref": "#/components/schemas/IService"
},
"description": "Array of services"
}
},
"required": [
"did",
"provider",
"keys",
"services"
],
"description": "Identifier interface"
},
"IKey": {
"type": "object",
"properties": {
"kid": {
"type": "string",
"description": "Key ID"
},
"kms": {
"type": "string",
"description": "Key Management System"
},
"type": {
"$ref": "#/components/schemas/TKeyType",
"description": "Key type"
},
"publicKeyHex": {
"type": "string",
"description": "Public key"
},
"privateKeyHex": {
"type": "string",
"description": "Optional. Private key"
},
"meta": {
"anyOf": [
{
"$ref": "#/components/schemas/KeyMetadata"
},
{
"type": "null"
}
],
"description": "Optional. Key metadata. This should be used to determine which algorithms are supported."
}
},
"required": [
"kid",
"kms",
"type",
"publicKeyHex"
],
"description": "Cryptographic key, usually managed by the current Veramo instance."
},
"TKeyType": {
"type": "string",
"enum": [
"Ed25519",
"Secp256k1",
"Secp256r1",
"X25519",
"Bls12381G1",
"Bls12381G2"
],
"description": "Cryptographic key type."
},
"KeyMetadata": {
"type": "object",
"properties": {
"algorithms": {
"type": "array",
"items": {
"$ref": "#/components/schemas/TAlg"
}
}
},
"description": "This encapsulates data about a key.\n\nImplementations of {@link @veramo/key-manager#AbstractKeyManagementSystem | AbstractKeyManagementSystem } should populate this object, for each key, with the algorithms that can be performed using it.\n\nThis can also be used to add various tags to the keys under management."
},
"TAlg": {
"type": "string",
"description": "Known algorithms supported by some of the above key types defined by {@link TKeyType } .\n\nActual implementations of {@link @veramo/key-manager#AbstractKeyManagementSystem | Key Management Systems } can support more. One should check the {@link IKey.meta | IKey.meta.algorithms } property to see what is possible for a particular managed key."
},
"IService": {
"type": "object",
"properties": {
"id": {
"type": "string",
"description": "ID"
},
"type": {
"type": "string",
"description": "Service type"
},
"serviceEndpoint": {
"anyOf": [
{
"$ref": "#/components/schemas/IServiceEndpoint"
},
{
"type": "array",
"items": {
"$ref": "#/components/schemas/IServiceEndpoint"
}
}
],
"description": "Endpoint URL"
},
"description": {
"type": "string",
"description": "Optional. Description"
}
},
"required": [
"id",
"type",
"serviceEndpoint"
],
"description": "Identifier service"
},
"IServiceEndpoint": {
"anyOf": [
{
"type": "string"
},
{
"type": "object"
}
],
"description": "Represents a service endpoint URL or a map of URLs"
}
},
"methods": {
Expand All @@ -4588,6 +4749,18 @@
"returnType": {
"$ref": "#/components/schemas/VerifiablePresentation"
}
},
"listUsableProofFormats": {
"description": "Returns a list of supported proof formats.",
"arguments": {
"$ref": "#/components/schemas/IIdentifier"
},
"returnType": {
"type": "array",
"items": {
"$ref": "#/components/schemas/ProofFormat"
}
}
}
}
}
Expand Down
Loading