Skip to content
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

feat: introduce separate DID and DIDURL types #81

Merged
merged 1 commit into from
Aug 30, 2024
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
3 changes: 2 additions & 1 deletion crates/teddybear-crypto/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand All @@ -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,
Expand Down
17 changes: 10 additions & 7 deletions crates/teddybear-js/module.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
* ```ts
* import {
* ContextLoader,
* DID,
* DIDURL,
* Document,
* PrivateEd25519,
* verifyJWS
Expand All @@ -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.
Expand All @@ -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"],
Expand All @@ -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"],
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
Loading