Skip to content

Implement clear auth for gift card mints#958

Open
jbojcic1 wants to merge 1 commit intosupport-clear-auth-with-shared-secretfrom
impl/clear-auth-wallet-authprovider
Open

Implement clear auth for gift card mints#958
jbojcic1 wants to merge 1 commit intosupport-clear-auth-with-shared-secretfrom
impl/clear-auth-wallet-authprovider

Conversation

@jbojcic1
Copy link
Copy Markdown
Collaborator

Implements #957

@jbojcic1 jbojcic1 requested a review from gudnuf March 25, 2026 15:20
@jbojcic1 jbojcic1 self-assigned this Mar 25, 2026
@supabase
Copy link
Copy Markdown

supabase bot commented Mar 25, 2026

This pull request has been ignored for the connected project hrebgkfhjpkbxpztqqke because there are no changes detected in supabase directory. You can change this behaviour in Project Integrations Settings ↗︎.


Preview Branches by Supabase.
Learn more about Supabase Branching ↗︎.

@vercel
Copy link
Copy Markdown

vercel bot commented Mar 25, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
agicash Ready Ready Preview, Comment Apr 1, 2026 9:59pm

Request Review

@jbojcic1
Copy link
Copy Markdown
Collaborator Author

Not ready for review yet. I am not happy with some stuff here so will iterate

quotes: pendingMeltQuotes,
getWallet: (mintUrl) => {
const sourceAccount = getCashuAccountByMintUrl(mintUrl);
const authProvider = getMintAuthProvider(sourceAccount?.purpose);
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

at the moment we have to check if there is existing account for mint url and if yes what is the purpose to decide which (if any) auth provider is needed

I don't see another way to do it. unless we want to:
a) make getCashuWallet async and call mint info first to get purpose from there
b) make list of gift card accounts somewhere static so getCashuWallet can read it

blocklist: mintBlocklist,
});

type MintPurpose = 'gift-card' | 'transactional';
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i don't want to import purpose from accounts folder becaue shared feature shouldn't import non shared one. I was thinking to import it from /lib/cash protocol extensions but it's not there. @gudnuf didn't we change how we expose that stuff in mint info to include purpose?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yea, but that's in my open PRs for offers. In the agicash PR to support offer mints I exported MintPurpose here. Then here I reexported it as AccountPurpose because spark accounts have a purpose of transactional

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we can update this then once that gets merged

@ditto-agent ditto-agent force-pushed the impl/clear-auth-wallet-authprovider branch from 7ec10a1 to bb72ec7 Compare April 1, 2026 16:21
blocklist: mintBlocklist,
});

type MintPurpose = 'gift-card' | 'transactional';
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yea, but that's in my open PRs for offers. In the agicash PR to support offer mints I exported MintPurpose here. Then here I reexported it as AccountPurpose because spark accounts have a purpose of transactional

const sourceAccount = getCashuAccountByMintUrl(sourceMintUrl);

const sourceWallet = getCashuWallet(sourceMintUrl, {
unit: cashuUnit,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The account should have the wallet on it already, why use getCashuWallet here instead of just sourceAccount.wallet?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good point. I forgot that

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i changed it so that it uses that wallet and calls getCashuWallet only if there is no account for that mint url

}

/**
* Hook to get the method which returns the first cashu account matching a mint URL, or null if not found.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if you have a USD and BTC account with same mint URL?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good point. fixed

@@ -39,6 +40,7 @@ import { type Currency, type CurrencyUnit, Money } from '~/lib/money';
import { measureOperation } from '~/lib/performance';
import { computeSHA256 } from '~/lib/sha256';
import { getSeedPhraseDerivationPath } from '../accounts/account-cryptography';
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

to your comment on importing to shared from non-shared, just btw this does that.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i know. I noticed that too but didn't want to make unrelated changes now. we need to clean that up and possibly reorganize some other stuff too (e.g. perhaps bunch of stuff from accounts need to go to shared etc)

Add NUT-21 Clear Auth support so gift card mints can protect endpoints.

- Add getAgicashMintAuthProvider in features/shared/agicash-mint-auth-provider.ts
  with React Query caching (shared across all gift card mints)
- Add getMintAuthProvider(purpose) in features/shared/cashu.ts to map
  account purpose to the appropriate auth provider
- Add useGetCashuAccountByMintUrlAndCurrency hook for looking up accounts
- Pass auth provider to getCashuWallet for gift card accounts in:
  account-repository, user-repository, receive hooks, send hooks
- Add getWallet callback to useOnMeltQuoteStateChange so callers control
  wallet construction with auth
- Change getInitializedCashuWallet to use named params object
- Extract isLoggedIn to features/shared/auth.ts
- Delete implementation plan doc

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants