Skip to content

Latest commit

 

History

History
104 lines (82 loc) · 1.94 KB

CRYPTO_STORAGE.md

File metadata and controls

104 lines (82 loc) · 1.94 KB

CryptoStorage

WARNING: This is not compliant with the W3 WebCrypto specification.

Interfaces

CryptoStorage interface

Base interface for all crypto storages

Used by:

/**
 * Base generic interface for crypto storages
 */
interface CryptoStorage<T> {
  /**
   * Returns list of indexes from storage
   */
  keys(): Promise<string[]>;

  /**
   * Returns index of item in storage
   * @param item Crypto item
   * @returns Index of item in storage otherwise null
   */
  indexOf(item: T): Promise<string | null>;

  /**
   * Add crypto item to storage and returns it's index
   */
  setItem(item: T): Promise<string>;

  /**
   * Returns crypto item from storage by index
   * @param index index of crypto item
   * @returns Crypto item
   * @throws Throws Error when cannot find crypto item in storage
   */
  getItem(index: string): Promise<T>;

  /**
   * Returns `true` if item is in storage otherwise `false`
   * @param item Crypto item
   */
  hasItem(item: T): Promise<boolean>;

  /**
   * Removes all items from storage
   */
  clear(): Promise<void>;

  /**
   * Removes crypto item from storage by index
   * @param index Index of crypto storage
   */
  removeItem(index: string): Promise<void>;

}

CryptoStorages interface

Interface for Crypto extending. Adds properties for storages getting.

interface CryptoStorages {
  keyStorage: CryptoKeyStorage;
  certStorage: CryptoCertificateStorage;
}

Operations

Keys getting

const indexes = await storage.keys();
// ["0001", "0002", ...]

Index of

const index = await storage.indexOf(key);
// "0001"

Set item

const index = await storage.setItem(cert);
// "0001"

Get item

const cert = await storage.getItem("0001");

Remove item

await storage.removeItem("0001");