@powersync/web 1.21.1 → 1.22.0

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.
@@ -2467,16 +2467,16 @@ function fromByteArray (uint8) {
2467
2467
  var w = this.words[i];
2468
2468
  var word = (((w << off) | carry) & 0xffffff).toString(16);
2469
2469
  carry = (w >>> (24 - off)) & 0xffffff;
2470
- if (carry !== 0 || i !== this.length - 1) {
2471
- out = zeros[6 - word.length] + word + out;
2472
- } else {
2473
- out = word + out;
2474
- }
2475
2470
  off += 2;
2476
2471
  if (off >= 26) {
2477
2472
  off -= 26;
2478
2473
  i--;
2479
2474
  }
2475
+ if (carry !== 0 || i !== this.length - 1) {
2476
+ out = zeros[6 - word.length] + word + out;
2477
+ } else {
2478
+ out = word + out;
2479
+ }
2480
2480
  }
2481
2481
  if (carry !== 0) {
2482
2482
  out = carry.toString(16) + out;
@@ -3936,6 +3936,7 @@ function fromByteArray (uint8) {
3936
3936
  this.words[i] = carry;
3937
3937
  this.length++;
3938
3938
  }
3939
+ this.length = num === 0 ? 1 : this.length;
3939
3940
 
3940
3941
  return this;
3941
3942
  };
@@ -8861,6 +8862,7 @@ module.exports = crt;
8861
8862
  this.words[i] = carry;
8862
8863
  this.length++;
8863
8864
  }
8865
+ this.length = num === 0 ? 1 : this.length;
8864
8866
 
8865
8867
  return isNegNum ? this.ineg() : this;
8866
8868
  };
@@ -12816,6 +12818,7 @@ module.exports = verify;
12816
12818
  this.words[i] = carry;
12817
12819
  this.length++;
12818
12820
  }
12821
+ this.length = num === 0 ? 1 : this.length;
12819
12822
 
12820
12823
  return isNegNum ? this.ineg() : this;
12821
12824
  };
