generated from TBD54566975/tbd-project-template
-
Notifications
You must be signed in to change notification settings - Fork 17
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
Add did web impl in web5-rs #273
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
#!/bin/bash | ||
|
||
for dir in */; do | ||
echo "Entering directory: $dir" | ||
(cd "$dir" && ./build) | ||
echo "Finished building in $dir" | ||
echo "------------------------" | ||
done | ||
|
||
echo "All builds completed" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
bound/kt/src/main/kotlin/web5/sdk/dids/methods/web/DidWeb.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
package web5.sdk.dids.methods.web | ||
|
||
import kotlinx.coroutines.runBlocking | ||
import web5.sdk.crypto.keys.Jwk | ||
import web5.sdk.dids.Did | ||
import web5.sdk.dids.Document | ||
import web5.sdk.dids.ResolutionResult | ||
import web5.sdk.rust.SystemTarget | ||
|
||
import web5.sdk.rust.didWebResolve as rustCoreDidWebResolve | ||
import web5.sdk.rust.DidWeb as RustCoreDidWeb | ||
|
||
/** | ||
* A class representing a DID (Decentralized Identifier) using the Web method. | ||
* | ||
* @property did The DID associated with this instance. | ||
* @property document The DID document associated with this instance. | ||
*/ | ||
class DidWeb { | ||
init { | ||
SystemTarget.set() // ensure the sys arch is set for first-time loading | ||
} | ||
|
||
val did: Did | ||
val document: Document | ||
|
||
/** | ||
* Constructs a DidWeb instance using a DID URI. | ||
* | ||
* @param uri The DID URI. | ||
*/ | ||
constructor(uri: String) { | ||
val rustCoreDidWeb = runBlocking { | ||
RustCoreDidWeb.fromUri(uri) | ||
} | ||
|
||
this.did = rustCoreDidWeb.getData().did | ||
this.document = rustCoreDidWeb.getData().document | ||
} | ||
|
||
/** | ||
* Constructs a DidWeb instance using a domain and public key jwk | ||
* | ||
* @param domain The DID domain name. | ||
*/ | ||
constructor(domain: String, publicKey: Jwk) { | ||
val rustCoreDidWeb = runBlocking { | ||
RustCoreDidWeb.fromPublicJwk(domain, publicKey); | ||
} | ||
|
||
this.did = rustCoreDidWeb.getData().did | ||
this.document = rustCoreDidWeb.getData().document | ||
} | ||
|
||
companion object { | ||
/** | ||
* Resolves a DID URI to a DidResolutionResult. | ||
* | ||
* @param uri The DID URI to resolve. | ||
* @return DidResolutionResult The result of the DID resolution. | ||
*/ | ||
@JvmStatic | ||
fun resolve(uri: String): ResolutionResult { | ||
val rustCoreResolutionObject = | ||
runBlocking { | ||
rustCoreDidWebResolve(uri).getData() | ||
} | ||
return rustCoreResolutionObject | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file modified
BIN
+18.1 KB
(100%)
bound/kt/src/main/resources/libweb5_uniffi_aarch64_apple_darwin.dylib
Binary file not shown.
Binary file modified
BIN
+27.8 KB
(100%)
bound/kt/src/main/resources/libweb5_uniffi_x86_64_apple_darwin.dylib
Binary file not shown.
Binary file modified
BIN
-8.27 KB
(100%)
bound/kt/src/main/resources/libweb5_uniffi_x86_64_unknown_linux_gnu.so
Binary file not shown.
Binary file modified
BIN
-140 KB
(100%)
bound/kt/src/main/resources/libweb5_uniffi_x86_64_unknown_linux_musl.so
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
bound/kt/src/test/kotlin/web5/sdk/dids/methods/web/DidWebTests.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package web5.sdk.dids.methods.web | ||
|
||
import org.junit.jupiter.api.Assertions.* | ||
import org.junit.jupiter.api.Test | ||
import web5.sdk.rust.ed25519GeneratorGenerate | ||
|
||
class DidWebTests { | ||
|
||
@Test | ||
fun `can create did web`() { | ||
val domain = "example.com" | ||
val jwk = ed25519GeneratorGenerate(); | ||
|
||
val didWeb = DidWeb(domain, jwk) | ||
assertEquals(didWeb.did.uri, "did:web:example.com") | ||
assertEquals(didWeb.document.verificationMethod.get(0).publicKeyJwk, jwk) | ||
} | ||
|
||
@Test | ||
fun `can resolve did web uri`() { | ||
// Works if you host a local did web document You must host this json at http://localhost:1234/.well-known/did.json | ||
// val didDocumentJson = """ | ||
// { | ||
// "id":"did:web.tbd.website", | ||
// "@context":[ | ||
// "https://www.w3.org/ns/did/v1" | ||
// ], | ||
// "verificationMethod":[ | ||
// { | ||
// "id":"did:web:www.tbd.website#key-0", | ||
// "type":"JsonWebKey", | ||
// "controller":"did:web:www.tbd.website", | ||
// "publicKeyJwk":{ | ||
// "alg":"Ed25519", | ||
// "kty":"OKP", | ||
// "crv":"Ed25519", | ||
// "x":"gNFtgCZhOYv00p48FHQYt4edkoBPOyw0oGAB20LrT0c" | ||
// } | ||
// } | ||
// ] | ||
// } | ||
// """.trimIndent() | ||
// | ||
// val didUri = "did:web:localhost%3A1234" | ||
// val resolvedDid = DidWeb.resolve(didUri) | ||
// | ||
// assertEquals(resolvedDid.document!!.id, "did:web:www.tbd.website") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
nice!