Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .cspell/custom-words.txt
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,8 @@ ropeproject
RPCURL
Rulebook
screenreaders
SDJWT
SECP
setlocal
sharedpref
Shopcider
Expand Down
16 changes: 14 additions & 2 deletions .github/workflows/linter.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,30 @@ on:
pull_request:
branches: [main]

permissions: {}

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
build:
name: Lint Code Base
runs-on: ubuntu-latest
permissions:
contents: read # Required to check out repository contents
packages: read # Required to pull container image
statuses: write # Required to post linter commit statuses

steps:
- name: Checkout Code
uses: actions/checkout@v5
uses: actions/checkout@fbc6f3992d24b796d5a048ff273f7fcc4a7b6c09 # v5.1.0
with:
fetch-depth: 0
persist-credentials: false

- name: Lint Code Base
uses: super-linter/super-linter/slim@v8
uses: super-linter/super-linter/slim@4ce20838b8ab83717e78138c5b3a1407148e0918 # v8.7.0
env:
DEFAULT_BRANCH: main
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Expand All @@ -25,6 +36,7 @@ jobs:
VALIDATE_ALL_CODEBASE: false
FILTER_REGEX_EXCLUDE: "^(\\.github/|\\.vscode/|code/samples/).*|CODE_OF_CONDUCT.md|CHANGELOG.md"
VALIDATE_BIOME_FORMAT: false
VALIDATE_BIOME_LINT: false
VALIDATE_PYTHON_BLACK: false
VALIDATE_PYTHON_FLAKE8: false
VALIDATE_PYTHON_ISORT: false
Expand Down
2 changes: 1 addition & 1 deletion code/sdk/python/ap2/sdk/sdjwt/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ def delegate_claims_from_model(payload: BaseModel) -> dict[str, Any]:
"""Serialize a Pydantic payload into AP2 delegate claims."""
if not isinstance(payload, BaseModel):
raise TypeError('payload must be an instance of pydantic.BaseModel')
return payload.model_dump(by_alias=True, exclude_none=True)
return payload.model_dump(by_alias=True, exclude_none=True, mode='json')


def selectively_disclosable_claims(
Expand Down
24 changes: 24 additions & 0 deletions code/sdk/python/ap2/tests/agent_recurrence_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
from ap2.sdk.generated.types.jwk import JsonWebKey
from ap2.sdk.generated.types.merchant import Merchant
from ap2.sdk.generated.types.payment_instrument import PaymentInstrument
from ap2.sdk.mandate import MandateClient
from ap2.sdk.utils import ec_key_to_jwk
from cryptography.hazmat.primitives.asymmetric import ec

Expand Down Expand Up @@ -178,3 +179,26 @@ def test_payment_agent_recurrence_missing_context():
'Missing mandate context required to evaluate recurrence' in v
for v in violations
)


def test_open_payment_mandate_agent_recurrence_can_be_signed(issuer_key):
"""OpenPaymentMandate carrying AgentRecurrence signs and verifies."""
mandate = _open_payment(
constraints=[
AgentRecurrence(frequency=Frequency.DAILY, max_occurrences=2),
AmountRange(min=100, max=2000, currency='USD'),
Budget(max=5000, currency='USD'),
]
)
client = MandateClient()
token = client.create(payloads=[mandate], issuer_key=issuer_key)
assert token
res = client.verify(
token, key_or_provider=issuer_key, payload_type=OpenPaymentMandate
)
assert res.is_valid
assert len(res.mandate_payload.constraints) == 3
recurrence = res.mandate_payload.constraints[0]
assert isinstance(recurrence, AgentRecurrence)
assert recurrence.frequency == Frequency.DAILY
assert recurrence.max_occurrences == 2
Loading