@le-space/orbitdb-identity-provider-webauthn-did 0.13.0 → 0.14.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/CHANGELOG.md CHANGED
@@ -1,5 +1,112 @@
1
1
  # Changes
2
2
 
3
+ ## 0.14.0
4
+
5
+ An identity proof is a proof and nothing else: its challenge is labelled, and no longer something a
6
+ signature made for another protocol can stand in for.
7
+
8
+ A vault that replaces another says so, and a keeper never steps back to the one from before.
9
+
10
+ ### Breaking
11
+
12
+ - **New identity proofs are in a new format, which 0.12.x and earlier cannot verify.** Update every
13
+ peer that verifies identities — relays included — before any device creates a new identity proof
14
+ on 0.14.0. A device that already has a proof stored keeps using it, so nothing changes for it until
15
+ the application refuses the first format (below).
16
+
17
+ ### Security
18
+
19
+ - **One 32-byte signature by the passkey could be turned into an identity for its DID.** The proof in
20
+ `signatures.publicKey` is a WebAuthn assertion, and its challenge was `SHA-256(credentialId ‖ data)`
21
+ — 32 bytes, a bare hash. The same passkey may sign for other protocols: since 0.8.0 it is meant to
22
+ be a wallet key, and `signP256Challenge` signs any 32 bytes it is given. So a signature over a value
23
+ somebody chose was, byte for byte, an identity proof for whatever that value hashed. An application
24
+ that let the passkey sign one attacker-supplied "hash" handed out a permanent binding of the
25
+ attacker's key to the victim's DID — proofs do not expire. Nothing this package ships signs chosen
26
+ values (`@le-space/passkey-wallet` signs keccak hashes only), which is why this is a hazard for
27
+ applications rather than a hole in them all. Found in an audit of 0.12.2.
28
+
29
+ A label inside the hash would not have helped, since whoever picks the 32 bytes can hash the label
30
+ in. The challenge itself is now
31
+ `"orbitdb-webauthn-did:v2:<context>:" ‖ SHA-256(len(credentialId) ‖ credentialId ‖ data)`: longer
32
+ than any hash and starting with text, so nothing that signs a 32-byte challenge can produce it, and
33
+ a proof cannot pass for a wallet signature either. The context keeps an identity binding
34
+ (`identity`) apart from what `WebAuthnDIDProvider.sign(data)` makes for an application (`data`): a
35
+ proof over text an application was handed is not an identity. The credential id, which the proof
36
+ names and the verifier cannot check, is length-prefixed. A proof in this format must also show the
37
+ user was verified, not merely present — `sign()` always asked for it, and nothing checked.
38
+
39
+ - **The first format still verifies unless the application refuses it**, because every identity made
40
+ before, and everything those identities wrote, is in it. While it does, the hole is open on the
41
+ verifying side — an attacker forges a first-format proof whatever format the victim uses.
42
+ `configureWebAuthn({ acceptLegacyProofs: false })` refuses it; a device with such a proof stored
43
+ then makes a new one (one passkey prompt, a new identity document, the same DID), and entries
44
+ written under the old document no longer verify on a peer that syncs them afresh. Unset, a
45
+ first-format proof is accepted with one console notice; `true` accepts without it. An application
46
+ with no history to keep should refuse from the start. See the README, "Identity proofs, and the
47
+ first format".
48
+
49
+ - **A vault from before a renewal was taken as readily as the renewal.** `renew` is the answer to a
50
+ stolen authenticator: a new vault key, a new vault, no slot for the key that went. The old record
51
+ still exists wherever it was copied to, still opens for the authenticators that stayed, and still
52
+ carries the stolen one's slot. A keeper took whatever `find` gave it and — once it kept a vault —
53
+ never asked again, so a device shown the old record sealed everything that followed under a vault
54
+ key the stolen authenticator knows, and a device that had adopted it stayed there for good. Found
55
+ in an audit of 0.12.2.
56
+
57
+ A renewed vault now carries a **generation**, one more than the vault it replaces, sealed into
58
+ every slot (vault format version 2). A slot is sealed under a key only its authenticator derives,
59
+ so each one that stays vouches for the number, and a removed authenticator — which knows the old
60
+ vault key and nothing more — cannot pass an old vault off as newer. The keeper asks `find` on every
61
+ unlock, takes one record or several, and of everything this authenticator's slot opens keeps the
62
+ latest: a renewal made elsewhere is picked up as soon as it is shown, and nothing older than the
63
+ vault kept here is ever taken. A record with this authenticator's slot that cannot be read — cut
64
+ short, altered, or of a later format — is refused (`VAULT_MALFORMED`) on a device with nothing
65
+ kept, as before, rather than passed over: a new vault made in its place would part the device from
66
+ the real one for good.
67
+
68
+ **What this cannot do:** a device with nothing kept, shown _only_ the old record, still opens it —
69
+ no record says it was replaced. Put the renewed record wherever `find` reads from at once, and
70
+ where the generation is known from something trusted, pass `open({ minGeneration })`: anything
71
+ earlier is refused (`VAULT_SUPERSEDED`), neither kept nor replaced by a new vault.
72
+
73
+ A vault made fresh is unchanged — version 1, generation 0, byte for byte what 0.12.x wrote and
74
+ reads. A _renewed_ vault is version 2, which 0.12.x refuses as malformed: update every device
75
+ before renewing.
76
+
77
+ ### Fixed
78
+
79
+ - **A cancel at the keystore step no longer makes the identity without it.** With
80
+ `encryptKeystore`, `createIdentity` caught every failure to create or unlock the encrypted
81
+ keystore, logged it and went on, and the two wrapped what they caught in an error of their own. So
82
+ a person who pressed Cancel on the step announced since 0.13.0 got an identity whose keystore key
83
+ is not sealed, or, with `useKeystoreDID`, the same prompt again and then a plain `Error`.
84
+ `PasskeyStepCancelled` now passes through all of them unchanged, as 0.13.0 promised.
85
+
86
+ ### Added
87
+
88
+ - `generationOf(vault)` and `createVault(payload, slot, { generation })` in the main entry,
89
+ `./standalone` and `./vault`; `open({ find, minGeneration })` on the vault keeper, where `find` may
90
+ return several records, and `generation` and `findError` on what it returns; the `VaultError` code
91
+ `VAULT_SUPERSEDED`.
92
+ - `configureWebAuthn({ acceptLegacyProofs })`; `sign(data, { context })` and
93
+ `verify(proof, data, publicKey, { context, acceptLegacyProofs })` on `WebAuthnDIDProvider`;
94
+ `PROOF_CONTEXTS` and `proofFormat(proof)` (`1`, `2` or `null`, by the challenge) in the main entry.
95
+
96
+ Tested in `tests/identity-proof-context.test.js`: the attack itself — a wallet signature over a
97
+ chosen 32 bytes verifies as an identity for the victim's DID in the first format, and no longer once
98
+ it is refused; the wallet signer refuses a current-format challenge; a proof made for an application
99
+ is not an identity; a touch without verification is not enough; and a device keeps a stored
100
+ first-format proof while it is accepted and replaces it once it is refused.
101
+
102
+ And in `tests/vault-generation.test.js`: the generation is sealed into slot and payload, and a
103
+ removed authenticator relabelling the old vault as newer gets a record that does not open; shown the
104
+ old and the renewed record in either order a device opens the renewed one; a device on the old vault
105
+ moves forward when shown the renewal, and one on the renewal is not moved back; `minGeneration`
106
+ refuses the old vault before it is kept; a record that cannot be read makes no vault of its own —
107
+ and, stated as a test, the limit above. The cancel at the keystore step is in
108
+ `tests/passkey-steps.test.js`, through `createIdentity` with and without `useKeystoreDID`.
109
+
3
110
  ## 0.13.0
