Skip to content

DA0-DA0/kvpk

Repository files navigation

kvpk

key-value for private key

A Cloudflare Worker that allows a Cosmos keypair to store arbitrary data in a KV store. Like the blockchain, all data is publicly readable. This is not a secure storage solution.

Used template for Cosmos wallet authentication to authenticate requests via a Cosmos wallet signature.

Development

Run locally

npm run dev
# OR
wrangler dev --local --persist

Configuration

  1. Copy wrangler.toml.example to wrangler.toml.

  2. Create KV namespaces for production and development:

npx wrangler kv:namespace create NONCES
npx wrangler kv:namespace create NONCES --preview

npx wrangler kv:namespace create DATA
npx wrangler kv:namespace create DATA --preview
  1. Update the binding IDs in wrangler.toml:
kv-namespaces = [
  { binding = "NONCES", id = "<INSERT NONCES_ID>", preview_id = "<INSERT NONCES_PREVIEW_ID>" },
  { binding = "DATA", id = "<INSERT DATA_ID>", preview_id = "<INSERT DATA_PREVIEW_ID>" },
]

Deploy

wrangler publish
# OR
npm run deploy

API

See the authentication template's docs on how to authenticate requests with a Cosmos wallet.

POST /set

The request data for this route must be included in the data field that gets signed in the authentication API 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.

Request data:

{
  "key": string
  "value": any | null
}

Response:

{
  "success": true
}

POST /setMany

The request data for this route must be included in the data field that gets signed in the authentication API 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.

Request data:

{
  "data": {
    "key": string
    "value": any | null
  }[]
}

Response:

{
  "success": true
}

GET /get/:publicKey/:key

Get a value from the KV store. publicKey is a hex-encoded Cosmos public key.

Response:

{
  "key": string
  "value": any | null
}

GET /list/:publicKey/:prefix

List keys with a prefix in the KV store. publicKey is a hex-encoded Cosmos public key.

Response:

{
  "items": Array<{
    "key": string
    "value": any
  }>
}

GET /reverse/:key

Get the list of public keys that have a key-value pair with the given key in the KV store. publicKey in the response is a hex-encoded Cosmos public key.

Response:

{
  "items": Array<{
    "publicKey": string
    "value": any
  }>
}

About

key-value for private key

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published