Skip to content
This repository has been archived by the owner on Jan 14, 2020. It is now read-only.

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
wanderingstan committed May 12, 2018
2 parents 14bc08e + 0413f3c commit b10c781
Show file tree
Hide file tree
Showing 14 changed files with 628 additions and 5,378 deletions.
2 changes: 1 addition & 1 deletion contracts/test/TestUserRegistry.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ contract("UserRegistry", accounts => {
let userRegistry

beforeEach(async () => {
userRegistry = await UserRegistry.new({ from: accounts[0] })
userRegistry = await UserRegistry.deployed()
})

it("should be able to register a user", async function() {
Expand Down
2 changes: 1 addition & 1 deletion contracts/test/identity/TestClaimHolderRegistered.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ contract("ClaimHolderRegistered", accounts => {
}

beforeEach(async function() {
userRegistry = await UserRegistry.new( { from: accounts[1] } )
userRegistry = await UserRegistry.deployed()
claimHolderRegistered = await ClaimHolderRegistered.new(userRegistry.address, { from: accounts[0] })
})

Expand Down
5,864 changes: 556 additions & 5,308 deletions package-lock.json

Large diffs are not rendered by default.

15 changes: 7 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,14 @@
"author": "Stan James <stan@originprotocol.com>",
"license": "MIT",
"dependencies": {
"ajv": "^6.5.0",
"babel-polyfill": "^6.26.0",
"bs58": "^4.0.1",
"cross-fetch": "^2.1.1",
"ethereumjs-util": "^5.2.0",
"form-data": "^2.3.2",
"ipfs-api": "^20.2.0",
"map-cache": "^0.2.2",
"npm": "^6.0.0",
"rlp": "^2.0.0",
"truffle-contract": "^3.0.5",
"util.promisify": "^1.0.0",
"web3": "^1.0.0-beta.34"
},
"devDependencies": {
Expand All @@ -58,15 +55,17 @@
"ganache-core": "^2.1.0",
"html-webpack-plugin": "^3.2.0",
"ipfs": "^0.28.2",
"ipfs-api": "^20.2.1",
"mocha": "^5.1.1",
"mocha-loader": "^1.1.3",
"node-watch": "^0.5.8",
"prettier": "1.12.1",
"sinon": "^5.0.3",
"truffle": "^4.1.7",
"sinon": "^5.0.7",
"truffle": "^4.1.8",
"truffle-contract": "^3.0.5",
"truffle-hdwallet-provider": "0.0.5",
"webpack": "^4.6.0",
"webpack-cli": "^2.1.2",
"webpack": "^4.8.1",
"webpack-cli": "^2.1.3",
"webpack-dev-server": "^3.1.4",
"webpack-node-externals": "^1.7.2"
}
Expand Down
2 changes: 1 addition & 1 deletion scripts/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ const testFormat = require('./helpers/test-format')
const start = async () => {
try {
await startGanache()
await deployContracts()
await testContracts()
await deployContracts()
await startIpfs()
await testJavascript()
await testFormat()
Expand Down
10 changes: 9 additions & 1 deletion src/contract-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,15 @@ class ContractService {
}
for (let name in contracts) {
this[name] = contracts[name]
try {
this[name].networks = Object.assign(
{},
this[name].networks,
options.contractAddresses[name]
)
} catch (e) {
/* Ignore */
}
}
}

Expand Down Expand Up @@ -200,7 +209,6 @@ class ContractService {
this.web3.eth.getTransaction(transactionHash, (error, transaction) => {
if (transaction.blockNumber != null) {
console.log(`Transaction mined at block ${transaction.blockNumber}`)
console.log(transaction)
// TODO: Wait maximum number of blocks
// TODO (Stan): Confirm transaction *sucessful* with getTransactionReceipt()

Expand Down
20 changes: 14 additions & 6 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,23 @@ var resources = {
users: require("./resources/users")
}

const defaultBridgeServer = "https://bridge.originprotocol.com"
const defaultIpfsDomain = "gateway.originprotocol.com"
const defaultIpfsApiPort = "5002"
const defaultIpfsGatewayPort = "443"
const defaultIpfsGatewayProtocol = "https"
const defaultAttestationServerUrl = `${defaultBridgeServer}/api/attestations`

class Origin {
constructor({
ipfsDomain,
ipfsApiPort,
ipfsGatewayPort,
ipfsGatewayProtocol,
attestationServerUrl
ipfsDomain = defaultIpfsDomain,
ipfsApiPort = defaultIpfsApiPort,
ipfsGatewayPort = defaultIpfsGatewayPort,
ipfsGatewayProtocol = defaultIpfsGatewayProtocol,
attestationServerUrl = defaultAttestationServerUrl,
contractAddresses
} = {}) {
this.contractService = new ContractService()
this.contractService = new ContractService({ contractAddresses })
this.ipfsService = new IpfsService({
ipfsDomain,
ipfsApiPort,
Expand Down
8 changes: 4 additions & 4 deletions src/ipfs-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ const Ports = {

class IpfsService {
constructor({
ipfsGatewayProtocol = "https",
ipfsDomain = "gateway.originprotocol.com",
ipfsGatewayPort = "443",
ipfsApiPort = "443"
ipfsGatewayProtocol,
ipfsDomain,
ipfsGatewayPort,
ipfsApiPort
} = {}) {
this.gateway = `${ipfsGatewayProtocol}://${ipfsDomain}`
this.api = `${ipfsGatewayProtocol}://${ipfsDomain}`
Expand Down
14 changes: 7 additions & 7 deletions src/resources/attestations.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,20 +88,19 @@ class Attestations {
)
}

async facebookAuthUrl({ redirectUrl }) {
async facebookAuthUrl() {
return await this.get(
`facebook/auth-url?redirect-url=${redirectUrl}`,
`facebook/auth-url`,
responseToUrl
)
}

async facebookVerify({ wallet, redirectUrl, code }) {
async facebookVerify({ wallet, code }) {
let identity = await this.getIdentityAddress(wallet)
return await this.post(
"facebook/verify",
{
identity,
"redirect-url": redirectUrl,
code
},
this.responseToAttestation
Expand All @@ -115,13 +114,13 @@ class Attestations {
)
}

async twitterVerify({ wallet, oauthVerifier }) {
async twitterVerify({ wallet, code }) {
let identity = await this.getIdentityAddress(wallet)
return await this.post(
"twitter/verify",
{
identity,
"oauth-verifier": oauthVerifier
"oauth-verifier": code
},
this.responseToAttestation
)
Expand All @@ -133,7 +132,8 @@ class Attestations {
{
method,
body: body ? JSON.stringify(body) : undefined,
headers: { "content-type": "application/json" }
headers: { "content-type": "application/json" },
credentials: 'include'
}
)
let json = await response.json()
Expand Down
2 changes: 1 addition & 1 deletion src/schemas/user.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"$schema":"http://json-schema.org/draft-06/schema#",
"$id":"http://json-schema.org/draft-06/schema",
"title": "User",
"type": "object",
"required": ["claims"],
Expand Down
21 changes: 21 additions & 0 deletions test/contract-service.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,4 +95,25 @@ describe("ContractService", function() {
)
})
})

describe("passing in contract addresses", () => {
it("should allow contract addresses to be overridden", () => {
const web3 = new Web3()
const userAddress = "0x1234567890123456789012345678901234567890"
const registryAddress = "0x9876543210987654321098765432109876543210"
const contractAddresses = {
userRegistryContract: { 4: { address: userAddress } },
listingsRegistryContract: { 4: { address: registryAddress } }
}

var contSrv = new ContractService({ web3, contractAddresses })

expect(contSrv.userRegistryContract.networks[4].address).to.equal(
userAddress
)
expect(contSrv.listingsRegistryContract.networks[4].address).to.equal(
registryAddress
)
})
})
})
32 changes: 0 additions & 32 deletions test/ipfs-service.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,38 +27,6 @@ describe("IpfsService", () => {
})
})

describe("constructor", () => {
it("should default to origin", () => {
var service = new IpfsService()
expect(service.gateway).to.equal("https://gateway.originprotocol.com")
expect(service.api).to.equal("https://gateway.originprotocol.com")
})

it("should use specified port if not protocol default", () => {
var service = new IpfsService({ ipfsGatewayPort: "8080" })
expect(service.gateway).to.equal(
"https://gateway.originprotocol.com:8080"
)

service = new IpfsService({
ipfsGatewayProtocol: "http",
ipfsGatewayPort: "8080"
})
expect(service.gateway).to.equal("http://gateway.originprotocol.com:8080")

service = new IpfsService({
ipfsGatewayProtocol: "http",
ipfsApiPort: "8080"
})
expect(service.api).to.equal("http://gateway.originprotocol.com:8080")
})

it("should use default protocol port if given port is empty", () => {
var service = new IpfsService({ ipfsGatewayPort: "" })
expect(service.gateway).to.equal("https://gateway.originprotocol.com")
})
})

describe("submitFile", () => {
listings.forEach(({ data, ipfsHash }) => {
it("should successfully submit file", async () => {
Expand Down
11 changes: 4 additions & 7 deletions test/resource_attestations.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,12 +138,10 @@ describe("Attestation Resource", function() {
it("should process the request", async () => {
let attestations = setupWithServer({
expectedMethod: "GET",
expectedPath: "facebook/auth-url?redirect-url=http://redirect.url",
expectedPath: "facebook/auth-url",
responseStub: { url: "foo.bar" }
})
let response = await attestations.facebookAuthUrl({
redirectUrl: "http://redirect.url"
})
let response = await attestations.facebookAuthUrl()
expect(response).to.equal("foo.bar")
})
})
Expand All @@ -153,12 +151,11 @@ describe("Attestation Resource", function() {
let attestations = setupWithServer({
expectedMethod: "POST",
expectedPath: "facebook/verify",
expectedParams: ["identity", "code", "redirect-url"],
expectedParams: ["identity", "code"],
responseStub: sampleAttestation
})
let response = await attestations.facebookVerify({
wallet: sampleWallet,
redirectUrl: "foo.bar",
code: "12345"
})
expectAttestation(response)
Expand Down Expand Up @@ -187,7 +184,7 @@ describe("Attestation Resource", function() {
})
let response = await attestations.twitterVerify({
wallet: sampleWallet,
oauthVerifier: "foo.bar"
code: "foo.bar"
})
expectAttestation(response)
})
Expand Down
3 changes: 2 additions & 1 deletion webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ var clientConfig = {
entry: ["babel-polyfill", './src/index.js'],
output: {
filename: './origin.js',
libraryTarget: 'window'
libraryTarget: 'var',
library: 'Origin'
},
mode: 'development',
devtool: 'inline-source-map',
Expand Down

0 comments on commit b10c781

Please sign in to comment.