@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
@@ -1,340 +0,0 @@
1
- /*
2
- (
3
- (/(
4
- (//(
5
- (///(
6
- (/////(
7
- (//////( )
8
- (////////( (/)
9
- (////////( (///)
10
- (//////////( (////)
11
- (//////////( (//////)
12
- (////////////( (///////)
13
- (/////////////( (/////////)
14
- (//////////////( (///////////)
15
- (///////////////( (/////////////)
16
- (////////////////( (//////////////)
17
- ((((((((((((((((((( (((((((((((((((
18
- ((((((((((((((((((( ((((((((((((((
19
- ((((((((((((((((((( ((((((((((((((
20
- (((((((((((((((((((( (((((((((((((
21
- (((((((((((((((((((( ((((((((((((
22
- ((((((((((((((((((( ((((((((((((
23
- ((((((((((((((((((( ((((((((((
24
- ((((((((((((((((((/ (((((((((
25
- (((((((((((((((((( ((((((((
26
- ((((((((((((((((( (((((((
27
- (((((((((((((((((( (((((
28
- ################# ##
29
- ################ #
30
- ################# ##
31
- %################ ###
32
- ###############( ####
33
- ############### ####
34
- ############### ######
35
- %#############( (#######
36
- %############# #########
37
- ############( ##########
38
- ########### #############
39
- ######### ##############
40
- %######
41
-
42
- Powered by Knish.IO: Connecting a Decentralized World
43
-
44
- Please visit https://github.com/WishKnish/KnishIO-Client-JS for information.
45
-
46
- License: https://github.com/WishKnish/KnishIO-Client-JS/blob/master/LICENSE
47
- */
48
- import KnishIOClient from '../KnishIOClient';
49
- import Dot from '../libraries/Dot';
50
- import {
51
- generateBundleHash,
52
- generateSecret
53
- } from '../libraries/crypto';
54
- import ResponseMolecule from '../response/ResponseProposeMolecule';
55
- import TokenUnit from '../TokenUnit';
56
-
57
- /*
58
-
59
- import Test from '@wishknish/knishio-client-js/src/test/Test';
60
- import { KNISHIO_SETTINGS, } from 'src/libraries/constants/knishio';
61
-
62
- // Run all test
63
- await TestTokenUnit.run( KNISHIO_SETTINGS.serverUriConfig );
64
-
65
- */
66
-
67
- export default class TestTokenUnit {
68
-
69
- /**
70
- * Run all
71
- */
72
- static async run ( uris ) {
73
- for ( let uriIndex in uris ) {
74
- let test = new TestTokenUnit( uris[ uriIndex ] );
75
- await test.testAll();
76
- }
77
- }
78
-
79
- /**
80
- *
81
- * @param graphqlUrl
82
- * @param encrypt
83
- */
84
- constructor ( graphqlUrl, encrypt = false ) {
85
- this.encrypt = encrypt;
86
- this.secrets = [ generateSecret(), generateSecret() ];
87
- this.tokenSlugs = [ 'UTNFUNGUNIT' ];
88
- this.graphqlUrl = graphqlUrl;
89
- console.log( `---------- GraphQL URI: ${ this.graphqlUrl }` );
90
-
91
- this.clients = {};
92
- this.tokenUnits = [
93
- [ 'unit_id_1', 'unit_name_1', {url: "test1.com"} ],
94
- [ 'unit_id_2', 'unit_name_2', {url: "test2.com"} ],
95
- [ 'unit_id_3', 'unit_name_3', {url: "test3.com"} ],
96
- [ 'unit_id_4', 'unit_name_4', {url: "test4.com"} ],
97
- [ 'unit_id_5', 'unit_name_5', {url: "test5.com"} ],
98
- [ 'unit_id_6', 'unit_name_6', {url: "test6.com"} ],
99
- ];
100
- }
101
-
102
-
103
- /**
104
- * Test all KnishIOClient functions
105
- */
106
- async testAll () {
107
- console.info( `Executing test for: ${ this.graphqlUrl }...` );
108
-
109
- await this.client( this.secrets[ 0 ] );
110
- await this.client( this.secrets[ 1 ] );
111
-
112
- await this.testCreateToken();
113
- await this.queryWalletsOutput();
114
-
115
- await this.testTransferToken1();
116
- await this.queryWalletsOutput();
117
-
118
- await this.testTransferToken2();
119
- await this.queryWalletsOutput();
120
-
121
- await this.testClaimShadowWallet();
122
- await this.queryWalletsOutput();
123
-
124
- await this.testTransferTokenBack1();
125
- await this.queryWalletsOutput();
126
-
127
- await this.testTransferTokenBack2();
128
- await this.queryWalletsOutput();
129
- }
130
-
131
- /**
132
- * @throws \Exception
133
- */
134
- async testCreateToken () {
135
-
136
- let responses = {};
137
-
138
- // Regular stackable token
139
- let client = await this.client( this.secrets[ 0 ] );
140
-
141
- // --------- UNITABLE TOKENS ----------
142
-
143
- // Create stackable unit token
144
- responses[ 0 ] = await client.createToken( {
145
- token: this.tokenSlugs[ 0 ],
146
- units: this.tokenUnits,
147
- meta: {
148
- name: this.tokenSlugs[ 0 ],
149
- supply: 'replenishable',
150
- fungibility: 'nonfungible'
151
- }
152
- } );
153
- this.checkResponse( responses[ 0 ], 'testCreateToken.0' );
154
- }
155
-
156
-
157
- /**
158
- *
159
- * @return {Promise<void>}
160
- */
161
- async testTransferToken1 () {
162
-
163
- let bundleHash = generateBundleHash( this.secrets[ 1 ] );
164
-
165
- let client = await this.client( this.secrets[ 0 ] );
166
- let response = await client.transferToken( {
167
- bundleHash,
168
- token: this.tokenSlugs[ 0 ],
169
- units: [ 'unit_id_1', 'unit_id_2' ],
170
- } );
171
- this.checkResponse( response, 'testTransferUnitToken.1' );
172
- }
173
-
174
- /**
175
- *
176
- * @return {Promise<void>}
177
- */
178
- async testTransferToken2 () {
179
-
180
- let bundleHash = generateBundleHash( this.secrets[ 1 ] );
181
-
182
- let client = await this.client( this.secrets[ 0 ] );
183
- let response = await client.transferToken( {
184
- bundleHash,
185
- token: this.tokenSlugs[ 0 ],
186
- units: [ 'unit_id_3', 'unit_id_4' ],
187
- } );
188
- this.checkResponse( response, 'testTransferUnitToken.2' );
189
- }
190
-
191
- /**
192
- *
193
- */
194
- async testClaimShadowWallet () {
195
- let client = await this.client( this.secrets[ 1 ] );
196
-
197
- let response = await client.claimShadowWallet( {
198
- token: this.tokenSlugs[ 0 ]
199
- } );
200
- this.checkResponse( response, 'testClaimShadowWallet' );
201
- }
202
-
203
-
204
- /**
205
- *
206
- * @return {Promise<void>}
207
- */
208
- async testTransferTokenBack1 () {
209
-
210
- let bundleHash = generateBundleHash( this.secrets[ 0 ] );
211
-
212
- let client = await this.client( this.secrets[ 1 ] );
213
- let response = await client.transferToken( {
214
- bundleHash,
215
- token: this.tokenSlugs[ 0 ],
216
- units: [ 'unit_id_1', ],
217
- } );
218
- this.checkResponse( response, 'testTransferBackToken.1' );
219
- }
220
-
221
- /**
222
- *
223
- * @return {Promise<void>}
224
- */
225
- async testTransferTokenBack2 () {
226
-
227
- let bundleHash = generateBundleHash( this.secrets[ 0 ] );
228
-
229
- let client = await this.client( this.secrets[ 1 ] );
230
- let response = await client.transferToken( {
231
- bundleHash,
232
- token: this.tokenSlugs[ 0 ],
233
- units: [ 'unit_id_3' ],
234
- } );
235
- this.checkResponse( response, 'testTransferBackToken.2' );
236
- }
237
-
238
-
239
- /**
240
- *
241
- */
242
- async queryWalletsOutput() {
243
- await this.queryWallet( this.secrets[ 0 ], 'Token creation wallet' );
244
- await this.queryWallet( this.secrets[ 1 ], 'Recipient wallet' );
245
- }
246
-
247
-
248
- /**
249
- *
250
- */
251
- async queryWallet ( secret, title ) {
252
- let client = await this.client( secret );
253
- let response = await client.queryWallets( {
254
- token: this.tokenSlugs[ 0 ]
255
- } );
256
-
257
- let outputData = 'Wallet not found.';
258
- if ( response[ 0 ] ) {
259
- outputData = response[ 0 ].tokenUnits;
260
- }
261
- console.warn( `--- Query wallet: ${ title }: `, outputData );
262
- }
263
-
264
-
265
- /**
266
- * Get a client for each secret
267
- *
268
- * @param secret
269
- * @param cellSlug
270
- * @returns {Promise<*>}
271
- */
272
- async client ( secret, cellSlug = 'unit_test' ) {
273
-
274
- // Create new client
275
- if ( !this.clients[ secret ] ) {
276
-
277
- // Create a client
278
- this.clients[ secret ] = new KnishIOClient( {
279
- uri: this.graphqlUrl,
280
- logging: true
281
- } );
282
-
283
- // Auth the client
284
- await this.clients[ secret ]
285
- .requestAuthToken( {
286
- secret,
287
- encrypt: this.encrypt,
288
- cellSlug
289
- } );
290
- if ( !this.clients[ secret ].getAuthToken() ) {
291
- console.log( 'Error with authorize - get an empty response.' );
292
- }
293
- }
294
-
295
- // Return the client by secret
296
- return this.clients[ secret ];
297
- }
298
-
299
-
300
- /**
301
- * Check a response
302
- * @param response
303
- * @param key
304
- */
305
- checkResponse ( response, key ) {
306
-
307
- console.log( ` ############### ${ key } ###############` );
308
- console.log( response );
309
-
310
- // Check molecule response
311
- if ( response instanceof ResponseMolecule ) {
312
- if ( !response.success() ) {
313
- this.debug( response );
314
- }
315
- console.assert( response.success(), response );
316
- }
317
-
318
- // Default response
319
- else {
320
- this.debug( response );
321
- }
322
- }
323
-
324
-
325
- /**
326
- * Debug output
327
- * @param response
328
- */
329
- debug ( response ) {
330
-
331
- // Reason data on the top of the output
332
- if ( response.data && Dot.get( response.data() || {}, 'reason' ) ) {
333
- console.log( response.data().reason );
334
- } else {
335
- console.log( response );
336
- }
337
-
338
- }
339
-
340
- }