@libp2p/peer-id-factory
Advanced tools
Comparing version 2.0.3 to 2.0.4
import { generateKeyPair, marshalPrivateKey, unmarshalPrivateKey, marshalPublicKey, unmarshalPublicKey } from '@libp2p/crypto/keys'; | ||
import { peerIdFromKeys, peerIdFromBytes } from '@libp2p/peer-id'; | ||
import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string'; | ||
import { peerIdFromKeys, peerIdFromBytes } from '@libp2p/peer-id'; | ||
import { PeerIdProto } from './proto.js'; | ||
@@ -30,6 +30,6 @@ export const createEd25519PeerId = async () => { | ||
export async function createFromPubKey(publicKey) { | ||
return await peerIdFromKeys(marshalPublicKey(publicKey)); | ||
return peerIdFromKeys(marshalPublicKey(publicKey)); | ||
} | ||
export async function createFromPrivKey(privateKey) { | ||
return await peerIdFromKeys(marshalPublicKey(privateKey.public), marshalPrivateKey(privateKey)); | ||
return peerIdFromKeys(marshalPublicKey(privateKey.public), marshalPrivateKey(privateKey)); | ||
} | ||
@@ -45,6 +45,6 @@ export function exportToProtobuf(peerId, excludePrivateKey) { | ||
const { id, privKey, pubKey } = PeerIdProto.decode(buf); | ||
return await createFromParts(id ?? new Uint8Array(0), privKey, pubKey); | ||
return createFromParts(id ?? new Uint8Array(0), privKey, pubKey); | ||
} | ||
export async function createFromJSON(obj) { | ||
return await createFromParts(uint8ArrayFromString(obj.id, 'base58btc'), obj.privKey != null ? uint8ArrayFromString(obj.privKey, 'base64pad') : undefined, obj.pubKey != null ? uint8ArrayFromString(obj.pubKey, 'base64pad') : undefined); | ||
return createFromParts(uint8ArrayFromString(obj.id, 'base58btc'), obj.privKey != null ? uint8ArrayFromString(obj.privKey, 'base64pad') : undefined, obj.pubKey != null ? uint8ArrayFromString(obj.pubKey, 'base64pad') : undefined); | ||
} | ||
@@ -54,7 +54,7 @@ async function createFromParts(multihash, privKey, pubKey) { | ||
const key = await unmarshalPrivateKey(privKey); | ||
return await createFromPrivKey(key); | ||
return createFromPrivKey(key); | ||
} | ||
else if (pubKey != null) { | ||
const key = unmarshalPublicKey(pubKey); | ||
return await createFromPubKey(key); | ||
return createFromPubKey(key); | ||
} | ||
@@ -61,0 +61,0 @@ return peerIdFromBytes(multihash); |
{ | ||
"name": "@libp2p/peer-id-factory", | ||
"version": "2.0.3", | ||
"version": "2.0.4", | ||
"description": "Create PeerId instances", | ||
@@ -155,5 +155,4 @@ "license": "Apache-2.0 OR MIT", | ||
"devDependencies": { | ||
"aegir": "^38.1.0", | ||
"protons": "^7.0.2", | ||
"util": "^0.12.4" | ||
"aegir": "^39.0.10", | ||
"protons": "^7.0.2" | ||
}, | ||
@@ -160,0 +159,0 @@ "typedoc": { |
import { generateKeyPair, marshalPrivateKey, unmarshalPrivateKey, marshalPublicKey, unmarshalPublicKey } from '@libp2p/crypto/keys' | ||
import { peerIdFromKeys, peerIdFromBytes } from '@libp2p/peer-id' | ||
import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string' | ||
import { peerIdFromKeys, peerIdFromBytes } from '@libp2p/peer-id' | ||
import { PeerIdProto } from './proto.js' | ||
@@ -42,7 +42,7 @@ import type { PublicKey, PrivateKey } from '@libp2p/interface-keys' | ||
export async function createFromPubKey (publicKey: PublicKey): Promise<PeerId> { | ||
return await peerIdFromKeys(marshalPublicKey(publicKey)) | ||
return peerIdFromKeys(marshalPublicKey(publicKey)) | ||
} | ||
export async function createFromPrivKey (privateKey: PrivateKey): Promise<PeerId> { | ||
return await peerIdFromKeys(marshalPublicKey(privateKey.public), marshalPrivateKey(privateKey)) | ||
return peerIdFromKeys(marshalPublicKey(privateKey.public), marshalPrivateKey(privateKey)) | ||
} | ||
@@ -65,3 +65,3 @@ | ||
return await createFromParts( | ||
return createFromParts( | ||
id ?? new Uint8Array(0), | ||
@@ -74,3 +74,3 @@ privKey, | ||
export async function createFromJSON (obj: { id: string, privKey?: string, pubKey?: string }): Promise<PeerId> { | ||
return await createFromParts( | ||
return createFromParts( | ||
uint8ArrayFromString(obj.id, 'base58btc'), | ||
@@ -86,7 +86,7 @@ obj.privKey != null ? uint8ArrayFromString(obj.privKey, 'base64pad') : undefined, | ||
return await createFromPrivKey(key) | ||
return createFromPrivKey(key) | ||
} else if (pubKey != null) { | ||
const key = unmarshalPublicKey(pubKey) | ||
return await createFromPubKey(key) | ||
return createFromPubKey(key) | ||
} | ||
@@ -93,0 +93,0 @@ |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
262867
2
1223