Compare commits

...
6 Commits
Author SHA1 Message Date
Mathias Buus 0227f45c6b 0.7.3 2020-11-13 16:46:11 +01:00
Mathias Buus ca32540960 load the sink just in time 2020-11-13 16:46:06 +01:00
Mathias Buus 51093efbc5 0.7.2 2020-11-12 14:46:28 +01:00
Christophe Diederichs f79aed4eee turn off worker_threads in browser (#52) 2020-11-12 14:04:40 +01:00
Kyle Mathews 3eb1d64460 Small copy change to README (#54) 2020-11-12 08:39:33 +01:00
RangerMauve 7febc97986 Detect window.close is defined (#49) 2020-10-09 13:35:11 +02:00
4 changed files with 16 additions and 8 deletions
+1 -1
View File
@@ -33,7 +33,7 @@ console.log('Plaintext:', plainText.toString())
## API
See [sodium-native](https://github.com/sodium-friends/sodium-native).
This is a work in progress so all functions are not implemented yet.
This is a work in progress so not all functions are implemented yet.
This module is organised into individual submodules which can be required
independently for smaller bundles in the browser. To leverage automatic
+11 -4
View File
@@ -1,21 +1,28 @@
/* eslint-disable camelcase */
var MessageChannel = global.MessageChannel
if (MessageChannel == null) ({ MessageChannel } = require('worker' + '_threads'))
function sodium_malloc (n) {
return new Uint8Array(n)
}
const sink = new MessageChannel()
function sodium_free (n) {
sodium_memzero(n)
sink.port1.postMessage(n.buffer, [n.buffer])
loadSink().port1.postMessage(n.buffer, [n.buffer])
}
function sodium_memzero (arr) {
arr.fill(0)
}
var sink
function loadSink () {
if (sink) return sink
var MessageChannel = global.MessageChannel
if (MessageChannel == null) ({ MessageChannel } = require('worker' + '_threads'))
sink = new MessageChannel()
return sink
}
module.exports = {
sodium_malloc,
sodium_free,
+3 -2
View File
@@ -1,6 +1,6 @@
{
"name": "sodium-javascript",
"version": "0.7.1",
"version": "0.7.3",
"description": "WIP - a pure javascript version of sodium-native",
"main": "index.js",
"dependencies": {
@@ -24,7 +24,8 @@
]
},
"browser": {
"crypto": false
"crypto": false,
"worker_threads": false
},
"react-native": {
"crypto": "crypto"
+1 -1
View File
@@ -1,3 +1,3 @@
require('sodium-test')(require('.'))
if (typeof window !== 'undefined') window.close()
if ((typeof window !== 'undefined') && window.close) window.close()