@@ -19032,105 +19035,174 @@ var hexSliceLookupTable = (function () {
19032
19035
  \***********************************************/
19033
19036
  /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
19034
19037
 
19035
- var Buffer = (__webpack_require__(/*! safe-buffer */ "../../node_modules/safe-buffer/index.js").Buffer)
19036
- var Transform = (__webpack_require__(/*! stream */ "../../node_modules/stream-browserify/index.js").Transform)
19037
- var StringDecoder = (__webpack_require__(/*! string_decoder */ "../../node_modules/string_decoder/lib/string_decoder.js").StringDecoder)
19038
- var inherits = __webpack_require__(/*! inherits */ "../../node_modules/inherits/inherits_browser.js")
19038
+ "use strict";
19039
19039
 
19040
- function CipherBase (hashMode) {
19041
- Transform.call(this)
19042
- this.hashMode = typeof hashMode === 'string'
19043
- if (this.hashMode) {
19044
- this[hashMode] = this._finalOrDigest
19045
- } else {
19046
- this.final = this._finalOrDigest
19047
- }
19048
- if (this._final) {
19049
- this.__final = this._final
19050
- this._final = null
19051
- }
19052
- this._decoder = null
19053
- this._encoding = null
19054
- }
19055
- inherits(CipherBase, Transform)
19056
19040
 
19057
- CipherBase.prototype.update = function (data, inputEnc, outputEnc) {
19058
- if (typeof data === 'string') {
19059
- data = Buffer.from(data, inputEnc)
19060
- }
19041
+ var Buffer = (__webpack_require__(/*! safe-buffer */ "../../node_modules/safe-buffer/index.js").Buffer);
19042
+ var Transform = (__webpack_require__(/*! stream */ "../../node_modules/stream-browserify/index.js").Transform);
19043
+ var StringDecoder = (__webpack_require__(/*! string_decoder */ "../../node_modules/string_decoder/lib/string_decoder.js").StringDecoder);
19044
+ var inherits = __webpack_require__(/*! inherits */ "../../node_modules/inherits/inherits_browser.js");
19061
19045
 
19062
- var outData = this._update(data)
19063
- if (this.hashMode) return this
19046
+ function CipherBase(hashMode) {
19047
+ Transform.call(this);
19048
+ this.hashMode = typeof hashMode === 'string';
19049
+ if (this.hashMode) {
19050
+ this[hashMode] = this._finalOrDigest;
19051
+ } else {
19052
+ this['final'] = this._finalOrDigest;
19053
+ }
19054
+ if (this._final) {
19055
+ this.__final = this._final;
19056
+ this._final = null;
19057
+ }
19058
+ this._decoder = null;
19059
+ this._encoding = null;
19060
+ }
19061
+ inherits(CipherBase, Transform);
19062
+
19063
+ var useUint8Array = typeof Uint8Array !== 'undefined';
19064
+ var useArrayBuffer = typeof ArrayBuffer !== 'undefined'
19065
+ && typeof Uint8Array !== 'undefined'
19066
+ && ArrayBuffer.isView
19067
+ && (Buffer.prototype instanceof Uint8Array || Buffer.TYPED_ARRAY_SUPPORT);
19068
+
19069
+ function toBuffer(data, encoding) {
19070
+ /*
19071
+ * No need to do anything for exact instance
19072
+ * This is only valid when safe-buffer.Buffer === buffer.Buffer, i.e. when Buffer.from/Buffer.alloc existed
19073
+ */
19074
+ if (data instanceof Buffer) {
19075
+ return data;
19076
+ }
19064
19077
 
19065
- if (outputEnc) {
19066
- outData = this._toString(outData, outputEnc)
19067
- }
19078
+ // Convert strings to Buffer
19079
+ if (typeof data === 'string') {
19080
+ return Buffer.from(data, encoding);
19081
+ }
19068
19082
 
19069
- return outData
19083
+ /*
19084
+ * Wrap any TypedArray instances and DataViews
19085
+ * Makes sense only on engines with full TypedArray support -- let Buffer detect that
19086
+ */
19087
+ if (useArrayBuffer && ArrayBuffer.isView(data)) {
19088
+ // Bug in Node.js <6.3.1, which treats this as out-of-bounds
19089
+ if (data.byteLength === 0) {
19090
+ return Buffer.alloc(0);
19091
+ }
19092
+
19093
+ var res = Buffer.from(data.buffer, data.byteOffset, data.byteLength);
19094
+ /*
19095
+ * Recheck result size, as offset/length doesn't work on Node.js <5.10
19096
+ * We just go to Uint8Array case if this fails
19097
+ */
19098
+ if (res.byteLength === data.byteLength) {
19099
+ return res;
19100
+ }
19101
+ }
19102
+
19103
+ /*
19104
+ * Uint8Array in engines where Buffer.from might not work with ArrayBuffer, just copy over
19105
+ * Doesn't make sense with other TypedArray instances
19106
+ */
19107
+ if (useUint8Array && data instanceof Uint8Array) {
19108
+ return Buffer.from(data);
19109
+ }
19110
+
19111
+ /*
19112
+ * Old Buffer polyfill on an engine that doesn't have TypedArray support
19113
+ * Also, this is from a different Buffer polyfill implementation then we have, as instanceof check failed
19114
+ * Convert to our current Buffer implementation
19115
+ */
19116
+ if (
19117
+ Buffer.isBuffer(data)
19118
+ && data.constructor
19119
+ && typeof data.constructor.isBuffer === 'function'
19120
+ && data.constructor.isBuffer(data)
19121
+ ) {
19122
+ return Buffer.from(data);
19123
+ }
19124
+
19125
+ throw new TypeError('The "data" argument must be of type string or an instance of Buffer, TypedArray, or DataView.');
19070
19126
  }
19071
19127
 
19072
- CipherBase.prototype.setAutoPadding = function () {}
19128
+ CipherBase.prototype.update = function (data, inputEnc, outputEnc) {
19129
+ var bufferData = toBuffer(data, inputEnc); // asserts correct input type
19130
+ var outData = this._update(bufferData);
19131
+ if (this.hashMode) {
19132
+ return this;
19133
+ }
19134
+
19135
+ if (outputEnc) {
19136
+ outData = this._toString(outData, outputEnc);
19137
+ }
19138
+
19139
+ return outData;
19140
+ };
19141
+
19142
+ CipherBase.prototype.setAutoPadding = function () {};
19073
19143
  CipherBase.prototype.getAuthTag = function () {
19074
- throw new Error('trying to get auth tag in unsupported state')
19075
- }
19144
+ throw new Error('trying to get auth tag in unsupported state');
19145
+ };
19076
19146
 
19077
19147
  CipherBase.prototype.setAuthTag = function () {
19078
- throw new Error('trying to set auth tag in unsupported state')
19079
- }
19148
+ throw new Error('trying to set auth tag in unsupported state');
19149
+ };
19080
19150
 
19081
19151
  CipherBase.prototype.setAAD = function () {
19082
- throw new Error('trying to set aad in unsupported state')
19083
- }
19152
+ throw new Error('trying to set aad in unsupported state');
19153
+ };
19084
19154
 
