# Class: SignaturePacket

## SignaturePacket()

Implementation of the Signature Packet (Tag 2)

RFC4480 5.2: A Signature packet describes a binding between some public key and some data. The most common signatures are a signature of a file or a block of text, and a signature that is a certification of a User ID.

## Constructor

#### new SignaturePacket()

Source:
  - packet/signature.js, line 46

### Members

#### hashAlgorithm :enums.hash

##### Type:

- enums.hash

Source:
  - packet/signature.js, line 56

#### publicKeyAlgorithm :enums.publicKey

##### Type:

- enums.publicKey

Source:
  - packet/signature.js, line 58

#### signatureType :enums.signature

##### Type:

- enums.signature

Source:
  - packet/signature.js, line 54

### Methods

#### getExpirationTime() → {Date|Infinity}

Returns the expiration time of the signature or Infinity if signature does not expire

Source:
  - packet/signature.js, line 806

##### Returns:

Expiration time.

Type
  Date | Infinity

#### isExpired(dateopt) → {Boolean}

Verifies signature expiration date

##### Parameters:

Name | Type | Attributes | Description
--- | --- | --- | ---
`date` | Date | <optional> | Use the given date for verification instead of the current time

Source:
  - packet/signature.js, line 794

##### Returns:

True if expired.

Type
  Boolean

#### read(bytes) → {SignaturePacket}

parsing function for a signature packet (tag 2).

##### Parameters:

Name | Type | Description
--- | --- | ---
`bytes` | String | Payload of a tag 2 packet

Source:
  - packet/signature.js, line 111

##### Returns:

Object representation.

Type
  SignaturePacket

#### (async) sign(key, data, dateopt, detachedopt)

Signs provided data. This needs to be done prior to serialization.

##### Parameters:

Name | Type | Attributes | Default | Description
--- | --- | --- | --- | ---
`key` | SecretKeyPacket |  |  | Private key used to sign the message.
`data` | Object |  |  | Contains packets to be signed.
`date` | Date | <optional> |  | The signature creation time.
`detached` | Boolean | <optional> | false | Whether to create a detached signature

Source:
  - packet/signature.js, line 198

##### Throws:

if signing failed

Type
  Error

#### (async) verify(key, signatureType, data, dateopt, detachedopt, configopt)

verifies the signature packet. Note: not all signature types are implemented

##### Parameters:

Name | Type | Attributes | Default | Description
--- | --- | --- | --- | ---
`key` | PublicSubkeyPacket | PublicKeyPacket | SecretSubkeyPacket | SecretKeyPacket |  |  | the public key to verify the signature
`signatureType` | module:enums.signature |  |  | Expected signature type
`data` | Uint8Array | Object |  |  | Data which on the signature applies
`date` | Date | <optional> |  | Use the given date instead of the current time to check for signature validity and expiration
`detached` | Boolean | <optional> | false | Whether to verify a detached signature
`config` | Object | <optional> |  | Full configuration, defaults to openpgp.config

Source:
  - packet/signature.js, line 726

##### Throws:

if signature validation failed

Type
  Error

#### writeHashedSubPackets() → {Uint8Array}

Creates Uint8Array of bytes of all subpacket data except Issuer and Embedded Signature subpackets

Source:
  - packet/signature.js, line 250

##### Returns:

Subpacket data.

Type
  Uint8Array

#### writeParams() → {Uint8Array|ReadableStream.<Uint8Array>}

Source:
  - packet/signature.js, line 167

##### Returns:

Type
  Uint8Array | ReadableStream.<Uint8Array>

#### writeUnhashedSubPackets() → {Uint8Array}

Creates an Uint8Array containing the unhashed subpackets

Source:
  - packet/signature.js, line 372

##### Returns:

Subpacket data.

Type
  Uint8Array