@@ -190,58 +82,42 @@ Fetches the specific account token auth and sets it to the current instance.
Fetches info about an election.
-**Returns**: Promise<[UnpublishedElection](UnpublishedElection)>
+**Returns**: Promise<(PublishedElection\|ArchivedElection)>
|PARAMETER|TYPE|OPTIONAL|DEFAULT|DESCRIPTION|
|:---:|:---:|:---:|:---:|:---:|
|electionId|string|✔️||The id of the election|
-### waitForTransaction {#waitForTransaction}
+### fetchProofForWallet {#fetchProofForWallet}
-A convenience method to wait for a transaction to be executed. It will
it fails.
-
-**Returns**: Promise<void>
-
-|PARAMETER|TYPE|OPTIONAL|DEFAULT|DESCRIPTION|
-|:---:|:---:|:---:|:---:|:---:|
-|tx|string|||Transaction to wait for|
-|wait|number|✔️||The delay in milliseconds between tries|
-|attempts|attempts|✔️||The attempts to try before failing|
-
-### fetchProof {#fetchProof}
-
-
-
Fetches proof that an address is part of the specified census.
-**Returns**: Promise<[OffchainCensusProof](OffchainCensusProof)>
+**Returns**: Promise<[CensusProof](CensusProof)>
|PARAMETER|TYPE|OPTIONAL|DEFAULT|DESCRIPTION|
|:---:|:---:|:---:|:---:|:---:|
-|censusId|string|||Census we want to check the address against|
-|key|string|||The address to be found|
-|type|CensusProofType|||Type of census|
+|censusId|string||||
+|wallet|Wallet \| Signer||||
-### fetchProofForWallet {#fetchProofForWallet}
+### calcZKProofForWallet {#calcZKProofForWallet}
-Fetches proof that an address is part of the specified census.
+Calculates ZK proof from given wallet.
-**Returns**: Promise<[OffchainCensusProof](OffchainCensusProof)>
+**Returns**: Promise<ZkProof>
|PARAMETER|TYPE|OPTIONAL|DEFAULT|DESCRIPTION|
|:---:|:---:|:---:|:---:|:---:|
|election|[PublishedElection](PublishedElection)||||
|wallet|Wallet \| Signer||||
+|password|string|✔️|"0"||
### createAccountInfo {#createAccountInfo}
@@ -283,7 +159,7 @@ Updates an account with information
|PARAMETER|TYPE|OPTIONAL|DEFAULT|DESCRIPTION|
|:---:|:---:|:---:|:---:|:---:|
-|promAccountData|Promise<{tx: Uint8Array, metadata: string}>||||
+|promAccountData|Promise<{tx: Uint8Array, metadata: string, message: string}>||||
### createAccount {#createAccount}
@@ -299,55 +175,60 @@ Registers an account against vochain, so it can create new elections.
|:---:|:---:|:---:|:---:|:---:|
|options|Object|✔️||Additional
options, like extra information of the account, or the faucet package string|
-### collectFaucetTokens {#collectFaucetTokens}
+### sendTokens {#sendTokens}
-Calls the faucet to get new tokens. Only under development.
+Send tokens from one account to another.
-**Returns**: Promise<[AccountData](AccountData)>
-- Account data information updated with new balance
+**Returns**: Promise<void>
-### createCensus {#createCensus}
+|PARAMETER|TYPE|OPTIONAL|DEFAULT|DESCRIPTION|
+|:---:|:---:|:---:|:---:|:---:|
+|options|SendTokensOptions|||Options for send tokens|
+
+### collectFaucetTokens {#collectFaucetTokens}
-Publishes the given census.
+Calls the faucet to get new tokens. Only under development.
-**Returns**: Promise<void>
+**Returns**: Promise<[AccountData](AccountData)>
+- Account data information updated with new balance
|PARAMETER|TYPE|OPTIONAL|DEFAULT|DESCRIPTION|
|:---:|:---:|:---:|:---:|:---:|
-|census|[PlainCensus](PlainCensus) \| [WeightedCensus](WeightedCensus)|||The census to be published.|
+|faucetPackage|string|✔️||The faucet package|
-### fetchCensusInfo {#fetchCensusInfo}
+### createElection {#createElection}
-Fetches the information of a given census.
+Creates a new voting election.
-**Returns**: Promise<{size: number, weight: bigint}>
+**Returns**: Promise<string>
+- Resulting election id.
|PARAMETER|TYPE|OPTIONAL|DEFAULT|DESCRIPTION|
|:---:|:---:|:---:|:---:|:---:|
-|censusId|string||||
+|election|[UnpublishedElection](UnpublishedElection)|||The election object to be created.|
-### createElection {#createElection}
+### createElectionSteps {#createElectionSteps}
-Creates a new voting election.
+Creates a new voting election by steps with async returns.
-**Returns**: Promise<string>
-- Resulting election id.
+**Returns**: AsyncGenerator<ElectionCreationStepValue>
+- The async step returns.
|PARAMETER|TYPE|OPTIONAL|DEFAULT|DESCRIPTION|
|:---:|:---:|:---:|:---:|:---:|
@@ -458,7 +339,7 @@ Checks if the user is in census.
### hasAlreadyVoted {#hasAlreadyVoted}
Checks if the user has already voted
@@ -511,7 +392,7 @@ Submits a vote to the current instance election id.
|PARAMETER|TYPE|OPTIONAL|DEFAULT|DESCRIPTION|
|:---:|:---:|:---:|:---:|:---:|
-|vote|[Vote](Vote) \| [CspVote](CspVote)|||The vote (or votes) to be sent.|
+|vote|[Vote](Vote) \| [CspVote](CspVote) \| [AnonymousVote](AnonymousVote)|||The vote (or votes) to be sent.|
### generateRandomWallet {#generateRandomWallet}
@@ -524,6 +405,97 @@ Assigns a random Wallet to the client and returns its private key.
**Returns**: string
- The private key.
+### fetchProof {#fetchProof}
+
+
+
+Fetches proof that an address is part of the specified census.
+
+**Returns**: Promise<[CensusProof](CensusProof)>
+
+|PARAMETER|TYPE|OPTIONAL|DEFAULT|DESCRIPTION|
+|:---:|:---:|:---:|:---:|:---:|
+|censusId|string|||Census we want to check the address against|
+|key|string|||The address to be found|
+
+### createCensus {#createCensus}
+
+
+
+Publishes the given census.
+
+**Returns**: Promise<void>
+
+|PARAMETER|TYPE|OPTIONAL|DEFAULT|DESCRIPTION|
+|:---:|:---:|:---:|:---:|:---:|
+|census|[PlainCensus](PlainCensus) \| [WeightedCensus](WeightedCensus)|||The census to be published.|
+
+### fetchCensusInfo {#fetchCensusInfo}
+
+
+
+Fetches the information of a given census.
+
+**Returns**: Promise<{size: number, weight: bigint}>
+
+|PARAMETER|TYPE|OPTIONAL|DEFAULT|DESCRIPTION|
+|:---:|:---:|:---:|:---:|:---:|
+|censusId|string||||
+
+### fetchCircuits {#fetchCircuits}
+
+
+
+Fetches circuits for anonymous voting
+
+**Returns**: Promise<ChainCircuits>
+
+|PARAMETER|TYPE|OPTIONAL|DEFAULT|DESCRIPTION|
+|:---:|:---:|:---:|:---:|:---:|
+|circuits|Omit<ChainCircuits, ('zKeyData'\|'vKeyData'\|'wasmData')>|✔️||Additional options for custom circuits|
+
+### setCircuits {#setCircuits}
+
+
+
+Sets circuits for anonymous voting
+
+**Returns**: Promise<ChainCircuits>
+
+|PARAMETER|TYPE|OPTIONAL|DEFAULT|DESCRIPTION|
+|:---:|:---:|:---:|:---:|:---:|
+|circuits|ChainCircuits|||Custom circuits|
+
+### fetchChainCosts {#fetchChainCosts}
+
+
+
+Fetches blockchain costs information if needed.
+
+**Returns**: Promise<ChainCosts>
+
+### fetchChainId {#fetchChainId}
+
+
+
+Fetches blockchain information if needed and returns the chain id.
+
+**Returns**: Promise<string>
+
### estimateElectionCost {#estimateElectionCost}
@@ -554,3 +526,58 @@ Calculate the election cost
|:---:|:---:|:---:|:---:|:---:|
|election|[UnpublishedElection](UnpublishedElection)||||
+### calculateCID {#calculateCID}
+
+
+
+
+
+Fetches the CID expected for the specified data content.
+
+**Returns**: Promise<string>
+- Resulting CID
+
+|PARAMETER|TYPE|OPTIONAL|DEFAULT|DESCRIPTION|
+|:---:|:---:|:---:|:---:|:---:|
+|data|string|||The data of which we want the CID of|
+
+### fetchFaucetPayload {#fetchFaucetPayload}
+
+
+
+
+
+Fetches a faucet payload. Only for development.
+
+**Returns**: Promise<{string}>
+
+### parseFaucetPackage {#parseFaucetPackage}
+
+
+
+
+
+Parses a faucet package.
+
+**Returns**: [FaucetPackage](FaucetPackage)
+
+|PARAMETER|TYPE|OPTIONAL|DEFAULT|DESCRIPTION|
+|:---:|:---:|:---:|:---:|:---:|
+|faucetPackage|string|||The encoded faucet package|
+
+### waitForTransaction {#waitForTransaction}
+
+
+
+
+
+A convenience method to wait for a transaction to be executed. It will
loop trying to get the transaction information, and will retry every time
it fails.
+
+**Returns**: Promise<void>
+
+|PARAMETER|TYPE|OPTIONAL|DEFAULT|DESCRIPTION|
+|:---:|:---:|:---:|:---:|:---:|
+|tx|string|||Transaction to wait for|
+|wait|number|✔️||The delay in milliseconds between tries|
+|attempts|attempts|✔️||The attempts to try before failing|
+
diff --git a/docs/sdk/VoteCore.mdx b/docs/sdk/VoteCore.mdx
index 5f3c26914..67839f578 100644
--- a/docs/sdk/VoteCore.mdx
+++ b/docs/sdk/VoteCore.mdx
@@ -41,5 +41,5 @@ Packages the given parameters into a proof that can be submitted to the Vochain
|:---:|:---:|:---:|:---:|:---:|
|electionId|string||||
|type|CensusType||||
-|censusProof|[OffchainCensusProof](OffchainCensusProof) \| [CspCensusProof](CspCensusProof)||||
+|censusProof|[CensusProof](CensusProof) \| [CspCensusProof](CspCensusProof) \| ZkProof||||
diff --git a/docs/sdk/VoteService.mdx b/docs/sdk/VoteService.mdx
new file mode 100644
index 000000000..20ea91185
--- /dev/null
+++ b/docs/sdk/VoteService.mdx
@@ -0,0 +1,63 @@
+---
+custom_edit_url: null
+---
+
+```ts
+class VoteService
+```
+
+
+
+
+
+
+
+## constructor
+```ts
+new VoteService(params)
+```
+
+
+
+
+
+Instantiate the election service.
+
+|PARAMETER|TYPE|OPTIONAL|DEFAULT|DESCRIPTION|
+|:---:|:---:|:---:|:---:|:---:|
+|params|Partial<VoteServiceParameters>|||The service parameters|
+
+## Methods
+
+### info {#info}
+
+
+
+
+
+Get the vote information
+
+**Returns**: Promise<VoteInfo>
+
+|PARAMETER|TYPE|OPTIONAL|DEFAULT|DESCRIPTION|
+|:---:|:---:|:---:|:---:|:---:|
+|address|string|||The address of the voter|
+|electionId|string|||The id of the election|
+
+### vote {#vote}
+
+
+
+
+
+Submit the vote to the chain
+
+**Returns**: Promise<VoteSubmit>
+
+|PARAMETER|TYPE|OPTIONAL|DEFAULT|DESCRIPTION|
+|:---:|:---:|:---:|:---:|:---:|
+|payload|string|||The base64 encoded vote transaction|
+
diff --git a/docs/sdk/ZkAPI.mdx b/docs/sdk/ZkAPI.mdx
new file mode 100644
index 000000000..5bb9037aa
--- /dev/null
+++ b/docs/sdk/ZkAPI.mdx
@@ -0,0 +1,61 @@
+---
+custom_edit_url: null
+---
+
+```ts
+class ZkAPI
+```
+
+
+
+
+
+
+
+## constructor
+```ts
+new ZkAPI()
+```
+
+
+
+
+
+Cannot be constructed.
+
+## Methods
+### proof {#proof}
+
+
+ static
+
+
+Returns the ZK proof on given address
+
+**Returns**: Promise<IZkProofResponse>
+- The ZK proof
+
+|PARAMETER|TYPE|OPTIONAL|DEFAULT|DESCRIPTION|
+|:---:|:---:|:---:|:---:|:---:|
+|url|string|||API endpoint URL|
+|key|string|||The address to be checked|
+
+### sik {#sik}
+
+
+ static
+
+
+Returns the SIK on given address
+
+**Returns**: Promise<IZkSIKResponse>
+- The ZK proof
+
+|PARAMETER|TYPE|OPTIONAL|DEFAULT|DESCRIPTION|
+|:---:|:---:|:---:|:---:|:---:|
+|url|string|||API endpoint URL|
+|key|string|||The address to be checked|
+
diff --git a/docs/sdk/changelog.md b/docs/sdk/changelog.md
index ee827758b..e123ea524 100644
--- a/docs/sdk/changelog.md
+++ b/docs/sdk/changelog.md
@@ -5,7 +5,140 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
-## [Unreleased]
+## [0.5.3] - 2023-11-28
+
+### Added
+
+- New account methods supported for listing, counting and checking account transfers in `AccountAPI`.
+
+### Fixed
+
+- Archived elections without census URI are now accepted.
+
+### Changed
+
+- Faucet options don't require `token_limit` anymore.
+
+## [0.5.2] - 2023-11-16
+
+### Fixed
+
+- Anonymous vote packages are no longer signed.
+
+## [0.5.1] - 2023-11-15
+
+### Fixed
+
+- Missing exported election type `ArchivedElection`.
+- Faucet errors correctly shown with message.
+
+## [0.5.0] - 2023-11-14
+
+### Changed
+
+- [**BREAKING**] New full integration for Census3 v2, using tokens, strategies and censuses.
+
+## [0.4.3] - 2023-11-09
+
+### Added
+
+- Support for archived elections with new election type `ArchivedElection` and with new census with type `ArchivedCensus`.
+
+## [0.4.2] - 2023-11-06
+
+### Changed
+
+- Removed faucet path from default URLs.
+- Updated `@vocdoni/proto` dependency to `1.15.4`.
+
+### Added
+
+- Import, export and delete census functionality in census service.
+- Added new election parameter `temporarySecretIdentity` for deleting temporary SIKs once election is finished.
+
+### Fixed
+
+- Fixed `ffjavascript` dependency to `0.2.59`.
+
+## [0.4.1] - 2023-10-24
+
+### Changed
+
+- Modified `dev`, `stg` and `prod` default URLs for all services.
+- Upgraded to new faucet.
+
+## [0.4.0] - 2023-10-10
+
+### Changed
+
+- [**BREAKING**] New signatures for chain transactions.
+
+## [0.3.2] - 2023-10-10
+
+### Added
+
+- Added support for uploading big censuses in chunks.
+
+### Fixed
+
+- Added `assert` as embedded in rollup configuration.
+
+## [0.3.1] - 2023-09-20
+
+### Added
+
+- New `createElectionSteps` function in client for using async generators and control creation flow.
+- New `sendTokens` function in client for transferring tokens between accounts.
+
+### Changed
+
+- New user-friendly text for SIK payload signing.
+
+### Fixed
+
+- Added `ethers` as embedded in rollup configuration for `circomlibjs` dependencies.
+
+## [0.3.0] - 2023-09-13
+
+### Fixed
+
+- Ensuring proof `value` handled as hex for anonymous circuits inputs.
+
+### Changed
+
+- [**BREAKING**] Removed some (probably not used) client properties for future refactor.
+- Added services as mid-layer between pure SDK client and API wrappers.
+
+### Added
+
+- Census3 supported chains information.
+
+## [0.2.0] - 2023-09-04
+
+### Fixed
+
+- `dotobject` helper returns null when key is not found.
+
+### Changed
+
+- `collectFaucetTokens` function accepts raw faucet package payload.
+
+### Added
+
+- Census3 error typings.
+- [**BREAKING**] Census3 anonymous censuses.
+
+## [0.1.1] - 2023-08-14
+
+### Fixed
+
+- Added missing dependency `readable-stream`.
+
+## [0.1.0] - 2023-08-11
+
+### Added
+
+- [**BREAKING**] Anonymous integration
### Fixed
@@ -227,6 +360,20 @@ which extend from the abstract `Election` class.
- First unstable version of the SDK for testing purposes
+[0.5.3]: https://github.com/vocdoni/vocdoni-sdk/releases/tag/v0.5.3
+[0.5.2]: https://github.com/vocdoni/vocdoni-sdk/releases/tag/v0.5.2
+[0.5.1]: https://github.com/vocdoni/vocdoni-sdk/releases/tag/v0.5.1
+[0.5.0]: https://github.com/vocdoni/vocdoni-sdk/releases/tag/v0.5.0
+[0.4.3]: https://github.com/vocdoni/vocdoni-sdk/releases/tag/v0.4.3
+[0.4.2]: https://github.com/vocdoni/vocdoni-sdk/releases/tag/v0.4.2
+[0.4.1]: https://github.com/vocdoni/vocdoni-sdk/releases/tag/v0.4.1
+[0.4.0]: https://github.com/vocdoni/vocdoni-sdk/releases/tag/v0.4.0
+[0.3.2]: https://github.com/vocdoni/vocdoni-sdk/releases/tag/v0.3.2
+[0.3.1]: https://github.com/vocdoni/vocdoni-sdk/releases/tag/v0.3.1
+[0.3.0]: https://github.com/vocdoni/vocdoni-sdk/releases/tag/v0.3.0
+[0.2.0]: https://github.com/vocdoni/vocdoni-sdk/releases/tag/v0.2.0
+[0.1.1]: https://github.com/vocdoni/vocdoni-sdk/releases/tag/v0.1.1
+[0.1.0]: https://github.com/vocdoni/vocdoni-sdk/releases/tag/v0.1.0
[0.0.18]: https://github.com/vocdoni/vocdoni-sdk/releases/tag/v0.0.18
[0.0.17]: https://github.com/vocdoni/vocdoni-sdk/releases/tag/v0.0.17
[0.0.16]: https://github.com/vocdoni/vocdoni-sdk/releases/tag/v0.0.16
diff --git a/docs/sdk/sdk.md b/docs/sdk/sdk.md
index 3769240c6..7d6b0da87 100644
--- a/docs/sdk/sdk.md
+++ b/docs/sdk/sdk.md
@@ -1,3 +1,18 @@
+
+
+
+
+
+
+![npm](https://img.shields.io/npm/v/%40vocdoni%2Fsdk)
+![GitHub commit activity (main)](https://img.shields.io/github/commit-activity/m/vocdoni/vocdoni-sdk)
+[![Example workflow](https://github.com/vocdoni/vocdoni-sdk/actions/workflows/examples.yml/badge.svg)](https://vocdoni.github.io/vocdoni-sdk/)
+![Main workflow](https://github.com/vocdoni/vocdoni-sdk/actions/workflows/main.yml/badge.svg)
+[![Join Discord](https://img.shields.io/badge/discord-join%20chat-blue.svg)](https://discord.gg/xFTh8Np2ga)
+[![Twitter Follow](https://img.shields.io/twitter/follow/vocdoni.svg?style=social&label=Follow)](https://twitter.com/vocdoni)
+
+
+
# Vocdoni SDK
The Vocdoni SDK is a convenient way to interact with the Vocdoni Protocol
@@ -547,9 +562,417 @@ const vote = client.cspVote(new Vote([index % 2]), signature);
const voteId = await client.submitVote(vote);
~~~
+## Census3
+
+### What is Census3?
+
+Census3 is an API service to create censuses for elections with holders of a single token or a combination of them.
+The service creates a list of holder addresses and balances and keeps it updated in real time, for every registered token.
+Then, it allows creating a merkle tree census (compatible with [Vocdoni](https://vocdoni.io/)) with those holders, using their balances as vote weights.
+
+More information about Census3 can be found [here](https://github.com/vocdoni/census3).
+
+### Using Census3
+
+The SDK comes with an implementation of the [Census3 API](https://github.com/vocdoni/census3/blob/main/api/README.md).
+
+#### Creating a Census3 client
+
+~~~ts
+const client = new VocdoniCensus3Client({
+ env: EnvOptions.DEV // dev environment
+})
+~~~
+
+#### Getting basic service information
+
+~~~ts
+// Get the supported chains
+const supportedChains = await client.getSupportedChains();
+// [
+// {
+// "chainID": 1,
+// "shortName": "eth",
+// "name": "Ethereum Mainnet"
+// },
+// {
+// "chainID": 5,
+// "shortName": "gor",
+// "name": "Goerli"
+// },
+// {
+// "chainID": 137,
+// "shortName": "matic",
+// "name": "Polygon Mainnet"
+// },
+// {
+// "chainID": 80001,
+// "shortName": "maticmum",
+// "name": "Mumbai"
+// }
+// ]
+~~~
+
+~~~ts
+// Get the supported token types
+const supportedTypes = await client.getSupportedTypes();
+// ["erc20", "erc777", "poap", "unknown", "erc721burned", "erc1155", "nation3", "want", "erc721"]
+~~~
+
+#### Getting tokens information and creating them
+
+~~~ts
+// Get the supported tokens
+const supportedTokens = await client.getSupportedTokens();
+// [
+// {
+// "ID": "0x0AaCfbeC6a24756c20D41914F2caba817C0d8521",
+// "type": "erc20",
+// "decimals": 18,
+// "startBlock": 10886913,
+// "symbol": "YAM",
+// "totalSupply": "",
+// "name": "YAM",
+// "status": {
+// "atBlock": 18565762,
+// "synced": true,
+// "progress": 100
+// },
+// "size": 14999,
+// "defaultStrategy": 19,
+// "chainID": 1,
+// "chainAddress": "eth:0x0AaCfbeC6a24756c20D41914F2caba817C0d8521"
+// },
+// {
+// "ID": "0x0b38210ea11411557c13457D4dA7dC6ea731B88a",
+// "type": "erc20",
+// "decimals": 18,
+// "startBlock": 11203771,
+// "symbol": "API3",
+// "totalSupply": "",
+// "name": "API3",
+// "status": {
+// "atBlock": 18565763,
+// "synced": true,
+// "progress": 100
+// },
+// "size": 51178,
+// "defaultStrategy": 8,
+// "chainID": 1,
+// "chainAddress": "eth:0x0b38210ea11411557c13457D4dA7dC6ea731B88a"
+// },
+// ...
+// ]
+~~~
+
+~~~ts
+// Get a token by its ID (address) and chain identifier
+const token = await client.getToken('0x0AaCfbeC6a24756c20D41914F2caba817C0d8521', 1);
+// {
+// "ID": "0x0AaCfbeC6a24756c20D41914F2caba817C0d8521",
+// "type": "erc20",
+// "decimals": 18,
+// "startBlock": 10886913,
+// "symbol": "YAM",
+// "totalSupply": "15164231312592159866595366",
+// "name": "YAM",
+// "status": {
+// "atBlock": 18565783,
+// "synced": true,
+// "progress": 100
+// },
+// "size": 14999,
+// "defaultStrategy": 19,
+// "chainID": 1,
+// "chainAddress": "eth:0x0AaCfbeC6a24756c20D41914F2caba817C0d8521",
+// "tags": []
+// }
+~~~
+
+~~~ts
+// Check if a holder is registered for a given token
+const token = await client.isHolderInToken(
+ '0x0AaCfbeC6a24756c20D41914F2caba817C0d8521',
+ 1,
+ '0x111000000000000000000000000000000000dEaD'
+);
+// false
+~~~
+
+~~~ts
+// Creates a new token by passing the address, the type and the chain identifier
+const token = await client.createToken('0xa117000000f279d81a1d3cc75430faa017fa5a2e', 'erc20', 1);
+~~~
+
+#### Getting strategies information and creating them
+
+~~~ts
+// Get the supported strategies
+const supportedStrategies = await client.getStrategies();
+// [
+// {
+// "ID": 1,
+// "alias": "Default strategy for token CRV",
+// "predicate": "CRV",
+// "uri": "ipfs://bafybeicjqjklqpumewpaue6weg47byz6fwmbg6ozief3w2pgqx7zlwl5ea",
+// "tokens": {
+// "CRV": {
+// "ID": "0xD533a949740bb3306d119CC777fa900bA034cd52",
+// "chainID": 1,
+// "minBalance": "0",
+// "chainAddress": "eth:0xD533a949740bb3306d119CC777fa900bA034cd52"
+// }
+// }
+// },
+// {
+// "ID": 2,
+// "alias": "Default strategy for token UNI",
+// "predicate": "UNI",
+// "uri": "ipfs://bafybeiesxbsbvp2agcuolezec6hvimntqdg3w43xs62mecdj2fyeh5anxu",
+// "tokens": {
+// "UNI": {
+// "ID": "0x1f9840a85d5aF5bf1D1762F925BDADdC4201F984",
+// "chainID": 1,
+// "minBalance": "0",
+// "chainAddress": "eth:0x1f9840a85d5aF5bf1D1762F925BDADdC4201F984"
+// }
+// }
+// },
+// ...
+// ]
+~~~
+
+~~~ts
+// Get the supported strategies by token and chain identifier
+const supportedStrategiesByToken = await client.getStrategiesByToken('0x0AaCfbeC6a24756c20D41914F2caba817C0d8521', 1);
+// [
+// {
+// "ID": 19,
+// "alias": "Default strategy for token YAM",
+// "predicate": "YAM",
+// "uri": "ipfs://bafybeicddxfktpcmbkvrflifbod6eeaizfab7l5ijggswnn5jwu3uhv4i4",
+// "tokens": {
+// "YAM": {
+// "ID": "0x0AaCfbeC6a24756c20D41914F2caba817C0d8521",
+// "chainID": 1,
+// "minBalance": "0",
+// "chainAddress": "eth:0x0AaCfbeC6a24756c20D41914F2caba817C0d8521"
+// }
+// }
+// },
+// {
+// "ID": 37,
+// "alias": "testStrategy_1699887257144",
+// "predicate": "(YAM OR API3) AND 1INCH",
+// "uri": "ipfs://bafybeic2gw6nb75ledp3jbz46rmdrnti33hgtlm5icfluxn5ol4enqps7i",
+// "tokens": {
+// "1INCH": {
+// "ID": "0x111111111117dC0aa78b770fA6A738034120C302",
+// "chainID": 1,
+// "minBalance": "50",
+// "chainAddress": "eth:0x111111111117dC0aa78b770fA6A738034120C302"
+// },
+// "API3": {
+// "ID": "0x0b38210ea11411557c13457D4dA7dC6ea731B88a",
+// "chainID": 1,
+// "minBalance": "0",
+// "chainAddress": "eth:0x0b38210ea11411557c13457D4dA7dC6ea731B88a"
+// },
+// "YAM": {
+// "ID": "0x0AaCfbeC6a24756c20D41914F2caba817C0d8521",
+// "chainID": 1,
+// "minBalance": "10000",
+// "chainAddress": "eth:0x0AaCfbeC6a24756c20D41914F2caba817C0d8521"
+// }
+// }
+// },
+// ...
+// ]
+~~~
+
+~~~ts
+// Get a strategy on a given identifier
+const strategy = await client.getStrategy(1);
+// {
+// "ID": 1,
+// "alias": "Default strategy for token CRV",
+// "predicate": "CRV",
+// "uri": "ipfs://bafybeicjqjklqpumewpaue6weg47byz6fwmbg6ozief3w2pgqx7zlwl5ea",
+// "tokens": {
+// "CRV": {
+// "ID": "0xD533a949740bb3306d119CC777fa900bA034cd52",
+// "chainID": 1,
+// "minBalance": "0",
+// "chainAddress": "eth:0xD533a949740bb3306d119CC777fa900bA034cd52"
+// }
+// }
+// }
+~~~
+
+~~~ts
+// Get strategy size
+const size = await client.getStrategySize(1);
+// 12455
+~~~
+
+~~~ts
+// Creates a new strategy by passing the alias, the predicate and the tokens information
+const strategyId = await client.createStrategy('test_strategy', '(wANT OR ANT) AND USDC', {
+ "wANT": {
+ "ID": "0x1324",
+ "chainID": 1,
+ "minBalance": "10000"
+ },
+ "ANT": {
+ "ID": "0x1324",
+ "chainID": 5,
+ },
+ "USDC": {
+ "ID": "0x1324",
+ "chainID": 1,
+ "minBalance": "50"
+ },
+});
+console.log(strategyId) // strategy identifier
+~~~
+
+~~~ts
+// Imports a strategy from IPFS by the given cid
+const strategy = await client.importStrategy('bafybeicjqjklqpumewpaue6weg47byz6fwmbg6ozief3w2pgqx7zlwl5ea');
+// {
+// "ID": 1,
+// "alias": "Default strategy for token CRV",
+// "predicate": "CRV",
+// "uri": "ipfs://bafybeicjqjklqpumewpaue6weg47byz6fwmbg6ozief3w2pgqx7zlwl5ea",
+// "tokens": {
+// "CRV": {
+// "ID": "0xD533a949740bb3306d119CC777fa900bA034cd52",
+// "chainID": 1,
+// "minBalance": "0",
+// "chainAddress": "eth:0xD533a949740bb3306d119CC777fa900bA034cd52"
+// }
+// }
+// }
+~~~
+
+~~~ts
+// Validates a predicate for a strategy and returns the parsed predicate in JSON
+const validatePredicate = await client.validatePredicate('1INCH AND (YAM OR API3)');
+// {
+// "result": {
+// "childs": {
+// "operator": "AND",
+// "tokens": [
+// {
+// "childs": {
+// "operator": "OR",
+// "tokens": [
+// {
+// "literal": "YAM"
+// },
+// {
+// "literal": "API3"
+// }
+// ]
+// }
+// },
+// {
+// "literal": "1INCH"
+// }
+// ]
+// }
+// }
+// }
+~~~
+
+~~~ts
+// Gets the supported predicate operators
+const operators = await client.getSupportedOperators();
+// [
+// {
+// "description": "AND logical operator that returns the common token holders between symbols with fixed balance to 1",
+// "tag": "AND"
+// },
+// {
+// "description": "AND:sum logical operator that returns the common token holders between symbols with the sum of their balances on both tokens",
+// "tag": "AND:sum"
+// },
+// {
+// "description": "AND:mul logical operator that returns the common token holders between symbols with the multiplication of their balances on both tokens",
+// "tag": "AND:mul"
+// },
+// ...
+// ]
+~~~
+
+#### Getting censuses information and creating them
+
+~~~ts
+// Get the supported censuses by strategy identifier
+const strategyID = 18;
+const censusesByStrategy = await client.getCensuses(strategyID);
+// [
+// {
+// "ID": 18569955180,
+// "strategyID": 18,
+// "merkleRoot": "9b1ac0ed374a66b781a22ec5e1b1382324adc0759662e1e6f85fc87f5a23407e",
+// "uri": "ipfs://bafybeihwz2mbkkphgs2ni5laymgtfokaskujg2qfqcvoxhkccbdqp6k7ly",
+// "size": 14999,
+// "weight": "81637958624197446065983341792",
+// "anonymous": false
+// },
+// {
+// "ID": 18569991180,
+// "strategyID": 18,
+// "merkleRoot": "ab1c003b923c4fec0b24f84893ddda8835fd3990904dc64f06c1fc0eadef402f",
+// "uri": "ipfs://bafybeig5jrzw7ayxb442evan4pwa4rfksznh3smyt4exyjkubet2u5ldjm",
+// "size": 14999,
+// "weight": "653103668993579568527866734336",
+// "anonymous": false
+// },
+// ...
+// ]
+~~~
+
+~~~ts
+// Get a census on a given identifier
+const census = await client.getCensus(18569955180);
+// {
+// "ID": 18569955180,
+// "strategyID": 18,
+// "merkleRoot": "9b1ac0ed374a66b781a22ec5e1b1382324adc0759662e1e6f85fc87f5a23407e",
+// "uri": "ipfs://bafybeihwz2mbkkphgs2ni5laymgtfokaskujg2qfqcvoxhkccbdqp6k7ly",
+// "size": 14999,
+// "weight": "1514939612264202552941935398517220938016694806267744586724593217517874",
+// "anonymous": false
+// }
+~~~
+
+~~~ts
+// Creates a new census by passing the strategy identifier
+const strategyID = 18;
+const census = await client.createCensus(strategyID);
+// {
+// "ID": 18570184180,
+// "strategyID": 18,
+// "merkleRoot": "542166dd4757904449e71d5c21058597ab4179f040ee1f9e7dd29eec622ca5ed",
+// "uri": "ipfs://bafybeifbhmytl6olebkdoas6uftj3ae5akutmji4io6k37ilzu5uli2nle",
+// "size": 14999,
+// "weight": "42801802051163230603042274301444096",
+// "anonymous": false
+// }
+~~~
+
+~~~ts
+// Creates a new census by passing the token address, using the default strategy and returns
+// an instance of `TokenCensus` which can be directly used as a census in the Vocdoni chain
+const census = await client.createTokenCensus('0x0AaCfbeC6a24756c20D41914F2caba817C0d8521', 1);
+console.log(typeof census); // TokenCensus
+~~~
+
## Examples
-You can find a [full featured CRA][example-cra] application with all the previous
+You can find a [full featured vite][example-vite] application with all the previous
steps in the [examples] folder. In that folder you'll also find a
[es modules example][example-esm], creating and voting an election process.
@@ -589,7 +1012,7 @@ This SDK is licensed under the [GNU Affero General Public License v3.0][license]
[election-lifecycle-states]: https://developer.vocdoni.io/get-started/intro#election-lifecycle-states
[election params interface]: https://github.com/vocdoni/vocdoni-sdk/blob/main/src/types/election/election.ts#23
[examples]: https://github.com/vocdoni/vocdoni-sdk/blob/main/examples
-[example-cra]: https://github.com/vocdoni/vocdoni-sdk/blob/main/examples/cra
+[example-vite]: https://github.com/vocdoni/vocdoni-sdk/blob/main/examples/vite-react-app
[example-esm]: https://github.com/vocdoni/vocdoni-sdk/blob/main/examples/esm
[quadratic voting example]: https://github.com/vocdoni/vocdoni-sdk/blob/main/examples/typescript/src/quadratic.ts
[quadratic voting documentation]: https://developer.vocdoni.io/protocol/ballot#quadratic-voting
diff --git a/docs/sdk/sidebars-api.js b/docs/sdk/sidebars-api.js
index 3f7de8ea3..ed542fa5c 100644
--- a/docs/sdk/sidebars-api.js
+++ b/docs/sdk/sidebars-api.js
@@ -9,6 +9,7 @@ module.exports = {
"sdk/CensusAPI",
"sdk/Census3API",
"sdk/Census3CensusAPI",
+ "sdk/Census3ServiceAPI",
"sdk/Census3StrategyAPI",
"sdk/Census3TokenAPI",
"sdk/ChainAPI",
@@ -18,13 +19,25 @@ module.exports = {
"sdk/FileAPI",
"sdk/VoteAPI",
"sdk/WalletAPI",
+ "sdk/ZkAPI",
"sdk/VocdoniCensus3Client",
"sdk/VocdoniSDKClient",
"sdk/AccountCore",
"sdk/ElectionCore",
"sdk/TransactionCore",
"sdk/VoteCore",
+ "sdk/AccountService",
+ "sdk/AnonymousService",
+ "sdk/CensusService",
+ "sdk/ChainService",
+ "sdk/CspService",
+ "sdk/ElectionService",
+ "sdk/FaucetService",
+ "sdk/FileService",
+ "sdk/Service",
+ "sdk/VoteService",
"sdk/Account",
+ "sdk/ArchivedCensus",
"sdk/Census",
"sdk/TokenCensus",
"sdk/CspCensus",
@@ -32,10 +45,12 @@ module.exports = {
"sdk/PlainCensus",
"sdk/PublishedCensus",
"sdk/WeightedCensus",
+ "sdk/ArchivedElection",
"sdk/Election",
"sdk/InvalidElection",
"sdk/PublishedElection",
"sdk/UnpublishedElection",
+ "sdk/AnonymousVote",
"sdk/CspVote",
"sdk/Vote",
"sdk/Asymmetric",
@@ -53,13 +68,14 @@ module.exports = {
"type": "category",
"label": "Typedef",
"items": [
+ "sdk/TxWaitOptions",
+ "sdk/ClientOptions",
"sdk/AccountData",
- "sdk/OffchainCensusProof",
+ "sdk/CensusProof",
+ "sdk/CensusImportExport",
"sdk/CspCensusProof",
- "sdk/FaucetPackage",
"sdk/FaucetOptions",
- "sdk/TxWaitOptions",
- "sdk/ClientOptions"
+ "sdk/FaucetPackage"
]
},
{