This repository has been archived by the owner on Jan 16, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #27 from dusk-network/pk-sk-integration
Integrate PublicKey and SecretKey from schnorr
- Loading branch information
Showing
18 changed files
with
533 additions
and
725 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
] |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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())) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
Oops, something went wrong.