@leofcoin/chain 1.5.19 → 1.5.21

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.
@@ -4883,11 +4883,27 @@ var index = {
4883
4883
  };
4884
4884
 
4885
4885
  class BasicInterface {
4886
- encoded;
4887
- decoded;
4886
+ #encoded;
4887
+ #decoded;
4888
4888
  keys;
4889
4889
  name;
4890
4890
  #proto;
4891
+ get encoded() {
4892
+ if (!this.#encoded)
4893
+ this.#encoded = this.encode();
4894
+ return this.#encoded;
4895
+ }
4896
+ set encoded(value) {
4897
+ this.#encoded = value;
4898
+ }
4899
+ get decoded() {
4900
+ if (!this.#decoded)
4901
+ this.#decoded = this.decode();
4902
+ return this.#decoded;
4903
+ }
4904
+ set decoded(value) {
4905
+ this.#decoded = value;
4906
+ }
4891
4907
  set proto(value) {
4892
4908
  this.#proto = value;
4893
4909
  this.keys = Object.keys(value);
@@ -4956,7 +4972,7 @@ class BasicInterface {
4956
4972
  toHex() {
4957
4973
  if (!this.encoded)
4958
4974
  this.encode();
4959
- return toHex(this.encoded);
4975
+ return toHex(this.encoded.toString().split(',').map(number => Number(number)));
4960
4976
  }
4961
4977
  /**
4962
4978
  * @return {String} encoded
@@ -4976,443 +4992,6 @@ class BasicInterface {
4976
4992
  }
4977
4993
  }
4978
4994
 
4979
- /*!
4980
- * hash-wasm (https://www.npmjs.com/package/hash-wasm)
4981
- * (c) Dani Biro
4982
- * @license MIT
4983
- */
4984
-
4985
- /******************************************************************************
4986
- Copyright (c) Microsoft Corporation.
4987
-
4988
- Permission to use, copy, modify, and/or distribute this software for any
4989
- purpose with or without fee is hereby granted.
4990
-
4991
- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
4992
- REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
4993
- AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
4994
- INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
4995
- LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
4996
- OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
4997
- PERFORMANCE OF THIS SOFTWARE.
4998
- ***************************************************************************** */
4999
- /* global Reflect, Promise, SuppressedError, Symbol */
5000
-
5001
-
5002
- function __awaiter(thisArg, _arguments, P, generator) {
5003
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
5004
- return new (P || (P = Promise))(function (resolve, reject) {
5005
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5006
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
5007
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
5008
- step((generator = generator.apply(thisArg, _arguments || [])).next());
5009
- });
5010
- }
5011
-
5012
- typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
5013
- var e = new Error(message);
5014
- return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
5015
- };
5016
-
5017
- class Mutex {
5018
- constructor() {
5019
- this.mutex = Promise.resolve();
5020
- }
5021
- lock() {
5022
- let begin = () => { };
5023
- this.mutex = this.mutex.then(() => new Promise(begin));
5024
- return new Promise((res) => {
5025
- begin = res;
5026
- });
5027
- }
5028
- dispatch(fn) {
5029
- return __awaiter(this, void 0, void 0, function* () {
5030
- const unlock = yield this.lock();
5031
- try {
5032
- return yield Promise.resolve(fn());
5033
- }
5034
- finally {
5035
- unlock();
5036
- }
5037
- });
5038
- }
5039
- }
5040
-
5041
- /* eslint-disable import/prefer-default-export */
5042
- /* eslint-disable no-bitwise */
5043
- var _a;
5044
- function getGlobal() {
5045
- if (typeof globalThis !== 'undefined')
5046
- return globalThis;
5047
- // eslint-disable-next-line no-restricted-globals
5048
- if (typeof self !== 'undefined')
5049
- return self;
5050
- if (typeof window !== 'undefined')
5051
- return window;
5052
- return global;
5053
- }
5054
- const globalObject = getGlobal();
5055
- const nodeBuffer = (_a = globalObject.Buffer) !== null && _a !== void 0 ? _a : null;
5056
- const textEncoder = globalObject.TextEncoder ? new globalObject.TextEncoder() : null;
5057
- function hexCharCodesToInt(a, b) {
5058
- return (((a & 0xF) + ((a >> 6) | ((a >> 3) & 0x8))) << 4) | ((b & 0xF) + ((b >> 6) | ((b >> 3) & 0x8)));
5059
- }
5060
- function writeHexToUInt8(buf, str) {
5061
- const size = str.length >> 1;
5062
- for (let i = 0; i < size; i++) {
5063
- const index = i << 1;
5064
- buf[i] = hexCharCodesToInt(str.charCodeAt(index), str.charCodeAt(index + 1));
5065
- }
5066
- }
5067
- function hexStringEqualsUInt8(str, buf) {
5068
- if (str.length !== buf.length * 2) {
5069
- return false;
5070
- }
5071
- for (let i = 0; i < buf.length; i++) {
5072
- const strIndex = i << 1;
5073
- if (buf[i] !== hexCharCodesToInt(str.charCodeAt(strIndex), str.charCodeAt(strIndex + 1))) {
5074
- return false;
5075
- }
5076
- }
5077
- return true;
5078
- }
5079
- const alpha = 'a'.charCodeAt(0) - 10;
5080
- const digit = '0'.charCodeAt(0);
5081
- function getDigestHex(tmpBuffer, input, hashLength) {
5082
- let p = 0;
5083
- /* eslint-disable no-plusplus */
5084
- for (let i = 0; i < hashLength; i++) {
5085
- let nibble = input[i] >>> 4;
5086
- tmpBuffer[p++] = nibble > 9 ? nibble + alpha : nibble + digit;
5087
- nibble = input[i] & 0xF;
5088
- tmpBuffer[p++] = nibble > 9 ? nibble + alpha : nibble + digit;
5089
- }
5090
- /* eslint-enable no-plusplus */
5091
- return String.fromCharCode.apply(null, tmpBuffer);
5092
- }
5093
- const getUInt8Buffer = nodeBuffer !== null
5094
- ? (data) => {
5095
- if (typeof data === 'string') {
5096
- const buf = nodeBuffer.from(data, 'utf8');
5097
- return new Uint8Array(buf.buffer, buf.byteOffset, buf.length);
5098
- }
5099
- if (nodeBuffer.isBuffer(data)) {
5100
- return new Uint8Array(data.buffer, data.byteOffset, data.length);
5101
- }
5102
- if (ArrayBuffer.isView(data)) {
5103
- return new Uint8Array(data.buffer, data.byteOffset, data.byteLength);
5104
- }
5105
- throw new Error('Invalid data type!');
5106
- }
5107
- : (data) => {
5108
- if (typeof data === 'string') {
5109
- return textEncoder.encode(data);
5110
- }
5111
- if (ArrayBuffer.isView(data)) {
5112
- return new Uint8Array(data.buffer, data.byteOffset, data.byteLength);
5113
- }
5114
- throw new Error('Invalid data type!');
5115
- };
5116
- const base64Chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
5117
- const base64Lookup = new Uint8Array(256);
5118
- for (let i = 0; i < base64Chars.length; i++) {
5119
- base64Lookup[base64Chars.charCodeAt(i)] = i;
5120
- }
5121
- function getDecodeBase64Length(data) {
5122
- let bufferLength = Math.floor(data.length * 0.75);
5123
- const len = data.length;
5124
- if (data[len - 1] === '=') {
5125
- bufferLength -= 1;
5126
- if (data[len - 2] === '=') {
5127
- bufferLength -= 1;
5128
- }
5129
- }
5130
- return bufferLength;
5131
- }
5132
- function decodeBase64(data) {
5133
- const bufferLength = getDecodeBase64Length(data);
5134
- const len = data.length;
5135
- const bytes = new Uint8Array(bufferLength);
5136
- let p = 0;
5137
- for (let i = 0; i < len; i += 4) {
5138
- const encoded1 = base64Lookup[data.charCodeAt(i)];
5139
- const encoded2 = base64Lookup[data.charCodeAt(i + 1)];
5140
- const encoded3 = base64Lookup[data.charCodeAt(i + 2)];
5141
- const encoded4 = base64Lookup[data.charCodeAt(i + 3)];
5142
- bytes[p] = (encoded1 << 2) | (encoded2 >> 4);
5143
- p += 1;
5144
- bytes[p] = ((encoded2 & 15) << 4) | (encoded3 >> 2);
5145
- p += 1;
5146
- bytes[p] = ((encoded3 & 3) << 6) | (encoded4 & 63);
5147
- p += 1;
5148
- }
5149
- return bytes;
5150
- }
5151
-
5152
- const MAX_HEAP = 16 * 1024;
5153
- const WASM_FUNC_HASH_LENGTH = 4;
5154
- const wasmMutex = new Mutex();
5155
- const wasmModuleCache = new Map();
5156
- function WASMInterface(binary, hashLength) {
5157
- return __awaiter(this, void 0, void 0, function* () {
5158
- let wasmInstance = null;
5159
- let memoryView = null;
5160
- let initialized = false;
5161
- if (typeof WebAssembly === 'undefined') {
5162
- throw new Error('WebAssembly is not supported in this environment!');
5163
- }
5164
- const writeMemory = (data, offset = 0) => {
5165
- memoryView.set(data, offset);
5166
- };
5167
- const getMemory = () => memoryView;
5168
- const getExports = () => wasmInstance.exports;
5169
- const setMemorySize = (totalSize) => {
5170
- wasmInstance.exports.Hash_SetMemorySize(totalSize);
5171
- const arrayOffset = wasmInstance.exports.Hash_GetBuffer();
5172
- const memoryBuffer = wasmInstance.exports.memory.buffer;
5173
- memoryView = new Uint8Array(memoryBuffer, arrayOffset, totalSize);
5174
- };
5175
- const getStateSize = () => {
5176
- const view = new DataView(wasmInstance.exports.memory.buffer);
5177
- const stateSize = view.getUint32(wasmInstance.exports.STATE_SIZE, true);
5178
- return stateSize;
5179
- };
5180
- const loadWASMPromise = wasmMutex.dispatch(() => __awaiter(this, void 0, void 0, function* () {
5181
- if (!wasmModuleCache.has(binary.name)) {
5182
- const asm = decodeBase64(binary.data);
5183
- const promise = WebAssembly.compile(asm);
5184
- wasmModuleCache.set(binary.name, promise);
5185
- }
5186
- const module = yield wasmModuleCache.get(binary.name);
5187
- wasmInstance = yield WebAssembly.instantiate(module, {
5188
- // env: {
5189
- // emscripten_memcpy_big: (dest, src, num) => {
5190
- // const memoryBuffer = wasmInstance.exports.memory.buffer;
5191
- // const memView = new Uint8Array(memoryBuffer, 0);
5192
- // memView.set(memView.subarray(src, src + num), dest);
5193
- // },
5194
- // print_memory: (offset, len) => {
5195
- // const memoryBuffer = wasmInstance.exports.memory.buffer;
5196
- // const memView = new Uint8Array(memoryBuffer, 0);
5197
- // console.log('print_int32', memView.subarray(offset, offset + len));
5198
- // },
5199
- // },
5200
- });
5201
- // wasmInstance.exports._start();
5202
- }));
5203
- const setupInterface = () => __awaiter(this, void 0, void 0, function* () {
5204
- if (!wasmInstance) {
5205
- yield loadWASMPromise;
5206
- }
5207
- const arrayOffset = wasmInstance.exports.Hash_GetBuffer();
5208
- const memoryBuffer = wasmInstance.exports.memory.buffer;
5209
- memoryView = new Uint8Array(memoryBuffer, arrayOffset, MAX_HEAP);
5210
- });
5211
- const init = (bits = null) => {
5212
- initialized = true;
5213
- wasmInstance.exports.Hash_Init(bits);
5214
- };
5215
- const updateUInt8Array = (data) => {
5216
- let read = 0;
5217
- while (read < data.length) {
5218
- const chunk = data.subarray(read, read + MAX_HEAP);
5219
- read += chunk.length;
5220
- memoryView.set(chunk);
5221
- wasmInstance.exports.Hash_Update(chunk.length);
5222
- }
5223
- };
5224
- const update = (data) => {
5225
- if (!initialized) {
5226
- throw new Error('update() called before init()');
5227
- }
5228
- const Uint8Buffer = getUInt8Buffer(data);
5229
- updateUInt8Array(Uint8Buffer);
5230
- };
5231
- const digestChars = new Uint8Array(hashLength * 2);
5232
- const digest = (outputType, padding = null) => {
5233
- if (!initialized) {
5234
- throw new Error('digest() called before init()');
5235
- }
5236
- initialized = false;
5237
- wasmInstance.exports.Hash_Final(padding);
5238
- if (outputType === 'binary') {
5239
- // the data is copied to allow GC of the original memory object
5240
- return memoryView.slice(0, hashLength);
5241
- }
5242
- return getDigestHex(digestChars, memoryView, hashLength);
5243
- };
5244
- const save = () => {
5245
- if (!initialized) {
5246
- throw new Error('save() can only be called after init() and before digest()');
5247
- }
5248
- const stateOffset = wasmInstance.exports.Hash_GetState();
5249
- const stateLength = getStateSize();
5250
- const memoryBuffer = wasmInstance.exports.memory.buffer;
5251
- const internalState = new Uint8Array(memoryBuffer, stateOffset, stateLength);
5252
- // prefix is 4 bytes from SHA1 hash of the WASM binary
5253
- // it is used to detect incompatible internal states between different versions of hash-wasm
5254
- const prefixedState = new Uint8Array(WASM_FUNC_HASH_LENGTH + stateLength);
5255
- writeHexToUInt8(prefixedState, binary.hash);
5256
- prefixedState.set(internalState, WASM_FUNC_HASH_LENGTH);
5257
- return prefixedState;
5258
- };
5259
- const load = (state) => {
5260
- if (!(state instanceof Uint8Array)) {
5261
- throw new Error('load() expects an Uint8Array generated by save()');
5262
- }
5263
- const stateOffset = wasmInstance.exports.Hash_GetState();
5264
- const stateLength = getStateSize();
5265
- const overallLength = WASM_FUNC_HASH_LENGTH + stateLength;
5266
- const memoryBuffer = wasmInstance.exports.memory.buffer;
5267
- if (state.length !== overallLength) {
5268
- throw new Error(`Bad state length (expected ${overallLength} bytes, got ${state.length})`);
5269
- }
5270
- if (!hexStringEqualsUInt8(binary.hash, state.subarray(0, WASM_FUNC_HASH_LENGTH))) {
5271
- throw new Error('This state was written by an incompatible hash implementation');
5272
- }
5273
- const internalState = state.subarray(WASM_FUNC_HASH_LENGTH);
5274
- new Uint8Array(memoryBuffer, stateOffset, stateLength).set(internalState);
5275
- initialized = true;
5276
- };
5277
- const isDataShort = (data) => {
5278
- if (typeof data === 'string') {
5279
- // worst case is 4 bytes / char
5280
- return data.length < MAX_HEAP / 4;
5281
- }
5282
- return data.byteLength < MAX_HEAP;
5283
- };
5284
- let canSimplify = isDataShort;
5285
- switch (binary.name) {
5286
- case 'argon2':
5287
- case 'scrypt':
5288
- canSimplify = () => true;
5289
- break;
5290
- case 'blake2b':
5291
- case 'blake2s':
5292
- // if there is a key at blake2 then cannot simplify
5293
- canSimplify = (data, initParam) => initParam <= 512 && isDataShort(data);
5294
- break;
5295
- case 'blake3':
5296
- // if there is a key at blake3 then cannot simplify
5297
- canSimplify = (data, initParam) => initParam === 0 && isDataShort(data);
5298
- break;
5299
- case 'xxhash64': // cannot simplify
5300
- case 'xxhash3':
5301
- case 'xxhash128':
5302
- canSimplify = () => false;
5303
- break;
5304
- }
5305
- // shorthand for (init + update + digest) for better performance
5306
- const calculate = (data, initParam = null, digestParam = null) => {
5307
- if (!canSimplify(data, initParam)) {
5308
- init(initParam);
5309
- update(data);
5310
- return digest('hex', digestParam);
5311
- }
5312
- const buffer = getUInt8Buffer(data);
5313
- memoryView.set(buffer);
5314
- wasmInstance.exports.Hash_Calculate(buffer.length, initParam, digestParam);
5315
- return getDigestHex(digestChars, memoryView, hashLength);
5316
- };
5317
- yield setupInterface();
5318
- return {
5319
- getMemory,
5320
- writeMemory,
5321
- getExports,
5322
- setMemorySize,
5323
- init,
5324
- update,
5325
- digest,
5326
- save,
5327
- load,
5328
- calculate,
5329
- hashLength,
5330
- };
5331
- });
5332
- }
5333
-
5334
- new Mutex();
5335
-
5336
- new Mutex();
5337
-
5338
- new Mutex();
5339
-
5340
- new Mutex();
5341
-
5342
- new Mutex();
5343
-
5344
- new Mutex();
5345
-
5346
- new Mutex();
5347
-
5348
- new Mutex();
5349
-
5350
- new Mutex();
5351
-
5352
- var name$b = "sha3";
5353
- var data$b = "AGFzbQEAAAABFARgAAF/YAF/AGACf38AYAN/f38AAwgHAAEBAgEAAwUEAQECAgYOAn8BQZCNBQt/AEGACAsHcAgGbWVtb3J5AgAOSGFzaF9HZXRCdWZmZXIAAAlIYXNoX0luaXQAAQtIYXNoX1VwZGF0ZQACCkhhc2hfRmluYWwABA1IYXNoX0dldFN0YXRlAAUOSGFzaF9DYWxjdWxhdGUABgpTVEFURV9TSVpFAwEKqBwHBQBBgAoL1wMAQQBCADcDgI0BQQBCADcD+IwBQQBCADcD8IwBQQBCADcD6IwBQQBCADcD4IwBQQBCADcD2IwBQQBCADcD0IwBQQBCADcDyIwBQQBCADcDwIwBQQBCADcDuIwBQQBCADcDsIwBQQBCADcDqIwBQQBCADcDoIwBQQBCADcDmIwBQQBCADcDkIwBQQBCADcDiIwBQQBCADcDgIwBQQBCADcD+IsBQQBCADcD8IsBQQBCADcD6IsBQQBCADcD4IsBQQBCADcD2IsBQQBCADcD0IsBQQBCADcDyIsBQQBCADcDwIsBQQBCADcDuIsBQQBCADcDsIsBQQBCADcDqIsBQQBCADcDoIsBQQBCADcDmIsBQQBCADcDkIsBQQBCADcDiIsBQQBCADcDgIsBQQBCADcD+IoBQQBCADcD8IoBQQBCADcD6IoBQQBCADcD4IoBQQBCADcD2IoBQQBCADcD0IoBQQBCADcDyIoBQQBCADcDwIoBQQBCADcDuIoBQQBCADcDsIoBQQBCADcDqIoBQQBCADcDoIoBQQBCADcDmIoBQQBCADcDkIoBQQBCADcDiIoBQQBCADcDgIoBQQBBwAwgAEEBdGtBA3Y2AoyNAUEAQQA2AoiNAQuMAwEIfwJAQQAoAoiNASIBQQBIDQBBACABIABqQQAoAoyNASICcDYCiI0BAkACQCABDQBBgAohAwwBCwJAIAIgAWsiBCAAIAQgAEkbIgNFDQAgA0EDcSEFQQAhBgJAIANBBEkNACABQYCKAWohByADQXxxIQhBACEGA0AgByAGaiIDQcgBaiAGQYAKai0AADoAACADQckBaiAGQYEKai0AADoAACADQcoBaiAGQYIKai0AADoAACADQcsBaiAGQYMKai0AADoAACAIIAZBBGoiBkcNAAsLIAVFDQAgAUHIiwFqIQMDQCADIAZqIAZBgApqLQAAOgAAIAZBAWohBiAFQX9qIgUNAAsLIAQgAEsNAUHIiwEgAhADIAAgBGshACAEQYAKaiEDCwJAIAAgAkkNAANAIAMgAhADIAMgAmohAyAAIAJrIgAgAk8NAAsLIABFDQBBACECQcgBIQYDQCAGQYCKAWogAyAGakG4fmotAAA6AAAgBkEBaiEGIAAgAkEBaiICQf8BcUsNAAsLC+QLAS1+IAApA0AhAkEAKQPAigEhAyAAKQM4IQRBACkDuIoBIQUgACkDMCEGQQApA7CKASEHIAApAyghCEEAKQOoigEhCSAAKQMgIQpBACkDoIoBIQsgACkDGCEMQQApA5iKASENIAApAxAhDkEAKQOQigEhDyAAKQMIIRBBACkDiIoBIREgACkDACESQQApA4CKASETQQApA8iKASEUAkACQCABQcgASw0AQQApA9CKASEVQQApA+CKASEWQQApA9iKASEXDAELQQApA+CKASAAKQNghSEWQQApA9iKASAAKQNYhSEXQQApA9CKASAAKQ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QALCwsGAEGAigEL0QYBA39BAEIANwOAjQFBAEIANwP4jAFBAEIANwPwjAFBAEIANwPojAFBAEIANwPgjAFBAEIANwPYjAFBAEIANwPQjAFBAEIANwPIjAFBAEIANwPAjAFBAEIANwO4jAFBAEIANwOwjAFBAEIANwOojAFBAEIANwOgjAFBAEIANwOYjAFBAEIANwOQjAFBAEIANwOIjAFBAEIANwOAjAFBAEIANwP4iwFBAEIANwPwiwFBAEIANwPoiwFBAEIANwPgiwFBAEIANwPYiwFBAEIANwPQiwFBAEIANwPIiwFBAEIANwPAiwFBAEIANwO4iwFBAEIANwOwiwFBAEIANwOoiwFBAEIANwOgiwFBAEIANwOYiwFBAEIANwOQiwFBAEIANwOIiwFBAEIANwOAiwFBAEIANwP4igFBAEIANwPwigFBAEIANwPoigFBAEIANwPgigFBAEIANwPYigFBAEIANwPQigFBAEIANwPIigFBAEIANwPAigFBAEIANwO4igFBAEIANwOwigFBAEIANwOoigFBAEIANwOgigFBAEIANwOYigFBAEIANwOQigFBAEIANwOIigFBAEIANwOAigFBAEHADCABQQF0a0EDdjYCjI0BQQBBADYCiI0BIAAQAkHkAEEAKAKMjQEiAEEBdmshAwJAQQAoAoiNASIBQQBIDQAgACEEAkAgACABRg0AIAFByIsBaiEFQQAhAQNAIAUgAWpBADoAACABQQFqIgEgAEEAKAKIjQEiBGtJDQALCyAEQciLAWoiASABLQAAIAJyOgAAIABBx4sBaiIBIAEtAABBgAFyOgAAQciLASAAEANBAEGAgICAeDYCiI0BCwJAIANBBEkNACADQQJ2IgFBA3EhBUEAIQQCQCABQX9qQQNJDQAgAUH8////A3EhAEEAIQFBACEEA0AgAUGACmogAUGAigFqKAIANgIAIAFBhApqIAFBhIoBaigCADYCACABQYgKaiABQYiKAWooAgA2AgAgAUGMCmogAUGMigFqKAIANgIAIAFBEGohASAAIARBBGoiBEcNAAsLIAVFDQAgBUECdCEAIARBAnQhAQNAIAFBgApqIAFBgIoBaigCADYCACABQQRqIQEgAEF8aiIADQALCwsL2AEBAEGACAvQAZABAAAAAAAAAAAAAAAAAAABAAAAAAAAAIKAAAAAAAAAioAAAAAAAIAAgACAAAAAgIuAAAAAAAAAAQAAgAAAAACBgACAAAAAgAmAAAAAAACAigAAAAAAAACIAAAAAAAAAAmAAIAAAAAACgAAgAAAAACLgACAAAAAAIsAAAAAAACAiYAAAAAAAIADgAAAAAAAgAKAAAAAAACAgAAAAAAAAIAKgAAAAAAAAAoAAIAAAACAgYAAgAAAAICAgAAAAAAAgAEAAIAAAAAACIAAgAAAAIA=";
5354
- var hash$b = "f2f6f5b2";
5355
- var wasmJson$b = {
5356
- name: name$b,
5357
- data: data$b,
5358
- hash: hash$b
5359
- };
5360
-
5361
- new Mutex();
5362
-
5363
- new Mutex();
5364
- function validateBits(bits) {
5365
- if (![224, 256, 384, 512].includes(bits)) {
5366
- return new Error('Invalid variant! Valid values: 224, 256, 384, 512');
5367
- }
5368
- return null;
5369
- }
5370
- /**
5371
- * Creates a new Keccak hash instance
5372
- * @param bits Number of output bits. Valid values: 224, 256, 384, 512
5373
- */
5374
- function createKeccak(bits = 512) {
5375
- if (validateBits(bits)) {
5376
- return Promise.reject(validateBits(bits));
5377
- }
5378
- const outputSize = bits / 8;
5379
- return WASMInterface(wasmJson$b, outputSize).then((wasm) => {
5380
- wasm.init(bits);
5381
- const obj = {
5382
- init: () => { wasm.init(bits); return obj; },
5383
- update: (data) => { wasm.update(data); return obj; },
5384
- digest: (outputType) => wasm.digest(outputType, 0x01),
5385
- save: () => wasm.save(),
5386
- load: (data) => { wasm.load(data); return obj; },
5387
- blockSize: 200 - 2 * outputSize,
5388
- digestSize: outputSize,
5389
- };
5390
- return obj;
5391
- });
5392
- }
5393
-
5394
- new Mutex();
5395
-
5396
- new Mutex();
5397
-
5398
- new Mutex();
5399
-
5400
- new Mutex();
5401
-
5402
- new Mutex();
5403
-
5404
- new Mutex();
5405
-
5406
- new Mutex();
5407
-
5408
- new Mutex();
5409
-
5410
- new Mutex();
5411
-
5412
- new Mutex();
5413
-
5414
- new Mutex();
5415
-
5416
4995
  const blockchainCodecs = [
5417
4996
  {
5418
4997
  name: 'leofcoin-block',
@@ -5624,7 +5203,7 @@ class Codec extends BasicInterface {
5624
5203
  }
5625
5204
  }
5626
5205
  else if (buffer instanceof ArrayBuffer) {
5627
- const codec = index$6.decode(new Uint8Array(buffer));
5206
+ const codec = index$6.decode(buffer);
5628
5207
  const name = this.getCodecName(codec);
5629
5208
  if (name) {
5630
5209
  this.name = name;
@@ -5672,6 +5251,12 @@ class Codec extends BasicInterface {
5672
5251
  this.hashAlg = this.getHashAlg(this.name);
5673
5252
  this.codec = this.getCodec(this.name);
5674
5253
  this.codecBuffer = index$6.encode(this.codec);
5254
+ this.decoded = {
5255
+ name: this.name,
5256
+ hashAlg: this.hashAlg,
5257
+ codec: this.codec,
5258
+ codecBuffer: this.codecBuffer
5259
+ };
5675
5260
  }
5676
5261
  fromName(name) {
5677
5262
  const codec = this.getCodec(name);
@@ -5679,6 +5264,12 @@ class Codec extends BasicInterface {
5679
5264
  this.codec = codec;
5680
5265
  this.hashAlg = this.getHashAlg(name);
5681
5266
  this.codecBuffer = index$6.encode(this.codec);
5267
+ this.decoded = {
5268
+ name: this.name,
5269
+ hashAlg: this.hashAlg,
5270
+ codec: this.codec,
5271
+ codecBuffer: this.codecBuffer
5272
+ };
5682
5273
  }
5683
5274
  decode(encoded) {
5684
5275
  encoded = encoded || this.encoded;
@@ -5695,10 +5286,8 @@ class Codec extends BasicInterface {
5695
5286
 
5696
5287
  class CodecHash extends BasicInterface {
5697
5288
  codec;
5698
- codecs;
5699
- digest;
5700
- size;
5701
- constructor(buffer, options) {
5289
+ discoCodec;
5290
+ constructor(buffer, options = {}) {
5702
5291
  super();
5703
5292
  if (options.name)
5704
5293
  this.name = options.name;
@@ -5706,14 +5295,13 @@ class CodecHash extends BasicInterface {
5706
5295
  this.name = 'disco-hash';
5707
5296
  if (options.codecs)
5708
5297
  this.codecs = options.codecs;
5709
- // @ts-ignore
5710
5298
  return this.init(buffer);
5711
5299
  }
5712
5300
  async init(uint8Array) {
5713
5301
  if (uint8Array) {
5714
5302
  if (uint8Array instanceof Uint8Array) {
5715
- this.codec = new Codec(uint8Array);
5716
- const name = this.codec.name;
5303
+ this.discoCodec = new Codec(uint8Array, this.codecs);
5304
+ const name = this.discoCodec.name;
5717
5305
  if (name) {
5718
5306
  this.name = name;
5719
5307
  this.decode(uint8Array);
@@ -5739,9 +5327,9 @@ class CodecHash extends BasicInterface {
5739
5327
  }
5740
5328
  get prefix() {
5741
5329
  const length = this.length;
5742
- const uint8Array = new Uint8Array(length.length + this.codec.codecBuffer.length);
5330
+ const uint8Array = new Uint8Array(length.length + this.discoCodec.codecBuffer.length);
5743
5331
  uint8Array.set(length);
5744
- uint8Array.set(this.codec.codecBuffer, length.length);
5332
+ uint8Array.set(this.discoCodec.codecBuffer, length.length);
5745
5333
  return uint8Array;
5746
5334
  }
5747
5335
  get length() {
@@ -5761,22 +5349,29 @@ class CodecHash extends BasicInterface {
5761
5349
  this.name = name;
5762
5350
  if (!buffer)
5763
5351
  buffer = this.buffer;
5764
- this.codec = new Codec(this.name);
5765
- this.codec.fromName(this.name);
5766
- let hashAlg = this.codec.hashAlg;
5352
+ this.discoCodec = new Codec(this.name);
5353
+ this.discoCodec.fromName(this.name);
5354
+ let hashAlg = this.discoCodec.hashAlg;
5767
5355
  const hashVariant = Number(hashAlg.split('-')[hashAlg.split('-').length - 1]);
5768
5356
  if (hashAlg.includes('dbl')) {
5769
5357
  hashAlg = hashAlg.replace('dbl-', '');
5770
- const hasher = await createKeccak(hashVariant);
5771
- await hasher.init();
5772
- hasher.update(buffer);
5773
- buffer = hasher.digest('binary');
5358
+ // const hasher = await createKeccak(hashVariant)
5359
+ // await hasher.init()
5360
+ // hasher.update(buffer)
5361
+ // buffer = hasher.digest('binary')
5362
+ buffer = await crypto.subtle.digest(`SHA-${hashVariant}`, buffer);
5363
+ }
5364
+ // const hasher = await createKeccak(hashVariant)
5365
+ // await hasher.init()
5366
+ // hasher.update(buffer)
5367
+ // this.digest = hasher.digest('binary')
5368
+ this.digest = await crypto.subtle.digest(`SHA-${hashVariant}`, buffer);
5369
+ if (this.digest instanceof ArrayBuffer) {
5370
+ this.digest = new Uint8Array(this.digest);
5774
5371
  }
5775
- const hasher = await createKeccak(hashVariant);
5776
- await hasher.init();
5777
- hasher.update(buffer);
5778
- this.digest = hasher.digest('binary');
5779
5372
  this.size = this.digest.length;
5373
+ this.codec = this.discoCodec.encode();
5374
+ this.codec = this.discoCodec.codecBuffer;
5780
5375
  const uint8Array = new Uint8Array(this.digest.length + this.prefix.length);
5781
5376
  uint8Array.set(this.prefix);
5782
5377
  uint8Array.set(this.digest, this.prefix.length);
@@ -5802,19 +5397,19 @@ class CodecHash extends BasicInterface {
5802
5397
  if (typeof buffer === 'object')
5803
5398
  this.fromJSON(buffer);
5804
5399
  }
5805
- decode(encoded) {
5806
- this.encoded = encoded;
5807
- const codec = index$6.decode(encoded);
5808
- this.codec = new Codec(codec);
5400
+ decode(buffer) {
5401
+ this.encoded = buffer;
5402
+ const codec = index$6.decode(buffer);
5403
+ this.discoCodec = new Codec(codec, this.codecs);
5809
5404
  // TODO: validate codec
5810
- encoded = encoded.slice(index$6.decode.bytes);
5811
- this.size = index$6.decode(encoded);
5812
- this.digest = encoded.slice(index$6.decode.bytes);
5405
+ buffer = buffer.slice(index$6.decode.bytes);
5406
+ this.size = index$6.decode(buffer);
5407
+ this.digest = buffer.slice(index$6.decode.bytes);
5813
5408
  if (this.digest.length !== this.size) {
5814
- throw new Error(`hash length inconsistent: ${this.encoded.toString()}`);
5409
+ throw new Error(`hash length inconsistent: 0x${this.encoded.toString('hex')}`);
5815
5410
  }
5816
- // const codec = new Codec(codec, this.codecs)
5817
- this.name = this.codec.name;
5411
+ // const discoCodec = new Codec(codec, this.codecs)
5412
+ this.name = this.discoCodec.name;
5818
5413
  this.size = this.digest.length;
5819
5414
  return {
5820
5415
  codec: this.codec,
@@ -5828,6 +5423,7 @@ class CodecHash extends BasicInterface {
5828
5423
 
5829
5424
  let FormatInterface$1 = class FormatInterface extends BasicInterface {
5830
5425
  hashFormat;
5426
+ #hash;
5831
5427
  init(buffer) {
5832
5428
  if (buffer instanceof Uint8Array)
5833
5429
  this.fromUint8Array(buffer);
@@ -5859,7 +5455,7 @@ let FormatInterface$1 = class FormatInterface extends BasicInterface {
5859
5455
  }
5860
5456
  decode(encoded) {
5861
5457
  encoded = encoded || this.encoded;
5862
- const codec = new Codec(this.encoded);
5458
+ const codec = new Codec(encoded);
5863
5459
  if (codec.codecBuffer) {
5864
5460
  encoded = encoded.slice(codec.codecBuffer.length);
5865
5461
  this.name = codec.name;
@@ -5876,8 +5472,7 @@ let FormatInterface$1 = class FormatInterface extends BasicInterface {
5876
5472
  }
5877
5473
  encode(decoded) {
5878
5474
  let encoded;
5879
- if (!decoded)
5880
- decoded = this.decoded;
5475
+ decoded = decoded || this.decoded;
5881
5476
  const codec = new Codec(this.name);
5882
5477
  if (decoded instanceof Uint8Array)
5883
5478
  encoded = decoded;
@@ -5907,19 +5502,29 @@ let FormatInterface$1 = class FormatInterface extends BasicInterface {
5907
5502
  this.name = options.name;
5908
5503
  this.init(buffer);
5909
5504
  }
5505
+ get format() {
5506
+ const upper = this.hashFormat.charAt(0).toUpperCase();
5507
+ return `${upper}${this.hashFormat.substring(1, this.hashFormat.length)}`;
5508
+ }
5910
5509
  /**
5911
5510
  * @return {PeernetHash}
5912
5511
  */
5913
5512
  get peernetHash() {
5914
- return new CodecHash(this.decoded, { name: this.name });
5513
+ const decoded = this.decoded;
5514
+ // @ts-ignore
5515
+ delete decoded.hash;
5516
+ return new CodecHash(decoded, { name: this.name });
5915
5517
  }
5916
5518
  /**
5917
5519
  * @return {peernetHash}
5918
5520
  */
5919
5521
  async hash() {
5522
+ if (this.#hash)
5523
+ return this.#hash;
5920
5524
  const upper = this.hashFormat.charAt(0).toUpperCase();
5921
5525
  const format = `${upper}${this.hashFormat.substring(1, this.hashFormat.length)}`;
5922
- return (await this.peernetHash)[`to${format}`]();
5526
+ this.#hash = (await this.peernetHash)[`to${format}`]();
5527
+ return this.#hash;
5923
5528
  }
5924
5529
  fromUint8Array(buffer) {
5925
5530
  this.encoded = buffer;
@@ -5934,12 +5539,14 @@ let FormatInterface$1 = class FormatInterface extends BasicInterface {
5934
5539
  */
5935
5540
  create(data) {
5936
5541
  const decoded = {};
5542
+ if (data.hash)
5543
+ this.#hash = data.hash;
5937
5544
  if (this.keys?.length > 0) {
5938
5545
  for (const key of this.keys) {
5939
5546
  decoded[key] = data[key];
5940
5547
  }
5941
5548
  this.decoded = decoded;
5942
- return this.encode(decoded);
5549
+ // return this.encode(decoded)
5943
5550
  }
5944
5551
  }
5945
5552
  };