Files
xahau.js/packages/ripple-binary-codec/src/index.js
2015-10-07 16:26:39 +07:00

41 lines
1.0 KiB
JavaScript

'use strict';
const assert = require('assert');
const coreTypes = require('@niq/ripple-core');
const {quality,
binary: {bytesToHex,
signingData,
multiSigningData,
binaryToJSON,
serializeObject}} = coreTypes;
exports.decode = function(binary) {
assert(typeof binary === 'string', 'binary must be a hex string');
return binaryToJSON(binary);
};
exports.encode = function(json) {
assert(typeof json === 'object');
return bytesToHex(serializeObject(json));
};
exports.encodeForSigning = function(json) {
assert(typeof json === 'object');
return bytesToHex(signingData(json));
};
exports.encodeForMultisigning = function(json, signer) {
assert(typeof json === 'object');
return bytesToHex(multiSigningData(json, signer));
};
exports.encodeQuality = function(value) {
assert(typeof value === 'string');
return bytesToHex(quality.encode(value));
};
exports.decodeQuality = function(value) {
assert(typeof value === 'string');
return quality.decode(value).toString();
};