Skip to content

Commit

Permalink
fix: IKeyManager arg types
Browse files Browse the repository at this point in the history
  • Loading branch information
simonas-notcat authored and mirceanis committed Sep 7, 2020
1 parent 56cf141 commit f79967e
Show file tree
Hide file tree
Showing 10 changed files with 279 additions and 66 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@
"ts-jest": "^25.2.1",
"ts-json-schema-generator": "^0.70.2",
"ts-node": "^8.6.2",
"typescript": "^3.9.6"
"typescript": "^3.9.6",
"typescript-json-schema": "^0.42.0"
},
"repository": {
"type": "git",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { IKey, EcdsaSignature, TKeyType } from '../types'
export abstract class AbstractKeyManagementSystem {
abstract createKey(args: { type: TKeyType; meta?: any }): Promise<Omit<IKey, 'kms'>>
abstract deleteKey(args: { kid: string }): Promise<boolean>
abstract encryptJWE(args: { key: IKey; to: IKey; data: string }): Promise<string>
abstract encryptJWE(args: { key: IKey; to: Omit<IKey, 'kms'>; data: string }): Promise<string>
abstract decryptJWE(args: { key: IKey; data: string }): Promise<string>
abstract signJWT(args: { key: IKey; data: string }): Promise<EcdsaSignature | string>
abstract signEthTX(args: { key: IKey; transaction: object }): Promise<string>
Expand Down
12 changes: 11 additions & 1 deletion packages/daf-core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,17 @@
export { Agent, createAgent, IAgentOptions } from './agent'
export * from './types'
export { IdentityManager, IIdentityManager } from './identity-manager'
export { KeyManager, IKeyManager } from './key-manager'
export {
KeyManager,
IKeyManager,
IKeyManagerCreateKeyArgs,
IKeyManagerDecryptJWEArgs,
IKeyManagerDeleteKeyArgs,
IKeyManagerEncryptJWEArgs,
IKeyManagerGetKeyArgs,
IKeyManagerSignEthTXArgs,
IKeyManagerSignJWTArgs,
} from './key-manager'
export { MessageHandler, IHandleMessage } from './message-handler'
export { Message } from './message'
export { AbstractIdentityProvider } from './abstract/abstract-identity-provider'
Expand Down
63 changes: 44 additions & 19 deletions packages/daf-core/src/key-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,44 @@ import { AbstractKeyStore } from './abstract/abstract-key-store'
import { AbstractKeyManagementSystem } from './abstract/abstract-key-management-system'
import { IKey, TKeyType, EcdsaSignature, IAgentPlugin, IPluginMethodMap } from './types'

export interface IKeyManagerCreateKeyArgs {
type: TKeyType
kms: string
meta?: Record<string, any>
}
export interface IKeyManagerGetKeyArgs {
kid: string
}
export interface IKeyManagerDeleteKeyArgs {
kid: string
}
export interface IKeyManagerEncryptJWEArgs {
kid: string
to: Omit<IKey, 'kms'>
data: string
}
export interface IKeyManagerDecryptJWEArgs {
kid: string
data: string
}
export interface IKeyManagerSignJWTArgs {
kid: string
data: string
}
export interface IKeyManagerSignEthTXArgs {
kid: string
transaction: object
}

export interface IKeyManager extends IPluginMethodMap {
keyManagerCreateKey: (args: { type: TKeyType; kms: string; meta?: Record<string, any> }) => Promise<IKey>
keyManagerGetKey: (args: { kid: string }) => Promise<IKey>
keyManagerDeleteKey: (args: { kid: string }) => Promise<boolean>
keyManagerImportKey: (args: IKey) => Promise<boolean>
keyManagerEncryptJWE: (args: { kid: string; to: Omit<IKey, 'kms'>; data: string }) => Promise<string>
keyManagerDecryptJWE: (args: { kid: string; data: string }) => Promise<string>
keyManagerSignJWT: (args: { kid: string; data: string }) => Promise<EcdsaSignature | string>
keyManagerSignEthTX: (args: { kid: string; transaction: object }) => Promise<string>
keyManagerCreateKey(args: IKeyManagerCreateKeyArgs): Promise<IKey>
keyManagerGetKey(args: IKeyManagerGetKeyArgs): Promise<IKey>
keyManagerDeleteKey(args: IKeyManagerDeleteKeyArgs): Promise<boolean>
keyManagerImportKey(args: IKey): Promise<boolean>
keyManagerEncryptJWE(args: IKeyManagerEncryptJWEArgs): Promise<string>
keyManagerDecryptJWE(args: IKeyManagerDecryptJWEArgs): Promise<string>
keyManagerSignJWT(args: IKeyManagerSignJWTArgs): Promise<EcdsaSignature | string>
keyManagerSignEthTX(args: IKeyManagerSignEthTXArgs): Promise<string>
}
export class KeyManager implements IAgentPlugin {
readonly methods: IKeyManager
Expand Down Expand Up @@ -38,11 +67,7 @@ export class KeyManager implements IAgentPlugin {
return kms
}

async keyManagerCreateKey(args: {
type: TKeyType
kms: string
meta?: Record<string, any>
}): Promise<IKey> {
async keyManagerCreateKey(args: IKeyManagerCreateKeyArgs): Promise<IKey> {
const kms = this.getKms(args.kms)
const partialKey = await kms.createKey({ type: args.type, meta: args.meta })
const key: IKey = { ...partialKey, kms: args.kms }
Expand All @@ -53,11 +78,11 @@ export class KeyManager implements IAgentPlugin {
return key
}

async keyManagerGetKey({ kid }: { kid: string }): Promise<IKey> {
async keyManagerGetKey({ kid }: IKeyManagerGetKeyArgs): Promise<IKey> {
return this.store.get({ kid })
}

async keyManagerDeleteKey({ kid }: { kid: string }): Promise<boolean> {
async keyManagerDeleteKey({ kid }: IKeyManagerDeleteKeyArgs): Promise<boolean> {
const key = await this.store.get({ kid })
const kms = this.getKms(key.kms)
await kms.deleteKey({ kid })
Expand All @@ -68,25 +93,25 @@ export class KeyManager implements IAgentPlugin {
return this.store.import(key)
}

async keyManagerEncryptJWE({ kid, to, data }: { kid: string; to: IKey; data: string }): Promise<string> {
async keyManagerEncryptJWE({ kid, to, data }: IKeyManagerEncryptJWEArgs): Promise<string> {
const key = await this.store.get({ kid })
const kms = this.getKms(key.kms)
return kms.encryptJWE({ key, to, data })
}

async keyManagerDecryptJWE({ kid, data }: { kid: string; data: string }): Promise<string> {
async keyManagerDecryptJWE({ kid, data }: IKeyManagerDecryptJWEArgs): Promise<string> {
const key = await this.store.get({ kid })
const kms = this.getKms(key.kms)
return kms.decryptJWE({ key, data })
}

async keyManagerSignJWT({ kid, data }: { kid: string; data: string }): Promise<EcdsaSignature | string> {
async keyManagerSignJWT({ kid, data }: IKeyManagerSignJWTArgs): Promise<EcdsaSignature | string> {
const key = await this.store.get({ kid })
const kms = this.getKms(key.kms)
return kms.signJWT({ key, data })
}

async keyManagerSignEthTX({ kid, transaction }: { kid: string; transaction: object }): Promise<string> {
async keyManagerSignEthTX({ kid, transaction }: IKeyManagerSignEthTXArgs): Promise<string> {
const key = await this.store.get({ kid })
const kms = this.getKms(key.kms)
return kms.signEthTX({ key, transaction })
Expand Down
88 changes: 72 additions & 16 deletions report/daf-core.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ export abstract class AbstractKeyManagementSystem {
// (undocumented)
abstract deleteKey(args: { kid: string }): Promise<boolean>
// (undocumented)
abstract encryptJWE(args: { key: IKey; to: IKey; data: string }): Promise<string>
abstract encryptJWE(args: { key: IKey; to: Omit<IKey, 'kms'>; data: string }): Promise<string>
// (undocumented)
abstract signEthTX(args: { key: IKey; transaction: object }): Promise<string>
// (undocumented)
Expand Down Expand Up @@ -423,21 +423,77 @@ export interface IKey {
// @public (undocumented)
export interface IKeyManager extends IPluginMethodMap {
// (undocumented)
keyManagerCreateKey: (args: { type: TKeyType; kms: string; meta?: Record<string, any> }) => Promise<IKey>
keyManagerCreateKey(args: IKeyManagerCreateKeyArgs): Promise<IKey>
// (undocumented)
keyManagerDecryptJWE: (args: { kid: string; data: string }) => Promise<string>
keyManagerDecryptJWE(args: IKeyManagerDecryptJWEArgs): Promise<string>
// (undocumented)
keyManagerDeleteKey: (args: { kid: string }) => Promise<boolean>
keyManagerDeleteKey(args: IKeyManagerDeleteKeyArgs): Promise<boolean>
// (undocumented)
keyManagerEncryptJWE: (args: { kid: string; to: Omit<IKey, 'kms'>; data: string }) => Promise<string>
keyManagerEncryptJWE(args: IKeyManagerEncryptJWEArgs): Promise<string>
// (undocumented)
keyManagerGetKey: (args: { kid: string }) => Promise<IKey>
keyManagerGetKey(args: IKeyManagerGetKeyArgs): Promise<IKey>
// (undocumented)
keyManagerImportKey: (args: IKey) => Promise<boolean>
keyManagerImportKey(args: IKey): Promise<boolean>
// (undocumented)
keyManagerSignEthTX: (args: { kid: string; transaction: object }) => Promise<string>
keyManagerSignEthTX(args: IKeyManagerSignEthTXArgs): Promise<string>
// (undocumented)
keyManagerSignJWT: (args: { kid: string; data: string }) => Promise<EcdsaSignature | string>
keyManagerSignJWT(args: IKeyManagerSignJWTArgs): Promise<EcdsaSignature | string>
}

// @public (undocumented)
export interface IKeyManagerCreateKeyArgs {
// (undocumented)
kms: string
// (undocumented)
meta?: Record<string, any>
// (undocumented)
type: TKeyType
}

// @public (undocumented)
export interface IKeyManagerDecryptJWEArgs {
// (undocumented)
data: string
// (undocumented)
kid: string
}

// @public (undocumented)
export interface IKeyManagerDeleteKeyArgs {
// (undocumented)
kid: string
}

// @public (undocumented)
export interface IKeyManagerEncryptJWEArgs {
// (undocumented)
data: string
// (undocumented)
kid: string
// (undocumented)
to: Omit<IKey, 'kms'>
}

// @public (undocumented)
export interface IKeyManagerGetKeyArgs {
// (undocumented)
kid: string
}

// @public (undocumented)
export interface IKeyManagerSignEthTXArgs {
// (undocumented)
kid: string
// (undocumented)
transaction: object
}

// @public (undocumented)
export interface IKeyManagerSignJWTArgs {
// (undocumented)
data: string
// (undocumented)
kid: string
}

// @public (undocumented)
Expand Down Expand Up @@ -510,21 +566,21 @@ export interface IService {
export class KeyManager implements IAgentPlugin {
constructor(options: { store: AbstractKeyStore; kms: Record<string, AbstractKeyManagementSystem> })
// (undocumented)
keyManagerCreateKey(args: { type: TKeyType; kms: string; meta?: Record<string, any> }): Promise<IKey>
keyManagerCreateKey(args: IKeyManagerCreateKeyArgs): Promise<IKey>
// (undocumented)
keyManagerDecryptJWE({ kid, data }: { kid: string; data: string }): Promise<string>
keyManagerDecryptJWE({ kid, data }: IKeyManagerDecryptJWEArgs): Promise<string>
// (undocumented)
keyManagerDeleteKey({ kid }: { kid: string }): Promise<boolean>
keyManagerDeleteKey({ kid }: IKeyManagerDeleteKeyArgs): Promise<boolean>
// (undocumented)
keyManagerEncryptJWE({ kid, to, data }: { kid: string; to: IKey; data: string }): Promise<string>
keyManagerEncryptJWE({ kid, to, data }: IKeyManagerEncryptJWEArgs): Promise<string>
// (undocumented)
keyManagerGetKey({ kid }: { kid: string }): Promise<IKey>
keyManagerGetKey({ kid }: IKeyManagerGetKeyArgs): Promise<IKey>
// (undocumented)
keyManagerImportKey(key: IKey): Promise<boolean>
// (undocumented)
keyManagerSignEthTX({ kid, transaction }: { kid: string; transaction: object }): Promise<string>
keyManagerSignEthTX({ kid, transaction }: IKeyManagerSignEthTXArgs): Promise<string>
// (undocumented)
keyManagerSignJWT({ kid, data }: { kid: string; data: string }): Promise<EcdsaSignature | string>
keyManagerSignJWT({ kid, data }: IKeyManagerSignJWTArgs): Promise<EcdsaSignature | string>
// (undocumented)
readonly methods: IKeyManager
}
Expand Down
19 changes: 19 additions & 0 deletions report/daf-url.api.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
## API Report File for "daf-url"

> Do not edit this file. It is a report generated by [API Extractor](https://api-extractor.com/).
```ts
import { AbstractMessageHandler } from 'daf-core'
import { IAgentContext } from 'daf-core'
import { Message } from 'daf-core'

// @public (undocumented)
export class UrlMessageHandler extends AbstractMessageHandler {
// Warning: (ae-forgotten-export) The symbol "IContext" needs to be exported by the entry point index.d.ts
//
// (undocumented)
handle(message: Message, context: IContext): Promise<Message>
}

// (No @packageDocumentation comment for this package)
```
88 changes: 88 additions & 0 deletions report/daf-w3c.api.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
## API Report File for "daf-w3c"

> Do not edit this file. It is a report generated by [API Extractor](https://api-extractor.com/).
```ts
import { AbstractMessageHandler } from 'daf-core'
import { IAgentContext } from 'daf-core'
import { IAgentPlugin } from 'daf-core'
import { IDataStore } from 'daf-core'
import { IIdentityManager } from 'daf-core'
import { IKeyManager } from 'daf-core'
import { IPluginMethodMap } from 'daf-core'
import { IResolveDid } from 'daf-core'
import { Message } from 'daf-core'
import { VerifiableCredential } from 'daf-core'
import { VerifiablePresentation } from 'daf-core'
import { W3CCredential } from 'daf-core'
import { W3CPresentation } from 'daf-core'

// @public (undocumented)
export interface ICreateVerifiableCredentialArgs {
// (undocumented)
credential: W3CCredential
// (undocumented)
proofFormat: 'jwt'
// (undocumented)
save?: boolean
}

// @public (undocumented)
export interface ICreateVerifiablePresentationArgs {
// (undocumented)
presentation: W3CPresentation
// (undocumented)
proofFormat: 'jwt'
// (undocumented)
save?: boolean
}

// @public (undocumented)
export interface IW3c extends IPluginMethodMap {
// (undocumented)
createVerifiableCredential(
args: ICreateVerifiableCredentialArgs,
context: IContext_2,
): Promise<VerifiableCredential>
// Warning: (ae-forgotten-export) The symbol "IContext" needs to be exported by the entry point index.d.ts
//
// (undocumented)
createVerifiablePresentation(
args: ICreateVerifiablePresentationArgs,
context: IContext_2,
): Promise<VerifiablePresentation>
}

// @public (undocumented)
export const MessageTypes: {
vc: string
vp: string
}

// @public (undocumented)
export class W3c implements IAgentPlugin {
constructor()
// (undocumented)
createVerifiableCredential(
args: ICreateVerifiableCredentialArgs,
context: IContext_2,
): Promise<VerifiableCredential>
// (undocumented)
createVerifiablePresentation(
args: ICreateVerifiablePresentationArgs,
context: IContext_2,
): Promise<VerifiablePresentation>
// (undocumented)
readonly methods: IW3c
}

// @public (undocumented)
export class W3cMessageHandler extends AbstractMessageHandler {
// Warning: (ae-forgotten-export) The symbol "IContext" needs to be exported by the entry point index.d.ts
//
// (undocumented)
handle(message: Message, context: IContext): Promise<Message>
}

// (No @packageDocumentation comment for this package)
```
4 changes: 2 additions & 2 deletions scripts/generate-docs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ const configs = [
// '../packages/daf-rest/api-extractor.json',
// '../packages/daf-selective-disclosure/api-extractor.json',
// '../packages/daf-typeorm/api-extractor.json',
// '../packages/daf-url/api-extractor.json',
// '../packages/daf-w3c/api-extractor.json',
'../packages/daf-url/api-extractor.json',
'../packages/daf-w3c/api-extractor.json',
]

for (const config of configs) {
Expand Down
Loading

0 comments on commit f79967e

Please sign in to comment.