If I use the following setup :
const peerId = await createEd25519PeerId();
console.log(peerId.toString());
const ipfs = await createIpfs({
libp2p:{
peerId
},
});
I’ve noticed the peerId saved in the ~/.jsipfs/config :
"Identity": {
"PeerID": "12D3KooW...eaDmhKifKjf9ripJav",
"PrivKey": "CAESQNNG0M...klMEweotbg4bsHK/dfrrkszFUDMS6aOdTLps="
},
Is not the same. This sounds surprising, as I don’t know which one is used to identify me in the ipfs network. Is it a bug or is there a explanation to such a behavior ?
Thanks
1 Like
By going deeper into ipfs code, I’ve succeeded to force the peerId by the following code :
const ipfs = await createIpfs({
libp2p: {
peerId, // no use... peerId is modified in ipfs repo creation
},
config: {
Bootstrap: bootstrap,
Identity: { // if I want to force the peerId read from .jsipfs/config
peerId: myPeerId.toString(),
PrivKey: privKey,
}
},
init: {
allowNew: true,
privateKey: privKey, // to force the peerId during the .jsipfs/config creation
}
});
It looks like it works, but I wonder what is the recommended setup, and why the libp2p peerId is not used. This not seems to be documented. What should be done ?
1 Like
It looks like all you need to do on init, as I understand it is:
Source: js-ipfs/CONFIG.md at master · ipfs/js-ipfs · GitHub
config: {
Identity: {
PrivKey: privKey,
}
}
As PeerID
is set on init anyways, which will be generated from PrivKey
. This configuration, as I understand it, should allow you to set your PeerID to whatever you want.
I agree that having a bundle of js-ipfs stuff, outlining how to do steps like this would be incredibly useful.
1 Like
I’ve understood the same : this config.Identity
is used to force the peerId
, whatever is the peerId
stored in .jsipfs
, and you’re right, the peerId
is not used, as seen here (btw, it should be written PeerID
…), but seems to be required in typescript to fit the IdentityConfig
:
Identity: {
PeerID: myPeerId.toString(),
PrivKey: privKeyString,
} as IdentityConfig,
1 Like