-
Notifications
You must be signed in to change notification settings - Fork 16
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
Decouple from UniFFI code-gen'd Web5Exception #334
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package web5.sdk | ||
|
||
class Web5Exception( | ||
val variant: String, | ||
override val message: String | ||
) : Exception(message) { | ||
companion object { | ||
internal fun fromRustCore(e: web5.sdk.rust.Web5Exception.Exception): Web5Exception { | ||
return Web5Exception(e.variant, e.msg) | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,22 @@ | ||
package web5.sdk.crypto | ||
|
||
import web5.sdk.rust.Dsa as RustCoreDsa | ||
|
||
enum class Dsa { | ||
ED25519, | ||
SECP256K1; | ||
} | ||
|
||
internal fun dsaFromRustCore(rustCore: RustCoreDsa): Dsa { | ||
return when (rustCore) { | ||
RustCoreDsa.ED25519 -> Dsa.ED25519 | ||
RustCoreDsa.SECP256K1 -> Dsa.SECP256K1 | ||
} | ||
} | ||
|
||
internal fun dsaToRustCore(dsa: Dsa): RustCoreDsa { | ||
return when(dsa) { | ||
Dsa.ED25519 -> RustCoreDsa.ED25519 | ||
Dsa.SECP256K1 -> RustCoreDsa.SECP256K1 | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,9 @@ | ||
package web5.sdk.crypto | ||
|
||
import web5.sdk.Web5Exception | ||
import web5.sdk.crypto.keys.Jwk | ||
import web5.sdk.rust.ed25519GeneratorGenerate | ||
import web5.sdk.rust.Web5Exception.Exception as RustCoreException | ||
|
||
/** | ||
* Generates private key material for Ed25519. | ||
|
@@ -14,8 +16,12 @@ class Ed25519Generator { | |
* @return Jwk the JWK with private key material included. | ||
*/ | ||
fun generate(): Jwk { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. chad says: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. also since there are a lot of these it could be cleaner to do it this way with return try:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nice catch! done |
||
val rustCoreJwkData = ed25519GeneratorGenerate() | ||
return Jwk.fromRustCoreJwkData(rustCoreJwkData) | ||
try { | ||
val rustCoreJwkData = ed25519GeneratorGenerate() | ||
return Jwk.fromRustCoreJwkData(rustCoreJwkData) | ||
} catch (e: RustCoreException) { | ||
throw Web5Exception.fromRustCore(e) | ||
} | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
perfect