Home Reference Source

Function

Static Public Summary
public

checkBallotHashBSpec(rawBallotSpecString: *, expectedSpecHash: *): boolean

Verify a BallotSpec's hash

public

checkBallotHashGBallot(ballotObject: *): *

public

async checkIfAddressIsEditor(objectPattern: {"svNetwork": *}, objectPattern1: {"userAddress": *, "democHash": *}): *

public

This will take an Ethereum hex string (or a normal hex string) and output a normal hex string (no '0x' header) or throw an error on a bad hex string.

public

ethAddrEq(addr1: string, addr2: string): bool

This compares ethereum addresses (taking into account case, etc)

public

ethSignHash(messageHash: *, privateKey: *): {messageHash: string, r: string, s: string, v: string}

Sign a message such that it can be verified with ecrecover.

public

ethVerifySig(messageHash: string, v, r, s: string[]): {verified: bool, address: EthAddress}

Operates ecrecover over the provided signature

public

genRange3VoteData(votesArray: array): string

Prepares voteData for a Range3 ballot from an array of votes

public

async getBackendAddress(objectPattern: {"index": *}): *

public

async getBallotObjectFromIpfs(ballotSpecHash: *): *

public

async getBallotObjectFromS3(archiveUrl: *, ballotSpecHash: *): *

public

async getBallotSpec(archiveUrl: *, ballotSpecHash: *): *

public

async getCommunityBallotPrice(objectPattern: {"payments": *}, democHash: *): *

public

async getContractAddresses(objectPattern: {"svNetwork": *}): {"indexAddress": *, "backendAddress": *, "auxAddress": *, "lookupAddress": *, "resolverAddress": *, "communityAuctionAddress": *, "delegationAddress": *, "paymentsAddress": *}

Takes in the svNetwork object and returns all relevant addresses

public

async getCurrentGasPrice(): {"safeLow": *, "average": *, "fast": *, "fastest": *}

public

async getDemocBallots(objectPattern: {"svNetwork": *, "democHash": *}): *

public

async getDemocInfo(objectPattern: {"backend": *, "democHash": *}): *

public

async getDemocNthBallot(objectPattern: {"svNetwork": *}, democBallotInfo: *): *

public

getNetwork(networkId: *, chainId: *): *

public

hashMsgRaw(data: *): *

Like web3.eth.accounts.hashMessage without the envelope.

public

This will convert a hex string to Base32 in the bech32 format WITHOUT a checksum.

public

async initializeSvLight(svConfig: *): {"svConfig": *, "web3": *, "resolver": *, "index": *, "backend": *, "aux": *, "payments": *}

public

mkPacked(start: number, end: number, submissionBits: number): BN

Creates a packed copy of start and end times with submissionBits

public

mkSignedBallotForProxy(ballotId: string, sequence: number, voteData: string, extra: string, privateKey: string, opts: object): object

Take the arguments and produce web3 data fitting the submitProxyVote method.

public

mkSubmissionBits(toCombine: number[]): number

This combines flags into a finished submissionBits.

public

networkName(networkId: *): string

public

async resolveEnsAddress(objectPattern: {"resolver": *}, ensName: *): *

public

verifySignedBallotForProxy(proxyVote: ProxyVote, opts: *): {verified: bool, address: EthAddress}

Verify a signed vote to be submitted via proxy as generated by mkSignedBallotForProxy

public

async weiToCents(objectPattern: {"payments": *}, wei: *): *

Static Public

public checkBallotHashBSpec(rawBallotSpecString: *, expectedSpecHash: *): boolean source

import {checkBallotHashBSpec} from 'sv-lib/src/light.ts'

Verify a BallotSpec's hash

Params:

NameTypeAttributeDescription
rawBallotSpecString *

The raw string/bytes before JSON.parse

expectedSpecHash *

The expected hash as Eth Hex

Return:

boolean

Whether the ballotSpec matched the expected hash

public checkBallotHashGBallot(ballotObject: *): * source

import {checkBallotHashGBallot} from 'sv-lib/src/light.ts'

Params:

NameTypeAttributeDescription
ballotObject *

Return:

*

public async checkIfAddressIsEditor(objectPattern: {"svNetwork": *}, objectPattern1: {"userAddress": *, "democHash": *}): * source

import {checkIfAddressIsEditor} from 'sv-lib/src/light.ts'

Params:

NameTypeAttributeDescription
objectPattern {"svNetwork": *}
  • default: {"svNetwork":null}
objectPattern1 {"userAddress": *, "democHash": *}
  • default: {"userAddress":null,"democHash":null}

Return:

*

public cleanEthHex(hex: string): string source

import {cleanEthHex} from 'sv-lib/src/utils.ts'

