add secret-key for ecash credential storage
This commit is contained in:
@@ -85,9 +85,9 @@ where
|
||||
.await?;
|
||||
storage
|
||||
.insert_ecash_credential(
|
||||
state.voucher.get_voucher_value(),
|
||||
ECASH_INFO.to_string(),
|
||||
wallet.to_bs58(),
|
||||
state.voucher.ecash_keypair().secret_key().to_bs58(),
|
||||
epoch_id.to_string(),
|
||||
)
|
||||
.await
|
||||
|
||||
@@ -41,8 +41,6 @@ impl<C, St: Storage> BandwidthController<C, St> {
|
||||
.get_next_ecash_credential()
|
||||
.await
|
||||
.map_err(|err| BandwidthControllerError::CredentialStorageError(Box::new(err)))?;
|
||||
let voucher_value = u64::from_str(&ecash_credential.voucher_value)
|
||||
.map_err(|_| StorageError::InconsistentData)?;
|
||||
let voucher_info = ecash_credential.voucher_info.clone();
|
||||
let wallet = Wallet::try_from_bs58(ecash_credential.wallet)?;
|
||||
let epoch_id = u64::from_str(&ecash_credential.epoch_id)
|
||||
|
||||
@@ -6,9 +6,9 @@
|
||||
CREATE TABLE ecash_credentials
|
||||
(
|
||||
id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
|
||||
voucher_value TEXT NOT NULL,
|
||||
voucher_info TEXT NOT NULL,
|
||||
wallet TEXT NOT NULL UNIQUE,
|
||||
secret_key TEXT NOT NULL,
|
||||
epoch_id TEXT NOT NULL,
|
||||
consumed BOOLEAN NOT NULL
|
||||
);
|
||||
@@ -56,25 +56,24 @@ impl CoconutCredentialManager {
|
||||
///
|
||||
/// # Arguments
|
||||
///
|
||||
/// * `voucher_value`: Plaintext bandwidth value of the credential.
|
||||
/// * `voucher_info`: Plaintext information of the credential.
|
||||
/// * `serial_number`: Base58 representation of the serial number attribute.
|
||||
/// * `binding_number`: Base58 representation of the binding number attribute.
|
||||
/// * `signature`: Coconut credential in the form of a signature.
|
||||
/// * `voucher_info`: What type of credential it is.
|
||||
/// * `signature`: Ecash wallet credential in the form of a wallet.
|
||||
/// * `secret_key`: The secret key with which this credential has been created.
|
||||
/// * `epoch_id`: The epoch when it was signed.
|
||||
pub async fn insert_ecash_credential(
|
||||
&self,
|
||||
voucher_value: String,
|
||||
voucher_info: String,
|
||||
wallet: String,
|
||||
secret_key: String,
|
||||
epoch_id: String,
|
||||
) {
|
||||
let mut creds = self.ecash.write().await;
|
||||
let id = creds.len() as i64;
|
||||
creds.push(EcashCredential {
|
||||
id,
|
||||
voucher_value,
|
||||
voucher_info,
|
||||
wallet,
|
||||
secret_key,
|
||||
epoch_id,
|
||||
consumed: false,
|
||||
});
|
||||
|
||||
@@ -49,19 +49,21 @@ impl CoconutCredentialManager {
|
||||
///
|
||||
/// # Arguments
|
||||
///
|
||||
/// * `voucher_value`: Plaintext bandwidth value of the credential.
|
||||
/// * `voucher_info`: Plaintext information of the credential.
|
||||
/// * `signature`: Coconut credential in the form of a signature.
|
||||
/// * `voucher_info`: What type of credential it is.
|
||||
/// * `signature`: Ecash wallet credential in the form of a wallet.
|
||||
/// * `secret_key`: The secret key with which this credential has been created.
|
||||
/// * `epoch_id`: The epoch when it was signed.
|
||||
|
||||
pub async fn insert_ecash_credential(
|
||||
&self,
|
||||
voucher_value: String,
|
||||
voucher_info: String,
|
||||
wallet: String,
|
||||
secret_key: String,
|
||||
epoch_id: String,
|
||||
) -> Result<(), sqlx::Error> {
|
||||
sqlx::query!(
|
||||
"INSERT INTO ecash_credentials(voucher_value, voucher_info, wallet, epoch_id, consumed) VALUES (?, ?, ?, ?, ?)",
|
||||
voucher_value, voucher_info, wallet, epoch_id, false
|
||||
"INSERT INTO ecash_credentials(voucher_info, wallet, secret_key, epoch_id, consumed) VALUES (?, ?, ?, ?, ?)",
|
||||
voucher_info, wallet, secret_key, epoch_id, false
|
||||
)
|
||||
.execute(&self.connection_pool)
|
||||
.await?;
|
||||
|
||||
@@ -52,13 +52,13 @@ impl Storage for EphemeralStorage {
|
||||
|
||||
async fn insert_ecash_credential(
|
||||
&self,
|
||||
voucher_value: String,
|
||||
voucher_info: String,
|
||||
wallet: String,
|
||||
secret_key: String,
|
||||
epoch_id: String,
|
||||
) -> Result<(), StorageError> {
|
||||
self.coconut_credential_manager
|
||||
.insert_ecash_credential(voucher_value, voucher_info, wallet, epoch_id)
|
||||
.insert_ecash_credential(voucher_info, wallet, secret_key, epoch_id)
|
||||
.await;
|
||||
|
||||
Ok(())
|
||||
|
||||
@@ -18,9 +18,9 @@ pub struct CoconutCredential {
|
||||
pub struct EcashCredential {
|
||||
#[allow(dead_code)]
|
||||
pub id: i64,
|
||||
pub voucher_value: String,
|
||||
pub voucher_info: String,
|
||||
pub wallet: String,
|
||||
pub secret_key: String,
|
||||
pub epoch_id: String,
|
||||
pub consumed: bool,
|
||||
}
|
||||
|
||||
@@ -83,13 +83,13 @@ impl Storage for PersistentStorage {
|
||||
|
||||
async fn insert_ecash_credential(
|
||||
&self,
|
||||
voucher_value: String,
|
||||
voucher_info: String,
|
||||
wallet: String,
|
||||
secret_key: String,
|
||||
epoch_id: String,
|
||||
) -> Result<(), StorageError> {
|
||||
self.coconut_credential_manager
|
||||
.insert_ecash_credential(voucher_value, voucher_info, wallet, epoch_id)
|
||||
.insert_ecash_credential(voucher_info, wallet, secret_key, epoch_id)
|
||||
.await?;
|
||||
|
||||
Ok(())
|
||||
|
||||
@@ -33,15 +33,15 @@ pub trait Storage: Send + Sync {
|
||||
///
|
||||
/// # Arguments
|
||||
///
|
||||
/// * `voucher_value`: How much bandwidth is in the credential.
|
||||
/// * `voucher_info`: What type of credential it is.
|
||||
/// * `signature`: Ecash wallet credential in the form of a wallet.
|
||||
/// * `secret_key`: The secret key with which this credential has been created.
|
||||
/// * `epoch_id`: The epoch when it was signed.
|
||||
async fn insert_ecash_credential(
|
||||
&self,
|
||||
voucher_value: String,
|
||||
voucher_info: String,
|
||||
signature: String,
|
||||
secret_key: String,
|
||||
epoch_id: String,
|
||||
) -> Result<(), Self::StorageError>;
|
||||
|
||||
|
||||
@@ -355,6 +355,18 @@ impl SecretKeyUser {
|
||||
}
|
||||
}
|
||||
|
||||
impl Bytable for SecretKeyUser {
|
||||
fn to_byte_vec(&self) -> Vec<u8> {
|
||||
self.to_bytes().to_vec()
|
||||
}
|
||||
|
||||
fn try_from_byte_slice(slice: &[u8]) -> std::result::Result<Self, CompactEcashError> {
|
||||
Self::from_bytes(slice)
|
||||
}
|
||||
}
|
||||
|
||||
impl Base58 for SecretKeyUser {}
|
||||
|
||||
#[derive(Debug, Eq, PartialEq, Clone, Hash)]
|
||||
pub struct PublicKeyUser {
|
||||
pub(crate) pk: G1Projective,
|
||||
|
||||
Reference in New Issue
Block a user