Free 30-min Web3 Consultation
Book Consultation
Smart Contract Security Audits
View Audit Services
Custom DeFi Protocol Development
Explore DeFi
Full-Stack Web3 dApp Development
View App Services
Free 30-min Web3 Consultation
Book Consultation
Smart Contract Security Audits
View Audit Services
Custom DeFi Protocol Development
Explore DeFi
Full-Stack Web3 dApp Development
View App Services
Free 30-min Web3 Consultation
Book Consultation
Smart Contract Security Audits
View Audit Services
Custom DeFi Protocol Development
Explore DeFi
Full-Stack Web3 dApp Development
View App Services
Free 30-min Web3 Consultation
Book Consultation
Smart Contract Security Audits
View Audit Services
Custom DeFi Protocol Development
Explore DeFi
Full-Stack Web3 dApp Development
View App Services
LABS
Guides

Setting Up a Decentralized Identity Layer for Medical Devices

A technical guide for developers on implementing W3C Decentralized Identifiers (DIDs) and Verifiable Credentials to create secure, self-sovereign identities for medical IoT devices within a DePIN architecture.
Chainscore © 2026
introduction
TUTORIAL

Setting Up a Decentralized Identity Layer for Medical Devices

A technical guide to implementing a decentralized identity (DID) system for secure, patient-controlled authentication of medical IoT devices.

Medical IoT devices, from glucose monitors to implantable sensors, generate sensitive health data. A centralized identity model creates a single point of failure and complicates patient data ownership. Decentralized Identity (DID) provides a solution by giving each device a cryptographically verifiable identifier anchored on a blockchain, such as Ethereum or Polygon. This DID acts as a globally unique, persistent key that is not controlled by any single institution, enabling secure, interoperable communication between devices, patients, and healthcare providers.

The core components of this system are the DID Document and Verifiable Credentials (VCs). A DID Document, stored on a decentralized ledger or IPFS, contains the device's public keys and service endpoints. A healthcare regulator or manufacturer can issue a Verifiable Credential—a cryptographically signed attestation—to the device's DID, stating its model, certification status, and calibration data. This creates a trust triangle where the device proves its identity, the issuer proves its authority, and the verifier (e.g., a hospital network) can cryptographically verify both without contacting a central database.

To implement this, start by choosing a DID method suitable for IoT constraints, such as did:key for simplicity or did:ethr for Ethereum-based management. For a glucose monitor, you would generate a DID and its corresponding private key securely within the device's hardware. The public key and metadata form the DID Document. A manufacturer's backend service would then issue a signed VC to this DID, containing attributes like "deviceModel": "GlucoCheck X1", "fdaCertified": true. This VC is stored with the patient or in a personal data store like a Solid pod.

When the device needs to transmit data to an Electronic Health Record (EHR) system, it creates a Verifiable Presentation. This package includes the signed health data and the relevant VC, proving the data's origin from a certified device. The EHR system, acting as a verifier, uses the public keys in the DID Document to check the signatures on both the data and the VC. This entire flow occurs peer-to-peer, eliminating the need for a central device registry and giving patients cryptographic control over when and with whom their device identity is shared.

Key technical considerations include key management for resource-constrained devices, often using a hardware security module (HSM) or a secure element. Interoperability is ensured by adhering to W3C DID and VC standards. Furthermore, privacy-preserving techniques like zero-knowledge proofs (ZKPs) can be integrated, allowing a device to prove it is certified without revealing its serial number. Frameworks like Microsoft ION (for Bitcoin) or Veramo provide libraries to bootstrap development, handling much of the underlying cryptography and ledger interactions.

This architecture fundamentally shifts security from perimeter-based to credential-based. It enables secure device onboarding at scale, automated compliance checks, and patient-mediated data sharing. By implementing a DID layer, healthcare IoT systems can achieve greater resilience against data breaches, streamline regulatory audits, and empower individuals with true ownership of their digital health footprint, paving the way for more personalized and interoperable care.

prerequisites
PREREQUISITES AND SETUP

Setting Up a Decentralized Identity Layer for Medical Devices

This guide outlines the technical foundation required to implement a decentralized identity (DID) system for medical device authentication and data provenance.

