diff --git a/.cspell.jsonc b/.cspell.jsonc index e773080..58fbce0 100644 --- a/.cspell.jsonc +++ b/.cspell.jsonc @@ -4,18 +4,28 @@ // language - current active spelling language "language": "en", // words - list of words to be always considered correct - "words": ["bindgen", "ecies", "eciesrs", "keypair"], + "words": [ + "bindgen", + "ecies", + "eciesrs", + "keypair", + "libsecp256k1" + ], // flagWords - list of words to be always considered incorrect // This is useful for offensive words and common spelling errors. // For example "hte" should be "the" - "flagWords": ["hte"], + "flagWords": [ + "hte" + ], "ignorePaths": [ ".git", ".github", ".gitignore", ".cspell.jsonc", + "node_modules", + "pkg", "LICENSE", "package.json", - "yarn.lock" + "pnpm-lock.yaml" ] } diff --git a/.github/dependabot.yml b/.github/dependabot.yml index 910241a..a630d8c 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -4,4 +4,4 @@ updates: directory: "/" schedule: interval: monthly - open-pull-requests-limit: 10 + open-pull-requests-limit: 3 diff --git a/.github/workflows/cd.yml b/.github/workflows/cd.yml index 049297b..5a06e76 100644 --- a/.github/workflows/cd.yml +++ b/.github/workflows/cd.yml @@ -10,13 +10,17 @@ env: jobs: publish: runs-on: ubuntu-latest + permissions: + contents: read + id-token: write steps: - uses: actions/checkout@v4 - + - uses: pnpm/action-setup@v4 + with: + version: 10 - uses: actions/setup-node@v4 with: - node-version: 20 - registry-url: "https://registry.npmjs.org" + node-version: 22 - uses: dtolnay/rust-toolchain@master with: @@ -37,3 +41,4 @@ jobs: run: cd pkg && npm publish env: NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} + NPM_CONFIG_PROVENANCE: true diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index de45da9..7a0a326 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -15,10 +15,12 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - + - uses: pnpm/action-setup@v4 + with: + version: 10 - uses: actions/setup-node@v4 with: - node-version: 20 + node-version: 22 - uses: dtolnay/rust-toolchain@master with: diff --git a/CHANGELOG.md b/CHANGELOG.md index fd9c7a1..2195054 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ # Changelog +## 0.2.1 + +- Bump dependencies +- Revamp type for typescript + ## 0.2.0 - Reduce wasm size from 1.2MB to ~100KB by revamping the build process @@ -9,6 +14,7 @@ - Bump dependencies ## 0.1.2 + - Bump dependencies ## 0.1.1 diff --git a/Cargo.toml b/Cargo.toml index d110342..140cef4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,38 +1,34 @@ [package] name = "ecies-wasm" -version = "0.2.0" +version = "0.2.1" # docs authors = ["Weiliang Li "] description = "A WASM binding for eciesrs" edition = "2021" -keywords = [ - "secp256k1", - "crypto", - "ecc", - "ecies", - "cryptocurrency", -] +keywords = ["secp256k1", "crypto", "ecc", "ecies", "cryptography"] license = "MIT" readme = "README.md" # links documentation = "https://www.npmjs.com/package/ecies-wasm/" homepage = "https://ecies.org/rs-wasm/" -repository = "https://github.com/ecies/rs-wasm" +repository = "git+https://github.com/ecies/rs-wasm.git" [dependencies] -ecies = {version = "0.2", default-features = false, features = ["pure"]} -once_cell = {version = "1.18.0", default-features = false, features = ["std"]} +ecies = { version = "0.2.9", default-features = false, features = ["aes-rust"] } +once_cell = { version = "1.21.3", default-features = false, features = ["std"] } # specify "lazy-static-context" to reduce wasm size -libsecp256k1 = {version = "0.7.1", default-features = false, features = ["lazy-static-context"]} +libsecp256k1 = { version = "0.7.2", default-features = false, features = [ + "lazy-static-context", +] } # wasm -js-sys = "0.3.64" -wasm-bindgen = "0.2.87" +js-sys = "0.3.77" +wasm-bindgen = "0.2.100" [dev-dependencies] -wasm-bindgen-test = "0.3.37" +wasm-bindgen-test = "0.3.50" [lib] crate-type = ["cdylib", "rlib"] diff --git a/LICENSE b/LICENSE index 8d93e2c..b649c98 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2020-2023 Weiliang Li +Copyright (c) 2020-2025 Weiliang Li Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/README.md b/README.md index bcba8c3..bc901c0 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,8 @@ [![License](https://img.shields.io/github/license/ecies/rs-wasm.svg)](https://github.com/ecies/rs-wasm) [![NPM Package](https://img.shields.io/npm/v/ecies-wasm.svg)](https://www.npmjs.com/package/ecies-wasm) +[![NPM Downloads](https://img.shields.io/npm/dm/ecies-wasm)](https://npm-stat.link/ecies-wasm) +[![Install size](https://packagephobia.com/badge?p=ecies-wasm)](https://packagephobia.com/result?p=ecies-wasm) [![CI](https://img.shields.io/github/actions/workflow/status/ecies/rs-wasm/ci.yml)](https://github.com/ecies/rs-wasm/actions) A WASM binding for [eciesrs](https://github.com/ecies/rs). @@ -33,7 +35,7 @@ Check [the example](./example) for how to use it in browsers. ## API ```ts -export function generateKeypair(): Array; // [sk, pk] +export function generateKeypair(): Uint8Array[]; // [sk, pk] export function encrypt(pk: Uint8Array, msg: Uint8Array): Uint8Array; export function decrypt(sk: Uint8Array, msg: Uint8Array): Uint8Array; ``` @@ -42,6 +44,7 @@ export function decrypt(sk: Uint8Array, msg: Uint8Array): Uint8Array; ```bash wasm-pack build +wasm-pack build --target web wasm-pack test --node ``` diff --git a/src/lib.rs b/src/lib.rs index fc13f0e..c4fbd17 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,37 +1,32 @@ use ecies::{ decrypt as _decrypt, encrypt as _encrypt, utils::generate_keypair as _generate_keypair, }; -use js_sys::{Array, Uint8Array}; +use js_sys::Uint8Array; use wasm_bindgen::prelude::{wasm_bindgen, JsError}; /// Generate a `(SecretKey, PublicKey)` pair #[allow(non_snake_case)] #[wasm_bindgen] -pub fn generateKeypair() -> Array { +pub fn generateKeypair() -> Vec { let (sk, pk) = _generate_keypair(); - let (sk, pk) = (&sk.serialize()[..], &pk.serialize_compressed()[..]); - let (sk, pk) = (Uint8Array::from(sk), Uint8Array::from(pk)); + let (sk, pk): (&[u8], &[u8]) = (&sk.serialize(), &pk.serialize_compressed()); - let ret = Array::new(); - ret.push(&sk); - ret.push(&pk); + let mut ret = Vec::with_capacity(2); + ret.push(Uint8Array::from(sk)); + ret.push(Uint8Array::from(pk)); ret } /// Encrypt a message by a public key #[wasm_bindgen] -pub fn encrypt(pk: &[u8], msg: &[u8]) -> Result { - _encrypt(pk, msg) - .map(|v| Uint8Array::from(v.as_slice())) - .map_err(|e| JsError::new(&e.to_string())) +pub fn encrypt(pk: &[u8], msg: &[u8]) -> Result, JsError> { + _encrypt(pk, msg).map_err(|e| JsError::new(&e.to_string())) } /// Decrypt a message by a secret key #[wasm_bindgen] -pub fn decrypt(sk: &[u8], msg: &[u8]) -> Result { - _decrypt(sk, msg) - .map(|v| Uint8Array::from(v.as_slice())) - .map_err(|e| JsError::new(&e.to_string())) +pub fn decrypt(sk: &[u8], msg: &[u8]) -> Result, JsError> { + _decrypt(sk, msg).map_err(|e| JsError::new(&e.to_string())) } #[cfg(all(test, target_arch = "wasm32"))] @@ -43,7 +38,7 @@ mod tests { use super::{_generate_keypair, decrypt, encrypt, generateKeypair}; - const MSG: &str = "hello-world🌎"; + const MSG: &str = "hello ecies🔒"; fn __enc_dec(sk: &[u8], pk: &[u8], msg: &[u8]) { let encrypted = encrypt(pk, msg).ok().unwrap().to_vec(); @@ -63,8 +58,8 @@ mod tests { #[wasm_bindgen_test] fn test_wasm() { let pair = generateKeypair(); - let sk = Uint8Array::from(pair.get(0)).to_vec(); - let pk = Uint8Array::from(pair.get(1)).to_vec(); + let sk = pair[0].to_vec(); + let pk = pair[1].to_vec(); let msg = Uint8Array::from(MSG.as_bytes()).to_vec(); __enc_dec(&sk, &pk, &msg);