diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml new file mode 100644 index 0000000..377eab9 --- /dev/null +++ b/.github/workflows/CI.yml @@ -0,0 +1,208 @@ +# This file is autogenerated by maturin v1.7.4 +# To update, run +# +# maturin generate-ci github +# +name: CI + +on: + push: + branches: + - main + tags: + - '*' + pull_request: + workflow_dispatch: + +permissions: + contents: read + +jobs: + test: + name: Run Unit Tests + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Set up Python + uses: actions/setup-python@v5 + with: + python-version: '3.12' + - name: Build wheel + uses: PyO3/maturin-action@v1 + with: + command: build + args: -o dist -i python3.12 + - name: Install wheel + run: | + pip install dist/*.whl + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install -r requirements.txt + - name: Run tests + run: | + pip install pytest + pytest tests.py + linux: + runs-on: ${{ matrix.platform.runner }} + needs: test + strategy: + matrix: + platform: + - runner: ubuntu-latest + target: x86_64 + - runner: ubuntu-latest + target: x86 + - runner: ubuntu-latest + target: aarch64 + - runner: ubuntu-latest + target: armv7 + - runner: ubuntu-latest + target: ppc64le + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-python@v5 + with: + python-version: 3.x + - name: Build wheels + uses: PyO3/maturin-action@v1 + with: + target: ${{ matrix.platform.target }} + args: --release --out dist --find-interpreter + sccache: 'true' + manylinux: auto + - name: Upload wheels + uses: actions/upload-artifact@v4 + with: + name: wheels-linux-${{ matrix.platform.target }} + path: dist + + musllinux: + runs-on: ${{ matrix.platform.runner }} + needs: test + strategy: + matrix: + platform: + - runner: ubuntu-latest + target: x86_64 + - runner: ubuntu-latest + target: x86 + - runner: ubuntu-latest + target: aarch64 + - runner: ubuntu-latest + target: armv7 + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-python@v5 + with: + python-version: 3.x + - name: Build wheels + uses: PyO3/maturin-action@v1 + with: + target: ${{ matrix.platform.target }} + args: --release --out dist --find-interpreter + sccache: 'true' + manylinux: musllinux_1_2 + - name: Upload wheels + uses: actions/upload-artifact@v4 + with: + name: wheels-musllinux-${{ matrix.platform.target }} + path: dist + + windows: + runs-on: ${{ matrix.platform.runner }} + needs: test + strategy: + matrix: + platform: + - runner: windows-latest + target: x64 + - runner: windows-latest + target: x86 + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-python@v5 + with: + python-version: 3.x + architecture: ${{ matrix.platform.target }} + - name: Build wheels + uses: PyO3/maturin-action@v1 + with: + target: ${{ matrix.platform.target }} + args: --release --out dist --find-interpreter + sccache: 'true' + - name: Upload wheels + uses: actions/upload-artifact@v4 + with: + name: wheels-windows-${{ matrix.platform.target }} + path: dist + + macos: + runs-on: ${{ matrix.platform.runner }} + needs: test + strategy: + matrix: + platform: + - runner: macos-14 + target: x86_64 + - runner: macos-14 + target: aarch64 + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-python@v5 + with: + python-version: 3.x + - name: Build wheels + uses: PyO3/maturin-action@v1 + with: + target: ${{ matrix.platform.target }} + args: --release --out dist --find-interpreter + sccache: 'true' + - name: Upload wheels + uses: actions/upload-artifact@v4 + with: + name: wheels-macos-${{ matrix.platform.target }} + path: dist + + sdist: + runs-on: ubuntu-latest + needs: test + steps: + - uses: actions/checkout@v4 + - name: Build sdist + uses: PyO3/maturin-action@v1 + with: + command: sdist + args: --out dist + - name: Upload sdist + uses: actions/upload-artifact@v4 + with: + name: wheels-sdist + path: dist + + release: + name: Release + runs-on: ubuntu-latest + if: ${{ startsWith(github.ref, 'refs/tags/') || github.event_name == 'workflow_dispatch' }} + needs: [linux, musllinux, windows, macos, sdist] + permissions: + # Use to sign the release artifacts + id-token: write + # Used to upload release artifacts + contents: write + # Used to generate artifact attestation + attestations: write + steps: + - uses: actions/download-artifact@v4 + - name: Generate artifact attestation + uses: actions/attest-build-provenance@v1 + with: + subject-path: 'wheels-*/*' + - name: Publish to PyPI + if: "startsWith(github.ref, 'refs/tags/')" + uses: PyO3/maturin-action@v1 + env: + MATURIN_PYPI_TOKEN: ${{ secrets.PYPI_API_TOKEN }} + with: + command: upload + args: --non-interactive --skip-existing wheels-*/* diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml deleted file mode 100644 index 5f0f2fb..0000000 --- a/.github/workflows/build.yml +++ /dev/null @@ -1,181 +0,0 @@ -name: Build wheels - -on: - push: - branches: - - main - -jobs: - macos: - runs-on: macos-latest - strategy: - matrix: - python-version: ['3.7', '3.8', '3.9', '3.10', '3.11', '3.12'] - steps: - - uses: actions/checkout@v4 - - uses: actions/setup-python@v5 - with: - python-version: ${{ matrix.python-version }} - - name: Install Rust toolchain - uses: actions-rs/toolchain@v1 - with: - toolchain: nightly-2024-02-04 - target: aarch64-apple-darwin - profile: minimal - default: true - - name: Build wheels - universal2 - if: ${{ matrix.python-version != '3.7' }} - uses: messense/maturin-action@v1 - with: - args: -i python --release --universal2 --out dist - rust-toolchain: nightly-2024-02-04 - - name: Install built wheel - universal2 - if: ${{ matrix.python-version != '3.7' }} - run: | - pip install py-ed25519-zebra-bindings --no-index --find-links dist --force-reinstall - - name: Upload wheels - uses: actions/upload-artifact@v4 - with: - name: dist-wheels-mac-${{ matrix.python-version }} - path: dist/*.whl - windows: - runs-on: windows-latest - strategy: - matrix: - python-version: ['3.7', '3.8', '3.9', '3.10', '3.11', '3.12'] - target: [x64, x86] - steps: - - uses: actions/checkout@v4 - - uses: actions/setup-python@v5 - with: - python-version: ${{ matrix.python-version }} - architecture: ${{ matrix.target }} - - name: Update rustup - run: rustup self update - - name: Install Rust toolchain - uses: actions-rs/toolchain@v1 - with: - toolchain: nightly-2024-02-04 - profile: minimal - default: true - - name: Build - if: matrix.target == 'x64' - run: cargo build --release - - name: Build wheels - uses: messense/maturin-action@v1 - with: - target: ${{ matrix.target }} - args: -i python --release --out dist - rust-toolchain: nightly-2024-02-04 - - name: Install built wheel - run: | - pip install py-ed25519-zebra-bindings --no-index --find-links dist --force-reinstall - - name: Upload wheels - uses: actions/upload-artifact@v4 - with: - name: dist-wheels-win-${{ matrix.target }}-${{ matrix.python-version }} - path: dist/*.whl - - linux: - runs-on: ubuntu-latest - strategy: - matrix: - python-version: ['3.7', '3.8', '3.9', '3.10', '3.11', '3.12'] - target: [x86_64, i686] - steps: - - uses: actions/checkout@v4 - - name: Install Rust toolchain - uses: actions-rs/toolchain@v1 - with: - toolchain: nightly-2024-02-04 - profile: minimal - default: true - - name: Build - run: cargo build --release - - uses: actions/setup-python@v5 - with: - python-version: ${{ matrix.python-version }} - - name: Build Wheels - uses: messense/maturin-action@v1 - with: - target: ${{ matrix.target }} - rust-toolchain: nightly-2024-02-04 - manylinux: auto - args: -i python${{ matrix.python-version }} --release --out dist - - name: Upload wheels - uses: actions/upload-artifact@v4 - with: - name: dist-wheels-linux-${{ matrix.target }}-${{ matrix.python-version }} - path: dist/*.whl - - muslwheels_x86: - name: Build musllinux wheels for x86 - runs-on: ubuntu-latest - - env: - CIBW_BUILD_VERBOSITY: 1 - CIBW_BEFORE_ALL_LINUX: "curl https://sh.rustup.rs -sSf | sh -s -- --default-toolchain nightly-2024-02-04 -y" - CIBW_ARCHS_LINUX: "auto64" - CIBW_ENVIRONMENT: 'PATH="$PATH:$HOME/.cargo/bin"' - CIBW_BUILD: "*-musllinux_x86_64" - CIBW_SKIP: "cp27-* cp34-* cp35-* cp36-*" - - steps: - - uses: actions/checkout@v4 - - - name: Build wheels - uses: pypa/cibuildwheel@v2.17.0 - with: - output-dir: dist - - - name: Upload wheels - uses: actions/upload-artifact@v4 - with: - name: dist-wheels-musl - path: dist/*.whl - - aarch64_wheels: - name: Build wheels for aarch64 linux - runs-on: ubuntu-latest - - env: - CIBW_BUILD_VERBOSITY: 1 - CIBW_BEFORE_ALL_LINUX: "curl https://sh.rustup.rs -sSf | sh -s -- --default-toolchain nightly-2024-02-04 -y" - CIBW_ARCHS_LINUX: "aarch64" - CIBW_ENVIRONMENT: 'PATH="$PATH:$HOME/.cargo/bin"' - CIBW_BUILD: "*-musllinux_aarch64 *-manylinux_aarch64" - CIBW_SKIP: "cp27-* cp34-* cp35-* cp36-*" - - steps: - - uses: actions/checkout@v4 - - - name: Set up QEMU - uses: docker/setup-qemu-action@v3 - with: - platforms: arm64 - - - name: Build wheels - uses: pypa/cibuildwheel@v2.17.0 - with: - output-dir: dist - - - - name: Upload wheels - uses: actions/upload-artifact@v4 - with: - name: dist-wheels - path: dist/*.whl - - build_sdist: - name: Build source distribution - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - - name: Build sdist - run: pipx run build --sdist - - - uses: actions/upload-artifact@v4 - with: - name: dist-src - path: dist/*.tar.gz diff --git a/.github/workflows/pypi.yml b/.github/workflows/pypi.yml deleted file mode 100644 index 243443e..0000000 --- a/.github/workflows/pypi.yml +++ /dev/null @@ -1,202 +0,0 @@ -name: Deploy to PyPI - -on: - release: - types: [ created ] - -jobs: - macos: - runs-on: macos-latest - strategy: - matrix: - python-version: ['3.7', '3.8', '3.9', '3.10', '3.11', '3.12'] - steps: - - uses: actions/checkout@v4 - - uses: actions/setup-python@v5 - with: - python-version: ${{ matrix.python-version }} - - name: Install Rust toolchain - uses: actions-rs/toolchain@v1 - with: - toolchain: nightly-2024-02-04 - target: aarch64-apple-darwin - profile: minimal - default: true - - name: Build wheels - universal2 - if: ${{ matrix.python-version != '3.7' }} - uses: messense/maturin-action@v1 - with: - args: -i python --release --universal2 --out dist - rust-toolchain: nightly-2024-02-04 - - name: Install built wheel - universal2 - if: ${{ matrix.python-version != '3.7' }} - run: | - pip install py-ed25519-zebra-bindings --no-index --find-links dist --force-reinstall - - name: Upload wheels - uses: actions/upload-artifact@v4 - with: - name: dist-wheels-mac-${{ matrix.python-version }} - path: dist/*.whl - windows: - runs-on: windows-latest - strategy: - matrix: - python-version: ['3.7', '3.8', '3.9', '3.10', '3.11', '3.12'] - target: [x64, x86] - steps: - - uses: actions/checkout@v4 - - uses: actions/setup-python@v5 - with: - python-version: ${{ matrix.python-version }} - architecture: ${{ matrix.target }} - - name: Update rustup - run: rustup self update - - name: Install Rust toolchain - uses: actions-rs/toolchain@v1 - with: - toolchain: nightly-2024-02-04 - profile: minimal - default: true - - name: Build - if: matrix.target == 'x64' - run: cargo build --release - - name: Build wheels - uses: messense/maturin-action@v1 - with: - target: ${{ matrix.target }} - args: -i python --release --out dist - rust-toolchain: nightly-2024-02-04 - - name: Install built wheel - run: | - pip install py-ed25519-zebra-bindings --no-index --find-links dist --force-reinstall - - name: Upload wheels - uses: actions/upload-artifact@v4 - with: - name: dist-wheels-win-${{ matrix.target }}-${{ matrix.python-version }} - path: dist/*.whl - - linux: - runs-on: ubuntu-latest - strategy: - matrix: - python-version: ['3.7', '3.8', '3.9', '3.10', '3.11', '3.12'] - target: [x86_64, i686] - steps: - - uses: actions/checkout@v4 - - name: Install Rust toolchain - uses: actions-rs/toolchain@v1 - with: - toolchain: nightly-2024-02-04 - profile: minimal - default: true - - name: Build - run: cargo build --release - - uses: actions/setup-python@v5 - with: - python-version: ${{ matrix.python-version }} - - name: Build Wheels - uses: messense/maturin-action@v1 - with: - target: ${{ matrix.target }} - rust-toolchain: nightly-2024-02-04 - manylinux: auto - args: -i python${{ matrix.python-version }} --release --out dist - - name: Upload wheels - uses: actions/upload-artifact@v4 - with: - name: dist-wheels-linux-${{ matrix.target }}-${{ matrix.python-version }} - path: dist/*.whl - - muslwheels_x86: - name: Build musllinux wheels for x86 - runs-on: ubuntu-latest - - env: - CIBW_BUILD_VERBOSITY: 1 - CIBW_BEFORE_ALL_LINUX: "curl https://sh.rustup.rs -sSf | sh -s -- --default-toolchain nightly-2024-02-04 -y" - CIBW_ARCHS_LINUX: "auto64" - CIBW_ENVIRONMENT: 'PATH="$PATH:$HOME/.cargo/bin"' - CIBW_BUILD: "*-musllinux_x86_64" - CIBW_SKIP: "cp27-* cp34-* cp35-* cp36-*" - - steps: - - uses: actions/checkout@v4 - - - name: Build wheels - uses: pypa/cibuildwheel@v2.17.0 - with: - output-dir: dist - - - name: Upload wheels - uses: actions/upload-artifact@v4 - with: - name: dist-wheels-musl - path: dist/*.whl - - aarch64_wheels: - name: Build wheels for aarch64 linux - runs-on: ubuntu-latest - - env: - CIBW_BUILD_VERBOSITY: 1 - CIBW_BEFORE_ALL_LINUX: "curl https://sh.rustup.rs -sSf | sh -s -- --default-toolchain nightly-2024-02-04 -y" - CIBW_ARCHS_LINUX: "aarch64" - CIBW_ENVIRONMENT: 'PATH="$PATH:$HOME/.cargo/bin"' - CIBW_BUILD: "*-musllinux_aarch64 *-manylinux_aarch64" - CIBW_SKIP: "cp27-* cp34-* cp35-* cp36-*" - - steps: - - uses: actions/checkout@v4 - - - name: Set up QEMU - uses: docker/setup-qemu-action@v3 - with: - platforms: arm64 - - - name: Build wheels - uses: pypa/cibuildwheel@v2.17.0 - with: - output-dir: dist - - - - name: Upload wheels - uses: actions/upload-artifact@v4 - with: - name: dist-wheels - path: dist/*.whl - - build_sdist: - name: Build source distribution - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - - name: Build sdist - run: pipx run build --sdist - - - uses: actions/upload-artifact@v4 - with: - name: dist-src - path: dist/*.tar.gz - - release: - name: Release - runs-on: ubuntu-latest - if: "startsWith(github.ref, 'refs/tags/')" - needs: [macos, windows, linux, muslwheels_x86, build_sdist] - steps: - - uses: actions/download-artifact@v4 - with: - pattern: dist-* - path: dist - merge-multiple: true - - uses: actions/setup-python@v2 - with: - python-version: 3.9 - - name: Publish to PyPi - env: - TWINE_USERNAME: __token__ - TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }} - run: | - pip install --upgrade twine - twine upload --skip-existing dist/* diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml deleted file mode 100644 index 2d970df..0000000 --- a/.github/workflows/test.yml +++ /dev/null @@ -1,45 +0,0 @@ -name: Run units tests - -on: - push: - branches: - - main - - develop - pull_request: - -jobs: - test: - name: Test - strategy: - fail-fast: false - matrix: - os: [ ubuntu-latest, macos-latest ] - runs-on: ${{ matrix.os }} - steps: - - uses: actions/checkout@v2 - - uses: actions/setup-python@v2 - with: - python-version: 3.8 - - name: Install cffi and virtualenv - run: pip install cffi virtualenv - - name: Install RUST toolchain - uses: actions-rs/toolchain@v1 - id: rustup - with: - profile: minimal - toolchain: nightly-2022-05-25 - override: true - - name: Build bindings - run: | - pip install maturin - maturin build -i python3.8 - - name: Install requirements - run: | - pip install -r requirements.txt - - name: Install bindings - run: | - pip install target/wheels/*.whl - - name: Test with pytest - run: | - pip install pytest - pytest tests.py diff --git a/Cargo.lock b/Cargo.lock index f266bcd..49f5941 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1,45 +1,40 @@ # This file is automatically @generated by Cargo. # It is not intended for manual editing. -version = 3 +version = 4 [[package]] name = "ahash" -version = "0.7.6" +version = "0.8.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fcb51a0695d8f838b1ee009b3fbf66bda078cd64590202a864a8f3e8c4315c47" +checksum = "e89da841a80418a9b391ebaea17f5c112ffaaa96f621d2c285b5174da76b9011" dependencies = [ - "getrandom", + "cfg-if", "once_cell", "version_check", + "zerocopy", ] [[package]] -name = "autocfg" -version = "1.1.0" +name = "allocator-api2" +version = "0.2.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" +checksum = "5c6cb57a04249c6480766f7f7cef5467412af1490f8d1e243141daddada3264f" [[package]] -name = "bitflags" -version = "1.3.2" +name = "autocfg" +version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" +checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" [[package]] name = "block-buffer" -version = "0.9.0" +version = "0.10.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4152116fd6e9dadb291ae18fc1ec3575ed6d84c29642d97890f4b4a3417297e4" +checksum = "3078c7629b62d3f0439517fa394996acacc5cbc91c5a20d8c658e77abd503a71" dependencies = [ "generic-array", ] -[[package]] -name = "byteorder" -version = "1.4.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "14c189c53d098945499cdfa7ecc63567cf3886b3332b312a5b4585d8d3a6a610" - [[package]] name = "cfg-if" version = "1.0.0" @@ -48,49 +43,90 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] name = "cpufeatures" -version = "0.2.2" +version = "0.2.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "59a6001667ab124aebae2a495118e11d30984c3a653e99d86d58971708cf5e4b" +checksum = "608697df725056feaccfa42cffdaeeec3fccc4ffc38358ecd19b243e716a78e0" dependencies = [ "libc", ] +[[package]] +name = "crypto-common" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1bfb12502f3fc46cca1bb51ac28df9d618d813cdc3d2f25b9fe775a34af26bb3" +dependencies = [ + "generic-array", + "typenum", +] + [[package]] name = "curve25519-dalek" -version = "3.2.1" +version = "4.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "90f9d052967f590a76e62eb387bd0bbb1b000182c3cefe5364db6b7211651bc0" +checksum = "97fb8b7c4503de7d6ae7b42ab72a5a59857b4c937ec27a3d4539dba95b5ab2be" dependencies = [ - "byteorder", + "cfg-if", + "cpufeatures", + "curve25519-dalek-derive", "digest", - "rand_core 0.5.1", + "fiat-crypto", + "rustc_version", "subtle", "zeroize", ] +[[package]] +name = "curve25519-dalek-derive" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f46882e17999c6cc590af592290432be3bce0428cb0d5f8b6715e4dc7b383eb3" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "digest" -version = "0.9.0" +version = "0.10.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d3dd60d1080a57a05ab032377049e0591415d2b31afd7028356dbf3cc6dcb066" +checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292" dependencies = [ - "generic-array", + "block-buffer", + "crypto-common", +] + +[[package]] +name = "ed25519" +version = "2.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "115531babc129696a58c64a4fef0a8bf9e9698629fb97e9e40767d235cfbcd53" +dependencies = [ + "signature", ] [[package]] name = "ed25519-zebra" -version = "3.1.0" +version = "4.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7c24f403d068ad0b359e577a77f92392118be3f3c927538f2bb544a5ecd828c6" +checksum = "7d9ce6874da5d4415896cd45ffbc4d1cfc0c4f9c079427bd870742c30f2f65a9" dependencies = [ "curve25519-dalek", + "ed25519", "hashbrown", "hex", - "rand_core 0.6.3", + "rand_core", "sha2", "zeroize", ] +[[package]] +name = "fiat-crypto" +version = "0.2.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "28dea519a9695b9977216879a3ebfddf92f1c08c05d984f8996aecd6ecdc811d" + [[package]] name = "generic-array" version = "0.14.6" @@ -114,13 +150,20 @@ dependencies = [ [[package]] name = "hashbrown" -version = "0.12.3" +version = "0.14.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888" +checksum = "e5274423e17b7c9fc20b6e7e208532f9b19825d82dfd615708b70edd83df41f1" dependencies = [ "ahash", + "allocator-api2", ] +[[package]] +name = "heck" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" + [[package]] name = "hex" version = "0.4.3" @@ -129,80 +172,36 @@ checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" [[package]] name = "indoc" -version = "1.0.9" +version = "2.0.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bfa799dd5ed20a7e349f3b4639aa80d74549c81716d9ec4f994c9b5815598306" - -[[package]] -name = "instant" -version = "0.1.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7a5bbe824c507c5da5956355e86a746d82e0e1464f65d862cc5e71da70e94b2c" -dependencies = [ - "cfg-if", -] +checksum = "b248f5224d1d606005e02c97f5aa4e88eeb230488bcc03bc9ca4d7991399f2b5" [[package]] name = "libc" -version = "0.2.131" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "04c3b4822ccebfa39c02fc03d1534441b22ead323fa0f48bb7ddd8e6ba076a40" - -[[package]] -name = "lock_api" -version = "0.4.7" +version = "0.2.161" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "327fa5b6a6940e4699ec49a9beae1ea4845c6bab9314e4f84ac68742139d8c53" -dependencies = [ - "autocfg", - "scopeguard", -] +checksum = "8e9489c2807c139ffd9c1794f4af0ebe86a828db53ecdc7fea2111d0fed085d1" [[package]] name = "memoffset" -version = "0.8.0" +version = "0.9.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d61c719bcfbcf5d62b3a09efa6088de8c54bc0bfcd3ea7ae39fcc186108b8de1" +checksum = "488016bfae457b036d996092f6cb448677611ce4449e970ceaf42695203f218a" dependencies = [ "autocfg", ] [[package]] name = "once_cell" -version = "1.17.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b7e5500299e16ebb147ae15a00a942af264cf3688f47923b8fc2cd5858f23ad3" - -[[package]] -name = "opaque-debug" -version = "0.3.0" +version = "1.20.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "624a8340c38c1b80fd549087862da4ba43e08858af025b236e509b6649fc13d5" +checksum = "1261fe7e33c73b354eab43b1273a57c8f967d0391e80353e51f764ac02cf6775" [[package]] -name = "parking_lot" -version = "0.11.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7d17b78036a60663b797adeaee46f5c9dfebb86948d1255007a1d6be0271ff99" -dependencies = [ - "instant", - "lock_api", - "parking_lot_core", -] - -[[package]] -name = "parking_lot_core" -version = "0.8.5" +name = "portable-atomic" +version = "1.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d76e8e1493bcac0d2766c42737f34458f1c8c50c0d23bcb24ea953affb273216" -dependencies = [ - "cfg-if", - "instant", - "libc", - "redox_syscall", - "smallvec", - "winapi", -] +checksum = "cc9c68a3f6da06753e9335d63e27f6b9754dd1920d941135b7ea8224f141adb2" [[package]] name = "ppv-lite86" @@ -212,16 +211,16 @@ checksum = "eb9f9e6e233e5c4a35559a617bf40a4ec447db2e84c20b55a6f83167b7e57872" [[package]] name = "proc-macro2" -version = "1.0.43" +version = "1.0.89" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0a2ca2c61bc9f3d74d2886294ab7b9853abd9c1ad903a3ac7815c58989bb7bab" +checksum = "f139b0662de085916d1fb67d2b4169d1addddda1919e696f3252b740b629986e" dependencies = [ "unicode-ident", ] [[package]] name = "py-ed25519-zebra-bindings" -version = "1.0.1" +version = "1.1.0" dependencies = [ "ed25519-zebra", "pyo3", @@ -230,15 +229,16 @@ dependencies = [ [[package]] name = "pyo3" -version = "0.18.1" +version = "0.22.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "06a3d8e8a46ab2738109347433cb7b96dffda2e4a218b03ef27090238886b147" +checksum = "3d922163ba1f79c04bc49073ba7b32fd5a8d3b76a87c955921234b8e77333c51" dependencies = [ "cfg-if", "indoc", "libc", "memoffset", - "parking_lot", + "once_cell", + "portable-atomic", "pyo3-build-config", "pyo3-ffi", "pyo3-macros", @@ -247,9 +247,9 @@ dependencies = [ [[package]] name = "pyo3-build-config" -version = "0.18.1" +version = "0.22.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "75439f995d07ddfad42b192dfcf3bc66a7ecfd8b4a1f5f6f046aa5c2c5d7677d" +checksum = "bc38c5feeb496c8321091edf3d63e9a6829eab4b863b4a6a65f26f3e9cc6b179" dependencies = [ "once_cell", "target-lexicon", @@ -257,9 +257,9 @@ dependencies = [ [[package]] name = "pyo3-ffi" -version = "0.18.1" +version = "0.22.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "839526a5c07a17ff44823679b68add4a58004de00512a95b6c1c98a6dcac0ee5" +checksum = "94845622d88ae274d2729fcefc850e63d7a3ddff5e3ce11bd88486db9f1d357d" dependencies = [ "libc", "pyo3-build-config", @@ -267,9 +267,9 @@ dependencies = [ [[package]] name = "pyo3-macros" -version = "0.18.1" +version = "0.22.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bd44cf207476c6a9760c4653559be4f206efafb924d3e4cbf2721475fc0d6cc5" +checksum = "e655aad15e09b94ffdb3ce3d217acf652e26bbc37697ef012f5e5e348c716e5e" dependencies = [ "proc-macro2", "pyo3-macros-backend", @@ -279,20 +279,22 @@ dependencies = [ [[package]] name = "pyo3-macros-backend" -version = "0.18.1" +version = "0.22.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc1f43d8e30460f36350d18631ccf85ded64c059829208fe680904c65bcd0a4c" +checksum = "ae1e3f09eecd94618f60a455a23def79f79eba4dc561a97324bf9ac8c6df30ce" dependencies = [ + "heck", "proc-macro2", + "pyo3-build-config", "quote", "syn", ] [[package]] name = "quote" -version = "1.0.21" +version = "1.0.37" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bbe448f377a7d6961e30f5955f9b8d106c3f5e449d493ee1b125c1d43c2b5179" +checksum = "b5b9d34b8991d19d98081b46eacdd8eb58c6f2b201139f7c5f643cc155a633af" dependencies = [ "proc-macro2", ] @@ -305,7 +307,7 @@ checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" dependencies = [ "libc", "rand_chacha", - "rand_core 0.6.3", + "rand_core", ] [[package]] @@ -315,15 +317,9 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" dependencies = [ "ppv-lite86", - "rand_core 0.6.3", + "rand_core", ] -[[package]] -name = "rand_core" -version = "0.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "90bde5296fc891b0cef12a6d03ddccc162ce7b2aff54160af9338f8d40df6d19" - [[package]] name = "rand_core" version = "0.6.3" @@ -334,38 +330,36 @@ dependencies = [ ] [[package]] -name = "redox_syscall" -version = "0.2.16" +name = "rustc_version" +version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fb5a58c1855b4b6819d59012155603f0b22ad30cad752600aadfcb695265519a" +checksum = "cfcb3a22ef46e85b45de6ee7e79d063319ebb6594faafcf1c225ea92ab6e9b92" dependencies = [ - "bitflags", + "semver", ] [[package]] -name = "scopeguard" -version = "1.1.0" +name = "semver" +version = "1.0.23" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd" +checksum = "61697e0a1c7e512e84a621326239844a24d8207b4669b41bc18b32ea5cbf988b" [[package]] name = "sha2" -version = "0.9.9" +version = "0.10.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4d58a1e1bf39749807d89cf2d98ac2dfa0ff1cb3faa38fbb64dd88ac8013d800" +checksum = "793db75ad2bcafc3ffa7c68b215fee268f537982cd901d132f89c6343f3a3dc8" dependencies = [ - "block-buffer", "cfg-if", "cpufeatures", "digest", - "opaque-debug", ] [[package]] -name = "smallvec" -version = "1.9.0" +name = "signature" +version = "2.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2fd0db749597d91ff862fd1d55ea87f7855a744a8425a64695b6fca237d1dad1" +checksum = "77549399552de45a898a580c1b41d445bf730df867cc44e6c0233bbc4b8329de" [[package]] name = "subtle" @@ -375,9 +369,9 @@ checksum = "6bdef32e8150c2a081110b42772ffe7d7c9032b606bc226c8260fd97e0976601" [[package]] name = "syn" -version = "1.0.99" +version = "2.0.85" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "58dbef6ec655055e20b86b15a8cc6d439cca19b667537ac6a1369572d151ab13" +checksum = "5023162dfcd14ef8f32034d8bcd4cc5ddc61ef7a247c024a33e24e1f24d21b56" dependencies = [ "proc-macro2", "quote", @@ -386,9 +380,9 @@ dependencies = [ [[package]] name = "target-lexicon" -version = "0.12.6" +version = "0.12.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8ae9980cab1db3fceee2f6c6f643d5d8de2997c58ee8d25fb0cc8a9e9e7348e5" +checksum = "61c41af27dd6d1e27b1b16b489db798443478cef1f06a660c96db617ba5de3b1" [[package]] name = "typenum" @@ -404,9 +398,9 @@ checksum = "c4f5b37a154999a8f3f98cc23a628d850e154479cd94decf3414696e12e31aaf" [[package]] name = "unindent" -version = "0.1.10" +version = "0.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "58ee9362deb4a96cef4d437d1ad49cffc9b9e92d202b6995674e928ce684f112" +checksum = "c7de7d73e1754487cb58364ee906a499937a0dfabd86bcb980fa99ec8c8fa2ce" [[package]] name = "version_check" @@ -421,29 +415,41 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" [[package]] -name = "winapi" -version = "0.3.9" +name = "zerocopy" +version = "0.7.35" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" +checksum = "1b9b4fd18abc82b8136838da5d50bae7bdea537c574d8dc1a34ed098d6c166f0" dependencies = [ - "winapi-i686-pc-windows-gnu", - "winapi-x86_64-pc-windows-gnu", + "zerocopy-derive", ] [[package]] -name = "winapi-i686-pc-windows-gnu" -version = "0.4.0" +name = "zerocopy-derive" +version = "0.7.35" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" +checksum = "fa4f8080344d4671fb4e831a13ad1e68092748387dfc4f55e356242fae12ce3e" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] [[package]] -name = "winapi-x86_64-pc-windows-gnu" -version = "0.4.0" +name = "zeroize" +version = "1.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" +checksum = "ced3678a2879b30306d323f4542626697a464a97c0a07c9aebf7ebca65cd4dde" +dependencies = [ + "zeroize_derive", +] [[package]] -name = "zeroize" -version = "1.3.0" +name = "zeroize_derive" +version = "1.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4756f7db3f7b5574938c3eb1c117038b8e07f95ee6718c0efad4ac21508f1efd" +checksum = "ce36e65b0d2999d2aafac989fb249189a141aee1f53c612c1f37d72631959f69" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] diff --git a/Cargo.toml b/Cargo.toml index 6605501..b2935ec 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,7 +2,7 @@ name = "py-ed25519-zebra-bindings" description = "Python bindings for the ed25519-zebra RUST crate" authors=["Stichting Polkascan (Polkascan Foundation)"] -version = "1.0.1" +version = "1.1.0" repository = "https://github.com/polkascan/py-ed25519-zebra-bindings" homepage = "https://github.com/polkascan/py-ed25519-zebra-bindings" license = "Apache-2.0" @@ -10,7 +10,7 @@ readme = "README.md" edition = "2018" [dependencies] -ed25519-zebra = { version = "3.0.0", default-features = false} +ed25519-zebra = { version = "4.0.3", default-features = false} rand = "0.8.5" [lib] @@ -18,5 +18,5 @@ name = "ed25519_zebra" crate-type = ["cdylib"] [dependencies.pyo3] -version = "0.18.1" +version = "0.22.5" features = ["extension-module"] diff --git a/pyproject.toml b/pyproject.toml index cb01c9d..eb4688c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,13 +1,13 @@ [build-system] -requires = ["maturin>=0.14,<0.15"] +requires = ["maturin>=1.7.0,<1.8.0"] build-backend = "maturin" [project] name = "py-ed25519-zebra-bindings" -version = "1.0.1" +version = "1.1.0" description = "Python bindings for the ed25519-zebra RUST crate" readme = "README.md" -requires-python = ">=3.7" +requires-python = ">=3.9" license = {file = "LICENSE"} authors = [ {email = "info@polkascan.org"}, @@ -19,9 +19,6 @@ maintainers = [ classifiers = [ "License :: OSI Approved :: Apache Software License", "Intended Audience :: Developers", - "Programming Language :: Python :: 3", - "Programming Language :: Python :: 3.7", - "Programming Language :: Python :: 3.8", "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.11", diff --git a/requirements.txt b/requirements.txt index 5c87ea3..f359ad7 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,5 +1,5 @@ # Rust->Python build process -maturin>=0.14,<0.15 +maturin~=1.7 toml # Dev-only bumpversion diff --git a/src/lib.rs b/src/lib.rs index 1875cd7..f766a73 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -71,6 +71,23 @@ pub fn ed_from_seed(seed: &[u8]) -> PyResult { Ok(PyKeypair(keypair.secret.into(), keypair.public.into())) } +/// Returns a public key for the given private key. +/// +/// # Arguments +/// +/// * `secret` - A 32 byte private key. +/// +/// # Returns +/// +/// 32-byte public key. +#[pyfunction] +pub fn ed_public_from_secret(secret: &[u8], py: Python) -> PyResult> { + let secret = SigningKey::try_from(secret).map_err(|err| exceptions::PyValueError::new_err(format!("Invalid secret key: {}", err.to_string())))?; + let public = VerificationKey::from(&secret); + + Ok(PyBytes::new_bound(py, &public.as_ref()).into()) +} + /// Signs a message with the given keypair, returning the resulting signature. /// /// # Arguments @@ -118,28 +135,30 @@ pub fn ed_verify(signature: &[u8], message: &[u8], public: &[u8]) -> bool { /// This module is a Python module implemented in Rust. #[pymodule] -fn ed25519_zebra(_py: Python<'_>, m: &PyModule) -> PyResult<()> { - m.add_wrapped(wrap_pyfunction!(ed_from_seed))?; - m.add_wrapped(wrap_pyfunction!(ed_sign))?; - m.add_wrapped(wrap_pyfunction!(ed_verify))?; - +fn ed25519_zebra(m: &Bound<'_, PyModule>) -> PyResult<()> { + m.add_function(wrap_pyfunction!(ed_from_seed, m)?)?; + m.add_function(wrap_pyfunction!(ed_sign, m)?)?; + m.add_function(wrap_pyfunction!(ed_verify, m)?)?; + m.add_function(wrap_pyfunction!(ed_public_from_secret, m)?)?; Ok(()) } // Convert Keypair object to a Python Keypair tuple impl IntoPy for PyKeypair { fn into_py(self, py: Python) -> PyObject { - let secret = PyBytes::new(py, &self.0); - let public = PyBytes::new(py, &self.1); + let secret = PyBytes::new_bound(py, &self.0); + let public = PyBytes::new_bound(py, &self.1); - PyTuple::new(py, vec![secret, public]).into_py(py) + PyTuple::new_bound(py, vec![secret, public]).into_py(py) } } // Convert Keypair object to a Python Keypair tuple impl IntoPy for PySignature { fn into_py(self, py: Python) -> PyObject { - let sig = PyBytes::new(py, &self.0); + // let sig = PyBytes::new(py, &self.0); + let sig = PyBytes::new_bound(py, &self.0); + sig.into_py(py) } } diff --git a/tests.py b/tests.py index 82ab4b4..a1cbe71 100644 --- a/tests.py +++ b/tests.py @@ -69,6 +69,11 @@ def test_sign_invalid_private_key_length(self): with self.assertRaises(ValueError): ed25519_zebra.ed_sign(bytes(1), b"test") + def test_public_from_private(self): + private_key = bytes(32) + public_key = ed25519_zebra.ed_public_from_secret(private_key) + self.assertEqual(bytes.fromhex("3b6a27bcceb6a42d62a3a8d02a6f0d73653215771de243a63ac048a18b59da29"), public_key) + if __name__ == '__main__': unittest.main()