@wishknish/knishio-client-js 0.6.3 → 0.7.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 (119) hide show
  1. package/dist/client.cjs.js +513 -0
  2. package/dist/client.cjs.js.map +1 -0
  3. package/dist/client.es.mjs +8176 -0
  4. package/dist/client.es.mjs.map +1 -0
  5. package/dist/client.iife.js +30 -45
  6. package/dist/client.iife.js.map +1 -0
  7. package/package.json +48 -28
  8. package/src/Atom.js +132 -5
  9. package/src/AtomMeta.js +7 -8
  10. package/src/AuthToken.js +1 -1
  11. package/src/KnishIOClient.js +145 -77
  12. package/src/Meta.js +6 -2
  13. package/src/Molecule.js +289 -38
  14. package/src/PolicyMeta.js +1 -1
  15. package/src/Wallet.js +19 -11
  16. package/src/exception/AtomIndexException.js +1 -1
  17. package/src/exception/AtomsMissingException.js +1 -1
  18. package/src/exception/AuthorizationRejectedException.js +1 -1
  19. package/src/exception/BalanceInsufficientException.js +1 -1
  20. package/src/exception/BatchIdException.js +1 -1
  21. package/src/exception/CodeException.js +1 -1
  22. package/src/exception/DecryptionKeyException.js +1 -1
  23. package/src/exception/InvalidResponseException.js +1 -1
  24. package/src/exception/MetaMissingException.js +1 -1
  25. package/src/exception/MolecularHashMismatchException.js +1 -1
  26. package/src/exception/MolecularHashMissingException.js +1 -1
  27. package/src/exception/NegativeAmountException.js +1 -1
  28. package/src/exception/PolicyInvalidException.js +1 -1
  29. package/src/exception/SignatureMalformedException.js +1 -1
  30. package/src/exception/SignatureMismatchException.js +1 -1
  31. package/src/exception/StackableUnitAmountException.js +1 -1
  32. package/src/exception/StackableUnitDecimalsException.js +1 -1
  33. package/src/exception/TransferBalanceException.js +1 -1
  34. package/src/exception/TransferMalformedException.js +1 -1
  35. package/src/exception/TransferMismatchedException.js +1 -1
  36. package/src/exception/TransferRemainderException.js +1 -1
  37. package/src/exception/TransferToSelfException.js +1 -1
  38. package/src/exception/TransferUnbalancedException.js +1 -1
  39. package/src/exception/UnauthenticatedException.js +1 -1
  40. package/src/exception/WalletCredentialException.js +1 -1
  41. package/src/exception/WalletShadowException.js +1 -1
  42. package/src/exception/WrongTokenTypeException.js +1 -1
  43. package/src/exception/index.js +25 -25
  44. package/src/index.js +23 -9
  45. package/src/instance/Rules/Callback.js +5 -5
  46. package/src/instance/Rules/Condition.js +1 -1
  47. package/src/instance/Rules/Rule.js +4 -4
  48. package/src/instance/Rules/exception/RuleArgumentException.js +1 -1
  49. package/src/libraries/CheckMolecule.js +76 -24
  50. package/src/libraries/crypto.js +16 -2
  51. package/src/libraries/strings.js +1 -1
  52. package/src/libraries/urql/UrqlClientWrapper.js +3 -1
  53. package/src/mutation/Mutation.js +2 -2
  54. package/src/mutation/MutationActiveSession.js +2 -2
  55. package/src/mutation/MutationAppendRequest.js +91 -0
  56. package/src/mutation/MutationClaimShadowWallet.js +3 -3
  57. package/src/mutation/MutationCreateIdentifier.js +2 -2
  58. package/src/mutation/MutationCreateMeta.js +2 -2
  59. package/src/mutation/MutationCreateRule.js +2 -2
  60. package/src/mutation/MutationCreateToken.js +2 -2
  61. package/src/mutation/MutationCreateWallet.js +2 -2
  62. package/src/mutation/MutationDepositBufferToken.js +1 -1
  63. package/src/mutation/MutationLinkIdentifier.js +2 -2
  64. package/src/mutation/MutationPeering.js +82 -0
  65. package/src/mutation/MutationProposeMolecule.js +2 -2
  66. package/src/mutation/MutationRequestAuthorization.js +2 -2
  67. package/src/mutation/MutationRequestAuthorizationGuest.js +2 -2
  68. package/src/mutation/MutationRequestTokens.js +2 -2
  69. package/src/mutation/MutationTransferTokens.js +2 -2
  70. package/src/mutation/MutationWithdrawBufferToken.js +1 -1
  71. package/src/query/Query.js +2 -2
  72. package/src/query/QueryActiveSession.js +2 -2
  73. package/src/query/QueryAtom.js +2 -2
  74. package/src/query/QueryBalance.js +2 -2
  75. package/src/query/QueryBatch.js +2 -2
  76. package/src/query/QueryBatchHistory.js +3 -3
  77. package/src/query/QueryContinuId.js +2 -2
  78. package/src/query/QueryMetaType.js +11 -5
  79. package/src/query/QueryMetaTypeViaAtom.js +11 -4
  80. package/src/query/QueryPolicy.js +2 -2
  81. package/src/query/QueryToken.js +2 -2
  82. package/src/query/QueryUserActivity.js +2 -2
  83. package/src/query/QueryWalletBundle.js +2 -2
  84. package/src/query/QueryWalletList.js +2 -2
  85. package/src/response/Response.js +168 -4
  86. package/src/response/ResponseActiveSession.js +2 -2
  87. package/src/response/{ResponseMetaBatch.js → ResponseAppendRequest.js} +4 -21
  88. package/src/response/ResponseAtom.js +2 -2
  89. package/src/response/ResponseAuthorizationGuest.js +4 -4
  90. package/src/response/ResponseBalance.js +9 -4
  91. package/src/response/ResponseClaimShadowWallet.js +1 -1
  92. package/src/response/ResponseContinuId.js +3 -3
  93. package/src/response/ResponseCreateIdentifier.js +1 -1
  94. package/src/response/ResponseCreateMeta.js +1 -1
  95. package/src/response/ResponseCreateRule.js +1 -1
  96. package/src/response/ResponseCreateToken.js +1 -1
  97. package/src/response/ResponseCreateWallet.js +1 -1
  98. package/src/response/ResponseLinkIdentifier.js +3 -3
  99. package/src/response/ResponseMetaType.js +2 -2
  100. package/src/response/ResponseMetaTypeViaAtom.js +2 -2
  101. package/src/response/ResponsePeering.js +55 -0
  102. package/src/response/ResponsePolicy.js +2 -2
  103. package/src/response/ResponseProposeMolecule.js +3 -3
  104. package/src/response/ResponseQueryActiveSession.js +2 -2
  105. package/src/response/ResponseQueryUserActivity.js +2 -2
  106. package/src/response/ResponseRequestAuthorization.js +3 -3
  107. package/src/response/ResponseRequestAuthorizationGuest.js +3 -3
  108. package/src/response/ResponseRequestTokens.js +1 -1
  109. package/src/response/ResponseTransferTokens.js +1 -1
  110. package/src/response/ResponseWalletBundle.js +3 -3
  111. package/src/response/ResponseWalletList.js +4 -4
  112. package/src/subscribe/ActiveSessionSubscribe.js +1 -1
  113. package/src/subscribe/ActiveWalletSubscribe.js +1 -1
  114. package/src/subscribe/CreateMoleculeSubscribe.js +1 -1
  115. package/src/subscribe/Subscribe.js +1 -1
  116. package/src/subscribe/WalletStatusSubscribe.js +1 -1
  117. package/src/types/index.js +2 -2
  118. package/src/versions/Version4.js +1 -1
  119. package/src/versions/index.js +1 -1
package/package.json CHANGED
@@ -1,12 +1,13 @@
1
1
  {
2
2
  "name": "@wishknish/knishio-client-js",
3
- "version": "0.6.3",
3
+ "version": "0.7.4",
4
+ "type": "module",
4
5
  "productName": "Knish.IO Javascript SDK Client",
5
6
  "description": "JavaScript implementation of the Knish.IO SDK to consume Knish.IO GraphQL APIs.",
6
7
  "license": "GPL-3.0-or-later",
7
8
  "repository": {
8
9
  "type": "git",
9
- "url": "https://github.com/WishKnish/KnishIO-Client-JS.git"
10
+ "url": "git+https://github.com/WishKnish/KnishIO-Client-JS.git"
10
11
  },
11
12
  "contributors": [
12
13
  {
@@ -15,12 +16,6 @@
15
16
  "homepage": "https://wishknish.com",
16
17
  "role": "developer"
17
18
  },
18
- {
19
- "name": "Vladimir Makarov",
20
- "email": "vladimir@wishknish.com",
21
- "homepage": "https://wishknish.com",
22
- "role": "developer"
23
- },
24
19
  {
25
20
  "name": "Yuri Kizilov",
26
21
  "email": "yuriy@wishknish.com",
@@ -28,44 +23,64 @@
28
23
  "role": "developer"
29
24
  }
30
25
  ],
31
- "main": "dist/client.iife.js",
32
- "module": "dist/client.es.js",
33
- "commonjs": "dist/client.cjs.js",
26
+ "main": "dist/client.cjs.js",
27
+ "module": "dist/client.es.mjs",
28
+ "browser": "dist/client.iife.js",
29
+ "exports": {
30
+ ".": {
31
+ "browser": "./dist/client.iife.js",
32
+ "import": "./dist/client.es.mjs",
33
+ "require": "./dist/client.cjs.js"
34
+ },
35
+ "./src": "./src/index.js",
36
+ "./src/*": "./src/*",
37
+ "./package.json": "./package.json"
38
+ },
34
39
  "keywords": [
35
40
  "wishknish",
36
41
  "knishio",
37
42
  "blockchain",
38
43
  "dag",
39
44
  "client",
40
- "graphql"
45
+ "graphql",
46
+ "xmss",
47
+ "post-quantum",
48
+ "quantum-safe",
49
+ "sdk",
50
+ "javascript",
51
+ "ml-kem768",
52
+ "cryptography",
53
+ "crystals-kyber",
54
+ "fips-202",
55
+ "fips-203"
41
56
  ],
42
57
  "dependencies": {
43
- "@noble/post-quantum": "^0.4.0",
58
+ "@noble/post-quantum": "^0.5.4",
44
59
  "@thumbmarkjs/thumbmarkjs": "^0.19.1",
45
- "@urql/core": "^5.1.0",
46
- "graphql": "^16.10.0",
47
- "graphql-ws": "^6.0.4",
60
+ "@urql/core": "^5.2.0",
61
+ "graphql": "^16.12.0",
62
+ "graphql-ws": "^6.0.7",
48
63
  "isomorphic-fetch": "^3.0.0",
49
64
  "jssha": "^3.3.1",
50
- "wonka": "^6.3.4"
65
+ "wonka": "^6.3.5"
51
66
  },
52
67
  "devDependencies": {
53
68
  "@jest/globals": "^29.7.0",
54
- "@rollup/plugin-babel": "^6.0.4",
55
- "@rollup/plugin-commonjs": "^28.0.2",
56
- "@rollup/plugin-node-resolve": "^16.0.0",
69
+ "@rollup/plugin-babel": "^6.1.0",
70
+ "@rollup/plugin-commonjs": "^28.0.9",
71
+ "@rollup/plugin-node-resolve": "^16.0.3",
57
72
  "buffer": "^6.0.3",
58
73
  "esbuild-jest": "^0.5.0",
59
74
  "eslint": "^8.57.1",
60
75
  "eslint-config-standard": "^17.1.0",
61
- "eslint-plugin-import": "^2.31.0",
76
+ "eslint-plugin-import": "^2.32.0",
62
77
  "eslint-plugin-n": "^16.6.2",
63
78
  "eslint-plugin-promise": "^6.6.0",
64
- "eslint-plugin-vue": "^9.32.0",
65
- "esmock": "^2.7.0",
79
+ "eslint-plugin-vue": "^9.33.0",
80
+ "esmock": "^2.7.3",
66
81
  "jest": "^29.7.0",
67
- "rollup": "^4.34.8",
68
- "vite": "^6.1.1"
82
+ "rollup": "^4.57.1",
83
+ "vite": "^6.4.1"
69
84
  },
70
85
  "browserslist": [
71
86
  "> 1%",
@@ -76,9 +91,14 @@
76
91
  "build": "vite build --config build/vite.config.mjs",
77
92
  "lint": "eslint --ext .js src",
78
93
  "test": "jest",
79
- "test:coverage": "jest --coverage"
94
+ "test:coverage": "jest --coverage",
95
+ "selftest": "npm run build && node tests/scripts/self-test.js",
96
+ "integration-test": "npm run build && node tests/scripts/integration-test.js",
97
+ "prepublishOnly": "npm run build"
80
98
  },
81
99
  "files": [
82
- "/src"
83
- ]
100
+ "/src",
101
+ "/dist"
102
+ ],
103
+ "packageManager": "yarn@4.9.2"
84
104
  }
