Comparing version 0.10.4 to 0.10.5
@@ -11,5 +11,6 @@ { | ||
"name": "Run Example", | ||
"program": "${workspaceFolder}/example/index" | ||
"program": "${workspaceFolder}/example/index", | ||
"cwd": "${workspaceFolder}/example" | ||
} | ||
] | ||
} |
import { Wallet, Signer } from "ethers"; | ||
import { DVoteGateway } from "../net/gateway"; | ||
import GatewayInfo from "../wrappers/gateway-info"; | ||
export declare function addCensus(censusId: string, pubKeys: string[], gateway: DVoteGateway, walletOrSigner: Wallet | Signer): Promise<any>; | ||
export declare function addClaim(): void; | ||
export declare function addClaimBulk(): void; | ||
export declare function getRoot(): void; | ||
/** | ||
* A census ID consists of the Entity ID and the hash of the name. | ||
* This function returns the full Census ID | ||
*/ | ||
export declare function generateCensusId(censusName: string, entityId: string): string; | ||
/** | ||
* A census ID consists of the Entity ID and the hash of the name. | ||
* This function computes the second term | ||
*/ | ||
export declare function generateCensusIdSuffix(censusName: string): string; | ||
/** | ||
* Asks the Gateway to create a new census and set the given public key as the ones who can manage it | ||
* @param censusName Name given to the census. Will be used to generate the census ID by trimming spaces and converting text to lowercase | ||
* @param managerPublicKeys ECDSA public key(s) that can manage this census | ||
* @param gateway A DVoteGateway instance connected to a remote Gateway | ||
* @param walletOrSigner | ||
* @returns Promise resolving with the new merkleRoot | ||
*/ | ||
export declare function addCensus(censusName: string, managerPublicKeys: string[], entityId: string, gateway: DVoteGateway, walletOrSigner: Wallet | Signer): Promise<{ | ||
censusId: string; | ||
merkleRoot: string; | ||
}>; | ||
/** | ||
* Asks the Gateway to add the given public key hashe to a census previously registered on it | ||
* @param censusId Full Census ID containing the Entity ID and the hash of the original name | ||
* @param pubKeyHash SHA3-256 array generated from a users' public key | ||
* @param gateway A DVoteGateway instance already connected to a remote Gateway | ||
* @param walletOrSigner | ||
* @returns Promise resolving with the new merkleRoot | ||
*/ | ||
export declare function addClaim(censusId: string, pubKeyHash: string, gateway: DVoteGateway, walletOrSigner: Wallet | Signer): Promise<string>; | ||
/** | ||
* Asks the Gateway to add the given public key hashes to a census previously registered on it | ||
* @param censusId Full Census ID containing the Entity ID and the hash of the original name | ||
* @param pubKeyHashes SHA3-256 array generated from the users' public keys | ||
* @param gateway A DVoteGateway instance already connected to a remote Gateway | ||
* @param walletOrSigner | ||
* @returns Promise resolving with the new merkleRoot | ||
*/ | ||
export declare function addClaimBulk(censusId: string, pubKeyHashes: string[], gateway: DVoteGateway, walletOrSigner: Wallet | Signer): Promise<string>; | ||
/** | ||
* Asks the Gateway to fetch | ||
* @param censusId The full Census ID to fetch from the Gateway | ||
* @param gateway A DVoteGateway instance already connected to a remote Gateway | ||
* @returns Promise resolving with the merkleRoot | ||
*/ | ||
export declare function getRoot(censusId: string, gateway: DVoteGateway): Promise<string>; | ||
/** Dumps the entire content of the census as an array of hexStrings rady to be imported to another census service */ | ||
export declare function dump(): void; | ||
/** Dumps the contents of a census in raw string format. Not valid to use with `importDump` */ | ||
export declare function dumpPlain(): void; | ||
/** Only works with specific merkletree format used by dump method. To add a list of plain claims use `addClaimBulk` instead */ | ||
export declare function importDump(): void; | ||
/** Import a previously published remote census. Only valid URIs accepted */ | ||
export declare function importRemote(): void; | ||
/** Exports and publish the entire census on the storage of the backend (usually IPFS). Returns the URI of the set of claims */ | ||
export declare function publishCensus(censusId: string, gateway: DVoteGateway): Promise<string>; | ||
/** | ||
* Fetch the proof of the given index on the process census using the given gateway | ||
* @param processId | ||
* @param keyPath | ||
* @param claim | ||
* @param gateway | ||
*/ | ||
export declare function generateProof(processId: string, keyPath: string, gateway: GatewayInfo): Promise<string>; | ||
export declare function generateProof(censusId: string, claim: string, gateway: DVoteGateway): Promise<void>; | ||
export declare function checkProof(): void; | ||
export declare function dump(): void; | ||
export declare function dumpPlain(): void; | ||
export declare function importDump(): void; |
@@ -11,28 +11,163 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
function addCensus(censusId, pubKeys, gateway, walletOrSigner) { | ||
if (!censusId || !pubKeys || !pubKeys.length || !gateway) | ||
throw new Error("Invalid parameters"); | ||
return gateway.sendMessage({ method: "addCensus", censusId, pubKeys }, walletOrSigner); | ||
const js_sha3_1 = require("js-sha3"); | ||
// import GatewayInfo from "../wrappers/gateway-info" | ||
/** | ||
* A census ID consists of the Entity ID and the hash of the name. | ||
* This function returns the full Census ID | ||
*/ | ||
function generateCensusId(censusName, entityId) { | ||
return entityId + "/" + generateCensusIdSuffix(censusName); | ||
} | ||
exports.generateCensusId = generateCensusId; | ||
/** | ||
* A census ID consists of the Entity ID and the hash of the name. | ||
* This function computes the second term | ||
*/ | ||
function generateCensusIdSuffix(censusName) { | ||
// A census ID consists of the Entity ID and the hash of the name | ||
// Now computing the second term | ||
return "0x" + js_sha3_1.sha3_256(censusName.toLowerCase().trim()); | ||
} | ||
exports.generateCensusIdSuffix = generateCensusIdSuffix; | ||
/** | ||
* Asks the Gateway to create a new census and set the given public key as the ones who can manage it | ||
* @param censusName Name given to the census. Will be used to generate the census ID by trimming spaces and converting text to lowercase | ||
* @param managerPublicKeys ECDSA public key(s) that can manage this census | ||
* @param gateway A DVoteGateway instance connected to a remote Gateway | ||
* @param walletOrSigner | ||
* @returns Promise resolving with the new merkleRoot | ||
*/ | ||
function addCensus(censusName, managerPublicKeys, entityId, gateway, walletOrSigner) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
if (!censusName || !managerPublicKeys || !managerPublicKeys.length || !entityId || !gateway) | ||
throw new Error("Invalid parameters"); | ||
const censusId = generateCensusId(censusName, entityId); | ||
// Check if the census already exists | ||
let existingRoot; | ||
try { | ||
// TODO: normalize the `censusId` parameter value | ||
// Pass the full censusId instead of the second term only | ||
existingRoot = yield getRoot(censusId, gateway); | ||
if (typeof existingRoot == "string" && existingRoot.match(/^0x[0-9a-zA-Z]+$/)) | ||
return { censusId, merkleRoot: existingRoot }; | ||
} | ||
catch (err) { | ||
// console.error(err) | ||
// If it errors because it doesn't exist, we continue below | ||
} | ||
// TODO: normalize the `censusId` parameter value | ||
// Pass the full censusId instead of the second term only | ||
const censusIdLastTerm = generateCensusIdSuffix(censusName); | ||
const response = yield gateway.sendMessage({ method: "addCensus", censusId: censusIdLastTerm, pubKeys: managerPublicKeys }, walletOrSigner); | ||
if (!response.ok) | ||
throw new Error("The census could not be created"); | ||
const merkleRoot = yield getRoot(censusId, gateway); | ||
return { censusId, merkleRoot }; | ||
}); | ||
} | ||
exports.addCensus = addCensus; | ||
function addClaim() { | ||
throw new Error("TODO: Unimplemented"); | ||
/** | ||
* Asks the Gateway to add the given public key hashe to a census previously registered on it | ||
* @param censusId Full Census ID containing the Entity ID and the hash of the original name | ||
* @param pubKeyHash SHA3-256 array generated from a users' public key | ||
* @param gateway A DVoteGateway instance already connected to a remote Gateway | ||
* @param walletOrSigner | ||
* @returns Promise resolving with the new merkleRoot | ||
*/ | ||
function addClaim(censusId, pubKeyHash, gateway, walletOrSigner) { | ||
if (!censusId || !pubKeyHash || !pubKeyHash.length || !gateway) | ||
throw new Error("Invalid parameters"); | ||
// TODO: Normalize the behavior of the Census ID passed to the Gateway | ||
const censusIdLastTerm = censusId.replace(/^0x[0-9a-zA-Z]+/, ""); | ||
return gateway.sendMessage({ method: "addClaim", censusIdLastTerm, claimData: pubKeyHash }, walletOrSigner).then(response => { | ||
if (!response.ok) | ||
throw new Error("The claim could not be added"); | ||
return getRoot(censusId, gateway); | ||
}); | ||
} | ||
exports.addClaim = addClaim; | ||
function addClaimBulk() { | ||
throw new Error("TODO: Unimplemented"); | ||
/** | ||
* Asks the Gateway to add the given public key hashes to a census previously registered on it | ||
* @param censusId Full Census ID containing the Entity ID and the hash of the original name | ||
* @param pubKeyHashes SHA3-256 array generated from the users' public keys | ||
* @param gateway A DVoteGateway instance already connected to a remote Gateway | ||
* @param walletOrSigner | ||
* @returns Promise resolving with the new merkleRoot | ||
*/ | ||
function addClaimBulk(censusId, pubKeyHashes, gateway, walletOrSigner) { | ||
if (!censusId || !pubKeyHashes || !pubKeyHashes.length || !gateway) | ||
throw new Error("Invalid parameters"); | ||
// TODO: Normalize the behavior of the Census ID passed to the Gateway | ||
const censusIdLastTerm = censusId.replace(/^0x[0-9a-zA-Z]+/, ""); | ||
return gateway.sendMessage({ method: "addClaimBulk", censusIdLastTerm, claimsData: pubKeyHashes }, walletOrSigner).then(response => { | ||
if (!response.ok) | ||
throw new Error("The claims could not be added"); | ||
return getRoot(censusId, gateway); | ||
}); | ||
} | ||
exports.addClaimBulk = addClaimBulk; | ||
function getRoot() { | ||
/** | ||
* Asks the Gateway to fetch | ||
* @param censusId The full Census ID to fetch from the Gateway | ||
* @param gateway A DVoteGateway instance already connected to a remote Gateway | ||
* @returns Promise resolving with the merkleRoot | ||
*/ | ||
function getRoot(censusId, gateway) { | ||
if (!censusId || !gateway) | ||
throw new Error("Invalid parameters"); | ||
// TODO: Normalize the behavior of the Census ID passed to the Gateway | ||
const censusIdLastTerm = censusId.replace(/^0x[0-9a-zA-Z]+/, ""); | ||
return gateway.sendMessage({ method: "getRoot", censusId: censusIdLastTerm }).then(response => { | ||
if (!response.root) | ||
throw new Error("The census merkle root could not be fetched"); | ||
return response.root; | ||
}); | ||
} | ||
exports.getRoot = getRoot; | ||
/** Dumps the entire content of the census as an array of hexStrings rady to be imported to another census service */ | ||
function dump() { | ||
throw new Error("TODO: Unimplemented"); | ||
} | ||
exports.getRoot = getRoot; | ||
exports.dump = dump; | ||
/** Dumps the contents of a census in raw string format. Not valid to use with `importDump` */ | ||
function dumpPlain() { | ||
throw new Error("TODO: Unimplemented"); | ||
} | ||
exports.dumpPlain = dumpPlain; | ||
/** Only works with specific merkletree format used by dump method. To add a list of plain claims use `addClaimBulk` instead */ | ||
function importDump() { | ||
throw new Error("TODO: Unimplemented"); | ||
} | ||
exports.importDump = importDump; | ||
/** Import a previously published remote census. Only valid URIs accepted */ | ||
function importRemote() { | ||
throw new Error("TODO: Unimplemented"); | ||
} | ||
exports.importRemote = importRemote; | ||
/** Exports and publish the entire census on the storage of the backend (usually IPFS). Returns the URI of the set of claims */ | ||
function publishCensus(censusId, gateway) { | ||
if (!censusId || !gateway) | ||
throw new Error("Invalid parameters"); | ||
// TODO: Normalize the behavior of the Census ID passed to the Gateway | ||
const censusIdLastTerm = censusId.replace(/^0x[0-9a-zA-Z]+/, ""); | ||
return gateway.sendMessage({ method: "publish", censusId: censusIdLastTerm }).then(response => { | ||
if (!response.uri) | ||
throw new Error("The census claim URI could not be retrieved"); | ||
return response.uri; | ||
}); | ||
} | ||
exports.publishCensus = publishCensus; | ||
/** | ||
* Fetch the proof of the given index on the process census using the given gateway | ||
* @param processId | ||
* @param keyPath | ||
* @param claim | ||
* @param gateway | ||
*/ | ||
function generateProof(processId, keyPath, gateway) { | ||
function generateProof(censusId, claim, gateway) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
// if (!censusId || !claim || !gateway) throw new Error("Invalid parameters") | ||
// return gateway.sendMessage({ method: "addClaim", censusId, claimData: pubKeyHash }, walletOrSigner).then(response => { | ||
// if (!response.ok) throw new Error("The claim could not be added") | ||
// return getRoot(censusId, gateway) | ||
// }) | ||
// const metadata = await getVoteMetadata(processId, gateway.web3) | ||
@@ -50,14 +185,2 @@ // TODO: Use the CensusService Object | ||
exports.checkProof = checkProof; | ||
function dump() { | ||
throw new Error("TODO: Unimplemented"); | ||
} | ||
exports.dump = dump; | ||
function dumpPlain() { | ||
throw new Error("TODO: Unimplemented"); | ||
} | ||
exports.dumpPlain = dumpPlain; | ||
function importDump() { | ||
throw new Error("TODO: Unimplemented"); | ||
} | ||
exports.importDump = importDump; | ||
//# sourceMappingURL=census.js.map |
export declare type DVoteSupportedApi = "file" | "vote" | "census"; | ||
export declare type FileApiMethod = "fetchFile" | "addFile" | "pinList" | "pinFile" | "unpinFile"; | ||
export declare type VoteApiMethod = "submitEnvelope" | "getEnvelopeStatus" | "getEnvelope" | "getEnvelopeHeight" | "getProcessList" | "getEnvelopeList"; | ||
export declare type CensusApiMethod = "addCensus" | "addClaim" | "addClaimBulk" | "getRoot" | "generateProof" | "checkProof" | "dump" | "dumpPlain" | "importDump"; | ||
export declare type CensusApiMethod = "addCensus" | "addClaim" | "addClaimBulk" | "getRoot" | "generateProof" | "checkProof" | "dump" | "dumpPlain" | "importDump" | "publish" | "importRemote"; | ||
export declare type WsGatewayMethod = FileApiMethod | VoteApiMethod | CensusApiMethod; | ||
@@ -6,0 +6,0 @@ export declare const fileApiMethods: FileApiMethod[]; |
@@ -5,7 +5,9 @@ const axios = require("axios") | ||
require('dotenv').config() | ||
const { sha3_256 } = require('js-sha3') | ||
const { | ||
API: { File, Entity, Census, Vote }, | ||
Network: { Contracts, Gateway }, | ||
Wrappers: { GatewayInfo, ContentURI, ContentHashedURI }, | ||
Wrappers: { GatewayInfo, ContentURI, ContentHashedURI, publishCensus, importRemote }, | ||
EtherUtils: { Providers, Signers } | ||
@@ -22,2 +24,3 @@ } = require("../dist") // require("dvote-js") | ||
const { getEntityId, getEntityMetadata, updateEntity } = Entity | ||
const { getRoot, addCensus, addClaim, addClaimBulk } = Census | ||
const { DVoteGateway, Web3Gateway, getDefaultGateways, getRandomGatewayInfo } = Gateway | ||
@@ -310,2 +313,47 @@ const { addFile, fetchFileString } = File | ||
async function ensResolver() { | ||
// const provider = new providers.EtherscanProvider() | ||
const provider = new providers.JsonRpcProvider(GATEWAY_WEB3_URI) | ||
const resolverAddr = await provider.resolveName("entity-resolver.vocdoni.eth") | ||
const processAddr = await provider.resolveName("voting-process.vocdoni.eth") | ||
console.log("Entity Resolver contract address", resolverAddr) | ||
console.log("Voting Process contract address", processAddr) | ||
} | ||
async function gwCensusOperations() { | ||
// SIGNED | ||
const wallet = Wallet.fromMnemonic(MNEMONIC, PATH) | ||
const myEntityAddress = await wallet.getAddress() | ||
const myEntityId = getEntityId(myEntityAddress) | ||
gw = new DVoteGateway({ uri: GATEWAY_DVOTE_URI, supportedApis: ["file", "census"], publicKey: GATEWAY_PUB_KEY }) | ||
console.log("THE DVOTE GW:", gw.publicKey) | ||
await gw.connect() | ||
const censusName = "My census name 2" | ||
const adminPublicKeys = [await wallet.signingKey.publicKey] | ||
const pubKeyHashes = ["0x12345678", "0x23456789"].map(v => sha3_256(v)) | ||
// Create a census if it doesn't exist | ||
let result = await addCensus(censusName, adminPublicKeys, myEntityId, gw, wallet) | ||
console.log("ADD CENSUS RESULT:", result) | ||
// { censusId: "0x.../0x...", merkleRoot: "0x0..."} | ||
// Add claims to the new census | ||
const censusId = result.censusId | ||
result = await addClaimBulk(censusId, pubKeyHashes, gw, wallet) | ||
console.log("ADDED", pubKeyHashes, "TO", censusId) | ||
console.log(result) | ||
result = await publishCensus(censusId, gw) | ||
console.log("PUBLISHED", censusId) | ||
console.log(result) | ||
gw.disconnect() | ||
} | ||
async function main() { | ||
@@ -323,3 +371,5 @@ // await deployEntityResolver() | ||
// await gatewayHealthCheck() | ||
await gatewayRequest() | ||
// await gatewayRequest() | ||
// await ensResolver() | ||
await gwCensusOperations() | ||
} | ||
@@ -326,0 +376,0 @@ |
{ | ||
"name": "dvote-js", | ||
"version": "0.10.4", | ||
"version": "0.10.5", | ||
"description": "Javascript/Typescript library to interact with Vocdoni voting processes", | ||
@@ -5,0 +5,0 @@ "main": "dist/index", |
import { Wallet, Signer } from "ethers" | ||
import { DVoteGateway } from "../net/gateway" | ||
import GatewayInfo from "../wrappers/gateway-info" | ||
import { sha3_256 } from 'js-sha3' | ||
// import GatewayInfo from "../wrappers/gateway-info" | ||
export function addCensus(censusId: string, pubKeys: string[], gateway: DVoteGateway, walletOrSigner: Wallet | Signer): Promise<any> { | ||
if (!censusId || !pubKeys || !pubKeys.length || !gateway) throw new Error("Invalid parameters") | ||
/** | ||
* A census ID consists of the Entity ID and the hash of the name. | ||
* This function returns the full Census ID | ||
*/ | ||
export function generateCensusId(censusName: string, entityId: string) { | ||
return entityId + "/" + generateCensusIdSuffix(censusName) | ||
} | ||
return gateway.sendMessage({ method: "addCensus", censusId, pubKeys }, walletOrSigner) | ||
/** | ||
* A census ID consists of the Entity ID and the hash of the name. | ||
* This function computes the second term | ||
*/ | ||
export function generateCensusIdSuffix(censusName: string) { | ||
// A census ID consists of the Entity ID and the hash of the name | ||
// Now computing the second term | ||
return "0x" + sha3_256(censusName.toLowerCase().trim()) | ||
} | ||
export function addClaim() { | ||
/** | ||
* Asks the Gateway to create a new census and set the given public key as the ones who can manage it | ||
* @param censusName Name given to the census. Will be used to generate the census ID by trimming spaces and converting text to lowercase | ||
* @param managerPublicKeys ECDSA public key(s) that can manage this census | ||
* @param gateway A DVoteGateway instance connected to a remote Gateway | ||
* @param walletOrSigner | ||
* @returns Promise resolving with the new merkleRoot | ||
*/ | ||
export async function addCensus(censusName: string, managerPublicKeys: string[], entityId: string, gateway: DVoteGateway, walletOrSigner: Wallet | Signer): Promise<{ censusId: string, merkleRoot: string }> { | ||
if (!censusName || !managerPublicKeys || !managerPublicKeys.length || !entityId || !gateway) throw new Error("Invalid parameters") | ||
const censusId = generateCensusId(censusName, entityId) | ||
// Check if the census already exists | ||
let existingRoot | ||
try { | ||
// TODO: normalize the `censusId` parameter value | ||
// Pass the full censusId instead of the second term only | ||
existingRoot = await getRoot(censusId, gateway) | ||
if (typeof existingRoot == "string" && existingRoot.match(/^0x[0-9a-zA-Z]+$/)) return { censusId, merkleRoot: existingRoot } | ||
} catch (err) { | ||
// console.error(err) | ||
// If it errors because it doesn't exist, we continue below | ||
} | ||
// TODO: normalize the `censusId` parameter value | ||
// Pass the full censusId instead of the second term only | ||
const censusIdLastTerm = generateCensusIdSuffix(censusName) | ||
const response = await gateway.sendMessage({ method: "addCensus", censusId: censusIdLastTerm, pubKeys: managerPublicKeys }, walletOrSigner) | ||
if (!response.ok) throw new Error("The census could not be created") | ||
const merkleRoot = await getRoot(censusId, gateway) | ||
return { censusId, merkleRoot } | ||
} | ||
/** | ||
* Asks the Gateway to add the given public key hashe to a census previously registered on it | ||
* @param censusId Full Census ID containing the Entity ID and the hash of the original name | ||
* @param pubKeyHash SHA3-256 array generated from a users' public key | ||
* @param gateway A DVoteGateway instance already connected to a remote Gateway | ||
* @param walletOrSigner | ||
* @returns Promise resolving with the new merkleRoot | ||
*/ | ||
export function addClaim(censusId: string, pubKeyHash: string, gateway: DVoteGateway, walletOrSigner: Wallet | Signer): Promise<string> { | ||
if (!censusId || !pubKeyHash || !pubKeyHash.length || !gateway) throw new Error("Invalid parameters") | ||
// TODO: Normalize the behavior of the Census ID passed to the Gateway | ||
const censusIdLastTerm = censusId.replace(/^0x[0-9a-zA-Z]+/, "") | ||
return gateway.sendMessage({ method: "addClaim", censusIdLastTerm, claimData: pubKeyHash }, walletOrSigner).then(response => { | ||
if (!response.ok) throw new Error("The claim could not be added") | ||
return getRoot(censusId, gateway) | ||
}) | ||
} | ||
/** | ||
* Asks the Gateway to add the given public key hashes to a census previously registered on it | ||
* @param censusId Full Census ID containing the Entity ID and the hash of the original name | ||
* @param pubKeyHashes SHA3-256 array generated from the users' public keys | ||
* @param gateway A DVoteGateway instance already connected to a remote Gateway | ||
* @param walletOrSigner | ||
* @returns Promise resolving with the new merkleRoot | ||
*/ | ||
export function addClaimBulk(censusId: string, pubKeyHashes: string[], gateway: DVoteGateway, walletOrSigner: Wallet | Signer): Promise<string> { | ||
if (!censusId || !pubKeyHashes || !pubKeyHashes.length || !gateway) throw new Error("Invalid parameters") | ||
// TODO: Normalize the behavior of the Census ID passed to the Gateway | ||
const censusIdLastTerm = censusId.replace(/^0x[0-9a-zA-Z]+/, "") | ||
return gateway.sendMessage({ method: "addClaimBulk", censusIdLastTerm, claimsData: pubKeyHashes }, walletOrSigner).then(response => { | ||
if (!response.ok) throw new Error("The claims could not be added") | ||
return getRoot(censusId, gateway) | ||
}) | ||
} | ||
/** | ||
* Asks the Gateway to fetch | ||
* @param censusId The full Census ID to fetch from the Gateway | ||
* @param gateway A DVoteGateway instance already connected to a remote Gateway | ||
* @returns Promise resolving with the merkleRoot | ||
*/ | ||
export function getRoot(censusId: string, gateway: DVoteGateway): Promise<string> { | ||
if (!censusId || !gateway) throw new Error("Invalid parameters") | ||
// TODO: Normalize the behavior of the Census ID passed to the Gateway | ||
const censusIdLastTerm = censusId.replace(/^0x[0-9a-zA-Z]+/, "") | ||
return gateway.sendMessage({ method: "getRoot", censusId: censusIdLastTerm }).then(response => { | ||
if (!response.root) throw new Error("The census merkle root could not be fetched") | ||
return response.root | ||
}) | ||
} | ||
/** Dumps the entire content of the census as an array of hexStrings rady to be imported to another census service */ | ||
export function dump() { | ||
throw new Error("TODO: Unimplemented") | ||
} | ||
export function addClaimBulk() { | ||
/** Dumps the contents of a census in raw string format. Not valid to use with `importDump` */ | ||
export function dumpPlain() { | ||
throw new Error("TODO: Unimplemented") | ||
} | ||
export function getRoot() { | ||
/** Only works with specific merkletree format used by dump method. To add a list of plain claims use `addClaimBulk` instead */ | ||
export function importDump() { | ||
throw new Error("TODO: Unimplemented") | ||
} | ||
/** Import a previously published remote census. Only valid URIs accepted */ | ||
export function importRemote() { | ||
throw new Error("TODO: Unimplemented") | ||
} | ||
/** Exports and publish the entire census on the storage of the backend (usually IPFS). Returns the URI of the set of claims */ | ||
export function publishCensus(censusId: string, gateway: DVoteGateway): Promise<string> { | ||
if (!censusId || !gateway) throw new Error("Invalid parameters") | ||
// TODO: Normalize the behavior of the Census ID passed to the Gateway | ||
const censusIdLastTerm = censusId.replace(/^0x[0-9a-zA-Z]+/, "") | ||
return gateway.sendMessage({ method: "publish", censusId: censusIdLastTerm }).then(response => { | ||
if (!response.uri) throw new Error("The census claim URI could not be retrieved") | ||
return response.uri | ||
}) | ||
} | ||
/** | ||
* Fetch the proof of the given index on the process census using the given gateway | ||
* @param processId | ||
* @param keyPath | ||
* @param claim | ||
* @param gateway | ||
*/ | ||
export async function generateProof(processId: string, keyPath: string, gateway: GatewayInfo): Promise<string> { | ||
export async function generateProof(censusId: string, claim: string, gateway: DVoteGateway) { | ||
// if (!censusId || !claim || !gateway) throw new Error("Invalid parameters") | ||
// return gateway.sendMessage({ method: "addClaim", censusId, claimData: pubKeyHash }, walletOrSigner).then(response => { | ||
// if (!response.ok) throw new Error("The claim could not be added") | ||
// return getRoot(censusId, gateway) | ||
// }) | ||
// const metadata = await getVoteMetadata(processId, gateway.web3) | ||
@@ -43,13 +182,1 @@ | ||
} | ||
export function dump() { | ||
throw new Error("TODO: Unimplemented") | ||
} | ||
export function dumpPlain() { | ||
throw new Error("TODO: Unimplemented") | ||
} | ||
export function importDump() { | ||
throw new Error("TODO: Unimplemented") | ||
} |
@@ -5,3 +5,3 @@ export type DVoteSupportedApi = "file" | "vote" | "census" | ||
export type VoteApiMethod = "submitEnvelope" | "getEnvelopeStatus" | "getEnvelope" | "getEnvelopeHeight" | "getProcessList" | "getEnvelopeList" | ||
export type CensusApiMethod = "addCensus" | "addClaim" | "addClaimBulk" | "getRoot" | "generateProof" | "checkProof" | "dump" | "dumpPlain" | "importDump" | ||
export type CensusApiMethod = "addCensus" | "addClaim" | "addClaimBulk" | "getRoot" | "generateProof" | "checkProof" | "dump" | "dumpPlain" | "importDump" | "publish" | "importRemote" | ||
export type WsGatewayMethod = FileApiMethod | VoteApiMethod | CensusApiMethod | ||
@@ -8,0 +8,0 @@ |
Sorry, the diff of this file is not supported yet
395151
6316
102