Skip to content
This repository was archived by the owner on Feb 12, 2024. It is now read-only.

Commit 7e0e85c

Browse files
authored
fix: support keychain without pass (#3212)
- add support for ed25519 and secp256k1 keys for the ipfs PeerId - add support for using ed25519 and secp256k1 keys with ipns - add support for keychain without a pass, this fixes several keychain commands - fix `name publish`, ttl should be optional but wasn't being allowed Includes changes in #3208 Key gen and key listing now works: ```sh $ jsipfs key gen --type=ed25519 my-ed-key generated QmUPJZ3ghsnkRVgYjrMrSC8MbbZTzcezn6mH7vY9vTbrMY my-ed-key $ jsipfs key list QmUPJZ3ghsnkRVgYjrMrSC8MbbZTzcezn6mH7vY9vTbrMY my-ed-key QmYPxJJb8Mpa6JjQj7hCTF4ajn2SE1HFLRoAnCbymTGzyC self ``` IPNS Publishing now works properly, including using other key types: ```sh jsipfs name publish -k my-ed-key /ipfs/QmP7WDyEdkFu2nfj35SUEB7fk3iKCHpcrCVbGk1HXZU22a Published to 12D3KooWGmSq6u3yZeXqeqSmQpJWKQGGdCxrZQAUZBzsbSM2kCE6: /ipfs/QmP7WDyEdkFu2nfj35SUEB7fk3iKCHpcrCVbGk1HXZU22a ``` I also fixed a couple of the example tests, they weren't waiting for IPFS to start before executing the tests, which could cause them to intermittently fail. BREAKING CHANGE: remove support for key.export over the http api
1 parent b1a2713 commit 7e0e85c

File tree

26 files changed

+150
-198
lines changed

26 files changed

+150
-198
lines changed

examples/browser-browserify/public/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
<body>
1616
<h1>JS IPFS - Add data to IPFS from the browser</h1>
1717
<textarea id="source" placeholder="Enter some text here"></textarea>
18-
<button id="store">Add text to ipfs</button>
18+
<button id="store" style="display: none">Add text to ipfs</button>
1919
<div id="output" style="display: none">
2020
<div>found in ipfs:</div>
2121
<div class="content" id="cid">[ipfs cid]</div>

examples/browser-browserify/src/index.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,12 @@
33
const IPFS = require('ipfs')
44

55
document.addEventListener('DOMContentLoaded', async () => {
6-
const node = await IPFS.create({ repo: String(Math.random() + Date.now()) })
6+
const node = await IPFS.create({
7+
repo: String(Math.random() + Date.now()),
8+
init: { alogorithm: 'ed25519' }
9+
10+
})
11+
const button = document.getElementById('store')
712

813
console.log('IPFS node is ready')
914

@@ -25,5 +30,6 @@ document.addEventListener('DOMContentLoaded', async () => {
2530
}
2631
}
2732

28-
document.getElementById('store').onclick = store
33+
button.onclick = store
34+
button.setAttribute('style', 'display: inline')
2935
})

examples/browser-browserify/test.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,8 @@ module.exports = {
99
.waitForElementVisible('#source')
1010
.setValue('#source', 'hello')
1111
.waitForElementVisible('#store')
12-
.pause(1000)
1312
.click('#store')
14-
.waitForElementVisible('#output')
13+
.waitForElementVisible('#output', 5e3, 100)
1514

1615
browser.expect.element('#cid').text.to.contain('QmWfVY9y3xjsixTgbd9AorQxH7VtMpzfx2HaWtsoUYecaX')
1716
browser.expect.element('#content').text.to.contain('hello')

examples/circuit-relaying/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ <h1>IPFS Simple Messaging</h1>
4646
<div class="row">
4747
<div class="box row">
4848
<label>Peer id:</label>
49-
<ul id="peer-id"></ul>
49+
<ul id="peer-id" style="display:none"></ul>
5050
</div>
5151
<div class="box addrs-box">
5252
<label>Addresses:</label>

examples/circuit-relaying/src/app.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ document.addEventListener('DOMContentLoaded', async () => {
5454

5555
let room = createRoom(roomName)
5656

57+
$peerId.setAttribute('style', '')
5758
$peerId.innerHTML = `<li>${info.id}</li>`
5859

5960
$send.addEventListener('click', () => {

examples/circuit-relaying/src/helpers.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ const $msgs = document.querySelector('#msgs')
77
const $addrs = document.querySelector('#addrs')
88
const $peers = document.querySelector('#peers')
99
const $pAddrs = document.querySelector('#peers-addrs')
10-
const delay = require('delay')
1110

1211
const NAMESPACE = 'ipfs-quick-msg'
1312

examples/circuit-relaying/test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,10 +91,10 @@ module.exports[pkg.name] = function (browser) {
9191

9292
browser
9393
.url(process.env.IPFS_EXAMPLE_TEST_URL)
94-
.waitForElementVisible('#peer')
94+
.waitForElementVisible('#peer-id') // Wait for ipfs to start
9595
.clearValue('#peer')
9696
.setValue('#peer', process.env.IPFS_RELAY_ADDRESS)
97-
.pause(1000)
97+
.pause(100)
9898
.click('#connect')
9999

100100
browser.expect.element('#peers-addrs').text.to.contain(process.env.IPFS_RELAY_ID)

packages/interface-ipfs-core/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
"it-drain": "^1.0.1",
5353
"it-last": "^1.0.1",
5454
"it-pushable": "^1.3.1",
55+
"libp2p-crypto": "^0.17.9",
5556
"multiaddr": "^7.4.3",
5657
"multibase": "^1.0.1",
5758
"multihashing-async": "^1.0.0",

packages/interface-ipfs-core/src/key/export.js

Lines changed: 0 additions & 37 deletions
This file was deleted.

packages/interface-ipfs-core/src/key/import.js

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
'use strict'
33

44
const { nanoid } = require('nanoid')
5+
const keys = require('libp2p-crypto/src/keys')
56
const { getDescribe, getIt, expect } = require('../utils/mocha')
67
const testTimeout = require('../utils/test-timeout')
78

@@ -26,24 +27,24 @@ module.exports = (common, options) => {
2627
it('should respect timeout option when importing a key', async () => {
2728
const password = nanoid()
2829

29-
const pem = await ipfs.key.export('self', password)
30-
expect(pem).to.exist()
30+
const key = await keys.generateKeyPair('ed25519')
31+
const exported = key.export(password)
3132

32-
await testTimeout(() => ipfs.key.import('derp', pem, password, {
33+
await testTimeout(() => ipfs.key.import('derp', exported, password, {
3334
timeout: 1
3435
}))
3536
})
3637

3738
it('should import an exported key', async () => {
3839
const password = nanoid()
3940

40-
const pem = await ipfs.key.export('self', password)
41-
expect(pem).to.exist()
41+
const key = await keys.generateKeyPair('ed25519')
42+
const exported = await key.export(password)
4243

43-
const key = await ipfs.key.import('clone', pem, password)
44-
expect(key).to.exist()
45-
expect(key).to.have.property('name', 'clone')
46-
expect(key).to.have.property('id')
44+
const importedKey = await ipfs.key.import('clone', exported, password)
45+
expect(importedKey).to.exist()
46+
expect(importedKey).to.have.property('name', 'clone')
47+
expect(importedKey).to.have.property('id')
4748
})
4849
})
4950
}

0 commit comments

Comments
 (0)