@oesp/crypto-sodium 4.0.0 → 6.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.d.ts CHANGED
@@ -1,6 +1,5 @@
1
- import { CryptoProvider } from '@oesp/core';
2
-
3
- declare class SodiumCryptoProvider implements CryptoProvider {
1
+ import type { CryptoProvider } from '@oesp/core';
2
+ export declare class SodiumCryptoProvider implements CryptoProvider {
4
3
  private ready;
5
4
  constructor();
6
5
  private ensureReady;
@@ -17,6 +16,4 @@ declare class SodiumCryptoProvider implements CryptoProvider {
17
16
  aeadDecrypt(key: Uint8Array, iv: Uint8Array, ct: Uint8Array, aad: Uint8Array): Uint8Array;
18
17
  randomBytes(n: number): Uint8Array;
19
18
  }
20
- declare function createSodiumCryptoProvider(): Promise<SodiumCryptoProvider>;
21
-
22
- export { SodiumCryptoProvider, createSodiumCryptoProvider };
19
+ export declare function createSodiumCryptoProvider(): Promise<SodiumCryptoProvider>;
package/dist/index.js CHANGED
@@ -1,47 +1,43 @@
1
- // src/index.ts
2
- import sodium from "libsodium-wrappers-sumo";
3
- var SodiumCryptoProvider = class {
4
- constructor() {
5
- this.ensureReady = async () => {
6
- await this.ready;
7
- };
8
- this.ready = sodium.ready;
9
- }
10
- sha256(bytes) {
11
- return sodium.crypto_hash_sha256(bytes);
12
- }
13
- ed25519Sign(priv, data) {
14
- return sodium.crypto_sign_detached(data, priv);
15
- }
16
- ed25519Verify(pub, data, sig) {
17
- return sodium.crypto_sign_verify_detached(sig, data, pub);
18
- }
19
- x25519Seal(recipientPub, sessionKey) {
20
- const sk = sodium.crypto_box_seal(sessionKey, recipientPub);
21
- return sk;
22
- }
23
- x25519Open(recipientPriv, sealed) {
24
- const pub = sodium.crypto_scalarmult_base(recipientPriv);
25
- const opened = sodium.crypto_box_seal_open(sealed, pub, recipientPriv);
26
- return opened;
27
- }
28
- aeadEncrypt(key, plaintext, aad) {
29
- const iv = sodium.randombytes_buf(sodium.crypto_aead_chacha20poly1305_ietf_NPUBBYTES);
30
- const ct = sodium.crypto_aead_chacha20poly1305_ietf_encrypt(plaintext, aad, null, iv, key);
31
- return { iv, ct };
32
- }
33
- aeadDecrypt(key, iv, ct, aad) {
34
- return sodium.crypto_aead_chacha20poly1305_ietf_decrypt(null, ct, aad, iv, key);
35
- }
36
- randomBytes(n) {
37
- return sodium.randombytes_buf(n);
38
- }
39
- };
40
- async function createSodiumCryptoProvider() {
41
- await sodium.ready;
42
- return new SodiumCryptoProvider();
1
+ import sodium from 'libsodium-wrappers-sumo';
2
+ export class SodiumCryptoProvider {
3
+ constructor() {
4
+ this.ensureReady = async () => { await this.ready; };
5
+ this.ready = sodium.ready;
6
+ }
7
+ sha256(bytes) {
8
+ return sodium.crypto_hash_sha256(bytes);
9
+ }
10
+ ed25519Sign(priv, data) {
11
+ return sodium.crypto_sign_detached(data, priv);
12
+ }
13
+ ed25519Verify(pub, data, sig) {
14
+ return sodium.crypto_sign_verify_detached(sig, data, pub);
15
+ }
16
+ x25519Seal(recipientPub, sessionKey) {
17
+ // Use sealed box to wrap sessionKey (demo)
18
+ const sk = sodium.crypto_box_seal(sessionKey, recipientPub);
19
+ return sk;
20
+ }
21
+ x25519Open(recipientPriv, sealed) {
22
+ // For sealed box, we need recipient keypair; derive public from priv using sodium
23
+ const pub = sodium.crypto_scalarmult_base(recipientPriv);
24
+ const opened = sodium.crypto_box_seal_open(sealed, pub, recipientPriv);
25
+ return opened;
26
+ }
27
+ aeadEncrypt(key, plaintext, aad) {
28
+ const iv = sodium.randombytes_buf(sodium.crypto_aead_chacha20poly1305_ietf_NPUBBYTES);
29
+ const ct = sodium.crypto_aead_chacha20poly1305_ietf_encrypt(plaintext, aad, null, iv, key);
30
+ // Sodium returns ciphertext+tag together; we keep it as ct
31
+ return { iv, ct };
32
+ }
33
+ aeadDecrypt(key, iv, ct, aad) {
34
+ return sodium.crypto_aead_chacha20poly1305_ietf_decrypt(null, ct, aad, iv, key);
35
+ }
36
+ randomBytes(n) {
37
+ return sodium.randombytes_buf(n);
38
+ }
39
+ }
40
+ export async function createSodiumCryptoProvider() {
41
+ await sodium.ready;
42
+ return new SodiumCryptoProvider();
43
43
  }
44
- export {
45
- SodiumCryptoProvider,
46
- createSodiumCryptoProvider
47
- };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@oesp/crypto-sodium",
3
- "version": "4.0.0",
3
+ "version": "6.0.0",
4
4
  "private": false,
5
5
  "description": "CryptoProvider via libsodium-wrappers (Node+Browser)",
6
6
  "license": "MIT",
@@ -23,7 +23,7 @@
23
23
  },
24
24
  "dependencies": {
25
25
  "libsodium-wrappers-sumo": "^0.7.14",
26
- "@oesp/core": "4.0.0"
26
+ "@oesp/core": "6.0.0"
27
27
  },
28
28
  "devDependencies": {
29
29
  "@types/libsodium-wrappers": "^0.7.14",
@@ -31,7 +31,7 @@
31
31
  "typescript": "^5.6.3"
32
32
  },
33
33
  "scripts": {
34
- "build": "tsup src/index.ts --dts --format esm,cjs",
34
+ "build": "tsc -p tsconfig.build.json",
35
35
  "lint": "tsc -p tsconfig.json --noEmit"
36
36
  }
37
37
  }
package/dist/index.cjs DELETED
@@ -1,83 +0,0 @@
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
- SodiumCryptoProvider: () => SodiumCryptoProvider,
34
- createSodiumCryptoProvider: () => createSodiumCryptoProvider
35
- });
36
- module.exports = __toCommonJS(index_exports);
37
- var import_libsodium_wrappers_sumo = __toESM(require("libsodium-wrappers-sumo"), 1);
38
- var SodiumCryptoProvider = class {
39
- constructor() {
40
- this.ensureReady = async () => {
41
- await this.ready;
42
- };
43
- this.ready = import_libsodium_wrappers_sumo.default.ready;
44
- }
45
- sha256(bytes) {
46
- return import_libsodium_wrappers_sumo.default.crypto_hash_sha256(bytes);
47
- }
48
- ed25519Sign(priv, data) {
49
- return import_libsodium_wrappers_sumo.default.crypto_sign_detached(data, priv);
50
- }
51
- ed25519Verify(pub, data, sig) {
52
- return import_libsodium_wrappers_sumo.default.crypto_sign_verify_detached(sig, data, pub);
53
- }
54
- x25519Seal(recipientPub, sessionKey) {
55
- const sk = import_libsodium_wrappers_sumo.default.crypto_box_seal(sessionKey, recipientPub);
56
- return sk;
57
- }
58
- x25519Open(recipientPriv, sealed) {
59
- const pub = import_libsodium_wrappers_sumo.default.crypto_scalarmult_base(recipientPriv);
60
- const opened = import_libsodium_wrappers_sumo.default.crypto_box_seal_open(sealed, pub, recipientPriv);
61
- return opened;
62
- }
63
- aeadEncrypt(key, plaintext, aad) {
64
- const iv = import_libsodium_wrappers_sumo.default.randombytes_buf(import_libsodium_wrappers_sumo.default.crypto_aead_chacha20poly1305_ietf_NPUBBYTES);
65
- const ct = import_libsodium_wrappers_sumo.default.crypto_aead_chacha20poly1305_ietf_encrypt(plaintext, aad, null, iv, key);
66
- return { iv, ct };
67
- }
68
- aeadDecrypt(key, iv, ct, aad) {
69
- return import_libsodium_wrappers_sumo.default.crypto_aead_chacha20poly1305_ietf_decrypt(null, ct, aad, iv, key);
70
- }
71
- randomBytes(n) {
72
- return import_libsodium_wrappers_sumo.default.randombytes_buf(n);
73
- }
74
- };
75
- async function createSodiumCryptoProvider() {
76
- await import_libsodium_wrappers_sumo.default.ready;
77
- return new SodiumCryptoProvider();
78
- }
79
- // Annotate the CommonJS export names for ESM import in node:
80
- 0 && (module.exports = {
81
- SodiumCryptoProvider,
82
- createSodiumCryptoProvider
83
- });
package/dist/index.d.cts DELETED
@@ -1,22 +0,0 @@
1
- import { CryptoProvider } from '@oesp/core';
2
-
3
- declare class SodiumCryptoProvider implements CryptoProvider {
4
- private ready;
5
- constructor();
6
- private ensureReady;
7
- sha256(bytes: Uint8Array): Uint8Array;
8
- ed25519Sign(priv: Uint8Array, data: Uint8Array): Uint8Array;
9
- ed25519Verify(pub: Uint8Array, data: Uint8Array, sig: Uint8Array): boolean;
10
- x25519Seal(recipientPub: Uint8Array, sessionKey: Uint8Array): Uint8Array;
11
- x25519Open(recipientPriv: Uint8Array, sealed: Uint8Array): Uint8Array;
12
- aeadEncrypt(key: Uint8Array, plaintext: Uint8Array, aad: Uint8Array): {
13
- iv: Uint8Array;
14
- ct: Uint8Array;
15
- tag?: Uint8Array;
16
- };
17
- aeadDecrypt(key: Uint8Array, iv: Uint8Array, ct: Uint8Array, aad: Uint8Array): Uint8Array;
18
- randomBytes(n: number): Uint8Array;
19
- }
20
- declare function createSodiumCryptoProvider(): Promise<SodiumCryptoProvider>;
21
-
22
- export { SodiumCryptoProvider, createSodiumCryptoProvider };