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, optsopt) → {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 <optional>

You may also specify initialization vector and ephemeral private key to get deterministic results

Properties
Name Type Description
iv Buffer

Initialization vector (16 bytes)

ephemPrivateKey Buffer

Ephemeral private key (32 bytes)

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 a 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.<null>}

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.<null>