Skip to content

Http Message Queries

Http Message Signatures

Every query is an http message signed by the http message signature scheme RFC9421, which is web standard and also compatible with AO-Core protocol. Each message can specify signature algorithm such as RSA and ECDSA, and will be verified before going into the monadic pipeline of the database core. This enables parallel verification of crypto signatures to increase the tps, as the biggest bottleneck to the compute performance of decentralized databases/blockchains is the signature verification.

const msg = {
  headers:{
    query: JSON.stringify(["set", { name: "Bob"}, "users", "bob"]),
    nonce: 1,
    id: "database_id", // generated by HyperBEAM
    signature: "xyz.....",
    "signature-input":
      "sig=("query" "nonce" "id");keyid="pubkey...";alg="rsa-pss-sha512";..."
  }
}

Each message must include id (a database process id), query and nonce to prevent replay attacks.

NoSQL Queries

The reference implementation of WeaveDB comes with a set of query parser, quary planner, index manager and B+ trees that enable Firestore-like NoSQL database, but fully decentralized.

Example queries:

await db.add({ age: 20, name: "Bob" }, dir_id)
await db.set({ age: 20, name: "Bob" }, dir_id, doc_id)
await db.upsert({ age: 20, name: "Bob" }, dir_id, doc_id)
await db.update({ age: 25 }, dir_id, doc_id)
await db.del(dir_id, doc_id)
await db.addIndex([["age", "desc"], ["name", "asc"]], dir_id)
 
await db.batch([
  ["set", { name: "Bob" }, "people", "Bob"],
  ["upsert", { name: "Alice" }, "people", "Alice"],
  ["del", "John"]
])
 
await db.get(dir_id, doc_id)
await db.get(dir_id, 5) // limit
await db.get(dir_id, ["age", "desc"], ["name", "asc"]) // sort
await db.get(dir_id, ["age"], ["startAfter", 20], ["endAt", 60]) // skip
await db.get(dir_id, ["age"], ["age", ">", 20]) // where

== > >= < <= != in not-in array-contains array-contains-any are supported.