key-value for private key
A Cloudflare Worker that allows a private key, typically associated with a blockchain wallet, to store arbitrary data in a KV store. Like most blockchains, all data is publicly available. This is not a secure storage solution—only write access is authenticated.
It uses the PFPK auth service as its authentication layer, which lets users manage unique profiles with one or more public key authorized to access them. PFPK generates a UUID (universally unique identifier) for each profile, which KVPK associates key-value pairs with.
To look up a value for a given public key or blockchain address, use PFPK's profile retrieval endpoint to resolve the profile's UUID, and then look it up here.
npm run dev
# OR
wrangler dev --local --persist-
Copy
wrangler.toml.exampletowrangler.toml. -
Create D1 database and update binding in
wrangler.toml:
npx wrangler d1 create kvpkwrangler publish
# OR
npm run deployRequest and response bodies are encoded via JSON.
-
Create a token with the PFPK auth service.
The token must have this service's hostname (probably
kvpk.daodao.zone) as the audience, andadminas the role.See the PFPK auth service docs for more information.
-
Set a bearer token in the
Authorizationheader, like:Authorization: Bearer JWT_TOKEN.
Set the Authorization header to the PFPK auth token as described above.
Set a key-value pair in the KV store. Set value to null to delete a key. Any
other value will be stored and returned identically.
{
"key": string
"value": any | null
}A 204 No Content response is returned on success.
Set the Authorization header to the PFPK auth token as described above.
Set many key-value pairs in the KV store. Set value to null to delete a key.
Any other value will be stored and returned identically.
{
"items": {
"key": string
"value": any | null
}[]
}A 204 No Content response is returned on success.
Set the Authorization header to the PFPK auth token as described above.
Insert a value into an array, creating the array if it doesn't exist. If index
is provided, the value is inserted at the given index. If index is not
provided, the value is appended to the end of the array.
{
"key": string
"value": any
"index": number | undefined
}The new array is returned.
{
"key": string
"value": any
}Set the Authorization header to the PFPK auth token as described above.
Remove a value from an array at the given index.
{
"key": string
"index": number
}The new array is returned.
{
"key": string
"value": any
}No authentication is required.
Get a value for a UUID and key. uuid is the UUID of the user's profile from
the PFPK auth service.
{
"key": string
"value": any | null
}No authentication is required.
List keys with a prefix for a given UUID. uuid is the UUID of the user's
profile from the PFPK auth service.
{
"items": Array<{
"key": string
"value": any
}>
}No authentication is required.
Get the list of UUIDs and values that have a given key set.
{
"items": Array<{
"uuid": string
"value": any
}>
}