Skip to content

Back the seller's identity (Seller VC / Stage 7)

This page adds a layer that uses a VC to back "who" is selling a dataset. It covers the fifth VC type, SellerVC.

What you'll do: Issue and present a SellerVC to back the seller's identity

Prerequisites: Read ServiceVC-written data with a PurchaseViewerVC (Stage 6)

Keep running: the Stage 6 Hardhat node (the chain deployed in Step E0), the publisher and the bridge. Step S6 also uses iot-market-ui

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

Time required: approx. 45 min

Where this page belongs

The fifth VC type: SellerVC

This adds a layer that uses a VC to back "who" is selling a dataset when it is listed on the marketplace. As in Stages 1–6, you proceed in the order present → obtain a token → call the API. For design details, see the SellerVC — marketplace listing governance VC (Stage 7 design spec).

Choosing licensed_datasets

The example uses home/env/temperature,home/env/humidity, but for consistency with Stage 0 you can also add home/event/possible_littering,home/event/flood_risk_high. The licensed_datasets of a SellerVC is an array, so it can hold both. Always keep home/env/temperature, which Steps S3–S6 use (without it S4 returns 403 seller_token_dataset_not_licensed).

Goal

  • Handle the fifth VC (SellerVC), which follows ConsentVC / ViewerVC / ServiceVC / PurchaseViewerVC
  • Right after listing an item with IoTMarket.registerMerchandise(), the Seller calls /marketplace/register on the publisher and proves with a VC that "I am selling this Merchandise"
  • Confirm the flow in which seller_did is returned when the Buyer reads /platform/data?merchandise=<addr>

What this page covers

  • How the licensed_datasets of a SellerVC states in the VC "which datasets this seller may sell"
  • Calling /marketplace/register with the SellerToken (24h, multi-use); the SellerToken also works for /provider/publish in §11 of Deliver images and video with tiered access (DataUserVC / Stage T)
  • (Optional) When the environment variable MARKETPLACE_HARDHAT_RPC is set, the publisher verifies on-chain that Merchandise.getOwner() == seller_eth_addr
  • A marketplace/seller_registered row is added to the audit log
  • The response on the buyer side contains seller_did, so the buyer can check who sold the data

Overview

flowchart TB
  SW["Seller wallet<br>1. /issuer/offer?type=SellerVC → receive<br>2. /verifier/request?vc_kind=SellerVC → present<br>3. SellerToken (24h, multi-use)"]
  SH["Seller (Hardhat console)<br>4. deploy a Merchandise + IoTMarket.registerMerchandise()"]
  SC["Seller (curl or /seller UI)<br>5. POST /marketplace/register<br>Authorization: Bearer SellerToken<br>body: merchandise_address + seller_eth_addr + tx_hash + dataset_id"]
  PUB["publisher<br>- verifies the SellerToken (licensed_datasets contains dataset_id)<br>- (optional) verifies Merchandise.getOwner() on-chain<br>- audit: raw_topic=marketplace/seller_registered<br>- merchandise → seller_did binding inside the publisher"]
  BUYER["Buyer (purchase flow of Stage 5/6)<br>→ GET /platform/data?merchandise=&lt;addr&gt;<br>the response carries seller_did"]
  SW --> SH --> SC --> PUB --> BUYER

Required environment

  • You have gone through the Stage 5 / 6 hands-on
  • The deploy script is the version that creates Merchandise contracts with dataset_id in additionalInfo (Stage 6 or later)
  • The publisher is running with code that supports Stage 7 (the latest main)
  • iw3ip-wallet (iPhone) works
  • $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
  • The steps assume a Mac and an iPhone, with the course repository cloned to ~/program/Blockchain_IoT_Marketplace and the wallet cloned to ~/program/iw3ip-wallet

Step S0. Bring the environment up to the latest code

Get the latest code.

cd ~/program/Blockchain_IoT_Marketplace
git checkout main && git pull --ff-only

Only when you enable on-chain owner verify, run the following (optional).

echo "MARKETPLACE_HARDHAT_RPC=http://host.docker.internal:8545" >> infra/.env

After git pull, rebuild the publisher with --build. Otherwise owner verify stays skipped.

