mirror of
https://github.com/Xahau/xahau.js.git
synced 2025-11-20 12:15:51 +00:00
Add encodeQuality/decodeQuality
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "ripple-binary-codec",
|
"name": "ripple-binary-codec",
|
||||||
"version": "0.0.2",
|
"version": "0.0.3",
|
||||||
"description": "ripple binary codec",
|
"description": "ripple binary codec",
|
||||||
"files": [
|
"files": [
|
||||||
"distrib/npm/*",
|
"distrib/npm/*",
|
||||||
@@ -14,7 +14,7 @@
|
|||||||
"test": "test"
|
"test": "test"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@niq/ripple-core-types": "0.0.3"
|
"@niq/ripple-core": "0.0.6"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"assert-diff": "^1.0.1",
|
"assert-diff": "^1.0.1",
|
||||||
|
|||||||
@@ -1,8 +1,9 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
const assert = require('assert');
|
const assert = require('assert');
|
||||||
const coreTypes = require('@niq/ripple-core-types');
|
const coreTypes = require('@niq/ripple-core');
|
||||||
const {binary: {bytesToHex,
|
const {quality,
|
||||||
|
binary: {bytesToHex,
|
||||||
signingData,
|
signingData,
|
||||||
multiSigningData,
|
multiSigningData,
|
||||||
binaryToJSON,
|
binaryToJSON,
|
||||||
@@ -27,3 +28,13 @@ exports.encodeForMultisigning = function(json, signer) {
|
|||||||
assert(typeof json === 'object');
|
assert(typeof json === 'object');
|
||||||
return bytesToHex(multiSigningData(json, signer));
|
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();
|
||||||
|
};
|
||||||
|
|||||||
18
packages/ripple-binary-codec/test/quality-test.js
Normal file
18
packages/ripple-binary-codec/test/quality-test.js
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
const assert = require('assert-diff');
|
||||||
|
const {encodeQuality, decodeQuality} = require('../src');
|
||||||
|
|
||||||
|
describe('Quality encode/decode', function() {
|
||||||
|
const bookDirectory =
|
||||||
|
'4627DFFCFF8B5A265EDBD8AE8C14A52325DBFEDAF4F5C32E5D06F4C3362FE1D0';
|
||||||
|
const expectedQuality = '195796912.5171664';
|
||||||
|
it('can decode', function() {
|
||||||
|
const decimal = decodeQuality(bookDirectory);
|
||||||
|
assert.equal(decimal, expectedQuality);
|
||||||
|
});
|
||||||
|
it('can encode', function() {
|
||||||
|
const hex = encodeQuality(expectedQuality);
|
||||||
|
assert.equal(hex, bookDirectory.slice(-16));
|
||||||
|
});
|
||||||
|
});
|
||||||
Reference in New Issue
Block a user