diff --git a/packages/ripple-binary-codec/src/coretypes.js b/packages/ripple-binary-codec/src/coretypes.js index 0e9f88e1..29b84c06 100644 --- a/packages/ripple-binary-codec/src/coretypes.js +++ b/packages/ripple-binary-codec/src/coretypes.js @@ -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, diff --git a/packages/ripple-binary-codec/src/signing.js b/packages/ripple-binary-codec/src/signing.js deleted file mode 100644 index 29e0944b..00000000 --- a/packages/ripple-binary-codec/src/signing.js +++ /dev/null @@ -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 -};