A decentralized identity layer for medical devices requires a foundational understanding of core Web3 concepts. You should be familiar with public-key cryptography, which underpins user-controlled wallets and digital signatures. A working knowledge of smart contracts is essential for automating access control and audit logs on-chain. For development, you'll need Node.js (v18 or later) and npm/yarn installed. This setup enables you to interact with blockchain networks and deploy the necessary identity protocols.

The primary tool for this implementation is the Decentralized Identifier (DID) standard, specifically the did:ethr method which is widely supported on EVM-compatible chains. We will use the Verifiable Credentials (VC) data model to represent device certifications and user authorizations. Key libraries include ethr-did for creating and managing DIDs, did-jwt-vc for issuing and verifying credentials, and a Web3 provider like ethers.js v6 to connect to a testnet such as Sepolia or Polygon Mumbai.

Start by initializing a new project and installing the required dependencies. Run npm init -y followed by npm install ethr-did did-jwt-vc ethers. Next, set up a .env file to securely manage your private keys and RPC endpoints. You will need a funded testnet account private key for deploying a DID registry contract and signing transactions. An Infura or Alchemy project ID is recommended for reliable blockchain access. Never commit your .env file to version control.

The first operational step is to deploy or connect to a EthereumDIDRegistry smart contract. This contract, defined by the did:ethr specification, maps DIDs to public keys and service endpoints. On testnets, you can often use a pre-deployed instance. Use ethers.js to create a signer from your private key and instantiate a Resolver from the ethr-did-resolver library. This resolver will allow your application to lookup DID documents on-chain, which is critical for verifying device identities.

With the resolver configured, you can create a DID for a medical device. A DID is a string like did:ethr:0x5:0xabc123... derived from the device's controlling public key. The ethr-did library provides a simple interface: new EthrDID({ identifier: '0xabc123...', provider, registry: '0xdca7ef...' }). This DID object can then sign a Verifiable Credential, such as an FDA clearance or a calibration certificate, creating a tamper-proof attestation that can be stored off-chain (e.g., on IPFS) and verified by any party with the device's DID.

Finally, structure your application to separate identity logic from business logic. Create modules for: DID creation and management, VC issuance for device attributes, and VC verification for data access requests. Implement a simple access control smart contract that checks for a valid VC signature before granting permission to write data from a specific device DID. This modular approach ensures scalability and auditability, forming a robust foundation for a compliant medical device identity layer.

key-concepts-text
CORE CONCEPTS: DIDS, VCS, AND DEPIN

Setting Up a Decentralized Identity Layer for Medical Devices

A technical guide to implementing Decentralized Identifiers (DIDs) and Verifiable Credentials (VCs) for secure, interoperable identity in the medical device ecosystem.

Medical devices, from insulin pumps to patient monitors, generate sensitive data that must be securely attributed to a specific patient and device. Traditional centralized identity systems create silos and single points of failure. A decentralized identity layer built on Decentralized Identifiers (DIDs) and Verifiable Credentials (VCs) solves this by giving patients and devices self-sovereign, cryptographically verifiable identities. This enables secure data provenance, automated compliance, and seamless interoperability across healthcare providers and regulatory bodies without relying on a central authority.

The foundation is the DID, a unique identifier (e.g., did:example:123456789abcdefghi) controlled by the device or patient, not a central registry. It resolves to a DID Document containing public keys and service endpoints for authentication. For a medical device, this document proves its authenticity and allows it to sign data. The Verifiable Credential is a tamper-evident digital attestation, like a manufacturer's certificate or a regulatory approval, issued by a trusted entity (e.g., the FDA). It is cryptographically signed and linked to the device's DID, creating a portable, machine-verifiable proof of its status.

Implementing this requires choosing a DID method suitable for the deployment environment. For high-assurance devices, did:key or did:jwk provide simple, embedded cryptographic proofs. For devices needing a blockchain anchor for public verification, did:ion (on Bitcoin) or did:ethr (on Ethereum) are robust options. The device generates its DID and keys during provisioning. A manufacturer then issues a signed VC containing claims like "deviceModel", "serialNumber", "fdaApprovalStatus", and the "issuanceDate". This VC is stored securely on the device or in a patient-controlled wallet.

