import { BaseNativeObject, BaseReleasableObject } from "./BaseNativeObject"; import { PowerAuthEncryptionHttpHeader } from "../index"; import { PowerAuthDataFormat } from "./PowerAuthDataFormat"; /** * Scope of encryptor. */ export type PowerAuthEncryptorScope = 'APPLICATION' | 'ACTIVATION'; /** * Interface representing encrypted data in request or response. */ export interface PowerAuthCryptogram { /** * Temporary key identifier. */ readonly temporaryKeyId: string; /** * Ephemeral public key, valid only for encrypted request. */ readonly ephemeralPublicKey?: string; /** * Encrypted data, valid for request and response. */ readonly encryptedData: string; /** * Message authenticated code, valid for request and response. */ readonly mac: string; /** * Nonce, valid for encrypted request. */ readonly nonce?: string; /** * Timestamp of request or response in milliseconds since 1.1.1970. */ readonly timestmap: number; } /** * Object returned from the `encryptRequest()` function. */ export interface PowerAuthEncryptedRequestData { /** * Cryptogram with encrypted request data. */ readonly cryptogram: PowerAuthCryptogram; /** * HTTP request header. You must include this header to your HTTP request * to properly decrypt the request data on the server. * * If you plan to combine encryption with PowerAuth Symmetric Signature, then * the header can be ommitted. */ readonly header: PowerAuthEncryptionHttpHeader; /** * Object that can decrypt encrypted response received from the server. */ readonly decryptor: PowerAuthDecryptor; } /** * Interface that implements End-To-End encryption. Use `PowerAuth` class to get instnace * of encryptor. */ export interface PowerAuthEncryptor extends BaseReleasableObject { /** * Scope of this encryptor. */ readonly encryptorScope: PowerAuthEncryptorScope; /** * Determine whether encryptor can encrypt the request. * * The encryptor is reusable, so this method typically returns `true`, unless the parent * `PowerAuth` instance is deconfigured or has no longer valid activation (if activation scoped). */ canEncryptRequest(): Promise; /** * Encrypt the request data. * @param body UTF8 encoded string to encrypt. * @returns Object containing encrypted data, HTTP header and decryptor for the response decryption. */ encryptRequest(body: string): Promise; /** * Encrypt the request data. * @param body Data to encrypt. By default plain string is expected, but you can use `bodyFormat` parameter to specify Base64 encoded string at input. * @param bodyFormat Specify encoding of `body` parameter. The default value is `UTF8`, so plain string is expected in `body` parameter. * @returns Object containing encrypted data, HTTP header and decryptor for the response decryption. */ encryptRequest(body: string, bodyFormat: PowerAuthDataFormat): Promise; } /** * Interface defining decryptor that is capable to decrypt encrypted response received from the server. * * Be aware that the native underlying object has a limited lifetime set to 5 minutes. If you don't decrypt * the resposne within this time interval, then the information required for the request decryption is lost. */ export interface PowerAuthDecryptor extends BaseReleasableObject { /** * Scope of this decryptor. */ readonly decryptorScope: PowerAuthEncryptorScope; /** * Determine whether object is able to decrypt the response. */ canDecryptResponse(): Promise; /** * Decrypt the response received from the server. The underlying native object is automatically released * after this call. * * @param cryptogram Cryptogram containing encrypted response from the server. * @param outputDataFormat Data format expected at the output. If not used, then 'UTF8' is applied. * @returns Decrypted data in specified format. */ decryptResponse(cryptogram: PowerAuthCryptogram, outputDataFormat: PowerAuthDataFormat): Promise; /** * Decrypt response received from the server into plain string. The underlying native object is automatically * released after this call. * @param cryptogram Cryptogram containing encrypted response from the server. * @returns Decrypted string. */ decryptResponse(cryptogram: PowerAuthCryptogram): Promise; } /** * Class that implements End-To-End encryption. Use `PowerAuth` class to get instnace * of properly scoped encryptor. */ export declare class PowerAuthEncryptorImpl extends BaseNativeObject implements PowerAuthEncryptor { canEncryptRequest(): Promise; encryptRequest(body: string, bodyFormat?: PowerAuthDataFormat): Promise; /** * Scope of this encryptor. */ readonly encryptorScope: PowerAuthEncryptorScope; /** * Instance identifier of PowerAuth instance owning this encryptor. */ private readonly powerAuthInstanceId; /** * Autorelease time in ms. */ private readonly autoreleaseTime; /** * Construct encryptor object and specify its scope. * @param scope Scope of the encryptor. * @param powerAuthInstanceId Instance identifier of PowerAuth class owning this encryptor. * @param autoreleaseTime Autorelease timeout in milliseconds. The value is used only for the testing purposes, and is ignored in the release build of library. */ constructor(scope: PowerAuthEncryptorScope, powerAuthInstanceId: string, autoreleaseTime?: number); protected onCreate(): Promise; protected onRelease(objectId: string): Promise; }