Skip to content

Commit c1d0291

Browse files
authored
Merge pull request #42 from Foundation-Devices/nix-flake
Nix flake + formatting
2 parents 37f94ab + a7243ae commit c1d0291

29 files changed

+287
-178
lines changed

.github/workflows/rust.yml

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,20 +19,22 @@ jobs:
1919
env:
2020
GH_TOKEN: ${{ secrets.GH_TOKEN }}
2121
run: |
22-
# Configure git to use gh as a credential helper for https://github.com
2322
gh auth setup-git
2423
24+
- name: Setup nix
25+
uses: DeterminateSystems/[email protected]
26+
2527
- name: Check formatting
2628
env:
2729
GH_TOKEN: ${{ secrets.GH_TOKEN }}
28-
run: cargo fmt --all -- --check
30+
run: nix develop --command cargo fmt --all -- --check
2931

3032
- name: Run Clippy (fail on warnings)
3133
env:
3234
GH_TOKEN: ${{ secrets.GH_TOKEN }}
33-
run: cargo clippy --all-targets --all-features -- -D warnings
35+
run: nix develop --command cargo clippy --all-targets --all-features -- -D warnings
3436

3537
- name: Run tests
3638
env:
3739
GH_TOKEN: ${{ secrets.GH_TOKEN }}
38-
run: cargo test --verbose
40+
run: nix develop --command cargo test --verbose

abstracted/src/abstracted/abstract_bluetooth.rs

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,16 @@
1-
use bc_envelope::prelude::CBOREncodable;
2-
use bc_envelope::{EnvelopeEncodable, Expression, ResponseBehavior};
3-
use bc_xid::XIDDocument;
4-
use gstp::{SealedRequestBehavior, SealedResponseBehavior};
5-
use {
6-
crate::{AbstractEnclave, SecureFrom, SecureTryFrom},
7-
anyhow::Result,
8-
async_trait::async_trait,
9-
bc_components::ARID,
10-
bc_envelope::Envelope,
11-
gstp::{SealedRequest, SealedResponse},
12-
std::time::Duration,
13-
};
1+
use std::time::Duration;
142

3+
use anyhow::Result;
4+
use async_trait::async_trait;
5+
use bc_components::ARID;
6+
use bc_envelope::{
7+
prelude::CBOREncodable, Envelope, EnvelopeEncodable, Expression, ResponseBehavior,
8+
};
9+
use bc_xid::XIDDocument;
1510
use btp::{chunk, Dechunker};
11+
use gstp::{SealedRequest, SealedRequestBehavior, SealedResponse, SealedResponseBehavior};
12+
13+
use crate::{AbstractEnclave, SecureFrom, SecureTryFrom};
1614