In practice, when a hospital's system needs to verify a device, it performs a DID resolution to fetch the public key. It then requests the device's VCs and verifies the cryptographic signatures against the issuer's and subject's DIDs. This creates a trust chain. For example, a smart infusion pump can present a VC from its manufacturer and another from the hospital's IT department authorizing it for use on Network A. A nurse's tablet app can instantly verify these credentials without calling a central database, enabling secure, automated device onboarding and data logging.

Integrating with DePIN (Decentralized Physical Infrastructure Networks) models this further. Device data, signed by its DID, can be streamed to a decentralized storage or compute network like Filecoin or Render. Patients can grant fine-grained, auditable access to this data for research via VC-based access tokens, creating a privacy-preserving data economy. This architecture reduces vendor lock-in, enhances security against breaches, and empowers patients with true ownership of their medical device identity and the data it generates, aligning with regulations like HIPAA and GDPR through cryptographic proof rather than policy alone.

TECHNICAL SPECS

DID Method Comparison for IoT Devices

A comparison of DID methods based on their suitability for resource-constrained medical IoT devices.

Feature / MetricIOTA IdentitySidetree (ION)Veres One

Underlying Ledger

IOTA Tangle (DAG)

Bitcoin / Ethereum

Ledger-agnostic

Transaction Fees

Zero

$2-50 (varies)

Varies by node

Write Latency (avg.)

< 10 seconds

~10 minutes (Bitcoin)

~5 seconds

Storage on Ledger

Anchor + Proofs only

Full DID Document

DID Document + Proofs

Light Client Support

Selective Disclosure

W3C DID Core Compliant

Hardware Security Module (HSM) Integration

step-1-create-did
DECENTRALIZED IDENTITY LAYER

Step 1: Creating a DID for a Medical Device

This guide explains how to create a Decentralized Identifier (DID) for a medical device, establishing its unique, self-sovereign identity on a blockchain.

A Decentralized Identifier (DID) is a globally unique, cryptographically verifiable identifier that is owned and controlled by the entity it represents, not a central registry. For a medical device, such as an insulin pump or a patient monitor, a DID serves as its foundational digital identity on the web. Unlike traditional serial numbers tied to a manufacturer's database, a DID is anchored on a public blockchain or other decentralized network, enabling trust without intermediaries. This allows the device to securely interact with other entities, like hospital systems or patient wallets, in a verifiable way.

Creating a DID involves generating a public-private key pair and registering the public key on a chosen blockchain. The DID document, which contains the public key and service endpoints, is then written to that chain. For this tutorial, we'll use the W3C DID Core specification and the IOTA Identity Framework, which is designed for IoT and machine identities. First, ensure you have Node.js installed, then initialize a new project and install the required package: npm install @iota/identity-wasm. This library handles the complex cryptography and blockchain interactions for you.

The following code demonstrates creating a DID for a device on the IOTA Shimmer testnet. The stronghold storage acts as a secure vault for the private key, which must never be exposed. The aliasOutput represents the on-chain state of the DID.

javascript
const { AccountBuilder, ExplorerUrl } = require('@iota/identity-wasm/node');

async function createDeviceDID(deviceName) {
  // 1. Create a secure storage for the key material
  const strongholdSecret = "your-strong-password-here";
  const strongholdPath = `./${deviceName}-vault.stronghold`;

  // 2. Build a new identity account
  const account = await new AccountBuilder({
    storagePath: strongholdPath,
    password: strongholdSecret,
  }).createIdentity();

  // 3. Retrieve the newly created DID
  const did = account.did();
  console.log(`Created DID for ${deviceName}: ${did}`);
  console.log(`Explorer URL: ${ExplorerUrl.mainnet().resolverUrl(did)}`);

  return { account, did };
}

// Execute for a sample device
createDeviceDID("Alpha-Insulin-Pump-001");

After running this script, your device has a live DID (e.g., did:iota:smr:0xabc123...) on the Shimmer network. The associated DID Document is now publicly resolvable and contains the device's public key. This document can be extended with service endpoints—critical for medical use cases. You can add a service pointing to the device's secure API for transmitting encrypted health data, or a link to its verifiable credentials attestation. The private key, stored securely in the Stronghold file, is used by the device to sign data, proving the origin and integrity of any message or sensor reading.

