Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(keyAutoAdd/cards): normalize ilp.dev wallet addresses #878

Merged
merged 4 commits into from
Jan 30, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 25 additions & 5 deletions src/content/keyAutoAdd/testWallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,11 @@ type AccountDetails = {
};
};

const API_ORIGIN =
location.host === 'wallet.interledger.cards'
? 'https://api.interledger.cards'
: `https://api.${location.host}`;
const IS_INTERLEDGER_CARDS = location.host === 'wallet.interledger.cards';

const API_ORIGIN = IS_INTERLEDGER_CARDS
? 'https://api.interledger.cards'
: `https://api.${location.host}`;

const waitForLogin: Run<void> = async (
{ keyAddUrl },
Expand Down Expand Up @@ -120,7 +121,7 @@ const findWallet: Run<{ accountId: string; walletId: string }> = async (
const accounts = output(getAccounts);
for (const account of accounts) {
for (const wallet of account.walletAddresses) {
if (toWalletAddressUrl(wallet.url) === walletAddressUrl) {
if (walletAddressUrl === normalizeWalletAddress(wallet.url)) {
return { accountId: account.id, walletId: wallet.id };
}
}
Expand Down Expand Up @@ -166,6 +167,25 @@ async function revokeKey(accountId: string, walletId: string, keyId: string) {
throw new Error(`Failed to revoke key: ${await res.text()}`);
}
}

function normalizeWalletAddress(urlOrPaymentPointer: string) {
const url = new URL(toWalletAddressUrl(urlOrPaymentPointer));
sidvishnoi marked this conversation as resolved.
Show resolved Hide resolved
if (IS_INTERLEDGER_CARDS && url.host === 'ilp.dev') {
// For Interledger Cards we can have two types of wallet addresses:
// - ilp.interledger.cards
// - ilp.dev (just a proxy behind ilp.interledger.cards for certain wallet addresses)
//
// `ilp.dev` wallet addresses are only used for wallet addresses that are
// linked to a card.
//
// `ilp.interledger.cards` used for the other wallet addresses (user created)
//
// Not all `ilp.interledger.cards` wallet addresses can be used with `ilp.dev`.
// Manually created wallet addresses cannot be used with `ilp.dev`.
return url.href.replace('ilp.dev', 'ilp.interledger.cards');
}
return url.href;
}
// endregion

// region: Main
Expand Down