Skip to content
This repository has been archived by the owner on Jan 16, 2025. It is now read-only.

Commit

Permalink
Merge pull request #27 from dusk-network/pk-sk-integration
Browse files Browse the repository at this point in the history
Integrate PublicKey and SecretKey from schnorr
  • Loading branch information
ZER0 authored Jan 28, 2021
2 parents c56b839 + c280464 commit a8ff0b5
Show file tree
Hide file tree
Showing 18 changed files with 533 additions and 725 deletions.
32 changes: 1 addition & 31 deletions .github/workflows/dusk_ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ jobs:
args: --release

test_nightly_canon:
name: Nightly tests
name: Nightly tests canon
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
Expand All @@ -65,36 +65,6 @@ jobs:
command: test
args: --release --features canon

test_nightly_nostd:
name: Nightly tests
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: nightly
override: true
- uses: actions-rs/cargo@v1
with:
command: test
args: --release --no-default-features

test_nightly_nostd_canon:
name: Nightly tests
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: nightly
override: true
- uses: actions-rs/cargo@v1
with:
command: test
args: --release --no-default-features --features canon

fmt:
name: Rustfmt
runs-on: ubuntu-latest
Expand Down
29 changes: 27 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,35 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [0.4.1] - 26-11-20
## [0.5.0] - 2021-01-28

### Added

- Add `PublicKey` and `SecretKey` (removed from `schnorr`)
- Add `dusk_bytes::Serializable` trait to structure

### Removed

- Remove manual implementation of `to_bytes` and `from_bytes`
- Remove `Error` enum
- Remove `decode` function

### Changed

- Bump `dusk-jubjub` to `v0.8`
- Bump `poseidon252` to `v0.16.0`
- Bump `canonical` to `v0.5`
- Bump `canonical_derive` `v0.5`
- Update CHANGELOG to ISO 8601

## [0.4.1] - 2020-11-26

### Changed

- Use poseidon252 dependency.

## [0.4.0] - 17-11-20
## [0.4.0] - 2020-11-17

### Changed

- No-Std compatibility.
34 changes: 12 additions & 22 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,35 +1,25 @@
[package]
name = "dusk-pki"
version = "0.4.1"
version = "0.5.0"
authors = ["zer0 <[email protected]>", "Victor Lopez <[email protected]"]
edition = "2018"

[dependencies]
rand_core = "0.5.1"
dusk-bls12_381 = {version = "0.3", default-features = false}
dusk-jubjub = {version = "0.5", default-features = false}
poseidon252 = {git = "https://github.com/dusk-network/Poseidon252", tag = "v0.14.1", default-features = false}
hex = {version = "^0.4", default-features = false}
subtle = {version = "^2.2.1", default-features = false}
canonical = {version = "0.4", optional = true}
canonical_derive = {version = "0.4", optional = true}
rand = {version = "0.7", optional = true}
sha2 = {version = "0.8", optional = true}
rand_core = "0.5"
dusk-jubjub = "0.8"
poseidon252 = {git = "https://github.com/dusk-network/Poseidon252", tag = "v0.16.0", default-features = false}
subtle = "^2.2.1"
canonical = {version = "0.5", optional = true}
canonical_derive = {version = "0.5", optional = true}
dusk-bytes = { version = "0.1" }

[dev-dependencies]
rand ="0.7"
sha2 = "0.8"

[features]
default = ["std"]
std = [
"dusk-jubjub/default",
"dusk-bls12_381/default",
"poseidon252/default",
"subtle/default",
"hex/default",
"rand/default",
"sha2/default"
]
canon = [
"canonical",
"canonical_derive",
"dusk-bls12_381/canon",
"dusk-jubjub/canon"
]
47 changes: 0 additions & 47 deletions src/decode.rs

This file was deleted.

31 changes: 0 additions & 31 deletions src/errors.rs

This file was deleted.

9 changes: 9 additions & 0 deletions src/keys.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
//
// Copyright (c) DUSK NETWORK. All rights reserved.

pub mod public;
pub mod secret;
pub mod spend;
58 changes: 58 additions & 0 deletions src/keys/public.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
//
// Copyright (c) DUSK NETWORK. All rights reserved.

use super::secret::SecretKey;
use crate::{JubJubAffine, JubJubExtended};
use dusk_bytes::{Error, HexDebug, Serializable};
use dusk_jubjub::GENERATOR_EXTENDED;

#[cfg(feature = "canon")]
use canonical::Canon;
#[cfg(feature = "canon")]
use canonical_derive::Canon;

/// Structure repesenting a [`PublicKey`]
#[derive(Copy, Clone, PartialEq, HexDebug)]
#[cfg_attr(feature = "canon", derive(Canon))]
pub struct PublicKey(pub(crate) JubJubExtended);

impl From<&SecretKey> for PublicKey {
fn from(sk: &SecretKey) -> Self {
let public_key = GENERATOR_EXTENDED * sk.0;

PublicKey(public_key)
}
}

impl From<JubJubExtended> for PublicKey {
fn from(p: JubJubExtended) -> PublicKey {
PublicKey(p)
}
}

impl From<&JubJubExtended> for PublicKey {
fn from(p: &JubJubExtended) -> PublicKey {
PublicKey(*p)
}
}

impl AsRef<JubJubExtended> for PublicKey {
fn as_ref(&self) -> &JubJubExtended {
&self.0
}
}

impl Serializable<32> for PublicKey {
type Error = Error;

fn to_bytes(&self) -> [u8; 32] {
JubJubAffine::from(self.0).to_bytes()
}

fn from_bytes(bytes: &[u8; 32]) -> Result<Self, Error> {
Ok(Self(JubJubAffine::from_bytes(bytes)?.into()))
}
}
63 changes: 63 additions & 0 deletions src/keys/secret.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
//
// Copyright (c) DUSK NETWORK. All rights reserved.

use crate::JubJubScalar;
use dusk_bytes::{Error, HexDebug, Serializable};
use rand_core::{CryptoRng, RngCore};

#[cfg(feature = "canon")]
use canonical::Canon;
#[cfg(feature = "canon")]
use canonical_derive::Canon;

#[allow(non_snake_case)]
#[cfg_attr(feature = "canon", derive(Canon))]
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, HexDebug)]
/// Structure repesenting a secret key
pub struct SecretKey(pub(crate) JubJubScalar);

impl From<JubJubScalar> for SecretKey {
fn from(s: JubJubScalar) -> SecretKey {
SecretKey(s)
}
}

impl From<&JubJubScalar> for SecretKey {
fn from(s: &JubJubScalar) -> SecretKey {
SecretKey(*s)
}
}

impl AsRef<JubJubScalar> for SecretKey {
fn as_ref(&self) -> &JubJubScalar {
&self.0
}
}

impl SecretKey {
/// This will create a random [`SecretKey`] from a scalar
/// of the Field JubJubScalar.
pub fn random<T>(rand: &mut T) -> SecretKey
where
T: RngCore + CryptoRng,
{
let fr = JubJubScalar::random(rand);

SecretKey(fr)
}
}

impl Serializable<32> for SecretKey {
type Error = Error;

fn to_bytes(&self) -> [u8; 32] {
self.0.to_bytes()
}

fn from_bytes(bytes: &[u8; 32]) -> Result<Self, Error> {
Ok(Self(JubJubScalar::from_bytes(bytes)?))
}
}
File renamed without changes.
Loading

0 comments on commit a8ff0b5

Please sign in to comment.