fix(keys): Creating persistent keystore for libp2p v1.0.x

This commit is contained in:
Chris Troutner
2024-01-28 08:19:38 -08:00
parent ceb58caba1
commit b697f37199
3 changed files with 4 additions and 44 deletions
-1
View File
@@ -25,7 +25,6 @@
"glob": "7.1.6",
"helia": "2.1.0",
"helia-coord": "1.2.23",
"interface-datastore": "8.2.10",
"jsonrpc-lite": "2.2.0",
"jsonwebtoken": "8.5.1",
"jwt-bch-lib": "1.3.0",
-1
View File
@@ -40,7 +40,6 @@
"glob": "7.1.6",
"helia": "2.1.0",
"helia-coord": "1.2.23",
"interface-datastore": "8.2.10",
"jsonrpc-lite": "2.2.0",
"jsonwebtoken": "8.5.1",
"jwt-bch-lib": "1.3.0",
+4 -42
View File
@@ -28,7 +28,6 @@ import { multiaddr } from '@multiformats/multiaddr'
import { webRTC } from '@libp2p/webrtc'
import { keychain } from '@libp2p/keychain'
import { defaultLogger } from '@libp2p/logger'
import { Key } from 'interface-datastore/key'
// Local libraries
import config from '../../../config/index.js'
@@ -122,15 +121,12 @@ class IpfsAdapter {
datastore,
logger: defaultLogger()
})
const selfKey = new Key('/pkcs8/self')
if (await datastore.has(selfKey)) {
// load the peer id from the keychain
peerId = await chain.exportPeerId('self')
} else {
// await chain.createKey('myKey', 'RSA', 4096)
try {
peerId = await chain.exportPeerId('myKey')
} catch (err) {
await chain.createKey('myKey', 'RSA', 4096)
peerId = await chain.exportPeerId('myKey')
}
console.log('Created peer ID: ', peerId)
// Configure services
const services = {
@@ -144,29 +140,6 @@ class IpfsAdapter {
console.log('Helia (IPFS) node IS NOT configured as Circuit Relay')
}
// const bootstrapList = [
// //
// // // launchpad-p2wdb-service (Launchpad pinning service)
// // '/ip4/137.184.13.92/tcp/4001/p2p/12D3KooWPpBXhhAeoCZCGuQ3KR4xwHzzvtP57f6zLmo8P7ZFBJFE',
// //
// // // PSFoundation.info metrics
// // '/ip4/5.161.72.148/tcp/4001/p2p/12D3KooWDL1kPixc6hcT4s7teWGufrxXmZFD1kPeGdDrsKgYrFUt',
// //
// // // PSFoundation.info P2WDB
// // '/ip4/5.161.72.148/tcp/4101/p2p/12D3KooWHz1sRB94EEVRQRJvUX9MyRm3xhr4QSyCoJbTdu2AYheq',
// //
// // // TokenTiger.com backup P2WDB
// // '/ip4/161.35.99.207/tcp/4001/p2p/12D3KooWDtj9cfj1SKuLbDNKvKRKSsGN8qivq9M8CYpLPDpcD5pu',
// //
// // // helia-p2wdb-dev-server-01 prototype P2WDB server using Helia (Token Tiger)
// // '/ip4/137.184.93.145/tcp/4001/p2p/12D3KooWGZCpD5Ue3CJCBBEKowcuKEgeVKbTM7VMbJ8xm1bqST1j',
// //
// // // helia-p2wdb-dev-server-01 prototype P2WDB server using Helia (FullStack.cash)
// // '/ip4/78.46.129.7/tcp/7001/p2p/12D3KooWRqe7TwTj8apPxmpPqPgHiv7qv5YBJTo1VeQ7zrdyA2HN'
// ]
// bootstrapList = bootstrapList.concat(this.config.bootstrapRelays)
// console.log('bootstrapList: ', bootstrapList)
// libp2p is the networking layer that underpins Helia
const libp2p = await this.createLibp2p({
peerId,
@@ -191,20 +164,9 @@ class IpfsAdapter {
streamMuxers: [
yamux()
],
// peerDiscovery: [
// bootstrap({
// list: bootstrapList
// })
// ],
services
})
// Save the identity if it was newly created.
if (peerId != null && !await datastore.has(selfKey)) {
console.log(`Saving key for peer ID ${libp2p.peerId}`)
// a new PeerId would have been generated so store it in the keychain for next time
await chain.importPeer('self', libp2p.peerId)
}
// create a Helia node
const helia = await createHelia({
blockstore,