Class: Key

key.Key(packetlist)

Class that represents an OpenPGP key. Must contain a primary key. Can contain additional subkeys, signatures, user ids, user attributes.

Constructor

new Key(packetlist)

Parameters:
Name Type Description
packetlist module:packet.List

The packets that form this key

Source:

Methods

(async) applyRevocationCertificate(revocationCertificate) → {Promise.<module:key.Key>}

Applies a revocation certificate to a key This adds the first signature packet in the armored text to the key, if it is a valid revocation signature.

Parameters:
Name Type Description
revocationCertificate String

armored revocation certificate

Source:
Returns:

new revoked key

Type
Promise.<module:key.Key>

armor() → {ReadableStream.<String>}

Returns ASCII armored text of key

Source:
Returns:

ASCII armor

Type
ReadableStream.<String>

(async) decrypt(passphrases, keyId) → {Promise.<Boolean>}

Decrypts all secret key and subkey packets matching keyId

Parameters:
Name Type Description
passphrases String | Array.<String>
keyId module:type/keyid
Source:
Returns:

true if all matching key and subkey packets decrypted successfully

Type
Promise.<Boolean>

(async) encrypt(passphrases, keyId) → {Promise.<Array.<(module:packet.SecretKey|module:packet.SecretSubkey)>>}

Encrypts all secret key and subkey packets matching keyId

Parameters:
Name Type Description
passphrases String | Array.<String>

if multiple passphrases, then should be in same order as packets each should encrypt

keyId module:type/keyid
Source:
Returns:
Type
Promise.<Array.<(module:packet.SecretKey|module:packet.SecretSubkey)>>

getAlgorithmInfo() → {Object}

Returns algorithm information

Source:
Returns:

An object of the form {algorithm: String, bits:int, curve:String}

Type
Object

getCreationTime() → {Date}

Returns the creation time of the key

Source:
Returns:
Type
Date

(async) getEncryptionKey(keyId,, date,, userId,) → {Promise.<(module:key.Key|module:key~SubKey|null)>}

Returns last created key or key by given keyId that is available for encryption or decryption

Parameters:
Name Type Description
keyId, module:type/keyid

optional

date, Date

optional

userId, String

optional

Source:
Returns:

key or null if no encryption key has been found

Type
Promise.<(module:key.Key|module:key~SubKey|null)>

(async) getExpirationTime(capabilities,, keyId,, userId,) → {Promise.<Date>}

Returns the latest date when the key can be used for encrypting, signing, or both, depending on the capabilities paramater. When capabilities is null, defaults to returning the expiry date of the primary key. Returns Infinity if the key doesn't expire.

Parameters:
Name Type Description
capabilities, encrypt | sign | encrypt_sign

optional

keyId, module:type/keyid

optional

userId, Object

optional user ID

Source:
Returns:
Type
Promise.<Date>

getFingerprint() → {String}

Calculates the fingerprint of the key

Source:
Returns:

A string containing the fingerprint in lowercase hex

Type
String

getKeyId() → {String}

Calculates the key id of the key

Source:
Returns:

A 8 byte key id

Type
String

getKeyIds() → {Array.<module:type/keyid>}

Returns key IDs of all keys

Source:
Returns:
Type
Array.<module:type/keyid>

getKeys(keyId) → {Array.<(module:key.Key|module:key~SubKey)>}

Returns an array containing all public or private keys matching keyId. If keyId is not present, returns all keys starting with the primary key.

Parameters:
Name Type Description
keyId type/keyid
Source:
Returns:
Type
Array.<(module:key.Key|module:key~SubKey)>

(async) getPrimaryUser(date, userId) → {Promise.<{user: module:key.User, selfCertification: module:packet.Signature}>}

Returns primary user and most significant (latest valid) self signature

  • if multiple primary users exist, returns the one with the latest self signature
  • otherwise, returns the user with the latest self signature
Parameters:
Name Type Description
date Date

use the given date for verification instead of the current time

userId Object

(optional) user ID to get instead of the primary user, if it exists

Source:
Returns:

The primary user and the self signature

Type
Promise.<{user: module:key.User, selfCertification: module:packet.Signature}>

getRevocationCertificate() → {String}

Get revocation certificate from a revoked key. (To get a revocation certificate for an unrevoked key, call revoke() first.)

Source:
Returns:

armored revocation certificate

Type
String

(async) getSigningKey(keyId,, date, userId,) → {Promise.<(module:key.Key|module:key~SubKey|null)>}

Returns last created key or key by given keyId that is available for signing and verification

Parameters:
Name Type Description
keyId, module:type/keyid

optional

date Date

use the given date for verification instead of the current time

userId, Object

optional user ID

Source:
Returns:

key or null if no signing key has been found

