From de1a4a3b690fbdecd417da21649dd0cfdbf0b5b1 Mon Sep 17 00:00:00 2001 From: Jesse Wicks <33884732+jwicks31@users.noreply.github.com> Date: Fri, 9 Nov 2018 10:50:56 -0600 Subject: [PATCH] refactor: Updated Claim Interface (#226) --- src/Interfaces.ts | 6 +++++- src/VerifiableClaim.ts | 3 ++- tests/unit/shared.ts | 5 +++-- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/Interfaces.ts b/src/Interfaces.ts index 347ed66..be5d960 100644 --- a/src/Interfaces.ts +++ b/src/Interfaces.ts @@ -9,12 +9,16 @@ export enum ClaimType { Work = 'Work', } +export interface Claim { + readonly [key: string]: string | number | Claim | ReadonlyArray +} + export interface BaseVerifiableClaim { readonly '@context': any readonly issuer: string readonly issuanceDate: string readonly type: ClaimType - readonly claim: object + readonly claim: Claim } export interface VerifiableClaim extends BaseVerifiableClaim { readonly id: string diff --git a/src/VerifiableClaim.ts b/src/VerifiableClaim.ts index c7c7792..0b75ad5 100644 --- a/src/VerifiableClaim.ts +++ b/src/VerifiableClaim.ts @@ -9,6 +9,7 @@ import { CreateVerifiableClaimConfig, DefaultClaimContext, VerifiableClaim, + Claim, } from './Interfaces' const canonizeClaim = async (document: BaseVerifiableClaim): Promise => { @@ -40,7 +41,7 @@ export const configureCreateVerifiableClaim = ({ issuer, type = ClaimType.Work, context = {}, -}: CreateVerifiableClaimConfig) => async (claim: object): Promise => { +}: CreateVerifiableClaimConfig) => async (claim: Claim): Promise => { const verifiableClaim = { '@context': { ...DefaultClaimContext, ...claimTypeDefaults[type], ...context }, type, diff --git a/tests/unit/shared.ts b/tests/unit/shared.ts index fe2e6b7..aaa95e8 100644 --- a/tests/unit/shared.ts +++ b/tests/unit/shared.ts @@ -10,6 +10,7 @@ import { Identity, SignedVerifiableClaim, SigningAlgorithm, + Claim, Work, } from '../../src/Interfaces' import { getVerifiableClaimSigner } from '../../src/VerifiableClaimSigner' @@ -20,7 +21,7 @@ export const claimSigner = getVerifiableClaimSigner() export const getErrorMessage = (err: Error): string => err.message export const makeClaim = ( - claim: object, + claim: Claim, type: ClaimType = ClaimType.Work, context: ClaimContext = DefaultClaimContext, ): BaseVerifiableClaim => { @@ -106,7 +107,7 @@ export const MyIdentity: Identity = { }, } -export const TheRavenClaim: object = { +export const TheRavenClaim: Claim = { name: 'The Raven', author: 'Edgar Allan Poe', tags: 'poem',