Protected_Protected_Have these keys been deleted? A deleted keypair is terminal -- the key material is gone, and any use of it throws.
ReadonlyexchangeThe indexedDB names this keypair was loaded from, and the names
persist and delete will use.
ReadonlywriteStatic_StaticEXCHANGE_StaticINFOStaticTYPEStaticWRITE_The machine-readable name for this keypair.
Drop the in-memory key material. Internal -- call delete instead.
Decrypt the given message. The encrypted message should be ephemeral public key + salt + iv + cipher text.
The ephemeral public key is extracted from the beginning of the message and used with our private key to derive the AES decryption key.
The encrypted content
OptionalaesAlgorithm: string | null
The algorithm. Default is AES-GCM.
Optionalinfo: string | null
Custom "info" parameter
OptionalaesKey: string | Uint8Array<ArrayBufferLike> | CryptoKey | null
Use this exact AES key
instead of deriving one from ECDH. Must match the aesKey
passed to the corresponding encrypt call.
The decrypted content.
Decrypt and return as string using ECIES. The encrypted message should be ephemeral public key + salt + iv + cipher text.
The ephemeral public key is extracted from the beginning of the message and used with our private key to derive the AES decryption key.
The encrypted content
OptionalaesAlgorithm: string | null
The algorithm. Default is AES-GCM.
Optionalinfo: string | null
Custom "info" parameter
OptionalaesKey: string | Uint8Array<ArrayBufferLike> | CryptoKey | nullThe decrypted content as a string.
Delete this keypair. This deletes the keys from indexedDB, drops the
in-memory key material, and clears the instance cache, so load will
not hand out these keys again.
After this, the instance is destroyed -- using it throws
a KeysDeletedError.
Encrypt the given content to the given public key, or encrypt to our own public key if a key is not passed in.
This does ECIES style encryption -- a new ephemeral keypair is generated and used to encrypt the message with ephemeral private + recipient public. The public key from the ephemeral keypair is prefixed to the cipher text.
Content to encrypt
Optionalrecipient: string | CryptoKey | null
Their public key. Optional b/c we will use our own public key if not passed in. Can be a CryptoKey or a base64 encoded string.
Optionalinfo: string | null
info tag for HKDF. Default is the class property.
OptionalaesKey: string | Uint8Array<ArrayBufferLike> | CryptoKey | null
Use this exact AES key
instead of deriving one from ECDH. Not relevant for most use
cases. Pass the same key to decrypt to read it back.
Optionalkeysize: SymmKeyLength | null
Default is 256
Buffer of ephemeral-public-key + salt + iv + cipher text
Encrypt and return as base64 string.
Optionalrecipient: string | CryptoKey | nullOptionalinfo: string | nullOptionalaesKey: string | Uint8Array<ArrayBufferLike> | CryptoKey | nullOptionalkeysize: SymmKeyLength | nullDo DHKE, create a new AES-GCM key.
The HKDF salt is either supplied by the caller (so both sides can
re-derive the exact same key later) or generated at random, in
which case it is returned as a .salt (base64) property on the
key so the caller can persist it for later re-derivation.
OptionalpublicKey: string | CryptoKey | null
Public key to use in DHKE. Will use our public key if it is not passed in.
Optionalinfo: string | null
The info parameter for DHKE. Will use the class
property INFO if it is not passed in.
Optionalsalt: string | ArrayBuffer | Uint8Array<ArrayBufferLike> | null
Reuse this salt instead of generating a random one -- pass the same salt on both sides to re-derive the same key.
New AES key, with a .salt (base64) property
Return a 32-character, DNS friendly hash of the public signing key.
Save this keys instance to indexedDB.
Optionalformat: SupportedEncodingsOptionalformat: SupportedEncodingsSign the given content and return as base64 string.
Optional_charsize: CharSizeSerialize this keys instance. Will return an object of
{ DID, publicExchangeKey }, where DID is the public write key,
and publicExchangeKey is the encryption key, base64 encoded.
Optionalformat: SupportedEncodingsUnwrap a content key that another device wrapped for this device
with wrap.
The recipient device uses its private key + the ephemeral public key to rederive the KEK and decrypt the wrapped content key.
The wrap's signature is always checked against signer before
anything is decrypted, and this throws if the signature is missing
or invalid. signer must be the DID of the device you expect the
key from, obtained over a channel an attacker cannot tamper with.
A DID that travels alongside the wrapped key proves nothing, since
an attacker who can swap the wrapped key can swap the DID too.
The { enc, wrappedKey, signature } object returned
by wrap.
The DID of the expected sender.
Optionalextractable?: booleanCan the returned key be exported with
crypto.subtle.exportKey? Default true.
Optionalinfo?: stringThe HKDF info string. Must match what was passed to
wrap. Defaults to 'key-wrap'.
The unwrapped AES content key.
"Add a device," meaning, take an existing AES key and add the ability for a new keypair to decrypt/use the AES key.
This implements HPKE-style key wrapping:
The result is signed with our Ed25519 write key, so the recipient
can verify who created the wrap. unwrap requires our DID and
rejects the wrap unless the signature matches it.
The existing AES key used to encrypt the content. Can be a base64 encoded string.
The new device's public X25519 key.
Optionalinfo: string
Optional info parameter for HKDF. Defaults to 'key-wrap'.
The ephemeral public key (base64), the wrapped AES key (base64), and a signature (base64) by our write key.
Static_Static_Static_If the cached instance was loaded from the given names, then its keys are gone too. Destroy it, and clear the cache. Internal.
Static_The indexedDB names for this class, optionally prefixed with dbKey.
Pure -- never writes to the class statics.
OptionaldbKey: stringStaticcreateFactory function.
Optionalsession: boolean
Session only? i.e., not saved in indexedDB.
Default false.
Optionalextractable: boolean
Can we extract the private keys? Default
false.
Optionalkeys: {Key options.
dbKey prefixes the IndexedDB names used for both keypairs.
A new class instance.
StaticdeleteDelete a stored keypair without loading it first. Deletes the keys from indexedDB, and destroys the cached instance, if there is one for these names.
Optionalopts: { encryptionKeyName?: string; writeKeyName?: string } = {}
The indexedDB names to delete. Defaults to this class's names.
StaticdeviceReturn a 32-character, DNS-friendly hash of the given DID.
A DID format string
32 character, base32 hash of the DID
StaticexistStaticloadRestore some keys from indexedDB, or create a new keypair if it doesn't exist yet. Overrides base class to use ECC-specific key names.
Saves the keys to indexedDB before returning, unless you pass
{ persist: false }.
Optionalopts: Partial<Prefix for both IndexedDB key names.
Class for ECC keys