Skip to content

Commit fa642c1

Browse files
committed
fixup! feat(truapi-server): add host logic primitives
1 parent 2d88bdf commit fa642c1

2 files changed

Lines changed: 56 additions & 44 deletions

File tree

rust/crates/truapi-server/src/host_logic/sso/messages.rs

Lines changed: 28 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ use crate::host_logic::statement_store::{
3333
statement_expiry_elapsed,
3434
};
3535

36+
pub mod v1;
37+
3638
#[derive(Debug, Clone, Copy, PartialEq, Eq, Encode, Decode, derive_more::Display)]
3739
enum SsoResponseCode {
3840
#[codec(index = 0)]
@@ -71,27 +73,7 @@ pub struct RemoteMessage {
7173
/// Versioned remote message body.
7274
#[derive(Debug, Clone, PartialEq, Eq, Encode, Decode)]
7375
pub enum RemoteMessageData {
74-
V1(RemoteMessageV1),
75-
}
76-
77-
/// v1 messages exchanged with the paired signing host over the encrypted SSO channel.
78-
///
79-
/// The variant order is part of the SCALE wire protocol used inside
80-
/// statement-store session statements.
81-
#[derive(Debug, Clone, PartialEq, Eq, Encode, Decode)]
82-
pub enum RemoteMessageV1 {
83-
Disconnected,
84-
SignRequest(Box<SigningRequest>),
85-
SignResponse(SigningResponse),
86-
RingVrfAliasRequest(RingVrfAliasRequest),
87-
RingVrfAliasResponse(RingVrfAliasResponse),
88-
ResourceAllocationRequest(ResourceAllocationRequest),
89-
ResourceAllocationResponse(ResourceAllocationResponse),
90-
CreateTransactionRequest(CreateTransactionRequest),
91-
CreateTransactionResponse(CreateTransactionResponse),
92-
CreateTransactionLegacyRequest(CreateTransactionLegacyRequest),
93-
SignRawLegacyRequest(SignRawLegacyRequest),
94-
SignRawLegacyResponse(SignRawLegacyResponse),
76+
V1(v1::RemoteMessage),
9577
}
9678

9779
/// Signing request flavor sent to the signing host.
@@ -155,7 +137,7 @@ impl From<truapi::v01::HostSignPayloadRequest> for SigningPayloadRequest {
155137
/// string message with a product-derived account.
156138
///
157139
/// Built from [`HostSignRawRequest`] and wrapped in
158-
/// [`RemoteMessageV1::SignRequest`] before being encrypted into an SSO session
140+
/// [`v1::RemoteMessage::SignRequest`] before being encrypted into an SSO session
159141
/// statement.
160142
#[derive(Debug, Clone, PartialEq, Eq, Encode, Decode)]
161143
pub struct SigningRawRequest {
@@ -205,7 +187,7 @@ impl From<RawPayload> for SigningRawPayload {
205187

206188
/// Response returned by the signing host for a product-account signing request.
207189
///
208-
/// Decoded from [`RemoteMessageV1::SignResponse`] while the runtime is waiting
190+
/// Decoded from [`v1::RemoteMessage::SignResponse`] while the runtime is waiting
209191
/// for a matching SSO remote message id.
210192
#[derive(Debug, Clone, PartialEq, Eq, Encode, Decode)]
211193
pub struct SigningResponse {
@@ -222,7 +204,7 @@ pub struct SigningPayloadResponseData {
222204

223205
/// Response returned by the signing host for a legacy-account raw signing request.
224206
///
225-
/// Decoded from [`RemoteMessageV1::SignRawLegacyResponse`] and mapped back to
207+
/// Decoded from [`v1::RemoteMessage::SignRawLegacyResponse`] and mapped back to
226208
/// the public raw-signing response shape.
227209
#[derive(Debug, Clone, PartialEq, Eq, Encode, Decode)]
228210
pub struct SignRawLegacyResponse {
@@ -419,7 +401,7 @@ pub fn decode_sso_session_statement(
419401
.map_err(|err| format!("invalid SSO remote message: {err}"))?;
420402
if matches!(
421403
&message.data,
422-
RemoteMessageData::V1(RemoteMessageV1::Disconnected)
404+
RemoteMessageData::V1(v1::RemoteMessage::Disconnected)
423405
) {
424406
return Ok(Some(SsoSessionStatement::Disconnected));
425407
}
@@ -451,27 +433,27 @@ fn remote_response_for_message(
451433
) -> Option<SsoRemoteResponse> {
452434
let RemoteMessageData::V1(data) = message.data;
453435
match data {
454-
RemoteMessageV1::SignResponse(response)
436+
v1::RemoteMessage::SignResponse(response)
455437
if response.responding_to == expected_remote_message_id =>
456438
{
457439
Some(SsoRemoteResponse::Sign(response))
458440
}
459-
RemoteMessageV1::RingVrfAliasResponse(response)
441+
v1::RemoteMessage::RingVrfAliasResponse(response)
460442
if response.responding_to == expected_remote_message_id =>
461443
{
462444
Some(SsoRemoteResponse::RingVrfAlias(response))
463445
}
464-
RemoteMessageV1::SignRawLegacyResponse(response)
446+
v1::RemoteMessage::SignRawLegacyResponse(response)
465447
if response.responding_to == expected_remote_message_id =>
466448
{
467449
Some(SsoRemoteResponse::SignRawLegacy(response))
468450
}
469-
RemoteMessageV1::ResourceAllocationResponse(response)
451+
v1::RemoteMessage::ResourceAllocationResponse(response)
470452
if response.responding_to == expected_remote_message_id =>
471453
{
472454
Some(SsoRemoteResponse::ResourceAllocation(response))
473455
}
474-
RemoteMessageV1::CreateTransactionResponse(response)
456+
v1::RemoteMessage::CreateTransactionResponse(response)
475457
if response.responding_to == expected_remote_message_id =>
476458
{
477459
Some(SsoRemoteResponse::CreateTransaction(response))
@@ -484,7 +466,7 @@ fn remote_response_for_message(
484466
pub fn sign_payload_message(message_id: String, request: HostSignPayloadRequest) -> RemoteMessage {
485467
RemoteMessage {
486468
message_id,
487-
data: RemoteMessageData::V1(RemoteMessageV1::SignRequest(Box::new(
469+
data: RemoteMessageData::V1(v1::RemoteMessage::SignRequest(Box::new(
488470
SigningRequest::Payload(Box::new(request.into())),
489471
))),
490472
}
@@ -494,9 +476,9 @@ pub fn sign_payload_message(message_id: String, request: HostSignPayloadRequest)
494476
pub fn sign_raw_message(message_id: String, request: HostSignRawRequest) -> RemoteMessage {
495477
RemoteMessage {
496478
message_id,
497-
data: RemoteMessageData::V1(RemoteMessageV1::SignRequest(Box::new(SigningRequest::Raw(
498-
request.into(),
499-
)))),
479+
data: RemoteMessageData::V1(v1::RemoteMessage::SignRequest(Box::new(
480+
SigningRequest::Raw(request.into()),
481+
))),
500482
}
501483
}
502484

@@ -508,7 +490,7 @@ pub fn sign_raw_legacy_message(
508490
) -> RemoteMessage {
509491
RemoteMessage {
510492
message_id,
511-
data: RemoteMessageData::V1(RemoteMessageV1::SignRawLegacyRequest(
493+
data: RemoteMessageData::V1(v1::RemoteMessage::SignRawLegacyRequest(
512494
SignRawLegacyRequest {
513495
account,
514496
data: payload.into(),
@@ -525,10 +507,12 @@ pub fn alias_request_message(
525507
) -> RemoteMessage {
526508
RemoteMessage {
527509
message_id,
528-
data: RemoteMessageData::V1(RemoteMessageV1::RingVrfAliasRequest(RingVrfAliasRequest {
529-
product_account_id,
530-
product_id,
531-
})),
510+
data: RemoteMessageData::V1(v1::RemoteMessage::RingVrfAliasRequest(
511+
RingVrfAliasRequest {
512+
product_account_id,
513+
product_id,
514+
},
515+
)),
532516
}
533517
}
534518

@@ -541,7 +525,7 @@ pub fn resource_allocation_message(
541525
) -> RemoteMessage {
542526
RemoteMessage {
543527
message_id,
544-
data: RemoteMessageData::V1(RemoteMessageV1::ResourceAllocationRequest(
528+
data: RemoteMessageData::V1(v1::RemoteMessage::ResourceAllocationRequest(
545529
ResourceAllocationRequest {
546530
calling_product_id,
547531
resources: resources.into_iter().map(Into::into).collect(),
@@ -558,7 +542,7 @@ pub fn create_transaction_message(
558542
) -> RemoteMessage {
559543
RemoteMessage {
560544
message_id,
561-
data: RemoteMessageData::V1(RemoteMessageV1::CreateTransactionRequest(
545+
data: RemoteMessageData::V1(v1::RemoteMessage::CreateTransactionRequest(
562546
CreateTransactionRequest {
563547
payload: CreateTransactionPayload::V1(payload),
564548
},
@@ -573,7 +557,7 @@ pub fn create_transaction_legacy_message(
573557
) -> RemoteMessage {
574558
RemoteMessage {
575559
message_id,
576-
data: RemoteMessageData::V1(RemoteMessageV1::CreateTransactionLegacyRequest(
560+
data: RemoteMessageData::V1(v1::RemoteMessage::CreateTransactionLegacyRequest(
577561
CreateTransactionLegacyRequest {
578562
payload: CreateTransactionLegacyPayload::V1(payload),
579563
},
@@ -698,7 +682,7 @@ mod tests {
698682
fn disconnected_message_matches_host_papp_variant_order() {
699683
let message = RemoteMessage {
700684
message_id: String::new(),
701-
data: RemoteMessageData::V1(RemoteMessageV1::Disconnected),
685+
data: RemoteMessageData::V1(v1::RemoteMessage::Disconnected),
702686
};
703687

704688
assert_eq!(message.encode(), vec![0, 0, 0]);
@@ -920,7 +904,7 @@ mod tests {
920904
],
921905
OnExistingAllowancePolicy::Increase,
922906
);
923-
let RemoteMessageData::V1(RemoteMessageV1::ResourceAllocationRequest(request)) =
907+
let RemoteMessageData::V1(v1::RemoteMessage::ResourceAllocationRequest(request)) =
924908
message.data
925909
else {
926910
panic!("expected resource allocation request");
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
use parity_scale_codec::{Decode, Encode};
2+
3+
use super::{
4+
CreateTransactionLegacyRequest, CreateTransactionRequest, CreateTransactionResponse,
5+
ResourceAllocationRequest, ResourceAllocationResponse, RingVrfAliasRequest,
6+
RingVrfAliasResponse, SignRawLegacyRequest, SignRawLegacyResponse, SigningRequest,
7+
SigningResponse,
8+
};
9+
10+
/// v1 messages exchanged with the paired signing host over the encrypted SSO channel.
11+
///
12+
/// The variant order is part of the SCALE wire protocol used inside
13+
/// statement-store session statements.
14+
#[derive(Debug, Clone, PartialEq, Eq, Encode, Decode)]
15+
pub enum RemoteMessage {
16+
Disconnected,
17+
SignRequest(Box<SigningRequest>),
18+
SignResponse(SigningResponse),
19+
RingVrfAliasRequest(RingVrfAliasRequest),
20+
RingVrfAliasResponse(RingVrfAliasResponse),
21+
ResourceAllocationRequest(ResourceAllocationRequest),
22+
ResourceAllocationResponse(ResourceAllocationResponse),
23+
CreateTransactionRequest(CreateTransactionRequest),
24+
CreateTransactionResponse(CreateTransactionResponse),
25+
CreateTransactionLegacyRequest(CreateTransactionLegacyRequest),
26+
SignRawLegacyRequest(SignRawLegacyRequest),
27+
SignRawLegacyResponse(SignRawLegacyResponse),
28+
}

0 commit comments

Comments
 (0)