Type
Promise.<(module:key.Key|module:key~SubKey|null)>

getSubkeys(keyId) → {Array.<module:key~SubKey>}

Returns an array containing all public or private subkeys matching keyId; If keyId is not present, returns all subkeys.

Parameters:
Name Type Description
keyId type/keyid
Source:
Returns:
Type
Array.<module:key~SubKey>

getUserIds() → {Array.<string>}

Returns userids

Source:
Returns:

array of userids

Type
Array.<string>

isDecrypted() → {Boolean|null}

Check whether secret-key data is available in decrypted form. Returns null for public keys.

Source:
Returns:
Type
Boolean | null

isPrivate() → {Boolean}

Returns true if this is a private key

Source:
Returns:
Type
Boolean

isPublic() → {Boolean}

Returns true if this is a public key

Source:
Returns:
Type
Boolean

(async) isRevoked(signature, key,, date) → {Promise.<Boolean>}

Checks if a signature on a key is revoked

Parameters:
Name Type Description
{module:packet.SecretKey|
signature module:packet.Signature

The signature to verify

key, module:packet.PublicSubkey | module:packet.SecretSubkey | module:packet.PublicKey | module:packet.SecretKey

optional The key to verify the signature

date Date

Use the given date instead of the current time

Source:
Returns:

True if the certificate is revoked

Type
Promise.<Boolean>

packetlist2structure(packetlist)

Transforms packetlist to structured key data

Parameters:
Name Type Description
packetlist module:packet.List

The packets that form a key

Source:

(async) revoke(reasonForRevocation, date) → {Promise.<module:key.Key>}

Revokes the key

Parameters:
Name Type Description
reasonForRevocation Object

optional, object indicating the reason for revocation

Properties
Name Type Description
flag module:enums.reasonForRevocation

optional, flag indicating the reason for revocation

string String

optional, string explaining the reason for revocation

date Date

optional, override the creationtime of the revocation signature

Source:
Returns:

new key with revocation signature

Type
Promise.<module:key.Key>

(async) signAllUsers(privateKeys) → {Promise.<module:key.Key>}

Signs all users of key

Parameters:
Name Type Description
privateKeys Array.<module:key.Key>

decrypted private keys for signing

Source:
Returns:

new public key with new certificate signature

Type
Promise.<module:key.Key>

(async) signPrimaryUser(privateKey) → {Promise.<module:key.Key>}

Signs primary user of key

Parameters:
Name Type Description
privateKey Array.<module:key.Key>

decrypted private keys for signing

Source:
Returns:

new public key with new certificate signature

Type
Promise.<module:key.Key>

toPacketlist() → {module:packet.List}

Transforms structured key data to packetlist

Source:
Returns:

The packets that form a key

Type
module:packet.List

toPublic() → {module:key.Key}

Returns key as public key (shallow copy)

Source:
Returns:

new public Key

Type
module:key.Key

(async) update(key) → {Promise.<undefined>}

Update key with new components from specified key with same key ID: users, subkeys, certificates are merged into the destination key, duplicates and expired signatures are ignored.

If the specified key is a private key and the destination key is public, the destination key is transformed to a private key.

Parameters:
Name Type Description
key module:key.Key

Source key to merge

Source:
Returns:
Type
Promise.<undefined>

(async) verifyAllUsers(keys) → {Promise.<Array.<{userid: String, keyid: module:type/keyid, valid: Boolean}>>}

Verifies all users of key

  • if no arguments are given, verifies the self certificates;
  • otherwise, verifies all certificates signed with given keys.
Parameters:
Name Type Description
keys Array.<module:key.Key>

array of keys to verify certificate signatures

Source:
Returns:

list of userid, signer's keyid and validity of signature

Type
Promise.<Array.<{userid: String, keyid: module:type/keyid, valid: Boolean}>>

(async) verifyPrimaryKey(date, userId) → {Promise.<module:enums.keyStatus>}

Verify primary key. Checks for revocation signatures, expiration time and valid self signature

Parameters:
Name Type Description
date Date

(optional) use the given date for verification instead of the current time

userId Object

(optional) user ID

Source:
Returns:

The status of the primary key

Type
Promise.<module:enums.keyStatus>

(async) verifyPrimaryUser(keys) → {Promise.<Array.<{keyid: module:type/keyid, valid: Boolean}>>}

Verifies primary user of key

  • if no arguments are given, verifies the self certificates;
  • otherwise, verifies all certificates signed with given keys.
Parameters:
Name Type Description
keys Array.<module:key.Key>

array of keys to verify certificate signatures

Source:
Returns:

List of signer's keyid and validity of signature

Type
Promise.<Array.<{keyid: module:type/keyid, valid: Boolean}>>