Compare commits

...
10 Commits
Author SHA1 Message Date
Christophe Diederichs 426ca77d47 0.7.4 2021-11-05 09:32:51 +00:00
Kasper Isager Dalsgarð 25c97802f4 crypto_sign: replace Buffer.alloc() with new Uint8Array() (#62) 2021-11-04 17:17:13 +00:00
Kasper Isager Dalsgarð 87ff2a56bd Use globalThis instead of global (#61)
* Use `globalThis` instead of `global`

* Update `standard`
2021-11-02 16:36:15 +01:00
RangerMauve 7ef6e52870 Remove "react-native" field
This field isn't adding anything at the moment, and it actually breaks things by pointing at an unresolvable module.
2020-12-01 11:29:33 +01:00
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
7 changed files with 20 additions and 14 deletions
+1
View File
@@ -1 +1,2 @@
node_modules
package-lock.json
+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
+1 -1
View File
@@ -452,7 +452,7 @@ function crypto_sign_ed25519_sk_to_curve25519 (curveSk, edSk) {
assert(curveSk && curveSk.byteLength === crypto_scalarmult_BYTES, "curveSk must be 'crypto_sign_SECRETKEYBYTES' long")
assert(edSk && edSk.byteLength === crypto_sign_ed25519_SECRETKEYBYTES, "edSk must be 'crypto_sign_ed25519_SECRETKEYBYTES' long")
var h = Buffer.alloc(crypto_hash_sha512_BYTES)
var h = new Uint8Array(crypto_hash_sha512_BYTES)
crypto_hash(h, edSk, 32)
h[0] &= 248
+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 = globalThis.MessageChannel
if (MessageChannel == null) ({ MessageChannel } = require('worker' + '_threads'))
sink = new MessageChannel()
return sink
}
module.exports = {
sodium_malloc,
sodium_free,
+4 -6
View File
@@ -1,6 +1,6 @@
{
"name": "sodium-javascript",
"version": "0.7.1",
"version": "0.7.4",
"description": "WIP - a pure javascript version of sodium-native",
"main": "index.js",
"dependencies": {
@@ -15,7 +15,7 @@
"devDependencies": {
"browserify": "^16.5.1",
"sodium-test": "^0.10.0",
"standard": "^14.3.4",
"standard": "^15.0.1",
"tape-run": "^7.0.0"
},
"standard": {
@@ -24,10 +24,8 @@
]
},
"browser": {
"crypto": false
},
"react-native": {
"crypto": "crypto"
"crypto": false,
"worker_threads": false
},
"scripts": {
"pretest": "standard",
+1 -1
View File
@@ -2,7 +2,7 @@ var assert = require('nanoassert')
var randombytes = (function () {
var QUOTA = 65536 // limit for QuotaExceededException
var crypto = global.crypto || global.msCrypto
var crypto = globalThis.crypto || globalThis.msCrypto
function browserBytes (out, n) {
for (let i = 0; i < n; i += QUOTA) {
+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()