backend.go 4.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. // Copyright 2017 The go-ethereum Authors
  2. // This file is part of the go-ethereum library.
  3. //
  4. // The go-ethereum library is free software: you can redistribute it and/or modify
  5. // it under the terms of the GNU Lesser General Public License as published by
  6. // the Free Software Foundation, either version 3 of the License, or
  7. // (at your option) any later version.
  8. //
  9. // The go-ethereum library is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. // GNU Lesser General Public License for more details.
  13. //
  14. // You should have received a copy of the GNU Lesser General Public License
  15. // along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
  16. package accounts
  17. import (
  18. "math/big"
  19. "github.com/ethereum/go-ethereum/common"
  20. "github.com/ethereum/go-ethereum/core/types"
  21. )
  22. // Backend is an "account provider" that can specify a batch of accounts it can
  23. // sign transactions with and upon request, do so.
  24. type Backend interface {
  25. // Accounts retrieves the list of signing accounts the backend is currently aware of.
  26. Accounts() []Account
  27. // HasAddress reports whether an account with the given address is present.
  28. HasAddress(addr common.Address) bool
  29. // SignHash requests the backend to sign the given hash.
  30. //
  31. // It looks up the account specified either solely via its address contained within,
  32. // or optionally with the aid of any location metadata from the embedded URL field.
  33. //
  34. // If the backend requires additional authentication to sign the request (e.g.
  35. // a password to decrypt the account, or a PIN code o verify the transaction),
  36. // an AuthNeededError instance will be returned, containing infos for the user
  37. // about which fields or actions are needed. The user may retry by providing
  38. // the needed details via SignHashWithPassphrase, or by other means (e.g. unlock
  39. // the account in a keystore).
  40. SignHash(acc Account, hash []byte) ([]byte, error)
  41. // SignTx requests the backend to sign the given transaction.
  42. //
  43. // It looks up the account specified either solely via its address contained within,
  44. // or optionally with the aid of any location metadata from the embedded URL field.
  45. //
  46. // If the backend requires additional authentication to sign the request (e.g.
  47. // a password to decrypt the account, or a PIN code o verify the transaction),
  48. // an AuthNeededError instance will be returned, containing infos for the user
  49. // about which fields or actions are needed. The user may retry by providing
  50. // the needed details via SignTxWithPassphrase, or by other means (e.g. unlock
  51. // the account in a keystore).
  52. SignTx(acc Account, tx *types.Transaction, chainID *big.Int) (*types.Transaction, error)
  53. // SignHashWithPassphrase requests the backend to sign the given transaction with
  54. // the given passphrase as extra authentication information.
  55. //
  56. // It looks up the account specified either solely via its address contained within,
  57. // or optionally with the aid of any location metadata from the embedded URL field.
  58. SignHashWithPassphrase(acc Account, passphrase string, hash []byte) ([]byte, error)
  59. // SignTxWithPassphrase requests the backend to sign the given transaction, with the
  60. // given passphrase as extra authentication information.
  61. //
  62. // It looks up the account specified either solely via its address contained within,
  63. // or optionally with the aid of any location metadata from the embedded URL field.
  64. SignTxWithPassphrase(acc Account, passphrase string, tx *types.Transaction, chainID *big.Int) (*types.Transaction, error)
  65. // TODO(karalabe,fjl): watching and caching needs the Go subscription system
  66. // Watch requests the backend to send a notification to the specified channel whenever
  67. // an new account appears or an existing one disappears.
  68. //Watch(chan AccountEvent) error
  69. // Unwatch requests the backend stop sending notifications to the given channel.
  70. //Unwatch(chan AccountEvent) error
  71. }
  72. // TODO(karalabe,fjl): watching and caching needs the Go subscription system
  73. // type AccountEvent struct {
  74. // Account Account
  75. // Added bool
  76. // }