@wishknish/knishio-client-js 0.5.2 → 0.6.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.
Files changed (133) hide show
  1. package/README.md +207 -274
  2. package/dist/client.iife.js +533 -0
  3. package/package.json +37 -79
  4. package/src/.babelrc +0 -22
  5. package/src/Atom.js +171 -132
  6. package/src/AtomMeta.js +76 -50
  7. package/src/AuthToken.js +38 -47
  8. package/src/KnishIOClient.js +934 -987
  9. package/src/Meta.js +15 -17
  10. package/src/Molecule.js +423 -494
  11. package/src/PolicyMeta.js +32 -41
  12. package/src/TokenUnit.js +30 -32
  13. package/src/Wallet.js +275 -265
  14. package/src/exception/AtomIndexException.js +4 -8
  15. package/src/exception/AtomsMissingException.js +4 -6
  16. package/src/exception/AuthorizationRejectedException.js +4 -5
  17. package/src/exception/BalanceInsufficientException.js +4 -8
  18. package/src/exception/BaseException.js +6 -8
  19. package/src/exception/BatchIdException.js +5 -7
  20. package/src/exception/CodeException.js +4 -8
  21. package/src/{libraries/ApolloLink/HttpLink.js → exception/DecryptionKeyException.js} +12 -15
  22. package/src/exception/InvalidResponseException.js +4 -5
  23. package/src/exception/MetaMissingException.js +4 -6
  24. package/src/exception/MolecularHashMismatchException.js +4 -6
  25. package/src/exception/MolecularHashMissingException.js +4 -5
  26. package/src/exception/NegativeAmountException.js +4 -5
  27. package/src/exception/PolicyInvalidException.js +4 -4
  28. package/src/exception/SignatureMalformedException.js +4 -5
  29. package/src/exception/SignatureMismatchException.js +4 -5
  30. package/src/exception/StackableUnitAmountException.js +4 -5
  31. package/src/exception/StackableUnitDecimalsException.js +4 -5
  32. package/src/exception/TransferBalanceException.js +4 -5
  33. package/src/exception/TransferMalformedException.js +4 -5
  34. package/src/exception/TransferMismatchedException.js +4 -5
  35. package/src/exception/TransferRemainderException.js +4 -5
  36. package/src/exception/TransferToSelfException.js +4 -5
  37. package/src/exception/TransferUnbalancedException.js +4 -5
  38. package/src/exception/UnauthenticatedException.js +4 -5
  39. package/src/{libraries/ApolloLink/AuthLink.js → exception/WalletCredentialException.js} +12 -40
  40. package/src/exception/WalletShadowException.js +4 -5
  41. package/src/exception/WrongTokenTypeException.js +4 -5
  42. package/src/exception/index.js +26 -26
  43. package/src/index.js +8 -10
  44. package/src/instance/Rules/Callback.js +91 -93
  45. package/src/instance/Rules/Condition.js +21 -23
  46. package/src/instance/Rules/Meta.js +13 -14
  47. package/src/instance/Rules/Rule.js +39 -43
  48. package/src/instance/Rules/exception/RuleArgumentException.js +4 -4
  49. package/src/libraries/CheckMolecule.js +253 -232
  50. package/src/libraries/Decimal.js +13 -17
  51. package/src/libraries/Dot.js +74 -48
  52. package/src/libraries/Hex.js +49 -54
  53. package/src/libraries/array.js +50 -41
  54. package/src/libraries/crypto.js +20 -27
  55. package/src/libraries/strings.js +58 -91
  56. package/src/libraries/urql/UrqlClientWrapper.js +166 -0
  57. package/src/mutation/Mutation.js +44 -25
  58. package/src/mutation/MutationActiveSession.js +12 -12
  59. package/src/mutation/MutationClaimShadowWallet.js +15 -17
  60. package/src/mutation/MutationCreateIdentifier.js +11 -12
  61. package/src/mutation/MutationCreateMeta.js +11 -12
  62. package/src/mutation/MutationCreateRule.js +11 -12
  63. package/src/mutation/MutationCreateToken.js +18 -13
  64. package/src/mutation/MutationCreateWallet.js +9 -11
  65. package/src/mutation/MutationDepositBufferToken.js +7 -9
  66. package/src/mutation/MutationLinkIdentifier.js +12 -14
  67. package/src/mutation/MutationProposeMolecule.js +24 -25
  68. package/src/mutation/MutationRequestAuthorization.js +9 -10
  69. package/src/mutation/MutationRequestAuthorizationGuest.js +12 -15
  70. package/src/mutation/MutationRequestTokens.js +11 -14
  71. package/src/mutation/MutationTransferTokens.js +11 -14
  72. package/src/mutation/MutationWithdrawBufferToken.js +7 -10
  73. package/src/query/Query.js +62 -36
  74. package/src/query/QueryActiveSession.js +11 -13
  75. package/src/query/QueryAtom.js +75 -76
  76. package/src/query/QueryBalance.js +11 -12
  77. package/src/query/QueryBatch.js +17 -14
  78. package/src/query/QueryBatchHistory.js +16 -13
  79. package/src/query/QueryContinuId.js +13 -10
  80. package/src/query/QueryMetaType.js +45 -57
  81. package/src/query/QueryMetaTypeViaAtom.js +49 -57
  82. package/src/query/QueryPolicy.js +11 -12
  83. package/src/query/QueryToken.js +11 -13
  84. package/src/query/QueryUserActivity.js +11 -13
  85. package/src/query/QueryWalletBundle.js +15 -47
  86. package/src/query/QueryWalletList.js +15 -16
  87. package/src/response/Response.js +29 -34
  88. package/src/response/ResponseActiveSession.js +6 -6
  89. package/src/response/ResponseAtom.js +29 -30
  90. package/src/response/ResponseAuthorizationGuest.js +17 -18
  91. package/src/response/ResponseBalance.js +12 -13
  92. package/src/response/ResponseClaimShadowWallet.js +1 -1
  93. package/src/response/ResponseContinuId.js +21 -22
  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 +9 -10
  100. package/src/response/ResponseMetaBatch.js +6 -8
  101. package/src/response/ResponseMetaType.js +19 -20
  102. package/src/response/ResponseMetaTypeViaAtom.js +19 -19
  103. package/src/response/ResponsePolicy.js +14 -15
  104. package/src/response/ResponseProposeMolecule.js +27 -30
  105. package/src/response/ResponseQueryActiveSession.js +20 -23
  106. package/src/response/ResponseQueryUserActivity.js +11 -12
  107. package/src/response/ResponseRequestAuthorization.js +11 -16
  108. package/src/response/ResponseRequestAuthorizationGuest.js +18 -21
  109. package/src/response/ResponseRequestTokens.js +1 -1
  110. package/src/response/ResponseTransferTokens.js +8 -9
  111. package/src/response/ResponseWalletBundle.js +16 -17
  112. package/src/response/ResponseWalletList.js +44 -47
  113. package/src/subscribe/ActiveSessionSubscribe.js +5 -6
  114. package/src/subscribe/ActiveWalletSubscribe.js +5 -6
  115. package/src/subscribe/CreateMoleculeSubscribe.js +5 -5
  116. package/src/subscribe/Subscribe.js +26 -26
  117. package/src/subscribe/WalletStatusSubscribe.js +5 -6
  118. package/src/versions/HashAtom.js +78 -0
  119. package/src/versions/Version4.js +34 -0
  120. package/src/versions/index.js +5 -0
  121. package/dist/client.umd.js +0 -453
  122. package/src/httpClient/ApolloClient.js +0 -245
  123. package/src/libraries/ApolloLink/CipherLink.js +0 -117
  124. package/src/libraries/ApolloLink/Client.js +0 -231
  125. package/src/libraries/ApolloLink/PusherLink.js +0 -234
  126. package/src/libraries/ApolloLink/handler.js +0 -106
  127. package/src/libraries/Base58.js +0 -71
  128. package/src/libraries/Base64.js +0 -40
  129. package/src/libraries/BaseX.js +0 -91
  130. package/src/libraries/Soda.js +0 -93
  131. package/src/query/QueryMetaInstance.js +0 -99
  132. package/src/test/Test.js +0 -670
  133. package/src/test/TestTokenUnit.js +0 -340
@@ -45,90 +45,92 @@ 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'
49
+ import Decimal from './libraries/Decimal'
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 ApolloClient from './httpClient/ApolloClient';
82
- import CreateMoleculeSubscribe from './subscribe/CreateMoleculeSubscribe';
83
- import WalletStatusSubscribe from './subscribe/WalletStatusSubscribe';
84
- import ActiveWalletSubscribe from './subscribe/ActiveWalletSubscribe';
85
- import ActiveSessionSubscribe from './subscribe/ActiveSessionSubscribe';
86
- import MutationActiveSession from './mutation/MutationActiveSession';
87
- import QueryActiveSession from './query/QueryActiveSession';
88
- import QueryUserActivity from './query/QueryUserActivity';
89
- import QueryToken from './query/QueryToken';
90
- import BatchIdException from './exception/BatchIdException';
91
- import AuthorizationRejectedException from './exception/AuthorizationRejectedException';
92
- import QueryAtom from './query/QueryAtom';
93
- import QueryPolicy from './query/QueryPolicy';
94
- import QueryMetaTypeViaAtom from './query/QueryMetaTypeViaAtom';
95
- import MutationCreateRule from './mutation/MutationCreateRule';
96
- import MutationDepositBufferToken from './mutation/MutationDepositBufferToken';
97
- import MutationWithdrawBufferToken from './mutation/MutationWithdrawBufferToken';
98
-
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'
97
+ import {
98
+ getFingerprint,
99
+ getFingerprintData
100
+ } from '@thumbmarkjs/thumbmarkjs'
101
+ import UrqlClientWrapper from "./libraries/urql/UrqlClientWrapper";
99
102
 
100
103
  /**
101
104
  * Base client class providing a powerful but user-friendly wrapper
102
105
  * around complex Knish.IO ledger transactions.
103
106
  */
