Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Blank UDL for the sake of agility #180 #181

Merged
merged 1 commit into from
May 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 2 additions & 24 deletions bindings/uniffi/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,27 +1,5 @@
use ::credentials::vc::{verify_vcjwt, CredentialError, CredentialSubject, VerifiableCredential};
use ::crypto::Curve;
use ::dids::{
bearer::{BearerDid, BearerDidError},
document::{KeySelector, VerificationMethodType},
};
use ::jwk::{Jwk, JwkError};
use ::jwt::{sign_jwt, verify_jwt, Claims, JwtError};
use ::keys::{
key::{Key, KeyError, PrivateKey, PublicKey},
key_manager::{
key_store::{in_memory_key_store::InMemoryKeyStore, KeyStore, KeyStoreError},
local_key_manager::LocalKeyManager,
KeyManager, KeyManagerError,
},
};
use std::sync::Arc;

pub async fn bearer_did_from_key_manager(
did_uri: &str,
key_manager: Arc<dyn KeyManager>,
) -> Result<Arc<BearerDid>, BearerDidError> {
let bearer_did = BearerDid::from_key_manager(did_uri, key_manager).await?;
Ok(Arc::new(bearer_did))
pub fn hello_world() {
println!("Hello web5 :)")
}

uniffi::include_scaffolding!("web5");
214 changes: 1 addition & 213 deletions bindings/uniffi/src/web5.udl
Original file line number Diff line number Diff line change
@@ -1,215 +1,3 @@
namespace web5 {
[Throws=BearerDidError, Async]
BearerDid bearer_did_from_key_manager([ByRef] string did_uri, KeyManager key_manager);

[Throws=JwtError]
string sign_jwt([ByRef] BearerDid bearer_did, [ByRef] KeySelector key_selector, [ByRef] string encoded_header, [ByRef] string encoded_payload);
[Throws=JwtError, Async]
void verify_jwt([ByRef] string jwt);

[Throws=CredentialError, Async]
VerifiableCredential verify_vcjwt([ByRef] string jwt);
void hello_world();
};

[Error]
enum KeyError {
"KeyGenerationFailed",
"SerializationFailed",
"CurveNotFound",
"AlgorithmNotFound",
"JwkError",
"CryptoError",
};

[Trait]
interface Key {
[Throws=KeyError]
string alias();
[Throws=KeyError]
Jwk jwk();
};

[Trait]
interface PublicKey {
[Throws=KeyError]
void verify([ByRef] sequence<u8> payload, [ByRef] sequence<u8> signature);
};

[Trait]
interface PrivateKey {
[Throws=KeyError]
PublicKey to_public();
[Throws=KeyError]
bytes sign([ByRef] sequence<u8> payload);
};

[Error]
enum JwkError {
"ThumbprintFailed",
};

interface Jwk {
[Throws=JwkError]
string compute_thumbprint();

[Throws=KeyError]
string alias();
[Throws=KeyError]
Jwk jwk();

[Throws=KeyError]
void verify([ByRef] sequence<u8> payload, [ByRef] sequence<u8> signature);

[Throws=KeyError]
PublicKey to_public();
[Throws=KeyError]
bytes sign([ByRef] sequence<u8> payload);
};

enum Curve {
"Secp256k1",
"Ed25519",
};

[Error]
enum KeyManagerError {
"KeyGenerationFailed",
"SigningKeyNotFound",
"KeyError",
"KeyStoreError",
};

[Trait]
interface KeyManager {
[Throws=KeyManagerError]
string generate_private_key(Curve curve, string? key_alias);
[Throws=KeyManagerError]
PublicKey get_public_key([ByRef] string key_alias);
[Throws=KeyManagerError]
bytes sign([ByRef] string key_alias, [ByRef] sequence<u8> payload);
[Throws=KeyManagerError]
sequence<PrivateKey> export_private_keys();
[Throws=KeyManagerError]
void import_private_keys(sequence<PrivateKey> private_keys);
};

interface LocalKeyManager {
constructor(KeyStore key_store);
[Name=new_in_memory]
constructor();

[Throws=KeyManagerError]
string generate_private_key(Curve curve, string? key_alias);
[Throws=KeyManagerError]
PublicKey get_public_key([ByRef] string key_alias);
[Throws=KeyManagerError]
bytes sign([ByRef] string key_alias, [ByRef] sequence<u8> payload);
[Throws=KeyManagerError]
sequence<PrivateKey> export_private_keys();
[Throws=KeyManagerError]
void import_private_keys(sequence<PrivateKey> private_keys);
};

[Error]
enum KeyStoreError {
"InternalKeyStoreError",
"KeyError",
"KeyNotFound",
"CryptoError",
"JwkError",
"UnsupportedOperation",
};

[Trait]
interface KeyStore {
[Throws=KeyStoreError]
string generate_new(Curve curve, string? key_alias);
[Throws=KeyStoreError]
sequence<string> get_all_aliases();
[Throws=KeyStoreError]
bytes sign([ByRef] string key_alias, [ByRef] sequence<u8> payload);
[Throws=KeyStoreError]
PublicKey get_public_key([ByRef] string key_alias);
[Throws=KeyStoreError]
sequence<PrivateKey> export_private_keys();
[Throws=KeyStoreError]
void import_private_keys(sequence<PrivateKey> private_keys);
};

interface InMemoryKeyStore {
constructor();

[Throws=KeyStoreError]
string generate_new(Curve curve, string? key_alias);
[Throws=KeyStoreError]
sequence<string> get_all_aliases();
[Throws=KeyStoreError]
bytes sign([ByRef] string key_alias, [ByRef] sequence<u8> payload);
[Throws=KeyStoreError]
PublicKey get_public_key([ByRef] string key_alias);
[Throws=KeyStoreError]
sequence<PrivateKey> export_private_keys();
[Throws=KeyStoreError]
void import_private_keys(sequence<PrivateKey> private_keys);
};

[Error]
enum BearerDidError {
"VerificationMethodNotFound",
"KeyManagerError",
"KeyError",
"DocumentError",
"ResolutionError",
"IdentifierError",
};

enum VerificationMethodType {
"VerificationMethod",
"AssertionMethod",
"Authentication",
"CapabilityDelegation",
"CapabilityInvocation",
};

[Enum]
interface KeySelector {
KeyId(string key_id);
MethodType(VerificationMethodType verification_method_type);
};

interface BearerDid {
[Throws=BearerDidError]
bytes sign([ByRef] KeySelector key_selector, [ByRef] sequence<u8> payload);
};

[Error]
enum JwtError {
"JwsError",
"SerializationError",
"DeserializationError",
};

interface Claims {
constructor(string? issuer, string? subject, string? audience, i64? expiration, i64? not_before, i64? issued_at, string? jti);
[Throws=JwtError]
string encode();
[Throws=JwtError]
string sign([ByRef] BearerDid bearer_did, [ByRef] KeySelector key_selector);
};

dictionary CredentialSubject {
string id;
record<string, string>? params;
};

[Error]
enum CredentialError {
"JwtError",
"JwsError",
};

interface VerifiableCredential {
constructor(sequence<string> context, string id, sequence<string> type, string issuer, i64 issuance_date, i64? expiration_date, CredentialSubject credential_subject);
[Throws=CredentialError]
string sign([ByRef] BearerDid bearer_did, [ByRef] KeySelector key_selector);
};
Loading