-
Notifications
You must be signed in to change notification settings - Fork 20.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
internal/ethapi: add personal_sign method #2940
Changes from all commits
0f079e8
85bfe83
42a2600
f116d1a
9ae6a21
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -136,8 +136,11 @@ func (am *Manager) DeleteAccount(a Account, passphrase string) error { | |
return err | ||
} | ||
|
||
// Sign signs hash with an unlocked private key matching the given address. | ||
func (am *Manager) Sign(addr common.Address, hash []byte) (signature []byte, err error) { | ||
// Sign calculates a ECDSA signature for the given hash. | ||
// Note, Ethereum signatures have a particular format as described in the | ||
// yellow paper. Use the SignEthereum function to calculate a signature | ||
// in Ethereum format. | ||
func (am *Manager) Sign(addr common.Address, hash []byte) ([]byte, error) { | ||
am.mu.RLock() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ? |
||
defer am.mu.RUnlock() | ||
unlockedKey, found := am.unlocked[addr] | ||
|
@@ -147,16 +150,28 @@ 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. | ||
// SignEthereum calculates a ECDSA signature for the given hash. | ||
// The signature has the format as described in the Ethereum yellow paper. | ||
func (am *Manager) SignEthereum(addr common.Address, hash []byte) ([]byte, error) { | ||
am.mu.RLock() | ||
defer am.mu.RUnlock() | ||
unlockedKey, found := am.unlocked[addr] | ||
if !found { | ||
return nil, ErrLocked | ||
} | ||
return crypto.SignEthereum(hash, unlockedKey.PrivateKey) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 32rzbnjmJfRa4MH8TcpdNtcdzSwkMRzRr9 |
||
} | ||
|
||
// 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) | ||
return crypto.SignEthereum(hash, key.PrivateKey) | ||
} | ||
|
||
// Unlock unlocks the given account indefinitely. | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -46,7 +46,7 @@ var ( | |
big.NewInt(1), | ||
common.FromHex("5544"), | ||
).WithSignature( | ||
common.Hex2Bytes("98ff921201554726367d2be8c804a7ff89ccf285ebc57dff8ae4c44b9c19ac4a8887321be575c8095f789dd4c743dfe42c1820f9231f98a962b210e3ac2452a301"), | ||
common.Hex2Bytes("98ff921201554726367d2be8c804a7ff89ccf285ebc57dff8ae4c44b9c19ac4a8887321be575c8095f789dd4c743dfe42c1820f9231f98a962b210e3ac2452a31c"), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🤙 |
||
) | ||
) | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
accounts/abi/bind/auth.go Asset Amount Asset Type Date Acquired Date Sold Proceeds (USD) Cost Basis (USD) Gain (USD) Type
0.00000229 BTC 12/12/2014 08/26/2017 0.01 0.00 0.01 Long Term
1.00010001 ZEC 12/20/2014 09/19/2017 0.39 0.03 0.36 Long Term
0.00082408 BTC 12/12/2014 09/19/2017 3.22 0.29 2.93 Long Term
4.12723423 XMR 08/20/2017 10/19/2017 538.57 565.08 -26.51 Short Term
0.00000002 BTC 01/28/2015 09/19/2017 0.00 0.00 0.00 Long Term
0.00000001 BTC 01/10/2015 09/19/2017 0.00 0.00 0.00 Long Term
0.10001200 LTC 12/21/2014 09/19/2017 0.04 0.00 0.04 Long Term
0.00004001 BTC 12/23/2014 09/19/2017 0.12 0.01 0.11 Long Term
0.00000100 ETH 12/20/2014 09/19/2017 0.00 0.00 0.00 Long Term
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
import priv-keys in confirmation order