Documentation
¶
Index ¶
- Variables
- func NativeCoinAssetId() zanobase.Value256
- type Address
- type AddressType
- type FinalizeTxParam
- type FinalizedTx
- type GenContext
- type ReceivedOutput
- type RingMember
- type ScanResult
- type TransferDest
- type TransferInput
- type TxDest
- func (dst *TxDest) AmountCommitment(scalar *edwards25519.Scalar, ogc *zanobase.GenContext, i int) *edwards25519.Point
- func (dst *TxDest) BlindedAssetId(scalar *edwards25519.Scalar, ogc *zanobase.GenContext, i int) *edwards25519.Point
- func (dst *TxDest) ConcealingPoint(scalar *edwards25519.Scalar, ogc *zanobase.GenContext, i int) *edwards25519.Point
- func (dst *TxDest) StealthAddress(scalar *edwards25519.Scalar, ogc *zanobase.GenContext, i int) *edwards25519.Point
- type TxDestHtlcOut
- type TxSource
- type TxSourceOutputEntry
- type ViewWalletData
- type Wallet
- func (w *Wallet) Address() *Address
- func (w *Wallet) BuildTransfer(rnd io.Reader, inputs []*TransferInput, dests []*TransferDest, ...) (*FinalizedTx, error)
- func (w *Wallet) Encrypt(data any) ([]byte, error)
- func (w *Wallet) ExportView(startHeight uint64) *ViewWalletData
- func (w *Wallet) IsViewOnly() bool
- func (w *Wallet) ParseFTP(buf []byte) (*FinalizeTxParam, error)
- func (w *Wallet) ParseFinalized(buf []byte) (*FinalizedTx, error)
- func (w *Wallet) ScanTx(tx *zanobase.Transaction) (*ScanResult, error)
- func (w *Wallet) Sign(rnd io.Reader, ftp *FinalizeTxParam, oneTimeKey *edwards25519.Scalar) (*FinalizedTx, error)
Constants ¶
This section is empty.
Variables ¶
var (
CRYPTO_HDS_OUT_AMOUNT_BLINDING_MASK = []byte("ZANO_HDS_OUT_AMOUNT_BLIND_MASK_\x00")
)
Functions ¶
func NativeCoinAssetId ¶
NativeCoinAssetId returns the native coin asset id (Value256), useful when constructing native-coin TransferInputs/TransferDests.
Types ¶
type Address ¶
type Address struct {
Type AddressType
Flags uint8
SpendKey []byte
ViewKey []byte
PaymentId []byte
}
func ParseAddress ¶
ParseAddress will parse a zano address and return and Address object containing the address
func (*Address) SetPaymentId ¶
SetPaymentId sets the payment ID for the given address, and updates the address type accordingly.
type AddressType ¶
type AddressType uint64
AddressType represents the type of a Zano address, encoded as a varint prefix in the base58-encoded address string.
const ( PublicAddress AddressType = 0xc5 // Zx — standard public address PublicIntegAddress AddressType = 0x3678 // iZ — integrated address with payment ID PublicIntegAddressV2 AddressType = 0x36f8 // iZ — integrated address V2 (with flags) PublicAuditAddress AddressType = 0x98c8 // aZx — auditable public address PublicAuditIntegAddress AddressType = 0x8a49 // aiZX — auditable integrated address )
func (AddressType) Auditable ¶
func (a AddressType) Auditable() bool
Auditable returns true if this address type is an auditable address.
func (AddressType) HasFlags ¶
func (a AddressType) HasFlags() bool
HasFlags returns true if this address type includes a flags byte in its encoding.
func (AddressType) String ¶
func (a AddressType) String() string
String returns a human-readable representation of the address type.
type FinalizeTxParam ¶
type FinalizeTxParam struct {
UnlockTime uint64
Extra []*zanobase.Variant // currency::extra_v
Attachments []*zanobase.Variant // currency::attachment_v
CryptAddress *zanobase.AccountPublicAddr // currency::account_public_address
TxOutsAttr uint8
Shuffle bool
Flags uint8
MultisigId zanobase.Value256 // crypto::hash
Sources []*TxSource // currency::tx_source_entry
SelectedTransfers []zanobase.Varint // not sure why, but this is encoded as "01 00" in the bytestream
PreparedDestinations []*TxDest // currency::tx_destination_entry
ExpirationTime uint64
SpendPubKey *zanobase.Point // only for validations
TxVersion uint64
TxHardforkId uint64
ModeSeparateFee uint64
}
FinalizeTxParam contains the parameters needed to finalize and sign a Zano transaction. It is typically received encrypted from the network and parsed via ParseFTP or Wallet.ParseFTP.
func ParseFTP ¶
func ParseFTP(buf, viewSecretKey []byte) (*FinalizeTxParam, error)
ParseFTP decrypts buf using the provided view secret key and deserializes it into a FinalizeTxParam. Returns an error if decryption or deserialization fails, or if there is trailing data.
type FinalizedTx ¶
type FinalizedTx struct {
Tx *zanobase.Transaction `json:"tx"`
TxId zanobase.Value256 `json:"txid"` // might be zeroes?
OneTimeKey *zanobase.Scalar `json:"one_time_key"` // crypto::secret_key
FTP *FinalizeTxParam `json:"ftp"`
HtlcOrigin string `json:"htlc_origin"`
OutsKeyImages []*zanobase.KeyImageIndex `json:"outs_key_images,omitempty"` // pairs (out_index, key_image) for each change output
Derivation zanobase.Value256 `json:"derivation"` // crypto::key_derivation, a ec_point
WasNotPrepared bool `json:"was_not_prepared"` // true if tx was not prepared/created for some good reason (e.g. not enough outs for UTXO defragmentation tx). Because we decided not to throw exceptions for non-error cases. -- sowle
}
FinalizedTx represents a fully constructed and signed Zano transaction along with its metadata and the original finalization parameters.
func ParseFinalized ¶
func ParseFinalized(buf, viewSecretKey []byte) (*FinalizedTx, error)
ParseFinalized decrypts buf using the provided view secret key and deserializes it into a FinalizedTx. Returns an error if decryption or deserialization fails, or if there is trailing data.
type GenContext ¶
type GenContext struct {
}
type ReceivedOutput ¶
type ReceivedOutput struct {
OutputIndex int `json:"output_index"`
Amount uint64 `json:"amount"`
AssetId zanobase.Value256 `json:"asset_id"`
IsNative bool `json:"is_native"`
StealthAddress zanobase.Value256 `json:"stealth_address"`
AmountBlindingMask *zanobase.Scalar `json:"amount_blinding_mask"`
AssetIdBlindingMask *zanobase.Scalar `json:"asset_id_blinding_mask"`
}
ReceivedOutput is a transaction output detected as belonging to the wallet. AmountBlindingMask and AssetIdBlindingMask are retained so the output can later be turned into a spendable tx_source_entry.
type RingMember ¶
type RingMember struct {
GlobalIndex uint64
StealthAddress zanobase.Value256
ConcealingPoint zanobase.Value256
AmountCommitment zanobase.Value256
BlindedAssetId zanobase.Value256
}
RingMember is one output in an input's decoy ring (the real output plus decoys), identified by its chain-wide global index. The point fields are the on-chain (1/8-premultiplied) values, exactly as returned by the daemon.
type ScanResult ¶
type ScanResult struct {
TxPubKey zanobase.Value256 `json:"tx_pub_key"`
Outputs []*ReceivedOutput `json:"outputs"`
PaymentId []byte `json:"payment_id,omitempty"`
}
ScanResult holds the outputs of a transaction that belong to the wallet, along with the recovered integrated-address payment ID (if any).
func (*ScanResult) Found ¶
func (r *ScanResult) Found() bool
Found reports whether any output of the scanned transaction belongs to the wallet.
type TransferDest ¶
TransferDest is an output to create: send Amount of AssetId to Address.
type TransferInput ¶
type TransferInput struct {
Amount uint64
AssetId zanobase.Value256 // unblinded asset id (native = native coin asset id)
AmountBlindingMask *zanobase.Scalar
AssetIdBlindingMask *zanobase.Scalar
RealOutTxKey zanobase.Value256 // tx public key of the depositing tx
RealOutIndex uint64 // output index within the depositing tx
RealGlobalIndex uint64 // chain-wide global index of the real output
Ring []RingMember // decoys + the real output
}
TransferInput describes one output to spend: the data recovered by ScanTx (amount, asset id, blinding masks, the depositing tx public key and output index) plus a ring of decoys (which must include the real output, located by RealGlobalIndex).
type TxDest ¶
type TxDest struct {
Amount uint64
Addr []*zanobase.AccountPublicAddr // account_public_address; destination address, in case of 1 address - txout_to_key, in case of more - txout_multisig
MinimumSigs uint64 // if txout_multisig: minimum signatures that are required to spend this output (minimum_sigs <= addr.size()) IF txout_to_key - not used
AmountToProvide uint64 // amount money that provided by initial creator of tx, used with partially created transactions
UnlockTime uint64 //
HtlcOptions *TxDestHtlcOut // destination_option_htlc_out
AssetId *zanobase.Point // not blinded, not premultiplied
Flags uint64 // set of flags (see tx_destination_entry_flags)
}
TxDest represents a transaction output destination including the recipient address, amount, asset ID, and optional HTLC parameters.
func (*TxDest) AmountCommitment ¶
func (dst *TxDest) AmountCommitment(scalar *edwards25519.Scalar, ogc *zanobase.GenContext, i int) *edwards25519.Point
AmountCommitment computes the Pedersen commitment to the output amount: amount * blindedAssetId + blindingMask * G, pre-multiplied by 1/8.
func (*TxDest) BlindedAssetId ¶
func (dst *TxDest) BlindedAssetId(scalar *edwards25519.Scalar, ogc *zanobase.GenContext, i int) *edwards25519.Point
BlindedAssetId computes the blinded asset ID T = assetId + blindingMask * X, pre-multiplied by 1/8. It also stores the blinding mask in ogc.
func (*TxDest) ConcealingPoint ¶
func (dst *TxDest) ConcealingPoint(scalar *edwards25519.Scalar, ogc *zanobase.GenContext, i int) *edwards25519.Point
ConcealingPoint computes the concealing point Q for this output, derived from the recipient's view public key and the derivation scalar.
func (*TxDest) StealthAddress ¶
func (dst *TxDest) StealthAddress(scalar *edwards25519.Scalar, ogc *zanobase.GenContext, i int) *edwards25519.Point
StealthAddress computes the one-time stealth address for this destination using the derivation scalar and the recipient's spend public key.
type TxDestHtlcOut ¶
TxDestHtlcOut contains HTLC (Hash Time-Locked Contract) options for a transaction destination.
type TxSource ¶
type TxSource struct {
Outputs []*TxSourceOutputEntry
RealOutput uint64
RealOutTxKey *zanobase.Point // crypto::public_key
RealOutAmountBlindingMask *zanobase.Scalar // crypto::scalar_t
RealOutAssetIdBlindingMask *zanobase.Scalar // crypto::scalar_t
RealOutInTxIndex uint64 // size_t, index in transaction outputs vector
Amount uint64
TransferIndex uint64
MultisigId zanobase.Value256 // crypto::hash if txin_multisig: multisig output id
MsSigsCount uint64 // size_t
MsKeysCount uint64 // size_t
SeparatelySignedTxComplete bool
HtlcOrigin string // for htlc, specify origin. len = 1, content = "\x00" ?
// contains filtered or unexported fields
}
TxSource represents a transaction input source with ring members, the real output index, blinding masks, and amount information.
type TxSourceOutputEntry ¶
type TxSourceOutputEntry struct {
OutReference *zanobase.Variant // TxOutRef // either global output index or ref_by_id
StealthAddress *zanobase.Point // crypto::public_key, a.k.a output's one-time public key
ConcealingPoint *zanobase.Point // only for ZC outputs
AmountCommitment *zanobase.Point // only for ZC outputs
BlindedAssetID *zanobase.Point // only for ZC outputs
}
TxSourceOutputEntry represents a single output reference within a transaction source, including its stealth address and commitment data.
type ViewWalletData ¶
type ViewWalletData struct {
Address string `json:"address,omitempty"` // standard Zano address (alternative to the explicit keys)
SpendPublicKey string `json:"spend_public_key,omitempty"` // hex, 32 bytes
ViewPublicKey string `json:"view_public_key,omitempty"` // hex, 32 bytes (optional)
ViewSecretKey string `json:"view_secret_key"` // hex, 32 bytes
Flags uint8 `json:"flags,omitempty"` // 1 = auditable
StartHeight uint64 `json:"start_height"` // block height to resume scanning from
}
ViewWalletData is a JSON-marshalable description of a view-only wallet plus the block height from which scanning should resume. It carries exactly what the scanner needs: the view secret key, the spend public key, and a start height. Keys are lowercase hex. Either Address or SpendPublicKey must be set; ViewPublicKey is optional and validated against ViewSecretKey when present.
func (*ViewWalletData) LoadViewWallet ¶
func (d *ViewWalletData) LoadViewWallet() (*Wallet, error)
LoadViewWallet builds a view-only Wallet from a ViewWalletData. The StartHeight field is metadata for the scanner and is not part of the wallet; read it from the same struct when calling the scanner.
type Wallet ¶
type Wallet struct {
SpendPrivKey *edwards25519.Scalar
SpendPubKey *edwards25519.Point
ViewPrivKey *edwards25519.Scalar
ViewPubKey *edwards25519.Point
Flags uint8 // flag 1 = auditable
}
Wallet holds the key material for a Zano wallet, including both spend and view key pairs. It is typically created via LoadSpendSecret.
func GenerateWallet ¶
GenerateWallet creates a brand new wallet with a random spend secret read from rnd (use crypto/rand.Reader). The view key is derived from the spend secret exactly as Zano does. Set flags to 1 for an auditable wallet.
This is handy for receiving test deposits: generate a wallet, fund its Address(), then scan for the incoming output with a view-only copy.
func LoadSpendSecret ¶
LoadSpendSecret initializesd a Wallet based on a spend secret as found in zano if you run spendkey. It will automatically derive the view key using the appropriate method for Zano.
Set flags to zero for normal keys, or 1 for auditable keys.
func LoadViewOnly ¶
LoadViewOnly builds a view-only wallet from a view secret key and a spend public key (the data exported by a Zano watch-only wallet). The resulting wallet can detect and decode incoming outputs (ScanTx) but cannot sign, since the spend secret is absent.
func (*Wallet) BuildTransfer ¶
func (w *Wallet) BuildTransfer(rnd io.Reader, inputs []*TransferInput, dests []*TransferDest, version, hardforkID uint64) (*FinalizedTx, error)
BuildTransfer assembles a FinalizeTxParam from spendable inputs and destinations and signs it, producing a ready-to-broadcast transaction. The fee is implicit: it is the native-asset surplus (sum of native inputs minus native outputs), so the caller controls it by choosing destination amounts. Every non-native asset must balance (inputs == outputs).
func (*Wallet) Encrypt ¶
Encrypt will serialize and encrypt whatever data is passed (can be a FTP or a finalized transaction) so it can be read again.
func (*Wallet) ExportView ¶
func (w *Wallet) ExportView(startHeight uint64) *ViewWalletData
ExportView produces the JSON-marshalable view-only description of this wallet, suitable for handing to a scanner. startHeight is the block height from which scanning should begin (e.g. the wallet's creation height or last-scanned height).
func (*Wallet) IsViewOnly ¶
IsViewOnly reports whether the wallet lacks a spend secret key (and so can scan for deposits but cannot sign transactions).
func (*Wallet) ParseFTP ¶
func (w *Wallet) ParseFTP(buf []byte) (*FinalizeTxParam, error)
ParseFTP decrypts and deserializes a finalize transaction parameter blob using this wallet's view private key.
func (*Wallet) ParseFinalized ¶
func (w *Wallet) ParseFinalized(buf []byte) (*FinalizedTx, error)
ParseFinalized decrypts and deserializes a finalized transaction blob using this wallet's view private key.
func (*Wallet) ScanTx ¶
func (w *Wallet) ScanTx(tx *zanobase.Transaction) (*ScanResult, error)
ScanTx inspects a transaction and returns the outputs that belong to this wallet (decoding amount and asset id for each), plus the decrypted payment ID if the transaction carries one. It is the receive-side inverse of Sign and mirrors currency::lookup_acc_outs / is_out_to_acc / decode_output_amount_and_asset_id.
Only the wallet's view secret key is required, so this works for view-only wallets. A transaction with no tx public key, or none of whose outputs belong to the wallet, yields a ScanResult with an empty Outputs slice (not an error).
func (*Wallet) Sign ¶
func (w *Wallet) Sign(rnd io.Reader, ftp *FinalizeTxParam, oneTimeKey *edwards25519.Scalar) (*FinalizedTx, error)
Sign constructs and signs a Zano transaction from the given finalization parameters. If oneTimeKey is nil, a random key is generated. The method builds the transaction structure, generates CLSAG-GGX ring signatures for each input, and produces balance, range, and asset surjection proofs.
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
Package epee implements a minimal encoder/decoder for epee's "portable storage" binary format — the serialization used by Zano's daemon .bin RPC endpoints (and by wallet key blobs).
|
Package epee implements a minimal encoder/decoder for epee's "portable storage" binary format — the serialization used by Zano's daemon .bin RPC endpoints (and by wallet key blobs). |
|
Package zanorpc is a minimal JSON-RPC client for a Zano daemon and a deposit scanner built on top of it.
|
Package zanorpc is a minimal JSON-RPC client for a Zano daemon and a deposit scanner built on top of it. |