@sorokchat-messenger/cryptography-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.
Files changed (43) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +1 -0
  3. package/dist/encryption/aes.service.d.ts +11 -0
  4. package/dist/encryption/aes.service.d.ts.map +1 -0
  5. package/dist/encryption/aes.service.js +21 -0
  6. package/dist/encryption/aes.service.js.map +1 -0
  7. package/dist/encryption/aes.spec.d.ts +2 -0
  8. package/dist/encryption/aes.spec.d.ts.map +1 -0
  9. package/dist/encryption/aes.spec.js +25 -0
  10. package/dist/encryption/aes.spec.js.map +1 -0
  11. package/dist/encryption/index.d.ts +2 -0
  12. package/dist/encryption/index.d.ts.map +1 -0
  13. package/dist/encryption/index.js +2 -0
  14. package/dist/encryption/index.js.map +1 -0
  15. package/dist/hashing/index.d.ts +2 -0
  16. package/dist/hashing/index.d.ts.map +1 -0
  17. package/dist/hashing/index.js +2 -0
  18. package/dist/hashing/index.js.map +1 -0
  19. package/dist/hashing/sha256.service.d.ts +5 -0
  20. package/dist/hashing/sha256.service.d.ts.map +1 -0
  21. package/dist/hashing/sha256.service.js +9 -0
  22. package/dist/hashing/sha256.service.js.map +1 -0
  23. package/dist/hashing/sha256.spec.d.ts +2 -0
  24. package/dist/hashing/sha256.spec.d.ts.map +1 -0
  25. package/dist/hashing/sha256.spec.js +18 -0
  26. package/dist/hashing/sha256.spec.js.map +1 -0
  27. package/dist/index.d.ts +4 -0
  28. package/dist/index.d.ts.map +1 -0
  29. package/dist/index.js +4 -0
  30. package/dist/index.js.map +1 -0
  31. package/dist/signing/hmac.service.d.ts +6 -0
  32. package/dist/signing/hmac.service.d.ts.map +1 -0
  33. package/dist/signing/hmac.service.js +18 -0
  34. package/dist/signing/hmac.service.js.map +1 -0
  35. package/dist/signing/hmac.spec.d.ts +2 -0
  36. package/dist/signing/hmac.spec.d.ts.map +1 -0
  37. package/dist/signing/hmac.spec.js +35 -0
  38. package/dist/signing/hmac.spec.js.map +1 -0
  39. package/dist/signing/index.d.ts +2 -0
  40. package/dist/signing/index.d.ts.map +1 -0
  41. package/dist/signing/index.js +2 -0
  42. package/dist/signing/index.js.map +1 -0
  43. package/package.json +47 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026-present Sorokovsky Andrey <Sorokovsky0809@gmail.com>
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1 @@
1
+ # @sorokchat-messenger/cryptography-client
@@ -0,0 +1,11 @@
1
+ import type { IEncryption } from "@sorokchat-messenger/cryptography-abstractions";
2
+ export type AesOptions = {
3
+ iv: string;
4
+ };
5
+ export declare class AesEncryption implements IEncryption<AesOptions> {
6
+ private static readonly ALGORITHM;
7
+ encrypt(plaintext: string, key: string, options: AesOptions): Promise<string>;
8
+ decrypt(ciphertext: string, key: string, options: AesOptions): Promise<string>;
9
+ private padParameter;
10
+ }
11
+ //# sourceMappingURL=aes.service.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"aes.service.d.ts","sourceRoot":"","sources":["../../src/encryption/aes.service.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,gDAAgD,CAAC;AAGlF,MAAM,MAAM,UAAU,GAAG;IACvB,EAAE,EAAE,MAAM,CAAC;CACZ,CAAC;AAEF,qBAAa,aAAc,YAAW,WAAW,CAAC,UAAU,CAAC;IAC3D,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,SAAS,CAAyB;IAE7C,OAAO,CAClB,SAAS,EAAE,MAAM,EACjB,GAAG,EAAE,MAAM,EACX,OAAO,EAAE,UAAU,GAClB,OAAO,CAAC,MAAM,CAAC,CAKjB;IAEY,OAAO,CAClB,UAAU,EAAE,MAAM,EAClB,GAAG,EAAE,MAAM,EACX,OAAO,EAAE,UAAU,GAClB,OAAO,CAAC,MAAM,CAAC,CAWjB;IAED,OAAO,CAAC,YAAY;CAIrB"}
@@ -0,0 +1,21 @@
1
+ import { createCipheriv, createDecipheriv } from "node:crypto";
2
+ export class AesEncryption {
3
+ static ALGORITHM = "aes-128-cbc";
4
+ async encrypt(plaintext, key, options) {
5
+ const keyBuffer = this.padParameter(key);
6
+ const ivBuffer = this.padParameter(options.iv);
7
+ const cipher = createCipheriv(AesEncryption.ALGORITHM, keyBuffer, ivBuffer);
8
+ return cipher.update(plaintext, "utf-8", "hex") + cipher.final("hex");
9
+ }
10
+ async decrypt(ciphertext, key, options) {
11
+ const keyBuffer = this.padParameter(key);
12
+ const ivBuffer = this.padParameter(options.iv);
13
+ const decipher = createDecipheriv(AesEncryption.ALGORITHM, keyBuffer, ivBuffer);
14
+ return (decipher.update(ciphertext, "hex", "utf-8") + decipher.final("utf-8"));
15
+ }
16
+ padParameter(hex) {
17
+ const padded = hex.padEnd(32, "0").substring(0, 32);
18
+ return Buffer.from(padded, "hex");
19
+ }
20
+ }
21
+ //# sourceMappingURL=aes.service.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"aes.service.js","sourceRoot":"","sources":["../../src/encryption/aes.service.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAM/D,MAAM,OAAO,aAAa;IAChB,MAAM,CAAU,SAAS,GAAW,aAAa,CAAC;IAEnD,KAAK,CAAC,OAAO,CAClB,SAAiB,EACjB,GAAW,EACX,OAAmB;QAEnB,MAAM,SAAS,GAAG,IAAI,CAAC,YAAY,CAAC,GAAG,CAAC,CAAC;QACzC,MAAM,QAAQ,GAAG,IAAI,CAAC,YAAY,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC;QAC/C,MAAM,MAAM,GAAG,cAAc,CAAC,aAAa,CAAC,SAAS,EAAE,SAAS,EAAE,QAAQ,CAAC,CAAC;QAC5E,OAAO,MAAM,CAAC,MAAM,CAAC,SAAS,EAAE,OAAO,EAAE,KAAK,CAAC,GAAG,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;IACxE,CAAC;IAEM,KAAK,CAAC,OAAO,CAClB,UAAkB,EAClB,GAAW,EACX,OAAmB;QAEnB,MAAM,SAAS,GAAG,IAAI,CAAC,YAAY,CAAC,GAAG,CAAC,CAAC;QACzC,MAAM,QAAQ,GAAG,IAAI,CAAC,YAAY,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC;QAC/C,MAAM,QAAQ,GAAG,gBAAgB,CAC/B,aAAa,CAAC,SAAS,EACvB,SAAS,EACT,QAAQ,CACT,CAAC;QACF,OAAO,CACL,QAAQ,CAAC,MAAM,CAAC,UAAU,EAAE,KAAK,EAAE,OAAO,CAAC,GAAG,QAAQ,CAAC,KAAK,CAAC,OAAO,CAAC,CACtE,CAAC;IACJ,CAAC;IAEO,YAAY,CAAC,GAAW;QAC9B,MAAM,MAAM,GAAG,GAAG,CAAC,MAAM,CAAC,EAAE,EAAE,GAAG,CAAC,CAAC,SAAS,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;QACpD,OAAO,MAAM,CAAC,IAAI,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;IACpC,CAAC;CACF"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=aes.spec.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"aes.spec.d.ts","sourceRoot":"","sources":["../../src/encryption/aes.spec.ts"],"names":[],"mappings":""}
@@ -0,0 +1,25 @@
1
+ import { beforeAll, describe, expect, it } from "vitest";
2
+ import { AesEncryption } from "./aes.service.js";
3
+ describe("AES tests", () => {
4
+ let encryption;
5
+ const iv = "3ff3321fdcbffffaabb123456785421";
6
+ const key = "54125747abf43213212d4432e3dfacb";
7
+ const plaintext = "Hello, world";
8
+ const ciphertext = "46563a2ee9e4ae7d433735f2f1f5b861";
9
+ const options = { iv };
10
+ beforeAll(() => {
11
+ encryption = new AesEncryption();
12
+ });
13
+ it("Aes must be defined", () => {
14
+ expect(encryption).toBeDefined();
15
+ });
16
+ it("should correct encrypt", async () => {
17
+ const result = await encryption.encrypt(plaintext, key, options);
18
+ expect(result).toEqual(ciphertext);
19
+ });
20
+ it("should correct decrypt", async () => {
21
+ const result = await encryption.decrypt(ciphertext, key, options);
22
+ expect(result).toEqual(plaintext);
23
+ });
24
+ });
25
+ //# sourceMappingURL=aes.spec.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"aes.spec.js","sourceRoot":"","sources":["../../src/encryption/aes.spec.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAC;AACzD,OAAO,EAAE,aAAa,EAAmB,MAAM,kBAAkB,CAAC;AAElE,QAAQ,CAAC,WAAW,EAAE,GAAG,EAAE;IACzB,IAAI,UAAmC,CAAC;IACxC,MAAM,EAAE,GAAW,iCAAiC,CAAC;IACrD,MAAM,GAAG,GAAW,iCAAiC,CAAC;IACtD,MAAM,SAAS,GAAW,cAAc,CAAC;IACzC,MAAM,UAAU,GAAW,kCAAkC,CAAC;IAC9D,MAAM,OAAO,GAAe,EAAE,EAAE,EAAE,CAAC;IACnC,SAAS,CAAC,GAAG,EAAE;QACb,UAAU,GAAG,IAAI,aAAa,EAAE,CAAC;IACnC,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,qBAAqB,EAAE,GAAG,EAAE;QAC7B,MAAM,CAAC,UAAU,CAAC,CAAC,WAAW,EAAE,CAAC;IACnC,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,wBAAwB,EAAE,KAAK,IAAI,EAAE;QACtC,MAAM,MAAM,GAAG,MAAM,UAAU,CAAC,OAAO,CAAC,SAAS,EAAE,GAAG,EAAE,OAAO,CAAC,CAAC;QACjE,MAAM,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC;IACrC,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,wBAAwB,EAAE,KAAK,IAAI,EAAE;QACtC,MAAM,MAAM,GAAG,MAAM,UAAU,CAAC,OAAO,CAAC,UAAU,EAAE,GAAG,EAAE,OAAO,CAAC,CAAC;QAClE,MAAM,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;IACpC,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
@@ -0,0 +1,2 @@
1
+ export * from "./aes.service.js";
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/encryption/index.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAC"}
@@ -0,0 +1,2 @@
1
+ export * from "./aes.service.js";
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/encryption/index.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAC"}
@@ -0,0 +1,2 @@
1
+ export * from "./sha256.service.js";
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/hashing/index.ts"],"names":[],"mappings":"AAAA,cAAc,qBAAqB,CAAC"}
@@ -0,0 +1,2 @@
1
+ export * from "./sha256.service.js";
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/hashing/index.ts"],"names":[],"mappings":"AAAA,cAAc,qBAAqB,CAAC"}
@@ -0,0 +1,5 @@
1
+ import type { IHashing } from "@sorokchat-messenger/cryptography-abstractions";
2
+ export declare class Sha256Hashing implements IHashing {
3
+ hash(plaintext: string): Promise<string>;
4
+ }
5
+ //# sourceMappingURL=sha256.service.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sha256.service.d.ts","sourceRoot":"","sources":["../../src/hashing/sha256.service.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,gDAAgD,CAAC;AAG/E,qBAAa,aAAc,YAAW,QAAQ;IAC/B,IAAI,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAIpD;CACF"}
@@ -0,0 +1,9 @@
1
+ import { createHash } from "node:crypto";
2
+ export class Sha256Hashing {
3
+ async hash(plaintext) {
4
+ return createHash("sha256")
5
+ .update(Buffer.from(plaintext, "utf-8"))
6
+ .digest("hex");
7
+ }
8
+ }
9
+ //# sourceMappingURL=sha256.service.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sha256.service.js","sourceRoot":"","sources":["../../src/hashing/sha256.service.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAEzC,MAAM,OAAO,aAAa;IACjB,KAAK,CAAC,IAAI,CAAC,SAAiB;QACjC,OAAO,UAAU,CAAC,QAAQ,CAAC;aACxB,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,SAAS,EAAE,OAAO,CAAC,CAAC;aACvC,MAAM,CAAC,KAAK,CAAC,CAAC;IACnB,CAAC;CACF"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=sha256.spec.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sha256.spec.d.ts","sourceRoot":"","sources":["../../src/hashing/sha256.spec.ts"],"names":[],"mappings":""}
@@ -0,0 +1,18 @@
1
+ import { beforeAll, describe, expect, it } from "vitest";
2
+ import { Sha256Hashing } from "./sha256.service.js";
3
+ describe("SHA-256 tests", () => {
4
+ let hashing;
5
+ beforeAll(() => {
6
+ hashing = new Sha256Hashing();
7
+ });
8
+ it("should be defined", () => {
9
+ expect(hashing).toBeDefined();
10
+ });
11
+ it("should return correct hash", async () => {
12
+ const plaintext = "hello";
13
+ const result = await hashing.hash(plaintext);
14
+ const expected = "2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824";
15
+ expect(result).toEqual(expected);
16
+ });
17
+ });
18
+ //# sourceMappingURL=sha256.spec.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sha256.spec.js","sourceRoot":"","sources":["../../src/hashing/sha256.spec.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAC;AACzD,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAEpD,QAAQ,CAAC,eAAe,EAAE,GAAG,EAAE;IAC7B,IAAI,OAAiB,CAAC;IACtB,SAAS,CAAC,GAAG,EAAE;QACb,OAAO,GAAG,IAAI,aAAa,EAAE,CAAC;IAChC,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,mBAAmB,EAAE,GAAG,EAAE;QAC3B,MAAM,CAAC,OAAO,CAAC,CAAC,WAAW,EAAE,CAAC;IAChC,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,4BAA4B,EAAE,KAAK,IAAI,EAAE;QAC1C,MAAM,SAAS,GAAW,OAAO,CAAC;QAClC,MAAM,MAAM,GAAW,MAAM,OAAO,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;QACrD,MAAM,QAAQ,GACZ,kEAAkE,CAAC;QACrE,MAAM,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;IACnC,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
@@ -0,0 +1,4 @@
1
+ export * from "./encryption/index.js";
2
+ export * from "./hashing/index.js";
3
+ export * from "./signing/index.js";
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,uBAAuB,CAAC;AACtC,cAAc,oBAAoB,CAAC;AACnC,cAAc,oBAAoB,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,4 @@
1
+ export * from "./encryption/index.js";
2
+ export * from "./hashing/index.js";
3
+ export * from "./signing/index.js";
4
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,uBAAuB,CAAC;AACtC,cAAc,oBAAoB,CAAC;AACnC,cAAc,oBAAoB,CAAC"}
@@ -0,0 +1,6 @@
1
+ import type { ISigning } from "@sorokchat-messenger/cryptography-abstractions";
2
+ export declare class HmacSigning implements ISigning {
3
+ sign(plaintext: string, secret: string): Promise<string>;
4
+ verify(plaintext: string, signing: string, secret: string): Promise<boolean>;
5
+ }
6
+ //# sourceMappingURL=hmac.service.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hmac.service.d.ts","sourceRoot":"","sources":["../../src/signing/hmac.service.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,gDAAgD,CAAC;AAG/E,qBAAa,WAAY,YAAW,QAAQ;IAC7B,IAAI,CAAC,SAAS,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAKpE;IAEY,MAAM,CACjB,SAAS,EAAE,MAAM,EACjB,OAAO,EAAE,MAAM,EACf,MAAM,EAAE,MAAM,GACb,OAAO,CAAC,OAAO,CAAC,CAMlB;CACF"}
@@ -0,0 +1,18 @@
1
+ import { createHmac, timingSafeEqual } from "node:crypto";
2
+ export class HmacSigning {
3
+ async sign(plaintext, secret) {
4
+ const secretBuffer = Buffer.from(secret, "utf-8");
5
+ const hmac = createHmac("sha256", secretBuffer);
6
+ hmac.update(plaintext, "utf-8");
7
+ return hmac.digest("hex");
8
+ }
9
+ async verify(plaintext, signing, secret) {
10
+ const actualSigning = await this.sign(plaintext, secret);
11
+ const actualBuffer = Buffer.from(actualSigning, "hex");
12
+ const expectedBuffer = Buffer.from(signing, "hex");
13
+ if (actualBuffer.length !== expectedBuffer.length)
14
+ return false;
15
+ return timingSafeEqual(actualBuffer, expectedBuffer);
16
+ }
17
+ }
18
+ //# sourceMappingURL=hmac.service.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hmac.service.js","sourceRoot":"","sources":["../../src/signing/hmac.service.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAE1D,MAAM,OAAO,WAAW;IACf,KAAK,CAAC,IAAI,CAAC,SAAiB,EAAE,MAAc;QACjD,MAAM,YAAY,GAAG,MAAM,CAAC,IAAI,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;QAClD,MAAM,IAAI,GAAG,UAAU,CAAC,QAAQ,EAAE,YAAY,CAAC,CAAC;QAChD,IAAI,CAAC,MAAM,CAAC,SAAS,EAAE,OAAO,CAAC,CAAC;QAChC,OAAO,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;IAC5B,CAAC;IAEM,KAAK,CAAC,MAAM,CACjB,SAAiB,EACjB,OAAe,EACf,MAAc;QAEd,MAAM,aAAa,GAAG,MAAM,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,MAAM,CAAC,CAAC;QACzD,MAAM,YAAY,GAAG,MAAM,CAAC,IAAI,CAAC,aAAa,EAAE,KAAK,CAAC,CAAC;QACvD,MAAM,cAAc,GAAG,MAAM,CAAC,IAAI,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;QACnD,IAAI,YAAY,CAAC,MAAM,KAAK,cAAc,CAAC,MAAM;YAAE,OAAO,KAAK,CAAC;QAChE,OAAO,eAAe,CAAC,YAAY,EAAE,cAAc,CAAC,CAAC;IACvD,CAAC;CACF"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=hmac.spec.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hmac.spec.d.ts","sourceRoot":"","sources":["../../src/signing/hmac.spec.ts"],"names":[],"mappings":""}
@@ -0,0 +1,35 @@
1
+ import { beforeAll, describe, expect, it } from "vitest";
2
+ import { HmacSigning } from "./hmac.service.js";
3
+ describe("HMAC tests", () => {
4
+ let signing;
5
+ const plaintext = "Hello, world";
6
+ const secret = "secret key";
7
+ const expectedSigning = "81e2384ce666bc4061ce89bc948636dc1ccd96d2e689533a604c506fce614629";
8
+ beforeAll(() => {
9
+ signing = new HmacSigning();
10
+ });
11
+ it("should successfully sign plaintext", async () => {
12
+ const result = await signing.sign(plaintext, secret);
13
+ expect(result).toBe(expectedSigning);
14
+ });
15
+ it("should successfully verify valid signature", async () => {
16
+ const isValid = await signing.verify(plaintext, expectedSigning, secret);
17
+ expect(isValid).toBeTruthy();
18
+ });
19
+ it("should fail verification if plaintext was modified", async () => {
20
+ const modifiedPlaintext = "Hello, world!";
21
+ const isValid = await signing.verify(modifiedPlaintext, expectedSigning, secret);
22
+ expect(isValid).toBeFalsy();
23
+ });
24
+ it("should fail verification if secret is incorrect", async () => {
25
+ const wrongSecret = "wrong key";
26
+ const isValid = await signing.verify(plaintext, expectedSigning, wrongSecret);
27
+ expect(isValid).toBeFalsy();
28
+ });
29
+ it("should fail verification if signature is corrupted", async () => {
30
+ const corruptedSigning = expectedSigning.replace("81e2", "0000");
31
+ const isValid = await signing.verify(plaintext, corruptedSigning, secret);
32
+ expect(isValid).toBeFalsy();
33
+ });
34
+ });
35
+ //# sourceMappingURL=hmac.spec.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hmac.spec.js","sourceRoot":"","sources":["../../src/signing/hmac.spec.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAC;AACzD,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAEhD,QAAQ,CAAC,YAAY,EAAE,GAAG,EAAE;IAC1B,IAAI,OAAiB,CAAC;IACtB,MAAM,SAAS,GAAW,cAAc,CAAC;IACzC,MAAM,MAAM,GAAW,YAAY,CAAC;IACpC,MAAM,eAAe,GACnB,kEAAkE,CAAC;IACrE,SAAS,CAAC,GAAG,EAAE;QACb,OAAO,GAAG,IAAI,WAAW,EAAE,CAAC;IAC9B,CAAC,CAAC,CAAC;IACH,EAAE,CAAC,oCAAoC,EAAE,KAAK,IAAI,EAAE;QAClD,MAAM,MAAM,GAAG,MAAM,OAAO,CAAC,IAAI,CAAC,SAAS,EAAE,MAAM,CAAC,CAAC;QACrD,MAAM,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,eAAe,CAAC,CAAC;IACvC,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,4CAA4C,EAAE,KAAK,IAAI,EAAE;QAC1D,MAAM,OAAO,GAAG,MAAM,OAAO,CAAC,MAAM,CAAC,SAAS,EAAE,eAAe,EAAE,MAAM,CAAC,CAAC;QACzE,MAAM,CAAC,OAAO,CAAC,CAAC,UAAU,EAAE,CAAC;IAC/B,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,oDAAoD,EAAE,KAAK,IAAI,EAAE;QAClE,MAAM,iBAAiB,GAAG,eAAe,CAAC;QAC1C,MAAM,OAAO,GAAG,MAAM,OAAO,CAAC,MAAM,CAClC,iBAAiB,EACjB,eAAe,EACf,MAAM,CACP,CAAC;QACF,MAAM,CAAC,OAAO,CAAC,CAAC,SAAS,EAAE,CAAC;IAC9B,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,iDAAiD,EAAE,KAAK,IAAI,EAAE;QAC/D,MAAM,WAAW,GAAG,WAAW,CAAC;QAChC,MAAM,OAAO,GAAG,MAAM,OAAO,CAAC,MAAM,CAClC,SAAS,EACT,eAAe,EACf,WAAW,CACZ,CAAC;QACF,MAAM,CAAC,OAAO,CAAC,CAAC,SAAS,EAAE,CAAC;IAC9B,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,oDAAoD,EAAE,KAAK,IAAI,EAAE;QAClE,MAAM,gBAAgB,GAAG,eAAe,CAAC,OAAO,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;QACjE,MAAM,OAAO,GAAG,MAAM,OAAO,CAAC,MAAM,CAAC,SAAS,EAAE,gBAAgB,EAAE,MAAM,CAAC,CAAC;QAC1E,MAAM,CAAC,OAAO,CAAC,CAAC,SAAS,EAAE,CAAC;IAC9B,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
@@ -0,0 +1,2 @@
1
+ export * from "./hmac.service.js";
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/signing/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAC"}
@@ -0,0 +1,2 @@
1
+ export * from "./hmac.service.js";
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/signing/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAC"}
package/package.json ADDED
@@ -0,0 +1,47 @@
1
+ {
2
+ "name": "@sorokchat-messenger/cryptography-node",
3
+ "version": "1.0.0",
4
+ "description": "Cryptography node api for sorokchat security messanger",
5
+ "keywords": [
6
+ "node",
7
+ "cryptography",
8
+ "messenger",
9
+ "secure"
10
+ ],
11
+ "publishConfig": {
12
+ "access": "public"
13
+ },
14
+ "homepage": "https://github.com/sorokchat-messenger/cryptography-node#readme",
15
+ "bugs": {
16
+ "url": "https://github.com/sorokchat-messenger/cryptography-node/issues"
17
+ },
18
+ "repository": {
19
+ "type": "git",
20
+ "url": "git+ssh://git@github.com/sorokchat-messenger/cryptography-node.git"
21
+ },
22
+ "license": "MIT",
23
+ "author": "Sorokovsky Andrey <Sorokovsky0809@gmail.com>",
24
+ "type": "module",
25
+ "main": "./dist/index.js",
26
+ "types": "./dist/index.d.ts",
27
+ "scripts": {
28
+ "build": "tsc",
29
+ "test": "vitest run"
30
+ },
31
+ "files": ["dist"],
32
+ "exports": {
33
+ ".": {
34
+ "import": "./dist/index.js",
35
+ "types": "./dist/index.d.ts"
36
+ }
37
+ },
38
+ "devDependencies": {
39
+ "@sorokchat-messenger/core": "^1.0.0",
40
+ "@sorokchat-messenger/cryptography-abstractions": "^1.0.2",
41
+ "@types/node": "^22.20.2",
42
+ "prettier": "^3.9.6"
43
+ },
44
+ "dependencies": {
45
+ "vitest": "^5.0.0"
46
+ }
47
+ }