104
107
  export default class KnishIOClient {
105
-
106
108
  /**
107
109
  * Class constructor
108
110
  *
109
111
  * @param {string} uri
110
112
  * @param {string|null} cellSlug
111
113
  * @param {object|null} socket
112
- * @param {ApolloClient|null} client
114
+ * @param {UrqlClientWrapper|null} client
113
115
  * @param {number} serverSdkVersion
114
116
  * @param {boolean} logging
115
117
  */
116
- constructor ( {
118
+ constructor ({
117
119
  uri,
118
120
  cellSlug = null,
119
121
  client = null,
120
122
  socket = null,
121
123
  serverSdkVersion = 3,
122
124
  logging = false
123
- } ) {
124
- this.initialize( {
125
+ }) {
126
+ this.initialize({
125
127
  uri,
126
128
  cellSlug,
127
129
  socket,
128
130
  client,
129
131
  serverSdkVersion,
130
132
  logging
131
- } );
133
+ })
132
134
  }
133
135
 
134
136
  /**
@@ -137,39 +139,39 @@ export default class KnishIOClient {
137
139
  * @param {string|[]} uri
138
140
  * @param {string|null} cellSlug
139
141
  * @param {object|null} socket
140
- * @param {ApolloClient|null} client
142
+ * @param {UrqlClientWrapper|null} client
141
143
  * @param {number} serverSdkVersion
142
144
  * @param {boolean} logging
143
145
  */
144
- initialize ( {
146
+ initialize ({
145
147
  uri,
146
148
  cellSlug = null,
147
149
  socket = null,
148
150
  client = null,
149
151
  serverSdkVersion = 3,
150
152
  logging = false
151
- } ) {
153
+ }) {
154
+ this.reset()
152
155
 
153
- this.$__logging = logging;
154
- this.$__uris = typeof uri === 'object' ? uri : [ uri ];
155
- this.$__authTokenObjects = {};
156
- this.$__authInProcess = false;
156
+ this.$__logging = logging
157
+ this.$__authTokenObjects = {}
158
+ this.$__authInProcess = false
159
+ this.abortControllers = new Map()
157
160
 
158
- if ( cellSlug ) {
159
- this.setCellSlug( cellSlug );
160
- }
161
+ this.setUri(uri)
161
162
 
162
- for ( let uriKey in this.$__uris ) {
163
- let url = this.$__uris [ uriKey ];
164
- this.$__authTokenObjects[ url ] = null;
163
+ if (cellSlug) {
164
+ this.setCellSlug(cellSlug)
165
165
  }
166
166
 
167
- if ( this.$__logging ) {
168
- console.info( `KnishIOClient::initialize() - Initializing new Knish.IO client session for SDK version ${ serverSdkVersion }...` );
167
+ for (const uriKey in this.$__uris) {
168
+ const url = this.$__uris[uriKey]
169
+ this.$__authTokenObjects[url] = null
169
170
  }
170
171
 
171
- this.reset();
172
- this.$__client = client || new ApolloClient( {
172
+ this.log('info', `KnishIOClient::initialize() - Initializing new Knish.IO client session for SDK version ${ serverSdkVersion }...`)
173
+
174
+ this.$__client = client || new UrqlClientWrapper({
173
175
  socket: {
174
176
  ...{
175
177
  socketUri: null,
@@ -178,91 +180,93 @@ export default class KnishIOClient {
178
180
  ...socket || {}
179
181
  },
180
182
  serverUri: this.getRandomUri()
181
- } );
183
+ })
182
184
 
183
- this.$__serverSdkVersion = serverSdkVersion;
185
+ this.$__serverSdkVersion = serverSdkVersion
184
186
  }
185
187
 
186
-
187
188
  /**
188
189
  * Get random uri from specified this.$__uris
189
190
  *
190
191
  * @return {string}
191
192
  */
192
193
  getRandomUri () {
193
- let rand = Math.floor( Math.random() * ( this.$__uris.length ) );
194
- return this.$__uris[ rand ];
194
+ const rand = Math.floor(Math.random() * (this.$__uris.length))
195
+ return this.$__uris[rand]
195
196
  }
196
197
 
197
-
198
198
  /**
199
199
  *
200
200
  * @param encrypt
201
201
  * @return {boolean}
202
202
  */
203
- switchEncryption ( encrypt ) {
204
- if ( this.$__encrypt === encrypt ) {
205
- return false;
206
- }
207
- if ( this.$__logging ) {
208
- console.info( `KnishIOClient::switchEncryption() - Forcing encryption ${ encrypt ? 'on' : 'off' } to match node...` );
203
+ switchEncryption (encrypt) {
204
+ if (this.$__encrypt === encrypt) {
205
+ return false
209
206
  }
207
+ this.log('info', `KnishIOClient::switchEncryption() - Forcing encryption ${ encrypt ? 'on' : 'off' } to match node...`)
210
208
 
211
209
  // Set encryption
212
- this.$__encrypt = encrypt;
213
- this.$__client.setEncryption( encrypt );
214
- return true;
210
+ this.$__encrypt = encrypt
211
+ this.$__client.setEncryption(encrypt)
212
+ return true
215
213
  }
216
214
 
217
215
  /**
218
216
  * De-initializes the Knish.IO client session so that a new session can replace it
219
217
  */
220
218
  deinitialize () {
221
- if ( this.$__logging ) {
222
- console.info( 'KnishIOClient::deinitialize() - Clearing the Knish.IO client session...' );
223
- }
224
- this.reset();
219
+ this.log('info', 'KnishIOClient::deinitialize() - Clearing the Knish.IO client session...')
220
+ this.reset()
225
221
  }
226
222
 
227
223
  /**
228
224
  * Subscribes the client to the node's broadcast socket
229
225
  *
230
- * @return {ApolloClient}
226
+ * @return {UrqlClientWrapper}
231
227
  */
232
228
  subscribe () {
233
- if ( !this.client().getSocketUri() ) {
234
- throw new CodeException( 'KnishIOClient::subscribe() - Socket client not initialized!' );
229
+ if (!this.client().getSocketUri()) {
230
+ throw new CodeException('KnishIOClient::subscribe() - Socket client not initialized!')
235
231
  }
236
- return this.client();
232
+ return this.client()
237
233
  }
238
234
 
239
-
240
235
  /**
241
236
  * Gets the client's SDK version
242
237
  *
243
238
  * @return {number}
244
239
  */
245
240
  getServerSdkVersion () {
246
- return this.$__serverSdkVersion;
241
+ return this.$__serverSdkVersion
247
242
  }
248
243
 
249
-
250
244
  /**
251
245
  * Reset common properties
252
246
  */
253
247
  reset () {
254
- this.$__secret = '';
255
- this.$__bundle = '';
256
- this.remainderWallet = null;
248
+ this.$__secret = ''
249
+ this.$__bundle = ''
250
+ this.remainderWallet = null
257
251
  }
258
252
 
259
253
  /**
260
254
  * Returns the currently defined Cell identifier for this session
261
255
  *
256
+ * @deprecated Please use getCellSlug() instead
262
257
  * @return {string|null}
263
258
  */
264
259
  cellSlug () {
265
- return this.$__cellSlug || null;
260
+ return this.getCellSlug()
261
+ }
262
+
263
+ /**
264
+ * Returns the currently defined Cell identifier for this session
265
+ *
266
+ * @return {string|null}
267
+ */
268
+ getCellSlug () {
269
+ return this.$__cellSlug || null
266
270
  }
267
271
 
268
272
  /**
@@ -270,8 +274,12 @@ export default class KnishIOClient {
270
274
  *
271
275
  * @param cellSlug
272
276
  */
273
- setCellSlug ( cellSlug ) {
274
- this.$__cellSlug = cellSlug;
277
+ setCellSlug (cellSlug) {
278
+ this.$__cellSlug = cellSlug
279
+ }
280
+
281
+ setUri (uri) {
282
+ this.$__uris = typeof uri === 'object' ? uri : [uri]
275
283
  }
276
284
 
277
285
  /**
@@ -279,39 +287,48 @@ export default class KnishIOClient {
279
287
  *
280
288
  * @return {string}
281
289
  */
290
+ getUri () {
291
+ return this.$__client.getUri()
292
+ }
293
+
294
+ /**
295
+ * Retrieves the endpoint URI for this session
296
+ *
297
+ * @deprecated Please use getUri() instead
298
+ * @returns {string}
299
+ */
282
300
  uri () {
283
- return this.$__client.getUri();
301
+ return this.getUri()
284
302
  }
285
303
 
286
304
  /**
287
- * Returns the Apollo client class session
305
+ * Returns the GraphQL client class session
288
306
  *
289
- * @return {ApolloClient}
307
+ * @return {UrqlClientWrapper}
290
308
  */
291
309
  client () {
292
- if ( !this.$__authInProcess ) {
293
- let randomUri = this.getRandomUri();
294
- this.$__client.setUri( randomUri );
310
+ if (!this.$__authInProcess) {
311
+ const randomUri = this.getRandomUri()
312
+ this.$__client.setUri(randomUri)
295
313
 
296
314
  // Try to get stored auth token object
297
- let authTokenObject = this.$__authTokenObjects[ randomUri ];
315
+ const authTokenObject = this.$__authTokenObjects[randomUri]
298
316
 
299
317
  // Not authorized - try to do it
300
- if ( !authTokenObject ) {
301
- this.requestAuthToken( {
318
+ if (!authTokenObject) {
319
+ this.requestAuthToken({
302
320
  secret: this.$__secret,
303
321
  cellSlug: this.$__cellSlug,
304
322
  encrypt: this.$__encrypt
305
- } ).then( () => {
323
+ }).then(() => {
306
324
  // Success
307
- } );
308
- }
309
- // Use stored authorization data
310
- else {
311
- this.$__client.setAuthData( authTokenObject.getAuthData() );
325
+ })
326
+ } else {
327
+ // Use stored authorization data
328
+ this.$__client.setAuthData(authTokenObject.getAuthData())
312
329
  }
313
330
  }
314
- return this.$__client;
331
+ return this.$__client
315
332
  }
316
333
 
317
334
  /**
@@ -320,20 +337,29 @@ export default class KnishIOClient {
320
337
  * @return {boolean}
321
338
  */
322
339
  hasSecret () {
323
- return !!this.$__secret;
340
+ return !!this.$__secret
324
341
  }
325
342
 
326
-
327
343
  /**
328
344
  * Set the client's secret
329
345
  *
330
346
  * @param secret
331
347
  */
332
- setSecret ( secret ) {
333
- this.$__secret = secret;
334
- this.$__bundle = generateBundleHash( secret );
348
+ setSecret (secret) {
349
+ this.$__secret = secret
350
+ this.$__bundle = this.hashSecret(secret, 'setSecret')
335
351
  }
336
352
 
353
+ /**
354
+ * Hashes the user secret to produce a bundle hash
355
+ * @param {string} secret
356
+ * @param {string|null} source
357
+ * @returns {string}
358
+ */
359
+ hashSecret (secret, source = null) {
360
+ this.log('info', `KnishIOClient::hashSecret(${ source ? `source: ${ source }` : '' }) - Computing wallet bundle from secret...`)
361
+ return generateBundleHash(secret)
362
+ }
337
363
 
338
364
  /**
339
365
  * Retrieves the stored secret for this session
@@ -341,10 +367,10 @@ export default class KnishIOClient {
341
367
  * @return {string}
342
368
  */
343
369
  getSecret () {
344
- if ( !this.hasSecret() ) {
345
- throw new UnauthenticatedException( 'KnishIOClient::getSecret() - Unable to find a stored secret! Have you set a secret?' );
370
+ if (!this.hasSecret()) {
371
+ throw new UnauthenticatedException('KnishIOClient::getSecret() - Unable to find a stored secret! Have you set a secret?')
346
372
  }
347
- return this.$__secret;
373
+ return this.$__secret
348
374
  }
349
375
 
350
376
  /**
@@ -353,20 +379,32 @@ export default class KnishIOClient {
353
379
  * @return {boolean}
354
380
  */
355
381
  hasBundle () {
356
- return !!this.$__bundle;
382
+ return !!this.$__bundle
357
383
  }
358
384
 
359
-
360
385
  /**
361
386
  * Returns the bundle hash for this session
362
387
  *
363
388
  * @return {string}
364
389
  */
365
390
  getBundle () {
366
- if ( !this.hasBundle() ) {
367
- throw new UnauthenticatedException( 'KnishIOClient::getBundle() - Unable to find a stored bundle! Have you set a secret?' );
391
+ if (!this.hasBundle()) {
392
+ throw new UnauthenticatedException('KnishIOClient::getBundle() - Unable to find a stored bundle! Have you set a secret?')
368
393
  }
369
- return this.$__bundle;
394
+ return this.$__bundle
395
+ }
396
+
397
+ /**
398
+ * Retrieves the device fingerprint.
399
+ *
400
+ * @returns {Promise<string>} A promise that resolves to the device fingerprint as a string.
401
+ */
402
+ getFingerprint () {
403
+ return getFingerprint()
404
+ }
405
+
406
+ getFingerprintData () {
407
+ return getFingerprintData()
370
408
  }
371
409
 
372
410
  /**
@@ -375,23 +413,23 @@ export default class KnishIOClient {
375
413
  * @return {Promise<*|Wallet|null>}
376
414
  */
377
415
  async getSourceWallet () {
378
- let sourceWallet = ( await this.queryContinuId( {
416
+ let sourceWallet = (await this.queryContinuId({
379
417
  bundle: this.getBundle()
380
- } ) ).payload();
418
+ })).payload()
381
419
 
382
- if ( !sourceWallet ) {
383
- sourceWallet = new Wallet( {
420
+ if (!sourceWallet) {
421
+ sourceWallet = new Wallet({
384
422
  secret: this.getSecret()
385
- } );
423
+ })
386
424
  } else {
387
- sourceWallet.key = Wallet.generateKey( {
425
+ sourceWallet.key = Wallet.generateKey({
388
426
  secret: this.getSecret(),
389
427
  token: sourceWallet.token,
390
428
  position: sourceWallet.position
391
- } );
429
+ })
392
430
  }
393
431
 
394
- return sourceWallet;
432
+ return sourceWallet
395
433
  }
396
434
 
397
435
  /**
@@ -400,78 +438,80 @@ export default class KnishIOClient {
400
438
  * @return {null}
401
439
  */
402
440
  getRemainderWallet () {
403
- return this.remainderWallet;
441
+ return this.remainderWallet
404
442
  }
405
443
 
406
444
  /**
407
445
  * Instantiates a new Molecule and prepares this client session to operate on it
408
446
  *
409
447
  * @param secret
448
+ * @param bundle
410
449
  * @param sourceWallet
411
450
  * @param remainderWallet
412
451
  * @return {Promise<Molecule>}
413
452
  */
414
- async createMolecule ( {
453
+ async createMolecule ({
415
454
  secret = null,
455
+ bundle = null,
416
456
  sourceWallet = null,
417
457
  remainderWallet = null
418
- } ) {
458
+ }) {
459
+ this.log('info', 'KnishIOClient::createMolecule() - Creating a new molecule...')
419
460
 
420
- if ( this.$__logging ) {
421
- console.info( 'KnishIOClient::createMolecule() - Creating a new molecule...' );
422
- }
423
-
424
- secret = secret || this.getSecret();
461
+ secret = secret || this.getSecret()
462
+ bundle = bundle || this.getBundle()
425
463
 
426
464
  // Sets the source wallet as the last remainder wallet (to maintain ContinuID)
427
- if ( !sourceWallet &&
465
+ if (!sourceWallet &&
428
466
  this.lastMoleculeQuery &&
429
467
  this.getRemainderWallet().token === 'USER' &&
430
468
  this.lastMoleculeQuery.response() &&
431
469
  this.lastMoleculeQuery.response().success()
432
470
  ) {
433
- sourceWallet = this.getRemainderWallet();
471
+ sourceWallet = this.getRemainderWallet()
434
472
  }
435
473
 
436
474
  // Unable to use last remainder wallet; Figure out what wallet to use:
437
- if ( sourceWallet === null ) {
438
- sourceWallet = await this.getSourceWallet();
475
+ if (sourceWallet === null) {
476
+ sourceWallet = await this.getSourceWallet()
439
477
  }
440
478
 
441
479
  // Set the remainder wallet for the next transaction
442
- this.remainderWallet = remainderWallet || Wallet.create( {
443
- secretOrBundle: secret,
480
+ this.remainderWallet = remainderWallet || Wallet.create({
481
+ secret,
482
+ bundle,
444
483
  token: 'USER',
445
484
  batchId: sourceWallet.batchId,
446
485
  characters: sourceWallet.characters
447
- } );
486
+ })
448
487
 
449
- return new Molecule( {
488
+ return new Molecule({
450
489
  secret,
451
490
  sourceWallet,
452
491
  remainderWallet: this.getRemainderWallet(),
453
- cellSlug: this.cellSlug()
454
- } );
492
+ cellSlug: this.getCellSlug(),
493
+ version: this.getServerSdkVersion()
494
+ })
455
495
  }
456
496
 
457
497
  /**
458
498
  * Builds a new instance of the provided Query class
459
499
  *
460
- * @param queryClass
500
+ * @param QueryClass
461
501
  * @return {*}
462
502
  */
463
- createQuery ( queryClass ) {
464
- return new queryClass( this.client() );
503
+ createQuery (QueryClass) {
504
+ return new QueryClass(this.client(), this)
465
505
  }
466
506
 
467
507
  /**
468
508
  * Builds a new instance of the provided Subscription class
469
509
  *
470
- * @param subscribeClass
510
+ * @param SubscribeClass
471
511
  * @return {*}
472
512
  */
473
- createSubscribe ( subscribeClass ) {
474
- return new subscribeClass( this.subscribe() );
513
+ createSubscribe (SubscribeClass) {
514
+ return new SubscribeClass(this.subscribe())
475
515
  }
476
516
 
477
517
  /**
@@ -480,53 +520,93 @@ export default class KnishIOClient {
480
520
  * @param mutationClass
481
521
  * @param molecule
482
522
  */
483
- async createMoleculeMutation ( {
523
+ async createMoleculeMutation ({
484
524
  mutationClass,
485
525
  molecule = null
486
- } ) {
487
-
488
- if ( this.$__logging ) {
489
- console.info( `KnishIOClient::createMoleculeQuery() - Creating a new ${ mutationClass.name } query...` );
490
- }
526
+ }) {
527
+ this.log('info', `KnishIOClient::createMoleculeQuery() - Creating a new ${ mutationClass.name } query...`)
491
528
 
492
529
  // If you don't supply the molecule, we'll generate one for you
493
- let _molecule = molecule || await this.createMolecule( {} );
530
+ const _molecule = molecule || await this.createMolecule({})
494
531
 
495
- const mutation = new mutationClass( this.client(), _molecule );
532
+ const mutation = new mutationClass(this.client(), this, _molecule)
496
533
 
497
- if ( !( mutation instanceof MutationProposeMolecule ) ) {
498
- throw new CodeException( `${ this.constructor.name }::createMoleculeMutation() - This method only accepts MutationProposeMolecule!` );
534
+ if (!(mutation instanceof MutationProposeMolecule)) {
535
+ throw new CodeException(`${ this.constructor.name }::createMoleculeMutation() - This method only accepts MutationProposeMolecule!`)
499
536
  }
500
537
 
501
- this.lastMoleculeQuery = mutation;
538
+ this.lastMoleculeQuery = mutation
502
539
 
503
- return mutation;
540
+ return mutation
504
541
  }
505
542
 
506
-
507
543
  /**
508
544
  *
509
545
  * @param query
510
546
  * @param variables
511
547
  * @returns {Promise<*>}
512
548
  */
513
- async executeQuery ( query, variables = null ) {
514
- // console.info( `KnishIOClient::executeQuery() - Check token expiration... ${ this.$__authToken.$__expiresAt * 1000 } == ${ Date.now() } ` );
515
- if ( this.$__authToken && this.$__authToken.isExpired() ) {
516
- console.info( 'KnishIOClient::executeQuery() - Access token is expired. Getting new one...' );
517
-
518
- await this.requestAuthToken( {
549
+ async executeQuery (query, variables = null) {
550
+ // Check and refresh authorization token if needed
551
+ if (this.$__authToken && this.$__authToken.isExpired()) {
552
+ this.log('info', 'KnishIOClient::executeQuery() - Access token is expired. Getting new one...')
553
+ await this.requestAuthToken({
519
554
  secret: this.$__secret,
520
555
  cellSlug: this.$__cellSlug,
521
556
  encrypt: this.$__encrypt
522
- } );
557
+ })
558
+ }
559
+
560
+ // Create a new AbortController for this query
561
+ const abortController = new AbortController()
562
+ const queryKey = JSON.stringify({
563
+ query: query.$__query,
564
+ variables
565
+ })
566
+ this.abortControllers.set(queryKey, abortController)
567
+
568
+ try {
569
+ // Use the existing query execution method, but add the abort signal
570
+ const result = await query.execute({
571
+ variables,
572
+ context: {
573
+ fetchOptions: {
574
+ signal: abortController.signal
575
+ }
576
+ }
577
+ })
578
+
579
+ // Remove the AbortController after the query is complete
580
+ this.abortControllers.delete(queryKey)
581
+
582
+ return result
583
+ } catch (error) {
584
+ if (error.name === 'AbortError') {
585
+ this.log('warn', 'Query was cancelled')
586
+ } else {
587
+ throw error
588
+ }
523
589
  }
590
+ }
524
591
 
525
- return query.execute( {
592
+ cancelQuery (query, variables = null) {
593
+ const queryKey = JSON.stringify({
594
+ query: query.$__query,
526
595
  variables
527
- } );
596
+ })
597
+ const controller = this.abortControllers.get(queryKey)
598
+ if (controller) {
599
+ controller.abort()
600
+ this.abortControllers.delete(queryKey)
601
+ }
528
602
  }
529
603
 
604
+ cancelAllQueries () {
605
+ for (const controller of this.abortControllers.values()) {
606
+ controller.abort()
607
+ }
608
+ this.abortControllers.clear()
609
+ }
530
610
 
531
611
  /**
532
612
  * Retrieves the balance wallet for a specified Knish.IO identity and token slug
@@ -536,23 +616,22 @@ export default class KnishIOClient {
536
616
  * @param {string} type
537
617
  * @returns {Promise<*>}
538
618
  */
539
- async queryBalance ( {
619
+ async queryBalance ({
540
620
  token,
541
621
  bundle = null,
542
622
  type = 'regular'
543
- } ) {
544
-
623
+ }) {
545
624
  /**
546
625
  * @type {QueryBalance}
547
626
  */
548
- const query = this.createQuery( QueryBalance );
627
+ const query = this.createQuery(QueryBalance)
549
628
 
550
629
  // Execute query with either the provided bundle hash or the active client's bundle
551
- return this.executeQuery( query, {
630
+ return this.executeQuery(query, {
552
631
  bundleHash: bundle || this.getBundle(),
553
632
  token,
554
633
  type
555
- } );
634
+ })
556
635
  }
557
636
 
558
637
  /**
@@ -562,27 +641,27 @@ export default class KnishIOClient {
562
641
  * @param {string} type
563
642
  * @returns {Promise<{address}|{position}|*>}
564
643
  */
565
- async querySourceWallet ( {
644
+ async querySourceWallet ({
566
645
  token,
567
646
  amount,
568
647
  type = 'regular'
569
- } ) {
570
- let sourceWallet = ( await this.queryBalance( {
648
+ }) {
649
+ const sourceWallet = (await this.queryBalance({
571
650
  token,
572
651
  type
573
- } ) ).payload();
652
+ })).payload()
574
653
 
575
654
  // Do you have enough tokens?
576
- if ( sourceWallet === null || Decimal.cmp( sourceWallet.balance, amount ) < 0 ) {
577
- throw new TransferBalanceException();
655
+ if (sourceWallet === null || Decimal.cmp(sourceWallet.balance, amount) < 0) {
656
+ throw new TransferBalanceException()
578
657
  }
579
658
 
580
659
  // Check shadow wallet
581
- if ( !sourceWallet.position || !sourceWallet.address ) {
582
- throw new TransferBalanceException( 'Source wallet can not be a shadow wallet.' );
660
+ if (!sourceWallet.position || !sourceWallet.address) {
661
+ throw new TransferBalanceException('Source wallet can not be a shadow wallet.')
583
662
  }
584
663
 
585
- return sourceWallet;
664
+ return sourceWallet
586
665
  }
587
666
 
588
667
  /**
@@ -590,18 +669,18 @@ export default class KnishIOClient {
590
669
  * @param {function} closure
591
670
  * @return {Promise<string>}
592
671
  */
593
- async subscribeCreateMolecule ( {
672
+ async subscribeCreateMolecule ({
594
673
  bundle,
595
674
  closure
596
- } ) {
597
- const subscribe = this.createSubscribe( CreateMoleculeSubscribe );
675
+ }) {
676
+ const subscribe = this.createSubscribe(CreateMoleculeSubscribe)
598
677
 
599
- return await subscribe.execute( {
678
+ return await subscribe.execute({
600
679
  variables: {
601
680
  bundle: bundle || this.getBundle()
602
681
  },
603
682
  closure
604
- } );
683
+ })
605
684
  }
606
685
 
607
686
  /**
@@ -612,25 +691,24 @@ export default class KnishIOClient {
612
691
  * @param {function} closure
613
692
  * @return {string}
614
693
  */
615
- subscribeWalletStatus ( {
694
+ subscribeWalletStatus ({
616
695
  bundle,
617
696
  token,
618
697
  closure
619
- } ) {
620
-
621
- if ( !token ) {
622
- throw new CodeException( `${ this.constructor.name }::subscribeWalletStatus() - Token parameter is required!` );
698
+ }) {
699
+ if (!token) {
700
+ throw new CodeException(`${ this.constructor.name }::subscribeWalletStatus() - Token parameter is required!`)
623
701
  }
624
702
 
625
- const subscribe = this.createSubscribe( WalletStatusSubscribe );
703
+ const subscribe = this.createSubscribe(WalletStatusSubscribe)
626
704
 
627
- return subscribe.execute( {
705
+ return subscribe.execute({
628
706
  variables: {
629
707
  bundle: bundle || this.getBundle(),
630
708
  token
631
709
  },
632
710
  closure
633
- } );
711
+ })
634
712
  }
635
713
 
636
714
  /**
@@ -640,18 +718,18 @@ export default class KnishIOClient {
640
718
  * @param {function} closure
641
719
  * @return {string}
642
720
  */
643
- subscribeActiveWallet ( {
721
+ subscribeActiveWallet ({
644
722
  bundle,
645
723
  closure
646
- } ) {
647
- const subscribe = this.createSubscribe( ActiveWalletSubscribe );
724
+ }) {
725
+ const subscribe = this.createSubscribe(ActiveWalletSubscribe)
648
726
 
649
- return subscribe.execute( {
727
+ return subscribe.execute({
650
728
  variables: {
651
729
  bundle: bundle || this.getBundle()
652
730
  },
653
731
  closure
654
- } );
732
+ })
655
733
  }
656
734
 
657
735
  /**
@@ -662,20 +740,20 @@ export default class KnishIOClient {
662
740
  * @param {function} closure
663
741
  * @return {*}
664
742
  */
665
- subscribeActiveSession ( {
743
+ subscribeActiveSession ({
666
744
  metaType,
667
745
  metaId,
668
746
  closure
669
- } ) {
670
- const subscribe = this.createSubscribe( ActiveSessionSubscribe );
747
+ }) {
748
+ const subscribe = this.createSubscribe(ActiveSessionSubscribe)
671
749
 
672
- return subscribe.execute( {
750
+ return subscribe.execute({
673
751
  variables: {
674
752
  metaType,
675
753
  metaId
676
754
  },
677
755
  closure
678
- } );
756
+ })
679
757
  }
680
758
 
681
759
  /**
@@ -683,12 +761,12 @@ export default class KnishIOClient {
683
761
  *
684
762
  * @param {string} operationName
685
763
  */
686
- unsubscribe ( operationName ) {
687
- this.subscribe().unsubscribe( operationName );
764
+ unsubscribe (operationName) {
765
+ this.subscribe().unsubscribe(operationName)
688
766
  }
689
767
 
690
768
  unsubscribeAll () {
691
- this.subscribe().unsubscribeAll();
769
+ this.subscribe().unsubscribeAll()
692
770
  }
693
771
 
694
772
  /**
@@ -699,7 +777,6 @@ export default class KnishIOClient {
699
777
  * @param {string|array|null} key
700
778
  * @param {string|array|null} value
701
779
  * @param {boolean|null} latest
702
- * @param {boolean|null} latestMetas
703
780
  * @param {object|null} fields
704
781
  * @param {object|null} filter
705
782
  * @param {object|null} queryArgs
@@ -711,120 +788,67 @@ export default class KnishIOClient {
711
788
  * @param {array|null} atomValues
712
789
  * @return {Promise<ResponseMetaType>}
713
790
  */
714
- queryMeta ( {
791
+ queryMeta ({
715
792
  metaType,
716
793
  metaId = null,
717
794
  key = null,
718
795
  value = null,
719
- latest = null,
720
- latestMetas = null,
796
+ latest = true,
721
797
  fields = null,
722
798
  filter = null,
723
799
  queryArgs = null,
724
800
  count = null,
725
801
  countBy = null,
726
- throughAtom = false,
802
+ throughAtom = true,
727
803
  values = null,
728
804
  keys = null,
729
805
  atomValues = null
730
- } ) {
731
-
732
- if ( this.$__logging ) {
733
- console.info( `KnishIOClient::queryMeta() - Querying metaType: ${ metaType }, metaId: ${ metaId }...` );
734
- }
806
+ }) {
807
+ this.log('info', `KnishIOClient::queryMeta() - Querying metaType: ${ metaType }, metaId: ${ metaId }...`)
735
808
 
736
- let query;
737
- let variables;
809
+ let query
810
+ let variables
738
811
 
739
- if ( throughAtom ) {
812
+ if (throughAtom) {
740
813
  /**
741
814
  * @type {QueryMetaTypeViaAtom}
742
815
  */
743
- query = this.createQuery( QueryMetaTypeViaAtom );
744
- variables = QueryMetaTypeViaAtom.createVariables( {
816
+ query = this.createQuery(QueryMetaTypeViaAtom)
817
+ variables = QueryMetaTypeViaAtom.createVariables({
745
818
  metaType,
746
819
  metaId,
747
820
  key,
748
821
  value,
749
822
  latest,
750
- latestMetas,
751
823
  filter,
752
824
  queryArgs,
753
825
  countBy,
754
826
  values,
755
827
  keys,
756
828
  atomValues
757
- } );
829
+ })
758
830
  } else {
759
831
  /**
760
832
  * @type {QueryMetaType}
761
833
  */
762
- query = this.createQuery( QueryMetaType );
763
- variables = QueryMetaType.createVariables( {
834
+ query = this.createQuery(QueryMetaType)
835
+ variables = QueryMetaType.createVariables({
764
836
  metaType,
765
837
  metaId,
766
838
  key,
767
839
  value,
768
840
  latest,
769
- latestMetas,
770
841
  filter,
771
842
  queryArgs,
772
843
  count,
773
844
  countBy
774
- } );
845
+ })
775
846
  }
776
847
 
777
-
778
- return this.executeQuery( query, variables )
779
- .then( ( response ) => {
780
- return response.payload();
781
- } );
782
- }
783
-
784
-
785
- /**
786
- * Retrieves metadata for the given metaType and provided parameters
787
- *
788
- * @param {string|array|null} metaType
789
- * @param {string|array|null} metaId
790
- * @param {string|array|null} key
791
- * @param {string|array|null} value
792
- * @param {boolean|null} latest
793
- * @param {object|null} fields
794
- * @param {object|null} filter
795
- * @return {Promise<ResponseMetaType>}
796
- */
797
- queryMetaInstance ( {
798
- metaType,
799
- metaId = null,
800
- key = null,
801
- value = null,
802
- latest = null,
803
- filter = null,
804
- fields = null
805
- } ) {
806
-
807
- if ( this.$__logging ) {
808
- console.info( `KnishIOClient::queryMetaInstance() - Querying metaType: ${ metaType }, metaId: ${ metaId }...` );
809
- }
810
-
811
- /**
812
- * @type {QueryMetaType}
813
- */
814
- const query = this.createQuery( QueryMetaType );
815
- const variables = {
816
- metaType: metaType,
817
- metaIds: [ metaId ],
818
- keys: [ key ],
819
- values: [ value ],
820
- latest: latest,
821
- filter: filter
822
- };
823
-
824
- return this.executeQuery( query, variables )
825
- .then( ( response ) => {
826
- return response.data();
827
- } );
848
+ return this.executeQuery(query, variables)
849
+ .then((response) => {
850
+ return response.payload()
851
+ })
828
852
  }
829
853
 
830
854
  /**
@@ -833,19 +857,14 @@ export default class KnishIOClient {
833
857
  * @param batchId
834
858
  * @return {Promise<*>}
835
859
  */
836
- async queryBatch ( {
860
+ async queryBatch ({
837
861
  batchId
838
- } ) {
839
-
840
- if ( this.$__logging ) {
841
- console.info( `KnishIOClient::queryBatch() - Querying cascading meta instances for batchId: ${ batchId }...` );
842
- }
843
-
844
- const query = this.createQuery( QueryBatch );
845
-
846
- return await this.executeQuery( query, {
862
+ }) {
863
+ this.log('info', `KnishIOClient::queryBatch() - Querying cascading meta instances for batchId: ${ batchId }...`)
864
+ const query = this.createQuery(QueryBatch)
865
+ return await this.executeQuery(query, {
847
866
  batchId
848
- } );
867
+ })
849
868
  }
850
869
 
851
870
  /**
@@ -854,54 +873,54 @@ export default class KnishIOClient {
854
873
  * @param batchId
855
874
  * @return {Promise<*>}
856
875
  */
857
- async queryBatchHistory ( {
876
+ async queryBatchHistory ({
858
877
  batchId
859
- } ) {
860
-
861
- if ( this.$__logging ) {
862
- console.info( `KnishIOClient::queryBatchHistory() - Querying cascading meta instances for batchId: ${ batchId }...` );
863
- }
878
+ }) {
879
+ this.log('info', `KnishIOClient::queryBatchHistory() - Querying cascading meta instances for batchId: ${ batchId }...`)
864
880
 
865
- const query = this.createQuery( QueryBatchHistory );
881
+ const query = this.createQuery(QueryBatchHistory)
866
882
 
867
- return await this.executeQuery( query, {
883
+ return await this.executeQuery(query, {
868
884
  batchId
869
- } );
870
- }
871
-
872
- /**
873
- * Queries Knish.IO Atoms
874
- *
875
- * @param {string[]} molecularHashes
876
- * @param {string} molecularHash
877
- * @param {string[]} bundleHashes
878
- * @param {string} bundleHash
879
- * @param {string[]} positions
880
- * @param {string} position
881
- * @param {string[]} walletAddresses
882
- * @param {string} walletAddress
883
- * @param {string[]} isotopes
884
- * @param {string} isotope
885
- * @param {string[]} tokenSlugs
886
- * @param {string} tokenSlug
887
- * @param {string[]} cellSlugs
888
- * @param {string} cellSlug
889
- * @param {string[]} batchIds
890
- * @param {string} batchId
891
- * @param {string[]} values
892
- * @param {string|number} value
893
- * @param {string[]} metaTypes
894
- * @param {string} metaType
895
- * @param {string[]} metaIds
896
- * @param {string} metaId
897
- * @param {string[]} indexes
898
- * @param {number} index
899
- * @param {object[]} filter,
900
- * @param {boolean} latest
901
- * @param {object} queryArgs
902
- * @return {Promise<Response>}
903
- */
904
- async queryAtom ( {
885
+ })
886
+ }
887
+
888
+ /**
889
+ * Queries atom instances based on the provided parameters.
890
+ *
891
+ * @param {string[]} molecularHashes - Array of multiple molecular hashes.
892
+ * @param {string} molecularHash - Single molecular hash.
893
+ * @param {string[]} bundleHashes - Array of multiple bundle hashes.
894
+ * @param {string} bundleHash - Single bundle hash.
895
+ * @param {number[]} positions - Array of multiple positions.
896
+ * @param {number} position - Single position.
897
+ * @param {string[]} walletAddresses - Array of multiple wallet addresses.
898
+ * @param {string} walletAddress - Single wallet address.
899
+ * @param {string[]} isotopes - Array of multiple isotopes.
900
+ * @param {string} isotope - Single isotope.
901
+ * @param {string[]} tokenSlugs - Array of multiple token slugs.
902
+ * @param {string} tokenSlug - Single token slug.
903
+ * @param {string[]} cellSlugs - Array of multiple cell slugs.
904
+ * @param {string} cellSlug - Single cell slug.
905
+ * @param {string[]} batchIds - Array of multiple batch IDs.
906
+ * @param {string} batchId - Single batch ID.
907
+ * @param {any[]} values - Array of multiple values.
908
+ * @param {any} value - Single value.
909
+ * @param {string[]} metaTypes - Array of multiple meta types.
910
+ * @param {string} metaType - Single meta type.
911
+ * @param {string[]} metaIds - Array of multiple meta IDs.
912
+ * @param {string} metaId - Single meta ID.
913
+ * @param {string[]} indexes - Array of multiple atom indices.
914
+ * @param {string} index - Single atom index.
915
+ * @param {object} filter - The filter object.
916
+ * @param {boolean} latest - The latest flag.
917
+ * @param {object} [queryArgs] - The query arguments (limit, offset).
918
+ * @param {number} [queryArgs.limit=15] - The limit.
919
+ * @param {number} [queryArgs.offset=1] - The offset.
920
+ *
921
+ * @returns {Promise<ResponseAtom>} - A promise that resolves with the queried atom instances.
922
+ */
923
+ async queryAtom ({
905
924
  molecularHashes,
906
925
  molecularHash,
907
926
  bundleHashes,
@@ -932,17 +951,13 @@ export default class KnishIOClient {
932
951
  limit: 15,
933
952
  offset: 1
934
953
  }
935
- } ) {
936
-
937
- if ( this.$__logging ) {
938
- console.info( 'KnishIOClient::queryAtom() - Querying atom instances' );
939
- }
954
+ }) {
955
+ this.log('info', 'KnishIOClient::queryAtom() - Querying atom instances')
940
956
 
941
957
  /** @type QueryAtom */
942
- const query = this.createQuery( QueryAtom );
958
+ const query = this.createQuery(QueryAtom)
943
959
 
944
-
945
- return await this.executeQuery( query, QueryAtom.createVariables( {
960
+ return await this.executeQuery(query, QueryAtom.createVariables({
946
961
  molecularHashes,
947
962
  molecularHash,
948
963
  bundleHashes,
@@ -970,75 +985,74 @@ export default class KnishIOClient {
970
985
  filter,
971
986
  latest,
972
987
  queryArgs
973
- } ) );
988
+ }))
974
989
  }
975
990
 
976
991
  /**
977
992
  * Builds and executes a molecule to issue a new Wallet on the ledger
978
993
  *
979
- * @param {string} token
980
- * @return {Promise<Response>}
994
+ * @param {string} token - The token slug for the new wallet
995
+ * @returns {Promise<ResponseCreateWallet>} - A Promise that resolves with the result of the execution.
981
996
  */
982
- async createWallet ( {
997
+ async createWallet ({
983
998
  token
984
- } ) {
985
-
986
- const newWallet = new Wallet( {
999
+ }) {
1000
+ const newWallet = new Wallet({
987
1001
  secret: this.getSecret(),
988
1002
  token
989
- } );
1003
+ })
990
1004
 
991
1005
  /**
992
1006
  * @type {MutationCreateWallet}
993
1007
  */
994
- const query = await this.createMoleculeMutation( {
1008
+ const query = await this.createMoleculeMutation({
995
1009
  mutationClass: MutationCreateWallet
996
- } );
1010
+ })
997
1011
 
998
- query.fillMolecule( newWallet );
1012
+ query.fillMolecule(newWallet)
999
1013
 
1000
- return await this.executeQuery( query );
1014
+ return await this.executeQuery(query)
1001
1015
  }
1002
1016
 
1003
1017
  /**
1004
1018
  * Queries the ledger to retrieve a list of active sessions for the given MetaType
1005
1019
  *
1006
- * @param {string} bundleHash
1007
- * @param {string} metaType
1008
- * @param {string} metaId
1009
- * @return {Promise<*>}
1020
+ * @param {string} bundleHash - The hash of the session bundle.
1021
+ * @param {string} metaType - The type of metadata associated with the session.
1022
+ * @param {string} metaId - The ID of the metadata associated with the session.
1023
+ * @returns {Promise<ResponseQueryActiveSession>} - Returns a promise containing the result of the query.
1010
1024
  */
1011
- async queryActiveSession ( {
1025
+ async queryActiveSession ({
1012
1026
  bundleHash,
1013
1027
  metaType,
1014
1028
  metaId
1015
- } ) {
1016
-
1017
- const query = this.createQuery( QueryActiveSession );
1029
+ }) {
1030
+ const query = this.createQuery(QueryActiveSession)
1018
1031
 
1019
- return await this.executeQuery( query, {
1032
+ return await this.executeQuery(query, {
1020
1033
  bundleHash,
1021
1034
  metaType,
1022
1035
  metaId
1023
- } );
1036
+ })
1024
1037
  }
1025
1038
 
1026
-
1027
1039
  /**
1040
+ * Queries user activity based on the provided parameters.
1028
1041
  *
1029
- * @param {string} bundleHash
1030
- * @param {string} metaType
1031
- * @param {string} metaId
1032
- * @param {string} ipAddress
1033
- * @param {string} browser
1034
- * @param {string} osCpu
1035
- * @param {string} resolution
1036
- * @param {string} timeZone
1037
- * @param {Array} countBy
1038
- * @param {string} interval
1039
- * @return {Promise<*>}
1042
+ * @param {string} bundleHash - The bundle hash.
1043
+ * @param {string} metaType - The meta type.
1044
+ * @param {string} metaId - The meta ID.
1045
+ * @param {string} ipAddress - The IP address.
1046
+ * @param {string} browser - The browser.
1047
+ * @param {string} osCpu - The operating system and CPU.
1048
+ * @param {string} resolution - The screen resolution.
1049
+ * @param {string} timeZone - The time zone.
1050
+ * @param {string} countBy - The count by parameter.
1051
+ * @param {string} interval - The interval parameter.
1052
+ *
1053
+ * @returns {Promise<ResponseQueryUserActivity>} The result of the query.
1040
1054
  */
1041
- async queryUserActivity ( {
1055
+ async queryUserActivity ({
1042
1056
  bundleHash,
1043
1057
  metaType,
1044
1058
  metaId,
@@ -1049,10 +1063,10 @@ export default class KnishIOClient {
1049
1063
  timeZone,
1050
1064
  countBy,
1051
1065
  interval
1052
- } ) {
1053
- const query = this.createQuery( QueryUserActivity );
1066
+ }) {
1067
+ const query = this.createQuery(QueryUserActivity)
1054
1068
 
1055
- return await this.executeQuery( query, {
1069
+ return await this.executeQuery(query, {
1056
1070
  bundleHash,
1057
1071
  metaType,
1058
1072
  metaId,
@@ -1063,24 +1077,25 @@ export default class KnishIOClient {
1063
1077
  timeZone,
1064
1078
  countBy,
1065
1079
  interval
1066
- } );
1080
+ })
1067
1081
  }
1068
1082
 
1069
1083
  /**
1070
1084
  * Builds and executes a molecule to declare an active session for the given MetaType
1071
1085
  *
1072
- * @param {string} bundle
1073
- * @param {string} metaType
1074
- * @param {string} metaId
1075
- * @param {string} ipAddress
1076
- * @param {string} browser
1077
- * @param {string} osCpu
1078
- * @param {string} resolution
1079
- * @param {string} timeZone
1080
- * @param {object|array} json
1081
- * @return {Promise<void>}
1082
- */
1083
- async activeSession ( {
1086
+ * @param {Object} options - The options for activating a session.
1087
+ * @param {string} options.bundle - The bundle hash.
1088
+ * @param {string} options.metaType - The meta type.
1089
+ * @param {string} options.metaId - The meta ID.
1090
+ * @param {string} options.ipAddress - The client's IP address.
1091
+ * @param {string} options.browser - The client's browser.
1092
+ * @param {string} options.osCpu - The client's operating system and CPU.
1093
+ * @param {string} options.resolution - The client's screen resolution.
1094
+ * @param {string} options.timeZone - The client's time zone.
1095
+ * @param {Object} [options.json={}] - Additional JSON data.
1096
+ * @returns {Promise<ResponseActiveSession>} A promise that resolves with the result of the activation.
1097
+ */
1098
+ async activeSession ({
1084
1099
  bundle,
1085
1100
  metaType,
1086
1101
  metaId,
@@ -1090,10 +1105,10 @@ export default class KnishIOClient {
1090
1105
  resolution,
1091
1106
  timeZone,
1092
1107
  json = {}
1093
- } ) {
1094
- const query = this.createQuery( MutationActiveSession );
1108
+ }) {
1109
+ const query = this.createQuery(MutationActiveSession)
1095
1110
 
1096
- return await this.executeQuery( query, {
1111
+ return await this.executeQuery(query, {
1097
1112
  bundleHash: bundle,
1098
1113
  metaType,
1099
1114
  metaId,
@@ -1102,735 +1117,688 @@ export default class KnishIOClient {
1102
1117
  osCpu,
1103
1118
  resolution,
1104
1119
  timeZone,
1105
- json: JSON.stringify( json )
1106
- } );
1120
+ json: JSON.stringify(json)
1121
+ })
1107
1122
  }
1108
1123
 
1109
1124
  /**
1110
- * Builds and executes a molecule to issue a new token on the ledger
1125
+ * Creates a new token with the given parameters.
1111
1126
  *
1112
- * @param {string} token
1113
- * @param {number|null} amount
1114
- * @param {array|object} meta
1115
- * @param {string|null} batchId
1116
- * @param {array} units
1117
- * @return {Promise<ResponseCreateToken>}
1127
+ * @param {object} options - The options for creating the token.
1128
+ * @param {string} options.token - The token identifier.
1129
+ * @param {number} [options.amount] - The amount of tokens to create.
1130
+ * @param {object} [options.meta] - Additional metadata for the token.
1131
+ * @param {string} [options.batchId] - The batch identifier for stackable tokens.
1132
+ * @param {array} [options.units] - The unit IDs for the token.
1133
+ *
1134
+ * @throws {StackableUnitDecimalsException} If a stackable token has decimals.
1135
+ * @throws {StackableUnitAmountException} If stackable units are provided with an amount.
1136
+ *
1137
+ * @returns {Promise<ResponseCreateToken>} A Promise that resolves to the result of creating the token.
1118
1138
  */
1119
- async createToken ( {
1139
+ async createToken ({
1120
1140
  token,
1121
1141
  amount = null,
1122
1142
  meta = null,
1123
1143
  batchId = null,
1124
1144
  units = []
1125
- } ) {
1126
-
1145
+ }) {
1127
1146
  // What is the fungibility mode for this token?
1128
- const fungibility = Dot.get( meta || {}, 'fungibility' );
1147
+ const fungibility = Dot.get(meta || {}, 'fungibility')
1129
1148
 
1130
1149
  // For stackable token - create a batch ID
1131
- if ( fungibility === 'stackable' ) {
1132
- meta.batchId = batchId || generateBatchId( {} );
1150
+ if (fungibility === 'stackable') {
1151
+ meta.batchId = batchId || generateBatchId({})
1133
1152
  }
1134
1153
 
1135
1154
  // Special logic for token unit initialization (nonfungible || stackable)
1136
- if ( [ 'nonfungible', 'stackable' ].includes( fungibility ) && units.length > 0 ) {
1137
-
1155
+ if (['nonfungible', 'stackable'].includes(fungibility) && units.length > 0) {
1138
1156
  // Stackable tokens with Unit IDs must not use decimals
1139
- if ( Dot.get( meta || {}, 'decimals' ) > 0 ) {
1140
- throw new StackableUnitDecimalsException();
1157
+ if (Dot.get(meta || {}, 'decimals') > 0) {
1158
+ throw new StackableUnitDecimalsException()
1141
1159
  }
1142
1160
 
1143
1161
  // Can't create stackable units AND provide amount
1144
- if ( amount > 0 ) {
1145
- throw new StackableUnitAmountException();
1162
+ if (amount > 0) {
1163
+ throw new StackableUnitAmountException()
1146
1164
  }
1147
1165
 
1148
1166
  // Calculating amount based on Unit IDs
1149
- amount = units.length;
1150
- meta.splittable = 1;
1151
- meta.decimals = 0;
1152
- meta.tokenUnits = JSON.stringify( units );
1167
+ amount = units.length
1168
+ meta.splittable = 1
1169
+ meta.decimals = 0
1170
+ meta.tokenUnits = JSON.stringify(units)
1153
1171
  }
1154
1172
 
1155
1173
  // Creating the wallet that will receive the new tokens
1156
- const recipientWallet = new Wallet( {
1174
+ const recipientWallet = new Wallet({
1157
1175
  secret: this.getSecret(),
1176
+ bundle: this.getBundle(),
1158
1177
  token,
1159
1178
  batchId
1160
- } );
1179
+ })
1161
1180
 
1162
1181
  /**
1163
1182
  * @type {MutationCreateToken}
1164
1183
  */
1165
- const query = await this.createMoleculeMutation( {
1184
+ const query = await this.createMoleculeMutation({
1166
1185
  mutationClass: MutationCreateToken
1167
- } );
1186
+ })
1168
1187
 
1169
- query.fillMolecule( {
1188
+ query.fillMolecule({
1170
1189
  recipientWallet,
1171
1190
  amount,
1172
1191
  meta: meta || {}
1173
- } );
1192
+ })
1174
1193
 
1175
- return await this.executeQuery( query );
1194
+ return await this.executeQuery(query)
1176
1195
  }
1177
1196
 
1178
1197
  /**
1198
+ * Creates a new rule with the specified parameters.
1179
1199
  *
1180
- * @param {string} metaType
1181
- * @param {string} metaId
1182
- * @param {object[]} rule
1183
- * @param {object} policy
1184
- * @returns {Promise<ResponseCreateRule>}
1200
+ * @param {string} metaType - The type of the metadata associated with the rule.
1201
+ * @param {string} metaId - The ID of the metadata associated with the rule.
1202
+ * @param {object} rule - The rule object.
1203
+ * @param {object} [policy={}] - The policy object. (optional)
1204
+ * @returns {Promise<ResponseCreateRule>} - A promise that resolves to the created rule.
1185
1205
  */
1186
- async createRule ( {
1206
+ async createRule ({
1187
1207
  metaType,
1188
1208
  metaId,
1189
1209
  rule,
1190
1210
  policy = {}
1191
- } ) {
1211
+ }) {
1192
1212
  /**
1193
1213
  * @type {MutationCreateRule}
1194
1214
  */
1195
- const query = await this.createMoleculeMutation( {
1215
+ const query = await this.createMoleculeMutation({
1196
1216
  mutationClass: MutationCreateRule,
1197
- molecule: await this.createMolecule( {
1217
+ molecule: await this.createMolecule({
1198
1218
  secret: this.getSecret(),
1199
1219
  sourceWallet: await this.getSourceWallet()
1200
- } )
1220
+ })
1201
1221
  }
1202
- );
1222
+ )
1203
1223
 
1204
- query.fillMolecule( {
1224
+ query.fillMolecule({
1205
1225
  metaType,
1206
1226
  metaId,
1207
1227
  rule,
1208
1228
  policy
1209
- } );
1229
+ })
1210
1230
 
1211
- return await this.executeQuery( query );
1231
+ return await this.executeQuery(query)
1212
1232
  }
1213
1233
 
1214
1234
  /**
1215
1235
  * Builds and executes a molecule to convey new metadata to the ledger
1216
1236
  *
1217
- * @param {string} metaType
1218
- * @param {string} metaId
1219
- * @param {array|object} metadata
1220
- * @param {object|null} policy
1221
- * @return {Promise<ResponseCreateMeta>}
1237
+ * @param {string} metaType - The type of the metadata entry.
1238
+ * @param {string} metaId - The ID of the metadata entry.
1239
+ * @param {Object} [meta=null] - The metadata object.
1240
+ * @param {Object} [policy={}] - The policy object.
1241
+ * @returns {Promise<ResponseCreateMeta>} - A Promise that resolves with the created metadata entry.
1222
1242
  */
1223
- async createMeta ( {
1243
+ async createMeta ({
1224
1244
  metaType,
1225
1245
  metaId,
1226
1246
  meta = null,
1227
1247
  policy = {}
1228
- } ) {
1229
-
1248
+ }) {
1230
1249
  /**
1231
1250
  * @type {MutationCreateMeta}
1232
1251
  */
1233
- const query = await this.createMoleculeMutation( {
1252
+ const query = await this.createMoleculeMutation({
1234
1253
  mutationClass: MutationCreateMeta,
1235
- molecule: await this.createMolecule( {
1254
+ molecule: await this.createMolecule({
1236
1255
  secret: this.getSecret(),
1237
1256
  sourceWallet: await this.getSourceWallet()
1238
- } )
1257
+ })
1239
1258
  }
1240
- );
1259
+ )
1241
1260
 
1242
- const metas = meta || {};
1261
+ const metas = meta || {}
1243
1262
 
1244
- query.fillMolecule( {
1263
+ query.fillMolecule({
1245
1264
  metaType,
1246
1265
  metaId,
1247
1266
  meta: metas,
1248
1267
  policy
1249
- } );
1268
+ })
1250
1269
 
1251
- return await this.executeQuery( query );
1270
+ return await this.executeQuery(query)
1252
1271
  }
1253
1272
 
1254
1273
  /**
1255
1274
  * Builds and executes a molecule to create a new identifier on the ledger
1256
1275
  *
1257
- * @param {string} type
1258
- * @param {string} contact
1259
- * @param {string} code
1260
- * @return {Promise<ResponseCreateIdentifier>}
1276
+ * @param {string} type - The type of the identifier.
1277
+ * @param {string} contact - The contact associated with the identifier.
1278
+ * @param {string} code - The code for the identifier.
1279
+ * @returns {Promise<ResponseCreateIdentifier>} - A promise that resolves to the created identifier.
1261
1280
  */
1262
- async createIdentifier ( {
1281
+ async createIdentifier ({
1263
1282
  type,
1264
1283
  contact,
1265
1284
  code
1266
- } ) {
1267
-
1285
+ }) {
1268
1286
  /**
1269
1287
  * @type {MutationCreateIdentifier}
1270
1288
  */
1271
- const query = await this.createMoleculeMutation( {
1289
+ const query = await this.createMoleculeMutation({
1272
1290
  mutationClass: MutationCreateIdentifier
1273
- } );
1291
+ })
1274
1292
 
1275
- query.fillMolecule( {
1293
+ query.fillMolecule({
1276
1294
  type,
1277
1295
  contact,
1278
1296
  code
1279
- } );
1297
+ })
1280
1298
 
1281
- return await this.executeQuery( query );
1299
+ return await this.executeQuery(query)
1282
1300
  }
1283
1301
 
1284
1302
  /**
1303
+ * Creates a policy for a given metaType and metaId.
1285
1304
  *
1286
- * @param metaType
1287
- * @param metaId
1288
- * @param policy
1289
- * @returns {Promise<*>}
1305
+ * @param {Object} options - The options for creating the policy.
1306
+ * @param {string} options.metaType - The type of the meta.
1307
+ * @param {string} options.metaId - The ID of the meta.
1308
+ * @param {Object} [options.policy={}] - The policy object.
1309
+ * @returns {Promise<*>} - A promise that resolves with the result of the execution.
1290
1310
  */
1291
- async createPolicy ( {
1311
+ async createPolicy ({
1292
1312
  metaType,
1293
1313
  metaId,
1294
1314
  policy = {}
1295
- } ) {
1296
-
1315
+ }) {
1297
1316
  // Create a molecule
1298
- let molecule = await this.createMolecule( {} );
1299
- molecule.addPolicyAtom( {
1317
+ const molecule = await this.createMolecule({})
1318
+ molecule.addPolicyAtom({
1300
1319
  metaType,
1301
1320
  metaId,
1302
1321
  meta: {},
1303
1322
  policy
1304
- } );
1305
- molecule.addContinuIdAtom();
1306
- molecule.sign( {} );
1307
- molecule.check();
1323
+ })
1324
+ molecule.addContinuIdAtom()
1325
+ molecule.sign({
1326
+ bundle: this.getBundle()
1327
+ })
1328
+ molecule.check()
1308
1329
 
1309
1330
  // Create & execute a mutation
1310
- const query = await this.createMoleculeMutation( {
1331
+ const query = await this.createMoleculeMutation({
1311
1332
  mutationClass: MutationProposeMolecule,
1312
1333
  molecule
1313
- } );
1314
- return await this.executeQuery( query );
1334
+ })
1335
+ return await this.executeQuery(query)
1315
1336
  }
1316
1337
 
1317
1338
  /**
1339
+ * Queries the policy based on the provided metaType and metaId.
1318
1340
  *
1319
- * @param {string} metaType
1320
- * @param {string} metaId
1321
- * @returns {ResponsePolicy}
1341
+ * @param {string} metaType - The type of the meta.
1342
+ * @param {string} metaId - The ID of the meta.
1343
+ * @returns {Promise<ResponsePolicy>} - A Promise that resolves to the query result.
1322
1344
  */
1323
- async queryPolicy ( {
1345
+ async queryPolicy ({
1324
1346
  metaType,
1325
1347
  metaId
1326
- } ) {
1327
- const query = this.createQuery( QueryPolicy );
1328
- return await this.executeQuery( query, {
1348
+ }) {
1349
+ const query = this.createQuery(QueryPolicy)
1350
+ return await this.executeQuery(query, {
1329
1351
  metaType,
1330
1352
  metaId
1331
- } );
1353
+ })
1332
1354
  }
1333
1355
 
1334
1356
  /**
1335
- * Retrieves a list of your active wallets (unspent)
1357
+ * Queries wallets based on the provided parameters.
1336
1358
  *
1337
- * @param {string|null} bundle
1338
- * @param {string|null} token
1339
- * @param {boolean|null} unspent
1340
- * @return {Promise<Response>}
1359
+ * @param {object} options - The options for querying wallets.
1360
+ * @param {string|null} options.bundle - The bundle to query wallets for.
1361
+ * @param {string|null} options.token - The token to query wallets for.
1362
+ * @param {boolean} [options.unspent=true] - Whether to include unspent wallets or not.
1363
+ *
1364
+ * @returns {Promise<ResponseWalletList>} - A promise that resolves to the response payload of the query.
1341
1365
  */
1342
- queryWallets ( {
1366
+ queryWallets ({
1343
1367
  bundle = null,
1344
1368
  token = null,
1345
1369
  unspent = true
1346
- } ) {
1347
-
1348
- if ( this.$__logging ) {
1349
- console.info( `KnishIOClient::queryWallets() - Querying wallets${ bundle ? ` for ${ bundle }` : '' }...` );
1350
- }
1370
+ }) {
1371
+ this.log('info', `KnishIOClient::queryWallets() - Querying wallets${ bundle ? ` for ${ bundle }` : '' }...`)
1351
1372
 
1352
1373
  /**
1353
1374
  * @type {QueryWalletList}
1354
1375
  */
1355
- const walletQuery = this.createQuery( QueryWalletList );
1376
+ const walletQuery = this.createQuery(QueryWalletList)
1356
1377
 
1357
- return this.executeQuery( walletQuery, {
1358
- bundleHash: bundle ? bundle : this.getBundle(),
1359
- token,
1378
+ return this.executeQuery(walletQuery, {
1379
+ bundleHash: bundle || this.getBundle(),
1380
+ tokenSlug: token,
1360
1381
  unspent
1361
- } )
1362
- .then( ( response ) => {
1363
- return response.payload();
1364
- } );
1365
- }
1366
-
1367
- /**
1368
- * Retrieves a list of your shadow wallets (balance, but no keys)
1369
- *
1370
- * @param {string} token
1371
- * @param {string|null} bundle
1372
- * @return {Promise<[]>}
1373
- */
1374
- queryShadowWallets ( {
1375
- token = 'KNISH',
1376
- bundle = null
1377
- } ) {
1378
-
1379
- bundle = bundle || this.getBundle();
1380
-
1381
- if ( this.$__logging ) {
1382
- console.info( `KnishIOClient::queryShadowWallets() - Querying ${ token } shadow wallets for ${ bundle }...` );
1383
- }
1384
-
1385
- /**
1386
- * @type {QueryWalletList}
1387
- */
1388
- const shadowWalletQuery = this.createQuery( QueryWalletList );
1389
-
1390
- return this.executeQuery( shadowWalletQuery, {
1391
- bundleHash: bundle,
1392
- token
1393
- } )
1394
- .then( ( /** ResponseWalletList */ response ) => {
1395
- return response.payload();
1396
- } );
1382
+ })
1383
+ .then((response) => {
1384
+ return response.payload()
1385
+ })
1397
1386
  }
1398
1387
 
1399
1388
  /**
1400
- * Retrieves your wallet bundle's metadata from the ledger
1389
+ * Queries wallet bundle metadata.
1401
1390
  *
1402
- * @param {string|boolean|null} bundle
1403
- * @param {string|array|null} key
1404
- * @param {string|array|null} value
1405
- * @param {boolean} latest
1406
- * @param {object|null} fields
1407
- * @param {boolean} raw
1408
- * @return {Promise<ResponseWalletBundle|{}>}
1391
+ * @param {Object} options - The options for the query.
1392
+ * @param {string|null} options.bundle - The bundle to query. Default is null.
1393
+ * @param {string|null} options.fields - The fields to retrieve. Default is null.
1394
+ * @param {boolean} options.raw - Whether to return the raw response or the payload. Default is false.
1395
+ * @returns {Promise<ResponseWalletBundle|{}|null>} - A promise that resolves to the response or payload.
1409
1396
  */
1410
- queryBundle ( {
1397
+ queryBundle ({
1411
1398
  bundle = null,
1412
- key = null,
1413
- value = null,
1414
- latest = true,
1415
1399
  fields = null,
1416
1400
  raw = false
1417
- } ) {
1401
+ }) {
1402
+ this.log('info', `KnishIOClient::queryBundle() - Querying wallet bundle metadata${ bundle ? ` for ${ bundle }` : '' }...`)
1418
1403
 
1419
- if ( this.$__logging ) {
1420
- console.info( `KnishIOClient::queryBundle() - Querying wallet bundle metadata${ bundle ? ` for ${ bundle }` : '' }...` );
1404
+ // Bundle default init & to array convertion
1405
+ if (!bundle) {
1406
+ bundle = this.getBundle()
1407
+ }
1408
+ if (typeof bundle === 'string') {
1409
+ bundle = [bundle]
1421
1410
  }
1422
1411
 
1423
1412
  /**
1424
1413
  * @type {QueryWalletBundle}
1425
1414
  */
1426
- const query = this.createQuery( QueryWalletBundle );
1427
- const variables = QueryWalletBundle.createVariables( {
1428
- bundleHash: bundle || this.getBundle(),
1429
- key,
1430
- value,
1431
- latest
1432
- } );
1433
-
1434
-
1435
- return this.executeQuery( query, variables )
1436
- .then( ( /** ResponseWalletBundle */ response ) => {
1437
- return raw ? response : response.payload();
1438
- } );
1415
+ const query = this.createQuery(QueryWalletBundle)
1416
+ return this.executeQuery(query, { bundleHashes: bundle })
1417
+ .then((/** ResponseWalletBundle */ response) => {
1418
+ return raw ? response : response.payload()
1419
+ })
1439
1420
  }
1440
1421
 
1441
1422
  /**
1442
1423
  * Queries the ledger for the next ContinuId wallet
1443
1424
  *
1444
- * @param bundle
1445
- * @return {Promise<ResponseContinuId>}
1425
+ * @param {String} bundle - The bundle hash used in the query.
1426
+ * @returns {Promise<ResponseContinuId>} - A promise that resolves to the result of the query.
1446
1427
  */
1447
- async queryContinuId ( {
1428
+ async queryContinuId ({
1448
1429
  bundle
1449
- } ) {
1430
+ }) {
1450
1431
  /**
1451
1432
  * @type {QueryContinuId}
1452
1433
  */
1453
- const query = this.createQuery( QueryContinuId );
1434
+ const query = this.createQuery(QueryContinuId)
1454
1435
 
1455
- return this.executeQuery( query, {
1436
+ return this.executeQuery(query, {
1456
1437
  bundle
1457
- } );
1438
+ })
1458
1439
  }
1459
1440
 
1460
1441
  /**
1461
- * Builds and executes a Molecule that requests token payment from the node
1442
+ * Requests tokens for a specific recipient or for the current wallet bundle.
1462
1443
  *
1463
- * @param {string} token
1464
- * @param {string|Wallet} to
1465
- * @param {number|null} amount
1466
- * @param {array|null} units
1467
- * @param {array|object} meta
1468
- * @param {string|null} batchId
1469
- * @return {Promise<ResponseRequestTokens>}
1444
+ * @param {Object} options - The options for the token request.
1445
+ * @param {string} options.token - The token slug.
1446
+ * @param {string|Wallet} [options.to] - The recipient of the tokens. If not provided, tokens will be requested for the current wallet bundle.
1447
+ * @param {number|null} [options.amount=null] - The amount of tokens to request. If not provided and `options.units` are provided, the amount will be calculated based on the number of
1448
+ * units.
1449
+ * @param {Array} [options.units=[]] - The array of unit IDs. If provided, the amount will be calculated based on the length of `options.units`.
1450
+ * @param {Object|null} [options.meta=null] - Additional metadata for the token request.
1451
+ * @param {string|null} [options.batchId=null] - The batch ID for the token request. If not provided and the token is stackable, a new batch ID will be generated.
1452
+ *
1453
+ * @returns {Promise<ResponseRequestTokens>} - A promise that resolves with the response from the token request.
1454
+ *
1455
+ * @throws {BatchIdException} - When a non-stackable token is used and `options.batchId` is not null.
1456
+ * @throws {StackableUnitAmountException} - When both `options.units` and `options.amount` are provided for stackable tokens.
1470
1457
  */
1471
- async requestTokens ( {
1458
+ async requestTokens ({
1472
1459
  token,
1473
1460
  to,
1474
1461
  amount = null,
1475
1462
  units = [],
1476
1463
  meta = null,
1477
1464
  batchId = null
1478
- } ) {
1479
-
1465
+ }) {
1480
1466
  let metaType,
1481
- metaId;
1482
-
1483
- meta = meta || {};
1467
+ metaId
1484
1468
 
1469
+ meta = meta || {}
1485
1470
 
1486
1471
  // Get a token & init is Stackable flag for batch ID initialization
1487
- const queryToken = this.createQuery( QueryToken );
1488
- const tokenResponse = await this.executeQuery( queryToken, {
1472
+ const queryToken = this.createQuery(QueryToken)
1473
+ const tokenResponse = await this.executeQuery(queryToken, {
1489
1474
  slug: token
1490
- } );
1491
- const isStackable = Dot.get( tokenResponse.data(), '0.fungibility' ) === 'stackable';
1475
+ })
1476
+ const isStackable = Dot.get(tokenResponse.data(), '0.fungibility') === 'stackable'
1492
1477
 
1493
1478
  // NON-stackable tokens & batch ID is NOT NULL - error
1494
- if ( !isStackable && batchId !== null ) {
1495
- throw new BatchIdException( 'Expected Batch ID = null for non-stackable tokens.' );
1479
+ if (!isStackable && batchId !== null) {
1480
+ throw new BatchIdException('Expected Batch ID = null for non-stackable tokens.')
1496
1481
  }
1497
1482
  // Stackable tokens & batch ID is NULL - generate new one
1498
- if ( isStackable && batchId === null ) {
1499
- batchId = generateBatchId( {} );
1483
+ if (isStackable && batchId === null) {
1484
+ batchId = generateBatchId({})
1500
1485
  }
1501
1486
 
1502
1487
  // Calculate amount & set meta key
1503
- if ( units.length > 0 ) {
1504
-
1488
+ if (units.length > 0) {
1505
1489
  // Can't move stackable units AND provide amount
1506
- if ( amount > 0 ) {
1507
- throw new StackableUnitAmountException();
1490
+ if (amount > 0) {
1491
+ throw new StackableUnitAmountException()
1508
1492
  }
1509
1493
 
1510
1494
  // Calculating amount based on Unit IDs
1511
- amount = units.length;
1512
- meta.tokenUnits = JSON.stringify( units );
1495
+ amount = units.length
1496
+ meta.tokenUnits = JSON.stringify(units)
1513
1497
  }
1514
1498
 
1515
1499
  // Are we specifying a specific recipient?
1516
- if ( to ) {
1517
-
1500
+ if (to) {
1518
1501
  // If the recipient is provided as an object, try to figure out the actual recipient
1519
- if ( Object.prototype.toString.call( to ) === '[object String]' ) {
1520
- if ( Wallet.isBundleHash( to ) ) {
1521
- metaType = 'walletBundle';
1522
- metaId = to;
1502
+ if (Object.prototype.toString.call(to) === '[object String]') {
1503
+ if (Wallet.isBundleHash(to)) {
1504
+ metaType = 'walletBundle'
1505
+ metaId = to
1523
1506
  } else {
1524
- to = Wallet.create( {
1525
- secretOrBundle: to,
1507
+ to = Wallet.create({
1508
+ secret: to,
1526
1509
  token
1527
- } );
1510
+ })
1528
1511
  }
1529
1512
  }
1530
1513
 
1531
1514
  // If recipient is a Wallet, we need to help the node triangulate
1532
1515
  // the transfer by providing position and bundle hash
1533
- if ( to instanceof Wallet ) {
1534
- metaType = 'wallet';
1535
- meta[ 'position' ] = to.position;
1536
- meta[ 'bundle' ] = to.bundle;
1537
- metaId = to.address;
1516
+ if (to instanceof Wallet) {
1517
+ metaType = 'wallet'
1518
+ meta.position = to.position
1519
+ meta.bundle = to.bundle
1520
+ metaId = to.address
1538
1521
  }
1539
1522
  } else {
1540
-
1541
1523
  // No recipient, so request tokens for ourselves
1542
- metaType = 'walletBundle';
1543
- metaId = this.getBundle();
1544
-
1524
+ metaType = 'walletBundle'
1525
+ metaId = this.getBundle()
1545
1526
  }
1546
1527
 
1547
1528
  /**
1548
1529
  * @type {MutationRequestTokens}
1549
1530
  */
1550
- const query = await this.createMoleculeMutation( {
1531
+ const query = await this.createMoleculeMutation({
1551
1532
  mutationClass: MutationRequestTokens
1552
- } );
1533
+ })
1553
1534
 
1554
- query.fillMolecule( {
1535
+ query.fillMolecule({
1555
1536
  token,
1556
1537
  amount,
1557
1538
  metaType,
1558
1539
  metaId,
1559
1540
  meta,
1560
1541
  batchId
1561
- } );
1542
+ })
1562
1543
 
1563
- return await this.executeQuery( query );
1544
+ return await this.executeQuery(query)
1564
1545
  }
1565
1546
 
1566
1547
  /**
1567
- * Creates and executes a Molecule that assigns keys to an unclaimed shadow wallet
1548
+ * Claims a shadow wallet for a given token.
1568
1549
  *
1569
- * @param {string} token
1570
- * @param {string|null} batchId
1571
- * @param {Molecule|null} molecule
1572
- * @return {Promise<ResponseClaimShadowWallet>}
1550
+ * @param {string} token - The token for which to claim the shadow wallet.
1551
+ * @param {string|null} batchId - The batch ID of the shadow wallet (optional).
1552
+ * @param {string|null} molecule - The molecule associated with the shadow wallet (optional).
1553
+ *
1554
+ * @returns {Promise<ResponseClaimShadowWallet>} - A promise that resolves to the result of the claim operation.
1573
1555
  */
1574
- async claimShadowWallet ( {
1556
+ async claimShadowWallet ({
1575
1557
  token,
1576
1558
  batchId = null,
1577
1559
  molecule = null
1578
- } ) {
1579
-
1560
+ }) {
1580
1561
  /**
1581
1562
  * @type {MutationClaimShadowWallet}
1582
1563
  */
1583
- const query = await this.createMoleculeMutation( {
1564
+ const query = await this.createMoleculeMutation({
1584
1565
  mutationClass: MutationClaimShadowWallet,
1585
1566
  molecule
1586
- } );
1567
+ })
1587
1568
 
1588
- query.fillMolecule( {
1569
+ query.fillMolecule({
1589
1570
  token,
1590
1571
  batchId
1591
- } );
1572
+ })
1592
1573
 
1593
- return await this.executeQuery( query );
1574
+ return await this.executeQuery(query)
1594
1575
  }
1595
1576
 
1596
-
1597
1577
  /**
1598
- * Claim shadow wallets
1578
+ * Claims all shadow wallets for a given token.
1599
1579
  *
1600
- * @param {string} token
1601
- * @return {[]}
1580
+ * @param {Object} options - The options for claiming shadow wallets.
1581
+ * @param {string} options.token - The token to claim shadow wallets for.
1582
+ * @returns {Promise<*>} - A promise that resolves to an array of responses from claiming shadow wallets.
1583
+ * @throws {WalletShadowException} - If the shadow wallet list is invalid or if a non-shadow wallet is found.
1602
1584
  */
1603
- async claimShadowWallets ( {
1585
+ async claimShadowWallets ({
1604
1586
  token
1605
- } ) {
1606
-
1587
+ }) {
1607
1588
  // --- Get & check a shadow wallet list
1608
- const shadowWallets = await this.queryShadowWallets( { token } );
1609
- if ( !shadowWallets || !Array.isArray( shadowWallets ) ) {
1610
- throw new WalletShadowException();
1589
+ const shadowWallets = await this.queryWallets({ token })
1590
+ if (!shadowWallets || !Array.isArray(shadowWallets)) {
1591
+ throw new WalletShadowException()
1611
1592
  }
1612
1593
 
1613
- shadowWallets.forEach( shadowWallet => {
1614
- if ( !shadowWallet.isShadow() ) {
1615
- throw new WalletShadowException();
1594
+ shadowWallets.forEach(shadowWallet => {
1595
+ if (!shadowWallet.isShadow()) {
1596
+ throw new WalletShadowException()
1616
1597
  }
1617
- } );
1598
+ })
1618
1599
  // ----
1619
1600
 
1620
- let responses = [];
1621
- for ( const shadowWallet of shadowWallets ) {
1622
- responses.push( await this.claimShadowWallet( {
1601
+ const responses = []
1602
+ for (const shadowWallet of shadowWallets) {
1603
+ responses.push(await this.claimShadowWallet({
1623
1604
  token,
1624
1605
  batchId: shadowWallet.batchId
1625
- } ) );
1606
+ }))
1626
1607
  }
1627
- return responses;
1608
+ return responses
1628
1609
  }
1629
1610
 
1630
1611
  /**
1631
- * Creates and executes a Molecule that moves tokens from one user to another
1632
- * @param {string} bundleHash
1633
- * @param {string} token
1634
- * @param {number|null} amount
1635
- * @param {[]} units
1636
- * @param {string|null} batchId
1637
- * @param {Wallet|null} sourceWallet
1638
- * @returns {Promise<*>}
1612
+ * Transfers tokens from one wallet to another.
1613
+ *
1614
+ * @param {Object} options - The transfer options.
1615
+ * @param {string} options.bundleHash - The bundle hash of the source wallet.
1616
+ * @param {string} options.token - The token to transfer.
1617
+ * @param {number} [options.amount=null] - The amount of tokens to transfer. Not required if units are provided.
1618
+ * @param {Array} [options.units=[]] - An array of units to transfer. Overrides the amount if provided.
1619
+ * @param {string} [options.batchId=null] - The batch ID for the recipient wallet.
1620
+ * @param {Object} [options.sourceWallet=null] - The source wallet object. If not provided, it will be queried.
1621
+ *
1622
+ * @returns {Promise} - A Promise that resolves to the transaction result.
1623
+ *
1624
+ * @throws {StackableUnitAmountException} - If both amount and units are provided.
1625
+ * @throws {TransferBalanceException} - If the source wallet does not have enough balance.
1639
1626
  */
1640
- async transferToken ( {
1627
+ async transferToken ({
1641
1628
  bundleHash,
1642
1629
  token,
1643
1630
  amount = null,
1644
1631
  units = [],
1645
1632
  batchId = null,
1646
1633
  sourceWallet = null
1647
- } ) {
1648
-
1634
+ }) {
1649
1635
  // Calculate amount & set meta key
1650
- if ( units.length > 0 ) {
1651
-
1636
+ if (units.length > 0) {
1652
1637
  // Can't move stackable units AND provide amount
1653
- if ( amount > 0 ) {
1654
- throw new StackableUnitAmountException();
1638
+ if (amount > 0) {
1639
+ throw new StackableUnitAmountException()
1655
1640
  }
1656
1641
 
1657
- amount = units.length;
1642
+ amount = units.length
1658
1643
  }
1659
1644
 
1660
1645
  // Get a source wallet
1661
- if ( sourceWallet === null ) {
1662
- sourceWallet = await this.querySourceWallet( {
1646
+ if (sourceWallet === null) {
1647
+ sourceWallet = await this.querySourceWallet({
1663
1648
  token,
1664
1649
  amount
1665
- } );
1650
+ })
1666
1651
  }
1667
1652
 
1668
1653
  // Do you have enough tokens?
1669
- if ( sourceWallet === null || Decimal.cmp( sourceWallet.balance, amount ) < 0 ) {
1670
- throw new TransferBalanceException();
1654
+ if (sourceWallet === null || Decimal.cmp(sourceWallet.balance, amount) < 0) {
1655
+ throw new TransferBalanceException()
1671
1656
  }
1672
1657
 
1673
1658
  // Attempt to get the recipient's wallet, if not provided
1674
- let recipientWallet = Wallet.create( {
1675
- secretOrBundle: bundleHash,
1659
+ const recipientWallet = Wallet.create({
1660
+ bundle: bundleHash,
1676
1661
  token
1677
- } );
1662
+ })
1678
1663
 
1679
1664
  // Compute the batch ID for the recipient
1680
1665
  // (typically used by stackable tokens)
1681
- if ( batchId !== null ) {
1682
- recipientWallet.batchId = batchId;
1666
+ if (batchId !== null) {
1667
+ recipientWallet.batchId = batchId
1683
1668
  } else {
1684
- recipientWallet.initBatchId( {
1669
+ recipientWallet.initBatchId({
1685
1670
  sourceWallet
1686
- } );
1671
+ })
1687
1672
  }
1688
1673
 
1689
- this.remainderWallet = Wallet.create( {
1690
- secretOrBundle: this.getSecret(),
1691
- token,
1692
- characters: sourceWallet.characters
1693
- } );
1694
- this.remainderWallet.initBatchId( {
1695
- sourceWallet,
1696
- isRemainder: true
1697
- } );
1674
+ // Create a remainder from the source wallet
1675
+ const remainderWallet = sourceWallet.createRemainder(this.getSecret())
1698
1676
 
1699
1677
  // --- Token units splitting
1700
1678
  sourceWallet.splitUnits(
1701
1679
  units,
1702
- this.remainderWallet,
1680
+ remainderWallet,
1703
1681
  recipientWallet
1704
- );
1682
+ )
1705
1683
  // ---
1706
1684
 
1707
1685
  // Build the molecule itself
1708
- const molecule = await this.createMolecule( {
1709
- sourceWallet: sourceWallet,
1710
- remainderWallet: this.remainderWallet
1711
- } ),
1712
- /**
1713
- * @type {MutationTransferTokens}
1714
- */
1715
- query = await this.createMoleculeMutation( {
1716
- mutationClass: MutationTransferTokens,
1717
- molecule
1718
- } );
1686
+ const molecule = await this.createMolecule({
1687
+ sourceWallet,
1688
+ remainderWallet
1689
+ })
1690
+ /**
1691
+ * @type {MutationTransferTokens}
1692
+ */
1693
+ const query = await this.createMoleculeMutation({
1694
+ mutationClass: MutationTransferTokens,
1695
+ molecule
1696
+ })
1719
1697
 
1720
- query.fillMolecule( {
1698
+ query.fillMolecule({
1721
1699
  recipientWallet,
1722
1700
  amount
1723
- } );
1701
+ })
1724
1702
 
1725
- return await this.executeQuery( query );
1703
+ return await this.executeQuery(query)
1726
1704
  }
1727
1705
 
1728
-
1729
1706
  /**
1707
+ * Deposits buffer token into the source wallet.
1730
1708
  *
1731
- * @param tokenSlug
1732
- * @param amount
1733
- * @param tradeRates
1734
- * @param sourceWallet
1735
- * @returns {Promise<function(*): *>}
1709
+ * @param {Object} options - The options for depositing buffer token.
1710
+ * @param {string} options.tokenSlug - The slug of the token to deposit.
1711
+ * @param {number} options.amount - The amount of token to deposit.
1712
+ * @param {Object} options.tradeRates - The trade rates for the deposit.
1713
+ * @param {Wallet|null} options.sourceWallet - The source wallet for the deposit. If not provided, a source wallet will be queried.
1714
+ *
1715
+ * @returns {Promise<*>} - A promise that resolves with the result of the deposit.
1736
1716
  */
1737
- async depositBufferToken ( {
1717
+ async depositBufferToken ({
1738
1718
  tokenSlug,
1739
1719
  amount,
1740
1720
  tradeRates,
1741
1721
  sourceWallet = null
1742
- } ) {
1743
-
1722
+ }) {
1744
1723
  // Get a source wallet
1745
- if ( sourceWallet === null ) {
1746
- sourceWallet = await this.querySourceWallet( {
1724
+ if (sourceWallet === null) {
1725
+ sourceWallet = await this.querySourceWallet({
1747
1726
  token: tokenSlug,
1748
1727
  amount
1749
- } );
1728
+ })
1750
1729
  }
1751
1730
 
1752
1731
  // Remainder wallet
1753
- this.remainderWallet = Wallet.create( {
1754
- secretOrBundle: this.getSecret(),
1755
- token: tokenSlug,
1756
- characters: sourceWallet.characters
1757
- } );
1758
- this.remainderWallet.initBatchId( {
1759
- sourceWallet,
1760
- isRemainder: true
1761
- } );
1762
-
1732
+ const remainderWallet = sourceWallet.createRemainder(this.getSecret())
1763
1733
 
1764
1734
  // Build the molecule itself
1765
- const molecule = await this.createMolecule( {
1735
+ const molecule = await this.createMolecule({
1766
1736
  sourceWallet,
1767
- remainderWallet: this.remainderWallet
1768
- } ),
1737
+ remainderWallet
1738
+ })
1769
1739
  /**
1770
1740
  * @type {MutationDepositBufferToken}
1771
1741
  */
1772
- query = await this.createMoleculeMutation( {
1742
+ const query = await this.createMoleculeMutation({
1773
1743
  mutationClass: MutationDepositBufferToken,
1774
1744
  molecule
1775
- } );
1776
- query.fillMolecule( {
1745
+ })
1746
+ query.fillMolecule({
1777
1747
  amount,
1778
1748
  tradeRates
1779
- } );
1780
- return await this.executeQuery( query );
1749
+ })
1750
+ return await this.executeQuery(query)
1781
1751
  }
1782
1752
 
1783
-
1784
1753
  /**
1754
+ * Withdraws buffer tokens.
1785
1755
  *
1786
- * @param tokenSlug
1787
- * @param amount
1788
- * @param sourceWallet
1789
- * @param signingWallet
1790
- * @returns {Promise<void>}
1791
- */
1792
- async withdrawBufferToken ( {
1756
+ * @param {Object} options - The options for withdrawing buffer tokens.
1757
+ * @param {string} options.tokenSlug - The token slug.
1758
+ * @param {number} options.amount - The amount of tokens to withdraw.
1759
+ * @param {Object} [options.sourceWallet=null] - The source wallet to withdraw tokens from. If not provided, a source wallet will be queried.
1760
+ * @param {Object} [options.signingWallet=null] - The signing wallet to use for the transaction.
1761
+ * @returns {Promise<Object>} A promise that resolves to the result of the withdrawal transaction.
1762
+ */
1763
+ async withdrawBufferToken ({
1793
1764
  tokenSlug,
1794
1765
  amount,
1795
1766
  sourceWallet = null,
1796
1767
  signingWallet = null
1797
- } ) {
1798
-
1768
+ }) {
1799
1769
  // Get a source wallet
1800
- if ( sourceWallet === null ) {
1801
- sourceWallet = await this.querySourceWallet( {
1770
+ if (sourceWallet === null) {
1771
+ sourceWallet = await this.querySourceWallet({
1802
1772
  token: tokenSlug,
1803
1773
  amount,
1804
1774
  type: 'buffer'
1805
- } );
1775
+ })
1806
1776
  }
1807
1777
 
1808
1778
  // Remainder wallet
1809
- this.remainderWallet = sourceWallet;
1810
-
1779
+ const remainderWallet = sourceWallet
1811
1780
 
1812
1781
  // Build the molecule itself
1813
- const molecule = await this.createMolecule( {
1782
+ const molecule = await this.createMolecule({
1814
1783
  sourceWallet,
1815
- remainderWallet: this.remainderWallet
1816
- } ),
1784
+ remainderWallet
1785
+ })
1817
1786
  /**
1818
1787
  * @type {MutationWithdrawBufferToken}
1819
1788
  */
1820
- query = await this.createMoleculeMutation( {
1789
+ const query = await this.createMoleculeMutation({
1821
1790
  mutationClass: MutationWithdrawBufferToken,
1822
1791
  molecule
1823
- } );
1824
- let recipients = {};
1825
- recipients[ this.getBundle() ] = amount;
1826
- query.fillMolecule( {
1792
+ })
1793
+ const recipients = {}
1794
+ recipients[this.getBundle()] = amount
1795
+ query.fillMolecule({
1827
1796
  recipients,
1828
1797
  signingWallet
1829
- } );
1830
- return await this.executeQuery( query );
1798
+ })
1799
+ return await this.executeQuery(query)
1831
1800
  }
1832
1801
 
1833
-
1834
1802
  /**
1835
1803
  * Builds and executes a molecule to destroy the specified Token units
1836
1804
  *
@@ -1840,69 +1808,60 @@ export default class KnishIOClient {
1840
1808
  * @param {Wallet|null} sourceWallet
1841
1809
  * @return {Promise<unknown>}
1842
1810
  */
1843
- async burnTokens ( {
1811
+ async burnTokens ({
1844
1812
  token,
1845
1813
  amount = null,
1846
1814
  units = [],
1847
1815
  sourceWallet = null
1848
- } ) {
1849
-
1816
+ }) {
1850
1817
  // Get a source wallet
1851
- if ( sourceWallet === null ) {
1852
- sourceWallet = await this.querySourceWallet( {
1818
+ if (sourceWallet === null) {
1819
+ sourceWallet = await this.querySourceWallet({
1853
1820
  token,
1854
1821
  amount
1855
- } );
1822
+ })
1856
1823
  }
1857
1824
 
1858
1825
  // Remainder wallet
1859
- let remainderWallet = Wallet.create( {
1860
- secretOrBundle: this.getSecret(),
1861
- token,
1862
- characters: sourceWallet.characters
1863
- } );
1864
-
1865
- // Batch ID default initialization
1866
- remainderWallet.initBatchId( {
1867
- sourceWallet,
1868
- isRemainder: true
1869
- } );
1826
+ const remainderWallet = sourceWallet.createRemainder(this.getSecret())
1870
1827
 
1871
1828
  // Calculate amount & set meta key
1872
- if ( units.length > 0 ) {
1873
-
1829
+ if (units.length > 0) {
1874
1830
  // Can't burn stackable units AND provide amount
1875
- if ( amount > 0 ) {
1876
- throw new StackableUnitAmountException();
1831
+ if (amount > 0) {
1832
+ throw new StackableUnitAmountException()
1877
1833
  }
1878
1834
 
1879
1835
  // Calculating amount based on Unit IDs
1880
- amount = units.length;
1836
+ amount = units.length
1881
1837
 
1882
1838
  // --- Token units splitting
1883
1839
  sourceWallet.splitUnits(
1884
1840
  units,
1885
1841
  remainderWallet
1886
- );
1842
+ )
1887
1843
  // ---
1888
-
1889
1844
  }
1890
1845
 
1891
1846
  // Create a molecule
1892
- let molecule = await this.createMolecule( { sourceWallet, remainderWallet } );
1893
- molecule.burnToken( { amount } );
1894
- molecule.sign( {} );
1895
- molecule.check();
1847
+ const molecule = await this.createMolecule({
1848
+ sourceWallet,
1849
+ remainderWallet
1850
+ })
1851
+ molecule.burnToken({ amount })
1852
+ molecule.sign({
1853
+ bundle: this.getBundle()
1854
+ })
1855
+ molecule.check()
1896
1856
 
1897
1857
  // Create & execute a mutation
1898
- const query = await this.createMoleculeMutation( {
1858
+ const query = await this.createMoleculeMutation({
1899
1859
  mutationClass: MutationProposeMolecule,
1900
1860
  molecule
1901
- } );
1902
- return this.executeQuery( query );
1861
+ })
1862
+ return this.executeQuery(query)
1903
1863
  }
1904
1864
 
1905
-
1906
1865
  /**
1907
1866
  * Builds and executes a molecule to destroy the specified Token units
1908
1867
  *
@@ -1912,51 +1871,44 @@ export default class KnishIOClient {
1912
1871
  * @param {Wallet|null} sourceWallet
1913
1872
  * @return {Promise<unknown>}
1914
1873
  */
1915
- async replenishToken ( {
1874
+ async replenishToken ({
1916
1875
  token,
1917
1876
  amount = null,
1918
1877
  units = [],
1919
1878
  sourceWallet = null
1920
- } ) {
1921
-
1922
-
1923
- if ( sourceWallet === null ) {
1924
- sourceWallet = ( await this.queryBalance( { token } ) ).payload();
1879
+ }) {
1880
+ if (sourceWallet === null) {
1881
+ sourceWallet = (await this.queryBalance({ token })).payload()
1925
1882
  }
1926
- if ( !sourceWallet ) {
1927
- throw new TransferBalanceException( 'Source wallet is missing or invalid.' );
1883
+ if (!sourceWallet) {
1884
+ throw new TransferBalanceException('Source wallet is missing or invalid.')
1928
1885
  }
1929
1886
 
1930
-
1931
1887
  // Remainder wallet
1932
- let remainderWallet = Wallet.create( {
1933
- secretOrBundle: this.getSecret(),
1934
- token,
1935
- characters: sourceWallet.characters
1936
- } );
1937
-
1938
- // Batch ID default initialization
1939
- remainderWallet.initBatchId( {
1940
- sourceWallet,
1941
- isRemainder: true
1942
- } );
1943
-
1888
+ const remainderWallet = sourceWallet.createRemainder(this.getSecret())
1944
1889
 
1945
1890
  // Create a molecule
1946
- let molecule = await this.createMolecule( { sourceWallet, remainderWallet } );
1947
- molecule.replenishToken( { amount, units } );
1948
- molecule.sign( {} );
1949
- molecule.check();
1891
+ const molecule = await this.createMolecule({
1892
+ sourceWallet,
1893
+ remainderWallet
1894
+ })
1895
+ molecule.replenishToken({
1896
+ amount,
1897
+ units
1898
+ })
1899
+ molecule.sign({
1900
+ bundle: this.getBundle()
1901
+ })
1902
+ molecule.check()
1950
1903
 
1951
1904
  // Create & execute a mutation
1952
- const query = await this.createMoleculeMutation( {
1905
+ const query = await this.createMoleculeMutation({
1953
1906
  mutationClass: MutationProposeMolecule,
1954
1907
  molecule
1955
- } );
1956
- return this.executeQuery( query );
1908
+ })
1909
+ return this.executeQuery(query)
1957
1910
  }
1958
1911
 
1959
-
1960
1912
  /**
1961
1913
  *
1962
1914
  * @param bundleHash
@@ -1966,137 +1918,124 @@ export default class KnishIOClient {
1966
1918
  * @param sourceWallet
1967
1919
  * @returns {Promise<*>}
1968
1920
  */
1969
- async fuseToken ( {
1921
+ async fuseToken ({
1970
1922
  bundleHash,
1971
1923
  tokenSlug,
1972
1924
  newTokenUnit,
1973
1925
  fusedTokenUnitIds,
1974
1926
  sourceWallet = null
1975
- } ) {
1976
-
1977
- if ( sourceWallet === null ) {
1978
- sourceWallet = ( await this.queryBalance( { token: tokenSlug } ) ).payload();
1927
+ }) {
1928
+ if (sourceWallet === null) {
1929
+ sourceWallet = (await this.queryBalance({ token: tokenSlug })).payload()
1979
1930
  }
1980
1931
 
1981
1932
  // Check source wallet
1982
- if ( sourceWallet === null ) {
1983
- throw new TransferBalanceException( 'Source wallet is missing or invalid.' );
1933
+ if (sourceWallet === null) {
1934
+ throw new TransferBalanceException('Source wallet is missing or invalid.')
1984
1935
  }
1985
- if ( !sourceWallet.tokenUnits || !sourceWallet.tokenUnits.length ) {
1986
- throw new TransferBalanceException( 'Source wallet does not have token units.' );
1936
+ if (!sourceWallet.tokenUnits || !sourceWallet.tokenUnits.length) {
1937
+ throw new TransferBalanceException('Source wallet does not have token units.')
1987
1938
  }
1988
- if ( !fusedTokenUnitIds.length ) {
1989
- throw new TransferBalanceException( 'Fused token unit list is empty.' );
1939
+ if (!fusedTokenUnitIds.length) {
1940
+ throw new TransferBalanceException('Fused token unit list is empty.')
1990
1941
  }
1991
1942
 
1992
1943
  // Check fused token units
1993
- let sourceTokenUnitIds = [];
1994
- sourceWallet.tokenUnits.forEach( ( tokenUnit ) => {
1995
- sourceTokenUnitIds.push( tokenUnit.id );
1996
- } );
1997
- fusedTokenUnitIds.forEach( ( tokenUnitId ) => {
1998
- if ( !sourceTokenUnitIds.includes( tokenUnitId ) ) {
1999
- throw new TransferBalanceException( `Fused token unit ID = ${ tokenUnitId } does not found in the source wallet.` );
1944
+ const sourceTokenUnitIds = []
1945
+ sourceWallet.tokenUnits.forEach((tokenUnit) => {
1946
+ sourceTokenUnitIds.push(tokenUnit.id)
1947
+ })
1948
+ fusedTokenUnitIds.forEach((tokenUnitId) => {
1949
+ if (!sourceTokenUnitIds.includes(tokenUnitId)) {
1950
+ throw new TransferBalanceException(`Fused token unit ID = ${ tokenUnitId } does not found in the source wallet.`)
2000
1951
  }
2001
- } );
2002
-
1952
+ })
2003
1953
 
2004
1954
  // Generate new recipient wallet if only recipient secret has been passed
2005
- let recipientWallet = Wallet.create( {
2006
- secretOrBundle: bundleHash,
1955
+ const recipientWallet = Wallet.create({
1956
+ bundle: bundleHash,
2007
1957
  token: tokenSlug
2008
- } );
1958
+ })
2009
1959
 
2010
1960
  // Set batch ID
2011
- recipientWallet.initBatchId( { sourceWallet } );
1961
+ recipientWallet.initBatchId({ sourceWallet })
2012
1962
 
2013
1963
  // Remainder wallet
2014
- let remainderWallet = Wallet.create( {
2015
- secretOrBundle: this.getSecret(),
2016
- token: tokenSlug,
2017
- batchId: sourceWallet.batchId,
2018
- characters: sourceWallet.characters
2019
- } );
2020
- remainderWallet.initBatchId( {
2021
- sourceWallet,
2022
- isRemainder: true
2023
- } );
2024
-
1964
+ const remainderWallet = sourceWallet.createRemainder(this.getSecret())
2025
1965
 
2026
1966
  // Split token units (fused)
2027
- sourceWallet.splitUnits( fusedTokenUnitIds, remainderWallet );
1967
+ sourceWallet.splitUnits(fusedTokenUnitIds, remainderWallet)
2028
1968
 
2029
1969
  // Set recipient new fused token unit
2030
- newTokenUnit.metas[ 'fusedTokenUnits' ] = sourceWallet.getTokenUnitsData();
2031
- recipientWallet.tokenUnits = [ newTokenUnit ];
1970
+ newTokenUnit.metas.fusedTokenUnits = sourceWallet.getTokenUnitsData()
1971
+ recipientWallet.tokenUnits = [newTokenUnit]
2032
1972
 
2033
1973
  // Create a molecule
2034
- let molecule = await this.createMolecule( { sourceWallet, remainderWallet } );
2035
- molecule.fuseToken( sourceWallet.tokenUnits, recipientWallet );
2036
- molecule.sign( {} );
2037
- molecule.check();
1974
+ const molecule = await this.createMolecule({
1975
+ sourceWallet,
1976
+ remainderWallet
1977
+ })
1978
+ molecule.fuseToken(sourceWallet.tokenUnits, recipientWallet)
1979
+ molecule.sign({
1980
+ bundle: this.getBundle()
1981
+ })
1982
+ molecule.check()
2038
1983
 
2039
1984
  // Create & execute a mutation
2040
- const query = await this.createMoleculeMutation( {
1985
+ const query = await this.createMoleculeMutation({
2041
1986
  mutationClass: MutationProposeMolecule,
2042
1987
  molecule
2043
- } );
2044
- return this.executeQuery( query );
1988
+ })
1989
+ return this.executeQuery(query)
2045
1990
  }
2046
1991
 
2047
-
2048
1992
  /**
2049
- * Request a guest auth token
2050
- *
2051
- * @param {string} cellSlug
2052
- * @param {boolean} encrypt
2053
- * @returns {Promise<ResponseRequestAuthorizationGuest>}
1993
+ * Requests a guest authentication token using the fingerprint of the user.
1994
+ * @param {Object} options - The options for the guest authentication token request.
1995
+ * @param {string} options.cellSlug - The slug of the cell to request the token for.
1996
+ * @param {boolean} options.encrypt - Indicates whether the session should be encrypted.
1997
+ * @returns {Promise<ResponseRequestAuthorizationGuest>} - A promise that resolves to the response of the guest authentication token request.
2054
1998
  */
2055
- async requestGuestAuthToken ( {
1999
+ async requestGuestAuthToken ({
2056
2000
  cellSlug,
2057
2001
  encrypt
2058
- } ) {
2059
- this.setCellSlug( cellSlug );
2002
+ }) {
2003
+ this.setCellSlug(cellSlug)
2060
2004
 
2061
2005
  // Create a wallet for encryption
2062
- const wallet = new Wallet( {
2063
- secret: generateSecret(),
2006
+ const wallet = new Wallet({
2007
+ secret: generateSecret(await this.getFingerprint()),
2064
2008
  token: 'AUTH'
2065
- } );
2009
+ })
2066
2010
 
2067
2011
  /**
2068
2012
  * @type {MutationRequestAuthorizationGuest}
2069
2013
  */
2070
- const query = await this.createQuery( MutationRequestAuthorizationGuest );
2014
+ const query = await this.createQuery(MutationRequestAuthorizationGuest)
2071
2015
 
2072
2016
  const variables = {
2073
2017
  cellSlug,
2074
2018
  pubkey: wallet.pubkey,
2075
2019
  encrypt
2076
- };
2020
+ }
2077
2021
 
2078
2022
  /**
2079
2023
  * @type {ResponseRequestAuthorizationGuest}
2080
2024
  */
2081
- const response = await query.execute( variables );
2025
+ const response = await query.execute({ variables })
2082
2026
 
2083
2027
  // Did the authorization molecule get accepted?
2084
- if ( response.success() ) {
2085
-
2028
+ if (response.success()) {
2086
2029
  // Create & set an auth token from the response data
2087
- const authToken = AuthToken.create( response.payload(), wallet );
2088
- this.setAuthToken( authToken );
2089
-
2030
+ const authToken = AuthToken.create(response.payload(), wallet)
2031
+ this.setAuthToken(authToken)
2090
2032
  } else {
2091
-
2092
- throw new AuthorizationRejectedException( `KnishIOClient::requestGuestAuthToken() - Authorization attempt rejected by ledger. Reason: ${ response.reason() }` );
2093
-
2033
+ throw new AuthorizationRejectedException(`KnishIOClient::requestGuestAuthToken() - Authorization attempt rejected by ledger. Reason: ${ response.reason() }`)
2094
2034
  }
2095
2035
 
2096
- return response;
2036
+ return response
2097
2037
  }
2098
2038
 
2099
-
2100
2039
  /**
2101
2040
  * Request a profile auth token
2102
2041
  *
@@ -2104,57 +2043,50 @@ export default class KnishIOClient {
2104
2043
  * @param encrypt
2105
2044
  * @returns {Promise<ResponseRequestAuthorization>}
2106
2045
  */
2107
- async requestProfileAuthToken ( {
2046
+ async requestProfileAuthToken ({
2108
2047
  secret,
2109
2048
  encrypt
2110
- } ) {
2111
- this.setSecret( secret );
2049
+ }) {
2050
+ this.setSecret(secret)
2112
2051
 
2113
2052
  // Generate a signing wallet
2114
- const wallet = new Wallet( {
2053
+ const wallet = new Wallet({
2115
2054
  secret,
2116
2055
  token: 'AUTH'
2117
- } );
2056
+ })
2118
2057
 
2119
2058
  // Create a wallet with a signing wallet
2120
- const molecule = await this.createMolecule( {
2059
+ const molecule = await this.createMolecule({
2121
2060
  secret,
2122
2061
  sourceWallet: wallet
2123
- } );
2062
+ })
2124
2063
 
2125
2064
  /**
2126
2065
  * @type {MutationRequestAuthorization}
2127
2066
  */
2128
- const query = await this.createMoleculeMutation( {
2067
+ const query = await this.createMoleculeMutation({
2129
2068
  mutationClass: MutationRequestAuthorization,
2130
2069
  molecule
2131
- } );
2132
-
2133
- query.fillMolecule( { meta: { encrypt: ( encrypt ? 'true' : 'false' ) } } );
2070
+ })
2134
2071
 
2072
+ query.fillMolecule({ meta: { encrypt: (encrypt ? 'true' : 'false') } })
2135
2073
  /**
2136
2074
  * @type {ResponseRequestAuthorization}
2137
2075
  */
2138
- const response = await query.execute( {} );
2139
-
2076
+ const response = await query.execute({})
2140
2077
 
2141
2078
  // Did the authorization molecule get accepted?
2142
- if ( response.success() ) {
2143
-
2079
+ if (response.success()) {
2144
2080
  // Create & set an auth token from the response data
2145
- const authToken = AuthToken.create( response.payload(), wallet );
2146
- this.setAuthToken( authToken );
2147
-
2081
+ const authToken = AuthToken.create(response.payload(), wallet)
2082
+ this.setAuthToken(authToken)
2148
2083
  } else {
2149
-
2150
- throw new AuthorizationRejectedException( `KnishIOClient::requestProfileAuthToken() - Authorization attempt rejected by ledger. Reason: ${ response.reason() }` );
2151
-
2084
+ throw new AuthorizationRejectedException(`KnishIOClient::requestProfileAuthToken() - Authorization attempt rejected by ledger. Reason: ${ response.reason() }`)
2152
2085
  }
2153
2086
 
2154
- return response;
2087
+ return response
2155
2088
  }
2156
2089
 
2157
-
2158
2090
  /**
2159
2091
  * Request an auth token (guest or profile)
2160
2092
  *
@@ -2164,97 +2096,112 @@ export default class KnishIOClient {
2164
2096
  * @param encrypt
2165
2097
  * @returns {Promise<ResponseRequestAuthorizationGuest|ResponseRequestAuthorization|null>}
2166
2098
  */
2167
- async requestAuthToken ( {
2099
+ async requestAuthToken ({
2168
2100
  secret = null,
2169
2101
  seed = null,
2170
2102
  cellSlug = null,
2171
2103
  encrypt = false
2172
- } ) {
2173
-
2104
+ }) {
2174
2105
  // SDK versions 2 and below do not utilize an authorization token
2175
- if ( this.$__serverSdkVersion < 3 ) {
2176
- if ( this.$__logging ) {
2177
- console.warn( 'KnishIOClient::authorize() - Server SDK version does not require an authorization...' );
2178
- }
2179
- return null;
2106
+ if (this.$__serverSdkVersion < 3) {
2107
+ this.log('warn', 'KnishIOClient::authorize() - Server SDK version does not require an authorization...')
2108
+ return null
2180
2109
  }
2181
2110
 
2182
2111
  // Generate a secret from the seed if it has been passed
2183
- if ( secret === null && seed ) {
2184
- secret = generateSecret( seed );
2112
+ if (secret === null && seed) {
2113
+ secret = generateSecret(seed)
2114
+ }
2115
+
2116
+ // Set cell slug if it has been passed
2117
+ if (cellSlug) {
2118
+ this.setCellSlug(cellSlug)
2185
2119
  }
2186
2120
 
2187
2121
  // Auth in process...
2188
- this.$__authInProcess = true;
2122
+ this.$__authInProcess = true
2189
2123
 
2190
2124
  // Auth token response
2191
- let response;
2125
+ let response
2192
2126
 
2193
2127
  // Authorized user
2194
- if ( secret ) {
2195
- response = await this.requestProfileAuthToken( {
2128
+ if (secret) {
2129
+ response = await this.requestProfileAuthToken({
2196
2130
  secret,
2197
2131
  encrypt
2198
- } );
2199
- }
2200
-
2201
- // Guest
2202
- else {
2203
- response = await this.requestGuestAuthToken( {
2132
+ })
2133
+ } else {
2134
+ // Guest
2135
+ response = await this.requestGuestAuthToken({
2204
2136
  cellSlug,
2205
2137
  encrypt
2206
- } );
2138
+ })
2207
2139
  }
2208
2140
 
2209
2141
  // Set auth token
2210
- if ( this.$__logging ) {
2211
- console.info( `KnishIOClient::authorize() - Successfully retrieved auth token ${ this.$__authToken.getToken() }...` );
2212
- }
2142
+ this.log('info', `KnishIOClient::authorize() - Successfully retrieved auth token ${ this.$__authToken.getToken() }...`)
2213
2143
 
2214
2144
  // Switch encryption mode if it has been changed
2215
- this.switchEncryption( encrypt );
2145
+ this.switchEncryption(encrypt)
2216
2146
 
2217
2147
  // Auth process is stopped
2218
- this.$__authInProcess = false;
2148
+ this.$__authInProcess = false
2219
2149
 
2220
2150
  // Return full response
2221
- return response;
2151
+ return response
2222
2152
  }
2223
2153
 
2224
-
2225
2154
  /**
2226
2155
  * Sets the auth token
2227
2156
  *
2228
2157
  * @param {AuthToken} authToken
2229
2158
  */
2230
- setAuthToken ( authToken ) {
2231
-
2159
+ setAuthToken (authToken) {
2232
2160
  // An empty auth token
2233
- if ( !authToken ) {
2234
- if ( this.$__logging ) {
2235
- console.info( 'KnishIOClient::setAuthToken() - authToken object is empty.' );
2236
- }
2237
- return;
2161
+ if (!authToken) {
2162
+ this.log('info', 'KnishIOClient::setAuthToken() - authToken object is empty.')
2163
+ return
2238
2164
  }
2239
2165
 
2240
2166
  // Save auth token object to global list
2241
- this.$__authTokenObjects[ this.uri() ] = authToken;
2167
+ this.$__authTokenObjects[this.getUri()] = authToken
2242
2168
 
2243
- // Set auth data to apollo client
2244
- this.client().setAuthData( authToken.getAuthData() );
2169
+ // Set auth data to GraphQL client
2170
+ this.client().setAuthData(authToken.getAuthData())
2245
2171
 
2246
2172
  // Save a full auth token object with expireAt key
2247
- this.$__authToken = authToken;
2173
+ this.$__authToken = authToken
2248
2174
  }
2249
2175
 
2250
-
2251
2176
  /**
2252
2177
  * Returns the current authorization token
2253
2178
  *
2254
2179
  * @return {AuthToken}
2255
2180
  */
2256
2181
  getAuthToken () {
2257
- return this.$__authToken;
2182
+ return this.$__authToken
2183
+ }
2184
+
2185
+ /**
2186
+ * Writes the specified message to the console.
2187
+ * @param {string} level
2188
+ * @param {string} message
2189
+ */
2190
+ log (level, message) {
2191
+ if (this.$__logging) {
2192
+ switch (level) {
2193
+ case 'info':
2194
+ console.info(message)
2195
+ break
2196
+ case 'warn':
2197
+ console.warn(message)
2198
+ break
2199
+ case 'error':
2200
+ console.error(message)
2201
+ break
2202
+ default:
2203
+ console.log(message)
2204
+ }
2205
+ }
2258
2206
  }
2259
-
2260
2207
  }