PeculiarVentures / webcrypto-core

A input validation layer for WebCrypto polyfills.
MIT License
28 stars 13 forks source link

[importKey] TypedArray is not supported #43

Closed panva closed 2 years ago

panva commented 2 years ago

SubtleCrypto.importKey() keyData argument is an ArrayBuffer, a TypedArray, a DataView, or a JSONWebKey object containing the key in the given format.

Currently, when webcrypto-liner > webcrypto-core is used, Typed Arrays such as Uint8Array or node's Buffer cannot be imported.

See https://github.com/panva/jose/discussions/363

microshine commented 2 years ago

It's strange. My local tests are passed for Object(JWK), Uint8Array, Buffer, and ArrayBuffer

image
panva commented 2 years ago

It is strange indeed, in the case linked, Uint8Array is used, but the OP has not responded with more details about their runtime either...

Feel free to close if you feel this falls on the OP's environment setup or is otherwise related to their usage.

Thanks for responding this quickly.

microshine commented 2 years ago

Here is a webcrypto-liner example. It shows that importKey works for Uint8Array and ArrayBuffer

https://codesandbox.io/s/webcrypto-liner-scgkyj?file=/index.html

microshine commented 2 years ago

webcrypto-core uses pvtsutils.BufferSource. It must work with those types of buffers.

https://github.com/PeculiarVentures/pvtsutils/blob/master/test/buffer_source_converter.ts#L4

I'm going to close this issue

panva commented 2 years ago

It must work with those types of buffers.

Well, clearly it fails for the OP. But I'm falling short on details and will to investigate myself.

@pshaddel, if you could provide steps to reproduce here.

pshaddel commented 2 years ago

It must work with those types of buffers.

Well, clearly it fails for the OP. But I'm falling short on details and will to investigate myself.

@pshaddel, if you could provide steps to reproduce here.

I'm using dgraph lambda functions which are pieces of Javascript code that executes on web workers. I try to make an example that helps reproducing this error.

pshaddel commented 2 years ago

Hi @microshine the issue is not related to the package and I was able to get the result without any error. Thank you for your time.