mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-26 14:46:42 +00:00
accounts, core, crypto: fun with docs to make things explicit
This commit is contained in:
parent
709cb157fb
commit
e1db48e289
3 changed files with 10 additions and 13 deletions
|
|
@ -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()
|
||||
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -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)))
|
||||
|
|
@ -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)))
|
||||
|
|
@ -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)))
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
@ -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))
|
||||
|
|
|
|||
Loading…
Reference in a new issue