postchain-client 1.13.0 → 1.14.0
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/built/cjs/index.js +249 -73
- package/built/cjs/index.js.map +1 -1
- package/built/esm/index.js +6929 -17147
- package/built/esm/index.js.map +1 -1
- package/built/src/blockchainClient/blockchainClient.js +59 -52
- package/built/src/blockchainClient/blockchainClient.js.map +1 -1
- package/built/src/blockchainClient/errors.d.ts +1 -1
- package/built/src/blockchainClient/errors.js +3 -3
- package/built/src/blockchainClient/errors.js.map +1 -1
- package/built/src/blockchainClient/utils.js +3 -10
- package/built/src/blockchainClient/utils.js.map +1 -1
- package/built/src/blockchainClient/validation/blockIdentifier.d.ts +12 -0
- package/built/src/blockchainClient/validation/blockIdentifier.js +38 -0
- package/built/src/blockchainClient/validation/blockIdentifier.js.map +1 -0
- package/built/src/blockchainClient/validation/blockIdentifier.test.d.ts +1 -0
- package/built/src/blockchainClient/validation/blockIdentifier.test.js +19 -0
- package/built/src/blockchainClient/validation/blockIdentifier.test.js.map +1 -0
- package/built/src/blockchainClient/validation/bufferSchema.d.ts +3 -0
- package/built/src/blockchainClient/validation/bufferSchema.js +3 -0
- package/built/src/blockchainClient/validation/bufferSchema.js.map +1 -0
- package/built/src/blockchainClient/validation/networkSettings.d.ts +18 -0
- package/built/src/blockchainClient/validation/networkSettings.js +102 -0
- package/built/src/blockchainClient/validation/networkSettings.js.map +1 -0
- package/built/src/blockchainClient/validation/networkSettings.test.d.ts +1 -0
- package/built/src/blockchainClient/validation/networkSettings.test.js +53 -0
- package/built/src/blockchainClient/validation/networkSettings.test.js.map +1 -0
- package/built/src/blockchainClient/validation/signMethod.d.ts +24 -0
- package/built/src/blockchainClient/validation/signMethod.js +32 -0
- package/built/src/blockchainClient/validation/signMethod.js.map +1 -0
- package/built/src/blockchainClient/validation/signMethod.test.d.ts +1 -0
- package/built/src/blockchainClient/validation/signMethod.test.js +35 -0
- package/built/src/blockchainClient/validation/signMethod.test.js.map +1 -0
- package/built/src/blockchainClient/validation/txRid.d.ts +4 -0
- package/built/src/blockchainClient/validation/txRid.js +21 -0
- package/built/src/blockchainClient/validation/txRid.js.map +1 -0
- package/built/src/blockchainClient/validation/txRid.test.d.ts +1 -0
- package/built/src/blockchainClient/validation/txRid.test.js +17 -0
- package/built/src/blockchainClient/validation/txRid.test.js.map +1 -0
- package/built/src/blockchainClient/validation/validation.types.d.ts +9 -0
- package/built/src/blockchainClient/validation/validation.types.js +2 -0
- package/built/src/blockchainClient/validation/validation.types.js.map +1 -0
- package/built/src/logger.js +1 -1
- package/built/src/restclient/errors.js +1 -1
- package/built/src/restclient/errors.js.map +1 -1
- package/built/test/unit/logger.test.js +1 -1
- package/built/umd/index.js +6889 -17107
- package/built/umd/index.js.map +1 -1
- package/changelog.md +12 -1
- package/package.json +7 -6
package/built/cjs/index.js
CHANGED
|
@@ -4,8 +4,9 @@ var require$$0$1 = require('buffer');
|
|
|
4
4
|
var bn_js = require('bn.js');
|
|
5
5
|
var crypto = require('crypto');
|
|
6
6
|
var secp256k1 = require('secp256k1');
|
|
7
|
-
var
|
|
7
|
+
var cloneDeep = require('lodash/cloneDeep');
|
|
8
8
|
var events = require('events');
|
|
9
|
+
var zod = require('zod');
|
|
9
10
|
|
|
10
11
|
function _interopNamespaceDefault(e) {
|
|
11
12
|
var n = Object.create(null);
|
|
@@ -1957,7 +1958,7 @@ const logLevelMap = {
|
|
|
1957
1958
|
[LogLevel.Warning]: 1,
|
|
1958
1959
|
[LogLevel.Info]: 2,
|
|
1959
1960
|
[LogLevel.Debug]: 3,
|
|
1960
|
-
[LogLevel.Error]:
|
|
1961
|
+
[LogLevel.Error]: 0,
|
|
1961
1962
|
[LogLevel.Disabled]: -1,
|
|
1962
1963
|
};
|
|
1963
1964
|
const DEFAULT_LOG_LEVEL = logLevelMap[LogLevel.Warning];
|
|
@@ -2180,7 +2181,7 @@ class UnexpectedResponseError extends Error {
|
|
|
2180
2181
|
}
|
|
2181
2182
|
class InvalidTxRidException extends Error {
|
|
2182
2183
|
constructor(txRID) {
|
|
2183
|
-
super(`expected length 32 of txRID, but got ${txRID.length}`);
|
|
2184
|
+
super(`expected length 32 of txRID, but got ${txRID && txRID.length}`);
|
|
2184
2185
|
}
|
|
2185
2186
|
}
|
|
2186
2187
|
class SerializedTransactionFormatException extends Error {
|
|
@@ -2379,14 +2380,14 @@ class MissingPubKeyError extends Error {
|
|
|
2379
2380
|
super(`No public key was provided`);
|
|
2380
2381
|
}
|
|
2381
2382
|
}
|
|
2382
|
-
class
|
|
2383
|
+
class MissingBlockchainIdentifierError extends Error {
|
|
2383
2384
|
constructor() {
|
|
2384
|
-
super(`No
|
|
2385
|
+
super(`No blockchain identifier was provided. Include either a blockchainRid (string) or a blockchainIid (number).`);
|
|
2385
2386
|
}
|
|
2386
2387
|
}
|
|
2387
2388
|
class MissingNodeUrlError extends Error {
|
|
2388
2389
|
constructor() {
|
|
2389
|
-
super(`No node url or directory node url was provided
|
|
2390
|
+
super(`No node url or directory node url was provided. Include either a nodeUrl (string) or a directory node url (number).`);
|
|
2390
2391
|
}
|
|
2391
2392
|
}
|
|
2392
2393
|
class BlockchainUrlUndefinedException extends Error {
|
|
@@ -2540,6 +2541,193 @@ exports.ResponseStatus = void 0;
|
|
|
2540
2541
|
ResponseStatus["Waiting"] = "waiting";
|
|
2541
2542
|
})(exports.ResponseStatus || (exports.ResponseStatus = {}));
|
|
2542
2543
|
|
|
2544
|
+
const WRONG_STRING_LENGTH = "wrong string length";
|
|
2545
|
+
const BlockIdentifierSchema = zod.z.union([
|
|
2546
|
+
zod.z
|
|
2547
|
+
.string()
|
|
2548
|
+
.refine((val) => /^[0-9a-fA-F]{64}$/.test(val), WRONG_STRING_LENGTH),
|
|
2549
|
+
zod.z.number(),
|
|
2550
|
+
]);
|
|
2551
|
+
const isBlockIdentifierValid = (blockIdentifier, options) => {
|
|
2552
|
+
const ctx = BlockIdentifierSchema.safeParse(blockIdentifier);
|
|
2553
|
+
const { success } = ctx;
|
|
2554
|
+
const hasError = "error" in ctx;
|
|
2555
|
+
const { throwOnError = false } = options || {};
|
|
2556
|
+
if (!hasError) {
|
|
2557
|
+
return { success };
|
|
2558
|
+
}
|
|
2559
|
+
const { error } = ctx;
|
|
2560
|
+
const isInvalidInputType = error.issues.some(({ code }) => code === "invalid_union");
|
|
2561
|
+
const isInvalidStringLength = error.issues.some(({ message }) => message === WRONG_STRING_LENGTH);
|
|
2562
|
+
const message = (() => {
|
|
2563
|
+
if (isInvalidInputType) {
|
|
2564
|
+
return `Invalid "blockIdentifier" type. Expected string or number, but received ${typeof blockIdentifier}.`;
|
|
2565
|
+
}
|
|
2566
|
+
if (isInvalidStringLength) {
|
|
2567
|
+
return "Parameter 'blockIdentifier' does not have the correct format (64-character hexadecimal string).";
|
|
2568
|
+
}
|
|
2569
|
+
return error.issues.map((issue) => issue.message).join(", ");
|
|
2570
|
+
})();
|
|
2571
|
+
if (throwOnError) {
|
|
2572
|
+
throw new Error(message);
|
|
2573
|
+
}
|
|
2574
|
+
return {
|
|
2575
|
+
success,
|
|
2576
|
+
error,
|
|
2577
|
+
message: error.issues.map((issue) => issue.message).join(", "),
|
|
2578
|
+
};
|
|
2579
|
+
};
|
|
2580
|
+
|
|
2581
|
+
const IdentifierSchema = zod.z.union([
|
|
2582
|
+
zod.z.object({
|
|
2583
|
+
blockchainRid: zod.z.undefined(),
|
|
2584
|
+
blockchainIid: zod.z.number(),
|
|
2585
|
+
}),
|
|
2586
|
+
zod.z.object({
|
|
2587
|
+
blockchainRid: zod.z.string(),
|
|
2588
|
+
blockchainIid: zod.z.undefined(),
|
|
2589
|
+
}),
|
|
2590
|
+
]);
|
|
2591
|
+
const NodeUrlSchema = zod.z.union([
|
|
2592
|
+
zod.z.object({
|
|
2593
|
+
nodeUrlPool: zod.z.union([zod.z.string(), zod.z.array(zod.z.string())]),
|
|
2594
|
+
directoryNodeUrlPool: zod.z.undefined(),
|
|
2595
|
+
}),
|
|
2596
|
+
zod.z.object({
|
|
2597
|
+
nodeUrlPool: zod.z.undefined(),
|
|
2598
|
+
directoryNodeUrlPool: zod.z.union([zod.z.string(), zod.z.array(zod.z.string())]),
|
|
2599
|
+
}),
|
|
2600
|
+
]);
|
|
2601
|
+
const RestNetworkSettingsSchema = zod.z.object({
|
|
2602
|
+
statusPollingInterval: zod.z.number().optional(),
|
|
2603
|
+
statusPollingCount: zod.z.number().optional(),
|
|
2604
|
+
failOverConfig: zod.z
|
|
2605
|
+
.object({
|
|
2606
|
+
strategy: zod.z.nativeEnum(exports.FailoverStrategy).optional(),
|
|
2607
|
+
attemptsPerEndpoint: zod.z.number().optional(),
|
|
2608
|
+
attemptInterval: zod.z.number().optional(),
|
|
2609
|
+
unreachableDuration: zod.z.number().optional(),
|
|
2610
|
+
})
|
|
2611
|
+
.optional(),
|
|
2612
|
+
});
|
|
2613
|
+
const validateBlockChainIdentifier = (networkSettings, options) => {
|
|
2614
|
+
const { throwOnError = false } = options || {};
|
|
2615
|
+
const identifierValidationContext = IdentifierSchema.safeParse(networkSettings);
|
|
2616
|
+
if ("error" in identifierValidationContext) {
|
|
2617
|
+
const missingBlockchainIdentifierError = new MissingBlockchainIdentifierError();
|
|
2618
|
+
if (throwOnError) {
|
|
2619
|
+
throw missingBlockchainIdentifierError;
|
|
2620
|
+
}
|
|
2621
|
+
return {
|
|
2622
|
+
success: identifierValidationContext.success,
|
|
2623
|
+
error: identifierValidationContext.error,
|
|
2624
|
+
message: missingBlockchainIdentifierError.message,
|
|
2625
|
+
};
|
|
2626
|
+
}
|
|
2627
|
+
return { success: true };
|
|
2628
|
+
};
|
|
2629
|
+
const validateNodeUrl = (networkSettings, options) => {
|
|
2630
|
+
const { throwOnError = false } = options || {};
|
|
2631
|
+
const nodeUrlValidationContext = NodeUrlSchema.safeParse(networkSettings);
|
|
2632
|
+
if ("error" in nodeUrlValidationContext) {
|
|
2633
|
+
const missingNodeUrlError = new MissingNodeUrlError();
|
|
2634
|
+
if (throwOnError) {
|
|
2635
|
+
throw missingNodeUrlError;
|
|
2636
|
+
}
|
|
2637
|
+
return {
|
|
2638
|
+
success: nodeUrlValidationContext.success,
|
|
2639
|
+
error: nodeUrlValidationContext.error,
|
|
2640
|
+
message: missingNodeUrlError.message,
|
|
2641
|
+
};
|
|
2642
|
+
}
|
|
2643
|
+
return { success: true };
|
|
2644
|
+
};
|
|
2645
|
+
const validateRestNetworkSettings = (networkSettings, options) => {
|
|
2646
|
+
const { throwOnError = false } = options || {};
|
|
2647
|
+
const restNetworkSettingsValidationContext = RestNetworkSettingsSchema.safeParse(networkSettings);
|
|
2648
|
+
if ("error" in restNetworkSettingsValidationContext) {
|
|
2649
|
+
const { error: { issues }, } = restNetworkSettingsValidationContext;
|
|
2650
|
+
const errorMessage = issues
|
|
2651
|
+
.map(({ message, path }) => `${path[0]}: ${message}`)
|
|
2652
|
+
.join(", ");
|
|
2653
|
+
if (throwOnError) {
|
|
2654
|
+
throw new Error(errorMessage);
|
|
2655
|
+
}
|
|
2656
|
+
return {
|
|
2657
|
+
success: restNetworkSettingsValidationContext.success,
|
|
2658
|
+
error: restNetworkSettingsValidationContext.error,
|
|
2659
|
+
message: errorMessage,
|
|
2660
|
+
};
|
|
2661
|
+
}
|
|
2662
|
+
return { success: true };
|
|
2663
|
+
};
|
|
2664
|
+
const isNetworkSettingValid = (networkSettings, options) => {
|
|
2665
|
+
const identifierValidationContext = validateBlockChainIdentifier(networkSettings, options);
|
|
2666
|
+
if ("error" in identifierValidationContext) {
|
|
2667
|
+
return identifierValidationContext;
|
|
2668
|
+
}
|
|
2669
|
+
const nodeUrlValidationContext = validateNodeUrl(networkSettings, options);
|
|
2670
|
+
if ("error" in nodeUrlValidationContext) {
|
|
2671
|
+
return nodeUrlValidationContext;
|
|
2672
|
+
}
|
|
2673
|
+
const restNetworkSettingsValidationContext = validateRestNetworkSettings(networkSettings, options);
|
|
2674
|
+
if ("error" in restNetworkSettingsValidationContext) {
|
|
2675
|
+
return restNetworkSettingsValidationContext;
|
|
2676
|
+
}
|
|
2677
|
+
return { success: true };
|
|
2678
|
+
};
|
|
2679
|
+
|
|
2680
|
+
const BufferSchema = zod.z.instanceof(Buffer);
|
|
2681
|
+
|
|
2682
|
+
const KeyPairSchema = zod.z.object({
|
|
2683
|
+
privKey: BufferSchema,
|
|
2684
|
+
pubKey: BufferSchema,
|
|
2685
|
+
});
|
|
2686
|
+
const SignatureProviderSchema = zod.z.object({
|
|
2687
|
+
pubKey: BufferSchema,
|
|
2688
|
+
sign: zod.z.function().args(BufferSchema).returns(zod.z.promise(BufferSchema)),
|
|
2689
|
+
});
|
|
2690
|
+
const SignMethodSchema = zod.z.union([
|
|
2691
|
+
KeyPairSchema,
|
|
2692
|
+
SignatureProviderSchema,
|
|
2693
|
+
]);
|
|
2694
|
+
const isSignMethodValid = (signMethod, options) => {
|
|
2695
|
+
const signMethodValidationCtx = SignMethodSchema.safeParse(signMethod);
|
|
2696
|
+
const { throwOnError = false } = options || {};
|
|
2697
|
+
const hasError = "error" in signMethodValidationCtx;
|
|
2698
|
+
if (!hasError) {
|
|
2699
|
+
return { success: true };
|
|
2700
|
+
}
|
|
2701
|
+
const message = "Invalid sign method";
|
|
2702
|
+
if (throwOnError) {
|
|
2703
|
+
throw new Error(message);
|
|
2704
|
+
}
|
|
2705
|
+
return {
|
|
2706
|
+
success: false,
|
|
2707
|
+
error: signMethodValidationCtx.error,
|
|
2708
|
+
message,
|
|
2709
|
+
};
|
|
2710
|
+
};
|
|
2711
|
+
|
|
2712
|
+
const TxRidSchema = BufferSchema.refine((x) => x.length === 32, "Rid must be 32 bytes long");
|
|
2713
|
+
const isTxRidValid = (rid, options) => {
|
|
2714
|
+
const TxRidValidationContext = TxRidSchema.safeParse(rid);
|
|
2715
|
+
const { throwOnError = false } = options || {};
|
|
2716
|
+
const hasError = "error" in TxRidValidationContext;
|
|
2717
|
+
if (!hasError) {
|
|
2718
|
+
return { success: true };
|
|
2719
|
+
}
|
|
2720
|
+
const validationError = new InvalidTxRidException(rid);
|
|
2721
|
+
if (throwOnError) {
|
|
2722
|
+
throw validationError;
|
|
2723
|
+
}
|
|
2724
|
+
return {
|
|
2725
|
+
success: false,
|
|
2726
|
+
error: TxRidValidationContext.error,
|
|
2727
|
+
message: validationError.message,
|
|
2728
|
+
};
|
|
2729
|
+
};
|
|
2730
|
+
|
|
2543
2731
|
var __awaiter$7 = (undefined && undefined.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2544
2732
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
2545
2733
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -2551,6 +2739,7 @@ var __awaiter$7 = (undefined && undefined.__awaiter) || function (thisArg, _argu
|
|
|
2551
2739
|
};
|
|
2552
2740
|
function createClient(settings) {
|
|
2553
2741
|
return __awaiter$7(this, void 0, void 0, function* () {
|
|
2742
|
+
isNetworkSettingValid(settings, { throwOnError: true });
|
|
2554
2743
|
return {
|
|
2555
2744
|
config: yield getClientConfigFromSettings(settings),
|
|
2556
2745
|
query(nameOrQueryObject, args, callback) {
|
|
@@ -2658,6 +2847,7 @@ function createClient(settings) {
|
|
|
2658
2847
|
return promiEvent;
|
|
2659
2848
|
},
|
|
2660
2849
|
signAndSendUniqueTransaction(transactionOrOperation, signMethod, doStatusPolling = true, callback = undefined) {
|
|
2850
|
+
isSignMethodValid(signMethod, { throwOnError: true });
|
|
2661
2851
|
const promiEvent = new Web3PromiEvent((resolve, reject) => {
|
|
2662
2852
|
const transaction = "name" in transactionOrOperation
|
|
2663
2853
|
? {
|
|
@@ -2687,11 +2877,12 @@ function createClient(settings) {
|
|
|
2687
2877
|
},
|
|
2688
2878
|
getTransaction(transactionRid, callback) {
|
|
2689
2879
|
return __awaiter$7(this, void 0, void 0, function* () {
|
|
2690
|
-
|
|
2691
|
-
|
|
2692
|
-
|
|
2693
|
-
|
|
2694
|
-
|
|
2880
|
+
try {
|
|
2881
|
+
isTxRidValid(transactionRid, { throwOnError: true });
|
|
2882
|
+
}
|
|
2883
|
+
catch (error) {
|
|
2884
|
+
callback === null || callback === void 0 ? void 0 : callback(error, null);
|
|
2885
|
+
throw error;
|
|
2695
2886
|
}
|
|
2696
2887
|
const { error, statusCode, rspBody } = yield requestWithRetry(Method.GET, `tx/${this.config.blockchainRid}/${transactionRid.toString("hex")}`, this.config);
|
|
2697
2888
|
return new Promise((resolve, reject) => {
|
|
@@ -2701,11 +2892,11 @@ function createClient(settings) {
|
|
|
2701
2892
|
},
|
|
2702
2893
|
getTransactionStatus(transactionRid, callback) {
|
|
2703
2894
|
return __awaiter$7(this, void 0, void 0, function* () {
|
|
2704
|
-
|
|
2705
|
-
|
|
2706
|
-
|
|
2707
|
-
|
|
2708
|
-
|
|
2895
|
+
try {
|
|
2896
|
+
isTxRidValid(transactionRid, { throwOnError: true });
|
|
2897
|
+
}
|
|
2898
|
+
catch (error) {
|
|
2899
|
+
callback === null || callback === void 0 ? void 0 : callback(error, null);
|
|
2709
2900
|
throw error;
|
|
2710
2901
|
}
|
|
2711
2902
|
const { error, statusCode, rspBody } = yield requestWithRetry(Method.GET, `tx/${this.config.blockchainRid}/${transactionRid.toString("hex")}/status`, this.config);
|
|
@@ -2715,7 +2906,7 @@ function createClient(settings) {
|
|
|
2715
2906
|
});
|
|
2716
2907
|
},
|
|
2717
2908
|
addNop(transaction) {
|
|
2718
|
-
const _transaction =
|
|
2909
|
+
const _transaction = cloneDeep(transaction);
|
|
2719
2910
|
const noOperation = {
|
|
2720
2911
|
name: "nop",
|
|
2721
2912
|
args: [crypto.randomBytes(32)],
|
|
@@ -2747,6 +2938,13 @@ function createClient(settings) {
|
|
|
2747
2938
|
},
|
|
2748
2939
|
getTransactionInfo(transactionRid, callback) {
|
|
2749
2940
|
return __awaiter$7(this, void 0, void 0, function* () {
|
|
2941
|
+
try {
|
|
2942
|
+
isTxRidValid(transactionRid, { throwOnError: true });
|
|
2943
|
+
}
|
|
2944
|
+
catch (error) {
|
|
2945
|
+
callback === null || callback === void 0 ? void 0 : callback(error, null);
|
|
2946
|
+
throw error;
|
|
2947
|
+
}
|
|
2750
2948
|
const { error, statusCode, rspBody, } = yield requestWithRetry(Method.GET, `transactions/${this.config.blockchainRid}/${toString(transactionRid)}`, this.config);
|
|
2751
2949
|
return new Promise((resolve, reject) => {
|
|
2752
2950
|
handleGetResponse(error, statusCode, statusCode === 200 ? formatTransactionInfoResponse(rspBody) : rspBody, callbackPromiseBuilder(reject, resolve, callback));
|
|
@@ -2763,14 +2961,7 @@ function createClient(settings) {
|
|
|
2763
2961
|
},
|
|
2764
2962
|
getBlockInfo(blockIdentifier, txs = false, callback) {
|
|
2765
2963
|
return __awaiter$7(this, void 0, void 0, function* () {
|
|
2766
|
-
|
|
2767
|
-
typeof blockIdentifier !== "number") {
|
|
2768
|
-
throw new TypeError(`Invalid "blockIdentifier" type. Expected string or number, but received ${typeof blockIdentifier}.`);
|
|
2769
|
-
}
|
|
2770
|
-
else if (typeof blockIdentifier === "string" &&
|
|
2771
|
-
!/^[0-9a-fA-F]{64}$/.test(blockIdentifier)) {
|
|
2772
|
-
throw new TypeError("Parameter 'blockIdentifier' does not have the correct format (64-character hexadecimal string).");
|
|
2773
|
-
}
|
|
2964
|
+
isBlockIdentifierValid(blockIdentifier, { throwOnError: true });
|
|
2774
2965
|
const queryString = typeof blockIdentifier === "string"
|
|
2775
2966
|
? blockIdentifier
|
|
2776
2967
|
: `height/${blockIdentifier}`;
|
|
@@ -2837,40 +3028,40 @@ function createClient(settings) {
|
|
|
2837
3028
|
*/
|
|
2838
3029
|
getConfirmationProof: function (txRid, callback) {
|
|
2839
3030
|
return __awaiter$7(this, void 0, void 0, function* () {
|
|
2840
|
-
|
|
2841
|
-
|
|
2842
|
-
callback(new InvalidTxRidException(txRid), null);
|
|
2843
|
-
}
|
|
2844
|
-
throw new InvalidTxRidException(txRid);
|
|
3031
|
+
try {
|
|
3032
|
+
isTxRidValid(txRid, { throwOnError: true });
|
|
2845
3033
|
}
|
|
2846
|
-
|
|
2847
|
-
|
|
2848
|
-
|
|
2849
|
-
|
|
2850
|
-
|
|
2851
|
-
|
|
2852
|
-
|
|
2853
|
-
|
|
2854
|
-
|
|
2855
|
-
|
|
2856
|
-
|
|
2857
|
-
|
|
2858
|
-
|
|
2859
|
-
|
|
2860
|
-
|
|
2861
|
-
|
|
2862
|
-
|
|
2863
|
-
|
|
2864
|
-
|
|
2865
|
-
|
|
2866
|
-
|
|
2867
|
-
|
|
3034
|
+
catch (error) {
|
|
3035
|
+
callback === null || callback === void 0 ? void 0 : callback(error, null);
|
|
3036
|
+
throw error;
|
|
3037
|
+
}
|
|
3038
|
+
const { error, statusCode, rspBody } = yield requestWithRetry(Method.GET, `tx/${this.config.blockchainRid}/${txRid.toString("hex")}/confirmationProof`, this.config);
|
|
3039
|
+
const confirmationProof = {
|
|
3040
|
+
hash: undefined,
|
|
3041
|
+
blockHeader: undefined,
|
|
3042
|
+
witness: undefined,
|
|
3043
|
+
merkleProofTree: "",
|
|
3044
|
+
txIndex: 0,
|
|
3045
|
+
};
|
|
3046
|
+
if (statusCode === 200) {
|
|
3047
|
+
try {
|
|
3048
|
+
const decodedProof = decodeValue(toBuffer(rspBody.proof));
|
|
3049
|
+
confirmationProof.txIndex = decodedProof.txIndex;
|
|
3050
|
+
confirmationProof.hash = decodedProof.hash;
|
|
3051
|
+
confirmationProof.blockHeader = decodedProof.blockHeader;
|
|
3052
|
+
confirmationProof.witness = decodedProof.witness;
|
|
3053
|
+
confirmationProof.merkleProofTree = decodedProof.merkleProofTree;
|
|
3054
|
+
}
|
|
3055
|
+
catch (decodeError) {
|
|
3056
|
+
if (callback) {
|
|
3057
|
+
callback(decodeError, null);
|
|
2868
3058
|
}
|
|
3059
|
+
throw decodeError;
|
|
2869
3060
|
}
|
|
2870
|
-
return new Promise((resolve, reject) => {
|
|
2871
|
-
handleGetResponse(error, statusCode, statusCode === 200 ? confirmationProof : rspBody, callbackPromiseBuilder(reject, resolve, callback));
|
|
2872
|
-
});
|
|
2873
3061
|
}
|
|
3062
|
+
return new Promise((resolve, reject) => {
|
|
3063
|
+
handleGetResponse(error, statusCode, statusCode === 200 ? confirmationProof : rspBody, callbackPromiseBuilder(reject, resolve, callback));
|
|
3064
|
+
});
|
|
2874
3065
|
});
|
|
2875
3066
|
},
|
|
2876
3067
|
};
|
|
@@ -2891,13 +3082,6 @@ require("web3-core-promievent");
|
|
|
2891
3082
|
function getClientConfigFromSettings(settings) {
|
|
2892
3083
|
var _a, _b, _c, _d;
|
|
2893
3084
|
return __awaiter$6(this, void 0, void 0, function* () {
|
|
2894
|
-
if (!settings.nodeUrlPool && !settings.directoryNodeUrlPool) {
|
|
2895
|
-
throw new MissingNodeUrlError();
|
|
2896
|
-
}
|
|
2897
|
-
if (!settings.blockchainRid &&
|
|
2898
|
-
typeof settings.blockchainIid === "undefined") {
|
|
2899
|
-
throw new MissingBlockchainError();
|
|
2900
|
-
}
|
|
2901
3085
|
const nodeUrlPoolToUse = yield getNodeUrlsFromSettings(settings);
|
|
2902
3086
|
const endpointPool = createEndpointObjects(nodeUrlPoolToUse);
|
|
2903
3087
|
const blockchainRidToUse = settings.blockchainRid ||
|
|
@@ -2917,21 +3101,13 @@ function getClientConfigFromSettings(settings) {
|
|
|
2917
3101
|
};
|
|
2918
3102
|
});
|
|
2919
3103
|
}
|
|
2920
|
-
function validTxRid(txRID) {
|
|
2921
|
-
if (txRID.length != 32) {
|
|
2922
|
-
const error$1 = new InvalidTxRidException(txRID);
|
|
2923
|
-
error(error$1.toString());
|
|
2924
|
-
return false;
|
|
2925
|
-
}
|
|
2926
|
-
return true;
|
|
2927
|
-
}
|
|
2928
3104
|
function nodeDiscovery(directoryEndpointPool, failOverConfig, blockchainRid, blockchainIid) {
|
|
2929
3105
|
return __awaiter$6(this, void 0, void 0, function* () {
|
|
2930
3106
|
if (directoryEndpointPool.length === 0) {
|
|
2931
3107
|
throw new DirectoryNodeUrlPoolException();
|
|
2932
3108
|
}
|
|
2933
3109
|
if (!(blockchainRid || blockchainIid != undefined)) {
|
|
2934
|
-
throw new
|
|
3110
|
+
throw new MissingBlockchainIdentifierError();
|
|
2935
3111
|
}
|
|
2936
3112
|
const directoryIid = 0;
|
|
2937
3113
|
const directoryBRID = yield getBlockchainRidFromIid(directoryEndpointPool, directoryIid, failOverConfig);
|
|
@@ -2939,7 +3115,7 @@ function nodeDiscovery(directoryEndpointPool, failOverConfig, blockchainRid, blo
|
|
|
2939
3115
|
(yield getBlockchainRidFromIid(directoryEndpointPool, blockchainIid, failOverConfig));
|
|
2940
3116
|
const queryObject = {
|
|
2941
3117
|
name: "cm_get_blockchain_api_urls",
|
|
2942
|
-
args: { blockchain_rid: blockchainRidToUse },
|
|
3118
|
+
args: { blockchain_rid: toBuffer(blockchainRidToUse) },
|
|
2943
3119
|
};
|
|
2944
3120
|
const D1Client = yield createClient({
|
|
2945
3121
|
nodeUrlPool: getUrlsFromEndpoints(directoryEndpointPool),
|
|
@@ -3963,7 +4139,7 @@ exports.InvalidBlockchainRIDException = InvalidBlockchainRIDException;
|
|
|
3963
4139
|
exports.InvalidTransactionFormatException = InvalidTransactionFormatException;
|
|
3964
4140
|
exports.InvalidTxRidException = InvalidTxRidException;
|
|
3965
4141
|
exports.LostMessageError = LostMessageError;
|
|
3966
|
-
exports.
|
|
4142
|
+
exports.MissingBlockchainIdentifierError = MissingBlockchainIdentifierError;
|
|
3967
4143
|
exports.MissingGtxException = MissingGtxException;
|
|
3968
4144
|
exports.MissingNodeUrlError = MissingNodeUrlError;
|
|
3969
4145
|
exports.MissingPrivKeyArgumentException = MissingPrivKeyArgumentException;
|