protocol0 0.1 e6aeb8 GitHub Get started
DocumentationPropose and sign

Documentation  /  Build  /  Propose and sign

Propose and sign

A change to a community needs a proposal and enough signatures. This page shows how a member proposes a change and how another member signs it.

1Start a group of 3

The example starts Flood Relief Network with 3 members as the Start a community page shows.

import { ready, newKeyPair, publicOf, syncDirect, Copy } from 'protocol0'

await ready()
const bob = newKeyPair()
const cat = newKeyPair()

const relief = Copy.start({
  key: newKeyPair(),
  me: { name: 'Ann' },
  name: 'Flood Relief Network',
  founders: [
    { name: 'Bob', key: publicOf(bob) },
    { name: 'Cat', key: publicOf(cat) },
  ],
  pages: [{ id: 'fund', name: 'Relief fund', content: 'The fund holds $90,000.' }],
})

2Propose a change

propose takes a title and a change and this change replaces the content of the Relief fund page. The call returns the code of the proposal.

The proposal counts as the signature of the member who wrote it. With 3 members the proposal needs 2 signatures so it starts at 1 and stays open.

const code = relief.propose({
  title: 'Send $40,000 to Hill End',
  change: { type: 'page', page: 'fund', content: 'The fund holds $50,000.' },
})
const open = relief.view().proposals[0]
console.log(open.count + ' of ' + open.size + ' signed so it stays ' + open.status)

The first line the program prints says 1 of 3 signed so it stays open.

3Sign on another copy

Bob loads his own copy from the entries of Ann's copy with Copy.load and signs with sign. The signature names the code of the proposal.

In real use the entries travel through a relay as the Send entries through a relay page shows. This example passes them with syncDirect on 1 computer.

const bobsCopy = Copy.load({ key: bob, items: relief.items() })
bobsCopy.sign(code)
syncDirect(relief, bobsCopy)
const done = relief.view().proposals[0]
console.log(done.count + ' of ' + done.size + ' signed so it is ' + done.status)

With the second signature the program prints 2 of 3 signed so it is decided.

4Read the result

Once a proposal has its number the change takes effect in every copy. The Relief fund page now holds the new words.

A signature cannot be taken back and a member counts once however many keys of that member sign.

const fund = relief.view().pages.find((p) => p.id === 'fund')
console.log(fund?.content)
It prints
1 of 3 signed so it stays open
2 of 3 signed so it is decided
The fund holds $50,000.

The last line the program prints is the new content of the page.

Something wrong on this page