ripple-binary-codec
Advanced tools
Comparing version 1.1.3 to 1.2.0-beta.1
@@ -43,3 +43,4 @@ { | ||
"Contract": 99, | ||
"GeneratorMap": 103, | ||
"NFTokenPage": 80, | ||
"NFTokenOffer": 55, | ||
"NegativeUNL": 78 | ||
@@ -99,2 +100,12 @@ }, | ||
[ | ||
"TransferFee", | ||
{ | ||
"nth": 4, | ||
"isVLEncoded": false, | ||
"isSerialized": true, | ||
"isSigningField": true, | ||
"type": "UInt16" | ||
} | ||
], | ||
[ | ||
"Flags", | ||
@@ -630,2 +641,12 @@ { | ||
[ | ||
"TokenID", | ||
{ | ||
"nth": 10, | ||
"isVLEncoded": false, | ||
"isSerialized": true, | ||
"isSigningField": true, | ||
"type": "Hash256" | ||
} | ||
], | ||
[ | ||
"BookDirectory", | ||
@@ -901,3 +922,3 @@ { | ||
[ | ||
"Generator", | ||
"URI", | ||
{ | ||
@@ -1142,2 +1163,12 @@ "nth": 5, | ||
[ | ||
"Minter", | ||
{ | ||
"nth": 9, | ||
"isVLEncoded": true, | ||
"isSerialized": true, | ||
"isSigningField": true, | ||
"type": "AccountID" | ||
} | ||
], | ||
[ | ||
"ObjectEndMarker", | ||
@@ -1253,2 +1284,12 @@ { | ||
[ | ||
"NonFungibleToken", | ||
{ | ||
"nth": 12, | ||
"isVLEncoded": false, | ||
"isSerialized": true, | ||
"isSigningField": true, | ||
"type": "STObject" | ||
} | ||
], | ||
[ | ||
"Signer", | ||
@@ -1364,2 +1405,12 @@ { | ||
[ | ||
"NonFungibleTokens", | ||
{ | ||
"nth": 10, | ||
"isVLEncoded": false, | ||
"isSerialized": true, | ||
"isSigningField": true, | ||
"type": "STArray" | ||
} | ||
], | ||
[ | ||
"Majorities", | ||
@@ -1495,2 +1546,12 @@ { | ||
[ | ||
"TokenIDs", | ||
{ | ||
"nth": 4, | ||
"isVLEncoded": true, | ||
"isSerialized": true, | ||
"isSigningField": true, | ||
"type": "Vector256" | ||
} | ||
], | ||
[ | ||
"Transaction", | ||
@@ -1566,2 +1627,32 @@ { | ||
[ | ||
"TokenTaxon", | ||
{ | ||
"nth": 42, | ||
"isVLEncoded": false, | ||
"isSerialized": true, | ||
"isSigningField": true, | ||
"type": "UInt32" | ||
} | ||
], | ||
[ | ||
"MintedTokens", | ||
{ | ||
"nth": 43, | ||
"isVLEncoded": false, | ||
"isSerialized": true, | ||
"isSigningField": true, | ||
"type": "UInt32" | ||
} | ||
], | ||
[ | ||
"BurnedTokens", | ||
{ | ||
"nth": 44, | ||
"isVLEncoded": false, | ||
"isSerialized": true, | ||
"isSigningField": true, | ||
"type": "UInt32" | ||
} | ||
], | ||
[ | ||
"Channel", | ||
@@ -1597,2 +1688,52 @@ { | ||
[ | ||
"ValidatedHash", | ||
{ | ||
"nth": 25, | ||
"isVLEncoded": false, | ||
"isSerialized": true, | ||
"isSigningField": true, | ||
"type": "Hash256" | ||
} | ||
], | ||
[ | ||
"PreviousPageMin", | ||
{ | ||
"nth": 26, | ||
"isVLEncoded": false, | ||
"isSerialized": true, | ||
"isSigningField": true, | ||
"type": "Hash256" | ||
} | ||
], | ||
[ | ||
"NextPageMin", | ||
{ | ||
"nth": 27, | ||
"isVLEncoded": false, | ||
"isSerialized": true, | ||
"isSigningField": true, | ||
"type": "Hash256" | ||
} | ||
], | ||
[ | ||
"BuyOffer", | ||
{ | ||
"nth": 28, | ||
"isVLEncoded": false, | ||
"isSerialized": true, | ||
"isSigningField": true, | ||
"type": "Hash256" | ||
} | ||
], | ||
[ | ||
"SellOffer", | ||
{ | ||
"nth": 29, | ||
"isVLEncoded": false, | ||
"isSerialized": true, | ||
"isSigningField": true, | ||
"type": "Hash256" | ||
} | ||
], | ||
[ | ||
"TickSize", | ||
@@ -1626,2 +1767,32 @@ { | ||
} | ||
], | ||
[ | ||
"Cookie", | ||
{ | ||
"nth": 10, | ||
"isVLEncoded": false, | ||
"isSerialized": true, | ||
"isSigningField": true, | ||
"type": "UInt64" | ||
} | ||
], | ||
[ | ||
"ServerVersion", | ||
{ | ||
"nth": 11, | ||
"isVLEncoded": false, | ||
"isSerialized": true, | ||
"isSigningField": true, | ||
"type": "UInt64" | ||
} | ||
], | ||
[ | ||
"OfferNode", | ||
{ | ||
"nth": 12, | ||
"isVLEncoded": false, | ||
"isSerialized": true, | ||
"isSigningField": true, | ||
"type": "UInt64" | ||
} | ||
] | ||
@@ -1751,3 +1922,14 @@ ], | ||
"tecHAS_OBLIGATIONS": 151, | ||
"tecTOO_SOON": 152 | ||
"tecTOO_SOON": 152, | ||
"tecMAX_SEQUENCE_REACHED": 154, | ||
"tecNO_SUITABLE_PAGE": 155, | ||
"tecBUY_SELL_MISMATCH": 156, | ||
"tecOFFER_TYPE_MISMATCH": 157, | ||
"tecCANT_ACCEPT_OWN_OFFER": 158, | ||
"tecINSUFFICIENT_FUNDS": 159, | ||
"tecOBJECT_NOT_FOUND": 160, | ||
"tecINSUFFICIENT_PAYMENT": 161, | ||
"tecINCORRECT_ASSET": 162, | ||
"tecTOO_MANY": 163 | ||
}, | ||
@@ -1779,3 +1961,7 @@ "TRANSACTION_TYPES": { | ||
"AccountDelete": 21, | ||
"NFTokenMint": 25, | ||
"NFTokenBurn": 26, | ||
"NFTokenCreateOffer": 27, | ||
"NFTokenCancelOffer": 28, | ||
"NFTokenAcceptOffer": 29, | ||
"EnableAmendment": 100, | ||
@@ -1782,0 +1968,0 @@ "SetFee": 101, |
@@ -21,2 +21,3 @@ "use strict"; | ||
var binary_serializer_1 = require("./serdes/binary-serializer"); | ||
var buffer_1 = require("buffer/"); | ||
/** | ||
@@ -58,3 +59,3 @@ * Class for hashing with SHA512 | ||
Sha512Half.prototype.finish256 = function () { | ||
var bytes = this.hash.digest(); | ||
var bytes = buffer_1.Buffer.from(this.hash.digest()); | ||
return bytes.slice(0, 32); | ||
@@ -61,0 +62,0 @@ }; |
@@ -8,17 +8,10 @@ import { Hash160 } from "./hash-160"; | ||
static readonly XRP: Currency; | ||
private readonly _iso?; | ||
private readonly _isNative; | ||
private readonly _iso; | ||
constructor(byteBuf: Buffer); | ||
/** | ||
* Tells if this currency is native | ||
* | ||
* @returns true if native, false if not | ||
*/ | ||
isNative(): boolean; | ||
/** | ||
* Return the ISO code of this currency | ||
* | ||
* @returns ISO code if it exists, else undefined | ||
* @returns ISO code if it exists, else null | ||
*/ | ||
iso(): string | undefined; | ||
iso(): string | null; | ||
/** | ||
@@ -25,0 +18,0 @@ * Constructs a Currency object |
@@ -36,4 +36,14 @@ "use strict"; | ||
function isIsoCode(iso) { | ||
return iso.length === 3; | ||
return ISO_REGEX.test(iso); | ||
} | ||
function isoCodeFromHex(code) { | ||
var iso = code.toString(); | ||
if (iso === "XRP") { | ||
throw new Error("Disallowed currency code: to indicate the currency XRP you must use 20 bytes of 0s"); | ||
} | ||
if (isIsoCode(iso)) { | ||
return iso; | ||
} | ||
return null; | ||
} | ||
/** | ||
@@ -49,3 +59,3 @@ * Tests if hex is a valid hex-string | ||
function isStringRepresentation(input) { | ||
return isIsoCode(input) || isHex(input); | ||
return input.length === 3 || isHex(input); | ||
} | ||
@@ -82,29 +92,18 @@ /** | ||
var _this = _super.call(this, byteBuf !== null && byteBuf !== void 0 ? byteBuf : Currency.XRP.bytes) || this; | ||
var onlyISO = true; | ||
var bytes = _this.bytes; | ||
var code = _this.bytes.slice(12, 15); | ||
var iso = code.toString(); | ||
for (var i = bytes.length - 1; i >= 0; i--) { | ||
if (bytes[i] !== 0 && !(i === 12 || i === 13 || i === 14)) { | ||
onlyISO = false; | ||
break; | ||
} | ||
if (_this.bytes[0] !== 0) { | ||
_this._iso = null; | ||
} | ||
var lossLessISO = onlyISO && iso !== "XRP" && ISO_REGEX.test(iso); | ||
_this._isNative = onlyISO && code.toString("hex") === "000000"; | ||
_this._iso = _this._isNative ? "XRP" : lossLessISO ? iso : undefined; | ||
else if (code.toString("hex") === "000000") { | ||
_this._iso = "XRP"; | ||
} | ||
else { | ||
_this._iso = isoCodeFromHex(code); | ||
} | ||
return _this; | ||
} | ||
/** | ||
* Tells if this currency is native | ||
* | ||
* @returns true if native, false if not | ||
*/ | ||
Currency.prototype.isNative = function () { | ||
return this._isNative; | ||
}; | ||
/** | ||
* Return the ISO code of this currency | ||
* | ||
* @returns ISO code if it exists, else undefined | ||
* @returns ISO code if it exists, else null | ||
*/ | ||
@@ -135,3 +134,3 @@ Currency.prototype.iso = function () { | ||
var iso = this.iso(); | ||
if (iso !== undefined) { | ||
if (iso !== null) { | ||
return iso; | ||
@@ -138,0 +137,0 @@ } |
{ | ||
"name": "ripple-binary-codec", | ||
"version": "1.1.3", | ||
"version": "1.2.0-beta.1", | ||
"description": "XRP Ledger binary codec", | ||
@@ -16,4 +16,4 @@ "files": [ | ||
"assert": "^2.0.0", | ||
"big-integer": "^1.6.48", | ||
"buffer": "5.6.0", | ||
"big-integer": "^1.6.48", | ||
"create-hash": "^1.2.0", | ||
@@ -24,2 +24,3 @@ "decimal.js": "^10.2.0", | ||
"devDependencies": { | ||
"@types/create-hash": "^1.2.2", | ||
"@types/jest": "^26.0.7", | ||
@@ -60,4 +61,4 @@ "@types/node": "^14.0.10", | ||
"node": ">=10.22.0", | ||
"yarn": "^1.22.4" | ||
"npm": ">=7.0.0" | ||
} | ||
} |
@@ -101,8 +101,8 @@ # ripple-binary-codec [![NPM](https://img.shields.io/npm/v/ripple-binary-codec.svg)](https://npmjs.org/package/ripple-binary-codec) | ||
yarn test | ||
npm test | ||
Use `--coverage` to generate and display code coverage information: | ||
yarn test --coverage | ||
npm test --coverage | ||
This tells jest to output code coverage info in the `./coverage` directory, in addition to showing it on the command line. | ||
This tells jest to output code coverage info in the `./coverage` directory, in addition to showing it on the command line. |
@@ -316,3 +316,3 @@ /* eslint-disable func-style */ | ||
180C769B66D942EE69E6DCC940CA48D82337AD10000000000000000000000000 | ||
58525000000000003000000000000000000000000055534400000000000A20B3 | ||
00000000000000003000000000000000000000000055534400000000000A20B3 | ||
C85F482532A9578DBB3950B85CA06594D100` | ||
@@ -375,3 +375,3 @@ ); | ||
}, | ||
{ currency: "0000000000000000000000005852500000000000" }, | ||
{ currency: "XRP" }, | ||
{ | ||
@@ -378,0 +378,0 @@ currency: "USD", |
@@ -53,6 +53,6 @@ const { coreTypes } = require("../dist/types"); | ||
describe("Currency", function () { | ||
test("Will have a null iso() for dodgy XRP ", function () { | ||
const bad = Currency.from("0000000000000000000000005852500000000000"); | ||
expect(bad.iso()).toBeUndefined(); | ||
expect(bad.isNative()).toBe(false); | ||
test("Will throw an error for dodgy XRP ", function () { | ||
expect(() => | ||
Currency.from("0000000000000000000000005852500000000000") | ||
).toThrow(); | ||
}); | ||
@@ -77,2 +77,6 @@ test("Currency with lowercase letters decode to hex", () => { | ||
}); | ||
test("Can handle non-standard currency codes", () => { | ||
const currency = "015841551A748AD2C1F76FF6ECB0CCCD00000000"; | ||
expect(Currency.from(currency).toJSON()).toBe(currency); | ||
}); | ||
test("throws on invalid reprs", function () { | ||
@@ -79,0 +83,0 @@ expect(() => Currency.from(Buffer.alloc(19))).toThrow(); |
@@ -14,3 +14,4 @@ const { encode, decode } = require("../dist"); | ||
LedgerEntryType: "AccountRoot", | ||
PreviousTxnID: "0735A0B32B2A3F4C938B76D6933003E29447DB8C7CE382BBE089402FF12A03E5".toLowerCase(), | ||
PreviousTxnID: | ||
"0735A0B32B2A3F4C938B76D6933003E29447DB8C7CE382BBE089402FF12A03E5".toLowerCase(), | ||
Flags: 0, | ||
@@ -17,0 +18,0 @@ Sequence: 1, |
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 too big to display
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
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
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
1148998
200
17850
108
14
1
1