@leofcoin/peernet 1.2.17 → 1.2.19

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 { b as base, a as base58$1, i as index$2, c as index$3, d as index$4, e as index$5, f as createSHA512, g as createSHA384, h as createSHA256, j as createSHA224, k as createSHA1, I as Identity } from './identity-CqSnKXWH.js';
1
+ import { k as index$2, b as base, a as base58$1, l as index$3, m as index$4, n as index$5, h as createSHA512, g as createSHA384, f as createSHA256, e as createSHA224, d as createSHA1, I as Identity } from './identity-CVOmmghe.js';
2
2
  import { K as KeyPath, a as KeyValue } from './value-C3vAp-wb.js';
3
3
 
4
4
  const getTargets = () => Array.from([]);
@@ -126,36 +126,6 @@ var isHex = string => /^[A-F0-9]+$/i.test(
126
126
  string
127
127
  );
128
128
 
129
- const ALPHABET$1 = '0123456789ABCDEF';
130
- base(ALPHABET$1);
131
-
132
- const ALPHABET = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_';
133
- base(ALPHABET);
134
-
135
- /**
136
- * Returns a Uint8Array as String
137
- * @param uint8Array Uint8Array to encode to String
138
- * @returns String
139
- */
140
- const toString$3 = (uint8Array) => new TextDecoder().decode(uint8Array);
141
- /**
142
- * hexString -> uint8Array
143
- * @param string hex encoded string
144
- * @returns UintArray
145
- */
146
- const fromHex = (string) => Uint8Array.from(string.match(/.{1,2}/g).map((byte) => parseInt(byte, 16)));
147
- /**
148
- * uint8Array -> hexString
149
- * @param bytes number[]
150
- * @returns hexString
151
- */
152
- const toHex = (bytes) => bytes.reduce((string, byte) => string + byte.toString(16).padStart(2, '0'), '');
153
- const toBase58 = (uint8Array) => base58$1.encode(uint8Array);
154
- const fromBase58 = (string) => base58$1.decode(string);
155
- const toBase32 = (uint8Array) => index$2.encode(uint8Array);
156
- var index$1 = {
157
- toString: toString$3};
158
-
159
129
  /*! pako 2.1.0 https://github.com/nodeca/pako @license (MIT AND Zlib) */
160
130
  // (C) 1995-2013 Jean-loup Gailly and Mark Adler
161
131
  // (C) 2014-2017 Vitaly Puzrin and Andrey Tupitsin
