/// Validates the payload and extracts node's public keys
Validates the payload and extracts node's public keys
Validates the payload and extracts node ' s public keys
fn valid_keys_from_payload(
    payload: &AddNodePayload,
) -> Result<(NodeId, ValidNodePublicKeys), String> {
    // 1. verify that the keys we got are not empty
    if payload.node_signing_pk.is_empty() {
        return Err(String::from("node_signing_pk is empty"));
    };
    if payload.committee_signing_pk.is_empty() {
        return Err(String::from("committee_signing_pk is empty"));
    };
    if payload.ni_dkg_dealing_encryption_pk.is_empty() {
        return Err(String::from("ni_dkg_dealing_encryption_pk is empty"));
    };
    if payload.transport_tls_cert.is_empty() {
        return Err(String::from("transport_tls_cert is empty"));
    };
    // 2. get the keys for verification -- for that, we need to create
    // NodePublicKeys first
    let node_signing_pk = PublicKey::decode(&payload.node_signing_pk[..])
        .map_err(|e| format!("node_signing_pk is not in the expected format: {:?}", e))?;
    let committee_signing_pk =
        PublicKey::decode(&payload.committee_signing_pk[..]).map_err(|e| {
            format!(
                "committee_signing_pk is not in the expected format: {:?}",
                e
            )
        })?;
    let tls_certificate = X509PublicKeyCert::decode(&payload.transport_tls_cert[..])
        .map_err(|e| format!("transport_tls_cert is not in the expected format: {:?}", e))?;
    let dkg_dealing_encryption_pk = PublicKey::decode(&payload.ni_dkg_dealing_encryption_pk[..])
        .map_err(|e| {
            format!(
                "ni_dkg_dealing_encryption_pk is not in the expected format: {:?}",
                e
            )
        })?;
    // 3. get the node id from the node_signing_pk
    let node_id = crypto_basicsig_conversions::derive_node_id(&node_signing_pk).map_err(|e| {
        format!(
            "node signing public key couldn't be converted to a NodeId: {:?}",
            e
        )
    })?;
    // 4. get the keys for verification -- for that, we need to create
    let node_pks = NodePublicKeys {
        version: 1, // irrelevant
        node_signing_pk: Some(node_signing_pk),
        committee_signing_pk: Some(committee_signing_pk),
        tls_certificate: Some(tls_certificate),
        dkg_dealing_encryption_pk: Some(dkg_dealing_encryption_pk),
    };
    // 5. validate the keys and the node_id
    match ValidNodePublicKeys::try_from(&node_pks, node_id) {
        Ok(valid_pks) => Ok((node_id, valid_pks)),
        Err(e) => Err(format!("Could not validate public keys, due to {:?}", e)),
    }
}
fn valid_keys_from_payload ( payload : & AddNodePayload , ) -> Result < ( NodeId , ValidNodePublicKeys ) , String > { // 1. verify that the keys we got are not empty if payload . node_signing_pk . is_empty ( ) { return Err ( String :: from ( " " ) ) ; } ; if payload . committee_signing_pk . is_empty ( ) { return Err ( String :: from ( " " ) ) ; } ; if payload . ni_dkg_dealing_encryption_pk . is_empty ( ) { return Err ( String :: from ( " " ) ) ; } ; if payload . transport_tls_cert . is_empty ( ) { return Err ( String :: from ( " " ) ) ; } ; // 2. get the keys for verification -- for that, we need to create // NodePublicKeys first let node_signing_pk = PublicKey :: decode ( & payload . node_signing_pk [ .. ] ) . map_err ( | e | format ! ( " " e ) ) ? ; let committee_signing_pk = PublicKey :: decode ( & payload . committee_signing_pk [ .. ] ) . map_err ( | e | { format ! ( " " e ) } ) ? ; let tls_certificate = X509PublicKeyCert :: decode ( & payload . transport_tls_cert [ .. ] ) . map_err ( | e | format ! ( " " e ) ) ? ; let dkg_dealing_encryption_pk = PublicKey :: decode ( & payload . ni_dkg_dealing_encryption_pk [ .. ] ) . map_err ( | e | { format ! ( " " e ) } ) ? ; // 3. get the node id from the node_signing_pk let node_id = crypto_basicsig_conversions :: derive_node_id ( & node_signing_pk ) . map_err ( | e | { format ! ( " " e ) } ) ? ; // 4. get the keys for verification -- for that, we need to create let node_pks = NodePublicKeys { version : 1 , // irrelevant node_signing_pk : Some ( node_signing_pk ) , committee_signing_pk : Some ( committee_signing_pk ) , tls_certificate : Some ( tls_certificate ) , dkg_dealing_encryption_pk : Some ( dkg_dealing_encryption_pk ) , } ; // 5. validate the keys and the node_id match ValidNodePublicKeys :: try_from ( & node_pks , node_id ) { Ok ( valid_pks ) => Ok ( ( node_id , valid_pks ) ) , Err ( e ) => Err ( format ! ( " " e ) ) , } }
Validates the payload and extracts node's public keys
Validates the payload and extracts node ' s public keys
payload
&AddNodePayload