15 lines
423 B
TypeScript
Raw Normal View History

2020-06-19 13:06:31 +02:00
import { keys, PrivateKey } from 'libp2p-crypto'
2020-06-19 12:49:40 +02:00
import { KeyPair } from '../src/@types/libp2p'
import PeerId from 'peer-id'
2019-11-07 10:55:18 +01:00
2020-06-19 13:06:31 +02:00
export async function generateEd25519Keys (): Promise<PrivateKey> {
return await keys.generateKeyPair('Ed25519', 32)
2019-11-07 10:55:18 +01:00
}
2019-12-03 13:52:44 +01:00
2020-06-19 12:49:40 +02:00
export function getKeyPairFromPeerId (peerId: PeerId): KeyPair {
2019-12-03 13:52:44 +01:00
return {
privateKey: peerId.privKey.marshal().slice(0, 32),
2020-06-19 12:49:40 +02:00
publicKey: peerId.marshalPubKey()
2019-12-03 13:52:44 +01:00
}
}