diff --git a/crates/teddybear-crypto/src/lib.rs b/crates/teddybear-crypto/src/lib.rs index eee8781..f1ad503 100644 --- a/crates/teddybear-crypto/src/lib.rs +++ b/crates/teddybear-crypto/src/lib.rs @@ -7,7 +7,7 @@ use did_web::DIDWeb; use rand::rngs::OsRng; use serde::{Deserialize, Serialize}; use ssi_dids_core::{ - document::{verification_method::ValueOrReference, DIDVerificationMethod, ResourceRef}, + document::{DIDVerificationMethod, ResourceRef}, DIDURLReference, DIDURLReferenceBuf, InvalidDIDURL, VerificationMethodDIDResolver, }; use ssi_jwk::{Algorithm, Params}; @@ -25,6 +25,7 @@ use teddybear_high_assurance::DnsError; use crate::okp_encoder::OKPEncoder; pub use ssi_dids_core::{ + document::verification_method::ValueOrReference, ssi_json_ld::{ iref::{Uri, UriBuf}, Iri, IriBuf, diff --git a/crates/teddybear-js/module.d.ts b/crates/teddybear-js/module.d.ts index 930c3d1..88aba71 100644 --- a/crates/teddybear-js/module.d.ts +++ b/crates/teddybear-js/module.d.ts @@ -13,6 +13,8 @@ * ```ts * import { * ContextLoader, + * DID, + * DIDURL, * Document, * PrivateEd25519, * verifyJWS @@ -33,7 +35,7 @@ * * // You can convert private Ed25519 keys to public Ed25519 keys * // by providing the related DID document identifier and controller. - * const publicKey = privateKey.toPublicKey("did:web:example.com", "did:web:example.com"); + * const publicKey = privateKey.toPublicKey(new DIDURL("did:web:example.com#key-1"), new DID("did:web:example.com")); * * // It is possible to convert a private Ed25519 key into a private * // X25519 key. @@ -45,7 +47,7 @@ * // ...issue verifiable credentials, ... * const contextLoader = new ContextLoader(); * const verifiableCredential = await key.issueVC( - * "did:web:example.com#key-1", + * new DIDURL("did:web:example.com#key-1"), * { * "@context": ["https://www.w3.org/ns/credentials/v2"], * type: ["VerifiableCredential"], @@ -59,7 +61,7 @@ * * // ...present them, ... * const vp = await key.presentVP( - * "did:web:example.com#key-1", + * new DIDURL("did:web:example.com#key-1"), * { * "@context": ["https://www.w3.org/ns/credentials/v2"], * type: ["VerifiablePresentation"], @@ -96,12 +98,12 @@ * * // Resolve a DID document. This is essentially an entrypoint * // to almost all Teddybear operations. - * const document = await Document.resolve("did:web:example.com"); + * const document = await Document.resolve(new DID("did:web:example.com")); * * // Resolved DID document may contain multiple keys with different * // algorithms within it, so usually you would select one based on * // key types, operation requirements, etc. - * const vm = document.verificationMethods().authentication?.[0]!; + * const vm = document.verificationMethods().authentication[0]!; * const resolvedKey = document.getEd25519VerificationMethod(vm); * * // Public Ed25519 keys can be used to verify JWS signatures @@ -112,13 +114,14 @@ * * ```ts * import { + * DID, * Document, * encryptAES * } from "@vaultie/teddybear"; * - * const document = await Document.resolve("did:web:example.com"); + * const document = await Document.resolve(new DID("did:web:example.com")); * - * const vm = document.verificationMethods().keyAgreement?.[0]!; + * const vm = document.verificationMethods().keyAgreement[0]!; * const resolvedKey = document.getX25519VerificationMethod(vm); * * // X25519 public keys can be used to encrypt data for multiple recipients diff --git a/crates/teddybear-js/src/lib.rs b/crates/teddybear-js/src/lib.rs index 17e3424..7c7b275 100644 --- a/crates/teddybear-js/src/lib.rs +++ b/crates/teddybear-js/src/lib.rs @@ -1,5 +1,11 @@ -// FIXME: https://github.com/rustwasm/wasm-bindgen/issues/3945 -#![allow(clippy::empty_docs)] +#![allow( + // FIXME: https://github.com/rustwasm/wasm-bindgen/issues/3945 + clippy::empty_docs, + + // This crate is not meant to be used in Rust at all, + // so ToString trait impls play no role in here. + clippy::inherent_to_string +)] extern crate alloc; @@ -14,8 +20,8 @@ use ssi_status::bitstring_status_list::{ }; use teddybear_c2pa::{Builder, Ed25519Signer, Reader}; use teddybear_crypto::{ - DIDURLBuf, Ed25519VerificationKey2020, IriBuf, JwkVerificationMethod, SignOptions, UriBuf, - X25519KeyAgreementKey2020, DID, + DIDBuf, DIDURLBuf, Ed25519VerificationKey2020, JwkVerificationMethod, SignOptions, + ValueOrReference, X25519KeyAgreementKey2020, }; use teddybear_jwe::{A256Gcm, XC20P}; use wasm_bindgen::prelude::*; @@ -71,27 +77,6 @@ export type JWSOptions = { embedSigningKey?: boolean; keyIdentifier?: string; }; - -/** - * Supported verification method types. - * - * @category DID - */ -export type VerificationMethod = - | "assertionMethod" - | "authentication" - | "capabilityInvocation" - | "capabilityDelegation" - | "keyAgreement"; - -/** - * Verification method map. - * - * @category DID - */ -export type VerificationMethods = { - [K in VerificationMethod]?: string[]; -}; "#; #[wasm_bindgen] @@ -104,9 +89,86 @@ extern "C" { #[wasm_bindgen(typescript_type = "JWSOptions")] pub type JwsOptions; +} + +/// DID value. +/// +/// @category DID +#[wasm_bindgen] +pub struct DID(DIDBuf); - #[wasm_bindgen(typescript_type = "VerificationMethods")] - pub type VerificationMethods; +#[wasm_bindgen] +impl DID { + #[wasm_bindgen(constructor)] + pub fn new(value: String) -> Result { + Ok(DID(DIDBuf::from_string(value)?)) + } + + #[wasm_bindgen(js_name = "toString")] + pub fn to_string(&self) -> String { + self.0.to_string() + } +} + +/// DIDURL value. +/// +/// @category DID +#[wasm_bindgen] +#[derive(Clone)] +pub struct DIDURL(DIDURLBuf); + +#[wasm_bindgen] +impl DIDURL { + #[wasm_bindgen(constructor)] + pub fn new(value: String) -> Result { + Ok(DIDURL(DIDURLBuf::from_string(value)?)) + } + + pub fn did(&self) -> DID { + DID(self.0.did().to_owned()) + } + + #[wasm_bindgen(js_name = "toString")] + pub fn to_string(&self) -> String { + self.0.to_string() + } +} + +#[wasm_bindgen] +pub struct VerificationMethods { + assertion_method: Vec, + authentication: Vec, + capability_invocation: Vec, + capability_delegation: Vec, + key_agreement: Vec, +} + +#[wasm_bindgen] +impl VerificationMethods { + #[wasm_bindgen(js_name = "assertionMethod", getter)] + pub fn assertion_method(&self) -> Vec { + self.assertion_method.clone() + } + + #[wasm_bindgen(getter)] + pub fn authentication(&self) -> Vec { + self.authentication.clone() + } + + #[wasm_bindgen(js_name = "capabilityInvocation", getter)] + pub fn capability_invocation(&self) -> Vec { + self.capability_invocation.clone() + } + + #[wasm_bindgen(js_name = "capabilityDelegation", getter)] + pub fn capability_delegation(&self) -> Vec { + self.capability_delegation.clone() + } + + #[wasm_bindgen(js_name = "keyAgreement", getter)] + pub fn key_agreement(&self) -> Vec { + self.key_agreement.clone() + } } /// DID document. @@ -123,7 +185,12 @@ impl Document { Ok(Document(document)) } - pub async fn resolve(did: &str, options: Option) -> Result { + #[wasm_bindgen(getter)] + pub fn id(&self) -> DID { + DID(self.0.inner.id.to_owned()) + } + + pub async fn resolve(did: &DID, options: Option) -> Result { let options = options .map(Into::into) .map(serde_wasm_bindgen::from_value) @@ -131,32 +198,59 @@ impl Document { .unwrap_or_default(); Ok(Document( - teddybear_crypto::Document::resolve(DID::new(did)?, options).await?, + teddybear_crypto::Document::resolve(&did.0, options).await?, )) } - pub fn id(&self) -> Result { - Ok(self.0.inner.id.to_string()) - } - #[wasm_bindgen(js_name = "verificationMethods")] - pub fn verification_methods(&self) -> Result { - let grouped = self.0.verification_methods().into_group_map(); - Ok(grouped.serialize(&OBJECT_SERIALIZER)?.into()) + pub fn verification_methods(&self) -> VerificationMethods { + fn convert_vr(id: &teddybear_crypto::DID, values: &[ValueOrReference]) -> Vec { + values + .iter() + .map(|vr| DIDURL(vr.id().resolve(id).into_owned())) + .collect() + } + + VerificationMethods { + assertion_method: convert_vr( + &self.0.inner.id, + &self.0.inner.verification_relationships.assertion_method, + ), + authentication: convert_vr( + &self.0.inner.id, + &self.0.inner.verification_relationships.authentication, + ), + capability_invocation: convert_vr( + &self.0.inner.id, + &self + .0 + .inner + .verification_relationships + .capability_invocation, + ), + capability_delegation: convert_vr( + &self.0.inner.id, + &self + .0 + .inner + .verification_relationships + .capability_delegation, + ), + key_agreement: convert_vr( + &self.0.inner.id, + &self.0.inner.verification_relationships.key_agreement, + ), + } } #[wasm_bindgen(js_name = "getEd25519VerificationMethod")] - pub fn get_ed25519_verification_method(&self, id: &str) -> Result { - Ok(PublicEd25519( - self.0.get_verification_method(&DIDURLBuf::from_str(id)?)?, - )) + pub fn get_ed25519_verification_method(&self, id: &DIDURL) -> Result { + Ok(PublicEd25519(self.0.get_verification_method(&id.0)?)) } #[wasm_bindgen(js_name = "getX25519VerificationMethod")] - pub fn get_x25519_verification_method(&self, id: &str) -> Result { - Ok(PublicX25519( - self.0.get_verification_method(&DIDURLBuf::from_str(id)?)?, - )) + pub fn get_x25519_verification_method(&self, id: &DIDURL) -> Result { + Ok(PublicX25519(self.0.get_verification_method(&id.0)?)) } /// Serialize the current document as an object. @@ -213,8 +307,8 @@ impl PrivateEd25519 { /// Get the did:key document DID value of the Ed25519 key. #[wasm_bindgen(js_name = "toDIDKey")] - pub fn to_did_key(&self) -> String { - self.0.to_did_key().into_string() + pub fn to_did_key(&self) -> DID { + DID(self.0.to_did_key()) } /// Get the did:key DID URL fragment value of the Ed25519 key. @@ -225,10 +319,10 @@ impl PrivateEd25519 { /// Derive an Ed25519 public key from the private key. #[wasm_bindgen(js_name = "toPublicKey")] - pub fn to_public_key(&self, id: &str, controller: &str) -> Result { + pub fn to_public_key(&self, id: &DIDURL, controller: &DID) -> Result { let verification_method = self .0 - .to_verification_method(IriBuf::from_str(id)?, UriBuf::from_str(controller)?); + .to_verification_method(id.0.as_iri().to_owned(), controller.0.as_uri().to_owned()); Ok(PublicEd25519(verification_method)) } @@ -249,16 +343,15 @@ impl PrivateEd25519 { #[wasm_bindgen(js_name = "issueVC")] pub async fn issue_vc( &self, - verification_method: &str, + verification_method: &DIDURL, vc: Object, context_loader: &mut ContextLoader, ) -> Result { let credential: SpecializedJsonCredential = serde_wasm_bindgen::from_value(vc.into())?; - let vm = IriBuf::from_str(verification_method)?; Ok(issue_vc( self.0.inner().clone(), - vm, + verification_method.0.as_iri().to_owned(), &credential, &mut context_loader.0, ) @@ -271,7 +364,7 @@ impl PrivateEd25519 { #[wasm_bindgen(js_name = "presentVP")] pub async fn present_vp( &self, - verification_method: &str, + verification_method: &DIDURL, vp: Object, context_loader: &mut ContextLoader, domain: Option, @@ -279,11 +372,10 @@ impl PrivateEd25519 { ) -> Result { let presentation: JsonPresentation = serde_wasm_bindgen::from_value(vp.into())?; - let vm = IriBuf::from_str(verification_method)?; Ok(present_vp( self.0.inner().clone(), - vm, + verification_method.0.as_iri().to_owned(), &presentation, domain, challenge, @@ -323,20 +415,24 @@ impl PrivateX25519 { /// Derive an X25519 public key from the private key. #[wasm_bindgen(js_name = "toPublicKey")] - pub fn to_public_key(&self, id: &str, controller: &str) -> Result { + pub fn to_public_key(&self, id: &DIDURL, controller: &DID) -> Result { let verification_method = self .0 - .to_verification_method(IriBuf::from_str(id)?, UriBuf::from_str(controller)?); + .to_verification_method(id.0.as_iri().to_owned(), controller.0.as_uri().to_owned()); Ok(PublicX25519(verification_method)) } /// Decrypt the provided JWE object using the X25519 key and the A256GCM algorithm. #[wasm_bindgen(js_name = "decryptAES")] - pub fn decrypt_aes(&self, verification_method: &str, jwe: Jwe) -> Result { + pub fn decrypt_aes( + &self, + verification_method: &DIDURL, + jwe: Jwe, + ) -> Result { let jwe = serde_wasm_bindgen::from_value(jwe.into())?; let payload = - &*teddybear_jwe::decrypt::(&jwe, verification_method, self.0.inner())?; + &*teddybear_jwe::decrypt::(&jwe, &verification_method.0, self.0.inner())?; Ok(payload.into()) } @@ -344,25 +440,26 @@ impl PrivateX25519 { #[wasm_bindgen(js_name = "decryptChaCha20")] pub fn decrypt_chacha20( &self, - verification_method: &str, + verification_method: &DIDURL, jwe: Jwe, ) -> Result { let jwe = serde_wasm_bindgen::from_value(jwe.into())?; - let payload = &*teddybear_jwe::decrypt::(&jwe, verification_method, self.0.inner())?; + let payload = + &*teddybear_jwe::decrypt::(&jwe, &verification_method.0, self.0.inner())?; Ok(payload.into()) } #[wasm_bindgen(js_name = "addAESRecipient")] pub fn add_aes_recipient( &self, - verification_method: &str, + verification_method: &DIDURL, jwe: Jwe, recipient: PublicX25519, ) -> Result { let jwe = serde_wasm_bindgen::from_value(jwe.into())?; let recipient = teddybear_jwe::add_recipient::( &jwe, - verification_method, + &verification_method.0, self.0.inner(), recipient.0.id.as_str().to_owned(), recipient.0.public_key.decoded(), @@ -373,14 +470,14 @@ impl PrivateX25519 { #[wasm_bindgen(js_name = "addChaCha20Recipient")] pub fn add_chacha20_recipient( &self, - verification_method: &str, + verification_method: &DIDURL, jwe: Jwe, recipient: PublicX25519, ) -> Result { let jwe = serde_wasm_bindgen::from_value(jwe.into())?; let recipient = teddybear_jwe::add_recipient::( &jwe, - verification_method, + &verification_method.0, self.0.inner(), recipient.0.id.as_str().to_owned(), recipient.0.public_key.decoded(), @@ -399,14 +496,16 @@ pub struct PublicEd25519(Ed25519VerificationKey2020); impl PublicEd25519 { /// Get the verification method identifier. #[wasm_bindgen(getter)] - pub fn id(&self) -> String { - self.0.id.to_string() + pub fn id(&self) -> Result { + // FIXME: Remove the unnecessary double-conversion + Ok(DIDURL(DIDURLBuf::from_str(&self.0.id)?)) } /// Get the verification method controller. #[wasm_bindgen(getter)] - pub fn controller(&self) -> String { - self.0.controller.to_string() + pub fn controller(&self) -> Result { + // FIXME: Remove the unnecessary double-conversion + Ok(DID(DIDBuf::from_str(&self.0.controller)?)) } /// Get the JWK value (without the private key) of the Ed25519 key within the current keypair. @@ -432,14 +531,16 @@ pub struct PublicX25519(X25519KeyAgreementKey2020); impl PublicX25519 { /// Get the verification method identifier. #[wasm_bindgen(getter)] - pub fn id(&self) -> String { - self.0.id.to_string() + pub fn id(&self) -> Result { + // FIXME: Remove the unnecessary double-conversion + Ok(DIDURL(DIDURLBuf::from_str(&self.0.id)?)) } /// Get the verification method controller. #[wasm_bindgen(getter)] - pub fn controller(&self) -> String { - self.0.controller.to_string() + pub fn controller(&self) -> Result { + // FIXME: Remove the unnecessary double-conversion + Ok(DID(DIDBuf::from_str(&self.0.controller)?)) } /// Get the JWK value (without the private key) of the X25519 key within the current keypair. diff --git a/tests/src/did.test.ts b/tests/src/did.test.ts index f838831..d9539c7 100644 --- a/tests/src/did.test.ts +++ b/tests/src/did.test.ts @@ -1,36 +1,45 @@ -import { Document } from "@vaultie/teddybear"; +import { DID, Document } from "@vaultie/teddybear"; import { describe, it, expect } from "vitest"; describe("can execute DID document-related operations", () => { it("can resolve did:key", async () => { const document = await Document.resolve( - "did:key:z6MkmpNwNTy4ATx87tZWHqSwNf1ZdeQrBHFWyhtvUwqrt32R", + new DID("did:key:z6MkmpNwNTy4ATx87tZWHqSwNf1ZdeQrBHFWyhtvUwqrt32R"), ); - expect(document.verificationMethods().assertionMethod?.[0]).toStrictEqual( + expect( + document.verificationMethods().assertionMethod[0].toString(), + ).toStrictEqual( "did:key:z6MkmpNwNTy4ATx87tZWHqSwNf1ZdeQrBHFWyhtvUwqrt32R#z6MkmpNwNTy4ATx87tZWHqSwNf1ZdeQrBHFWyhtvUwqrt32R", ); - expect(document.verificationMethods().authentication?.[0]).toStrictEqual( + expect( + document.verificationMethods().authentication[0].toString(), + ).toStrictEqual( "did:key:z6MkmpNwNTy4ATx87tZWHqSwNf1ZdeQrBHFWyhtvUwqrt32R#z6MkmpNwNTy4ATx87tZWHqSwNf1ZdeQrBHFWyhtvUwqrt32R", ); - expect(document.verificationMethods().keyAgreement?.[0]).toStrictEqual( + expect( + document.verificationMethods().keyAgreement[0].toString(), + ).toStrictEqual( "did:key:z6MkmpNwNTy4ATx87tZWHqSwNf1ZdeQrBHFWyhtvUwqrt32R#z6LSej1Ss4cgai4cK8KspVmAEgCa7TP7c6zGHtftB16YNXoE", ); }); it("can resolve did:web", async () => { - const document = await Document.resolve("did:web:issuer.localhost", { - requireHighAssuranceVerification: false, - }); - - expect(document.verificationMethods().assertionMethod?.[0]).toStrictEqual( - "did:web:issuer.localhost#key-1", + const document = await Document.resolve( + new DID("did:web:issuer.localhost"), + { + requireHighAssuranceVerification: false, + }, ); - expect(document.verificationMethods().authentication?.[0]).toStrictEqual( - "did:web:issuer.localhost#key-1", - ); + expect( + document.verificationMethods().assertionMethod[0].toString(), + ).toStrictEqual("did:web:issuer.localhost#key-1"); + + expect( + document.verificationMethods().authentication[0].toString(), + ).toStrictEqual("did:web:issuer.localhost#key-1"); }); }); diff --git a/tests/src/ed25519.test.ts b/tests/src/ed25519.test.ts index 12a8477..29358ae 100644 --- a/tests/src/ed25519.test.ts +++ b/tests/src/ed25519.test.ts @@ -23,9 +23,8 @@ describe("can execute ed25519 operations", () => { const thirdPartyDid = `did:key:${thirdPartyKey.fingerprint()}`; const key = PrivateEd25519.fromBytes(seed); - const did = key.toDIDKey(); - expect(thirdPartyDid).toStrictEqual(key.toDIDKey()); + expect(thirdPartyDid).toStrictEqual(key.toDIDKey().toString()); expect(thirdPartyKey.fingerprint()).toStrictEqual( key.toDIDKeyURLFragment(), ); diff --git a/tests/src/vc.test.ts b/tests/src/vc.test.ts index 3c0ac0c..9ede08c 100644 --- a/tests/src/vc.test.ts +++ b/tests/src/vc.test.ts @@ -1,5 +1,6 @@ import { ContextLoader, + DIDURL, PrivateEd25519, verifyCredential, verifyPresentation, @@ -29,7 +30,7 @@ describe("can execute verifiable credentials operations", () => { vcTest("can issue a test credential", ({ contextLoader, key }) => key.issueVC( - `${key.toDIDKey()}#${key.toDIDKeyURLFragment()}`, + new DIDURL(`${key.toDIDKey()}#${key.toDIDKeyURLFragment()}`), { "@context": [ "https://www.w3.org/ns/credentials/v2", @@ -37,7 +38,7 @@ describe("can execute verifiable credentials operations", () => { ], type: ["VerifiableCredential", "Identity"], id: "https://example.com/test", - issuer: key.toDIDKey(), + issuer: key.toDIDKey().toString(), issuanceDate: new Date().toISOString(), credentialSubject: { type: "Person", @@ -65,7 +66,7 @@ describe("can execute verifiable credentials operations", () => { vcTest("can sign a test presentation", async ({ contextLoader, key }) => { const verifiableCredential = await key.issueVC( - `${key.toDIDKey()}#${key.toDIDKeyURLFragment()}`, + new DIDURL(`${key.toDIDKey()}#${key.toDIDKeyURLFragment()}`), { "@context": [ "https://www.w3.org/ns/credentials/v2", @@ -73,7 +74,7 @@ describe("can execute verifiable credentials operations", () => { ], type: ["VerifiableCredential", "Identity"], id: "https://example.com/test", - issuer: key.toDIDKey(), + issuer: key.toDIDKey().toString(), issuanceDate: new Date().toISOString(), credentialSubject: { type: "Person", @@ -99,11 +100,11 @@ describe("can execute verifiable credentials operations", () => { ); const verifiablePresentation = await key.presentVP( - `${key.toDIDKey()}#${key.toDIDKeyURLFragment()}`, + new DIDURL(`${key.toDIDKey()}#${key.toDIDKeyURLFragment()}`), { "@context": ["https://www.w3.org/ns/credentials/v2"], type: ["VerifiablePresentation"], - holder: key.toDIDKey(), + holder: key.toDIDKey().toString(), verifiableCredential, }, contextLoader, @@ -114,7 +115,7 @@ describe("can execute verifiable credentials operations", () => { const { key: credentialKey, challenge: credentialChallenge } = await verifyCredential(verifiableCredential, contextLoader); - expect(credentialKey.id).toStrictEqual( + expect(credentialKey.id.toString()).toStrictEqual( `${key.toDIDKey()}#${key.toDIDKeyURLFragment()}`, ); expect(credentialChallenge).toBeUndefined(); @@ -122,7 +123,7 @@ describe("can execute verifiable credentials operations", () => { const { key: presentationKey, challenge: presentationChallenge } = await verifyPresentation(verifiablePresentation, contextLoader); - expect(presentationKey.id).toStrictEqual( + expect(presentationKey.id.toString()).toStrictEqual( `${key.toDIDKey()}#${key.toDIDKeyURLFragment()}`, ); expect(presentationChallenge).toStrictEqual("123456"); diff --git a/tests/src/x25519.test.ts b/tests/src/x25519.test.ts index 1960f28..0191993 100644 --- a/tests/src/x25519.test.ts +++ b/tests/src/x25519.test.ts @@ -1,4 +1,5 @@ import { + DID, Document, encryptAES, encryptChaCha20, @@ -26,7 +27,7 @@ const generateX25519 = async (): Promise<{ }> => { const ed25519 = PrivateEd25519.generate(); const document = await Document.resolve(ed25519.toDIDKey()); - const x25519VM = document.verificationMethods().keyAgreement?.[0]!; + const x25519VM = document.verificationMethods().keyAgreement[0]!; const publicX25519 = document.getX25519VerificationMethod(x25519VM); const privateX25519 = ed25519.toX25519PrivateKey(); @@ -43,7 +44,7 @@ describe("can execute x25519 operations", () => { it("can extract did:key-related values", async () => { const { ed25519, privateX25519, x25519VM } = await generateX25519(); - expect(x25519VM).toStrictEqual( + expect(x25519VM.toString()).toStrictEqual( `${ed25519.toDIDKey()}#${privateX25519.toDIDKeyURLFragment()}`, ); }); @@ -101,8 +102,8 @@ describe("can execute x25519 operations", () => { keyAgreementKey.controller = did; keyAgreementKey.id = `${did}#${keyAgreementKey.fingerprint()}`; - const document = await Document.resolve(did); - const vm = document.verificationMethods().keyAgreement?.[0]!; + const document = await Document.resolve(new DID(did)); + const vm = document.verificationMethods().keyAgreement[0]!; const firstKey = document.getX25519VerificationMethod(vm); const { publicX25519: secondKey } = await generateX25519(); @@ -131,13 +132,14 @@ describe("can execute x25519 operations", () => { } = await generateX25519(); const recipients = [ - { header: { kid: firstKeyDID, alg: "ECDH-ES+A256KW" } }, - { header: { kid: secondKeyDID, alg: "ECDH-ES+A256KW" } }, + { header: { kid: firstKeyDID.toString(), alg: "ECDH-ES+A256KW" } }, + { header: { kid: secondKeyDID.toString(), alg: "ECDH-ES+A256KW" } }, ]; const documents: Record = { - [firstKeyDID]: firstKeyDocument.toJSON().verificationMethod[1], - [secondKeyDID]: secondKeyDocument.toJSON().verificationMethod[1], + [firstKeyDID.toString()]: firstKeyDocument.toJSON().verificationMethod[1], + [secondKeyDID.toString()]: + secondKeyDocument.toJSON().verificationMethod[1], }; const keyResolver = async ({ id }: { id: string }) => documents[id];