Move to new ripple-keypairs API

This commit is contained in:
Chris Clark
2015-09-22 15:31:10 -07:00
parent 7b5d6e9fc5
commit 715c648d52
14 changed files with 52 additions and 288 deletions

View File

@@ -481,7 +481,7 @@ describe('RippleAPI', function() {
function random() {
return _.fill(Array(16), 0);
}
assert.deepEqual(this.api.generateAddress({random}),
assert.deepEqual(this.api.generateAddress({entropy: random()}),
responses.generateAddress);
});

View File

@@ -1,46 +0,0 @@
/* eslint max-len: 0 */
/* eslint-disable max-nested-callbacks */
'use strict';
const assert = require('assert');
const Seed = require('ripple-lib').Seed;
describe('Seed', function() {
it('saESc82Vun7Ta5EJRzGJbrXb5HNYk', function() {
const seed = Seed.from_json('saESc82Vun7Ta5EJRzGJbrXb5HNYk');
assert.strictEqual(seed.to_hex(), 'FF1CF838D02B2CF7B45BAC27F5F24F4F');
});
it('can create ed25519 seeds from a phrase', function() {
const seed = Seed.from_json('phrase').set_ed25519().to_json();
assert.strictEqual(seed, 'sEdT7U4WpkoiH6wBoNeLzDi1eu9N64Y');
});
it('sp6iDHnmiPN7tQFHm5sCW59ax3hfE', function() {
const seed = Seed.from_json('sp6iDHnmiPN7tQFHm5sCW59ax3hfE');
assert.strictEqual(seed.to_hex(), '00AD8DA764C3C8AF5F9B8D51C94B9E49');
});
it('sp6iDHnmiPN7tQFHm5sCW59ax3hfE using parse_base58', function() {
const seed = new Seed().parse_base58('sp6iDHnmiPN7tQFHm5sCW59ax3hfE');
assert.strictEqual(seed.to_hex(), '00AD8DA764C3C8AF5F9B8D51C94B9E49');
});
it('parse_base58 should throw on non-string input', function() {
assert.throws(function() {
new Seed().parse_base58(1);
});
});
it('parse_base58 should make invalid seed from empty string', function() {
const seed = new Seed().parse_base58('');
assert(!seed.is_valid());
});
it('parse_base58 should make invalid seed from invalid input', function() {
const seed = new Seed().parse_base58('Xs');
assert(!seed.is_valid());
});
it('should return the key_pair for a valid account and secret pair', function() {
const address = 'r3GgMwvgvP8h4yVWvjH1dPZNvC37TjzBBE';
const seed = Seed.from_json('shsWGZcmZz6YsWWmcnpfr6fLTdtFV');
const keyPair = seed.get_key();
assert.strictEqual(keyPair.accountID(), address);
assert.strictEqual(keyPair.pubKeyHex(), '02F89EAEC7667B30F33D0687BBA86C3FE2A08CCA40A9186C5BDE2DAA6FA97A37D8');
});
});
// vim:sw=2:sts=2:ts=8:et

View File

@@ -1,62 +0,0 @@
'use strict';
const assert = require('assert');
const Seed = require('ripple-lib').Seed;
function _isNaN(n) {
return typeof n === 'number' && isNaN(n);
}
describe('Signing', function() {
describe('Keys', function() {
it('SigningPubKey 1 (ripple-client issue #245)', function() {
const seed = Seed.from_json('saESc82Vun7Ta5EJRzGJbrXb5HNYk');
const key = seed.get_key('rBZ4j6MsoctipM6GEyHSjQKzXG3yambDnZ');
const pub = key.pubKeyHex();
assert.strictEqual(
pub,
'0396941B22791A448E5877A44CE98434DB217D6FB97D63F0DAD23BE49ED45173C9');
});
it('SigningPubKey 2 (master seed)', function() {
const seed = Seed.from_json('snoPBrXtMeMyMHUVTgbuqAfg1SUTb');
const key = seed.get_key('rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh');
const pub = key.pubKeyHex();
assert.strictEqual(
pub,
'0330E7FC9D56BB25D6893BA3F317AE5BCF33B3291BD63DB32654A313222F7FD020');
});
});
describe('parse_json', function() {
it('empty string', function() {
assert(_isNaN(new Seed().parse_json('').to_json()));
});
it('hex string', function() {
// 32 0s is a valid hex repr of seed bytes
const str = new Array(33).join('0');
assert.strictEqual((new Seed().parse_json(str).to_json()),
'sp6JS7f14BuwFY8Mw6bTtLKWauoUs');
});
it('passphrase', function() {
const str = new Array(60).join('0');
assert.strictEqual('snFRPnVL3secohdpwSie8ANXdFQvG',
new Seed().parse_json(str).to_json());
});
it('null', function() {
assert(_isNaN(new Seed().parse_json(null).to_json()));
});
});
describe('parse_passphrase', function() {
it('invalid passphrase', function() {
assert.throws(function() {
new Seed().parse_passphrase(null);
});
});
});
describe('get_key', function() {
it('get key from invalid seed', function() {
assert.throws(function() {
new Seed().get_key('rBZ4j6MsoctipM6GEyHSjQKzXG3yambDnZ');
});
});
});
});

View File

@@ -2,8 +2,9 @@
'use strict';
const assert = require('assert');
const assert = require('assert-diff');
const lodash = require('lodash');
const addresses = require('./fixtures/addresses');
const ripple = require('ripple-lib');
const Transaction = require('ripple-lib').Transaction;
const TransactionQueue = require('ripple-lib').TransactionQueue;
@@ -340,7 +341,7 @@ describe('Transaction', function() {
const dst = 'rGihwhaqU8g7ahwAvTq6iX5rvsfcbgZw6v';
transaction.payment(src, dst, '100');
remote.setSecret(src, 'masterpassphrase');
remote.setSecret(src, addresses.SECRET);
assert(transaction.complete());
const json = transaction.serialize().to_json();
@@ -2278,20 +2279,19 @@ describe('Transaction', function() {
const a1 = 'rPMh7Pi9ct699iZUTWaytJUoHcJ7cgyziK';
const a2 = 'rH4KEcG9dEwGwpn6AyoWK9cZPLL4RLSmWW';
const s1 = t1.multiSign(a1, 'alice');
const s1 = t1.multiSign(a1, addresses.SECRET);
assert.deepEqual(s1, {
Account: 'rPMh7Pi9ct699iZUTWaytJUoHcJ7cgyziK',
TxnSignature: '3045022100DB13DC794DDFA1E27D099CDBFC7DB5B1EE892AD1725B0CEEE97D8B1C4C2055C7022030B3372C96D08106594B3CF8CDF88E05CC6260C51954F02387289CB69B839D7A',
SigningPubKey: '0388935426E0D08083314842EDFBB2D517BD47699F9A4527318A8E10468C97C052'
TxnSignature: '30440220613DF9410B4844C7FAB637FD707F5185A2107DD10D0C2F59155844CD1910AB99022004A2AE607C15DD0959FDB3AAEE6A0337AA5337515230CE6EC11E32B74EEE896E',
SigningPubKey: '02F89EAEC7667B30F33D0687BBA86C3FE2A08CCA40A9186C5BDE2DAA6FA97A37D8'
});
const s2 = t1.multiSign(a2, 'bob');
const s2 = t1.multiSign(a2, addresses.SECRET);
assert.deepEqual(s2, {
Account: 'rH4KEcG9dEwGwpn6AyoWK9cZPLL4RLSmWW',
TxnSignature: '304402207A22109088069C5ABE3E961C2F85B2B8111C5666C869E8BA3F2A57C2ECEA7FC402205F9D87FB42266CC498FCE9B4904955D0E6D5F44D092596F5DE3E25843F6D10AB',
SigningPubKey: '02691AC5AE1C4C333AE5DF8A93BDC495F0EEBFC6DB0DA7EB6EF808F3AFC006E3FE'
TxnSignature: '3044022011762BC175E166EF540ABB162F0E8B48250E7C95DE5E8464E3F648EAF9A94A50022022439146DC3C6BB943C719F89696E7EBED14888A653F4618F62F8DA5CE202A45',
SigningPubKey: '02F89EAEC7667B30F33D0687BBA86C3FE2A08CCA40A9186C5BDE2DAA6FA97A37D8'
});
transaction.addMultiSigner(s1);