import { type SupportedEncodings } from 'uint8arrays'; import { SymmKeyLength, type DID, type Msg, type CharSize, type SymmKey } from './types.js'; import { publicKeyToDid, getPublicKeyAsArrayBuffer } from './util.js'; export { publicKeyToDid, getPublicKeyAsArrayBuffer }; export * from './constants.js'; export type { DID }; export { getPublicKeyAsUint8Array } from './util.js'; export type SerializedKeys = { DID: DID; publicEncryptKey: string; }; /** * Expose RSA keys only for now, because we are * waiting for more browsers to support ECC. * * Create an instance with `Keys.create` b/c async. */ export declare class Keys { private _encryptKey; private _signKey; static _instance: any; persisted: boolean; ENCRYPTION_KEY_NAME: string; SIGNING_KEY_NAME: string; DID: DID; session: boolean; constructor(opts: { keys: { encrypt: CryptoKeyPair; sign: CryptoKeyPair; }; did: DID; persisted: boolean; session: boolean; }); get signKeypair(): CryptoKeyPair; get encryptKeypair(): CryptoKeyPair; get publicSignKey(): CryptoKey; get privateSignKey(): CryptoKey; get privateEncryptKey(): CryptoKey; get publicEncryptKey(): CryptoKey; get deviceName(): Promise; /** * Delete the keys stored in indexedDB. */ delete(): Promise; /** * Get the public encryption key as a string. * * @param {SupportedEncodings} [format] Optional string format for * `uint8arrays`. Defaults to base64. * @returns {string} Return a string b/c mostly would use this for * serializing the public encryption key. */ getPublicEncryptKey: ((format?: SupportedEncodings) => Promise) & { uint8Array: () => Promise; }; /** * Return a 32-character, DNS-friendly hash of the given DID. * * @param {DID} did a DID format string * @returns {string} 32 character, base32 hash of the DID */ static deviceName(did: DID): Promise; /** * Create a new `Keys` instance. * * @returns {Promise} */ static create(opts?: { session: boolean; }): Promise; /** * Save this keys instance to `indexedDB`. */ persist(): Promise; /** * Return a 32-character, DNS friendly hash of the public signing key. * * @returns {Promise} */ getDeviceName(): Promise; /** * Restore some keys from indexedDB, or create a new keypair if it doesn't * exist yet. * * @param {{ encryptionKeyName, signingKeyName }} opts Strings to use as * keys in indexedDB. * @returns {Promise} */ static load(opts?: Partial<{ encryptionKeyName: string; signingKeyName: string; session: boolean; }>): Promise>; decrypt: ((msg: string | Uint8Array | ArrayBuffer, keysize?: SymmKeyLength) => Promise) & { asString: (msg: string, keysize?: SymmKeyLength) => Promise; }; sign: ((msg: Msg, charsize?: CharSize) => Promise) & { /** * Sign a message, return the signature as a base64 encoded string. * * @param {Msg} msg The message to sign * @param {CharSize} [charsize] Character size * @returns {Promise} */ asString: (msg: Msg, charsize?: CharSize) => Promise; }; /** * Decrypt the given encrypted AES key. * Return the key as `Uint8Array`. */ decryptKey: ((key: string | Uint8Array | ArrayBuffer) => Promise) & { /** * Decrypt the given AES key, return the result as a string. */ asString: (msg: string | Uint8Array, format?: SupportedEncodings) => Promise; }; /** * Serialize this keys instance. Will return an object of * { DID, publicEncryptionKey }, where DID is the public signature key, * and `publicEncryptKey` is the encryption key, `base64` encoded. * @returns {Promise<{ DID:DID, publicEncryptKey:string }>} */ toJson(): Promise<{ DID: DID; publicEncryptKey: string; }>; } /** * Check that the given signature is valid with the given message. */ export declare function verify(msg: string | Uint8Array, sig: string | Uint8Array, signingDid: DID): Promise; /** * Encrypt the given message to the given public key. If an AES key is not * provided, one will be created. Use an AES key to encrypt the given * content, then we encrypt the AES key to the given public key. * * @param {{ content, publicKey }} opts The content to encrypt and * public key to encrypt to * @param {SymmKey|Uint8Array|string} [aesKey] An optional AES key to encrypt * to the given public key * @returns {Promise} The encrypted AES key, concattenated with * the encrypted content. */ export declare function encryptTo(opts: { content: string | Uint8Array; publicKey: CryptoKey | string; }, aesKey?: SymmKey | Uint8Array | string): Promise; export declare namespace encryptTo { var asString: (opts: { content: string | Uint8Array; publicKey: CryptoKey | string; }, aesKey?: SymmKey | Uint8Array | string) => Promise; } export declare const AES: { create(opts?: { alg: string; length: number; }): Promise; export: ((key: CryptoKey) => Promise) & { asString: (key: CryptoKey, format?: SupportedEncodings) => Promise; }; import(key: Uint8Array | string): Promise; exportAsString(key: CryptoKey): Promise; encrypt: typeof encrypt; decrypt(encryptedData: Uint8Array | string | ArrayBuffer, cryptoKey: CryptoKey | Uint8Array | ArrayBuffer, iv?: Uint8Array): Promise; }; export declare function encryptKeyTo({ key, publicKey }: { key: string | Uint8Array | CryptoKey; publicKey: CryptoKey | Uint8Array | string; }, format: 'arraybuffer'): Promise; export declare function encryptKeyTo({ key, publicKey }: { key: string | Uint8Array | CryptoKey; publicKey: CryptoKey | Uint8Array | string; }, format: 'uint8array'): Promise; export declare function encryptKeyTo({ key, publicKey }: { key: string | Uint8Array | CryptoKey; publicKey: CryptoKey | Uint8Array | string; }, format?: undefined): Promise; export declare namespace encryptKeyTo { var asString: ({ key, publicKey }: { key: string | Uint8Array | CryptoKey; publicKey: CryptoKey | string | Uint8Array; }, format?: SupportedEncodings) => Promise; } declare function encrypt(data: Uint8Array, cryptoKey: CryptoKey | Uint8Array, format?: undefined, iv?: Uint8Array): Promise; declare function encrypt(data: Uint8Array, cryptoKey: CryptoKey | Uint8Array, format: 'uint8array', iv?: Uint8Array): Promise; declare function encrypt(data: Uint8Array, cryptoKey: CryptoKey | Uint8Array, format: 'arraybuffer', iv?: Uint8Array): Promise; export declare function getDeviceName(did: DID | string): Promise; //# sourceMappingURL=index.d.ts.map