chains

package
v0.0.1-gowrapper-test Latest Latest
Warning

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

Go to latest
Published: Sep 30, 2025 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetValid192BytePrivateKey

func GetValid192BytePrivateKey() []byte

GetValid192BytePrivateKey returns a valid 192-byte Cardano extended private key

func GetValidCardanoAddress

func GetValidCardanoAddress() string

GetValidCardanoAddress returns a valid Cardano address

func GetValidPreimageData

func GetValidPreimageData() []byte

GetValidPreimageData returns valid preimage data for transaction signing

func GetValidPrivateKey32Bytes

func GetValidPrivateKey32Bytes() []byte

GetValidPrivateKey32Bytes returns a valid 32-byte private key for ED25519 signing

func ValidateTestData

func ValidateTestData(data *CardanoTestData) error

ValidateTestData validates that test data is properly formatted

Types

type CardanoChain

type CardanoChain struct {
	*chain_abstraction.BaseChain
}

CardanoChain provides a complete implementation for Cardano blockchain It implements the chain_abstraction.Chain interface.

func NewCardanoChain

func NewCardanoChain() *CardanoChain

NewCardanoChain creates a new Cardano chain instance

func (*CardanoChain) BuildSigningInput

func (c *CardanoChain) BuildSigningInput(
	utxos []*cardano.TxInput,
	privateKeys [][]byte,
	toAddress string,
	amount uint64,
	changeAddress string,
	ttl uint64,
) (*cardano.SigningInput, error)

BuildSigningInput creates a Cardano transfer signing input

func (*CardanoChain) CompileTransaction

func (c *CardanoChain) CompileTransaction(
	input *chain_abstraction.TransactionInput,
	signatures [][]byte,
	publicKeys [][]byte,
) ([]byte, error)

CompileTransaction compiles a transaction with signatures

func (*CardanoChain) CreateAndSignTransaction

func (c *CardanoChain) CreateAndSignTransaction(input interface{}, privateKey []byte) ([]byte, error)

CreateAndSignTransaction creates and signs a transaction

func (*CardanoChain) CreateAndSignTransactionWithHash

func (c *CardanoChain) CreateAndSignTransactionWithHash(input interface{}, privateKey []byte) ([]byte, string, error)

CreateAndSignTransactionWithHash creates and signs a transaction and returns both the encoded transaction and transaction hash

func (*CardanoChain) CreateWalletWithPrivateKey

func (c *CardanoChain) CreateWalletWithPrivateKey(privateKey string) (*chain_abstraction.Wallet, error)

CreateWalletWithPrivateKey creates a wallet from private key

⚠️ LIMITATION: This function currently does not work for Cardano due to core library issues with ED25519 extended key address derivation.

TECHNICAL ISSUE: The core library's DeriveAddress function in wrapper/go-wrapper/core/privatekey.go is hardcoded to only handle SECP256k1 public keys (33 or 65 bytes), but Cardano uses ED25519 extended keys with different lengths (128+ bytes).

WORKAROUND: Use CreateWallet(mnemonic) instead, which works correctly.

ROOT CAUSE: The generic DeriveAddress function needs to be updated to: 1. Add ED25519 public key type constants (missing from core/publicKey.go) 2. Handle coin-type-specific public key type detection 3. Support Cardano's ED25519ExtendedCardano curve properly

TODO: Fix the core library's address derivation for non-SECP256k1 curves

func (*CardanoChain) GetPreimageHash

func (c *CardanoChain) GetPreimageHash(input *chain_abstraction.TransactionInput) ([]byte, []byte, error)

GetPreimageHash gets the preimage hash for external signing

func (*CardanoChain) GetTransactionHash

func (c *CardanoChain) GetTransactionHash(encodedTx []byte) (string, error)

func (*CardanoChain) PrepareTransaction

func (c *CardanoChain) PrepareTransaction(input interface{}) (*chain_abstraction.TransactionInput, error)

PrepareTransaction prepares a transaction for external signing

func (*CardanoChain) Sign

func (c *CardanoChain) Sign(preimage []byte, privateKey []byte) ([]byte, error)

Sign signs a preimage with the extended private key (192 bytes for Cardano)

func (*CardanoChain) ValidateTransactionInput

func (c *CardanoChain) ValidateTransactionInput(input interface{}) error

ValidateTransactionInput validates a Cardano transaction input

type CardanoKeyUtils

type CardanoKeyUtils struct{}

CardanoKeyUtils provides utility functions for Cardano key management

func NewCardanoKeyUtils

func NewCardanoKeyUtils() *CardanoKeyUtils

NewCardanoKeyUtils creates a new Cardano key utilities instance

func (*CardanoKeyUtils) GetSpendingKeys

func (c *CardanoKeyUtils) GetSpendingKeys(privKeyBytes []byte, pubKeyBytes []byte) (privateKey []byte, publicKey []byte, err error)

GetSpendingKeys is a convenience function that returns both spending keys

func (*CardanoKeyUtils) GetSpendingPrivateKey

func (c *CardanoKeyUtils) GetSpendingPrivateKey(privKeyBytes []byte) ([]byte, error)

GetSpendingPrivateKey extracts the 32-byte spending private key from Cardano's 192-byte private key This is the key needed for EdDSA signing of spending transactions

func (*CardanoKeyUtils) GetSpendingPublicKey

func (c *CardanoKeyUtils) GetSpendingPublicKey(pubKeyBytes []byte) ([]byte, error)

GetSpendingPublicKey extracts the 32-byte spending public key from Cardano's 128-byte public key This is the key needed for EdDSA signature validation

func (*CardanoKeyUtils) GetStakingKeys

func (c *CardanoKeyUtils) GetStakingKeys(privKeyBytes []byte, pubKeyBytes []byte) (privateKey []byte, publicKey []byte, err error)

GetStakingKeys is a convenience function that returns both staking keys

func (*CardanoKeyUtils) GetStakingPrivateKey

func (c *CardanoKeyUtils) GetStakingPrivateKey(privKeyBytes []byte) ([]byte, error)

GetStakingPrivateKey extracts the 32-byte staking private key from Cardano's 192-byte private key This is used for staking operations

func (*CardanoKeyUtils) GetStakingPublicKey

func (c *CardanoKeyUtils) GetStakingPublicKey(pubKeyBytes []byte) ([]byte, error)

GetStakingPublicKey extracts the 32-byte staking public key from Cardano's 128-byte public key This is used for staking operations

type CardanoTestData

type CardanoTestData struct {
	Name           string
	Mnemonic       string
	PrivateKey192  string // 192-byte (384 hex chars) extended private key
	PrivateKey32   string // 32-byte spending private key (extracted)
	PublicKey32    string // 32-byte spending public key (extracted)
	Address        string
	ValidPreimage  []byte
	ValidSignature []byte
	TestMessage    []byte
}

CardanoTestData contains valid test vectors for Cardano testing

func GenerateValidTestData

func GenerateValidTestData(t *testing.T) *CardanoTestData

GenerateValidTestData creates valid test data dynamically

func GetValidCardanoTestData

func GetValidCardanoTestData() []CardanoTestData

GetValidCardanoTestData returns real, working test vectors

Jump to

Keyboard shortcuts

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