You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

parseNFTokenID.js 1.5KB

12345678910111213141516171819202122232425262728293031
  1. "use strict";
  2. var __importDefault = (this && this.__importDefault) || function (mod) {
  3. return (mod && mod.__esModule) ? mod : { "default": mod };
  4. };
  5. Object.defineProperty(exports, "__esModule", { value: true });
  6. const bignumber_js_1 = __importDefault(require("bignumber.js"));
  7. const ripple_address_codec_1 = require("ripple-address-codec");
  8. const errors_1 = require("../errors");
  9. function unscrambleTaxon(taxon, tokenSeq) {
  10. return (taxon ^ (384160001 * tokenSeq + 2459)) % 4294967296;
  11. }
  12. function parseNFTokenID(nftokenID) {
  13. const expectedLength = 64;
  14. if (nftokenID.length !== expectedLength) {
  15. throw new errors_1.XrplError(`Attempting to parse a nftokenID with length ${nftokenID.length}
  16. , but expected a token with length ${expectedLength}`);
  17. }
  18. const scrambledTaxon = new bignumber_js_1.default(nftokenID.substring(48, 56), 16).toNumber();
  19. const sequence = new bignumber_js_1.default(nftokenID.substring(56, 64), 16).toNumber();
  20. const NFTokenIDData = {
  21. NFTokenID: nftokenID,
  22. Flags: new bignumber_js_1.default(nftokenID.substring(0, 4), 16).toNumber(),
  23. TransferFee: new bignumber_js_1.default(nftokenID.substring(4, 8), 16).toNumber(),
  24. Issuer: (0, ripple_address_codec_1.encodeAccountID)(Buffer.from(nftokenID.substring(8, 48), 'hex')),
  25. Taxon: unscrambleTaxon(scrambledTaxon, sequence),
  26. Sequence: sequence,
  27. };
  28. return NFTokenIDData;
  29. }
  30. exports.default = parseNFTokenID;
  31. //# sourceMappingURL=parseNFTokenID.js.map