Skip to content
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

'getRandomValues' in WebCrypto throws if receiver isn't a 'Crypto' instance. #4

Open
rbuckton opened this issue Feb 6, 2020 · 3 comments

Comments

@rbuckton
Copy link
Collaborator

rbuckton commented Feb 6, 2020

There's a slight difference here in that getRandomValues as currently specified in WebCrypto must be invoked with a receiver which is a crypto object: (0, crypto.getRandomValues)(new Uint8Array()) fails.

Note that the receiver just needs to be a crypto object:

let i = document.createElement('iframe');
document.body.append(i);
i.contentWindow.crypto.getRandomValues.call(crypto, new Uint8Array());

works.

The fact that crypto works this way is pretty unfortunate and, as I understand it, is just an accident of history: I'm pretty sure it's because crypto was specified before namespaces were introduced to WebIDL, which was done specifically to make (0, console.log)() work (done here). But it is what it is.

Originally posted by @bakkot in #2 (comment)

@rbuckton
Copy link
Collaborator Author

rbuckton commented Feb 6, 2020

Opening this as a separate issue to ensure we track this and discuss ramifications with the individuals involved with the WebCrypto spec.

@bakkot
Copy link

bakkot commented Feb 6, 2020

I don't believe this to be a web compatibility issue, however. Not throwing an error shouldn't make any existing code break today, though it would be worthwhile to discuss this more with someone directly involved with the WebCrypto spec about maintaining compatibility.

Originally posted by @rbuckton in #2 (comment)

Agreed.

@rbuckton
Copy link
Collaborator Author

rbuckton commented Feb 6, 2020

NOTE: @bakkot I edited your comment to add a link to where I originally wrote that comment, for anyone coming to this discussion later.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants