smWallet implements the Spacemesh encrypted wallet used by the Spacemesh App.
NewWallet
creates an unlocked encrypted wallet with mnemonic phrase and a single keypair
myWallet, err := NewWallet("My main wallet","notAGoodPassword")
LoadWallet
loads a wallet but does not unlock it.
myWallet, err := LoadWallet("keystores/dz.json")
To access the accounts or mnemonic phrase, you need to unlock the wallet.
example : load and unlock the wallet
myWallet, err := LoadWallet("keystores/dz.json")
if err != nil {
log.Fatal(err)
}
err := myWallet.Unlock("notAGoodPassword")
....
This is used to save a new wallet (which does not have a load path) or to save the current state of any open wallet.
err = myWallet.SaveAs("keystores/backup_copy.json")
Only works with wallets that have been loaded or previously saved with SaveWalletAs
err = myWallet.SaveWallet()
Signs a transaction using current keypair, returns []byte
ready to submit
var tx types.Transaction
tx.Recipient = types.BytesToAddress(util.Hex2Byte("865330189761187daa2243a1533b0412b8e14613"))
tx.GasLimit = 100
tx.Fee = 1
tx.Amount = 1000000000000
tx.AccountNonce = 3 // get from account info
txs, err := smData.SignedTransaction(&tx)
...
Requires an unlocked wallet.
keyNum,err := myWallet.GenerateNewPair("name of new keypair")
num,err := myWallet.GetNumberOfAccounts()
addr,err := myWallet.GetAddress(3)
...
fmt.Println(addr.Hex())
pub,err := myWallet.GetPublicKey(3)
name,err := myWallet.GetAddress(3)
...
fmt.Println(name)
select an existing keypair to be used for signing
err := myWallet.SetCurrent(3)