Skip to content

Commit

Permalink
accounts, core, crypto: fun with docs to make things explicit
Browse files Browse the repository at this point in the history
  • Loading branch information
karalabe committed Jan 4, 2017
1 parent 709cb15 commit e1db48e
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 13 deletions.
4 changes: 2 additions & 2 deletions accounts/account_manager.go
Expand Up @@ -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
// 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) {
am.mu.RLock()
defer am.mu.RUnlock()
Expand All @@ -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
// 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) {
_, key, err := am.getDecryptedKey(Account{Address: addr}, passphrase)
if err != nil {
Expand Down
12 changes: 6 additions & 6 deletions core/types/transaction_signing.go
Expand Up @@ -161,8 +161,8 @@ func (s EIP155Signer) PublicKey(tx *Transaction) ([]byte, error) {
return pub, nil
}

// WithSignature returns a new transaction with the given signature.
// This signature needs to be in the canonical secp256k1 form (v = 0 or 1).
// WithSignature returns a new transaction with the given signature. This signature
// 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) {
if len(sig) != 65 {
panic(fmt.Sprintf("wrong size for snature: got %d, want 65", len(sig)))
Expand Down Expand Up @@ -211,8 +211,8 @@ func (s HomesteadSigner) Equal(s2 Signer) bool {
return ok
}

// WithSignature returns a new transaction with the given snature.
// This signature needs to be in the canonical secp256k1 form (v = 0 or 1).
// WithSignature returns a new transaction with the given signature. This signature
// 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) {
if len(sig) != 65 {
panic(fmt.Sprintf("wrong size for snature: got %d, want 65", len(sig)))
Expand Down Expand Up @@ -267,8 +267,8 @@ func (s FrontierSigner) Equal(s2 Signer) bool {
return ok
}

// WithSignature returns a new transaction with the given snature.
// This signature needs to be in the canonical secp256k1 form (v = 0 or 1).
// WithSignature returns a new transaction with the given signature. This signature
// 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) {
if len(sig) != 65 {
panic(fmt.Sprintf("wrong size for snature: got %d, want 65", len(sig)))
Expand Down
7 changes: 2 additions & 5 deletions crypto/crypto.go
Expand Up @@ -168,8 +168,7 @@ func GenerateKey() (*ecdsa.PrivateKey, error) {
}

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

0 comments on commit e1db48e

Please sign in to comment.