Created
May 9, 2018 21:18
-
-
Save tranvictor/860d5f1be393c444ef4e8600c9a2360f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func (self IEOSigner) IEOSign(contributor ethereum.Address, userid uint64, ieoid *big.Int) (string, string, string, error) { | |
// 1. concat all bytes of contributor, userid (0 padded to 32 bytes), ieoid (0 padded to 32 bytes) | |
contributorBytes := ethereum.LeftPadBytes(contributor.Big().Bytes(), 20) | |
useridBytes := ethereum.LeftPadBytes(big.NewInt(int64(userid)).Bytes(), 32) | |
ieoidBytes := ethereum.LeftPadBytes(ieoid.Bytes(), 32) | |
concat := append(contributorBytes, useridBytes...) | |
concat = append(concat, ieoidBytes...) | |
// 2. sha3 the concatenation to get msg | |
msg := crypto.Keccak256(concat) | |
fmt.Printf("msg: %s\n", ethereum.ToHex(msg)) | |
// 3. sign the msg to get signed msg | |
signed, err := secp256k1.Sign(msg, self.priv) | |
if err != nil { | |
return "", "", "", err | |
} | |
// 4. extract r, s, v from signed msg | |
r := signed[0:32] | |
s := signed[32:64] | |
v := signed[64:65] | |
return ethereum.ToHex(v), ethereum.ToHex(r), ethereum.ToHex(s), nil | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment