Git Product home page Git Product logo

handbook's Introduction

p2panda

All the things a panda needs


This library provides all tools required to write a client, node or even your own protocol implementation for the p2panda network. It is shipped both as a Rust crate p2panda-rs with WebAssembly bindings and a NPM package p2panda-js with TypeScript definitions running in NodeJS or any modern web browser.

The core p2panda specification is fully functional but still under review so please be prepared for breaking API changes until we reach v1.0. Currently no p2panda implementation has recieved a security audit.

Features

  • Generate Ed25519 key pairs.
  • Create and encode Bamboo entries.
  • Publish schemas and validate data.
  • Create, update and delete data collaboratively.
  • Encrypt data with OpenMLS.
  • Materialise documents from data changes.
  • Prepare data for node servers.

Usage

import { KeyPair } from "p2panda-js";
const keyPair = new KeyPair();
console.log(keyPair.publicKey());
use p2panda_rs::identity::KeyPair;
let key_pair = KeyPair::new();
println!("{}", key_pair.public_key());

See the demo application and its source code. More examples can be found in the p2panda-rs and p2panda-js directories.

Installation

If you are using p2panda in web browsers or NodeJS applications run:

$ npm i p2panda-js

For Rust environments run:

$ cargo add p2panda-rs

Documentation

Visit the corresponding folders for development instructions and documentation:

Benchmarks

Performance benchmarks can be found in benches. You can run them using cargo-criterion:

$ cargo install cargo-criterion
$ cargo criterion
# An HTML report with plots is generated automatically
$ open target/criterion/reports/index.html

These benchmarks can be used to compare the performance across branches by running them first in a base branch and then in the comparison branch. The HTML-reports will include a comparison of the two results.

License

GNU Affero General Public License v3.0 AGPL-3.0-or-later

Supported by



This project has received funding from the European Union’s Horizon 2020 research and innovation programme within the framework of the NGI-POINTER Project funded under grant agreement No 871528 and NGI-ASSURE No 957073

handbook's People

Contributors

adzialocha avatar aljoschameyer avatar cafca avatar dependabot[bot] avatar gers2017 avatar hackmd-deploy avatar link2xt avatar sandreae avatar sophiiistika avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

handbook's Issues

Background task which automatically removes payloads

Have a background task which automatically removes payloads of entries which are “not used” anymore (is it deleted instances? Outdated MLS key packages? etc.), if a sequence between skiplinks is finally empty it should also delete the complete entry, only keeping the skiplink

Built-in schemas

I want to write something about built-in schemas. Which ones do we have?

schema

describes schemas

fields:

  • name
  • description
  • fields (list of field definitions)

persona

fields:

  • username
  • relations (list of relations to other personas, e.g. "same user as..." / same-as or "bot controlled by...")

Ephemeral data

Create self-destructing, ephemeral instances (maybe using encryption / throwing away the key).

  • It could be interesting to build a system where every piece of data has an expiry date (which may be far in the future)
  • It may be interesting to allow setting an expiry date on data explicitly
  • It may be interesting to let node operators configure a node to only store e.g. data that is less than a year old

Specify different permissions for the authors that make up a persona

A way to specify different permissions for the authors that make up a persona. Could be used e.g. to make bots part of your persona (and allow posting on your behalf) but not give them the right to add and remove authors, or just allow them to post using specific schemas.

Think about update messages and underlying data type

Very-random-vague-thinking-which-is-probably-mistaken: are there any interesting parallels between a chain of update messages which form an Instance, and bamboo / Magma / Lava append only logs? This is a raw thought I’ve never managed to follow through properls. But I’ve had it a few times now (maybe many, I can’t remember) so I’d like to discus it and put it to bed for good.

Application schemas

Proposal to add a new system schema with the name "application_schema" to the p2panda spec. The purpose of the application_schema schema is to represent user-defined data schemas. These can be created by developers of applications who want to transmit and store application data using p2panda.

Related: schema migrations

User Stories

Developers can define data schemas for their applications

Alex is a developer and wants to build a blogging application using p2panda. Users of the application will be able to publish blog entries containing text content. Other users can then read these blogs on their own computer.

Alex creates a new schema by publishing a create operation of the schema schema. The operation defines the name "blog", the description "markdown-formatted blog post" and a list of field definitions. The fields defined by Alex are:

  • title
  • body
  • created

After publishing this operation, Alex has created the new blog schema. They can now program their blogging application to create blog instances by publishing operations of the blog schema. When Alex publishes the first blog operation, the p2panda node they use assigns Alex' first unused user log to the new schema. All blog operation created by Alex from now on will be appended to this log.

Alex can configure their p2panda node to track the new schema. Tracking a schema causes the node to materialise blog documents described by blog operation in a database table. The contents of this table can then be queried through the node's API.

Now, Alex can program their blogging application to retrieve blog documents created by all users of their application by querying the node's API. Users of the blogging software can now comfortably read blogs created by other users and write their own blogs.

Developers can reference data that uses another schema in their entries

[tbd]

Schema specification

Following is a CDDL definition of schema operations that builds upon the schema of OperationEncoded

