import { Affinity } from '@affinidi/common'; import { EventComponent } from '@affinidi/affinity-metrics-lib'; import { VCV1, VCV1SubjectBaseMA, VCV1Unsigned, VPV1, VPV1Unsigned } from '@affinidi/vc-common'; import { ClaimMetadata, SignedCredential, SignCredentialOptionalInput, OfferedCredential, CredentialRequirement, JwtOptions, KeyParams, KeyAlgorithmType, KeyOptions } from '../dto/shared.dto'; import { CredentialShareResponseOutput, CredentialOfferResponseOutput, PresentationValidationOutput } from '../dto/verifier.dto'; import { ParsedOptions } from '../shared/getOptionsFromEnvironment'; import { IPlatformCryptographyTools } from '../shared/interfaces'; import KeyManagementService from '../services/KeyManagementService'; import WalletStorageService from '../services/WalletStorageService'; export declare const createKeyManagementService: ({ basicOptions, accessApiKey, otherOptions }: ParsedOptions) => KeyManagementService; export declare type StaticDependencies = { platformCryptographyTools: IPlatformCryptographyTools; eventComponent: EventComponent; }; export declare type ConstructorUserData = { didDocument?: any; did: string; didDocumentKeyId: string; encryptedSeed: string; password: string; accountNumber?: number; }; export declare abstract class BaseNetworkMember { readonly didDocument?: any; readonly accountNumber?: number; private readonly _did; private readonly _encryptedSeed; private readonly _password; protected readonly _walletStorageService: WalletStorageService; private readonly _holderService; private readonly _issuerApiService; private readonly _verifierApiService; private readonly _registryApiService; private readonly _revocationApiService; protected readonly _keyManagementService: KeyManagementService; protected readonly _affinity: Affinity; protected readonly _options: { region: string; basicOptions: { issuerUrl: string; registryUrl: string; verifierUrl: string; affinidiVaultUrl: string; keyStorageUrl: string; revocationUrl: string; metricsUrl: string; migrationUrl: string; env: import("../dto/shared.dto").Env; clientId: string; userPoolId: string; phoneIssuerBasePath: string; emailIssuerBasePath: string; }; accessApiKey: string; storageRegion: string; otherOptions: Omit; origin: string; }; private readonly _didDocumentKeyId; protected readonly _component: EventComponent; protected readonly _platformCryptographyTools: IPlatformCryptographyTools; constructor({ didDocument, did, didDocumentKeyId, encryptedSeed, password, accountNumber }: ConstructorUserData, { platformCryptographyTools, eventComponent }: StaticDependencies, options: ParsedOptions); /** * @description Returns user's encrypted seed * @returns encrypted seed */ get encryptedSeed(): string; /** * @description Returns user's password * @returns encrypted seed */ get password(): string; /** * @description Creates DID and anchors it * 1. generate seed/keys * 2. build DID document * 3. sign DID document * 4. store DID document in IPFS * 5. anchor DID with DID document ID from IPFS * @param dependencies * @param password - encryption key which will be used to encrypt randomly created seed/keys pair * @param options - optional parameter { registryUrl: 'https://affinity-registry.apse1.dev.affinidi.io' } * @param keyOptions * @returns * * did - hash from public key (your decentralized ID) * * encryptedSeed - seed is encrypted by provided password. Seed - it's a source to derive your keys */ protected static _register(dependencies: StaticDependencies, options: ParsedOptions, password: string, keyOptions?: KeyOptions): Promise<{ did: string; encryptedSeed: string; didDocumentKeyId: string; didDocument?: undefined; } | { did: string; didDocumentKeyId: string; encryptedSeed: string; didDocument: any; }>; protected static _anchorDid(encryptedSeed: string, password: string, didDocument: any, nonce: number, { basicOptions: { registryUrl }, accessApiKey, origin, otherOptions: { skipAnchoringForElemMethod }, }: ParsedOptions): Promise<{ did: string; } | { did: string; }>; /** * @description Resolves DID * @param did - decentralized ID * @returns DID document */ resolveDid(did: string): Promise; /** * @description Update DidDocument , supporting only jolo method at this point * @param didDocument - updated did document * @returns void */ updateDidDocument(didDocument: any): Promise; getShareCredential(credentialShareRequestToken: string, options: { credentials: SignedCredential[]; }): SignedCredential[]; protected static _validateKeys(keyParams: KeyParams): void; protected saveEncryptedCredentials(data: any, storageRegion?: string): Promise; /** * @description Creates JWT of credential offer request * @param offeredCredentials - array of credentials to be offered * @param options - optional, JwtOptions containing: * * audienceDid (string) - audience of generated token * * expiresAt (isoString) - expire date-time of generated token * * nonce (string) - nonce/jti of generated token * * callbackUrl (string) * @returns JWT */ generateCredentialOfferRequestToken(offeredCredentials: OfferedCredential[], options?: JwtOptions): Promise; generateDidAuthRequest(options?: JwtOptions): Promise; /** * @description Creates JWT of credential share request * @param credentialRequirements - array of credential requirements with credential types * @param issuerDid - DID of the issuer * @param options - optional, JwtOptions containing: * * audienceDid (string) - audience of generated token * * expiresAt (isoString) - expire date-time of generated token * * nonce (number) - nonce/jti of generated token * @returns JWT */ generateCredentialShareRequestToken(credentialRequirements: CredentialRequirement[], issuerDid?: string, options?: JwtOptions): Promise; /** * @description Creates JWT of credential offer response * @param credentialOfferToken - JWT with offered credentials * @returns JWT */ createCredentialOfferResponseToken(credentialOfferToken: string): Promise; createDidAuthResponse(didAuthRequestToken: string, expiresAt?: string): Promise; private _validateSignedCredentialsSupportedStructures; /** * @description Creates JWT of credential share response * @param credentialShareRequestToken - JWT with the requested VCs * @param suppliedCredentials - array of signed credentials * @param expiresAt (isoString) - optional, expire date-time of generated token * @returns JWT */ createCredentialShareResponseToken(credentialShareRequestToken: string, suppliedCredentials: SignedCredential[], expiresAt?: string): Promise; /** * @description Returns user's DID * @returns DID */ get did(): string; /** * @description Returns user's DID document key ID * @returns key ID */ get didDocumentKeyId(): string; /** * @description Returns credential types credential request token * @param credentialRequest - object with credential requirements * @returns array of credential types */ getCredentialTypes(credentialRequest: any): any[]; buildRevocationListStatus(unsignedCredential: any): Promise; revokeCredential(credentialId: string, revocationReason: string): Promise; /** * @description Signs credentials * @param credentialOfferResponseToken - credential offer response JWT * @param credentialParams - params for credentials * @returns array of SignedCredential */ signCredentials(credentialOfferResponseToken: string, credentialParams: VCV1Unsigned[]): Promise; signUnsignedCredential(unsignedCredential: VCV1Unsigned, keyType?: KeyAlgorithmType): Promise, import("@affinidi/vc-common").VCV1Type, import("@affinidi/vc-common").VCV1Holder, import("@affinidi/vc-common").VCV1Revocation, import("@affinidi/vc-common").VCV1Proof>>; /** * @description Signs credential * @param claim - data which should be present in VC according to VC schema, * e.g. const claim = { ageOver: 18 } * @param claimMetadata - schema of credential * @param signCredentialOptionalInput - object with optional * credential offer response JWT and requester DID * @param expiresAt - optional, date-time when VC is to be expired * @returns signed credential object */ signCredential(credentialSubject: Subject, claimMetadata: ClaimMetadata, signCredentialOptionalInput: SignCredentialOptionalInput, expiresAt?: string, keyType?: KeyAlgorithmType): Promise; validateCredential(signedCredential: SignedCredential, holderKey?: string, didDocument?: any): Promise<{ result: boolean; error: string; }>; verifyDidAuthResponse(didAuthResponseToken: string, didAuthRequestToken?: string): Promise; /** * @description Validates response token, verifies signature on provided VCs * and expiration date of VCs * @param credentialShareResponseToken - optional, used if need to check * response against request (when request have constrains) * @param credentialShareRequestToken - JWT with requested VC * @param shouldOwn - optional (boolean), can be passed as true, * when needed to verify if holder is a subject of VC * @returns { isValid, did, jti, suppliedCredentials, errors } * * isValid - boolean, result of the verification * * did - DID of the issuer * * jti - unique identifier for the JWT * * suppliedCredentials - array of supplied credentials */ verifyCredentialShareResponseToken(credentialShareResponseToken: string, credentialShareRequest?: any, shouldOwn?: boolean): Promise; /** * @description Validates offer response against offer request * @param credentialOfferResponseToken - JWT with credential offer response * @param credentialOfferRequestToken - JWT with credential offer request * @returns { isValid, did, jti, selectedCredentials, errors } * * isValid - boolean, result of the verification * * did - DID of the issuer * * jti - unique identifier for the JWT * * selectedCredentials - array of selected credentials */ verifyCredentialOfferResponseToken(credentialOfferResponseToken: string, credentialOfferRequestToken?: string): Promise; /** * @description Creates JWT of presentation challenge * @param credentialRequirements - array of credential requirements with credential types * @param issuerDid - DID of the issuer * @param options - optional, JwtOptions containing: * * audienceDid (string) - audience of generated token * * expiresAt (isoString) - expire date-time of generated token * * nonce (number) - nonce/jti of generated token * callbackUrl (string) * @returns JWT */ generatePresentationChallenge(credentialRequirements: CredentialRequirement[], issuerDid?: string, options?: JwtOptions): Promise; signUnsignedPresentation(vp: VPV1Unsigned, challenge: string, domain: string): Promise, import("@affinidi/vc-common").VCV1Type, import("@affinidi/vc-common").VCV1Holder, import("@affinidi/vc-common").VCV1Revocation, import("@affinidi/vc-common").VCV1Proof>, import("@affinidi/vc-common").VPV1Type, import("@affinidi/vc-common").VPV1Holder, import("@affinidi/vc-common").VPV1Proof>>; /** * @description Creates VP from VP challenge and credentials * @param challenge - challenge with the requested VCs * @param vcs - array of signed credentials * @returns VPV1 */ createPresentationFromChallenge(challenge: string, vcs: VCV1[], domain: string): Promise; /** * @description Validate status of provided VC * @param credential - the W3c VC * @returns { verified, error } * * verified - boolean, result of the verification * * error - validation error */ checkCredentialStatus(credential: any): Promise<{ verified: boolean; error?: string; }>; /** * @description Validates a VP, and the contained VCs * @param vp - the presentation to be validated * when needed to verify if holder is a subject of VC * @param challenge (optional) - challenge from VP requester to * be compared with challenge in presentation * @returns { isValid, did, challenge, suppliedPresentation, errors } * * isValid - boolean, result of the verification * * did - DID of the VP issuer (holder of the shared VCs) * * challenge - unique identifier for the presentation. * You are responsible for checking this to protect against replay attacks * * suppliedPresentation - the validated presentation * * errors - array of validation errors */ verifyPresentation(vp: unknown, challenge?: string, didDocuments?: any): Promise; /** * Wrapper for Affinity class validateJWT method. * @param token */ validateJWT(token: string): Promise; /** * @description Save's encrypted VCs in Affinity Guardian Wallet * 1. encrypt VCs * 2. store encrypted VCs in Affinity Guardian Wallet * @param data - array of VCs * @param storageRegion (string) - (optional) specify region where credentials will be stored * @returns array of ids for corelated records */ saveCredentials(data: any[], storageRegion?: string): Promise; /** * @description Retrieve only the credential * @param credentialId (string) - id for the VC in vault * @param storageRegion (string) - (optional) specify region where credentials will be stored * @returns a single VC */ getCredentialById(credentialId: string, storageRegion?: string): Promise; /** * @description Retrieve all credentials * @param storageRegion (string) - (optional) specify region where credentials will be stored * @returns array of VC */ getAllCredentials(storageRegion?: string): Promise; /** * @description Retrieve only the credential * @param token (string) - specify credential share request token to filter * @param storageRegion (string) - (optional) specify region where credentials will be stored * @returns array of VCs */ getCredentialsByShareToken(token: string, storageRegion?: string): Promise; /** * @description Delete credential by id * @param credentialId (string) - credential to remove * @param storageRegion (string) - (optional) specify region where credentials will be stored */ deleteCredentialById(credentialId: string, storageRegion?: string): Promise; /** * @description Deletes all credentials from the wallet * @param storageRegion (string) - (optional) specify region where credentials will be stored */ deleteAllCredentials(storageRegion?: string): Promise; /** * @description Searches all of VCs for matches for the given credentialShareRequestToken. * If a token is not given returns all the available credentials * @param credentialShareRequestToken - JWT received from verifier * @returns array of VCs */ getCredentials(credentialShareRequestToken?: string): Promise; /** * @description Decrypts message using user's private key * @param encryptedMessage - message encrypted for you by your public key * @returns decrypted message */ readEncryptedMessage(encryptedMessage: string): Promise; /** * @description Creates encrypted message for another user DID * 1. resolve DID (for whom message will be encrypted) * 2. get public key from resolved DID document * 3. encrypt message using public key of resolved DID * @param did - DID of user for whom message will be sent (only this user * will be able to decrypt it using his private key), * or if DID Document is passed, resolveDid won't happen * @param object - message object which will be send * @returns encryptedMessage - string version of encrypted message */ createEncryptedMessage(did: string | any, object: any): Promise; signJwt(jwtObject: any): Promise; /** * @description Claim credentials from credentialOfferRequestToken callback endpoint * @param credentialOfferRequestToken * @return array of VCs */ claimCredentials(credentialOfferRequestToken: string): Promise; }