Sign calculates an Cpchain ECDSA signature for: keccack256("\x19Cpchain Signed Message:\n" + len(message) + message)) Note, the produced signature conforms to the secp256k1 curve R, S and V values, where the V value will be 27 or 28 for legacy reasons. The key used to calculate the signature is de
(ctx context.Context, data hexutil.Bytes, addr common.Address, passwd string)
| 416 | // |
| 417 | // https://github.com/ethereum/go-ethereum/wiki/Management-APIs#personal_sign |
| 418 | func (s *PrivateAccountAPI) Sign(ctx context.Context, data hexutil.Bytes, addr common.Address, passwd string) (hexutil.Bytes, error) { |
| 419 | // Look up the wallet containing the requested signer |
| 420 | account := accounts.Account{Address: addr} |
| 421 | |
| 422 | wallet, err := s.b.AccountManager().Find(account) |
| 423 | if err != nil { |
| 424 | return nil, err |
| 425 | } |
| 426 | // Assemble sign the data with the wallet |
| 427 | signature, err := wallet.SignHashWithPassphrase(account, passwd, signHash(data)) |
| 428 | if err != nil { |
| 429 | return nil, err |
| 430 | } |
| 431 | signature[64] += 27 // Transform V from 0/1 to 27/28 according to the yellow paper |
| 432 | return signature, nil |
| 433 | } |
| 434 | |
| 435 | // EcRecover returns the address for the account that was used to create the signature. |
| 436 | // Note, this function is compatible with eth_sign and personal_sign. As such it recovers |