Skip to content

Authenticate machines (Service VC / Stage 4 prep)

Covers the M2M (machine-to-machine) case where a service (a program), not a person, holds a VC and writes continuously.

What you'll do: Authorize continuous writes from a service that holds a ServiceVC

Prerequisites: Authenticate the data provider (Consent VC / Stage 1) and Authenticate the viewer (Viewer VC / Stage 3)

Keep running: the publisher started in 2.2 and 2.3 (ssi-wallet profile). If you stopped it, step 1 starts it. Keep the Quickstart IPFS stopped (it shares port 8080)

What you need: PC + smartphone (iw3ip-wallet)

Time required: approx. 45 min

Where this page belongs

Choosing a dataset

The example uses home/env/temperature, but the same steps work with home/event/possible_littering (the same as Stage 0; service-possible-littering.json is already registered).

Goal

ConsentVC's PolicyToken is 5 min, single-use — designed for a human consenting to one share at a time. But a continuous publisher (MQTT-driven) can't tolerate re-presentation per event.

ServiceVC encodes "this service may write continuously," and presentation yields a ServiceToken valid for 1 hour that can be used any number of times within the TTL. A publisher process holds this token and attaches it as Bearer to every /platform/ingest call.

sequenceDiagram
  participant S as service
  participant V as Verifier
  participant P as Publisher
  S->>V: ServiceVC presentation (once)
  V-->>S: ServiceToken (1h, reusable)
  S->>P: POST /platform/ingest x N
  Note over P: authz via ServiceToken

What this page covers

  • Why "human VC (ConsentVC)" and "service VC (ServiceVC)" are split
  • The three token shapes: single-use write, repeated reads, repeated continuous writes
  • ServiceToken's 1-hour TTL with write_count accumulation
  • How /platform/ingest accepts both PolicyToken and ServiceToken (PolicyToken first, fall through to ServiceToken on "unknown")

The diagram below shows the order in which /platform/ingest checks a Bearer token.

flowchart TB
  REQ["POST /platform/ingest<br>Authorization: Bearer token"]
  Q1{"Is it a known<br>PolicyToken?"}
  QP{"Not expired, unused,<br>and dataset_id matches?"}
  OKP["Accept<br>token becomes consumed"]
  Q2{"Is it a known<br>ServiceToken?"}
  QS{"Not expired (1 hour)<br>and dataset_id matches?"}
  OKS["Accept<br>write_count += 1"]
  NGP["Reject<br>policy_token_...<br>(unknown tokens end here)"]
  NGS["Reject<br>service_token_expired, etc."]
  REQ --> Q1
  Q1 -->|"yes"| QP
  QP -->|"yes"| OKP
  QP -->|"no"| NGP
  Q1 -->|"no"| Q2
  Q2 -->|"yes"| QS
  Q2 -->|"no"| NGP
  QS -->|"yes"| OKS
  QS -->|"no"| NGS
  classDef allow fill:#e3f4e1,stroke:#2e7d32,color:#1b5e20
  classDef deny fill:#fde2e2,stroke:#c0392b,color:#7b241c
  class OKP,OKS allow
  class NGP,NGS deny

Every accepted or rejected request adds one line to the audit log. A PolicyToken is consumed after one use, while a ServiceToken passes any number of times within its TTL and increments write_count each time.

Common issues

  • ConsentVC / ViewerVC / ServiceVC are distinct; cross-use is denied
  • ServiceToken differs from ViewerToken in TTL and target endpoint; it works only on /platform/ingest (the read side /platform/data takes ViewerToken only)
  • ServiceVC is M2M-oriented. It can be held in a phone wallet for experimentation, but properly belongs to a holder embedded in the publisher

Required environment

  • Completed Authenticate the data provider (Consent VC / Stage 1)
  • Publisher running from the main branch
  • iw3ip-wallet available on the phone (used in §2 and §3 to receive and present the ServiceVC)
  • $HOST_IP in commands and <HOST_IP> in URLs stand for the PC's LAN IP. In each terminal you use, first run export HOST_IP='<your PC LAN IP>' (see the Hands-on for how to find it). Replace <HOST_IP> in URLs you type into a browser or phone with the same IP

1. Start and inspect metadata

cd ~/program/Blockchain_IoT_Marketplace
docker compose -f infra/docker-compose.yml --profile ssi-wallet up --build -d

# Confirm ServiceVC is registered. The current release has 6 VC types:
# ConsentVC / ViewerVC / ServiceVC / DataUserVC / SellerVC / PurchaseViewerVC.
# PurchaseViewerVC also has tier entries .full / .access / .event, so 9 entries in total
curl -s http://$HOST_IP:8080/.well-known/openid-credential-issuer | python3 -m json.tool | grep -A2 ServiceVC

Expected: "vct": "https://iw3ip.example/credentials/ServiceVC/v1" appears.

