Skip to content

Commit

Permalink
WIP: JS Bindings From Jerzy Kozera (jkozera)
Browse files Browse the repository at this point in the history
  • Loading branch information
jgriffiths committed Jun 29, 2017
1 parent 78700bc commit 75c5c9d
Show file tree
Hide file tree
Showing 36 changed files with 3,167 additions and 6 deletions.
14 changes: 12 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
bld
src/*.pyc
src/test/*.pyc
*.pyc
src/test/__pycache__/
*~
*.class
Expand Down Expand Up @@ -46,6 +45,17 @@ src/swig_java/swig_java_wrap.c
src/swig_java/*.java
src/swig_java/*.jar
src/swig_java/src/com/blockstream/libwally
src/swig_js/CDVWally.swift
src/swig_js/WallyCordova.java
src/swig_js/node_modules
src/swig_js/swig.i
src/swig_js/swig_js_wrap.cxx
src/swig_js/wally.js
src/swig_js/cordovaplugin/wally.js
src/swig_js/cordovaplugin/CDVWally.swift
src/swig_js/cordovaplugin/swig.i
src/swig_js/cordovaplugin/WallyCordova.java
src/swig_js/cordovaplugin/Wally.java
src/swig_python/swig_python_wrap.c
src/swig_python/wallycore/__init__.py
src/swig_python/wallycore/wallycore.egg-info
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ $ make check
- `--enable-swig-python`. Enable the [SWIG](http://www.swig.org/) Python
interface. The resulting shared library can be imported from Python using
the generated interface file `src/swig_python/wallycore/wallycore.py`. (default: no).
- `--enable-swig-js`. Enable the [SWIG](http://www.swig.org/) Javascript
interface. Note that this currently requires `--enable-swig-python` (default: no).
- `--enable-swig-java`. Enable the [SWIG](http://www.swig.org/) Java (JNI)
interface. After building, see `src/swig_java/src/com/blockstream/libwally/Wally.java`
for the Java interface definition (default: no).
Expand Down
18 changes: 17 additions & 1 deletion configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include <stdlib.h>]],[[return posix_memalign(
AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include <string.h>]],[[int x[1]; memset_s(x, 1, 0, 1)]])],
[AC_DEFINE(HAVE_MEMSET_S, 1, [Define if we have memset_s])])

AC_CHECK_HEADERS([byteswap.h])
AC_CHECK_HEADERS([byteswap.h, sys/mman.h])

AX_PTHREAD([ac_have_pthread=yes], [ac_have_pthread=no])
AM_CONDITIONAL([USE_PTHREAD], [test "x$ac_have_pthread" == "xyes"])
Expand Down Expand Up @@ -213,6 +213,22 @@ if test "x$swig_python" == "xyes"; then
AX_CHECK_COMPILE_FLAG([-DSWIG_PYTHON_BUILD=1], [AM_CFLAGS="$AM_CFLAGS -DSWIG_PYTHON_BUILD=1"])
fi

AC_ARG_ENABLE(swig-js,
AS_HELP_STRING([--enable-swig-js],[enable the SWIG Javascript interface (default: no)]),
[swig_js=$enableval], [swig_js=no])
AM_CONDITIONAL([USE_SWIG_JS], [test "x$swig_js" == "xyes"])

if test "x$swig_js" == "xyes"; then
# FIXME: Check other build deps
if test "x$pythonexists" != "xyes"; then
AC_MSG_FAILURE([ERROR: No usable python was found for generating swig-js wrappers])
fi
if test "x$swig_python" != "xyes"; then
SWIG_PYTHON
fi
AX_CHECK_COMPILE_FLAG([-DSWIG_JAVASCRIPT_BUILD=1], [AM_CFLAGS="$AM_CFLAGS -DSWIG_JAVASCRIPT_BUILD=1"])
fi

AC_ARG_ENABLE(swig-java,
AS_HELP_STRING([--enable-swig-java],[enable the SWIG java (JNI) interface (default: no)]),
[swig_java=$enableval], [swig_java=no])
Expand Down
27 changes: 26 additions & 1 deletion src/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,32 @@ if IS_OSX
SWIG_PYTHON_TEST_DEPS = .libs/libwallycore.so
endif

endif
endif # USE_SWIG_PYTHON

if USE_SWIG_JS
# The SWIG interface files and wrappers are generated from a python script
swig_js/swig.i:
PYTHONDONTWRITEBYTECODE=1 $(PYTHON) swig_js/makewrappers/wrap.py swig_js/

# We generate the swig wrapper normally...
# FIXME: Put this in the autoconf machinery
SWIG_JS_OPT := -javascript -node -c++
swig_js/swig_js_wrap.cxx : swig_js/swig.i
$(AM_V_at)$(SWIG) $(SWIG_JS_OPT) -outdir swig_js -o $@ $<

# ...And then build it with node-gyp
swig_js/build/Release/wallycore.node: swig_js/swig_js_wrap.cxx
cd swig_js && node-gyp configure && node-gyp build

bin_PROGRAMS = swig_js/build/Release/wallycore.node

# FIXME: Run the test(s) as part of 'make check'

.PHONY: clean-swig-js
clean-swig-js:
$(AM_V_at)rm -f swig_js/swig_js_wrap.cxx
clean-local: clean-swig-js
endif # USE_SWIG_JS

if USE_SWIG_JAVA
noinst_LTLIBRARIES += libswig_java.la
Expand Down
2 changes: 1 addition & 1 deletion src/bip32.c
Original file line number Diff line number Diff line change
Expand Up @@ -634,7 +634,7 @@ int bip32_key_init_alloc(uint32_t version, uint32_t depth, uint32_t child_num,
}


#if defined (SWIG_JAVA_BUILD) || defined (SWIG_PYTHON_BUILD)
#if defined (SWIG_JAVA_BUILD) || defined (SWIG_PYTHON_BUILD) || defined (SWIG_JAVASCRIPT_BUILD)

/* Getters for ext_key values */

