Initial commit
commit
cc9f108bb3
@ -0,0 +1,2 @@
|
||||
bundle.js
|
||||
node_modules
|
@ -0,0 +1,11 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>Ethereum Signing Test</title>
|
||||
<script src="bundle.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
(check the console)
|
||||
</body>
|
||||
</html>
|
@ -0,0 +1,35 @@
|
||||
'use strict';
|
||||
|
||||
// ecsign (messageHash, privateKey) -> {r, s, v}
|
||||
// ecrecover (messageHash, v, r, s) -> publicKey
|
||||
// sha3 (message, bits) -> messageHash
|
||||
// privateToPublic (privateKey) -> publicKey
|
||||
|
||||
const crypto = require("crypto");
|
||||
const ethereumUtil = require("ethereumjs-util");
|
||||
|
||||
let privateKey = crypto.randomBytes(32);
|
||||
let publicKey = ethereumUtil.privateToPublic(privateKey);
|
||||
|
||||
console.log("-- Key data:");
|
||||
console.log("Private key: (hex)", privateKey.toString("hex"));
|
||||
console.log("Public key: (hex)", publicKey.toString("hex"));
|
||||
|
||||
let message = "hello world!";
|
||||
let messageHash = ethereumUtil.sha3(message);
|
||||
|
||||
console.log("-- Message:");
|
||||
console.log("Plaintext:", message);
|
||||
console.log("Hash: (hex)", messageHash.toString("hex"));
|
||||
|
||||
let signature = ethereumUtil.ecsign(messageHash, privateKey);
|
||||
let recoveredPublicKey = ethereumUtil.ecrecover(messageHash, signature.v, signature.r, signature.s);
|
||||
|
||||
console.log("-- Signing:");
|
||||
console.log("Signature:");
|
||||
console.log(" v:", signature.v);
|
||||
console.log(" r: (hex)", signature.r.toString("hex"));
|
||||
console.log(" s: (hex)", signature.s.toString("hex"));
|
||||
console.log("Recovered public key: (hex)", recoveredPublicKey.toString("hex"));
|
||||
|
||||
console.log("\nPublic keys match:", (publicKey.compare(recoveredPublicKey) === 0));
|
@ -0,0 +1,23 @@
|
||||
{
|
||||
"name": "ethereum-signing-test",
|
||||
"version": "1.0.0",
|
||||
"description": "",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1",
|
||||
"build": "browserify index.js -o bundle.js"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git@git.cryto.net:joepie91/ethereum-signing-test.git"
|
||||
},
|
||||
"keywords": [],
|
||||
"author": "",
|
||||
"license": "ISC",
|
||||
"devDependencies": {
|
||||
"browserify": "^14.4.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"ethereumjs-util": "^5.1.2"
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue