Repository navigation
feat: serve B3Note at note.b3pay.net with the same principals - #11
Merged
Merged
Conversation
Internet Identity derives a principal per origin, so a custom domain is a new origin and would give every user a new, empty account. At https://note.b3pay.net the app now signs in with derivationOrigin set to the canister's own address, which lists the domain in /.well-known/ii-alternative-origins, so a user keeps their principal and their notes at both addresses. - src/lib/origins.ts: production's frontend origin, backend id and custom domains, and customDomainAt(origin) for the page. - src/reactor.ts: on a custom domain, AuthClient gets derivationOrigin and the backend is called by its id. The ic_env cookie is not trusted there (any b3pay.net subdomain can set it), so the id comes from origins.ts. Nothing changes at the canister's own address or locally. - public/.well-known/ic-domains (read by the HTTP gateways before they serve the domain) and ii-alternative-origins (read by Internet Identity). - .ic-assets.json5: keep .well-known, which the asset canister skips as a hidden folder, and serve ii-alternative-origins as JSON with CORS. - tests/customDomain.test.ts: the origin mapping, the three lists agree, the asset rules, and the app's client loaded at note.b3pay.net and at the canister's address (AuthClient options, backend id, agent host). - README: a Custom domain section with the DNS records and registration. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017cSwEz3Q2o3DpuJ8qSQzY5
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Serve B3Note at
https://note.b3pay.netwithout giving its users new accounts. Internet Identity derives a principal per origin, so at the custom domain the app now signs in withderivationOriginset to the canister's own address,https://4lidq-zqaaa-aaaap-abkbq-cai.icp0.io, which lists the domain in/.well-known/ii-alternative-origins. A user has the same principal, and the same notes, at both addresses.Changes
frontend/src/lib/origins.ts(new): production's frontend origin, backend id and custom domains, andcustomDomainAt(origin).frontend/src/reactor.ts: at a custom domain,AuthClientgetsderivationOrigin, and the backend is called by its id. ic-reactor does not trust theic_envcookie there (anyb3pay.netsubdomain can set it), so the id comes fromorigins.ts. Nothing changes at the canister's own address or locally.frontend/public/.well-known/ic-domains(read by the HTTP gateways before they serve the domain) andii-alternative-origins(read by Internet Identity).frontend/public/.ic-assets.json5: keeps.well-known, which the asset canister skips as a hidden folder, and servesii-alternative-originsas JSON withAccess-Control-Allow-Origin: *.frontend/tests/customDomain.test.ts(new, 6 tests): the origin mapping, thatorigins.tsand both.well-knownfiles list the same domains, the asset rules, and the app's client loaded atnote.b3pay.netand at the canister's address (theAuthClientoptions, the backend it calls even with a hostileic_envcookie, the agent host).README.md: a "Custom domain" section with the DNS records and the registration calls.Verification
frontend/,pnpm format:check,pnpm typecheck,pnpm test(6 files, 48 tests) andpnpm buildpass.dist/holds.well-known/ic-domains,.well-known/ii-alternative-originsand.ic-assets.json5, the bundle holds the domain and both ids, andsrc/canistersis unchanged.derivationOrigin, no custom-domain backend id, every origin treated as a custom domain, no.well-knownrule, a wrong alternative origin) each failed the matching test, and were reverted.https://<canister id>.icp0.io/.well-known/ii-alternative-origins, and issues an alternative origin listed there the derivation origin's principals.@dfinity/asset-canisterrecipe uploads.well-knownonly withignore: false, and the gateways need/.well-known/ic-domains. The shared sessions guide saysicp.net,icp0.ioandic0.appalready give a canister one principal, and recommends the canister's own address as the derivation origin, pinned before the app has users.forge.b3pay.nethas the same three records, DNS only, and its registration status isregistered.note.b3pay.nethas no records yet, and its validation fails on the missing_acme-challengeCNAME, as expected.After merge (mainnet, yours)
icp deploy -e production frontendcurl -si https://4lidq-zqaaa-aaaap-abkbq-cai.icp0.io/.well-known/ii-alternative-originsshowsaccess-control-allow-origin: *and the JSON, andcurl -s https://4lidq-zqaaa-aaaap-abkbq-cai.icp0.io/.well-known/ic-domainsprintsnote.b3pay.net.validate, thenPOST, then poll the status untilregistered(README).Notes
b3noteapp already listshttps://note.b3pay.net; B3Pay/b3pay-hub#13 adds it to the hub worker's CORS origins.servedByTheIctrusts theic_envcookie onic0.app, which is not on the Public Suffix List (icp0.ioand*.icp.netare, list of 2026-10-22), so anotheric0.appcanister could set that cookie. This canister answers 400 onic0.app, so no B3Note page runs there today.Generated by Claude Code