Created
March 14, 2018 16:56
-
-
Save anonymous/356d589687ed41180944a935a5dad1b7 to your computer and use it in GitHub Desktop.
Generate proof-of-public-key, for use with the Teikhos authentication method
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
const ethUtils = require('ethereumjs-util'); | |
const EthCrypto = require('eth-crypto'); | |
const xor = require('buffer-xor') | |
const keccak = require('keccakjs') | |
const identity = EthCrypto.createIdentity(); | |
const privateKey = new Buffer(identity.privateKey.slice(2), 'hex') | |
console.log("privateKey:") | |
console.log(privateKey.toString('hex')) | |
var publicKey = ethUtils.privateToPublic(privateKey) | |
console.log("Public Key: ") | |
console.log(publicKey.toString('hex')) | |
var address = ethUtils.pubToAddress(publicKey) | |
console.log("Address: ") | |
console.log(address.toString('hex')) | |
var keccakHash = new keccak() // uses 512 bits by default | |
keccakHash.update(publicKey) | |
var keyHashKeccak = new Buffer(keccakHash.digest('hex'), 'hex') | |
console.log("sha3(publicKey):") | |
console.log(keyHashKeccak.toString('hex')) | |
var msgHash = ethUtils.hashPersonalMessage(publicKey) | |
console.log("Message Hash: ") | |
console.log(msgHash.toString('hex')) | |
var sig = ethUtils.ecsign(msgHash, privateKey) | |
var signature = new Buffer(ethUtils.toRpcSig(sig.v, sig.r, sig.s).slice(2, -2), 'hex') | |
console.log("Signature: ") | |
console.log(signature.toString('hex')) | |
console.log(sig.r.toString('hex')) | |
var proof_of_public_key = xor(signature, keyHashKeccak) | |
console.log("Proof-Of-Public-Key: ") | |
console.log(proof_of_public_key.toString('hex')) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment