Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 15 additions & 12 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
SCRYPTRAW=scrypt_raw.js
SCRYPTRAW=src/scrypt_raw.js
SCRYPTVERSION=1.1.6
JSSCRYPTVERSION=${shell node -e 'console.log(require("./tools/version.js"))'}
RELEASE=browser/scrypt-$(JSSCRYPTVERSION).js
SCRYPTUNPACKED=scrypt-$(SCRYPTVERSION)
SCRYPTTARBALL=scrypt-$(SCRYPTVERSION).tgz

PYTHON=python
EMCC=`which emcc`

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

$(SCRYPTRAW): $(SCRYPTUNPACKED)
EMCC_DEBUG=2 $(PYTHON) $(EMCC) \
Expand All @@ -21,16 +23,17 @@ $(SCRYPTRAW): $(SCRYPTUNPACKED)

clean:
rm -f $(SCRYPTRAW)
rm -rf browser

browser: $(SCRYPTRAW) scrypt_browser_prefix.js scrypt_cooked.js scrypt_browser_suffix.js
mkdir -p $@
cat \
scrypt_browser_prefix.js \
$(SCRYPTRAW) \
scrypt_cooked.js \
scrypt_browser_suffix.js \
> $@/scrypt.js
rm -r $(RELEASE)

node_modules: package.json
@ npm prune
@ npm install

index.js: $(SCRYPTRAW) src/scrypt_cooked.js node_modules tools/create-index.js
node tools/create-index.js

release: node_modules index.js
./node_modules/.bin/umd scrypt --commonJS index.js $(RELEASE)

veryclean: clean
rm -rf $(SCRYPTUNPACKED)
Expand Down
25 changes: 14 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,21 @@ use the library in the browser.

## Using the library

In the browser, include the `browser/scrypt.js` script, and invoke
`scrypt_module_factory` to produce a usable `scrypt` module:
In the browser, include the `browser/scrypt-<version>.js` script:

<script src="browser/scrypt.js"></script>
<script> var scrypt = scrypt_module_factory(); </script>
<script src="browser/scrypt-0.0.1.js"></script>
...
<script> alert(scrypt.to_hex(scrypt.random_bytes(16))); </script>
<script> alert(window.scrypt.to_hex(scrypt.random_bytes(16))); </script>

The `scrypt_module_factory` function takes an optional argument
specifying the total memory available for use by `scrypt()`. If
supplied, it must be a power of two. If omitted, the default is
33,554,432 bytes; 32 megabytes.
This will add `scrypt` to the `window` object, if that is undesired
the script does have a [UMD](https://npmjs.org/package/umd) wrapper
around it and will work with require.js as well as npm and browserify.

If you need an instance of `scrypt` with the total memory adjusted
from it's default use `scrypt.create(total_memory)`. The create
method takes an optional argument specifying the total memory
available for use by `scrypt()`. If supplied, it must be a power of
two. If omitted, the default is 33,554,432 bytes; 32 megabytes.

The memory assigned to the produced `scrypt` module will not be
released until the module is garbage collected.
Expand Down Expand Up @@ -123,7 +126,7 @@ as a `Uint8Array`.
js-scrypt is written by Tony Garnock-Jones
<[email protected]> and is licensed under the [2-clause BSD license](http://opensource.org/licenses/BSD-2-Clause):

> Copyright &copy; 2013, Tony Garnock-Jones
> Copyright &copy; 2013, Tony Garnock-Jones
> All rights reserved.
>
> Redistribution and use in source and binary forms, with or without
Expand Down Expand Up @@ -154,7 +157,7 @@ js-scrypt is written by Tony Garnock-Jones
js-scrypt relies on `scrypt` itself, which is written by Colin
Percival and licensed as follows:

> Copyright 2009 Colin Percival
> Copyright 2009 Colin Percival
> All rights reserved.
>
> Redistribution and use in source and binary forms, with or without
Expand Down
Loading