Skip to content

Commit 16a1a9a

Browse files
authored
update for support node 12 (#143)
* 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
1 parent fd7500c commit 16a1a9a

9 files changed

+54
-24
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,5 @@ build
44
node_modules
55

66
npm-debug.log
7+
package-lock.json
8+
yarn.lock

.travis.yml

+3-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ node_js:
1010
- "7"
1111
- "8"
1212
- "9"
13-
- "10"
13+
- "11"
14+
- "12"
1415
addons:
1516
apt:
1617
sources:
@@ -26,7 +27,7 @@ matrix:
2627
fast_finish: true
2728
include:
2829
- os: linux
29-
node_js: "10"
30+
node_js: "12"
3031
env: TEST_SUITE=lint
3132
before_install:
3233
- if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then export CXX=g++-6; fi

appveyor.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ platform:
1414
install:
1515
- git submodule update --init --recursive
1616
- ps: Install-Product node $env:nodejs_version $env:platform
17-
- npm --global install npm@latest
17+
# - npm --global install npm@latest
1818
- set PATH=%APPDATA%\npm;%APPVEYOR_BUILD_FOLDER%\node_modules\.bin;%PATH%
1919
- npm install
2020
- for /f %%i in ('node -v') do set exact_nodejs_version=%%i

binding.gyp

+3
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@
4141
"-Wno-nonnull-compare",
4242
"-Wno-uninitialized",
4343
"-Wno-unused-function",
44+
# "-Wno-cast-function-type",
45+
# "-Wno-unused-result",
46+
# "-Wno-deprecated-declarations",
4447
"-Wextra"
4548
],
4649
"cflags_cc+": [

package.json

+15-15
Original file line numberDiff line numberDiff line change
@@ -47,29 +47,29 @@
4747
"unit": "tape test/index.js"
4848
},
4949
"dependencies": {
50-
"bindings": "^1.2.1",
51-
"bip66": "^1.1.3",
52-
"bn.js": "^4.11.3",
53-
"create-hash": "^1.1.2",
50+
"bindings": "^1.5.0",
51+
"bip66": "^1.1.5",
52+
"bn.js": "^4.11.8",
53+
"create-hash": "^1.2.0",
5454
"drbg.js": "^1.0.1",
55-
"elliptic": "^6.2.3",
56-
"nan": "^2.2.1",
57-
"safe-buffer": "^5.1.0"
55+
"elliptic": "^6.4.1",
56+
"nan": "^2.13.2",
57+
"safe-buffer": "^5.1.2"
5858
},
5959
"devDependencies": {
60-
"bignum": "^0.13.0",
61-
"browserify": "^14.4.0",
60+
"bignum": "https://github.com/fanatid/node-bignum#e688fd40dff43b03480bcdb5e4c099ee9ac27102",
61+
"browserify": "^16.2.3",
6262
"karma": "^1.3.0",
6363
"karma-browserify": "^5.0.4",
64-
"karma-chrome-launcher": "^2.0.0",
65-
"karma-detect-browsers": "^2.1.0",
64+
"karma-chrome-launcher": "^2.2.0",
65+
"karma-detect-browsers": "^2.3.3",
6666
"karma-env-preprocessor": "^0.1.1",
6767
"karma-firefox-launcher": "^1.0.0",
6868
"karma-tap": "^3.1.1",
69-
"node-gyp": "^3.3.1",
70-
"nyc": "^11.0.2",
71-
"standard": "*",
72-
"tape": "^4.5.1",
69+
"node-gyp": "^4.0.0",
70+
"nyc": "^14.1.0",
71+
"standard": "^12.0.1",
72+
"tape": "^4.10.1",
7373
"xorshift.js": "^1.0.3"
7474
},
7575
"engines": {

src/ecdsa.cc

+16-3
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@ int nonce_function_custom(unsigned char *nonce32, const unsigned char *msg32, co
1818
Nan::New(counter)
1919
};
2020

21-
#if (NODE_MODULE_VERSION > NODE_0_10_MODULE_VERSION)
2221
v8::Isolate *isolate = v8::Isolate::GetCurrent();
23-
v8::Local<v8::Value> result = noncefn_callback->Call(isolate->GetCurrentContext()->Global(), 5, argv);
22+
#if (NODE_MODULE_VERSION > NODE_11_0_MODULE_VERSION)
23+
v8::Local<v8::Value> result = noncefn_callback->Call(isolate->GetCurrentContext(), isolate->GetCurrentContext()->Global(), 5, argv).ToLocalChecked();
2424
#else
25-
v8::Local<v8::Value> result = noncefn_callback->Call(v8::Context::GetCurrent()->Global(), 5, argv);
25+
v8::Local<v8::Value> result = noncefn_callback->Call(isolate->GetCurrentContext()->Global(), 5, argv);
2626
#endif
2727

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

55+
#if (NODE_MODULE_VERSION > NODE_11_0_MODULE_VERSION)
56+
v8::Local<v8::Value> data_value = options->Get(info.GetIsolate()->GetCurrentContext(), Nan::New<v8::String>("data").ToLocalChecked()).ToLocalChecked();
57+
#else
5558
v8::Local<v8::Value> data_value = options->Get(Nan::New<v8::String>("data").ToLocalChecked());
59+
#endif
5660
if (!data_value->IsUndefined()) {
5761
CHECK_TYPE_BUFFER(data_value, OPTIONS_DATA_TYPE_INVALID);
5862
CHECK_BUFFER_LENGTH(data_value, 32, OPTIONS_DATA_LENGTH_INVALID);
5963
data = (void*) node::Buffer::Data(data_value);
6064
}
6165

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

7886
v8::Local<v8::Object> obj = Nan::New<v8::Object>();
87+
#if (NODE_MODULE_VERSION > NODE_11_0_MODULE_VERSION)
88+
obj->Set(info.GetIsolate()->GetCurrentContext(), Nan::New<v8::String>("signature").ToLocalChecked(), COPY_BUFFER(&output[0], 64));
89+
obj->Set(info.GetIsolate()->GetCurrentContext(), Nan::New<v8::String>("recovery").ToLocalChecked(), Nan::New<v8::Number>(recid));
90+
#else
7991
obj->Set(Nan::New<v8::String>("signature").ToLocalChecked(), COPY_BUFFER(&output[0], 64));
8092
obj->Set(Nan::New<v8::String>("recovery").ToLocalChecked(), Nan::New<v8::Number>(recid));
93+
#endif
8194
info.GetReturnValue().Set(obj);
8295
}
8396

