Repository navigation
Test that a notepad started over in NOTE never costs a file #4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,94 @@ | ||
| import { localRuntime } from "@flow-industries/seal/internal/app/local-runtime"; | ||
| import { | ||
| type CheckpointPolicy, | ||
| savedCheckpoint, | ||
| signedState, | ||
| type UnlockPort, | ||
| } from "@flow-industries/seal/internal/app/unlock"; | ||
| import { passkeyAdmin } from "@flow-industries/seal/internal/crypto/access-v3"; | ||
| import { AuthVaultTransport } from "@flow-industries/seal/internal/sync/vault-transport"; | ||
| import { | ||
| type AdminBrowser, | ||
| type FakeFlowId, | ||
| TEST_DID, | ||
| } from "@flow-industries/seal/internal/testing/kit"; | ||
|
|
||
| const did = TEST_DID; | ||
|
|
||
| /** | ||
| * NOTE starting a new notepad over the current one, as a passkey the notepad | ||
| * doesn't list does: a brand-new vault (new id, new key, epoch 1, a signed | ||
| * `create` listing only that passkey) published over the existing record, | ||
| * compare-and-swap against the record it read. Every linked device loses | ||
| * its notepad at once. Built like seal's own test `adminBrowser`, whose | ||
| * vault can only be the first one, and returned in its shape, so the | ||
| * kit's `approveLink` and `openAdminVault` work on the new notepad. | ||
| */ | ||
| export async function startOver(note: FakeFlowId): Promise<AdminBrowser> { | ||
| const replaced = note.record(); | ||
| if (!replaced) throw new Error("No notepad to start over"); | ||
| const key = crypto.getRandomValues(new Uint8Array(32)); | ||
| const prf = crypto.getRandomValues(new Uint8Array(32)); | ||
| const admin = await passkeyAdmin(prf, "recreated", did); | ||
| const state = await signedState( | ||
| key, | ||
| { did, vault: crypto.randomUUID(), epoch: 1 }, | ||
| { | ||
| kind: "create", | ||
| sequence: 1, | ||
| recipients: [admin.recipient], | ||
| signer: admin, | ||
| }, | ||
| "created", | ||
| ); | ||
| const created = new AuthVaultTransport(note.browserRpc, { | ||
| key, | ||
| did, | ||
| ...state, | ||
| }); | ||
| try { | ||
| await created.writeSnapshot([], replaced.cid); | ||
| } finally { | ||
| created.stop(); | ||
| } | ||
| let checkpoint: CheckpointPolicy | null = savedCheckpoint(state); | ||
| const port: UnlockPort = { | ||
| current: () => ({ | ||
| userId: "owner", | ||
| did, | ||
| credentialId: "recreated", | ||
| sessionVersion: 1, | ||
| }), | ||
| checkpoint: async () => checkpoint, | ||
| saveCheckpoint: async (value) => { | ||
| checkpoint = value; | ||
| }, | ||
| resolve: async () => ({ did, active: true, authorized: true }), | ||
| readHeader: async () => { | ||
| const current = note.record(); | ||
| return current ? { header: current.value, cid: current.cid } : null; | ||
| }, | ||
| publish: async (publishedKey, published, expectedCid) => { | ||
| const reader = new AuthVaultTransport(note.browserRpc, { | ||
| key: publishedKey, | ||
| did, | ||
| ...published, | ||
| pinned: null, | ||
| }); | ||
| const previous = await reader.readSnapshot(); | ||
| reader.stop(); | ||
| if (previous?.cid !== expectedCid) | ||
| throw new Error("Vault changed during publish"); | ||
| const writer = new AuthVaultTransport(note.browserRpc, { | ||
| key: publishedKey, | ||
| did, | ||
| ...published, | ||
| }); | ||
| await writer.writeSnapshot(previous.entries, expectedCid); | ||
| writer.stop(); | ||
| }, | ||
| evaluatePrf: async () => prf.slice(), | ||
| runtime: (session) => localRuntime(session), | ||
| }; | ||
| return { note, key, port, state, admin }; | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In every
apply-based start-over scenario,startOver(note)replaces the record beforedropBlobs()examinesnote.record(). Because the replacement is an empty notepad, the old attachment CIDs are no longer available to add togone, so these cases do not simulate the specified replacement-then-blob-deletion sequence and could miss a device attempting to download an old attachment during that window. Capture the old record's blob refs before replacement, then mark those refs unavailable afterward.Useful? React with 👍 / 👎.