ripple-binary-codec
Advanced tools
Comparing version 1.0.2 to 1.0.3
@@ -15,2 +15,3 @@ "use strict"; | ||
Object.defineProperty(exports, "transactionID", { enumerable: true, get: function () { return hashes_1.transactionID; } }); | ||
var bigInt = require("big-integer"); | ||
/** | ||
@@ -85,5 +86,6 @@ * Construct a BinaryParser | ||
function signingClaimData(claim) { | ||
var num = bigInt(String(claim.amount)); | ||
var prefix = hash_prefixes_1.HashPrefix.paymentChannelClaim; | ||
var channel = types_1.coreTypes.Hash256.from(claim.channel).toBytes(); | ||
var amount = types_1.coreTypes.UInt64.from(BigInt(claim.amount)).toBytes(); | ||
var amount = types_1.coreTypes.UInt64.from(num).toBytes(); | ||
var bytesList = new binary_serializer_1.BytesList(); | ||
@@ -90,0 +92,0 @@ bytesList.put(prefix); |
import { Hash256 } from "./types/hash-256"; | ||
import { JsonObject } from "./types/serialized-type"; | ||
import * as bigInt from "big-integer"; | ||
/** | ||
@@ -22,3 +23,3 @@ * Function computing the hash of a transaction tree | ||
ledger_index: number; | ||
total_coins: string | number | bigint; | ||
total_coins: string | number | bigInt.BigInteger; | ||
parent_hash: string; | ||
@@ -25,0 +26,0 @@ transaction_hash: string; |
@@ -15,2 +15,3 @@ "use strict"; | ||
var binary_parser_1 = require("./serdes/binary-parser"); | ||
var bigInt = require("big-integer"); | ||
/** | ||
@@ -102,3 +103,3 @@ * Computes the hash of a list of objects | ||
uint_32_1.UInt32.from(header.ledger_index).toBytesSink(hash); | ||
uint_64_1.UInt64.from(BigInt(header.total_coins)).toBytesSink(hash); | ||
uint_64_1.UInt64.from(bigInt(String(header.total_coins))).toBytesSink(hash); | ||
hash_256_1.Hash256.from(header.parent_hash).toBytesSink(hash); | ||
@@ -105,0 +106,0 @@ hash_256_1.Hash256.from(header.transaction_hash).toBytesSink(hash); |
@@ -6,2 +6,3 @@ "use strict"; | ||
var decimal_js_1 = require("decimal.js"); | ||
var bigInt = require("big-integer"); | ||
/** | ||
@@ -23,3 +24,3 @@ * class for encoding and decoding quality | ||
var qualityString = decimal.times("1e" + -exponent).abs().toString(); | ||
var bytes = types_1.coreTypes.UInt64.from(BigInt(qualityString)).toBytes(); | ||
var bytes = types_1.coreTypes.UInt64.from(bigInt(qualityString)).toBytes(); | ||
bytes[0] = exponent + 100; | ||
@@ -26,0 +27,0 @@ return bytes; |
@@ -22,2 +22,3 @@ "use strict"; | ||
var serialized_type_1 = require("./serialized-type"); | ||
var bigInt = require("big-integer"); | ||
/** | ||
@@ -31,2 +32,3 @@ * Constants for validating amounts | ||
var MIN_XRP = new decimal_js_1.Decimal("1e-6"); | ||
var mask = bigInt(0x00000000ffffffff); | ||
/** | ||
@@ -71,4 +73,7 @@ * decimal.js configuration for Amount IOUs | ||
Amount.assertXrpIsValid(value); | ||
var number = BigInt(value); | ||
amount.writeBigUInt64BE(number); | ||
var number = bigInt(value); | ||
var intBuf = [Buffer.alloc(4), Buffer.alloc(4)]; | ||
intBuf[0].writeUInt32BE(Number(number.shiftRight(32))); | ||
intBuf[1].writeUInt32BE(Number(number.and(mask))); | ||
amount = Buffer.concat(intBuf); | ||
amount[0] |= 0x40; | ||
@@ -88,3 +93,7 @@ return new Amount(amount); | ||
.toString(); | ||
amount.writeBigUInt64BE(BigInt(integerNumberString)); | ||
var num = bigInt(integerNumberString); | ||
var intBuf = [Buffer.alloc(4), Buffer.alloc(4)]; | ||
intBuf[0].writeUInt32BE(Number(num.shiftRight(32))); | ||
intBuf[1].writeUInt32BE(Number(num.and(mask))); | ||
amount = Buffer.concat(intBuf); | ||
amount[0] |= 0x80; | ||
@@ -127,3 +136,6 @@ if (number.gt(new decimal_js_1.Decimal(0))) { | ||
bytes[0] &= 0x3f; | ||
return "" + sign + bytes.readBigUInt64BE().toString(); | ||
var msb = bigInt(bytes.slice(0, 4).readUInt32BE()); | ||
var lsb = bigInt(bytes.slice(4).readUInt32BE()); | ||
var num = msb.shiftLeft(32).or(lsb); | ||
return "" + sign + num.toString(); | ||
} | ||
@@ -130,0 +142,0 @@ else { |
/// <reference types="node" /> | ||
import { BytesList } from "../serdes/binary-serializer"; | ||
import { BinaryParser } from "../serdes/binary-parser"; | ||
import * as bigInt from "big-integer"; | ||
declare type JSON = string | number | boolean | null | undefined | JSON[] | JsonObject; | ||
@@ -15,3 +16,3 @@ declare type JsonObject = { | ||
static fromParser(parser: BinaryParser, hint?: number): SerializedType; | ||
static from(value: SerializedType | JSON | bigint): SerializedType; | ||
static from(value: SerializedType | JSON | bigInt.BigInteger): SerializedType; | ||
/** | ||
@@ -18,0 +19,0 @@ * Write the bytes representation of a SerializedType to a BytesList |
/// <reference types="node" /> | ||
import { UInt } from "./uint"; | ||
import { BinaryParser } from "../serdes/binary-parser"; | ||
import * as bigInt from "big-integer"; | ||
/** | ||
@@ -15,6 +16,6 @@ * Derived UInt class for serializing/deserializing 64 bit UInt | ||
* | ||
* @param val A UInt64, hex-string, bigint, or number | ||
* @param val A UInt64, hex-string, bigInt, or number | ||
* @returns A UInt64 object | ||
*/ | ||
static from<T extends UInt64 | string | bigint | number>(val: T): UInt64; | ||
static from<T extends UInt64 | string | bigInt.BigInteger | number>(val: T): UInt64; | ||
/** | ||
@@ -31,3 +32,3 @@ * The JSON representation of a UInt64 object | ||
*/ | ||
valueOf(): bigint; | ||
valueOf(): bigInt.BigInteger; | ||
/** | ||
@@ -34,0 +35,0 @@ * Get the bytes representation of the UInt64 object |
@@ -18,3 +18,6 @@ "use strict"; | ||
var uint_1 = require("./uint"); | ||
var bigInt = require("big-integer"); | ||
var big_integer_1 = require("big-integer"); | ||
var HEX_REGEX = /^[A-F0-9]{16}$/; | ||
var mask = bigInt(0x00000000ffffffff); | ||
/** | ||
@@ -34,3 +37,3 @@ * Derived UInt class for serializing/deserializing 64 bit UInt | ||
* | ||
* @param val A UInt64, hex-string, bigint, or number | ||
* @param val A UInt64, hex-string, bigInt, or number | ||
* @returns A UInt64 object | ||
@@ -47,4 +50,7 @@ */ | ||
} | ||
buf.writeBigUInt64BE(BigInt(val)); | ||
return new UInt64(buf); | ||
var number = bigInt(val); | ||
var intBuf = [Buffer.alloc(4), Buffer.alloc(4)]; | ||
intBuf[0].writeUInt32BE(Number(number.shiftRight(32))); | ||
intBuf[1].writeUInt32BE(Number(number.and(mask))); | ||
return new UInt64(Buffer.concat(intBuf)); | ||
} | ||
@@ -58,5 +64,7 @@ if (typeof val === "string") { | ||
} | ||
if (typeof val === "bigint") { | ||
buf.writeBigUInt64BE(val); | ||
return new UInt64(buf); | ||
if (big_integer_1.isInstance(val)) { | ||
var intBuf = [Buffer.alloc(4), Buffer.alloc(4)]; | ||
intBuf[0].writeUInt32BE(Number(val.shiftRight(bigInt(32)))); | ||
intBuf[1].writeUInt32BE(Number(val.and(mask))); | ||
return new UInt64(Buffer.concat(intBuf)); | ||
} | ||
@@ -79,3 +87,5 @@ throw new Error("Cannot construct UInt64 from given value"); | ||
UInt64.prototype.valueOf = function () { | ||
return this.bytes.readBigUInt64BE(); | ||
var msb = bigInt(this.bytes.slice(0, 4).readUInt32BE()); | ||
var lsb = bigInt(this.bytes.slice(4).readUInt32BE()); | ||
return msb.shiftLeft(bigInt(32)).or(lsb); | ||
}; | ||
@@ -82,0 +92,0 @@ /** |
/// <reference types="node" /> | ||
import * as bigInt from "big-integer"; | ||
import { Comparable } from "./serialized-type"; | ||
@@ -27,4 +28,4 @@ /** | ||
*/ | ||
abstract valueOf(): number | bigint; | ||
abstract valueOf(): number | bigInt.BigInteger; | ||
} | ||
export { UInt }; |
@@ -19,3 +19,3 @@ "use strict"; | ||
/** | ||
* Compare numbers and bigints n1 and n2 | ||
* Compare numbers and bigInts n1 and n2 | ||
* | ||
@@ -22,0 +22,0 @@ * @param n1 First object to compare |
{ | ||
"name": "ripple-binary-codec", | ||
"version": "1.0.2", | ||
"version": "1.0.3", | ||
"description": "XRP Ledger binary codec", | ||
@@ -15,2 +15,3 @@ "files": [ | ||
"dependencies": { | ||
"big-integer": "^1.6.48", | ||
"create-hash": "^1.2.0", | ||
@@ -17,0 +18,0 @@ "decimal.js": "^10.2.0", |
@@ -8,2 +8,3 @@ /* eslint-disable func-style */ | ||
const { UInt8, UInt16, UInt32, UInt64, STObject } = coreTypes; | ||
const bigInt = require("big-integer"); | ||
@@ -166,3 +167,3 @@ const { loadFixture } = require("./utils"); | ||
check(UInt64, 1, [0, 0, 0, 0, 0, 0, 0, 1]); | ||
check(UInt64, BigInt(1), [0, 0, 0, 0, 0, 0, 0, 1]); | ||
check(UInt64, bigInt(1), [0, 0, 0, 0, 0, 0, 0, 1]); | ||
@@ -169,0 +170,0 @@ function deliverMinTest() { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1078623
16510
4
+ Addedbig-integer@^1.6.48
+ Addedbig-integer@1.6.52(transitive)