Skip to content

Commit

Permalink
Add Delegation Super Builder (#20)
Browse files Browse the repository at this point in the history
  • Loading branch information
expede committed Aug 6, 2024
1 parent a8d1b1d commit 076ea4c
Show file tree
Hide file tree
Showing 10 changed files with 585 additions and 285 deletions.
96 changes: 12 additions & 84 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 4 additions & 11 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -19,7 +17,6 @@

outputs = {
self,
devshell,
flake-utils,
nixos-unstable,
nixpkgs,
Expand All @@ -29,7 +26,6 @@
flake-utils.lib.eachDefaultSystem (
system: let
overlays = [
devshell.overlays.default
(import rust-overlay)
];

Expand Down Expand Up @@ -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"
Expand All @@ -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";

Expand Down Expand Up @@ -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";
Expand Down Expand Up @@ -220,7 +216,6 @@
self.packages.${system}.irust
(pkgs.hiPrio pkgs.rust-bin.nightly.latest.rustfmt)

pre-commit
pkgs.wasm-pack
chromedriver
protobuf
Expand All @@ -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
''
Expand Down
25 changes: 1 addition & 24 deletions src/crypto/signature/envelope.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,29 +89,6 @@ pub trait Envelope: Sized {
Ok(w)
}

/// Attempt to sign some payload with a given signer.
///
/// # Arguments
///
/// * `signer` - The signer to use to sign the payload.
/// * `payload` - The payload to sign.
///
/// # Errors
///
/// * [`SignError`] - the payload can't be encoded or the signature fails.
// FIXME ported
fn try_sign(
signer: &<Self::DID as Did>::Signer,
varsig_header: Self::VarsigHeader,
payload: Self::Payload,
) -> Result<Self, SignError>
where
Ipld: Encode<Self::Encoder>,
Named<Ipld>: From<Self::Payload>,
{
Self::try_sign_generic(signer, varsig_header, payload)
}

/// Attempt to sign some payload with a given signer and specific codec.
///
/// # Arguments
Expand All @@ -126,7 +103,7 @@ pub trait Envelope: Sized {
///
/// # Example
///
fn try_sign_generic(
fn try_sign(
signer: &<Self::DID as Did>::Signer,
varsig_header: Self::VarsigHeader,
payload: Self::Payload,
Expand Down
8 changes: 4 additions & 4 deletions src/crypto/varsig/header/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,21 @@ use libipld_core::codec::{Codec, Encode};
use signature::Verifier;
use thiserror::Error;

pub trait Header<Enc: Codec>: for<'a> TryFrom<&'a [u8]> + Into<Vec<u8>> {
pub trait Header<C: Codec>: for<'a> TryFrom<&'a [u8]> + Into<Vec<u8>> {
type Signature: signature::SignatureEncoding;
type Verifier: signature::Verifier<Self::Signature>;

fn codec(&self) -> &Enc;
fn codec(&self) -> &C;

fn encode_payload<T: Encode<Enc>, Buf: std::io::Write>(
fn encode_payload<T: Encode<C>, Buf: std::io::Write>(
&self,
payload: T,
buffer: &mut Buf,
) -> Result<(), libipld_core::error::Error> {
payload.encode(Self::codec(self).clone(), buffer)
}

fn try_verify<'a, T: Encode<Enc>>(
fn try_verify<'a, T: Encode<C>>(
&self,
verifier: &'a Self::Verifier,
signature: &'a Self::Signature,
Expand Down
Loading

0 comments on commit 076ea4c

Please sign in to comment.