postchain-client 1.5.2 → 1.5.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.
Files changed (40) hide show
  1. package/built/cjs/index.js +50 -44
  2. package/built/cjs/index.js.map +1 -1
  3. package/built/esm/index.js +292 -287
  4. package/built/esm/index.js.map +1 -1
  5. package/built/index.d.ts +1 -0
  6. package/built/src/blockchainClient/blockchainClient.js +7 -5
  7. package/built/src/blockchainClient/blockchainClient.js.map +1 -1
  8. package/built/src/blockchainClient/types.d.ts +1 -1
  9. package/built/src/blockchainClient/utils.d.ts +4 -9
  10. package/built/src/blockchainClient/utils.js +6 -5
  11. package/built/src/blockchainClient/utils.js.map +1 -1
  12. package/built/src/encryption/encryption.d.ts +1 -0
  13. package/built/src/encryption/encryption.js +1 -0
  14. package/built/src/encryption/encryption.js.map +1 -1
  15. package/built/src/formatter.d.ts +1 -0
  16. package/built/src/formatter.js +1 -0
  17. package/built/src/formatter.js.map +1 -1
  18. package/built/src/gtx/gtxclient.js +1 -0
  19. package/built/src/gtx/gtxclient.js.map +1 -1
  20. package/built/src/gtx/serialization.d.ts +1 -0
  21. package/built/src/gtx/serialization.js +1 -0
  22. package/built/src/gtx/serialization.js.map +1 -1
  23. package/built/src/merkle/binarytreefactory.js +1 -0
  24. package/built/src/merkle/binarytreefactory.js.map +1 -1
  25. package/built/src/merkle/merkleHelper.d.ts +1 -0
  26. package/built/src/merkle/merkleHelper.js +1 -0
  27. package/built/src/merkle/merkleHelper.js.map +1 -1
  28. package/built/src/merkle/merklehashcalculator.d.ts +2 -0
  29. package/built/src/merkle/merklehashcalculator.js +1 -0
  30. package/built/src/merkle/merklehashcalculator.js.map +1 -1
  31. package/built/src/merkle/proof/merkleprooftreefactory.js +1 -0
  32. package/built/src/merkle/proof/merkleprooftreefactory.js.map +1 -1
  33. package/built/src/restclient/httpUtil.d.ts +1 -0
  34. package/built/src/restclient/httpUtil.js +1 -0
  35. package/built/src/restclient/httpUtil.js.map +1 -1
  36. package/built/src/restclient/restclient.js +1 -0
  37. package/built/src/restclient/restclient.js.map +1 -1
  38. package/built/umd/index.js +292 -287
  39. package/built/umd/index.js.map +1 -1
  40. package/package.json +4 -2
@@ -1,5 +1,6 @@
1
1
  'use strict';
2
2
 
3
+ var require$$0$1 = require('buffer');
3
4
  var bn_js = require('bn.js');
4
5
  var crypto = require('crypto');
5
6
  var secp256k1 = require('secp256k1');
@@ -101,7 +102,7 @@ class MissingSignerException extends Error {
101
102
  }
102
103
 
103
104
  function pgBytes(buffer) {
104
- if (!Buffer.isBuffer(buffer)) {
105
+ if (!require$$0$1.Buffer.isBuffer(buffer)) {
105
106
  throw new PgBytesInputException(buffer);
106
107
  }
107
108
  return "\\x" + buffer.toString("hex");
@@ -112,7 +113,7 @@ function pgBytes(buffer) {
112
113
  * @returns {Buffer}
113
114
  */
114
115
  function toBuffer(key) {
115
- return Buffer.from(key, "hex");
116
+ return require$$0$1.Buffer.from(key, "hex");
116
117
  }
117
118
  /**
118
119
  * Converts Buffer to hex string
@@ -141,7 +142,7 @@ class PgBytesInputException extends Error {
141
142
  }
142
143
  }
143
144
  function ensureBuffer(value) {
144
- if (value instanceof Buffer) {
145
+ if (value instanceof require$$0$1.Buffer) {
145
146
  return value;
146
147
  }
147
148
  else {
@@ -153,7 +154,7 @@ function checkGtvType(value) {
153
154
  if (value == null) {
154
155
  return true;
155
156
  }
156
- if (Buffer.isBuffer(value)) {
157
+ if (require$$0$1.Buffer.isBuffer(value)) {
157
158
  return true;
158
159
  }
159
160
  if (typeof value === "string") {
@@ -221,7 +222,7 @@ function removeDuplicateSigners(signers) {
221
222
  });
222
223
  const result = [];
223
224
  signersAsString.forEach((item) => {
224
- result.push(Buffer.from(item, "hex"));
225
+ result.push(require$$0$1.Buffer.from(item, "hex"));
225
226
  });
226
227
  return result;
227
228
  }
@@ -294,7 +295,7 @@ function createTypedArg(value) {
294
295
  if (value == null) {
295
296
  return { type: "null", value: null };
296
297
  }
297
- if (Buffer.isBuffer(value)) {
298
+ if (require$$0$1.Buffer.isBuffer(value)) {
298
299
  return { type: "byteArray", value: value };
299
300
  }
300
301
  if (typeof value === "boolean") {
@@ -344,7 +345,7 @@ var serialization$1 = /*#__PURE__*/Object.freeze({
344
345
  parseValue: parseValue
345
346
  });
346
347
 
347
- var require$$0$1 = /*@__PURE__*/getAugmentedNamespace(serialization$1);
348
+ var require$$1 = /*@__PURE__*/getAugmentedNamespace(serialization$1);
348
349
 
349
350
  var require$$0 = /*@__PURE__*/getAugmentedNamespace(formatter);
350
351
 
@@ -811,7 +812,7 @@ class MissingPrivKeyArgumentException extends Error {
811
812
 
812
813
  function createPublicKey(privKey) {
813
814
  validatePrivKeyFormat(privKey);
814
- return Buffer.from(secp256k1__namespace.publicKeyCreate(privKey, true).buffer);
815
+ return require$$0$1.Buffer.from(secp256k1__namespace.publicKeyCreate(privKey, true).buffer);
815
816
  }
816
817
  function randomBytes(size) {
817
818
  return crypto__namespace.randomBytes(size);
@@ -821,7 +822,7 @@ function sha256(buffer) {
821
822
  }
822
823
  const hash256 = sha256;
823
824
  function hashConcat(items) {
824
- return hash256(Buffer.concat(items));
825
+ return hash256(require$$0$1.Buffer.concat(items));
825
826
  }
826
827
  /**
827
828
  * @param content the content that the signature signs. It will be digested before validating.
@@ -862,7 +863,7 @@ function sign$1(content, privKey) {
862
863
  * @return the signature
863
864
  */
864
865
  function signDigest(digestBuffer, privKey) {
865
- return Buffer.from(secp256k1__namespace.ecdsaSign(digestBuffer, privKey).signature);
866
+ return require$$0$1.Buffer.from(secp256k1__namespace.ecdsaSign(digestBuffer, privKey).signature);
866
867
  }
867
868
  /**
868
869
  * Creates a key pair (which usually represents one user)
@@ -879,7 +880,7 @@ function makeKeyPair(privKey) {
879
880
  do {
880
881
  privKey = randomBytes(32);
881
882
  } while (!secp256k1__namespace.privateKeyVerify(privKey));
882
- pubKey = Buffer.from(secp256k1__namespace.publicKeyCreate(privKey).buffer);
883
+ pubKey = require$$0$1.Buffer.from(secp256k1__namespace.publicKeyCreate(privKey).buffer);
883
884
  }
884
885
  return { pubKey, privKey };
885
886
  }
@@ -897,14 +898,14 @@ function makeTuid() {
897
898
  */
898
899
  function verifyKeyPair(privKey) {
899
900
  validatePrivKeyFormat(privKey);
900
- const pubKey = Buffer.from(secp256k1__namespace.publicKeyCreate(privKey).buffer);
901
+ const pubKey = require$$0$1.Buffer.from(secp256k1__namespace.publicKeyCreate(privKey).buffer);
901
902
  return { pubKey, privKey };
902
903
  }
903
904
  function validatePrivKeyFormat(privKey) {
904
905
  if (!privKey) {
905
906
  throw new MissingPrivKeyArgumentException();
906
907
  }
907
- if (!Buffer.isBuffer(privKey) || privKey.length !== 32) {
908
+ if (!require$$0$1.Buffer.isBuffer(privKey) || privKey.length !== 32) {
908
909
  throw new PrivKeyFormatException(privKey);
909
910
  }
910
911
  }
@@ -925,11 +926,12 @@ var encryption$1 = /*#__PURE__*/Object.freeze({
925
926
  verifyKeyPair: verifyKeyPair
926
927
  });
927
928
 
928
- var require$$2 = /*@__PURE__*/getAugmentedNamespace(encryption$1);
929
+ var require$$3 = /*@__PURE__*/getAugmentedNamespace(encryption$1);
929
930
 
930
- var serialization = require$$0$1;
931
+ const { Buffer: Buffer$3 } = require$$0$1;
932
+ var serialization = require$$1;
931
933
  var HASH_PREFIX_LEAF = binarytree.HASH_PREFIX_LEAF;
932
- var encryption = require$$2;
934
+ var encryption = require$$3;
933
935
  function CryptoSystem() { }
934
936
  CryptoSystem.prototype.digest = function (buffer) {
935
937
  return encryption.hash256(buffer);
@@ -974,15 +976,15 @@ MerkleHashCalculator.prototype.calculateLeafHash = function (value) {
974
976
  * @param {Buffer} hashRight
975
977
  */
976
978
  MerkleHashCalculator.prototype.calculateNodeHashInternal = function (prefix, hashLeft, hashRight, hashFunc) {
977
- var buf = Buffer.alloc(1);
979
+ var buf = Buffer$3.alloc(1);
978
980
  buf.writeInt8(prefix);
979
- var bufferSum = Buffer.concat([buf, hashLeft, hashRight]);
981
+ var bufferSum = Buffer$3.concat([buf, hashLeft, hashRight]);
980
982
  return hashFunc(bufferSum, this.cryptoSystem);
981
983
  };
982
984
  MerkleHashCalculator.prototype.calculateHashOfValueInternal = function (valuetoHash, serializeFun, hashFunc) {
983
- var buf = Buffer.alloc(1);
985
+ var buf = Buffer$3.alloc(1);
984
986
  buf.writeInt8(HASH_PREFIX_LEAF);
985
- var bufferSum = Buffer.concat([buf, serializeFun(valuetoHash)]);
987
+ var bufferSum = Buffer$3.concat([buf, serializeFun(valuetoHash)]);
986
988
  return hashFunc(bufferSum, this.cryptoSystem);
987
989
  };
988
990
  MerkleHashCalculator.prototype.isContainerProofValueLeaf = function (value) {
@@ -999,6 +1001,7 @@ MerkleHashCalculator.prototype.isContainerProofValueLeaf = function (value) {
999
1001
  var merklehashcalculator = { MerkleHashCalculator, CryptoSystem };
1000
1002
 
1001
1003
  var util = require$$0;
1004
+ const { Buffer: Buffer$2 } = require$$0$1;
1002
1005
  var PathSet = path.PathSet;
1003
1006
  var PathLeafElement$1 = path.PathLeafElement;
1004
1007
  var EmptyLeaf$1 = binarytree.EmptyLeaf;
@@ -1049,7 +1052,7 @@ BinaryTreeFactory$1.prototype.innerHandleLeaf = function (leaf, paths) {
1049
1052
  if (leaf == null) {
1050
1053
  return this.handlePrimitiveLeaf(leaf, paths);
1051
1054
  }
1052
- if (Buffer.isBuffer(leaf)) {
1055
+ if (Buffer$2.isBuffer(leaf)) {
1053
1056
  return this.handlePrimitiveLeaf(leaf, paths);
1054
1057
  }
1055
1058
  if (typeof leaf === 'string') {
@@ -1350,6 +1353,7 @@ MerkleProofTree$1.prototype.maxLevelInternal = function (node) {
1350
1353
  var merkleprooftree = { ProofNode: ProofNode$1, ProofNodeSimple: ProofNodeSimple$1, ProofHashedLeaf: ProofHashedLeaf$2, ProofValueLeaf: ProofValueLeaf$2,
1351
1354
  ProofNodeArrayHead: ProofNodeArrayHead$1, ProofNodeDictHead: ProofNodeDictHead$1, MerkleProofElement, MerkleProofTree: MerkleProofTree$1 };
1352
1355
 
1356
+ const { Buffer: Buffer$1 } = require$$0$1;
1353
1357
  var Node = binarytree.Node;
1354
1358
  var Leaf = binarytree.Leaf;
1355
1359
  var EmptyLeaf = binarytree.EmptyLeaf;
@@ -1363,7 +1367,7 @@ var SubTreeRootNode = binarytree.SubTreeRootNode;
1363
1367
  var ArrayHeadNode = binarytree.ArrayHeadNode;
1364
1368
  var DictHeadNode = binarytree.DictHeadNode;
1365
1369
  var ProofNodeSimple = merkleprooftree.ProofNodeSimple;
1366
- const EMPTY_HASH = new Buffer.alloc(32);
1370
+ const EMPTY_HASH = new Buffer$1.alloc(32);
1367
1371
  /**
1368
1372
  *
1369
1373
  */
@@ -1880,10 +1884,10 @@ function createClient$1(restApiClient, blockchainRID, functionNames) {
1880
1884
  gtx: gtx$1,
1881
1885
  sign: function (privOrSigProv, pubKey) {
1882
1886
  return __awaiter$7(this, void 0, void 0, function* () {
1883
- debug(`signing transaction with ${privOrSigProv instanceof Buffer
1887
+ debug(`signing transaction with ${privOrSigProv instanceof require$$0$1.Buffer
1884
1888
  ? "privkey: " + privOrSigProv.toString("hex")
1885
1889
  : "signature provider [pubkey: " + privOrSigProv.pubKey + "]"}`);
1886
- if (privOrSigProv instanceof Buffer) {
1890
+ if (privOrSigProv instanceof require$$0$1.Buffer) {
1887
1891
  yield sign(this.gtx, privOrSigProv, pubKey);
1888
1892
  }
1889
1893
  else {
@@ -1928,7 +1932,7 @@ function createClient$1(restApiClient, blockchainRID, functionNames) {
1928
1932
  const client = {
1929
1933
  newTransaction: function (signers) {
1930
1934
  signers = removeDuplicateSigners(signers);
1931
- const newGtx = emptyGtx(Buffer.from(blockchainRID, "hex"));
1935
+ const newGtx = emptyGtx(require$$0$1.Buffer.from(blockchainRID, "hex"));
1932
1936
  signers.forEach((signer) => addSignerToGtx(signer, newGtx));
1933
1937
  const req = transaction(newGtx);
1934
1938
  addFunctions(req);
@@ -2075,7 +2079,7 @@ function post(path, endpoint, requestBody) {
2075
2079
  return __awaiter$6(this, void 0, void 0, function* () {
2076
2080
  debug("POST URL " + new URL(path, endpoint).href);
2077
2081
  debug("POST body " + JSON.stringify(requestBody));
2078
- if (Buffer.isBuffer(requestBody)) {
2082
+ if (require$$0$1.Buffer.isBuffer(requestBody)) {
2079
2083
  try {
2080
2084
  const requestOptions = {
2081
2085
  method: "post",
@@ -2085,7 +2089,7 @@ function post(path, endpoint, requestBody) {
2085
2089
  return {
2086
2090
  error: null,
2087
2091
  statusCode: response.status,
2088
- rspBody: decodeValue(Buffer.from(yield response.arrayBuffer())),
2092
+ rspBody: decodeValue(require$$0$1.Buffer.from(yield response.arrayBuffer())),
2089
2093
  };
2090
2094
  }
2091
2095
  catch (error) {
@@ -2219,7 +2223,7 @@ function createRestClient(endpointPool, blockchainRID, maxSockets = 10, pollingI
2219
2223
  },
2220
2224
  postTransaction: function (serializedTransaction, callback) {
2221
2225
  return __awaiter$4(this, void 0, void 0, function* () {
2222
- if (!Buffer.isBuffer(serializedTransaction)) {
2226
+ if (!require$$0$1.Buffer.isBuffer(serializedTransaction)) {
2223
2227
  throw new SerializedTransactionFormatException();
2224
2228
  }
2225
2229
  const transactionObject = {
@@ -2396,13 +2400,13 @@ var restclient = /*#__PURE__*/Object.freeze({
2396
2400
  handlePostResponse: handlePostResponse
2397
2401
  });
2398
2402
 
2399
- var internalNodePrefix = Buffer.alloc(1, 0);
2400
- var leafPrefix = Buffer.alloc(1, 1);
2401
- var nonExistingNodeHash = Buffer.alloc(32);
2403
+ var internalNodePrefix = require$$0$1.Buffer.alloc(1, 0);
2404
+ var leafPrefix = require$$0$1.Buffer.alloc(1, 1);
2405
+ var nonExistingNodeHash = require$$0$1.Buffer.alloc(32);
2402
2406
  function calculateRoot(hashes, depth, leafDepth) {
2403
2407
  var numTransactions = hashes.length;
2404
2408
  if (numTransactions === 0) {
2405
- return Buffer.alloc(32);
2409
+ return require$$0$1.Buffer.alloc(32);
2406
2410
  }
2407
2411
  if (depth === undefined) {
2408
2412
  depth = 0;
@@ -2487,7 +2491,7 @@ function validateMerklePath(path, target, merkleRoot) {
2487
2491
  let currentHash = target;
2488
2492
  for (let i = 0; i < path.length; i++) {
2489
2493
  const item = path[i];
2490
- const prefix = (i === 0) ? Buffer.from([1]) : Buffer.from([0]);
2494
+ const prefix = (i === 0) ? require$$0$1.Buffer.from([1]) : require$$0$1.Buffer.from([0]);
2491
2495
  if (item.side === 0) {
2492
2496
  currentHash = hashConcat([prefix, item.hash, prefix, currentHash]);
2493
2497
  }
@@ -2614,8 +2618,8 @@ function getConfig(settings) {
2614
2618
  return {
2615
2619
  endpointPool: nodeUrlPool,
2616
2620
  blockchainRID: settings.blockchainRID
2617
- ? toBuffer(settings.blockchainRID)
2618
- : toBuffer(yield getBrid(nodeUrlPool[0], settings.blockchainIID)),
2621
+ ? settings.blockchainRID
2622
+ : yield getBrid(nodeUrlPool[0], settings.blockchainIID),
2619
2623
  pollingInterval: settings.pollingInterval || 500,
2620
2624
  attemptsPerEndpoint: ((_a = settings.failOverConfig) === null || _a === void 0 ? void 0 : _a.attemptsPerEndpoint) || 3,
2621
2625
  attemptInterval: ((_b = settings.failOverConfig) === null || _b === void 0 ? void 0 : _b.attemptInterval) || 500,
@@ -2666,18 +2670,18 @@ function convertToRellOperation(operations) {
2666
2670
  }
2667
2671
  function getSerializedGTX(gtx$1) {
2668
2672
  const gtxBytes = serialize(gtx$1);
2669
- if (!Buffer.isBuffer(gtxBytes)) {
2673
+ if (!require$$0$1.Buffer.isBuffer(gtxBytes)) {
2670
2674
  throw new SerializedTransactionFormatException();
2671
2675
  }
2672
2676
  return gtxBytes;
2673
2677
  }
2674
2678
  function getGTXFromBufferOrTransactionOrOperation(transaction, blockchainRID) {
2675
- if (Buffer.isBuffer(transaction)) {
2679
+ if (require$$0$1.Buffer.isBuffer(transaction)) {
2676
2680
  return deserialize(transaction);
2677
2681
  }
2678
2682
  else if ("operations" in transaction) {
2679
2683
  return {
2680
- blockchainRID,
2684
+ blockchainRID: toBuffer(blockchainRID),
2681
2685
  operations: convertToRellOperation(transaction.operations),
2682
2686
  signers: transaction.signers,
2683
2687
  signatures: [],
@@ -2685,7 +2689,7 @@ function getGTXFromBufferOrTransactionOrOperation(transaction, blockchainRID) {
2685
2689
  }
2686
2690
  else if ("name" in transaction) {
2687
2691
  return {
2688
- blockchainRID,
2692
+ blockchainRID: toBuffer(blockchainRID),
2689
2693
  operations: convertToRellOperation([transaction]),
2690
2694
  signers: [],
2691
2695
  signatures: [],
@@ -2850,7 +2854,6 @@ var __awaiter = (undefined && undefined.__awaiter) || function (thisArg, _argume
2850
2854
  };
2851
2855
  function createClient(settings) {
2852
2856
  return __awaiter(this, void 0, void 0, function* () {
2853
- const blockchainRID = settings.blockchainRID;
2854
2857
  return {
2855
2858
  config: yield getConfig(settings),
2856
2859
  query(nameOrQueryObject, args, callback) {
@@ -2864,7 +2867,7 @@ function createClient(settings) {
2864
2867
  _name = nameOrQueryObject === null || nameOrQueryObject === void 0 ? void 0 : nameOrQueryObject.name;
2865
2868
  _args = nameOrQueryObject === null || nameOrQueryObject === void 0 ? void 0 : nameOrQueryObject.args;
2866
2869
  }
2867
- const { error, statusCode, rspBody } = yield requestWithRetry(Method.POST, `query_gtv/${blockchainRID}`, this.config, encodeValue(toQueryObjectGTV(_name, _args)));
2870
+ const { error, statusCode, rspBody } = yield requestWithRetry(Method.POST, `query_gtv/${this.config.blockchainRID}`, this.config, encodeValue(toQueryObjectGTV(_name, _args)));
2868
2871
  return new Promise((resolve, reject) => {
2869
2872
  handlePostResponse(error, statusCode, rspBody, callbackPromiseBuilder(reject, resolve, callback));
2870
2873
  });
@@ -2905,7 +2908,7 @@ function createClient(settings) {
2905
2908
  const transactionObject = {
2906
2909
  tx: gtxBytes.toString("hex"),
2907
2910
  };
2908
- const { error: error$1, statusCode, rspBody } = yield requestWithRetry(Method.POST, "tx/" + blockchainRID, this.config, transactionObject);
2911
+ const { error: error$1, statusCode, rspBody } = yield requestWithRetry(Method.POST, "tx/" + this.config.blockchainRID, this.config, transactionObject);
2909
2912
  const transactionRID = getDigestToSign(gtx$1);
2910
2913
  try {
2911
2914
  yield handlePostResponsePromisified(error$1, statusCode, rspBody);
@@ -3015,7 +3018,10 @@ function createClient(settings) {
3015
3018
  }
3016
3019
  throw new UnvalidTxRidException(transactionRID);
3017
3020
  }
3018
- const { error, statusCode, rspBody } = yield requestWithRetry(Method.GET, "tx/" + blockchainRID + "/" + transactionRID.toString("hex"), this.config);
3021
+ const { error, statusCode, rspBody } = yield requestWithRetry(Method.GET, "tx/" +
3022
+ this.config.blockchainRID +
3023
+ "/" +
3024
+ transactionRID.toString("hex"), this.config);
3019
3025
  return new Promise((resolve, reject) => {
3020
3026
  handleGetResponse(error, statusCode, statusCode === 200 ? toBuffer(rspBody.tx) : rspBody, callbackPromiseBuilder(reject, resolve, callback));
3021
3027
  });
@@ -3031,7 +3037,7 @@ function createClient(settings) {
3031
3037
  throw error;
3032
3038
  }
3033
3039
  const { error, statusCode, rspBody } = yield requestWithRetry(Method.GET, "tx/" +
3034
- blockchainRID +
3040
+ this.config.blockchainRID +
3035
3041
  "/" +
3036
3042
  transactionRID.toString("hex") +
3037
3043
  "/status", this.config);