evernode-js-client 0.6.2 → 0.6.4
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.
- package/index.js +97 -32
- package/package.json +1 -1
package/index.js
CHANGED
@@ -11725,7 +11725,7 @@ const { Buffer } = __nccwpck_require__(4300);
|
|
11725
11725
|
const { XrplApi } = __nccwpck_require__(1850);
|
11726
11726
|
const { XrplAccount } = __nccwpck_require__(9329);
|
11727
11727
|
const { XrplApiEvents, XrplConstants } = __nccwpck_require__(3307);
|
11728
|
-
const { EvernodeEvents, EventTypes, MemoFormats, EvernodeConstants, HookStateKeys, HookParamKeys } = __nccwpck_require__(9849);
|
11728
|
+
const { EvernodeEvents, EventTypes, MemoFormats, EvernodeConstants, HookStateKeys, HookParamKeys, RegExp } = __nccwpck_require__(9849);
|
11729
11729
|
const { DefaultValues } = __nccwpck_require__(8262);
|
11730
11730
|
const { EncryptionHelper } = __nccwpck_require__(4832);
|
11731
11731
|
const { EventEmitter } = __nccwpck_require__(6170);
|
@@ -11763,6 +11763,9 @@ class BaseEvernodeClient {
|
|
11763
11763
|
|
11764
11764
|
this.xrplAcc = new XrplAccount(xrpAddress, xrpSecret, { xrplApi: this.xrplApi });
|
11765
11765
|
this.accKeyPair = xrpSecret && this.xrplAcc.deriveKeypair();
|
11766
|
+
this.messagePrivateKey = options.messagePrivateKey || (this.accKeyPair ? this.accKeyPair.privateKey : null);
|
11767
|
+
if (this.messagePrivateKey && !RegExp.PublicPrivateKey.test(this.messagePrivateKey))
|
11768
|
+
throw "Message private key is not valid.";
|
11766
11769
|
this.#watchEvents = watchEvents;
|
11767
11770
|
this.#autoSubscribe = autoSubscribe;
|
11768
11771
|
this.events = new EventEmitter();
|
@@ -11975,14 +11978,21 @@ class BaseEvernodeClient {
|
|
11975
11978
|
if (tx.TransactionType === 'URITokenBuy' && eventType === EventTypes.ACQUIRE_LEASE && tx.Memos.length &&
|
11976
11979
|
tx.Memos[0].type === EventTypes.ACQUIRE_LEASE && tx.Memos[0].format === MemoFormats.BASE64 && tx.Memos[0].data) {
|
11977
11980
|
|
11978
|
-
// If our account is the destination host account, then decrypt the payload.
|
11981
|
+
// If our account is the destination host account, then decrypt the payload if it is encrypted.
|
11979
11982
|
let payload = tx.Memos[0].data;
|
11980
|
-
if (tx.Destination === this.xrplAcc.address) {
|
11981
|
-
const
|
11982
|
-
if (
|
11983
|
-
payload =
|
11984
|
-
|
11985
|
-
|
11983
|
+
if (tx.Memos[0].format === MemoFormats.BASE64 && tx.Destination === this.xrplAcc.address) {
|
11984
|
+
const prefixBuf = (Buffer.from(payload, 'base64')).slice(0, 1);
|
11985
|
+
if (prefixBuf.readInt8() == 1) { // 1 denoted the data is encrypted
|
11986
|
+
payload = Buffer.from(payload, 'base64').slice(1).toString('base64');
|
11987
|
+
const decrypted = this.messagePrivateKey && await EncryptionHelper.decrypt(this.messagePrivateKey, payload);
|
11988
|
+
if (decrypted)
|
11989
|
+
payload = decrypted;
|
11990
|
+
else
|
11991
|
+
console.log('Failed to decrypt acquire data.');
|
11992
|
+
}
|
11993
|
+
else {
|
11994
|
+
payload = JSON.parse(Buffer.from(payload, 'base64').slice(1).toString());
|
11995
|
+
}
|
11986
11996
|
}
|
11987
11997
|
|
11988
11998
|
return {
|
@@ -12005,13 +12015,20 @@ class BaseEvernodeClient {
|
|
12005
12015
|
let payload = tx.Memos[0].data;
|
12006
12016
|
const acquireRefId = eventData;
|
12007
12017
|
|
12008
|
-
// If our account is the destination user account, then decrypt the payload.
|
12018
|
+
// If our account is the destination user account, then decrypt the payload if it is encrypted.
|
12009
12019
|
if (tx.Memos[0].format === MemoFormats.BASE64 && tx.Destination === this.xrplAcc.address) {
|
12010
|
-
const
|
12011
|
-
if (
|
12012
|
-
payload =
|
12013
|
-
|
12014
|
-
|
12020
|
+
const prefixBuf = (Buffer.from(payload, 'base64')).slice(0, 1);
|
12021
|
+
if (prefixBuf.readInt8() == 1) { // 1 denoted the data is encrypted
|
12022
|
+
payload = Buffer.from(payload, 'base64').slice(1).toString('base64');
|
12023
|
+
const decrypted = this.messagePrivateKey && await EncryptionHelper.decrypt(this.messagePrivateKey, payload);
|
12024
|
+
if (decrypted)
|
12025
|
+
payload = decrypted;
|
12026
|
+
else
|
12027
|
+
console.log('Failed to decrypt instance data.');
|
12028
|
+
}
|
12029
|
+
else {
|
12030
|
+
payload = JSON.parse(Buffer.from(payload, 'base64').slice(1).toString());
|
12031
|
+
}
|
12015
12032
|
}
|
12016
12033
|
|
12017
12034
|
return {
|
@@ -13043,7 +13060,7 @@ module.exports = {
|
|
13043
13060
|
|
13044
13061
|
const { XrplConstants } = __nccwpck_require__(3307);
|
13045
13062
|
const { BaseEvernodeClient } = __nccwpck_require__(6263);
|
13046
|
-
const { EvernodeEvents, EvernodeConstants, MemoFormats, EventTypes, ErrorCodes, HookParamKeys } = __nccwpck_require__(9849);
|
13063
|
+
const { EvernodeEvents, EvernodeConstants, MemoFormats, EventTypes, ErrorCodes, HookParamKeys, RegExp } = __nccwpck_require__(9849);
|
13047
13064
|
const { XrplAccount } = __nccwpck_require__(9329);
|
13048
13065
|
const { EncryptionHelper } = __nccwpck_require__(4832);
|
13049
13066
|
const { Buffer } = __nccwpck_require__(4300);
|
@@ -13431,17 +13448,37 @@ class HostClient extends BaseEvernodeClient {
|
|
13431
13448
|
|
13432
13449
|
// Encrypt the instance info with the tenant's encryption key (Specified in MessageKey field of the tenant account).
|
13433
13450
|
const tenantAcc = new XrplAccount(tenantAddress, null, { xrplApi: this.xrplApi });
|
13434
|
-
const encKey = await tenantAcc.getMessageKey();
|
13435
|
-
if (!encKey)
|
13436
|
-
throw "Tenant encryption key not set.";
|
13437
13451
|
|
13438
|
-
|
13452
|
+
let encKey = null;
|
13453
|
+
let doEncrypt = true;
|
13454
|
+
// Initialize with not-encrypted prefix flag and the data.
|
13455
|
+
let data = Buffer.concat([Buffer.from([0x00]), Buffer.from(JSON.stringify(instanceInfo))]).toString('base64');
|
13456
|
+
|
13457
|
+
if ('messageKey' in options) {
|
13458
|
+
if (options.messageKey !== 'none' && RegExp.PublicPrivateKey.test(options.messageKey)) {
|
13459
|
+
encKey = options.messageKey;
|
13460
|
+
} else if (options.messageKey === 'none') {
|
13461
|
+
doEncrypt = false;
|
13462
|
+
} else
|
13463
|
+
throw "Tenant encryption key not valid.";
|
13464
|
+
} else {
|
13465
|
+
encKey = await tenantAcc.getMessageKey();
|
13466
|
+
}
|
13467
|
+
|
13468
|
+
if (doEncrypt) {
|
13469
|
+
if (!encKey)
|
13470
|
+
throw "Tenant encryption key not set.";
|
13471
|
+
const encrypted = await EncryptionHelper.encrypt(encKey, instanceInfo);
|
13472
|
+
// Override encrypted prefix flag and the data.
|
13473
|
+
data = Buffer.concat([Buffer.from([0x01]), Buffer.from(encrypted, 'base64')]).toString('base64');
|
13474
|
+
}
|
13475
|
+
|
13439
13476
|
return this.xrplAcc.makePayment(tenantAddress,
|
13440
13477
|
XrplConstants.MIN_XRP_AMOUNT,
|
13441
13478
|
XrplConstants.XRP,
|
13442
13479
|
null,
|
13443
13480
|
[
|
13444
|
-
{ type: EventTypes.ACQUIRE_SUCCESS, format: MemoFormats.BASE64, data:
|
13481
|
+
{ type: EventTypes.ACQUIRE_SUCCESS, format: MemoFormats.BASE64, data: data }
|
13445
13482
|
],
|
13446
13483
|
{
|
13447
13484
|
hookParams: [
|
@@ -13643,8 +13680,9 @@ module.exports = {
|
|
13643
13680
|
/***/ ((module, __unused_webpack_exports, __nccwpck_require__) => {
|
13644
13681
|
|
13645
13682
|
const { BaseEvernodeClient } = __nccwpck_require__(6263);
|
13646
|
-
const { EvernodeEvents, MemoFormats, EventTypes, ErrorCodes, ErrorReasons, EvernodeConstants, HookParamKeys } = __nccwpck_require__(9849);
|
13683
|
+
const { EvernodeEvents, MemoFormats, EventTypes, ErrorCodes, ErrorReasons, EvernodeConstants, HookParamKeys, RegExp } = __nccwpck_require__(9849);
|
13647
13684
|
const { EncryptionHelper } = __nccwpck_require__(4832);
|
13685
|
+
const { Buffer } = __nccwpck_require__(4300);
|
13648
13686
|
const { XrplAccount } = __nccwpck_require__(9329);
|
13649
13687
|
const { UtilHelpers } = __nccwpck_require__(6687);
|
13650
13688
|
const { EvernodeHelpers } = __nccwpck_require__(2523);
|
@@ -13729,20 +13767,37 @@ class TenantClient extends BaseEvernodeClient {
|
|
13729
13767
|
if (!buyUriOffer)
|
13730
13768
|
throw { reason: ErrorReasons.NO_OFFER, error: "No offers available." };
|
13731
13769
|
|
13732
|
-
|
13733
|
-
|
13734
|
-
|
13735
|
-
|
13770
|
+
let encKey = null;
|
13771
|
+
let doEncrypt = true;
|
13772
|
+
// Initialize with not-encrypted prefix flag and the data.
|
13773
|
+
let data = Buffer.concat([Buffer.from([0x00]), Buffer.from(JSON.stringify(requirement))]).toString('base64');
|
13774
|
+
|
13775
|
+
if ('messageKey' in options) {
|
13776
|
+
if (options.messageKey !== 'none' && RegExp.PublicPrivateKey.test(options.messageKey)) {
|
13777
|
+
encKey = options.messageKey;
|
13778
|
+
} else if (options.messageKey === 'none') {
|
13779
|
+
doEncrypt = false;
|
13780
|
+
} else
|
13781
|
+
throw "Tenant encryption key not valid.";
|
13782
|
+
} else {
|
13783
|
+
encKey = await hostAcc.getMessageKey();
|
13784
|
+
}
|
13736
13785
|
|
13737
|
-
|
13738
|
-
|
13739
|
-
|
13740
|
-
|
13786
|
+
if (doEncrypt) {
|
13787
|
+
if (!encKey)
|
13788
|
+
throw "Tenant encryption key not set.";
|
13789
|
+
const encrypted = await EncryptionHelper.encrypt(encKey, requirement, {
|
13790
|
+
iv: options.iv, // Must be null or 16 bytes.
|
13791
|
+
ephemPrivateKey: options.ephemPrivateKey // Must be null or 32 bytes.
|
13792
|
+
});
|
13793
|
+
// Override encrypted prefix flag and the data.
|
13794
|
+
data = Buffer.concat([Buffer.from([0x01]), Buffer.from(encrypted, 'base64')]).toString('base64');
|
13795
|
+
}
|
13741
13796
|
|
13742
13797
|
return this.xrplAcc.buyURIToken(
|
13743
13798
|
buyUriOffer,
|
13744
13799
|
[
|
13745
|
-
{ type: EventTypes.ACQUIRE_LEASE, format: MemoFormats.BASE64, data:
|
13800
|
+
{ type: EventTypes.ACQUIRE_LEASE, format: MemoFormats.BASE64, data: data }
|
13746
13801
|
],
|
13747
13802
|
{
|
13748
13803
|
hookParams: [
|
@@ -14566,6 +14621,10 @@ const URITokenTypes = {
|
|
14566
14621
|
REGISTRATION_URI_TOKEN: 2
|
14567
14622
|
}
|
14568
14623
|
|
14624
|
+
const RegExp = {
|
14625
|
+
PublicPrivateKey: /^[0-9A-Fa-f]{66}$/
|
14626
|
+
}
|
14627
|
+
|
14569
14628
|
module.exports = {
|
14570
14629
|
EvernodeConstants,
|
14571
14630
|
EventTypes,
|
@@ -14575,7 +14634,8 @@ module.exports = {
|
|
14575
14634
|
HookStateKeys,
|
14576
14635
|
EvernodeEvents,
|
14577
14636
|
URITokenTypes,
|
14578
|
-
HookParamKeys
|
14637
|
+
HookParamKeys,
|
14638
|
+
RegExp
|
14579
14639
|
}
|
14580
14640
|
|
14581
14641
|
/***/ }),
|
@@ -15805,7 +15865,7 @@ class UtilHelpers {
|
|
15805
15865
|
leaseIndex: uriBuf.readUint16BE(prefixLen),
|
15806
15866
|
halfTos: uriBuf.slice(prefixLen + 2, halfToSLen),
|
15807
15867
|
leaseAmount: parseFloat(XflHelpers.toString(uriBuf.readBigInt64BE(prefixLen + 2 + halfToSLen))),
|
15808
|
-
identifier: uriBuf.readUInt32BE(prefixLen + 10 + halfToSLen)
|
15868
|
+
identifier: uriBuf.length >= (prefixLen + 10 + halfToSLen) ? uriBuf.readUInt32BE(prefixLen + 10 + halfToSLen) : null
|
15809
15869
|
}
|
15810
15870
|
}
|
15811
15871
|
|
@@ -16952,6 +17012,11 @@ class XrplApi {
|
|
16952
17012
|
}
|
16953
17013
|
}
|
16954
17014
|
|
17015
|
+
async getTxnInfo(txnHash, options) {
|
17016
|
+
const resp = (await this.#client.request({ command: 'tx', transaction: txnHash, binary: false, ...options }));
|
17017
|
+
return resp?.result;
|
17018
|
+
}
|
17019
|
+
|
16955
17020
|
async submitAndVerify(tx, options) {
|
16956
17021
|
return await this.#client.submitAndWait(tx, options);
|
16957
17022
|
}
|