Expand Down
2 changes: 1 addition & 1 deletion src/bip32_int.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#ifndef LIBWALLY_CORE_BIP32_INT_H
#define LIBWALLY_CORE_BIP32_INT_H 1

#if defined(SWIG) || defined (SWIG_JAVA_BUILD) || defined (SWIG_PYTHON_BUILD)
#if defined(SWIG) || defined (SWIG_JAVA_BUILD) || defined (SWIG_PYTHON_BUILD) || defined(SWIG_JAVASCRIPT_BUILD)

WALLY_CORE_API int bip32_key_get_chain_code(const struct ext_key *key_in, unsigned char *bytes_out, size_t len);
WALLY_CORE_API int bip32_key_get_parent160(const struct ext_key *key_in, unsigned char *bytes_out, size_t len);
Expand Down
2 changes: 2 additions & 0 deletions src/scrypt/crypto_scrypt.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@
#endif

#include <sys/types.h>
#ifdef HAVE_SYS_MMAN_H
#include <sys/mman.h>
#endif

#include <errno.h>
#include <stdint.h>
Expand Down
63 changes: 63 additions & 0 deletions src/swig_js/binding.gyp
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
{
"targets": [
{
"target_name": "copy_srcs",
"copies": [
{
"files": [ "<(libwally_dir)/src/internal.h", "<(libwally_dir)/src/ccan/ccan/crypto/sha512/sha512.c", "<(libwally_dir)/src/ccan/ccan/crypto/ripemd160/ripemd160.c", "<(libwally_dir)/src/ccan/ccan/crypto/sha256/sha256.c", "<(libwally_dir)/src/secp256k1/src/secp256k1.c", "<(libwally_dir)/src/secp256k1/src/util.h", "<(libwally_dir)/src/internal.c", "<(libwally_dir)/src/base58.c", "<(libwally_dir)/src/aes.c", "<(libwally_dir)/src/scrypt.c", "<(libwally_dir)/src/pbkdf2.c", "<(libwally_dir)/src/hmac.c", "<(libwally_dir)/src/bip38.c", "<(libwally_dir)/src/sign.c", "<(libwally_dir)/src/bip32.c", "<(libwally_dir)/src/elements.c" ],
"destination": "src"
}
],
"conditions": [
[ 'OS=="win"', {
"copies+=": [
{
"files": [ "windows_config/config.h", "windows_config/libsecp256k1-config.h" ],
"destination": "src"
}
]
}],
]
},
{
"target_name": "deps",
"dependencies": [ "copy_srcs" ],
"sources": [ "src/aes.c", "src/base58.c", "src/bip38.c", "src/hmac.c", "src/internal.c", "src/pbkdf2.c", "src/ripemd160.c", "src/scrypt.c", "src/secp256k1.c", "src/sha256.c", "src/sha512.c", "src/sign.c", "src/bip32.c", "src/elements.c" ],
"defines": [ "SWIG_JAVASCRIPT_BUILD", "HAVE_CONFIG_H" ],
"include_dirs": [ "src", "<(libwally_dir)", "<(libwally_dir)/src", "<(libwally_dir)/src/secp256k1", "<(libwally_dir)/src/secp256k1/src", "<(libwally_dir)/src/ccan" ],
"type": "static_library"
},
{
"target_name": "wallycore",
"dependencies": [ "deps" ],
"sources": [ "nan_wrap.cc" ],
"include_dirs": [ "<(libwally_dir)/src", "<!(node -e \"require('nan')\")" ],
"defines": [ "SWIG_JAVASCRIPT_BUILD", "HAVE_CONFIG_H" ],
"conditions": [
[ 'OS=="win"', {
"libraries": [ "Release/deps.lib" ],
}],
[ 'OS!="win"', {
"libraries": [ "Release/deps.a" ],
}]
]
}
],
"conditions": [
[ 'OS=="mac"', {
"xcode_settings": {
"CLANG_CXX_LIBRARY": "libc++"
}
}],
[ 'OS=="win"', {
"variables": {
"libwally_dir": "<!(echo %LIBWALLY_DIR%)"
}
}],
[ 'OS!="win"', {
"variables": {
"libwally_dir": "<!(echo $LIBWALLY_DIR)"
}
}]
]
}
Empty file.
8 changes: 8 additions & 0 deletions src/swig_js/cordovaplugin/WallyModule/module.map
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
module Wally [system] {
header "wally_define_javascript_build.h"
header "../../../include/wally_crypto.h"
header "../../../include/wally_bip38.h"
header "../../../include/wally_bip32.h"
header "../../../bip32_int.h"
export *
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#define SWIG_JAVASCRIPT_BUILD 1
Loading

0 comments on commit 75c5c9d

Please sign in to comment.