@oesp/crypto-sodium 2.0.0 → 5.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,12 +1,20 @@
1
1
  {
2
2
  "name": "@oesp/crypto-sodium",
3
- "version": "2.0.0",
3
+ "version": "5.0.0",
4
4
  "private": false,
5
5
  "description": "CryptoProvider via libsodium-wrappers (Node+Browser)",
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,
10
18
  "files": [
11
19
  "dist"
12
20
  ],
@@ -15,7 +23,7 @@
15
23
  },
16
24
  "dependencies": {
17
25
  "libsodium-wrappers-sumo": "^0.7.14",
18
- "@oesp/core": "2.0.0"
26
+ "@oesp/core": "5.0.0"
19
27
  },
20
28
  "devDependencies": {
21
29
  "@types/libsodium-wrappers": "^0.7.14",
@@ -23,7 +31,7 @@
23
31
  "typescript": "^5.6.3"
24
32
  },
25
33
  "scripts": {
26
- "build": "tsup src/index.ts --dts --format esm,cjs",
34
+ "build": "tsc -p tsconfig.build.json",
27
35
  "lint": "tsc -p tsconfig.json --noEmit"
28
36
  }
29
37
  }