operation-fields /= {
    name: schema-name,
    description: schema-description,
    fields: [+ field-definition]
}

; Every schema has a name, which is limited in length to ensure 
; readability when displayed in logs or listings.
schema-name = tstr .regexp "\w{1,80}"

; Schema descriptions are less constrained but also have a maximum
; length of 256 bytes to keep them concise.
schema-description = tstr .size (1..256)

; Field names have the same length restriction as schema names
field-name = tstr .regexp "\w{1,80}"

; Possible data types are chosen to ensure compatibility with storing
; the data in Postgres databases.
; `datetime` is a ISO8601-formatted string
field-definition /= {
    type: "text" / "int" / "float" / "boolean" / "datetime",
    name: field-name,
}

; The `relation` data type allows referencing documents described by 
; other schemas. This has implications for materialisation: All schemas
; referenced must also be materialised.
field-definition /= {
    type: "relation",
    name: field-name,
    references: hash
}

Naming things

Let's discuss how we are naming stuff.

Instance

We created this name because instances are instances of schemas (which we had thought of before). However, developers coming in contact with p2panda instances for the first time will probably not share this context.

How about:

  • object
  • entity

We can also add more candidates to discuss above.

Maximum payload size for entries / logs / operations

Think about a maximum payload size for entries / logs (blobs), is it configurable or defined on protocol level? Or are these actually two separate things?

This could be configured on a per-schema level so that schema designers can design them explicitly for a specific usage scenario including specific target devices (and schemas can be excluded from replication).

Description of `Persona`, a way to group a set of authors who represent a shared identity

  • content published is identified by being associated with a key pair
  • when multiple devices are used to publish content a solution has been to place a copy of the key pair on each device which introduces all kinds of problems in key pair management
  • instead we create a key pair per device and create another way of modeling identity:
    • when a user initially starts using p2panda using their device D1 they create a persona P, which is linked to their device's key pair - and publish it to the network
    • when they want to use a second device D2 (which creates its own key pair) they publish a message using D2 that declares "i am the same as persona P"
    • when D1 receives this message it notifies the user that there was a "log-in attempt from a new device" and gives them the option to confirm or reject this
    • if the user confirms, D1 publishes a message that says "i accept D2's declaration"
    • now, the clients of other users can lookup the persona associated with the key pairs of D1 and D2, which is the same persona P
  • TBD:
    • users can remove associated devices
    • users can create multiple personas
    • a persona can be shared by multiple users
    • users can block devices from asserting identity with their device
    • users can assign metadata to persona-associations, e.g.
      • "this is P's mobile device"
      • "this device has limited rights"
      • "this device is not allowed to de-associate other key pairs from this persona"
      • "this device is a spokesperson posting on behalf of persona P"
      • "this is a bot posting on behalf of P"
      • "this is a bot controlled by persona P"
      • and others

Schemas

persona

  • name: string

persona-authorization-request

  • persona: hash

persona-authorization

  • request: hash
  • accepted: boolean

Entry encoding validation

Bamboo Entry Encoding

Log Integrity

TODO

Multi-writer updates on instances

  • Specify a pointer at the last entry of an instance you’re applying the update on
  • Specify how we materialize multi-writer instances (they form a DAG)

Operation encoding validation

CBOR

  • Bytes encoded following the CBOR specification: https://datatracker.ietf.org/doc/html/rfc7049
    • We do not make use of CBOR tags
    • SHOULD (Recommendation): Canonical CBOR encoding as per https://datatracker.ietf.org/doc/html/rfc7049#section-3.9
      • Note: If not followed, hashes will be different for the same content on different implementations (test vectors / examples will potentially not work across implementations)
      • Integers must be as small as possible
      • The expression of lengths in major types 2 through 5 must be as
        short as possible
      • The keys in every map must be sorted lowest to highest
      • Indefinite-length items must be made into definite-length items
      • IEEE Floats are used, it is recommended to follow the canonicalization rules by the CBOR specification
    • MUST We use CBOR in "strict" mode
      • Operations not following the rules of "strict" mode need to be rejected
      • This includes:
        • A map (major type 5) can not have duplicate keys
        • Incorrect formatting (value does not represent claimed type)
      • We do not have to worry about tags as we do not use them

Operation Format

  • Map keys must match ^[A-Za-z]{1}[A-Za-z0-9_]{0,63}$
  • Canonical format:
    • Similar to the canonical format of CBOR, p2panda recommends one for operations to assure same hashes across different implementations
    • All array values SHOULD be in sorted order (from lowest to highest)
      • as long as the ordering does not hold semantic value, this is true for:
        • previous_operations
        • document view ids in pinned relations (also the ones inside of lists)
      • Arrays with semantic ordering (not sorted):
        • pinned relation lists
        • relation lists
  • All operations MUST follow the Operation format encoding (version, action, previous_operations, schema, fields), specified here: https://p2panda.org/handbook/docs/writing-data/operations

"Gossip" Discovery

Specify how we do “gossip” discovery (one node told the other that a third exists), does it make sense to put this into a schema? The data inside of it might be very old (IP addresses change …)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.