This self-owned identity is the first step in building a trust layer for the Internet of Medical Things (IoMT). With a DID, the device can now:

  • Authenticate itself to networks and electronic health record (EHR) systems without a username/password.
  • Issue and hold Verifiable Credentials (VCs) for regulatory approvals or calibration certificates.
  • Participate in secure, auditable data exchanges where every transaction is signed and linked to its immutable identity. The next step is to issue a Verifiable Credential to this DID, attesting to its manufacturer, model, and compliance status, which we will cover in the following guide.
step-2-issue-vc
IMPLEMENTATION

Step 2: Issuing a Verifiable Credential

This section details the technical process of creating and issuing a W3C-compliant Verifiable Credential (VC) for a medical device, establishing its decentralized identity on-chain.

A Verifiable Credential (VC) is a tamper-evident digital claim issued by an issuer (e.g., a medical device manufacturer) about a subject (the device). For our use case, the credential's data payload, or claim, contains critical device metadata. This includes the device's unique serial number, model, firmware version, manufacturing date, and compliance certifications (like FDA 510(k) or CE mark). This structured data is cryptographically signed, creating a credential that is both machine-readable and independently verifiable.

The core of the VC is a JSON-LD document following the W3C standard. The credentialSubject.id field is crucial—it must be a Decentralized Identifier (DID). For a medical device, this is the DID we created and anchored on-chain in Step 1 (e.g., did:ethr:0x123...:device123). The issuer also signs the credential with their own private key, corresponding to their DID. Here's a simplified schema of the VC JSON structure:

json
{
  "@context": ["https://www.w3.org/2018/credentials/v1"],
  "id": "urn:uuid:credential-id-456",
  "type": ["VerifiableCredential", "MedicalDeviceCredential"],
  "issuer": "did:ethr:0x456...:manufacturer",
  "issuanceDate": "2024-01-15T10:30:00Z",
  "credentialSubject": {
    "id": "did:ethr:0x123...:device123",
    "model": "GlucoseMonitor X1",
    "serialNumber": "GMX1-2024-00123",
    "firmwareVersion": "2.1.5",
    "certification": "FDA 510(k) K123456"
  },
  "proof": { ... } // JWT or LD-Proof signature
}

To make the credential truly verifiable, you must add a cryptographic proof. Common methods include JSON Web Tokens (JWT) or Data Integrity Proofs (e.g., Ed25519Signature2020). Using a library like did-jwt-vc or jsonld-signatures, you sign the entire credential payload with the issuer's private key. This proof is embedded in the VC, allowing any verifier to check the signature against the issuer's public DID document on the blockchain, confirming the credential's authenticity and that it hasn't been altered post-issuance.

For persistent, decentralized storage of the VC, you have two primary patterns. The first is to store the signed VC document off-chain in a secure, content-addressable system like IPFS or Arweave, then record the content identifier (CID) or transaction ID on-chain linked to the device's DID. The second, more gas-efficient pattern is to emit an on-chain event containing only the essential credential metadata (issuer DID, credential type, issuance timestamp, and off-chain storage pointer) from a smart contract. This creates an immutable audit log on the blockchain itself.

The issued credential enables critical downstream functions. A hospital's procurement system can verify the device's authenticity before deployment. An IoT gateway can request the credential to confirm a connected device is legitimate and running approved firmware. Furthermore, this VC serves as the foundational source credential for generating more specific, user-centric attestations, such as a credential about a device's calibration status or its linkage to a specific patient's health record, enabling a full chain of trust.

step-3-present-verify
DECENTRALIZED IDENTITY LAYER

Presentation and Verification

This step details how a medical device presents its verified credentials to a verifier and how that verification is cryptographically validated on-chain.

With a Verifiable Credential (VC) issued and stored, the medical device can now present proof of its identity and compliance. The presentation is not the raw credential itself, but a Verifiable Presentation (VP). This is a wrapper, created by the device's wallet, that contains the specific claims a verifier needs—like deviceType and fdaApprovalStatus—while optionally hiding other private attributes. The presentation is cryptographically signed by the device's private key, proving the device controls the DID to which the credential was issued.