@@ -3885,7 +3855,7 @@ function ZStream() {
3885
3855
 
3886
3856
  var zstream = ZStream;
3887
3857
 
3888
- const toString$1 = Object.prototype.toString;
3858
+ const toString$1$1 = Object.prototype.toString;
3889
3859
 
3890
3860
  /* Public constants ==========================================================*/
3891
3861
  /* ===========================================================================*/
@@ -4037,7 +4007,7 @@ function Deflate$1(options) {
4037
4007
  if (typeof opt.dictionary === 'string') {
4038
4008
  // If we need to compress text, change encoding to utf8.
4039
4009
  dict = strings.string2buf(opt.dictionary);
4040
- } else if (toString$1.call(opt.dictionary) === '[object ArrayBuffer]') {
4010
+ } else if (toString$1$1.call(opt.dictionary) === '[object ArrayBuffer]') {
4041
4011
  dict = new Uint8Array(opt.dictionary);
4042
4012
  } else {
4043
4013
  dict = opt.dictionary;
@@ -4089,7 +4059,7 @@ Deflate$1.prototype.push = function (data, flush_mode) {
4089
4059
  if (typeof data === 'string') {
4090
4060
  // If we need to compress text, change encoding to utf8.
4091
4061
  strm.input = strings.string2buf(data);
4092
- } else if (toString$1.call(data) === '[object ArrayBuffer]') {
4062
+ } else if (toString$1$1.call(data) === '[object ArrayBuffer]') {
4093
4063
  strm.input = new Uint8Array(data);
4094
4064
  } else {
4095
4065
  strm.input = data;
@@ -7026,88 +6996,128 @@ var pako = {
7026
6996
  };
7027
6997
 
7028
6998
  const jsonStringifyBigInt$1 = (key, value) => (typeof value === 'bigint' ? { $bigint: value.toString() } : value);
7029
- const jsonParseBigInt$1 = (key, value) => typeof value === 'object' && value.$bigint ? BigInt(value.$bigint) : value;
6999
+ const jsonParseBigInt$1 = (key, value) => typeof value === 'object' && value?.$bigint ? BigInt(value.$bigint) : value;
7030
7000
 
7031
- const { toString } = index$1;
7032
- const isString = (type) => type === 'string';
7033
- const isNumber = (type) => type === 'number';
7034
- const isBoolean = (type) => type === 'boolean';
7035
- const isUint8Array = (type) => type === 'uint8Array';
7036
- const isBigInt = (type) => type === 'bigint';
7001
+ const tokenCache = new WeakMap();
7037
7002
  const tokenize = (key, value) => {
7038
7003
  const optional = key.endsWith('?');
7039
7004
  let type = value === undefined ? key : value;
7040
7005
  if (type instanceof Uint8Array)
7041
7006
  type = 'uint8Array';
7042
- else if (type instanceof BigInt)
7007
+ else if (typeof type === 'bigint')
7043
7008
  type = 'bigint';
7044
7009
  else
7045
7010
  type = Array.isArray(type) ? 'array' : typeof type;
7046
7011
  const parts = key.split('?');
7047
- const minimumLength = parts[2]?.includes('min') ? parts[2].split['min:'][1] : 0;
7048
- return { type, optional, key: parts[0], minimumLength };
7012
+ const minimumLength = parts[2]?.includes('min') ? Number(parts[2].split('min:')[1]) : 0;
7013
+ return { type, optional, key: parts[0], minimumLength, defaultValue: value };
7049
7014
  };
7015
+ const getTokens = (proto) => {
7016
+ if (tokenCache.has(proto))
7017
+ return tokenCache.get(proto);
7018
+ const keys = Object.keys(proto);
7019
+ const values = Object.values(proto);
7020
+ const tokens = keys.map((k, i) => tokenize(k, values[i]));
7021
+ tokenCache.set(proto, tokens);
7022
+ return tokens;
7023
+ };
7024
+
7025
+ const encoder = new TextEncoder();
7050
7026
  const toType = (data) => {
7051
- // always return uint8Arrays as they are
7052
7027
  if (data instanceof Uint8Array)
7053
7028
  return data;
7054
- // returns the ArrayBuffer as UintArray
7055
7029
  if (data instanceof ArrayBuffer)
7056
7030
  return new Uint8Array(data);
7057
- // returns the BigTnt string as UintArray
7058
7031
  if (typeof data === 'bigint')
7059
- return new TextEncoder().encode(data.toString());
7060
- // returns the string as UintArray
7032
+ return encoder.encode(data.toString());
7061
7033
  if (typeof data === 'string')
7062
- return new TextEncoder().encode(data);
7063
- // returns the object as UintArray
7034
+ return encoder.encode(data);
7064
7035
  if (typeof data === 'object')
7065
- return new TextEncoder().encode(JSON.stringify(data, jsonStringifyBigInt$1));
7066
- // returns the number as UintArray
7036
+ return encoder.encode(JSON.stringify(data, jsonStringifyBigInt$1));
7067
7037
  if (typeof data === 'number' || typeof data === 'boolean')
7068
- return new TextEncoder().encode(data.toString());
7038
+ return encoder.encode(data.toString());
7069
7039
  throw new Error(`unsuported type ${typeof data || data}`);
7070
7040
  };
7071
7041
  const encode = (proto, input, compress) => {
7072
- const keys = Object.keys(proto);
7073
- const values = Object.values(proto);
7042
+ const tokens = getTokens(proto);
7074
7043
  const set = [];
7075
- for (let i = 0; i < values.length; i++) {
7076
- const token = tokenize(keys[i], values[i]);
7044
+ for (let i = 0; i < tokens.length; i++) {
7045
+ const token = tokens[i];
7077
7046
  const data = input[token.key];
7078
7047
  if (!token.optional && data === undefined)
7079
7048
  throw new Error(`missing required property: ${token.key}`);
7080
7049
  if ((token.type === 'array' && token.minimumLength > data?.length) ||
7081
7050
  (token.type === 'object' && token.minimumLength > Object.keys(data).length))
7082
7051
  throw new Error(`minimumLength for ${token.key} is set to ${token.minimumLength} but got ${data.length}`);
7083
- // always push data to the set.
7084
- // when data is undefined push the default value of the proto
7085
- set.push(toType(data || values[i]));
7052
+ set.push(toType(data !== undefined ? data : token.defaultValue));
7086
7053
  }
7087
- return compress ? pako.deflate(index$3(set)) : index$3(set);
7054
+ return compress ? pako.deflate(index$2(set)) : index$2(set);
7088
7055
  };
7056
+
7057
+ const ALPHABET$1 = '0123456789ABCDEF';
7058
+ const base16 = base(ALPHABET$1);
7059
+ base16.decode;
7060
+ base16.encode;
7061
+
7062
+ const ALPHABET = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_';
7063
+ const base64 = base(ALPHABET);
7064
+ base64.decode;
7065
+ base64.encode;
7066
+
7067
+ /**
7068
+ * Returns a Uint8Array as String
7069
+ * @param uint8Array Uint8Array to encode to String
7070
+ * @returns String
7071
+ */
7072
+ const toString$1 = (uint8Array) => new TextDecoder().decode(uint8Array);
7073
+ /**
7074
+ * hexString -> uint8Array
7075
+ * @param string hex encoded string
7076
+ * @returns UintArray
7077
+ */
7078
+ const fromHex = (string) => Uint8Array.from(string.match(/.{1,2}/g).map((byte) => parseInt(byte, 16)));
7079
+ /**
7080
+ * uint8Array -> hexString
7081
+ * @param bytes number[]
7082
+ * @returns hexString
7083
+ */
7084
+ const toHex = (bytes) => bytes.reduce((string, byte) => string + byte.toString(16).padStart(2, '0'), '');
7085
+ /**
7086
+ * number[] -> Uint8Array
7087
+ * @param array number[]
7088
+ * @returns Uint8Array
7089
+ */
7090
+ const fromArrayLike = (array) => Uint8Array.from(array);
7091
+ const toBase58 = (uint8Array) => base58$1.encode(uint8Array);
7092
+ const fromBase58 = (string) => base58$1.decode(string);
7093
+ const toBase32 = (uint8Array) => index$3.encode(uint8Array);
7094
+ var index$1 = {
7095
+ toString: toString$1};
7096
+
7097
+ const { toString } = index$1;
7098
+ const decoder = new TextDecoder();
7089
7099
  const decode = (proto, uint8Array, compressed) => {
7090
7100
  if (compressed)
7091
7101
  uint8Array = pako.inflate(uint8Array);
7092
7102
  let deconcated = index$4(uint8Array);
7093
7103
  const output = {};
7094
- const keys = Object.keys(proto);
7095
- const values = Object.values(proto);
7096
- if (keys.length !== deconcated.length)
7097
- console.warn(`length mismatch: expected ${keys.length} got ${uint8Array.length}`);
7098
- for (let i = 0; i < values.length; i++) {
7099
- const token = tokenize(keys[i], values[i]);
7100
- if (isUint8Array(token.type))
7104
+ const tokens = getTokens(proto);
7105
+ if (tokens.length !== deconcated.length)
7106
+ console.warn(`length mismatch: expected ${tokens.length} got ${uint8Array.length}`);
7107
+ for (let i = 0; i < tokens.length; i++) {
7108
+ const token = tokens[i];
7109
+ if (token.type === 'uint8Array')
7101
7110
  output[token.key] = deconcated[i];
7102
- else if (isString(token.type))
7111
+ else if (token.type === 'string')
7103
7112
  output[token.key] = toString(deconcated[i]);
7104
- else if (isBoolean(token.type))
7105
- output[token.key] = new TextDecoder().decode(deconcated[i]) === 'true';
7106
- else if (isNumber(token.type))
7107
- output[token.key] = Number(new TextDecoder().decode(deconcated[i]));
7108
- else if (isBigInt(token.type))
7109
- output[token.key] = BigInt(new TextDecoder().decode(deconcated[i]));
7110
- else output[token.key] = JSON.parse(new TextDecoder().decode(deconcated[i]), jsonParseBigInt$1);
7113
+ else if (token.type === 'boolean')
7114
+ output[token.key] = decoder.decode(deconcated[i]) === 'true';
7115
+ else if (token.type === 'number')
7116
+ output[token.key] = Number(decoder.decode(deconcated[i]));
7117
+ else if (token.type === 'bigint')
7118
+ output[token.key] = BigInt(decoder.decode(deconcated[i]));
7119
+ else if (token.type === 'object' || token.type === 'array')
7120
+ output[token.key] = JSON.parse(decoder.decode(deconcated[i]), jsonParseBigInt$1);
7111
7121
  if (token.optional) {
7112
7122
  if (!output[token.key] || output[token.key].length === 0)
7113
7123
  delete output[token.key];
@@ -7117,10 +7127,8 @@ const decode = (proto, uint8Array, compressed) => {
7117
7127
  }
7118
7128
  return output;
7119
7129
  };
7120
- var index = {
7121
- encode,
7122
- decode
7123
- };
7130
+
7131
+ var index = { encode, decode };
7124
7132
 
7125
7133
  const jsonStringifyBigInt = (key, value) => {
7126
7134
  if (typeof value === 'bigint')
@@ -7134,13 +7142,13 @@ const jsonParseBigInt = (key, value) => {
7134
7142
  }
7135
7143
  return value;
7136
7144
  };
7137
- const _textEncoder = new TextEncoder();
7138
- const _textDecoder = new TextDecoder();
7139
7145
  class BasicInterface {
7140
7146
  #encoded;
7141
7147
  #decoded;
7142
7148
  name;
7143
7149
  #proto;
7150
+ textEncoder = new TextEncoder();
7151
+ textDecoder = new TextDecoder();
7144
7152
  get keys() {
7145
7153
  // handles proto keys
7146
7154
  // protokey -> key
@@ -7168,11 +7176,42 @@ class BasicInterface {
7168
7176
  get proto() {
7169
7177
  return this.#proto;
7170
7178
  }
7179
+ from(value) {
7180
+ if (value instanceof Uint8Array)
7181
+ this.fromUint8Array(value);
7182
+ else if (value instanceof ArrayBuffer)
7183
+ this.fromArrayBuffer(value);
7184
+ else if (typeof value === 'string' && isHex(value)) {
7185
+ this.fromHex(value);
7186
+ }
7187
+ else if (typeof value === 'string') {
7188
+ if (base58$1.isBase58(value)) {
7189
+ try {
7190
+ this.fromBs58(value);
7191
+ }
7192
+ catch {
7193
+ if (index$3.isBase32(value))
7194
+ this.fromBs32(value);
7195
+ else
7196
+ throw new Error('Invalid base58/base32 input');
7197
+ }
7198
+ }
7199
+ else if (index$3.isBase32(value))
7200
+ this.fromBs32(value);
7201
+ else
7202
+ this.fromString(value);
7203
+ }
7204
+ else if (Array.isArray(value))
7205
+ this.fromArray(value);
7206
+ else if (typeof value === 'object')
7207
+ this.create(value);
7208
+ return this;
7209
+ }
7171
7210
  decode(encoded) {
7172
7211
  encoded = encoded || this.encoded;
7173
7212
  // Example: decode as JSON if possible (override in subclass)
7174
7213
  try {
7175
- return JSON.parse(_textDecoder.decode(encoded), jsonParseBigInt);
7214
+ return JSON.parse(this.textDecoder.decode(encoded), jsonParseBigInt);
7176
7215
  }
7177
7216
  catch {
7178
7217
  return new Object();
@@ -7181,9 +7220,16 @@ class BasicInterface {
7181
7220
  encode(decoded) {
7182
7221
  decoded = decoded || this.decoded;
7183
7222
  // Example: encode as JSON (override in subclass)
7184
- return _textEncoder.encode(JSON.stringify(decoded, jsonStringifyBigInt));
7223
+ return this.textEncoder.encode(JSON.stringify(decoded, jsonStringifyBigInt));
7185
7224
  }
7186
7225
  // get Codec(): Codec {}
7226
+ create(options) {
7227
+ for (const key of this.keys) {
7228
+ if (options[key]) {
7229
+ this[key] = options[key];
7230
+ }
7231
+ }
7232
+ }
7187
7233
  // Cache proto keys/values for reuse
7188
7234
  static _protoCache = new WeakMap();
7189
7235
  protoEncode(data) {
@@ -7218,13 +7264,13 @@ class BasicInterface {
7218
7264
  return isHex(string);
7219
7265
  }
7220
7266
  isBase32(string) {
7221
- return index$2.isBase32(string);
7267
+ return index$3.isBase32(string);
7222
7268
  }
7223
7269
  isBase58(string) {
7224
7270
  return base58$1.isBase58(string);
7225
7271
  }
7226
7272
  fromBs32(encoded) {
7227
- return this.decode(index$2.decode(encoded));
7273
+ return this.decode(index$3.decode(encoded));
7228
7274
  }
7229
7275
  fromBs58(encoded) {
7230
7276
  return this.decode(fromBase58(encoded));
@@ -7250,8 +7296,26 @@ class BasicInterface {
7250
7296
  return this.decode(array);
7251
7297
  return this.decode(Uint8Array.from(array));
7252
7298
  }
7253
- fromEncoded(encoded) {
7254
- return this.decode(encoded);
7299
+ fromArrayBuffer(uint8Array) {
7300
+ return fromArrayLike(new Uint8Array(uint8Array));
7301
+ }
7302
+ fromUint8Array(uint8Array) {
7303
+ return fromArrayLike(uint8Array);
7304
+ }
7305
+ toUint8Array(format) {
7306
+ if (format === 'bs32')
7307
+ return toBase32(this.encoded);
7308
+ if (format === 'bs58')
7309
+ return toBase58(this.encoded);
7310
+ if (format === 'hex')
7311
+ return toHex(this.encoded);
7312
+ if (format === 'utf8')
7313
+ return this.encoded.toString();
7314
+ if (format === 'uint8Array')
7315
+ return this.encoded;
7316
+ if (format === 'uint8ArrayString')
7317
+ return this.encoded.toString();
7318
+ throw new Error(`Unknown format: ${format}`);
7255
7319
  }
7256
7320
  toString() {
7257
7321
  if (!this.encoded)
@@ -7293,209 +7357,237 @@ class BasicInterface {
7293
7357
  }
7294
7358
  }
7295
7359
 
7296
- const blockchainCodecs = [
7297
- {
7298
- name: 'leofcoin-block',
7299
- codec: '0x6c62',
7300
- hashAlg: 'dbl-keccak-512',
7301
- },
7302
- {
7303
- name: 'leofcoin-tx',
7304
- codec: '0x6c74',
7305
- hashAlg: 'dbl-keccak-512',
7306
- },
7307
- {
7308
- name: 'leofcoin-itx',
7309
- codec: '0x6c69',
7310
- hashAlg: 'keccak-512',
7311
- },
7312
- {
7313
- name: 'leofcoin-pr',
7314
- codec: '0x6c70',
7315
- hashAlg: 'keccak-256',
7316
- },
7317
- {
7318
- name: 'contract-message',
7319
- codec: '0x63636d',
7320
- hashAlg: 'keccak-256'
7321
- },
7322
- {
7323
- name: 'transaction-message',
7324
- codec: '0x746d',
7325
- hashAlg: 'keccak-256'
7326
- },
7327
- {
7328
- name: 'raw-transaction-message',
7329
- codec: '0x772746d',
7330
- hashAlg: 'keccak-256'
7331
- },
7332
- {
7333
- name: 'block-message',
7334
- codec: '0x626d',
7335
- hashAlg: 'keccak-256'
7336
- },
7337
- {
7338
- name: 'bw-message',
7339
- codec: '0x62776d',
7340
- hashAlg: 'keccak-256'
7341
- },
7342
- {
7343
- name: 'bw-request-message',
7344
- codec: '0x6277726d',
7345
- hashAlg: 'keccak-256'
7346
- },
7347
- {
7348
- name: 'validator-message',
7349
- codec: '0x766d',
7350
- hashAlg: 'keccak-256'
7351
- }
7360
+ const blockchainCodecs = [
7361
+ {
7362
+ name: 'leofcoin-block',
7363
+ codec: '0x6c62',
7364
+ hashAlg: 'dbl-keccak-512'
7365
+ },
7366
+ {
7367
+ name: 'leofcoin-tx',
7368
+ codec: '0x6c74',
7369
+ hashAlg: 'dbl-keccak-512'
7370
+ },
7371
+ {
7372
+ name: 'leofcoin-itx',
7373
+ codec: '0x6c69',
7374
+ hashAlg: 'keccak-512'
7375
+ },
7376
+ {
7377
+ name: 'leofcoin-pr',
7378
+ codec: '0x6c70',
7379
+ hashAlg: 'keccak-256'
7380
+ },
7381
+ {
7382
+ name: 'contract-message',
7383
+ codec: '0x63636d',
7384
+ hashAlg: 'keccak-256'
7385
+ },
7386
+ {
7387
+ name: 'transaction-message',
7388
+ codec: '0x746d',
7389
+ hashAlg: 'keccak-256'
7390
+ },
7391
+ {
7392
+ name: 'raw-transaction-message',
7393
+ codec: '0x772746d',
7394
+ hashAlg: 'keccak-256'
7395
+ },
7396
+ {
7397
+ name: 'block-message',
7398
+ codec: '0x626d',
7399
+ hashAlg: 'keccak-256'
7400
+ },
7401
+ {
7402
+ name: 'bw-message',
7403
+ codec: '0x62776d',
7404
+ hashAlg: 'keccak-256'
7405
+ },
7406
+ {
7407
+ name: 'bw-request-message',
7408
+ codec: '0x6277726d',
7409
+ hashAlg: 'keccak-256'
7410
+ },
7411
+ {
7412
+ name: 'validator-message',
7413
+ codec: '0x766d',
7414
+ hashAlg: 'keccak-256'
7415
+ },
7416
+ {
7417
+ name: 'last-block-message',
7418
+ codec: '0x6c626d',
7419
+ hashAlg: 'keccak-256'
7420
+ },
7421
+ {
7422
+ name: 'last-block-request-message',
7423
+ codec: '0x6c62726d',
7424
+ hashAlg: 'keccak-256'
7425
+ },
7426
+ {
7427
+ name: 'state-message',
7428
+ codec: '0x73746d',
7429
+ hashAlg: 'keccak-256'
7430
+ },
7431
+ {
7432
+ name: 'publish-message',
7433
+ codec: '0x70626d',
7434
+ hashAlg: 'keccak-256'
7435
+ }
7352
7436
  ];
7353
-
7354
- const internalCodecs = [
7355
- {
7356
- name: 'pubsub-request',
7357
- codec: '0x70737271',
7358
- hashAlg: 'keccak-256'
7359
- },
7360
- {
7361
- name: 'pubsub-response',
7362
- codec: '0x707372',
7363
- hashAlg: 'keccak-256'
7364
- }
7437
+ const consensusCodecs = [
7438
+ {
7439
+ name: 'proposal-message',
7440
+ codec: '0x70726d',
7441
+ hashAlg: 'keccak-256'
7442
+ },
7443
+ {
7444
+ name: 'prevote-message',
7445
+ codec: '0x70766d',
7446
+ hashAlg: 'keccak-256'
7447
+ },
7448
+ {
7449
+ name: 'precommit-message',
7450
+ codec: '0x7063636d',
7451
+ hashAlg: 'keccak-256'
7452
+ }
7365
7453
  ];
7366
-
7367
- var social = [{
7368
- name: 'chat-message',
7369
- codec: '0x70636d',
7370
- hashAlg: 'dbl-keccak-256',
7371
- }];
7372
-
7373
- const peernetCodecs = [
7374
- {
7375
- name: 'disco-hash',
7376
- codec: '0x30',
7377
- hashAlg: 'dbl-keccak-256',
7378
- },
7379
- {
7380
- name: 'peernet-peer-response',
7381
- codec: '0x707072',
7382
- hashAlg: 'keccak-256',
7383
- },
7384
- {
7385
- name: 'peernet-peer',
7386
- codec: '0x7070',
7387
- hashAlg: 'keccak-256',
7388
- },
7389
- {
7390
- name: 'peernet-dht',
7391
- codec: '0x706468',
7392
- hashAlg: 'keccak-256',
7393
- },
7394
- {
7395
- name: 'peernet-dht-response',
7396
- codec: '0x706472',
7397
- hashAlg: 'keccak-256',
7398
- },
7399
- {
7400
- name: 'peernet-data',
7401
- codec: '0x706461',
7402
- hashAlg: 'keccak-256',
7403
- },
7404
- {
7405
- name: 'peernet-data-response',
7406
- codec: '0x70646172',
7407
- hashAlg: 'keccak-256',
7408
- },
7409
- {
7410
- name: 'peernet-message',
7411
- codec: '0x706d65',
7412
- hashAlg: 'keccak-256',
7413
- },
7414
- {
7415
- name: 'peernet-ps',
7416
- codec: '707073',
7417
- hashAlg: 'keccak-256',
7418
- },
7419
- {
7420
- name: 'peernet-response',
7421
- codec: '0x7072',
7422
- hashAlg: 'keccak-256',
7423
- },
7424
- {
7425
- name: 'peernet-request',
7426
- codec: '0x707271',
7427
- hashAlg: 'keccak-256',
7428
- },
7429
- {
7430
- name: 'peernet-file',
7431
- codec: '0x7066',
7432
- hashAlg: 'keccak-256',
7433
- },
7434
- {
7435
- name: 'peernet-file-response',
7436
- codec: '0x706672',
7437
- hashAlg: 'keccak-256',
7438
- }
7454
+ const internalCodecs = [
7455
+ {
7456
+ name: 'pubsub-request',
7457
+ codec: '0x70737271',
7458
+ hashAlg: 'keccak-256'
7459
+ },
7460
+ {
7461
+ name: 'pubsub-response',
7462
+ codec: '0x707372',
7463
+ hashAlg: 'keccak-256'
7464
+ }
7439
7465
  ];
7440
-
7441
- const codecs$1 = [
7442
- ...internalCodecs,
7443
- ...blockchainCodecs,
7444
- ...social,
7445
- ...peernetCodecs
7466
+ const socialCodecs = [
7467
+ {
7468
+ name: 'chat-message',
7469
+ codec: '0x70636d',
7470
+ hashAlg: 'dbl-keccak-256'
7471
+ }
7472
+ ];
7473
+ const peernetCodecs = [
7474
+ {
7475
+ name: 'disco-hash',
7476
+ codec: '0x30',
7477
+ hashAlg: 'dbl-keccak-256'
7478
+ },
7479
+ {
7480
+ name: 'peernet-peer-response',
7481
+ codec: '0x707072',
7482
+ hashAlg: 'keccak-256'
7483
+ },
7484
+ {
7485
+ name: 'peernet-peer',
7486
+ codec: '0x7070',
7487
+ hashAlg: 'keccak-256'
7488
+ },
7489
+ {
7490
+ name: 'peernet-dht',
7491
+ codec: '0x706468',
7492
+ hashAlg: 'keccak-256'
7493
+ },
7494
+ {
7495
+ name: 'peernet-dht-response',
7496
+ codec: '0x706472',
7497
+ hashAlg: 'keccak-256'
7498
+ },
7499
+ {
7500
+ name: 'peernet-data',
7501
+ codec: '0x706461',
7502
+ hashAlg: 'keccak-256'
7503
+ },
7504
+ {
7505
+ name: 'peernet-data-response',
7506
+ codec: '0x70646172',
7507
+ hashAlg: 'keccak-256'
7508
+ },
7509
+ {
7510
+ name: 'peernet-message',
7511
+ codec: '0x706d65',
7512
+ hashAlg: 'keccak-256'
7513
+ },
7514
+ {
7515
+ name: 'peernet-ps',
7516
+ codec: '707073',
7517
+ hashAlg: 'keccak-256'
7518
+ },
7519
+ {
7520
+ name: 'peernet-response',
7521
+ codec: '0x7072',
7522
+ hashAlg: 'keccak-256'
7523
+ },
7524
+ {
7525
+ name: 'peernet-request',
7526
+ codec: '0x707271',
7527
+ hashAlg: 'keccak-256'
7528
+ },
7529
+ {
7530
+ name: 'peernet-file',
7531
+ codec: '0x7066',
7532
+ hashAlg: 'keccak-256'
7533
+ },
7534
+ {
7535
+ name: 'peernet-file-response',
7536
+ codec: '0x706672',
7537
+ hashAlg: 'keccak-256'
7538
+ }
7539
+ ];
7540
+ const codecs = [
7541
+ ...internalCodecs,
7542
+ ...blockchainCodecs,
7543
+ ...consensusCodecs,
7544
+ ...socialCodecs,
7545
+ ...peernetCodecs
7446
7546
  ];
7447
7547
 
7448
- const codecs = {};
7449
- const addCodec = (codecInput) => {
7450
- let { hashAlg, codec, name } = codecInput;
7451
- if (!codecs[name])
7452
- codecs[name] = {
7453
- hashAlg,
7454
- codec: typeof codec === 'string' ? parseInt(codec, 16) : codec
7455
- };
7456
- };
7457
- for (const codec of codecs$1) {
7458
- addCodec(codec);
7459
- }
7460
- const getCodec = (name) => {
7461
- if (typeof name === 'number')
7462
- return name;
7463
- return getCodecByName(name).codec;
7464
- };
7465
- const getCodecName = (codec) => {
7466
- return Object.keys(codecs).reduce((p, c) => {
7467
- const item = codecs[c];
7468
- if (item.codec === codec)
7469
- return c;
7470
- else
7471
- return p;
7472
- }, undefined);
7473
- };
7474
- const getCodecByName = (name) => codecs[name];
7475
- const getHashAlg = (name) => {
7476
- if (typeof name === 'number')
7477
- return getCodecByName(getCodecName(name)).hashAlg;
7478
- return getCodecByName(name).hashAlg;
7479
- };
7480
- const isCodec = (codec) => {
7481
- if (codec.codec !== undefined && codec.hashAlg)
7482
- return true;
7483
- return false;
7484
- };
7485
- const validateCodec = (codec) => {
7486
- if (codec.codec === undefined ||
7487
- codec.hashAlg === undefined ||
7488
- codec.name === undefined)
7489
- throw new Error(`invalid codecInput: ${codec}`);
7490
- };
7491
- var utils = {
7492
- isCodec,
7493
- addCodec,
7494
- getCodec,
7495
- getHashAlg,
7496
- getCodecName,
7497
- validateCodec,
7498
- codecs: codecs
7548
+ const registry = {};
7549
+ const addCodec = (codecInput) => {
7550
+ const { hashAlg, codec, name } = codecInput;
7551
+ if (!registry[name])
7552
+ registry[name] = {
7553
+ hashAlg,
7554
+ codec: typeof codec === 'string' ? parseInt(codec, 16) : codec
7555
+ };
7556
+ };
7557
+ for (const codec of codecs) {
7558
+ addCodec(codec);
7559
+ }
7560
+ const getCodecByName = (name) => registry[name];
7561
+ const getCodecName = (codec) => {
7562
+ return Object.keys(registry).reduce((p, c) => {
7563
+ return registry[c].codec === codec ? c : p;
7564
+ }, undefined);
7565
+ };
7566
+ const getCodec = (name) => {
7567
+ if (typeof name === 'number')
7568
+ return name;
7569
+ return getCodecByName(name).codec;
7570
+ };
7571
+ const getHashAlg = (name) => {
7572
+ if (typeof name === 'number')
7573
+ return getCodecByName(getCodecName(name)).hashAlg;
7574
+ return getCodecByName(name).hashAlg;
7575
+ };
7576
+ const isCodec = (codec) => {
7577
+ return codec.codec !== undefined && !!codec.hashAlg;
7578
+ };
7579
+ const validateCodec = (codec) => {
7580
+ if (codec.codec === undefined || codec.hashAlg === undefined || codec.name === undefined)
7581
+ throw new Error(`invalid codecInput: ${codec}`);
7582
+ };
7583
+ const utils = {
7584
+ isCodec,
7585
+ addCodec,
7586
+ getCodec,
7587
+ getHashAlg,
7588
+ getCodecName,
7589
+ validateCodec,
7590
+ codecs: registry
7499
7591
  };
7500
7592
 
7501
7593
  let Codec$1 = class Codec extends BasicInterface {
@@ -7742,34 +7834,11 @@ let FormatInterface$1 = class FormatInterface extends BasicInterface {
7742
7834
  set encoded(value) {
7743
7835
  this.#encoded = value;
7744
7836
  }
7745
- init(buffer) {
7746
- if (buffer instanceof FormatInterface && buffer?.name === this.name) {
7747
- return buffer;
7837
+ init(value) {
7838
+ if (value instanceof FormatInterface && value?.name === this.name) {
7839
+ return value;
7748
7840
  }
7749
- else if (buffer instanceof Uint8Array) {
7750
- this.fromUint8Array(buffer);
7751
- }
7752
- else if (buffer instanceof ArrayBuffer) {
7753
- this.fromArrayBuffer(buffer);
7754
- }
7755
- else if (typeof buffer === 'string') {
7756
- if (this.isHex(buffer))
7757
- this.fromHex(buffer);
7758
- else if (this.isBase58(buffer))
7759
- this.fromBs58(buffer);
7760
- else if (this.isBase32(buffer))
7761
- this.fromBs32(buffer);
7762
- else
7763
- this.fromString(buffer);
7764
- }
7765
- else if (typeof buffer === 'object' && buffer !== null) {
7766
- this.create(buffer);
7767
- }
7768
- else {
7769
- // Explicitly reject all other types (number, boolean, undefined, symbol, function, null)
7770
- throw new TypeError(`Invalid input type for FormatInterface: ${typeof buffer}`);
7771
- }
7772
- return this;
7841
+ return this.from(value);
7773
7842
  }
7774
7843
  hasCodec() {
7775
7844
  if (!this.encoded)
@@ -7887,13 +7956,13 @@ let FormatInterface$1 = class FormatInterface extends BasicInterface {
7887
7956
  this.encoded = buffer;
7888
7957
  return this.hasCodec()
7889
7958
  ? this.decode()
7890
- : this.create(JSON.parse(BasicInterface._textDecoder.decode(this.encoded), jsonParseBigInt));
7959
+ : this.create(JSON.parse(this.textDecoder.decode(this.encoded), jsonParseBigInt));
7891
7960
  }
7892
7961
  fromArrayBuffer(buffer) {
7893
7962
  this.encoded = new Uint8Array(buffer, buffer.byteOffset, buffer.byteLength);
7894
7963
  return this.hasCodec()
7895
7964
  ? this.decode()
7896
- : this.create(JSON.parse(BasicInterface._textDecoder.decode(this.encoded), jsonParseBigInt));
7965
+ : this.create(JSON.parse(this.textDecoder.decode(this.encoded), jsonParseBigInt));
7897
7966
  }
7898
7967
  /**
7899
7968
  * @param {Object} data
@@ -8475,7 +8544,7 @@ class Peernet {
8475
8544
  await getAddress();
8476
8545
  this.storePrefix = options.storePrefix;
8477
8546
  this.root = options.root;
8478
- const { RequestMessage, ResponseMessage, PeerMessage, PeerMessageResponse, PeernetMessage, DHTMessage, DHTMessageResponse, DataMessage, DataMessageResponse, PsMessage, ChatMessage, PeernetFile } = await import(/* webpackChunkName: "messages" */ './messages-B1x_wCLa.js');
8547
+ const { RequestMessage, ResponseMessage, PeerMessage, PeerMessageResponse, PeernetMessage, DHTMessage, DHTMessageResponse, DataMessage, DataMessageResponse, PsMessage, ChatMessage, PeernetFile } = await import(/* webpackChunkName: "messages" */ './messages-CVgBNJyv.js');
8479
8548
  /**
8480
8549
  * proto Object containing protos
8481
8550
  * @type {Object}
@@ -8522,7 +8591,7 @@ class Peernet {
8522
8591
  if (this.#starting || this.#started)
8523
8592
  return;
8524
8593
  this.#starting = true;
8525
- const importee = await import('./client-otmI2TFk.js');
8594
+ const importee = await import('./client-DoGApAbT.js');
8526
8595
  /**
8527
8596
  * @access public
8528
8597
  * @type {PeernetClient}