EOSIO / eosjs-ecc

Elliptic curve cryptography functions: Private Key, Public Key, Signature, AES, Encryption, Decryption
288 stars 119 forks source link

ecc.recover() does not seem to function as expected #28

Closed WarrickFitz closed 6 years ago

WarrickFitz commented 6 years ago

The below code signs a string "123" and then called recover .. for some reason the key returned does not match the expected key. Please explain or flag as bug.

The output of the below looks as follows: 123 SIG_K1_K1K6bCbJ9AqxYgeYLGxqtG4MhiyBodTqGsjEeeGcguBTWpBEg54rywEGkNUYbn9uPF7QtCUo9sD8XKd7By3FbJDd78cY9m recovered key: EOS5Q36JqHkTrsBuEufZTFLgKn7YQ582ew6STCFWmwVTuEFEgERec

    function recoverTest() {

        var initaPrivate = '5KQwrPbwdL6PhXujxW37FSSQZ1JiwsST4cqQzDeyXtP79zkvFD3';
        var initaPublic = 'EOS6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV';

        var action = document.getElementById('transaction').value;
        console.log(action);

        var sign = ecc.sign(action, initaPrivate ,'hex').toString();
        console.log(sign);

        var recover = ecc.recover(sign, action);
        console.log("recovered key: "+recover);
    }
jcalfee commented 6 years ago

try cc.recover(sign, action, 'hex')

WarrickFitz commented 6 years ago

Ah drat, it's always the simplest thing. Thank you sir, that did it.