Skip to content

Commit

Permalink
Export all modules
Browse files Browse the repository at this point in the history
  • Loading branch information
kigawas committed Oct 10, 2024
1 parent 82c6d72 commit 18e99bd
Show file tree
Hide file tree
Showing 10 changed files with 78 additions and 55 deletions.
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,4 @@ jobs:

- run: cd example && pnpm install
- run: node example/index.js
- run: node example/import.js
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@

# Changelog

## 0.4.9

- Add examples
- Update documentation
- Migrate to vitest
- Export all modules to allow full customization

## 0.4.1 ~ 0.4.8

- Revamp util functions
Expand Down
4 changes: 3 additions & 1 deletion example/import.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import { ECIES_CONFIG, utils } from "eciesjs";
import { ECIES_CONFIG, utils as _utils } from "eciesjs";
import config from "eciesjs/config";
import consts from "eciesjs/consts";
import utils from "eciesjs/utils";

console.log("ECIES_CONFIG:", ECIES_CONFIG)
console.log("config:", config)
console.log("consts:", consts)
console.log("utils:", utils)
console.log("index utils:", _utils)
28 changes: 23 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"type": "git",
"url": "git+https://github.com/ecies/js.git"
},
"version": "0.4.8",
"version": "0.4.9",
"engines": {
"node": ">=16.0.0"
},
Expand All @@ -30,6 +30,24 @@
"files": [
"dist"
],
"exports": {
".": {
"types": "./dist/index.d.ts",
"import": "./dist/index.js"
},
"./config": {
"types": "./dist/config.d.ts",
"import": "./dist/config.js"
},
"./consts": {
"types": "./dist/consts.d.ts",
"import": "./dist/consts.js"
},
"./utils": {
"types": "./dist/utils/index.d.ts",
"import": "./dist/utils/index.js"
}
},
"scripts": {
"build": "npx tsc",
"test": "vitest"
Expand All @@ -40,11 +58,11 @@
"@noble/hashes": "^1.5.0"
},
"devDependencies": {
"@types/node": "^22.7.4",
"@types/node": "^22.7.5",
"@vitest/coverage-v8": "2.1.2",
"typescript": "^5.6.2",
"undici": "^6.19.8",
"typescript": "^5.6.3",
"undici": "^6.20.0",
"vitest": "^2.1.2"
},
"packageManager": "[email protected].0+sha512.4abf725084d7bcbafbd728bfc7bee61f2f791f977fd87542b3579dcb23504d170d46337945e4c66485cd12d588a0c0e570ed9c477e7ccdd8507cf05f3f92eaca"
"packageManager": "[email protected].1+sha512.e5a7e52a4183a02d5931057f7a0dbff9d5e9ce3161e33fa68ae392125b79282a8a8a470a51dfc8a0ed86221442eb2fb57019b0990ed24fab519bf0e1bc5ccfc4"
}
77 changes: 35 additions & 42 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ export function decrypt(receiverRawSK: string | Uint8Array, msg: Uint8Array): Bu
export { ECIES_CONFIG } from "./config";
export { PrivateKey, PublicKey } from "./keys";

/** @deprecated - use `import utils from "eciesjs/utils"` instead. */
export const utils = {
// TODO: review these before 0.5.0
aesEncrypt,
Expand Down
2 changes: 1 addition & 1 deletion src/utils/elliptic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import { secp256k1 } from "@noble/curves/secp256k1";

import { ellipticCurve } from "../config";
import { ETH_PUBLIC_KEY_SIZE, SECRET_KEY_LENGTH } from "../consts";
import { deriveKey } from "./hash";
import { decodeHex } from "./hex";
import { deriveKey } from "./symmetric";

export const isValidPrivateKey = (secret: Uint8Array): boolean =>
// on secp256k1: only key ∈ (0, group order) is valid
Expand Down
6 changes: 6 additions & 0 deletions src/utils/hash.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { hkdf } from "@noble/hashes/hkdf";
import { sha256 } from "@noble/hashes/sha256";

export const deriveKey = (master: Uint8Array): Uint8Array =>
// 32 bytes shared secret for aes256 and xchacha20 derived from HKDF-SHA256
hkdf(sha256, master, undefined, undefined, 32);
1 change: 1 addition & 0 deletions src/utils/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// under this folder no `Buffer`
export * from "./elliptic";
export * from "./hash";
export * from "./hex";
export * from "./symmetric";
6 changes: 0 additions & 6 deletions src/utils/symmetric.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import { xchacha20poly1305 as xchacha20 } from "@noble/ciphers/chacha";
import { Cipher, concatBytes } from "@noble/ciphers/utils";
import { randomBytes } from "@noble/ciphers/webcrypto";
import { hkdf } from "@noble/hashes/hkdf";
import { sha256 } from "@noble/hashes/sha256";

import { symmetricAlgorithm, symmetricNonceLength } from "../config";
import { AEAD_TAG_LENGTH, XCHACHA20_NONCE_LENGTH } from "../consts";
Expand All @@ -20,10 +18,6 @@ export const aesEncrypt = symEncrypt; // TODO: delete
/** @deprecated - use `symDecrypt` instead. */
export const aesDecrypt = symDecrypt; // TODO: delete

export const deriveKey = (master: Uint8Array): Uint8Array =>
// 32 bytes shared secret for aes256 and xchacha20 derived from HKDF-SHA256
hkdf(sha256, master, undefined, undefined, 32);

function _exec(is_encryption: boolean, key: Uint8Array, data: Uint8Array): Uint8Array {
const algorithm = symmetricAlgorithm();
const callback = is_encryption ? _encrypt : _decrypt;
Expand Down

0 comments on commit 18e99bd

Please sign in to comment.