OID4VP 任务内授权扩展的凭证代金券演示

该演示展示酒店预订 Agent 如何借助 OID4VP 任务内授权 A2A 扩展,接受合作方签发的折扣代金券。用户助手只负责转发授权请求,钱包直接与商户验证方交互,商户依据可信签发方列表校验 SD-JWT VC。

# OID4VP 任务授权扩展 - 合伙人贴现券Demo 演示 [OID4VP 任务授权 A2A 扩展](https://github.com/a2aproject/experimental-ext-oid4vp-auth): 一个酒店订票代理("BlueSky Stays"),负责支付合伙人旅行发放的贴现券. 品牌,即买方由一名私人助理代理人代理,该代理人负责转发 用户钱包的授权请求 。 它的建造与 [孙子](https://genkit.dev/) + 用于特工的OpenAI API,以及 [OWF 克里多语系](https://credo.js.org/) 作为可验证的证书钱包/验证人的框架 (OID4VP Holder和验证器). > 这是样本代码,并非用于生产质量。 **免责声明** 在结尾。 ## 使用大小写 - 为什么这里有可验证的证书和 OID4VP (而不是普通的 OAuth ) ? - **发行人QQ校验,没有整合.** 发行凭单的伙伴品牌(一家航空公司) 忠诚计划,一个银行旅行计划, ...) 与接受他们的商人没有直接的融合. 商家信任一个VC(根据一份受信任的发行人名单核对)——不是 一个伙伴后端或共享数据库。登上一个新的伙伴只是添加了它的 DID 。 - **许多发行商的可移动性。** 任何可信赖的品牌都接受同样的凭证; 没有每个伙伴的奥奥特联合会。 - **即时,内容驱动.** 只有在用户请求应用时授权点火 折扣——不是作为登录过程. - **选择性披露/隐私。** 券上只显示 `percent_off` / `expires_at`; 身份,凭证身份,甚至发售的品牌名称都藏起来. - **复置防弹.** 售票券VC是绑定在持票人身上的 所以漏掉的券是不行的 由另一方提出——一个普通的优惠券代码没有提供的东西。 ## 角色和地形学 A2A 客户端是用户的助手代理。 由于凭证属于用户, 助理无法满足 。 请求本身: 它将授权请求转发到用户的钱包, 然后这些钱包会说话 。 直接到商家的核查员那里 助手是纯运输的 从未见过 VC. | 进程 | A2A 角色 | OID4VP 角色 | 端口( S) | |------------------------------------------|-------------------------------------------------------|------------------------------------------------|------------------------------| | 用户 CLI + 钱包 (`src/cli.ts`) | A2A 客户端( 给助手) | 持有者(克里多)——持有预先发行的凭证 | 无(仅限外调用) | | 差旅助理(`src/assistant/`) | A2A 服务器(给 CLI ) + A2A 客户端(给商家) | 无 – 转发请求, 绝不持有 VP | A2A `10004` | | BlueSky 留在商场(`src/merchant/`) | A2A 服务器(给助手) | 验证器( Credo + OID4VP 服务器) | A2A `10003`,核查者 `3001` | ```mermaid sequenceDiagram participant U as User (CLI) participant W as User Wallet (Credo holder, in CLI) participant A as Travel Assistant (A2A client→merchant) participant M as BlueSky Stays (A2A server) participant V as Merchant Verifier (OID4VP, in merchant) U->>A: "Book the Grand Hotel and apply my partner discount" A->>M: A2A task: book stay + apply discount M->>V: build voucher DCQL → createAuthorizationRequest V-->>M: authorizationRequest { client_id, request_uri } M-->>A: status=auth-required (+ authorizationRequest) Note over A: Holder-determination: voucher is the USER's,<br/>assistant holds no wallet → relay verbatim A-->>U: status=auth-required (SAME authorizationRequest) U->>W: pick a voucher, consent to disclose percent_off/expires_at W->>V: GET request_uri → POST vp_token (directly — assistant is blind) V->>V: verify signature + holder binding + nonce,<br/>issuer DID ∈ allowlist?, not expired?, map percent_off V-->>M: approve (out-of-band) M-->>A: status=working → completed (discounted quote) A-->>U: relay working → completed (discounted quote) ``` 中继器 `authorizationRequest`'s `client_id` / `request_uri` 继续指着商人 核查人(`:3001`),所以钱包的演示直接交给商家——确认. 助理对证书视而不见。 ## 证书计划 A `DiscountVoucher` SD - JWT VC,持有者行: ```jsonc { "vct": "DiscountVoucher", "issuer_brand": "Aurora Airlines Rewards", "percent_off": 25, "expires_at": "2027-01-01T00:00:00Z", "voucher_id": "aurora-gold-0001", } ``` 三张券在启动时预先发行到钱包中(发行范围超出扩展范围): | 品牌( 发行者) | 在商家的许可名单上吗? | 贴现 | |-------------------------|------------------------|----------| | 奥罗拉航空公司奖励公司 | ✅ | 25% | | 美利坚银行 | ✅ | 10% | | BargainTrips | ❌ | 50% | **说明**:BargainTrips发行有效,非常慷慨的券——但具体商家与它没有合作关系,为BargainTrips券发行的发行商DID不是VC. 在商家的许可列表中。其结果是,试图为折扣提供BargainTrips凭证的尝试将被拒绝。 商家只要求(通过选择性披露)下列权利要求: ```json { "credentials": [ { "id": "voucher", "format": "vc+sd-jwt", "meta": { "vct_values": ["DiscountVoucher"] }, "claims": [{ "path": ["percent_off"] }, { "path": ["expires_at"] }] } ], "credential_sets": [{ "options": [["voucher"]], "purpose": "Apply partner discount" }] } ``` ## 运行演示 ### 1. 先决条件 - [节点.js](https://nodejs.org/) v18+ - 一个 OpenAI API 密钥 ### 2. 设置 ```bash git clone https://github.com/a2aproject/a2a-samples.git cd a2a-samples/samples/js/extensions/oid4vp-in-task-auth npm install cp .env.example .env # then edit .env and set OPENAI_API_KEY ``` 除此以外 `OPENAI_API_KEY`,聊天模式可以被推翻 `OPENAI_MODEL` (违约情况) `gpt-4o-mini`). 端口、代理 URL 和商家的自动等待超时也都可以配置——看 `.env.example` 用于完整列表和默认值。 ### 3. 启动三个进程(三个终端) ```bash npm run merchant # BlueSky Stays: A2A on :10003, OID4VP verifier on :3001 npm run assistant # Travel Assistant: A2A on :10004 (forwards to the merchant) npm run client # User CLI + wallet (talks to the assistant on :10004) ``` 先发动商人,然后是助手,然后是客户. ### 4. 试试看吧 用户钱包由三个凭证 VC 提供,然后您可以聊天: - **应用有效的折扣** — `Book a deluxe room for 2 nights and apply my partner discount` ——助理转发a. `auth-required`; 选择 **奥罗拉** (25%) 凭单; 确认 ——商家价格(2 × $300)并应用25% − **$450.00**. - **信任失败** - 再问一次,再挑 **BargainTrips** (50%) ——商人. **拒绝** 它( 发件人) 而非伴侣),并引用未贴现的 **$600.00**. - **无折扣( 无认证)** — `Just book me a standard room for Saturday` − 不要求证书 完全没有; **$200.00** (1夜,标准). > **复次流转.** 每一次折扣预订都会触发新的授权,这样你就可以重新运行 > 在同一会话中演示并每次提交不同的凭单——不需要重设(`/new` 刚刚 > 开始新的对话。 示例客户记录 : ```text 👛 Wallet provisioned with 3 discount voucher(s): • Aurora Airlines Rewards: 25% off (expires 2027-01-01T00:00:00Z) • Meridian Bank Travel: 10% off (expires 2027-01-01T00:00:00Z) • BargainTrips: 50% off (expires 2027-01-01T00:00:00Z) ✓ Connected to "Travel Assistant". Type a message. Use '/new' to reset the session, '/exit' to quit. Travel Assistant > You: Book a deluxe room for 2 nights and apply my partner discount Sending message... Travel Assistant [10:15:02 AM]: ⏳ Status: working Part 1: 📝 Text: Forwarding your request to BlueSky Stays on your behalf... Travel Assistant [10:15:02 AM]: ⏳ Status: working Part 1: 📝 Text: Reviewing your booking request... Travel Assistant [10:15:05 AM]: 🔐 Status: auth-required Part 1: 📝 Text: BlueSky Stays needs a partner discount voucher. I don't hold your vouchers, so please present one from your wallet. 🔐 The agent requested a verifiable credential (purpose: "Apply partner discount"). Your wallet holds 3 matching credential(s): [1] Aurora Airlines Rewards — 25% off, expires 2027-01-01T00:00:00Z [2] BargainTrips — 50% off, expires 2027-01-01T00:00:00Z [3] Meridian Bank Travel — 10% off, expires 2027-01-01T00:00:00Z Choose a voucher to present (1-3), or 'n' to decline: 1 Presenting will disclose ONLY: {"percent_off":25,"expires_at":"2027-01-01T00:00:00Z"} (Your identity, voucher id and issuing brand stay private.) Confirm sharing? (yes/no): yes ✓ Presentation sent to the verifier. Travel Assistant [10:15:30 AM]: ⏳ Status: working Part 1: 📝 Text: Preparing your quote... Travel Assistant [10:15:30 AM]: ✅ Status: completed [FINAL] Part 1: 📝 Text: Quote for 2 nights in a deluxe room: $600.00, with your Aurora Airlines Rewards partner discount (25% off) applied -> final price $450.00. --- End of response stream --- ``` ## 免责声明 重要: 提供的样本代码是为了演示目的,并说明了模型的力学。 代理对代理( A2A ) 协议和 OID4VP 任务内授权扩展 。 应用,将任何在您直接控制之外运行的代理视为一种 潜在的不信任实体。 从外部代理人收到的所有数据——包括但不限于其AgentCard,信息, 文物和任务状态——应该作为不可信的输入处理。 能够提供AgentCard包含其领域(如描述、名称、名称、名称、名称、名称、名称、名称、名称、名称、名称、名称、名称、名称、名称、名称、名称、名称、名称、名称、名称、名称、名称、名称、名称、名称、名称、名称、名称、名称、名称、名称、名称、名称、名称、名称、名称、名称、名称、名称、名称、名称、名称、名称、名称、名称、名称、名称、名称、名称、名称、名称、名称、名称、名称、名称、名称、名称、名称、名称、名称、名称、名称、名称、名称、名称、名称、名称、名称、名称、名称、名称、名称、名称、名称、名称、名称、名称、名称、名称、名称、名称、名称、名称、名称、名称、名称、名称、名称、名称、名称、名称、名称、名称、名称、名称、 如果使用此数据时没有进行消毒,则用于构建一个大型的提示。 语言模型(LLM),它可能使您的应用面临迅速注射攻击。 在使用这些数据之前,适当验证和消毒这些数据,可以将安全弱点引入到您 应用。 开发者负责执行适当的安全措施,如输入验证 并妥善处理全权证书,以保护其系统和用户。

查看原始来源