Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions crates/spidermonkey-embedding-splicer/src/stub_wasi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,12 +136,11 @@ pub fn stub_wasi(

let mut module = Module::parse(wasm.as_slice(), false, false).unwrap();

stub_preview1(&mut module)?;

stub_filesystem(&mut module, &target_world_imports)?;
stub_cli(&mut module, &target_world_imports)?;

if !features.contains(&Feature::Random) {
stub_preview1(&mut module)?;
stub_random(&mut module)?;
}

Expand Down Expand Up @@ -208,7 +207,6 @@ fn target_world_requires_io(target_world_imports: &HashSet<String>) -> bool {

const PREVIEW1: &str = "wasi_snapshot_preview1";
fn stub_preview1(module: &mut Module) -> Result<()> {
// random comes from prevew2 only in StarlingMonkey
stub_import(module, PREVIEW1, "random_get", unreachable_stub)?;
Ok(())
}
Expand Down
31 changes: 31 additions & 0 deletions test/builtins/crypto-import-key.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { strictEqual } from 'node:assert';
import { generateKeyPairSync, sign } from 'node:crypto';

const data = 'componentize-js';
const rsa = generateKeyPairSync('rsa', { modulusLength: 2048 });
const ec = generateKeyPairSync('ec', { namedCurve: 'P-256' });
const rsaSig = sign('sha256', Buffer.from(data), rsa.privateKey);
const ecSig = sign('sha256', Buffer.from(data), {
key: ec.privateKey,
dsaEncoding: 'ieee-p1363',
});

export const source = `
const b64 = (s) => Uint8Array.from(atob(s), (c) => c.charCodeAt(0));
const data = new TextEncoder().encode('${data}');
async function verify(jwk, sig, importAlg, verifyAlg) {
const key = await crypto.subtle.importKey('jwk', jwk, importAlg, false, ['verify']);
return key.type + ' ' + await crypto.subtle.verify(verifyAlg, key, b64(sig), data);
}
export async function run () {
const rsaAlg = { name: 'RSASSA-PKCS1-v1_5', hash: 'SHA-256' };
console.log(await verify(${JSON.stringify(rsa.publicKey.export({ format: 'jwk' }))}, '${rsaSig.toString('base64')}', rsaAlg, rsaAlg));
console.log(await verify(${JSON.stringify(ec.publicKey.export({ format: 'jwk' }))}, '${ecSig.toString('base64')}', { name: 'ECDSA', namedCurve: 'P-256' }, { name: 'ECDSA', hash: 'SHA-256' }));
}
`;

export async function test(run) {
const { stdout, stderr } = await run();
strictEqual(stderr, '');
strictEqual(stdout, 'public true\npublic true\n');
}