package/src/Atom.js CHANGED
@@ -46,11 +46,11 @@ Please visit https://github.com/WishKnish/KnishIO-Client-JS for information.
46
46
  License: https://github.com/WishKnish/KnishIO-Client-JS/blob/master/LICENSE
47
47
  */
48
48
  import JsSHA from 'jssha'
49
- import { charsetBaseConvert } from './libraries/strings'
50
- import Meta from './Meta'
51
- import AtomMeta from './AtomMeta'
52
- import AtomsMissingException from './exception/AtomsMissingException'
53
- import versions from './versions/index'
49
+ import { charsetBaseConvert } from './libraries/strings.js'
50
+ import Meta from './Meta.js'
51
+ import AtomMeta from './AtomMeta.js'
52
+ import AtomsMissingException from './exception/AtomsMissingException.js'
53
+ import versions from './versions/index.js'
54
54
 
55
55
  /**
56
56
  * Atom class used to form microtransactions within a Molecule
@@ -176,6 +176,8 @@ export default class Atom {
176
176
  }
177
177
 
178
178
  // Create the final atom's object
179
+ // walletAddress is null for atoms without a pre-existing wallet (e.g., recipient V-atoms).
180
+ // toJSON() serializes null as '' for GraphQL compatibility; hash computation treats both identically.
179
181
  return new Atom({
180
182
  position: wallet ? wallet.position : null,
181
183
  walletAddress: wallet ? wallet.address : null,
@@ -208,6 +210,131 @@ export default class Atom {
208
210
  return target
209
211
  }
210
212
 
213
+ /**
214
+ * Returns JSON-ready object for cross-SDK compatibility (2025 JS best practices)
215
+ *
216
+ * Provides clean serialization of atomic operations with optional OTS fragments.
217
+ * Follows 2025 JavaScript best practices with proper type safety and validation.
218
+ *
219
+ * @param {Object} options - Serialization options
220
+ * @param {boolean} options.includeOtsFragments - Include OTS signature fragments (default: true)
221
+ * @param {boolean} options.validateFields - Validate required fields (default: false)
222
+ * @return {Object} JSON-serializable object
223
+ * @throws {Error} If atom is in invalid state for serialization
224
+ */
225
+ toJSON (options = {}) {
226
+ const {
227
+ includeOtsFragments = true,
228
+ validateFields = false
229
+ } = options;
230
+
231
+ try {
232
+ // Validate required fields if requested
233
+ if (validateFields) {
234
+ const requiredFields = ['position', 'walletAddress', 'isotope', 'token'];
235
+ for (const field of requiredFields) {
236
+ if (!this[field]) {
237
+ throw new Error(`Required field '${field}' is missing or empty`);
238
+ }
239
+ }
240
+ }
241
+
242
+ // Core atom properties (always included)
243
+ // Coerce null position/walletAddress/token to empty string for GraphQL compatibility.
244
+ // The molecular hash computation (getHashableValues) already treats null as '' (line 448),
245
+ // so this coercion does NOT change the hash. Required because the Rust validator's
246
+ // GraphQL schema uses String! (non-null) with #[graphql(default)] for these fields,
247
+ // which accepts omitted values but rejects explicit null.
248
+ const serialized = {
249
+ position: this.position ?? '',
250
+ walletAddress: this.walletAddress ?? '',
251
+ isotope: this.isotope,
252
+ token: this.token ?? '',
253
+ value: this.value,
254
+ batchId: this.batchId,
255
+ metaType: this.metaType,
256
+ metaId: this.metaId,
257
+ meta: this.meta || [],
258
+ index: this.index,
259
+ createdAt: this.createdAt,
260
+ version: this.version
261
+ };
262
+
263
+ // Optional OTS fragments (can be large, so optional)
264
+ if (includeOtsFragments && this.otsFragment) {
265
+ serialized.otsFragment = this.otsFragment;
266
+ }
267
+
268
+ return serialized;
269
+
270
+ } catch (error) {
271
+ throw new Error(`Atom serialization failed: ${error.message}`);
272
+ }
273
+ }
274
+
275
+ /**
276
+ * Creates an Atom instance from JSON data (2025 JS best practices)
277
+ *
278
+ * Handles cross-SDK atom deserialization with robust error handling.
279
+ * Essential for reconstructing atoms from other SDK implementations.
280
+ *
281
+ * @param {string|Object} json - JSON string or object to deserialize
282
+ * @param {Object} options - Deserialization options
283
+ * @param {boolean} options.validateStructure - Validate required fields (default: true)
284
+ * @param {boolean} options.strictMode - Strict validation mode (default: false)
285
+ * @return {Atom} Reconstructed atom instance
286
+ * @throws {Error} If JSON is invalid or required fields are missing
287
+ */
288
+ static fromJSON (json, options = {}) {
289
+ const {
290
+ validateStructure = true,
291
+ strictMode = false
292
+ } = options;
293
+
294
+ try {
295
+ // Parse JSON safely
296
+ const data = typeof json === 'string' ? JSON.parse(json) : json;
297
+
298
+ // Validate required fields in strict mode
299
+ if (strictMode || validateStructure) {
300
+ const requiredFields = ['position', 'walletAddress', 'isotope', 'token'];
301
+ for (const field of requiredFields) {
302
+ if (!data[field]) {
303
+ throw new Error(`Required field '${field}' is missing or empty`);
304
+ }
305
+ }
306
+ }
307
+
308
+ // Create atom instance with required fields
309
+ const atom = new Atom({
310
+ position: data.position,
311
+ walletAddress: data.walletAddress,
312
+ isotope: data.isotope,
313
+ token: data.token,
314
+ value: data.value,
315
+ batchId: data.batchId,
316
+ metaType: data.metaType,
317
+ metaId: data.metaId,
318
+ meta: data.meta,
319
+ index: data.index,
320
+ version: data.version
321
+ });
322
+
323
+ // Set additional properties that may not be in constructor
324
+ if (data.otsFragment) {
325
+ atom.otsFragment = data.otsFragment;
326
+ }
327
+ if (data.createdAt) {
328
+ atom.createdAt = data.createdAt;
329
+ }
330
+
331
+ return atom;
332
+
333
+ } catch (error) {
334
+ throw new Error(`Atom deserialization failed: ${error.message}`);
335
+ }
336
+ }
337
+
211
338
  /**
212
339
  * Produces a hash of the atoms inside a molecule.
213
340
  * Used to generate the molecularHash field for Molecules.
package/src/AtomMeta.js CHANGED
@@ -46,8 +46,8 @@ Please visit https://github.com/WishKnish/KnishIO-Client-JS for information.
46
46
  License: https://github.com/WishKnish/KnishIO-Client-JS/blob/master/LICENSE
47
47
  */
