Class Keychain

Manages the lifecycle of a key. Keys are encrypted at rest using PKCS #8.

A key in the store has two entries

  • '/info/key-name', contains the KeyInfo for the key
  • '/pkcs8/key-name', contains the PKCS #8 for the key

Hierarchy

  • Keychain

Index

References

Key

Re-exports Key

KeyInfo

Re-exports KeyInfo

PeerId

Re-exports PeerId

Constructors

constructor

  • new Keychain(store: any, options: object): Keychain
  • Creates a new instance of a key chain.

    Parameters

    • store: any

      where the key are.

    • options: object

    Returns Keychain

Properties

opts

opts: any

store

store: any

Accessors

cms

  • get cms(): CMS
  • Gets an object that can encrypt/decrypt protected data using the Cryptographic Message Syntax (CMS).

    CMS describes an encapsulation syntax for data protection. It is used to digitally sign, digest, authenticate, or encrypt arbitrary message content.

    Returns CMS

Static options

  • get options(): any
  • Gets an object that can encrypt/decrypt protected data. The default options for a keychain.

    Returns any

Methods

_getPrivateKey

  • _getPrivateKey(name: string): Promise<string>
  • Gets the private key as PEM encoded PKCS #8 string.

    Parameters

    • name: string

    Returns Promise<string>

createKey

  • createKey(name: string, type: string, size?: number | undefined): Promise<KeyInfo>
  • Create a new key.

    Parameters

    • name: string

      The local key name; cannot already exist.

    • type: string

      One of the key types; 'rsa'.

    • Optional size: number | undefined

    Returns Promise<KeyInfo>

exportKey

  • exportKey(name: string, password: string): Promise<string>
  • Export an existing key as a PEM encrypted PKCS #8 string

    Parameters

    • name: string

      The local key name; must already exist.

    • password: string

      The password

    Returns Promise<string>

findKeyById

  • findKeyById(id: string): Promise<KeyInfo | undefined>
  • Find a key by it's id.

    Parameters

    • id: string

      The universally unique key identifier.

    Returns Promise<KeyInfo | undefined>

findKeyByName

  • findKeyByName(name: string): Promise<KeyInfo>
  • Find a key by it's name.

    Parameters

    • name: string

      The local key name.

    Returns Promise<KeyInfo>

importKey

  • importKey(name: string, pem: string, password: string): Promise<KeyInfo>
  • Import a new key from a PEM encoded PKCS #8 string

    Parameters

    • name: string

      The local key name; must not already exist.

    • pem: string

      The PEM encoded PKCS #8 string

    • password: string

      The password.

    Returns Promise<KeyInfo>

importPeer

  • Import a peer key

    Parameters

    • name: string

      The local key name; must not already exist.

    • peer: PeerId

      The PEM encoded PKCS #8 string

    Returns Promise<KeyInfo>

listKeys

  • List all the keys.

    Returns Promise<KeyInfo[]>

removeKey

  • removeKey(name: string): Promise<KeyInfo>
  • Remove an existing key.

    Parameters

    • name: string

      The local key name; must already exist.

    Returns Promise<KeyInfo>

renameKey

  • renameKey(oldName: string, newName: string): Promise<KeyInfo>
  • Rename a key

    Parameters

    • oldName: string

      The old local key name; must already exist.

    • newName: string

      The new local key name; must not already exist.

    Returns Promise<KeyInfo>

Static generateOptions

  • generateOptions(): any
  • Generates the options for a keychain. A random salt is produced.

    Returns any