@vocdoni/davinci-sdk 0.1.1 → 0.1.2

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.
@@ -414,7 +414,7 @@ interface DavinciCryptoOutput {
414
414
  voteId: string;
415
415
  circomInputs: ProofInputs;
416
416
  }
417
- interface CSPSignOutput {
417
+ interface CSPSignOutput$1 {
418
418
  censusOrigin: CensusOrigin;
419
419
  root: string;
420
420
  address: string;
@@ -429,7 +429,7 @@ interface RawResult<T = any> {
429
429
  }
430
430
  interface GoDavinciCryptoWasm {
431
431
  proofInputs(inputJson: string): RawResult<DavinciCryptoOutput>;
432
- cspSign(censusOrigin: number, privKey: string, processId: string, address: string, weight: string): RawResult<CSPSignOutput>;
432
+ cspSign(censusOrigin: number, privKey: string, processId: string, address: string, weight: string): RawResult<CSPSignOutput$1>;
433
433
  cspVerify(cspProof: string): RawResult<boolean>;
434
434
  cspCensusRoot(censusOrigin: number, privKey: string): RawResult<{
435
435
  root: string;
@@ -493,7 +493,7 @@ declare class DavinciCrypto {
493
493
  * @returns The CSP proof as a parsed JSON object
494
494
  * @throws if called before `await init()`, or if Go returns an error
495
495
  */
496
- cspSign(censusOrigin: CensusOrigin, privKey: string, processId: string, address: string, weight: string): Promise<CSPSignOutput>;
496
+ cspSign(censusOrigin: CensusOrigin, privKey: string, processId: string, address: string, weight: string): Promise<CSPSignOutput$1>;
497
497
  /**
498
498
  * Verify a CSP (Credential Service Provider) proof.
499
499
  * @param censusOrigin - The census origin type (e.g., CensusOrigin.CensusOriginCSP)
@@ -517,6 +517,48 @@ declare class DavinciCrypto {
517
517
  cspCensusRoot(censusOrigin: CensusOrigin, privKey: string): Promise<string>;
518
518
  }
519
519
 
520
+ interface Ciphertext {
521
+ c1: [string, string];
522
+ c2: [string, string];
523
+ }
524
+ interface BallotInputsOutput {
525
+ processId: string;
526
+ address: string;
527
+ ballot: {
528
+ curveType: string;
529
+ ciphertexts: Ciphertext[];
530
+ };
531
+ ballotInputsHash: string;
532
+ voteId: string;
533
+ circomInputs: ProofInputs;
534
+ }
535
+
536
+ declare class BallotInputGenerator {
537
+ private builder?;
538
+ private initialized;
539
+ constructor();
540
+ /**
541
+ * Initialize the ballot input generator
542
+ * Must be called before generating inputs
543
+ */
544
+ init(): Promise<void>;
545
+ /**
546
+ * Generate ballot inputs for voting
547
+ * @param processId - Process ID (hex string without 0x)
548
+ * @param address - Voter address (hex string without 0x)
549
+ * @param encryptionKey - Encryption public key [x, y]
550
+ * @param ballotMode - Ballot mode configuration
551
+ * @param choices - Array of voter choices
552
+ * @param weight - Voter weight
553
+ * @param customK - Optional custom randomness (will be generated if not provided)
554
+ * @returns Ballot inputs ready for proof generation
555
+ */
556
+ generateInputs(processId: string, address: string, encryptionKey: {
557
+ x: string;
558
+ y: string;
559
+ }, ballotMode: BallotMode, choices: number[], weight: string, customK?: string): Promise<BallotInputsOutput>;
560
+ }
561
+
520
562
  declare class VocdoniSequencerService extends BaseService {
521
563
  constructor(baseURL: string);
522
564
  ping(): Promise<void>;
@@ -536,5 +578,84 @@ declare class VocdoniSequencerService extends BaseService {
536
578
  getWorkers(): Promise<WorkersResponse>;
537
579
  }
538
580
 
539
- export { CircomProof, DavinciCrypto, VocdoniSequencerService, VoteStatus, createProcessSignatureMessage, signProcessCreation, validateProcessId };
540
- export type { CSPSignOutput, CircomProofOptions, CreateProcessRequest, CreateProcessResponse, DavinciCryptoCiphertext, DavinciCryptoInputs, DavinciCryptoOptions, DavinciCryptoOutput, GetProcessResponse, Groth16Proof, InfoResponse, ListProcessesResponse, ParticipantInfoResponse, ProofInputs, SequencerStats, VoteBallot, VoteCiphertext, VoteProof, VoteRequest, VoteStatusResponse, WorkerStats, WorkersResponse };
581
+ interface CSPSignOutput {
582
+ censusOrigin: CensusOrigin;
583
+ root: string;
584
+ address: string;
585
+ weight: string;
586
+ processId: string;
587
+ publicKey: string;
588
+ signature: string;
589
+ }
590
+ interface DavinciCSPOptions {
591
+ /** URL to wasm_exec.js */
592
+ wasmExecUrl: string;
593
+ /** URL to the compiled davinci_crypto.wasm */
594
+ wasmUrl: string;
595
+ /** How long (ms) to wait for the Go runtime to attach DavinciCrypto */
596
+ initTimeoutMs?: number;
597
+ /** Optional SHA-256 hash to verify wasm_exec.js integrity */
598
+ wasmExecHash?: string;
599
+ /** Optional SHA-256 hash to verify davinci_crypto.wasm integrity */
600
+ wasmHash?: string;
601
+ }
602
+ declare class DavinciCSP {
603
+ private go;
604
+ private initialized;
605
+ private readonly wasmExecUrl;
606
+ private readonly wasmUrl;
607
+ private readonly initTimeoutMs;
608
+ private readonly wasmExecHash?;
609
+ private readonly wasmHash?;
610
+ private static wasmExecCache;
611
+ private static wasmBinaryCache;
612
+ constructor(opts: DavinciCSPOptions);
613
+ /**
614
+ * Computes SHA-256 hash of the given data and compares it with the expected hash.
615
+ * @param data - The data to hash (string or ArrayBuffer)
616
+ * @param expectedHash - The expected SHA-256 hash in hexadecimal format
617
+ * @param filename - The filename for error reporting
618
+ * @throws Error if the computed hash doesn't match the expected hash
619
+ */
620
+ private verifyHash;
621
+ /**
622
+ * Must be awaited before calling CSP functions.
623
+ * Safe to call multiple times.
624
+ */
625
+ init(): Promise<void>;
626
+ /**
627
+ * Generate a CSP (Credential Service Provider) signature for census proof.
628
+ * @param censusOrigin - The census origin type (e.g., CensusOrigin.CSP)
629
+ * @param privKey - The private key in hex format
630
+ * @param processId - The process ID in hex format
631
+ * @param address - The address in hex format
632
+ * @param weight - The vote weight as a decimal string
633
+ * @returns The CSP proof as a parsed JSON object
634
+ * @throws if called before `await init()`, or if Go returns an error
635
+ */
636
+ cspSign(censusOrigin: CensusOrigin, privKey: string, processId: string, address: string, weight: string): Promise<CSPSignOutput>;
637
+ /**
638
+ * Verify a CSP (Credential Service Provider) proof.
639
+ * @param censusOrigin - The census origin type (e.g., CensusOrigin.CSP)
640
+ * @param root - The census root
641
+ * @param address - The address
642
+ * @param weight - The vote weight as a decimal string
643
+ * @param processId - The process ID
644
+ * @param publicKey - The public key
645
+ * @param signature - The signature
646
+ * @returns The verification result
647
+ * @throws if called before `await init()`, or if Go returns an error
648
+ */
649
+ cspVerify(censusOrigin: CensusOrigin, root: string, address: string, weight: string, processId: string, publicKey: string, signature: string): Promise<boolean>;
650
+ /**
651
+ * Generate a CSP (Credential Service Provider) census root.
652
+ * @param censusOrigin - The census origin type (e.g., CensusOrigin.CSP)
653
+ * @param privKey - The private key in hex format
654
+ * @returns The census root as a hexadecimal string
655
+ * @throws if called before `await init()`, or if Go returns an error
656
+ */
657
+ cspCensusRoot(censusOrigin: CensusOrigin, privKey: string): Promise<string>;
658
+ }
659
+
660
+ export { BallotInputGenerator, CircomProof, DavinciCSP, DavinciCrypto, VocdoniSequencerService, VoteStatus, createProcessSignatureMessage, signProcessCreation, validateProcessId };
661
+ export type { CSPSignOutput$1 as CSPSignOutput, CircomProofOptions, CreateProcessRequest, CreateProcessResponse, DavinciCryptoCiphertext, DavinciCryptoInputs, DavinciCryptoOptions, DavinciCryptoOutput, GetProcessResponse, Groth16Proof, InfoResponse, ListProcessesResponse, ParticipantInfoResponse, ProofInputs, SequencerStats, VoteBallot, VoteCiphertext, VoteProof, VoteRequest, VoteStatusResponse, WorkerStats, WorkersResponse };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vocdoni/davinci-sdk",
3
- "version": "0.1.1",
3
+ "version": "0.1.2",
4
4
  "type": "module",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",
@@ -74,6 +74,7 @@
74
74
  "@ethereumjs/common": "^4.4.0",
75
75
  "@vocdoni/davinci-contracts": "0.0.35",
76
76
  "axios": "^1.8.4",
77
+ "circomlibjs": "^0.1.7",
77
78
  "ethers": "^6.7.1",
78
79
  "snarkjs": "^0.7.5"
79
80
  },