@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.
- package/README.md +207 -274
- package/dist/client.iife.js +577 -0
- package/package.json +36 -79
- package/src/.babelrc +0 -22
- package/src/Atom.js +171 -132
- package/src/AtomMeta.js +76 -50
- package/src/AuthToken.js +37 -46
- package/src/KnishIOClient.js +932 -985
- 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/apollo/ApolloClientWrapper.js +143 -0
- package/src/libraries/apollo/CipherLink.js +116 -0
- package/src/libraries/apollo/Client.js +154 -0
- package/src/libraries/apollo/ErrorHandler.js +32 -0
- package/src/libraries/apollo/SubscriptionManager.js +60 -0
- package/src/libraries/apollo/operationUtils.js +26 -0
- package/src/libraries/array.js +50 -41
- package/src/libraries/crypto.js +20 -27
- package/src/libraries/strings.js +58 -91
- 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/README.md
CHANGED
|
@@ -5,8 +5,7 @@
|
|
|
5
5
|
|
|
6
6
|
# Knish.IO Javascript Client SDK
|
|
7
7
|
|
|
8
|
-
This is
|
|
9
|
-
libraries for building and signing Knish.IO Molecules, composing Atoms, generating Wallets, and so much more.
|
|
8
|
+
This is the official Javascript / NodeJS implementation of the Knish.IO client SDK. Its purpose is to expose class libraries for building and signing Knish.IO Molecules, composing Atoms, generating Wallets, and much more.
|
|
10
9
|
|
|
11
10
|
## Installation
|
|
12
11
|
|
|
@@ -16,6 +15,8 @@ The SDK can be installed via either of the following:
|
|
|
16
15
|
|
|
17
16
|
2. `npm install @wishknish/knishio-client-js --save`
|
|
18
17
|
|
|
18
|
+
(**Note:** For installations in a Vite-based environment, you will need to install the https://www.npmjs.com/package/vite-plugin-node-polyfills plugin to ensure compatibility with Node.js libraries.)
|
|
19
|
+
|
|
19
20
|
## Basic Usage
|
|
20
21
|
|
|
21
22
|
The purpose of the Knish.IO SDK is to expose various ledger functions to new or existing applications.
|
|
@@ -37,62 +38,56 @@ This document will explain both ways.
|
|
|
37
38
|
|
|
38
39
|
2. Instantiate the class with your node URI:
|
|
39
40
|
```javascript
|
|
40
|
-
const client = new KnishIOClient(
|
|
41
|
-
uri: myNodeURI
|
|
42
|
-
|
|
41
|
+
const client = new KnishIOClient({
|
|
42
|
+
uri: myNodeURI,
|
|
43
|
+
cellSlug: myCellSlug,
|
|
44
|
+
serverSdkVersion: 3, // Optional, defaults to 3
|
|
45
|
+
logging: false // Optional, enables logging
|
|
46
|
+
});
|
|
43
47
|
```
|
|
44
48
|
|
|
45
|
-
3.
|
|
46
|
-
```javascript
|
|
47
|
-
client.setCellSlug( myCellSlug );
|
|
48
|
-
```
|
|
49
|
-
(**Note:** the `knishio_cells` table on the node must contain an entry for this Cell)
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
4. Request authorization token from the node:
|
|
49
|
+
3. Request authorization token from the node:
|
|
53
50
|
```javascript
|
|
54
|
-
client.requestAuthToken
|
|
55
|
-
|
|
56
|
-
|
|
51
|
+
await client.requestAuthToken({
|
|
52
|
+
seed: 'myTopSecretCode',
|
|
53
|
+
encrypt: true // Optional, enables encryption
|
|
54
|
+
});
|
|
57
55
|
```
|
|
58
56
|
|
|
59
|
-
(**Note:**
|
|
60
|
-
user identifier from an external authentication process, for example)
|
|
57
|
+
(**Note:** The `seed` parameter can be a salted combination of username + password, a biometric hash, an existing user identifier from an external authentication process, for example)
|
|
61
58
|
|
|
62
|
-
|
|
63
|
-
5. Begin using `client` to trigger commands described below...
|
|
59
|
+
4. Begin using `client` to trigger commands described below...
|
|
64
60
|
|
|
65
61
|
### KnishIOClient Methods
|
|
66
62
|
|
|
67
|
-
- Query metadata for a **Wallet Bundle**. Omit the `
|
|
63
|
+
- Query metadata for a **Wallet Bundle**. Omit the `bundle` parameter to query your own Wallet Bundle:
|
|
68
64
|
```javascript
|
|
69
|
-
const result = await client.queryBundle
|
|
70
|
-
|
|
71
|
-
}
|
|
65
|
+
const result = await client.queryBundle({
|
|
66
|
+
bundle: 'c47e20f99df190e418f0cc5ddfa2791e9ccc4eb297cfa21bd317dc0f98313b1d',
|
|
67
|
+
});
|
|
72
68
|
|
|
73
|
-
// Raw Metadata
|
|
74
|
-
console.log( result );
|
|
69
|
+
console.log(result); // Raw Metadata
|
|
75
70
|
```
|
|
76
71
|
|
|
77
|
-
- Query metadata for a **Meta Asset
|
|
72
|
+
- Query metadata for a **Meta Asset**:
|
|
78
73
|
|
|
79
74
|
```javascript
|
|
80
|
-
const result = await client.queryMeta
|
|
75
|
+
const result = await client.queryMeta({
|
|
81
76
|
metaType: 'Vehicle',
|
|
82
77
|
metaId: null, // Meta ID
|
|
83
78
|
key: 'LicensePlate',
|
|
84
79
|
value: '1H17P',
|
|
85
|
-
latest: true // Limit meta values to latest per key
|
|
86
|
-
|
|
80
|
+
latest: true, // Limit meta values to latest per key
|
|
81
|
+
throughAtom: true // Optional, query through Atom (default: true)
|
|
82
|
+
});
|
|
87
83
|
|
|
88
|
-
// Raw Metadata
|
|
89
|
-
console.log( result );
|
|
84
|
+
console.log(result); // Raw Metadata
|
|
90
85
|
```
|
|
91
86
|
|
|
92
|
-
- Writing new metadata for a **Meta Asset
|
|
87
|
+
- Writing new metadata for a **Meta Asset**:
|
|
93
88
|
|
|
94
89
|
```javascript
|
|
95
|
-
const result = await client.createMeta
|
|
90
|
+
const result = await client.createMeta({
|
|
96
91
|
metaType: 'Pokemon',
|
|
97
92
|
metaId: 'Charizard',
|
|
98
93
|
meta: {
|
|
@@ -107,46 +102,50 @@ This document will explain both ways.
|
|
|
107
102
|
],
|
|
108
103
|
hp: 78,
|
|
109
104
|
attack: 84,
|
|
110
|
-
}
|
|
111
|
-
|
|
105
|
+
},
|
|
106
|
+
policy: {} // Optional policy object
|
|
107
|
+
});
|
|
112
108
|
|
|
113
|
-
if(
|
|
109
|
+
if (result.success()) {
|
|
114
110
|
// Do things!
|
|
115
111
|
}
|
|
116
112
|
|
|
117
|
-
console.log(
|
|
113
|
+
console.log(result.data()); // Raw response
|
|
118
114
|
```
|
|
119
115
|
|
|
120
116
|
- Query Wallets associated with a Wallet Bundle:
|
|
121
117
|
|
|
122
118
|
```javascript
|
|
123
|
-
const result = await client.queryWallets
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
119
|
+
const result = await client.queryWallets({
|
|
120
|
+
bundle: 'c47e20f99df190e418f0cc5ddfa2791e9ccc4eb297cfa21bd317dc0f98313b1d',
|
|
121
|
+
token: 'FOO', // Optional, filter by token
|
|
122
|
+
unspent: true // Optional, limit results to unspent wallets
|
|
123
|
+
});
|
|
127
124
|
|
|
128
|
-
console.log(
|
|
125
|
+
console.log(result); // Raw response
|
|
129
126
|
```
|
|
130
127
|
|
|
131
|
-
- Declaring new **Wallets
|
|
132
|
-
|
|
128
|
+
- Declaring new **Wallets**:
|
|
129
|
+
|
|
130
|
+
(**Note:** If Tokens are sent to undeclared Wallets, **Shadow Wallets** will be used (placeholder
|
|
131
|
+
Wallets that can receive, but cannot send) to store tokens until they are claimed.)
|
|
133
132
|
|
|
134
133
|
```javascript
|
|
135
|
-
const result = await client.createWallet
|
|
134
|
+
const result = await client.createWallet({
|
|
136
135
|
token: 'FOO' // Token Slug for the wallet we are declaring
|
|
137
|
-
}
|
|
136
|
+
});
|
|
138
137
|
|
|
139
|
-
if(
|
|
138
|
+
if (result.success()) {
|
|
140
139
|
// Do things!
|
|
141
140
|
}
|
|
142
141
|
|
|
143
|
-
console.log(
|
|
142
|
+
console.log(result.data()); // Raw response
|
|
144
143
|
```
|
|
145
144
|
|
|
146
145
|
- Issuing new **Tokens**:
|
|
147
146
|
|
|
148
147
|
```javascript
|
|
149
|
-
const result = await client.createToken
|
|
148
|
+
const result = await client.createToken({
|
|
150
149
|
token: 'CRZY', // Token slug (ticker symbol)
|
|
151
150
|
amount: '100000000', // Initial amount to issue
|
|
152
151
|
meta: {
|
|
@@ -154,234 +153,170 @@ This document will explain both ways.
|
|
|
154
153
|
fungibility: 'fungible', // Fungibility style (fungible / nonfungible / stackable)
|
|
155
154
|
supply: 'limited', // Supply style (limited / replenishable)
|
|
156
155
|
decimals: '2' // Decimal places
|
|
157
|
-
}
|
|
158
|
-
|
|
156
|
+
},
|
|
157
|
+
units: [], // Optional, for stackable tokens
|
|
158
|
+
batchId: null // Optional, for stackable tokens
|
|
159
|
+
});
|
|
159
160
|
|
|
160
|
-
if(
|
|
161
|
+
if (result.success()) {
|
|
161
162
|
// Do things!
|
|
162
163
|
}
|
|
163
164
|
|
|
164
|
-
console.log(
|
|
165
|
+
console.log(result.data()); // Raw response
|
|
165
166
|
```
|
|
166
167
|
|
|
167
168
|
- Transferring **Tokens** to other users:
|
|
168
169
|
|
|
169
170
|
```javascript
|
|
170
|
-
const result = await client.transferToken
|
|
171
|
-
|
|
171
|
+
const result = await client.transferToken({
|
|
172
|
+
bundleHash: '7bf38257401eb3b0f20cabf5e6cf3f14c76760386473b220d95fa1c38642b61d', // Recipient's bundle hash
|
|
172
173
|
token: 'CRZY', // Token slug
|
|
173
|
-
amount: '100'
|
|
174
|
-
|
|
174
|
+
amount: '100',
|
|
175
|
+
units: [], // Optional, for stackable tokens
|
|
176
|
+
batchId: null // Optional, for stackable tokens
|
|
177
|
+
});
|
|
175
178
|
|
|
176
|
-
if(
|
|
179
|
+
if (result.success()) {
|
|
177
180
|
// Do things!
|
|
178
181
|
}
|
|
179
182
|
|
|
180
|
-
console.log(
|
|
183
|
+
console.log(result.data()); // Raw response
|
|
181
184
|
```
|
|
182
185
|
|
|
183
|
-
|
|
186
|
+
- Creating a new **Rule**:
|
|
184
187
|
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
188
|
+
```javascript
|
|
189
|
+
const result = await client.createRule({
|
|
190
|
+
metaType: 'MyMetaType',
|
|
191
|
+
metaId: 'MyMetaId',
|
|
192
|
+
rule: [
|
|
193
|
+
// Rule definition
|
|
194
|
+
],
|
|
195
|
+
policy: {} // Optional policy object
|
|
196
|
+
});
|
|
197
|
+
|
|
198
|
+
if (result.success()) {
|
|
199
|
+
// Do things!
|
|
200
|
+
}
|
|
189
201
|
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
```javascript
|
|
193
|
-
client.createMoleculeMutation ( {
|
|
194
|
-
mutationClass: myQueryClass // More info on these below
|
|
195
|
-
} )
|
|
196
|
-
```
|
|
202
|
+
console.log(result.data()); // Raw response
|
|
203
|
+
```
|
|
197
204
|
|
|
198
|
-
-
|
|
199
|
-
```javascript
|
|
200
|
-
client.queryBalance ( {
|
|
201
|
-
token: myTokenSlug,
|
|
202
|
-
bundle: myBundleHash // Omit to get your own balance
|
|
203
|
-
} )
|
|
204
|
-
```
|
|
205
|
+
- Querying **Atoms**:
|
|
205
206
|
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
207
|
+
```javascript
|
|
208
|
+
const result = await client.queryAtom({
|
|
209
|
+
molecularHash: 'hash',
|
|
210
|
+
bundleHash: 'bundle',
|
|
211
|
+
isotope: 'V',
|
|
212
|
+
tokenSlug: 'CRZY',
|
|
213
|
+
latest: true,
|
|
214
|
+
queryArgs: {
|
|
215
|
+
limit: 15,
|
|
216
|
+
offset: 1
|
|
217
|
+
}
|
|
218
|
+
});
|
|
216
219
|
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
```javascript
|
|
220
|
-
client.queryShadowWallets ( {
|
|
221
|
-
token: tokenSlug,
|
|
222
|
-
bundle: myBundleHash // Omit to get your own balance
|
|
223
|
-
} )
|
|
224
|
-
```
|
|
220
|
+
console.log(result.data()); // Raw response
|
|
221
|
+
```
|
|
225
222
|
|
|
226
|
-
-
|
|
227
|
-
```javascript
|
|
228
|
-
client.claimShadowWallet ( {
|
|
229
|
-
token: tokenSlug
|
|
230
|
-
} )
|
|
231
|
-
```
|
|
223
|
+
- Working with **Buffer Tokens**:
|
|
232
224
|
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
225
|
+
```javascript
|
|
226
|
+
// Deposit to buffer
|
|
227
|
+
const depositResult = await client.depositBufferToken({
|
|
228
|
+
tokenSlug: 'CRZY',
|
|
229
|
+
amount: 100,
|
|
230
|
+
tradeRates: {
|
|
231
|
+
'OTHER_TOKEN': 0.5
|
|
232
|
+
}
|
|
233
|
+
});
|
|
241
234
|
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
const
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
const
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
value: 'Eugene'
|
|
294
|
-
}
|
|
295
|
-
|
|
296
|
-
// Define which fields we want to get back
|
|
297
|
-
const fields = {
|
|
298
|
-
bundleHash: null,
|
|
299
|
-
metas: {
|
|
300
|
-
key: null,
|
|
301
|
-
value: null,
|
|
302
|
-
},
|
|
303
|
-
}
|
|
304
|
-
|
|
305
|
-
// Execute the query
|
|
306
|
-
const result = await query.execute( {
|
|
307
|
-
variables,
|
|
308
|
-
fields
|
|
309
|
-
} );
|
|
310
|
-
|
|
311
|
-
console.log( result.data() );
|
|
312
|
-
```
|
|
313
|
-
|
|
314
|
-
#### `QueryWalletList` (for getting a list of Wallets)
|
|
315
|
-
|
|
316
|
-
```javascript
|
|
317
|
-
// Build the query
|
|
318
|
-
const query = await client.createQuery( QueryWalletList );
|
|
319
|
-
|
|
320
|
-
// Define variable parameters
|
|
321
|
-
// (eg: how we want to filter Wallet Bundles)
|
|
322
|
-
const variables = {
|
|
323
|
-
token: 'DYD',
|
|
324
|
-
};
|
|
325
|
-
|
|
326
|
-
// Define which fields we want to get back
|
|
327
|
-
const fields = {
|
|
328
|
-
address: null,
|
|
329
|
-
amount: null,
|
|
330
|
-
};
|
|
331
|
-
|
|
332
|
-
// Execute the query
|
|
333
|
-
const result = await query.execute( {
|
|
334
|
-
variables,
|
|
335
|
-
fields
|
|
336
|
-
} );
|
|
337
|
-
|
|
338
|
-
console.log( result.data() );
|
|
339
|
-
```
|
|
340
|
-
|
|
341
|
-
## The Extreme Way: DIY Everything
|
|
342
|
-
|
|
343
|
-
This method involves individually building Atoms and Molecules, triggering the signature and validation processes, and
|
|
344
|
-
communicating the resulting signed Molecule mutation or Query to a Knish.IO node via your favorite GraphQL client.
|
|
235
|
+
// Withdraw from buffer
|
|
236
|
+
const withdrawResult = await client.withdrawBufferToken({
|
|
237
|
+
tokenSlug: 'CRZY',
|
|
238
|
+
amount: 50
|
|
239
|
+
});
|
|
240
|
+
|
|
241
|
+
console.log(depositResult.data(), withdrawResult.data()); // Raw responses
|
|
242
|
+
```
|
|
243
|
+
|
|
244
|
+
- Getting client fingerprint:
|
|
245
|
+
|
|
246
|
+
```javascript
|
|
247
|
+
const fingerprint = await client.getFingerprint();
|
|
248
|
+
console.log(fingerprint);
|
|
249
|
+
|
|
250
|
+
const fingerprintData = await client.getFingerprintData();
|
|
251
|
+
console.log(fingerprintData);
|
|
252
|
+
```
|
|
253
|
+
|
|
254
|
+
## Advanced Usage: Working with Molecules
|
|
255
|
+
|
|
256
|
+
For more granular control, you can work directly with Molecules:
|
|
257
|
+
|
|
258
|
+
- Create a new Molecule:
|
|
259
|
+
```javascript
|
|
260
|
+
const molecule = await client.createMolecule();
|
|
261
|
+
```
|
|
262
|
+
|
|
263
|
+
- Create a custom Mutation:
|
|
264
|
+
```javascript
|
|
265
|
+
const mutation = await client.createMoleculeMutation({
|
|
266
|
+
mutationClass: MyCustomMutationClass
|
|
267
|
+
});
|
|
268
|
+
```
|
|
269
|
+
|
|
270
|
+
- Sign and check a Molecule:
|
|
271
|
+
```javascript
|
|
272
|
+
molecule.sign();
|
|
273
|
+
if (!molecule.check()) {
|
|
274
|
+
// Handle error
|
|
275
|
+
}
|
|
276
|
+
```
|
|
277
|
+
|
|
278
|
+
- Execute a custom Query or Mutation:
|
|
279
|
+
```javascript
|
|
280
|
+
const result = await client.executeQuery(myQueryOrMutation, variables);
|
|
281
|
+
```
|
|
282
|
+
|
|
283
|
+
## The Hard Way: DIY Everything
|
|
284
|
+
|
|
285
|
+
This method involves individually building Atoms and Molecules, triggering the signature and validation processes, and communicating the resulting signed Molecule mutation or Query to a Knish.IO node via your favorite GraphQL client.
|
|
345
286
|
|
|
346
287
|
1. Include the relevant classes in your application code:
|
|
347
288
|
```javascript
|
|
348
|
-
|
|
289
|
+
import { Molecule, Wallet, Atom } from '@wishknish/knishio-client-js'
|
|
349
290
|
```
|
|
350
291
|
|
|
351
|
-
2. Generate a 2048-symbol hexadecimal secret, either randomly, or via hashing login + password + salt, OAuth secret ID,
|
|
352
|
-
biometric ID, or any other static value
|
|
353
|
-
|
|
292
|
+
2. Generate a 2048-symbol hexadecimal secret, either randomly, or via hashing login + password + salt, OAuth secret ID, biometric ID, or any other static value.
|
|
354
293
|
|
|
355
294
|
3. (optional) Initialize a signing wallet with:
|
|
356
295
|
```javascript
|
|
357
|
-
const wallet = new Wallet(
|
|
296
|
+
const wallet = new Wallet({
|
|
358
297
|
secret: mySecret,
|
|
359
298
|
token: tokenSlug,
|
|
360
|
-
position: myCustomPosition // (optional) instantiate specific wallet instance vs. random
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
// characters: myCharacterSet
|
|
364
|
-
} )
|
|
299
|
+
position: myCustomPosition, // (optional) instantiate specific wallet instance vs. random
|
|
300
|
+
characters: myCharacterSet // (optional) override the character set used by the wallet
|
|
301
|
+
})
|
|
365
302
|
```
|
|
366
303
|
|
|
367
|
-
**WARNING 1:** If ContinuID is enabled on the node, you will need to use a specific wallet, and therefore will first
|
|
368
|
-
need to query the node to retrieve the `position` for that wallet.
|
|
304
|
+
**WARNING 1:** If ContinuID is enabled on the node, you will need to use a specific wallet, and therefore will first need to query the node to retrieve the `position` for that wallet.
|
|
369
305
|
|
|
370
306
|
**WARNING 2:** The Knish.IO protocol mandates that all C and M transactions be signed with a `USER` token wallet.
|
|
371
307
|
|
|
372
|
-
|
|
373
308
|
4. Build your molecule with:
|
|
374
309
|
```javascript
|
|
375
|
-
const molecule = new Molecule(
|
|
310
|
+
const molecule = new Molecule({
|
|
376
311
|
secret: mySecret,
|
|
377
312
|
sourceWallet: mySourceWallet, // (optional) wallet for signing
|
|
378
|
-
|
|
379
|
-
cellSlug: myCellSlug // (optional) used to point a transaction to a specific branch of the ledger
|
|
380
|
-
|
|
313
|
+
remainderWallet: myRemainderWallet, // (optional) wallet to receive remainder tokens
|
|
314
|
+
cellSlug: myCellSlug, // (optional) used to point a transaction to a specific branch of the ledger
|
|
315
|
+
version: 4 // (optional) specify the molecule version
|
|
316
|
+
});
|
|
381
317
|
```
|
|
382
318
|
|
|
383
|
-
5. Either use one of the shortcut methods provided by the `Molecule` class (which will build `Atom` instances for you),
|
|
384
|
-
or create `Atom` instances yourself.
|
|
319
|
+
5. Either use one of the shortcut methods provided by the `Molecule` class (which will build `Atom` instances for you), or create `Atom` instances yourself.
|
|
385
320
|
|
|
386
321
|
DIY example:
|
|
387
322
|
```javascript
|
|
@@ -393,11 +328,11 @@ communicating the resulting signed Molecule mutation or Query to a Knish.IO node
|
|
|
393
328
|
token: newWallet.token,
|
|
394
329
|
bundle: newWallet.bundle,
|
|
395
330
|
position: newWallet.position,
|
|
396
|
-
|
|
331
|
+
batchId: newWallet.batchId,
|
|
397
332
|
}
|
|
398
|
-
|
|
333
|
+
|
|
399
334
|
// Build the C isotope atom
|
|
400
|
-
const walletCreationAtom = new Atom(
|
|
335
|
+
const walletCreationAtom = new Atom({
|
|
401
336
|
position: sourceWallet.position,
|
|
402
337
|
walletAddress: sourceWallet.address,
|
|
403
338
|
isotope: 'C',
|
|
@@ -406,13 +341,13 @@ communicating the resulting signed Molecule mutation or Query to a Knish.IO node
|
|
|
406
341
|
metaId: newWallet.address,
|
|
407
342
|
meta: newWalletMeta,
|
|
408
343
|
index: molecule.generateIndex()
|
|
409
|
-
}
|
|
410
|
-
|
|
344
|
+
})
|
|
345
|
+
|
|
411
346
|
// Add the atom to our molecule
|
|
412
|
-
molecule.addAtom(
|
|
413
|
-
|
|
347
|
+
molecule.addAtom(walletCreationAtom)
|
|
348
|
+
|
|
414
349
|
// Adding a ContinuID / remainder atom
|
|
415
|
-
molecule.
|
|
350
|
+
molecule.addContinuIdAtom();
|
|
416
351
|
```
|
|
417
352
|
|
|
418
353
|
Molecule shortcut method example:
|
|
@@ -424,12 +359,13 @@ communicating the resulting signed Molecule mutation or Query to a Knish.IO node
|
|
|
424
359
|
foo: 'Foo',
|
|
425
360
|
bar: 'Bar'
|
|
426
361
|
}
|
|
427
|
-
|
|
428
|
-
molecule.initMeta(
|
|
362
|
+
|
|
363
|
+
molecule.initMeta({
|
|
429
364
|
meta: metadata,
|
|
430
365
|
metaType: 'MyMetaType',
|
|
431
|
-
metaId: 'MetaId123'
|
|
432
|
-
|
|
366
|
+
metaId: 'MetaId123',
|
|
367
|
+
policy: {} // Optional policy object
|
|
368
|
+
});
|
|
433
369
|
```
|
|
434
370
|
|
|
435
371
|
6. Sign the molecule with the stored user secret:
|
|
@@ -439,52 +375,49 @@ communicating the resulting signed Molecule mutation or Query to a Knish.IO node
|
|
|
439
375
|
|
|
440
376
|
7. Make sure everything checks out by verifying the molecule:
|
|
441
377
|
```javascript
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
378
|
+
try {
|
|
379
|
+
molecule.check();
|
|
380
|
+
// If we're validating a V isotope transaction,
|
|
381
|
+
// add the source wallet as a parameter
|
|
382
|
+
molecule.check(sourceWallet);
|
|
383
|
+
} catch (error) {
|
|
384
|
+
console.error('Molecule check failed:', error);
|
|
385
|
+
// Handle the error
|
|
450
386
|
}
|
|
451
387
|
```
|
|
452
388
|
|
|
453
389
|
8. Broadcast the molecule to a Knish.IO node:
|
|
454
390
|
```javascript
|
|
455
391
|
// Build our query object using the KnishIOClient wrapper
|
|
456
|
-
const
|
|
457
|
-
|
|
392
|
+
const mutation = await client.createMoleculeMutation({
|
|
393
|
+
mutationClass: MutationProposeMolecule,
|
|
394
|
+
molecule: molecule
|
|
395
|
+
});
|
|
396
|
+
|
|
458
397
|
// Send the query to the node and get a response
|
|
459
|
-
const response = await
|
|
398
|
+
const response = await client.executeQuery(mutation);
|
|
460
399
|
```
|
|
461
400
|
|
|
462
401
|
9. Inspect the response...
|
|
463
402
|
```javascript
|
|
464
403
|
// For basic queries, we look at the data property:
|
|
465
|
-
console.log(
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
console.log( response.success() )
|
|
471
|
-
|
|
404
|
+
console.log(response.data())
|
|
405
|
+
|
|
406
|
+
// For mutations, check if the molecule was accepted by the ledger:
|
|
407
|
+
console.log(response.success())
|
|
408
|
+
|
|
472
409
|
// We can also check the reason for rejection
|
|
473
|
-
console.log(
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
console.log( response.payload() )
|
|
410
|
+
console.log(response.reason())
|
|
411
|
+
|
|
412
|
+
// Some queries may also produce a payload, with additional data:
|
|
413
|
+
console.log(response.payload())
|
|
478
414
|
```
|
|
415
|
+
|
|
479
416
|
Payloads are provided by responses to the following queries:
|
|
480
417
|
1. `QueryBalance` and `QueryContinuId` -> returns a `Wallet` instance
|
|
481
418
|
2. `QueryWalletList` -> returns a list of `Wallet` instances
|
|
482
|
-
3. `MutationProposeMolecule`, `MutationRequestAuthorization`, `MutationCreateIdentifier`, `MutationLinkIdentifier`
|
|
483
|
-
, `MutationClaimShadowWallet`, `MutationCreateToken`, `MutationRequestTokens`, and `MutationTransferTokens` ->
|
|
484
|
-
returns molecule metadata
|
|
419
|
+
3. `MutationProposeMolecule`, `MutationRequestAuthorization`, `MutationCreateIdentifier`, `MutationLinkIdentifier`, `MutationClaimShadowWallet`, `MutationCreateToken`, `MutationRequestTokens`, and `MutationTransferTokens` -> returns molecule metadata
|
|
485
420
|
|
|
486
421
|
## Getting Help
|
|
487
422
|
|
|
488
|
-
Knish.IO is active development, and our team is ready to assist with integration questions. The best way to seek help is
|
|
489
|
-
to stop by our [Telegram Support Channel](https://t.me/wishknish). You can
|
|
490
|
-
also [send us a contact request](https://knish.io/contact) via our website.
|
|
423
|
+
Knish.IO is under active development, and our team is ready to assist with integration questions. The best way to seek help is to stop by our [Telegram Support Channel](https://t.me/wishknish). You can also [send us a contact request](https://knish.io/contact) via our website.
|