diff --git a/package.json b/package.json index 8b888772..06890013 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "minibits_wallet", - "version": "0.1.8-beta.23", + "version": "0.1.8-beta.24", "private": true, "scripts": { "android:clean": "cd android && ./gradlew clean", diff --git a/patches/@cashu+cashu-ts+1.0.0-rc.3.patch b/patches/@cashu+cashu-ts+1.0.0-rc.3.patch index a3b23031..75bb329a 100644 --- a/patches/@cashu+cashu-ts+1.0.0-rc.3.patch +++ b/patches/@cashu+cashu-ts+1.0.0-rc.3.patch @@ -63,7 +63,7 @@ index 1491934..7852bd1 100644 * Requests the mint to perform token minting after the LN invoice has been paid * @param mintUrl diff --git a/node_modules/@cashu/cashu-ts/src/CashuWallet.ts b/node_modules/@cashu/cashu-ts/src/CashuWallet.ts -index 6d3a0b4..02ddb59 100644 +index 6d3a0b4..e4cd79b 100644 --- a/node_modules/@cashu/cashu-ts/src/CashuWallet.ts +++ b/node_modules/@cashu/cashu-ts/src/CashuWallet.ts @@ -1,7 +1,7 @@ @@ -96,7 +96,15 @@ index 6d3a0b4..02ddb59 100644 import { validateMnemonic } from '@scure/bip39'; import { wordlist } from '@scure/bip39/wordlists/english'; import { createP2PKsecret, getSignedProofs } from '@cashu/crypto/modules/client/NUT11'; -@@ -113,6 +113,7 @@ class CashuWallet { +@@ -106,6 +106,7 @@ class CashuWallet { + async receive( + token: string | Token, + options?: { ++ keysetId?: string; + preference?: Array; + counter?: number; + pubkey?: string; +@@ -113,6 +114,7 @@ class CashuWallet { } ): Promise { let decodedToken: Array; @@ -104,12 +112,13 @@ index 6d3a0b4..02ddb59 100644 if (typeof token === 'string') { decodedToken = cleanToken(getDecodedToken(token)).token; } else { -@@ -125,25 +126,26 @@ class CashuWallet { +@@ -125,25 +127,27 @@ class CashuWallet { continue; } try { - const { proofs, proofsWithError } = await this.receiveTokenEntry(tokenEntry, { + const { proofs, proofsWithError, error } = await this.receiveTokenEntry(tokenEntry, { ++ keysetId: options?.keysetId, preference: options?.preference, counter: options?.counter, pubkey: options?.pubkey, @@ -136,7 +145,15 @@ index 6d3a0b4..02ddb59 100644 }; } -@@ -167,6 +169,7 @@ class CashuWallet { +@@ -159,6 +163,7 @@ class CashuWallet { + async receiveTokenEntry( + tokenEntry: TokenEntry, + options?: { ++ keysetId?: string; + preference?: Array; + counter?: number; + pubkey?: string; +@@ -167,13 +172,14 @@ class CashuWallet { ): Promise { const proofsWithError: Array = []; const proofs: Array = []; @@ -144,7 +161,15 @@ index 6d3a0b4..02ddb59 100644 try { const amount = tokenEntry.proofs.reduce((total, curr) => total + curr.amount, 0); let preference = options?.preference; -@@ -192,12 +195,13 @@ class CashuWallet { + if (!preference) { + preference = getDefaultAmountPreference(amount); + } +- const keys = await this.getKeys(); ++ const keys = await this.getKeys(options?.keysetId); + const { payload, blindedMessages } = this.createSplitPayload( + amount, + tokenEntry.proofs, +@@ -192,12 +198,13 @@ class CashuWallet { ); proofs.push(...newProofs); } catch (error) { @@ -160,7 +185,24 @@ index 6d3a0b4..02ddb59 100644 }; } -@@ -317,7 +321,7 @@ class CashuWallet { +@@ -217,6 +224,7 @@ class CashuWallet { + amount: number, + proofs: Array, + options?: { ++ keysetId?: string; + preference?: Array; + counter?: number; + pubkey?: string; +@@ -226,7 +234,7 @@ class CashuWallet { + if (options?.preference) { + amount = options?.preference?.reduce((acc, curr) => acc + curr.amount * curr.count, 0); + } +- const keyset = await this.getKeys(); ++ const keyset = await this.getKeys(options?.keysetId); + let amountAvailable = 0; + const proofsToSend: Array = []; + const proofsToKeep: Array = []; +@@ -317,7 +325,7 @@ class CashuWallet { /** * Initialize the wallet with the mints public keys */ @@ -169,7 +211,7 @@ index 6d3a0b4..02ddb59 100644 if (!this._keys || this._keys.id !== keysetId) { const allKeys = await this.mint.getKeys(keysetId); let keys; -@@ -564,7 +568,7 @@ class CashuWallet { +@@ -564,7 +572,7 @@ class CashuWallet { * @param proofs (only the 'Y' field is required) * @returns */ @@ -178,7 +220,7 @@ index 6d3a0b4..02ddb59 100644 const enc = new TextEncoder(); const Ys = proofs.map((p) => dhke.hashToCurve(enc.encode(p.secret)).toHex(true)); const payload = { -@@ -573,10 +577,17 @@ class CashuWallet { +@@ -573,11 +581,20 @@ class CashuWallet { }; const { states } = await this.mint.check(payload); @@ -195,8 +237,11 @@ index 6d3a0b4..02ddb59 100644 + + return {spent, pending} } ++ ++ private splitReceive( amount: number, + amountAvailable: number diff --git a/node_modules/@cashu/cashu-ts/src/DHKE.ts b/node_modules/@cashu/cashu-ts/src/DHKE.ts index da1dfe6..99f60a2 100644 --- a/node_modules/@cashu/cashu-ts/src/DHKE.ts diff --git a/src/screens/RemoteRecoveryScreen.tsx b/src/screens/RemoteRecoveryScreen.tsx index 40e6b828..b4140ca0 100644 --- a/src/screens/RemoteRecoveryScreen.tsx +++ b/src/screens/RemoteRecoveryScreen.tsx @@ -261,8 +261,9 @@ export const RemoteRecoveryScreen: FC> = o recoveredMint.increaseProofsCounter(selectedKeyset.id as string, Math.abs(endIndex - startIndex)) const {spent, pending} = await MintClient.getSpentOrPendingProofsFromMint( + proofs as Proof[], recoveredMint.mintUrl, - proofs as Proof[] + selectedKeyset.unit as MintUnit, ) log.debug('[restore]', `Spent and pending proofs`, {spent: spent.length, pending: pending.length}) diff --git a/src/services/cashuMintClient.ts b/src/services/cashuMintClient.ts index c1f859bc..83ea764a 100644 --- a/src/services/cashuMintClient.ts +++ b/src/services/cashuMintClient.ts @@ -209,6 +209,7 @@ const receiveFromMint = async function ( // this method returns quite a mess, we normalize naming of returned parameters const {token, tokensWithErrors, errors} = await cashuWallet.receive(decodedToken, { + keysetId: cashuWallet.keys.id, preference: amountPreferences, counter, pubkey: undefined, @@ -248,6 +249,7 @@ const sendFromMint = async function ( amountToSend, proofsToSendFrom, { + keysetId: cashuWallet.keys.id, preference: amountPreferences, counter, pubkey: undefined, @@ -302,13 +304,13 @@ const sendFromMint = async function ( const getSpentOrPendingProofsFromMint = async function ( - mintUrl: string, - // unit: MintUnit, proofs: Proof[], + mintUrl: string, + unit: MintUnit, ) { try { - // use default unit as check does not need it - const cashuWallet = await getWallet(mintUrl, 'sat', {withSeed: true}) + + const cashuWallet = await getWallet(mintUrl, unit, {withSeed: true}) const spentPendingProofs = await cashuWallet.checkProofsSpent(proofs) diff --git a/src/services/wallet/transferTask.ts b/src/services/wallet/transferTask.ts index a10d1cd0..34fe2f23 100644 --- a/src/services/wallet/transferTask.ts +++ b/src/services/wallet/transferTask.ts @@ -134,7 +134,7 @@ export const transferTask = async function ( // I have no idea yet if this can happen, unpaid call throws, return sent Proofs to the store an track tx as Reverted if (!isPaid) { - const { amountPendingByMint } = await _moveProofsFromPending(proofsToPay, mintUrl, transactionId) + const { amountPendingByMint } = await _moveProofsFromPending(proofsToPay, mintUrl, unit, transactionId) // release lock mintInstance.resetInFlight(transactionId) @@ -244,7 +244,7 @@ export const transferTask = async function ( const { amountToMove, amountPendingByMint - } = await _moveProofsFromPending(proofsToPay, mintUrl, transactionId) + } = await _moveProofsFromPending(proofsToPay, mintUrl, unit, transactionId) // keep tx as pending if proofs were not added because of a mint that keeps them as pending for timed out in-flight payment if(amountPendingByMint > 0) { @@ -301,6 +301,7 @@ export const transferTask = async function ( const _moveProofsFromPending = async function ( proofsToMove: CashuProof[], mintUrl: string, + unit: MintUnit, transactionId: number, ): Promise<{ amountToMove: number, @@ -321,8 +322,9 @@ const _moveProofsFromPending = async function ( // due to the timeout but mint's node keeps the payment as in-flight (e.g. receiving node holds the invoice) // In this case we need to keep such proofs as pending and not move them back to wallet as in other payment failures. const {pending: pendingByMint} = await MintClient.getSpentOrPendingProofsFromMint( - mintUrl, proofsToMove as Proof[], + mintUrl, + unit, ) let amountPendingByMint: number = 0 diff --git a/src/services/walletService.ts b/src/services/walletService.ts index 0846f4b1..782881fe 100644 --- a/src/services/walletService.ts +++ b/src/services/walletService.ts @@ -356,14 +356,15 @@ const _handleSpentByMintTask = async function ( proofsCount: 0, proofsAmount: 0 } as WalletTaskResult - } + } const { spent: spentProofs, pending: pendingProofs } = await MintClient.getSpentOrPendingProofsFromMint( - mintUrl, proofsFromMint, + mintUrl, + mint && mint.units ? mint.units[0] : 'sat' ) if(mint) { @@ -602,8 +603,9 @@ const _handleInFlightByMintTask = async function (mint: Mint, seed: Uint8Array): } const {spent, pending} = await MintClient.getSpentOrPendingProofsFromMint( + proofs as Proof[], mint.mintUrl, - proofs as Proof[] + mint.units ? mint.units[0] : 'sat' ) const spentCount = spent.length