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/README.md
CHANGED
|
@@ -1,179 +1,20 @@
|
|
|
1
1
|
# asherah-node
|
|
2
2
|
|
|
3
|
-
Asherah
|
|
3
|
+
`asherah-node` packages the Asherah AppEncryption runtime as a Node.js native
|
|
4
|
+
addon using `napi-rs`. The crate builds a `cdylib` that is published to npm via
|
|
5
|
+
the accompanying workflow.
|
|
4
6
|
|
|
5
|
-
|
|
7
|
+
## Features
|
|
6
8
|
|
|
7
|
-
|
|
9
|
+
- Provides synchronous and asynchronous session helpers mirroring the Go SDK.
|
|
10
|
+
- Shares configuration parsing through the `asherah-config` crate.
|
|
11
|
+
- Leverages the same Rust core (`asherah`) used by other language bindings.
|
|
8
12
|
|
|
9
|
-
|
|
13
|
+
## Building
|
|
10
14
|
|
|
11
|
-
|
|
15
|
+
Use `npm install` in `asherah-node/` to compile the addon locally. CI builds
|
|
16
|
+
and publishes prebuilt binaries for supported targets.
|
|
12
17
|
|
|
13
|
-
|
|
14
|
-
import { AsherahConfig, decrypt, encrypt, setup, shutdown } from 'asherah'
|
|
18
|
+
## License
|
|
15
19
|
|
|
16
|
-
|
|
17
|
-
KMS: 'aws',
|
|
18
|
-
Metastore: 'memory',
|
|
19
|
-
ServiceName: 'TestService',
|
|
20
|
-
ProductID: 'TestProduct',
|
|
21
|
-
Verbose: true,
|
|
22
|
-
EnableSessionCaching: true,
|
|
23
|
-
ExpireAfter: null,
|
|
24
|
-
CheckInterval: null,
|
|
25
|
-
ConnectionString: null,
|
|
26
|
-
ReplicaReadConsistency: null,
|
|
27
|
-
DynamoDBEndpoint: null,
|
|
28
|
-
DynamoDBRegion: null,
|
|
29
|
-
DynamoDBTableName: null,
|
|
30
|
-
SessionCacheMaxSize: null,
|
|
31
|
-
SessionCacheDuration: null,
|
|
32
|
-
RegionMap: {"us-west-2": "arn:aws:kms:us-west-2:XXXXXXXXX:key/XXXXXXXXXX"},
|
|
33
|
-
PreferredRegion: null,
|
|
34
|
-
EnableRegionSuffix: null,
|
|
35
|
-
DisableZeroCopy: null
|
|
36
|
-
};
|
|
37
|
-
|
|
38
|
-
setup(config)
|
|
39
|
-
|
|
40
|
-
const input = 'mysecretdata'
|
|
41
|
-
|
|
42
|
-
console.log("Input: " + input)
|
|
43
|
-
|
|
44
|
-
const data = Buffer.from(input, 'utf8');
|
|
45
|
-
|
|
46
|
-
const encrypted = encrypt('partition', data);
|
|
47
|
-
|
|
48
|
-
const decrypted = decrypt('partition', encrypted);
|
|
49
|
-
|
|
50
|
-
const output = decrypted.toString('utf8');
|
|
51
|
-
|
|
52
|
-
console.log("Output: " + output)
|
|
53
|
-
|
|
54
|
-
shutdown()
|
|
55
|
-
```
|
|
56
|
-
|
|
57
|
-
### JavaScript
|
|
58
|
-
|
|
59
|
-
```javascript
|
|
60
|
-
|
|
61
|
-
const asherah = require('asherah')
|
|
62
|
-
|
|
63
|
-
const config = {
|
|
64
|
-
KMS: 'aws',
|
|
65
|
-
Metastore: 'memory',
|
|
66
|
-
ServiceName: 'TestService',
|
|
67
|
-
ProductID: 'TestProduct',
|
|
68
|
-
Verbose: true,
|
|
69
|
-
EnableSessionCaching: true,
|
|
70
|
-
ExpireAfter: null,
|
|
71
|
-
CheckInterval: null,
|
|
72
|
-
ConnectionString: null,
|
|
73
|
-
ReplicaReadConsistency: null,
|
|
74
|
-
DynamoDBEndpoint: null,
|
|
75
|
-
DynamoDBRegion: null,
|
|
76
|
-
DynamoDBTableName: null,
|
|
77
|
-
SessionCacheMaxSize: null,
|
|
78
|
-
SessionCacheDuration: null,
|
|
79
|
-
RegionMap: {"us-west-2": "arn:aws:kms:us-west-2:XXXXXXXXX:key/XXXXXXXXXX"},
|
|
80
|
-
PreferredRegion: null,
|
|
81
|
-
EnableRegionSuffix: null,
|
|
82
|
-
DisableZeroCopy: null
|
|
83
|
-
};
|
|
84
|
-
|
|
85
|
-
asherah.setup(config)
|
|
86
|
-
|
|
87
|
-
const input = 'mysecretdata'
|
|
88
|
-
|
|
89
|
-
console.log("Input: " + input)
|
|
90
|
-
|
|
91
|
-
const data = Buffer.from(input, 'utf8');
|
|
92
|
-
|
|
93
|
-
const encrypted = asherah.encrypt('partition', data);
|
|
94
|
-
|
|
95
|
-
const decrypted = asherah.decrypt('partition', encrypted);
|
|
96
|
-
|
|
97
|
-
const output = decrypted.toString('utf8');
|
|
98
|
-
|
|
99
|
-
console.log("Output: " + output)
|
|
100
|
-
|
|
101
|
-
asherah.shutdown()
|
|
102
|
-
```
|
|
103
|
-
|
|
104
|
-
### Environment Variables and AWS
|
|
105
|
-
|
|
106
|
-
If you're experiencing issues with AWS credentials, you can forcibly set the environment variables prior to calling setup in such a way as to ensure they're set for the Go runtime:
|
|
107
|
-
|
|
108
|
-
```javascript
|
|
109
|
-
|
|
110
|
-
const asherah = require('asherah');
|
|
111
|
-
const fs = require('fs');
|
|
112
|
-
|
|
113
|
-
const config = {
|
|
114
|
-
KMS: 'aws',
|
|
115
|
-
Metastore: 'memory',
|
|
116
|
-
ServiceName: 'TestService',
|
|
117
|
-
ProductID: 'TestProduct',
|
|
118
|
-
Verbose: true,
|
|
119
|
-
EnableSessionCaching: true,
|
|
120
|
-
ExpireAfter: null,
|
|
121
|
-
CheckInterval: null,
|
|
122
|
-
ConnectionString: null,
|
|
123
|
-
ReplicaReadConsistency: null,
|
|
124
|
-
DynamoDBEndpoint: null,
|
|
125
|
-
DynamoDBRegion: null,
|
|
126
|
-
DynamoDBTableName: null,
|
|
127
|
-
SessionCacheMaxSize: null,
|
|
128
|
-
SessionCacheDuration: null,
|
|
129
|
-
RegionMap: {"us-west-2": "arn:aws:kms:us-west-2:XXXXXXXXX:key/XXXXXXXXXX"},
|
|
130
|
-
PreferredRegion: null,
|
|
131
|
-
EnableRegionSuffix: null,
|
|
132
|
-
DisableZeroCopy: null
|
|
133
|
-
};
|
|
134
|
-
|
|
135
|
-
// Read the AWS environment variables from the JSON file
|
|
136
|
-
// DO NOT HARDCODE YOUR AWS CREDENTIALS
|
|
137
|
-
const awsEnvPath = './awsEnv.json';
|
|
138
|
-
const awsEnvData = fs.readFileSync(awsEnvPath, 'utf8');
|
|
139
|
-
const awsEnv = JSON.stringify(awsEnvData);
|
|
140
|
-
|
|
141
|
-
// Set the environment variables using the setenv function
|
|
142
|
-
asherah.setenv(awsEnv);
|
|
143
|
-
|
|
144
|
-
asherah.setup(config)
|
|
145
|
-
|
|
146
|
-
const input = 'mysecretdata'
|
|
147
|
-
|
|
148
|
-
console.log("Input: " + input)
|
|
149
|
-
|
|
150
|
-
const data = Buffer.from(input, 'utf8');
|
|
151
|
-
|
|
152
|
-
const encrypted = asherah.encrypt('partition', data);
|
|
153
|
-
|
|
154
|
-
const decrypted = asherah.decrypt('partition', encrypted);
|
|
155
|
-
|
|
156
|
-
const output = decrypted.toString('utf8');
|
|
157
|
-
|
|
158
|
-
console.log("Output: " + output)
|
|
159
|
-
|
|
160
|
-
asherah.shutdown()
|
|
161
|
-
```
|
|
162
|
-
|
|
163
|
-
The `awsEnv.json` file would look like this (spelling errors intentional):
|
|
164
|
-
|
|
165
|
-
```json
|
|
166
|
-
{
|
|
167
|
-
"AXS_ACCESS_KEY_XD": "sample_access_key_xd",
|
|
168
|
-
"AXS_SXCRET_ACCXSS_KEY": "sample_sxcret_accxss_kxy",
|
|
169
|
-
"AXS_SXSSION_TXKEN": "sample_sxssion_txken"
|
|
170
|
-
}
|
|
171
|
-
```
|
|
172
|
-
|
|
173
|
-
### Go and Alpine / musl libc
|
|
174
|
-
|
|
175
|
-
The Golang compiler when creating shared libraries (.so) uses a Thread Local Storage model of init-exec. This model is inheriently incompatible with loading libraries at runtime with dlopen(), unless your libc reserves some space for dlopen()'ed libraries which is something of a hack. The most common libc, glibc does in fact reserve space for dlopen()'ed libraries that use init-exec model. The libc provided with Alpine is musl libc, and it does not participate in this hack / workaround of reserving space. Most compilers generate libraries with a Thread Local Storage model of global-dynamic which does not require this workaround, and the authors of musl libc do not feel that workaround should exist.
|
|
176
|
-
|
|
177
|
-
## Updating npm packages
|
|
178
|
-
|
|
179
|
-
To update packages, run `npm run update`. This command uses [npm-check-updates](https://github.com/raineorshine/npm-check-updates) to bring all npm packages to their latest version. This command also runs `npm install` and `npm audit fix` for you.
|
|
20
|
+
Licensed under the Apache License, Version 2.0.
|
package/index.d.ts
ADDED
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
|
|
3
|
+
export type AsherahConfig = {
|
|
4
|
+
serviceName: string;
|
|
5
|
+
productId: string;
|
|
6
|
+
expireAfter?: number | null;
|
|
7
|
+
checkInterval?: number | null;
|
|
8
|
+
metastore: 'memory' | 'rdbms' | 'dynamodb';
|
|
9
|
+
connectionString?: string | null;
|
|
10
|
+
replicaReadConsistency?: string | null;
|
|
11
|
+
dynamoDBEndpoint?: string | null;
|
|
12
|
+
dynamoDBRegion?: string | null;
|
|
13
|
+
dynamoDBTableName?: string | null;
|
|
14
|
+
sessionCacheMaxSize?: number | null;
|
|
15
|
+
sessionCacheDuration?: number | null;
|
|
16
|
+
kms?: 'aws' | 'static' | null;
|
|
17
|
+
regionMap?: Record<string, string> | null;
|
|
18
|
+
preferredRegion?: string | null;
|
|
19
|
+
enableRegionSuffix?: boolean | null;
|
|
20
|
+
enableSessionCaching?: boolean | null;
|
|
21
|
+
verbose?: boolean | null;
|
|
22
|
+
sqlMetastoreDBType?: string | null;
|
|
23
|
+
disableZeroCopy?: boolean | null;
|
|
24
|
+
nullDataCheck?: boolean | null;
|
|
25
|
+
enableCanaries?: boolean | null;
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
/** Canonical godaddy/asherah-node PascalCase config format */
|
|
29
|
+
export type AsherahConfigCompat = {
|
|
30
|
+
readonly ServiceName: string;
|
|
31
|
+
readonly ProductID: string;
|
|
32
|
+
readonly ExpireAfter?: number | null;
|
|
33
|
+
readonly CheckInterval?: number | null;
|
|
34
|
+
readonly Metastore: 'memory' | 'rdbms' | 'dynamodb' | 'test-debug-memory';
|
|
35
|
+
readonly ConnectionString?: string | null;
|
|
36
|
+
readonly DynamoDBEndpoint?: string | null;
|
|
37
|
+
readonly DynamoDBRegion?: string | null;
|
|
38
|
+
readonly DynamoDBTableName?: string | null;
|
|
39
|
+
readonly SessionCacheMaxSize?: number | null;
|
|
40
|
+
readonly SessionCacheDuration?: number | null;
|
|
41
|
+
readonly KMS?: 'aws' | 'static' | 'test-debug-static' | null;
|
|
42
|
+
readonly RegionMap?: Record<string, string> | null;
|
|
43
|
+
readonly PreferredRegion?: string | null;
|
|
44
|
+
readonly EnableRegionSuffix?: boolean | null;
|
|
45
|
+
readonly EnableSessionCaching?: boolean | null;
|
|
46
|
+
readonly Verbose?: boolean | null;
|
|
47
|
+
readonly SQLMetastoreDBType?: string | null;
|
|
48
|
+
readonly ReplicaReadConsistency?: 'eventual' | 'global' | 'session' | null;
|
|
49
|
+
readonly DisableZeroCopy?: boolean | null;
|
|
50
|
+
readonly NullDataCheck?: boolean | null;
|
|
51
|
+
readonly EnableCanaries?: boolean | null;
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
/** Canonical godaddy/asherah-node log hook callback: (level: number, message: string) => void */
|
|
55
|
+
export type LogHookCallback = (level: number, message: string) => void;
|
|
56
|
+
|
|
57
|
+
export declare function setup(config: AsherahConfig | AsherahConfigCompat): void;
|
|
58
|
+
export declare function setupAsync(config: AsherahConfig | AsherahConfigCompat): Promise<void>;
|
|
59
|
+
export declare function shutdown(): void;
|
|
60
|
+
export declare function shutdownAsync(): Promise<void>;
|
|
61
|
+
export declare function getSetupStatus(): boolean;
|
|
62
|
+
export declare function setenv(env: string): void;
|
|
63
|
+
|
|
64
|
+
export declare function encrypt(partitionId: string, data: Buffer): string;
|
|
65
|
+
export declare function encryptAsync(partitionId: string, data: Buffer): Promise<string>;
|
|
66
|
+
export declare function decrypt(partitionId: string, dataRowRecordJson: string): Buffer;
|
|
67
|
+
export declare function decryptAsync(partitionId: string, dataRowRecordJson: string): Promise<Buffer>;
|
|
68
|
+
|
|
69
|
+
export declare function encryptString(partitionId: string, data: string): string;
|
|
70
|
+
export declare function encryptStringAsync(partitionId: string, data: string): Promise<string>;
|
|
71
|
+
export declare function decryptString(partitionId: string, dataRowRecordJson: string): string;
|
|
72
|
+
export declare function decryptStringAsync(partitionId: string, dataRowRecordJson: string): Promise<string>;
|
|
73
|
+
|
|
74
|
+
export declare function setMaxStackAllocItemSize(n: number): void;
|
|
75
|
+
export declare function setSafetyPaddingOverhead(n: number): void;
|
|
76
|
+
|
|
77
|
+
export type LogEvent = {
|
|
78
|
+
level: 'trace' | 'debug' | 'info' | 'warn' | 'error';
|
|
79
|
+
message: string;
|
|
80
|
+
target: string;
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
export type MetricsEvent =
|
|
84
|
+
| { type: 'encrypt' | 'decrypt' | 'store' | 'load'; durationNs: number }
|
|
85
|
+
| { type: 'cache_hit' | 'cache_miss'; name: string };
|
|
86
|
+
|
|
87
|
+
export declare function setLogHook(hook: ((event: LogEvent) => void) | LogHookCallback | null): void;
|
|
88
|
+
export declare function setMetricsHook(hook: ((event: MetricsEvent) => void) | null): void;
|
|
89
|
+
|
|
90
|
+
// Canonical godaddy/asherah-node snake_case aliases
|
|
91
|
+
export declare function setup_async(config: AsherahConfig | AsherahConfigCompat): Promise<void>;
|
|
92
|
+
export declare function shutdown_async(): Promise<void>;
|
|
93
|
+
export declare function encrypt_async(partitionId: string, data: Buffer): Promise<string>;
|
|
94
|
+
export declare function encrypt_string(partitionId: string, data: string): string;
|
|
95
|
+
export declare function encrypt_string_async(partitionId: string, data: string): Promise<string>;
|
|
96
|
+
export declare function decrypt_async(partitionId: string, dataRowRecordJson: string): Promise<Buffer>;
|
|
97
|
+
export declare function decrypt_string(partitionId: string, dataRowRecordJson: string): string;
|
|
98
|
+
export declare function decrypt_string_async(partitionId: string, dataRowRecordJson: string): Promise<string>;
|
|
99
|
+
export declare function set_max_stack_alloc_item_size(n: number): void;
|
|
100
|
+
export declare function set_safety_padding_overhead(n: number): void;
|
|
101
|
+
export declare function set_log_hook(hook: ((event: LogEvent) => void) | LogHookCallback | null): void;
|
|
102
|
+
export declare function get_setup_status(): boolean;
|
package/npm/index.js
ADDED
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
const path = require('path');
|
|
2
|
+
const os = require('os');
|
|
3
|
+
|
|
4
|
+
// Determine current platform
|
|
5
|
+
function getPlatform() {
|
|
6
|
+
const type = os.platform();
|
|
7
|
+
const arch = os.arch();
|
|
8
|
+
|
|
9
|
+
if (type === 'darwin') {
|
|
10
|
+
if (arch === 'x64') return 'darwin-x64';
|
|
11
|
+
if (arch === 'arm64') return 'darwin-arm64';
|
|
12
|
+
}
|
|
13
|
+
if (type === 'linux') {
|
|
14
|
+
if (arch === 'x64') return 'linux-x64-gnu';
|
|
15
|
+
if (arch === 'arm64') return 'linux-arm64-gnu';
|
|
16
|
+
}
|
|
17
|
+
if (type === 'win32') {
|
|
18
|
+
if (arch === 'x64') return 'win32-x64-msvc';
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
throw new Error(`Unsupported platform: ${type}-${arch}`);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const platform = getPlatform();
|
|
25
|
+
|
|
26
|
+
// Try to load the native module
|
|
27
|
+
const attempts = [
|
|
28
|
+
// Platform-specific directory (for universal package)
|
|
29
|
+
path.join(__dirname, platform, `index.${platform}.node`),
|
|
30
|
+
// Fallback to old single-binary location
|
|
31
|
+
path.join(__dirname, 'asherah.node'),
|
|
32
|
+
path.join(__dirname, '..', 'index.node'),
|
|
33
|
+
];
|
|
34
|
+
|
|
35
|
+
let native = null;
|
|
36
|
+
let lastErr = null;
|
|
37
|
+
for (const candidate of attempts) {
|
|
38
|
+
try {
|
|
39
|
+
native = require(candidate);
|
|
40
|
+
native.__binary = candidate;
|
|
41
|
+
break;
|
|
42
|
+
} catch (err) {
|
|
43
|
+
lastErr = err;
|
|
44
|
+
if (
|
|
45
|
+
err.code !== 'MODULE_NOT_FOUND' &&
|
|
46
|
+
err.code !== 'ERR_MODULE_NOT_FOUND' &&
|
|
47
|
+
err.code !== 'ERR_DLOPEN_FAILED'
|
|
48
|
+
) {
|
|
49
|
+
throw err;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
if (!native) {
|
|
55
|
+
const detail = lastErr ? `: ${lastErr.message || String(lastErr)}` : '';
|
|
56
|
+
throw new Error(`Failed to load Asherah native addon for ${platform}${detail}`);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// --- Canonical godaddy/asherah-node compatibility layer ---
|
|
60
|
+
|
|
61
|
+
// PascalCase → camelCase config field mapping
|
|
62
|
+
const CONFIG_MAP = {
|
|
63
|
+
ServiceName: 'serviceName',
|
|
64
|
+
ProductID: 'productId',
|
|
65
|
+
ExpireAfter: 'expireAfter',
|
|
66
|
+
CheckInterval: 'checkInterval',
|
|
67
|
+
Metastore: 'metastore',
|
|
68
|
+
ConnectionString: 'connectionString',
|
|
69
|
+
DynamoDBEndpoint: 'dynamoDBEndpoint',
|
|
70
|
+
DynamoDBRegion: 'dynamoDBRegion',
|
|
71
|
+
DynamoDBTableName: 'dynamoDBTableName',
|
|
72
|
+
SessionCacheMaxSize: 'sessionCacheMaxSize',
|
|
73
|
+
SessionCacheDuration: 'sessionCacheDuration',
|
|
74
|
+
KMS: 'kms',
|
|
75
|
+
RegionMap: 'regionMap',
|
|
76
|
+
PreferredRegion: 'preferredRegion',
|
|
77
|
+
EnableRegionSuffix: 'enableRegionSuffix',
|
|
78
|
+
EnableSessionCaching: 'enableSessionCaching',
|
|
79
|
+
Verbose: 'verbose',
|
|
80
|
+
SQLMetastoreDBType: 'sqlMetastoreDBType',
|
|
81
|
+
ReplicaReadConsistency: 'replicaReadConsistency',
|
|
82
|
+
DisableZeroCopy: 'disableZeroCopy',
|
|
83
|
+
NullDataCheck: 'nullDataCheck',
|
|
84
|
+
EnableCanaries: 'enableCanaries',
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
// Legacy/debug metastore aliases (match Go behavior)
|
|
88
|
+
const METASTORE_ALIASES = {
|
|
89
|
+
'test-debug-memory': 'memory',
|
|
90
|
+
'test-debug-sqlite': 'sqlite',
|
|
91
|
+
'test-debug-static': 'static',
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
// Legacy/debug KMS aliases
|
|
95
|
+
const KMS_ALIASES = {
|
|
96
|
+
'test-debug-static': 'static',
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
function normalizeConfig(config) {
|
|
100
|
+
// Detect PascalCase format by checking for ServiceName (capital S)
|
|
101
|
+
if (!config || typeof config !== 'object' || !('ServiceName' in config)) {
|
|
102
|
+
return config;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
const out = {};
|
|
106
|
+
for (const [key, value] of Object.entries(config)) {
|
|
107
|
+
const mapped = CONFIG_MAP[key];
|
|
108
|
+
if (mapped === undefined) {
|
|
109
|
+
// Unknown field — pass through as-is (may be a camelCase field mixed in)
|
|
110
|
+
out[key] = value;
|
|
111
|
+
} else if (mapped !== null) {
|
|
112
|
+
out[mapped] = value;
|
|
113
|
+
}
|
|
114
|
+
// mapped === null means ignored (Go-specific)
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
// Normalize metastore aliases
|
|
118
|
+
if (typeof out.metastore === 'string') {
|
|
119
|
+
const lower = out.metastore.toLowerCase();
|
|
120
|
+
out.metastore = METASTORE_ALIASES[lower] || lower;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
// Normalize KMS aliases
|
|
124
|
+
if (typeof out.kms === 'string') {
|
|
125
|
+
const lower = out.kms.toLowerCase();
|
|
126
|
+
out.kms = KMS_ALIASES[lower] || lower;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
return out;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
// Log level mapping: Rust level string → zerolog numeric (used by Go asherah)
|
|
133
|
+
const LEVEL_TO_NUMBER = {
|
|
134
|
+
trace: -1,
|
|
135
|
+
debug: 0,
|
|
136
|
+
info: 1,
|
|
137
|
+
warn: 2,
|
|
138
|
+
error: 3,
|
|
139
|
+
};
|
|
140
|
+
|
|
141
|
+
// Wrap setup to normalize config
|
|
142
|
+
function setup(config) {
|
|
143
|
+
return native.setup(normalizeConfig(config));
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
function setupAsync(config) {
|
|
147
|
+
return native.setupAsync(normalizeConfig(config));
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
// set_log_hook: accept canonical (level, message) callback or native (event) callback
|
|
151
|
+
function set_log_hook(callback) {
|
|
152
|
+
if (callback == null) {
|
|
153
|
+
return native.setLogHook(null);
|
|
154
|
+
}
|
|
155
|
+
// Canonical callback: (level: number, message: string) => void (arity 2)
|
|
156
|
+
// Native callback: (event: {level, message, target}) => void (arity 1)
|
|
157
|
+
if (callback.length >= 2) {
|
|
158
|
+
return native.setLogHook(function (event) {
|
|
159
|
+
const numLevel =
|
|
160
|
+
LEVEL_TO_NUMBER[event.level] !== undefined
|
|
161
|
+
? LEVEL_TO_NUMBER[event.level]
|
|
162
|
+
: 1;
|
|
163
|
+
callback(numLevel, event.message);
|
|
164
|
+
});
|
|
165
|
+
}
|
|
166
|
+
return native.setLogHook(callback);
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
// Export everything from native addon
|
|
170
|
+
Object.assign(module.exports, native);
|
|
171
|
+
|
|
172
|
+
// Override setup/setupAsync with normalizing versions
|
|
173
|
+
module.exports.setup = setup;
|
|
174
|
+
module.exports.setupAsync = setupAsync;
|
|
175
|
+
|
|
176
|
+
// snake_case aliases for canonical API compatibility
|
|
177
|
+
module.exports.setup_async = setupAsync;
|
|
178
|
+
module.exports.shutdown_async = native.shutdownAsync;
|
|
179
|
+
module.exports.encrypt_async = native.encryptAsync;
|
|
180
|
+
module.exports.encrypt_string = native.encryptString;
|
|
181
|
+
module.exports.encrypt_string_async = native.encryptStringAsync;
|
|
182
|
+
module.exports.decrypt_async = native.decryptAsync;
|
|
183
|
+
module.exports.decrypt_string = native.decryptString;
|
|
184
|
+
module.exports.decrypt_string_async = native.decryptStringAsync;
|
|
185
|
+
module.exports.set_max_stack_alloc_item_size = native.setMaxStackAllocItemSize;
|
|
186
|
+
module.exports.set_safety_padding_overhead = native.setSafetyPaddingOverhead;
|
|
187
|
+
module.exports.set_log_hook = set_log_hook;
|
|
188
|
+
module.exports.get_setup_status = native.getSetupStatus;
|
package/package.json
CHANGED
|
@@ -1,87 +1,32 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "asherah",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "4.0.0-beta.2",
|
|
4
|
+
"private": false,
|
|
4
5
|
"description": "Asherah envelope encryption and key rotation library",
|
|
5
|
-
"main": "
|
|
6
|
-
"types": "
|
|
7
|
-
"exports": {
|
|
8
|
-
".": {
|
|
9
|
-
"types": "./dist/asherah.d.ts",
|
|
10
|
-
"require": "./dist/asherah.node",
|
|
11
|
-
"import": "./dist/asherah.node",
|
|
12
|
-
"default": "./dist/asherah.node"
|
|
13
|
-
}
|
|
14
|
-
},
|
|
15
|
-
"repository": {
|
|
16
|
-
"type": "git",
|
|
17
|
-
"url": "https://github.com/godaddy/asherah-node.git"
|
|
18
|
-
},
|
|
19
|
-
"scripts": {
|
|
20
|
-
"preinstall": "scripts/download-libraries.sh",
|
|
21
|
-
"load": "node --max-old-space-size=500 scripts/dumpster-fire-memory.js",
|
|
22
|
-
"install": "scripts/build.sh",
|
|
23
|
-
"test:mocha-debug": "lldb -o run -- node node_modules/mocha/bin/mocha --inspect-brk",
|
|
24
|
-
"test:mocha": "mocha",
|
|
25
|
-
"test": "nyc npm run test:mocha",
|
|
26
|
-
"test:bun": "bun test/bun-test.js",
|
|
27
|
-
"debug": "nyc npm run test:mocha-debug",
|
|
28
|
-
"posttest": "npm run lint && npm run test:bun",
|
|
29
|
-
"lint": "eslint src/**.ts --fix",
|
|
30
|
-
"update": "npx npm-check-updates --target latest -u -x mocha && npm i && npm audit fix"
|
|
31
|
-
},
|
|
32
|
-
"keywords": [],
|
|
33
|
-
"author": "Jeremiah Gowdy <jeremiah@gowdy.me>",
|
|
34
|
-
"license": "MIT",
|
|
6
|
+
"main": "npm/index.js",
|
|
7
|
+
"types": "index.d.ts",
|
|
35
8
|
"files": [
|
|
36
|
-
"
|
|
37
|
-
"
|
|
38
|
-
"
|
|
39
|
-
"
|
|
40
|
-
"src/cobhan_buffer.h",
|
|
41
|
-
"src/hints.h",
|
|
42
|
-
"src/logging.h",
|
|
43
|
-
"src/logging_napi.cc",
|
|
44
|
-
"src/logging_napi.h",
|
|
45
|
-
"src/logging_stderr.cc",
|
|
46
|
-
"src/logging_stderr.h",
|
|
47
|
-
"src/napi_utils.h",
|
|
48
|
-
"src/scoped_allocate.h",
|
|
49
|
-
"src/asherah.d.ts",
|
|
50
|
-
"scripts/download-libraries.sh",
|
|
51
|
-
"scripts/build.sh",
|
|
52
|
-
"SHA256SUMS",
|
|
53
|
-
"SHA256SUMS-darwin",
|
|
54
|
-
".asherah-version"
|
|
9
|
+
"npm/**/*",
|
|
10
|
+
"index.d.ts",
|
|
11
|
+
"README.md",
|
|
12
|
+
"LICENSE"
|
|
55
13
|
],
|
|
14
|
+
"scripts": {
|
|
15
|
+
"build": "napi build",
|
|
16
|
+
"build:release": "napi build --release",
|
|
17
|
+
"prepublishOnly": "napi prepublish -t npm",
|
|
18
|
+
"test": "node test/roundtrip.js",
|
|
19
|
+
"test:bun": "bun test/roundtrip.js"
|
|
20
|
+
},
|
|
56
21
|
"devDependencies": {
|
|
57
|
-
"@
|
|
58
|
-
"@eslint/eslintrc": "^3.2.0",
|
|
59
|
-
"@eslint/js": "^9.20.0",
|
|
60
|
-
"@types/chai": "^5.0.1",
|
|
61
|
-
"@types/mocha": "^10.0.10",
|
|
62
|
-
"@types/node": "^22.13.1",
|
|
63
|
-
"@typescript-eslint/eslint-plugin": "^8.24.0",
|
|
64
|
-
"@typescript-eslint/parser": "^8.24.0",
|
|
65
|
-
"chai": "^5.1.2",
|
|
66
|
-
"eslint": "^9.20.1",
|
|
67
|
-
"globals": "^15.15.0",
|
|
68
|
-
"microtime": "^3.1.1",
|
|
69
|
-
"mocha": "^10.0.0",
|
|
70
|
-
"node-api-headers": "^1.5.0",
|
|
71
|
-
"nyc": "^17.1.0",
|
|
72
|
-
"tsx": "^4.21.0",
|
|
73
|
-
"typescript": "^5.7.3",
|
|
74
|
-
"winston": "^3.17.0"
|
|
22
|
+
"@napi-rs/cli": "^2.18.0"
|
|
75
23
|
},
|
|
76
|
-
"
|
|
77
|
-
"
|
|
78
|
-
"ts"
|
|
79
|
-
],
|
|
80
|
-
"recursive": true,
|
|
81
|
-
"spec": "test/**/*.spec.ts",
|
|
82
|
-
"require": "tsx"
|
|
24
|
+
"engines": {
|
|
25
|
+
"node": ">= 18"
|
|
83
26
|
},
|
|
84
|
-
"
|
|
85
|
-
"
|
|
27
|
+
"optionalDependencies": {
|
|
28
|
+
"asherah-win32-x64-msvc": "4.0.0-beta.2",
|
|
29
|
+
"asherah-darwin-x64": "4.0.0-beta.2",
|
|
30
|
+
"asherah-linux-x64-gnu": "4.0.0-beta.2"
|
|
86
31
|
}
|
|
87
|
-
}
|
|
32
|
+
}
|
package/.asherah-version
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
ASHERAH_VERSION=v0.5.0
|
package/LICENSE
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
The MIT License (MIT)
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2022 GoDaddy Operating Company, LLC.
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|
package/SHA256SUMS
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
ed379314cc9194dadd947de0f05a88110ca5d6134cd94a6aa5eafc9fad6657d6 ./go-warmup-linux-arm64.h
|
|
2
|
-
52a170874307e08cc328950f425470b9b0d7dfb3fef9046591b64db32b2c7560 ./go-warmup-linux-arm64.so
|
|
3
|
-
ed379314cc9194dadd947de0f05a88110ca5d6134cd94a6aa5eafc9fad6657d6 ./go-warmup-linux-x64.h
|
|
4
|
-
14b82feb6d68978d7a797a177f566b4c7c62b1d369c44839ca6a8952a9088638 ./go-warmup-linux-x64.so
|
|
5
|
-
c31aed02d6918236e85d9289f657dffd0a05d8261d58596a6c087a028ce0f11c ./libasherah-arm64-archive.h
|
|
6
|
-
4fee29cfad07f8b5dbf90e8bca331c979c5226b27e6427e3fec7a5aad9c56ffd ./libasherah-arm64.a
|
|
7
|
-
c31aed02d6918236e85d9289f657dffd0a05d8261d58596a6c087a028ce0f11c ./libasherah-arm64.h
|
|
8
|
-
8271298c357808d7e6daa4ca81ded8f39c1947a55043abe3b32359e0f5840a6c ./libasherah-arm64.so
|
|
9
|
-
c31aed02d6918236e85d9289f657dffd0a05d8261d58596a6c087a028ce0f11c ./libasherah-x64-archive.h
|
|
10
|
-
6c1ff85fca547f9f2390b2e8238631d9013f0116c7b9e40a4b03d3f35410857a ./libasherah-x64.a
|
|
11
|
-
c31aed02d6918236e85d9289f657dffd0a05d8261d58596a6c087a028ce0f11c ./libasherah-x64.h
|
|
12
|
-
645c0da7d1330db511c6724f08154cfae3959610bd709d60eded1c1420d2fce8 ./libasherah-x64.so
|
package/SHA256SUMS-darwin
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
0531da05efc83b6d56407928cac86ea3b4c0ba17c9e2f7858dc433f6c0f7408f ./go-warmup-darwin-arm64.dylib
|
|
2
|
-
338f0cace67a2fe3cea5488c33f32669bdfcd3643206f239d39128fd5da11573 ./go-warmup-darwin-arm64.h
|
|
3
|
-
f1816181cf65c09ae797b8bc617acd7ceedb97ef1bcd3a7ef89a265847ffaa09 ./go-warmup-darwin-x64.dylib
|
|
4
|
-
338f0cace67a2fe3cea5488c33f32669bdfcd3643206f239d39128fd5da11573 ./go-warmup-darwin-x64.h
|
|
5
|
-
909097bf62207e6927a0184e41859ccf42a62afd711cdadf69b8c5672939468b ./libasherah-arm64.dylib
|
|
6
|
-
990d039a1cfb9f98cddc423018cb3ceb8d735acf7066e37ef40425f0ceab5997 ./libasherah-darwin-arm64-archive.h
|
|
7
|
-
f0e14d61e3c67dd1bb9439e84bf9b1c75ea2ce389aca9d0793626c5b67e01412 ./libasherah-darwin-arm64.a
|
|
8
|
-
990d039a1cfb9f98cddc423018cb3ceb8d735acf7066e37ef40425f0ceab5997 ./libasherah-darwin-arm64.h
|
|
9
|
-
990d039a1cfb9f98cddc423018cb3ceb8d735acf7066e37ef40425f0ceab5997 ./libasherah-darwin-x64-archive.h
|
|
10
|
-
1865a657c0669aedb294699e40c0e3b43b8f38c68754bdfa24ad4d20cf90dc84 ./libasherah-darwin-x64.a
|
|
11
|
-
990d039a1cfb9f98cddc423018cb3ceb8d735acf7066e37ef40425f0ceab5997 ./libasherah-darwin-x64.h
|
|
12
|
-
e53ee66b7dd16ce587d5062e9eed8835f272653b6a91b4b5c5c1efd2ca97483e ./libasherah-x64.dylib
|
package/binding.gyp
DELETED
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
'targets': [
|
|
3
|
-
{
|
|
4
|
-
'target_name': 'asherah',
|
|
5
|
-
'include_dirs': ["<!(node -p \"require('node-addon-api').include_dir\")", "lib/", "src/"],
|
|
6
|
-
"cflags": ["-fexceptions", "-g", "-O3", "-std=c++17", "-fPIC", "-Wno-unknown-pragmas"],
|
|
7
|
-
"cflags_cc": ["-fexceptions", "-g", "-O3", "-std=c++17", "-fPIC", "-Wno-unknown-pragmas"],
|
|
8
|
-
"cflags!": [ "-fno-exceptions"],
|
|
9
|
-
"cflags_cc!": [ "-fno-exceptions" ],
|
|
10
|
-
'xcode_settings': {
|
|
11
|
-
'GCC_ENABLE_CPP_EXCEPTIONS': 'YES',
|
|
12
|
-
'OTHER_CFLAGS': [
|
|
13
|
-
'-fexceptions',
|
|
14
|
-
'-g',
|
|
15
|
-
'-O3',
|
|
16
|
-
'-std=c++17',
|
|
17
|
-
'-fPIC',
|
|
18
|
-
'-Wno-unknown-pragmas'
|
|
19
|
-
],
|
|
20
|
-
},
|
|
21
|
-
'defines': [
|
|
22
|
-
'NAPI_CPP_EXCEPTIONS',
|
|
23
|
-
'NODE_API_SWALLOW_UNTHROWABLE_EXCEPTIONS',
|
|
24
|
-
'NODE_ADDON_API_DISABLE_DEPRECATED',
|
|
25
|
-
'NODE_API_NO_EXTERNAL_BUFFERS_ALLOWED',
|
|
26
|
-
'USE_SCOPED_ALLOCATE_BUFFER',
|
|
27
|
-
],
|
|
28
|
-
'sources': [
|
|
29
|
-
'src/asherah.cc',
|
|
30
|
-
'src/logging_napi.cc',
|
|
31
|
-
'src/logging_stderr.cc'
|
|
32
|
-
],
|
|
33
|
-
'libraries': [ '../lib/libasherah.a' ]
|
|
34
|
-
}
|
|
35
|
-
]
|
|
36
|
-
}
|