pub struct DIDPeer;
Implementations§
Source§impl DIDPeer
impl DIDPeer
Sourcepub fn create_peer_did(
keys: &Vec<DIDPeerCreateKeys>,
services: Option<&Vec<DIDPeerService>>,
) -> Result<(String, Vec<DIDPeerCreatedKeys>), DIDPeerError>
pub fn create_peer_did( keys: &Vec<DIDPeerCreateKeys>, services: Option<&Vec<DIDPeerService>>, ) -> Result<(String, Vec<DIDPeerCreatedKeys>), DIDPeerError>
Creates a new did:peer DID
This will preserve the order of the keys and services in creating the did:peer string
§Examples
ⓘ
// Create a did:peer with pre-existing encryption key (Multibase base58-btc e.g: z6MkhaXgBZDvotDkL5257faiztiGiC2QtKLGpbnnEGta2doK)
let keys = vec![DIDPeerCreateKeys {
type_: Some(DIDPeerKeyType::Ed25519),
purpose: DIDPeerKeys::Encryption,
public_key_multibase: Some("z6MkhaXgBZDvotDkL5257faiztiGiC2QtKLGpbnnEGta2doK".into()),
}];
let did_peer = DIDPeer::create_peer_did(&keys, None).expect("Failed to create did:peer");
// Create a random did:peer with services
let keys = vec![DIDPeerCreateKeys {
type_: Some(DIDPeerKeyType::Secp256k1),
purpose: DIDPeerKeys::Encryption,
public_key_multibase: Some("z6MkhaXgBZDvotDkL5257faiztiGiC2QtKLGpbnnEGta2doK".into()),
}];
let services: Vec<DIDPeerService> = vec![DIDPeerService {
_type: "dm".into(),
id: None,
service_end_point: PeerServiceEndPoint::Long(PeerServiceEndPointLong {
uri: "http://example.com/didcomm".into(),
accept: vec!["didcomm/v2".into()],
routing_keys: vec!["did:example:123456789abcdefghi#key-1".into()],
}),
}];
let did_peer =
DIDPeer::create_peer_did(&keys, Some(&services)).expect("Failed to create did:peer");
// How to create a key prior to creating a did:peer
let did =
DIDKey::generate(&JWK::generate_ed25519().unwrap()).expect("Failed to create did:key");
let keys = vec![DIDPeerCreateKeys {
type_: Some(DIDPeerKeyType::Ed25519),
purpose: DIDPeerKeys::Verification,
public_key_multibase: Some(did[8..].to_string()),
}];
let did_peer = DIDPeer::create_peer_did(&keys, None).expect("Failed to create did:peer");
Sourcepub async fn expand_keys(doc: &Document) -> Result<Document, DIDPeerError>
pub async fn expand_keys(doc: &Document) -> Result<Document, DIDPeerError>
Expands an existing DID Document from the did:key Multikeys to full JWT keys This is useful for when you want to resolve a did:peer DID Document to a full JWT included DID Document Converts base58 multi-keys to full JWTs in verificationMethod
Auto Trait Implementations§
impl Freeze for DIDPeer
impl RefUnwindSafe for DIDPeer
impl Send for DIDPeer
impl Sync for DIDPeer
impl Unpin for DIDPeer
impl UnwindSafe for DIDPeer
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more