mirror of
https://github.com/fluencelabs/js-peer-id
synced 2025-06-27 22:41:43 +00:00
feat: add compact protobuf format (#76)
* docs: document .createFromProtobuf and .marshal * fix: lint * test: verify .marshal() does it's job
This commit is contained in:
committed by
Jacob Heun
parent
f50b2ac016
commit
76864184da
@ -86,6 +86,16 @@ describe('PeerId', () => {
|
||||
expect(id.marshalPubKey()).to.deep.equal(id2.marshalPubKey())
|
||||
})
|
||||
|
||||
it('Recreate from Protobuf', async () => {
|
||||
const id = await PeerId.createFromProtobuf(testId.marshaled)
|
||||
expect(testIdB58String).to.equal(id.toB58String())
|
||||
const encoded = Buffer.from(testId.privKey, 'base64')
|
||||
const id2 = await PeerId.createFromPrivKey(encoded)
|
||||
expect(testIdB58String).to.equal(id2.toB58String())
|
||||
expect(id.marshalPubKey()).to.deep.equal(id2.marshalPubKey())
|
||||
expect(id.marshal().toString('hex')).to.deep.equal(testId.marshaled)
|
||||
})
|
||||
|
||||
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)
|
||||
@ -200,7 +210,7 @@ describe('PeerId', () => {
|
||||
Buffer.from(''), 'aGVsbG93b3JsZA==', 'helloworld', ''
|
||||
]
|
||||
|
||||
const fncs = ['createFromPubKey', 'createFromPrivKey', 'createFromJSON']
|
||||
const fncs = ['createFromPubKey', 'createFromPrivKey', 'createFromJSON', 'createFromProtobuf']
|
||||
|
||||
for (const gb of garbage) {
|
||||
for (const fn of fncs) {
|
||||
|
Reference in New Issue
Block a user