@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.cjs CHANGED
@@ -62,8 +62,13 @@ var __defProp = Object.defineProperty;
62
62
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
63
63
  var __getOwnPropNames = Object.getOwnPropertyNames;
64
64
  var __hasOwnProp = Object.prototype.hasOwnProperty;
65
- var __esm = (fn, res) => function __init() {
66
- return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
65
+ var __esm = (fn, res, err) => function __init() {
66
+ if (err) throw err[0];
67
+ try {
68
+ return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
69
+ } catch (e) {
70
+ throw err = [e], e;
71
+ }
67
72
  };
68
73
  var __export = (target, all) => {
69
74
  for (var name in all)
@@ -6411,6 +6416,9 @@ var Decimal = class _Decimal {
6411
6416
  return _Decimal.cmp(value1, value2) === 0;
6412
6417
  }
6413
6418
  };
6419
+
6420
+ // src/libraries/GraphQLClient.ts
6421
+ init_exception();
6414
6422
  var CIPHER_HASH_QUERY = "query ( $Hash: String! ) { CipherHash ( Hash: $Hash ) { hash } }";
6415
6423
  function parseOperation(query) {
6416
6424
  const typeMatch = (query || "").match(/\b(query|mutation|subscription)\b/i);
@@ -6518,15 +6526,21 @@ var GraphQLClient = class {
6518
6526
  async cipherFetch(input, init) {
6519
6527
  const wallet = this.$__wallet;
6520
6528
  const serverPubkey = this.$__pubkey;
6521
- let encryptedRequest = false;
6529
+ let cipherWallet = null;
6522
6530
  let requestInit = init;
6523
- if (wallet && serverPubkey && init && typeof init.body === "string" && this.shouldEncrypt(init.body)) {
6531
+ if (init && typeof init.body === "string" && this.shouldEncrypt(init.body)) {
6532
+ if (!wallet) {
6533
+ throw new CodeException("Authorized wallet missing.");
6534
+ }
6535
+ if (!serverPubkey) {
6536
+ throw new CodeException("Server public key missing.");
6537
+ }
6524
6538
  const hashVar = await wallet.encryptStringML(init.body, serverPubkey);
6525
6539
  requestInit = { ...init, body: JSON.stringify({ query: CIPHER_HASH_QUERY, variables: { Hash: hashVar } }) };
6526
- encryptedRequest = true;
6540
+ cipherWallet = wallet;
6527
6541
  }
6528
6542
  const response = await fetch(input, requestInit);
6529
- if (!encryptedRequest) {
6543
+ if (!cipherWallet) {
6530
6544
  return response;
6531
6545
  }
6532
6546
  const text = await response.text();
@@ -6541,7 +6555,7 @@ var GraphQLClient = class {
6541
6555
  if (typeof hash !== "string") {
6542
6556
  return new Response(text, init2);
6543
6557
  }
6544
- const decrypted = await wallet.decryptMyMessageML(JSON.parse(hash));
6558
+ const decrypted = await cipherWallet.decryptMyMessageML(JSON.parse(hash));
6545
6559
  return new Response(decrypted != null ? decrypted : text, init2);
6546
6560
  }
6547
6561
  setAuthData({
@@ -9590,7 +9604,7 @@ var ResponseProposeMolecule = class extends exports.Response {
9590
9604
  code: "HASH_MISMATCH"
9591
9605
  });
9592
9606
  }
9593
- if (/ots.*position.*reuse|position.*already.*used|ots.*verification/.test(lc)) {
9607
+ if (/ots.*(?:position|key).*reuse|position.*already.*(?:used|consumed)|ots.*verification/.test(lc)) {
9594
9608
  return new exports.SignatureMismatchException(reason, {
9595
9609
  details: { reason },
9596
9610
  code: "OTS_VERIFICATION_FAILED"
@@ -12667,6 +12681,7 @@ var KnishIOClient = class {
12667
12681
  pubkey: response.pubKey()
12668
12682
  }, wallet);
12669
12683
  this.setAuthToken(authToken);
12684
+ this.lastMoleculeQuery = null;
12670
12685
  } else {
12671
12686
  throw new AuthorizationRejectedException_default(
12672
12687
  `KnishIOClient::requestProfileAuthToken() - Authorization attempt rejected by ledger. Reason: ${response.reason()}`
@@ -14029,7 +14044,7 @@ function createDefaultSecretStorage(options = {}) {
14029
14044
  }
14030
14045
 
14031
14046
  // src/index.ts
14032
- var SDK_VERSION = "1.1.0";
14047
+ var SDK_VERSION = "1.2.1";
14033
14048
  var SDK_NAME = "KnishIO-Client-TS";
14034
14049
  var COMPATIBLE_SERVER_VERSIONS = [4, 5];
14035
14050
  var SDK_INFO = {