19085
19155
  CipherBase.prototype._transform = function (data, _, next) {
19086
- var err
19087
- try {
19088
- if (this.hashMode) {
19089
- this._update(data)
19090
- } else {
19091
- this.push(this._update(data))
19092
- }
19093
- } catch (e) {
19094
- err = e
19095
- } finally {
19096
- next(err)
19097
- }
19098
- }
19156
+ var err;
19157
+ try {
19158
+ if (this.hashMode) {
19159
+ this._update(data);
19160
+ } else {
19161
+ this.push(this._update(data));
19162
+ }
19163
+ } catch (e) {
19164
+ err = e;
19165
+ } finally {
19166
+ next(err);
19167
+ }
19168
+ };
19099
19169
  CipherBase.prototype._flush = function (done) {
19100
- var err
19101
- try {
19102
- this.push(this.__final())
19103
- } catch (e) {
19104
- err = e
19105
- }
19170
+ var err;
19171
+ try {
19172
+ this.push(this.__final());
19173
+ } catch (e) {
19174
+ err = e;
19175
+ }
19106
19176
 
19107
- done(err)
19108
- }
19177
+ done(err);
19178
+ };
19109
19179
  CipherBase.prototype._finalOrDigest = function (outputEnc) {
19110
- var outData = this.__final() || Buffer.alloc(0)
19111
- if (outputEnc) {
19112
- outData = this._toString(outData, outputEnc, true)
19113
- }
19114
- return outData
19115
- }
19180
+ var outData = this.__final() || Buffer.alloc(0);
19181
+ if (outputEnc) {
19182
+ outData = this._toString(outData, outputEnc, true);
19183
+ }
19184
+ return outData;
19185
+ };
19116
19186
 
19117
19187
  CipherBase.prototype._toString = function (value, enc, fin) {
19118
- if (!this._decoder) {
19119
- this._decoder = new StringDecoder(enc)
19120
- this._encoding = enc
19121
- }
19188
+ if (!this._decoder) {
19189
+ this._decoder = new StringDecoder(enc);
19190
+ this._encoding = enc;
19191
+ }
19122
19192
 
19123
- if (this._encoding !== enc) throw new Error('can\'t switch encodings')
19193
+ if (this._encoding !== enc) {
19194
+ throw new Error('can’t switch encodings');
19195
+ }
19124
19196
 
19125
- var out = this._decoder.write(value)
19126
- if (fin) {
19127
- out += this._decoder.end()
19128
- }
19197
+ var out = this._decoder.write(value);
19198
+ if (fin) {
19199
+ out += this._decoder.end();
19200
+ }
19129
19201
 
19130
- return out
19131
- }
19202
+ return out;
19203
+ };
19132
19204
 
19133
- module.exports = CipherBase
19205
+ module.exports = CipherBase;
19134
19206
 
19135
19207
 
19136
19208
  /***/ }),
@@ -19581,101 +19653,107 @@ module.exports = Hmac
19581
19653
  "use strict";
19582
19654
 
19583
19655
 
19584
- exports.randomBytes = exports.rng = exports.pseudoRandomBytes = exports.prng = __webpack_require__(/*! randombytes */ "../../node_modules/randombytes/browser.js")
19585
- exports.createHash = exports.Hash = __webpack_require__(/*! create-hash */ "../../node_modules/create-hash/browser.js")
19586
- exports.createHmac = exports.Hmac = __webpack_require__(/*! create-hmac */ "../../node_modules/create-hmac/browser.js")
19656
+ // eslint-disable-next-line no-multi-assign
19657
+ exports.randomBytes = exports.rng = exports.pseudoRandomBytes = exports.prng = __webpack_require__(/*! randombytes */ "../../node_modules/randombytes/browser.js");
19658
+
19659
+ // eslint-disable-next-line no-multi-assign
19660
+ exports.createHash = exports.Hash = __webpack_require__(/*! create-hash */ "../../node_modules/create-hash/browser.js");
19661
+
19662
+ // eslint-disable-next-line no-multi-assign
19663
+ exports.createHmac = exports.Hmac = __webpack_require__(/*! create-hmac */ "../../node_modules/create-hmac/browser.js");
19664
+
19665
+ var algos = __webpack_require__(/*! browserify-sign/algos */ "../../node_modules/browserify-sign/algos.js");
19666
+ var algoKeys = Object.keys(algos);
19667
+ var hashes = [
19668
+ 'sha1',
19669
+ 'sha224',
19670
+ 'sha256',
19671
+ 'sha384',
19672
+ 'sha512',
19673
+ 'md5',
19674
+ 'rmd160'
19675
+ ].concat(algoKeys);
19587
19676
 
