Skip to content

Commit

Permalink
Update to build with emsdk v1.36.x. Problems with chrome and, separat…
Browse files Browse the repository at this point in the history
…ely, the closure compiler prevent making this a release build.
  • Loading branch information
tonyg committed May 23, 2016
1 parent d13a282 commit 9053dbf
Show file tree
Hide file tree
Showing 13 changed files with 487 additions and 26,002 deletions.
6 changes: 1 addition & 5 deletions BUILDING.md
Expand Up @@ -6,11 +6,7 @@ policy is to include the generated javascript as a checked-in file.
## Ingredients

- Python 2.x
- a recent Emscripten, which in turn has dependencies on:
- LLVM 3.2
- Clang 3.2
- Node.js 0.6.12 or newer
- Python 2.7.3
- a recent Emscripten SDK
- Node.js and npm to run the [mocha](http://visionmedia.github.io/mocha/)-based tests

Within the `js-nacl` directory,
Expand Down
7 changes: 4 additions & 3 deletions Makefile
Expand Up @@ -8,17 +8,17 @@ EMCC=`which emcc`
test: all
npm test

## Builds well with emscripten of August 8, 2013 or newer and Clang/LLVM 3.2.
## Builds well with emscripten SDK 1.36.4.
all: lib


$(NACLRAW): subnacl
EMCC_DEBUG=2 $(PYTHON) $(EMCC) \
-s ASSERTIONS=2 \
-s LINKABLE=1 \
-s EXPORTED_FUNCTIONS="$$(cat subnacl/naclexports.sh)" \
--js-library nacl_randombytes_emscripten.js \
--post-js subnacl/naclapi.js \
-O2 --closure 1 -o $@ \
-O3 -o $@ \
-I subnacl/include \
keys.c \
$$(find subnacl -name '*.c')
Expand All @@ -31,6 +31,7 @@ lib: $(NACLRAW) nacl_cooked_prefix.js nacl_cooked.js nacl_cooked_suffix.js
mkdir -p $@
cat nacl_cooked_prefix.js $(NACLRAW) nacl_cooked.js nacl_cooked_suffix.js \
> $@/nacl_factory.js
cp nacl_raw.js.mem $@/

veryclean: clean
rm -rf subnacl
Expand Down
44 changes: 30 additions & 14 deletions README.md
Expand Up @@ -23,6 +23,11 @@ all the versions I've tried.

## Changes

Version 1.1.0: **API change.** The `nacl_factory.instantiate` function
now expects a callback as its first argument. It calls the callback
with the `nacl` instance containing the API functions, and returns no
useful value.

Version 0.5.0: **API change.** Instead of being provided with a module
`nacl`, with API functions available directly, library importers are
given `nacl_factory` with a single function `instantiate`, which
Expand Down Expand Up @@ -55,33 +60,44 @@ In the browser, include the `lib/nacl_factory.js` script:
<script src="lib/nacl_factory.js"></script>
...
<script>
var nacl = nacl_factory.instantiate();
alert(nacl.to_hex(nacl.random_bytes(16)));
nacl_factory.instantiate(function (nacl) {
alert(nacl.to_hex(nacl.random_bytes(16)));
});
</script>

In node.js, require the `lib/nacl_factory.js` module:

var nacl_factory = require("./lib/nacl_factory.js");
var nacl = nacl_factory.instantiate();
...
console.log(nacl.to_hex(nacl.random_bytes(16)));
nacl_factory.instantiate(function (nacl) {
...
console.log(nacl.to_hex(nacl.random_bytes(16)));
});

Or if you have installed the library via `npm`,

var nacl_factory = require("js-nacl");
var nacl = nacl_factory.instantiate();
...
console.log(nacl.to_hex(nacl.random_bytes(16)));
nacl_factory.instantiate(function (nacl) {
...
console.log(nacl.to_hex(nacl.random_bytes(16)));
});

## Instantiating the NaCl module

Calling `nacl_factory.instantiate()` creates an entirely fresh module
instance, complete with its own private heap area. By default, this
heap is 32 megabytes in size, 33,554,432 bytes. The size of the module
instance's private heap can be altered by supplying an argument to
`instantiate`, e.g.:
Pass `nacl_factory.instantiate` a callback function expecting a single
argument, the `nacl` module instance.

The `nacl_factory.instantiate` function expects also a second optional
argument, a dictionary of optional configuration values.

Each call to `nacl_factory.instantiate()` creates an entirely fresh
module instance, complete with its own private heap area. By default,
this heap is 32 megabytes in size, 33,554,432 bytes. The size of the
module instance's private heap can be altered by supplying
`requested_total_memory` to to `instantiate`, e.g.:

var nacl = nacl_factory.instantiate(16777216);
nacl_factory.instantiate(on_ready, {
requested_total_memory: 16777216
});

The argument must be a power of two, if supplied.

Expand Down
7 changes: 5 additions & 2 deletions benchmark.js
Expand Up @@ -13,9 +13,12 @@ function main () {
output("Test,Iterations per second,Seconds per iteration");

try {
do_tests(nacl_factory.instantiate());
nacl_factory.instantiate(do_tests, {
memoryInitializerPrefixURL: 'lib/'
});
} catch (e) {
output('EXCEPTION: ' + JSON.stringify(e));
console.error(e);
output('EXCEPTION: ' + e.message);
}
}

Expand Down
2 changes: 1 addition & 1 deletion bower.json
@@ -1,6 +1,6 @@
{
"name": "js-nacl",
"version": "0.6.0",
"version": "1.1.0",
"homepage": "https://github.com/tonyg/js-nacl",
"authors": [
"Tony Garnock-Jones"
Expand Down
2 changes: 2 additions & 0 deletions keys.c
@@ -1,5 +1,7 @@
/* Derivation of Ed25519 keypairs from seeds. Compatible with libsodium. */

#include <stdlib.h>

#include "crypto_hash_sha512.h"
#include "subnacl/sign_ed25519/fe25519.h"
#include "subnacl/sign_ed25519/ge25519.h"
Expand Down

0 comments on commit 9053dbf

Please sign in to comment.