@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.
- package/LICENSE +88 -88
- package/README.md +4 -4
- package/exports/chain.js +1071 -0
- package/exports/node.js +23 -0
- package/exports/typings/chain.d.ts +83 -0
- package/exports/typings/config/config.d.ts +1 -0
- package/exports/typings/config/main.d.ts +5 -0
- package/exports/typings/config/protocol.d.ts +6 -0
- package/exports/typings/contract.d.ts +29 -0
- package/exports/typings/fee/config.d.ts +4 -0
- package/exports/typings/machine.d.ts +26 -0
- package/exports/typings/node.d.ts +9 -0
- package/exports/typings/protocol.d.ts +4 -0
- package/exports/typings/state.d.ts +5 -0
- package/exports/typings/transaction.d.ts +47 -0
- package/exports/typings/typer.d.ts +6 -0
- package/package.json +77 -75
- package/CHANGELOG.md +0 -14
- package/block-worker.js +0 -1
- package/demo/865.browser.js +0 -10
- package/demo/chain.browser.js +0 -66842
- package/demo/generate-account.browser.js +0 -50
- package/demo/index.html +0 -25
- package/demo/messages.browser.js +0 -328
- package/demo/multi-wallet.browser.js +0 -15
- package/demo/node.browser.js +0 -9858
- package/demo/pako.browser.js +0 -6900
- package/demo/peernet-swarm.browser.js +0 -839
- package/demo/storage.browser.js +0 -3724
- package/demo/workers/865.js +0 -10
- package/demo/workers/block-worker.js +0 -13175
- package/demo/workers/machine-worker.js +0 -13385
- package/demo/workers/pool-worker.js +0 -8503
- package/demo/workers/transaction-worker.js +0 -8495
- package/demo/wrtc.browser.js +0 -28
- package/dist/browser/workers/865.js +0 -10
- package/dist/browser/workers/block-worker.js +0 -9460
- package/dist/browser/workers/machine-worker.js +0 -9670
- package/dist/browser/workers/pool-worker.js +0 -4608
- package/dist/browser/workers/transaction-worker.js +0 -4600
- package/dist/chain.js +0 -10128
- package/dist/client-80bc8156.js +0 -491
- package/dist/commonjs-7fe3c381.js +0 -270
- package/dist/contracts/factory.js +0 -1
- package/dist/contracts/name-service.js +0 -1
- package/dist/contracts/native-token.js +0 -1
- package/dist/contracts/validators.js +0 -1
- package/dist/generate-account-445db122.js +0 -46
- package/dist/index-57f93805.js +0 -718
- package/dist/messages-bce1b91d-81af3b00.js +0 -315
- package/dist/module/chain.js +0 -10091
- package/dist/module/client-8031ec88.js +0 -489
- package/dist/module/commonjs-9005d5c0.js +0 -268
- package/dist/module/generate-account-489552b6.js +0 -44
- package/dist/module/index-ac2285c4.js +0 -688
- package/dist/module/messages-bce1b91d-eaf75d83.js +0 -302
- package/dist/module/node.js +0 -7049
- package/dist/module/workers/block-worker.js +0 -94
- package/dist/module/workers/machine-worker.js +0 -304
- package/dist/module/workers/pool-worker.js +0 -55
- package/dist/module/workers/transaction-worker.js +0 -47
- package/dist/node.js +0 -7061
- package/dist/standards/token.js +0 -1
- package/dist/workers/machine-worker.js +0 -1
- package/dist/workers/pool-worker.js +0 -1
- package/dist/workers/transaction-worker.js +0 -1
- package/examples/contracts/token.js +0 -7
- package/plugins/bundle.js +0 -18
- package/rollup.config.js +0 -15
- package/src/chain.ts +0 -710
- package/src/config/config.js +0 -14
- package/src/config/main.js +0 -4
- package/src/config/protocol.js +0 -5
- package/src/contract.js +0 -52
- package/src/fee/config.js +0 -3
- package/src/machine.js +0 -215
- package/src/node.ts +0 -24
- package/src/protocol.js +0 -4
- package/src/state.js +0 -31
- package/src/transaction.ts +0 -182
- package/src/type.index.d.ts +0 -21
- package/src/typer.js +0 -19
- package/test/chain.js +0 -150
- package/test/contracts/token.js +0 -40
- package/test/create-genesis.js +0 -66
- package/test/index.js +0 -1
- package/tsconfig.json +0 -17
- package/workers/block-worker.js +0 -40
- package/workers/machine-worker.js +0 -219
- package/workers/pool-worker.js +0 -28
- package/workers/transaction-worker.js +0 -20
- 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;
|