Skip to content

Commit ac10508

Browse files
committed
recommendos
1 parent 206d829 commit ac10508

File tree

2 files changed

+147
-59
lines changed

2 files changed

+147
-59
lines changed

packages/mobile-sdk-alpha/MIGRATION_CHECKLIST.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222

2323
- Fetch protocol trees with pagination and a TTL cache.
2424
- Verify computed roots against server data.
25+
- Implement rate limiting with exponential backoff and jitter.
26+
- Set memory bounds for concatenated trees and honor Retry-After headers.
2527

2628
## 5. Proof input generation
2729

@@ -40,11 +42,17 @@
4042

4143
- Runtime-selectable adapter using WebCrypto with `@noble/*` fallbacks.
4244
- Parity tests across implementations.
45+
- Detect WebCrypto availability on React Native/Hermes environments.
46+
- Ensure CSPRNG-backed random number generation.
47+
- Use timing-safe comparison for secret values.
4348

4449
## 9. Artifact management
4550

4651
- Manifest schema & integrity verification.
4752
- CDN downloads with caching and storage adapter.
53+
- Verify manifest signature with pinned public key before caching.
54+
- Enforce CDN allowlist and Content-Length checks.
55+
- Stream hashing to avoid buffering large files.
4856

4957
## 10. Sample applications
5058

packages/mobile-sdk-alpha/MIGRATION_PROMPTS.md

Lines changed: 139 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -2,209 +2,289 @@
22

33
Each chapter from the migration checklist includes granular tasks below. Pick tasks independently to parallelize work.
44

5+
> **Note**: This document uses standard Markdown `<details>` and `<summary>` tags for collapsible task sections, ensuring proper rendering on GitHub and other Markdown viewers.
6+
57
## 1. Scanning adapters & NFC lifecycle
68

7-
:::task-stub{title="Create scanning adapter interface"}
9+
<details>
10+
<summary><strong>Create scanning adapter interface</strong></summary>
811

912
1. In `src/adapters/`, add `scanner.ts` exporting TypeScript interfaces for `MRZScanner` and `NFCScanner`.
1013
2. Reference React Native camera/NFC packages only through these interfaces.
11-
3. Document usage in `README.md`.
12-
:::
14+
3. Document usage in `README.md`. Include a "Privacy & PII" subsection: forbid logging MRZ/NFC data, enable on-device processing only, and provide redaction utilities for debug.
15+
4. Never log MRZ strings, NFC APDUs, or chip contents anywhere (including telemetry).
16+
5. Ensure camera frames and NFC/APDU processing occur on-device with analytics disabled for those paths by default.
17+
6. Provide a redact/sanitize helper function for debug builds only.
18+
19+
</details>
1320

14-
:::task-stub{title="Implement React Native MRZ adapter"}
21+
<details>
22+
<summary><strong>Implement React Native MRZ adapter</strong></summary>
1523

1624
1. Add `mrz-rn.ts` in `src/adapters/` implementing `MRZScanner` via `react-native-vision-camera`.
1725
2. Expose configuration for permissions, preview, and result handling.
1826
3. Write unit tests under `tests/` mocking camera output.
19-
:::
2027

21-
:::task-stub{title="Implement React Native NFC adapter"}
28+
</details>
29+
30+
<details>
31+
<summary><strong>Implement React Native NFC adapter</strong></summary>
2232

2333
1. Create `nfc-rn.ts` in `src/adapters/` implementing `NFCScanner` with `react-native-nfc-manager`.
2434
2. Provide lifecycle hooks so the app can call `keepScreenOn(true|false)` during sessions.
2535
3. Document app-level setup in `MIGRATION_CHECKLIST.md`.
26-
:::
2736

28-
:::task-stub{title="Add scanning sample"}
37+
</details>
38+
39+
<details>
40+
<summary><strong>Add scanning sample</strong></summary>
2941

3042
1. Under `samples/`, add a React Native demo showing MRZ then NFC scanning.
3143
2. Include simple error handling and log output.
3244
3. Reference the sample from `README.md`.
33-
:::
45+
46+
</details>
3447

3548
## 2. Processing helpers (MRZ & NFC)
3649

