@wishknish/knishio-client-js 0.5.2 → 0.6.0

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 (138) hide show
  1. package/README.md +207 -274
  2. package/dist/client.iife.js +577 -0
  3. package/package.json +36 -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 +37 -46
  8. package/src/KnishIOClient.js +932 -985
  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/apollo/ApolloClientWrapper.js +143 -0
  54. package/src/libraries/apollo/CipherLink.js +116 -0
  55. package/src/libraries/apollo/Client.js +154 -0
  56. package/src/libraries/apollo/ErrorHandler.js +32 -0
  57. package/src/libraries/apollo/SubscriptionManager.js +60 -0
  58. package/src/libraries/apollo/operationUtils.js +26 -0
  59. package/src/libraries/array.js +50 -41
  60. package/src/libraries/crypto.js +20 -27
  61. package/src/libraries/strings.js +58 -91
  62. package/src/mutation/Mutation.js +44 -25
  63. package/src/mutation/MutationActiveSession.js +12 -12
  64. package/src/mutation/MutationClaimShadowWallet.js +15 -17
  65. package/src/mutation/MutationCreateIdentifier.js +11 -12
  66. package/src/mutation/MutationCreateMeta.js +11 -12
  67. package/src/mutation/MutationCreateRule.js +11 -12
  68. package/src/mutation/MutationCreateToken.js +18 -13
  69. package/src/mutation/MutationCreateWallet.js +9 -11
  70. package/src/mutation/MutationDepositBufferToken.js +7 -9
  71. package/src/mutation/MutationLinkIdentifier.js +12 -14
  72. package/src/mutation/MutationProposeMolecule.js +24 -25
  73. package/src/mutation/MutationRequestAuthorization.js +9 -10
  74. package/src/mutation/MutationRequestAuthorizationGuest.js +12 -15
  75. package/src/mutation/MutationRequestTokens.js +11 -14
  76. package/src/mutation/MutationTransferTokens.js +11 -14
  77. package/src/mutation/MutationWithdrawBufferToken.js +7 -10
  78. package/src/query/Query.js +62 -36
  79. package/src/query/QueryActiveSession.js +11 -13
  80. package/src/query/QueryAtom.js +75 -76
  81. package/src/query/QueryBalance.js +11 -12
  82. package/src/query/QueryBatch.js +17 -14
  83. package/src/query/QueryBatchHistory.js +16 -13
  84. package/src/query/QueryContinuId.js +13 -10
  85. package/src/query/QueryMetaType.js +45 -57
  86. package/src/query/QueryMetaTypeViaAtom.js +49 -57
  87. package/src/query/QueryPolicy.js +11 -12
  88. package/src/query/QueryToken.js +11 -13
  89. package/src/query/QueryUserActivity.js +11 -13
  90. package/src/query/QueryWalletBundle.js +15 -47
  91. package/src/query/QueryWalletList.js +15 -16
  92. package/src/response/Response.js +29 -34
  93. package/src/response/ResponseActiveSession.js +6 -6
  94. package/src/response/ResponseAtom.js +29 -30
  95. package/src/response/ResponseAuthorizationGuest.js +17 -18
  96. package/src/response/ResponseBalance.js +12 -13
  97. package/src/response/ResponseClaimShadowWallet.js +1 -1
  98. package/src/response/ResponseContinuId.js +21 -22
  99. package/src/response/ResponseCreateIdentifier.js +1 -1
  100. package/src/response/ResponseCreateMeta.js +1 -1
  101. package/src/response/ResponseCreateRule.js +1 -1
  102. package/src/response/ResponseCreateToken.js +1 -1
  103. package/src/response/ResponseCreateWallet.js +1 -1
  104. package/src/response/ResponseLinkIdentifier.js +9 -10
  105. package/src/response/ResponseMetaBatch.js +6 -8
  106. package/src/response/ResponseMetaType.js +19 -20
  107. package/src/response/ResponseMetaTypeViaAtom.js +19 -19
  108. package/src/response/ResponsePolicy.js +14 -15
  109. package/src/response/ResponseProposeMolecule.js +27 -30
  110. package/src/response/ResponseQueryActiveSession.js +20 -23
  111. package/src/response/ResponseQueryUserActivity.js +11 -12
  112. package/src/response/ResponseRequestAuthorization.js +11 -16
  113. package/src/response/ResponseRequestAuthorizationGuest.js +18 -21
  114. package/src/response/ResponseRequestTokens.js +1 -1
  115. package/src/response/ResponseTransferTokens.js +8 -9
  116. package/src/response/ResponseWalletBundle.js +16 -17
  117. package/src/response/ResponseWalletList.js +44 -47
  118. package/src/subscribe/ActiveSessionSubscribe.js +5 -6
  119. package/src/subscribe/ActiveWalletSubscribe.js +5 -6
  120. package/src/subscribe/CreateMoleculeSubscribe.js +5 -5
  121. package/src/subscribe/Subscribe.js +26 -26
  122. package/src/subscribe/WalletStatusSubscribe.js +5 -6
  123. package/src/versions/HashAtom.js +78 -0
  124. package/src/versions/Version4.js +34 -0
  125. package/src/versions/index.js +5 -0
  126. package/dist/client.umd.js +0 -453
  127. package/src/httpClient/ApolloClient.js +0 -245
  128. package/src/libraries/ApolloLink/CipherLink.js +0 -117
  129. package/src/libraries/ApolloLink/Client.js +0 -231
  130. package/src/libraries/ApolloLink/PusherLink.js +0 -234
  131. package/src/libraries/ApolloLink/handler.js +0 -106
  132. package/src/libraries/Base58.js +0 -71
  133. package/src/libraries/Base64.js +0 -40
  134. package/src/libraries/BaseX.js +0 -91
  135. package/src/libraries/Soda.js +0 -93
  136. package/src/query/QueryMetaInstance.js +0 -99
  137. package/src/test/Test.js +0 -670
  138. package/src/test/TestTokenUnit.js +0 -340
