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, stored as a WIF string.

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 bytesKey from the SHA-256 of the seed
fromLoginusername, password, roleHive login key for that role
randomKeynoneNew random key
createPublicoptional prefixPublicKey
sign32-byte hashSignature
toStringnoneWIF string
inspectnoneMasked WIF, safe to log
getSharedSecretPublicKey64-byte secret, used for memo encryption

fromLogin roles are owner, active (the default), posting, and memo. The seed is username + role + password, the same as Hive wallets use.

PublicKey

A public key string starts with the address prefix, STM by default.

import { PublicKey } from 'hive-tx'

const pub = privateKey.createPublic()
const fromStr = PublicKey.from('STM8m5UgaFAAYQRuaNejYdS8FVLVp9Ss3K1qAVk5de6F8s3HnVbvA')
const ok = pub.verify(messageHash, signature)
MethodDoes
from / fromStringParses a public key string.
verifyReturns true if the signature (object or hex) matches the 32-byte hash.
toString / toJSONReturns the key string with its prefix.

Signature

A compact recoverable signature, written as 130 hex characters.

import { Signature } from 'hive-tx'

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

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

To check a Hive Keychain requestSignBuffer proof, use utils.verifyMessage; see utilities.