Skip to content

Commit 78830a9

Browse files
committed
Add signature_context to NetworkCapabilities
1 parent 604213f commit 78830a9

1 file changed

Lines changed: 34 additions & 0 deletions

File tree

src/models.rs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ use nekoton_abi::*;
1010
use nekoton_utils::*;
1111

1212
// TODO: (-_-)
13+
use crate::crypto::{SignatureContext, SignatureDomain, SignatureType};
1314
pub use nekoton_contracts::tip3_any::{
1415
RootTokenContractDetails, TokenWalletDetails, TokenWalletVersion,
1516
};
@@ -420,11 +421,44 @@ pub struct NetworkCapabilities {
420421

421422
impl NetworkCapabilities {
422423
const CAP_SIGNATURE_WITH_ID: u64 = 0x4000000;
424+
const CAP_SIGNATURE_DOMAIN: u64 = 0x800000000;
423425

424426
/// Returns the signature id if `CapSignatureWithId` capability is enabled.
425427
pub fn signature_id(&self) -> Option<i32> {
426428
(self.raw & Self::CAP_SIGNATURE_WITH_ID != 0).then_some(self.global_id)
427429
}
430+
431+
/// Returns the signature domain type from `CapSignatureDomain` value (enabled or not)
432+
pub fn signature_domain(&self) -> SignatureDomain {
433+
if self.raw & Self::CAP_SIGNATURE_DOMAIN != 0 {
434+
SignatureDomain::L2 {
435+
global_id: self.global_id,
436+
}
437+
} else {
438+
SignatureDomain::Empty
439+
}
440+
}
441+
442+
/// Returns the signature context type which depends on enabled signature capability
443+
pub fn signature_context(&self) -> SignatureContext {
444+
let signature_id_enabled = self.raw & Self::CAP_SIGNATURE_WITH_ID != 0;
445+
let signature_domain_enabled = self.raw & Self::CAP_SIGNATURE_DOMAIN != 0;
446+
447+
match (signature_domain_enabled, signature_id_enabled) {
448+
(true, _) => SignatureContext {
449+
global_id: Some(self.global_id),
450+
signature_type: SignatureType::SignatureDomain,
451+
},
452+
(false, true) => SignatureContext {
453+
global_id: Some(self.global_id),
454+
signature_type: SignatureType::SignatureId,
455+
},
456+
_ => SignatureContext {
457+
global_id: None,
458+
signature_type: SignatureType::Empty,
459+
},
460+
}
461+
}
428462
}
429463

430464
#[derive(Debug, Copy, Clone, Eq, PartialEq, Serialize, Deserialize)]

0 commit comments

Comments
 (0)