19588
- var algos = __webpack_require__(/*! browserify-sign/algos */ "../../node_modules/browserify-sign/algos.js")
19589
- var algoKeys = Object.keys(algos)
19590
- var hashes = ['sha1', 'sha224', 'sha256', 'sha384', 'sha512', 'md5', 'rmd160'].concat(algoKeys)
19591
19677
  exports.getHashes = function () {
19592
- return hashes
19593
- }
19678
+ return hashes;
19679
+ };
19594
19680
 
19595
- var p = __webpack_require__(/*! pbkdf2 */ "../../node_modules/pbkdf2/browser.js")
19596
- exports.pbkdf2 = p.pbkdf2
19597
- exports.pbkdf2Sync = p.pbkdf2Sync
19681
+ var p = __webpack_require__(/*! pbkdf2 */ "../../node_modules/pbkdf2/browser.js");
19682
+ exports.pbkdf2 = p.pbkdf2;
19683
+ exports.pbkdf2Sync = p.pbkdf2Sync;
19598
19684
 
19599
- var aes = __webpack_require__(/*! browserify-cipher */ "../../node_modules/browserify-cipher/browser.js")
19685
+ var aes = __webpack_require__(/*! browserify-cipher */ "../../node_modules/browserify-cipher/browser.js");
19600
19686
 
19601
- exports.Cipher = aes.Cipher
19602
- exports.createCipher = aes.createCipher
19603
- exports.Cipheriv = aes.Cipheriv
19604
- exports.createCipheriv = aes.createCipheriv
19605
- exports.Decipher = aes.Decipher
19606
- exports.createDecipher = aes.createDecipher
19607
- exports.Decipheriv = aes.Decipheriv
19608
- exports.createDecipheriv = aes.createDecipheriv
19609
- exports.getCiphers = aes.getCiphers
19610
- exports.listCiphers = aes.listCiphers
19687
+ exports.Cipher = aes.Cipher;
19688
+ exports.createCipher = aes.createCipher;
19689
+ exports.Cipheriv = aes.Cipheriv;
19690
+ exports.createCipheriv = aes.createCipheriv;
19691
+ exports.Decipher = aes.Decipher;
19692
+ exports.createDecipher = aes.createDecipher;
19693
+ exports.Decipheriv = aes.Decipheriv;
19694
+ exports.createDecipheriv = aes.createDecipheriv;
19695
+ exports.getCiphers = aes.getCiphers;
19696
+ exports.listCiphers = aes.listCiphers;
19611
19697
 
19612
- var dh = __webpack_require__(/*! diffie-hellman */ "../../node_modules/diffie-hellman/browser.js")
19698
+ var dh = __webpack_require__(/*! diffie-hellman */ "../../node_modules/diffie-hellman/browser.js");
19613
19699
 
19614
- exports.DiffieHellmanGroup = dh.DiffieHellmanGroup
19615
- exports.createDiffieHellmanGroup = dh.createDiffieHellmanGroup
19616
- exports.getDiffieHellman = dh.getDiffieHellman
19617
- exports.createDiffieHellman = dh.createDiffieHellman
19618
- exports.DiffieHellman = dh.DiffieHellman
19700
+ exports.DiffieHellmanGroup = dh.DiffieHellmanGroup;
19701
+ exports.createDiffieHellmanGroup = dh.createDiffieHellmanGroup;
19702
+ exports.getDiffieHellman = dh.getDiffieHellman;
19703
+ exports.createDiffieHellman = dh.createDiffieHellman;
19704
+ exports.DiffieHellman = dh.DiffieHellman;
19619
19705
 
19620
- var sign = __webpack_require__(/*! browserify-sign */ "../../node_modules/browserify-sign/browser/index.js")
19706
+ var sign = __webpack_require__(/*! browserify-sign */ "../../node_modules/browserify-sign/browser/index.js");
19621
19707
 
19622
- exports.createSign = sign.createSign
19623
- exports.Sign = sign.Sign
19624
- exports.createVerify = sign.createVerify
19625
- exports.Verify = sign.Verify
19708
+ exports.createSign = sign.createSign;
19709
+ exports.Sign = sign.Sign;
19710
+ exports.createVerify = sign.createVerify;
19711
+ exports.Verify = sign.Verify;
19626
19712
 
19627
- exports.createECDH = __webpack_require__(/*! create-ecdh */ "../../node_modules/create-ecdh/browser.js")
19713
+ exports.createECDH = __webpack_require__(/*! create-ecdh */ "../../node_modules/create-ecdh/browser.js");
19628
19714
 
19629
- var publicEncrypt = __webpack_require__(/*! public-encrypt */ "../../node_modules/public-encrypt/browser.js")
19715
+ var publicEncrypt = __webpack_require__(/*! public-encrypt */ "../../node_modules/public-encrypt/browser.js");
19630
19716
 
