# Class: Subkey

## Subkey(subkeyPacket, mainKey)

Class that represents a subkey packet and the relevant signatures.

## Constructor

#### new Subkey(subkeyPacket, mainKey)

##### Parameters:

Name | Type | Description
--- | --- | ---
`subkeyPacket` | SecretSubkeyPacket | PublicSubkeyPacket | subkey packet to hold in the Subkey
`mainKey` | Key | reference to main Key object, containing the primary key packet corresponding to the subkey

Source:
  - key/subkey.js, line 25

### Methods

#### clone() → {Subkey}

Shallow clone

Source:
  - key/subkey.js, line 48

##### Returns:

Type
  Subkey

#### getAlgorithmInfo() → {Object}

Returns algorithm information

Overrides:
  - PublicKeyPacket#getAlgorithmInfo
Source:
  - packet/public_key.js, line 262

##### Returns:

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

Type
  Object

#### getAlgorithmInfo() → {Object}

Returns algorithm information

Overrides:
  - PublicKeyPacket#getAlgorithmInfo
Source:
  - packet/public_key.js, line 262

##### Returns:

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

Type
  Object

#### getCreationTime() → {Date}

Returns the creation time of the key

Overrides:
  - PublicKeyPacket#getCreationTime
Source:
  - packet/public_key.js, line 190

##### Returns:

Type
  Date

#### getCreationTime() → {Date}

Returns the creation time of the key

Overrides:
  - PublicKeyPacket#getCreationTime
Source:
  - packet/public_key.js, line 190

##### Returns:

Type
  Date

#### (async) getExpirationTime(date, configopt) → {Promise.<(Date|Infinity|null)>}

Returns the expiration time of the subkey or Infinity if key does not expire. Returns null if the subkey is invalid.

##### Parameters:

Name | Type | Attributes | Description
--- | --- | --- | ---
`date` | Date |  | Use the given date instead of the current time
`config` | Object | <optional> | Full configuration, defaults to openpgp.config

Source:
  - key/subkey.js, line 110

##### Returns:

Type
  Promise.<(Date|Infinity|null)>

#### getFingerprint() → {String}

Calculates and returns the fingerprint of the key, as a string

Overrides:
  - PublicKeyPacket#getFingerprint
Source:
  - packet/public_key.js, line 246

##### Returns:

A string containing the fingerprint in lowercase hex

Type
  String

#### getFingerprint() → {String}

Calculates and returns the fingerprint of the key, as a string

Overrides:
  - PublicKeyPacket#getFingerprint
Source:
  - packet/public_key.js, line 246

##### Returns:

A string containing the fingerprint in lowercase hex

Type
  String

#### getKeyID() → {module:type/keyid~KeyID}

Return the key ID of the key

Overrides:
  - PublicKeyPacket#getKeyID
Source:
  - packet/public_key.js, line 198

##### Returns:

The 8-byte key ID

Type
  module:type/keyid~KeyID

#### getKeyID() → {module:type/keyid~KeyID}

Return the key ID of the key

Overrides:
  - PublicKeyPacket#getKeyID
Source:
  - packet/public_key.js, line 198

##### Returns:

The 8-byte key ID

Type
  module:type/keyid~KeyID

#### hasSameFingerprintAs() → {Boolean}

Calculates whether two keys have the same fingerprint without actually calculating the fingerprint

Overrides:
  - PublicKeyPacket#hasSameFingerprintAs
Source:
  - packet/public_key.js, line 254

##### Returns:

Whether the two keys have the same version and public key data.

Type
  Boolean

#### hasSameFingerprintAs() → {Boolean}

Calculates whether two keys have the same fingerprint without actually calculating the fingerprint

Overrides:
  - PublicKeyPacket#hasSameFingerprintAs
Source:
  - packet/public_key.js, line 254

##### Returns:

Whether the two keys have the same version and public key data.

Type
  Boolean

#### isDecrypted() → {Boolean|null}

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

Overrides:
  - PublicKeyPacket#isDecrypted
Source:
  - packet/public_key.js, line 182

##### Returns:

Type
  Boolean | null

#### isDecrypted() → {Boolean|null}

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

Overrides:
  - PublicKeyPacket#isDecrypted
Source:
  - packet/public_key.js, line 182

##### Returns:

Type
  Boolean | null

#### (async) isRevoked(signature, key,, dateopt, configopt) → {Promise.<Boolean>}

Checks if a binding signature of a subkey is revoked

##### Parameters:

Name | Type | Attributes | Description
--- | --- | --- | ---
`signature` | SignaturePacket |  | The binding signature to verify
`key,` | PublicSubkeyPacket | SecretSubkeyPacket | PublicKeyPacket | SecretKeyPacket |  | optional The key to verify the signature
`date` | Date | <optional> | Use the given date for verification instead of the current time
`config` | Object | <optional> | Full configuration, defaults to openpgp.config

Source:
  - key/subkey.js, line 67

##### Returns:

True if the binding signature is revoked.

Type
  Promise.<Boolean>

#### (async) revoke(primaryKey, reasonForRevocation, date, configopt) → {Promise.<Subkey>}

Revokes the subkey

##### Parameters:

Name | Type | Attributes | Description
--- | --- | --- | ---
`primaryKey` | SecretKeyPacket |  | decrypted private primary key for revocation
`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
`config` | Object | <optional> | Full configuration, defaults to openpgp.config

Source:
  - key/subkey.js, line 178

##### Returns:

New subkey with revocation signature.

Type
  Promise.<Subkey>

#### toPacketList() → {PacketList}

Transforms structured subkey data to packetlist

Source:
  - key/subkey.js, line 36

##### Returns:

Type
  PacketList

#### (async) update(subkey, dateopt, configopt)

Update subkey with new components from specified subkey

##### Parameters:

Name | Type | Attributes | Description
--- | --- | --- | ---
`subkey` | Subkey |  | Source subkey to merge
`date` | Date | <optional> | Date to verify validity of signatures
`config` | Object | <optional> | Full configuration, defaults to openpgp.config

Source:
  - key/subkey.js, line 132

##### Throws:

if update failed

Type
  Error

#### (async) verify(date, configopt) → {Promise.<SignaturePacket>}

Verify subkey. Checks for revocation signatures, expiration time and valid binding signature.

##### Parameters:

Name | Type | Attributes | Description
--- | --- | --- | ---
`date` | Date |  | Use the given date instead of the current time
`config` | Object | <optional> | Full configuration, defaults to openpgp.config

Source:
  - key/subkey.js, line 86

##### Throws:

if the subkey is invalid.

Type
  Error

##### Returns:

Type
  Promise.<SignaturePacket>