37-
:::task-stub{title="Test MRZ parsing utilities"}
50+
<details>
51+
<summary><strong>Test MRZ parsing utilities</strong></summary>
3852

3953
1. In `tests/processing/`, add test cases for `extractMRZInfo` and `formatDateToYYMMDD` covering valid/invalid inputs.
4054
2. Use sample MRZ strings from ICAO specs for fixtures.
41-
:::
4255

43-
:::task-stub{title="Add NFC response parser"}
56+
</details>
57+
58+
<details>
59+
<summary><strong>Add NFC response parser</strong></summary>
4460

4561
1. Create `src/processing/nfc.ts` exporting a pure function to parse NFC chip responses into DG1/DG2 structures.
4662
2. Write tests in `tests/processing/nfc.test.ts`.
4763
3. Ensure no React Native dependencies.
48-
:::
4964

50-
:::task-stub{title="Expose processing utilities"}
65+
</details>
66+
67+
<details>
68+
<summary><strong>Expose processing utilities</strong></summary>
5169

5270
1. Update `src/index.ts` to re-export MRZ and NFC helpers.
53-
2. Document them in `README.md` under a “Processing utilities” section.
54-
:::
71+
2. Document them in `README.md` under a "Processing utilities" section.
72+
73+
</details>
5574

5675
## 3. Validation module
5776

58-
:::task-stub{title="Port minimal document validation"}
77+
<details>
78+
<summary><strong>Port minimal document validation</strong></summary>
5979

6080
1. Create `src/validation/document.ts`.
6181
2. Port `isPassportDataValid` logic without analytics or store calls.
6282
3. Type the function using `PassportData` from `src/types/public.ts`.
63-
:::
6483

65-
:::task-stub{title="Test document validation"}
84+
</details>
85+
86+
<details>
87+
<summary><strong>Test document validation</strong></summary>
6688

6789
1. Add `tests/validation/document.test.ts` with cases for missing metadata and hash mismatches.
6890
2. Run via `yarn workspace @selfxyz/mobile-sdk-alpha test`.
69-
:::
91+
92+
</details>
7093

7194
## 4. Protocol synchronization
7295

73-
:::task-stub{title="Add paginated tree fetch"}
96+
<details>
97+
<summary><strong>Add paginated tree fetch</strong></summary>
7498

7599
1. Under `src/client/`, create `treeFetcher.ts` with `fetchTreePaginated(url, pageSize)` returning concatenated pages.
76100
2. Handle pagination tokens from the backend.
77101
3. Include retries for transient network errors.
78-
:::
79102

80-
:::task-stub{title="Introduce tree cache with TTL"}
103+
</details>
104+
105+
<details>
106+
<summary><strong>Introduce tree cache with TTL</strong></summary>
81107

82108
1. In `treeFetcher.ts`, wrap results with an in-memory cache keyed by URL and `pageSize`.
83109
2. Allow TTL configuration through SDK options.
84110
3. Expose `clearExpired()` to purge stale entries.
85-
:::
86111

87-
:::task-stub{title="Implement root verification"}
112+
</details>
113+
114+
<details>
115+
<summary><strong>Implement root verification</strong></summary>
88116

89117
1. After assembling the full tree, compute its root and compare to the server-provided root.
90118
2. Throw descriptive errors on mismatch.
91119
3. Add tests with mock data ensuring verification triggers.
92-
:::
120+
121+
</details>
93122

94123
## 5. Proof input generation
95124

96-
:::task-stub{title="Port generateTEEInputsRegister"}
125+
<details>
126+
<summary><strong>Port generateTEEInputsRegister</strong></summary>
97127

98128
1. Copy logic from `app/src/utils/proving/provingInputs.ts` lines 106-117 into `src/proving/registerInputs.ts`.
99129
2. Replace `useProtocolStore` calls with parameters for `dscTree` and environment.
100130
3. Ensure types align with `PassportData`.
101-
:::
102131

103-
:::task-stub{title="Port generateTEEInputsDisclose"}
132+
</details>
133+
134+
<details>
135+
<summary><strong>Port generateTEEInputsDisclose</strong></summary>
104136

