Skip to content

Instantly share code, notes, and snippets.

@w00tc
Created June 2, 2020 23:06
Show Gist options
  • Save w00tc/408e7f75994aa563544c86bef90088a8 to your computer and use it in GitHub Desktop.
Save w00tc/408e7f75994aa563544c86bef90088a8 to your computer and use it in GitHub Desktop.
Sign DCCD Fix 1.0
let elliptic = require('elliptic');
let ec = new elliptic.ec('secp256k1');
let secp256k1 = require('secp256k1')
let wif = require('wif');
let sha256 = require('js-sha256');
let cargoId = inputs.cargoId;
let information = inputs.information;
console.log(inputs.privateKey);
let privateKey = wif.decode(inputs.privateKey);
privateKey = buf2hex(privateKey.privateKey);
let keyPair = ec.keyFromPrivate(privateKey);
let privKey = keyPair.getPrivate("hex");
let pubKey = keyPair.getPublic();
console.log(privateKey);
console.log(`Private key: ${privKey}`);
console.log("Public key :", pubKey.encode("hex"));
console.log("Public key (compressed):",
pubKey.encodeCompressed("hex"));
let timestamp = Math.round((new Date()).getTime() / 1000);
let temperature = '0'
let string = (cargoId + timestamp + temperature + information);
console.log(string);
let msgHash = sha256(string);
let hash = Buffer.from(msgHash, 'hex')
hash = buf2hex(hash);
hash = sha256(hash);
hash = Buffer.from(hash, 'hex')
console.log(hash);
let priv = Buffer.from(privateKey, 'hex')
console.log(buf2hex(priv));
const sigObj = secp256k1.ecdsaSign(hash, priv);
let final = (buf2hex(sigObj.signature));
console.log(final);
let dictionary = {
dictionary: {
cargo_id: cargoId,
timestamp: timestamp,
temperature: temperature,
information: information,
public_key: pubKey.encode("hex"),
signed_hash: final
}
}
dispatch(postItems(dictionary))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment