-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Export inputs in uniffi * Replace mono/poly interactors with a single interactor for signing * Expose sign request to uniffi * Expose neglected factors * Expose hd signature * Expose sign response * Expose sign with factors outcome * WIP * WIP 2 * WIP 3 * WIP 4 * WIP 5 * Add Send + Sync to SignInteractor * Use a single "poly" interactor for keys derivation * Separate boot methods to expose one for clients * Bridge the internal and the uniffi host interactor * Fix android unit tests * Expose sign methods in sargon os * Rename outcome * Implement signing methods for export * Replace with rwlock in PetitionForFactorsSubState * Replace with rwlock in PetitionForFactorsState * Replace with rwlock in PetitionForFactors * Fix debug and remove clone * Replace with rwlock in PetitionForEntity * Replace with rwlock in PetitionForTransaction * Replace with rwlock in Petitions * Replace with rwlock in SignaturesCollectorState * Replace with rwlock in SignaturesCollector * Expose signing methods with uniffi * Run fmt * Run clippy * Add failing profile test * Add failing test due to irrelevant entity * Remove no ui interactor * Run fmt * Put back methods * Fix hdsignature ctor * Fix tests * Replace with signature with public key * Add uniffi tests * Replace custom conversions with InternalConversion * Rename expect messages * Remove cloned * Implement macros for hd signature * Implement macros for invalid transaction if neglected * Implement macros for signatures per factor source * Implement macros for sign response * Implement macros for sign with factors outcome * Remove hashmap from uniffi sign request * Implement macros for sign request * Fix kotlin tests * Define interactors type * Bump sargon * Add abandoned reasons * Declare signed outcome with macro * Add some tests * Fix per factor source * Clippy fix * WIP * WIP * Add send + sync * Redeclare macros * fmt * lift HasSampleValues restriction on Signable trait (#290) * Remove outcome * Replace outcome with result * Allow simulated user to also reject signing. * Fmt * Clippy * Throw signing rejected * Skip swift tests * fmt * Swift format --------- Co-authored-by: Alexander Cyon <[email protected]>
- Loading branch information
1 parent
61bf503
commit 55e0def
Showing
129 changed files
with
3,188 additions
and
1,551 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
apple/Sources/Sargon/SargonOS/ThrowingHostInteractor+Static+Shared.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// A default stub implementation of the HostInteractor, that always rejects any operation | ||
public class ThrowingHostInteractor: HostInteractor { | ||
public nonisolated(unsafe) static var shared: HostInteractor = ThrowingHostInteractor() | ||
|
||
public func signTransactions(request: SargonUniFFI.SignRequestOfTransactionIntent) async throws -> SargonUniFFI.SignWithFactorsOutcomeOfTransactionIntentHash { | ||
throw CommonError.SigningRejected | ||
} | ||
|
||
public func signSubintents(request: SargonUniFFI.SignRequestOfSubintent) async throws -> SargonUniFFI.SignWithFactorsOutcomeOfSubintentHash { | ||
throw CommonError.SigningRejected | ||
} | ||
|
||
public func deriveKeys(request: SargonUniFFI.KeyDerivationRequest) async throws -> SargonUniFFI.KeyDerivationResponse { | ||
throw CommonError.Unknown | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
crates/sargon-uniffi/src/keys_collector/key_derivation_request.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
use crate::prelude::*; | ||
use sargon::indexmap::IndexMap; | ||
use sargon::{IndexSet, KeyDerivationRequest as InternalKeyDerivationRequest}; | ||
|
||
/// A collection of derivation paths, on a per-factor-source basis. | ||
#[derive(Clone, PartialEq, Eq, uniffi::Record)] | ||
pub struct KeyDerivationRequest { | ||
pub per_factor_source: HashMap<FactorSourceIDFromHash, Vec<DerivationPath>>, | ||
} | ||
|
||
impl KeyDerivationRequest { | ||
pub fn into_internal(&self) -> InternalKeyDerivationRequest { | ||
self.clone().into() | ||
} | ||
} | ||
|
||
impl From<InternalKeyDerivationRequest> for KeyDerivationRequest { | ||
fn from(value: InternalKeyDerivationRequest) -> Self { | ||
Self { | ||
per_factor_source: value | ||
.per_factor_source | ||
.into_iter() | ||
.map(|(k, v)| { | ||
(k.into(), v.into_iter().map(|d| d.into()).collect()) | ||
}) | ||
.collect(), | ||
} | ||
} | ||
} | ||
|
||
impl From<KeyDerivationRequest> for InternalKeyDerivationRequest { | ||
fn from(value: KeyDerivationRequest) -> Self { | ||
Self::new(IndexMap::from_iter( | ||
value.per_factor_source.into_iter().map(|(k, v)| { | ||
( | ||
k.into_internal(), | ||
IndexSet::from_iter( | ||
v.into_iter().map(|d| d.into_internal()), | ||
), | ||
) | ||
}), | ||
)) | ||
} | ||
} |
70 changes: 70 additions & 0 deletions
70
crates/sargon-uniffi/src/keys_collector/key_derivation_response.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
use crate::prelude::*; | ||
use sargon::IndexMap; | ||
use sargon::IndexSet; | ||
use sargon::KeyDerivationResponse as InternalKeyDerivationResponse; | ||
|
||
/// A collection of `HierarchicalDeterministicFactorInstance`s, on a | ||
/// per-factor-source basis. In case of MonoKeyDerivation the list will contain | ||
/// a single `KeyDerivationPerFactorSource`. | ||
#[derive(Clone, PartialEq, Eq, uniffi::Record)] | ||
pub struct KeyDerivationResponse { | ||
pub per_factor_source: Vec<KeyDerivationPerFactorSource>, | ||
} | ||
|
||
#[derive(Clone, PartialEq, Eq, uniffi::Record)] | ||
pub struct KeyDerivationPerFactorSource { | ||
pub factor_source_id: FactorSourceIDFromHash, | ||
pub factor_instances: Vec<HierarchicalDeterministicFactorInstance>, | ||
} | ||
|
||
impl KeyDerivationPerFactorSource { | ||
pub fn new( | ||
factor_source_id: FactorSourceIDFromHash, | ||
factor_instances: Vec<HierarchicalDeterministicFactorInstance>, | ||
) -> Self { | ||
Self { | ||
factor_source_id, | ||
factor_instances, | ||
} | ||
} | ||
} | ||
|
||
impl KeyDerivationResponse { | ||
pub fn into_internal(&self) -> InternalKeyDerivationResponse { | ||
self.clone().into() | ||
} | ||
} | ||
|
||
impl From<InternalKeyDerivationResponse> for KeyDerivationResponse { | ||
fn from(value: InternalKeyDerivationResponse) -> Self { | ||
Self { | ||
per_factor_source: value | ||
.per_factor_source | ||
.into_iter() | ||
.map(|(k, v)| { | ||
KeyDerivationPerFactorSource::new( | ||
k.into(), | ||
v.into_iter().map(|d| d.into()).collect(), | ||
) | ||
}) | ||
.collect(), | ||
} | ||
} | ||
} | ||
|
||
impl From<KeyDerivationResponse> for InternalKeyDerivationResponse { | ||
fn from(value: KeyDerivationResponse) -> Self { | ||
Self::new(IndexMap::from_iter( | ||
value.per_factor_source.into_iter().map(|item| { | ||
( | ||
item.factor_source_id.into_internal(), | ||
IndexSet::from_iter( | ||
item.factor_instances | ||
.into_iter() | ||
.map(|d| d.into_internal()), | ||
), | ||
) | ||
}), | ||
)) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
mod key_derivation_request; | ||
mod key_derivation_response; | ||
|
||
pub use key_derivation_request::*; | ||
pub use key_derivation_response::*; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
use crate::prelude::*; | ||
use paste::paste; | ||
|
||
macro_rules! decl_hd_signature { | ||
( | ||
struct_name: $struct_name:ident, | ||
inp: $input:ident | ||
) => { | ||
#[derive(Clone, PartialEq, Eq, Hash, InternalConversion, uniffi::Record)] | ||
pub struct $struct_name { | ||
/// The input used to produce this `HDSignature` | ||
pub input: $input, | ||
|
||
/// The ECDSA/EdDSA signature produced by the private key of the | ||
/// `owned_hd_factor_instance.public_key`, | ||
/// derived by the HDFactorSource identified by | ||
/// `owned_hd_factor_ | ||
/// instance.factor_s | ||
/// ource_id` and which | ||
/// was derived at `owned_hd_factor_instance.derivation_path`. | ||
pub signature: SignatureWithPublicKey, | ||
} | ||
}; | ||
($type:ty) => { | ||
paste! { | ||
use sargon::[< $type >] as [< Internal $type >]; | ||
|
||
type [< InternalHDSignatureOf $type >] = sargon::HDSignature<[< Internal $type >]>; | ||
|
||
decl_hd_signature!( | ||
struct_name: [< HDSignatureOf $type >], | ||
inp: [< HDSignatureInputOf $type >] | ||
); | ||
} | ||
}; | ||
} | ||
|
||
decl_hd_signature!(TransactionIntentHash); | ||
decl_hd_signature!(SubintentHash); |
Oops, something went wrong.