wavs-api 0.0.1-security → 0.24.2

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.

Potentially problematic release.


This version of wavs-api might be problematic. Click here for more details.

package/LICENSE.md ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 Phil Filippak
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,5 +1,487 @@
1
- # Security holding package
1
+ # Waves API [![npm version](https://badge.fury.io/js/waves-api.svg)](https://www.npmjs.com/package/waves-api) [![downloads/month](https://img.shields.io/npm/dm/waves-api.svg)](https://www.npmjs.com/package/waves-api)
2
2
 
3
- This package contained malicious code and was removed from the registry by the npm security team. A placeholder was published to ensure users are not affected in the future.
3
+ Waves Platform core features and Waves API library for both Node.js and browser.
4
4
 
5
- Please refer to www.npmjs.com/advisories?search=wavs-api for more information.
5
+ The latest and most actual version of this documentation [is hosted on GitHub](https://github.com/xenohunter/waves-api/blob/master/README.md).
6
+
7
+ ## Installation
8
+
9
+ ```
10
+ npm install waves-api --save
11
+ ```
12
+
13
+ In Node.js:
14
+
15
+ ```
16
+ const WavesAPI = require('waves-api');
17
+ ```
18
+
19
+ In browser:
20
+
21
+ ```
22
+ <script src="./node_modules/waves-api/dist/waves-api.min.js"></script>
23
+ ```
24
+
25
+ You can use `waves-api` even within Web Workers.
26
+
27
+ ## Usage
28
+
29
+ ```
30
+ const Waves = WavesAPI.create(WavesAPI.TESTNET_CONFIG);
31
+ ```
32
+
33
+ ### Seed
34
+
35
+ You can create a new random seed:
36
+
37
+ ```
38
+ const seed = Waves.Seed.create();
39
+
40
+ console.log(seed.phrase); // 'hole law front bottom then mobile fabric under horse drink other member work twenty boss'
41
+ console.log(seed.address); // '3Mr5af3Y7r7gQej3tRtugYbKaPr5qYps2ei'
42
+ console.log(seed.keyPair); // { privateKey: 'HkFCbtBHX1ZUF42aNE4av52JvdDPWth2jbP88HPTDyp4', publicKey: 'AF9HLq2Rsv2fVfLPtsWxT7Y3S9ZTv6Mw4ZTp8K8LNdEp' }
43
+ ```
44
+
45
+ That seed may be encrypted with a password:
46
+
47
+ ```
48
+ const password = '0123456789';
49
+ const encrypted = seed.encrypt(password);
50
+
51
+ console.log(encrypted); // 'U2FsdGVkX1+5TpaxcK/eJyjht7bSpjLYlSU8gVXNapU3MG8xgWm3uavW37aPz/KTcROK7OjOA3dpCLXfZ4YjCV3OW2r1CCaUhOMPBCX64QA/iAlgPJNtfMvjLKTHZko/JDgrxBHgQkz76apORWdKEQ=='
52
+ ```
53
+
54
+ And decrypted (with the same password, of course):
55
+
56
+ ```
57
+ const restoredPhrase = Waves.Seed.decryptSeedPhrase(encrypted, password);
58
+
59
+ console.log(restoredPhrase); // 'hole law front bottom then mobile fabric under horse drink other member work twenty boss'
60
+ ```
61
+
62
+ Being called with a wrong password `Waves.Seed.decryptSeedPhrase()` throws an exception.
63
+
64
+ You also can create a `Seed` object from an existing seed:
65
+
66
+ ```
67
+ const anotherSeed = Waves.Seed.fromExistingPhrase('a seed which was backed up some time ago');
68
+
69
+ console.log(seed.phrase); // 'a seed which was backed up some time ago'
70
+ console.log(seed.address); // '3N3dy1P8Dccup5WnYsrC6VmaGHF6wMxdLn4'
71
+ console.log(seed.keyPair); // { privateKey: '2gSboTPsiQfi1i3zNtFppVJVgjoCA9P4HE9K95y8yCMm', publicKey: 'CFr94paUnDSTRk8jz6Ep3bzhXb9LKarNmLYXW6gqw6Y3' }
72
+ ```
73
+
74
+ ### Node API
75
+
76
+ Right now only the first version of Node API is available. If you want to contribute to the new versions of Waves API please see [the section below](#see-also).
77
+
78
+ #### Sending transactions
79
+
80
+ You will need a pair of keys from an account with a balance to send transactions:
81
+
82
+ ```
83
+ const seed = Waves.Seed.fromExistingPhrase('a seed from an account with some funds');
84
+ ```
85
+
86
+ ##### Issue transaction
87
+
88
+ ```
89
+ const issueData = {
90
+
91
+ name: 'Your token name',
92
+ description: 'Some words about it',
93
+
94
+ // With given options you'll have 100000.00000 tokens
95
+ quantity: 10000000000,
96
+ precision: 5,
97
+
98
+ // This flag defines whether additional emission is possible
99
+ reissuable: false,
100
+
101
+ fee: 100000000,
102
+ timestamp: Date.now()
103
+
104
+ };
105
+
106
+ Waves.API.Node.v1.assets.issue(issueData, seed.keyPair).then((responseData) => {
107
+ console.log(responseData);
108
+ });
109
+ ```
110
+
111
+ ##### Transfer transaction
112
+
113
+ ```
114
+ const transferData = {
115
+
116
+ // An arbitrary address; mine, in this example
117
+ recipient: '3PMgh8ra7v9USWUJxUCxKQKr6PM3MgqNVR8',
118
+
119
+ // ID of a token, or WAVES
120
+ assetId: 'WAVES',
121
+
122
+ // The real amount is the given number divided by 10^(precision of the token)
123
+ amount: 10000000,
124
+
125
+ // The same rules for these two fields
126
+ feeAssetId: 'WAVES',
127
+ fee: 100000,
128
+
129
+ // 140 bytes of data (it's allowed to use Uint8Array here)
130
+ attachment: '',
131
+
132
+ timestamp: Date.now()
133
+
134
+ };
135
+
136
+ Waves.API.Node.v1.assets.transfer(transferData, seed.keyPair).then((responseData) => {
137
+ console.log(responseData);
138
+ });
139
+ ```
140
+
141
+ ##### Reissue transaction
142
+
143
+ ```
144
+ const reissueData = {
145
+
146
+ // Asset ID which is to be additionnaly emitted
147
+ assetId: '5xN8XPkKi7RoYUAT5hNKC26FKCcX6Rj6epASpgFEYZss',
148
+
149
+ // Additional quantity is the given number divided by 10^(precision of the token)
150
+ quantity: 100000000,
151
+
152
+ reissuable: false,
153
+ fee: 100000000,
154
+ timestamp: Date.now()
155
+
156
+ };
157
+
158
+ Waves.API.Node.v1.assets.reissue(reissueData, seed.keyPair).then((responseData) => {
159
+ console.log(responseData);
160
+ });
161
+ ```
162
+
163
+ ##### Burn transaction
164
+
165
+ ```
166
+ const burnData = {
167
+
168
+ // Asset ID and its quantity to be burned
169
+ assetId: '5xN8XPkKi7RoYUAT5hNKC26FKCcX6Rj6epASpgFEYZss',
170
+ quantity: 20000000000,
171
+
172
+ fee: 100000,
173
+ timestamp: Date.now()
174
+
175
+ };
176
+
177
+ Waves.API.Node.v1.assets.burn(burnData, seed.keyPair).then((responseData) => {
178
+ console.log(responseData);
179
+ });
180
+ ```
181
+
182
+ ##### Lease transaction
183
+
184
+ ```
185
+ const leaseData = {
186
+
187
+ recipient: '5xN8XPkKi7RoYUAT5hNKC26FKCcX6Rj6epASpgFEYZss',
188
+
189
+ // Both amount and fee may be presented as divided by 10^8 (8 is Waves precision)
190
+ amount: 1000000000, // 10 Waves
191
+ fee: 100000, // 0.001 Waves
192
+
193
+ timestamp: Date.now()
194
+
195
+ };
196
+
197
+ Waves.API.Node.v1.leasing.lease(leaseData, seed.keyPair).then((responseData) => {
198
+ console.log(responseData);
199
+ });
200
+ ```
201
+
202
+ ##### Cancel Leasing transaction
203
+
204
+ ```
205
+ const cancelLeasingData = {
206
+
207
+ // Related Lease transaction ID
208
+ transactionId: '2kPvxtAit2nsumxBL7xYjvaWYmvmMfDL5oPgs4nZsHvZ',
209
+
210
+ fee: 100000,
211
+ timestamp: Date.now()
212
+
213
+ };
214
+
215
+ Waves.API.Node.v1.leasing.cancelLeasing(cancelLeasingData, seed.keyPair).then((responseData) => {
216
+ console.log(responseData);
217
+ });
218
+ ```
219
+
220
+ ##### Create Alias transaction
221
+
222
+ ```
223
+ const createAliasData = {
224
+
225
+ // That's a kind of a nickname you attach to your address
226
+ alias: 'xenohunter',
227
+
228
+ fee: 100000,
229
+ timestamp: Date.now()
230
+
231
+ };
232
+
233
+ Waves.API.Node.v1.aliases.createAlias(createAliasData, seed.keyPair).then((responseData) => {
234
+ console.log(responseData);
235
+ });
236
+ ```
237
+
238
+ #### Getting the information from Node
239
+
240
+ The most used GET requests are those related to balances and transactions history.
241
+
242
+ ##### Waves balance
243
+
244
+ There are two types of Waves balance: simple, with optional `confirmations` parameter, and detailed, showing different types of Waves balance.
245
+
246
+ With the first type, without additional arguments, you get the current balance on an address:
247
+
248
+ ```
249
+ Waves.API.Node.v1.addresses.balance('3PMgh8ra7v9USWUJxUCxKQKr6PM3MgqNVR8').then((balance) => {
250
+ console.log(balance);
251
+ });
252
+ ```
253
+
254
+ If you pass an optional `confirmations` argument, you get the balance with N confirmations, i.e. the balance as it was N blocks ago from the moment:
255
+
256
+ ```
257
+ Waves.API.Node.v1.addresses.balance('3PMgh8ra7v9USWUJxUCxKQKr6PM3MgqNVR8', 100).then((balance) => {
258
+ console.log(balance);
259
+ });
260
+ ```
261
+
262
+ For the second type, there is a separate method:
263
+
264
+ ```
265
+ Waves.API.Node.v1.addresses.balanceDetails('3PMgh8ra7v9USWUJxUCxKQKr6PM3MgqNVR8').then((balanceDetails) => {
266
+ console.log(balanceDetails);
267
+ });
268
+ ```
269
+
270
+ ##### Token balances
271
+
272
+ You can get the list of all balances on an address:
273
+
274
+ ```
275
+ Waves.API.Node.v1.assets.balances(address).then((balancesList) => {
276
+ console.log(balancesList);
277
+ });
278
+ ```
279
+
280
+ You also can get the balance of a given token:
281
+
282
+ ```
283
+ Waves.API.Node.v1.assets.balance(address, assetId).then((balance) => {
284
+ console.log(balance);
285
+ });
286
+ ```
287
+
288
+ ##### Token distribution
289
+
290
+ A very useful method allowing you to get a map with balances of all addresses in possession of a token:
291
+
292
+ ```
293
+ Waves.API.Node.v1.assets.distribution(assetId).then((distributionMap) => {
294
+ console.log(distributionMap);
295
+ });
296
+ ```
297
+
298
+ ##### Transactions
299
+
300
+ Every transaction in the blockchain has its own ID. You can both get one by ID, or get a list of all recent transactions.
301
+
302
+ ```
303
+ Waves.API.Node.v1.transactions.get('Bn2opYvcmYAMCaJHKP1uXYCHFGnAyrzGoiboBLT8RALt').then((tx) => {
304
+ console.log(tx);
305
+ });
306
+ ```
307
+
308
+ To get the list you need to provide an address which is either the sender or the recipient of the transactions in the resulting list:
309
+
310
+ ```
311
+ Waves.API.Node.v1.transactions.getList('3PMgh8ra7v9USWUJxUCxKQKr6PM3MgqNVR8').then((txList) => {
312
+ console.log(txList);
313
+ }):
314
+ ```
315
+
316
+ One of the concepts in most blockchains is UTX, unconfirmed transactions pool. During the time between blocks appearance, transactions from users are stored in it.
317
+
318
+ There are methods to get the size of UTX pool and UTX pool itself (note that the address is not needed here):
319
+
320
+ ```
321
+ Waves.API.Node.v1.transactions.utxSize().then((utxSize) => {
322
+ console.log(utxSize);
323
+ });
324
+
325
+ Waves.API.Node.v1.transactions.utxGetList().then((utxList) => {
326
+ console.log(utxList);
327
+ });
328
+ ```
329
+
330
+ Also if a transaction is still in UTX pool and you know its ID, you can get only it from UTX:
331
+
332
+ ```
333
+ Waves.API.Node.v1.transactions.utxGet('Bn2opYvcmYAMCaJHKP1uXYCHFGnAyrzGoiboBLT8RALt').then((tx) => {
334
+ console.log(tx);
335
+ });
336
+ ```
337
+
338
+ ##### Aliases
339
+
340
+ Aside from creating an alias, you also can get the list of aliases bound to an address, or get the address related to the given alias.
341
+
342
+ ```
343
+ Waves.API.Node.v1.aliases.byAddress('3PMgh8ra7v9USWUJxUCxKQKr6PM3MgqNVR8').then((aliasesList) => {
344
+ console.log(aliasesList);
345
+ });
346
+
347
+ Waves.API.Node.v1.aliases.byAlias('xenohunter').then((address) => {
348
+ console.log(address);
349
+ });
350
+ ```
351
+
352
+ ##### Blocks
353
+
354
+ Everything is simple here. You can get the whole block by its signature (`get()`) or height (`at()`). Method `height()` returns the current height of the Waves blockchain. The names of the remaining methods speak for themselves.
355
+
356
+ ```
357
+ Waves.API.Node.v1.blocks.get(signature).then((block) => console.log(block));
358
+
359
+ Waves.API.Node.v1.blocks.at(height).then((block) => console.log(block));
360
+
361
+ Waves.API.Node.v1.blocks.height().then((currentHeight) => console.log(currentHeight));
362
+
363
+ Waves.API.Node.v1.blocks.first().then((firstBlock) => console.log(firstBlock));
364
+
365
+ Waves.API.Node.v1.blocks.last().then((lastBlock) => console.log(lastBlock));
366
+ ```
367
+
368
+ ### Configuration
369
+
370
+ The configuration is changeable even during the runtime. The structure of the config is following:
371
+
372
+ ```
373
+ const newConfig = {
374
+
375
+ // The byte allowing to distinguish networks (mainnet, testnet, devnet, etc)
376
+ networkByte: Waves.constants.MAINNET_BYTE,
377
+
378
+ // Node and Matcher addresses, no comments here
379
+ nodeAddress: 'https://nodes.wavesnodes.com',
380
+ matcherAddress: 'https://nodes.wavesnodes.com/matcher',
381
+
382
+ // If a seed phrase length falls below that value an error will be thrown
383
+ minimumSeedLength: 50
384
+
385
+ };
386
+ ```
387
+
388
+ All fields are optional, only filled ones will be replaced.
389
+
390
+ You can change the config like that:
391
+
392
+ ```
393
+ Waves.config.set(newConfig);
394
+ ```
395
+
396
+ ### Tools
397
+
398
+ #### Get address from public key
399
+
400
+ ```
401
+ const address = Waves.tools.getAddressFromPublicKey('GL6Cbk3JnD9XiBRK5ntCavSrGGD5JT9pXSRkukcEcaSW');
402
+ console.log(address); // '3N1JKsPcQ5x49utR79Maey4tbjssfrn2RYp'
403
+ ```
404
+
405
+ ## Common pitfalls
406
+
407
+ ### Precision and coins-to-tokens transformation
408
+
409
+ In Waves blockchain different tokens have different precision, i.e. number of decimal digits. For example, it would be 10.00 USD and 10.00000000 BTC. That distinction allows to create tokens for various purposes but also makes things harder to understand sometimes.
410
+
411
+ Two words have emerged: _token_ and _coin_. Token is used to refer to the whole part of the amount. Coin describes the smallest value which is possible for a given token. For USD _token_ would be one dollar, and _coin_ would be one cent. If you are familiar with Bitcoin you could have encountered the word _Satoshi_ which refers to one hundred millionth of a single Bitcoin.
412
+
413
+ In the blockchain every token is stored with its explicitly specified precision and amount of coins. Every transaction is signed and stored in the blockchain in its coin representation. So if you send 2 USD tokens to someone, you really send 200 USD token coins instead.
414
+
415
+ The same goes for the fees, and issue transactions, and leasing amounts, and so on.
416
+
417
+ Waves precision equals 8. Therefore there are `100000000 * 10^8` of Waves coins (Wavelets) in Waves blockchain.
418
+
419
+ ### Reissuability and the additive nature of it
420
+
421
+ The amount in reissue transactions refer not to the final amount of asset after reissuing but to the amount which will be added to the current token amount.
422
+
423
+ ### Waves ID in the library and in the blockchain
424
+
425
+ One of the trickiest things about Waves blockchain is that Waves ID equals empty string. In the first version on Node API it also equals to empty string. That is an unobvious and potentially dangerous behavior. Therefore in this library Waves ID strictly equals string `WAVES`. Please mind that fact.
426
+
427
+ ### Fee asset choice for transfer transactions
428
+
429
+ There is only one type of transactions (currently) in which we can use arbitrary tokens as fees. The only limitation is that the Node to which you connect must support the token you use as fees. Please note that transactions with the Waves fee will be prior over transactions with fees in other tokens.
430
+
431
+ ### Impossibility of transactions with the absolutely same data
432
+
433
+ Transaction IDs are built from all the data in a transaction except the signature. That process is deterministic. So there cannot be two transactions with the absolutely same data.
434
+
435
+ ### Delays in the leasing process
436
+
437
+ For the security reasons all leased Waves take effect only after 1000 blocks. Don't worry when your generating balance isn't updated right away.
438
+
439
+ ### Mess with balances in the first version of API
440
+
441
+ It happened so that Waves balance and token balances are served through different API methods in the first version of Waves API. That's not very useful and we designed the new version otherwise.
442
+
443
+ ### Different types of Waves balance
444
+
445
+ There is the most understandable type of Waves balance. It is the regular balance. It is served through `Waves.API.Node.v1.addresses.balance()`. There are also several types of Waves balance related to leasing and the delays in its processing.
446
+
447
+ 1. *Regular* — that's how much Waves you have, including those you leased;
448
+ 2. *Available* — the same as _regular_ only without Waves you leased;
449
+ 3. *Effective* — _available_ plus those Waves which is leased to you;
450
+ 4. *Generating* — the minimal _effective_ for last 1000 blocks;
451
+ 5. *Leased* — the amount you leased to other addresses.
452
+
453
+ Available balance you can lease and spend.
454
+
455
+ Generating balance gives you mining power.
456
+
457
+ ## Tests
458
+
459
+ ```
460
+ cd ./node_modules/waves-api/
461
+ npm install
462
+ npm run test # to run tests in Node.js
463
+ npm run test-browser # to run test in Chrome browser
464
+ ```
465
+
466
+ Test configuration may be changed in the _./node_modules/waves-api/karma.conf.js_ file.
467
+
468
+ ## Tools
469
+
470
+ * [TypeScript](https://www.typescriptlang.org/) - Typed superset of JavaScript
471
+ * [Karma](https://karma-runner.github.io/1.0/index.html) - Test runner
472
+ * [Chai](http://chaijs.com/) - Assertion library
473
+
474
+ ## Authors
475
+
476
+ * [**Phil Filippak**](https://github.com/xenohunter) - *Initial work*
477
+ * [**Daniil Tsigelnitskiy**](https://github.com/tsigel) - *TypeScript expertise*
478
+
479
+ See also the list of [contributors](https://github.com/xenohunter/waves-api/contributors) who participated in this project.
480
+
481
+ ## License
482
+
483
+ This project is licensed under the MIT License - see the [LICENSE.md](LICENSE.md) file for details.
484
+
485
+ ## See also
486
+
487
+ * [Waves API design repository](https://github.com/wavesplatform/swagger-api-design)