4
111
 
5
112
  An application can now say, before each passkey prompt, what it is for — and `./elements` brings a
package/README.md CHANGED
@@ -127,6 +127,37 @@ says no, a webauthn identity is checked again the way an uncached one would be
127
127
  signature over the public key, and this provider's binding of the key to the DID. Other providers'
128
128
  identities, and anything that fails those checks, stay refused.
129
129
 
130
+ ### Identity proofs, and the first format
131
+
132
+ A passkey identity carries a proof that the passkey vouches for its signing key: a WebAuthn
133
+ assertion in `signatures.publicKey`. Until 0.14.0 that assertion's challenge was
134
+ `SHA-256(credentialId ‖ data)` — 32 bytes, a bare hash. The same passkey may sign for other
135
+ protocols, and a wallet signs any 32 bytes it is handed, so **one wallet signature over a value
136
+ somebody chose was a valid identity for the passkey's DID**, for good.
137
+
138
+ From 0.14.0 the challenge is labelled and longer than any hash —
139
+ `"orbitdb-webauthn-did:v2:identity:" ‖ SHA-256(…)` — which nothing that signs a 32-byte challenge
140
+ can produce. New identities get such a proof. Verification takes both formats by default, because
141
+ every identity made before, and everything those identities wrote, is in the first:
142
+
143
+ ```javascript
144
+ import { configureWebAuthn } from '@le-space/orbitdb-identity-provider-webauthn-did';
145
+
146
+ configureWebAuthn({ acceptLegacyProofs: false }); // refuse the first format
147
+ ```
148
+
149
+ - **Unset** (default): the first format verifies, with one console notice. The hole stays open on
150
+ this peer: an attacker forges a first-format proof whatever format the victim uses.
151
+ - **`false`**: the first format is refused, and a device that has such a proof stored makes a new
152
+ one — one passkey prompt, a new identity document, the same DID. Entries written under the old
153
+ document no longer verify on a peer that syncs them afresh. For an application without history
154
+ to keep, set this from the start.
155
+ - **`true`**: accepted knowingly, without the notice.
156
+
157
+ **Rolling out.** A peer on 0.12.x or earlier cannot verify the new format. Update every peer that
158
+ verifies identities — relays too — before any device creates a new identity proof on 0.14.0; devices
159
+ that already have one stored keep using it and are not affected.
160
+
130
161
  ### Discoverable Recovery Notes
131
162
 
132
163
  For the DID-based flow:
@@ -263,6 +294,7 @@ const { authenticatorData, clientDataJSON, challengeIndex, typeIndex, r, s } =
263
294
  - **Key.** `x` and `y` are 32-byte big-endian `Uint8Array`s, like `publicKey.x`/`y` on the default path; Calibur's `abi.encode(uint256 x, uint256 y)` is the two concatenated. They come from `publicKey` (`{ x, y }` or SEC1 bytes) or, failing that, from a P-256 `did:key`; where both are present they must agree. `rpId` is the one `createCredential` returns; a credential stored before it returned one falls back to `window.location.hostname`.
264
295
  - **`null`** for RS256 and Ed25519 keys, for the placeholder `createCredential` writes when it cannot read the public key (also once largeBlob metadata has dropped its `synthetic` flag: the point is not on the curve), and for anything unreadable.
265
296
  - **Signing.** Unlike other requests, this one pins `allowCredentials` to the descriptor, whatever `configureWebAuthn` says, and requires user verification. An assertion from another credential is refused. The challenge is used as the WebAuthn challenge itself, as Calibur passes its hash.
297
+ - **Only ever a protocol's own hash.** `signP256Challenge` signs whatever 32 bytes it is given, so give it a user operation hash or an ERC-7739 digest and never a value somebody else chose. Identity proofs made before 0.14.0 used a bare 32-byte hash as their challenge too, and one signature over a chosen value was an identity for the passkey's DID — see [Identity proofs](#identity-proofs-and-the-first-format).
266
298
  - **Result**: the fields of webauthn-sol's `WebAuthnAuth`. `r` and `s` are 32 bytes big-endian, `s` normalised to low-s (webauthn-sol refuses `s > n/2`). `clientDataJSON` is a string; `typeIndex` and `challengeIndex` are the UTF-8 byte offsets of `"type":"webauthn.get"` and `"challenge":"<base64url(challenge), unpadded>"` in it. The signature is verified against `x`/`y` before it is returned; anything a verifier would refuse throws instead.
267
299
 
268
300
  | Signing mode | Descriptor |
@@ -312,6 +344,64 @@ const opened = await keeper.open({
312
344
 
313
345
  Since **0.10.0**, a secret kept in that vault can be an identity of its own: `createSecretSigner(secret, { info })` turns it into an Ed25519 signer for the provider's `signer` option, so every key that opens the vault writes as the same identity — the root of a database's access controller, which a single passkey's identity would hold for good. See [docs/API.md](docs/API.md#an-identity-that-is-nobodys-passkey-createsecretsignersecret--info-).
314
346
 
347
+ ### Default path (passkey DID + derived signing key)
348
+
349
+ ```mermaid
350
+ sequenceDiagram
351
+ autonumber
352
+ participant User
353
+ participant App
354
+ participant WebAuthn
355
+ participant Auth as Authenticator
356
+ participant Prov as WebAuthn provider
357
+ participant KS as OrbitDB keystore
358
+ participant DB as OrbitDB
359
+
360
+ User->>App: Create credential
361
+ App->>WebAuthn: create() with PRF and largeBlob requested
362
+ WebAuthn->>Auth: Create passkey
363
+ Auth-->>WebAuthn: Attestation
364
+ WebAuthn-->>App: Credential
365
+
366
+ App->>Prov: createIdentity({ webauthnCredential })
367
+ Prov->>Prov: DID = did:key of the passkey's P-256 key
368
+ alt the keystore already holds a key for the DID
369
+ Note right of Prov: Nothing asked. That key stays.
370
+ else prfOutput handed over (one touch)
371
+ Prov->>KS: addKey(DID, key derived from prfOutput)
372
+ else the provider asks
373
+ Prov->>WebAuthn: get() with PRF
374
+ WebAuthn->>Auth: User verification
375
+ alt PRF output
376
+ Auth-->>Prov: PRF output
377
+ Prov->>KS: addKey(DID, HKDF(PRF output, DID) gives secp256k1 or Ed25519)
378
+ else no PRF
379
+ Auth-->>Prov: no PRF result
380
+ Note right of Prov: OrbitDB generates a random key. Stable on this device only.
381
+ end
382
+ end
383
+ alt identity signature stored (localStorage)
384
+ Prov->>Prov: reuse it
385
+ else first time on this device
386
+ Prov->>WebAuthn: get() over publicKey + idSignature
387
+ WebAuthn->>Auth: User verification
388
+ Auth-->>Prov: Assertion, becomes signatures.publicKey
389
+ end
390
+ Prov-->>App: Identity
391
+
392
+ User->>App: Add entry
393
+ App->>DB: db.put()
394
+ DB->>KS: sign entry with the derived key
395
+ KS-->>DB: Entry signature
396
+
397
+ Note over App,KS: No prompt per write. The derived key sits in OrbitDB's keystore unencrypted.
398
+ ```
399
+
400
+ An application that reads the PRF output for keys of its own hands it over as
401
+ `prfOutput` and saves the second touch. That path, a vault a second security
402
+ key opens, and an identity derived from a secret in the vault are drawn in
403
+ [docs/EXAMPLE-SEQUENCES.md](docs/EXAMPLE-SEQUENCES.md).
404
+
315
405
  ### Keystore-based DID (WebAuthn + OrbitDB keystore)
316
406
 
317
407
  ```mermaid
@@ -488,8 +578,8 @@ forgeries.
488
578
 
489
579
  The identity for each option is built by one module under
490
580
  `examples/shared/lib/options/`, which is also the shortest way to read the
491
- API; `docs/EXAMPLE-SEQUENCES.md` walks through the three sequences and their
492
- prompt counts.
581
+ API; `docs/EXAMPLE-SEQUENCES.md` walks through the three sequences, three
582
+ more an application builds around them, and their prompt counts.
493
583
 
494
584
  ### In other repositories
495
585
 
@@ -511,15 +601,27 @@ Three consumers that show the package doing a whole job rather than one call:
511
601
 
512
602
  ## Documentation
513
603
 
514
- - `docs/API.md`
515
- - `docs/ED25519-KEYSTORE-DID.md`
516
- - `docs/WEBAUTHN-ENCRYPTED-KEYSTORE-INTEGRATION.md`
517
- - `docs/WEBAUTHN-DID-AND-ORBITDB-IDENTITY.md`
518
- - `docs/STANDALONE-API-PLAN.md`
519
- - `docs/EXAMPLE-SEQUENCES.md`
520
- - `docs/E2E-TEST-SUMMARY.md`
521
- - `SECURITY.md`
522
- - `CODE_OF_CONDUCT.md`
604
+ - [`docs/API.md`](docs/API.md) — the reference: every export, its options
605
+ and defaults, and what it throws.
606
+ - [`docs/EXAMPLE-SEQUENCES.md`](docs/EXAMPLE-SEQUENCES.md) — one sequence
607
+ diagram per way of using the package, what a peer verifies for each, and
608
+ how many passkey prompts each costs.
609
+ - [`docs/WEBAUTHN-DID-AND-ORBITDB-IDENTITY.md`](docs/WEBAUTHN-DID-AND-ORBITDB-IDENTITY.md)
610
+ — which DID an identity has, which key signs its entries, how the DID
611
+ relates to the identity hash, and how peers check the binding.
612
+ - [`docs/ED25519-KEYSTORE-DID.md`](docs/ED25519-KEYSTORE-DID.md) — the
613
+ keystore DID (`useKeystoreDID`) in detail.
614
+ - [`docs/WEBAUTHN-ENCRYPTED-KEYSTORE-INTEGRATION.md`](docs/WEBAUTHN-ENCRYPTED-KEYSTORE-INTEGRATION.md)
615
+ — sealing the keystore DID's key with the passkey (`encryptKeystore`).
616
+ - [`docs/E2E-TEST-SUMMARY.md`](docs/E2E-TEST-SUMMARY.md) — the test
617
+ configurations, what CI runs, and what a new suite needs to run there.
618
+ - [`docs/STANDALONE-API-PLAN.md`](docs/STANDALONE-API-PLAN.md) — historical:
619
+ the plan the `./standalone` export started from (#13). Its export list is
620
+ out of date; the reference is
621
+ [docs/API.md](docs/API.md#standalone-export).
622
+ - [`SECURITY.md`](SECURITY.md) — supported versions and how to report a
623
+ vulnerability.
624
+ - [`CODE_OF_CONDUCT.md`](CODE_OF_CONDUCT.md)
523
625
 
524
626
  ## Cross-Project Verification
525
627
 
package/docs/API.md CHANGED
@@ -172,16 +172,46 @@ const identity = await identities.createIdentity({
172
172
  });
173
173
  ```
174
174
 
175
- Common options:
176
-
177
- - `webauthnCredential`
178
- - `encryptKeystore`
179
- - `keystoreEncryptionMethod`
180
- - `keyType`
181
- - `usePersistentKey`
175
+ Options, as `src/keystore/provider.js` reads them:
176
+
177
+ - `webauthnCredential` — the credential from `createCredential`, a stored
178
+ copy, or `restoreIdentityFromAuthenticator().credential`. Required unless
179
+ `signer` is given; without either the provider throws a `TypeError`.
180
+ - `signingKeyType` — `'secp256k1'` (default) or `'Ed25519'`: the type of the
181
+ signing key derived from the PRF output. Any other value throws. A key
182
+ already in the keystore for the DID is kept, whatever its type.
183
+ - `deriveSigningKeyFromPrf` — `true` by default: derive the signing key from
184
+ the passkey's PRF output, at the cost of one assertion the first time an
185
+ identity is created on a device. `false` leaves it to the keystore, which
186
+ generates a random secp256k1 key that stays on that device.
182
187
  - `prfOutput` — a PRF output already read with `readPrfOutput`, so the signing
183
188
  key costs no second touch; see
184
- [One touch for the data and the identity](#one-touch-for-the-data-and-the-identity)
189
+ [One touch for the data and the identity](#one-touch-for-the-data-and-the-identity).
190
+ A `Uint8Array` of at least 32 bytes, or the provider throws a `TypeError`.
191
+ Unused with `signer`, `useKeystoreDID` or `deriveSigningKeyFromPrf: false`,
192
+ and once the keystore holds a key for the DID.
193
+ - `useKeystoreDID` — `false` by default. `true` makes the DID the `did:key` of
194
+ a key in the keystore, which also signs the entries (the keystore DID). It
195
+ needs `keystore`: without one the provider returns the passkey DID.
196
+ - `keystore` — `null` by default. The OrbitDB keystore, the same one given to
197
+ `Identities()`. `useKeystoreDID` needs it; the default path uses the
198
+ keystore OrbitDB passes to `getId()` and falls back to this one.
199
+ - `keystoreKeyType` — `'secp256k1'` (default) or `'Ed25519'`: the type of the
200
+ keystore DID's key. Only with `useKeystoreDID`.
201
+ - `encryptKeystore` — `false` by default. Seals the keystore DID's key with the
202
+ passkey, so it takes effect only with `useKeystoreDID` and `keystore`.
203
+ `provider.encryptionState` says whether it was sealed.
204
+ - `keystoreEncryptionMethod` — `'prf'` (default), `'largeBlob'` or
205
+ `'hmac-secret'`.
206
+ - `signer` — `null` by default. A key that signs elsewhere,
207
+ `{ did, type: 'Ed25519', publicKey, sign(data) }`, from `createWorkerSigner`
208
+ or `createSecretSigner`. The identity is its DID, and nothing asks a
209
+ passkey. Give `Identities()` the keystore from
210
+ `createSessionKeystore({ signer })`: `getId()` throws when the keystore
211
+ has no key under the signer's DID.
212
+
213
+ `keyType` and `usePersistentKey`, listed here before, are not options: the
214
+ provider never read either.
185
215
 
186
216
  ### WebAuthn Configuration
187
217
 
@@ -430,6 +460,14 @@ What a vault does not do:
430
460
  what the old one protected.
431
461
  - **It cannot tell the current record from an earlier copy of itself.** Where a
432
462
  rollback matters, the place the record is stored has to say which is current.
463
+ What it can tell, since 0.14.0, is which of two records is the later
464
+ _renewal_: a vault that replaces another is version 2 and carries a
465
+ `generation`, sealed into every slot, so each authenticator that stays vouches
466
+ for it and a removed one — which knows the old vault key and nothing more —
467
+ cannot raise it. `generationOf(vault)` reads it (0 for a vault made fresh,
468
+ which stays version 1 and opens with earlier versions of this package; a
469
+ renewed vault does not). No record can say that a later one exists somewhere
470
+ it was not shown.
433
471
  - **It does not make two keys one person.** Each authenticator keeps its own DID
434
472
  and signing key; who may write to a database is its access controller's
435
473
  decision.
@@ -474,11 +512,28 @@ await keeper.addPasskey(opened, {
474
512
  a record kept elsewhere — a backup, an index — and keeps it here once it has
475
513
  opened; without that it makes a new vault holding `create()`, with this
476
514
  authenticator's slot. It returns `{ record, payload, vaultKey, kid, created,
477
- found }`; keep that in memory while the vault is open, it holds the vault key.
515
+ found, generation }`; keep that in memory while the vault is open, it holds the
516
+ vault key.
478
517
  - Pass `find` on every unlock where the vault may be kept elsewhere, not only
479
518
  on a restore path. A synced passkey on a new device otherwise makes a vault
480
519
  of its own, and from then on `open` finds that one here and never asks
481
520
  `find` again (Le-Space/belege#524).
521
+ - **After a renewal**, `find` is how the other devices learn of it. It is asked
522
+ on every unlock — also when a vault is kept here — and may return one record
523
+ or several. Of everything this authenticator's slot opens, the latest
524
+ generation wins: a vault renewed elsewhere replaces the one kept here as soon
525
+ as `find` shows it, and a copy from before a renewal is never taken in place
526
+ of a later one. With a vault kept here, a `find` that fails does not stop the
527
+ unlock; the error comes back as `findError`.
528
+ - **What that cannot do:** a device with nothing kept, shown only the vault from
529
+ before a renewal, opens that vault — and seals what follows under a key the
530
+ removed authenticator knows. So put the renewed record wherever `find` reads
531
+ from straight away, and keep that place from being written by whoever holds
532
+ the removed key. An application that knows the generation the vault has
533
+ reached, from something it trusts (a pointer the owner's identity signed, for
534
+ one), passes `minGeneration`: anything earlier is refused with
535
+ `VAULT_SUPERSEDED`, before it is kept here and without a new vault being made
536
+ instead.
482
537
  - An authenticator removed here is refused (`VAULT_SLOT_REMOVED`), never given
483
538
  a new vault: for an application whose books existed before the vault, that
484
539
  would be a stale copy that looks like the real books.
@@ -491,7 +546,9 @@ found }`; keep that in memory while the vault is open, it holds the vault key.
491
546
  vault id, with a slot for every authenticator that stays. Every one of them
492
547
  answers with its PRF output, checked against its slot, so none is left out
493
548
  by mistake; the ones in `removed` are taken out. A new `payload` replaces
494
- keys a removed authenticator must not know.
549
+ keys a removed authenticator must not know. The new vault is one generation
550
+ on from the old. It protects what is sealed from then on **on devices that
551
+ have it**: see `find` above for the ones that do not yet.
495
552
  - `replacePayload(opened, payload)`, `status(rawCredentialId)` (is there a
496
553
  vault here for this key, without asking it?) and `records()`.
497
554
 
@@ -511,8 +568,9 @@ it with `deriveSubkey(root, info)`, so the vault never changes when the
511
568
  application needs one more key. Belege's vaults hold exactly that.
512
569
 
513
570
  More refusals from the keeper, as `VaultError` codes: `VAULT_STORE_UNREADABLE`,
514
- `VAULT_SLOT_REMOVED`, and `VAULT_SLOT_IN_USE` — the authenticator that opened
515
- the vault cannot remove itself, or be left out of a renewal.
571
+ `VAULT_SLOT_REMOVED`, `VAULT_SLOT_IN_USE` — the authenticator that opened
572
+ the vault cannot remove itself, or be left out of a renewal — and
573
+ `VAULT_SUPERSEDED`, when nothing at hand reaches `minGeneration`.
516
574
 
517
575
  #### An identity that is nobody's passkey: `createSecretSigner(secret, { info })`
518
576
 
@@ -775,6 +833,10 @@ with webauthn-sol). See the README section "Passkeys for smart accounts".
775
833
  ### Worker Keystore Client
776
834
 
777
835
  - `createWorkerKeystoreClient(options?)`
836
+ - `createWorkerSigner(client, { did, publicKey })` — the result of
837
+ `client.deriveSigner(prfSeed)` as a signer for
838
+ `createSessionKeystore({ signer })` and the provider's `signer` option;
839
+ `sign` runs in the worker
778
840
  - `isWorkerKeystoreAvailable()`
779
841
  - `createEd25519DidFromPublicKey(publicKeyBytes)`
780
842
  - `getDefaultWorkerKeystoreClient(options?)`
package/package.json CHANGED
@@ -1,10 +1,14 @@
1
1
  {
2
2
  "name": "@le-space/orbitdb-identity-provider-webauthn-did",
3
- "version": "0.13.0",
3
+ "version": "0.14.0",
4
4
  "description": "WebAuthn-based DID identity provider for OrbitDB for hardware-secured wallets and biometric Passkey authentication",
5
5
  "main": "src/index.js",
6
6
  "types": "types/index.d.ts",
7
7
  "type": "module",
8
+ "sideEffects": [
9
+ "./src/elements/index.js",
10
+ "./src/standalone/worker/ed25519-keystore.worker.js"
11
+ ],
8
12
  "exports": {
9
13
  ".": {
10
14
  "types": "./types/index.d.ts",
@@ -61,7 +65,7 @@
61
65
  "postversion": "git push && git push --tags",
62
66
  "test:two-peer": "playwright test tests/webauthn-two-peer-replication.test.js --project=chromium --reporter=line",
63
67
  "test:node": "playwright test --config=playwright.node.config.js",
64
- "test:wallet-fork": "PASSKEY_WALLET_FORK_URL=${PASSKEY_WALLET_FORK_URL:-https://sepolia.drpc.org} playwright test --config=playwright.fork.config.js"
68
+ "test:wallet-fork": "node -e \"process.env.PASSKEY_WALLET_FORK_URL || (console.error('test:wallet-fork needs PASSKEY_WALLET_FORK_URL, a Sepolia RPC URL, e.g. https://eth-sepolia.g.alchemy.com/v2/<key>'), process.exit(1))\" && playwright test --config=playwright.fork.config.js"
65
69
  },
66
70
  "keywords": [
67
71
  "orbitdb",
@@ -7,6 +7,7 @@
7
7
  */
8
8
  import { setPasskeyStepHandler } from '../passkey-steps.js';
9
9
  import {
10
+ CONTINUE_DELAY_MS,
10
11
  PasskeyStepDialogElement,
11
12
  PASSKEY_STEP_STRINGS,
12
13
  } from './passkey-step-dialog.js';
@@ -31,7 +32,7 @@ export function connectPasskeyStepDialog(element) {
31
32
  return setPasskeyStepHandler((step) => element.ask(step));
32
33
  }
33
34
 
34
- export { PasskeyStepDialogElement, PASSKEY_STEP_STRINGS };
35
+ export { CONTINUE_DELAY_MS, PasskeyStepDialogElement, PASSKEY_STEP_STRINGS };
35
36
  export {
36
37
  setPasskeyStepHandler,
37
38
  withPasskeySteps,
@@ -194,11 +194,29 @@ const fill = (template, values) =>
194
194
  key in values ? String(values[key]) : whole
195
195
  );
196
196
 
197
- export class PasskeyStepDialogElement extends HTMLElement {
197
+ /**
198
+ * Where there is no DOM — a server-side render importing ./elements — the
199
+ * class is still defined, on a stand-in, so that the import does not throw.
200
+ * It is only registered where there is a customElements registry.
201
+ */
202
+ const Base = /** @type {typeof HTMLElement} */ (
203
+ globalThis.HTMLElement ?? class {}
204
+ );
205
+
206
+ /**
207
+ * How long "Continue" ignores clicks and key presses after a step appears,
208
+ * in milliseconds: the second click of a double click, or a held Enter,
209
+ * meant for the step before, must not approve this one unread.
210
+ */
211
+ export const CONTINUE_DELAY_MS = 400;
212
+
213
+ export class PasskeyStepDialogElement extends Base {
198
214
  /** @type {Partial<Record<string, Partial<PasskeyStepStrings>>>} */
199
215
  #overrides = {};
200
216
  /** @type {{ resolve: () => void, reject: (error: Error) => void } | null} */
201
217
  #pending = null;
218
+ /** When the step on screen appeared (`performance.now()`). */
219
+ #shownAt = 0;
202
220
 
203
221
  constructor() {
204
222
  super();
@@ -217,9 +235,10 @@ export class PasskeyStepDialogElement extends HTMLElement {
217
235
  this.dialog = /** @type {HTMLDialogElement} */ (
218
236
  root.querySelector('dialog')
219
237
  );
220
- root
221
- .querySelector('[part=continue]')
222
- .addEventListener('click', () => this.#settle(null));
238
+ root.querySelector('[part=continue]').addEventListener('click', () => {
239
+ if (performance.now() - this.#shownAt < CONTINUE_DELAY_MS) return;
240
+ this.#settle(null);
241
+ });
223
242
  root
224
243
  .querySelector('[part=cancel]')
225
244
  .addEventListener('click', () =>
@@ -230,6 +249,12 @@ export class PasskeyStepDialogElement extends HTMLElement {
230
249
  event.preventDefault();
231
250
  this.#settle(new PasskeyStepCancelled());
232
251
  });
252
+ // Closed some other way — `dialog.close()` from the page, say — the step
253
+ // is not answered "Continue". A close that a new step has already
254
+ // reopened (`#settle` closes, `ask` opens again) is not one.
255
+ this.dialog.addEventListener('close', () => {
256
+ if (!this.dialog.open) this.#settle(new PasskeyStepCancelled());
257
+ });
233
258
  }
234
259
 
235
260
  /**
@@ -301,8 +326,17 @@ export class PasskeyStepDialogElement extends HTMLElement {
301
326
  this.setAttribute('data-purpose', step.purpose);
302
327
 
303
328
  return new Promise((resolve, reject) => {
329
+ try {
330
+ if (!this.dialog.open) this.dialog.showModal();
331
+ } catch (error) {
332
+ // Not on the page, for one: nothing is waiting, and nothing is left
333
+ // marked as if it were.
334
+ this.removeAttribute('data-purpose');
335
+ reject(error);
336
+ return;
337
+ }
304
338
  this.#pending = { resolve, reject };
305
- if (!this.dialog.open) this.dialog.showModal();
339
+ this.#shownAt = performance.now();
306
340
  /** @type {HTMLElement} */ (
307
341
  root.querySelector('[part=continue]')
308
342
  ).focus();
package/src/errors.js CHANGED
@@ -14,6 +14,7 @@ export const ERROR_CODES = Object.freeze({
14
14
  VAULT_STORE_UNREADABLE: 'VAULT_STORE_UNREADABLE',
15
15
  VAULT_SLOT_REMOVED: 'VAULT_SLOT_REMOVED',
16
16
  VAULT_SLOT_IN_USE: 'VAULT_SLOT_IN_USE',
17
+ VAULT_SUPERSEDED: 'VAULT_SUPERSEDED',
17
18
  });
18
19
 
19
20
  export class WebAuthnIdentityError extends Error {
@@ -101,8 +102,10 @@ export class PrfUnavailableError extends KeystoreEncryptionError {
101
102
  * (`VAULT_SLOT_EXISTS`), or the slot is the last one (`VAULT_LAST_SLOT`).
102
103
  * From the vault keeper also: the vaults kept in a store cannot be read
103
104
  * (`VAULT_STORE_UNREADABLE`), the authenticator was removed from the vault
104
- * kept there (`VAULT_SLOT_REMOVED`), or it is the one that opened the vault
105
- * and so cannot remove itself (`VAULT_SLOT_IN_USE`).
105
+ * kept there (`VAULT_SLOT_REMOVED`), it is the one that opened the vault
106
+ * and so cannot remove itself (`VAULT_SLOT_IN_USE`), or the only vault at
107
+ * hand is from before a renewal the application knows of
108
+ * (`VAULT_SUPERSEDED`).
106
109
  */
107
110
  export class VaultError extends KeystoreEncryptionError {
108
111
  constructor(message, options = {}) {
package/src/index.js CHANGED
@@ -66,6 +66,10 @@ import {
66
66
  isUnsupportedVarsigEnvelopeError,
67
67
  } from './varsig/index.js';
68
68
 
69
+ // What a proof is about, and which format one is in — for an application
70
+ // deciding when it can stop accepting the first format.
71
+ export { PROOF_CONTEXTS, proofFormat } from './webauthn/proof-verification.js';
72
+
69
73
  export {
70
74
  WebAuthnDIDProvider,
71
75
  OrbitDBWebAuthnIdentityProvider,
@@ -344,6 +348,7 @@ export {
344
348
  removeSlot,
345
349
  replacePayload,
346
350
  slotIdFor,
351
+ generationOf,
347
352
  } from './keystore/vault.js';
348
353
  // Where the vaults are kept, and what every unlock does with them.
349
354
  export {