@vocdoni/skills 0.6.0 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude-plugin/marketplace.json +27 -15
- package/CHANGELOG.md +22 -0
- package/README.md +38 -24
- package/bin/install.js +13 -2
- package/package.json +1 -1
- package/plugins/agentic-dev/.claude-plugin/plugin.json +1 -1
- package/plugins/agentic-dev/skills/subagent-driven-development/SKILL.md +6 -4
- package/plugins/agentic-dev/skills/subagent-driven-development/references/dispatch.md +6 -1
- package/plugins/agentic-dev/skills/subagent-driven-development/references/ledger.md +8 -5
- package/plugins/agentic-dev/skills/subagent-driven-development/references/models.md +38 -6
- package/plugins/agentic-dev/skills/subagent-driven-development/scripts/init-workspace.sh +1 -0
- package/plugins/agentic-dev/skills/subagent-driven-development/scripts/model-inventory.sh +6 -4
- package/plugins/claude-pi-subagent/plugins/pi-subagent/package-lock.json +4 -3
- package/plugins/vocdoni-contributing/.claude-plugin/plugin.json +2 -2
- package/plugins/vocdoni-contributing/hooks/session-start.sh +1 -1
- package/plugins/vocdoni-contributing/skills/contributing/SKILL.md +33 -6
- package/plugins/vocdoni-go/.claude-plugin/plugin.json +2 -2
- package/plugins/vocdoni-go/skills/vocdoni-backend-review/SKILL.md +522 -0
- package/plugins/vocdoni-go/skills/vocdoni-backend-review/references/prompts.md +260 -0
- package/plugins/vocdoni-go/skills/vocdoni-backend-review/scripts/untracked-list.sh +35 -0
- package/plugins/vocdoni-sdk/.claude-plugin/plugin.json +4 -5
- package/plugins/vocdoni-sdk/skills/vocdoni-ballot-protocol/SKILL.md +61 -38
- package/plugins/vocdoni-sdk/skills/vocdoni-sdk/SKILL.md +35 -21
- package/plugins/vocdoni-sdk/skills/vocdoni-sdk/recipes/approval-vote.ts +3 -3
- package/plugins/vocdoni-sdk/skills/vocdoni-sdk/recipes/basic-poll.ts +6 -6
- package/plugins/vocdoni-sdk/skills/vocdoni-sdk/recipes/csp-vote.ts +12 -7
- package/plugins/vocdoni-sdk/skills/vocdoni-sdk/recipes/multichoice-vote.ts +3 -3
- package/plugins/vocdoni-sdk/skills/vocdoni-sdk/recipes/quadratic-vote.ts +3 -3
- package/plugins/vocdoni-sdk/skills/vocdoni-sdk/recipes/ranked-vote.ts +3 -3
- package/plugins/vocdoni-sdk/skills/vocdoni-sdk/recipes/weighted-census.ts +3 -3
- package/plugins/vocdoni-sdk/skills/vocdoni-sdk/references/accounts.md +26 -15
- package/plugins/vocdoni-sdk/skills/vocdoni-sdk/references/census.md +9 -10
- package/plugins/vocdoni-sdk/skills/vocdoni-sdk/references/client.md +15 -13
- package/plugins/vocdoni-sdk/skills/vocdoni-sdk/references/csp.md +43 -18
- package/plugins/vocdoni-sdk/skills/vocdoni-sdk/references/elections.md +4 -4
- package/plugins/vocdoni-sdk/skills/vocdoni-sdk/references/errors.md +24 -21
- package/plugins/vocdoni-sdk/skills/vocdoni-sdk/references/removed-features.md +98 -0
- package/plugins/vocdoni-sdk/skills/vocdoni-sdk/references/results.md +0 -1
- package/plugins/vocdoni-sdk/skills/vocdoni-sdk/references/voting.md +30 -34
- package/plugins/vocdoni-sequencer/.claude-plugin/plugin.json +21 -0
- package/plugins/vocdoni-sequencer/skills/vocdoni-sequencer/SKILL.md +169 -0
- package/plugins/vocdoni-sequencer/skills/vocdoni-sequencer/references/removed-routes.md +60 -0
- package/plugins/davinci-sdk/.claude-plugin/plugin.json +0 -13
- package/plugins/davinci-sdk/skills/davinci-sdk/SKILL.md +0 -120
- package/plugins/davinci-sdk/skills/davinci-sdk/recipes/bootstrap.ts +0 -61
- package/plugins/davinci-sdk/skills/davinci-sdk/recipes/cast-vote.ts +0 -78
- package/plugins/davinci-sdk/skills/davinci-sdk/recipes/create-process.ts +0 -102
- package/plugins/davinci-sdk/skills/davinci-sdk/recipes/full-election.ts +0 -128
- package/plugins/davinci-sdk/skills/davinci-sdk/recipes/read-results.ts +0 -73
- package/plugins/davinci-sdk/skills/davinci-sdk/recipes/token-census.ts +0 -111
- package/plugins/davinci-sdk/skills/davinci-sdk/references/ballot-modes.md +0 -125
- package/plugins/davinci-sdk/skills/davinci-sdk/references/census.md +0 -168
- package/plugins/davinci-sdk/skills/davinci-sdk/references/contracts.md +0 -133
- package/plugins/davinci-sdk/skills/davinci-sdk/references/errors.md +0 -83
- package/plugins/davinci-sdk/skills/davinci-sdk/references/process.md +0 -225
- package/plugins/davinci-sdk/skills/davinci-sdk/references/protocol.md +0 -65
- package/plugins/davinci-sdk/skills/davinci-sdk/references/sequencer.md +0 -135
- package/plugins/davinci-sdk/skills/davinci-sdk/references/setup.md +0 -123
- package/plugins/davinci-sdk/skills/davinci-sdk/references/voting.md +0 -128
- package/plugins/vocdoni-sdk/skills/vocdoni-sdk/recipes/anonymous-vote.ts +0 -108
- package/plugins/vocdoni-sdk/skills/vocdoni-sdk/recipes/token-census.ts +0 -121
- package/plugins/vocdoni-sdk/skills/vocdoni-sdk/references/anonymous.md +0 -183
- package/plugins/vocdoni-sdk/skills/vocdoni-sdk/references/census3.md +0 -308
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: vocdoni-sequencer
|
|
3
|
+
description: Use this skill when calling, running or debugging the Vochain node behind the Vocdoni SaaS API - vocdoni-sequencer, its voconed binary and the ghcr.io/vocdoni/vocdoni-sequencer image - which replaced the archived vocdoni-node (go.vocdoni.io/dvote) and its vocone. Triggers on voconed, vocdoni-sequencer, vochain-sequencer, vocone, the Vochain /v2 API, vocdoni-node, go.vocdoni.io/dvote apiclient calls from saas-backend, VOCONED_* environment variables, `voconed migrate`, Postgres errors at node startup, HTTP 410 "endpoint removed" (code 4067), "anonymous process not supported", "census origin ... not supported for new process", "invalid vote:" rejections at submission, minValue/minTotalCost/costExponent election errors, funded accounts and faucet packages, and running a local Vochain for integration tests. Covers what changed for /v2 consumers and how to run it. It is NOT about Davinci: davinci-node, the Davinci "sequencer" and @vocdoni/davinci-sdk are a different protocol.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# vocdoni-sequencer (voconed)
|
|
7
|
+
|
|
8
|
+
**Rule: before acting on "the sequencer", check which one is meant.** `vocdoni/vocdoni-sequencer`
|
|
9
|
+
is the minimal single-node Vochain: the `voconed` binary serving the `/v2` API that the archived
|
|
10
|
+
`vocdoni/vocdoni-node` served. It has nothing to do with Davinci.
|
|
11
|
+
|
|
12
|
+
| Name in the task | What it is | Go here |
|
|
13
|
+
| --- | --- | --- |
|
|
14
|
+
| voconed, vocone, Vochain, `/v2` API, saas-backend's chain | `vocdoni/vocdoni-sequencer` (formerly `vochain-sequencer`; GitHub redirects the old name) | this skill |
|
|
15
|
+
| vocdoni-node, `go.vocdoni.io/dvote` node | archived predecessor; its API contract lives on in voconed | this skill |
|
|
16
|
+
| davinci-node, Davinci "sequencer", zk ballots, `@vocdoni/davinci-sdk` | Davinci protocol node, whose own repo calls it "the sequencer" | [[davinci-sdk]] |
|
|
17
|
+
|
|
18
|
+
Why it matters: the names collide. An agent told to "use the vocdoni sequencer" once ended up on
|
|
19
|
+
davinci-node. If the task mentions `voconed`, `/v2`, saas-backend or `@vocdoni/sdk`, it is this
|
|
20
|
+
repo.
|
|
21
|
+
|
|
22
|
+
Who talks to it: saas-backend through `go.vocdoni.io/dvote`'s `apiclient`, the legacy
|
|
23
|
+
[[vocdoni-sdk]] over `/v2`, and explorers. The [[vocdoni-integrator-sdk]] does not: it talks to
|
|
24
|
+
saas-backend's API only, although its integration stack runs voconed behind saas-backend.
|
|
25
|
+
|
|
26
|
+
Contributing to the sequencer itself (CI commands, gofumpt, downstream `/integration` pinning) is
|
|
27
|
+
covered by the repo's own `AGENTS.md`; read that instead.
|
|
28
|
+
|
|
29
|
+
## What changed for a /v2 consumer
|
|
30
|
+
|
|
31
|
+
The API keeps vocdoni-node's contract: same routes, fields and error JSON
|
|
32
|
+
(`{"error":"...","code":N}`). The differences:
|
|
33
|
+
|
|
34
|
+
**1. Removed routes answer 410, not 404.** 35 vocdoni-node routes stay registered and return HTTP
|
|
35
|
+
410, code 4067, with the reason in the message:
|
|
36
|
+
|
|
37
|
+
```json
|
|
38
|
+
{"error":"endpoint removed: GET /elections/page/{page}: use GET /elections?page={page}","code":4067}
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
Most are `/page/{page}` and `/count` paths replaced by `?page=` query parameters and
|
|
42
|
+
`pagination.totalItems` or a count field. The full table is in
|
|
43
|
+
[references/removed-routes.md](references/removed-routes.md). Fix the caller; do not retry.
|
|
44
|
+
|
|
45
|
+
**2. No anonymous (ZK) voting.** `GET /chain/info/circuit` and `/siks/*` return 410. A new
|
|
46
|
+
election with `envelopeType.anonymous` is rejected with `anonymous process not supported`.
|
|
47
|
+
|
|
48
|
+
**3. Only four census origins.** New elections accept `OFF_CHAIN_TREE`,
|
|
49
|
+
`OFF_CHAIN_TREE_WEIGHTED`, `OFF_CHAIN_CA` and `OFF_CHAIN_CA_V2` (CSP). Any other origin, token
|
|
50
|
+
censuses included, fails with `census origin <X> not supported for new process`; a vote on one
|
|
51
|
+
fails with `census origin not compatible`. Census3 is down (its host answers 404 everywhere), so
|
|
52
|
+
`VocdoniCensus3Client` and token censuses are dead code.
|
|
53
|
+
|
|
54
|
+
**4. No IPFS.** The IPFS census routes are gone; censuses move with the admin-only
|
|
55
|
+
`GET /censuses/export` and `POST /censuses/import`. Election and account metadata keep the
|
|
56
|
+
vocdoni-node routes and CIDs, but the node stores the documents in Postgres instead of IPFS.
|
|
57
|
+
|
|
58
|
+
**5. No faucet, and most of the wallet API is gone.** `GET /open/claim/{to}`,
|
|
59
|
+
`GET /wallet/bootstrap`, `POST /wallet/election` and `GET /wallet/transfer/{dstAddress}/{amount}`
|
|
60
|
+
return 410. `POST /wallet/add/{privateKey}` still works (200 with `{token, address}` and
|
|
61
|
+
deprecation headers), because `@vocdoni/sdk` calls it before creating a census; census creation is
|
|
62
|
+
not broken. Tokens come from accounts funded at genesis, which sign faucet packages
|
|
63
|
+
(`vochain.GenerateFaucetPackage`) for the accounts they fund. saas-backend does this for every
|
|
64
|
+
organization it creates.
|
|
65
|
+
|
|
66
|
+
**6. Plaintext ballots are validated at submission.** In an election without encrypted votes, a
|
|
67
|
+
ballot the tally would skip is now rejected when sent, and the error message carries
|
|
68
|
+
`invalid vote: <rule>` (or `cannot decode vote package: ...`). vocdoni-node accepted it and
|
|
69
|
+
silently dropped it at the tally. Encrypted (`secretUntilTheEnd`) ballots cannot be decoded at
|
|
70
|
+
submission and are still only checked at the tally. A client that relied on bad ballots
|
|
71
|
+
"succeeding" now gets an error; fix the ballot, not the check.
|
|
72
|
+
|
|
73
|
+
**7. Ballot minimums exist on chain.** `ProcessVoteOptions` gained `minValue` and `minTotalCost`
|
|
74
|
+
(0 means no minimum), shown in `tallyMode` by `GET /elections/{id}`. Election creation rejects:
|
|
75
|
+
|
|
76
|
+
```
|
|
77
|
+
minValue 2 greater than maxValue 1
|
|
78
|
+
minTotalCost 20 greater than maxTotalCost 10
|
|
79
|
+
costExponent 10000 greater than 8 # only when minTotalCost > 0
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
`costExponent` is the plain integer power in `sum(v^costExponent)`. The cap of 8 applies only
|
|
83
|
+
with `minTotalCost > 0`, so old SDKs' inert default of 10000 still works on elections without a
|
|
84
|
+
minimum. A plaintext ballot below a minimum is rejected at submission (`invalid vote: min value
|
|
85
|
+
underflow 0`, `invalid vote: min total cost underflow: 1`); an encrypted one is accepted and then
|
|
86
|
+
skipped at the tally: only the tally's Info log counts it as skipped (the reason is debug-only),
|
|
87
|
+
and no error reaches the voter or the API.
|
|
88
|
+
See [[vocdoni-ballot-protocol]] for the full ballot model.
|
|
89
|
+
|
|
90
|
+
**8. Vote resends are decided by the vote record.** Resending the signed vote that currently
|
|
91
|
+
counts returns 200 and the vote ID; resending one a later vote superseded is rejected with
|
|
92
|
+
`superseded by a later vote`. The ID excludes the signature, so re-encoding it changes nothing.
|
|
93
|
+
|
|
94
|
+
## Running it locally
|
|
95
|
+
|
|
96
|
+
voconed keeps all state (chain, block store, mempool, indexer) in Postgres. There is no data
|
|
97
|
+
directory. Three things are required: `VOCONED_PG_DSN`, a schema migrated by `voconed migrate`,
|
|
98
|
+
and `VOCONED_KEYMANAGER` (required on the default `candidate` role).
|
|
99
|
+
|
|
100
|
+
```yaml
|
|
101
|
+
services:
|
|
102
|
+
postgres:
|
|
103
|
+
image: postgres:17-alpine
|
|
104
|
+
environment: { POSTGRES_PASSWORD: vocone, POSTGRES_DB: voconed }
|
|
105
|
+
healthcheck: { test: ["CMD", "pg_isready", "-U", "postgres"], interval: 2s, retries: 30 }
|
|
106
|
+
|
|
107
|
+
voconed-migrate: # one-shot and idempotent
|
|
108
|
+
image: ghcr.io/vocdoni/vocdoni-sequencer:main
|
|
109
|
+
command: ["migrate"]
|
|
110
|
+
environment:
|
|
111
|
+
VOCONED_PG_DSN: postgres://postgres:vocone@postgres:5432/voconed?sslmode=disable
|
|
112
|
+
depends_on: { postgres: { condition: service_healthy } }
|
|
113
|
+
|
|
114
|
+
voconed:
|
|
115
|
+
image: ghcr.io/vocdoni/vocdoni-sequencer:main
|
|
116
|
+
environment:
|
|
117
|
+
VOCONED_PG_DSN: postgres://postgres:vocone@postgres:5432/voconed?sslmode=disable
|
|
118
|
+
VOCONED_KEYMANAGER: "<64 hex chars, any test key>"
|
|
119
|
+
VOCONED_LISTENHOST: 0.0.0.0 # default 127.0.0.1 is unreachable from other containers
|
|
120
|
+
VOCONED_CHAIN_ID: dev
|
|
121
|
+
VOCONED_CHAIN_BLOCKPERIOD: 1
|
|
122
|
+
VOCONED_CHAIN_FUNDEDACCOUNTS: "0x<address of your backend key>:100000000"
|
|
123
|
+
VOCONED_CHAIN_TXCOSTS: 2
|
|
124
|
+
VOCONED_CHAIN_SETTXCOSTS: "true"
|
|
125
|
+
depends_on: { voconed-migrate: { condition: service_completed_successfully } }
|
|
126
|
+
healthcheck: { test: ["CMD", "curl", "-sf", "http://localhost:9090/v2/chain/info"], interval: 3s, retries: 120 }
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
Point the client at `http://voconed:9090/v2` (saas-backend: `VOCDONI_VOCDONIAPI`).
|
|
130
|
+
|
|
131
|
+
Environment variable names are `VOCONED_` plus the flag name upper-cased, dots as underscores:
|
|
132
|
+
`--pg.dsn` is `VOCONED_PG_DSN`, `--chain.fundedAccounts` is `VOCONED_CHAIN_FUNDEDACCOUNTS`.
|
|
133
|
+
`voconed --help` lists every flag. Defaults: `--listenPort 9090`, `--urlPath /v2`,
|
|
134
|
+
`--chain.id vocone`.
|
|
135
|
+
|
|
136
|
+
Pitfalls:
|
|
137
|
+
|
|
138
|
+
- **Old flat names are ignored.** `VOCONED_DSN`, `VOCONED_PORT`, `VOCONED_LISTEN`,
|
|
139
|
+
`VOCONED_BLOCKPERIOD`, `VOCONED_FUNDEDACCOUNTS`, `VOCONED_CHAINID` and similar no longer match a
|
|
140
|
+
flag. The node logs `unknown setting VOCONED_DSN ignored` and then fails for lack of a DSN. Some
|
|
141
|
+
compose files still carry them; rename to the dotted form.
|
|
142
|
+
- **Schema out of date:** the node refuses to start with `... run voconed migrate`. Run the
|
|
143
|
+
migrate service again after pulling a new image.
|
|
144
|
+
- **Funded accounts apply only when the chain is created.** Changing them on an existing chain is
|
|
145
|
+
ignored with a warning. Reset by dropping the Postgres database or volume, not a run directory.
|
|
146
|
+
- **`:main` moves on every push to the sequencer's `main`.** Pin `:<sha8>` or `:vX.Y.Z` when a
|
|
147
|
+
test needs a fixed node; `:stage` and `:lts` follow those branches.
|
|
148
|
+
- voconed serves plain HTTP. In any shared deployment keep it on loopback behind a TLS proxy and
|
|
149
|
+
never publish port 9090 to the Internet.
|
|
150
|
+
|
|
151
|
+
## Environments
|
|
152
|
+
|
|
153
|
+
The repo's API docs (`api/docs/descriptions/api.md`) list the public `/v2` endpoints:
|
|
154
|
+
|
|
155
|
+
| Environment | URL |
|
|
156
|
+
| --- | --- |
|
|
157
|
+
| Production | `https://api.vocdoni.io/v2` |
|
|
158
|
+
| Staging | `https://api-stg.vocdoni.net/v2` |
|
|
159
|
+
| Development | `https://api-dev.vocdoni.net/v2` |
|
|
160
|
+
|
|
161
|
+
DEV, STG and LTS (production) all run voconed. `GET /v2/chain/info` returns the live chain ID;
|
|
162
|
+
read it rather than hardcoding one, since chains are bumped.
|
|
163
|
+
|
|
164
|
+
## Related skills
|
|
165
|
+
|
|
166
|
+
- [[vocdoni-ballot-protocol]]: the ballot and results model this node enforces at submission and tally.
|
|
167
|
+
- [[vocdoni-sdk]]: the legacy TypeScript client of this `/v2` API.
|
|
168
|
+
- [[vocdoni-integrator-sdk]]: talks to saas-backend, never to the chain directly.
|
|
169
|
+
- [[davinci-sdk]]: the Davinci protocol and its own, unrelated, "sequencer".
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
# vocdoni-node routes voconed does not serve
|
|
2
|
+
|
|
3
|
+
Source: `api/removed.go` in `vocdoni/vocdoni-sequencer`. Paths are relative to the API prefix
|
|
4
|
+
(`/v2` by default). Every route below still answers, with HTTP 410 and API error code 4067:
|
|
5
|
+
|
|
6
|
+
```json
|
|
7
|
+
{"error":"endpoint removed: GET /chain/info/circuit: anonymous voting is not supported","code":4067}
|
|
8
|
+
```
|
|
9
|
+
|
|
10
|
+
The message is `endpoint removed: <METHOD> <path>: <reason>`. Most reasons name the replacement:
|
|
11
|
+
a `/page/{page}` path became a `?page=` query parameter, and a `/count` route became a field of
|
|
12
|
+
another response or `pagination.totalItems`.
|
|
13
|
+
|
|
14
|
+
## Paginated lists and counters (replacement exists)
|
|
15
|
+
|
|
16
|
+
| Removed | Use instead |
|
|
17
|
+
| --- | --- |
|
|
18
|
+
| `GET /accounts/count` | `GET /accounts`, field `pagination.totalItems` |
|
|
19
|
+
| `GET /accounts/page/{page}` | `GET /accounts?page={page}` |
|
|
20
|
+
| `GET /accounts/{accountId}/fees/page/{page}` | `GET /chain/fees?accountId={accountId}&page={page}` |
|
|
21
|
+
| `GET /accounts/{accountId}/transfers/count` | `transfersCount` from `GET /accounts/{accountId}` |
|
|
22
|
+
| `GET /accounts/{accountId}/transfers/page/{page}` | `GET /chain/transfers?accountId={accountId}&page={page}` |
|
|
23
|
+
| `GET /accounts/{organizationId}/elections/count` | `GET /elections?organizationId={organizationId}`, field `pagination.totalItems` |
|
|
24
|
+
| `GET /accounts/{organizationId}/elections/page/{page}` | `GET /elections?organizationId={organizationId}&page={page}` |
|
|
25
|
+
| `GET /accounts/{organizationId}/elections/status/{status}/page/{page}` | `GET /elections?organizationId={organizationId}&status={status}&page={page}` |
|
|
26
|
+
| `GET /chain/blocks/{height}/transactions/page/{page}` | `GET /chain/transactions?height={height}&page={page}` |
|
|
27
|
+
| `GET /chain/fees/page/{page}` | `GET /chain/fees?page={page}` |
|
|
28
|
+
| `GET /chain/fees/reference/{reference}/page/{page}` | `GET /chain/fees?reference={reference}&page={page}` |
|
|
29
|
+
| `GET /chain/fees/type/{type}/page/{page}` | `GET /chain/fees?type={type}&page={page}` |
|
|
30
|
+
| `GET /chain/organizations/count` | `organizationCount` from `GET /chain/info` |
|
|
31
|
+
| `POST /chain/organizations/filter/page/{page}` | `GET /chain/organizations?organizationId={id}&page={page}` |
|
|
32
|
+
| `GET /chain/organizations/page/{page}` | `GET /chain/organizations?page={page}` |
|
|
33
|
+
| `GET /chain/transactions/count` | `transactionCount` from `GET /chain/info` |
|
|
34
|
+
| `GET /chain/transactions/page/{page}` | `GET /chain/transactions?page={page}` |
|
|
35
|
+
| `GET /chain/transactions/{height}/{index}` | `GET /chain/transactions?height={height}` (items carry `index` and `hash`), then `GET /chain/transactions/{hash}` |
|
|
36
|
+
| `POST /elections/filter` | `GET /elections` with query parameters |
|
|
37
|
+
| `POST /elections/filter/page/{page}` | `GET /elections` with query parameters and `page={page}` |
|
|
38
|
+
| `GET /elections/page/{page}` | `GET /elections?page={page}` |
|
|
39
|
+
| `GET /elections/{electionId}/votes/count` | `voteCount` from `GET /elections/{electionId}` |
|
|
40
|
+
| `GET /elections/{electionId}/votes/page/{page}` | `GET /votes?electionId={electionId}&page={page}` |
|
|
41
|
+
|
|
42
|
+
## Features that are gone (no replacement)
|
|
43
|
+
|
|
44
|
+
| Removed | Reason in the 410 message |
|
|
45
|
+
| --- | --- |
|
|
46
|
+
| `GET /chain/info/circuit` | anonymous voting is not supported |
|
|
47
|
+
| `GET /siks/{address}` | anonymous voting is not supported |
|
|
48
|
+
| `GET /siks/proof/{address}` | anonymous voting is not supported |
|
|
49
|
+
| `GET /siks/roots` | anonymous voting is not supported |
|
|
50
|
+
| `GET /censuses/export/ipfs` | this node does not use IPFS, use `GET /censuses/export` and `POST /censuses/import` |
|
|
51
|
+
| `GET /censuses/export/ipfs/list` | same as above |
|
|
52
|
+
| `GET /censuses/import/{ipfscid}` | same as above |
|
|
53
|
+
| `GET /chain/export/indexer` | exporting the indexer is not available |
|
|
54
|
+
| `GET /open/claim/{to}` | this node has no faucet: a funded account signs the faucet package (`vochain.GenerateFaucetPackage`) |
|
|
55
|
+
| `GET /wallet/bootstrap` | the wallet API is not available |
|
|
56
|
+
| `POST /wallet/election` | the wallet API is not available |
|
|
57
|
+
| `GET /wallet/transfer/{dstAddress}/{amount}` | the wallet API is not available |
|
|
58
|
+
|
|
59
|
+
`GET /censuses/export` and `POST /censuses/import` are admin routes (`--adminToken`), not public
|
|
60
|
+
ones (`api/censuses.go`).
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "davinci-sdk",
|
|
3
|
-
"version": "0.1.0",
|
|
4
|
-
"description": "Reference for the Vocdoni Davinci SDK (@vocdoni/davinci-sdk): the high-level DavinciSDK facade for the zk-based voting protocol — create a process, cast encrypted (ElGamal + zk-SNARK) votes, build any census (Merkle/dynamic/CSP/on-chain), configure ballot modes, drive lifecycle, and read results. Includes per-topic references, protocol grounding, and copy-pasteable runnable recipes for the full create-process → encrypted-vote → results flow.",
|
|
5
|
-
"author": {
|
|
6
|
-
"name": "Vocdoni",
|
|
7
|
-
"url": "https://vocdoni.io"
|
|
8
|
-
},
|
|
9
|
-
"homepage": "https://github.com/vocdoni/skills",
|
|
10
|
-
"repository": "https://github.com/vocdoni/skills",
|
|
11
|
-
"license": "AGPL-3.0-or-later",
|
|
12
|
-
"keywords": ["claude-code", "skills", "vocdoni", "davinci", "voting", "zk", "blockchain"]
|
|
13
|
-
}
|
|
@@ -1,120 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
name: davinci-sdk
|
|
3
|
-
description: Use this skill whenever the user is building, debugging, or asking about code that uses the Vocdoni Davinci SDK (`@vocdoni/davinci-sdk`) — the TypeScript SDK for the Davinci zk-based voting protocol. Triggers on imports from `@vocdoni/davinci-sdk`; mentions of the `DavinciSDK` class, `createProcess` / `submitVote` / `waitForVoteStatus`, the census classes (`OffchainCensus`, `CspCensus`, `OnchainCensus`, `PublishedCensus`), `CensusOrigin`, `VoteStatus` / `TxStatus`, `ProcessRegistryService`, the sequencer or census services, encrypted/homomorphic ballots, zk-SNARK ballot proofs, ballot modes (approval/ranked/quadratic/budget), token-holder / on-chain censuses, or CSP voting. Also load it for high-level intents like "create an election", "let users vote privately", "encrypt a ballot", or "submit a vote to the sequencer" — the SDK has specific class/method shapes (a high-level `DavinciSDK` facade, a two-status async vote flow, and a parametric ballot model) the agent will not recall accurately unaided.
|
|
4
|
-
---
|
|
5
|
-
|
|
6
|
-
# Davinci SDK (`@vocdoni/davinci-sdk`)
|
|
7
|
-
|
|
8
|
-
The TypeScript SDK for **Davinci**, Vocdoni's zk-based voting protocol. It runs private, verifiable elections where ballots are **homomorphically encrypted** (ElGamal) and accompanied by **zk-SNARK validity proofs**, collected and aggregated off-chain by a **sequencer**, with canonical state and results anchored in **Ethereum smart contracts**.
|
|
9
|
-
|
|
10
|
-
The SDK ships a single high-level facade, **`DavinciSDK`**, that orchestrates all of this. Almost every task goes through it. Lower-level services (`ProcessRegistryService`, the sequencer/census REST clients, the crypto primitives) exist and are reachable, but you reach for them only when the facade doesn't cover a case.
|
|
11
|
-
|
|
12
|
-
This is the entry point. Read the section matching the task, load the matching `references/` file for the exhaustive API, and lift a `recipes/` file when you need a complete working flow.
|
|
13
|
-
|
|
14
|
-
## How to use this skill
|
|
15
|
-
|
|
16
|
-
1. **Find the area** in the task → reference table below.
|
|
17
|
-
2. **Read only the references you need** — most tasks need 1–3.
|
|
18
|
-
3. **Start from a recipe** when one fits; adapt rather than reinvent the boilerplate.
|
|
19
|
-
4. **Respect the exact shapes.** The facade hides most cryptography, but the public shapes still have sharp edges: a single root import (no subpaths), a `choices: number[]` ballot model whose length must equal `ballot.numFields`, two *different* status enums (`TxStatus` for on-chain transactions, `VoteStatus` for vote processing), and `bigint` results. The references spell these out.
|
|
20
|
-
|
|
21
|
-
## Task → reference
|
|
22
|
-
|
|
23
|
-
| Goal | Read | Recipe |
|
|
24
|
-
| ----------------------------------------------------------------- | ----------------------------------------------------- | ---------------------------- |
|
|
25
|
-
| Install, construct & `init()` the SDK, signer vs provider, env | `references/setup.md` | `recipes/bootstrap.ts` |
|
|
26
|
-
| Create a process/election; lifecycle (end/pause/cancel/resume) | `references/process.md` | `recipes/create-process.ts` |
|
|
27
|
-
| Choose & build a census (Merkle, dynamic, CSP, on-chain, prebuilt)| `references/census.md` | `recipes/create-process.ts` |
|
|
28
|
-
| Cast an encrypted vote; check/await status; eligibility | `references/voting.md` | `recipes/cast-vote.ts` |
|
|
29
|
-
| Configure a voting system (approval/ranked/quadratic/budget…) | `references/ballot-modes.md` | — |
|
|
30
|
-
| Token-holder / on-chain (ERC20/721) census | `references/census.md` | `recipes/token-census.ts` |
|
|
31
|
-
| Read results / tally; vote & voter counts | `references/process.md` | `recipes/read-results.ts` |
|
|
32
|
-
| Talk to the sequencer REST API directly (`sdk.api.sequencer`) | `references/sequencer.md` | — |
|
|
33
|
-
| Drop to the raw contract service (`sdk.processes`) | `references/contracts.md` | — |
|
|
34
|
-
| Debug a runtime error / revert / proof / "not accepting votes" | `references/errors.md` | — |
|
|
35
|
-
| Understand the protocol itself (crypto, lifecycle, why) | `references/protocol.md` | — |
|
|
36
|
-
| Run the whole thing end to end | — | `recipes/full-election.ts` |
|
|
37
|
-
|
|
38
|
-
## Package shape
|
|
39
|
-
|
|
40
|
-
`@vocdoni/davinci-sdk` is published with a **single root export** — there are *no* `/sequencer`, `/contracts`, or `/core` subpaths. Import everything from the root:
|
|
41
|
-
|
|
42
|
-
```ts
|
|
43
|
-
import {
|
|
44
|
-
DavinciSDK, // the facade you'll use 95% of the time
|
|
45
|
-
OffchainCensus, // + OffchainDynamicCensus, CspCensus, OnchainCensus, PublishedCensus
|
|
46
|
-
CensusOrigin, // enum: OffchainStatic=1, OffchainDynamic=2, Onchain=3, CSP=4
|
|
47
|
-
VoteStatus, // pending | verified | aggregated | processed | settled | error
|
|
48
|
-
TxStatus, // pending | completed | reverted | failed
|
|
49
|
-
} from "@vocdoni/davinci-sdk";
|
|
50
|
-
```
|
|
51
|
-
|
|
52
|
-
It depends on **ethers v6**, `@noble/curves`, `@noble/hashes`, `circomlibjs`, and `snarkjs`. Node ≥ 18 (global `fetch`) or a browser.
|
|
53
|
-
|
|
54
|
-
> ⚠️ If you see code importing `@vocdoni/davinci-sdk/sequencer`, `OrganizationRegistryService`, `VocdoniContracts`, or `deployedAddresses`, it is **wrong / from an older imagined API**. None of those exist. There is no "organization" object in this SDK — the process creator is simply the signer's Ethereum address.
|
|
55
|
-
|
|
56
|
-
## Mental model
|
|
57
|
-
|
|
58
|
-
- **One facade, three actors.** The `DavinciSDK` instance acts as whoever its `signer` is. The *organizer* (a signer with a provider) calls `createProcess` and the lifecycle methods. A *voter* (a signer, no provider needed) calls `submitVote`. The *sequencer* is a remote service you talk to via REST — you never run it. To act as a different person, construct a second `DavinciSDK` with that wallet.
|
|
59
|
-
- **Two transports, hidden behind the facade.** Canonical state lives in Ethereum contracts (ethers v6); the heavy off-chain work (proof verification, aggregation) is done by the sequencer (REST). `createProcess` coordinates both; you don't.
|
|
60
|
-
- **`init()` is mandatory.** Every facade method throws until you `await sdk.init()`. `init()` resolves contract addresses from the sequencer's `/info` and wires the services.
|
|
61
|
-
- **Signer with provider ⇒ on-chain ops; signer alone ⇒ voting only.** `createProcess`, `getProcess`, and lifecycle methods need `signer.provider`. `submitVote`, `getVoteStatus`, `hasAddressVoted` do not — a bare `new Wallet(pk)` is fine for voting.
|
|
62
|
-
- **The encrypted vote is two-phase, and the SDK does the crypto for you.** `submitVote({ processId, choices })` builds the ballot, ElGamal-encrypts it against the process key, generates the zk-SNARK proof with `snarkjs` (downloading circuits from the sequencer once, then caching), signs, and submits. It returns a `voteId` with an initial `VoteStatus`. The vote only *counts* after the sequencer drives it to `settled` — always `waitForVoteStatus`.
|
|
63
|
-
- **`choices` is `number[]`, length === `ballot.numFields`.** Each entry is the value for one ballot field. A single-choice question with N options is encoded as N one-hot fields (`[0,1,0,0]`). Multi-question elections concatenate the fields. See `references/ballot-modes.md`.
|
|
64
|
-
- **Two status enums, don't mix them.** On-chain transactions (process create/end/pause/…) report `TxStatus` (`pending|completed|reverted|failed`). Vote processing reports `VoteStatus` (`pending|verified|aggregated|processed|settled|error`).
|
|
65
|
-
- **Numbers: `choices`/`maxVoters`/`numFields`/`costExponent` are `number`; ballot bounds (`maxValue`/`minValue`/`maxValueSum`/`minValueSum`) are decimal **strings**; on-chain results/weights come back as `bigint` (or numeric strings from the sequencer).**
|
|
66
|
-
|
|
67
|
-
## The SDK in ~25 lines (single yes/no question)
|
|
68
|
-
|
|
69
|
-
```ts
|
|
70
|
-
import { JsonRpcProvider, Wallet } from "ethers";
|
|
71
|
-
import { DavinciSDK, OffchainCensus, VoteStatus } from "@vocdoni/davinci-sdk";
|
|
72
|
-
|
|
73
|
-
// 1. Organizer SDK — signer WITH a provider (on-chain ops need it).
|
|
74
|
-
const organizer = new Wallet(process.env.PRIVATE_KEY!, new JsonRpcProvider(process.env.RPC_URL));
|
|
75
|
-
const sdk = new DavinciSDK({
|
|
76
|
-
signer: organizer,
|
|
77
|
-
sequencerUrl: process.env.SEQUENCER_API_URL!, // e.g. https://sequencer-dev.davinci.vote
|
|
78
|
-
censusUrl: process.env.CENSUS_API_URL!, // needed to publish a Merkle census
|
|
79
|
-
});
|
|
80
|
-
await sdk.init();
|
|
81
|
-
|
|
82
|
-
// 2. Census of eligible voters (auto-published during createProcess).
|
|
83
|
-
const census = new OffchainCensus();
|
|
84
|
-
census.add(["0xVoterA…", "0xVoterB…"]); // weight defaults to 1
|
|
85
|
-
|
|
86
|
-
// 3. Create the process. One question, two options → 2 one-hot ballot fields.
|
|
87
|
-
const { processId } = await sdk.createProcess({
|
|
88
|
-
title: "Is the sky blue?",
|
|
89
|
-
census, // maxVoters auto = participant count
|
|
90
|
-
ballot: { numFields: 2, minValue: "0", maxValue: "1",
|
|
91
|
-
uniqueValues: false, costExponent: 1, minValueSum: "0", maxValueSum: "1" },
|
|
92
|
-
timing: { duration: 3600 }, // startDate defaults to now+60s
|
|
93
|
-
questions: [{ title: "Pick one",
|
|
94
|
-
choices: [{ title: "Yes", value: 0 }, { title: "No", value: 1 }] }],
|
|
95
|
-
});
|
|
96
|
-
|
|
97
|
-
// 4. Vote AS a voter — a fresh SDK with the voter's wallet (no provider needed).
|
|
98
|
-
const voterSdk = new DavinciSDK({ signer: new Wallet(VOTER_PK),
|
|
99
|
-
sequencerUrl: process.env.SEQUENCER_API_URL!, censusUrl: process.env.CENSUS_API_URL! });
|
|
100
|
-
await voterSdk.init();
|
|
101
|
-
const { voteId } = await voterSdk.submitVote({ processId, choices: [1, 0] }); // votes "Yes"
|
|
102
|
-
await voterSdk.waitForVoteStatus(processId, voteId, VoteStatus.Settled);
|
|
103
|
-
|
|
104
|
-
// 5. Read results (bigint per ballot field).
|
|
105
|
-
const info = await sdk.getProcess(processId);
|
|
106
|
-
console.log(info.result); // e.g. [ 1n, 0n ] → 1 vote on field 0 ("Yes")
|
|
107
|
-
```
|
|
108
|
-
|
|
109
|
-
The full, runnable version with real-time status streaming is `recipes/full-election.ts`. Don't hand-roll the encrypt/prove step — the facade owns it; you only ever supply `choices`.
|
|
110
|
-
|
|
111
|
-
## Safe reading order when the task is open-ended
|
|
112
|
-
|
|
113
|
-
1. `references/setup.md` — construct & `init()`, signer-vs-provider rule, env vars.
|
|
114
|
-
2. `references/process.md` — `createProcess` config, lifecycle, `getProcess` / results.
|
|
115
|
-
3. `references/census.md` — pick a census class; the `maxVoters` rule per type.
|
|
116
|
-
4. `references/voting.md` — `submitVote`, the `choices` model, status polling.
|
|
117
|
-
5. `references/ballot-modes.md` — only when the user wants a specific voting system.
|
|
118
|
-
6. A `recipes/*.ts` for the closest scenario.
|
|
119
|
-
|
|
120
|
-
`references/sequencer.md` and `references/contracts.md` are escape hatches for when the facade isn't enough; `references/errors.md` is the gotcha catalogue; `references/protocol.md` explains the cryptography and the *why*.
|
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* recipes/bootstrap.ts
|
|
3
|
-
*
|
|
4
|
-
* Wire up the Davinci SDK and verify the connection. This is the foundation
|
|
5
|
-
* every other recipe builds on.
|
|
6
|
-
*
|
|
7
|
-
* - construct a DavinciSDK with an ethers v6 signer + sequencer/census URLs
|
|
8
|
-
* - init() (mandatory — resolves contract addresses from the sequencer)
|
|
9
|
-
* - sanity-check that the RPC chain matches what the sequencer serves
|
|
10
|
-
*
|
|
11
|
-
* Usage:
|
|
12
|
-
* npm install @vocdoni/davinci-sdk ethers
|
|
13
|
-
* # set env vars (see references/setup.md), then:
|
|
14
|
-
* tsx bootstrap.ts
|
|
15
|
-
*/
|
|
16
|
-
|
|
17
|
-
import { JsonRpcProvider, Wallet } from "ethers";
|
|
18
|
-
import { DavinciSDK } from "@vocdoni/davinci-sdk";
|
|
19
|
-
|
|
20
|
-
const SEQUENCER_API_URL = process.env.SEQUENCER_API_URL!; // e.g. https://sequencer-dev.davinci.vote
|
|
21
|
-
const CENSUS_API_URL = process.env.CENSUS_API_URL!; // e.g. https://c3-dev.davinci.vote
|
|
22
|
-
const RPC_URL = process.env.RPC_URL!;
|
|
23
|
-
const PRIVATE_KEY = process.env.PRIVATE_KEY!;
|
|
24
|
-
|
|
25
|
-
async function main() {
|
|
26
|
-
// An organizer signer needs a provider (on-chain ops). A voting-only signer would not.
|
|
27
|
-
const signer = new Wallet(PRIVATE_KEY, new JsonRpcProvider(RPC_URL));
|
|
28
|
-
|
|
29
|
-
const sdk = new DavinciSDK({
|
|
30
|
-
signer,
|
|
31
|
-
sequencerUrl: SEQUENCER_API_URL,
|
|
32
|
-
censusUrl: CENSUS_API_URL, // only needed to publish Merkle censuses / fetch census proofs
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
await sdk.init(); // REQUIRED before any other method
|
|
36
|
-
console.log("SDK initialized");
|
|
37
|
-
|
|
38
|
-
// Sanity check: does the sequencer serve our RPC's chain?
|
|
39
|
-
const info = await sdk.api.sequencer.getInfo();
|
|
40
|
-
const net = await signer.provider!.getNetwork();
|
|
41
|
-
const chainId = Number(net.chainId);
|
|
42
|
-
|
|
43
|
-
const supported = Object.values(info.networks).some((n) => n.chainID === chainId);
|
|
44
|
-
if (!supported) {
|
|
45
|
-
const available = Object.values(info.networks)
|
|
46
|
-
.map((n) => `${n.shortName}(${n.chainID})`)
|
|
47
|
-
.join(", ");
|
|
48
|
-
throw new Error(`RPC chain ${chainId} not served by this sequencer. Available: ${available}`);
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
console.log(`Connected. chainId=${chainId}, sequencer=${info.sequencerAddress}`);
|
|
52
|
-
console.log(`Ballot-proof circuit: ${info.circuitUrl}`);
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
main().then(
|
|
56
|
-
() => process.exit(0),
|
|
57
|
-
(err) => {
|
|
58
|
-
console.error(err);
|
|
59
|
-
process.exit(1);
|
|
60
|
-
},
|
|
61
|
-
);
|
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* recipes/cast-vote.ts
|
|
3
|
-
*
|
|
4
|
-
* Cast a single encrypted vote and wait for it to settle.
|
|
5
|
-
*
|
|
6
|
-
* - construct a DavinciSDK as the VOTER (their wallet; no provider needed)
|
|
7
|
-
* - confirm the process is accepting votes
|
|
8
|
-
* - submitVote with a one-hot choices array
|
|
9
|
-
* - waitForVoteStatus(Settled)
|
|
10
|
-
*
|
|
11
|
-
* The SDK does all the cryptography (ElGamal encrypt → zk-SNARK proof → sign).
|
|
12
|
-
* You only ever supply `choices`.
|
|
13
|
-
*
|
|
14
|
-
* Usage:
|
|
15
|
-
* tsx cast-vote.ts <processId>
|
|
16
|
-
*/
|
|
17
|
-
|
|
18
|
-
import { Wallet } from "ethers";
|
|
19
|
-
import { DavinciSDK, VoteStatus } from "@vocdoni/davinci-sdk";
|
|
20
|
-
|
|
21
|
-
const { SEQUENCER_API_URL, CENSUS_API_URL, VOTER_PRIVATE_KEY } = process.env as Record<string, string>;
|
|
22
|
-
const processId = process.argv[2];
|
|
23
|
-
|
|
24
|
-
async function main() {
|
|
25
|
-
if (!processId) throw new Error("usage: tsx cast-vote.ts <processId>");
|
|
26
|
-
|
|
27
|
-
// Voter SDK — a bare Wallet is fine; voting never touches the chain directly.
|
|
28
|
-
const voter = new DavinciSDK({
|
|
29
|
-
signer: new Wallet(VOTER_PRIVATE_KEY),
|
|
30
|
-
sequencerUrl: SEQUENCER_API_URL,
|
|
31
|
-
censusUrl: CENSUS_API_URL, // lets the SDK fetch this voter's census proof/weight
|
|
32
|
-
});
|
|
33
|
-
await voter.init();
|
|
34
|
-
|
|
35
|
-
const address = await new Wallet(VOTER_PRIVATE_KEY).getAddress();
|
|
36
|
-
|
|
37
|
-
// Optional pre-checks (no provider needed).
|
|
38
|
-
if (!(await voter.isAddressAbleToVote(processId, address))) {
|
|
39
|
-
throw new Error(`${address} is not in this process's census`);
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
// Wait until the sequencer reports the process is accepting votes.
|
|
43
|
-
for (let i = 0; i < 30; i++) {
|
|
44
|
-
try {
|
|
45
|
-
const p = await voter.api.sequencer.getProcess(processId);
|
|
46
|
-
if (p.isAcceptingVotes) break;
|
|
47
|
-
} catch (e: any) {
|
|
48
|
-
if (e.code !== 40007) throw e; // 40007 = not indexed yet
|
|
49
|
-
}
|
|
50
|
-
await new Promise((r) => setTimeout(r, 10_000));
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
// Submit. choices.length MUST equal the process's ballot.numFields.
|
|
54
|
-
// Here: 4 one-hot fields, voting for option 1 ("Blue").
|
|
55
|
-
const result = await voter.submitVote({
|
|
56
|
-
processId,
|
|
57
|
-
choices: [0, 1, 0, 0],
|
|
58
|
-
});
|
|
59
|
-
console.log("Vote submitted:", result.voteId, "status:", result.status);
|
|
60
|
-
|
|
61
|
-
// The vote only counts once settled — settlement can take minutes.
|
|
62
|
-
const final = await voter.waitForVoteStatus(
|
|
63
|
-
processId,
|
|
64
|
-
result.voteId,
|
|
65
|
-
VoteStatus.Settled,
|
|
66
|
-
800_000, // generous timeout
|
|
67
|
-
5_000,
|
|
68
|
-
);
|
|
69
|
-
console.log("Final status:", final.status);
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
main().then(
|
|
73
|
-
() => process.exit(0),
|
|
74
|
-
(err) => {
|
|
75
|
-
console.error(err);
|
|
76
|
-
process.exit(1);
|
|
77
|
-
},
|
|
78
|
-
);
|
|
@@ -1,102 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* recipes/create-process.ts
|
|
3
|
-
*
|
|
4
|
-
* Create a voting process with a locally-built Merkle census, watching the
|
|
5
|
-
* on-chain transaction in real time.
|
|
6
|
-
*
|
|
7
|
-
* - build an OffchainCensus (auto-published by createProcess)
|
|
8
|
-
* - one single-choice question with 4 options, encoded as 4 one-hot fields
|
|
9
|
-
* - stream TxStatus events so a UI can show progress
|
|
10
|
-
*
|
|
11
|
-
* The organizer signer MUST have a provider (process creation is on-chain).
|
|
12
|
-
*
|
|
13
|
-
* Usage:
|
|
14
|
-
* tsx create-process.ts
|
|
15
|
-
*/
|
|
16
|
-
|
|
17
|
-
import { JsonRpcProvider, Wallet } from "ethers";
|
|
18
|
-
import { DavinciSDK, OffchainCensus, TxStatus } from "@vocdoni/davinci-sdk";
|
|
19
|
-
|
|
20
|
-
const { SEQUENCER_API_URL, CENSUS_API_URL, RPC_URL, PRIVATE_KEY } = process.env as Record<string, string>;
|
|
21
|
-
|
|
22
|
-
async function main() {
|
|
23
|
-
const sdk = new DavinciSDK({
|
|
24
|
-
signer: new Wallet(PRIVATE_KEY, new JsonRpcProvider(RPC_URL)),
|
|
25
|
-
sequencerUrl: SEQUENCER_API_URL,
|
|
26
|
-
censusUrl: CENSUS_API_URL, // required to publish the Merkle census
|
|
27
|
-
});
|
|
28
|
-
await sdk.init();
|
|
29
|
-
|
|
30
|
-
// 1. Census of eligible voters. Plain addresses → weight 1 each.
|
|
31
|
-
// (For weighted voting use census.add({ key, weight }).)
|
|
32
|
-
const census = new OffchainCensus();
|
|
33
|
-
census.add([
|
|
34
|
-
"0x1111111111111111111111111111111111111111",
|
|
35
|
-
"0x2222222222222222222222222222222222222222",
|
|
36
|
-
"0x3333333333333333333333333333333333333333",
|
|
37
|
-
]);
|
|
38
|
-
|
|
39
|
-
// 2. Process config. One question, 4 options → numFields: 4 (one-hot).
|
|
40
|
-
// Single-choice: each field 0..1, exactly one selected (maxValueSum "1").
|
|
41
|
-
const config = {
|
|
42
|
-
title: "Favourite colour",
|
|
43
|
-
description: "Pick one",
|
|
44
|
-
census, // auto-published; maxVoters defaults to participant count
|
|
45
|
-
ballot: {
|
|
46
|
-
numFields: 4,
|
|
47
|
-
minValue: "0",
|
|
48
|
-
maxValue: "1",
|
|
49
|
-
uniqueValues: false,
|
|
50
|
-
costExponent: 1,
|
|
51
|
-
minValueSum: "1",
|
|
52
|
-
maxValueSum: "1",
|
|
53
|
-
},
|
|
54
|
-
timing: {
|
|
55
|
-
startDate: new Date(Date.now() + 60 * 1000), // start in ~1 minute
|
|
56
|
-
duration: 3600 * 8, // 8 hours
|
|
57
|
-
},
|
|
58
|
-
questions: [
|
|
59
|
-
{
|
|
60
|
-
title: "What is your favourite colour?",
|
|
61
|
-
choices: [
|
|
62
|
-
{ title: "Red", value: 0 },
|
|
63
|
-
{ title: "Blue", value: 1 },
|
|
64
|
-
{ title: "Green", value: 2 },
|
|
65
|
-
{ title: "Yellow", value: 3 },
|
|
66
|
-
],
|
|
67
|
-
},
|
|
68
|
-
],
|
|
69
|
-
};
|
|
70
|
-
|
|
71
|
-
// 3. Stream the creation so we can react to each on-chain state.
|
|
72
|
-
let processId = "";
|
|
73
|
-
for await (const event of sdk.createProcessStream(config)) {
|
|
74
|
-
switch (event.status) {
|
|
75
|
-
case TxStatus.Pending:
|
|
76
|
-
console.log("Tx submitted:", event.hash);
|
|
77
|
-
break;
|
|
78
|
-
case TxStatus.Completed:
|
|
79
|
-
processId = event.response.processId;
|
|
80
|
-
console.log("Process created:", processId);
|
|
81
|
-
console.log("Tx:", event.response.transactionHash);
|
|
82
|
-
break;
|
|
83
|
-
case TxStatus.Failed:
|
|
84
|
-
throw event.error;
|
|
85
|
-
case TxStatus.Reverted:
|
|
86
|
-
throw new Error(`Reverted: ${event.reason ?? "unknown"}`);
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
// Simpler, non-streaming equivalent:
|
|
91
|
-
// const { processId } = await sdk.createProcess(config);
|
|
92
|
-
|
|
93
|
-
console.log("Done. processId =", processId);
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
main().then(
|
|
97
|
-
() => process.exit(0),
|
|
98
|
-
(err) => {
|
|
99
|
-
console.error(err);
|
|
100
|
-
process.exit(1);
|
|
101
|
-
},
|
|
102
|
-
);
|