Skip to content

Commit

Permalink
rpc: ensure strings are string types in proto files
Browse files Browse the repository at this point in the history
Update all proto fields that have their corresponding protocol type
encoded as utf8 to `string` but were previously listed as `bytes`. This
is a wire-format compatible change and is safe to make since all
previous uses of these fields were as valid utf8 strings.
  • Loading branch information
bmwill committed Dec 16, 2024
1 parent 3496436 commit f8bfb03
Show file tree
Hide file tree
Showing 7 changed files with 61 additions and 80 deletions.
22 changes: 11 additions & 11 deletions crates/sui-rpc-api/proto/sui.types.proto
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ message GasCostSummary {
// Move {{{

message Identifier {
optional bytes identifier = 1;
optional string identifier = 1;
}

message StructTag {
Expand Down Expand Up @@ -482,19 +482,19 @@ message ActiveJwk {
}

message JwkId {
optional bytes iss = 1;
optional bytes kid = 2;
optional string iss = 1;
optional string kid = 2;
}

message Jwk {
// Key type parameter, <https://datatracker.ietf.org/doc/html/rfc7517#section-4.1>
optional bytes kty = 1;
optional string kty = 1;
// RSA public exponent, <https://datatracker.ietf.org/doc/html/rfc7517#section-9.3>
optional bytes e = 2;
optional string e = 2;
// RSA modulus, <https://datatracker.ietf.org/doc/html/rfc7517#section-9.3>
optional bytes n = 3;
optional string n = 3;
// Algorithm parameter, <https://datatracker.ietf.org/doc/html/rfc7517#section-4.4>
optional bytes alg = 4;
optional string alg = 4;
}

message EndOfEpochTransaction {
Expand Down Expand Up @@ -925,7 +925,7 @@ message SimpleSignature {
}

message ZkLoginPublicIdentifier {
optional bytes iss = 1;
optional string iss = 1;
optional Bn254FieldElement address_seed = 2;
}

Expand Down Expand Up @@ -973,7 +973,7 @@ message ZkLoginAuthenticator {
message ZkLoginInputs {
optional ZkLoginProof proof_points = 1;
optional ZkLoginClaim iss_base64_details = 2;
optional bytes header_base64 = 3;
optional string header_base64 = 3;
optional Bn254FieldElement address_seed = 4;
}

Expand All @@ -984,7 +984,7 @@ message ZkLoginProof {
}

message ZkLoginClaim {
optional bytes value = 1;
optional string value = 1;
optional uint32 index_mod_4 = 2;
}

Expand All @@ -1011,7 +1011,7 @@ message Bn254FieldElement {

message PasskeyAuthenticator {
optional bytes authenticator_data = 1;
optional bytes client_data_json = 2;
optional string client_data_json = 2;
optional SimpleSignature signature = 3;
}

Expand Down
Binary file modified crates/sui-rpc-api/src/proto/generated/sui.node.v2.fds.bin
Binary file not shown.
44 changes: 22 additions & 22 deletions crates/sui-rpc-api/src/proto/generated/sui.types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -262,8 +262,8 @@ pub struct GasCostSummary {
}
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct Identifier {
#[prost(bytes = "bytes", optional, tag = "1")]
pub identifier: ::core::option::Option<::prost::bytes::Bytes>,
#[prost(string, optional, tag = "1")]
pub identifier: ::core::option::Option<::prost::alloc::string::String>,
}
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct StructTag {
Expand Down Expand Up @@ -725,25 +725,25 @@ pub struct ActiveJwk {
}
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct JwkId {
#[prost(bytes = "bytes", optional, tag = "1")]
pub iss: ::core::option::Option<::prost::bytes::Bytes>,
#[prost(bytes = "bytes", optional, tag = "2")]
pub kid: ::core::option::Option<::prost::bytes::Bytes>,
#[prost(string, optional, tag = "1")]
pub iss: ::core::option::Option<::prost::alloc::string::String>,
#[prost(string, optional, tag = "2")]
pub kid: ::core::option::Option<::prost::alloc::string::String>,
}
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct Jwk {
/// Key type parameter, <<https://datatracker.ietf.org/doc/html/rfc7517#section-4.1>>
#[prost(bytes = "bytes", optional, tag = "1")]
pub kty: ::core::option::Option<::prost::bytes::Bytes>,
#[prost(string, optional, tag = "1")]
pub kty: ::core::option::Option<::prost::alloc::string::String>,
/// RSA public exponent, <<https://datatracker.ietf.org/doc/html/rfc7517#section-9.3>>
#[prost(bytes = "bytes", optional, tag = "2")]
pub e: ::core::option::Option<::prost::bytes::Bytes>,
#[prost(string, optional, tag = "2")]
pub e: ::core::option::Option<::prost::alloc::string::String>,
/// RSA modulus, <<https://datatracker.ietf.org/doc/html/rfc7517#section-9.3>>
#[prost(bytes = "bytes", optional, tag = "3")]
pub n: ::core::option::Option<::prost::bytes::Bytes>,
#[prost(string, optional, tag = "3")]
pub n: ::core::option::Option<::prost::alloc::string::String>,
/// Algorithm parameter, <<https://datatracker.ietf.org/doc/html/rfc7517#section-4.4>>
#[prost(bytes = "bytes", optional, tag = "4")]
pub alg: ::core::option::Option<::prost::bytes::Bytes>,
#[prost(string, optional, tag = "4")]
pub alg: ::core::option::Option<::prost::alloc::string::String>,
}
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct EndOfEpochTransaction {
Expand Down Expand Up @@ -1336,8 +1336,8 @@ pub struct SimpleSignature {
}
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct ZkLoginPublicIdentifier {
#[prost(bytes = "bytes", optional, tag = "1")]
pub iss: ::core::option::Option<::prost::bytes::Bytes>,
#[prost(string, optional, tag = "1")]
pub iss: ::core::option::Option<::prost::alloc::string::String>,
#[prost(message, optional, tag = "2")]
pub address_seed: ::core::option::Option<Bn254FieldElement>,
}
Expand Down Expand Up @@ -1419,8 +1419,8 @@ pub struct ZkLoginInputs {
pub proof_points: ::core::option::Option<ZkLoginProof>,
#[prost(message, optional, tag = "2")]
pub iss_base64_details: ::core::option::Option<ZkLoginClaim>,
#[prost(bytes = "bytes", optional, tag = "3")]
pub header_base64: ::core::option::Option<::prost::bytes::Bytes>,
#[prost(string, optional, tag = "3")]
pub header_base64: ::core::option::Option<::prost::alloc::string::String>,
#[prost(message, optional, tag = "4")]
pub address_seed: ::core::option::Option<Bn254FieldElement>,
}
Expand All @@ -1435,8 +1435,8 @@ pub struct ZkLoginProof {
}
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct ZkLoginClaim {
#[prost(bytes = "bytes", optional, tag = "1")]
pub value: ::core::option::Option<::prost::bytes::Bytes>,
#[prost(string, optional, tag = "1")]
pub value: ::core::option::Option<::prost::alloc::string::String>,
#[prost(uint32, optional, tag = "2")]
pub index_mod_4: ::core::option::Option<u32>,
}
Expand Down Expand Up @@ -1473,8 +1473,8 @@ pub struct Bn254FieldElement {
pub struct PasskeyAuthenticator {
#[prost(bytes = "bytes", optional, tag = "1")]
pub authenticator_data: ::core::option::Option<::prost::bytes::Bytes>,
#[prost(bytes = "bytes", optional, tag = "2")]
pub client_data_json: ::core::option::Option<::prost::bytes::Bytes>,
#[prost(string, optional, tag = "2")]
pub client_data_json: ::core::option::Option<::prost::alloc::string::String>,
#[prost(message, optional, tag = "3")]
pub signature: ::core::option::Option<SimpleSignature>,
}
Expand Down
6 changes: 0 additions & 6 deletions crates/sui-rpc-api/src/proto/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,6 @@ impl From<std::num::TryFromIntError> for TryFromProtoError {
}
}

impl From<std::str::Utf8Error> for TryFromProtoError {
fn from(value: std::str::Utf8Error) -> Self {
Self::from_error(value)
}
}

impl From<std::array::TryFromSliceError> for TryFromProtoError {
fn from(value: std::array::TryFromSliceError) -> Self {
Self::from_error(value)
Expand Down
4 changes: 1 addition & 3 deletions crates/sui-rpc-api/src/proto/types/move_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use tap::Pipe;
impl From<sui_sdk_types::types::Identifier> for super::Identifier {
fn from(value: sui_sdk_types::types::Identifier) -> Self {
Self {
identifier: Some(value.into_inner().into_boxed_bytes().into()),
identifier: Some(value.into_inner().into()),
}
}
}
Expand All @@ -21,8 +21,6 @@ impl TryFrom<&super::Identifier> for sui_sdk_types::types::Identifier {
.identifier
.as_ref()
.ok_or_else(|| TryFromProtoError::missing("identifier"))?
.as_ref()
.pipe(std::str::from_utf8)?
.pipe(Self::new)
.map_err(TryFromProtoError::from_error)
}
Expand Down
37 changes: 19 additions & 18 deletions crates/sui-rpc-api/src/proto/types/signatures.rs
Original file line number Diff line number Diff line change
Expand Up @@ -278,10 +278,12 @@ impl TryFrom<&super::CircomG2> for sui_sdk_types::types::CircomG2 {
//

impl From<sui_sdk_types::types::Claim> for super::ZkLoginClaim {
fn from(value: sui_sdk_types::types::Claim) -> Self {
fn from(
sui_sdk_types::types::Claim { value, index_mod_4 }: sui_sdk_types::types::Claim,
) -> Self {
Self {
value: Some(value.value.into_bytes().into()),
index_mod_4: Some(value.index_mod_4.into()),
value: Some(value),
index_mod_4: Some(index_mod_4.into()),
}
}
}
Expand All @@ -295,8 +297,6 @@ impl TryFrom<&super::ZkLoginClaim> for sui_sdk_types::types::Claim {
let value = value
.as_ref()
.ok_or_else(|| TryFromProtoError::missing("value"))?
.as_ref()
.pipe(std::str::from_utf8)?
.into();
let index_mod_4 = index_mod_4
.ok_or_else(|| TryFromProtoError::missing("index_mod_4"))?
Expand Down Expand Up @@ -349,12 +349,19 @@ impl TryFrom<&super::ZkLoginProof> for sui_sdk_types::types::ZkLoginProof {
//

impl From<sui_sdk_types::types::ZkLoginInputs> for super::ZkLoginInputs {
fn from(value: sui_sdk_types::types::ZkLoginInputs) -> Self {
fn from(
sui_sdk_types::types::ZkLoginInputs {
proof_points,
iss_base64_details,
header_base64,
address_seed,
}: sui_sdk_types::types::ZkLoginInputs,
) -> Self {
Self {
proof_points: Some(value.proof_points.into()),
iss_base64_details: Some(value.iss_base64_details.into()),
header_base64: Some(value.header_base64.into_bytes().into()),
address_seed: Some(value.address_seed.into()),
proof_points: Some(proof_points.into()),
iss_base64_details: Some(iss_base64_details.into()),
header_base64: Some(header_base64),
address_seed: Some(address_seed.into()),
}
}
}
Expand All @@ -377,8 +384,6 @@ impl TryFrom<&super::ZkLoginInputs> for sui_sdk_types::types::ZkLoginInputs {
.header_base64
.as_ref()
.ok_or_else(|| TryFromProtoError::missing("header_base64"))?
.as_ref()
.pipe(std::str::from_utf8)?
.into();
let address_seed = value
.address_seed
Expand Down Expand Up @@ -442,7 +447,7 @@ impl TryFrom<&super::ZkLoginAuthenticator> for sui_sdk_types::types::ZkLoginAuth
impl From<&sui_sdk_types::types::ZkLoginPublicIdentifier> for super::ZkLoginPublicIdentifier {
fn from(value: &sui_sdk_types::types::ZkLoginPublicIdentifier) -> Self {
Self {
iss: Some(value.iss().to_owned().into_bytes().into()),
iss: Some(value.iss().to_owned()),
address_seed: Some(value.address_seed().to_owned().into()),
}
}
Expand All @@ -456,8 +461,6 @@ impl TryFrom<&super::ZkLoginPublicIdentifier> for sui_sdk_types::types::ZkLoginP
.iss
.as_ref()
.ok_or_else(|| TryFromProtoError::missing("iss"))?
.as_ref()
.pipe(std::str::from_utf8)?
.into();
let address_seed = value
.address_seed
Expand Down Expand Up @@ -595,7 +598,7 @@ impl From<sui_sdk_types::types::PasskeyAuthenticator> for super::PasskeyAuthenti
fn from(value: sui_sdk_types::types::PasskeyAuthenticator) -> Self {
Self {
authenticator_data: Some(value.authenticator_data().to_vec().into()),
client_data_json: Some(value.client_data_json().as_bytes().to_vec().into()),
client_data_json: Some(value.client_data_json().to_owned()),
signature: Some(value.signature().into()),
}
}
Expand All @@ -614,8 +617,6 @@ impl TryFrom<&super::PasskeyAuthenticator> for sui_sdk_types::types::PasskeyAuth
.client_data_json
.as_ref()
.ok_or_else(|| TryFromProtoError::missing("client_data_json"))?
.as_ref()
.pipe(std::str::from_utf8)?
.into();

let signature = value
Expand Down
28 changes: 8 additions & 20 deletions crates/sui-rpc-api/src/proto/types/transaction_convert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -610,12 +610,12 @@ impl TryFrom<&super::AuthenticatorStateUpdate> for sui_sdk_types::types::Authent
//

impl From<sui_sdk_types::types::Jwk> for super::Jwk {
fn from(value: sui_sdk_types::types::Jwk) -> Self {
fn from(sui_sdk_types::types::Jwk { kty, e, n, alg }: sui_sdk_types::types::Jwk) -> Self {
Self {
kty: Some(value.kty.into_bytes().into()),
e: Some(value.e.into_bytes().into()),
n: Some(value.n.into_bytes().into()),
alg: Some(value.alg.into_bytes().into()),
kty: Some(kty),
e: Some(e),
n: Some(n),
alg: Some(alg),
}
}
}
Expand All @@ -627,26 +627,18 @@ impl TryFrom<&super::Jwk> for sui_sdk_types::types::Jwk {
let kty = kty
.as_ref()
.ok_or_else(|| TryFromProtoError::missing("kty"))?
.as_ref()
.pipe(std::str::from_utf8)?
.into();
let e = e
.as_ref()
.ok_or_else(|| TryFromProtoError::missing("e"))?
.as_ref()
.pipe(std::str::from_utf8)?
.into();
let n = n
.as_ref()
.ok_or_else(|| TryFromProtoError::missing("n"))?
.as_ref()
.pipe(std::str::from_utf8)?
.into();
let alg = alg
.as_ref()
.ok_or_else(|| TryFromProtoError::missing("alg"))?
.as_ref()
.pipe(std::str::from_utf8)?
.into();
Ok(Self { kty, e, n, alg })
}
Expand All @@ -657,10 +649,10 @@ impl TryFrom<&super::Jwk> for sui_sdk_types::types::Jwk {
//

impl From<sui_sdk_types::types::JwkId> for super::JwkId {
fn from(value: sui_sdk_types::types::JwkId) -> Self {
fn from(sui_sdk_types::types::JwkId { iss, kid }: sui_sdk_types::types::JwkId) -> Self {
Self {
iss: Some(value.iss.into_bytes().into()),
kid: Some(value.kid.into_bytes().into()),
iss: Some(iss),
kid: Some(kid),
}
}
}
Expand All @@ -672,14 +664,10 @@ impl TryFrom<&super::JwkId> for sui_sdk_types::types::JwkId {
let iss = iss
.as_ref()
.ok_or_else(|| TryFromProtoError::missing("iss"))?
.as_ref()
.pipe(std::str::from_utf8)?
.into();
let kid = kid
.as_ref()
.ok_or_else(|| TryFromProtoError::missing("kid"))?
.as_ref()
.pipe(std::str::from_utf8)?
.into();
Ok(Self { iss, kid })
}
Expand Down

0 comments on commit f8bfb03

Please sign in to comment.