Fork me on GitHub
#nbb
<
2022-09-30
>
genRaiy09:09:38

Something odd here ... this function "just works" in CLJS

genRaiy09:09:45

(defn ->encryption-key
	[]
	(js/crypto.subtle.generateKey
		(clj->js {:name "RSA-OAEP"
							:modulusLength 4096
							:publicExponent (js/Uint8Array. [1 0 1])
							:hash "SHA-384"})
		extractable?
		["encrypt" "decrypt"]))

genRaiy09:09:10

with nbb it fails ... saying that the key needs usages

genRaiy09:09:16

the fix is

genRaiy09:09:51

(defn ->encryption-key
	[]
	(js/crypto.subtle.generateKey
		(clj->js {:name "RSA-OAEP"
							:modulusLength 4096
							:publicExponent (js/Uint8Array. [1 0 1])
							:hash "SHA-384"})
		extractable?
		(clj->js ["encrypt" "decrypt"]))) ; <-- extra clj-js needed

genRaiy09:09:02

is that right?

borkdude09:09:00

I don't see why that would be necessary?

borkdude09:09:35

In CLJS ["foo" "bar"] would not be an array, it would be a vector

borkdude09:09:57

you could also prefix it with #js [..]

😬 1
genRaiy10:09:30

point is that it works unadorned in CLJS but not nbb .... is that a bug?

borkdude10:09:04

I don't know. What is the type that the last argument of generateKey accepts? And what does CLJS pass and how is that differently than what nbb passes? It's not obvious to me

borkdude10:09:26

Perhaps you can print the type of that thing. If the types are equal, the "bug" may be somewhere else

lilactown16:09:41

it could be different environments. Node.js implements an assertion in crypto.subtle.generateKey that checks whether the keyUsage argument is in fact an array

lilactown16:09:06

maybe the environment you're running your CLJS in is different? you didn't say whether it was Node.js as well or in the browser

genRaiy16:09:53

Nbb is node

genRaiy16:09:12

The other was indeed in a browser

genRaiy16:09:45

Ok so it's a node thing rather than an nbb thing

genRaiy16:09:56

Thanks Will

gratitude 1