Repository navigation
feat(#95): an AdMob provider beside AdSense, selected by source on POST /proofs - #100
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
Deployed: the relay host (
@Nabil-Aufa: #104 can now run against the real relay from |
3102f64 to
1095ba6
Compare
|
Rebased onto |
…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.
1095ba6 to
8097128
Compare
Lexirieru
left a comment
There was a problem hiding this comment.
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.
* 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
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 ofbe/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.\n,\r\nseparator never matters. The figure is extracted asrevenueMicros(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 norow, so the relay stops withproviderbefore the attestor.audit.ts: AdMob'sClaimShape.auditRevenueProoftakes aClaimShape, 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 /proofstakessource: "adsense" | "admob", defaulting toadsense. An AdSenserequestis byte-identical to before. An AdMob one addssourceandrevenueMicros, andrevenueUsdis then an exact decimal, for display only.prove:admobproduces one real proof, with the token passed inline (GOOGLE_ACCESS_TOKEN="$(wl-paste)"), so it is never written tobe/.env. That proof is AdMob (#90): pin the AdMob claim template from a real proof #96's input.docs/admob-provider.md(new) anddocs/api.md.For #94 (@Lexirieru)
be/src/admob/request.test.tschecks that, in the canonical parameters, the six date numbers come before/accounts/pub-…. That is your[sy, sm, sd, ey, em, ed, pub_id].revenueMicros, notrevenueUsd. Sorebuild_contextneeds the key per source as well,{"revenueMicros":"…"}for AdMob. That is one more arm in the samematch. 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:source, andPOST /proofsvalidation.tools/check_links.pyon both docs.Not done yet, and listed on #95: one real AdMob proof through
prove:admob, and redeploying the relay once this merges.