import { Logger, SudoKeyManager } from '@sudoplatform/sudo-common'; import { SudoUserClient } from '@sudoplatform/sudo-user'; import localForage from 'localforage'; import { ApiClient } from '../client/apiClient'; import { S3Client } from '../core/s3Client'; import { SecureClaimInput } from '../gen/graphql-types'; import { FetchOption, Sudo } from './sudo'; import { ChangeType, SudoSubscriber } from './sudo-subscriber'; export interface SudoProfileOptions { sudoUserClient: SudoUserClient; apiClient?: ApiClient; s3Client?: S3Client; blobCache?: typeof localForage; logger?: Logger; keyManager?: SudoKeyManager; } export declare enum ClaimVisibility { /** * Claim is only accessible by the user, i.e. it's encrypted using the user's key. */ Private = 0, /** * Claim is accessible by other users in Sudo platform. */ Public = 1 } /** * Interface encapsulating a library of functions for calling Sudo service and managing Sudos. */ export interface SudoProfilesClient { /** * Creates a new Sudo * * @param sudo Sudo to create. * * @return Sudo: The new Sudo * * @throws IllegalStateError * @throws InsufficientEntitlementsError * @throws ServiceError * @throws UnknownGraphQLError * @throws FatalError */ createSudo(sudo: Sudo): Promise; /** * Updates a Sudo. * * @param sudo Sudo to update. * @param keyId new claims keyId * * @return Sudo: The updated Sudo * * @throws IllegalArgumentException * @throws IllegalStateError * @throws VersionMismatchError * @throws UploadError * @throws ServiceError * @throws UnknownGraphQLError * @throws FatalError */ updateSudo(sudo: Sudo, keyId: string): Promise; /** * Retrieves a signed ownership proof for the specified owner. The ownership proof JWT has the * following payload. * { * "jti": "DBEEF4EB-F84A-4AB7-A45E-02B05B93F5A3", * "owner": "cd73a478-23bd-4c70-8c2b-1403e2085845", * "iss": "sudoplatform.sudoservice", * "aud": "sudoplatform.virtualcardservice", * "exp": 1578986266, * "sub": "da17f346-cf49-4db4-98c2-862f85515fc4", * "iat": 1578982666 * } * * "owner" is an unique ID of an identity managed by the issuing serivce. In case of Sudo * service this represents unique reference to a Sudo. "sub" is the subject to which this * proof is issued, i.e. the user. "aud" is the target audience of the proof. * * @param sudoId Sudo Id to generated an ownership proof for. * @param audience target audience for this proof. * * @return String: The JWT * * @throws ServiceError * @throws UnknownGraphQLError * @throws FatalError */ getOwnershipProof(sudoId: string, audience: string): Promise; /** * Retrieves all Sudos owned by the signed in user. * * @param fetchPolicy option for controlling the behaviour of this API. Refer to `FetchOption` enum. * * @return Sudo[]: An array of Sudos * * @throws DownloadError * @throws ServiceError * @throws UnknownGraphQLError * @throws FatalError */ listSudos(fetchPolicy?: FetchOption): Promise; /** * Reset any internal state and cached content. */ reset(): Promise; /** * Subscribes to be notified of new, updated and deleted Sudos. Blob data is not downloaded automatically * so the caller is expected to use `listSudos` API if they need to access any associated blobs. * * @param id unique ID for the subscriber. * @param subscriber subscriber to notify. * * @throws NotSignedInError */ subscribeAll(id: string, subscriber: SudoSubscriber): Promise; /** * Subscribes to be notified of new, updated or deleted Sudos. Blob data is not downloaded automatically * so the caller is expected to use `listSudos` API if they need to access any associated blobs. * * @param id unique ID for the subscriber. * @param changeType change type to subscribe to. * @param subscriber subscriber to notify. * * @throws NotSignedInError */ subscribe(id: string, changeType: ChangeType, subscriber: SudoSubscriber): Promise; /** * Unsubscribes the specified subscriber so that it no longer receives notifications about * new, updated or deleted Sudos. * * @param id unique ID for the subscriber. * @param changeType change type to unsubscribe from. */ unsubscribe(id: string, changeType: ChangeType): void; /** * Unsubscribe all subscribers from receiving notifications about new, updated or deleted Sudos. */ unsubscribeAll(): void; /** * Deletes a Sudo. * * @param sudo Sudo to delete. * * @return void * * @throws IllegalArgumentError * @throws FatalError * @throws SudoNotFoundError */ deleteSudo(sudo: Sudo): Promise; /** * Adds a key value pair to the store (keyId, key), then sets that keyId as the pointer to the current symmetric key to use. * * As symmetric keys can be rotated, this will also allow a list of symmetric keys to exist in the store in which to decrypt * older sudo claims with if needed and also give the ability to set the current symmetric key. * * The last symmetric key pushed will be set to the current active symmetric key. * * @param keyId The keyId that points to the symmetric key used for encrypting claims * @param key The symmetric key to encrypt claims with */ pushSymmetricKey(keyId: string, key: string): Promise; } export declare class DefaultSudoProfilesClient implements SudoProfilesClient { private static readonly Constants; private readonly _apiClient; private readonly _sudoUserClient; private readonly _keyManager; private readonly _s3Client; private readonly _blobCache; private readonly _logger; private readonly _onCreateSudoSubscriptionManager; private readonly _onUpdateSudoSubscriptionManager; private readonly _onDeleteSudoSubscriptionManager; constructor(options: SudoProfileOptions); createSudo(sudo: Sudo): Promise; updateSudo(sudo: Sudo): Promise; getOwnershipProof(sudoId: string, audience: string): Promise; listSudos(fetchPolicy?: FetchOption): Promise; reset(): Promise; subscribeAll(id: string, subscriber: SudoSubscriber): Promise; subscribe(id: string, changeType: ChangeType, subscriber: SudoSubscriber): Promise; unsubscribe(id: string, changeType: ChangeType): void; unsubscribeAll(): void; pushSymmetricKey(keyId: string, key: string): Promise; private executeCreateSudoSubscriptionWatcher; deleteSudo(sudo: Sudo): Promise; private deleteSecureS3Object; private getSudo; private executeUpdateSudoSubscriptionWatcher; private executeDeleteSudoSubscription; /** * Map between ListSudosQuery.Item and Sudo * @param items * @param option * @param processS3Object */ private processListSudos; private getObjectId; /** * Get default symmetric key Id */ private getSymmetricKeyId; protected createSecureString(name: string, value: string): Promise; private processSecureClaim; }