/// import { PrivateKey, PublicKey, SHAStringType, SymmetricKey } from "unicrypto"; import { BossObject, UniversalKey } from "uparsecjs"; import { MapSerializable } from "./MapSerializer"; export interface SymmetricKeyAnnotation { type: "SymmetricKeyAnnotation"; id: Uint8Array; } export interface RSAKeyAnnotation { type: "RSAKeyAnnotation"; id: Uint8Array; } /** * Supported hashes used in annotation key digests, mainly, in password * generators PBKDF2 and like */ export declare type AnnotatedKeyDigestType = "SHA256" | "SHA512" | "SHA3_256" | "SHA3_384"; export interface PasswordKeyAnnotation { type: "PasswordKeyAnnotation"; id: Uint8Array; digest: AnnotatedKeyDigestType; rounds: number; salt: Uint8Array; fullLength: number; keyOffset: number; keyLength: number; } export declare type KeyAnnotation = PasswordKeyAnnotation | RSAKeyAnnotation | SymmetricKeyAnnotation; /** * Convert [KeyAnnotation] fo a serialized form suitable for MyOnlyCloud binary serialization. * @param annotation to serialize */ export declare function serializeKeyAnnotation(annotation: KeyAnnotation): BossObject; /** * Deserializes MyOnlyCould-serialized KeyAnnotation */ export declare function deserializeKeyAnnotation(_source: BossObject): KeyAnnotation; export declare function annotationLabel(keyAnnotation: KeyAnnotation): string; export declare type SupportedAnnotatedKeys = SymmetricKey | PrivateKey | PublicKey; export declare class AnnotatedKey implements MapSerializable { readonly key: SupportedAnnotatedKeys; readonly annotation: KeyAnnotation; static Exception: { new (message?: string | undefined): { name: string; message: string; stack?: string | undefined; }; captureStackTrace(targetObject: object, constructorOpt?: Function | undefined): void; prepareStackTrace?: ((err: Error, stackTraces: NodeJS.CallSite[]) => any) | undefined; stackTraceLimit: number; }; constructor(key: SupportedAnnotatedKeys, annotation: KeyAnnotation); private _label?; get annotationLabel(): string; /** * The promise to the separately packed key. To pack the whole annotated key use * [[MapSerializer.toBoss]] */ get packedKey(): Promise; etaEncrypt(ciphertext: Uint8Array): Promise; etaDecrypt(plaintext: Uint8Array): Promise; matchesAnnotation(annotation: KeyAnnotation): boolean; equalsTo(otherKey: AnnotatedKey | PrivateKey | PublicKey): boolean; static createRandomSymmetric(): AnnotatedKey; static createPrivate(bitStrength?: number): Promise; static fromPassword(password: string, salt: Uint8Array | string, rounds: number, digest?: AnnotatedKeyDigestType): Promise; static fromAsymmetricKey(key: PublicKey | PrivateKey): AnnotatedKey; static fromUniversalKey(uk: UniversalKey): Promise; toMap(): Promise; static fromMap(source: BossObject): Promise; } /** * Convert `unicrypto` hash algorithm name to the the annotated key's label. See [[SHA]] for example. * @param hashAlgorithm as recognized by unicrypto * @return converted label * @throws AnnotatedKey.Exception if the name of the hash is not supported bu annotated keys infrastructure */ export declare function toAnnotatedKeyHashType(hashAlgorithm: SHAStringType): AnnotatedKeyDigestType; /** * Convert annotated key hash type tag to a string that `unicrypto` library supports in its [[SHA]] module/ * @param algorithm as specified in annotated keys, for example in [[PasswordKeyAnnotation]] * @return string with hash type that `unicrypto` [[SHA]] understands. */ export declare function fromAnnotatedKeyHashType(algorithm: AnnotatedKeyDigestType): SHAStringType; export declare function hashDigest(algorithm: AnnotatedKeyDigestType, data: Uint8Array | string): Promise; export declare function hashDigest64(algorithm: AnnotatedKeyDigestType, data: Uint8Array | string): Promise; export declare function hashDigest64Compact(algorithm: AnnotatedKeyDigestType, data: Uint8Array | string): Promise;