105137
1. Move disclosure-related logic into `src/proving/discloseInputs.ts`.
106138
2. Accept OFAC trees and other dependencies as function parameters instead of store lookups.
107139
3. Write unit tests for both register and disclose generators with mocked trees.
108-
:::
140+
141+
</details>
109142

110143
## 6. TEE session management
111144

112-
:::task-stub{title="Implement TEE WebSocket wrapper"}
145+
<details>
146+
<summary><strong>Implement TEE WebSocket wrapper</strong></summary>
113147

114148
1. Add `src/tee/session.ts` exporting `openSession(url, options)`.
115149
2. Accept an `AbortSignal` and timeout; reject if aborted or timed out.
116150
3. Emit progress events via an `EventEmitter` interface.
117-
:::
118151

119-
:::task-stub{title="Test and document TEE session"}
152+
</details>
153+
154+
<details>
155+
<summary><strong>Test and document TEE session</strong></summary>
120156

121157
1. Write tests using a mocked WebSocket server verifying abort/timeout handling.
122158
2. Update `README.md` with example code showing progress listener usage.
123-
:::
159+
160+
</details>
124161

125162
## 7. Attestation verification
126163

127-
:::task-stub{title="Port basic attestation verification"}
164+
<details>
165+
<summary><strong>Port basic attestation verification</strong></summary>
128166

129167
1. In `src/attestation/verify.ts`, port `checkPCR0Mapping` and `getPublicKey` without logging.
130168
2. Replace on-chain contract calls with parameters or pluggable providers.
131169
3. Provide TypeScript types for attestation documents.
132-
:::
170+
4. Validate attestation timestamps against device clock with configurable skew tolerance.
171+
5. Define trust anchors and key pinning strategy for PCR0/public key mapping.
172+
6. Add optional OCSP/CRL checks with network fallbacks and clear opt-out rationale.
173+
174+
</details>
133175

134-
:::task-stub{title="Implement certificate chain check"}
176+
<details>
177+
<summary><strong>Implement certificate chain check</strong></summary>
135178

136179
1. Port simplified `verifyCertChain` from `attest.ts` ensuring no Node-specific APIs.
137180
2. Add unit tests with mock certificates to cover success and failure paths.
138-
:::
181+
182+
</details>
139183

140184
## 8. Crypto adapters
141185

142-
:::task-stub{title="Create CryptoAdapter"}
186+
<details>
187+
<summary><strong>Create CryptoAdapter</strong></summary>
143188

144189
1. In `src/crypto/`, add `adapter.ts` defining methods for hashing, random bytes, and asymmetric operations.
145190
2. Document required methods (e.g., `digest`, `getRandomValues`, `subtle` operations).
146-
:::
191+
3. Add a constant-time `timingSafeEqual(a, b)` utility and document RNG requirements (cryptographically secure only).
192+
4. Implement environment detection for WebCrypto (detect globalThis.crypto and feature-check subtle/digest/getRandomValues).
193+
5. Provide fallback to react-native-get-random-values or noble-based adapter when WebCrypto unavailable.
194+
6. Ensure all secret comparisons use constant-time comparison instead of ===.
195+
196+
</details>
147197

148-
:::task-stub{title="Implement crypto adapters"}
198+
<details>
199+
<summary><strong>Implement crypto adapters</strong></summary>
149200

150201
1. Add `webcrypto.ts` implementing the interface using `globalThis.crypto`.
151202
2. Add `noble.ts` using `@noble/hashes` and `@noble/curves` where WebCrypto is unavailable.
152203
3. Export a factory that chooses the appropriate adapter at runtime.
153204
4. Provide tests ensuring both adapters yield identical results for sample inputs.
154-
:::
205+
5. In noble adapter: select well-known safe curves (secp256r1/ed25519) and recommended hash algorithms.
206+
6. Ensure sensitive buffers are zeroized after use where possible.
207+
7. Add tests for constant-time comparator and RNG fallback behavior.
208+
209+
</details>
155210

156211
## 9. Artifact management
157212

158-
:::task-stub{title="Add artifact manifest schema"}
213+
<details>
214+
<summary><strong>Add artifact manifest schema</strong></summary>
159215