src/publickey.cc

+4
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,11 @@ NAN_METHOD(publicKeyCombine) {
143143
std::unique_ptr<secp256k1_pubkey[]> public_keys(new secp256k1_pubkey[input_buffers->Length()]);
144144
std::unique_ptr<secp256k1_pubkey*[]> ins(new secp256k1_pubkey*[input_buffers->Length()]);
145145
for (unsigned int i = 0; i < input_buffers->Length(); ++i) {
146+
#if (NODE_MODULE_VERSION > NODE_11_0_MODULE_VERSION)
147+
v8::Local<v8::Object> public_key_buffer = v8::Local<v8::Object>::Cast(input_buffers->Get(info.GetIsolate()->GetCurrentContext(), i).ToLocalChecked());
148+
#else
146149
v8::Local<v8::Object> public_key_buffer = v8::Local<v8::Object>::Cast(input_buffers->Get(i));
150+
#endif
147151
CHECK_TYPE_BUFFER(public_key_buffer, EC_PUBLIC_KEY_TYPE_INVALID);
148152
CHECK_BUFFER_LENGTH2(public_key_buffer, 33, 65, EC_PUBLIC_KEY_LENGTH_INVALID);
149153

src/util.h

+9-2
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,18 @@
88

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

11-
#if (NODE_MODULE_VERSION >= NODE_7_0_MODULE_VERSION)
11+
#if (NODE_MODULE_VERSION > NODE_11_0_MODULE_VERSION)
12+
#define UPDATE_COMPRESSED_VALUE(compressed, value, v_true, v_false) { \
13+
if (!value->IsUndefined()) { \
14+
CHECK_TYPE_BOOLEAN(value, COMPRESSED_TYPE_INVALID); \
15+
compressed = value->BooleanValue(info.GetIsolate()) ? v_true : v_false; \
16+
} \
17+
}
18+
#elif (NODE_MODULE_VERSION >= NODE_7_0_MODULE_VERSION)
1219
#define UPDATE_COMPRESSED_VALUE(compressed, value, v_true, v_false) { \
1320
if (!value->IsUndefined()) { \
1421
CHECK_TYPE_BOOLEAN(value, COMPRESSED_TYPE_INVALID); \
15-
compressed = value->BooleanValue(info.GetIsolate()->GetCurrentContext()).ToChecked() ? v_true : v_false; \
22+
compressed = value->BooleanValue(info.GetIsolate()->GetCurrentContext()).ToChecked() ? v_true : v_false; \
1623
} \
1724
}
1825
#else

0 commit comments

Comments
 (0)