2020-06-24 12:01:48 +00:00
|
|
|
/* eslint-disable camelcase */
|
|
|
|
|
|
|
|
function sodium_malloc (n) {
|
|
|
|
return new Uint8Array(n)
|
|
|
|
}
|
|
|
|
|
2020-08-12 13:39:14 +00:00
|
|
|
function sodium_free (n) {
|
|
|
|
sodium_memzero(n)
|
2020-11-13 15:46:06 +00:00
|
|
|
loadSink().port1.postMessage(n.buffer, [n.buffer])
|
2020-08-12 13:39:14 +00:00
|
|
|
}
|
|
|
|
|
2020-06-24 12:01:48 +00:00
|
|
|
function sodium_memzero (arr) {
|
|
|
|
arr.fill(0)
|
|
|
|
}
|
|
|
|
|
2020-11-13 15:46:06 +00:00
|
|
|
var sink
|
|
|
|
|
|
|
|
function loadSink () {
|
|
|
|
if (sink) return sink
|
|
|
|
var MessageChannel = global.MessageChannel
|
|
|
|
if (MessageChannel == null) ({ MessageChannel } = require('worker' + '_threads'))
|
|
|
|
sink = new MessageChannel()
|
|
|
|
return sink
|
|
|
|
}
|
|
|
|
|
2020-06-24 12:01:48 +00:00
|
|
|
module.exports = {
|
|
|
|
sodium_malloc,
|
2020-08-12 13:39:14 +00:00
|
|
|
sodium_free,
|
2020-06-24 12:01:48 +00:00
|
|
|
sodium_memzero
|
|
|
|
}
|