@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.mjs CHANGED
@@ -384,16 +384,19 @@ class OnchainCensus extends Census {
384
384
  /**
385
385
  * Creates an OnchainCensus
386
386
  * @param contractAddress - The address of the smart contract (e.g., ERC20, ERC721)
387
- * @param uri - Optional URI with census information
387
+ * @param uri - The URI pointing to census data source (e.g., subgraph endpoint)
388
388
  */
389
389
  constructor(contractAddress, uri) {
390
390
  super(CensusOrigin.Onchain);
391
391
  if (!/^(0x)?[0-9a-fA-F]{40}$/i.test(contractAddress)) {
392
392
  throw new Error("Contract address is missing or invalid");
393
393
  }
394
+ if (!uri || uri.trim() === "") {
395
+ throw new Error("URI is required for onchain census");
396
+ }
394
397
  this._contractAddress = contractAddress;
395
- this._censusRoot = contractAddress;
396
- this._censusURI = uri || `contract://${contractAddress}`;
398
+ this._censusRoot = "0x0000000000000000000000000000000000000000000000000000000000000000";
399
+ this._censusURI = uri;
397
400
  }
398
401
  get contractAddress() {
399
402
  return this._contractAddress;
@@ -473,10 +476,12 @@ class CensusOrchestrator {
473
476
  if (!census.censusRoot || !census.censusURI) {
474
477
  throw new Error("Census data is incomplete");
475
478
  }
479
+ const contractAddress = "contractAddress" in census ? census.contractAddress : void 0;
476
480
  return {
477
481
  type: census.censusOrigin,
478
482
  root: census.censusRoot,
479
- uri: census.censusURI
483
+ uri: census.censusURI,
484
+ contractAddress
480
485
  };
481
486
  }
482
487
  }
@@ -1000,7 +1005,9 @@ class ProcessRegistryService extends SmartContractService {
1000
1005
  const contractCensus = {
1001
1006
  censusOrigin: BigInt(census.censusOrigin),
1002
1007
  censusRoot: census.censusRoot,
1003
- censusURI: census.censusURI
1008
+ contractAddress: census.contractAddress ?? "0x0000000000000000000000000000000000000000",
1009
+ censusURI: census.censusURI,
1010
+ onchainAllowAnyValidRoot: census.onchainAllowAnyValidRoot ?? false
1004
1011
  };
1005
1012
  return this.sendTx(
1006
1013
  this.contract.newProcess(
@@ -1031,7 +1038,9 @@ class ProcessRegistryService extends SmartContractService {
1031
1038
  const contractCensus = {
1032
1039
  censusOrigin: BigInt(census.censusOrigin),
1033
1040
  censusRoot: census.censusRoot,
1034
- censusURI: census.censusURI
1041
+ contractAddress: census.contractAddress ?? "0x0000000000000000000000000000000000000000",
1042
+ censusURI: census.censusURI,
1043
+ onchainAllowAnyValidRoot: census.onchainAllowAnyValidRoot ?? false
1035
1044
  };
1036
1045
  return this.sendTx(
1037
1046
  this.contract.setProcessCensus(processID, contractCensus).catch((e) => {
@@ -1163,12 +1172,7 @@ class ProcessOrchestrationService {
1163
1172
  }
1164
1173
  await this.censusOrchestrator.publish(census);
1165
1174
  }
1166
- const censusData = this.censusOrchestrator.getCensusData(census);
1167
- return {
1168
- type: censusData.type,
1169
- root: censusData.root,
1170
- uri: censusData.uri
1171
- };
1175
+ return this.censusOrchestrator.getCensusData(census);
1172
1176
  }
1173
1177
  const { size, ...censusWithoutSize } = census;
1174
1178
  return censusWithoutSize;
@@ -1398,7 +1402,12 @@ class ProcessOrchestrationService {
1398
1402
  const census = {
1399
1403
  censusOrigin: censusConfig.type,
1400
1404
  censusRoot,
1401
- censusURI: censusConfig.uri
1405
+ contractAddress: censusConfig.contractAddress,
1406
+ // Only set for onchain censuses
1407
+ censusURI: censusConfig.uri,
1408
+ // For onchain censuses (ERC20 token snapshots), allow any valid merkle root
1409
+ // For other census types, require the specific censusRoot
1410
+ onchainAllowAnyValidRoot: censusConfig.type === CensusOrigin.Onchain
1402
1411
  };
1403
1412
  return {
1404
1413
  processId,