@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,13 +45,12 @@ 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 ResponseProposeMolecule from './ResponseProposeMolecule';
48
+ import ResponseProposeMolecule from './ResponseProposeMolecule'
49
49
 
50
50
  /**
51
51
  * Response for token transfer queries
52
52
  */
53
53
  export default class ResponseTransferTokens extends ResponseProposeMolecule {
54
-
55
54
  /**
56
55
  * Returns result of the transfer
57
56
  *
@@ -59,14 +58,14 @@ export default class ResponseTransferTokens extends ResponseProposeMolecule {
59
58
  */
60
59
  payload () {
61
60
  const result = {
62
- reason: null,
63
- status: null
64
- },
65
- data = this.data();
61
+ reason: null,
62
+ status: null
63
+ }
64
+ const data = this.data()
66
65
 
67
- result.reason = typeof data.reason === 'undefined' ? 'Invalid response from server' : data.reason;
68
- result.status = typeof data.status === 'undefined' ? 'rejected' : data.status;
66
+ result.reason = typeof data.reason === 'undefined' ? 'Invalid response from server' : data.reason
67
+ result.status = typeof data.status === 'undefined' ? 'rejected' : data.status
69
68
 
70
- return result;
69
+ return result
71
70
  }
72
71
  }
@@ -45,30 +45,29 @@ 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 Query from '../query/Query';
49
- import Response from './Response';
50
- import Meta from '../Meta';
48
+ import Query from '../query/Query'
49
+ import Response from './Response'
50
+ import Meta from '../Meta'
51
51
 
52
52
  /**
53
53
  * Response for Wallet Bundle query
54
54
  */
