### Install the SDK Source: https://github.com/openvtc/rp-sdk-js/blob/main/README.md Install the package via npm. ```bash npm install @openvtc/rp-sdk ``` -------------------------------- ### Establish a session cookie Source: https://github.com/openvtc/rp-sdk-js/blob/main/README.md Create a secure session cookie after successful token verification. ```typescript import { establishSession } from "@openvtc/rp-sdk"; const accessToken = await myJwtMinter.mint({ sub: verified.subject }); const { subject, cookie } = establishSession(verified, accessToken); res.cookie(cookie.name, cookie.value, cookie.options); // SDK sets HttpOnly + Secure + SameSite=Strict by default. ``` -------------------------------- ### Implement a Multi-Method DID Resolver Source: https://github.com/openvtc/rp-sdk-js/blob/main/README.md Implement the DidResolver interface to handle multiple DID methods, using the built-in KeyResolver for did:key and custom logic for others. ```ts import type { DidResolver } from "@openvtc/rp-sdk"; class MultiMethodResolver implements DidResolver { async resolveAuthenticationKey(did: string): Promise { if (did.startsWith("did:key:")) return keyResolver.resolveAuthenticationKey(did); // ... did:peer / did:webvh / did:web cases } } ``` -------------------------------- ### Perform Consent Confirmation Exchange Source: https://github.com/openvtc/rp-sdk-js/blob/main/README.md Build and sign a confirmation request, then verify the wallet's response using the SDK's verification utilities. ```ts import { buildConfirmRequest, signConfirmRequest, verifyConfirmResponse, KeyResolver, } from "@openvtc/rp-sdk"; // 1. Build a request, bind the challenge server-side to (subject, action), // and (per spec) sign it so `reason` is bound to your RP key. const request = buildConfirmRequest({ issuer: RP_DID, subject: walletDid, challenge, // ≥128-bit base64url nonce, persisted against this pending confirm reason: "Confirm transfer of $1,000 to did:web:bob.example", actionType: "payment.transfer", }); await signConfirmRequest(request, rpSigner); // rpSigner: { verificationMethod, sign() } // …authcrypt + deliver `request` to the wallet over DIDComm… // 2. When the wallet's confirm/response arrives (already DIDComm-decrypted), // verify the proof + framework bindings: const decision = await verifyConfirmResponse({ document: responseDoc, subject: walletDid, // must equal issuer + proof signer challenge, // must be echoed bit-for-bit audience: RP_DID, // optional recipient cross-check resolver: new KeyResolver(), }); // decision.decision ∈ {"approved","denied"}; retain the document for audit. ``` -------------------------------- ### Verify an id_token Source: https://github.com/openvtc/rp-sdk-js/blob/main/README.md Verify a SIOPv2 id_token using a KeyResolver and specific audience/nonce constraints. ```typescript import { verifyIdToken, KeyResolver } from "@openvtc/rp-sdk"; const resolver = new KeyResolver(); // did:key only; see below const verified = await verifyIdToken({ idToken: req.body.id_token, audience: process.env.RP_DID!, nonce: sessionStore.challengeFor(req.body.session_id), resolver, }); // verified.subject is the wallet's holder DID; bind your session to it. console.log(`logged in: ${verified.subject}`); ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.