Repository navigation
feat(web): add attested Selfie Check embedding enrollment #604
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
Open
Takaros999
wants to merge
14
commits into
main
Choose a base branch
from
takis/selfie-enrollment-client
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 11 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
839ac7e
feat(web): expose attested Selfie Check embedding extraction
Takaros999 efbbc35
fix(web): bound and cancel enrollment admission response streams
Takaros999 8be2b3b
style(web): format admission stream regression tests
Takaros999 d324338
test(web): accept bounded tickets before strict enclave verification
Takaros999 f2aebc6
fix(web): keep admission stream future worker-local
Takaros999 5f35140
ci(web): retain manual build packages for live validation
Takaros999 4a6485c
fix(web): align enrollment client with stateless assignments
Takaros999 61547ee
chore: preserve unrelated dependency lock resolution
Takaros999 ccbce93
chore(web): track enrollment Flamingo release update
Takaros999 de4aa33
refactor(web): simplify enrollment to a verified session
Takaros999 9a1bbbf
refactor(web): expose Face PCP enrollment embeddings
Takaros999 e3a5c15
style(web): format enrollment policy fixture
Takaros999 910578d
chore(web): pin final enrollment source revision
Takaros999 22d32f1
test(web): verify enrollment success across worker messages
Takaros999 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
Some comments aren't visible on the classic Files Changed page.
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,82 @@ | ||
| //! Embedding enrollment over the dedicated browser-compatible TEE channel. | ||
| use js_sys::Promise; | ||
| use selfie_enrollment_client::{Config, Error}; | ||
| use selfie_enrollment_sealed_types::{EmbeddingResult, Failure}; | ||
| use wasm_bindgen::prelude::*; | ||
| use zeroize::Zeroizing; | ||
|
|
||
| use crate::{error::to_js, js}; | ||
|
|
||
| #[wasm_bindgen(typescript_custom_section)] | ||
| const TS_TYPES: &str = r#" | ||
| export type SelfieEmbeddingResult = | ||
| | { status: "success"; embedding: FaceEmbedding } | ||
| | { status: "failed"; reason: "invalid_image" | "quality_rejected" | "extraction_failed" | "invalid_request" }; | ||
|
|
||
| export interface FaceEmbedding { | ||
| embedding: string; | ||
| embeddingType: string; | ||
| embeddingVersion: string; | ||
| embeddingInferenceBackend: string; | ||
| } | ||
| "#; | ||
|
|
||
| /// Extracts an embedding after verifying Nitro measurements. | ||
| /// | ||
| /// `configJson` is the trusted release policy from the enrollment deployment. | ||
| /// The image is sealed inside this worker before upload and is never persisted. | ||
| /// | ||
| /// Calls have a bounded deadline. Terminate the `WalletKit` instance to cancel an | ||
| /// in-flight enrollment immediately. This operation does not issue a credential. | ||
| /// | ||
| /// # Errors | ||
| /// Throws a `SelfieEnrollmentError` for invalid policy, rejected attestation, or | ||
| /// transport failures. Image/quality rejections return a typed failed result. | ||
| #[wasm_bindgen(js_name = extractSelfieEmbedding, unchecked_return_type = "Promise<SelfieEmbeddingResult>")] | ||
| pub fn extract_selfie_embedding(config_json: String, image: Vec<u8>) -> Promise { | ||
|
|
||
| let mut image = Zeroizing::new(image); | ||
| js::promise(async move { | ||
| let config: Config = | ||
| serde_json::from_str(&config_json).map_err(|_| to_js(Error::Config))?; | ||
| let result = selfie_enrollment_client::browser::extract( | ||
| config, | ||
| std::mem::take(&mut *image), | ||
| None, | ||
| ) | ||
| .await | ||
| .map_err(to_js)?; | ||
| result_to_js(&result) | ||
| }) | ||
| } | ||
|
|
||
| fn result_to_js(result: &EmbeddingResult) -> Result<JsValue, JsValue> { | ||
| match result { | ||
| EmbeddingResult::Success { embedding } => js::object(&[ | ||
| ("status", "success".into()), | ||
| ( | ||
| "embedding", | ||
| js::object(&[ | ||
|
Copilot marked this conversation as resolved.
|
||
| ("embedding", embedding.embedding.as_str().into()), | ||
| ("embeddingType", embedding.embedding_type.as_str().into()), | ||
| ( | ||
| "embeddingVersion", | ||
| embedding.embedding_version.as_str().into(), | ||
| ), | ||
| ( | ||
| "embeddingInferenceBackend", | ||
| embedding.embedding_inference_backend.as_str().into(), | ||
| ), | ||
| ])?, | ||
| ), | ||
| ]), | ||
| EmbeddingResult::Failed { reason } => { | ||
| let reason = match reason { | ||
| Failure::InvalidImage => "invalid_image", | ||
| Failure::QualityRejected => "quality_rejected", | ||
| Failure::ExtractionFailed => "extraction_failed", | ||
| Failure::InvalidRequest => "invalid_request", | ||
| }; | ||
| js::object(&[("status", "failed".into()), ("reason", reason.into())]) | ||
| } | ||
| } | ||
| } | ||
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
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
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,68 @@ | ||
| import init, { | ||
| extractSelfieEmbedding, | ||
| sanitizeHexSecrets, | ||
| } from "../../src/generated/walletkit.js"; | ||
|
|
||
| self.onmessage = async ({ data }) => { | ||
| try { | ||
| await init({ module_or_path: new URL(data.wasmUrl) }); | ||
| const sent: string[] = []; | ||
| let closed = false; | ||
| Object.assign(self, { | ||
| WebSocket: class { | ||
| static OPEN = 1; | ||
| readyState = 1; | ||
| bufferedAmount = 0; | ||
| onopen?: (event: Event) => void; | ||
| onmessage?: (event: MessageEvent) => void; | ||
| constructor() { | ||
| setTimeout(() => this.onopen?.(new Event("open")), 0); | ||
| } | ||
| send(value: unknown) { | ||
| sent.push( | ||
| typeof value === "string" ? JSON.parse(value).type : "image", | ||
| ); | ||
| setTimeout( | ||
| () => | ||
| this.onmessage?.( | ||
| new MessageEvent("message", { | ||
| data: JSON.stringify({ | ||
| type: "assignment", | ||
| attestation: "AQ==", | ||
| public_key: "Ag==", | ||
| }), | ||
| }), | ||
| ), | ||
| 0, | ||
| ); | ||
| } | ||
| close() { | ||
| this.readyState = 3; | ||
| closed = true; | ||
| } | ||
| }, | ||
| }); | ||
| const config = { | ||
| endpoint: "wss://enrollment.invalid/v1/embeddings", | ||
| releases: [ | ||
| { | ||
| pcr0: "1".repeat(96), | ||
| pcr1: "2".repeat(96), | ||
| pcr2: "3".repeat(96), | ||
|
|
||
| }, | ||
| ], | ||
| }; | ||
| let code; | ||
| try { | ||
| await extractSelfieEmbedding(JSON.stringify(config), new Uint8Array([1])); | ||
| } catch (error) { | ||
| code = (error as Error & { code?: string }).code; | ||
| } | ||
| self.postMessage({ | ||
| result: { code, sent, closed, alive: sanitizeHexSecrets("alive") }, | ||
| }); | ||
| } catch (error) { | ||
| self.postMessage({ error: String(error) }); | ||
| } | ||
| }; |
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
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.