Documentation
¶
Overview ¶
Package wallet provides a wallet for the Renegade system
Index ¶
- Constants
- func DeriveWalletID(privateKey *ecdsa.PrivateKey, chainID uint64) (uuid.UUID, error)
- func FromScalarsRecursive(s interface{}, scalars *ScalarIterator) error
- type Balance
- type BalanceBuilder
- func (bb *BalanceBuilder) Build() Balance
- func (bb *BalanceBuilder) WithAmount(amount Scalar) *BalanceBuilder
- func (bb *BalanceBuilder) WithAmountBigInt(amount *big.Int) *BalanceBuilder
- func (bb *BalanceBuilder) WithMint(mint Scalar) *BalanceBuilder
- func (bb *BalanceBuilder) WithMintHex(hexMint string) *BalanceBuilder
- func (bb *BalanceBuilder) WithProtocolFeeBalance(fee Scalar) *BalanceBuilder
- func (bb *BalanceBuilder) WithRelayerFeeBalance(fee Scalar) *BalanceBuilder
- type FeeEncryptionKey
- type FixedPoint
- type HmacKey
- type Keychain
- type Order
- type OrderBuilder
- func (ob *OrderBuilder) Build() Order
- func (ob *OrderBuilder) WithAmount(amount Scalar) *OrderBuilder
- func (ob *OrderBuilder) WithAmountBigInt(amount *big.Int) *OrderBuilder
- func (ob *OrderBuilder) WithBaseMint(baseMint Scalar) *OrderBuilder
- func (ob *OrderBuilder) WithBaseMintHex(hexBaseMint string) *OrderBuilder
- func (ob *OrderBuilder) WithId(id uuid.UUID) *OrderBuilder
- func (ob *OrderBuilder) WithQuoteMint(quoteMint Scalar) *OrderBuilder
- func (ob *OrderBuilder) WithQuoteMintHex(hexQuoteMint string) *OrderBuilder
- func (ob *OrderBuilder) WithSide(side OrderSide) *OrderBuilder
- func (ob *OrderBuilder) WithWorstCasePrice(price FixedPoint) *OrderBuilder
- type OrderSide
- type PrivateKeychain
- type PrivateSigningKey
- func (pk *PrivateSigningKey) FromHexString(hexString string) (PrivateSigningKey, error)
- func (pk *PrivateSigningKey) FromScalars(scalars *ScalarIterator) error
- func (pk *PrivateSigningKey) NumScalars() int
- func (pk *PrivateSigningKey) ToHexString() string
- func (pk *PrivateSigningKey) ToScalars() ([]Scalar, error)
- type PublicKeychain
- type PublicSigningKey
- func (pk *PublicSigningKey) FromHexString(hexString string) (PublicSigningKey, error)
- func (pk *PublicSigningKey) FromScalars(scalars *ScalarIterator) error
- func (pk *PublicSigningKey) NumScalars() int
- func (pk *PublicSigningKey) ToHexString() string
- func (pk *PublicSigningKey) ToScalars() ([]Scalar, error)
- type Scalar
- func (s *Scalar) Add(other Scalar) Scalar
- func (s *Scalar) Bytes() [fr.Bytes]byte
- func (s *Scalar) FromBigInt(i *big.Int) Scalar
- func (s *Scalar) FromBytes(bytes [fr.Bytes]byte)
- func (s *Scalar) FromHexString(hexString string) (Scalar, error)
- func (s *Scalar) FromLittleEndianBytes(bytes [fr.Bytes]byte) (*Scalar, error)
- func (s *Scalar) FromScalars(scalars *ScalarIterator) error
- func (s *Scalar) IsOne() bool
- func (s *Scalar) IsZero() bool
- func (s *Scalar) LittleEndianBytes() [fr.Bytes]byte
- func (s *Scalar) NumScalars() int
- func (s *Scalar) SetUint64(val uint64) *Scalar
- func (s *Scalar) Sub(other Scalar) Scalar
- func (s *Scalar) ToBigInt() *big.Int
- func (s *Scalar) ToHexString() string
- func (s *Scalar) ToScalars() ([]Scalar, error)
- func (s *Scalar) Uint64() uint64
- type ScalarIterator
- type ScalarSerialize
- type Uint64
- type Wallet
- func (w *Wallet) AddBalance(balance Balance) error
- func (w *Wallet) CancelOrder(orderID uuid.UUID) error
- func (w *Wallet) GetBalance(mint string) (*big.Int, error)
- func (w *Wallet) GetNonzeroBalances() []Balance
- func (w *Wallet) GetNonzeroOrders() []Order
- func (w *Wallet) GetPrivateShareCommitment() (Scalar, error)
- func (w *Wallet) GetShareCommitment() (Scalar, error)
- func (w *Wallet) NewOrder(order Order) error
- func (w *Wallet) Reblind() error
- func (w *Wallet) RemoveBalance(balance Balance) error
- func (w *Wallet) SignCommitment(commitment Scalar) ([]byte, error)
- type WalletSecrets
- type WalletShare
Constants ¶
const ( // MaxBalances is the maximum number of balances in a wallet MaxBalances = 10 // MaxOrders is the maximum number of orders in a wallet MaxOrders = 4 )
const OrderSide_BUY = 0 //nolint:revive
OrderSide_BUY is a buy side order
const OrderSide_SELL = 1 //nolint:revive
OrderSide_SELL is a sell side order
Variables ¶
This section is empty.
Functions ¶
func DeriveWalletID ¶
DeriveWalletID derives the wallet ID from the private key
func FromScalarsRecursive ¶
func FromScalarsRecursive(s interface{}, scalars *ScalarIterator) error
FromScalarsRecursive is a helper function to deserialize a struct from a slice of scalars using reflection
Types ¶
type Balance ¶
type Balance struct { // Mint is the erc20 address of the balance's asset Mint Scalar // Amount is the amount of the balance Amount Scalar // RelayerFeeBalance is the balance due to the relayer in fees RelayerFeeBalance Scalar // ProtocolFeeBalance is the balance due to the protocol in fees ProtocolFeeBalance Scalar }
Balance is a balance in the Renegade system
func NewBalance ¶
NewBalance creates a new balance with the given mint and amount
func NewEmptyBalance ¶
func NewEmptyBalance() Balance
NewEmptyBalance creates a new balance with all zero values
type BalanceBuilder ¶
type BalanceBuilder struct {
// contains filtered or unexported fields
}
BalanceBuilder is a builder for Balance
func NewBalanceBuilder ¶
func NewBalanceBuilder() *BalanceBuilder
NewBalanceBuilder creates a new BalanceBuilder
func (*BalanceBuilder) Build ¶
func (bb *BalanceBuilder) Build() Balance
Build returns the constructed Balance
func (*BalanceBuilder) WithAmount ¶
func (bb *BalanceBuilder) WithAmount(amount Scalar) *BalanceBuilder
WithAmount sets the Amount
func (*BalanceBuilder) WithAmountBigInt ¶
func (bb *BalanceBuilder) WithAmountBigInt(amount *big.Int) *BalanceBuilder
WithAmountBigInt sets the Amount from a big.Int
func (*BalanceBuilder) WithMint ¶
func (bb *BalanceBuilder) WithMint(mint Scalar) *BalanceBuilder
WithMint sets the Mint
func (*BalanceBuilder) WithMintHex ¶
func (bb *BalanceBuilder) WithMintHex(hexMint string) *BalanceBuilder
WithMintHex sets the Mint from a hex string
func (*BalanceBuilder) WithProtocolFeeBalance ¶
func (bb *BalanceBuilder) WithProtocolFeeBalance(fee Scalar) *BalanceBuilder
WithProtocolFeeBalance sets the ProtocolFeeBalance
func (*BalanceBuilder) WithRelayerFeeBalance ¶
func (bb *BalanceBuilder) WithRelayerFeeBalance(fee Scalar) *BalanceBuilder
WithRelayerFeeBalance sets the RelayerFeeBalance
type FeeEncryptionKey ¶
FeeEncryptionKey is a public encryption key on the Baby Jubjub curve We represent the key in coordinate form with scalar values
func (*FeeEncryptionKey) FromBytes ¶
func (pk *FeeEncryptionKey) FromBytes(bytes []byte) error
FromBytes converts a byte slice to a fee encryption key
func (*FeeEncryptionKey) FromHexString ¶
func (pk *FeeEncryptionKey) FromHexString(hexString string) error
FromHexString converts a hex string to a fee encryption key
func (*FeeEncryptionKey) ToBytes ¶
func (pk *FeeEncryptionKey) ToBytes() []byte
ToBytes converts the fee encryption key to a byte slice
func (*FeeEncryptionKey) ToHexString ¶
func (pk *FeeEncryptionKey) ToHexString() string
ToHexString converts the fee encryption key to a hex string
type FixedPoint ¶
type FixedPoint struct { // Repr is the integral representation of the fixed point number Repr Scalar }
FixedPoint is a fixed point number with a scalar representation The scalar represents the value `floor(repr >> 2^PRECISION)` For our purposes, the precision is 63 bits
func FixedPointFromFloat ¶
func FixedPointFromFloat(f float64) FixedPoint
FixedPointFromFloat creates a new fixed point number from a float
func NewFixedPoint ¶
func NewFixedPoint(repr Scalar) FixedPoint
NewFixedPoint creates a new fixed point number from a scalar representation
func (*FixedPoint) FromReprDecimalString ¶
func (fp *FixedPoint) FromReprDecimalString(s string) (FixedPoint, error)
FromReprDecimalString creates a new fixed point number from a decimal string
func (FixedPoint) ToFloat ¶
func (fp FixedPoint) ToFloat() float64
ToFloat converts a fixed point number to a float
func (FixedPoint) ToReprDecimalString ¶
func (fp FixedPoint) ToReprDecimalString() string
ToReprDecimalString converts a fixed point number to the base10 string representation of its `repr`
type HmacKey ¶
type HmacKey [32]byte
HmacKey is a symmetric key for HMAC-SHA256
func (*HmacKey) FromBase64String ¶
FromBase64String converts a base64 string to an HMAC key
func (*HmacKey) FromHexString ¶
FromHexString converts a hex string to an HMAC key
func (*HmacKey) ToBase64String ¶
ToBase64String converts the HMAC key to a base64 string
func (*HmacKey) ToHexString ¶
ToHexString converts the HMAC key to a hex string
type Keychain ¶
type Keychain struct { PublicKeys PublicKeychain PrivateKeys PrivateKeychain }
Keychain is a keychain for the API wallet
func DeriveKeychain ¶
func DeriveKeychain(pkey *ecdsa.PrivateKey, chainID uint64) (*Keychain, error)
DeriveKeychain derives the keychain from the private key
func (*Keychain) SkRoot ¶
func (k *Keychain) SkRoot() *PrivateSigningKey
SkRoot returns the private root key
type Order ¶
type Order struct { // ID is the id of the order Id uuid.UUID `scalar_serialize:"skip"` //nolint:revive // QuoteMint is the erc20 address of the quote asset QuoteMint Scalar // BaseMint is the erc20 address of the base asset BaseMint Scalar // Side is the side of the order // 0 for buy, 1 for sell Side Scalar // Amount is the amount of the order Amount Scalar // WorstCasePrice is the worst case price of the order WorstCasePrice FixedPoint }
Order is an order in the Renegade system
type OrderBuilder ¶
type OrderBuilder struct {
// contains filtered or unexported fields
}
OrderBuilder is a builder for Order
func NewOrderBuilder ¶
func NewOrderBuilder() *OrderBuilder
NewOrderBuilder creates a new OrderBuilder
func (*OrderBuilder) Build ¶
func (ob *OrderBuilder) Build() Order
Build returns the constructed Order
func (*OrderBuilder) WithAmount ¶
func (ob *OrderBuilder) WithAmount(amount Scalar) *OrderBuilder
WithAmount sets the Amount
func (*OrderBuilder) WithAmountBigInt ¶
func (ob *OrderBuilder) WithAmountBigInt(amount *big.Int) *OrderBuilder
WithAmountBigInt sets the Amount from a big.Int
func (*OrderBuilder) WithBaseMint ¶
func (ob *OrderBuilder) WithBaseMint(baseMint Scalar) *OrderBuilder
WithBaseMint sets the BaseMint
func (*OrderBuilder) WithBaseMintHex ¶
func (ob *OrderBuilder) WithBaseMintHex(hexBaseMint string) *OrderBuilder
WithBaseMintHex sets the BaseMint from a hex string
func (*OrderBuilder) WithId ¶
func (ob *OrderBuilder) WithId(id uuid.UUID) *OrderBuilder
WithId sets the Id
func (*OrderBuilder) WithQuoteMint ¶
func (ob *OrderBuilder) WithQuoteMint(quoteMint Scalar) *OrderBuilder
WithQuoteMint sets the QuoteMint
func (*OrderBuilder) WithQuoteMintHex ¶
func (ob *OrderBuilder) WithQuoteMintHex(hexQuoteMint string) *OrderBuilder
WithQuoteMintHex sets the QuoteMint from a hex string
func (*OrderBuilder) WithSide ¶
func (ob *OrderBuilder) WithSide(side OrderSide) *OrderBuilder
WithSide sets the Side
func (*OrderBuilder) WithWorstCasePrice ¶
func (ob *OrderBuilder) WithWorstCasePrice(price FixedPoint) *OrderBuilder
WithWorstCasePrice sets the WorstCasePrice
type OrderSide ¶
type OrderSide int
OrderSide is an enum for the side of an order
func (*OrderSide) FromScalars ¶
func (s *OrderSide) FromScalars(scalars *ScalarIterator) error
FromScalars converts a slice of scalars to an OrderSide
func (*OrderSide) NumScalars ¶
NumScalars returns the number of scalars in the OrderSide
type PrivateKeychain ¶
type PrivateKeychain struct { SkRoot *PrivateSigningKey SkMatch Scalar SymmetricKey HmacKey }
PrivateKeychain is a private keychain for the API wallet
type PrivateSigningKey ¶
type PrivateSigningKey ecdsa.PrivateKey
PrivateSigningKey is a private key over the secp256k1 curve
func (*PrivateSigningKey) FromHexString ¶
func (pk *PrivateSigningKey) FromHexString(hexString string) (PrivateSigningKey, error)
FromHexString converts a hex string to a private key
func (*PrivateSigningKey) FromScalars ¶
func (pk *PrivateSigningKey) FromScalars(scalars *ScalarIterator) error
FromScalars converts a slice of scalars to a private key
func (*PrivateSigningKey) NumScalars ¶
func (pk *PrivateSigningKey) NumScalars() int
NumScalars returns the number of scalars in the private key
func (*PrivateSigningKey) ToHexString ¶
func (pk *PrivateSigningKey) ToHexString() string
ToHexString converts the private key to a hex string
func (*PrivateSigningKey) ToScalars ¶
func (pk *PrivateSigningKey) ToScalars() ([]Scalar, error)
ToScalars converts the private key to a slice of scalars
type PublicKeychain ¶
type PublicKeychain struct { PkRoot PublicSigningKey PkMatch Scalar Nonce Scalar }
PublicKeychain is a public keychain for the API wallet
type PublicSigningKey ¶
PublicSigningKey is a verification key over the secp256k1 curve
func (*PublicSigningKey) FromHexString ¶
func (pk *PublicSigningKey) FromHexString(hexString string) (PublicSigningKey, error)
FromHexString converts a hex string to a public key
func (*PublicSigningKey) FromScalars ¶
func (pk *PublicSigningKey) FromScalars(scalars *ScalarIterator) error
FromScalars converts a slice of scalars to a public key
func (*PublicSigningKey) NumScalars ¶
func (pk *PublicSigningKey) NumScalars() int
NumScalars returns the number of scalars in the public key
func (*PublicSigningKey) ToHexString ¶
func (pk *PublicSigningKey) ToHexString() string
ToHexString converts the public key to a hex string
func (*PublicSigningKey) ToScalars ¶
func (pk *PublicSigningKey) ToScalars() ([]Scalar, error)
ToScalars converts the public key to a slice of scalars
type Scalar ¶
Scalar is a scalar field element from the bn254 curve
func DeriveWalletSeeds ¶
func DeriveWalletSeeds(privateKey *ecdsa.PrivateKey, chainID uint64) ( blinderSeed, shareSeed Scalar, err error, )
DeriveWalletSeeds derives the blinder and secret share seeds from the derivation key
func HashScalars ¶
HashScalars hashes a slice of scalars using Poseidon2
func ToScalarsRecursive ¶
ToScalarsRecursive is a helper function to serialize a value to a slice of scalars using reflection
func (*Scalar) FromBigInt ¶
FromBigInt sets the scalar from a big.Int
func (*Scalar) FromHexString ¶
FromHexString sets the scalar from a hex string
func (*Scalar) FromLittleEndianBytes ¶
FromLittleEndianBytes sets the scalar from a little-endian byte slice
func (*Scalar) FromScalars ¶
func (s *Scalar) FromScalars(scalars *ScalarIterator) error
FromScalars converts a `ScalarIterator` to
func (*Scalar) LittleEndianBytes ¶
LittleEndianBytes returns the bytes representation of the scalar in little-endian order
func (*Scalar) NumScalars ¶
NumScalars returns the number of `Scalar`s in the `Scalar`
func (*Scalar) ToHexString ¶
ToHexString returns the hex string representation of the scalar
type ScalarIterator ¶
type ScalarIterator struct {
// contains filtered or unexported fields
}
ScalarIterator is a helper type that iterates over a slice of scalars
func NewScalarIterator ¶
func NewScalarIterator(scalars []Scalar) *ScalarIterator
NewScalarIterator creates a new ScalarIterator
func (*ScalarIterator) Next ¶
func (s *ScalarIterator) Next() (Scalar, error)
Next returns the next scalar in the iterator
func (*ScalarIterator) NumRemaining ¶
func (s *ScalarIterator) NumRemaining() int
NumRemaining returns the remaining scalars in the iterator
type ScalarSerialize ¶
type ScalarSerialize interface { // FromScalars deserializes a value from a slice of Scalars FromScalars(scalars *ScalarIterator) error // ToScalars serializes a value to a slice of Scalars ToScalars() ([]Scalar, error) // NumScalars returns the number of Scalars that will be serialized NumScalars() int }
ScalarSerialize is an interface that can be implemented by any type that can be serialized to a slice of Scalars
type Uint64 ¶
type Uint64 uint64
Uint64 is a type that can be serialized to a slice of `Scalar`s
func (*Uint64) FromScalars ¶
func (s *Uint64) FromScalars(scalars *ScalarIterator) error
FromScalars converts a `ScalarIterator` to a `Uint64`
func (*Uint64) NumScalars ¶
NumScalars returns the number of `Scalar`s in the `Uint64`
type Wallet ¶
type Wallet struct { Id uuid.UUID //nolint:revive Orders []Order Balances []Balance Keychain *Keychain ManagingCluster FeeEncryptionKey MatchFee FixedPoint Blinder Scalar }
Wallet is a wallet in the Renegade system
func NewEmptyWallet ¶
func NewEmptyWallet(privateKey *ecdsa.PrivateKey, chainID uint64) (*Wallet, error)
NewEmptyWallet creates a new empty wallet
func NewEmptyWalletFromSecrets ¶
func NewEmptyWalletFromSecrets(secrets *WalletSecrets) (*Wallet, error)
NewEmptyWalletFromSecrets creates a new wallet from the given wallet secrets
func (*Wallet) AddBalance ¶
AddBalance appends a balance to the wallet
func (*Wallet) CancelOrder ¶
CancelOrder cancels an order by ID
func (*Wallet) GetBalance ¶
GetBalance gets the balance for a given mint
func (*Wallet) GetNonzeroBalances ¶
GetNonzeroBalances gets all non-zero balances in a wallet
func (*Wallet) GetNonzeroOrders ¶
GetNonzeroOrders gets all non-empty orders
func (*Wallet) GetPrivateShareCommitment ¶
GetPrivateShareCommitment returns a Poseidon hash commitment of the wallet's private share
func (*Wallet) GetShareCommitment ¶
GetShareCommitment returns a Poseidon hash commitment of the wallet's shares
func (*Wallet) Reblind ¶
Reblind reblinds the wallet, sampling new secret shares and blinders from the CSPRNGs
func (*Wallet) RemoveBalance ¶
RemoveBalance removes a balance from the wallet
type WalletSecrets ¶
type WalletSecrets struct { // Id is the UUID of the wallet Id uuid.UUID //nolint:revive // Address is the Ethereum address of the wallet Address string // Keychain is the keychain used to manage the wallet Keychain *Keychain // BlinderSeed is the seed of the CSPRNG used to generate blinders and blinder shares BlinderSeed Scalar ShareSeed Scalar }
WalletSecrets contains the information about a wallet necessary to recover it
func DeriveWalletSecrets ¶
func DeriveWalletSecrets(ethKey *ecdsa.PrivateKey, chainId uint64) (*WalletSecrets, error)
DeriveWalletSecrets derives the wallet secrets from the given Ethereum private key
type WalletShare ¶
type WalletShare struct { MaxBalances]Balance Orders [MaxOrders]Order Keys PublicKeychain MatchFee FixedPoint // receives fees for matching orders in the wallet ManagingCluster FeeEncryptionKey // algebraic system on the shares impossible, even when one knows the underlying value Blinder Scalar }Balances [
WalletShare represents a secret share of a wallet, containing only the elements of a wallet that are stored on-chain
func CombineShares ¶
func CombineShares( publicShare WalletShare, privateShare WalletShare, blinder Scalar, ) (WalletShare, error)
CombineShares combines two wallet shares into a single wallet share
func EmptyWalletShare ¶
func EmptyWalletShare(publicKeys PublicKeychain) (WalletShare, error)
EmptyWalletShare creates a new wallet share with all zero values
func (*WalletShare) SplitPublicPrivate ¶
func (ws *WalletShare) SplitPublicPrivate( privateShares []Scalar, blinder Scalar, ) (WalletShare, WalletShare, error)
SplitPublicPrivate splits a wallet share into two shares using the given private shares and blinder