mirror of
https://github.com/Xahau/xahau.js.git
synced 2025-11-20 04:05:52 +00:00
Add nodePublicAccountID
This commit is contained in:
@@ -63,4 +63,6 @@ Ed25519Pair.prototype.verify = function(message, signature) {
|
||||
return this.key().verify(message, signature);
|
||||
};
|
||||
|
||||
module.exports = Ed25519Pair;
|
||||
module.exports = {
|
||||
Ed25519Pair
|
||||
};
|
||||
|
||||
@@ -6,8 +6,8 @@ const rand = require('brorand');
|
||||
|
||||
const {seedFromPhrase, createAccountID} = require('./utils');
|
||||
const {KeyPair, KeyType} = require('./keypair');
|
||||
const Ed25519Pair = require('./ed25519');
|
||||
const K256Pair = require('./secp256k1');
|
||||
const {Ed25519Pair} = require('./ed25519');
|
||||
const {K256Pair, accountPublicFromGenerator} = require('./secp256k1');
|
||||
|
||||
KeyPair.fromSeed = function(seedBytes, type, options) {
|
||||
assert(type === 'secp256k1' || type === 'ed25519');
|
||||
@@ -54,6 +54,12 @@ function generateValidatorKeys(opts={}) {
|
||||
return deriveValidator(randGen(16));
|
||||
}
|
||||
|
||||
function nodePublicAccountID(publicKey) {
|
||||
const genBytes = codec.decodeNodePublic(publicKey);
|
||||
const accountPublicBytes = accountPublicFromGenerator(genBytes);
|
||||
return codec.encodeAccountID(createAccountID(accountPublicBytes));
|
||||
}
|
||||
|
||||
function validatorKeysFromSeed(seed) {
|
||||
const {type, bytes} = codec.decodeSeed(seed);
|
||||
assert(type === KeyType.secp256k1);
|
||||
@@ -71,5 +77,6 @@ module.exports = {
|
||||
generateWallet,
|
||||
generateValidatorKeys,
|
||||
walletFromSeed,
|
||||
validatorKeysFromSeed
|
||||
validatorKeysFromSeed,
|
||||
nodePublicAccountID
|
||||
};
|
||||
|
||||
@@ -57,6 +57,14 @@ function deriveSecret(seed, opts={}) {
|
||||
.add(privateGen).mod(order);
|
||||
}
|
||||
|
||||
function accountPublicFromGenerator(publicGenBytes) {
|
||||
const rootPubPoint = secp256k1.curve.decodePoint(publicGenBytes);
|
||||
const scalar = deriveScalar(publicGenBytes, 0);
|
||||
const point = secp256k1.g.mul(scalar);
|
||||
const offset = rootPubPoint.add(point);
|
||||
return offset.encodeCompressed();
|
||||
}
|
||||
|
||||
/*
|
||||
* @class
|
||||
*/
|
||||
@@ -116,4 +124,7 @@ K256Pair.prototype.verify = function(message, signature) {
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = K256Pair;
|
||||
module.exports = {
|
||||
K256Pair,
|
||||
accountPublicFromGenerator
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user