nbb

ray 2022-09-30T09:37:38.182689Z

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

ray 2022-09-30T09:37:45.704519Z

(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"]))

ray 2022-09-30T09:38:10.841329Z

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

ray 2022-09-30T09:38:16.254509Z

the fix is

ray 2022-09-30T09:38:51.626799Z

(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

ray 2022-09-30T09:39:02.491769Z

is that right?

borkdude 2022-09-30T09:43:00.937599Z

I don't see why that would be necessary?

borkdude 2022-09-30T09:44:35.927249Z

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

borkdude 2022-09-30T09:44:57.802269Z

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

😬 1
ray 2022-09-30T10:19:30.621019Z

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

borkdude 2022-09-30T10:23:04.361109Z

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

borkdude 2022-09-30T10:34:26.915579Z

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

lilactown 2022-09-30T16:00:41.047009Z

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

lilactown 2022-09-30T16:01:06.006479Z

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

ray 2022-09-30T16:27:53.293729Z

Nbb is node

ray 2022-09-30T16:28:12.113169Z

The other was indeed in a browser

ray 2022-09-30T16:28:45.171949Z

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

ray 2022-09-30T16:28:56.362799Z

Thanks Will

1