@leofcoin/peernet 1.1.76 → 1.1.78

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.
@@ -14,7 +14,8 @@ const debug$1 = (target, text) => {
14
14
  globalThis.DEBUG === 'true' ||
15
15
  globalThis.DEBUG === true ||
16
16
  globalThis.DEBUG?.indexOf(target) !== -1 ||
17
- globalThis.DEBUG?.indexOf('*') !== -1
17
+ globalThis.DEBUG?.indexOf('*') !== -1 ||
18
+ globalThis.DEBUG?.indexOf(target.split('/')[0]) !== -1
18
19
  )
19
20
  if (text) console.log('\x1b[34m\x1b[1m%s', `${target}: ${text}`, '\x1b[0m');
20
21
  else console.log('\x1b[34m\x1b[1m%s', `${target}`, '\x1b[0m');
@@ -12767,6 +12768,7 @@ const nothingFoundError = (hash) => {
12767
12768
  };
12768
12769
 
12769
12770
  const isBrowser = globalThis.process?.versions?.node ? false : true;
12771
+
12770
12772
  let LeofcoinStorage$1 = class LeofcoinStorage {
12771
12773
  name;
12772
12774
  root;
@@ -12802,7 +12804,7 @@ let LeofcoinStorage$1 = class LeofcoinStorage {
12802
12804
  if (typeof key === 'object')
12803
12805
  return this.many('has', key);
12804
12806
  try {
12805
- const has = await this.db.get(new KeyPath(key));
12807
+ const has = await this.db.has(new KeyPath(key));
12806
12808
  return Boolean(has);
12807
12809
  }
12808
12810
  catch (e) {
@@ -13015,182 +13017,519 @@ var index$1 = {
13015
13017
  }
13016
13018
  };
13017
13019
 
13018
- var elliptic$2 = {};
13019
-
13020
- var name = "elliptic";
13021
- var version$1 = "6.5.4";
13022
- var description = "EC cryptography";
13023
- var main = "lib/elliptic.js";
13024
- var files = [
13025
- "lib"
13026
- ];
13027
- var scripts = {
13028
- lint: "eslint lib test",
13029
- "lint:fix": "npm run lint -- --fix",
13030
- unit: "istanbul test _mocha --reporter=spec test/index.js",
13031
- test: "npm run lint && npm run unit",
13032
- version: "grunt dist && git add dist/"
13033
- };
13034
- var repository = {
13035
- type: "git",
13036
- url: "git@github.com:indutny/elliptic"
13037
- };
13038
- var keywords = [
13039
- "EC",
13040
- "Elliptic",
13041
- "curve",
13042
- "Cryptography"
13043
- ];
13044
- var author = "Fedor Indutny <fedor@indutny.com>";
13045
- var license = "MIT";
13046
- var bugs = {
13047
- url: "https://github.com/indutny/elliptic/issues"
13048
- };
13049
- var homepage = "https://github.com/indutny/elliptic";
13050
- var devDependencies = {
13051
- brfs: "^2.0.2",
13052
- coveralls: "^3.1.0",
13053
- eslint: "^7.6.0",
13054
- grunt: "^1.2.1",
13055
- "grunt-browserify": "^5.3.0",
13056
- "grunt-cli": "^1.3.2",
13057
- "grunt-contrib-connect": "^3.0.0",
13058
- "grunt-contrib-copy": "^1.0.0",
13059
- "grunt-contrib-uglify": "^5.0.0",
13060
- "grunt-mocha-istanbul": "^5.0.2",
13061
- "grunt-saucelabs": "^9.0.1",
13062
- istanbul: "^0.4.5",
13063
- mocha: "^8.0.1"
13064
- };
13065
- var dependencies = {
13066
- "bn.js": "^4.11.9",
13067
- brorand: "^1.1.0",
13068
- "hash.js": "^1.0.0",
13069
- "hmac-drbg": "^1.0.1",
13070
- inherits: "^2.0.4",
13071
- "minimalistic-assert": "^1.0.1",
13072
- "minimalistic-crypto-utils": "^1.0.1"
13073
- };
13074
- var require$$0 = {
13075
- name: name,
13076
- version: version$1,
13077
- description: description,
13078
- main: main,
13079
- files: files,
13080
- scripts: scripts,
13081
- repository: repository,
13082
- keywords: keywords,
13083
- author: author,
13084
- license: license,
13085
- bugs: bugs,
13086
- homepage: homepage,
13087
- devDependencies: devDependencies,
13088
- dependencies: dependencies
13020
+ const errors = {
13021
+ IMPOSSIBLE_CASE: 'Impossible case. Please create issue.',
13022
+ TWEAK_ADD:
13023
+ 'The tweak was out of range or the resulted private key is invalid',
13024
+ TWEAK_MUL: 'The tweak was out of range or equal to zero',
13025
+ CONTEXT_RANDOMIZE_UNKNOW: 'Unknow error on context randomization',
13026
+ SECKEY_INVALID: 'Private Key is invalid',
13027
+ PUBKEY_PARSE: 'Public Key could not be parsed',
13028
+ PUBKEY_SERIALIZE: 'Public Key serialization error',
13029
+ PUBKEY_COMBINE: 'The sum of the public keys is not valid',
13030
+ SIG_PARSE: 'Signature could not be parsed',
13031
+ SIGN: 'The nonce generation function failed, or the private key was invalid',
13032
+ RECOVER: 'Public key could not be recover',
13033
+ ECDH: 'Scalar was invalid (zero or overflow)'
13089
13034
  };
13090
13035
 
13091
- var utils$o = {};
13036
+ function assert$g (cond, msg) {
13037
+ if (!cond) throw new Error(msg)
13038
+ }
13092
13039
 
13093
- var bn = {exports: {}};
13040
+ function isUint8Array (name, value, length) {
13041
+ assert$g(value instanceof Uint8Array, `Expected ${name} to be an Uint8Array`);
13094
13042
 
13095
- bn.exports;
13043
+ if (length !== undefined) {
13044
+ if (Array.isArray(length)) {
13045
+ const numbers = length.join(', ');
13046
+ const msg = `Expected ${name} to be an Uint8Array with length [${numbers}]`;
13047
+ assert$g(length.includes(value.length), msg);
13048
+ } else {
13049
+ const msg = `Expected ${name} to be an Uint8Array with length ${length}`;
13050
+ assert$g(value.length === length, msg);
13051
+ }
13052
+ }
13053
+ }
13096
13054
 
13097
- (function (module) {
13098
- (function (module, exports) {
13055
+ function isCompressed (value) {
13056
+ assert$g(toTypeString(value) === 'Boolean', 'Expected compressed to be a Boolean');
13057
+ }
13099
13058
 
13100
- // Utils
13101
- function assert (val, msg) {
13102
- if (!val) throw new Error(msg || 'Assertion failed');
13103
- }
13059
+ function getAssertedOutput (output = (len) => new Uint8Array(len), length) {
13060
+ if (typeof output === 'function') output = output(length);
13061
+ isUint8Array('output', output, length);
13062
+ return output
13063
+ }
13104
13064
 
13105
- // Could use `inherits` module, but don't want to move from single file
13106
- // architecture yet.
13107
- function inherits (ctor, superCtor) {
13108
- ctor.super_ = superCtor;
13109
- var TempCtor = function () {};
13110
- TempCtor.prototype = superCtor.prototype;
13111
- ctor.prototype = new TempCtor();
13112
- ctor.prototype.constructor = ctor;
13113
- }
13065
+ function toTypeString (value) {
13066
+ return Object.prototype.toString.call(value).slice(8, -1)
13067
+ }
13114
13068
 
13115
- // BN
13069
+ var lib = (secp256k1) => {
13070
+ return {
13071
+ contextRandomize (seed) {
13072
+ assert$g(
13073
+ seed === null || seed instanceof Uint8Array,
13074
+ 'Expected seed to be an Uint8Array or null'
13075
+ );
13076
+ if (seed !== null) isUint8Array('seed', seed, 32);
13116
13077
 
13117
- function BN (number, base, endian) {
13118
- if (BN.isBN(number)) {
13119
- return number;
13120
- }
13078
+ switch (secp256k1.contextRandomize(seed)) {
13079
+ case 1:
13080
+ throw new Error(errors.CONTEXT_RANDOMIZE_UNKNOW)
13081
+ }
13082
+ },
13121
13083
 
13122
- this.negative = 0;
13123
- this.words = null;
13124
- this.length = 0;
13084
+ privateKeyVerify (seckey) {
13085
+ isUint8Array('private key', seckey, 32);
13125
13086
 
13126
- // Reduction context
13127
- this.red = null;
13087
+ return secp256k1.privateKeyVerify(seckey) === 0
13088
+ },
13128
13089
 
13129
- if (number !== null) {
13130
- if (base === 'le' || base === 'be') {
13131
- endian = base;
13132
- base = 10;
13133
- }
13090
+ privateKeyNegate (seckey) {
13091
+ isUint8Array('private key', seckey, 32);
13134
13092
 
13135
- this._init(number || 0, base || 10, endian || 'be');
13136
- }
13137
- }
13138
- if (typeof module === 'object') {
13139
- module.exports = BN;
13140
- } else {
13141
- exports.BN = BN;
13142
- }
13093
+ switch (secp256k1.privateKeyNegate(seckey)) {
13094
+ case 0:
13095
+ return seckey
13096
+ case 1:
13097
+ throw new Error(errors.IMPOSSIBLE_CASE)
13098
+ }
13099
+ },
13143
13100
 
13144
- BN.BN = BN;
13145
- BN.wordSize = 26;
13101
+ privateKeyTweakAdd (seckey, tweak) {
13102
+ isUint8Array('private key', seckey, 32);
13103
+ isUint8Array('tweak', tweak, 32);
13146
13104
 
13147
- var Buffer;
13148
- try {
13149
- if (typeof window !== 'undefined' && typeof window.Buffer !== 'undefined') {
13150
- Buffer = window.Buffer;
13151
- } else {
13152
- Buffer = require$$3.Buffer;
13153
- }
13154
- } catch (e) {
13155
- }
13105
+ switch (secp256k1.privateKeyTweakAdd(seckey, tweak)) {
13106
+ case 0:
13107
+ return seckey
13108
+ case 1:
13109
+ throw new Error(errors.TWEAK_ADD)
13110
+ }
13111
+ },
13156
13112
 
13157
- BN.isBN = function isBN (num) {
13158
- if (num instanceof BN) {
13159
- return true;
13160
- }
13113
+ privateKeyTweakMul (seckey, tweak) {
13114
+ isUint8Array('private key', seckey, 32);
13115
+ isUint8Array('tweak', tweak, 32);
13161
13116
 
13162
- return num !== null && typeof num === 'object' &&
13163
- num.constructor.wordSize === BN.wordSize && Array.isArray(num.words);
13164
- };
13117
+ switch (secp256k1.privateKeyTweakMul(seckey, tweak)) {
13118
+ case 0:
13119
+ return seckey
13120
+ case 1:
13121
+ throw new Error(errors.TWEAK_MUL)
13122
+ }
13123
+ },
13165
13124
 
13166
- BN.max = function max (left, right) {
13167
- if (left.cmp(right) > 0) return left;
13168
- return right;
13169
- };
13125
+ publicKeyVerify (pubkey) {
13126
+ isUint8Array('public key', pubkey, [33, 65]);
13170
13127
 
13171
- BN.min = function min (left, right) {
13172
- if (left.cmp(right) < 0) return left;
13173
- return right;
13174
- };
13128
+ return secp256k1.publicKeyVerify(pubkey) === 0
13129
+ },
13175
13130
 
13176
- BN.prototype._init = function init (number, base, endian) {
13177
- if (typeof number === 'number') {
13178
- return this._initNumber(number, base, endian);
13179
- }
13131
+ publicKeyCreate (seckey, compressed = true, output) {
13132
+ isUint8Array('private key', seckey, 32);
13133
+ isCompressed(compressed);
13134
+ output = getAssertedOutput(output, compressed ? 33 : 65);
13180
13135
 
13181
- if (typeof number === 'object') {
13182
- return this._initArray(number, base, endian);
13183
- }
13136
+ switch (secp256k1.publicKeyCreate(output, seckey)) {
13137
+ case 0:
13138
+ return output
13139
+ case 1:
13140
+ throw new Error(errors.SECKEY_INVALID)
13141
+ case 2:
13142
+ throw new Error(errors.PUBKEY_SERIALIZE)
13143
+ }
13144
+ },
13184
13145
 
13185
- if (base === 'hex') {
13186
- base = 16;
13187
- }
13188
- assert(base === (base | 0) && base >= 2 && base <= 36);
13146
+ publicKeyConvert (pubkey, compressed = true, output) {
13147
+ isUint8Array('public key', pubkey, [33, 65]);
13148
+ isCompressed(compressed);
13149
+ output = getAssertedOutput(output, compressed ? 33 : 65);
13189
13150
 
13190
- number = number.toString().replace(/\s+/g, '');
13191
- var start = 0;
13192
- if (number[0] === '-') {
13193
- start++;
13151
+ switch (secp256k1.publicKeyConvert(output, pubkey)) {
13152
+ case 0:
13153
+ return output
13154
+ case 1:
13155
+ throw new Error(errors.PUBKEY_PARSE)
13156
+ case 2:
13157
+ throw new Error(errors.PUBKEY_SERIALIZE)
13158
+ }
13159
+ },
13160
+
13161
+ publicKeyNegate (pubkey, compressed = true, output) {
13162
+ isUint8Array('public key', pubkey, [33, 65]);
13163
+ isCompressed(compressed);
13164
+ output = getAssertedOutput(output, compressed ? 33 : 65);
13165
+
13166
+ switch (secp256k1.publicKeyNegate(output, pubkey)) {
13167
+ case 0:
13168
+ return output
13169
+ case 1:
13170
+ throw new Error(errors.PUBKEY_PARSE)
13171
+ case 2:
13172
+ throw new Error(errors.IMPOSSIBLE_CASE)
13173
+ case 3:
13174
+ throw new Error(errors.PUBKEY_SERIALIZE)
13175
+ }
13176
+ },
13177
+
13178
+ publicKeyCombine (pubkeys, compressed = true, output) {
13179
+ assert$g(Array.isArray(pubkeys), 'Expected public keys to be an Array');
13180
+ assert$g(pubkeys.length > 0, 'Expected public keys array will have more than zero items');
13181
+ for (const pubkey of pubkeys) {
13182
+ isUint8Array('public key', pubkey, [33, 65]);
13183
+ }
13184
+ isCompressed(compressed);
13185
+ output = getAssertedOutput(output, compressed ? 33 : 65);
13186
+
13187
+ switch (secp256k1.publicKeyCombine(output, pubkeys)) {
13188
+ case 0:
13189
+ return output
13190
+ case 1:
13191
+ throw new Error(errors.PUBKEY_PARSE)
13192
+ case 2:
13193
+ throw new Error(errors.PUBKEY_COMBINE)
13194
+ case 3:
13195
+ throw new Error(errors.PUBKEY_SERIALIZE)
13196
+ }
13197
+ },
13198
+
13199
+ publicKeyTweakAdd (pubkey, tweak, compressed = true, output) {
13200
+ isUint8Array('public key', pubkey, [33, 65]);
13201
+ isUint8Array('tweak', tweak, 32);
13202
+ isCompressed(compressed);
13203
+ output = getAssertedOutput(output, compressed ? 33 : 65);
13204
+
13205
+ switch (secp256k1.publicKeyTweakAdd(output, pubkey, tweak)) {
13206
+ case 0:
13207
+ return output
13208
+ case 1:
13209
+ throw new Error(errors.PUBKEY_PARSE)
13210
+ case 2:
13211
+ throw new Error(errors.TWEAK_ADD)
13212
+ }
13213
+ },
13214
+
13215
+ publicKeyTweakMul (pubkey, tweak, compressed = true, output) {
13216
+ isUint8Array('public key', pubkey, [33, 65]);
13217
+ isUint8Array('tweak', tweak, 32);
13218
+ isCompressed(compressed);
13219
+ output = getAssertedOutput(output, compressed ? 33 : 65);
13220
+
13221
+ switch (secp256k1.publicKeyTweakMul(output, pubkey, tweak)) {
13222
+ case 0:
13223
+ return output
13224
+ case 1:
13225
+ throw new Error(errors.PUBKEY_PARSE)
13226
+ case 2:
13227
+ throw new Error(errors.TWEAK_MUL)
13228
+ }
13229
+ },
13230
+
13231
+ signatureNormalize (sig) {
13232
+ isUint8Array('signature', sig, 64);
13233
+
13234
+ switch (secp256k1.signatureNormalize(sig)) {
13235
+ case 0:
13236
+ return sig
13237
+ case 1:
13238
+ throw new Error(errors.SIG_PARSE)
13239
+ }
13240
+ },
13241
+
13242
+ signatureExport (sig, output) {
13243
+ isUint8Array('signature', sig, 64);
13244
+ output = getAssertedOutput(output, 72);
13245
+
13246
+ const obj = { output, outputlen: 72 };
13247
+ switch (secp256k1.signatureExport(obj, sig)) {
13248
+ case 0:
13249
+ return output.slice(0, obj.outputlen)
13250
+ case 1:
13251
+ throw new Error(errors.SIG_PARSE)
13252
+ case 2:
13253
+ throw new Error(errors.IMPOSSIBLE_CASE)
13254
+ }
13255
+ },
13256
+
13257
+ signatureImport (sig, output) {
13258
+ isUint8Array('signature', sig);
13259
+ output = getAssertedOutput(output, 64);
13260
+
13261
+ switch (secp256k1.signatureImport(output, sig)) {
13262
+ case 0:
13263
+ return output
13264
+ case 1:
13265
+ throw new Error(errors.SIG_PARSE)
13266
+ case 2:
13267
+ throw new Error(errors.IMPOSSIBLE_CASE)
13268
+ }
13269
+ },
13270
+
13271
+ ecdsaSign (msg32, seckey, options = {}, output) {
13272
+ isUint8Array('message', msg32, 32);
13273
+ isUint8Array('private key', seckey, 32);
13274
+ assert$g(toTypeString(options) === 'Object', 'Expected options to be an Object');
13275
+ if (options.data !== undefined) isUint8Array('options.data', options.data);
13276
+ if (options.noncefn !== undefined) assert$g(toTypeString(options.noncefn) === 'Function', 'Expected options.noncefn to be a Function');
13277
+ output = getAssertedOutput(output, 64);
13278
+
13279
+ const obj = { signature: output, recid: null };
13280
+ switch (secp256k1.ecdsaSign(obj, msg32, seckey, options.data, options.noncefn)) {
13281
+ case 0:
13282
+ return obj
13283
+ case 1:
13284
+ throw new Error(errors.SIGN)
13285
+ case 2:
13286
+ throw new Error(errors.IMPOSSIBLE_CASE)
13287
+ }
13288
+ },
13289
+
13290
+ ecdsaVerify (sig, msg32, pubkey) {
13291
+ isUint8Array('signature', sig, 64);
13292
+ isUint8Array('message', msg32, 32);
13293
+ isUint8Array('public key', pubkey, [33, 65]);
13294
+
13295
+ switch (secp256k1.ecdsaVerify(sig, msg32, pubkey)) {
13296
+ case 0:
13297
+ return true
13298
+ case 3:
13299
+ return false
13300
+ case 1:
13301
+ throw new Error(errors.SIG_PARSE)
13302
+ case 2:
13303
+ throw new Error(errors.PUBKEY_PARSE)
13304
+ }
13305
+ },
13306
+
13307
+ ecdsaRecover (sig, recid, msg32, compressed = true, output) {
13308
+ isUint8Array('signature', sig, 64);
13309
+ assert$g(
13310
+ toTypeString(recid) === 'Number' &&
13311
+ recid >= 0 &&
13312
+ recid <= 3,
13313
+ 'Expected recovery id to be a Number within interval [0, 3]'
13314
+ );
13315
+ isUint8Array('message', msg32, 32);
13316
+ isCompressed(compressed);
13317
+ output = getAssertedOutput(output, compressed ? 33 : 65);
13318
+
13319
+ switch (secp256k1.ecdsaRecover(output, sig, recid, msg32)) {
13320
+ case 0:
13321
+ return output
13322
+ case 1:
13323
+ throw new Error(errors.SIG_PARSE)
13324
+ case 2:
13325
+ throw new Error(errors.RECOVER)
13326
+ case 3:
13327
+ throw new Error(errors.IMPOSSIBLE_CASE)
13328
+ }
13329
+ },
13330
+
13331
+ ecdh (pubkey, seckey, options = {}, output) {
13332
+ isUint8Array('public key', pubkey, [33, 65]);
13333
+ isUint8Array('private key', seckey, 32);
13334
+ assert$g(toTypeString(options) === 'Object', 'Expected options to be an Object');
13335
+ if (options.data !== undefined) isUint8Array('options.data', options.data);
13336
+ if (options.hashfn !== undefined) {
13337
+ assert$g(toTypeString(options.hashfn) === 'Function', 'Expected options.hashfn to be a Function');
13338
+ if (options.xbuf !== undefined) isUint8Array('options.xbuf', options.xbuf, 32);
13339
+ if (options.ybuf !== undefined) isUint8Array('options.ybuf', options.ybuf, 32);
13340
+ isUint8Array('output', output);
13341
+ } else {
13342
+ output = getAssertedOutput(output, 32);
13343
+ }
13344
+
13345
+ switch (secp256k1.ecdh(output, pubkey, seckey, options.data, options.hashfn, options.xbuf, options.ybuf)) {
13346
+ case 0:
13347
+ return output
13348
+ case 1:
13349
+ throw new Error(errors.PUBKEY_PARSE)
13350
+ case 2:
13351
+ throw new Error(errors.ECDH)
13352
+ }
13353
+ }
13354
+ }
13355
+ };
13356
+
13357
+ var elliptic$2 = {};
13358
+
13359
+ var name = "elliptic";
13360
+ var version$1 = "6.5.4";
13361
+ var description = "EC cryptography";
13362
+ var main = "lib/elliptic.js";
13363
+ var files = [
13364
+ "lib"
13365
+ ];
13366
+ var scripts = {
13367
+ lint: "eslint lib test",
13368
+ "lint:fix": "npm run lint -- --fix",
13369
+ unit: "istanbul test _mocha --reporter=spec test/index.js",
13370
+ test: "npm run lint && npm run unit",
13371
+ version: "grunt dist && git add dist/"
13372
+ };
13373
+ var repository = {
13374
+ type: "git",
13375
+ url: "git@github.com:indutny/elliptic"
13376
+ };
13377
+ var keywords = [
13378
+ "EC",
13379
+ "Elliptic",
13380
+ "curve",
13381
+ "Cryptography"
13382
+ ];
13383
+ var author = "Fedor Indutny <fedor@indutny.com>";
13384
+ var license = "MIT";
13385
+ var bugs = {
13386
+ url: "https://github.com/indutny/elliptic/issues"
13387
+ };
13388
+ var homepage = "https://github.com/indutny/elliptic";
13389
+ var devDependencies = {
13390
+ brfs: "^2.0.2",
13391
+ coveralls: "^3.1.0",
13392
+ eslint: "^7.6.0",
13393
+ grunt: "^1.2.1",
13394
+ "grunt-browserify": "^5.3.0",
13395
+ "grunt-cli": "^1.3.2",
13396
+ "grunt-contrib-connect": "^3.0.0",
13397
+ "grunt-contrib-copy": "^1.0.0",
13398
+ "grunt-contrib-uglify": "^5.0.0",
13399
+ "grunt-mocha-istanbul": "^5.0.2",
13400
+ "grunt-saucelabs": "^9.0.1",
13401
+ istanbul: "^0.4.5",
13402
+ mocha: "^8.0.1"
13403
+ };
13404
+ var dependencies = {
13405
+ "bn.js": "^4.11.9",
13406
+ brorand: "^1.1.0",
13407
+ "hash.js": "^1.0.0",
13408
+ "hmac-drbg": "^1.0.1",
13409
+ inherits: "^2.0.4",
13410
+ "minimalistic-assert": "^1.0.1",
13411
+ "minimalistic-crypto-utils": "^1.0.1"
13412
+ };
13413
+ var require$$0 = {
13414
+ name: name,
13415
+ version: version$1,
13416
+ description: description,
13417
+ main: main,
13418
+ files: files,
13419
+ scripts: scripts,
13420
+ repository: repository,
13421
+ keywords: keywords,
13422
+ author: author,
13423
+ license: license,
13424
+ bugs: bugs,
13425
+ homepage: homepage,
13426
+ devDependencies: devDependencies,
13427
+ dependencies: dependencies
13428
+ };
13429
+
13430
+ var utils$o = {};
13431
+
13432
+ var bn = {exports: {}};
13433
+
13434
+ bn.exports;
13435
+
13436
+ (function (module) {
13437
+ (function (module, exports) {
13438
+
13439
+ // Utils
13440
+ function assert (val, msg) {
13441
+ if (!val) throw new Error(msg || 'Assertion failed');
13442
+ }
13443
+
13444
+ // Could use `inherits` module, but don't want to move from single file
13445
+ // architecture yet.
13446
+ function inherits (ctor, superCtor) {
13447
+ ctor.super_ = superCtor;
13448
+ var TempCtor = function () {};
13449
+ TempCtor.prototype = superCtor.prototype;
13450
+ ctor.prototype = new TempCtor();
13451
+ ctor.prototype.constructor = ctor;
13452
+ }
13453
+
13454
+ // BN
13455
+
13456
+ function BN (number, base, endian) {
13457
+ if (BN.isBN(number)) {
13458
+ return number;
13459
+ }
13460
+
13461
+ this.negative = 0;
13462
+ this.words = null;
13463
+ this.length = 0;
13464
+
13465
+ // Reduction context
13466
+ this.red = null;
13467
+
13468
+ if (number !== null) {
13469
+ if (base === 'le' || base === 'be') {
13470
+ endian = base;
13471
+ base = 10;
13472
+ }
13473
+
13474
+ this._init(number || 0, base || 10, endian || 'be');
13475
+ }
13476
+ }
13477
+ if (typeof module === 'object') {
13478
+ module.exports = BN;
13479
+ } else {
13480
+ exports.BN = BN;
13481
+ }
13482
+
13483
+ BN.BN = BN;
13484
+ BN.wordSize = 26;
13485
+
13486
+ var Buffer;
13487
+ try {
13488
+ if (typeof window !== 'undefined' && typeof window.Buffer !== 'undefined') {
13489
+ Buffer = window.Buffer;
13490
+ } else {
13491
+ Buffer = require$$3.Buffer;
13492
+ }
13493
+ } catch (e) {
13494
+ }
13495
+
13496
+ BN.isBN = function isBN (num) {
13497
+ if (num instanceof BN) {
13498
+ return true;
13499
+ }
13500
+
13501
+ return num !== null && typeof num === 'object' &&
13502
+ num.constructor.wordSize === BN.wordSize && Array.isArray(num.words);
13503
+ };
13504
+
13505
+ BN.max = function max (left, right) {
13506
+ if (left.cmp(right) > 0) return left;
13507
+ return right;
13508
+ };
13509
+
13510
+ BN.min = function min (left, right) {
13511
+ if (left.cmp(right) < 0) return left;
13512
+ return right;
13513
+ };
13514
+
13515
+ BN.prototype._init = function init (number, base, endian) {
13516
+ if (typeof number === 'number') {
13517
+ return this._initNumber(number, base, endian);
13518
+ }
13519
+
13520
+ if (typeof number === 'object') {
13521
+ return this._initArray(number, base, endian);
13522
+ }
13523
+
13524
+ if (base === 'hex') {
13525
+ base = 16;
13526
+ }
13527
+ assert(base === (base | 0) && base >= 2 && base <= 36);
13528
+
13529
+ number = number.toString().replace(/\s+/g, '');
13530
+ var start = 0;
13531
+ if (number[0] === '-') {
13532
+ start++;
13194
13533
  this.negative = 1;
13195
13534
  }
13196
13535
 
@@ -16542,14 +16881,14 @@ bn.exports;
16542
16881
 
16543
16882
  var bnExports = bn.exports;
16544
16883
 
16545
- var minimalisticAssert = assert$g;
16884
+ var minimalisticAssert = assert$f;
16546
16885
 
16547
- function assert$g(val, msg) {
16886
+ function assert$f(val, msg) {
16548
16887
  if (!val)
16549
16888
  throw new Error(msg || 'Assertion failed');
16550
16889
  }
16551
16890
 
16552
- assert$g.equal = function assertEqual(l, r, msg) {
16891
+ assert$f.equal = function assertEqual(l, r, msg) {
16553
16892
  if (l != r)
16554
16893
  throw new Error(msg || ('Assertion failed: ' + l + ' != ' + r));
16555
16894
  };
@@ -16812,7 +17151,7 @@ var BN$8 = bnExports;
16812
17151
  var utils$m = utils$o;
16813
17152
  var getNAF = utils$m.getNAF;
16814
17153
  var getJSF = utils$m.getJSF;
16815
- var assert$f = utils$m.assert;
17154
+ var assert$e = utils$m.assert;
16816
17155
 
16817
17156
  function BaseCurve(type, conf) {
16818
17157
  this.type = type;
@@ -16858,7 +17197,7 @@ BaseCurve.prototype.validate = function validate() {
16858
17197
  };
16859
17198
 
16860
17199
  BaseCurve.prototype._fixedNafMul = function _fixedNafMul(p, k) {
16861
- assert$f(p.precomputed);
17200
+ assert$e(p.precomputed);
16862
17201
  var doubles = p._getDoubles();
16863
17202
 
16864
17203
  var naf = getNAF(k, 1, this._bitLength);
@@ -16915,7 +17254,7 @@ BaseCurve.prototype._wnafMul = function _wnafMul(p, k) {
16915
17254
  if (i < 0)
16916
17255
  break;
16917
17256
  var z = naf[i];
16918
- assert$f(z !== 0);
17257
+ assert$e(z !== 0);
16919
17258
  if (p.type === 'affine') {
16920
17259
  // J +- P
16921
17260
  if (z > 0)
@@ -17083,9 +17422,9 @@ BaseCurve.prototype.decodePoint = function decodePoint(bytes, enc) {
17083
17422
  if ((bytes[0] === 0x04 || bytes[0] === 0x06 || bytes[0] === 0x07) &&
17084
17423
  bytes.length - 1 === 2 * len) {
17085
17424
  if (bytes[0] === 0x06)
17086
- assert$f(bytes[bytes.length - 1] % 2 === 0);
17425
+ assert$e(bytes[bytes.length - 1] % 2 === 0);
17087
17426
  else if (bytes[0] === 0x07)
17088
- assert$f(bytes[bytes.length - 1] % 2 === 1);
17427
+ assert$e(bytes[bytes.length - 1] % 2 === 1);
17089
17428
 
17090
17429
  var res = this.point(bytes.slice(1, 1 + len),
17091
17430
  bytes.slice(1 + len, 1 + 2 * len));
@@ -17224,7 +17563,7 @@ var BN$7 = bnExports;
17224
17563
  var inherits$3 = inherits_browserExports;
17225
17564
  var Base$2 = base;
17226
17565
 
17227
- var assert$e = utils$l.assert;
17566
+ var assert$d = utils$l.assert;
17228
17567
 
17229
17568
  function ShortCurve(conf) {
17230
17569
  Base$2.call(this, 'short', conf);
@@ -17269,7 +17608,7 @@ ShortCurve.prototype._getEndomorphism = function _getEndomorphism(conf) {
17269
17608
  lambda = lambdas[0];
17270
17609
  } else {
17271
17610
  lambda = lambdas[1];
17272
- assert$e(this.g.mul(lambda).x.cmp(this.g.x.redMul(beta)) === 0);
17611
+ assert$d(this.g.mul(lambda).x.cmp(this.g.x.redMul(beta)) === 0);
17273
17612
  }
17274
17613
  }
17275
17614
 
@@ -18338,7 +18677,7 @@ var BN$5 = bnExports;
18338
18677
  var inherits$1 = inherits_browserExports;
18339
18678
  var Base = base;
18340
18679
 
18341
- var assert$d = utils$j.assert;
18680
+ var assert$c = utils$j.assert;
18342
18681
 
18343
18682
  function EdwardsCurve(conf) {
18344
18683
  // NOTE: Important as we are creating point in Base.call()
@@ -18355,7 +18694,7 @@ function EdwardsCurve(conf) {
18355
18694
  this.d = new BN$5(conf.d, 16).toRed(this.red);
18356
18695
  this.dd = this.d.redAdd(this.d);
18357
18696
 
18358
- assert$d(!this.twisted || this.c.fromRed().cmpn(1) === 0);
18697
+ assert$c(!this.twisted || this.c.fromRed().cmpn(1) === 0);
18359
18698
  this.oneC = (conf.c | 0) === 1;
18360
18699
  }
18361
18700
  inherits$1(EdwardsCurve, Base);
@@ -18783,7 +19122,7 @@ var hash$2 = {};
18783
19122
 
18784
19123
  var utils$i = {};
18785
19124
 
18786
- var assert$c = minimalisticAssert;
19125
+ var assert$b = minimalisticAssert;
18787
19126
  var inherits = inherits_browserExports;
18788
19127
 
18789
19128
  utils$i.inherits = inherits;
@@ -18904,7 +19243,7 @@ utils$i.zero8 = zero8;
18904
19243
 
18905
19244
  function join32(msg, start, end, endian) {
18906
19245
  var len = end - start;
18907
- assert$c(len % 4 === 0);
19246
+ assert$b(len % 4 === 0);
18908
19247
  var res = new Array(len / 4);
18909
19248
  for (var i = 0, k = start; i < res.length; i++, k += 4) {
18910
19249
  var w;
@@ -19063,7 +19402,7 @@ utils$i.shr64_lo = shr64_lo$1;
19063
19402
  var common$5 = {};
19064
19403
 
19065
19404
  var utils$h = utils$i;
19066
- var assert$b = minimalisticAssert;
19405
+ var assert$a = minimalisticAssert;
19067
19406
 
19068
19407
  function BlockHash$4() {
19069
19408
  this.pending = null;
@@ -19108,7 +19447,7 @@ BlockHash$4.prototype.update = function update(msg, enc) {
19108
19447
 
19109
19448
  BlockHash$4.prototype.digest = function digest(enc) {
19110
19449
  this.update(this._pad());
19111
- assert$b(this.pending === null);
19450
+ assert$a(this.pending === null);
19112
19451
 
19113
19452
  return this._digest(enc);
19114
19453
  };
@@ -19281,7 +19620,7 @@ SHA1.prototype._digest = function digest(enc) {
19281
19620
  var utils$e = utils$i;
19282
19621
  var common$2 = common$5;
19283
19622
  var shaCommon = common$4;
19284
- var assert$a = minimalisticAssert;
19623
+ var assert$9 = minimalisticAssert;
19285
19624
 
19286
19625
  var sum32$1 = utils$e.sum32;
19287
19626
  var sum32_4$1 = utils$e.sum32_4;
@@ -19351,7 +19690,7 @@ SHA256$1.prototype._update = function _update(msg, start) {
19351
19690
  var g = this.h[6];
19352
19691
  var h = this.h[7];
19353
19692
 
19354
- assert$a(this.k.length === W.length);
19693
+ assert$9(this.k.length === W.length);
19355
19694
  for (i = 0; i < W.length; i++) {
19356
19695
  var T1 = sum32_5(h, s1_256(e), ch32(e, f, g), this.k[i], W[i]);
19357
19696
  var T2 = sum32$1(s0_256(a), maj32(a, b, c));
@@ -19412,7 +19751,7 @@ SHA224.prototype._digest = function digest(enc) {
19412
19751
 
19413
19752
  var utils$c = utils$i;
19414
19753
  var common$1 = common$5;
19415
- var assert$9 = minimalisticAssert;
19754
+ var assert$8 = minimalisticAssert;
19416
19755
 
19417
19756
  var rotr64_hi = utils$c.rotr64_hi;
19418
19757
  var rotr64_lo = utils$c.rotr64_lo;
@@ -19547,7 +19886,7 @@ SHA512$1.prototype._update = function _update(msg, start) {
19547
19886
  var hh = this.h[14];
19548
19887
  var hl = this.h[15];
19549
19888
 
19550
- assert$9(this.k.length === W.length);
19889
+ assert$8(this.k.length === W.length);
19551
19890
  for (var i = 0; i < W.length; i += 2) {
19552
19891
  var c0_hi = hh;
19553
19892
  var c0_lo = hl;
@@ -19927,7 +20266,7 @@ var sh = [
19927
20266
  ];
19928
20267
 
19929
20268
  var utils$9 = utils$i;
19930
- var assert$8 = minimalisticAssert;
20269
+ var assert$7 = minimalisticAssert;
19931
20270
 
19932
20271
  function Hmac(hash, key, enc) {
19933
20272
  if (!(this instanceof Hmac))
@@ -19946,7 +20285,7 @@ Hmac.prototype._init = function init(key) {
19946
20285
  // Shorten key, if needed
19947
20286
  if (key.length > this.blockSize)
19948
20287
  key = new this.Hash().update(key).digest();
19949
- assert$8(key.length <= this.blockSize);
20288
+ assert$7(key.length <= this.blockSize);
19950
20289
 
19951
20290
  // Add padding to key
19952
20291
  for (var i = key.length; i < this.blockSize; i++)
@@ -20989,7 +21328,7 @@ function requireSecp256k1 () {
20989
21328
 
20990
21329
  var hash$1 = hash$2;
20991
21330
  var utils$8 = utils$n;
20992
- var assert$7 = minimalisticAssert;
21331
+ var assert$6 = minimalisticAssert;
20993
21332
 
20994
21333
  function HmacDRBG$1(options) {
20995
21334
  if (!(this instanceof HmacDRBG$1))
@@ -21008,7 +21347,7 @@ function HmacDRBG$1(options) {
21008
21347
  var entropy = utils$8.toArray(options.entropy, options.entropyEnc || 'hex');
21009
21348
  var nonce = utils$8.toArray(options.nonce, options.nonceEnc || 'hex');
21010
21349
  var pers = utils$8.toArray(options.pers, options.persEnc || 'hex');
21011
- assert$7(entropy.length >= (this.minEntropy / 8),
21350
+ assert$6(entropy.length >= (this.minEntropy / 8),
21012
21351
  'Not enough entropy. Minimum is: ' + this.minEntropy + ' bits');
21013
21352
  this._init(entropy, nonce, pers);
21014
21353
  }
@@ -21063,7 +21402,7 @@ HmacDRBG$1.prototype.reseed = function reseed(entropy, entropyEnc, add, addEnc)
21063
21402
  entropy = utils$8.toArray(entropy, entropyEnc);
21064
21403
  add = utils$8.toArray(add, addEnc);
21065
21404
 
21066
- assert$7(entropy.length >= (this.minEntropy / 8),
21405
+ assert$6(entropy.length >= (this.minEntropy / 8),
21067
21406
  'Not enough entropy. Minimum is: ' + this.minEntropy + ' bits');
21068
21407
 
21069
21408
  this._update(entropy.concat(add || []));
@@ -21101,7 +21440,7 @@ HmacDRBG$1.prototype.generate = function generate(len, enc, add, addEnc) {
21101
21440
 
21102
21441
  var BN$4 = bnExports;
21103
21442
  var utils$7 = utils$o;
21104
- var assert$6 = utils$7.assert;
21443
+ var assert$5 = utils$7.assert;
21105
21444
 
21106
21445
  function KeyPair$3(ec, options) {
21107
21446
  this.ec = ec;
@@ -21186,10 +21525,10 @@ KeyPair$3.prototype._importPublic = function _importPublic(key, enc) {
21186
21525
  // Weierstrass/Edwards points on the other hand have both `x` and
21187
21526
  // `y` coordinates.
21188
21527
  if (this.ec.curve.type === 'mont') {
21189
- assert$6(key.x, 'Need x coordinate');
21528
+ assert$5(key.x, 'Need x coordinate');
21190
21529
  } else if (this.ec.curve.type === 'short' ||
21191
21530
  this.ec.curve.type === 'edwards') {
21192
- assert$6(key.x && key.y, 'Need both x and y coordinate');
21531
+ assert$5(key.x && key.y, 'Need both x and y coordinate');
21193
21532
  }
21194
21533
  this.pub = this.ec.curve.point(key.x, key.y);
21195
21534
  return;
@@ -21200,7 +21539,7 @@ KeyPair$3.prototype._importPublic = function _importPublic(key, enc) {
21200
21539
  // ECDH
21201
21540
  KeyPair$3.prototype.derive = function derive(pub) {
21202
21541
  if(!pub.validate()) {
21203
- assert$6(pub.validate(), 'public point not validated');
21542
+ assert$5(pub.validate(), 'public point not validated');
21204
21543
  }
21205
21544
  return pub.mul(this.priv).getX();
21206
21545
  };
@@ -21222,7 +21561,7 @@ KeyPair$3.prototype.inspect = function inspect() {
21222
21561
  var BN$3 = bnExports;
21223
21562
 
21224
21563
  var utils$6 = utils$o;
21225
- var assert$5 = utils$6.assert;
21564
+ var assert$4 = utils$6.assert;
21226
21565
 
21227
21566
  function Signature$3(options, enc) {
21228
21567
  if (options instanceof Signature$3)
@@ -21231,7 +21570,7 @@ function Signature$3(options, enc) {
21231
21570
  if (this._importDER(options, enc))
21232
21571
  return;
21233
21572
 
21234
- assert$5(options.r && options.s, 'Signature without r or s');
21573
+ assert$4(options.r && options.s, 'Signature without r or s');
21235
21574
  this.r = new BN$3(options.r, 16);
21236
21575
  this.s = new BN$3(options.s, 16);
21237
21576
  if (options.recoveryParam === undefined)
@@ -21389,7 +21728,7 @@ var HmacDRBG = hmacDrbg;
21389
21728
  var utils$5 = utils$o;
21390
21729
  var curves$1 = curves$2;
21391
21730
  var rand = brorandExports;
21392
- var assert$4 = utils$5.assert;
21731
+ var assert$3 = utils$5.assert;
21393
21732
 
21394
21733
  var KeyPair$2 = key$1;
21395
21734
  var Signature$2 = signature$1;
@@ -21400,7 +21739,7 @@ function EC$1(options) {
21400
21739
 
21401
21740
  // Shortcut `elliptic.ec(curve-name)`
21402
21741
  if (typeof options === 'string') {
21403
- assert$4(Object.prototype.hasOwnProperty.call(curves$1, options),
21742
+ assert$3(Object.prototype.hasOwnProperty.call(curves$1, options),
21404
21743
  'Unknown curve ' + options);
21405
21744
 
21406
21745
  options = curves$1[options];
@@ -21578,7 +21917,7 @@ EC$1.prototype.verify = function verify(msg, signature, key, enc) {
21578
21917
  };
21579
21918
 
21580
21919
  EC$1.prototype.recoverPubKey = function(msg, signature, j, enc) {
21581
- assert$4((3 & j) === j, 'The recovery param is more than two bits');
21920
+ assert$3((3 & j) === j, 'The recovery param is more than two bits');
21582
21921
  signature = new Signature$2(signature, enc);
21583
21922
 
21584
21923
  var n = this.n;
@@ -21627,7 +21966,7 @@ EC$1.prototype.getKeyRecoveryParam = function(e, signature, Q, enc) {
21627
21966
  };
21628
21967
 
21629
21968
  var utils$4 = utils$o;
21630
- var assert$3 = utils$4.assert;
21969
+ var assert$2 = utils$4.assert;
21631
21970
  var parseBytes$2 = utils$4.parseBytes;
21632
21971
  var cachedProperty$1 = utils$4.cachedProperty;
21633
21972
 
@@ -21701,7 +22040,7 @@ cachedProperty$1(KeyPair$1, 'messagePrefix', function messagePrefix() {
21701
22040
  });
21702
22041
 
21703
22042
  KeyPair$1.prototype.sign = function sign(message) {
21704
- assert$3(this._secret, 'KeyPair can only verify');
22043
+ assert$2(this._secret, 'KeyPair can only verify');
21705
22044
  return this.eddsa.sign(message, this);
21706
22045
  };
21707
22046
 
@@ -21710,7 +22049,7 @@ KeyPair$1.prototype.verify = function verify(message, sig) {
21710
22049
  };
21711
22050
 
21712
22051
  KeyPair$1.prototype.getSecret = function getSecret(enc) {
21713
- assert$3(this._secret, 'KeyPair is public only');
22052
+ assert$2(this._secret, 'KeyPair is public only');
21714
22053
  return utils$4.encode(this.secret(), enc);
21715
22054
  };
21716
22055
 
@@ -21722,7 +22061,7 @@ var key = KeyPair$1;
21722
22061
 
21723
22062
  var BN$1 = bnExports;
21724
22063
  var utils$3 = utils$o;
21725
- var assert$2 = utils$3.assert;
22064
+ var assert$1 = utils$3.assert;
21726
22065
  var cachedProperty = utils$3.cachedProperty;
21727
22066
  var parseBytes$1 = utils$3.parseBytes;
21728
22067
 
@@ -21747,7 +22086,7 @@ function Signature$1(eddsa, sig) {
21747
22086
  };
21748
22087
  }
21749
22088
 
21750
- assert$2(sig.R && sig.S, 'Signature without R or S');
22089
+ assert$1(sig.R && sig.S, 'Signature without R or S');
21751
22090
 
21752
22091
  if (eddsa.isPoint(sig.R))
21753
22092
  this._R = sig.R;
@@ -21787,13 +22126,13 @@ var signature = Signature$1;
21787
22126
  var hash = hash$2;
21788
22127
  var curves = curves$2;
21789
22128
  var utils$2 = utils$o;
21790
- var assert$1 = utils$2.assert;
22129
+ var assert = utils$2.assert;
21791
22130
  var parseBytes = utils$2.parseBytes;
21792
22131
  var KeyPair = key;
21793
22132
  var Signature = signature;
21794
22133
 
21795
22134
  function EDDSA(curve) {
21796
- assert$1(curve === 'ed25519', 'only tested with ed25519 so far');
22135
+ assert(curve === 'ed25519', 'only tested with ed25519 so far');
21797
22136
 
21798
22137
  if (!(this instanceof EDDSA))
21799
22138
  return new EDDSA(curve);
@@ -22212,447 +22551,110 @@ var elliptic$1 = {
22212
22551
  if (s.cmp(ecparams.n) >= 0) s = new BN(0);
22213
22552
 
22214
22553
  output.set(r.toArrayLike(Uint8Array, 'be', 32), 0);
22215
- output.set(s.toArrayLike(Uint8Array, 'be', 32), 32);
22216
-
22217
- return 0
22218
- },
22219
-
22220
- ecdsaSign (obj, message, seckey, data, noncefn) {
22221
- if (noncefn) {
22222
- const _noncefn = noncefn;
22223
- noncefn = (counter) => {
22224
- const nonce = _noncefn(message, seckey, null, data, counter);
22225
-
22226
- const isValid = nonce instanceof Uint8Array && nonce.length === 32;
22227
- if (!isValid) throw new Error('This is the way')
22228
-
22229
- return new BN(nonce)
22230
- };
22231
- }
22232
-
22233
- const d = new BN(seckey);
22234
- if (d.cmp(ecparams.n) >= 0 || d.isZero()) return 1
22235
-
22236
- let sig;
22237
- try {
22238
- sig = ec.sign(message, seckey, { canonical: true, k: noncefn, pers: data });
22239
- } catch (err) {
22240
- return 1
22241
- }
22242
-
22243
- obj.signature.set(sig.r.toArrayLike(Uint8Array, 'be', 32), 0);
22244
- obj.signature.set(sig.s.toArrayLike(Uint8Array, 'be', 32), 32);
22245
- obj.recid = sig.recoveryParam;
22246
-
22247
- return 0
22248
- },
22249
-
22250
- ecdsaVerify (sig, msg32, pubkey) {
22251
- const sigObj = { r: sig.subarray(0, 32), s: sig.subarray(32, 64) };
22252
-
22253
- const sigr = new BN(sigObj.r);
22254
- const sigs = new BN(sigObj.s);
22255
- if (sigr.cmp(ecparams.n) >= 0 || sigs.cmp(ecparams.n) >= 0) return 1
22256
- if (sigs.cmp(ec.nh) === 1 || sigr.isZero() || sigs.isZero()) return 3
22257
-
22258
- const pair = loadPublicKey(pubkey);
22259
- if (pair === null) return 2
22260
-
22261
- const point = pair.getPublic();
22262
- const isValid = ec.verify(msg32, sigObj, point);
22263
- return isValid ? 0 : 3
22264
- },
22265
-
22266
- ecdsaRecover (output, sig, recid, msg32) {
22267
- const sigObj = { r: sig.slice(0, 32), s: sig.slice(32, 64) };
22268
-
22269
- const sigr = new BN(sigObj.r);
22270
- const sigs = new BN(sigObj.s);
22271
- if (sigr.cmp(ecparams.n) >= 0 || sigs.cmp(ecparams.n) >= 0) return 1
22272
-
22273
- if (sigr.isZero() || sigs.isZero()) return 2
22274
-
22275
- // Can throw `throw new Error('Unable to find sencond key candinate');`
22276
- let point;
22277
- try {
22278
- point = ec.recoverPubKey(msg32, sigObj, recid);
22279
- } catch (err) {
22280
- return 2
22281
- }
22282
-
22283
- savePublicKey(output, point);
22284
-
22285
- return 0
22286
- },
22287
-
22288
- ecdh (output, pubkey, seckey, data, hashfn, xbuf, ybuf) {
22289
- const pair = loadPublicKey(pubkey);
22290
- if (pair === null) return 1
22291
-
22292
- const scalar = new BN(seckey);
22293
- if (scalar.cmp(ecparams.n) >= 0 || scalar.isZero()) return 2
22294
-
22295
- const point = pair.getPublic().mul(scalar);
22296
-
22297
- if (hashfn === undefined) {
22298
- const data = point.encode(null, true);
22299
- const sha256 = ec.hash().update(data).digest();
22300
- for (let i = 0; i < 32; ++i) output[i] = sha256[i];
22301
- } else {
22302
- if (!xbuf) xbuf = new Uint8Array(32);
22303
- const x = point.getX().toArray('be', 32);
22304
- for (let i = 0; i < 32; ++i) xbuf[i] = x[i];
22305
-
22306
- if (!ybuf) ybuf = new Uint8Array(32);
22307
- const y = point.getY().toArray('be', 32);
22308
- for (let i = 0; i < 32; ++i) ybuf[i] = y[i];
22309
-
22310
- const hash = hashfn(xbuf, ybuf, data);
22311
-
22312
- const isValid = hash instanceof Uint8Array && hash.length === output.length;
22313
- if (!isValid) return 2
22314
-
22315
- output.set(hash);
22316
- }
22317
-
22318
- return 0
22319
- }
22320
- };
22321
-
22322
- const errors = {
22323
- IMPOSSIBLE_CASE: 'Impossible case. Please create issue.',
22324
- TWEAK_ADD:
22325
- 'The tweak was out of range or the resulted private key is invalid',
22326
- TWEAK_MUL: 'The tweak was out of range or equal to zero',
22327
- CONTEXT_RANDOMIZE_UNKNOW: 'Unknow error on context randomization',
22328
- SECKEY_INVALID: 'Private Key is invalid',
22329
- PUBKEY_PARSE: 'Public Key could not be parsed',
22330
- PUBKEY_SERIALIZE: 'Public Key serialization error',
22331
- PUBKEY_COMBINE: 'The sum of the public keys is not valid',
22332
- SIG_PARSE: 'Signature could not be parsed',
22333
- SIGN: 'The nonce generation function failed, or the private key was invalid',
22334
- RECOVER: 'Public key could not be recover',
22335
- ECDH: 'Scalar was invalid (zero or overflow)'
22336
- };
22337
-
22338
- function assert (cond, msg) {
22339
- if (!cond) throw new Error(msg)
22340
- }
22341
-
22342
- function isUint8Array (name, value, length) {
22343
- assert(value instanceof Uint8Array, `Expected ${name} to be an Uint8Array`);
22344
-
22345
- if (length !== undefined) {
22346
- if (Array.isArray(length)) {
22347
- const numbers = length.join(', ');
22348
- const msg = `Expected ${name} to be an Uint8Array with length [${numbers}]`;
22349
- assert(length.includes(value.length), msg);
22350
- } else {
22351
- const msg = `Expected ${name} to be an Uint8Array with length ${length}`;
22352
- assert(value.length === length, msg);
22353
- }
22354
- }
22355
- }
22356
-
22357
- function isCompressed (value) {
22358
- assert(toTypeString(value) === 'Boolean', 'Expected compressed to be a Boolean');
22359
- }
22360
-
22361
- function getAssertedOutput (output = (len) => new Uint8Array(len), length) {
22362
- if (typeof output === 'function') output = output(length);
22363
- isUint8Array('output', output, length);
22364
- return output
22365
- }
22366
-
22367
- function toTypeString (value) {
22368
- return Object.prototype.toString.call(value).slice(8, -1)
22369
- }
22370
-
22371
- var lib = (secp256k1) => {
22372
- return {
22373
- contextRandomize (seed) {
22374
- assert(
22375
- seed === null || seed instanceof Uint8Array,
22376
- 'Expected seed to be an Uint8Array or null'
22377
- );
22378
- if (seed !== null) isUint8Array('seed', seed, 32);
22379
-
22380
- switch (secp256k1.contextRandomize(seed)) {
22381
- case 1:
22382
- throw new Error(errors.CONTEXT_RANDOMIZE_UNKNOW)
22383
- }
22384
- },
22385
-
22386
- privateKeyVerify (seckey) {
22387
- isUint8Array('private key', seckey, 32);
22388
-
22389
- return secp256k1.privateKeyVerify(seckey) === 0
22390
- },
22391
-
22392
- privateKeyNegate (seckey) {
22393
- isUint8Array('private key', seckey, 32);
22394
-
22395
- switch (secp256k1.privateKeyNegate(seckey)) {
22396
- case 0:
22397
- return seckey
22398
- case 1:
22399
- throw new Error(errors.IMPOSSIBLE_CASE)
22400
- }
22401
- },
22402
-
22403
- privateKeyTweakAdd (seckey, tweak) {
22404
- isUint8Array('private key', seckey, 32);
22405
- isUint8Array('tweak', tweak, 32);
22406
-
22407
- switch (secp256k1.privateKeyTweakAdd(seckey, tweak)) {
22408
- case 0:
22409
- return seckey
22410
- case 1:
22411
- throw new Error(errors.TWEAK_ADD)
22412
- }
22413
- },
22414
-
22415
- privateKeyTweakMul (seckey, tweak) {
22416
- isUint8Array('private key', seckey, 32);
22417
- isUint8Array('tweak', tweak, 32);
22418
-
22419
- switch (secp256k1.privateKeyTweakMul(seckey, tweak)) {
22420
- case 0:
22421
- return seckey
22422
- case 1:
22423
- throw new Error(errors.TWEAK_MUL)
22424
- }
22425
- },
22426
-
22427
- publicKeyVerify (pubkey) {
22428
- isUint8Array('public key', pubkey, [33, 65]);
22429
-
22430
- return secp256k1.publicKeyVerify(pubkey) === 0
22431
- },
22432
-
22433
- publicKeyCreate (seckey, compressed = true, output) {
22434
- isUint8Array('private key', seckey, 32);
22435
- isCompressed(compressed);
22436
- output = getAssertedOutput(output, compressed ? 33 : 65);
22437
-
22438
- switch (secp256k1.publicKeyCreate(output, seckey)) {
22439
- case 0:
22440
- return output
22441
- case 1:
22442
- throw new Error(errors.SECKEY_INVALID)
22443
- case 2:
22444
- throw new Error(errors.PUBKEY_SERIALIZE)
22445
- }
22446
- },
22554
+ output.set(s.toArrayLike(Uint8Array, 'be', 32), 32);
22447
22555
 
22448
- publicKeyConvert (pubkey, compressed = true, output) {
22449
- isUint8Array('public key', pubkey, [33, 65]);
22450
- isCompressed(compressed);
22451
- output = getAssertedOutput(output, compressed ? 33 : 65);
22556
+ return 0
22557
+ },
22452
22558
 
22453
- switch (secp256k1.publicKeyConvert(output, pubkey)) {
22454
- case 0:
22455
- return output
22456
- case 1:
22457
- throw new Error(errors.PUBKEY_PARSE)
22458
- case 2:
22459
- throw new Error(errors.PUBKEY_SERIALIZE)
22460
- }
22461
- },
22559
+ ecdsaSign (obj, message, seckey, data, noncefn) {
22560
+ if (noncefn) {
22561
+ const _noncefn = noncefn;
22562
+ noncefn = (counter) => {
22563
+ const nonce = _noncefn(message, seckey, null, data, counter);
22462
22564
 
22463
- publicKeyNegate (pubkey, compressed = true, output) {
22464
- isUint8Array('public key', pubkey, [33, 65]);
22465
- isCompressed(compressed);
22466
- output = getAssertedOutput(output, compressed ? 33 : 65);
22565
+ const isValid = nonce instanceof Uint8Array && nonce.length === 32;
22566
+ if (!isValid) throw new Error('This is the way')
22467
22567
 
22468
- switch (secp256k1.publicKeyNegate(output, pubkey)) {
22469
- case 0:
22470
- return output
22471
- case 1:
22472
- throw new Error(errors.PUBKEY_PARSE)
22473
- case 2:
22474
- throw new Error(errors.IMPOSSIBLE_CASE)
22475
- case 3:
22476
- throw new Error(errors.PUBKEY_SERIALIZE)
22477
- }
22478
- },
22568
+ return new BN(nonce)
22569
+ };
22570
+ }
22479
22571
 
22480
- publicKeyCombine (pubkeys, compressed = true, output) {
22481
- assert(Array.isArray(pubkeys), 'Expected public keys to be an Array');
22482
- assert(pubkeys.length > 0, 'Expected public keys array will have more than zero items');
22483
- for (const pubkey of pubkeys) {
22484
- isUint8Array('public key', pubkey, [33, 65]);
22485
- }
22486
- isCompressed(compressed);
22487
- output = getAssertedOutput(output, compressed ? 33 : 65);
22572
+ const d = new BN(seckey);
22573
+ if (d.cmp(ecparams.n) >= 0 || d.isZero()) return 1
22488
22574
 
22489
- switch (secp256k1.publicKeyCombine(output, pubkeys)) {
22490
- case 0:
22491
- return output
22492
- case 1:
22493
- throw new Error(errors.PUBKEY_PARSE)
22494
- case 2:
22495
- throw new Error(errors.PUBKEY_COMBINE)
22496
- case 3:
22497
- throw new Error(errors.PUBKEY_SERIALIZE)
22498
- }
22499
- },
22575
+ let sig;
22576
+ try {
22577
+ sig = ec.sign(message, seckey, { canonical: true, k: noncefn, pers: data });
22578
+ } catch (err) {
22579
+ return 1
22580
+ }
22500
22581
 
22501
- publicKeyTweakAdd (pubkey, tweak, compressed = true, output) {
22502
- isUint8Array('public key', pubkey, [33, 65]);
22503
- isUint8Array('tweak', tweak, 32);
22504
- isCompressed(compressed);
22505
- output = getAssertedOutput(output, compressed ? 33 : 65);
22582
+ obj.signature.set(sig.r.toArrayLike(Uint8Array, 'be', 32), 0);
22583
+ obj.signature.set(sig.s.toArrayLike(Uint8Array, 'be', 32), 32);
22584
+ obj.recid = sig.recoveryParam;
22506
22585
 
22507
- switch (secp256k1.publicKeyTweakAdd(output, pubkey, tweak)) {
22508
- case 0:
22509
- return output
22510
- case 1:
22511
- throw new Error(errors.PUBKEY_PARSE)
22512
- case 2:
22513
- throw new Error(errors.TWEAK_ADD)
22514
- }
22515
- },
22586
+ return 0
22587
+ },
22516
22588
 
22517
- publicKeyTweakMul (pubkey, tweak, compressed = true, output) {
22518
- isUint8Array('public key', pubkey, [33, 65]);
22519
- isUint8Array('tweak', tweak, 32);
22520
- isCompressed(compressed);
22521
- output = getAssertedOutput(output, compressed ? 33 : 65);
22589
+ ecdsaVerify (sig, msg32, pubkey) {
22590
+ const sigObj = { r: sig.subarray(0, 32), s: sig.subarray(32, 64) };
22522
22591
 
22523
- switch (secp256k1.publicKeyTweakMul(output, pubkey, tweak)) {
22524
- case 0:
22525
- return output
22526
- case 1:
22527
- throw new Error(errors.PUBKEY_PARSE)
22528
- case 2:
22529
- throw new Error(errors.TWEAK_MUL)
22530
- }
22531
- },
22592
+ const sigr = new BN(sigObj.r);
22593
+ const sigs = new BN(sigObj.s);
22594
+ if (sigr.cmp(ecparams.n) >= 0 || sigs.cmp(ecparams.n) >= 0) return 1
22595
+ if (sigs.cmp(ec.nh) === 1 || sigr.isZero() || sigs.isZero()) return 3
22532
22596
 
22533
- signatureNormalize (sig) {
22534
- isUint8Array('signature', sig, 64);
22597
+ const pair = loadPublicKey(pubkey);
22598
+ if (pair === null) return 2
22535
22599
 
22536
- switch (secp256k1.signatureNormalize(sig)) {
22537
- case 0:
22538
- return sig
22539
- case 1:
22540
- throw new Error(errors.SIG_PARSE)
22541
- }
22542
- },
22600
+ const point = pair.getPublic();
22601
+ const isValid = ec.verify(msg32, sigObj, point);
22602
+ return isValid ? 0 : 3
22603
+ },
22543
22604
 
22544
- signatureExport (sig, output) {
22545
- isUint8Array('signature', sig, 64);
22546
- output = getAssertedOutput(output, 72);
22605
+ ecdsaRecover (output, sig, recid, msg32) {
22606
+ const sigObj = { r: sig.slice(0, 32), s: sig.slice(32, 64) };
22547
22607
 
22548
- const obj = { output, outputlen: 72 };
22549
- switch (secp256k1.signatureExport(obj, sig)) {
22550
- case 0:
22551
- return output.slice(0, obj.outputlen)
22552
- case 1:
22553
- throw new Error(errors.SIG_PARSE)
22554
- case 2:
22555
- throw new Error(errors.IMPOSSIBLE_CASE)
22556
- }
22557
- },
22608
+ const sigr = new BN(sigObj.r);
22609
+ const sigs = new BN(sigObj.s);
22610
+ if (sigr.cmp(ecparams.n) >= 0 || sigs.cmp(ecparams.n) >= 0) return 1
22558
22611
 
22559
- signatureImport (sig, output) {
22560
- isUint8Array('signature', sig);
22561
- output = getAssertedOutput(output, 64);
22612
+ if (sigr.isZero() || sigs.isZero()) return 2
22562
22613
 
22563
- switch (secp256k1.signatureImport(output, sig)) {
22564
- case 0:
22565
- return output
22566
- case 1:
22567
- throw new Error(errors.SIG_PARSE)
22568
- case 2:
22569
- throw new Error(errors.IMPOSSIBLE_CASE)
22570
- }
22571
- },
22614
+ // Can throw `throw new Error('Unable to find sencond key candinate');`
22615
+ let point;
22616
+ try {
22617
+ point = ec.recoverPubKey(msg32, sigObj, recid);
22618
+ } catch (err) {
22619
+ return 2
22620
+ }
22572
22621
 
22573
- ecdsaSign (msg32, seckey, options = {}, output) {
22574
- isUint8Array('message', msg32, 32);
22575
- isUint8Array('private key', seckey, 32);
22576
- assert(toTypeString(options) === 'Object', 'Expected options to be an Object');
22577
- if (options.data !== undefined) isUint8Array('options.data', options.data);
22578
- if (options.noncefn !== undefined) assert(toTypeString(options.noncefn) === 'Function', 'Expected options.noncefn to be a Function');
22579
- output = getAssertedOutput(output, 64);
22622
+ savePublicKey(output, point);
22580
22623
 
22581
- const obj = { signature: output, recid: null };
22582
- switch (secp256k1.ecdsaSign(obj, msg32, seckey, options.data, options.noncefn)) {
22583
- case 0:
22584
- return obj
22585
- case 1:
22586
- throw new Error(errors.SIGN)
22587
- case 2:
22588
- throw new Error(errors.IMPOSSIBLE_CASE)
22589
- }
22590
- },
22624
+ return 0
22625
+ },
22591
22626
 
22592
- ecdsaVerify (sig, msg32, pubkey) {
22593
- isUint8Array('signature', sig, 64);
22594
- isUint8Array('message', msg32, 32);
22595
- isUint8Array('public key', pubkey, [33, 65]);
22627
+ ecdh (output, pubkey, seckey, data, hashfn, xbuf, ybuf) {
22628
+ const pair = loadPublicKey(pubkey);
22629
+ if (pair === null) return 1
22596
22630
 
22597
- switch (secp256k1.ecdsaVerify(sig, msg32, pubkey)) {
22598
- case 0:
22599
- return true
22600
- case 3:
22601
- return false
22602
- case 1:
22603
- throw new Error(errors.SIG_PARSE)
22604
- case 2:
22605
- throw new Error(errors.PUBKEY_PARSE)
22606
- }
22607
- },
22631
+ const scalar = new BN(seckey);
22632
+ if (scalar.cmp(ecparams.n) >= 0 || scalar.isZero()) return 2
22608
22633
 
22609
- ecdsaRecover (sig, recid, msg32, compressed = true, output) {
22610
- isUint8Array('signature', sig, 64);
22611
- assert(
22612
- toTypeString(recid) === 'Number' &&
22613
- recid >= 0 &&
22614
- recid <= 3,
22615
- 'Expected recovery id to be a Number within interval [0, 3]'
22616
- );
22617
- isUint8Array('message', msg32, 32);
22618
- isCompressed(compressed);
22619
- output = getAssertedOutput(output, compressed ? 33 : 65);
22634
+ const point = pair.getPublic().mul(scalar);
22620
22635
 
22621
- switch (secp256k1.ecdsaRecover(output, sig, recid, msg32)) {
22622
- case 0:
22623
- return output
22624
- case 1:
22625
- throw new Error(errors.SIG_PARSE)
22626
- case 2:
22627
- throw new Error(errors.RECOVER)
22628
- case 3:
22629
- throw new Error(errors.IMPOSSIBLE_CASE)
22630
- }
22631
- },
22636
+ if (hashfn === undefined) {
22637
+ const data = point.encode(null, true);
22638
+ const sha256 = ec.hash().update(data).digest();
22639
+ for (let i = 0; i < 32; ++i) output[i] = sha256[i];
22640
+ } else {
22641
+ if (!xbuf) xbuf = new Uint8Array(32);
22642
+ const x = point.getX().toArray('be', 32);
22643
+ for (let i = 0; i < 32; ++i) xbuf[i] = x[i];
22632
22644
 
22633
- ecdh (pubkey, seckey, options = {}, output) {
22634
- isUint8Array('public key', pubkey, [33, 65]);
22635
- isUint8Array('private key', seckey, 32);
22636
- assert(toTypeString(options) === 'Object', 'Expected options to be an Object');
22637
- if (options.data !== undefined) isUint8Array('options.data', options.data);
22638
- if (options.hashfn !== undefined) {
22639
- assert(toTypeString(options.hashfn) === 'Function', 'Expected options.hashfn to be a Function');
22640
- if (options.xbuf !== undefined) isUint8Array('options.xbuf', options.xbuf, 32);
22641
- if (options.ybuf !== undefined) isUint8Array('options.ybuf', options.ybuf, 32);
22642
- isUint8Array('output', output);
22643
- } else {
22644
- output = getAssertedOutput(output, 32);
22645
- }
22645
+ if (!ybuf) ybuf = new Uint8Array(32);
22646
+ const y = point.getY().toArray('be', 32);
22647
+ for (let i = 0; i < 32; ++i) ybuf[i] = y[i];
22646
22648
 
22647
- switch (secp256k1.ecdh(output, pubkey, seckey, options.data, options.hashfn, options.xbuf, options.ybuf)) {
22648
- case 0:
22649
- return output
22650
- case 1:
22651
- throw new Error(errors.PUBKEY_PARSE)
22652
- case 2:
22653
- throw new Error(errors.ECDH)
22654
- }
22649
+ const hash = hashfn(xbuf, ybuf, data);
22650
+
22651
+ const isValid = hash instanceof Uint8Array && hash.length === output.length;
22652
+ if (!isValid) return 2
22653
+
22654
+ output.set(hash);
22655
22655
  }
22656
+
22657
+ return 0
22656
22658
  }
22657
22659
  };
22658
22660
 
@@ -27107,7 +27109,7 @@ class Identity {
27107
27109
  this.selectedAccount = new TextDecoder().decode(selected);
27108
27110
  }
27109
27111
  else {
27110
- const importee = await import(/* webpackChunkName: "generate-account" */ './index-ub31QSed.js');
27112
+ const importee = await import(/* webpackChunkName: "generate-account" */ './index-fC0k-d_O.js');
27111
27113
  const { identity, accounts } = await importee.default(password, this.network);
27112
27114
  await globalThis.accountStore.put('public', JSON.stringify({ walletId: identity.walletId }));
27113
27115
  await globalThis.walletStore.put('version', String(1));
@@ -27299,7 +27301,7 @@ class Peernet {
27299
27301
  this.root = options.root;
27300
27302
  const { RequestMessage, ResponseMessage, PeerMessage, PeerMessageResponse, PeernetMessage, DHTMessage, DHTMessageResponse, DataMessage, DataMessageResponse, PsMessage, ChatMessage, PeernetFile
27301
27303
  // FolderMessageResponse
27302
- } = await import(/* webpackChunkName: "messages" */ './messages-guyZfse6.js');
27304
+ } = await import(/* webpackChunkName: "messages" */ './messages-rdtq6jgH.js');
27303
27305
  /**
27304
27306
  * proto Object containing protos
27305
27307
  * @type {Object}
@@ -27393,7 +27395,7 @@ class Peernet {
27393
27395
  if (this.#starting || this.#started)
27394
27396
  return;
27395
27397
  this.#starting = true;
27396
- const importee = await import('./client-UOCjJBGl.js');
27398
+ const importee = await import('./client-5mPwJbpC.js');
27397
27399
  /**
27398
27400
  * @access public
27399
27401
  * @type {PeernetClient}
@@ -27550,7 +27552,7 @@ class Peernet {
27550
27552
  let providers = this.dht.providersFor(hash);
27551
27553
  // walk the network to find a provider
27552
27554
  let tries = 0;
27553
- while ((!providers && tries < 3) || (Object.keys(providers).length === 0 && tries < 3)) {
27555
+ while ((!providers && tries < 3) || (providers && Object.keys(providers).length === 0 && tries < 3)) {
27554
27556
  tries += 1;
27555
27557
  await this.walk(hash);
27556
27558
  providers = this.dht.providersFor(hash);