@leofcoin/chain 1.4.21 → 1.4.22

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 (78) hide show
  1. package/CHANGELOG.md +14 -14
  2. package/LICENSE +88 -88
  3. package/README.md +4 -4
  4. package/demo/index.html +25 -25
  5. package/examples/contracts/token.js +7 -7
  6. package/package.json +71 -75
  7. package/plugins/bundle.js +18 -18
  8. package/src/{chain.ts → chain.js} +716 -710
  9. package/src/config/config.js +14 -14
  10. package/src/config/main.js +4 -4
  11. package/src/config/protocol.js +5 -5
  12. package/src/contract.js +51 -51
  13. package/src/fee/config.js +3 -3
  14. package/src/machine.js +215 -215
  15. package/src/{node.ts → node.js} +24 -24
  16. package/src/protocol.js +3 -3
  17. package/src/state.js +31 -31
  18. package/src/{transaction.ts → transaction.js} +233 -181
  19. package/src/type.index.d.ts +20 -20
  20. package/src/typer.js +19 -19
  21. package/test/chain.js +120 -150
  22. package/test/contracts/token.js +40 -40
  23. package/test/create-genesis.js +66 -66
  24. package/tsconfig.js +15 -0
  25. package/workers/block-worker.js +40 -40
  26. package/workers/machine-worker.js +218 -218
  27. package/workers/pool-worker.js +28 -28
  28. package/workers/transaction-worker.js +19 -19
  29. package/workers/workers.js +8 -8
  30. package/block-worker.js +0 -1
  31. package/demo/865.browser.js +0 -10
  32. package/demo/chain.browser.js +0 -66842
  33. package/demo/generate-account.browser.js +0 -50
  34. package/demo/messages.browser.js +0 -328
  35. package/demo/multi-wallet.browser.js +0 -15
  36. package/demo/node.browser.js +0 -9858
  37. package/demo/pako.browser.js +0 -6900
  38. package/demo/peernet-swarm.browser.js +0 -839
  39. package/demo/storage.browser.js +0 -3724
  40. package/demo/workers/865.js +0 -10
  41. package/demo/workers/block-worker.js +0 -13175
  42. package/demo/workers/machine-worker.js +0 -13385
  43. package/demo/workers/pool-worker.js +0 -8503
  44. package/demo/workers/transaction-worker.js +0 -8495
  45. package/demo/wrtc.browser.js +0 -28
  46. package/dist/browser/workers/865.js +0 -10
  47. package/dist/browser/workers/block-worker.js +0 -9460
  48. package/dist/browser/workers/machine-worker.js +0 -9670
  49. package/dist/browser/workers/pool-worker.js +0 -4608
  50. package/dist/browser/workers/transaction-worker.js +0 -4600
  51. package/dist/chain.js +0 -10128
  52. package/dist/client-80bc8156.js +0 -491
  53. package/dist/commonjs-7fe3c381.js +0 -270
  54. package/dist/contracts/factory.js +0 -1
  55. package/dist/contracts/name-service.js +0 -1
  56. package/dist/contracts/native-token.js +0 -1
  57. package/dist/contracts/validators.js +0 -1
  58. package/dist/generate-account-445db122.js +0 -46
  59. package/dist/index-57f93805.js +0 -718
  60. package/dist/messages-bce1b91d-81af3b00.js +0 -315
  61. package/dist/module/chain.js +0 -10091
  62. package/dist/module/client-8031ec88.js +0 -489
  63. package/dist/module/commonjs-9005d5c0.js +0 -268
  64. package/dist/module/generate-account-489552b6.js +0 -44
  65. package/dist/module/index-ac2285c4.js +0 -688
  66. package/dist/module/messages-bce1b91d-eaf75d83.js +0 -302
  67. package/dist/module/node.js +0 -7049
  68. package/dist/module/workers/block-worker.js +0 -94
  69. package/dist/module/workers/machine-worker.js +0 -304
  70. package/dist/module/workers/pool-worker.js +0 -55
  71. package/dist/module/workers/transaction-worker.js +0 -47
  72. package/dist/node.js +0 -7061
  73. package/dist/standards/token.js +0 -1
  74. package/dist/workers/machine-worker.js +0 -1
  75. package/dist/workers/pool-worker.js +0 -1
  76. package/dist/workers/transaction-worker.js +0 -1
  77. package/rollup.config.js +0 -15
  78. package/tsconfig.json +0 -17