docker compose -f infra/docker-compose.yml --profile ssi-wallet --profile mv-bridge up --build -d
sleep 5

Check that the fifth VC type (SellerVC) is exposed.

curl -s http://$HOST_IP:8080/.well-known/openid-credential-issuer \
  | python3 -m json.tool | grep -A1 SellerVC

Expected output (excerpt):

            "vct": "https://iw3ip.example/credentials/SellerVC/v1",

grep -A1 prints every line that contains SellerVC plus the line after it, so you actually see more lines than this. If this vct line is among them, the publisher can issue SellerVCs.

When S0 recreates the publisher (when the image changes or when infra/.env changes), the claims and ingested rows held in the publisher's memory since Stage 6 are cleared. So count in Step S5 can be 0. This does not affect the seller_did that Step S5 checks.


Step S1. Issue a SellerVC

What to check

  • You pass seller_id and licensed_datasets (a whitelist of dataset_id values) in the query, and the wallet receives a SellerVC
  • Datasets other than those written in licensed_datasets are rejected later

Steps

In a PC browser:

http://<HOST_IP>:8080/issuer/offer?type=SellerVC&seller_id=ertl-seller-001&licensed_datasets=home/env/temperature,home/env/humidity

Scan the QR code with the iPhone wallet → approve "IW3IP Seller Credential" → receive.

Expected result

  • "IW3IP Seller Credential" is added to the wallet's VC list
  • claim:
    • seller_id: ertl-seller-001
    • licensed_datasets: ["home/env/temperature", "home/env/humidity"]
    • subject_id: did:jwk:...

Step S2. Present the SellerVC and obtain a SellerToken

What to check

  • The presentation yields a SellerToken (a token separate from PolicyToken / ViewerToken / ServiceToken)
  • The TTL is 24 hours (86400 seconds)
  • The response contains licensed_datasets as is

Steps

In a PC browser:

http://<HOST_IP>:8080/verifier/request?vc_kind=SellerVC

The dataset_id parameter is not needed (a SellerVC does not depend on a specific dataset). QR code → select the SellerVC in the wallet and present it.

Expected output

PUB=$(docker ps -qf name=publisher)
docker logs $PUB 2>&1 | grep "seller_token_issued" | tail -1

→ (each publisher log line is JSON; its "message" holds the following)

seller_token_issued jti=... token=... seller_id=ertl-seller-001 licensed=['home/env/temperature', 'home/env/humidity'] ttl=86400s

Put the token in a variable.

SELLER=$(docker logs $PUB 2>&1 | grep "seller_token_issued" | tail -1 | sed -E 's/.*token=([^ ]+).*/\1/')
echo "SELLER=$SELLER"

Step S3. Deploy a Merchandise and register it in IoTMarket

What to check

  • Deploy a Merchandise in the Hardhat console and call IoTMarket.registerMerchandise()
  • At deploy time, put dataset_id=home/env/temperature in additionalInfo (the same format as Stage 6)

Steps

Terminal B (Hardhat console):

cd ~/program/Blockchain_IoT_Marketplace/iot-market
npx hardhat console --network localhost
// use seller = Account #1 (iotOwner)
const [_, iotOwner] = await ethers.getSigners();
console.log("seller:", await iotOwner.getAddress());

// Register a PubKey (only on first use of PubKey)
const pubKey = await ethers.getContractAt("PubKey", "0x5FbDB2315678afecb367f032d93F642f64180aa3", iotOwner);
try { await (await pubKey.registerKey("[seller-key]")).wait(); } catch (e) { /* ignore if already registered */ }

// Deploy a Merchandise (include dataset_id in additionalInfo)
const dataHash = "0x" + "5".repeat(64);
const merch = await (await ethers.getContractFactory("Merchandise", iotOwner)).deploy(
  ethers.parseEther("0.02"),
  dataHash,
  pubKey,
  [],   // deniedBuyers
  ["fileType", "dataSize", "dataset_id"],
  ["json", "1MB", "home/env/temperature"]
);
const deployReceipt = await merch.deploymentTransaction().wait();
const merchandiseAddress = await merch.getAddress();
console.log("merchandise:", merchandiseAddress);
console.log("deploy tx:", deployReceipt.hash);

