ap2_mandate_verifier 1.2.0 → 1.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.ja.md +15 -10
- data/README.md +15 -10
- data/docs/PUBLIC_API.md +9 -3
- data/docs/RELEASE_120_CANDIDATE.md +2 -0
- data/docs/RELEASE_130_CANDIDATE.md +29 -0
- data/docs/SELECTIVE_CHECKOUT.md +70 -0
- data/docs/SELECTIVE_PAYMENT.md +4 -4
- data/examples/selective_checkout.rb +97 -0
- data/examples/selective_checkout_payment.rb +72 -0
- data/lib/ap2_mandate_verifier/checkout_jwt.rb +1 -1
- data/lib/ap2_mandate_verifier/input_builder.rb +1 -1
- data/lib/ap2_mandate_verifier/payment.rb +10 -4
- data/lib/ap2_mandate_verifier/root_disclosures.rb +8 -0
- data/lib/ap2_mandate_verifier/scoped_constraints.rb +1 -1
- data/lib/ap2_mandate_verifier/selective_checkout.rb +261 -0
- data/lib/ap2_mandate_verifier/selective_payment.rb +5 -3
- data/lib/ap2_mandate_verifier/trust_context.rb +6 -0
- data/lib/ap2_mandate_verifier.rb +1 -0
- metadata +11 -6
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 30a608bea84123fca2724d48ba8b2ee76b00aeeb6013b5b328c6d0a33744bd8f
|
|
4
|
+
data.tar.gz: 60efae2c70da3138cb1046584fa4686353e3b0b92203c38938c9be23c5ae7957
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 120c8702536c4f00245874d2c8f160b3ce8a0b6368fb78564a4d3b65ee29dbce7628ef2cd2463ad11227c9107cca1a79e84d7385b8e6720faa3ee732db9ccdc8
|
|
7
|
+
data.tar.gz: 81a9170e60e911059a6c081c9099229384d6f4b5676246ba375edffa33c784c32bef33a00c0da94fffb631e554016c3efeddc38917817a3bd533aa7bdd6f2adb
|
data/README.ja.md
CHANGED
|
@@ -1,22 +1,27 @@
|
|
|
1
|
-
# AP2 Mandate Verifier — Checkout
|
|
1
|
+
# AP2 Mandate Verifier — Checkout・PaymentのRuby SDK
|
|
2
2
|
|
|
3
|
-
###
|
|
3
|
+
### 1.3.0候補:Checkoutの選択的開示
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
次期候補では、販売者・商品の非選択候補を送らず、全明細の必要数量を検証できます。CheckoutとPaymentの両方を選択的に開示するRuby単体例も用意します。まだ公開していません。[仕様・制限](docs/SELECTIVE_CHECKOUT.md)、[公開前の確認項目](docs/RELEASE_130_CANDIDATE.md)。以下の公開版導入手順は1.2.0です。
|
|
6
6
|
|
|
7
7
|
|
|
8
|
-
### 公開済み1.
|
|
8
|
+
### 公開済み1.2.0:Payment候補の選択的開示
|
|
9
|
+
|
|
10
|
+
公開済み1.2.0の明示的な`SelectivePayment` profileで、支払先・決済手段の非選択候補を送らずに検証できます。必須条件・委任・原文参照は省略しません。[API・プライバシー・Python差分](docs/SELECTIVE_PAYMENT.md)、[保持/送信を比較するRuby単体例](examples/selective_payment.rb)、[公開照合記録](docs/POST_RELEASE_120.md)。既存`Payment`の既定profileは変更しません。
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
### Payment発行・検証(1.1.0から継続)
|
|
9
14
|
|
|
10
15
|
Direct/条件付きPayment Mandateと成功/エラーPayment Receiptを追加しました。[API・制約・信頼境界](docs/PAYMENT.md)、[Ruby単体サンプル](examples/payment.rb)、[公開照合記録](docs/POST_RELEASE_110.md)、[GitHub Release](https://github.com/cuichangquan/ap2-mandate-verifier/releases/tag/v1.1.0)。検証成功は実行許可ではなく、永続的・原子的な単発利用管理と実決済は利用アプリの責任です。
|
|
11
16
|
|
|
12
17
|
```sh
|
|
13
|
-
gem install ap2_mandate_verifier --version 1.
|
|
14
|
-
ruby "$(ruby -e 'puts Gem::Specification.find_by_name("ap2_mandate_verifier", "1.
|
|
18
|
+
gem install ap2_mandate_verifier --version 1.2.0
|
|
19
|
+
ruby "$(ruby -e 'puts Gem::Specification.find_by_name("ap2_mandate_verifier", "1.2.0").full_gem_path')/examples/payment.rb"
|
|
15
20
|
```
|
|
16
21
|
|
|
17
22
|
[English](README.md)
|
|
18
23
|
|
|
19
|
-
**公開済み安定版は1.
|
|
24
|
+
**公開済み安定版は1.2.0です。**
|
|
20
25
|
|
|
21
26
|
1.0.0では、既存のDirectと条件付きCheckoutの公開API・保守契約を確立しました。
|
|
22
27
|
0.8.0の引数・既定値・profile・結果の意味・保存形式と製品実装を維持します。
|
|
@@ -36,8 +41,8 @@ Agent処理へProvider秘密鍵を渡しません。[API・信頼境界](docs/CO
|
|
|
36
41
|
正式対応MRI 3.4.12/4.0.9で動くRuby単体の導入例です。source checkoutやRailsは不要です:
|
|
37
42
|
|
|
38
43
|
```sh
|
|
39
|
-
gem install ap2_mandate_verifier --version 1.
|
|
40
|
-
ruby "$(ruby -e 'puts Gem::Specification.find_by_name("ap2_mandate_verifier", "1.
|
|
44
|
+
gem install ap2_mandate_verifier --version 1.2.0
|
|
45
|
+
ruby "$(ruby -e 'puts Gem::Specification.find_by_name("ap2_mandate_verifier", "1.2.0").full_gem_path')/examples/conditional_checkout.rb"
|
|
41
46
|
```
|
|
42
47
|
|
|
43
48
|
[Ruby単体の実行例](examples/conditional_checkout.rb)はインストール済み公開APIだけを使い、
|
|
@@ -67,7 +72,7 @@ Rubyで購入委任データを検証する、AP2の固定profile向けGemです
|
|
|
67
72
|
正式対応は **MRI 3.4.12とMRI 4.0.9** です。利用者が選ぶGem環境で導入します。
|
|
68
73
|
|
|
69
74
|
```sh
|
|
70
|
-
gem install ap2_mandate_verifier --version 1.
|
|
75
|
+
gem install ap2_mandate_verifier --version 1.2.0
|
|
71
76
|
```
|
|
72
77
|
|
|
73
78
|
BundlerのGemfile:
|
data/README.md
CHANGED
|
@@ -1,22 +1,27 @@
|
|
|
1
|
-
# AP2 Mandate Verifier — Ruby SDK for Checkout
|
|
1
|
+
# AP2 Mandate Verifier — Ruby SDK for Checkout and Payment
|
|
2
2
|
|
|
3
|
-
###
|
|
3
|
+
### 1.3.0 candidate: selective Checkout
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
The next candidate adds merchant and product candidate selection with all required quantities retained, plus a combined selective Checkout/Payment Ruby lifecycle. It is not published yet. [Contract and limitations](docs/SELECTIVE_CHECKOUT.md), [release gates](docs/RELEASE_130_CANDIDATE.md). Published installation instructions below remain on 1.2.0.
|
|
6
6
|
|
|
7
7
|
|
|
8
|
-
###
|
|
8
|
+
### Published1.2.0: selective Payment
|
|
9
|
+
|
|
10
|
+
Published1.2.0 adds explicit `SelectivePayment` candidate-array disclosure: retain confidential full issuance, send selected payee/instrument disclosures only, and verify every mandatory condition and exact original-wire reference. [Profile/API/privacy/Python limits](docs/SELECTIVE_PAYMENT.md), [plain Ruby retained-vs-sent example](examples/selective_payment.rb), [verified publication](docs/POST_RELEASE_120.md). Existing `Payment` defaults remain unchanged.
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
### Payment lifecycle (since1.1.0)
|
|
9
14
|
|
|
10
15
|
1.1.0 adds Direct and conditional Payment Mandates plus signed Success/Error Payment Receipts. [Payment APIs and constraints](docs/PAYMENT.md), [plain Ruby lifecycle sample](examples/payment.rb), [verified publication](docs/POST_RELEASE_110.md), [GitHub Release](https://github.com/cuichangquan/ap2-mandate-verifier/releases/tag/v1.1.0). Verification does not grant execution permission; durable atomic one-use state and actual payment remain application responsibilities.
|
|
11
16
|
|
|
12
17
|
```sh
|
|
13
|
-
gem install ap2_mandate_verifier --version 1.
|
|
14
|
-
ruby "$(ruby -e 'puts Gem::Specification.find_by_name("ap2_mandate_verifier", "1.
|
|
18
|
+
gem install ap2_mandate_verifier --version 1.2.0
|
|
19
|
+
ruby "$(ruby -e 'puts Gem::Specification.find_by_name("ap2_mandate_verifier", "1.2.0").full_gem_path')/examples/payment.rb"
|
|
15
20
|
```
|
|
16
21
|
|
|
17
22
|
[日本語](README.ja.md)
|
|
18
23
|
|
|
19
|
-
**Published stable: 1.
|
|
24
|
+
**Published stable: 1.2.0.**
|
|
20
25
|
|
|
21
26
|
1.0.0 establishes the stable public contract for the existing
|
|
22
27
|
Direct and conditional Checkout APIs. It preserves 0.8.0 signatures, defaults,
|
|
@@ -40,8 +45,8 @@ multi-item profile. Provider private keys never enter Agent operations.
|
|
|
40
45
|
Ruby-only Quick Start on MRI 3.4.12 or 4.0.9; no source checkout or Rails required:
|
|
41
46
|
|
|
42
47
|
```sh
|
|
43
|
-
gem install ap2_mandate_verifier --version 1.
|
|
44
|
-
ruby "$(ruby -e 'puts Gem::Specification.find_by_name("ap2_mandate_verifier", "1.
|
|
48
|
+
gem install ap2_mandate_verifier --version 1.2.0
|
|
49
|
+
ruby "$(ruby -e 'puts Gem::Specification.find_by_name("ap2_mandate_verifier", "1.2.0").full_gem_path')/examples/conditional_checkout.rb"
|
|
45
50
|
```
|
|
46
51
|
|
|
47
52
|
The [standalone Ruby example](examples/conditional_checkout.rb) uses only installed
|
|
@@ -75,7 +80,7 @@ The [Rails demo](https://github.com/cuichangquan/ap2-mandate-verifier-demo#readm
|
|
|
75
80
|
Formal support is **MRI 3.4.12 and MRI 4.0.9**. In your chosen Gem environment:
|
|
76
81
|
|
|
77
82
|
```sh
|
|
78
|
-
gem install ap2_mandate_verifier --version 1.
|
|
83
|
+
gem install ap2_mandate_verifier --version 1.2.0
|
|
79
84
|
```
|
|
80
85
|
|
|
81
86
|
Or add to your Gemfile:
|
data/docs/PUBLIC_API.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Ruby SDK public API — 1.x
|
|
2
2
|
|
|
3
|
-
**Status: published 1.
|
|
3
|
+
**Status: published 1.2.0; the original 1.0.0 Checkout contract below is preserved.**
|
|
4
4
|
This document defines the 1.x contract for the existing Checkout APIs.
|
|
5
5
|
The 1.0.0 release preserves the 0.8.0 runtime behavior, API names and accepted
|
|
6
6
|
formats. Exact distribution identity and validation are in
|
|
@@ -202,6 +202,12 @@ observable error behavior, or the documented profile identities and bounds.
|
|
|
202
202
|
|
|
203
203
|
The preceding 1.0.0 Checkout contract remains unchanged. New `Payment` and `PaymentReceipt` APIs have a separate [Payment contract](PAYMENT.md); they are available in 1.1.0 and later, not in 1.0.0.
|
|
204
204
|
|
|
205
|
-
##
|
|
205
|
+
## Published1.2.0 selective Payment
|
|
206
206
|
|
|
207
|
-
New explicit `SelectivePayment` APIs are described in the [
|
|
207
|
+
New explicit `SelectivePayment` APIs are described in the [selective Payment contract](SELECTIVE_PAYMENT.md). They do not alter the published1.1.0 `Payment` default profile or Receipt reference format. They are available in1.2.0 and later, not in1.1.0.
|
|
208
|
+
|
|
209
|
+
## 1.3.0 candidate: selective Checkout
|
|
210
|
+
|
|
211
|
+
The additive `SelectiveCheckout` profile is included in the 1.3.0 candidate. See the [candidate contract](SELECTIVE_CHECKOUT.md) for mandatory disclosure, independent candidate semantics, original-wire references and application responsibilities. It is not available in the published 1.2.0 package. Existing complete profile defaults are preserved.
|
|
212
|
+
|
|
213
|
+
For the explicit selective Checkout profile, Evidence `original_root_graph_closure` records that every signed commitment and supplied disclosure was inspected and accounted for, allowing unresolved candidate leaves only at registered positions. It does not certify hidden preimages, their schema or uniqueness, or consent provenance. The checked scope covers the visible candidate subset and all mandatory conditions.
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
> Historical preparation snapshot. The exact approved candidate is now published; see [publication evidence](POST_RELEASE_120.md). Earlier approval boundaries below describe that checkpoint.
|
|
2
|
+
|
|
1
3
|
# 1.2.0 candidate — unpublished, Owner decision required
|
|
2
4
|
|
|
3
5
|
Published1.1.0 remains the released SDK. This is preparation for an additive opt-in Payment candidate-disclosure profile. No RubyGems push/yank, formal tag, GitHub Release, announcement or deployment is authorized by this document. The Owner decides final version and publication after reviewing exact source/artifact/verification identity in Issue#238.
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
# 1.3.0 release candidate preparation
|
|
2
|
+
|
|
3
|
+
Status: release candidate prepared; final evidence and GO/HOLD judgment are tracked in [Issue #241](https://github.com/cuichangquan/ap2-mandate-verifier/issues/241). **Publication remains HOLD pending the Owner’s final decision.** RubyGems publication, formal v1.3.0 tag, GitHub Release and announcements require the Owner’s final approval. No production deployment or real payment is included.
|
|
4
|
+
|
|
5
|
+
## Proposed release notes
|
|
6
|
+
|
|
7
|
+
Ruby applications can retain the approved full Checkout Mandate while disclosing only the merchant and products needed for the purchase. Every required line group and quantity remains enforced, including overlapping product choices and multiple purchased lines. The same Ruby lifecycle can combine selective Checkout with selective Payment and authenticate their respective Receipts.
|
|
8
|
+
|
|
9
|
+
Existing complete Checkout and Payment profiles retain their APIs and defaults. The new Checkout profile requires explicit Host trust registration and explicit Payment issuance profile selection. It describes independent merchant/product candidate sets; correlated policies need separate Opens. Counts, ordering and issuer-JWT linkage remain visible. No general AP2 or official high-level Python facade conformance is claimed.
|
|
10
|
+
|
|
11
|
+
## Completion gates
|
|
12
|
+
|
|
13
|
+
- Exact source SHA and independent latest-HEAD review, with no unresolved substantive findings.
|
|
14
|
+
- Signed positive/negative/privacy/quantity coverage and all prior regressions on supported MRI versions.
|
|
15
|
+
- Official pinned Python low-level interoperability with independently checked expectations and explicit high-level limitations.
|
|
16
|
+
- CI on the reviewed HEAD; merged source tree equals reviewed tree.
|
|
17
|
+
- Build one candidate, inspect metadata/allowlist, install the same bytes offline under both supported MRI versions and compare every packaged file with source.
|
|
18
|
+
- Run standalone installed Checkout and combined Payment samples and optional demo.
|
|
19
|
+
- Record exact artifact size, SHA256, source and evidence before Owner GO/HOLD judgment.
|
|
20
|
+
|
|
21
|
+
## Observed local verification
|
|
22
|
+
|
|
23
|
+
The implementation has passed the full source regression suite under MRI 3.4.12 and 4.0.9, including 95 new selective Checkout assertions. An initial candidate passed ordinary offline installation on both versions with all 49 files matching source/archive/installed bytes, plus installed standalone and combined examples. Official pinned Python low-level interoperability passed two scenarios in each direction, eight Receipt checks and 28 negative controls, both from source and an ordinary installed Gem under Ruby 3.4.12 / Python 3.11.2.
|
|
24
|
+
|
|
25
|
+
The fixed candidate builder uses MRI 3.4.12, RubyGems 3.6.9 and `SOURCE_DATE_EPOCH=1793750400`. Two builds under that builder matched byte for byte. MRI 4.0.9’s RubyGems 4.0.20 changes the `rubygems_version` metadata; its payload was identical, but that independently built archive is not the approved candidate. Both supported MRIs must test the same fixed-builder archive. After any packaged source change, rebuild and repeat its package equality checks. Exact final artifact hash, merged source, latest review and CI links belong in the tracking issue/external manifest to avoid a self-referential package checksum.
|
|
26
|
+
|
|
27
|
+
## Publication procedure (not authorized yet)
|
|
28
|
+
|
|
29
|
+
After explicit approval of an exact candidate, recheck registry version absence and the approved artifact bytes/source/reviews/CI. The Owner can perform the single interactive RubyGems push using existing credentials and Docker. Never print credentials or retry an ambiguous push. Read registry metadata and download the published Gem, compare its complete bytes and payload to the approved candidate, then create the matching formal tag and GitHub Release only under the approved publication scope. Update published-state documentation after verification. Stop on any mismatch or uncertain mutation.
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
# Selective Checkout Mandates (1.3.0 candidate)
|
|
2
|
+
|
|
3
|
+
This explicit profile lets an application retain a confidential complete Open Checkout Mandate and send only the merchant and product candidates needed for a purchase. Every requirement and quantity remains visible and enforced. The existing complete Checkout profiles and their defaults remain available.
|
|
4
|
+
|
|
5
|
+
## Approval and disclosure boundary
|
|
6
|
+
|
|
7
|
+
The application authenticates the user, obtains informed approval and stores the complete issuance securely before selecting a presentation. Merchant and per-requirement product lists describe independent allowed sets. They cannot encode “merchant A only sells approved product X, merchant B only approved product Y”, or correlated choices between requirements. Issue separate Opens for correlated policies. Never expand a restricted approval into independent lists.
|
|
8
|
+
|
|
9
|
+
Only the elements of `checkout.allowed_merchants.allowed` and each `checkout.line_items.items[*].acceptable_items` may be omitted. The signed content disclosure, both constraints, every requirement ID and quantity, delegation key and validity interval are mandatory. At least one candidate per requirement must be disclosed. Unresolved commitments in any other location, unknown conditions and unsupported formats fail closed.
|
|
10
|
+
|
|
11
|
+
Keep the complete issuance and its unselected leaf disclosures out of network requests, logs, exception reporting and analytics. Selection is data minimization, not anonymity: the issuer JWT, candidate counts, ordering, mandatory requirements and resulting transaction remain observable. Presentations sharing an issuer JWT can be linked.
|
|
12
|
+
|
|
13
|
+
## Ruby API
|
|
14
|
+
|
|
15
|
+
```ruby
|
|
16
|
+
m = AP2MandateVerifier
|
|
17
|
+
full = m::SelectiveCheckout.issue_open(
|
|
18
|
+
allowed_merchants: approved_merchants, requirements: approved_requirements,
|
|
19
|
+
candidate_policy: :independent,
|
|
20
|
+
agent_public_key_pem: agent_public_pem,
|
|
21
|
+
issued_at: now, expires_at: now + 600,
|
|
22
|
+
signer: provider_signer, public_key_pem: provider_public_pem)
|
|
23
|
+
|
|
24
|
+
# Keep full confidential; original candidate indices are zero based.
|
|
25
|
+
selected = m::SelectiveCheckout.select(
|
|
26
|
+
open_sd_jwt: full.root_presentation,
|
|
27
|
+
merchant_index: 0, item_indices: [[1], [0, 2]])
|
|
28
|
+
# Alternatively, select all approved candidates matching the actual cart IDs,
|
|
29
|
+
# and prove exact quantity coverage before returning the reduced Open:
|
|
30
|
+
selected = m::SelectiveCheckout.select_for_checkout(
|
|
31
|
+
open_sd_jwt: full.root_presentation, checkout: checkout_hash)
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
`candidate_policy: :independent` is an explicit contract, not proof of consent. Supply only independently approved candidate sets from protected application state. `item_indices` contains one nonempty index array for every requirement, in original requirement order. The selection API preserves original signed commitment slots. Its immutable `Open` exposes `root_presentation` and alias `open_sd_jwt`; selecting is structural preparation, not issuer authentication.
|
|
35
|
+
|
|
36
|
+
Use `SelectiveCheckout.issue_closed` with the reduced `root_presentation`, original Merchant `checkout_jwt`, independently selected issuer/Agent/Merchant public keys, expected Merchant ID, audience, nonce, time and Agent signer. Its immutable Closed exposes the existing `root_presentation`, `terminal_jws`, `checkout_jwt` and `closed_sd_jwt` fields. `present` restores those transport fields without claiming verification.
|
|
37
|
+
|
|
38
|
+
Configure `InputBuilder.trust(..., profile_ref: SelectiveCheckout::PROFILE_REF)` using the application’s authenticated registry, then use the existing `InputBuilder.prepare`, `restore`, `inputs` and `verify` lifecycle with the reduced Open. The new profile is `ap2.checkout.selective_candidates.1`; the presentation cannot select trusted policy for the Host. Checkout signing and Receipt APIs accept this explicit `profile_ref`.
|
|
39
|
+
|
|
40
|
+
For Payment, pass `checkout_profile_ref: SelectiveCheckout::PROFILE_REF` explicitly to `Payment.issue_open` or `SelectivePayment.issue_open`, and supply the reduced Checkout Open as `open_checkout_sd_jwt`. The default is unchanged. `SelectivePayment.verify` still takes the seven original Checkout verification inputs and rechecks the full Host-bound chain.
|
|
41
|
+
|
|
42
|
+
Run the installed candidate’s [standalone Checkout example](../examples/selective_checkout.rb) and [combined Checkout/Payment example](../examples/selective_checkout_payment.rb). They generate synthetic keys in memory, compare retained/sent disclosures and authenticate both Success/Error Receipt alternatives without executing a purchase.
|
|
43
|
+
|
|
44
|
+
## Verification and quantities
|
|
45
|
+
|
|
46
|
+
A new registered Host profile must be selected independently from the presentation. Verification follows the existing Host trust, issuer signature, complete commitment graph inspection, Agent key/signature/delegation, audience/nonce/time, Merchant signature and original Checkout binding, constraints and Host order/challenge verification path. A signature or a structurally restored presentation alone is insufficient.
|
|
47
|
+
|
|
48
|
+
For this profile, the existing Evidence field `original_root_graph_closure` means every signed commitment and every supplied disclosure was accounted for, with unresolved leaves allowed only at the registered candidate positions. It does not mean hidden candidate values were reconstructed or validated. A verifier cannot establish the schema, identity or uniqueness of an undisclosed preimage. The issuance API checks the complete approved candidate universe; presentation verification certifies the disclosed subset and every mandatory condition. These facts do not prove the application’s consent provenance.
|
|
49
|
+
|
|
50
|
+
All mandatory quantities participate in integer max-flow matching. Total required quantity must equal total purchased quantity and the maximum assignable flow. Matching uses product IDs; product titles are descriptive, as in the existing multi-item profile. Duplicate line IDs and requirement IDs are rejected. Multiple lines for the same product and overlapping candidate sets are supported. Hidden candidates do not add edges to the quantity graph.
|
|
51
|
+
|
|
52
|
+
The Agent signs the exact reduced Open bytes, including disclosure order and terminal `~`. The Host challenge and Payment reference must bind those same bytes. A confidential complete Open cannot be substituted after selection. Checkout Receipt references remain tied to the exact final Closed wire.
|
|
53
|
+
|
|
54
|
+
## Supported bounds
|
|
55
|
+
|
|
56
|
+
The explicit profile supports at most eight merchant candidates, eight mandatory requirements, eight product candidates per requirement and eight purchased lines. A reduced presentation contains exactly one merchant disclosure and a nonempty subset for every requirement. A complete issuance can contain up to 73 disclosures including its content disclosure. Each encoded disclosure is limited to 8,192 bytes, the compact issuer token to 16,384 bytes and the complete original Open wire to 131,072 bytes. JSON parsing retains the existing bounded depth policy. These are joint limits: long identifiers/values can exhaust a byte budget before a count limit is reached. Issuance checks the final representation before calling a signer.
|
|
57
|
+
|
|
58
|
+
## Compatibility and responsibility
|
|
59
|
+
|
|
60
|
+
Opt in explicitly when issuing a selective Checkout and configuring its Host trust profile. Existing complete profiles retain their missing-disclosure rejection. Existing saved records are not silently migrated. Payment issuance must explicitly identify the new Checkout profile when using its reduced Open; Payment verification still re-verifies the complete Checkout chain with independent Host inputs.
|
|
61
|
+
|
|
62
|
+
Verification establishes scoped checked facts; it does not authorize a purchase, execute payment or establish issuer provenance. The application owns consent, key enrollment/custody, revocation, current order state, atomic nonce consumption, replay prevention and uncertain outcome recovery. Receipt authenticity is distinct from independent settlement confirmation.
|
|
63
|
+
|
|
64
|
+
## Official source and interoperability
|
|
65
|
+
|
|
66
|
+
The adopted AP2 source remains pinned to `b4587ac1d055888a73b4b21750973cffba961793`. [Its Open Checkout Schema](https://github.com/google-agentic-commerce/AP2/blob/b4587ac1d055888a73b4b21750973cffba961793/code/sdk/schemas/ap2/open_checkout_mandate.json) marks merchant and acceptable-item array values as selectively disclosable while retaining mandatory line requirement structure. The explicit registered profile, strict limits and subset acceptance policy are this SDK’s supported contract, not a claim of general AP2 conformance.
|
|
67
|
+
|
|
68
|
+
The pinned Python SDK high-level presentation helper does not expose this candidate selection/profile flow. Interoperability must distinguish official low-level signatures/chain/typed Schema checks from the strict subset adapter. In particular, its max-flow helper may accept an empty candidate list as a wildcard or accept underfilled demand; this SDK requires nonempty disclosed candidates and exact quantity coverage. Official SDK acceptance alone is not a strict quantity oracle.
|
|
69
|
+
|
|
70
|
+
Source interoperability observed two Checkout scenarios in each direction, eight Success/Error Receipt checks and 28 negative controls under Ruby 3.4.12 / Python 3.11.2. The Python terminal adapter uses the official JWT primitive plus an exact reduced-wire `sd_hash`, because the SDK’s generic key-binding creator discloses its final payload while this supported Checkout grammar requires an inline final Closed payload. Source and installed-candidate evidence, final review and CI are recorded separately in the release preparation report; these limited synthetic observations do not establish production trust.
|
data/docs/SELECTIVE_PAYMENT.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
# Payment candidate disclosure —
|
|
1
|
+
# Payment candidate disclosure — published1.2.0 profile
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
[1.2.0 is published](POST_RELEASE_120.md). The1.1.0 complete-content Payment profile remains unchanged. New `AP2MandateVerifier::SelectivePayment` is an explicit opt-in conditional-only profile: `ap2.payment.selective_candidates.1`. Existing `Payment` remains strict and does not accept this new Open format. Existing Checkout/Payment/Receipt keyword/default/result/storage/reference contracts are unchanged. Payment verification/issuance additionally detaches mutable Agent-key inputs consistently and rechecks copied Checkout time; this tightens snapshot safety without changing supported formats or defaults. This is a framework-independent Ruby API; Rails is optional.
|
|
4
4
|
|
|
5
5
|
## Normative source and policy boundary
|
|
6
6
|
|
|
@@ -58,10 +58,10 @@ Official generic crypto verification and Schema validation are not this profile'
|
|
|
58
58
|
|
|
59
59
|
At most8payees/8instruments, one Agent hop, one immediate payment, supported1.1.0 integer minor units/currencies and600-second lifetime. Only known candidate-array disclosures are supported; no generic arbitrary SD or Checkout selective-disclosure extension. Open wire is limited to65,536bytes, root compactJWT to16,384bytes, each decoded disclosure to24,576bytes, and total disclosures to2–17. Each candidate array has1–8entries; selected presentation requires one revealed candidate per selective axis. Existing JSON depth24, finalClosed32,769-byte wire and per-field bounds are reused. All structural/signing bounds are checked before signer effects. Recurrence/budget/PISP/execution_date/risk_data, arbitrary delegation, unsupported algorithms and unknown constraints reject.
|
|
60
60
|
|
|
61
|
-
After installing
|
|
61
|
+
After installing published1.2.0 with its pinned dependencies:
|
|
62
62
|
|
|
63
63
|
```sh
|
|
64
64
|
ruby "$(ruby -e 'puts Gem::Specification.find_by_name("ap2_mandate_verifier", "1.2.0").full_gem_path')/examples/selective_payment.rb"
|
|
65
65
|
```
|
|
66
66
|
|
|
67
|
-
The runnable example prints retained/transmitted disclosure counts and byte counts, confirms unchanged issuer JWT and changed presentation bytes, verifies chosen Payment and both Receipt outcomes without printing unselected values/disclosures. Its approved matrix is explicitly synthetic; real code reads protected consent. The application owns user authentication/consent, key enrollment/custody/revocation, current order/trust, final authorization, payment, durable one-use identity and atomic state transitions. Missing/invalid Receipt or uncertain processing remains pending, never automatic retry permission.
|
|
67
|
+
The runnable example prints retained/transmitted disclosure counts and byte counts, confirms unchanged issuer JWT and changed presentation bytes, verifies chosen Payment and both Receipt outcomes without printing unselected values/disclosures. Its approved matrix is explicitly synthetic; real code reads protected consent. The application owns user authentication/consent, key enrollment/custody/revocation, current order/trust, final authorization, payment, durable one-use identity and atomic state transitions. Missing/invalid Receipt or uncertain processing remains pending, never automatic retry permission. Exact published artifact verification is in [publication evidence](POST_RELEASE_120.md); [release preparation](RELEASE_120_CANDIDATE.md) retains the historical candidate checkpoint.
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
# Ordinary installed Gem only. No test fixtures, source-path loading or network.
|
|
3
|
+
require "ap2_mandate_verifier"
|
|
4
|
+
require "openssl"
|
|
5
|
+
|
|
6
|
+
module SelectiveCheckoutExample
|
|
7
|
+
M = AP2MandateVerifier
|
|
8
|
+
PROFILE = M::SelectiveCheckout::PROFILE_REF
|
|
9
|
+
NOW = 1_800_000_000
|
|
10
|
+
def self.totals(n) = %w[subtotal total].map { |type| {"type" => type, "amount" => n} }
|
|
11
|
+
def self.run
|
|
12
|
+
provider, agent, merchant = Array.new(3) { OpenSSL::PKey::EC.generate("prime256v1") }
|
|
13
|
+
seller = {"id" => "shop", "name" => "Office supplies"}
|
|
14
|
+
# This protected record is created AFTER application authentication, display
|
|
15
|
+
# of these conditions and authority/consent checks. No approved flag is proof.
|
|
16
|
+
requirements = [{"id" => "choice", "quantity" => 1,
|
|
17
|
+
"acceptable_items" => %w[A B].map { |id| {"id" => id, "title" => "Product #{id}"} }},
|
|
18
|
+
{"id" => "required", "quantity" => 2, "acceptable_items" => [{"id" => "C", "title" => "Product C"}]}]
|
|
19
|
+
full = M::SelectiveCheckout.issue_open(allowed_merchants: [seller, {"id" => "private-shop", "name" => "Private alternative merchant"}],
|
|
20
|
+
requirements: requirements, candidate_policy: :independent,
|
|
21
|
+
agent_public_key_pem: agent.public_to_pem, issued_at: NOW, expires_at: NOW + 600,
|
|
22
|
+
signer: M::CheckoutJWT.es256_signer(private_key: provider), public_key_pem: provider.public_to_pem)
|
|
23
|
+
# Store full securely. The complete candidate universe is not sent to the merchant.
|
|
24
|
+
opening = M::SelectiveCheckout.select(open_sd_jwt: full.root_presentation,
|
|
25
|
+
merchant_index: 0, item_indices: [[1], [0]])
|
|
26
|
+
visible = opening.root_presentation.split("~", -1)[1...-1].map do |part|
|
|
27
|
+
JSON.parse(Base64.urlsafe_decode64(part))
|
|
28
|
+
end
|
|
29
|
+
raise "privacy boundary failed" if JSON.generate(visible).include?("private-shop") ||
|
|
30
|
+
visible.any? { |disclosure| disclosure[1] == {"id" => "A", "title" => "Product A"} }
|
|
31
|
+
puts "Checkout retained full disclosures=#{full.root_presentation.count('~') - 1}; sent=#{opening.root_presentation.count('~') - 1}"
|
|
32
|
+
puts "Checkout issuer JWT unchanged=#{full.root_presentation.split('~').first == opening.root_presentation.split('~').first}; unselected candidate values not sent"
|
|
33
|
+
# Merchant Checkout has three rows, including C in two distinct rows.
|
|
34
|
+
lines = %w[B C C].each_with_index.map do |id, i|
|
|
35
|
+
{"id" => "row-#{i}", "item" => {"id" => id, "title" => "Product #{id}", "price" => 100},
|
|
36
|
+
"quantity" => 1, "totals" => totals(100)}
|
|
37
|
+
end
|
|
38
|
+
order = {"id" => "office-1", "merchant" => seller, "status" => "ready_for_complete",
|
|
39
|
+
"currency" => "USD", "line_items" => lines, "totals" => totals(300), "links" => []}
|
|
40
|
+
inferred = M::SelectiveCheckout.select_for_checkout(open_sd_jwt: full.root_presentation, checkout: order)
|
|
41
|
+
raise "selection mismatch" unless inferred.root_presentation == opening.root_presentation
|
|
42
|
+
checkout = M::CheckoutJWT.sign(checkout: order, profile_ref: PROFILE,
|
|
43
|
+
signer: M::CheckoutJWT.es256_signer(private_key: merchant), public_key_pem: merchant.public_to_pem)
|
|
44
|
+
|
|
45
|
+
# Host enrollment and challenge are synthetic authenticated application data.
|
|
46
|
+
roles = %w[Issuer Agent Merchant]
|
|
47
|
+
records = roles.zip([provider, agent, merchant]).map do |role, key|
|
|
48
|
+
{"role" => role, "identity" => role == "Merchant" ? "shop" : role.downcase,
|
|
49
|
+
"tenant_id" => "tenant", "purpose" => "checkout", "key_ref" => role.downcase,
|
|
50
|
+
"public_key_pem" => key.public_to_pem, "active" => true, "not_before" => NOW - 1, "not_after" => NOW + 1000}
|
|
51
|
+
end
|
|
52
|
+
selectors = records.to_h { |record| [record["role"].downcase.to_sym, record.slice("identity", "purpose", "key_ref")] }
|
|
53
|
+
trust = M::InputBuilder.trust(snapshot: {"id" => "registry", "policy_version" => "1", "active" => true,
|
|
54
|
+
"not_before" => NOW - 1, "not_after" => NOW + 1000, "records" => records},
|
|
55
|
+
tenant_id: "tenant", verified_at: NOW, profile_ref: PROFILE, **selectors)
|
|
56
|
+
host_order = {"tenant_id" => "tenant", "buyer_account_id" => "buyer", "order_id" => "office-1",
|
|
57
|
+
"merchant_id" => "shop", "audience" => "merchant-host", "order_version" => "1", "currency" => "USD", "expected_total" => 300}
|
|
58
|
+
host_inputs = {trust: trust, order: host_order, root_presentation: opening.root_presentation, host_checkout_jws: checkout.jwt}
|
|
59
|
+
saved = M::InputBuilder.prepare(**host_inputs, challenge_id: "challenge-1", nonce: "synthetic-one-use-nonce",
|
|
60
|
+
issuer_id: "host", not_before: NOW, not_after: NOW + 60)
|
|
61
|
+
# Agent receives public trust, Open, Checkout, challenge and its own signer.
|
|
62
|
+
# Provider signer/private key is not an input to this operation.
|
|
63
|
+
closed = M::SelectiveCheckout.issue_closed(root_presentation: opening.root_presentation, checkout_jwt: checkout.jwt,
|
|
64
|
+
trusted_issuer_public_key_pem: provider.public_to_pem, agent_public_key_pem: agent.public_to_pem,
|
|
65
|
+
trusted_merchant_public_key_pem: merchant.public_to_pem, expected_merchant_id: "shop",
|
|
66
|
+
audience: "merchant-host", nonce: "synthetic-one-use-nonce", verified_at: NOW,
|
|
67
|
+
signer: M::CheckoutJWT.es256_signer(private_key: agent))
|
|
68
|
+
wire = M::SelectiveCheckout.present(root_presentation: closed.root_presentation,
|
|
69
|
+
terminal_jws: closed.terminal_jws, checkout_jwt: closed.checkout_jwt)
|
|
70
|
+
checked = M::InputBuilder.verify(**host_inputs, terminal_jws: wire.terminal_jws,
|
|
71
|
+
saved_challenge: M::InputBuilder.restore(saved_challenge: saved), expected_challenge_issuer_id: "host",
|
|
72
|
+
clock_source_id: "synthetic-clock", verified_at: NOW)
|
|
73
|
+
raise "verification failed" unless checked.success?
|
|
74
|
+
puts "Open -> Agent Closed -> merchant evidence: verified=true; rows=3; requirements=2"
|
|
75
|
+
# These are ALTERNATIVE synthetic application outcomes, never two executions.
|
|
76
|
+
%w[Success Error].each do |outcome|
|
|
77
|
+
fields = outcome == "Success" ? {order_id: "office-1"} : {error: "policy_rejected", error_description: "Application declined"}
|
|
78
|
+
receipt = M::CheckoutReceipt.sign(closed_sd_jwt: wire.closed_sd_jwt, profile_ref: PROFILE,
|
|
79
|
+
issuer: "shop", outcome: outcome, issued_at: NOW, **fields,
|
|
80
|
+
signer: M::CheckoutJWT.es256_signer(private_key: merchant), public_key_pem: merchant.public_to_pem)
|
|
81
|
+
result = M::CheckoutReceipt.verify(jwt: receipt.jwt, closed_sd_jwt: wire.closed_sd_jwt,
|
|
82
|
+
profile_ref: PROFILE, trusted_public_key_pem: merchant.public_to_pem, expected_issuer: "shop",
|
|
83
|
+
not_before: NOW, not_after: NOW + 60, verified_at: NOW)
|
|
84
|
+
raise "receipt failed" unless result.verified? && result.outcome == outcome
|
|
85
|
+
puts "Receipt #{outcome}: authentic=true; purchase_succeeded=#{result.purchase_succeeded?}"
|
|
86
|
+
end
|
|
87
|
+
# Application state, not an SDK purchase permit: durable transaction/CAS in
|
|
88
|
+
# real code must consume approval/challenge/order once and save its receipt.
|
|
89
|
+
states = {"success" => :consumed, "error" => :requires_new_policy_decision, "missing_receipt" => :pending}
|
|
90
|
+
raise "unknown replay" unless states["missing_receipt"] == :pending
|
|
91
|
+
puts "Success=consumed; Error=policy decision; missing Receipt/uncertain commit=pending"
|
|
92
|
+
puts "Synthetic only; evidence and Receipt authenticity are not payment completion."
|
|
93
|
+
{opening: opening, closed: closed, result: checked, host_inputs: host_inputs, saved: saved,
|
|
94
|
+
keys: [provider, agent, merchant], requirements: requirements, checkout: order}
|
|
95
|
+
end
|
|
96
|
+
end
|
|
97
|
+
SelectiveCheckoutExample.run if $PROGRAM_NAME == __FILE__
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
# Installed SDK only. Confidential issuance stays local; simulated payments only.
|
|
3
|
+
require "ap2_mandate_verifier"
|
|
4
|
+
require_relative "selective_checkout"
|
|
5
|
+
module SelectiveCheckoutPaymentExample
|
|
6
|
+
M = AP2MandateVerifier
|
|
7
|
+
NOW = SelectiveCheckoutExample::NOW
|
|
8
|
+
def self.run
|
|
9
|
+
state = SelectiveCheckoutExample.run
|
|
10
|
+
provider, agent, merchant = state.fetch(:keys)
|
|
11
|
+
signer = ->(key) { M::CheckoutJWT.es256_signer(private_key: key) }
|
|
12
|
+
checkout = state.fetch(:closed).checkout_jwt
|
|
13
|
+
chosen_instrument = {"id" => "synthetic-card-A", "type" => "card"}
|
|
14
|
+
details = M::Payment.details(checkout_jwt: checkout, trusted_merchant_public_key_pem: merchant.public_to_pem,
|
|
15
|
+
expected_merchant_id: "shop", payment_instrument: chosen_instrument)
|
|
16
|
+
payees = [details.fetch("payee"), {"id" => "another-shop", "name" => "Private alternative payee"}]
|
|
17
|
+
instruments = [chosen_instrument, {"id" => "private-alternative-B", "type" => "card"}]
|
|
18
|
+
conditions = [{"type" => "payment.amount_range", "currency" => "USD", "min" => 100, "max" => 300},
|
|
19
|
+
{"type" => "payment.allowed_payees", "allowed" => payees},
|
|
20
|
+
{"type" => "payment.allowed_payment_instruments", "allowed" => instruments}]
|
|
21
|
+
# This list comes from the app's PROTECTED approval record: every crossproduct
|
|
22
|
+
# combination is expressly approved. Do not expand a correlated subset here.
|
|
23
|
+
approved_combinations = [[0, 0], [0, 1], [1, 0], [1, 1]]
|
|
24
|
+
full = M::SelectivePayment.issue_open(open_checkout_sd_jwt: state.fetch(:opening).root_presentation,
|
|
25
|
+
checkout_profile_ref: M::SelectiveCheckout::PROFILE_REF,
|
|
26
|
+
constraints: conditions, fixed: {}, approved_combinations: approved_combinations, selective: :both,
|
|
27
|
+
agent_public_key_pem: agent.public_to_pem, issued_at: NOW, expires_at: NOW+60,
|
|
28
|
+
signer: signer.call(provider), public_key_pem: provider.public_to_pem)
|
|
29
|
+
reduced = M::SelectivePayment.select(open_sd_jwt: full, payee_index: 0, instrument_index: 0)
|
|
30
|
+
transmitted_disclosures = reduced.split("~", -1)[1...-1]
|
|
31
|
+
visible = transmitted_disclosures.map { |wire| JSON.parse(Base64.urlsafe_decode64(wire)) }
|
|
32
|
+
hidden_leaves = full.split("~", -1)[1...-1].select do |wire|
|
|
33
|
+
value = JSON.parse(Base64.urlsafe_decode64(wire))[1]
|
|
34
|
+
value == payees[1] || value == instruments[1]
|
|
35
|
+
end
|
|
36
|
+
raise "privacy boundary failed" unless (hidden_leaves & transmitted_disclosures).empty? &&
|
|
37
|
+
!JSON.generate(visible).include?("Private alternative") && !JSON.generate(visible).include?("private-alternative-B")
|
|
38
|
+
# Keep full confidential issuance in protected storage; send only reduced.
|
|
39
|
+
# No original unselected disclosure or confidential full wire is printed.
|
|
40
|
+
puts "Retained locally: payees=2; instruments=2; disclosures=#{full.count('~')-1}; bytes=#{full.bytesize}"
|
|
41
|
+
puts "Sent: chosen payee=shop; chosen instrument=synthetic-card-A; disclosures=#{reduced.count('~')-1}; bytes=#{reduced.bytesize}"
|
|
42
|
+
puts "Issuer JWT unchanged=#{full.split('~').first == reduced.split('~').first}; presentation bytes changed=#{full != reduced}"
|
|
43
|
+
closed = M::SelectivePayment.issue_closed(open_presentation: reduced, payment: details,
|
|
44
|
+
trusted_provider_public_key_pem: provider.public_to_pem, agent_public_key_pem: agent.public_to_pem,
|
|
45
|
+
audience: "credential-provider", nonce: "synthetic-selective-payment-nonce", verified_at: NOW,
|
|
46
|
+
signer: signer.call(agent))
|
|
47
|
+
restored = M::SelectivePayment.present(open_presentation: reduced, closed_sd_jwt: closed.closed_sd_jwt)
|
|
48
|
+
checkout_inputs = M::InputBuilder.inputs(**state.fetch(:host_inputs), saved_challenge: state.fetch(:saved),
|
|
49
|
+
terminal_jws: state.fetch(:closed).terminal_jws, expected_challenge_issuer_id: "host",
|
|
50
|
+
clock_source_id: "synthetic-clock", verified_at: NOW)
|
|
51
|
+
verified = M::SelectivePayment.verify(open_presentation: restored.open_sd_jwt, closed_sd_jwt: restored.closed_sd_jwt,
|
|
52
|
+
checkout_inputs: checkout_inputs, expected_payment: details, trusted_provider_public_key_pem: provider.public_to_pem,
|
|
53
|
+
expected_agent_public_key_pem: agent.public_to_pem, expected_audience: "credential-provider",
|
|
54
|
+
expected_nonce: "synthetic-selective-payment-nonce", verified_at: NOW)
|
|
55
|
+
raise "selective verification failed" unless verified.verified?
|
|
56
|
+
puts "Selected Payment verified=true; unselected candidate values/disclosures were not sent"
|
|
57
|
+
%w[Success Error].each do |outcome|
|
|
58
|
+
fields = outcome == "Success" ? {psp_confirmation_id: "synthetic-psp", network_confirmation_id: "synthetic-network"} :
|
|
59
|
+
{error: "declined", error_description: "Simulated rejection"}
|
|
60
|
+
receipt = M::PaymentReceipt.sign(closed_sd_jwt: restored.closed_sd_jwt, issuer: "processor",
|
|
61
|
+
payment_id: "synthetic-selective-payment", outcome: outcome, issued_at: NOW, **fields,
|
|
62
|
+
signer: signer.call(merchant), public_key_pem: merchant.public_to_pem)
|
|
63
|
+
checked = M::PaymentReceipt.verify(jwt: receipt.jwt, closed_sd_jwt: restored.closed_sd_jwt,
|
|
64
|
+
trusted_public_key_pem: merchant.public_to_pem, expected_issuer: "processor", expected_payment_id: "synthetic-selective-payment",
|
|
65
|
+
not_before: NOW, not_after: NOW+60, verified_at: NOW)
|
|
66
|
+
raise "receipt failed" unless checked.verified? && checked.outcome == outcome
|
|
67
|
+
puts "Payment Receipt #{outcome}: authentic=#{checked.verified?}; reported_success=#{checked.payment_succeeded?}"
|
|
68
|
+
end
|
|
69
|
+
puts "Synthetic only. Verification is not execution permission; one-use atomic state belongs to the app; unknown outcome remains pending."
|
|
70
|
+
end
|
|
71
|
+
end
|
|
72
|
+
SelectiveCheckoutPaymentExample.run if $PROGRAM_NAME == __FILE__
|
|
@@ -72,7 +72,7 @@ module AP2MandateVerifier
|
|
|
72
72
|
|
|
73
73
|
def self.validate!(checkout, profile_ref: TrustContext::PROFILE_REF)
|
|
74
74
|
profile_ref = InputValidator.snapshot!(profile_ref, max_bytes: 256)
|
|
75
|
-
if
|
|
75
|
+
if [ScopedConstraints::MULTI_PROFILE_REF, TrustContext::SELECTIVE_PROFILE_REF].include?(profile_ref)
|
|
76
76
|
ScopedConstraints.multi_checkout!(checkout)
|
|
77
77
|
return nil
|
|
78
78
|
end
|
|
@@ -113,7 +113,7 @@ module AP2MandateVerifier
|
|
|
113
113
|
value = InputValidator.parse!(wire)
|
|
114
114
|
shape!(value, %w[format_version profile_ref profile_version challenge], "saved_challenge")
|
|
115
115
|
invalid!("saved_challenge", :unsupported_saved_format) unless
|
|
116
|
-
[TrustContext::PROFILE_REF, TrustContext::MULTI_PROFILE_REF].include?(value["profile_ref"])
|
|
116
|
+
[TrustContext::PROFILE_REF, TrustContext::MULTI_PROFILE_REF, TrustContext::SELECTIVE_PROFILE_REF].include?(value["profile_ref"])
|
|
117
117
|
profile = TrustContext.profile!(value["profile_ref"])
|
|
118
118
|
invalid!("saved_challenge", :unsupported_saved_format) unless value.values_at("format_version", "profile_ref", "profile_version") ==
|
|
119
119
|
[FORMAT_VERSION, profile[:ref], profile[:version]]
|
|
@@ -59,9 +59,9 @@ module AP2MandateVerifier
|
|
|
59
59
|
# Reference is calculated over exact original Open Checkout, never rebuilt JSON.
|
|
60
60
|
# The app authenticates consent to these conditions before invoking this API.
|
|
61
61
|
def self.issue_open(open_checkout_sd_jwt:, constraints:, fixed:, agent_public_key_pem:,
|
|
62
|
-
issued_at:, expires_at:, signer:, public_key_pem:)
|
|
62
|
+
issued_at:, expires_at:, signer:, public_key_pem:, checkout_profile_ref: ScopedConstraints::MULTI_PROFILE_REF)
|
|
63
63
|
RootSignature.send(:dependencies!)
|
|
64
|
-
root = checkout_open!(open_checkout_sd_jwt)
|
|
64
|
+
root = checkout_open!(open_checkout_sd_jwt, profile_ref: checkout_profile_ref)
|
|
65
65
|
conditions = InputBuilder.send(:copy!, constraints)
|
|
66
66
|
raise Invalid unless conditions.instance_of?(Array)
|
|
67
67
|
conditions << {"type" => "payment.reference", "conditional_transaction_id" => digest(root)}
|
|
@@ -271,9 +271,15 @@ module AP2MandateVerifier
|
|
|
271
271
|
CheckoutReceipt.send(:epoch!, now)
|
|
272
272
|
raise Invalid unless v.fetch("iat") <= now && now < v.fetch("exp")
|
|
273
273
|
end
|
|
274
|
-
def self.checkout_open!(wire)
|
|
274
|
+
def self.checkout_open!(wire, profile_ref: ScopedConstraints::MULTI_PROFILE_REF)
|
|
275
275
|
wire = InputValidator.snapshot!(wire)
|
|
276
|
-
|
|
276
|
+
profile = InputValidator.snapshot!(profile_ref, max_bytes: 256)
|
|
277
|
+
opening = if profile == TrustContext::SELECTIVE_PROFILE_REF
|
|
278
|
+
SelectiveCheckout.send(:parse!, wire, complete: false).fetch(:opening)
|
|
279
|
+
else
|
|
280
|
+
raise Invalid unless profile == ScopedConstraints::MULTI_PROFILE_REF
|
|
281
|
+
RootDisclosures.send(:structural_root!, wire).fetch("delegate_payload").first
|
|
282
|
+
end
|
|
277
283
|
raise Invalid unless opening.fetch("vct") == "mandate.checkout.open.1"
|
|
278
284
|
wire
|
|
279
285
|
end
|
|
@@ -22,6 +22,14 @@ module AP2MandateVerifier
|
|
|
22
22
|
# Internal handoff only: signature and entire closure are verified first.
|
|
23
23
|
# AP2 semantics, constraints and Host authorization remain unvalidated.
|
|
24
24
|
def self.verified_root!(source, issuer_pem, profile_ref: TrustContext::PROFILE_REF)
|
|
25
|
+
if profile_ref == TrustContext::SELECTIVE_PROFILE_REF
|
|
26
|
+
begin
|
|
27
|
+
parsed = SelectiveCheckout.send(:authenticated!, source, issuer_pem)
|
|
28
|
+
return {"delegate_payload" => [parsed.fetch(:opening)]}
|
|
29
|
+
rescue SelectiveCheckout::Invalid, KeyError
|
|
30
|
+
raise Rejected.new(:unsupported_disclosure_profile), cause: nil
|
|
31
|
+
end
|
|
32
|
+
end
|
|
25
33
|
multi = profile_ref == "ap2.checkout.single_merchant_multi_item"
|
|
26
34
|
raise Rejected, :unsupported_disclosure_profile unless multi || profile_ref == TrustContext::PROFILE_REF
|
|
27
35
|
wire = InputValidator.snapshot!(source)
|
|
@@ -29,7 +29,7 @@ module AP2MandateVerifier
|
|
|
29
29
|
raise RootSignature::Unavailable, :constraint_context_unavailable unless
|
|
30
30
|
CURRENCIES.include?(currency) && CORE_INSTANCE_OF.bind_call(expected_total_minor, Integer) &&
|
|
31
31
|
expected_total_minor.between?(0, MAX_AMOUNT)
|
|
32
|
-
if profile_ref
|
|
32
|
+
if [MULTI_PROFILE_REF, TrustContext::SELECTIVE_PROFILE_REF].include?(profile_ref)
|
|
33
33
|
details = PurchaseBinding.verified_details!(**binding_inputs, profile_ref: profile_ref)
|
|
34
34
|
multi_constraints!(details, currency, expected_total_minor)
|
|
35
35
|
return details
|
|
@@ -0,0 +1,261 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module AP2MandateVerifier
|
|
4
|
+
# Explicit bounded leaf-candidate profile, never a generic SD-JWT resolver.
|
|
5
|
+
module SelectiveCheckout
|
|
6
|
+
PROFILE_REF = "ap2.checkout.selective_candidates.1".freeze
|
|
7
|
+
MAX_DISCLOSURES = 73
|
|
8
|
+
MAX_SEGMENT = 8_192
|
|
9
|
+
class Invalid < ArgumentError
|
|
10
|
+
def initialize = super("invalid selective checkout information")
|
|
11
|
+
end
|
|
12
|
+
class Open
|
|
13
|
+
attr_reader :root_presentation
|
|
14
|
+
alias open_sd_jwt root_presentation
|
|
15
|
+
def initialize(wire)
|
|
16
|
+
@root_presentation = wire.freeze
|
|
17
|
+
freeze
|
|
18
|
+
end
|
|
19
|
+
private_class_method :new
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
# The protected consent must approve independent merchant/product lists.
|
|
23
|
+
# Relationships between lists require separate Open Mandates.
|
|
24
|
+
def self.issue_open(allowed_merchants:, requirements:, candidate_policy:, agent_public_key_pem:,
|
|
25
|
+
issued_at:, expires_at:, signer:, public_key_pem:)
|
|
26
|
+
RootSignature.send(:dependencies!)
|
|
27
|
+
raise Invalid unless candidate_policy == :independent
|
|
28
|
+
agent = InputValidator.snapshot!(agent_public_key_pem, max_bytes: 1_024)
|
|
29
|
+
provider = InputValidator.snapshot!(public_key_pem, max_bytes: 1_024)
|
|
30
|
+
opening = {"vct" => "mandate.checkout.open.1", "iat" => issued_at, "exp" => expires_at,
|
|
31
|
+
"cnf" => {"jwk" => RootSignature.public_jwk!(agent)}, "constraints" => [
|
|
32
|
+
{"type" => "checkout.line_items", "items" => InputBuilder.send(:copy!, requirements)},
|
|
33
|
+
{"type" => "checkout.allowed_merchants", "allowed" => InputBuilder.send(:copy!, allowed_merchants)}]}
|
|
34
|
+
validate_open!(opening, complete: true)
|
|
35
|
+
disclosures = []
|
|
36
|
+
opening["constraints"][0]["items"].each do |group|
|
|
37
|
+
group["acceptable_items"] = group["acceptable_items"].map { |item| disclose!(item, disclosures) }
|
|
38
|
+
end
|
|
39
|
+
opening["constraints"][1]["allowed"] = opening["constraints"][1]["allowed"].map { |m| disclose!(m, disclosures) }
|
|
40
|
+
content = []
|
|
41
|
+
marker = disclose!(opening, content)
|
|
42
|
+
payload = {"ap2_profile" => PROFILE_REF, "_sd_alg" => "sha-256", "delegate_payload" => [marker]}
|
|
43
|
+
preview = [encode({"alg" => "ES256", "typ" => "example+sd-jwt"}), encode(payload), encode("\0" * 64)].join(".")
|
|
44
|
+
parse!(([preview] + content + disclosures + [""]).join("~"), complete: true)
|
|
45
|
+
jwt = MerchantSignature.sign!(payload, signer, provider, typ: "example+sd-jwt")
|
|
46
|
+
Open.send(:new, ([jwt] + content + disclosures + [""]).join("~"))
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
def self.select(open_sd_jwt:, merchant_index:, item_indices:)
|
|
50
|
+
parsed = parse!(open_sd_jwt, complete: true)
|
|
51
|
+
indices = InputBuilder.send(:copy!, item_indices)
|
|
52
|
+
groups = parsed.fetch(:item_slots)
|
|
53
|
+
raise Invalid unless indices.instance_of?(Array) && indices.size == groups.size
|
|
54
|
+
keep = [parsed.fetch(:content_digest), index!(parsed.fetch(:merchant_slots), merchant_index)]
|
|
55
|
+
groups.each_with_index do |slots, i|
|
|
56
|
+
chosen = indices[i]
|
|
57
|
+
raise Invalid unless chosen.instance_of?(Array) && chosen.size.between?(1, slots.size) && chosen.uniq.size == chosen.size
|
|
58
|
+
chosen.each { |n| keep << index!(slots, n) }
|
|
59
|
+
end
|
|
60
|
+
wire = ([parsed.fetch(:compact)] + parsed.fetch(:disclosures).select { |d| keep.include?(digest(d)) } + [""]).join("~")
|
|
61
|
+
parse!(wire, complete: false)
|
|
62
|
+
Open.send(:new, wire)
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
# Preparation from caller-owned checkout data only; not Merchant trust.
|
|
66
|
+
def self.select_for_checkout(open_sd_jwt:, checkout:)
|
|
67
|
+
parsed = parse!(open_sd_jwt, complete: true)
|
|
68
|
+
cart = InputBuilder.send(:copy!, checkout)
|
|
69
|
+
ScopedConstraints.multi_checkout!(cart)
|
|
70
|
+
opening = parsed.fetch(:opening)
|
|
71
|
+
merchants = opening.fetch("constraints")[1].fetch("allowed")
|
|
72
|
+
merchant = merchants.index(cart.fetch("merchant"))
|
|
73
|
+
raise Invalid unless merchant
|
|
74
|
+
ids = cart.fetch("line_items").map { |line| line.fetch("item").fetch("id") }
|
|
75
|
+
indices = opening.fetch("constraints")[0].fetch("items").map do |group|
|
|
76
|
+
group.fetch("acceptable_items").each_index.select { |i| ids.include?(group["acceptable_items"][i]["id"]) }
|
|
77
|
+
end
|
|
78
|
+
selected = select(open_sd_jwt: parsed.fetch(:wire), merchant_index: merchant, item_indices: indices)
|
|
79
|
+
details = {open: parse!(selected.root_presentation, complete: false).fetch(:opening), checkout: cart}
|
|
80
|
+
ScopedConstraints.send(:multi_constraints!, details, cart.fetch("currency"), ScopedConstraints.multi_checkout!(cart))
|
|
81
|
+
selected
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
def self.issue_closed(root_presentation:, checkout_jwt:, trusted_issuer_public_key_pem:,
|
|
85
|
+
agent_public_key_pem:, trusted_merchant_public_key_pem:, expected_merchant_id:,
|
|
86
|
+
audience:, nonce:, verified_at:, signer:)
|
|
87
|
+
provider = InputValidator.snapshot!(trusted_issuer_public_key_pem, max_bytes: 1_024)
|
|
88
|
+
agent = InputValidator.snapshot!(agent_public_key_pem, max_bytes: 1_024)
|
|
89
|
+
merchant = InputValidator.snapshot!(trusted_merchant_public_key_pem, max_bytes: 1_024)
|
|
90
|
+
identity = InputValidator.snapshot!(expected_merchant_id, max_bytes: 256)
|
|
91
|
+
checkout = InputValidator.snapshot!(checkout_jwt, max_bytes: 16_384)
|
|
92
|
+
aud = InputValidator.snapshot!(audience, max_bytes: 512)
|
|
93
|
+
challenge = InputValidator.snapshot!(nonce, max_bytes: 512)
|
|
94
|
+
raise Invalid if aud.empty? || challenge.empty?
|
|
95
|
+
CheckoutReceipt.send(:epoch!, verified_at)
|
|
96
|
+
parsed = authenticated!(root_presentation, provider)
|
|
97
|
+
opening = parsed.fetch(:opening)
|
|
98
|
+
PurchaseBinding.send(:times!, opening, verified_at)
|
|
99
|
+
raise Invalid unless opening["cnf"]["jwk"] == RootSignature.public_jwk!(agent)
|
|
100
|
+
checked = CheckoutJWT.verify(jwt: checkout, trusted_public_key_pem: merchant,
|
|
101
|
+
expected_merchant_id: identity, profile_ref: PROFILE_REF)
|
|
102
|
+
ScopedConstraints.send(:multi_constraints!, {open: opening, checkout: checked.checkout},
|
|
103
|
+
checked.checkout.fetch("currency"), ScopedConstraints.multi_checkout!(checked.checkout))
|
|
104
|
+
closed = {"vct" => "mandate.checkout.1", "iat" => opening.fetch("iat"), "exp" => opening.fetch("exp"),
|
|
105
|
+
"checkout_jwt" => checkout, "checkout_hash" => checked.checkout_hash}
|
|
106
|
+
claims = {"aud" => aud, "nonce" => challenge, "iat" => verified_at,
|
|
107
|
+
"sd_hash" => digest(parsed.fetch(:wire)), "delegate_payload" => [closed]}
|
|
108
|
+
Payment.send(:preflight!, claims, "kb+sd-jwt")
|
|
109
|
+
terminal = MerchantSignature.sign!(claims, signer, agent, typ: "kb+sd-jwt")
|
|
110
|
+
ScopedConstraints.check!(root_presentation: parsed.fetch(:wire), terminal_jws: terminal, host_checkout_jws: checkout,
|
|
111
|
+
trusted_issuer_public_key_pem: provider, expected_agent_public_key_pem: agent,
|
|
112
|
+
trusted_merchant_public_key_pem: merchant, expected_aud: aud, expected_nonce: challenge,
|
|
113
|
+
verified_at: verified_at, expected_checkout_id: checked.checkout.fetch("id"), expected_merchant_id: identity,
|
|
114
|
+
expected_currency: checked.checkout.fetch("currency"), expected_total_minor: ScopedConstraints.multi_checkout!(checked.checkout),
|
|
115
|
+
profile_ref: PROFILE_REF)
|
|
116
|
+
ConditionalCheckout::Closed.send(:new, parsed.fetch(:wire), terminal, checkout)
|
|
117
|
+
end
|
|
118
|
+
|
|
119
|
+
# Transport restoration only; authenticate with the genuine Host inputs.
|
|
120
|
+
def self.present(root_presentation:, terminal_jws:, checkout_jwt:)
|
|
121
|
+
parsed = parse!(root_presentation, complete: false)
|
|
122
|
+
terminal = InputValidator.snapshot!(terminal_jws, max_bytes: 32_768)
|
|
123
|
+
checkout = InputValidator.snapshot!(checkout_jwt, max_bytes: 16_384)
|
|
124
|
+
CheckoutReceipt.reference(closed_sd_jwt: terminal + "~", profile_ref: PROFILE_REF)
|
|
125
|
+
claims = Payment.send(:jwt_payload!, terminal, "kb+sd-jwt")
|
|
126
|
+
closed = claims.fetch("delegate_payload").first
|
|
127
|
+
raise Invalid unless claims["sd_hash"] == digest(parsed.fetch(:wire)) && closed["checkout_jwt"] == checkout &&
|
|
128
|
+
%w[iat exp].all? { |f| closed[f] == parsed.fetch(:opening)[f] }
|
|
129
|
+
ConditionalCheckout::Closed.send(:new, parsed.fetch(:wire), terminal, checkout)
|
|
130
|
+
end
|
|
131
|
+
|
|
132
|
+
def self.authenticated!(source, provider)
|
|
133
|
+
wire, parts = split!(source)
|
|
134
|
+
RootSignature.verified_payload!(parts.first, provider)
|
|
135
|
+
parse!(wire, complete: false)
|
|
136
|
+
end
|
|
137
|
+
|
|
138
|
+
def self.split!(source)
|
|
139
|
+
wire = InputValidator.snapshot!(source)
|
|
140
|
+
raise Invalid unless wire.ascii_only? && wire.end_with?("~")
|
|
141
|
+
parts = wire.split("~", -1)
|
|
142
|
+
raise Invalid unless parts.size.between?(5, MAX_DISCLOSURES + 2) && parts.last == "" && parts[0...-1].none?(&:empty?)
|
|
143
|
+
InputValidator.snapshot!(parts.first, max_bytes: 16_384)
|
|
144
|
+
[wire, parts]
|
|
145
|
+
end
|
|
146
|
+
|
|
147
|
+
def self.parse!(source, complete:)
|
|
148
|
+
RootSignature.send(:dependencies!)
|
|
149
|
+
wire, parts = split!(source)
|
|
150
|
+
claims = Payment.send(:jwt_payload!, parts.first, "example+sd-jwt")
|
|
151
|
+
PurchaseBinding.send(:exact!, claims, %w[ap2_profile _sd_alg delegate_payload])
|
|
152
|
+
raise Invalid unless claims["ap2_profile"] == PROFILE_REF && claims["_sd_alg"] == "sha-256" &&
|
|
153
|
+
claims["delegate_payload"].instance_of?(Array) && claims["delegate_payload"].size == 1
|
|
154
|
+
marker = claims["delegate_payload"].first
|
|
155
|
+
PurchaseBinding.send(:exact!, marker, ["..."])
|
|
156
|
+
hash!(marker["..."])
|
|
157
|
+
values = {}; salts = []
|
|
158
|
+
disclosures = parts[1...-1]
|
|
159
|
+
disclosures.each do |part|
|
|
160
|
+
raise Invalid if part.bytesize > MAX_SEGMENT
|
|
161
|
+
value = Buyer.send(:decode_disclosure!, part, 2)
|
|
162
|
+
hash = digest(part)
|
|
163
|
+
raise Invalid if values.key?(hash) || salts.include?(value[0])
|
|
164
|
+
salts << value[0]; values[hash] = value[1]
|
|
165
|
+
end
|
|
166
|
+
content = marker.fetch("...")
|
|
167
|
+
opening = InputBuilder.send(:copy!, values.fetch(content))
|
|
168
|
+
PurchaseBinding.send(:exact!, opening, %w[cnf constraints exp iat vct])
|
|
169
|
+
cs = opening.fetch("constraints")
|
|
170
|
+
raise Invalid unless cs.instance_of?(Array) && cs.size == 2
|
|
171
|
+
PurchaseBinding.send(:exact!, cs[0], %w[type items])
|
|
172
|
+
PurchaseBinding.send(:exact!, cs[1], %w[type allowed])
|
|
173
|
+
raise Invalid unless cs[0]["type"] == "checkout.line_items" && cs[1]["type"] == "checkout.allowed_merchants"
|
|
174
|
+
groups = cs[0]["items"]
|
|
175
|
+
raise Invalid unless groups.instance_of?(Array) && groups.size.between?(1, 8)
|
|
176
|
+
commitments = [content]; used = [content]
|
|
177
|
+
item_slots = groups.map do |group|
|
|
178
|
+
PurchaseBinding.send(:exact!, group, %w[id quantity acceptable_items])
|
|
179
|
+
resolve_list!(group, "acceptable_items", values, commitments, used, complete, false)
|
|
180
|
+
end
|
|
181
|
+
merchant_slots = resolve_list!(cs[1], "allowed", values, commitments, used, complete, true)
|
|
182
|
+
raise Invalid unless used.sort == values.keys.sort
|
|
183
|
+
validate_open!(opening, complete: complete)
|
|
184
|
+
{wire: wire, compact: parts.first, disclosures: disclosures, content_digest: content,
|
|
185
|
+
opening: opening, item_slots: item_slots, merchant_slots: merchant_slots}
|
|
186
|
+
end
|
|
187
|
+
|
|
188
|
+
def self.resolve_list!(owner, field, values, commitments, used, complete, merchant)
|
|
189
|
+
list = owner.fetch(field)
|
|
190
|
+
raise Invalid unless list.instance_of?(Array) && list.size.between?(1, 8)
|
|
191
|
+
selected = []
|
|
192
|
+
slots = list.map do |marker|
|
|
193
|
+
PurchaseBinding.send(:exact!, marker, ["..."])
|
|
194
|
+
h = marker.fetch("..."); hash!(h)
|
|
195
|
+
raise Invalid if commitments.include?(h)
|
|
196
|
+
commitments << h
|
|
197
|
+
if values.key?(h)
|
|
198
|
+
selected << values.fetch(h); used << h
|
|
199
|
+
elsif complete
|
|
200
|
+
raise Invalid
|
|
201
|
+
end
|
|
202
|
+
h
|
|
203
|
+
end
|
|
204
|
+
raise Invalid unless selected.size.between?(1, merchant && !complete ? 1 : 8)
|
|
205
|
+
owner[field] = selected
|
|
206
|
+
slots
|
|
207
|
+
end
|
|
208
|
+
|
|
209
|
+
def self.validate_open!(opening, complete:)
|
|
210
|
+
PurchaseBinding.send(:exact!, opening, %w[cnf constraints exp iat vct])
|
|
211
|
+
raise Invalid unless opening["vct"] == "mandate.checkout.open.1"
|
|
212
|
+
PurchaseBinding.send(:times!, opening, opening["iat"])
|
|
213
|
+
PurchaseBinding.send(:exact!, opening["cnf"], ["jwk"])
|
|
214
|
+
jwk = opening["cnf"]["jwk"]
|
|
215
|
+
PurchaseBinding.send(:exact!, jwk, %w[kty crv x y])
|
|
216
|
+
raise Invalid unless jwk["kty"] == "EC" && jwk["crv"] == "P-256" &&
|
|
217
|
+
%w[x y].all? { |f| RootSignature.send(:decode!, jwk[f], 32).bytesize == 32 }
|
|
218
|
+
cs = opening["constraints"]
|
|
219
|
+
raise Invalid unless cs.instance_of?(Array) && cs.size == 2
|
|
220
|
+
PurchaseBinding.send(:exact!, cs[1], %w[type allowed])
|
|
221
|
+
raise Invalid unless cs[1]["type"] == "checkout.allowed_merchants"
|
|
222
|
+
merchants = cs[1]["allowed"]
|
|
223
|
+
raise Invalid unless merchants.instance_of?(Array) && merchants.size.between?(1, complete ? 8 : 1)
|
|
224
|
+
ScopedConstraints.send(:unique_ids!, merchants)
|
|
225
|
+
merchants.each do |m|
|
|
226
|
+
PurchaseBinding.send(:exact!, m, %w[id name]); ScopedConstraints.send(:text!, m["name"], 512)
|
|
227
|
+
end
|
|
228
|
+
# Reuse the reviewed multi-item grammar with each approved merchant.
|
|
229
|
+
merchants.each do |m|
|
|
230
|
+
ScopedConstraints.send(:multi_open!, [cs[0], {"type" => "checkout.allowed_merchants", "allowed" => [m]}])
|
|
231
|
+
end
|
|
232
|
+
end
|
|
233
|
+
def self.index!(slots, n)
|
|
234
|
+
raise Invalid unless Object.instance_method(:instance_of?).bind_call(n, Integer) && n.between?(0, slots.size - 1)
|
|
235
|
+
slots.fetch(n)
|
|
236
|
+
end
|
|
237
|
+
def self.hash!(h)
|
|
238
|
+
raise Invalid unless h.instance_of?(String) && h.match?(/\A[A-Za-z0-9_-]{43}\z/) && RootSignature.send(:decode!, h, 32).bytesize == 32
|
|
239
|
+
end
|
|
240
|
+
def self.disclose!(value, disclosures)
|
|
241
|
+
require "securerandom"
|
|
242
|
+
part = encode([encode(SecureRandom.random_bytes(16)), value])
|
|
243
|
+
disclosures << part
|
|
244
|
+
{"..." => digest(part)}
|
|
245
|
+
end
|
|
246
|
+
def self.encode(value) = Buyer.send(:encode, value)
|
|
247
|
+
def self.digest(value) = Payment.send(:digest, value)
|
|
248
|
+
|
|
249
|
+
%i[issue_open select select_for_checkout issue_closed present].each do |name|
|
|
250
|
+
implementation = method(name)
|
|
251
|
+
fields = implementation.parameters.map(&:last).freeze
|
|
252
|
+
define_singleton_method(name) do |**args|
|
|
253
|
+
raise Invalid unless (fields - args.keys).empty? && (args.keys - fields).empty?
|
|
254
|
+
implementation.call(**args)
|
|
255
|
+
rescue StandardError, LoadError
|
|
256
|
+
raise Invalid.new, cause: nil
|
|
257
|
+
end
|
|
258
|
+
end
|
|
259
|
+
singleton_methods(false).reject { |n| %i[issue_open select select_for_checkout issue_closed present].include?(n) }.each { |n| private_class_method n }
|
|
260
|
+
end
|
|
261
|
+
end
|
|
@@ -15,10 +15,11 @@ module AP2MandateVerifier
|
|
|
15
15
|
# All candidates and their exact Cartesian authorization come from a
|
|
16
16
|
# protected approval record. This confidential issuance MUST NOT be sent.
|
|
17
17
|
def self.issue_open(open_checkout_sd_jwt:, constraints:, fixed:, approved_combinations:, selective:,
|
|
18
|
-
agent_public_key_pem:, issued_at:, expires_at:, signer:, public_key_pem
|
|
18
|
+
agent_public_key_pem:, issued_at:, expires_at:, signer:, public_key_pem:,
|
|
19
|
+
checkout_profile_ref: ScopedConstraints::MULTI_PROFILE_REF)
|
|
19
20
|
RootSignature.send(:dependencies!)
|
|
20
21
|
raise Invalid unless %i[payees instruments both].include?(selective)
|
|
21
|
-
checkout = Payment.send(:checkout_open!, open_checkout_sd_jwt)
|
|
22
|
+
checkout = Payment.send(:checkout_open!, open_checkout_sd_jwt, profile_ref: checkout_profile_ref)
|
|
22
23
|
cs = InputBuilder.send(:copy!, constraints)
|
|
23
24
|
raise Invalid unless cs.instance_of?(Array)
|
|
24
25
|
cs << {"type" => "payment.reference", "conditional_transaction_id" => digest(checkout)}
|
|
@@ -242,9 +243,10 @@ module AP2MandateVerifier
|
|
|
242
243
|
|
|
243
244
|
%i[issue_open select issue_closed present verify].each do |name|
|
|
244
245
|
implementation = method(name)
|
|
246
|
+
required = implementation.parameters.filter_map { |kind, field| field if kind == :keyreq }.freeze
|
|
245
247
|
fields = implementation.parameters.map(&:last).freeze
|
|
246
248
|
define_singleton_method(name) do |**args|
|
|
247
|
-
unless (
|
|
249
|
+
unless (required - args.keys).empty? && (args.keys - fields).empty?
|
|
248
250
|
next Payment::Verification.send(:new) if name == :verify
|
|
249
251
|
raise Invalid
|
|
250
252
|
end
|
|
@@ -12,6 +12,10 @@ module AP2MandateVerifier
|
|
|
12
12
|
MULTI_PROFILE_VERSION = "1"
|
|
13
13
|
MULTI_PROFILE_BODY = '{"profile_ref":"ap2.checkout.single_merchant_multi_item","version":"1","ap2_source":"b4587ac1d055888a73b4b21750973cffba961793","algorithm":"ES256","key_format":"canonical-public-SPKI-P256-SHA256","root_type":"example+sd-jwt","terminal_type":"kb+sd-jwt","checkout_type":"JWT","disclosure_path_semantics":"root-walker-with-synthetic-disclosed-edges","disclosure_positions":["delegate_payload[0]","delegate_payload[0].disclosed.constraints[0].items[*].acceptable_items[*]","delegate_payload[0].disclosed.constraints[1].allowed[0]"],"constraints":["checkout.line_items","checkout.allowed_merchants"],"max_disclosures":66,"max_disclosure_segment_bytes":8192,"max_root_bytes":131072,"max_graph_nodes":2048,"max_graph_depth":24,"max_array_entries":16,"max_line_items":8,"max_requirements":8,"max_candidates_per_requirement":8,"quantity_matching":"integer-max-flow-product-id-exact-coverage","duplicate_line_ids":"reject","duplicate_requirement_ids":"reject","same_product_multiple_lines":"allow","amount_model":"integer-minor-unit-no-tax-shipping-discount"}'.freeze
|
|
14
14
|
MULTI_PROFILE_HASH = Digest::SHA256.hexdigest(MULTI_PROFILE_BODY).freeze
|
|
15
|
+
SELECTIVE_PROFILE_REF = "ap2.checkout.selective_candidates.1".freeze
|
|
16
|
+
SELECTIVE_PROFILE_VERSION = "1".freeze
|
|
17
|
+
SELECTIVE_PROFILE_BODY = '{"profile_ref":"ap2.checkout.selective_candidates.1","version":"1","ap2_source":"b4587ac1d055888a73b4b21750973cffba961793","algorithm":"ES256","root_type":"example+sd-jwt","terminal_type":"kb+sd-jwt","checkout_type":"JWT","signed_profile_marker":"ap2_profile","mandatory_content":"all-requirements-id-quantity-cnf-iat-exp","selective_positions":["constraints[0].items[*].acceptable_items[*]","constraints[1].allowed[*]"],"max_disclosures":73,"max_disclosure_segment_bytes":8192,"max_root_bytes":131072,"max_requirements":8,"max_candidates_per_requirement":8,"max_merchants":8,"merchant_selection":"exactly-one","item_selection":"nonempty-subset-per-requirement","candidate_policy":"independent-lists-no-correlation","quantity_matching":"integer-max-flow-product-id-exact-coverage","amount_model":"integer-minor-unit-no-tax-shipping-discount"}'.freeze
|
|
18
|
+
SELECTIVE_PROFILE_HASH = Digest::SHA256.hexdigest(SELECTIVE_PROFILE_BODY).freeze
|
|
15
19
|
|
|
16
20
|
# Explicit Host policy registration. Signed token claims never select this.
|
|
17
21
|
def self.profile!(reference)
|
|
@@ -20,6 +24,8 @@ module AP2MandateVerifier
|
|
|
20
24
|
{ref: PROFILE_REF, version: PROFILE_VERSION, body: PROFILE_BODY, hash: PROFILE_HASH}.freeze
|
|
21
25
|
when MULTI_PROFILE_REF
|
|
22
26
|
{ref: MULTI_PROFILE_REF, version: MULTI_PROFILE_VERSION, body: MULTI_PROFILE_BODY, hash: MULTI_PROFILE_HASH}.freeze
|
|
27
|
+
when SELECTIVE_PROFILE_REF
|
|
28
|
+
{ref: SELECTIVE_PROFILE_REF, version: SELECTIVE_PROFILE_VERSION, body: SELECTIVE_PROFILE_BODY, hash: SELECTIVE_PROFILE_HASH}.freeze
|
|
23
29
|
else
|
|
24
30
|
reject!(:unsupported_trust_profile)
|
|
25
31
|
end
|
data/lib/ap2_mandate_verifier.rb
CHANGED
|
@@ -18,6 +18,7 @@ require_relative "ap2_mandate_verifier/conditional_checkout"
|
|
|
18
18
|
require_relative "ap2_mandate_verifier/payment"
|
|
19
19
|
require_relative "ap2_mandate_verifier/payment_receipt"
|
|
20
20
|
require_relative "ap2_mandate_verifier/selective_payment"
|
|
21
|
+
require_relative "ap2_mandate_verifier/selective_checkout"
|
|
21
22
|
|
|
22
23
|
module AP2MandateVerifier
|
|
23
24
|
# Accepts original JSON bytes only. Syntax validity is not AP2 validity,
|
metadata
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: ap2_mandate_verifier
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.
|
|
4
|
+
version: 1.3.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- AP2 Mandate Verifier contributors
|
|
8
8
|
bindir: bin
|
|
9
9
|
cert_chain: []
|
|
10
|
-
date:
|
|
10
|
+
date: 2026-11-04 00:00:00.000000000 Z
|
|
11
11
|
dependencies:
|
|
12
12
|
- !ruby/object:Gem::Dependency
|
|
13
13
|
name: json
|
|
@@ -82,9 +82,9 @@ dependencies:
|
|
|
82
82
|
description: 'Framework-independent Ruby SDK for supported AP2 Checkout profiles:
|
|
83
83
|
Merchant JWT signing, Direct and conditional Mandate issuance and presentation,
|
|
84
84
|
full verification with immutable Evidence, Checkout Receipts, Direct and conditional
|
|
85
|
-
Payment Mandates, and Payment Receipts. Adds opt-in selective Payment
|
|
86
|
-
disclosure. Requires independently trusted application inputs; verification
|
|
87
|
-
not grant purchase or payment permission.'
|
|
85
|
+
Payment Mandates, and Payment Receipts. Adds opt-in selective Checkout and Payment
|
|
86
|
+
candidate disclosure. Requires independently trusted application inputs; verification
|
|
87
|
+
does not grant purchase or payment permission.'
|
|
88
88
|
executables: []
|
|
89
89
|
extensions: []
|
|
90
90
|
extra_rdoc_files: []
|
|
@@ -107,11 +107,15 @@ files:
|
|
|
107
107
|
- docs/RELEASE_100_CANDIDATE.md
|
|
108
108
|
- docs/RELEASE_110_CANDIDATE.md
|
|
109
109
|
- docs/RELEASE_120_CANDIDATE.md
|
|
110
|
+
- docs/RELEASE_130_CANDIDATE.md
|
|
111
|
+
- docs/SELECTIVE_CHECKOUT.md
|
|
110
112
|
- docs/SELECTIVE_PAYMENT.md
|
|
111
113
|
- docs/SUPPORT_CONTRACT.md
|
|
112
114
|
- docs/evidence/1.1.0_publication.json
|
|
113
115
|
- examples/conditional_checkout.rb
|
|
114
116
|
- examples/payment.rb
|
|
117
|
+
- examples/selective_checkout.rb
|
|
118
|
+
- examples/selective_checkout_payment.rb
|
|
115
119
|
- examples/selective_payment.rb
|
|
116
120
|
- lib/ap2_mandate_verifier.rb
|
|
117
121
|
- lib/ap2_mandate_verifier/buyer.rb
|
|
@@ -131,6 +135,7 @@ files:
|
|
|
131
135
|
- lib/ap2_mandate_verifier/root_disclosures.rb
|
|
132
136
|
- lib/ap2_mandate_verifier/root_signature.rb
|
|
133
137
|
- lib/ap2_mandate_verifier/scoped_constraints.rb
|
|
138
|
+
- lib/ap2_mandate_verifier/selective_checkout.rb
|
|
134
139
|
- lib/ap2_mandate_verifier/selective_payment.rb
|
|
135
140
|
- lib/ap2_mandate_verifier/trust_context.rb
|
|
136
141
|
homepage: https://github.com/cuichangquan/ap2-mandate-verifier
|
|
@@ -154,7 +159,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
154
159
|
- !ruby/object:Gem::Version
|
|
155
160
|
version: '0'
|
|
156
161
|
requirements: []
|
|
157
|
-
rubygems_version:
|
|
162
|
+
rubygems_version: 3.6.9
|
|
158
163
|
specification_version: 4
|
|
159
164
|
summary: Ruby SDK for supported AP2 Checkout and Payment Mandates
|
|
160
165
|
test_files: []
|