sqlite3.dart icon indicating copy to clipboard operation
sqlite3.dart copied to clipboard

dart2wasm support

Open simolus3 opened this issue 1 year ago • 2 comments

Current state: package:sqlite3 experimentally supports being compiled with dart2wasm. Unit tests exercising the bindings themselves all pass, but persistence is broken. There are additional caveats and todos to be aware of:

  • [x] (fixed in upcoming Dart SDK release) dart2wasm doesn't seem to support Random.secure(), which we use for our VFS implementations. You can work around this issue by supplying your own non-secure Random() instance to VFS constructors, but please be aware that this may be a security risk. sqlite3 docs require that "The xRandomness() function attempts to return nBytes bytes of good-quality randomness into zOut", so I won't use the non-secure random instance as a default in this package.
  • [x] When binding over web APIs returning JavaScript ArrayBuffers, we're converting them to Dart TypedData subclasses for convenience. This is not sound for dart2wasm, which copies the bytes instead of referencing the original buffer. This may just be hugely inefficient, but it can also cause deadlocks for OPFS and data corruption issues on other VFS implementations.
  • [ ] We're currently loading an additional wasm module for sqlite3 (sqlite3.wasm). Once the native assets feature is stable and supports WebAssembly, obviously we want to link the Dart application and sqlite3 into the same wasm file for easier deployments.

simolus3 avatar May 10 '24 21:05 simolus3

For secure rng. Could you use one of the implementations from the pointycastle package?

ekuleshov avatar May 11 '24 00:05 ekuleshov

That doesn't help getting entropy. Secure random has been implemented, it's just not on stable yet. So we can just wait.

simolus3 avatar May 11 '24 12:05 simolus3