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')
| Method | Input | Output |
|---|---|---|
from | WIF string or 32-byte Uint8Array | PrivateKey |
fromString | WIF string | PrivateKey |
fromSeed | UTF-8 string, hex string, or bytes | Key from the SHA-256 of the seed |
fromLogin | username, password, role | Hive login key for that role |
randomKey | none | New random key |
createPublic | optional prefix | PublicKey |
sign | 32-byte hash | Signature |
toString | none | WIF string |
inspect | none | Masked WIF, safe to log |
getSharedSecret | PublicKey | 64-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)
| Method | Does |
|---|---|
from / fromString | Parses a public key string. |
verify | Returns true if the signature (object or hex) matches the 32-byte hash. |
toString / toJSON | Returns 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.