aboutsummaryrefslogtreecommitdiffstats
path: root/accounts
diff options
context:
space:
mode:
authorBas van Kervel <bas@ethdev.com>2016-05-13 01:32:04 +0800
committerBas van Kervel <bas@ethdev.com>2016-05-20 21:54:18 +0800
commit64a6c2c1b6c81fddccc7d3d728b7a05c5814124b (patch)
tree05d6c04a1c5eeb5746425b3d7e691ee071f66c0e /accounts
parente798e4fd750745cec99c5a531e42998d9a7be85e (diff)
downloaddexon-64a6c2c1b6c81fddccc7d3d728b7a05c5814124b.tar
dexon-64a6c2c1b6c81fddccc7d3d728b7a05c5814124b.tar.gz
dexon-64a6c2c1b6c81fddccc7d3d728b7a05c5814124b.tar.bz2
dexon-64a6c2c1b6c81fddccc7d3d728b7a05c5814124b.tar.lz
dexon-64a6c2c1b6c81fddccc7d3d728b7a05c5814124b.tar.xz
dexon-64a6c2c1b6c81fddccc7d3d728b7a05c5814124b.tar.zst
dexon-64a6c2c1b6c81fddccc7d3d728b7a05c5814124b.zip
eth: add new RPC method (personal.) SignAndSendTransaction
Diffstat (limited to 'accounts')
-rw-r--r--accounts/account_manager.go16
-rw-r--r--accounts/accounts_test.go28
2 files changed, 42 insertions, 2 deletions
diff --git a/accounts/account_manager.go b/accounts/account_manager.go
index 3afadf6b2..bfb7556d6 100644
--- a/accounts/account_manager.go
+++ b/accounts/account_manager.go
@@ -147,9 +147,21 @@ func (am *Manager) Sign(addr common.Address, hash []byte) (signature []byte, err
return crypto.Sign(hash, unlockedKey.PrivateKey)
}
+// SignWithPassphrase signs hash if the private key matching the given address can be
+// decrypted with the given passphrase.
+func (am *Manager) SignWithPassphrase(addr common.Address, passphrase string, hash []byte) (signature []byte, err error) {
+ _, key, err := am.getDecryptedKey(Account{Address: addr}, passphrase)
+ if err != nil {
+ return nil, err
+ }
+
+ defer zeroKey(key.PrivateKey)
+ return crypto.Sign(hash, key.PrivateKey)
+}
+
// Unlock unlocks the given account indefinitely.
-func (am *Manager) Unlock(a Account, keyAuth string) error {
- return am.TimedUnlock(a, keyAuth, 0)
+func (am *Manager) Unlock(a Account, passphrase string) error {
+ return am.TimedUnlock(a, passphrase, 0)
}
// Lock removes the private key with the given address from memory.
diff --git a/accounts/accounts_test.go b/accounts/accounts_test.go
index 829cf3968..2e5f2b44a 100644
--- a/accounts/accounts_test.go
+++ b/accounts/accounts_test.go
@@ -81,6 +81,34 @@ func TestSign(t *testing.T) {
}
}
+func TestSignWithPassphrase(t *testing.T) {
+ dir, am := tmpManager(t, true)
+ defer os.RemoveAll(dir)
+
+ pass := "passwd"
+ acc, err := am.NewAccount(pass)
+ if err != nil {
+ t.Fatal(err)
+ }
+
+ if _, unlocked := am.unlocked[acc.Address]; unlocked {
+ t.Fatal("expected account to be locked")
+ }
+
+ _, err = am.SignWithPassphrase(acc.Address, pass, testSigData)
+ if err != nil {
+ t.Fatal(err)
+ }
+
+ if _, unlocked := am.unlocked[acc.Address]; unlocked {
+ t.Fatal("expected account to be locked")
+ }
+
+ if _, err = am.SignWithPassphrase(acc.Address, "invalid passwd", testSigData); err == nil {
+ t.Fatal("expected SignHash to fail with invalid password")
+ }
+}
+
func TestTimedUnlock(t *testing.T) {
dir, am := tmpManager(t, true)
defer os.RemoveAll(dir)