2. Issue a ServiceVC (substitute = phone wallet)

Production would issue to a publisher-embedded holder. For the hands-on, the phone wallet is easiest. Open in a PC browser:

http://<HOST_IP>:8080/issuer/offer?type=ServiceVC&dataset_id=home/env/temperature&purpose=write_continuous

Open the displayed QR code (or deeplink) in the phone wallet and store the credential.

Claims:

  • dataset_id: home/env/temperature
  • allowed_actions: ["write_continuous"]

3. Present the ServiceVC

http://<HOST_IP>:8080/verifier/request?dataset_id=home/env/temperature&vc_kind=ServiceVC

vc_kind=ServiceVC is required; without it the ConsentVC PD is selected.

After presenting, check the publisher log.

cd ~/program/Blockchain_IoT_Marketplace
docker compose -f infra/docker-compose.yml logs publisher 2>&1 | grep service_token_issued | tail -n 1

Each log line is JSON, and its "message" holds:

service_token_issued jti=... token=... dataset=home/env/temperature ttl=3600s

token=... is the ServiceToken.

4. Continuous ingest with ServiceToken

SERVICE='<service_token>'

for i in 1 2 3 4 5; do
  curl -s -X POST http://$HOST_IP:8080/platform/ingest \
    -H "Authorization: Bearer $SERVICE" \
    -H "Content-Type: application/json" \
    -d "{\"dataset_id\":\"home/env/temperature\",\"value\":$((20 + i))}"
  echo
done

Expected: all 5 return {"status":"received","count":N} (N is the number of rows ingested since the publisher started, and grows by one each time).

Unlike PolicyToken, the second call doesn't trigger 403 policy_token_already_consumed.

5. Inspect write_count in the audit log

curl -s "http://$HOST_IP:8080/audit/logs?limit=5" | python3 -m json.tool

The result is a list, newest first, with one row per ingest. Below is an excerpt showing only the first row (the fifth ingest); the other rows are cut as ...:

[
    {
        "id": ...,
        "ts": "...",
        "action": "allow",
        "subject_did": "did:jwk:...",
        "dataset_id": "home/env/temperature",
        "purpose": "write_continuous",
        "reason": "service_token_used:<jti>:5",
        "message_hash": "",
        "raw_topic": "platform/ingest",
        "holder_did": "did:jwk:...",
        "vc_hash": null,
        "presentation_verified": "allow"
    },
    ...
]

The trailing number in reason is write_count. Five calls list 5 down to 1, newest first.

6. Error cases

Situation HTTP detail
Expired (1 h elapsed) 401 service_token_expired
Dataset mismatch 403 service_token_dataset_mismatch
Unknown token 401 policy_token_unknown (Stage 1 compat)

The unknown-token case returns policy_token_* rather than service_* on purpose — to preserve the Stage 1 user-visible error name.

Stop

If you go on to the next page, Hand a credential to the buyer's wallet (Bridge / Stage 5), you can keep the publisher running. Step 4 of that page starts it again with the ssi-wallet and mv-bridge profiles. If you stop here, run the following command.

cd ~/program/Blockchain_IoT_Marketplace
docker compose -f infra/docker-compose.yml --profile ssi-wallet down

Three VCs side by side

ConsentVC (Stage 1) ViewerVC (Stage 3) ServiceVC (Stage 4 prep)
Purpose write authz read authz M2M continuous write
Holder human user human viewer service (e.g. publisher)
Token PolicyToken ViewerToken ServiceToken
TTL 5 min 60 s 1 h
Use single-use any number of times within TTL any number of times within TTL
API POST /platform/ingest GET /platform/data POST /platform/ingest
VC claim allowed_purposes allowed_actions=[read] allowed_actions=[write_continuous]

Limits of this hands-on (future work)

  • No publisher-embedded holder yet: ideally the publisher acquires a ServiceVC at startup, presents it once, holds the resulting token internally, and attaches it to every ingest. The hands-on uses a phone wallet + curl as a stand-in
  • No ServiceToken auto-renewal: a background loop that re-presents 5 minutes before expiry is not implemented
  • Issuance governance: today the publisher self-issues ServiceVCs; who should issue them is a future policy decision

Once these land, Stage 4 LLM Planner can prove its dataset access for each plan step via a VC presentation. This is why this page is called Stage 4 prep.

Next steps

Next is Hand a credential to the buyer's wallet (Bridge / Stage 5) in 2.4 (Hands-on).

  • You can keep the publisher running. Step 4 of the next page starts it again with the ssi-wallet and mv-bridge profiles.
  • Keep the Quickstart IPFS stopped. IPFS and the publisher both use port 8080.
  • Step 1 of the next page starts a new Hardhat node. If the Quickstart Hardhat node and the mediators are running, stop them there.