browser-crypto-secure-store
Version:
Securely store Crypto Keys in the browser
93 lines (87 loc) • 2.92 kB
TypeScript
/**
* @beta
*
* CryptoKeyPairOptions is an object containing optional arguments supplied as options in SetKeyOptions.
*
* See [SubtleCrypto.generateKey()](https://developer.mozilla.org/en-US/docs/Web/API/SubtleCrypto/generateKey)
*/
export declare type CryptoKeyPairOptions = {
algorithm: RsaHashedKeyGenParams | EcKeyGenParams | HmacKeyGenParams | AesKeyGenParams;
extractable: false;
keyUsages: KeyUsage[];
};
/**
* @beta
*/
export declare interface CryptoKeyPairStore {
set(key: string, value: CryptoKeyPair | CryptoKey): Promise<void>;
get(key: string): Promise<CryptoKeyPair | CryptoKey>;
remove(key: string): Promise<void>;
getAllKeys(): Promise<string[]>;
}
/**
* @beta
*
* SecureStore is a class that provides a secure way to store and retrieve CryptoKeyPairs.
*
* By default it uses IndexedDb to store CryptoKeyPairs with non extractable private keys.
*/
export declare class SecureStore {
private cryptoKeyPairStore;
/**
* Creates a new instance of SecureStore using indexedDb as the storage mechanism.
*
* @param args - An object containing optional arguments.
*/
constructor({ cryptoKeyPairStore, dbName, storeName, }?: SecureStoreOptions);
/**
* Generates a new CryptoKeyPair and stores it in the SecureStore.
*
* @param args - A SeyKeyOptions object containing the key name and optional arguments.
* @returns - A CryptoKeyPair or CryptoKey.
*/
setKey({ key, options, ttl, }: SetKeyOptions): Promise<CryptoKeyPair | CryptoKey>;
/**
* Retrieves a CryptoKeyPair from the SecureStore.
* @param key - the name of the key to retrieve.
*/
getKey(key: string): Promise<CryptoKeyPair>;
/**
* Removes a CryptoKeyPair from the SecureStore.
* @param key - the name of the key to remove.
*/
removeKey(key: string): Promise<void>;
/**
* Retrieves all the names of all keys stored in the SecureStore.
* @returns An array of key names.
*/
getAllKeys(): Promise<string[]>;
setTtl(key: string, ttl: number): Promise<void>;
}
/**
* @beta
*
* SecureStoreOptions is an object containing optional arguments for the SecureStore constructor.
*
*/
export declare type SecureStoreOptions = {
cryptoKeyPairStore?: CryptoKeyPairStore;
dbName?: string;
storeName?: string;
};
/**
* @beta
*
* SetKeyOptions is an object containing arguments for the setKey method.
*
* key - The name of the key to store.
* options - An object containing optional arguments for the CryptoKeyPair. See https://developer.mozilla.org/en-US/docs/Web/API/SubtleCrypto/generateKey.
* ttl - The time to live for the key in seconds.
*
*/
export declare type SetKeyOptions = {
key: string;
options?: CryptoKeyPairOptions;
ttl?: number;
};
export { }