import { SymmAlg } from "keystore-idb/types.js" export { SymmAlg } export type ImplementationOptions = { exchangeKeyName: string storeName: string writeKeyName: string } export type Implementation = { aes: { // Related to AES-GCM, this should be able to decrypt both: // (a) with the `iv` prefixed in the cipher text (first 16 bytes), and (b) with a given `iv` decrypt: (encrypted: Uint8Array, key: CryptoKey | Uint8Array, alg: SymmAlg, iv?: Uint8Array) => Promise // Related to AES-GCM, this will produce a cipher text with // a random `iv` prefixed into it. Unless, you provide the `iv` as a parameter. encrypt: (data: Uint8Array, key: CryptoKey | Uint8Array, alg: SymmAlg, iv?: Uint8Array) => Promise exportKey: (key: CryptoKey) => Promise genKey: (alg: SymmAlg) => Promise } did: { /** * Using the key type as the record property name (ie. string = key type) * * The magic bytes are the `code` found in https://github.com/multiformats/multicodec/blob/master/table.csv * encoded as a variable integer (more info about that at https://github.com/multiformats/unsigned-varint). * * The key type is also found in that table. * It's the name of the codec minus the `-pub` suffix. * * Example * ------- * Ed25519 public key * Key type: "ed25519" * Magic bytes: [ 0xed, 0x01 ] */ keyTypes: Record< string, { magicBytes: Uint8Array verify: (args: VerifyArgs) => Promise } > } hash: { sha256: (bytes: Uint8Array) => Promise } keystore: { clearStore: () => Promise decrypt: (encrypted: Uint8Array) => Promise exportSymmKey: (name: string) => Promise getAlgorithm: () => Promise // This goes hand in hand with the DID keyTypes record getUcanAlgorithm: () => Promise importSymmKey: (key: Uint8Array, name: string) => Promise keyExists: (keyName: string) => Promise publicExchangeKey: () => Promise publicWriteKey: () => Promise sign: (message: Uint8Array) => Promise } misc: { randomNumbers: (options: { amount: number }) => Uint8Array } rsa: { // Used for exchange keys only decrypt: (data: Uint8Array, privateKey: CryptoKey | Uint8Array) => Promise encrypt: (message: Uint8Array, publicKey: CryptoKey | Uint8Array) => Promise exportPublicKey: (key: CryptoKey) => Promise genKey: () => Promise } } export type VerifyArgs = { message: Uint8Array publicKey: Uint8Array signature: Uint8Array }