asherah 3.0.16 → 4.0.0-beta.2
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/README.md +12 -171
- package/index.d.ts +102 -0
- package/npm/index.js +188 -0
- package/package.json +23 -78
- package/.asherah-version +0 -1
- package/LICENSE +0 -21
- package/SHA256SUMS +0 -12
- package/SHA256SUMS-darwin +0 -12
- package/binding.gyp +0 -36
- package/scripts/build.sh +0 -16
- package/scripts/download-libraries.sh +0 -322
- package/src/asherah.cc +0 -792
- package/src/asherah.d.ts +0 -65
- package/src/asherah_async_worker.h +0 -60
- package/src/cobhan_buffer.h +0 -260
- package/src/cobhan_buffer_napi.h +0 -218
- package/src/hints.h +0 -7
- package/src/logging.h +0 -49
- package/src/logging_napi.cc +0 -115
- package/src/logging_napi.h +0 -41
- package/src/logging_stderr.cc +0 -60
- package/src/logging_stderr.h +0 -23
- package/src/napi_utils.h +0 -164
- package/src/scoped_allocate.h +0 -50
package/scripts/build.sh
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
#!/bin/bash
|
|
2
|
-
|
|
3
|
-
set -e
|
|
4
|
-
|
|
5
|
-
mkdir -p dist/
|
|
6
|
-
|
|
7
|
-
# Check if USE_CMAKE is set to 1
|
|
8
|
-
if [ "$USE_CMAKE" = "1" ]; then
|
|
9
|
-
# Run CMake commands
|
|
10
|
-
(cmake . && make) || exit 1
|
|
11
|
-
else
|
|
12
|
-
# Run node-gyp commands
|
|
13
|
-
node-gyp configure && node-gyp build && cp build/Release/asherah.node dist/asherah.node
|
|
14
|
-
fi
|
|
15
|
-
|
|
16
|
-
cp src/asherah.d.ts dist/asherah.d.ts
|
|
@@ -1,322 +0,0 @@
|
|
|
1
|
-
#!/bin/bash
|
|
2
|
-
|
|
3
|
-
set -e # Exit on any command failure
|
|
4
|
-
|
|
5
|
-
# Global Constants
|
|
6
|
-
CHECK_INTERVAL_SECONDS=$((5 * 60)) # 5 minutes
|
|
7
|
-
MAX_DOWNLOAD_RETRIES=3
|
|
8
|
-
MAX_FILE_DOWNLOAD_RETRIES=5
|
|
9
|
-
DOWNLOAD_TIMEOUT=60 # 1 minute per file
|
|
10
|
-
|
|
11
|
-
# Function to check if a specific file download is necessary
|
|
12
|
-
function check_download_required {
|
|
13
|
-
local file=$1
|
|
14
|
-
local no_cache=$2
|
|
15
|
-
local check_interval_seconds=$3
|
|
16
|
-
local etag_file="${file}.etag"
|
|
17
|
-
|
|
18
|
-
# If the file does not exist or the .etag file is missing, download is required
|
|
19
|
-
if [[ ! -f "$file" ]]; then
|
|
20
|
-
echo "${file} does not exist"
|
|
21
|
-
return 0 # (download required)
|
|
22
|
-
else
|
|
23
|
-
echo "${file} exists"
|
|
24
|
-
fi
|
|
25
|
-
|
|
26
|
-
# If the file does not exist or the .etag file is missing, download is required
|
|
27
|
-
if [[ ! -f "$etag_file" ]]; then
|
|
28
|
-
echo "${etag_file} does not exist"
|
|
29
|
-
return 0 # (download required)
|
|
30
|
-
fi
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
# If no-cache is passed, we ignore the modified date of the .etag files
|
|
34
|
-
if [[ "$no_cache" == true ]]; then
|
|
35
|
-
return 0 # (download required)
|
|
36
|
-
fi
|
|
37
|
-
|
|
38
|
-
# Check if the .etag file is older than the interval
|
|
39
|
-
if [[ "$OSTYPE" == "darwin"* ]]; then
|
|
40
|
-
# macOS uses 'stat -f'
|
|
41
|
-
last_check=$(stat -f %m "$etag_file")
|
|
42
|
-
else
|
|
43
|
-
# Linux uses 'stat -c'
|
|
44
|
-
last_check=$(stat -c %Y "$etag_file")
|
|
45
|
-
fi
|
|
46
|
-
|
|
47
|
-
current_time=$(date +%s)
|
|
48
|
-
elapsed_time=$((current_time - last_check))
|
|
49
|
-
|
|
50
|
-
if (( elapsed_time > check_interval_seconds )); then
|
|
51
|
-
return 0 # (download required)
|
|
52
|
-
fi
|
|
53
|
-
|
|
54
|
-
return 1 # (download not required)
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
# Function to download a file with retry logic
|
|
58
|
-
function download_file {
|
|
59
|
-
local url=$1
|
|
60
|
-
local file=$2
|
|
61
|
-
local etag_file="${file}.etag"
|
|
62
|
-
local retry_count=0
|
|
63
|
-
local backoff=1
|
|
64
|
-
|
|
65
|
-
while [[ $retry_count -lt $MAX_FILE_DOWNLOAD_RETRIES ]]; do
|
|
66
|
-
# Use --show-error to display errors even with -s (silent progress)
|
|
67
|
-
# Add connection and max-time timeouts to prevent hanging
|
|
68
|
-
if curl -sS -L --fail \
|
|
69
|
-
--connect-timeout 30 \
|
|
70
|
-
--max-time "$DOWNLOAD_TIMEOUT" \
|
|
71
|
-
--retry 2 \
|
|
72
|
-
--retry-delay 2 \
|
|
73
|
-
--etag-save "$etag_file" \
|
|
74
|
-
--etag-compare "$etag_file" \
|
|
75
|
-
-O "$url"; then
|
|
76
|
-
# Explicitly touch the etag file to update its modification time only if successful
|
|
77
|
-
touch "$etag_file"
|
|
78
|
-
return 0
|
|
79
|
-
fi
|
|
80
|
-
|
|
81
|
-
((retry_count++))
|
|
82
|
-
|
|
83
|
-
if [[ $retry_count -lt $MAX_FILE_DOWNLOAD_RETRIES ]]; then
|
|
84
|
-
echo "Download attempt $retry_count failed for $url, retrying in ${backoff}s..." >&2
|
|
85
|
-
sleep "$backoff"
|
|
86
|
-
# Exponential backoff with a cap at 16 seconds
|
|
87
|
-
backoff=$((backoff * 2))
|
|
88
|
-
if [[ $backoff -gt 16 ]]; then
|
|
89
|
-
backoff=16
|
|
90
|
-
fi
|
|
91
|
-
fi
|
|
92
|
-
done
|
|
93
|
-
|
|
94
|
-
echo "Failed to download $url after $MAX_FILE_DOWNLOAD_RETRIES attempts" >&2
|
|
95
|
-
return 1
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
# Function to verify checksums
|
|
99
|
-
function verify_checksums {
|
|
100
|
-
local archive=$1
|
|
101
|
-
local header=$2
|
|
102
|
-
local warmup=$3
|
|
103
|
-
local sums=$4
|
|
104
|
-
|
|
105
|
-
# Determine the available SHA hashing utility
|
|
106
|
-
if command -v sha256sum &> /dev/null; then
|
|
107
|
-
sha_cmd="sha256sum"
|
|
108
|
-
elif command -v shasum &> /dev/null; then
|
|
109
|
-
sha_cmd="shasum -a 256"
|
|
110
|
-
else
|
|
111
|
-
echo "Error: Neither sha256sum nor shasum is available on this system." >&2
|
|
112
|
-
exit 1 # Exit since this is fatal
|
|
113
|
-
fi
|
|
114
|
-
|
|
115
|
-
if [[ ! -f "${sums}" ]]; then
|
|
116
|
-
echo "Error: Checksum file '${sums}' does not exist." >&2
|
|
117
|
-
rm -f ./*.a ./*.h ./*.etag
|
|
118
|
-
return 1
|
|
119
|
-
fi
|
|
120
|
-
|
|
121
|
-
# Filter the relevant checksums and verify they are not empty
|
|
122
|
-
checksums=$(grep -e "${archive}" -e "${header}" -e "${warmup}" "${sums}")
|
|
123
|
-
if [[ -z "$checksums" ]]; then
|
|
124
|
-
echo "Error: No matching checksums found for ${archive}, ${header}, or ${warmup} in ${sums}." >&2
|
|
125
|
-
return 1
|
|
126
|
-
fi
|
|
127
|
-
|
|
128
|
-
echo "$checksums" > ./SHA256SUM # Return value
|
|
129
|
-
|
|
130
|
-
if ! $sha_cmd -c ./SHA256SUM; then
|
|
131
|
-
echo 'SHA256 mismatch!' >&2
|
|
132
|
-
rm -f ./*.a ./*.h
|
|
133
|
-
return 1
|
|
134
|
-
fi
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
# Function to copy library and header files
|
|
138
|
-
function copy_files {
|
|
139
|
-
local archive=$1
|
|
140
|
-
local header=$2
|
|
141
|
-
|
|
142
|
-
if [[ ! -f "${archive}" ]]; then
|
|
143
|
-
echo "Error: Source archive file '${archive}' does not exist." >&2
|
|
144
|
-
exit 1
|
|
145
|
-
fi
|
|
146
|
-
|
|
147
|
-
if [[ ! -f "${header}" ]]; then
|
|
148
|
-
echo "Error: Source header file '${header}' does not exist." >&2
|
|
149
|
-
exit 1
|
|
150
|
-
fi
|
|
151
|
-
|
|
152
|
-
if ! cp -f "${archive}" libasherah.a; then
|
|
153
|
-
echo "Error: Failed to copy archive file '${archive}' to 'libasherah.a'." >&2
|
|
154
|
-
exit 1
|
|
155
|
-
fi
|
|
156
|
-
|
|
157
|
-
if ! cp -f "${header}" libasherah.h; then
|
|
158
|
-
echo "Error: Failed to copy header file '${header}' to 'libasherah.h'." >&2
|
|
159
|
-
exit 1
|
|
160
|
-
fi
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
# Function to detect OS and CPU architecture
|
|
164
|
-
function detect_os_and_cpu {
|
|
165
|
-
OS=$(uname)
|
|
166
|
-
MACHINE=$(uname -m)
|
|
167
|
-
|
|
168
|
-
#echo "Detected OS: ${OS}"
|
|
169
|
-
#echo "Detected CPU architecture: ${MACHINE}"
|
|
170
|
-
|
|
171
|
-
if [[ "${OS}" == 'Linux' ]]; then
|
|
172
|
-
if [[ ${MACHINE} == 'x86_64' ]]; then
|
|
173
|
-
#echo "Using Asherah libraries for Linux x86_64"
|
|
174
|
-
ARCHIVE="libasherah-x64.a"
|
|
175
|
-
HEADER="libasherah-x64-archive.h"
|
|
176
|
-
WARMUP="go-warmup-linux-x64.so"
|
|
177
|
-
SUMS="SHA256SUMS"
|
|
178
|
-
elif [[ ${MACHINE} == 'aarch64' ]]; then
|
|
179
|
-
#echo "Using Asherah libraries for Linux aarch64"
|
|
180
|
-
ARCHIVE="libasherah-arm64.a"
|
|
181
|
-
HEADER="libasherah-arm64-archive.h"
|
|
182
|
-
WARMUP="go-warmup-linux-arm64.so"
|
|
183
|
-
SUMS="SHA256SUMS"
|
|
184
|
-
else
|
|
185
|
-
#echo "Unsupported CPU architecture: ${MACHINE}" >&2
|
|
186
|
-
exit 1
|
|
187
|
-
fi
|
|
188
|
-
elif [[ "${OS}" == 'Darwin' ]]; then
|
|
189
|
-
if [[ ${MACHINE} == 'x86_64' ]]; then
|
|
190
|
-
#echo "Using Asherah libraries for MacOS x86_64"
|
|
191
|
-
ARCHIVE="libasherah-darwin-x64.a"
|
|
192
|
-
HEADER="libasherah-darwin-x64-archive.h"
|
|
193
|
-
WARMUP="go-warmup-darwin-x64.dylib"
|
|
194
|
-
SUMS="SHA256SUMS-darwin"
|
|
195
|
-
elif [[ ${MACHINE} == 'arm64' ]]; then
|
|
196
|
-
#echo "Using Asherah libraries for MacOS arm64"
|
|
197
|
-
ARCHIVE="libasherah-darwin-arm64.a"
|
|
198
|
-
HEADER="libasherah-darwin-arm64-archive.h"
|
|
199
|
-
WARMUP="go-warmup-darwin-arm64.dylib"
|
|
200
|
-
SUMS="SHA256SUMS-darwin"
|
|
201
|
-
else
|
|
202
|
-
echo "Unsupported CPU architecture: ${MACHINE}" >&2
|
|
203
|
-
exit 1
|
|
204
|
-
fi
|
|
205
|
-
else
|
|
206
|
-
echo "Unsupported operating system: ${OS}" >&2
|
|
207
|
-
exit 1
|
|
208
|
-
fi
|
|
209
|
-
|
|
210
|
-
echo "${ARCHIVE}" "${HEADER}" "${WARMUP}" "${SUMS}" # Return value
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
# Parse script arguments
|
|
214
|
-
function parse_args {
|
|
215
|
-
local no_cache=false
|
|
216
|
-
while [[ $# -gt 0 ]]; do
|
|
217
|
-
case "$1" in
|
|
218
|
-
--no-cache)
|
|
219
|
-
no_cache=true
|
|
220
|
-
shift
|
|
221
|
-
;;
|
|
222
|
-
*)
|
|
223
|
-
echo "Unknown parameter: $1" >&2
|
|
224
|
-
exit 1
|
|
225
|
-
;;
|
|
226
|
-
esac
|
|
227
|
-
done
|
|
228
|
-
echo "${no_cache}" # Return value
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
# Function to determine the interval message
|
|
232
|
-
function interval_message {
|
|
233
|
-
local interval=$1
|
|
234
|
-
if (( interval % 60 == 0 )); then
|
|
235
|
-
echo "$((interval / 60)) minutes" # Return value
|
|
236
|
-
else
|
|
237
|
-
echo "$interval seconds" # Return value
|
|
238
|
-
fi
|
|
239
|
-
}
|
|
240
|
-
|
|
241
|
-
# Main function
|
|
242
|
-
function main {
|
|
243
|
-
echo "Downloading Asherah libraries"
|
|
244
|
-
# shellcheck disable=SC1091
|
|
245
|
-
source .asherah-version
|
|
246
|
-
|
|
247
|
-
# Parse arguments
|
|
248
|
-
local no_cache
|
|
249
|
-
no_cache=$(parse_args "$@")
|
|
250
|
-
|
|
251
|
-
# Detect OS and CPU architecture
|
|
252
|
-
read -r archive header warmup sums < <(detect_os_and_cpu)
|
|
253
|
-
echo "Archive: $archive"
|
|
254
|
-
echo "Header: $header"
|
|
255
|
-
echo "Warmup: $warmup"
|
|
256
|
-
echo "Sums: $sums"
|
|
257
|
-
echo "Version: $ASHERAH_VERSION"
|
|
258
|
-
|
|
259
|
-
# Interpolate the URLs
|
|
260
|
-
url_prefix="https://github.com/godaddy/asherah-cobhan/releases/download/${ASHERAH_VERSION}"
|
|
261
|
-
file_names=("${archive}" "${header}" "${warmup}" "${sums}")
|
|
262
|
-
file_urls=(
|
|
263
|
-
"${url_prefix}/${archive}"
|
|
264
|
-
"${url_prefix}/${header}"
|
|
265
|
-
"${url_prefix}/${warmup}"
|
|
266
|
-
"${url_prefix}/${sums}"
|
|
267
|
-
)
|
|
268
|
-
|
|
269
|
-
# Create the `lib` directory if it doesn't exist
|
|
270
|
-
mkdir -p lib
|
|
271
|
-
cd lib || exit 1
|
|
272
|
-
|
|
273
|
-
local retries=0
|
|
274
|
-
local checksums_verified=false
|
|
275
|
-
while [[ $checksums_verified == false && $retries -lt $MAX_DOWNLOAD_RETRIES ]]; do
|
|
276
|
-
local download_failed=false
|
|
277
|
-
|
|
278
|
-
# Per-file touch and download logic
|
|
279
|
-
for i in "${!file_names[@]}"; do
|
|
280
|
-
if check_download_required "${file_names[$i]}" "$no_cache" "$CHECK_INTERVAL_SECONDS"; then
|
|
281
|
-
if ! download_file "${file_urls[$i]}" "${file_names[$i]}"; then
|
|
282
|
-
echo "Failed to download ${file_names[$i]}" >&2
|
|
283
|
-
download_failed=true
|
|
284
|
-
break
|
|
285
|
-
fi
|
|
286
|
-
else
|
|
287
|
-
interval_str=$(interval_message "$CHECK_INTERVAL_SECONDS")
|
|
288
|
-
echo "${file_names[$i]} is up to date (checked within the last ${interval_str})"
|
|
289
|
-
fi
|
|
290
|
-
done
|
|
291
|
-
|
|
292
|
-
# If any download failed, retry the whole batch
|
|
293
|
-
if [[ $download_failed == true ]]; then
|
|
294
|
-
echo "Download failed, cleaning up and retrying..."
|
|
295
|
-
rm -f ./*.a ./*.h ./*.so ./*.dylib ./*.etag
|
|
296
|
-
((retries++))
|
|
297
|
-
sleep 2
|
|
298
|
-
continue
|
|
299
|
-
fi
|
|
300
|
-
|
|
301
|
-
# Verify checksums and copy files
|
|
302
|
-
if verify_checksums "${archive}" "${header}" "${warmup}" "${sums}"; then
|
|
303
|
-
copy_files "${archive}" "${header}"
|
|
304
|
-
checksums_verified=true
|
|
305
|
-
else
|
|
306
|
-
echo "Verification failed, re-downloading files..."
|
|
307
|
-
((retries++))
|
|
308
|
-
# Sleep for a bit before retrying to avoid hammering the server
|
|
309
|
-
sleep 2
|
|
310
|
-
fi
|
|
311
|
-
done
|
|
312
|
-
|
|
313
|
-
if [[ $checksums_verified == true ]]; then
|
|
314
|
-
echo "Asherah libraries downloaded successfully"
|
|
315
|
-
else
|
|
316
|
-
echo "Failed to download Asherah libraries after $retries retries."
|
|
317
|
-
exit 1
|
|
318
|
-
fi
|
|
319
|
-
}
|
|
320
|
-
|
|
321
|
-
# Execute the main function
|
|
322
|
-
main "$@"
|