// Register in IoTMarket
const market = await ethers.getContractAt("IoTMarket", "0xe7f1725E7734CE288F8367e1Bb143E90bb3F0512", iotOwner);
const regTx = await market.registerMerchandise(merch);
const regReceipt = await regTx.wait();
console.log("register tx:", regReceipt.hash);
.exit   // leave the console and return to the shell

Note down

Note down the four values shown in the console: seller, merchandise, deploy tx, and register tx.


Step S4. Bind the seller on the publisher with /marketplace/register

What to check

  • /marketplace/register succeeds with the SellerToken as Bearer
  • Only a dataset_id contained in licensed_datasets passes
  • (Optional) When MARKETPLACE_HARDHAT_RPC is enabled, Merchandise.getOwner() is verified
  • A marketplace/seller_registered row appears in the audit log

The next diagram shows the order of the checks the publisher runs on /marketplace/register. The first part uses the SellerToken obtained from the SellerVC; the second (optional) part checks the owner of the Merchandise on the blockchain.

flowchart TB
  R["POST /marketplace/register<br>(Bearer SellerToken)"]
  T{"SellerToken valid and<br>dataset_id in<br>licensed_datasets?"}
  E1["401 / 403<br>seller_token_..."]
  C{"MARKETPLACE_HARDHAT_RPC<br>set?"}
  Q["Query Merchandise.getOwner()<br>on the Hardhat node"]
  Q2{"Query succeeded?"}
  E2["502 chain_rpc_failed"]
  O{"Owner equals<br>seller_eth_addr?"}
  E3["403 owner_mismatch"]
  B["Bind merchandise to seller_did<br>audit: marketplace/seller_registered"]
  R --> T
  T -->|"no"| E1
  T -->|"yes"| C
  C -->|"no (owner_verify: skipped)"| B
  C -->|"yes"| Q --> Q2
  Q2 -->|"no"| E2
  Q2 -->|"yes"| O
  O -->|"no"| E3
  O -->|"yes (owner_verify: verified)"| B
  classDef allow fill:#e3f4e1,stroke:#2e7d32,color:#1b5e20
  classDef deny fill:#fde2e2,stroke:#c0392b,color:#7b241c
  classDef chain fill:#e3ecfa,stroke:#2c5aa0,color:#1a3a6b
  class B allow
  class E1,E2,E3 deny
  class Q chain

The SellerVC vouches for which datasets the seller may sell. Whether this seller really owns that Merchandise can only be checked by querying the blockchain, and that query runs only when MARKETPLACE_HARDHAT_RPC is set.

Steps

Run this in the terminal where you set SELLER in Step S2 (at the repository top). Before running, replace each whole <…> in the first three lines, including the angle brackets, with the value you noted in Step S3. If you forget, nothing errors out, because the values are quoted: the placeholder text is sent as is. When MARKETPLACE_HARDHAT_RPC is not set, the bogus values get registered. When it is set, a forgotten MERCH makes the on-chain lookup fail with HTTP 502 chain_rpc_failed, and a forgotten SELLER_ETH does not match the on-chain owner and fails with HTTP 403 owner_mismatch. TX_HASH is not checked, so a forgotten TX_HASH is registered as is.

cd ~/program/Blockchain_IoT_Marketplace
SELLER_ETH='<seller address from Step S3>'
MERCH='<merchandise address from Step S3>'
TX_HASH='<register tx hash from Step S3>'
curl -s -X POST http://$HOST_IP:8080/marketplace/register \
  -H "Authorization: Bearer $SELLER" \
  -H "Content-Type: application/json" \
  -d "{
    \"merchandise_address\": \"$MERCH\",
    \"seller_eth_addr\": \"$SELLER_ETH\",
    \"tx_hash\": \"$TX_HASH\",
    \"dataset_id\": \"home/env/temperature\"
  }" | python3 -m json.tool

Expected output

{
    "registered": true,
    "merchandise_address": "0x...",
    "seller_did": "did:jwk:...",
    "dataset_id": "home/env/temperature",
    "tx_hash": "0x...",
    "register_count": 1,
    "owner_verify": "skipped"
}

Values of owner_verify:

  • skipped: MARKETPLACE_HARDHAT_RPC is not set (for testing / development)
  • verified: getOwner() matches seller_eth_addr on-chain

