Skip to content

feat(#95): an AdMob provider beside AdSense, selected by source on POST /proofs - #100

Merged
Lexirieru merged 4 commits into
mainfrom
feat/admob-relay
Oct 30, 2026
Merged

Lexirieru merged 4 commits into
mainfrom
feat/admob-relay

Conversation

@Lin1er

@Lin1er Lin1er commented Oct 26, 2026

Copy link
Copy Markdown
Collaborator

Closes the code half of #95. Draft until @Lexirieru says go on #90 (path A, moved earlier). Nothing here changes the shipped AdSense flow.

What

  • be/src/admob/, the sibling of be/src/adsense/:
    • request.ts: POST …/networkReport:generate. The body is written by hand, so the same window always gives the same bytes: the window, ESTIMATED_EARNINGS, no dimensions, USD. The token goes into the secret headers only.
    • Two RE2 regexes, each kept inside one element of the streamed array, so Spike (#90): zkFetch POST body signing, and AdMob's response at zero and above #93's \n,\r\n separator never matters. The figure is extracted as revenueMicros (integer micros).
    • account.ts: the only AdMob account the token can read, and a live check on the raw response text. At zero AdMob sends no row, so the relay stops with provider before the attestor.
    • audit.ts: AdMob's ClaimShape.
  • The audit is shared. auditRevenueProof takes a ClaimShape, so both sources use the same allow-list, credential scan and signature check. For AdSense the default shape is exactly the old checks; its tests are unchanged and pass.
  • POST /proofs takes source: "adsense" | "admob", defaulting to adsense. An AdSense request is byte-identical to before. An AdMob one adds source and revenueMicros, and revenueUsd is then an exact decimal, for display only.
  • prove:admob produces one real proof, with the token passed inline (GOOGLE_ACCESS_TOKEN="$(wl-paste)"), so it is never written to be/.env. That proof is AdMob (#90): pin the AdMob claim template from a real proof #96's input.
  • Docs: docs/admob-provider.md (new) and docs/api.md.

For #94 (@Lexirieru)

  • The value order is pinned by a test here. be/src/admob/request.test.ts checks that, in the canonical parameters, the six date numbers come before /accounts/pub-…. That is your [sy, sm, sd, ey, em, ed, pub_id].
  • The extracted name is revenueMicros, not revenueUsd. So rebuild_context needs the key per source as well, {"revenueMicros":"…"} for AdMob. That is one more arm in the same match. I chose a separate name so that a micros string can never be read as dollars by anything that sees the claim. If you would rather keep one key, say so before AdMob (#90): pin the AdMob claim template from a real proof #96 derives the template, because the name is inside the signed context.

Checked

  • tsc --noEmit, eslint .: clean.
  • tsx --test: 117 of 117 (99 before). The new tests cover:
  • tools/check_links.py on both docs.
  • No real account's figures or ids are in the code, tests or docs. The fixtures use made-up values.

Not done yet, and listed on #95: one real AdMob proof through prove:admob, and redeploying the relay once this merges.

@Lin1er
Lin1er requested a review from Lexirieru October 26, 2026 14:57
@vercel

vercel Bot commented Oct 26, 2026 •

Copy link
Copy Markdown

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

Project Deployment Actions Updated
forepay Ready Ready Preview Oct 30, 2026 1:36pm UTC
forepay-vue5 Ready Ready Preview Oct 30, 2026 1:36pm UTC

@Lin1er

Lin1er commented Oct 27, 2026

Copy link
Copy Markdown
Collaborator Author

Deployed: the relay host (api-forepay.jameshub.fun) runs this branch at 3102f64 as of 2026-10-27. This PR is still unmerged.

@Nabil-Aufa: #104 can now run against the real relay from http://localhost:3000, which is in CORS_ORIGINS. A Vercel preview origin is not. A proof works end to end. The last step, request_advance, is still refused until #94.

@Lin1er

Lin1er commented Oct 29, 2026

Copy link
Copy Markdown
Collaborator Author

Rebased onto main (with #103) and redeployed: the relay host runs 1095ba6 as of 2026-10-29 23:35 UTC. One conflict, in prove.ts: #103's owner check now applies to AdMob proofs too, with a test. BE 121/121. #101 is rebased on top (780aa7c). Evidence: docs/deployments.md on #99. #107 must reach the host before #106's execute_upgrade.

…ST /proofs

be/src/admob/ proves the trailing AdMob revenue the way be/src/adsense/
proves AdSense's: a POST to networkReport:generate whose JSON body carries
the window (signed byte for byte, #93), with regexes written against the
bytes #93 read from a real account, including the \n,\r\n separator.

- The figure is extracted as revenueMicros, an integer; the contract
  truncates it to cents (#94). At zero AdMob sends no row, and the relay
  stops with provider before the attestor.
- The AdSense audit takes a ClaimShape, so both sources share one
  allow-list, credential scan and signature check. AdSense's behaviour
  and its request JSON are unchanged.
- POST /proofs takes source: "adsense" | "admob", defaulting to adsense.
- prove:admob produces one real proof, with the token passed inline, as
  the input to the AdMob template (#96).
- A test pins the signed value order for AdMob, dates before pub_id,
  which is what the contract has to rebuild (#94).

docs/admob-provider.md and docs/api.md describe it. 117 BE tests pass.
A report with no row is how AdMob says the account earned nothing. That is
not a shape the relay failed to expect, so the front end should not tell the
creator to try again in a few minutes (asked on #104).
An approved AdSense account with no earnings answers with only its headers and
dates: no totals, no averages, no row count. That failed as provider, the same
as a shape we did not expect. It is now empty, before the attestor, like AdMob.
@Lin1er
Lin1er marked this pull request as ready for review October 30, 2026 13:36

@Lexirieru Lexirieru left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Approving, and the go you were waiting for on #90 is given — @Lexirieru's, as PM, relayed here.

The thing I came to break was the shared audit, because it touches the shipped AdSense path and a regression there costs us the demo, not just AdMob. I traced it branch by branch rather than trusting "its tests are unchanged":

Check in auditRevenueProof Before With adsenseShape Same?
parameters.url expected.url shape.url, from the same buildRevenueRequest(expect) yes
parameters.method literal "GET" shape.method = "GET" yes
parameters.body undefined || "" passes (params.body ?? "") === "" yes, including undefined
publicHeaders PUBLIC_HEADERS shape.publicHeaders, the same set object yes
responseMatches / responseRedactions expected.secretOptions.* shape.*, same source yes
extractedParameters exactly { revenueUsd: DECIMAL } shape.figure.name + format yes
returned revenueUsd the extracted figure shape.figure.toUsd(figure), identity for AdSense yes

So the AdSense audit is behaviour-identical, and the default shape = adsenseShape(expect) fails closed if an AdMob proof ever reaches it unlabelled: the URL check rejects it first.

Verified on main as it is now, not on your branch

Your branch predates #107 and #104. I merged it onto current main locally, because that combination is what actually ships and neither CI run has seen it:

What Result
tsx --test on main + this 124 pass, 0 fail (104 from main, 20 new)
eslint . clean
tsc --noEmit clean

No interaction with #107's source on /advances — that one is read from the chain, this one is an input to POST /proofs. Different field, different direction.

microsToUsd I checked by hand at the edges, since the front end displays its output and #104's provenUsd falls back to it: "0" → "0", "1" → "0.000001", "1000000" → "1", "10000000" → "10", "4567" → "0.004567", "12345678" → "12.345678". Exact, never rounded, and the sub-cent case stops loudly later — I simulated quote("0.00") against the live contract and it is AdvanceTooSmall (#31), not a silent zero offer.

Your question about the figure name is settled, and you were right

If you would rather keep one key, say so before #96 derives the template.

Separate keys. #106 is merged (3fe8ba2) and already implements it that way:

fn revenue_key(source: &Source) -> &'static [u8] {
    match source {
        Source::AdSense => b"revenueUsd",
        Source::AdMob => b"revenueMicros",
    }
}

The asymmetry is the whole argument. Micros read as dollars is silent and maximal — quote("123450000") returns exactly the cap. Dollars read as micros is loud. One of those two mistakes you find in testing and the other you find in the ledger, so the name has to make the first one impossible. Putting it inside the signed context, as you did, means the attestor's signature covers the unit.

Your value-order test is the other thing I needed: [sy, sm, sd, ey, em, ed, pub_id] for AdMob is what #106 encodes in claim_values, and it lives in the contract rather than in the template because rebuild_parameters interleaves positionally.

One correction to your own "Not done yet"

one real AdMob proof through prove:admob, and redeploying the relay once this merges.

Both are already behind you, and that is the problem I raised on #99. The host answers an AdMob request today: I probed it with a deliberately bad token and it came back naming admob.readonly, a string that exists nowhere in be/ on main. So this code has been live on the host for some time, and you have the real proof from it.

That is good work and the strongest evidence this project has. It just means the record was wrong, not the relay. With this merged, the host and main can agree again — redeploy and #99 becomes true as written.

Merging. Keeping feat/admob-relay: #101 is based on it, and deleting the base is what auto-closed #57.

@Lexirieru
Lexirieru merged commit 8d4a03b into main Oct 30, 2026
9 checks passed
Lexirieru pushed a commit that referenced this pull request Oct 30, 2026
* docs(#17): the relay host runs main, at 03da644

The host was fast-forwarded from 29d6719 and restarted. The only
runtime change is #92's wording; health, config, ready and CORS were
checked from outside afterwards.

* docs(#17): the relay host runs feat/admob-relay at 3102f64, for AdMob before #100 merges

* docs(#17): the relay host runs feat/admob-relay rebased onto main, at 1095ba6

* docs(#17): #107 is on the relay host, at 8097128, before #106's upgrade

* docs(#17): the relay host is back on main, at 2ea1e15
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.

2 participants