48
48
 
49
- import PolicyMeta from './PolicyMeta'
50
- import Meta from './Meta'
49
+ import PolicyMeta from './PolicyMeta.js'
50
+ import Meta from './Meta.js'
51
51
 
52
52
  const USE_META_CONTEXT = false
53
53
  const DEFAULT_META_CONTEXT = 'https://www.schema.org'
@@ -94,10 +94,7 @@ export default class AtomMeta {
94
94
  * @returns {AtomMeta}
95
95
  */
96
96
  setAtomWallet (wallet) {
97
- const walletMeta = {
98
- pubkey: wallet.pubkey,
99
- characters: wallet.characters
100
- }
97
+ const walletMeta = {}
101
98
 
102
99
  // Add token units meta key
103
100
  if (wallet.tokenUnits && wallet.tokenUnits.length) {
@@ -108,8 +105,10 @@ export default class AtomMeta {
108
105
  walletMeta.tradeRates = JSON.stringify(wallet.tradeRates)
109
106
  }
110
107
 
111
- // Merge all wallet's metas
112
- this.merge(walletMeta)
108
+ // Merge all wallet's metas (if any)
109
+ if (Object.keys(walletMeta).length > 0) {
110
+ this.merge(walletMeta)
111
+ }
113
112
  return this
114
113
  }
115
114
 
package/src/AuthToken.js CHANGED
@@ -46,7 +46,7 @@ Please visit https://github.com/WishKnish/KnishIO-Client-JS for information.
46
46
  License: https://github.com/WishKnish/KnishIO-Client-JS/blob/master/LICENSE
47
47
  */
48
48
 
49
- import Wallet from './Wallet'
49
+ import Wallet from './Wallet.js'
50
50
 
51
51
  /**
52
52
  *
@@ -45,60 +45,62 @@ Please visit https://github.com/WishKnish/KnishIO-Client-JS for information.
45
45
 
46
46
  License: https://github.com/WishKnish/KnishIO-Client-JS/blob/master/LICENSE
47
47
  */
48
- import Dot from './libraries/Dot'
49
- import Decimal from './libraries/Decimal'
48
+ import Dot from './libraries/Dot.js'
49
+ import Decimal from './libraries/Decimal.js'
50
50
  import {
51
51
  generateBatchId,
52
52
  generateBundleHash,
53
53
  generateSecret
54
- } from './libraries/crypto'
55
- import Molecule from './Molecule'
56
- import Wallet from './Wallet'
57
- import AuthToken from './AuthToken'
58
- import QueryContinuId from './query/QueryContinuId'
59
- import QueryWalletBundle from './query/QueryWalletBundle'
60
- import QueryWalletList from './query/QueryWalletList'
61
- import QueryBalance from './query/QueryBalance'
62
- import QueryMetaType from './query/QueryMetaType'
63
- import QueryBatch from './query/QueryBatch'
64
- import QueryBatchHistory from './query/QueryBatchHistory'
65
- import MutationRequestAuthorization from './mutation/MutationRequestAuthorization'
66
- import MutationCreateToken from './mutation/MutationCreateToken'
67
- import MutationRequestTokens from './mutation/MutationRequestTokens'
68
- import MutationTransferTokens from './mutation/MutationTransferTokens'
69
- import MutationProposeMolecule from './mutation/MutationProposeMolecule'
70
- import MutationCreateIdentifier from './mutation/MutationCreateIdentifier'
71
- import MutationClaimShadowWallet from './mutation/MutationClaimShadowWallet'
72
- import MutationCreateMeta from './mutation/MutationCreateMeta'
73
- import MutationCreateWallet from './mutation/MutationCreateWallet'
74
- import MutationRequestAuthorizationGuest from './mutation/MutationRequestAuthorizationGuest'
75
- import TransferBalanceException from './exception/TransferBalanceException'
76
- import CodeException from './exception/CodeException'
77
- import UnauthenticatedException from './exception/UnauthenticatedException'
78
- import WalletShadowException from './exception/WalletShadowException'
79
- import StackableUnitDecimalsException from './exception/StackableUnitDecimalsException'
80
- import StackableUnitAmountException from './exception/StackableUnitAmountException'
81
- import CreateMoleculeSubscribe from './subscribe/CreateMoleculeSubscribe'
82
- import WalletStatusSubscribe from './subscribe/WalletStatusSubscribe'
83
- import ActiveWalletSubscribe from './subscribe/ActiveWalletSubscribe'
84
- import ActiveSessionSubscribe from './subscribe/ActiveSessionSubscribe'
85
- import MutationActiveSession from './mutation/MutationActiveSession'
86
- import QueryActiveSession from './query/QueryActiveSession'
87
- import QueryUserActivity from './query/QueryUserActivity'
88
- import QueryToken from './query/QueryToken'
89
- import BatchIdException from './exception/BatchIdException'
90
- import AuthorizationRejectedException from './exception/AuthorizationRejectedException'
91
- import QueryAtom from './query/QueryAtom'
92
- import QueryPolicy from './query/QueryPolicy'
93
- import QueryMetaTypeViaAtom from './query/QueryMetaTypeViaAtom'
94
- import MutationCreateRule from './mutation/MutationCreateRule'
95
- import MutationDepositBufferToken from './mutation/MutationDepositBufferToken'
96
- import MutationWithdrawBufferToken from './mutation/MutationWithdrawBufferToken'
54
+ } from './libraries/crypto.js'
55
+ import Molecule from './Molecule.js'
56
+ import Wallet from './Wallet.js'
57
+ import AuthToken from './AuthToken.js'
58
+ import QueryContinuId from './query/QueryContinuId.js'
59
+ import QueryWalletBundle from './query/QueryWalletBundle.js'
60
+ import QueryWalletList from './query/QueryWalletList.js'
61
+ import QueryBalance from './query/QueryBalance.js'
62
+ import QueryMetaType from './query/QueryMetaType.js'
63
+ import QueryBatch from './query/QueryBatch.js'
64
+ import QueryBatchHistory from './query/QueryBatchHistory.js'
65
+ import MutationRequestAuthorization from './mutation/MutationRequestAuthorization.js'
66
+ import MutationCreateToken from './mutation/MutationCreateToken.js'
67
+ import MutationRequestTokens from './mutation/MutationRequestTokens.js'
68
+ import MutationTransferTokens from './mutation/MutationTransferTokens.js'
69
+ import MutationProposeMolecule from './mutation/MutationProposeMolecule.js'
70
+ import MutationCreateIdentifier from './mutation/MutationCreateIdentifier.js'
71
+ import MutationClaimShadowWallet from './mutation/MutationClaimShadowWallet.js'
72
+ import MutationCreateMeta from './mutation/MutationCreateMeta.js'
73
+ import MutationPeering from './mutation/MutationPeering.js'
74
+ import MutationAppendRequest from './mutation/MutationAppendRequest.js'
75
+ import MutationCreateWallet from './mutation/MutationCreateWallet.js'
76
+ import MutationRequestAuthorizationGuest from './mutation/MutationRequestAuthorizationGuest.js'
77
+ import TransferBalanceException from './exception/TransferBalanceException.js'
78
+ import CodeException from './exception/CodeException.js'
79
+ import UnauthenticatedException from './exception/UnauthenticatedException.js'
80
+ import WalletShadowException from './exception/WalletShadowException.js'
81
+ import StackableUnitDecimalsException from './exception/StackableUnitDecimalsException.js'
82
+ import StackableUnitAmountException from './exception/StackableUnitAmountException.js'
83
+ import CreateMoleculeSubscribe from './subscribe/CreateMoleculeSubscribe.js'
84
+ import WalletStatusSubscribe from './subscribe/WalletStatusSubscribe.js'
85
+ import ActiveWalletSubscribe from './subscribe/ActiveWalletSubscribe.js'
86
+ import ActiveSessionSubscribe from './subscribe/ActiveSessionSubscribe.js'
87
+ import MutationActiveSession from './mutation/MutationActiveSession.js'
88
+ import QueryActiveSession from './query/QueryActiveSession.js'
89
+ import QueryUserActivity from './query/QueryUserActivity.js'
90
+ import QueryToken from './query/QueryToken.js'
91
+ import BatchIdException from './exception/BatchIdException.js'
92
+ import AuthorizationRejectedException from './exception/AuthorizationRejectedException.js'
93
+ import QueryAtom from './query/QueryAtom.js'
94
+ import QueryPolicy from './query/QueryPolicy.js'
95
+ import QueryMetaTypeViaAtom from './query/QueryMetaTypeViaAtom.js'
96
+ import MutationCreateRule from './mutation/MutationCreateRule.js'
97
+ import MutationDepositBufferToken from './mutation/MutationDepositBufferToken.js'
98
+ import MutationWithdrawBufferToken from './mutation/MutationWithdrawBufferToken.js'
97
99
  import {
98
100
  getFingerprint,
99
101
  getFingerprintData
100
102
  } from '@thumbmarkjs/thumbmarkjs'
101
- import UrqlClientWrapper from './libraries/urql/UrqlClientWrapper'
103
+ import UrqlClientWrapper from './libraries/urql/UrqlClientWrapper.js'
102
104
 
103
105
  /**
104
106
  * Base client class providing a powerful but user-friendly wrapper
@@ -250,16 +252,6 @@ export default class KnishIOClient {
250
252
  this.remainderWallet = null
251
253
  }
252
254
 
253
- /**
254
- * Returns the currently defined Cell identifier for this session
255
- *
256
- * @deprecated Please use getCellSlug() instead
257
- * @return {string|null}
258
- */
259
- cellSlug () {
260
- return this.getCellSlug()
261
- }
262
-
263
255
  /**
264
256
  * Returns the currently defined Cell identifier for this session
265
257
  *
@@ -272,14 +264,25 @@ export default class KnishIOClient {
272
264
  /**
273
265
  * Sets the Cell identifier for this session
274
266
  *
275
- * @param cellSlug
267
+ * @param {string} cellSlug
276
268
  */
277
269
  setCellSlug (cellSlug) {
278
270
  this.$__cellSlug = cellSlug
279
271
  }
280
272
 
273
+ /**
274
+ * Sets the endpoint URI for this session
275
+ *
276
+ * @param {string|object} uri
277
+ */
281
278
  setUri (uri) {
282
279
  this.$__uris = typeof uri === 'object' ? uri : [uri]
280
+
281
+ // If client exists, update its URI with a random one from the new array
282
+ if (this.$__client) {
283
+ const randomUri = this.getRandomUri()
284
+ this.$__client.setUri(randomUri)
285
+ }
283
286
  }
284
287
 
285
288
  /**
@@ -291,16 +294,6 @@ export default class KnishIOClient {
291
294
  return this.$__client.getUri()
292
295
  }
293
296
 
294
- /**
295
- * Retrieves the endpoint URI for this session
296
- *
297
- * @deprecated Please use getUri() instead
298
- * @returns {string}
299
- */
300
- uri () {
301
- return this.getUri()
302
- }
303
-
304
297
  /**
305
298
  * Returns the GraphQL client class session
306
299
  *
@@ -320,8 +313,8 @@ export default class KnishIOClient {
320
313
  secret: this.$__secret,
321
314
  cellSlug: this.$__cellSlug,
322
315
  encrypt: this.$__encrypt
323
- }).then(() => {
324
- // Success
316
+ }).catch(err => {
317
+ this.log('warn', `KnishIOClient::client() - Background authorization failed: ${ err.message }`)
325
318
  })
326
319
  } else {
327
320
  // Use stored authorization data
@@ -548,7 +541,8 @@ export default class KnishIOClient {
548
541
  */
549
542
  async executeQuery (query, variables = null) {
550
543
  // Check and refresh authorization token if needed
551
- if (this.$__authToken && this.$__authToken.isExpired()) {
544
+ // Guard with $__authInProcess to prevent concurrent auth requests
545
+ if (this.$__authToken && this.$__authToken.isExpired() && !this.$__authInProcess) {
552
546
  this.log('info', 'KnishIOClient::executeQuery() - Access token is expired. Getting new one...')
553
547
  await this.requestAuthToken({
554
548
  secret: this.$__secret,
@@ -825,7 +819,8 @@ export default class KnishIOClient {
825
819
  countBy,
826
820
  values,
827
821
  keys,
828
- atomValues
822
+ atomValues,
823
+ cellSlug: this.getCellSlug()
829
824
  })
830
825
  } else {
831
826
  /**
@@ -841,14 +836,12 @@ export default class KnishIOClient {
841
836
  filter,
842
837
  queryArgs,
843
838
  count,
844
- countBy
839
+ countBy,
840
+ cellSlug: this.getCellSlug()
845
841
  })
846
842
  }
847
843
 
848
844
  return this.executeQuery(query, variables)
849
- .then((response) => {
850
- return response.payload()
851
- })
852
845
  }
853
846
 
854
847
  /**
@@ -1270,6 +1263,69 @@ export default class KnishIOClient {
1270
1263
  return await this.executeQuery(query)
1271
1264
  }
1272
1265
 
1266
+ /**
1267
+ * Builds and executes a molecule to register a peer node via P-isotope
1268
+ *
1269
+ * @param {string} host - The peer host URL to register
1270
+ * @returns {Promise<ResponsePeering>} - A Promise that resolves with the peering response.
1271
+ */
1272
+ async registerPeer ({
1273
+ host
1274
+ }) {
1275
+ /**
1276
+ * @type {MutationPeering}
1277
+ */
1278
+ const query = await this.createMoleculeMutation({
1279
+ mutationClass: MutationPeering,
1280
+ molecule: await this.createMolecule({
1281
+ secret: this.getSecret(),
1282
+ sourceWallet: await this.getSourceWallet()
1283
+ })
1284
+ })
1285
+
1286
+ query.fillMolecule({
1287
+ host
1288
+ })
1289
+
1290
+ return await this.executeQuery(query)
1291
+ }
1292
+
1293
+ /**
1294
+ * Builds and executes a molecule to submit an append request via A-isotope
1295
+ *
1296
+ * @param {string} metaType - The target MetaType to append to
1297
+ * @param {string} metaId - The target MetaId to append to
1298
+ * @param {string} action - The action to perform
1299
+ * @param {object} [meta={}] - Additional metadata
1300
+ * @returns {Promise<ResponseAppendRequest>} - A Promise that resolves with the append request response.
1301
+ */
1302
+ async appendRequest ({
1303
+ metaType,
1304
+ metaId,
1305
+ action,
1306
+ meta = {}
1307
+ }) {
1308
+ /**
1309
+ * @type {MutationAppendRequest}
1310
+ */
1311
+ const query = await this.createMoleculeMutation({
1312
+ mutationClass: MutationAppendRequest,
1313
+ molecule: await this.createMolecule({
1314
+ secret: this.getSecret(),
1315
+ sourceWallet: await this.getSourceWallet()
1316
+ })
1317
+ })
1318
+
1319
+ query.fillMolecule({
1320
+ metaType,
1321
+ metaId,
1322
+ action,
1323
+ meta
1324
+ })
1325
+
1326
+ return await this.executeQuery(query)
1327
+ }
1328
+
1273
1329
  /**
1274
1330
  * Builds and executes a molecule to create a new identifier on the ledger
1275
1331
  *
@@ -2027,7 +2083,13 @@ export default class KnishIOClient {
2027
2083
  // Did the authorization molecule get accepted?
2028
2084
  if (response.success()) {
2029
2085
  // Create & set an auth token from the response data
2030
- const authToken = AuthToken.create(response.payload(), wallet)
2086
+ // Map server payload field names (time/key) to AuthToken constructor names (expiresAt/pubkey)
2087
+ const authToken = AuthToken.create({
2088
+ token: response.token(),
2089
+ expiresAt: response.time(),
2090
+ pubkey: response.pubKey(),
2091
+ encrypt: response.encrypt()
2092
+ }, wallet)
2031
2093
  this.setAuthToken(authToken)
2032
2094
  } else {
2033
2095
  throw new AuthorizationRejectedException(`KnishIOClient::requestGuestAuthToken() - Authorization attempt rejected by ledger. Reason: ${ response.reason() }`)
@@ -2078,7 +2140,13 @@ export default class KnishIOClient {
2078
2140
  // Did the authorization molecule get accepted?
2079
2141
  if (response.success()) {
2080
2142
  // Create & set an auth token from the response data
2081
- const authToken = AuthToken.create(response.payload(), wallet)
2143
+ // Map server payload field names (time/key) to AuthToken constructor names (expiresAt/pubkey)
2144
+ const authToken = AuthToken.create({
2145
+ token: response.token(),
2146
+ expiresAt: response.time(),
2147
+ pubkey: response.pubKey(),
2148
+ encrypt: response.encrypt()
2149
+ }, wallet)
2082
2150
  this.setAuthToken(authToken)
2083
2151
  } else {
2084
2152
  throw new AuthorizationRejectedException(`KnishIOClient::requestProfileAuthToken() - Authorization attempt rejected by ledger. Reason: ${ response.reason() }`)
package/src/Meta.js CHANGED
@@ -59,14 +59,18 @@ export default class Meta {
59
59
  static normalizeMeta (meta) {
60
60
  // Ensuring that only object-based meta gets normalized
61
61
  if (Array.isArray(meta)) {
62
- return meta
62
+ return meta.map(entry => ({
63
+ key: entry.key,
64
+ value: entry.value == null ? null : String(entry.value)
65
+ }))
63
66
  }
64
67
 
65
68
  // Converting object-based meta into array-based notation
66
69
  const target = []
67
70
  for (const property in meta) {
68
71
  if (Object.prototype.hasOwnProperty.call(meta, property)) {
69
- target.push({ key: property, value: meta[property] })
72
+ const raw = meta[property]
73
+ target.push({ key: property, value: raw == null ? null : String(raw) })
70
74
  }
71
75
  }
72
76