SubtleCrypto providing invalid CryptoKey

I'm trying to import a public key using importKey, but it just returns an empty CryptoKey, meanwhile in NodeJS it'll import just fine. Code:
const publicKey = await crypto.subtle.importKey(
"spki",
Buffer.from(
"3059301306072a8648ce3d020106082a8648ce3d03010703420004ea1371a3dca5e8a934bf5e434ead0aeee951cc1d09774df2f1aa6948dde7c67cb4bc62502d1d05e03e7ae318820875ff988093e14cc541660366b5af868267c4",
"hex"
),
{ name: "ECDSA", namedCurve: "P-256", hash: { name: "SHA-256" } },
true,
["verify"]
);
const publicKey = await crypto.subtle.importKey(
"spki",
Buffer.from(
"3059301306072a8648ce3d020106082a8648ce3d03010703420004ea1371a3dca5e8a934bf5e434ead0aeee951cc1d09774df2f1aa6948dde7c67cb4bc62502d1d05e03e7ae318820875ff988093e14cc541660366b5af868267c4",
"hex"
),
{ name: "ECDSA", namedCurve: "P-256", hash: { name: "SHA-256" } },
true,
["verify"]
);
On the worker runtime it returns
CryptoKey {
usages: undefined,
algorithm: undefined,
extractable: undefined,
type: undefined
}
CryptoKey {
usages: undefined,
algorithm: undefined,
extractable: undefined,
type: undefined
}
In NodeJS it returns
CryptoKey {
type: 'public',
extractable: true,
algorithm: { name: 'ECDSA', namedCurve: 'P-256' },
usages: [ 'verify' ]
}
CryptoKey {
type: 'public',
extractable: true,
algorithm: { name: 'ECDSA', namedCurve: 'P-256' },
usages: [ 'verify' ]
}
5 Replies
kian
kian17mo ago
It's not empty, it's just a quirk of console.log.
pee cee beez
pee cee beezOP17mo ago
...no, it's empty, it throws errors if I try to use it. It looks like it might be a miniflare bug, since I guess it does actually work in the worker runtime
kian
kian17mo ago
Well, Miniflare is the Worker runtime - and no, it isn't empty.
kian
kian17mo ago
pee cee beez
pee cee beezOP17mo ago
👍
Want results from more Discord servers?
Add your server