92225a4de857b4db49051afbaefbc3d57d45188e9c19381c0d2797f582d7f3bf.json raw
1 {"ast":null,"code":"var __assign = this && this.__assign || function () {\n __assign = Object.assign || function (t) {\n for (var s, i = 1, n = arguments.length; i < n; i++) {\n s = arguments[i];\n for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];\n }\n return t;\n };\n return __assign.apply(this, arguments);\n};\nvar __awaiter = this && this.__awaiter || function (thisArg, _arguments, P, generator) {\n function adopt(value) {\n return value instanceof P ? value : new P(function (resolve) {\n resolve(value);\n });\n }\n return new (P || (P = Promise))(function (resolve, reject) {\n function fulfilled(value) {\n try {\n step(generator.next(value));\n } catch (e) {\n reject(e);\n }\n }\n function rejected(value) {\n try {\n step(generator[\"throw\"](value));\n } catch (e) {\n reject(e);\n }\n }\n function step(result) {\n result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);\n }\n step((generator = generator.apply(thisArg, _arguments || [])).next());\n });\n};\nvar __generator = this && this.__generator || function (thisArg, body) {\n var _ = {\n label: 0,\n sent: function () {\n if (t[0] & 1) throw t[1];\n return t[1];\n },\n trys: [],\n ops: []\n },\n f,\n y,\n t,\n g;\n return g = {\n next: verb(0),\n \"throw\": verb(1),\n \"return\": verb(2)\n }, typeof Symbol === \"function\" && (g[Symbol.iterator] = function () {\n return this;\n }), g;\n function verb(n) {\n return function (v) {\n return step([n, v]);\n };\n }\n function step(op) {\n if (f) throw new TypeError(\"Generator is already executing.\");\n while (g && (g = 0, op[0] && (_ = 0)), _) try {\n if (f = 1, y && (t = op[0] & 2 ? y[\"return\"] : op[0] ? y[\"throw\"] || ((t = y[\"return\"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;\n if (y = 0, t) op = [op[0] & 2, t.value];\n switch (op[0]) {\n case 0:\n case 1:\n t = op;\n break;\n case 4:\n _.label++;\n return {\n value: op[1],\n done: false\n };\n case 5:\n _.label++;\n y = op[1];\n op = [0];\n continue;\n case 7:\n op = _.ops.pop();\n _.trys.pop();\n continue;\n default:\n if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {\n _ = 0;\n continue;\n }\n if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {\n _.label = op[1];\n break;\n }\n if (op[0] === 6 && _.label < t[1]) {\n _.label = t[1];\n t = op;\n break;\n }\n if (t && _.label < t[2]) {\n _.label = t[2];\n _.ops.push(op);\n break;\n }\n if (t[2]) _.ops.pop();\n _.trys.pop();\n continue;\n }\n op = body.call(thisArg, _);\n } catch (e) {\n op = [6, e];\n y = 0;\n } finally {\n f = t = 0;\n }\n if (op[0] & 5) throw op[1];\n return {\n value: op[0] ? op[1] : void 0,\n done: true\n };\n }\n};\nvar __spreadArray = this && this.__spreadArray || function (to, from, pack) {\n if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {\n if (ar || !(i in from)) {\n if (!ar) ar = Array.prototype.slice.call(from, 0, i);\n ar[i] = from[i];\n }\n }\n return to.concat(ar || Array.prototype.slice.call(from));\n};\nimport { bytesToHex, hexToBytes, randomBytes } from '@noble/hashes/utils';\nimport { BlindedMessage } from './model/BlindedMessage.js';\nimport { MintQuoteState, MeltQuoteState } from './model/types/index.js';\nimport { bytesToNumber, getDecodedToken, splitAmount, sumProofs, getKeepAmounts, numberToHexPadded64, hasValidDleq, stripDleq } from './utils.js';\nimport { hashToCurve, pointFromHex } from '@cashu/crypto/modules/common';\nimport { blindMessage, constructProofFromPromise, serializeProof } from '@cashu/crypto/modules/client';\nimport { deriveBlindingFactor, deriveSecret } from '@cashu/crypto/modules/client/NUT09';\nimport { createP2PKsecret, getSignedProofs } from '@cashu/crypto/modules/client/NUT11';\nimport { verifyDLEQProof_reblind } from '@cashu/crypto/modules/client/NUT12';\n/**\n * The default number of proofs per denomination to keep in a wallet.\n */\nvar DEFAULT_DENOMINATION_TARGET = 3;\n/**\n * The default unit for the wallet, if not specified in constructor.\n */\nvar DEFAULT_UNIT = 'sat';\n/**\n * Class that represents a Cashu wallet.\n * This class should act as the entry point for this library\n */\nvar CashuWallet = /** @class */function () {\n /**\n * @param mint Cashu mint instance is used to make api calls\n * @param options.unit optionally set unit (default is 'sat')\n * @param options.keys public keys from the mint (will be fetched from mint if not provided)\n * @param options.keysets keysets from the mint (will be fetched from mint if not provided)\n * @param options.mintInfo mint info from the mint (will be fetched from mint if not provided)\n * @param options.denominationTarget target number proofs per denomination (default: see @constant DEFAULT_DENOMINATION_TARGET)\n * @param options.bip39seed BIP39 seed for deterministic secrets.\n * This can lead to poor performance, in which case the seed should be directly provided\n */\n function CashuWallet(mint, options) {\n var _this = this;\n this._keys = new Map();\n this._keysets = [];\n this._seed = undefined;\n this._unit = DEFAULT_UNIT;\n this._mintInfo = undefined;\n this._denominationTarget = DEFAULT_DENOMINATION_TARGET;\n this.mint = mint;\n var keys = [];\n if ((options === null || options === void 0 ? void 0 : options.keys) && !Array.isArray(options.keys)) {\n keys = [options.keys];\n } else if ((options === null || options === void 0 ? void 0 : options.keys) && Array.isArray(options === null || options === void 0 ? void 0 : options.keys)) {\n keys = options === null || options === void 0 ? void 0 : options.keys;\n }\n if (keys) keys.forEach(function (key) {\n return _this._keys.set(key.id, key);\n });\n if (options === null || options === void 0 ? void 0 : options.unit) this._unit = options === null || options === void 0 ? void 0 : options.unit;\n if (options === null || options === void 0 ? void 0 : options.keysets) this._keysets = options.keysets;\n if (options === null || options === void 0 ? void 0 : options.mintInfo) this._mintInfo = options.mintInfo;\n if (options === null || options === void 0 ? void 0 : options.denominationTarget) {\n this._denominationTarget = options.denominationTarget;\n }\n if (options === null || options === void 0 ? void 0 : options.bip39seed) {\n if (options.bip39seed instanceof Uint8Array) {\n this._seed = options.bip39seed;\n return;\n }\n throw new Error('bip39seed must be a valid UInt8Array');\n }\n }\n Object.defineProperty(CashuWallet.prototype, \"unit\", {\n get: function () {\n return this._unit;\n },\n enumerable: false,\n configurable: true\n });\n Object.defineProperty(CashuWallet.prototype, \"keys\", {\n get: function () {\n return this._keys;\n },\n enumerable: false,\n configurable: true\n });\n Object.defineProperty(CashuWallet.prototype, \"keysetId\", {\n get: function () {\n if (!this._keysetId) {\n throw new Error('No keysetId set');\n }\n return this._keysetId;\n },\n set: function (keysetId) {\n this._keysetId = keysetId;\n },\n enumerable: false,\n configurable: true\n });\n Object.defineProperty(CashuWallet.prototype, \"keysets\", {\n get: function () {\n return this._keysets;\n },\n enumerable: false,\n configurable: true\n });\n Object.defineProperty(CashuWallet.prototype, \"mintInfo\", {\n get: function () {\n if (!this._mintInfo) {\n throw new Error('Mint info not loaded');\n }\n return this._mintInfo;\n },\n enumerable: false,\n configurable: true\n });\n /**\n * Get information about the mint\n * @returns mint info\n */\n CashuWallet.prototype.getMintInfo = function () {\n return __awaiter(this, void 0, void 0, function () {\n var _a;\n return __generator(this, function (_b) {\n switch (_b.label) {\n case 0:\n _a = this;\n return [4 /*yield*/, this.mint.getInfo()];\n case 1:\n _a._mintInfo = _b.sent();\n return [2 /*return*/, this._mintInfo];\n }\n });\n });\n };\n /**\n * Load mint information, keysets and keys. This function can be called if no keysets are passed in the constructor\n */\n CashuWallet.prototype.loadMint = function () {\n return __awaiter(this, void 0, void 0, function () {\n return __generator(this, function (_a) {\n switch (_a.label) {\n case 0:\n return [4 /*yield*/, this.getMintInfo()];\n case 1:\n _a.sent();\n return [4 /*yield*/, this.getKeySets()];\n case 2:\n _a.sent();\n return [4 /*yield*/, this.getKeys()];\n case 3:\n _a.sent();\n return [2 /*return*/];\n }\n });\n });\n };\n /**\n * Choose a keyset to activate based on the lowest input fee\n *\n * Note: this function will filter out deprecated base64 keysets\n *\n * @param keysets keysets to choose from\n * @returns active keyset\n */\n CashuWallet.prototype.getActiveKeyset = function (keysets) {\n var activeKeysets = keysets.filter(function (k) {\n return k.active;\n });\n // we only consider keyset IDs that start with \"00\"\n activeKeysets = activeKeysets.filter(function (k) {\n return k.id.startsWith('00');\n });\n var activeKeyset = activeKeysets.sort(function (a, b) {\n var _a, _b;\n return ((_a = a.input_fee_ppk) !== null && _a !== void 0 ? _a : 0) - ((_b = b.input_fee_ppk) !== null && _b !== void 0 ? _b : 0);\n })[0];\n if (!activeKeyset) {\n throw new Error('No active keyset found');\n }\n return activeKeyset;\n };\n /**\n * Get keysets from the mint with the unit of the wallet\n * @returns keysets with wallet's unit\n */\n CashuWallet.prototype.getKeySets = function () {\n return __awaiter(this, void 0, void 0, function () {\n var allKeysets, unitKeysets;\n var _this = this;\n return __generator(this, function (_a) {\n switch (_a.label) {\n case 0:\n return [4 /*yield*/, this.mint.getKeySets()];\n case 1:\n allKeysets = _a.sent();\n unitKeysets = allKeysets.keysets.filter(function (k) {\n return k.unit === _this._unit;\n });\n this._keysets = unitKeysets;\n return [2 /*return*/, this._keysets];\n }\n });\n });\n };\n /**\n * Get all active keys from the mint and set the keyset with the lowest fees as the active wallet keyset.\n * @returns keyset\n */\n CashuWallet.prototype.getAllKeys = function () {\n return __awaiter(this, void 0, void 0, function () {\n var keysets;\n return __generator(this, function (_a) {\n switch (_a.label) {\n case 0:\n return [4 /*yield*/, this.mint.getKeys()];\n case 1:\n keysets = _a.sent();\n this._keys = new Map(keysets.keysets.map(function (k) {\n return [k.id, k];\n }));\n this.keysetId = this.getActiveKeyset(this._keysets).id;\n return [2 /*return*/, keysets.keysets];\n }\n });\n });\n };\n /**\n * Get public keys from the mint. If keys were already fetched, it will return those.\n *\n * If `keysetId` is set, it will fetch and return that specific keyset.\n * Otherwise, we select an active keyset with the unit of the wallet.\n *\n * @param keysetId optional keysetId to get keys for\n * @param forceRefresh? if set to true, it will force refresh the keyset from the mint\n * @returns keyset\n */\n CashuWallet.prototype.getKeys = function (keysetId, forceRefresh) {\n return __awaiter(this, void 0, void 0, function () {\n var localKeyset, keys;\n return __generator(this, function (_a) {\n switch (_a.label) {\n case 0:\n if (!(!(this._keysets.length > 0) || forceRefresh)) return [3 /*break*/, 2];\n return [4 /*yield*/, this.getKeySets()];\n case 1:\n _a.sent();\n _a.label = 2;\n case 2:\n // no keyset id is chosen, let's choose one\n if (!keysetId) {\n localKeyset = this.getActiveKeyset(this._keysets);\n keysetId = localKeyset.id;\n }\n if (!!this._keysets.find(function (k) {\n return k.id === keysetId;\n })) return [3 /*break*/, 4];\n return [4 /*yield*/, this.getKeySets()];\n case 3:\n _a.sent();\n if (!this._keysets.find(function (k) {\n return k.id === keysetId;\n })) {\n throw new Error(\"could not initialize keys. No keyset with id '\".concat(keysetId, \"' found\"));\n }\n _a.label = 4;\n case 4:\n if (!!this._keys.get(keysetId)) return [3 /*break*/, 6];\n return [4 /*yield*/, this.mint.getKeys(keysetId)];\n case 5:\n keys = _a.sent();\n this._keys.set(keysetId, keys.keysets[0]);\n _a.label = 6;\n case 6:\n // set and return\n this.keysetId = keysetId;\n return [2 /*return*/, this._keys.get(keysetId)];\n }\n });\n });\n };\n /**\n * Receive an encoded or raw Cashu token (only supports single tokens. It will only process the first token in the token array)\n * @param {(string|Token)} token - Cashu token, either as string or decoded\n * @param options.keysetId? override the keysetId derived from the current mintKeys with a custom one. This should be a keyset that was fetched from the `/keysets` endpoint\n * @param options.outputAmounts? optionally specify the output's amounts to keep and to send.\n * @param options.proofsWeHave? optionally provide all currently stored proofs of this mint. Cashu-ts will use them to derive the optimal output amounts\n * @param options.counter? optionally set counter to derive secret deterministically. CashuWallet class must be initialized with seed phrase to take effect\n * @param options.pubkey? optionally locks ecash to pubkey. Will not be deterministic, even if counter is set!\n * @param options.privkey? will create a signature on the @param token secrets if set\n * @param options.requireDleq? will check each proof for DLEQ proofs. Reject the token if any one of them can't be verified.\n * @returns New token with newly created proofs, token entries that had errors\n */\n CashuWallet.prototype.receive = function (token, options) {\n return __awaiter(this, void 0, void 0, function () {\n var keys, amount, _a, payload, blindingData, signatures, freshProofs;\n return __generator(this, function (_b) {\n switch (_b.label) {\n case 0:\n if (typeof token === 'string') {\n token = getDecodedToken(token);\n }\n return [4 /*yield*/, this.getKeys(options === null || options === void 0 ? void 0 : options.keysetId)];\n case 1:\n keys = _b.sent();\n if (options === null || options === void 0 ? void 0 : options.requireDleq) {\n if (token.proofs.some(function (p) {\n return !hasValidDleq(p, keys);\n })) {\n throw new Error('Token contains proofs with invalid DLEQ');\n }\n }\n amount = sumProofs(token.proofs) - this.getFeesForProofs(token.proofs);\n _a = this.createSwapPayload(amount, token.proofs, keys, options === null || options === void 0 ? void 0 : options.outputAmounts, options === null || options === void 0 ? void 0 : options.counter, options === null || options === void 0 ? void 0 : options.pubkey, options === null || options === void 0 ? void 0 : options.privkey), payload = _a.payload, blindingData = _a.blindingData;\n return [4 /*yield*/, this.mint.swap(payload)];\n case 2:\n signatures = _b.sent().signatures;\n freshProofs = this.constructProofs(signatures, blindingData.blindingFactors, blindingData.secrets, keys);\n return [2 /*return*/, freshProofs];\n }\n });\n });\n };\n /**\n * Send proofs of a given amount, by providing at least the required amount of proofs\n * @param amount amount to send\n * @param proofs array of proofs (accumulated amount of proofs must be >= than amount)\n * @param options.outputAmounts? optionally specify the output's amounts to keep and send.\n * @param options.counter? optionally set counter to derive secret deterministically. CashuWallet class must be initialized with seed phrase to take effect\n * @param options.proofsWeHave? optionally provide all currently stored proofs of this mint. Cashu-ts will use them to derive the optimal output amounts\n * @param options.pubkey? optionally locks ecash to pubkey. Will not be deterministic, even if counter is set!\n * @param options.privkey? will create a signature on the output secrets if set\n * @param options.keysetId? override the keysetId derived from the current mintKeys with a custom one. This should be a keyset that was fetched from the `/keysets` endpoint\n * @param options.offline? optionally send proofs offline.\n * @param options.includeFees? optionally include fees in the response.\n * @param options.includeDleq? optionally include DLEQ proof in the proofs to send.\n * @returns {SendResponse}\n */\n CashuWallet.prototype.send = function (amount, proofs, options) {\n var _a;\n return __awaiter(this, void 0, void 0, function () {\n var _b, keepProofsOffline, sendProofOffline, expectedFee, _c, keepProofsSelect, sendProofs, _d, keep, send;\n return __generator(this, function (_e) {\n switch (_e.label) {\n case 0:\n if (options === null || options === void 0 ? void 0 : options.includeDleq) {\n proofs = proofs.filter(function (p) {\n return p.dleq != undefined;\n });\n }\n if (sumProofs(proofs) < amount) {\n throw new Error('Not enough funds available to send');\n }\n _b = this.selectProofsToSend(proofs, amount, options === null || options === void 0 ? void 0 : options.includeFees), keepProofsOffline = _b.keep, sendProofOffline = _b.send;\n expectedFee = (options === null || options === void 0 ? void 0 : options.includeFees) ? this.getFeesForProofs(sendProofOffline) : 0;\n if (!(!(options === null || options === void 0 ? void 0 : options.offline) && (sumProofs(sendProofOffline) != amount + expectedFee || (\n // if the exact amount cannot be selected\n options === null || options === void 0 ? void 0 : options.outputAmounts) || (options === null || options === void 0 ? void 0 : options.pubkey) || (options === null || options === void 0 ? void 0 : options.privkey) || (options === null || options === void 0 ? void 0 : options.keysetId))) // these options require a swap\n ) return [3 /*break*/, 2]; // these options require a swap\n _c = this.selectProofsToSend(proofs, amount, true), keepProofsSelect = _c.keep, sendProofs = _c.send;\n (_a = options === null || options === void 0 ? void 0 : options.proofsWeHave) === null || _a === void 0 ? void 0 : _a.push.apply(_a, keepProofsSelect);\n return [4 /*yield*/, this.swap(amount, sendProofs, options)];\n case 1:\n _d = _e.sent(), keep = _d.keep, send = _d.send;\n keep = keepProofsSelect.concat(keep);\n if (!(options === null || options === void 0 ? void 0 : options.includeDleq)) {\n send = stripDleq(send);\n }\n return [2 /*return*/, {\n keep: keep,\n send: send\n }];\n case 2:\n if (sumProofs(sendProofOffline) < amount + expectedFee) {\n throw new Error('Not enough funds available to send');\n }\n if (!(options === null || options === void 0 ? void 0 : options.includeDleq)) {\n return [2 /*return*/, {\n keep: keepProofsOffline,\n send: stripDleq(sendProofOffline)\n }];\n }\n return [2 /*return*/, {\n keep: keepProofsOffline,\n send: sendProofOffline\n }];\n }\n });\n });\n };\n CashuWallet.prototype.selectProofsToSend = function (proofs, amountToSend, includeFees) {\n var sortedProofs = proofs.sort(function (a, b) {\n return a.amount - b.amount;\n });\n var smallerProofs = sortedProofs.filter(function (p) {\n return p.amount <= amountToSend;\n }).sort(function (a, b) {\n return b.amount - a.amount;\n });\n var biggerProofs = sortedProofs.filter(function (p) {\n return p.amount > amountToSend;\n }).sort(function (a, b) {\n return a.amount - b.amount;\n });\n var nextBigger = biggerProofs[0];\n if (!smallerProofs.length && nextBigger) {\n return {\n keep: proofs.filter(function (p) {\n return p.secret !== nextBigger.secret;\n }),\n send: [nextBigger]\n };\n }\n if (!smallerProofs.length && !nextBigger) {\n return {\n keep: proofs,\n send: []\n };\n }\n var remainder = amountToSend;\n var selectedProofs = [smallerProofs[0]];\n var returnedProofs = [];\n var feePPK = includeFees ? this.getFeesForProofs(selectedProofs) : 0;\n remainder -= selectedProofs[0].amount - feePPK / 1000;\n if (remainder > 0) {\n var _a = this.selectProofsToSend(smallerProofs.slice(1), remainder, includeFees),\n keep = _a.keep,\n send = _a.send;\n selectedProofs.push.apply(selectedProofs, send);\n returnedProofs.push.apply(returnedProofs, keep);\n }\n var selectedFeePPK = includeFees ? this.getFeesForProofs(selectedProofs) : 0;\n if (sumProofs(selectedProofs) < amountToSend + selectedFeePPK && nextBigger) {\n selectedProofs = [nextBigger];\n }\n return {\n keep: proofs.filter(function (p) {\n return !selectedProofs.includes(p);\n }),\n send: selectedProofs\n };\n };\n /**\n * calculates the fees based on inputs (proofs)\n * @param proofs input proofs to calculate fees for\n * @returns fee amount\n */\n CashuWallet.prototype.getFeesForProofs = function (proofs) {\n var _this = this;\n if (!this._keysets.length) {\n throw new Error('Could not calculate fees. No keysets found');\n }\n var keysetIds = new Set(proofs.map(function (p) {\n return p.id;\n }));\n keysetIds.forEach(function (id) {\n if (!_this._keysets.find(function (k) {\n return k.id === id;\n })) {\n throw new Error(\"Could not calculate fees. No keyset found with id: \".concat(id));\n }\n });\n var fees = Math.floor(Math.max((proofs.reduce(function (total, curr) {\n var _a;\n return total + (((_a = _this._keysets.find(function (k) {\n return k.id === curr.id;\n })) === null || _a === void 0 ? void 0 : _a.input_fee_ppk) || 0);\n }, 0) + 999) / 1000, 0));\n return fees;\n };\n /**\n * calculates the fees based on inputs for a given keyset\n * @param nInputs number of inputs\n * @param keysetId keysetId used to lookup `input_fee_ppk`\n * @returns fee amount\n */\n CashuWallet.prototype.getFeesForKeyset = function (nInputs, keysetId) {\n var _a;\n var fees = Math.floor(Math.max((nInputs * (((_a = this._keysets.find(function (k) {\n return k.id === keysetId;\n })) === null || _a === void 0 ? void 0 : _a.input_fee_ppk) || 0) + 999) / 1000, 0));\n return fees;\n };\n /**\n * Splits and creates sendable tokens\n * if no amount is specified, the amount is implied by the cumulative amount of all proofs\n * if both amount and preference are set, but the preference cannot fulfill the amount, then we use the default split\n * @param amount amount to send while performing the optimal split (least proofs possible). can be set to undefined if preference is set\n * @param proofs proofs matching that amount\n * @param options.outputAmounts? optionally specify the output's amounts to keep and to send.\n * @param options.counter? optionally set counter to derive secret deterministically. CashuWallet class must be initialized with seed phrase to take effect\n * @param options.keysetId? override the keysetId derived from the current mintKeys with a custom one. This should be a keyset that was fetched from the `/keysets` endpoint\n * @param options.includeFees? include estimated fees for the receiver to receive the proofs\n * @param options.proofsWeHave? optionally provide all currently stored proofs of this mint. Cashu-ts will use them to derive the optimal output amounts\n * @param options.pubkey? optionally locks ecash to pubkey. Will not be deterministic, even if counter is set!\n * @param options.privkey? will create a signature on the @param proofs secrets if set\n * @returns promise of the change- and send-proofs\n */\n CashuWallet.prototype.swap = function (amount, proofs, options) {\n var _a, _b, _c;\n return __awaiter(this, void 0, void 0, function () {\n var keyset, proofsToSend, amountToSend, amountAvailable, amountToKeep, sendAmounts, outputFee, sendAmountsFee, keepAmounts, _d, payload, blindingData, signatures, swapProofs, splitProofsToKeep, splitProofsToSend, amountToKeepCounter;\n return __generator(this, function (_e) {\n switch (_e.label) {\n case 0:\n if (!options) options = {};\n return [4 /*yield*/, this.getKeys(options.keysetId)];\n case 1:\n keyset = _e.sent();\n proofsToSend = proofs;\n amountToSend = amount;\n amountAvailable = sumProofs(proofs);\n amountToKeep = amountAvailable - amountToSend - this.getFeesForProofs(proofsToSend);\n sendAmounts = ((_a = options === null || options === void 0 ? void 0 : options.outputAmounts) === null || _a === void 0 ? void 0 : _a.sendAmounts) || splitAmount(amountToSend, keyset.keys);\n // include the fees to spend the the outputs of the swap\n if (options === null || options === void 0 ? void 0 : options.includeFees) {\n outputFee = this.getFeesForKeyset(sendAmounts.length, keyset.id);\n sendAmountsFee = splitAmount(outputFee, keyset.keys);\n while (this.getFeesForKeyset(sendAmounts.concat(sendAmountsFee).length, keyset.id) > outputFee) {\n outputFee++;\n sendAmountsFee = splitAmount(outputFee, keyset.keys);\n }\n sendAmounts = sendAmounts.concat(sendAmountsFee);\n amountToSend += outputFee;\n amountToKeep -= outputFee;\n }\n if (options && !((_b = options.outputAmounts) === null || _b === void 0 ? void 0 : _b.keepAmounts) && options.proofsWeHave) {\n keepAmounts = getKeepAmounts(options.proofsWeHave, amountToKeep, keyset.keys, this._denominationTarget);\n } else if (options.outputAmounts) {\n if (((_c = options.outputAmounts.keepAmounts) === null || _c === void 0 ? void 0 : _c.reduce(function (a, b) {\n return a + b;\n }, 0)) != amountToKeep) {\n throw new Error('Keep amounts do not match amount to keep');\n }\n keepAmounts = options.outputAmounts.keepAmounts;\n }\n if (amountToSend + this.getFeesForProofs(proofsToSend) > amountAvailable) {\n console.error(\"Not enough funds available (\".concat(amountAvailable, \") for swap amountToSend: \").concat(amountToSend, \" + fee: \").concat(this.getFeesForProofs(proofsToSend), \" | length: \").concat(proofsToSend.length));\n throw new Error(\"Not enough funds available for swap\");\n }\n if (amountToSend + this.getFeesForProofs(proofsToSend) + amountToKeep != amountAvailable) {\n throw new Error('Amounts do not match for swap');\n }\n options.outputAmounts = {\n keepAmounts: keepAmounts,\n sendAmounts: sendAmounts\n };\n _d = this.createSwapPayload(amountToSend, proofsToSend, keyset, options === null || options === void 0 ? void 0 : options.outputAmounts, options === null || options === void 0 ? void 0 : options.counter, options === null || options === void 0 ? void 0 : options.pubkey, options === null || options === void 0 ? void 0 : options.privkey), payload = _d.payload, blindingData = _d.blindingData;\n return [4 /*yield*/, this.mint.swap(payload)];\n case 2:\n signatures = _e.sent().signatures;\n swapProofs = this.constructProofs(signatures, blindingData.blindingFactors, blindingData.secrets, keyset);\n splitProofsToKeep = [];\n splitProofsToSend = [];\n amountToKeepCounter = 0;\n swapProofs.forEach(function (proof) {\n if (amountToKeepCounter < amountToKeep) {\n amountToKeepCounter += proof.amount;\n splitProofsToKeep.push(proof);\n return;\n }\n splitProofsToSend.push(proof);\n });\n return [2 /*return*/, {\n keep: splitProofsToKeep,\n send: splitProofsToSend\n }];\n }\n });\n });\n };\n /**\n * Regenerates\n * @param start set starting point for count (first cycle for each keyset should usually be 0)\n * @param count set number of blinded messages that should be generated\n * @param options.keysetId set a custom keysetId to restore from. keysetIds can be loaded with `CashuMint.getKeySets()`\n */\n CashuWallet.prototype.restore = function (start, count, options) {\n return __awaiter(this, void 0, void 0, function () {\n var keys, amounts, _a, blindedMessages, blindingFactors, secrets, _b, outputs, promises, validBlindingFactors, validSecrets;\n return __generator(this, function (_c) {\n switch (_c.label) {\n case 0:\n return [4 /*yield*/, this.getKeys(options === null || options === void 0 ? void 0 : options.keysetId)];\n case 1:\n keys = _c.sent();\n if (!this._seed) {\n throw new Error('CashuWallet must be initialized with a seed to use restore');\n }\n amounts = Array(count).fill(0);\n _a = this.createBlindedMessages(amounts, keys.id, start), blindedMessages = _a.blindedMessages, blindingFactors = _a.blindingFactors, secrets = _a.secrets;\n return [4 /*yield*/, this.mint.restore({\n outputs: blindedMessages\n })];\n case 2:\n _b = _c.sent(), outputs = _b.outputs, promises = _b.promises;\n validBlindingFactors = blindingFactors.filter(function (_, i) {\n return outputs.map(function (o) {\n return o.B_;\n }).includes(blindedMessages[i].B_);\n });\n validSecrets = secrets.filter(function (_, i) {\n return outputs.map(function (o) {\n return o.B_;\n }).includes(blindedMessages[i].B_);\n });\n return [2 /*return*/, {\n proofs: this.constructProofs(promises, validBlindingFactors, validSecrets, keys)\n }];\n }\n });\n });\n };\n /**\n * Requests a mint quote form the mint. Response returns a Lightning payment request for the requested given amount and unit.\n * @param amount Amount requesting for mint.\n * @param description optional description for the mint quote\n * @returns the mint will return a mint quote with a Lightning invoice for minting tokens of the specified amount and unit\n */\n CashuWallet.prototype.createMintQuote = function (amount, description) {\n return __awaiter(this, void 0, void 0, function () {\n var mintQuotePayload;\n return __generator(this, function (_a) {\n switch (_a.label) {\n case 0:\n mintQuotePayload = {\n unit: this._unit,\n amount: amount,\n description: description\n };\n return [4 /*yield*/, this.mint.createMintQuote(mintQuotePayload)];\n case 1:\n return [2 /*return*/, _a.sent()];\n }\n });\n });\n };\n /**\n * Gets an existing mint quote from the mint.\n * @param quote Quote ID\n * @returns the mint will create and return a Lightning invoice for the specified amount\n */\n CashuWallet.prototype.checkMintQuote = function (quote) {\n return __awaiter(this, void 0, void 0, function () {\n return __generator(this, function (_a) {\n switch (_a.label) {\n case 0:\n return [4 /*yield*/, this.mint.checkMintQuote(quote)];\n case 1:\n return [2 /*return*/, _a.sent()];\n }\n });\n });\n };\n /**\n * Mint proofs for a given mint quote\n * @param amount amount to request\n * @param quote ID of mint quote\n * @param options.keysetId? optionally set keysetId for blank outputs for returned change.\n * @param options.preference? Deprecated. Use `outputAmounts` instead. Optional preference for splitting proofs into specific amounts.\n * @param options.outputAmounts? optionally specify the output's amounts to keep and to send.\n * @param options.counter? optionally set counter to derive secret deterministically. CashuWallet class must be initialized with seed phrase to take effect\n * @param options.pubkey? optionally locks ecash to pubkey. Will not be deterministic, even if counter is set!\n * @returns proofs\n */\n CashuWallet.prototype.mintProofs = function (amount, quote, options) {\n var _a;\n return __awaiter(this, void 0, void 0, function () {\n var keyset, _b, blindedMessages, secrets, blindingFactors, mintPayload, signatures;\n return __generator(this, function (_c) {\n switch (_c.label) {\n case 0:\n return [4 /*yield*/, this.getKeys(options === null || options === void 0 ? void 0 : options.keysetId)];\n case 1:\n keyset = _c.sent();\n if (!(options === null || options === void 0 ? void 0 : options.outputAmounts) && (options === null || options === void 0 ? void 0 : options.proofsWeHave)) {\n options.outputAmounts = {\n keepAmounts: getKeepAmounts(options.proofsWeHave, amount, keyset.keys, this._denominationTarget),\n sendAmounts: []\n };\n }\n _b = this.createRandomBlindedMessages(amount, keyset, (_a = options === null || options === void 0 ? void 0 : options.outputAmounts) === null || _a === void 0 ? void 0 : _a.keepAmounts, options === null || options === void 0 ? void 0 : options.counter, options === null || options === void 0 ? void 0 : options.pubkey), blindedMessages = _b.blindedMessages, secrets = _b.secrets, blindingFactors = _b.blindingFactors;\n mintPayload = {\n outputs: blindedMessages,\n quote: quote\n };\n return [4 /*yield*/, this.mint.mint(mintPayload)];\n case 2:\n signatures = _c.sent().signatures;\n return [2 /*return*/, this.constructProofs(signatures, blindingFactors, secrets, keyset)];\n }\n });\n });\n };\n /**\n * Requests a melt quote from the mint. Response returns amount and fees for a given unit in order to pay a Lightning invoice.\n * @param invoice LN invoice that needs to get a fee estimate\n * @returns the mint will create and return a melt quote for the invoice with an amount and fee reserve\n */\n CashuWallet.prototype.createMeltQuote = function (invoice) {\n return __awaiter(this, void 0, void 0, function () {\n var meltQuotePayload, meltQuote;\n return __generator(this, function (_a) {\n switch (_a.label) {\n case 0:\n meltQuotePayload = {\n unit: this._unit,\n request: invoice\n };\n return [4 /*yield*/, this.mint.createMeltQuote(meltQuotePayload)];\n case 1:\n meltQuote = _a.sent();\n return [2 /*return*/, meltQuote];\n }\n });\n });\n };\n /**\n * Return an existing melt quote from the mint.\n * @param quote ID of the melt quote\n * @returns the mint will return an existing melt quote\n */\n CashuWallet.prototype.checkMeltQuote = function (quote) {\n return __awaiter(this, void 0, void 0, function () {\n var meltQuote;\n return __generator(this, function (_a) {\n switch (_a.label) {\n case 0:\n return [4 /*yield*/, this.mint.checkMeltQuote(quote)];\n case 1:\n meltQuote = _a.sent();\n return [2 /*return*/, meltQuote];\n }\n });\n });\n };\n /**\n * Melt proofs for a melt quote. proofsToSend must be at least amount+fee_reserve form the melt quote. This function does not perform coin selection!.\n * Returns melt quote and change proofs\n * @param meltQuote ID of the melt quote\n * @param proofsToSend proofs to melt\n * @param options.keysetId? optionally set keysetId for blank outputs for returned change.\n * @param options.counter? optionally set counter to derive secret deterministically. CashuWallet class must be initialized with seed phrase to take effect\n * @param options.privkey? optionally set a private key to unlock P2PK locked secrets\n * @returns\n */\n CashuWallet.prototype.meltProofs = function (meltQuote, proofsToSend, options) {\n return __awaiter(this, void 0, void 0, function () {\n var keys, _a, blindedMessages, secrets, blindingFactors, meltPayload, meltResponse, change;\n return __generator(this, function (_b) {\n switch (_b.label) {\n case 0:\n return [4 /*yield*/, this.getKeys(options === null || options === void 0 ? void 0 : options.keysetId)];\n case 1:\n keys = _b.sent();\n _a = this.createBlankOutputs(sumProofs(proofsToSend) - meltQuote.amount, keys.id, options === null || options === void 0 ? void 0 : options.counter), blindedMessages = _a.blindedMessages, secrets = _a.secrets, blindingFactors = _a.blindingFactors;\n if ((options === null || options === void 0 ? void 0 : options.privkey) != undefined) {\n proofsToSend = getSignedProofs(proofsToSend.map(function (p) {\n return {\n amount: p.amount,\n C: pointFromHex(p.C),\n id: p.id,\n secret: new TextEncoder().encode(p.secret)\n };\n }), options.privkey).map(function (p) {\n return serializeProof(p);\n });\n }\n proofsToSend = stripDleq(proofsToSend);\n meltPayload = {\n quote: meltQuote.quote,\n inputs: proofsToSend,\n outputs: __spreadArray([], blindedMessages, true)\n };\n return [4 /*yield*/, this.mint.melt(meltPayload)];\n case 2:\n meltResponse = _b.sent();\n change = [];\n if (meltResponse.change) {\n change = this.constructProofs(meltResponse.change, blindingFactors, secrets, keys);\n }\n return [2 /*return*/, {\n quote: meltResponse,\n change: change\n }];\n }\n });\n });\n };\n /**\n * Creates a split payload\n * @param amount amount to send\n * @param proofsToSend proofs to split*\n * @param outputAmounts? optionally specify the output's amounts to keep and to send.\n * @param counter? optionally set counter to derive secret deterministically. CashuWallet class must be initialized with seed phrase to take effect\n * @param pubkey? optionally locks ecash to pubkey. Will not be deterministic, even if counter is set!\n * @param privkey? will create a signature on the @param proofsToSend secrets if set\n * @returns\n */\n CashuWallet.prototype.createSwapPayload = function (amount, proofsToSend, keyset, outputAmounts, counter, pubkey, privkey) {\n var totalAmount = proofsToSend.reduce(function (total, curr) {\n return total + curr.amount;\n }, 0);\n if (outputAmounts && outputAmounts.sendAmounts && !outputAmounts.keepAmounts) {\n outputAmounts.keepAmounts = splitAmount(totalAmount - amount - this.getFeesForProofs(proofsToSend), keyset.keys);\n }\n var keepBlindedMessages = this.createRandomBlindedMessages(totalAmount - amount - this.getFeesForProofs(proofsToSend), keyset, outputAmounts === null || outputAmounts === void 0 ? void 0 : outputAmounts.keepAmounts, counter);\n if (this._seed && counter) {\n counter = counter + keepBlindedMessages.secrets.length;\n }\n var sendBlindedMessages = this.createRandomBlindedMessages(amount, keyset, outputAmounts === null || outputAmounts === void 0 ? void 0 : outputAmounts.sendAmounts, counter, pubkey);\n if (privkey) {\n proofsToSend = getSignedProofs(proofsToSend.map(function (p) {\n return {\n amount: p.amount,\n C: pointFromHex(p.C),\n id: p.id,\n secret: new TextEncoder().encode(p.secret)\n };\n }), privkey).map(function (p) {\n return serializeProof(p);\n });\n }\n proofsToSend = stripDleq(proofsToSend);\n // join keepBlindedMessages and sendBlindedMessages\n var blindingData = {\n blindedMessages: __spreadArray(__spreadArray([], keepBlindedMessages.blindedMessages, true), sendBlindedMessages.blindedMessages, true),\n secrets: __spreadArray(__spreadArray([], keepBlindedMessages.secrets, true), sendBlindedMessages.secrets, true),\n blindingFactors: __spreadArray(__spreadArray([], keepBlindedMessages.blindingFactors, true), sendBlindedMessages.blindingFactors, true)\n };\n var payload = {\n inputs: proofsToSend,\n outputs: __spreadArray([], blindingData.blindedMessages, true)\n };\n return {\n payload: payload,\n blindingData: blindingData\n };\n };\n /**\n * Get an array of the states of proofs from the mint (as an array of CheckStateEnum's)\n * @param proofs (only the `secret` field is required)\n * @returns\n */\n CashuWallet.prototype.checkProofsStates = function (proofs) {\n return __awaiter(this, void 0, void 0, function () {\n var enc, Ys, BATCH_SIZE, states, _loop_1, this_1, i;\n return __generator(this, function (_a) {\n switch (_a.label) {\n case 0:\n enc = new TextEncoder();\n Ys = proofs.map(function (p) {\n return hashToCurve(enc.encode(p.secret)).toHex(true);\n });\n BATCH_SIZE = 100;\n states = [];\n _loop_1 = function (i) {\n var YsSlice, batchStates, stateMap, j, state;\n return __generator(this, function (_b) {\n switch (_b.label) {\n case 0:\n YsSlice = Ys.slice(i, i + BATCH_SIZE);\n return [4 /*yield*/, this_1.mint.check({\n Ys: YsSlice\n })];\n case 1:\n batchStates = _b.sent().states;\n stateMap = {};\n batchStates.forEach(function (s) {\n stateMap[s.Y] = s;\n });\n for (j = 0; j < YsSlice.length; j++) {\n state = stateMap[YsSlice[j]];\n if (!state) {\n throw new Error('Could not find state for proof with Y: ' + YsSlice[j]);\n }\n states.push(state);\n }\n return [2 /*return*/];\n }\n });\n };\n this_1 = this;\n i = 0;\n _a.label = 1;\n case 1:\n if (!(i < Ys.length)) return [3 /*break*/, 4];\n return [5 /*yield**/, _loop_1(i)];\n case 2:\n _a.sent();\n _a.label = 3;\n case 3:\n i += BATCH_SIZE;\n return [3 /*break*/, 1];\n case 4:\n return [2 /*return*/, states];\n }\n });\n });\n };\n /**\n * Register a callback to be called whenever a mint quote's state changes\n * @param quoteIds List of mint quote IDs that should be subscribed to\n * @param callback Callback function that will be called whenever a mint quote state changes\n * @param errorCallback\n * @returns\n */\n CashuWallet.prototype.onMintQuoteUpdates = function (quoteIds, callback, errorCallback) {\n return __awaiter(this, void 0, void 0, function () {\n var subId;\n var _this = this;\n return __generator(this, function (_a) {\n switch (_a.label) {\n case 0:\n return [4 /*yield*/, this.mint.connectWebSocket()];\n case 1:\n _a.sent();\n if (!this.mint.webSocketConnection) {\n throw new Error('failed to establish WebSocket connection.');\n }\n subId = this.mint.webSocketConnection.createSubscription({\n kind: 'bolt11_mint_quote',\n filters: quoteIds\n }, callback, errorCallback);\n return [2 /*return*/, function () {\n var _a;\n (_a = _this.mint.webSocketConnection) === null || _a === void 0 ? void 0 : _a.cancelSubscription(subId, callback);\n }];\n }\n });\n });\n };\n /**\n * Register a callback to be called whenever a melt quote's state changes\n * @param quoteIds List of melt quote IDs that should be subscribed to\n * @param callback Callback function that will be called whenever a melt quote state changes\n * @param errorCallback\n * @returns\n */\n CashuWallet.prototype.onMeltQuotePaid = function (quoteId, callback, errorCallback) {\n return __awaiter(this, void 0, void 0, function () {\n return __generator(this, function (_a) {\n return [2 /*return*/, this.onMeltQuoteUpdates([quoteId], function (p) {\n if (p.state === MeltQuoteState.PAID) {\n callback(p);\n }\n }, errorCallback)];\n });\n });\n };\n /**\n * Register a callback to be called when a single mint quote gets paid\n * @param quoteId Mint quote id that should be subscribed to\n * @param callback Callback function that will be called when this mint quote gets paid\n * @param errorCallback\n * @returns\n */\n CashuWallet.prototype.onMintQuotePaid = function (quoteId, callback, errorCallback) {\n return __awaiter(this, void 0, void 0, function () {\n return __generator(this, function (_a) {\n return [2 /*return*/, this.onMintQuoteUpdates([quoteId], function (p) {\n if (p.state === MintQuoteState.PAID) {\n callback(p);\n }\n }, errorCallback)];\n });\n });\n };\n /**\n * Register a callback to be called when a single melt quote gets paid\n * @param quoteId Melt quote id that should be subscribed to\n * @param callback Callback function that will be called when this melt quote gets paid\n * @param errorCallback\n * @returns\n */\n CashuWallet.prototype.onMeltQuoteUpdates = function (quoteIds, callback, errorCallback) {\n return __awaiter(this, void 0, void 0, function () {\n var subId;\n var _this = this;\n return __generator(this, function (_a) {\n switch (_a.label) {\n case 0:\n return [4 /*yield*/, this.mint.connectWebSocket()];\n case 1:\n _a.sent();\n if (!this.mint.webSocketConnection) {\n throw new Error('failed to establish WebSocket connection.');\n }\n subId = this.mint.webSocketConnection.createSubscription({\n kind: 'bolt11_melt_quote',\n filters: quoteIds\n }, callback, errorCallback);\n return [2 /*return*/, function () {\n var _a;\n (_a = _this.mint.webSocketConnection) === null || _a === void 0 ? void 0 : _a.cancelSubscription(subId, callback);\n }];\n }\n });\n });\n };\n /**\n * Register a callback to be called whenever a subscribed proof state changes\n * @param proofs List of proofs that should be subscribed to\n * @param callback Callback function that will be called whenever a proof's state changes\n * @param errorCallback\n * @returns\n */\n CashuWallet.prototype.onProofStateUpdates = function (proofs, callback, errorCallback) {\n return __awaiter(this, void 0, void 0, function () {\n var enc, proofMap, i, y, ys, subId;\n var _this = this;\n return __generator(this, function (_a) {\n switch (_a.label) {\n case 0:\n return [4 /*yield*/, this.mint.connectWebSocket()];\n case 1:\n _a.sent();\n if (!this.mint.webSocketConnection) {\n throw new Error('failed to establish WebSocket connection.');\n }\n enc = new TextEncoder();\n proofMap = {};\n for (i = 0; i < proofs.length; i++) {\n y = hashToCurve(enc.encode(proofs[i].secret)).toHex(true);\n proofMap[y] = proofs[i];\n }\n ys = Object.keys(proofMap);\n subId = this.mint.webSocketConnection.createSubscription({\n kind: 'proof_state',\n filters: ys\n }, function (p) {\n callback(__assign(__assign({}, p), {\n proof: proofMap[p.Y]\n }));\n }, errorCallback);\n return [2 /*return*/, function () {\n var _a;\n (_a = _this.mint.webSocketConnection) === null || _a === void 0 ? void 0 : _a.cancelSubscription(subId, callback);\n }];\n }\n });\n });\n };\n /**\n * Creates blinded messages for a given amount\n * @param amount amount to create blinded messages for\n * @param split optional preference for splitting proofs into specific amounts. overrides amount param\n * @param keyksetId? override the keysetId derived from the current mintKeys with a custom one. This should be a keyset that was fetched from the `/keysets` endpoint\n * @param counter? optionally set counter to derive secret deterministically. CashuWallet class must be initialized with seed phrase to take effect\n * @param pubkey? optionally locks ecash to pubkey. Will not be deterministic, even if counter is set!\n * @returns blinded messages, secrets, rs, and amounts\n */\n CashuWallet.prototype.createRandomBlindedMessages = function (amount, keyset, split, counter, pubkey) {\n var amounts = splitAmount(amount, keyset.keys, split);\n return this.createBlindedMessages(amounts, keyset.id, counter, pubkey);\n };\n /**\n * Creates blinded messages for a according to @param amounts\n * @param amount array of amounts to create blinded messages for\n * @param counter? optionally set counter to derive secret deterministically. CashuWallet class must be initialized with seed phrase to take effect\n * @param keyksetId? override the keysetId derived from the current mintKeys with a custom one. This should be a keyset that was fetched from the `/keysets` endpoint\n * @param pubkey? optionally locks ecash to pubkey. Will not be deterministic, even if counter is set!\n * @returns blinded messages, secrets, rs, and amounts\n */\n CashuWallet.prototype.createBlindedMessages = function (amounts, keysetId, counter, pubkey) {\n // if we atempt to create deterministic messages without a _seed, abort.\n if (counter != undefined && !this._seed) {\n throw new Error('Cannot create deterministic messages without seed. Instantiate CashuWallet with a bip39seed, or omit counter param.');\n }\n var blindedMessages = [];\n var secrets = [];\n var blindingFactors = [];\n for (var i = 0; i < amounts.length; i++) {\n var deterministicR = undefined;\n var secretBytes = undefined;\n if (pubkey) {\n secretBytes = createP2PKsecret(pubkey);\n } else if (this._seed && counter != undefined) {\n secretBytes = deriveSecret(this._seed, keysetId, counter + i);\n deterministicR = bytesToNumber(deriveBlindingFactor(this._seed, keysetId, counter + i));\n } else {\n secretBytes = randomBytes(32);\n }\n if (!pubkey) {\n var secretHex = bytesToHex(secretBytes);\n secretBytes = new TextEncoder().encode(secretHex);\n }\n secrets.push(secretBytes);\n var _a = blindMessage(secretBytes, deterministicR),\n B_ = _a.B_,\n r = _a.r;\n blindingFactors.push(r);\n var blindedMessage = new BlindedMessage(amounts[i], B_, keysetId);\n blindedMessages.push(blindedMessage.getSerializedBlindedMessage());\n }\n return {\n blindedMessages: blindedMessages,\n secrets: secrets,\n blindingFactors: blindingFactors,\n amounts: amounts\n };\n };\n /**\n * Creates NUT-08 blank outputs (fee returns) for a given fee reserve\n * See: https://github.com/cashubtc/nuts/blob/main/08.md\n * @param amount amount to cover with blank outputs\n * @param keysetId mint keysetId\n * @param counter? optionally set counter to derive secret deterministically. CashuWallet class must be initialized with seed phrase to take effect\n * @returns blinded messages, secrets, and rs\n */\n CashuWallet.prototype.createBlankOutputs = function (amount, keysetId, counter) {\n var count = Math.ceil(Math.log2(amount)) || 1;\n //Prevent count from being -Infinity\n if (count < 0) {\n count = 0;\n }\n var amounts = count ? Array(count).fill(1) : [];\n var _a = this.createBlindedMessages(amounts, keysetId, counter),\n blindedMessages = _a.blindedMessages,\n blindingFactors = _a.blindingFactors,\n secrets = _a.secrets;\n return {\n blindedMessages: blindedMessages,\n secrets: secrets,\n blindingFactors: blindingFactors\n };\n };\n /**\n * construct proofs from @params promises, @params rs, @params secrets, and @params keyset\n * @param promises array of serialized blinded signatures\n * @param rs arrays of binding factors\n * @param secrets array of secrets\n * @param keyset mint keyset\n * @returns array of serialized proofs\n */\n CashuWallet.prototype.constructProofs = function (promises, rs, secrets, keyset) {\n return promises.map(function (p, i) {\n var _a;\n var dleq = p.dleq == undefined ? undefined : {\n s: hexToBytes(p.dleq.s),\n e: hexToBytes(p.dleq.e),\n r: rs[i]\n };\n var blindSignature = {\n id: p.id,\n amount: p.amount,\n C_: pointFromHex(p.C_),\n dleq: dleq\n };\n var r = rs[i];\n var secret = secrets[i];\n var A = pointFromHex(keyset.keys[p.amount]);\n var proof = constructProofFromPromise(blindSignature, r, secret, A);\n var serializedProof = __assign(__assign(__assign({}, serializeProof(proof)), dleq && {\n dleqValid: verifyDLEQProof_reblind(secret, dleq, proof.C, A)\n }), dleq && {\n dleq: {\n s: bytesToHex(dleq.s),\n e: bytesToHex(dleq.e),\n r: numberToHexPadded64((_a = dleq.r) !== null && _a !== void 0 ? _a : BigInt(0))\n }\n });\n return serializedProof;\n });\n };\n return CashuWallet;\n}();\nexport { CashuWallet };\n//# sourceMappingURL=CashuWallet.js.map","map":null,"metadata":{},"sourceType":"module","externalDependencies":[]}