This will take an Ethereum hex string (or a normal hex string) and output a normal hex string (no '0x' header) or throw an error on a bad hex string.

Params:

NameTypeAttributeDescription
hex string

Return:

string

the hex string.

public ethAddrEq(addr1: string, addr2: string): bool source

import {ethAddrEq} from 'sv-lib/src/utils.ts'

This compares ethereum addresses (taking into account case, etc)

Params:

NameTypeAttributeDescription
addr1 string
addr2 string

Return:

bool

public ethSignHash(messageHash: *, privateKey: *): {messageHash: string, r: string, s: string, v: string} source

import {ethSignHash} from 'sv-lib/src/crypto.ts'

Sign a message such that it can be verified with ecrecover. Similar to web3.eth.accounts.sign except that we sign the hash directly.

Params:

NameTypeAttributeDescription
messageHash *

Hash of a message, as returned by web3.utils.soliditySha3 or similar.

privateKey *

Privkey to sign with.

Return:

{messageHash: string, r: string, s: string, v: string}

public ethVerifySig(messageHash: string, v, r, s: string[]): {verified: bool, address: EthAddress} source

import {ethVerifySig} from 'sv-lib/src/crypto.ts'

Operates ecrecover over the provided signature

Params:

NameTypeAttributeDescription
messageHash string

This should be an Ethereum HexString

v, r, s string[]
  • optional

Components for the secp256k1 signature

Return:

{verified: bool, address: EthAddress}

public genRange3VoteData(votesArray: array): string source

import {genRange3VoteData} from 'sv-lib/src/ballotBox.ts'

Prepares voteData for a Range3 ballot from an array of votes

Params:

NameTypeAttributeDescription
votesArray array

Takes an array of numbers which represent the votes to be transformed Format: [1, 2, -1]

Return:

string

Returns an eth hex string of the vote data

public async getBackendAddress(objectPattern: {"index": *}): * source

import {getBackendAddress} from 'sv-lib/src/light.ts'

Params:

NameTypeAttributeDescription
objectPattern {"index": *}
  • default: {"index":null}

Return:

*

public async getBallotObjectFromIpfs(ballotSpecHash: *): * source

import {getBallotObjectFromIpfs} from 'sv-lib/src/light.ts'

Params:

NameTypeAttributeDescription
ballotSpecHash *

Return:

*

public async getBallotObjectFromS3(archiveUrl: *, ballotSpecHash: *): * source

import {getBallotObjectFromS3} from 'sv-lib/src/light.ts'

Params:

NameTypeAttributeDescription
archiveUrl *
ballotSpecHash *

Return:

*

public async getBallotSpec(archiveUrl: *, ballotSpecHash: *): * source

import {getBallotSpec} from 'sv-lib/src/light.ts'

Params:

NameTypeAttributeDescription
archiveUrl *
ballotSpecHash *

Return:

*

public async getCommunityBallotPrice(objectPattern: {"payments": *}, democHash: *): * source

import {getCommunityBallotPrice} from 'sv-lib/src/light.ts'

Params:

NameTypeAttributeDescription
objectPattern {"payments": *}
  • default: {"payments":null}
democHash *

Return:

*

public async getContractAddresses(objectPattern: {"svNetwork": *}): {"indexAddress": *, "backendAddress": *, "auxAddress": *, "lookupAddress": *, "resolverAddress": *, "communityAuctionAddress": *, "delegationAddress": *, "paymentsAddress": *} source

import {getContractAddresses} from 'sv-lib/src/light.ts'

Takes in the svNetwork object and returns all relevant addresses

Params:

NameTypeAttributeDescription
objectPattern {"svNetwork": *}
  • default: {"svNetwork":null}

Return:

{"indexAddress": *, "backendAddress": *, "auxAddress": *, "lookupAddress": *, "resolverAddress": *, "communityAuctionAddress": *, "delegationAddress": *, "paymentsAddress": *}

public async getCurrentGasPrice(): {"safeLow": *, "average": *, "fast": *, "fastest": *} source

import {getCurrentGasPrice} from 'sv-lib/src/light.ts'

Return:

{"safeLow": *, "average": *, "fast": *, "fastest": *}

public async getDemocBallots(objectPattern: {"svNetwork": *, "democHash": *}): * source

import {getDemocBallots} from 'sv-lib/src/light.ts'

Params:

NameTypeAttributeDescription
objectPattern {"svNetwork": *, "democHash": *}
  • default: {"svNetwork":null,"democHash":null}

Return:

*

public async getDemocInfo(objectPattern: {"backend": *, "democHash": *}): * source

import {getDemocInfo} from 'sv-lib/src/light.ts'

Params:

NameTypeAttributeDescription
objectPattern {"backend": *, "democHash": *}
  • default: {"backend":null,"democHash":null}

