@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.
- package/README.md +207 -274
- package/dist/client.iife.js +533 -0
- package/package.json +37 -79
- package/src/.babelrc +0 -22
- package/src/Atom.js +171 -132
- package/src/AtomMeta.js +76 -50
- package/src/AuthToken.js +38 -47
- package/src/KnishIOClient.js +934 -987
- package/src/Meta.js +15 -17
- package/src/Molecule.js +423 -494
- package/src/PolicyMeta.js +32 -41
- package/src/TokenUnit.js +30 -32
- package/src/Wallet.js +275 -265
- package/src/exception/AtomIndexException.js +4 -8
- package/src/exception/AtomsMissingException.js +4 -6
- package/src/exception/AuthorizationRejectedException.js +4 -5
- package/src/exception/BalanceInsufficientException.js +4 -8
- package/src/exception/BaseException.js +6 -8
- package/src/exception/BatchIdException.js +5 -7
- package/src/exception/CodeException.js +4 -8
- package/src/{libraries/ApolloLink/HttpLink.js → exception/DecryptionKeyException.js} +12 -15
- package/src/exception/InvalidResponseException.js +4 -5
- package/src/exception/MetaMissingException.js +4 -6
- package/src/exception/MolecularHashMismatchException.js +4 -6
- package/src/exception/MolecularHashMissingException.js +4 -5
- package/src/exception/NegativeAmountException.js +4 -5
- package/src/exception/PolicyInvalidException.js +4 -4
- package/src/exception/SignatureMalformedException.js +4 -5
- package/src/exception/SignatureMismatchException.js +4 -5
- package/src/exception/StackableUnitAmountException.js +4 -5
- package/src/exception/StackableUnitDecimalsException.js +4 -5
- package/src/exception/TransferBalanceException.js +4 -5
- package/src/exception/TransferMalformedException.js +4 -5
- package/src/exception/TransferMismatchedException.js +4 -5
- package/src/exception/TransferRemainderException.js +4 -5
- package/src/exception/TransferToSelfException.js +4 -5
- package/src/exception/TransferUnbalancedException.js +4 -5
- package/src/exception/UnauthenticatedException.js +4 -5
- package/src/{libraries/ApolloLink/AuthLink.js → exception/WalletCredentialException.js} +12 -40
- package/src/exception/WalletShadowException.js +4 -5
- package/src/exception/WrongTokenTypeException.js +4 -5
- package/src/exception/index.js +26 -26
- package/src/index.js +8 -10
- package/src/instance/Rules/Callback.js +91 -93
- package/src/instance/Rules/Condition.js +21 -23
- package/src/instance/Rules/Meta.js +13 -14
- package/src/instance/Rules/Rule.js +39 -43
- package/src/instance/Rules/exception/RuleArgumentException.js +4 -4
- package/src/libraries/CheckMolecule.js +253 -232
- package/src/libraries/Decimal.js +13 -17
- package/src/libraries/Dot.js +74 -48
- package/src/libraries/Hex.js +49 -54
- package/src/libraries/array.js +50 -41
- package/src/libraries/crypto.js +20 -27
- package/src/libraries/strings.js +58 -91
- package/src/libraries/urql/UrqlClientWrapper.js +166 -0
- package/src/mutation/Mutation.js +44 -25
- package/src/mutation/MutationActiveSession.js +12 -12
- package/src/mutation/MutationClaimShadowWallet.js +15 -17
- package/src/mutation/MutationCreateIdentifier.js +11 -12
- package/src/mutation/MutationCreateMeta.js +11 -12
- package/src/mutation/MutationCreateRule.js +11 -12
- package/src/mutation/MutationCreateToken.js +18 -13
- package/src/mutation/MutationCreateWallet.js +9 -11
- package/src/mutation/MutationDepositBufferToken.js +7 -9
- package/src/mutation/MutationLinkIdentifier.js +12 -14
- package/src/mutation/MutationProposeMolecule.js +24 -25
- package/src/mutation/MutationRequestAuthorization.js +9 -10
- package/src/mutation/MutationRequestAuthorizationGuest.js +12 -15
- package/src/mutation/MutationRequestTokens.js +11 -14
- package/src/mutation/MutationTransferTokens.js +11 -14
- package/src/mutation/MutationWithdrawBufferToken.js +7 -10
- package/src/query/Query.js +62 -36
- package/src/query/QueryActiveSession.js +11 -13
- package/src/query/QueryAtom.js +75 -76
- package/src/query/QueryBalance.js +11 -12
- package/src/query/QueryBatch.js +17 -14
- package/src/query/QueryBatchHistory.js +16 -13
- package/src/query/QueryContinuId.js +13 -10
- package/src/query/QueryMetaType.js +45 -57
- package/src/query/QueryMetaTypeViaAtom.js +49 -57
- package/src/query/QueryPolicy.js +11 -12
- package/src/query/QueryToken.js +11 -13
- package/src/query/QueryUserActivity.js +11 -13
- package/src/query/QueryWalletBundle.js +15 -47
- package/src/query/QueryWalletList.js +15 -16
- package/src/response/Response.js +29 -34
- package/src/response/ResponseActiveSession.js +6 -6
- package/src/response/ResponseAtom.js +29 -30
- package/src/response/ResponseAuthorizationGuest.js +17 -18
- package/src/response/ResponseBalance.js +12 -13
- package/src/response/ResponseClaimShadowWallet.js +1 -1
- package/src/response/ResponseContinuId.js +21 -22
- package/src/response/ResponseCreateIdentifier.js +1 -1
- package/src/response/ResponseCreateMeta.js +1 -1
- package/src/response/ResponseCreateRule.js +1 -1
- package/src/response/ResponseCreateToken.js +1 -1
- package/src/response/ResponseCreateWallet.js +1 -1
- package/src/response/ResponseLinkIdentifier.js +9 -10
- package/src/response/ResponseMetaBatch.js +6 -8
- package/src/response/ResponseMetaType.js +19 -20
- package/src/response/ResponseMetaTypeViaAtom.js +19 -19
- package/src/response/ResponsePolicy.js +14 -15
- package/src/response/ResponseProposeMolecule.js +27 -30
- package/src/response/ResponseQueryActiveSession.js +20 -23
- package/src/response/ResponseQueryUserActivity.js +11 -12
- package/src/response/ResponseRequestAuthorization.js +11 -16
- package/src/response/ResponseRequestAuthorizationGuest.js +18 -21
- package/src/response/ResponseRequestTokens.js +1 -1
- package/src/response/ResponseTransferTokens.js +8 -9
- package/src/response/ResponseWalletBundle.js +16 -17
- package/src/response/ResponseWalletList.js +44 -47
- package/src/subscribe/ActiveSessionSubscribe.js +5 -6
- package/src/subscribe/ActiveWalletSubscribe.js +5 -6
- package/src/subscribe/CreateMoleculeSubscribe.js +5 -5
- package/src/subscribe/Subscribe.js +26 -26
- package/src/subscribe/WalletStatusSubscribe.js +5 -6
- package/src/versions/HashAtom.js +78 -0
- package/src/versions/Version4.js +34 -0
- package/src/versions/index.js +5 -0
- package/dist/client.umd.js +0 -453
- package/src/httpClient/ApolloClient.js +0 -245
- package/src/libraries/ApolloLink/CipherLink.js +0 -117
- package/src/libraries/ApolloLink/Client.js +0 -231
- package/src/libraries/ApolloLink/PusherLink.js +0 -234
- package/src/libraries/ApolloLink/handler.js +0 -106
- package/src/libraries/Base58.js +0 -71
- package/src/libraries/Base64.js +0 -40
- package/src/libraries/BaseX.js +0 -91
- package/src/libraries/Soda.js +0 -93
- package/src/query/QueryMetaInstance.js +0 -99
- package/src/test/Test.js +0 -670
- package/src/test/TestTokenUnit.js +0 -340
package/src/AtomMeta.js
CHANGED
|
@@ -46,22 +46,21 @@ Please visit https://github.com/WishKnish/KnishIO-Client-JS for information.
|
|
|
46
46
|
License: https://github.com/WishKnish/KnishIO-Client-JS/blob/master/LICENSE
|
|
47
47
|
*/
|
|
48
48
|
|
|
49
|
-
import PolicyMeta from './PolicyMeta'
|
|
49
|
+
import PolicyMeta from './PolicyMeta'
|
|
50
50
|
|
|
51
|
-
const USE_META_CONTEXT = false
|
|
52
|
-
const DEFAULT_META_CONTEXT = 'https://www.schema.org'
|
|
51
|
+
const USE_META_CONTEXT = false
|
|
52
|
+
const DEFAULT_META_CONTEXT = 'https://www.schema.org'
|
|
53
53
|
|
|
54
54
|
/**
|
|
55
55
|
*
|
|
56
56
|
*/
|
|
57
57
|
export default class AtomMeta {
|
|
58
|
-
|
|
59
58
|
/**
|
|
60
59
|
*
|
|
61
60
|
* @param meta
|
|
62
61
|
*/
|
|
63
|
-
constructor(
|
|
64
|
-
this.meta = meta
|
|
62
|
+
constructor (meta = {}) {
|
|
63
|
+
this.meta = meta
|
|
65
64
|
}
|
|
66
65
|
|
|
67
66
|
/**
|
|
@@ -69,9 +68,9 @@ export default class AtomMeta {
|
|
|
69
68
|
* @param meta
|
|
70
69
|
* @returns {AtomMeta}
|
|
71
70
|
*/
|
|
72
|
-
merge(
|
|
73
|
-
this.meta = Object.assign(
|
|
74
|
-
return this
|
|
71
|
+
merge (meta) {
|
|
72
|
+
this.meta = Object.assign(this.meta, meta)
|
|
73
|
+
return this
|
|
75
74
|
}
|
|
76
75
|
|
|
77
76
|
/**
|
|
@@ -79,84 +78,111 @@ export default class AtomMeta {
|
|
|
79
78
|
* @param context
|
|
80
79
|
* @returns {AtomMeta}
|
|
81
80
|
*/
|
|
82
|
-
addContext(
|
|
83
|
-
|
|
81
|
+
addContext (context = null) {
|
|
84
82
|
// Add context key if it is enabled
|
|
85
|
-
if (
|
|
86
|
-
this.merge(
|
|
83
|
+
if (USE_META_CONTEXT) {
|
|
84
|
+
this.merge({ context: context || DEFAULT_META_CONTEXT })
|
|
87
85
|
}
|
|
88
86
|
|
|
89
|
-
return this
|
|
87
|
+
return this
|
|
90
88
|
}
|
|
91
89
|
|
|
92
90
|
/**
|
|
93
91
|
*
|
|
94
|
-
* @param wallet
|
|
92
|
+
* @param {Wallet} wallet
|
|
95
93
|
* @returns {AtomMeta}
|
|
96
94
|
*/
|
|
97
|
-
|
|
98
|
-
|
|
95
|
+
setAtomWallet (wallet) {
|
|
96
|
+
const walletMeta = {
|
|
99
97
|
pubkey: wallet.pubkey,
|
|
100
98
|
characters: wallet.characters
|
|
101
|
-
}
|
|
99
|
+
}
|
|
102
100
|
|
|
103
101
|
// Add token units meta key
|
|
104
|
-
if (
|
|
105
|
-
walletMeta.tokenUnits = JSON.stringify(
|
|
102
|
+
if (wallet.tokenUnits && wallet.tokenUnits.length) {
|
|
103
|
+
walletMeta.tokenUnits = JSON.stringify(wallet.getTokenUnitsData())
|
|
106
104
|
}
|
|
107
105
|
// Add trade rates meta key
|
|
108
|
-
if (
|
|
109
|
-
walletMeta.tradeRates = JSON.stringify(
|
|
106
|
+
if (wallet.tradeRates && wallet.tradeRates.length) {
|
|
107
|
+
walletMeta.tradeRates = JSON.stringify(wallet.tradeRates)
|
|
110
108
|
}
|
|
111
109
|
|
|
112
110
|
// Merge all wallet's metas
|
|
113
|
-
this.merge(
|
|
114
|
-
return this
|
|
111
|
+
this.merge(walletMeta)
|
|
112
|
+
return this
|
|
115
113
|
}
|
|
116
114
|
|
|
117
|
-
|
|
118
115
|
/**
|
|
116
|
+
* Set full NEW wallet metadata
|
|
117
|
+
* Used for shadow wallet claim & wallet creation & token creation
|
|
119
118
|
*
|
|
120
|
-
* @param
|
|
121
|
-
* @todo move logic to the separated class
|
|
119
|
+
* @param {Wallet} wallet
|
|
122
120
|
* @returns {AtomMeta}
|
|
123
121
|
*/
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
122
|
+
setMetaWallet (wallet) {
|
|
123
|
+
this.merge({
|
|
124
|
+
walletTokenSlug: wallet.token,
|
|
125
|
+
walletBundleHash: wallet.bundle,
|
|
126
|
+
walletAddress: wallet.address,
|
|
127
|
+
walletPosition: wallet.position,
|
|
128
|
+
walletBatchId: wallet.batchId,
|
|
129
|
+
walletPubkey: wallet.pubkey,
|
|
130
|
+
walletCharacters: wallet.characters
|
|
131
|
+
})
|
|
132
|
+
return this
|
|
133
|
+
}
|
|
132
134
|
|
|
133
|
-
|
|
135
|
+
/**
|
|
136
|
+
*
|
|
137
|
+
* @param shadowWalletClaim
|
|
138
|
+
* @returns {AtomMeta}
|
|
139
|
+
*/
|
|
140
|
+
setShadowWalletClaim (shadowWalletClaim) {
|
|
141
|
+
this.merge({ shadowWalletClaim: shadowWalletClaim * 1 })
|
|
142
|
+
return this
|
|
134
143
|
}
|
|
135
144
|
|
|
136
145
|
/**
|
|
137
146
|
*
|
|
138
|
-
* @param
|
|
147
|
+
* @param {Wallet} signingWallet
|
|
139
148
|
* @returns {AtomMeta}
|
|
140
149
|
*/
|
|
141
|
-
|
|
142
|
-
this.merge(
|
|
143
|
-
signingWallet: JSON.stringify(
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
150
|
+
setSigningWallet (signingWallet) {
|
|
151
|
+
this.merge({
|
|
152
|
+
signingWallet: JSON.stringify({
|
|
153
|
+
tokenSlug: signingWallet.token,
|
|
154
|
+
bundleHash: signingWallet.bundle,
|
|
155
|
+
address: signingWallet.address,
|
|
156
|
+
position: signingWallet.position,
|
|
157
|
+
pubkey: signingWallet.pubkey,
|
|
158
|
+
characters: signingWallet.characters
|
|
159
|
+
})
|
|
160
|
+
})
|
|
161
|
+
return this
|
|
151
162
|
}
|
|
152
163
|
|
|
164
|
+
/**
|
|
165
|
+
*
|
|
166
|
+
* @param policy
|
|
167
|
+
* @todo move logic to the separated class
|
|
168
|
+
* @returns {AtomMeta}
|
|
169
|
+
*/
|
|
170
|
+
addPolicy (policy) {
|
|
171
|
+
// Policy meta initialization
|
|
172
|
+
const policyMeta = new PolicyMeta(policy, Object.keys(this.meta))
|
|
173
|
+
|
|
174
|
+
this.merge({
|
|
175
|
+
policy: policyMeta.toJson()
|
|
176
|
+
})
|
|
177
|
+
|
|
178
|
+
return this
|
|
179
|
+
}
|
|
153
180
|
|
|
154
181
|
/**
|
|
155
182
|
*
|
|
156
183
|
* @returns {*}
|
|
157
184
|
*/
|
|
158
|
-
get() {
|
|
159
|
-
return this.meta
|
|
185
|
+
get () {
|
|
186
|
+
return this.meta
|
|
160
187
|
}
|
|
161
|
-
|
|
162
188
|
}
|
package/src/AuthToken.js
CHANGED
|
@@ -46,13 +46,30 @@ Please visit https://github.com/WishKnish/KnishIO-Client-JS for information.
|
|
|
46
46
|
License: https://github.com/WishKnish/KnishIO-Client-JS/blob/master/LICENSE
|
|
47
47
|
*/
|
|
48
48
|
|
|
49
|
-
import Wallet from './Wallet'
|
|
49
|
+
import Wallet from './Wallet'
|
|
50
50
|
|
|
51
51
|
/**
|
|
52
52
|
*
|
|
53
53
|
*/
|
|
54
54
|
export default class AuthToken {
|
|
55
|
-
|
|
55
|
+
/**
|
|
56
|
+
*
|
|
57
|
+
* @param {string} token
|
|
58
|
+
* @param {number} expiresAt
|
|
59
|
+
* @param {boolean} encrypt
|
|
60
|
+
* @param {string} pubkey
|
|
61
|
+
*/
|
|
62
|
+
constructor ({
|
|
63
|
+
token,
|
|
64
|
+
expiresAt,
|
|
65
|
+
encrypt,
|
|
66
|
+
pubkey
|
|
67
|
+
}) {
|
|
68
|
+
this.$__token = token
|
|
69
|
+
this.$__expiresAt = expiresAt
|
|
70
|
+
this.$__pubkey = pubkey
|
|
71
|
+
this.$__encrypt = encrypt
|
|
72
|
+
}
|
|
56
73
|
|
|
57
74
|
/**
|
|
58
75
|
*
|
|
@@ -60,61 +77,39 @@ export default class AuthToken {
|
|
|
60
77
|
* @param wallet
|
|
61
78
|
* @returns {AuthToken}
|
|
62
79
|
*/
|
|
63
|
-
static create (
|
|
64
|
-
|
|
65
|
-
authToken.setWallet(
|
|
66
|
-
return authToken
|
|
80
|
+
static create (data, wallet) {
|
|
81
|
+
const authToken = new AuthToken(data)
|
|
82
|
+
authToken.setWallet(wallet)
|
|
83
|
+
return authToken
|
|
67
84
|
}
|
|
68
85
|
|
|
69
|
-
|
|
70
86
|
/**
|
|
71
87
|
*
|
|
72
88
|
* @param {object} snapshot
|
|
73
89
|
* @param {string} secret
|
|
74
90
|
* @return {AuthToken}
|
|
75
91
|
*/
|
|
76
|
-
static restore (
|
|
77
|
-
|
|
92
|
+
static restore (snapshot, secret) {
|
|
93
|
+
const wallet = new Wallet({
|
|
78
94
|
secret,
|
|
79
95
|
token: 'AUTH',
|
|
80
96
|
position: snapshot.wallet.position,
|
|
81
97
|
characters: snapshot.wallet.characters
|
|
82
|
-
}
|
|
83
|
-
return AuthToken.create(
|
|
98
|
+
})
|
|
99
|
+
return AuthToken.create({
|
|
84
100
|
token: snapshot.token,
|
|
85
101
|
expiresAt: snapshot.expiresAt,
|
|
86
102
|
pubkey: snapshot.pubkey,
|
|
87
103
|
encrypt: snapshot.encrypt
|
|
88
|
-
}, wallet
|
|
104
|
+
}, wallet)
|
|
89
105
|
}
|
|
90
106
|
|
|
91
|
-
|
|
92
|
-
/**
|
|
93
|
-
*
|
|
94
|
-
* @param {string} token
|
|
95
|
-
* @param {number} expiresAt
|
|
96
|
-
* @param {boolean} encrypt
|
|
97
|
-
* @param {string} pubkey
|
|
98
|
-
*/
|
|
99
|
-
constructor ( {
|
|
100
|
-
token,
|
|
101
|
-
expiresAt,
|
|
102
|
-
encrypt,
|
|
103
|
-
pubkey
|
|
104
|
-
} ) {
|
|
105
|
-
this.$__token = token;
|
|
106
|
-
this.$__expiresAt = expiresAt;
|
|
107
|
-
this.$__pubkey = pubkey;
|
|
108
|
-
this.$__encrypt = encrypt;
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
|
|
112
107
|
/**
|
|
113
108
|
*
|
|
114
109
|
* @param {Wallet} wallet
|
|
115
110
|
*/
|
|
116
|
-
setWallet (
|
|
117
|
-
this.$__wallet = wallet
|
|
111
|
+
setWallet (wallet) {
|
|
112
|
+
this.$__wallet = wallet
|
|
118
113
|
}
|
|
119
114
|
|
|
120
115
|
/**
|
|
@@ -122,7 +117,7 @@ export default class AuthToken {
|
|
|
122
117
|
* @return {Wallet}
|
|
123
118
|
*/
|
|
124
119
|
getWallet () {
|
|
125
|
-
return this.$__wallet
|
|
120
|
+
return this.$__wallet
|
|
126
121
|
}
|
|
127
122
|
|
|
128
123
|
/**
|
|
@@ -139,25 +134,23 @@ export default class AuthToken {
|
|
|
139
134
|
position: this.$__wallet.position,
|
|
140
135
|
characters: this.$__wallet.characters
|
|
141
136
|
}
|
|
142
|
-
}
|
|
137
|
+
}
|
|
143
138
|
}
|
|
144
139
|
|
|
145
|
-
|
|
146
140
|
/**
|
|
147
141
|
*
|
|
148
142
|
* @return {string}
|
|
149
143
|
*/
|
|
150
144
|
getToken () {
|
|
151
|
-
return this.$__token
|
|
145
|
+
return this.$__token
|
|
152
146
|
}
|
|
153
147
|
|
|
154
|
-
|
|
155
148
|
/**
|
|
156
149
|
*
|
|
157
150
|
* @return {string}
|
|
158
151
|
*/
|
|
159
152
|
getPubkey () {
|
|
160
|
-
return this.$__pubkey
|
|
153
|
+
return this.$__pubkey
|
|
161
154
|
}
|
|
162
155
|
|
|
163
156
|
/**
|
|
@@ -165,7 +158,7 @@ export default class AuthToken {
|
|
|
165
158
|
* @return {number}
|
|
166
159
|
*/
|
|
167
160
|
getExpireInterval () {
|
|
168
|
-
return (
|
|
161
|
+
return (this.$__expiresAt * 1000) - Date.now()
|
|
169
162
|
}
|
|
170
163
|
|
|
171
164
|
/**
|
|
@@ -173,12 +166,11 @@ export default class AuthToken {
|
|
|
173
166
|
* @return {boolean}
|
|
174
167
|
*/
|
|
175
168
|
isExpired () {
|
|
176
|
-
return !this.$__expiresAt || this.getExpireInterval() < 0
|
|
169
|
+
return !this.$__expiresAt || this.getExpireInterval() < 0
|
|
177
170
|
}
|
|
178
171
|
|
|
179
|
-
|
|
180
172
|
/**
|
|
181
|
-
* Get auth data for the final client
|
|
173
|
+
* Get auth data for the final GraphQL client
|
|
182
174
|
* @return {{wallet: Wallet, token: string, pubkey: string}}
|
|
183
175
|
*/
|
|
184
176
|
getAuthData () {
|
|
@@ -186,7 +178,6 @@ export default class AuthToken {
|
|
|
186
178
|
token: this.getToken(),
|
|
187
179
|
pubkey: this.getPubkey(),
|
|
188
180
|
wallet: this.getWallet()
|
|
189
|
-
}
|
|
181
|
+
}
|
|
190
182
|
}
|
|
191
|
-
|
|
192
183
|
}
|