Skip to content

Commit

Permalink
rfc3339, json, Web5Error, and VerifiableCredential (#283)
Browse files Browse the repository at this point in the history
  • Loading branch information
KendallWeihe authored Aug 16, 2024
1 parent 24966d2 commit ea1c48e
Show file tree
Hide file tree
Showing 29 changed files with 1,665 additions and 792 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ jobs:
- name: Run Rust Tests
run: |
mkdir -p test-results
cargo nextest run --profile ci --config-file ./nextest.toml
cargo nextest run --profile ci --config-file ./nextest.toml -E 'test(test_vectors::)'
- name: Modify testsuite name in XML for test runner consumption
run: |
sed -i '' 's/<testsuite name="web5"/<testsuite name="Web5TestVectorsProtocolTest"/' target/nextest/ci/junit.xml
Expand All @@ -252,4 +252,4 @@ jobs:
uses: actions/upload-artifact@v3
with:
name: rust-test-results
path: test-results/rust-test-results.xml
path: test-results/rust-test-results.xml
6 changes: 4 additions & 2 deletions Justfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ set shell := ["bash", "-uc"]
setup:
#!/bin/bash
source bin/activate-hermit
git submodule update --init --recursive
if [ ! -d ".git/modules/web5-spec" ]; then
git submodule update --init --recursive
fi
if [[ "$(cargo 2>&1)" == *"rustup could not choose a version of cargo to run"* ]]; then
rustup default 1.78.0
rustup default 1.80.0
rustup target add aarch64-apple-darwin
fi

Expand Down
7 changes: 3 additions & 4 deletions bindings/web5_uniffi/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
use web5_uniffi_wrapper::{
credentials::{
presentation_definition::PresentationDefinition,
verifiable_credential_1_1::{
data::VerifiableCredential as VerifiableCredentialData, VerifiableCredential,
},
verifiable_credential_1_1::{VerifiableCredential, VerifiableCredentialData},
},
crypto::{
dsa::{
Expand All @@ -25,10 +23,11 @@ use web5_uniffi_wrapper::{
portable_did::PortableDid,
resolution::resolution_result::ResolutionResult,
},
errors::RustCoreError,
errors::Web5Error,
};

use web5::{
credentials::verifiable_credential_1_1::VerifiableCredentialCreateOptions as VerifiableCredentialCreateOptionsData,
crypto::{dsa::Dsa, jwk::Jwk as JwkData},
dids::{
data_model::{
Expand Down
105 changes: 56 additions & 49 deletions bindings/web5_uniffi/src/web5.udl
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ namespace web5 {
JwkData ed25519_generator_generate();

ResolutionResult did_jwk_resolve([ByRef] string uri);
[Async, Throws=RustCoreError]
[Async, Throws=Web5Error]
ResolutionResult did_web_resolve([ByRef] string uri);
[Throws=RustCoreError]
[Throws=Web5Error]
ResolutionResult did_dht_resolve([ByRef] string uri);
};

[Error]
interface RustCoreError {
interface Web5Error {
Error(string type, string variant, string msg);
};

Expand All @@ -24,15 +24,15 @@ dictionary JwkData {

[Trait, WithForeign]
interface KeyManager {
[Throws=RustCoreError]
[Throws=Web5Error]
Signer get_signer(JwkData public_jwk);
};

interface InMemoryKeyManager {
constructor();
[Throws=RustCoreError]
[Throws=Web5Error]
Signer get_signer(JwkData public_jwk);
[Throws=RustCoreError]
[Throws=Web5Error]
JwkData import_private_jwk(JwkData private_key);
KeyManager get_as_key_manager();
};
Expand All @@ -43,25 +43,25 @@ enum Dsa {

[Trait, WithForeign]
interface Signer {
[Throws=RustCoreError]
[Throws=Web5Error]
bytes sign(bytes payload);
};

[Trait, WithForeign]
interface Verifier {
[Throws=RustCoreError]
[Throws=Web5Error]
boolean verify(bytes message, bytes signature);
};

interface Ed25519Signer {
constructor(JwkData private_key);
[Throws=RustCoreError]
[Throws=Web5Error]
bytes sign(bytes payload);
};

interface Ed25519Verifier {
constructor(JwkData public_jwk);
[Throws=RustCoreError]
[Throws=Web5Error]
boolean verify(bytes message, bytes signature);
};

Expand All @@ -77,7 +77,7 @@ dictionary DidData {
};

interface Did {
[Throws=RustCoreError]
[Throws=Web5Error]
constructor([ByRef] string uri);
DidData get_data();
};
Expand Down Expand Up @@ -112,7 +112,7 @@ dictionary ServiceData {
interface Document {
constructor(DocumentData data);
DocumentData get_data();
[Throws=RustCoreError]
[Throws=Web5Error]
JwkData find_public_key_jwk(string key_id);
};

Expand Down Expand Up @@ -159,9 +159,9 @@ dictionary DidJwkData {
};

interface DidJwk {
[Name=from_public_jwk, Throws=RustCoreError]
[Name=from_public_jwk, Throws=Web5Error]
constructor(JwkData public_jwk);
[Name=from_uri, Throws=RustCoreError]
[Name=from_uri, Throws=Web5Error]
constructor([ByRef] string uri);
DidJwkData get_data();
};
Expand All @@ -172,9 +172,9 @@ dictionary DidWebData {
};

interface DidWeb {
[Name=from_public_jwk, Throws=RustCoreError]
[Name=from_public_jwk, Throws=Web5Error]
constructor([ByRef] string domain, JwkData public_jwk);
[Async, Name=from_uri, Throws=RustCoreError]
[Async, Name=from_uri, Throws=Web5Error]
constructor([ByRef] string uri);
DidWebData get_data();
};
Expand All @@ -185,13 +185,13 @@ dictionary DidDhtData {
};

interface DidDht {
[Name=from_identity_key, Throws=RustCoreError]
[Name=from_identity_key, Throws=Web5Error]
constructor(JwkData identity_key);
[Name=from_uri, Throws=RustCoreError]
[Name=from_uri, Throws=Web5Error]
constructor([ByRef] string uri);
[Throws=RustCoreError]
[Throws=Web5Error]
void publish(Signer signer);
[Throws=RustCoreError]
[Throws=Web5Error]
void deactivate(Signer signer);
DidDhtData get_data();
};
Expand All @@ -203,7 +203,7 @@ dictionary PortableDidData {
};

interface PortableDid {
[Throws=RustCoreError]
[Throws=Web5Error]
constructor([ByRef] string json);
PortableDidData get_data();
};
Expand All @@ -215,45 +215,52 @@ dictionary BearerDidData {
};

interface BearerDid {
[Throws=RustCoreError]
[Throws=Web5Error]
constructor([ByRef] string uri, KeyManager key_manager);
[Throws=RustCoreError, Name=from_portable_did]
[Throws=Web5Error, Name=from_portable_did]
constructor(PortableDid portable_did);
BearerDidData get_data();
[Throws=RustCoreError]
[Throws=Web5Error]
Signer get_signer(string key_id);
};

dictionary VerifiableCredentialData {
sequence<string> context;
string id;
sequence<string> type;
string json_serialized_issuer;
timestamp issuance_date;
interface PresentationDefinition {
[Throws=Web5Error]
constructor(string json_serialized_presentation_definition);
[Throws=Web5Error]
string get_json_serialized_presentation_definition();
[Throws=Web5Error]
sequence<string> select_credentials([ByRef] sequence<string> vc_jwts);
};





dictionary VerifiableCredentialCreateOptionsData {
string? id;
sequence<string>? context;
sequence<string>? type;
timestamp? issuance_date;
timestamp? expiration_date;
string json_serialized_credential_subject;
};

interface VerifiableCredential {
[Throws=RustCoreError]
constructor(VerifiableCredentialData data);
[Name=verify, Throws=RustCoreError]
constructor([ByRef] string vcjwt);
[Name=verify_with_verifier, Throws=RustCoreError]
constructor([ByRef] string vcjwt, Verifier verifier);
[Throws=RustCoreError]
string sign(BearerDid bearer_did);
[Throws=RustCoreError]
string sign_with_signer([ByRef] string key_id, Signer signer);
[Throws=RustCoreError]
[Throws=Web5Error, Name=create]
constructor(
string json_serialized_issuer,
string json_serialized_credential_subject,
VerifiableCredentialCreateOptionsData? options
);
VerifiableCredentialData get_data();
};

interface PresentationDefinition {
[Throws=RustCoreError]
constructor(string json_serialized_presentation_definition);
[Throws=RustCoreError]
string get_json_serialized_presentation_definition();
[Throws=RustCoreError]
sequence<string> select_credentials([ByRef] sequence<string> vc_jwts);
dictionary VerifiableCredentialData {
sequence<string> context;
sequence<string> type;
string id;
string json_serialized_issuer;
string json_serialized_credential_subject;
timestamp issuance_date;
timestamp? expiration_date;
};
Loading

0 comments on commit ea1c48e

Please sign in to comment.