You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
/** A pseudo-random number generator */classRng{/** Returns random bytes of specified length */randomBytes(count: number): Uint8Array{constarray=newUint8Array(count);self.crypto.getRandomValues(array);returnarray;}}
However, that'll copy the array generated inside randomBytes from the JS heap into the Wasm heap.
We can do better, if instead we defined fn get_random_bytes(this: &Rng, buffer: &mut [u8]) or fn get_random_bytes(this: &Rng, buffer: Uint8Array) or something along those lines, where the buffer to write into is provided by the Wasm side. crypto.getRandomBytes can write into any location in zero copies :)
The text was updated successfully, but these errors were encountered:
Currently the
Rng
interface in wnfs-wasm looks like this:So it's implemented like this on the JS side:
However, that'll copy the
array
generated insiderandomBytes
from the JS heap into the Wasm heap.We can do better, if instead we defined
fn get_random_bytes(this: &Rng, buffer: &mut [u8])
orfn get_random_bytes(this: &Rng, buffer: Uint8Array)
or something along those lines, where the buffer to write into is provided by the Wasm side.crypto.getRandomBytes
can write into any location in zero copies :)The text was updated successfully, but these errors were encountered: