Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use undefined instead of null privKey #154

Merged
merged 1 commit into from
Jul 26, 2021

Conversation

wemeetagain
Copy link
Member

Respect the PeerId#privKey typescript type, which is PrivateKey | undefined, not PrivateKey | null

Found this in the course of manually creating a peer id using typescript.

import {expect} from "chai";
import PeerId from "peer-id";
import mh from "multihashes";
import { keys } from "libp2p-crypto";
const { supportedKeys } = keys;

async function test () {
  const privKey = await supportedKeys.secp256k1.generateKeyPair();
  const pubKey = privKey.public;
  const id = mh.encode(pubKey.bytes, "identity");

  // these two should be identical
  const manualPeerId = new PeerId(id, undefined, pubKey); 
  const peerId = await PeerId.createFromPubKey(pubKey.bytes);

  // but they aren't
  expect(manualPeerId).to.deep.equal(peerId);
  // replace 'undefined' with 'null as any' to avoid error
}

test();

Respect the `PeerId#privKey` typescript type, which is `PrivateKey | undefined`, not `PrivateKey | null`
Copy link
Member

@vasco-santos vasco-santos left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@vasco-santos vasco-santos merged commit 35faac2 into libp2p:master Jul 26, 2021
@wemeetagain wemeetagain deleted the patch-1 branch July 26, 2021 16:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants