Documentation ¶
Overview ¶
Package wallet contains the definition of the wallet backend interfaces, and manages a global wallet backend instance that is accessible from the rest of the project.
Index ¶
- func DecodeSparseSigs(r io.Reader, sigs *[]Sig) (err error)
- func EncodeSparseSigs(w io.Writer, sigs []Sig) error
- func IndexOfAddr(addrs []Address, addr Address) int
- func SetBackend(b Backend)
- func SetBackendTest(t *testing.T)
- func VerifySignature(msg []byte, sign Sig, a Address) (bool, error)
- type Account
- type Address
- type Backend
- type Sig
- type Wallet
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DecodeSparseSigs ¶ added in v0.2.1
DecodeSparseSigs decodes a collection of signatures in the form (mask, sig, sig, sig, ...)
func EncodeSparseSigs ¶ added in v0.2.1
EncodeSparseSigs encodes a collection of signatures in the form ( mask, sig, sig, sig, ...)
func IndexOfAddr ¶
IndexOfAddr returns the index of the given address in the address slice, or -1 if it is not part of the slice.
func SetBackend ¶
func SetBackend(b Backend)
SetBackend sets the global wallet backend. Must not be called directly but through importing the needed backend.
func SetBackendTest ¶
SetBackendTest is a generic test to test that the wallet backend is set correctly.
Types ¶
type Account ¶
type Account interface { // Address used by this account. Address() Address // SignData requests a signature from this account. // It returns the signature or an error. SignData(data []byte) ([]byte, error) }
Account represents a single account.
type Address ¶
type Address interface { io.Serializer // Bytes should return the representation of the address as byte slice. Bytes() []byte // String converts this address to a string fmt.Stringer // Equals checks the equality of two addresses Equals(Address) bool }
Address represents a identifier used in a cryptocurrency. It is dependent on the currency and needs to be implemented for every blockchain.
type Backend ¶
type Backend interface { // DecodeAddress reads and decodes an address from an io.Writer DecodeAddress(io.Reader) (Address, error) // DecodeSig reads a signature from the provided stream. It is needed for // decoding of wire messages. DecodeSig(io.Reader) (Sig, error) // VerifySignature verifies if this signature was signed by this address. // It should return an error iff the signature or message are malformed. // If the signature does not match the address it should return false, nil VerifySignature(msg []byte, sign Sig, a Address) (bool, error) }
Backend provides useful methods for this blockchain.
type Sig ¶
type Sig = []byte
Sig is a single signature
type Wallet ¶
type Wallet interface { // Unlock requests an unlocked Account for an Address from the Wallet. // The returned account must be able to sign messages at least until // LockAll has been called, or a matching count of IncrementUsage and // DecrementUsage calls on the account's address has been made. Unlock may // be called multiple times for the same Address by the Perun SDK. Unlock(Address) (Account, error) // LockAll is called by the framework when a Client shuts down. This should // release all temporary resources held by the wallet, and accesses to // accounts after this call are no longer expected to succeed by the Perun // SDK. Implementing this function with any behavior is not essential. LockAll() // IncrementUsage is called whenever a new channel is created or restored. // The address passed to the function belongs to the Account the Client is // using to participate in the channel. Implementing this function with any // behavior is not essential. IncrementUsage(Address) // DecrementUsage is called whenever a channel is settled. The address // passed to the function belongs to the Account the Client is using to // participate in the channel. It is guaranteed by the Perun SDK that when // an account had the same number of DecrementUsage calls as prior // IncrementUsage calls made to it, it can be safely deleted permanently by // the wallet implementation. In that event, the affected account does not // have to be able to sign messages anymore. Implementing this function with // any behavior is not essential. DecrementUsage(Address) }
Wallet is a collection of Accounts, i.e., secret keys. The interface defines a method Unlock, which the framework calls to get an Account for an Address. The other methods may, but don't need to, be implemented to gain more efficient resource handling by the Wallet implementation.