@leofcoin/chain 1.4.21 → 1.4.23

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 (92) hide show
  1. package/LICENSE +88 -88
  2. package/README.md +4 -4
  3. package/exports/chain.js +1071 -0
  4. package/exports/node.js +23 -0
  5. package/exports/typings/chain.d.ts +83 -0
  6. package/exports/typings/config/config.d.ts +1 -0
  7. package/exports/typings/config/main.d.ts +5 -0
  8. package/exports/typings/config/protocol.d.ts +6 -0
  9. package/exports/typings/contract.d.ts +29 -0
  10. package/exports/typings/fee/config.d.ts +4 -0
  11. package/exports/typings/machine.d.ts +26 -0
  12. package/exports/typings/node.d.ts +9 -0
  13. package/exports/typings/protocol.d.ts +4 -0
  14. package/exports/typings/state.d.ts +5 -0
  15. package/exports/typings/transaction.d.ts +47 -0
  16. package/exports/typings/typer.d.ts +6 -0
  17. package/package.json +77 -75
  18. package/CHANGELOG.md +0 -14
  19. package/block-worker.js +0 -1
  20. package/demo/865.browser.js +0 -10
  21. package/demo/chain.browser.js +0 -66842
  22. package/demo/generate-account.browser.js +0 -50
  23. package/demo/index.html +0 -25
  24. package/demo/messages.browser.js +0 -328
  25. package/demo/multi-wallet.browser.js +0 -15
  26. package/demo/node.browser.js +0 -9858
  27. package/demo/pako.browser.js +0 -6900
  28. package/demo/peernet-swarm.browser.js +0 -839
  29. package/demo/storage.browser.js +0 -3724
  30. package/demo/workers/865.js +0 -10
  31. package/demo/workers/block-worker.js +0 -13175
  32. package/demo/workers/machine-worker.js +0 -13385
  33. package/demo/workers/pool-worker.js +0 -8503
  34. package/demo/workers/transaction-worker.js +0 -8495
  35. package/demo/wrtc.browser.js +0 -28
  36. package/dist/browser/workers/865.js +0 -10
  37. package/dist/browser/workers/block-worker.js +0 -9460
  38. package/dist/browser/workers/machine-worker.js +0 -9670
  39. package/dist/browser/workers/pool-worker.js +0 -4608
  40. package/dist/browser/workers/transaction-worker.js +0 -4600
  41. package/dist/chain.js +0 -10128
  42. package/dist/client-80bc8156.js +0 -491
  43. package/dist/commonjs-7fe3c381.js +0 -270
  44. package/dist/contracts/factory.js +0 -1
  45. package/dist/contracts/name-service.js +0 -1
  46. package/dist/contracts/native-token.js +0 -1
  47. package/dist/contracts/validators.js +0 -1
  48. package/dist/generate-account-445db122.js +0 -46
  49. package/dist/index-57f93805.js +0 -718
  50. package/dist/messages-bce1b91d-81af3b00.js +0 -315
  51. package/dist/module/chain.js +0 -10091
  52. package/dist/module/client-8031ec88.js +0 -489
  53. package/dist/module/commonjs-9005d5c0.js +0 -268
  54. package/dist/module/generate-account-489552b6.js +0 -44
  55. package/dist/module/index-ac2285c4.js +0 -688
  56. package/dist/module/messages-bce1b91d-eaf75d83.js +0 -302
  57. package/dist/module/node.js +0 -7049
  58. package/dist/module/workers/block-worker.js +0 -94
  59. package/dist/module/workers/machine-worker.js +0 -304
  60. package/dist/module/workers/pool-worker.js +0 -55
  61. package/dist/module/workers/transaction-worker.js +0 -47
  62. package/dist/node.js +0 -7061
  63. package/dist/standards/token.js +0 -1
  64. package/dist/workers/machine-worker.js +0 -1
  65. package/dist/workers/pool-worker.js +0 -1
  66. package/dist/workers/transaction-worker.js +0 -1
  67. package/examples/contracts/token.js +0 -7
  68. package/plugins/bundle.js +0 -18
  69. package/rollup.config.js +0 -15
  70. package/src/chain.ts +0 -710
  71. package/src/config/config.js +0 -14
  72. package/src/config/main.js +0 -4
  73. package/src/config/protocol.js +0 -5
  74. package/src/contract.js +0 -52
  75. package/src/fee/config.js +0 -3
  76. package/src/machine.js +0 -215
  77. package/src/node.ts +0 -24
  78. package/src/protocol.js +0 -4
  79. package/src/state.js +0 -31
  80. package/src/transaction.ts +0 -182
  81. package/src/type.index.d.ts +0 -21
  82. package/src/typer.js +0 -19
  83. package/test/chain.js +0 -150
  84. package/test/contracts/token.js +0 -40
  85. package/test/create-genesis.js +0 -66
  86. package/test/index.js +0 -1
  87. package/tsconfig.json +0 -17
  88. package/workers/block-worker.js +0 -40
  89. package/workers/machine-worker.js +0 -219
  90. package/workers/pool-worker.js +0 -28
  91. package/workers/transaction-worker.js +0 -20
  92. package/workers/workers.js +0 -9
@@ -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;