19631
- exports.publicEncrypt = publicEncrypt.publicEncrypt
19632
- exports.privateEncrypt = publicEncrypt.privateEncrypt
19633
- exports.publicDecrypt = publicEncrypt.publicDecrypt
19634
- exports.privateDecrypt = publicEncrypt.privateDecrypt
19717
+ exports.publicEncrypt = publicEncrypt.publicEncrypt;
19718
+ exports.privateEncrypt = publicEncrypt.privateEncrypt;
19719
+ exports.publicDecrypt = publicEncrypt.publicDecrypt;
19720
+ exports.privateDecrypt = publicEncrypt.privateDecrypt;
19635
19721
 
19636
19722
  // the least I can do is make error messages for the rest of the node.js/crypto api.
19637
- // ;[
19723
+ // [
19638
19724
  // 'createCredentials'
19639
19725
  // ].forEach(function (name) {
19640
19726
  // exports[name] = function () {
19641
- // throw new Error([
19642
- // 'sorry, ' + name + ' is not implemented yet',
19643
- // 'we accept pull requests',
19644
- // 'https://github.com/crypto-browserify/crypto-browserify'
19645
- // ].join('\n'))
19646
- // }
19647
- // })
19727
+ // throw new Error('sorry, ' + name + ' is not implemented yet\nwe accept pull requests\nhttps://github.com/browserify/crypto-browserify');
19728
+ // };
19729
+ // });
19648
19730
 
19649
- var rf = __webpack_require__(/*! randomfill */ "../../node_modules/randomfill/browser.js")
19731
+ var rf = __webpack_require__(/*! randomfill */ "../../node_modules/randomfill/browser.js");
19650
19732
 
19651
- exports.randomFill = rf.randomFill
19652
- exports.randomFillSync = rf.randomFillSync
19733
+ exports.randomFill = rf.randomFill;
19734
+ exports.randomFillSync = rf.randomFillSync;
19653
19735
 
19654
19736
  exports.createCredentials = function () {
19655
- throw new Error([
19656
- 'sorry, createCredentials is not implemented yet',
19657
- 'we accept pull requests',
19658
- 'https://github.com/crypto-browserify/crypto-browserify'
19659
- ].join('\n'))
19660
- }
19737
+ throw new Error('sorry, createCredentials is not implemented yet\nwe accept pull requests\nhttps://github.com/browserify/crypto-browserify');
19738
+ };
19661
19739
 
19662
19740
  exports.constants = {
19663
- 'DH_CHECK_P_NOT_SAFE_PRIME': 2,
19664
- 'DH_CHECK_P_NOT_PRIME': 1,
19665
- 'DH_UNABLE_TO_CHECK_GENERATOR': 4,
19666
- 'DH_NOT_SUITABLE_GENERATOR': 8,
19667
- 'NPN_ENABLED': 1,
19668
- 'ALPN_ENABLED': 1,
19669
- 'RSA_PKCS1_PADDING': 1,
19670
- 'RSA_SSLV23_PADDING': 2,
19671
- 'RSA_NO_PADDING': 3,
19672
- 'RSA_PKCS1_OAEP_PADDING': 4,
19673
- 'RSA_X931_PADDING': 5,
19674
- 'RSA_PKCS1_PSS_PADDING': 6,
19675
- 'POINT_CONVERSION_COMPRESSED': 2,
19676
- 'POINT_CONVERSION_UNCOMPRESSED': 4,
19677
- 'POINT_CONVERSION_HYBRID': 6
19678
- }
19741
+ DH_CHECK_P_NOT_SAFE_PRIME: 2,
19742
+ DH_CHECK_P_NOT_PRIME: 1,
19743
+ DH_UNABLE_TO_CHECK_GENERATOR: 4,
19744
+ DH_NOT_SUITABLE_GENERATOR: 8,
19745
+ NPN_ENABLED: 1,
19746
+ ALPN_ENABLED: 1,
19747
+ RSA_PKCS1_PADDING: 1,
19748
+ RSA_SSLV23_PADDING: 2,
19749
+ RSA_NO_PADDING: 3,
19750
+ RSA_PKCS1_OAEP_PADDING: 4,
19751
+ RSA_X931_PADDING: 5,
19752
+ RSA_PKCS1_PSS_PADDING: 6,
19753
+ POINT_CONVERSION_COMPRESSED: 2,
19754
+ POINT_CONVERSION_UNCOMPRESSED: 4,
19755
+ POINT_CONVERSION_HYBRID: 6
19756
+ };
19679
19757
 
19680
19758
 
19681
19759
  /***/ }),
@@ -23095,8 +23173,27 @@ EC.prototype.genKeyPair = function genKeyPair(options) {
23095
23173
  }
23096
23174
  };
23097
23175
 
