@oesp/keystore-node 6.0.0 → 7.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/dist/index.cjs +76 -0
- package/dist/index.d.cts +9 -0
- package/dist/index.d.ts +5 -2
- package/dist/index.js +47 -37
- package/package.json +6 -12
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
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
1
|
+
import { KeyStore, Identity } from '@oesp/core';
|
|
2
|
+
|
|
3
|
+
declare class NodeFileKeyStore implements KeyStore {
|
|
3
4
|
private path;
|
|
4
5
|
constructor(path: string);
|
|
5
6
|
getOrCreateIdentity(): Promise<Identity>;
|
|
6
7
|
}
|
|
8
|
+
|
|
9
|
+
export { NodeFileKeyStore };
|
package/dist/index.js
CHANGED
|
@@ -1,38 +1,48 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
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;
|
|
6
43
|
}
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
return {
|
|
13
|
-
ed25519Priv: Uint8Array.from(json.ed25519Priv),
|
|
14
|
-
ed25519Pub: Uint8Array.from(json.ed25519Pub),
|
|
15
|
-
x25519Priv: Uint8Array.from(json.x25519Priv),
|
|
16
|
-
x25519Pub: Uint8Array.from(json.x25519Pub)
|
|
17
|
-
};
|
|
18
|
-
}
|
|
19
|
-
catch {
|
|
20
|
-
const ed = sodium.crypto_sign_keypair();
|
|
21
|
-
const x = sodium.crypto_kx_keypair(); // curve25519 keypair
|
|
22
|
-
const id = {
|
|
23
|
-
ed25519Priv: ed.privateKey,
|
|
24
|
-
ed25519Pub: ed.publicKey,
|
|
25
|
-
x25519Priv: x.privateKey,
|
|
26
|
-
x25519Pub: x.publicKey
|
|
27
|
-
};
|
|
28
|
-
await fs.mkdir(require('path').dirname(this.path), { recursive: true });
|
|
29
|
-
await fs.writeFile(this.path, JSON.stringify({
|
|
30
|
-
ed25519Priv: Array.from(id.ed25519Priv),
|
|
31
|
-
ed25519Pub: Array.from(id.ed25519Pub),
|
|
32
|
-
x25519Priv: Array.from(id.x25519Priv),
|
|
33
|
-
x25519Pub: Array.from(id.x25519Pub)
|
|
34
|
-
}));
|
|
35
|
-
return id;
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
}
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
export {
|
|
47
|
+
NodeFileKeyStore
|
|
48
|
+
};
|
package/package.json
CHANGED
|
@@ -1,20 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@oesp/keystore-node",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "7.0.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "KeyStore Node (fichier JSON)",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"type": "module",
|
|
8
8
|
"main": "dist/index.js",
|
|
9
9
|
"types": "dist/index.d.ts",
|
|
10
|
-
"exports": {
|
|
11
|
-
".": {
|
|
12
|
-
"types": "./dist/index.d.ts",
|
|
13
|
-
"import": "./dist/index.js",
|
|
14
|
-
"require": "./dist/index.cjs"
|
|
15
|
-
}
|
|
16
|
-
},
|
|
17
|
-
"sideEffects": false,
|
|
18
10
|
"files": [
|
|
19
11
|
"dist"
|
|
20
12
|
],
|
|
@@ -22,8 +14,10 @@
|
|
|
22
14
|
"access": "public"
|
|
23
15
|
},
|
|
24
16
|
"dependencies": {
|
|
25
|
-
"
|
|
26
|
-
|
|
17
|
+
"@oesp/core": "7.0.0"
|
|
18
|
+
},
|
|
19
|
+
"peerDependencies": {
|
|
20
|
+
"libsodium-wrappers-sumo": "^0.7.14 || ^0.8.0"
|
|
27
21
|
},
|
|
28
22
|
"devDependencies": {
|
|
29
23
|
"@types/libsodium-wrappers": "^0.7.14",
|
|
@@ -32,7 +26,7 @@
|
|
|
32
26
|
"typescript": "^5.6.3"
|
|
33
27
|
},
|
|
34
28
|
"scripts": {
|
|
35
|
-
"build": "
|
|
29
|
+
"build": "tsup src/index.ts --dts --format esm,cjs",
|
|
36
30
|
"lint": "tsc -p tsconfig.json --noEmit"
|
|
37
31
|
}
|
|
38
32
|
}
|