@@ -0,0 +1,154 @@
1
+ import {
2
+ ApolloClient,
3
+ InMemoryCache,
4
+ from,
5
+ split
6
+ } from '@apollo/client/core'
7
+ import { onError } from '@apollo/client/link/error'
8
+ import { getMainDefinition } from '@apollo/client/utilities'
9
+ import { createHttpLink } from '@apollo/client/link/http'
10
+ import { setContext } from '@apollo/client/link/context'
11
+ import { GraphQLWsLink } from '@apollo/client/link/subscriptions'
12
+ import { createClient } from 'graphql-ws'
13
+ import fetch from 'isomorphic-fetch'
14
+ import { errorHandler } from './errorHandler'
15
+ import CipherLink from './CipherLink'
16
+
17
+ /**
18
+ * Custom Apollo Client implementation
19
+ * Extends ApolloClient with additional functionality
20
+ */
21
+ class Client extends ApolloClient {
22
+ /**
23
+ * @param {Object} config - Configuration object
24
+ * @param {string} config.serverUri - URI of the GraphQL server
25
+ * @param {Object|null} config.soketi - WebSocket configuration (optional)
26
+ * @param {boolean} config.encrypt - Whether to use encryption (default: false)
27
+ */
28
+ constructor ({ serverUri, soketi = null, encrypt = false }) {
29
+ // Create HTTP link
30
+ const httpLink = createHttpLink({
31
+ uri: serverUri,
32
+ fetch
33
+ })
34
+
35
+ // Initialize empty auth token
36
+ const authToken = ''
37
+
38
+ // Create auth link to add token to headers
39
+ const authLink = setContext((_, { headers }) => ({
40
+ headers: {
41
+ ...headers,
42
+ 'X-Auth-Token': authToken
43
+ }
44
+ }))
45
+
46
+ // Create error handling link
47
+ const errorLink = onError(errorHandler)
48
+
49
+ // Combine links
50
+ let link = from([authLink, errorLink, httpLink])
51
+
52
+ // Add encryption link if enabled
53
+ let cipherLink
54
+ if (encrypt) {
55
+ cipherLink = new CipherLink()
56
+ link = from([cipherLink, link])
57
+ }
58
+
59
+ // Add WebSocket link if configured
60
+ let wsLink
61
+ if (soketi && soketi.socketUri) {
62
+ wsLink = new GraphQLWsLink(createClient({
63
+ url: soketi.socketUri,
64
+ connectionParams: () => ({
65
+ authToken
66
+ })
67
+ }))
68
+
69
+ // Split queries between WebSocket and HTTP
70
+ link = split(
71
+ ({ query }) => {
72
+ const definition = getMainDefinition(query)
73
+ return (
74
+ definition.kind === 'OperationDefinition' &&
75
+ definition.operation === 'subscription'
76
+ )
77
+ },
78
+ wsLink,
79
+ link
80
+ )
81
+ }
82
+
83
+ // Call parent constructor with configured options
84
+ super({
85
+ link,
86
+ cache: new InMemoryCache(),
87
+ defaultOptions: {
88
+ watchQuery: {
89
+ fetchPolicy: 'no-cache',
90
+ errorPolicy: 'ignore'
91
+ },
92
+ query: {
93
+ fetchPolicy: 'no-cache',
94
+ errorPolicy: 'all'
95
+ },
96
+ mutate: {
97
+ fetchPolicy: 'no-cache',
98
+ errorPolicy: 'all'
99
+ }
100
+ }
101
+ })
102
+
103
+ // Store configuration and links
104
+ this.serverUri = serverUri
105
+ this.soketi = soketi
106
+ this.authToken = authToken
107
+ this.pubkey = null
108
+ this.wallet = null
109
+ this.cipherLink = cipherLink
110
+ this.wsLink = wsLink
111
+ }
112
+
113
+ /**
114
+ * Set authentication data
115
+ * @param {Object} authData - Authentication data
116
+ * @param {string} authData.token - Auth token
117
+ * @param {string} authData.pubkey - Public key
118
+ * @param {Object} authData.wallet - Wallet object
119
+ */
120
+ setAuthData ({ token, pubkey, wallet }) {
121
+ this.authToken = token
122
+ this.pubkey = pubkey
123
+ this.wallet = wallet
124
+
125
+ if (this.cipherLink) {
126
+ this.cipherLink.setWallet(wallet)
127
+ this.cipherLink.setPubKey(pubkey)
128
+ }
129
+
130
+ if (this.wsLink) {
131
+ this.wsLink.client.connectionParams = () => ({
132
+ authToken: this.authToken
133
+ })
134
+ }
135
+ }
136
+
137
+ /**
138
+ * Disconnect the WebSocket connection
139
+ */
140
+ socketDisconnect () {
141
+ if (this.wsLink) {
142
+ this.wsLink.client.dispose()
143
+ }
144
+ }
145
+
146
+ // Getter methods
147
+ getAuthToken () { return this.authToken }
148
+ getPubKey () { return this.pubkey }
149
+ getWallet () { return this.wallet }
150
+ getServerUri () { return this.serverUri }
151
+ getSocketUri () { return this.soketi ? this.soketi.socketUri : null }
152
+ }
153
+
154
+ export default Client
@@ -0,0 +1,32 @@
1
+ /**
2
+ * Handle GraphQL and network errors
3
+ * @param {Object} errorInfo - Error information object
4
+ */
5
+ export function errorHandler ({
6
+ graphQLErrors,
7
+ networkError,
8
+ operation,
9
+ forward,
10
+ response
11
+ }) {
12
+ if (graphQLErrors) {
13
+ graphQLErrors.forEach(({ message, debugMessage, locations, path }) =>
14
+ console.error(
15
+ `[GraphQL error]: ${message}`,
16
+ `\n Message : ${debugMessage}`,
17
+ `\n Path : ${path}`,
18
+ `\n Location: ${JSON.stringify(locations)}`
19
+ )
20
+ )
21
+ }
22
+
23
+ if (networkError) {
24
+ const { name, statusCode, result = {} } = networkError
25
+ console.error(`[Network error]: ${name}, status code: ${statusCode}`)
26
+ // TODO: Implement automatic retry logic for network errors
27
+ // This could involve using an exponential backoff strategy
28
+ }
29
+
30
+ // You can add custom error handling logic here
31
+ // For example, you could dispatch actions to update the app state on certain errors
32
+ }
@@ -0,0 +1,60 @@
1
+ /**
2
+ * Manages GraphQL subscriptions
3
+ */
4
+ class SubscriptionManager {
5
+ /**
6
+ * @param {Client} client - Apollo Client instance
7
+ */
8
+ constructor (client) {
9
+ this.$__client = client
10
+ this.$__subscribers = {}
11
+ }
12
+
13
+ /**
14
+ * Set the client instance
15
+ * @param {Client} client - Apollo Client instance
16
+ */
17
+ setClient (client) {
18
+ this.$__client = client
19
+ }
20
+
21
+ /**
22
+ * Create a new subscription
23
+ * @param {Object} request - Subscription request
24
+ * @param {Function} closure - Callback function for subscription updates
25
+ * @returns {Object} Subscription object
26
+ */
27
+ subscribe (request, closure) {
28
+ const subscription = this.$__client.subscribe(request).subscribe(closure)
29
+ this.$__subscribers[request.operationName] = subscription
30
+ return subscription
31
+ }
32
+
33
+ /**
34
+ * Unsubscribe from a specific subscription
35
+ * @param {string} operationName - Name of the operation to unsubscribe from
36
+ */
37
+ unsubscribe (operationName) {
38
+ if (this.$__subscribers[operationName]) {
39
+ this.$__subscribers[operationName].unsubscribe()
40
+ this.$__client.unsubscribeFromChannel(operationName)
41
+ delete this.$__subscribers[operationName]
42
+ }
43
+ }
44
+
45
+ /**
46
+ * Unsubscribe from all subscriptions
47
+ */
48
+ unsubscribeAll () {
49
+ Object.keys(this.$__subscribers).forEach(this.unsubscribe.bind(this))
50
+ }
51
+
52
+ /**
53
+ * Clear all subscriptions without unsubscribing
54
+ */
55
+ clear () {
56
+ this.$__subscribers = {}
57
+ }
58
+ }
59
+
60
+ export default SubscriptionManager
@@ -0,0 +1,26 @@
1
+ /**
2
+ * Extract the operation name from a GraphQL operation
3
+ * @param {Object} operation - GraphQL operation object
4
+ * @returns {string} Operation name
5
+ */
6
+ export function operationName (operation) {
7
+ const operationDefinition = operation.query.definitions.find(
8
+ definitionNode => definitionNode.kind === 'OperationDefinition'
9
+ )
10
+ const fieldNode = operationDefinition.selectionSet.selections.find(
11
+ definitionNode => definitionNode.kind === 'Field'
12
+ )
13
+ return fieldNode.name.value
14
+ }
15
+
16
+ /**
17
+ * Extract the operation type from a GraphQL operation
18
+ * @param {Object} operation - GraphQL operation object
19
+ * @returns {string} Operation type (query, mutation, subscription)
20
+ */
21
+ export function operationType (operation) {
22
+ const operationDefinition = operation.query.definitions.find(
23
+ definitionNode => definitionNode.kind === 'OperationDefinition'
24
+ )
25
+ return operationDefinition.operation
26
+ }
@@ -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
  }