23098
- EC.prototype._truncateToN = function _truncateToN(msg, truncOnly) {
23099
- var delta = msg.byteLength() * 8 - this.n.bitLength();
23176
+ EC.prototype._truncateToN = function _truncateToN(msg, truncOnly, bitLength) {
23177
+ var byteLength;
23178
+ if (BN.isBN(msg) || typeof msg === 'number') {
23179
+ msg = new BN(msg, 16);
23180
+ byteLength = msg.byteLength();
23181
+ } else if (typeof msg === 'object') {
23182
+ // BN assumes an array-like input and asserts length
23183
+ byteLength = msg.length;
23184
+ msg = new BN(msg, 16);
23185
+ } else {
23186
+ // BN converts the value to string
23187
+ var str = msg.toString();
23188
+ // HEX encoding
23189
+ byteLength = (str.length + 1) >>> 1;
23190
+ msg = new BN(str, 16);
23191
+ }
23192
+ // Allow overriding
23193
+ if (typeof bitLength !== 'number') {
23194
+ bitLength = byteLength * 8;
23195
+ }
23196
+ var delta = bitLength - this.n.bitLength();
23100
23197
  if (delta > 0)
23101
23198
  msg = msg.ushrn(delta);
23102
23199
  if (!truncOnly && msg.cmp(this.n) >= 0)
@@ -23113,8 +23210,18 @@ EC.prototype.sign = function sign(msg, key, enc, options) {
23113
23210
  if (!options)
23114
23211
  options = {};
23115
23212
 
23213
+ if (typeof msg !== 'string' && typeof msg !== 'number' && !BN.isBN(msg)) {
23214
+ assert(typeof msg === 'object' && msg && typeof msg.length === 'number',
23215
+ 'Expected message to be an array-like, a hex string, or a BN instance');
23216
+ assert((msg.length >>> 0) === msg.length); // non-negative 32-bit integer
23217
+ for (var i = 0; i < msg.length; i++) assert((msg[i] & 255) === msg[i]);
23218
+ }
23219
+
23116
23220
  key = this.keyFromPrivate(key, enc);
23117
- msg = this._truncateToN(new BN(msg, 16));
23221
+ msg = this._truncateToN(msg, false, options.msgBitLength);
23222
+
23223
+ // Would fail further checks, but let's make the error message clear
23224
+ assert(!msg.isNeg(), 'Can not sign a negative message');
23118
23225
 
23119
23226
  // Zero-extend key to provide enough entropy
23120
23227
  var bytes = this.n.byteLength();
@@ -23123,6 +23230,9 @@ EC.prototype.sign = function sign(msg, key, enc, options) {
23123
23230
  // Zero-extend nonce to have the same byte size as N
23124
23231
  var nonce = msg.toArray('be', bytes);
23125
23232
 
23233
+ // Recheck nonce to be bijective to msg
23234
+ assert((new BN(nonce)).eq(msg), 'Can not sign message');
23235
+
23126
23236
  // Instantiate Hmac_DRBG
23127
23237
  var drbg = new HmacDRBG({
23128
23238
  hash: this.hash,
@@ -23170,8 +23280,11 @@ EC.prototype.sign = function sign(msg, key, enc, options) {
23170
23280
  }
23171
23281
  };
23172
23282
 
23173
- EC.prototype.verify = function verify(msg, signature, key, enc) {
23174
- msg = this._truncateToN(new BN(msg, 16));
23283
+ EC.prototype.verify = function verify(msg, signature, key, enc, options) {
23284
+ if (!options)
23285
+ options = {};
23286
+
23287
+ msg = this._truncateToN(msg, false, options.msgBitLength);
23175
23288
  key = this.keyFromPublic(key, enc);
23176
23289
  signature = new Signature(signature, 'hex');
23177
23290
 
@@ -23382,8 +23495,8 @@ KeyPair.prototype.sign = function sign(msg, enc, options) {
23382
23495
  return this.ec.sign(msg, this, enc, options);
23383
23496
  };
23384
23497
 
23385
- KeyPair.prototype.verify = function verify(msg, signature) {
23386
- return this.ec.verify(msg, signature, this);
23498
+ KeyPair.prototype.verify = function verify(msg, signature, options) {
23499
+ return this.ec.verify(msg, signature, this, undefined, options);
23387
23500
  };
23388
23501
 
23389
23502
  KeyPair.prototype.inspect = function inspect() {
@@ -24826,7 +24939,7 @@ utils.intFromLE = intFromLE;
24826
24939
  /***/ ((module) => {
24827
24940
 
24828
24941
  "use strict";
24829
- module.exports = /*#__PURE__*/JSON.parse('{"name":"elliptic","version":"6.5.7","description":"EC cryptography","main":"lib/elliptic.js","files":["lib"],"scripts":{"lint":"eslint lib test","lint:fix":"npm run lint -- --fix","unit":"istanbul test _mocha --reporter=spec test/index.js","test":"npm run lint && npm run unit","version":"grunt dist && git add dist/"},"repository":{"type":"git","url":"git@github.com:indutny/elliptic"},"keywords":["EC","Elliptic","curve","Cryptography"],"author":"Fedor Indutny <fedor@indutny.com>","license":"MIT","bugs":{"url":"https://github.com/indutny/elliptic/issues"},"homepage":"https://github.com/indutny/elliptic","devDependencies":{"brfs":"^2.0.2","coveralls":"^3.1.0","eslint":"^7.6.0","grunt":"^1.2.1","grunt-browserify":"^5.3.0","grunt-cli":"^1.3.2","grunt-contrib-connect":"^3.0.0","grunt-contrib-copy":"^1.0.0","grunt-contrib-uglify":"^5.0.0","grunt-mocha-istanbul":"^5.0.2","grunt-saucelabs":"^9.0.1","istanbul":"^0.4.5","mocha":"^8.0.1"},"dependencies":{"bn.js":"^4.11.9","brorand":"^1.1.0","hash.js":"^1.0.0","hmac-drbg":"^1.0.1","inherits":"^2.0.4","minimalistic-assert":"^1.0.1","minimalistic-crypto-utils":"^1.0.1"}}');
24942
+ module.exports = /*#__PURE__*/JSON.parse('{"name":"elliptic","version":"6.6.1","description":"EC cryptography","main":"lib/elliptic.js","files":["lib"],"scripts":{"lint":"eslint lib test","lint:fix":"npm run lint -- --fix","unit":"istanbul test _mocha --reporter=spec test/index.js","test":"npm run lint && npm run unit","version":"grunt dist && git add dist/"},"repository":{"type":"git","url":"git@github.com:indutny/elliptic"},"keywords":["EC","Elliptic","curve","Cryptography"],"author":"Fedor Indutny <fedor@indutny.com>","license":"MIT","bugs":{"url":"https://github.com/indutny/elliptic/issues"},"homepage":"https://github.com/indutny/elliptic","devDependencies":{"brfs":"^2.0.2","coveralls":"^3.1.0","eslint":"^7.6.0","grunt":"^1.2.1","grunt-browserify":"^5.3.0","grunt-cli":"^1.3.2","grunt-contrib-connect":"^3.0.0","grunt-contrib-copy":"^1.0.0","grunt-contrib-uglify":"^5.0.0","grunt-mocha-istanbul":"^5.0.2","grunt-saucelabs":"^9.0.1","istanbul":"^0.4.5","mocha":"^8.0.1"},"dependencies":{"bn.js":"^4.11.9","brorand":"^1.1.0","hash.js":"^1.0.0","hmac-drbg":"^1.0.1","inherits":"^2.0.4","minimalistic-assert":"^1.0.1","minimalistic-crypto-utils":"^1.0.1"}}');
24830
24943
 
24831
24944
  /***/ }),
24832
24945
 
@@ -25402,15 +25515,9 @@ module.exports = EVP_BytesToKey
25402
25515
  "use strict";
25403
25516
 
25404
25517
  var Buffer = (__webpack_require__(/*! safe-buffer */ "../../node_modules/safe-buffer/index.js").Buffer)
25405
- var Transform = (__webpack_require__(/*! readable-stream */ "../../node_modules/readable-stream/readable-browser.js").Transform)
25518
+ var Transform = (__webpack_require__(/*! stream */ "../../node_modules/stream-browserify/index.js").Transform)
25406
25519
  var inherits = __webpack_require__(/*! inherits */ "../../node_modules/inherits/inherits_browser.js")
25407
25520
 
25408
- function throwIfNotStringOrBuffer (val, prefix) {
25409
- if (!Buffer.isBuffer(val) && typeof val !== 'string') {
25410
- throw new TypeError(prefix + ' must be a string or a buffer')
25411
- }
25412
- }
25413
-
25414
25521
  function HashBase (blockSize) {
25415
25522
  Transform.call(this)
25416
25523
 
@@ -25446,10 +25553,59 @@ HashBase.prototype._flush = function (callback) {
25446
25553
  callback(error)
25447
25554
  }
25448
25555
 
25556
+ var useUint8Array = typeof Uint8Array !== 'undefined'
25557
+ var useArrayBuffer = typeof ArrayBuffer !== 'undefined' &&
25558
+ typeof Uint8Array !== 'undefined' &&
25559
+ ArrayBuffer.isView &&
25560
+ (Buffer.prototype instanceof Uint8Array || Buffer.TYPED_ARRAY_SUPPORT)
25561
+
25562
+ function toBuffer (data, encoding) {
25563
+ // No need to do anything for exact instance
25564
+ // This is only valid when safe-buffer.Buffer === buffer.Buffer, i.e. when Buffer.from/Buffer.alloc existed
25565
+ if (data instanceof Buffer) return data
25566
+
25567
+ // Convert strings to Buffer
25568
+ if (typeof data === 'string') return Buffer.from(data, encoding)
25569
+
25570
+ /*
25571
+ * Wrap any TypedArray instances and DataViews
25572
+ * Makes sense only on engines with full TypedArray support -- let Buffer detect that
25573
+ */
25574
+ if (useArrayBuffer && ArrayBuffer.isView(data)) {
25575
+ if (data.byteLength === 0) return Buffer.alloc(0) // Bug in Node.js <6.3.1, which treats this as out-of-bounds
25576
+ var res = Buffer.from(data.buffer, data.byteOffset, data.byteLength)
25577
+ // Recheck result size, as offset/length doesn't work on Node.js <5.10
25578
+ // We just go to Uint8Array case if this fails
25579
+ if (res.byteLength === data.byteLength) return res
25580
+ }
25581
+
25582
+ /*
25583
+ * Uint8Array in engines where Buffer.from might not work with ArrayBuffer, just copy over
25584
+ * Doesn't make sense with other TypedArray instances
25585
+ */
25586
+ if (useUint8Array && data instanceof Uint8Array) return Buffer.from(data)
25587
+
25588
+ /*
25589
+ * Old Buffer polyfill on an engine that doesn't have TypedArray support
25590
+ * Also, this is from a different Buffer polyfill implementation then we have, as instanceof check failed
25591
+ * Convert to our current Buffer implementation
25592
+ */
25593
+ if (
25594
+ Buffer.isBuffer(data) &&
25595
+ data.constructor &&
25596
+ typeof data.constructor.isBuffer === 'function' &&
25597
+ data.constructor.isBuffer(data)
25598
+ ) {
25599
+ return Buffer.from(data)
25600
+ }
25601
+
25602
+ throw new TypeError('The "data" argument must be of type string or an instance of Buffer, TypedArray, or DataView.')
25603
+ }
25604
+
25449
25605
  HashBase.prototype.update = function (data, encoding) {
25450
- throwIfNotStringOrBuffer(data, 'Data')
25451
25606
  if (this._finalized) throw new Error('Digest already called')
25452
- if (!Buffer.isBuffer(data)) data = Buffer.from(data, encoding)
25607
+
25608
+ data = toBuffer(data, encoding) // asserts correct input type
25453
25609
 
25454
25610
  // consume data
25455
25611
  var block = this._block
@@ -31688,25 +31844,6 @@ module.exports = {
31688
31844
  module.exports = __webpack_require__(/*! events */ "../../node_modules/events/events.js").EventEmitter;
31689
31845
 
31690
31846
 
31691
- /***/ }),
31692
-
31693
- /***/ "../../node_modules/readable-stream/readable-browser.js":
31694
- /*!**************************************************************!*\
31695
- !*** ../../node_modules/readable-stream/readable-browser.js ***!
31696
- \**************************************************************/
31697
- /***/ ((module, exports, __webpack_require__) => {
31698
-
31699
- exports = module.exports = __webpack_require__(/*! ./lib/_stream_readable.js */ "../../node_modules/readable-stream/lib/_stream_readable.js");
31700
- exports.Stream = exports;
31701
- exports.Readable = exports;
31702
- exports.Writable = __webpack_require__(/*! ./lib/_stream_writable.js */ "../../node_modules/readable-stream/lib/_stream_writable.js");
31703
- exports.Duplex = __webpack_require__(/*! ./lib/_stream_duplex.js */ "../../node_modules/readable-stream/lib/_stream_duplex.js");
31704
- exports.Transform = __webpack_require__(/*! ./lib/_stream_transform.js */ "../../node_modules/readable-stream/lib/_stream_transform.js");
31705
- exports.PassThrough = __webpack_require__(/*! ./lib/_stream_passthrough.js */ "../../node_modules/readable-stream/lib/_stream_passthrough.js");
31706
- exports.finished = __webpack_require__(/*! ./lib/internal/streams/end-of-stream.js */ "../../node_modules/readable-stream/lib/internal/streams/end-of-stream.js");
31707
- exports.pipeline = __webpack_require__(/*! ./lib/internal/streams/pipeline.js */ "../../node_modules/readable-stream/lib/internal/streams/pipeline.js");
31708
-
31709
-
31710
31847
  /***/ }),
31711
31848
 
31712
31849
  /***/ "../../node_modules/ripemd160/index.js":