Files
simplexmq/smp-web/cbits/js_random.js
T
Evgeny 34e3d30c78 smp web: implement protocol encodings and encryption end-to-end (#1778)
* smp web: protocol encodings and x3dh

* fix

* strnup761 compiled to wasm

* AES-256-GCM, comatibility tests

* core of double ratchet

* PQ double ratchet

* test typescript ratchets

* agent encoding/encryption stack with test

---------

Co-authored-by: Evgeny @ SimpleX Chat <259188159+evgeny-simplex@users.noreply.github.com>
2026-05-16 18:18:45 +01:00

15 lines
398 B
JavaScript

addToLibrary({
js_random_bytes: function(buf, len) {
var bytes = new Uint8Array(len);
if (typeof crypto !== 'undefined' && crypto.getRandomValues) {
crypto.getRandomValues(bytes);
} else {
// Node.js fallback
var nodeCrypto = require('crypto');
var nodeBytes = nodeCrypto.randomBytes(len);
bytes.set(nodeBytes);
}
HEAPU8.set(bytes, buf);
}
});