@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,18 +1,17 @@
1
1
  // Value determines by min sql decimal precision
2
- const multiplier = 10 ** 18;
2
+ const multiplier = 10 ** 18
3
3
 
4
4
  export default class Decimal {
5
-
6
5
  /**
7
6
  * @param {number} value
8
7
  * @return {number}
9
8
  */
10
- static val ( value ) {
11
- if ( Math.abs( value * multiplier ) < 1 ) {
12
- return 0.0;
9
+ static val (value) {
10
+ if (Math.abs(value * multiplier) < 1) {
11
+ return 0.0
13
12
  }
14
13
 
15
- return value;
14
+ return value
16
15
  }
17
16
 
18
17
  /**
@@ -21,19 +20,17 @@ export default class Decimal {
21
20
  * @param {boolean} debug
22
21
  * @return {number}
23
22
  */
24
- static cmp ( value1, value2, debug = false ) {
25
-
26
- const val1 = Decimal.val( value1 ) * multiplier,
27
- val2 = Decimal.val( value2 ) * multiplier;
23
+ static cmp (value1, value2, debug = false) {
24
+ const val1 = Decimal.val(value1) * multiplier
25
+ const val2 = Decimal.val(value2) * multiplier
28
26
 
29
27
  // Equal
30
- if ( Math.abs( val1 - val2 ) < 1 ) {
31
- return 0;
28
+ if (Math.abs(val1 - val2) < 1) {
29
+ return 0
32
30
  }
33
31
 
34
32
  // Greater or smaller
35
- return ( val1 > val2 ) ? 1 : -1;
36
-
33
+ return (val1 > val2) ? 1 : -1
37
34
  }
38
35
 
39
36
  /**
@@ -41,8 +38,7 @@ export default class Decimal {
41
38
  * @param {number} value2
42
39
  * @return {boolean}
43
40
  */
44
- static equal ( value1, value2 ) {
45
- return ( Decimal.cmp( value1, value2 ) === 0 );
41
+ static equal (value1, value2) {
42
+ return (Decimal.cmp(value1, value2) === 0)
46
43
  }
47
-
48
44
  }
@@ -1,81 +1,107 @@
1
1
  /**
2
- *
2
+ * Utility class for accessing nested object properties using dot notation
3
3
  */
4
4
  export default class Dot {
5
-
6
5
  /**
7
- * @param {object|array} obj
8
- * @param {string} keys
6
+ * Initialize the Dot utility with the given object and key path
7
+ * @param {object|array} obj - The object or array to traverse
8
+ * @param {string} keys - The dot-notated string of keys
9
9
  * @private
10
10
  */
11
- static __init ( obj, keys ) {
12
-
13
- this.arr = [];
14
- this.key = null;
15
-
16
- this.arr = String( keys ).split( '.' );
17
- this.key = this.arr.shift();
18
-
19
- const numberKey = Number( this.key );
20
-
21
- if ( Number.isInteger( numberKey ) ) {
22
- this.key = numberKey;
11
+ static __init (obj, keys) {
12
+ this.arr = String(keys).split('.')
13
+ this.key = this.arr.shift()
14
+
15
+ // Convert to number if the key is a valid integer
16
+ const numberKey = Number(this.key)
17
+ if (Number.isInteger(numberKey)) {
18
+ this.key = numberKey
23
19
  }
24
20
 
25
- this.__nextKey = this.arr.length;
26
- this.__next = this.__tic( obj );
21
+ this.__nextKey = this.arr.length
22
+ this.__next = this.__tic(obj)
27
23
  }
28
24
 
29
25
  /**
30
- * @param {object|array} obj
31
- * @return {boolean}
26
+ * Check if the current key exists in the object
27
+ * @param {object|array} obj - The object or array to check
28
+ * @return {boolean} - Whether the key exists
32
29
  * @private
33
30
  */
34
- static __tic ( obj ) {
35
-
36
- if ( !Array.isArray( obj ) && !( obj instanceof Object ) ) {
37
- return false;
31
+ static __tic (obj) {
32
+ if (!Array.isArray(obj) && !(obj instanceof Object)) {
33
+ return false
38
34
  }
39
35
 
40
- return typeof obj[ this.key ] !== 'undefined';
36
+ return typeof obj[this.key] !== 'undefined'
41
37
  }
42
38
 
43
39
  /**
44
- * @param {object|array} obj
45
- * @param {string} keys
46
- * @return {boolean}
40
+ * Check if a nested property exists in an object using dot notation
41
+ * @param {object|array} obj - The object or array to search
42
+ * @param {string} keys - The path to the property, using dot notation
43
+ * @return {boolean} - True if the property exists, false otherwise
47
44
  */
48
- static has ( obj, keys ) {
45
+ static has (obj, keys) {
46
+ this.__init(obj, keys)
49
47
 
50
- this.__init( obj, keys );
51
-
52
- if ( !this.__next ) {
53
- return false;
48
+ if (!this.__next) {
49
+ return false
54
50
  }
55
- if ( this.__nextKey === 0 ) {
56
- return true;
51
+ if (this.__nextKey === 0) {
52
+ return true
57
53
  }
58
54
 
59
- return this.has( obj[ this.key ], this.arr.join( '.' ) );
55
+ return this.has(obj[this.key], this.arr.join('.'))
60
56
  }
61
57
 
62
58
  /**
63
- * @param {object|array} obj
64
- * @param {string} keys
65
- * @param {*} def
66
- * @return {*}
59
+ * Get a nested property from an object using dot notation
60
+ * @param {object|array} obj - The object or array to search
61
+ * @param {string} keys - The path to the property, using dot notation
62
+ * @param {*} [def=null] - The default value to return if the property is not found
63
+ * @return {*} - The value of the property, or the default value if not found
67
64
  */
68
- static get ( obj, keys, def = null ) {
69
-
70
- this.__init( obj, keys );
65
+ static get (obj, keys, def = null) {
66
+ this.__init(obj, keys)
71
67
 
72
- if ( !this.__next ) {
73
- return def;
68
+ if (!this.__next) {
69
+ return def
74
70
  }
75
- if ( this.__nextKey === 0 ) {
76
- return obj[ this.key ];
71
+ if (this.__nextKey === 0) {
72
+ return obj[this.key]
77
73
  }
78
74
 
79
- return this.get( obj[ this.key ], this.arr.join( '.' ), def );
75
+ return this.get(obj[this.key], this.arr.join('.'), def)
76
+ }
77
+
78
+ /**
79
+ * Set a nested property in an object using dot notation
80
+ * @param {object|array} obj - The object or array to modify
81
+ * @param {string} keys - The path to the property, using dot notation
82
+ * @param {*} value - The value to set
83
+ * @return {object|array} - The modified object or array
84
+ */
85
+ static set (obj, keys, value) {
86
+ const parts = keys.split('.')
87
+ let current = obj
88
+ const lastIndex = parts.length - 1
89
+
90
+ for (let i = 0; i < lastIndex; i++) {
91
+ const key = parts[i]
92
+ const numberKey = Number(key)
93
+ const useNumberKey = Number.isInteger(numberKey)
94
+
95
+ if (!(useNumberKey ? numberKey : key in current)) {
96
+ current[useNumberKey ? numberKey : key] = parts[i + 1].match(/^\d+$/) ? [] : {}
97
+ }
98
+ current = current[useNumberKey ? numberKey : key]
99
+ }
100
+
101
+ const lastKey = parts[lastIndex]
102
+ const lastNumberKey = Number(lastKey)
103
+ current[Number.isInteger(lastNumberKey) ? lastNumberKey : lastKey] = value
104
+
105
+ return obj
80
106
  }
81
107
  }
@@ -1,8 +1,12 @@
1
1
  /**
2
2
  * Create Uint8Array buffers from hexadecimal strings, and vice versa.
3
3
  */
4
- export default class Hex {
5
4
 
5
+ if (typeof self === 'undefined') {
6
+ global.self = global
7
+ }
8
+
9
+ export default class Hex {
6
10
  /**
7
11
  * Converts the given buffer to a string containing its hexadecimal representation.
8
12
  *
@@ -19,58 +23,52 @@ export default class Hex {
19
23
  * @param {object} options
20
24
  * @return {string}
21
25
  */
22
- static toHex ( arr, options ) {
23
-
26
+ static toHex (arr, options) {
24
27
  /**
25
28
  * @param {number} val
26
29
  * @param {boolean} uppercase
27
30
  * @return {*}
28
31
  */
29
- const numberToHex = ( val, uppercase ) => {
30
-
31
- const set = uppercase ?
32
- [ '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' ] :
33
- [ '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' ];
34
-
35
- return set[ Math.floor( val / 16 ) ] + set[ val % 16 ];
32
+ const numberToHex = (val, uppercase) => {
33
+ const set = uppercase
34
+ ? ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F']
35
+ : ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f']
36
36
 
37
+ return set[Math.floor(val / 16)] + set[val % 16]
38
+ }
39
+ const opts = Object.assign(
40
+ {
41
+ grouping: 0,
42
+ rowlength: 0,
43
+ uppercase: false
37
44
  },
38
- opts = Object.assign(
39
- {
40
- grouping: 0,
41
- rowlength: 0,
42
- uppercase: false
43
- },
44
- options || {}
45
- );
46
-
47
- let str = '',
48
- group = 0,
49
- column = 0;
45
+ options || {}
46
+ )
50
47
 
51
- for ( let i = 0; i < arr.length; ++i ) {
48
+ let str = ''
49
+ let group = 0
50
+ let column = 0
52
51
 
53
- str += numberToHex( arr[ i ], opts.uppercase );
52
+ for (let i = 0; i < arr.length; ++i) {
53
+ str += numberToHex(arr[i], opts.uppercase)
54
54
 
55
- if ( i === arr.length - 1 ) {
56
- break;
55
+ if (i === arr.length - 1) {
56
+ break
57
57
  }
58
58
 
59
- if ( opts.grouping > 0 && ++group === opts.grouping ) {
60
-
61
- group = 0;
62
-
63
- if ( opts.rowlength > 0 && ++column === opts.rowlength ) {
59
+ if (opts.grouping > 0 && ++group === opts.grouping) {
60
+ group = 0
64
61
 
65
- column = 0;
66
- str += '\n';
62
+ if (opts.rowlength > 0 && ++column === opts.rowlength) {
63
+ column = 0
64
+ str += '\n'
67
65
  } else {
68
- str += ' ';
66
+ str += ' '
69
67
  }
70
68
  }
71
69
  }
72
70
 
73
- return str;
71
+ return str
74
72
  }
75
73
 
76
74
  /**
@@ -84,35 +82,32 @@ export default class Hex {
84
82
  * @param {string} str
85
83
  * @return {Uint8Array}
86
84
  */
87
- static toUint8Array ( str ) {
85
+ static toUint8Array (str) {
86
+ let target = str.toLowerCase().replace(/\s/g, '')
88
87
 
89
- let target = str.toLowerCase().replace( /\s/g, '' );
90
-
91
- if ( target.length % 2 === 1 ) {
92
- target = `0${ target }`;
88
+ if (target.length % 2 === 1) {
89
+ target = `0${ target }`
93
90
  }
94
91
 
95
- let buffer = new Uint8Array( Math.floor( target.length / 2 ) ),
96
- curr = -1;
97
-
98
- for ( let i = 0; i < target.length; ++i ) {
92
+ const buffer = new Uint8Array(Math.floor(target.length / 2))
93
+ let curr = -1
99
94
 
100
- let c = target[ i ],
101
- val = [ '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' ].indexOf( c );
95
+ for (let i = 0; i < target.length; ++i) {
96
+ const c = target[i]
97
+ const val = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'].indexOf(c)
102
98
 
103
- if ( val === -1 ) {
104
- throw Error( 'unexpected character' );
99
+ if (val === -1) {
100
+ throw Error('unexpected character')
105
101
  }
106
102
 
107
- if ( curr === -1 ) {
108
- curr = 16 * val;
103
+ if (curr === -1) {
104
+ curr = 16 * val
109
105
  } else {
110
-
111
- buffer[ Math.floor( i / 2 ) ] = curr + val;
112
- curr = -1;
106
+ buffer[Math.floor(i / 2)] = curr + val
107
+ curr = -1
113
108
  }
114
109
  }
115
110
 
116
- return buffer;
111
+ return buffer
117
112
  }
118
113
  }
@@ -5,69 +5,78 @@
5
5
  * @param {number} size
6
6
  * @return {array}
7
7
  */
8
- export function chunkArray ( arr, size ) {
9
-
10
- if ( !arr.length ) {
11
- return [];
8
+ export function chunkArray (arr, size) {
9
+ if (!arr.length) {
10
+ return []
12
11
  }
13
12
 
14
- return [ arr.slice( 0, size ) ].concat( chunkArray( arr.slice( size ), size ) );
13
+ return [arr.slice(0, size)].concat(chunkArray(arr.slice(size), size))
15
14
  }
16
15
 
17
16
  export function deepCloning (
18
17
  o // The only argument passed by user: object to clone
19
18
  , h // Cache (organized as array: [key,value,key,value,...])
20
19
  ) {
21
- let i,
22
- r,
23
- x // Property indexer, result, temporary variable
24
- ,
25
- t = [ Array, Date, Number, String, Boolean ] // Types to treat in a special way
26
- ,
27
- s = Object.prototype.toString; // Shortcut to Object.prototype.toString
28
- h = h || []; // If cache is not created yet, create it!
29
- for ( i = 0; i < h.length; i += 2 ) // Search cache for our object
30
- if ( o === h[ i ] )
31
- r = h[ i + 1 ];
32
- if ( !r && o && typeof o == 'object' ) { // Clone o if it is uncached object and not null
33
- r = {}; // Default result template: plain hash
34
- for ( i = 0; i < t.length; i++ ) // To handle multiframe environment, search for type by
35
- if ( s.call( o ) === s.call( // comparing Object.prototype.toString's of our object
36
- x = new t[ i ]( o ) ) ) // and new object x created with the constructor t[i]
37
- // Notice that it will create new Date(o), new String(o)
38
- // which is good and new Array(o) which is bad
39
- r = i ? x : []; // If i==0, t==Array. We need to recreate it. Else use x
40
- h.push( o, r ); // Add object to cache before (!) making recursive call
41
- for ( i in o ) // Just copy properties recursively
42
- if ( h.hasOwnProperty.call( o, i ) ) // As o might have key 'hasOwnProperty', use something
43
- r[ i ] = deepCloning( o[ i ], h ); // we defined right instead
20
+ let i
21
+ let r
22
+ let x // Property indexer, result, temporary variable
23
+
24
+ const t = [Array, Date, Number, String, Boolean] // Types to treat in a special way
25
+
26
+ const s = Object.prototype.toString // Shortcut to Object.prototype.toString
27
+ h = h || [] // If cache is not created yet, create it!
28
+ // Search cache for our object
29
+ for (i = 0; i < h.length; i += 2) {
30
+ if (o === h[i]) {
31
+ r = h[i + 1]
32
+ }
33
+ }
34
+ // Clone o if it is uncached object and not null
35
+ if (!r && o && typeof o === 'object') {
36
+ r = {} // Default result template: plain hash
37
+ // To handle multiframe environment, search for type by
38
+ for (i = 0; i < t.length; i++) {
39
+ // comparing Object.prototype.toString's of our object
40
+ // and new object x created with the constructor t[i]
41
+ // Notice that it will create new Date(o), new String(o)
42
+ // which is good and new Array(o) which is bad
43
+ if (s.call(o) === s.call(x = new t[i](o))) {
44
+ r = i ? x : []
45
+ }
46
+ } // If i==0, t==Array. We need to recreate it. Else use x
47
+ h.push(o, r) // Add object to cache before (!) making recursive call
48
+ // Just copy properties recursively
49
+ for (i in o) {
50
+ // As o might have key 'hasOwnProperty', use something
51
+ if (h.hasOwnProperty.call(o, i)) {
52
+ r[i] = deepCloning(o[i], h)
53
+ }
54
+ } // we defined right instead
44
55
  }
45
- return r || o; // Return r if it was found in cache or built in if(){}
56
+ return r || o // Return r if it was found in cache or built in if(){}
46
57
  }
47
58
 
48
59
  /**
49
60
  * @param arrays
50
61
  * @returns {*[]}
51
62
  */
52
- export function diff ( ...arrays ) {
63
+ export function diff (...arrays) {
64
+ return [].concat(...arrays.map((arr, i) => {
65
+ const others = arrays.slice(0)
53
66
 
54
- return [].concat( ...arrays.map( ( arr, i ) => {
67
+ others.splice(i, 1)
55
68
 
56
- const others = arrays.slice( 0 );
69
+ const unique = [...new Set([].concat(...others))]
57
70
 
58
- others.splice( i, 1 );
59
-
60
- const unique = [ ...new Set( [].concat( ...others ) ) ];
61
-
62
- return arr.filter( item => !unique.includes( item ) );
63
- } ) );
71
+ return arr.filter(item => !unique.includes(item))
72
+ }))
64
73
  }
65
74
 
66
- /**
75
+ /**
67
76
  *
68
77
  * @param arrays
69
78
  * @return {*[]}
70
79
  */
71
- export function intersect ( ...arrays ) {
72
- return arrays.reduce( ( first, second ) => first.filter( item => second.includes( item ) ) );
80
+ export function intersect (...arrays) {
81
+ return arrays.reduce((first, second) => first.filter(item => second.includes(item)))
73
82
  }
@@ -45,8 +45,8 @@ 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 { shake256 } from 'js-sha3';
49
- import { randomString } from './strings';
48
+ import { randomString } from './strings'
49
+ import JsSHA from 'jssha'
50
50
 
51
51
  /**
52
52
  * Generates a secret based on an optional seed
@@ -55,17 +55,14 @@ import { randomString } from './strings';
55
55
  * @param length
56
56
  * @return {string|*}
57
57
  */
58
- export function generateSecret ( seed = null, length = 2048 ) {
59
-
60
- console.info( `Crypto::generateSecret() - Computing new secret${ seed ? ' from existing seed' : '' }...` );
61
-
62
- if ( seed ) {
63
- const sponge = shake256.create( length * 2 );
64
- sponge.update( seed );
65
- return sponge.hex();
66
- }
67
- else {
68
- return randomString( length );
58
+ export function generateSecret (seed = null, length = 2048) {
59
+ // console.info(`Crypto::generateSecret() - Computing new secret${ seed ? ' from existing seed' : '' }...`)
60
+ if (seed) {
61
+ const sponge = new JsSHA('SHAKE256', 'TEXT')
62
+ sponge.update(seed)
63
+ return sponge.getHash('HEX', { outputLen: length * 2 })
64
+ } else {
65
+ return randomString(length)
69
66
  }
70
67
  }
71
68
 
@@ -73,16 +70,13 @@ export function generateSecret ( seed = null, length = 2048 ) {
73
70
  * Hashes the user secret to produce a bundle hash
74
71
  *
75
72
  * @param {string} secret
73
+ * @param {string|null} source
76
74
  * @return {string}
77
75
  */
78
- export function generateBundleHash ( secret ) {
79
-
80
- console.info( 'Crypto::generateBundleHash() - Computing wallet bundle from secret...' );
81
-
82
- const sponge = shake256.create( 256 );
83
- sponge.update( secret );
84
- return sponge.hex();
85
-
76
+ export function generateBundleHash (secret, source = null) {
77
+ const sponge = new JsSHA('SHAKE256', 'TEXT')
78
+ sponge.update(secret)
79
+ return sponge.getHash('HEX', { outputLen: 256 })
86
80
  }
87
81
 
88
82
  /**
@@ -93,14 +87,13 @@ export function generateBundleHash ( secret ) {
93
87
  *
94
88
  * @return {string}
95
89
  */
96
- export function generateBatchId ( {
90
+ export function generateBatchId ({
97
91
  molecularHash = null,
98
92
  index = null
99
- } ) {
100
-
101
- if ( molecularHash !== null && index !== null ) {
102
- return generateBundleHash( String( molecularHash ) + String( index ) );
93
+ }) {
94
+ if (molecularHash !== null && index !== null) {
95
+ return generateBundleHash(String(molecularHash) + String(index), 'generateBatchId')
103
96
  }
104
97
 
105
- return randomString( 64 );
98
+ return randomString(64)
106
99
  }