@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.esm.js
CHANGED
|
@@ -1,22 +1,23 @@
|
|
|
1
1
|
import * as crypto$2 from '@cosmjs/crypto';
|
|
2
2
|
import { EnglishMnemonic, Bip39, Slip10, Slip10Curve, Secp256k1 } from '@cosmjs/crypto';
|
|
3
3
|
import * as encoding from '@cosmjs/encoding';
|
|
4
|
-
import {
|
|
4
|
+
import { toBase64, fromBase64 } from '@cosmjs/encoding';
|
|
5
5
|
import * as protoSigning from '@cosmjs/proto-signing';
|
|
6
|
-
import { decodeTxRaw, DirectSecp256k1HdWallet } from '@cosmjs/proto-signing';
|
|
6
|
+
import { decodeTxRaw, DirectSecp256k1HdWallet, encodePubkey, makeAuthInfoBytes } from '@cosmjs/proto-signing';
|
|
7
7
|
import * as amino from '@cosmjs/amino';
|
|
8
8
|
import * as axios from 'axios';
|
|
9
9
|
import axios__default from 'axios';
|
|
10
|
-
import { Client as Client$1, MsgTypes, makeClientPath,
|
|
10
|
+
import { Client as Client$1, bech32ToBase64, MsgTypes, makeClientPath, base64ToBech32 } from '@xchainjs/xchain-cosmos-sdk';
|
|
11
11
|
import { createHash } from 'crypto';
|
|
12
12
|
import * as buffer from 'buffer';
|
|
13
13
|
import * as bignumber from 'bignumber.js';
|
|
14
14
|
import { BigNumber } from 'bignumber.js';
|
|
15
15
|
import { toWords as toWords$1, encode as encode$2 } from 'bech32';
|
|
16
|
-
import { assetToString, isSynthAsset, assetToBase, assetAmount, eqAsset, assetFromString } from '@xchainjs/xchain-util';
|
|
17
16
|
import { fromSeed } from 'bip32';
|
|
18
17
|
import { publicKeyCreate } from 'secp256k1';
|
|
18
|
+
import { assetToString, isSynthAsset, assetToBase, assetAmount, eqAsset, assetFromString, assetFromStringEx } from '@xchainjs/xchain-util';
|
|
19
19
|
import { Network } from '@xchainjs/xchain-client';
|
|
20
|
+
import THORChainApp, { extractSignatureFromTLV } from '@xchainjs/ledger-thorchain';
|
|
20
21
|
|
|
21
22
|
/******************************************************************************
|
|
22
23
|
Copyright (c) Microsoft Corporation.
|
|
@@ -5510,13 +5511,13 @@ function requireMinimal () {
|
|
|
5510
5511
|
|
|
5511
5512
|
var writer = Writer$1;
|
|
5512
5513
|
|
|
5513
|
-
var util$
|
|
5514
|
+
var util$5 = requireMinimal();
|
|
5514
5515
|
|
|
5515
5516
|
var BufferWriter$1; // cyclic
|
|
5516
5517
|
|
|
5517
|
-
var LongBits$1 = util$
|
|
5518
|
-
base64 = util$
|
|
5519
|
-
utf8$1 = util$
|
|
5518
|
+
var LongBits$1 = util$5.LongBits,
|
|
5519
|
+
base64 = util$5.base64,
|
|
5520
|
+
utf8$1 = util$5.utf8;
|
|
5520
5521
|
|
|
5521
5522
|
/**
|
|
5522
5523
|
* Constructs a new writer operation instance.
|
|
@@ -5631,7 +5632,7 @@ function Writer$1() {
|
|
|
5631
5632
|
}
|
|
5632
5633
|
|
|
5633
5634
|
var create$1 = function create() {
|
|
5634
|
-
return util$
|
|
5635
|
+
return util$5.Buffer
|
|
5635
5636
|
? function create_buffer_setup() {
|
|
5636
5637
|
return (Writer$1.create = function create_buffer() {
|
|
5637
5638
|
return new BufferWriter$1();
|
|
@@ -5656,13 +5657,13 @@ Writer$1.create = create$1();
|
|
|
5656
5657
|
* @returns {Uint8Array} Buffer
|
|
5657
5658
|
*/
|
|
5658
5659
|
Writer$1.alloc = function alloc(size) {
|
|
5659
|
-
return new util$
|
|
5660
|
+
return new util$5.Array(size);
|
|
5660
5661
|
};
|
|
5661
5662
|
|
|
5662
5663
|
// Use Uint8Array buffer pool in the browser, just like node does with buffers
|
|
5663
5664
|
/* istanbul ignore else */
|
|
5664
|
-
if (util$
|
|
5665
|
-
Writer$1.alloc = util$
|
|
5665
|
+
if (util$5.Array !== Array)
|
|
5666
|
+
Writer$1.alloc = util$5.pool(Writer$1.alloc, util$5.Array.prototype.subarray);
|
|
5666
5667
|
|
|
5667
5668
|
/**
|
|
5668
5669
|
* Pushes a new operation to the queue.
|
|
@@ -5852,7 +5853,7 @@ Writer$1.prototype.sfixed64 = Writer$1.prototype.fixed64;
|
|
|
5852
5853
|
* @returns {Writer} `this`
|
|
5853
5854
|
*/
|
|
5854
5855
|
Writer$1.prototype.float = function write_float(value) {
|
|
5855
|
-
return this._push(util$
|
|
5856
|
+
return this._push(util$5.float.writeFloatLE, 4, value);
|
|
5856
5857
|
};
|
|
5857
5858
|
|
|
5858
5859
|
/**
|
|
@@ -5862,10 +5863,10 @@ Writer$1.prototype.float = function write_float(value) {
|
|
|
5862
5863
|
* @returns {Writer} `this`
|
|
5863
5864
|
*/
|
|
5864
5865
|
Writer$1.prototype.double = function write_double(value) {
|
|
5865
|
-
return this._push(util$
|
|
5866
|
+
return this._push(util$5.float.writeDoubleLE, 8, value);
|
|
5866
5867
|
};
|
|
5867
5868
|
|
|
5868
|
-
var writeBytes = util$
|
|
5869
|
+
var writeBytes = util$5.Array.prototype.set
|
|
5869
5870
|
? function writeBytes_set(val, buf, pos) {
|
|
5870
5871
|
buf.set(val, pos); // also works for plain array values
|
|
5871
5872
|
}
|
|
@@ -5884,7 +5885,7 @@ Writer$1.prototype.bytes = function write_bytes(value) {
|
|
|
5884
5885
|
var len = value.length >>> 0;
|
|
5885
5886
|
if (!len)
|
|
5886
5887
|
return this._push(writeByte, 1, 0);
|
|
5887
|
-
if (util$
|
|
5888
|
+
if (util$5.isString(value)) {
|
|
5888
5889
|
var buf = Writer$1.alloc(len = base64.length(value));
|
|
5889
5890
|
base64.decode(value, buf, 0);
|
|
5890
5891
|
value = buf;
|
|
@@ -5979,7 +5980,7 @@ var writer_buffer = BufferWriter;
|
|
|
5979
5980
|
var Writer = writer;
|
|
5980
5981
|
(BufferWriter.prototype = Object.create(Writer.prototype)).constructor = BufferWriter;
|
|
5981
5982
|
|
|
5982
|
-
var util$
|
|
5983
|
+
var util$4 = requireMinimal();
|
|
5983
5984
|
|
|
5984
5985
|
/**
|
|
5985
5986
|
* Constructs a new buffer writer instance.
|
|
@@ -5998,9 +5999,9 @@ BufferWriter._configure = function () {
|
|
|
5998
5999
|
* @param {number} size Buffer size
|
|
5999
6000
|
* @returns {Buffer} Buffer
|
|
6000
6001
|
*/
|
|
6001
|
-
BufferWriter.alloc = util$
|
|
6002
|
+
BufferWriter.alloc = util$4._Buffer_allocUnsafe;
|
|
6002
6003
|
|
|
6003
|
-
BufferWriter.writeBytesBuffer = util$
|
|
6004
|
+
BufferWriter.writeBytesBuffer = util$4.Buffer && util$4.Buffer.prototype instanceof Uint8Array && util$4.Buffer.prototype.set.name === "set"
|
|
6004
6005
|
? function writeBytesBuffer_set(val, buf, pos) {
|
|
6005
6006
|
buf.set(val, pos); // faster than copy (requires node >= 4 where Buffers extend Uint8Array and set is properly inherited)
|
|
6006
6007
|
// also works for plain array values
|
|
@@ -6019,8 +6020,8 @@ BufferWriter._configure = function () {
|
|
|
6019
6020
|
* @override
|
|
6020
6021
|
*/
|
|
6021
6022
|
BufferWriter.prototype.bytes = function write_bytes_buffer(value) {
|
|
6022
|
-
if (util$
|
|
6023
|
-
value = util$
|
|
6023
|
+
if (util$4.isString(value))
|
|
6024
|
+
value = util$4._Buffer_from(value, "base64");
|
|
6024
6025
|
var len = value.length >>> 0;
|
|
6025
6026
|
this.uint32(len);
|
|
6026
6027
|
if (len)
|
|
@@ -6030,7 +6031,7 @@ BufferWriter.prototype.bytes = function write_bytes_buffer(value) {
|
|
|
6030
6031
|
|
|
6031
6032
|
function writeStringBuffer(val, buf, pos) {
|
|
6032
6033
|
if (val.length < 40) // plain js is faster for short strings (probably due to redundant assertions)
|
|
6033
|
-
util$
|
|
6034
|
+
util$4.utf8.write(val, buf, pos);
|
|
6034
6035
|
else if (buf.utf8Write)
|
|
6035
6036
|
buf.utf8Write(val, pos);
|
|
6036
6037
|
else
|
|
@@ -6041,7 +6042,7 @@ function writeStringBuffer(val, buf, pos) {
|
|
|
6041
6042
|
* @override
|
|
6042
6043
|
*/
|
|
6043
6044
|
BufferWriter.prototype.string = function write_string_buffer(value) {
|
|
6044
|
-
var len = util$
|
|
6045
|
+
var len = util$4.Buffer.byteLength(value);
|
|
6045
6046
|
this.uint32(len);
|
|
6046
6047
|
if (len)
|
|
6047
6048
|
this._push(writeStringBuffer, len, value);
|
|
@@ -6060,12 +6061,12 @@ BufferWriter._configure();
|
|
|
6060
6061
|
|
|
6061
6062
|
var reader = Reader$1;
|
|
6062
6063
|
|
|
6063
|
-
var util$
|
|
6064
|
+
var util$3 = requireMinimal();
|
|
6064
6065
|
|
|
6065
6066
|
var BufferReader$1; // cyclic
|
|
6066
6067
|
|
|
6067
|
-
var LongBits = util$
|
|
6068
|
-
utf8 = util$
|
|
6068
|
+
var LongBits = util$3.LongBits,
|
|
6069
|
+
utf8 = util$3.utf8;
|
|
6069
6070
|
|
|
6070
6071
|
/* istanbul ignore next */
|
|
6071
6072
|
function indexOutOfRange(reader, writeLength) {
|
|
@@ -6113,10 +6114,10 @@ var create_array = typeof Uint8Array !== "undefined"
|
|
|
6113
6114
|
};
|
|
6114
6115
|
|
|
6115
6116
|
var create = function create() {
|
|
6116
|
-
return util$
|
|
6117
|
+
return util$3.Buffer
|
|
6117
6118
|
? function create_buffer_setup(buffer) {
|
|
6118
6119
|
return (Reader$1.create = function create_buffer(buffer) {
|
|
6119
|
-
return util$
|
|
6120
|
+
return util$3.Buffer.isBuffer(buffer)
|
|
6120
6121
|
? new BufferReader$1(buffer)
|
|
6121
6122
|
/* istanbul ignore next */
|
|
6122
6123
|
: create_array(buffer);
|
|
@@ -6135,7 +6136,7 @@ var create = function create() {
|
|
|
6135
6136
|
*/
|
|
6136
6137
|
Reader$1.create = create();
|
|
6137
6138
|
|
|
6138
|
-
Reader$1.prototype._slice = util$
|
|
6139
|
+
Reader$1.prototype._slice = util$3.Array.prototype.subarray || /* istanbul ignore next */ util$3.Array.prototype.slice;
|
|
6139
6140
|
|
|
6140
6141
|
/**
|
|
6141
6142
|
* Reads a varint as an unsigned 32 bit value.
|
|
@@ -6334,7 +6335,7 @@ Reader$1.prototype.float = function read_float() {
|
|
|
6334
6335
|
if (this.pos + 4 > this.len)
|
|
6335
6336
|
throw indexOutOfRange(this, 4);
|
|
6336
6337
|
|
|
6337
|
-
var value = util$
|
|
6338
|
+
var value = util$3.float.readFloatLE(this.buf, this.pos);
|
|
6338
6339
|
this.pos += 4;
|
|
6339
6340
|
return value;
|
|
6340
6341
|
};
|
|
@@ -6350,7 +6351,7 @@ Reader$1.prototype.double = function read_double() {
|
|
|
6350
6351
|
if (this.pos + 8 > this.len)
|
|
6351
6352
|
throw indexOutOfRange(this, 4);
|
|
6352
6353
|
|
|
6353
|
-
var value = util$
|
|
6354
|
+
var value = util$3.float.readDoubleLE(this.buf, this.pos);
|
|
6354
6355
|
this.pos += 8;
|
|
6355
6356
|
return value;
|
|
6356
6357
|
};
|
|
@@ -6443,8 +6444,8 @@ Reader$1._configure = function(BufferReader_) {
|
|
|
6443
6444
|
Reader$1.create = create();
|
|
6444
6445
|
BufferReader$1._configure();
|
|
6445
6446
|
|
|
6446
|
-
var fn = util$
|
|
6447
|
-
util$
|
|
6447
|
+
var fn = util$3.Long ? "toLong" : /* istanbul ignore next */ "toNumber";
|
|
6448
|
+
util$3.merge(Reader$1.prototype, {
|
|
6448
6449
|
|
|
6449
6450
|
int64: function read_int64() {
|
|
6450
6451
|
return readLongVarint.call(this)[fn](false);
|
|
@@ -6475,7 +6476,7 @@ var reader_buffer = BufferReader;
|
|
|
6475
6476
|
var Reader = reader;
|
|
6476
6477
|
(BufferReader.prototype = Object.create(Reader.prototype)).constructor = BufferReader;
|
|
6477
6478
|
|
|
6478
|
-
var util$
|
|
6479
|
+
var util$2 = requireMinimal();
|
|
6479
6480
|
|
|
6480
6481
|
/**
|
|
6481
6482
|
* Constructs a new buffer reader instance.
|
|
@@ -6496,8 +6497,8 @@ function BufferReader(buffer) {
|
|
|
6496
6497
|
|
|
6497
6498
|
BufferReader._configure = function () {
|
|
6498
6499
|
/* istanbul ignore else */
|
|
6499
|
-
if (util$
|
|
6500
|
-
BufferReader.prototype._slice = util$
|
|
6500
|
+
if (util$2.Buffer)
|
|
6501
|
+
BufferReader.prototype._slice = util$2.Buffer.prototype.slice;
|
|
6501
6502
|
};
|
|
6502
6503
|
|
|
6503
6504
|
|
|
@@ -6524,10 +6525,10 @@ var rpc = {};
|
|
|
6524
6525
|
|
|
6525
6526
|
var service$1 = Service;
|
|
6526
6527
|
|
|
6527
|
-
var util$
|
|
6528
|
+
var util$1 = requireMinimal();
|
|
6528
6529
|
|
|
6529
6530
|
// Extends EventEmitter
|
|
6530
|
-
(Service.prototype = Object.create(util$
|
|
6531
|
+
(Service.prototype = Object.create(util$1.EventEmitter.prototype)).constructor = Service;
|
|
6531
6532
|
|
|
6532
6533
|
/**
|
|
6533
6534
|
* A service method callback as used by {@link rpc.ServiceMethod|ServiceMethod}.
|
|
@@ -6567,7 +6568,7 @@ function Service(rpcImpl, requestDelimited, responseDelimited) {
|
|
|
6567
6568
|
if (typeof rpcImpl !== "function")
|
|
6568
6569
|
throw TypeError("rpcImpl must be a function");
|
|
6569
6570
|
|
|
6570
|
-
util$
|
|
6571
|
+
util$1.EventEmitter.call(this);
|
|
6571
6572
|
|
|
6572
6573
|
/**
|
|
6573
6574
|
* RPC implementation. Becomes `null` once the service is ended.
|
|
@@ -6606,7 +6607,7 @@ Service.prototype.rpcCall = function rpcCall(method, requestCtor, responseCtor,
|
|
|
6606
6607
|
|
|
6607
6608
|
var self = this;
|
|
6608
6609
|
if (!callback)
|
|
6609
|
-
return util$
|
|
6610
|
+
return util$1.asPromise(rpcCall, self, method, requestCtor, responseCtor, request);
|
|
6610
6611
|
|
|
6611
6612
|
if (!self.rpcImpl) {
|
|
6612
6613
|
setTimeout(function() { callback(Error("already ended")); }, 0);
|
|
@@ -115179,20 +115180,25 @@ function requireBlowfish () {
|
|
|
115179
115180
|
|
|
115180
115181
|
cryptoJs.exports;
|
|
115181
115182
|
|
|
115182
|
-
|
|
115183
|
-
(function (root, factory, undef) {
|
|
115184
|
-
{
|
|
115185
|
-
// CommonJS
|
|
115186
|
-
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());
|
|
115187
|
-
}
|
|
115188
|
-
}(commonjsGlobal$1, function (CryptoJS) {
|
|
115183
|
+
var hasRequiredCryptoJs;
|
|
115189
115184
|
|
|
115190
|
-
|
|
115185
|
+
function requireCryptoJs () {
|
|
115186
|
+
if (hasRequiredCryptoJs) return cryptoJs.exports;
|
|
115187
|
+
hasRequiredCryptoJs = 1;
|
|
115188
|
+
(function (module, exports) {
|
|
115189
|
+
(function (root, factory, undef) {
|
|
115190
|
+
{
|
|
115191
|
+
// CommonJS
|
|
115192
|
+
module.exports = factory(requireCore$1(), requireX64Core(), requireLibTypedarrays(), requireEncUtf16(), requireEncBase64(), requireEncBase64url(), requireMd5(), requireSha1(), requireSha256(), requireSha224(), requireSha512(), requireSha384(), requireSha3(), requireRipemd160(), requireHmac(), requirePbkdf2(), requireEvpkdf(), requireCipherCore(), requireModeCfb(), requireModeCtr(), requireModeCtrGladman(), requireModeOfb(), requireModeEcb(), requirePadAnsix923(), requirePadIso10126(), requirePadIso97971(), requirePadZeropadding(), requirePadNopadding(), requireFormatHex(), requireAes(), requireTripledes(), requireRc4(), requireRabbit(), requireRabbitLegacy(), requireBlowfish());
|
|
115193
|
+
}
|
|
115194
|
+
}(commonjsGlobal$1, function (CryptoJS) {
|
|
115191
115195
|
|
|
115192
|
-
|
|
115193
|
-
} (cryptoJs, cryptoJs.exports));
|
|
115196
|
+
return CryptoJS;
|
|
115194
115197
|
|
|
115195
|
-
|
|
115198
|
+
}));
|
|
115199
|
+
} (cryptoJs, cryptoJs.exports));
|
|
115200
|
+
return cryptoJs.exports;
|
|
115201
|
+
}
|
|
115196
115202
|
|
|
115197
115203
|
var utility = {};
|
|
115198
115204
|
|
|
@@ -117697,826 +117703,858 @@ function requireUtility () {
|
|
|
117697
117703
|
return utility;
|
|
117698
117704
|
}
|
|
117699
117705
|
|
|
117700
|
-
|
|
117701
|
-
|
|
117702
|
-
// For convenience, let people hash a string, not just a Uint8Array
|
|
117703
|
-
function normalizeInput (input) {
|
|
117704
|
-
let ret;
|
|
117705
|
-
if (input instanceof Uint8Array) {
|
|
117706
|
-
ret = input;
|
|
117707
|
-
} else if (typeof input === 'string') {
|
|
117708
|
-
const encoder = new TextEncoder();
|
|
117709
|
-
ret = encoder.encode(input);
|
|
117710
|
-
} else {
|
|
117711
|
-
throw new Error(ERROR_MSG_INPUT)
|
|
117712
|
-
}
|
|
117713
|
-
return ret
|
|
117714
|
-
}
|
|
117715
|
-
|
|
117716
|
-
// Converts a Uint8Array to a hexadecimal string
|
|
117717
|
-
// For example, toHex([255, 0, 255]) returns "ff00ff"
|
|
117718
|
-
function toHex (bytes) {
|
|
117719
|
-
return Array.prototype.map
|
|
117720
|
-
.call(bytes, function (n) {
|
|
117721
|
-
return (n < 16 ? '0' : '') + n.toString(16)
|
|
117722
|
-
})
|
|
117723
|
-
.join('')
|
|
117724
|
-
}
|
|
117725
|
-
|
|
117726
|
-
// Converts any value in [0...2^32-1] to an 8-character hex string
|
|
117727
|
-
function uint32ToHex (val) {
|
|
117728
|
-
return (0x100000000 + val).toString(16).substring(1)
|
|
117729
|
-
}
|
|
117730
|
-
|
|
117731
|
-
// For debugging: prints out hash state in the same format as the RFC
|
|
117732
|
-
// sample computation exactly, so that you can diff
|
|
117733
|
-
function debugPrint (label, arr, size) {
|
|
117734
|
-
let msg = '\n' + label + ' = ';
|
|
117735
|
-
for (let i = 0; i < arr.length; i += 2) {
|
|
117736
|
-
if (size === 32) {
|
|
117737
|
-
msg += uint32ToHex(arr[i]).toUpperCase();
|
|
117738
|
-
msg += ' ';
|
|
117739
|
-
msg += uint32ToHex(arr[i + 1]).toUpperCase();
|
|
117740
|
-
} else if (size === 64) {
|
|
117741
|
-
msg += uint32ToHex(arr[i + 1]).toUpperCase();
|
|
117742
|
-
msg += uint32ToHex(arr[i]).toUpperCase();
|
|
117743
|
-
} else throw new Error('Invalid size ' + size)
|
|
117744
|
-
if (i % 6 === 4) {
|
|
117745
|
-
msg += '\n' + new Array(label.length + 4).join(' ');
|
|
117746
|
-
} else if (i < arr.length - 2) {
|
|
117747
|
-
msg += ' ';
|
|
117748
|
-
}
|
|
117749
|
-
}
|
|
117750
|
-
console.log(msg);
|
|
117751
|
-
}
|
|
117752
|
-
|
|
117753
|
-
// For performance testing: generates N bytes of input, hashes M times
|
|
117754
|
-
// Measures and prints MB/second hash performance each time
|
|
117755
|
-
function testSpeed (hashFn, N, M) {
|
|
117756
|
-
let startMs = new Date().getTime();
|
|
117757
|
-
|
|
117758
|
-
const input = new Uint8Array(N);
|
|
117759
|
-
for (let i = 0; i < N; i++) {
|
|
117760
|
-
input[i] = i % 256;
|
|
117761
|
-
}
|
|
117762
|
-
const genMs = new Date().getTime();
|
|
117763
|
-
console.log('Generated random input in ' + (genMs - startMs) + 'ms');
|
|
117764
|
-
startMs = genMs;
|
|
117765
|
-
|
|
117766
|
-
for (let i = 0; i < M; i++) {
|
|
117767
|
-
const hashHex = hashFn(input);
|
|
117768
|
-
const hashMs = new Date().getTime();
|
|
117769
|
-
const ms = hashMs - startMs;
|
|
117770
|
-
startMs = hashMs;
|
|
117771
|
-
console.log('Hashed in ' + ms + 'ms: ' + hashHex.substring(0, 20) + '...');
|
|
117772
|
-
console.log(
|
|
117773
|
-
Math.round((N / (1 << 20) / (ms / 1000)) * 100) / 100 + ' MB PER SECOND'
|
|
117774
|
-
);
|
|
117775
|
-
}
|
|
117776
|
-
}
|
|
117777
|
-
|
|
117778
|
-
var util$2 = {
|
|
117779
|
-
normalizeInput: normalizeInput,
|
|
117780
|
-
toHex: toHex,
|
|
117781
|
-
debugPrint: debugPrint,
|
|
117782
|
-
testSpeed: testSpeed
|
|
117783
|
-
};
|
|
117706
|
+
var util;
|
|
117707
|
+
var hasRequiredUtil;
|
|
117784
117708
|
|
|
117785
|
-
|
|
117786
|
-
|
|
117787
|
-
|
|
117788
|
-
|
|
117789
|
-
const util$1 = util$2;
|
|
117790
|
-
|
|
117791
|
-
// 64-bit unsigned addition
|
|
117792
|
-
// Sets v[a,a+1] += v[b,b+1]
|
|
117793
|
-
// v should be a Uint32Array
|
|
117794
|
-
function ADD64AA (v, a, b) {
|
|
117795
|
-
const o0 = v[a] + v[b];
|
|
117796
|
-
let o1 = v[a + 1] + v[b + 1];
|
|
117797
|
-
if (o0 >= 0x100000000) {
|
|
117798
|
-
o1++;
|
|
117799
|
-
}
|
|
117800
|
-
v[a] = o0;
|
|
117801
|
-
v[a + 1] = o1;
|
|
117802
|
-
}
|
|
117803
|
-
|
|
117804
|
-
// 64-bit unsigned addition
|
|
117805
|
-
// Sets v[a,a+1] += b
|
|
117806
|
-
// b0 is the low 32 bits of b, b1 represents the high 32 bits
|
|
117807
|
-
function ADD64AC (v, a, b0, b1) {
|
|
117808
|
-
let o0 = v[a] + b0;
|
|
117809
|
-
if (b0 < 0) {
|
|
117810
|
-
o0 += 0x100000000;
|
|
117811
|
-
}
|
|
117812
|
-
let o1 = v[a + 1] + b1;
|
|
117813
|
-
if (o0 >= 0x100000000) {
|
|
117814
|
-
o1++;
|
|
117815
|
-
}
|
|
117816
|
-
v[a] = o0;
|
|
117817
|
-
v[a + 1] = o1;
|
|
117818
|
-
}
|
|
117819
|
-
|
|
117820
|
-
// Little-endian byte access
|
|
117821
|
-
function B2B_GET32 (arr, i) {
|
|
117822
|
-
return arr[i] ^ (arr[i + 1] << 8) ^ (arr[i + 2] << 16) ^ (arr[i + 3] << 24)
|
|
117823
|
-
}
|
|
117824
|
-
|
|
117825
|
-
// G Mixing function
|
|
117826
|
-
// The ROTRs are inlined for speed
|
|
117827
|
-
function B2B_G (a, b, c, d, ix, iy) {
|
|
117828
|
-
const x0 = m$1[ix];
|
|
117829
|
-
const x1 = m$1[ix + 1];
|
|
117830
|
-
const y0 = m$1[iy];
|
|
117831
|
-
const y1 = m$1[iy + 1];
|
|
117832
|
-
|
|
117833
|
-
ADD64AA(v$1, a, b); // v[a,a+1] += v[b,b+1] ... in JS we must store a uint64 as two uint32s
|
|
117834
|
-
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
|
|
117835
|
-
|
|
117836
|
-
// v[d,d+1] = (v[d,d+1] xor v[a,a+1]) rotated to the right by 32 bits
|
|
117837
|
-
let xor0 = v$1[d] ^ v$1[a];
|
|
117838
|
-
let xor1 = v$1[d + 1] ^ v$1[a + 1];
|
|
117839
|
-
v$1[d] = xor1;
|
|
117840
|
-
v$1[d + 1] = xor0;
|
|
117841
|
-
|
|
117842
|
-
ADD64AA(v$1, c, d);
|
|
117843
|
-
|
|
117844
|
-
// v[b,b+1] = (v[b,b+1] xor v[c,c+1]) rotated right by 24 bits
|
|
117845
|
-
xor0 = v$1[b] ^ v$1[c];
|
|
117846
|
-
xor1 = v$1[b + 1] ^ v$1[c + 1];
|
|
117847
|
-
v$1[b] = (xor0 >>> 24) ^ (xor1 << 8);
|
|
117848
|
-
v$1[b + 1] = (xor1 >>> 24) ^ (xor0 << 8);
|
|
117849
|
-
|
|
117850
|
-
ADD64AA(v$1, a, b);
|
|
117851
|
-
ADD64AC(v$1, a, y0, y1);
|
|
117852
|
-
|
|
117853
|
-
// v[d,d+1] = (v[d,d+1] xor v[a,a+1]) rotated right by 16 bits
|
|
117854
|
-
xor0 = v$1[d] ^ v$1[a];
|
|
117855
|
-
xor1 = v$1[d + 1] ^ v$1[a + 1];
|
|
117856
|
-
v$1[d] = (xor0 >>> 16) ^ (xor1 << 16);
|
|
117857
|
-
v$1[d + 1] = (xor1 >>> 16) ^ (xor0 << 16);
|
|
117858
|
-
|
|
117859
|
-
ADD64AA(v$1, c, d);
|
|
117860
|
-
|
|
117861
|
-
// v[b,b+1] = (v[b,b+1] xor v[c,c+1]) rotated right by 63 bits
|
|
117862
|
-
xor0 = v$1[b] ^ v$1[c];
|
|
117863
|
-
xor1 = v$1[b + 1] ^ v$1[c + 1];
|
|
117864
|
-
v$1[b] = (xor1 >>> 31) ^ (xor0 << 1);
|
|
117865
|
-
v$1[b + 1] = (xor0 >>> 31) ^ (xor1 << 1);
|
|
117866
|
-
}
|
|
117867
|
-
|
|
117868
|
-
// Initialization Vector
|
|
117869
|
-
const BLAKE2B_IV32 = new Uint32Array([
|
|
117870
|
-
0xf3bcc908, 0x6a09e667, 0x84caa73b, 0xbb67ae85, 0xfe94f82b, 0x3c6ef372,
|
|
117871
|
-
0x5f1d36f1, 0xa54ff53a, 0xade682d1, 0x510e527f, 0x2b3e6c1f, 0x9b05688c,
|
|
117872
|
-
0xfb41bd6b, 0x1f83d9ab, 0x137e2179, 0x5be0cd19
|
|
117873
|
-
]);
|
|
117709
|
+
function requireUtil () {
|
|
117710
|
+
if (hasRequiredUtil) return util;
|
|
117711
|
+
hasRequiredUtil = 1;
|
|
117712
|
+
const ERROR_MSG_INPUT = 'Input must be an string, Buffer or Uint8Array';
|
|
117874
117713
|
|
|
117875
|
-
|
|
117876
|
-
|
|
117877
|
-
|
|
117878
|
-
|
|
117879
|
-
|
|
117880
|
-
|
|
117881
|
-
|
|
117882
|
-
|
|
117883
|
-
|
|
117884
|
-
|
|
117885
|
-
|
|
117714
|
+
// For convenience, let people hash a string, not just a Uint8Array
|
|
117715
|
+
function normalizeInput (input) {
|
|
117716
|
+
let ret;
|
|
117717
|
+
if (input instanceof Uint8Array) {
|
|
117718
|
+
ret = input;
|
|
117719
|
+
} else if (typeof input === 'string') {
|
|
117720
|
+
const encoder = new TextEncoder();
|
|
117721
|
+
ret = encoder.encode(input);
|
|
117722
|
+
} else {
|
|
117723
|
+
throw new Error(ERROR_MSG_INPUT)
|
|
117724
|
+
}
|
|
117725
|
+
return ret
|
|
117726
|
+
}
|
|
117727
|
+
|
|
117728
|
+
// Converts a Uint8Array to a hexadecimal string
|
|
117729
|
+
// For example, toHex([255, 0, 255]) returns "ff00ff"
|
|
117730
|
+
function toHex (bytes) {
|
|
117731
|
+
return Array.prototype.map
|
|
117732
|
+
.call(bytes, function (n) {
|
|
117733
|
+
return (n < 16 ? '0' : '') + n.toString(16)
|
|
117734
|
+
})
|
|
117735
|
+
.join('')
|
|
117736
|
+
}
|
|
117737
|
+
|
|
117738
|
+
// Converts any value in [0...2^32-1] to an 8-character hex string
|
|
117739
|
+
function uint32ToHex (val) {
|
|
117740
|
+
return (0x100000000 + val).toString(16).substring(1)
|
|
117741
|
+
}
|
|
117742
|
+
|
|
117743
|
+
// For debugging: prints out hash state in the same format as the RFC
|
|
117744
|
+
// sample computation exactly, so that you can diff
|
|
117745
|
+
function debugPrint (label, arr, size) {
|
|
117746
|
+
let msg = '\n' + label + ' = ';
|
|
117747
|
+
for (let i = 0; i < arr.length; i += 2) {
|
|
117748
|
+
if (size === 32) {
|
|
117749
|
+
msg += uint32ToHex(arr[i]).toUpperCase();
|
|
117750
|
+
msg += ' ';
|
|
117751
|
+
msg += uint32ToHex(arr[i + 1]).toUpperCase();
|
|
117752
|
+
} else if (size === 64) {
|
|
117753
|
+
msg += uint32ToHex(arr[i + 1]).toUpperCase();
|
|
117754
|
+
msg += uint32ToHex(arr[i]).toUpperCase();
|
|
117755
|
+
} else throw new Error('Invalid size ' + size)
|
|
117756
|
+
if (i % 6 === 4) {
|
|
117757
|
+
msg += '\n' + new Array(label.length + 4).join(' ');
|
|
117758
|
+
} else if (i < arr.length - 2) {
|
|
117759
|
+
msg += ' ';
|
|
117760
|
+
}
|
|
117761
|
+
}
|
|
117762
|
+
console.log(msg);
|
|
117763
|
+
}
|
|
117886
117764
|
|
|
117887
|
-
//
|
|
117888
|
-
//
|
|
117889
|
-
|
|
117890
|
-
|
|
117891
|
-
SIGMA8.map(function (x) {
|
|
117892
|
-
return x * 2
|
|
117893
|
-
})
|
|
117894
|
-
);
|
|
117765
|
+
// For performance testing: generates N bytes of input, hashes M times
|
|
117766
|
+
// Measures and prints MB/second hash performance each time
|
|
117767
|
+
function testSpeed (hashFn, N, M) {
|
|
117768
|
+
let startMs = new Date().getTime();
|
|
117895
117769
|
|
|
117896
|
-
|
|
117897
|
-
|
|
117898
|
-
|
|
117899
|
-
|
|
117900
|
-
|
|
117901
|
-
|
|
117902
|
-
|
|
117903
|
-
|
|
117904
|
-
|
|
117905
|
-
|
|
117906
|
-
|
|
117907
|
-
|
|
117908
|
-
|
|
117909
|
-
|
|
117910
|
-
|
|
117911
|
-
|
|
117912
|
-
|
|
117913
|
-
|
|
117914
|
-
|
|
117915
|
-
if (last) {
|
|
117916
|
-
v$1[28] = ~v$1[28];
|
|
117917
|
-
v$1[29] = ~v$1[29];
|
|
117918
|
-
}
|
|
117919
|
-
|
|
117920
|
-
// get little-endian words
|
|
117921
|
-
for (i = 0; i < 32; i++) {
|
|
117922
|
-
m$1[i] = B2B_GET32(ctx.b, 4 * i);
|
|
117923
|
-
}
|
|
117924
|
-
|
|
117925
|
-
// twelve rounds of mixing
|
|
117926
|
-
// uncomment the DebugPrint calls to log the computation
|
|
117927
|
-
// and match the RFC sample documentation
|
|
117928
|
-
// util.debugPrint(' m[16]', m, 64)
|
|
117929
|
-
for (i = 0; i < 12; i++) {
|
|
117930
|
-
// util.debugPrint(' (i=' + (i < 10 ? ' ' : '') + i + ') v[16]', v, 64)
|
|
117931
|
-
B2B_G(0, 8, 16, 24, SIGMA82[i * 16 + 0], SIGMA82[i * 16 + 1]);
|
|
117932
|
-
B2B_G(2, 10, 18, 26, SIGMA82[i * 16 + 2], SIGMA82[i * 16 + 3]);
|
|
117933
|
-
B2B_G(4, 12, 20, 28, SIGMA82[i * 16 + 4], SIGMA82[i * 16 + 5]);
|
|
117934
|
-
B2B_G(6, 14, 22, 30, SIGMA82[i * 16 + 6], SIGMA82[i * 16 + 7]);
|
|
117935
|
-
B2B_G(0, 10, 20, 30, SIGMA82[i * 16 + 8], SIGMA82[i * 16 + 9]);
|
|
117936
|
-
B2B_G(2, 12, 22, 24, SIGMA82[i * 16 + 10], SIGMA82[i * 16 + 11]);
|
|
117937
|
-
B2B_G(4, 14, 16, 26, SIGMA82[i * 16 + 12], SIGMA82[i * 16 + 13]);
|
|
117938
|
-
B2B_G(6, 8, 18, 28, SIGMA82[i * 16 + 14], SIGMA82[i * 16 + 15]);
|
|
117939
|
-
}
|
|
117940
|
-
// util.debugPrint(' (i=12) v[16]', v, 64)
|
|
117941
|
-
|
|
117942
|
-
for (i = 0; i < 16; i++) {
|
|
117943
|
-
ctx.h[i] = ctx.h[i] ^ v$1[i] ^ v$1[i + 16];
|
|
117944
|
-
}
|
|
117945
|
-
// util.debugPrint('h[8]', ctx.h, 64)
|
|
117946
|
-
}
|
|
117947
|
-
|
|
117948
|
-
// reusable parameterBlock
|
|
117949
|
-
const parameterBlock = new Uint8Array([
|
|
117950
|
-
0,
|
|
117951
|
-
0,
|
|
117952
|
-
0,
|
|
117953
|
-
0, // 0: outlen, keylen, fanout, depth
|
|
117954
|
-
0,
|
|
117955
|
-
0,
|
|
117956
|
-
0,
|
|
117957
|
-
0, // 4: leaf length, sequential mode
|
|
117958
|
-
0,
|
|
117959
|
-
0,
|
|
117960
|
-
0,
|
|
117961
|
-
0, // 8: node offset
|
|
117962
|
-
0,
|
|
117963
|
-
0,
|
|
117964
|
-
0,
|
|
117965
|
-
0, // 12: node offset
|
|
117966
|
-
0,
|
|
117967
|
-
0,
|
|
117968
|
-
0,
|
|
117969
|
-
0, // 16: node depth, inner length, rfu
|
|
117970
|
-
0,
|
|
117971
|
-
0,
|
|
117972
|
-
0,
|
|
117973
|
-
0, // 20: rfu
|
|
117974
|
-
0,
|
|
117975
|
-
0,
|
|
117976
|
-
0,
|
|
117977
|
-
0, // 24: rfu
|
|
117978
|
-
0,
|
|
117979
|
-
0,
|
|
117980
|
-
0,
|
|
117981
|
-
0, // 28: rfu
|
|
117982
|
-
0,
|
|
117983
|
-
0,
|
|
117984
|
-
0,
|
|
117985
|
-
0, // 32: salt
|
|
117986
|
-
0,
|
|
117987
|
-
0,
|
|
117988
|
-
0,
|
|
117989
|
-
0, // 36: salt
|
|
117990
|
-
0,
|
|
117991
|
-
0,
|
|
117992
|
-
0,
|
|
117993
|
-
0, // 40: salt
|
|
117994
|
-
0,
|
|
117995
|
-
0,
|
|
117996
|
-
0,
|
|
117997
|
-
0, // 44: salt
|
|
117998
|
-
0,
|
|
117999
|
-
0,
|
|
118000
|
-
0,
|
|
118001
|
-
0, // 48: personal
|
|
118002
|
-
0,
|
|
118003
|
-
0,
|
|
118004
|
-
0,
|
|
118005
|
-
0, // 52: personal
|
|
118006
|
-
0,
|
|
118007
|
-
0,
|
|
118008
|
-
0,
|
|
118009
|
-
0, // 56: personal
|
|
118010
|
-
0,
|
|
118011
|
-
0,
|
|
118012
|
-
0,
|
|
118013
|
-
0 // 60: personal
|
|
118014
|
-
]);
|
|
117770
|
+
const input = new Uint8Array(N);
|
|
117771
|
+
for (let i = 0; i < N; i++) {
|
|
117772
|
+
input[i] = i % 256;
|
|
117773
|
+
}
|
|
117774
|
+
const genMs = new Date().getTime();
|
|
117775
|
+
console.log('Generated random input in ' + (genMs - startMs) + 'ms');
|
|
117776
|
+
startMs = genMs;
|
|
117777
|
+
|
|
117778
|
+
for (let i = 0; i < M; i++) {
|
|
117779
|
+
const hashHex = hashFn(input);
|
|
117780
|
+
const hashMs = new Date().getTime();
|
|
117781
|
+
const ms = hashMs - startMs;
|
|
117782
|
+
startMs = hashMs;
|
|
117783
|
+
console.log('Hashed in ' + ms + 'ms: ' + hashHex.substring(0, 20) + '...');
|
|
117784
|
+
console.log(
|
|
117785
|
+
Math.round((N / (1 << 20) / (ms / 1000)) * 100) / 100 + ' MB PER SECOND'
|
|
117786
|
+
);
|
|
117787
|
+
}
|
|
117788
|
+
}
|
|
118015
117789
|
|
|
118016
|
-
|
|
118017
|
-
|
|
118018
|
-
|
|
118019
|
-
|
|
118020
|
-
|
|
118021
|
-
|
|
118022
|
-
|
|
118023
|
-
|
|
118024
|
-
}
|
|
118025
|
-
if (key && key.length > 64) {
|
|
118026
|
-
throw new Error('Illegal key, expected Uint8Array with 0 < length <= 64')
|
|
118027
|
-
}
|
|
118028
|
-
if (salt && salt.length !== 16) {
|
|
118029
|
-
throw new Error('Illegal salt, expected Uint8Array with length is 16')
|
|
118030
|
-
}
|
|
118031
|
-
if (personal && personal.length !== 16) {
|
|
118032
|
-
throw new Error('Illegal personal, expected Uint8Array with length is 16')
|
|
118033
|
-
}
|
|
118034
|
-
|
|
118035
|
-
// state, 'param block'
|
|
118036
|
-
const ctx = {
|
|
118037
|
-
b: new Uint8Array(128),
|
|
118038
|
-
h: new Uint32Array(16),
|
|
118039
|
-
t: 0, // input count
|
|
118040
|
-
c: 0, // pointer within buffer
|
|
118041
|
-
outlen: outlen // output length in bytes
|
|
118042
|
-
};
|
|
118043
|
-
|
|
118044
|
-
// initialize parameterBlock before usage
|
|
118045
|
-
parameterBlock.fill(0);
|
|
118046
|
-
parameterBlock[0] = outlen;
|
|
118047
|
-
if (key) parameterBlock[1] = key.length;
|
|
118048
|
-
parameterBlock[2] = 1; // fanout
|
|
118049
|
-
parameterBlock[3] = 1; // depth
|
|
118050
|
-
if (salt) parameterBlock.set(salt, 32);
|
|
118051
|
-
if (personal) parameterBlock.set(personal, 48);
|
|
118052
|
-
|
|
118053
|
-
// initialize hash state
|
|
118054
|
-
for (let i = 0; i < 16; i++) {
|
|
118055
|
-
ctx.h[i] = BLAKE2B_IV32[i] ^ B2B_GET32(parameterBlock, i * 4);
|
|
118056
|
-
}
|
|
118057
|
-
|
|
118058
|
-
// key the hash, if applicable
|
|
118059
|
-
if (key) {
|
|
118060
|
-
blake2bUpdate(ctx, key);
|
|
118061
|
-
// at the end
|
|
118062
|
-
ctx.c = 128;
|
|
118063
|
-
}
|
|
118064
|
-
|
|
118065
|
-
return ctx
|
|
118066
|
-
}
|
|
118067
|
-
|
|
118068
|
-
// Updates a BLAKE2b streaming hash
|
|
118069
|
-
// Requires hash context and Uint8Array (byte array)
|
|
118070
|
-
function blake2bUpdate (ctx, input) {
|
|
118071
|
-
for (let i = 0; i < input.length; i++) {
|
|
118072
|
-
if (ctx.c === 128) {
|
|
118073
|
-
// buffer full ?
|
|
118074
|
-
ctx.t += ctx.c; // add counters
|
|
118075
|
-
blake2bCompress(ctx, false); // compress (not last)
|
|
118076
|
-
ctx.c = 0; // counter to zero
|
|
118077
|
-
}
|
|
118078
|
-
ctx.b[ctx.c++] = input[i];
|
|
118079
|
-
}
|
|
118080
|
-
}
|
|
118081
|
-
|
|
118082
|
-
// Completes a BLAKE2b streaming hash
|
|
118083
|
-
// Returns a Uint8Array containing the message digest
|
|
118084
|
-
function blake2bFinal (ctx) {
|
|
118085
|
-
ctx.t += ctx.c; // mark last block offset
|
|
118086
|
-
|
|
118087
|
-
while (ctx.c < 128) {
|
|
118088
|
-
// fill up with zeros
|
|
118089
|
-
ctx.b[ctx.c++] = 0;
|
|
118090
|
-
}
|
|
118091
|
-
blake2bCompress(ctx, true); // final block flag = 1
|
|
118092
|
-
|
|
118093
|
-
// little endian convert and store
|
|
118094
|
-
const out = new Uint8Array(ctx.outlen);
|
|
118095
|
-
for (let i = 0; i < ctx.outlen; i++) {
|
|
118096
|
-
out[i] = ctx.h[i >> 2] >> (8 * (i & 3));
|
|
118097
|
-
}
|
|
118098
|
-
return out
|
|
118099
|
-
}
|
|
118100
|
-
|
|
118101
|
-
// Computes the BLAKE2B hash of a string or byte array, and returns a Uint8Array
|
|
118102
|
-
//
|
|
118103
|
-
// Returns a n-byte Uint8Array
|
|
118104
|
-
//
|
|
118105
|
-
// Parameters:
|
|
118106
|
-
// - input - the input bytes, as a string, Buffer or Uint8Array
|
|
118107
|
-
// - key - optional key Uint8Array, up to 64 bytes
|
|
118108
|
-
// - outlen - optional output length in bytes, default 64
|
|
118109
|
-
// - salt - optional salt bytes, string, Buffer or Uint8Array
|
|
118110
|
-
// - personal - optional personal bytes, string, Buffer or Uint8Array
|
|
118111
|
-
function blake2b (input, key, outlen, salt, personal) {
|
|
118112
|
-
// preprocess inputs
|
|
118113
|
-
outlen = outlen || 64;
|
|
118114
|
-
input = util$1.normalizeInput(input);
|
|
118115
|
-
if (salt) {
|
|
118116
|
-
salt = util$1.normalizeInput(salt);
|
|
118117
|
-
}
|
|
118118
|
-
if (personal) {
|
|
118119
|
-
personal = util$1.normalizeInput(personal);
|
|
118120
|
-
}
|
|
118121
|
-
|
|
118122
|
-
// do the math
|
|
118123
|
-
const ctx = blake2bInit(outlen, key, salt, personal);
|
|
118124
|
-
blake2bUpdate(ctx, input);
|
|
118125
|
-
return blake2bFinal(ctx)
|
|
118126
|
-
}
|
|
118127
|
-
|
|
118128
|
-
// Computes the BLAKE2B hash of a string or byte array
|
|
118129
|
-
//
|
|
118130
|
-
// Returns an n-byte hash in hex, all lowercase
|
|
118131
|
-
//
|
|
118132
|
-
// Parameters:
|
|
118133
|
-
// - input - the input bytes, as a string, Buffer, or Uint8Array
|
|
118134
|
-
// - key - optional key Uint8Array, up to 64 bytes
|
|
118135
|
-
// - outlen - optional output length in bytes, default 64
|
|
118136
|
-
// - salt - optional salt bytes, string, Buffer or Uint8Array
|
|
118137
|
-
// - personal - optional personal bytes, string, Buffer or Uint8Array
|
|
118138
|
-
function blake2bHex (input, key, outlen, salt, personal) {
|
|
118139
|
-
const output = blake2b(input, key, outlen, salt, personal);
|
|
118140
|
-
return util$1.toHex(output)
|
|
118141
|
-
}
|
|
118142
|
-
|
|
118143
|
-
var blake2b_1 = {
|
|
118144
|
-
blake2b: blake2b,
|
|
118145
|
-
blake2bHex: blake2bHex,
|
|
118146
|
-
blake2bInit: blake2bInit,
|
|
118147
|
-
blake2bUpdate: blake2bUpdate,
|
|
118148
|
-
blake2bFinal: blake2bFinal
|
|
118149
|
-
};
|
|
117790
|
+
util = {
|
|
117791
|
+
normalizeInput: normalizeInput,
|
|
117792
|
+
toHex: toHex,
|
|
117793
|
+
debugPrint: debugPrint,
|
|
117794
|
+
testSpeed: testSpeed
|
|
117795
|
+
};
|
|
117796
|
+
return util;
|
|
117797
|
+
}
|
|
118150
117798
|
|
|
118151
|
-
|
|
118152
|
-
|
|
118153
|
-
// Ported to Javascript by DC - https://github.com/dcposch
|
|
118154
|
-
|
|
118155
|
-
const util = util$2;
|
|
118156
|
-
|
|
118157
|
-
// Little-endian byte access.
|
|
118158
|
-
// Expects a Uint8Array and an index
|
|
118159
|
-
// Returns the little-endian uint32 at v[i..i+3]
|
|
118160
|
-
function B2S_GET32 (v, i) {
|
|
118161
|
-
return v[i] ^ (v[i + 1] << 8) ^ (v[i + 2] << 16) ^ (v[i + 3] << 24)
|
|
118162
|
-
}
|
|
118163
|
-
|
|
118164
|
-
// Mixing function G.
|
|
118165
|
-
function B2S_G (a, b, c, d, x, y) {
|
|
118166
|
-
v[a] = v[a] + v[b] + x;
|
|
118167
|
-
v[d] = ROTR32(v[d] ^ v[a], 16);
|
|
118168
|
-
v[c] = v[c] + v[d];
|
|
118169
|
-
v[b] = ROTR32(v[b] ^ v[c], 12);
|
|
118170
|
-
v[a] = v[a] + v[b] + y;
|
|
118171
|
-
v[d] = ROTR32(v[d] ^ v[a], 8);
|
|
118172
|
-
v[c] = v[c] + v[d];
|
|
118173
|
-
v[b] = ROTR32(v[b] ^ v[c], 7);
|
|
118174
|
-
}
|
|
118175
|
-
|
|
118176
|
-
// 32-bit right rotation
|
|
118177
|
-
// x should be a uint32
|
|
118178
|
-
// y must be between 1 and 31, inclusive
|
|
118179
|
-
function ROTR32 (x, y) {
|
|
118180
|
-
return (x >>> y) ^ (x << (32 - y))
|
|
118181
|
-
}
|
|
118182
|
-
|
|
118183
|
-
// Initialization Vector.
|
|
118184
|
-
const BLAKE2S_IV = new Uint32Array([
|
|
118185
|
-
0x6a09e667,
|
|
118186
|
-
0xbb67ae85,
|
|
118187
|
-
0x3c6ef372,
|
|
118188
|
-
0xa54ff53a,
|
|
118189
|
-
0x510e527f,
|
|
118190
|
-
0x9b05688c,
|
|
118191
|
-
0x1f83d9ab,
|
|
118192
|
-
0x5be0cd19
|
|
118193
|
-
]);
|
|
117799
|
+
var blake2b_1;
|
|
117800
|
+
var hasRequiredBlake2b;
|
|
118194
117801
|
|
|
118195
|
-
|
|
118196
|
-
|
|
118197
|
-
|
|
118198
|
-
|
|
118199
|
-
|
|
118200
|
-
|
|
118201
|
-
5,
|
|
118202
|
-
6,
|
|
118203
|
-
7,
|
|
118204
|
-
8,
|
|
118205
|
-
9,
|
|
118206
|
-
10,
|
|
118207
|
-
11,
|
|
118208
|
-
12,
|
|
118209
|
-
13,
|
|
118210
|
-
14,
|
|
118211
|
-
15,
|
|
118212
|
-
14,
|
|
118213
|
-
10,
|
|
118214
|
-
4,
|
|
118215
|
-
8,
|
|
118216
|
-
9,
|
|
118217
|
-
15,
|
|
118218
|
-
13,
|
|
118219
|
-
6,
|
|
118220
|
-
1,
|
|
118221
|
-
12,
|
|
118222
|
-
0,
|
|
118223
|
-
2,
|
|
118224
|
-
11,
|
|
118225
|
-
7,
|
|
118226
|
-
5,
|
|
118227
|
-
3,
|
|
118228
|
-
11,
|
|
118229
|
-
8,
|
|
118230
|
-
12,
|
|
118231
|
-
0,
|
|
118232
|
-
5,
|
|
118233
|
-
2,
|
|
118234
|
-
15,
|
|
118235
|
-
13,
|
|
118236
|
-
10,
|
|
118237
|
-
14,
|
|
118238
|
-
3,
|
|
118239
|
-
6,
|
|
118240
|
-
7,
|
|
118241
|
-
1,
|
|
118242
|
-
9,
|
|
118243
|
-
4,
|
|
118244
|
-
7,
|
|
118245
|
-
9,
|
|
118246
|
-
3,
|
|
118247
|
-
1,
|
|
118248
|
-
13,
|
|
118249
|
-
12,
|
|
118250
|
-
11,
|
|
118251
|
-
14,
|
|
118252
|
-
2,
|
|
118253
|
-
6,
|
|
118254
|
-
5,
|
|
118255
|
-
10,
|
|
118256
|
-
4,
|
|
118257
|
-
0,
|
|
118258
|
-
15,
|
|
118259
|
-
8,
|
|
118260
|
-
9,
|
|
118261
|
-
0,
|
|
118262
|
-
5,
|
|
118263
|
-
7,
|
|
118264
|
-
2,
|
|
118265
|
-
4,
|
|
118266
|
-
10,
|
|
118267
|
-
15,
|
|
118268
|
-
14,
|
|
118269
|
-
1,
|
|
118270
|
-
11,
|
|
118271
|
-
12,
|
|
118272
|
-
6,
|
|
118273
|
-
8,
|
|
118274
|
-
3,
|
|
118275
|
-
13,
|
|
118276
|
-
2,
|
|
118277
|
-
12,
|
|
118278
|
-
6,
|
|
118279
|
-
10,
|
|
118280
|
-
0,
|
|
118281
|
-
11,
|
|
118282
|
-
8,
|
|
118283
|
-
3,
|
|
118284
|
-
4,
|
|
118285
|
-
13,
|
|
118286
|
-
7,
|
|
118287
|
-
5,
|
|
118288
|
-
15,
|
|
118289
|
-
14,
|
|
118290
|
-
1,
|
|
118291
|
-
9,
|
|
118292
|
-
12,
|
|
118293
|
-
5,
|
|
118294
|
-
1,
|
|
118295
|
-
15,
|
|
118296
|
-
14,
|
|
118297
|
-
13,
|
|
118298
|
-
4,
|
|
118299
|
-
10,
|
|
118300
|
-
0,
|
|
118301
|
-
7,
|
|
118302
|
-
6,
|
|
118303
|
-
3,
|
|
118304
|
-
9,
|
|
118305
|
-
2,
|
|
118306
|
-
8,
|
|
118307
|
-
11,
|
|
118308
|
-
13,
|
|
118309
|
-
11,
|
|
118310
|
-
7,
|
|
118311
|
-
14,
|
|
118312
|
-
12,
|
|
118313
|
-
1,
|
|
118314
|
-
3,
|
|
118315
|
-
9,
|
|
118316
|
-
5,
|
|
118317
|
-
0,
|
|
118318
|
-
15,
|
|
118319
|
-
4,
|
|
118320
|
-
8,
|
|
118321
|
-
6,
|
|
118322
|
-
2,
|
|
118323
|
-
10,
|
|
118324
|
-
6,
|
|
118325
|
-
15,
|
|
118326
|
-
14,
|
|
118327
|
-
9,
|
|
118328
|
-
11,
|
|
118329
|
-
3,
|
|
118330
|
-
0,
|
|
118331
|
-
8,
|
|
118332
|
-
12,
|
|
118333
|
-
2,
|
|
118334
|
-
13,
|
|
118335
|
-
7,
|
|
118336
|
-
1,
|
|
118337
|
-
4,
|
|
118338
|
-
10,
|
|
118339
|
-
5,
|
|
118340
|
-
10,
|
|
118341
|
-
2,
|
|
118342
|
-
8,
|
|
118343
|
-
4,
|
|
118344
|
-
7,
|
|
118345
|
-
6,
|
|
118346
|
-
1,
|
|
118347
|
-
5,
|
|
118348
|
-
15,
|
|
118349
|
-
11,
|
|
118350
|
-
9,
|
|
118351
|
-
14,
|
|
118352
|
-
3,
|
|
118353
|
-
12,
|
|
118354
|
-
13,
|
|
118355
|
-
0
|
|
118356
|
-
]);
|
|
117802
|
+
function requireBlake2b () {
|
|
117803
|
+
if (hasRequiredBlake2b) return blake2b_1;
|
|
117804
|
+
hasRequiredBlake2b = 1;
|
|
117805
|
+
// Blake2B in pure Javascript
|
|
117806
|
+
// Adapted from the reference implementation in RFC7693
|
|
117807
|
+
// Ported to Javascript by DC - https://github.com/dcposch
|
|
118357
117808
|
|
|
118358
|
-
|
|
118359
|
-
const v = new Uint32Array(16);
|
|
118360
|
-
const m = new Uint32Array(16);
|
|
118361
|
-
function blake2sCompress (ctx, last) {
|
|
118362
|
-
let i = 0;
|
|
118363
|
-
for (i = 0; i < 8; i++) {
|
|
118364
|
-
// init work variables
|
|
118365
|
-
v[i] = ctx.h[i];
|
|
118366
|
-
v[i + 8] = BLAKE2S_IV[i];
|
|
118367
|
-
}
|
|
118368
|
-
|
|
118369
|
-
v[12] ^= ctx.t; // low 32 bits of offset
|
|
118370
|
-
v[13] ^= ctx.t / 0x100000000; // high 32 bits
|
|
118371
|
-
if (last) {
|
|
118372
|
-
// last block flag set ?
|
|
118373
|
-
v[14] = ~v[14];
|
|
118374
|
-
}
|
|
118375
|
-
|
|
118376
|
-
for (i = 0; i < 16; i++) {
|
|
118377
|
-
// get little-endian words
|
|
118378
|
-
m[i] = B2S_GET32(ctx.b, 4 * i);
|
|
118379
|
-
}
|
|
118380
|
-
|
|
118381
|
-
// ten rounds of mixing
|
|
118382
|
-
// uncomment the DebugPrint calls to log the computation
|
|
118383
|
-
// and match the RFC sample documentation
|
|
118384
|
-
// util.debugPrint(' m[16]', m, 32)
|
|
118385
|
-
for (i = 0; i < 10; i++) {
|
|
118386
|
-
// util.debugPrint(' (i=' + i + ') v[16]', v, 32)
|
|
118387
|
-
B2S_G(0, 4, 8, 12, m[SIGMA[i * 16 + 0]], m[SIGMA[i * 16 + 1]]);
|
|
118388
|
-
B2S_G(1, 5, 9, 13, m[SIGMA[i * 16 + 2]], m[SIGMA[i * 16 + 3]]);
|
|
118389
|
-
B2S_G(2, 6, 10, 14, m[SIGMA[i * 16 + 4]], m[SIGMA[i * 16 + 5]]);
|
|
118390
|
-
B2S_G(3, 7, 11, 15, m[SIGMA[i * 16 + 6]], m[SIGMA[i * 16 + 7]]);
|
|
118391
|
-
B2S_G(0, 5, 10, 15, m[SIGMA[i * 16 + 8]], m[SIGMA[i * 16 + 9]]);
|
|
118392
|
-
B2S_G(1, 6, 11, 12, m[SIGMA[i * 16 + 10]], m[SIGMA[i * 16 + 11]]);
|
|
118393
|
-
B2S_G(2, 7, 8, 13, m[SIGMA[i * 16 + 12]], m[SIGMA[i * 16 + 13]]);
|
|
118394
|
-
B2S_G(3, 4, 9, 14, m[SIGMA[i * 16 + 14]], m[SIGMA[i * 16 + 15]]);
|
|
118395
|
-
}
|
|
118396
|
-
// util.debugPrint(' (i=10) v[16]', v, 32)
|
|
118397
|
-
|
|
118398
|
-
for (i = 0; i < 8; i++) {
|
|
118399
|
-
ctx.h[i] ^= v[i] ^ v[i + 8];
|
|
118400
|
-
}
|
|
118401
|
-
// util.debugPrint('h[8]', ctx.h, 32)
|
|
118402
|
-
}
|
|
118403
|
-
|
|
118404
|
-
// Creates a BLAKE2s hashing context
|
|
118405
|
-
// Requires an output length between 1 and 32 bytes
|
|
118406
|
-
// Takes an optional Uint8Array key
|
|
118407
|
-
function blake2sInit (outlen, key) {
|
|
118408
|
-
if (!(outlen > 0 && outlen <= 32)) {
|
|
118409
|
-
throw new Error('Incorrect output length, should be in [1, 32]')
|
|
118410
|
-
}
|
|
118411
|
-
const keylen = key ? key.length : 0;
|
|
118412
|
-
if (key && !(keylen > 0 && keylen <= 32)) {
|
|
118413
|
-
throw new Error('Incorrect key length, should be in [1, 32]')
|
|
118414
|
-
}
|
|
118415
|
-
|
|
118416
|
-
const ctx = {
|
|
118417
|
-
h: new Uint32Array(BLAKE2S_IV), // hash state
|
|
118418
|
-
b: new Uint8Array(64), // input block
|
|
118419
|
-
c: 0, // pointer within block
|
|
118420
|
-
t: 0, // input count
|
|
118421
|
-
outlen: outlen // output length in bytes
|
|
118422
|
-
};
|
|
118423
|
-
ctx.h[0] ^= 0x01010000 ^ (keylen << 8) ^ outlen;
|
|
118424
|
-
|
|
118425
|
-
if (keylen > 0) {
|
|
118426
|
-
blake2sUpdate(ctx, key);
|
|
118427
|
-
ctx.c = 64; // at the end
|
|
118428
|
-
}
|
|
118429
|
-
|
|
118430
|
-
return ctx
|
|
118431
|
-
}
|
|
118432
|
-
|
|
118433
|
-
// Updates a BLAKE2s streaming hash
|
|
118434
|
-
// Requires hash context and Uint8Array (byte array)
|
|
118435
|
-
function blake2sUpdate (ctx, input) {
|
|
118436
|
-
for (let i = 0; i < input.length; i++) {
|
|
118437
|
-
if (ctx.c === 64) {
|
|
118438
|
-
// buffer full ?
|
|
118439
|
-
ctx.t += ctx.c; // add counters
|
|
118440
|
-
blake2sCompress(ctx, false); // compress (not last)
|
|
118441
|
-
ctx.c = 0; // counter to zero
|
|
118442
|
-
}
|
|
118443
|
-
ctx.b[ctx.c++] = input[i];
|
|
118444
|
-
}
|
|
118445
|
-
}
|
|
118446
|
-
|
|
118447
|
-
// Completes a BLAKE2s streaming hash
|
|
118448
|
-
// Returns a Uint8Array containing the message digest
|
|
118449
|
-
function blake2sFinal (ctx) {
|
|
118450
|
-
ctx.t += ctx.c; // mark last block offset
|
|
118451
|
-
while (ctx.c < 64) {
|
|
118452
|
-
// fill up with zeros
|
|
118453
|
-
ctx.b[ctx.c++] = 0;
|
|
118454
|
-
}
|
|
118455
|
-
blake2sCompress(ctx, true); // final block flag = 1
|
|
118456
|
-
|
|
118457
|
-
// little endian convert and store
|
|
118458
|
-
const out = new Uint8Array(ctx.outlen);
|
|
118459
|
-
for (let i = 0; i < ctx.outlen; i++) {
|
|
118460
|
-
out[i] = (ctx.h[i >> 2] >> (8 * (i & 3))) & 0xff;
|
|
118461
|
-
}
|
|
118462
|
-
return out
|
|
118463
|
-
}
|
|
118464
|
-
|
|
118465
|
-
// Computes the BLAKE2S hash of a string or byte array, and returns a Uint8Array
|
|
118466
|
-
//
|
|
118467
|
-
// Returns a n-byte Uint8Array
|
|
118468
|
-
//
|
|
118469
|
-
// Parameters:
|
|
118470
|
-
// - input - the input bytes, as a string, Buffer, or Uint8Array
|
|
118471
|
-
// - key - optional key Uint8Array, up to 32 bytes
|
|
118472
|
-
// - outlen - optional output length in bytes, default 64
|
|
118473
|
-
function blake2s (input, key, outlen) {
|
|
118474
|
-
// preprocess inputs
|
|
118475
|
-
outlen = outlen || 32;
|
|
118476
|
-
input = util.normalizeInput(input);
|
|
118477
|
-
|
|
118478
|
-
// do the math
|
|
118479
|
-
const ctx = blake2sInit(outlen, key);
|
|
118480
|
-
blake2sUpdate(ctx, input);
|
|
118481
|
-
return blake2sFinal(ctx)
|
|
118482
|
-
}
|
|
118483
|
-
|
|
118484
|
-
// Computes the BLAKE2S hash of a string or byte array
|
|
118485
|
-
//
|
|
118486
|
-
// Returns an n-byte hash in hex, all lowercase
|
|
118487
|
-
//
|
|
118488
|
-
// Parameters:
|
|
118489
|
-
// - input - the input bytes, as a string, Buffer, or Uint8Array
|
|
118490
|
-
// - key - optional key Uint8Array, up to 32 bytes
|
|
118491
|
-
// - outlen - optional output length in bytes, default 64
|
|
118492
|
-
function blake2sHex (input, key, outlen) {
|
|
118493
|
-
const output = blake2s(input, key, outlen);
|
|
118494
|
-
return util.toHex(output)
|
|
118495
|
-
}
|
|
118496
|
-
|
|
118497
|
-
var blake2s_1 = {
|
|
118498
|
-
blake2s: blake2s,
|
|
118499
|
-
blake2sHex: blake2sHex,
|
|
118500
|
-
blake2sInit: blake2sInit,
|
|
118501
|
-
blake2sUpdate: blake2sUpdate,
|
|
118502
|
-
blake2sFinal: blake2sFinal
|
|
118503
|
-
};
|
|
117809
|
+
const util = requireUtil();
|
|
118504
117810
|
|
|
118505
|
-
|
|
118506
|
-
|
|
118507
|
-
|
|
118508
|
-
|
|
118509
|
-
|
|
118510
|
-
|
|
118511
|
-
|
|
118512
|
-
|
|
118513
|
-
|
|
118514
|
-
|
|
118515
|
-
|
|
118516
|
-
|
|
118517
|
-
|
|
118518
|
-
|
|
118519
|
-
|
|
117811
|
+
// 64-bit unsigned addition
|
|
117812
|
+
// Sets v[a,a+1] += v[b,b+1]
|
|
117813
|
+
// v should be a Uint32Array
|
|
117814
|
+
function ADD64AA (v, a, b) {
|
|
117815
|
+
const o0 = v[a] + v[b];
|
|
117816
|
+
let o1 = v[a + 1] + v[b + 1];
|
|
117817
|
+
if (o0 >= 0x100000000) {
|
|
117818
|
+
o1++;
|
|
117819
|
+
}
|
|
117820
|
+
v[a] = o0;
|
|
117821
|
+
v[a + 1] = o1;
|
|
117822
|
+
}
|
|
117823
|
+
|
|
117824
|
+
// 64-bit unsigned addition
|
|
117825
|
+
// Sets v[a,a+1] += b
|
|
117826
|
+
// b0 is the low 32 bits of b, b1 represents the high 32 bits
|
|
117827
|
+
function ADD64AC (v, a, b0, b1) {
|
|
117828
|
+
let o0 = v[a] + b0;
|
|
117829
|
+
if (b0 < 0) {
|
|
117830
|
+
o0 += 0x100000000;
|
|
117831
|
+
}
|
|
117832
|
+
let o1 = v[a + 1] + b1;
|
|
117833
|
+
if (o0 >= 0x100000000) {
|
|
117834
|
+
o1++;
|
|
117835
|
+
}
|
|
117836
|
+
v[a] = o0;
|
|
117837
|
+
v[a + 1] = o1;
|
|
117838
|
+
}
|
|
117839
|
+
|
|
117840
|
+
// Little-endian byte access
|
|
117841
|
+
function B2B_GET32 (arr, i) {
|
|
117842
|
+
return arr[i] ^ (arr[i + 1] << 8) ^ (arr[i + 2] << 16) ^ (arr[i + 3] << 24)
|
|
117843
|
+
}
|
|
117844
|
+
|
|
117845
|
+
// G Mixing function
|
|
117846
|
+
// The ROTRs are inlined for speed
|
|
117847
|
+
function B2B_G (a, b, c, d, ix, iy) {
|
|
117848
|
+
const x0 = m[ix];
|
|
117849
|
+
const x1 = m[ix + 1];
|
|
117850
|
+
const y0 = m[iy];
|
|
117851
|
+
const y1 = m[iy + 1];
|
|
117852
|
+
|
|
117853
|
+
ADD64AA(v, a, b); // v[a,a+1] += v[b,b+1] ... in JS we must store a uint64 as two uint32s
|
|
117854
|
+
ADD64AC(v, a, x0, x1); // v[a, a+1] += x ... x0 is the low 32 bits of x, x1 is the high 32 bits
|
|
117855
|
+
|
|
117856
|
+
// v[d,d+1] = (v[d,d+1] xor v[a,a+1]) rotated to the right by 32 bits
|
|
117857
|
+
let xor0 = v[d] ^ v[a];
|
|
117858
|
+
let xor1 = v[d + 1] ^ v[a + 1];
|
|
117859
|
+
v[d] = xor1;
|
|
117860
|
+
v[d + 1] = xor0;
|
|
117861
|
+
|
|
117862
|
+
ADD64AA(v, c, d);
|
|
117863
|
+
|
|
117864
|
+
// v[b,b+1] = (v[b,b+1] xor v[c,c+1]) rotated right by 24 bits
|
|
117865
|
+
xor0 = v[b] ^ v[c];
|
|
117866
|
+
xor1 = v[b + 1] ^ v[c + 1];
|
|
117867
|
+
v[b] = (xor0 >>> 24) ^ (xor1 << 8);
|
|
117868
|
+
v[b + 1] = (xor1 >>> 24) ^ (xor0 << 8);
|
|
117869
|
+
|
|
117870
|
+
ADD64AA(v, a, b);
|
|
117871
|
+
ADD64AC(v, a, y0, y1);
|
|
117872
|
+
|
|
117873
|
+
// v[d,d+1] = (v[d,d+1] xor v[a,a+1]) rotated right by 16 bits
|
|
117874
|
+
xor0 = v[d] ^ v[a];
|
|
117875
|
+
xor1 = v[d + 1] ^ v[a + 1];
|
|
117876
|
+
v[d] = (xor0 >>> 16) ^ (xor1 << 16);
|
|
117877
|
+
v[d + 1] = (xor1 >>> 16) ^ (xor0 << 16);
|
|
117878
|
+
|
|
117879
|
+
ADD64AA(v, c, d);
|
|
117880
|
+
|
|
117881
|
+
// v[b,b+1] = (v[b,b+1] xor v[c,c+1]) rotated right by 63 bits
|
|
117882
|
+
xor0 = v[b] ^ v[c];
|
|
117883
|
+
xor1 = v[b + 1] ^ v[c + 1];
|
|
117884
|
+
v[b] = (xor1 >>> 31) ^ (xor0 << 1);
|
|
117885
|
+
v[b + 1] = (xor0 >>> 31) ^ (xor1 << 1);
|
|
117886
|
+
}
|
|
117887
|
+
|
|
117888
|
+
// Initialization Vector
|
|
117889
|
+
const BLAKE2B_IV32 = new Uint32Array([
|
|
117890
|
+
0xf3bcc908, 0x6a09e667, 0x84caa73b, 0xbb67ae85, 0xfe94f82b, 0x3c6ef372,
|
|
117891
|
+
0x5f1d36f1, 0xa54ff53a, 0xade682d1, 0x510e527f, 0x2b3e6c1f, 0x9b05688c,
|
|
117892
|
+
0xfb41bd6b, 0x1f83d9ab, 0x137e2179, 0x5be0cd19
|
|
117893
|
+
]);
|
|
117894
|
+
|
|
117895
|
+
const SIGMA8 = [
|
|
117896
|
+
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 14, 10, 4, 8, 9, 15, 13,
|
|
117897
|
+
6, 1, 12, 0, 2, 11, 7, 5, 3, 11, 8, 12, 0, 5, 2, 15, 13, 10, 14, 3, 6, 7, 1,
|
|
117898
|
+
9, 4, 7, 9, 3, 1, 13, 12, 11, 14, 2, 6, 5, 10, 4, 0, 15, 8, 9, 0, 5, 7, 2, 4,
|
|
117899
|
+
10, 15, 14, 1, 11, 12, 6, 8, 3, 13, 2, 12, 6, 10, 0, 11, 8, 3, 4, 13, 7, 5,
|
|
117900
|
+
15, 14, 1, 9, 12, 5, 1, 15, 14, 13, 4, 10, 0, 7, 6, 3, 9, 2, 8, 11, 13, 11, 7,
|
|
117901
|
+
14, 12, 1, 3, 9, 5, 0, 15, 4, 8, 6, 2, 10, 6, 15, 14, 9, 11, 3, 0, 8, 12, 2,
|
|
117902
|
+
13, 7, 1, 4, 10, 5, 10, 2, 8, 4, 7, 6, 1, 5, 15, 11, 9, 14, 3, 12, 13, 0, 0,
|
|
117903
|
+
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 14, 10, 4, 8, 9, 15, 13, 6,
|
|
117904
|
+
1, 12, 0, 2, 11, 7, 5, 3
|
|
117905
|
+
];
|
|
117906
|
+
|
|
117907
|
+
// These are offsets into a uint64 buffer.
|
|
117908
|
+
// Multiply them all by 2 to make them offsets into a uint32 buffer,
|
|
117909
|
+
// because this is Javascript and we don't have uint64s
|
|
117910
|
+
const SIGMA82 = new Uint8Array(
|
|
117911
|
+
SIGMA8.map(function (x) {
|
|
117912
|
+
return x * 2
|
|
117913
|
+
})
|
|
117914
|
+
);
|
|
117915
|
+
|
|
117916
|
+
// Compression function. 'last' flag indicates last block.
|
|
117917
|
+
// Note we're representing 16 uint64s as 32 uint32s
|
|
117918
|
+
const v = new Uint32Array(32);
|
|
117919
|
+
const m = new Uint32Array(32);
|
|
117920
|
+
function blake2bCompress (ctx, last) {
|
|
117921
|
+
let i = 0;
|
|
117922
|
+
|
|
117923
|
+
// init work variables
|
|
117924
|
+
for (i = 0; i < 16; i++) {
|
|
117925
|
+
v[i] = ctx.h[i];
|
|
117926
|
+
v[i + 16] = BLAKE2B_IV32[i];
|
|
117927
|
+
}
|
|
117928
|
+
|
|
117929
|
+
// low 64 bits of offset
|
|
117930
|
+
v[24] = v[24] ^ ctx.t;
|
|
117931
|
+
v[25] = v[25] ^ (ctx.t / 0x100000000);
|
|
117932
|
+
// high 64 bits not supported, offset may not be higher than 2**53-1
|
|
117933
|
+
|
|
117934
|
+
// last block flag set ?
|
|
117935
|
+
if (last) {
|
|
117936
|
+
v[28] = ~v[28];
|
|
117937
|
+
v[29] = ~v[29];
|
|
117938
|
+
}
|
|
117939
|
+
|
|
117940
|
+
// get little-endian words
|
|
117941
|
+
for (i = 0; i < 32; i++) {
|
|
117942
|
+
m[i] = B2B_GET32(ctx.b, 4 * i);
|
|
117943
|
+
}
|
|
117944
|
+
|
|
117945
|
+
// twelve rounds of mixing
|
|
117946
|
+
// uncomment the DebugPrint calls to log the computation
|
|
117947
|
+
// and match the RFC sample documentation
|
|
117948
|
+
// util.debugPrint(' m[16]', m, 64)
|
|
117949
|
+
for (i = 0; i < 12; i++) {
|
|
117950
|
+
// util.debugPrint(' (i=' + (i < 10 ? ' ' : '') + i + ') v[16]', v, 64)
|
|
117951
|
+
B2B_G(0, 8, 16, 24, SIGMA82[i * 16 + 0], SIGMA82[i * 16 + 1]);
|
|
117952
|
+
B2B_G(2, 10, 18, 26, SIGMA82[i * 16 + 2], SIGMA82[i * 16 + 3]);
|
|
117953
|
+
B2B_G(4, 12, 20, 28, SIGMA82[i * 16 + 4], SIGMA82[i * 16 + 5]);
|
|
117954
|
+
B2B_G(6, 14, 22, 30, SIGMA82[i * 16 + 6], SIGMA82[i * 16 + 7]);
|
|
117955
|
+
B2B_G(0, 10, 20, 30, SIGMA82[i * 16 + 8], SIGMA82[i * 16 + 9]);
|
|
117956
|
+
B2B_G(2, 12, 22, 24, SIGMA82[i * 16 + 10], SIGMA82[i * 16 + 11]);
|
|
117957
|
+
B2B_G(4, 14, 16, 26, SIGMA82[i * 16 + 12], SIGMA82[i * 16 + 13]);
|
|
117958
|
+
B2B_G(6, 8, 18, 28, SIGMA82[i * 16 + 14], SIGMA82[i * 16 + 15]);
|
|
117959
|
+
}
|
|
117960
|
+
// util.debugPrint(' (i=12) v[16]', v, 64)
|
|
117961
|
+
|
|
117962
|
+
for (i = 0; i < 16; i++) {
|
|
117963
|
+
ctx.h[i] = ctx.h[i] ^ v[i] ^ v[i + 16];
|
|
117964
|
+
}
|
|
117965
|
+
// util.debugPrint('h[8]', ctx.h, 64)
|
|
117966
|
+
}
|
|
117967
|
+
|
|
117968
|
+
// reusable parameterBlock
|
|
117969
|
+
const parameterBlock = new Uint8Array([
|
|
117970
|
+
0,
|
|
117971
|
+
0,
|
|
117972
|
+
0,
|
|
117973
|
+
0, // 0: outlen, keylen, fanout, depth
|
|
117974
|
+
0,
|
|
117975
|
+
0,
|
|
117976
|
+
0,
|
|
117977
|
+
0, // 4: leaf length, sequential mode
|
|
117978
|
+
0,
|
|
117979
|
+
0,
|
|
117980
|
+
0,
|
|
117981
|
+
0, // 8: node offset
|
|
117982
|
+
0,
|
|
117983
|
+
0,
|
|
117984
|
+
0,
|
|
117985
|
+
0, // 12: node offset
|
|
117986
|
+
0,
|
|
117987
|
+
0,
|
|
117988
|
+
0,
|
|
117989
|
+
0, // 16: node depth, inner length, rfu
|
|
117990
|
+
0,
|
|
117991
|
+
0,
|
|
117992
|
+
0,
|
|
117993
|
+
0, // 20: rfu
|
|
117994
|
+
0,
|
|
117995
|
+
0,
|
|
117996
|
+
0,
|
|
117997
|
+
0, // 24: rfu
|
|
117998
|
+
0,
|
|
117999
|
+
0,
|
|
118000
|
+
0,
|
|
118001
|
+
0, // 28: rfu
|
|
118002
|
+
0,
|
|
118003
|
+
0,
|
|
118004
|
+
0,
|
|
118005
|
+
0, // 32: salt
|
|
118006
|
+
0,
|
|
118007
|
+
0,
|
|
118008
|
+
0,
|
|
118009
|
+
0, // 36: salt
|
|
118010
|
+
0,
|
|
118011
|
+
0,
|
|
118012
|
+
0,
|
|
118013
|
+
0, // 40: salt
|
|
118014
|
+
0,
|
|
118015
|
+
0,
|
|
118016
|
+
0,
|
|
118017
|
+
0, // 44: salt
|
|
118018
|
+
0,
|
|
118019
|
+
0,
|
|
118020
|
+
0,
|
|
118021
|
+
0, // 48: personal
|
|
118022
|
+
0,
|
|
118023
|
+
0,
|
|
118024
|
+
0,
|
|
118025
|
+
0, // 52: personal
|
|
118026
|
+
0,
|
|
118027
|
+
0,
|
|
118028
|
+
0,
|
|
118029
|
+
0, // 56: personal
|
|
118030
|
+
0,
|
|
118031
|
+
0,
|
|
118032
|
+
0,
|
|
118033
|
+
0 // 60: personal
|
|
118034
|
+
]);
|
|
118035
|
+
|
|
118036
|
+
// Creates a BLAKE2b hashing context
|
|
118037
|
+
// Requires an output length between 1 and 64 bytes
|
|
118038
|
+
// Takes an optional Uint8Array key
|
|
118039
|
+
// Takes an optinal Uint8Array salt
|
|
118040
|
+
// Takes an optinal Uint8Array personal
|
|
118041
|
+
function blake2bInit (outlen, key, salt, personal) {
|
|
118042
|
+
if (outlen === 0 || outlen > 64) {
|
|
118043
|
+
throw new Error('Illegal output length, expected 0 < length <= 64')
|
|
118044
|
+
}
|
|
118045
|
+
if (key && key.length > 64) {
|
|
118046
|
+
throw new Error('Illegal key, expected Uint8Array with 0 < length <= 64')
|
|
118047
|
+
}
|
|
118048
|
+
if (salt && salt.length !== 16) {
|
|
118049
|
+
throw new Error('Illegal salt, expected Uint8Array with length is 16')
|
|
118050
|
+
}
|
|
118051
|
+
if (personal && personal.length !== 16) {
|
|
118052
|
+
throw new Error('Illegal personal, expected Uint8Array with length is 16')
|
|
118053
|
+
}
|
|
118054
|
+
|
|
118055
|
+
// state, 'param block'
|
|
118056
|
+
const ctx = {
|
|
118057
|
+
b: new Uint8Array(128),
|
|
118058
|
+
h: new Uint32Array(16),
|
|
118059
|
+
t: 0, // input count
|
|
118060
|
+
c: 0, // pointer within buffer
|
|
118061
|
+
outlen: outlen // output length in bytes
|
|
118062
|
+
};
|
|
118063
|
+
|
|
118064
|
+
// initialize parameterBlock before usage
|
|
118065
|
+
parameterBlock.fill(0);
|
|
118066
|
+
parameterBlock[0] = outlen;
|
|
118067
|
+
if (key) parameterBlock[1] = key.length;
|
|
118068
|
+
parameterBlock[2] = 1; // fanout
|
|
118069
|
+
parameterBlock[3] = 1; // depth
|
|
118070
|
+
if (salt) parameterBlock.set(salt, 32);
|
|
118071
|
+
if (personal) parameterBlock.set(personal, 48);
|
|
118072
|
+
|
|
118073
|
+
// initialize hash state
|
|
118074
|
+
for (let i = 0; i < 16; i++) {
|
|
118075
|
+
ctx.h[i] = BLAKE2B_IV32[i] ^ B2B_GET32(parameterBlock, i * 4);
|
|
118076
|
+
}
|
|
118077
|
+
|
|
118078
|
+
// key the hash, if applicable
|
|
118079
|
+
if (key) {
|
|
118080
|
+
blake2bUpdate(ctx, key);
|
|
118081
|
+
// at the end
|
|
118082
|
+
ctx.c = 128;
|
|
118083
|
+
}
|
|
118084
|
+
|
|
118085
|
+
return ctx
|
|
118086
|
+
}
|
|
118087
|
+
|
|
118088
|
+
// Updates a BLAKE2b streaming hash
|
|
118089
|
+
// Requires hash context and Uint8Array (byte array)
|
|
118090
|
+
function blake2bUpdate (ctx, input) {
|
|
118091
|
+
for (let i = 0; i < input.length; i++) {
|
|
118092
|
+
if (ctx.c === 128) {
|
|
118093
|
+
// buffer full ?
|
|
118094
|
+
ctx.t += ctx.c; // add counters
|
|
118095
|
+
blake2bCompress(ctx, false); // compress (not last)
|
|
118096
|
+
ctx.c = 0; // counter to zero
|
|
118097
|
+
}
|
|
118098
|
+
ctx.b[ctx.c++] = input[i];
|
|
118099
|
+
}
|
|
118100
|
+
}
|
|
118101
|
+
|
|
118102
|
+
// Completes a BLAKE2b streaming hash
|
|
118103
|
+
// Returns a Uint8Array containing the message digest
|
|
118104
|
+
function blake2bFinal (ctx) {
|
|
118105
|
+
ctx.t += ctx.c; // mark last block offset
|
|
118106
|
+
|
|
118107
|
+
while (ctx.c < 128) {
|
|
118108
|
+
// fill up with zeros
|
|
118109
|
+
ctx.b[ctx.c++] = 0;
|
|
118110
|
+
}
|
|
118111
|
+
blake2bCompress(ctx, true); // final block flag = 1
|
|
118112
|
+
|
|
118113
|
+
// little endian convert and store
|
|
118114
|
+
const out = new Uint8Array(ctx.outlen);
|
|
118115
|
+
for (let i = 0; i < ctx.outlen; i++) {
|
|
118116
|
+
out[i] = ctx.h[i >> 2] >> (8 * (i & 3));
|
|
118117
|
+
}
|
|
118118
|
+
return out
|
|
118119
|
+
}
|
|
118120
|
+
|
|
118121
|
+
// Computes the BLAKE2B hash of a string or byte array, and returns a Uint8Array
|
|
118122
|
+
//
|
|
118123
|
+
// Returns a n-byte Uint8Array
|
|
118124
|
+
//
|
|
118125
|
+
// Parameters:
|
|
118126
|
+
// - input - the input bytes, as a string, Buffer or Uint8Array
|
|
118127
|
+
// - key - optional key Uint8Array, up to 64 bytes
|
|
118128
|
+
// - outlen - optional output length in bytes, default 64
|
|
118129
|
+
// - salt - optional salt bytes, string, Buffer or Uint8Array
|
|
118130
|
+
// - personal - optional personal bytes, string, Buffer or Uint8Array
|
|
118131
|
+
function blake2b (input, key, outlen, salt, personal) {
|
|
118132
|
+
// preprocess inputs
|
|
118133
|
+
outlen = outlen || 64;
|
|
118134
|
+
input = util.normalizeInput(input);
|
|
118135
|
+
if (salt) {
|
|
118136
|
+
salt = util.normalizeInput(salt);
|
|
118137
|
+
}
|
|
118138
|
+
if (personal) {
|
|
118139
|
+
personal = util.normalizeInput(personal);
|
|
118140
|
+
}
|
|
118141
|
+
|
|
118142
|
+
// do the math
|
|
118143
|
+
const ctx = blake2bInit(outlen, key, salt, personal);
|
|
118144
|
+
blake2bUpdate(ctx, input);
|
|
118145
|
+
return blake2bFinal(ctx)
|
|
118146
|
+
}
|
|
118147
|
+
|
|
118148
|
+
// Computes the BLAKE2B hash of a string or byte array
|
|
118149
|
+
//
|
|
118150
|
+
// Returns an n-byte hash in hex, all lowercase
|
|
118151
|
+
//
|
|
118152
|
+
// Parameters:
|
|
118153
|
+
// - input - the input bytes, as a string, Buffer, or Uint8Array
|
|
118154
|
+
// - key - optional key Uint8Array, up to 64 bytes
|
|
118155
|
+
// - outlen - optional output length in bytes, default 64
|
|
118156
|
+
// - salt - optional salt bytes, string, Buffer or Uint8Array
|
|
118157
|
+
// - personal - optional personal bytes, string, Buffer or Uint8Array
|
|
118158
|
+
function blake2bHex (input, key, outlen, salt, personal) {
|
|
118159
|
+
const output = blake2b(input, key, outlen, salt, personal);
|
|
118160
|
+
return util.toHex(output)
|
|
118161
|
+
}
|
|
118162
|
+
|
|
118163
|
+
blake2b_1 = {
|
|
118164
|
+
blake2b: blake2b,
|
|
118165
|
+
blake2bHex: blake2bHex,
|
|
118166
|
+
blake2bInit: blake2bInit,
|
|
118167
|
+
blake2bUpdate: blake2bUpdate,
|
|
118168
|
+
blake2bFinal: blake2bFinal
|
|
118169
|
+
};
|
|
118170
|
+
return blake2b_1;
|
|
118171
|
+
}
|
|
118172
|
+
|
|
118173
|
+
var blake2s_1;
|
|
118174
|
+
var hasRequiredBlake2s;
|
|
118175
|
+
|
|
118176
|
+
function requireBlake2s () {
|
|
118177
|
+
if (hasRequiredBlake2s) return blake2s_1;
|
|
118178
|
+
hasRequiredBlake2s = 1;
|
|
118179
|
+
// BLAKE2s hash function in pure Javascript
|
|
118180
|
+
// Adapted from the reference implementation in RFC7693
|
|
118181
|
+
// Ported to Javascript by DC - https://github.com/dcposch
|
|
118182
|
+
|
|
118183
|
+
const util = requireUtil();
|
|
118184
|
+
|
|
118185
|
+
// Little-endian byte access.
|
|
118186
|
+
// Expects a Uint8Array and an index
|
|
118187
|
+
// Returns the little-endian uint32 at v[i..i+3]
|
|
118188
|
+
function B2S_GET32 (v, i) {
|
|
118189
|
+
return v[i] ^ (v[i + 1] << 8) ^ (v[i + 2] << 16) ^ (v[i + 3] << 24)
|
|
118190
|
+
}
|
|
118191
|
+
|
|
118192
|
+
// Mixing function G.
|
|
118193
|
+
function B2S_G (a, b, c, d, x, y) {
|
|
118194
|
+
v[a] = v[a] + v[b] + x;
|
|
118195
|
+
v[d] = ROTR32(v[d] ^ v[a], 16);
|
|
118196
|
+
v[c] = v[c] + v[d];
|
|
118197
|
+
v[b] = ROTR32(v[b] ^ v[c], 12);
|
|
118198
|
+
v[a] = v[a] + v[b] + y;
|
|
118199
|
+
v[d] = ROTR32(v[d] ^ v[a], 8);
|
|
118200
|
+
v[c] = v[c] + v[d];
|
|
118201
|
+
v[b] = ROTR32(v[b] ^ v[c], 7);
|
|
118202
|
+
}
|
|
118203
|
+
|
|
118204
|
+
// 32-bit right rotation
|
|
118205
|
+
// x should be a uint32
|
|
118206
|
+
// y must be between 1 and 31, inclusive
|
|
118207
|
+
function ROTR32 (x, y) {
|
|
118208
|
+
return (x >>> y) ^ (x << (32 - y))
|
|
118209
|
+
}
|
|
118210
|
+
|
|
118211
|
+
// Initialization Vector.
|
|
118212
|
+
const BLAKE2S_IV = new Uint32Array([
|
|
118213
|
+
0x6a09e667,
|
|
118214
|
+
0xbb67ae85,
|
|
118215
|
+
0x3c6ef372,
|
|
118216
|
+
0xa54ff53a,
|
|
118217
|
+
0x510e527f,
|
|
118218
|
+
0x9b05688c,
|
|
118219
|
+
0x1f83d9ab,
|
|
118220
|
+
0x5be0cd19
|
|
118221
|
+
]);
|
|
118222
|
+
|
|
118223
|
+
const SIGMA = new Uint8Array([
|
|
118224
|
+
0,
|
|
118225
|
+
1,
|
|
118226
|
+
2,
|
|
118227
|
+
3,
|
|
118228
|
+
4,
|
|
118229
|
+
5,
|
|
118230
|
+
6,
|
|
118231
|
+
7,
|
|
118232
|
+
8,
|
|
118233
|
+
9,
|
|
118234
|
+
10,
|
|
118235
|
+
11,
|
|
118236
|
+
12,
|
|
118237
|
+
13,
|
|
118238
|
+
14,
|
|
118239
|
+
15,
|
|
118240
|
+
14,
|
|
118241
|
+
10,
|
|
118242
|
+
4,
|
|
118243
|
+
8,
|
|
118244
|
+
9,
|
|
118245
|
+
15,
|
|
118246
|
+
13,
|
|
118247
|
+
6,
|
|
118248
|
+
1,
|
|
118249
|
+
12,
|
|
118250
|
+
0,
|
|
118251
|
+
2,
|
|
118252
|
+
11,
|
|
118253
|
+
7,
|
|
118254
|
+
5,
|
|
118255
|
+
3,
|
|
118256
|
+
11,
|
|
118257
|
+
8,
|
|
118258
|
+
12,
|
|
118259
|
+
0,
|
|
118260
|
+
5,
|
|
118261
|
+
2,
|
|
118262
|
+
15,
|
|
118263
|
+
13,
|
|
118264
|
+
10,
|
|
118265
|
+
14,
|
|
118266
|
+
3,
|
|
118267
|
+
6,
|
|
118268
|
+
7,
|
|
118269
|
+
1,
|
|
118270
|
+
9,
|
|
118271
|
+
4,
|
|
118272
|
+
7,
|
|
118273
|
+
9,
|
|
118274
|
+
3,
|
|
118275
|
+
1,
|
|
118276
|
+
13,
|
|
118277
|
+
12,
|
|
118278
|
+
11,
|
|
118279
|
+
14,
|
|
118280
|
+
2,
|
|
118281
|
+
6,
|
|
118282
|
+
5,
|
|
118283
|
+
10,
|
|
118284
|
+
4,
|
|
118285
|
+
0,
|
|
118286
|
+
15,
|
|
118287
|
+
8,
|
|
118288
|
+
9,
|
|
118289
|
+
0,
|
|
118290
|
+
5,
|
|
118291
|
+
7,
|
|
118292
|
+
2,
|
|
118293
|
+
4,
|
|
118294
|
+
10,
|
|
118295
|
+
15,
|
|
118296
|
+
14,
|
|
118297
|
+
1,
|
|
118298
|
+
11,
|
|
118299
|
+
12,
|
|
118300
|
+
6,
|
|
118301
|
+
8,
|
|
118302
|
+
3,
|
|
118303
|
+
13,
|
|
118304
|
+
2,
|
|
118305
|
+
12,
|
|
118306
|
+
6,
|
|
118307
|
+
10,
|
|
118308
|
+
0,
|
|
118309
|
+
11,
|
|
118310
|
+
8,
|
|
118311
|
+
3,
|
|
118312
|
+
4,
|
|
118313
|
+
13,
|
|
118314
|
+
7,
|
|
118315
|
+
5,
|
|
118316
|
+
15,
|
|
118317
|
+
14,
|
|
118318
|
+
1,
|
|
118319
|
+
9,
|
|
118320
|
+
12,
|
|
118321
|
+
5,
|
|
118322
|
+
1,
|
|
118323
|
+
15,
|
|
118324
|
+
14,
|
|
118325
|
+
13,
|
|
118326
|
+
4,
|
|
118327
|
+
10,
|
|
118328
|
+
0,
|
|
118329
|
+
7,
|
|
118330
|
+
6,
|
|
118331
|
+
3,
|
|
118332
|
+
9,
|
|
118333
|
+
2,
|
|
118334
|
+
8,
|
|
118335
|
+
11,
|
|
118336
|
+
13,
|
|
118337
|
+
11,
|
|
118338
|
+
7,
|
|
118339
|
+
14,
|
|
118340
|
+
12,
|
|
118341
|
+
1,
|
|
118342
|
+
3,
|
|
118343
|
+
9,
|
|
118344
|
+
5,
|
|
118345
|
+
0,
|
|
118346
|
+
15,
|
|
118347
|
+
4,
|
|
118348
|
+
8,
|
|
118349
|
+
6,
|
|
118350
|
+
2,
|
|
118351
|
+
10,
|
|
118352
|
+
6,
|
|
118353
|
+
15,
|
|
118354
|
+
14,
|
|
118355
|
+
9,
|
|
118356
|
+
11,
|
|
118357
|
+
3,
|
|
118358
|
+
0,
|
|
118359
|
+
8,
|
|
118360
|
+
12,
|
|
118361
|
+
2,
|
|
118362
|
+
13,
|
|
118363
|
+
7,
|
|
118364
|
+
1,
|
|
118365
|
+
4,
|
|
118366
|
+
10,
|
|
118367
|
+
5,
|
|
118368
|
+
10,
|
|
118369
|
+
2,
|
|
118370
|
+
8,
|
|
118371
|
+
4,
|
|
118372
|
+
7,
|
|
118373
|
+
6,
|
|
118374
|
+
1,
|
|
118375
|
+
5,
|
|
118376
|
+
15,
|
|
118377
|
+
11,
|
|
118378
|
+
9,
|
|
118379
|
+
14,
|
|
118380
|
+
3,
|
|
118381
|
+
12,
|
|
118382
|
+
13,
|
|
118383
|
+
0
|
|
118384
|
+
]);
|
|
118385
|
+
|
|
118386
|
+
// Compression function. "last" flag indicates last block
|
|
118387
|
+
const v = new Uint32Array(16);
|
|
118388
|
+
const m = new Uint32Array(16);
|
|
118389
|
+
function blake2sCompress (ctx, last) {
|
|
118390
|
+
let i = 0;
|
|
118391
|
+
for (i = 0; i < 8; i++) {
|
|
118392
|
+
// init work variables
|
|
118393
|
+
v[i] = ctx.h[i];
|
|
118394
|
+
v[i + 8] = BLAKE2S_IV[i];
|
|
118395
|
+
}
|
|
118396
|
+
|
|
118397
|
+
v[12] ^= ctx.t; // low 32 bits of offset
|
|
118398
|
+
v[13] ^= ctx.t / 0x100000000; // high 32 bits
|
|
118399
|
+
if (last) {
|
|
118400
|
+
// last block flag set ?
|
|
118401
|
+
v[14] = ~v[14];
|
|
118402
|
+
}
|
|
118403
|
+
|
|
118404
|
+
for (i = 0; i < 16; i++) {
|
|
118405
|
+
// get little-endian words
|
|
118406
|
+
m[i] = B2S_GET32(ctx.b, 4 * i);
|
|
118407
|
+
}
|
|
118408
|
+
|
|
118409
|
+
// ten rounds of mixing
|
|
118410
|
+
// uncomment the DebugPrint calls to log the computation
|
|
118411
|
+
// and match the RFC sample documentation
|
|
118412
|
+
// util.debugPrint(' m[16]', m, 32)
|
|
118413
|
+
for (i = 0; i < 10; i++) {
|
|
118414
|
+
// util.debugPrint(' (i=' + i + ') v[16]', v, 32)
|
|
118415
|
+
B2S_G(0, 4, 8, 12, m[SIGMA[i * 16 + 0]], m[SIGMA[i * 16 + 1]]);
|
|
118416
|
+
B2S_G(1, 5, 9, 13, m[SIGMA[i * 16 + 2]], m[SIGMA[i * 16 + 3]]);
|
|
118417
|
+
B2S_G(2, 6, 10, 14, m[SIGMA[i * 16 + 4]], m[SIGMA[i * 16 + 5]]);
|
|
118418
|
+
B2S_G(3, 7, 11, 15, m[SIGMA[i * 16 + 6]], m[SIGMA[i * 16 + 7]]);
|
|
118419
|
+
B2S_G(0, 5, 10, 15, m[SIGMA[i * 16 + 8]], m[SIGMA[i * 16 + 9]]);
|
|
118420
|
+
B2S_G(1, 6, 11, 12, m[SIGMA[i * 16 + 10]], m[SIGMA[i * 16 + 11]]);
|
|
118421
|
+
B2S_G(2, 7, 8, 13, m[SIGMA[i * 16 + 12]], m[SIGMA[i * 16 + 13]]);
|
|
118422
|
+
B2S_G(3, 4, 9, 14, m[SIGMA[i * 16 + 14]], m[SIGMA[i * 16 + 15]]);
|
|
118423
|
+
}
|
|
118424
|
+
// util.debugPrint(' (i=10) v[16]', v, 32)
|
|
118425
|
+
|
|
118426
|
+
for (i = 0; i < 8; i++) {
|
|
118427
|
+
ctx.h[i] ^= v[i] ^ v[i + 8];
|
|
118428
|
+
}
|
|
118429
|
+
// util.debugPrint('h[8]', ctx.h, 32)
|
|
118430
|
+
}
|
|
118431
|
+
|
|
118432
|
+
// Creates a BLAKE2s hashing context
|
|
118433
|
+
// Requires an output length between 1 and 32 bytes
|
|
118434
|
+
// Takes an optional Uint8Array key
|
|
118435
|
+
function blake2sInit (outlen, key) {
|
|
118436
|
+
if (!(outlen > 0 && outlen <= 32)) {
|
|
118437
|
+
throw new Error('Incorrect output length, should be in [1, 32]')
|
|
118438
|
+
}
|
|
118439
|
+
const keylen = key ? key.length : 0;
|
|
118440
|
+
if (key && !(keylen > 0 && keylen <= 32)) {
|
|
118441
|
+
throw new Error('Incorrect key length, should be in [1, 32]')
|
|
118442
|
+
}
|
|
118443
|
+
|
|
118444
|
+
const ctx = {
|
|
118445
|
+
h: new Uint32Array(BLAKE2S_IV), // hash state
|
|
118446
|
+
b: new Uint8Array(64), // input block
|
|
118447
|
+
c: 0, // pointer within block
|
|
118448
|
+
t: 0, // input count
|
|
118449
|
+
outlen: outlen // output length in bytes
|
|
118450
|
+
};
|
|
118451
|
+
ctx.h[0] ^= 0x01010000 ^ (keylen << 8) ^ outlen;
|
|
118452
|
+
|
|
118453
|
+
if (keylen > 0) {
|
|
118454
|
+
blake2sUpdate(ctx, key);
|
|
118455
|
+
ctx.c = 64; // at the end
|
|
118456
|
+
}
|
|
118457
|
+
|
|
118458
|
+
return ctx
|
|
118459
|
+
}
|
|
118460
|
+
|
|
118461
|
+
// Updates a BLAKE2s streaming hash
|
|
118462
|
+
// Requires hash context and Uint8Array (byte array)
|
|
118463
|
+
function blake2sUpdate (ctx, input) {
|
|
118464
|
+
for (let i = 0; i < input.length; i++) {
|
|
118465
|
+
if (ctx.c === 64) {
|
|
118466
|
+
// buffer full ?
|
|
118467
|
+
ctx.t += ctx.c; // add counters
|
|
118468
|
+
blake2sCompress(ctx, false); // compress (not last)
|
|
118469
|
+
ctx.c = 0; // counter to zero
|
|
118470
|
+
}
|
|
118471
|
+
ctx.b[ctx.c++] = input[i];
|
|
118472
|
+
}
|
|
118473
|
+
}
|
|
118474
|
+
|
|
118475
|
+
// Completes a BLAKE2s streaming hash
|
|
118476
|
+
// Returns a Uint8Array containing the message digest
|
|
118477
|
+
function blake2sFinal (ctx) {
|
|
118478
|
+
ctx.t += ctx.c; // mark last block offset
|
|
118479
|
+
while (ctx.c < 64) {
|
|
118480
|
+
// fill up with zeros
|
|
118481
|
+
ctx.b[ctx.c++] = 0;
|
|
118482
|
+
}
|
|
118483
|
+
blake2sCompress(ctx, true); // final block flag = 1
|
|
118484
|
+
|
|
118485
|
+
// little endian convert and store
|
|
118486
|
+
const out = new Uint8Array(ctx.outlen);
|
|
118487
|
+
for (let i = 0; i < ctx.outlen; i++) {
|
|
118488
|
+
out[i] = (ctx.h[i >> 2] >> (8 * (i & 3))) & 0xff;
|
|
118489
|
+
}
|
|
118490
|
+
return out
|
|
118491
|
+
}
|
|
118492
|
+
|
|
118493
|
+
// Computes the BLAKE2S hash of a string or byte array, and returns a Uint8Array
|
|
118494
|
+
//
|
|
118495
|
+
// Returns a n-byte Uint8Array
|
|
118496
|
+
//
|
|
118497
|
+
// Parameters:
|
|
118498
|
+
// - input - the input bytes, as a string, Buffer, or Uint8Array
|
|
118499
|
+
// - key - optional key Uint8Array, up to 32 bytes
|
|
118500
|
+
// - outlen - optional output length in bytes, default 64
|
|
118501
|
+
function blake2s (input, key, outlen) {
|
|
118502
|
+
// preprocess inputs
|
|
118503
|
+
outlen = outlen || 32;
|
|
118504
|
+
input = util.normalizeInput(input);
|
|
118505
|
+
|
|
118506
|
+
// do the math
|
|
118507
|
+
const ctx = blake2sInit(outlen, key);
|
|
118508
|
+
blake2sUpdate(ctx, input);
|
|
118509
|
+
return blake2sFinal(ctx)
|
|
118510
|
+
}
|
|
118511
|
+
|
|
118512
|
+
// Computes the BLAKE2S hash of a string or byte array
|
|
118513
|
+
//
|
|
118514
|
+
// Returns an n-byte hash in hex, all lowercase
|
|
118515
|
+
//
|
|
118516
|
+
// Parameters:
|
|
118517
|
+
// - input - the input bytes, as a string, Buffer, or Uint8Array
|
|
118518
|
+
// - key - optional key Uint8Array, up to 32 bytes
|
|
118519
|
+
// - outlen - optional output length in bytes, default 64
|
|
118520
|
+
function blake2sHex (input, key, outlen) {
|
|
118521
|
+
const output = blake2s(input, key, outlen);
|
|
118522
|
+
return util.toHex(output)
|
|
118523
|
+
}
|
|
118524
|
+
|
|
118525
|
+
blake2s_1 = {
|
|
118526
|
+
blake2s: blake2s,
|
|
118527
|
+
blake2sHex: blake2sHex,
|
|
118528
|
+
blake2sInit: blake2sInit,
|
|
118529
|
+
blake2sUpdate: blake2sUpdate,
|
|
118530
|
+
blake2sFinal: blake2sFinal
|
|
118531
|
+
};
|
|
118532
|
+
return blake2s_1;
|
|
118533
|
+
}
|
|
118534
|
+
|
|
118535
|
+
var blakejs;
|
|
118536
|
+
var hasRequiredBlakejs;
|
|
118537
|
+
|
|
118538
|
+
function requireBlakejs () {
|
|
118539
|
+
if (hasRequiredBlakejs) return blakejs;
|
|
118540
|
+
hasRequiredBlakejs = 1;
|
|
118541
|
+
const b2b = requireBlake2b();
|
|
118542
|
+
const b2s = requireBlake2s();
|
|
118543
|
+
|
|
118544
|
+
blakejs = {
|
|
118545
|
+
blake2b: b2b.blake2b,
|
|
118546
|
+
blake2bHex: b2b.blake2bHex,
|
|
118547
|
+
blake2bInit: b2b.blake2bInit,
|
|
118548
|
+
blake2bUpdate: b2b.blake2bUpdate,
|
|
118549
|
+
blake2bFinal: b2b.blake2bFinal,
|
|
118550
|
+
blake2s: b2s.blake2s,
|
|
118551
|
+
blake2sHex: b2s.blake2sHex,
|
|
118552
|
+
blake2sInit: b2s.blake2sInit,
|
|
118553
|
+
blake2sUpdate: b2s.blake2sUpdate,
|
|
118554
|
+
blake2sFinal: b2s.blake2sFinal
|
|
118555
|
+
};
|
|
118556
|
+
return blakejs;
|
|
118557
|
+
}
|
|
118520
118558
|
|
|
118521
118559
|
var hasRequiredHash;
|
|
118522
118560
|
|
|
@@ -118525,12 +118563,12 @@ function requireHash () {
|
|
|
118525
118563
|
hasRequiredHash = 1;
|
|
118526
118564
|
Object.defineProperty(hash, "__esModule", { value: true });
|
|
118527
118565
|
hash.ripemd160 = hash.blake128WithKey = hash.blake128 = hash.blake160WithKey = hash.blake160 = hash.blake256WithKey = hash.blake256 = void 0;
|
|
118528
|
-
const crypto_js_1 =
|
|
118566
|
+
const crypto_js_1 = requireCryptoJs();
|
|
118529
118567
|
const utility_1 = requireUtility();
|
|
118530
118568
|
/**
|
|
118531
118569
|
* @hidden
|
|
118532
118570
|
*/
|
|
118533
|
-
const blake =
|
|
118571
|
+
const blake = requireBlakejs();
|
|
118534
118572
|
/**
|
|
118535
118573
|
* Gets data's 256 bit blake hash.
|
|
118536
118574
|
* @param data buffer or hexadecimal string
|
|
@@ -127630,6 +127668,58 @@ const getPrefix = (network) => {
|
|
|
127630
127668
|
return 'tthor';
|
|
127631
127669
|
}
|
|
127632
127670
|
};
|
|
127671
|
+
/**
|
|
127672
|
+
* Parse the derivation path from a string to an Array of numbers
|
|
127673
|
+
* @param {string} path - Path to parse
|
|
127674
|
+
* @returns {number[]} - The derivation path as Array of numbers
|
|
127675
|
+
*/
|
|
127676
|
+
const parseDerivationPath = (path) => {
|
|
127677
|
+
if (!path.startsWith('m'))
|
|
127678
|
+
throw new Error("Path string must start with 'm'");
|
|
127679
|
+
let rest = path.slice(1);
|
|
127680
|
+
const out = new Array();
|
|
127681
|
+
while (rest) {
|
|
127682
|
+
const match = rest.match(/^\/([0-9]+)('?)/);
|
|
127683
|
+
if (!match)
|
|
127684
|
+
throw new Error('Syntax error while reading path component');
|
|
127685
|
+
const [fullMatch, numberString] = match;
|
|
127686
|
+
const value = build$6.Uint53.fromString(numberString).toNumber();
|
|
127687
|
+
if (value >= Math.pow(2, 31))
|
|
127688
|
+
throw new Error('Component value too high. Must not exceed 2**31-1.');
|
|
127689
|
+
out.push(value);
|
|
127690
|
+
rest = rest.slice(fullMatch.length);
|
|
127691
|
+
}
|
|
127692
|
+
return out;
|
|
127693
|
+
};
|
|
127694
|
+
/**
|
|
127695
|
+
* Sort JSON object
|
|
127696
|
+
* @param {any} obj - JSON object
|
|
127697
|
+
* @returns {any} JSON object sorted
|
|
127698
|
+
*/
|
|
127699
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
127700
|
+
function sortedObject(obj) {
|
|
127701
|
+
if (typeof obj !== 'object' || obj === null) {
|
|
127702
|
+
return obj;
|
|
127703
|
+
}
|
|
127704
|
+
if (Array.isArray(obj)) {
|
|
127705
|
+
return obj.map(sortedObject);
|
|
127706
|
+
}
|
|
127707
|
+
const sortedKeys = Object.keys(obj).sort();
|
|
127708
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
127709
|
+
const result = {};
|
|
127710
|
+
// NOTE: Use forEach instead of reduce for performance with large objects eg Wasm code
|
|
127711
|
+
sortedKeys.forEach((key) => {
|
|
127712
|
+
result[key] = sortedObject(obj[key]);
|
|
127713
|
+
});
|
|
127714
|
+
return result;
|
|
127715
|
+
}
|
|
127716
|
+
/**
|
|
127717
|
+
* Returns a JSON string with objects sorted by key
|
|
127718
|
+
* */
|
|
127719
|
+
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types, @typescript-eslint/no-explicit-any
|
|
127720
|
+
function sortAndStringifyJson(obj) {
|
|
127721
|
+
return JSON.stringify(sortedObject(obj));
|
|
127722
|
+
}
|
|
127633
127723
|
|
|
127634
127724
|
/**
|
|
127635
127725
|
* Import necessary modules and types for the Thorchain client configuration.
|
|
@@ -127699,7 +127789,7 @@ const defaultClientConfig = {
|
|
|
127699
127789
|
};
|
|
127700
127790
|
|
|
127701
127791
|
/**
|
|
127702
|
-
* Thorchain client
|
|
127792
|
+
* Thorchain base client
|
|
127703
127793
|
*/
|
|
127704
127794
|
class Client extends Client$1 {
|
|
127705
127795
|
/**
|
|
@@ -127710,53 +127800,6 @@ class Client extends Client$1 {
|
|
|
127710
127800
|
constructor(config = defaultClientConfig) {
|
|
127711
127801
|
super(Object.assign(Object.assign({}, defaultClientConfig), config));
|
|
127712
127802
|
}
|
|
127713
|
-
/**
|
|
127714
|
-
* Asynchronous version of getAddress method.
|
|
127715
|
-
* @param {number} index Derivation path index of the address to be generated.
|
|
127716
|
-
* @returns {string} A promise that resolves to the generated address.
|
|
127717
|
-
*/
|
|
127718
|
-
getAddressAsync(index = 0) {
|
|
127719
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
127720
|
-
return this.getAddress(index);
|
|
127721
|
-
});
|
|
127722
|
-
}
|
|
127723
|
-
/**
|
|
127724
|
-
* Get the address derived from the provided phrase.
|
|
127725
|
-
* @param {number | undefined} walletIndex The index of the address derivation path. Default is 0.
|
|
127726
|
-
* @returns {string} The user address at the specified walletIndex.
|
|
127727
|
-
*/
|
|
127728
|
-
getAddress(walletIndex) {
|
|
127729
|
-
const seed = getSeed(this.phrase);
|
|
127730
|
-
const node = fromSeed(seed);
|
|
127731
|
-
const child = node.derivePath(this.getFullDerivationPath(walletIndex || 0));
|
|
127732
|
-
if (!child.privateKey)
|
|
127733
|
-
throw new Error('child does not have a privateKey');
|
|
127734
|
-
// TODO: Make this method async and use CosmosJS official address generation strategy
|
|
127735
|
-
const pubKey = publicKeyCreate(child.privateKey);
|
|
127736
|
-
const rawAddress = this.hash160(Uint8Array.from(pubKey));
|
|
127737
|
-
const words = toWords$1(Buffer.from(rawAddress));
|
|
127738
|
-
const address = encode$2(this.prefix, words);
|
|
127739
|
-
return address;
|
|
127740
|
-
}
|
|
127741
|
-
transfer(params) {
|
|
127742
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
127743
|
-
const sender = yield this.getAddressAsync(params.walletIndex || 0);
|
|
127744
|
-
const { rawUnsignedTx } = yield this.prepareTx({
|
|
127745
|
-
sender,
|
|
127746
|
-
recipient: params.recipient,
|
|
127747
|
-
asset: params.asset,
|
|
127748
|
-
amount: params.amount,
|
|
127749
|
-
memo: params.memo,
|
|
127750
|
-
});
|
|
127751
|
-
const unsignedTx = decodeTxRaw(fromBase64(rawUnsignedTx));
|
|
127752
|
-
const signer = yield DirectSecp256k1HdWallet.fromMnemonic(this.phrase, {
|
|
127753
|
-
prefix: this.prefix,
|
|
127754
|
-
hdPaths: [makeClientPath(this.getFullDerivationPath(params.walletIndex || 0))],
|
|
127755
|
-
});
|
|
127756
|
-
const tx = yield this.roundRobinSignAndBroadcastTx(sender, unsignedTx, signer);
|
|
127757
|
-
return tx.transactionHash;
|
|
127758
|
-
});
|
|
127759
|
-
}
|
|
127760
127803
|
/**
|
|
127761
127804
|
* Get address prefix by network
|
|
127762
127805
|
* @param {Network} network The network of which return the prefix
|
|
@@ -127877,60 +127920,70 @@ class Client extends Client$1 {
|
|
|
127877
127920
|
});
|
|
127878
127921
|
}
|
|
127879
127922
|
/**
|
|
127880
|
-
*
|
|
127923
|
+
* Get deposit transaction
|
|
127881
127924
|
*
|
|
127882
|
-
* @
|
|
127883
|
-
*
|
|
127884
|
-
* @param {Asset} param.asset Optional - The asset that will be deposit. If it is not set, Thorchain native asset will be
|
|
127885
|
-
* used
|
|
127886
|
-
* @param {BaseAmount} param.amount The amount that will be deposit
|
|
127887
|
-
* @param {string} param.memo Optional - The memo associated with the deposit
|
|
127888
|
-
* @param {BigNumber} param.gasLimit Optional - The limit amount of gas allowed to spend in the deposit. If not set, default
|
|
127889
|
-
* value of 600000000 will be used
|
|
127890
|
-
* @returns {string} The deposit hash
|
|
127925
|
+
* @deprecated Use getTransactionData instead
|
|
127926
|
+
* @param {string} txId The transaction ID for which to get the deposit transaction
|
|
127891
127927
|
*/
|
|
127892
|
-
|
|
127928
|
+
getDepositTransaction(txId) {
|
|
127893
127929
|
return __awaiter(this, void 0, void 0, function* () {
|
|
127894
|
-
|
|
127895
|
-
const sender = yield this.getAddressAsync(walletIndex);
|
|
127896
|
-
// Create signer
|
|
127897
|
-
const signer = yield DirectSecp256k1HdWallet.fromMnemonic(this.phrase, {
|
|
127898
|
-
prefix: this.prefix,
|
|
127899
|
-
hdPaths: [makeClientPath(this.getFullDerivationPath(walletIndex || 0))],
|
|
127900
|
-
});
|
|
127901
|
-
const tx = yield this.roundRobinSignAndBroadcastDeposit(sender, signer, gasLimit, amount, memo, asset);
|
|
127902
|
-
return tx.transactionHash;
|
|
127930
|
+
return this.getTransactionData(txId);
|
|
127903
127931
|
});
|
|
127904
127932
|
}
|
|
127905
127933
|
/**
|
|
127906
|
-
*
|
|
127934
|
+
* Get the message type url by type used by the cosmos-sdk client to make certain actions
|
|
127907
127935
|
*
|
|
127908
|
-
* @
|
|
127936
|
+
* @param {MsgTypes} msgType The message type of which return the type url
|
|
127937
|
+
* @returns {string} the type url of the message
|
|
127909
127938
|
*/
|
|
127910
|
-
|
|
127939
|
+
getMsgTypeUrlByType(msgType) {
|
|
127940
|
+
const messageTypeUrls = {
|
|
127941
|
+
[MsgTypes.TRANSFER]: MSG_SEND_TYPE_URL,
|
|
127942
|
+
};
|
|
127943
|
+
return messageTypeUrls[msgType];
|
|
127944
|
+
}
|
|
127945
|
+
/**
|
|
127946
|
+
* Returns the standard fee used by the client
|
|
127947
|
+
*
|
|
127948
|
+
* @returns {StdFee} the standard fee
|
|
127949
|
+
*/
|
|
127950
|
+
getStandardFee() {
|
|
127951
|
+
return { amount: [], gas: '6000000' };
|
|
127952
|
+
}
|
|
127953
|
+
}
|
|
127954
|
+
|
|
127955
|
+
/**
|
|
127956
|
+
* Thorchain Keystore client
|
|
127957
|
+
*/
|
|
127958
|
+
class ClientKeystore extends Client {
|
|
127959
|
+
/**
|
|
127960
|
+
* Asynchronous version of getAddress method.
|
|
127961
|
+
* @param {number} index Derivation path index of the address to be generated.
|
|
127962
|
+
* @returns {string} A promise that resolves to the generated address.
|
|
127963
|
+
*/
|
|
127964
|
+
getAddressAsync(index = 0) {
|
|
127911
127965
|
return __awaiter(this, void 0, void 0, function* () {
|
|
127912
|
-
|
|
127913
|
-
const sender = yield this.getAddressAsync(walletIndex);
|
|
127914
|
-
// Prepare unsigned transaction
|
|
127915
|
-
const { rawUnsignedTx } = yield this.prepareTx({
|
|
127916
|
-
sender,
|
|
127917
|
-
recipient: recipient,
|
|
127918
|
-
asset: asset,
|
|
127919
|
-
amount: amount,
|
|
127920
|
-
memo: memo,
|
|
127921
|
-
});
|
|
127922
|
-
// Decode unsigned transaction
|
|
127923
|
-
const unsignedTx = decodeTxRaw(fromBase64(rawUnsignedTx));
|
|
127924
|
-
// Create signer
|
|
127925
|
-
const signer = yield DirectSecp256k1HdWallet.fromMnemonic(this.phrase, {
|
|
127926
|
-
prefix: this.prefix,
|
|
127927
|
-
hdPaths: [makeClientPath(this.getFullDerivationPath(walletIndex))],
|
|
127928
|
-
});
|
|
127929
|
-
const rawTx = yield this.roundRobinSign(sender, unsignedTx, signer, gasLimit);
|
|
127930
|
-
// Return encoded signed transaction
|
|
127931
|
-
return toBase64(tx$1.TxRaw.encode(rawTx).finish());
|
|
127966
|
+
return this.getAddress(index);
|
|
127932
127967
|
});
|
|
127933
127968
|
}
|
|
127969
|
+
/**
|
|
127970
|
+
* Get the address derived from the provided phrase.
|
|
127971
|
+
* @param {number | undefined} walletIndex The index of the address derivation path. Default is 0.
|
|
127972
|
+
* @returns {string} The user address at the specified walletIndex.
|
|
127973
|
+
*/
|
|
127974
|
+
getAddress(walletIndex) {
|
|
127975
|
+
const seed = getSeed(this.phrase);
|
|
127976
|
+
const node = fromSeed(seed);
|
|
127977
|
+
const child = node.derivePath(this.getFullDerivationPath(walletIndex || 0));
|
|
127978
|
+
if (!child.privateKey)
|
|
127979
|
+
throw new Error('child does not have a privateKey');
|
|
127980
|
+
// TODO: Make this method async and use CosmosJS official address generation strategy
|
|
127981
|
+
const pubKey = publicKeyCreate(child.privateKey);
|
|
127982
|
+
const rawAddress = this.hash160(Uint8Array.from(pubKey));
|
|
127983
|
+
const words = toWords$1(Buffer.from(rawAddress));
|
|
127984
|
+
const address = encode$2(this.prefix, words);
|
|
127985
|
+
return address;
|
|
127986
|
+
}
|
|
127934
127987
|
/**
|
|
127935
127988
|
* Returns the private key associated with an index
|
|
127936
127989
|
*
|
|
@@ -127964,36 +128017,79 @@ class Client extends Client$1 {
|
|
|
127964
128017
|
return Secp256k1.compressPubkey(pubkey);
|
|
127965
128018
|
});
|
|
127966
128019
|
}
|
|
127967
|
-
|
|
127968
|
-
* Get deposit transaction
|
|
127969
|
-
*
|
|
127970
|
-
* @deprecated Use getTransactionData instead
|
|
127971
|
-
* @param {string} txId The transaction ID for which to get the deposit transaction
|
|
127972
|
-
*/
|
|
127973
|
-
getDepositTransaction(txId) {
|
|
128020
|
+
transfer(params) {
|
|
127974
128021
|
return __awaiter(this, void 0, void 0, function* () {
|
|
127975
|
-
|
|
128022
|
+
const sender = yield this.getAddressAsync(params.walletIndex || 0);
|
|
128023
|
+
const { rawUnsignedTx } = yield this.prepareTx({
|
|
128024
|
+
sender,
|
|
128025
|
+
recipient: params.recipient,
|
|
128026
|
+
asset: params.asset,
|
|
128027
|
+
amount: params.amount,
|
|
128028
|
+
memo: params.memo,
|
|
128029
|
+
});
|
|
128030
|
+
const unsignedTx = decodeTxRaw(fromBase64(rawUnsignedTx));
|
|
128031
|
+
const signer = yield DirectSecp256k1HdWallet.fromMnemonic(this.phrase, {
|
|
128032
|
+
prefix: this.prefix,
|
|
128033
|
+
hdPaths: [makeClientPath(this.getFullDerivationPath(params.walletIndex || 0))],
|
|
128034
|
+
});
|
|
128035
|
+
const tx = yield this.roundRobinSignAndBroadcastTx(sender, unsignedTx, signer);
|
|
128036
|
+
return tx.transactionHash;
|
|
127976
128037
|
});
|
|
127977
128038
|
}
|
|
127978
128039
|
/**
|
|
127979
|
-
*
|
|
128040
|
+
* Make a deposit
|
|
127980
128041
|
*
|
|
127981
|
-
* @param {
|
|
127982
|
-
*
|
|
128042
|
+
* @param {number} param.walletIndex Optional - The index to use to generate the address from the transaction will be done.
|
|
128043
|
+
* If it is not set, address associated with index 0 will be used
|
|
128044
|
+
* @param {Asset} param.asset Optional - The asset that will be deposit. If it is not set, Thorchain native asset will be
|
|
128045
|
+
* used
|
|
128046
|
+
* @param {BaseAmount} param.amount The amount that will be deposit
|
|
128047
|
+
* @param {string} param.memo Optional - The memo associated with the deposit
|
|
128048
|
+
* @param {BigNumber} param.gasLimit Optional - The limit amount of gas allowed to spend in the deposit. If not set, default
|
|
128049
|
+
* value of 600000000 will be used
|
|
128050
|
+
* @returns {string} The deposit hash
|
|
127983
128051
|
*/
|
|
127984
|
-
|
|
127985
|
-
|
|
127986
|
-
|
|
127987
|
-
|
|
127988
|
-
|
|
128052
|
+
deposit({ walletIndex = 0, asset = AssetRuneNative, amount, memo, gasLimit = new BigNumber(DEPOSIT_GAS_LIMIT_VALUE), }) {
|
|
128053
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
128054
|
+
// Get sender address
|
|
128055
|
+
const sender = yield this.getAddressAsync(walletIndex);
|
|
128056
|
+
// Create signer
|
|
128057
|
+
const signer = yield DirectSecp256k1HdWallet.fromMnemonic(this.phrase, {
|
|
128058
|
+
prefix: this.prefix,
|
|
128059
|
+
hdPaths: [makeClientPath(this.getFullDerivationPath(walletIndex || 0))],
|
|
128060
|
+
});
|
|
128061
|
+
const tx = yield this.roundRobinSignAndBroadcastDeposit(sender, signer, gasLimit, amount, memo, asset);
|
|
128062
|
+
return tx.transactionHash;
|
|
128063
|
+
});
|
|
127989
128064
|
}
|
|
127990
128065
|
/**
|
|
127991
|
-
*
|
|
128066
|
+
* Create and sign transaction without broadcasting it
|
|
127992
128067
|
*
|
|
127993
|
-
* @
|
|
128068
|
+
* @deprecated Use prepare Tx instead
|
|
127994
128069
|
*/
|
|
127995
|
-
|
|
127996
|
-
return
|
|
128070
|
+
transferOffline({ walletIndex = 0, recipient, asset, amount, memo, gasLimit = new BigNumber(DEFAULT_GAS_LIMIT_VALUE), }) {
|
|
128071
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
128072
|
+
// Get sender address
|
|
128073
|
+
const sender = yield this.getAddressAsync(walletIndex);
|
|
128074
|
+
// Prepare unsigned transaction
|
|
128075
|
+
const { rawUnsignedTx } = yield this.prepareTx({
|
|
128076
|
+
sender,
|
|
128077
|
+
recipient: recipient,
|
|
128078
|
+
asset: asset,
|
|
128079
|
+
amount: amount,
|
|
128080
|
+
memo: memo,
|
|
128081
|
+
});
|
|
128082
|
+
// Decode unsigned transaction
|
|
128083
|
+
const unsignedTx = decodeTxRaw(fromBase64(rawUnsignedTx));
|
|
128084
|
+
// Create signer
|
|
128085
|
+
const signer = yield DirectSecp256k1HdWallet.fromMnemonic(this.phrase, {
|
|
128086
|
+
prefix: this.prefix,
|
|
128087
|
+
hdPaths: [makeClientPath(this.getFullDerivationPath(walletIndex))],
|
|
128088
|
+
});
|
|
128089
|
+
const rawTx = yield this.roundRobinSign(sender, unsignedTx, signer, gasLimit);
|
|
128090
|
+
// Return encoded signed transaction
|
|
128091
|
+
return toBase64(tx$1.TxRaw.encode(rawTx).finish());
|
|
128092
|
+
});
|
|
127997
128093
|
}
|
|
127998
128094
|
/**
|
|
127999
128095
|
* Hashes a buffer using SHA256 followed by RIPEMD160 or RMD160.
|
|
@@ -128022,18 +128118,21 @@ class Client extends Client$1 {
|
|
|
128022
128118
|
return __awaiter(this, void 0, void 0, function* () {
|
|
128023
128119
|
// Connect to signing client
|
|
128024
128120
|
for (const url of this.clientUrls[this.network]) {
|
|
128025
|
-
|
|
128026
|
-
|
|
128027
|
-
|
|
128028
|
-
|
|
128029
|
-
|
|
128030
|
-
|
|
128031
|
-
|
|
128032
|
-
|
|
128033
|
-
|
|
128034
|
-
|
|
128035
|
-
|
|
128036
|
-
|
|
128121
|
+
try {
|
|
128122
|
+
const signingClient = yield build$7.SigningStargateClient.connectWithSigner(url, signer, {
|
|
128123
|
+
registry: this.registry,
|
|
128124
|
+
});
|
|
128125
|
+
// Prepare messages
|
|
128126
|
+
const messages = unsignedTx.body.messages.map((message) => {
|
|
128127
|
+
return { typeUrl: this.getMsgTypeUrlByType(MsgTypes.TRANSFER), value: signingClient.registry.decode(message) };
|
|
128128
|
+
});
|
|
128129
|
+
// Sign transaction
|
|
128130
|
+
return yield signingClient.sign(sender, messages, {
|
|
128131
|
+
amount: [],
|
|
128132
|
+
gas: gasLimit.toString(),
|
|
128133
|
+
}, unsignedTx.body.memo);
|
|
128134
|
+
}
|
|
128135
|
+
catch (_a) { }
|
|
128037
128136
|
}
|
|
128038
128137
|
throw Error('No clients available. Can not sign transaction');
|
|
128039
128138
|
});
|
|
@@ -128105,5 +128204,225 @@ class Client extends Client$1 {
|
|
|
128105
128204
|
}
|
|
128106
128205
|
}
|
|
128107
128206
|
|
|
128108
|
-
|
|
128207
|
+
/**
|
|
128208
|
+
* Thorchain Ledger client
|
|
128209
|
+
*/
|
|
128210
|
+
class ClientLedger extends Client {
|
|
128211
|
+
constructor(params) {
|
|
128212
|
+
super(Object.assign(Object.assign({}, defaultClientConfig), params));
|
|
128213
|
+
this.app = new THORChainApp(params.transport);
|
|
128214
|
+
}
|
|
128215
|
+
/**
|
|
128216
|
+
* Asynchronous version of getAddress method.
|
|
128217
|
+
* @param {number} index Derivation path index of the address to be generated.
|
|
128218
|
+
* @param {boolean} verify True to check the address against the Ledger device, otherwise false
|
|
128219
|
+
* @returns {string} A promise that resolves to the generated address.
|
|
128220
|
+
*/
|
|
128221
|
+
getAddressAsync(index, verify = false) {
|
|
128222
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
128223
|
+
const derivationPath = parseDerivationPath(this.getFullDerivationPath(index || 0));
|
|
128224
|
+
const { bech32Address } = verify
|
|
128225
|
+
? yield this.app.showAddressAndPubKey(derivationPath, this.getPrefix(this.network))
|
|
128226
|
+
: yield this.app.getAddressAndPubKey(derivationPath, this.getPrefix(this.network));
|
|
128227
|
+
return bech32Address;
|
|
128228
|
+
});
|
|
128229
|
+
}
|
|
128230
|
+
/**
|
|
128231
|
+
* @deprecated
|
|
128232
|
+
* Asynchronous version of getAddress method. Not supported for ledger client
|
|
128233
|
+
* @throws {Error} Not supported method
|
|
128234
|
+
*/
|
|
128235
|
+
getAddress() {
|
|
128236
|
+
throw Error('Sync method not supported for Ledger');
|
|
128237
|
+
}
|
|
128238
|
+
/**
|
|
128239
|
+
* Transfers RUNE or synth token
|
|
128240
|
+
*
|
|
128241
|
+
* @param {TxParams} params The transfer options.
|
|
128242
|
+
* @param {number} params.walletIndex Optional - The index to use to generate the address from the transaction will be done.
|
|
128243
|
+
* If it is not set, address associated with index 0 will be used
|
|
128244
|
+
* @param {asset} params.asset Optional - The asset that will be deposit. If it is not set, Thorchain native asset will be
|
|
128245
|
+
* used
|
|
128246
|
+
* @param {BaseAmount} params.amount The amount that will be transfer
|
|
128247
|
+
* @param {string} params.recipient Recipient of the transfer
|
|
128248
|
+
* @param {string} params.memo Optional - The memo associated with the transfer
|
|
128249
|
+
* @returns {TxHash} The transaction hash.
|
|
128250
|
+
*/
|
|
128251
|
+
transfer(params) {
|
|
128252
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
128253
|
+
const signedTx = yield this.transferOffline(params);
|
|
128254
|
+
return this.broadcastTx(signedTx);
|
|
128255
|
+
});
|
|
128256
|
+
}
|
|
128257
|
+
/**
|
|
128258
|
+
* Make a deposit
|
|
128259
|
+
*
|
|
128260
|
+
* @param {number} param.walletIndex Optional - The index to use to generate the address from the transaction will be done.
|
|
128261
|
+
* If it is not set, address associated with index 0 will be used
|
|
128262
|
+
* @param {Asset} param.asset Optional - The asset that will be deposit. If it is not set, Thorchain native asset will be
|
|
128263
|
+
* used
|
|
128264
|
+
* @param {BaseAmount} param.amount The amount that will be deposit
|
|
128265
|
+
* @param {string} param.memo Optional - The memo associated with the deposit
|
|
128266
|
+
* @param {BigNumber} param.gasLimit Optional - The limit amount of gas allowed to spend in the deposit. If not set, default
|
|
128267
|
+
* value of 600000000 will be used
|
|
128268
|
+
* @returns {string} The deposit hash
|
|
128269
|
+
*/
|
|
128270
|
+
deposit({ walletIndex = 0, asset = AssetRuneNative, amount, memo, gasLimit = new BigNumber(DEPOSIT_GAS_LIMIT_VALUE), }) {
|
|
128271
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
128272
|
+
const sender = yield this.getAddressAsync(walletIndex || 0);
|
|
128273
|
+
const account = yield this.getAccount(sender);
|
|
128274
|
+
const formattedDP = parseDerivationPath(this.getFullDerivationPath(walletIndex || 0));
|
|
128275
|
+
const { compressedPk } = yield this.app.getAddressAndPubKey(formattedDP, this.getPrefix(this.getNetwork()));
|
|
128276
|
+
const pubkey = encodePubkey({
|
|
128277
|
+
type: 'tendermint/PubKeySecp256k1',
|
|
128278
|
+
value: toBase64(compressedPk),
|
|
128279
|
+
});
|
|
128280
|
+
const msgs = sortedObject([
|
|
128281
|
+
{
|
|
128282
|
+
type: 'thorchain/MsgDeposit',
|
|
128283
|
+
value: {
|
|
128284
|
+
signer: sender,
|
|
128285
|
+
memo,
|
|
128286
|
+
coins: [
|
|
128287
|
+
{
|
|
128288
|
+
amount: amount.amount().toString(),
|
|
128289
|
+
asset: assetToString(asset),
|
|
128290
|
+
},
|
|
128291
|
+
],
|
|
128292
|
+
},
|
|
128293
|
+
},
|
|
128294
|
+
]);
|
|
128295
|
+
const fee = { amount: [], gas: gasLimit.toString() };
|
|
128296
|
+
const { signature, returnCode, errorMessage } = yield this.app.sign(formattedDP, sortAndStringifyJson({
|
|
128297
|
+
account_number: account.accountNumber.toString(),
|
|
128298
|
+
chain_id: yield this.getChainId(),
|
|
128299
|
+
fee,
|
|
128300
|
+
memo,
|
|
128301
|
+
msgs,
|
|
128302
|
+
sequence: account.sequence.toString(),
|
|
128303
|
+
}));
|
|
128304
|
+
if (!signature)
|
|
128305
|
+
throw Error(`Can not sign deposit transaction. Return code ${returnCode}. Error: ${errorMessage}`);
|
|
128306
|
+
const aminoTypes = this.getProtocolAminoMessages();
|
|
128307
|
+
const rawTx = tx$1.TxRaw.fromPartial({
|
|
128308
|
+
bodyBytes: yield this.registry.encodeTxBody({
|
|
128309
|
+
memo,
|
|
128310
|
+
messages: msgs.map((msg) => aminoTypes.fromAmino(msg)),
|
|
128311
|
+
}),
|
|
128312
|
+
authInfoBytes: makeAuthInfoBytes([
|
|
128313
|
+
{
|
|
128314
|
+
pubkey,
|
|
128315
|
+
sequence: account.sequence,
|
|
128316
|
+
},
|
|
128317
|
+
], fee.amount, Number.parseInt(fee.gas), undefined, undefined, signing.SignMode.SIGN_MODE_LEGACY_AMINO_JSON),
|
|
128318
|
+
signatures: [extractSignatureFromTLV(signature)],
|
|
128319
|
+
});
|
|
128320
|
+
return this.broadcastTx(toBase64(tx$1.TxRaw.encode(rawTx).finish()));
|
|
128321
|
+
});
|
|
128322
|
+
}
|
|
128323
|
+
/**
|
|
128324
|
+
* @deprecated
|
|
128325
|
+
* Create a transaction and sign it without broadcasting it
|
|
128326
|
+
*
|
|
128327
|
+
* @param {TxParams} params The transfer options.
|
|
128328
|
+
* @param {number} params.walletIndex Optional - The index to use to generate the address from the transaction will be done.
|
|
128329
|
+
* If it is not set, address associated with index 0 will be used
|
|
128330
|
+
* @param {asset} params.asset Optional - The asset that will be deposit. If it is not set, Thorchain native asset will be
|
|
128331
|
+
* used
|
|
128332
|
+
* @param {BaseAmount} params.amount The amount that will be transfer
|
|
128333
|
+
* @param {string} params.recipient Recipient of the transfer
|
|
128334
|
+
* @param {string} params.memo Optional - The memo associated with the transfer
|
|
128335
|
+
* @returns {TxHash} The transaction hash.
|
|
128336
|
+
*/
|
|
128337
|
+
transferOffline(params) {
|
|
128338
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
128339
|
+
const sender = yield this.getAddressAsync(params.walletIndex || 0);
|
|
128340
|
+
const account = yield this.getAccount(sender);
|
|
128341
|
+
const formattedDP = parseDerivationPath(this.getFullDerivationPath(params.walletIndex || 0));
|
|
128342
|
+
const { compressedPk } = yield this.app.getAddressAndPubKey(formattedDP, this.getPrefix(this.getNetwork()));
|
|
128343
|
+
const pubkey = encodePubkey({
|
|
128344
|
+
type: 'tendermint/PubKeySecp256k1',
|
|
128345
|
+
value: toBase64(compressedPk),
|
|
128346
|
+
});
|
|
128347
|
+
const msgs = sortedObject([
|
|
128348
|
+
{
|
|
128349
|
+
type: 'thorchain/MsgSend',
|
|
128350
|
+
value: {
|
|
128351
|
+
from_address: sender,
|
|
128352
|
+
to_address: params.recipient,
|
|
128353
|
+
amount: [
|
|
128354
|
+
{
|
|
128355
|
+
amount: params.amount.amount().toString(),
|
|
128356
|
+
denom: this.getDenom(params.asset || AssetRuneNative),
|
|
128357
|
+
},
|
|
128358
|
+
],
|
|
128359
|
+
},
|
|
128360
|
+
},
|
|
128361
|
+
]);
|
|
128362
|
+
const fee = this.getStandardFee();
|
|
128363
|
+
const { signature, returnCode, errorMessage } = yield this.app.sign(formattedDP, sortAndStringifyJson({
|
|
128364
|
+
account_number: account.accountNumber.toString(),
|
|
128365
|
+
chain_id: yield this.getChainId(),
|
|
128366
|
+
fee,
|
|
128367
|
+
memo: params.memo || '',
|
|
128368
|
+
msgs,
|
|
128369
|
+
sequence: account.sequence.toString(),
|
|
128370
|
+
}));
|
|
128371
|
+
if (!signature)
|
|
128372
|
+
throw Error(`Can not sign transfer transaction. Return code ${returnCode}. Error: ${errorMessage}`);
|
|
128373
|
+
const aminoTypes = this.getProtocolAminoMessages();
|
|
128374
|
+
const rawTx = tx$1.TxRaw.fromPartial({
|
|
128375
|
+
bodyBytes: yield this.registry.encodeTxBody({
|
|
128376
|
+
messages: msgs.map((msg) => aminoTypes.fromAmino(msg)),
|
|
128377
|
+
memo: params.memo,
|
|
128378
|
+
}),
|
|
128379
|
+
authInfoBytes: makeAuthInfoBytes([
|
|
128380
|
+
{
|
|
128381
|
+
pubkey,
|
|
128382
|
+
sequence: account.sequence,
|
|
128383
|
+
},
|
|
128384
|
+
], fee.amount, Number.parseInt(fee.gas), undefined, undefined, signing.SignMode.SIGN_MODE_LEGACY_AMINO_JSON),
|
|
128385
|
+
signatures: [extractSignatureFromTLV(signature)],
|
|
128386
|
+
});
|
|
128387
|
+
return toBase64(tx$1.TxRaw.encode(rawTx).finish());
|
|
128388
|
+
});
|
|
128389
|
+
}
|
|
128390
|
+
getProtocolAminoMessages() {
|
|
128391
|
+
const prefix = this.getPrefix(this.network);
|
|
128392
|
+
return new build$7.AminoTypes({
|
|
128393
|
+
'/types.MsgSend': {
|
|
128394
|
+
aminoType: `thorchain/MsgSend`,
|
|
128395
|
+
toAmino: (params) => ({
|
|
128396
|
+
from_address: base64ToBech32(params.fromAddress, prefix),
|
|
128397
|
+
to_address: base64ToBech32(params.toAddress, prefix),
|
|
128398
|
+
amount: [...params.amount],
|
|
128399
|
+
}),
|
|
128400
|
+
fromAmino: (params) => ({
|
|
128401
|
+
fromAddress: bech32ToBase64(params.from_address),
|
|
128402
|
+
toAddress: bech32ToBase64(params.to_address),
|
|
128403
|
+
amount: [...params.amount],
|
|
128404
|
+
}),
|
|
128405
|
+
},
|
|
128406
|
+
'/types.MsgDeposit': {
|
|
128407
|
+
aminoType: `thorchain/MsgDeposit`,
|
|
128408
|
+
toAmino: (params) => ({
|
|
128409
|
+
signer: base64ToBech32(params.signer, prefix),
|
|
128410
|
+
memo: params.memo,
|
|
128411
|
+
coins: params.coins.map((coin) => {
|
|
128412
|
+
return Object.assign(Object.assign({}, coin), { asset: assetToString(coin.asset) });
|
|
128413
|
+
}),
|
|
128414
|
+
}),
|
|
128415
|
+
fromAmino: (params) => ({
|
|
128416
|
+
signer: bech32ToBase64(params.signer),
|
|
128417
|
+
memo: params.memo,
|
|
128418
|
+
coins: params.coins.map((coin) => {
|
|
128419
|
+
return Object.assign(Object.assign({}, coin), { asset: assetFromStringEx(coin.asset) });
|
|
128420
|
+
}),
|
|
128421
|
+
}),
|
|
128422
|
+
},
|
|
128423
|
+
});
|
|
128424
|
+
}
|
|
128425
|
+
}
|
|
128426
|
+
|
|
128427
|
+
export { AssetRuneNative, ClientKeystore as Client, ClientKeystore, ClientLedger, DEFAULT_EXPLORER_URL, DEFAULT_FEE, DEFAULT_GAS_LIMIT_VALUE, DEPOSIT_GAS_LIMIT_VALUE, MSG_DEPOSIT_TYPE_URL, MSG_SEND_TYPE_URL, RUNE_DECIMAL, RUNE_DENOM, RUNE_TICKER, THORChain, defaultClientConfig, getChainId, getDefaultClientUrls, getDefaultExplorers, getDefaultRootDerivationPaths, getDenom, getExplorerAddressUrl, getExplorerTxUrl, getPrefix, isAssetRuneNative, parseDerivationPath, sortAndStringifyJson, sortedObject };
|
|
128109
128428
|
//# sourceMappingURL=index.esm.js.map
|