Skip to content

Commit

Permalink
update for support node 12 (#143)
Browse files Browse the repository at this point in the history
* update travis config

* add lock files to .gitignore

* remove outdated code

* fix code for node12

* update secp256k1: e34ceb3 => b19c000

* update dev dependencies

* update dependencies

* rollback karma dev deps

* adjust appveyor
  • Loading branch information
fanatid authored May 8, 2019
1 parent fd7500c commit 16a1a9a
Show file tree
Hide file tree
Showing 9 changed files with 54 additions and 24 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@ build
node_modules

npm-debug.log
package-lock.json
yarn.lock
5 changes: 3 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ node_js:
- "7"
- "8"
- "9"
- "10"
- "11"
- "12"
addons:
apt:
sources:
Expand All @@ -26,7 +27,7 @@ matrix:
fast_finish: true
include:
- os: linux
node_js: "10"
node_js: "12"
env: TEST_SUITE=lint
before_install:
- if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then export CXX=g++-6; fi
Expand Down
2 changes: 1 addition & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ platform:
install:
- git submodule update --init --recursive
- ps: Install-Product node $env:nodejs_version $env:platform
- npm --global install npm@latest
# - npm --global install npm@latest
- set PATH=%APPDATA%\npm;%APPVEYOR_BUILD_FOLDER%\node_modules\.bin;%PATH%
- npm install
- for /f %%i in ('node -v') do set exact_nodejs_version=%%i
Expand Down
3 changes: 3 additions & 0 deletions binding.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@
"-Wno-nonnull-compare",
"-Wno-uninitialized",
"-Wno-unused-function",
# "-Wno-cast-function-type",
# "-Wno-unused-result",
# "-Wno-deprecated-declarations",
"-Wextra"
],
"cflags_cc+": [
Expand Down
30 changes: 15 additions & 15 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,29 +47,29 @@
"unit": "tape test/index.js"
},
"dependencies": {
"bindings": "^1.2.1",
"bip66": "^1.1.3",
"bn.js": "^4.11.3",
"create-hash": "^1.1.2",
"bindings": "^1.5.0",
"bip66": "^1.1.5",
"bn.js": "^4.11.8",
"create-hash": "^1.2.0",
"drbg.js": "^1.0.1",
"elliptic": "^6.2.3",
"nan": "^2.2.1",
"safe-buffer": "^5.1.0"
"elliptic": "^6.4.1",
"nan": "^2.13.2",
"safe-buffer": "^5.1.2"
},
"devDependencies": {
"bignum": "^0.13.0",
"browserify": "^14.4.0",
"bignum": "https://github.com/fanatid/node-bignum#e688fd40dff43b03480bcdb5e4c099ee9ac27102",
"browserify": "^16.2.3",
"karma": "^1.3.0",
"karma-browserify": "^5.0.4",
"karma-chrome-launcher": "^2.0.0",
"karma-detect-browsers": "^2.1.0",
"karma-chrome-launcher": "^2.2.0",
"karma-detect-browsers": "^2.3.3",
"karma-env-preprocessor": "^0.1.1",
"karma-firefox-launcher": "^1.0.0",
"karma-tap": "^3.1.1",
"node-gyp": "^3.3.1",
"nyc": "^11.0.2",
"standard": "*",
"tape": "^4.5.1",
"node-gyp": "^4.0.0",
"nyc": "^14.1.0",
"standard": "^12.0.1",
"tape": "^4.10.1",
"xorshift.js": "^1.0.3"
},
"engines": {
Expand Down
19 changes: 16 additions & 3 deletions src/ecdsa.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ int nonce_function_custom(unsigned char *nonce32, const unsigned char *msg32, co
Nan::New(counter)
};

#if (NODE_MODULE_VERSION > NODE_0_10_MODULE_VERSION)
v8::Isolate *isolate = v8::Isolate::GetCurrent();
v8::Local<v8::Value> result = noncefn_callback->Call(isolate->GetCurrentContext()->Global(), 5, argv);
#if (NODE_MODULE_VERSION > NODE_11_0_MODULE_VERSION)
v8::Local<v8::Value> result = noncefn_callback->Call(isolate->GetCurrentContext(), isolate->GetCurrentContext()->Global(), 5, argv).ToLocalChecked();
#else
v8::Local<v8::Value> result = noncefn_callback->Call(v8::Context::GetCurrent()->Global(), 5, argv);
v8::Local<v8::Value> result = noncefn_callback->Call(isolate->GetCurrentContext()->Global(), 5, argv);
#endif

if (!node::Buffer::HasInstance(result) || node::Buffer::Length(result) != 32) {
Expand Down Expand Up @@ -52,14 +52,22 @@ NAN_METHOD(sign) {
if (!options->IsUndefined()) {
CHECK_TYPE_OBJECT(options, OPTIONS_TYPE_INVALID);

#if (NODE_MODULE_VERSION > NODE_11_0_MODULE_VERSION)
v8::Local<v8::Value> data_value = options->Get(info.GetIsolate()->GetCurrentContext(), Nan::New<v8::String>("data").ToLocalChecked()).ToLocalChecked();
#else
v8::Local<v8::Value> data_value = options->Get(Nan::New<v8::String>("data").ToLocalChecked());
#endif
if (!data_value->IsUndefined()) {
CHECK_TYPE_BUFFER(data_value, OPTIONS_DATA_TYPE_INVALID);
CHECK_BUFFER_LENGTH(data_value, 32, OPTIONS_DATA_LENGTH_INVALID);
data = (void*) node::Buffer::Data(data_value);
}

#if (NODE_MODULE_VERSION > NODE_11_0_MODULE_VERSION)
noncefn_callback = v8::Local<v8::Function>::Cast(options->Get(info.GetIsolate()->GetCurrentContext(), Nan::New<v8::String>("noncefn").ToLocalChecked()).ToLocalChecked());
#else
noncefn_callback = v8::Local<v8::Function>::Cast(options->Get(Nan::New<v8::String>("noncefn").ToLocalChecked()));
#endif
if (!noncefn_callback->IsUndefined()) {
CHECK_TYPE_FUNCTION(noncefn_callback, OPTIONS_NONCEFN_TYPE_INVALID);
noncefn = nonce_function_custom;
Expand All @@ -76,8 +84,13 @@ NAN_METHOD(sign) {
secp256k1_ecdsa_recoverable_signature_serialize_compact(secp256k1ctx, &output[0], &recid, &sig);

v8::Local<v8::Object> obj = Nan::New<v8::Object>();
#if (NODE_MODULE_VERSION > NODE_11_0_MODULE_VERSION)
obj->Set(info.GetIsolate()->GetCurrentContext(), Nan::New<v8::String>("signature").ToLocalChecked(), COPY_BUFFER(&output[0], 64));
obj->Set(info.GetIsolate()->GetCurrentContext(), Nan::New<v8::String>("recovery").ToLocalChecked(), Nan::New<v8::Number>(recid));
#else
obj->Set(Nan::New<v8::String>("signature").ToLocalChecked(), COPY_BUFFER(&output[0], 64));
obj->Set(Nan::New<v8::String>("recovery").ToLocalChecked(), Nan::New<v8::Number>(recid));
#endif
info.GetReturnValue().Set(obj);
}

Expand Down
4 changes: 4 additions & 0 deletions src/publickey.cc
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,11 @@ NAN_METHOD(publicKeyCombine) {
std::unique_ptr<secp256k1_pubkey[]> public_keys(new secp256k1_pubkey[input_buffers->Length()]);
std::unique_ptr<secp256k1_pubkey*[]> ins(new secp256k1_pubkey*[input_buffers->Length()]);
for (unsigned int i = 0; i < input_buffers->Length(); ++i) {
#if (NODE_MODULE_VERSION > NODE_11_0_MODULE_VERSION)
v8::Local<v8::Object> public_key_buffer = v8::Local<v8::Object>::Cast(input_buffers->Get(info.GetIsolate()->GetCurrentContext(), i).ToLocalChecked());
#else
v8::Local<v8::Object> public_key_buffer = v8::Local<v8::Object>::Cast(input_buffers->Get(i));
#endif
CHECK_TYPE_BUFFER(public_key_buffer, EC_PUBLIC_KEY_TYPE_INVALID);
CHECK_BUFFER_LENGTH2(public_key_buffer, 33, 65, EC_PUBLIC_KEY_LENGTH_INVALID);

Expand Down
11 changes: 9 additions & 2 deletions src/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,18 @@

#define COPY_BUFFER(data, datalen) Nan::CopyBuffer((const char*) data, (uint32_t) datalen).ToLocalChecked()

#if (NODE_MODULE_VERSION >= NODE_7_0_MODULE_VERSION)
#if (NODE_MODULE_VERSION > NODE_11_0_MODULE_VERSION)
#define UPDATE_COMPRESSED_VALUE(compressed, value, v_true, v_false) { \
if (!value->IsUndefined()) { \
CHECK_TYPE_BOOLEAN(value, COMPRESSED_TYPE_INVALID); \
compressed = value->BooleanValue(info.GetIsolate()) ? v_true : v_false; \
} \
}
#elif (NODE_MODULE_VERSION >= NODE_7_0_MODULE_VERSION)
#define UPDATE_COMPRESSED_VALUE(compressed, value, v_true, v_false) { \
if (!value->IsUndefined()) { \
CHECK_TYPE_BOOLEAN(value, COMPRESSED_TYPE_INVALID); \
compressed = value->BooleanValue(info.GetIsolate()->GetCurrentContext()).ToChecked() ? v_true : v_false; \
compressed = value->BooleanValue(info.GetIsolate()->GetCurrentContext()).ToChecked() ? v_true : v_false; \
} \
}
#else
Expand Down

0 comments on commit 16a1a9a

Please sign in to comment.