diff --git a/SPEC/KEY.md b/SPEC/KEY.md index 2cd78445..f0342f1d 100644 --- a/SPEC/KEY.md +++ b/SPEC/KEY.md @@ -23,16 +23,13 @@ If no `callback` is passed, a promise is returned. **Example:** ```JavaScript -ipfs.key.add( - 'my-key', - { type: 'rsa', size: 2048 }, - (err, key) => console.log(key)) +ipfs.key.gen('my-key', { + type: 'rsa', + size: 2048 +}, (err, key) => console.log(key)) - -{ - Name: 'my-key', - Id: 'Qmd4xC46Um6s24MradViGLFtMitvrR4SVexKUgPgFjMNzg' -} +// { id: 'QmYWqAFvLWb2G5A69JGXui2JJXzaHXiUEmQkQgor6kNNcJ', +// name: 'my-key' } ``` #### `list` @@ -43,7 +40,14 @@ ipfs.key.add( ##### `JavaScript` - ipfs.key.list([callback]) -`callback` must follow `function (err, keys) {}` signature, where `err` is an Error if the operation was not successful. `keys` is an object with the property `Keys` that is an array of `KeyInfo` (`name` and `id`) +`callback` must follow `function (err, keys) {}` signature, where `err` is an Error if the operation was not successful. `keys` is an array of: + +``` +{ + id: 'hash', // string - the hash of the key + name: 'self' // string - the name of the key +} +``` If no `callback` is passed, a promise is returned. @@ -52,14 +56,12 @@ If no `callback` is passed, a promise is returned. ```JavaScript ipfs.key.list((err, keys) => console.log(keys)) -{ - Keys: [ - { Name: 'self', - Id: 'QmRT6i9wXVSmxKi3MxVRduZqF3Wvv8DuV5utMXPN3BxPML' }, - { Name: 'my-key', - Id: 'Qmd4xC46Um6s24MradViGLFtMitvrR4SVexKUgPgFjMNzg' } - ] -} +// [ +// { id: 'QmTe4tuceM2sAmuZiFsJ9tmAopA8au71NabBDdpPYDjxAb', +// name: 'self' }, +// { id: 'QmWETF5QvzGnP7jKq5sPDiRjSM2fzwzNsna4wSBEzRzK6W', +// name: 'my-key' } +// ] ``` #### `rm` @@ -73,7 +75,14 @@ ipfs.key.list((err, keys) => console.log(keys)) Where: - `name` is the local name for the key -`callback` must follow `function (err, key) {}` signature, where `err` is an Error if the operation was not successful. `key` is an object that describes the removed key. +`callback` must follow `function (err, key) {}` signature, where `err` is an Error if the operation was not successful. `key` is an object that describes the removed key: + +``` +{ + id: 'hash', // string - the hash of the key + name: 'self' // string - the name of the key +} +``` If no `callback` is passed, a promise is returned. @@ -82,12 +91,8 @@ If no `callback` is passed, a promise is returned. ```JavaScript ipfs.key.rm('my-key', (err, key) => console.log(key)) -{ - Keys: [ - { Name: 'my-key', - Id: 'Qmd4xC46Um6s24MradViGLFtMitvrR4SVexKUgPgFjMNzg' } - ] -} +// { id: 'QmWETF5QvzGnP7jKq5sPDiRjSM2fzwzNsna4wSBEzRzK6W', +// name: 'my-key' } ``` #### `rename` @@ -109,17 +114,12 @@ If no `callback` is passed, a promise is returned. **Example:** ```JavaScript -ipfs.key.rename( - 'my-key', - 'my-new-key', - (err, key) => console.log(key)) - -{ - Was: 'my-key', - Now: 'my-new-key', - Id: 'Qmd4xC46Um6s24MradViGLFtMitvrR4SVexKUgPgFjMNzg', - Overwrite: false -} +ipfs.key.rename('my-key', 'my-new-key', (err, key) => console.log(key)) + +// { id: 'Qmd4xC46Um6s24MradViGLFtMitvrR4SVexKUgPgFjMNzg', +// was: 'my-key', +// now: 'my-new-key', +// overwrite: false } ``` #### `export` @@ -134,7 +134,7 @@ Where: - `name` is the local name for the key - `password` is the password to protect the key -`callback` must follow `function (err, pem) {}` signature, where `err` is an Error if the operation was not successful. `pem` is the string representation of the key +`callback` must follow `function (err, pem) {}` signature, where `err` is an Error if the operation was not successful. `pem` is the string representation of the key. If no `callback` is passed, a promise is returned. @@ -143,12 +143,11 @@ If no `callback` is passed, a promise is returned. ```JavaScript ipfs.key.export('self', 'password', (err, pem) => console.log(pem)) ------BEGIN ENCRYPTED PRIVATE KEY----- -MIIFDTA/BgkqhkiG9w0BBQ0wMjAaBgkqhkiG9w0BBQwwDQQIpdO40RVyBwACAWQw -... -YA== ------END ENCRYPTED PRIVATE KEY----- - +// -----BEGIN ENCRYPTED PRIVATE KEY----- +// MIIFDTA/BgkqhkiG9w0BBQ0wMjAaBgkqhkiG9w0BBQwwDQQIpdO40RVyBwACAWQw +// ... +// YA== +// -----END ENCRYPTED PRIVATE KEY----- ``` #### `import` @@ -173,7 +172,6 @@ If no `callback` is passed, a promise is returned. ```JavaScript ipfs.key.import('clone', 'password', (err, key) => console.log(key)) -{ Name: 'clone', - Id: 'QmQRiays958UM7norGRQUG3tmrLq8pJdmJarwYSk2eLthQ' -} +// { id: 'QmQRiays958UM7norGRQUG3tmrLq8pJdmJarwYSk2eLthQ', +// name: 'clone' } ``` diff --git a/src/key.js b/src/key.js index 48daa2d7..4e60f72e 100644 --- a/src/key.js +++ b/src/key.js @@ -47,8 +47,8 @@ module.exports = (common) => { ipfs.key.gen(name, kt, (err, key) => { expect(err).to.not.exist() expect(key).to.exist() - expect(key).to.have.property('Name', name) - expect(key).to.have.property('Id') + expect(key).to.have.property('name', name) + expect(key).to.have.property('id') keys.push(key) done() }) @@ -62,16 +62,16 @@ module.exports = (common) => { ipfs.key.list((err, res) => { expect(err).to.not.exist() expect(res).to.exist() - expect(res.Keys).to.exist() - expect(res.Keys.length).to.be.above(keys.length - 1) - listedKeys = res.Keys + expect(res).to.be.an('array') + expect(res.length).to.be.above(keys.length - 1) + listedKeys = res done() }) }) it('contains the created keys', () => { keys.forEach(ki => { - const found = listedKeys.filter(lk => ki.Name === lk.Name && ki.Id === lk.Id) + const found = listedKeys.filter(lk => ki.name === lk.name && ki.id === lk.id) expect(found).to.have.length(1) }) }) @@ -82,7 +82,7 @@ module.exports = (common) => { let newName before(() => { - oldName = keys[0].Name + oldName = keys[0].name newName = 'x' + oldName }) @@ -90,10 +90,10 @@ module.exports = (common) => { ipfs.key.rename(oldName, newName, (err, res) => { expect(err).to.not.exist() expect(res).to.exist() - expect(res).to.have.property('Was', oldName) - expect(res).to.have.property('Now', newName) - expect(res).to.have.property('Id', keys[0].Id) - keys[0].Name = newName + expect(res).to.have.property('was', oldName) + expect(res).to.have.property('now', newName) + expect(res).to.have.property('id', keys[0].id) + keys[0].name = newName done() }) }) @@ -101,7 +101,7 @@ module.exports = (common) => { it('contains the new name', (done) => { ipfs.key.list((err, res) => { expect(err).to.not.exist() - const found = res.Keys.filter(k => k.Name === newName) + const found = res.filter(k => k.name === newName) expect(found).to.have.length(1) done() }) @@ -110,7 +110,7 @@ module.exports = (common) => { it('does not contain the old name', (done) => { ipfs.key.list((err, res) => { expect(err).to.not.exist() - const found = res.Keys.filter(k => k.Name === oldName) + const found = res.filter(k => k.name === oldName) expect(found).to.have.length(0) done() }) @@ -124,13 +124,11 @@ module.exports = (common) => { }) it('removes a key', function (done) { - ipfs.key.rm(key.Name, (err, res) => { + ipfs.key.rm(key.name, (err, res) => { expect(err).to.not.exist() expect(res).to.exist() - expect(res).to.have.property('Keys') - expect(res.Keys).to.have.length(1) - expect(res.Keys[0]).to.have.property('Name', key.Name) - expect(res.Keys[0]).to.have.property('Id', key.Id) + expect(res).to.have.property('name', key.name) + expect(res).to.have.property('id', key.id) done() }) }) @@ -138,7 +136,7 @@ module.exports = (common) => { it('does not contain the removed name', (done) => { ipfs.key.list((err, res) => { expect(err).to.not.exist() - const found = res.Keys.filter(k => k.Name === key.Name) + const found = res.filter(k => k.name === key.name) expect(found).to.have.length(0) done() }) @@ -170,8 +168,8 @@ module.exports = (common) => { ipfs.key.import('clone', selfPem, passwordPem, (err, key) => { expect(err).to.not.exist() expect(key).to.exist() - expect(key).to.have.property('Name', 'clone') - expect(key).to.have.property('Id') + expect(key).to.have.property('name', 'clone') + expect(key).to.have.property('id') done() }) })