Created
May 21, 2018 21:10
-
-
Save abdulowork/5433f8f3937393e006fc53f41da29e29 to your computer and use it in GitHub Desktop.
This file contains 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
/** | |
{ | |
"exchangeContractAddress" : "0x12459c951127e0c374ff9105dda097662a027093", | |
"maker" : "0x8c7d76d9aef6a104b500cfd1746c331f4da5bce8", | |
"taker" : "0x0000000000000000000000000000000000000000", | |
"makerTokenAddress" : "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2", | |
"takerTokenAddress" : "0xe41d2489571d322189246dafa5ebde1f4699f498", | |
"feeRecipient" : "0xa258b39954cef5cb142fd567a46cddb31a670124", | |
"makerTokenAmount" : "1950100000000000", | |
"takerTokenAmount" : "1000000000000000000", | |
"makerFee" : "0", | |
"takerFee" : "0", | |
"expirationUnixTimestampSec" : "1526921772", | |
"salt" : "86785906954588868942673379887384221477103830402997510744810924003638980963919", | |
"ecSignature" : { | |
"r" : "0x806197f32b842430dc15508e1d04c7794543273f1b6cf9fd997417448268e4ba", | |
"v" : 28, | |
"s" : "0x44ae08ffa24152f60c86b071be80d2ac18aed968b5d29baf1cf3f7b07b99ee98" | |
} | |
} | |
*/ | |
let message: BytesScalar = ConcatenatedBytes( | |
bytes: [ | |
BytesFromHexString( | |
hex: "0x12459c951127e0c374ff9105dda097662a027093" | |
), | |
BytesFromHexString( | |
hex: "0x8c7d76d9aef6a104b500cfd1746c331f4da5bce8" | |
), | |
BytesFromHexString( | |
hex: "0x0000000000000000000000000000000000000000" | |
), | |
BytesFromHexString( | |
hex: "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2" | |
), | |
BytesFromHexString( | |
hex: "0xe41d2489571d322189246dafa5ebde1f4699f498" | |
), | |
BytesFromHexString( | |
hex: "0xa258b39954cef5cb142fd567a46cddb31a670124" | |
), | |
LeftZeroesPaddedBytes( | |
origin: BytesFromHexString( | |
hex: "06ED9B09C6C800" | |
), | |
padding: 32 | |
), | |
LeftZeroesPaddedBytes( | |
origin: BytesFromHexString( | |
hex: "0DE0B6B3A7640000" | |
), | |
padding: 32 | |
), | |
LeftZeroesPaddedBytes( | |
origin: BytesFromHexString( | |
hex: "00" | |
), | |
padding: 32 | |
), | |
LeftZeroesPaddedBytes( | |
origin: BytesFromHexString( | |
hex: "00" | |
), | |
padding: 32 | |
), | |
LeftZeroesPaddedBytes( | |
origin: BytesFromHexString( | |
hex: "5B02FA2C" | |
), | |
padding: 32 | |
), | |
BytesFromHexString( | |
hex: "BFDF1526B0814C13561DD504979F4BBB1E9BA84DBAF50DBB24B046B76A08EE4F" | |
) | |
] | |
) | |
let pk = try SECP256k1Signature( | |
privateKey: EthPrivateKey( | |
bytes: BytesFromHexString( | |
hex: fatalError("YOUR PRIVATE KEY HERE") | |
) | |
), | |
message: ConcatenatedBytes( | |
bytes: [ | |
UTF8StringBytes( | |
string: SimpleString( | |
string: "\u{19}Ethereum Signed Message:\n32" //32 because keccak256 is always 32 | |
) | |
), | |
Keccak256Bytes( | |
origin: message | |
) | |
] | |
), | |
hashFunction: SHA3(variant: .keccak256).calculate | |
) | |
print( | |
try! "r: " + pk.r().value().toHexString() | |
) | |
print( | |
try! "s: " + pk.s().value().toHexString() | |
) | |
print( | |
try! "recid: " + "\(pk.recoverID().value())" | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment