js-peer-id icon indicating copy to clipboard operation
js-peer-id copied to clipboard

Instantiating CreateLibp2p function with Proper Assessment to PeerIds

Open peterkim2014 opened this issue 1 year ago • 0 comments

Current Method

  1. Made a peerId using the createEd25519PeerId. const peerId = await createEd25519PeerId({ privateKey: privateKey });

  2. Store into json, which eliminates the formats of ed25519, converts the values into string.

  3. Retrieving the data of peerId to instantiate the CreateLibp2p.


Process

  • When I store the data as hex values, because Uint8Array doesn't store the format, only the values, I'm trying to revert the hex values into a Uint8Array to extract the same peerId using the public and private key.

Error

  • CreateLibp2p doesn't instantiate the node. Instead, I'm given these error messages: if (publicKey.length === MARSHALLED_ED225519_PUBLIC_KEY_LENGTH) { ^

TypeError: Cannot read properties of undefined (reading 'length')


The pasted details below is the data structure of the peer.meta that I'm using, in order to retrieve the peerId.

  • Before inputting the meta into createFromPrivKey function, I'm converting the hex values into Uint8Array

CodeBase const peerIdForm = await createFromPrivKey(peer.meta); "meta": { "id": { "code": 0, "size": 36, "digest": "0x080112202a43350be8249d8a381f85da2e7b0ca661ceb2b3d727ad967cd4903ac3fa5341", "bytes": "0x0024080112202a43350be8249d8a381f85da2e7b0ca661ceb2b3d727ad967cd4903ac3fa5341" }, "key": "0x080112401330d9b33b2f6de93088ab2424a36394fa8dc67c706b2f1cac5df80eb66c2a6b2a43350be8249d8a381f85da2e7b0ca661ceb2b3d727ad967cd4903ac3fa5341", "public": "0x080112202a43350be8249d8a381f85da2e7b0ca661ceb2b3d727ad967cd4903ac3fa5341", "CID": { "/": "bafzaajaiaejcaksdguf6qje5ri4b7bo2fz5qzjtbz2zlhvzhvwlhzveqhlb7uu2b" }, "type": "Ed25519" },

If I'm missing any details that could help figure out this issue, please let me know. Thank you.

peterkim2014 avatar Feb 13 '24 21:02 peterkim2014