If the RPC cannot be reached, the response has no owner_verify; the call fails with HTTP 502 (chain_rpc_failed). If the on-chain owner does not match seller_eth_addr, it fails with 403 (owner_mismatch).

audit log

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

The result is a list, newest first. The first row is marketplace/seller_registered (the other rows are cut as ...):

[
    {
        "id": ...,
        "ts": "...",
        "action": "allow",
        "subject_did": "did:jwk:...",
        "dataset_id": "home/env/temperature",
        "purpose": "register",
        "reason": "seller_register:jti=...:merchandise=0x...:eth=0x...:tx=0x...:owner_verify=skipped",
        "message_hash": "",
        "raw_topic": "marketplace/seller_registered",
        "holder_did": "did:jwk:...",
        "vc_hash": null,
        "presentation_verified": "allow"
    },
    ...
]

Step S5. The seller_did seen by the Buyer

What to check

  • When the Buyer calls /platform/data?merchandise=<addr> via a PurchaseViewerVC, the response contains seller_did

Steps

The bridge watches only the Merchandise that were registered in IoTMarket when it started. Before purchasing the Merchandise added in Step S3, recreate the bridge so that it picks it up.

cd ~/program/Blockchain_IoT_Marketplace
docker compose -f infra/docker-compose.yml --profile mv-bridge up -d --force-recreate bridge

Then follow the procedure of the Hand a credential to the buyer's wallet (Bridge / Stage 5): purchase with MetaMask → receive in the wallet → obtain a ViewerToken → fetch. The ViewerToken expires after 60 seconds, so run the next commands right after presenting; if you get viewer_token_expired, present again. Before running, replace the whole <buyer ViewerToken>, including the angle brackets, with the token you extracted as in Stage 5 Step 8. If you forget, the placeholder text is sent as the token and the call fails with 401 (viewer_token_unknown).

The next command uses the $MERCH you set in Step S4. Run it in the same terminal as Step S4. The first line should print MERCH=0x.... If nothing follows MERCH=, you are in a different terminal: first run MERCH='<merchandise address from Step S3>' with the <…> replaced by the value you noted in Step S3.

echo "MERCH=$MERCH"
TOKEN='<buyer ViewerToken>'
curl -s -H "Authorization: Bearer $TOKEN" \
  "http://$HOST_IP:8080/platform/data?merchandise=$MERCH" | python3 -m json.tool

Expected output

{
    "dataset_id": "home/env/temperature",
    "count": N,
    "read_count": 1,
    "seller_did": "did:jwk:...(the seller's DID)",
    "allowed_views": [
        "event"
    ],
    "rows": [...]
}

seller_did is the value bound in Step S4. For a Merchandise that has only gone through Stage 5/6 (/marketplace/register has not been called), "unknown" is returned.


Step S6. Register from the /seller page of iot-market-ui

This section is optional. It is another way to do the issuance, presentation and registration of Steps S1–S4 from a web UI. You can check the Stage 7 completion condition (seller_did) by the end of Step S5.

What to check

  • /marketplace/register can also be called from the Web UI
  • The three-step structure of the form (issue → present → register) is self-contained from the seller's point of view

Steps

With iot-market-ui already running:

http://<HOST_IP>:5173/seller

Procedure in the UI:

  1. Step 1: enter seller_id and licensed_datasets, then "Open /issuer/offer" → receive in the wallet
  2. Step 2: "Open /verifier/request" → present the SellerVC in the wallet → copy the SellerToken from the publisher log
  3. Step 3: paste the token obtained above and the merchandise/eth/tx from Step S3, enter the dataset_id, and press "Register"

On success, the same JSON response as in Step S4 is shown at the bottom of the screen.


Completion matrix

