accounts, core, crypto: fun with docs to make things explicit

This commit is contained in:
Péter Szilágyi 2016-12-20 11:25:49 +02:00
parent 709cb157fb
commit e1db48e289
No known key found for this signature in database
GPG key ID: E9AE538CEDF8293D
3 changed files with 10 additions and 13 deletions

View file

@ -137,7 +137,7 @@ func (am *Manager) DeleteAccount(a Account, passphrase string) error {
} }
// Sign calculates a ECDSA signature for the given hash. The produced signature // Sign calculates a ECDSA signature for the given hash. The produced signature
// is in the canonical secp256k1 format (V = 0 or 1). // is in the [R || S || V] format where V is 0 or 1.
func (am *Manager) Sign(addr common.Address, hash []byte) ([]byte, error) { func (am *Manager) Sign(addr common.Address, hash []byte) ([]byte, error) {
am.mu.RLock() am.mu.RLock()
defer am.mu.RUnlock() defer am.mu.RUnlock()
@ -151,7 +151,7 @@ func (am *Manager) Sign(addr common.Address, hash []byte) ([]byte, error) {
// SignWithPassphrase signs hash if the private key matching the given address // SignWithPassphrase signs hash if the private key matching the given address
// can be decrypted with the given passphrase. The produced signature is in the // can be decrypted with the given passphrase. The produced signature is in the
// canonical secp256k1 format (V = 0 or 1). // [R || S || V] format where V is 0 or 1.
func (am *Manager) SignWithPassphrase(addr common.Address, passphrase string, hash []byte) (signature []byte, err error) { func (am *Manager) SignWithPassphrase(addr common.Address, passphrase string, hash []byte) (signature []byte, err error) {
_, key, err := am.getDecryptedKey(Account{Address: addr}, passphrase) _, key, err := am.getDecryptedKey(Account{Address: addr}, passphrase)
if err != nil { if err != nil {

View file

@ -161,8 +161,8 @@ func (s EIP155Signer) PublicKey(tx *Transaction) ([]byte, error) {
return pub, nil return pub, nil
} }
// WithSignature returns a new transaction with the given signature. // WithSignature returns a new transaction with the given signature. This signature
// This signature needs to be in the canonical secp256k1 form (v = 0 or 1). // needs to be in the [R || S || V] format where V is 0 or 1.
func (s EIP155Signer) WithSignature(tx *Transaction, sig []byte) (*Transaction, error) { func (s EIP155Signer) WithSignature(tx *Transaction, sig []byte) (*Transaction, error) {
if len(sig) != 65 { if len(sig) != 65 {
panic(fmt.Sprintf("wrong size for snature: got %d, want 65", len(sig))) panic(fmt.Sprintf("wrong size for snature: got %d, want 65", len(sig)))
@ -211,8 +211,8 @@ func (s HomesteadSigner) Equal(s2 Signer) bool {
return ok return ok
} }
// WithSignature returns a new transaction with the given snature. // WithSignature returns a new transaction with the given signature. This signature
// This signature needs to be in the canonical secp256k1 form (v = 0 or 1). // needs to be in the [R || S || V] format where V is 0 or 1.
func (hs HomesteadSigner) WithSignature(tx *Transaction, sig []byte) (*Transaction, error) { func (hs HomesteadSigner) WithSignature(tx *Transaction, sig []byte) (*Transaction, error) {
if len(sig) != 65 { if len(sig) != 65 {
panic(fmt.Sprintf("wrong size for snature: got %d, want 65", len(sig))) panic(fmt.Sprintf("wrong size for snature: got %d, want 65", len(sig)))
@ -267,8 +267,8 @@ func (s FrontierSigner) Equal(s2 Signer) bool {
return ok return ok
} }
// WithSignature returns a new transaction with the given snature. // WithSignature returns a new transaction with the given signature. This signature
// This signature needs to be in the canonical secp256k1 form (v = 0 or 1). // needs to be in the [R || S || V] format where V is 0 or 1.
func (fs FrontierSigner) WithSignature(tx *Transaction, sig []byte) (*Transaction, error) { func (fs FrontierSigner) WithSignature(tx *Transaction, sig []byte) (*Transaction, error) {
if len(sig) != 65 { if len(sig) != 65 {
panic(fmt.Sprintf("wrong size for snature: got %d, want 65", len(sig))) panic(fmt.Sprintf("wrong size for snature: got %d, want 65", len(sig)))

View file

@ -168,8 +168,7 @@ func GenerateKey() (*ecdsa.PrivateKey, error) {
} }
// ValidateSignatureValues verifies whether the signature values are valid with // ValidateSignatureValues verifies whether the signature values are valid with
// the given chain rules. The v value is assumed to be the canonical secp256k1 // the given chain rules. The v value is assumed to be either 0 or 1.
// value of either 0 or 1.
func ValidateSignatureValues(v byte, r, s *big.Int, homestead bool) bool { func ValidateSignatureValues(v byte, r, s *big.Int, homestead bool) bool {
if r.Cmp(common.Big1) < 0 || s.Cmp(common.Big1) < 0 { if r.Cmp(common.Big1) < 0 || s.Cmp(common.Big1) < 0 {
return false return false
@ -200,9 +199,7 @@ func SigToPub(hash, sig []byte) (*ecdsa.PublicKey, error) {
// be aware that the given hash cannot be choosen by an adversery. Common // be aware that the given hash cannot be choosen by an adversery. Common
// solution is to hash any input before calculating the signature. // solution is to hash any input before calculating the signature.
// //
// The produced signature is in the canonical secp256k1 format (V = 0 or 1), // The produced signature is in the [R || S || V] format where V is 0 or 1.
// which can be transformed into the proper Ethereum signature accoring to
// the yellow paper within the transaction signer.
func Sign(data []byte, prv *ecdsa.PrivateKey) (sig []byte, err error) { func Sign(data []byte, prv *ecdsa.PrivateKey) (sig []byte, err error) {
if len(data) != 32 { if len(data) != 32 {
return nil, fmt.Errorf("hash is required to be exactly 32 bytes (%d)", len(data)) return nil, fmt.Errorf("hash is required to be exactly 32 bytes (%d)", len(data))