mirror of
https://github.com/fluencelabs/js-peer-id
synced 2025-06-27 12:11:52 +00:00
feat(peerid): support creating from secp256k1; harmonize algo with Go (#95)
This commit is contained in:
@ -36,6 +36,12 @@ describe('PeerId', () => {
|
||||
expect(id.toB58String().length).to.equal(46)
|
||||
})
|
||||
|
||||
it('can be created for a Secp256k1 key', async () => {
|
||||
const id = await PeerId.create({ keyType: 'secp256k1', bits: 256 })
|
||||
const expB58 = mh.toB58String(mh.encode(id.pubKey.bytes, 'identity'))
|
||||
expect(id.toB58String()).to.equal(expB58)
|
||||
})
|
||||
|
||||
it('isPeerId', async () => {
|
||||
const id = await PeerId.create(testOpts)
|
||||
expect(PeerId.isPeerId(id)).to.equal(true)
|
||||
@ -80,6 +86,20 @@ describe('PeerId', () => {
|
||||
expect(id.marshalPubKey()).to.deep.equal(id2.marshalPubKey())
|
||||
})
|
||||
|
||||
it('can be created from a Secp256k1 public key', async () => {
|
||||
const privKey = await crypto.keys.generateKeyPair('secp256k1', 256)
|
||||
const id = await PeerId.createFromPubKey(privKey.public.bytes)
|
||||
const expB58 = mh.toB58String(mh.encode(id.pubKey.bytes, 'identity'))
|
||||
expect(id.toB58String()).to.equal(expB58)
|
||||
})
|
||||
|
||||
it('can be created from a Secp256k1 private key', async () => {
|
||||
const privKey = await crypto.keys.generateKeyPair('secp256k1', 256)
|
||||
const id = await PeerId.createFromPrivKey(privKey.bytes)
|
||||
const expB58 = mh.toB58String(mh.encode(id.pubKey.bytes, 'identity'))
|
||||
expect(id.toB58String()).to.equal(expB58)
|
||||
})
|
||||
|
||||
it('Compare generated ID with one created from PubKey', async () => {
|
||||
const id1 = await PeerId.create(testOpts)
|
||||
const id2 = await PeerId.createFromPubKey(id1.marshalPubKey())
|
||||
|
Reference in New Issue
Block a user