Crypto Lib
    Preparing search index...

    Class Keyring

    In-memory keyring for storing, looking up, rotating, and exporting keys.

    Index
    • get size(): number

      Number of keys in the keyring (including archived).

      Returns number

    • Deserialize a keyring from a JSON string produced by serialize().

      Parameters

      • json: string

      Returns Keyring

    • Decrypt and restore a keyring from an encrypted blob.

      Parameters

      • key: string | Uint8Array<ArrayBufferLike>

        256-bit key (hex or bytes).

      • encrypted: string

        Base64-encoded encrypted keyring.

      Returns Keyring

    • Generate a new key pair and add it to the keyring.

      Parameters

      • algorithm:
            | "ed25519"
            | "x25519"
            | "ed448"
            | "x448"
            | "p256"
            | "p384"
            | "ml-kem-512"
            | "ml-kem-768"
            | "ml-kem-1024"
            | "ml-dsa-44"
            | "ml-dsa-65"
            | "ml-dsa-87"
      • metadata: KeyMetadata = {}

      Returns KeyEntry

    • Delete a key from the keyring.

      Parameters

      • kid: string

      Returns boolean

    • List all keys matching the optional filters.

      Parameters

      • Optionalfilters: {
            algorithm?:
                | "ed25519"
                | "x25519"
                | "ed448"
                | "x448"
                | "p256"
                | "p384"
                | "ml-kem-512"
                | "ml-kem-768"
                | "ml-kem-1024"
                | "ml-dsa-44"
                | "ml-dsa-65"
                | "ml-dsa-87";
            use?: "sig"
            | "enc";
            includeArchived?: boolean;
        }

      Returns KeyEntry[]

    • Rotate a key: archive the current one and generate a new key with the same algorithm and metadata.

      Parameters

      • kid: string

      Returns KeyEntry

      The new key entry.

    • Export public keys as a JWKS (JSON Web Key Set). Only supports Ed25519 and X25519 keys.

      Returns Jwks

    • Serialize the keyring to a JSON string. WARNING: contains private keys. Use toEncrypted() for secure storage.

      Returns string

    • Encrypt the keyring with a password using secretbox.

      Parameters

      • key: string | Uint8Array<ArrayBufferLike>

        256-bit key (hex or bytes).

      Returns string