The verifier, such as a hospital network's gateway or a telehealth platform, receives this VP. Its verification logic involves several checks performed via smart contracts on the chosen blockchain (e.g., Ethereum, Polygon). First, it resolves the device's DID from the decentralized identifier registry to fetch its public key. It then cryptographically verifies the signature on the presentation. Next, it checks the status of the credential by querying the revocation registry—a smart contract that maintains a list of revoked credential IDs—to ensure it hasn't been invalidated.

Finally, the verifier validates the credential's proof. For a W3C-compliant VC with a JSON-LD proof, this involves checking the linked data signatures. For a JWT-based VC, it validates the JWT signature. The smart contract can also verify the issuer's DID is authorized (e.g., checked against a registry of trusted manufacturer DIDs). This entire process is trustless and automated; the verifier's smart contract returns a simple true or false based on the cryptographic proofs, with no need to contact the issuer directly.

For example, an infusion pump connecting to a hospital's IoT network would present a VP containing its deviceSerialNumber and lastCalibrationDate. The hospital's verification contract, deployed on a low-cost chain like Polygon PoS, would execute the checks. If all pass, the network grants the device specific access permissions defined by role-based access control (RBAC) policies, also encoded on-chain. This creates a seamless, auditable handshake without centralized databases.

Implementing this requires a verifier SDK like those provided by SpruceID's Kepler or Microsoft's ION. A basic verification contract snippet in Solidity might check a revocation registry:

solidity
function verifyCredentialStatus(bytes32 credentialId) public view returns (bool) {
    RevocationRegistry registry = RevocationRegistry(registryAddress);
    return !registry.isRevoked(credentialId);
}

This on-chain verification result becomes an immutable log entry, providing a tamper-proof audit trail for compliance with regulations like HIPAA or EU MDR, as every access event is recorded.

The final output of this step is a cryptographic guarantee that the device is who it claims to be and is in good standing. This enables secure, automated trust in scenarios like dynamic device onboarding, secure data transmission to electronic health records, and participation in decentralized clinical trials. The system's resilience comes from distributing trust across the blockchain, issuers, and the device's cryptographic keys, eliminating single points of failure inherent in traditional certificate authorities.

step-4-deploy-smart-contract
IMPLEMENTATION

Step 4: Deploying an Access Control Smart Contract

This guide walks through writing and deploying a smart contract that manages role-based permissions for medical device data access, using OpenZeppelin's AccessControl library.

The core of your decentralized identity layer is a smart contract that defines and enforces access rules. We'll use Solidity and the widely-audited AccessControl contract from OpenZeppelin, which implements a flexible role-based permission system. Start by setting up a new Hardhat project and installing the required dependencies: npm install @openzeppelin/contracts. This library provides the security primitives needed to manage roles like DOCTOR_ROLE, PATIENT_ROLE, and DEVICE_MANUFACTURER_ROLE without reinventing the wheel.

Below is a foundational contract example. It establishes a PATIENT_ROLE that can grant the DOCTOR_ROLE permission to access their data, mimicking patient consent. The contract inherits from OpenZeppelin's AccessControl and uses the ERC165 standard for interface detection.

solidity
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;

import "@openzeppelin/contracts/access/AccessControl.sol";
import "@openzeppelin/contracts/utils/introspection/ERC165.sol";

contract MedicalAccessControl is AccessControl {
    // Define role constants as keccak256 hashes for security
    bytes32 public constant PATIENT_ROLE = keccak256("PATIENT_ROLE");
    bytes32 public constant DOCTOR_ROLE = keccak256("DOCTOR_ROLE");

    constructor() {
        // The contract deployer gets the default admin role
        _grantRole(DEFAULT_ADMIN_ROLE, msg.sender);
    }

    // Function allowing a patient to grant doctor role to an address
    function grantDoctorAccess(address doctor) public onlyRole(PATIENT_ROLE) {
        grantRole(DOCTOR_ROLE, doctor);
    }
}

After writing your contract, compile it with npx hardhat compile. For deployment, you'll need a script. Using a network like Sepolia or a local Hardhat node, configure your hardhat.config.js with an RPC URL and a private key from a wallet like MetaMask. A basic deployment script uses the Hardhat Runtime Environment (HRE) to deploy the contract and optionally initialize roles.

Deploying the contract is a transaction that creates it on the blockchain. Run your script with npx hardhat run scripts/deploy.js --network sepolia. Upon successful deployment, the terminal will output the contract address. Save this address; it is the unique identifier for your access control layer. You can verify the contract on a block explorer like Etherscan to make the source code publicly verifiable, enhancing trust.