160216
1. In `src/artifacts/`, create `manifest.ts` defining the JSON schema (name, version, urls, hashes).
161-
2. Implement a function `verifyManifest(manifest, signature)` that validates hashes and schema.
162-
:::
217+
2. Implement `verifyManifest(manifest, signature, publisherKey)` that validates schema and signature using a pinned publisher key. Only then validate per-file hashes.
218+
3. Verify manifest signature against pinned public key before any caching or storage access.
219+
4. Enforce CDN/domain allowlist and validate response Content-Length header against expected sizes.
220+
5. Compute and verify streaming hash while downloading to avoid buffering full files in memory.
163221

164-
:::task-stub{title="Download and cache artifacts"}
222+
</details>
223+
224+
<details>
225+
<summary><strong>Download and cache artifacts</strong></summary>
165226

166227
1. Create `downloader.ts` that fetches artifact files from a CDN, verifies integrity, and stores them via a pluggable storage adapter.
167228
2. Support cache lookup before network fetch and provide `clearCache()` helper.
168229
3. Add tests mocking fetch and storage layers.
169-
:::
230+
4. Stream HTTP responses into hash verifier (do not buffer full files).
231+
5. Verify Content-Length matches bytes read to detect truncation.
232+
6. Validate download host against allowed-domains whitelist.
233+
7. Only write to persistent storage after both signature and per-file hash verification succeed.
234+
235+
</details>
170236

171237
## 10. Sample applications
172238

173-
:::task-stub{title="Add React Native sample"}
239+
<details>
240+
<summary><strong>Add React Native sample</strong></summary>
174241

175242
1. Under `samples/react-native/`, scaffold a bare-bones app using Expo or React Native CLI.
176243
2. Demonstrate MRZ scanning, NFC reading, and registration flow using SDK APIs.
177244
3. Include instructions in a `README.md`.
178-
:::
179245

180-
:::task-stub{title="Add web sample"}
246+
</details>
247+
248+
<details>
249+
<summary><strong>Add web sample</strong></summary>
181250

182251
1. Under `samples/web/`, set up a Vite/React project showing browser-based MRZ input and proof generation.
183252
2. Document setup and build steps.
184-
:::
185253

186-
:::task-stub{title="Configure OpenPassport scheme"}
254+
</details>
255+
256+
<details>
257+
<summary><strong>Configure OpenPassport scheme</strong></summary>
187258

188-
1. In the React Native sample’s iOS project, add URL type `OpenPassport` to `Info.plist`.
189-
2. Document how the scheme is used for callback flows.
190-
:::
259+
1. In the React Native sample's iOS project, add URL type `OpenPassport` to `Info.plist`.
260+
2. Document Android intent filters (AndroidManifest.xml). Ensure scheme uniqueness and validate redirect origins to prevent hijacking.
261+
3. Choose a scheme unique to your app (e.g., using reverse-domain or app-identifier prefix).
262+
4. Detect and handle collisions (fallback checks, verify caller package/signature).
263+
5. Verify redirect domains and consider app-claimed links/Android App Links and iOS Universal Links for stronger security.
264+
265+
</details>
191266

192267
## 11. Integrate SDK into `/app`
193268

194-
:::task-stub{title="Integrate SDK in /app"}
269+
<details>
270+
<summary><strong>Integrate SDK in /app</strong></summary>
195271

196272
1. Add `@selfxyz/mobile-sdk-alpha` to `app/package.json`.
197273
2. Replace existing MRZ/NFC scanning modules with SDK adapters.
198274
3. Wire app screens to SDK processing and validation helpers.
199275
4. Validate builds and unit tests in the `app` workspace.
200-
:::
276+
277+
</details>
201278

202279
## 12. In-SDK lightweight demo
203280

204-
:::task-stub{title="Create embedded demo app"}
281+
<details>
282+
<summary><strong>Create embedded demo app</strong></summary>
205283

206284
1. Scaffold `demo/` under the SDK as a minimal React Native project.
207285
2. Use SDK APIs for MRZ → NFC → registration flow.
208286
3. Expose simple theming configuration.
209287
4. Add `demo/README.md` with build/run instructions.
210-
:::
288+
5. Add publishing guardrails: exclude `demo/` from npm and add a CI step to verify the published tarball contents.
289+
290+
</details>

0 commit comments

Comments
 (0)