interface Keychain {
    exportKey(name): Promise<PrivateKey>;
    findKeyById(id): Promise<KeyInfo>;
    findKeyByName(name): Promise<KeyInfo>;
    importKey(name, key): Promise<KeyInfo>;
    listKeys(): Promise<KeyInfo[]>;
    removeKey(name): Promise<KeyInfo>;
    renameKey(oldName, newName): Promise<KeyInfo>;
    rotateKeychainPass(oldPass, newPass): Promise<void>;
}

Methods

  • Export an existing private key.

    Parameters

    • name: string

    Returns Promise<PrivateKey>

    Example

    import { generateKeyPair } from '@libp2p/crypto/keys'

    const key = await generateKeyPair('Ed25519')
    const keyInfo = await libp2p.keychain.importKey('my-key', key)
    const key = await libp2p.keychain.exportKey(keyInfo.id)
  • Find a key by id

    Parameters

    • id: string

    Returns Promise<KeyInfo>

    Example

    import { generateKeyPair } from '@libp2p/crypto/keys'

    const key = await generateKeyPair('Ed25519')
    const keyInfo = await libp2p.keychain.importKey('my-key', key)
    const keyInfo2 = await libp2p.keychain.findKeyById(keyInfo.id)
  • Find a key by name

    Parameters

    • name: string

    Returns Promise<KeyInfo>

    Example

    import { generateKeyPair } from '@libp2p/crypto/keys'

    const key = await generateKeyPair('Ed25519')
    const keyInfo = await libp2p.keychain.importKey('my-key', key)
    const keyInfo2 = await libp2p.keychain.findKeyByName(keyInfo.name)
  • Import a new private key.

    Parameters

    Returns Promise<KeyInfo>

    Example

    import { generateKeyPair } from '@libp2p/crypto/keys'

    const key = await generateKeyPair('Ed25519')
    const keyInfo = await libp2p.keychain.importKey('my-key', key)
  • Removes a key from the keychain.

    Parameters

    • name: string

    Returns Promise<KeyInfo>

    Example

    await libp2p.services.keychain.createKey('keyTest', 'RSA', 4096)
    const keyInfo = await libp2p.services.keychain.removeKey('keyTest')
  • Rename a key in the keychain. This is done in a batch commit with rollback so errors thrown during the operation will not cause key loss.

    Parameters

    • oldName: string
    • newName: string

    Returns Promise<KeyInfo>

    Example

    await libp2p.services.keychain.createKey('keyTest', 'RSA', 4096)
    const keyInfo = await libp2p.services.keychain.renameKey('keyTest', 'keyNewNtest')
  • Rotate keychain password and re-encrypt all associated keys

    Parameters

    • oldPass: string
    • newPass: string

    Returns Promise<void>

    Example

    await libp2p.services.keychain.rotateKeychainPass('oldPassword', 'newPassword')