postchain-client 1.13.0 → 1.15.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/README.md +3 -2
- package/built/cjs/index.js +257 -76
- package/built/cjs/index.js.map +1 -1
- package/built/esm/index.js +6934 -17148
- package/built/esm/index.js.map +1 -1
- package/built/index.d.ts +2 -2
- package/built/index.js +1 -1
- package/built/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/types.d.ts +2 -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/gtx/gtx.js +7 -3
- package/built/src/gtx/gtx.js.map +1 -1
- package/built/src/gtx/interfaces.d.ts +4 -4
- 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 +6896 -17109
- package/built/umd/index.js.map +1 -1
- package/changelog.md +20 -1
- package/package.json +6 -5
package/README.md
CHANGED
|
@@ -317,8 +317,9 @@ chromiaClient
|
|
|
317
317
|
This example demonstrates that you can use external signing mechanisms. It could involve a complex function requiring you to sign from your phone, another device, or a different method.
|
|
318
318
|
|
|
319
319
|
```typescript
|
|
320
|
-
function askUserBToSign(
|
|
321
|
-
|
|
320
|
+
function askUserBToSign(rawGtxBody) {
|
|
321
|
+
const digest = getDigestToSignFromRawGtxBody(rawGtxBody);
|
|
322
|
+
return Buffer.from(secp256k1.ecdsaSign(digest, signerPrivKeyB).signature);
|
|
322
323
|
}
|
|
323
324
|
```
|
|
324
325
|
|
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);
|
|
@@ -1763,8 +1764,9 @@ function sign(gtx, privOrSigProv, pubKey) {
|
|
|
1763
1764
|
return addSignature(pubKey || makeKeyPair(privOrSigProv).pubKey, signature, gtx);
|
|
1764
1765
|
}
|
|
1765
1766
|
else {
|
|
1766
|
-
|
|
1767
|
-
const
|
|
1767
|
+
// Removes signatures and extract the rawgtxBody
|
|
1768
|
+
const rawGtxBody = gtxToRawGtxBody(gtx);
|
|
1769
|
+
const signature = yield privOrSigProv.sign(rawGtxBody);
|
|
1768
1770
|
return addSignature(privOrSigProv.pubKey, signature, gtx);
|
|
1769
1771
|
}
|
|
1770
1772
|
});
|
|
@@ -1847,7 +1849,10 @@ function newSignatureProvider(keyPair) {
|
|
|
1847
1849
|
}
|
|
1848
1850
|
return {
|
|
1849
1851
|
pubKey: pub,
|
|
1850
|
-
sign: (
|
|
1852
|
+
sign: (gtx) => __awaiter$c(this, void 0, void 0, function* () {
|
|
1853
|
+
const signature = getDigestToSignFromRawGtxBody(gtx);
|
|
1854
|
+
return signDigest(signature, priv);
|
|
1855
|
+
}),
|
|
1851
1856
|
};
|
|
1852
1857
|
}
|
|
1853
1858
|
function rawGtvToGtx(gtv) {
|
|
@@ -1957,7 +1962,7 @@ const logLevelMap = {
|
|
|
1957
1962
|
[LogLevel.Warning]: 1,
|
|
1958
1963
|
[LogLevel.Info]: 2,
|
|
1959
1964
|
[LogLevel.Debug]: 3,
|
|
1960
|
-
[LogLevel.Error]:
|
|
1965
|
+
[LogLevel.Error]: 0,
|
|
1961
1966
|
[LogLevel.Disabled]: -1,
|
|
1962
1967
|
};
|
|
1963
1968
|
const DEFAULT_LOG_LEVEL = logLevelMap[LogLevel.Warning];
|
|
@@ -2180,7 +2185,7 @@ class UnexpectedResponseError extends Error {
|
|
|
2180
2185
|
}
|
|
2181
2186
|
class InvalidTxRidException extends Error {
|
|
2182
2187
|
constructor(txRID) {
|
|
2183
|
-
super(`expected length 32 of txRID, but got ${txRID.length}`);
|
|
2188
|
+
super(`expected length 32 of txRID, but got ${txRID && txRID.length}`);
|
|
2184
2189
|
}
|
|
2185
2190
|
}
|
|
2186
2191
|
class SerializedTransactionFormatException extends Error {
|
|
@@ -2379,14 +2384,14 @@ class MissingPubKeyError extends Error {
|
|
|
2379
2384
|
super(`No public key was provided`);
|
|
2380
2385
|
}
|
|
2381
2386
|
}
|
|
2382
|
-
class
|
|
2387
|
+
class MissingBlockchainIdentifierError extends Error {
|
|
2383
2388
|
constructor() {
|
|
2384
|
-
super(`No
|
|
2389
|
+
super(`No blockchain identifier was provided. Include either a blockchainRid (string) or a blockchainIid (number).`);
|
|
2385
2390
|
}
|
|
2386
2391
|
}
|
|
2387
2392
|
class MissingNodeUrlError extends Error {
|
|
2388
2393
|
constructor() {
|
|
2389
|
-
super(`No node url or directory node url was provided
|
|
2394
|
+
super(`No node url or directory node url was provided. Include either a nodeUrl (string) or a directory node url (number).`);
|
|
2390
2395
|
}
|
|
2391
2396
|
}
|
|
2392
2397
|
class BlockchainUrlUndefinedException extends Error {
|
|
@@ -2540,6 +2545,193 @@ exports.ResponseStatus = void 0;
|
|
|
2540
2545
|
ResponseStatus["Waiting"] = "waiting";
|
|
2541
2546
|
})(exports.ResponseStatus || (exports.ResponseStatus = {}));
|
|
2542
2547
|
|
|
2548
|
+
const WRONG_STRING_LENGTH = "wrong string length";
|
|
2549
|
+
const BlockIdentifierSchema = zod.z.union([
|
|
2550
|
+
zod.z
|
|
2551
|
+
.string()
|
|
2552
|
+
.refine((val) => /^[0-9a-fA-F]{64}$/.test(val), WRONG_STRING_LENGTH),
|
|
2553
|
+
zod.z.number(),
|
|
2554
|
+
]);
|
|
2555
|
+
const isBlockIdentifierValid = (blockIdentifier, options) => {
|
|
2556
|
+
const ctx = BlockIdentifierSchema.safeParse(blockIdentifier);
|
|
2557
|
+
const { success } = ctx;
|
|
2558
|
+
const hasError = "error" in ctx;
|
|
2559
|
+
const { throwOnError = false } = options || {};
|
|
2560
|
+
if (!hasError) {
|
|
2561
|
+
return { success };
|
|
2562
|
+
}
|
|
2563
|
+
const { error } = ctx;
|
|
2564
|
+
const isInvalidInputType = error.issues.some(({ code }) => code === "invalid_union");
|
|
2565
|
+
const isInvalidStringLength = error.issues.some(({ message }) => message === WRONG_STRING_LENGTH);
|
|
2566
|
+
const message = (() => {
|
|
2567
|
+
if (isInvalidInputType) {
|
|
2568
|
+
return `Invalid "blockIdentifier" type. Expected string or number, but received ${typeof blockIdentifier}.`;
|
|
2569
|
+
}
|
|
2570
|
+
if (isInvalidStringLength) {
|
|
2571
|
+
return "Parameter 'blockIdentifier' does not have the correct format (64-character hexadecimal string).";
|
|
2572
|
+
}
|
|
2573
|
+
return error.issues.map((issue) => issue.message).join(", ");
|
|
2574
|
+
})();
|
|
2575
|
+
if (throwOnError) {
|
|
2576
|
+
throw new Error(message);
|
|
2577
|
+
}
|
|
2578
|
+
return {
|
|
2579
|
+
success,
|
|
2580
|
+
error,
|
|
2581
|
+
message: error.issues.map((issue) => issue.message).join(", "),
|
|
2582
|
+
};
|
|
2583
|
+
};
|
|
2584
|
+
|
|
2585
|
+
const IdentifierSchema = zod.z.union([
|
|
2586
|
+
zod.z.object({
|
|
2587
|
+
blockchainRid: zod.z.undefined(),
|
|
2588
|
+
blockchainIid: zod.z.number(),
|
|
2589
|
+
}),
|
|
2590
|
+
zod.z.object({
|
|
2591
|
+
blockchainRid: zod.z.string(),
|
|
2592
|
+
blockchainIid: zod.z.undefined(),
|
|
2593
|
+
}),
|
|
2594
|
+
]);
|
|
2595
|
+
const NodeUrlSchema = zod.z.union([
|
|
2596
|
+
zod.z.object({
|
|
2597
|
+
nodeUrlPool: zod.z.union([zod.z.string(), zod.z.array(zod.z.string())]),
|
|
2598
|
+
directoryNodeUrlPool: zod.z.undefined(),
|
|
2599
|
+
}),
|
|
2600
|
+
zod.z.object({
|
|
2601
|
+
nodeUrlPool: zod.z.undefined(),
|
|
2602
|
+
directoryNodeUrlPool: zod.z.union([zod.z.string(), zod.z.array(zod.z.string())]),
|
|
2603
|
+
}),
|
|
2604
|
+
]);
|
|
2605
|
+
const RestNetworkSettingsSchema = zod.z.object({
|
|
2606
|
+
statusPollingInterval: zod.z.number().optional(),
|
|
2607
|
+
statusPollingCount: zod.z.number().optional(),
|
|
2608
|
+
failOverConfig: zod.z
|
|
2609
|
+
.object({
|
|
2610
|
+
strategy: zod.z.nativeEnum(exports.FailoverStrategy).optional(),
|
|
2611
|
+
attemptsPerEndpoint: zod.z.number().optional(),
|
|
2612
|
+
attemptInterval: zod.z.number().optional(),
|
|
2613
|
+
unreachableDuration: zod.z.number().optional(),
|
|
2614
|
+
})
|
|
2615
|
+
.optional(),
|
|
2616
|
+
});
|
|
2617
|
+
const validateBlockChainIdentifier = (networkSettings, options) => {
|
|
2618
|
+
const { throwOnError = false } = options || {};
|
|
2619
|
+
const identifierValidationContext = IdentifierSchema.safeParse(networkSettings);
|
|
2620
|
+
if ("error" in identifierValidationContext) {
|
|
2621
|
+
const missingBlockchainIdentifierError = new MissingBlockchainIdentifierError();
|
|
2622
|
+
if (throwOnError) {
|
|
2623
|
+
throw missingBlockchainIdentifierError;
|
|
2624
|
+
}
|
|
2625
|
+
return {
|
|
2626
|
+
success: identifierValidationContext.success,
|
|
2627
|
+
error: identifierValidationContext.error,
|
|
2628
|
+
message: missingBlockchainIdentifierError.message,
|
|
2629
|
+
};
|
|
2630
|
+
}
|
|
2631
|
+
return { success: true };
|
|
2632
|
+
};
|
|
2633
|
+
const validateNodeUrl = (networkSettings, options) => {
|
|
2634
|
+
const { throwOnError = false } = options || {};
|
|
2635
|
+
const nodeUrlValidationContext = NodeUrlSchema.safeParse(networkSettings);
|
|
2636
|
+
if ("error" in nodeUrlValidationContext) {
|
|
2637
|
+
const missingNodeUrlError = new MissingNodeUrlError();
|
|
2638
|
+
if (throwOnError) {
|
|
2639
|
+
throw missingNodeUrlError;
|
|
2640
|
+
}
|
|
2641
|
+
return {
|
|
2642
|
+
success: nodeUrlValidationContext.success,
|
|
2643
|
+
error: nodeUrlValidationContext.error,
|
|
2644
|
+
message: missingNodeUrlError.message,
|
|
2645
|
+
};
|
|
2646
|
+
}
|
|
2647
|
+
return { success: true };
|
|
2648
|
+
};
|
|
2649
|
+
const validateRestNetworkSettings = (networkSettings, options) => {
|
|
2650
|
+
const { throwOnError = false } = options || {};
|
|
2651
|
+
const restNetworkSettingsValidationContext = RestNetworkSettingsSchema.safeParse(networkSettings);
|
|
2652
|
+
if ("error" in restNetworkSettingsValidationContext) {
|
|
2653
|
+
const { error: { issues }, } = restNetworkSettingsValidationContext;
|
|
2654
|
+
const errorMessage = issues
|
|
2655
|
+
.map(({ message, path }) => `${path[0]}: ${message}`)
|
|
2656
|
+
.join(", ");
|
|
2657
|
+
if (throwOnError) {
|
|
2658
|
+
throw new Error(errorMessage);
|
|
2659
|
+
}
|
|
2660
|
+
return {
|
|
2661
|
+
success: restNetworkSettingsValidationContext.success,
|
|
2662
|
+
error: restNetworkSettingsValidationContext.error,
|
|
2663
|
+
message: errorMessage,
|
|
2664
|
+
};
|
|
2665
|
+
}
|
|
2666
|
+
return { success: true };
|
|
2667
|
+
};
|
|
2668
|
+
const isNetworkSettingValid = (networkSettings, options) => {
|
|
2669
|
+
const identifierValidationContext = validateBlockChainIdentifier(networkSettings, options);
|
|
2670
|
+
if ("error" in identifierValidationContext) {
|
|
2671
|
+
return identifierValidationContext;
|
|
2672
|
+
}
|
|
2673
|
+
const nodeUrlValidationContext = validateNodeUrl(networkSettings, options);
|
|
2674
|
+
if ("error" in nodeUrlValidationContext) {
|
|
2675
|
+
return nodeUrlValidationContext;
|
|
2676
|
+
}
|
|
2677
|
+
const restNetworkSettingsValidationContext = validateRestNetworkSettings(networkSettings, options);
|
|
2678
|
+
if ("error" in restNetworkSettingsValidationContext) {
|
|
2679
|
+
return restNetworkSettingsValidationContext;
|
|
2680
|
+
}
|
|
2681
|
+
return { success: true };
|
|
2682
|
+
};
|
|
2683
|
+
|
|
2684
|
+
const BufferSchema = zod.z.instanceof(Buffer);
|
|
2685
|
+
|
|
2686
|
+
const KeyPairSchema = zod.z.object({
|
|
2687
|
+
privKey: BufferSchema,
|
|
2688
|
+
pubKey: BufferSchema,
|
|
2689
|
+
});
|
|
2690
|
+
const SignatureProviderSchema = zod.z.object({
|
|
2691
|
+
pubKey: BufferSchema,
|
|
2692
|
+
sign: zod.z.function().args(BufferSchema).returns(zod.z.promise(BufferSchema)),
|
|
2693
|
+
});
|
|
2694
|
+
const SignMethodSchema = zod.z.union([
|
|
2695
|
+
KeyPairSchema,
|
|
2696
|
+
SignatureProviderSchema,
|
|
2697
|
+
]);
|
|
2698
|
+
const isSignMethodValid = (signMethod, options) => {
|
|
2699
|
+
const signMethodValidationCtx = SignMethodSchema.safeParse(signMethod);
|
|
2700
|
+
const { throwOnError = false } = options || {};
|
|
2701
|
+
const hasError = "error" in signMethodValidationCtx;
|
|
2702
|
+
if (!hasError) {
|
|
2703
|
+
return { success: true };
|
|
2704
|
+
}
|
|
2705
|
+
const message = "Invalid sign method";
|
|
2706
|
+
if (throwOnError) {
|
|
2707
|
+
throw new Error(message);
|
|
2708
|
+
}
|
|
2709
|
+
return {
|
|
2710
|
+
success: false,
|
|
2711
|
+
error: signMethodValidationCtx.error,
|
|
2712
|
+
message,
|
|
2713
|
+
};
|
|
2714
|
+
};
|
|
2715
|
+
|
|
2716
|
+
const TxRidSchema = BufferSchema.refine((x) => x.length === 32, "Rid must be 32 bytes long");
|
|
2717
|
+
const isTxRidValid = (rid, options) => {
|
|
2718
|
+
const TxRidValidationContext = TxRidSchema.safeParse(rid);
|
|
2719
|
+
const { throwOnError = false } = options || {};
|
|
2720
|
+
const hasError = "error" in TxRidValidationContext;
|
|
2721
|
+
if (!hasError) {
|
|
2722
|
+
return { success: true };
|
|
2723
|
+
}
|
|
2724
|
+
const validationError = new InvalidTxRidException(rid);
|
|
2725
|
+
if (throwOnError) {
|
|
2726
|
+
throw validationError;
|
|
2727
|
+
}
|
|
2728
|
+
return {
|
|
2729
|
+
success: false,
|
|
2730
|
+
error: TxRidValidationContext.error,
|
|
2731
|
+
message: validationError.message,
|
|
2732
|
+
};
|
|
2733
|
+
};
|
|
2734
|
+
|
|
2543
2735
|
var __awaiter$7 = (undefined && undefined.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2544
2736
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
2545
2737
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -2551,6 +2743,7 @@ var __awaiter$7 = (undefined && undefined.__awaiter) || function (thisArg, _argu
|
|
|
2551
2743
|
};
|
|
2552
2744
|
function createClient(settings) {
|
|
2553
2745
|
return __awaiter$7(this, void 0, void 0, function* () {
|
|
2746
|
+
isNetworkSettingValid(settings, { throwOnError: true });
|
|
2554
2747
|
return {
|
|
2555
2748
|
config: yield getClientConfigFromSettings(settings),
|
|
2556
2749
|
query(nameOrQueryObject, args, callback) {
|
|
@@ -2658,6 +2851,7 @@ function createClient(settings) {
|
|
|
2658
2851
|
return promiEvent;
|
|
2659
2852
|
},
|
|
2660
2853
|
signAndSendUniqueTransaction(transactionOrOperation, signMethod, doStatusPolling = true, callback = undefined) {
|
|
2854
|
+
isSignMethodValid(signMethod, { throwOnError: true });
|
|
2661
2855
|
const promiEvent = new Web3PromiEvent((resolve, reject) => {
|
|
2662
2856
|
const transaction = "name" in transactionOrOperation
|
|
2663
2857
|
? {
|
|
@@ -2687,11 +2881,12 @@ function createClient(settings) {
|
|
|
2687
2881
|
},
|
|
2688
2882
|
getTransaction(transactionRid, callback) {
|
|
2689
2883
|
return __awaiter$7(this, void 0, void 0, function* () {
|
|
2690
|
-
|
|
2691
|
-
|
|
2692
|
-
|
|
2693
|
-
|
|
2694
|
-
|
|
2884
|
+
try {
|
|
2885
|
+
isTxRidValid(transactionRid, { throwOnError: true });
|
|
2886
|
+
}
|
|
2887
|
+
catch (error) {
|
|
2888
|
+
callback === null || callback === void 0 ? void 0 : callback(error, null);
|
|
2889
|
+
throw error;
|
|
2695
2890
|
}
|
|
2696
2891
|
const { error, statusCode, rspBody } = yield requestWithRetry(Method.GET, `tx/${this.config.blockchainRid}/${transactionRid.toString("hex")}`, this.config);
|
|
2697
2892
|
return new Promise((resolve, reject) => {
|
|
@@ -2701,11 +2896,11 @@ function createClient(settings) {
|
|
|
2701
2896
|
},
|
|
2702
2897
|
getTransactionStatus(transactionRid, callback) {
|
|
2703
2898
|
return __awaiter$7(this, void 0, void 0, function* () {
|
|
2704
|
-
|
|
2705
|
-
|
|
2706
|
-
|
|
2707
|
-
|
|
2708
|
-
|
|
2899
|
+
try {
|
|
2900
|
+
isTxRidValid(transactionRid, { throwOnError: true });
|
|
2901
|
+
}
|
|
2902
|
+
catch (error) {
|
|
2903
|
+
callback === null || callback === void 0 ? void 0 : callback(error, null);
|
|
2709
2904
|
throw error;
|
|
2710
2905
|
}
|
|
2711
2906
|
const { error, statusCode, rspBody } = yield requestWithRetry(Method.GET, `tx/${this.config.blockchainRid}/${transactionRid.toString("hex")}/status`, this.config);
|
|
@@ -2715,7 +2910,7 @@ function createClient(settings) {
|
|
|
2715
2910
|
});
|
|
2716
2911
|
},
|
|
2717
2912
|
addNop(transaction) {
|
|
2718
|
-
const _transaction =
|
|
2913
|
+
const _transaction = cloneDeep(transaction);
|
|
2719
2914
|
const noOperation = {
|
|
2720
2915
|
name: "nop",
|
|
2721
2916
|
args: [crypto.randomBytes(32)],
|
|
@@ -2747,6 +2942,13 @@ function createClient(settings) {
|
|
|
2747
2942
|
},
|
|
2748
2943
|
getTransactionInfo(transactionRid, callback) {
|
|
2749
2944
|
return __awaiter$7(this, void 0, void 0, function* () {
|
|
2945
|
+
try {
|
|
2946
|
+
isTxRidValid(transactionRid, { throwOnError: true });
|
|
2947
|
+
}
|
|
2948
|
+
catch (error) {
|
|
2949
|
+
callback === null || callback === void 0 ? void 0 : callback(error, null);
|
|
2950
|
+
throw error;
|
|
2951
|
+
}
|
|
2750
2952
|
const { error, statusCode, rspBody, } = yield requestWithRetry(Method.GET, `transactions/${this.config.blockchainRid}/${toString(transactionRid)}`, this.config);
|
|
2751
2953
|
return new Promise((resolve, reject) => {
|
|
2752
2954
|
handleGetResponse(error, statusCode, statusCode === 200 ? formatTransactionInfoResponse(rspBody) : rspBody, callbackPromiseBuilder(reject, resolve, callback));
|
|
@@ -2763,14 +2965,7 @@ function createClient(settings) {
|
|
|
2763
2965
|
},
|
|
2764
2966
|
getBlockInfo(blockIdentifier, txs = false, callback) {
|
|
2765
2967
|
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
|
-
}
|
|
2968
|
+
isBlockIdentifierValid(blockIdentifier, { throwOnError: true });
|
|
2774
2969
|
const queryString = typeof blockIdentifier === "string"
|
|
2775
2970
|
? blockIdentifier
|
|
2776
2971
|
: `height/${blockIdentifier}`;
|
|
@@ -2837,40 +3032,40 @@ function createClient(settings) {
|
|
|
2837
3032
|
*/
|
|
2838
3033
|
getConfirmationProof: function (txRid, callback) {
|
|
2839
3034
|
return __awaiter$7(this, void 0, void 0, function* () {
|
|
2840
|
-
|
|
2841
|
-
|
|
2842
|
-
callback(new InvalidTxRidException(txRid), null);
|
|
2843
|
-
}
|
|
2844
|
-
throw new InvalidTxRidException(txRid);
|
|
3035
|
+
try {
|
|
3036
|
+
isTxRidValid(txRid, { throwOnError: true });
|
|
2845
3037
|
}
|
|
2846
|
-
|
|
2847
|
-
|
|
2848
|
-
|
|
2849
|
-
|
|
2850
|
-
|
|
2851
|
-
|
|
2852
|
-
|
|
2853
|
-
|
|
2854
|
-
|
|
2855
|
-
|
|
2856
|
-
|
|
2857
|
-
|
|
2858
|
-
|
|
2859
|
-
|
|
2860
|
-
|
|
2861
|
-
|
|
2862
|
-
|
|
2863
|
-
|
|
2864
|
-
|
|
2865
|
-
|
|
2866
|
-
|
|
2867
|
-
|
|
3038
|
+
catch (error) {
|
|
3039
|
+
callback === null || callback === void 0 ? void 0 : callback(error, null);
|
|
3040
|
+
throw error;
|
|
3041
|
+
}
|
|
3042
|
+
const { error, statusCode, rspBody } = yield requestWithRetry(Method.GET, `tx/${this.config.blockchainRid}/${txRid.toString("hex")}/confirmationProof`, this.config);
|
|
3043
|
+
const confirmationProof = {
|
|
3044
|
+
hash: undefined,
|
|
3045
|
+
blockHeader: undefined,
|
|
3046
|
+
witness: undefined,
|
|
3047
|
+
merkleProofTree: "",
|
|
3048
|
+
txIndex: 0,
|
|
3049
|
+
};
|
|
3050
|
+
if (statusCode === 200) {
|
|
3051
|
+
try {
|
|
3052
|
+
const decodedProof = decodeValue(toBuffer(rspBody.proof));
|
|
3053
|
+
confirmationProof.txIndex = decodedProof.txIndex;
|
|
3054
|
+
confirmationProof.hash = decodedProof.hash;
|
|
3055
|
+
confirmationProof.blockHeader = decodedProof.blockHeader;
|
|
3056
|
+
confirmationProof.witness = decodedProof.witness;
|
|
3057
|
+
confirmationProof.merkleProofTree = decodedProof.merkleProofTree;
|
|
3058
|
+
}
|
|
3059
|
+
catch (decodeError) {
|
|
3060
|
+
if (callback) {
|
|
3061
|
+
callback(decodeError, null);
|
|
2868
3062
|
}
|
|
3063
|
+
throw decodeError;
|
|
2869
3064
|
}
|
|
2870
|
-
return new Promise((resolve, reject) => {
|
|
2871
|
-
handleGetResponse(error, statusCode, statusCode === 200 ? confirmationProof : rspBody, callbackPromiseBuilder(reject, resolve, callback));
|
|
2872
|
-
});
|
|
2873
3065
|
}
|
|
3066
|
+
return new Promise((resolve, reject) => {
|
|
3067
|
+
handleGetResponse(error, statusCode, statusCode === 200 ? confirmationProof : rspBody, callbackPromiseBuilder(reject, resolve, callback));
|
|
3068
|
+
});
|
|
2874
3069
|
});
|
|
2875
3070
|
},
|
|
2876
3071
|
};
|
|
@@ -2891,13 +3086,6 @@ require("web3-core-promievent");
|
|
|
2891
3086
|
function getClientConfigFromSettings(settings) {
|
|
2892
3087
|
var _a, _b, _c, _d;
|
|
2893
3088
|
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
3089
|
const nodeUrlPoolToUse = yield getNodeUrlsFromSettings(settings);
|
|
2902
3090
|
const endpointPool = createEndpointObjects(nodeUrlPoolToUse);
|
|
2903
3091
|
const blockchainRidToUse = settings.blockchainRid ||
|
|
@@ -2917,21 +3105,13 @@ function getClientConfigFromSettings(settings) {
|
|
|
2917
3105
|
};
|
|
2918
3106
|
});
|
|
2919
3107
|
}
|
|
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
3108
|
function nodeDiscovery(directoryEndpointPool, failOverConfig, blockchainRid, blockchainIid) {
|
|
2929
3109
|
return __awaiter$6(this, void 0, void 0, function* () {
|
|
2930
3110
|
if (directoryEndpointPool.length === 0) {
|
|
2931
3111
|
throw new DirectoryNodeUrlPoolException();
|
|
2932
3112
|
}
|
|
2933
3113
|
if (!(blockchainRid || blockchainIid != undefined)) {
|
|
2934
|
-
throw new
|
|
3114
|
+
throw new MissingBlockchainIdentifierError();
|
|
2935
3115
|
}
|
|
2936
3116
|
const directoryIid = 0;
|
|
2937
3117
|
const directoryBRID = yield getBlockchainRidFromIid(directoryEndpointPool, directoryIid, failOverConfig);
|
|
@@ -2939,7 +3119,7 @@ function nodeDiscovery(directoryEndpointPool, failOverConfig, blockchainRid, blo
|
|
|
2939
3119
|
(yield getBlockchainRidFromIid(directoryEndpointPool, blockchainIid, failOverConfig));
|
|
2940
3120
|
const queryObject = {
|
|
2941
3121
|
name: "cm_get_blockchain_api_urls",
|
|
2942
|
-
args: { blockchain_rid: blockchainRidToUse },
|
|
3122
|
+
args: { blockchain_rid: toBuffer(blockchainRidToUse) },
|
|
2943
3123
|
};
|
|
2944
3124
|
const D1Client = yield createClient({
|
|
2945
3125
|
nodeUrlPool: getUrlsFromEndpoints(directoryEndpointPool),
|
|
@@ -3963,7 +4143,7 @@ exports.InvalidBlockchainRIDException = InvalidBlockchainRIDException;
|
|
|
3963
4143
|
exports.InvalidTransactionFormatException = InvalidTransactionFormatException;
|
|
3964
4144
|
exports.InvalidTxRidException = InvalidTxRidException;
|
|
3965
4145
|
exports.LostMessageError = LostMessageError;
|
|
3966
|
-
exports.
|
|
4146
|
+
exports.MissingBlockchainIdentifierError = MissingBlockchainIdentifierError;
|
|
3967
4147
|
exports.MissingGtxException = MissingGtxException;
|
|
3968
4148
|
exports.MissingNodeUrlError = MissingNodeUrlError;
|
|
3969
4149
|
exports.MissingPrivKeyArgumentException = MissingPrivKeyArgumentException;
|
|
@@ -3988,6 +4168,7 @@ exports.encryption = encryption$1;
|
|
|
3988
4168
|
exports.formatter = formatter;
|
|
3989
4169
|
exports.getAnchoringClient = getAnchoringClient;
|
|
3990
4170
|
exports.getBlockAnchoringTransaction = getBlockAnchoringTransaction;
|
|
4171
|
+
exports.getDigestToSignFromRawGtxBody = getDigestToSignFromRawGtxBody;
|
|
3991
4172
|
exports.getTransactionRidException = getTransactionRidException;
|
|
3992
4173
|
exports.gtv = index;
|
|
3993
4174
|
exports.gtx = gtx;
|