Step Check item Example output (values obtained in verification on real devices)
S0 The fifth type, SellerVC, appears in the metadata "vct": "https://iw3ip.example/credentials/SellerVC/v1"
S1 SellerVC in the wallet seller_id: "ertl-seller-001" and licensed_datasets: ["home/env/temperature", "home/env/humidity"] in the claims
S2 SellerToken issued seller_token_issued jti=... seller_id=ertl-seller-001 licensed=['home/env/temperature', 'home/env/humidity'] ttl=86400s
S3 Merchandise + IoTMarket registration two transactions: deploy tx + register tx
S4 /marketplace/register succeeds { "registered": true, "seller_did": "did:jwk:...", "register_count": <cumulative count>, "owner_verify": "verified" / "skipped" }
S4 audit log raw_topic=marketplace/seller_registered, reason=seller_register:jti=...:merchandise=0x...:eth=0x...:tx=0x...:owner_verify=...
S5 seller_did shown on the buyer side { "dataset_id": "home/env/temperature", "seller_did": "did:jwk:...", ... }
S6 Registration also works through the UI the response JSON is shown at the bottom of the screen after the /seller form is submitted

Completion condition for Stage 7: the response JSON of /platform/data?merchandise=<addr> contains a seller_did field with a did:jwk: value. This lets you check a record, backed by a VC, of which seller sold the data.


Troubleshooting

A. 403 with seller_token_dataset_not_licensed

Cause: You passed to /marketplace/register a dataset that is not contained in the licensed_datasets of the SellerVC.

Fix: Add more entries to licensed_datasets in Step S1, or issue a separate SellerVC for the target dataset.

B. chain_rpc_failed (502) when MARKETPLACE_HARDHAT_RPC is enabled

Cause: The publisher container cannot reach host.docker.internal:8545.

Fix: Check that the Hardhat node is running with npx hardhat node --hostname 0.0.0.0 and that infra/.env contains MARKETPLACE_HARDHAT_RPC=http://host.docker.internal:8545, then run cd ~/program/Blockchain_IoT_Marketplace && docker compose -f infra/docker-compose.yml up -d --build publisher again. The publisher's extra_hosts is already set in infra/docker-compose.yml, so you do not need to add it.

C. owner_mismatch (403)

Cause: The seller_eth_addr passed to /marketplace/register differs from the on-chain Merchandise.getOwner(). This happens when seller_eth_addr is not the address of the Hardhat account used for the deploy.

Fix: Set seller_eth_addr to the address of the Hardhat signer that deployed the Merchandise (for example, Account #1 = iotOwner).

D. try { ... } catch (e) { ... } causes a SyntaxError in the Hardhat console

Uncaught SyntaxError: missing ) after argument list

Cause: The Hardhat console (Node REPL) evaluates input as soon as it forms a complete statement. The line that closes the try { ... } block is treated as complete, so a catch on the next line is a syntax error (multi-line calls with an unclosed parenthesis, such as deploy(...), are fine).

Fix: Write it on one line. Example:

let r; try { r = await (await pubKey.registerKey("[buyer-key]")).wait(); console.log("ok:", r.status); } catch (e) { console.log("err:", e.message); }

E. After restarting the Hardhat node, getState() and similar calls return 0x and fail with BAD_DATA

