@leofcoin/chain 1.4.36 → 1.4.37
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/exports/browser/chain.js +122 -4324
- package/exports/browser/client-033977a1-60f68d3b.js +41066 -0
- package/exports/browser/contract-32687834.js +6071 -0
- package/exports/browser/{index-1ce30988-44319c80.js → index-123daa04-05013cc5.js} +2 -2
- package/exports/browser/{messages-e025829d-a0354268.js → messages-5ddc1083-1bd0ab64.js} +2 -2
- package/exports/browser/{node-browser-64b82fc8.js → node-browser-c95add6b.js} +60 -56
- package/exports/browser/node-browser.js +2 -2
- package/exports/browser/workers/block-worker.js +6069 -0
- package/exports/browser/workers/machine-worker.js +6279 -0
- package/exports/chain.js +104 -94
- package/exports/node.js +2 -1
- package/exports/typings/chain.d.ts +4 -2
- package/exports/typings/contract.d.ts +1 -0
- package/exports/typings/node.d.ts +1 -0
- package/exports/typings/transaction.d.ts +1 -1
- package/package.json +4 -2
- package/exports/browser/browser-10ffabe1-10ffabe1.js +0 -56
- package/exports/browser/browser-e1cd4e67-e1cd4e67.js +0 -198
- package/exports/browser/client-111c93a3-b0dcdc19.js +0 -612
- package/exports/browser/client-1d0234a7-df40059a.js +0 -624
- package/exports/browser/client-21cee984-77440b6b.js +0 -624
- package/exports/browser/contract-163f031f.js +0 -1859
- package/exports/browser/index-3d3f56ca-064d16ce.js +0 -37
- package/exports/browser/index-543bc6a3-be806e11.js +0 -37
- package/exports/browser/messages-48deb2c3-73e8ace1.js +0 -205
- package/exports/browser/messages-af41e873-479a93a8.js +0 -205
- package/exports/browser/node-browser-13cbe71a.js +0 -16881
- package/exports/browser/node-browser-63c7cb33.js +0 -16877
- package/exports/browser/pako.esm-aa674ebf-aa674ebf.js +0 -6876
- package/exports/browser/simple-peer-743c19fe-03a0830e.js +0 -7856
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { M as MultiWallet, e as encrypt, b as base58$1 } from './node-browser-
|
|
2
|
-
import './contract-
|
|
1
|
+
import { M as MultiWallet, e as encrypt, b as base58$1 } from './node-browser-c95add6b.js';
|
|
2
|
+
import './contract-32687834.js';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* @params {String} network
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { C as ContractMessage, T as TransactionMessage,
|
|
1
|
+
import { C as ContractMessage, T as TransactionMessage, d as BlockMessage, e as BWMessage, f as BWRequestMessage, V as ValidatorMessage } from './contract-32687834.js';
|
|
2
2
|
|
|
3
3
|
var nodeConfig = async (config = {
|
|
4
4
|
network: 'leofcoin:peach',
|
|
@@ -2206,7 +2206,7 @@ class DhtEarth {
|
|
|
2206
2206
|
const address = await getAddress();
|
|
2207
2207
|
const peerLoc = await this.getCoordinates(address);
|
|
2208
2208
|
for (const provider of providers) {
|
|
2209
|
-
if (provider.address === '127.0.0.1')
|
|
2209
|
+
if (provider.address === '127.0.0.1' || provider.address === '::1')
|
|
2210
2210
|
all.push({ provider, distance: 0 });
|
|
2211
2211
|
else
|
|
2212
2212
|
all.push(this.getDistance(peerLoc, provider));
|
|
@@ -2273,9 +2273,9 @@ class MessageHandler {
|
|
|
2273
2273
|
const dataHandler = async (message) => {
|
|
2274
2274
|
if (!message)
|
|
2275
2275
|
return;
|
|
2276
|
-
const { data, id, from } = message;
|
|
2276
|
+
const { data, id, from, peer } = message;
|
|
2277
2277
|
const proto = await protoFor(data);
|
|
2278
|
-
peernet._protoHandler({ id, proto }, peernet.
|
|
2278
|
+
peernet._protoHandler({ id, proto }, peernet.connections[from] || peer, from);
|
|
2279
2279
|
};
|
|
2280
2280
|
|
|
2281
2281
|
const dhtError = (proto) => {
|
|
@@ -2683,6 +2683,10 @@ var index = {
|
|
|
2683
2683
|
|
|
2684
2684
|
var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
|
|
2685
2685
|
|
|
2686
|
+
function getDefaultExportFromCjs (x) {
|
|
2687
|
+
return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
|
|
2688
|
+
}
|
|
2689
|
+
|
|
2686
2690
|
function getAugmentedNamespace(n) {
|
|
2687
2691
|
if (n.__esModule) return n;
|
|
2688
2692
|
var f = n.default;
|
|
@@ -16165,7 +16169,7 @@ class Identity {
|
|
|
16165
16169
|
globalThis.peernet.selectedAccount = new TextDecoder().decode(selected);
|
|
16166
16170
|
}
|
|
16167
16171
|
else {
|
|
16168
|
-
const importee = await import(/* webpackChunkName: "generate-account" */ './index-
|
|
16172
|
+
const importee = await import(/* webpackChunkName: "generate-account" */ './index-123daa04-05013cc5.js');
|
|
16169
16173
|
const { identity, accounts } = await importee.default(password, this.network);
|
|
16170
16174
|
await globalThis.accountStore.put('public', JSON.stringify({ walletId: identity.walletId }));
|
|
16171
16175
|
await globalThis.walletStore.put('version', String(1));
|
|
@@ -16229,6 +16233,7 @@ class Peernet {
|
|
|
16229
16233
|
autoStart = true;
|
|
16230
16234
|
#starting = false;
|
|
16231
16235
|
#started = false;
|
|
16236
|
+
#connections = {};
|
|
16232
16237
|
/**
|
|
16233
16238
|
* @access public
|
|
16234
16239
|
* @param {Object} options
|
|
@@ -16307,13 +16312,13 @@ class Peernet {
|
|
|
16307
16312
|
* @return {Array} peerId
|
|
16308
16313
|
*/
|
|
16309
16314
|
get peers() {
|
|
16310
|
-
return Object.
|
|
16315
|
+
return Object.values(this.#connections);
|
|
16311
16316
|
}
|
|
16312
16317
|
get connections() {
|
|
16313
|
-
return Object.values(this
|
|
16318
|
+
return Object.values(this.#connections);
|
|
16314
16319
|
}
|
|
16315
16320
|
get peerEntries() {
|
|
16316
|
-
return Object.
|
|
16321
|
+
return Object.values(this.#connections);
|
|
16317
16322
|
}
|
|
16318
16323
|
/**
|
|
16319
16324
|
* @return {String} id - peerId
|
|
@@ -16335,7 +16340,7 @@ class Peernet {
|
|
|
16335
16340
|
this.root = options.root;
|
|
16336
16341
|
const { RequestMessage, ResponseMessage, PeerMessage, PeerMessageResponse, PeernetMessage, DHTMessage, DHTMessageResponse, DataMessage, DataMessageResponse, PsMessage, ChatMessage, PeernetFile
|
|
16337
16342
|
// FolderMessageResponse
|
|
16338
|
-
} = await import(/* webpackChunkName: "messages" */ './messages-
|
|
16343
|
+
} = await import(/* webpackChunkName: "messages" */ './messages-5ddc1083-1bd0ab64.js');
|
|
16339
16344
|
/**
|
|
16340
16345
|
* proto Object containing protos
|
|
16341
16346
|
* @type {Object}
|
|
@@ -16369,15 +16374,19 @@ class Peernet {
|
|
|
16369
16374
|
await this.identity.load(password);
|
|
16370
16375
|
this._peerHandler = new PeerDiscovery(this.id);
|
|
16371
16376
|
this.peerId = this.id;
|
|
16372
|
-
|
|
16377
|
+
this.addRequestHandler('handshake', () => {
|
|
16378
|
+
return new peernet.protos['peernet-response']({ response: { peerId: this.id } });
|
|
16379
|
+
});
|
|
16380
|
+
pubsub.subscribe('peer:discovered', async (peer) => {
|
|
16373
16381
|
// console.log(peer);
|
|
16374
|
-
|
|
16375
|
-
|
|
16376
|
-
|
|
16377
|
-
|
|
16378
|
-
//
|
|
16379
|
-
|
|
16380
|
-
|
|
16382
|
+
let data = await new globalThis.peernet.protos['peernet-request']({ request: 'handshake' });
|
|
16383
|
+
let node = await globalThis.peernet.prepareMessage(data);
|
|
16384
|
+
let response = await peer.request(node.encoded);
|
|
16385
|
+
response = await new globalThis.peernet.protos['peernet-response'](new Uint8Array(Object.values(response)));
|
|
16386
|
+
// todo: response.decoded should be the response and not response.peerId
|
|
16387
|
+
this.#connections[response.decoded.response.peerId] = peer;
|
|
16388
|
+
pubsub.publish('peer:connected', peer);
|
|
16389
|
+
// todo: cleanup discovered
|
|
16381
16390
|
});
|
|
16382
16391
|
/**
|
|
16383
16392
|
* converts data -> message -> proto
|
|
@@ -16402,7 +16411,7 @@ class Peernet {
|
|
|
16402
16411
|
if (this.#starting || this.#started)
|
|
16403
16412
|
return;
|
|
16404
16413
|
this.#starting = true;
|
|
16405
|
-
const importee = await import('./client-
|
|
16414
|
+
const importee = await import('./client-033977a1-60f68d3b.js');
|
|
16406
16415
|
/**
|
|
16407
16416
|
* @access public
|
|
16408
16417
|
* @type {PeernetClient}
|
|
@@ -16414,12 +16423,13 @@ class Peernet {
|
|
|
16414
16423
|
addRequestHandler(name, method) {
|
|
16415
16424
|
this.requestProtos[name] = method;
|
|
16416
16425
|
}
|
|
16417
|
-
sendMessage(peer, id, data) {
|
|
16418
|
-
if (peer.readyState === 'open') {
|
|
16419
|
-
|
|
16420
|
-
|
|
16421
|
-
}
|
|
16422
|
-
|
|
16426
|
+
async sendMessage(peer, id, data) {
|
|
16427
|
+
// if (peer.readyState === 'open') {
|
|
16428
|
+
await peer.send(data, id);
|
|
16429
|
+
this.bw.up += data.length;
|
|
16430
|
+
// } else if (peer.readyState === 'closed') {
|
|
16431
|
+
// this.removePeer(peer)
|
|
16432
|
+
// }
|
|
16423
16433
|
}
|
|
16424
16434
|
async handleDHT(peer, id, proto) {
|
|
16425
16435
|
let { hash, store } = proto.decoded;
|
|
@@ -16476,6 +16486,7 @@ class Peernet {
|
|
|
16476
16486
|
}
|
|
16477
16487
|
case 'peernet-request': {
|
|
16478
16488
|
this.handleRequest(peer, id, proto);
|
|
16489
|
+
break;
|
|
16479
16490
|
}
|
|
16480
16491
|
case 'peernet-ps': {
|
|
16481
16492
|
if (peer.peerId !== this.id)
|
|
@@ -16492,33 +16503,24 @@ class Peernet {
|
|
|
16492
16503
|
if (!hash)
|
|
16493
16504
|
throw new Error('hash expected, received undefined');
|
|
16494
16505
|
const data = await new globalThis.peernet.protos['peernet-dht']({ hash });
|
|
16495
|
-
|
|
16496
|
-
const walk = async (peer) => {
|
|
16506
|
+
const walk = async (peer, peerId) => {
|
|
16497
16507
|
const node = await this.prepareMessage(data);
|
|
16498
16508
|
let result = await peer.request(node.encoded);
|
|
16499
16509
|
result = new Uint8Array(Object.values(result));
|
|
16500
16510
|
const proto = await protoFor(result);
|
|
16501
16511
|
if (proto.name !== 'peernet-dht-response')
|
|
16502
16512
|
throw dhtError(proto.name);
|
|
16503
|
-
// TODO: give ip and port (just used for location)
|
|
16504
|
-
if (!peer.connection.remoteAddress || !peer.connection.localAddress) {
|
|
16505
|
-
peer.connection.remoteFamily = 'ipv4';
|
|
16506
|
-
peer.connection.remoteAddress = '127.0.0.1';
|
|
16507
|
-
peer.connection.remotePort = '0000';
|
|
16508
|
-
}
|
|
16509
16513
|
const peerInfo = {
|
|
16510
|
-
|
|
16511
|
-
|
|
16512
|
-
port: peer.connection.remotePort || peer.connection.localPort,
|
|
16513
|
-
id: peer.peerId,
|
|
16514
|
+
...peer.connectionStats,
|
|
16515
|
+
id: peerId,
|
|
16514
16516
|
};
|
|
16515
16517
|
if (proto.decoded.has)
|
|
16516
16518
|
this.dht.addProvider(peerInfo, proto.decoded.hash);
|
|
16517
16519
|
};
|
|
16518
16520
|
let walks = [];
|
|
16519
|
-
for (const peer of this
|
|
16520
|
-
if (
|
|
16521
|
-
walks.push(walk(peer));
|
|
16521
|
+
for (const [peerId, peer] of Object.entries(this.#connections)) {
|
|
16522
|
+
if (peerId !== this.id) {
|
|
16523
|
+
walks.push(walk(peer, peerId));
|
|
16522
16524
|
}
|
|
16523
16525
|
}
|
|
16524
16526
|
return Promise.all(walks);
|
|
@@ -16528,7 +16530,7 @@ class Peernet {
|
|
|
16528
16530
|
*
|
|
16529
16531
|
* @param {String} hash
|
|
16530
16532
|
*/
|
|
16531
|
-
async providersFor(hash) {
|
|
16533
|
+
async providersFor(hash, store) {
|
|
16532
16534
|
let providers = await this.dht.providersFor(hash);
|
|
16533
16535
|
// walk the network to find a provider
|
|
16534
16536
|
if (!providers || providers.length === 0) {
|
|
@@ -16591,23 +16593,25 @@ class Peernet {
|
|
|
16591
16593
|
if (!closestPeer || !closestPeer.id)
|
|
16592
16594
|
return this.requestData(hash, store?.name || store);
|
|
16593
16595
|
const id = closestPeer.id;
|
|
16594
|
-
if (this
|
|
16595
|
-
|
|
16596
|
-
if (peer.peerId === id)
|
|
16597
|
-
return peer;
|
|
16598
|
-
});
|
|
16596
|
+
if (this.#connections[id]) {
|
|
16597
|
+
const peer = this.#connections[id];
|
|
16599
16598
|
let data = await new globalThis.peernet.protos['peernet-data']({ hash, store: store?.name || store });
|
|
16600
16599
|
const node = await this.prepareMessage(data);
|
|
16601
|
-
if (
|
|
16602
|
-
data = await
|
|
16600
|
+
if (peer)
|
|
16601
|
+
data = await peer.request(node.encoded);
|
|
16603
16602
|
else {
|
|
16604
|
-
|
|
16605
|
-
|
|
16606
|
-
|
|
16607
|
-
|
|
16608
|
-
|
|
16609
|
-
|
|
16603
|
+
// fallback and try every provider found
|
|
16604
|
+
const promises = [];
|
|
16605
|
+
const providers = await this.providersFor(hash, store);
|
|
16606
|
+
for (const provider of providers) {
|
|
16607
|
+
const peer = this.#connections[provider.id];
|
|
16608
|
+
if (peer)
|
|
16609
|
+
promises.push(peer.request(node.encoded));
|
|
16610
|
+
}
|
|
16611
|
+
data = await Promise.race(promises);
|
|
16610
16612
|
}
|
|
16613
|
+
if (data)
|
|
16614
|
+
data = new Uint8Array(Object.values(data));
|
|
16611
16615
|
const proto = await protoFor(data);
|
|
16612
16616
|
// TODO: store data automaticly or not
|
|
16613
16617
|
return BufferToUint8Array(proto.decoded.data);
|
|
@@ -16808,8 +16812,8 @@ class Peernet {
|
|
|
16808
16812
|
// globalSub.publish(topic, data)
|
|
16809
16813
|
const id = Math.random().toString(36).slice(-12);
|
|
16810
16814
|
data = await new globalThis.peernet.protos['peernet-ps']({ data, topic });
|
|
16811
|
-
for (const peer of this
|
|
16812
|
-
if (
|
|
16815
|
+
for (const [peerId, peer] of Object.entries(this.#connections)) {
|
|
16816
|
+
if (peerId !== this.id) {
|
|
16813
16817
|
const node = await this.prepareMessage(data);
|
|
16814
16818
|
this.sendMessage(peer, id, node.encoded);
|
|
16815
16819
|
}
|
|
@@ -16874,4 +16878,4 @@ class Node {
|
|
|
16874
16878
|
}
|
|
16875
16879
|
}
|
|
16876
16880
|
|
|
16877
|
-
export { FormatInterface as F,
|
|
16881
|
+
export { FormatInterface as F, MultiWallet as M, Node as N, base58$1 as b, commonjsGlobal as c, encrypt as e, getDefaultExportFromCjs as g };
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { N as default } from './node-browser-
|
|
2
|
-
import './contract-
|
|
1
|
+
export { N as default } from './node-browser-c95add6b.js';
|
|
2
|
+
import './contract-32687834.js';
|