@wishknish/knishio-client-js 0.6.4 → 0.7.5

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 (121) hide show
  1. package/dist/client.cjs.js +567 -0
  2. package/dist/client.cjs.js.map +1 -0
  3. package/dist/client.es.mjs +8665 -0
  4. package/dist/client.es.mjs.map +1 -0
  5. package/dist/client.iife.js +84 -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 +180 -78
  12. package/src/Meta.js +6 -2
  13. package/src/Molecule.js +383 -44
  14. package/src/PolicyMeta.js +1 -1
  15. package/src/Wallet.js +67 -12
  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 +29 -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 +285 -27
  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/QueryMetaTypeViaMolecule.js +223 -0
  81. package/src/query/QueryPolicy.js +2 -2
  82. package/src/query/QueryToken.js +2 -2
  83. package/src/query/QueryUserActivity.js +2 -2
  84. package/src/query/QueryWalletBundle.js +2 -2
  85. package/src/query/QueryWalletList.js +2 -2
  86. package/src/response/Response.js +168 -4
  87. package/src/response/ResponseActiveSession.js +2 -2
  88. package/src/response/{ResponseMetaBatch.js → ResponseAppendRequest.js} +4 -21
  89. package/src/response/ResponseAtom.js +2 -2
  90. package/src/response/ResponseAuthorizationGuest.js +4 -4
  91. package/src/response/ResponseBalance.js +9 -4
  92. package/src/response/ResponseClaimShadowWallet.js +1 -1
  93. package/src/response/ResponseContinuId.js +4 -4
  94. package/src/response/ResponseCreateIdentifier.js +1 -1
  95. package/src/response/ResponseCreateMeta.js +1 -1
  96. package/src/response/ResponseCreateRule.js +1 -1
  97. package/src/response/ResponseCreateToken.js +1 -1
  98. package/src/response/ResponseCreateWallet.js +1 -1
  99. package/src/response/ResponseLinkIdentifier.js +3 -3
  100. package/src/response/ResponseMetaType.js +2 -2
  101. package/src/response/ResponseMetaTypeViaAtom.js +2 -2
  102. package/src/response/ResponseMetaTypeViaMolecule.js +210 -0
  103. package/src/response/ResponsePeering.js +55 -0
  104. package/src/response/ResponsePolicy.js +2 -2
  105. package/src/response/ResponseProposeMolecule.js +3 -3
  106. package/src/response/ResponseQueryActiveSession.js +2 -2
  107. package/src/response/ResponseQueryUserActivity.js +2 -2
  108. package/src/response/ResponseRequestAuthorization.js +3 -3
  109. package/src/response/ResponseRequestAuthorizationGuest.js +3 -3
  110. package/src/response/ResponseRequestTokens.js +1 -1
  111. package/src/response/ResponseTransferTokens.js +1 -1
  112. package/src/response/ResponseWalletBundle.js +3 -3
  113. package/src/response/ResponseWalletList.js +5 -5
  114. package/src/subscribe/ActiveSessionSubscribe.js +1 -1
  115. package/src/subscribe/ActiveWalletSubscribe.js +1 -1
  116. package/src/subscribe/CreateMoleculeSubscribe.js +1 -1
  117. package/src/subscribe/Subscribe.js +1 -1
  118. package/src/subscribe/WalletStatusSubscribe.js +1 -1
  119. package/src/types/index.js +2 -2
  120. package/src/versions/Version4.js +1 -1
  121. 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.4",
3
+ "version": "0.7.5",
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.1",
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.3",
56
- "@rollup/plugin-node-resolve": "^16.0.1",
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
  *