Skip to content
This repository was archived by the owner on Jul 10, 2025. It is now read-only.

Conversation

folex
Copy link
Contributor

@folex folex commented Sep 13, 2021

Most important changes are:

  • fromBytes allows to pass any seed you want
  • constructor takes PeerId (previously was empty and maybe private)
  • toEd25519PrivateKey to complete the lifecycle.

API is as follows:

export class KeyPair {
    /**
     * Key pair in libp2p format. Used for backward compatibility with the current FluencePeer implementation
     */
    public Libp2pPeerId: PeerId;

    constructor(libp2pPeerId: PeerId) { ... }

    /**
     * Generates new KeyPair from base64 string containing the 32 byte Ed25519 private key
     * @returns - Promise with the created KeyPair
     */
    static async fromEd25519SK(base64Key: string): Promise<KeyPair> {
        // deserialize private key from base64
        const key = base64.toByteArray(base64Key);
        return await KeyPair.fromBytes(key);
    }

    /**
     * Generates new KeyPair from a 32 byte array
     * @param key - Any sequence of 32 bytes
     * @returns - Promise with the created KeyPair
     */
    static async fromBytes(arr: Uint8Array): Promise<KeyPair> { ... }

    /**
     * Generates new KeyPair with a random secret key
     * @returns - Promise with the created KeyPair
     */
    static async randomEd25519(): Promise<KeyPair> { ... }

    /**
     * @returns 32 byte private key
     */
    toEd25519PrivateKey(): Uint8Array { ... }
}

@folex folex requested review from alari and coder11 September 13, 2021 12:52
@folex folex changed the title Add KeyPair.fromSeed method Add KeyPair.fromArray method Sep 13, 2021
@folex folex changed the title Add KeyPair.fromArray method KeyPair: add fromBytes, toEd25519PrivateKey Sep 13, 2021
@folex folex merged commit 763e641 into master Sep 14, 2021
@folex folex deleted the keypair_seed branch September 14, 2021 09:16
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants