GetScatter / ScatterWebExtension

Extension that allows you to sign transactions with your private keys securely from within the browser without ever exposing them.
MIT License
366 stars 127 forks source link

Example payload of signer(bgContext, payload ...) ecc.Signature.signHash(payload.data... #158

Closed MarcelBlockchain closed 6 years ago

MarcelBlockchain commented 6 years ago

What is an example payload of the following snippet? I tried to test it in dev mode, but encountered a problem as described here #157

Would answer my question at https://github.com/EOSIO/eosjs/issues/306 as well.

https://github.com/GetScatter/ScatterWebExtension/blob/master/src/plugins/defaults/eos.js#L118

signer(bgContext, payload, publicKey, callback, arbitrary = false, isHash = false){
        bgContext.publicToPrivate(privateKey => {
            if(!privateKey){
                callback(null);
                return false;
            }

            let sig;
            if(arbitrary && isHash) sig = ecc.Signature.signHash(payload.data, privateKey).toString();
            else sig = ecc.sign(Buffer.from(arbitrary ? payload.data : payload.buf.data, 'utf8'), privateKey);

            callback(sig);
        }, publicKey)
}

bgContext and callback are interesting as well

nsjames commented 6 years ago

I'd check out this instead as it's far more succinct and this code has fallen out of sync with Scatter's methodologies.

https://github.com/GetScatter/ScatterDesktop/blob/master/src/plugins/defaults/eos.js#L228

The payload itself can be just

{ 
  buf:{
    data:[] // An array of bytes that encapsulates the entire transaction
  }
}

Of for arbitrary data

{ 
  data:[] // An array of bytes or a hash string
}