Skip to content

Commit 240a916

Browse files
committed
Add signature_context to NetworkCapabilities
1 parent 63d593f commit 240a916

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

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
};
@@ -411,11 +412,44 @@ pub struct NetworkCapabilities {
411412

412413
impl NetworkCapabilities {
413414
const CAP_SIGNATURE_WITH_ID: u64 = 0x4000000;
415+
const CAP_SIGNATURE_DOMAIN: u64 = 0x800000000;
414416

415417
/// Returns the signature id if `CapSignatureWithId` capability is enabled.
416418
pub fn signature_id(&self) -> Option<i32> {
417419
(self.raw & Self::CAP_SIGNATURE_WITH_ID != 0).then_some(self.global_id)
418420
}
421+
422+
/// Returns the signature domain type from `CapSignatureDomain` value (enabled or not)
423+
pub fn signature_domain(&self) -> SignatureDomain {
424+
if self.raw & Self::CAP_SIGNATURE_DOMAIN != 0 {
425+
SignatureDomain::L2 {
426+
global_id: self.global_id,
427+
}
428+
} else {
429+
SignatureDomain::Empty
430+
}
431+
}
432+
433+
/// Returns the signature context type which depends on enabled signature capability
434+
pub fn signature_context(&self) -> SignatureContext {
435+
let signature_id_enabled = self.raw & Self::CAP_SIGNATURE_WITH_ID != 0;
436+
let signature_domain_enabled = self.raw & Self::CAP_SIGNATURE_DOMAIN != 0;
437+
438+
match (signature_domain_enabled, signature_id_enabled) {
439+
(true, _) => SignatureContext {
440+
global_id: Some(self.global_id),
441+
signature_type: SignatureType::SignatureDomain,
442+
},
443+
(false, true) => SignatureContext {
444+
global_id: Some(self.global_id),
445+
signature_type: SignatureType::SignatureId,
446+
},
447+
_ => SignatureContext {
448+
global_id: None,
449+
signature_type: SignatureType::Empty,
450+
},
451+
}
452+
}
419453
}
420454

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

0 commit comments

Comments
 (0)