From 7e6e74374978ecf7fff00b5f5ad9a8463a9680f0 Mon Sep 17 00:00:00 2001 From: Brooklyn Zelenka Date: Mon, 5 Aug 2024 22:26:14 -0700 Subject: [PATCH] Bump cargo versions --- flake.lock | 96 ++++++------------------------------------ flake.nix | 15 ++----- src/delegation.rs | 103 +++++++++++++++++----------------------------- 3 files changed, 53 insertions(+), 161 deletions(-) diff --git a/flake.lock b/flake.lock index c13ba4a7..036ecc31 100644 --- a/flake.lock +++ b/flake.lock @@ -19,25 +19,6 @@ "type": "github" } }, - "devshell": { - "inputs": { - "flake-utils": "flake-utils_2", - "nixpkgs": "nixpkgs_2" - }, - "locked": { - "lastModified": 1711099426, - "narHash": "sha256-HzpgM/wc3aqpnHJJ2oDqPBkNsqWbW0WfWUO8lKu8nGk=", - "owner": "numtide", - "repo": "devshell", - "rev": "2d45b54ca4a183f2fdcf4b19c895b64fbf620ee8", - "type": "github" - }, - "original": { - "owner": "numtide", - "repo": "devshell", - "type": "github" - } - }, "flake-utils": { "inputs": { "systems": "systems" @@ -59,24 +40,6 @@ "inputs": { "systems": "systems_2" }, - "locked": { - "lastModified": 1701680307, - "narHash": "sha256-kAuep2h5ajznlPMD9rnQyffWG8EM/C73lejGofXvdM8=", - "owner": "numtide", - "repo": "flake-utils", - "rev": "4022d587cbbfd70fe950c1e2083a02621806a725", - "type": "github" - }, - "original": { - "owner": "numtide", - "repo": "flake-utils", - "type": "github" - } - }, - "flake-utils_3": { - "inputs": { - "systems": "systems_3" - }, "locked": { "lastModified": 1710146030, "narHash": "sha256-SZ5L6eA7HJ/nmkzGG7/ISclqe6oZdOZTNoesiInkXPQ=", @@ -93,11 +56,11 @@ }, "nixos-unstable": { "locked": { - "lastModified": 1711616573, - "narHash": "sha256-FvZiEl6D4iLXqSQ3oGjQ/qehhPZ5E7iTHr/YA1Rw8kY=", + "lastModified": 1722892243, + "narHash": "sha256-E0CKe8EJfdEA0Td/Z79AHpYuWg8H8U6RFUxaEaRVHdc=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "c99b66784962e8984444b4d9e72d00d3549afdb2", + "rev": "54a75f91a509dec6e474c9336830af230fce8d1a", "type": "github" }, "original": { @@ -123,60 +86,40 @@ }, "nixpkgs_2": { "locked": { - "lastModified": 1704161960, - "narHash": "sha256-QGua89Pmq+FBAro8NriTuoO/wNaUtugt29/qqA8zeeM=", - "owner": "NixOS", - "repo": "nixpkgs", - "rev": "63143ac2c9186be6d9da6035fa22620018c85932", - "type": "github" - }, - "original": { - "owner": "NixOS", - "ref": "nixpkgs-unstable", - "repo": "nixpkgs", - "type": "github" - } - }, - "nixpkgs_3": { - "locked": { - "lastModified": 1711460390, - "narHash": "sha256-akSgjDZL6pVHEfSE6sz1DNSXuYX6hq+P/1Z5IoYWs7E=", + "lastModified": 1722791413, + "narHash": "sha256-rCTrlCWvHzMCNcKxPE3Z/mMK2gDZ+BvvpEVyRM4tKmU=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "44733514b72e732bd49f5511bd0203dea9b9a434", + "rev": "8b5b6723aca5a51edf075936439d9cd3947b7b2c", "type": "github" }, "original": { "id": "nixpkgs", - "ref": "nixos-23.11", + "ref": "nixos-24.05", "type": "indirect" } }, "root": { "inputs": { "command-utils": "command-utils", - "devshell": "devshell", - "flake-utils": "flake-utils_3", + "flake-utils": "flake-utils_2", "nixos-unstable": "nixos-unstable", - "nixpkgs": "nixpkgs_3", + "nixpkgs": "nixpkgs_2", "rust-overlay": "rust-overlay" } }, "rust-overlay": { "inputs": { - "flake-utils": [ - "flake-utils" - ], "nixpkgs": [ "nixpkgs" ] }, "locked": { - "lastModified": 1711592024, - "narHash": "sha256-oD4OJ3TRmVrbAuKZWxElRCyCagNCDuhfw2exBmNOy48=", + "lastModified": 1722910815, + "narHash": "sha256-v6Vk/xlABhw2QzOa6xh3Jx/IvmlbKbOazFM+bDFQlWU=", "owner": "oxalica", "repo": "rust-overlay", - "rev": "aa858717377db2ed8ffd2d44147d907baee656e5", + "rev": "7df2ac544c203d21b63aac23bfaec7f9b919a733", "type": "github" }, "original": { @@ -214,21 +157,6 @@ "repo": "default", "type": "github" } - }, - "systems_3": { - "locked": { - "lastModified": 1681028828, - "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", - "owner": "nix-systems", - "repo": "default", - "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", - "type": "github" - }, - "original": { - "owner": "nix-systems", - "repo": "default", - "type": "github" - } } }, "root": "root", diff --git a/flake.nix b/flake.nix index 925581d7..74ae9831 100644 --- a/flake.nix +++ b/flake.nix @@ -2,13 +2,11 @@ description = "ucan"; inputs = { - nixpkgs.url = "nixpkgs/nixos-23.11"; + nixpkgs.url = "nixpkgs/nixos-24.05"; nixos-unstable.url = "nixpkgs/nixos-unstable-small"; command-utils.url = "github:expede/nix-command-utils"; - flake-utils.url = "github:numtide/flake-utils"; - devshell.url = "github:numtide/devshell"; rust-overlay = { url = "github:oxalica/rust-overlay"; @@ -19,7 +17,6 @@ outputs = { self, - devshell, flake-utils, nixos-unstable, nixpkgs, @@ -29,7 +26,6 @@ flake-utils.lib.eachDefaultSystem ( system: let overlays = [ - devshell.overlays.default (import rust-overlay) ]; @@ -102,7 +98,7 @@ "release:host" = cmd "Build release for ${system}" "${cargo} build --release"; - "release:wasm:web" = cmd "Build release for wasm32-unknown-unknown with web bindings" + "release:wasm:web" = cmd "Build release for wasm32-unknown-unknown with web bindings" "${wasm-pack} build --release --target=web"; "release:wasm:nodejs" = cmd "Build release for wasm32-unknown-unknown with Node.js bindgings" @@ -115,7 +111,7 @@ "build:wasm:web" = cmd "Build for wasm32-unknown-unknown with web bindings" "${wasm-pack} build --dev --target=web"; - + "build:wasm:nodejs" = cmd "Build for wasm32-unknown-unknown with Node.js bindgings" "${wasm-pack} build --dev --target=nodejs"; @@ -174,7 +170,7 @@ "test:host && test:docs && test:wasm"; "test:host" = cmd "Run Cargo tests for host target" - "${cargo} test --features=test_utils"; + "${cargo} test --features=mermaid_docs,test_utils"; "test:wasm" = cmd "Run wasm-pack tests on all targets" "test:wasm:node && test:wasm:chrome"; @@ -220,7 +216,6 @@ self.packages.${system}.irust (pkgs.hiPrio pkgs.rust-bin.nightly.latest.rustfmt) - pre-commit pkgs.wasm-pack chromedriver protobuf @@ -234,8 +229,6 @@ ++ lib.optionals stdenv.isDarwin darwin-installs; shellHook = '' - [ -e .git/hooks/pre-commit ] || pre-commit install --install-hooks && pre-commit install --hook-type commit-msg - export RUSTC_WRAPPER="${pkgs.sccache}/bin/sccache" unset SOURCE_DATE_EPOCH '' diff --git a/src/delegation.rs b/src/delegation.rs index 151de7fb..dae31f1d 100644 --- a/src/delegation.rs +++ b/src/delegation.rs @@ -96,7 +96,7 @@ impl + Clone, C: Codec> DelegationRequire where Ipld: Encode, { - pub fn to_builder(self) -> DelegationBuilder { + pub fn into_builder(self) -> DelegationBuilder { DelegationBuilder { subject: self.subject, issuer: self.issuer, @@ -115,50 +115,13 @@ where not_before: None, } } - - pub fn try_finalize(self) -> Result, crate::crypto::signature::SignError> - where - ::Err: std::fmt::Debug, - { - self.to_builder().try_finalize() - } - - pub fn with_via(self, via: DID) -> DelegationBuilder { - let builder = self.to_builder(); - builder.with_via(via) - } - - pub fn with_policy(self, policy: Vec) -> DelegationBuilder { - let builder = self.to_builder(); - builder.with_policy(policy) - } - - pub fn with_nonce(self, nonce: Nonce) -> DelegationBuilder { - let builder = self.to_builder(); - builder.with_nonce(nonce) - } - - pub fn with_metadata(self, metadata: BTreeMap) -> DelegationBuilder { - let builder = self.to_builder(); - builder.with_metadata(metadata) - } - - pub fn with_expiration(self, expiration: Timestamp) -> DelegationBuilder { - let builder = self.to_builder(); - builder.with_expiration(expiration) - } - - pub fn with_not_before(self, not_before: Timestamp) -> DelegationBuilder { - let builder = self.to_builder(); - builder.with_not_before(not_before) - } } impl + Clone, C: Codec> DelegationBuilder where Ipld: Encode, { - pub fn try_finalize(self) -> Result, crate::crypto::signature::SignError> + pub fn try_sign(self) -> Result, crate::crypto::signature::SignError> where ::Err: std::fmt::Debug, { @@ -181,35 +144,32 @@ where Delegation::try_sign(&self.signer, self.varsig_header, payload) } - pub fn with_via(mut self, via: DID) -> DelegationBuilder { + pub fn via(mut self, via: DID) -> DelegationBuilder { self.via = Some(via); self } - pub fn with_policy(mut self, policy: Vec) -> DelegationBuilder { + pub fn policy(mut self, policy: Vec) -> DelegationBuilder { self.policy = policy; self } - pub fn with_nonce(mut self, nonce: Nonce) -> DelegationBuilder { + pub fn nonce(mut self, nonce: Nonce) -> DelegationBuilder { self.nonce = Some(nonce); self } - pub fn with_metadata( - mut self, - metadata: BTreeMap, - ) -> DelegationBuilder { + pub fn metadata(mut self, metadata: BTreeMap) -> DelegationBuilder { self.metadata = metadata; self } - pub fn with_expiration(mut self, expiration: Timestamp) -> DelegationBuilder { + pub fn expiration(mut self, expiration: Timestamp) -> DelegationBuilder { self.expiration = Some(expiration); self } - pub fn with_not_before(mut self, not_before: Timestamp) -> DelegationBuilder { + pub fn not_before(mut self, not_before: Timestamp) -> DelegationBuilder { self.not_before = Some(not_before); self } @@ -387,8 +347,8 @@ mod tests { fn fixture() -> DelegationRequired { let (alice, alice_signer) = gen_did(); - let (bob, bob_signer) = gen_did(); - let (carol, carol_signer) = gen_did(); + let (bob, _bob_signer) = gen_did(); + let (carol, _carol_signer) = gen_did(); DelegationRequired { subject: Subject::Any, @@ -405,50 +365,60 @@ mod tests { } #[test_log::test] - fn test_finalize() -> TestResult { - let delegation = fixture().try_finalize(); + fn test_sign() -> TestResult { + let delegation = fixture().into_builder().try_sign(); assert_matches!(delegation, Ok(_)); Ok(()) } #[test_log::test] - fn test_finalize_with_metadata() -> TestResult { + fn test_sign_with_metadata() -> TestResult { let meta = BTreeMap::from_iter([("foo".into(), 123.into())]); - let delegation = fixture().with_metadata(meta.clone()).try_finalize()?; + let delegation = fixture().into_builder().metadata(meta.clone()).try_sign()?; + assert_eq!(delegation.metadata(), &meta); Ok(()) } #[test_log::test] - fn test_finalize_with_via() -> TestResult { + fn test_sign_with_via() -> TestResult { let (alice, _) = gen_did(); - let delegation = fixture().with_via(alice.clone()).try_finalize()?; + let delegation = fixture().into_builder().via(alice.clone()).try_sign()?; assert_eq!(delegation.via(), Some(alice).as_ref()); Ok(()) } #[test_log::test] - fn test_finalize_with_policy() -> TestResult { + fn test_sign_with_policy() -> TestResult { let pred = Predicate::Equal(FromStr::from_str(".foo")?, 123.into()); - let delegation = fixture().with_policy(vec![pred.clone()]).try_finalize()?; + let delegation = fixture() + .into_builder() + .policy(vec![pred.clone()]) + .try_sign()?; assert_eq!(delegation.policy(), &vec![pred]); Ok(()) } #[test_log::test] - fn test_finalize_with_expiration() -> TestResult { + fn test_sign_with_expiration() -> TestResult { let exp = Timestamp::now(); - let delegation = fixture().with_expiration(exp.clone()).try_finalize()?; + let delegation = fixture() + .into_builder() + .expiration(exp.clone()) + .try_sign()?; assert_eq!(delegation.expiration(), Some(&exp)); Ok(()) } #[test_log::test] - fn test_finalize_with_not_before() -> TestResult { + fn test_sign_with_not_before() -> TestResult { let nbf = Timestamp::now(); - let delegation = fixture().with_not_before(nbf.clone()).try_finalize()?; + let delegation = fixture() + .into_builder() + .not_before(nbf.clone()) + .try_sign()?; assert_eq!(delegation.not_before(), Some(&nbf)); Ok(()) @@ -475,10 +445,11 @@ mod tests { codec: encoding::Preset::DagCbor, }), } - .with_via(carol) - .with_policy(vec![]) - .with_metadata(BTreeMap::from_iter([("foo".into(), 123.into())])) - .try_finalize() + .into_builder() + .via(carol) + .policy(vec![]) + .metadata(BTreeMap::from_iter([("foo".into(), 123.into())])) + .try_sign() } #[test_log::test]