mirror of
https://github.com/Xahau/xahau.js.git
synced 2025-11-20 12:15:51 +00:00
Tweak README and accountPublicFromPublicGenerator
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
# ripple-keypairs
|
# ripple-keypairs
|
||||||
|
|
||||||
[](https://npmjs.org/package/ripple-keypairs) [](https://travis-ci.org/sublimator/ripple-keypairs) [](https://coveralls.io/github/sublimator/ripple-keypairs?branch=master)
|
[](https://npmjs.org/package/ripple-keypairs) [](https://travis-ci.org/sublimator/ripple-keypairs) [](https://coveralls.io/github/sublimator/ripple-keypairs?branch=master)
|
||||||
|
|
||||||
An implementation of ripple keypairs & wallet generation using
|
An implementation of ripple keypairs & wallet generation using
|
||||||
[elliptic](https://github.com/indutny/elliptic) which supports rfc6979 and
|
[elliptic](https://github.com/indutny/elliptic) which supports rfc6979 and
|
||||||
|
|||||||
@@ -1,13 +1,15 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
const assert = require('assert');
|
const assert = require('assert');
|
||||||
const codec = require('ripple-address-codec');
|
|
||||||
const rand = require('brorand');
|
const rand = require('brorand');
|
||||||
|
|
||||||
const {seedFromPhrase, createAccountID} = require('./utils');
|
const {seedFromPhrase, createAccountID} = require('./utils');
|
||||||
const {KeyPair, KeyType} = require('./keypair');
|
const {KeyPair, KeyType} = require('./keypair');
|
||||||
const {Ed25519Pair} = require('./ed25519');
|
const {Ed25519Pair} = require('./ed25519');
|
||||||
const {K256Pair, accountPublicFromGenerator} = require('./secp256k1');
|
const {K256Pair, accountPublicFromPublicGenerator} = require('./secp256k1');
|
||||||
|
|
||||||
|
const {decodeSeed, encodeNodePublic, decodeNodePublic, encodeAccountID} =
|
||||||
|
require('ripple-address-codec');
|
||||||
|
|
||||||
KeyPair.fromSeed = function(seedBytes, type, options) {
|
KeyPair.fromSeed = function(seedBytes, type, options) {
|
||||||
assert(type === 'secp256k1' || type === 'ed25519');
|
assert(type === 'secp256k1' || type === 'ed25519');
|
||||||
@@ -16,7 +18,7 @@ KeyPair.fromSeed = function(seedBytes, type, options) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
function keyPairFromSeed(seedString, options) {
|
function keyPairFromSeed(seedString, options) {
|
||||||
const decoded = codec.decodeSeed(seedString);
|
const decoded = decodeSeed(seedString);
|
||||||
return KeyPair.fromSeed(decoded.bytes, decoded.type, options);
|
return KeyPair.fromSeed(decoded.bytes, decoded.type, options);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -37,7 +39,7 @@ function generateWallet(opts={}) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function walletFromSeed(seed) {
|
function walletFromSeed(seed) {
|
||||||
const {type, bytes} = codec.decodeSeed(seed);
|
const {type, bytes} = decodeSeed(seed);
|
||||||
return deriveWallet(type, bytes);
|
return deriveWallet(type, bytes);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -45,7 +47,7 @@ function deriveValidator(seedBytes) {
|
|||||||
const pair = K256Pair.fromSeed(seedBytes, {validator: true});
|
const pair = K256Pair.fromSeed(seedBytes, {validator: true});
|
||||||
return {
|
return {
|
||||||
seed: pair.seed(),
|
seed: pair.seed(),
|
||||||
publicKey: codec.encodeNodePublic(pair.pubKeyCanonicalBytes())
|
publicKey: encodeNodePublic(pair.pubKeyCanonicalBytes())
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -55,13 +57,13 @@ function generateValidatorKeys(opts={}) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function nodePublicAccountID(publicKey) {
|
function nodePublicAccountID(publicKey) {
|
||||||
const genBytes = codec.decodeNodePublic(publicKey);
|
const generatorBytes = decodeNodePublic(publicKey);
|
||||||
const accountPublicBytes = accountPublicFromGenerator(genBytes);
|
const accountPublicBytes = accountPublicFromPublicGenerator(generatorBytes);
|
||||||
return codec.encodeAccountID(createAccountID(accountPublicBytes));
|
return encodeAccountID(createAccountID(accountPublicBytes));
|
||||||
}
|
}
|
||||||
|
|
||||||
function validatorKeysFromSeed(seed) {
|
function validatorKeysFromSeed(seed) {
|
||||||
const {type, bytes} = codec.decodeSeed(seed);
|
const {type, bytes} = decodeSeed(seed);
|
||||||
assert(type === KeyType.secp256k1);
|
assert(type === KeyType.secp256k1);
|
||||||
return deriveValidator(bytes);
|
return deriveValidator(bytes);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -57,7 +57,7 @@ function deriveSecret(seed, opts={}) {
|
|||||||
.add(privateGen).mod(order);
|
.add(privateGen).mod(order);
|
||||||
}
|
}
|
||||||
|
|
||||||
function accountPublicFromGenerator(publicGenBytes) {
|
function accountPublicFromPublicGenerator(publicGenBytes) {
|
||||||
const rootPubPoint = secp256k1.curve.decodePoint(publicGenBytes);
|
const rootPubPoint = secp256k1.curve.decodePoint(publicGenBytes);
|
||||||
const scalar = deriveScalar(publicGenBytes, 0);
|
const scalar = deriveScalar(publicGenBytes, 0);
|
||||||
const point = secp256k1.g.mul(scalar);
|
const point = secp256k1.g.mul(scalar);
|
||||||
@@ -126,5 +126,5 @@ K256Pair.prototype.verify = function(message, signature) {
|
|||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
K256Pair,
|
K256Pair,
|
||||||
accountPublicFromGenerator
|
accountPublicFromPublicGenerator
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user