Module: bitmessage/crypto

Isomorphic Bitmessage crypto module. Reexports platform-dependent implementations and also some common routines.

Source:

Methods

(static) decrypt(privateKey, buf) → {Promise.<Buffer>}

Decrypt message using given private key.

Parameters:
Name Type Description
privateKey Buffer

A 32-byte private key of recepient of the mesage

buf Buffer

Encrypted data

Source:
Returns:
  • A promise that resolves with the plaintext on successful decryption and rejects on failure.
Type
Promise.<Buffer>

(static) encrypt(publicKeyTo, msg, optsnullable) → {Promise.<Buffer>}

Encrypt message for given recepient's public key.

Parameters:
Name Type Attributes Description
publicKeyTo Buffer

Recipient's public key (65 bytes)

msg Buffer

The message being encrypted

opts Object <nullable>

You may also specify initialization vector (16 bytes) and ephemeral private key (32 bytes) to get deterministic results.

Source:
Returns:
  • A promise that resolves with the buffer in encrypted format successful encryption and rejects on failure.
Type
Promise.<Buffer>

(static) getPrivate() → {Buffer}

Generate new random private key.

Source:
Returns:

New private key.

Type
Buffer

(static) getPublic(privateKey) → {Buffer}

Generate public key for the given private key.

Parameters:
Name Type Description
privateKey Buffer

A 32-byte private key

Source:
Returns:

A 65-byte (uncompressed) public key.

Type
Buffer

(static) randomBytes(size) → {Buffer}

Generate cryptographically strong pseudo-random data.

Parameters:
Name Type Description
size number

Number of bytes

Source:
Returns:

Buffer with random data.

Type
Buffer

(static) ripemd160(buf) → {Buffer}

Calculate RIPEMD-160 hash.

Parameters:
Name Type Description
buf Buffer

Input data

Source:
Returns:

Resulting hash.

Type
Buffer

(static) sha1(buf) → {Buffer}

Calculate SHA-1 hash.

Parameters:
Name Type Description
buf Buffer

Input data

Source:
Returns:

Resulting hash.

Type
Buffer

(static) sha256(buf) → {Buffer}

Calculate SHA-256 hash.

Parameters:
Name Type Description
buf Buffer

Input data

Source:
Returns:

Resulting hash.

Type
Buffer

(static) sha512(buf) → {Buffer}

Calculate SHA-512 hash.

Parameters:
Name Type Description
buf Buffer

Input data

Source:
Returns:

Resulting hash.

Type
Buffer

(static) sign(privateKey, msg) → {Promise.<Buffer>}

Sign message using ecdsa-with-sha1 scheme.

Parameters:
Name Type Description
privateKey Buffer

A 32-byte private key

msg Buffer

The message being signed

Source:
Returns:

A promise that contains signature in DER format when fulfilled.

Type
Promise.<Buffer>

(static) verify(publicKey, msg, sig) → {Promise.<undefined>}

Verify signature using ecdsa-with-sha1 scheme.

Parameters:
Name Type Description
publicKey Buffer

A 65-byte public key

msg Buffer

The message being verified

sig Buffer

The signature in DER format

Source:
Returns:

A promise that resolves on correct signature and rejects on bad key or signature.

Type
Promise.<undefined>