aes-bridge 2.0.6 → 2.1.0
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/.github/workflows/publish.yml +5 -4
- package/.github/workflows/tests.yml +1 -1
- package/package.json +7 -8
- package/rollup.config.js +7 -4
- package/test/formats.test.js +133 -0
- package/vitest.config.js +17 -0
|
@@ -8,6 +8,10 @@ jobs:
|
|
|
8
8
|
deploy:
|
|
9
9
|
runs-on: ubuntu-latest
|
|
10
10
|
|
|
11
|
+
permissions:
|
|
12
|
+
id-token: write
|
|
13
|
+
contents: read
|
|
14
|
+
|
|
11
15
|
environment:
|
|
12
16
|
name: npm
|
|
13
17
|
url: https://www.npmjs.com/package/aes-bridge
|
|
@@ -20,7 +24,6 @@ jobs:
|
|
|
20
24
|
uses: actions/setup-node@v4
|
|
21
25
|
with:
|
|
22
26
|
node-version: '20'
|
|
23
|
-
registry-url: 'https://registry.npmjs.org/'
|
|
24
27
|
|
|
25
28
|
- name: Install dependencies
|
|
26
29
|
run: npm ci
|
|
@@ -29,6 +32,4 @@ jobs:
|
|
|
29
32
|
run: npm run build
|
|
30
33
|
|
|
31
34
|
- name: Publish to npm
|
|
32
|
-
run: npm publish --access public
|
|
33
|
-
env:
|
|
34
|
-
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
|
|
35
|
+
run: npm publish --access public --provenance
|
package/package.json
CHANGED
|
@@ -1,25 +1,24 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "aes-bridge",
|
|
3
|
-
"version": "2.0
|
|
3
|
+
"version": "2.1.0",
|
|
4
4
|
"description": "AesBridge is a modern, secure and cross-language AES encryption library",
|
|
5
|
-
"type": "module",
|
|
6
5
|
"main": "dist/aes-bridge.umd.js",
|
|
7
6
|
"module": "dist/aes-bridge.esm.js",
|
|
8
7
|
"types": "dist/index.d.ts",
|
|
9
8
|
"exports": {
|
|
10
|
-
"
|
|
11
|
-
"types": "./dist/index.d.ts",
|
|
12
|
-
"default": "./dist/aes-bridge.esm.js"
|
|
13
|
-
},
|
|
14
|
-
"require": {
|
|
9
|
+
".": {
|
|
15
10
|
"types": "./dist/index.d.ts",
|
|
11
|
+
"import": "./dist/aes-bridge.esm.js",
|
|
12
|
+
"require": "./dist/aes-bridge.cjs.js",
|
|
16
13
|
"default": "./dist/aes-bridge.umd.js"
|
|
17
14
|
}
|
|
18
15
|
},
|
|
19
16
|
"scripts": {
|
|
20
17
|
"build": "rollup -c && npm run copy-types",
|
|
21
18
|
"copy-types": "cp src/*.d.ts dist/ 2>/dev/null || true",
|
|
22
|
-
"test": "vitest"
|
|
19
|
+
"test": "vitest --run",
|
|
20
|
+
"test:build": "npm run build && npm test",
|
|
21
|
+
"test:formats": "npm run build && vitest formats.test.js"
|
|
23
22
|
},
|
|
24
23
|
"repository": {
|
|
25
24
|
"type": "git",
|
package/rollup.config.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import json from '@rollup/plugin-json';
|
|
2
2
|
import terser from '@rollup/plugin-terser';
|
|
3
|
-
|
|
3
|
+
import commonjs from '@rollup/plugin-commonjs';
|
|
4
4
|
import { nodeResolve } from '@rollup/plugin-node-resolve';
|
|
5
5
|
|
|
6
6
|
export default [
|
|
@@ -21,11 +21,13 @@ export default [
|
|
|
21
21
|
{
|
|
22
22
|
file: 'dist/aes-bridge.cjs.js',
|
|
23
23
|
format: 'cjs',
|
|
24
|
-
sourcemap: true
|
|
24
|
+
sourcemap: true,
|
|
25
|
+
exports: 'named',
|
|
26
|
+
esModule: false
|
|
25
27
|
}
|
|
26
28
|
],
|
|
27
29
|
plugins: [
|
|
28
|
-
|
|
30
|
+
commonjs(),
|
|
29
31
|
nodeResolve(),
|
|
30
32
|
json(),
|
|
31
33
|
terser({
|
|
@@ -33,6 +35,7 @@ export default [
|
|
|
33
35
|
comments: false
|
|
34
36
|
}
|
|
35
37
|
})
|
|
36
|
-
]
|
|
38
|
+
],
|
|
39
|
+
external: []
|
|
37
40
|
}
|
|
38
41
|
];
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
import { describe, it, expect } from 'vitest';
|
|
2
|
+
import { spawnSync } from 'child_process';
|
|
3
|
+
import { readFileSync } from 'fs';
|
|
4
|
+
import { rmSync, mkdirSync } from 'fs';
|
|
5
|
+
import { fileURLToPath } from 'url';
|
|
6
|
+
import path from 'path';
|
|
7
|
+
import { writeFile, readFile } from 'fs/promises';
|
|
8
|
+
|
|
9
|
+
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
10
|
+
const distDir = path.resolve(__dirname, '../dist');
|
|
11
|
+
const projectRoot = path.dirname(__dirname);
|
|
12
|
+
|
|
13
|
+
describe('Build Formats Compatibility', () => {
|
|
14
|
+
const testText = 'hello world';
|
|
15
|
+
const testPass = 'MyStrongPass123';
|
|
16
|
+
|
|
17
|
+
// 1. ESM test
|
|
18
|
+
it('ESM import works', async () => {
|
|
19
|
+
const { encryptGcm, decryptGcm } = await import('../dist/aes-bridge.esm.js');
|
|
20
|
+
const ciphertext = await encryptGcm(testText, testPass);
|
|
21
|
+
const decrypted = await decryptGcm(ciphertext, testPass);
|
|
22
|
+
const plaintext = (new TextDecoder('utf-8')).decode(decrypted);
|
|
23
|
+
expect(plaintext).toBe(testText);
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
// 2. CJS test
|
|
27
|
+
it('CJS require works', () => {
|
|
28
|
+
const result = spawnSync('node', [
|
|
29
|
+
'-e',
|
|
30
|
+
`const aes = require('${path.resolve(distDir, 'aes-bridge.cjs.js')}');
|
|
31
|
+
console.log(JSON.stringify({
|
|
32
|
+
success: typeof aes.encryptGcm === 'function',
|
|
33
|
+
hasEncrypt: !!aes.encryptGcm
|
|
34
|
+
}))`
|
|
35
|
+
]);
|
|
36
|
+
|
|
37
|
+
const output = JSON.parse(result.stdout.toString());
|
|
38
|
+
expect(output.success).toBe(true);
|
|
39
|
+
expect(output.hasEncrypt).toBe(true);
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
// 3. UMD test
|
|
43
|
+
it('UMD global works', () => {
|
|
44
|
+
const umdContent = readFileSync(path.resolve(distDir, 'aes-bridge.umd.js'), 'utf8');
|
|
45
|
+
const script = `(function() { ${umdContent} })();`;
|
|
46
|
+
|
|
47
|
+
const vm = require('vm');
|
|
48
|
+
const context = vm.createContext({ console, aes_bridge: null });
|
|
49
|
+
vm.runInContext(script, context);
|
|
50
|
+
|
|
51
|
+
expect(context.aes_bridge).toBeDefined();
|
|
52
|
+
expect(typeof context.aes_bridge.encryptGcm).toBe('function');
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
// 4. npm pack test
|
|
56
|
+
it('npm pack + require works', async () => {
|
|
57
|
+
const tempDir = path.join(__dirname, 'temp-pack-test');
|
|
58
|
+
|
|
59
|
+
try {
|
|
60
|
+
rmSync(tempDir, { recursive: true, force: true });
|
|
61
|
+
} catch (e) {
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
mkdirSync(tempDir, { recursive: true });
|
|
65
|
+
|
|
66
|
+
await writeFile(
|
|
67
|
+
path.join(tempDir, 'package.json'),
|
|
68
|
+
JSON.stringify({
|
|
69
|
+
name: 'test-consumer',
|
|
70
|
+
version: '1.0.0',
|
|
71
|
+
type: 'commonjs'
|
|
72
|
+
})
|
|
73
|
+
);
|
|
74
|
+
|
|
75
|
+
const packResult = spawnSync('npm', ['pack'], {
|
|
76
|
+
cwd: projectRoot,
|
|
77
|
+
encoding: 'utf8'
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
const tgzFile = packResult.stdout.trim();
|
|
81
|
+
const fullTgzPath = path.join(projectRoot, tgzFile);
|
|
82
|
+
|
|
83
|
+
const installResult = spawnSync('npm', ['install', fullTgzPath], {
|
|
84
|
+
cwd: tempDir,
|
|
85
|
+
stdio: 'inherit'
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
expect(installResult.status).toBe(0);
|
|
89
|
+
|
|
90
|
+
// Testing require
|
|
91
|
+
const result = spawnSync('node', [
|
|
92
|
+
'-e',
|
|
93
|
+
`const aes = require('aes-bridge');
|
|
94
|
+
(async()=>{
|
|
95
|
+
try {
|
|
96
|
+
if (!aes || !aes.encryptGcm) {
|
|
97
|
+
throw new Error('No aes.encryptGcm');
|
|
98
|
+
}
|
|
99
|
+
const ct = await aes.encryptGcm('${testText}', '${testPass}');
|
|
100
|
+
const decrypted = await aes.decryptGcm(ct, '${testPass}');
|
|
101
|
+
const pt = (new TextDecoder('utf-8')).decode(decrypted);
|
|
102
|
+
console.log(JSON.stringify({success: pt === '${testText}'}));
|
|
103
|
+
} catch(e) {
|
|
104
|
+
console.error('ERROR:', e.message);
|
|
105
|
+
console.log(JSON.stringify({success: false, error: e.message}));
|
|
106
|
+
process.exit(1);
|
|
107
|
+
}
|
|
108
|
+
})();`
|
|
109
|
+
], {
|
|
110
|
+
cwd: tempDir,
|
|
111
|
+
timeout: 5000
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
if (result.status !== 0) {
|
|
115
|
+
console.error('Test result:', result.stderr.toString());
|
|
116
|
+
throw new Error(`Require test failed with status ${result.status}`);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
const output = JSON.parse(result.stdout.toString().trim());
|
|
120
|
+
expect(output.success).toBe(true);
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
// 5. package.json exports
|
|
124
|
+
it('package.json exports are correct', () => {
|
|
125
|
+
const pkg = JSON.parse(readFileSync(path.resolve(projectRoot, 'package.json'), 'utf8'));
|
|
126
|
+
const exports = pkg.exports['.'];
|
|
127
|
+
|
|
128
|
+
expect(exports.types).toBe('./dist/index.d.ts');
|
|
129
|
+
expect(exports.import).toBe('./dist/aes-bridge.esm.js');
|
|
130
|
+
expect(exports.require).toBe('./dist/aes-bridge.cjs.js');
|
|
131
|
+
expect(exports.default).toBe('./dist/aes-bridge.umd.js');
|
|
132
|
+
});
|
|
133
|
+
});
|
package/vitest.config.js
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { defineConfig } from 'vitest/config';
|
|
2
|
+
import path from 'path';
|
|
3
|
+
|
|
4
|
+
export default defineConfig({
|
|
5
|
+
test: {
|
|
6
|
+
include: [
|
|
7
|
+
'index.test.js',
|
|
8
|
+
'formats.test.js',
|
|
9
|
+
'test/**/*.{test,spec}.js'
|
|
10
|
+
],
|
|
11
|
+
environment: 'node',
|
|
12
|
+
coverage: {
|
|
13
|
+
provider: 'v8',
|
|
14
|
+
reporter: ['text', 'json', 'html']
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
});
|