@@ -1,268 +0,0 @@
1
- var path = require('path');
2
- var os = require('os');
3
- var fs = require('fs');
4
- var child_process = require('child_process');
5
- var classicLevel = require('classic-level');
6
-
7
- // import base32 from '@vandeurenglenn/base32'
8
- // import base58 from '@vandeurenglenn/base58'
9
-
10
- // export const encodings = {
11
- // base58,
12
- // base32
13
- // }
14
-
15
- const encode = (string, encoding = 'utf-8') => {
16
- if (typeof string === 'string') {
17
- let encoded;
18
-
19
- // if (encodings[encoding]) encoded = encodings[encoding].encode(encoded)
20
- encoded = new TextEncoder().encode(string);
21
- return encoded
22
- }
23
- throw Error(`expected typeof String instead got ${string}`)
24
- };
25
-
26
- const decode = (uint8Array, encoding) => {
27
- if (uint8Array instanceof Uint8Array) {
28
- let decoded;
29
- // if (encodings[encoding]) decoded = encodings[encoding].decode(decoded)
30
- decoded = new TextDecoder().decode(uint8Array);
31
-
32
- return decoded
33
- }
34
- throw Error(`expected typeof uint8Array instead got ${uint8Array}`)
35
- };
36
-
37
- const pathSepS = '/';
38
- class KeyPath {
39
-
40
- /**
41
- * @param {string | Uint8Array} input
42
- */
43
- constructor(input) {
44
- if (typeof input === 'string') {
45
- this.uint8Array = encode(input);
46
- } else if (input instanceof Uint8Array) {
47
- this.uint8Array = input;
48
- } else if (input instanceof KeyPath) {
49
- this.uint8Array = input.uint8Array;
50
- } else {
51
- throw new Error('Invalid keyPath, should be a String, Uint8Array or KeyPath')
52
- }
53
- }
54
-
55
- /**
56
- * Convert to the string representation
57
- *
58
- * @param {import('uint8arrays/to-string').SupportedEncodings} [encoding='utf8'] - The encoding to use.
59
- * @returns {string}
60
- */
61
- toString (encoding = 'hex') {
62
- return decode(this.uint8Array)
63
- }
64
-
65
- /**
66
- * Returns the `list` representation of this path.
67
- *
68
- * @returns {Array<string>}
69
- *
70
- * @example
71
- * ```js
72
- * new Key('/Comedy/MontyPython/Actor:JohnCleese').list()
73
- * // => ['Comedy', 'MontyPythong', 'Actor:JohnCleese']
74
- * ```
75
- */
76
- list() {
77
- return this.toString().split(pathSepS).slice(1)
78
- }
79
-
80
- }
81
-
82
- class KeyValue {
83
-
84
- /**
85
- * @param {string | Uint8Array} input
86
- */
87
- constructor(input) {
88
- if (typeof input === 'string') {
89
- this.uint8Array = encode(input);
90
- } else if (input instanceof Uint8Array) {
91
- this.uint8Array = input;
92
- } else if (input instanceof KeyValue) {
93
- this.uint8Array = input.uint8Array;
94
- } else {
95
- throw new Error('Invalid KeyValue, should be a String, Uint8Array or KeyValue')
96
- }
97
- }
98
-
99
- /**
100
- * Convert to the string representation
101
- *
102
- * @param {import('uint8arrays/to-string').SupportedEncodings} [encoding='utf8'] - The encoding to use.
103
- * @returns {string}
104
- */
105
- toString(encoding = 'utf8') {
106
- return decode(this.uint8Array)
107
- }
108
-
109
- }
110
-
111
- const mkdirp = path => child_process.execSync(`mkdir "${path.replace(/\//g, '\\')}"`);
112
-
113
- const init = (root, home = true) => {
114
- let _root;
115
- if (home) _root = path.join(os.homedir(), root);
116
- if (fs.readdirSync) try {
117
- fs.readdirSync(_root);
118
- } catch (e) {
119
- mkdirp(_root);
120
- }
121
-
122
- return _root
123
- };
124
-
125
- class Store {
126
- constructor(name = 'storage', root, version = 'v1.0.0') {
127
- this.name = name;
128
- this.root = init(root);
129
- this.version = version;
130
-
131
- this.db = new classicLevel.ClassicLevel(path.join(this.root, this.name), { valueEncoding: 'view'});
132
- }
133
-
134
- toKeyPath(key) {
135
- return key ? key.toString('base32') : key
136
- }
137
-
138
- toKeyValue(value) {
139
- return value.uint8Array
140
- }
141
-
142
- async get(key) {
143
- return this.db.get(this.toKeyPath(key))
144
- }
145
-
146
- async put(key, value) {
147
- return this.db.put(this.toKeyPath(key), this.toKeyValue(value))
148
- }
149
-
150
- async delete(key) {
151
- return this.db.del(this.toKeyPath(key))
152
- }
153
-
154
- async clear() {
155
- return this.db.clear()
156
- }
157
-
158
- async values(limit = -1) {
159
- const values = [];
160
- for await (const value of this.db.values({limit})) {
161
- values.push(value);
162
- }
163
- return values
164
- }
165
-
166
- async keys(limit = -1) {
167
- const keys = [];
168
- for await (const key of this.db.keys({limit})) {
169
- keys.push(key);
170
- }
171
- return keys
172
- }
173
-
174
- }
175
-
176
- class LeofcoinStorage {
177
-
178
- constructor(name = 'storage', root = '.leofcoin') {
179
- this.name = name;
180
- this.db = new Store(name, root);
181
- }
182
-
183
- async get(key) {
184
- if (!key) return this.query()
185
- if (typeof key === 'object') return this.many('get', key);
186
- return this.db.get(new KeyPath(key))
187
- }
188
-
189
- /**
190
- *
191
- * @param {*} key
192
- * @param {*} value
193
- * @returns Promise
194
- */
195
- put(key, value) {
196
- if (typeof key === 'object') return this.many('put', key);
197
- return this.db.put(new KeyPath(key), new KeyValue(value));
198
- }
199
-
200
- async has(key) {
201
- if (typeof key === 'object') return this.many('has', key);
202
-
203
- try {
204
- const has = await this.db.get(new KeyPath(key));
205
-
206
- return Boolean(has);
207
- } catch (e) {
208
- return false
209
- }
210
- }
211
-
212
- async delete(key) {
213
- return this.db.delete(new KeyPath(key))
214
- }
215
-
216
- keys(limit = -1) {
217
- return this.db.keys({limit})
218
- }
219
-
220
- async #queryJob(key) {
221
- const value = await this.db.get(key);
222
- return { key, value }
223
- }
224
-
225
- async query() {
226
- const keys = await this.keys();
227
- let promises = [];
228
- for (const key of keys) {
229
- promises.push(this.#queryJob(key));
230
- }
231
- return Promise.all(promises)
232
- }
233
-
234
- async values(limit = -1) {
235
- return this.db.values({limit})
236
- }
237
-
238
- async many(type, _value) {
239
- const jobs = [];
240
-
241
- for (const key of Object.keys(_value)) {
242
- jobs.push(this[type](key, _value[key]));
243
- }
244
-
245
- return Promise.all(jobs)
246
- }
247
-
248
- async length() {
249
- const keys = await this.keys();
250
- return keys.length
251
- }
252
-
253
- async size() {
254
- let size = 0;
255
- const query = await this.query();
256
- for (const item of query) {
257
- size += item.value.length;
258
- }
259
- return size
260
- }
261
-
262
- async clear() {
263
- return this.db.clear()
264
- }
265
-
266
- }
267
-
268
- module.exports = LeofcoinStorage;
@@ -1,44 +0,0 @@
1
- var MultiWallet = require('@leofcoin/multi-wallet');
2
-
3
- function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
4
-
5
- var MultiWallet__default = /*#__PURE__*/_interopDefaultLegacy(MultiWallet);
6
-
7
- /**
8
- * @params {String} network
9
- * @return {object} { identity, accounts, config }
10
- */
11
- var generateAccount = async network => {
12
- let wallet = new MultiWallet__default["default"](network);
13
- /**
14
- * @type {string}
15
- */
16
- const mnemonic = await wallet.generate();
17
-
18
- wallet = new MultiWallet__default["default"](network);
19
- await wallet.recover(mnemonic, network);
20
- /**
21
- * @type {object}
22
- */
23
- const account = wallet.account(0);
24
- /**
25
- * @type {object}
26
- */
27
- const external = account.external(0);
28
- const internal = account.internal(0);
29
-
30
- return {
31
- identity: {
32
- mnemonic,
33
- // multiWIF: wallet.export(),
34
- publicKey: external.publicKey,
35
- privateKey: external.privateKey,
36
- walletId: external.id
37
- },
38
- accounts: [['main account', external.address, internal.address]]
39
- // config: {
40
- // }
41
- }
42
- };
43
-
44
- module.exports = generateAccount;