@wishknish/knishio-client-js 0.6.4 → 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.
- package/dist/client.cjs.js +513 -0
- package/dist/client.cjs.js.map +1 -0
- package/dist/client.es.mjs +8176 -0
- package/dist/client.es.mjs.map +1 -0
- package/dist/client.iife.js +30 -45
- package/dist/client.iife.js.map +1 -0
- package/package.json +48 -28
- package/src/Atom.js +132 -5
- package/src/AtomMeta.js +7 -8
- package/src/AuthToken.js +1 -1
- package/src/KnishIOClient.js +133 -76
- package/src/Meta.js +6 -2
- package/src/Molecule.js +289 -38
- package/src/PolicyMeta.js +1 -1
- package/src/Wallet.js +19 -11
- package/src/exception/AtomIndexException.js +1 -1
- package/src/exception/AtomsMissingException.js +1 -1
- package/src/exception/AuthorizationRejectedException.js +1 -1
- package/src/exception/BalanceInsufficientException.js +1 -1
- package/src/exception/BatchIdException.js +1 -1
- package/src/exception/CodeException.js +1 -1
- package/src/exception/DecryptionKeyException.js +1 -1
- package/src/exception/InvalidResponseException.js +1 -1
- package/src/exception/MetaMissingException.js +1 -1
- package/src/exception/MolecularHashMismatchException.js +1 -1
- package/src/exception/MolecularHashMissingException.js +1 -1
- package/src/exception/NegativeAmountException.js +1 -1
- package/src/exception/PolicyInvalidException.js +1 -1
- package/src/exception/SignatureMalformedException.js +1 -1
- package/src/exception/SignatureMismatchException.js +1 -1
- package/src/exception/StackableUnitAmountException.js +1 -1
- package/src/exception/StackableUnitDecimalsException.js +1 -1
- package/src/exception/TransferBalanceException.js +1 -1
- package/src/exception/TransferMalformedException.js +1 -1
- package/src/exception/TransferMismatchedException.js +1 -1
- package/src/exception/TransferRemainderException.js +1 -1
- package/src/exception/TransferToSelfException.js +1 -1
- package/src/exception/TransferUnbalancedException.js +1 -1
- package/src/exception/UnauthenticatedException.js +1 -1
- package/src/exception/WalletCredentialException.js +1 -1
- package/src/exception/WalletShadowException.js +1 -1
- package/src/exception/WrongTokenTypeException.js +1 -1
- package/src/exception/index.js +25 -25
- package/src/index.js +23 -9
- package/src/instance/Rules/Callback.js +5 -5
- package/src/instance/Rules/Condition.js +1 -1
- package/src/instance/Rules/Rule.js +4 -4
- package/src/instance/Rules/exception/RuleArgumentException.js +1 -1
- package/src/libraries/CheckMolecule.js +76 -24
- package/src/libraries/crypto.js +16 -2
- package/src/libraries/strings.js +1 -1
- package/src/libraries/urql/UrqlClientWrapper.js +3 -1
- package/src/mutation/Mutation.js +2 -2
- package/src/mutation/MutationActiveSession.js +2 -2
- package/src/mutation/MutationAppendRequest.js +91 -0
- package/src/mutation/MutationClaimShadowWallet.js +3 -3
- package/src/mutation/MutationCreateIdentifier.js +2 -2
- package/src/mutation/MutationCreateMeta.js +2 -2
- package/src/mutation/MutationCreateRule.js +2 -2
- package/src/mutation/MutationCreateToken.js +2 -2
- package/src/mutation/MutationCreateWallet.js +2 -2
- package/src/mutation/MutationDepositBufferToken.js +1 -1
- package/src/mutation/MutationLinkIdentifier.js +2 -2
- package/src/mutation/MutationPeering.js +82 -0
- package/src/mutation/MutationProposeMolecule.js +2 -2
- package/src/mutation/MutationRequestAuthorization.js +2 -2
- package/src/mutation/MutationRequestAuthorizationGuest.js +2 -2
- package/src/mutation/MutationRequestTokens.js +2 -2
- package/src/mutation/MutationTransferTokens.js +2 -2
- package/src/mutation/MutationWithdrawBufferToken.js +1 -1
- package/src/query/Query.js +2 -2
- package/src/query/QueryActiveSession.js +2 -2
- package/src/query/QueryAtom.js +2 -2
- package/src/query/QueryBalance.js +2 -2
- package/src/query/QueryBatch.js +2 -2
- package/src/query/QueryBatchHistory.js +3 -3
- package/src/query/QueryContinuId.js +2 -2
- package/src/query/QueryMetaType.js +11 -5
- package/src/query/QueryMetaTypeViaAtom.js +11 -4
- package/src/query/QueryPolicy.js +2 -2
- package/src/query/QueryToken.js +2 -2
- package/src/query/QueryUserActivity.js +2 -2
- package/src/query/QueryWalletBundle.js +2 -2
- package/src/query/QueryWalletList.js +2 -2
- package/src/response/Response.js +168 -4
- package/src/response/ResponseActiveSession.js +2 -2
- package/src/response/{ResponseMetaBatch.js → ResponseAppendRequest.js} +4 -21
- package/src/response/ResponseAtom.js +2 -2
- package/src/response/ResponseAuthorizationGuest.js +4 -4
- package/src/response/ResponseBalance.js +9 -4
- package/src/response/ResponseClaimShadowWallet.js +1 -1
- package/src/response/ResponseContinuId.js +3 -3
- package/src/response/ResponseCreateIdentifier.js +1 -1
- package/src/response/ResponseCreateMeta.js +1 -1
- package/src/response/ResponseCreateRule.js +1 -1
- package/src/response/ResponseCreateToken.js +1 -1
- package/src/response/ResponseCreateWallet.js +1 -1
- package/src/response/ResponseLinkIdentifier.js +3 -3
- package/src/response/ResponseMetaType.js +2 -2
- package/src/response/ResponseMetaTypeViaAtom.js +2 -2
- package/src/response/ResponsePeering.js +55 -0
- package/src/response/ResponsePolicy.js +2 -2
- package/src/response/ResponseProposeMolecule.js +3 -3
- package/src/response/ResponseQueryActiveSession.js +2 -2
- package/src/response/ResponseQueryUserActivity.js +2 -2
- package/src/response/ResponseRequestAuthorization.js +3 -3
- package/src/response/ResponseRequestAuthorizationGuest.js +3 -3
- package/src/response/ResponseRequestTokens.js +1 -1
- package/src/response/ResponseTransferTokens.js +1 -1
- package/src/response/ResponseWalletBundle.js +3 -3
- package/src/response/ResponseWalletList.js +4 -4
- package/src/subscribe/ActiveSessionSubscribe.js +1 -1
- package/src/subscribe/ActiveWalletSubscribe.js +1 -1
- package/src/subscribe/CreateMoleculeSubscribe.js +1 -1
- package/src/subscribe/Subscribe.js +1 -1
- package/src/subscribe/WalletStatusSubscribe.js +1 -1
- package/src/types/index.js +2 -2
- package/src/versions/Version4.js +1 -1
- 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.
|
|
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.
|
|
32
|
-
"module": "dist/client.es.
|
|
33
|
-
"
|
|
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
|
|
58
|
+
"@noble/post-quantum": "^0.5.4",
|
|
44
59
|
"@thumbmarkjs/thumbmarkjs": "^0.19.1",
|
|
45
|
-
"@urql/core": "^5.
|
|
46
|
-
"graphql": "^16.
|
|
47
|
-
"graphql-ws": "^6.0.
|
|
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.
|
|
65
|
+
"wonka": "^6.3.5"
|
|
51
66
|
},
|
|
52
67
|
"devDependencies": {
|
|
53
68
|
"@jest/globals": "^29.7.0",
|
|
54
|
-
"@rollup/plugin-babel": "^6.0
|
|
55
|
-
"@rollup/plugin-commonjs": "^28.0.
|
|
56
|
-
"@rollup/plugin-node-resolve": "^16.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.
|
|
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.
|
|
65
|
-
"esmock": "^2.7.
|
|
79
|
+
"eslint-plugin-vue": "^9.33.0",
|
|
80
|
+
"esmock": "^2.7.3",
|
|
66
81
|
"jest": "^29.7.0",
|
|
67
|
-
"rollup": "^4.
|
|
68
|
-
"vite": "^6.
|
|
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
|
-
|
|
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
package/src/KnishIOClient.js
CHANGED
|
@@ -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
|
|
74
|
-
import
|
|
75
|
-
import
|
|
76
|
-
import
|
|
77
|
-
import
|
|
78
|
-
import
|
|
79
|
-
import
|
|
80
|
-
import
|
|
81
|
-
import
|
|
82
|
-
import
|
|
83
|
-
import
|
|
84
|
-
import
|
|
85
|
-
import
|
|
86
|
-
import
|
|
87
|
-
import
|
|
88
|
-
import
|
|
89
|
-
import
|
|
90
|
-
import
|
|
91
|
-
import
|
|
92
|
-
import
|
|
93
|
-
import
|
|
94
|
-
import
|
|
95
|
-
import
|
|
96
|
-
import
|
|
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
|
*
|
|
@@ -302,16 +294,6 @@ export default class KnishIOClient {
|
|
|
302
294
|
return this.$__client.getUri()
|
|
303
295
|
}
|
|
304
296
|
|
|
305
|
-
/**
|
|
306
|
-
* Retrieves the endpoint URI for this session
|
|
307
|
-
*
|
|
308
|
-
* @deprecated Please use getUri() instead
|
|
309
|
-
* @returns {string}
|
|
310
|
-
*/
|
|
311
|
-
uri () {
|
|
312
|
-
return this.getUri()
|
|
313
|
-
}
|
|
314
|
-
|
|
315
297
|
/**
|
|
316
298
|
* Returns the GraphQL client class session
|
|
317
299
|
*
|
|
@@ -331,8 +313,8 @@ export default class KnishIOClient {
|
|
|
331
313
|
secret: this.$__secret,
|
|
332
314
|
cellSlug: this.$__cellSlug,
|
|
333
315
|
encrypt: this.$__encrypt
|
|
334
|
-
}).
|
|
335
|
-
|
|
316
|
+
}).catch(err => {
|
|
317
|
+
this.log('warn', `KnishIOClient::client() - Background authorization failed: ${ err.message }`)
|
|
336
318
|
})
|
|
337
319
|
} else {
|
|
338
320
|
// Use stored authorization data
|
|
@@ -559,7 +541,8 @@ export default class KnishIOClient {
|
|
|
559
541
|
*/
|
|
560
542
|
async executeQuery (query, variables = null) {
|
|
561
543
|
// Check and refresh authorization token if needed
|
|
562
|
-
|
|
544
|
+
// Guard with $__authInProcess to prevent concurrent auth requests
|
|
545
|
+
if (this.$__authToken && this.$__authToken.isExpired() && !this.$__authInProcess) {
|
|
563
546
|
this.log('info', 'KnishIOClient::executeQuery() - Access token is expired. Getting new one...')
|
|
564
547
|
await this.requestAuthToken({
|
|
565
548
|
secret: this.$__secret,
|
|
@@ -836,7 +819,8 @@ export default class KnishIOClient {
|
|
|
836
819
|
countBy,
|
|
837
820
|
values,
|
|
838
821
|
keys,
|
|
839
|
-
atomValues
|
|
822
|
+
atomValues,
|
|
823
|
+
cellSlug: this.getCellSlug()
|
|
840
824
|
})
|
|
841
825
|
} else {
|
|
842
826
|
/**
|
|
@@ -852,14 +836,12 @@ export default class KnishIOClient {
|
|
|
852
836
|
filter,
|
|
853
837
|
queryArgs,
|
|
854
838
|
count,
|
|
855
|
-
countBy
|
|
839
|
+
countBy,
|
|
840
|
+
cellSlug: this.getCellSlug()
|
|
856
841
|
})
|
|
857
842
|
}
|
|
858
843
|
|
|
859
844
|
return this.executeQuery(query, variables)
|
|
860
|
-
.then((response) => {
|
|
861
|
-
return response.payload()
|
|
862
|
-
})
|
|
863
845
|
}
|
|
864
846
|
|
|
865
847
|
/**
|
|
@@ -1281,6 +1263,69 @@ export default class KnishIOClient {
|
|
|
1281
1263
|
return await this.executeQuery(query)
|
|
1282
1264
|
}
|
|
1283
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
|
+
|
|
1284
1329
|
/**
|
|
1285
1330
|
* Builds and executes a molecule to create a new identifier on the ledger
|
|
1286
1331
|
*
|
|
@@ -2038,7 +2083,13 @@ export default class KnishIOClient {
|
|
|
2038
2083
|
// Did the authorization molecule get accepted?
|
|
2039
2084
|
if (response.success()) {
|
|
2040
2085
|
// Create & set an auth token from the response data
|
|
2041
|
-
|
|
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)
|
|
2042
2093
|
this.setAuthToken(authToken)
|
|
2043
2094
|
} else {
|
|
2044
2095
|
throw new AuthorizationRejectedException(`KnishIOClient::requestGuestAuthToken() - Authorization attempt rejected by ledger. Reason: ${ response.reason() }`)
|
|
@@ -2089,7 +2140,13 @@ export default class KnishIOClient {
|
|
|
2089
2140
|
// Did the authorization molecule get accepted?
|
|
2090
2141
|
if (response.success()) {
|
|
2091
2142
|
// Create & set an auth token from the response data
|
|
2092
|
-
|
|
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)
|
|
2093
2150
|
this.setAuthToken(authToken)
|
|
2094
2151
|
} else {
|
|
2095
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
|
-
|
|
72
|
+
const raw = meta[property]
|
|
73
|
+
target.push({ key: property, value: raw == null ? null : String(raw) })
|
|
70
74
|
}
|
|
71
75
|
}
|
|
72
76
|
|