| … | … | @@ -27,18 +27,16 @@ |
| 27 | 27 | import crypto from 'bare-crypto' |
| 28 | 28 | import b4a from 'b4a' |
| 29 | 29 | import { readAttested } from 'favela-identity/lib/attestation.js' |
| 30 | // ⛔ THE BYTES COME FROM THE SHARED PACKAGE, not from here. The claimant builds them too, and a |
| 31 | // disagreement of one byte surfaces as "proof does not attest that identity" — indistinguishable |
| 32 | // from a forged proof. One definition, next to the verifier that consumes it. |
| 33 | import { claimBytes, releaseBytes } from 'favela-identity/lib/bridge-claim.js' |
| 30 | 34 | |
| 31 | 35 | const HEX64 = /^[0-9a-f]{64}$/i |
| 32 | 36 | // Deliberately the same shape registrations.js enforces, so bytes signed here can never describe a |
| 33 | 37 | // name the registry would reject. |
| 34 | 38 | const NAME = /^[a-z0-9][a-z0-9_-]{0,31}$/ |
| 35 | 39 | |
| 36 | | // ⚠ VERSIONED AND PREFIXED. The prefix keeps a claim proof from ever verifying as a release proof; |
| 37 | | // the version means a future change to what is bound can be introduced without silently accepting |
| 38 | | // both shapes. Colons are safe separators: a username cannot contain one (NAME), and the nonce and |
| 39 | | // feed key are hex. |
| 40 | | const CLAIM = 'favela-bridge:v1:claim' |
| 41 | | const RELEASE = 'favela-bridge:v1:release' |
| 42 | 40 | |
| 43 | 41 | const DEFAULT_TTL = 120_000 // two minutes — a round trip, not a session |
| 44 | 42 | |
| … | … | @@ -65,14 +63,10 @@ export class Admission { |
| 65 | 63 | } |
| 66 | 64 | |
| 67 | 65 | /** The exact bytes a claimant must sign. Public, because the caller has to produce them too. */ |
| 68 | | claimBytes ({ nonce, username, feedKey }) { |
| 69 | | return b4a.from([CLAIM, nonce, username, feedKey || ''].join(':'), 'utf8') |
| 70 | | } |
| 66 | claimBytes (params) { return claimBytes(params) } |
| 71 | 67 | |
| 72 | | /** The exact bytes a releaser must sign. No feed: releasing says nothing about where a feed is. */ |
| 73 | | releaseBytes ({ nonce, username }) { |
| 74 | | return b4a.from([RELEASE, nonce, username].join(':'), 'utf8') |
| 75 | | } |
| 68 | /** The exact bytes a releaser must sign. */ |
| 69 | releaseBytes (params) { return releaseBytes(params) } |
| 76 | 70 | |
| 77 | 71 | verifyClaim ({ nonce, username, feedKey, root, proof } = {}) { |
| 78 | 72 | if (badName(username)) return fail('bad username') |