Skip to content
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
4 changes: 2 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ jobs:
- name: Test
run: cargo test --locked

- name: Test WASM JWE encryption
run: cargo test --locked -p didkit-wasm --lib jwe::tests
- name: Test WASM library (JWE, did:key)
run: cargo test --locked -p didkit-wasm --lib

- name: Test CLI
run: cli/tests/example.sh
Expand Down
2 changes: 1 addition & 1 deletion lib/web/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ unsigned-varint = "0.7.0"
[dependencies.didkit]
path = "../"
default-features = false
features = ["ed25519", "rsa", "ripemd-160", "eip", "tezos", "secp256r1"]
features = ["ed25519", "rsa", "ripemd-160", "eip", "tezos", "secp256r1", "secp256k1"]

[dependencies.did-ethr]
path = "../../../ssi/did-ethr"
Expand Down
14 changes: 14 additions & 0 deletions lib/web/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,20 @@ features explicitly. Avoid `--all-features`: it can introduce proposals that the
target browser does not support. Keep the generated JavaScript glue paired with
its WASM binary.

## DID methods

In this WASM build:

- `keyToDID` and `keyToVerificationMethod` can generate `did:key` (Ed25519,
secp256k1 and P-256 keys), `did:tz`, `did:ethr`, `did:pkh` and `did:jwk`.
- `resolveDID` can resolve `did:key`, `did:web`, `did:tz`, `did:ethr`,
`did:pkh` and `did:jwk`.
- `did:ion` and `did:onion` don't resolve. Both read their endpoint from an
environment variable (`DID_ION_API_URL`, `DID_ONION_PROXY_URL`), and a
browser has none: `did:ion` fails with `Missing Sidetree API endpoint`, and
`did:onion` tries a plain HTTP request to the `.onion` host. Use the native
library or CLI for those methods.

## Tests

The `test/` directory contains manual tests to run in the browser. Instructions
Expand Down
27 changes: 27 additions & 0 deletions lib/web/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1091,3 +1091,30 @@ async fn context_loader(url: String) -> Result<String, Error> {
pub fn contextLoader(url: String) -> Promise {
map_async_jsvalue(context_loader(url))
}

#[cfg(test)]
mod tests {
use super::*;
use serde_json::Value;

// LearnCard derives its secp256k1 key from seed bytes, then asks for a did:key.
#[cfg(feature = "generate")]
#[tokio::test]
async fn secp256k1_key_to_did_key_round_trips() {
let jwk = generate_secp256k1_key_from_bytes(&[7u8; 32]).unwrap();

let did = key_to_did("key".to_string(), jwk.clone()).unwrap();
assert!(did.starts_with("did:key:zQ3s"), "unexpected did: {}", did);

let doc: Value =
serde_json::from_str(&resolve_did(did.clone(), "{}".to_string()).await.unwrap())
.unwrap();
assert_eq!(doc["id"], did.as_str());

let key: Value = serde_json::from_str(&jwk).unwrap();
let resolved_key = &doc["verificationMethod"][0]["publicKeyJwk"];
assert_eq!(resolved_key["crv"], "secp256k1");
assert_eq!(resolved_key["x"], key["x"]);
assert_eq!(resolved_key["y"], key["y"]);
}
}
Loading