new FilePrivateKeyStorage(nonDefaultTpmPath)
FilePrivateKeyStorage works with NFD's default private key storage, the files
stored in .ndn/ndnsec-tpm-file. This library will not be available from the
browser
Parameters:
Name | Type | Description |
---|---|---|
nonDefaultTpmPath |
string | if desired, override the default TPM path (i.e. .ndn/ndnsec-tpm-file) |
Methods
(static) getUserHomePath() → {string}
Retrieve the user's current home directory
Returns:
path to the user's home directory
- Type
- string
deleteKey(keyName)
Delete all keys with this name. If the key doesn't exist, do nothing.
Parameters:
Name | Type | Description |
---|---|---|
keyName |
Name | The name of the key pair. |
deleteKeyPairPromise(keyName) → {SyncPromise}
Delete a pair of asymmetric keys. If the key doesn't exist, do nothing.
Parameters:
Name | Type | Description |
---|---|---|
keyName |
Name | The name of the key pair. |
Returns:
A promise that fulfills when the key pair is deleted.
- Type
- SyncPromise
doesKeyExistPromise(keyName, keyClass) → {SyncPromise}
Check if a particular key exists.
Parameters:
Name | Type | Description |
---|---|---|
keyName |
Name | The name of the key. |
keyClass |
number | The class of the key, e.g. KeyClass.PUBLIC, KeyClass.PRIVATE, or KeyClass.SYMMETRIC. |
Returns:
A promise which returns true if the key exists.
- Type
- SyncPromise
generateKeyPairPromise(keyName, params) → {SyncPromise}
Generate a pair of asymmetric keys; only currently supports RSA
Parameters:
Name | Type | Description |
---|---|---|
keyName |
Name | The name of the key pair. |
params |
KeyParams | The parameters of the key. |
Returns:
A promise that fulfills when the pair is generated.
- Type
- SyncPromise
getPrivateKey(keyName, keyType) → {string}
A private method to get the private key.
Parameters:
Name | Type | Description |
---|---|---|
keyName |
Name | The name of private key. |
keyType |
Array.<KeyType> | Set keyType[0] to the KeyType. |
Returns:
The PEM-encoded private key for use by the crypto module.
- Type
- string
getPublicKeyPromise(keyName) → {SyncPromise}
Get the public key
Parameters:
Name | Type | Description |
---|---|---|
keyName |
Name | The name of public key. |
Returns:
A promise that returns the PublicKey.
- Type
- SyncPromise
maintainMapping(keyNameUri) → {string}
Use nameTransform to get the file path for keyName (without the extension)
and also add to the mapping.txt file.
Parameters:
Name | Type | Description |
---|---|---|
keyNameUri |
string | The key name URI which is transformed to a file path. |
Returns:
The key file path without the extension.
- Type
- string
nameTransform(keyNameUri, extension) → {string}
Transform a key name to its hashed file path.
Parameters:
Name | Type | Description |
---|---|---|
keyNameUri |
string | The key name URI which is transformed to a file path. |
extension |
string | The file name extension. You can use KeyClassExtensions[keyClass]. |
Returns:
The hashed key file path.
- Type
- string
read(keyName, keyClass) → {Buffer}
Read from a key file
Parameters:
Name | Type | Description |
---|---|---|
keyName |
Name | |
keyClass |
number | An int from KeyClass. |
Throws:
Error if the file cannot be read from
Returns:
key bytes
- Type
- Buffer
signPromise(data, keyName, digestAlgorithm) → {SyncPromise}
Fetch the private key for keyName and sign the data to produce a signature Blob.
Parameters:
Name | Type | Description |
---|---|---|
data |
Buffer | Pointer to the input byte array. |
keyName |
Name | The name of the signing key. |
digestAlgorithm |
number | (optional) The digest algorithm from DigestAlgorithm, such as DigestAlgorithm.SHA256. If omitted, use DigestAlgorithm.SHA256. |
Returns:
A promise that returns the signature Blob.
- Type
- SyncPromise
write(keyName, keyClass, bytes)
Write to a key file. If keyClass is PRIVATE, then also update mapping.txt.
Parameters:
Name | Type | Description |
---|---|---|
keyName |
Name | |
keyClass |
KeyClass | [PUBLIC, PRIVATE, SYMMETRIC] |
bytes |
Buffer |
Throws:
Error if the file cannot be written to