UNPKG

@ew-did-registry/claims

Version:

The package exposes functionality needed to create, inspect, approve, and verify Private and Public claims

161 lines (160 loc) 5.57 kB
/// <reference types="sjcl" /> import { IProofData, ISaltedFields } from '../models'; import { IClaimsUser } from '../interface'; import { Claims } from '../claims'; declare module 'sjcl' { interface SjclEllipticalCurve { r: number; G: sjcl.SjclEllipticalPoint; } interface SjclEllipticalPoint { x: sjcl.BigNumber; y: sjcl.BigNumber; } } export declare class ClaimsUser extends Claims implements IClaimsUser { curve: import("sjcl").SjclEllipticalCurve; q: number; g: import("sjcl").SjclEllipticalPoint; paranoia: number; /** * * Creates token with data about subject provided in claimData * * @example * ```typescript * import { ClaimsUser } from '@ew-did-registry/claims'; * import { Keys } from '@ew-did-registry/keys'; * * const user = new Keys(); * const claims = new ClaimsUser(user); * const claimData = { * name: 'John' * }; * const token = await claims.createPublicClaim(claimData); * ``` * @param { IClaimData } publicData * * @returns { Promise<string> } */ createPublicClaim(publicData: Record<string, unknown>, jwtOptions?: { subject: string; issuer: string; }): Promise<string>; /** * Used by the claim subject to create token with subject encrypted * private data which afterwards will be sent to the issuer. Salted private * fields will be saved in the `saltedFields` argument * * @example * ```typescript * import { ClaimsUser } from '@ew-did-registry/claims'; * import { Keys } from '@ew-did-registry/keys'; * * const user = new Keys(); * const claims = new ClaimsUser(user); * const claimData = { * secret: '123' * }; * const claim = await claims.createPrivateClaim(claimData, issuer); * ``` * @param { IClaimData } publicData object with claim subject private data * @param { string } issuer DID * * @returns { Promise<{token: string, saltedFields:{ [key: string]: string }}> } token with private data encrypted by issuer key */ createPrivateClaim(privateData: { [key: string]: string; }, issuer: string, jwtOptions?: { subject: string; issuer: string; }): Promise<{ token: string; saltedFields: ISaltedFields; }>; /** * Used by the claim subject based on the salted values calculated * when creating private claim * * @example * ```typescript * import { ClaimsUser } from '@ew-did-registry/claims'; * import { Keys } from '@ew-did-registry/keys'; * * const user = new Keys(); * const claims = new ClaimsUser(user); * const claimUrl = 'http://example.com'; * const saltedFields = { * secret: '123abc' * }; * const claim = await claims.createProofClaim(claimUrl, saltedFields); * ``` * @param { string } claimUrl - url of previously saved token * @param { { [keys: string]: string } } saltedFields - salted private user data * * @returns { Promise<string> } */ createProofClaim(claimUrl: string, proofData: IProofData, jwtOptions?: { subject: string; issuer: string; }): Promise<string>; /** * Verifies that content of issued and requested tokens is the same. * This performed before issued token is published * * @example * ```typescript * import { ClaimsUser } from '@ew-did-registry/claims'; * import { Keys } from '@ew-did-registry/keys'; * * const user = new Keys(); * const claims = new UserClaims(user); * const verified = await claims.verifyClaimContent(issuedToken); * ``` * @param { string } token - issued token * @throws if the proof failed */ verifyClaimContent(token: string, verifyData: Record<string, unknown>): void; /** * Verifies token with private data received from issuer * * @example * ```typescript * import { ClaimsUser } from '@ew-did-registry/claims'; * import { Keys } from '@ew-did-registry/keys'; * * const user = new Keys(); * const claims = new UserClaims(user); * const verified = await claims.verifyPrivateToken(issuedToken); * ``` * @param { string } token - issued token * @returns {Promise<string>} * @throw if the proof failed */ verifyPrivateClaim(token: string, saltedFields: ISaltedFields): Promise<boolean>; /** * Verifies content of the issued claim, issuer identity and adds claim to service endpoints * * @param issued {string} claim approved by the issuer * @param verifyData {object} user data that should be contained in issued claim * * @returns {string} url of the saved claim */ publishPublicClaim(issued: string, verifyData: Record<string, unknown>, opts?: { hashAlg: string; createHash: (data: string) => string; }): Promise<string>; /** * Verifies content of the issued claim, issuer identity and add claim to service endpoints * * @param issued {string} claim with encrypted user data approved by the issuer * @param saltedFields {ISaltedFields} private user data * * @returns {string} url of the saved claim */ publishPrivateClaim(issued: string, saltedFields: ISaltedFields, opts?: { hashAlg: string; createHash: (data: string) => string; }): Promise<string>; private addClaimToServiceEndpoints; }