|
1 | 1 | import { test, expect } from '@playwright/test'; |
2 | | -import { execSync } from 'child_process'; |
3 | 2 | import * as fs from 'fs'; |
4 | 3 | import * as path from 'path'; |
5 | 4 | import { |
@@ -31,28 +30,6 @@ test.describe('QR Scanner', () => { |
31 | 30 | } |
32 | 31 | }); |
33 | 32 |
|
34 | | - // Extract a compact share string from a bundle's README.txt using the CLI |
35 | | - function getCompactShare(bundleDir: string): string { |
36 | | - const readmePath = path.join(bundleDir, 'README.txt'); |
37 | | - const content = fs.readFileSync(readmePath, 'utf8'); |
38 | | - |
39 | | - // Parse the PEM share via the CLI to get the compact format |
40 | | - // We can use the share content directly - extract the PEM block |
41 | | - const pemMatch = content.match( |
42 | | - /-----BEGIN REMEMORY SHARE-----([\s\S]*?)-----END REMEMORY SHARE-----/ |
43 | | - ); |
44 | | - if (!pemMatch) throw new Error('No PEM share found in README.txt'); |
45 | | - |
46 | | - // Use the binary to convert - run rememory doc compact-share with the share file |
47 | | - // Actually, let's just extract the share data from the output directory |
48 | | - const sharesDir = path.join(projectDir, 'output', 'shares'); |
49 | | - const shareFiles = fs.readdirSync(sharesDir); |
50 | | - |
51 | | - // We need the compact format. Let's get it via page.evaluate after WASM loads. |
52 | | - // For now, return the full PEM content and we'll convert in-browser. |
53 | | - return pemMatch[0]; |
54 | | - } |
55 | | - |
56 | 33 | test('scan button is visible when BarcodeDetector is available', async ({ page }) => { |
57 | 34 | const bundleDir = extractBundle(bundlesDir, 'Alice'); |
58 | 35 |
|
@@ -176,17 +153,10 @@ test.describe('QR Scanner', () => { |
176 | 153 | const compactShare = await page.evaluate((pem: string) => { |
177 | 154 | const result = (window as any).rememoryParseShare(pem); |
178 | 155 | if (result.error || !result.share) return ''; |
179 | | - const share = result.share; |
180 | | - const b64url = share.dataB64.replace(/\+/g, '-').replace(/\//g, '_').replace(/=+$/, ''); |
181 | | - const data = Uint8Array.from(atob(share.dataB64), (c: string) => c.charCodeAt(0)); |
182 | | - return crypto.subtle.digest('SHA-256', data).then((hash: ArrayBuffer) => { |
183 | | - const arr = new Uint8Array(hash); |
184 | | - const check = Array.from(arr.slice(0, 2)).map(b => b.toString(16).padStart(2, '0')).join(''); |
185 | | - return `RM1:${share.index}:${share.total}:${share.threshold}:${b64url}:${check}`; |
186 | | - }); |
| 156 | + return result.share.compact; |
187 | 157 | }, bobPemShare); |
188 | 158 |
|
189 | | - expect(compactShare).toMatch(/^RM1:\d+:\d+:\d+:[A-Za-z0-9_-]+:[0-9a-f]{4}$/); |
| 159 | + expect(compactShare).toMatch(/^RM\d+:\d+:\d+:\d+:[A-Za-z0-9_-]+:[0-9a-f]{4}$/); |
190 | 160 |
|
191 | 161 | // Verify the compact share parses correctly |
192 | 162 | const parseResult = await page.evaluate((compact: string) => { |
@@ -256,18 +226,11 @@ test.describe('QR Scanner', () => { |
256 | 226 | const recovery = new RecoveryPage(page, aliceDir); |
257 | 227 | await recovery.open(); |
258 | 228 |
|
259 | | - // Build compact share from PEM via in-browser conversion |
| 229 | + // Convert PEM share to compact format via WASM |
260 | 230 | const compactShare = await page.evaluate((pem: string) => { |
261 | 231 | const result = (window as any).rememoryParseShare(pem); |
262 | 232 | if (result.error || !result.share) return ''; |
263 | | - const share = result.share; |
264 | | - const b64url = share.dataB64.replace(/\+/g, '-').replace(/\//g, '_').replace(/=+$/, ''); |
265 | | - const data = Uint8Array.from(atob(share.dataB64), (c: string) => c.charCodeAt(0)); |
266 | | - return crypto.subtle.digest('SHA-256', data).then((hash: ArrayBuffer) => { |
267 | | - const arr = new Uint8Array(hash); |
268 | | - const check = Array.from(arr.slice(0, 2)).map(b => b.toString(16).padStart(2, '0')).join(''); |
269 | | - return `RM1:${share.index}:${share.total}:${share.threshold}:${b64url}:${check}`; |
270 | | - }); |
| 233 | + return result.share.compact; |
271 | 234 | }, pemMatch[0]); |
272 | 235 |
|
273 | 236 | await page.evaluate((compact: string) => { |
|
0 commit comments