55
55
  export default class ResponseWalletBundle extends Response {
56
-
57
56
  /**
58
57
  * Class constructor
59
58
  *
60
59
  * @param {Query} query
61
60
  * @param {object} json
62
61
  */
63
- constructor ( {
62
+ constructor ({
64
63
  query,
65
64
  json
66
- } ) {
67
- super( {
65
+ }) {
66
+ super({
68
67
  query,
69
68
  json,
70
69
  dataKey: 'data.WalletBundle'
71
- } );
70
+ })
72
71
  }
73
72
 
74
73
  /**
@@ -77,19 +76,19 @@ export default class ResponseWalletBundle extends Response {
77
76
  * @return {{}|null}
78
77
  */
79
78
  payload () {
80
- const bundleData = this.data();
79
+ const bundleData = this.data()
81
80
 
82
- if ( !bundleData || bundleData.length === 0 ) {
83
- return null;
81
+ if (!bundleData || bundleData.length === 0) {
82
+ return null
84
83
  }
85
84
 
86
- const aggregate = {};
85
+ const aggregate = {}
87
86
 
88
- bundleData.forEach( bundle => {
89
- bundle.metas = Meta.aggregateMeta( bundle.metas );
90
- aggregate[ bundle.bundleHash ] = bundle;
91
- } );
87
+ bundleData.forEach(bundle => {
88
+ bundle.metas = Meta.aggregateMeta(bundle.metas)
89
+ aggregate[bundle.bundleHash] = bundle
90
+ })
92
91
 
93
- return aggregate;
92
+ return aggregate
94
93
  }
95
94
  }
@@ -45,31 +45,30 @@ 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 Response from './Response';
49
- import Query from '../query/Query';
50
- import Wallet from '../Wallet';
51
- import TokenUnit from '../TokenUnit';
48
+ import Query from '../query/Query'
49
+ import Response from './Response'
50
+ import Wallet from '../Wallet'
51
+ import TokenUnit from '../TokenUnit'
52
52
 
53
53
  /**
54
54
  * Response for Wallet List query
55
55
  */
56
56
  export default class ResponseWalletList extends Response {
57
-
58
57
  /**
59
58
  * Class constructor
60
59
  *
61
60
  * @param {Query} query
62
61
  * @param {object} json
63
62
  */
64
- constructor ( {
63
+ constructor ({
65
64
  query,
66
65
  json
67
- } ) {
68
- super( {
66
+ }) {
67
+ super({
69
68
  query,
70
69
  json,
71
70
  dataKey: 'data.Wallet'
72
- } );
71
+ })
73
72
  }
74
73
 
75
74
  /**
@@ -79,56 +78,55 @@ export default class ResponseWalletList extends Response {
79
78
  * @param {string|null} secret
80
79
  * @return {Wallet}
81
80
  */
82
- static toClientWallet ( {
81
+ static toClientWallet ({
83
82
  data,
84
83
  secret = null
85
- } ) {
86
- let wallet;
84
+ }) {
85
+ let wallet
87
86
 
88
- if ( data.position === null || typeof data.position === 'undefined' ) {
89
- wallet = Wallet.create( {
90
- secretOrBundle: data.bundleHash,
87
+ if (data.position === null || typeof data.position === 'undefined') {
88
+ wallet = Wallet.create({
89
+ bundle: data.bundleHash,
91
90
  token: data.tokenSlug,
92
91
  batchId: data.batchId,
93
92
  characters: data.characters
94
- } );
93
+ })
95
94
  } else {
96
- wallet = new Wallet( {
95
+ wallet = new Wallet({
97
96
  secret,
98
97
  token: data.tokenSlug,
99
98
  position: data.position,
100
99
  batchId: data.batchId,
101
100
  characters: data.characters
102
- } );
103
- wallet.address = data.address;
104
- wallet.bundle = data.bundleHash;
101
+ })
102
+ wallet.address = data.address
103
+ wallet.bundle = data.bundleHash
105
104
  }
106
105
 
107
- if ( data.token ) {
108
- wallet.tokenName = data.token.name;
109
- wallet.tokenAmount = data.token.amount;
110
- wallet.tokenSupply = data.token.supply;
111
- wallet.tokenFungibility = data.token.fungibility;
106
+ if (data.token) {
107
+ wallet.tokenName = data.token.name
108
+ wallet.tokenAmount = data.token.amount
109
+ wallet.tokenSupply = data.token.supply
110
+ wallet.tokenFungibility = data.token.fungibility
112
111
  }
113
112
 
114
- if ( data.tokenUnits.length ) {
115
- for ( let tokenUnitData of data.tokenUnits ) {
116
- wallet.tokenUnits.push( TokenUnit.createFromGraphQL( tokenUnitData ) );
113
+ if (data.tokenUnits.length) {
114
+ for (const tokenUnitData of data.tokenUnits) {
115
+ wallet.tokenUnits.push(TokenUnit.createFromGraphQL(tokenUnitData))
117
116
  }
118
117
  }
119
118
 
120
- if ( data.tradeRates.length ) {
121
- for ( let tradeRate of data.tradeRates ) {
122
- wallet.tradeRates[ tradeRate[ 'tokenSlug' ] ] = tradeRate[ 'amount' ];
119
+ if (data.tradeRates.length) {
120
+ for (const tradeRate of data.tradeRates) {
121
+ wallet.tradeRates[tradeRate.tokenSlug] = tradeRate.amount
123
122
  }
124
123
  }
125
124
 
126
- wallet.molecules = data.molecules;
127
- wallet.balance = Number( data.amount );
128
- wallet.pubkey = data.pubkey;
129
- wallet.createdAt = data.createdAt;
125
+ wallet.balance = Number(data.amount)
126
+ wallet.pubkey = data.pubkey
127
+ wallet.createdAt = data.createdAt
130
128
 
131
- return wallet;
129
+ return wallet
132
130
  }
133
131
 
134
132
  /**
@@ -137,24 +135,23 @@ export default class ResponseWalletList extends Response {
137
135
  * @param secret
138
136
  * @return {null|[Wallet]}
139
137
  */
140
- getWallets ( secret = null ) {
141
-
142
- const list = this.data();
138
+ getWallets (secret = null) {
139
+ const list = this.data()
143
140
 
144
- if ( !list ) {
145
- return null;
141
+ if (!list) {
142
+ return null
146
143
  }
147
144
 
148
- const wallets = [];
145
+ const wallets = []
149
146
 
150
- for ( let data of list ) {
151
- wallets.push( ResponseWalletList.toClientWallet( {
147
+ for (const data of list) {
148
+ wallets.push(ResponseWalletList.toClientWallet({
152
149
  data,
153
150
  secret
154
- } ) );
151
+ }))
155
152
  }
156
153
 
157
- return wallets;
154
+ return wallets
158
155
  }
159
156
 
160
157
  /**
@@ -163,6 +160,6 @@ export default class ResponseWalletList extends Response {
163
160
  * @return {null|[Wallet]}
164
161
  */
165
162
  payload () {
166
- return this.getWallets();
163
+ return this.getWallets()
167
164
  }
168
165
  }
@@ -1,10 +1,9 @@
1
- import Subscribe from './Subscribe';
2
- import { gql } from '@apollo/client/core';
3
-
1
+ import Subscribe from './Subscribe'
2
+ import { gql } from '@urql/core'
4
3
 
5
4
  export default class ActiveSessionSubscribe extends Subscribe {
6
- constructor ( apolloClient ) {
7
- super( apolloClient );
5
+ constructor (graphQLClient) {
6
+ super(graphQLClient)
8
7
  this.$__subscribe = gql`
9
8
  subscription onActiveUser ( $metaType: String!, $metaId: String! ) {
10
9
  ActiveUser( metaType: $metaType, metaId: $metaId ) {
@@ -15,6 +14,6 @@ export default class ActiveSessionSubscribe extends Subscribe {
15
14
  createdAt,
16
15
  updatedAt
17
16
  }
18
- }`;
17
+ }`
19
18
  }
20
19
  }
@@ -1,10 +1,9 @@
1
- import Subscribe from './Subscribe';
2
- import { gql } from '@apollo/client/core';
3
-
1
+ import Subscribe from './Subscribe'
2
+ import { gql } from '@urql/core'
4
3
 
5
4
  export default class ActiveWalletSubscribe extends Subscribe {
6
- constructor ( apolloClient ) {
7
- super( apolloClient );
5
+ constructor (graphQLClient) {
6
+ super(graphQLClient)
8
7
  this.$__subscribe = gql`
9
8
  subscription onActiveWallet ( $bundle: String! ) {
10
9
  ActiveWallet( bundle: $bundle ) {
@@ -43,6 +42,6 @@ export default class ActiveWalletSubscribe extends Subscribe {
43
42
  }
44
43
  }
45
44
  }
46
- `;
45
+ `
47
46
  }
48
47
  }
@@ -1,9 +1,9 @@
1
- import Subscribe from './Subscribe';
2
- import { gql } from '@apollo/client/core';
1
+ import Subscribe from './Subscribe'
2
+ import { gql } from '@urql/core'
3
3
 
4
4
  export default class CreateMoleculeSubscribe extends Subscribe {
5
- constructor ( apolloClient ) {
6
- super( apolloClient );
5
+ constructor (graphQLClient) {
6
+ super(graphQLClient)
7
7
  this.$__subscribe = gql`
8
8
  subscription onCreateMolecule ( $bundle: String! ) {
9
9
  CreateMolecule( bundle: $bundle ) {
@@ -49,6 +49,6 @@ export default class CreateMoleculeSubscribe extends Subscribe {
49
49
  }
50
50
  }
51
51
  }
52
- `;
52
+ `
53
53
  }
54
54
  }
@@ -1,14 +1,14 @@
1
- import CodeException from '../exception/CodeException';
1
+ import CodeException from '../exception/CodeException'
2
2
 
3
3
  export default class Subscribe {
4
4
  /**
5
5
  *
6
- * @param {ApolloClient} apolloClient
6
+ * @param {UrqlClientWrapper} graphQLClient
7
7
  */
8
- constructor ( apolloClient ) {
9
- this.client = apolloClient;
10
- this.$__variables = null;
11
- this.$__subscribe = null;
8
+ constructor (graphQLClient) {
9
+ this.client = graphQLClient
10
+ this.$__variables = null
11
+ this.$__subscribe = null
12
12
  }
13
13
 
14
14
  /**
@@ -17,27 +17,27 @@ export default class Subscribe {
17
17
  * @param {{}} variables
18
18
  * @returns {{variables: (Object|null), fetchPolicy: string, query: null}}
19
19
  */
20
- createSubscribe ( {
20
+ createSubscribe ({
21
21
  variables = null
22
- } ) {
23
- this.$__variables = this.compiledVariables( variables );
22
+ }) {
23
+ this.$__variables = this.compiledVariables(variables)
24
24
 
25
25
  // Uri is a required parameter
26
- let uri = this.uri();
26
+ const uri = this.uri()
27
27
 
28
- if ( !uri ) {
29
- throw new CodeException( 'Subscribe::createSubscribe() - Node URI was not initialized for this client instance!' );
28
+ if (!uri) {
29
+ throw new CodeException('Subscribe::createSubscribe() - Node URI was not initialized for this client instance!')
30
30
  }
31
31
 
32
- if ( this.$__subscribe === null ) {
33
- throw new CodeException( 'Subscribe::createSubscribe() - GraphQL subscription was not initialized!' );
32
+ if (this.$__subscribe === null) {
33
+ throw new CodeException('Subscribe::createSubscribe() - GraphQL subscription was not initialized!')
34
34
  }
35
35
 
36
36
  return {
37
37
  query: this.$__subscribe,
38
38
  variables: this.variables(),
39
39
  fetchPolicy: 'no-cache'
40
- };
40
+ }
41
41
  }
42
42
 
43
43
  /**
@@ -47,19 +47,19 @@ export default class Subscribe {
47
47
  * @param {function} closure
48
48
  * @return {string}
49
49
  */
50
- async execute ( {
50
+ async execute ({
51
51
  variables = null,
52
52
  closure
53
- } ) {
54
- if ( !closure ) {
55
- throw new CodeException( `${ this.constructor.name }::execute() - closure parameter is required!` );
53
+ }) {
54
+ if (!closure) {
55
+ throw new CodeException(`${ this.constructor.name }::execute() - closure parameter is required!`)
56
56
  }
57
57
 
58
- this.$__request = this.createSubscribe( {
58
+ this.$__request = this.createSubscribe({
59
59
  variables
60
- } );
60
+ })
61
61
 
62
- return this.client.subscribe( this.$__request, closure );
62
+ return this.client.subscribe(this.$__request, closure)
63
63
  }
64
64
 
65
65
  /**
@@ -68,8 +68,8 @@ export default class Subscribe {
68
68
  * @param variables
69
69
  * @return {object}
70
70
  */
71
- compiledVariables ( variables = null ) {
72
- return variables || {};
71
+ compiledVariables (variables = null) {
72
+ return variables || {}
73
73
  }
74
74
 
75
75
  /**
@@ -78,7 +78,7 @@ export default class Subscribe {
78
78
  * @return {string}
79
79
  */
80
80
  uri () {
81
- return this.client.getUri();
81
+ return this.client.getUri()
82
82
  }
83
83
 
84
84
  /**
@@ -87,6 +87,6 @@ export default class Subscribe {
87
87
  * @return {object|null}
88
88
  */
89
89
  variables () {
90
- return this.$__variables;
90
+ return this.$__variables
91
91
  }
92
92
  }
@@ -1,10 +1,9 @@
1
- import Subscribe from './Subscribe';
2
- import { gql } from '@apollo/client/core';
3
-
1
+ import Subscribe from './Subscribe'
2
+ import { gql } from '@urql/core'
4
3
 
5
4
  export default class WalletStatusSubscribe extends Subscribe {
6
- constructor ( apolloClient ) {
7
- super( apolloClient );
5
+ constructor (graphQLClient) {
6
+ super(graphQLClient)
8
7
  this.$__subscribe = gql`
9
8
  subscription onWalletStatus ( $bundle: String!, $token: String! ) {
10
9
  WalletStatus( bundle: $bundle, token: $token ) {
@@ -14,6 +13,6 @@ export default class WalletStatusSubscribe extends Subscribe {
14
13
  balance,
15
14
  }
16
15
  }
17
- `;
16
+ `
18
17
  }
19
18
  }
@@ -0,0 +1,78 @@
1
+ export default class HashAtom {
2
+ /**
3
+ *
4
+ * @param {Atom} atom
5
+ */
6
+ static create (atom) {
7
+ const parameters = {}
8
+
9
+ for (const key of Object.keys(atom)) {
10
+ if (Object.prototype.hasOwnProperty.call(atom, key)) {
11
+ parameters[key] = atom[key]
12
+ }
13
+ }
14
+
15
+ return new this(parameters)
16
+ }
17
+
18
+ /**
19
+ *
20
+ * @param {Object|Array} object
21
+ * @returns {Object|Array[]}
22
+ */
23
+ static structure (object) {
24
+ switch (Object.prototype.toString.call(object)) {
25
+ case '[object Array]': {
26
+ const result = []
27
+ for (const key in object) {
28
+ result.push(HashAtom.isStructure(object[key]) ? HashAtom.structure(object[key]) : object[key])
29
+ }
30
+
31
+ return result
32
+ }
33
+
34
+ case '[object Object]': {
35
+ const result = []
36
+ const keys = Object.keys(object).sort((first, second) => {
37
+ if (first === second) {
38
+ return 0
39
+ }
40
+ return (first < second) ? -1 : 1
41
+ })
42
+
43
+ for (const key of keys) {
44
+ if (Object.prototype.hasOwnProperty.call(object, key)) {
45
+ const item = {}
46
+ item[key] = HashAtom.isStructure(object[key]) ? HashAtom.structure(object[key]) : object[key]
47
+ result.push(item)
48
+ }
49
+ }
50
+
51
+ if (result.length > 0) {
52
+ return result
53
+ }
54
+
55
+ break
56
+ }
57
+ }
58
+
59
+ return object
60
+ }
61
+
62
+ /**
63
+ *
64
+ * @param {*} structure
65
+ * @returns {boolean}
66
+ */
67
+ static isStructure (structure) {
68
+ return ['[object Object]', '[object Array]'].includes(Object.prototype.toString.call(structure))
69
+ }
70
+
71
+ /**
72
+ *
73
+ * @returns {Object[]}
74
+ */
75
+ view () {
76
+ return HashAtom.structure(this)
77
+ }
78
+ }
@@ -0,0 +1,34 @@
1
+ import HashAtom from './HashAtom'
2
+
3
+ export default class Version4 extends HashAtom {
4
+ constructor ({
5
+ position = null,
6
+ walletAddress = null,
7
+ isotope = null,
8
+ token = null,
9
+ value = null,
10
+ batchId = null,
11
+ metaType = null,
12
+ metaId = null,
13
+ meta = null,
14
+ index = null,
15
+ createdAt = null,
16
+ version = null
17
+ }) {
18
+ super()
19
+ this.position = position
20
+ this.walletAddress = walletAddress
21
+ this.isotope = isotope
22
+ this.token = token
23
+ this.value = value
24
+ this.batchId = batchId
25
+
26
+ this.metaType = metaType
27
+ this.metaId = metaId
28
+ this.meta = meta
29
+
30
+ this.index = index
31
+ this.createdAt = createdAt
32
+ this.version = version
33
+ }
34
+ }
@@ -0,0 +1,5 @@
1
+ import Version4 from './Version4'
2
+
3
+ export default {
4
+ 4: Version4
5
+ }