This repository is currently being migrated. It's locked while the migration is in progress.
-
Notifications
You must be signed in to change notification settings - Fork 27
couldn't recover public key from signature #26
Comments
Looks like the developers abandoned IDEX API project. If so then remove the link to here from https://idex.market |
Hi @GoldRat, did you get this sorted out? We don't have C# code samples, but in case it helps, here is what it would look like in JS: const { soliditySha3 } = require('web3-utils');
const {
hashPersonalMessage,
bufferToHex,
toBuffer,
ecsign,
} = require('ethereumjs-util');
const { mapValues } = require('lodash');
const args = {
"contractAddress": '0x2a0c0dbecc7e4d658f48e01e3fa353f44050c208',
"tokenBuy": "0xcdcfc0f66c522fd086a1b725ea3c0eeb9f9e8814",
"amountBuy": "139611895000864697098",
"tokenSell": "0x0000000000000000000000000000000000000000",
"amountSell": "40000000000000000",
"address": "0x351296f44a5bf3f05eaa7d78a560f50dd736b728",
"nonce": 2,
"expires": 10000,
}
const raw = soliditySha3({
t: 'address',
v: args.contractAddress
}, {
t: 'address',
v: args.tokenBuy
}, {
t: 'uint256',
v: args.amountBuy
}, {
t: 'address',
v: args.tokenSell
}, {
t: 'uint256',
v: args.amountSell
}, {
t: 'uint256',
v: args.expires
}, {
t: 'uint256',
v: args.nonce
}, {
t: 'address',
v: args.address
});
const salted = hashPersonalMessage(toBuffer(raw));
const vrs = mapValues(ecsign(salted, toBuffer('0xce8291ae3e3f6db1f7d763fa543c1aa7c76080f69880d695bf131f4ca7bde67a')), (value, key) => key === 'v' ? value : bufferToHex(value));
delete args.contractAddress;
const args2 = Object.assign(args, vrs);
console.log(JSON.stringify(args2)); Which produces this request payload: {
"tokenBuy": "0xcdcfc0f66c522fd086a1b725ea3c0eeb9f9e8814",
"amountBuy": "139611895000864697098",
"tokenSell": "0x0000000000000000000000000000000000000000",
"amountSell": "40000000000000000",
"address": "0x351296f44a5bf3f05eaa7d78a560f50dd736b728",
"nonce": 2,
"expires": 10000,
"r": "0x50573d44812198c38d03fc815026c8c85669a43bcade519f44440acaaf2ab2be",
"s": "0x3136be5df241628bcafb845aea2c9b4d6e5d1bb87bc410af228e4d503ec39134",
"v": 28
} You can use this script to output any of the data points in the calculations and compare with the ones you've mentioned. In case you're new to JS, install node.js, copy and paste the above code into a file called something like
Also, as I'm sure you're aware, you should never hand out your private key, so don't use this wallet for real trading. Cheers, Phil |
Closed
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I'm trying to buy AURA, using C# (API call "order"). But it returns:
{"error":"couldn't recover public key from signature"}
Please help me to find out on which step I've mistaken.
Wallet: 0x351296f44a5bf3f05eaa7d78a560f50dd736b728
Private key: 0xce8291ae3e3f6db1f7d763fa543c1aa7c76080f69880d695bf131f4ca7bde67a
This is arguments:
"contractAddress":"0x2a0c0dbecc7e4d658f48e01e3fa353f44050c208",
"tokenBuy":"0xcdcfc0f66c522fd086a1b725ea3c0eeb9f9e8814",
"amountBuy":"139611895000864697098",
"tokenSell":"0x0000000000000000000000000000000000000000",
"amountSell":"40000000000000000",
"expires":10000,
"nonce":2,
"address":"0x351296f44a5bf3f05eaa7d78a560f50dd736b728"
This is arguments string in hex:
0x2a0c0dbecc7e4d658f48e01e3fa353f44050c208cdcfc0f66c522fd086a1b725ea3c0eeb9f9e8814000000000000000000000000000000000000000000000007918116cec9acab0a0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000008e1bc9bf04000000000000000000000000000000000000000000000000000000000000000027100000000000000000000000000000000000000000000000000000000000000002351296f44a5bf3f05eaa7d78a560f50dd736b728
This is the hash of arguments string (raw):
0x42829b360851b370442abe990de6aa4719918c887f172f1ad7f8415f6b0430ba
This is the hash of raw with prefix \x19Ethereum Signed Message:\n32 (salted):
0x1481258241d0bb45803c5efc22caaaf6d9301aff5b19fe8e119936cf0e77aa94
This is API call properties with signature:
{"contractAddress":"0x2a0c0dbecc7e4d658f48e01e3fa353f44050c208",
"tokenBuy":"0xcdcfc0f66c522fd086a1b725ea3c0eeb9f9e8814",
"amountBuy":"139611895000864697098",
"tokenSell":"0x0000000000000000000000000000000000000000",
"amountSell":"40000000000000000",
"expires":10000,
"nonce":2,
"address":"0x351296f44a5bf3f05eaa7d78a560f50dd736b728",
"v":27,
"r":"0x02edb1229ffd4f53b17c41bd016d1846c21774cc6f74f1863d11ab7cb62e9f55",
"s":"0x035fa7351c3c4d2fbddd6d9248e1295b21df1d8b0d554fa744cb0e406db046a7"}
I also will be very grateful for the example similar to the above with right values.
The text was updated successfully, but these errors were encountered: