@leofcoin/peernet 1.1.75 → 1.1.77

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.
@@ -8,21 +8,23 @@ if (!globalThis.DEBUG) {
8
8
  }
9
9
  }
10
10
 
11
+ const debug$1 = (target, text) => {
12
+ if (!globalThis.DEBUG && globalThis.DEBUG.length === 0) return;
13
+ if (
14
+ globalThis.DEBUG === 'true' ||
15
+ globalThis.DEBUG === true ||
16
+ globalThis.DEBUG?.indexOf(target) !== -1 ||
17
+ globalThis.DEBUG?.indexOf('*') !== -1 ||
18
+ globalThis.DEBUG?.indexOf(target.split('/')[0]) !== -1
19
+ )
20
+ if (text) console.log('\x1b[34m\x1b[1m%s', `${target}: ${text}`, '\x1b[0m');
21
+ else console.log('\x1b[34m\x1b[1m%s', `${target}`, '\x1b[0m');
22
+ };
23
+
11
24
  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);
25
+ globalThis.debug = debug$1;
26
+
27
+ globalThis.createDebugger = (target) => (text) => debug$1(target, text);
26
28
  }
27
29
 
28
30
  class LittlePubSub {
@@ -12766,6 +12768,7 @@ const nothingFoundError = (hash) => {
12766
12768
  };
12767
12769
 
12768
12770
  const isBrowser = globalThis.process?.versions?.node ? false : true;
12771
+
12769
12772
  let LeofcoinStorage$1 = class LeofcoinStorage {
12770
12773
  name;
12771
12774
  root;
@@ -12801,7 +12804,7 @@ let LeofcoinStorage$1 = class LeofcoinStorage {
12801
12804
  if (typeof key === 'object')
12802
12805
  return this.many('has', key);
12803
12806
  try {
12804
- const has = await this.db.get(new KeyPath(key));
12807
+ const has = await this.db.has(new KeyPath(key));
12805
12808
  return Boolean(has);
12806
12809
  }
12807
12810
  catch (e) {
@@ -13014,179 +13017,516 @@ var index$1 = {
13014
13017
  }
13015
13018
  };
13016
13019
 
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
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)'
13088
13034
  };
13089
13035
 
13090
- var utils$o = {};
13036
+ function assert$g (cond, msg) {
13037
+ if (!cond) throw new Error(msg)
13038
+ }
13091
13039
 
13092
- var bn = {exports: {}};
13040
+ function isUint8Array (name, value, length) {
13041
+ assert$g(value instanceof Uint8Array, `Expected ${name} to be an Uint8Array`);
13093
13042
 
13094
- 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
+ }
13095
13054
 
13096
- (function (module) {
13097
- (function (module, exports) {
13055
+ function isCompressed (value) {
13056
+ assert$g(toTypeString(value) === 'Boolean', 'Expected compressed to be a Boolean');
13057
+ }
13098
13058
 
13099
- // Utils
13100
- function assert (val, msg) {
13101
- if (!val) throw new Error(msg || 'Assertion failed');
13102
- }
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
+ }
13103
13064
 
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
- }
13065
+ function toTypeString (value) {
13066
+ return Object.prototype.toString.call(value).slice(8, -1)
13067
+ }
13113
13068
 
13114
- // 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);
13115
13077
 
13116
- function BN (number, base, endian) {
13117
- if (BN.isBN(number)) {
13118
- return number;
13119
- }
13078
+ switch (secp256k1.contextRandomize(seed)) {
13079
+ case 1:
13080
+ throw new Error(errors.CONTEXT_RANDOMIZE_UNKNOW)
13081
+ }
13082
+ },
13120
13083
 
13121
- this.negative = 0;
13122
- this.words = null;
13123
- this.length = 0;
13084
+ privateKeyVerify (seckey) {
13085
+ isUint8Array('private key', seckey, 32);
13124
13086
 
13125
- // Reduction context
13126
- this.red = null;
13087
+ return secp256k1.privateKeyVerify(seckey) === 0
13088
+ },
13127
13089
 
13128
- if (number !== null) {
13129
- if (base === 'le' || base === 'be') {
13130
- endian = base;
13131
- base = 10;
13132
- }
13090
+ privateKeyNegate (seckey) {
13091
+ isUint8Array('private key', seckey, 32);
13133
13092
 
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
- }
13093
+ switch (secp256k1.privateKeyNegate(seckey)) {
13094
+ case 0:
13095
+ return seckey
13096
+ case 1:
13097
+ throw new Error(errors.IMPOSSIBLE_CASE)
13098
+ }
13099
+ },
13142
13100
 
13143
- BN.BN = BN;
13144
- BN.wordSize = 26;
13101
+ privateKeyTweakAdd (seckey, tweak) {
13102
+ isUint8Array('private key', seckey, 32);
13103
+ isUint8Array('tweak', tweak, 32);
13145
13104
 
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
- }
13105
+ switch (secp256k1.privateKeyTweakAdd(seckey, tweak)) {
13106
+ case 0:
13107
+ return seckey
13108
+ case 1:
13109
+ throw new Error(errors.TWEAK_ADD)
13110
+ }
13111
+ },
13155
13112
 
13156
- BN.isBN = function isBN (num) {
13157
- if (num instanceof BN) {
13158
- return true;
13159
- }
13113
+ privateKeyTweakMul (seckey, tweak) {
13114
+ isUint8Array('private key', seckey, 32);
13115
+ isUint8Array('tweak', tweak, 32);
13160
13116
 
13161
- return num !== null && typeof num === 'object' &&
13162
- num.constructor.wordSize === BN.wordSize && Array.isArray(num.words);
13163
- };
13117
+ switch (secp256k1.privateKeyTweakMul(seckey, tweak)) {
13118
+ case 0:
13119
+ return seckey
13120
+ case 1:
13121
+ throw new Error(errors.TWEAK_MUL)
13122
+ }
13123
+ },
13164
13124
 
13165
- BN.max = function max (left, right) {
13166
- if (left.cmp(right) > 0) return left;
13167
- return right;
13168
- };
13125
+ publicKeyVerify (pubkey) {
13126
+ isUint8Array('public key', pubkey, [33, 65]);
13169
13127
 
13170
- BN.min = function min (left, right) {
13171
- if (left.cmp(right) < 0) return left;
13172
- return right;
13173
- };
13128
+ return secp256k1.publicKeyVerify(pubkey) === 0
13129
+ },
13174
13130
 
13175
- BN.prototype._init = function init (number, base, endian) {
13176
- if (typeof number === 'number') {
13177
- return this._initNumber(number, base, endian);
13178
- }
13131
+ publicKeyCreate (seckey, compressed = true, output) {
13132
+ isUint8Array('private key', seckey, 32);
13133
+ isCompressed(compressed);
13134
+ output = getAssertedOutput(output, compressed ? 33 : 65);
13179
13135
 
13180
- if (typeof number === 'object') {
13181
- return this._initArray(number, base, endian);
13182
- }
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
+ },
13183
13145
 
13184
- if (base === 'hex') {
13185
- base = 16;
13186
- }
13187
- 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);
13188
13150
 
13189
- number = number.toString().replace(/\s+/g, '');
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, '');
13190
13530
  var start = 0;
13191
13531
  if (number[0] === '-') {
13192
13532
  start++;
@@ -16541,14 +16881,14 @@ bn.exports;
16541
16881
 
16542
16882
  var bnExports = bn.exports;
16543
16883
 
16544
- var minimalisticAssert = assert$g;
16884
+ var minimalisticAssert = assert$f;
16545
16885
 
16546
- function assert$g(val, msg) {
16886
+ function assert$f(val, msg) {
16547
16887
  if (!val)
16548
16888
  throw new Error(msg || 'Assertion failed');
16549
16889
  }
16550
16890
 
16551
- assert$g.equal = function assertEqual(l, r, msg) {
16891
+ assert$f.equal = function assertEqual(l, r, msg) {
16552
16892
  if (l != r)
16553
16893
  throw new Error(msg || ('Assertion failed: ' + l + ' != ' + r));
16554
16894
  };
@@ -16811,7 +17151,7 @@ var BN$8 = bnExports;
16811
17151
  var utils$m = utils$o;
16812
17152
  var getNAF = utils$m.getNAF;
16813
17153
  var getJSF = utils$m.getJSF;
16814
- var assert$f = utils$m.assert;
17154
+ var assert$e = utils$m.assert;
16815
17155
 
16816
17156
  function BaseCurve(type, conf) {
16817
17157
  this.type = type;
@@ -16857,7 +17197,7 @@ BaseCurve.prototype.validate = function validate() {
16857
17197
  };
16858
17198
 
16859
17199
  BaseCurve.prototype._fixedNafMul = function _fixedNafMul(p, k) {
16860
- assert$f(p.precomputed);
17200
+ assert$e(p.precomputed);
16861
17201
  var doubles = p._getDoubles();
16862
17202
 
16863
17203
  var naf = getNAF(k, 1, this._bitLength);
@@ -16914,7 +17254,7 @@ BaseCurve.prototype._wnafMul = function _wnafMul(p, k) {
16914
17254
  if (i < 0)
16915
17255
  break;
16916
17256
  var z = naf[i];
16917
- assert$f(z !== 0);
17257
+ assert$e(z !== 0);
16918
17258
  if (p.type === 'affine') {
16919
17259
  // J +- P
16920
17260
  if (z > 0)
@@ -17082,9 +17422,9 @@ BaseCurve.prototype.decodePoint = function decodePoint(bytes, enc) {
17082
17422
  if ((bytes[0] === 0x04 || bytes[0] === 0x06 || bytes[0] === 0x07) &&
17083
17423
  bytes.length - 1 === 2 * len) {
17084
17424
  if (bytes[0] === 0x06)
17085
- assert$f(bytes[bytes.length - 1] % 2 === 0);
17425
+ assert$e(bytes[bytes.length - 1] % 2 === 0);
17086
17426
  else if (bytes[0] === 0x07)
17087
- assert$f(bytes[bytes.length - 1] % 2 === 1);
17427
+ assert$e(bytes[bytes.length - 1] % 2 === 1);
17088
17428
 
17089
17429
  var res = this.point(bytes.slice(1, 1 + len),
17090
17430
  bytes.slice(1 + len, 1 + 2 * len));
@@ -17223,7 +17563,7 @@ var BN$7 = bnExports;
17223
17563
  var inherits$3 = inherits_browserExports;
17224
17564
  var Base$2 = base;
17225
17565
 
17226
- var assert$e = utils$l.assert;
17566
+ var assert$d = utils$l.assert;
17227
17567
 
17228
17568
  function ShortCurve(conf) {
17229
17569
  Base$2.call(this, 'short', conf);
@@ -17268,7 +17608,7 @@ ShortCurve.prototype._getEndomorphism = function _getEndomorphism(conf) {
17268
17608
  lambda = lambdas[0];
17269
17609
  } else {
17270
17610
  lambda = lambdas[1];
17271
- 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);
17272
17612
  }
17273
17613
  }
17274
17614
 
@@ -18337,7 +18677,7 @@ var BN$5 = bnExports;
18337
18677
  var inherits$1 = inherits_browserExports;
18338
18678
  var Base = base;
18339
18679
 
18340
- var assert$d = utils$j.assert;
18680
+ var assert$c = utils$j.assert;
18341
18681
 
18342
18682
  function EdwardsCurve(conf) {
18343
18683
  // NOTE: Important as we are creating point in Base.call()
@@ -18354,7 +18694,7 @@ function EdwardsCurve(conf) {
18354
18694
  this.d = new BN$5(conf.d, 16).toRed(this.red);
18355
18695
  this.dd = this.d.redAdd(this.d);
18356
18696
 
18357
- assert$d(!this.twisted || this.c.fromRed().cmpn(1) === 0);
18697
+ assert$c(!this.twisted || this.c.fromRed().cmpn(1) === 0);
18358
18698
  this.oneC = (conf.c | 0) === 1;
18359
18699
  }
18360
18700
  inherits$1(EdwardsCurve, Base);
@@ -18782,7 +19122,7 @@ var hash$2 = {};
18782
19122
 
18783
19123
  var utils$i = {};
18784
19124
 
18785
- var assert$c = minimalisticAssert;
19125
+ var assert$b = minimalisticAssert;
18786
19126
  var inherits = inherits_browserExports;
18787
19127
 
18788
19128
  utils$i.inherits = inherits;
@@ -18903,7 +19243,7 @@ utils$i.zero8 = zero8;
18903
19243
 
18904
19244
  function join32(msg, start, end, endian) {
18905
19245
  var len = end - start;
18906
- assert$c(len % 4 === 0);
19246
+ assert$b(len % 4 === 0);
18907
19247
  var res = new Array(len / 4);
18908
19248
  for (var i = 0, k = start; i < res.length; i++, k += 4) {
18909
19249
  var w;
@@ -19062,7 +19402,7 @@ utils$i.shr64_lo = shr64_lo$1;
19062
19402
  var common$5 = {};
19063
19403
 
19064
19404
  var utils$h = utils$i;
19065
- var assert$b = minimalisticAssert;
19405
+ var assert$a = minimalisticAssert;
19066
19406
 
19067
19407
  function BlockHash$4() {
19068
19408
  this.pending = null;
@@ -19107,7 +19447,7 @@ BlockHash$4.prototype.update = function update(msg, enc) {
19107
19447
 
19108
19448
  BlockHash$4.prototype.digest = function digest(enc) {
19109
19449
  this.update(this._pad());
19110
- assert$b(this.pending === null);
19450
+ assert$a(this.pending === null);
19111
19451
 
19112
19452
  return this._digest(enc);
19113
19453
  };
@@ -19280,7 +19620,7 @@ SHA1.prototype._digest = function digest(enc) {
19280
19620
  var utils$e = utils$i;
19281
19621
  var common$2 = common$5;
19282
19622
  var shaCommon = common$4;
19283
- var assert$a = minimalisticAssert;
19623
+ var assert$9 = minimalisticAssert;
19284
19624
 
19285
19625
  var sum32$1 = utils$e.sum32;
19286
19626
  var sum32_4$1 = utils$e.sum32_4;
@@ -19350,7 +19690,7 @@ SHA256$1.prototype._update = function _update(msg, start) {
19350
19690
  var g = this.h[6];
19351
19691
  var h = this.h[7];
19352
19692
 
19353
- assert$a(this.k.length === W.length);
19693
+ assert$9(this.k.length === W.length);
19354
19694
  for (i = 0; i < W.length; i++) {
19355
19695
  var T1 = sum32_5(h, s1_256(e), ch32(e, f, g), this.k[i], W[i]);
19356
19696
  var T2 = sum32$1(s0_256(a), maj32(a, b, c));
@@ -19411,7 +19751,7 @@ SHA224.prototype._digest = function digest(enc) {
19411
19751
 
19412
19752
  var utils$c = utils$i;
19413
19753
  var common$1 = common$5;
19414
- var assert$9 = minimalisticAssert;
19754
+ var assert$8 = minimalisticAssert;
19415
19755
 
19416
19756
  var rotr64_hi = utils$c.rotr64_hi;
19417
19757
  var rotr64_lo = utils$c.rotr64_lo;
@@ -19546,7 +19886,7 @@ SHA512$1.prototype._update = function _update(msg, start) {
19546
19886
  var hh = this.h[14];
19547
19887
  var hl = this.h[15];
19548
19888
 
19549
- assert$9(this.k.length === W.length);
19889
+ assert$8(this.k.length === W.length);
19550
19890
  for (var i = 0; i < W.length; i += 2) {
19551
19891
  var c0_hi = hh;
19552
19892
  var c0_lo = hl;
@@ -19926,7 +20266,7 @@ var sh = [
19926
20266
  ];
19927
20267
 
19928
20268
  var utils$9 = utils$i;
19929
- var assert$8 = minimalisticAssert;
20269
+ var assert$7 = minimalisticAssert;
19930
20270
 
19931
20271
  function Hmac(hash, key, enc) {
19932
20272
  if (!(this instanceof Hmac))
@@ -19945,7 +20285,7 @@ Hmac.prototype._init = function init(key) {
19945
20285
  // Shorten key, if needed
19946
20286
  if (key.length > this.blockSize)
19947
20287
  key = new this.Hash().update(key).digest();
19948
- assert$8(key.length <= this.blockSize);
20288
+ assert$7(key.length <= this.blockSize);
19949
20289
 
19950
20290
  // Add padding to key
19951
20291
  for (var i = key.length; i < this.blockSize; i++)
@@ -20988,7 +21328,7 @@ function requireSecp256k1 () {
20988
21328
 
20989
21329
  var hash$1 = hash$2;
20990
21330
  var utils$8 = utils$n;
20991
- var assert$7 = minimalisticAssert;
21331
+ var assert$6 = minimalisticAssert;
20992
21332
 
20993
21333
  function HmacDRBG$1(options) {
20994
21334
  if (!(this instanceof HmacDRBG$1))
@@ -21007,7 +21347,7 @@ function HmacDRBG$1(options) {
21007
21347
  var entropy = utils$8.toArray(options.entropy, options.entropyEnc || 'hex');
21008
21348
  var nonce = utils$8.toArray(options.nonce, options.nonceEnc || 'hex');
21009
21349
  var pers = utils$8.toArray(options.pers, options.persEnc || 'hex');
21010
- assert$7(entropy.length >= (this.minEntropy / 8),
21350
+ assert$6(entropy.length >= (this.minEntropy / 8),
21011
21351
  'Not enough entropy. Minimum is: ' + this.minEntropy + ' bits');
21012
21352
  this._init(entropy, nonce, pers);
21013
21353
  }
@@ -21062,7 +21402,7 @@ HmacDRBG$1.prototype.reseed = function reseed(entropy, entropyEnc, add, addEnc)
21062
21402
  entropy = utils$8.toArray(entropy, entropyEnc);
21063
21403
  add = utils$8.toArray(add, addEnc);
21064
21404
 
21065
- assert$7(entropy.length >= (this.minEntropy / 8),
21405
+ assert$6(entropy.length >= (this.minEntropy / 8),
21066
21406
  'Not enough entropy. Minimum is: ' + this.minEntropy + ' bits');
21067
21407
 
21068
21408
  this._update(entropy.concat(add || []));
@@ -21100,7 +21440,7 @@ HmacDRBG$1.prototype.generate = function generate(len, enc, add, addEnc) {
21100
21440
 
21101
21441
  var BN$4 = bnExports;
21102
21442
  var utils$7 = utils$o;
21103
- var assert$6 = utils$7.assert;
21443
+ var assert$5 = utils$7.assert;
21104
21444
 
21105
21445
  function KeyPair$3(ec, options) {
21106
21446
  this.ec = ec;
@@ -21185,10 +21525,10 @@ KeyPair$3.prototype._importPublic = function _importPublic(key, enc) {
21185
21525
  // Weierstrass/Edwards points on the other hand have both `x` and
21186
21526
  // `y` coordinates.
21187
21527
  if (this.ec.curve.type === 'mont') {
21188
- assert$6(key.x, 'Need x coordinate');
21528
+ assert$5(key.x, 'Need x coordinate');
21189
21529
  } else if (this.ec.curve.type === 'short' ||
21190
21530
  this.ec.curve.type === 'edwards') {
21191
- 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');
21192
21532
  }
21193
21533
  this.pub = this.ec.curve.point(key.x, key.y);
21194
21534
  return;
@@ -21199,7 +21539,7 @@ KeyPair$3.prototype._importPublic = function _importPublic(key, enc) {
21199
21539
  // ECDH
21200
21540
  KeyPair$3.prototype.derive = function derive(pub) {
21201
21541
  if(!pub.validate()) {
21202
- assert$6(pub.validate(), 'public point not validated');
21542
+ assert$5(pub.validate(), 'public point not validated');
21203
21543
  }
21204
21544
  return pub.mul(this.priv).getX();
21205
21545
  };
@@ -21221,7 +21561,7 @@ KeyPair$3.prototype.inspect = function inspect() {
21221
21561
  var BN$3 = bnExports;
21222
21562
 
21223
21563
  var utils$6 = utils$o;
21224
- var assert$5 = utils$6.assert;
21564
+ var assert$4 = utils$6.assert;
21225
21565
 
21226
21566
  function Signature$3(options, enc) {
21227
21567
  if (options instanceof Signature$3)
@@ -21230,7 +21570,7 @@ function Signature$3(options, enc) {
21230
21570
  if (this._importDER(options, enc))
21231
21571
  return;
21232
21572
 
21233
- assert$5(options.r && options.s, 'Signature without r or s');
21573
+ assert$4(options.r && options.s, 'Signature without r or s');
21234
21574
  this.r = new BN$3(options.r, 16);
21235
21575
  this.s = new BN$3(options.s, 16);
21236
21576
  if (options.recoveryParam === undefined)
@@ -21388,7 +21728,7 @@ var HmacDRBG = hmacDrbg;
21388
21728
  var utils$5 = utils$o;
21389
21729
  var curves$1 = curves$2;
21390
21730
  var rand = brorandExports;
21391
- var assert$4 = utils$5.assert;
21731
+ var assert$3 = utils$5.assert;
21392
21732
 
21393
21733
  var KeyPair$2 = key$1;
21394
21734
  var Signature$2 = signature$1;
@@ -21399,7 +21739,7 @@ function EC$1(options) {
21399
21739
 
21400
21740
  // Shortcut `elliptic.ec(curve-name)`
21401
21741
  if (typeof options === 'string') {
21402
- assert$4(Object.prototype.hasOwnProperty.call(curves$1, options),
21742
+ assert$3(Object.prototype.hasOwnProperty.call(curves$1, options),
21403
21743
  'Unknown curve ' + options);
21404
21744
 
21405
21745
  options = curves$1[options];
@@ -21577,7 +21917,7 @@ EC$1.prototype.verify = function verify(msg, signature, key, enc) {
21577
21917
  };
21578
21918
 
21579
21919
  EC$1.prototype.recoverPubKey = function(msg, signature, j, enc) {
21580
- 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');
21581
21921
  signature = new Signature$2(signature, enc);
21582
21922
 
21583
21923
  var n = this.n;
@@ -21626,7 +21966,7 @@ EC$1.prototype.getKeyRecoveryParam = function(e, signature, Q, enc) {
21626
21966
  };
21627
21967
 
21628
21968
  var utils$4 = utils$o;
21629
- var assert$3 = utils$4.assert;
21969
+ var assert$2 = utils$4.assert;
21630
21970
  var parseBytes$2 = utils$4.parseBytes;
21631
21971
  var cachedProperty$1 = utils$4.cachedProperty;
21632
21972
 
@@ -21700,7 +22040,7 @@ cachedProperty$1(KeyPair$1, 'messagePrefix', function messagePrefix() {
21700
22040
  });
21701
22041
 
21702
22042
  KeyPair$1.prototype.sign = function sign(message) {
21703
- assert$3(this._secret, 'KeyPair can only verify');
22043
+ assert$2(this._secret, 'KeyPair can only verify');
21704
22044
  return this.eddsa.sign(message, this);
21705
22045
  };
21706
22046
 
@@ -21709,7 +22049,7 @@ KeyPair$1.prototype.verify = function verify(message, sig) {
21709
22049
  };
21710
22050
 
21711
22051
  KeyPair$1.prototype.getSecret = function getSecret(enc) {
21712
- assert$3(this._secret, 'KeyPair is public only');
22052
+ assert$2(this._secret, 'KeyPair is public only');
21713
22053
  return utils$4.encode(this.secret(), enc);
21714
22054
  };
21715
22055
 
@@ -21721,7 +22061,7 @@ var key = KeyPair$1;
21721
22061
 
21722
22062
  var BN$1 = bnExports;
21723
22063
  var utils$3 = utils$o;
21724
- var assert$2 = utils$3.assert;
22064
+ var assert$1 = utils$3.assert;
21725
22065
  var cachedProperty = utils$3.cachedProperty;
21726
22066
  var parseBytes$1 = utils$3.parseBytes;
21727
22067
 
@@ -21746,7 +22086,7 @@ function Signature$1(eddsa, sig) {
21746
22086
  };
21747
22087
  }
21748
22088
 
21749
- assert$2(sig.R && sig.S, 'Signature without R or S');
22089
+ assert$1(sig.R && sig.S, 'Signature without R or S');
21750
22090
 
21751
22091
  if (eddsa.isPoint(sig.R))
21752
22092
  this._R = sig.R;
@@ -21786,13 +22126,13 @@ var signature = Signature$1;
21786
22126
  var hash = hash$2;
21787
22127
  var curves = curves$2;
21788
22128
  var utils$2 = utils$o;
21789
- var assert$1 = utils$2.assert;
22129
+ var assert = utils$2.assert;
21790
22130
  var parseBytes = utils$2.parseBytes;
21791
22131
  var KeyPair = key;
21792
22132
  var Signature = signature;
21793
22133
 
21794
22134
  function EDDSA(curve) {
21795
- assert$1(curve === 'ed25519', 'only tested with ed25519 so far');
22135
+ assert(curve === 'ed25519', 'only tested with ed25519 so far');
21796
22136
 
21797
22137
  if (!(this instanceof EDDSA))
21798
22138
  return new EDDSA(curve);
@@ -22211,447 +22551,110 @@ var elliptic$1 = {
22211
22551
  if (s.cmp(ecparams.n) >= 0) s = new BN(0);
22212
22552
 
22213
22553
  output.set(r.toArrayLike(Uint8Array, 'be', 32), 0);
22214
- output.set(s.toArrayLike(Uint8Array, 'be', 32), 32);
22215
-
22216
- return 0
22217
- },
22218
-
22219
- ecdsaSign (obj, message, seckey, data, noncefn) {
22220
- if (noncefn) {
22221
- const _noncefn = noncefn;
22222
- noncefn = (counter) => {
22223
- const nonce = _noncefn(message, seckey, null, data, counter);
22224
-
22225
- const isValid = nonce instanceof Uint8Array && nonce.length === 32;
22226
- if (!isValid) throw new Error('This is the way')
22227
-
22228
- return new BN(nonce)
22229
- };
22230
- }
22231
-
22232
- const d = new BN(seckey);
22233
- if (d.cmp(ecparams.n) >= 0 || d.isZero()) return 1
22234
-
22235
- let sig;
22236
- try {
22237
- sig = ec.sign(message, seckey, { canonical: true, k: noncefn, pers: data });
22238
- } catch (err) {
22239
- return 1
22240
- }
22241
-
22242
- obj.signature.set(sig.r.toArrayLike(Uint8Array, 'be', 32), 0);
22243
- obj.signature.set(sig.s.toArrayLike(Uint8Array, 'be', 32), 32);
22244
- obj.recid = sig.recoveryParam;
22245
-
22246
- return 0
22247
- },
22248
-
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
- },
22554
+ output.set(s.toArrayLike(Uint8Array, 'be', 32), 32);
22446
22555
 
22447
- publicKeyConvert (pubkey, compressed = true, output) {
22448
- isUint8Array('public key', pubkey, [33, 65]);
22449
- isCompressed(compressed);
22450
- output = getAssertedOutput(output, compressed ? 33 : 65);
22556
+ return 0
22557
+ },
22451
22558
 
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
- },
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);
22461
22564
 
22462
- publicKeyNegate (pubkey, compressed = true, output) {
22463
- isUint8Array('public key', pubkey, [33, 65]);
22464
- isCompressed(compressed);
22465
- 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')
22466
22567
 
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
- },
22568
+ return new BN(nonce)
22569
+ };
22570
+ }
22478
22571
 
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);
22572
+ const d = new BN(seckey);
22573
+ if (d.cmp(ecparams.n) >= 0 || d.isZero()) return 1
22487
22574
 
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
- },
22575
+ let sig;
22576
+ try {
22577
+ sig = ec.sign(message, seckey, { canonical: true, k: noncefn, pers: data });
22578
+ } catch (err) {
22579
+ return 1
22580
+ }
22499
22581
 
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);
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;
22505
22585
 
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
- },
22586
+ return 0
22587
+ },
22515
22588
 
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);
22589
+ ecdsaVerify (sig, msg32, pubkey) {
22590
+ const sigObj = { r: sig.subarray(0, 32), s: sig.subarray(32, 64) };
22521
22591
 
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
- },
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
22531
22596
 
22532
- signatureNormalize (sig) {
22533
- isUint8Array('signature', sig, 64);
22597
+ const pair = loadPublicKey(pubkey);
22598
+ if (pair === null) return 2
22534
22599
 
22535
- switch (secp256k1.signatureNormalize(sig)) {
22536
- case 0:
22537
- return sig
22538
- case 1:
22539
- throw new Error(errors.SIG_PARSE)
22540
- }
22541
- },
22600
+ const point = pair.getPublic();
22601
+ const isValid = ec.verify(msg32, sigObj, point);
22602
+ return isValid ? 0 : 3
22603
+ },
22542
22604
 
22543
- signatureExport (sig, output) {
22544
- isUint8Array('signature', sig, 64);
22545
- output = getAssertedOutput(output, 72);
22605
+ ecdsaRecover (output, sig, recid, msg32) {
22606
+ const sigObj = { r: sig.slice(0, 32), s: sig.slice(32, 64) };
22546
22607
 
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
- },
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
22557
22611
 
22558
- signatureImport (sig, output) {
22559
- isUint8Array('signature', sig);
22560
- output = getAssertedOutput(output, 64);
22612
+ if (sigr.isZero() || sigs.isZero()) return 2
22561
22613
 
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
- },
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
+ }
22571
22621
 
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);
22622
+ savePublicKey(output, point);
22579
22623
 
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
- },
22624
+ return 0
22625
+ },
22590
22626
 
22591
- ecdsaVerify (sig, msg32, pubkey) {
22592
- isUint8Array('signature', sig, 64);
22593
- isUint8Array('message', msg32, 32);
22594
- 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
22595
22630
 
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
- },
22631
+ const scalar = new BN(seckey);
22632
+ if (scalar.cmp(ecparams.n) >= 0 || scalar.isZero()) return 2
22607
22633
 
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);
22634
+ const point = pair.getPublic().mul(scalar);
22619
22635
 
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
- },
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];
22631
22644
 
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
- }
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];
22645
22648
 
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
- }
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);
22654
22655
  }
22656
+
22657
+ return 0
22655
22658
  }
22656
22659
  };
22657
22660
 
@@ -27106,7 +27109,7 @@ class Identity {
27106
27109
  this.selectedAccount = new TextDecoder().decode(selected);
27107
27110
  }
27108
27111
  else {
27109
- const importee = await import(/* webpackChunkName: "generate-account" */ './index-JbTsvSFB.js');
27112
+ const importee = await import(/* webpackChunkName: "generate-account" */ './index-G74WLzL7.js');
27110
27113
  const { identity, accounts } = await importee.default(password, this.network);
27111
27114
  await globalThis.accountStore.put('public', JSON.stringify({ walletId: identity.walletId }));
27112
27115
  await globalThis.walletStore.put('version', String(1));
@@ -27298,7 +27301,7 @@ class Peernet {
27298
27301
  this.root = options.root;
27299
27302
  const { RequestMessage, ResponseMessage, PeerMessage, PeerMessageResponse, PeernetMessage, DHTMessage, DHTMessageResponse, DataMessage, DataMessageResponse, PsMessage, ChatMessage, PeernetFile
27300
27303
  // FolderMessageResponse
27301
- } = await import(/* webpackChunkName: "messages" */ './messages-tiGOv4p0.js');
27304
+ } = await import(/* webpackChunkName: "messages" */ './messages-lWRTai7t.js');
27302
27305
  /**
27303
27306
  * proto Object containing protos
27304
27307
  * @type {Object}
@@ -27392,7 +27395,7 @@ class Peernet {
27392
27395
  if (this.#starting || this.#started)
27393
27396
  return;
27394
27397
  this.#starting = true;
27395
- const importee = await import('./client-OL7g9E_m.js');
27398
+ const importee = await import('./client-A009z8av.js');
27396
27399
  /**
27397
27400
  * @access public
27398
27401
  * @type {PeernetClient}