Skip to content

Commit

Permalink
Added canary script and samples.
Browse files Browse the repository at this point in the history
  • Loading branch information
ricmoo committed Feb 8, 2017
1 parent 95f2d24 commit df8d88c
Show file tree
Hide file tree
Showing 5 changed files with 88 additions and 0 deletions.
20 changes: 20 additions & 0 deletions tools/canary/canary-test.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"version": "0.1",
"alerts": [
{
"affectedVersions": [
"io.ethers.app/0.1"
],
"heading": "Warning",
"text": [
"This is a test of the **emergency canary** system.",
"This is only a drill.",
"",
"If this had been a real emergency, this would have included the problem and possible solutions.",
"",
""
],
"button": "I Agree"
}
]
}
5 changes: 5 additions & 0 deletions tools/canary/canary.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"version": "0.1",
"alerts": [
]
}
1 change: 1 addition & 0 deletions tools/canary/canary.raw
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0xf86680808080809d7b2276657273696f6e223a22302e31222c22616c65727473223a5b5d7d1ba03f0e5fb1ee9adb9e689b0d1a5ad4566ea91915007b1c43ab59369c40cc82d26fa02a49304771de9f5777cd34cdc5e2098df3027f11f6c1019f00241bdef89f7765
48 changes: 48 additions & 0 deletions tools/canary/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/**
* Canary
*
* The canary file can be uploaded to https://ethers.io/canary.raw
* in the event a serious bug is discovered that users must be warned
* of.
*
* It must be signed with the private key for the address:
*
* 0x70C14080922f091fD7d0E891eB483C9f8464a527
*
* TODO: This needs to be updated to take a secure password from
* readlineSync rather than the command line.
*/

var crypto = require('crypto');
var fs = require('fs');

var Wallet = require('ethers-wallet');

var jsonFilename = process.argv[2];
var password = process.argv[3];
var canaryFilename = process.argv[4];

var canaryData = fs.readFileSync(canaryFilename);
canaryData = JSON.stringify(JSON.parse(canaryData));

var transaction = {
nonce: '0x00',
gasPrice: '0x00',
gasLimit: '0x00',
value: '0x00',
data: (new Buffer(canaryData)),
}


Wallet.decrypt(fs.readFileSync(jsonFilename), new Buffer(password)).then(function(wallet) {
var data = wallet.sign(transaction);
var hash = crypto.createHash('sha256').update(new Buffer(data.substring(2), 'hex')).digest()

console.log('Address: ' + wallet.address);
console.log('Hash: 0x' + hash.toString('hex'));
console.log('Filename: canary-' + hash.slice(0, 4).toString('hex') + '.hex');
console.log('Data: ' + data);

}, function(error) {
console.log(error);
});
14 changes: 14 additions & 0 deletions tools/canary/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"name": "ethers-canary",
"version": "0.0.1",
"description": "Script to generate and sign the https://ethers.io/canary.raw file.",
"main": "index.js",
"dependencies": {
"ethers-wallet": "1.0.10"
},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "Richard Moore <me@ricmoo.com>",
"license": "MIT"
}

0 comments on commit df8d88c

Please sign in to comment.