Return:

*

public async getDemocNthBallot(objectPattern: {"svNetwork": *}, democBallotInfo: *): * source

import {getDemocNthBallot} from 'sv-lib/src/light.ts'

Params:

NameTypeAttributeDescription
objectPattern {"svNetwork": *}
  • default: {"svNetwork":null}
democBallotInfo *

Return:

*

public getNetwork(networkId: *, chainId: *): * source

import {getNetwork} from 'sv-lib/src/const.ts'

Params:

NameTypeAttributeDescription
networkId *
chainId *

Return:

*

public hashMsgRaw(data: *): * source

import {hashMsgRaw} from 'sv-lib/src/crypto.ts'

Like web3.eth.accounts.hashMessage without the envelope.

Params:

NameTypeAttributeDescription
data *

A message to hash - if it is hex it'll be UTF8 decoded.

Return:

*

The hashed message (using keccak256)

public hexToBase32(hex: string): string source

import {hexToBase32} from 'sv-lib/src/utils.ts'

This will convert a hex string to Base32 in the bech32 format WITHOUT a checksum.

Params:

NameTypeAttributeDescription
hex string

The hex string to convert to Base32 - can be an EthHex or plain hex string.

Return:

string

The Base32 version of the hex string.

public async initializeSvLight(svConfig: *): {"svConfig": *, "web3": *, "resolver": *, "index": *, "backend": *, "aux": *, "payments": *} source

import {initializeSvLight} from 'sv-lib/src/light.ts'

Params:

NameTypeAttributeDescription
svConfig *

Return:

{"svConfig": *, "web3": *, "resolver": *, "index": *, "backend": *, "aux": *, "payments": *}

public mkPacked(start: number, end: number, submissionBits: number): BN source

import {mkPacked} from 'sv-lib/src/ballotBox.ts'

Creates a packed copy of start and end times with submissionBits

Params:

NameTypeAttributeDescription
start number

Start time in seconds since epoch

end number

End time in seconds since epoch

submissionBits number

Submission bits - can be created using mkSubmissionBits

Return:

BN

Returns a bn.js BigNum of the packed values. Format: [submissionBits(16)][startTime(64)][endTime(64)]

public mkSignedBallotForProxy(ballotId: string, sequence: number, voteData: string, extra: string, privateKey: string, opts: object): object source

import {mkSignedBallotForProxy} from 'sv-lib/src/ballotBox.ts'

Take the arguments and produce web3 data fitting the submitProxyVote method.

Params:

NameTypeAttributeDescription
ballotId string

a BN.js or Hex ballotId

sequence number

the sequence number to use (0 < sequence < 2^32)

voteData string

the vote data to use, should be 32 bytes hex encoded

extra string

any extra data included with the vote (such as curve25519 pubkeys)

privateKey string

the privkey used to sign

opts object

options:

  • skipSequenceSizeCheck: boolean (will not throw if sequence is >= 2^32)

Return:

object

{ proxyReq (bytes32[5]), extra (bytes) } in the required format for submitProxyVote

public mkSubmissionBits(toCombine: number[]): number source

import {mkSubmissionBits} from 'sv-lib/src/ballotBox.ts'

This combines flags into a finished submissionBits. It also does some validation.

Params:

NameTypeAttributeDescription
toCombine number[]

Array of all submission flags to combine. See SV.ballotBox.flags for flag options. All flags must be a power of 2 (which indicates they occupy a single bit in the number when combining).

Return:

number

A 16 bit integer of combined flags.

public networkName(networkId: *): string source

import {networkName} from 'sv-lib/src/const.ts'

Params:

NameTypeAttributeDescription
networkId *

Return:

string

public async resolveEnsAddress(objectPattern: {"resolver": *}, ensName: *): * source

import {resolveEnsAddress} from 'sv-lib/src/light.ts'

Params:

NameTypeAttributeDescription
objectPattern {"resolver": *}
  • default: {"resolver":null}
ensName *

Return:

*

public verifySignedBallotForProxy(proxyVote: ProxyVote, opts: *): {verified: bool, address: EthAddress} source

import {verifySignedBallotForProxy} from 'sv-lib/src/ballotBox.ts'

Verify a signed vote to be submitted via proxy as generated by mkSignedBallotForProxy

Params:

NameTypeAttributeDescription
proxyVote ProxyVote

The ProxyVote object

opts *
  • optional
  • default: {}

Not used currently; for future options

Return:

{verified: bool, address: EthAddress}

public async weiToCents(objectPattern: {"payments": *}, wei: *): * source

import {weiToCents} from 'sv-lib/src/light.ts'

Params:

NameTypeAttributeDescription
objectPattern {"payments": *}
  • default: {"payments":null}
wei *

Return:

*