Post-deployment, you must initialize the roles. As the DEFAULT_ADMIN_ROLE, you can grant the PATIENT_ROLE to patient wallets (e.g., via a secure backend service). Once a patient has this role, they can call grantDoctorAccess to delegate permissions, creating a user-centric consent model. This contract now serves as the authoritative source for permissions that your off-chain API or application logic will check before serving medical device data.

This smart contract is a foundational component. In a production system, you would extend it with features like: time-bound roles using AccessControlEnumerable, event emission for audit trails, and integration with a decentralized identifier (DID) document for each entity. The next step involves building the off-chain service that queries this contract's state to enforce access controls in your application's backend.

DEVELOPER FAQ

Frequently Asked Questions

Common technical questions and troubleshooting for implementing a decentralized identity layer for medical devices using blockchain.

A Decentralized Identifier (DID) is a globally unique, cryptographically verifiable identifier that a medical device controls, independent of any central registry. It is created by generating a public/private key pair on the device or a secure hardware module. The public key forms the basis of the DID, which is typically expressed as a URI (e.g., did:ethr:0xabc123...). The corresponding DID Document, containing the public key and service endpoints, is then anchored to a blockchain like Ethereum or Polygon, creating an immutable proof of the DID's existence and initial state. This allows the device to prove ownership and authenticate itself without relying on a hospital's central IT system.

DECENTRALIZED IDENTITY FOR MEDICAL DEVICES

Troubleshooting Common Issues

Common technical hurdles and solutions for developers implementing a decentralized identity layer for connected medical hardware.

A Verifiable Credential can be rejected for several technical reasons. First, verify the credential status. If you're using a Status List 2021, ensure the credential's credentialStatus index points to a valid, non-revoked entry on the published list. Second, check the proof signature. The cryptographic proof (e.g., Ed25519Signature2020, BbsBlsSignature2020) must be valid and signed by the issuer's DID whose public key is correctly resolved. Third, confirm the credential hasn't expired by checking the expirationDate. Finally, ensure the credential's context (@context) and schema (credentialSchema) URLs are reachable and return the expected JSON-LD definitions, as verifiers perform schema validation.

Common Fixes:

  • Use a reliable DID resolver like universal-resolver or did:web for testing.
  • For Status Lists, host the list on a persistent, decentralized service like IPFS with a predictable CID.
conclusion
IMPLEMENTATION SUMMARY

Conclusion and Next Steps

This guide has outlined the core components for building a decentralized identity layer for medical devices using verifiable credentials and blockchain.

You have now implemented a foundational system where a Medical Device Manufacturer can issue a Verifiable Credential (VC) containing a device's DID, model, firmware hash, and certification status. This credential is anchored to a blockchain like Ethereum or Polygon for timestamping and non-repudiation. A Hospital or patient can then verify this credential's authenticity and cryptographic integrity off-chain without exposing sensitive data on the public ledger, ensuring both transparency and privacy.

The next step is to integrate this identity layer into real-world workflows. For a patient's insulin pump, this could mean the pump's app automatically presents its verified credential to a hospital's admission system. For a clinical trial, a sponsor could verify the calibration status of all data-collecting devices. Start by extending the credential schema to include specific attestations like lastServiceDate, calibrationCertificate, or regulatoryApprovalId. Tools like SpruceID's Credible or Veramo can help manage these complex schemas and presentation flows.

To move from prototype to production, focus on key infrastructure: secure key management for device wallets (using HSMs or cloud KMS), credential revocation via smart contract-based registries, and interoperability with existing standards like W3C Decentralized Identifiers (DIDs) and HL7 FHIR for healthcare data. Monitoring the Ethereum Attestation Service (EAS) or IOTA Identity frameworks can provide insights into evolving best practices for on-chain attestations.

Finally, consider the regulatory landscape. A decentralized identity system must facilitate compliance with regulations like HIPAA, GDPR, and FDA's UDI requirements. The architecture's design—keeping personal health information (PHI) off-chain in the holder's custody while anchoring proofs on-chain—is a significant advantage. Document your credential schemas, security audits, and data flow diagrams to streamline compliance reviews with health authorities.