Function: usePeerDID()

typescript
1
usePeerDID(): object

Defined in: packages/identus-react/src/hooks/usePeerDID.ts:49

Hook for accessing Peer DID context and operations.

Peer DIDs are ephemeral, off-ledger DIDs used for direct peer-to-peer communication. They're created quickly and don't require blockchain anchoring. This hook must be used within a PeerDIDProvider.

Returns

Peer DID context

create()

typescript
1
create: () => Promise<DID>

Function to create a new Peer DID

Returns

Promise<DID>

peerDID

typescript
1
peerDID: null | DID

Current Peer DID instance, null if not yet created

Throws

When used outside of PeerDIDProvider

Example

tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import { usePeerDID } from '@trust0/identus-react/hooks';
function PeerDIDComponent() {
const { peerDID, create } = usePeerDID();
const handleCreatePeerDID = async () => {
try {
await create();
console.log('Peer DID created for communication');
} catch (error) {
console.error('Failed to create Peer DID:', error);
}
};
return (
<div>
{peerDID ? (
<div>
<p>Peer DID: {peerDID.toString()}</p>
<p>Ready for peer-to-peer communication</p>
</div>
) : (
<button onClick={handleCreatePeerDID}>
Create Peer DID
</button>
)}
</div>
);
}