mirror of
https://github.com/Xahau/xahau.js.git
synced 2025-11-20 12:15:51 +00:00
Remove unused 'signing' code (#34)
Use ripple-keypairs library for signing
This commit is contained in:
@@ -7,7 +7,6 @@ const {ShaMap} = require('./shamap');
|
||||
const ledgerHashes = require('./ledger-hashes');
|
||||
const hashes = require('./hashes');
|
||||
const quality = require('./quality');
|
||||
const signing = require('./signing');
|
||||
const {HashPrefix} = require('./hash-prefixes');
|
||||
|
||||
|
||||
@@ -15,7 +14,6 @@ module.exports = _.assign({
|
||||
hashes: _.assign({}, hashes, ledgerHashes),
|
||||
binary,
|
||||
enums,
|
||||
signing,
|
||||
quality,
|
||||
Field,
|
||||
HashPrefix,
|
||||
|
||||
@@ -1,66 +0,0 @@
|
||||
/* eslint-disable func-style */
|
||||
|
||||
const _ = require('lodash');
|
||||
const {AccountID} = require('./types');
|
||||
const binary = require('./binary');
|
||||
const {
|
||||
serializeObject,
|
||||
bytesToHex,
|
||||
multiSigningData,
|
||||
transactionID,
|
||||
signingData
|
||||
} = binary;
|
||||
|
||||
const FULL_CANONICAL_SIGNATURE = 0x80000000;
|
||||
|
||||
const toHex = v => bytesToHex(v);
|
||||
const getSigner = o => AccountID.from(o.Signer.Account);
|
||||
const signerComparator = (a, b) => getSigner(a).compareTo(getSigner(b));
|
||||
|
||||
function setCanonicalSignatureFlag(tx_json) {
|
||||
tx_json.Flags |= FULL_CANONICAL_SIGNATURE;
|
||||
tx_json.Flags >>>= 0;
|
||||
}
|
||||
|
||||
function serializedBundle(tx_json) {
|
||||
const serialized = serializeObject(tx_json);
|
||||
const hash = transactionID(serialized).toHex();
|
||||
const tx_blob = toHex(serialized);
|
||||
return {tx_json, tx_blob, hash};
|
||||
}
|
||||
|
||||
function signFor(tx_json_, keyPair, signingAccount = null) {
|
||||
const tx_json = _.clone(tx_json_);
|
||||
tx_json.SigningPubKey = '';
|
||||
setCanonicalSignatureFlag(tx_json);
|
||||
const signerID = signingAccount || keyPair.id();
|
||||
const signature = keyPair.sign(multiSigningData(tx_json, signerID));
|
||||
const signer = {
|
||||
Signer: {
|
||||
SigningPubKey: toHex(keyPair.publicBytes()),
|
||||
TxnSignature: toHex(signature),
|
||||
Account: signerID
|
||||
}
|
||||
};
|
||||
|
||||
const signers = tx_json.Signers = tx_json.Signers || [];
|
||||
signers.push(signer);
|
||||
signers.sort(signerComparator);
|
||||
|
||||
return serializedBundle(tx_json);
|
||||
}
|
||||
|
||||
function sign(tx_json_, keyPair) {
|
||||
const tx_json = _.clone(tx_json_);
|
||||
setCanonicalSignatureFlag(tx_json);
|
||||
|
||||
tx_json.SigningPubKey = toHex(keyPair.publicBytes());
|
||||
tx_json.TxnSignature = toHex(keyPair.sign(signingData(tx_json)));
|
||||
|
||||
return serializedBundle(tx_json);
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
signFor,
|
||||
sign
|
||||
};
|
||||
Reference in New Issue
Block a user