Generate a new key
Where:
name
is a local name for the keyoptions
is an object that contains following properties- 'type' - the key type, one of 'rsa'
- 'size' - the key size in bits
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 key; name
and id
.
If no callback
is passed, a promise is returned.
Example:
ipfs.key.gen('my-key', {
type: 'rsa',
size: 2048
}, (err, key) => console.log(key))
// { id: 'QmYWqAFvLWb2G5A69JGXui2JJXzaHXiUEmQkQgor6kNNcJ',
// name: 'my-key' }
List all the keys
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.
Example:
ipfs.key.list((err, keys) => console.log(keys))
// [
// { id: 'QmTe4tuceM2sAmuZiFsJ9tmAopA8au71NabBDdpPYDjxAb',
// name: 'self' },
// { id: 'QmWETF5QvzGnP7jKq5sPDiRjSM2fzwzNsna4wSBEzRzK6W',
// name: 'my-key' }
// ]
Remove a key
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:
{
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.
Example:
ipfs.key.rm('my-key', (err, key) => console.log(key))
// { id: 'QmWETF5QvzGnP7jKq5sPDiRjSM2fzwzNsna4wSBEzRzK6W',
// name: 'my-key' }
Rename a key
Where:
oldName
is the local name for the keynewName
a new name for 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 renamed key.
If no callback
is passed, a promise is returned.
Example:
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 a key in a PEM encoded password protected PKCS #8
Where:
name
is the local name for the keypassword
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.
If no callback
is passed, a promise is returned.
Example:
ipfs.key.export('self', 'password', (err, pem) => console.log(pem))
// -----BEGIN ENCRYPTED PRIVATE KEY-----
// MIIFDTA/BgkqhkiG9w0BBQ0wMjAaBgkqhkiG9w0BBQwwDQQIpdO40RVyBwACAWQw
// ...
// YA==
// -----END ENCRYPTED PRIVATE KEY-----
Import a PEM encoded password protected PKCS #8 key
Where:
name
is a local name for the keypem
is the PEM encoded keypassword
is the password that protects the PEM 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 new key.
If no callback
is passed, a promise is returned.
Example:
ipfs.key.import('clone', 'password', (err, key) => console.log(key))
// { id: 'QmQRiays958UM7norGRQUG3tmrLq8pJdmJarwYSk2eLthQ',
// name: 'clone' }