@leofcoin/chain 1.4.78 → 1.4.80

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.
@@ -1,4 +1,4 @@
1
- import { C as ContractMessage, T as TransactionMessage, c as BlockMessage, d as BWMessage, e as BWRequestMessage, V as ValidatorMessage } from './index-fa2c6beb.js';
1
+ import { C as ContractMessage, T as TransactionMessage, c as BlockMessage, d as BWMessage, e as BWRequestMessage, V as ValidatorMessage } from './index-c3f4012c.js';
2
2
 
3
3
  var nodeConfig = async (config = {
4
4
  network: 'leofcoin:peach',
@@ -91,55 +91,55 @@ globalThis.debug = text => {
91
91
  if (globalThis.DEBUG) console.log('\x1b[34m\x1b[1m%s', text, '\x1b[0m'); // bright blue
92
92
  };
93
93
 
94
- class LittlePubSub {
95
- subscribers = {};
96
- verbose;
97
- constructor(verbose = false) {
98
- this.verbose = verbose;
99
- }
100
- #handleContext(handler, context) {
101
- if (typeof context === 'undefined') {
102
- context = handler;
103
- }
104
- return context;
105
- }
106
- hasSubscribers(event) {
107
- return this.subscribers[event] ? true : false;
108
- }
109
- subscribe(event, handler, context) {
110
- if (!this.hasSubscribers(event))
111
- this.subscribers[event] = { handlers: [], value: undefined };
112
- context = this.#handleContext(handler, context);
113
- this.subscribers[event].handlers.push(handler.bind(context));
114
- }
115
- unsubscribe(event, handler, context) {
116
- if (!this.hasSubscribers(event))
117
- return;
118
- context = this.#handleContext(handler, context);
119
- const index = this.subscribers[event].handlers.indexOf(handler.bind(context));
120
- this.subscribers[event].handlers.splice(index);
121
- if (this.subscribers[event].handlers.length === 0)
122
- delete this.subscribers[event];
123
- }
124
- publish(event, change) {
125
- if (!this.hasSubscribers(event))
126
- return;
127
- if (this.verbose || this.subscribers[event].value !== change) {
128
- this.subscribers[event].value = change;
129
- this.subscribers[event].handlers.forEach((handler) => {
130
- handler(change, this.subscribers[event].value);
131
- });
132
- }
133
- }
134
- once(event) {
135
- return new Promise((resolve) => {
136
- const cb = (value) => {
137
- this.unsubscribe(event, cb);
138
- resolve(value);
139
- };
140
- this.subscribe(event, cb);
141
- });
142
- }
94
+ class LittlePubSub {
95
+ subscribers = {};
96
+ verbose;
97
+ constructor(verbose) {
98
+ this.verbose = verbose;
99
+ }
100
+ _handleContext(handler, context) {
101
+ if (typeof context === 'undefined') {
102
+ context = handler;
103
+ }
104
+ return context;
105
+ }
106
+ hasSubscribers(event) {
107
+ return this.subscribers[event] ? true : false;
108
+ }
109
+ subscribe(event, handler, context) {
110
+ if (!this.hasSubscribers(event))
111
+ this.subscribers[event] = { handlers: [], value: undefined };
112
+ context = this._handleContext(handler, context);
113
+ this.subscribers[event].handlers.push(handler.bind(context));
114
+ }
115
+ unsubscribe(event, handler, context) {
116
+ if (!this.hasSubscribers(event))
117
+ return;
118
+ context = this._handleContext(handler, context);
119
+ const index = this.subscribers[event].handlers.indexOf(handler.bind(context));
120
+ this.subscribers[event].handlers.splice(index);
121
+ if (this.subscribers[event].handlers.length === 0)
122
+ delete this.subscribers[event];
123
+ }
124
+ publish(event, change) {
125
+ if (!this.hasSubscribers(event))
126
+ return;
127
+ if (this.verbose || this.subscribers[event]?.value !== change) {
128
+ this.subscribers[event].value = change;
129
+ this.subscribers[event].handlers.forEach((handler) => {
130
+ handler(change, this.subscribers[event].value);
131
+ });
132
+ }
133
+ }
134
+ once(event) {
135
+ return new Promise((resolve) => {
136
+ const cb = (value) => {
137
+ this.unsubscribe(event, cb);
138
+ resolve(value);
139
+ };
140
+ this.subscribe(event, cb);
141
+ });
142
+ }
143
143
  }
144
144
 
145
145
  // base-x encoding / decoding
@@ -6129,55 +6129,54 @@ const FormatInterface = FormatInterface$1;
6129
6129
  const Codec = Codec$1;
6130
6130
 
6131
6131
  const BufferToUint8Array = data => {
6132
- if (data.type === 'Buffer') {
6133
- data = new Uint8Array(data.data);
6134
- }
6135
- return data;
6132
+ if (data.type === 'Buffer') {
6133
+ data = new Uint8Array(data.data);
6134
+ }
6135
+ return data
6136
6136
  };
6137
+
6137
6138
  const protoFor = (message) => {
6138
- const codec = new Codec(message);
6139
- if (!codec.name)
6140
- throw new Error('proto not found');
6141
- const Proto = globalThis.peernet.protos[codec.name];
6142
- if (!Proto)
6143
- throw (new Error(`No proto defined for ${codec.name}`));
6144
- return new Proto(message);
6139
+ const codec = new Codec(message);
6140
+ if (!codec.name) throw new Error('proto not found')
6141
+ const Proto = globalThis.peernet.protos[codec.name];
6142
+ if (!Proto) throw (new Error(`No proto defined for ${codec.name}`))
6143
+ return new Proto(message)
6145
6144
  };
6145
+
6146
6146
  /**
6147
6147
  * wether or not a peernet daemon is active
6148
6148
  * @return {Boolean}
6149
6149
  */
6150
6150
  const hasDaemon = async () => {
6151
- try {
6152
- let response = await fetch('http://127.0.0.1:1000/api/version');
6153
- response = await response.json();
6154
- return Boolean(response.client === '@peernet/api/http');
6155
- }
6156
- catch (e) {
6157
- return false;
6158
- }
6151
+ try {
6152
+ let response = await fetch('http://127.0.0.1:1000/api/version');
6153
+ response = await response.json();
6154
+ return Boolean(response.client === '@peernet/api/http')
6155
+ } catch (e) {
6156
+ return false
6157
+ }
6159
6158
  };
6159
+
6160
6160
  const https = () => {
6161
- if (!globalThis.location)
6162
- return false;
6163
- return Boolean(globalThis.location.protocol === 'https:');
6161
+ if (!globalThis.location) return false;
6162
+ return Boolean(globalThis.location.protocol === 'https:')
6164
6163
  };
6164
+
6165
6165
  /**
6166
6166
  * Get current environment
6167
6167
  * @return {String} current environment [node, electron, browser]
6168
6168
  */
6169
6169
  const environment = () => {
6170
- const _navigator = globalThis.navigator;
6171
- if (!_navigator) {
6172
- return 'node';
6173
- }
6174
- else if (_navigator && /electron/i.test(_navigator.userAgent)) {
6175
- return 'electron';
6176
- }
6177
- else {
6178
- return 'browser';
6179
- }
6170
+ const _navigator = globalThis.navigator;
6171
+ if (!_navigator) {
6172
+ return 'node'
6173
+ } else if (_navigator && /electron/i.test(_navigator.userAgent)) {
6174
+ return 'electron'
6175
+ } else {
6176
+ return 'browser'
6177
+ }
6180
6178
  };
6179
+
6181
6180
  /**
6182
6181
  * * Get current environment
6183
6182
  * @return {Object} result
@@ -6185,84 +6184,84 @@ const environment = () => {
6185
6184
  * @property {Boolean} reult.environment Current environment
6186
6185
  */
6187
6186
  const target = async () => {
6188
- let daemon = false;
6189
- if (!https())
6190
- daemon = await hasDaemon();
6191
- return { daemon, environment: environment() };
6187
+ let daemon = false;
6188
+ if (!https()) daemon = await hasDaemon();
6189
+
6190
+ return {daemon, environment: environment()}
6192
6191
  };
6193
6192
 
6194
6193
  class PeerDiscovery {
6195
- constructor(id) {
6196
- this.id = id;
6197
- }
6198
- _getPeerId(id) {
6199
- if (!peernet.peerMap || peernet.peerMap && peernet.peerMap.size === 0)
6200
- return false;
6201
- for (const entry of [...peernet.peerMap.entries()]) {
6202
- for (const _id of entry[1]) {
6203
- if (_id === id)
6204
- return entry[0];
6205
- }
6206
- }
6194
+ constructor(id) {
6195
+ this.id = id;
6196
+ }
6197
+
6198
+ _getPeerId(id) {
6199
+ if (!peernet.peerMap || peernet.peerMap && peernet.peerMap.size === 0) return false
6200
+
6201
+ for (const entry of [...peernet.peerMap.entries()]) {
6202
+ for (const _id of entry[1]) {
6203
+ if (_id === id) return entry[0]
6204
+ }
6207
6205
  }
6208
- async discover(peer) {
6209
- let id = this._getPeerId(peer.id);
6210
- if (id)
6211
- return id;
6212
- const data = await new peernet.protos['peernet-peer']({ id: this.id });
6213
- const node = await peernet.prepareMessage(peer.id, data.encoded);
6214
- let response = await peer.request(node.encoded);
6215
- response = await protoFor(response);
6216
- response = await new peernet.protos['peernet-peer-response'](response.decoded.data);
6217
- id = response.decoded.id;
6218
- if (id === this.id)
6219
- return;
6220
- if (!peernet.peerMap.has(id))
6221
- peernet.peerMap.set(id, [peer.id]);
6222
- else {
6223
- const connections = peernet.peerMap.get(id);
6224
- if (connections.indexOf(peer.id) === -1) {
6225
- connections.push(peer.id);
6226
- peernet.peerMap.set(peer.id, connections);
6227
- }
6228
- }
6229
- return id;
6206
+ }
6207
+
6208
+ async discover(peer) {
6209
+ let id = this._getPeerId(peer.id);
6210
+ if (id) return id
6211
+ const data = await new peernet.protos['peernet-peer']({id: this.id});
6212
+ const node = await peernet.prepareMessage(peer.id, data.encoded);
6213
+
6214
+ let response = await peer.request(node.encoded);
6215
+ response = await protoFor(response);
6216
+ response = await new peernet.protos['peernet-peer-response'](response.decoded.data);
6217
+
6218
+ id = response.decoded.id;
6219
+ if (id === this.id) return;
6220
+
6221
+ if (!peernet.peerMap.has(id)) peernet.peerMap.set(id, [peer.id]);
6222
+ else {
6223
+ const connections = peernet.peerMap.get(id);
6224
+ if (connections.indexOf(peer.id) === -1) {
6225
+ connections.push(peer.id);
6226
+ peernet.peerMap.set(peer.id, connections);
6227
+ }
6230
6228
  }
6231
- async discoverHandler(message, peer) {
6232
- const { id, proto } = message;
6233
- // if (typeof message.data === 'string') message.data = Buffer.from(message.data)
6234
- if (proto.name === 'peernet-peer') {
6235
- const from = proto.decoded.id;
6236
- if (from === this.id)
6237
- return;
6238
- if (!peernet.peerMap.has(from))
6239
- peernet.peerMap.set(from, [peer.id]);
6240
- else {
6241
- const connections = peernet.peerMap.get(from);
6242
- if (connections.indexOf(peer.id) === -1) {
6243
- connections.push(peer.id);
6244
- peernet.peerMap.set(from, connections);
6245
- }
6246
- }
6247
- const data = await new peernet.protos['peernet-peer-response']({ id: this.id });
6248
- const node = await peernet.prepareMessage(from, data.encoded);
6249
- peer.write(Buffer.from(JSON.stringify({ id, data: node.encoded })));
6229
+ return id
6230
+ }
6231
+
6232
+ async discoverHandler(message, peer) {
6233
+ const {id, proto} = message;
6234
+ // if (typeof message.data === 'string') message.data = Buffer.from(message.data)
6235
+ if (proto.name === 'peernet-peer') {
6236
+ const from = proto.decoded.id;
6237
+ if (from === this.id) return;
6238
+
6239
+ if (!peernet.peerMap.has(from)) peernet.peerMap.set(from, [peer.id]);
6240
+ else {
6241
+ const connections = peernet.peerMap.get(from);
6242
+ if (connections.indexOf(peer.id) === -1) {
6243
+ connections.push(peer.id);
6244
+ peernet.peerMap.set(from, connections);
6250
6245
  }
6251
- else if (proto.name === 'peernet-peer-response') {
6252
- const from = proto.decoded.id;
6253
- if (from === this.id)
6254
- return;
6255
- if (!peernet.peerMap.has(from))
6256
- peernet.peerMap.set(from, [peer.id]);
6257
- else {
6258
- const connections = peernet.peerMap.get(from);
6259
- if (connections.indexOf(peer.id) === -1) {
6260
- connections.push(peer.id);
6261
- peernet.peerMap.set(from, connections);
6262
- }
6263
- }
6246
+ }
6247
+ const data = await new peernet.protos['peernet-peer-response']({id: this.id});
6248
+ const node = await peernet.prepareMessage(from, data.encoded);
6249
+
6250
+ peer.write(Buffer.from(JSON.stringify({id, data: node.encoded})));
6251
+ } else if (proto.name === 'peernet-peer-response') {
6252
+ const from = proto.decoded.id;
6253
+ if (from === this.id) return;
6254
+
6255
+ if (!peernet.peerMap.has(from)) peernet.peerMap.set(from, [peer.id]);
6256
+ else {
6257
+ const connections = peernet.peerMap.get(from);
6258
+ if (connections.indexOf(peer.id) === -1) {
6259
+ connections.push(peer.id);
6260
+ peernet.peerMap.set(from, connections);
6264
6261
  }
6262
+ }
6265
6263
  }
6264
+ }
6266
6265
  }
6267
6266
 
6268
6267
  /**
@@ -6375,52 +6374,55 @@ class DhtEarth {
6375
6374
  }
6376
6375
 
6377
6376
  class MessageHandler {
6378
- constructor(network) {
6379
- this.network = network;
6380
- }
6381
- /**
6382
- * hash and sign message
6383
- *
6384
- * @param {object} message
6385
- * @param {Buffer} message.from peer id
6386
- * @param {Buffer} message.to peer id
6387
- * @param {string} message.data Peernet message
6388
- * (PeernetMessage excluded) encoded as a string
6389
- * @return message
6390
- */
6391
- async hashAndSignMessage(message) {
6392
- const hash = await message.peernetHash;
6393
- message.decoded.signature = globalThis.identity.sign(hash.buffer);
6394
- return message;
6395
- }
6396
- /**
6397
- * @param {String} from - peer id
6398
- * @param {String} to - peer id
6399
- * @param {String|PeernetMessage} data - data encoded message string
6400
- * or the messageNode itself
6401
- */
6402
- async prepareMessage(message) {
6403
- if (message.keys.includes('signature')) {
6404
- message = await this.hashAndSignMessage(message);
6405
- }
6406
- return message;
6377
+ constructor(network) {
6378
+ this.network = network;
6379
+ }
6380
+ /**
6381
+ * hash and sign message
6382
+ *
6383
+ * @param {object} message
6384
+ * @param {Buffer} message.from peer id
6385
+ * @param {Buffer} message.to peer id
6386
+ * @param {string} message.data Peernet message
6387
+ * (PeernetMessage excluded) encoded as a string
6388
+ * @return message
6389
+ */
6390
+ async hashAndSignMessage(message) {
6391
+ const hash = await message.peernetHash;
6392
+ message.decoded.signature = globalThis.identity.sign(hash.buffer);
6393
+ return message
6394
+ }
6395
+
6396
+ /**
6397
+ * @param {String} from - peer id
6398
+ * @param {String} to - peer id
6399
+ * @param {String|PeernetMessage} data - data encoded message string
6400
+ * or the messageNode itself
6401
+ */
6402
+ async prepareMessage(message) {
6403
+ if (message.keys.includes('signature')) {
6404
+ message = await this.hashAndSignMessage(message);
6407
6405
  }
6406
+
6407
+ return message
6408
+ }
6408
6409
  }
6409
6410
 
6410
- const dataHandler = async (message) => {
6411
- if (!message)
6412
- return;
6413
- const { data, id, from, peer } = message;
6414
- const proto = await protoFor(data);
6415
- peernet._protoHandler({ id, proto }, peernet.connections[from] || peer, from);
6411
+ const dataHandler = async message => {
6412
+ if (!message) return
6413
+
6414
+ const {data, id, from, peer} = message;
6415
+ const proto = await protoFor(data);
6416
+ peernet._protoHandler({id, proto}, peernet.connections[from] || peer, from);
6416
6417
  };
6417
6418
 
6418
6419
  const dhtError = (proto) => {
6419
- const text = `Received proto ${proto.name} expected peernet-dht-response`;
6420
- return new Error(`Routing error: ${text}`);
6420
+ const text = `Received proto ${proto.name} expected peernet-dht-response`;
6421
+ return new Error(`Routing error: ${text}`)
6421
6422
  };
6423
+
6422
6424
  const nothingFoundError = (hash) => {
6423
- return new Error(`nothing found for ${hash}`);
6425
+ return new Error(`nothing found for ${hash}`)
6424
6426
  };
6425
6427
 
6426
6428
  // import base32 from '@vandeurenglenn/base32'
@@ -6502,7 +6504,7 @@ class KeyPath {
6502
6504
 
6503
6505
  }
6504
6506
 
6505
- class LeofcoinStorage {
6507
+ let LeofcoinStorage$1 = class LeofcoinStorage {
6506
6508
 
6507
6509
  constructor(name = 'storage', root = '.leofcoin') {
6508
6510
  this.name = name;
@@ -6587,7 +6589,7 @@ class LeofcoinStorage {
6587
6589
  return this.db.iterate()
6588
6590
  }
6589
6591
 
6590
- }
6592
+ };
6591
6593
 
6592
6594
  const randombytes = strength => crypto.getRandomValues(new Uint8Array(strength));
6593
6595
 
@@ -20257,7 +20259,7 @@ class Identity {
20257
20259
  globalThis.peernet.selectedAccount = new TextDecoder().decode(selected);
20258
20260
  }
20259
20261
  else {
20260
- const importee = await import(/* webpackChunkName: "generate-account" */ './index-502d190c-60cfcc02.js');
20262
+ const importee = await import(/* webpackChunkName: "generate-account" */ './index-6311966e-b5f647d8.js');
20261
20263
  const { identity, accounts } = await importee.default(password, this.network);
20262
20264
  await globalThis.accountStore.put('public', JSON.stringify({ walletId: identity.walletId }));
20263
20265
  await globalThis.walletStore.put('version', String(1));
@@ -20295,7 +20297,7 @@ class Identity {
20295
20297
  }
20296
20298
  }
20297
20299
 
20298
- globalThis.LeofcoinStorage = LeofcoinStorage;
20300
+ globalThis.LeofcoinStorage = LeofcoinStorage$1;
20299
20301
  globalThis.leofcoin = globalThis.leofcoin || {};
20300
20302
  globalThis.pubsub = globalThis.pubsub || new LittlePubSub();
20301
20303
  globalThis.globalSub = globalThis.globalSub || new LittlePubSub();
@@ -20318,11 +20320,14 @@ class Peernet {
20318
20320
  stars;
20319
20321
  networkVersion;
20320
20322
  bw;
20323
+ hasDaemon = false;
20321
20324
  autoStart = true;
20322
20325
  #starting = false;
20323
20326
  #started = false;
20324
20327
  #connections = {};
20325
20328
  requestProtos = {};
20329
+ _messageHandler;
20330
+ protos;
20326
20331
  /**
20327
20332
  * @access public
20328
20333
  * @param {Object} options
@@ -20428,7 +20433,7 @@ class Peernet {
20428
20433
  this.root = options.root;
20429
20434
  const { RequestMessage, ResponseMessage, PeerMessage, PeerMessageResponse, PeernetMessage, DHTMessage, DHTMessageResponse, DataMessage, DataMessageResponse, PsMessage, ChatMessage, PeernetFile
20430
20435
  // FolderMessageResponse
20431
- } = await import(/* webpackChunkName: "messages" */ './messages-cd01524c-8d88d84b.js');
20436
+ } = await import(/* webpackChunkName: "messages" */ './messages-54aa3cad-5309745b.js');
20432
20437
  /**
20433
20438
  * proto Object containing protos
20434
20439
  * @type {Object}