From 79bcfc047a56897b4e70e61282f75bbfea454356 Mon Sep 17 00:00:00 2001 From: VolkerSchiewe Date: Mon, 2 Dec 2019 17:10:39 +0100 Subject: [PATCH] fix(json-ld validation): adding type definitions --- js/credentials/credential/credential.d.ts | 5 +- js/credentials/credential/types.d.ts | 6 +- .../signedCredential/signedCredential.d.ts | 6 +- js/credentials/signedCredential/types.d.ts | 5 +- js/identity/didDocument/didDocument.d.ts | 5 +- js/identity/didDocument/sections/types.d.ts | 7 +- js/identity/didDocument/types.d.ts | 7 +- js/linkedData/index.d.ts | 8 ++ js/linkedData/types.d.ts | 12 ++ js/linkedDataSignature/types.d.ts | 3 +- js/utils/contexts.d.ts | 108 +++++++++++++++++- js/vaultedKeyProvider/softwareProvider.d.ts | 6 +- 12 files changed, 149 insertions(+), 29 deletions(-) create mode 100644 js/linkedData/index.d.ts create mode 100644 js/linkedData/types.d.ts diff --git a/js/credentials/credential/credential.d.ts b/js/credentials/credential/credential.d.ts index 6f588ee0..934e662b 100644 --- a/js/credentials/credential/credential.d.ts +++ b/js/credentials/credential/credential.d.ts @@ -1,6 +1,7 @@ import { ICredentialAttrs, IClaimSection } from './types'; -import { BaseMetadata, ContextEntry } from 'cred-types-jolocom-core'; +import { BaseMetadata } from 'cred-types-jolocom-core'; import { ISignedCredCreationArgs } from '../signedCredential/types'; +import { JsonLdContext } from '../../linkedData/types'; export declare class Credential { private '_@context'; private _id; @@ -11,7 +12,7 @@ export declare class Credential { claim: IClaimSection; type: string[]; name: string; - context: ContextEntry[]; + context: JsonLdContext; static create({ metadata, claim, subject, }: ISignedCredCreationArgs): Credential; static fromJSON(json: ICredentialAttrs): Credential; toJSON(): ICredentialAttrs; diff --git a/js/credentials/credential/types.d.ts b/js/credentials/credential/types.d.ts index d7e15dac..0a85f15a 100644 --- a/js/credentials/credential/types.d.ts +++ b/js/credentials/credential/types.d.ts @@ -1,12 +1,12 @@ -import { ContextEntry, ClaimInterface } from 'cred-types-jolocom-core'; +import { ClaimInterface } from 'cred-types-jolocom-core'; +import { JsonLdObject } from '../../linkedData/types'; declare type ClaimType = string | number | boolean | {}; export declare type ClaimEntry = ClaimType | ClaimInterface; export interface IClaimSection { id?: string; [x: string]: ClaimEntry; } -export interface ICredentialAttrs { - '@context': ContextEntry[]; +export interface ICredentialAttrs extends JsonLdObject { type: string[]; name?: string; claim: ClaimEntry; diff --git a/js/credentials/signedCredential/signedCredential.d.ts b/js/credentials/signedCredential/signedCredential.d.ts index 9d420891..eab629a3 100644 --- a/js/credentials/signedCredential/signedCredential.d.ts +++ b/js/credentials/signedCredential/signedCredential.d.ts @@ -2,8 +2,9 @@ import 'reflect-metadata'; import { ISignedCredCreationArgs, ISignedCredentialAttrs } from './types'; import { IDigestable, ILinkedDataSignature } from '../../linkedDataSignature/types'; -import { BaseMetadata, ContextEntry } from 'cred-types-jolocom-core'; +import { BaseMetadata } from 'cred-types-jolocom-core'; import { IClaimSection } from '../credential/types'; +import { JsonLdContext } from '../../linkedData/types'; import { ISigner } from '../../registries/types'; interface IIssInfo { keyId: string; @@ -19,7 +20,7 @@ export declare class SignedCredential implements IDigestable { private _issued; private _expires?; private _proof; - context: ContextEntry[]; + context: JsonLdContext; id: string; issuer: string; issued: Date; @@ -34,7 +35,6 @@ export declare class SignedCredential implements IDigestable { static create(credentialOptions: ISignedCredCreationArgs, issInfo: IIssInfo, expires?: Date): Promise; private prepareSignature; digest(): Promise; - private normalize; static fromJSON(json: ISignedCredentialAttrs): SignedCredential; toJSON(): ISignedCredentialAttrs; } diff --git a/js/credentials/signedCredential/types.d.ts b/js/credentials/signedCredential/types.d.ts index 352279e3..12f91b8b 100644 --- a/js/credentials/signedCredential/types.d.ts +++ b/js/credentials/signedCredential/types.d.ts @@ -1,13 +1,12 @@ import { ICredentialAttrs, IClaimSection } from '../credential/types'; -import { ILinkedDataSignatureAttrs } from '../../linkedDataSignature/types'; import { BaseMetadata } from 'cred-types-jolocom-core'; -export interface ISignedCredentialAttrs extends ICredentialAttrs { +import { SignedJsonLdObject } from '../../linkedData/types'; +export interface ISignedCredentialAttrs extends SignedJsonLdObject, ICredentialAttrs { id: string; issuer: string; issued: string; expires?: string; claim: IClaimSection; - proof: ILinkedDataSignatureAttrs; } export interface ISignedCredCreationArgs { metadata: T; diff --git a/js/identity/didDocument/didDocument.d.ts b/js/identity/didDocument/didDocument.d.ts index 728175f1..773bebf7 100644 --- a/js/identity/didDocument/didDocument.d.ts +++ b/js/identity/didDocument/didDocument.d.ts @@ -2,7 +2,7 @@ import { IDidDocumentAttrs } from './types'; import { AuthenticationSection, PublicKeySection, ServiceEndpointsSection } from './sections'; import { ISigner } from '../../registries/types'; -import { ContextEntry } from 'cred-types-jolocom-core'; +import { JsonLdContext } from '../../linkedData/types'; import { ILinkedDataSignature, IDigestable } from '../../linkedDataSignature/types'; export declare class DidDocument implements IDigestable { private _id; @@ -12,7 +12,7 @@ export declare class DidDocument implements IDigestable { private _created; private _proof; private '_@context'; - context: ContextEntry[]; + context: JsonLdContext; did: string; authentication: AuthenticationSection[]; publicKey: PublicKeySection[]; @@ -28,7 +28,6 @@ export declare class DidDocument implements IDigestable { static fromPublicKey(publicKey: Buffer): DidDocument; private prepareSignature; digest(): Promise; - normalize(): Promise; toJSON(): IDidDocumentAttrs; static fromJSON(json: IDidDocumentAttrs): DidDocument; } diff --git a/js/identity/didDocument/sections/types.d.ts b/js/identity/didDocument/sections/types.d.ts index bd9923be..f123dbd5 100644 --- a/js/identity/didDocument/sections/types.d.ts +++ b/js/identity/didDocument/sections/types.d.ts @@ -1,13 +1,14 @@ -export interface IPublicKeySectionAttrs { +import { JsonLdObject } from '../../../linkedData/types'; +export interface IPublicKeySectionAttrs extends JsonLdObject { id: string; type: string; publicKeyHex: string; } -export interface IAuthenticationSectionAttrs { +export interface IAuthenticationSectionAttrs extends JsonLdObject { publicKey: string; type: string; } -export interface IServiceEndpointSectionAttrs { +export interface IServiceEndpointSectionAttrs extends JsonLdObject { id: string; type: string; serviceEndpoint: string; diff --git a/js/identity/didDocument/types.d.ts b/js/identity/didDocument/types.d.ts index 5d816535..c2fd196e 100644 --- a/js/identity/didDocument/types.d.ts +++ b/js/identity/didDocument/types.d.ts @@ -1,12 +1,9 @@ import { IPublicKeySectionAttrs, IAuthenticationSectionAttrs, IServiceEndpointSectionAttrs } from './sections/types'; -import { ILinkedDataSignatureAttrs } from '../../linkedDataSignature/types'; -import { ContextEntry } from 'cred-types-jolocom-core'; -export interface IDidDocumentAttrs { - '@context': ContextEntry[]; +import { SignedJsonLdObject } from '../../linkedData/types'; +export interface IDidDocumentAttrs extends SignedJsonLdObject { id: string; authentication: IAuthenticationSectionAttrs[]; publicKey: IPublicKeySectionAttrs[]; service: IServiceEndpointSectionAttrs[]; created: string; - proof: ILinkedDataSignatureAttrs; } diff --git a/js/linkedData/index.d.ts b/js/linkedData/index.d.ts new file mode 100644 index 00000000..54dcf770 --- /dev/null +++ b/js/linkedData/index.d.ts @@ -0,0 +1,8 @@ +/// +import { ILinkedDataSignatureAttrs } from '../linkedDataSignature/types'; +import { IRegistry } from '../registries/types'; +import { JsonLdObject, SignedJsonLdObject, JsonLdContext } from './types'; +export declare const normalizeJsonLd: ({ ["@context"]: _, ...data }: JsonLdObject, context: JsonLdContext) => Promise; +export declare const normalizeLdProof: ({ signatureValue, id, type, ...toNormalize }: ILinkedDataSignatureAttrs, context: JsonLdContext) => Promise; +export declare const digestJsonLd: ({ proof, ["@context"]: _, ...data }: SignedJsonLdObject, context: JsonLdContext) => Promise; +export declare const validateJsonLd: (json: SignedJsonLdObject, customRegistry?: IRegistry) => Promise; diff --git a/js/linkedData/types.d.ts b/js/linkedData/types.d.ts new file mode 100644 index 00000000..cd49d3d8 --- /dev/null +++ b/js/linkedData/types.d.ts @@ -0,0 +1,12 @@ +import { ILinkedDataSignatureAttrs } from '../linkedDataSignature/types'; +import { ContextEntry } from 'cred-types-jolocom-core'; +declare type JsonLdPrimitive = string | number | boolean | JsonLdObject | JsonLdObject[]; +export declare type JsonLdContext = ContextEntry | ContextEntry[]; +export interface JsonLdObject { + '@context'?: JsonLdContext; + [key: string]: JsonLdPrimitive | JsonLdPrimitive[]; +} +export interface SignedJsonLdObject extends JsonLdObject { + proof: ILinkedDataSignatureAttrs; +} +export {}; diff --git a/js/linkedDataSignature/types.d.ts b/js/linkedDataSignature/types.d.ts index 94ec389f..3aaa8154 100644 --- a/js/linkedDataSignature/types.d.ts +++ b/js/linkedDataSignature/types.d.ts @@ -1,4 +1,5 @@ /// +import { JsonLdObject } from '../linkedData/types'; export interface ISerializable { toJSON: () => {}; } @@ -16,7 +17,7 @@ export interface IDigestable { keyId: string; }; } -export interface ILinkedDataSignatureAttrs { +export interface ILinkedDataSignatureAttrs extends JsonLdObject { type: string; created: string; creator: string; diff --git a/js/utils/contexts.d.ts b/js/utils/contexts.d.ts index 6d73e107..134965b8 100644 --- a/js/utils/contexts.d.ts +++ b/js/utils/contexts.d.ts @@ -1,3 +1,105 @@ -import { ContextEntry } from 'cred-types-jolocom-core'; -export declare const defaultContext: ContextEntry[]; -export declare const defaultContextIdentity: ContextEntry[]; +export declare const defaultContext: { + id: string; + type: string; + cred: string; + schema: string; + dc: string; + xsd: string; + sec: string; + Credential: string; + issuer: { + '@id': string; + '@type': string; + }; + issued: { + '@id': string; + '@type': string; + }; + claim: { + '@id': string; + '@type': string; + }; + credential: { + '@id': string; + '@type': string; + }; + expires: { + '@id': string; + '@type': string; + }; + proof: { + '@id': string; + '@type': string; + }; + EcdsaKoblitzSignature2016: string; + created: { + '@id': string; + '@type': string; + }; + creator: { + '@id': string; + '@type': string; + }; + domain: string; + nonce: string; + signatureValue: string; +}[]; +export declare const defaultContextIdentity: { + id: string; + type: string; + dc: string; + rdfs: string; + schema: string; + sec: string; + didv: string; + xsd: string; + AuthenticationSuite: string; + CryptographicKey: string; + LinkedDataSignature2016: string; + authentication: string; + created: { + '@id': string; + '@type': string; + }; + creator: { + '@id': string; + '@type': string; + }; + digestAlgorithm: string; + digestValue: string; + domain: string; + entity: string; + expires: { + '@id': string; + '@type': string; + }; + name: string; + nonce: string; + normalizationAlgorithm: string; + owner: { + '@id': string; + '@type': string; + }; + privateKey: { + '@id': string; + '@type': string; + }; + proof: string; + proofAlgorithm: string; + proofType: string; + proofValue: string; + publicKey: { + '@id': string; + '@type': string; + '@container': string; + }; + publicKeyHex: string; + requiredProof: string; + revoked: { + '@id': string; + '@type': string; + }; + signature: string; + signatureAlgorithm: string; + signatureValue: string; +}[]; diff --git a/js/vaultedKeyProvider/softwareProvider.d.ts b/js/vaultedKeyProvider/softwareProvider.d.ts index 250dccde..04d6e6c3 100644 --- a/js/vaultedKeyProvider/softwareProvider.d.ts +++ b/js/vaultedKeyProvider/softwareProvider.d.ts @@ -1,6 +1,6 @@ /// import { IDigestable } from '../linkedDataSignature/types'; -import { IVaultedKeyProvider, IKeyDerivationArgs } from './types'; +import { IKeyDerivationArgs, IVaultedKeyProvider } from './types'; export interface EncryptedData { keys: EncryptedKey[]; data: string; @@ -26,8 +26,8 @@ export declare class SoftwareKeyProvider implements IVaultedKeyProvider { static verifyDigestable(publicKey: Buffer, toVerify: IDigestable): Promise; private static encrypt; private static decrypt; - encryptHybrid(data: object, derivationArgs: IKeyDerivationArgs): Promise; - decryptHybrid(encryptedData: EncryptedData, derivationArg: IKeyDerivationArgs): Promise; + encryptHybrid(data: object, derivationArgs: IKeyDerivationArgs): Promise; + decryptHybrid(encryptedData: EncryptedData, derivationArg: IKeyDerivationArgs): Promise; private stringifyEncryptedData; private parseEncryptedData; private static normalizePassword;