New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

dvote-js

Package Overview
Dependencies
Maintainers
1
Versions
247
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

dvote-js - npm Package Compare versions

Comparing version 0.10.6 to 0.10.7

dist/net/gateway-bootnodes.d.ts

2

dist/index.d.ts

@@ -6,2 +6,3 @@ import * as File from "./api/file";

import * as Gateway from "./net/gateway";
import * as Bootnodes from "./net/gateway-bootnodes";
import * as Contracts from "./net/contracts";

@@ -28,2 +29,3 @@ import { default as ContentURI } from "./wrappers/content-uri";

export declare const Network: {
Bootnodes: typeof Bootnodes;
Gateway: typeof Gateway;

@@ -30,0 +32,0 @@ Contracts: typeof Contracts;

3

dist/index.js

@@ -10,2 +10,3 @@ "use strict";

const Gateway = require("./net/gateway");
const Bootnodes = require("./net/gateway-bootnodes");
const Contracts = require("./net/contracts");

@@ -26,5 +27,5 @@ // WRAPPERS

exports.Models = { Entity: EntityModel, Vote: VotingProcessModel, Gateway: GatewayModel };
exports.Network = { Gateway, Contracts };
exports.Network = { Bootnodes, Gateway, Contracts };
exports.Wrappers = { ContentURI: content_uri_1.default, ContentHashedURI: content_hashed_uri_1.default, GatewayInfo: gateway_info_1.default };
exports.EtherUtils = { Providers, Signers };
//# sourceMappingURL=index.js.map
import { Contract, providers, utils, Wallet, Signer } from "ethers";
import ContentURI from "../wrappers/content-uri";
import GatewayInfo from "../wrappers/gateway-info";
import { GatewayBootNodes, DVoteSupportedApi, WsGatewayMethod } from "../models/gateway";
/**
* Retrieve a list of gateways provided by default by Vocdoni.
* The resulting set of `dvote[]` objects may need that you call `connect()` before you use them.
*/
export declare function getDefaultGateways(): Promise<{
[networkId: string]: {
dvote: DVoteGateway[];
web3: Web3Gateway[];
};
}>;
/**
* Retrieve the list of gateways for a given BootNode(s) Content URI.
* The resulting set of `dvote[]` objects may need that you call `connect()` before you use them.
*/
export declare function getGatewaysFromBootNode(bootnodesContentUri: string | ContentURI): Promise<{
[networkId: string]: {
dvote: DVoteGateway[];
web3: Web3Gateway[];
};
}>;
/**
* Retrieve the parameters of a randomly chosen DVote and Web3 gateway.
* If no parameter is provided, the default gateways provided by Vocdoni will be used as the source.
* If a Content URI is provided, the choice will be made from its data.
*/
export declare function getRandomGatewayInfo(bootnodesContentUri?: string | ContentURI): Promise<{
[networkId: string]: GatewayInfo;
}>;
/**
* Retrieve the list of gateways provided by default by Vocdoni
*/
export declare function fetchDefaultBootNode(): Promise<GatewayBootNodes>;
/**
* Retrieve the list of gateways for a given BootNode(s) Content URI
*/
export declare function fetchFromBootNode(bootnodesContentUri: string | ContentURI): Promise<GatewayBootNodes>;
/**
* Retrieve a list of curently active gateways for the given entityAddress
*/
export declare function getActiveEntityGateways(entityAddress: string): Promise<GatewayInfo[]>;
import { DVoteSupportedApi, WsGatewayMethod } from "../models/gateway";
/** Parameters sent by the function caller */

@@ -46,0 +5,0 @@ export interface DvoteRequestParameters {

@@ -20,104 +20,5 @@ "use strict";

const gateway_info_1 = require("../wrappers/gateway-info");
const file_1 = require("../api/file");
const constants_1 = require("../constants");
const gateway_1 = require("../models/gateway");
const uriPattern = /^([a-z][a-z0-9+.-]+):(\/\/([^@]+@)?([a-z0-9.\-_~]+)(:\d+)?)?((?:[a-z0-9-._~]|%[a-f0-9]|[!$&'()*+,;=:@])+(?:\/(?:[a-z0-9-._~]|%[a-f0-9]|[!$&'()*+,;=:@])*)*|(?:\/(?:[a-z0-9-._~]|%[a-f0-9]|[!$&'()*+,;=:@])+)*)?(\?(?:[a-z0-9-._~]|%[a-f0-9]|[!$&'()*+,;=:@]|[/?])+)?(\#(?:[a-z0-9-._~]|%[a-f0-9]|[!$&'()*+,;=:@]|[/?])+)?$/i;
///////////////////////////////////////////////////////////////////////////////
// GLOBAL FUNCTIONS
///////////////////////////////////////////////////////////////////////////////
/**
* Retrieve a list of gateways provided by default by Vocdoni.
* The resulting set of `dvote[]` objects may need that you call `connect()` before you use them.
*/
function getDefaultGateways() {
return getGatewaysFromBootNode(constants_1.defaultBootnodeContentUri);
}
exports.getDefaultGateways = getDefaultGateways;
/**
* Retrieve the list of gateways for a given BootNode(s) Content URI.
* The resulting set of `dvote[]` objects may need that you call `connect()` before you use them.
*/
function getGatewaysFromBootNode(bootnodesContentUri) {
if (!bootnodesContentUri)
throw new Error("Invalid Content URI");
return fetchFromBootNode(bootnodesContentUri).then(data => {
const result = {};
Object.keys(data).forEach(networkId => {
result[networkId] = {
dvote: (data[networkId].dvote || []).map(item => {
return new DVoteGateway({ uri: item.uri, supportedApis: item.apis, publicKey: item.pubKey });
}),
web3: (data[networkId].web3 || []).map(item => {
return new Web3Gateway(item.uri);
})
};
});
return result;
}).catch(err => {
throw new Error(err && err.message || "Unable to fetch the boot node(s) data");
});
}
exports.getGatewaysFromBootNode = getGatewaysFromBootNode;
/**
* Retrieve the parameters of a randomly chosen DVote and Web3 gateway.
* If no parameter is provided, the default gateways provided by Vocdoni will be used as the source.
* If a Content URI is provided, the choice will be made from its data.
*/
function getRandomGatewayInfo(bootnodesContentUri) {
return __awaiter(this, void 0, void 0, function* () {
const result = {};
const gws = bootnodesContentUri ? yield fetchFromBootNode(bootnodesContentUri) : yield fetchDefaultBootNode();
for (let networkId in gws) {
const dvLen = gws && gws[networkId] && gws[networkId].dvote
&& gws[networkId].dvote.length || 0;
if (!dvLen)
throw new Error("Could not fetch the Entity metadata");
const w3Len = gws && gws[networkId] && gws[networkId].web3
&& gws[networkId].web3.length || 0;
if (!w3Len)
throw new Error("Could not fetch the Entity metadata");
const dvGw = gws[networkId].dvote[Math.floor(Math.random() * dvLen)];
const w3Gw = gws[networkId].web3[Math.floor(Math.random() * w3Len)];
result[networkId] = new gateway_info_1.default(dvGw.uri, dvGw.apis, w3Gw.uri, dvGw.pubKey);
}
return result;
});
}
exports.getRandomGatewayInfo = getRandomGatewayInfo;
/**
* Retrieve the list of gateways provided by default by Vocdoni
*/
function fetchDefaultBootNode() {
return file_1.fetchFileString(constants_1.defaultBootnodeContentUri).then(strResult => {
const result = JSON.parse(strResult);
return result;
}).catch(err => {
throw new Error(err && err.message || "Unable to fetch the boot node(s) data");
});
}
exports.fetchDefaultBootNode = fetchDefaultBootNode;
/**
* Retrieve the list of gateways for a given BootNode(s) Content URI
*/
function fetchFromBootNode(bootnodesContentUri) {
if (!bootnodesContentUri)
throw new Error("Invalid bootNodeUri");
return file_1.fetchFileString(bootnodesContentUri).then(strResult => {
const result = JSON.parse(strResult);
return result;
}).catch(err => {
throw new Error(err && err.message || "Unable to fetch the boot node(s) data");
});
}
exports.fetchFromBootNode = fetchFromBootNode;
/**
* Retrieve a list of curently active gateways for the given entityAddress
*/
function getActiveEntityGateways(entityAddress) {
return __awaiter(this, void 0, void 0, function* () {
throw new Error("TODO: unimplemented"); // TODO: getActiveEntityGateways()
});
}
exports.getActiveEntityGateways = getActiveEntityGateways;
/**
* This class provides access to Vocdoni Gateways sending JSON payloads over Web Sockets

@@ -124,0 +25,0 @@ * intended to interact within voting processes

@@ -10,3 +10,3 @@ const axios = require("axios")

API: { File, Entity, Census, Vote },
Network: { Contracts, Gateway },
Network: { Bootnodes, Gateway, Contracts },
Wrappers: { GatewayInfo, ContentURI, ContentHashedURI },

@@ -25,3 +25,4 @@ EtherUtils: { Providers, Signers }

const { getRoot, addCensus, addClaim, addClaimBulk, generateCensusId, generateCensusIdSuffix, publishCensus, importRemote } = Census
const { DVoteGateway, Web3Gateway, getDefaultGateways, getRandomGatewayInfo } = Gateway
const { DVoteGateway, Web3Gateway } = Gateway
const { getDefaultGateways, getRandomGatewayInfo } = Bootnodes
const { addFile, fetchFileString } = File

@@ -344,2 +345,7 @@

// // Add a claim to the new census
// const censusId = result.censusId
// result = await addClaim(censusId, pubKeyHashes[0], gw, wallet)
// console.log("ADDED", pubKeyHashes[0], "TO", censusId)
// Add claims to the new census

@@ -346,0 +352,0 @@ const censusId = result.censusId

{
"name": "dvote-js",
"version": "0.10.6",
"version": "0.10.7",
"description": "Javascript/Typescript library to interact with Vocdoni voting processes",

@@ -5,0 +5,0 @@ "main": "dist/index",

@@ -64,3 +64,3 @@ # DVote JS

API: { File, Entity, Census, Vote },
// Network: { Contracts, Gateway },
Network: { Bootnodes, Gateway, Contracts },
Wrappers: { GatewayInfo, ContentURI, ContentHashedURI },

@@ -77,11 +77,13 @@ // EtherUtils: { Providers, Signers }

const { getEntityId, getEntityMetadata, updateEntity } = Entity
const { DVoteGateway, Web3Gateway } = Gateway
const { getRandomGatewayInfo } = Bootnodes
const { Wallet, providers } = require("ethers")
const GATEWAY_DVOTE_URI = "wss://host:443/dvote"
const GATEWAY_SUPPORTED_APIS = ["file", "vote", "census"]
const GATEWAY_WEB3_PROVIDER_URI = "https://rpc.slock.it/goerli"
const MNEMONIC = "..."
const provider = new providers.JsonRpcProvider(GATEWAY_WEB3_PROVIDER_URI)
// Use a random GW from Vocdoni
const gws = await getRandomGatewayInfo()
const gw = new DVoteGateway(gws["goerli"])
const provider = new Web3Gateway(gws["goerli"]).getProvider()
const wallet = Wallet.fromMnemonic(MNEMONIC, PATH)

@@ -96,7 +98,4 @@

// Define the info of the Gateway
const gw = new GatewayInfo(GATEWAY_DVOTE_URI, GATEWAY_SUPPORTED_APIS, GATEWAY_ETH_PROVIDER_URI, GATEWAY_PUBLIC_KEY)
// Request the update
const contentUri = await updateEntity(myEntityAddress, resolverContractAddress, jsonMetadata, wallet, gw)
const contentUri = await updateEntity(myEntityAddress, jsonMetadata, wallet, gw)

@@ -111,3 +110,3 @@ console.log("IPFS ORIGIN:", contentUri)

API: { File, Entity, Census, Vote },
// Network: { Contracts, Gateway },
Network: { Bootnodes, Gateway, Contracts },
Wrappers: { GatewayInfo, ContentURI, ContentHashedURI },

@@ -131,3 +130,2 @@ // EtherUtils: { Providers, Signers }

const GATEWAY_WEB3_PROVIDER_URI = "https://rpc.slock.it/goerli"
const resolverContractAddress = "0x9fa513Df94fF9EAE4b63669F187928d20bd7cE6F"
const MNEMONIC = "..."

@@ -141,3 +139,3 @@

const meta = await getEntityMetadata(myEntityAddress, resolverContractAddress, gw)
const meta = await getEntityMetadata(myEntityAddress, gw)
console.log("JSON METADATA", meta)

@@ -151,3 +149,3 @@ ```

API: { File, Entity, Census, Vote },
// Network: { Contracts, Gateway },
Network: { Bootnodes, Gateway, Contracts },
Wrappers: { GatewayInfo, ContentURI, ContentHashedURI },

@@ -154,0 +152,0 @@ // EtherUtils: { Providers, Signers }

@@ -9,2 +9,3 @@ // API

import * as Gateway from "./net/gateway"
import * as Bootnodes from "./net/gateway-bootnodes"
import * as Contracts from "./net/contracts"

@@ -30,3 +31,3 @@

export const Models = { Entity: EntityModel, Vote: VotingProcessModel, Gateway: GatewayModel }
export const Network = { Gateway, Contracts }
export const Network = { Bootnodes, Gateway, Contracts }
export const Wrappers = { ContentURI, ContentHashedURI, GatewayInfo }

@@ -33,0 +34,0 @@ export const EtherUtils = { Providers, Signers }

@@ -9,9 +9,5 @@ // NOTE:

import { Contract, ContractFactory, providers, utils, Wallet, Signer } from "ethers"
import axios from "axios"
import { providerFromUri } from "../util/providers"
import ContentURI from "../wrappers/content-uri"
import GatewayInfo from "../wrappers/gateway-info"
import { fetchFileString } from "../api/file"
import { defaultBootnodeContentUri } from "../constants"
import { GatewayBootNodes, DVoteSupportedApi, WsGatewayMethod, fileApiMethods, voteApiMethods, censusApiMethods } from "../models/gateway"
import { DVoteSupportedApi, WsGatewayMethod, fileApiMethods, voteApiMethods, censusApiMethods } from "../models/gateway"

@@ -21,97 +17,2 @@ const uriPattern = /^([a-z][a-z0-9+.-]+):(\/\/([^@]+@)?([a-z0-9.\-_~]+)(:\d+)?)?((?:[a-z0-9-._~]|%[a-f0-9]|[!$&'()*+,;=:@])+(?:\/(?:[a-z0-9-._~]|%[a-f0-9]|[!$&'()*+,;=:@])*)*|(?:\/(?:[a-z0-9-._~]|%[a-f0-9]|[!$&'()*+,;=:@])+)*)?(\?(?:[a-z0-9-._~]|%[a-f0-9]|[!$&'()*+,;=:@]|[/?])+)?(\#(?:[a-z0-9-._~]|%[a-f0-9]|[!$&'()*+,;=:@]|[/?])+)?$/i

///////////////////////////////////////////////////////////////////////////////
// GLOBAL FUNCTIONS
///////////////////////////////////////////////////////////////////////////////
/**
* Retrieve a list of gateways provided by default by Vocdoni.
* The resulting set of `dvote[]` objects may need that you call `connect()` before you use them.
*/
export function getDefaultGateways(): Promise<{ [networkId: string]: { dvote: DVoteGateway[], web3: Web3Gateway[] } }> {
return getGatewaysFromBootNode(defaultBootnodeContentUri)
}
/**
* Retrieve the list of gateways for a given BootNode(s) Content URI.
* The resulting set of `dvote[]` objects may need that you call `connect()` before you use them.
*/
export function getGatewaysFromBootNode(bootnodesContentUri: string | ContentURI): Promise<{ [networkId: string]: { dvote: DVoteGateway[], web3: Web3Gateway[] } }> {
if (!bootnodesContentUri) throw new Error("Invalid Content URI")
return fetchFromBootNode(bootnodesContentUri).then(data => {
const result: { [networkId: string]: { dvote: DVoteGateway[], web3: Web3Gateway[] } } = {}
Object.keys(data).forEach(networkId => {
result[networkId] = {
dvote: (data[networkId].dvote || []).map(item => {
return new DVoteGateway({ uri: item.uri, supportedApis: item.apis, publicKey: item.pubKey })
}),
web3: (data[networkId].web3 || []).map(item => {
return new Web3Gateway(item.uri)
})
}
})
return result
}).catch(err => {
throw new Error(err && err.message || "Unable to fetch the boot node(s) data")
})
}
/**
* Retrieve the parameters of a randomly chosen DVote and Web3 gateway.
* If no parameter is provided, the default gateways provided by Vocdoni will be used as the source.
* If a Content URI is provided, the choice will be made from its data.
*/
export async function getRandomGatewayInfo(bootnodesContentUri?: string | ContentURI): Promise<{ [networkId: string]: GatewayInfo }> {
const result: { [networkId: string]: GatewayInfo } = {}
const gws = bootnodesContentUri ? await fetchFromBootNode(bootnodesContentUri) : await fetchDefaultBootNode()
for (let networkId in gws) {
const dvLen = gws && gws[networkId] && gws[networkId].dvote
&& gws[networkId].dvote.length || 0
if (!dvLen) throw new Error("Could not fetch the Entity metadata")
const w3Len = gws && gws[networkId] && gws[networkId].web3
&& gws[networkId].web3.length || 0
if (!w3Len) throw new Error("Could not fetch the Entity metadata")
const dvGw = gws[networkId].dvote[Math.floor(Math.random() * dvLen)]
const w3Gw = gws[networkId].web3[Math.floor(Math.random() * w3Len)]
result[networkId] = new GatewayInfo(dvGw.uri, dvGw.apis, w3Gw.uri, dvGw.pubKey)
}
return result
}
/**
* Retrieve the list of gateways provided by default by Vocdoni
*/
export function fetchDefaultBootNode(): Promise<GatewayBootNodes> {
return fetchFileString(defaultBootnodeContentUri).then(strResult => {
const result = JSON.parse(strResult)
return result
}).catch(err => {
throw new Error(err && err.message || "Unable to fetch the boot node(s) data")
})
}
/**
* Retrieve the list of gateways for a given BootNode(s) Content URI
*/
export function fetchFromBootNode(bootnodesContentUri: string | ContentURI): Promise<GatewayBootNodes> {
if (!bootnodesContentUri) throw new Error("Invalid bootNodeUri")
return fetchFileString(bootnodesContentUri).then(strResult => {
const result = JSON.parse(strResult)
return result
}).catch(err => {
throw new Error(err && err.message || "Unable to fetch the boot node(s) data")
})
}
/**
* Retrieve a list of curently active gateways for the given entityAddress
*/
export async function getActiveEntityGateways(entityAddress: string): Promise<GatewayInfo[]> {
throw new Error("TODO: unimplemented") // TODO: getActiveEntityGateways()
}
///////////////////////////////////////////////////////////////////////////////
// DVOTE GATEWAY

@@ -558,2 +459,2 @@ ///////////////////////////////////////////////////////////////////////////////

}, {})
}
}

@@ -6,2 +6,7 @@ import "mocha" // using @types/mocha

const {
DVoteGateway,
Web3Gateway
} = Network.Gateway
const {
getDefaultGateways,

@@ -11,6 +16,4 @@ getGatewaysFromBootNode,

fetchDefaultBootNode,
fetchFromBootNode,
DVoteGateway,
Web3Gateway
} = Network.Gateway
fetchFromBootNode
} = Network.Bootnodes

@@ -17,0 +20,0 @@ const DEFAULT_BOOTNODES_URL = "https://bootnodes.github.io/gateways.json"

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc