@wishknish/knishio-client-ts 1.1.0 → 1.2.1

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/dist/index.js CHANGED
@@ -56,8 +56,13 @@ var __defProp = Object.defineProperty;
56
56
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
57
57
  var __getOwnPropNames = Object.getOwnPropertyNames;
58
58
  var __hasOwnProp = Object.prototype.hasOwnProperty;
59
- var __esm = (fn, res) => function __init() {
60
- return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
59
+ var __esm = (fn, res, err) => function __init() {
60
+ if (err) throw err[0];
61
+ try {
62
+ return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
63
+ } catch (e) {
64
+ throw err = [e], e;
65
+ }
61
66
  };
62
67
  var __export = (target, all) => {
63
68
  for (var name in all)
@@ -6405,6 +6410,9 @@ var Decimal = class _Decimal {
6405
6410
  return _Decimal.cmp(value1, value2) === 0;
6406
6411
  }
6407
6412
  };
6413
+
6414
+ // src/libraries/GraphQLClient.ts
6415
+ init_exception();
6408
6416
  var CIPHER_HASH_QUERY = "query ( $Hash: String! ) { CipherHash ( Hash: $Hash ) { hash } }";
6409
6417
  function parseOperation(query) {
6410
6418
  const typeMatch = (query || "").match(/\b(query|mutation|subscription)\b/i);
@@ -6512,15 +6520,21 @@ var GraphQLClient = class {
6512
6520
  async cipherFetch(input, init) {
6513
6521
  const wallet = this.$__wallet;
6514
6522
  const serverPubkey = this.$__pubkey;
6515
- let encryptedRequest = false;
6523
+ let cipherWallet = null;
6516
6524
  let requestInit = init;
6517
- if (wallet && serverPubkey && init && typeof init.body === "string" && this.shouldEncrypt(init.body)) {
6525
+ if (init && typeof init.body === "string" && this.shouldEncrypt(init.body)) {
6526
+ if (!wallet) {
6527
+ throw new CodeException("Authorized wallet missing.");
6528
+ }
6529
+ if (!serverPubkey) {
6530
+ throw new CodeException("Server public key missing.");
6531
+ }
6518
6532
  const hashVar = await wallet.encryptStringML(init.body, serverPubkey);
6519
6533
  requestInit = { ...init, body: JSON.stringify({ query: CIPHER_HASH_QUERY, variables: { Hash: hashVar } }) };
6520
- encryptedRequest = true;
6534
+ cipherWallet = wallet;
6521
6535
  }
6522
6536
  const response = await fetch(input, requestInit);
6523
- if (!encryptedRequest) {
6537
+ if (!cipherWallet) {
6524
6538
  return response;
6525
6539
  }
6526
6540
  const text = await response.text();
@@ -6535,7 +6549,7 @@ var GraphQLClient = class {
6535
6549
  if (typeof hash !== "string") {
6536
6550
  return new Response(text, init2);
6537
6551
  }
6538
- const decrypted = await wallet.decryptMyMessageML(JSON.parse(hash));
6552
+ const decrypted = await cipherWallet.decryptMyMessageML(JSON.parse(hash));
6539
6553
  return new Response(decrypted != null ? decrypted : text, init2);
6540
6554
  }
6541
6555
  setAuthData({
@@ -9584,7 +9598,7 @@ var ResponseProposeMolecule = class extends Response2 {
9584
9598
  code: "HASH_MISMATCH"
9585
9599
  });
9586
9600
  }
9587
- if (/ots.*position.*reuse|position.*already.*used|ots.*verification/.test(lc)) {
9601
+ if (/ots.*(?:position|key).*reuse|position.*already.*(?:used|consumed)|ots.*verification/.test(lc)) {
9588
9602
  return new SignatureMismatchException(reason, {
9589
9603
  details: { reason },
9590
9604
  code: "OTS_VERIFICATION_FAILED"
@@ -12661,6 +12675,7 @@ var KnishIOClient = class {
12661
12675
  pubkey: response.pubKey()
12662
12676
  }, wallet);
12663
12677
  this.setAuthToken(authToken);
12678
+ this.lastMoleculeQuery = null;
12664
12679
  } else {
12665
12680
  throw new AuthorizationRejectedException_default(
12666
12681
  `KnishIOClient::requestProfileAuthToken() - Authorization attempt rejected by ledger. Reason: ${response.reason()}`
@@ -14023,7 +14038,7 @@ function createDefaultSecretStorage(options = {}) {
14023
14038
  }
14024
14039
 
14025
14040
  // src/index.ts
14026
- var SDK_VERSION = "1.1.0";
14041
+ var SDK_VERSION = "1.2.1";
14027
14042
  var SDK_NAME = "KnishIO-Client-TS";
14028
14043
  var COMPATIBLE_SERVER_VERSIONS = [4, 5];
14029
14044
  var SDK_INFO = {