Browse Source

Armory: cleaned up example

patch-2
olalonde 11 years ago
parent
commit
fa211f98bb
  1. 35
      examples/Armory.js
  2. 9
      lib/Armory.js

35
examples/Armory.js

@ -1,42 +1,33 @@
var Armory = require('../lib/Armory');
var Address = require('../lib/Address');
var Point = require('../lib/Point');
var bignum = require('bignum');
var Key = require('../lib/Key');
// Chain code can be generated from paper backup
// on brainwallet.org/#chains
//
// Paper backup used for testing:
//
// aagh hjfj sihk ietj giik wwai awtd uodh hnji
// soss uaku egod utai itos fijj ihgi jhau jtoo
var chaincode = '84ac14bc4b388b33da099a0b4ee3b507284d99e1476639e36e5ca5e6af86481e';
// Initial public key can be retrieved from paper backup
//var PublicX = '9df5 23e7 18b9 1f59 a790 2d46 999f 9357 ccf8 7208 24d4 3076 4516 b809 f7ab ce4e'
//var PublicY = '66ba 5d21 4682 0dae 401d 9506 8437 2516 79f9 0c56 4186 cc50 07df c6d0 6989 1ff4';
//var pubkey = '04' + PublicX.split(' ').join('') + PublicY.split(' ').join('');
//console.log(pubkey);
var PublicX = '9df5 23e7 18b9 1f59 a790 2d46 999f 9357 ccf8 7208 24d4 3076 4516 b809 f7ab ce4e';
var PublicY = '66ba 5d21 4682 0dae 401d 9506 8437 2516 79f9 0c56 4186 cc50 07df c6d0 6989 1ff4';
var pubkey = '04' + PublicX.split(' ').join('') + PublicY.split(' ').join('');
// mmm... can't figure out how to arrive at same pubkey as brainwallet
var pubkey = '045a09a3286873a72f164476bde9d1d8e5c2bc044e35aa47eb6e798e325a86417f7c35b61d9905053533e0b4f2a26eca0330aadf21c638969e45aaace50e4c0c87';
// Chain code can be generated by entering paper backup
// on brainwallet.org/#chains or by using Armory.fromSeed() below
var chaincode = '84ac14bc4b388b33da099a0b4ee3b507284d99e1476639e36e5ca5e6af86481e';
var armory = new Armory(chaincode, pubkey);
var pubkey;
for (var i = 0; i < 5; i++) {
armory = armory.next();
console.log(Address.fromPubKey(armory.pubkey).as('base58'));
armory = armory.next();
}
// Derive stuff from root cod
// Derive first public key and chain code from seed
var seed = [
'aagh hjfj sihk ietj giik wwai awtd uodh hnji',
'soss uaku egod utai itos fijj ihgi jhau jtoo'
].join('\n');
console.log(seed);
console.log(Armory.fromSeed(seed));
var a = Armory.fromSeed(seed);
console.log(Address.fromPubKey(a.next().pubkey).as('base58'));

9
lib/Armory.js

@ -1,4 +1,5 @@
var Point = require('./browser/Point'),
Key = require('./Key'),
buffertools = require('buffertools'),
sha256 = require('../util').sha256,
twoSha256 = require('../util').twoSha256,
@ -73,7 +74,13 @@ Armory.decodeSeed = function (seed) {
// Derive chain code from root key
Armory.fromSeed = function (seed) {
var res = Armory.decodeSeed(seed);
return res;
// generate first public key
var key = new Key();
key.private = res.privKey;
key.compressed = false;
key.regenerateSync();
return new Armory(res.chainCode, key.public);
};
Armory.deriveChaincode = function (root) {

Loading…
Cancel
Save