ERROR: could not decode result data (value="0x", info={ "method": "getState", ...

Cause: Stopping the Hardhat node with Ctrl+C or similar erases all on-chain state. The already deployed PubKey / IoTMarket / Merchandise also lose their code. An address for which provider.getCode(addr) returns "0x" (= length 2) has no contract.

Fix:

// Check whether the main addresses have code
const c1 = await ethers.provider.getCode("0x5FbDB2315678afecb367f032d93F642f64180aa3");  // PubKey
const c2 = await ethers.provider.getCode("0xe7f1725E7734CE288F8367e1Bb143E90bb3F0512");  // IoTMarket
console.log({ pubKey: c1.length, ioTMarket: c2.length });
// If 2 is printed, the code is gone

If it is gone, leave the console with .exit, then redeploy with npx hardhat run scripts/deployMerchandiseWithIoTMarket.ts --network localhost.

Note: on the chain after a node restart, a Merchandise that you deployed manually in the previous session (other than the deterministic addresses of the script) is not restored. After a chain reset, it is safe to use only the five contracts deployed by the script.

F. After redeploying the chain, a purchase by Account #2 reverts with 0x295f0a57

Cause: The PubKey contract was redeployed and its state was reset, so the public key registration of the buyer (Account #2) is gone. The i_pubKey.getPubKey(tx.origin) called inside Merchandise.purchase() reverts with PubKey__NotRegistered (0x295f0a57) (the same as Stage 5 troubleshooting B).

Fix: Register the PubKey again.

const [_, __, buyer] = await ethers.getSigners();
const pk = await ethers.getContractAt("PubKey", "0x5FbDB2315678afecb367f032d93F642f64180aa3", buyer);
let r; try { r = await (await pk.registerKey("[buyer-key]")).wait(); console.log("ok:", r.status); } catch (e) { console.log("err:", e.message); }

Register in the same way when you use the seller (Account #1).

G. No new Purchase event appears in the bridge log / the bridge stops / the wallet gets 400 at /issuer/token

Cause: At startup, the bridge reads the list of Merchandise from IoTMarket and watches only blocks after the block number at that moment. Restarting Hardhat empties the chain and resets the block number to 0.

  • A bridge that is still running watches only blocks after the old block number, so it misses new Purchase events
  • If you recreate the bridge while IoTMarket is not deployed yet, it cannot read the list, prints bridge: fatal, and exits (exit 1). It does not restart on its own

The wallet's 400 appears when the wallet tries to reuse a pre_authorized_code issued on the old chain and the publisher treats it as already used.

Fix: Redo the steps in this order.

  1. Redeploy the contracts (the steps in E). Register the buyer's public key again as well (the steps in F)
  2. If you recreate the publisher (when the 400 below persists), do it now. The SellerToken and the seller registration in the publisher's memory are cleared, so redo from Step S2
  3. Deploy and register the Merchandise again in Step S3, and redo the seller binding in Step S4. On the new chain the Merchandise address also changes, so use the values printed in S3. S4 is needed even if you did not recreate the publisher
  4. Recreate the bridge after S3. The bridge watches only the Merchandise that exist when it is recreated, so if you recreate it before S3, it does not watch the new Merchandise
cd ~/program/Blockchain_IoT_Marketplace
docker compose -f infra/docker-compose.yml --profile mv-bridge up -d --force-recreate bridge
sleep 5
docker logs iw3ip-mv-bridge 2>&1 | tail -5

Expected output (the number of Merchandise is the five from the deploy script plus the one from S3):

bridge: listening to 6 merchandise(s)
bridge: starting poll from block <current number>
bridge: started rpc=http://host.docker.internal:8545 market=0x... publisher=http://publisher:8080

If you see bridge: fatal, IoTMarket is not deployed yet. Go back to step 1.

After that, running Merchandise.purchase() again lets the bridge capture the new Purchase event. Discard the old deeplink and take a new one from the new bridge: claim ok line.

If the wallet still gets 400, you may have repeated the same purchase after restarting Hardhat, so the transaction ID (tx hash) is the same as before. The publisher returns the previous, already used code for the same transaction ID, so recreate the publisher as well in step 2.

cd ~/program/Blockchain_IoT_Marketplace
docker compose -f infra/docker-compose.yml --profile mv-bridge up -d --force-recreate publisher

Then redo Steps S2–S4, and finally recreate the bridge as shown above. The ingested rows (written in Stage 6 Step E1) are cleared too; redo Stage 6 Step E1 if you want rows in S5.

H. Other issues

See also Troubleshooting in Stage 5 (MetaMask chainId cache, BRIDGE_PUBLIC_PUBLISHER_URL not set, etc.).


Limits / future work

  • On-chain guard: currently IoTMarket.registerMerchandise() itself passes even without publisher verification. An on-chain guard is future work (Stage 8 or later)
  • EIP-712 signatures: the binding between the seller_did obtained via the SellerVC and the eth address relies on trust by the publisher (the same MVP level as eth_did_bound in Stage 5/6)
  • Where to declare the dataset_id: Stage 6 case B made it possible to read the dataset_id value from additionalInfo, but /marketplace/register depends on the client POST. One future option is for the publisher itself to call getAllAdditionalInfo() and cross-check the value

Next steps

Next is Marketplace as a phone app (Stage A). You go from purchase to viewing using only the phone screen.

  • Keep the Hardhat node (Terminal A) running. Stage A uses the contracts deployed and the public key registered in Step E0 of Stage 6.
  • You can leave the publisher and the bridge running. Step M0 of Stage A recreates them.
  • iot-market-ui is stopped with Ctrl+C and restarted in Step M0 of Stage A.
  • Keep Metro running.