@333eco/origin-verify 0.3.0 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -33,10 +33,22 @@ Four states. Each stands alone and none implies another.
33
33
  **What a record does not say:** who imagined the work, or that one person holds one account. Without a signer's reveal it says *the operator witnessed this claim at this time and cannot later remove it*. With the reveal, *a passkey whose public key is given here signed exactly this claim*.
34
34
 
35
35
  **Version-3 records** name their press, inside the log's signature: `press: { key: "passkey" }`, or for a key held by the B-PoH app
36
- `{ key: "b-poh", unlock, shown }` (how it was unlocked; whose screen showed the words). A revealed press must carry the origin its
37
- press allows: a press made in the app's own screen (`shown: "app"`) one of the trust file's `appOrigins` — none is listed yet, so such
38
- a reveal is refused until the app ships — and every other press sign.333.eco's, including an app key pressed through the phone's
39
- passkey sheet, whose origin the browser writes. Version-2 records read exactly as before.
36
+ `{ key: "b-poh", unlock, shown, platform }` (how it was unlocked; whose screen showed the words; `android` or `ios`). A revealed press
37
+ must carry the origin its press allows: a press made in the app's own screen (`shown: "app"`) one of the trust file's `appOrigins`, in
38
+ its platform's form (`android:apk-key-hash:<…>` or `ios:app-id:<team>.<bundle>`) — none is listed yet, so such a reveal is refused
39
+ until the app ships — and every other press sign.333.eco's, including an Android app key pressed through the phone's passkey sheet,
40
+ whose origin the browser writes. An iPhone press is made only in the app's own screen and has no key statement: Apple's App Attest
41
+ vouched for the app, which vouched for the key. A `b-poh` record without `platform` (the sandbox's, before v1.11) reads as Android.
42
+ Version-2 records read exactly as before.
43
+
44
+ **Key statements and revocations** (b-poh-statements §5, §6.1). A press made with a B-PoH app key may travel with a *key statement*:
45
+ what sign.333.eco found, when the key was enrolled, about where the key lives and what unlocks it, signed by the key statement key
46
+ (the trust file's `keyStatementKeys`, never a record key). `checkKeyStatement(statement, entry, opening, trust, revocations)`, called
47
+ after `checkReveal` passed, answers for that press: `covered: true` (no revocation reaches the press's minute), `covered: false` with
48
+ both dates of the revocation that reaches it, or `covered: null` when the log was not read (never read as covered). It returns
49
+ `declared` apart from `attested`: a declared field is the app's word, and `sensorsPresent` lists sensors the phone HAS, never which one
50
+ unlocks the key. `findRevocations(get, size, trust)` reads the log's `revoke` entries; a holder's revocation reveals through
51
+ `checkReveal` like a record. None of it says who held the phone.
40
52
 
41
53
  ## Finding a file after its metadata is gone
42
54
 
package/index.mjs CHANGED
@@ -158,7 +158,10 @@ export async function checkReveal(entry, opening, trust) {
158
158
  if (toB64u(commitment) !== entry.assertionCommitment) return fail("the opening does not match the record's commitment");
159
159
  const challenge = entry.t === "record"
160
160
  ? sha256(utf8("b-origin/claim/v1\0"), raw.nonce, sha256(utf8(canonical(entry.claim))))
161
- : entry.t === "withdraw" ? sha256(utf8("b-origin/withdraw/v1\0"), raw.nonce, u64(entry.target)) : null;
161
+ : entry.t === "withdraw" ? sha256(utf8("b-origin/withdraw/v1\0"), raw.nonce, u64(entry.target))
162
+ // A holder's revocation (b-poh-statements §5): one passkey press bound to EVERY key the entry names, in order, and the date.
163
+ : entry.t === "revoke" && entry.by === "holder" && Array.isArray(entry.keys) && typeof entry.compromised === "string"
164
+ ? sha256(utf8("b-origin/revoke/v1\0"), raw.nonce, u32(entry.keys.length), ...entry.keys.map((k) => lp(b64u(String(k)))), lp(utf8(entry.compromised))) : null;
162
165
  if (!challenge) return fail("nothing to reveal in this entry");
163
166
  if (toB64u(challenge) !== entry.claimCommitment) return fail("the challenge does not bind this claim");
164
167
  let cd;
@@ -166,8 +169,15 @@ export async function checkReveal(entry, opening, trust) {
166
169
  // Version 3: the record names its press, inside the log's signature. A press made in the B-PoH app's own screen (shown "app")
167
170
  // carries an app origin the trust file must list; every other press carries sign.333.eco's — a passkey, every version-2 record,
168
171
  // and an app key pressed through the phone's passkey sheet (shown "site"), whose origin the browser writes.
169
- const appPress = entry.v >= 3 && entry.press?.key === "b-poh" && entry.press?.shown === "app";
170
- const originOk = appPress ? Array.isArray(trust.appOrigins) && trust.appOrigins.includes(cd.origin) : cd.origin === trust.webOrigin;
172
+ // v1.11: `platform` says which phone pressed, and with it what was attested at enrollment, and the origin's FORM must agree: `ios` (Apple's
173
+ // App Attest attested the APP, which vouched for the key) presses only in the app's own screen, from `ios:app-id:<team>.<bundle>`;
174
+ // `android` (the phone attested the KEY itself) from `android:apk-key-hash:<…>`. A b-poh record without it was written before v1.11, in
175
+ // the sandbox, on Android: read as `android`. So a record cannot name one platform and carry the other's press.
176
+ const bpoh = entry.v >= 3 && entry.press?.key === "b-poh", platform = entry.press?.platform ?? "android";
177
+ if (bpoh && !(platform === "android" || (platform === "ios" && entry.press.shown === "app"))) return fail("the record's press says something no app writes");
178
+ const appPress = bpoh && entry.press?.shown === "app";
179
+ const form = platform === "ios" ? "ios:app-id:" : "android:apk-key-hash:";
180
+ const originOk = appPress ? Array.isArray(trust.appOrigins) && trust.appOrigins.includes(cd.origin) && String(cd.origin).startsWith(form) : cd.origin === trust.webOrigin;
171
181
  if (cd.type !== "webauthn.get" || !originOk || cd.challenge !== entry.claimCommitment) return fail("the assertion was made elsewhere or for something else");
172
182
  const auth = raw.authenticatorData;
173
183
  if (auth.length < 37 || !eq(auth.subarray(0, 32), sha256(utf8(trust.rpId)))) return fail("the assertion names another site");
@@ -177,6 +187,45 @@ export async function checkReveal(entry, opening, trust) {
177
187
  if (!good) return fail("the passkey's signature does not verify");
178
188
  return { ok: true, passkeyPublicKey: opening.credentialPublicKey };
179
189
  }
190
+ // ── key statements and revocations (b-poh-statements §5, §6.1) ────────────────────────────────────────────────────────────────
191
+ /** A key ID: the SHA-256 of the COSE public key a proof's opening carries (`credentialPublicKey`, base64url-decoded). */
192
+ export const keyIdOf = (cosePublicKey) => toB64u(sha256(cosePublicKey));
193
+ /** Every revocation among these entries whose witness signature verifies. ⛔ Read the log to its latest checkpoint first (auditLog). */
194
+ export async function revocationsIn(entries, trust) {
195
+ const out = [];
196
+ for (const e of entries) if (e?.t === "revoke" && Array.isArray(e.keys) && typeof e.compromised === "string" && (await checkWitnessSignature(e, trust))) out.push(e);
197
+ return out;
198
+ }
199
+ export async function findRevocations(get, size, trust) { return revocationsIn((await readEntries(get, size)).map((b) => JSON.parse(text(b))), trust); }
200
+ /**
201
+ * What a key statement lets a checker say about ONE b-poh press (§6.1, §9.5). Call it after `checkReveal(entry, opening)` passed.
202
+ * `revocations`: from findRevocations; `null` when the log could not be read → `covered: null`, never read as covered.
203
+ * The answer is about the KEY when the press was made, never about who held the phone (§1); `declared` is the app's word and is
204
+ * returned apart from `attested`, never as attested.
205
+ */
206
+ export async function checkKeyStatement(statement, entry, opening, trust, revocations) {
207
+ const fail = (why) => ({ ok: false, why });
208
+ if (!statement || statement.t !== "key" || statement.v !== 1 || typeof statement.sig !== "string") return fail("not a key statement");
209
+ const spki = trust.keyStatementKeys?.[statement.kid];
210
+ if (!spki) return fail("the key statement's key is not one the trust file lists for key statements");
211
+ const { sig, ...rest } = statement;
212
+ let good = false;
213
+ try { good = await crypto.subtle.verify({ name: "ECDSA", hash: "SHA-256" }, await importP256(b64(spki)), b64u(sig), concat(utf8("b-origin/key/v1\0"), utf8(canonical(rest)))); } catch { good = false; }
214
+ if (!good) return fail("the key statement's signature does not verify");
215
+ if (statement.key !== keyIdOf(b64u(String(opening?.credentialPublicKey ?? "")))) return fail("a key statement that doesn't belong to this press");
216
+ if (!(entry?.v >= 3 && entry.press?.key === "b-poh")) return fail("this record was not pressed with a B-PoH app key");
217
+ // v1.11: a key statement is about a key the phone itself attested; an iPhone's (platform: "ios") has none.
218
+ if (entry.press.platform === "ios") return fail("an iPhone press has no key statement: Apple attested the app, not the key");
219
+ if (entry.press.unlock !== statement.attested?.unlock) return fail("the record's unlock is not one this key allows");
220
+ if (!(Date.parse(statement.checked) <= Date.parse(entry.witnessedAt))) return fail("the key statement is dated after the press");
221
+ const base = { ok: true, key: statement.key, checked: statement.checked, attested: statement.attested, declared: statement.declared };
222
+ if (!Array.isArray(revocations)) return { ...base, covered: null, why: "the key couldn't be checked just now: the log was not read to its latest checkpoint" };
223
+ const hits = revocations.filter((r) => r.keys.includes(statement.key) && Date.parse(r.compromised) <= Date.parse(entry.witnessedAt))
224
+ .sort((a, b) => Date.parse(a.compromised) - Date.parse(b.compromised));
225
+ if (hits.length) return { ...base, covered: false, revoked: { compromised: hits[0].compromised, known: hits[0].witnessedAt, by: hits[0].by, index: hits[0].index } };
226
+ return { ...base, covered: true };
227
+ }
228
+
180
229
  /** SPEC §6.4: which of these entries carry this person's tag. Anything here they did not make is a forgery to report. */
181
230
  export function findMine(tagKey, entries) {
182
231
  const key = b64u(tagKey), out = [];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@333eco/origin-verify",
3
- "version": "0.3.0",
3
+ "version": "0.5.0",
4
4
  "description": "Checks a B-Origin record with no help from its operator: signatures, its place in the public log, witness cosignatures, RFC 3161 tokens, OpenTimestamps proofs against Bitcoin, and a signer's reveal. Browser or Node, no runtime dependencies.",
5
5
  "license": "CC0-1.0 OR Apache-2.0",
6
6
  "author": "Thon Ly",
package/trust.mjs CHANGED
@@ -5,6 +5,11 @@ export default {
5
5
  "recordKeys": {
6
6
  "k1-1": "MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEBJbkbZoh6NVkspuIZKGXnOs25DxF331TbbGqhK1j2rtsWIZI5x6Ze+jo4mc3kNcqnJFnpUGlOoVu0zexPo0WzQ=="
7
7
  },
8
+ // K12, the key statement key (b-poh-statements §6.1): created 2026-11-26 (sign.333.eco KEYS.md Ceremony 3), SPKI SHA-256 b7612d5c…48b0.
9
+ // ⛔ Apart from recordKeys on purpose: a record key never signs a key statement, and this key never signs a log entry.
10
+ "keyStatementKeys": {
11
+ "k12-1": "MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEgFEqWgp0FhU+uOphnSUK3+CvM5jr8Iem/Z8jB64cpQFUQe/CuA5ZfsjRKPYxOFS0bOXKqE15eg0BUXyEfgq+lg=="
12
+ },
8
13
  "rpId": "sign.333.eco",
9
14
  "webOrigin": "https://sign.333.eco",
10
15
  // The Witness Network's TESTING list (2026-11-04). These witnesses may reset or disappear, so they are named and NOT counted: no witnessQuorum, so `witnessed` stays false.