Skip to content

Commit

Permalink
Merge pull request #250 from AdExNetwork/fix-identity-auth-cf
Browse files Browse the repository at this point in the history
ethereum adapter: support counterfactual accounts
  • Loading branch information
Ivo Georgiev authored Jan 15, 2020
2 parents b8f9829 + 4cc39d7 commit 66ada04
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
11 changes: 7 additions & 4 deletions adapters/ethereum/index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
const { MerkleTree, Channel, ChannelState } = require('adex-protocol-eth/js')
const { Wallet, Contract, utils, getDefaultProvider } = require('ethers')
const coreABI = require('adex-protocol-eth/abi/AdExCore')
const identityABI = require('adex-protocol-eth/abi/Identity')
const formatAddress = require('ethers').utils.getAddress
const fetch = require('node-fetch')
const util = require('util')
const assert = require('assert')
const fs = require('fs')
Expand Down Expand Up @@ -98,9 +98,12 @@ function Adapter(opts, cfg, ethProvider) {
// @TODO: validate era here too
let sess = { era: payload.era }
if (typeof payload.identity === 'string' && payload.identity.length === 42) {
const id = new Contract(payload.identity, identityABI, provider)
const privLevel = await id.privileges(from)
if (privLevel === 0) return Promise.reject(new Error('insufficient privilege'))
const relayerUrl = `${cfg.ETHEREUM_ADAPTER_RELAYER}/identity/by-owner/${from}`
const identitiesOwned = await fetch(relayerUrl).then(r => r.json())
const privEntry = Object.entries(identitiesOwned).find(
([k, v]) => k.toLowerCase() === payload.identity.toLowerCase() && v
)
if (!privEntry) return Promise.reject(new Error('insufficient privilege'))
sess = { uid: payload.identity, ...sess }
} else {
sess = { uid: from, ...sess }
Expand Down
1 change: 1 addition & 0 deletions cfg/dev.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,6 @@ module.exports = {
MINIMAL_FEE: 0,
ETHEREUM_CORE_ADDR: '0x333420fc6a897356e69b62417cd17ff012177d2b',
ETHEREUM_NETWORK: 'goerli',
ETHEREUM_ADAPTER_RELAYER: 'https://goerli-relayer.adex.network',
VALIDATORS_WHITELIST: []
}
1 change: 1 addition & 0 deletions cfg/prod.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,6 @@ module.exports = {
],
ETHEREUM_CORE_ADDR: '0x333420fc6a897356e69b62417cd17ff012177d2b',
ETHEREUM_NETWORK: 'homestead',
ETHEREUM_ADAPTER_RELAYER: 'https://relayer.adex.network',
VALIDATORS_WHITELIST: []
}

0 comments on commit 66ada04

Please sign in to comment.