ipfs.key.gen(name, [options])
ipfs.key.list([options])
ipfs.key.rm(name, [options])
ipfs.key.rename(oldName, newName, [options])
ipfs.key.export(name, password, [options])
ipfs.key.import(name, pem, password, [options])
Generate a new key
Name | Type | Description |
---|---|---|
name | String | The name to give the key |
An optional object which may have the following keys:
Name | Type | Default | Description |
---|---|---|---|
type | String |
'rsa' |
The key type, one of 'rsa' or 'ed25519' |
size | Number |
2048 |
The key size in bits |
timeout | Number |
undefined |
A timeout in ms |
signal | AbortSignal | undefined |
Can be used to cancel any long running requests started as a result of this call |
Type | Description |
---|---|
Promise<Object> |
An object that describes the key; name and id |
const key = await ipfs.key.gen('my-key', {
type: 'rsa',
size: 2048
})
console.log(key)
// { id: 'QmYWqAFvLWb2G5A69JGXui2JJXzaHXiUEmQkQgor6kNNcJ',
// name: 'my-key' }
A great source of examples can be found in the tests for this API.
List all the keys
None
An optional object which may have the following keys:
Name | Type | Default | Description |
---|---|---|---|
timeout | Number |
undefined |
A timeout in ms |
signal | AbortSignal | undefined |
Can be used to cancel any long running requests started as a result of this call |
Type | Description |
---|---|
Promise<Array> |
An array representing all the keys |
example of the returned array:
{
id: 'hash', // string - the hash of the key
name: 'self' // string - the name of the key
}
const keys = await ipfs.key.list()
console.log(keys)
// [
// { id: 'QmTe4tuceM2sAmuZiFsJ9tmAopA8au71NabBDdpPYDjxAb',
// name: 'self' },
// { id: 'QmWETF5QvzGnP7jKq5sPDiRjSM2fzwzNsna4wSBEzRzK6W',
// name: 'my-key' }
// ]
A great source of examples can be found in the tests for this API.
Remove a key
Name | Type | Description |
---|---|---|
name | String | The name of the key to remove |
An optional object which may have the following keys:
Name | Type | Default | Description |
---|---|---|---|
timeout | Number |
undefined |
A timeout in ms |
signal | AbortSignal | undefined |
Can be used to cancel any long running requests started as a result of this call |
Type | Description |
---|---|
Promise<Object> |
An object that describes the removed key |
example of the returned object:
{
id: 'hash', // string - the hash of the key
name: 'self' // string - the name of the key
}
const key = await ipfs.key.rm('my-key')
console.log(key)
// { id: 'QmWETF5QvzGnP7jKq5sPDiRjSM2fzwzNsna4wSBEzRzK6W',
// name: 'my-key' }
A great source of examples can be found in the tests for this API.
Rename a key
Name | Type | Description |
---|---|---|
oldName | String | The current key name |
newName | String | The desired key name |
An optional object which may have the following keys:
Name | Type | Default | Description |
---|---|---|---|
timeout | Number |
undefined |
A timeout in ms |
signal | AbortSignal | undefined |
Can be used to cancel any long running requests started as a result of this call |
Type | Description |
---|---|
Promise<Object> |
An object that describes the renamed key |
const key = await ipfs.key.rename('my-key', 'my-new-key')
console.log(key)
// { id: 'Qmd4xC46Um6s24MradViGLFtMitvrR4SVexKUgPgFjMNzg',
// was: 'my-key',
// now: 'my-new-key',
// overwrite: false }
A great source of examples can be found in the tests for this API.
Export a key in a PEM encoded password protected PKCS #8
Name | Type | Description |
---|---|---|
name | String | The name of the key to export |
password | String | Password to set on the PEM output |
An optional object which may have the following keys:
Name | Type | Default | Description |
---|---|---|---|
timeout | Number |
undefined |
A timeout in ms |
signal | AbortSignal | undefined |
Can be used to cancel any long running requests started as a result of this call |
Type | Description |
---|---|
Promise<String> |
The string representation of the key |
const pem = await ipfs.key.export('self', 'password')
console.log(pem)
// -----BEGIN ENCRYPTED PRIVATE KEY-----
// MIIFDTA/BgkqhkiG9w0BBQ0wMjAaBgkqhkiG9w0BBQwwDQQIpdO40RVyBwACAWQw
// ...
// YA==
// -----END ENCRYPTED PRIVATE KEY-----
A great source of examples can be found in the tests for this API.
Import a PEM encoded password protected PKCS #8 key
Name | Type | Description |
---|---|---|
name | String | The name of the key to export |
pem | String | The PEM encoded key |
password | String | The password that protects the PEM key |
An optional object which may have the following keys:
Name | Type | Default | Description |
---|---|---|---|
timeout | Number |
undefined |
A timeout in ms |
signal | AbortSignal | undefined |
Can be used to cancel any long running requests started as a result of this call |
Type | Description |
---|---|
Promise<Object> |
An object that describes the new key |
const key = await ipfs.key.import('clone', pem, 'password')
console.log(key)
// { id: 'QmQRiays958UM7norGRQUG3tmrLq8pJdmJarwYSk2eLthQ',
// name: 'clone' }
A great source of examples can be found in the tests for this API.