@vocdoni/davinci-sdk 0.1.0 → 0.1.1

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.umd.js CHANGED
@@ -385,16 +385,19 @@
385
385
  /**
386
386
  * Creates an OnchainCensus
387
387
  * @param contractAddress - The address of the smart contract (e.g., ERC20, ERC721)
388
- * @param uri - Optional URI with census information
388
+ * @param uri - The URI pointing to census data source (e.g., subgraph endpoint)
389
389
  */
390
390
  constructor(contractAddress, uri) {
391
391
  super(CensusOrigin.Onchain);
392
392
  if (!/^(0x)?[0-9a-fA-F]{40}$/i.test(contractAddress)) {
393
393
  throw new Error("Contract address is missing or invalid");
394
394
  }
395
+ if (!uri || uri.trim() === "") {
396
+ throw new Error("URI is required for onchain census");
397
+ }
395
398
  this._contractAddress = contractAddress;
396
- this._censusRoot = contractAddress;
397
- this._censusURI = uri || `contract://${contractAddress}`;
399
+ this._censusRoot = "0x0000000000000000000000000000000000000000000000000000000000000000";
400
+ this._censusURI = uri;
398
401
  }
399
402
  get contractAddress() {
400
403
  return this._contractAddress;
@@ -474,10 +477,12 @@
474
477
  if (!census.censusRoot || !census.censusURI) {
475
478
  throw new Error("Census data is incomplete");
476
479
  }
480
+ const contractAddress = "contractAddress" in census ? census.contractAddress : void 0;
477
481
  return {
478
482
  type: census.censusOrigin,
479
483
  root: census.censusRoot,
480
- uri: census.censusURI
484
+ uri: census.censusURI,
485
+ contractAddress
481
486
  };
482
487
  }
483
488
  }
@@ -1001,7 +1006,9 @@
1001
1006
  const contractCensus = {
1002
1007
  censusOrigin: BigInt(census.censusOrigin),
1003
1008
  censusRoot: census.censusRoot,
1004
- censusURI: census.censusURI
1009
+ contractAddress: census.contractAddress ?? "0x0000000000000000000000000000000000000000",
1010
+ censusURI: census.censusURI,
1011
+ onchainAllowAnyValidRoot: census.onchainAllowAnyValidRoot ?? false
1005
1012
  };
1006
1013
  return this.sendTx(
1007
1014
  this.contract.newProcess(
@@ -1032,7 +1039,9 @@
1032
1039
  const contractCensus = {
1033
1040
  censusOrigin: BigInt(census.censusOrigin),
1034
1041
  censusRoot: census.censusRoot,
1035
- censusURI: census.censusURI
1042
+ contractAddress: census.contractAddress ?? "0x0000000000000000000000000000000000000000",
1043
+ censusURI: census.censusURI,
1044
+ onchainAllowAnyValidRoot: census.onchainAllowAnyValidRoot ?? false
1036
1045
  };
1037
1046
  return this.sendTx(
1038
1047
  this.contract.setProcessCensus(processID, contractCensus).catch((e) => {
@@ -1164,12 +1173,7 @@
1164
1173
  }
1165
1174
  await this.censusOrchestrator.publish(census);
1166
1175
  }
1167
- const censusData = this.censusOrchestrator.getCensusData(census);
1168
- return {
1169
- type: censusData.type,
1170
- root: censusData.root,
1171
- uri: censusData.uri
1172
- };
1176
+ return this.censusOrchestrator.getCensusData(census);
1173
1177
  }
1174
1178
  const { size, ...censusWithoutSize } = census;
1175
1179
  return censusWithoutSize;
@@ -1399,7 +1403,12 @@
1399
1403
  const census = {
1400
1404
  censusOrigin: censusConfig.type,
1401
1405
  censusRoot,
1402
- censusURI: censusConfig.uri
1406
+ contractAddress: censusConfig.contractAddress,
1407
+ // Only set for onchain censuses
1408
+ censusURI: censusConfig.uri,
1409
+ // For onchain censuses (ERC20 token snapshots), allow any valid merkle root
1410
+ // For other census types, require the specific censusRoot
1411
+ onchainAllowAnyValidRoot: censusConfig.type === CensusOrigin.Onchain
1403
1412
  };
1404
1413
  return {
1405
1414
  processId,
@@ -149,7 +149,19 @@ interface BallotMode {
149
149
  interface CensusData {
150
150
  censusOrigin: CensusOrigin;
151
151
  censusRoot: string;
152
+ /**
153
+ * Contract address for onchain censuses (ERC20/ERC721 token contract).
154
+ * For offchain censuses, defaults to zero address.
155
+ * @default "0x0000000000000000000000000000000000000000"
156
+ */
157
+ contractAddress?: string;
152
158
  censusURI: string;
159
+ /**
160
+ * For onchain censuses, allows any valid Merkle root from the onchain source.
161
+ * For other census types, set to false to require the specific censusRoot.
162
+ * @default false
163
+ */
164
+ onchainAllowAnyValidRoot?: boolean;
153
165
  }
154
166
  interface EncryptionKey {
155
167
  x: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vocdoni/davinci-sdk",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "type": "module",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",
@@ -72,7 +72,7 @@
72
72
  },
73
73
  "dependencies": {
74
74
  "@ethereumjs/common": "^4.4.0",
75
- "@vocdoni/davinci-contracts": "0.0.31",
75
+ "@vocdoni/davinci-contracts": "0.0.35",
76
76
  "axios": "^1.8.4",
77
77
  "ethers": "^6.7.1",
78
78
  "snarkjs": "^0.7.5"