secp256k1

Methods

(inner) decrypt(derive, ciphertext) → {Promise}

Decrypt ECIES ciphertext object with derived private key https://en.wikipedia.org/wiki/Integrated_Encryption_Scheme

Parameters:
Name Type Description
derive string

key derivation path, see BIP32

ciphertext Object

encrypted message object

Source:
Example
import crypto from 'crypto'
import secp256k1 from 'secp256k1'

vault.secp256k1.decrypt('m/0', ecies)
  .then((plaintext) => {
    console.log("Decrypted Message:", plaintext)
  })

(inner) encrypt(pubkey, plaintext) → {Promise}

Encrypt plaintext data with ECIES against provided public key https://en.wikipedia.org/wiki/Integrated_Encryption_Scheme

Parameters:
Name Type Description
pubkey string

Uncompressed secp256k1 public key encoded in hex

plaintext string

Plain text message to encrypt

Source:
Example
import crypto from 'crypto'
import secp256k1 from 'secp256k1'

const key = crypto.randomBytes(32)
const pubkey = secp256k1.publicKeyCreate(key, false).toString('hex')

vault.secp256k1.encrypt(pubkey, 'Some message here')
  .then((ecies) => {
    console.log("Encrypted Message:", ecies)
  })

(inner) keyInfo(derive) → {Promise}

Get derived public key and extended public key information

Parameters:
Name Type Description
derive string

key derivation path, see BIP32

Source:
Example
vault.secp256k1.keyInfo('m/0')
  .then(({ pubkey, pubex }) => {
    console.log("Public Key:", pubkey)
    console.log("Public Extended:", pubex)
  })

(inner) sign(derive, hash) → {Promise}

Sign hash with derived private key

Parameters:
Name Type Description
derive string

key derivation path, see BIP32

hash string

32-bit SHA256 hex encoded hash to sign

Source:
Example
vault.secp256k1.sign('m/0', sha256('Some Message Here').toString('hex'))
  .then((signature) => {
    console.log("Signature:", signature)
  })