15 lines
386 B
TypeScript
Raw Normal View History

2020-06-19 12:49:40 +02:00
import { keys } from 'libp2p-crypto'
import { KeyPair } from '../src/@types/libp2p'
import PeerId from 'peer-id'
2019-11-07 10:55:18 +01:00
2020-06-19 12:49:40 +02:00
export async function generateEd25519Keys () {
return await keys.generateKeyPair('ed25519')
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
}
}