asherah 1.2.0 → 1.2.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/binding.gyp ADDED
@@ -0,0 +1,14 @@
1
+ {
2
+ 'targets': [
3
+ {
4
+ 'target_name': 'napiasherah',
5
+ 'include_dirs': ["<!(node -p \"require('node-addon-api').include_dir\")"],
6
+ 'sources': [
7
+ 'lib/libasherah.h',
8
+ 'src/napiasherah.cc'
9
+ ],
10
+ 'defines': [ 'NAPI_DISABLE_CPP_EXCEPTIONS' ],
11
+ 'libraries': [ '../lib/libasherah.a' ]
12
+ }
13
+ ]
14
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "asherah",
3
- "version": "1.2.0",
3
+ "version": "1.2.3",
4
4
  "description": "Asherah envelope encryption and key rotation library",
5
5
  "main": "dist/asherah.js",
6
6
  "repository": {
@@ -9,7 +9,8 @@
9
9
  },
10
10
  "scripts": {
11
11
  "build": "npx tsc",
12
- "preinstall": "scripts/download-libraries.sh && node-gyp configure && node-gyp build",
12
+ "preinstall": "scripts/download-libraries.sh",
13
+ "install": "node-gyp rebuild",
13
14
  "test:mocha": "mocha",
14
15
  "test": "nyc npm run test:mocha",
15
16
  "posttest": "npm run lint",
@@ -19,8 +20,10 @@
19
20
  "author": "Jeremiah Gowdy <jeremiah@gowdy.me>",
20
21
  "license": "MIT",
21
22
  "files": [
23
+ "binding.gyp",
24
+ "src/napiasherah.cc",
22
25
  "dist/asherah.d.ts",
23
- "scripts/download-binaries.sh",
26
+ "scripts/download-libraries.sh",
24
27
  "build/Release/napi-asherah.node",
25
28
  "SHA256SUMS",
26
29
  "SHA256SUMS-darwin",
@@ -0,0 +1,55 @@
1
+ #!/bin/bash
2
+
3
+ echo "Downloading Asherah libraries"
4
+
5
+ source .asherah-version
6
+
7
+ rm -rf lib
8
+ mkdir lib
9
+ cd lib || exit 1
10
+
11
+ OS=$(uname)
12
+ MACHINE=$(uname -m)
13
+
14
+ if [[ "${OS}" == 'Linux' ]]; then
15
+ if [[ ${MACHINE} == 'x86_64' ]]; then
16
+ echo "Linux x64"
17
+ ARCHIVE=libasherah-x64.a
18
+ HEADER=libasherah-x64-archive.h
19
+ SUMS=../SHA256SUMS
20
+ elif [[ ${MACHINE} == 'aarch64' ]]; then
21
+ echo "Linux arm64"
22
+ ARCHIVE=libasherah-arm64.a
23
+ HEADER=libasherah-arm64-archive.h
24
+ SUMS=../SHA256SUMS
25
+ else
26
+ echo "Unsupported CPU architecture"
27
+ exit 1
28
+ fi
29
+ elif [[ ${OS} == 'Darwin' ]]; then
30
+ if [[ ${MACHINE} == 'x86_64' ]]; then
31
+ echo "MacOS x64"
32
+ ARCHIVE=libasherah-darwin-x64.a
33
+ HEADER=libasherah-darwin-x64-archive.h
34
+ SUMS=../SHA256SUMS-darwin
35
+ elif [[ ${MACHINE} == 'arm64' ]]; then
36
+ echo "MacOS arm64"
37
+ ARCHIVE=libasherah-darwin-arm64.a
38
+ HEADER=libasherah-darwin-arm64-archive.h
39
+ SUMS=../SHA256SUMS-darwin
40
+ else
41
+ echo "Unsupported CPU architecture"
42
+ exit 1
43
+ fi
44
+ else
45
+ echo "Unsupported operating system"
46
+ exit 1
47
+ fi
48
+
49
+ curl -s -L --fail -O --retry 999 --retry-max-time 0 "https://github.com/godaddy/asherah-cobhan/releases/download/${ASHERAH_VERSION}/${ARCHIVE}" || echo "Failed to download ${ASHERAH_VERSION}/${ARCHIVE}"
50
+ curl -s -L --fail -O --retry 999 --retry-max-time 0 "https://github.com/godaddy/asherah-cobhan/releases/download/${ASHERAH_VERSION}/${HEADER}" || echo "Failed to download ${ASHERAH_VERSION}/${HEADER}"
51
+ grep -e "${ARCHIVE}" -e "${HEADER}" "${SUMS}" > ./SHA256SUM
52
+ #shasum -a 256 -c ./SHA256SUM || (echo 'SHA256 mismatch!' ; rm -f ./*.a ./*.h ; exit 1)
53
+
54
+ mv "${ARCHIVE}" libasherah.a
55
+ mv "${HEADER}" libasherah.h
@@ -0,0 +1,87 @@
1
+ #include <napi.h>
2
+ #include "../lib/libasherah.h"
3
+
4
+ //extern GoInt32 SetupJson(void* configJson);
5
+ Napi::Value Napi_SetupJson(const Napi::CallbackInfo& info) {
6
+ Napi::Env env = info.Env();
7
+
8
+ if (info.Length() < 1) {
9
+ Napi::TypeError::New(env, "Wrong number of arguments")
10
+ .ThrowAsJavaScriptException();
11
+ return env.Null();
12
+ }
13
+
14
+ Napi::Buffer<unsigned char> configJson = info[0].As<Napi::Buffer<unsigned char>>();
15
+
16
+ GoInt32 result = SetupJson(configJson.Data());
17
+
18
+ Napi::Number num = Napi::Number::New(env, result);
19
+ return num;
20
+ }
21
+
22
+ //extern GoInt32 EncryptToJson(void* partitionIdPtr, void* dataPtr, void* jsonPtr);
23
+ Napi::Value Napi_EncryptToJson(const Napi::CallbackInfo& info) {
24
+ Napi::Env env = info.Env();
25
+
26
+ if (info.Length() < 3) {
27
+ Napi::TypeError::New(env, "Wrong number of arguments")
28
+ .ThrowAsJavaScriptException();
29
+ return env.Null();
30
+ }
31
+
32
+ if (!info[0].IsBuffer() || !info[1].IsBuffer() || !info[2].IsBuffer()) {
33
+ Napi::TypeError::New(env, "Wrong arguments").ThrowAsJavaScriptException();
34
+ return env.Null();
35
+ }
36
+
37
+ Napi::Buffer<unsigned char> partitionId = info[0].As<Napi::Buffer<unsigned char>>();
38
+ Napi::Buffer<unsigned char> data = info[1].As<Napi::Buffer<unsigned char>>();
39
+ Napi::Buffer<unsigned char> outputJson = info[2].As<Napi::Buffer<unsigned char>>();
40
+
41
+ GoInt32 result = EncryptToJson(partitionId.Data(), data.Data(), outputJson.Data());
42
+
43
+ Napi::Number num = Napi::Number::New(env, result);
44
+ return num;
45
+ }
46
+
47
+ //extern GoInt32 DecryptFromJson(void* partitionIdPtr, void* jsonPtr, void* dataPtr);
48
+ Napi::Value Napi_DecryptFromJson(const Napi::CallbackInfo& info) {
49
+ Napi::Env env = info.Env();
50
+
51
+ if (info.Length() < 3) {
52
+ Napi::TypeError::New(env, "Wrong number of arguments")
53
+ .ThrowAsJavaScriptException();
54
+ return env.Null();
55
+ }
56
+
57
+ if (!info[0].IsBuffer() || !info[1].IsBuffer() || !info[2].IsBuffer()) {
58
+ Napi::TypeError::New(env, "Wrong arguments").ThrowAsJavaScriptException();
59
+ return env.Null();
60
+ }
61
+
62
+ Napi::Buffer<unsigned char> partitionId = info[0].As<Napi::Buffer<unsigned char>>();
63
+ Napi::Buffer<unsigned char> inputJson = info[1].As<Napi::Buffer<unsigned char>>();
64
+ Napi::Buffer<unsigned char> outputData = info[2].As<Napi::Buffer<unsigned char>>();
65
+
66
+ GoInt32 result = DecryptFromJson(partitionId.Data(), inputJson.Data(), outputData.Data());
67
+
68
+ Napi::Number num = Napi::Number::New(env, result);
69
+ return num;
70
+ }
71
+
72
+ //extern void Shutdown();
73
+ Napi::Value Napi_Shutdown(const Napi::CallbackInfo& info) {
74
+ Napi::Env env = info.Env();
75
+ Shutdown();
76
+ return env.Null();
77
+ }
78
+
79
+ Napi::Object Init(Napi::Env env, Napi::Object exports) {
80
+ exports.Set(Napi::String::New(env, "Napi_SetupJson"), Napi::Function::New(env, Napi_SetupJson));
81
+ exports.Set(Napi::String::New(env, "Napi_EncryptToJson"), Napi::Function::New(env, Napi_EncryptToJson));
82
+ exports.Set(Napi::String::New(env, "Napi_DecryptFromJson"), Napi::Function::New(env, Napi_DecryptFromJson));
83
+ exports.Set(Napi::String::New(env, "Napi_Shutdown"), Napi::Function::New(env, Napi_Shutdown));
84
+ return exports;
85
+ }
86
+
87
+ NODE_API_MODULE(napiasherah, Init)