hive-tx v7
GitHub npm

Use

Keys and signatures

PrivateKey, PublicKey, and Signature create Hive keys and verify signatures.

PrivateKey

A private key is a secp256k1 secret. The WIF string is the storage format.

import { PrivateKey } from 'hive-tx'

const fromWif = PrivateKey.from('5JdeC9P7Pbd1uGdFVEsJ41EkEnADbbHGq6p1BwFxm6txNBsQnsw')
const random = PrivateKey.randomKey()
const fromSeed = PrivateKey.fromSeed('my-secret-seed')
const posting = PrivateKey.fromLogin('alice', 'master-password', 'posting')
MethodInputOutput
fromWIF string or 32-byte Uint8ArrayPrivateKey
fromStringWIF stringPrivateKey
fromSeedUTF-8 string, hex string, or bytesSHA-256 of the seed as a key
fromLoginusername, password, roleHive login key for that role
randomKeynoneNew random key
createPublicoptional prefixPublicKey
sign32-byte hashSignature
toStringnoneWIF string
inspectnoneMasked WIF string
getSharedSecretPublicKey64-byte secret for memo encryption

Roles for fromLogin are owner, active, posting, and memo. The default role is active.

The seed for fromLogin is username + role + password.

PublicKey

A Hive public key string starts with the address prefix. The default prefix is STM.

import { PublicKey } from 'hive-tx'

const pub = privateKey.createPublic()
const fromStr = PublicKey.from('STM8m5UgaFAAYQRuaNejYdS8FVLVp9Ss3K1qAVk5de6F8s3HnVbvA')
const ok = pub.verify(messageHash, signature)
MethodFunction
from / fromStringRead a public key string.
verifyReturn true if the signature matches the 32-byte hash.
toString / toJSONReturn the public key string with prefix.

Signature

A compact recoverable signature is a hex string with 130 characters.

import { Signature } from 'hive-tx'

const sig = Signature.from(hex)
const recovered = sig.getPublicKey(messageHash)
const hexOut = sig.customToString()

getPublicKey needs a 32-byte hash as Uint8Array or a 64-character hex string.

To recover a Hive Keychain requestSignBuffer proof:

  1. Create a SHA-256 hash of the UTF-8 message.
  2. Remove a leading 0x from the signature if it is present.
  3. Call Signature.from(hex).getPublicKey(hash).toString().