@leofcoin/peernet 1.1.72 → 1.1.74

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,12 +1,29 @@
1
- import { K as KeyPath, a as KeyValue } from './value-4e80eeeb.js';
1
+ import { K as KeyPath, a as KeyValue } from './value-wzPYMxsX.js';
2
2
 
3
3
  if (!globalThis.DEBUG) {
4
- if (globalThis.localStorage) globalThis.DEBUG = Boolean(globalThis.localStorage.getItem('DEBUG') === 'true');
4
+ let DEBUG = [];
5
+ if (globalThis.localStorage) {
6
+ DEBUG = globalThis.localStorage.getItem('DEBUG');
7
+ globalThis.DEBUG = DEBUG ? DEBUG.split(',') : [DEBUG];
8
+ }
5
9
  }
6
10
 
7
- globalThis.debug = text => {
8
- if (globalThis.DEBUG) console.log('\x1b[34m\x1b[1m%s', text, '\x1b[0m'); // bright blue
9
- };
11
+ if (!globalThis.debug) {
12
+ globalThis.debug = (target, text) => {
13
+ if (!globalThis.DEBUG && globalThis.DEBUG.length === 0) return;
14
+ if (
15
+ globalThis.DEBUG.indexOf(target) !== -1 ||
16
+ globalThis.DEBUG.indexOf('*') !== -1 ||
17
+ globalThis.DEBUG === 'true' ||
18
+ globalThis.DEBUG === true
19
+ )
20
+ if (text)
21
+ console.log('\x1b[34m\x1b[1m%s', `${target}: ${text}`, '\x1b[0m');
22
+ else console.log('\x1b[34m\x1b[1m%s', `${target}`, '\x1b[0m');
23
+ };
24
+ globalThis.createDebugger = (target) => (text) =>
25
+ globalThis.debug(target, text);
26
+ }
10
27
 
11
28
  class LittlePubSub {
12
29
  subscribers = {};
@@ -669,10 +686,7 @@ function getAugmentedNamespace(n) {
669
686
  if (typeof f == "function") {
670
687
  var a = function a () {
671
688
  if (this instanceof a) {
672
- var args = [null];
673
- args.push.apply(args, arguments);
674
- var Ctor = Function.bind.apply(f, args);
675
- return new Ctor();
689
+ return Reflect.construct(f, arguments, this.constructor);
676
690
  }
677
691
  return f.apply(this, arguments);
678
692
  };
@@ -700,7 +714,7 @@ var _nodeResolve_empty$1 = /*#__PURE__*/Object.freeze({
700
714
  default: _nodeResolve_empty
701
715
  });
702
716
 
703
- var require$$0$1 = /*@__PURE__*/getAugmentedNamespace(_nodeResolve_empty$1);
717
+ var require$$3 = /*@__PURE__*/getAugmentedNamespace(_nodeResolve_empty$1);
704
718
 
705
719
  bn$1.exports;
706
720
 
@@ -759,7 +773,7 @@ bn$1.exports;
759
773
  if (typeof window !== 'undefined' && typeof window.Buffer !== 'undefined') {
760
774
  Buffer = window.Buffer;
761
775
  } else {
762
- Buffer = require$$0$1.Buffer;
776
+ Buffer = require$$3.Buffer;
763
777
  }
764
778
  } catch (e) {
765
779
  }
@@ -12751,7 +12765,7 @@ const nothingFoundError = (hash) => {
12751
12765
  return new Error(`nothing found for ${hash}`)
12752
12766
  };
12753
12767
 
12754
- const isBrowser = globalThis.navigator ? true : false;
12768
+ const isBrowser = globalThis.process?.versions?.node ? false : true;
12755
12769
  let LeofcoinStorage$1 = class LeofcoinStorage {
12756
12770
  name;
12757
12771
  root;
@@ -13000,514 +13014,177 @@ var index$1 = {
13000
13014
  }
13001
13015
  };
13002
13016
 
13003
- const errors = {
13004
- IMPOSSIBLE_CASE: 'Impossible case. Please create issue.',
13005
- TWEAK_ADD:
13006
- 'The tweak was out of range or the resulted private key is invalid',
13007
- TWEAK_MUL: 'The tweak was out of range or equal to zero',
13008
- CONTEXT_RANDOMIZE_UNKNOW: 'Unknow error on context randomization',
13009
- SECKEY_INVALID: 'Private Key is invalid',
13010
- PUBKEY_PARSE: 'Public Key could not be parsed',
13011
- PUBKEY_SERIALIZE: 'Public Key serialization error',
13012
- PUBKEY_COMBINE: 'The sum of the public keys is not valid',
13013
- SIG_PARSE: 'Signature could not be parsed',
13014
- SIGN: 'The nonce generation function failed, or the private key was invalid',
13015
- RECOVER: 'Public key could not be recover',
13016
- ECDH: 'Scalar was invalid (zero or overflow)'
13017
+ var elliptic$2 = {};
13018
+
13019
+ var name = "elliptic";
13020
+ var version$1 = "6.5.4";
13021
+ var description = "EC cryptography";
13022
+ var main = "lib/elliptic.js";
13023
+ var files = [
13024
+ "lib"
13025
+ ];
13026
+ var scripts = {
13027
+ lint: "eslint lib test",
13028
+ "lint:fix": "npm run lint -- --fix",
13029
+ unit: "istanbul test _mocha --reporter=spec test/index.js",
13030
+ test: "npm run lint && npm run unit",
13031
+ version: "grunt dist && git add dist/"
13032
+ };
13033
+ var repository = {
13034
+ type: "git",
13035
+ url: "git@github.com:indutny/elliptic"
13036
+ };
13037
+ var keywords = [
13038
+ "EC",
13039
+ "Elliptic",
13040
+ "curve",
13041
+ "Cryptography"
13042
+ ];
13043
+ var author = "Fedor Indutny <fedor@indutny.com>";
13044
+ var license = "MIT";
13045
+ var bugs = {
13046
+ url: "https://github.com/indutny/elliptic/issues"
13047
+ };
13048
+ var homepage = "https://github.com/indutny/elliptic";
13049
+ var devDependencies = {
13050
+ brfs: "^2.0.2",
13051
+ coveralls: "^3.1.0",
13052
+ eslint: "^7.6.0",
13053
+ grunt: "^1.2.1",
13054
+ "grunt-browserify": "^5.3.0",
13055
+ "grunt-cli": "^1.3.2",
13056
+ "grunt-contrib-connect": "^3.0.0",
13057
+ "grunt-contrib-copy": "^1.0.0",
13058
+ "grunt-contrib-uglify": "^5.0.0",
13059
+ "grunt-mocha-istanbul": "^5.0.2",
13060
+ "grunt-saucelabs": "^9.0.1",
13061
+ istanbul: "^0.4.5",
13062
+ mocha: "^8.0.1"
13063
+ };
13064
+ var dependencies = {
13065
+ "bn.js": "^4.11.9",
13066
+ brorand: "^1.1.0",
13067
+ "hash.js": "^1.0.0",
13068
+ "hmac-drbg": "^1.0.1",
13069
+ inherits: "^2.0.4",
13070
+ "minimalistic-assert": "^1.0.1",
13071
+ "minimalistic-crypto-utils": "^1.0.1"
13072
+ };
13073
+ var require$$0 = {
13074
+ name: name,
13075
+ version: version$1,
13076
+ description: description,
13077
+ main: main,
13078
+ files: files,
13079
+ scripts: scripts,
13080
+ repository: repository,
13081
+ keywords: keywords,
13082
+ author: author,
13083
+ license: license,
13084
+ bugs: bugs,
13085
+ homepage: homepage,
13086
+ devDependencies: devDependencies,
13087
+ dependencies: dependencies
13017
13088
  };
13018
13089
 
13019
- function assert$g (cond, msg) {
13020
- if (!cond) throw new Error(msg)
13021
- }
13090
+ var utils$o = {};
13022
13091
 
13023
- function isUint8Array (name, value, length) {
13024
- assert$g(value instanceof Uint8Array, `Expected ${name} to be an Uint8Array`);
13092
+ var bn = {exports: {}};
13025
13093
 
13026
- if (length !== undefined) {
13027
- if (Array.isArray(length)) {
13028
- const numbers = length.join(', ');
13029
- const msg = `Expected ${name} to be an Uint8Array with length [${numbers}]`;
13030
- assert$g(length.includes(value.length), msg);
13031
- } else {
13032
- const msg = `Expected ${name} to be an Uint8Array with length ${length}`;
13033
- assert$g(value.length === length, msg);
13034
- }
13035
- }
13036
- }
13094
+ bn.exports;
13037
13095
 
13038
- function isCompressed (value) {
13039
- assert$g(toTypeString(value) === 'Boolean', 'Expected compressed to be a Boolean');
13040
- }
13096
+ (function (module) {
13097
+ (function (module, exports) {
13041
13098
 
13042
- function getAssertedOutput (output = (len) => new Uint8Array(len), length) {
13043
- if (typeof output === 'function') output = output(length);
13044
- isUint8Array('output', output, length);
13045
- return output
13046
- }
13099
+ // Utils
13100
+ function assert (val, msg) {
13101
+ if (!val) throw new Error(msg || 'Assertion failed');
13102
+ }
13047
13103
 
13048
- function toTypeString (value) {
13049
- return Object.prototype.toString.call(value).slice(8, -1)
13050
- }
13104
+ // Could use `inherits` module, but don't want to move from single file
13105
+ // architecture yet.
13106
+ function inherits (ctor, superCtor) {
13107
+ ctor.super_ = superCtor;
13108
+ var TempCtor = function () {};
13109
+ TempCtor.prototype = superCtor.prototype;
13110
+ ctor.prototype = new TempCtor();
13111
+ ctor.prototype.constructor = ctor;
13112
+ }
13051
13113
 
13052
- var lib = (secp256k1) => {
13053
- return {
13054
- contextRandomize (seed) {
13055
- assert$g(
13056
- seed === null || seed instanceof Uint8Array,
13057
- 'Expected seed to be an Uint8Array or null'
13058
- );
13059
- if (seed !== null) isUint8Array('seed', seed, 32);
13114
+ // BN
13060
13115
 
13061
- switch (secp256k1.contextRandomize(seed)) {
13062
- case 1:
13063
- throw new Error(errors.CONTEXT_RANDOMIZE_UNKNOW)
13064
- }
13065
- },
13116
+ function BN (number, base, endian) {
13117
+ if (BN.isBN(number)) {
13118
+ return number;
13119
+ }
13066
13120
 
13067
- privateKeyVerify (seckey) {
13068
- isUint8Array('private key', seckey, 32);
13121
+ this.negative = 0;
13122
+ this.words = null;
13123
+ this.length = 0;
13069
13124
 
13070
- return secp256k1.privateKeyVerify(seckey) === 0
13071
- },
13125
+ // Reduction context
13126
+ this.red = null;
13072
13127
 
13073
- privateKeyNegate (seckey) {
13074
- isUint8Array('private key', seckey, 32);
13128
+ if (number !== null) {
13129
+ if (base === 'le' || base === 'be') {
13130
+ endian = base;
13131
+ base = 10;
13132
+ }
13075
13133
 
13076
- switch (secp256k1.privateKeyNegate(seckey)) {
13077
- case 0:
13078
- return seckey
13079
- case 1:
13080
- throw new Error(errors.IMPOSSIBLE_CASE)
13081
- }
13082
- },
13134
+ this._init(number || 0, base || 10, endian || 'be');
13135
+ }
13136
+ }
13137
+ if (typeof module === 'object') {
13138
+ module.exports = BN;
13139
+ } else {
13140
+ exports.BN = BN;
13141
+ }
13083
13142
 
13084
- privateKeyTweakAdd (seckey, tweak) {
13085
- isUint8Array('private key', seckey, 32);
13086
- isUint8Array('tweak', tweak, 32);
13143
+ BN.BN = BN;
13144
+ BN.wordSize = 26;
13087
13145
 
13088
- switch (secp256k1.privateKeyTweakAdd(seckey, tweak)) {
13089
- case 0:
13090
- return seckey
13091
- case 1:
13092
- throw new Error(errors.TWEAK_ADD)
13093
- }
13094
- },
13146
+ var Buffer;
13147
+ try {
13148
+ if (typeof window !== 'undefined' && typeof window.Buffer !== 'undefined') {
13149
+ Buffer = window.Buffer;
13150
+ } else {
13151
+ Buffer = require$$3.Buffer;
13152
+ }
13153
+ } catch (e) {
13154
+ }
13095
13155
 
13096
- privateKeyTweakMul (seckey, tweak) {
13097
- isUint8Array('private key', seckey, 32);
13098
- isUint8Array('tweak', tweak, 32);
13156
+ BN.isBN = function isBN (num) {
13157
+ if (num instanceof BN) {
13158
+ return true;
13159
+ }
13099
13160
 
13100
- switch (secp256k1.privateKeyTweakMul(seckey, tweak)) {
13101
- case 0:
13102
- return seckey
13103
- case 1:
13104
- throw new Error(errors.TWEAK_MUL)
13105
- }
13106
- },
13161
+ return num !== null && typeof num === 'object' &&
13162
+ num.constructor.wordSize === BN.wordSize && Array.isArray(num.words);
13163
+ };
13107
13164
 
13108
- publicKeyVerify (pubkey) {
13109
- isUint8Array('public key', pubkey, [33, 65]);
13165
+ BN.max = function max (left, right) {
13166
+ if (left.cmp(right) > 0) return left;
13167
+ return right;
13168
+ };
13110
13169
 
13111
- return secp256k1.publicKeyVerify(pubkey) === 0
13112
- },
13170
+ BN.min = function min (left, right) {
13171
+ if (left.cmp(right) < 0) return left;
13172
+ return right;
13173
+ };
13113
13174
 
13114
- publicKeyCreate (seckey, compressed = true, output) {
13115
- isUint8Array('private key', seckey, 32);
13116
- isCompressed(compressed);
13117
- output = getAssertedOutput(output, compressed ? 33 : 65);
13175
+ BN.prototype._init = function init (number, base, endian) {
13176
+ if (typeof number === 'number') {
13177
+ return this._initNumber(number, base, endian);
13178
+ }
13118
13179
 
13119
- switch (secp256k1.publicKeyCreate(output, seckey)) {
13120
- case 0:
13121
- return output
13122
- case 1:
13123
- throw new Error(errors.SECKEY_INVALID)
13124
- case 2:
13125
- throw new Error(errors.PUBKEY_SERIALIZE)
13126
- }
13127
- },
13180
+ if (typeof number === 'object') {
13181
+ return this._initArray(number, base, endian);
13182
+ }
13128
13183
 
13129
- publicKeyConvert (pubkey, compressed = true, output) {
13130
- isUint8Array('public key', pubkey, [33, 65]);
13131
- isCompressed(compressed);
13132
- output = getAssertedOutput(output, compressed ? 33 : 65);
13133
-
13134
- switch (secp256k1.publicKeyConvert(output, pubkey)) {
13135
- case 0:
13136
- return output
13137
- case 1:
13138
- throw new Error(errors.PUBKEY_PARSE)
13139
- case 2:
13140
- throw new Error(errors.PUBKEY_SERIALIZE)
13141
- }
13142
- },
13143
-
13144
- publicKeyNegate (pubkey, compressed = true, output) {
13145
- isUint8Array('public key', pubkey, [33, 65]);
13146
- isCompressed(compressed);
13147
- output = getAssertedOutput(output, compressed ? 33 : 65);
13148
-
13149
- switch (secp256k1.publicKeyNegate(output, pubkey)) {
13150
- case 0:
13151
- return output
13152
- case 1:
13153
- throw new Error(errors.PUBKEY_PARSE)
13154
- case 2:
13155
- throw new Error(errors.IMPOSSIBLE_CASE)
13156
- case 3:
13157
- throw new Error(errors.PUBKEY_SERIALIZE)
13158
- }
13159
- },
13160
-
13161
- publicKeyCombine (pubkeys, compressed = true, output) {
13162
- assert$g(Array.isArray(pubkeys), 'Expected public keys to be an Array');
13163
- assert$g(pubkeys.length > 0, 'Expected public keys array will have more than zero items');
13164
- for (const pubkey of pubkeys) {
13165
- isUint8Array('public key', pubkey, [33, 65]);
13166
- }
13167
- isCompressed(compressed);
13168
- output = getAssertedOutput(output, compressed ? 33 : 65);
13169
-
13170
- switch (secp256k1.publicKeyCombine(output, pubkeys)) {
13171
- case 0:
13172
- return output
13173
- case 1:
13174
- throw new Error(errors.PUBKEY_PARSE)
13175
- case 2:
13176
- throw new Error(errors.PUBKEY_COMBINE)
13177
- case 3:
13178
- throw new Error(errors.PUBKEY_SERIALIZE)
13179
- }
13180
- },
13181
-
13182
- publicKeyTweakAdd (pubkey, tweak, compressed = true, output) {
13183
- isUint8Array('public key', pubkey, [33, 65]);
13184
- isUint8Array('tweak', tweak, 32);
13185
- isCompressed(compressed);
13186
- output = getAssertedOutput(output, compressed ? 33 : 65);
13187
-
13188
- switch (secp256k1.publicKeyTweakAdd(output, pubkey, tweak)) {
13189
- case 0:
13190
- return output
13191
- case 1:
13192
- throw new Error(errors.PUBKEY_PARSE)
13193
- case 2:
13194
- throw new Error(errors.TWEAK_ADD)
13195
- }
13196
- },
13197
-
13198
- publicKeyTweakMul (pubkey, tweak, compressed = true, output) {
13199
- isUint8Array('public key', pubkey, [33, 65]);
13200
- isUint8Array('tweak', tweak, 32);
13201
- isCompressed(compressed);
13202
- output = getAssertedOutput(output, compressed ? 33 : 65);
13203
-
13204
- switch (secp256k1.publicKeyTweakMul(output, pubkey, tweak)) {
13205
- case 0:
13206
- return output
13207
- case 1:
13208
- throw new Error(errors.PUBKEY_PARSE)
13209
- case 2:
13210
- throw new Error(errors.TWEAK_MUL)
13211
- }
13212
- },
13213
-
13214
- signatureNormalize (sig) {
13215
- isUint8Array('signature', sig, 64);
13216
-
13217
- switch (secp256k1.signatureNormalize(sig)) {
13218
- case 0:
13219
- return sig
13220
- case 1:
13221
- throw new Error(errors.SIG_PARSE)
13222
- }
13223
- },
13224
-
13225
- signatureExport (sig, output) {
13226
- isUint8Array('signature', sig, 64);
13227
- output = getAssertedOutput(output, 72);
13228
-
13229
- const obj = { output, outputlen: 72 };
13230
- switch (secp256k1.signatureExport(obj, sig)) {
13231
- case 0:
13232
- return output.slice(0, obj.outputlen)
13233
- case 1:
13234
- throw new Error(errors.SIG_PARSE)
13235
- case 2:
13236
- throw new Error(errors.IMPOSSIBLE_CASE)
13237
- }
13238
- },
13239
-
13240
- signatureImport (sig, output) {
13241
- isUint8Array('signature', sig);
13242
- output = getAssertedOutput(output, 64);
13243
-
13244
- switch (secp256k1.signatureImport(output, sig)) {
13245
- case 0:
13246
- return output
13247
- case 1:
13248
- throw new Error(errors.SIG_PARSE)
13249
- case 2:
13250
- throw new Error(errors.IMPOSSIBLE_CASE)
13251
- }
13252
- },
13253
-
13254
- ecdsaSign (msg32, seckey, options = {}, output) {
13255
- isUint8Array('message', msg32, 32);
13256
- isUint8Array('private key', seckey, 32);
13257
- assert$g(toTypeString(options) === 'Object', 'Expected options to be an Object');
13258
- if (options.data !== undefined) isUint8Array('options.data', options.data);
13259
- if (options.noncefn !== undefined) assert$g(toTypeString(options.noncefn) === 'Function', 'Expected options.noncefn to be a Function');
13260
- output = getAssertedOutput(output, 64);
13261
-
13262
- const obj = { signature: output, recid: null };
13263
- switch (secp256k1.ecdsaSign(obj, msg32, seckey, options.data, options.noncefn)) {
13264
- case 0:
13265
- return obj
13266
- case 1:
13267
- throw new Error(errors.SIGN)
13268
- case 2:
13269
- throw new Error(errors.IMPOSSIBLE_CASE)
13270
- }
13271
- },
13272
-
13273
- ecdsaVerify (sig, msg32, pubkey) {
13274
- isUint8Array('signature', sig, 64);
13275
- isUint8Array('message', msg32, 32);
13276
- isUint8Array('public key', pubkey, [33, 65]);
13277
-
13278
- switch (secp256k1.ecdsaVerify(sig, msg32, pubkey)) {
13279
- case 0:
13280
- return true
13281
- case 3:
13282
- return false
13283
- case 1:
13284
- throw new Error(errors.SIG_PARSE)
13285
- case 2:
13286
- throw new Error(errors.PUBKEY_PARSE)
13287
- }
13288
- },
13289
-
13290
- ecdsaRecover (sig, recid, msg32, compressed = true, output) {
13291
- isUint8Array('signature', sig, 64);
13292
- assert$g(
13293
- toTypeString(recid) === 'Number' &&
13294
- recid >= 0 &&
13295
- recid <= 3,
13296
- 'Expected recovery id to be a Number within interval [0, 3]'
13297
- );
13298
- isUint8Array('message', msg32, 32);
13299
- isCompressed(compressed);
13300
- output = getAssertedOutput(output, compressed ? 33 : 65);
13301
-
13302
- switch (secp256k1.ecdsaRecover(output, sig, recid, msg32)) {
13303
- case 0:
13304
- return output
13305
- case 1:
13306
- throw new Error(errors.SIG_PARSE)
13307
- case 2:
13308
- throw new Error(errors.RECOVER)
13309
- case 3:
13310
- throw new Error(errors.IMPOSSIBLE_CASE)
13311
- }
13312
- },
13313
-
13314
- ecdh (pubkey, seckey, options = {}, output) {
13315
- isUint8Array('public key', pubkey, [33, 65]);
13316
- isUint8Array('private key', seckey, 32);
13317
- assert$g(toTypeString(options) === 'Object', 'Expected options to be an Object');
13318
- if (options.data !== undefined) isUint8Array('options.data', options.data);
13319
- if (options.hashfn !== undefined) {
13320
- assert$g(toTypeString(options.hashfn) === 'Function', 'Expected options.hashfn to be a Function');
13321
- if (options.xbuf !== undefined) isUint8Array('options.xbuf', options.xbuf, 32);
13322
- if (options.ybuf !== undefined) isUint8Array('options.ybuf', options.ybuf, 32);
13323
- isUint8Array('output', output);
13324
- } else {
13325
- output = getAssertedOutput(output, 32);
13326
- }
13327
-
13328
- switch (secp256k1.ecdh(output, pubkey, seckey, options.data, options.hashfn, options.xbuf, options.ybuf)) {
13329
- case 0:
13330
- return output
13331
- case 1:
13332
- throw new Error(errors.PUBKEY_PARSE)
13333
- case 2:
13334
- throw new Error(errors.ECDH)
13335
- }
13336
- }
13337
- }
13338
- };
13339
-
13340
- var elliptic$2 = {};
13341
-
13342
- var name = "elliptic";
13343
- var version$1 = "6.5.4";
13344
- var description = "EC cryptography";
13345
- var main = "lib/elliptic.js";
13346
- var files = [
13347
- "lib"
13348
- ];
13349
- var scripts = {
13350
- lint: "eslint lib test",
13351
- "lint:fix": "npm run lint -- --fix",
13352
- unit: "istanbul test _mocha --reporter=spec test/index.js",
13353
- test: "npm run lint && npm run unit",
13354
- version: "grunt dist && git add dist/"
13355
- };
13356
- var repository = {
13357
- type: "git",
13358
- url: "git@github.com:indutny/elliptic"
13359
- };
13360
- var keywords = [
13361
- "EC",
13362
- "Elliptic",
13363
- "curve",
13364
- "Cryptography"
13365
- ];
13366
- var author = "Fedor Indutny <fedor@indutny.com>";
13367
- var license = "MIT";
13368
- var bugs = {
13369
- url: "https://github.com/indutny/elliptic/issues"
13370
- };
13371
- var homepage = "https://github.com/indutny/elliptic";
13372
- var devDependencies = {
13373
- brfs: "^2.0.2",
13374
- coveralls: "^3.1.0",
13375
- eslint: "^7.6.0",
13376
- grunt: "^1.2.1",
13377
- "grunt-browserify": "^5.3.0",
13378
- "grunt-cli": "^1.3.2",
13379
- "grunt-contrib-connect": "^3.0.0",
13380
- "grunt-contrib-copy": "^1.0.0",
13381
- "grunt-contrib-uglify": "^5.0.0",
13382
- "grunt-mocha-istanbul": "^5.0.2",
13383
- "grunt-saucelabs": "^9.0.1",
13384
- istanbul: "^0.4.5",
13385
- mocha: "^8.0.1"
13386
- };
13387
- var dependencies = {
13388
- "bn.js": "^4.11.9",
13389
- brorand: "^1.1.0",
13390
- "hash.js": "^1.0.0",
13391
- "hmac-drbg": "^1.0.1",
13392
- inherits: "^2.0.4",
13393
- "minimalistic-assert": "^1.0.1",
13394
- "minimalistic-crypto-utils": "^1.0.1"
13395
- };
13396
- var require$$0 = {
13397
- name: name,
13398
- version: version$1,
13399
- description: description,
13400
- main: main,
13401
- files: files,
13402
- scripts: scripts,
13403
- repository: repository,
13404
- keywords: keywords,
13405
- author: author,
13406
- license: license,
13407
- bugs: bugs,
13408
- homepage: homepage,
13409
- devDependencies: devDependencies,
13410
- dependencies: dependencies
13411
- };
13412
-
13413
- var utils$o = {};
13414
-
13415
- var bn = {exports: {}};
13416
-
13417
- bn.exports;
13418
-
13419
- (function (module) {
13420
- (function (module, exports) {
13421
-
13422
- // Utils
13423
- function assert (val, msg) {
13424
- if (!val) throw new Error(msg || 'Assertion failed');
13425
- }
13426
-
13427
- // Could use `inherits` module, but don't want to move from single file
13428
- // architecture yet.
13429
- function inherits (ctor, superCtor) {
13430
- ctor.super_ = superCtor;
13431
- var TempCtor = function () {};
13432
- TempCtor.prototype = superCtor.prototype;
13433
- ctor.prototype = new TempCtor();
13434
- ctor.prototype.constructor = ctor;
13435
- }
13436
-
13437
- // BN
13438
-
13439
- function BN (number, base, endian) {
13440
- if (BN.isBN(number)) {
13441
- return number;
13442
- }
13443
-
13444
- this.negative = 0;
13445
- this.words = null;
13446
- this.length = 0;
13447
-
13448
- // Reduction context
13449
- this.red = null;
13450
-
13451
- if (number !== null) {
13452
- if (base === 'le' || base === 'be') {
13453
- endian = base;
13454
- base = 10;
13455
- }
13456
-
13457
- this._init(number || 0, base || 10, endian || 'be');
13458
- }
13459
- }
13460
- if (typeof module === 'object') {
13461
- module.exports = BN;
13462
- } else {
13463
- exports.BN = BN;
13464
- }
13465
-
13466
- BN.BN = BN;
13467
- BN.wordSize = 26;
13468
-
13469
- var Buffer;
13470
- try {
13471
- if (typeof window !== 'undefined' && typeof window.Buffer !== 'undefined') {
13472
- Buffer = window.Buffer;
13473
- } else {
13474
- Buffer = require$$0$1.Buffer;
13475
- }
13476
- } catch (e) {
13477
- }
13478
-
13479
- BN.isBN = function isBN (num) {
13480
- if (num instanceof BN) {
13481
- return true;
13482
- }
13483
-
13484
- return num !== null && typeof num === 'object' &&
13485
- num.constructor.wordSize === BN.wordSize && Array.isArray(num.words);
13486
- };
13487
-
13488
- BN.max = function max (left, right) {
13489
- if (left.cmp(right) > 0) return left;
13490
- return right;
13491
- };
13492
-
13493
- BN.min = function min (left, right) {
13494
- if (left.cmp(right) < 0) return left;
13495
- return right;
13496
- };
13497
-
13498
- BN.prototype._init = function init (number, base, endian) {
13499
- if (typeof number === 'number') {
13500
- return this._initNumber(number, base, endian);
13501
- }
13502
-
13503
- if (typeof number === 'object') {
13504
- return this._initArray(number, base, endian);
13505
- }
13506
-
13507
- if (base === 'hex') {
13508
- base = 16;
13509
- }
13510
- assert(base === (base | 0) && base >= 2 && base <= 36);
13184
+ if (base === 'hex') {
13185
+ base = 16;
13186
+ }
13187
+ assert(base === (base | 0) && base >= 2 && base <= 36);
13511
13188
 
13512
13189
  number = number.toString().replace(/\s+/g, '');
13513
13190
  var start = 0;
@@ -16864,14 +16541,14 @@ bn.exports;
16864
16541
 
16865
16542
  var bnExports = bn.exports;
16866
16543
 
16867
- var minimalisticAssert = assert$f;
16544
+ var minimalisticAssert = assert$g;
16868
16545
 
16869
- function assert$f(val, msg) {
16546
+ function assert$g(val, msg) {
16870
16547
  if (!val)
16871
16548
  throw new Error(msg || 'Assertion failed');
16872
16549
  }
16873
16550
 
16874
- assert$f.equal = function assertEqual(l, r, msg) {
16551
+ assert$g.equal = function assertEqual(l, r, msg) {
16875
16552
  if (l != r)
16876
16553
  throw new Error(msg || ('Assertion failed: ' + l + ' != ' + r));
16877
16554
  };
@@ -17115,7 +16792,7 @@ if (typeof self === 'object') {
17115
16792
  } else {
17116
16793
  // Node.js or Web worker with no crypto support
17117
16794
  try {
17118
- var crypto$1 = require$$0$1;
16795
+ var crypto$1 = require$$3;
17119
16796
  if (typeof crypto$1.randomBytes !== 'function')
17120
16797
  throw new Error('Not supported');
17121
16798
 
@@ -17134,7 +16811,7 @@ var BN$8 = bnExports;
17134
16811
  var utils$m = utils$o;
17135
16812
  var getNAF = utils$m.getNAF;
17136
16813
  var getJSF = utils$m.getJSF;
17137
- var assert$e = utils$m.assert;
16814
+ var assert$f = utils$m.assert;
17138
16815
 
17139
16816
  function BaseCurve(type, conf) {
17140
16817
  this.type = type;
@@ -17180,7 +16857,7 @@ BaseCurve.prototype.validate = function validate() {
17180
16857
  };
17181
16858
 
17182
16859
  BaseCurve.prototype._fixedNafMul = function _fixedNafMul(p, k) {
17183
- assert$e(p.precomputed);
16860
+ assert$f(p.precomputed);
17184
16861
  var doubles = p._getDoubles();
17185
16862
 
17186
16863
  var naf = getNAF(k, 1, this._bitLength);
@@ -17237,7 +16914,7 @@ BaseCurve.prototype._wnafMul = function _wnafMul(p, k) {
17237
16914
  if (i < 0)
17238
16915
  break;
17239
16916
  var z = naf[i];
17240
- assert$e(z !== 0);
16917
+ assert$f(z !== 0);
17241
16918
  if (p.type === 'affine') {
17242
16919
  // J +- P
17243
16920
  if (z > 0)
@@ -17405,9 +17082,9 @@ BaseCurve.prototype.decodePoint = function decodePoint(bytes, enc) {
17405
17082
  if ((bytes[0] === 0x04 || bytes[0] === 0x06 || bytes[0] === 0x07) &&
17406
17083
  bytes.length - 1 === 2 * len) {
17407
17084
  if (bytes[0] === 0x06)
17408
- assert$e(bytes[bytes.length - 1] % 2 === 0);
17085
+ assert$f(bytes[bytes.length - 1] % 2 === 0);
17409
17086
  else if (bytes[0] === 0x07)
17410
- assert$e(bytes[bytes.length - 1] % 2 === 1);
17087
+ assert$f(bytes[bytes.length - 1] % 2 === 1);
17411
17088
 
17412
17089
  var res = this.point(bytes.slice(1, 1 + len),
17413
17090
  bytes.slice(1 + len, 1 + 2 * len));
@@ -17546,7 +17223,7 @@ var BN$7 = bnExports;
17546
17223
  var inherits$3 = inherits_browserExports;
17547
17224
  var Base$2 = base;
17548
17225
 
17549
- var assert$d = utils$l.assert;
17226
+ var assert$e = utils$l.assert;
17550
17227
 
17551
17228
  function ShortCurve(conf) {
17552
17229
  Base$2.call(this, 'short', conf);
@@ -17591,7 +17268,7 @@ ShortCurve.prototype._getEndomorphism = function _getEndomorphism(conf) {
17591
17268
  lambda = lambdas[0];
17592
17269
  } else {
17593
17270
  lambda = lambdas[1];
17594
- assert$d(this.g.mul(lambda).x.cmp(this.g.x.redMul(beta)) === 0);
17271
+ assert$e(this.g.mul(lambda).x.cmp(this.g.x.redMul(beta)) === 0);
17595
17272
  }
17596
17273
  }
17597
17274
 
@@ -18660,7 +18337,7 @@ var BN$5 = bnExports;
18660
18337
  var inherits$1 = inherits_browserExports;
18661
18338
  var Base = base;
18662
18339
 
18663
- var assert$c = utils$j.assert;
18340
+ var assert$d = utils$j.assert;
18664
18341
 
18665
18342
  function EdwardsCurve(conf) {
18666
18343
  // NOTE: Important as we are creating point in Base.call()
@@ -18677,7 +18354,7 @@ function EdwardsCurve(conf) {
18677
18354
  this.d = new BN$5(conf.d, 16).toRed(this.red);
18678
18355
  this.dd = this.d.redAdd(this.d);
18679
18356
 
18680
- assert$c(!this.twisted || this.c.fromRed().cmpn(1) === 0);
18357
+ assert$d(!this.twisted || this.c.fromRed().cmpn(1) === 0);
18681
18358
  this.oneC = (conf.c | 0) === 1;
18682
18359
  }
18683
18360
  inherits$1(EdwardsCurve, Base);
@@ -19105,7 +18782,7 @@ var hash$2 = {};
19105
18782
 
19106
18783
  var utils$i = {};
19107
18784
 
19108
- var assert$b = minimalisticAssert;
18785
+ var assert$c = minimalisticAssert;
19109
18786
  var inherits = inherits_browserExports;
19110
18787
 
19111
18788
  utils$i.inherits = inherits;
@@ -19226,7 +18903,7 @@ utils$i.zero8 = zero8;
19226
18903
 
19227
18904
  function join32(msg, start, end, endian) {
19228
18905
  var len = end - start;
19229
- assert$b(len % 4 === 0);
18906
+ assert$c(len % 4 === 0);
19230
18907
  var res = new Array(len / 4);
19231
18908
  for (var i = 0, k = start; i < res.length; i++, k += 4) {
19232
18909
  var w;
@@ -19385,7 +19062,7 @@ utils$i.shr64_lo = shr64_lo$1;
19385
19062
  var common$5 = {};
19386
19063
 
19387
19064
  var utils$h = utils$i;
19388
- var assert$a = minimalisticAssert;
19065
+ var assert$b = minimalisticAssert;
19389
19066
 
19390
19067
  function BlockHash$4() {
19391
19068
  this.pending = null;
@@ -19430,7 +19107,7 @@ BlockHash$4.prototype.update = function update(msg, enc) {
19430
19107
 
19431
19108
  BlockHash$4.prototype.digest = function digest(enc) {
19432
19109
  this.update(this._pad());
19433
- assert$a(this.pending === null);
19110
+ assert$b(this.pending === null);
19434
19111
 
19435
19112
  return this._digest(enc);
19436
19113
  };
@@ -19603,7 +19280,7 @@ SHA1.prototype._digest = function digest(enc) {
19603
19280
  var utils$e = utils$i;
19604
19281
  var common$2 = common$5;
19605
19282
  var shaCommon = common$4;
19606
- var assert$9 = minimalisticAssert;
19283
+ var assert$a = minimalisticAssert;
19607
19284
 
19608
19285
  var sum32$1 = utils$e.sum32;
19609
19286
  var sum32_4$1 = utils$e.sum32_4;
@@ -19673,7 +19350,7 @@ SHA256$1.prototype._update = function _update(msg, start) {
19673
19350
  var g = this.h[6];
19674
19351
  var h = this.h[7];
19675
19352
 
19676
- assert$9(this.k.length === W.length);
19353
+ assert$a(this.k.length === W.length);
19677
19354
  for (i = 0; i < W.length; i++) {
19678
19355
  var T1 = sum32_5(h, s1_256(e), ch32(e, f, g), this.k[i], W[i]);
19679
19356
  var T2 = sum32$1(s0_256(a), maj32(a, b, c));
@@ -19734,7 +19411,7 @@ SHA224.prototype._digest = function digest(enc) {
19734
19411
 
19735
19412
  var utils$c = utils$i;
19736
19413
  var common$1 = common$5;
19737
- var assert$8 = minimalisticAssert;
19414
+ var assert$9 = minimalisticAssert;
19738
19415
 
19739
19416
  var rotr64_hi = utils$c.rotr64_hi;
19740
19417
  var rotr64_lo = utils$c.rotr64_lo;
@@ -19869,7 +19546,7 @@ SHA512$1.prototype._update = function _update(msg, start) {
19869
19546
  var hh = this.h[14];
19870
19547
  var hl = this.h[15];
19871
19548
 
19872
- assert$8(this.k.length === W.length);
19549
+ assert$9(this.k.length === W.length);
19873
19550
  for (var i = 0; i < W.length; i += 2) {
19874
19551
  var c0_hi = hh;
19875
19552
  var c0_lo = hl;
@@ -20249,7 +19926,7 @@ var sh = [
20249
19926
  ];
20250
19927
 
20251
19928
  var utils$9 = utils$i;
20252
- var assert$7 = minimalisticAssert;
19929
+ var assert$8 = minimalisticAssert;
20253
19930
 
20254
19931
  function Hmac(hash, key, enc) {
20255
19932
  if (!(this instanceof Hmac))
@@ -20268,7 +19945,7 @@ Hmac.prototype._init = function init(key) {
20268
19945
  // Shorten key, if needed
20269
19946
  if (key.length > this.blockSize)
20270
19947
  key = new this.Hash().update(key).digest();
20271
- assert$7(key.length <= this.blockSize);
19948
+ assert$8(key.length <= this.blockSize);
20272
19949
 
20273
19950
  // Add padding to key
20274
19951
  for (var i = key.length; i < this.blockSize; i++)
@@ -21311,7 +20988,7 @@ function requireSecp256k1 () {
21311
20988
 
21312
20989
  var hash$1 = hash$2;
21313
20990
  var utils$8 = utils$n;
21314
- var assert$6 = minimalisticAssert;
20991
+ var assert$7 = minimalisticAssert;
21315
20992
 
21316
20993
  function HmacDRBG$1(options) {
21317
20994
  if (!(this instanceof HmacDRBG$1))
@@ -21330,7 +21007,7 @@ function HmacDRBG$1(options) {
21330
21007
  var entropy = utils$8.toArray(options.entropy, options.entropyEnc || 'hex');
21331
21008
  var nonce = utils$8.toArray(options.nonce, options.nonceEnc || 'hex');
21332
21009
  var pers = utils$8.toArray(options.pers, options.persEnc || 'hex');
21333
- assert$6(entropy.length >= (this.minEntropy / 8),
21010
+ assert$7(entropy.length >= (this.minEntropy / 8),
21334
21011
  'Not enough entropy. Minimum is: ' + this.minEntropy + ' bits');
21335
21012
  this._init(entropy, nonce, pers);
21336
21013
  }
@@ -21385,7 +21062,7 @@ HmacDRBG$1.prototype.reseed = function reseed(entropy, entropyEnc, add, addEnc)
21385
21062
  entropy = utils$8.toArray(entropy, entropyEnc);
21386
21063
  add = utils$8.toArray(add, addEnc);
21387
21064
 
21388
- assert$6(entropy.length >= (this.minEntropy / 8),
21065
+ assert$7(entropy.length >= (this.minEntropy / 8),
21389
21066
  'Not enough entropy. Minimum is: ' + this.minEntropy + ' bits');
21390
21067
 
21391
21068
  this._update(entropy.concat(add || []));
@@ -21423,7 +21100,7 @@ HmacDRBG$1.prototype.generate = function generate(len, enc, add, addEnc) {
21423
21100
 
21424
21101
  var BN$4 = bnExports;
21425
21102
  var utils$7 = utils$o;
21426
- var assert$5 = utils$7.assert;
21103
+ var assert$6 = utils$7.assert;
21427
21104
 
21428
21105
  function KeyPair$3(ec, options) {
21429
21106
  this.ec = ec;
@@ -21508,10 +21185,10 @@ KeyPair$3.prototype._importPublic = function _importPublic(key, enc) {
21508
21185
  // Weierstrass/Edwards points on the other hand have both `x` and
21509
21186
  // `y` coordinates.
21510
21187
  if (this.ec.curve.type === 'mont') {
21511
- assert$5(key.x, 'Need x coordinate');
21188
+ assert$6(key.x, 'Need x coordinate');
21512
21189
  } else if (this.ec.curve.type === 'short' ||
21513
21190
  this.ec.curve.type === 'edwards') {
21514
- assert$5(key.x && key.y, 'Need both x and y coordinate');
21191
+ assert$6(key.x && key.y, 'Need both x and y coordinate');
21515
21192
  }
21516
21193
  this.pub = this.ec.curve.point(key.x, key.y);
21517
21194
  return;
@@ -21522,7 +21199,7 @@ KeyPair$3.prototype._importPublic = function _importPublic(key, enc) {
21522
21199
  // ECDH
21523
21200
  KeyPair$3.prototype.derive = function derive(pub) {
21524
21201
  if(!pub.validate()) {
21525
- assert$5(pub.validate(), 'public point not validated');
21202
+ assert$6(pub.validate(), 'public point not validated');
21526
21203
  }
21527
21204
  return pub.mul(this.priv).getX();
21528
21205
  };
@@ -21544,7 +21221,7 @@ KeyPair$3.prototype.inspect = function inspect() {
21544
21221
  var BN$3 = bnExports;
21545
21222
 
21546
21223
  var utils$6 = utils$o;
21547
- var assert$4 = utils$6.assert;
21224
+ var assert$5 = utils$6.assert;
21548
21225
 
21549
21226
  function Signature$3(options, enc) {
21550
21227
  if (options instanceof Signature$3)
@@ -21553,7 +21230,7 @@ function Signature$3(options, enc) {
21553
21230
  if (this._importDER(options, enc))
21554
21231
  return;
21555
21232
 
21556
- assert$4(options.r && options.s, 'Signature without r or s');
21233
+ assert$5(options.r && options.s, 'Signature without r or s');
21557
21234
  this.r = new BN$3(options.r, 16);
21558
21235
  this.s = new BN$3(options.s, 16);
21559
21236
  if (options.recoveryParam === undefined)
@@ -21711,7 +21388,7 @@ var HmacDRBG = hmacDrbg;
21711
21388
  var utils$5 = utils$o;
21712
21389
  var curves$1 = curves$2;
21713
21390
  var rand = brorandExports;
21714
- var assert$3 = utils$5.assert;
21391
+ var assert$4 = utils$5.assert;
21715
21392
 
21716
21393
  var KeyPair$2 = key$1;
21717
21394
  var Signature$2 = signature$1;
@@ -21722,7 +21399,7 @@ function EC$1(options) {
21722
21399
 
21723
21400
  // Shortcut `elliptic.ec(curve-name)`
21724
21401
  if (typeof options === 'string') {
21725
- assert$3(Object.prototype.hasOwnProperty.call(curves$1, options),
21402
+ assert$4(Object.prototype.hasOwnProperty.call(curves$1, options),
21726
21403
  'Unknown curve ' + options);
21727
21404
 
21728
21405
  options = curves$1[options];
@@ -21900,7 +21577,7 @@ EC$1.prototype.verify = function verify(msg, signature, key, enc) {
21900
21577
  };
21901
21578
 
21902
21579
  EC$1.prototype.recoverPubKey = function(msg, signature, j, enc) {
21903
- assert$3((3 & j) === j, 'The recovery param is more than two bits');
21580
+ assert$4((3 & j) === j, 'The recovery param is more than two bits');
21904
21581
  signature = new Signature$2(signature, enc);
21905
21582
 
21906
21583
  var n = this.n;
@@ -21949,7 +21626,7 @@ EC$1.prototype.getKeyRecoveryParam = function(e, signature, Q, enc) {
21949
21626
  };
21950
21627
 
21951
21628
  var utils$4 = utils$o;
21952
- var assert$2 = utils$4.assert;
21629
+ var assert$3 = utils$4.assert;
21953
21630
  var parseBytes$2 = utils$4.parseBytes;
21954
21631
  var cachedProperty$1 = utils$4.cachedProperty;
21955
21632
 
@@ -22023,7 +21700,7 @@ cachedProperty$1(KeyPair$1, 'messagePrefix', function messagePrefix() {
22023
21700
  });
22024
21701
 
22025
21702
  KeyPair$1.prototype.sign = function sign(message) {
22026
- assert$2(this._secret, 'KeyPair can only verify');
21703
+ assert$3(this._secret, 'KeyPair can only verify');
22027
21704
  return this.eddsa.sign(message, this);
22028
21705
  };
22029
21706
 
@@ -22032,7 +21709,7 @@ KeyPair$1.prototype.verify = function verify(message, sig) {
22032
21709
  };
22033
21710
 
22034
21711
  KeyPair$1.prototype.getSecret = function getSecret(enc) {
22035
- assert$2(this._secret, 'KeyPair is public only');
21712
+ assert$3(this._secret, 'KeyPair is public only');
22036
21713
  return utils$4.encode(this.secret(), enc);
22037
21714
  };
22038
21715
 
@@ -22044,7 +21721,7 @@ var key = KeyPair$1;
22044
21721
 
22045
21722
  var BN$1 = bnExports;
22046
21723
  var utils$3 = utils$o;
22047
- var assert$1 = utils$3.assert;
21724
+ var assert$2 = utils$3.assert;
22048
21725
  var cachedProperty = utils$3.cachedProperty;
22049
21726
  var parseBytes$1 = utils$3.parseBytes;
22050
21727
 
@@ -22069,7 +21746,7 @@ function Signature$1(eddsa, sig) {
22069
21746
  };
22070
21747
  }
22071
21748
 
22072
- assert$1(sig.R && sig.S, 'Signature without R or S');
21749
+ assert$2(sig.R && sig.S, 'Signature without R or S');
22073
21750
 
22074
21751
  if (eddsa.isPoint(sig.R))
22075
21752
  this._R = sig.R;
@@ -22109,13 +21786,13 @@ var signature = Signature$1;
22109
21786
  var hash = hash$2;
22110
21787
  var curves = curves$2;
22111
21788
  var utils$2 = utils$o;
22112
- var assert = utils$2.assert;
21789
+ var assert$1 = utils$2.assert;
22113
21790
  var parseBytes = utils$2.parseBytes;
22114
21791
  var KeyPair = key;
22115
21792
  var Signature = signature;
22116
21793
 
22117
21794
  function EDDSA(curve) {
22118
- assert(curve === 'ed25519', 'only tested with ed25519 so far');
21795
+ assert$1(curve === 'ed25519', 'only tested with ed25519 so far');
22119
21796
 
22120
21797
  if (!(this instanceof EDDSA))
22121
21798
  return new EDDSA(curve);
@@ -22569,75 +22246,412 @@ var elliptic$1 = {
22569
22246
  return 0
22570
22247
  },
22571
22248
 
22572
- ecdsaVerify (sig, msg32, pubkey) {
22573
- const sigObj = { r: sig.subarray(0, 32), s: sig.subarray(32, 64) };
22249
+ ecdsaVerify (sig, msg32, pubkey) {
22250
+ const sigObj = { r: sig.subarray(0, 32), s: sig.subarray(32, 64) };
22251
+
22252
+ const sigr = new BN(sigObj.r);
22253
+ const sigs = new BN(sigObj.s);
22254
+ if (sigr.cmp(ecparams.n) >= 0 || sigs.cmp(ecparams.n) >= 0) return 1
22255
+ if (sigs.cmp(ec.nh) === 1 || sigr.isZero() || sigs.isZero()) return 3
22256
+
22257
+ const pair = loadPublicKey(pubkey);
22258
+ if (pair === null) return 2
22259
+
22260
+ const point = pair.getPublic();
22261
+ const isValid = ec.verify(msg32, sigObj, point);
22262
+ return isValid ? 0 : 3
22263
+ },
22264
+
22265
+ ecdsaRecover (output, sig, recid, msg32) {
22266
+ const sigObj = { r: sig.slice(0, 32), s: sig.slice(32, 64) };
22267
+
22268
+ const sigr = new BN(sigObj.r);
22269
+ const sigs = new BN(sigObj.s);
22270
+ if (sigr.cmp(ecparams.n) >= 0 || sigs.cmp(ecparams.n) >= 0) return 1
22271
+
22272
+ if (sigr.isZero() || sigs.isZero()) return 2
22273
+
22274
+ // Can throw `throw new Error('Unable to find sencond key candinate');`
22275
+ let point;
22276
+ try {
22277
+ point = ec.recoverPubKey(msg32, sigObj, recid);
22278
+ } catch (err) {
22279
+ return 2
22280
+ }
22281
+
22282
+ savePublicKey(output, point);
22283
+
22284
+ return 0
22285
+ },
22286
+
22287
+ ecdh (output, pubkey, seckey, data, hashfn, xbuf, ybuf) {
22288
+ const pair = loadPublicKey(pubkey);
22289
+ if (pair === null) return 1
22290
+
22291
+ const scalar = new BN(seckey);
22292
+ if (scalar.cmp(ecparams.n) >= 0 || scalar.isZero()) return 2
22293
+
22294
+ const point = pair.getPublic().mul(scalar);
22295
+
22296
+ if (hashfn === undefined) {
22297
+ const data = point.encode(null, true);
22298
+ const sha256 = ec.hash().update(data).digest();
22299
+ for (let i = 0; i < 32; ++i) output[i] = sha256[i];
22300
+ } else {
22301
+ if (!xbuf) xbuf = new Uint8Array(32);
22302
+ const x = point.getX().toArray('be', 32);
22303
+ for (let i = 0; i < 32; ++i) xbuf[i] = x[i];
22304
+
22305
+ if (!ybuf) ybuf = new Uint8Array(32);
22306
+ const y = point.getY().toArray('be', 32);
22307
+ for (let i = 0; i < 32; ++i) ybuf[i] = y[i];
22308
+
22309
+ const hash = hashfn(xbuf, ybuf, data);
22310
+
22311
+ const isValid = hash instanceof Uint8Array && hash.length === output.length;
22312
+ if (!isValid) return 2
22313
+
22314
+ output.set(hash);
22315
+ }
22316
+
22317
+ return 0
22318
+ }
22319
+ };
22320
+
22321
+ const errors = {
22322
+ IMPOSSIBLE_CASE: 'Impossible case. Please create issue.',
22323
+ TWEAK_ADD:
22324
+ 'The tweak was out of range or the resulted private key is invalid',
22325
+ TWEAK_MUL: 'The tweak was out of range or equal to zero',
22326
+ CONTEXT_RANDOMIZE_UNKNOW: 'Unknow error on context randomization',
22327
+ SECKEY_INVALID: 'Private Key is invalid',
22328
+ PUBKEY_PARSE: 'Public Key could not be parsed',
22329
+ PUBKEY_SERIALIZE: 'Public Key serialization error',
22330
+ PUBKEY_COMBINE: 'The sum of the public keys is not valid',
22331
+ SIG_PARSE: 'Signature could not be parsed',
22332
+ SIGN: 'The nonce generation function failed, or the private key was invalid',
22333
+ RECOVER: 'Public key could not be recover',
22334
+ ECDH: 'Scalar was invalid (zero or overflow)'
22335
+ };
22336
+
22337
+ function assert (cond, msg) {
22338
+ if (!cond) throw new Error(msg)
22339
+ }
22340
+
22341
+ function isUint8Array (name, value, length) {
22342
+ assert(value instanceof Uint8Array, `Expected ${name} to be an Uint8Array`);
22343
+
22344
+ if (length !== undefined) {
22345
+ if (Array.isArray(length)) {
22346
+ const numbers = length.join(', ');
22347
+ const msg = `Expected ${name} to be an Uint8Array with length [${numbers}]`;
22348
+ assert(length.includes(value.length), msg);
22349
+ } else {
22350
+ const msg = `Expected ${name} to be an Uint8Array with length ${length}`;
22351
+ assert(value.length === length, msg);
22352
+ }
22353
+ }
22354
+ }
22355
+
22356
+ function isCompressed (value) {
22357
+ assert(toTypeString(value) === 'Boolean', 'Expected compressed to be a Boolean');
22358
+ }
22359
+
22360
+ function getAssertedOutput (output = (len) => new Uint8Array(len), length) {
22361
+ if (typeof output === 'function') output = output(length);
22362
+ isUint8Array('output', output, length);
22363
+ return output
22364
+ }
22365
+
22366
+ function toTypeString (value) {
22367
+ return Object.prototype.toString.call(value).slice(8, -1)
22368
+ }
22369
+
22370
+ var lib = (secp256k1) => {
22371
+ return {
22372
+ contextRandomize (seed) {
22373
+ assert(
22374
+ seed === null || seed instanceof Uint8Array,
22375
+ 'Expected seed to be an Uint8Array or null'
22376
+ );
22377
+ if (seed !== null) isUint8Array('seed', seed, 32);
22378
+
22379
+ switch (secp256k1.contextRandomize(seed)) {
22380
+ case 1:
22381
+ throw new Error(errors.CONTEXT_RANDOMIZE_UNKNOW)
22382
+ }
22383
+ },
22384
+
22385
+ privateKeyVerify (seckey) {
22386
+ isUint8Array('private key', seckey, 32);
22387
+
22388
+ return secp256k1.privateKeyVerify(seckey) === 0
22389
+ },
22390
+
22391
+ privateKeyNegate (seckey) {
22392
+ isUint8Array('private key', seckey, 32);
22393
+
22394
+ switch (secp256k1.privateKeyNegate(seckey)) {
22395
+ case 0:
22396
+ return seckey
22397
+ case 1:
22398
+ throw new Error(errors.IMPOSSIBLE_CASE)
22399
+ }
22400
+ },
22401
+
22402
+ privateKeyTweakAdd (seckey, tweak) {
22403
+ isUint8Array('private key', seckey, 32);
22404
+ isUint8Array('tweak', tweak, 32);
22405
+
22406
+ switch (secp256k1.privateKeyTweakAdd(seckey, tweak)) {
22407
+ case 0:
22408
+ return seckey
22409
+ case 1:
22410
+ throw new Error(errors.TWEAK_ADD)
22411
+ }
22412
+ },
22413
+
22414
+ privateKeyTweakMul (seckey, tweak) {
22415
+ isUint8Array('private key', seckey, 32);
22416
+ isUint8Array('tweak', tweak, 32);
22417
+
22418
+ switch (secp256k1.privateKeyTweakMul(seckey, tweak)) {
22419
+ case 0:
22420
+ return seckey
22421
+ case 1:
22422
+ throw new Error(errors.TWEAK_MUL)
22423
+ }
22424
+ },
22425
+
22426
+ publicKeyVerify (pubkey) {
22427
+ isUint8Array('public key', pubkey, [33, 65]);
22428
+
22429
+ return secp256k1.publicKeyVerify(pubkey) === 0
22430
+ },
22431
+
22432
+ publicKeyCreate (seckey, compressed = true, output) {
22433
+ isUint8Array('private key', seckey, 32);
22434
+ isCompressed(compressed);
22435
+ output = getAssertedOutput(output, compressed ? 33 : 65);
22436
+
22437
+ switch (secp256k1.publicKeyCreate(output, seckey)) {
22438
+ case 0:
22439
+ return output
22440
+ case 1:
22441
+ throw new Error(errors.SECKEY_INVALID)
22442
+ case 2:
22443
+ throw new Error(errors.PUBKEY_SERIALIZE)
22444
+ }
22445
+ },
22446
+
22447
+ publicKeyConvert (pubkey, compressed = true, output) {
22448
+ isUint8Array('public key', pubkey, [33, 65]);
22449
+ isCompressed(compressed);
22450
+ output = getAssertedOutput(output, compressed ? 33 : 65);
22451
+
22452
+ switch (secp256k1.publicKeyConvert(output, pubkey)) {
22453
+ case 0:
22454
+ return output
22455
+ case 1:
22456
+ throw new Error(errors.PUBKEY_PARSE)
22457
+ case 2:
22458
+ throw new Error(errors.PUBKEY_SERIALIZE)
22459
+ }
22460
+ },
22461
+
22462
+ publicKeyNegate (pubkey, compressed = true, output) {
22463
+ isUint8Array('public key', pubkey, [33, 65]);
22464
+ isCompressed(compressed);
22465
+ output = getAssertedOutput(output, compressed ? 33 : 65);
22466
+
22467
+ switch (secp256k1.publicKeyNegate(output, pubkey)) {
22468
+ case 0:
22469
+ return output
22470
+ case 1:
22471
+ throw new Error(errors.PUBKEY_PARSE)
22472
+ case 2:
22473
+ throw new Error(errors.IMPOSSIBLE_CASE)
22474
+ case 3:
22475
+ throw new Error(errors.PUBKEY_SERIALIZE)
22476
+ }
22477
+ },
22478
+
22479
+ publicKeyCombine (pubkeys, compressed = true, output) {
22480
+ assert(Array.isArray(pubkeys), 'Expected public keys to be an Array');
22481
+ assert(pubkeys.length > 0, 'Expected public keys array will have more than zero items');
22482
+ for (const pubkey of pubkeys) {
22483
+ isUint8Array('public key', pubkey, [33, 65]);
22484
+ }
22485
+ isCompressed(compressed);
22486
+ output = getAssertedOutput(output, compressed ? 33 : 65);
22487
+
22488
+ switch (secp256k1.publicKeyCombine(output, pubkeys)) {
22489
+ case 0:
22490
+ return output
22491
+ case 1:
22492
+ throw new Error(errors.PUBKEY_PARSE)
22493
+ case 2:
22494
+ throw new Error(errors.PUBKEY_COMBINE)
22495
+ case 3:
22496
+ throw new Error(errors.PUBKEY_SERIALIZE)
22497
+ }
22498
+ },
22499
+
22500
+ publicKeyTweakAdd (pubkey, tweak, compressed = true, output) {
22501
+ isUint8Array('public key', pubkey, [33, 65]);
22502
+ isUint8Array('tweak', tweak, 32);
22503
+ isCompressed(compressed);
22504
+ output = getAssertedOutput(output, compressed ? 33 : 65);
22574
22505
 
22575
- const sigr = new BN(sigObj.r);
22576
- const sigs = new BN(sigObj.s);
22577
- if (sigr.cmp(ecparams.n) >= 0 || sigs.cmp(ecparams.n) >= 0) return 1
22578
- if (sigs.cmp(ec.nh) === 1 || sigr.isZero() || sigs.isZero()) return 3
22506
+ switch (secp256k1.publicKeyTweakAdd(output, pubkey, tweak)) {
22507
+ case 0:
22508
+ return output
22509
+ case 1:
22510
+ throw new Error(errors.PUBKEY_PARSE)
22511
+ case 2:
22512
+ throw new Error(errors.TWEAK_ADD)
22513
+ }
22514
+ },
22579
22515
 
22580
- const pair = loadPublicKey(pubkey);
22581
- if (pair === null) return 2
22516
+ publicKeyTweakMul (pubkey, tweak, compressed = true, output) {
22517
+ isUint8Array('public key', pubkey, [33, 65]);
22518
+ isUint8Array('tweak', tweak, 32);
22519
+ isCompressed(compressed);
22520
+ output = getAssertedOutput(output, compressed ? 33 : 65);
22582
22521
 
22583
- const point = pair.getPublic();
22584
- const isValid = ec.verify(msg32, sigObj, point);
22585
- return isValid ? 0 : 3
22586
- },
22522
+ switch (secp256k1.publicKeyTweakMul(output, pubkey, tweak)) {
22523
+ case 0:
22524
+ return output
22525
+ case 1:
22526
+ throw new Error(errors.PUBKEY_PARSE)
22527
+ case 2:
22528
+ throw new Error(errors.TWEAK_MUL)
22529
+ }
22530
+ },
22587
22531
 
22588
- ecdsaRecover (output, sig, recid, msg32) {
22589
- const sigObj = { r: sig.slice(0, 32), s: sig.slice(32, 64) };
22532
+ signatureNormalize (sig) {
22533
+ isUint8Array('signature', sig, 64);
22590
22534
 
22591
- const sigr = new BN(sigObj.r);
22592
- const sigs = new BN(sigObj.s);
22593
- if (sigr.cmp(ecparams.n) >= 0 || sigs.cmp(ecparams.n) >= 0) return 1
22535
+ switch (secp256k1.signatureNormalize(sig)) {
22536
+ case 0:
22537
+ return sig
22538
+ case 1:
22539
+ throw new Error(errors.SIG_PARSE)
22540
+ }
22541
+ },
22594
22542
 
22595
- if (sigr.isZero() || sigs.isZero()) return 2
22543
+ signatureExport (sig, output) {
22544
+ isUint8Array('signature', sig, 64);
22545
+ output = getAssertedOutput(output, 72);
22596
22546
 
22597
- // Can throw `throw new Error('Unable to find sencond key candinate');`
22598
- let point;
22599
- try {
22600
- point = ec.recoverPubKey(msg32, sigObj, recid);
22601
- } catch (err) {
22602
- return 2
22603
- }
22547
+ const obj = { output, outputlen: 72 };
22548
+ switch (secp256k1.signatureExport(obj, sig)) {
22549
+ case 0:
22550
+ return output.slice(0, obj.outputlen)
22551
+ case 1:
22552
+ throw new Error(errors.SIG_PARSE)
22553
+ case 2:
22554
+ throw new Error(errors.IMPOSSIBLE_CASE)
22555
+ }
22556
+ },
22604
22557
 
22605
- savePublicKey(output, point);
22558
+ signatureImport (sig, output) {
22559
+ isUint8Array('signature', sig);
22560
+ output = getAssertedOutput(output, 64);
22606
22561
 
22607
- return 0
22608
- },
22562
+ switch (secp256k1.signatureImport(output, sig)) {
22563
+ case 0:
22564
+ return output
22565
+ case 1:
22566
+ throw new Error(errors.SIG_PARSE)
22567
+ case 2:
22568
+ throw new Error(errors.IMPOSSIBLE_CASE)
22569
+ }
22570
+ },
22609
22571
 
22610
- ecdh (output, pubkey, seckey, data, hashfn, xbuf, ybuf) {
22611
- const pair = loadPublicKey(pubkey);
22612
- if (pair === null) return 1
22572
+ ecdsaSign (msg32, seckey, options = {}, output) {
22573
+ isUint8Array('message', msg32, 32);
22574
+ isUint8Array('private key', seckey, 32);
22575
+ assert(toTypeString(options) === 'Object', 'Expected options to be an Object');
22576
+ if (options.data !== undefined) isUint8Array('options.data', options.data);
22577
+ if (options.noncefn !== undefined) assert(toTypeString(options.noncefn) === 'Function', 'Expected options.noncefn to be a Function');
22578
+ output = getAssertedOutput(output, 64);
22613
22579
 
22614
- const scalar = new BN(seckey);
22615
- if (scalar.cmp(ecparams.n) >= 0 || scalar.isZero()) return 2
22580
+ const obj = { signature: output, recid: null };
22581
+ switch (secp256k1.ecdsaSign(obj, msg32, seckey, options.data, options.noncefn)) {
22582
+ case 0:
22583
+ return obj
22584
+ case 1:
22585
+ throw new Error(errors.SIGN)
22586
+ case 2:
22587
+ throw new Error(errors.IMPOSSIBLE_CASE)
22588
+ }
22589
+ },
22616
22590
 
22617
- const point = pair.getPublic().mul(scalar);
22591
+ ecdsaVerify (sig, msg32, pubkey) {
22592
+ isUint8Array('signature', sig, 64);
22593
+ isUint8Array('message', msg32, 32);
22594
+ isUint8Array('public key', pubkey, [33, 65]);
22618
22595
 
22619
- if (hashfn === undefined) {
22620
- const data = point.encode(null, true);
22621
- const sha256 = ec.hash().update(data).digest();
22622
- for (let i = 0; i < 32; ++i) output[i] = sha256[i];
22623
- } else {
22624
- if (!xbuf) xbuf = new Uint8Array(32);
22625
- const x = point.getX().toArray('be', 32);
22626
- for (let i = 0; i < 32; ++i) xbuf[i] = x[i];
22596
+ switch (secp256k1.ecdsaVerify(sig, msg32, pubkey)) {
22597
+ case 0:
22598
+ return true
22599
+ case 3:
22600
+ return false
22601
+ case 1:
22602
+ throw new Error(errors.SIG_PARSE)
22603
+ case 2:
22604
+ throw new Error(errors.PUBKEY_PARSE)
22605
+ }
22606
+ },
22627
22607
 
22628
- if (!ybuf) ybuf = new Uint8Array(32);
22629
- const y = point.getY().toArray('be', 32);
22630
- for (let i = 0; i < 32; ++i) ybuf[i] = y[i];
22608
+ ecdsaRecover (sig, recid, msg32, compressed = true, output) {
22609
+ isUint8Array('signature', sig, 64);
22610
+ assert(
22611
+ toTypeString(recid) === 'Number' &&
22612
+ recid >= 0 &&
22613
+ recid <= 3,
22614
+ 'Expected recovery id to be a Number within interval [0, 3]'
22615
+ );
22616
+ isUint8Array('message', msg32, 32);
22617
+ isCompressed(compressed);
22618
+ output = getAssertedOutput(output, compressed ? 33 : 65);
22631
22619
 
22632
- const hash = hashfn(xbuf, ybuf, data);
22620
+ switch (secp256k1.ecdsaRecover(output, sig, recid, msg32)) {
22621
+ case 0:
22622
+ return output
22623
+ case 1:
22624
+ throw new Error(errors.SIG_PARSE)
22625
+ case 2:
22626
+ throw new Error(errors.RECOVER)
22627
+ case 3:
22628
+ throw new Error(errors.IMPOSSIBLE_CASE)
22629
+ }
22630
+ },
22633
22631
 
22634
- const isValid = hash instanceof Uint8Array && hash.length === output.length;
22635
- if (!isValid) return 2
22632
+ ecdh (pubkey, seckey, options = {}, output) {
22633
+ isUint8Array('public key', pubkey, [33, 65]);
22634
+ isUint8Array('private key', seckey, 32);
22635
+ assert(toTypeString(options) === 'Object', 'Expected options to be an Object');
22636
+ if (options.data !== undefined) isUint8Array('options.data', options.data);
22637
+ if (options.hashfn !== undefined) {
22638
+ assert(toTypeString(options.hashfn) === 'Function', 'Expected options.hashfn to be a Function');
22639
+ if (options.xbuf !== undefined) isUint8Array('options.xbuf', options.xbuf, 32);
22640
+ if (options.ybuf !== undefined) isUint8Array('options.ybuf', options.ybuf, 32);
22641
+ isUint8Array('output', output);
22642
+ } else {
22643
+ output = getAssertedOutput(output, 32);
22644
+ }
22636
22645
 
22637
- output.set(hash);
22646
+ switch (secp256k1.ecdh(output, pubkey, seckey, options.data, options.hashfn, options.xbuf, options.ybuf)) {
22647
+ case 0:
22648
+ return output
22649
+ case 1:
22650
+ throw new Error(errors.PUBKEY_PARSE)
22651
+ case 2:
22652
+ throw new Error(errors.ECDH)
22653
+ }
22638
22654
  }
22639
-
22640
- return 0
22641
22655
  }
22642
22656
  };
22643
22657
 
@@ -24118,7 +24132,7 @@ b||"returnDetailedScanResult"in b)?(m=b.scanRegion,c=b.qrEngine,d=b.canvas,f=b.d
24118
24132
  [d,k]=e._drawToCanvas(p,m,d,f);let q;if(c instanceof Worker){let g=c;b||e._postWorkerMessageSync(g,"inversionMode","both");q=await new Promise((l,v)=>{let w,u,r,y=-1;u=t=>{t.data.id===y&&(g.removeEventListener("message",u),g.removeEventListener("error",r),clearTimeout(w),null!==t.data.data?l({data:t.data.data,cornerPoints:e._convertPoints(t.data.cornerPoints,m)}):v(e.NO_QR_CODE_FOUND));};r=t=>{g.removeEventListener("message",u);g.removeEventListener("error",r);clearTimeout(w);v("Scanner error: "+(t?
24119
24133
  t.message||t:"Unknown Error"));};g.addEventListener("message",u);g.addEventListener("error",r);w=setTimeout(()=>r("timeout"),1E4);let x=k.getImageData(0,0,d.width,d.height);y=e._postWorkerMessageSync(g,"decode",x,[x.data.buffer]);});}else q=await Promise.race([new Promise((g,l)=>window.setTimeout(()=>l("Scanner error: timeout"),1E4)),(async()=>{try{var [g]=await c.detect(d);if(!g)throw e.NO_QR_CODE_FOUND;return {data:g.rawValue,cornerPoints:e._convertPoints(g.cornerPoints,m)}}catch(l){g=l.message||l;
24120
24134
  if(/not implemented|service unavailable/.test(g))return e._disableBarcodeDetector=!0,e.scanImage(a,{scanRegion:m,canvas:d,disallowCanvasResizing:f,alsoTryWithoutScanRegion:h});throw `Scanner error: ${g}`;}})()]);return n?q:q.data}catch(p){if(!m||!h)throw p;let k=await e.scanImage(a,{qrEngine:c,canvas:d,disallowCanvasResizing:f});return n?k:k.data}finally{b||e._postWorkerMessage(c,"close");}}setGrayscaleWeights(a,b,c,d=!0){e._postWorkerMessage(this._qrEnginePromise,"grayscaleWeights",{red:a,green:b,
24121
- blue:c,useIntegerApproximation:d});}setInversionMode(a){e._postWorkerMessage(this._qrEnginePromise,"inversionMode",a);}static async createQrEngine(a){a&&console.warn("Specifying a worker path is not required and not supported anymore.");a=()=>import('./qr-scanner-worker.min-c002e984.js').then(c=>c.createWorker());if(!(!e._disableBarcodeDetector&&"BarcodeDetector"in window&&BarcodeDetector.getSupportedFormats&&(await BarcodeDetector.getSupportedFormats()).includes("qr_code")))return a();let b=navigator.userAgentData;
24135
+ blue:c,useIntegerApproximation:d});}setInversionMode(a){e._postWorkerMessage(this._qrEnginePromise,"inversionMode",a);}static async createQrEngine(a){a&&console.warn("Specifying a worker path is not required and not supported anymore.");a=()=>import('./qr-scanner-worker.min-RaSiJc_R.js').then(c=>c.createWorker());if(!(!e._disableBarcodeDetector&&"BarcodeDetector"in window&&BarcodeDetector.getSupportedFormats&&(await BarcodeDetector.getSupportedFormats()).includes("qr_code")))return a();let b=navigator.userAgentData;
24122
24136
  return b&&b.brands.some(({brand:c})=>/Chromium/i.test(c))&&/mac ?OS/i.test(b.platform)&&await b.getHighEntropyValues(["architecture","platformVersion"]).then(({architecture:c,platformVersion:d})=>/arm/i.test(c||"arm")&&13<=parseInt(d||"13")).catch(()=>!0)?a():new BarcodeDetector({formats:["qr_code"]})}_onPlay(){this._scanRegion=this._calculateScanRegion(this.$video);this._updateOverlay();this.$overlay&&(this.$overlay.style.display="");this._scanFrame();}_onLoadedMetaData(){this._scanRegion=this._calculateScanRegion(this.$video);
24123
24137
  this._updateOverlay();}_onVisibilityChange(){document.hidden?this.pause():this._active&&this.start();}_calculateScanRegion(a){let b=Math.round(2/3*Math.min(a.videoWidth,a.videoHeight));return {x:Math.round((a.videoWidth-b)/2),y:Math.round((a.videoHeight-b)/2),width:b,height:b,downScaledWidth:this._legacyCanvasSize,downScaledHeight:this._legacyCanvasSize}}_updateOverlay(){requestAnimationFrame(()=>{if(this.$overlay){var a=this.$video,b=a.videoWidth,c=a.videoHeight,d=a.offsetWidth,f=a.offsetHeight,h=a.offsetLeft,
24124
24138
  m=a.offsetTop,n=window.getComputedStyle(a),p=n.objectFit,k=b/c,q=d/f;switch(p){case "none":var g=b;var l=c;break;case "fill":g=d;l=f;break;default:("cover"===p?k>q:k<q)?(l=f,g=l*k):(g=d,l=g/k),"scale-down"===p&&(g=Math.min(g,b),l=Math.min(l,c));}var [v,w]=n.objectPosition.split(" ").map((r,y)=>{const x=parseFloat(r);return r.endsWith("%")?(y?f-l:d-g)*x/100:x});n=this._scanRegion.width||b;q=this._scanRegion.height||c;p=this._scanRegion.x||0;var u=this._scanRegion.y||0;k=this.$overlay.style;k.width=
@@ -27092,7 +27106,7 @@ class Identity {
27092
27106
  this.selectedAccount = new TextDecoder().decode(selected);
27093
27107
  }
27094
27108
  else {
27095
- const importee = await import(/* webpackChunkName: "generate-account" */ './index-687f692b.js');
27109
+ const importee = await import(/* webpackChunkName: "generate-account" */ './index-Wv-fIkmw.js');
27096
27110
  const { identity, accounts } = await importee.default(password, this.network);
27097
27111
  await globalThis.accountStore.put('public', JSON.stringify({ walletId: identity.walletId }));
27098
27112
  await globalThis.walletStore.put('version', String(1));
@@ -27283,7 +27297,7 @@ class Peernet {
27283
27297
  this.root = options.root;
27284
27298
  const { RequestMessage, ResponseMessage, PeerMessage, PeerMessageResponse, PeernetMessage, DHTMessage, DHTMessageResponse, DataMessage, DataMessageResponse, PsMessage, ChatMessage, PeernetFile
27285
27299
  // FolderMessageResponse
27286
- } = await import(/* webpackChunkName: "messages" */ './messages-1c117282.js');
27300
+ } = await import(/* webpackChunkName: "messages" */ './messages-y2oPb2AE.js');
27287
27301
  /**
27288
27302
  * proto Object containing protos
27289
27303
  * @type {Object}
@@ -27377,247 +27391,7 @@ class Peernet {
27377
27391
  if (this.#starting || this.#started)
27378
27392
  return;
27379
27393
  this.#starting = true;
27380
- const importee = class Client {
27381
- #peerId;
27382
- #connections = {};
27383
- #stars = {};
27384
- #connectEvent = 'peer:connected';
27385
- id;
27386
- networkVersion;
27387
- starsConfig;
27388
- socketClient;
27389
- messageSize = 262144;
27390
- version;
27391
- #messagesToHandle = {};
27392
- get peerId() {
27393
- return this.#peerId;
27394
- }
27395
- get connections() {
27396
- return { ...this.#connections };
27397
- }
27398
- get peers() {
27399
- return Object.entries(this.#connections);
27400
- }
27401
- getPeer(peerId) {
27402
- return this.#connections[peerId];
27403
- }
27404
- /**
27405
- *
27406
- * @param options {object}
27407
- * @param options.peerId {string}
27408
- * @param options.networkVersion {string}
27409
- * @param options.version {string}
27410
- * @param options.stars {string[]}
27411
- * @param options.connectEvent {string} defaults to peer:connected, can be renamed to handle different protocols, like peer:discovered (setup peer props before fireing the connect event)
27412
- */
27413
- constructor(options) {
27414
- const { peerId, networkVersion, version, connectEvent, stars } = {
27415
- ...defaultOptions,
27416
- ...options
27417
- };
27418
- this.#peerId = peerId;
27419
- this.networkVersion = networkVersion;
27420
- this.version = version;
27421
- this.#connectEvent = connectEvent;
27422
- this.starsConfig = stars;
27423
- this._init();
27424
- }
27425
- async _init() {
27426
- // reconnectJob()
27427
- if (!globalThis.RTCPeerConnection)
27428
- globalThis.wrtc = (await import('./browser-2c73e2ef.js').then(function (n) { return n.b; })).default;
27429
- for (const star of this.starsConfig) {
27430
- try {
27431
- const client = new SocketRequestClient(star, this.networkVersion);
27432
- this.#stars[star] = await client.init();
27433
- this.setupStarListeners(this.#stars[star]);
27434
- this.#stars[star].send({
27435
- url: 'join',
27436
- params: { version: this.version, peerId: this.peerId }
27437
- });
27438
- }
27439
- catch (e) {
27440
- if (this.starsConfig.indexOf(star) === this.starsConfig.length - 1 &&
27441
- !this.socketClient)
27442
- throw new Error(`No star available to connect`);
27443
- }
27444
- }
27445
- if (globalThis.navigator) {
27446
- globalThis.addEventListener('beforeunload', async () => this.close());
27447
- }
27448
- else {
27449
- process.on('SIGINT', async () => {
27450
- process.stdin.resume();
27451
- await this.close();
27452
- process.exit();
27453
- });
27454
- }
27455
- }
27456
- setupStarListeners(star) {
27457
- star.pubsub.subscribe('peer:joined', (id) => this.#peerJoined(id, star));
27458
- star.pubsub.subscribe('peer:left', (id) => this.#peerLeft(id, star));
27459
- star.pubsub.subscribe('star:joined', this.#starJoined);
27460
- star.pubsub.subscribe('star:left', this.#starLeft);
27461
- star.pubsub.subscribe('signal', (message) => this.#inComingSignal(message, star));
27462
- }
27463
- #starJoined = (id) => {
27464
- if (this.#stars[id]) {
27465
- this.#stars[id].close(0);
27466
- delete this.#stars[id];
27467
- }
27468
- console.log(`star ${id} joined`);
27469
- };
27470
- #starLeft = async (id) => {
27471
- if (this.#stars[id]) {
27472
- this.#stars[id].close(0);
27473
- delete this.#stars[id];
27474
- }
27475
- if (Object.keys(this.#stars).length === 0) {
27476
- for (const star of this.starsConfig) {
27477
- try {
27478
- const socketClient = await new SocketRequestClient(star, this.networkVersion).init();
27479
- if (!socketClient?.client?.OPEN)
27480
- return;
27481
- this.#stars[star] = socketClient;
27482
- this.#stars[star].send({
27483
- url: 'join',
27484
- params: { peerId: this.peerId, version: this.version }
27485
- });
27486
- this.setupStarListeners(socketClient);
27487
- }
27488
- catch (e) {
27489
- if (this.starsConfig.indexOf(star) === this.starsConfig.length - 1)
27490
- throw new Error(`No star available to connect`);
27491
- }
27492
- }
27493
- }
27494
- globalThis.debug(`star ${id} left`);
27495
- };
27496
- #peerLeft = (peer, star) => {
27497
- const id = peer.peerId || peer;
27498
- if (this.#connections[id]) {
27499
- this.#connections[id].destroy();
27500
- delete this.#connections[id];
27501
- }
27502
- globalThis.debug(`peer ${id} left`);
27503
- };
27504
- #createRTCPeerConnection = (peerId, star, version, initiator = false) => {
27505
- const peer = new Peer({
27506
- initiator: initiator,
27507
- from: this.peerId,
27508
- to: peerId,
27509
- version
27510
- });
27511
- peer.on('signal', (signal) => this.#peerSignal(peer, signal, star, this.version));
27512
- peer.on('connect', () => this.#peerConnect(peer));
27513
- peer.on('close', () => this.#peerClose(peer));
27514
- peer.on('data', (data) => this.#peerData(peer, data));
27515
- peer.on('error', (error) => this.#peerError(peer, error));
27516
- this.#connections[peerId] = peer;
27517
- };
27518
- #peerJoined = async ({ peerId, version }, star) => {
27519
- // check if peer rejoined before the previous connection closed
27520
- if (this.#connections[peerId]) {
27521
- this.#connections[peerId].destroy();
27522
- delete this.#connections[peerId];
27523
- }
27524
- // RTCPeerConnection
27525
- this.#createRTCPeerConnection(peerId, star, version, true);
27526
- globalThis.debug(`peer ${peerId} joined`);
27527
- };
27528
- #inComingSignal = async ({ from, signal, channelName, version }, star) => {
27529
- if (version !== this.version) {
27530
- console.warn(`${from} joined using the wrong version.\nexpected: ${this.version} but got:${version}`);
27531
- return;
27532
- }
27533
- let peer = this.#connections[from];
27534
- if (!peer) {
27535
- this.#createRTCPeerConnection(from, star, version);
27536
- peer = this.#connections[from];
27537
- }
27538
- if (String(peer.channelName) !== String(channelName))
27539
- console.warn(`channelNames don't match: got ${peer.channelName}, expected: ${channelName}`);
27540
- peer.signal(signal);
27541
- };
27542
- #peerSignal = (peer, signal, star, version) => {
27543
- let client = this.#stars[star];
27544
- if (!client)
27545
- client = this.#stars[Object.keys(this.#stars)[0]];
27546
- client.send({
27547
- url: 'signal',
27548
- params: {
27549
- from: this.peerId,
27550
- to: peer.peerId,
27551
- channelName: peer.channelName,
27552
- version,
27553
- signal
27554
- }
27555
- });
27556
- };
27557
- #peerClose = (peer) => {
27558
- if (this.#connections[peer.peerId]) {
27559
- peer.destroy();
27560
- delete this.#connections[peer.peerId];
27561
- }
27562
- globalThis.debug(`closed ${peer.peerId}'s connection`);
27563
- };
27564
- #peerConnect = (peer) => {
27565
- globalThis.debug(`${peer.peerId} connected`);
27566
- globalThis.pubsub.publishVerbose(this.#connectEvent, peer.peerId);
27567
- };
27568
- #noticeMessage = (message, id, from, peer) => {
27569
- if (globalThis.pubsub.subscribers[id]) {
27570
- globalThis.pubsub.publish(id, {
27571
- data: new Uint8Array(Object.values(message)),
27572
- id,
27573
- from,
27574
- peer
27575
- });
27576
- }
27577
- else {
27578
- globalThis.pubsub.publish('peer:data', {
27579
- data: new Uint8Array(Object.values(message)),
27580
- id,
27581
- from,
27582
- peer
27583
- });
27584
- }
27585
- };
27586
- #peerData = (peer, data) => {
27587
- const { id, size, chunk } = JSON.parse(new TextDecoder().decode(data));
27588
- peer.bw.down += size;
27589
- if (size <= MAX_MESSAGE_SIZE) {
27590
- this.#noticeMessage(chunk, id, peer.peerId, peer);
27591
- }
27592
- else {
27593
- if (!this.#messagesToHandle[id])
27594
- this.#messagesToHandle[id] = [];
27595
- this.#messagesToHandle[id] = [
27596
- ...this.#messagesToHandle[id],
27597
- ...Object.values(chunk)
27598
- ];
27599
- if (this.#messagesToHandle[id].length === Number(size)) {
27600
- this.#noticeMessage(this.#messagesToHandle[id], id, peer.peerId, peer);
27601
- delete this.#messagesToHandle[id];
27602
- }
27603
- }
27604
- };
27605
- #peerError = (peer, error) => {
27606
- console.warn(`Connection error: ${error.message}`);
27607
- peer.destroy();
27608
- };
27609
- async close() {
27610
- for (const star in this.#stars) {
27611
- if (this.#stars[star].connectionState() === 'open')
27612
- await this.#stars[star].send({ url: 'leave', params: this.peerId });
27613
- }
27614
- const promises = [
27615
- Object.values(this.#connections).map((connection) => connection.destroy()),
27616
- Object.values(this.#stars).map((connection) => connection.close(0))
27617
- ];
27618
- return Promise.allSettled(promises);
27619
- }
27620
- };
27394
+ const importee = await import('./client-peGn0FvK.js');
27621
27395
  /**
27622
27396
  * @access public
27623
27397
  * @type {PeernetClient}
@@ -28091,4 +27865,4 @@ class Peernet {
28091
27865
  }
28092
27866
  globalThis.Peernet = Peernet;
28093
27867
 
28094
- export { FormatInterface as F, MultiWallet as M, Peernet as P, base58$1 as b, encrypt as e };
27868
+ export { FormatInterface as F, LittlePubSub as L, MultiWallet as M, Peernet as P, base58$1 as b, commonjsGlobal as c, encrypt as e, getDefaultExportFromCjs as g, inherits_browserExports as i, require$$3 as r };