@oesp/keystore-node 1.0.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/README.md +18 -0
- package/dist/index.cjs +76 -0
- package/dist/index.d.cts +9 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.js +48 -0
- package/package.json +30 -0
package/README.md
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
# @oesp/keystore-node
|
|
2
|
+
|
|
3
|
+
Implémentation de `KeyStore` pour OESP stockant l'identité dans un fichier JSON local. Conçu pour les environnements Node.js.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @oesp/keystore-node
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Utilisation
|
|
12
|
+
|
|
13
|
+
```ts
|
|
14
|
+
import { NodeFileKeyStore } from '@oesp/keystore-node';
|
|
15
|
+
|
|
16
|
+
const keystore = new NodeFileKeyStore('./identity.json');
|
|
17
|
+
// L'identité sera créée automatiquement si le fichier n'existe pas
|
|
18
|
+
```
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
|
|
30
|
+
// src/index.ts
|
|
31
|
+
var index_exports = {};
|
|
32
|
+
__export(index_exports, {
|
|
33
|
+
NodeFileKeyStore: () => NodeFileKeyStore
|
|
34
|
+
});
|
|
35
|
+
module.exports = __toCommonJS(index_exports);
|
|
36
|
+
var import_fs = require("fs");
|
|
37
|
+
var import_libsodium_wrappers_sumo = __toESM(require("libsodium-wrappers-sumo"), 1);
|
|
38
|
+
var NodeFileKeyStore = class {
|
|
39
|
+
constructor(path) {
|
|
40
|
+
this.path = path;
|
|
41
|
+
}
|
|
42
|
+
async getOrCreateIdentity() {
|
|
43
|
+
await import_libsodium_wrappers_sumo.default.ready;
|
|
44
|
+
try {
|
|
45
|
+
const buf = await import_fs.promises.readFile(this.path);
|
|
46
|
+
const json = JSON.parse(buf.toString("utf-8"));
|
|
47
|
+
return {
|
|
48
|
+
ed25519Priv: Uint8Array.from(json.ed25519Priv),
|
|
49
|
+
ed25519Pub: Uint8Array.from(json.ed25519Pub),
|
|
50
|
+
x25519Priv: Uint8Array.from(json.x25519Priv),
|
|
51
|
+
x25519Pub: Uint8Array.from(json.x25519Pub)
|
|
52
|
+
};
|
|
53
|
+
} catch {
|
|
54
|
+
const ed = import_libsodium_wrappers_sumo.default.crypto_sign_keypair();
|
|
55
|
+
const x = import_libsodium_wrappers_sumo.default.crypto_kx_keypair();
|
|
56
|
+
const id = {
|
|
57
|
+
ed25519Priv: ed.privateKey,
|
|
58
|
+
ed25519Pub: ed.publicKey,
|
|
59
|
+
x25519Priv: x.privateKey,
|
|
60
|
+
x25519Pub: x.publicKey
|
|
61
|
+
};
|
|
62
|
+
await import_fs.promises.mkdir(require("path").dirname(this.path), { recursive: true });
|
|
63
|
+
await import_fs.promises.writeFile(this.path, JSON.stringify({
|
|
64
|
+
ed25519Priv: Array.from(id.ed25519Priv),
|
|
65
|
+
ed25519Pub: Array.from(id.ed25519Pub),
|
|
66
|
+
x25519Priv: Array.from(id.x25519Priv),
|
|
67
|
+
x25519Pub: Array.from(id.x25519Pub)
|
|
68
|
+
}));
|
|
69
|
+
return id;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
74
|
+
0 && (module.exports = {
|
|
75
|
+
NodeFileKeyStore
|
|
76
|
+
});
|
package/dist/index.d.cts
ADDED
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
2
|
+
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
3
|
+
}) : x)(function(x) {
|
|
4
|
+
if (typeof require !== "undefined") return require.apply(this, arguments);
|
|
5
|
+
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
6
|
+
});
|
|
7
|
+
|
|
8
|
+
// src/index.ts
|
|
9
|
+
import { promises as fs } from "fs";
|
|
10
|
+
import sodium from "libsodium-wrappers-sumo";
|
|
11
|
+
var NodeFileKeyStore = class {
|
|
12
|
+
constructor(path) {
|
|
13
|
+
this.path = path;
|
|
14
|
+
}
|
|
15
|
+
async getOrCreateIdentity() {
|
|
16
|
+
await sodium.ready;
|
|
17
|
+
try {
|
|
18
|
+
const buf = await fs.readFile(this.path);
|
|
19
|
+
const json = JSON.parse(buf.toString("utf-8"));
|
|
20
|
+
return {
|
|
21
|
+
ed25519Priv: Uint8Array.from(json.ed25519Priv),
|
|
22
|
+
ed25519Pub: Uint8Array.from(json.ed25519Pub),
|
|
23
|
+
x25519Priv: Uint8Array.from(json.x25519Priv),
|
|
24
|
+
x25519Pub: Uint8Array.from(json.x25519Pub)
|
|
25
|
+
};
|
|
26
|
+
} catch {
|
|
27
|
+
const ed = sodium.crypto_sign_keypair();
|
|
28
|
+
const x = sodium.crypto_kx_keypair();
|
|
29
|
+
const id = {
|
|
30
|
+
ed25519Priv: ed.privateKey,
|
|
31
|
+
ed25519Pub: ed.publicKey,
|
|
32
|
+
x25519Priv: x.privateKey,
|
|
33
|
+
x25519Pub: x.publicKey
|
|
34
|
+
};
|
|
35
|
+
await fs.mkdir(__require("path").dirname(this.path), { recursive: true });
|
|
36
|
+
await fs.writeFile(this.path, JSON.stringify({
|
|
37
|
+
ed25519Priv: Array.from(id.ed25519Priv),
|
|
38
|
+
ed25519Pub: Array.from(id.ed25519Pub),
|
|
39
|
+
x25519Priv: Array.from(id.x25519Priv),
|
|
40
|
+
x25519Pub: Array.from(id.x25519Pub)
|
|
41
|
+
}));
|
|
42
|
+
return id;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
export {
|
|
47
|
+
NodeFileKeyStore
|
|
48
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@oesp/keystore-node",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"private": false,
|
|
5
|
+
"description": "KeyStore Node (fichier JSON)",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"type": "module",
|
|
8
|
+
"main": "dist/index.js",
|
|
9
|
+
"types": "dist/index.d.ts",
|
|
10
|
+
"files": [
|
|
11
|
+
"dist"
|
|
12
|
+
],
|
|
13
|
+
"publishConfig": {
|
|
14
|
+
"access": "public"
|
|
15
|
+
},
|
|
16
|
+
"scripts": {
|
|
17
|
+
"build": "tsup src/index.ts --dts --format esm,cjs",
|
|
18
|
+
"lint": "tsc -p tsconfig.json --noEmit"
|
|
19
|
+
},
|
|
20
|
+
"dependencies": {
|
|
21
|
+
"libsodium-wrappers-sumo": "^0.7.14",
|
|
22
|
+
"@oesp/core": "workspace:*"
|
|
23
|
+
},
|
|
24
|
+
"devDependencies": {
|
|
25
|
+
"@types/libsodium-wrappers": "^0.7.14",
|
|
26
|
+
"@types/node": "^20.0.0",
|
|
27
|
+
"tsup": "^8.0.1",
|
|
28
|
+
"typescript": "^5.6.3"
|
|
29
|
+
}
|
|
30
|
+
}
|