BSV blockchainBSV blockchain

P2P Medical

Open the P2P Medical demo to see how a patient shares an encrypted file with a doctor. A BRC-100BSV Request for Comments 100, the standard interface between apps and wallets wallet encrypts the file for the identity keyThe public key that identifies a wallet to an app. The private key never leaves the wallet of the doctor, UHRPUniversal Hash Resolution Protocol, content storage addressed by the hash of the file stores the encrypted copy, and the app keeps an audit timeline of who shared and viewed it. The demo runs on Mainnet, where the wallet transactions and the storage cost real satoshis. It is hosted at p2p-medical.bsvblockchain.tech, and the source code is in bsv-blockchain-demos/p2p-medical.

Use synthetic files only, never a real medical record. A transaction on Mainnet cannot be undone.

When to use it

Use the P2P Medical demo when you are building an app that shares private files between two identities and you want to see how the parts work together in code.

How it works

A file goes through three steps, from the browser of the patient to the wallet of the doctor.

Encrypt and upload

The patient selects a file and a recipient. The wallet encrypts the file with the identity key of the recipient, and the app uploads the encrypted copy to the UHRP providers that the patient selects.

Share a reference

The app creates a PushDropA script template that stores data fields in an output that only a key holder can spend transaction that holds the metadata of the file, sends the metadata to its backend and tries to notify the doctor with MessageBoxA BSV blockchain service that delivers messages between wallet identities. The hash of the encrypted copy identifies the file and lets the doctor check it, but it does not give access to it.

Verify and decrypt

The doctor downloads the encrypted copy and checks its SHA-256 hash against the metadata. The wallet then decrypts the file with the identity key of the patient and the shared key identifier, so only the wallets of the patient and the doctor can open it.

What the demo records and what it does not guarantee

The demo keeps an audit timeline with the sender, the recipient, the transaction ID, the file and the date of each share and view. The backend stores the share and view events in MongoDB. The viewer records a view after decryption without waiting for it to succeed, so the demo does not guarantee that every view is recorded, and the view events are not on-chain.

The REST routes of the backend accept identity keys from the request body and do not check a wallet signature. Treat the demo as an example of the flow, not as a base for a system that holds real patient data.

Try the hosted demo

You need a BRC-100 wallet, such as BSV Desktop or BSV Browser, connected to Mainnet and funded. To follow the whole flow you need two wallet identities, one for the patient and one for the doctor.

Open p2p-medical.bsvblockchain.tech and click Connect Wallet. The first time an identity connects, the app asks for a profile, and each identity key has one role, patient or doctor.

Run it locally

A local run needs Node.js 22, Docker or a MongoDB instance, and a BRC-100 wallet.

Start the services

In a terminal, clone the repository and start the Docker setup:

git clone https://github.com/bsv-blockchain-demos/p2p-medical.git
cd p2p-medical
docker compose up --build

Docker starts four services:

ServicePort
Frontend3000
Backend3001
MongoDB27017
Block headers service8080

Open the app

Open http://localhost:3000 in your browser and click Connect Wallet.

Without Docker, start MongoDB, copy .env.example to .env in both backend and frontend, and run npm install and npm run dev in each folder.

The frontend uploads to the UHRP provider go-uhrp-us-1.bsvblockchain.tech by default, with nanostore.babbage.systems as a second option, and the patient chooses one or both at upload time. The UHRP code of the frontend is set to Mainnet, and the Docker setup broadcasts through Mainnet ARCA transaction broadcast API of miners. The backend of the demo forwards BEEF transactions to it infrastructure.

How it is built

The demo has a frontend and a backend:

LayerTechnologyWhat it does
FrontendVite, React and TypeScriptShows the interface, encrypts the file through the wallet and lets the patient pick the UHRP providers
BackendExpress and MongoDB, with @bsv/overlay and @bsv/overlay-expressStores the tokens and the audit events, and handles the /submit and /lookup routes of an overlay serviceBuilt from topic managers, which decide what is admitted, and lookup services, which query what was admitted.
Blockchain@bsv/sdkProvides WalletClient, PushDrop and identity resolution
Messaging@bsv/message-box-clientSends the notification to the doctor

The README of the project declares the MIT license.

To learn more about the parts the P2P Medical demo uses on the BSV blockchain, review these articles: