Documentation ¶
Index ¶
- Variables
- type Account
- func NewAccount() (*Account, error)
- func NewAccountFromEncryptedWIF(wif string, pass string, scrypt keys.ScryptParams) (*Account, error)
- func NewAccountFromPrivateKey(p *keys.PrivateKey) *Account
- func NewAccountFromWIF(wif string) (*Account, error)
- func NewContractAccount(hash util.Uint160, args ...any) *Account
- func (a *Account) CanSign() bool
- func (a *Account) Close()
- func (a *Account) ConvertMultisig(m int, pubs []*keys.PublicKey) error
- func (a *Account) ConvertMultisigEncrypted(accKey *keys.PublicKey, m int, pubs []*keys.PublicKey) error
- func (a *Account) Decrypt(passphrase string, scrypt keys.ScryptParams) error
- func (a *Account) Encrypt(passphrase string, scrypt keys.ScryptParams) error
- func (a *Account) GetVerificationScript() []byte
- func (a *Account) PrivateKey() *keys.PrivateKey
- func (a *Account) PublicKey() *keys.PublicKey
- func (a *Account) ScriptHash() util.Uint160
- func (a *Account) SignHashable(net netmode.Magic, item hash.Hashable) []byte
- func (a *Account) SignTx(net netmode.Magic, t *transaction.Transaction) error
- type Contract
- type ContractParam
- type Extra
- type Token
- type Wallet
- func (w *Wallet) AddAccount(acc *Account)
- func (w *Wallet) AddToken(tok *Token)
- func (w *Wallet) Close()
- func (w *Wallet) CreateAccount(name, passphrase string) error
- func (w *Wallet) GetAccount(h util.Uint160) *Account
- func (w *Wallet) GetChangeAddress() util.Uint160
- func (w *Wallet) JSON() ([]byte, error)
- func (w *Wallet) Path() string
- func (w *Wallet) RemoveAccount(addr string) error
- func (w *Wallet) RemoveToken(h util.Uint160) error
- func (w *Wallet) Save() error
- func (w *Wallet) SavePretty() error
- func (w *Wallet) SetPath(path string)
Constants ¶
This section is empty.
Variables ¶
var ( // ErrPathIsEmpty appears if wallet was created without linking to file system path, // for instance with [NewInMemoryWallet] or [NewWalletFromBytes]. // Despite this, there was an attempt to save it via [Wallet.Save] or [Wallet.SavePretty] without [Wallet.SetPath]. ErrPathIsEmpty = errors.New("path is empty") )
Functions ¶
This section is empty.
Types ¶
type Account ¶
type Account struct { // NEO public address. Address string `json:"address"` // Encrypted WIF of the account also known as the key. EncryptedWIF string `json:"key"` // Label is a label the user had made for this account. Label string `json:"label"` // Contract is a Contract object which describes the details of the contract. // This field can be null (for watch-only address). Contract *Contract `json:"contract"` // Indicates whether the account is locked by the user. // the client shouldn't spend the funds in a locked account. Locked bool `json:"lock"` // Indicates whether the account is the default change account. Default bool `json:"isDefault"` // contains filtered or unexported fields }
Account represents a NEO account. It holds the private and the public key along with some metadata.
func NewAccount ¶
NewAccount creates a new Account with a random generated PrivateKey.
func NewAccountFromEncryptedWIF ¶
func NewAccountFromEncryptedWIF(wif string, pass string, scrypt keys.ScryptParams) (*Account, error)
NewAccountFromEncryptedWIF creates a new Account from the given encrypted WIF.
func NewAccountFromPrivateKey ¶ added in v0.92.0
func NewAccountFromPrivateKey(p *keys.PrivateKey) *Account
NewAccountFromPrivateKey creates a wallet from the given PrivateKey.
func NewAccountFromWIF ¶
NewAccountFromWIF creates a new Account from the given WIF.
func NewContractAccount ¶ added in v0.105.0
NewContractAccount creates a contract account belonging to some deployed contract. SignTx can be called on this account with no error and will create invocation script, which puts provided arguments on stack for use in `verify`.
func (*Account) CanSign ¶ added in v0.99.3
CanSign returns true when account is not locked and has a decrypted private key inside, so it's ready to create real signatures.
func (*Account) Close ¶ added in v0.99.3
func (a *Account) Close()
Close cleans up the private key used by Account and disassociates it from Account. The Account can no longer sign anything after this call, but Decrypt can make it usable again.
func (*Account) ConvertMultisig ¶
ConvertMultisig sets a's contract to multisig contract with m sufficient signatures.
func (*Account) ConvertMultisigEncrypted ¶ added in v0.106.0
func (a *Account) ConvertMultisigEncrypted(accKey *keys.PublicKey, m int, pubs []*keys.PublicKey) error
ConvertMultisigEncrypted sets a's contract to an encrypted multisig contract with m sufficient signatures. The encrypted private key is not modified and remains the same.
func (*Account) Decrypt ¶
func (a *Account) Decrypt(passphrase string, scrypt keys.ScryptParams) error
Decrypt decrypts the EncryptedWIF with the given passphrase returning error if anything goes wrong. After the decryption Account can be used to sign things unless it's locked. Don't decrypt the key unless you want to sign something and don't forget to call Close after use for maximum safety.
func (*Account) Encrypt ¶
func (a *Account) Encrypt(passphrase string, scrypt keys.ScryptParams) error
Encrypt encrypts the wallet's PrivateKey with the given passphrase under the NEP-2 standard.
func (*Account) GetVerificationScript ¶ added in v0.93.0
GetVerificationScript returns account's verification script.
func (*Account) PrivateKey ¶
func (a *Account) PrivateKey() *keys.PrivateKey
PrivateKey returns private key corresponding to the account if it's unlocked. Please be very careful when using it, do not copy its contents and do not keep a pointer to it unless you absolutely need to. Most of the time you can use other methods (PublicKey, ScriptHash, SignHashable) depending on your needs and it'll be safer this way.
func (*Account) PublicKey ¶ added in v0.99.3
PublicKey returns the public key associated with the private key corresponding to the account. It can return nil if account is locked (use CanSign to check).
func (*Account) ScriptHash ¶ added in v0.99.3
ScriptHash returns the script hash (account) that the Account.Address is derived from. It never returns an error, so if this Account has an invalid Address you'll just get a zero script hash.
func (*Account) SignHashable ¶ added in v0.99.3
SignHashable signs the given Hashable item and returns the signature. If this account can't sign (CanSign() returns false) nil is returned.
func (*Account) SignTx ¶
func (a *Account) SignTx(net netmode.Magic, t *transaction.Transaction) error
SignTx signs transaction t and updates it's Witnesses.
type Contract ¶
type Contract struct { // Script of the contract deployed on the blockchain. Script []byte `json:"script"` // A list of parameters used deploying this contract. Parameters []ContractParam `json:"parameters"` // Indicates whether the contract has been deployed to the blockchain. Deployed bool `json:"deployed"` // InvocationBuilder returns invocation script for deployed contracts. // In case contract is not deployed or has 0 arguments, this field is ignored. // It might be executed on a partially formed tx, and is primarily needed to properly // calculate network fee for complex contract signers. InvocationBuilder func(tx *transaction.Transaction) ([]byte, error) `json:"-"` }
Contract represents a subset of the smartcontract to embed in the Account so it's NEP-6 compliant.
func (Contract) ScriptHash ¶
ScriptHash returns the hash of contract's script.
type ContractParam ¶
type ContractParam struct { Name string `json:"name"` Type smartcontract.ParamType `json:"type"` }
ContractParam is a descriptor of a contract parameter containing type and optional name.
type Extra ¶
type Extra struct { // Tokens is a list of imported token contracts. Tokens []*Token }
Extra stores imported token contracts.
type Token ¶
type Token struct { Name string `json:"name"` Hash util.Uint160 `json:"script_hash"` Decimals int64 `json:"decimals"` Symbol string `json:"symbol"` Standard string `json:"standard"` }
Token represents an imported token contract.
type Wallet ¶
type Wallet struct { // Version of the wallet, used for later upgrades. Version string `json:"version"` // A list of accounts which describes the details of each account // in the wallet. Accounts []*Account `json:"accounts"` Scrypt keys.ScryptParams `json:"scrypt"` // Extra metadata can be used for storing arbitrary data. // This field can be empty. Extra Extra `json:"extra"` // contains filtered or unexported fields }
Wallet represents a NEO (NEP-2, NEP-6) compliant wallet.
func NewInMemoryWallet ¶ added in v0.105.0
func NewInMemoryWallet() *Wallet
NewInMemoryWallet creates a new NEO wallet without linking to the read file on file system. If wallet required to be written to the file system, Wallet.SetPath should be used to set the path.
func NewWalletFromBytes ¶ added in v0.105.0
NewWalletFromBytes creates a Wallet from the given byte slice. Parameter wallet contains JSON representation of wallet, see Wallet.JSON for details.
NewWalletFromBytes constructor doesn't set wallet's path. If you want to save the wallet to file system, use Wallet.SetPath.
func NewWalletFromFile ¶
NewWalletFromFile creates a Wallet from the given wallet file path.
func (*Wallet) AddAccount ¶
AddAccount adds an existing Account to the wallet.
func (*Wallet) Close ¶
func (w *Wallet) Close()
Close closes all Wallet accounts making them incapable of signing anything (unless they're decrypted again). It's not doing anything to the underlying wallet file.
func (*Wallet) CreateAccount ¶
CreateAccount generates a new account for the end user and encrypts the private key with the given passphrase.
func (*Wallet) GetAccount ¶
GetAccount returns an account corresponding to the provided scripthash.
func (*Wallet) GetChangeAddress ¶
GetChangeAddress returns the default address to send transaction's change to.
func (*Wallet) RemoveAccount ¶
RemoveAccount removes an Account with the specified addr from the wallet.
func (*Wallet) RemoveToken ¶
RemoveToken removes the token with the specified hash from the wallet.
func (*Wallet) Save ¶
Save saves the wallet data to the file located at the path that was either provided via NewWalletFromFile constructor or via Wallet.SetPath.
Returns ErrPathIsEmpty if wallet path is not set. See Wallet.SetPath.
func (*Wallet) SavePretty ¶ added in v0.99.1
SavePretty saves the wallet in a beautiful JSON.
Returns ErrPathIsEmpty if wallet path is not set. See Wallet.SetPath.