@open-norantec/utilities 1.0.1-alpha.12 → 1.0.1-alpha.14

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.
@@ -0,0 +1,11 @@
1
+ /// <reference types="node" />
2
+ /// <reference types="node" />
3
+ import * as crypto from 'node:crypto';
4
+ export declare class ECDHUtil {
5
+ protected readonly privateKey: Buffer;
6
+ protected readonly ALGORITHM: crypto.CipherGCMTypes;
7
+ protected readonly ecdh: crypto.ECDH;
8
+ constructor(privateKey: Buffer);
9
+ encrypt(data: string, otherPublicKey: Buffer): string;
10
+ decrypt(encryptedData: string, otherPublicKey: Buffer): string;
11
+ }
@@ -0,0 +1,33 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ECDHUtil = void 0;
4
+ const crypto = require("node:crypto");
5
+ class ECDHUtil {
6
+ constructor(privateKey) {
7
+ this.privateKey = privateKey;
8
+ this.ALGORITHM = 'aes-256-gcm';
9
+ this.ecdh = crypto.createECDH('secp256k1');
10
+ this.ecdh.setPrivateKey(new Uint8Array(privateKey));
11
+ }
12
+ encrypt(data, otherPublicKey) {
13
+ const sharedKey = this.ecdh.computeSecret(new Uint8Array(otherPublicKey));
14
+ const iv = crypto.randomBytes(16);
15
+ const cipher = crypto.createCipheriv(this.ALGORITHM, new Uint8Array(sharedKey), new Uint8Array(iv));
16
+ const encrypted = Buffer.concat([new Uint8Array(cipher.update(data, 'utf-8')), new Uint8Array(cipher.final())]);
17
+ return Buffer.concat([new Uint8Array(iv), new Uint8Array(encrypted), new Uint8Array(cipher.getAuthTag())]).toString('base64');
18
+ }
19
+ decrypt(encryptedData, otherPublicKey) {
20
+ const sharedKey = this.ecdh.computeSecret(new Uint8Array(otherPublicKey));
21
+ const data = Buffer.from(encryptedData, 'base64');
22
+ const iv = data.subarray(0, 16);
23
+ const authTag = data.subarray(data.length - 16);
24
+ const encrypted = data.subarray(16, data.length - 16);
25
+ const decipher = crypto.createDecipheriv(this.ALGORITHM, new Uint8Array(sharedKey), new Uint8Array(iv));
26
+ decipher.setAuthTag(new Uint8Array(authTag));
27
+ return Buffer.concat([
28
+ new Uint8Array(decipher.update(new Uint8Array(encrypted))),
29
+ new Uint8Array(decipher.final()),
30
+ ]).toString('utf-8');
31
+ }
32
+ }
33
+ exports.ECDHUtil = ECDHUtil;
@@ -51,7 +51,7 @@ export declare namespace Enum {
51
51
  };
52
52
  }
53
53
  export declare class SchemaUtil {
54
- static createEnumSchema<const T extends Record<string, string>>(object: T): z.ZodEnum<[T[keyof T], ...T[keyof T][]]>;
54
+ static createEnumSchema<const T extends Record<string, string>>(object: T, params?: z.RawCreateParams): z.ZodEnum<[T[keyof T], ...T[keyof T][]]>;
55
55
  static readonly ID: z.ZodString;
56
56
  static readonly ID_LIST: z.ZodArray<z.ZodString, "many">;
57
57
  static readonly ID_LIST_OBJECT: z.ZodObject<{
@@ -60,8 +60,8 @@ var Enum;
60
60
  };
61
61
  })(Enum || (exports.Enum = Enum = {}));
62
62
  class SchemaUtil {
63
- static createEnumSchema(object) {
64
- return zod_1.z.enum(Object.values(object));
63
+ static createEnumSchema(object, params) {
64
+ return zod_1.z.enum(Object.values(object), params);
65
65
  }
66
66
  }
67
67
  exports.SchemaUtil = SchemaUtil;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@open-norantec/utilities",
3
- "version": "1.0.1-alpha.12",
3
+ "version": "1.0.1-alpha.14",
4
4
  "description": "NoranTec Utilities",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {