@leofcoin/chain 1.7.55 → 1.7.66

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.
@@ -7458,6 +7458,9 @@ var pako = {
7458
7458
  constants: constants_1
7459
7459
  };
7460
7460
 
7461
+ const jsonStringifyBigInt$1 = (key, value) => (typeof value === 'bigint' ? { $bigint: value.toString() } : value);
7462
+ const jsonParseBigInt$1 = (key, value) => typeof value === 'object' && value.$bigint ? BigInt(value.$bigint) : value;
7463
+
7461
7464
  const { fromString, toString } = index$1;
7462
7465
  const isJson = (type) => type === 'object' || 'array';
7463
7466
  const isString = (type) => type === 'string';
@@ -7493,7 +7496,7 @@ const toType = (data) => {
7493
7496
  return new TextEncoder().encode(data);
7494
7497
  // returns the object as UintArray
7495
7498
  if (typeof data === 'object')
7496
- return new TextEncoder().encode(JSON.stringify(data));
7499
+ return new TextEncoder().encode(JSON.stringify(data, jsonStringifyBigInt$1));
7497
7500
  // returns the number as UintArray
7498
7501
  if (typeof data === 'number' || typeof data === 'boolean')
7499
7502
  return new TextEncoder().encode(data.toString());
@@ -7539,7 +7542,7 @@ const decode = (proto, uint8Array, compressed) => {
7539
7542
  else if (isBigInt(token.type))
7540
7543
  output[token.key] = BigInt(new TextDecoder().decode(deconcated[i]));
7541
7544
  else if (isJson(token.type))
7542
- output[token.key] = JSON.parse(new TextDecoder().decode(deconcated[i]));
7545
+ output[token.key] = JSON.parse(new TextDecoder().decode(deconcated[i]), jsonParseBigInt$1);
7543
7546
  if (token.optional) {
7544
7547
  if (!output[token.key] || output[token.key].length === 0)
7545
7548
  delete output[token.key];
@@ -7554,6 +7557,8 @@ var index = {
7554
7557
  decode
7555
7558
  };
7556
7559
 
7560
+ const jsonStringifyBigInt = (key, value) => typeof value === 'bigint' ? { $bigint: value.toString() } : value;
7561
+ const jsonParseBigInt = (key, value) => typeof value === 'object' && value.$bigint ? BigInt(value.$bigint) : value;
7557
7562
  class BasicInterface {
7558
7563
  #encoded;
7559
7564
  #decoded;
@@ -7670,195 +7675,209 @@ class BasicInterface {
7670
7675
  }
7671
7676
  }
7672
7677
 
7673
- const blockchainCodecs = [
7674
- {
7675
- name: 'leofcoin-block',
7676
- codec: '0x6c62',
7677
- hashAlg: 'dbl-keccak-512',
7678
- },
7679
- {
7680
- name: 'leofcoin-tx',
7681
- codec: '0x6c74',
7682
- hashAlg: 'dbl-keccak-512',
7683
- },
7684
- {
7685
- name: 'leofcoin-itx',
7686
- codec: '0x6c69',
7687
- hashAlg: 'keccak-512',
7688
- },
7689
- {
7690
- name: 'leofcoin-pr',
7691
- codec: '0x6c70',
7692
- hashAlg: 'keccak-256',
7693
- },
7694
- {
7695
- name: 'contract-message',
7696
- codec: '0x63636d',
7697
- hashAlg: 'keccak-256'
7698
- },
7699
- {
7700
- name: 'transaction-message',
7701
- codec: '0x746d',
7702
- hashAlg: 'keccak-256'
7703
- },
7704
- {
7705
- name: 'raw-transaction-message',
7706
- codec: '0x772746d',
7707
- hashAlg: 'keccak-256'
7708
- },
7709
- {
7710
- name: 'block-message',
7711
- codec: '0x626d',
7712
- hashAlg: 'keccak-256'
7713
- },
7714
- {
7715
- name: 'bw-message',
7716
- codec: '0x62776d',
7717
- hashAlg: 'keccak-256'
7718
- },
7719
- {
7720
- name: 'bw-request-message',
7721
- codec: '0x6277726d',
7722
- hashAlg: 'keccak-256'
7723
- },
7724
- {
7725
- name: 'validator-message',
7726
- codec: '0x766d',
7727
- hashAlg: 'keccak-256'
7728
- }
7678
+ const blockchainCodecs = [
7679
+ {
7680
+ name: 'leofcoin-block',
7681
+ codec: '0x6c62',
7682
+ hashAlg: 'dbl-keccak-512',
7683
+ },
7684
+ {
7685
+ name: 'leofcoin-tx',
7686
+ codec: '0x6c74',
7687
+ hashAlg: 'dbl-keccak-512',
7688
+ },
7689
+ {
7690
+ name: 'leofcoin-itx',
7691
+ codec: '0x6c69',
7692
+ hashAlg: 'keccak-512',
7693
+ },
7694
+ {
7695
+ name: 'leofcoin-pr',
7696
+ codec: '0x6c70',
7697
+ hashAlg: 'keccak-256',
7698
+ },
7699
+ {
7700
+ name: 'contract-message',
7701
+ codec: '0x63636d',
7702
+ hashAlg: 'keccak-256'
7703
+ },
7704
+ {
7705
+ name: 'transaction-message',
7706
+ codec: '0x746d',
7707
+ hashAlg: 'keccak-256'
7708
+ },
7709
+ {
7710
+ name: 'raw-transaction-message',
7711
+ codec: '0x772746d',
7712
+ hashAlg: 'keccak-256'
7713
+ },
7714
+ {
7715
+ name: 'block-message',
7716
+ codec: '0x626d',
7717
+ hashAlg: 'keccak-256'
7718
+ },
7719
+ {
7720
+ name: 'bw-message',
7721
+ codec: '0x62776d',
7722
+ hashAlg: 'keccak-256'
7723
+ },
7724
+ {
7725
+ name: 'bw-request-message',
7726
+ codec: '0x6277726d',
7727
+ hashAlg: 'keccak-256'
7728
+ },
7729
+ {
7730
+ name: 'validator-message',
7731
+ codec: '0x766d',
7732
+ hashAlg: 'keccak-256'
7733
+ }
7729
7734
  ];
7730
7735
 
7731
- const internalCodecs = [
7732
- {
7733
- name: 'disco-hash',
7734
- codec: '0x30',
7735
- hashAlg: 'dbl-keccak-256',
7736
- },
7737
- {
7738
- name: 'peernet-peer-response',
7739
- codec: '0x707072',
7740
- hashAlg: 'keccak-256',
7741
- },
7742
- {
7743
- name: 'peernet-peer',
7744
- codec: '0x7070',
7745
- hashAlg: 'keccak-256',
7746
- },
7747
- {
7748
- name: 'peernet-dht',
7749
- codec: '0x706468',
7750
- hashAlg: 'keccak-256',
7751
- },
7752
- {
7753
- name: 'peernet-dht-response',
7754
- codec: '0x706472',
7755
- hashAlg: 'keccak-256',
7756
- },
7757
- {
7758
- name: 'peernet-data',
7759
- codec: '0x706461',
7760
- hashAlg: 'keccak-256',
7761
- },
7762
- {
7763
- name: 'peernet-data-response',
7764
- codec: '0x70646172',
7765
- hashAlg: 'keccak-256',
7766
- },
7767
- {
7768
- name: 'peernet-message',
7769
- codec: '0x706d65',
7770
- hashAlg: 'keccak-256',
7771
- },
7772
- {
7773
- name: 'peernet-ps',
7774
- codec: '707073',
7775
- hashAlg: 'keccak-256',
7776
- },
7777
- {
7778
- name: 'peernet-response',
7779
- codec: '0x7072',
7780
- hashAlg: 'keccak-256',
7781
- },
7782
- {
7783
- name: 'peernet-request',
7784
- codec: '0x707271',
7785
- hashAlg: 'keccak-256',
7786
- },
7787
- {
7788
- name: 'peernet-file',
7789
- codec: '0x7066',
7790
- hashAlg: 'keccak-256',
7791
- },
7792
- {
7793
- name: 'peernet-file-response',
7794
- codec: '0x706672',
7795
- hashAlg: 'keccak-256',
7796
- }
7736
+ const internalCodecs = [
7737
+ {
7738
+ name: 'pubsub-request',
7739
+ codec: '0x70737271',
7740
+ hashAlg: 'keccak-256'
7741
+ },
7742
+ {
7743
+ name: 'pubsub-response',
7744
+ codec: '0x707372',
7745
+ hashAlg: 'keccak-256'
7746
+ }
7797
7747
  ];
7798
7748
 
7799
- var social = [{
7800
- name: 'chat-message',
7801
- codec: '0x70636d',
7802
- hashAlg: 'dbl-keccak-256',
7749
+ var social = [{
7750
+ name: 'chat-message',
7751
+ codec: '0x70636d',
7752
+ hashAlg: 'dbl-keccak-256',
7803
7753
  }];
7804
7754
 
7805
- const codecs = [
7806
- ...internalCodecs,
7807
- ...blockchainCodecs,
7808
- ...social
7755
+ const peernetCodecs = [
7756
+ {
7757
+ name: 'disco-hash',
7758
+ codec: '0x30',
7759
+ hashAlg: 'dbl-keccak-256',
7760
+ },
7761
+ {
7762
+ name: 'peernet-peer-response',
7763
+ codec: '0x707072',
7764
+ hashAlg: 'keccak-256',
7765
+ },
7766
+ {
7767
+ name: 'peernet-peer',
7768
+ codec: '0x7070',
7769
+ hashAlg: 'keccak-256',
7770
+ },
7771
+ {
7772
+ name: 'peernet-dht',
7773
+ codec: '0x706468',
7774
+ hashAlg: 'keccak-256',
7775
+ },
7776
+ {
7777
+ name: 'peernet-dht-response',
7778
+ codec: '0x706472',
7779
+ hashAlg: 'keccak-256',
7780
+ },
7781
+ {
7782
+ name: 'peernet-data',
7783
+ codec: '0x706461',
7784
+ hashAlg: 'keccak-256',
7785
+ },
7786
+ {
7787
+ name: 'peernet-data-response',
7788
+ codec: '0x70646172',
7789
+ hashAlg: 'keccak-256',
7790
+ },
7791
+ {
7792
+ name: 'peernet-message',
7793
+ codec: '0x706d65',
7794
+ hashAlg: 'keccak-256',
7795
+ },
7796
+ {
7797
+ name: 'peernet-ps',
7798
+ codec: '707073',
7799
+ hashAlg: 'keccak-256',
7800
+ },
7801
+ {
7802
+ name: 'peernet-response',
7803
+ codec: '0x7072',
7804
+ hashAlg: 'keccak-256',
7805
+ },
7806
+ {
7807
+ name: 'peernet-request',
7808
+ codec: '0x707271',
7809
+ hashAlg: 'keccak-256',
7810
+ },
7811
+ {
7812
+ name: 'peernet-file',
7813
+ codec: '0x7066',
7814
+ hashAlg: 'keccak-256',
7815
+ },
7816
+ {
7817
+ name: 'peernet-file-response',
7818
+ codec: '0x706672',
7819
+ hashAlg: 'keccak-256',
7820
+ }
7809
7821
  ];
7810
7822
 
7811
- globalThis.peernetCodecs = globalThis.peernetCodecs || {};
7812
- const addCodec = (codecInput) => {
7813
- let { hashAlg, codec, name } = codecInput;
7814
- if (!globalThis.peernetCodecs[name])
7815
- globalThis.peernetCodecs[name] = {
7816
- hashAlg,
7817
- codec: typeof codec === 'string' ? parseInt(codec, 16) : codec
7818
- };
7819
- };
7820
- const getCodec = (name) => {
7821
- if (typeof name === 'number')
7822
- return name;
7823
- return getCodecByName(name).codec;
7824
- };
7825
- const getCodecName = (codec) => {
7826
- return Object.keys(globalThis.peernetCodecs).reduce((p, c) => {
7827
- const item = globalThis.peernetCodecs[c];
7828
- if (item.codec === codec)
7829
- return c;
7830
- else
7831
- return p;
7832
- }, undefined);
7833
- };
7834
- const getCodecByName = (name) => globalThis.peernetCodecs[name];
7835
- const getHashAlg = (name) => {
7836
- if (typeof name === 'number')
7837
- return getCodecByName(getCodecName(name)).hashAlg;
7838
- return getCodecByName(name).hashAlg;
7839
- };
7840
- const isCodec = (codec) => {
7841
- if (codec.codec !== undefined && codec.hashAlg)
7842
- return true;
7843
- return false;
7844
- };
7845
- const validateCodec = (codec) => {
7846
- if (codec.codec === undefined ||
7847
- codec.hashAlg === undefined ||
7848
- codec.name === undefined)
7849
- throw new Error(`invalid codecInput: ${codec}`);
7850
- };
7851
- for (const codec of codecs) {
7852
- addCodec(codec);
7853
- }
7854
- var utils = {
7855
- isCodec,
7856
- addCodec,
7857
- getCodec,
7858
- getHashAlg,
7859
- getCodecName,
7860
- validateCodec,
7861
- codecs: globalThis.peernetCodecs
7823
+ const codecs$1 = [
7824
+ ...internalCodecs,
7825
+ ...blockchainCodecs,
7826
+ ...social,
7827
+ ...peernetCodecs
7828
+ ];
7829
+
7830
+ const codecs = {};
7831
+ const addCodec = (codecInput) => {
7832
+ let { hashAlg, codec, name } = codecInput;
7833
+ if (!codecs[name])
7834
+ codecs[name] = {
7835
+ hashAlg,
7836
+ codec: typeof codec === 'string' ? parseInt(codec, 16) : codec
7837
+ };
7838
+ };
7839
+ for (const codec of codecs$1) {
7840
+ addCodec(codec);
7841
+ }
7842
+ const getCodec = (name) => {
7843
+ if (typeof name === 'number')
7844
+ return name;
7845
+ return getCodecByName(name).codec;
7846
+ };
7847
+ const getCodecName = (codec) => {
7848
+ return Object.keys(codecs).reduce((p, c) => {
7849
+ const item = codecs[c];
7850
+ if (item.codec === codec)
7851
+ return c;
7852
+ else
7853
+ return p;
7854
+ }, undefined);
7855
+ };
7856
+ const getCodecByName = (name) => codecs[name];
7857
+ const getHashAlg = (name) => {
7858
+ if (typeof name === 'number')
7859
+ return getCodecByName(getCodecName(name)).hashAlg;
7860
+ return getCodecByName(name).hashAlg;
7861
+ };
7862
+ const isCodec = (codec) => {
7863
+ if (codec.codec !== undefined && codec.hashAlg)
7864
+ return true;
7865
+ return false;
7866
+ };
7867
+ const validateCodec = (codec) => {
7868
+ if (codec.codec === undefined ||
7869
+ codec.hashAlg === undefined ||
7870
+ codec.name === undefined)
7871
+ throw new Error(`invalid codecInput: ${codec}`);
7872
+ };
7873
+ var utils = {
7874
+ isCodec,
7875
+ addCodec,
7876
+ getCodec,
7877
+ getHashAlg,
7878
+ getCodecName,
7879
+ validateCodec,
7880
+ codecs: codecs
7862
7881
  };
7863
7882
 
7864
7883
  class Codec extends BasicInterface {
@@ -7965,20 +7984,21 @@ class Codec extends BasicInterface {
7965
7984
  class CodecHash extends BasicInterface {
7966
7985
  codec;
7967
7986
  discoCodec;
7968
- constructor(buffer, options = {}) {
7987
+ size;
7988
+ constructor(buffer, options) {
7969
7989
  super();
7970
- if (options.name)
7990
+ if (options?.name)
7971
7991
  this.name = options.name;
7972
7992
  else
7973
7993
  this.name = 'disco-hash';
7974
- if (options.codecs)
7994
+ if (options?.codecs)
7975
7995
  this.codecs = options.codecs;
7976
7996
  return this.init(buffer);
7977
7997
  }
7978
7998
  async init(uint8Array) {
7979
7999
  if (uint8Array) {
7980
8000
  if (uint8Array instanceof Uint8Array) {
7981
- this.discoCodec = new Codec(uint8Array, this.codecs);
8001
+ this.discoCodec = new Codec(uint8Array);
7982
8002
  const name = this.discoCodec.name;
7983
8003
  if (name) {
7984
8004
  this.name = name;
@@ -8020,7 +8040,7 @@ class CodecHash extends BasicInterface {
8020
8040
  return this.encoded;
8021
8041
  }
8022
8042
  fromJSON(json) {
8023
- return this.encode(new TextEncoder().encode(JSON.stringify(json)));
8043
+ return this.encode(new TextEncoder().encode(JSON.stringify(json, jsonStringifyBigInt)));
8024
8044
  }
8025
8045
  async encode(buffer, name) {
8026
8046
  if (!this.name && name)
@@ -8094,7 +8114,7 @@ class CodecHash extends BasicInterface {
8094
8114
  name: this.name,
8095
8115
  size: this.size,
8096
8116
  length: this.length,
8097
- digest: this.digest,
8117
+ digest: this.digest
8098
8118
  };
8099
8119
  }
8100
8120
  }
@@ -8218,13 +8238,13 @@ let FormatInterface$1 = class FormatInterface extends BasicInterface {
8218
8238
  this.encoded = buffer;
8219
8239
  return this.hasCodec()
8220
8240
  ? this.decode()
8221
- : this.create(JSON.parse(new TextDecoder().decode(this.encoded)));
8241
+ : this.create(JSON.parse(new TextDecoder().decode(this.encoded), jsonParseBigInt));
8222
8242
  }
8223
8243
  fromArrayBuffer(buffer) {
8224
8244
  this.encoded = new Uint8Array(buffer, buffer.byteOffset, buffer.byteLength);
8225
8245
  return this.hasCodec()
8226
8246
  ? this.decode()
8227
- : this.create(JSON.parse(new TextDecoder().decode(this.encoded)));
8247
+ : this.create(JSON.parse(new TextDecoder().decode(this.encoded), jsonParseBigInt));
8228
8248
  }
8229
8249
  /**
8230
8250
  * @param {Object} data
@@ -8264,7 +8284,7 @@ class ValidatorMessage extends FormatInterface {
8264
8284
  }
8265
8285
 
8266
8286
  var proto$2 = {
8267
- index: Number(),
8287
+ index: BigInt(0),
8268
8288
  previousHash: String(),
8269
8289
  timestamp: Number(),
8270
8290
  reward: BigInt(0),
@@ -8323,6 +8343,11 @@ class ContractMessage extends FormatInterface {
8323
8343
  }
8324
8344
  }
8325
8345
 
8346
+ ({
8347
+ hash: String(),
8348
+ index: BigInt(0)
8349
+ });
8350
+
8326
8351
  var proto = {
8327
8352
  timestamp: Number(),
8328
8353
  from: String(),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@leofcoin/chain",
3
- "version": "1.7.55",
3
+ "version": "1.7.66",
4
4
  "description": "Official javascript implementation",
5
5
  "private": false,
6
6
  "exports": {
@@ -49,30 +49,30 @@
49
49
  "author": "",
50
50
  "license": "MIT",
51
51
  "devDependencies": {
52
- "@rollup/plugin-commonjs": "^26.0.1",
52
+ "@rollup/plugin-commonjs": "^28.0.0",
53
53
  "@rollup/plugin-json": "^6.1.0",
54
- "@rollup/plugin-node-resolve": "^15.2.3",
55
- "@rollup/plugin-typescript": "^11.1.6",
54
+ "@rollup/plugin-node-resolve": "^15.3.0",
55
+ "@rollup/plugin-typescript": "^12.1.0",
56
56
  "@types/semver": "^7.5.8",
57
57
  "@vandeurenglenn/debug": "^1.2.5",
58
- "rollup": "^4.22.2",
58
+ "rollup": "^4.23.0",
59
59
  "rollup-plugin-modify": "^3.0.0",
60
60
  "tape": "^5.9.0",
61
61
  "tslib": "^2.7.0"
62
62
  },
63
63
  "dependencies": {
64
- "@leofcoin/addresses": "^1.0.43",
65
- "@leofcoin/contracts": "^0.1.13",
66
- "@leofcoin/crypto": "^0.2.27",
67
- "@leofcoin/errors": "^1.0.22",
68
- "@leofcoin/lib": "^1.2.66",
69
- "@leofcoin/messages": "^1.4.36",
64
+ "@leofcoin/addresses": "^1.0.44",
65
+ "@leofcoin/contracts": "^0.1.14",
66
+ "@leofcoin/crypto": "^0.2.28",
67
+ "@leofcoin/errors": "^1.0.23",
68
+ "@leofcoin/lib": "^1.2.67",
69
+ "@leofcoin/messages": "^1.4.37",
70
70
  "@leofcoin/multi-wallet": "^3.1.8",
71
- "@leofcoin/networks": "^1.1.21",
71
+ "@leofcoin/networks": "^1.1.22",
72
72
  "@leofcoin/peernet": "^1.1.80",
73
73
  "@leofcoin/storage": "^3.5.32",
74
- "@leofcoin/utils": "^1.1.33",
75
- "@leofcoin/workers": "^1.5.18",
74
+ "@leofcoin/utils": "^1.1.36",
75
+ "@leofcoin/workers": "^1.5.19",
76
76
  "@vandeurenglenn/base58": "^1.1.9",
77
77
  "@vandeurenglenn/easy-worker": "^1.0.2",
78
78
  "semver": "^7.6.3"