@@ -28,6 +28,24 @@ import {createCredentialProvider} from '@docknetwork/wallet-sdk-core/src/credent
2828import { createDIDProvider } from '@docknetwork/wallet-sdk-core/src/did-provider' ;
2929import { createMessageProvider } from '@docknetwork/wallet-sdk-core/src/message-provider' ;
3030import { createVerificationController } from '@docknetwork/wallet-sdk-core/src/verification-controller' ;
31+ import {
32+ createDelegationOffer ,
33+ createOOBInvitation ,
34+ acceptDelegationOffer ,
35+ handleMessage ,
36+ decodeMessage ,
37+ } from '@docknetwork/wallet-sdk-core/src/delegation/delegation-offer' ;
38+ import {
39+ issueCredential ,
40+ delegateCredential ,
41+ } from '@docknetwork/wallet-sdk-core/src/delegation/delegation-issuance' ;
42+ import { getDelegationDetails } from '@docknetwork/wallet-sdk-core/src/delegation/delegation-policy' ;
43+ import { getDelegationChain } from '@docknetwork/wallet-sdk-core/src/delegation/delegation-chain' ;
44+ import {
45+ revokeDelegatableCredential ,
46+ unrevokeDelegatableCredential ,
47+ isDelegatableCredentialRevoked ,
48+ } from '@docknetwork/wallet-sdk-core/src/delegation/delegation-revocation' ;
3149import { blockchainService } from '@docknetwork/wallet-sdk-wasm/src/services/blockchain' ;
3250import {
3351 checkPasskeySupport ,
@@ -637,6 +655,78 @@ async function initialize({
637655 } ,
638656 } ;
639657 } ,
658+
659+ /**
660+ * Routes incoming DIDComm delegation messages (offers, credential
661+ * requests, issuance, acks) to the delegation handlers automatically.
662+ *
663+ * Without this, delegation messages must be dispatched manually via
664+ * `handleMessage`. Call once after initialization to participate in
665+ * delegation flows as issuer and/or holder. Listen for the
666+ * `delegationOfferReceived` and `delegatedCredentialReceived` events on
667+ * `wallet.eventManager` to react in the UI.
668+ *
669+ * @returns {Function } Unsubscribe function that stops routing.
670+ *
671+ * @example
672+ * const stop = wallet.enableDelegation();
673+ * wallet.wallet.eventManager.addListener('delegationOfferReceived', offer => {
674+ * // prompt the user, then accept
675+ * wallet.acceptDelegationOffer(offer);
676+ * });
677+ */
678+ enableDelegation : ( ) =>
679+ messageProvider . addMessageListener ( message =>
680+ handleMessage ( message , { wallet, messageProvider} ) ,
681+ ) ,
682+
683+ /**
684+ * Creates a delegation offer for a role and persists it on the wallet.
685+ * Pass the returned offer to `createOOBInvitation` to produce a shareable
686+ * URL. Works for both root issuance (no `credentialId`) and re-delegation
687+ * (pass the delegatable credential's `credentialId`).
688+ *
689+ * @async
690+ * @param {Object } params - see core createDelegationOffer; `wallet` is bound automatically
691+ * @returns {Promise<Object> } The delegation offer
692+ */
693+ createDelegationOffer : params =>
694+ createDelegationOffer ( { wallet, ...params } ) ,
695+
696+ /**
697+ * Accepts a received delegation offer, sending a credential request back
698+ * to the issuer.
699+ *
700+ * @async
701+ * @param {Object } delegationOffer - The offer from a `delegationOfferReceived` event
702+ * @returns {Promise<void> }
703+ */
704+ acceptDelegationOffer : delegationOffer =>
705+ acceptDelegationOffer ( { delegationOffer, wallet, messageProvider} ) ,
706+
707+ /**
708+ * Resolves the full delegation details for a stored delegatable credential:
709+ * policy, role, remaining delegation depth, chain, and the roles the holder
710+ * may re-delegate to.
711+ *
712+ * @async
713+ * @param {Object } credential - A stored delegatable credential
714+ * @returns {Promise<Object> } Delegation details
715+ */
716+ getDelegationDetails : credential =>
717+ getDelegationDetails ( credential , wallet ) ,
718+
719+ /**
720+ * Manually dispatch a DIDComm delegation message (e.g. an OOB invitation
721+ * URL scanned from a QR code) to the delegation handlers. Prefer
722+ * `enableDelegation()` for automatic routing of relayed messages.
723+ *
724+ * @async
725+ * @param {string|Object } message - OOB URL string or DIDComm message object
726+ * @returns {Promise<void> }
727+ */
728+ handleMessage : message =>
729+ handleMessage ( message , { wallet, messageProvider} ) ,
640730 } ;
641731
642732 if ( passkeyMnemonic ) {
@@ -735,6 +825,18 @@ export {
735825 enrollUserWithPasskey ,
736826 authenticateWithPasskey ,
737827 initializeCloudWalletWithPasskey ,
828+ createDelegationOffer ,
829+ createOOBInvitation ,
830+ acceptDelegationOffer ,
831+ handleMessage ,
832+ decodeMessage ,
833+ issueCredential ,
834+ delegateCredential ,
835+ getDelegationDetails ,
836+ getDelegationChain ,
837+ revokeDelegatableCredential ,
838+ unrevokeDelegatableCredential ,
839+ isDelegatableCredentialRevoked ,
738840} ;
739841
740842export default {
@@ -759,4 +861,16 @@ export default {
759861 enrollUserWithPasskey,
760862 authenticateWithPasskey,
761863 initializeCloudWalletWithPasskey,
864+ createDelegationOffer,
865+ createOOBInvitation,
866+ acceptDelegationOffer,
867+ handleMessage,
868+ decodeMessage,
869+ issueCredential,
870+ delegateCredential,
871+ getDelegationDetails,
872+ getDelegationChain,
873+ revokeDelegatableCredential,
874+ unrevokeDelegatableCredential,
875+ isDelegatableCredentialRevoked,
762876} ;
0 commit comments