opportunity-service 0.0.534 → 0.0.539
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/OpportunityService.js +16 -20
- package/dist/OpportunityService.js.map +1 -1
- package/dist/api/dispute/check-vote-results.js +33 -0
- package/dist/api/dispute/check-vote-results.js.map +1 -0
- package/dist/api/dispute/connect.js +39 -0
- package/dist/api/dispute/connect.js.map +1 -0
- package/dist/api/dispute/ensure-entity-metadata.js +39 -0
- package/dist/api/dispute/ensure-entity-metadata.js.map +1 -0
- package/dist/api/dispute/launch-new-vote.js +94 -0
- package/dist/api/dispute/launch-new-vote.js.map +1 -0
- package/dist/api/dispute/submit-vote.js +41 -0
- package/dist/api/dispute/submit-vote.js.map +1 -0
- package/dist/api/dispute/util/wait-until-present.js +27 -0
- package/dist/api/dispute/util/wait-until-present.js.map +1 -0
- package/dist/api/{voting/connect.js → dispute/util/wait-until-started.js} +11 -21
- package/dist/api/dispute/util/wait-until-started.js.map +1 -0
- package/dist/api/exchange/create-dispute.js +1 -2
- package/dist/api/exchange/create-dispute.js.map +1 -1
- package/dist/api/exchange/create-task.js +1 -1
- package/dist/api/exchange/create-task.js.map +1 -1
- package/dist/api/identity/register-new-user.js +11 -6
- package/dist/api/identity/register-new-user.js.map +1 -1
- package/dist/api/index.js +31 -2
- package/dist/api/index.js.map +1 -1
- package/dist/api/internal/abis.js +2 -1
- package/dist/api/internal/abis.js.map +1 -1
- package/dist/api/internal/addresses.js +21 -4
- package/dist/api/internal/addresses.js.map +1 -1
- package/dist/api/other/create-eth-crypto-creds.js +20 -0
- package/dist/api/other/create-eth-crypto-creds.js.map +1 -0
- package/dist/api/provider/decrypt.js +18 -0
- package/dist/api/provider/decrypt.js.map +1 -0
- package/dist/api/provider/encrypt.js +18 -0
- package/dist/api/provider/encrypt.js.map +1 -0
- package/dist/api/util/encrypt-by-public-key.js +52 -0
- package/dist/api/util/encrypt-by-public-key.js.map +1 -0
- package/dist/api/util/parse-cipher.js +11 -0
- package/dist/api/util/parse-cipher.js.map +1 -0
- package/dist/api/util/stringify-cipher.js +5 -0
- package/dist/api/util/stringify-cipher.js.map +1 -0
- package/dist/blockchain/abi.json +779 -1
- package/dist/blockchain/addresses.json +15 -5
- package/dist/blockchain/bytecode.json +2 -2
- package/dist/constants.js +0 -1
- package/dist/constants.js.map +1 -1
- package/dist/modules/storage/OpportunityStorageProvider.js +71 -41
- package/dist/modules/storage/OpportunityStorageProvider.js.map +1 -1
- package/dist/sync/sync-markets.js +1 -1
- package/dist/sync/sync-markets.js.map +1 -1
- package/package.json +13 -2
- package/src/OpportunityService.ts +22 -24
- package/src/api/dispute/check-vote-results.ts +30 -0
- package/src/api/dispute/connect.ts +36 -0
- package/src/api/dispute/ensure-entity-metadata.ts +34 -0
- package/src/api/dispute/launch-new-vote.ts +116 -0
- package/src/api/dispute/submit-vote.ts +59 -0
- package/src/api/dispute/util/wait-until-present.ts +19 -0
- package/src/api/dispute/util/wait-until-started.ts +14 -0
- package/src/api/exchange/create-dispute.ts +1 -1
- package/src/api/exchange/create-task.ts +1 -1
- package/src/api/identity/register-new-user.ts +7 -1
- package/src/api/index.ts +31 -2
- package/src/api/internal/abis.ts +2 -1
- package/src/api/internal/addresses.ts +21 -4
- package/src/api/other/create-eth-crypto-creds.ts +14 -0
- package/src/api/provider/decrypt.ts +9 -0
- package/src/api/provider/encrypt.ts +9 -0
- package/src/api/util/encrypt-by-public-key.ts +47 -0
- package/src/api/util/parse-cipher.ts +11 -0
- package/src/api/util/stringify-cipher.ts +5 -0
- package/src/blockchain/abi.json +779 -1
- package/src/blockchain/addresses.json +17 -5
- package/src/blockchain/bytecode.json +2 -2
- package/src/constants.ts +0 -1
- package/src/modules/storage/OpportunityStorageProvider.ts +80 -23
- package/src/sync/sync-markets.ts +1 -1
- package/src/types.ts +21 -1
- package/dist/api/voting/census.js +0 -38
- package/dist/api/voting/census.js.map +0 -1
- package/dist/api/voting/connect.js.map +0 -1
- package/dist/api/voting/entity.js +0 -39
- package/dist/api/voting/entity.js.map +0 -1
- package/dist/api/voting/process.js +0 -101
- package/dist/api/voting/process.js.map +0 -1
- package/src/api/voting/census.ts +0 -39
- package/src/api/voting/connect.ts +0 -34
- package/src/api/voting/entity.ts +0 -33
- package/src/api/voting/process.ts +0 -119
@@ -0,0 +1,59 @@
|
|
1
|
+
import { Wallet } from "@ethersproject/wallet"
|
2
|
+
import { CensusErc20Api } from "@vocdoni/census"
|
3
|
+
import { ProcessState, VotingApi, VotingOracleApi } from "@vocdoni/voting"
|
4
|
+
import { DVoteGateway, Erc20TokensApi, GatewayPool } from "@vocdoni/client"
|
5
|
+
import { ProcessMetadata } from "@vocdoni/data-models"
|
6
|
+
import { Signer } from "@ethersproject/abstract-signer"
|
7
|
+
import { JsonRpcProvider } from "@ethersproject/providers"
|
8
|
+
import { assert } from "console"
|
9
|
+
|
10
|
+
export async function submitVote(
|
11
|
+
processId: string,
|
12
|
+
processParams: ProcessState,
|
13
|
+
processMetadata: ProcessMetadata,
|
14
|
+
accounts,
|
15
|
+
tokenAddress: string,
|
16
|
+
voter: Signer,
|
17
|
+
voterChoice: number[],
|
18
|
+
gwPool: GatewayPool) {
|
19
|
+
console.log("Launching votes")
|
20
|
+
|
21
|
+
const processKeys = processParams.envelopeType.hasEncryptedVotes ? await VotingApi.getProcessKeys(processId, gwPool) : null
|
22
|
+
const balanceMappingPosition = (await CensusErc20Api.getTokenInfo(tokenAddress, gwPool)).balanceMappingPosition
|
23
|
+
const voterAddress = await voter.getAddress()
|
24
|
+
|
25
|
+
const result = await CensusErc20Api.generateProof(
|
26
|
+
tokenAddress,
|
27
|
+
voterAddress,
|
28
|
+
balanceMappingPosition,
|
29
|
+
processParams.sourceBlockHeight,
|
30
|
+
gwPool.provider as JsonRpcProvider
|
31
|
+
)
|
32
|
+
|
33
|
+
const censusProof = result.storageProof[0]
|
34
|
+
|
35
|
+
console.log('Creating voter envelope')
|
36
|
+
const envelope = processParams.envelopeType.encryptedVotes ?
|
37
|
+
await VotingApi.packageSignedEnvelope({ censusOrigin: processParams.censusOrigin, votes: voterChoice, censusProof, processId, walletOrSigner: voter, processKeys }) :
|
38
|
+
await VotingApi.packageSignedEnvelope({ censusOrigin: processParams.censusOrigin, votes: voterChoice, censusProof, processId, walletOrSigner: voter })
|
39
|
+
|
40
|
+
console.log('Attempting to submit voter envelope: ' + voter)
|
41
|
+
await VotingApi.submitEnvelope(envelope, voter, gwPool)
|
42
|
+
|
43
|
+
// wait a bit
|
44
|
+
await new Promise(resolve => setTimeout(resolve, 11000))
|
45
|
+
|
46
|
+
const nullifier = VotingApi.getSignedVoteNullifier(voterAddress, processId)
|
47
|
+
const { block, date, registered } = await VotingApi.getEnvelopeStatus(processId, nullifier, gwPool)
|
48
|
+
|
49
|
+
if (!registered) {
|
50
|
+
console.log('Vote not submitted.. voter not registered...')
|
51
|
+
return false;
|
52
|
+
}
|
53
|
+
|
54
|
+
console.log('Voter envelope successfully submitted')
|
55
|
+
console.log('Block: ' + block)
|
56
|
+
console.log('Date: ' + date)
|
57
|
+
console.log('Registered: ' + registered)
|
58
|
+
return true
|
59
|
+
}
|
@@ -0,0 +1,19 @@
|
|
1
|
+
import { VotingApi, VochainWaiter, ProcessState } from '@vocdoni/voting'
|
2
|
+
import * as assert from 'assert'
|
3
|
+
import { ProcessStatus } from 'dvote-solidity'
|
4
|
+
|
5
|
+
export async function waitUntilPresent(processId, gwPool) {
|
6
|
+
let attempts = 10
|
7
|
+
while (attempts >= 0) {
|
8
|
+
console.log("Waiting for process", processId, "to be created")
|
9
|
+
await VochainWaiter.wait(1, gwPool)
|
10
|
+
|
11
|
+
const state: ProcessState | void = await VotingApi.getProcessState(processId, gwPool).catch(error => console.log(error))
|
12
|
+
console.log('Attempted to get process state: ' + state)
|
13
|
+
if (state?.entityId) break
|
14
|
+
|
15
|
+
attempts--
|
16
|
+
}
|
17
|
+
|
18
|
+
if (attempts < 0) throw new Error("The process still does not exist on the Vochain after 10 blocks")
|
19
|
+
}
|
@@ -0,0 +1,14 @@
|
|
1
|
+
import { VotingApi, VochainWaiter } from '@vocdoni/voting'
|
2
|
+
import * as assert from 'assert'
|
3
|
+
import { ProcessStatus } from 'dvote-solidity'
|
4
|
+
|
5
|
+
export async function waitUntilStarted(processId, startBlock, gwPool) {
|
6
|
+
console.log('Waiting until block: ' + startBlock)
|
7
|
+
|
8
|
+
// start block
|
9
|
+
await VochainWaiter.waitUntil(startBlock, gwPool, { verbose: true })
|
10
|
+
|
11
|
+
console.log("Waiting for the process to be ready")
|
12
|
+
const state = await VotingApi.getProcessState(processId, gwPool)
|
13
|
+
assert.strictEqual(state.status, ProcessStatus.READY, "Should be ready but is not")
|
14
|
+
}
|
@@ -31,7 +31,7 @@ async function createDispute(data) : Promise<void> {
|
|
31
31
|
const disputeContractfactory = new ContractFactory(abi, bytecodeMap[Contracts.DISPUTE], opportunityService.getSignersInterface())
|
32
32
|
|
33
33
|
// Deploy an instance of the contract
|
34
|
-
const disputeContract = await disputeContractfactory.deploy(relationshipAddress,
|
34
|
+
const disputeContract = await disputeContractfactory.deploy(relationshipAddress, complaintMetadataPointer, complaintResponseMetadataPointer);
|
35
35
|
const txReceipt = await disputeContract.deployTransaction.wait()
|
36
36
|
console.log(txReceipt)
|
37
37
|
} catch(error) {
|
@@ -40,7 +40,7 @@ async function createTask(data) : Promise<void> {
|
|
40
40
|
console.log('d')
|
41
41
|
const contract = await new ethers.Contract(taskMarket, abi).connect(opportunityService.getSignersInterface());
|
42
42
|
console.log('e')
|
43
|
-
const txResponse = await contract.functions.createJob(taskOwner, ContractType.NORMAL, taskMetadataPointer, addressMap[
|
43
|
+
const txResponse = await contract.functions.createJob(taskOwner, ContractType.NORMAL, taskMetadataPointer, addressMap[opportunityService.getEthNetwork()][Contracts.DAI])
|
44
44
|
const txReceipt = await txResponse.wait()
|
45
45
|
console.log(txReceipt)
|
46
46
|
} catch(error) {
|
@@ -7,16 +7,22 @@ import abiMap from '../internal/abis'
|
|
7
7
|
import { Result } from 'ethers/lib/utils';
|
8
8
|
|
9
9
|
async function registerNewUser() {
|
10
|
+
try {
|
10
11
|
const msgSender = await opportunityService.getSignersInterface()._address
|
11
12
|
console.log('Registering new user: ' + msgSender)
|
12
13
|
|
14
|
+
|
15
|
+
|
13
16
|
const txResult = new Contract(
|
14
|
-
addressMap['UserRegistration'],
|
17
|
+
addressMap[opportunityService.getEthNetwork()]['UserRegistration'],
|
15
18
|
abiMap['UserRegistration']
|
16
19
|
).connect(opportunityService.getSignersInterface())
|
17
20
|
.registerNewUser({
|
18
21
|
from: msgSender
|
19
22
|
})
|
23
|
+
} catch(error) {
|
24
|
+
console.log(error)
|
25
|
+
}
|
20
26
|
}
|
21
27
|
|
22
28
|
export default registerNewUser;
|
package/src/api/index.ts
CHANGED
@@ -10,9 +10,25 @@ import { createMarket } from "./market/create-market";
|
|
10
10
|
import { abis, events, addresses } from './internal/index';
|
11
11
|
|
12
12
|
import { sendAsync } from './ethereum/sendAsync'
|
13
|
+
import { parseCypher } from "./util/parse-cipher";
|
14
|
+
import { stringifyCypher } from "./util/stringify-cipher";
|
15
|
+
import { decryptByPrivateKey, encryptByPublicKey } from "./util/encrypt-by-public-key";
|
16
|
+
import { createEthCryptoCreds } from "./other/create-eth-crypto-creds";
|
17
|
+
import { encrypt } from "./provider/encrypt";
|
18
|
+
import { decrypt } from "./provider/decrypt";
|
19
|
+
import { connectGateways, getOracleClient } from "./dispute/connect";
|
20
|
+
import { checkVoteResults } from "./dispute/check-vote-results";
|
21
|
+
import { ensureEntityMetadata } from "./dispute/ensure-entity-metadata";
|
22
|
+
import { launchNewVote } from "./dispute/launch-new-vote";
|
23
|
+
import { submitVote } from "./dispute/submit-vote";
|
13
24
|
|
14
25
|
function generateAPI() {
|
15
26
|
return {
|
27
|
+
crypto: {
|
28
|
+
encryptByPublicKey,
|
29
|
+
decryptByPrivateKey,
|
30
|
+
createEthCryptoCreds
|
31
|
+
},
|
16
32
|
internal: {
|
17
33
|
abis: abis,
|
18
34
|
addresses,
|
@@ -22,7 +38,14 @@ function generateAPI() {
|
|
22
38
|
createTask,
|
23
39
|
enterWorkRelationship
|
24
40
|
},
|
25
|
-
dispute: {
|
41
|
+
dispute: {
|
42
|
+
connectGateways: connectGateways,
|
43
|
+
getOracleClient: getOracleClient,
|
44
|
+
checkVoteResults: checkVoteResults,
|
45
|
+
ensureEntityMetadata: ensureEntityMetadata,
|
46
|
+
launchNewVote: launchNewVote,
|
47
|
+
submitVote: submitVote
|
48
|
+
},
|
26
49
|
identity: {
|
27
50
|
registerNewUser
|
28
51
|
},
|
@@ -37,7 +60,13 @@ function generateAPI() {
|
|
37
60
|
}
|
38
61
|
},
|
39
62
|
provider: {
|
40
|
-
sendAsync
|
63
|
+
sendAsync,
|
64
|
+
encrypt,
|
65
|
+
decrypt
|
66
|
+
},
|
67
|
+
util: {
|
68
|
+
parseCypher,
|
69
|
+
stringifyCypher
|
41
70
|
}
|
42
71
|
}
|
43
72
|
}
|
package/src/api/internal/abis.ts
CHANGED
@@ -2,8 +2,25 @@ import opportunityService from '../../OpportunityService';
|
|
2
2
|
import * as addressMap from '../../blockchain/addresses.json';
|
3
3
|
|
4
4
|
export default {
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
5
|
+
"rinkeby": {
|
6
|
+
'MarketFactory': addressMap['rinkeby']['MarketFactory'],
|
7
|
+
'UserRegistration': addressMap['rinkeby']['UserRegistration'],
|
8
|
+
'UserSummaryFactory': addressMap['rinkeby']['UserSummaryFactory'],
|
9
|
+
'Dai': addressMap['rinkeby']['Dai'],
|
10
|
+
'Participation': addressMap['rinkeby']['Participation']
|
11
|
+
},
|
12
|
+
"mainnet": {
|
13
|
+
'MarketFactory': addressMap['mainnet']['MarketFactory'],
|
14
|
+
'UserRegistration': addressMap['mainnet']['UserRegistration'],
|
15
|
+
'UserSummaryFactory': addressMap['mainnet']['UserSummaryFactory'],
|
16
|
+
'Dai': addressMap['mainnet']['Dai'],
|
17
|
+
'Participation': addressMap['mainnet']['Participation']
|
18
|
+
},
|
19
|
+
"xdai": {
|
20
|
+
'MarketFactory': addressMap['xdai']['MarketFactory'],
|
21
|
+
'UserRegistration': addressMap['xdai']['UserRegistration'],
|
22
|
+
'UserSummaryFactory': addressMap['xdai']['UserSummaryFactory'],
|
23
|
+
'Dai': addressMap['xdai']['Dai'],
|
24
|
+
'Participation': addressMap['xdai']['Participation']
|
25
|
+
}
|
9
26
|
}
|
@@ -0,0 +1,14 @@
|
|
1
|
+
import EthCrypto from 'eth-crypto';
|
2
|
+
import jswallet from 'ethereumjs-wallet'
|
3
|
+
import opportunityService from '../..//OpportunityService';
|
4
|
+
import Web3 from 'web3'
|
5
|
+
|
6
|
+
async function createEthCryptoCreds(passphrase) {
|
7
|
+
const entropy = Buffer.from(passphrase, 'utf-8')
|
8
|
+
const identity = EthCrypto.createIdentity(entropy)
|
9
|
+
|
10
|
+
const { address, publicKey, privateKey } = identity
|
11
|
+
return identity
|
12
|
+
}
|
13
|
+
|
14
|
+
export { createEthCryptoCreds }
|
@@ -0,0 +1,9 @@
|
|
1
|
+
import Web3 from 'web3'
|
2
|
+
import opportunityService from '../../OpportunityService'
|
3
|
+
|
4
|
+
export async function decrypt (keystore, passphrase) {
|
5
|
+
const web3 : Web3 = opportunityService.getDefaultProviderInterface()
|
6
|
+
|
7
|
+
const data = await web3.eth.accounts.decrypt(keystore, passphrase)
|
8
|
+
return data
|
9
|
+
}
|
@@ -0,0 +1,9 @@
|
|
1
|
+
import Web3 from 'web3'
|
2
|
+
import opportunityService from '../../OpportunityService'
|
3
|
+
|
4
|
+
export async function encrypt(privKey, password) {
|
5
|
+
const web3 : Web3 = opportunityService.getDefaultProviderInterface()
|
6
|
+
|
7
|
+
const keystore = await web3.eth.accounts.encrypt(privKey, password);
|
8
|
+
return keystore
|
9
|
+
}
|
@@ -0,0 +1,47 @@
|
|
1
|
+
import EthCrypto from 'eth-crypto';
|
2
|
+
|
3
|
+
/**
|
4
|
+
*
|
5
|
+
* @param pubKey
|
6
|
+
* @param message
|
7
|
+
* @returns
|
8
|
+
*/
|
9
|
+
async function encryptByPublicKey(pubKey, message) {
|
10
|
+
const encrypted = await EthCrypto.encryptWithPublicKey(
|
11
|
+
pubKey, // publicKey
|
12
|
+
message// message
|
13
|
+
);
|
14
|
+
|
15
|
+
return encrypted
|
16
|
+
}
|
17
|
+
|
18
|
+
/*
|
19
|
+
{
|
20
|
+
iv: '02aeac54cb45283b427bd1a5028552c1',
|
21
|
+
ephemPublicKey: '044acf39ed83c304f19f41ea66615d7a6c0068d5fc48ee181f2fb1091...',
|
22
|
+
ciphertext: '5fbbcc1a44ee19f7499dbc39cfc4ce96',
|
23
|
+
mac: '96490b293763f49a371d3a2040a2d2cb57f246ee88958009fe3c7ef2a38264a1'
|
24
|
+
} // encrypted-data
|
25
|
+
*/
|
26
|
+
|
27
|
+
|
28
|
+
/**
|
29
|
+
*
|
30
|
+
* @param privKey
|
31
|
+
* @param encryptedData
|
32
|
+
*/
|
33
|
+
async function decryptByPrivateKey(privKey, encryptedData) {
|
34
|
+
const { iv, ephemPublicKey, ciphertext, mac } = encryptedData
|
35
|
+
const message = await EthCrypto.decryptWithPrivateKey(
|
36
|
+
privKey, // privateKey
|
37
|
+
{
|
38
|
+
iv,
|
39
|
+
ephemPublicKey,
|
40
|
+
ciphertext,
|
41
|
+
mac
|
42
|
+
} // encrypted-data
|
43
|
+
);
|
44
|
+
}
|
45
|
+
|
46
|
+
|
47
|
+
export { encryptByPublicKey, decryptByPrivateKey }
|
@@ -0,0 +1,11 @@
|
|
1
|
+
import EthCrypto from 'eth-crypto'
|
2
|
+
|
3
|
+
/* > {
|
4
|
+
iv: '02aeac54cb45283b427bd1a5028552c1',
|
5
|
+
ephemPublicKey: '044acf39ed83c304f19f41ea66615d7a6c0068d5fc48ee181f2fb1091...',
|
6
|
+
ciphertext: '5fbbcc1a44ee19f7499dbc39cfc4ce96',
|
7
|
+
mac: '96490b293763f49a371d3a2040a2d2cb57f246ee88958009fe3c7ef2a38264a1'
|
8
|
+
} */
|
9
|
+
export function parseCypher(str) {
|
10
|
+
return EthCrypto.cipher.parse(str);
|
11
|
+
}
|