From c2e3eb9cc151cbbb62972211b8a0a8719cbbd839 Mon Sep 17 00:00:00 2001 From: Kristian Nygaard Jensen Date: Tue, 18 Jun 2024 10:44:35 +0200 Subject: [PATCH 1/3] fix: docs/example fs.add is not a function "Invalid key type" key type must be specified https://github.com/libp2p/js-libp2p/blob/main/packages/keychain/src/keychain.ts#L157 --- packages/ipns/README.md | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/packages/ipns/README.md b/packages/ipns/README.md index 0e2e3f7c..985a0017 100644 --- a/packages/ipns/README.md +++ b/packages/ipns/README.md @@ -45,12 +45,12 @@ const helia = await createHelia() const name = ipns(helia) // create a public key to publish as an IPNS name -const keyInfo = await helia.libp2p.services.keychain.createKey('my-key') +const keyInfo = await helia.libp2p.services.keychain.createKey('my-key', 'RSA', 4096) const peerId = await helia.libp2p.services.keychain.exportPeerId(keyInfo.name) // store some data to publish const fs = unixfs(helia) -const cid = await fs.add(Uint8Array.from([0, 1, 2, 3, 4])) +const cid = await fs.addBytes(Uint8Array.from([0, 1, 2, 3, 4])) // publish the name await name.publish(peerId, cid) @@ -75,18 +75,18 @@ const helia = await createHelia() const name = ipns(helia) // create a public key to publish as an IPNS name -const keyInfo = await helia.libp2p.services.keychain.createKey('my-key') +const keyInfo = await helia.libp2p.services.keychain.createKey('my-key', 'RSA', 4096) const peerId = await helia.libp2p.services.keychain.exportPeerId(keyInfo.name) // store some data to publish const fs = unixfs(helia) -const cid = await fs.add(Uint8Array.from([0, 1, 2, 3, 4])) +const cid = await fs.addBytes(Uint8Array.from([0, 1, 2, 3, 4])) // publish the name await name.publish(peerId, cid) // create another public key to re-publish the original record -const recursiveKeyInfo = await helia.libp2p.services.keychain.createKey('my-recursive-key') +const recursiveKeyInfo = await helia.libp2p.services.keychain.createKey('my-recursive-key', 'RSA', 4096) const recursivePeerId = await helia.libp2p.services.keychain.exportPeerId(recursiveKeyInfo.name) // publish the recursive name @@ -110,12 +110,12 @@ const helia = await createHelia() const name = ipns(helia) // create a public key to publish as an IPNS name -const keyInfo = await helia.libp2p.services.keychain.createKey('my-key') +const keyInfo = await helia.libp2p.services.keychain.createKey('my-key', 'RSA', 4096) const peerId = await helia.libp2p.services.keychain.exportPeerId(keyInfo.name) // store some data to publish const fs = unixfs(helia) -const fileCid = await fs.add(Uint8Array.from([0, 1, 2, 3, 4])) +const fileCid = await fs.addBytes(Uint8Array.from([0, 1, 2, 3, 4])) // store the file in a directory const dirCid = await fs.mkdir() @@ -166,12 +166,12 @@ const name = ipns(helia, { }) // create a public key to publish as an IPNS name -const keyInfo = await helia.libp2p.services.keychain.createKey('my-key') +const keyInfo = await helia.libp2p.services.keychain.createKey('my-key', 'RSA', 4096) const peerId = await helia.libp2p.services.keychain.exportPeerId(keyInfo.name) // store some data to publish const fs = unixfs(helia) -const cid = await fs.add(Uint8Array.from([0, 1, 2, 3, 4])) +const cid = await fs.addBytes(Uint8Array.from([0, 1, 2, 3, 4])) // publish the name await name.publish(peerId, cid) From c1532369cecc54fb6bf100494910223b85dbc34b Mon Sep 17 00:00:00 2001 From: Kristian Nygaard Jensen Date: Tue, 18 Jun 2024 10:44:35 +0200 Subject: [PATCH 2/3] fix: docs/example fs.add is not a function "Invalid key type" key type must be specified Ed keys are preferred over RSA for new code https://github.com/libp2p/js-libp2p/blob/main/packages/keychain/src/keychain.ts#L157 --- packages/ipns/README.md | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/packages/ipns/README.md b/packages/ipns/README.md index 0e2e3f7c..cac47df6 100644 --- a/packages/ipns/README.md +++ b/packages/ipns/README.md @@ -45,12 +45,12 @@ const helia = await createHelia() const name = ipns(helia) // create a public key to publish as an IPNS name -const keyInfo = await helia.libp2p.services.keychain.createKey('my-key') +const keyInfo = await helia.libp2p.services.keychain.createKey('my-key', 'Ed25519') const peerId = await helia.libp2p.services.keychain.exportPeerId(keyInfo.name) // store some data to publish const fs = unixfs(helia) -const cid = await fs.add(Uint8Array.from([0, 1, 2, 3, 4])) +const cid = await fs.addBytes(Uint8Array.from([0, 1, 2, 3, 4])) // publish the name await name.publish(peerId, cid) @@ -75,18 +75,18 @@ const helia = await createHelia() const name = ipns(helia) // create a public key to publish as an IPNS name -const keyInfo = await helia.libp2p.services.keychain.createKey('my-key') +const keyInfo = await helia.libp2p.services.keychain.createKey('my-key', 'Ed25519') const peerId = await helia.libp2p.services.keychain.exportPeerId(keyInfo.name) // store some data to publish const fs = unixfs(helia) -const cid = await fs.add(Uint8Array.from([0, 1, 2, 3, 4])) +const cid = await fs.addBytes(Uint8Array.from([0, 1, 2, 3, 4])) // publish the name await name.publish(peerId, cid) // create another public key to re-publish the original record -const recursiveKeyInfo = await helia.libp2p.services.keychain.createKey('my-recursive-key') +const recursiveKeyInfo = await helia.libp2p.services.keychain.createKey('my-recursive-key', 'Ed25519') const recursivePeerId = await helia.libp2p.services.keychain.exportPeerId(recursiveKeyInfo.name) // publish the recursive name @@ -110,12 +110,12 @@ const helia = await createHelia() const name = ipns(helia) // create a public key to publish as an IPNS name -const keyInfo = await helia.libp2p.services.keychain.createKey('my-key') +const keyInfo = await helia.libp2p.services.keychain.createKey('my-key', 'Ed25519') const peerId = await helia.libp2p.services.keychain.exportPeerId(keyInfo.name) // store some data to publish const fs = unixfs(helia) -const fileCid = await fs.add(Uint8Array.from([0, 1, 2, 3, 4])) +const fileCid = await fs.addBytes(Uint8Array.from([0, 1, 2, 3, 4])) // store the file in a directory const dirCid = await fs.mkdir() @@ -166,12 +166,12 @@ const name = ipns(helia, { }) // create a public key to publish as an IPNS name -const keyInfo = await helia.libp2p.services.keychain.createKey('my-key') +const keyInfo = await helia.libp2p.services.keychain.createKey('my-key', 'Ed25519') const peerId = await helia.libp2p.services.keychain.exportPeerId(keyInfo.name) // store some data to publish const fs = unixfs(helia) -const cid = await fs.add(Uint8Array.from([0, 1, 2, 3, 4])) +const cid = await fs.addBytes(Uint8Array.from([0, 1, 2, 3, 4])) // publish the name await name.publish(peerId, cid) From 29a3f857b1e90489533a91265b0345b46a0b7bc2 Mon Sep 17 00:00:00 2001 From: Kristian Nygaard Jensen Date: Thu, 20 Jun 2024 19:25:15 +0200 Subject: [PATCH 3/3] Async --- packages/ipns/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/ipns/README.md b/packages/ipns/README.md index cac47df6..307e1762 100644 --- a/packages/ipns/README.md +++ b/packages/ipns/README.md @@ -56,7 +56,7 @@ const cid = await fs.addBytes(Uint8Array.from([0, 1, 2, 3, 4])) await name.publish(peerId, cid) // resolve the name -const result = name.resolve(peerId) +const result = await name.resolve(peerId) console.info(result.cid, result.path) ```