@xchainjs/xchain-thorchain 1.0.11 → 1.1.1
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/client.d.ts +4 -91
- package/lib/clientKeystore.d.ts +97 -0
- package/lib/clientLedger.d.ts +70 -0
- package/lib/index.d.ts +2 -1
- package/lib/index.esm.js +1307 -988
- package/lib/index.esm.js.map +1 -1
- package/lib/index.js +1310 -985
- package/lib/index.js.map +1 -1
- package/lib/utils.d.ts +16 -3
- package/package.json +6 -4
package/lib/index.js
CHANGED
|
@@ -12,10 +12,11 @@ var crypto$3 = require('crypto');
|
|
|
12
12
|
var buffer = require('buffer');
|
|
13
13
|
var bignumber = require('bignumber.js');
|
|
14
14
|
var bech32$1 = require('bech32');
|
|
15
|
-
var xchainUtil = require('@xchainjs/xchain-util');
|
|
16
15
|
var bip32 = require('bip32');
|
|
17
16
|
var secp256k1 = require('secp256k1');
|
|
17
|
+
var xchainUtil = require('@xchainjs/xchain-util');
|
|
18
18
|
var xchainClient = require('@xchainjs/xchain-client');
|
|
19
|
+
var THORChainApp = require('@xchainjs/ledger-thorchain');
|
|
19
20
|
|
|
20
21
|
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
21
22
|
|
|
@@ -45,6 +46,7 @@ var axios__namespace = /*#__PURE__*/_interopNamespace(axios);
|
|
|
45
46
|
var axios__default = /*#__PURE__*/_interopDefaultLegacy(axios);
|
|
46
47
|
var buffer__namespace = /*#__PURE__*/_interopNamespace(buffer);
|
|
47
48
|
var bignumber__namespace = /*#__PURE__*/_interopNamespace(bignumber);
|
|
49
|
+
var THORChainApp__default = /*#__PURE__*/_interopDefaultLegacy(THORChainApp);
|
|
48
50
|
|
|
49
51
|
/******************************************************************************
|
|
50
52
|
Copyright (c) Microsoft Corporation.
|
|
@@ -5538,13 +5540,13 @@ function requireMinimal () {
|
|
|
5538
5540
|
|
|
5539
5541
|
var writer = Writer$1;
|
|
5540
5542
|
|
|
5541
|
-
var util$
|
|
5543
|
+
var util$5 = requireMinimal();
|
|
5542
5544
|
|
|
5543
5545
|
var BufferWriter$1; // cyclic
|
|
5544
5546
|
|
|
5545
|
-
var LongBits$1 = util$
|
|
5546
|
-
base64 = util$
|
|
5547
|
-
utf8$1 = util$
|
|
5547
|
+
var LongBits$1 = util$5.LongBits,
|
|
5548
|
+
base64 = util$5.base64,
|
|
5549
|
+
utf8$1 = util$5.utf8;
|
|
5548
5550
|
|
|
5549
5551
|
/**
|
|
5550
5552
|
* Constructs a new writer operation instance.
|
|
@@ -5659,7 +5661,7 @@ function Writer$1() {
|
|
|
5659
5661
|
}
|
|
5660
5662
|
|
|
5661
5663
|
var create$1 = function create() {
|
|
5662
|
-
return util$
|
|
5664
|
+
return util$5.Buffer
|
|
5663
5665
|
? function create_buffer_setup() {
|
|
5664
5666
|
return (Writer$1.create = function create_buffer() {
|
|
5665
5667
|
return new BufferWriter$1();
|
|
@@ -5684,13 +5686,13 @@ Writer$1.create = create$1();
|
|
|
5684
5686
|
* @returns {Uint8Array} Buffer
|
|
5685
5687
|
*/
|
|
5686
5688
|
Writer$1.alloc = function alloc(size) {
|
|
5687
|
-
return new util$
|
|
5689
|
+
return new util$5.Array(size);
|
|
5688
5690
|
};
|
|
5689
5691
|
|
|
5690
5692
|
// Use Uint8Array buffer pool in the browser, just like node does with buffers
|
|
5691
5693
|
/* istanbul ignore else */
|
|
5692
|
-
if (util$
|
|
5693
|
-
Writer$1.alloc = util$
|
|
5694
|
+
if (util$5.Array !== Array)
|
|
5695
|
+
Writer$1.alloc = util$5.pool(Writer$1.alloc, util$5.Array.prototype.subarray);
|
|
5694
5696
|
|
|
5695
5697
|
/**
|
|
5696
5698
|
* Pushes a new operation to the queue.
|
|
@@ -5880,7 +5882,7 @@ Writer$1.prototype.sfixed64 = Writer$1.prototype.fixed64;
|
|
|
5880
5882
|
* @returns {Writer} `this`
|
|
5881
5883
|
*/
|
|
5882
5884
|
Writer$1.prototype.float = function write_float(value) {
|
|
5883
|
-
return this._push(util$
|
|
5885
|
+
return this._push(util$5.float.writeFloatLE, 4, value);
|
|
5884
5886
|
};
|
|
5885
5887
|
|
|
5886
5888
|
/**
|
|
@@ -5890,10 +5892,10 @@ Writer$1.prototype.float = function write_float(value) {
|
|
|
5890
5892
|
* @returns {Writer} `this`
|
|
5891
5893
|
*/
|
|
5892
5894
|
Writer$1.prototype.double = function write_double(value) {
|
|
5893
|
-
return this._push(util$
|
|
5895
|
+
return this._push(util$5.float.writeDoubleLE, 8, value);
|
|
5894
5896
|
};
|
|
5895
5897
|
|
|
5896
|
-
var writeBytes = util$
|
|
5898
|
+
var writeBytes = util$5.Array.prototype.set
|
|
5897
5899
|
? function writeBytes_set(val, buf, pos) {
|
|
5898
5900
|
buf.set(val, pos); // also works for plain array values
|
|
5899
5901
|
}
|
|
@@ -5912,7 +5914,7 @@ Writer$1.prototype.bytes = function write_bytes(value) {
|
|
|
5912
5914
|
var len = value.length >>> 0;
|
|
5913
5915
|
if (!len)
|
|
5914
5916
|
return this._push(writeByte, 1, 0);
|
|
5915
|
-
if (util$
|
|
5917
|
+
if (util$5.isString(value)) {
|
|
5916
5918
|
var buf = Writer$1.alloc(len = base64.length(value));
|
|
5917
5919
|
base64.decode(value, buf, 0);
|
|
5918
5920
|
value = buf;
|
|
@@ -6007,7 +6009,7 @@ var writer_buffer = BufferWriter;
|
|
|
6007
6009
|
var Writer = writer;
|
|
6008
6010
|
(BufferWriter.prototype = Object.create(Writer.prototype)).constructor = BufferWriter;
|
|
6009
6011
|
|
|
6010
|
-
var util$
|
|
6012
|
+
var util$4 = requireMinimal();
|
|
6011
6013
|
|
|
6012
6014
|
/**
|
|
6013
6015
|
* Constructs a new buffer writer instance.
|
|
@@ -6026,9 +6028,9 @@ BufferWriter._configure = function () {
|
|
|
6026
6028
|
* @param {number} size Buffer size
|
|
6027
6029
|
* @returns {Buffer} Buffer
|
|
6028
6030
|
*/
|
|
6029
|
-
BufferWriter.alloc = util$
|
|
6031
|
+
BufferWriter.alloc = util$4._Buffer_allocUnsafe;
|
|
6030
6032
|
|
|
6031
|
-
BufferWriter.writeBytesBuffer = util$
|
|
6033
|
+
BufferWriter.writeBytesBuffer = util$4.Buffer && util$4.Buffer.prototype instanceof Uint8Array && util$4.Buffer.prototype.set.name === "set"
|
|
6032
6034
|
? function writeBytesBuffer_set(val, buf, pos) {
|
|
6033
6035
|
buf.set(val, pos); // faster than copy (requires node >= 4 where Buffers extend Uint8Array and set is properly inherited)
|
|
6034
6036
|
// also works for plain array values
|
|
@@ -6047,8 +6049,8 @@ BufferWriter._configure = function () {
|
|
|
6047
6049
|
* @override
|
|
6048
6050
|
*/
|
|
6049
6051
|
BufferWriter.prototype.bytes = function write_bytes_buffer(value) {
|
|
6050
|
-
if (util$
|
|
6051
|
-
value = util$
|
|
6052
|
+
if (util$4.isString(value))
|
|
6053
|
+
value = util$4._Buffer_from(value, "base64");
|
|
6052
6054
|
var len = value.length >>> 0;
|
|
6053
6055
|
this.uint32(len);
|
|
6054
6056
|
if (len)
|
|
@@ -6058,7 +6060,7 @@ BufferWriter.prototype.bytes = function write_bytes_buffer(value) {
|
|
|
6058
6060
|
|
|
6059
6061
|
function writeStringBuffer(val, buf, pos) {
|
|
6060
6062
|
if (val.length < 40) // plain js is faster for short strings (probably due to redundant assertions)
|
|
6061
|
-
util$
|
|
6063
|
+
util$4.utf8.write(val, buf, pos);
|
|
6062
6064
|
else if (buf.utf8Write)
|
|
6063
6065
|
buf.utf8Write(val, pos);
|
|
6064
6066
|
else
|
|
@@ -6069,7 +6071,7 @@ function writeStringBuffer(val, buf, pos) {
|
|
|
6069
6071
|
* @override
|
|
6070
6072
|
*/
|
|
6071
6073
|
BufferWriter.prototype.string = function write_string_buffer(value) {
|
|
6072
|
-
var len = util$
|
|
6074
|
+
var len = util$4.Buffer.byteLength(value);
|
|
6073
6075
|
this.uint32(len);
|
|
6074
6076
|
if (len)
|
|
6075
6077
|
this._push(writeStringBuffer, len, value);
|
|
@@ -6088,12 +6090,12 @@ BufferWriter._configure();
|
|
|
6088
6090
|
|
|
6089
6091
|
var reader = Reader$1;
|
|
6090
6092
|
|
|
6091
|
-
var util$
|
|
6093
|
+
var util$3 = requireMinimal();
|
|
6092
6094
|
|
|
6093
6095
|
var BufferReader$1; // cyclic
|
|
6094
6096
|
|
|
6095
|
-
var LongBits = util$
|
|
6096
|
-
utf8 = util$
|
|
6097
|
+
var LongBits = util$3.LongBits,
|
|
6098
|
+
utf8 = util$3.utf8;
|
|
6097
6099
|
|
|
6098
6100
|
/* istanbul ignore next */
|
|
6099
6101
|
function indexOutOfRange(reader, writeLength) {
|
|
@@ -6141,10 +6143,10 @@ var create_array = typeof Uint8Array !== "undefined"
|
|
|
6141
6143
|
};
|
|
6142
6144
|
|
|
6143
6145
|
var create = function create() {
|
|
6144
|
-
return util$
|
|
6146
|
+
return util$3.Buffer
|
|
6145
6147
|
? function create_buffer_setup(buffer) {
|
|
6146
6148
|
return (Reader$1.create = function create_buffer(buffer) {
|
|
6147
|
-
return util$
|
|
6149
|
+
return util$3.Buffer.isBuffer(buffer)
|
|
6148
6150
|
? new BufferReader$1(buffer)
|
|
6149
6151
|
/* istanbul ignore next */
|
|
6150
6152
|
: create_array(buffer);
|
|
@@ -6163,7 +6165,7 @@ var create = function create() {
|
|
|
6163
6165
|
*/
|
|
6164
6166
|
Reader$1.create = create();
|
|
6165
6167
|
|
|
6166
|
-
Reader$1.prototype._slice = util$
|
|
6168
|
+
Reader$1.prototype._slice = util$3.Array.prototype.subarray || /* istanbul ignore next */ util$3.Array.prototype.slice;
|
|
6167
6169
|
|
|
6168
6170
|
/**
|
|
6169
6171
|
* Reads a varint as an unsigned 32 bit value.
|
|
@@ -6362,7 +6364,7 @@ Reader$1.prototype.float = function read_float() {
|
|
|
6362
6364
|
if (this.pos + 4 > this.len)
|
|
6363
6365
|
throw indexOutOfRange(this, 4);
|
|
6364
6366
|
|
|
6365
|
-
var value = util$
|
|
6367
|
+
var value = util$3.float.readFloatLE(this.buf, this.pos);
|
|
6366
6368
|
this.pos += 4;
|
|
6367
6369
|
return value;
|
|
6368
6370
|
};
|
|
@@ -6378,7 +6380,7 @@ Reader$1.prototype.double = function read_double() {
|
|
|
6378
6380
|
if (this.pos + 8 > this.len)
|
|
6379
6381
|
throw indexOutOfRange(this, 4);
|
|
6380
6382
|
|
|
6381
|
-
var value = util$
|
|
6383
|
+
var value = util$3.float.readDoubleLE(this.buf, this.pos);
|
|
6382
6384
|
this.pos += 8;
|
|
6383
6385
|
return value;
|
|
6384
6386
|
};
|
|
@@ -6471,8 +6473,8 @@ Reader$1._configure = function(BufferReader_) {
|
|
|
6471
6473
|
Reader$1.create = create();
|
|
6472
6474
|
BufferReader$1._configure();
|
|
6473
6475
|
|
|
6474
|
-
var fn = util$
|
|
6475
|
-
util$
|
|
6476
|
+
var fn = util$3.Long ? "toLong" : /* istanbul ignore next */ "toNumber";
|
|
6477
|
+
util$3.merge(Reader$1.prototype, {
|
|
6476
6478
|
|
|
6477
6479
|
int64: function read_int64() {
|
|
6478
6480
|
return readLongVarint.call(this)[fn](false);
|
|
@@ -6503,7 +6505,7 @@ var reader_buffer = BufferReader;
|
|
|
6503
6505
|
var Reader = reader;
|
|
6504
6506
|
(BufferReader.prototype = Object.create(Reader.prototype)).constructor = BufferReader;
|
|
6505
6507
|
|
|
6506
|
-
var util$
|
|
6508
|
+
var util$2 = requireMinimal();
|
|
6507
6509
|
|
|
6508
6510
|
/**
|
|
6509
6511
|
* Constructs a new buffer reader instance.
|
|
@@ -6524,8 +6526,8 @@ function BufferReader(buffer) {
|
|
|
6524
6526
|
|
|
6525
6527
|
BufferReader._configure = function () {
|
|
6526
6528
|
/* istanbul ignore else */
|
|
6527
|
-
if (util$
|
|
6528
|
-
BufferReader.prototype._slice = util$
|
|
6529
|
+
if (util$2.Buffer)
|
|
6530
|
+
BufferReader.prototype._slice = util$2.Buffer.prototype.slice;
|
|
6529
6531
|
};
|
|
6530
6532
|
|
|
6531
6533
|
|
|
@@ -6552,10 +6554,10 @@ var rpc = {};
|
|
|
6552
6554
|
|
|
6553
6555
|
var service$1 = Service;
|
|
6554
6556
|
|
|
6555
|
-
var util$
|
|
6557
|
+
var util$1 = requireMinimal();
|
|
6556
6558
|
|
|
6557
6559
|
// Extends EventEmitter
|
|
6558
|
-
(Service.prototype = Object.create(util$
|
|
6560
|
+
(Service.prototype = Object.create(util$1.EventEmitter.prototype)).constructor = Service;
|
|
6559
6561
|
|
|
6560
6562
|
/**
|
|
6561
6563
|
* A service method callback as used by {@link rpc.ServiceMethod|ServiceMethod}.
|
|
@@ -6595,7 +6597,7 @@ function Service(rpcImpl, requestDelimited, responseDelimited) {
|
|
|
6595
6597
|
if (typeof rpcImpl !== "function")
|
|
6596
6598
|
throw TypeError("rpcImpl must be a function");
|
|
6597
6599
|
|
|
6598
|
-
util$
|
|
6600
|
+
util$1.EventEmitter.call(this);
|
|
6599
6601
|
|
|
6600
6602
|
/**
|
|
6601
6603
|
* RPC implementation. Becomes `null` once the service is ended.
|
|
@@ -6634,7 +6636,7 @@ Service.prototype.rpcCall = function rpcCall(method, requestCtor, responseCtor,
|
|
|
6634
6636
|
|
|
6635
6637
|
var self = this;
|
|
6636
6638
|
if (!callback)
|
|
6637
|
-
return util$
|
|
6639
|
+
return util$1.asPromise(rpcCall, self, method, requestCtor, responseCtor, request);
|
|
6638
6640
|
|
|
6639
6641
|
if (!self.rpcImpl) {
|
|
6640
6642
|
setTimeout(function() { callback(Error("already ended")); }, 0);
|
|
@@ -115207,20 +115209,25 @@ function requireBlowfish () {
|
|
|
115207
115209
|
|
|
115208
115210
|
cryptoJs.exports;
|
|
115209
115211
|
|
|
115210
|
-
|
|
115211
|
-
(function (root, factory, undef) {
|
|
115212
|
-
{
|
|
115213
|
-
// CommonJS
|
|
115214
|
-
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());
|
|
115215
|
-
}
|
|
115216
|
-
}(commonjsGlobal$1, function (CryptoJS) {
|
|
115212
|
+
var hasRequiredCryptoJs;
|
|
115217
115213
|
|
|
115218
|
-
|
|
115214
|
+
function requireCryptoJs () {
|
|
115215
|
+
if (hasRequiredCryptoJs) return cryptoJs.exports;
|
|
115216
|
+
hasRequiredCryptoJs = 1;
|
|
115217
|
+
(function (module, exports) {
|
|
115218
|
+
(function (root, factory, undef) {
|
|
115219
|
+
{
|
|
115220
|
+
// CommonJS
|
|
115221
|
+
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());
|
|
115222
|
+
}
|
|
115223
|
+
}(commonjsGlobal$1, function (CryptoJS) {
|
|
115219
115224
|
|
|
115220
|
-
|
|
115221
|
-
} (cryptoJs, cryptoJs.exports));
|
|
115225
|
+
return CryptoJS;
|
|
115222
115226
|
|
|
115223
|
-
|
|
115227
|
+
}));
|
|
115228
|
+
} (cryptoJs, cryptoJs.exports));
|
|
115229
|
+
return cryptoJs.exports;
|
|
115230
|
+
}
|
|
115224
115231
|
|
|
115225
115232
|
var utility = {};
|
|
115226
115233
|
|
|
@@ -117725,826 +117732,858 @@ function requireUtility () {
|
|
|
117725
117732
|
return utility;
|
|
117726
117733
|
}
|
|
117727
117734
|
|
|
117728
|
-
|
|
117729
|
-
|
|
117730
|
-
// For convenience, let people hash a string, not just a Uint8Array
|
|
117731
|
-
function normalizeInput (input) {
|
|
117732
|
-
let ret;
|
|
117733
|
-
if (input instanceof Uint8Array) {
|
|
117734
|
-
ret = input;
|
|
117735
|
-
} else if (typeof input === 'string') {
|
|
117736
|
-
const encoder = new TextEncoder();
|
|
117737
|
-
ret = encoder.encode(input);
|
|
117738
|
-
} else {
|
|
117739
|
-
throw new Error(ERROR_MSG_INPUT)
|
|
117740
|
-
}
|
|
117741
|
-
return ret
|
|
117742
|
-
}
|
|
117743
|
-
|
|
117744
|
-
// Converts a Uint8Array to a hexadecimal string
|
|
117745
|
-
// For example, toHex([255, 0, 255]) returns "ff00ff"
|
|
117746
|
-
function toHex (bytes) {
|
|
117747
|
-
return Array.prototype.map
|
|
117748
|
-
.call(bytes, function (n) {
|
|
117749
|
-
return (n < 16 ? '0' : '') + n.toString(16)
|
|
117750
|
-
})
|
|
117751
|
-
.join('')
|
|
117752
|
-
}
|
|
117753
|
-
|
|
117754
|
-
// Converts any value in [0...2^32-1] to an 8-character hex string
|
|
117755
|
-
function uint32ToHex (val) {
|
|
117756
|
-
return (0x100000000 + val).toString(16).substring(1)
|
|
117757
|
-
}
|
|
117758
|
-
|
|
117759
|
-
// For debugging: prints out hash state in the same format as the RFC
|
|
117760
|
-
// sample computation exactly, so that you can diff
|
|
117761
|
-
function debugPrint (label, arr, size) {
|
|
117762
|
-
let msg = '\n' + label + ' = ';
|
|
117763
|
-
for (let i = 0; i < arr.length; i += 2) {
|
|
117764
|
-
if (size === 32) {
|
|
117765
|
-
msg += uint32ToHex(arr[i]).toUpperCase();
|
|
117766
|
-
msg += ' ';
|
|
117767
|
-
msg += uint32ToHex(arr[i + 1]).toUpperCase();
|
|
117768
|
-
} else if (size === 64) {
|
|
117769
|
-
msg += uint32ToHex(arr[i + 1]).toUpperCase();
|
|
117770
|
-
msg += uint32ToHex(arr[i]).toUpperCase();
|
|
117771
|
-
} else throw new Error('Invalid size ' + size)
|
|
117772
|
-
if (i % 6 === 4) {
|
|
117773
|
-
msg += '\n' + new Array(label.length + 4).join(' ');
|
|
117774
|
-
} else if (i < arr.length - 2) {
|
|
117775
|
-
msg += ' ';
|
|
117776
|
-
}
|
|
117777
|
-
}
|
|
117778
|
-
console.log(msg);
|
|
117779
|
-
}
|
|
117780
|
-
|
|
117781
|
-
// For performance testing: generates N bytes of input, hashes M times
|
|
117782
|
-
// Measures and prints MB/second hash performance each time
|
|
117783
|
-
function testSpeed (hashFn, N, M) {
|
|
117784
|
-
let startMs = new Date().getTime();
|
|
117785
|
-
|
|
117786
|
-
const input = new Uint8Array(N);
|
|
117787
|
-
for (let i = 0; i < N; i++) {
|
|
117788
|
-
input[i] = i % 256;
|
|
117789
|
-
}
|
|
117790
|
-
const genMs = new Date().getTime();
|
|
117791
|
-
console.log('Generated random input in ' + (genMs - startMs) + 'ms');
|
|
117792
|
-
startMs = genMs;
|
|
117793
|
-
|
|
117794
|
-
for (let i = 0; i < M; i++) {
|
|
117795
|
-
const hashHex = hashFn(input);
|
|
117796
|
-
const hashMs = new Date().getTime();
|
|
117797
|
-
const ms = hashMs - startMs;
|
|
117798
|
-
startMs = hashMs;
|
|
117799
|
-
console.log('Hashed in ' + ms + 'ms: ' + hashHex.substring(0, 20) + '...');
|
|
117800
|
-
console.log(
|
|
117801
|
-
Math.round((N / (1 << 20) / (ms / 1000)) * 100) / 100 + ' MB PER SECOND'
|
|
117802
|
-
);
|
|
117803
|
-
}
|
|
117804
|
-
}
|
|
117805
|
-
|
|
117806
|
-
var util$2 = {
|
|
117807
|
-
normalizeInput: normalizeInput,
|
|
117808
|
-
toHex: toHex,
|
|
117809
|
-
debugPrint: debugPrint,
|
|
117810
|
-
testSpeed: testSpeed
|
|
117811
|
-
};
|
|
117735
|
+
var util;
|
|
117736
|
+
var hasRequiredUtil;
|
|
117812
117737
|
|
|
117813
|
-
|
|
117814
|
-
|
|
117815
|
-
|
|
117816
|
-
|
|
117817
|
-
const util$1 = util$2;
|
|
117818
|
-
|
|
117819
|
-
// 64-bit unsigned addition
|
|
117820
|
-
// Sets v[a,a+1] += v[b,b+1]
|
|
117821
|
-
// v should be a Uint32Array
|
|
117822
|
-
function ADD64AA (v, a, b) {
|
|
117823
|
-
const o0 = v[a] + v[b];
|
|
117824
|
-
let o1 = v[a + 1] + v[b + 1];
|
|
117825
|
-
if (o0 >= 0x100000000) {
|
|
117826
|
-
o1++;
|
|
117827
|
-
}
|
|
117828
|
-
v[a] = o0;
|
|
117829
|
-
v[a + 1] = o1;
|
|
117830
|
-
}
|
|
117831
|
-
|
|
117832
|
-
// 64-bit unsigned addition
|
|
117833
|
-
// Sets v[a,a+1] += b
|
|
117834
|
-
// b0 is the low 32 bits of b, b1 represents the high 32 bits
|
|
117835
|
-
function ADD64AC (v, a, b0, b1) {
|
|
117836
|
-
let o0 = v[a] + b0;
|
|
117837
|
-
if (b0 < 0) {
|
|
117838
|
-
o0 += 0x100000000;
|
|
117839
|
-
}
|
|
117840
|
-
let o1 = v[a + 1] + b1;
|
|
117841
|
-
if (o0 >= 0x100000000) {
|
|
117842
|
-
o1++;
|
|
117843
|
-
}
|
|
117844
|
-
v[a] = o0;
|
|
117845
|
-
v[a + 1] = o1;
|
|
117846
|
-
}
|
|
117847
|
-
|
|
117848
|
-
// Little-endian byte access
|
|
117849
|
-
function B2B_GET32 (arr, i) {
|
|
117850
|
-
return arr[i] ^ (arr[i + 1] << 8) ^ (arr[i + 2] << 16) ^ (arr[i + 3] << 24)
|
|
117851
|
-
}
|
|
117852
|
-
|
|
117853
|
-
// G Mixing function
|
|
117854
|
-
// The ROTRs are inlined for speed
|
|
117855
|
-
function B2B_G (a, b, c, d, ix, iy) {
|
|
117856
|
-
const x0 = m$1[ix];
|
|
117857
|
-
const x1 = m$1[ix + 1];
|
|
117858
|
-
const y0 = m$1[iy];
|
|
117859
|
-
const y1 = m$1[iy + 1];
|
|
117860
|
-
|
|
117861
|
-
ADD64AA(v$1, a, b); // v[a,a+1] += v[b,b+1] ... in JS we must store a uint64 as two uint32s
|
|
117862
|
-
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
|
|
117863
|
-
|
|
117864
|
-
// v[d,d+1] = (v[d,d+1] xor v[a,a+1]) rotated to the right by 32 bits
|
|
117865
|
-
let xor0 = v$1[d] ^ v$1[a];
|
|
117866
|
-
let xor1 = v$1[d + 1] ^ v$1[a + 1];
|
|
117867
|
-
v$1[d] = xor1;
|
|
117868
|
-
v$1[d + 1] = xor0;
|
|
117869
|
-
|
|
117870
|
-
ADD64AA(v$1, c, d);
|
|
117871
|
-
|
|
117872
|
-
// v[b,b+1] = (v[b,b+1] xor v[c,c+1]) rotated right by 24 bits
|
|
117873
|
-
xor0 = v$1[b] ^ v$1[c];
|
|
117874
|
-
xor1 = v$1[b + 1] ^ v$1[c + 1];
|
|
117875
|
-
v$1[b] = (xor0 >>> 24) ^ (xor1 << 8);
|
|
117876
|
-
v$1[b + 1] = (xor1 >>> 24) ^ (xor0 << 8);
|
|
117877
|
-
|
|
117878
|
-
ADD64AA(v$1, a, b);
|
|
117879
|
-
ADD64AC(v$1, a, y0, y1);
|
|
117880
|
-
|
|
117881
|
-
// v[d,d+1] = (v[d,d+1] xor v[a,a+1]) rotated right by 16 bits
|
|
117882
|
-
xor0 = v$1[d] ^ v$1[a];
|
|
117883
|
-
xor1 = v$1[d + 1] ^ v$1[a + 1];
|
|
117884
|
-
v$1[d] = (xor0 >>> 16) ^ (xor1 << 16);
|
|
117885
|
-
v$1[d + 1] = (xor1 >>> 16) ^ (xor0 << 16);
|
|
117886
|
-
|
|
117887
|
-
ADD64AA(v$1, c, d);
|
|
117888
|
-
|
|
117889
|
-
// v[b,b+1] = (v[b,b+1] xor v[c,c+1]) rotated right by 63 bits
|
|
117890
|
-
xor0 = v$1[b] ^ v$1[c];
|
|
117891
|
-
xor1 = v$1[b + 1] ^ v$1[c + 1];
|
|
117892
|
-
v$1[b] = (xor1 >>> 31) ^ (xor0 << 1);
|
|
117893
|
-
v$1[b + 1] = (xor0 >>> 31) ^ (xor1 << 1);
|
|
117894
|
-
}
|
|
117895
|
-
|
|
117896
|
-
// Initialization Vector
|
|
117897
|
-
const BLAKE2B_IV32 = new Uint32Array([
|
|
117898
|
-
0xf3bcc908, 0x6a09e667, 0x84caa73b, 0xbb67ae85, 0xfe94f82b, 0x3c6ef372,
|
|
117899
|
-
0x5f1d36f1, 0xa54ff53a, 0xade682d1, 0x510e527f, 0x2b3e6c1f, 0x9b05688c,
|
|
117900
|
-
0xfb41bd6b, 0x1f83d9ab, 0x137e2179, 0x5be0cd19
|
|
117901
|
-
]);
|
|
117738
|
+
function requireUtil () {
|
|
117739
|
+
if (hasRequiredUtil) return util;
|
|
117740
|
+
hasRequiredUtil = 1;
|
|
117741
|
+
const ERROR_MSG_INPUT = 'Input must be an string, Buffer or Uint8Array';
|
|
117902
117742
|
|
|
117903
|
-
|
|
117904
|
-
|
|
117905
|
-
|
|
117906
|
-
|
|
117907
|
-
|
|
117908
|
-
|
|
117909
|
-
|
|
117910
|
-
|
|
117911
|
-
|
|
117912
|
-
|
|
117913
|
-
|
|
117743
|
+
// For convenience, let people hash a string, not just a Uint8Array
|
|
117744
|
+
function normalizeInput (input) {
|
|
117745
|
+
let ret;
|
|
117746
|
+
if (input instanceof Uint8Array) {
|
|
117747
|
+
ret = input;
|
|
117748
|
+
} else if (typeof input === 'string') {
|
|
117749
|
+
const encoder = new TextEncoder();
|
|
117750
|
+
ret = encoder.encode(input);
|
|
117751
|
+
} else {
|
|
117752
|
+
throw new Error(ERROR_MSG_INPUT)
|
|
117753
|
+
}
|
|
117754
|
+
return ret
|
|
117755
|
+
}
|
|
117756
|
+
|
|
117757
|
+
// Converts a Uint8Array to a hexadecimal string
|
|
117758
|
+
// For example, toHex([255, 0, 255]) returns "ff00ff"
|
|
117759
|
+
function toHex (bytes) {
|
|
117760
|
+
return Array.prototype.map
|
|
117761
|
+
.call(bytes, function (n) {
|
|
117762
|
+
return (n < 16 ? '0' : '') + n.toString(16)
|
|
117763
|
+
})
|
|
117764
|
+
.join('')
|
|
117765
|
+
}
|
|
117766
|
+
|
|
117767
|
+
// Converts any value in [0...2^32-1] to an 8-character hex string
|
|
117768
|
+
function uint32ToHex (val) {
|
|
117769
|
+
return (0x100000000 + val).toString(16).substring(1)
|
|
117770
|
+
}
|
|
117771
|
+
|
|
117772
|
+
// For debugging: prints out hash state in the same format as the RFC
|
|
117773
|
+
// sample computation exactly, so that you can diff
|
|
117774
|
+
function debugPrint (label, arr, size) {
|
|
117775
|
+
let msg = '\n' + label + ' = ';
|
|
117776
|
+
for (let i = 0; i < arr.length; i += 2) {
|
|
117777
|
+
if (size === 32) {
|
|
117778
|
+
msg += uint32ToHex(arr[i]).toUpperCase();
|
|
117779
|
+
msg += ' ';
|
|
117780
|
+
msg += uint32ToHex(arr[i + 1]).toUpperCase();
|
|
117781
|
+
} else if (size === 64) {
|
|
117782
|
+
msg += uint32ToHex(arr[i + 1]).toUpperCase();
|
|
117783
|
+
msg += uint32ToHex(arr[i]).toUpperCase();
|
|
117784
|
+
} else throw new Error('Invalid size ' + size)
|
|
117785
|
+
if (i % 6 === 4) {
|
|
117786
|
+
msg += '\n' + new Array(label.length + 4).join(' ');
|
|
117787
|
+
} else if (i < arr.length - 2) {
|
|
117788
|
+
msg += ' ';
|
|
117789
|
+
}
|
|
117790
|
+
}
|
|
117791
|
+
console.log(msg);
|
|
117792
|
+
}
|
|
117914
117793
|
|
|
117915
|
-
//
|
|
117916
|
-
//
|
|
117917
|
-
|
|
117918
|
-
|
|
117919
|
-
SIGMA8.map(function (x) {
|
|
117920
|
-
return x * 2
|
|
117921
|
-
})
|
|
117922
|
-
);
|
|
117794
|
+
// For performance testing: generates N bytes of input, hashes M times
|
|
117795
|
+
// Measures and prints MB/second hash performance each time
|
|
117796
|
+
function testSpeed (hashFn, N, M) {
|
|
117797
|
+
let startMs = new Date().getTime();
|
|
117923
117798
|
|
|
117924
|
-
|
|
117925
|
-
|
|
117926
|
-
|
|
117927
|
-
|
|
117928
|
-
|
|
117929
|
-
|
|
117930
|
-
|
|
117931
|
-
|
|
117932
|
-
|
|
117933
|
-
|
|
117934
|
-
|
|
117935
|
-
|
|
117936
|
-
|
|
117937
|
-
|
|
117938
|
-
|
|
117939
|
-
|
|
117940
|
-
|
|
117941
|
-
|
|
117942
|
-
|
|
117943
|
-
if (last) {
|
|
117944
|
-
v$1[28] = ~v$1[28];
|
|
117945
|
-
v$1[29] = ~v$1[29];
|
|
117946
|
-
}
|
|
117947
|
-
|
|
117948
|
-
// get little-endian words
|
|
117949
|
-
for (i = 0; i < 32; i++) {
|
|
117950
|
-
m$1[i] = B2B_GET32(ctx.b, 4 * i);
|
|
117951
|
-
}
|
|
117952
|
-
|
|
117953
|
-
// twelve rounds of mixing
|
|
117954
|
-
// uncomment the DebugPrint calls to log the computation
|
|
117955
|
-
// and match the RFC sample documentation
|
|
117956
|
-
// util.debugPrint(' m[16]', m, 64)
|
|
117957
|
-
for (i = 0; i < 12; i++) {
|
|
117958
|
-
// util.debugPrint(' (i=' + (i < 10 ? ' ' : '') + i + ') v[16]', v, 64)
|
|
117959
|
-
B2B_G(0, 8, 16, 24, SIGMA82[i * 16 + 0], SIGMA82[i * 16 + 1]);
|
|
117960
|
-
B2B_G(2, 10, 18, 26, SIGMA82[i * 16 + 2], SIGMA82[i * 16 + 3]);
|
|
117961
|
-
B2B_G(4, 12, 20, 28, SIGMA82[i * 16 + 4], SIGMA82[i * 16 + 5]);
|
|
117962
|
-
B2B_G(6, 14, 22, 30, SIGMA82[i * 16 + 6], SIGMA82[i * 16 + 7]);
|
|
117963
|
-
B2B_G(0, 10, 20, 30, SIGMA82[i * 16 + 8], SIGMA82[i * 16 + 9]);
|
|
117964
|
-
B2B_G(2, 12, 22, 24, SIGMA82[i * 16 + 10], SIGMA82[i * 16 + 11]);
|
|
117965
|
-
B2B_G(4, 14, 16, 26, SIGMA82[i * 16 + 12], SIGMA82[i * 16 + 13]);
|
|
117966
|
-
B2B_G(6, 8, 18, 28, SIGMA82[i * 16 + 14], SIGMA82[i * 16 + 15]);
|
|
117967
|
-
}
|
|
117968
|
-
// util.debugPrint(' (i=12) v[16]', v, 64)
|
|
117969
|
-
|
|
117970
|
-
for (i = 0; i < 16; i++) {
|
|
117971
|
-
ctx.h[i] = ctx.h[i] ^ v$1[i] ^ v$1[i + 16];
|
|
117972
|
-
}
|
|
117973
|
-
// util.debugPrint('h[8]', ctx.h, 64)
|
|
117974
|
-
}
|
|
117975
|
-
|
|
117976
|
-
// reusable parameterBlock
|
|
117977
|
-
const parameterBlock = new Uint8Array([
|
|
117978
|
-
0,
|
|
117979
|
-
0,
|
|
117980
|
-
0,
|
|
117981
|
-
0, // 0: outlen, keylen, fanout, depth
|
|
117982
|
-
0,
|
|
117983
|
-
0,
|
|
117984
|
-
0,
|
|
117985
|
-
0, // 4: leaf length, sequential mode
|
|
117986
|
-
0,
|
|
117987
|
-
0,
|
|
117988
|
-
0,
|
|
117989
|
-
0, // 8: node offset
|
|
117990
|
-
0,
|
|
117991
|
-
0,
|
|
117992
|
-
0,
|
|
117993
|
-
0, // 12: node offset
|
|
117994
|
-
0,
|
|
117995
|
-
0,
|
|
117996
|
-
0,
|
|
117997
|
-
0, // 16: node depth, inner length, rfu
|
|
117998
|
-
0,
|
|
117999
|
-
0,
|
|
118000
|
-
0,
|
|
118001
|
-
0, // 20: rfu
|
|
118002
|
-
0,
|
|
118003
|
-
0,
|
|
118004
|
-
0,
|
|
118005
|
-
0, // 24: rfu
|
|
118006
|
-
0,
|
|
118007
|
-
0,
|
|
118008
|
-
0,
|
|
118009
|
-
0, // 28: rfu
|
|
118010
|
-
0,
|
|
118011
|
-
0,
|
|
118012
|
-
0,
|
|
118013
|
-
0, // 32: salt
|
|
118014
|
-
0,
|
|
118015
|
-
0,
|
|
118016
|
-
0,
|
|
118017
|
-
0, // 36: salt
|
|
118018
|
-
0,
|
|
118019
|
-
0,
|
|
118020
|
-
0,
|
|
118021
|
-
0, // 40: salt
|
|
118022
|
-
0,
|
|
118023
|
-
0,
|
|
118024
|
-
0,
|
|
118025
|
-
0, // 44: salt
|
|
118026
|
-
0,
|
|
118027
|
-
0,
|
|
118028
|
-
0,
|
|
118029
|
-
0, // 48: personal
|
|
118030
|
-
0,
|
|
118031
|
-
0,
|
|
118032
|
-
0,
|
|
118033
|
-
0, // 52: personal
|
|
118034
|
-
0,
|
|
118035
|
-
0,
|
|
118036
|
-
0,
|
|
118037
|
-
0, // 56: personal
|
|
118038
|
-
0,
|
|
118039
|
-
0,
|
|
118040
|
-
0,
|
|
118041
|
-
0 // 60: personal
|
|
118042
|
-
]);
|
|
117799
|
+
const input = new Uint8Array(N);
|
|
117800
|
+
for (let i = 0; i < N; i++) {
|
|
117801
|
+
input[i] = i % 256;
|
|
117802
|
+
}
|
|
117803
|
+
const genMs = new Date().getTime();
|
|
117804
|
+
console.log('Generated random input in ' + (genMs - startMs) + 'ms');
|
|
117805
|
+
startMs = genMs;
|
|
117806
|
+
|
|
117807
|
+
for (let i = 0; i < M; i++) {
|
|
117808
|
+
const hashHex = hashFn(input);
|
|
117809
|
+
const hashMs = new Date().getTime();
|
|
117810
|
+
const ms = hashMs - startMs;
|
|
117811
|
+
startMs = hashMs;
|
|
117812
|
+
console.log('Hashed in ' + ms + 'ms: ' + hashHex.substring(0, 20) + '...');
|
|
117813
|
+
console.log(
|
|
117814
|
+
Math.round((N / (1 << 20) / (ms / 1000)) * 100) / 100 + ' MB PER SECOND'
|
|
117815
|
+
);
|
|
117816
|
+
}
|
|
117817
|
+
}
|
|
118043
117818
|
|
|
118044
|
-
|
|
118045
|
-
|
|
118046
|
-
|
|
118047
|
-
|
|
118048
|
-
|
|
118049
|
-
|
|
118050
|
-
|
|
118051
|
-
|
|
118052
|
-
}
|
|
118053
|
-
if (key && key.length > 64) {
|
|
118054
|
-
throw new Error('Illegal key, expected Uint8Array with 0 < length <= 64')
|
|
118055
|
-
}
|
|
118056
|
-
if (salt && salt.length !== 16) {
|
|
118057
|
-
throw new Error('Illegal salt, expected Uint8Array with length is 16')
|
|
118058
|
-
}
|
|
118059
|
-
if (personal && personal.length !== 16) {
|
|
118060
|
-
throw new Error('Illegal personal, expected Uint8Array with length is 16')
|
|
118061
|
-
}
|
|
118062
|
-
|
|
118063
|
-
// state, 'param block'
|
|
118064
|
-
const ctx = {
|
|
118065
|
-
b: new Uint8Array(128),
|
|
118066
|
-
h: new Uint32Array(16),
|
|
118067
|
-
t: 0, // input count
|
|
118068
|
-
c: 0, // pointer within buffer
|
|
118069
|
-
outlen: outlen // output length in bytes
|
|
118070
|
-
};
|
|
118071
|
-
|
|
118072
|
-
// initialize parameterBlock before usage
|
|
118073
|
-
parameterBlock.fill(0);
|
|
118074
|
-
parameterBlock[0] = outlen;
|
|
118075
|
-
if (key) parameterBlock[1] = key.length;
|
|
118076
|
-
parameterBlock[2] = 1; // fanout
|
|
118077
|
-
parameterBlock[3] = 1; // depth
|
|
118078
|
-
if (salt) parameterBlock.set(salt, 32);
|
|
118079
|
-
if (personal) parameterBlock.set(personal, 48);
|
|
118080
|
-
|
|
118081
|
-
// initialize hash state
|
|
118082
|
-
for (let i = 0; i < 16; i++) {
|
|
118083
|
-
ctx.h[i] = BLAKE2B_IV32[i] ^ B2B_GET32(parameterBlock, i * 4);
|
|
118084
|
-
}
|
|
118085
|
-
|
|
118086
|
-
// key the hash, if applicable
|
|
118087
|
-
if (key) {
|
|
118088
|
-
blake2bUpdate(ctx, key);
|
|
118089
|
-
// at the end
|
|
118090
|
-
ctx.c = 128;
|
|
118091
|
-
}
|
|
118092
|
-
|
|
118093
|
-
return ctx
|
|
118094
|
-
}
|
|
118095
|
-
|
|
118096
|
-
// Updates a BLAKE2b streaming hash
|
|
118097
|
-
// Requires hash context and Uint8Array (byte array)
|
|
118098
|
-
function blake2bUpdate (ctx, input) {
|
|
118099
|
-
for (let i = 0; i < input.length; i++) {
|
|
118100
|
-
if (ctx.c === 128) {
|
|
118101
|
-
// buffer full ?
|
|
118102
|
-
ctx.t += ctx.c; // add counters
|
|
118103
|
-
blake2bCompress(ctx, false); // compress (not last)
|
|
118104
|
-
ctx.c = 0; // counter to zero
|
|
118105
|
-
}
|
|
118106
|
-
ctx.b[ctx.c++] = input[i];
|
|
118107
|
-
}
|
|
118108
|
-
}
|
|
118109
|
-
|
|
118110
|
-
// Completes a BLAKE2b streaming hash
|
|
118111
|
-
// Returns a Uint8Array containing the message digest
|
|
118112
|
-
function blake2bFinal (ctx) {
|
|
118113
|
-
ctx.t += ctx.c; // mark last block offset
|
|
118114
|
-
|
|
118115
|
-
while (ctx.c < 128) {
|
|
118116
|
-
// fill up with zeros
|
|
118117
|
-
ctx.b[ctx.c++] = 0;
|
|
118118
|
-
}
|
|
118119
|
-
blake2bCompress(ctx, true); // final block flag = 1
|
|
118120
|
-
|
|
118121
|
-
// little endian convert and store
|
|
118122
|
-
const out = new Uint8Array(ctx.outlen);
|
|
118123
|
-
for (let i = 0; i < ctx.outlen; i++) {
|
|
118124
|
-
out[i] = ctx.h[i >> 2] >> (8 * (i & 3));
|
|
118125
|
-
}
|
|
118126
|
-
return out
|
|
118127
|
-
}
|
|
118128
|
-
|
|
118129
|
-
// Computes the BLAKE2B hash of a string or byte array, and returns a Uint8Array
|
|
118130
|
-
//
|
|
118131
|
-
// Returns a n-byte Uint8Array
|
|
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 blake2b (input, key, outlen, salt, personal) {
|
|
118140
|
-
// preprocess inputs
|
|
118141
|
-
outlen = outlen || 64;
|
|
118142
|
-
input = util$1.normalizeInput(input);
|
|
118143
|
-
if (salt) {
|
|
118144
|
-
salt = util$1.normalizeInput(salt);
|
|
118145
|
-
}
|
|
118146
|
-
if (personal) {
|
|
118147
|
-
personal = util$1.normalizeInput(personal);
|
|
118148
|
-
}
|
|
118149
|
-
|
|
118150
|
-
// do the math
|
|
118151
|
-
const ctx = blake2bInit(outlen, key, salt, personal);
|
|
118152
|
-
blake2bUpdate(ctx, input);
|
|
118153
|
-
return blake2bFinal(ctx)
|
|
118154
|
-
}
|
|
118155
|
-
|
|
118156
|
-
// Computes the BLAKE2B hash of a string or byte array
|
|
118157
|
-
//
|
|
118158
|
-
// Returns an n-byte hash in hex, all lowercase
|
|
118159
|
-
//
|
|
118160
|
-
// Parameters:
|
|
118161
|
-
// - input - the input bytes, as a string, Buffer, or Uint8Array
|
|
118162
|
-
// - key - optional key Uint8Array, up to 64 bytes
|
|
118163
|
-
// - outlen - optional output length in bytes, default 64
|
|
118164
|
-
// - salt - optional salt bytes, string, Buffer or Uint8Array
|
|
118165
|
-
// - personal - optional personal bytes, string, Buffer or Uint8Array
|
|
118166
|
-
function blake2bHex (input, key, outlen, salt, personal) {
|
|
118167
|
-
const output = blake2b(input, key, outlen, salt, personal);
|
|
118168
|
-
return util$1.toHex(output)
|
|
118169
|
-
}
|
|
118170
|
-
|
|
118171
|
-
var blake2b_1 = {
|
|
118172
|
-
blake2b: blake2b,
|
|
118173
|
-
blake2bHex: blake2bHex,
|
|
118174
|
-
blake2bInit: blake2bInit,
|
|
118175
|
-
blake2bUpdate: blake2bUpdate,
|
|
118176
|
-
blake2bFinal: blake2bFinal
|
|
118177
|
-
};
|
|
117819
|
+
util = {
|
|
117820
|
+
normalizeInput: normalizeInput,
|
|
117821
|
+
toHex: toHex,
|
|
117822
|
+
debugPrint: debugPrint,
|
|
117823
|
+
testSpeed: testSpeed
|
|
117824
|
+
};
|
|
117825
|
+
return util;
|
|
117826
|
+
}
|
|
118178
117827
|
|
|
118179
|
-
|
|
118180
|
-
|
|
118181
|
-
// Ported to Javascript by DC - https://github.com/dcposch
|
|
118182
|
-
|
|
118183
|
-
const util = util$2;
|
|
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
|
-
]);
|
|
117828
|
+
var blake2b_1;
|
|
117829
|
+
var hasRequiredBlake2b;
|
|
118222
117830
|
|
|
118223
|
-
|
|
118224
|
-
|
|
118225
|
-
|
|
118226
|
-
|
|
118227
|
-
|
|
118228
|
-
|
|
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
|
-
]);
|
|
117831
|
+
function requireBlake2b () {
|
|
117832
|
+
if (hasRequiredBlake2b) return blake2b_1;
|
|
117833
|
+
hasRequiredBlake2b = 1;
|
|
117834
|
+
// Blake2B in pure Javascript
|
|
117835
|
+
// Adapted from the reference implementation in RFC7693
|
|
117836
|
+
// Ported to Javascript by DC - https://github.com/dcposch
|
|
118385
117837
|
|
|
118386
|
-
|
|
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
|
-
var blake2s_1 = {
|
|
118526
|
-
blake2s: blake2s,
|
|
118527
|
-
blake2sHex: blake2sHex,
|
|
118528
|
-
blake2sInit: blake2sInit,
|
|
118529
|
-
blake2sUpdate: blake2sUpdate,
|
|
118530
|
-
blake2sFinal: blake2sFinal
|
|
118531
|
-
};
|
|
117838
|
+
const util = requireUtil();
|
|
118532
117839
|
|
|
118533
|
-
|
|
118534
|
-
|
|
118535
|
-
|
|
118536
|
-
|
|
118537
|
-
|
|
118538
|
-
|
|
118539
|
-
|
|
118540
|
-
|
|
118541
|
-
|
|
118542
|
-
|
|
118543
|
-
|
|
118544
|
-
|
|
118545
|
-
|
|
118546
|
-
|
|
118547
|
-
|
|
117840
|
+
// 64-bit unsigned addition
|
|
117841
|
+
// Sets v[a,a+1] += v[b,b+1]
|
|
117842
|
+
// v should be a Uint32Array
|
|
117843
|
+
function ADD64AA (v, a, b) {
|
|
117844
|
+
const o0 = v[a] + v[b];
|
|
117845
|
+
let o1 = v[a + 1] + v[b + 1];
|
|
117846
|
+
if (o0 >= 0x100000000) {
|
|
117847
|
+
o1++;
|
|
117848
|
+
}
|
|
117849
|
+
v[a] = o0;
|
|
117850
|
+
v[a + 1] = o1;
|
|
117851
|
+
}
|
|
117852
|
+
|
|
117853
|
+
// 64-bit unsigned addition
|
|
117854
|
+
// Sets v[a,a+1] += b
|
|
117855
|
+
// b0 is the low 32 bits of b, b1 represents the high 32 bits
|
|
117856
|
+
function ADD64AC (v, a, b0, b1) {
|
|
117857
|
+
let o0 = v[a] + b0;
|
|
117858
|
+
if (b0 < 0) {
|
|
117859
|
+
o0 += 0x100000000;
|
|
117860
|
+
}
|
|
117861
|
+
let o1 = v[a + 1] + b1;
|
|
117862
|
+
if (o0 >= 0x100000000) {
|
|
117863
|
+
o1++;
|
|
117864
|
+
}
|
|
117865
|
+
v[a] = o0;
|
|
117866
|
+
v[a + 1] = o1;
|
|
117867
|
+
}
|
|
117868
|
+
|
|
117869
|
+
// Little-endian byte access
|
|
117870
|
+
function B2B_GET32 (arr, i) {
|
|
117871
|
+
return arr[i] ^ (arr[i + 1] << 8) ^ (arr[i + 2] << 16) ^ (arr[i + 3] << 24)
|
|
117872
|
+
}
|
|
117873
|
+
|
|
117874
|
+
// G Mixing function
|
|
117875
|
+
// The ROTRs are inlined for speed
|
|
117876
|
+
function B2B_G (a, b, c, d, ix, iy) {
|
|
117877
|
+
const x0 = m[ix];
|
|
117878
|
+
const x1 = m[ix + 1];
|
|
117879
|
+
const y0 = m[iy];
|
|
117880
|
+
const y1 = m[iy + 1];
|
|
117881
|
+
|
|
117882
|
+
ADD64AA(v, a, b); // v[a,a+1] += v[b,b+1] ... in JS we must store a uint64 as two uint32s
|
|
117883
|
+
ADD64AC(v, a, x0, x1); // v[a, a+1] += x ... x0 is the low 32 bits of x, x1 is the high 32 bits
|
|
117884
|
+
|
|
117885
|
+
// v[d,d+1] = (v[d,d+1] xor v[a,a+1]) rotated to the right by 32 bits
|
|
117886
|
+
let xor0 = v[d] ^ v[a];
|
|
117887
|
+
let xor1 = v[d + 1] ^ v[a + 1];
|
|
117888
|
+
v[d] = xor1;
|
|
117889
|
+
v[d + 1] = xor0;
|
|
117890
|
+
|
|
117891
|
+
ADD64AA(v, c, d);
|
|
117892
|
+
|
|
117893
|
+
// v[b,b+1] = (v[b,b+1] xor v[c,c+1]) rotated right by 24 bits
|
|
117894
|
+
xor0 = v[b] ^ v[c];
|
|
117895
|
+
xor1 = v[b + 1] ^ v[c + 1];
|
|
117896
|
+
v[b] = (xor0 >>> 24) ^ (xor1 << 8);
|
|
117897
|
+
v[b + 1] = (xor1 >>> 24) ^ (xor0 << 8);
|
|
117898
|
+
|
|
117899
|
+
ADD64AA(v, a, b);
|
|
117900
|
+
ADD64AC(v, a, y0, y1);
|
|
117901
|
+
|
|
117902
|
+
// v[d,d+1] = (v[d,d+1] xor v[a,a+1]) rotated right by 16 bits
|
|
117903
|
+
xor0 = v[d] ^ v[a];
|
|
117904
|
+
xor1 = v[d + 1] ^ v[a + 1];
|
|
117905
|
+
v[d] = (xor0 >>> 16) ^ (xor1 << 16);
|
|
117906
|
+
v[d + 1] = (xor1 >>> 16) ^ (xor0 << 16);
|
|
117907
|
+
|
|
117908
|
+
ADD64AA(v, c, d);
|
|
117909
|
+
|
|
117910
|
+
// v[b,b+1] = (v[b,b+1] xor v[c,c+1]) rotated right by 63 bits
|
|
117911
|
+
xor0 = v[b] ^ v[c];
|
|
117912
|
+
xor1 = v[b + 1] ^ v[c + 1];
|
|
117913
|
+
v[b] = (xor1 >>> 31) ^ (xor0 << 1);
|
|
117914
|
+
v[b + 1] = (xor0 >>> 31) ^ (xor1 << 1);
|
|
117915
|
+
}
|
|
117916
|
+
|
|
117917
|
+
// Initialization Vector
|
|
117918
|
+
const BLAKE2B_IV32 = new Uint32Array([
|
|
117919
|
+
0xf3bcc908, 0x6a09e667, 0x84caa73b, 0xbb67ae85, 0xfe94f82b, 0x3c6ef372,
|
|
117920
|
+
0x5f1d36f1, 0xa54ff53a, 0xade682d1, 0x510e527f, 0x2b3e6c1f, 0x9b05688c,
|
|
117921
|
+
0xfb41bd6b, 0x1f83d9ab, 0x137e2179, 0x5be0cd19
|
|
117922
|
+
]);
|
|
117923
|
+
|
|
117924
|
+
const SIGMA8 = [
|
|
117925
|
+
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 14, 10, 4, 8, 9, 15, 13,
|
|
117926
|
+
6, 1, 12, 0, 2, 11, 7, 5, 3, 11, 8, 12, 0, 5, 2, 15, 13, 10, 14, 3, 6, 7, 1,
|
|
117927
|
+
9, 4, 7, 9, 3, 1, 13, 12, 11, 14, 2, 6, 5, 10, 4, 0, 15, 8, 9, 0, 5, 7, 2, 4,
|
|
117928
|
+
10, 15, 14, 1, 11, 12, 6, 8, 3, 13, 2, 12, 6, 10, 0, 11, 8, 3, 4, 13, 7, 5,
|
|
117929
|
+
15, 14, 1, 9, 12, 5, 1, 15, 14, 13, 4, 10, 0, 7, 6, 3, 9, 2, 8, 11, 13, 11, 7,
|
|
117930
|
+
14, 12, 1, 3, 9, 5, 0, 15, 4, 8, 6, 2, 10, 6, 15, 14, 9, 11, 3, 0, 8, 12, 2,
|
|
117931
|
+
13, 7, 1, 4, 10, 5, 10, 2, 8, 4, 7, 6, 1, 5, 15, 11, 9, 14, 3, 12, 13, 0, 0,
|
|
117932
|
+
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 14, 10, 4, 8, 9, 15, 13, 6,
|
|
117933
|
+
1, 12, 0, 2, 11, 7, 5, 3
|
|
117934
|
+
];
|
|
117935
|
+
|
|
117936
|
+
// These are offsets into a uint64 buffer.
|
|
117937
|
+
// Multiply them all by 2 to make them offsets into a uint32 buffer,
|
|
117938
|
+
// because this is Javascript and we don't have uint64s
|
|
117939
|
+
const SIGMA82 = new Uint8Array(
|
|
117940
|
+
SIGMA8.map(function (x) {
|
|
117941
|
+
return x * 2
|
|
117942
|
+
})
|
|
117943
|
+
);
|
|
117944
|
+
|
|
117945
|
+
// Compression function. 'last' flag indicates last block.
|
|
117946
|
+
// Note we're representing 16 uint64s as 32 uint32s
|
|
117947
|
+
const v = new Uint32Array(32);
|
|
117948
|
+
const m = new Uint32Array(32);
|
|
117949
|
+
function blake2bCompress (ctx, last) {
|
|
117950
|
+
let i = 0;
|
|
117951
|
+
|
|
117952
|
+
// init work variables
|
|
117953
|
+
for (i = 0; i < 16; i++) {
|
|
117954
|
+
v[i] = ctx.h[i];
|
|
117955
|
+
v[i + 16] = BLAKE2B_IV32[i];
|
|
117956
|
+
}
|
|
117957
|
+
|
|
117958
|
+
// low 64 bits of offset
|
|
117959
|
+
v[24] = v[24] ^ ctx.t;
|
|
117960
|
+
v[25] = v[25] ^ (ctx.t / 0x100000000);
|
|
117961
|
+
// high 64 bits not supported, offset may not be higher than 2**53-1
|
|
117962
|
+
|
|
117963
|
+
// last block flag set ?
|
|
117964
|
+
if (last) {
|
|
117965
|
+
v[28] = ~v[28];
|
|
117966
|
+
v[29] = ~v[29];
|
|
117967
|
+
}
|
|
117968
|
+
|
|
117969
|
+
// get little-endian words
|
|
117970
|
+
for (i = 0; i < 32; i++) {
|
|
117971
|
+
m[i] = B2B_GET32(ctx.b, 4 * i);
|
|
117972
|
+
}
|
|
117973
|
+
|
|
117974
|
+
// twelve rounds of mixing
|
|
117975
|
+
// uncomment the DebugPrint calls to log the computation
|
|
117976
|
+
// and match the RFC sample documentation
|
|
117977
|
+
// util.debugPrint(' m[16]', m, 64)
|
|
117978
|
+
for (i = 0; i < 12; i++) {
|
|
117979
|
+
// util.debugPrint(' (i=' + (i < 10 ? ' ' : '') + i + ') v[16]', v, 64)
|
|
117980
|
+
B2B_G(0, 8, 16, 24, SIGMA82[i * 16 + 0], SIGMA82[i * 16 + 1]);
|
|
117981
|
+
B2B_G(2, 10, 18, 26, SIGMA82[i * 16 + 2], SIGMA82[i * 16 + 3]);
|
|
117982
|
+
B2B_G(4, 12, 20, 28, SIGMA82[i * 16 + 4], SIGMA82[i * 16 + 5]);
|
|
117983
|
+
B2B_G(6, 14, 22, 30, SIGMA82[i * 16 + 6], SIGMA82[i * 16 + 7]);
|
|
117984
|
+
B2B_G(0, 10, 20, 30, SIGMA82[i * 16 + 8], SIGMA82[i * 16 + 9]);
|
|
117985
|
+
B2B_G(2, 12, 22, 24, SIGMA82[i * 16 + 10], SIGMA82[i * 16 + 11]);
|
|
117986
|
+
B2B_G(4, 14, 16, 26, SIGMA82[i * 16 + 12], SIGMA82[i * 16 + 13]);
|
|
117987
|
+
B2B_G(6, 8, 18, 28, SIGMA82[i * 16 + 14], SIGMA82[i * 16 + 15]);
|
|
117988
|
+
}
|
|
117989
|
+
// util.debugPrint(' (i=12) v[16]', v, 64)
|
|
117990
|
+
|
|
117991
|
+
for (i = 0; i < 16; i++) {
|
|
117992
|
+
ctx.h[i] = ctx.h[i] ^ v[i] ^ v[i + 16];
|
|
117993
|
+
}
|
|
117994
|
+
// util.debugPrint('h[8]', ctx.h, 64)
|
|
117995
|
+
}
|
|
117996
|
+
|
|
117997
|
+
// reusable parameterBlock
|
|
117998
|
+
const parameterBlock = new Uint8Array([
|
|
117999
|
+
0,
|
|
118000
|
+
0,
|
|
118001
|
+
0,
|
|
118002
|
+
0, // 0: outlen, keylen, fanout, depth
|
|
118003
|
+
0,
|
|
118004
|
+
0,
|
|
118005
|
+
0,
|
|
118006
|
+
0, // 4: leaf length, sequential mode
|
|
118007
|
+
0,
|
|
118008
|
+
0,
|
|
118009
|
+
0,
|
|
118010
|
+
0, // 8: node offset
|
|
118011
|
+
0,
|
|
118012
|
+
0,
|
|
118013
|
+
0,
|
|
118014
|
+
0, // 12: node offset
|
|
118015
|
+
0,
|
|
118016
|
+
0,
|
|
118017
|
+
0,
|
|
118018
|
+
0, // 16: node depth, inner length, rfu
|
|
118019
|
+
0,
|
|
118020
|
+
0,
|
|
118021
|
+
0,
|
|
118022
|
+
0, // 20: rfu
|
|
118023
|
+
0,
|
|
118024
|
+
0,
|
|
118025
|
+
0,
|
|
118026
|
+
0, // 24: rfu
|
|
118027
|
+
0,
|
|
118028
|
+
0,
|
|
118029
|
+
0,
|
|
118030
|
+
0, // 28: rfu
|
|
118031
|
+
0,
|
|
118032
|
+
0,
|
|
118033
|
+
0,
|
|
118034
|
+
0, // 32: salt
|
|
118035
|
+
0,
|
|
118036
|
+
0,
|
|
118037
|
+
0,
|
|
118038
|
+
0, // 36: salt
|
|
118039
|
+
0,
|
|
118040
|
+
0,
|
|
118041
|
+
0,
|
|
118042
|
+
0, // 40: salt
|
|
118043
|
+
0,
|
|
118044
|
+
0,
|
|
118045
|
+
0,
|
|
118046
|
+
0, // 44: salt
|
|
118047
|
+
0,
|
|
118048
|
+
0,
|
|
118049
|
+
0,
|
|
118050
|
+
0, // 48: personal
|
|
118051
|
+
0,
|
|
118052
|
+
0,
|
|
118053
|
+
0,
|
|
118054
|
+
0, // 52: personal
|
|
118055
|
+
0,
|
|
118056
|
+
0,
|
|
118057
|
+
0,
|
|
118058
|
+
0, // 56: personal
|
|
118059
|
+
0,
|
|
118060
|
+
0,
|
|
118061
|
+
0,
|
|
118062
|
+
0 // 60: personal
|
|
118063
|
+
]);
|
|
118064
|
+
|
|
118065
|
+
// Creates a BLAKE2b hashing context
|
|
118066
|
+
// Requires an output length between 1 and 64 bytes
|
|
118067
|
+
// Takes an optional Uint8Array key
|
|
118068
|
+
// Takes an optinal Uint8Array salt
|
|
118069
|
+
// Takes an optinal Uint8Array personal
|
|
118070
|
+
function blake2bInit (outlen, key, salt, personal) {
|
|
118071
|
+
if (outlen === 0 || outlen > 64) {
|
|
118072
|
+
throw new Error('Illegal output length, expected 0 < length <= 64')
|
|
118073
|
+
}
|
|
118074
|
+
if (key && key.length > 64) {
|
|
118075
|
+
throw new Error('Illegal key, expected Uint8Array with 0 < length <= 64')
|
|
118076
|
+
}
|
|
118077
|
+
if (salt && salt.length !== 16) {
|
|
118078
|
+
throw new Error('Illegal salt, expected Uint8Array with length is 16')
|
|
118079
|
+
}
|
|
118080
|
+
if (personal && personal.length !== 16) {
|
|
118081
|
+
throw new Error('Illegal personal, expected Uint8Array with length is 16')
|
|
118082
|
+
}
|
|
118083
|
+
|
|
118084
|
+
// state, 'param block'
|
|
118085
|
+
const ctx = {
|
|
118086
|
+
b: new Uint8Array(128),
|
|
118087
|
+
h: new Uint32Array(16),
|
|
118088
|
+
t: 0, // input count
|
|
118089
|
+
c: 0, // pointer within buffer
|
|
118090
|
+
outlen: outlen // output length in bytes
|
|
118091
|
+
};
|
|
118092
|
+
|
|
118093
|
+
// initialize parameterBlock before usage
|
|
118094
|
+
parameterBlock.fill(0);
|
|
118095
|
+
parameterBlock[0] = outlen;
|
|
118096
|
+
if (key) parameterBlock[1] = key.length;
|
|
118097
|
+
parameterBlock[2] = 1; // fanout
|
|
118098
|
+
parameterBlock[3] = 1; // depth
|
|
118099
|
+
if (salt) parameterBlock.set(salt, 32);
|
|
118100
|
+
if (personal) parameterBlock.set(personal, 48);
|
|
118101
|
+
|
|
118102
|
+
// initialize hash state
|
|
118103
|
+
for (let i = 0; i < 16; i++) {
|
|
118104
|
+
ctx.h[i] = BLAKE2B_IV32[i] ^ B2B_GET32(parameterBlock, i * 4);
|
|
118105
|
+
}
|
|
118106
|
+
|
|
118107
|
+
// key the hash, if applicable
|
|
118108
|
+
if (key) {
|
|
118109
|
+
blake2bUpdate(ctx, key);
|
|
118110
|
+
// at the end
|
|
118111
|
+
ctx.c = 128;
|
|
118112
|
+
}
|
|
118113
|
+
|
|
118114
|
+
return ctx
|
|
118115
|
+
}
|
|
118116
|
+
|
|
118117
|
+
// Updates a BLAKE2b streaming hash
|
|
118118
|
+
// Requires hash context and Uint8Array (byte array)
|
|
118119
|
+
function blake2bUpdate (ctx, input) {
|
|
118120
|
+
for (let i = 0; i < input.length; i++) {
|
|
118121
|
+
if (ctx.c === 128) {
|
|
118122
|
+
// buffer full ?
|
|
118123
|
+
ctx.t += ctx.c; // add counters
|
|
118124
|
+
blake2bCompress(ctx, false); // compress (not last)
|
|
118125
|
+
ctx.c = 0; // counter to zero
|
|
118126
|
+
}
|
|
118127
|
+
ctx.b[ctx.c++] = input[i];
|
|
118128
|
+
}
|
|
118129
|
+
}
|
|
118130
|
+
|
|
118131
|
+
// Completes a BLAKE2b streaming hash
|
|
118132
|
+
// Returns a Uint8Array containing the message digest
|
|
118133
|
+
function blake2bFinal (ctx) {
|
|
118134
|
+
ctx.t += ctx.c; // mark last block offset
|
|
118135
|
+
|
|
118136
|
+
while (ctx.c < 128) {
|
|
118137
|
+
// fill up with zeros
|
|
118138
|
+
ctx.b[ctx.c++] = 0;
|
|
118139
|
+
}
|
|
118140
|
+
blake2bCompress(ctx, true); // final block flag = 1
|
|
118141
|
+
|
|
118142
|
+
// little endian convert and store
|
|
118143
|
+
const out = new Uint8Array(ctx.outlen);
|
|
118144
|
+
for (let i = 0; i < ctx.outlen; i++) {
|
|
118145
|
+
out[i] = ctx.h[i >> 2] >> (8 * (i & 3));
|
|
118146
|
+
}
|
|
118147
|
+
return out
|
|
118148
|
+
}
|
|
118149
|
+
|
|
118150
|
+
// Computes the BLAKE2B hash of a string or byte array, and returns a Uint8Array
|
|
118151
|
+
//
|
|
118152
|
+
// Returns a n-byte Uint8Array
|
|
118153
|
+
//
|
|
118154
|
+
// Parameters:
|
|
118155
|
+
// - input - the input bytes, as a string, Buffer or Uint8Array
|
|
118156
|
+
// - key - optional key Uint8Array, up to 64 bytes
|
|
118157
|
+
// - outlen - optional output length in bytes, default 64
|
|
118158
|
+
// - salt - optional salt bytes, string, Buffer or Uint8Array
|
|
118159
|
+
// - personal - optional personal bytes, string, Buffer or Uint8Array
|
|
118160
|
+
function blake2b (input, key, outlen, salt, personal) {
|
|
118161
|
+
// preprocess inputs
|
|
118162
|
+
outlen = outlen || 64;
|
|
118163
|
+
input = util.normalizeInput(input);
|
|
118164
|
+
if (salt) {
|
|
118165
|
+
salt = util.normalizeInput(salt);
|
|
118166
|
+
}
|
|
118167
|
+
if (personal) {
|
|
118168
|
+
personal = util.normalizeInput(personal);
|
|
118169
|
+
}
|
|
118170
|
+
|
|
118171
|
+
// do the math
|
|
118172
|
+
const ctx = blake2bInit(outlen, key, salt, personal);
|
|
118173
|
+
blake2bUpdate(ctx, input);
|
|
118174
|
+
return blake2bFinal(ctx)
|
|
118175
|
+
}
|
|
118176
|
+
|
|
118177
|
+
// Computes the BLAKE2B hash of a string or byte array
|
|
118178
|
+
//
|
|
118179
|
+
// Returns an n-byte hash in hex, all lowercase
|
|
118180
|
+
//
|
|
118181
|
+
// Parameters:
|
|
118182
|
+
// - input - the input bytes, as a string, Buffer, or Uint8Array
|
|
118183
|
+
// - key - optional key Uint8Array, up to 64 bytes
|
|
118184
|
+
// - outlen - optional output length in bytes, default 64
|
|
118185
|
+
// - salt - optional salt bytes, string, Buffer or Uint8Array
|
|
118186
|
+
// - personal - optional personal bytes, string, Buffer or Uint8Array
|
|
118187
|
+
function blake2bHex (input, key, outlen, salt, personal) {
|
|
118188
|
+
const output = blake2b(input, key, outlen, salt, personal);
|
|
118189
|
+
return util.toHex(output)
|
|
118190
|
+
}
|
|
118191
|
+
|
|
118192
|
+
blake2b_1 = {
|
|
118193
|
+
blake2b: blake2b,
|
|
118194
|
+
blake2bHex: blake2bHex,
|
|
118195
|
+
blake2bInit: blake2bInit,
|
|
118196
|
+
blake2bUpdate: blake2bUpdate,
|
|
118197
|
+
blake2bFinal: blake2bFinal
|
|
118198
|
+
};
|
|
118199
|
+
return blake2b_1;
|
|
118200
|
+
}
|
|
118201
|
+
|
|
118202
|
+
var blake2s_1;
|
|
118203
|
+
var hasRequiredBlake2s;
|
|
118204
|
+
|
|
118205
|
+
function requireBlake2s () {
|
|
118206
|
+
if (hasRequiredBlake2s) return blake2s_1;
|
|
118207
|
+
hasRequiredBlake2s = 1;
|
|
118208
|
+
// BLAKE2s hash function in pure Javascript
|
|
118209
|
+
// Adapted from the reference implementation in RFC7693
|
|
118210
|
+
// Ported to Javascript by DC - https://github.com/dcposch
|
|
118211
|
+
|
|
118212
|
+
const util = requireUtil();
|
|
118213
|
+
|
|
118214
|
+
// Little-endian byte access.
|
|
118215
|
+
// Expects a Uint8Array and an index
|
|
118216
|
+
// Returns the little-endian uint32 at v[i..i+3]
|
|
118217
|
+
function B2S_GET32 (v, i) {
|
|
118218
|
+
return v[i] ^ (v[i + 1] << 8) ^ (v[i + 2] << 16) ^ (v[i + 3] << 24)
|
|
118219
|
+
}
|
|
118220
|
+
|
|
118221
|
+
// Mixing function G.
|
|
118222
|
+
function B2S_G (a, b, c, d, x, y) {
|
|
118223
|
+
v[a] = v[a] + v[b] + x;
|
|
118224
|
+
v[d] = ROTR32(v[d] ^ v[a], 16);
|
|
118225
|
+
v[c] = v[c] + v[d];
|
|
118226
|
+
v[b] = ROTR32(v[b] ^ v[c], 12);
|
|
118227
|
+
v[a] = v[a] + v[b] + y;
|
|
118228
|
+
v[d] = ROTR32(v[d] ^ v[a], 8);
|
|
118229
|
+
v[c] = v[c] + v[d];
|
|
118230
|
+
v[b] = ROTR32(v[b] ^ v[c], 7);
|
|
118231
|
+
}
|
|
118232
|
+
|
|
118233
|
+
// 32-bit right rotation
|
|
118234
|
+
// x should be a uint32
|
|
118235
|
+
// y must be between 1 and 31, inclusive
|
|
118236
|
+
function ROTR32 (x, y) {
|
|
118237
|
+
return (x >>> y) ^ (x << (32 - y))
|
|
118238
|
+
}
|
|
118239
|
+
|
|
118240
|
+
// Initialization Vector.
|
|
118241
|
+
const BLAKE2S_IV = new Uint32Array([
|
|
118242
|
+
0x6a09e667,
|
|
118243
|
+
0xbb67ae85,
|
|
118244
|
+
0x3c6ef372,
|
|
118245
|
+
0xa54ff53a,
|
|
118246
|
+
0x510e527f,
|
|
118247
|
+
0x9b05688c,
|
|
118248
|
+
0x1f83d9ab,
|
|
118249
|
+
0x5be0cd19
|
|
118250
|
+
]);
|
|
118251
|
+
|
|
118252
|
+
const SIGMA = new Uint8Array([
|
|
118253
|
+
0,
|
|
118254
|
+
1,
|
|
118255
|
+
2,
|
|
118256
|
+
3,
|
|
118257
|
+
4,
|
|
118258
|
+
5,
|
|
118259
|
+
6,
|
|
118260
|
+
7,
|
|
118261
|
+
8,
|
|
118262
|
+
9,
|
|
118263
|
+
10,
|
|
118264
|
+
11,
|
|
118265
|
+
12,
|
|
118266
|
+
13,
|
|
118267
|
+
14,
|
|
118268
|
+
15,
|
|
118269
|
+
14,
|
|
118270
|
+
10,
|
|
118271
|
+
4,
|
|
118272
|
+
8,
|
|
118273
|
+
9,
|
|
118274
|
+
15,
|
|
118275
|
+
13,
|
|
118276
|
+
6,
|
|
118277
|
+
1,
|
|
118278
|
+
12,
|
|
118279
|
+
0,
|
|
118280
|
+
2,
|
|
118281
|
+
11,
|
|
118282
|
+
7,
|
|
118283
|
+
5,
|
|
118284
|
+
3,
|
|
118285
|
+
11,
|
|
118286
|
+
8,
|
|
118287
|
+
12,
|
|
118288
|
+
0,
|
|
118289
|
+
5,
|
|
118290
|
+
2,
|
|
118291
|
+
15,
|
|
118292
|
+
13,
|
|
118293
|
+
10,
|
|
118294
|
+
14,
|
|
118295
|
+
3,
|
|
118296
|
+
6,
|
|
118297
|
+
7,
|
|
118298
|
+
1,
|
|
118299
|
+
9,
|
|
118300
|
+
4,
|
|
118301
|
+
7,
|
|
118302
|
+
9,
|
|
118303
|
+
3,
|
|
118304
|
+
1,
|
|
118305
|
+
13,
|
|
118306
|
+
12,
|
|
118307
|
+
11,
|
|
118308
|
+
14,
|
|
118309
|
+
2,
|
|
118310
|
+
6,
|
|
118311
|
+
5,
|
|
118312
|
+
10,
|
|
118313
|
+
4,
|
|
118314
|
+
0,
|
|
118315
|
+
15,
|
|
118316
|
+
8,
|
|
118317
|
+
9,
|
|
118318
|
+
0,
|
|
118319
|
+
5,
|
|
118320
|
+
7,
|
|
118321
|
+
2,
|
|
118322
|
+
4,
|
|
118323
|
+
10,
|
|
118324
|
+
15,
|
|
118325
|
+
14,
|
|
118326
|
+
1,
|
|
118327
|
+
11,
|
|
118328
|
+
12,
|
|
118329
|
+
6,
|
|
118330
|
+
8,
|
|
118331
|
+
3,
|
|
118332
|
+
13,
|
|
118333
|
+
2,
|
|
118334
|
+
12,
|
|
118335
|
+
6,
|
|
118336
|
+
10,
|
|
118337
|
+
0,
|
|
118338
|
+
11,
|
|
118339
|
+
8,
|
|
118340
|
+
3,
|
|
118341
|
+
4,
|
|
118342
|
+
13,
|
|
118343
|
+
7,
|
|
118344
|
+
5,
|
|
118345
|
+
15,
|
|
118346
|
+
14,
|
|
118347
|
+
1,
|
|
118348
|
+
9,
|
|
118349
|
+
12,
|
|
118350
|
+
5,
|
|
118351
|
+
1,
|
|
118352
|
+
15,
|
|
118353
|
+
14,
|
|
118354
|
+
13,
|
|
118355
|
+
4,
|
|
118356
|
+
10,
|
|
118357
|
+
0,
|
|
118358
|
+
7,
|
|
118359
|
+
6,
|
|
118360
|
+
3,
|
|
118361
|
+
9,
|
|
118362
|
+
2,
|
|
118363
|
+
8,
|
|
118364
|
+
11,
|
|
118365
|
+
13,
|
|
118366
|
+
11,
|
|
118367
|
+
7,
|
|
118368
|
+
14,
|
|
118369
|
+
12,
|
|
118370
|
+
1,
|
|
118371
|
+
3,
|
|
118372
|
+
9,
|
|
118373
|
+
5,
|
|
118374
|
+
0,
|
|
118375
|
+
15,
|
|
118376
|
+
4,
|
|
118377
|
+
8,
|
|
118378
|
+
6,
|
|
118379
|
+
2,
|
|
118380
|
+
10,
|
|
118381
|
+
6,
|
|
118382
|
+
15,
|
|
118383
|
+
14,
|
|
118384
|
+
9,
|
|
118385
|
+
11,
|
|
118386
|
+
3,
|
|
118387
|
+
0,
|
|
118388
|
+
8,
|
|
118389
|
+
12,
|
|
118390
|
+
2,
|
|
118391
|
+
13,
|
|
118392
|
+
7,
|
|
118393
|
+
1,
|
|
118394
|
+
4,
|
|
118395
|
+
10,
|
|
118396
|
+
5,
|
|
118397
|
+
10,
|
|
118398
|
+
2,
|
|
118399
|
+
8,
|
|
118400
|
+
4,
|
|
118401
|
+
7,
|
|
118402
|
+
6,
|
|
118403
|
+
1,
|
|
118404
|
+
5,
|
|
118405
|
+
15,
|
|
118406
|
+
11,
|
|
118407
|
+
9,
|
|
118408
|
+
14,
|
|
118409
|
+
3,
|
|
118410
|
+
12,
|
|
118411
|
+
13,
|
|
118412
|
+
0
|
|
118413
|
+
]);
|
|
118414
|
+
|
|
118415
|
+
// Compression function. "last" flag indicates last block
|
|
118416
|
+
const v = new Uint32Array(16);
|
|
118417
|
+
const m = new Uint32Array(16);
|
|
118418
|
+
function blake2sCompress (ctx, last) {
|
|
118419
|
+
let i = 0;
|
|
118420
|
+
for (i = 0; i < 8; i++) {
|
|
118421
|
+
// init work variables
|
|
118422
|
+
v[i] = ctx.h[i];
|
|
118423
|
+
v[i + 8] = BLAKE2S_IV[i];
|
|
118424
|
+
}
|
|
118425
|
+
|
|
118426
|
+
v[12] ^= ctx.t; // low 32 bits of offset
|
|
118427
|
+
v[13] ^= ctx.t / 0x100000000; // high 32 bits
|
|
118428
|
+
if (last) {
|
|
118429
|
+
// last block flag set ?
|
|
118430
|
+
v[14] = ~v[14];
|
|
118431
|
+
}
|
|
118432
|
+
|
|
118433
|
+
for (i = 0; i < 16; i++) {
|
|
118434
|
+
// get little-endian words
|
|
118435
|
+
m[i] = B2S_GET32(ctx.b, 4 * i);
|
|
118436
|
+
}
|
|
118437
|
+
|
|
118438
|
+
// ten rounds of mixing
|
|
118439
|
+
// uncomment the DebugPrint calls to log the computation
|
|
118440
|
+
// and match the RFC sample documentation
|
|
118441
|
+
// util.debugPrint(' m[16]', m, 32)
|
|
118442
|
+
for (i = 0; i < 10; i++) {
|
|
118443
|
+
// util.debugPrint(' (i=' + i + ') v[16]', v, 32)
|
|
118444
|
+
B2S_G(0, 4, 8, 12, m[SIGMA[i * 16 + 0]], m[SIGMA[i * 16 + 1]]);
|
|
118445
|
+
B2S_G(1, 5, 9, 13, m[SIGMA[i * 16 + 2]], m[SIGMA[i * 16 + 3]]);
|
|
118446
|
+
B2S_G(2, 6, 10, 14, m[SIGMA[i * 16 + 4]], m[SIGMA[i * 16 + 5]]);
|
|
118447
|
+
B2S_G(3, 7, 11, 15, m[SIGMA[i * 16 + 6]], m[SIGMA[i * 16 + 7]]);
|
|
118448
|
+
B2S_G(0, 5, 10, 15, m[SIGMA[i * 16 + 8]], m[SIGMA[i * 16 + 9]]);
|
|
118449
|
+
B2S_G(1, 6, 11, 12, m[SIGMA[i * 16 + 10]], m[SIGMA[i * 16 + 11]]);
|
|
118450
|
+
B2S_G(2, 7, 8, 13, m[SIGMA[i * 16 + 12]], m[SIGMA[i * 16 + 13]]);
|
|
118451
|
+
B2S_G(3, 4, 9, 14, m[SIGMA[i * 16 + 14]], m[SIGMA[i * 16 + 15]]);
|
|
118452
|
+
}
|
|
118453
|
+
// util.debugPrint(' (i=10) v[16]', v, 32)
|
|
118454
|
+
|
|
118455
|
+
for (i = 0; i < 8; i++) {
|
|
118456
|
+
ctx.h[i] ^= v[i] ^ v[i + 8];
|
|
118457
|
+
}
|
|
118458
|
+
// util.debugPrint('h[8]', ctx.h, 32)
|
|
118459
|
+
}
|
|
118460
|
+
|
|
118461
|
+
// Creates a BLAKE2s hashing context
|
|
118462
|
+
// Requires an output length between 1 and 32 bytes
|
|
118463
|
+
// Takes an optional Uint8Array key
|
|
118464
|
+
function blake2sInit (outlen, key) {
|
|
118465
|
+
if (!(outlen > 0 && outlen <= 32)) {
|
|
118466
|
+
throw new Error('Incorrect output length, should be in [1, 32]')
|
|
118467
|
+
}
|
|
118468
|
+
const keylen = key ? key.length : 0;
|
|
118469
|
+
if (key && !(keylen > 0 && keylen <= 32)) {
|
|
118470
|
+
throw new Error('Incorrect key length, should be in [1, 32]')
|
|
118471
|
+
}
|
|
118472
|
+
|
|
118473
|
+
const ctx = {
|
|
118474
|
+
h: new Uint32Array(BLAKE2S_IV), // hash state
|
|
118475
|
+
b: new Uint8Array(64), // input block
|
|
118476
|
+
c: 0, // pointer within block
|
|
118477
|
+
t: 0, // input count
|
|
118478
|
+
outlen: outlen // output length in bytes
|
|
118479
|
+
};
|
|
118480
|
+
ctx.h[0] ^= 0x01010000 ^ (keylen << 8) ^ outlen;
|
|
118481
|
+
|
|
118482
|
+
if (keylen > 0) {
|
|
118483
|
+
blake2sUpdate(ctx, key);
|
|
118484
|
+
ctx.c = 64; // at the end
|
|
118485
|
+
}
|
|
118486
|
+
|
|
118487
|
+
return ctx
|
|
118488
|
+
}
|
|
118489
|
+
|
|
118490
|
+
// Updates a BLAKE2s streaming hash
|
|
118491
|
+
// Requires hash context and Uint8Array (byte array)
|
|
118492
|
+
function blake2sUpdate (ctx, input) {
|
|
118493
|
+
for (let i = 0; i < input.length; i++) {
|
|
118494
|
+
if (ctx.c === 64) {
|
|
118495
|
+
// buffer full ?
|
|
118496
|
+
ctx.t += ctx.c; // add counters
|
|
118497
|
+
blake2sCompress(ctx, false); // compress (not last)
|
|
118498
|
+
ctx.c = 0; // counter to zero
|
|
118499
|
+
}
|
|
118500
|
+
ctx.b[ctx.c++] = input[i];
|
|
118501
|
+
}
|
|
118502
|
+
}
|
|
118503
|
+
|
|
118504
|
+
// Completes a BLAKE2s streaming hash
|
|
118505
|
+
// Returns a Uint8Array containing the message digest
|
|
118506
|
+
function blake2sFinal (ctx) {
|
|
118507
|
+
ctx.t += ctx.c; // mark last block offset
|
|
118508
|
+
while (ctx.c < 64) {
|
|
118509
|
+
// fill up with zeros
|
|
118510
|
+
ctx.b[ctx.c++] = 0;
|
|
118511
|
+
}
|
|
118512
|
+
blake2sCompress(ctx, true); // final block flag = 1
|
|
118513
|
+
|
|
118514
|
+
// little endian convert and store
|
|
118515
|
+
const out = new Uint8Array(ctx.outlen);
|
|
118516
|
+
for (let i = 0; i < ctx.outlen; i++) {
|
|
118517
|
+
out[i] = (ctx.h[i >> 2] >> (8 * (i & 3))) & 0xff;
|
|
118518
|
+
}
|
|
118519
|
+
return out
|
|
118520
|
+
}
|
|
118521
|
+
|
|
118522
|
+
// Computes the BLAKE2S hash of a string or byte array, and returns a Uint8Array
|
|
118523
|
+
//
|
|
118524
|
+
// Returns a n-byte Uint8Array
|
|
118525
|
+
//
|
|
118526
|
+
// Parameters:
|
|
118527
|
+
// - input - the input bytes, as a string, Buffer, or Uint8Array
|
|
118528
|
+
// - key - optional key Uint8Array, up to 32 bytes
|
|
118529
|
+
// - outlen - optional output length in bytes, default 64
|
|
118530
|
+
function blake2s (input, key, outlen) {
|
|
118531
|
+
// preprocess inputs
|
|
118532
|
+
outlen = outlen || 32;
|
|
118533
|
+
input = util.normalizeInput(input);
|
|
118534
|
+
|
|
118535
|
+
// do the math
|
|
118536
|
+
const ctx = blake2sInit(outlen, key);
|
|
118537
|
+
blake2sUpdate(ctx, input);
|
|
118538
|
+
return blake2sFinal(ctx)
|
|
118539
|
+
}
|
|
118540
|
+
|
|
118541
|
+
// Computes the BLAKE2S hash of a string or byte array
|
|
118542
|
+
//
|
|
118543
|
+
// Returns an n-byte hash in hex, all lowercase
|
|
118544
|
+
//
|
|
118545
|
+
// Parameters:
|
|
118546
|
+
// - input - the input bytes, as a string, Buffer, or Uint8Array
|
|
118547
|
+
// - key - optional key Uint8Array, up to 32 bytes
|
|
118548
|
+
// - outlen - optional output length in bytes, default 64
|
|
118549
|
+
function blake2sHex (input, key, outlen) {
|
|
118550
|
+
const output = blake2s(input, key, outlen);
|
|
118551
|
+
return util.toHex(output)
|
|
118552
|
+
}
|
|
118553
|
+
|
|
118554
|
+
blake2s_1 = {
|
|
118555
|
+
blake2s: blake2s,
|
|
118556
|
+
blake2sHex: blake2sHex,
|
|
118557
|
+
blake2sInit: blake2sInit,
|
|
118558
|
+
blake2sUpdate: blake2sUpdate,
|
|
118559
|
+
blake2sFinal: blake2sFinal
|
|
118560
|
+
};
|
|
118561
|
+
return blake2s_1;
|
|
118562
|
+
}
|
|
118563
|
+
|
|
118564
|
+
var blakejs;
|
|
118565
|
+
var hasRequiredBlakejs;
|
|
118566
|
+
|
|
118567
|
+
function requireBlakejs () {
|
|
118568
|
+
if (hasRequiredBlakejs) return blakejs;
|
|
118569
|
+
hasRequiredBlakejs = 1;
|
|
118570
|
+
const b2b = requireBlake2b();
|
|
118571
|
+
const b2s = requireBlake2s();
|
|
118572
|
+
|
|
118573
|
+
blakejs = {
|
|
118574
|
+
blake2b: b2b.blake2b,
|
|
118575
|
+
blake2bHex: b2b.blake2bHex,
|
|
118576
|
+
blake2bInit: b2b.blake2bInit,
|
|
118577
|
+
blake2bUpdate: b2b.blake2bUpdate,
|
|
118578
|
+
blake2bFinal: b2b.blake2bFinal,
|
|
118579
|
+
blake2s: b2s.blake2s,
|
|
118580
|
+
blake2sHex: b2s.blake2sHex,
|
|
118581
|
+
blake2sInit: b2s.blake2sInit,
|
|
118582
|
+
blake2sUpdate: b2s.blake2sUpdate,
|
|
118583
|
+
blake2sFinal: b2s.blake2sFinal
|
|
118584
|
+
};
|
|
118585
|
+
return blakejs;
|
|
118586
|
+
}
|
|
118548
118587
|
|
|
118549
118588
|
var hasRequiredHash;
|
|
118550
118589
|
|
|
@@ -118553,12 +118592,12 @@ function requireHash () {
|
|
|
118553
118592
|
hasRequiredHash = 1;
|
|
118554
118593
|
Object.defineProperty(hash, "__esModule", { value: true });
|
|
118555
118594
|
hash.ripemd160 = hash.blake128WithKey = hash.blake128 = hash.blake160WithKey = hash.blake160 = hash.blake256WithKey = hash.blake256 = void 0;
|
|
118556
|
-
const crypto_js_1 =
|
|
118595
|
+
const crypto_js_1 = requireCryptoJs();
|
|
118557
118596
|
const utility_1 = requireUtility();
|
|
118558
118597
|
/**
|
|
118559
118598
|
* @hidden
|
|
118560
118599
|
*/
|
|
118561
|
-
const blake =
|
|
118600
|
+
const blake = requireBlakejs();
|
|
118562
118601
|
/**
|
|
118563
118602
|
* Gets data's 256 bit blake hash.
|
|
118564
118603
|
* @param data buffer or hexadecimal string
|
|
@@ -127658,6 +127697,58 @@ const getPrefix = (network) => {
|
|
|
127658
127697
|
return 'tthor';
|
|
127659
127698
|
}
|
|
127660
127699
|
};
|
|
127700
|
+
/**
|
|
127701
|
+
* Parse the derivation path from a string to an Array of numbers
|
|
127702
|
+
* @param {string} path - Path to parse
|
|
127703
|
+
* @returns {number[]} - The derivation path as Array of numbers
|
|
127704
|
+
*/
|
|
127705
|
+
const parseDerivationPath = (path) => {
|
|
127706
|
+
if (!path.startsWith('m'))
|
|
127707
|
+
throw new Error("Path string must start with 'm'");
|
|
127708
|
+
let rest = path.slice(1);
|
|
127709
|
+
const out = new Array();
|
|
127710
|
+
while (rest) {
|
|
127711
|
+
const match = rest.match(/^\/([0-9]+)('?)/);
|
|
127712
|
+
if (!match)
|
|
127713
|
+
throw new Error('Syntax error while reading path component');
|
|
127714
|
+
const [fullMatch, numberString] = match;
|
|
127715
|
+
const value = build$6.Uint53.fromString(numberString).toNumber();
|
|
127716
|
+
if (value >= Math.pow(2, 31))
|
|
127717
|
+
throw new Error('Component value too high. Must not exceed 2**31-1.');
|
|
127718
|
+
out.push(value);
|
|
127719
|
+
rest = rest.slice(fullMatch.length);
|
|
127720
|
+
}
|
|
127721
|
+
return out;
|
|
127722
|
+
};
|
|
127723
|
+
/**
|
|
127724
|
+
* Sort JSON object
|
|
127725
|
+
* @param {any} obj - JSON object
|
|
127726
|
+
* @returns {any} JSON object sorted
|
|
127727
|
+
*/
|
|
127728
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
127729
|
+
function sortedObject(obj) {
|
|
127730
|
+
if (typeof obj !== 'object' || obj === null) {
|
|
127731
|
+
return obj;
|
|
127732
|
+
}
|
|
127733
|
+
if (Array.isArray(obj)) {
|
|
127734
|
+
return obj.map(sortedObject);
|
|
127735
|
+
}
|
|
127736
|
+
const sortedKeys = Object.keys(obj).sort();
|
|
127737
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
127738
|
+
const result = {};
|
|
127739
|
+
// NOTE: Use forEach instead of reduce for performance with large objects eg Wasm code
|
|
127740
|
+
sortedKeys.forEach((key) => {
|
|
127741
|
+
result[key] = sortedObject(obj[key]);
|
|
127742
|
+
});
|
|
127743
|
+
return result;
|
|
127744
|
+
}
|
|
127745
|
+
/**
|
|
127746
|
+
* Returns a JSON string with objects sorted by key
|
|
127747
|
+
* */
|
|
127748
|
+
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types, @typescript-eslint/no-explicit-any
|
|
127749
|
+
function sortAndStringifyJson(obj) {
|
|
127750
|
+
return JSON.stringify(sortedObject(obj));
|
|
127751
|
+
}
|
|
127661
127752
|
|
|
127662
127753
|
/**
|
|
127663
127754
|
* Import necessary modules and types for the Thorchain client configuration.
|
|
@@ -127727,7 +127818,7 @@ const defaultClientConfig = {
|
|
|
127727
127818
|
};
|
|
127728
127819
|
|
|
127729
127820
|
/**
|
|
127730
|
-
* Thorchain client
|
|
127821
|
+
* Thorchain base client
|
|
127731
127822
|
*/
|
|
127732
127823
|
class Client extends xchainCosmosSdk.Client {
|
|
127733
127824
|
/**
|
|
@@ -127738,53 +127829,6 @@ class Client extends xchainCosmosSdk.Client {
|
|
|
127738
127829
|
constructor(config = defaultClientConfig) {
|
|
127739
127830
|
super(Object.assign(Object.assign({}, defaultClientConfig), config));
|
|
127740
127831
|
}
|
|
127741
|
-
/**
|
|
127742
|
-
* Asynchronous version of getAddress method.
|
|
127743
|
-
* @param {number} index Derivation path index of the address to be generated.
|
|
127744
|
-
* @returns {string} A promise that resolves to the generated address.
|
|
127745
|
-
*/
|
|
127746
|
-
getAddressAsync(index = 0) {
|
|
127747
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
127748
|
-
return this.getAddress(index);
|
|
127749
|
-
});
|
|
127750
|
-
}
|
|
127751
|
-
/**
|
|
127752
|
-
* Get the address derived from the provided phrase.
|
|
127753
|
-
* @param {number | undefined} walletIndex The index of the address derivation path. Default is 0.
|
|
127754
|
-
* @returns {string} The user address at the specified walletIndex.
|
|
127755
|
-
*/
|
|
127756
|
-
getAddress(walletIndex) {
|
|
127757
|
-
const seed = getSeed(this.phrase);
|
|
127758
|
-
const node = bip32.fromSeed(seed);
|
|
127759
|
-
const child = node.derivePath(this.getFullDerivationPath(walletIndex || 0));
|
|
127760
|
-
if (!child.privateKey)
|
|
127761
|
-
throw new Error('child does not have a privateKey');
|
|
127762
|
-
// TODO: Make this method async and use CosmosJS official address generation strategy
|
|
127763
|
-
const pubKey = secp256k1.publicKeyCreate(child.privateKey);
|
|
127764
|
-
const rawAddress = this.hash160(Uint8Array.from(pubKey));
|
|
127765
|
-
const words = bech32$1.toWords(Buffer.from(rawAddress));
|
|
127766
|
-
const address = bech32$1.encode(this.prefix, words);
|
|
127767
|
-
return address;
|
|
127768
|
-
}
|
|
127769
|
-
transfer(params) {
|
|
127770
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
127771
|
-
const sender = yield this.getAddressAsync(params.walletIndex || 0);
|
|
127772
|
-
const { rawUnsignedTx } = yield this.prepareTx({
|
|
127773
|
-
sender,
|
|
127774
|
-
recipient: params.recipient,
|
|
127775
|
-
asset: params.asset,
|
|
127776
|
-
amount: params.amount,
|
|
127777
|
-
memo: params.memo,
|
|
127778
|
-
});
|
|
127779
|
-
const unsignedTx = protoSigning.decodeTxRaw(encoding.fromBase64(rawUnsignedTx));
|
|
127780
|
-
const signer = yield protoSigning.DirectSecp256k1HdWallet.fromMnemonic(this.phrase, {
|
|
127781
|
-
prefix: this.prefix,
|
|
127782
|
-
hdPaths: [xchainCosmosSdk.makeClientPath(this.getFullDerivationPath(params.walletIndex || 0))],
|
|
127783
|
-
});
|
|
127784
|
-
const tx = yield this.roundRobinSignAndBroadcastTx(sender, unsignedTx, signer);
|
|
127785
|
-
return tx.transactionHash;
|
|
127786
|
-
});
|
|
127787
|
-
}
|
|
127788
127832
|
/**
|
|
127789
127833
|
* Get address prefix by network
|
|
127790
127834
|
* @param {Network} network The network of which return the prefix
|
|
@@ -127905,60 +127949,70 @@ class Client extends xchainCosmosSdk.Client {
|
|
|
127905
127949
|
});
|
|
127906
127950
|
}
|
|
127907
127951
|
/**
|
|
127908
|
-
*
|
|
127952
|
+
* Get deposit transaction
|
|
127909
127953
|
*
|
|
127910
|
-
* @
|
|
127911
|
-
*
|
|
127912
|
-
* @param {Asset} param.asset Optional - The asset that will be deposit. If it is not set, Thorchain native asset will be
|
|
127913
|
-
* used
|
|
127914
|
-
* @param {BaseAmount} param.amount The amount that will be deposit
|
|
127915
|
-
* @param {string} param.memo Optional - The memo associated with the deposit
|
|
127916
|
-
* @param {BigNumber} param.gasLimit Optional - The limit amount of gas allowed to spend in the deposit. If not set, default
|
|
127917
|
-
* value of 600000000 will be used
|
|
127918
|
-
* @returns {string} The deposit hash
|
|
127954
|
+
* @deprecated Use getTransactionData instead
|
|
127955
|
+
* @param {string} txId The transaction ID for which to get the deposit transaction
|
|
127919
127956
|
*/
|
|
127920
|
-
|
|
127957
|
+
getDepositTransaction(txId) {
|
|
127921
127958
|
return __awaiter(this, void 0, void 0, function* () {
|
|
127922
|
-
|
|
127923
|
-
const sender = yield this.getAddressAsync(walletIndex);
|
|
127924
|
-
// Create signer
|
|
127925
|
-
const signer = yield protoSigning.DirectSecp256k1HdWallet.fromMnemonic(this.phrase, {
|
|
127926
|
-
prefix: this.prefix,
|
|
127927
|
-
hdPaths: [xchainCosmosSdk.makeClientPath(this.getFullDerivationPath(walletIndex || 0))],
|
|
127928
|
-
});
|
|
127929
|
-
const tx = yield this.roundRobinSignAndBroadcastDeposit(sender, signer, gasLimit, amount, memo, asset);
|
|
127930
|
-
return tx.transactionHash;
|
|
127959
|
+
return this.getTransactionData(txId);
|
|
127931
127960
|
});
|
|
127932
127961
|
}
|
|
127933
127962
|
/**
|
|
127934
|
-
*
|
|
127963
|
+
* Get the message type url by type used by the cosmos-sdk client to make certain actions
|
|
127935
127964
|
*
|
|
127936
|
-
* @
|
|
127965
|
+
* @param {MsgTypes} msgType The message type of which return the type url
|
|
127966
|
+
* @returns {string} the type url of the message
|
|
127937
127967
|
*/
|
|
127938
|
-
|
|
127968
|
+
getMsgTypeUrlByType(msgType) {
|
|
127969
|
+
const messageTypeUrls = {
|
|
127970
|
+
[xchainCosmosSdk.MsgTypes.TRANSFER]: MSG_SEND_TYPE_URL,
|
|
127971
|
+
};
|
|
127972
|
+
return messageTypeUrls[msgType];
|
|
127973
|
+
}
|
|
127974
|
+
/**
|
|
127975
|
+
* Returns the standard fee used by the client
|
|
127976
|
+
*
|
|
127977
|
+
* @returns {StdFee} the standard fee
|
|
127978
|
+
*/
|
|
127979
|
+
getStandardFee() {
|
|
127980
|
+
return { amount: [], gas: '6000000' };
|
|
127981
|
+
}
|
|
127982
|
+
}
|
|
127983
|
+
|
|
127984
|
+
/**
|
|
127985
|
+
* Thorchain Keystore client
|
|
127986
|
+
*/
|
|
127987
|
+
class ClientKeystore extends Client {
|
|
127988
|
+
/**
|
|
127989
|
+
* Asynchronous version of getAddress method.
|
|
127990
|
+
* @param {number} index Derivation path index of the address to be generated.
|
|
127991
|
+
* @returns {string} A promise that resolves to the generated address.
|
|
127992
|
+
*/
|
|
127993
|
+
getAddressAsync(index = 0) {
|
|
127939
127994
|
return __awaiter(this, void 0, void 0, function* () {
|
|
127940
|
-
|
|
127941
|
-
const sender = yield this.getAddressAsync(walletIndex);
|
|
127942
|
-
// Prepare unsigned transaction
|
|
127943
|
-
const { rawUnsignedTx } = yield this.prepareTx({
|
|
127944
|
-
sender,
|
|
127945
|
-
recipient: recipient,
|
|
127946
|
-
asset: asset,
|
|
127947
|
-
amount: amount,
|
|
127948
|
-
memo: memo,
|
|
127949
|
-
});
|
|
127950
|
-
// Decode unsigned transaction
|
|
127951
|
-
const unsignedTx = protoSigning.decodeTxRaw(encoding.fromBase64(rawUnsignedTx));
|
|
127952
|
-
// Create signer
|
|
127953
|
-
const signer = yield protoSigning.DirectSecp256k1HdWallet.fromMnemonic(this.phrase, {
|
|
127954
|
-
prefix: this.prefix,
|
|
127955
|
-
hdPaths: [xchainCosmosSdk.makeClientPath(this.getFullDerivationPath(walletIndex))],
|
|
127956
|
-
});
|
|
127957
|
-
const rawTx = yield this.roundRobinSign(sender, unsignedTx, signer, gasLimit);
|
|
127958
|
-
// Return encoded signed transaction
|
|
127959
|
-
return encoding.toBase64(tx$1.TxRaw.encode(rawTx).finish());
|
|
127995
|
+
return this.getAddress(index);
|
|
127960
127996
|
});
|
|
127961
127997
|
}
|
|
127998
|
+
/**
|
|
127999
|
+
* Get the address derived from the provided phrase.
|
|
128000
|
+
* @param {number | undefined} walletIndex The index of the address derivation path. Default is 0.
|
|
128001
|
+
* @returns {string} The user address at the specified walletIndex.
|
|
128002
|
+
*/
|
|
128003
|
+
getAddress(walletIndex) {
|
|
128004
|
+
const seed = getSeed(this.phrase);
|
|
128005
|
+
const node = bip32.fromSeed(seed);
|
|
128006
|
+
const child = node.derivePath(this.getFullDerivationPath(walletIndex || 0));
|
|
128007
|
+
if (!child.privateKey)
|
|
128008
|
+
throw new Error('child does not have a privateKey');
|
|
128009
|
+
// TODO: Make this method async and use CosmosJS official address generation strategy
|
|
128010
|
+
const pubKey = secp256k1.publicKeyCreate(child.privateKey);
|
|
128011
|
+
const rawAddress = this.hash160(Uint8Array.from(pubKey));
|
|
128012
|
+
const words = bech32$1.toWords(Buffer.from(rawAddress));
|
|
128013
|
+
const address = bech32$1.encode(this.prefix, words);
|
|
128014
|
+
return address;
|
|
128015
|
+
}
|
|
127962
128016
|
/**
|
|
127963
128017
|
* Returns the private key associated with an index
|
|
127964
128018
|
*
|
|
@@ -127992,36 +128046,79 @@ class Client extends xchainCosmosSdk.Client {
|
|
|
127992
128046
|
return crypto$2.Secp256k1.compressPubkey(pubkey);
|
|
127993
128047
|
});
|
|
127994
128048
|
}
|
|
127995
|
-
|
|
127996
|
-
* Get deposit transaction
|
|
127997
|
-
*
|
|
127998
|
-
* @deprecated Use getTransactionData instead
|
|
127999
|
-
* @param {string} txId The transaction ID for which to get the deposit transaction
|
|
128000
|
-
*/
|
|
128001
|
-
getDepositTransaction(txId) {
|
|
128049
|
+
transfer(params) {
|
|
128002
128050
|
return __awaiter(this, void 0, void 0, function* () {
|
|
128003
|
-
|
|
128051
|
+
const sender = yield this.getAddressAsync(params.walletIndex || 0);
|
|
128052
|
+
const { rawUnsignedTx } = yield this.prepareTx({
|
|
128053
|
+
sender,
|
|
128054
|
+
recipient: params.recipient,
|
|
128055
|
+
asset: params.asset,
|
|
128056
|
+
amount: params.amount,
|
|
128057
|
+
memo: params.memo,
|
|
128058
|
+
});
|
|
128059
|
+
const unsignedTx = protoSigning.decodeTxRaw(encoding.fromBase64(rawUnsignedTx));
|
|
128060
|
+
const signer = yield protoSigning.DirectSecp256k1HdWallet.fromMnemonic(this.phrase, {
|
|
128061
|
+
prefix: this.prefix,
|
|
128062
|
+
hdPaths: [xchainCosmosSdk.makeClientPath(this.getFullDerivationPath(params.walletIndex || 0))],
|
|
128063
|
+
});
|
|
128064
|
+
const tx = yield this.roundRobinSignAndBroadcastTx(sender, unsignedTx, signer);
|
|
128065
|
+
return tx.transactionHash;
|
|
128004
128066
|
});
|
|
128005
128067
|
}
|
|
128006
128068
|
/**
|
|
128007
|
-
*
|
|
128069
|
+
* Make a deposit
|
|
128008
128070
|
*
|
|
128009
|
-
* @param {
|
|
128010
|
-
*
|
|
128071
|
+
* @param {number} param.walletIndex Optional - The index to use to generate the address from the transaction will be done.
|
|
128072
|
+
* If it is not set, address associated with index 0 will be used
|
|
128073
|
+
* @param {Asset} param.asset Optional - The asset that will be deposit. If it is not set, Thorchain native asset will be
|
|
128074
|
+
* used
|
|
128075
|
+
* @param {BaseAmount} param.amount The amount that will be deposit
|
|
128076
|
+
* @param {string} param.memo Optional - The memo associated with the deposit
|
|
128077
|
+
* @param {BigNumber} param.gasLimit Optional - The limit amount of gas allowed to spend in the deposit. If not set, default
|
|
128078
|
+
* value of 600000000 will be used
|
|
128079
|
+
* @returns {string} The deposit hash
|
|
128011
128080
|
*/
|
|
128012
|
-
|
|
128013
|
-
|
|
128014
|
-
|
|
128015
|
-
|
|
128016
|
-
|
|
128081
|
+
deposit({ walletIndex = 0, asset = AssetRuneNative, amount, memo, gasLimit = new bignumber.BigNumber(DEPOSIT_GAS_LIMIT_VALUE), }) {
|
|
128082
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
128083
|
+
// Get sender address
|
|
128084
|
+
const sender = yield this.getAddressAsync(walletIndex);
|
|
128085
|
+
// Create signer
|
|
128086
|
+
const signer = yield protoSigning.DirectSecp256k1HdWallet.fromMnemonic(this.phrase, {
|
|
128087
|
+
prefix: this.prefix,
|
|
128088
|
+
hdPaths: [xchainCosmosSdk.makeClientPath(this.getFullDerivationPath(walletIndex || 0))],
|
|
128089
|
+
});
|
|
128090
|
+
const tx = yield this.roundRobinSignAndBroadcastDeposit(sender, signer, gasLimit, amount, memo, asset);
|
|
128091
|
+
return tx.transactionHash;
|
|
128092
|
+
});
|
|
128017
128093
|
}
|
|
128018
128094
|
/**
|
|
128019
|
-
*
|
|
128095
|
+
* Create and sign transaction without broadcasting it
|
|
128020
128096
|
*
|
|
128021
|
-
* @
|
|
128097
|
+
* @deprecated Use prepare Tx instead
|
|
128022
128098
|
*/
|
|
128023
|
-
|
|
128024
|
-
return
|
|
128099
|
+
transferOffline({ walletIndex = 0, recipient, asset, amount, memo, gasLimit = new bignumber.BigNumber(DEFAULT_GAS_LIMIT_VALUE), }) {
|
|
128100
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
128101
|
+
// Get sender address
|
|
128102
|
+
const sender = yield this.getAddressAsync(walletIndex);
|
|
128103
|
+
// Prepare unsigned transaction
|
|
128104
|
+
const { rawUnsignedTx } = yield this.prepareTx({
|
|
128105
|
+
sender,
|
|
128106
|
+
recipient: recipient,
|
|
128107
|
+
asset: asset,
|
|
128108
|
+
amount: amount,
|
|
128109
|
+
memo: memo,
|
|
128110
|
+
});
|
|
128111
|
+
// Decode unsigned transaction
|
|
128112
|
+
const unsignedTx = protoSigning.decodeTxRaw(encoding.fromBase64(rawUnsignedTx));
|
|
128113
|
+
// Create signer
|
|
128114
|
+
const signer = yield protoSigning.DirectSecp256k1HdWallet.fromMnemonic(this.phrase, {
|
|
128115
|
+
prefix: this.prefix,
|
|
128116
|
+
hdPaths: [xchainCosmosSdk.makeClientPath(this.getFullDerivationPath(walletIndex))],
|
|
128117
|
+
});
|
|
128118
|
+
const rawTx = yield this.roundRobinSign(sender, unsignedTx, signer, gasLimit);
|
|
128119
|
+
// Return encoded signed transaction
|
|
128120
|
+
return encoding.toBase64(tx$1.TxRaw.encode(rawTx).finish());
|
|
128121
|
+
});
|
|
128025
128122
|
}
|
|
128026
128123
|
/**
|
|
128027
128124
|
* Hashes a buffer using SHA256 followed by RIPEMD160 or RMD160.
|
|
@@ -128050,18 +128147,21 @@ class Client extends xchainCosmosSdk.Client {
|
|
|
128050
128147
|
return __awaiter(this, void 0, void 0, function* () {
|
|
128051
128148
|
// Connect to signing client
|
|
128052
128149
|
for (const url of this.clientUrls[this.network]) {
|
|
128053
|
-
|
|
128054
|
-
|
|
128055
|
-
|
|
128056
|
-
|
|
128057
|
-
|
|
128058
|
-
|
|
128059
|
-
|
|
128060
|
-
|
|
128061
|
-
|
|
128062
|
-
|
|
128063
|
-
|
|
128064
|
-
|
|
128150
|
+
try {
|
|
128151
|
+
const signingClient = yield build$7.SigningStargateClient.connectWithSigner(url, signer, {
|
|
128152
|
+
registry: this.registry,
|
|
128153
|
+
});
|
|
128154
|
+
// Prepare messages
|
|
128155
|
+
const messages = unsignedTx.body.messages.map((message) => {
|
|
128156
|
+
return { typeUrl: this.getMsgTypeUrlByType(xchainCosmosSdk.MsgTypes.TRANSFER), value: signingClient.registry.decode(message) };
|
|
128157
|
+
});
|
|
128158
|
+
// Sign transaction
|
|
128159
|
+
return yield signingClient.sign(sender, messages, {
|
|
128160
|
+
amount: [],
|
|
128161
|
+
gas: gasLimit.toString(),
|
|
128162
|
+
}, unsignedTx.body.memo);
|
|
128163
|
+
}
|
|
128164
|
+
catch (_a) { }
|
|
128065
128165
|
}
|
|
128066
128166
|
throw Error('No clients available. Can not sign transaction');
|
|
128067
128167
|
});
|
|
@@ -128133,8 +128233,230 @@ class Client extends xchainCosmosSdk.Client {
|
|
|
128133
128233
|
}
|
|
128134
128234
|
}
|
|
128135
128235
|
|
|
128236
|
+
/**
|
|
128237
|
+
* Thorchain Ledger client
|
|
128238
|
+
*/
|
|
128239
|
+
class ClientLedger extends Client {
|
|
128240
|
+
constructor(params) {
|
|
128241
|
+
super(Object.assign(Object.assign({}, defaultClientConfig), params));
|
|
128242
|
+
this.app = new THORChainApp__default["default"](params.transport);
|
|
128243
|
+
}
|
|
128244
|
+
/**
|
|
128245
|
+
* Asynchronous version of getAddress method.
|
|
128246
|
+
* @param {number} index Derivation path index of the address to be generated.
|
|
128247
|
+
* @param {boolean} verify True to check the address against the Ledger device, otherwise false
|
|
128248
|
+
* @returns {string} A promise that resolves to the generated address.
|
|
128249
|
+
*/
|
|
128250
|
+
getAddressAsync(index, verify = false) {
|
|
128251
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
128252
|
+
const derivationPath = parseDerivationPath(this.getFullDerivationPath(index || 0));
|
|
128253
|
+
const { bech32Address } = verify
|
|
128254
|
+
? yield this.app.showAddressAndPubKey(derivationPath, this.getPrefix(this.network))
|
|
128255
|
+
: yield this.app.getAddressAndPubKey(derivationPath, this.getPrefix(this.network));
|
|
128256
|
+
return bech32Address;
|
|
128257
|
+
});
|
|
128258
|
+
}
|
|
128259
|
+
/**
|
|
128260
|
+
* @deprecated
|
|
128261
|
+
* Asynchronous version of getAddress method. Not supported for ledger client
|
|
128262
|
+
* @throws {Error} Not supported method
|
|
128263
|
+
*/
|
|
128264
|
+
getAddress() {
|
|
128265
|
+
throw Error('Sync method not supported for Ledger');
|
|
128266
|
+
}
|
|
128267
|
+
/**
|
|
128268
|
+
* Transfers RUNE or synth token
|
|
128269
|
+
*
|
|
128270
|
+
* @param {TxParams} params The transfer options.
|
|
128271
|
+
* @param {number} params.walletIndex Optional - The index to use to generate the address from the transaction will be done.
|
|
128272
|
+
* If it is not set, address associated with index 0 will be used
|
|
128273
|
+
* @param {asset} params.asset Optional - The asset that will be deposit. If it is not set, Thorchain native asset will be
|
|
128274
|
+
* used
|
|
128275
|
+
* @param {BaseAmount} params.amount The amount that will be transfer
|
|
128276
|
+
* @param {string} params.recipient Recipient of the transfer
|
|
128277
|
+
* @param {string} params.memo Optional - The memo associated with the transfer
|
|
128278
|
+
* @returns {TxHash} The transaction hash.
|
|
128279
|
+
*/
|
|
128280
|
+
transfer(params) {
|
|
128281
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
128282
|
+
const signedTx = yield this.transferOffline(params);
|
|
128283
|
+
return this.broadcastTx(signedTx);
|
|
128284
|
+
});
|
|
128285
|
+
}
|
|
128286
|
+
/**
|
|
128287
|
+
* Make a deposit
|
|
128288
|
+
*
|
|
128289
|
+
* @param {number} param.walletIndex Optional - The index to use to generate the address from the transaction will be done.
|
|
128290
|
+
* If it is not set, address associated with index 0 will be used
|
|
128291
|
+
* @param {Asset} param.asset Optional - The asset that will be deposit. If it is not set, Thorchain native asset will be
|
|
128292
|
+
* used
|
|
128293
|
+
* @param {BaseAmount} param.amount The amount that will be deposit
|
|
128294
|
+
* @param {string} param.memo Optional - The memo associated with the deposit
|
|
128295
|
+
* @param {BigNumber} param.gasLimit Optional - The limit amount of gas allowed to spend in the deposit. If not set, default
|
|
128296
|
+
* value of 600000000 will be used
|
|
128297
|
+
* @returns {string} The deposit hash
|
|
128298
|
+
*/
|
|
128299
|
+
deposit({ walletIndex = 0, asset = AssetRuneNative, amount, memo, gasLimit = new bignumber.BigNumber(DEPOSIT_GAS_LIMIT_VALUE), }) {
|
|
128300
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
128301
|
+
const sender = yield this.getAddressAsync(walletIndex || 0);
|
|
128302
|
+
const account = yield this.getAccount(sender);
|
|
128303
|
+
const formattedDP = parseDerivationPath(this.getFullDerivationPath(walletIndex || 0));
|
|
128304
|
+
const { compressedPk } = yield this.app.getAddressAndPubKey(formattedDP, this.getPrefix(this.getNetwork()));
|
|
128305
|
+
const pubkey = protoSigning.encodePubkey({
|
|
128306
|
+
type: 'tendermint/PubKeySecp256k1',
|
|
128307
|
+
value: encoding.toBase64(compressedPk),
|
|
128308
|
+
});
|
|
128309
|
+
const msgs = sortedObject([
|
|
128310
|
+
{
|
|
128311
|
+
type: 'thorchain/MsgDeposit',
|
|
128312
|
+
value: {
|
|
128313
|
+
signer: sender,
|
|
128314
|
+
memo,
|
|
128315
|
+
coins: [
|
|
128316
|
+
{
|
|
128317
|
+
amount: amount.amount().toString(),
|
|
128318
|
+
asset: xchainUtil.assetToString(asset),
|
|
128319
|
+
},
|
|
128320
|
+
],
|
|
128321
|
+
},
|
|
128322
|
+
},
|
|
128323
|
+
]);
|
|
128324
|
+
const fee = { amount: [], gas: gasLimit.toString() };
|
|
128325
|
+
const { signature, returnCode, errorMessage } = yield this.app.sign(formattedDP, sortAndStringifyJson({
|
|
128326
|
+
account_number: account.accountNumber.toString(),
|
|
128327
|
+
chain_id: yield this.getChainId(),
|
|
128328
|
+
fee,
|
|
128329
|
+
memo,
|
|
128330
|
+
msgs,
|
|
128331
|
+
sequence: account.sequence.toString(),
|
|
128332
|
+
}));
|
|
128333
|
+
if (!signature)
|
|
128334
|
+
throw Error(`Can not sign deposit transaction. Return code ${returnCode}. Error: ${errorMessage}`);
|
|
128335
|
+
const aminoTypes = this.getProtocolAminoMessages();
|
|
128336
|
+
const rawTx = tx$1.TxRaw.fromPartial({
|
|
128337
|
+
bodyBytes: yield this.registry.encodeTxBody({
|
|
128338
|
+
memo,
|
|
128339
|
+
messages: msgs.map((msg) => aminoTypes.fromAmino(msg)),
|
|
128340
|
+
}),
|
|
128341
|
+
authInfoBytes: protoSigning.makeAuthInfoBytes([
|
|
128342
|
+
{
|
|
128343
|
+
pubkey,
|
|
128344
|
+
sequence: account.sequence,
|
|
128345
|
+
},
|
|
128346
|
+
], fee.amount, Number.parseInt(fee.gas), undefined, undefined, signing.SignMode.SIGN_MODE_LEGACY_AMINO_JSON),
|
|
128347
|
+
signatures: [THORChainApp.extractSignatureFromTLV(signature)],
|
|
128348
|
+
});
|
|
128349
|
+
return this.broadcastTx(encoding.toBase64(tx$1.TxRaw.encode(rawTx).finish()));
|
|
128350
|
+
});
|
|
128351
|
+
}
|
|
128352
|
+
/**
|
|
128353
|
+
* @deprecated
|
|
128354
|
+
* Create a transaction and sign it without broadcasting it
|
|
128355
|
+
*
|
|
128356
|
+
* @param {TxParams} params The transfer options.
|
|
128357
|
+
* @param {number} params.walletIndex Optional - The index to use to generate the address from the transaction will be done.
|
|
128358
|
+
* If it is not set, address associated with index 0 will be used
|
|
128359
|
+
* @param {asset} params.asset Optional - The asset that will be deposit. If it is not set, Thorchain native asset will be
|
|
128360
|
+
* used
|
|
128361
|
+
* @param {BaseAmount} params.amount The amount that will be transfer
|
|
128362
|
+
* @param {string} params.recipient Recipient of the transfer
|
|
128363
|
+
* @param {string} params.memo Optional - The memo associated with the transfer
|
|
128364
|
+
* @returns {TxHash} The transaction hash.
|
|
128365
|
+
*/
|
|
128366
|
+
transferOffline(params) {
|
|
128367
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
128368
|
+
const sender = yield this.getAddressAsync(params.walletIndex || 0);
|
|
128369
|
+
const account = yield this.getAccount(sender);
|
|
128370
|
+
const formattedDP = parseDerivationPath(this.getFullDerivationPath(params.walletIndex || 0));
|
|
128371
|
+
const { compressedPk } = yield this.app.getAddressAndPubKey(formattedDP, this.getPrefix(this.getNetwork()));
|
|
128372
|
+
const pubkey = protoSigning.encodePubkey({
|
|
128373
|
+
type: 'tendermint/PubKeySecp256k1',
|
|
128374
|
+
value: encoding.toBase64(compressedPk),
|
|
128375
|
+
});
|
|
128376
|
+
const msgs = sortedObject([
|
|
128377
|
+
{
|
|
128378
|
+
type: 'thorchain/MsgSend',
|
|
128379
|
+
value: {
|
|
128380
|
+
from_address: sender,
|
|
128381
|
+
to_address: params.recipient,
|
|
128382
|
+
amount: [
|
|
128383
|
+
{
|
|
128384
|
+
amount: params.amount.amount().toString(),
|
|
128385
|
+
denom: this.getDenom(params.asset || AssetRuneNative),
|
|
128386
|
+
},
|
|
128387
|
+
],
|
|
128388
|
+
},
|
|
128389
|
+
},
|
|
128390
|
+
]);
|
|
128391
|
+
const fee = this.getStandardFee();
|
|
128392
|
+
const { signature, returnCode, errorMessage } = yield this.app.sign(formattedDP, sortAndStringifyJson({
|
|
128393
|
+
account_number: account.accountNumber.toString(),
|
|
128394
|
+
chain_id: yield this.getChainId(),
|
|
128395
|
+
fee,
|
|
128396
|
+
memo: params.memo || '',
|
|
128397
|
+
msgs,
|
|
128398
|
+
sequence: account.sequence.toString(),
|
|
128399
|
+
}));
|
|
128400
|
+
if (!signature)
|
|
128401
|
+
throw Error(`Can not sign transfer transaction. Return code ${returnCode}. Error: ${errorMessage}`);
|
|
128402
|
+
const aminoTypes = this.getProtocolAminoMessages();
|
|
128403
|
+
const rawTx = tx$1.TxRaw.fromPartial({
|
|
128404
|
+
bodyBytes: yield this.registry.encodeTxBody({
|
|
128405
|
+
messages: msgs.map((msg) => aminoTypes.fromAmino(msg)),
|
|
128406
|
+
memo: params.memo,
|
|
128407
|
+
}),
|
|
128408
|
+
authInfoBytes: protoSigning.makeAuthInfoBytes([
|
|
128409
|
+
{
|
|
128410
|
+
pubkey,
|
|
128411
|
+
sequence: account.sequence,
|
|
128412
|
+
},
|
|
128413
|
+
], fee.amount, Number.parseInt(fee.gas), undefined, undefined, signing.SignMode.SIGN_MODE_LEGACY_AMINO_JSON),
|
|
128414
|
+
signatures: [THORChainApp.extractSignatureFromTLV(signature)],
|
|
128415
|
+
});
|
|
128416
|
+
return encoding.toBase64(tx$1.TxRaw.encode(rawTx).finish());
|
|
128417
|
+
});
|
|
128418
|
+
}
|
|
128419
|
+
getProtocolAminoMessages() {
|
|
128420
|
+
const prefix = this.getPrefix(this.network);
|
|
128421
|
+
return new build$7.AminoTypes({
|
|
128422
|
+
'/types.MsgSend': {
|
|
128423
|
+
aminoType: `thorchain/MsgSend`,
|
|
128424
|
+
toAmino: (params) => ({
|
|
128425
|
+
from_address: xchainCosmosSdk.base64ToBech32(params.fromAddress, prefix),
|
|
128426
|
+
to_address: xchainCosmosSdk.base64ToBech32(params.toAddress, prefix),
|
|
128427
|
+
amount: [...params.amount],
|
|
128428
|
+
}),
|
|
128429
|
+
fromAmino: (params) => ({
|
|
128430
|
+
fromAddress: xchainCosmosSdk.bech32ToBase64(params.from_address),
|
|
128431
|
+
toAddress: xchainCosmosSdk.bech32ToBase64(params.to_address),
|
|
128432
|
+
amount: [...params.amount],
|
|
128433
|
+
}),
|
|
128434
|
+
},
|
|
128435
|
+
'/types.MsgDeposit': {
|
|
128436
|
+
aminoType: `thorchain/MsgDeposit`,
|
|
128437
|
+
toAmino: (params) => ({
|
|
128438
|
+
signer: xchainCosmosSdk.base64ToBech32(params.signer, prefix),
|
|
128439
|
+
memo: params.memo,
|
|
128440
|
+
coins: params.coins.map((coin) => {
|
|
128441
|
+
return Object.assign(Object.assign({}, coin), { asset: xchainUtil.assetToString(coin.asset) });
|
|
128442
|
+
}),
|
|
128443
|
+
}),
|
|
128444
|
+
fromAmino: (params) => ({
|
|
128445
|
+
signer: xchainCosmosSdk.bech32ToBase64(params.signer),
|
|
128446
|
+
memo: params.memo,
|
|
128447
|
+
coins: params.coins.map((coin) => {
|
|
128448
|
+
return Object.assign(Object.assign({}, coin), { asset: xchainUtil.assetFromStringEx(coin.asset) });
|
|
128449
|
+
}),
|
|
128450
|
+
}),
|
|
128451
|
+
},
|
|
128452
|
+
});
|
|
128453
|
+
}
|
|
128454
|
+
}
|
|
128455
|
+
|
|
128136
128456
|
exports.AssetRuneNative = AssetRuneNative;
|
|
128137
|
-
exports.Client =
|
|
128457
|
+
exports.Client = ClientKeystore;
|
|
128458
|
+
exports.ClientKeystore = ClientKeystore;
|
|
128459
|
+
exports.ClientLedger = ClientLedger;
|
|
128138
128460
|
exports.DEFAULT_EXPLORER_URL = DEFAULT_EXPLORER_URL;
|
|
128139
128461
|
exports.DEFAULT_FEE = DEFAULT_FEE;
|
|
128140
128462
|
exports.DEFAULT_GAS_LIMIT_VALUE = DEFAULT_GAS_LIMIT_VALUE;
|
|
@@ -128155,4 +128477,7 @@ exports.getExplorerAddressUrl = getExplorerAddressUrl;
|
|
|
128155
128477
|
exports.getExplorerTxUrl = getExplorerTxUrl;
|
|
128156
128478
|
exports.getPrefix = getPrefix;
|
|
128157
128479
|
exports.isAssetRuneNative = isAssetRuneNative;
|
|
128480
|
+
exports.parseDerivationPath = parseDerivationPath;
|
|
128481
|
+
exports.sortAndStringifyJson = sortAndStringifyJson;
|
|
128482
|
+
exports.sortedObject = sortedObject;
|
|
128158
128483
|
//# sourceMappingURL=index.js.map
|