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.
npm run dev
# OR
wrangler dev --local --persist
-
Copy
wrangler.toml.example
towrangler.toml
. -
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
- 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>" },
]
wrangler publish
# OR
npm run deploy
See the authentication template's docs on how to authenticate requests with a Cosmos wallet.
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.
{
"key": string
"value": any | null
}
{
"success": true
}
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.
{
"data": {
"key": string
"value": any | null
}[]
}
{
"success": true
}
Get a value from the KV store. publicKey
is a hex-encoded Cosmos public key.
{
"key": string
"value": any | null
}
List keys with a prefix in the KV store. publicKey
is a hex-encoded Cosmos
public key.
{
"items": Array<{
"key": string
"value": any
}>
}
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.
{
"items": Array<{
"publicKey": string
"value": any
}>
}