@vocdoni/davinci-sdk 0.1.1 → 0.1.3
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/dist/index.d.ts +147 -13
- package/dist/index.js +53330 -170
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +53310 -170
- package/dist/index.mjs.map +1 -1
- package/dist/index.umd.js +53327 -167
- package/dist/sequencer.d.ts +126 -5
- package/package.json +4 -1
package/dist/index.d.ts
CHANGED
|
@@ -1110,7 +1110,7 @@ interface DavinciCryptoOutput {
|
|
|
1110
1110
|
voteId: string;
|
|
1111
1111
|
circomInputs: ProofInputs;
|
|
1112
1112
|
}
|
|
1113
|
-
interface CSPSignOutput {
|
|
1113
|
+
interface CSPSignOutput$1 {
|
|
1114
1114
|
censusOrigin: CensusOrigin;
|
|
1115
1115
|
root: string;
|
|
1116
1116
|
address: string;
|
|
@@ -1125,7 +1125,7 @@ interface RawResult<T = any> {
|
|
|
1125
1125
|
}
|
|
1126
1126
|
interface GoDavinciCryptoWasm {
|
|
1127
1127
|
proofInputs(inputJson: string): RawResult<DavinciCryptoOutput>;
|
|
1128
|
-
cspSign(censusOrigin: number, privKey: string, processId: string, address: string, weight: string): RawResult<CSPSignOutput>;
|
|
1128
|
+
cspSign(censusOrigin: number, privKey: string, processId: string, address: string, weight: string): RawResult<CSPSignOutput$1>;
|
|
1129
1129
|
cspVerify(cspProof: string): RawResult<boolean>;
|
|
1130
1130
|
cspCensusRoot(censusOrigin: number, privKey: string): RawResult<{
|
|
1131
1131
|
root: string;
|
|
@@ -1189,7 +1189,7 @@ declare class DavinciCrypto {
|
|
|
1189
1189
|
* @returns The CSP proof as a parsed JSON object
|
|
1190
1190
|
* @throws if called before `await init()`, or if Go returns an error
|
|
1191
1191
|
*/
|
|
1192
|
-
cspSign(censusOrigin: CensusOrigin, privKey: string, processId: string, address: string, weight: string): Promise<CSPSignOutput>;
|
|
1192
|
+
cspSign(censusOrigin: CensusOrigin, privKey: string, processId: string, address: string, weight: string): Promise<CSPSignOutput$1>;
|
|
1193
1193
|
/**
|
|
1194
1194
|
* Verify a CSP (Credential Service Provider) proof.
|
|
1195
1195
|
* @param censusOrigin - The census origin type (e.g., CensusOrigin.CensusOriginCSP)
|
|
@@ -1690,6 +1690,48 @@ declare class ProcessOrchestrationService {
|
|
|
1690
1690
|
setProcessMaxVoters(processId: string, maxVoters: number): Promise<void>;
|
|
1691
1691
|
}
|
|
1692
1692
|
|
|
1693
|
+
interface Ciphertext {
|
|
1694
|
+
c1: [string, string];
|
|
1695
|
+
c2: [string, string];
|
|
1696
|
+
}
|
|
1697
|
+
interface BallotInputsOutput {
|
|
1698
|
+
processId: string;
|
|
1699
|
+
address: string;
|
|
1700
|
+
ballot: {
|
|
1701
|
+
curveType: string;
|
|
1702
|
+
ciphertexts: Ciphertext[];
|
|
1703
|
+
};
|
|
1704
|
+
ballotInputsHash: string;
|
|
1705
|
+
voteId: string;
|
|
1706
|
+
circomInputs: ProofInputs;
|
|
1707
|
+
}
|
|
1708
|
+
|
|
1709
|
+
declare class BallotInputGenerator {
|
|
1710
|
+
private builder?;
|
|
1711
|
+
private initialized;
|
|
1712
|
+
constructor();
|
|
1713
|
+
/**
|
|
1714
|
+
* Initialize the ballot input generator
|
|
1715
|
+
* Must be called before generating inputs
|
|
1716
|
+
*/
|
|
1717
|
+
init(): Promise<void>;
|
|
1718
|
+
/**
|
|
1719
|
+
* Generate ballot inputs for voting
|
|
1720
|
+
* @param processId - Process ID (hex string without 0x)
|
|
1721
|
+
* @param address - Voter address (hex string without 0x)
|
|
1722
|
+
* @param encryptionKey - Encryption public key [x, y]
|
|
1723
|
+
* @param ballotMode - Ballot mode configuration
|
|
1724
|
+
* @param choices - Array of voter choices
|
|
1725
|
+
* @param weight - Voter weight
|
|
1726
|
+
* @param customK - Optional custom randomness (will be generated if not provided)
|
|
1727
|
+
* @returns Ballot inputs ready for proof generation
|
|
1728
|
+
*/
|
|
1729
|
+
generateInputs(processId: string, address: string, encryptionKey: {
|
|
1730
|
+
x: string;
|
|
1731
|
+
y: string;
|
|
1732
|
+
}, ballotMode: BallotMode, choices: number[], weight: string, customK?: string): Promise<BallotInputsOutput>;
|
|
1733
|
+
}
|
|
1734
|
+
|
|
1693
1735
|
/**
|
|
1694
1736
|
* Simplified vote configuration interface for end users
|
|
1695
1737
|
*/
|
|
@@ -1742,12 +1784,15 @@ interface VoteOrchestrationConfig {
|
|
|
1742
1784
|
*/
|
|
1743
1785
|
declare class VoteOrchestrationService {
|
|
1744
1786
|
private apiService;
|
|
1745
|
-
private
|
|
1787
|
+
private getBallotInputGenerator;
|
|
1746
1788
|
private signer;
|
|
1747
1789
|
private censusProviders;
|
|
1748
1790
|
private readonly verifyCircuitFiles;
|
|
1749
1791
|
private readonly verifyProof;
|
|
1750
|
-
|
|
1792
|
+
private wasmCache;
|
|
1793
|
+
private zkeyCache;
|
|
1794
|
+
private vkeyCache;
|
|
1795
|
+
constructor(apiService: VocdoniApiService, getBallotInputGenerator: () => Promise<BallotInputGenerator>, signer: Signer, censusProviders?: CensusProviders, config?: VoteOrchestrationConfig);
|
|
1751
1796
|
/**
|
|
1752
1797
|
* Submit a vote with simplified configuration
|
|
1753
1798
|
* This method handles all the complex orchestration internally:
|
|
@@ -1828,7 +1873,7 @@ declare class VoteOrchestrationService {
|
|
|
1828
1873
|
*/
|
|
1829
1874
|
private getCensusProof;
|
|
1830
1875
|
/**
|
|
1831
|
-
* Generate vote proof inputs using
|
|
1876
|
+
* Generate vote proof inputs using BallotInputGenerator
|
|
1832
1877
|
*/
|
|
1833
1878
|
private generateVoteProofInputs;
|
|
1834
1879
|
/**
|
|
@@ -1836,7 +1881,11 @@ declare class VoteOrchestrationService {
|
|
|
1836
1881
|
*/
|
|
1837
1882
|
private validateChoices;
|
|
1838
1883
|
/**
|
|
1839
|
-
*
|
|
1884
|
+
* Verify hash of downloaded file
|
|
1885
|
+
*/
|
|
1886
|
+
private verifyHash;
|
|
1887
|
+
/**
|
|
1888
|
+
* Generate zk-SNARK proof using snarkjs directly (no CircomProof wrapper)
|
|
1840
1889
|
*/
|
|
1841
1890
|
private generateZkProof;
|
|
1842
1891
|
private hexToBytes;
|
|
@@ -1844,10 +1893,6 @@ declare class VoteOrchestrationService {
|
|
|
1844
1893
|
* Sign the vote using the signer
|
|
1845
1894
|
*/
|
|
1846
1895
|
private signVote;
|
|
1847
|
-
/**
|
|
1848
|
-
* Submit the vote request to the sequencer
|
|
1849
|
-
*/
|
|
1850
|
-
private submitVoteRequest;
|
|
1851
1896
|
}
|
|
1852
1897
|
|
|
1853
1898
|
/**
|
|
@@ -1946,6 +1991,85 @@ declare function signProcessCreation(processId: string, signer: Signer | Wallet)
|
|
|
1946
1991
|
*/
|
|
1947
1992
|
declare function validateProcessId(processId: string): boolean;
|
|
1948
1993
|
|
|
1994
|
+
interface CSPSignOutput {
|
|
1995
|
+
censusOrigin: CensusOrigin;
|
|
1996
|
+
root: string;
|
|
1997
|
+
address: string;
|
|
1998
|
+
weight: string;
|
|
1999
|
+
processId: string;
|
|
2000
|
+
publicKey: string;
|
|
2001
|
+
signature: string;
|
|
2002
|
+
}
|
|
2003
|
+
interface DavinciCSPOptions {
|
|
2004
|
+
/** URL to wasm_exec.js */
|
|
2005
|
+
wasmExecUrl: string;
|
|
2006
|
+
/** URL to the compiled davinci_crypto.wasm */
|
|
2007
|
+
wasmUrl: string;
|
|
2008
|
+
/** How long (ms) to wait for the Go runtime to attach DavinciCrypto */
|
|
2009
|
+
initTimeoutMs?: number;
|
|
2010
|
+
/** Optional SHA-256 hash to verify wasm_exec.js integrity */
|
|
2011
|
+
wasmExecHash?: string;
|
|
2012
|
+
/** Optional SHA-256 hash to verify davinci_crypto.wasm integrity */
|
|
2013
|
+
wasmHash?: string;
|
|
2014
|
+
}
|
|
2015
|
+
declare class DavinciCSP {
|
|
2016
|
+
private go;
|
|
2017
|
+
private initialized;
|
|
2018
|
+
private readonly wasmExecUrl;
|
|
2019
|
+
private readonly wasmUrl;
|
|
2020
|
+
private readonly initTimeoutMs;
|
|
2021
|
+
private readonly wasmExecHash?;
|
|
2022
|
+
private readonly wasmHash?;
|
|
2023
|
+
private static wasmExecCache;
|
|
2024
|
+
private static wasmBinaryCache;
|
|
2025
|
+
constructor(opts: DavinciCSPOptions);
|
|
2026
|
+
/**
|
|
2027
|
+
* Computes SHA-256 hash of the given data and compares it with the expected hash.
|
|
2028
|
+
* @param data - The data to hash (string or ArrayBuffer)
|
|
2029
|
+
* @param expectedHash - The expected SHA-256 hash in hexadecimal format
|
|
2030
|
+
* @param filename - The filename for error reporting
|
|
2031
|
+
* @throws Error if the computed hash doesn't match the expected hash
|
|
2032
|
+
*/
|
|
2033
|
+
private verifyHash;
|
|
2034
|
+
/**
|
|
2035
|
+
* Must be awaited before calling CSP functions.
|
|
2036
|
+
* Safe to call multiple times.
|
|
2037
|
+
*/
|
|
2038
|
+
init(): Promise<void>;
|
|
2039
|
+
/**
|
|
2040
|
+
* Generate a CSP (Credential Service Provider) signature for census proof.
|
|
2041
|
+
* @param censusOrigin - The census origin type (e.g., CensusOrigin.CSP)
|
|
2042
|
+
* @param privKey - The private key in hex format
|
|
2043
|
+
* @param processId - The process ID in hex format
|
|
2044
|
+
* @param address - The address in hex format
|
|
2045
|
+
* @param weight - The vote weight as a decimal string
|
|
2046
|
+
* @returns The CSP proof as a parsed JSON object
|
|
2047
|
+
* @throws if called before `await init()`, or if Go returns an error
|
|
2048
|
+
*/
|
|
2049
|
+
cspSign(censusOrigin: CensusOrigin, privKey: string, processId: string, address: string, weight: string): Promise<CSPSignOutput>;
|
|
2050
|
+
/**
|
|
2051
|
+
* Verify a CSP (Credential Service Provider) proof.
|
|
2052
|
+
* @param censusOrigin - The census origin type (e.g., CensusOrigin.CSP)
|
|
2053
|
+
* @param root - The census root
|
|
2054
|
+
* @param address - The address
|
|
2055
|
+
* @param weight - The vote weight as a decimal string
|
|
2056
|
+
* @param processId - The process ID
|
|
2057
|
+
* @param publicKey - The public key
|
|
2058
|
+
* @param signature - The signature
|
|
2059
|
+
* @returns The verification result
|
|
2060
|
+
* @throws if called before `await init()`, or if Go returns an error
|
|
2061
|
+
*/
|
|
2062
|
+
cspVerify(censusOrigin: CensusOrigin, root: string, address: string, weight: string, processId: string, publicKey: string, signature: string): Promise<boolean>;
|
|
2063
|
+
/**
|
|
2064
|
+
* Generate a CSP (Credential Service Provider) census root.
|
|
2065
|
+
* @param censusOrigin - The census origin type (e.g., CensusOrigin.CSP)
|
|
2066
|
+
* @param privKey - The private key in hex format
|
|
2067
|
+
* @returns The census root as a hexadecimal string
|
|
2068
|
+
* @throws if called before `await init()`, or if Go returns an error
|
|
2069
|
+
*/
|
|
2070
|
+
cspCensusRoot(censusOrigin: CensusOrigin, privKey: string): Promise<string>;
|
|
2071
|
+
}
|
|
2072
|
+
|
|
1949
2073
|
/**
|
|
1950
2074
|
* Configuration interface for the DavinciSDK
|
|
1951
2075
|
*/
|
|
@@ -2004,6 +2128,8 @@ declare class DavinciSDK {
|
|
|
2004
2128
|
private _processOrchestrator?;
|
|
2005
2129
|
private _voteOrchestrator?;
|
|
2006
2130
|
private davinciCrypto?;
|
|
2131
|
+
private davinciCSP?;
|
|
2132
|
+
private ballotInputGenerator?;
|
|
2007
2133
|
private initialized;
|
|
2008
2134
|
private censusProviders;
|
|
2009
2135
|
constructor(config: DavinciSDKConfig);
|
|
@@ -2034,6 +2160,14 @@ declare class DavinciSDK {
|
|
|
2034
2160
|
* Get or initialize the DavinciCrypto service for cryptographic operations
|
|
2035
2161
|
*/
|
|
2036
2162
|
getCrypto(): Promise<DavinciCrypto>;
|
|
2163
|
+
/**
|
|
2164
|
+
* Get or initialize the DavinciCSP service for CSP cryptographic operations
|
|
2165
|
+
*/
|
|
2166
|
+
getCSP(): Promise<DavinciCSP>;
|
|
2167
|
+
/**
|
|
2168
|
+
* Get or initialize the BallotInputGenerator service for ballot input generation
|
|
2169
|
+
*/
|
|
2170
|
+
getBallotInputGenerator(): Promise<BallotInputGenerator>;
|
|
2037
2171
|
/**
|
|
2038
2172
|
* Get the process orchestration service for simplified process creation.
|
|
2039
2173
|
* Requires a signer with a provider for blockchain interactions.
|
|
@@ -2716,5 +2850,5 @@ declare class DavinciSDK {
|
|
|
2716
2850
|
private ensureProvider;
|
|
2717
2851
|
}
|
|
2718
2852
|
|
|
2719
|
-
export { BaseService, Census, CensusNotUpdatable, CensusOrchestrator, CensusOrigin, CircomProof, ContractServiceError, CspCensus, DavinciCrypto, DavinciSDK, ElectionMetadataTemplate, ElectionResultsTypeNames, MerkleCensus, OffchainCensus, OffchainDynamicCensus, OnchainCensus, OrganizationAdministratorError, OrganizationCreateError, OrganizationDeleteError, OrganizationRegistryService, OrganizationUpdateError, ProcessCensusError, ProcessCreateError, ProcessDurationError, ProcessOrchestrationService, ProcessRegistryService, ProcessResultError, ProcessStateTransitionError, ProcessStatus, ProcessStatusError, PublishedCensus, SmartContractService, TxStatus, VocdoniApiService, VocdoniCensusService, VocdoniSequencerService, VoteOrchestrationService, VoteStatus, assertCSPCensusProof, assertMerkleCensusProof, createProcessSignatureMessage, getElectionMetadataTemplate, isCSPCensusProof, isMerkleCensusProof, signProcessCreation, validateProcessId };
|
|
2720
|
-
export type { AbstainProperties, AnyJson, ApiError, ApprovalProperties, BallotMode, BaseCensusProof, BaseProcess, BudgetProperties, CSPCensusProof, CSPCensusProofProvider, CSPSignOutput, CensusData, CensusParticipant, CensusProof, CensusProviders, CensusSizeResponse, Choice, ChoiceProperties, CircomProofOptions, CreateProcessRequest, CreateProcessResponse, CustomMeta, DavinciCryptoCiphertext, DavinciCryptoInputs, DavinciCryptoOptions, DavinciCryptoOutput, DavinciSDKConfig, ElectionMetadata, ElectionResultsType, EncryptionKey, EntityCallback, GetProcessResponse, Groth16Proof, HealthResponse, IChoice, IQuestion, InfoResponse, JsonArray, JsonMap, ListProcessesResponse, MerkleCensusProof, MerkleCensusProofProvider, MultiLanguage, OrganizationAdministratorAddedCallback, OrganizationAdministratorRemovedCallback, OrganizationCreatedCallback, OrganizationInfo, OrganizationUpdatedCallback, Participant, ParticipantInfoResponse, ProcessCensusUpdatedCallback, ProcessConfig, ProcessConfigWithMetadata, ProcessConfigWithMetadataUri, ProcessCreatedCallback, ProcessCreationResult, ProcessDurationChangedCallback, ProcessInfo, ProcessMaxVotersChangedCallback, ProcessQuestion, ProcessResultsSetCallback, ProcessStateTransitionedCallback, ProcessStatusChangedCallback, ProofInputs, ProtocolVersion, PublishCensusResponse, QuadraticProperties, Question, SequencerStats, Snapshot, SnapshotsQueryParams, SnapshotsResponse, TxStatusEvent, VocdoniApiServiceConfig, VoteBallot, VoteCiphertext, VoteConfig, VoteOrchestrationConfig, VoteProof, VoteRequest, VoteResult, VoteStatusInfo, VoteStatusResponse, WorkerStats, WorkersResponse };
|
|
2853
|
+
export { BallotInputGenerator, BaseService, Census, CensusNotUpdatable, CensusOrchestrator, CensusOrigin, CircomProof, ContractServiceError, CspCensus, DavinciCSP, DavinciCrypto, DavinciSDK, ElectionMetadataTemplate, ElectionResultsTypeNames, MerkleCensus, OffchainCensus, OffchainDynamicCensus, OnchainCensus, OrganizationAdministratorError, OrganizationCreateError, OrganizationDeleteError, OrganizationRegistryService, OrganizationUpdateError, ProcessCensusError, ProcessCreateError, ProcessDurationError, ProcessOrchestrationService, ProcessRegistryService, ProcessResultError, ProcessStateTransitionError, ProcessStatus, ProcessStatusError, PublishedCensus, SmartContractService, TxStatus, VocdoniApiService, VocdoniCensusService, VocdoniSequencerService, VoteOrchestrationService, VoteStatus, assertCSPCensusProof, assertMerkleCensusProof, createProcessSignatureMessage, getElectionMetadataTemplate, isCSPCensusProof, isMerkleCensusProof, signProcessCreation, validateProcessId };
|
|
2854
|
+
export type { AbstainProperties, AnyJson, ApiError, ApprovalProperties, BallotMode, BaseCensusProof, BaseProcess, BudgetProperties, CSPCensusProof, CSPCensusProofProvider, CSPSignOutput$1 as CSPSignOutput, CensusData, CensusParticipant, CensusProof, CensusProviders, CensusSizeResponse, Choice, ChoiceProperties, CircomProofOptions, CreateProcessRequest, CreateProcessResponse, CustomMeta, DavinciCryptoCiphertext, DavinciCryptoInputs, DavinciCryptoOptions, DavinciCryptoOutput, DavinciSDKConfig, ElectionMetadata, ElectionResultsType, EncryptionKey, EntityCallback, GetProcessResponse, Groth16Proof, HealthResponse, IChoice, IQuestion, InfoResponse, JsonArray, JsonMap, ListProcessesResponse, MerkleCensusProof, MerkleCensusProofProvider, MultiLanguage, OrganizationAdministratorAddedCallback, OrganizationAdministratorRemovedCallback, OrganizationCreatedCallback, OrganizationInfo, OrganizationUpdatedCallback, Participant, ParticipantInfoResponse, ProcessCensusUpdatedCallback, ProcessConfig, ProcessConfigWithMetadata, ProcessConfigWithMetadataUri, ProcessCreatedCallback, ProcessCreationResult, ProcessDurationChangedCallback, ProcessInfo, ProcessMaxVotersChangedCallback, ProcessQuestion, ProcessResultsSetCallback, ProcessStateTransitionedCallback, ProcessStatusChangedCallback, ProofInputs, ProtocolVersion, PublishCensusResponse, QuadraticProperties, Question, SequencerStats, Snapshot, SnapshotsQueryParams, SnapshotsResponse, TxStatusEvent, VocdoniApiServiceConfig, VoteBallot, VoteCiphertext, VoteConfig, VoteOrchestrationConfig, VoteProof, VoteRequest, VoteResult, VoteStatusInfo, VoteStatusResponse, WorkerStats, WorkersResponse };
|