evernode-js-client 0.6.18 → 0.6.20

Sign up to get free protection for your applications and to get access to all the features.
Binary file
package/index.js CHANGED
@@ -53257,6 +53257,8 @@ const HOST_UPDATE_PARAM_SIZE = 123;
53257
53257
 
53258
53258
  const VOTE_VALIDATION_ERR = "VOTE_VALIDATION_ERR";
53259
53259
 
53260
+ const IPV6_FAMILY = 6;
53261
+
53260
53262
  class HostClient extends BaseEvernodeClient {
53261
53263
 
53262
53264
  constructor(xrpAddress, xrpSecret, options = {}) {
@@ -53335,17 +53337,57 @@ class HostClient extends BaseEvernodeClient {
53335
53337
  * @param {number} leaseIndex Index number for the lease.
53336
53338
  * @param {number} leaseAmount Amount (EVRs) of the lease offer.
53337
53339
  * @param {string} tosHash Hex hash of the Terms Of Service text.
53340
+ * @param {string} outboundIPAddress Assigned IP Address.
53338
53341
  */
53339
- async offerLease(leaseIndex, leaseAmount, tosHash) {
53340
- // <prefix><lease index 16)><half of tos hash><lease amount (int64)><identifier (uint32)>
53342
+ async offerLease(leaseIndex, leaseAmount, tosHash, outboundIPAddress = null) {
53343
+
53344
+ // <prefix><version tag ("LTV"+uint8)><lease index (uint16)><half of tos hash><lease amount (int64)><identifier (uint32)><ip data>
53345
+ // Lengths of sub sections.
53341
53346
  const prefixLen = EvernodeConstants.LEASE_TOKEN_PREFIX_HEX.length / 2;
53347
+ const versionPrefixLen = EvernodeConstants.LEASE_TOKEN_VERSION_PREFIX_HEX.length / 2;
53348
+ const versionLen = versionPrefixLen + 2; // ("LTV"<Version Number>)
53349
+ const indexLen = 2;
53342
53350
  const halfToSLen = tosHash.length / 4;
53343
- const uriBuf = Buffer.allocUnsafe(prefixLen + halfToSLen + 14);
53351
+ const leaseAmountLen = 8;
53352
+ const identifierLen = 4;
53353
+ const ipDataLen = 17;
53354
+
53355
+ // Offsets of sub sections
53356
+ const versionPrefixOffset = prefixLen;
53357
+ const versionOffset = prefixLen + versionPrefixLen;
53358
+ const indexOffset = prefixLen + versionLen;
53359
+ const halfTosHashOffset = prefixLen + versionLen + indexLen;
53360
+ const leaseAmountOffset = prefixLen + versionLen + indexLen + halfToSLen;
53361
+ const identifierOffset = prefixLen + versionLen + indexLen + halfToSLen + leaseAmountLen;
53362
+ const ipDataOffset = prefixLen + versionLen + indexLen + halfToSLen + leaseAmountLen + identifierLen;
53363
+
53364
+ const uriBuf = Buffer.alloc((prefixLen + versionLen + indexLen + halfToSLen + leaseAmountLen + identifierLen + ipDataLen));
53365
+
53344
53366
  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);
53367
+ Buffer.from(EvernodeConstants.LEASE_TOKEN_VERSION_PREFIX_HEX, 'hex').copy(uriBuf, versionPrefixOffset, 0, versionPrefixLen);
53368
+ uriBuf.writeUInt16BE(EvernodeConstants.LEASE_TOKEN_VERSION, versionOffset);
53369
+ uriBuf.writeUInt16BE(leaseIndex, indexOffset);
53370
+ Buffer.from(tosHash, 'hex').copy(uriBuf, halfTosHashOffset, 0, halfToSLen);
53371
+ uriBuf.writeBigInt64BE(XflHelpers.getXfl(leaseAmount.toString()), leaseAmountOffset);
53372
+ uriBuf.writeUInt32BE((await this.xrplAcc.getSequence()), identifierOffset);
53373
+
53374
+ if (outboundIPAddress) {
53375
+ if (outboundIPAddress.includes(":")) {
53376
+ uriBuf.writeUInt8(IPV6_FAMILY, ipDataOffset);
53377
+ const ipBuf = Buffer.from(outboundIPAddress.split(':').map(v => {
53378
+ const bytes = [];
53379
+ for (let i = 0; i < v.length; i += 2) {
53380
+ bytes.push(parseInt(v.substr(i, 2), 16));
53381
+ }
53382
+ return bytes;
53383
+ }).flat());
53384
+
53385
+ ipBuf.copy(uriBuf, ipDataOffset + 1, 0, ipDataLen);
53386
+ } else {
53387
+ throw "Invalid outbound IP address was provided";
53388
+ }
53389
+ }
53390
+
53349
53391
  const uri = uriBuf.toString('base64');
53350
53392
 
53351
53393
  try {
@@ -54779,6 +54821,8 @@ const EvernodeConstants = {
54779
54821
  EVR: 'EVR',
54780
54822
  TOKEN_PREFIX_HEX: '657672686F7374', // evrhost
54781
54823
  LEASE_TOKEN_PREFIX_HEX: '6576726C65617365', // evrlease
54824
+ LEASE_TOKEN_VERSION_PREFIX_HEX: '4C5456', // LTV (Lease_Token_Version)
54825
+ LEASE_TOKEN_VERSION: 1,
54782
54826
  HOOK_NAMESPACE: '01EAF09326B4911554384121FF56FA8FECC215FDDE2EC35D9E59F2C53EC665A0',
54783
54827
  NOW_IN_EVRS: "0.00000001",
54784
54828
  HOOKS: [
@@ -56200,23 +56244,45 @@ const { Buffer } = __nccwpck_require__(4300);
56200
56244
  const { XflHelpers } = __nccwpck_require__(3243);
56201
56245
  const { EvernodeConstants } = __nccwpck_require__(9849);
56202
56246
  const { TransactionHelper } = __nccwpck_require__(7071);
56247
+ const { EvernodeHelpers } = __nccwpck_require__(2523);
56203
56248
 
56204
56249
  // Utility helper functions.
56205
56250
  class UtilHelpers {
56206
56251
 
56207
56252
  static decodeLeaseTokenUri(hexUri) {
56208
56253
  // Get the lease index from the token's URI.
56209
- // <prefix><lease index 16)><half of tos hash><lease amount (int64)><identifier (uint32)>
56254
+ // <prefix><version>lease index 16)><half of tos hash><lease amount (int64)><identifier (uint32)><(ip numeric array)>
56210
56255
 
56211
56256
  const asciiUri = TransactionHelper.hexToASCII(hexUri);
56212
56257
  const uriBuf = Buffer.from(asciiUri, 'base64');
56258
+ // Lengths of sub sections.
56213
56259
  const prefixLen = EvernodeConstants.LEASE_TOKEN_PREFIX_HEX.length / 2;
56260
+ const versionPrefixLen = EvernodeConstants.LEASE_TOKEN_VERSION_PREFIX_HEX.length / 2;
56261
+ const versionLen = versionPrefixLen + 2;
56262
+ const indexLen = 2;
56214
56263
  const halfToSLen = 16;
56264
+ const leaseAmountLen = 8;
56265
+ const identifierLen = 4;
56266
+ const ipDataLen = 17;
56267
+
56268
+ const isVersionedURI = EvernodeHelpers.isValidURI(hexUri, `${EvernodeConstants.LEASE_TOKEN_PREFIX_HEX}${EvernodeConstants.LEASE_TOKEN_VERSION_PREFIX_HEX}`);
56269
+
56270
+ // Offsets of sub sections
56271
+ const versionPrefixOffset = prefixLen + versionPrefixLen;
56272
+ const halfTosHashOffset = isVersionedURI ? (prefixLen + versionLen + indexLen) : (prefixLen + indexLen);
56273
+ const leaseAmountOffset = isVersionedURI ? (prefixLen + versionLen + indexLen + halfToSLen) : (prefixLen + indexLen + halfToSLen);
56274
+ const identifierOffset = isVersionedURI ? (prefixLen + versionLen + indexLen + halfToSLen + leaseAmountLen) : (prefixLen + indexLen + halfToSLen + leaseAmountLen);
56275
+ const ipDataOffset = isVersionedURI ? (prefixLen + versionLen + indexLen + halfToSLen + leaseAmountLen + identifierLen) : (prefixLen + indexLen + halfToSLen + leaseAmountLen + identifierLen);
56276
+
56215
56277
  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
56278
+ version: isVersionedURI ? `${uriBuf.slice(prefixLen, versionPrefixOffset).toString()}${uriBuf.readUint16BE(prefixLen + versionPrefixLen)}` : null,
56279
+ leaseIndex: isVersionedURI ? uriBuf.readUint16BE(prefixLen + versionLen) : uriBuf.readUint16BE(prefixLen),
56280
+ halfTos: uriBuf.slice(halfTosHashOffset, halfTosHashOffset + halfToSLen),
56281
+ leaseAmount: parseFloat(XflHelpers.toString(uriBuf.readBigInt64BE(leaseAmountOffset))),
56282
+ identifier: uriBuf.length > identifierOffset ? uriBuf.readUInt32BE(identifierOffset) : null,
56283
+ outboundIP: (uriBuf.length > ipDataOffset && (uriBuf.readUint8(ipDataOffset) == 6))
56284
+ ? { family: 6, address: uriBuf.slice(ipDataOffset + 1, ipDataOffset + 1 + ipDataLen).toString('hex').toUpperCase().replace(/(.{4})(?!$)/g, "$1:") }
56285
+ : null
56220
56286
  }
56221
56287
  }
56222
56288
 
@@ -56229,6 +56295,7 @@ class UtilHelpers {
56229
56295
  return time;
56230
56296
  }
56231
56297
  }
56298
+
56232
56299
  }
56233
56300
 
56234
56301
  module.exports = {
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.20",
10
10
  "dependencies": {
11
11
  "elliptic": "6.5.4",
12
12
  "libsodium-wrappers": "0.7.10",