1715
#[async_trait]
1816
pub trait AbstractBluetoothChannel {

abstracted/src/abstracted/abstract_enclave.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1+
use anyhow::Result;
2+
use bc_components::ARID;
3+
use bc_envelope::prelude::*;
14
use bc_xid::XIDDocument;
25
use gstp::{SealedRequest, SealedResponse};
3-
use {anyhow::Result, bc_components::ARID, bc_envelope::prelude::*};
46

57
pub trait AbstractEnclave {
68
// Public key operations
@@ -12,7 +14,8 @@ pub trait AbstractEnclave {
1214
fn sign(&self, envelope: &Envelope) -> Envelope;
1315
fn seal_response(&self, envelope: &SealedResponse, recipient: &XIDDocument) -> Envelope;
1416
fn decrypt(&self, envelope: &Envelope) -> Result<Envelope>;
15-
//fn unseal(&self, envelope: &Envelope, sender: &XIDDocument) -> Result<Envelope>;
17+
//fn unseal(&self, envelope: &Envelope, sender: &XIDDocument) ->
18+
// Result<Envelope>;
1619
fn self_decrypt(&self, envelope: &Envelope) -> Result<Envelope>;
1720

1821
// Request -> Envelope

api-demo/src/demo/bluetooth.rs

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
1-
use {
2-
anyhow::Result,
3-
async_trait::async_trait,
4-
foundation_abstracted::AbstractBluetoothChannel,
5-
std::sync::Arc,
6-
tokio::{
7-
sync::{
8-
mpsc::{self, Receiver, Sender},
9-
Mutex,
10-
},
11-
time::{self, Duration},
1+
use std::sync::Arc;
2+
3+
use anyhow::Result;
4+
use async_trait::async_trait;
5+
use foundation_abstracted::AbstractBluetoothChannel;
6+
use tokio::{
7+
sync::{
8+
mpsc::{self, Receiver, Sender},
9+
Mutex,
1210
},
11+
time::{self, Duration},
1312
};
1413

1514
#[derive(Debug)]

api-demo/src/demo/enclave.rs

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
11
#![allow(dead_code)]
22

3-
use bc_components::{EncapsulationScheme, SignatureScheme};
3+
use anyhow::Result;
4+
use bc_components::{EncapsulationScheme, PrivateKeys, PublicKeys, SignatureScheme, ARID};
5+
use bc_envelope::prelude::*;
46
use bc_xid::XIDDocument;
7+
use foundation_abstracted::AbstractEnclave;
58
use gstp::{SealedRequest, SealedResponse};
6-
use {
7-
anyhow::Result,
8-
bc_components::{PrivateKeys, PublicKeys, ARID},
9-
bc_envelope::prelude::*,
10-
foundation_abstracted::AbstractEnclave,
11-
};
129

1310
#[derive(Debug)]
1411
pub struct Enclave {
@@ -65,8 +62,8 @@ impl AbstractEnclave for Enclave {
6562
envelope.decrypt_to_recipient(&self.private_keys)
6663
}
6764

68-
// fn unseal(&self, envelope: &Envelope, sender: &XIDDocument) -> Result<Envelope> {
69-
// envelope.unseal(sender, &self.private_key)
65+
// fn unseal(&self, envelope: &Envelope, sender: &XIDDocument) ->
66+
// Result<Envelope> { envelope.unseal(sender, &self.private_key)
7067
// }
7168

7269
fn self_decrypt(&self, envelope: &Envelope) -> Result<Envelope> {
@@ -122,7 +119,9 @@ impl AbstractEnclave for Enclave {
122119

123120
#[cfg(test)]
124121
pub mod tests {
125-
use {super::*, indoc::indoc};
122+
use indoc::indoc;
123+
124+
use super::*;
126125

127126
#[test]
128127
fn test_sign() {
@@ -171,8 +170,8 @@ pub mod tests {
171170
// let enclave1 = Enclave::new();
172171
// let enclave2 = Enclave::new();
173172
// let envelope = Envelope::new("Hello, World!");
174-
// let signed_and_encrypted = enclave1.seal(&envelope, enclave2.xid_document());
175-
// assert_eq!(
173+
// let signed_and_encrypted = enclave1.seal(&envelope,
174+
// enclave2.xid_document()); assert_eq!(
176175
// signed_and_encrypted.format(),
177176
// (indoc! {
178177
// r#"

api-demo/src/demo/envoy.rs

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,22 @@
1+
use std::sync::Arc;
2+
3+
use anyhow::{anyhow, bail, Ok, Result};
4+
use bc_envelope::prelude::*;
15
use bc_xid::XIDDocument;
2-
use foundation_api::api::discovery::Discovery;
3-
use foundation_api::api::quantum_link::QUANTUM_LINK;
4-
use foundation_api::quantum_link::QuantumLink;
5-
6-
use foundation_api::api::message::QuantumLinkMessage;
7-
use foundation_api::fx::ExchangeRate;
8-
use foundation_api::message::{EnvoyMessage, PassportMessage};
9-
use foundation_api::pairing::PairingRequest;
6+
use foundation_abstracted::{AbstractBluetoothChannel, SecureTryFrom};
7+
use foundation_api::{
8+
api::{discovery::Discovery, message::QuantumLinkMessage, quantum_link::QUANTUM_LINK},
9+
fx::ExchangeRate,
10+
message::{EnvoyMessage, PassportMessage},
11+
pairing::PairingRequest,
12+
quantum_link::QuantumLink,
13+
};
1014
use gstp::{SealedResponse, SealedResponseBehavior};
11-
use {
12-
crate::{
13-
chapter_title, latency, paint_broadcast, paint_response, sleep, BluetoothChannel, Camera,
14-
Enclave,
15-
},
16-
anyhow::{anyhow, bail, Ok, Result},
17-
bc_envelope::prelude::*,
18-
foundation_abstracted::AbstractBluetoothChannel,
19-
foundation_abstracted::SecureTryFrom,
20-
std::sync::Arc,
21-
tokio::{sync::Mutex, task::JoinHandle, time::Duration},
15+
use tokio::{sync::Mutex, task::JoinHandle, time::Duration};
16+
17+
use crate::{
18+
chapter_title, latency, paint_broadcast, paint_response, sleep, BluetoothChannel, Camera,
19+
Enclave,
2220
};
2321

2422
pub const ENVOY_PREFIX: &str = "🔶 Envoy ";
@@ -119,7 +117,8 @@ impl Envoy {
119117
envelope: Envelope,
120118
_stop: Arc<Mutex<bool>>,
121119
) -> Result<()> {
122-
// TODO: Need code here to determine if it's a SealedResponse, SealedRequest or Event
120+
// TODO: Need code here to determine if it's a SealedResponse, SealedRequest or
121+
// Event
123122
let response = SealedResponse::secure_try_from(envelope, &self.enclave)?;
124123
log!("📡 Received: {}", paint_response!(response));
125124

api-demo/src/demo/passport.rs

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,26 @@
1+
use std::sync::Arc;
2+
3+
use anyhow::{bail, Result};
4+
use bc_envelope::prelude::*;
15
use bc_xid::XIDDocument;
2-
use foundation_api::api::message::QuantumLinkMessage;
3-
use foundation_api::api::passport::{PassportFirmwareVersion, PassportSerial};
4-
use foundation_api::api::quantum_link::QuantumLink;
5-
use foundation_api::api::quantum_link::QUANTUM_LINK;
6-
use foundation_api::message::EnvoyMessage;
7-
use foundation_api::pairing::PairingResponse;
8-
use foundation_api::passport::{PassportColor, PassportModel};
9-
use gstp::SealedRequest;
10-
use gstp::SealedRequestBehavior;
11-
use {
12-
super::{BluetoothChannel, Screen},
13-
crate::{chapter_title, latency, paint_broadcast, paint_request, Enclave},
14-
anyhow::{bail, Result},
15-
bc_envelope::prelude::*,
16-
foundation_abstracted::AbstractBluetoothChannel,
17-
foundation_abstracted::AbstractEnclave,
18-
foundation_abstracted::SecureTryFrom,
19-
foundation_api::api::discovery::Discovery,
20-
foundation_ur::Encoder,
21-
std::sync::Arc,
22-
tokio::{sync::Mutex, task::JoinHandle, time::Duration},
6+
use foundation_abstracted::{AbstractBluetoothChannel, AbstractEnclave, SecureTryFrom};
7+
use foundation_api::{
8+
api::{
9+
discovery::Discovery,
10+
message::QuantumLinkMessage,
11+
passport::{PassportFirmwareVersion, PassportSerial},
12+
quantum_link::{QuantumLink, QUANTUM_LINK},
13+
},
14+
message::EnvoyMessage,
15+
pairing::PairingResponse,
16+
passport::{PassportColor, PassportModel},
2317
};
18+
use foundation_ur::Encoder;
19+
use gstp::{SealedRequest, SealedRequestBehavior};
20+
use tokio::{sync::Mutex, task::JoinHandle, time::Duration};
21+
22+
use super::{BluetoothChannel, Screen};
23+
use crate::{chapter_title, latency, paint_broadcast, paint_request, Enclave};
2424

2525
pub const PASSPORT_PREFIX: &str = "🛂 Passport";
2626

api-demo/src/demo/screen.rs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
1-
use {
2-
anyhow::Result,
3-
bc_envelope::prelude::*,
4-
std::{
5-
sync::{Arc, Mutex},
6-
time::Duration,
7-
},
8-
tokio::sync::Notify,
1+
use std::{
2+
sync::{Arc, Mutex},
3+
time::Duration,
94
};
105

6+
use anyhow::Result;
7+
use bc_envelope::prelude::*;
8+
use tokio::sync::Notify;
9+
1110
#[derive(Debug)]
1211
pub struct ScreenPeers {
1312
screen: Arc<Screen>,

api/rustfmt.toml

Lines changed: 0 additions & 11 deletions
This file was deleted.

api/src/api/backup.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
use crate::api::quantum_link::QuantumLink;
21
use flutter_rust_bridge::frb;
3-
use {
4-
minicbor_derive::{Decode, Encode},
5-
quantum_link_macros::quantum_link,
6-
};
2+
use minicbor_derive::{Decode, Encode};
3+
use quantum_link_macros::quantum_link;
4+
5+
use crate::api::quantum_link::QuantumLink;
76

87
#[quantum_link]
98
pub struct Shard {

0 commit comments

Comments
 (0)