@etree/cli 2.0.2 → 2.0.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/dist/index.js +0 -0
- package/dist/lib/crypto.d.ts +0 -15
- package/dist/lib/crypto.js +28 -152
- package/dist/lib/crypto.js.map +1 -1
- package/package.json +3 -1
package/dist/index.js
CHANGED
|
File without changes
|
package/dist/lib/crypto.d.ts
CHANGED
|
@@ -1,23 +1,8 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Generate a new X25519 key pair.
|
|
3
|
-
*/
|
|
4
1
|
export declare function generateKeys(): Promise<{
|
|
5
2
|
private_key: string;
|
|
6
3
|
public_key: string;
|
|
7
4
|
}>;
|
|
8
|
-
/**
|
|
9
|
-
* Derive the public key from an existing private key.
|
|
10
|
-
*/
|
|
11
5
|
export declare function derivePublicKey(privateKey: string): Promise<string>;
|
|
12
|
-
/**
|
|
13
|
-
* Encrypt a plaintext value using the recipient's public key (SealedBox).
|
|
14
|
-
*/
|
|
15
6
|
export declare function encrypt(plaintext: string, publicKey: string): Promise<string>;
|
|
16
|
-
/**
|
|
17
|
-
* Decrypt a ciphertext using the recipient's private key (SealedBox).
|
|
18
|
-
*/
|
|
19
7
|
export declare function decrypt(ciphertext: string, privateKey: string): Promise<string>;
|
|
20
|
-
/**
|
|
21
|
-
* Shut down the crypto engine process.
|
|
22
|
-
*/
|
|
23
8
|
export declare function shutdown(): void;
|
package/dist/lib/crypto.js
CHANGED
|
@@ -1,173 +1,49 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
-
var ownKeys = function(o) {
|
|
20
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
-
var ar = [];
|
|
22
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
-
return ar;
|
|
24
|
-
};
|
|
25
|
-
return ownKeys(o);
|
|
26
|
-
};
|
|
27
|
-
return function (mod) {
|
|
28
|
-
if (mod && mod.__esModule) return mod;
|
|
29
|
-
var result = {};
|
|
30
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
-
__setModuleDefault(result, mod);
|
|
32
|
-
return result;
|
|
33
|
-
};
|
|
34
|
-
})();
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
35
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
6
|
exports.generateKeys = generateKeys;
|
|
37
7
|
exports.derivePublicKey = derivePublicKey;
|
|
38
8
|
exports.encrypt = encrypt;
|
|
39
9
|
exports.decrypt = decrypt;
|
|
40
10
|
exports.shutdown = shutdown;
|
|
41
|
-
const
|
|
42
|
-
const
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
* Get or spawn the crypto engine Python process.
|
|
47
|
-
*/
|
|
48
|
-
function getEngine() {
|
|
49
|
-
if (engineProcess && !engineProcess.killed) {
|
|
50
|
-
return engineProcess;
|
|
51
|
-
}
|
|
52
|
-
// Try venv python first, fall back to system python
|
|
53
|
-
const venvDir = path.resolve(__dirname, "../../../../packages/crypto/.venv");
|
|
54
|
-
const isWindows = process.platform === "win32";
|
|
55
|
-
// Potential Venv Paths
|
|
56
|
-
const potentialVenvPaths = isWindows
|
|
57
|
-
? [
|
|
58
|
-
path.join(venvDir, "Scripts", "python.exe"),
|
|
59
|
-
path.join(venvDir, "bin", "python.exe"),
|
|
60
|
-
]
|
|
61
|
-
: [path.join(venvDir, "bin", "python")];
|
|
62
|
-
let pythonCmd = isWindows ? "python" : "python3";
|
|
63
|
-
for (const venvPath of potentialVenvPaths) {
|
|
64
|
-
if (require("fs").existsSync(venvPath)) {
|
|
65
|
-
pythonCmd = venvPath;
|
|
66
|
-
break;
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
// If we haven't found a venv python, verify the system command exists
|
|
70
|
-
if (pythonCmd === "python" || pythonCmd === "python3") {
|
|
71
|
-
try {
|
|
72
|
-
// Use system python if it exists and works
|
|
73
|
-
require("child_process").execSync(`${pythonCmd} --version`, {
|
|
74
|
-
stdio: "ignore",
|
|
75
|
-
});
|
|
76
|
-
}
|
|
77
|
-
catch {
|
|
78
|
-
// If the preferred one fails, try the fallback
|
|
79
|
-
pythonCmd = pythonCmd === "python3" ? "python" : "python3";
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
engineProcess = (0, child_process_1.spawn)(pythonCmd, [CRYPTO_ENGINE_PATH], {
|
|
83
|
-
stdio: ["pipe", "pipe", "pipe"],
|
|
84
|
-
cwd: path.resolve(__dirname, "../../../../packages/crypto"),
|
|
85
|
-
});
|
|
86
|
-
engineProcess.on("exit", () => {
|
|
87
|
-
engineProcess = null;
|
|
88
|
-
});
|
|
89
|
-
return engineProcess;
|
|
90
|
-
}
|
|
91
|
-
/**
|
|
92
|
-
* Send a command to the crypto engine and get the response.
|
|
93
|
-
*/
|
|
94
|
-
function sendCommand(request) {
|
|
95
|
-
return new Promise((resolve, reject) => {
|
|
96
|
-
const engine = getEngine();
|
|
97
|
-
const onData = (data) => {
|
|
98
|
-
try {
|
|
99
|
-
const response = JSON.parse(data.toString().trim());
|
|
100
|
-
engine.stdout.removeListener("data", onData);
|
|
101
|
-
engine.stderr.removeListener("data", onError);
|
|
102
|
-
if (response.status === "error") {
|
|
103
|
-
reject(new Error(response.message));
|
|
104
|
-
}
|
|
105
|
-
else {
|
|
106
|
-
resolve(response);
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
catch (e) {
|
|
110
|
-
// partial data, wait for more
|
|
111
|
-
}
|
|
112
|
-
};
|
|
113
|
-
const onError = (data) => {
|
|
114
|
-
engine.stdout.removeListener("data", onData);
|
|
115
|
-
engine.stderr.removeListener("data", onError);
|
|
116
|
-
reject(new Error(`Crypto engine error: ${data.toString()}`));
|
|
117
|
-
};
|
|
118
|
-
engine.stdout.on("data", onData);
|
|
119
|
-
engine.stderr.on("data", onError);
|
|
120
|
-
engine.stdin.write(JSON.stringify(request) + "\n");
|
|
121
|
-
});
|
|
11
|
+
const libsodium_wrappers_1 = __importDefault(require("libsodium-wrappers"));
|
|
12
|
+
const buffer_1 = require("buffer");
|
|
13
|
+
async function getSodium() {
|
|
14
|
+
await libsodium_wrappers_1.default.ready;
|
|
15
|
+
return libsodium_wrappers_1.default;
|
|
122
16
|
}
|
|
123
|
-
/**
|
|
124
|
-
* Generate a new X25519 key pair.
|
|
125
|
-
*/
|
|
126
17
|
async function generateKeys() {
|
|
127
|
-
const
|
|
18
|
+
const sodium = await getSodium();
|
|
19
|
+
const keypair = sodium.crypto_box_keypair();
|
|
128
20
|
return {
|
|
129
|
-
private_key:
|
|
130
|
-
public_key:
|
|
21
|
+
private_key: buffer_1.Buffer.from(keypair.privateKey).toString("base64"),
|
|
22
|
+
public_key: buffer_1.Buffer.from(keypair.publicKey).toString("base64"),
|
|
131
23
|
};
|
|
132
24
|
}
|
|
133
|
-
/**
|
|
134
|
-
* Derive the public key from an existing private key.
|
|
135
|
-
*/
|
|
136
25
|
async function derivePublicKey(privateKey) {
|
|
137
|
-
const
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
return result.public_key;
|
|
26
|
+
const sodium = await getSodium();
|
|
27
|
+
const sk = buffer_1.Buffer.from(privateKey, "base64");
|
|
28
|
+
const pk = sodium.crypto_scalarmult_base(sk);
|
|
29
|
+
return buffer_1.Buffer.from(pk).toString("base64");
|
|
142
30
|
}
|
|
143
|
-
/**
|
|
144
|
-
* Encrypt a plaintext value using the recipient's public key (SealedBox).
|
|
145
|
-
*/
|
|
146
31
|
async function encrypt(plaintext, publicKey) {
|
|
147
|
-
const
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
return result.ciphertext;
|
|
32
|
+
const sodium = await getSodium();
|
|
33
|
+
const pk = buffer_1.Buffer.from(publicKey, "base64");
|
|
34
|
+
const encrypted = sodium.crypto_box_seal(sodium.from_string(plaintext), pk);
|
|
35
|
+
return buffer_1.Buffer.from(encrypted).toString("base64");
|
|
152
36
|
}
|
|
153
|
-
/**
|
|
154
|
-
* Decrypt a ciphertext using the recipient's private key (SealedBox).
|
|
155
|
-
*/
|
|
156
37
|
async function decrypt(ciphertext, privateKey) {
|
|
157
|
-
const
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
38
|
+
const sodium = await getSodium();
|
|
39
|
+
const ct = buffer_1.Buffer.from(ciphertext, "base64");
|
|
40
|
+
const sk = buffer_1.Buffer.from(privateKey, "base64");
|
|
41
|
+
// Need to compute public key corresponding to private key for unsealing
|
|
42
|
+
const pk = sodium.crypto_scalarmult_base(sk);
|
|
43
|
+
const decrypted = sodium.crypto_box_seal_open(ct, pk, sk);
|
|
44
|
+
return sodium.to_string(decrypted);
|
|
162
45
|
}
|
|
163
|
-
/**
|
|
164
|
-
* Shut down the crypto engine process.
|
|
165
|
-
*/
|
|
166
46
|
function shutdown() {
|
|
167
|
-
|
|
168
|
-
engineProcess.stdin.end();
|
|
169
|
-
engineProcess.kill();
|
|
170
|
-
engineProcess = null;
|
|
171
|
-
}
|
|
47
|
+
// Graceful stub for backward compatibility
|
|
172
48
|
}
|
|
173
49
|
//# sourceMappingURL=crypto.js.map
|
package/dist/lib/crypto.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"crypto.js","sourceRoot":"","sources":["../../src/lib/crypto.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"crypto.js","sourceRoot":"","sources":["../../src/lib/crypto.ts"],"names":[],"mappings":";;;;;AAQA,oCAUC;AAED,0CAKC;AAED,0BAQC;AAED,0BAaC;AAED,4BAEC;AAtDD,4EAAyC;AACzC,mCAAgC;AAEhC,KAAK,UAAU,SAAS;IACtB,MAAM,4BAAO,CAAC,KAAK,CAAC;IACpB,OAAO,4BAAO,CAAC;AACjB,CAAC;AAEM,KAAK,UAAU,YAAY;IAIhC,MAAM,MAAM,GAAG,MAAM,SAAS,EAAE,CAAC;IACjC,MAAM,OAAO,GAAG,MAAM,CAAC,kBAAkB,EAAE,CAAC;IAC5C,OAAO;QACL,WAAW,EAAE,eAAM,CAAC,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC,QAAQ,CAAC,QAAQ,CAAC;QAC/D,UAAU,EAAE,eAAM,CAAC,IAAI,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC,QAAQ,CAAC,QAAQ,CAAC;KAC9D,CAAC;AACJ,CAAC;AAEM,KAAK,UAAU,eAAe,CAAC,UAAkB;IACtD,MAAM,MAAM,GAAG,MAAM,SAAS,EAAE,CAAC;IACjC,MAAM,EAAE,GAAG,eAAM,CAAC,IAAI,CAAC,UAAU,EAAE,QAAQ,CAAC,CAAC;IAC7C,MAAM,EAAE,GAAG,MAAM,CAAC,sBAAsB,CAAC,EAAE,CAAC,CAAC;IAC7C,OAAO,eAAM,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;AAC5C,CAAC;AAEM,KAAK,U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
23
|
+
"libsodium-wrappers": "^0.8.2",
|
|
23
24
|
"ora": "^5.4.1"
|
|
24
25
|
},
|
|
25
26
|
"devDependencies": {
|
|
26
27
|
"@envtree/eslint-config": "workspace:*",
|
|
27
28
|
"@envtree/typescript-config": "workspace:*",
|
|
28
29
|
"@types/inquirer": "^8.2.10",
|
|
30
|
+
"@types/libsodium-wrappers": "^0.8.2",
|
|
29
31
|
"@types/node": "^22.15.2",
|
|
30
32
|
"tsx": "^4.19.4",
|
|
31
33
|
"typescript": "5.9.2"
|