evernode-js-client 0.6.18 → 0.6.19

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Binary file
package/index.js CHANGED
@@ -53223,6 +53223,7 @@ const { XflHelpers } = __nccwpck_require__(3243);
53223
53223
  const { EvernodeHelpers } = __nccwpck_require__(2523);
53224
53224
  const { StateHelpers } = __nccwpck_require__(3860);
53225
53225
  const { TransactionHelper } = __nccwpck_require__(7071);
53226
+ const { UtilHelpers } = __nccwpck_require__(6687);
53226
53227
 
53227
53228
  const OFFER_WAIT_TIMEOUT = 60;
53228
53229
 
@@ -53257,6 +53258,9 @@ const HOST_UPDATE_PARAM_SIZE = 123;
53257
53258
 
53258
53259
  const VOTE_VALIDATION_ERR = "VOTE_VALIDATION_ERR";
53259
53260
 
53261
+ const IPV4_FAMILY = 4;
53262
+ const IPV6_FAMILY = 6;
53263
+
53260
53264
  class HostClient extends BaseEvernodeClient {
53261
53265
 
53262
53266
  constructor(xrpAddress, xrpSecret, options = {}) {
@@ -53335,17 +53339,73 @@ class HostClient extends BaseEvernodeClient {
53335
53339
  * @param {number} leaseIndex Index number for the lease.
53336
53340
  * @param {number} leaseAmount Amount (EVRs) of the lease offer.
53337
53341
  * @param {string} tosHash Hex hash of the Terms Of Service text.
53342
+ * @param {string} outboundIPAddress Assigned IP Address.
53338
53343
  */
53339
- async offerLease(leaseIndex, leaseAmount, tosHash) {
53340
- // <prefix><lease index 16)><half of tos hash><lease amount (int64)><identifier (uint32)>
53344
+ async offerLease(leaseIndex, leaseAmount, tosHash, outboundIPAddress = null) {
53345
+
53346
+ // If Outbound IP address is not specified resolve the IPV4 address of host using domain.
53347
+ if (!outboundIPAddress) {
53348
+ const domain = await this.xrplAcc.getDomain();
53349
+ outboundIPAddress = await UtilHelpers.resolveIP(domain, { family: 4 });
53350
+ }
53351
+
53352
+ // <prefix><version tag ("LTV"+uint8)><lease index (uint16)><half of tos hash><lease amount (int64)><identifier (uint32)><ip data>
53353
+ // Lengths of sub sections.
53341
53354
  const prefixLen = EvernodeConstants.LEASE_TOKEN_PREFIX_HEX.length / 2;
53355
+ const versionPrefixLen = EvernodeConstants.LEASE_TOKEN_VERSION_PREFIX_HEX.length / 2;
53356
+ const versionLen = versionPrefixLen + 2; // ("LTV"<Version Number>)
53357
+ const indexLen = 2;
53342
53358
  const halfToSLen = tosHash.length / 4;
53343
- const uriBuf = Buffer.allocUnsafe(prefixLen + halfToSLen + 14);
53359
+ const leaseAmountLen = 8;
53360
+ const identifierLen = 4;
53361
+ const ipDataLen = outboundIPAddress ? 17 : 0; // (Allocating block for considering both IPV6 and IPV4)
53362
+
53363
+ // Offsets of sub sections
53364
+ const versionPrefixOffset = prefixLen;
53365
+ const versionOffset = prefixLen + versionPrefixLen;
53366
+ const indexOffset = prefixLen + versionLen;
53367
+ const halfTosHashOffset = prefixLen + versionLen + indexLen;
53368
+ const leaseAmountOffset = prefixLen + versionLen + indexLen + halfToSLen;
53369
+ const identifierOffset = prefixLen + versionLen + indexLen + halfToSLen + leaseAmountLen;
53370
+ const ipDataOffset = prefixLen + versionLen + indexLen + halfToSLen + leaseAmountLen + identifierLen;
53371
+
53372
+ const uriBuf = Buffer.alloc((prefixLen + versionLen + indexLen + halfToSLen + leaseAmountLen + identifierLen + ipDataLen));
53373
+
53344
53374
  Buffer.from(EvernodeConstants.LEASE_TOKEN_PREFIX_HEX, 'hex').copy(uriBuf);
53345
- uriBuf.writeUInt16BE(leaseIndex, prefixLen);
53346
- Buffer.from(tosHash, 'hex').copy(uriBuf, prefixLen + 2, 0, halfToSLen);
53347
- uriBuf.writeBigInt64BE(XflHelpers.getXfl(leaseAmount.toString()), prefixLen + 2 + halfToSLen);
53348
- uriBuf.writeUInt32BE((await this.xrplAcc.getSequence()), prefixLen + 10 + halfToSLen);
53375
+ Buffer.from(EvernodeConstants.LEASE_TOKEN_VERSION_PREFIX_HEX, 'hex').copy(uriBuf, versionPrefixOffset, 0, versionPrefixLen);
53376
+ uriBuf.writeUInt16BE(EvernodeConstants.LEASE_TOKEN_VERSION, versionOffset);
53377
+ uriBuf.writeUInt16BE(leaseIndex, indexOffset);
53378
+ Buffer.from(tosHash, 'hex').copy(uriBuf, halfTosHashOffset, 0, halfToSLen);
53379
+ uriBuf.writeBigInt64BE(XflHelpers.getXfl(leaseAmount.toString()), leaseAmountOffset);
53380
+ uriBuf.writeUInt32BE((await this.xrplAcc.getSequence()), identifierOffset);
53381
+
53382
+ if (ipDataLen > 0) {
53383
+ if (outboundIPAddress.includes(":")) {
53384
+ uriBuf.writeUInt8(IPV6_FAMILY, ipDataOffset);
53385
+ const ipBuf = Buffer.from(outboundIPAddress.split(':').map(v => {
53386
+ const bytes = [];
53387
+ for (let i = 0; i < v.length; i += 2) {
53388
+ bytes.push(parseInt(v.substr(i, 2), 16));
53389
+ }
53390
+ return bytes;
53391
+ }).flat());
53392
+
53393
+ ipBuf.copy(uriBuf, ipDataOffset + 1, 0, ipDataLen);
53394
+ } else {
53395
+ uriBuf.writeUInt8(IPV4_FAMILY, ipDataOffset);
53396
+
53397
+ const ipBuf = Buffer.from(outboundIPAddress.split('.').map(v => {
53398
+ const bytes = [];
53399
+ bytes.push(parseInt(v));
53400
+ return bytes;
53401
+ }).flat());
53402
+
53403
+
53404
+ // Last 4 bytes of 17 byte buffer.
53405
+ ipBuf.copy(uriBuf, (ipDataOffset + 1) + 12, 0, 4);
53406
+ }
53407
+ }
53408
+
53349
53409
  const uri = uriBuf.toString('base64');
53350
53410
 
53351
53411
  try {
@@ -54779,6 +54839,8 @@ const EvernodeConstants = {
54779
54839
  EVR: 'EVR',
54780
54840
  TOKEN_PREFIX_HEX: '657672686F7374', // evrhost
54781
54841
  LEASE_TOKEN_PREFIX_HEX: '6576726C65617365', // evrlease
54842
+ LEASE_TOKEN_VERSION_PREFIX_HEX: '4C5456', // LTV (Lease_Token_Version)
54843
+ LEASE_TOKEN_VERSION: 1,
54782
54844
  HOOK_NAMESPACE: '01EAF09326B4911554384121FF56FA8FECC215FDDE2EC35D9E59F2C53EC665A0',
54783
54845
  NOW_IN_EVRS: "0.00000001",
54784
54846
  HOOKS: [
@@ -56200,23 +56262,48 @@ const { Buffer } = __nccwpck_require__(4300);
56200
56262
  const { XflHelpers } = __nccwpck_require__(3243);
56201
56263
  const { EvernodeConstants } = __nccwpck_require__(9849);
56202
56264
  const { TransactionHelper } = __nccwpck_require__(7071);
56265
+ const { EvernodeHelpers } = __nccwpck_require__(2523);
56266
+ const dns = __nccwpck_require__(604);
56203
56267
 
56204
56268
  // Utility helper functions.
56205
56269
  class UtilHelpers {
56206
56270
 
56207
56271
  static decodeLeaseTokenUri(hexUri) {
56208
56272
  // Get the lease index from the token's URI.
56209
- // <prefix><lease index 16)><half of tos hash><lease amount (int64)><identifier (uint32)>
56273
+ // <prefix><version>lease index 16)><half of tos hash><lease amount (int64)><identifier (uint32)><(ip numeric array)>
56210
56274
 
56211
56275
  const asciiUri = TransactionHelper.hexToASCII(hexUri);
56212
56276
  const uriBuf = Buffer.from(asciiUri, 'base64');
56277
+ // Lengths of sub sections.
56213
56278
  const prefixLen = EvernodeConstants.LEASE_TOKEN_PREFIX_HEX.length / 2;
56279
+ const versionPrefixLen = EvernodeConstants.LEASE_TOKEN_VERSION_PREFIX_HEX.length / 2;
56280
+ const versionLen = versionPrefixLen + 2;
56281
+ const indexLen = 2;
56214
56282
  const halfToSLen = 16;
56283
+ const leaseAmountLen = 8;
56284
+ const identifierLen = 4;
56285
+ const ipDataLen = 17;
56286
+
56287
+ const isVersionedURI = EvernodeHelpers.isValidURI(hexUri, `${EvernodeConstants.LEASE_TOKEN_PREFIX_HEX}${EvernodeConstants.LEASE_TOKEN_VERSION_PREFIX_HEX}`);
56288
+
56289
+ // Offsets of sub sections
56290
+ const versionPrefixOffset = prefixLen + versionPrefixLen;
56291
+ const halfTosHashOffset = isVersionedURI ? (prefixLen + versionLen + indexLen) : (prefixLen + indexLen);
56292
+ const leaseAmountOffset = isVersionedURI ? (prefixLen + versionLen + indexLen + halfToSLen) : (prefixLen + indexLen + halfToSLen);
56293
+ const identifierOffset = isVersionedURI ? (prefixLen + versionLen + indexLen + halfToSLen + leaseAmountLen) : (prefixLen + indexLen + halfToSLen + leaseAmountLen);
56294
+ const ipDataOffset = isVersionedURI ? (prefixLen + versionLen + indexLen + halfToSLen + leaseAmountLen + identifierLen) : (prefixLen + indexLen + halfToSLen + leaseAmountLen + identifierLen);
56295
+
56215
56296
  return {
56216
- leaseIndex: uriBuf.readUint16BE(prefixLen),
56217
- halfTos: uriBuf.slice(prefixLen + 2, halfToSLen),
56218
- leaseAmount: parseFloat(XflHelpers.toString(uriBuf.readBigInt64BE(prefixLen + 2 + halfToSLen))),
56219
- identifier: uriBuf.length >= (prefixLen + 14 + halfToSLen) ? uriBuf.readUInt32BE(prefixLen + 10 + halfToSLen) : null
56297
+ version: isVersionedURI ? `${uriBuf.slice(prefixLen, versionPrefixOffset).toString()}${uriBuf.readUint16BE(prefixLen + versionPrefixLen)}` : null,
56298
+ leaseIndex: isVersionedURI ? uriBuf.readUint16BE(prefixLen + versionLen) : uriBuf.readUint16BE(prefixLen),
56299
+ halfTos: uriBuf.slice(halfTosHashOffset, halfTosHashOffset + halfToSLen),
56300
+ leaseAmount: parseFloat(XflHelpers.toString(uriBuf.readBigInt64BE(leaseAmountOffset))),
56301
+ identifier: uriBuf.length > identifierOffset ? uriBuf.readUInt32BE(identifierOffset) : null,
56302
+ outboundIP: uriBuf.length > ipDataOffset ?
56303
+ (uriBuf.readUint8(ipDataOffset) == 4)
56304
+ ? { family: 4, address: uriBuf.slice((ipDataOffset + 13), (ipDataOffset + 13) + ipDataLen).map(b => b.toString()).join('.') }
56305
+ : { family: 6, address: uriBuf.slice(ipDataOffset + 1, ipDataOffset + 1 + ipDataLen).toString('hex').toUpperCase().replace(/(.{4})(?!$)/g, "$1:") }
56306
+ : null
56220
56307
  }
56221
56308
  }
56222
56309
 
@@ -56229,6 +56316,18 @@ class UtilHelpers {
56229
56316
  return time;
56230
56317
  }
56231
56318
  }
56319
+
56320
+ static async resolveIP(domain, options) {
56321
+ return new Promise((resolve, reject) => {
56322
+ dns.lookup(domain, options, (err, address) => {
56323
+ if (err) {
56324
+ reject(null);
56325
+ } else {
56326
+ resolve(address);
56327
+ }
56328
+ });
56329
+ });
56330
+ }
56232
56331
  }
56233
56332
 
56234
56333
  module.exports = {
@@ -57792,6 +57891,14 @@ module.exports = require("node:crypto");
57792
57891
 
57793
57892
  /***/ }),
57794
57893
 
57894
+ /***/ 604:
57895
+ /***/ ((module) => {
57896
+
57897
+ "use strict";
57898
+ module.exports = require("node:dns");
57899
+
57900
+ /***/ }),
57901
+
57795
57902
  /***/ 2037:
57796
57903
  /***/ ((module) => {
57797
57904
 
package/package.json CHANGED
@@ -6,7 +6,7 @@
6
6
  ],
7
7
  "homepage": "https://github.com/HotPocketDev/evernode-js-client",
8
8
  "license": "MIT",
9
- "version": "0.6.18",
9
+ "version": "0.6.19",
10
10
  "dependencies": {
11
11
  "elliptic": "6.5.4",
12
12
  "libsodium-wrappers": "0.7.10",