@meshsdk/wallet 2.0.0-beta.2 → 2.0.0-beta.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -21893,7 +21893,7 @@ var require_src = __commonJS({
21893
21893
  }).then((res) => Buffer.from(res));
21894
21894
  }
21895
21895
  exports.mnemonicToSeed = mnemonicToSeed;
21896
- function mnemonicToEntropy2(mnemonic, wordlist) {
21896
+ function mnemonicToEntropy3(mnemonic, wordlist) {
21897
21897
  wordlist = wordlist || DEFAULT_WORDLIST;
21898
21898
  if (!wordlist) {
21899
21899
  throw new Error(WORDLIST_REQUIRED);
@@ -21929,7 +21929,7 @@ var require_src = __commonJS({
21929
21929
  }
21930
21930
  return entropy.toString("hex");
21931
21931
  }
21932
- exports.mnemonicToEntropy = mnemonicToEntropy2;
21932
+ exports.mnemonicToEntropy = mnemonicToEntropy3;
21933
21933
  function entropyToMnemonic(entropy, wordlist) {
21934
21934
  if (!Buffer.isBuffer(entropy)) {
21935
21935
  entropy = Buffer.from(entropy, "hex");
@@ -21958,7 +21958,7 @@ var require_src = __commonJS({
21958
21958
  return wordlist[0] === "\u3042\u3044\u3053\u304F\u3057\u3093" ? words.join("\u3000") : words.join(" ");
21959
21959
  }
21960
21960
  exports.entropyToMnemonic = entropyToMnemonic;
21961
- function generateMnemonic(strength, rng, wordlist) {
21961
+ function generateMnemonic2(strength, rng, wordlist) {
21962
21962
  strength = strength || 128;
21963
21963
  if (strength % 32 !== 0) {
21964
21964
  throw new TypeError(INVALID_ENTROPY);
@@ -21966,10 +21966,10 @@ var require_src = __commonJS({
21966
21966
  rng = rng || ((size) => Buffer.from(utils_1.randomBytes(size)));
21967
21967
  return entropyToMnemonic(rng(strength / 8), wordlist);
21968
21968
  }
21969
- exports.generateMnemonic = generateMnemonic;
21969
+ exports.generateMnemonic = generateMnemonic2;
21970
21970
  function validateMnemonic(mnemonic, wordlist) {
21971
21971
  try {
21972
- mnemonicToEntropy2(mnemonic, wordlist);
21972
+ mnemonicToEntropy3(mnemonic, wordlist);
21973
21973
  } catch (e) {
21974
21974
  return false;
21975
21975
  }
@@ -22002,580 +22002,3906 @@ var require_src = __commonJS({
22002
22002
  }
22003
22003
  });
22004
22004
 
22005
+ // node_modules/bech32/dist/index.js
22006
+ var require_dist = __commonJS({
22007
+ "node_modules/bech32/dist/index.js"(exports) {
22008
+ "use strict";
22009
+ Object.defineProperty(exports, "__esModule", { value: true });
22010
+ exports.bech32m = exports.bech32 = void 0;
22011
+ var ALPHABET = "qpzry9x8gf2tvdw0s3jn54khce6mua7l";
22012
+ var ALPHABET_MAP = {};
22013
+ for (let z = 0; z < ALPHABET.length; z++) {
22014
+ const x = ALPHABET.charAt(z);
22015
+ ALPHABET_MAP[x] = z;
22016
+ }
22017
+ function polymodStep(pre) {
22018
+ const b = pre >> 25;
22019
+ return (pre & 33554431) << 5 ^ -(b >> 0 & 1) & 996825010 ^ -(b >> 1 & 1) & 642813549 ^ -(b >> 2 & 1) & 513874426 ^ -(b >> 3 & 1) & 1027748829 ^ -(b >> 4 & 1) & 705979059;
22020
+ }
22021
+ function prefixChk(prefix) {
22022
+ let chk = 1;
22023
+ for (let i = 0; i < prefix.length; ++i) {
22024
+ const c = prefix.charCodeAt(i);
22025
+ if (c < 33 || c > 126)
22026
+ return "Invalid prefix (" + prefix + ")";
22027
+ chk = polymodStep(chk) ^ c >> 5;
22028
+ }
22029
+ chk = polymodStep(chk);
22030
+ for (let i = 0; i < prefix.length; ++i) {
22031
+ const v = prefix.charCodeAt(i);
22032
+ chk = polymodStep(chk) ^ v & 31;
22033
+ }
22034
+ return chk;
22035
+ }
22036
+ function convert(data, inBits, outBits, pad) {
22037
+ let value = 0;
22038
+ let bits = 0;
22039
+ const maxV = (1 << outBits) - 1;
22040
+ const result = [];
22041
+ for (let i = 0; i < data.length; ++i) {
22042
+ value = value << inBits | data[i];
22043
+ bits += inBits;
22044
+ while (bits >= outBits) {
22045
+ bits -= outBits;
22046
+ result.push(value >> bits & maxV);
22047
+ }
22048
+ }
22049
+ if (pad) {
22050
+ if (bits > 0) {
22051
+ result.push(value << outBits - bits & maxV);
22052
+ }
22053
+ } else {
22054
+ if (bits >= inBits)
22055
+ return "Excess padding";
22056
+ if (value << outBits - bits & maxV)
22057
+ return "Non-zero padding";
22058
+ }
22059
+ return result;
22060
+ }
22061
+ function toWords(bytes) {
22062
+ return convert(bytes, 8, 5, true);
22063
+ }
22064
+ function fromWordsUnsafe(words) {
22065
+ const res = convert(words, 5, 8, false);
22066
+ if (Array.isArray(res))
22067
+ return res;
22068
+ }
22069
+ function fromWords(words) {
22070
+ const res = convert(words, 5, 8, false);
22071
+ if (Array.isArray(res))
22072
+ return res;
22073
+ throw new Error(res);
22074
+ }
22075
+ function getLibraryFromEncoding(encoding) {
22076
+ let ENCODING_CONST;
22077
+ if (encoding === "bech32") {
22078
+ ENCODING_CONST = 1;
22079
+ } else {
22080
+ ENCODING_CONST = 734539939;
22081
+ }
22082
+ function encode(prefix, words, LIMIT) {
22083
+ LIMIT = LIMIT || 90;
22084
+ if (prefix.length + 7 + words.length > LIMIT)
22085
+ throw new TypeError("Exceeds length limit");
22086
+ prefix = prefix.toLowerCase();
22087
+ let chk = prefixChk(prefix);
22088
+ if (typeof chk === "string")
22089
+ throw new Error(chk);
22090
+ let result = prefix + "1";
22091
+ for (let i = 0; i < words.length; ++i) {
22092
+ const x = words[i];
22093
+ if (x >> 5 !== 0)
22094
+ throw new Error("Non 5-bit word");
22095
+ chk = polymodStep(chk) ^ x;
22096
+ result += ALPHABET.charAt(x);
22097
+ }
22098
+ for (let i = 0; i < 6; ++i) {
22099
+ chk = polymodStep(chk);
22100
+ }
22101
+ chk ^= ENCODING_CONST;
22102
+ for (let i = 0; i < 6; ++i) {
22103
+ const v = chk >> (5 - i) * 5 & 31;
22104
+ result += ALPHABET.charAt(v);
22105
+ }
22106
+ return result;
22107
+ }
22108
+ function __decode(str, LIMIT) {
22109
+ LIMIT = LIMIT || 90;
22110
+ if (str.length < 8)
22111
+ return str + " too short";
22112
+ if (str.length > LIMIT)
22113
+ return "Exceeds length limit";
22114
+ const lowered = str.toLowerCase();
22115
+ const uppered = str.toUpperCase();
22116
+ if (str !== lowered && str !== uppered)
22117
+ return "Mixed-case string " + str;
22118
+ str = lowered;
22119
+ const split = str.lastIndexOf("1");
22120
+ if (split === -1)
22121
+ return "No separator character for " + str;
22122
+ if (split === 0)
22123
+ return "Missing prefix for " + str;
22124
+ const prefix = str.slice(0, split);
22125
+ const wordChars = str.slice(split + 1);
22126
+ if (wordChars.length < 6)
22127
+ return "Data too short";
22128
+ let chk = prefixChk(prefix);
22129
+ if (typeof chk === "string")
22130
+ return chk;
22131
+ const words = [];
22132
+ for (let i = 0; i < wordChars.length; ++i) {
22133
+ const c = wordChars.charAt(i);
22134
+ const v = ALPHABET_MAP[c];
22135
+ if (v === void 0)
22136
+ return "Unknown character " + c;
22137
+ chk = polymodStep(chk) ^ v;
22138
+ if (i + 6 >= wordChars.length)
22139
+ continue;
22140
+ words.push(v);
22141
+ }
22142
+ if (chk !== ENCODING_CONST)
22143
+ return "Invalid checksum for " + str;
22144
+ return { prefix, words };
22145
+ }
22146
+ function decodeUnsafe(str, LIMIT) {
22147
+ const res = __decode(str, LIMIT);
22148
+ if (typeof res === "object")
22149
+ return res;
22150
+ }
22151
+ function decode(str, LIMIT) {
22152
+ const res = __decode(str, LIMIT);
22153
+ if (typeof res === "object")
22154
+ return res;
22155
+ throw new Error(res);
22156
+ }
22157
+ return {
22158
+ decodeUnsafe,
22159
+ decode,
22160
+ encode,
22161
+ toWords,
22162
+ fromWordsUnsafe,
22163
+ fromWords
22164
+ };
22165
+ }
22166
+ exports.bech32 = getLibraryFromEncoding("bech32");
22167
+ exports.bech32m = getLibraryFromEncoding("bech32m");
22168
+ }
22169
+ });
22170
+
22171
+ // node_modules/nanoassert/index.js
22172
+ var require_nanoassert = __commonJS({
22173
+ "node_modules/nanoassert/index.js"(exports, module) {
22174
+ module.exports = assert;
22175
+ var AssertionError = class extends Error {
22176
+ };
22177
+ AssertionError.prototype.name = "AssertionError";
22178
+ function assert(t, m) {
22179
+ if (!t) {
22180
+ var err = new AssertionError(m);
22181
+ if (Error.captureStackTrace) Error.captureStackTrace(err, assert);
22182
+ throw err;
22183
+ }
22184
+ }
22185
+ }
22186
+ });
22187
+
22188
+ // node_modules/b4a/index.js
22189
+ var require_b4a = __commonJS({
22190
+ "node_modules/b4a/index.js"(exports, module) {
22191
+ function isBuffer(value) {
22192
+ return Buffer.isBuffer(value) || value instanceof Uint8Array;
22193
+ }
22194
+ function isEncoding(encoding) {
22195
+ return Buffer.isEncoding(encoding);
22196
+ }
22197
+ function alloc(size, fill2, encoding) {
22198
+ return Buffer.alloc(size, fill2, encoding);
22199
+ }
22200
+ function allocUnsafe(size) {
22201
+ return Buffer.allocUnsafe(size);
22202
+ }
22203
+ function allocUnsafeSlow(size) {
22204
+ return Buffer.allocUnsafeSlow(size);
22205
+ }
22206
+ function byteLength(string, encoding) {
22207
+ return Buffer.byteLength(string, encoding);
22208
+ }
22209
+ function compare(a, b) {
22210
+ return Buffer.compare(a, b);
22211
+ }
22212
+ function concat(buffers, totalLength) {
22213
+ return Buffer.concat(buffers, totalLength);
22214
+ }
22215
+ function copy(source, target, targetStart, start, end) {
22216
+ return toBuffer(source).copy(target, targetStart, start, end);
22217
+ }
22218
+ function equals(a, b) {
22219
+ return toBuffer(a).equals(b);
22220
+ }
22221
+ function fill(buffer, value, offset, end, encoding) {
22222
+ return toBuffer(buffer).fill(value, offset, end, encoding);
22223
+ }
22224
+ function from(value, encodingOrOffset, length) {
22225
+ return Buffer.from(value, encodingOrOffset, length);
22226
+ }
22227
+ function includes(buffer, value, byteOffset, encoding) {
22228
+ return toBuffer(buffer).includes(value, byteOffset, encoding);
22229
+ }
22230
+ function indexOf(buffer, value, byfeOffset, encoding) {
22231
+ return toBuffer(buffer).indexOf(value, byfeOffset, encoding);
22232
+ }
22233
+ function lastIndexOf(buffer, value, byteOffset, encoding) {
22234
+ return toBuffer(buffer).lastIndexOf(value, byteOffset, encoding);
22235
+ }
22236
+ function swap16(buffer) {
22237
+ return toBuffer(buffer).swap16();
22238
+ }
22239
+ function swap32(buffer) {
22240
+ return toBuffer(buffer).swap32();
22241
+ }
22242
+ function swap64(buffer) {
22243
+ return toBuffer(buffer).swap64();
22244
+ }
22245
+ function toBuffer(buffer) {
22246
+ if (Buffer.isBuffer(buffer)) return buffer;
22247
+ return Buffer.from(buffer.buffer, buffer.byteOffset, buffer.byteLength);
22248
+ }
22249
+ function toString(buffer, encoding, start, end) {
22250
+ return toBuffer(buffer).toString(encoding, start, end);
22251
+ }
22252
+ function write(buffer, string, offset, length, encoding) {
22253
+ return toBuffer(buffer).write(string, offset, length, encoding);
22254
+ }
22255
+ function readDoubleBE(buffer, offset) {
22256
+ return toBuffer(buffer).readDoubleBE(offset);
22257
+ }
22258
+ function readDoubleLE(buffer, offset) {
22259
+ return toBuffer(buffer).readDoubleLE(offset);
22260
+ }
22261
+ function readFloatBE(buffer, offset) {
22262
+ return toBuffer(buffer).readFloatBE(offset);
22263
+ }
22264
+ function readFloatLE(buffer, offset) {
22265
+ return toBuffer(buffer).readFloatLE(offset);
22266
+ }
22267
+ function readInt32BE(buffer, offset) {
22268
+ return toBuffer(buffer).readInt32BE(offset);
22269
+ }
22270
+ function readInt32LE(buffer, offset) {
22271
+ return toBuffer(buffer).readInt32LE(offset);
22272
+ }
22273
+ function readUInt32BE(buffer, offset) {
22274
+ return toBuffer(buffer).readUInt32BE(offset);
22275
+ }
22276
+ function readUInt32LE(buffer, offset) {
22277
+ return toBuffer(buffer).readUInt32LE(offset);
22278
+ }
22279
+ function writeDoubleBE(buffer, value, offset) {
22280
+ return toBuffer(buffer).writeDoubleBE(value, offset);
22281
+ }
22282
+ function writeDoubleLE(buffer, value, offset) {
22283
+ return toBuffer(buffer).writeDoubleLE(value, offset);
22284
+ }
22285
+ function writeFloatBE(buffer, value, offset) {
22286
+ return toBuffer(buffer).writeFloatBE(value, offset);
22287
+ }
22288
+ function writeFloatLE(buffer, value, offset) {
22289
+ return toBuffer(buffer).writeFloatLE(value, offset);
22290
+ }
22291
+ function writeInt32BE(buffer, value, offset) {
22292
+ return toBuffer(buffer).writeInt32BE(value, offset);
22293
+ }
22294
+ function writeInt32LE(buffer, value, offset) {
22295
+ return toBuffer(buffer).writeInt32LE(value, offset);
22296
+ }
22297
+ function writeUInt32BE(buffer, value, offset) {
22298
+ return toBuffer(buffer).writeUInt32BE(value, offset);
22299
+ }
22300
+ function writeUInt32LE(buffer, value, offset) {
22301
+ return toBuffer(buffer).writeUInt32LE(value, offset);
22302
+ }
22303
+ module.exports = {
22304
+ isBuffer,
22305
+ isEncoding,
22306
+ alloc,
22307
+ allocUnsafe,
22308
+ allocUnsafeSlow,
22309
+ byteLength,
22310
+ compare,
22311
+ concat,
22312
+ copy,
22313
+ equals,
22314
+ fill,
22315
+ from,
22316
+ includes,
22317
+ indexOf,
22318
+ lastIndexOf,
22319
+ swap16,
22320
+ swap32,
22321
+ swap64,
22322
+ toBuffer,
22323
+ toString,
22324
+ write,
22325
+ readDoubleBE,
22326
+ readDoubleLE,
22327
+ readFloatBE,
22328
+ readFloatLE,
22329
+ readInt32BE,
22330
+ readInt32LE,
22331
+ readUInt32BE,
22332
+ readUInt32LE,
22333
+ writeDoubleBE,
22334
+ writeDoubleLE,
22335
+ writeFloatBE,
22336
+ writeFloatLE,
22337
+ writeInt32BE,
22338
+ writeInt32LE,
22339
+ writeUInt32BE,
22340
+ writeUInt32LE
22341
+ };
22342
+ }
22343
+ });
22344
+
22345
+ // node_modules/blake2b-wasm/blake2b.js
22346
+ var require_blake2b = __commonJS({
22347
+ "node_modules/blake2b-wasm/blake2b.js"(exports, module) {
22348
+ var __commonJS2 = (cb, mod) => function __require2() {
22349
+ return mod || (0, cb[Object.keys(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
22350
+ };
22351
+ var __toBinary = /* @__PURE__ */ (() => {
22352
+ var table = new Uint8Array(128);
22353
+ for (var i = 0; i < 64; i++)
22354
+ table[i < 26 ? i + 65 : i < 52 ? i + 71 : i < 62 ? i - 4 : i * 4 - 205] = i;
22355
+ return (base64) => {
22356
+ var n = base64.length, bytes2 = new Uint8Array((n - (base64[n - 1] == "=") - (base64[n - 2] == "=")) * 3 / 4 | 0);
22357
+ for (var i2 = 0, j = 0; i2 < n; ) {
22358
+ var c0 = table[base64.charCodeAt(i2++)], c1 = table[base64.charCodeAt(i2++)];
22359
+ var c2 = table[base64.charCodeAt(i2++)], c3 = table[base64.charCodeAt(i2++)];
22360
+ bytes2[j++] = c0 << 2 | c1 >> 4;
22361
+ bytes2[j++] = c1 << 4 | c2 >> 2;
22362
+ bytes2[j++] = c2 << 6 | c3;
22363
+ }
22364
+ return bytes2;
22365
+ };
22366
+ })();
22367
+ var require_blake2b4 = __commonJS2({
22368
+ "wasm-binary:./blake2b.wat"(exports2, module2) {
22369
+ module2.exports = __toBinary("AGFzbQEAAAABEANgAn9/AGADf39/AGABfwADBQQAAQICBQUBAQroBwdNBQZtZW1vcnkCAAxibGFrZTJiX2luaXQAAA5ibGFrZTJiX3VwZGF0ZQABDWJsYWtlMmJfZmluYWwAAhBibGFrZTJiX2NvbXByZXNzAAMKvz8EwAIAIABCADcDACAAQgA3AwggAEIANwMQIABCADcDGCAAQgA3AyAgAEIANwMoIABCADcDMCAAQgA3AzggAEIANwNAIABCADcDSCAAQgA3A1AgAEIANwNYIABCADcDYCAAQgA3A2ggAEIANwNwIABCADcDeCAAQoiS853/zPmE6gBBACkDAIU3A4ABIABCu86qptjQ67O7f0EIKQMAhTcDiAEgAEKr8NP0r+68tzxBECkDAIU3A5ABIABC8e30+KWn/aelf0EYKQMAhTcDmAEgAELRhZrv+s+Uh9EAQSApAwCFNwOgASAAQp/Y+dnCkdqCm39BKCkDAIU3A6gBIABC6/qG2r+19sEfQTApAwCFNwOwASAAQvnC+JuRo7Pw2wBBOCkDAIU3A7gB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KIQggBCAIIBd8fCEEIBAgBIVCEIohECAMIBB8IQwgCCAMhUI/iiEIIAEgBiASfHwhASAQIAGFQiCKIRAgCyAQfCELIAYgC4VCGIohBiABIAYgHXx8IQEgECABhUIQiiEQIAsgEHwhCyAGIAuFQj+KIQYgAiAHIBF8fCECIA0gAoVCIIohDSAMIA18IQwgByAMhUIYiiEHIAIgByATfHwhAiANIAKFQhCKIQ0gDCANfCEMIAcgDIVCP4ohByADIAggHHx8IQMgDiADhUIgiiEOIAkgDnwhCSAIIAmFQhiKIQggAyAIIBh8fCEDIA4gA4VCEIohDiAJIA58IQkgCCAJhUI/iiEIIAQgBSAWfHwhBCAPIASFQiCKIQ8gCiAPfCEKIAUgCoVCGIohBSAEIAUgFHx8IQQgDyAEhUIQiiEPIAogD3whCiAFIAqFQj+KIQUgISAhKQMAIAEgCYWFNwMAICIgIikDACACIAqFhTcDACAjICMpAwAgAyALhYU3AwAgJCAkKQMAIAQgDIWFNwMAICUgJSkDACAFIA2FhTcDACAmICYpAwAgBiAOhYU3AwAgJyAnKQMAIAcgD4WFNwMAICggKCkDACAIIBCFhTcDAAs=");
22370
+ }
22371
+ });
22372
+ var bytes = require_blake2b4();
22373
+ var compiled = WebAssembly.compile(bytes);
22374
+ module.exports = async (imports) => {
22375
+ const instance = await WebAssembly.instantiate(await compiled, imports);
22376
+ return instance.exports;
22377
+ };
22378
+ }
22379
+ });
22380
+
22381
+ // node_modules/blake2b-wasm/index.js
22382
+ var require_blake2b_wasm = __commonJS({
22383
+ "node_modules/blake2b-wasm/index.js"(exports, module) {
22384
+ var assert = require_nanoassert();
22385
+ var b4a = require_b4a();
22386
+ var wasm = null;
22387
+ var wasmPromise = typeof WebAssembly !== "undefined" && require_blake2b()().then((mod) => {
22388
+ wasm = mod;
22389
+ });
22390
+ var head = 64;
22391
+ var freeList = [];
22392
+ module.exports = Blake2b;
22393
+ var BYTES_MIN = module.exports.BYTES_MIN = 16;
22394
+ var BYTES_MAX = module.exports.BYTES_MAX = 64;
22395
+ var BYTES = module.exports.BYTES = 32;
22396
+ var KEYBYTES_MIN = module.exports.KEYBYTES_MIN = 16;
22397
+ var KEYBYTES_MAX = module.exports.KEYBYTES_MAX = 64;
22398
+ var KEYBYTES = module.exports.KEYBYTES = 32;
22399
+ var SALTBYTES = module.exports.SALTBYTES = 16;
22400
+ var PERSONALBYTES = module.exports.PERSONALBYTES = 16;
22401
+ function Blake2b(digestLength, key, salt, personal, noAssert) {
22402
+ if (!(this instanceof Blake2b)) return new Blake2b(digestLength, key, salt, personal, noAssert);
22403
+ if (!wasm) throw new Error("WASM not loaded. Wait for Blake2b.ready(cb)");
22404
+ if (!digestLength) digestLength = 32;
22405
+ if (noAssert !== true) {
22406
+ assert(digestLength >= BYTES_MIN, "digestLength must be at least " + BYTES_MIN + ", was given " + digestLength);
22407
+ assert(digestLength <= BYTES_MAX, "digestLength must be at most " + BYTES_MAX + ", was given " + digestLength);
22408
+ if (key != null) {
22409
+ assert(key instanceof Uint8Array, "key must be Uint8Array or Buffer");
22410
+ assert(key.length >= KEYBYTES_MIN, "key must be at least " + KEYBYTES_MIN + ", was given " + key.length);
22411
+ assert(key.length <= KEYBYTES_MAX, "key must be at least " + KEYBYTES_MAX + ", was given " + key.length);
22412
+ }
22413
+ if (salt != null) {
22414
+ assert(salt instanceof Uint8Array, "salt must be Uint8Array or Buffer");
22415
+ assert(salt.length === SALTBYTES, "salt must be exactly " + SALTBYTES + ", was given " + salt.length);
22416
+ }
22417
+ if (personal != null) {
22418
+ assert(personal instanceof Uint8Array, "personal must be Uint8Array or Buffer");
22419
+ assert(personal.length === PERSONALBYTES, "personal must be exactly " + PERSONALBYTES + ", was given " + personal.length);
22420
+ }
22421
+ }
22422
+ if (!freeList.length) {
22423
+ freeList.push(head);
22424
+ head += 216;
22425
+ }
22426
+ this.digestLength = digestLength;
22427
+ this.finalized = false;
22428
+ this.pointer = freeList.pop();
22429
+ this._memory = new Uint8Array(wasm.memory.buffer);
22430
+ this._memory.fill(0, 0, 64);
22431
+ this._memory[0] = this.digestLength;
22432
+ this._memory[1] = key ? key.length : 0;
22433
+ this._memory[2] = 1;
22434
+ this._memory[3] = 1;
22435
+ if (salt) this._memory.set(salt, 32);
22436
+ if (personal) this._memory.set(personal, 48);
22437
+ if (this.pointer + 216 > this._memory.length) this._realloc(this.pointer + 216);
22438
+ wasm.blake2b_init(this.pointer, this.digestLength);
22439
+ if (key) {
22440
+ this.update(key);
22441
+ this._memory.fill(0, head, head + key.length);
22442
+ this._memory[this.pointer + 200] = 128;
22443
+ }
22444
+ }
22445
+ Blake2b.prototype._realloc = function(size) {
22446
+ wasm.memory.grow(Math.max(0, Math.ceil(Math.abs(size - this._memory.length) / 65536)));
22447
+ this._memory = new Uint8Array(wasm.memory.buffer);
22448
+ };
22449
+ Blake2b.prototype.update = function(input) {
22450
+ assert(this.finalized === false, "Hash instance finalized");
22451
+ assert(input instanceof Uint8Array, "input must be Uint8Array or Buffer");
22452
+ if (head + input.length > this._memory.length) this._realloc(head + input.length);
22453
+ this._memory.set(input, head);
22454
+ wasm.blake2b_update(this.pointer, head, head + input.length);
22455
+ return this;
22456
+ };
22457
+ Blake2b.prototype.digest = function(enc) {
22458
+ assert(this.finalized === false, "Hash instance finalized");
22459
+ this.finalized = true;
22460
+ freeList.push(this.pointer);
22461
+ wasm.blake2b_final(this.pointer);
22462
+ if (!enc || enc === "binary") {
22463
+ return this._memory.slice(this.pointer + 128, this.pointer + 128 + this.digestLength);
22464
+ }
22465
+ if (typeof enc === "string") {
22466
+ return b4a.toString(this._memory, enc, this.pointer + 128, this.pointer + 128 + this.digestLength);
22467
+ }
22468
+ assert(enc instanceof Uint8Array && enc.length >= this.digestLength, "input must be Uint8Array or Buffer");
22469
+ for (var i = 0; i < this.digestLength; i++) {
22470
+ enc[i] = this._memory[this.pointer + 128 + i];
22471
+ }
22472
+ return enc;
22473
+ };
22474
+ Blake2b.prototype.final = Blake2b.prototype.digest;
22475
+ Blake2b.WASM = wasm;
22476
+ Blake2b.SUPPORTED = typeof WebAssembly !== "undefined";
22477
+ Blake2b.ready = function(cb) {
22478
+ if (!cb) cb = noop;
22479
+ if (!wasmPromise) return cb(new Error("WebAssembly not supported"));
22480
+ return wasmPromise.then(() => cb(), cb);
22481
+ };
22482
+ Blake2b.prototype.ready = Blake2b.ready;
22483
+ Blake2b.prototype.getPartialHash = function() {
22484
+ return this._memory.slice(this.pointer, this.pointer + 216);
22485
+ };
22486
+ Blake2b.prototype.setPartialHash = function(ph) {
22487
+ this._memory.set(ph, this.pointer);
22488
+ };
22489
+ function noop() {
22490
+ }
22491
+ }
22492
+ });
22493
+
22494
+ // node_modules/blake2b/index.js
22495
+ var require_blake2b2 = __commonJS({
22496
+ "node_modules/blake2b/index.js"(exports, module) {
22497
+ var assert = require_nanoassert();
22498
+ var b2wasm = require_blake2b_wasm();
22499
+ function ADD64AA(v2, a, b) {
22500
+ var o0 = v2[a] + v2[b];
22501
+ var o1 = v2[a + 1] + v2[b + 1];
22502
+ if (o0 >= 4294967296) {
22503
+ o1++;
22504
+ }
22505
+ v2[a] = o0;
22506
+ v2[a + 1] = o1;
22507
+ }
22508
+ function ADD64AC(v2, a, b0, b1) {
22509
+ var o0 = v2[a] + b0;
22510
+ if (b0 < 0) {
22511
+ o0 += 4294967296;
22512
+ }
22513
+ var o1 = v2[a + 1] + b1;
22514
+ if (o0 >= 4294967296) {
22515
+ o1++;
22516
+ }
22517
+ v2[a] = o0;
22518
+ v2[a + 1] = o1;
22519
+ }
22520
+ function B2B_GET32(arr, i) {
22521
+ return arr[i] ^ arr[i + 1] << 8 ^ arr[i + 2] << 16 ^ arr[i + 3] << 24;
22522
+ }
22523
+ function B2B_G(a, b, c, d, ix, iy) {
22524
+ var x0 = m[ix];
22525
+ var x1 = m[ix + 1];
22526
+ var y0 = m[iy];
22527
+ var y1 = m[iy + 1];
22528
+ ADD64AA(v, a, b);
22529
+ ADD64AC(v, a, x0, x1);
22530
+ var xor0 = v[d] ^ v[a];
22531
+ var xor1 = v[d + 1] ^ v[a + 1];
22532
+ v[d] = xor1;
22533
+ v[d + 1] = xor0;
22534
+ ADD64AA(v, c, d);
22535
+ xor0 = v[b] ^ v[c];
22536
+ xor1 = v[b + 1] ^ v[c + 1];
22537
+ v[b] = xor0 >>> 24 ^ xor1 << 8;
22538
+ v[b + 1] = xor1 >>> 24 ^ xor0 << 8;
22539
+ ADD64AA(v, a, b);
22540
+ ADD64AC(v, a, y0, y1);
22541
+ xor0 = v[d] ^ v[a];
22542
+ xor1 = v[d + 1] ^ v[a + 1];
22543
+ v[d] = xor0 >>> 16 ^ xor1 << 16;
22544
+ v[d + 1] = xor1 >>> 16 ^ xor0 << 16;
22545
+ ADD64AA(v, c, d);
22546
+ xor0 = v[b] ^ v[c];
22547
+ xor1 = v[b + 1] ^ v[c + 1];
22548
+ v[b] = xor1 >>> 31 ^ xor0 << 1;
22549
+ v[b + 1] = xor0 >>> 31 ^ xor1 << 1;
22550
+ }
22551
+ var BLAKE2B_IV32 = new Uint32Array([
22552
+ 4089235720,
22553
+ 1779033703,
22554
+ 2227873595,
22555
+ 3144134277,
22556
+ 4271175723,
22557
+ 1013904242,
22558
+ 1595750129,
22559
+ 2773480762,
22560
+ 2917565137,
22561
+ 1359893119,
22562
+ 725511199,
22563
+ 2600822924,
22564
+ 4215389547,
22565
+ 528734635,
22566
+ 327033209,
22567
+ 1541459225
22568
+ ]);
22569
+ var SIGMA8 = [
22570
+ 0,
22571
+ 1,
22572
+ 2,
22573
+ 3,
22574
+ 4,
22575
+ 5,
22576
+ 6,
22577
+ 7,
22578
+ 8,
22579
+ 9,
22580
+ 10,
22581
+ 11,
22582
+ 12,
22583
+ 13,
22584
+ 14,
22585
+ 15,
22586
+ 14,
22587
+ 10,
22588
+ 4,
22589
+ 8,
22590
+ 9,
22591
+ 15,
22592
+ 13,
22593
+ 6,
22594
+ 1,
22595
+ 12,
22596
+ 0,
22597
+ 2,
22598
+ 11,
22599
+ 7,
22600
+ 5,
22601
+ 3,
22602
+ 11,
22603
+ 8,
22604
+ 12,
22605
+ 0,
22606
+ 5,
22607
+ 2,
22608
+ 15,
22609
+ 13,
22610
+ 10,
22611
+ 14,
22612
+ 3,
22613
+ 6,
22614
+ 7,
22615
+ 1,
22616
+ 9,
22617
+ 4,
22618
+ 7,
22619
+ 9,
22620
+ 3,
22621
+ 1,
22622
+ 13,
22623
+ 12,
22624
+ 11,
22625
+ 14,
22626
+ 2,
22627
+ 6,
22628
+ 5,
22629
+ 10,
22630
+ 4,
22631
+ 0,
22632
+ 15,
22633
+ 8,
22634
+ 9,
22635
+ 0,
22636
+ 5,
22637
+ 7,
22638
+ 2,
22639
+ 4,
22640
+ 10,
22641
+ 15,
22642
+ 14,
22643
+ 1,
22644
+ 11,
22645
+ 12,
22646
+ 6,
22647
+ 8,
22648
+ 3,
22649
+ 13,
22650
+ 2,
22651
+ 12,
22652
+ 6,
22653
+ 10,
22654
+ 0,
22655
+ 11,
22656
+ 8,
22657
+ 3,
22658
+ 4,
22659
+ 13,
22660
+ 7,
22661
+ 5,
22662
+ 15,
22663
+ 14,
22664
+ 1,
22665
+ 9,
22666
+ 12,
22667
+ 5,
22668
+ 1,
22669
+ 15,
22670
+ 14,
22671
+ 13,
22672
+ 4,
22673
+ 10,
22674
+ 0,
22675
+ 7,
22676
+ 6,
22677
+ 3,
22678
+ 9,
22679
+ 2,
22680
+ 8,
22681
+ 11,
22682
+ 13,
22683
+ 11,
22684
+ 7,
22685
+ 14,
22686
+ 12,
22687
+ 1,
22688
+ 3,
22689
+ 9,
22690
+ 5,
22691
+ 0,
22692
+ 15,
22693
+ 4,
22694
+ 8,
22695
+ 6,
22696
+ 2,
22697
+ 10,
22698
+ 6,
22699
+ 15,
22700
+ 14,
22701
+ 9,
22702
+ 11,
22703
+ 3,
22704
+ 0,
22705
+ 8,
22706
+ 12,
22707
+ 2,
22708
+ 13,
22709
+ 7,
22710
+ 1,
22711
+ 4,
22712
+ 10,
22713
+ 5,
22714
+ 10,
22715
+ 2,
22716
+ 8,
22717
+ 4,
22718
+ 7,
22719
+ 6,
22720
+ 1,
22721
+ 5,
22722
+ 15,
22723
+ 11,
22724
+ 9,
22725
+ 14,
22726
+ 3,
22727
+ 12,
22728
+ 13,
22729
+ 0,
22730
+ 0,
22731
+ 1,
22732
+ 2,
22733
+ 3,
22734
+ 4,
22735
+ 5,
22736
+ 6,
22737
+ 7,
22738
+ 8,
22739
+ 9,
22740
+ 10,
22741
+ 11,
22742
+ 12,
22743
+ 13,
22744
+ 14,
22745
+ 15,
22746
+ 14,
22747
+ 10,
22748
+ 4,
22749
+ 8,
22750
+ 9,
22751
+ 15,
22752
+ 13,
22753
+ 6,
22754
+ 1,
22755
+ 12,
22756
+ 0,
22757
+ 2,
22758
+ 11,
22759
+ 7,
22760
+ 5,
22761
+ 3
22762
+ ];
22763
+ var SIGMA82 = new Uint8Array(SIGMA8.map(function(x) {
22764
+ return x * 2;
22765
+ }));
22766
+ var v = new Uint32Array(32);
22767
+ var m = new Uint32Array(32);
22768
+ function blake2bCompress(ctx, last) {
22769
+ var i = 0;
22770
+ for (i = 0; i < 16; i++) {
22771
+ v[i] = ctx.h[i];
22772
+ v[i + 16] = BLAKE2B_IV32[i];
22773
+ }
22774
+ v[24] = v[24] ^ ctx.t;
22775
+ v[25] = v[25] ^ ctx.t / 4294967296;
22776
+ if (last) {
22777
+ v[28] = ~v[28];
22778
+ v[29] = ~v[29];
22779
+ }
22780
+ for (i = 0; i < 32; i++) {
22781
+ m[i] = B2B_GET32(ctx.b, 4 * i);
22782
+ }
22783
+ for (i = 0; i < 12; i++) {
22784
+ B2B_G(0, 8, 16, 24, SIGMA82[i * 16 + 0], SIGMA82[i * 16 + 1]);
22785
+ B2B_G(2, 10, 18, 26, SIGMA82[i * 16 + 2], SIGMA82[i * 16 + 3]);
22786
+ B2B_G(4, 12, 20, 28, SIGMA82[i * 16 + 4], SIGMA82[i * 16 + 5]);
22787
+ B2B_G(6, 14, 22, 30, SIGMA82[i * 16 + 6], SIGMA82[i * 16 + 7]);
22788
+ B2B_G(0, 10, 20, 30, SIGMA82[i * 16 + 8], SIGMA82[i * 16 + 9]);
22789
+ B2B_G(2, 12, 22, 24, SIGMA82[i * 16 + 10], SIGMA82[i * 16 + 11]);
22790
+ B2B_G(4, 14, 16, 26, SIGMA82[i * 16 + 12], SIGMA82[i * 16 + 13]);
22791
+ B2B_G(6, 8, 18, 28, SIGMA82[i * 16 + 14], SIGMA82[i * 16 + 15]);
22792
+ }
22793
+ for (i = 0; i < 16; i++) {
22794
+ ctx.h[i] = ctx.h[i] ^ v[i] ^ v[i + 16];
22795
+ }
22796
+ }
22797
+ var parameter_block = new Uint8Array([
22798
+ 0,
22799
+ 0,
22800
+ 0,
22801
+ 0,
22802
+ // 0: outlen, keylen, fanout, depth
22803
+ 0,
22804
+ 0,
22805
+ 0,
22806
+ 0,
22807
+ // 4: leaf length, sequential mode
22808
+ 0,
22809
+ 0,
22810
+ 0,
22811
+ 0,
22812
+ // 8: node offset
22813
+ 0,
22814
+ 0,
22815
+ 0,
22816
+ 0,
22817
+ // 12: node offset
22818
+ 0,
22819
+ 0,
22820
+ 0,
22821
+ 0,
22822
+ // 16: node depth, inner length, rfu
22823
+ 0,
22824
+ 0,
22825
+ 0,
22826
+ 0,
22827
+ // 20: rfu
22828
+ 0,
22829
+ 0,
22830
+ 0,
22831
+ 0,
22832
+ // 24: rfu
22833
+ 0,
22834
+ 0,
22835
+ 0,
22836
+ 0,
22837
+ // 28: rfu
22838
+ 0,
22839
+ 0,
22840
+ 0,
22841
+ 0,
22842
+ // 32: salt
22843
+ 0,
22844
+ 0,
22845
+ 0,
22846
+ 0,
22847
+ // 36: salt
22848
+ 0,
22849
+ 0,
22850
+ 0,
22851
+ 0,
22852
+ // 40: salt
22853
+ 0,
22854
+ 0,
22855
+ 0,
22856
+ 0,
22857
+ // 44: salt
22858
+ 0,
22859
+ 0,
22860
+ 0,
22861
+ 0,
22862
+ // 48: personal
22863
+ 0,
22864
+ 0,
22865
+ 0,
22866
+ 0,
22867
+ // 52: personal
22868
+ 0,
22869
+ 0,
22870
+ 0,
22871
+ 0,
22872
+ // 56: personal
22873
+ 0,
22874
+ 0,
22875
+ 0,
22876
+ 0
22877
+ // 60: personal
22878
+ ]);
22879
+ function Blake2b(outlen, key, salt, personal) {
22880
+ parameter_block.fill(0);
22881
+ this.b = new Uint8Array(128);
22882
+ this.h = new Uint32Array(16);
22883
+ this.t = 0;
22884
+ this.c = 0;
22885
+ this.outlen = outlen;
22886
+ parameter_block[0] = outlen;
22887
+ if (key) parameter_block[1] = key.length;
22888
+ parameter_block[2] = 1;
22889
+ parameter_block[3] = 1;
22890
+ if (salt) parameter_block.set(salt, 32);
22891
+ if (personal) parameter_block.set(personal, 48);
22892
+ for (var i = 0; i < 16; i++) {
22893
+ this.h[i] = BLAKE2B_IV32[i] ^ B2B_GET32(parameter_block, i * 4);
22894
+ }
22895
+ if (key) {
22896
+ blake2bUpdate(this, key);
22897
+ this.c = 128;
22898
+ }
22899
+ }
22900
+ Blake2b.prototype.update = function(input) {
22901
+ assert(input instanceof Uint8Array, "input must be Uint8Array or Buffer");
22902
+ blake2bUpdate(this, input);
22903
+ return this;
22904
+ };
22905
+ Blake2b.prototype.digest = function(out) {
22906
+ var buf = !out || out === "binary" || out === "hex" ? new Uint8Array(this.outlen) : out;
22907
+ assert(buf instanceof Uint8Array, 'out must be "binary", "hex", Uint8Array, or Buffer');
22908
+ assert(buf.length >= this.outlen, "out must have at least outlen bytes of space");
22909
+ blake2bFinal(this, buf);
22910
+ if (out === "hex") return hexSlice(buf);
22911
+ return buf;
22912
+ };
22913
+ Blake2b.prototype.final = Blake2b.prototype.digest;
22914
+ Blake2b.ready = function(cb) {
22915
+ b2wasm.ready(function() {
22916
+ cb();
22917
+ });
22918
+ };
22919
+ function blake2bUpdate(ctx, input) {
22920
+ for (var i = 0; i < input.length; i++) {
22921
+ if (ctx.c === 128) {
22922
+ ctx.t += ctx.c;
22923
+ blake2bCompress(ctx, false);
22924
+ ctx.c = 0;
22925
+ }
22926
+ ctx.b[ctx.c++] = input[i];
22927
+ }
22928
+ }
22929
+ function blake2bFinal(ctx, out) {
22930
+ ctx.t += ctx.c;
22931
+ while (ctx.c < 128) {
22932
+ ctx.b[ctx.c++] = 0;
22933
+ }
22934
+ blake2bCompress(ctx, true);
22935
+ for (var i = 0; i < ctx.outlen; i++) {
22936
+ out[i] = ctx.h[i >> 2] >> 8 * (i & 3);
22937
+ }
22938
+ return out;
22939
+ }
22940
+ function hexSlice(buf) {
22941
+ var str = "";
22942
+ for (var i = 0; i < buf.length; i++) str += toHex(buf[i]);
22943
+ return str;
22944
+ }
22945
+ function toHex(n) {
22946
+ if (n < 16) return "0" + n.toString(16);
22947
+ return n.toString(16);
22948
+ }
22949
+ var Proto = Blake2b;
22950
+ module.exports = function createHash(outlen, key, salt, personal, noAssert) {
22951
+ if (noAssert !== true) {
22952
+ assert(outlen >= BYTES_MIN, "outlen must be at least " + BYTES_MIN + ", was given " + outlen);
22953
+ assert(outlen <= BYTES_MAX, "outlen must be at most " + BYTES_MAX + ", was given " + outlen);
22954
+ if (key != null) {
22955
+ assert(key instanceof Uint8Array, "key must be Uint8Array or Buffer");
22956
+ assert(key.length >= KEYBYTES_MIN, "key must be at least " + KEYBYTES_MIN + ", was given " + key.length);
22957
+ assert(key.length <= KEYBYTES_MAX, "key must be at most " + KEYBYTES_MAX + ", was given " + key.length);
22958
+ }
22959
+ if (salt != null) {
22960
+ assert(salt instanceof Uint8Array, "salt must be Uint8Array or Buffer");
22961
+ assert(salt.length === SALTBYTES, "salt must be exactly " + SALTBYTES + ", was given " + salt.length);
22962
+ }
22963
+ if (personal != null) {
22964
+ assert(personal instanceof Uint8Array, "personal must be Uint8Array or Buffer");
22965
+ assert(personal.length === PERSONALBYTES, "personal must be exactly " + PERSONALBYTES + ", was given " + personal.length);
22966
+ }
22967
+ }
22968
+ return new Proto(outlen, key, salt, personal);
22969
+ };
22970
+ module.exports.ready = function(cb) {
22971
+ b2wasm.ready(function() {
22972
+ cb();
22973
+ });
22974
+ };
22975
+ module.exports.WASM_SUPPORTED = b2wasm.SUPPORTED;
22976
+ module.exports.WASM_LOADED = false;
22977
+ var BYTES_MIN = module.exports.BYTES_MIN = 16;
22978
+ var BYTES_MAX = module.exports.BYTES_MAX = 64;
22979
+ var BYTES = module.exports.BYTES = 32;
22980
+ var KEYBYTES_MIN = module.exports.KEYBYTES_MIN = 16;
22981
+ var KEYBYTES_MAX = module.exports.KEYBYTES_MAX = 64;
22982
+ var KEYBYTES = module.exports.KEYBYTES = 32;
22983
+ var SALTBYTES = module.exports.SALTBYTES = 16;
22984
+ var PERSONALBYTES = module.exports.PERSONALBYTES = 16;
22985
+ b2wasm.ready(function(err) {
22986
+ if (!err) {
22987
+ module.exports.WASM_LOADED = true;
22988
+ module.exports = b2wasm;
22989
+ }
22990
+ });
22991
+ }
22992
+ });
22993
+
22994
+ // node_modules/blakejs/util.js
22995
+ var require_util = __commonJS({
22996
+ "node_modules/blakejs/util.js"(exports, module) {
22997
+ var ERROR_MSG_INPUT = "Input must be an string, Buffer or Uint8Array";
22998
+ function normalizeInput(input) {
22999
+ let ret;
23000
+ if (input instanceof Uint8Array) {
23001
+ ret = input;
23002
+ } else if (typeof input === "string") {
23003
+ const encoder = new TextEncoder();
23004
+ ret = encoder.encode(input);
23005
+ } else {
23006
+ throw new Error(ERROR_MSG_INPUT);
23007
+ }
23008
+ return ret;
23009
+ }
23010
+ function toHex(bytes) {
23011
+ return Array.prototype.map.call(bytes, function(n) {
23012
+ return (n < 16 ? "0" : "") + n.toString(16);
23013
+ }).join("");
23014
+ }
23015
+ function uint32ToHex(val) {
23016
+ return (4294967296 + val).toString(16).substring(1);
23017
+ }
23018
+ function debugPrint(label, arr, size) {
23019
+ let msg = "\n" + label + " = ";
23020
+ for (let i = 0; i < arr.length; i += 2) {
23021
+ if (size === 32) {
23022
+ msg += uint32ToHex(arr[i]).toUpperCase();
23023
+ msg += " ";
23024
+ msg += uint32ToHex(arr[i + 1]).toUpperCase();
23025
+ } else if (size === 64) {
23026
+ msg += uint32ToHex(arr[i + 1]).toUpperCase();
23027
+ msg += uint32ToHex(arr[i]).toUpperCase();
23028
+ } else throw new Error("Invalid size " + size);
23029
+ if (i % 6 === 4) {
23030
+ msg += "\n" + new Array(label.length + 4).join(" ");
23031
+ } else if (i < arr.length - 2) {
23032
+ msg += " ";
23033
+ }
23034
+ }
23035
+ console.log(msg);
23036
+ }
23037
+ function testSpeed(hashFn, N, M) {
23038
+ let startMs = (/* @__PURE__ */ new Date()).getTime();
23039
+ const input = new Uint8Array(N);
23040
+ for (let i = 0; i < N; i++) {
23041
+ input[i] = i % 256;
23042
+ }
23043
+ const genMs = (/* @__PURE__ */ new Date()).getTime();
23044
+ console.log("Generated random input in " + (genMs - startMs) + "ms");
23045
+ startMs = genMs;
23046
+ for (let i = 0; i < M; i++) {
23047
+ const hashHex = hashFn(input);
23048
+ const hashMs = (/* @__PURE__ */ new Date()).getTime();
23049
+ const ms = hashMs - startMs;
23050
+ startMs = hashMs;
23051
+ console.log("Hashed in " + ms + "ms: " + hashHex.substring(0, 20) + "...");
23052
+ console.log(
23053
+ Math.round(N / (1 << 20) / (ms / 1e3) * 100) / 100 + " MB PER SECOND"
23054
+ );
23055
+ }
23056
+ }
23057
+ module.exports = {
23058
+ normalizeInput,
23059
+ toHex,
23060
+ debugPrint,
23061
+ testSpeed
23062
+ };
23063
+ }
23064
+ });
23065
+
23066
+ // node_modules/blakejs/blake2b.js
23067
+ var require_blake2b3 = __commonJS({
23068
+ "node_modules/blakejs/blake2b.js"(exports, module) {
23069
+ var util = require_util();
23070
+ function ADD64AA(v2, a, b) {
23071
+ const o0 = v2[a] + v2[b];
23072
+ let o1 = v2[a + 1] + v2[b + 1];
23073
+ if (o0 >= 4294967296) {
23074
+ o1++;
23075
+ }
23076
+ v2[a] = o0;
23077
+ v2[a + 1] = o1;
23078
+ }
23079
+ function ADD64AC(v2, a, b0, b1) {
23080
+ let o0 = v2[a] + b0;
23081
+ if (b0 < 0) {
23082
+ o0 += 4294967296;
23083
+ }
23084
+ let o1 = v2[a + 1] + b1;
23085
+ if (o0 >= 4294967296) {
23086
+ o1++;
23087
+ }
23088
+ v2[a] = o0;
23089
+ v2[a + 1] = o1;
23090
+ }
23091
+ function B2B_GET32(arr, i) {
23092
+ return arr[i] ^ arr[i + 1] << 8 ^ arr[i + 2] << 16 ^ arr[i + 3] << 24;
23093
+ }
23094
+ function B2B_G(a, b, c, d, ix, iy) {
23095
+ const x0 = m[ix];
23096
+ const x1 = m[ix + 1];
23097
+ const y0 = m[iy];
23098
+ const y1 = m[iy + 1];
23099
+ ADD64AA(v, a, b);
23100
+ ADD64AC(v, a, x0, x1);
23101
+ let xor0 = v[d] ^ v[a];
23102
+ let xor1 = v[d + 1] ^ v[a + 1];
23103
+ v[d] = xor1;
23104
+ v[d + 1] = xor0;
23105
+ ADD64AA(v, c, d);
23106
+ xor0 = v[b] ^ v[c];
23107
+ xor1 = v[b + 1] ^ v[c + 1];
23108
+ v[b] = xor0 >>> 24 ^ xor1 << 8;
23109
+ v[b + 1] = xor1 >>> 24 ^ xor0 << 8;
23110
+ ADD64AA(v, a, b);
23111
+ ADD64AC(v, a, y0, y1);
23112
+ xor0 = v[d] ^ v[a];
23113
+ xor1 = v[d + 1] ^ v[a + 1];
23114
+ v[d] = xor0 >>> 16 ^ xor1 << 16;
23115
+ v[d + 1] = xor1 >>> 16 ^ xor0 << 16;
23116
+ ADD64AA(v, c, d);
23117
+ xor0 = v[b] ^ v[c];
23118
+ xor1 = v[b + 1] ^ v[c + 1];
23119
+ v[b] = xor1 >>> 31 ^ xor0 << 1;
23120
+ v[b + 1] = xor0 >>> 31 ^ xor1 << 1;
23121
+ }
23122
+ var BLAKE2B_IV32 = new Uint32Array([
23123
+ 4089235720,
23124
+ 1779033703,
23125
+ 2227873595,
23126
+ 3144134277,
23127
+ 4271175723,
23128
+ 1013904242,
23129
+ 1595750129,
23130
+ 2773480762,
23131
+ 2917565137,
23132
+ 1359893119,
23133
+ 725511199,
23134
+ 2600822924,
23135
+ 4215389547,
23136
+ 528734635,
23137
+ 327033209,
23138
+ 1541459225
23139
+ ]);
23140
+ var SIGMA8 = [
23141
+ 0,
23142
+ 1,
23143
+ 2,
23144
+ 3,
23145
+ 4,
23146
+ 5,
23147
+ 6,
23148
+ 7,
23149
+ 8,
23150
+ 9,
23151
+ 10,
23152
+ 11,
23153
+ 12,
23154
+ 13,
23155
+ 14,
23156
+ 15,
23157
+ 14,
23158
+ 10,
23159
+ 4,
23160
+ 8,
23161
+ 9,
23162
+ 15,
23163
+ 13,
23164
+ 6,
23165
+ 1,
23166
+ 12,
23167
+ 0,
23168
+ 2,
23169
+ 11,
23170
+ 7,
23171
+ 5,
23172
+ 3,
23173
+ 11,
23174
+ 8,
23175
+ 12,
23176
+ 0,
23177
+ 5,
23178
+ 2,
23179
+ 15,
23180
+ 13,
23181
+ 10,
23182
+ 14,
23183
+ 3,
23184
+ 6,
23185
+ 7,
23186
+ 1,
23187
+ 9,
23188
+ 4,
23189
+ 7,
23190
+ 9,
23191
+ 3,
23192
+ 1,
23193
+ 13,
23194
+ 12,
23195
+ 11,
23196
+ 14,
23197
+ 2,
23198
+ 6,
23199
+ 5,
23200
+ 10,
23201
+ 4,
23202
+ 0,
23203
+ 15,
23204
+ 8,
23205
+ 9,
23206
+ 0,
23207
+ 5,
23208
+ 7,
23209
+ 2,
23210
+ 4,
23211
+ 10,
23212
+ 15,
23213
+ 14,
23214
+ 1,
23215
+ 11,
23216
+ 12,
23217
+ 6,
23218
+ 8,
23219
+ 3,
23220
+ 13,
23221
+ 2,
23222
+ 12,
23223
+ 6,
23224
+ 10,
23225
+ 0,
23226
+ 11,
23227
+ 8,
23228
+ 3,
23229
+ 4,
23230
+ 13,
23231
+ 7,
23232
+ 5,
23233
+ 15,
23234
+ 14,
23235
+ 1,
23236
+ 9,
23237
+ 12,
23238
+ 5,
23239
+ 1,
23240
+ 15,
23241
+ 14,
23242
+ 13,
23243
+ 4,
23244
+ 10,
23245
+ 0,
23246
+ 7,
23247
+ 6,
23248
+ 3,
23249
+ 9,
23250
+ 2,
23251
+ 8,
23252
+ 11,
23253
+ 13,
23254
+ 11,
23255
+ 7,
23256
+ 14,
23257
+ 12,
23258
+ 1,
23259
+ 3,
23260
+ 9,
23261
+ 5,
23262
+ 0,
23263
+ 15,
23264
+ 4,
23265
+ 8,
23266
+ 6,
23267
+ 2,
23268
+ 10,
23269
+ 6,
23270
+ 15,
23271
+ 14,
23272
+ 9,
23273
+ 11,
23274
+ 3,
23275
+ 0,
23276
+ 8,
23277
+ 12,
23278
+ 2,
23279
+ 13,
23280
+ 7,
23281
+ 1,
23282
+ 4,
23283
+ 10,
23284
+ 5,
23285
+ 10,
23286
+ 2,
23287
+ 8,
23288
+ 4,
23289
+ 7,
23290
+ 6,
23291
+ 1,
23292
+ 5,
23293
+ 15,
23294
+ 11,
23295
+ 9,
23296
+ 14,
23297
+ 3,
23298
+ 12,
23299
+ 13,
23300
+ 0,
23301
+ 0,
23302
+ 1,
23303
+ 2,
23304
+ 3,
23305
+ 4,
23306
+ 5,
23307
+ 6,
23308
+ 7,
23309
+ 8,
23310
+ 9,
23311
+ 10,
23312
+ 11,
23313
+ 12,
23314
+ 13,
23315
+ 14,
23316
+ 15,
23317
+ 14,
23318
+ 10,
23319
+ 4,
23320
+ 8,
23321
+ 9,
23322
+ 15,
23323
+ 13,
23324
+ 6,
23325
+ 1,
23326
+ 12,
23327
+ 0,
23328
+ 2,
23329
+ 11,
23330
+ 7,
23331
+ 5,
23332
+ 3
23333
+ ];
23334
+ var SIGMA82 = new Uint8Array(
23335
+ SIGMA8.map(function(x) {
23336
+ return x * 2;
23337
+ })
23338
+ );
23339
+ var v = new Uint32Array(32);
23340
+ var m = new Uint32Array(32);
23341
+ function blake2bCompress(ctx, last) {
23342
+ let i = 0;
23343
+ for (i = 0; i < 16; i++) {
23344
+ v[i] = ctx.h[i];
23345
+ v[i + 16] = BLAKE2B_IV32[i];
23346
+ }
23347
+ v[24] = v[24] ^ ctx.t;
23348
+ v[25] = v[25] ^ ctx.t / 4294967296;
23349
+ if (last) {
23350
+ v[28] = ~v[28];
23351
+ v[29] = ~v[29];
23352
+ }
23353
+ for (i = 0; i < 32; i++) {
23354
+ m[i] = B2B_GET32(ctx.b, 4 * i);
23355
+ }
23356
+ for (i = 0; i < 12; i++) {
23357
+ B2B_G(0, 8, 16, 24, SIGMA82[i * 16 + 0], SIGMA82[i * 16 + 1]);
23358
+ B2B_G(2, 10, 18, 26, SIGMA82[i * 16 + 2], SIGMA82[i * 16 + 3]);
23359
+ B2B_G(4, 12, 20, 28, SIGMA82[i * 16 + 4], SIGMA82[i * 16 + 5]);
23360
+ B2B_G(6, 14, 22, 30, SIGMA82[i * 16 + 6], SIGMA82[i * 16 + 7]);
23361
+ B2B_G(0, 10, 20, 30, SIGMA82[i * 16 + 8], SIGMA82[i * 16 + 9]);
23362
+ B2B_G(2, 12, 22, 24, SIGMA82[i * 16 + 10], SIGMA82[i * 16 + 11]);
23363
+ B2B_G(4, 14, 16, 26, SIGMA82[i * 16 + 12], SIGMA82[i * 16 + 13]);
23364
+ B2B_G(6, 8, 18, 28, SIGMA82[i * 16 + 14], SIGMA82[i * 16 + 15]);
23365
+ }
23366
+ for (i = 0; i < 16; i++) {
23367
+ ctx.h[i] = ctx.h[i] ^ v[i] ^ v[i + 16];
23368
+ }
23369
+ }
23370
+ var parameterBlock = new Uint8Array([
23371
+ 0,
23372
+ 0,
23373
+ 0,
23374
+ 0,
23375
+ // 0: outlen, keylen, fanout, depth
23376
+ 0,
23377
+ 0,
23378
+ 0,
23379
+ 0,
23380
+ // 4: leaf length, sequential mode
23381
+ 0,
23382
+ 0,
23383
+ 0,
23384
+ 0,
23385
+ // 8: node offset
23386
+ 0,
23387
+ 0,
23388
+ 0,
23389
+ 0,
23390
+ // 12: node offset
23391
+ 0,
23392
+ 0,
23393
+ 0,
23394
+ 0,
23395
+ // 16: node depth, inner length, rfu
23396
+ 0,
23397
+ 0,
23398
+ 0,
23399
+ 0,
23400
+ // 20: rfu
23401
+ 0,
23402
+ 0,
23403
+ 0,
23404
+ 0,
23405
+ // 24: rfu
23406
+ 0,
23407
+ 0,
23408
+ 0,
23409
+ 0,
23410
+ // 28: rfu
23411
+ 0,
23412
+ 0,
23413
+ 0,
23414
+ 0,
23415
+ // 32: salt
23416
+ 0,
23417
+ 0,
23418
+ 0,
23419
+ 0,
23420
+ // 36: salt
23421
+ 0,
23422
+ 0,
23423
+ 0,
23424
+ 0,
23425
+ // 40: salt
23426
+ 0,
23427
+ 0,
23428
+ 0,
23429
+ 0,
23430
+ // 44: salt
23431
+ 0,
23432
+ 0,
23433
+ 0,
23434
+ 0,
23435
+ // 48: personal
23436
+ 0,
23437
+ 0,
23438
+ 0,
23439
+ 0,
23440
+ // 52: personal
23441
+ 0,
23442
+ 0,
23443
+ 0,
23444
+ 0,
23445
+ // 56: personal
23446
+ 0,
23447
+ 0,
23448
+ 0,
23449
+ 0
23450
+ // 60: personal
23451
+ ]);
23452
+ function blake2bInit(outlen, key, salt, personal) {
23453
+ if (outlen === 0 || outlen > 64) {
23454
+ throw new Error("Illegal output length, expected 0 < length <= 64");
23455
+ }
23456
+ if (key && key.length > 64) {
23457
+ throw new Error("Illegal key, expected Uint8Array with 0 < length <= 64");
23458
+ }
23459
+ if (salt && salt.length !== 16) {
23460
+ throw new Error("Illegal salt, expected Uint8Array with length is 16");
23461
+ }
23462
+ if (personal && personal.length !== 16) {
23463
+ throw new Error("Illegal personal, expected Uint8Array with length is 16");
23464
+ }
23465
+ const ctx = {
23466
+ b: new Uint8Array(128),
23467
+ h: new Uint32Array(16),
23468
+ t: 0,
23469
+ // input count
23470
+ c: 0,
23471
+ // pointer within buffer
23472
+ outlen
23473
+ // output length in bytes
23474
+ };
23475
+ parameterBlock.fill(0);
23476
+ parameterBlock[0] = outlen;
23477
+ if (key) parameterBlock[1] = key.length;
23478
+ parameterBlock[2] = 1;
23479
+ parameterBlock[3] = 1;
23480
+ if (salt) parameterBlock.set(salt, 32);
23481
+ if (personal) parameterBlock.set(personal, 48);
23482
+ for (let i = 0; i < 16; i++) {
23483
+ ctx.h[i] = BLAKE2B_IV32[i] ^ B2B_GET32(parameterBlock, i * 4);
23484
+ }
23485
+ if (key) {
23486
+ blake2bUpdate(ctx, key);
23487
+ ctx.c = 128;
23488
+ }
23489
+ return ctx;
23490
+ }
23491
+ function blake2bUpdate(ctx, input) {
23492
+ for (let i = 0; i < input.length; i++) {
23493
+ if (ctx.c === 128) {
23494
+ ctx.t += ctx.c;
23495
+ blake2bCompress(ctx, false);
23496
+ ctx.c = 0;
23497
+ }
23498
+ ctx.b[ctx.c++] = input[i];
23499
+ }
23500
+ }
23501
+ function blake2bFinal(ctx) {
23502
+ ctx.t += ctx.c;
23503
+ while (ctx.c < 128) {
23504
+ ctx.b[ctx.c++] = 0;
23505
+ }
23506
+ blake2bCompress(ctx, true);
23507
+ const out = new Uint8Array(ctx.outlen);
23508
+ for (let i = 0; i < ctx.outlen; i++) {
23509
+ out[i] = ctx.h[i >> 2] >> 8 * (i & 3);
23510
+ }
23511
+ return out;
23512
+ }
23513
+ function blake2b4(input, key, outlen, salt, personal) {
23514
+ outlen = outlen || 64;
23515
+ input = util.normalizeInput(input);
23516
+ if (salt) {
23517
+ salt = util.normalizeInput(salt);
23518
+ }
23519
+ if (personal) {
23520
+ personal = util.normalizeInput(personal);
23521
+ }
23522
+ const ctx = blake2bInit(outlen, key, salt, personal);
23523
+ blake2bUpdate(ctx, input);
23524
+ return blake2bFinal(ctx);
23525
+ }
23526
+ function blake2bHex(input, key, outlen, salt, personal) {
23527
+ const output = blake2b4(input, key, outlen, salt, personal);
23528
+ return util.toHex(output);
23529
+ }
23530
+ module.exports = {
23531
+ blake2b: blake2b4,
23532
+ blake2bHex,
23533
+ blake2bInit,
23534
+ blake2bUpdate,
23535
+ blake2bFinal
23536
+ };
23537
+ }
23538
+ });
23539
+
23540
+ // node_modules/blakejs/blake2s.js
23541
+ var require_blake2s = __commonJS({
23542
+ "node_modules/blakejs/blake2s.js"(exports, module) {
23543
+ var util = require_util();
23544
+ function B2S_GET32(v2, i) {
23545
+ return v2[i] ^ v2[i + 1] << 8 ^ v2[i + 2] << 16 ^ v2[i + 3] << 24;
23546
+ }
23547
+ function B2S_G(a, b, c, d, x, y) {
23548
+ v[a] = v[a] + v[b] + x;
23549
+ v[d] = ROTR32(v[d] ^ v[a], 16);
23550
+ v[c] = v[c] + v[d];
23551
+ v[b] = ROTR32(v[b] ^ v[c], 12);
23552
+ v[a] = v[a] + v[b] + y;
23553
+ v[d] = ROTR32(v[d] ^ v[a], 8);
23554
+ v[c] = v[c] + v[d];
23555
+ v[b] = ROTR32(v[b] ^ v[c], 7);
23556
+ }
23557
+ function ROTR32(x, y) {
23558
+ return x >>> y ^ x << 32 - y;
23559
+ }
23560
+ var BLAKE2S_IV = new Uint32Array([
23561
+ 1779033703,
23562
+ 3144134277,
23563
+ 1013904242,
23564
+ 2773480762,
23565
+ 1359893119,
23566
+ 2600822924,
23567
+ 528734635,
23568
+ 1541459225
23569
+ ]);
23570
+ var SIGMA = new Uint8Array([
23571
+ 0,
23572
+ 1,
23573
+ 2,
23574
+ 3,
23575
+ 4,
23576
+ 5,
23577
+ 6,
23578
+ 7,
23579
+ 8,
23580
+ 9,
23581
+ 10,
23582
+ 11,
23583
+ 12,
23584
+ 13,
23585
+ 14,
23586
+ 15,
23587
+ 14,
23588
+ 10,
23589
+ 4,
23590
+ 8,
23591
+ 9,
23592
+ 15,
23593
+ 13,
23594
+ 6,
23595
+ 1,
23596
+ 12,
23597
+ 0,
23598
+ 2,
23599
+ 11,
23600
+ 7,
23601
+ 5,
23602
+ 3,
23603
+ 11,
23604
+ 8,
23605
+ 12,
23606
+ 0,
23607
+ 5,
23608
+ 2,
23609
+ 15,
23610
+ 13,
23611
+ 10,
23612
+ 14,
23613
+ 3,
23614
+ 6,
23615
+ 7,
23616
+ 1,
23617
+ 9,
23618
+ 4,
23619
+ 7,
23620
+ 9,
23621
+ 3,
23622
+ 1,
23623
+ 13,
23624
+ 12,
23625
+ 11,
23626
+ 14,
23627
+ 2,
23628
+ 6,
23629
+ 5,
23630
+ 10,
23631
+ 4,
23632
+ 0,
23633
+ 15,
23634
+ 8,
23635
+ 9,
23636
+ 0,
23637
+ 5,
23638
+ 7,
23639
+ 2,
23640
+ 4,
23641
+ 10,
23642
+ 15,
23643
+ 14,
23644
+ 1,
23645
+ 11,
23646
+ 12,
23647
+ 6,
23648
+ 8,
23649
+ 3,
23650
+ 13,
23651
+ 2,
23652
+ 12,
23653
+ 6,
23654
+ 10,
23655
+ 0,
23656
+ 11,
23657
+ 8,
23658
+ 3,
23659
+ 4,
23660
+ 13,
23661
+ 7,
23662
+ 5,
23663
+ 15,
23664
+ 14,
23665
+ 1,
23666
+ 9,
23667
+ 12,
23668
+ 5,
23669
+ 1,
23670
+ 15,
23671
+ 14,
23672
+ 13,
23673
+ 4,
23674
+ 10,
23675
+ 0,
23676
+ 7,
23677
+ 6,
23678
+ 3,
23679
+ 9,
23680
+ 2,
23681
+ 8,
23682
+ 11,
23683
+ 13,
23684
+ 11,
23685
+ 7,
23686
+ 14,
23687
+ 12,
23688
+ 1,
23689
+ 3,
23690
+ 9,
23691
+ 5,
23692
+ 0,
23693
+ 15,
23694
+ 4,
23695
+ 8,
23696
+ 6,
23697
+ 2,
23698
+ 10,
23699
+ 6,
23700
+ 15,
23701
+ 14,
23702
+ 9,
23703
+ 11,
23704
+ 3,
23705
+ 0,
23706
+ 8,
23707
+ 12,
23708
+ 2,
23709
+ 13,
23710
+ 7,
23711
+ 1,
23712
+ 4,
23713
+ 10,
23714
+ 5,
23715
+ 10,
23716
+ 2,
23717
+ 8,
23718
+ 4,
23719
+ 7,
23720
+ 6,
23721
+ 1,
23722
+ 5,
23723
+ 15,
23724
+ 11,
23725
+ 9,
23726
+ 14,
23727
+ 3,
23728
+ 12,
23729
+ 13,
23730
+ 0
23731
+ ]);
23732
+ var v = new Uint32Array(16);
23733
+ var m = new Uint32Array(16);
23734
+ function blake2sCompress(ctx, last) {
23735
+ let i = 0;
23736
+ for (i = 0; i < 8; i++) {
23737
+ v[i] = ctx.h[i];
23738
+ v[i + 8] = BLAKE2S_IV[i];
23739
+ }
23740
+ v[12] ^= ctx.t;
23741
+ v[13] ^= ctx.t / 4294967296;
23742
+ if (last) {
23743
+ v[14] = ~v[14];
23744
+ }
23745
+ for (i = 0; i < 16; i++) {
23746
+ m[i] = B2S_GET32(ctx.b, 4 * i);
23747
+ }
23748
+ for (i = 0; i < 10; i++) {
23749
+ B2S_G(0, 4, 8, 12, m[SIGMA[i * 16 + 0]], m[SIGMA[i * 16 + 1]]);
23750
+ B2S_G(1, 5, 9, 13, m[SIGMA[i * 16 + 2]], m[SIGMA[i * 16 + 3]]);
23751
+ B2S_G(2, 6, 10, 14, m[SIGMA[i * 16 + 4]], m[SIGMA[i * 16 + 5]]);
23752
+ B2S_G(3, 7, 11, 15, m[SIGMA[i * 16 + 6]], m[SIGMA[i * 16 + 7]]);
23753
+ B2S_G(0, 5, 10, 15, m[SIGMA[i * 16 + 8]], m[SIGMA[i * 16 + 9]]);
23754
+ B2S_G(1, 6, 11, 12, m[SIGMA[i * 16 + 10]], m[SIGMA[i * 16 + 11]]);
23755
+ B2S_G(2, 7, 8, 13, m[SIGMA[i * 16 + 12]], m[SIGMA[i * 16 + 13]]);
23756
+ B2S_G(3, 4, 9, 14, m[SIGMA[i * 16 + 14]], m[SIGMA[i * 16 + 15]]);
23757
+ }
23758
+ for (i = 0; i < 8; i++) {
23759
+ ctx.h[i] ^= v[i] ^ v[i + 8];
23760
+ }
23761
+ }
23762
+ function blake2sInit(outlen, key) {
23763
+ if (!(outlen > 0 && outlen <= 32)) {
23764
+ throw new Error("Incorrect output length, should be in [1, 32]");
23765
+ }
23766
+ const keylen = key ? key.length : 0;
23767
+ if (key && !(keylen > 0 && keylen <= 32)) {
23768
+ throw new Error("Incorrect key length, should be in [1, 32]");
23769
+ }
23770
+ const ctx = {
23771
+ h: new Uint32Array(BLAKE2S_IV),
23772
+ // hash state
23773
+ b: new Uint8Array(64),
23774
+ // input block
23775
+ c: 0,
23776
+ // pointer within block
23777
+ t: 0,
23778
+ // input count
23779
+ outlen
23780
+ // output length in bytes
23781
+ };
23782
+ ctx.h[0] ^= 16842752 ^ keylen << 8 ^ outlen;
23783
+ if (keylen > 0) {
23784
+ blake2sUpdate(ctx, key);
23785
+ ctx.c = 64;
23786
+ }
23787
+ return ctx;
23788
+ }
23789
+ function blake2sUpdate(ctx, input) {
23790
+ for (let i = 0; i < input.length; i++) {
23791
+ if (ctx.c === 64) {
23792
+ ctx.t += ctx.c;
23793
+ blake2sCompress(ctx, false);
23794
+ ctx.c = 0;
23795
+ }
23796
+ ctx.b[ctx.c++] = input[i];
23797
+ }
23798
+ }
23799
+ function blake2sFinal(ctx) {
23800
+ ctx.t += ctx.c;
23801
+ while (ctx.c < 64) {
23802
+ ctx.b[ctx.c++] = 0;
23803
+ }
23804
+ blake2sCompress(ctx, true);
23805
+ const out = new Uint8Array(ctx.outlen);
23806
+ for (let i = 0; i < ctx.outlen; i++) {
23807
+ out[i] = ctx.h[i >> 2] >> 8 * (i & 3) & 255;
23808
+ }
23809
+ return out;
23810
+ }
23811
+ function blake2s(input, key, outlen) {
23812
+ outlen = outlen || 32;
23813
+ input = util.normalizeInput(input);
23814
+ const ctx = blake2sInit(outlen, key);
23815
+ blake2sUpdate(ctx, input);
23816
+ return blake2sFinal(ctx);
23817
+ }
23818
+ function blake2sHex(input, key, outlen) {
23819
+ const output = blake2s(input, key, outlen);
23820
+ return util.toHex(output);
23821
+ }
23822
+ module.exports = {
23823
+ blake2s,
23824
+ blake2sHex,
23825
+ blake2sInit,
23826
+ blake2sUpdate,
23827
+ blake2sFinal
23828
+ };
23829
+ }
23830
+ });
23831
+
23832
+ // node_modules/blakejs/index.js
23833
+ var require_blakejs = __commonJS({
23834
+ "node_modules/blakejs/index.js"(exports, module) {
23835
+ var b2b = require_blake2b3();
23836
+ var b2s = require_blake2s();
23837
+ module.exports = {
23838
+ blake2b: b2b.blake2b,
23839
+ blake2bHex: b2b.blake2bHex,
23840
+ blake2bInit: b2b.blake2bInit,
23841
+ blake2bUpdate: b2b.blake2bUpdate,
23842
+ blake2bFinal: b2b.blake2bFinal,
23843
+ blake2s: b2s.blake2s,
23844
+ blake2sHex: b2s.blake2sHex,
23845
+ blake2sInit: b2s.blake2sInit,
23846
+ blake2sUpdate: b2s.blake2sUpdate,
23847
+ blake2sFinal: b2s.blake2sFinal
23848
+ };
23849
+ }
23850
+ });
23851
+
23852
+ // src/bip32/in-memory-bip32.ts
23853
+ import {
23854
+ Bip32PrivateKey,
23855
+ ready
23856
+ } from "@cardano-sdk/crypto";
23857
+
23858
+ // node_modules/@scure/base/lib/esm/index.js
23859
+ function isBytes(a) {
23860
+ return a instanceof Uint8Array || ArrayBuffer.isView(a) && a.constructor.name === "Uint8Array";
23861
+ }
23862
+ function isArrayOf(isString, arr) {
23863
+ if (!Array.isArray(arr))
23864
+ return false;
23865
+ if (arr.length === 0)
23866
+ return true;
23867
+ if (isString) {
23868
+ return arr.every((item) => typeof item === "string");
23869
+ } else {
23870
+ return arr.every((item) => Number.isSafeInteger(item));
23871
+ }
23872
+ }
23873
+ function afn(input) {
23874
+ if (typeof input !== "function")
23875
+ throw new Error("function expected");
23876
+ return true;
23877
+ }
23878
+ function astr(label, input) {
23879
+ if (typeof input !== "string")
23880
+ throw new Error(`${label}: string expected`);
23881
+ return true;
23882
+ }
23883
+ function anumber(n) {
23884
+ if (!Number.isSafeInteger(n))
23885
+ throw new Error(`invalid integer: ${n}`);
23886
+ }
23887
+ function aArr(input) {
23888
+ if (!Array.isArray(input))
23889
+ throw new Error("array expected");
23890
+ }
23891
+ function astrArr(label, input) {
23892
+ if (!isArrayOf(true, input))
23893
+ throw new Error(`${label}: array of strings expected`);
23894
+ }
23895
+ function anumArr(label, input) {
23896
+ if (!isArrayOf(false, input))
23897
+ throw new Error(`${label}: array of numbers expected`);
23898
+ }
23899
+ // @__NO_SIDE_EFFECTS__
23900
+ function chain(...args) {
23901
+ const id = (a) => a;
23902
+ const wrap = (a, b) => (c) => a(b(c));
23903
+ const encode = args.map((x) => x.encode).reduceRight(wrap, id);
23904
+ const decode = args.map((x) => x.decode).reduce(wrap, id);
23905
+ return { encode, decode };
23906
+ }
23907
+ // @__NO_SIDE_EFFECTS__
23908
+ function alphabet(letters) {
23909
+ const lettersA = typeof letters === "string" ? letters.split("") : letters;
23910
+ const len = lettersA.length;
23911
+ astrArr("alphabet", lettersA);
23912
+ const indexes = new Map(lettersA.map((l, i) => [l, i]));
23913
+ return {
23914
+ encode: (digits) => {
23915
+ aArr(digits);
23916
+ return digits.map((i) => {
23917
+ if (!Number.isSafeInteger(i) || i < 0 || i >= len)
23918
+ throw new Error(`alphabet.encode: digit index outside alphabet "${i}". Allowed: ${letters}`);
23919
+ return lettersA[i];
23920
+ });
23921
+ },
23922
+ decode: (input) => {
23923
+ aArr(input);
23924
+ return input.map((letter) => {
23925
+ astr("alphabet.decode", letter);
23926
+ const i = indexes.get(letter);
23927
+ if (i === void 0)
23928
+ throw new Error(`Unknown letter: "${letter}". Allowed: ${letters}`);
23929
+ return i;
23930
+ });
23931
+ }
23932
+ };
23933
+ }
23934
+ // @__NO_SIDE_EFFECTS__
23935
+ function join(separator = "") {
23936
+ astr("join", separator);
23937
+ return {
23938
+ encode: (from) => {
23939
+ astrArr("join.decode", from);
23940
+ return from.join(separator);
23941
+ },
23942
+ decode: (to) => {
23943
+ astr("join.decode", to);
23944
+ return to.split(separator);
23945
+ }
23946
+ };
23947
+ }
23948
+ var gcd = (a, b) => b === 0 ? a : gcd(b, a % b);
23949
+ var radix2carry = /* @__NO_SIDE_EFFECTS__ */ (from, to) => from + (to - gcd(from, to));
23950
+ var powers = /* @__PURE__ */ (() => {
23951
+ let res = [];
23952
+ for (let i = 0; i < 40; i++)
23953
+ res.push(2 ** i);
23954
+ return res;
23955
+ })();
23956
+ function convertRadix2(data, from, to, padding) {
23957
+ aArr(data);
23958
+ if (from <= 0 || from > 32)
23959
+ throw new Error(`convertRadix2: wrong from=${from}`);
23960
+ if (to <= 0 || to > 32)
23961
+ throw new Error(`convertRadix2: wrong to=${to}`);
23962
+ if (/* @__PURE__ */ radix2carry(from, to) > 32) {
23963
+ throw new Error(`convertRadix2: carry overflow from=${from} to=${to} carryBits=${/* @__PURE__ */ radix2carry(from, to)}`);
23964
+ }
23965
+ let carry = 0;
23966
+ let pos = 0;
23967
+ const max = powers[from];
23968
+ const mask = powers[to] - 1;
23969
+ const res = [];
23970
+ for (const n of data) {
23971
+ anumber(n);
23972
+ if (n >= max)
23973
+ throw new Error(`convertRadix2: invalid data word=${n} from=${from}`);
23974
+ carry = carry << from | n;
23975
+ if (pos + from > 32)
23976
+ throw new Error(`convertRadix2: carry overflow pos=${pos} from=${from}`);
23977
+ pos += from;
23978
+ for (; pos >= to; pos -= to)
23979
+ res.push((carry >> pos - to & mask) >>> 0);
23980
+ const pow = powers[pos];
23981
+ if (pow === void 0)
23982
+ throw new Error("invalid carry");
23983
+ carry &= pow - 1;
23984
+ }
23985
+ carry = carry << to - pos & mask;
23986
+ if (!padding && pos >= from)
23987
+ throw new Error("Excess padding");
23988
+ if (!padding && carry > 0)
23989
+ throw new Error(`Non-zero padding: ${carry}`);
23990
+ if (padding && pos > 0)
23991
+ res.push(carry >>> 0);
23992
+ return res;
23993
+ }
23994
+ // @__NO_SIDE_EFFECTS__
23995
+ function radix2(bits, revPadding = false) {
23996
+ anumber(bits);
23997
+ if (bits <= 0 || bits > 32)
23998
+ throw new Error("radix2: bits should be in (0..32]");
23999
+ if (/* @__PURE__ */ radix2carry(8, bits) > 32 || /* @__PURE__ */ radix2carry(bits, 8) > 32)
24000
+ throw new Error("radix2: carry overflow");
24001
+ return {
24002
+ encode: (bytes) => {
24003
+ if (!isBytes(bytes))
24004
+ throw new Error("radix2.encode input should be Uint8Array");
24005
+ return convertRadix2(Array.from(bytes), 8, bits, !revPadding);
24006
+ },
24007
+ decode: (digits) => {
24008
+ anumArr("radix2.decode", digits);
24009
+ return Uint8Array.from(convertRadix2(digits, bits, 8, revPadding));
24010
+ }
24011
+ };
24012
+ }
24013
+ function unsafeWrapper(fn) {
24014
+ afn(fn);
24015
+ return function(...args) {
24016
+ try {
24017
+ return fn.apply(null, args);
24018
+ } catch (e) {
24019
+ }
24020
+ };
24021
+ }
24022
+ var BECH_ALPHABET = /* @__PURE__ */ chain(/* @__PURE__ */ alphabet("qpzry9x8gf2tvdw0s3jn54khce6mua7l"), /* @__PURE__ */ join(""));
24023
+ var POLYMOD_GENERATORS = [996825010, 642813549, 513874426, 1027748829, 705979059];
24024
+ function bech32Polymod(pre) {
24025
+ const b = pre >> 25;
24026
+ let chk = (pre & 33554431) << 5;
24027
+ for (let i = 0; i < POLYMOD_GENERATORS.length; i++) {
24028
+ if ((b >> i & 1) === 1)
24029
+ chk ^= POLYMOD_GENERATORS[i];
24030
+ }
24031
+ return chk;
24032
+ }
24033
+ function bechChecksum(prefix, words, encodingConst = 1) {
24034
+ const len = prefix.length;
24035
+ let chk = 1;
24036
+ for (let i = 0; i < len; i++) {
24037
+ const c = prefix.charCodeAt(i);
24038
+ if (c < 33 || c > 126)
24039
+ throw new Error(`Invalid prefix (${prefix})`);
24040
+ chk = bech32Polymod(chk) ^ c >> 5;
24041
+ }
24042
+ chk = bech32Polymod(chk);
24043
+ for (let i = 0; i < len; i++)
24044
+ chk = bech32Polymod(chk) ^ prefix.charCodeAt(i) & 31;
24045
+ for (let v of words)
24046
+ chk = bech32Polymod(chk) ^ v;
24047
+ for (let i = 0; i < 6; i++)
24048
+ chk = bech32Polymod(chk);
24049
+ chk ^= encodingConst;
24050
+ return BECH_ALPHABET.encode(convertRadix2([chk % powers[30]], 30, 5, false));
24051
+ }
24052
+ // @__NO_SIDE_EFFECTS__
24053
+ function genBech32(encoding) {
24054
+ const ENCODING_CONST = encoding === "bech32" ? 1 : 734539939;
24055
+ const _words = /* @__PURE__ */ radix2(5);
24056
+ const fromWords = _words.decode;
24057
+ const toWords = _words.encode;
24058
+ const fromWordsUnsafe = unsafeWrapper(fromWords);
24059
+ function encode(prefix, words, limit = 90) {
24060
+ astr("bech32.encode prefix", prefix);
24061
+ if (isBytes(words))
24062
+ words = Array.from(words);
24063
+ anumArr("bech32.encode", words);
24064
+ const plen = prefix.length;
24065
+ if (plen === 0)
24066
+ throw new TypeError(`Invalid prefix length ${plen}`);
24067
+ const actualLength = plen + 7 + words.length;
24068
+ if (limit !== false && actualLength > limit)
24069
+ throw new TypeError(`Length ${actualLength} exceeds limit ${limit}`);
24070
+ const lowered = prefix.toLowerCase();
24071
+ const sum = bechChecksum(lowered, words, ENCODING_CONST);
24072
+ return `${lowered}1${BECH_ALPHABET.encode(words)}${sum}`;
24073
+ }
24074
+ function decode(str, limit = 90) {
24075
+ astr("bech32.decode input", str);
24076
+ const slen = str.length;
24077
+ if (slen < 8 || limit !== false && slen > limit)
24078
+ throw new TypeError(`invalid string length: ${slen} (${str}). Expected (8..${limit})`);
24079
+ const lowered = str.toLowerCase();
24080
+ if (str !== lowered && str !== str.toUpperCase())
24081
+ throw new Error(`String must be lowercase or uppercase`);
24082
+ const sepIndex = lowered.lastIndexOf("1");
24083
+ if (sepIndex === 0 || sepIndex === -1)
24084
+ throw new Error(`Letter "1" must be present between prefix and data only`);
24085
+ const prefix = lowered.slice(0, sepIndex);
24086
+ const data = lowered.slice(sepIndex + 1);
24087
+ if (data.length < 6)
24088
+ throw new Error("Data must be at least 6 characters long");
24089
+ const words = BECH_ALPHABET.decode(data).slice(0, -6);
24090
+ const sum = bechChecksum(prefix, words, ENCODING_CONST);
24091
+ if (!data.endsWith(sum))
24092
+ throw new Error(`Invalid checksum in ${str}: expected "${sum}"`);
24093
+ return { prefix, words };
24094
+ }
24095
+ const decodeUnsafe = unsafeWrapper(decode);
24096
+ function decodeToBytes(str) {
24097
+ const { prefix, words } = decode(str, false);
24098
+ return { prefix, words, bytes: fromWords(words) };
24099
+ }
24100
+ function encodeFromBytes(prefix, bytes) {
24101
+ return encode(prefix, toWords(bytes));
24102
+ }
24103
+ return {
24104
+ encode,
24105
+ decode,
24106
+ encodeFromBytes,
24107
+ decodeToBytes,
24108
+ decodeUnsafe,
24109
+ fromWords,
24110
+ fromWordsUnsafe,
24111
+ toWords
24112
+ };
24113
+ }
24114
+ var bech32 = /* @__PURE__ */ genBech32("bech32");
24115
+
22005
24116
  // src/bip32/in-memory-bip32.ts
22006
- import { setInConwayEra as setInConwayEra2 } from "@cardano-sdk/core";
24117
+ var import_bip39 = __toESM(require_src(), 1);
24118
+
24119
+ // src/cardano/utils/constants.ts
24120
+ var HARDENED_OFFSET = 2147483648;
24121
+ var DEFAULT_ACCOUNT_KEY_DERIVATION_PATH = [
24122
+ 1852 + HARDENED_OFFSET,
24123
+ 1815 + HARDENED_OFFSET,
24124
+ 0 + HARDENED_OFFSET
24125
+ ];
24126
+ var DEFAULT_PAYMENT_KEY_DERIVATION_PATH = [
24127
+ ...DEFAULT_ACCOUNT_KEY_DERIVATION_PATH,
24128
+ 0
24129
+ ];
24130
+ var DEFAULT_STAKE_KEY_DERIVATION_PATH = [
24131
+ ...DEFAULT_ACCOUNT_KEY_DERIVATION_PATH,
24132
+ 2
24133
+ ];
24134
+ var DEFAULT_DREP_KEY_DERIVATION_PATH = [
24135
+ ...DEFAULT_ACCOUNT_KEY_DERIVATION_PATH,
24136
+ 3
24137
+ ];
24138
+
24139
+ // src/interfaces/secret-manager.ts
24140
+ var derivationPathVectorFromString = (path) => {
24141
+ if (!/^m?\/\d+(\/\d+)*$/.test(path)) {
24142
+ throw new Error(`Invalid derivation path: ${path}`);
24143
+ }
24144
+ let pathString = path;
24145
+ if (pathString.startsWith("m/")) {
24146
+ pathString = pathString.slice(2);
24147
+ }
24148
+ return pathString.split("/").map((part) => {
24149
+ if (part.endsWith("'")) {
24150
+ return Number.parseInt(part.slice(0, -1)) + HARDENED_OFFSET;
24151
+ } else {
24152
+ return Number.parseInt(part);
24153
+ }
24154
+ });
24155
+ };
24156
+
24157
+ // src/signer/base-signer.ts
24158
+ import { setInConwayEra } from "@cardano-sdk/core";
22007
24159
  import {
22008
- Bip32PrivateKey,
22009
- ready
24160
+ Ed25519PrivateExtendedKeyHex,
24161
+ Ed25519PrivateKey,
24162
+ Ed25519PrivateNormalKeyHex,
24163
+ Ed25519Signature,
24164
+ Ed25519SignatureHex
22010
24165
  } from "@cardano-sdk/crypto";
24166
+ import { HexBlob } from "@cardano-sdk/util";
24167
+ var BaseSigner = class _BaseSigner {
24168
+ constructor(ed25519PrivateKey) {
24169
+ setInConwayEra(true);
24170
+ this.ed25519PrivateKey = ed25519PrivateKey;
24171
+ }
24172
+ /**
24173
+ * Create a BaseSigner instance from an Ed25519 private key in extended hex format.
24174
+ * @param keyHex Ed25519 private key in extended hex format
24175
+ * @returns {BaseSigner} A BaseSigner instance
24176
+ */
24177
+ static fromExtendedKeyHex(keyHex) {
24178
+ return new _BaseSigner(
24179
+ Ed25519PrivateKey.fromExtendedHex(Ed25519PrivateExtendedKeyHex(keyHex))
24180
+ );
24181
+ }
24182
+ /**
24183
+ * Create a BaseSigner instance from an Ed25519 private key in normal hex format.
24184
+ * @param keyHex Ed25519 private key in normal hex format
24185
+ * @returns {BaseSigner} A BaseSigner instance
24186
+ */
24187
+ static fromNormalKeyHex(keyHex) {
24188
+ return new _BaseSigner(
24189
+ Ed25519PrivateKey.fromNormalHex(Ed25519PrivateNormalKeyHex(keyHex))
24190
+ );
24191
+ }
24192
+ static fromKeyHex(keyHex) {
24193
+ const hexLength = keyHex.length;
24194
+ if (hexLength === 128) {
24195
+ return this.fromExtendedKeyHex(keyHex);
24196
+ } else if (hexLength === 64) {
24197
+ return this.fromNormalKeyHex(keyHex);
24198
+ } else {
24199
+ throw new Error(
24200
+ `Invalid key length: ${hexLength}. Expected 64 (normal key) or 128 (extended key) hex characters.`
24201
+ );
24202
+ }
24203
+ }
24204
+ /**
24205
+ * Get the Ed25519 public key in hex format.
24206
+ * @returns {Promise<string>} A promise that resolves to the public key in hex format.
24207
+ */
24208
+ async getPublicKey() {
24209
+ return this.ed25519PrivateKey.toPublic().hex();
24210
+ }
24211
+ /**
24212
+ * Get the Ed25519 public key hash in hex format.
24213
+ * @returns {Promise<string>} A promise that resolves to the public key hash in hex format.
24214
+ */
24215
+ async getPublicKeyHash() {
24216
+ return this.ed25519PrivateKey.toPublic().hash().hex();
24217
+ }
24218
+ /**
24219
+ * Sign data using the Ed25519 private key.
24220
+ * @param data data to be signed in hex format
24221
+ * @returns {Promise<string>} A promise that resolves to the signature in hex format.
24222
+ */
24223
+ async sign(data) {
24224
+ return this.ed25519PrivateKey.sign(HexBlob(data)).hex();
24225
+ }
24226
+ /**
24227
+ * Verify a signature using the Ed25519 public key.
24228
+ * @param data The original data in hex format.
24229
+ * @param signature The signature to verify in hex format.
24230
+ * @returns {Promise<boolean>} A promise that resolves to true if the signature is valid, false otherwise.
24231
+ */
24232
+ async verify(data, signature) {
24233
+ return this.ed25519PrivateKey.toPublic().verify(
24234
+ Ed25519Signature.fromHex(Ed25519SignatureHex(signature)),
24235
+ HexBlob(data)
24236
+ );
24237
+ }
24238
+ };
24239
+
24240
+ // src/bip32/in-memory-bip32.ts
24241
+ var InMemoryBip32 = class _InMemoryBip32 {
24242
+ constructor(privateKey) {
24243
+ this.bip32PrivateKey = privateKey;
24244
+ }
24245
+ static async fromMnemonic(mnemonic, password) {
24246
+ await ready();
24247
+ const entropy = (0, import_bip39.mnemonicToEntropy)(mnemonic.join(" "));
24248
+ const bip32PrivateKey = Bip32PrivateKey.fromBip39Entropy(
24249
+ Buffer.from(entropy, "hex"),
24250
+ password || ""
24251
+ );
24252
+ return new _InMemoryBip32(bip32PrivateKey);
24253
+ }
24254
+ static async fromEntropy(entropy, password) {
24255
+ await ready();
24256
+ const bip32PrivateKey = Bip32PrivateKey.fromBip39Entropy(
24257
+ Buffer.from(entropy, "hex"),
24258
+ password || ""
24259
+ );
24260
+ return new _InMemoryBip32(bip32PrivateKey);
24261
+ }
24262
+ static fromKeyHex(keyHex) {
24263
+ const bip32PrivateKey = Bip32PrivateKey.fromHex(
24264
+ keyHex
24265
+ );
24266
+ return new _InMemoryBip32(bip32PrivateKey);
24267
+ }
24268
+ static fromBech32(bech323) {
24269
+ const bech32DecodedBytes = bech32.decodeToBytes(bech323).bytes;
24270
+ const bip32PrivateKey = Bip32PrivateKey.fromBytes(bech32DecodedBytes);
24271
+ return new _InMemoryBip32(bip32PrivateKey);
24272
+ }
24273
+ /**
24274
+ * Get the Bip32 public key in hex format.
24275
+ * @returns {Promise<string>} A promise that resolves to the public key in hex format.
24276
+ */
24277
+ async getPublicKey() {
24278
+ await ready();
24279
+ return this.bip32PrivateKey.toPublic().hex();
24280
+ }
24281
+ /**
24282
+ * Get an ISigner instance initialized with the current Bip32 private key.
24283
+ * @returns {Promise<ISigner>} A promise that resolves to an ISigner instance initialized with the current Bip32 private key.
24284
+ */
24285
+ async getSigner(derivationPath) {
24286
+ const path = Array.isArray(derivationPath) ? derivationPath : derivationPathVectorFromString(derivationPath);
24287
+ const bip32PrivateKey = this.bip32PrivateKey.derive(path);
24288
+ return BaseSigner.fromExtendedKeyHex(bip32PrivateKey.toRawKey().hex());
24289
+ }
24290
+ };
24291
+
24292
+ // src/cardano/address/cardano-address.ts
24293
+ import { Cardano, setInConwayEra as setInConwayEra2 } from "@cardano-sdk/core";
24294
+ import { Hash28ByteBase16 } from "@cardano-sdk/crypto";
24295
+ var CredentialType = /* @__PURE__ */ ((CredentialType2) => {
24296
+ CredentialType2[CredentialType2["KeyHash"] = 0] = "KeyHash";
24297
+ CredentialType2[CredentialType2["ScriptHash"] = 1] = "ScriptHash";
24298
+ return CredentialType2;
24299
+ })(CredentialType || {});
24300
+ var AddressType = /* @__PURE__ */ ((AddressType2) => {
24301
+ AddressType2[AddressType2["Enterprise"] = 0] = "Enterprise";
24302
+ AddressType2[AddressType2["Base"] = 1] = "Base";
24303
+ AddressType2[AddressType2["Reward"] = 2] = "Reward";
24304
+ return AddressType2;
24305
+ })(AddressType || {});
24306
+ var CardanoAddress = class {
24307
+ constructor(addressType, networkId, paymentCredential, stakeCredential) {
24308
+ setInConwayEra2(true);
24309
+ if (addressType === 1 /* Base */ && !stakeCredential) {
24310
+ throw new Error("No stake credential");
24311
+ }
24312
+ this.addressType = addressType;
24313
+ this.networkId = networkId;
24314
+ this.paymentCredential = paymentCredential;
24315
+ this.stakeCredential = stakeCredential;
24316
+ }
24317
+ getAddressBech32() {
24318
+ if (this.addressType === 0 /* Enterprise */) {
24319
+ return this.getEnterpriseAddressBech32();
24320
+ } else if (this.addressType === 1 /* Base */) {
24321
+ return this.getBaseAddressBech32();
24322
+ } else if (this.addressType === 2 /* Reward */) {
24323
+ return this.getRewardAddressBech32();
24324
+ }
24325
+ throw new Error(`Invalid address type: ${this.addressType}`);
24326
+ }
24327
+ getAddressHex() {
24328
+ if (this.addressType === 0 /* Enterprise */) {
24329
+ return this.getEnterpriseAddressHex();
24330
+ } else if (this.addressType === 1 /* Base */) {
24331
+ return this.getBaseAddressHex();
24332
+ } else if (this.addressType === 2 /* Reward */) {
24333
+ return this.getRewardAddressHex();
24334
+ }
24335
+ throw new Error(`Invalid address type: ${this.addressType}`);
24336
+ }
24337
+ getEnterpriseAddressBech32() {
24338
+ const enterpriseAddress = Cardano.EnterpriseAddress.fromCredentials(
24339
+ this.networkId === 1 ? Cardano.NetworkId.Mainnet : Cardano.NetworkId.Testnet,
24340
+ {
24341
+ hash: Hash28ByteBase16(this.paymentCredential.hash),
24342
+ type: mapCredentialTypeToCredential(this.paymentCredential.type)
24343
+ }
24344
+ );
24345
+ return enterpriseAddress.toAddress().toBech32();
24346
+ }
24347
+ getEnterpriseAddressHex() {
24348
+ const enterpriseAddress = Cardano.EnterpriseAddress.fromCredentials(
24349
+ this.networkId === 1 ? Cardano.NetworkId.Mainnet : Cardano.NetworkId.Testnet,
24350
+ {
24351
+ hash: Hash28ByteBase16(this.paymentCredential.hash),
24352
+ type: mapCredentialTypeToCredential(this.paymentCredential.type)
24353
+ }
24354
+ );
24355
+ return enterpriseAddress.toAddress().toBytes();
24356
+ }
24357
+ getBaseAddressBech32() {
24358
+ if (!this.stakeCredential) throw new Error("No stake credential");
24359
+ const baseAddress = Cardano.BaseAddress.fromCredentials(
24360
+ this.networkId === 1 ? Cardano.NetworkId.Mainnet : Cardano.NetworkId.Testnet,
24361
+ {
24362
+ hash: Hash28ByteBase16(this.paymentCredential.hash),
24363
+ type: mapCredentialTypeToCredential(this.paymentCredential.type)
24364
+ },
24365
+ {
24366
+ hash: Hash28ByteBase16(this.stakeCredential.hash),
24367
+ type: mapCredentialTypeToCredential(this.stakeCredential.type)
24368
+ }
24369
+ );
24370
+ return baseAddress.toAddress().toBech32();
24371
+ }
24372
+ getBaseAddressHex() {
24373
+ if (!this.stakeCredential) throw new Error("No stake credential");
24374
+ const baseAddress = Cardano.BaseAddress.fromCredentials(
24375
+ this.networkId === 1 ? Cardano.NetworkId.Mainnet : Cardano.NetworkId.Testnet,
24376
+ {
24377
+ hash: Hash28ByteBase16(this.paymentCredential.hash),
24378
+ type: mapCredentialTypeToCredential(this.paymentCredential.type)
24379
+ },
24380
+ {
24381
+ hash: Hash28ByteBase16(this.stakeCredential.hash),
24382
+ type: this.stakeCredential.type
24383
+ }
24384
+ );
24385
+ return baseAddress.toAddress().toBytes();
24386
+ }
24387
+ getRewardAddressBech32() {
24388
+ if (!this.stakeCredential) throw new Error("No stake credential");
24389
+ const rewardAddress = Cardano.RewardAddress.fromCredentials(
24390
+ this.networkId === 1 ? Cardano.NetworkId.Mainnet : Cardano.NetworkId.Testnet,
24391
+ {
24392
+ hash: Hash28ByteBase16(this.stakeCredential.hash),
24393
+ type: this.stakeCredential.type
24394
+ }
24395
+ );
24396
+ return rewardAddress.toAddress().toBech32();
24397
+ }
24398
+ getRewardAddressHex() {
24399
+ if (!this.stakeCredential) throw new Error("No stake credential");
24400
+ const rewardAddress = Cardano.RewardAddress.fromCredentials(
24401
+ this.networkId === 1 ? Cardano.NetworkId.Mainnet : Cardano.NetworkId.Testnet,
24402
+ {
24403
+ hash: Hash28ByteBase16(this.stakeCredential.hash),
24404
+ type: this.stakeCredential.type
24405
+ }
24406
+ );
24407
+ return rewardAddress.toAddress().toBytes();
24408
+ }
24409
+ };
24410
+ var mapCredentialTypeToCredential = (credentialType) => {
24411
+ switch (credentialType) {
24412
+ case 0 /* KeyHash */:
24413
+ return Cardano.CredentialType.KeyHash;
24414
+ case 1 /* ScriptHash */:
24415
+ return Cardano.CredentialType.ScriptHash;
24416
+ }
24417
+ };
22011
24418
 
22012
- // node_modules/@scure/base/lib/esm/index.js
22013
- function isBytes(a) {
22014
- return a instanceof Uint8Array || ArrayBuffer.isView(a) && a.constructor.name === "Uint8Array";
22015
- }
22016
- function isArrayOf(isString, arr) {
22017
- if (!Array.isArray(arr))
22018
- return false;
22019
- if (arr.length === 0)
22020
- return true;
22021
- if (isString) {
22022
- return arr.every((item) => typeof item === "string");
22023
- } else {
22024
- return arr.every((item) => Number.isSafeInteger(item));
24419
+ // src/cardano/wallet/browser/cardano-browser-wallet.ts
24420
+ var CardanoBrowserWallet = class _CardanoBrowserWallet {
24421
+ constructor(walletInstance) {
24422
+ this.walletInstance = walletInstance;
22025
24423
  }
22026
- }
22027
- function afn(input) {
22028
- if (typeof input !== "function")
22029
- throw new Error("function expected");
22030
- return true;
22031
- }
22032
- function astr(label, input) {
22033
- if (typeof input !== "string")
22034
- throw new Error(`${label}: string expected`);
22035
- return true;
22036
- }
22037
- function anumber(n) {
22038
- if (!Number.isSafeInteger(n))
22039
- throw new Error(`invalid integer: ${n}`);
22040
- }
22041
- function aArr(input) {
22042
- if (!Array.isArray(input))
22043
- throw new Error("array expected");
22044
- }
22045
- function astrArr(label, input) {
22046
- if (!isArrayOf(true, input))
22047
- throw new Error(`${label}: array of strings expected`);
22048
- }
22049
- function anumArr(label, input) {
22050
- if (!isArrayOf(false, input))
22051
- throw new Error(`${label}: array of numbers expected`);
22052
- }
22053
- // @__NO_SIDE_EFFECTS__
22054
- function chain(...args) {
22055
- const id = (a) => a;
22056
- const wrap = (a, b) => (c) => a(b(c));
22057
- const encode = args.map((x) => x.encode).reduceRight(wrap, id);
22058
- const decode = args.map((x) => x.decode).reduce(wrap, id);
22059
- return { encode, decode };
22060
- }
22061
- // @__NO_SIDE_EFFECTS__
22062
- function alphabet(letters) {
22063
- const lettersA = typeof letters === "string" ? letters.split("") : letters;
22064
- const len = lettersA.length;
22065
- astrArr("alphabet", lettersA);
22066
- const indexes = new Map(lettersA.map((l, i) => [l, i]));
22067
- return {
22068
- encode: (digits) => {
22069
- aArr(digits);
22070
- return digits.map((i) => {
22071
- if (!Number.isSafeInteger(i) || i < 0 || i >= len)
22072
- throw new Error(`alphabet.encode: digit index outside alphabet "${i}". Allowed: ${letters}`);
22073
- return lettersA[i];
22074
- });
22075
- },
22076
- decode: (input) => {
22077
- aArr(input);
22078
- return input.map((letter) => {
22079
- astr("alphabet.decode", letter);
22080
- const i = indexes.get(letter);
22081
- if (i === void 0)
22082
- throw new Error(`Unknown letter: "${letter}". Allowed: ${letters}`);
22083
- return i;
22084
- });
24424
+ async getNetworkId() {
24425
+ return this.walletInstance.getNetworkId();
24426
+ }
24427
+ async getUtxos() {
24428
+ return this.walletInstance.getUtxos();
24429
+ }
24430
+ async getCollateral() {
24431
+ return this.walletInstance.getCollateral();
24432
+ }
24433
+ async getBalance() {
24434
+ return this.walletInstance.getBalance();
24435
+ }
24436
+ async getUsedAddresses() {
24437
+ return this.walletInstance.getUsedAddresses();
24438
+ }
24439
+ async getUnusedAddresses() {
24440
+ return this.walletInstance.getUnusedAddresses();
24441
+ }
24442
+ async getRewardAddresses() {
24443
+ return this.walletInstance.getRewardAddresses();
24444
+ }
24445
+ async getChangeAddress() {
24446
+ return this.walletInstance.getChangeAddress();
24447
+ }
24448
+ async signTx(data, partialSign) {
24449
+ return this.walletInstance.signTx(data, partialSign);
24450
+ }
24451
+ async signData(addressBech32, data) {
24452
+ return this.walletInstance.signData(addressBech32, data);
24453
+ }
24454
+ async submitTx(tx) {
24455
+ return this.walletInstance.submitTx(tx);
24456
+ }
24457
+ /**
24458
+ * Returns a list of wallets installed on user's device. Each wallet is an object with the following properties:
24459
+ * - A name is provided to display wallet's name on the user interface.
24460
+ * - A version is provided to display wallet's version on the user interface.
24461
+ * - An icon is provided to display wallet's icon on the user interface.
24462
+ *
24463
+ * @returns a list of wallet names
24464
+ */
24465
+ static getInstalledWallets() {
24466
+ if (globalThis === void 0) return [];
24467
+ if (globalThis.cardano === void 0) return [];
24468
+ let wallets = [];
24469
+ for (const key in globalThis.cardano) {
24470
+ try {
24471
+ const _wallet = globalThis.cardano[key];
24472
+ if (_wallet === void 0) continue;
24473
+ if (_wallet.name === void 0) continue;
24474
+ if (_wallet.icon === void 0) continue;
24475
+ if (_wallet.apiVersion === void 0) continue;
24476
+ wallets.push({
24477
+ id: key,
24478
+ name: key == "nufiSnap" ? "MetaMask" : _wallet.name,
24479
+ icon: _wallet.icon,
24480
+ version: _wallet.apiVersion
24481
+ });
24482
+ } catch (e) {
24483
+ }
22085
24484
  }
22086
- };
22087
- }
22088
- // @__NO_SIDE_EFFECTS__
22089
- function join(separator = "") {
22090
- astr("join", separator);
24485
+ return wallets;
24486
+ }
24487
+ /**
24488
+ * This is the entrypoint to start communication with the user's wallet. The wallet should request the user's permission to connect the web page to the user's wallet, and if permission has been granted, the wallet will be returned and exposing the full API for the app to use.
24489
+ *
24490
+ * Query BrowserWallet.getInstalledWallets() to get a list of available wallets, then provide the wallet name for which wallet the user would like to connect with.
24491
+ *
24492
+ * @param walletName - the name of the wallet to enable (e.g. "eternl", "begin")
24493
+ * @param extensions - optional, a list of CIPs that the wallet should support
24494
+ * @returns WalletInstance
24495
+ */
24496
+ static async enable(walletName, extensions = []) {
24497
+ try {
24498
+ const walletInstance = extensions.length > 0 ? await globalThis.cardano[walletName].enable({
24499
+ extensions
24500
+ }) : await globalThis.cardano[walletName].enable();
24501
+ if (walletInstance !== void 0)
24502
+ return new _CardanoBrowserWallet(walletInstance);
24503
+ throw new Error(`Couldn't create an instance of wallet: ${walletName}`);
24504
+ } catch (error) {
24505
+ throw new Error(
24506
+ `[BrowserWallet] An error occurred during enable: ${JSON.stringify(
24507
+ error
24508
+ )}.`
24509
+ );
24510
+ }
24511
+ }
24512
+ };
24513
+
24514
+ // src/cardano/wallet/browser/mesh-browser-wallet.ts
24515
+ import { Serialization as Serialization2, Cardano as Cardano3 } from "@cardano-sdk/core";
24516
+ import { HexBlob as HexBlob3 } from "@cardano-sdk/util";
24517
+
24518
+ // src/cardano/utils/converter.ts
24519
+ import { Cardano as Cardano2, Serialization } from "@cardano-sdk/core";
24520
+ import { Hash32ByteBase16 } from "@cardano-sdk/crypto";
24521
+ import { HexBlob as HexBlob2 } from "@cardano-sdk/util";
24522
+ var toTxUnspentOutput = (utxo) => {
24523
+ const txInput = new Serialization.TransactionInput(
24524
+ Cardano2.TransactionId(utxo.input.txHash),
24525
+ BigInt(utxo.input.outputIndex)
24526
+ );
24527
+ const txOutput = new Serialization.TransactionOutput(
24528
+ Cardano2.Address.fromBech32(utxo.output.address),
24529
+ toValue(utxo.output.amount)
24530
+ );
24531
+ if (utxo.output.dataHash !== void 0) {
24532
+ txOutput.setDatum(
24533
+ Serialization.Datum.fromCore(Hash32ByteBase16(utxo.output.dataHash))
24534
+ );
24535
+ }
24536
+ if (utxo.output.plutusData !== void 0) {
24537
+ const plutusData = Serialization.PlutusData.fromCbor(
24538
+ HexBlob2(utxo.output.plutusData)
24539
+ );
24540
+ const datum = new Serialization.Datum(void 0, plutusData);
24541
+ txOutput.setDatum(datum);
24542
+ }
24543
+ if (utxo.output.scriptRef !== void 0) {
24544
+ txOutput.setScriptRef(
24545
+ Serialization.Script.fromCbor(HexBlob2(utxo.output.scriptRef))
24546
+ );
24547
+ }
24548
+ return new Serialization.TransactionUnspentOutput(txInput, txOutput);
24549
+ };
24550
+ var fromTxUnspentOutput = (txUnspentOutput) => {
24551
+ const dataHash = txUnspentOutput.output().datum() ? txUnspentOutput.output().datum()?.asDataHash()?.toString() : void 0;
24552
+ const scriptRef = txUnspentOutput.output().scriptRef() ? txUnspentOutput.output().scriptRef()?.toCbor().toString() : void 0;
24553
+ const plutusData = txUnspentOutput.output().datum()?.asInlineData() ? txUnspentOutput.output().datum()?.asInlineData()?.toCbor().toString() : void 0;
22091
24554
  return {
22092
- encode: (from) => {
22093
- astrArr("join.decode", from);
22094
- return from.join(separator);
24555
+ input: {
24556
+ outputIndex: Number(txUnspentOutput.input().index()),
24557
+ txHash: txUnspentOutput.input().transactionId()
22095
24558
  },
22096
- decode: (to) => {
22097
- astr("join.decode", to);
22098
- return to.split(separator);
24559
+ output: {
24560
+ address: txUnspentOutput.output().address().toBech32(),
24561
+ amount: fromValue(txUnspentOutput.output().amount()),
24562
+ dataHash,
24563
+ // todo not sure if correct
24564
+ plutusData,
24565
+ // todo not sure if correct
24566
+ scriptRef
24567
+ // todo not sure if correct
22099
24568
  }
22100
24569
  };
24570
+ };
24571
+ var toValue = (assets) => {
24572
+ const multiAsset = /* @__PURE__ */ new Map();
24573
+ assets.filter((asset) => asset.unit !== "lovelace" && asset.unit !== "").forEach((asset) => {
24574
+ multiAsset.set(Cardano2.AssetId(asset.unit), BigInt(asset.quantity));
24575
+ });
24576
+ const lovelace = assets.find(
24577
+ (asset) => asset.unit === "lovelace" || asset.unit === ""
24578
+ );
24579
+ const value = new Serialization.Value(
24580
+ BigInt(lovelace ? lovelace.quantity : 0)
24581
+ );
24582
+ if (assets.length > 1 || !lovelace) {
24583
+ value.setMultiasset(multiAsset);
24584
+ }
24585
+ return value;
24586
+ };
24587
+ var fromValue = (value) => {
24588
+ const assets = [
24589
+ { unit: "lovelace", quantity: value.coin().toString() }
24590
+ ];
24591
+ const multiAsset = value.multiasset();
24592
+ if (multiAsset !== void 0) {
24593
+ const _assets = Array.from(multiAsset.keys());
24594
+ for (let i = 0; i < _assets.length; i += 1) {
24595
+ const assetId = _assets[i];
24596
+ if (assetId !== void 0) {
24597
+ const assetQuantity = multiAsset.get(assetId);
24598
+ if (assetQuantity !== void 0) {
24599
+ assets.push({
24600
+ unit: assetId,
24601
+ quantity: assetQuantity.toString()
24602
+ });
24603
+ }
24604
+ }
24605
+ }
24606
+ }
24607
+ return assets;
24608
+ };
24609
+
24610
+ // src/cardano/wallet/browser/mesh-browser-wallet.ts
24611
+ var MeshCardanoBrowserWallet = class _MeshCardanoBrowserWallet extends CardanoBrowserWallet {
24612
+ constructor(walletInstance) {
24613
+ super(walletInstance);
24614
+ }
24615
+ static async enable(walletName, extensions = []) {
24616
+ const walletInstance = await super.enable(walletName, extensions);
24617
+ return new _MeshCardanoBrowserWallet(walletInstance);
24618
+ }
24619
+ async getUtxosMesh() {
24620
+ const utxosCbor = await this.getUtxos();
24621
+ return utxosCbor.map(
24622
+ (utxoCbor) => fromTxUnspentOutput(
24623
+ Serialization2.TransactionUnspentOutput.fromCbor(HexBlob3(utxoCbor))
24624
+ )
24625
+ );
24626
+ }
24627
+ async getCollateralMesh() {
24628
+ const collateralCbor = await this.getCollateral();
24629
+ return collateralCbor.map(
24630
+ (utxoCbor) => fromTxUnspentOutput(
24631
+ Serialization2.TransactionUnspentOutput.fromCbor(HexBlob3(utxoCbor))
24632
+ )
24633
+ );
24634
+ }
24635
+ async getBalanceMesh() {
24636
+ const balanceCbor = await this.getBalance();
24637
+ const value = Serialization2.Value.fromCbor(HexBlob3(balanceCbor));
24638
+ return fromValue(value);
24639
+ }
24640
+ async getUsedAddressesBech32() {
24641
+ const addressesHex = await this.getUsedAddresses();
24642
+ return addressesHex.map((addr) => {
24643
+ const cardanoAddr = Cardano3.Address.fromBytes(HexBlob3(addr));
24644
+ return cardanoAddr.toBech32();
24645
+ });
24646
+ }
24647
+ async getUnusedAddressesBech32() {
24648
+ const addressesHex = await this.getUnusedAddresses();
24649
+ return addressesHex.map((addr) => {
24650
+ const cardanoAddr = Cardano3.Address.fromBytes(HexBlob3(addr));
24651
+ return cardanoAddr.toBech32();
24652
+ });
24653
+ }
24654
+ async getChangeAddressBech32() {
24655
+ const addressHex = await this.getChangeAddress();
24656
+ const cardanoAddr = Cardano3.Address.fromBytes(HexBlob3(addressHex));
24657
+ return cardanoAddr.toBech32();
24658
+ }
24659
+ async getRewardAddressesBech32() {
24660
+ const addresses = await this.getRewardAddresses();
24661
+ return addresses.map((addr) => {
24662
+ const cardanoAddr = Cardano3.Address.fromBytes(HexBlob3(addr));
24663
+ return cardanoAddr.toBech32();
24664
+ });
24665
+ }
24666
+ async signTxReturnFullTx(tx, partialSign = false) {
24667
+ const witnessCbor = await this.signTx(tx, partialSign);
24668
+ const addedWitnesses = Serialization2.TransactionWitnessSet.fromCbor(
24669
+ HexBlob3(witnessCbor)
24670
+ );
24671
+ const transaction = Serialization2.Transaction.fromCbor(
24672
+ Serialization2.TxCBOR(tx)
24673
+ );
24674
+ let witnessSet = transaction.witnessSet();
24675
+ let witnessSetVkeys = witnessSet.vkeys();
24676
+ let witnessSetVkeysValues = witnessSetVkeys ? [
24677
+ ...witnessSetVkeys.values(),
24678
+ ...addedWitnesses.vkeys()?.values() ?? []
24679
+ ] : [...addedWitnesses.vkeys()?.values() ?? []];
24680
+ witnessSet.setVkeys(
24681
+ Serialization2.CborSet.fromCore(
24682
+ witnessSetVkeysValues.map((vkw) => vkw.toCore()),
24683
+ Serialization2.VkeyWitness.fromCore
24684
+ )
24685
+ );
24686
+ const signedTx = new Serialization2.Transaction(
24687
+ transaction.body(),
24688
+ witnessSet,
24689
+ transaction.auxiliaryData()
24690
+ );
24691
+ return signedTx.toCbor();
24692
+ }
24693
+ };
24694
+
24695
+ // src/cardano/wallet/mesh/cardano-base-wallet.ts
24696
+ import { Cardano as Cardano6, Serialization as Serialization6, setInConwayEra as setInConwayEra5 } from "@cardano-sdk/core";
24697
+
24698
+ // src/utils/value.ts
24699
+ import { Serialization as Serialization3 } from "@cardano-sdk/core";
24700
+ function mergeValue(a, b) {
24701
+ const ma = a.multiasset() ?? /* @__PURE__ */ new Map();
24702
+ b.multiasset()?.forEach((v, k) => {
24703
+ const newVal = (ma.get(k) ?? 0n) + v;
24704
+ if (newVal == 0n) {
24705
+ ma.delete(k);
24706
+ } else {
24707
+ ma.set(k, newVal);
24708
+ }
24709
+ });
24710
+ return new Serialization3.Value(
24711
+ BigInt(a.coin()) + BigInt(b.coin()),
24712
+ ma.size > 0 ? ma : void 0
24713
+ );
22101
24714
  }
22102
- var gcd = (a, b) => b === 0 ? a : gcd(b, a % b);
22103
- var radix2carry = /* @__NO_SIDE_EFFECTS__ */ (from, to) => from + (to - gcd(from, to));
22104
- var powers = /* @__PURE__ */ (() => {
22105
- let res = [];
22106
- for (let i = 0; i < 40; i++)
22107
- res.push(2 ** i);
22108
- return res;
22109
- })();
22110
- function convertRadix2(data, from, to, padding) {
22111
- aArr(data);
22112
- if (from <= 0 || from > 32)
22113
- throw new Error(`convertRadix2: wrong from=${from}`);
22114
- if (to <= 0 || to > 32)
22115
- throw new Error(`convertRadix2: wrong to=${to}`);
22116
- if (/* @__PURE__ */ radix2carry(from, to) > 32) {
22117
- throw new Error(`convertRadix2: carry overflow from=${from} to=${to} carryBits=${/* @__PURE__ */ radix2carry(from, to)}`);
24715
+
24716
+ // src/cardano/address/single-address-manager.ts
24717
+ import { setInConwayEra as setInConwayEra3 } from "@cardano-sdk/core";
24718
+ var AddressManager = class _AddressManager {
24719
+ static async create(config) {
24720
+ let paymentSigner;
24721
+ let paymentCredential;
24722
+ if (config.addressSource.type === "credentials") {
24723
+ if (config.addressSource.paymentCredential.type === "scriptHash") {
24724
+ throw new Error(
24725
+ "Payment credential cannot be a script hash. Payment credentials must be key hashes that can sign transactions."
24726
+ );
24727
+ } else {
24728
+ paymentSigner = config.addressSource.paymentCredential.signer;
24729
+ paymentCredential = {
24730
+ type: 0 /* KeyHash */,
24731
+ hash: await paymentSigner.getPublicKeyHash()
24732
+ };
24733
+ }
24734
+ } else {
24735
+ paymentSigner = await config.addressSource.secretManager.getSigner([
24736
+ ...DEFAULT_PAYMENT_KEY_DERIVATION_PATH,
24737
+ 0
24738
+ ]);
24739
+ paymentCredential = {
24740
+ type: 0 /* KeyHash */,
24741
+ hash: await paymentSigner.getPublicKeyHash()
24742
+ };
24743
+ }
24744
+ let stakeSigner = void 0;
24745
+ let stakeCredential;
24746
+ if (config.addressSource.type === "credentials" && config.addressSource.stakeCredential) {
24747
+ if (config.addressSource.stakeCredential.type === "scriptHash") {
24748
+ stakeCredential = {
24749
+ type: 1 /* ScriptHash */,
24750
+ hash: config.addressSource.stakeCredential.scriptHash
24751
+ };
24752
+ } else {
24753
+ stakeSigner = config.addressSource.stakeCredential.signer;
24754
+ stakeCredential = {
24755
+ type: 0 /* KeyHash */,
24756
+ hash: await stakeSigner.getPublicKeyHash()
24757
+ };
24758
+ }
24759
+ } else if (config.addressSource.type === "secretManager") {
24760
+ stakeSigner = await config.addressSource.secretManager.getSigner([
24761
+ ...DEFAULT_STAKE_KEY_DERIVATION_PATH,
24762
+ 0
24763
+ ]);
24764
+ stakeCredential = {
24765
+ type: 0 /* KeyHash */,
24766
+ hash: await stakeSigner.getPublicKeyHash()
24767
+ };
24768
+ }
24769
+ let drepSigner = void 0;
24770
+ let drepCredential;
24771
+ if (config.addressSource.type === "credentials" && config.addressSource.drepCredential) {
24772
+ if (config.addressSource.drepCredential.type === "scriptHash") {
24773
+ drepCredential = {
24774
+ type: 1 /* ScriptHash */,
24775
+ hash: config.addressSource.drepCredential.scriptHash
24776
+ };
24777
+ } else {
24778
+ drepSigner = config.addressSource.drepCredential.signer;
24779
+ drepCredential = {
24780
+ type: 0 /* KeyHash */,
24781
+ hash: await drepSigner.getPublicKeyHash()
24782
+ };
24783
+ }
24784
+ } else if (config.addressSource.type === "secretManager") {
24785
+ drepSigner = await config.addressSource.secretManager.getSigner([
24786
+ ...DEFAULT_DREP_KEY_DERIVATION_PATH,
24787
+ 0
24788
+ ]);
24789
+ drepCredential = {
24790
+ type: 0 /* KeyHash */,
24791
+ hash: await drepSigner.getPublicKeyHash()
24792
+ };
24793
+ }
24794
+ const networkId = config.networkId;
24795
+ return new _AddressManager(
24796
+ paymentCredential,
24797
+ stakeCredential,
24798
+ drepCredential,
24799
+ paymentSigner,
24800
+ networkId,
24801
+ stakeSigner,
24802
+ drepSigner
24803
+ );
22118
24804
  }
22119
- let carry = 0;
22120
- let pos = 0;
22121
- const max = powers[from];
22122
- const mask = powers[to] - 1;
22123
- const res = [];
22124
- for (const n of data) {
22125
- anumber(n);
22126
- if (n >= max)
22127
- throw new Error(`convertRadix2: invalid data word=${n} from=${from}`);
22128
- carry = carry << from | n;
22129
- if (pos + from > 32)
22130
- throw new Error(`convertRadix2: carry overflow pos=${pos} from=${from}`);
22131
- pos += from;
22132
- for (; pos >= to; pos -= to)
22133
- res.push((carry >> pos - to & mask) >>> 0);
22134
- const pow = powers[pos];
22135
- if (pow === void 0)
22136
- throw new Error("invalid carry");
22137
- carry &= pow - 1;
24805
+ constructor(paymentCredential, stakeCredential, drepCredential, paymentSigner, networkId, stakeSigner, drepSigner) {
24806
+ setInConwayEra3(true);
24807
+ this.paymentCredential = paymentCredential;
24808
+ this.stakeCredential = stakeCredential;
24809
+ this.drepCredential = drepCredential;
24810
+ this.paymentSigner = paymentSigner;
24811
+ this.stakeSigner = stakeSigner;
24812
+ this.drepSigner = drepSigner;
24813
+ this.networkId = networkId;
24814
+ }
24815
+ async getNextAddress(addressType) {
24816
+ return new CardanoAddress(
24817
+ addressType,
24818
+ this.networkId,
24819
+ this.paymentCredential,
24820
+ this.stakeCredential
24821
+ );
24822
+ }
24823
+ async getChangeAddress(addressType) {
24824
+ return new CardanoAddress(
24825
+ addressType,
24826
+ this.networkId,
24827
+ this.paymentCredential,
24828
+ this.stakeCredential
24829
+ );
24830
+ }
24831
+ async getRewardAccount() {
24832
+ return new CardanoAddress(
24833
+ 2 /* Reward */,
24834
+ this.networkId,
24835
+ this.paymentCredential,
24836
+ this.stakeCredential
24837
+ );
24838
+ }
24839
+ asyncGetAllUsedAddresses() {
24840
+ return Promise.all([
24841
+ this.getNextAddress(1 /* Base */),
24842
+ this.getNextAddress(0 /* Enterprise */)
24843
+ ]);
24844
+ }
24845
+ //TODO: Implement getDrepId
24846
+ //async getDrepId(): Promise<string> {
24847
+ //}
24848
+ async getCredentialsSigners(pubkeyHashes) {
24849
+ const signersMap = /* @__PURE__ */ new Map();
24850
+ if (this.paymentCredential.type === 0 /* KeyHash */ && pubkeyHashes.has(this.paymentCredential.hash)) {
24851
+ signersMap.set(this.paymentCredential.hash, this.paymentSigner);
24852
+ }
24853
+ if (this.stakeCredential && this.stakeCredential.type === 0 /* KeyHash */ && pubkeyHashes.has(this.stakeCredential.hash) && this.stakeSigner) {
24854
+ signersMap.set(this.stakeCredential.hash, this.stakeSigner);
24855
+ }
24856
+ if (this.drepCredential && this.drepCredential.type === 0 /* KeyHash */ && pubkeyHashes.has(this.drepCredential.hash) && this.drepSigner) {
24857
+ signersMap.set(this.drepCredential.hash, this.drepSigner);
24858
+ }
24859
+ return signersMap;
24860
+ }
24861
+ };
24862
+
24863
+ // src/cardano/signer/cardano-signer.ts
24864
+ import { Serialization as Serialization4, setInConwayEra as setInConwayEra4 } from "@cardano-sdk/core";
24865
+ import { Ed25519PublicKeyHex, Ed25519SignatureHex as Ed25519SignatureHex2 } from "@cardano-sdk/crypto";
24866
+ import { HexBlob as HexBlob5 } from "@cardano-sdk/util";
24867
+ import {
24868
+ CborBytes as CborBytes2,
24869
+ CborMap as CborMap2,
24870
+ CborNegInt as CborNegInt2,
24871
+ CborText as CborText2,
24872
+ CborUInt as CborUInt2
24873
+ } from "@harmoniclabs/cbor";
24874
+
24875
+ // node_modules/@meshsdk/common/dist/index.js
24876
+ var import_bech32 = __toESM(require_dist(), 1);
24877
+ var import_blake2b = __toESM(require_blake2b2(), 1);
24878
+ var import_blakejs = __toESM(require_blakejs(), 1);
24879
+ var import_bip392 = __toESM(require_src(), 1);
24880
+ var stringToHex = (str) => Buffer.from(str, "utf8").toString("hex");
24881
+ var isHexString = (hex) => /^[0-9A-F]*$/i.test(hex);
24882
+ var SLOT_CONFIG_NETWORK = {
24883
+ mainnet: {
24884
+ zeroTime: 1596059091e3,
24885
+ zeroSlot: 4492800,
24886
+ slotLength: 1e3,
24887
+ startEpoch: 208,
24888
+ epochLength: 432e3
24889
+ },
24890
+ // Starting at Shelley era
24891
+ preview: {
24892
+ zeroTime: 1666656e6,
24893
+ zeroSlot: 0,
24894
+ slotLength: 1e3,
24895
+ startEpoch: 0,
24896
+ epochLength: 86400
24897
+ },
24898
+ // Starting at Shelley era
24899
+ preprod: {
24900
+ zeroTime: 16540416e5 + 1728e6,
24901
+ zeroSlot: 86400,
24902
+ slotLength: 1e3,
24903
+ startEpoch: 4,
24904
+ epochLength: 432e3
24905
+ },
24906
+ // Starting at Shelley era
24907
+ /** Customizable slot config (Initialized with 0 values). */
24908
+ testnet: {
24909
+ zeroTime: 0,
24910
+ zeroSlot: 0,
24911
+ slotLength: 0,
24912
+ startEpoch: 0,
24913
+ epochLength: 0
22138
24914
  }
22139
- carry = carry << to - pos & mask;
22140
- if (!padding && pos >= from)
22141
- throw new Error("Excess padding");
22142
- if (!padding && carry > 0)
22143
- throw new Error(`Non-zero padding: ${carry}`);
22144
- if (padding && pos > 0)
22145
- res.push(carry >>> 0);
22146
- return res;
22147
- }
22148
- // @__NO_SIDE_EFFECTS__
22149
- function radix2(bits, revPadding = false) {
22150
- anumber(bits);
22151
- if (bits <= 0 || bits > 32)
22152
- throw new Error("radix2: bits should be in (0..32]");
22153
- if (/* @__PURE__ */ radix2carry(8, bits) > 32 || /* @__PURE__ */ radix2carry(bits, 8) > 32)
22154
- throw new Error("radix2: carry overflow");
22155
- return {
22156
- encode: (bytes) => {
22157
- if (!isBytes(bytes))
22158
- throw new Error("radix2.encode input should be Uint8Array");
22159
- return convertRadix2(Array.from(bytes), 8, bits, !revPadding);
22160
- },
22161
- decode: (digits) => {
22162
- anumArr("radix2.decode", digits);
22163
- return Uint8Array.from(convertRadix2(digits, bits, 8, revPadding));
24915
+ };
24916
+
24917
+ // src/cardano/signer/cip-8.ts
24918
+ var import_blakejs2 = __toESM(require_blakejs(), 1);
24919
+ import * as Crypto from "@cardano-sdk/crypto";
24920
+ import { HexBlob as HexBlob4 } from "@cardano-sdk/util";
24921
+ import {
24922
+ Cbor,
24923
+ CborArray,
24924
+ CborBytes,
24925
+ CborMap,
24926
+ CborNegInt,
24927
+ CborSimple,
24928
+ CborText,
24929
+ CborUInt,
24930
+ isRawCborArray,
24931
+ isRawCborMap
24932
+ } from "@harmoniclabs/cbor";
24933
+ import JSONBig from "json-bigint";
24934
+ var CoseSign1 = class _CoseSign1 {
24935
+ constructor(payload) {
24936
+ this.protectedMap = payload.protectedMap;
24937
+ this.unProtectedMap = payload.unProtectedMap;
24938
+ this.payload = payload.payload;
24939
+ if (!this.unProtectedMap.map.find((value) => {
24940
+ return JSONBig.stringify(value.k) === JSONBig.stringify(new CborText("hashed"));
24941
+ })) {
24942
+ this.unProtectedMap.map.push({
24943
+ k: new CborText("hashed"),
24944
+ v: new CborSimple(false)
24945
+ });
22164
24946
  }
22165
- };
22166
- }
22167
- function unsafeWrapper(fn) {
22168
- afn(fn);
22169
- return function(...args) {
24947
+ this.signature = payload.signature;
24948
+ }
24949
+ static fromCbor(cbor) {
24950
+ const decoded = Cbor.parse(cbor);
24951
+ if (!isRawCborArray(decoded.toRawObj()))
24952
+ throw Error("Invalid CBOR");
24953
+ if (decoded.array.length !== 4) throw Error("Invalid COSE_SIGN1");
24954
+ let protectedMap;
24955
+ const protectedSerialized = decoded.array[0];
22170
24956
  try {
22171
- return fn.apply(null, args);
22172
- } catch (e) {
24957
+ protectedMap = Cbor.parse(protectedSerialized.bytes);
24958
+ if (!isRawCborMap(protectedMap.toRawObj())) {
24959
+ throw Error();
24960
+ }
24961
+ } catch (error) {
24962
+ throw Error("Invalid protected");
22173
24963
  }
22174
- };
22175
- }
22176
- var BECH_ALPHABET = /* @__PURE__ */ chain(/* @__PURE__ */ alphabet("qpzry9x8gf2tvdw0s3jn54khce6mua7l"), /* @__PURE__ */ join(""));
22177
- var POLYMOD_GENERATORS = [996825010, 642813549, 513874426, 1027748829, 705979059];
22178
- function bech32Polymod(pre) {
22179
- const b = pre >> 25;
22180
- let chk = (pre & 33554431) << 5;
22181
- for (let i = 0; i < POLYMOD_GENERATORS.length; i++) {
22182
- if ((b >> i & 1) === 1)
22183
- chk ^= POLYMOD_GENERATORS[i];
24964
+ let unProtectedMap = decoded.array[1];
24965
+ if (!isRawCborMap(unProtectedMap.toRawObj()))
24966
+ throw Error("Invalid unprotected");
24967
+ const payload = decoded.array[2];
24968
+ const signature = decoded.array[3];
24969
+ return new _CoseSign1({
24970
+ protectedMap,
24971
+ unProtectedMap,
24972
+ payload,
24973
+ signature
24974
+ });
22184
24975
  }
22185
- return chk;
22186
- }
22187
- function bechChecksum(prefix, words, encodingConst = 1) {
22188
- const len = prefix.length;
22189
- let chk = 1;
22190
- for (let i = 0; i < len; i++) {
22191
- const c = prefix.charCodeAt(i);
22192
- if (c < 33 || c > 126)
22193
- throw new Error(`Invalid prefix (${prefix})`);
22194
- chk = bech32Polymod(chk) ^ c >> 5;
24976
+ createSigStructure(externalAad = Buffer.alloc(0)) {
24977
+ let protectedSerialized = new CborBytes(Buffer.alloc(0));
24978
+ if (this.protectedMap.map.length !== 0) {
24979
+ protectedSerialized = new CborBytes(
24980
+ Cbor.encode(this.protectedMap).toBuffer()
24981
+ );
24982
+ }
24983
+ if (!this.payload) throw Error("Invalid payload");
24984
+ const structure = new CborArray([
24985
+ new CborText("Signature1"),
24986
+ protectedSerialized,
24987
+ new CborBytes(externalAad),
24988
+ this.payload
24989
+ ]);
24990
+ return Buffer.from(Cbor.encode(structure).toBuffer());
22195
24991
  }
22196
- chk = bech32Polymod(chk);
22197
- for (let i = 0; i < len; i++)
22198
- chk = bech32Polymod(chk) ^ prefix.charCodeAt(i) & 31;
22199
- for (let v of words)
22200
- chk = bech32Polymod(chk) ^ v;
22201
- for (let i = 0; i < 6; i++)
22202
- chk = bech32Polymod(chk);
22203
- chk ^= encodingConst;
22204
- return BECH_ALPHABET.encode(convertRadix2([chk % powers[30]], 30, 5, false));
22205
- }
22206
- // @__NO_SIDE_EFFECTS__
22207
- function genBech32(encoding) {
22208
- const ENCODING_CONST = encoding === "bech32" ? 1 : 734539939;
22209
- const _words = /* @__PURE__ */ radix2(5);
22210
- const fromWords = _words.decode;
22211
- const toWords = _words.encode;
22212
- const fromWordsUnsafe = unsafeWrapper(fromWords);
22213
- function encode(prefix, words, limit = 90) {
22214
- astr("bech32.encode prefix", prefix);
22215
- if (isBytes(words))
22216
- words = Array.from(words);
22217
- anumArr("bech32.encode", words);
22218
- const plen = prefix.length;
22219
- if (plen === 0)
22220
- throw new TypeError(`Invalid prefix length ${plen}`);
22221
- const actualLength = plen + 7 + words.length;
22222
- if (limit !== false && actualLength > limit)
22223
- throw new TypeError(`Length ${actualLength} exceeds limit ${limit}`);
22224
- const lowered = prefix.toLowerCase();
22225
- const sum = bechChecksum(lowered, words, ENCODING_CONST);
22226
- return `${lowered}1${BECH_ALPHABET.encode(words)}${sum}`;
24992
+ buildMessage(signature) {
24993
+ this.signature = new CborBytes(signature);
24994
+ let protectedSerialized = new CborBytes(Buffer.alloc(0));
24995
+ if (this.protectedMap.map.length !== 0) {
24996
+ protectedSerialized = new CborBytes(
24997
+ Cbor.encode(this.protectedMap).toBuffer()
24998
+ );
24999
+ }
25000
+ if (!this.payload) throw Error("Invalid payload");
25001
+ const coseSign1 = new CborArray([
25002
+ protectedSerialized,
25003
+ this.unProtectedMap,
25004
+ this.payload,
25005
+ this.signature
25006
+ ]);
25007
+ return Buffer.from(Cbor.encode(coseSign1).toBuffer());
22227
25008
  }
22228
- function decode(str, limit = 90) {
22229
- astr("bech32.decode input", str);
22230
- const slen = str.length;
22231
- if (slen < 8 || limit !== false && slen > limit)
22232
- throw new TypeError(`invalid string length: ${slen} (${str}). Expected (8..${limit})`);
22233
- const lowered = str.toLowerCase();
22234
- if (str !== lowered && str !== str.toUpperCase())
22235
- throw new Error(`String must be lowercase or uppercase`);
22236
- const sepIndex = lowered.lastIndexOf("1");
22237
- if (sepIndex === 0 || sepIndex === -1)
22238
- throw new Error(`Letter "1" must be present between prefix and data only`);
22239
- const prefix = lowered.slice(0, sepIndex);
22240
- const data = lowered.slice(sepIndex + 1);
22241
- if (data.length < 6)
22242
- throw new Error("Data must be at least 6 characters long");
22243
- const words = BECH_ALPHABET.decode(data).slice(0, -6);
22244
- const sum = bechChecksum(prefix, words, ENCODING_CONST);
22245
- if (!data.endsWith(sum))
22246
- throw new Error(`Invalid checksum in ${str}: expected "${sum}"`);
22247
- return { prefix, words };
25009
+ verifySignature({
25010
+ externalAad = Buffer.alloc(0),
25011
+ publicKeyBuffer
25012
+ } = {}) {
25013
+ if (!publicKeyBuffer) {
25014
+ publicKeyBuffer = this.getPublicKey();
25015
+ }
25016
+ if (!publicKeyBuffer) throw Error("Public key not found");
25017
+ if (!this.signature) throw Error("Signature not found");
25018
+ const publicKey = new Crypto.Ed25519PublicKey(publicKeyBuffer);
25019
+ return publicKey.verify(
25020
+ new Crypto.Ed25519Signature(this.signature.bytes),
25021
+ HexBlob4(Buffer.from(this.createSigStructure(externalAad)).toString("hex"))
25022
+ );
22248
25023
  }
22249
- const decodeUnsafe = unsafeWrapper(decode);
22250
- function decodeToBytes(str) {
22251
- const { prefix, words } = decode(str, false);
22252
- return { prefix, words, bytes: fromWords(words) };
25024
+ hashPayload() {
25025
+ if (!this.unProtectedMap) throw Error("Invalid unprotected map");
25026
+ if (!this.payload) throw Error("Invalid payload");
25027
+ const hashedIndex = this.unProtectedMap.map.findIndex((value) => {
25028
+ return JSONBig.stringify(value.k) === JSONBig.stringify(new CborText("hashed"));
25029
+ });
25030
+ const hashed = this.unProtectedMap.map[hashedIndex];
25031
+ if (hashed && JSONBig.stringify(hashed.v) === JSONBig.stringify(new CborSimple(true)))
25032
+ throw Error("Payload already hashed");
25033
+ if (hashed && JSONBig.stringify(hashed.v) === JSONBig.stringify(new CborSimple(true)) != false)
25034
+ throw Error("Invalid unprotected map");
25035
+ this.unProtectedMap.map.splice(hashedIndex, 1);
25036
+ const hash = (0, import_blakejs2.blake2b)(this.payload.bytes, void 0, 24);
25037
+ this.payload = new CborBytes(hash);
22253
25038
  }
22254
- function encodeFromBytes(prefix, bytes) {
22255
- return encode(prefix, toWords(bytes));
25039
+ getAddress() {
25040
+ const address = this.protectedMap.map.find((value) => {
25041
+ return JSONBig.stringify(value.k) === JSONBig.stringify(new CborText("address"));
25042
+ });
25043
+ if (!address) throw Error("Address not found");
25044
+ return Buffer.from(address.v.bytes);
22256
25045
  }
22257
- return {
22258
- encode,
22259
- decode,
22260
- encodeFromBytes,
22261
- decodeToBytes,
22262
- decodeUnsafe,
22263
- fromWords,
22264
- fromWordsUnsafe,
22265
- toWords
22266
- };
22267
- }
22268
- var bech32 = /* @__PURE__ */ genBech32("bech32");
22269
-
22270
- // src/bip32/in-memory-bip32.ts
22271
- var import_bip39 = __toESM(require_src(), 1);
25046
+ getPublicKey() {
25047
+ const publicKey = this.protectedMap.map.find((value) => {
25048
+ return JSONBig.stringify(value.k) === JSONBig.stringify(new CborUInt(4));
25049
+ });
25050
+ if (!publicKey) throw Error("Public key not found");
25051
+ return Buffer.from(publicKey.v.bytes);
25052
+ }
25053
+ getSignature() {
25054
+ return this.signature ? Buffer.from(this.signature.bytes) : void 0;
25055
+ }
25056
+ getPayload() {
25057
+ return this.payload ? Buffer.from(this.payload.bytes) : null;
25058
+ }
25059
+ };
25060
+ var getCoseKeyFromPublicKey = (cbor) => {
25061
+ const coseKeyMap = [];
25062
+ coseKeyMap.push({ k: new CborUInt(1), v: new CborUInt(1) });
25063
+ coseKeyMap.push({ k: new CborUInt(3), v: new CborNegInt(-8) });
25064
+ coseKeyMap.push({ k: new CborNegInt(-1), v: new CborUInt(6) });
25065
+ coseKeyMap.push({
25066
+ k: new CborNegInt(-2),
25067
+ v: new CborBytes(Buffer.from(cbor, "hex"))
25068
+ });
25069
+ return Buffer.from(Cbor.encode(new CborMap(coseKeyMap)).toBuffer());
25070
+ };
22272
25071
 
22273
- // src/utils/constants.ts
22274
- var HARDENED_OFFSET = 2147483648;
22275
- var DEFAULT_ACCOUNT_KEY_DERIVATION_PATH = [
22276
- 1852 + HARDENED_OFFSET,
22277
- 1815 + HARDENED_OFFSET,
22278
- 0 + HARDENED_OFFSET
22279
- ];
22280
- var DEFAULT_PAYMENT_KEY_DERIVATION_PATH = [
22281
- ...DEFAULT_ACCOUNT_KEY_DERIVATION_PATH,
22282
- 0
22283
- ];
22284
- var DEFAULT_STAKE_KEY_DERIVATION_PATH = [
22285
- ...DEFAULT_ACCOUNT_KEY_DERIVATION_PATH,
22286
- 2
22287
- ];
22288
- var DEFAULT_DREP_KEY_DERIVATION_PATH = [
22289
- ...DEFAULT_ACCOUNT_KEY_DERIVATION_PATH,
22290
- 3
22291
- ];
25072
+ // src/cardano/signer/cardano-signer.ts
25073
+ var CardanoSigner = class {
25074
+ constructor() {
25075
+ setInConwayEra4(true);
25076
+ }
25077
+ static async signTx(tx, signers, returnFullTx = false) {
25078
+ const cardanoTx = Serialization4.Transaction.fromCbor(
25079
+ Serialization4.TxCBOR(tx)
25080
+ );
25081
+ const txHash = cardanoTx.body().hash();
25082
+ const vkeyWitnesses = [];
25083
+ for (const signer of signers) {
25084
+ vkeyWitnesses.push([
25085
+ Ed25519PublicKeyHex(await signer.getPublicKey()),
25086
+ Ed25519SignatureHex2(await signer.sign(HexBlob5(txHash)))
25087
+ ]);
25088
+ }
25089
+ if (returnFullTx) {
25090
+ const txWitnessSet2 = cardanoTx.witnessSet();
25091
+ let witnessSetVkeys = txWitnessSet2.vkeys();
25092
+ let witnessSetVkeysValues = witnessSetVkeys ? [
25093
+ ...witnessSetVkeys.values().map((vkw) => vkw.toCore()),
25094
+ ...vkeyWitnesses
25095
+ ] : vkeyWitnesses;
25096
+ txWitnessSet2.setVkeys(
25097
+ Serialization4.CborSet.fromCore(
25098
+ witnessSetVkeysValues,
25099
+ Serialization4.VkeyWitness.fromCore
25100
+ )
25101
+ );
25102
+ return new Serialization4.Transaction(
25103
+ cardanoTx.body(),
25104
+ txWitnessSet2,
25105
+ cardanoTx.auxiliaryData()
25106
+ ).toCbor();
25107
+ }
25108
+ const txWitnessSet = new Serialization4.TransactionWitnessSet();
25109
+ txWitnessSet.setVkeys(
25110
+ Serialization4.CborSet.fromCore(
25111
+ vkeyWitnesses,
25112
+ Serialization4.VkeyWitness.fromCore
25113
+ )
25114
+ );
25115
+ return txWitnessSet.toCbor();
25116
+ }
25117
+ static async signData(data, addressHex, signer) {
25118
+ const hexData = isHexString(data) ? data : stringToHex(data);
25119
+ const payload = Buffer.from(hexData, "hex");
25120
+ const publicKey = Buffer.from(await signer.getPublicKey(), "hex");
25121
+ const protectedMap = [];
25122
+ protectedMap.push({ k: new CborUInt2(1), v: new CborNegInt2(-8) });
25123
+ protectedMap.push({
25124
+ k: new CborText2("address"),
25125
+ v: new CborBytes2(Buffer.from(addressHex, "hex"))
25126
+ });
25127
+ const coseSign1Builder = new CoseSign1({
25128
+ protectedMap: new CborMap2(protectedMap),
25129
+ unProtectedMap: new CborMap2([]),
25130
+ payload: new CborBytes2(payload)
25131
+ });
25132
+ const signature = await signer.sign(
25133
+ HexBlob5(
25134
+ Buffer.from(coseSign1Builder.createSigStructure()).toString("hex")
25135
+ )
25136
+ );
25137
+ const coseSignature = coseSign1Builder.buildMessage(Buffer.from(signature, "hex")).toString("hex");
25138
+ return {
25139
+ key: getCoseKeyFromPublicKey(publicKey.toString("hex")).toString("hex"),
25140
+ signature: coseSignature
25141
+ };
25142
+ }
25143
+ };
22292
25144
 
22293
- // src/interfaces/secret-manager.ts
22294
- var derivationPathVectorFromString = (path) => {
22295
- if (!/^m?\/\d+(\/\d+)*$/.test(path)) {
22296
- throw new Error(`Invalid derivation path: ${path}`);
25145
+ // src/cardano/utils/transaction-signers.ts
25146
+ import { Cardano as Cardano5 } from "@cardano-sdk/core";
25147
+ async function getRequiredSignersFromInputs(txBody, fetcher) {
25148
+ const requiredSigners = /* @__PURE__ */ new Set();
25149
+ let inputs = txBody.inputs().values();
25150
+ if (txBody.collateral()) {
25151
+ inputs = [...inputs, ...txBody.collateral().values()];
22297
25152
  }
22298
- let pathString = path;
22299
- if (pathString.startsWith("m/")) {
22300
- pathString = pathString.slice(2);
25153
+ const transactionIds = /* @__PURE__ */ new Set();
25154
+ for (const input of inputs) {
25155
+ transactionIds.add(input.transactionId());
22301
25156
  }
22302
- return pathString.split("/").map((part) => {
22303
- if (part.endsWith("'")) {
22304
- return Number.parseInt(part.slice(0, -1)) + HARDENED_OFFSET;
25157
+ let utxos = [];
25158
+ for (const txId of transactionIds) {
25159
+ const fetchedUtxos = await fetcher.fetchUTxOs(txId);
25160
+ if (fetchedUtxos) {
25161
+ utxos.push(...fetchedUtxos);
22305
25162
  } else {
22306
- return Number.parseInt(part);
25163
+ throw new Error(
25164
+ `[TransactionSigners] Transaction not found for transaction id: ${txId}`
25165
+ );
22307
25166
  }
25167
+ }
25168
+ utxos = utxos.filter((utxo) => {
25169
+ return inputs.some((input) => {
25170
+ return input.transactionId() === utxo.input.txHash && input.index() === BigInt(utxo.input.outputIndex);
25171
+ });
22308
25172
  });
22309
- };
25173
+ for (const utxo of utxos) {
25174
+ const address = Cardano5.Address.fromBech32(utxo.output.address);
25175
+ const addressProps = address.getProps();
25176
+ if (addressProps.paymentPart) {
25177
+ if (addressProps.paymentPart.type === 0 /* KeyHash */) {
25178
+ requiredSigners.add(addressProps.paymentPart.hash);
25179
+ }
25180
+ }
25181
+ }
25182
+ return requiredSigners;
25183
+ }
25184
+ function getRequiredSignersFromCertificates(txBody) {
25185
+ const requiredSigners = /* @__PURE__ */ new Set();
25186
+ const certs = txBody.certs();
25187
+ if (!certs) {
25188
+ return requiredSigners;
25189
+ }
25190
+ const certsIter = certs.values();
25191
+ for (const cert of certsIter) {
25192
+ if (cert.asStakeRegistration()) {
25193
+ const stakeReg = cert.asStakeRegistration();
25194
+ if (stakeReg.stakeCredential().type === 0 /* KeyHash */) {
25195
+ requiredSigners.add(stakeReg.stakeCredential().hash);
25196
+ }
25197
+ } else if (cert.asStakeDeregistration()) {
25198
+ const stakeDereg = cert.asStakeDeregistration();
25199
+ if (stakeDereg.stakeCredential().type === 0 /* KeyHash */) {
25200
+ requiredSigners.add(stakeDereg.stakeCredential().hash);
25201
+ }
25202
+ } else if (cert.asStakeDelegation()) {
25203
+ const stakeDeleg = cert.asStakeDelegation();
25204
+ if (stakeDeleg.stakeCredential().type === 0 /* KeyHash */) {
25205
+ requiredSigners.add(stakeDeleg.stakeCredential().hash);
25206
+ }
25207
+ } else if (cert.asPoolRegistration()) {
25208
+ const poolReg = cert.asPoolRegistration();
25209
+ const poolOwners = poolReg.poolParameters().poolOwners().values();
25210
+ for (const owner of poolOwners) {
25211
+ requiredSigners.add(owner.value());
25212
+ }
25213
+ const poolOperator = poolReg.poolParameters().operator();
25214
+ requiredSigners.add(poolOperator);
25215
+ } else if (cert.asPoolRetirement()) {
25216
+ const poolRetire = cert.asPoolRetirement();
25217
+ requiredSigners.add(poolRetire.poolKeyHash());
25218
+ } else if (cert.asGenesisKeyDelegation()) {
25219
+ } else if (cert.asMoveInstantaneousRewardsCert()) {
25220
+ } else if (cert.asRegistrationCert()) {
25221
+ const reg = cert.asRegistrationCert();
25222
+ if (reg.stakeCredential().type === 0 /* KeyHash */) {
25223
+ requiredSigners.add(reg.stakeCredential().hash);
25224
+ }
25225
+ } else if (cert.asUnregistrationCert()) {
25226
+ const unreg = cert.asUnregistrationCert();
25227
+ if (unreg.stakeCredential().type === 0 /* KeyHash */) {
25228
+ requiredSigners.add(unreg.stakeCredential().hash);
25229
+ }
25230
+ } else if (cert.asVoteDelegationCert()) {
25231
+ const voteDel = cert.asVoteDelegationCert();
25232
+ if (voteDel.stakeCredential().type === 0 /* KeyHash */) {
25233
+ requiredSigners.add(voteDel.stakeCredential().hash);
25234
+ }
25235
+ } else if (cert.asStakeVoteDelegationCert()) {
25236
+ const stakeVoteDel = cert.asStakeVoteDelegationCert();
25237
+ if (stakeVoteDel.stakeCredential().type === 0 /* KeyHash */) {
25238
+ requiredSigners.add(stakeVoteDel.stakeCredential().hash);
25239
+ }
25240
+ } else if (cert.asStakeRegistrationDelegationCert()) {
25241
+ const stakeRegDel = cert.asStakeRegistrationDelegationCert();
25242
+ if (stakeRegDel.stakeCredential().type === 0 /* KeyHash */) {
25243
+ requiredSigners.add(stakeRegDel.stakeCredential().hash);
25244
+ }
25245
+ } else if (cert.asVoteRegistrationDelegationCert()) {
25246
+ const voteRegDel = cert.asVoteRegistrationDelegationCert();
25247
+ if (voteRegDel.stakeCredential().type === 0 /* KeyHash */) {
25248
+ requiredSigners.add(voteRegDel.stakeCredential().hash);
25249
+ }
25250
+ } else if (cert.asStakeVoteRegistrationDelegationCert()) {
25251
+ const stakeVoteRegDel = cert.asStakeVoteRegistrationDelegationCert();
25252
+ if (stakeVoteRegDel.stakeCredential().type === 0 /* KeyHash */) {
25253
+ requiredSigners.add(stakeVoteRegDel.stakeCredential().hash);
25254
+ }
25255
+ } else if (cert.asAuthCommitteeHotCert()) {
25256
+ const authCommHot = cert.asAuthCommitteeHotCert();
25257
+ if (authCommHot.hotCredential().type === 0 /* KeyHash */) {
25258
+ requiredSigners.add(authCommHot.hotCredential().hash);
25259
+ }
25260
+ if (authCommHot.coldCredential().type === 0 /* KeyHash */) {
25261
+ requiredSigners.add(authCommHot.coldCredential().hash);
25262
+ }
25263
+ } else if (cert.asResignCommitteeColdCert()) {
25264
+ const resignCommCold = cert.asResignCommitteeColdCert();
25265
+ if (resignCommCold.coldCredential().type === 0 /* KeyHash */) {
25266
+ requiredSigners.add(resignCommCold.coldCredential().hash);
25267
+ }
25268
+ } else if (cert.asRegisterDelegateRepresentativeCert()) {
25269
+ const drepReg = cert.asRegisterDelegateRepresentativeCert();
25270
+ if (drepReg.credential().type === 0 /* KeyHash */) {
25271
+ requiredSigners.add(drepReg.credential().hash);
25272
+ }
25273
+ } else if (cert.asUnregisterDelegateRepresentativeCert()) {
25274
+ const drepUnreg = cert.asUnregisterDelegateRepresentativeCert();
25275
+ if (drepUnreg.credential().type === 0 /* KeyHash */) {
25276
+ requiredSigners.add(drepUnreg.credential().hash);
25277
+ }
25278
+ } else if (cert.asUpdateDelegateRepresentativeCert()) {
25279
+ const drepUpdate = cert.asUpdateDelegateRepresentativeCert();
25280
+ if (drepUpdate.credential().type === 0 /* KeyHash */) {
25281
+ requiredSigners.add(drepUpdate.credential().hash);
25282
+ }
25283
+ } else {
25284
+ throw new Error(
25285
+ "[TransactionSigners] Error parsing required signers: Unknown certificate type"
25286
+ );
25287
+ }
25288
+ }
25289
+ return requiredSigners;
25290
+ }
25291
+ function getRequiredSignersFromWithdrawals(txBody) {
25292
+ const requiredSigners = /* @__PURE__ */ new Set();
25293
+ const withdrawals = txBody.withdrawals();
25294
+ if (withdrawals) {
25295
+ for (const rewardAccount of withdrawals.keys()) {
25296
+ requiredSigners.add(Cardano5.RewardAccount.toHash(rewardAccount));
25297
+ }
25298
+ }
25299
+ return requiredSigners;
25300
+ }
25301
+ function getRequiredSignersFromRequiredSignersField(txBody) {
25302
+ const requiredSigners = /* @__PURE__ */ new Set();
25303
+ const reqSigners = txBody.requiredSigners();
25304
+ if (reqSigners) {
25305
+ const reqSignersIter = reqSigners.values();
25306
+ for (const reqSigner of reqSignersIter) {
25307
+ requiredSigners.add(reqSigner.value());
25308
+ }
25309
+ }
25310
+ return requiredSigners;
25311
+ }
25312
+ function getRequiredSignersFromVotingProcedures(txBody) {
25313
+ const requiredSigners = /* @__PURE__ */ new Set();
25314
+ const votingProcedures = txBody.votingProcedures();
25315
+ if (votingProcedures) {
25316
+ const voters = votingProcedures.getVoters().values();
25317
+ for (const voter of voters) {
25318
+ if (voter.toDrepCred()) {
25319
+ const drepCred = voter.toDrepCred();
25320
+ if (drepCred.type === 0 /* KeyHash */) {
25321
+ requiredSigners.add(drepCred.hash);
25322
+ }
25323
+ } else if (voter.toConstitutionalCommitteeHotCred()) {
25324
+ const ccHotCred = voter.toConstitutionalCommitteeHotCred();
25325
+ if (ccHotCred.type === 0 /* KeyHash */) {
25326
+ requiredSigners.add(ccHotCred.hash);
25327
+ }
25328
+ } else if (voter.toStakingPoolKeyHash()) {
25329
+ const poolKeyHash = voter.toStakingPoolKeyHash();
25330
+ requiredSigners.add(poolKeyHash);
25331
+ }
25332
+ }
25333
+ }
25334
+ return requiredSigners;
25335
+ }
25336
+ async function getTransactionRequiredSigners(transaction, fetcher) {
25337
+ const txBody = transaction.body();
25338
+ const allRequiredSigners = /* @__PURE__ */ new Set();
25339
+ const inputSigners = await getRequiredSignersFromInputs(txBody, fetcher);
25340
+ const certSigners = getRequiredSignersFromCertificates(txBody);
25341
+ const withdrawalSigners = getRequiredSignersFromWithdrawals(txBody);
25342
+ const explicitSigners = getRequiredSignersFromRequiredSignersField(txBody);
25343
+ const votingSigners = getRequiredSignersFromVotingProcedures(txBody);
25344
+ for (const signer of inputSigners) allRequiredSigners.add(signer);
25345
+ for (const signer of certSigners) allRequiredSigners.add(signer);
25346
+ for (const signer of withdrawalSigners) allRequiredSigners.add(signer);
25347
+ for (const signer of explicitSigners) allRequiredSigners.add(signer);
25348
+ for (const signer of votingSigners) allRequiredSigners.add(signer);
25349
+ return allRequiredSigners;
25350
+ }
22310
25351
 
22311
- // src/signer/base-signer.ts
22312
- import { setInConwayEra } from "@cardano-sdk/core";
22313
- import {
22314
- Ed25519PrivateExtendedKeyHex,
22315
- Ed25519PrivateKey,
22316
- Ed25519PrivateNormalKeyHex,
22317
- Ed25519Signature,
22318
- Ed25519SignatureHex
22319
- } from "@cardano-sdk/crypto";
22320
- import { HexBlob } from "@cardano-sdk/util";
22321
- var BaseSigner = class _BaseSigner {
22322
- constructor(ed25519PrivateKey) {
22323
- setInConwayEra(true);
22324
- this.ed25519PrivateKey = ed25519PrivateKey;
25352
+ // src/cardano/wallet/mesh/cardano-base-wallet.ts
25353
+ var CardanoHeadlessWallet = class _CardanoHeadlessWallet {
25354
+ constructor(networkId, addressManager, walletAddressType, fetcher, submitter) {
25355
+ setInConwayEra5(true);
25356
+ this.networkId = networkId;
25357
+ this.addressManager = addressManager;
25358
+ this.fetcher = fetcher;
25359
+ this.submitter = submitter;
25360
+ this.walletAddressType = walletAddressType;
25361
+ }
25362
+ static async create(config) {
25363
+ const addressManager = await AddressManager.create({
25364
+ addressSource: config.addressSource,
25365
+ networkId: config.networkId
25366
+ });
25367
+ return new _CardanoHeadlessWallet(
25368
+ config.networkId,
25369
+ addressManager,
25370
+ config.walletAddressType,
25371
+ config.fetcher,
25372
+ config.submitter
25373
+ );
22325
25374
  }
22326
25375
  /**
22327
- * Create a BaseSigner instance from an Ed25519 private key in extended hex format.
22328
- * @param keyHex Ed25519 private key in extended hex format
22329
- * @returns {BaseSigner} A BaseSigner instance
25376
+ * Create a CardanoHeadlessWallet instance from a Bip32 root in Bech32 format.
25377
+ * @param config The configuration object
25378
+ * @returns {Promise<CardanoHeadlessWallet>} A promise that resolves to a CardanoHeadlessWallet instance
22330
25379
  */
22331
- static fromExtendedKeyHex(keyHex) {
22332
- return new _BaseSigner(
22333
- Ed25519PrivateKey.fromExtendedHex(Ed25519PrivateExtendedKeyHex(keyHex))
22334
- );
25380
+ static async fromBip32Root(config) {
25381
+ const bip32 = InMemoryBip32.fromBech32(config.bech32);
25382
+ return _CardanoHeadlessWallet.create({
25383
+ addressSource: { type: "secretManager", secretManager: bip32 },
25384
+ networkId: config.networkId,
25385
+ walletAddressType: config.walletAddressType,
25386
+ fetcher: config.fetcher,
25387
+ submitter: config.submitter
25388
+ });
22335
25389
  }
22336
25390
  /**
22337
- * Create a BaseSigner instance from an Ed25519 private key in normal hex format.
22338
- * @param keyHex Ed25519 private key in normal hex format
22339
- * @returns {BaseSigner} A BaseSigner instance
25391
+ * Create a CardanoHeadlessWallet instance from a Bip32 root in hex format.
25392
+ * @param config The configuration object
25393
+ * @returns {Promise<CardanoHeadlessWallet>} A promise that resolves to a CardanoHeadlessWallet instance
22340
25394
  */
22341
- static fromNormalKeyHex(keyHex) {
22342
- return new _BaseSigner(
22343
- Ed25519PrivateKey.fromNormalHex(Ed25519PrivateNormalKeyHex(keyHex))
25395
+ static async fromBip32RootHex(config) {
25396
+ const bip32 = InMemoryBip32.fromKeyHex(config.hex);
25397
+ return _CardanoHeadlessWallet.create({
25398
+ addressSource: { type: "secretManager", secretManager: bip32 },
25399
+ networkId: config.networkId,
25400
+ walletAddressType: config.walletAddressType,
25401
+ fetcher: config.fetcher,
25402
+ submitter: config.submitter
25403
+ });
25404
+ }
25405
+ /**
25406
+ * Create a CardanoHeadlessWallet instance from a mnemonic phrase.
25407
+ * @param config The configuration object
25408
+ * @returns {Promise<CardanoHeadlessWallet>} A promise that resolves to a CardanoHeadlessWallet instance
25409
+ */
25410
+ static async fromMnemonic(config) {
25411
+ const bip32 = await InMemoryBip32.fromMnemonic(
25412
+ config.mnemonic,
25413
+ config.password
22344
25414
  );
25415
+ return _CardanoHeadlessWallet.create({
25416
+ addressSource: { type: "secretManager", secretManager: bip32 },
25417
+ networkId: config.networkId,
25418
+ walletAddressType: config.walletAddressType,
25419
+ fetcher: config.fetcher,
25420
+ submitter: config.submitter
25421
+ });
22345
25422
  }
22346
- static fromKeyHex(keyHex) {
22347
- const hexLength = keyHex.length;
22348
- if (hexLength === 128) {
22349
- return this.fromExtendedKeyHex(keyHex);
22350
- } else if (hexLength === 64) {
22351
- return this.fromNormalKeyHex(keyHex);
22352
- } else {
22353
- throw new Error(
22354
- `Invalid key length: ${hexLength}. Expected 64 (normal key) or 128 (extended key) hex characters.`
22355
- );
22356
- }
25423
+ static async fromCredentialSources(config) {
25424
+ return _CardanoHeadlessWallet.create({
25425
+ addressSource: {
25426
+ type: "credentials",
25427
+ paymentCredential: config.paymentCredentialSource,
25428
+ stakeCredential: config.stakeCredentialSource,
25429
+ drepCredential: config.drepCredentialSource
25430
+ },
25431
+ networkId: config.networkId,
25432
+ walletAddressType: config.walletAddressType,
25433
+ fetcher: config.fetcher,
25434
+ submitter: config.submitter
25435
+ });
22357
25436
  }
22358
25437
  /**
22359
- * Get the Ed25519 public key in hex format.
22360
- * @returns {Promise<string>} A promise that resolves to the public key in hex format.
25438
+ * Submit a transaction to the network, using the submitter instance.
25439
+ * @param tx The transaction in CBOR hex format
25440
+ * @returns {Promise<string>} A promise that resolves to the transaction ID
22361
25441
  */
22362
- async getPublicKey() {
22363
- return this.ed25519PrivateKey.toPublic().hex();
25442
+ async submitTx(tx) {
25443
+ if (!this.submitter) {
25444
+ throw new Error("[CardanoWallet] No submitter provided");
25445
+ }
25446
+ return await this.submitter.submitTx(tx);
22364
25447
  }
22365
25448
  /**
22366
- * Get the Ed25519 public key hash in hex format.
22367
- * @returns {Promise<string>} A promise that resolves to the public key hash in hex format.
25449
+ * Get the network ID.
25450
+ * @returns {number} The network ID
22368
25451
  */
22369
- async getPublicKeyHash() {
22370
- return this.ed25519PrivateKey.toPublic().hash().hex();
25452
+ async getNetworkId() {
25453
+ return this.networkId;
22371
25454
  }
22372
25455
  /**
22373
- * Sign data using the Ed25519 private key.
22374
- * @param data data to be signed in hex format
22375
- * @returns {Promise<string>} A promise that resolves to the signature in hex format.
25456
+ * Get the UTxOs for the wallet.
25457
+ *
25458
+ * NOTE: This method is only an approximation to CIP-30 getUtxos, as this wallet is completely
25459
+ * stateless and does not track which UTxOs are specifically set as collateral. Which means that there
25460
+ * will be overlap between getUtxos() and getCollateral() results. This can result in the collateral being
25461
+ * spent between transactions.
25462
+ *
25463
+ * The method also does not perform pagination, nor is there a coin selection mechanism.
25464
+ * @returns {Promise<string[]>} A promise that resolves to an array of UTxOs in CBOR hex format
22376
25465
  */
22377
- async sign(data) {
22378
- return this.ed25519PrivateKey.sign(HexBlob(data)).hex();
25466
+ async getUtxos() {
25467
+ if (!this.fetcher) {
25468
+ throw new Error("[CardanoWallet] No fetcher provided");
25469
+ }
25470
+ const utxos = await this.fetchAccountUtxos();
25471
+ return utxos.map((utxo) => toTxUnspentOutput(utxo).toCbor());
22379
25472
  }
22380
25473
  /**
22381
- * Verify a signature using the Ed25519 public key.
22382
- * @param data The original data in hex format.
22383
- * @param signature The signature to verify in hex format.
22384
- * @returns {Promise<boolean>} A promise that resolves to true if the signature is valid, false otherwise.
25474
+ * Get the collateral UTxOs for the wallet.
25475
+ *
25476
+ * NOTE: This method is only an approximation to CIP-30 getCollateral, as this wallet is completely
25477
+ * stateless and does not track which UTxOs are specifically set as collateral. Which means that there
25478
+ * will be overlap between getUtxos() and getCollateral() results.
25479
+ *
25480
+ * The basic strategy is to return the smallest pure ADA UTxO that is at least 5 ADA belonging to the wallet.
25481
+ * @returns {Promise<string[]>} A promise that resolves to an array of UTxOs in CBOR hex format
22385
25482
  */
22386
- async verify(data, signature) {
22387
- return this.ed25519PrivateKey.toPublic().verify(
22388
- Ed25519Signature.fromHex(Ed25519SignatureHex(signature)),
22389
- HexBlob(data)
22390
- );
25483
+ async getCollateral() {
25484
+ if (!this.fetcher) {
25485
+ throw new Error("[CardanoWallet] No fetcher provided");
25486
+ }
25487
+ const utxos = await this.fetchAccountUtxos();
25488
+ const cardanoUtxos = utxos.map((utxo) => toTxUnspentOutput(utxo));
25489
+ const pureAdaUtxos = cardanoUtxos.filter((utxo) => {
25490
+ return utxo.output().amount().multiasset() === void 0;
25491
+ });
25492
+ pureAdaUtxos.sort((a, b) => {
25493
+ return Number(a.output().amount().coin()) - Number(b.output().amount().coin());
25494
+ });
25495
+ for (const utxo of pureAdaUtxos) {
25496
+ if (Number(utxo.output().amount().coin()) >= 5e6) {
25497
+ return [utxo.toCbor()];
25498
+ }
25499
+ }
25500
+ return [];
22391
25501
  }
22392
- };
22393
-
22394
- // src/bip32/in-memory-bip32.ts
22395
- var InMemoryBip32 = class _InMemoryBip32 {
22396
- constructor(privateKey) {
22397
- setInConwayEra2(true);
22398
- this.bip32PrivateKey = privateKey;
25502
+ /**
25503
+ * Get the balance of the wallet.
25504
+ *
25505
+ * NOTE: This method is only an approximation to CIP-30 getBalance, as this wallet is completely
25506
+ * stateless and does not track which UTxOs are specifically set as collateral. Which means the balance
25507
+ * returned includes all UTxOs, including those that may be used as collateral.
25508
+ * @returns {Promise<string>} A promise that resolves to the balance in CBOR hex format
25509
+ */
25510
+ async getBalance() {
25511
+ if (!this.fetcher) {
25512
+ throw new Error("[CardanoWallet] No fetcher provided");
25513
+ }
25514
+ const utxos = await this.fetchAccountUtxos();
25515
+ const cardanoUtxos = utxos.map((utxo) => toTxUnspentOutput(utxo));
25516
+ let total = new Serialization6.Value(0n);
25517
+ for (const utxo of cardanoUtxos) {
25518
+ total = mergeValue(total, utxo.output().amount());
25519
+ }
25520
+ return total.toCbor();
22399
25521
  }
22400
- static async fromMnemonic(mnemonic, password) {
22401
- await ready();
22402
- const entropy = (0, import_bip39.mnemonicToEntropy)(mnemonic.join(" "));
22403
- const bip32PrivateKey = Bip32PrivateKey.fromBip39Entropy(
22404
- Buffer.from(entropy, "hex"),
22405
- password || ""
25522
+ /**
25523
+ * Get the used addresses for the wallet.
25524
+ *
25525
+ * NOTE: This method completely deviates from CIP-30 getUsedAddresses, as this wallet is stateless
25526
+ * it is impossible to track which addresses have been used. This method simply returns the wallet's main address.
25527
+ *
25528
+ * It will be effective to be used as a single address wallet.
25529
+ *
25530
+ * @returns {Promise<string[]>} A promise that resolves to an array of used addresses in hex format
25531
+ */
25532
+ async getUsedAddresses() {
25533
+ const address = await this.addressManager.getNextAddress(
25534
+ this.walletAddressType
22406
25535
  );
22407
- return new _InMemoryBip32(bip32PrivateKey);
25536
+ return [address.getAddressHex()];
22408
25537
  }
22409
- static async fromEntropy(entropy, password) {
22410
- await ready();
22411
- const bip32PrivateKey = Bip32PrivateKey.fromBip39Entropy(
22412
- Buffer.from(entropy, "hex"),
22413
- password || ""
25538
+ /**
25539
+ * Get the unused addresses for the wallet.
25540
+ *
25541
+ * NOTE: This method completely deviates from CIP-30 getUnusedAddresses, as this wallet is stateless
25542
+ * it is impossible to track which addresses have been used. This method simply returns the wallet's main address.
25543
+ *
25544
+ * It will be effective to be used as a single address wallet.
25545
+ *
25546
+ * @returns {Promise<string[]>} A promise that resolves to an array of unused addresses in hex format
25547
+ */
25548
+ async getUnusedAddresses() {
25549
+ const address = await this.addressManager.getNextAddress(
25550
+ this.walletAddressType
22414
25551
  );
22415
- return new _InMemoryBip32(bip32PrivateKey);
25552
+ return [address.getAddressHex()];
22416
25553
  }
22417
- static fromKeyHex(keyHex) {
22418
- const bip32PrivateKey = Bip32PrivateKey.fromHex(
22419
- keyHex
25554
+ /**
25555
+ * Get the change address for the wallet.
25556
+ * NOTE: This method deviates from CIP-30 getChangeAddress, as this wallet is stateless
25557
+ * it does not track which addresses has been previously used as change address. This method simply
25558
+ * returns the wallet's main address.
25559
+ *
25560
+ * It will be effective to be used as a single address wallet.
25561
+ *
25562
+ * @returns {Promise<string>} A promise that resolves to the change address in hex format
25563
+ */
25564
+ async getChangeAddress() {
25565
+ const address = await this.addressManager.getChangeAddress(
25566
+ this.walletAddressType
22420
25567
  );
22421
- return new _InMemoryBip32(bip32PrivateKey);
22422
- }
22423
- static fromBech32(bech322) {
22424
- const bech32DecodedBytes = bech32.decodeToBytes(bech322).bytes;
22425
- const bip32PrivateKey = Bip32PrivateKey.fromBytes(bech32DecodedBytes);
22426
- return new _InMemoryBip32(bip32PrivateKey);
25568
+ return address.getAddressHex();
22427
25569
  }
22428
25570
  /**
22429
- * Get the Bip32 public key in hex format.
22430
- * @returns {Promise<string>} A promise that resolves to the public key in hex format.
25571
+ * Get the reward address for the wallet.
25572
+ *
25573
+ * @returns {Promise<string[]>} A promise that resolves an array of reward addresses in hex format
22431
25574
  */
22432
- async getPublicKey() {
22433
- await ready();
22434
- return this.bip32PrivateKey.toPublic().hex();
25575
+ async getRewardAddresses() {
25576
+ const rewardAddress = await this.addressManager.getRewardAccount();
25577
+ return [rewardAddress.getAddressHex()];
22435
25578
  }
22436
25579
  /**
22437
- * Get an ISigner instance initialized with the current Bip32 private key.
22438
- * @returns {Promise<ISigner>} A promise that resolves to an ISigner instance initialized with the current Bip32 private key.
25580
+ * Sign a transaction with the wallet.
25581
+ *
25582
+ * NOTE: This method requires a fetcher to resolve input UTxOs for determining required signers.
25583
+ *
25584
+ * It is also only an approximation to CIP-30 signTx, as this wallet is stateless and does not repeatedly
25585
+ * derive keys, it is unable to sign for multiple derived key indexes.
25586
+ *
25587
+ * It will be effective to be used as a single address wallet.
25588
+ *
25589
+ * @param tx The transaction in CBOR hex format
25590
+ * @returns A promise that resolves to a witness set with the signatures in CBOR hex format
22439
25591
  */
22440
- async getSigner(derivationPath) {
22441
- const path = Array.isArray(derivationPath) ? derivationPath : derivationPathVectorFromString(derivationPath);
22442
- const bip32PrivateKey = this.bip32PrivateKey.derive(path);
22443
- return BaseSigner.fromExtendedKeyHex(bip32PrivateKey.toRawKey().hex());
22444
- }
22445
- };
22446
-
22447
- // src/cardano/address/cardano-address.ts
22448
- import { Cardano, setInConwayEra as setInConwayEra3 } from "@cardano-sdk/core";
22449
- import { Hash28ByteBase16 } from "@cardano-sdk/crypto";
22450
- var CredentialType = /* @__PURE__ */ ((CredentialType2) => {
22451
- CredentialType2[CredentialType2["KeyHash"] = 0] = "KeyHash";
22452
- CredentialType2[CredentialType2["ScriptHash"] = 1] = "ScriptHash";
22453
- return CredentialType2;
22454
- })(CredentialType || {});
22455
- var AddressType = /* @__PURE__ */ ((AddressType2) => {
22456
- AddressType2[AddressType2["Enterprise"] = 0] = "Enterprise";
22457
- AddressType2[AddressType2["Base"] = 1] = "Base";
22458
- AddressType2[AddressType2["Reward"] = 2] = "Reward";
22459
- return AddressType2;
22460
- })(AddressType || {});
22461
- var CardanoAddress = class {
22462
- constructor(addressType, networkId, paymentCredential, stakeCredential) {
22463
- setInConwayEra3(true);
22464
- if (addressType === 1 /* Base */ && !stakeCredential) {
22465
- throw new Error("No stake credential");
25592
+ async signTx(tx, partialSign = false) {
25593
+ if (!this.fetcher) {
25594
+ throw new Error(
25595
+ "[CardanoWallet] No fetcher provided, wallet sign tx does not behave correctly without a fetcher to resolve inputs. If you need to blindly sign a tx, use the CardanoSigner class directly."
25596
+ );
22466
25597
  }
22467
- this.addressType = addressType;
22468
- this.networkId = networkId;
22469
- this.paymentCredential = paymentCredential;
22470
- this.stakeCredential = stakeCredential;
25598
+ const transaction = Serialization6.Transaction.fromCbor(
25599
+ Serialization6.TxCBOR(tx)
25600
+ );
25601
+ const requiredSigners = await getTransactionRequiredSigners(
25602
+ transaction,
25603
+ this.fetcher
25604
+ );
25605
+ const signersMap = await this.addressManager.getCredentialsSigners(
25606
+ requiredSigners
25607
+ );
25608
+ if (!partialSign) {
25609
+ if (requiredSigners.size !== signersMap.size) {
25610
+ throw new Error("[CardanoWallet] Not all required signers found");
25611
+ }
25612
+ }
25613
+ const signers = Array.from(signersMap.values());
25614
+ return await CardanoSigner.signTx(tx, signers, false);
22471
25615
  }
22472
- getAddressBech32() {
22473
- if (this.addressType === 0 /* Enterprise */) {
22474
- return this.getEnterpriseAddressBech32();
22475
- } else if (this.addressType === 1 /* Base */) {
22476
- return this.getBaseAddressBech32();
22477
- } else if (this.addressType === 2 /* Reward */) {
22478
- return this.getRewardAddressBech32();
25616
+ async signData(addressBech32, data) {
25617
+ let targetAddressBech32 = addressBech32;
25618
+ if (!targetAddressBech32) {
25619
+ const address2 = await this.addressManager.getNextAddress(
25620
+ this.walletAddressType
25621
+ );
25622
+ targetAddressBech32 = address2.getAddressBech32();
22479
25623
  }
22480
- throw new Error(`Invalid address type: ${this.addressType}`);
25624
+ const address = Cardano6.Address.fromBech32(targetAddressBech32);
25625
+ if (!address) {
25626
+ throw new Error("[CardanoWallet] Invalid address");
25627
+ }
25628
+ const addressProps = address.getProps();
25629
+ let credentialHash;
25630
+ if (addressProps.type === Cardano6.AddressType.RewardKey && addressProps.delegationPart) {
25631
+ credentialHash = addressProps.delegationPart.hash;
25632
+ } else if (addressProps.paymentPart) {
25633
+ credentialHash = addressProps.paymentPart.hash;
25634
+ } else {
25635
+ throw new Error("[CardanoWallet] No credential found in address");
25636
+ }
25637
+ const signersMap = await this.addressManager.getCredentialsSigners(
25638
+ /* @__PURE__ */ new Set([credentialHash])
25639
+ );
25640
+ const signer = signersMap.get(credentialHash);
25641
+ if (!signer) {
25642
+ throw new Error(
25643
+ `[CardanoWallet] No signer found for credential hash: ${credentialHash}`
25644
+ );
25645
+ }
25646
+ return await CardanoSigner.signData(data, address.toBytes(), signer);
22481
25647
  }
22482
- getAddressHex() {
22483
- if (this.addressType === 0 /* Enterprise */) {
22484
- return this.getEnterpriseAddressHex();
22485
- } else if (this.addressType === 1 /* Base */) {
22486
- return this.getBaseAddressHex();
22487
- } else if (this.addressType === 2 /* Reward */) {
22488
- return this.getRewardAddressHex();
25648
+ async fetchAccountUtxos() {
25649
+ if (!this.fetcher) {
25650
+ throw new Error("[CardanoWallet] No fetcher provided");
22489
25651
  }
22490
- throw new Error(`Invalid address type: ${this.addressType}`);
25652
+ const addresses = (await this.addressManager.asyncGetAllUsedAddresses()).map((address) => address.getAddressBech32());
25653
+ const utxos = [];
25654
+ for (const addr of addresses) {
25655
+ const fetchedUtxos = await this.fetcher.fetchAddressUTxOs(addr);
25656
+ utxos.push(...fetchedUtxos);
25657
+ }
25658
+ return utxos;
22491
25659
  }
22492
- getEnterpriseAddressBech32() {
22493
- const enterpriseAddress = Cardano.EnterpriseAddress.fromCredentials(
22494
- this.networkId === 1 ? Cardano.NetworkId.Mainnet : Cardano.NetworkId.Testnet,
22495
- {
22496
- hash: Hash28ByteBase16(this.paymentCredential.hash),
22497
- type: mapCredentialTypeToCredential(this.paymentCredential.type)
22498
- }
25660
+ };
25661
+
25662
+ // src/cardano/wallet/mesh/mesh-wallet.ts
25663
+ import { Cardano as Cardano7, Serialization as Serialization7 } from "@cardano-sdk/core";
25664
+ import { HexBlob as HexBlob6 } from "@cardano-sdk/util";
25665
+ var MeshCardanoHeadlessWallet = class _MeshCardanoHeadlessWallet extends CardanoHeadlessWallet {
25666
+ static async create(config) {
25667
+ const addressManager = await AddressManager.create({
25668
+ addressSource: config.addressSource,
25669
+ networkId: config.networkId
25670
+ });
25671
+ return new _MeshCardanoHeadlessWallet(
25672
+ config.networkId,
25673
+ addressManager,
25674
+ config.walletAddressType,
25675
+ config.fetcher,
25676
+ config.submitter
22499
25677
  );
22500
- return enterpriseAddress.toAddress().toBech32();
22501
25678
  }
22502
- getEnterpriseAddressHex() {
22503
- const enterpriseAddress = Cardano.EnterpriseAddress.fromCredentials(
22504
- this.networkId === 1 ? Cardano.NetworkId.Mainnet : Cardano.NetworkId.Testnet,
22505
- {
22506
- hash: Hash28ByteBase16(this.paymentCredential.hash),
22507
- type: mapCredentialTypeToCredential(this.paymentCredential.type)
22508
- }
25679
+ static async fromMnemonic(config) {
25680
+ const bip32 = await InMemoryBip32.fromMnemonic(
25681
+ config.mnemonic,
25682
+ config.password
22509
25683
  );
22510
- return enterpriseAddress.toAddress().toBytes();
25684
+ return _MeshCardanoHeadlessWallet.create({
25685
+ addressSource: { type: "secretManager", secretManager: bip32 },
25686
+ networkId: config.networkId,
25687
+ walletAddressType: config.walletAddressType,
25688
+ fetcher: config.fetcher,
25689
+ submitter: config.submitter
25690
+ });
22511
25691
  }
22512
- getBaseAddressBech32() {
22513
- if (!this.stakeCredential) throw new Error("No stake credential");
22514
- const baseAddress = Cardano.BaseAddress.fromCredentials(
22515
- this.networkId === 1 ? Cardano.NetworkId.Mainnet : Cardano.NetworkId.Testnet,
22516
- {
22517
- hash: Hash28ByteBase16(this.paymentCredential.hash),
22518
- type: mapCredentialTypeToCredential(this.paymentCredential.type)
22519
- },
22520
- {
22521
- hash: Hash28ByteBase16(this.stakeCredential.hash),
22522
- type: mapCredentialTypeToCredential(this.stakeCredential.type)
22523
- }
22524
- );
22525
- return baseAddress.toAddress().toBech32();
25692
+ static async fromBip32Root(config) {
25693
+ const bip32 = InMemoryBip32.fromBech32(config.bech32);
25694
+ return _MeshCardanoHeadlessWallet.create({
25695
+ addressSource: { type: "secretManager", secretManager: bip32 },
25696
+ networkId: config.networkId,
25697
+ walletAddressType: config.walletAddressType,
25698
+ fetcher: config.fetcher,
25699
+ submitter: config.submitter
25700
+ });
22526
25701
  }
22527
- getBaseAddressHex() {
22528
- if (!this.stakeCredential) throw new Error("No stake credential");
22529
- const baseAddress = Cardano.BaseAddress.fromCredentials(
22530
- this.networkId === 1 ? Cardano.NetworkId.Mainnet : Cardano.NetworkId.Testnet,
22531
- {
22532
- hash: Hash28ByteBase16(this.paymentCredential.hash),
22533
- type: mapCredentialTypeToCredential(this.paymentCredential.type)
25702
+ static async fromBip32RootHex(config) {
25703
+ const bip32 = InMemoryBip32.fromKeyHex(config.hex);
25704
+ return _MeshCardanoHeadlessWallet.create({
25705
+ addressSource: { type: "secretManager", secretManager: bip32 },
25706
+ networkId: config.networkId,
25707
+ walletAddressType: config.walletAddressType,
25708
+ fetcher: config.fetcher,
25709
+ submitter: config.submitter
25710
+ });
25711
+ }
25712
+ static async fromCredentialSources(config) {
25713
+ return _MeshCardanoHeadlessWallet.create({
25714
+ addressSource: {
25715
+ type: "credentials",
25716
+ paymentCredential: config.paymentCredentialSource,
25717
+ stakeCredential: config.stakeCredentialSource,
25718
+ drepCredential: config.drepCredentialSource
22534
25719
  },
22535
- {
22536
- hash: Hash28ByteBase16(this.stakeCredential.hash),
22537
- type: this.stakeCredential.type
22538
- }
22539
- );
22540
- return baseAddress.toAddress().toBytes();
25720
+ networkId: config.networkId,
25721
+ walletAddressType: config.walletAddressType,
25722
+ fetcher: config.fetcher,
25723
+ submitter: config.submitter
25724
+ });
22541
25725
  }
22542
- getRewardAddressBech32() {
22543
- if (!this.stakeCredential) throw new Error("No stake credential");
22544
- const rewardAddress = Cardano.RewardAddress.fromCredentials(
22545
- this.networkId === 1 ? Cardano.NetworkId.Mainnet : Cardano.NetworkId.Testnet,
22546
- {
22547
- hash: Hash28ByteBase16(this.stakeCredential.hash),
22548
- type: this.stakeCredential.type
22549
- }
22550
- );
22551
- return rewardAddress.toAddress().toBech32();
25726
+ /**
25727
+ * Get the UTxOs for the wallet.
25728
+ *
25729
+ * NOTE: This method is only an approximation to CIP-30 getUtxos, as this wallet is completely
25730
+ * stateless and does not track which UTxOs are specifically set as collateral. Which means that there
25731
+ * will be overlap between getUtxos() and getCollateral() results. This can result in the collateral being
25732
+ * spent between transactions.
25733
+ *
25734
+ * The method also does not perform pagination, nor is there a coin selection mechanism.
25735
+ * @returns {Promise<UTxO[]>} A promise that resolves to an array of UTxOs in the Mesh UTxO format
25736
+ */
25737
+ async getUtxosMesh() {
25738
+ if (!this.fetcher) {
25739
+ throw new Error("[CardanoWallet] No fetcher provided");
25740
+ }
25741
+ return await this.fetchAccountUtxos();
22552
25742
  }
22553
- getRewardAddressHex() {
22554
- if (!this.stakeCredential) throw new Error("No stake credential");
22555
- const rewardAddress = Cardano.RewardAddress.fromCredentials(
22556
- this.networkId === 1 ? Cardano.NetworkId.Mainnet : Cardano.NetworkId.Testnet,
22557
- {
22558
- hash: Hash28ByteBase16(this.stakeCredential.hash),
22559
- type: this.stakeCredential.type
25743
+ /**
25744
+ * Get the collateral UTxOs for the wallet.
25745
+ *
25746
+ * NOTE: This method is only an approximation to CIP-30 getCollateral, as this wallet is completely
25747
+ * stateless and does not track which UTxOs are specifically set as collateral. Which means that there
25748
+ * will be overlap between getUtxos() and getCollateral() results.
25749
+ *
25750
+ * The basic strategy is to return the smallest pure ADA UTxO that is at least 5 ADA belonging to the wallet.
25751
+ * @returns {Promise<UTxO[]>} A promise that resolves to an array of UTxOs in the Mesh UTxO format
25752
+ */
25753
+ async getCollateralMesh() {
25754
+ if (!this.fetcher) {
25755
+ throw new Error("[CardanoWallet] No fetcher provided");
25756
+ }
25757
+ const utxos = await this.fetchAccountUtxos();
25758
+ const getUtxoLovelaceValue = (utxo) => {
25759
+ const value = utxo.output.amount;
25760
+ let lovelace = 0;
25761
+ for (const asset of value) {
25762
+ if (asset.unit === "lovelace" || asset.unit === "") {
25763
+ lovelace = parseInt(asset.quantity);
25764
+ }
22560
25765
  }
25766
+ return lovelace;
25767
+ };
25768
+ const sortedUtxos = utxos.sort(
25769
+ (a, b) => getUtxoLovelaceValue(a) - getUtxoLovelaceValue(b)
22561
25770
  );
22562
- return rewardAddress.toAddress().toBytes();
25771
+ for (const utxo of sortedUtxos) {
25772
+ if (getUtxoLovelaceValue(utxo) >= 5e6) {
25773
+ return [utxo];
25774
+ }
25775
+ }
25776
+ return [];
22563
25777
  }
22564
- };
22565
- var mapCredentialTypeToCredential = (credentialType) => {
22566
- switch (credentialType) {
22567
- case 0 /* KeyHash */:
22568
- return Cardano.CredentialType.KeyHash;
22569
- case 1 /* ScriptHash */:
22570
- return Cardano.CredentialType.ScriptHash;
25778
+ /**
25779
+ * Get the balance of the wallet.
25780
+ *
25781
+ * NOTE: This method is only an approximation to CIP-30 getBalance, as this wallet is completely
25782
+ * stateless and does not track which UTxOs are specifically set as collateral. Which means the balance
25783
+ * returned includes all UTxOs, including those that may be used as collateral.
25784
+ * @returns {Promise<Asset[]>} A promise that resolves to the balance in the Mesh Asset format
25785
+ */
25786
+ async getBalanceMesh() {
25787
+ if (!this.fetcher) {
25788
+ throw new Error("[CardanoWallet] No fetcher provided");
25789
+ }
25790
+ const utxos = await this.fetchAccountUtxos();
25791
+ return utxos.map((utxo) => utxo.output.amount).flat();
25792
+ }
25793
+ /**
25794
+ * Get the used addresses for the wallet.
25795
+ *
25796
+ * NOTE: This method completely deviates from CIP-30 getUsedAddresses, as this wallet is stateless
25797
+ * it is impossible to track which addresses have been used. This method simply returns the wallet's main address.
25798
+ *
25799
+ * It will be effective to be used as a single address wallet.
25800
+ *
25801
+ * @returns {Promise<string[]>} A promise that resolves to an array of used addresses in Bech32 format
25802
+ */
25803
+ async getUsedAddressesBech32() {
25804
+ const addresses = await this.getUsedAddresses();
25805
+ return addresses.map((addr) => {
25806
+ const cardanoAddr = Cardano7.Address.fromBytes(HexBlob6(addr));
25807
+ return cardanoAddr.toBech32();
25808
+ });
25809
+ }
25810
+ /**
25811
+ * Get the unused addresses for the wallet.
25812
+ *
25813
+ * NOTE: This method completely deviates from CIP-30 getUnusedAddresses, as this wallet is stateless
25814
+ * it is impossible to track which addresses have been used. This method simply returns the wallet's main address.
25815
+ *
25816
+ * It will be effective to be used as a single address wallet.
25817
+ *
25818
+ * @returns {Promise<string[]>} A promise that resolves to an array of unused addresses in Bech32 format
25819
+ */
25820
+ async getUnusedAddressesBech32() {
25821
+ const addresses = await this.getUnusedAddresses();
25822
+ return addresses.map((addr) => {
25823
+ const cardanoAddr = Cardano7.Address.fromBytes(HexBlob6(addr));
25824
+ return cardanoAddr.toBech32();
25825
+ });
25826
+ }
25827
+ /**
25828
+ * Get the change address for the wallet.
25829
+ * NOTE: This method deviates from CIP-30 getChangeAddress, as this wallet is stateless
25830
+ * it does not track which addresses has been previously used as change address. This method simply
25831
+ * returns the wallet's main address.
25832
+ *
25833
+ * It will be effective to be used as a single address wallet.
25834
+ *
25835
+ * @returns {Promise<string>} A promise that resolves to the change address in Bech32 format
25836
+ */
25837
+ async getChangeAddressBech32() {
25838
+ const address = await this.getChangeAddress();
25839
+ const cardanoAddr = Cardano7.Address.fromBytes(HexBlob6(address));
25840
+ return cardanoAddr.toBech32();
25841
+ }
25842
+ /**
25843
+ * Get the reward address for the wallet.
25844
+ * @returns {Promise<string[]>} A promise that resolves an array of reward addresses in Bech32 format
25845
+ */
25846
+ async getRewardAddressesBech32() {
25847
+ const addresses = await this.getRewardAddresses();
25848
+ return addresses.map((addr) => {
25849
+ const cardanoAddr = Cardano7.Address.fromBytes(HexBlob6(addr));
25850
+ return cardanoAddr.toBech32();
25851
+ });
25852
+ }
25853
+ /**
25854
+ * Sign a transaction with the wallet.
25855
+ *
25856
+ * NOTE: This method requires a fetcher to resolve input UTxOs for determining required signers.
25857
+ *
25858
+ * It is also only an approximation to CIP-30 signTx, as this wallet is stateless and does not repeatedly
25859
+ * derive keys, it is unable to sign for multiple derived key indexes.
25860
+ *
25861
+ * It will be effective to be used as a single address wallet.
25862
+ *
25863
+ * @param tx The transaction in CBOR hex format
25864
+ * @returns A promise that resolves to a full transaction with extra vkey witnesses added from the wallet
25865
+ * to the witness set in CBOR hex format
25866
+ */
25867
+ async signTxReturnFullTx(tx, partialSign = false) {
25868
+ const witnessCbor = await this.signTx(tx, partialSign);
25869
+ const addedWitnesses = Serialization7.TransactionWitnessSet.fromCbor(
25870
+ HexBlob6(witnessCbor)
25871
+ );
25872
+ const transaction = Serialization7.Transaction.fromCbor(
25873
+ Serialization7.TxCBOR(tx)
25874
+ );
25875
+ let witnessSet = transaction.witnessSet();
25876
+ let witnessSetVkeys = witnessSet.vkeys();
25877
+ let witnessSetVkeysValues = witnessSetVkeys ? [
25878
+ ...witnessSetVkeys.values(),
25879
+ ...addedWitnesses.vkeys()?.values() ?? []
25880
+ ] : [...addedWitnesses.vkeys()?.values() ?? []];
25881
+ witnessSet.setVkeys(
25882
+ Serialization7.CborSet.fromCore(
25883
+ witnessSetVkeysValues.map((vkw) => vkw.toCore()),
25884
+ Serialization7.VkeyWitness.fromCore
25885
+ )
25886
+ );
25887
+ const signedTx = new Serialization7.Transaction(
25888
+ transaction.body(),
25889
+ witnessSet,
25890
+ transaction.auxiliaryData()
25891
+ );
25892
+ return signedTx.toCbor();
22571
25893
  }
22572
25894
  };
22573
25895
  export {
22574
25896
  AddressType,
22575
25897
  BaseSigner,
22576
25898
  CardanoAddress,
25899
+ CardanoBrowserWallet,
25900
+ CardanoHeadlessWallet,
22577
25901
  CredentialType,
22578
- InMemoryBip32
25902
+ InMemoryBip32,
25903
+ MeshCardanoBrowserWallet,
25904
+ MeshCardanoHeadlessWallet
22579
25905
  };
22580
25906
  /*! Bundled license information:
22581
25907