Skip to content

Commit 71b4bfb

Browse files
chunninghamCharles Cunningham
andauthored
update ssi imports and types to post-restructure (spruceid#312)
* update ssi imports and types to post-restructure * fix wasm module, add zcap err to error type * add eip and tezos features to wasm * use main ssi branch in GitHub action Co-authored-by: Charles Cunningham <charlescunningham@Charless-MacBook-Pro.local>
1 parent fcb8882 commit 71b4bfb

8 files changed

Lines changed: 77 additions & 88 deletions

File tree

‎.github/workflows/build.yml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ on:
1111

1212
env:
1313
CARGO_TERM_COLOR: always
14-
SSI_REF: e865520085dc1b88f0a26fa94380b7590cbf6725
14+
SSI_REF: main
1515

1616
defaults:
1717
run:

‎cli/src/main.rs‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@ use didkit::generate_proof;
1616
use didkit::{
1717
dereference, get_verification_method, runtime, DIDCreate, DIDDeactivate, DIDDocumentOperation,
1818
DIDMethod, DIDRecover, DIDResolver, DIDUpdate, DereferencingInputMetadata, Error,
19-
LinkedDataProofOptions, Metadata, ProofFormat, ProofPurpose, ResolutionInputMetadata,
20-
ResolutionResult, Source, VerifiableCredential, VerifiablePresentation, DIDURL, DID_METHODS,
21-
JWK, URI,
19+
LinkedDataProofOptions, Metadata, ProofFormat, ResolutionInputMetadata, ResolutionResult,
20+
Source, VerifiableCredential, VerifiablePresentation, VerificationRelationship, DIDURL,
21+
DID_METHODS, JWK, URI,
2222
};
2323
use didkit_cli::opts::ResolverOptions;
24-
use ssi::did::{DIDMethodTransaction, Service, ServiceEndpoint, VerificationRelationship};
24+
use ssi::did::{DIDMethodTransaction, Service, ServiceEndpoint};
2525
use ssi::one_or_many::OneOrMany;
2626

2727
#[derive(StructOpt, Debug)]
@@ -415,7 +415,7 @@ pub struct ProofOptions {
415415
#[clap(env, short, long)]
416416
pub verification_method: Option<URI>,
417417
#[clap(env, short, long)]
418-
pub proof_purpose: Option<ProofPurpose>,
418+
pub proof_purpose: Option<VerificationRelationship>,
419419
#[clap(env, short, long)]
420420
pub created: Option<DateTime<Utc>>,
421421
#[clap(env, short = 'C', long)]

‎lib/Cargo.toml‎

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,24 @@ include = [
1919
]
2020

2121
[features]
22-
default = ["ring", "secp256k1", "p256"]
23-
ring = ["ssi/ring"]
24-
no-ring = ["ssi/ed25519-dalek", "ssi/sha2", "ssi/rsa", "ssi/rand"]
25-
wasm = []
22+
default = ["w3c", "eip"]
23+
24+
w3c = ["ssi/w3c", "secp256k1", "secp256r1", "ed25519", "rsa"]
25+
secp256k1 = ["ssi/secp256k1", "did-tz/secp256k1", "did-method-key/secp256k1", "did-ion/secp256k1"]
26+
secp256r1 = ["ssi/secp256r1", "did-tz/secp256r1", "did-webkey/secp256r1", "did-method-key/secp256r1", "did-ion/secp256r1"]
27+
ed25519 = ["ssi/ed25519", "did-tz/ed25519", "did-ion/ed25519"]
28+
rsa = ["ssi/rsa", "did-ion/rsa"]
29+
30+
aleo = ["ssi/aleo"]
31+
eip = ["ssi/eip"]
32+
tezos = ["ssi/tezos"]
33+
solana = ["ssi/solana"]
34+
2635
http-did = ["ssi/http-did"]
27-
secp256k1 = ["ssi/libsecp256k1", "did-tz/secp256k1", "did-method-key/secp256k1"]
28-
p256 = ["ssi/secp256r1", "did-tz/p256", "did-webkey/p256", "did-method-key/secp256r1"]
36+
37+
wasm = []
38+
ring = ["ssi/ring"]
39+
openssl = ["ssi/openssl"]
2940

3041
[dependencies]
3142
ssi = { version = "0.4", path = "../../ssi", default-features = false }

‎lib/src/error.rs‎

Lines changed: 29 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,42 @@
1-
use std::cell::BorrowError;
21
use std::ffi::CString;
3-
use std::ffi::NulError;
42
use std::fmt;
53
use std::os::raw::{c_char, c_int};
64
use std::ptr;
75

8-
use serde_json::Error as JSONError;
9-
use ssi::error::Error as SSIError;
10-
use std::error::Error as StdError;
11-
use std::io::Error as IOError;
12-
use std::str::Utf8Error;
13-
146
static UNKNOWN_ERROR: &str = "Unable to create error string\0";
157

168
use std::cell::RefCell;
179
thread_local! {
1810
pub static LAST_ERROR: RefCell<Option<(i32, CString)>> = RefCell::new(None);
1911
}
2012

21-
#[derive(Debug)]
13+
#[derive(thiserror::Error, Debug)]
2214
pub enum Error {
23-
SSI(ssi::error::Error),
24-
Null(NulError),
25-
Utf8(Utf8Error),
26-
Borrow(BorrowError),
27-
IO(IOError),
15+
#[error(transparent)]
16+
VC(#[from] ssi::vc::Error),
17+
#[error(transparent)]
18+
Zcap(#[from] ssi::zcap::Error),
19+
#[error(transparent)]
20+
JWK(#[from] ssi::jwk::Error),
21+
#[error(transparent)]
22+
Null(#[from] std::ffi::NulError),
23+
#[error(transparent)]
24+
Utf8(#[from] std::str::Utf8Error),
25+
#[error(transparent)]
26+
Borrow(#[from] std::cell::BorrowError),
27+
#[error(transparent)]
28+
IO(#[from] std::io::Error),
29+
#[error("Unable to generate DID")]
2830
UnableToGenerateDID,
31+
#[error("Unknown DID method")]
2932
UnknownDIDMethod,
33+
#[error("Unable to get verification method")]
3034
UnableToGetVerificationMethod,
35+
#[error("Unknown proof format: {0}")]
3136
UnknownProofFormat(String),
3237

3338
#[doc(hidden)]
39+
#[error("")]
3440
__Nonexhaustive,
3541
}
3642

@@ -47,16 +53,16 @@ impl Error {
4753
fn get_code(&self) -> c_int {
4854
// TODO: try to give each individual error its own number
4955
match self {
50-
Error::SSI(_) => 1,
56+
Error::VC(_) => 1,
5157
Error::Null(_) => 2,
5258
Error::Utf8(_) => 3,
59+
Error::JWK(_) => 4,
60+
Error::Zcap(_) => 5,
5361
_ => -1,
5462
}
5563
}
5664
}
5765

58-
impl StdError for Error {}
59-
6066
#[no_mangle]
6167
/// Retrieve a human-readable description of the most recent error encountered by a DIDKit C
6268
/// function. The returned string is valid until the next call to a DIDKit function in the current
@@ -84,54 +90,15 @@ pub extern "C" fn didkit_error_code() -> c_int {
8490
})
8591
}
8692

87-
impl fmt::Display for Error {
88-
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
89-
match self {
90-
Error::SSI(e) => e.fmt(f),
91-
Error::Null(e) => e.fmt(f),
92-
Error::Utf8(e) => e.fmt(f),
93-
Error::UnableToGenerateDID => write!(f, "Unable to generate DID"),
94-
Error::UnknownDIDMethod => write!(f, "Unknown DID method"),
95-
Error::UnableToGetVerificationMethod => write!(f, "Unable to get verification method"),
96-
Error::UnknownProofFormat(format) => write!(f, "Unknown proof format: {}", format),
97-
_ => unreachable!(),
98-
}
99-
}
100-
}
101-
102-
impl From<SSIError> for Error {
103-
fn from(err: SSIError) -> Error {
104-
Error::SSI(err)
105-
}
106-
}
107-
108-
impl From<JSONError> for Error {
109-
fn from(err: JSONError) -> Error {
110-
Error::SSI(SSIError::from(err))
111-
}
112-
}
113-
114-
impl From<NulError> for Error {
115-
fn from(err: NulError) -> Error {
116-
Error::Null(err)
117-
}
118-
}
119-
120-
impl From<Utf8Error> for Error {
121-
fn from(err: Utf8Error) -> Error {
122-
Error::Utf8(err)
123-
}
124-
}
125-
126-
impl From<IOError> for Error {
127-
fn from(err: IOError) -> Error {
128-
Error::IO(err)
93+
impl From<serde_json::Error> for Error {
94+
fn from(err: serde_json::Error) -> Error {
95+
Error::VC(ssi::vc::Error::from(err))
12996
}
13097
}
13198

132-
impl From<BorrowError> for Error {
133-
fn from(err: BorrowError) -> Error {
134-
Error::Borrow(err)
99+
impl From<ssi::ldp::Error> for Error {
100+
fn from(e: ssi::ldp::Error) -> Error {
101+
ssi::vc::Error::from(e).into()
135102
}
136103
}
137104

‎lib/src/lib.rs‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,15 @@ pub use ssi::did_resolve::{
2727
};
2828
pub use ssi::jsonld::ContextLoader;
2929
pub use ssi::jwk::JWK;
30-
pub use ssi::ldp::resolve_key;
30+
pub use ssi::did_resolve::resolve_key;
3131
pub use ssi::ldp::ProofPreparation;
3232
pub use ssi::tzkey::jwk_from_tezos_key;
3333
pub use ssi::vc::get_verification_method;
3434
pub use ssi::vc::Credential as VerifiableCredential;
3535
pub use ssi::vc::CredentialOrJWT;
3636
pub use ssi::vc::LinkedDataProofOptions;
3737
pub use ssi::vc::Presentation as VerifiablePresentation;
38-
pub use ssi::vc::ProofPurpose;
38+
pub use ssi::did::VerificationRelationship;
3939
pub use ssi::vc::VerificationResult;
4040
pub use ssi::vc::URI;
4141
pub use ssi::zcap::{Delegation, Invocation};
@@ -60,7 +60,7 @@ impl JWTOrLDPOptions {
6060
pub fn default_for_vp() -> Self {
6161
Self {
6262
ldp_options: LinkedDataProofOptions {
63-
proof_purpose: Some(ProofPurpose::Authentication),
63+
proof_purpose: Some(VerificationRelationship::Authentication),
6464
..Default::default()
6565
},
6666
proof_format: None,
@@ -112,8 +112,8 @@ pub enum GenerateProofError {
112112
#[cfg(not(any(feature = "wasm", target_os = "windows")))]
113113
#[error("Unable to sign: {0}")]
114114
Sign(#[from] crate::ssh_agent::SignError),
115-
#[error("SSI: {0}")]
116-
SSI(#[from] ssi::error::Error),
115+
#[error("SSI Linked Data Proof: {0}")]
116+
LDP(#[from] ssi::ldp::Error),
117117
#[error("IO: {0}")]
118118
IO(#[from] std::io::Error),
119119
#[error("WASM support for ssh-agent is not enabled")]
@@ -129,7 +129,7 @@ pub async fn generate_proof(
129129
resolver: &dyn DIDResolver,
130130
context_loader: &mut ContextLoader,
131131
ssh_agent_sock_path_opt: Option<&str>,
132-
) -> Result<ssi::vc::Proof, GenerateProofError> {
132+
) -> Result<ssi::ldp::Proof, GenerateProofError> {
133133
use ssi::ldp::LinkedDataProofs;
134134
let proof = match ssh_agent_sock_path_opt {
135135
#[cfg(feature = "wasm")]

‎lib/src/ssh_agent.rs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ pub enum SignError {
6262
#[error("Unable to calculate JWK thumbprint: {0}")]
6363
JWKThumbprint(String),
6464
#[error("Unable to prepare proof: {0}")]
65-
Prep(#[from] ssi::error::Error),
65+
Prep(#[from] ssi::ldp::Error),
6666
#[error("RSA key must be at least 2048 bits")]
6767
RSAKeyTooSmall,
6868
}
@@ -308,7 +308,7 @@ pub async fn generate_proof(
308308
resolver: &dyn DIDResolver,
309309
context_loader: &mut ContextLoader,
310310
jwk_opt: Option<&JWK>,
311-
) -> Result<ssi::vc::Proof, SignError> {
311+
) -> Result<ssi::ldp::Proof, SignError> {
312312
let keys = list_keys(ssh_agent_sock).await?;
313313
let (jwk, pk) = select_key(keys, jwk_opt)?;
314314
let prep =

‎lib/web/Cargo.toml‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ edition = "2018"
88
wasm-bindgen = "0.2"
99
wasm-bindgen-futures = "0.4"
1010
serde_json = "1.0"
11+
thiserror = "1.0"
1112
js-sys = "0.3"
1213
getrandom = { version = "0.2", features = ["js"] }
1314
rand = { version = "0.7", features = ["wasm-bindgen"] }
@@ -16,23 +17,23 @@ chrono = { version = "0.4", features = ["wasmbind"] }
1617
[dependencies.didkit]
1718
path = "../"
1819
default-features = false
19-
features = ["wasm"]
20+
features = ["wasm", "w3c", "tezos", "eip"]
2021

2122
# TODO remove dependency on ssi
2223
[dependencies.ssi]
2324
path = "../../../ssi"
2425
default-features = false
25-
features = ["ed25519-dalek", "sha2", "rsa", "rand", "libsecp256k1", "p256"]
26+
features = ["w3c", "tezos", "eip"]
2627

2728
[dependencies.did-method-key]
2829
path = "../../../ssi/did-key"
2930
default-features = false
30-
features = ["secp256k1", "p256"]
31+
features = ["secp256k1", "secp256r1"]
3132

3233
[dependencies.did-tz]
3334
path = "../../../ssi/did-tezos"
3435
default-features = false
35-
features = ["secp256k1", "dalek", "p256"]
36+
features = ["secp256k1", "ed25519", "secp256r1"]
3637

3738
[dependencies.did-webkey]
3839
path = "../../../ssi/did-webkey"

‎lib/web/src/lib.rs‎

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,9 @@ fn map_jsvalue(result: Result<String, Error>) -> Result<String, JsValue> {
2828
}
2929
}
3030

31-
fn map_async_jsvalue(future: impl Future<Output = Result<String, Error>> + 'static) -> Promise {
31+
fn map_async_jsvalue<E: std::error::Error>(
32+
future: impl Future<Output = Result<String, E>> + 'static,
33+
) -> Promise {
3234
future_to_promise(async {
3335
match future.await {
3436
Ok(string) => Ok(string.into()),
@@ -498,7 +500,15 @@ pub fn DIDAuth(holder: String, linked_data_proof_options: String, key: String) -
498500
map_async_jsvalue(did_auth(holder, linked_data_proof_options, key))
499501
}
500502

501-
async fn jwk_from_tezos(tz_pk: String) -> Result<String, Error> {
503+
#[derive(thiserror::Error, Debug)]
504+
pub enum TezosJwkError {
505+
#[error(transparent)]
506+
TzKey(#[from] ssi::tzkey::DecodeTezosPkError),
507+
#[error(transparent)]
508+
Json(#[from] serde_json::Error),
509+
}
510+
511+
async fn jwk_from_tezos(tz_pk: String) -> Result<String, TezosJwkError> {
502512
let jwk = ssi::tzkey::jwk_from_tezos_key(&tz_pk)?;
503513
let jwk_json = serde_json::to_string(&jwk)?;
504514
Ok(jwk_json)

0 commit comments

Comments
 (0)