# Module: key/helper

Provides helpers methods for key module

Source:
  - key/helper.js, line 1

### Methods

#### (static) checkKeyRequirements(keyPacket, config)

Check key against blacklisted algorithms and minimum strength requirements.

##### Parameters:

Name | Type | Description
--- | --- | ---
`keyPacket` | SecretKeyPacket | PublicKeyPacket | SecretSubkeyPacket | PublicSubkeyPacket |
`config` | Config |

Source:
  - key/helper.js, line 432

##### Throws:

if the key packet does not meet the requirements

Type
  Error

#### (static) createBindingSignature(subkey, primaryKey, options, config)

Create Binding signature to the key according to the https://tools.ietf.org/html/rfc4880#section-5.2.1

##### Parameters:

Name | Type | Description
--- | --- | ---
`subkey` | SecretSubkeyPacket | Subkey key packet
`primaryKey` | SecretKeyPacket | Primary key packet
`options` | Object |
`config` | Object | Full configuration

Source:
  - key/helper.js, line 84

#### (static) createSignaturePacket(dataToSign, privateKey, signingKeyPacket, signaturePropertiesopt, dateopt, userIDopt, notationsopt, detachedopt, config) → {Promise.<SignaturePacket>}

Create signature packet

##### Parameters:

Name | Type | Attributes | Description
--- | --- | --- | ---
`dataToSign` | Object |  | Contains packets to be signed
`privateKey` | PrivateKey |  | key to get preferences from
`signingKeyPacket` | SecretKeyPacket | SecretSubkeyPacket |  | secret key packet for signing
`signatureProperties` | Object | <optional> | Properties to write on the signature packet before signing
`date` | Date | <optional> | Override the creationtime of the signature
`userID` | Object | <optional> | User ID
`notations` | Array | <optional> | Notation Data to add to the signature, e.g. [{ name: 'test@example.org', value: new TextEncoder().encode('test'), humanReadable: true, critical: false }]
`detached` | Object | <optional> | Whether to create a detached signature packet
`config` | Object |  | full configuration

Source:
  - key/helper.js, line 210

##### Returns:

Signature packet.

Type
  Promise.<SignaturePacket>

#### (static) getKeyExpirationTime(keyPacket, signature) → {Date|Infinity}

Returns key expiration time based on the given certification signature. The expiration time of the signature is ignored.

##### Parameters:

Name | Type | Description
--- | --- | ---
`keyPacket` | PublicSubkeyPacket | PublicKeyPacket | key to check
`signature` | SignaturePacket | signature to process

Source:
  - key/helper.js, line 309

##### Returns:

expiration time or infinity if the key does not expire

Type
  Date | Infinity

#### (async, static) getLatestValidSignature(signatures, publicKey, date, config) → {Promise.<SignaturePacket>}

Returns the valid and non-expired signature that has the latest creation date, while ignoring signatures created in the future.

##### Parameters:

Name | Type | Description
--- | --- | ---
`signatures` | Array.<SignaturePacket> | List of signatures
`publicKey` | PublicKeyPacket | PublicSubkeyPacket | Public key packet to verify the signature
`date` | Date | Use the given date instead of the current time
`config` | Object | full configuration

Source:
  - key/helper.js, line 43

##### Returns:

The latest valid signature.

Type
  Promise.<SignaturePacket>

#### (async, static) getPreferredCipherSuite(keysopt, dateopt, userIDsopt, configopt) → {Promise.<{symmetricAlgo: module:enums.symmetric, aeadAlgo: (module:enums.aead|undefined)}>}

Returns the preferred symmetric and AEAD algorithm (if any) for a set of keys

##### Parameters:

Name | Type | Attributes | Description
--- | --- | --- | ---
`keys` | Array.<Key> | <optional> | Set of keys
`date` | Date | <optional> | Use the given date for verification instead of the current time
`userIDs` | Array | <optional> | User IDs
`config` | Object | <optional> | Full configuration, defaults to openpgp.config

Source:
  - key/helper.js, line 171

##### Returns:

Object containing the preferred symmetric algorithm, and the preferred AEAD algorithm, or undefined if CFB is preferred

Type
  Promise.<{symmetricAlgo: module:enums.symmetric, aeadAlgo: (module:enums.aead|undefined)}>

#### (async, static) getPreferredCompressionAlgo(keysopt, dateopt, userIDsopt, configopt) → {Promise.<module:enums.compression>}

Returns the preferred compression algorithm for a set of keys

##### Parameters:

Name | Type | Attributes | Description
--- | --- | --- | ---
`keys` | Array.<Key> | <optional> | Set of keys
`date` | Date | <optional> | Use the given date for verification instead of the current time
`userIDs` | Array | <optional> | User IDs
`config` | Object | <optional> | Full configuration, defaults to openpgp.config

Source:
  - key/helper.js, line 147

##### Returns:

Preferred compression algorithm

Type
  Promise.<module:enums.compression>

#### (async, static) getPreferredHashAlgo(keyopt, keyPacket, dateopt, userIDopt, config) → {Promise.<enums.hash>}

Returns the preferred signature hash algorithm of a key

##### Parameters:

Name | Type | Attributes | Description
--- | --- | --- | ---
`key` | Key | <optional> | The key to get preferences from
`keyPacket` | SecretKeyPacket | SecretSubkeyPacket |  | key packet used for signing
`date` | Date | <optional> | Use the given date for verification instead of the current time
`userID` | Object | <optional> | User ID
`config` | Object |  | full configuration

Source:
  - key/helper.js, line 115

##### Returns:

Type
  Promise.<enums.hash>

#### (async, static) isDataRevoked(primaryKey, dataToVerify, revocations, signature, key,, date, config) → {Promise.<Boolean>}

Checks if a given certificate or binding signature is revoked

##### Parameters:

Name | Type | Description
--- | --- | ---
`primaryKey` | SecretKeyPacket | PublicKeyPacket | The primary key packet
`dataToVerify` | Object | The data to check
`revocations` | Array.<SignaturePacket> | The revocation signatures to check
`signature` | SignaturePacket | The certificate or signature to check
`key,` | PublicSubkeyPacket | SecretSubkeyPacket | PublicKeyPacket | SecretKeyPacket | optional The key packet to verify the signature, instead of the primary key
`date` | Date | Use the given date instead of the current time
`config` | Object | Full configuration

Source:
  - key/helper.js, line 268

##### Returns:

True if the signature revokes the data.

Type
  Promise.<Boolean>

#### (static) mergeSignatures(source, dest, attr, dateopt, checkFnopt)

Merges signatures from source[attr] to dest[attr]

##### Parameters:

Name | Type | Attributes | Description
--- | --- | --- | ---
`source` | Object |  |
`dest` | Object |  |
`attr` | String |  |
`date` | Date | <optional> | date to use for signature expiration check, instead of the current time
`checkFn` | function | <optional> | signature only merged if true

Source:
  - key/helper.js, line 234