@verixyz/core v2.0.0
verixyz Core
Core functions
- instantiate and orchestrate plugins
- coordinate events
- validate schemas
- define core types
Functions
createAgent(options)
Helper function to create a new instance of the Agent class with correct type.
Parameters:
options: IAgentOptions & { Context ?: C;}
Returns: TAgent & {Context? : C'}
Example
import { createAgent, IResolver, IMessageHandler } from '@verixyz/core' import { AgentRestClient } from '@verixyz/remote-client' import { CredentialIssuer, ICredentialIssuer } from '@verixyz/credential-w3c' const agent = createAgent<IResolver & IMessageHandler & ICredentialIssuer>({ plugins: [ new CredentialIssuer(), new AgentRestClient({ url: 'http://localhost:3002/agent', enabledMethods: ['resolveDid', 'handleMessage'], }), ], })
Interfaces
GetDIDComponentArgs
Input arguments for getDIDComponentById
Properties
- didDocument The DID document from which to extract the fragment. This MUST be the document resolved by
- didUrl The DID URI that refers to the subsection by #fragment. Example: did:example:identifier#controller
- section The section of the DID document where to search for the fragment. Example 'keyAgreement', or 'assertionMethod', or 'authentication', etc
IAgent
Agent that can execute methods
Properties
- emit (eventType: string, data: any) => Promise
- excute <A = any, R = any>(method: string, args: A) => Promise
IAgentBase
Agent base interface
Properties
- availableMethods () => string[]
- getSchema () => IAgentPluginSchema
IAgentContext
Standard plugin method context interface
Properties
- agent TAgent
Example
await agent.resolveDid({
didUrl: 'did:example:123',
})
IAgentOptions
Agent configuration options.
This interface is used to describe the constellation of plugins that this agent will use and provide.
You will use this to attach plugins, to setup overrides for their methods and to explicitly set the methods that this agent instance is allowed to call. This permissioning method is also used for internal calls made by plugin code.
Properties
- authorizedMethods:string[] The array of method names that will be exposed by the agent
- context : Record<string, any> The context object that will be available to the plugin methods
- overrides : IPluginMethodMap The map of plugin methods. Can be used to override methods provided by plugins, or to add additional methods without writing a plugin
- plugins : IAgentPlugin [] The array of agent plugins
- schemaValidation : boolean Flag that enables schema validation for plugin methods. false
IAgentPlugin
Agent plugin interface
Properties
- methods IPluginMethodMap
- schema IAgentPluginSchema
IAgentPluginSchema
Agent plugin schema
Properties
- components { schemas: any; methods: any; }
IDataStore
Basic data store interface
Methods
- dataStoreDeleteVerifiableCredential(args) Deletes verifiable credential from the data store
- dataStoreGetMessage(args) Gets message from the data store
- dataStoreGetVerifiableCredential(args) Gets verifiable credential from the data store
- dataStoreGetVerifiablePresentation(args) Gets verifiable presentation from the data store
- dataStoreSaveMessage(args) Saves message to the data store
- dataStoreSaveVerifiableCredential(args) Saves verifiable credential to the data store
- dataStoreSaveVerifiablePresentation(args) Saves verifiable presentation to the data store
IDataStoreDeleteVerifiableCredentialArgs
Input arguments for
Properties
- hash: string Required. VerifiableCredential hash
IDataStoreGetMessageArgs
Input arguments for dataStoreGetMessage
Properties
- id: string Required. Messgae ID
IDataStoreGetVerifiableCredentialArgs
Input arguments for dataStoreGetVerifiableCredential
Properties
- hash: string Required. VerifiableCredential hash
IDataStoreGetVerifiablePresentationArgs
Input arguments for dataStoreGetVerifiablePresentation
Properties
- hash: string Required. VerifiablePresentation hash
IDataStoreSaveMessageArgs
Input arguments for dataStoreSaveMessage
Properties
- message: IMessgae Required. Required message
IDataStoreSaveVerifiableCredentialArgs
Input arguments for dataStoreSaveVerifiableCredential
IDataStoreSaveVerifiablePresentationArgs
Input arguments for dataStoreSaveVerifiablePresentation
Properties
- verifiablePresentation:VerifiablePresentation
Required. VerifiablePresentation
IDIDManager
Identifier manager interface
Methods
didManagerAddKey(args, context) Adds a key to a DID Document
args: IDIDManagerAddKeyArgs
context: IAgentContext
Returns: Promise
didManagerAddService(args, context) Adds a service to a DID Document
args: IDIDManagerAddServiceArgs
context: IAgentContext
Returns: Promise
didManagerCreate(args, context) Creates and returns a new identifier
args: IDIDManagerCreateArgs
context: IAgentContext
Returns: Promise Example
const identifier = await agent.didManagerCreate({ alias: 'charlie', provider: 'did:ethr:rinkeby', kms: 'local', })
didManagerDelete(args, context) Deletes identifier
args: IDIDManagerDeleteArgs
conext: IAgentContext
Returns: Promise
didManagerFind(args) Returns a list of managed identifiers
args: IDIDManagerFindArgs
Returns: Promise<Array> Example
const aliceIdentifiers = await agent.didManagerFind({ alias: 'alice', })
const rinkebyIdentifiers = await agent.didManagerFind({ provider: 'did:ethr:rinkeby', })
didManagerGet(args) Returns a specific identifier
args: IDIDManagerGetArgs
Returns: Promise
didManagerGetByAlias(args) Returns a specific identifier by alias
args: IDIDManagerGetByAliasArgs
Returns: Promise Example
const identifier = await agent.didManagerGetByAlias({ alias: 'charlie', provider: 'did:ethr:rinkeby', })
didManagerGetOrCreate(args, context) Returns an existing identifier or creates a new one for a specific alias
args: IDIDManagerGetOrCreateArgs
contex: IAgentContext
Returns: Promise
didManagerGetProviders() Returns a list of available identifier providers
Rerturns: Promise
didManagerImport(args, context) Imports identifier
args: MinimallmportableIdentifier
context: IagentContext
Returns: Promise
didManagerRemoveKey(args, context) Removes a key from a DID Document
args: IDIDManagerRemoveKeyArgs
context: IAgentContext
Returns: Promise
didManagerRemoveService(args, context) Removes a service from a DID Document
args: IDIDManagerRemoveServiceArgs
context: IAgentContext
Returns: Promise
didManagerSetAlias(args, context) Sets identifier alias
args: IDIDManagerSetAliasArgs
context: IAgentContext
Returns: Promise Example
const identifier = await agent.didManagerCreate() const result = await agent.didManagerSetAlias({ did: identifier.did, alias: 'carol', })
IDIDManagerAddKeyArgs
Input arguments for didManagerAddKey
Properties
- did: string
- key: IKey
- options: object
IDIDManagerAddServiceArgs
Input arguments for didManagerAddService
Peroperties
- did: string
- options: object
- service: IService
IDIDManagerCreateArgs
Input arguments for didManagerCreate
Properties
- alias: string
- kms: string
- options: object
- provider: string
IDIDManagerDeleteArgs
Input arguments for didManagerDelete
Properties
- did: string
IDIDManagerFindArgs
Input arguments for didManagerFind
Properties
- alias: string
- provider: string
IDIDManagerGetArgs
Input arguments for didManagerGet
Properties
- did: string
IDIDManagerGetByAliasArgs
Input arguments for didManagerGetByAlias
Properties
- alias: string
- provider: string
IDIDManagerGetOrCreateArgs
Input arguments for didManagerGetOrCreate
Properties
- alias: string
- kms: string
- options: object
- provider: string
IDIDManagerRemoveKeyArgs
Input arguments for didManagerRemoveKey
Properties
- did: string
- kdid: string
- options: object
IDIDManagerRemoveServiceArgs
Input arguments for didManagerRemoveService
Properties
- did: string
- id: string
- options: object
IDIDManagerSetAliasArgs
Input arguments for didManagerSetAlias
Properties
- alias: string
- did: string
IEventListener
Describes a listener interface that needs to be implemented by components interested in listening to events emitted by an agent.
Properties
- eventTypes:string[] Declares the event types that this listener is interested in.
Methods
- onEvent(event, context) Processes an event emitted by the agent.
IHandleMessageArgs
Input arguments for handleMessage
Properties
- metaData: IMetaData[] Optional. Message metadata.
- raw: string Raw message data.
- save: boolean
Optional. If set to
true
, the message will be saved using dataStoreSaveMessage.
IIdentifier
Identifier interface
Properties
- alias: string Optional. Identifier alias. Can be used to reference an object in an external system
- controllerKeyId:string Controller key id
- did: string Decentralized identifier
- keys: IKey[] Array of managed keys
- provdier: string Identifier provider name
- services: IService[] Array of services
IKey
Cryptographic key
Properties
- kid: string Key ID
- kms: string Key Management Systems
- meta: KeyMetadata | Null Optional. Key metadata. This should be used to determine which algorithms are supported.
- privateKeyHex: string Optional. Private key.
- publicKeyHex: string Public key
- type: TKeyType Key type
IKeyManager
Key manager interface
Methods
keyManagerCreate(args) Creates and returns a new key
args: IKeyManagerCreateArgs
Returns: Promise
keyManagerDecryptJWE(args) (BETA) Decrypts data
args: IKeyManagerDecryptJWEArgs
Returns: Promise
keyManagerDelete(args) Deletes a key
args:IKeyManagerDeleteArgs
Returns: Promise
keyManagerEncryptJWE(args) (BETA) Encrypts data
args: IKeyManagerEncryptJWEArgs
Returns: Promise
keyManagerGet(args) Returns an existing key
args: IKeyManagerGetArgs
Returns: Promise
keyManagerGetKeyManagementSystems() Lists available key management systems
Returns: Promise<Array>
keyManagerImport(args) Imports a created key
args: MinimalImportableKey
Returns: Promise
keyManagerSharedSecret(args) Compute a shared secret with the public key of another party. This computes the raw shared secret (the result of a Diffie-Hellman computation) To use this for symmetric encryption you MUST apply a KDF on the result.
args: IKeyManagerSharedSecretArgs
Returns: Promise
keyManagerSign(args) Generates a signature according to the algorithm specified.
args: IKeyManagerSignArgs
Returns: Promise
keyManagerSignEthTX(args) Signs Ethereum transaction
args: IKeyManagerSignEthTXArgs
Returns: Promise
keyManagerSignJWT(args) Signs JWT
args:IKeyManagerSignJWTArgs
Returns: Promise
IKeyManagerCreateArgs
Input arguments for keyManagerCreate
Properties
- kms:string Key Management Systems
- meta: keyMetadata Optional. Key Metadata.
- type: TKeyType Key type
IKeyManagerDecryptJWEArgs
(BETA) Input arguments for keyManagerDecryptJWE
Properties
- data: string (BETA) Encrypted dta
- kid: string (BETA) Key ID
IKeyManagerDeleteArgs
Input arguments for keyManagerDelete
Properties
- kid: string Key DID
IKeyManagerEncryptJWEArgs
(BETA) Input arguments for keyManagerEncryptJWE
Propperties
- data:string (BETA) Data to encrypt
- kid:string (BETA) Key ID to use for encryption
- to:Omit<IKey , 'kms'> (BETA) Recipient key object
IKeyManagerGetArgs
Input arguments for keyManagerGet
Properties
-kid: string Key DID
IKeyManagerSharedSecretArgs
Input arguments for keyManagerSharedSecret
Properties
- publicKey:Pick<IKey , 'publicKeyHex' | 'type'> The public key of the other party. The type of key MUST be compatible with the type referenced by secretKeyRef
- secretKeyRef:string The secret key handle (kid) as returned by keyManagerCreate
IKeyManagerSignArgs
Input arguments for keyManagerSign
Properties
- algorithm:string The algorithm to use for signing. This must be one of the algorithms supported by the KMS for this key type. The algorithm used here should match one of the names listed in IKey.meta.algorithms
- data:string Data to sign
- encoding:'utf-8' | 'base16' | 'base64' | 'hex' If the data is a "string" then you can specify which encoding is used. Default is "utf-8"
- keyRef:string The key handle, as returned during keyManagerCreateKey
IKeyManagerSignEthTXArgs
Input arguments for keyManagerSignEthTX
Properties
- kid: string Key ID
- transaction: object
IKeyManagerSignJWTArgs
Input arguments for keyManagerSignJWT
Properties
- data: string | Uint8Array Data to sign
- kid: string Key ID
IMessage
DIDComm message
Properties
- createdAt: string Optional. Creation date (ISO 8601)
- credentials: VerifiableCredential [] Optional. Array of attached verifiable credentials
- data: object | null Optional. Parsed data
- expiresAt: string Optional. Expiration date (ISO 8601)
- from:string Optional. Sender DID
- id:string Unique message ID
- metaData:IMetaData [] | null Optional. Array of message metadata
- presentations:VerifiablePresentation [] Optional. Array of attached verifiable presentations
- raw:string Optional. Original message raw data
- replyTo:string[] Optional. List of DIDs to reply to
- replyUrl:string Optional. URL to post a reply message to
- threadId:string Optional. Thread ID
- to:string Optional. Recipient DID
- type:string Message type
IMessageHandler
Message handler interface
Methods:
- handleMessage(args, context)
Parses and optionally saves a message args: IHandleMessageArgs
context: IAgentContext
Returns: Promise
IMetaData
Message meta data
Properties
- type: string Type
- value: string Optional. Value
IPluginMethod
Agent plugin method interface
IPluginMethodMap
Plugin method map interface
IResolver
DID Resolver interface
Methods
- getDIDComponentById(args)
(BETA) Dereferences a DID URL fragment and returns the corresponding DID document entry. args: GetDIDComponentArgs
Returns: Promise Example
const did = 'did:ethr:rinkeby:[xxx]' const didFragment = `${did}#controller` const fragment = await agent.getDIDComponentById({ didDocument: (await agent.resolveDid({ didUrl: did }))?.didDocument, didUrl: didFragment, section: 'authentication', }) expect(fragment).toEqual({ id: 'did:ethr:rinkeby:[]', type: 'EcdsaSecp256k1RecoveryMethod2020', controller: 'did:ethr:rinkeby:[]', blockchainAccountId: '[]', })
- resolveDid(args)
Resolves DID and returns DID Resolution Result args: ResolveDidArgs
Input arguments for resolving a DID
Exmaple
const doc = await agent.resolveDid({ didUrl: 'did:ethr:rinkeby:[]', }) expect(doc.didDocument).toEqual({ '@context': [ 'https://www.w3.org/ns/did/v1', 'https://identity.foundation/EcdsaSecp256k1RecoverySignature2020/lds-ecdsa-secp256k1-recovery2020-0.0.jsonld', ], id: 'did:ethr:rinkeby:[]', verificationMethod: [ { id: 'did:ethr:rinkeby:[]#controller', type: 'EcdsaSecp256k1RecoveryMethod2020', controller: 'did:ethr:rinkeby:[]', blockchainAccountId: '[]', }, ], authentication: ['did:ethr:rinkeby:[]#controller'], assertionMethod: ['did:ethr:rinkeby:[]#controller'], })
### IService
Identifier service
> Properties
- description: string
Optional. Description
- id:string
ID
- serviceEndpoint:string
Endpoint URL
- type: string
Service type
### KeyMetadata
> Properties
- algorithms:string[]
### RemoveContext
Removes context parameter from plugin method interface
### ResolveDidArgs
Input arguments for resolveDid
> Properties
- didUrl: string
DID URL
- options: DIDResolutionOptions
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
### VerifiableCredential
Verifiable Credential https://github.com/decentralized-identifier/did-jwt-vc
> Properties
- "@context" :string[]
- crendentialStatus: {id: string; type: string; }
- credentialSubject: {id?: string; [x: string]: ant;}
- expirationDate: string
- id: string
- issuanceDate: string
- issuer: {id: string; [x: string]: any;}
- proof: { type?: string; [x: string]: any;}
- type: string[]
### VerifiablePresentation
Verifiable Presentation https://github.com/decentralized-identifier/did-jwt-vc
> Properties
- "@context" :string[]
- expirationDate: string
- holder:string
- id: string
- issuanceDate: string
- proof: {type?:string; [x: string]: any;}
- type: string[]
- verifibaleCredential: VerifiableCredential[]
- verifier: string[]
### W3CCredential
W3CCredential https://github.com/decentralized-identifier/did-jwt-vc
> Properties
- "@context" :string[]
- crendentialStatus: {id: string; type: string; }
- credentialSubject: {id?: string; [x: string]: ant;}
- expirationDate: string
- id: string
- issuanceDate: string
- issuer: {id: string; [x: string]: any;}
- type: string[]
### W3CPresentation
W3CPresentation https://github.com/decentralized-identifier/did-jwt-vc
> Properties
- "@context" :string[]
- expirationData: string
- holder: string
- id: string
- issuanceDate: string
- type: string[]
- verifiableCredential: VerifiableCredential[]
- verifier: string[]
## Variables
- CoreEvents
This collection defines the core event types.
```json
CoreEvents: {
error: string
warning: string
}
- Schema<any>
## Type Aliases
### DIDDocComponent
(BETA) Return type of getDIDComponentById represents a VerificationMethod or a ServiceEndpoint entry.
```js
export declare type DIDDocComponent = VerificationMethod | ServiceEndpoint
``
### DIDDocumentSection
```js
export declare type DIDDocumentSection =
| 'verificationMethod'
| 'publicKey'
| 'service'
| 'authentication'
| 'assertionMethod'
| 'keyAgreement'
| 'capabilityInvocation'
| 'capabilityDelegation'
ManagedKeyInfo
Represents information about a managed key. Private or secret key material is not present.
export declare type ManagedKeyInfo = Omit<IKey, 'privateKeyHex'>
MinimalImportableIdentifier
Represents the minimum amount of information needed to import an IIdentifier
export declare type MinimalImportableIdentifier = {
keys: MinimalImportableKey[]
services?: IService[]
} & Omit<IIdentifier, 'keys' | 'services'>
MinimalImportableKey
Represents the properties required to import a key.
export declare type MinimalImportableKey = RequireOnly<IKey, 'privateKeyHex' | 'type' | 'kms'>
RequireOnly
Represents an object type where a subset of keys are required and everything else is optional.
export declare type RequireOnly<T, K extends keyof T> = Required<Pick<T, K>> & Partial<T>
TAgent
Utility type for constructing agent type that has a list of available methods
export declare type TAgent<T extends IPluginMethodMap> = {
[P in keyof T]: RemoveContext<T[P]>
} & IAgent
TKeyType
Cryptographic key type
export declare type TKeyType = 'Ed25519' | 'Secp256k1' | 'X25519'