signer

package
v0.4.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 12, 2026 License: MIT Imports: 23 Imported by: 0

Documentation

Overview

Package signer holds the SDK's private-key-bearing implementations of nimiq.Signer.

It is a separate package so that services which only read the chain — balance lookups, transaction verification, confirmation tracking — can import nimiq and nimiq/rpc without ever linking key-handling code. Keep it that way: nothing here should be needed to inspect or verify a transaction.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func EncryptPrivateKey added in v0.2.0

func EncryptPrivateKey(seed []byte, passphrase []byte) ([]byte, error)

EncryptPrivateKey encrypts a 32-byte private key under a passphrase, returning the serialized key file.

func SaveEncryptedKeyFile added in v0.2.0

func SaveEncryptedKeyFile(path string, seed, passphrase []byte) error

SaveEncryptedKeyFile writes an encrypted key file with owner-only permissions, refusing to overwrite an existing file.

Types

type MnemonicType added in v0.3.0

type MnemonicType int

MnemonicType classifies a recovery phrase's checksum scheme.

const (
	// MnemonicUnknown means the phrase validates as both BIP39 and legacy.
	// Callers must not guess which branch to derive.
	MnemonicUnknown MnemonicType = -1
	// MnemonicLegacy is the deprecated CRC-8 checksum scheme.
	MnemonicLegacy MnemonicType = 0
	// MnemonicBIP39 is the standard SHA-256 checksum scheme.
	MnemonicBIP39 MnemonicType = 1
)

func TypeOf added in v0.3.0

func TypeOf(phrase string) (MnemonicType, error)

TypeOf reports which checksum scheme phrase uses.

type PrivateKey

type PrivateKey struct {
	// contains filtered or unexported fields
}

PrivateKey signs with an in-process Ed25519 key.

The key material lives in ordinary Go memory for the lifetime of the value: it can be paged to swap and will appear in a core dump. That is acceptable for a hot wallet with a bounded balance and is not acceptable for a treasury. For those, implement nimiq.Signer against a KMS, an HSM or a separate signing service — no transaction-handling code has to change.

func DecryptPrivateKey added in v0.2.0

func DecryptPrivateKey(fileData, passphrase []byte) (*PrivateKey, error)

DecryptPrivateKey recovers a signer from an encrypted key file.

The error deliberately does not distinguish a wrong passphrase from a corrupted file, and never echoes the passphrase or any plaintext.

func FromMnemonic added in v0.3.0

func FromMnemonic(phrase, password string) (*PrivateKey, error)

FromMnemonic derives the first account key from a BIP39 phrase.

Ambiguous (MnemonicUnknown) and legacy phrases are rejected: deriving the wrong branch silently hands the user an empty wallet. Use FromMnemonicType for an explicit legacy import.

func FromMnemonicType added in v0.3.0

func FromMnemonicType(phrase, password string, kind MnemonicType) (*PrivateKey, error)

FromMnemonicType derives a key using an explicit checksum scheme.

func Generate

func Generate() (*PrivateKey, error)

Generate creates a new random key using crypto/rand.

func LoadEncryptedKeyFile added in v0.2.0

func LoadEncryptedKeyFile(path string, passphrase []byte) (*PrivateKey, error)

LoadEncryptedKeyFile reads and decrypts a key file from disk.

It refuses a file that is readable by group or other. A key encrypted at rest but left world-readable only raises the attacker's cost from "read it" to "read it and crack one passphrase".

func NewPrivateKey

func NewPrivateKey(seed []byte) (*PrivateKey, error)

NewPrivateKey builds a signer from a 32-byte Nimiq private key, which is the Ed25519 seed.

func ParsePrivateKeyHex

func ParsePrivateKeyHex(s string) (*PrivateKey, error)

ParsePrivateKeyHex builds a signer from a hex-encoded 32-byte private key, the form Nimiq wallet exports and the importRawKey RPC use.

The error deliberately does not quote the input, so a malformed key cannot end up in a log line.

func (*PrivateKey) Address

func (p *PrivateKey) Address() nimiq.Address

Address returns the Nimiq address this signer controls.

func (*PrivateKey) Mnemonic added in v0.3.0

func (p *PrivateKey) Mnemonic() (string, error)

Mnemonic returns a 24-word BIP39 encoding of this key's entropy.

Keys created with FromMnemonic export their original entropy. Keys created with NewPrivateKey or Generate encode the Ed25519 seed.

func (*PrivateKey) PublicKey

func (p *PrivateKey) PublicKey(ctx context.Context) (ed25519.PublicKey, error)

PublicKey implements nimiq.Signer.

func (*PrivateKey) Seed added in v0.3.0

func (p *PrivateKey) Seed() []byte

Seed returns a copy of the 32-byte Ed25519 seed (Nimiq private key).

func (*PrivateKey) Sign

func (p *PrivateKey) Sign(ctx context.Context, message []byte) ([]byte, error)

Sign implements nimiq.Signer. Ed25519 signing is deterministic and needs no entropy, so this never fails for a well-formed key.

func (*PrivateKey) String

func (p *PrivateKey) String() string

String deliberately does not reveal key material. Without it, embedding a PrivateKey in a struct that gets logged with %v would print the raw key.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL