Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0227f45c6b | ||
|
|
ca32540960 | ||
|
|
51093efbc5 | ||
|
|
f79aed4eee | ||
|
|
3eb1d64460 | ||
|
|
7febc97986 |
@@ -33,7 +33,7 @@ console.log('Plaintext:', plainText.toString())
|
|||||||
## API
|
## API
|
||||||
|
|
||||||
See [sodium-native](https://github.com/sodium-friends/sodium-native).
|
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
|
This module is organised into individual submodules which can be required
|
||||||
independently for smaller bundles in the browser. To leverage automatic
|
independently for smaller bundles in the browser. To leverage automatic
|
||||||
|
|||||||
@@ -1,21 +1,28 @@
|
|||||||
/* eslint-disable camelcase */
|
/* eslint-disable camelcase */
|
||||||
var MessageChannel = global.MessageChannel
|
|
||||||
if (MessageChannel == null) ({ MessageChannel } = require('worker' + '_threads'))
|
|
||||||
|
|
||||||
function sodium_malloc (n) {
|
function sodium_malloc (n) {
|
||||||
return new Uint8Array(n)
|
return new Uint8Array(n)
|
||||||
}
|
}
|
||||||
|
|
||||||
const sink = new MessageChannel()
|
|
||||||
function sodium_free (n) {
|
function sodium_free (n) {
|
||||||
sodium_memzero(n)
|
sodium_memzero(n)
|
||||||
sink.port1.postMessage(n.buffer, [n.buffer])
|
loadSink().port1.postMessage(n.buffer, [n.buffer])
|
||||||
}
|
}
|
||||||
|
|
||||||
function sodium_memzero (arr) {
|
function sodium_memzero (arr) {
|
||||||
arr.fill(0)
|
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 = {
|
module.exports = {
|
||||||
sodium_malloc,
|
sodium_malloc,
|
||||||
sodium_free,
|
sodium_free,
|
||||||
|
|||||||
+3
-2
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "sodium-javascript",
|
"name": "sodium-javascript",
|
||||||
"version": "0.7.1",
|
"version": "0.7.3",
|
||||||
"description": "WIP - a pure javascript version of sodium-native",
|
"description": "WIP - a pure javascript version of sodium-native",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
@@ -24,7 +24,8 @@
|
|||||||
]
|
]
|
||||||
},
|
},
|
||||||
"browser": {
|
"browser": {
|
||||||
"crypto": false
|
"crypto": false,
|
||||||
|
"worker_threads": false
|
||||||
},
|
},
|
||||||
"react-native": {
|
"react-native": {
|
||||||
"crypto": "crypto"
|
"crypto": "crypto"
|
||||||
|
|||||||
Reference in New Issue
Block a user