@xchainjs/xchain-thorchain 2.0.2 → 2.0.3
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.
- package/lib/index.esm.js +898 -861
- package/lib/index.esm.js.map +1 -1
- package/lib/index.js +898 -861
- package/lib/index.js.map +1 -1
- package/package.json +1 -1
package/lib/index.esm.js
CHANGED
|
@@ -5511,13 +5511,13 @@ function requireMinimal () {
|
|
|
5511
5511
|
|
|
5512
5512
|
var writer = Writer$1;
|
|
5513
5513
|
|
|
5514
|
-
var util$
|
|
5514
|
+
var util$5 = requireMinimal();
|
|
5515
5515
|
|
|
5516
5516
|
var BufferWriter$1; // cyclic
|
|
5517
5517
|
|
|
5518
|
-
var LongBits$1 = util$
|
|
5519
|
-
base64 = util$
|
|
5520
|
-
utf8$1 = util$
|
|
5518
|
+
var LongBits$1 = util$5.LongBits,
|
|
5519
|
+
base64 = util$5.base64,
|
|
5520
|
+
utf8$1 = util$5.utf8;
|
|
5521
5521
|
|
|
5522
5522
|
/**
|
|
5523
5523
|
* Constructs a new writer operation instance.
|
|
@@ -5632,7 +5632,7 @@ function Writer$1() {
|
|
|
5632
5632
|
}
|
|
5633
5633
|
|
|
5634
5634
|
var create$1 = function create() {
|
|
5635
|
-
return util$
|
|
5635
|
+
return util$5.Buffer
|
|
5636
5636
|
? function create_buffer_setup() {
|
|
5637
5637
|
return (Writer$1.create = function create_buffer() {
|
|
5638
5638
|
return new BufferWriter$1();
|
|
@@ -5657,13 +5657,13 @@ Writer$1.create = create$1();
|
|
|
5657
5657
|
* @returns {Uint8Array} Buffer
|
|
5658
5658
|
*/
|
|
5659
5659
|
Writer$1.alloc = function alloc(size) {
|
|
5660
|
-
return new util$
|
|
5660
|
+
return new util$5.Array(size);
|
|
5661
5661
|
};
|
|
5662
5662
|
|
|
5663
5663
|
// Use Uint8Array buffer pool in the browser, just like node does with buffers
|
|
5664
5664
|
/* istanbul ignore else */
|
|
5665
|
-
if (util$
|
|
5666
|
-
Writer$1.alloc = util$
|
|
5665
|
+
if (util$5.Array !== Array)
|
|
5666
|
+
Writer$1.alloc = util$5.pool(Writer$1.alloc, util$5.Array.prototype.subarray);
|
|
5667
5667
|
|
|
5668
5668
|
/**
|
|
5669
5669
|
* Pushes a new operation to the queue.
|
|
@@ -5853,7 +5853,7 @@ Writer$1.prototype.sfixed64 = Writer$1.prototype.fixed64;
|
|
|
5853
5853
|
* @returns {Writer} `this`
|
|
5854
5854
|
*/
|
|
5855
5855
|
Writer$1.prototype.float = function write_float(value) {
|
|
5856
|
-
return this._push(util$
|
|
5856
|
+
return this._push(util$5.float.writeFloatLE, 4, value);
|
|
5857
5857
|
};
|
|
5858
5858
|
|
|
5859
5859
|
/**
|
|
@@ -5863,10 +5863,10 @@ Writer$1.prototype.float = function write_float(value) {
|
|
|
5863
5863
|
* @returns {Writer} `this`
|
|
5864
5864
|
*/
|
|
5865
5865
|
Writer$1.prototype.double = function write_double(value) {
|
|
5866
|
-
return this._push(util$
|
|
5866
|
+
return this._push(util$5.float.writeDoubleLE, 8, value);
|
|
5867
5867
|
};
|
|
5868
5868
|
|
|
5869
|
-
var writeBytes = util$
|
|
5869
|
+
var writeBytes = util$5.Array.prototype.set
|
|
5870
5870
|
? function writeBytes_set(val, buf, pos) {
|
|
5871
5871
|
buf.set(val, pos); // also works for plain array values
|
|
5872
5872
|
}
|
|
@@ -5885,7 +5885,7 @@ Writer$1.prototype.bytes = function write_bytes(value) {
|
|
|
5885
5885
|
var len = value.length >>> 0;
|
|
5886
5886
|
if (!len)
|
|
5887
5887
|
return this._push(writeByte, 1, 0);
|
|
5888
|
-
if (util$
|
|
5888
|
+
if (util$5.isString(value)) {
|
|
5889
5889
|
var buf = Writer$1.alloc(len = base64.length(value));
|
|
5890
5890
|
base64.decode(value, buf, 0);
|
|
5891
5891
|
value = buf;
|
|
@@ -5980,7 +5980,7 @@ var writer_buffer = BufferWriter;
|
|
|
5980
5980
|
var Writer = writer;
|
|
5981
5981
|
(BufferWriter.prototype = Object.create(Writer.prototype)).constructor = BufferWriter;
|
|
5982
5982
|
|
|
5983
|
-
var util$
|
|
5983
|
+
var util$4 = requireMinimal();
|
|
5984
5984
|
|
|
5985
5985
|
/**
|
|
5986
5986
|
* Constructs a new buffer writer instance.
|
|
@@ -5999,9 +5999,9 @@ BufferWriter._configure = function () {
|
|
|
5999
5999
|
* @param {number} size Buffer size
|
|
6000
6000
|
* @returns {Buffer} Buffer
|
|
6001
6001
|
*/
|
|
6002
|
-
BufferWriter.alloc = util$
|
|
6002
|
+
BufferWriter.alloc = util$4._Buffer_allocUnsafe;
|
|
6003
6003
|
|
|
6004
|
-
BufferWriter.writeBytesBuffer = util$
|
|
6004
|
+
BufferWriter.writeBytesBuffer = util$4.Buffer && util$4.Buffer.prototype instanceof Uint8Array && util$4.Buffer.prototype.set.name === "set"
|
|
6005
6005
|
? function writeBytesBuffer_set(val, buf, pos) {
|
|
6006
6006
|
buf.set(val, pos); // faster than copy (requires node >= 4 where Buffers extend Uint8Array and set is properly inherited)
|
|
6007
6007
|
// also works for plain array values
|
|
@@ -6020,8 +6020,8 @@ BufferWriter._configure = function () {
|
|
|
6020
6020
|
* @override
|
|
6021
6021
|
*/
|
|
6022
6022
|
BufferWriter.prototype.bytes = function write_bytes_buffer(value) {
|
|
6023
|
-
if (util$
|
|
6024
|
-
value = util$
|
|
6023
|
+
if (util$4.isString(value))
|
|
6024
|
+
value = util$4._Buffer_from(value, "base64");
|
|
6025
6025
|
var len = value.length >>> 0;
|
|
6026
6026
|
this.uint32(len);
|
|
6027
6027
|
if (len)
|
|
@@ -6031,7 +6031,7 @@ BufferWriter.prototype.bytes = function write_bytes_buffer(value) {
|
|
|
6031
6031
|
|
|
6032
6032
|
function writeStringBuffer(val, buf, pos) {
|
|
6033
6033
|
if (val.length < 40) // plain js is faster for short strings (probably due to redundant assertions)
|
|
6034
|
-
util$
|
|
6034
|
+
util$4.utf8.write(val, buf, pos);
|
|
6035
6035
|
else if (buf.utf8Write)
|
|
6036
6036
|
buf.utf8Write(val, pos);
|
|
6037
6037
|
else
|
|
@@ -6042,7 +6042,7 @@ function writeStringBuffer(val, buf, pos) {
|
|
|
6042
6042
|
* @override
|
|
6043
6043
|
*/
|
|
6044
6044
|
BufferWriter.prototype.string = function write_string_buffer(value) {
|
|
6045
|
-
var len = util$
|
|
6045
|
+
var len = util$4.Buffer.byteLength(value);
|
|
6046
6046
|
this.uint32(len);
|
|
6047
6047
|
if (len)
|
|
6048
6048
|
this._push(writeStringBuffer, len, value);
|
|
@@ -6061,12 +6061,12 @@ BufferWriter._configure();
|
|
|
6061
6061
|
|
|
6062
6062
|
var reader = Reader$1;
|
|
6063
6063
|
|
|
6064
|
-
var util$
|
|
6064
|
+
var util$3 = requireMinimal();
|
|
6065
6065
|
|
|
6066
6066
|
var BufferReader$1; // cyclic
|
|
6067
6067
|
|
|
6068
|
-
var LongBits = util$
|
|
6069
|
-
utf8 = util$
|
|
6068
|
+
var LongBits = util$3.LongBits,
|
|
6069
|
+
utf8 = util$3.utf8;
|
|
6070
6070
|
|
|
6071
6071
|
/* istanbul ignore next */
|
|
6072
6072
|
function indexOutOfRange(reader, writeLength) {
|
|
@@ -6114,10 +6114,10 @@ var create_array = typeof Uint8Array !== "undefined"
|
|
|
6114
6114
|
};
|
|
6115
6115
|
|
|
6116
6116
|
var create = function create() {
|
|
6117
|
-
return util$
|
|
6117
|
+
return util$3.Buffer
|
|
6118
6118
|
? function create_buffer_setup(buffer) {
|
|
6119
6119
|
return (Reader$1.create = function create_buffer(buffer) {
|
|
6120
|
-
return util$
|
|
6120
|
+
return util$3.Buffer.isBuffer(buffer)
|
|
6121
6121
|
? new BufferReader$1(buffer)
|
|
6122
6122
|
/* istanbul ignore next */
|
|
6123
6123
|
: create_array(buffer);
|
|
@@ -6136,7 +6136,7 @@ var create = function create() {
|
|
|
6136
6136
|
*/
|
|
6137
6137
|
Reader$1.create = create();
|
|
6138
6138
|
|
|
6139
|
-
Reader$1.prototype._slice = util$
|
|
6139
|
+
Reader$1.prototype._slice = util$3.Array.prototype.subarray || /* istanbul ignore next */ util$3.Array.prototype.slice;
|
|
6140
6140
|
|
|
6141
6141
|
/**
|
|
6142
6142
|
* Reads a varint as an unsigned 32 bit value.
|
|
@@ -6335,7 +6335,7 @@ Reader$1.prototype.float = function read_float() {
|
|
|
6335
6335
|
if (this.pos + 4 > this.len)
|
|
6336
6336
|
throw indexOutOfRange(this, 4);
|
|
6337
6337
|
|
|
6338
|
-
var value = util$
|
|
6338
|
+
var value = util$3.float.readFloatLE(this.buf, this.pos);
|
|
6339
6339
|
this.pos += 4;
|
|
6340
6340
|
return value;
|
|
6341
6341
|
};
|
|
@@ -6351,7 +6351,7 @@ Reader$1.prototype.double = function read_double() {
|
|
|
6351
6351
|
if (this.pos + 8 > this.len)
|
|
6352
6352
|
throw indexOutOfRange(this, 4);
|
|
6353
6353
|
|
|
6354
|
-
var value = util$
|
|
6354
|
+
var value = util$3.float.readDoubleLE(this.buf, this.pos);
|
|
6355
6355
|
this.pos += 8;
|
|
6356
6356
|
return value;
|
|
6357
6357
|
};
|
|
@@ -6444,8 +6444,8 @@ Reader$1._configure = function(BufferReader_) {
|
|
|
6444
6444
|
Reader$1.create = create();
|
|
6445
6445
|
BufferReader$1._configure();
|
|
6446
6446
|
|
|
6447
|
-
var fn = util$
|
|
6448
|
-
util$
|
|
6447
|
+
var fn = util$3.Long ? "toLong" : /* istanbul ignore next */ "toNumber";
|
|
6448
|
+
util$3.merge(Reader$1.prototype, {
|
|
6449
6449
|
|
|
6450
6450
|
int64: function read_int64() {
|
|
6451
6451
|
return readLongVarint.call(this)[fn](false);
|
|
@@ -6476,7 +6476,7 @@ var reader_buffer = BufferReader;
|
|
|
6476
6476
|
var Reader = reader;
|
|
6477
6477
|
(BufferReader.prototype = Object.create(Reader.prototype)).constructor = BufferReader;
|
|
6478
6478
|
|
|
6479
|
-
var util$
|
|
6479
|
+
var util$2 = requireMinimal();
|
|
6480
6480
|
|
|
6481
6481
|
/**
|
|
6482
6482
|
* Constructs a new buffer reader instance.
|
|
@@ -6497,8 +6497,8 @@ function BufferReader(buffer) {
|
|
|
6497
6497
|
|
|
6498
6498
|
BufferReader._configure = function () {
|
|
6499
6499
|
/* istanbul ignore else */
|
|
6500
|
-
if (util$
|
|
6501
|
-
BufferReader.prototype._slice = util$
|
|
6500
|
+
if (util$2.Buffer)
|
|
6501
|
+
BufferReader.prototype._slice = util$2.Buffer.prototype.slice;
|
|
6502
6502
|
};
|
|
6503
6503
|
|
|
6504
6504
|
|
|
@@ -6525,10 +6525,10 @@ var rpc = {};
|
|
|
6525
6525
|
|
|
6526
6526
|
var service$1 = Service;
|
|
6527
6527
|
|
|
6528
|
-
var util$
|
|
6528
|
+
var util$1 = requireMinimal();
|
|
6529
6529
|
|
|
6530
6530
|
// Extends EventEmitter
|
|
6531
|
-
(Service.prototype = Object.create(util$
|
|
6531
|
+
(Service.prototype = Object.create(util$1.EventEmitter.prototype)).constructor = Service;
|
|
6532
6532
|
|
|
6533
6533
|
/**
|
|
6534
6534
|
* A service method callback as used by {@link rpc.ServiceMethod|ServiceMethod}.
|
|
@@ -6568,7 +6568,7 @@ function Service(rpcImpl, requestDelimited, responseDelimited) {
|
|
|
6568
6568
|
if (typeof rpcImpl !== "function")
|
|
6569
6569
|
throw TypeError("rpcImpl must be a function");
|
|
6570
6570
|
|
|
6571
|
-
util$
|
|
6571
|
+
util$1.EventEmitter.call(this);
|
|
6572
6572
|
|
|
6573
6573
|
/**
|
|
6574
6574
|
* RPC implementation. Becomes `null` once the service is ended.
|
|
@@ -6607,7 +6607,7 @@ Service.prototype.rpcCall = function rpcCall(method, requestCtor, responseCtor,
|
|
|
6607
6607
|
|
|
6608
6608
|
var self = this;
|
|
6609
6609
|
if (!callback)
|
|
6610
|
-
return util$
|
|
6610
|
+
return util$1.asPromise(rpcCall, self, method, requestCtor, responseCtor, request);
|
|
6611
6611
|
|
|
6612
6612
|
if (!self.rpcImpl) {
|
|
6613
6613
|
setTimeout(function() { callback(Error("already ended")); }, 0);
|
|
@@ -115180,20 +115180,25 @@ function requireBlowfish () {
|
|
|
115180
115180
|
|
|
115181
115181
|
cryptoJs.exports;
|
|
115182
115182
|
|
|
115183
|
-
|
|
115184
|
-
(function (root, factory, undef) {
|
|
115185
|
-
{
|
|
115186
|
-
// CommonJS
|
|
115187
|
-
module.exports = factory(requireCore$1(), requireX64Core(), requireLibTypedarrays(), requireEncUtf16(), requireEncBase64(), requireEncBase64url(), requireMd5(), requireSha1(), requireSha256(), requireSha224(), requireSha512(), requireSha384(), requireSha3(), requireRipemd160(), requireHmac(), requirePbkdf2(), requireEvpkdf(), requireCipherCore(), requireModeCfb(), requireModeCtr(), requireModeCtrGladman(), requireModeOfb(), requireModeEcb(), requirePadAnsix923(), requirePadIso10126(), requirePadIso97971(), requirePadZeropadding(), requirePadNopadding(), requireFormatHex(), requireAes(), requireTripledes(), requireRc4(), requireRabbit(), requireRabbitLegacy(), requireBlowfish());
|
|
115188
|
-
}
|
|
115189
|
-
}(commonjsGlobal$1, function (CryptoJS) {
|
|
115183
|
+
var hasRequiredCryptoJs;
|
|
115190
115184
|
|
|
115191
|
-
|
|
115185
|
+
function requireCryptoJs () {
|
|
115186
|
+
if (hasRequiredCryptoJs) return cryptoJs.exports;
|
|
115187
|
+
hasRequiredCryptoJs = 1;
|
|
115188
|
+
(function (module, exports) {
|
|
115189
|
+
(function (root, factory, undef) {
|
|
115190
|
+
{
|
|
115191
|
+
// CommonJS
|
|
115192
|
+
module.exports = factory(requireCore$1(), requireX64Core(), requireLibTypedarrays(), requireEncUtf16(), requireEncBase64(), requireEncBase64url(), requireMd5(), requireSha1(), requireSha256(), requireSha224(), requireSha512(), requireSha384(), requireSha3(), requireRipemd160(), requireHmac(), requirePbkdf2(), requireEvpkdf(), requireCipherCore(), requireModeCfb(), requireModeCtr(), requireModeCtrGladman(), requireModeOfb(), requireModeEcb(), requirePadAnsix923(), requirePadIso10126(), requirePadIso97971(), requirePadZeropadding(), requirePadNopadding(), requireFormatHex(), requireAes(), requireTripledes(), requireRc4(), requireRabbit(), requireRabbitLegacy(), requireBlowfish());
|
|
115193
|
+
}
|
|
115194
|
+
}(commonjsGlobal$1, function (CryptoJS) {
|
|
115192
115195
|
|
|
115193
|
-
|
|
115194
|
-
} (cryptoJs, cryptoJs.exports));
|
|
115196
|
+
return CryptoJS;
|
|
115195
115197
|
|
|
115196
|
-
|
|
115198
|
+
}));
|
|
115199
|
+
} (cryptoJs, cryptoJs.exports));
|
|
115200
|
+
return cryptoJs.exports;
|
|
115201
|
+
}
|
|
115197
115202
|
|
|
115198
115203
|
var utility = {};
|
|
115199
115204
|
|
|
@@ -117698,826 +117703,858 @@ function requireUtility () {
|
|
|
117698
117703
|
return utility;
|
|
117699
117704
|
}
|
|
117700
117705
|
|
|
117701
|
-
|
|
117702
|
-
|
|
117703
|
-
// For convenience, let people hash a string, not just a Uint8Array
|
|
117704
|
-
function normalizeInput (input) {
|
|
117705
|
-
let ret;
|
|
117706
|
-
if (input instanceof Uint8Array) {
|
|
117707
|
-
ret = input;
|
|
117708
|
-
} else if (typeof input === 'string') {
|
|
117709
|
-
const encoder = new TextEncoder();
|
|
117710
|
-
ret = encoder.encode(input);
|
|
117711
|
-
} else {
|
|
117712
|
-
throw new Error(ERROR_MSG_INPUT)
|
|
117713
|
-
}
|
|
117714
|
-
return ret
|
|
117715
|
-
}
|
|
117716
|
-
|
|
117717
|
-
// Converts a Uint8Array to a hexadecimal string
|
|
117718
|
-
// For example, toHex([255, 0, 255]) returns "ff00ff"
|
|
117719
|
-
function toHex (bytes) {
|
|
117720
|
-
return Array.prototype.map
|
|
117721
|
-
.call(bytes, function (n) {
|
|
117722
|
-
return (n < 16 ? '0' : '') + n.toString(16)
|
|
117723
|
-
})
|
|
117724
|
-
.join('')
|
|
117725
|
-
}
|
|
117726
|
-
|
|
117727
|
-
// Converts any value in [0...2^32-1] to an 8-character hex string
|
|
117728
|
-
function uint32ToHex (val) {
|
|
117729
|
-
return (0x100000000 + val).toString(16).substring(1)
|
|
117730
|
-
}
|
|
117731
|
-
|
|
117732
|
-
// For debugging: prints out hash state in the same format as the RFC
|
|
117733
|
-
// sample computation exactly, so that you can diff
|
|
117734
|
-
function debugPrint (label, arr, size) {
|
|
117735
|
-
let msg = '\n' + label + ' = ';
|
|
117736
|
-
for (let i = 0; i < arr.length; i += 2) {
|
|
117737
|
-
if (size === 32) {
|
|
117738
|
-
msg += uint32ToHex(arr[i]).toUpperCase();
|
|
117739
|
-
msg += ' ';
|
|
117740
|
-
msg += uint32ToHex(arr[i + 1]).toUpperCase();
|
|
117741
|
-
} else if (size === 64) {
|
|
117742
|
-
msg += uint32ToHex(arr[i + 1]).toUpperCase();
|
|
117743
|
-
msg += uint32ToHex(arr[i]).toUpperCase();
|
|
117744
|
-
} else throw new Error('Invalid size ' + size)
|
|
117745
|
-
if (i % 6 === 4) {
|
|
117746
|
-
msg += '\n' + new Array(label.length + 4).join(' ');
|
|
117747
|
-
} else if (i < arr.length - 2) {
|
|
117748
|
-
msg += ' ';
|
|
117749
|
-
}
|
|
117750
|
-
}
|
|
117751
|
-
console.log(msg);
|
|
117752
|
-
}
|
|
117753
|
-
|
|
117754
|
-
// For performance testing: generates N bytes of input, hashes M times
|
|
117755
|
-
// Measures and prints MB/second hash performance each time
|
|
117756
|
-
function testSpeed (hashFn, N, M) {
|
|
117757
|
-
let startMs = new Date().getTime();
|
|
117758
|
-
|
|
117759
|
-
const input = new Uint8Array(N);
|
|
117760
|
-
for (let i = 0; i < N; i++) {
|
|
117761
|
-
input[i] = i % 256;
|
|
117762
|
-
}
|
|
117763
|
-
const genMs = new Date().getTime();
|
|
117764
|
-
console.log('Generated random input in ' + (genMs - startMs) + 'ms');
|
|
117765
|
-
startMs = genMs;
|
|
117766
|
-
|
|
117767
|
-
for (let i = 0; i < M; i++) {
|
|
117768
|
-
const hashHex = hashFn(input);
|
|
117769
|
-
const hashMs = new Date().getTime();
|
|
117770
|
-
const ms = hashMs - startMs;
|
|
117771
|
-
startMs = hashMs;
|
|
117772
|
-
console.log('Hashed in ' + ms + 'ms: ' + hashHex.substring(0, 20) + '...');
|
|
117773
|
-
console.log(
|
|
117774
|
-
Math.round((N / (1 << 20) / (ms / 1000)) * 100) / 100 + ' MB PER SECOND'
|
|
117775
|
-
);
|
|
117776
|
-
}
|
|
117777
|
-
}
|
|
117778
|
-
|
|
117779
|
-
var util$2 = {
|
|
117780
|
-
normalizeInput: normalizeInput,
|
|
117781
|
-
toHex: toHex,
|
|
117782
|
-
debugPrint: debugPrint,
|
|
117783
|
-
testSpeed: testSpeed
|
|
117784
|
-
};
|
|
117706
|
+
var util;
|
|
117707
|
+
var hasRequiredUtil;
|
|
117785
117708
|
|
|
117786
|
-
|
|
117787
|
-
|
|
117788
|
-
|
|
117789
|
-
|
|
117790
|
-
const util$1 = util$2;
|
|
117791
|
-
|
|
117792
|
-
// 64-bit unsigned addition
|
|
117793
|
-
// Sets v[a,a+1] += v[b,b+1]
|
|
117794
|
-
// v should be a Uint32Array
|
|
117795
|
-
function ADD64AA (v, a, b) {
|
|
117796
|
-
const o0 = v[a] + v[b];
|
|
117797
|
-
let o1 = v[a + 1] + v[b + 1];
|
|
117798
|
-
if (o0 >= 0x100000000) {
|
|
117799
|
-
o1++;
|
|
117800
|
-
}
|
|
117801
|
-
v[a] = o0;
|
|
117802
|
-
v[a + 1] = o1;
|
|
117803
|
-
}
|
|
117804
|
-
|
|
117805
|
-
// 64-bit unsigned addition
|
|
117806
|
-
// Sets v[a,a+1] += b
|
|
117807
|
-
// b0 is the low 32 bits of b, b1 represents the high 32 bits
|
|
117808
|
-
function ADD64AC (v, a, b0, b1) {
|
|
117809
|
-
let o0 = v[a] + b0;
|
|
117810
|
-
if (b0 < 0) {
|
|
117811
|
-
o0 += 0x100000000;
|
|
117812
|
-
}
|
|
117813
|
-
let o1 = v[a + 1] + b1;
|
|
117814
|
-
if (o0 >= 0x100000000) {
|
|
117815
|
-
o1++;
|
|
117816
|
-
}
|
|
117817
|
-
v[a] = o0;
|
|
117818
|
-
v[a + 1] = o1;
|
|
117819
|
-
}
|
|
117820
|
-
|
|
117821
|
-
// Little-endian byte access
|
|
117822
|
-
function B2B_GET32 (arr, i) {
|
|
117823
|
-
return arr[i] ^ (arr[i + 1] << 8) ^ (arr[i + 2] << 16) ^ (arr[i + 3] << 24)
|
|
117824
|
-
}
|
|
117825
|
-
|
|
117826
|
-
// G Mixing function
|
|
117827
|
-
// The ROTRs are inlined for speed
|
|
117828
|
-
function B2B_G (a, b, c, d, ix, iy) {
|
|
117829
|
-
const x0 = m$1[ix];
|
|
117830
|
-
const x1 = m$1[ix + 1];
|
|
117831
|
-
const y0 = m$1[iy];
|
|
117832
|
-
const y1 = m$1[iy + 1];
|
|
117833
|
-
|
|
117834
|
-
ADD64AA(v$1, a, b); // v[a,a+1] += v[b,b+1] ... in JS we must store a uint64 as two uint32s
|
|
117835
|
-
ADD64AC(v$1, a, x0, x1); // v[a, a+1] += x ... x0 is the low 32 bits of x, x1 is the high 32 bits
|
|
117836
|
-
|
|
117837
|
-
// v[d,d+1] = (v[d,d+1] xor v[a,a+1]) rotated to the right by 32 bits
|
|
117838
|
-
let xor0 = v$1[d] ^ v$1[a];
|
|
117839
|
-
let xor1 = v$1[d + 1] ^ v$1[a + 1];
|
|
117840
|
-
v$1[d] = xor1;
|
|
117841
|
-
v$1[d + 1] = xor0;
|
|
117842
|
-
|
|
117843
|
-
ADD64AA(v$1, c, d);
|
|
117844
|
-
|
|
117845
|
-
// v[b,b+1] = (v[b,b+1] xor v[c,c+1]) rotated right by 24 bits
|
|
117846
|
-
xor0 = v$1[b] ^ v$1[c];
|
|
117847
|
-
xor1 = v$1[b + 1] ^ v$1[c + 1];
|
|
117848
|
-
v$1[b] = (xor0 >>> 24) ^ (xor1 << 8);
|
|
117849
|
-
v$1[b + 1] = (xor1 >>> 24) ^ (xor0 << 8);
|
|
117850
|
-
|
|
117851
|
-
ADD64AA(v$1, a, b);
|
|
117852
|
-
ADD64AC(v$1, a, y0, y1);
|
|
117853
|
-
|
|
117854
|
-
// v[d,d+1] = (v[d,d+1] xor v[a,a+1]) rotated right by 16 bits
|
|
117855
|
-
xor0 = v$1[d] ^ v$1[a];
|
|
117856
|
-
xor1 = v$1[d + 1] ^ v$1[a + 1];
|
|
117857
|
-
v$1[d] = (xor0 >>> 16) ^ (xor1 << 16);
|
|
117858
|
-
v$1[d + 1] = (xor1 >>> 16) ^ (xor0 << 16);
|
|
117859
|
-
|
|
117860
|
-
ADD64AA(v$1, c, d);
|
|
117861
|
-
|
|
117862
|
-
// v[b,b+1] = (v[b,b+1] xor v[c,c+1]) rotated right by 63 bits
|
|
117863
|
-
xor0 = v$1[b] ^ v$1[c];
|
|
117864
|
-
xor1 = v$1[b + 1] ^ v$1[c + 1];
|
|
117865
|
-
v$1[b] = (xor1 >>> 31) ^ (xor0 << 1);
|
|
117866
|
-
v$1[b + 1] = (xor0 >>> 31) ^ (xor1 << 1);
|
|
117867
|
-
}
|
|
117868
|
-
|
|
117869
|
-
// Initialization Vector
|
|
117870
|
-
const BLAKE2B_IV32 = new Uint32Array([
|
|
117871
|
-
0xf3bcc908, 0x6a09e667, 0x84caa73b, 0xbb67ae85, 0xfe94f82b, 0x3c6ef372,
|
|
117872
|
-
0x5f1d36f1, 0xa54ff53a, 0xade682d1, 0x510e527f, 0x2b3e6c1f, 0x9b05688c,
|
|
117873
|
-
0xfb41bd6b, 0x1f83d9ab, 0x137e2179, 0x5be0cd19
|
|
117874
|
-
]);
|
|
117709
|
+
function requireUtil () {
|
|
117710
|
+
if (hasRequiredUtil) return util;
|
|
117711
|
+
hasRequiredUtil = 1;
|
|
117712
|
+
const ERROR_MSG_INPUT = 'Input must be an string, Buffer or Uint8Array';
|
|
117875
117713
|
|
|
117876
|
-
|
|
117877
|
-
|
|
117878
|
-
|
|
117879
|
-
|
|
117880
|
-
|
|
117881
|
-
|
|
117882
|
-
|
|
117883
|
-
|
|
117884
|
-
|
|
117885
|
-
|
|
117886
|
-
|
|
117714
|
+
// For convenience, let people hash a string, not just a Uint8Array
|
|
117715
|
+
function normalizeInput (input) {
|
|
117716
|
+
let ret;
|
|
117717
|
+
if (input instanceof Uint8Array) {
|
|
117718
|
+
ret = input;
|
|
117719
|
+
} else if (typeof input === 'string') {
|
|
117720
|
+
const encoder = new TextEncoder();
|
|
117721
|
+
ret = encoder.encode(input);
|
|
117722
|
+
} else {
|
|
117723
|
+
throw new Error(ERROR_MSG_INPUT)
|
|
117724
|
+
}
|
|
117725
|
+
return ret
|
|
117726
|
+
}
|
|
117727
|
+
|
|
117728
|
+
// Converts a Uint8Array to a hexadecimal string
|
|
117729
|
+
// For example, toHex([255, 0, 255]) returns "ff00ff"
|
|
117730
|
+
function toHex (bytes) {
|
|
117731
|
+
return Array.prototype.map
|
|
117732
|
+
.call(bytes, function (n) {
|
|
117733
|
+
return (n < 16 ? '0' : '') + n.toString(16)
|
|
117734
|
+
})
|
|
117735
|
+
.join('')
|
|
117736
|
+
}
|
|
117737
|
+
|
|
117738
|
+
// Converts any value in [0...2^32-1] to an 8-character hex string
|
|
117739
|
+
function uint32ToHex (val) {
|
|
117740
|
+
return (0x100000000 + val).toString(16).substring(1)
|
|
117741
|
+
}
|
|
117742
|
+
|
|
117743
|
+
// For debugging: prints out hash state in the same format as the RFC
|
|
117744
|
+
// sample computation exactly, so that you can diff
|
|
117745
|
+
function debugPrint (label, arr, size) {
|
|
117746
|
+
let msg = '\n' + label + ' = ';
|
|
117747
|
+
for (let i = 0; i < arr.length; i += 2) {
|
|
117748
|
+
if (size === 32) {
|
|
117749
|
+
msg += uint32ToHex(arr[i]).toUpperCase();
|
|
117750
|
+
msg += ' ';
|
|
117751
|
+
msg += uint32ToHex(arr[i + 1]).toUpperCase();
|
|
117752
|
+
} else if (size === 64) {
|
|
117753
|
+
msg += uint32ToHex(arr[i + 1]).toUpperCase();
|
|
117754
|
+
msg += uint32ToHex(arr[i]).toUpperCase();
|
|
117755
|
+
} else throw new Error('Invalid size ' + size)
|
|
117756
|
+
if (i % 6 === 4) {
|
|
117757
|
+
msg += '\n' + new Array(label.length + 4).join(' ');
|
|
117758
|
+
} else if (i < arr.length - 2) {
|
|
117759
|
+
msg += ' ';
|
|
117760
|
+
}
|
|
117761
|
+
}
|
|
117762
|
+
console.log(msg);
|
|
117763
|
+
}
|
|
117887
117764
|
|
|
117888
|
-
//
|
|
117889
|
-
//
|
|
117890
|
-
|
|
117891
|
-
|
|
117892
|
-
SIGMA8.map(function (x) {
|
|
117893
|
-
return x * 2
|
|
117894
|
-
})
|
|
117895
|
-
);
|
|
117765
|
+
// For performance testing: generates N bytes of input, hashes M times
|
|
117766
|
+
// Measures and prints MB/second hash performance each time
|
|
117767
|
+
function testSpeed (hashFn, N, M) {
|
|
117768
|
+
let startMs = new Date().getTime();
|
|
117896
117769
|
|
|
117897
|
-
|
|
117898
|
-
|
|
117899
|
-
|
|
117900
|
-
|
|
117901
|
-
|
|
117902
|
-
|
|
117903
|
-
|
|
117904
|
-
|
|
117905
|
-
|
|
117906
|
-
|
|
117907
|
-
|
|
117908
|
-
|
|
117909
|
-
|
|
117910
|
-
|
|
117911
|
-
|
|
117912
|
-
|
|
117913
|
-
|
|
117914
|
-
|
|
117915
|
-
|
|
117916
|
-
if (last) {
|
|
117917
|
-
v$1[28] = ~v$1[28];
|
|
117918
|
-
v$1[29] = ~v$1[29];
|
|
117919
|
-
}
|
|
117920
|
-
|
|
117921
|
-
// get little-endian words
|
|
117922
|
-
for (i = 0; i < 32; i++) {
|
|
117923
|
-
m$1[i] = B2B_GET32(ctx.b, 4 * i);
|
|
117924
|
-
}
|
|
117925
|
-
|
|
117926
|
-
// twelve rounds of mixing
|
|
117927
|
-
// uncomment the DebugPrint calls to log the computation
|
|
117928
|
-
// and match the RFC sample documentation
|
|
117929
|
-
// util.debugPrint(' m[16]', m, 64)
|
|
117930
|
-
for (i = 0; i < 12; i++) {
|
|
117931
|
-
// util.debugPrint(' (i=' + (i < 10 ? ' ' : '') + i + ') v[16]', v, 64)
|
|
117932
|
-
B2B_G(0, 8, 16, 24, SIGMA82[i * 16 + 0], SIGMA82[i * 16 + 1]);
|
|
117933
|
-
B2B_G(2, 10, 18, 26, SIGMA82[i * 16 + 2], SIGMA82[i * 16 + 3]);
|
|
117934
|
-
B2B_G(4, 12, 20, 28, SIGMA82[i * 16 + 4], SIGMA82[i * 16 + 5]);
|
|
117935
|
-
B2B_G(6, 14, 22, 30, SIGMA82[i * 16 + 6], SIGMA82[i * 16 + 7]);
|
|
117936
|
-
B2B_G(0, 10, 20, 30, SIGMA82[i * 16 + 8], SIGMA82[i * 16 + 9]);
|
|
117937
|
-
B2B_G(2, 12, 22, 24, SIGMA82[i * 16 + 10], SIGMA82[i * 16 + 11]);
|
|
117938
|
-
B2B_G(4, 14, 16, 26, SIGMA82[i * 16 + 12], SIGMA82[i * 16 + 13]);
|
|
117939
|
-
B2B_G(6, 8, 18, 28, SIGMA82[i * 16 + 14], SIGMA82[i * 16 + 15]);
|
|
117940
|
-
}
|
|
117941
|
-
// util.debugPrint(' (i=12) v[16]', v, 64)
|
|
117942
|
-
|
|
117943
|
-
for (i = 0; i < 16; i++) {
|
|
117944
|
-
ctx.h[i] = ctx.h[i] ^ v$1[i] ^ v$1[i + 16];
|
|
117945
|
-
}
|
|
117946
|
-
// util.debugPrint('h[8]', ctx.h, 64)
|
|
117947
|
-
}
|
|
117948
|
-
|
|
117949
|
-
// reusable parameterBlock
|
|
117950
|
-
const parameterBlock = new Uint8Array([
|
|
117951
|
-
0,
|
|
117952
|
-
0,
|
|
117953
|
-
0,
|
|
117954
|
-
0, // 0: outlen, keylen, fanout, depth
|
|
117955
|
-
0,
|
|
117956
|
-
0,
|
|
117957
|
-
0,
|
|
117958
|
-
0, // 4: leaf length, sequential mode
|
|
117959
|
-
0,
|
|
117960
|
-
0,
|
|
117961
|
-
0,
|
|
117962
|
-
0, // 8: node offset
|
|
117963
|
-
0,
|
|
117964
|
-
0,
|
|
117965
|
-
0,
|
|
117966
|
-
0, // 12: node offset
|
|
117967
|
-
0,
|
|
117968
|
-
0,
|
|
117969
|
-
0,
|
|
117970
|
-
0, // 16: node depth, inner length, rfu
|
|
117971
|
-
0,
|
|
117972
|
-
0,
|
|
117973
|
-
0,
|
|
117974
|
-
0, // 20: rfu
|
|
117975
|
-
0,
|
|
117976
|
-
0,
|
|
117977
|
-
0,
|
|
117978
|
-
0, // 24: rfu
|
|
117979
|
-
0,
|
|
117980
|
-
0,
|
|
117981
|
-
0,
|
|
117982
|
-
0, // 28: rfu
|
|
117983
|
-
0,
|
|
117984
|
-
0,
|
|
117985
|
-
0,
|
|
117986
|
-
0, // 32: salt
|
|
117987
|
-
0,
|
|
117988
|
-
0,
|
|
117989
|
-
0,
|
|
117990
|
-
0, // 36: salt
|
|
117991
|
-
0,
|
|
117992
|
-
0,
|
|
117993
|
-
0,
|
|
117994
|
-
0, // 40: salt
|
|
117995
|
-
0,
|
|
117996
|
-
0,
|
|
117997
|
-
0,
|
|
117998
|
-
0, // 44: salt
|
|
117999
|
-
0,
|
|
118000
|
-
0,
|
|
118001
|
-
0,
|
|
118002
|
-
0, // 48: personal
|
|
118003
|
-
0,
|
|
118004
|
-
0,
|
|
118005
|
-
0,
|
|
118006
|
-
0, // 52: personal
|
|
118007
|
-
0,
|
|
118008
|
-
0,
|
|
118009
|
-
0,
|
|
118010
|
-
0, // 56: personal
|
|
118011
|
-
0,
|
|
118012
|
-
0,
|
|
118013
|
-
0,
|
|
118014
|
-
0 // 60: personal
|
|
118015
|
-
]);
|
|
117770
|
+
const input = new Uint8Array(N);
|
|
117771
|
+
for (let i = 0; i < N; i++) {
|
|
117772
|
+
input[i] = i % 256;
|
|
117773
|
+
}
|
|
117774
|
+
const genMs = new Date().getTime();
|
|
117775
|
+
console.log('Generated random input in ' + (genMs - startMs) + 'ms');
|
|
117776
|
+
startMs = genMs;
|
|
117777
|
+
|
|
117778
|
+
for (let i = 0; i < M; i++) {
|
|
117779
|
+
const hashHex = hashFn(input);
|
|
117780
|
+
const hashMs = new Date().getTime();
|
|
117781
|
+
const ms = hashMs - startMs;
|
|
117782
|
+
startMs = hashMs;
|
|
117783
|
+
console.log('Hashed in ' + ms + 'ms: ' + hashHex.substring(0, 20) + '...');
|
|
117784
|
+
console.log(
|
|
117785
|
+
Math.round((N / (1 << 20) / (ms / 1000)) * 100) / 100 + ' MB PER SECOND'
|
|
117786
|
+
);
|
|
117787
|
+
}
|
|
117788
|
+
}
|
|
118016
117789
|
|
|
118017
|
-
|
|
118018
|
-
|
|
118019
|
-
|
|
118020
|
-
|
|
118021
|
-
|
|
118022
|
-
|
|
118023
|
-
|
|
118024
|
-
|
|
118025
|
-
}
|
|
118026
|
-
if (key && key.length > 64) {
|
|
118027
|
-
throw new Error('Illegal key, expected Uint8Array with 0 < length <= 64')
|
|
118028
|
-
}
|
|
118029
|
-
if (salt && salt.length !== 16) {
|
|
118030
|
-
throw new Error('Illegal salt, expected Uint8Array with length is 16')
|
|
118031
|
-
}
|
|
118032
|
-
if (personal && personal.length !== 16) {
|
|
118033
|
-
throw new Error('Illegal personal, expected Uint8Array with length is 16')
|
|
118034
|
-
}
|
|
118035
|
-
|
|
118036
|
-
// state, 'param block'
|
|
118037
|
-
const ctx = {
|
|
118038
|
-
b: new Uint8Array(128),
|
|
118039
|
-
h: new Uint32Array(16),
|
|
118040
|
-
t: 0, // input count
|
|
118041
|
-
c: 0, // pointer within buffer
|
|
118042
|
-
outlen: outlen // output length in bytes
|
|
118043
|
-
};
|
|
118044
|
-
|
|
118045
|
-
// initialize parameterBlock before usage
|
|
118046
|
-
parameterBlock.fill(0);
|
|
118047
|
-
parameterBlock[0] = outlen;
|
|
118048
|
-
if (key) parameterBlock[1] = key.length;
|
|
118049
|
-
parameterBlock[2] = 1; // fanout
|
|
118050
|
-
parameterBlock[3] = 1; // depth
|
|
118051
|
-
if (salt) parameterBlock.set(salt, 32);
|
|
118052
|
-
if (personal) parameterBlock.set(personal, 48);
|
|
118053
|
-
|
|
118054
|
-
// initialize hash state
|
|
118055
|
-
for (let i = 0; i < 16; i++) {
|
|
118056
|
-
ctx.h[i] = BLAKE2B_IV32[i] ^ B2B_GET32(parameterBlock, i * 4);
|
|
118057
|
-
}
|
|
118058
|
-
|
|
118059
|
-
// key the hash, if applicable
|
|
118060
|
-
if (key) {
|
|
118061
|
-
blake2bUpdate(ctx, key);
|
|
118062
|
-
// at the end
|
|
118063
|
-
ctx.c = 128;
|
|
118064
|
-
}
|
|
118065
|
-
|
|
118066
|
-
return ctx
|
|
118067
|
-
}
|
|
118068
|
-
|
|
118069
|
-
// Updates a BLAKE2b streaming hash
|
|
118070
|
-
// Requires hash context and Uint8Array (byte array)
|
|
118071
|
-
function blake2bUpdate (ctx, input) {
|
|
118072
|
-
for (let i = 0; i < input.length; i++) {
|
|
118073
|
-
if (ctx.c === 128) {
|
|
118074
|
-
// buffer full ?
|
|
118075
|
-
ctx.t += ctx.c; // add counters
|
|
118076
|
-
blake2bCompress(ctx, false); // compress (not last)
|
|
118077
|
-
ctx.c = 0; // counter to zero
|
|
118078
|
-
}
|
|
118079
|
-
ctx.b[ctx.c++] = input[i];
|
|
118080
|
-
}
|
|
118081
|
-
}
|
|
118082
|
-
|
|
118083
|
-
// Completes a BLAKE2b streaming hash
|
|
118084
|
-
// Returns a Uint8Array containing the message digest
|
|
118085
|
-
function blake2bFinal (ctx) {
|
|
118086
|
-
ctx.t += ctx.c; // mark last block offset
|
|
118087
|
-
|
|
118088
|
-
while (ctx.c < 128) {
|
|
118089
|
-
// fill up with zeros
|
|
118090
|
-
ctx.b[ctx.c++] = 0;
|
|
118091
|
-
}
|
|
118092
|
-
blake2bCompress(ctx, true); // final block flag = 1
|
|
118093
|
-
|
|
118094
|
-
// little endian convert and store
|
|
118095
|
-
const out = new Uint8Array(ctx.outlen);
|
|
118096
|
-
for (let i = 0; i < ctx.outlen; i++) {
|
|
118097
|
-
out[i] = ctx.h[i >> 2] >> (8 * (i & 3));
|
|
118098
|
-
}
|
|
118099
|
-
return out
|
|
118100
|
-
}
|
|
118101
|
-
|
|
118102
|
-
// Computes the BLAKE2B hash of a string or byte array, and returns a Uint8Array
|
|
118103
|
-
//
|
|
118104
|
-
// Returns a n-byte Uint8Array
|
|
118105
|
-
//
|
|
118106
|
-
// Parameters:
|
|
118107
|
-
// - input - the input bytes, as a string, Buffer or Uint8Array
|
|
118108
|
-
// - key - optional key Uint8Array, up to 64 bytes
|
|
118109
|
-
// - outlen - optional output length in bytes, default 64
|
|
118110
|
-
// - salt - optional salt bytes, string, Buffer or Uint8Array
|
|
118111
|
-
// - personal - optional personal bytes, string, Buffer or Uint8Array
|
|
118112
|
-
function blake2b (input, key, outlen, salt, personal) {
|
|
118113
|
-
// preprocess inputs
|
|
118114
|
-
outlen = outlen || 64;
|
|
118115
|
-
input = util$1.normalizeInput(input);
|
|
118116
|
-
if (salt) {
|
|
118117
|
-
salt = util$1.normalizeInput(salt);
|
|
118118
|
-
}
|
|
118119
|
-
if (personal) {
|
|
118120
|
-
personal = util$1.normalizeInput(personal);
|
|
118121
|
-
}
|
|
118122
|
-
|
|
118123
|
-
// do the math
|
|
118124
|
-
const ctx = blake2bInit(outlen, key, salt, personal);
|
|
118125
|
-
blake2bUpdate(ctx, input);
|
|
118126
|
-
return blake2bFinal(ctx)
|
|
118127
|
-
}
|
|
118128
|
-
|
|
118129
|
-
// Computes the BLAKE2B hash of a string or byte array
|
|
118130
|
-
//
|
|
118131
|
-
// Returns an n-byte hash in hex, all lowercase
|
|
118132
|
-
//
|
|
118133
|
-
// Parameters:
|
|
118134
|
-
// - input - the input bytes, as a string, Buffer, or Uint8Array
|
|
118135
|
-
// - key - optional key Uint8Array, up to 64 bytes
|
|
118136
|
-
// - outlen - optional output length in bytes, default 64
|
|
118137
|
-
// - salt - optional salt bytes, string, Buffer or Uint8Array
|
|
118138
|
-
// - personal - optional personal bytes, string, Buffer or Uint8Array
|
|
118139
|
-
function blake2bHex (input, key, outlen, salt, personal) {
|
|
118140
|
-
const output = blake2b(input, key, outlen, salt, personal);
|
|
118141
|
-
return util$1.toHex(output)
|
|
118142
|
-
}
|
|
118143
|
-
|
|
118144
|
-
var blake2b_1 = {
|
|
118145
|
-
blake2b: blake2b,
|
|
118146
|
-
blake2bHex: blake2bHex,
|
|
118147
|
-
blake2bInit: blake2bInit,
|
|
118148
|
-
blake2bUpdate: blake2bUpdate,
|
|
118149
|
-
blake2bFinal: blake2bFinal
|
|
118150
|
-
};
|
|
117790
|
+
util = {
|
|
117791
|
+
normalizeInput: normalizeInput,
|
|
117792
|
+
toHex: toHex,
|
|
117793
|
+
debugPrint: debugPrint,
|
|
117794
|
+
testSpeed: testSpeed
|
|
117795
|
+
};
|
|
117796
|
+
return util;
|
|
117797
|
+
}
|
|
118151
117798
|
|
|
118152
|
-
|
|
118153
|
-
|
|
118154
|
-
// Ported to Javascript by DC - https://github.com/dcposch
|
|
118155
|
-
|
|
118156
|
-
const util = util$2;
|
|
118157
|
-
|
|
118158
|
-
// Little-endian byte access.
|
|
118159
|
-
// Expects a Uint8Array and an index
|
|
118160
|
-
// Returns the little-endian uint32 at v[i..i+3]
|
|
118161
|
-
function B2S_GET32 (v, i) {
|
|
118162
|
-
return v[i] ^ (v[i + 1] << 8) ^ (v[i + 2] << 16) ^ (v[i + 3] << 24)
|
|
118163
|
-
}
|
|
118164
|
-
|
|
118165
|
-
// Mixing function G.
|
|
118166
|
-
function B2S_G (a, b, c, d, x, y) {
|
|
118167
|
-
v[a] = v[a] + v[b] + x;
|
|
118168
|
-
v[d] = ROTR32(v[d] ^ v[a], 16);
|
|
118169
|
-
v[c] = v[c] + v[d];
|
|
118170
|
-
v[b] = ROTR32(v[b] ^ v[c], 12);
|
|
118171
|
-
v[a] = v[a] + v[b] + y;
|
|
118172
|
-
v[d] = ROTR32(v[d] ^ v[a], 8);
|
|
118173
|
-
v[c] = v[c] + v[d];
|
|
118174
|
-
v[b] = ROTR32(v[b] ^ v[c], 7);
|
|
118175
|
-
}
|
|
118176
|
-
|
|
118177
|
-
// 32-bit right rotation
|
|
118178
|
-
// x should be a uint32
|
|
118179
|
-
// y must be between 1 and 31, inclusive
|
|
118180
|
-
function ROTR32 (x, y) {
|
|
118181
|
-
return (x >>> y) ^ (x << (32 - y))
|
|
118182
|
-
}
|
|
118183
|
-
|
|
118184
|
-
// Initialization Vector.
|
|
118185
|
-
const BLAKE2S_IV = new Uint32Array([
|
|
118186
|
-
0x6a09e667,
|
|
118187
|
-
0xbb67ae85,
|
|
118188
|
-
0x3c6ef372,
|
|
118189
|
-
0xa54ff53a,
|
|
118190
|
-
0x510e527f,
|
|
118191
|
-
0x9b05688c,
|
|
118192
|
-
0x1f83d9ab,
|
|
118193
|
-
0x5be0cd19
|
|
118194
|
-
]);
|
|
117799
|
+
var blake2b_1;
|
|
117800
|
+
var hasRequiredBlake2b;
|
|
118195
117801
|
|
|
118196
|
-
|
|
118197
|
-
|
|
118198
|
-
|
|
118199
|
-
|
|
118200
|
-
|
|
118201
|
-
|
|
118202
|
-
5,
|
|
118203
|
-
6,
|
|
118204
|
-
7,
|
|
118205
|
-
8,
|
|
118206
|
-
9,
|
|
118207
|
-
10,
|
|
118208
|
-
11,
|
|
118209
|
-
12,
|
|
118210
|
-
13,
|
|
118211
|
-
14,
|
|
118212
|
-
15,
|
|
118213
|
-
14,
|
|
118214
|
-
10,
|
|
118215
|
-
4,
|
|
118216
|
-
8,
|
|
118217
|
-
9,
|
|
118218
|
-
15,
|
|
118219
|
-
13,
|
|
118220
|
-
6,
|
|
118221
|
-
1,
|
|
118222
|
-
12,
|
|
118223
|
-
0,
|
|
118224
|
-
2,
|
|
118225
|
-
11,
|
|
118226
|
-
7,
|
|
118227
|
-
5,
|
|
118228
|
-
3,
|
|
118229
|
-
11,
|
|
118230
|
-
8,
|
|
118231
|
-
12,
|
|
118232
|
-
0,
|
|
118233
|
-
5,
|
|
118234
|
-
2,
|
|
118235
|
-
15,
|
|
118236
|
-
13,
|
|
118237
|
-
10,
|
|
118238
|
-
14,
|
|
118239
|
-
3,
|
|
118240
|
-
6,
|
|
118241
|
-
7,
|
|
118242
|
-
1,
|
|
118243
|
-
9,
|
|
118244
|
-
4,
|
|
118245
|
-
7,
|
|
118246
|
-
9,
|
|
118247
|
-
3,
|
|
118248
|
-
1,
|
|
118249
|
-
13,
|
|
118250
|
-
12,
|
|
118251
|
-
11,
|
|
118252
|
-
14,
|
|
118253
|
-
2,
|
|
118254
|
-
6,
|
|
118255
|
-
5,
|
|
118256
|
-
10,
|
|
118257
|
-
4,
|
|
118258
|
-
0,
|
|
118259
|
-
15,
|
|
118260
|
-
8,
|
|
118261
|
-
9,
|
|
118262
|
-
0,
|
|
118263
|
-
5,
|
|
118264
|
-
7,
|
|
118265
|
-
2,
|
|
118266
|
-
4,
|
|
118267
|
-
10,
|
|
118268
|
-
15,
|
|
118269
|
-
14,
|
|
118270
|
-
1,
|
|
118271
|
-
11,
|
|
118272
|
-
12,
|
|
118273
|
-
6,
|
|
118274
|
-
8,
|
|
118275
|
-
3,
|
|
118276
|
-
13,
|
|
118277
|
-
2,
|
|
118278
|
-
12,
|
|
118279
|
-
6,
|
|
118280
|
-
10,
|
|
118281
|
-
0,
|
|
118282
|
-
11,
|
|
118283
|
-
8,
|
|
118284
|
-
3,
|
|
118285
|
-
4,
|
|
118286
|
-
13,
|
|
118287
|
-
7,
|
|
118288
|
-
5,
|
|
118289
|
-
15,
|
|
118290
|
-
14,
|
|
118291
|
-
1,
|
|
118292
|
-
9,
|
|
118293
|
-
12,
|
|
118294
|
-
5,
|
|
118295
|
-
1,
|
|
118296
|
-
15,
|
|
118297
|
-
14,
|
|
118298
|
-
13,
|
|
118299
|
-
4,
|
|
118300
|
-
10,
|
|
118301
|
-
0,
|
|
118302
|
-
7,
|
|
118303
|
-
6,
|
|
118304
|
-
3,
|
|
118305
|
-
9,
|
|
118306
|
-
2,
|
|
118307
|
-
8,
|
|
118308
|
-
11,
|
|
118309
|
-
13,
|
|
118310
|
-
11,
|
|
118311
|
-
7,
|
|
118312
|
-
14,
|
|
118313
|
-
12,
|
|
118314
|
-
1,
|
|
118315
|
-
3,
|
|
118316
|
-
9,
|
|
118317
|
-
5,
|
|
118318
|
-
0,
|
|
118319
|
-
15,
|
|
118320
|
-
4,
|
|
118321
|
-
8,
|
|
118322
|
-
6,
|
|
118323
|
-
2,
|
|
118324
|
-
10,
|
|
118325
|
-
6,
|
|
118326
|
-
15,
|
|
118327
|
-
14,
|
|
118328
|
-
9,
|
|
118329
|
-
11,
|
|
118330
|
-
3,
|
|
118331
|
-
0,
|
|
118332
|
-
8,
|
|
118333
|
-
12,
|
|
118334
|
-
2,
|
|
118335
|
-
13,
|
|
118336
|
-
7,
|
|
118337
|
-
1,
|
|
118338
|
-
4,
|
|
118339
|
-
10,
|
|
118340
|
-
5,
|
|
118341
|
-
10,
|
|
118342
|
-
2,
|
|
118343
|
-
8,
|
|
118344
|
-
4,
|
|
118345
|
-
7,
|
|
118346
|
-
6,
|
|
118347
|
-
1,
|
|
118348
|
-
5,
|
|
118349
|
-
15,
|
|
118350
|
-
11,
|
|
118351
|
-
9,
|
|
118352
|
-
14,
|
|
118353
|
-
3,
|
|
118354
|
-
12,
|
|
118355
|
-
13,
|
|
118356
|
-
0
|
|
118357
|
-
]);
|
|
117802
|
+
function requireBlake2b () {
|
|
117803
|
+
if (hasRequiredBlake2b) return blake2b_1;
|
|
117804
|
+
hasRequiredBlake2b = 1;
|
|
117805
|
+
// Blake2B in pure Javascript
|
|
117806
|
+
// Adapted from the reference implementation in RFC7693
|
|
117807
|
+
// Ported to Javascript by DC - https://github.com/dcposch
|
|
118358
117808
|
|
|
118359
|
-
|
|
118360
|
-
const v = new Uint32Array(16);
|
|
118361
|
-
const m = new Uint32Array(16);
|
|
118362
|
-
function blake2sCompress (ctx, last) {
|
|
118363
|
-
let i = 0;
|
|
118364
|
-
for (i = 0; i < 8; i++) {
|
|
118365
|
-
// init work variables
|
|
118366
|
-
v[i] = ctx.h[i];
|
|
118367
|
-
v[i + 8] = BLAKE2S_IV[i];
|
|
118368
|
-
}
|
|
118369
|
-
|
|
118370
|
-
v[12] ^= ctx.t; // low 32 bits of offset
|
|
118371
|
-
v[13] ^= ctx.t / 0x100000000; // high 32 bits
|
|
118372
|
-
if (last) {
|
|
118373
|
-
// last block flag set ?
|
|
118374
|
-
v[14] = ~v[14];
|
|
118375
|
-
}
|
|
118376
|
-
|
|
118377
|
-
for (i = 0; i < 16; i++) {
|
|
118378
|
-
// get little-endian words
|
|
118379
|
-
m[i] = B2S_GET32(ctx.b, 4 * i);
|
|
118380
|
-
}
|
|
118381
|
-
|
|
118382
|
-
// ten rounds of mixing
|
|
118383
|
-
// uncomment the DebugPrint calls to log the computation
|
|
118384
|
-
// and match the RFC sample documentation
|
|
118385
|
-
// util.debugPrint(' m[16]', m, 32)
|
|
118386
|
-
for (i = 0; i < 10; i++) {
|
|
118387
|
-
// util.debugPrint(' (i=' + i + ') v[16]', v, 32)
|
|
118388
|
-
B2S_G(0, 4, 8, 12, m[SIGMA[i * 16 + 0]], m[SIGMA[i * 16 + 1]]);
|
|
118389
|
-
B2S_G(1, 5, 9, 13, m[SIGMA[i * 16 + 2]], m[SIGMA[i * 16 + 3]]);
|
|
118390
|
-
B2S_G(2, 6, 10, 14, m[SIGMA[i * 16 + 4]], m[SIGMA[i * 16 + 5]]);
|
|
118391
|
-
B2S_G(3, 7, 11, 15, m[SIGMA[i * 16 + 6]], m[SIGMA[i * 16 + 7]]);
|
|
118392
|
-
B2S_G(0, 5, 10, 15, m[SIGMA[i * 16 + 8]], m[SIGMA[i * 16 + 9]]);
|
|
118393
|
-
B2S_G(1, 6, 11, 12, m[SIGMA[i * 16 + 10]], m[SIGMA[i * 16 + 11]]);
|
|
118394
|
-
B2S_G(2, 7, 8, 13, m[SIGMA[i * 16 + 12]], m[SIGMA[i * 16 + 13]]);
|
|
118395
|
-
B2S_G(3, 4, 9, 14, m[SIGMA[i * 16 + 14]], m[SIGMA[i * 16 + 15]]);
|
|
118396
|
-
}
|
|
118397
|
-
// util.debugPrint(' (i=10) v[16]', v, 32)
|
|
118398
|
-
|
|
118399
|
-
for (i = 0; i < 8; i++) {
|
|
118400
|
-
ctx.h[i] ^= v[i] ^ v[i + 8];
|
|
118401
|
-
}
|
|
118402
|
-
// util.debugPrint('h[8]', ctx.h, 32)
|
|
118403
|
-
}
|
|
118404
|
-
|
|
118405
|
-
// Creates a BLAKE2s hashing context
|
|
118406
|
-
// Requires an output length between 1 and 32 bytes
|
|
118407
|
-
// Takes an optional Uint8Array key
|
|
118408
|
-
function blake2sInit (outlen, key) {
|
|
118409
|
-
if (!(outlen > 0 && outlen <= 32)) {
|
|
118410
|
-
throw new Error('Incorrect output length, should be in [1, 32]')
|
|
118411
|
-
}
|
|
118412
|
-
const keylen = key ? key.length : 0;
|
|
118413
|
-
if (key && !(keylen > 0 && keylen <= 32)) {
|
|
118414
|
-
throw new Error('Incorrect key length, should be in [1, 32]')
|
|
118415
|
-
}
|
|
118416
|
-
|
|
118417
|
-
const ctx = {
|
|
118418
|
-
h: new Uint32Array(BLAKE2S_IV), // hash state
|
|
118419
|
-
b: new Uint8Array(64), // input block
|
|
118420
|
-
c: 0, // pointer within block
|
|
118421
|
-
t: 0, // input count
|
|
118422
|
-
outlen: outlen // output length in bytes
|
|
118423
|
-
};
|
|
118424
|
-
ctx.h[0] ^= 0x01010000 ^ (keylen << 8) ^ outlen;
|
|
118425
|
-
|
|
118426
|
-
if (keylen > 0) {
|
|
118427
|
-
blake2sUpdate(ctx, key);
|
|
118428
|
-
ctx.c = 64; // at the end
|
|
118429
|
-
}
|
|
118430
|
-
|
|
118431
|
-
return ctx
|
|
118432
|
-
}
|
|
118433
|
-
|
|
118434
|
-
// Updates a BLAKE2s streaming hash
|
|
118435
|
-
// Requires hash context and Uint8Array (byte array)
|
|
118436
|
-
function blake2sUpdate (ctx, input) {
|
|
118437
|
-
for (let i = 0; i < input.length; i++) {
|
|
118438
|
-
if (ctx.c === 64) {
|
|
118439
|
-
// buffer full ?
|
|
118440
|
-
ctx.t += ctx.c; // add counters
|
|
118441
|
-
blake2sCompress(ctx, false); // compress (not last)
|
|
118442
|
-
ctx.c = 0; // counter to zero
|
|
118443
|
-
}
|
|
118444
|
-
ctx.b[ctx.c++] = input[i];
|
|
118445
|
-
}
|
|
118446
|
-
}
|
|
118447
|
-
|
|
118448
|
-
// Completes a BLAKE2s streaming hash
|
|
118449
|
-
// Returns a Uint8Array containing the message digest
|
|
118450
|
-
function blake2sFinal (ctx) {
|
|
118451
|
-
ctx.t += ctx.c; // mark last block offset
|
|
118452
|
-
while (ctx.c < 64) {
|
|
118453
|
-
// fill up with zeros
|
|
118454
|
-
ctx.b[ctx.c++] = 0;
|
|
118455
|
-
}
|
|
118456
|
-
blake2sCompress(ctx, true); // final block flag = 1
|
|
118457
|
-
|
|
118458
|
-
// little endian convert and store
|
|
118459
|
-
const out = new Uint8Array(ctx.outlen);
|
|
118460
|
-
for (let i = 0; i < ctx.outlen; i++) {
|
|
118461
|
-
out[i] = (ctx.h[i >> 2] >> (8 * (i & 3))) & 0xff;
|
|
118462
|
-
}
|
|
118463
|
-
return out
|
|
118464
|
-
}
|
|
118465
|
-
|
|
118466
|
-
// Computes the BLAKE2S hash of a string or byte array, and returns a Uint8Array
|
|
118467
|
-
//
|
|
118468
|
-
// Returns a n-byte Uint8Array
|
|
118469
|
-
//
|
|
118470
|
-
// Parameters:
|
|
118471
|
-
// - input - the input bytes, as a string, Buffer, or Uint8Array
|
|
118472
|
-
// - key - optional key Uint8Array, up to 32 bytes
|
|
118473
|
-
// - outlen - optional output length in bytes, default 64
|
|
118474
|
-
function blake2s (input, key, outlen) {
|
|
118475
|
-
// preprocess inputs
|
|
118476
|
-
outlen = outlen || 32;
|
|
118477
|
-
input = util.normalizeInput(input);
|
|
118478
|
-
|
|
118479
|
-
// do the math
|
|
118480
|
-
const ctx = blake2sInit(outlen, key);
|
|
118481
|
-
blake2sUpdate(ctx, input);
|
|
118482
|
-
return blake2sFinal(ctx)
|
|
118483
|
-
}
|
|
118484
|
-
|
|
118485
|
-
// Computes the BLAKE2S hash of a string or byte array
|
|
118486
|
-
//
|
|
118487
|
-
// Returns an n-byte hash in hex, all lowercase
|
|
118488
|
-
//
|
|
118489
|
-
// Parameters:
|
|
118490
|
-
// - input - the input bytes, as a string, Buffer, or Uint8Array
|
|
118491
|
-
// - key - optional key Uint8Array, up to 32 bytes
|
|
118492
|
-
// - outlen - optional output length in bytes, default 64
|
|
118493
|
-
function blake2sHex (input, key, outlen) {
|
|
118494
|
-
const output = blake2s(input, key, outlen);
|
|
118495
|
-
return util.toHex(output)
|
|
118496
|
-
}
|
|
118497
|
-
|
|
118498
|
-
var blake2s_1 = {
|
|
118499
|
-
blake2s: blake2s,
|
|
118500
|
-
blake2sHex: blake2sHex,
|
|
118501
|
-
blake2sInit: blake2sInit,
|
|
118502
|
-
blake2sUpdate: blake2sUpdate,
|
|
118503
|
-
blake2sFinal: blake2sFinal
|
|
118504
|
-
};
|
|
117809
|
+
const util = requireUtil();
|
|
118505
117810
|
|
|
118506
|
-
|
|
118507
|
-
|
|
118508
|
-
|
|
118509
|
-
|
|
118510
|
-
|
|
118511
|
-
|
|
118512
|
-
|
|
118513
|
-
|
|
118514
|
-
|
|
118515
|
-
|
|
118516
|
-
|
|
118517
|
-
|
|
118518
|
-
|
|
118519
|
-
|
|
118520
|
-
|
|
117811
|
+
// 64-bit unsigned addition
|
|
117812
|
+
// Sets v[a,a+1] += v[b,b+1]
|
|
117813
|
+
// v should be a Uint32Array
|
|
117814
|
+
function ADD64AA (v, a, b) {
|
|
117815
|
+
const o0 = v[a] + v[b];
|
|
117816
|
+
let o1 = v[a + 1] + v[b + 1];
|
|
117817
|
+
if (o0 >= 0x100000000) {
|
|
117818
|
+
o1++;
|
|
117819
|
+
}
|
|
117820
|
+
v[a] = o0;
|
|
117821
|
+
v[a + 1] = o1;
|
|
117822
|
+
}
|
|
117823
|
+
|
|
117824
|
+
// 64-bit unsigned addition
|
|
117825
|
+
// Sets v[a,a+1] += b
|
|
117826
|
+
// b0 is the low 32 bits of b, b1 represents the high 32 bits
|
|
117827
|
+
function ADD64AC (v, a, b0, b1) {
|
|
117828
|
+
let o0 = v[a] + b0;
|
|
117829
|
+
if (b0 < 0) {
|
|
117830
|
+
o0 += 0x100000000;
|
|
117831
|
+
}
|
|
117832
|
+
let o1 = v[a + 1] + b1;
|
|
117833
|
+
if (o0 >= 0x100000000) {
|
|
117834
|
+
o1++;
|
|
117835
|
+
}
|
|
117836
|
+
v[a] = o0;
|
|
117837
|
+
v[a + 1] = o1;
|
|
117838
|
+
}
|
|
117839
|
+
|
|
117840
|
+
// Little-endian byte access
|
|
117841
|
+
function B2B_GET32 (arr, i) {
|
|
117842
|
+
return arr[i] ^ (arr[i + 1] << 8) ^ (arr[i + 2] << 16) ^ (arr[i + 3] << 24)
|
|
117843
|
+
}
|
|
117844
|
+
|
|
117845
|
+
// G Mixing function
|
|
117846
|
+
// The ROTRs are inlined for speed
|
|
117847
|
+
function B2B_G (a, b, c, d, ix, iy) {
|
|
117848
|
+
const x0 = m[ix];
|
|
117849
|
+
const x1 = m[ix + 1];
|
|
117850
|
+
const y0 = m[iy];
|
|
117851
|
+
const y1 = m[iy + 1];
|
|
117852
|
+
|
|
117853
|
+
ADD64AA(v, a, b); // v[a,a+1] += v[b,b+1] ... in JS we must store a uint64 as two uint32s
|
|
117854
|
+
ADD64AC(v, a, x0, x1); // v[a, a+1] += x ... x0 is the low 32 bits of x, x1 is the high 32 bits
|
|
117855
|
+
|
|
117856
|
+
// v[d,d+1] = (v[d,d+1] xor v[a,a+1]) rotated to the right by 32 bits
|
|
117857
|
+
let xor0 = v[d] ^ v[a];
|
|
117858
|
+
let xor1 = v[d + 1] ^ v[a + 1];
|
|
117859
|
+
v[d] = xor1;
|
|
117860
|
+
v[d + 1] = xor0;
|
|
117861
|
+
|
|
117862
|
+
ADD64AA(v, c, d);
|
|
117863
|
+
|
|
117864
|
+
// v[b,b+1] = (v[b,b+1] xor v[c,c+1]) rotated right by 24 bits
|
|
117865
|
+
xor0 = v[b] ^ v[c];
|
|
117866
|
+
xor1 = v[b + 1] ^ v[c + 1];
|
|
117867
|
+
v[b] = (xor0 >>> 24) ^ (xor1 << 8);
|
|
117868
|
+
v[b + 1] = (xor1 >>> 24) ^ (xor0 << 8);
|
|
117869
|
+
|
|
117870
|
+
ADD64AA(v, a, b);
|
|
117871
|
+
ADD64AC(v, a, y0, y1);
|
|
117872
|
+
|
|
117873
|
+
// v[d,d+1] = (v[d,d+1] xor v[a,a+1]) rotated right by 16 bits
|
|
117874
|
+
xor0 = v[d] ^ v[a];
|
|
117875
|
+
xor1 = v[d + 1] ^ v[a + 1];
|
|
117876
|
+
v[d] = (xor0 >>> 16) ^ (xor1 << 16);
|
|
117877
|
+
v[d + 1] = (xor1 >>> 16) ^ (xor0 << 16);
|
|
117878
|
+
|
|
117879
|
+
ADD64AA(v, c, d);
|
|
117880
|
+
|
|
117881
|
+
// v[b,b+1] = (v[b,b+1] xor v[c,c+1]) rotated right by 63 bits
|
|
117882
|
+
xor0 = v[b] ^ v[c];
|
|
117883
|
+
xor1 = v[b + 1] ^ v[c + 1];
|
|
117884
|
+
v[b] = (xor1 >>> 31) ^ (xor0 << 1);
|
|
117885
|
+
v[b + 1] = (xor0 >>> 31) ^ (xor1 << 1);
|
|
117886
|
+
}
|
|
117887
|
+
|
|
117888
|
+
// Initialization Vector
|
|
117889
|
+
const BLAKE2B_IV32 = new Uint32Array([
|
|
117890
|
+
0xf3bcc908, 0x6a09e667, 0x84caa73b, 0xbb67ae85, 0xfe94f82b, 0x3c6ef372,
|
|
117891
|
+
0x5f1d36f1, 0xa54ff53a, 0xade682d1, 0x510e527f, 0x2b3e6c1f, 0x9b05688c,
|
|
117892
|
+
0xfb41bd6b, 0x1f83d9ab, 0x137e2179, 0x5be0cd19
|
|
117893
|
+
]);
|
|
117894
|
+
|
|
117895
|
+
const SIGMA8 = [
|
|
117896
|
+
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 14, 10, 4, 8, 9, 15, 13,
|
|
117897
|
+
6, 1, 12, 0, 2, 11, 7, 5, 3, 11, 8, 12, 0, 5, 2, 15, 13, 10, 14, 3, 6, 7, 1,
|
|
117898
|
+
9, 4, 7, 9, 3, 1, 13, 12, 11, 14, 2, 6, 5, 10, 4, 0, 15, 8, 9, 0, 5, 7, 2, 4,
|
|
117899
|
+
10, 15, 14, 1, 11, 12, 6, 8, 3, 13, 2, 12, 6, 10, 0, 11, 8, 3, 4, 13, 7, 5,
|
|
117900
|
+
15, 14, 1, 9, 12, 5, 1, 15, 14, 13, 4, 10, 0, 7, 6, 3, 9, 2, 8, 11, 13, 11, 7,
|
|
117901
|
+
14, 12, 1, 3, 9, 5, 0, 15, 4, 8, 6, 2, 10, 6, 15, 14, 9, 11, 3, 0, 8, 12, 2,
|
|
117902
|
+
13, 7, 1, 4, 10, 5, 10, 2, 8, 4, 7, 6, 1, 5, 15, 11, 9, 14, 3, 12, 13, 0, 0,
|
|
117903
|
+
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 14, 10, 4, 8, 9, 15, 13, 6,
|
|
117904
|
+
1, 12, 0, 2, 11, 7, 5, 3
|
|
117905
|
+
];
|
|
117906
|
+
|
|
117907
|
+
// These are offsets into a uint64 buffer.
|
|
117908
|
+
// Multiply them all by 2 to make them offsets into a uint32 buffer,
|
|
117909
|
+
// because this is Javascript and we don't have uint64s
|
|
117910
|
+
const SIGMA82 = new Uint8Array(
|
|
117911
|
+
SIGMA8.map(function (x) {
|
|
117912
|
+
return x * 2
|
|
117913
|
+
})
|
|
117914
|
+
);
|
|
117915
|
+
|
|
117916
|
+
// Compression function. 'last' flag indicates last block.
|
|
117917
|
+
// Note we're representing 16 uint64s as 32 uint32s
|
|
117918
|
+
const v = new Uint32Array(32);
|
|
117919
|
+
const m = new Uint32Array(32);
|
|
117920
|
+
function blake2bCompress (ctx, last) {
|
|
117921
|
+
let i = 0;
|
|
117922
|
+
|
|
117923
|
+
// init work variables
|
|
117924
|
+
for (i = 0; i < 16; i++) {
|
|
117925
|
+
v[i] = ctx.h[i];
|
|
117926
|
+
v[i + 16] = BLAKE2B_IV32[i];
|
|
117927
|
+
}
|
|
117928
|
+
|
|
117929
|
+
// low 64 bits of offset
|
|
117930
|
+
v[24] = v[24] ^ ctx.t;
|
|
117931
|
+
v[25] = v[25] ^ (ctx.t / 0x100000000);
|
|
117932
|
+
// high 64 bits not supported, offset may not be higher than 2**53-1
|
|
117933
|
+
|
|
117934
|
+
// last block flag set ?
|
|
117935
|
+
if (last) {
|
|
117936
|
+
v[28] = ~v[28];
|
|
117937
|
+
v[29] = ~v[29];
|
|
117938
|
+
}
|
|
117939
|
+
|
|
117940
|
+
// get little-endian words
|
|
117941
|
+
for (i = 0; i < 32; i++) {
|
|
117942
|
+
m[i] = B2B_GET32(ctx.b, 4 * i);
|
|
117943
|
+
}
|
|
117944
|
+
|
|
117945
|
+
// twelve rounds of mixing
|
|
117946
|
+
// uncomment the DebugPrint calls to log the computation
|
|
117947
|
+
// and match the RFC sample documentation
|
|
117948
|
+
// util.debugPrint(' m[16]', m, 64)
|
|
117949
|
+
for (i = 0; i < 12; i++) {
|
|
117950
|
+
// util.debugPrint(' (i=' + (i < 10 ? ' ' : '') + i + ') v[16]', v, 64)
|
|
117951
|
+
B2B_G(0, 8, 16, 24, SIGMA82[i * 16 + 0], SIGMA82[i * 16 + 1]);
|
|
117952
|
+
B2B_G(2, 10, 18, 26, SIGMA82[i * 16 + 2], SIGMA82[i * 16 + 3]);
|
|
117953
|
+
B2B_G(4, 12, 20, 28, SIGMA82[i * 16 + 4], SIGMA82[i * 16 + 5]);
|
|
117954
|
+
B2B_G(6, 14, 22, 30, SIGMA82[i * 16 + 6], SIGMA82[i * 16 + 7]);
|
|
117955
|
+
B2B_G(0, 10, 20, 30, SIGMA82[i * 16 + 8], SIGMA82[i * 16 + 9]);
|
|
117956
|
+
B2B_G(2, 12, 22, 24, SIGMA82[i * 16 + 10], SIGMA82[i * 16 + 11]);
|
|
117957
|
+
B2B_G(4, 14, 16, 26, SIGMA82[i * 16 + 12], SIGMA82[i * 16 + 13]);
|
|
117958
|
+
B2B_G(6, 8, 18, 28, SIGMA82[i * 16 + 14], SIGMA82[i * 16 + 15]);
|
|
117959
|
+
}
|
|
117960
|
+
// util.debugPrint(' (i=12) v[16]', v, 64)
|
|
117961
|
+
|
|
117962
|
+
for (i = 0; i < 16; i++) {
|
|
117963
|
+
ctx.h[i] = ctx.h[i] ^ v[i] ^ v[i + 16];
|
|
117964
|
+
}
|
|
117965
|
+
// util.debugPrint('h[8]', ctx.h, 64)
|
|
117966
|
+
}
|
|
117967
|
+
|
|
117968
|
+
// reusable parameterBlock
|
|
117969
|
+
const parameterBlock = new Uint8Array([
|
|
117970
|
+
0,
|
|
117971
|
+
0,
|
|
117972
|
+
0,
|
|
117973
|
+
0, // 0: outlen, keylen, fanout, depth
|
|
117974
|
+
0,
|
|
117975
|
+
0,
|
|
117976
|
+
0,
|
|
117977
|
+
0, // 4: leaf length, sequential mode
|
|
117978
|
+
0,
|
|
117979
|
+
0,
|
|
117980
|
+
0,
|
|
117981
|
+
0, // 8: node offset
|
|
117982
|
+
0,
|
|
117983
|
+
0,
|
|
117984
|
+
0,
|
|
117985
|
+
0, // 12: node offset
|
|
117986
|
+
0,
|
|
117987
|
+
0,
|
|
117988
|
+
0,
|
|
117989
|
+
0, // 16: node depth, inner length, rfu
|
|
117990
|
+
0,
|
|
117991
|
+
0,
|
|
117992
|
+
0,
|
|
117993
|
+
0, // 20: rfu
|
|
117994
|
+
0,
|
|
117995
|
+
0,
|
|
117996
|
+
0,
|
|
117997
|
+
0, // 24: rfu
|
|
117998
|
+
0,
|
|
117999
|
+
0,
|
|
118000
|
+
0,
|
|
118001
|
+
0, // 28: rfu
|
|
118002
|
+
0,
|
|
118003
|
+
0,
|
|
118004
|
+
0,
|
|
118005
|
+
0, // 32: salt
|
|
118006
|
+
0,
|
|
118007
|
+
0,
|
|
118008
|
+
0,
|
|
118009
|
+
0, // 36: salt
|
|
118010
|
+
0,
|
|
118011
|
+
0,
|
|
118012
|
+
0,
|
|
118013
|
+
0, // 40: salt
|
|
118014
|
+
0,
|
|
118015
|
+
0,
|
|
118016
|
+
0,
|
|
118017
|
+
0, // 44: salt
|
|
118018
|
+
0,
|
|
118019
|
+
0,
|
|
118020
|
+
0,
|
|
118021
|
+
0, // 48: personal
|
|
118022
|
+
0,
|
|
118023
|
+
0,
|
|
118024
|
+
0,
|
|
118025
|
+
0, // 52: personal
|
|
118026
|
+
0,
|
|
118027
|
+
0,
|
|
118028
|
+
0,
|
|
118029
|
+
0, // 56: personal
|
|
118030
|
+
0,
|
|
118031
|
+
0,
|
|
118032
|
+
0,
|
|
118033
|
+
0 // 60: personal
|
|
118034
|
+
]);
|
|
118035
|
+
|
|
118036
|
+
// Creates a BLAKE2b hashing context
|
|
118037
|
+
// Requires an output length between 1 and 64 bytes
|
|
118038
|
+
// Takes an optional Uint8Array key
|
|
118039
|
+
// Takes an optinal Uint8Array salt
|
|
118040
|
+
// Takes an optinal Uint8Array personal
|
|
118041
|
+
function blake2bInit (outlen, key, salt, personal) {
|
|
118042
|
+
if (outlen === 0 || outlen > 64) {
|
|
118043
|
+
throw new Error('Illegal output length, expected 0 < length <= 64')
|
|
118044
|
+
}
|
|
118045
|
+
if (key && key.length > 64) {
|
|
118046
|
+
throw new Error('Illegal key, expected Uint8Array with 0 < length <= 64')
|
|
118047
|
+
}
|
|
118048
|
+
if (salt && salt.length !== 16) {
|
|
118049
|
+
throw new Error('Illegal salt, expected Uint8Array with length is 16')
|
|
118050
|
+
}
|
|
118051
|
+
if (personal && personal.length !== 16) {
|
|
118052
|
+
throw new Error('Illegal personal, expected Uint8Array with length is 16')
|
|
118053
|
+
}
|
|
118054
|
+
|
|
118055
|
+
// state, 'param block'
|
|
118056
|
+
const ctx = {
|
|
118057
|
+
b: new Uint8Array(128),
|
|
118058
|
+
h: new Uint32Array(16),
|
|
118059
|
+
t: 0, // input count
|
|
118060
|
+
c: 0, // pointer within buffer
|
|
118061
|
+
outlen: outlen // output length in bytes
|
|
118062
|
+
};
|
|
118063
|
+
|
|
118064
|
+
// initialize parameterBlock before usage
|
|
118065
|
+
parameterBlock.fill(0);
|
|
118066
|
+
parameterBlock[0] = outlen;
|
|
118067
|
+
if (key) parameterBlock[1] = key.length;
|
|
118068
|
+
parameterBlock[2] = 1; // fanout
|
|
118069
|
+
parameterBlock[3] = 1; // depth
|
|
118070
|
+
if (salt) parameterBlock.set(salt, 32);
|
|
118071
|
+
if (personal) parameterBlock.set(personal, 48);
|
|
118072
|
+
|
|
118073
|
+
// initialize hash state
|
|
118074
|
+
for (let i = 0; i < 16; i++) {
|
|
118075
|
+
ctx.h[i] = BLAKE2B_IV32[i] ^ B2B_GET32(parameterBlock, i * 4);
|
|
118076
|
+
}
|
|
118077
|
+
|
|
118078
|
+
// key the hash, if applicable
|
|
118079
|
+
if (key) {
|
|
118080
|
+
blake2bUpdate(ctx, key);
|
|
118081
|
+
// at the end
|
|
118082
|
+
ctx.c = 128;
|
|
118083
|
+
}
|
|
118084
|
+
|
|
118085
|
+
return ctx
|
|
118086
|
+
}
|
|
118087
|
+
|
|
118088
|
+
// Updates a BLAKE2b streaming hash
|
|
118089
|
+
// Requires hash context and Uint8Array (byte array)
|
|
118090
|
+
function blake2bUpdate (ctx, input) {
|
|
118091
|
+
for (let i = 0; i < input.length; i++) {
|
|
118092
|
+
if (ctx.c === 128) {
|
|
118093
|
+
// buffer full ?
|
|
118094
|
+
ctx.t += ctx.c; // add counters
|
|
118095
|
+
blake2bCompress(ctx, false); // compress (not last)
|
|
118096
|
+
ctx.c = 0; // counter to zero
|
|
118097
|
+
}
|
|
118098
|
+
ctx.b[ctx.c++] = input[i];
|
|
118099
|
+
}
|
|
118100
|
+
}
|
|
118101
|
+
|
|
118102
|
+
// Completes a BLAKE2b streaming hash
|
|
118103
|
+
// Returns a Uint8Array containing the message digest
|
|
118104
|
+
function blake2bFinal (ctx) {
|
|
118105
|
+
ctx.t += ctx.c; // mark last block offset
|
|
118106
|
+
|
|
118107
|
+
while (ctx.c < 128) {
|
|
118108
|
+
// fill up with zeros
|
|
118109
|
+
ctx.b[ctx.c++] = 0;
|
|
118110
|
+
}
|
|
118111
|
+
blake2bCompress(ctx, true); // final block flag = 1
|
|
118112
|
+
|
|
118113
|
+
// little endian convert and store
|
|
118114
|
+
const out = new Uint8Array(ctx.outlen);
|
|
118115
|
+
for (let i = 0; i < ctx.outlen; i++) {
|
|
118116
|
+
out[i] = ctx.h[i >> 2] >> (8 * (i & 3));
|
|
118117
|
+
}
|
|
118118
|
+
return out
|
|
118119
|
+
}
|
|
118120
|
+
|
|
118121
|
+
// Computes the BLAKE2B hash of a string or byte array, and returns a Uint8Array
|
|
118122
|
+
//
|
|
118123
|
+
// Returns a n-byte Uint8Array
|
|
118124
|
+
//
|
|
118125
|
+
// Parameters:
|
|
118126
|
+
// - input - the input bytes, as a string, Buffer or Uint8Array
|
|
118127
|
+
// - key - optional key Uint8Array, up to 64 bytes
|
|
118128
|
+
// - outlen - optional output length in bytes, default 64
|
|
118129
|
+
// - salt - optional salt bytes, string, Buffer or Uint8Array
|
|
118130
|
+
// - personal - optional personal bytes, string, Buffer or Uint8Array
|
|
118131
|
+
function blake2b (input, key, outlen, salt, personal) {
|
|
118132
|
+
// preprocess inputs
|
|
118133
|
+
outlen = outlen || 64;
|
|
118134
|
+
input = util.normalizeInput(input);
|
|
118135
|
+
if (salt) {
|
|
118136
|
+
salt = util.normalizeInput(salt);
|
|
118137
|
+
}
|
|
118138
|
+
if (personal) {
|
|
118139
|
+
personal = util.normalizeInput(personal);
|
|
118140
|
+
}
|
|
118141
|
+
|
|
118142
|
+
// do the math
|
|
118143
|
+
const ctx = blake2bInit(outlen, key, salt, personal);
|
|
118144
|
+
blake2bUpdate(ctx, input);
|
|
118145
|
+
return blake2bFinal(ctx)
|
|
118146
|
+
}
|
|
118147
|
+
|
|
118148
|
+
// Computes the BLAKE2B hash of a string or byte array
|
|
118149
|
+
//
|
|
118150
|
+
// Returns an n-byte hash in hex, all lowercase
|
|
118151
|
+
//
|
|
118152
|
+
// Parameters:
|
|
118153
|
+
// - input - the input bytes, as a string, Buffer, or Uint8Array
|
|
118154
|
+
// - key - optional key Uint8Array, up to 64 bytes
|
|
118155
|
+
// - outlen - optional output length in bytes, default 64
|
|
118156
|
+
// - salt - optional salt bytes, string, Buffer or Uint8Array
|
|
118157
|
+
// - personal - optional personal bytes, string, Buffer or Uint8Array
|
|
118158
|
+
function blake2bHex (input, key, outlen, salt, personal) {
|
|
118159
|
+
const output = blake2b(input, key, outlen, salt, personal);
|
|
118160
|
+
return util.toHex(output)
|
|
118161
|
+
}
|
|
118162
|
+
|
|
118163
|
+
blake2b_1 = {
|
|
118164
|
+
blake2b: blake2b,
|
|
118165
|
+
blake2bHex: blake2bHex,
|
|
118166
|
+
blake2bInit: blake2bInit,
|
|
118167
|
+
blake2bUpdate: blake2bUpdate,
|
|
118168
|
+
blake2bFinal: blake2bFinal
|
|
118169
|
+
};
|
|
118170
|
+
return blake2b_1;
|
|
118171
|
+
}
|
|
118172
|
+
|
|
118173
|
+
var blake2s_1;
|
|
118174
|
+
var hasRequiredBlake2s;
|
|
118175
|
+
|
|
118176
|
+
function requireBlake2s () {
|
|
118177
|
+
if (hasRequiredBlake2s) return blake2s_1;
|
|
118178
|
+
hasRequiredBlake2s = 1;
|
|
118179
|
+
// BLAKE2s hash function in pure Javascript
|
|
118180
|
+
// Adapted from the reference implementation in RFC7693
|
|
118181
|
+
// Ported to Javascript by DC - https://github.com/dcposch
|
|
118182
|
+
|
|
118183
|
+
const util = requireUtil();
|
|
118184
|
+
|
|
118185
|
+
// Little-endian byte access.
|
|
118186
|
+
// Expects a Uint8Array and an index
|
|
118187
|
+
// Returns the little-endian uint32 at v[i..i+3]
|
|
118188
|
+
function B2S_GET32 (v, i) {
|
|
118189
|
+
return v[i] ^ (v[i + 1] << 8) ^ (v[i + 2] << 16) ^ (v[i + 3] << 24)
|
|
118190
|
+
}
|
|
118191
|
+
|
|
118192
|
+
// Mixing function G.
|
|
118193
|
+
function B2S_G (a, b, c, d, x, y) {
|
|
118194
|
+
v[a] = v[a] + v[b] + x;
|
|
118195
|
+
v[d] = ROTR32(v[d] ^ v[a], 16);
|
|
118196
|
+
v[c] = v[c] + v[d];
|
|
118197
|
+
v[b] = ROTR32(v[b] ^ v[c], 12);
|
|
118198
|
+
v[a] = v[a] + v[b] + y;
|
|
118199
|
+
v[d] = ROTR32(v[d] ^ v[a], 8);
|
|
118200
|
+
v[c] = v[c] + v[d];
|
|
118201
|
+
v[b] = ROTR32(v[b] ^ v[c], 7);
|
|
118202
|
+
}
|
|
118203
|
+
|
|
118204
|
+
// 32-bit right rotation
|
|
118205
|
+
// x should be a uint32
|
|
118206
|
+
// y must be between 1 and 31, inclusive
|
|
118207
|
+
function ROTR32 (x, y) {
|
|
118208
|
+
return (x >>> y) ^ (x << (32 - y))
|
|
118209
|
+
}
|
|
118210
|
+
|
|
118211
|
+
// Initialization Vector.
|
|
118212
|
+
const BLAKE2S_IV = new Uint32Array([
|
|
118213
|
+
0x6a09e667,
|
|
118214
|
+
0xbb67ae85,
|
|
118215
|
+
0x3c6ef372,
|
|
118216
|
+
0xa54ff53a,
|
|
118217
|
+
0x510e527f,
|
|
118218
|
+
0x9b05688c,
|
|
118219
|
+
0x1f83d9ab,
|
|
118220
|
+
0x5be0cd19
|
|
118221
|
+
]);
|
|
118222
|
+
|
|
118223
|
+
const SIGMA = new Uint8Array([
|
|
118224
|
+
0,
|
|
118225
|
+
1,
|
|
118226
|
+
2,
|
|
118227
|
+
3,
|
|
118228
|
+
4,
|
|
118229
|
+
5,
|
|
118230
|
+
6,
|
|
118231
|
+
7,
|
|
118232
|
+
8,
|
|
118233
|
+
9,
|
|
118234
|
+
10,
|
|
118235
|
+
11,
|
|
118236
|
+
12,
|
|
118237
|
+
13,
|
|
118238
|
+
14,
|
|
118239
|
+
15,
|
|
118240
|
+
14,
|
|
118241
|
+
10,
|
|
118242
|
+
4,
|
|
118243
|
+
8,
|
|
118244
|
+
9,
|
|
118245
|
+
15,
|
|
118246
|
+
13,
|
|
118247
|
+
6,
|
|
118248
|
+
1,
|
|
118249
|
+
12,
|
|
118250
|
+
0,
|
|
118251
|
+
2,
|
|
118252
|
+
11,
|
|
118253
|
+
7,
|
|
118254
|
+
5,
|
|
118255
|
+
3,
|
|
118256
|
+
11,
|
|
118257
|
+
8,
|
|
118258
|
+
12,
|
|
118259
|
+
0,
|
|
118260
|
+
5,
|
|
118261
|
+
2,
|
|
118262
|
+
15,
|
|
118263
|
+
13,
|
|
118264
|
+
10,
|
|
118265
|
+
14,
|
|
118266
|
+
3,
|
|
118267
|
+
6,
|
|
118268
|
+
7,
|
|
118269
|
+
1,
|
|
118270
|
+
9,
|
|
118271
|
+
4,
|
|
118272
|
+
7,
|
|
118273
|
+
9,
|
|
118274
|
+
3,
|
|
118275
|
+
1,
|
|
118276
|
+
13,
|
|
118277
|
+
12,
|
|
118278
|
+
11,
|
|
118279
|
+
14,
|
|
118280
|
+
2,
|
|
118281
|
+
6,
|
|
118282
|
+
5,
|
|
118283
|
+
10,
|
|
118284
|
+
4,
|
|
118285
|
+
0,
|
|
118286
|
+
15,
|
|
118287
|
+
8,
|
|
118288
|
+
9,
|
|
118289
|
+
0,
|
|
118290
|
+
5,
|
|
118291
|
+
7,
|
|
118292
|
+
2,
|
|
118293
|
+
4,
|
|
118294
|
+
10,
|
|
118295
|
+
15,
|
|
118296
|
+
14,
|
|
118297
|
+
1,
|
|
118298
|
+
11,
|
|
118299
|
+
12,
|
|
118300
|
+
6,
|
|
118301
|
+
8,
|
|
118302
|
+
3,
|
|
118303
|
+
13,
|
|
118304
|
+
2,
|
|
118305
|
+
12,
|
|
118306
|
+
6,
|
|
118307
|
+
10,
|
|
118308
|
+
0,
|
|
118309
|
+
11,
|
|
118310
|
+
8,
|
|
118311
|
+
3,
|
|
118312
|
+
4,
|
|
118313
|
+
13,
|
|
118314
|
+
7,
|
|
118315
|
+
5,
|
|
118316
|
+
15,
|
|
118317
|
+
14,
|
|
118318
|
+
1,
|
|
118319
|
+
9,
|
|
118320
|
+
12,
|
|
118321
|
+
5,
|
|
118322
|
+
1,
|
|
118323
|
+
15,
|
|
118324
|
+
14,
|
|
118325
|
+
13,
|
|
118326
|
+
4,
|
|
118327
|
+
10,
|
|
118328
|
+
0,
|
|
118329
|
+
7,
|
|
118330
|
+
6,
|
|
118331
|
+
3,
|
|
118332
|
+
9,
|
|
118333
|
+
2,
|
|
118334
|
+
8,
|
|
118335
|
+
11,
|
|
118336
|
+
13,
|
|
118337
|
+
11,
|
|
118338
|
+
7,
|
|
118339
|
+
14,
|
|
118340
|
+
12,
|
|
118341
|
+
1,
|
|
118342
|
+
3,
|
|
118343
|
+
9,
|
|
118344
|
+
5,
|
|
118345
|
+
0,
|
|
118346
|
+
15,
|
|
118347
|
+
4,
|
|
118348
|
+
8,
|
|
118349
|
+
6,
|
|
118350
|
+
2,
|
|
118351
|
+
10,
|
|
118352
|
+
6,
|
|
118353
|
+
15,
|
|
118354
|
+
14,
|
|
118355
|
+
9,
|
|
118356
|
+
11,
|
|
118357
|
+
3,
|
|
118358
|
+
0,
|
|
118359
|
+
8,
|
|
118360
|
+
12,
|
|
118361
|
+
2,
|
|
118362
|
+
13,
|
|
118363
|
+
7,
|
|
118364
|
+
1,
|
|
118365
|
+
4,
|
|
118366
|
+
10,
|
|
118367
|
+
5,
|
|
118368
|
+
10,
|
|
118369
|
+
2,
|
|
118370
|
+
8,
|
|
118371
|
+
4,
|
|
118372
|
+
7,
|
|
118373
|
+
6,
|
|
118374
|
+
1,
|
|
118375
|
+
5,
|
|
118376
|
+
15,
|
|
118377
|
+
11,
|
|
118378
|
+
9,
|
|
118379
|
+
14,
|
|
118380
|
+
3,
|
|
118381
|
+
12,
|
|
118382
|
+
13,
|
|
118383
|
+
0
|
|
118384
|
+
]);
|
|
118385
|
+
|
|
118386
|
+
// Compression function. "last" flag indicates last block
|
|
118387
|
+
const v = new Uint32Array(16);
|
|
118388
|
+
const m = new Uint32Array(16);
|
|
118389
|
+
function blake2sCompress (ctx, last) {
|
|
118390
|
+
let i = 0;
|
|
118391
|
+
for (i = 0; i < 8; i++) {
|
|
118392
|
+
// init work variables
|
|
118393
|
+
v[i] = ctx.h[i];
|
|
118394
|
+
v[i + 8] = BLAKE2S_IV[i];
|
|
118395
|
+
}
|
|
118396
|
+
|
|
118397
|
+
v[12] ^= ctx.t; // low 32 bits of offset
|
|
118398
|
+
v[13] ^= ctx.t / 0x100000000; // high 32 bits
|
|
118399
|
+
if (last) {
|
|
118400
|
+
// last block flag set ?
|
|
118401
|
+
v[14] = ~v[14];
|
|
118402
|
+
}
|
|
118403
|
+
|
|
118404
|
+
for (i = 0; i < 16; i++) {
|
|
118405
|
+
// get little-endian words
|
|
118406
|
+
m[i] = B2S_GET32(ctx.b, 4 * i);
|
|
118407
|
+
}
|
|
118408
|
+
|
|
118409
|
+
// ten rounds of mixing
|
|
118410
|
+
// uncomment the DebugPrint calls to log the computation
|
|
118411
|
+
// and match the RFC sample documentation
|
|
118412
|
+
// util.debugPrint(' m[16]', m, 32)
|
|
118413
|
+
for (i = 0; i < 10; i++) {
|
|
118414
|
+
// util.debugPrint(' (i=' + i + ') v[16]', v, 32)
|
|
118415
|
+
B2S_G(0, 4, 8, 12, m[SIGMA[i * 16 + 0]], m[SIGMA[i * 16 + 1]]);
|
|
118416
|
+
B2S_G(1, 5, 9, 13, m[SIGMA[i * 16 + 2]], m[SIGMA[i * 16 + 3]]);
|
|
118417
|
+
B2S_G(2, 6, 10, 14, m[SIGMA[i * 16 + 4]], m[SIGMA[i * 16 + 5]]);
|
|
118418
|
+
B2S_G(3, 7, 11, 15, m[SIGMA[i * 16 + 6]], m[SIGMA[i * 16 + 7]]);
|
|
118419
|
+
B2S_G(0, 5, 10, 15, m[SIGMA[i * 16 + 8]], m[SIGMA[i * 16 + 9]]);
|
|
118420
|
+
B2S_G(1, 6, 11, 12, m[SIGMA[i * 16 + 10]], m[SIGMA[i * 16 + 11]]);
|
|
118421
|
+
B2S_G(2, 7, 8, 13, m[SIGMA[i * 16 + 12]], m[SIGMA[i * 16 + 13]]);
|
|
118422
|
+
B2S_G(3, 4, 9, 14, m[SIGMA[i * 16 + 14]], m[SIGMA[i * 16 + 15]]);
|
|
118423
|
+
}
|
|
118424
|
+
// util.debugPrint(' (i=10) v[16]', v, 32)
|
|
118425
|
+
|
|
118426
|
+
for (i = 0; i < 8; i++) {
|
|
118427
|
+
ctx.h[i] ^= v[i] ^ v[i + 8];
|
|
118428
|
+
}
|
|
118429
|
+
// util.debugPrint('h[8]', ctx.h, 32)
|
|
118430
|
+
}
|
|
118431
|
+
|
|
118432
|
+
// Creates a BLAKE2s hashing context
|
|
118433
|
+
// Requires an output length between 1 and 32 bytes
|
|
118434
|
+
// Takes an optional Uint8Array key
|
|
118435
|
+
function blake2sInit (outlen, key) {
|
|
118436
|
+
if (!(outlen > 0 && outlen <= 32)) {
|
|
118437
|
+
throw new Error('Incorrect output length, should be in [1, 32]')
|
|
118438
|
+
}
|
|
118439
|
+
const keylen = key ? key.length : 0;
|
|
118440
|
+
if (key && !(keylen > 0 && keylen <= 32)) {
|
|
118441
|
+
throw new Error('Incorrect key length, should be in [1, 32]')
|
|
118442
|
+
}
|
|
118443
|
+
|
|
118444
|
+
const ctx = {
|
|
118445
|
+
h: new Uint32Array(BLAKE2S_IV), // hash state
|
|
118446
|
+
b: new Uint8Array(64), // input block
|
|
118447
|
+
c: 0, // pointer within block
|
|
118448
|
+
t: 0, // input count
|
|
118449
|
+
outlen: outlen // output length in bytes
|
|
118450
|
+
};
|
|
118451
|
+
ctx.h[0] ^= 0x01010000 ^ (keylen << 8) ^ outlen;
|
|
118452
|
+
|
|
118453
|
+
if (keylen > 0) {
|
|
118454
|
+
blake2sUpdate(ctx, key);
|
|
118455
|
+
ctx.c = 64; // at the end
|
|
118456
|
+
}
|
|
118457
|
+
|
|
118458
|
+
return ctx
|
|
118459
|
+
}
|
|
118460
|
+
|
|
118461
|
+
// Updates a BLAKE2s streaming hash
|
|
118462
|
+
// Requires hash context and Uint8Array (byte array)
|
|
118463
|
+
function blake2sUpdate (ctx, input) {
|
|
118464
|
+
for (let i = 0; i < input.length; i++) {
|
|
118465
|
+
if (ctx.c === 64) {
|
|
118466
|
+
// buffer full ?
|
|
118467
|
+
ctx.t += ctx.c; // add counters
|
|
118468
|
+
blake2sCompress(ctx, false); // compress (not last)
|
|
118469
|
+
ctx.c = 0; // counter to zero
|
|
118470
|
+
}
|
|
118471
|
+
ctx.b[ctx.c++] = input[i];
|
|
118472
|
+
}
|
|
118473
|
+
}
|
|
118474
|
+
|
|
118475
|
+
// Completes a BLAKE2s streaming hash
|
|
118476
|
+
// Returns a Uint8Array containing the message digest
|
|
118477
|
+
function blake2sFinal (ctx) {
|
|
118478
|
+
ctx.t += ctx.c; // mark last block offset
|
|
118479
|
+
while (ctx.c < 64) {
|
|
118480
|
+
// fill up with zeros
|
|
118481
|
+
ctx.b[ctx.c++] = 0;
|
|
118482
|
+
}
|
|
118483
|
+
blake2sCompress(ctx, true); // final block flag = 1
|
|
118484
|
+
|
|
118485
|
+
// little endian convert and store
|
|
118486
|
+
const out = new Uint8Array(ctx.outlen);
|
|
118487
|
+
for (let i = 0; i < ctx.outlen; i++) {
|
|
118488
|
+
out[i] = (ctx.h[i >> 2] >> (8 * (i & 3))) & 0xff;
|
|
118489
|
+
}
|
|
118490
|
+
return out
|
|
118491
|
+
}
|
|
118492
|
+
|
|
118493
|
+
// Computes the BLAKE2S hash of a string or byte array, and returns a Uint8Array
|
|
118494
|
+
//
|
|
118495
|
+
// Returns a n-byte Uint8Array
|
|
118496
|
+
//
|
|
118497
|
+
// Parameters:
|
|
118498
|
+
// - input - the input bytes, as a string, Buffer, or Uint8Array
|
|
118499
|
+
// - key - optional key Uint8Array, up to 32 bytes
|
|
118500
|
+
// - outlen - optional output length in bytes, default 64
|
|
118501
|
+
function blake2s (input, key, outlen) {
|
|
118502
|
+
// preprocess inputs
|
|
118503
|
+
outlen = outlen || 32;
|
|
118504
|
+
input = util.normalizeInput(input);
|
|
118505
|
+
|
|
118506
|
+
// do the math
|
|
118507
|
+
const ctx = blake2sInit(outlen, key);
|
|
118508
|
+
blake2sUpdate(ctx, input);
|
|
118509
|
+
return blake2sFinal(ctx)
|
|
118510
|
+
}
|
|
118511
|
+
|
|
118512
|
+
// Computes the BLAKE2S hash of a string or byte array
|
|
118513
|
+
//
|
|
118514
|
+
// Returns an n-byte hash in hex, all lowercase
|
|
118515
|
+
//
|
|
118516
|
+
// Parameters:
|
|
118517
|
+
// - input - the input bytes, as a string, Buffer, or Uint8Array
|
|
118518
|
+
// - key - optional key Uint8Array, up to 32 bytes
|
|
118519
|
+
// - outlen - optional output length in bytes, default 64
|
|
118520
|
+
function blake2sHex (input, key, outlen) {
|
|
118521
|
+
const output = blake2s(input, key, outlen);
|
|
118522
|
+
return util.toHex(output)
|
|
118523
|
+
}
|
|
118524
|
+
|
|
118525
|
+
blake2s_1 = {
|
|
118526
|
+
blake2s: blake2s,
|
|
118527
|
+
blake2sHex: blake2sHex,
|
|
118528
|
+
blake2sInit: blake2sInit,
|
|
118529
|
+
blake2sUpdate: blake2sUpdate,
|
|
118530
|
+
blake2sFinal: blake2sFinal
|
|
118531
|
+
};
|
|
118532
|
+
return blake2s_1;
|
|
118533
|
+
}
|
|
118534
|
+
|
|
118535
|
+
var blakejs;
|
|
118536
|
+
var hasRequiredBlakejs;
|
|
118537
|
+
|
|
118538
|
+
function requireBlakejs () {
|
|
118539
|
+
if (hasRequiredBlakejs) return blakejs;
|
|
118540
|
+
hasRequiredBlakejs = 1;
|
|
118541
|
+
const b2b = requireBlake2b();
|
|
118542
|
+
const b2s = requireBlake2s();
|
|
118543
|
+
|
|
118544
|
+
blakejs = {
|
|
118545
|
+
blake2b: b2b.blake2b,
|
|
118546
|
+
blake2bHex: b2b.blake2bHex,
|
|
118547
|
+
blake2bInit: b2b.blake2bInit,
|
|
118548
|
+
blake2bUpdate: b2b.blake2bUpdate,
|
|
118549
|
+
blake2bFinal: b2b.blake2bFinal,
|
|
118550
|
+
blake2s: b2s.blake2s,
|
|
118551
|
+
blake2sHex: b2s.blake2sHex,
|
|
118552
|
+
blake2sInit: b2s.blake2sInit,
|
|
118553
|
+
blake2sUpdate: b2s.blake2sUpdate,
|
|
118554
|
+
blake2sFinal: b2s.blake2sFinal
|
|
118555
|
+
};
|
|
118556
|
+
return blakejs;
|
|
118557
|
+
}
|
|
118521
118558
|
|
|
118522
118559
|
var hasRequiredHash;
|
|
118523
118560
|
|
|
@@ -118526,12 +118563,12 @@ function requireHash () {
|
|
|
118526
118563
|
hasRequiredHash = 1;
|
|
118527
118564
|
Object.defineProperty(hash, "__esModule", { value: true });
|
|
118528
118565
|
hash.ripemd160 = hash.blake128WithKey = hash.blake128 = hash.blake160WithKey = hash.blake160 = hash.blake256WithKey = hash.blake256 = void 0;
|
|
118529
|
-
const crypto_js_1 =
|
|
118566
|
+
const crypto_js_1 = requireCryptoJs();
|
|
118530
118567
|
const utility_1 = requireUtility();
|
|
118531
118568
|
/**
|
|
118532
118569
|
* @hidden
|
|
118533
118570
|
*/
|
|
118534
|
-
const blake =
|
|
118571
|
+
const blake = requireBlakejs();
|
|
118535
118572
|
/**
|
|
118536
118573
|
* Gets data's 256 bit blake hash.
|
|
118537
118574
|
* @param data buffer or hexadecimal string
|
|
@@ -127756,7 +127793,7 @@ const getDefaultClientUrls = () => {
|
|
|
127756
127793
|
return {
|
|
127757
127794
|
[Network.Testnet]: ['deprecated'],
|
|
127758
127795
|
[Network.Stagenet]: ['https://stagenet-rpc.ninerealms.com'],
|
|
127759
|
-
[Network.Mainnet]: ['https://rpc
|
|
127796
|
+
[Network.Mainnet]: ['https://rpc.ninerealms.com'],
|
|
127760
127797
|
};
|
|
127761
127798
|
};
|
|
127762
127799
|
/**
|