Skip to content

Commit 41c138a

Browse files
committed
fix peer id key generation
1 parent 4526d5d commit 41c138a

File tree

5 files changed

+13
-8
lines changed

5 files changed

+13
-8
lines changed

src/components/P2P/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ export class OceanP2P extends EventEmitter {
234234
P2P_LOGGER.info(`Starting P2P Node with peerID: ${this._publicAddress}`)
235235

236236
this._publicKey = config.keys.publicKey
237-
this._privateKey = config.keys.privateKey
237+
this._privateKey = config.keys.privateKey.raw
238238
/** @type {import('libp2p').Libp2pOptions} */
239239
// start with some default, overwrite based on config later
240240
const bindInterfaces = []
@@ -341,7 +341,7 @@ export class OceanP2P extends EventEmitter {
341341

342342
let options = {
343343
addresses,
344-
peerId: config.keys.peerId,
344+
privateKey: config.keys.privateKey,
345345
transports,
346346
streamMuxers: [yamux()],
347347
connectionEncryption: [

src/components/core/handler/downloadHandler.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ export async function handleDownloadUrlCommand(
108108
// we parse the string into the object again
109109
const encryptedObject = ethCrypto.cipher.parse(task.aes_encrypted_key)
110110
// get the key from configuration
111-
const nodePrivateKey = Buffer.from(config.keys.privateKey).toString('hex')
111+
const nodePrivateKey = Buffer.from(config.keys.privateKey.raw).toString('hex')
112112
const decrypted = await ethCrypto.decryptWithPrivateKey(
113113
nodePrivateKey,
114114
encryptedObject

src/components/core/utils/feesHandler.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -452,15 +452,15 @@ export async function checkFee(
452452
*/
453453
export async function getProviderWallet(chainId?: string): Promise<ethers.Wallet> {
454454
return new ethers.Wallet(
455-
Buffer.from((await getConfiguration()).keys.privateKey).toString('hex')
455+
Buffer.from((await getConfiguration()).keys.privateKey.raw).toString('hex')
456456
)
457457
}
458458
export async function getProviderWalletAddress(): Promise<string> {
459459
return (await getProviderWallet()).address
460460
}
461461

462462
export async function getProviderKey(): Promise<string> {
463-
return Buffer.from((await getConfiguration()).keys.privateKey).toString('hex')
463+
return Buffer.from((await getConfiguration()).keys.privateKey.raw).toString('hex')
464464
}
465465

466466
/**

src/test/unit/oceanP2P.test.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,13 @@ import {
99
setupEnvironment,
1010
tearDownEnvironment
1111
} from '../utils/utils.js'
12+
import { OceanNodeConfig } from '../../@types/OceanNode.js'
1213

1314
describe('OceanP2P Test', () => {
1415
let node1: OceanP2P
1516
let node2: OceanP2P
16-
let config1: any
17-
let config2: any
17+
let config1: OceanNodeConfig
18+
let config2: OceanNodeConfig
1819
const mDNSInterval: number = 1
1920

2021
const envOverrides = buildEnvOverrideConfig(
@@ -67,6 +68,10 @@ describe('OceanP2P Test', () => {
6768
assert(node2, 'Failed to create P2P Node instance')
6869
})
6970
it('Start check peerID of each node', () => {
71+
console.log(config1.keys.peerId.toString())
72+
console.log(node1._libp2p.peerId.toString())
73+
console.log(config2.keys.peerId.toString())
74+
console.log(node2._libp2p.peerId.toString())
7075
assert(
7176
config1.keys.peerId.toString() === node1._libp2p.peerId.toString(),
7277
'Peer missmatch for node1'

src/utils/config/builder.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ export function getPeerIdFromPrivateKey(privateKey: string): OceanNodeKeys {
9090
return {
9191
peerId: peerIdFromPrivateKey(key),
9292
publicKey: key.publicKey.raw,
93-
privateKey: key.raw,
93+
privateKey: key,
9494
ethAddress: new Wallet(privateKey.substring(2)).address
9595
}
9696
}

0 commit comments

Comments
 (0)