Identity issue (#82)

* docs: Correctly print out db query results.

* test: Remove concurrent.

* test: Remove unimplemented and 3rd party AC tests.

* test: Remove unimplemented and 3rd party identity tests.

* docs: Move jsdoc config to conf directory.

* Point package.json main at index.js to access all exported functions.

* test: Identities storage pointing at wrong location.

* refactor: Identities is configurable when creating an OrbitDB instance.
This commit is contained in:
Hayden Young 2023-06-13 23:55:25 +08:00 committed by GitHub
parent 8a97a39047
commit 6def69f345
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
17 changed files with 46 additions and 1786 deletions

View File

@ -88,8 +88,12 @@ import OrbitDB from 'orbit-db'
// Listen for updates from peers
db.events.on("update", entry => {
console.log(entry)
<<<<<<< HEAD
const all = await db.all()
console.log(all)
=======
console.log(await db.all({ limit: 1 }))
>>>>>>> 582c826 (docs: Correctly print out db query results.)
})
// Add an entry
@ -97,9 +101,13 @@ import OrbitDB from 'orbit-db'
console.log(hash)
// Query
<<<<<<< HEAD
for await (const record of db.iterator()) {
console.log(record)
}
=======
console.log(await db.all({ limit: 1 }))
>>>>>>> 582c826 (docs: Correctly print out db query results.)
await db.close()
await orbitdb.stop()

View File

@ -16,7 +16,7 @@
"dist"
],
"type": "module",
"main": "src/orbitdb.js",
"main": "src/index.js",
"dependencies": {
"@ipld/dag-cbor": "^9.0.0",
"@libp2p/crypto": "^1.0.12",
@ -62,7 +62,7 @@
"build:examples": "webpack --config conf/webpack.example.config.js",
"build:dist": "webpack --config conf/webpack.config.js",
"build:debug": "webpack --config conf/webpack.debug.config.js",
"build:docs": "jsdoc -c ./jsdoc.json -r src/**",
"build:docs": "jsdoc -c ./conf/jsdoc/jsdoc.json -r src/**",
"build:tests": "rm -f test/browser/bundle.js* && webpack --config ./conf/webpack.tests.config.js",
"prepublishOnly": "npm run build",
"lint": "standard --env=mocha",

View File

@ -19,7 +19,7 @@
* ```
* @example <caption>Instantiate OrbitDB and open a new database:</caption>
* import { create } from 'ipfs-core'
* import OrbitDB from 'orbit-db'
* import { OrbitDB } from 'orbit-db'
*
* const ipfs = await create() // IPFS is required for storage and syncing
* const orbitdb = await OrbitDB({ ipfs })
@ -27,6 +27,26 @@
* const dbAddress = mydb.address // E.g. /orbitdb/zdpuAuK3BHpS7NvMBivynypqciYCuy2UW77XYBPUYRnLjnw13
* @example <caption>Open an existing database using its multiformat address:</caption>
* const mydb = await orbitdb.open(dbAddress)
* @example <caption>Use with pre-configured identities:</caption>
* import { create } from 'ipfs-core'
* import { OrbitDB, Identities } from 'orbit-db'
* import CustomStorage from './custom-storage.js'
*
* const storage = await CustomStorage()
* const identities = await Identities({ storage })
* const ipfs = await create() // IPFS is required for storage and syncing
* const orbitdb = await OrbitDB({ ipfs, identities })
* const mydb = await orbitdb.open('mydb')
* @example <caption>Use with existing identities:</caption>
* import { create } from 'ipfs-core'
* import { OrbitDB, Identities } from 'orbit-db'
*
* const identities = await Identities()
* await identities.createIdentity('userA')
*
* const ipfs = await create() // IPFS is required for storage and syncing
* const orbitdb = await OrbitDB({ ipfs, identities, id: 'userA' })
* const mydb = await orbitdb.open('mydb')
*/
import { Events, KeyValue, Documents } from './db/index.js'
import KeyStore from './key-store.js'
@ -82,15 +102,14 @@ const DefaultAccessController = IPFSAccessController
* @param {Object} params One or more parameters for configuring OrbitDB.
* @param {IPFS} params.ipfs An IPFS instance.
* @param {string} [params.id] The id of the OrbitDB instance.
* @param {Identity} [params.identity] An Identity instance.
* @param {namespace:KeyStore} [params.keystore] A KeyStore instance.
* @param {module:Identities} [params.identities] An Identities instance.
* @param {string} [params.directory] A location for storing OrbitDB-related
* data.
* @return {module:OrbitDB~OrbitDB} An instance of OrbitDB.
* @throws IPFSinstance is required argument if no IPFS instance is provided.
* @instance
*/
const OrbitDB = async ({ ipfs, id, identity, keystore, directory } = {}) => {
const OrbitDB = async ({ ipfs, id, identities, directory } = {}) => {
/**
* @namespace module:OrbitDB~OrbitDB
* @description The instance returned by {@link module:OrbitDB}.
@ -103,9 +122,17 @@ const OrbitDB = async ({ ipfs, id, identity, keystore, directory } = {}) => {
id = id || await createId()
const { id: peerId } = await ipfs.id()
directory = directory || './orbitdb'
keystore = keystore || await KeyStore({ path: pathJoin(directory, './keystore') })
const identities = await Identities({ ipfs, keystore })
identity = identity || await identities.createIdentity({ id })
let keystore
if (identities) {
keystore = identities.keystore
} else {
keystore = await KeyStore({ path: pathJoin(directory, './keystore') })
identities = await Identities({ ipfs, keystore })
}
const identity = await identities.createIdentity({ id })
const manifests = await Manifests({ ipfs })

View File

@ -1,174 +0,0 @@
{
"contractName": "Access",
"abi": [
{
"constant": true,
"inputs": [
{
"name": "",
"type": "address"
},
{
"name": "",
"type": "bytes32"
}
],
"name": "capabilities",
"outputs": [
{
"name": "",
"type": "bool"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": true,
"inputs": [],
"name": "OGAdmin",
"outputs": [
{
"name": "",
"type": "address"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"payable": false,
"stateMutability": "nonpayable",
"type": "constructor"
},
{
"anonymous": false,
"inputs": [
{
"indexed": false,
"name": "user",
"type": "address"
},
{
"indexed": false,
"name": "capability",
"type": "bytes32"
}
],
"name": "CapabilityGranted",
"type": "event"
},
{
"anonymous": false,
"inputs": [
{
"indexed": false,
"name": "user",
"type": "address"
},
{
"indexed": false,
"name": "capability",
"type": "bytes32"
}
],
"name": "CapabilityRevoked",
"type": "event"
},
{
"constant": false,
"inputs": [
{
"name": "newAdmin",
"type": "address"
}
],
"name": "grantAdminStatus",
"outputs": [],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
},
{
"constant": false,
"inputs": [
{
"name": "adminToRemove",
"type": "address"
}
],
"name": "revokeAdminStatus",
"outputs": [],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
},
{
"constant": false,
"inputs": [
{
"name": "user",
"type": "address"
},
{
"name": "capability",
"type": "bytes32"
}
],
"name": "grantCapability",
"outputs": [],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
},
{
"constant": false,
"inputs": [
{
"name": "user",
"type": "address"
},
{
"name": "capability",
"type": "bytes32"
}
],
"name": "revokeCapability",
"outputs": [],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
},
{
"constant": true,
"inputs": [
{
"name": "user",
"type": "address"
},
{
"name": "capability",
"type": "bytes32"
}
],
"name": "isPermitted",
"outputs": [
{
"name": "",
"type": "bool"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
}
],
"bytecode": "0x608060405234801561001057600080fd5b50336000806101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555060018060003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060006101000a81548160ff021916908315150217905550610822806100b76000396000f3fe608060405260043610610083576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff168063106bab8c146100885780631faad3c4146100fb578063228e3f9b14610152578063330506d9146101ad5780637caac39814610208578063e21c478314610259578063fa62a1ff146102cc575b600080fd5b34801561009457600080fd5b506100e1600480360360408110156100ab57600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff1690602001909291908035906020019092919050505061031d565b604051808215151515815260200191505060405180910390f35b34801561010757600080fd5b5061011061034c565b604051808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b34801561015e57600080fd5b506101ab6004803603604081101561017557600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff16906020019092919080359060200190929190505050610371565b005b3480156101b957600080fd5b50610206600480360360408110156101d057600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803590602001909291905050506104a3565b005b34801561021457600080fd5b506102576004803603602081101561022b57600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff1690602001909291905050506105d5565b005b34801561026557600080fd5b506102b26004803603604081101561027c57600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff16906020019092919080359060200190929190505050610689565b604051808215151515815260200191505060405180910390f35b3480156102d857600080fd5b5061031b600480360360208110156102ef57600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050610745565b005b60026020528160005260406000206020528060005260406000206000915091509054906101000a900460ff1681565b6000809054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b60011515600160003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff161515141561049f576000600260008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020600083815260200190815260200160002060006101000a81548160ff0219169083151502179055507f6cc46c13bf9ecc309370a9150165239f833c3742128d77220c49cb4915a07bc78282604051808373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020018281526020019250505060405180910390a15b5050565b60011515600160003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff16151514156105d1576001600260008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020600083815260200190815260200160002060006101000a81548160ff0219169083151502179055507faf409f79c52d1fc6127b156de998c22b9c6cf6d4f0f58e934e62f983c4dc82bf8282604051808373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020018281526020019250505060405180910390a15b5050565b60011515600160003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff16151514156106865760018060008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060006101000a81548160ff0219169083151502179055505b50565b6000600160008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff168061073d5750600260008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020600083815260200190815260200160002060009054906101000a900460ff165b905092915050565b6000809054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff1614156107f3576000600160008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060006101000a81548160ff0219169083151502179055505b5056fea165627a7a7230582009cc4036faa4edfffcc9ba31cfc8caab65942780eb1dedaa2459f3514b30db5d0029",
"deployedBytecode": "0x608060405260043610610083576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff168063106bab8c146100885780631faad3c4146100fb578063228e3f9b14610152578063330506d9146101ad5780637caac39814610208578063e21c478314610259578063fa62a1ff146102cc575b600080fd5b34801561009457600080fd5b506100e1600480360360408110156100ab57600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff1690602001909291908035906020019092919050505061031d565b604051808215151515815260200191505060405180910390f35b34801561010757600080fd5b5061011061034c565b604051808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b34801561015e57600080fd5b506101ab6004803603604081101561017557600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff16906020019092919080359060200190929190505050610371565b005b3480156101b957600080fd5b50610206600480360360408110156101d057600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803590602001909291905050506104a3565b005b34801561021457600080fd5b506102576004803603602081101561022b57600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff1690602001909291905050506105d5565b005b34801561026557600080fd5b506102b26004803603604081101561027c57600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff16906020019092919080359060200190929190505050610689565b604051808215151515815260200191505060405180910390f35b3480156102d857600080fd5b5061031b600480360360208110156102ef57600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050610745565b005b60026020528160005260406000206020528060005260406000206000915091509054906101000a900460ff1681565b6000809054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b60011515600160003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff161515141561049f576000600260008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020600083815260200190815260200160002060006101000a81548160ff0219169083151502179055507f6cc46c13bf9ecc309370a9150165239f833c3742128d77220c49cb4915a07bc78282604051808373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020018281526020019250505060405180910390a15b5050565b60011515600160003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff16151514156105d1576001600260008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020600083815260200190815260200160002060006101000a81548160ff0219169083151502179055507faf409f79c52d1fc6127b156de998c22b9c6cf6d4f0f58e934e62f983c4dc82bf8282604051808373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020018281526020019250505060405180910390a15b5050565b60011515600160003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff16151514156106865760018060008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060006101000a81548160ff0219169083151502179055505b50565b6000600160008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff168061073d5750600260008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020600083815260200190815260200160002060009054906101000a900460ff165b905092915050565b6000809054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff1614156107f3576000600160008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060006101000a81548160ff0219169083151502179055505b5056fea165627a7a7230582009cc4036faa4edfffcc9ba31cfc8caab65942780eb1dedaa2459f3514b30db5d0029",
"sourceMap": "25:1342:0:-;;;185:93;8:9:-1;5:2;;;30:1;27;20:12;5:2;185:93:0;227:10;217:7;;:20;;;;;;;;;;;;;;;;;;267:4;247:5;:17;253:10;247:17;;;;;;;;;;;;;;;;:24;;;;;;;;;;;;;;;;;;25:1342;;;;;;",
"deployedSourceMap": "25:1342:0:-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;112:66;;8:9:-1;5:2;;;30:1;27;20:12;5:2;112:66:0;;;;;;13:2:-1;8:3;5:11;2:2;;;29:1;26;19:12;2:2;112:66:0;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;47:22;;8:9:-1;5:2;;;30:1;27;20:12;5:2;47:22:0;;;;;;;;;;;;;;;;;;;;;;;;;;;978:230;;8:9:-1;5:2;;;30:1;27;20:12;5:2;978:230:0;;;;;;13:2:-1;8:3;5:11;2:2;;;29:1;26;19:12;2:2;978:230:0;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;744:228;;8:9:-1;5:2;;;30:1;27;20:12;5:2;744:228:0;;;;;;13:2:-1;8:3;5:11;2:2;;;29:1;26;19:12;2:2;744:228:0;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;434:145;;8:9:-1;5:2;;;30:1;27;20:12;5:2;434:145:0;;;;;;13:2:-1;8:3;5:11;2:2;;;29:1;26;19:12;2:2;434:145:0;;;;;;;;;;;;;;;;;;;;;;1214:151;;8:9:-1;5:2;;;30:1;27;20:12;5:2;1214:151:0;;;;;;13:2:-1;8:3;5:11;2:2;;;29:1;26;19:12;2:2;1214:151:0;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;585:153;;8:9:-1;5:2;;;30:1;27;20:12;5:2;585:153:0;;;;;;13:2:-1;8:3;5:11;2:2;;;29:1;26;19:12;2:2;585:153:0;;;;;;;;;;;;;;;;;;;;;;112:66;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;:::o;47:22::-;;;;;;;;;;;;;:::o;978:230::-;1079:4;1058:25;;:5;:17;1064:10;1058:17;;;;;;;;;;;;;;;;;;;;;;;;;:25;;;1055:147;;;1132:5;1099:12;:18;1112:4;1099:18;;;;;;;;;;;;;;;:30;1118:10;1099:30;;;;;;;;;;;;:38;;;;;;;;;;;;;;;;;;1156:35;1174:4;1180:10;1156:35;;;;;;;;;;;;;;;;;;;;;;;;;;;;1055:147;978:230;;:::o;744:228::-;844:4;823:25;;:5;:17;829:10;823:17;;;;;;;;;;;;;;;;;;;;;;;;;:25;;;820:146;;;897:4;864:12;:18;877:4;864:18;;;;;;;;;;;;;;;:30;883:10;864:30;;;;;;;;;;;;:37;;;;;;;;;;;;;;;;;;920:35;938:4;944:10;920:35;;;;;;;;;;;;;;;;;;;;;;;;;;;;820:146;744:228;;:::o;434:145::-;520:4;499:25;;:5;:17;505:10;499:17;;;;;;;;;;;;;;;;;;;;;;;;;:25;;;495:78;;;558:4;540:5;:15;546:8;540:15;;;;;;;;;;;;;;;;:22;;;;;;;;;;;;;;;;;;495:78;434:145;:::o;1214:151::-;1290:4;1313:5;:11;1319:4;1313:11;;;;;;;;;;;;;;;;;;;;;;;;;:45;;;;1328:12;:18;1341:4;1328:18;;;;;;;;;;;;;;;:30;1347:10;1328:30;;;;;;;;;;;;;;;;;;;;;1313:45;1306:52;;1214:151;;;;:::o;585:153::-;670:7;;;;;;;;;;;656:21;;:10;:21;;;652:80;;;716:5;693;:20;699:13;693:20;;;;;;;;;;;;;;;;:28;;;;;;;;;;;;;;;;;;652:80;585:153;:::o",
"source": "pragma solidity ^0.5.0;\n\ncontract Access {\n address public OGAdmin;\n mapping (address => bool) admin;\n mapping (address => mapping (bytes32 => bool)) public capabilities;\n\n constructor () public {\n OGAdmin = msg.sender;\n admin[msg.sender] = true;\n }\n\n event CapabilityGranted(address user, bytes32 capability);\n\n event CapabilityRevoked(\n address user,\n bytes32 capability\n );\n\n function grantAdminStatus(address newAdmin) public {\n if (admin[msg.sender] == true) {\n admin[newAdmin] = true;\n }\n }\n\n function revokeAdminStatus(address adminToRemove) public {\n if (msg.sender == OGAdmin) {\n admin[adminToRemove] = false;\n }\n }\n\n function grantCapability(address user, bytes32 capability) public {\n if(admin[msg.sender] == true) {\n capabilities[user][capability] = true;\n emit CapabilityGranted(user, capability);\n }\n }\n\n function revokeCapability(address user, bytes32 capability) public {\n if(admin[msg.sender] == true) {\n capabilities[user][capability] = false;\n emit CapabilityRevoked(user, capability);\n }\n }\n\n function isPermitted(address user, bytes32 capability) public view returns (bool) {\n return admin[user] || capabilities[user][capability];\n }\n}\n"
}

View File

@ -1,124 +0,0 @@
{
"contractName": "PayDeposit",
"abi": [
{
"constant": true,
"inputs": [],
"name": "OGAdmin",
"outputs": [
{
"name": "",
"type": "address"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": true,
"inputs": [
{
"name": "",
"type": "address"
}
],
"name": "paid",
"outputs": [
{
"name": "",
"type": "bool"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"payable": false,
"stateMutability": "nonpayable",
"type": "constructor"
},
{
"constant": false,
"inputs": [
{
"name": "newAdmin",
"type": "address"
}
],
"name": "grantAdminStatus",
"outputs": [],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
},
{
"constant": false,
"inputs": [
{
"name": "adminToRemove",
"type": "address"
}
],
"name": "revokeAdminStatus",
"outputs": [],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
},
{
"constant": false,
"inputs": [
{
"name": "user",
"type": "address"
}
],
"name": "payDeposit",
"outputs": [],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
},
{
"constant": false,
"inputs": [
{
"name": "user",
"type": "address"
}
],
"name": "expireDeposit",
"outputs": [],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
},
{
"constant": true,
"inputs": [
{
"name": "user",
"type": "address"
}
],
"name": "hasPaidDeposit",
"outputs": [
{
"name": "",
"type": "bool"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
}
],
"bytecode": "0x608060405234801561001057600080fd5b50336000806101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555060018060003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060006101000a81548160ff02191690831515021790555061068b806100b76000396000f3fe608060405260043610610083576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff1680631faad3c4146100885780632c679d63146100df57806354dae7801461013057806359f3ef05146101995780637caac398146101ea578063a340cf791461023b578063fa62a1ff146102a4575b600080fd5b34801561009457600080fd5b5061009d6102f5565b604051808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b3480156100eb57600080fd5b5061012e6004803603602081101561010257600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff16906020019092919050505061031a565b005b34801561013c57600080fd5b5061017f6004803603602081101561015357600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff1690602001909291905050506103cf565b604051808215151515815260200191505060405180910390f35b3480156101a557600080fd5b506101e8600480360360208110156101bc57600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050610425565b005b3480156101f657600080fd5b506102396004803603602081101561020d57600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff1690602001909291905050506104da565b005b34801561024757600080fd5b5061028a6004803603602081101561025e57600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff16906020019092919050505061058e565b604051808215151515815260200191505060405180910390f35b3480156102b057600080fd5b506102f3600480360360208110156102c757600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff1690602001909291905050506105ae565b005b6000809054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b60011515600160003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff16151514156103cc576000600260008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060006101000a81548160ff0219169083151502179055505b50565b6000600260008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff169050919050565b60011515600160003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff16151514156104d7576001600260008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060006101000a81548160ff0219169083151502179055505b50565b60011515600160003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff161515141561058b5760018060008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060006101000a81548160ff0219169083151502179055505b50565b60026020528060005260406000206000915054906101000a900460ff1681565b6000809054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff16141561065c576000600160008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060006101000a81548160ff0219169083151502179055505b5056fea165627a7a72305820d6f5392496318abaff5d492d31c15fee1934106beb9aa461d99727d9d77955cb0029",
"deployedBytecode": "0x608060405260043610610083576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff1680631faad3c4146100885780632c679d63146100df57806354dae7801461013057806359f3ef05146101995780637caac398146101ea578063a340cf791461023b578063fa62a1ff146102a4575b600080fd5b34801561009457600080fd5b5061009d6102f5565b604051808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b3480156100eb57600080fd5b5061012e6004803603602081101561010257600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff16906020019092919050505061031a565b005b34801561013c57600080fd5b5061017f6004803603602081101561015357600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff1690602001909291905050506103cf565b604051808215151515815260200191505060405180910390f35b3480156101a557600080fd5b506101e8600480360360208110156101bc57600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050610425565b005b3480156101f657600080fd5b506102396004803603602081101561020d57600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff1690602001909291905050506104da565b005b34801561024757600080fd5b5061028a6004803603602081101561025e57600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff16906020019092919050505061058e565b604051808215151515815260200191505060405180910390f35b3480156102b057600080fd5b506102f3600480360360208110156102c757600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff1690602001909291905050506105ae565b005b6000809054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b60011515600160003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff16151514156103cc576000600260008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060006101000a81548160ff0219169083151502179055505b50565b6000600260008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff169050919050565b60011515600160003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff16151514156104d7576001600260008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060006101000a81548160ff0219169083151502179055505b50565b60011515600160003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff161515141561058b5760018060008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060006101000a81548160ff0219169083151502179055505b50565b60026020528060005260406000206000915054906101000a900460ff1681565b6000809054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff16141561065c576000600160008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060006101000a81548160ff0219169083151502179055505b5056fea165627a7a72305820d6f5392496318abaff5d492d31c15fee1934106beb9aa461d99727d9d77955cb0029",
"sourceMap": "25:919:2:-;;;160:93;8:9:-1;5:2;;;30:1;27;20:12;5:2;160:93:2;202:10;192:7;;:20;;;;;;;;;;;;;;;;;;242:4;222:5;:17;228:10;222:17;;;;;;;;;;;;;;;;:24;;;;;;;;;;;;;;;;;;25:919;;;;;;",
"deployedSourceMap": "25:919:2:-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;51:22;;8:9:-1;5:2;;;30:1;27;20:12;5:2;51:22:2;;;;;;;;;;;;;;;;;;;;;;;;;;;704:133;;8:9:-1;5:2;;;30:1;27;20:12;5:2;704:133:2;;;;;;13:2:-1;8:3;5:11;2:2;;;29:1;26;19:12;2:2;704:133:2;;;;;;;;;;;;;;;;;;;;;;843:99;;8:9:-1;5:2;;;30:1;27;20:12;5:2;843:99:2;;;;;;13:2:-1;8:3;5:11;2:2;;;29:1;26;19:12;2:2;843:99:2;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;569:129;;8:9:-1;5:2;;;30:1;27;20:12;5:2;569:129:2;;;;;;13:2:-1;8:3;5:11;2:2;;;29:1;26;19:12;2:2;569:129:2;;;;;;;;;;;;;;;;;;;;;;259:145;;8:9:-1;5:2;;;30:1;27;20:12;5:2;259:145:2;;;;;;13:2:-1;8:3;5:11;2:2;;;29:1;26;19:12;2:2;259:145:2;;;;;;;;;;;;;;;;;;;;;;116:37;;8:9:-1;5:2;;;30:1;27;20:12;5:2;116:37:2;;;;;;13:2:-1;8:3;5:11;2:2;;;29:1;26;19:12;2:2;116:37:2;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;410:153;;8:9:-1;5:2;;;30:1;27;20:12;5:2;410:153:2;;;;;;13:2:-1;8:3;5:11;2:2;;;29:1;26;19:12;2:2;410:153:2;;;;;;;;;;;;;;;;;;;;;;51:22;;;;;;;;;;;;;:::o;704:133::-;782:4;761:25;;:5;:17;767:10;761:17;;;;;;;;;;;;;;;;;;;;;;;;;:25;;;758:73;;;815:5;802:4;:10;807:4;802:10;;;;;;;;;;;;;;;;:18;;;;;;;;;;;;;;;;;;758:73;704:133;:::o;843:99::-;902:4;925;:10;930:4;925:10;;;;;;;;;;;;;;;;;;;;;;;;;918:17;;843:99;;;:::o;569:129::-;644:4;623:25;;:5;:17;629:10;623:17;;;;;;;;;;;;;;;;;;;;;;;;;:25;;;620:72;;;677:4;664;:10;669:4;664:10;;;;;;;;;;;;;;;;:17;;;;;;;;;;;;;;;;;;620:72;569:129;:::o;259:145::-;345:4;324:25;;:5;:17;330:10;324:17;;;;;;;;;;;;;;;;;;;;;;;;;:25;;;320:78;;;383:4;365:5;:15;371:8;365:15;;;;;;;;;;;;;;;;:22;;;;;;;;;;;;;;;;;;320:78;259:145;:::o;116:37::-;;;;;;;;;;;;;;;;;;;;;;:::o;410:153::-;495:7;;;;;;;;;;;481:21;;:10;:21;;;477:80;;;541:5;518;:20;524:13;518:20;;;;;;;;;;;;;;;;:28;;;;;;;;;;;;;;;;;;477:80;410:153;:::o",
"source": "pragma solidity ^0.5.0;\n\ncontract PayDeposit {\n address public OGAdmin;\n mapping (address => bool) admin;\n mapping (address => bool) public paid;\n\n constructor () public {\n OGAdmin = msg.sender;\n admin[msg.sender] = true;\n }\n\n function grantAdminStatus(address newAdmin) public {\n if (admin[msg.sender] == true) {\n admin[newAdmin] = true;\n }\n }\n\n function revokeAdminStatus(address adminToRemove) public {\n if (msg.sender == OGAdmin) {\n admin[adminToRemove] = false;\n }\n }\n\n function payDeposit(address user) public {\n if(admin[msg.sender] == true) {\n paid[user] = true;\n }\n }\n\n function expireDeposit(address user) public {\n if(admin[msg.sender] == true) {\n paid[user] = false;\n }\n }\n\n function hasPaidDeposit(address user) public view returns (bool) {\n return paid[user];\n }\n}\n"
}

View File

@ -1,138 +0,0 @@
// import assert from 'assert'
// import rmrf from 'rimraf'
// // import Web3 from 'web3'
// import OrbitDB from '../../src/orbitdb.js'
//
// // import IdentityProvider from 'orbit-db-identity-provider'
// import Keystore from '../../src/key-store.js'
// import AccessControllers from '../../src/access-controllers/index.js'
// // import ContractAccessController from 'orbit-db-access-controllers/contract'
// // import ganache from 'ganache-cli'
// // import Access from './Access.json' assert {type: "json"}
// import config from '../config.js'
// import connectPeers from '../utils/connect-nodes.js'
//
// const abi = Access.abi
// const bytecode = Access.bytecode
// const dbPath1 = './orbitdb/tests/orbitdb-access-controller/1'
// const dbPath2 = './orbitdb/tests/orbitdb-access-controller/2'
//
// describe('Access Controller Handlers', function () {
// this.timeout(config.timeout)
//
// let ipfs1, ipfs2
// let orbitdb1, orbitdb2
//
// before(async () => {
// ipfs1 = await IPFS.create({ ...config.daemon1, repo: './ipfs1' })
// ipfs2 = await IPFS.create({ ...config.daemon2, repo: './ipfs2' })
// await connectPeers(ipfs1, ipfs2)
//
// const keystore1 = await Keystore({ path: dbPath1 + '/keys' })
// const keystore2 = await Keystore({ path: dbPath2 + '/keys' })
//
// identities1 = await Identities({ keystore: keystore1 })
// identities2 = await Identities({ keystore: keystore2 })
//
// testIdentity1 = await identities1.createIdentity({ id: 'userA' })
// testIdentity2 = await identities2.createIdentity({ id: 'userB' })
//
// orbitdb1 = await OrbitDB({ ipfs: ipfs1, identity: testIdentity1, directory: dbPath1 })
// orbitdb2 = await OrbitDB({ ipfs: ipfs2, identity: testIdentity2, directory: dbPath2 })
// })
//
// after(async () => {
// if (orbitdb1) {
// await orbitdb1.stop()
// }
//
// if (orbitdb2) {
// await orbitdb2.stop()
// }
//
// if (ipfs1) {
// await ipfs1.stop()
// }
//
// if (ipfs2) {
// await ipfs2.stop()
// }
//
// await rmrf('./orbitdb')
// await rmrf('./ipfs1')
// await rmrf('./ipfs2')
// })
//
// describe.only('isSupported', function () {
// it('supports default access controllers', () => {
// assert.strictEqual(AccessControllers.isSupported('ipfs'), true)
// assert.strictEqual(AccessControllers.isSupported('orbitdb'), true)
// })
//
// it('doesn\'t support smart contract access controller by default', () => {
// assert.strictEqual(AccessControllers.isSupported(ContractAccessController.type), false)
// })
// })
//
// // describe('addAccessController', function () {
// // it('supports added access controller', () => {
// // const options = {
// // AccessController: ContractAccessController,
// // web3: web3,
// // abi: abi
// // }
// // AccessControllers.addAccessController(options)
// // assert.strictEqual(AccessControllers.isSupported(ContractAccessController.type), true)
// // })
// // })
// //
// // describe('create access controllers', function () {
// // let options = {
// // AccessController: ContractAccessController
// // }
// //
// // before(async () => {
// // web3 = new Web3(ganache.provider())
// // const accounts = await web3.eth.getAccounts()
// // contract = await new web3.eth.Contract(abi)
// // .deploy({ data: bytecode })
// // .send({ from: accounts[0], gas: '1000000' })
// // options = Object.assign({}, options, { web3, abi, contractAddress: contract._address, defaultAccount: accounts[0] })
// // AccessControllers.addAccessController(options)
// // })
// //
// // it('throws an error if AccessController is not defined', async () => {
// // let err
// // try {
// // AccessControllers.addAccessController({})
// // } catch (e) {
// // err = e.toString()
// // }
// // assert.strictEqual(err, 'Error: AccessController class needs to be given as an option')
// // })
// //
// // it('throws an error if AccessController doesn\'t define type', async () => {
// // let err
// // try {
// // AccessControllers.addAccessController({ AccessController: {} })
// // } catch (e) {
// // err = e.toString()
// // }
// // assert.strictEqual(err, 'Error: Given AccessController class needs to implement: static get type() { /* return a string */}.')
// // })
// //
// // it('creates a custom access controller', async () => {
// // const type = ContractAccessController.type
// // const acManifestHash = await AccessControllers.create(orbitdb1, type, options)
// // assert.notStrictEqual(acManifestHash, null)
// //
// // const ac = await AccessControllers.resolve(orbitdb1, acManifestHash, options)
// // assert.strictEqual(ac.type, type)
// // })
// //
// // it('removes the custom access controller', async () => {
// // AccessControllers.removeAccessController(ContractAccessController.type)
// // assert.strictEqual(AccessControllers.isSupported(ContractAccessController.type), false)
// // })
// // })
// })

View File

@ -1,275 +0,0 @@
// import assert from 'assert'
// import rmrf from 'rimraf'
// import OrbitDB from '../../src/orbitdb.js'
// import IdentityProvider from 'orbit-db-identity-provider'
// import EthIdentityProvider from 'orbit-db-identity-provider/ethereum'
// import Keystore from 'orbit-db-keystore'
// import AccessControllers from 'orbit-db-access-controllers'
// import ContractAccessController from 'orbit-db-access-controllers/contract'
// import DepositContractAccessController from 'orbit-db-access-controllers/deposit-contract'
// import ganache from 'ganache-cli'
// import Web3 from 'web3'
// import * as io from 'orbit-db-io'
// import Access from './Access.json' assert {type: "json"}
// import PayDeposit from './PayDeposit.json' assert {type: "json"}
// // Include test utilities
// import {
// config,
// startIpfs,
// stopIpfs,
// testAPIs,
// connectPeers
// } from 'orbit-db-test-utils'
// const dbPath1 = './orbitdb/tests/contract-access-controller-integration/1'
// const dbPath2 = './orbitdb/tests/contract-access-controller-integration/2'
// const accessControllers = [
// {
// AccessController: ContractAccessController,
// contract: Access
// },
// {
// AccessController: DepositContractAccessController,
// contract: PayDeposit
// }
// ]
// Object.keys(testAPIs).forEach(API => {
// describe(`orbit-db - ContractAccessController Integration (${API})`, function () {
// this.timeout(config.timeout * 2)
// let ipfsd1, ipfsd2, ipfs1, ipfs2, id1, id2
// let orbitdb1, orbitdb2
// let web3, accounts
// before(async () => {
// rmrf.sync(dbPath1)
// rmrf.sync(dbPath2)
// ipfsd1 = await startIpfs(API, config.daemon1)
// ipfsd2 = await startIpfs(API, config.daemon2)
// ipfs1 = ipfsd1.api
// ipfs2 = ipfsd2.api
// // Connect the peers manually to speed up test times
// const isLocalhostAddress = (addr) => addr.toString().includes('127.0.0.1')
// await connectPeers(ipfs1, ipfs2, { filter: isLocalhostAddress })
// const keystore1 = new Keystore(dbPath1 + '/keys')
// const keystore2 = new Keystore(dbPath2 + '/keys')
// IdentityProvider.addIdentityProvider(EthIdentityProvider)
// id1 = await IdentityProvider.createIdentity({ type: 'ethereum', keystore: keystore1 })
// id2 = await IdentityProvider.createIdentity({ type: 'ethereum', keystore: keystore2 })
// web3 = new Web3(ganache.provider())
// accounts = await web3.eth.getAccounts()
// accessControllers.forEach(ac => AccessControllers.addAccessController(ac))
// orbitdb1 = await OrbitDB.createInstance(ipfs1, {
// AccessControllers: AccessControllers,
// directory: dbPath1,
// identity: id1
// })
// orbitdb2 = await OrbitDB.createInstance(ipfs2, {
// AccessControllers: AccessControllers,
// directory: dbPath2,
// identity: id2
// })
// })
// after(async () => {
// if (orbitdb1) {
// await orbitdb1.stop()
// }
// if (orbitdb2) {
// await orbitdb2.stop()
// }
// if (ipfsd1) {
// await stopIpfs(ipfsd1)
// }
// if (ipfsd2) {
// await stopIpfs(ipfsd2)
// }
// })
// describe('OrbitDB Integration', function () {
// accessControllers.forEach(async (ac, i) => {
// let db, db2
// let dbManifest, acManifest, access
// let contract
// before(async () => {
// contract = await new web3.eth.Contract(ac.contract.abi)
// .deploy({ data: ac.contract.bytecode })
// .send({ from: accounts[i], gas: '1000000' })
// // DB creator needs to provide ac-type, abi and contract-address
// db = await orbitdb1.feed('AABB', {
// identity: id1,
// accessController: {
// type: ac.AccessController.type,
// web3: web3,
// abi: ac.contract.abi,
// contractAddress: contract._address,
// defaultAccount: accounts[i]
// },
// timeout: 1000
// })
// // DB peer needs to provide web3 instance
// db2 = await orbitdb2.feed(db.address, {
// identity: id2,
// accessController: {
// web3: web3,
// defaultAccount: accounts[(i + 1) % accessControllers.length] // peer owns different eth-account
// },
// timeout: 1000
// })
// await db2.load()
// dbManifest = await io.read(ipfs1, db.address.root)
// const hash = dbManifest.accessController.split('/').pop()
// acManifest = await io.read(ipfs1, hash)
// access = await io.read(ipfs1, acManifest.params.address)
// })
// it('makes database use the correct access controller', async () => {
// assert.strictEqual(access.contractAddress, db.access.address)
// })
// it('saves database manifest file locally', async () => {
// assert.notStrictEqual(dbManifest, null)
// })
// it('saves access controller manifest file locally', async () => {
// assert.notStrictEqual(acManifest, null)
// })
// describe('database manifest', () => {
// it('has correct name', async () => {
// assert.strictEqual(dbManifest.name, 'AABB')
// })
// it('has correct type', async () => {
// assert.strictEqual(dbManifest.type, 'feed')
// })
// it('has correct address', async () => {
// assert.notStrictEqual(dbManifest.accessController, null)
// assert.strictEqual(dbManifest.accessController.indexOf('/ipfs'), 0)
// })
// })
// describe('access controller manifest', () => {
// it('has correct type', async () => {
// assert.strictEqual(acManifest.type, ac.AccessController.type)
// })
// it('has correct address', async () => {
// assert.strictEqual(access.contractAddress.indexOf('0x'), 0)
// assert.strictEqual(access.contractAddress, db.access.address)
// })
// })
// describe('access controls', () => {
// it('throws error if key not permitted to write', async () => {
// let err
// try {
// await db.add('hello?') // should throw error
// assert.strictEqual('Should not end here', false)
// } catch (e) {
// err = e.toString()
// }
// assert.strictEqual(err, `Error: Could not append entry, key "${id1.id}" is not allowed to write to the log`)
// })
// it('granting access enables to write to the database', async () => {
// await db.access.grant('write', id1.id)
// const doChanges = () => {
// return new Promise((resolve, reject) => {
// try {
// db2.events.once('replicated', () => {
// // FIXME: timeout to get rid of the "libp2p node not started yet" errors
// setTimeout(() => resolve(), 1000)
// })
// db.add('hello!')
// } catch (e) {
// reject(e)
// }
// })
// }
// // Try adding something again
// await doChanges()
// const res1 = await db.iterator().collect().map(e => e.payload.value)
// const res2 = await db2.iterator().collect().map(e => e.payload.value)
// assert.deepStrictEqual(res1, ['hello!'])
// assert.deepStrictEqual(res2, ['hello!'])
// })
// it('can\'t grant access if not admin', async () => {
// await db2.access.grant('write', id2.id)
// const canAppend = await db2.access.canAppend({ identity: id2 }, id2.provider)
// assert.strictEqual(canAppend, false)
// })
// it('can\'t revoke access if not admin', async () => {
// await db2.access.revoke('write', id1.id)
// const canAppend = await db2.access.canAppend({ identity: id1 }, id1.provider)
// assert.strictEqual(canAppend, true)
// })
// it('can check permissions without defaultAccount set', async () => {
// db2.access.defaultAccount = null
// const canAppend = await db2.access.canAppend({ identity: id1 }, id1.provider)
// assert.strictEqual(canAppend, true)
// })
// it('can\'t change permissions without from address if no defaultAccount set', async () => {
// let err
// db2.access.defaultAccount = null
// try {
// await db2.access.grant('write', id2.id)
// } catch (e) {
// err = e.toString()
// }
// assert.strictEqual(err, 'Error: No "from" address specified in neither the given options, nor the default options.')
// })
// it('can change permissions by passing in from address', async () => {
// let err
// db2.access.defaultAccount = null
// try {
// await db2.access.grant('write', id2.id, { from: accounts[i] }) // from address can grant/revoke access
// } catch (e) {
// err = e.toString()
// }
// assert.strictEqual(err, undefined)
// const canAppend = await db2.access.canAppend({ identity: id2 }, id2.provider)
// assert.strictEqual(canAppend, true)
// })
// it('revoking access disables ability to write to the database', async () => {
// let err
// try {
// // Revoke user's access
// await db.access.revoke('write', id2.id)
// await db2.add('hello?')
// } catch (e) {
// err = e.toString()
// }
// assert.strictEqual(err, `Error: Could not append entry, key "${id2.id}" is not allowed to write to the log`)
// })
// })
// })
// })
// })
// })

View File

@ -1,183 +0,0 @@
// import assert from 'assert'
// import rmrf from 'rimraf'
// import OrbitDB from '../../src/OrbitDB.js'
// import IdentityProvider from 'orbit-db-identity-provider'
// import EthIdentityProvider from 'orbit-db-identity-provider/ethereum'
// import Keystore from 'orbit-db-keystore'
// import ContractAccessController from 'orbit-db-access-controllers/contract'
// import DepositContractAccessController from 'orbit-db-access-controllers/deposit-contract'
// import AccessControllers from 'orbit-db-access-controllers'
// import Web3 from 'web3'
// import ganache from 'ganache-cli'
// import * as io from 'orbit-db-io'
// import Access from './Access.json' assert { 'type': 'json' }
// import PayDeposit from './PayDeposit.json' assert { 'type': 'json' }
// // Include test utilities
// import {
// config,
// startIpfs,
// stopIpfs,
// testAPIs
// } from 'orbit-db-test-utils'
// const dbPath1 = './orbitdb/tests/contract-access-controller/1'
// const dbPath2 = './orbitdb/tests/contract-access-controller/2'
// const accessControllers = [
// {
// AccessController: ContractAccessController,
// contract: Access
// },
// {
// AccessController: DepositContractAccessController,
// contract: PayDeposit
// }
// ]
// Object.keys(testAPIs).forEach(API => {
// describe(`orbit-db - ContractAccessController (${API})`, function () {
// this.timeout(config.timeout)
// let ipfsd1, ipfsd2, ipfs1, ipfs2, id1, id2
// let orbitdb1, orbitdb2
// let web3, accounts
// before(async () => {
// rmrf.sync(dbPath1)
// rmrf.sync(dbPath2)
// ipfsd1 = await startIpfs(API, config.daemon1)
// ipfsd2 = await startIpfs(API, config.daemon2)
// ipfs1 = ipfsd1.api
// ipfs2 = ipfsd2.api
// const keystore1 = new Keystore(dbPath1 + '/keys')
// const keystore2 = new Keystore(dbPath2 + '/keys')
// IdentityProvider.addIdentityProvider(EthIdentityProvider)
// id1 = await IdentityProvider.createIdentity({ type: EthIdentityProvider.type, keystore: keystore1 })
// id2 = await IdentityProvider.createIdentity({ type: EthIdentityProvider.type, keystore: keystore2 })
// web3 = new Web3(ganache.provider())
// accounts = await web3.eth.getAccounts()
// orbitdb1 = await OrbitDB.createInstance(ipfs1, {
// AccessControllers: AccessControllers,
// directory: dbPath1,
// identity: id1
// })
// orbitdb2 = await OrbitDB.createInstance(ipfs2, {
// AccessControllers: AccessControllers,
// directory: dbPath2,
// identity: id2
// })
// })
// after(async () => {
// if (orbitdb1) {
// await orbitdb1.stop()
// }
// if (orbitdb2) {
// await orbitdb2.stop()
// }
// if (ipfsd1) {
// await stopIpfs(ipfsd1)
// }
// if (ipfsd2) {
// await stopIpfs(ipfsd2)
// }
// })
// describe('Constructor', function () {
// accessControllers.forEach(async (ac, i) => {
// let accessController, contract
// before(async () => {
// contract = await new web3.eth.Contract(ac.contract.abi)
// .deploy({ data: ac.contract.bytecode })
// .send({ from: accounts[i], gas: '1000000' })
// accessController = await ac.AccessController.create(orbitdb1, {
// type: ac.AccessController.type,
// web3: web3,
// abi: ac.contract.abi,
// contractAddress: contract._address,
// defaultAccount: accounts[i]
// })
// await accessController.load()
// })
// it('creates an access controller', () => {
// assert.notStrictEqual(accessController, null)
// assert.notStrictEqual(accessController, undefined)
// })
// it('sets the controller type', () => {
// assert.strictEqual(accessController.type, ac.AccessController.type)
// })
// it('grants access to key', async () => {
// const mockEntry = {
// identity: id1
// // ...
// // doesn't matter what we put here, only identity is used for the check
// }
// await accessController.grant('write', id1.id)
// const canAppend = await accessController.canAppend(mockEntry, id1.provider)
// assert.strictEqual(canAppend, true)
// })
// it('grants access to multiple keys', async () => {
// const canAppend1 = await accessController.canAppend({ identity: orbitdb1.identity }, orbitdb1.identity.provider)
// const canAppend2 = await accessController.canAppend({ identity: orbitdb2.identity }, orbitdb2.identity.provider)
// await accessController.grant('write', orbitdb2.identity.id)
// const canAppend3 = await accessController.canAppend({ identity: orbitdb2.identity }, orbitdb2.identity.provider)
// assert.strictEqual(canAppend1, true)
// assert.strictEqual(canAppend2, false)
// assert.strictEqual(canAppend3, true)
// })
// describe('save and load', function () {
// let accessController, manifest
// before(async () => {
// accessController = await ac.AccessController.create(orbitdb1, {
// type: ac.AccessController.type,
// web3: web3,
// abi: ac.contract.abi,
// contractAddress: contract._address,
// defaultAccount: accounts[i]
// })
// manifest = await accessController.save()
// const access = await io.read(ipfs1, manifest.address)
// accessController = await ac.AccessController.create(orbitdb1, {
// type: ac.AccessController.type,
// web3: web3,
// abi: JSON.parse(access.abi),
// contractAddress: access.contractAddress,
// defaultAccount: accounts[i]
// })
// await accessController.load(manifest.address)
// })
// it('has correct capabalities', async () => {
// const canAppend1 = await accessController.canAppend({ identity: orbitdb1.identity }, orbitdb1.identity.provider)
// const canAppend2 = await accessController.canAppend({ identity: orbitdb2.identity }, orbitdb2.identity.provider)
// const canAppend3 = await accessController.canAppend({ identity: { id: 'someotherid' } }, orbitdb1.identity.provider)
// assert.strictEqual(canAppend1, true)
// assert.strictEqual(canAppend2, true)
// assert.strictEqual(canAppend3, false)
// })
// })
// })
// })
// })
// })

View File

@ -1,159 +0,0 @@
// import assert from 'assert'
// import rmrf from 'rimraf'
// import OrbitDB from '../../src/orbitdb.js'
// import IdentityProvider from 'orbit-db-identity-provider'
// import Keystore from 'orbit-db-keystore'
// import AccessControllers from 'orbit-db-access-controllers'
// import * as io from 'orbit-db-io'
// // Include test utilities
// import {
// config,
// startIpfs,
// stopIpfs,
// testAPIs,
// connectPeers
// } from 'orbit-db-test-utils'
// const dbPath1 = './orbitdb/tests/orbitdb-access-controller-integration/1'
// const dbPath2 = './orbitdb/tests/orbitdb-access-controller-integration/2'
// Object.keys(testAPIs).forEach(API => {
// describe(`orbit-db - IPFSAccessController Integration (${API})`, function () {
// this.timeout(config.timeout)
// let ipfsd1, ipfsd2, ipfs1, ipfs2, id1, id2
// let orbitdb1, orbitdb2
// before(async () => {
// rmrf.sync(dbPath1)
// rmrf.sync(dbPath2)
// ipfsd1 = await startIpfs(API, config.daemon1)
// ipfsd2 = await startIpfs(API, config.daemon2)
// ipfs1 = ipfsd1.api
// ipfs2 = ipfsd2.api
// // Connect the peers manually to speed up test times
// const isLocalhostAddress = (addr) => addr.toString().includes('127.0.0.1')
// await connectPeers(ipfs1, ipfs2, { filter: isLocalhostAddress })
// const keystore1 = new Keystore(dbPath1 + '/keys')
// const keystore2 = new Keystore(dbPath2 + '/keys')
// id1 = await IdentityProvider.createIdentity({ id: 'A', keystore: keystore1 })
// id2 = await IdentityProvider.createIdentity({ id: 'B', keystore: keystore2 })
// orbitdb1 = await OrbitDB.createInstance(ipfs1, {
// AccessControllers,
// directory: dbPath1,
// identity: id1
// })
// orbitdb2 = await OrbitDB.createInstance(ipfs2, {
// AccessControllers,
// directory: dbPath2,
// identity: id2
// })
// })
// after(async () => {
// if (orbitdb1) { await orbitdb1.stop() }
// if (orbitdb2) { await orbitdb2.stop() }
// if (ipfsd1) { await stopIpfs(ipfsd1) }
// if (ipfsd2) { await stopIpfs(ipfsd2) }
// })
// describe('OrbitDB Integration', function () {
// let db, db2
// let dbManifest, acManifest
// before(async () => {
// db = await orbitdb1.feed('AABB', {
// identity: id1,
// accessController: {
// type: 'ipfs',
// write: [id1.id]
// }
// })
// db2 = await orbitdb2.feed(db.address, {
// identity: id2
// })
// await db2.load()
// dbManifest = await io.read(ipfs1, db.address.root)
// const hash = dbManifest.accessController.split('/').pop()
// acManifest = await io.read(ipfs1, hash)
// })
// it('has the correct access rights after creating the database', async () => {
// assert.deepStrictEqual(db.access.write, [id1.id])
// })
// it('makes database use the correct access controller', async () => {
// const { address } = await db.access.save()
// assert.strictEqual(acManifest.params.address, address)
// })
// it('saves database manifest file locally', async () => {
// assert.notStrictEqual(dbManifest, null)
// })
// it('saves access controller manifest file locally', async () => {
// assert.notStrictEqual(acManifest, null)
// })
// it('has correct type', async () => {
// assert.strictEqual(acManifest.type, 'ipfs')
// })
// describe('database manifest', () => {
// it('has correct name', async () => {
// assert.strictEqual(dbManifest.name, 'AABB')
// })
// it('has correct type', async () => {
// assert.strictEqual(dbManifest.type, 'feed')
// })
// it('has correct address', async () => {
// assert.notStrictEqual(dbManifest.accessController, null)
// assert.strictEqual(dbManifest.accessController.indexOf('/ipfs'), 0)
// })
// })
// describe('access controls', () => {
// it('allows to write if user has write access', async () => {
// let err
// try {
// await db.add('hello?')
// } catch (e) {
// err = e.toString()
// }
// const res = await db.iterator().collect().map(e => e.payload.value)
// assert.strictEqual(err, undefined)
// assert.deepStrictEqual(res, ['hello?'])
// })
// it('doesn\'t allow to write without write access', async () => {
// let err
// try {
// await db2.add('hello!!')
// assert.strictEqual('Should not end here', false)
// } catch (e) {
// err = e
// }
// const res = await db2.iterator().collect().map(e => e.payload.value)
// assert.strictEqual(err.message, `Could not append entry, key "${db2.identity.id}" is not allowed to write to the log`)
// assert.deepStrictEqual(res.includes(e => e === 'hello!!'), false)
// })
// })
// })
// })
// // TODO: use two separate peers for testing the AC
// // TODO: add tests for revocation correctness with a database (integration tests)
// })

View File

@ -1,231 +0,0 @@
// import assert from 'assert'
// import rmrf from 'rimraf'
// import OrbitDB from '../../src/orbitdb.js'
// import IdentityProvider from 'orbit-db-identity-provider'
// import Keystore from 'orbit-db-keystore'
// import AccessControllers from 'orbit-db-access-controllers'
// import * as io from 'orbit-db-io'
// // Include test utilities
// import {
// config,
// startIpfs,
// stopIpfs,
// testAPIs,
// connectPeers
// } from 'orbit-db-test-utils'
// const dbPath1 = './orbitdb/tests/orbitdb-access-controller-integration/1'
// const dbPath2 = './orbitdb/tests/orbitdb-access-controller-integration/2'
// Object.keys(testAPIs).forEach(API => {
// describe(`orbit-db - OrbitDBAccessController Integration (${API})`, function () {
// this.timeout(config.timeout)
// let ipfsd1, ipfsd2, ipfs1, ipfs2, id1, id2
// let orbitdb1, orbitdb2
// before(async () => {
// rmrf.sync(dbPath1)
// rmrf.sync(dbPath2)
// ipfsd1 = await startIpfs(API, config.daemon1)
// ipfsd2 = await startIpfs(API, config.daemon2)
// ipfs1 = ipfsd1.api
// ipfs2 = ipfsd2.api
// // Connect the peers manually to speed up test times
// const isLocalhostAddress = (addr) => addr.toString().includes('127.0.0.1')
// await connectPeers(ipfs1, ipfs2, { filter: isLocalhostAddress })
// const keystore1 = new Keystore(dbPath1 + '/keys')
// const keystore2 = new Keystore(dbPath2 + '/keys')
// id1 = await IdentityProvider.createIdentity({ id: 'A', keystore: keystore1 })
// id2 = await IdentityProvider.createIdentity({ id: 'B', keystore: keystore2 })
// orbitdb1 = await OrbitDB.createInstance(ipfs1, {
// AccessControllers,
// directory: dbPath1,
// identity: id1
// })
// orbitdb2 = await OrbitDB.createInstance(ipfs2, {
// AccessControllers,
// directory: dbPath2,
// identity: id2
// })
// })
// after(async () => {
// if (orbitdb1) {
// await orbitdb1.stop()
// }
// if (orbitdb2) {
// await orbitdb2.stop()
// }
// if (ipfsd1) {
// await stopIpfs(ipfsd1)
// }
// if (ipfsd2) {
// await stopIpfs(ipfsd2)
// }
// })
// describe('OrbitDB Integration', function () {
// let db, db2
// let dbManifest, acManifest
// before(async () => {
// db = await orbitdb1.feed('AABB', {
// identity: id1,
// accessController: {
// type: 'orbitdb',
// write: [id1.id]
// }
// })
// db2 = await orbitdb2.feed(db.address, { identity: id2 })
// await db2.load()
// dbManifest = await io.read(ipfs1, db.address.root)
// const hash = dbManifest.accessController.split('/').pop()
// acManifest = await io.read(ipfs1, hash)
// })
// it('has the correct access rights after creating the database', async () => {
// assert.deepStrictEqual(db.access.capabilities, {
// admin: new Set([id1.id]),
// write: new Set([id1.id])
// })
// })
// it('makes database use the correct access controller', async () => {
// assert.strictEqual(acManifest.params.address, db.access._db.address.toString())
// })
// it('saves database manifest file locally', async () => {
// assert.notStrictEqual(dbManifest, null)
// })
// it('saves access controller manifest file locally', async () => {
// assert.notStrictEqual(acManifest, null)
// })
// describe('database manifest', () => {
// it('has correct name', async () => {
// assert.strictEqual(dbManifest.name, 'AABB')
// })
// it('has correct type', async () => {
// assert.strictEqual(dbManifest.type, 'feed')
// })
// it('has correct address', async () => {
// assert.notStrictEqual(dbManifest.accessController, null)
// assert.strictEqual(dbManifest.accessController.indexOf('/ipfs'), 0)
// })
// })
// describe('access controller manifest', () => {
// it('has correct type', async () => {
// assert.strictEqual(acManifest.type, 'orbitdb')
// })
// it('has correct address', async () => {
// assert.strictEqual(acManifest.params.address.indexOf('/orbitdb'), 0)
// assert.strictEqual(acManifest.params.address.split('/').pop(), '_access')
// })
// })
// describe('access controls', () => {
// it('granting access enables to write to the database', async () => {
// let err
// try {
// await db2.add('hello?')
// assert.strictEqual('Should not end here', false)
// } catch (e) {
// err = e.toString()
// }
// assert.strictEqual(err, `Error: Could not append entry, key "${db2.identity.id}" is not allowed to write to the log`)
// const doChanges = () => {
// return new Promise((resolve, reject) => {
// try {
// // Wait for the second user's AC to notify it was updated
// db2.access.once('updated', async () => {
// // Wait for the first user's db to replicate the update
// db.events.once('replicated', () => {
// // FIXME: timeout to get rid of the "libp2p node not started yet" errors
// setTimeout(() => resolve(), 1000)
// })
// // Try adding something again
// await db2.add('hello!')
// })
// // Give access to the second user
// db.access.grant('write', id2.id)
// } catch (e) {
// reject(e)
// }
// })
// }
// await doChanges()
// const res1 = await db.iterator().collect().map(e => e.payload.value)
// const res2 = await db2.iterator().collect().map(e => e.payload.value)
// assert.deepStrictEqual(res1, ['hello!'])
// assert.deepStrictEqual(res2, ['hello!'])
// })
// it('can\'t grant access if doesn\'t have write access', async () => {
// let err
// try {
// await db2.access.grant('write', id2.id)
// } catch (e) {
// err = e.toString()
// }
// assert.strictEqual(err, `Error: Could not append entry, key "${db2.identity.id}" is not allowed to write to the log`)
// })
// it('can\'t revoke access if doesn\'t have write access', async () => {
// let err
// try {
// await db2.access.revoke('write', id1.id)
// } catch (e) {
// err = e.toString()
// }
// assert.strictEqual(err, `Error: Could not append entry, key "${db2.identity.id}" is not allowed to write to the log`)
// })
// it('revoking access disables ability to write to the database', async () => {
// const getError = () => {
// return new Promise((resolve, reject) => {
// try {
// // Wait for the second user's AC to notify it was updated
// db2.access.once('updated', async () => {
// let err
// try {
// // Try adding something again
// await db2.add('hello?')
// } catch (e) {
// err = e.toString()
// }
// resolve(err)
// })
// // Revoke user's access
// db.access.revoke('write', id2.id)
// } catch (e) {
// reject(e)
// }
// })
// }
// const err = await getError()
// assert.strictEqual(err, `Error: Could not append entry, key "${db2.identity.id}" is not allowed to write to the log`)
// })
// })
// })
// })
// // TODO: use two separate peers for testing the AC
// // TODO: add tests for revocation correctness with a database (integration tests)
// })

View File

@ -32,8 +32,8 @@ describe('OrbitDBAccessController', function () {
testIdentity1 = await identities1.createIdentity({ id: 'userA' })
testIdentity2 = await identities2.createIdentity({ id: 'userB' })
orbitdb1 = await OrbitDB({ ipfs: ipfs1, identity: testIdentity1, directory: dbPath1, keystore: keystore1 })
orbitdb2 = await OrbitDB({ ipfs: ipfs2, identity: testIdentity2, directory: dbPath2, keystore: keystore2 })
orbitdb1 = await OrbitDB({ ipfs: ipfs1, identities: identities1, id: 'userA', directory: dbPath1 })
orbitdb2 = await OrbitDB({ ipfs: ipfs2, identities: identities2, id: 'userB', directory: dbPath2 })
})
after(async () => {

View File

@ -1,130 +0,0 @@
// 'use strict'
// import assert from 'assert'
// import puppeteer from 'puppeteer-core'
// import chromium from 'chromium'
// import path from 'path'
// import mapSeries from 'p-map-series'
// import pMap from 'p-map'
// import { config } from 'orbit-db-test-utils'
// const clicksPerTab = 20
// const numTabs = 3
// const wait = async (milliseconds) => {
// return new Promise((resolve, reject) => {
// console.log('waiting...')
// setTimeout(resolve, milliseconds)
// })
// }
// describe('orbit-db - browser concurrent writes', function () {
// this.timeout(numTabs * config.timeout)
// let browser
// const options = {
// ignoreHTTPSErrors: true,
// dumpio: true,
// args: ['--no-sandbox', '--disable-setuid-sandbox'],
// executablePath: chromium.path
// }
// before(async () => {
// browser = await puppeteer.launch(options)
// })
// after(async () => {
// await browser.close()
// })
// describe('Write concurrently', function () {
// const tabs = []
// before(async () => {
// const createTab = async () => {
// const page = await browser.newPage()
// await page.goto(`file://${path.resolve('test/browser/index.html')}`)
// page.on('dialog', dialog => dialog.dismiss())
// page.on('pageerror', err => console.error(err))
// page.on('console', message => console.log(message))
// await wait(1000)
// return page
// }
// // open several tabs
// for (let i = 0; i < numTabs; i++) {
// const tab = await createTab()
// tabs.push(tab)
// }
// const addDataButton = 'button#addData'
// await pMap(tabs, async (page) => {
// await page.waitForFunction(
// 'document.querySelector("#waitForOpenDB").innerText.includes("orbitdb")'
// )
// const addDataToLog = (maxClicks, maxWaitTime) => {
// let count = 0
// const repeat = () => new Promise((resolve, reject) => {
// setTimeout(async () => {
// await page.click(addDataButton)
// if (++count < maxClicks) {
// await repeat()
// }
// resolve()
// }, Math.random() * maxWaitTime + 300) // ensure waiting at least ~300ms
// })
// return repeat()
// }
// return addDataToLog(clicksPerTab, 1000)
// })
// })
// it('syncLocal option - Multiple tabs converge to same log', async () => {
// return new Promise((resolve, reject) => {
// let polls = 0
// const interval = setInterval(async () => {
// const logHashes = []
// await mapSeries(tabs, async (page) => {
// await page.evaluate(() => loadConsistentLog())
// const hash = await page.evaluate(async () => await getConsistentLogHash())
// logHashes.push(hash)
// })
// try {
// const hashes = Array.from(new Set(logHashes))
// // ensure log hashes are equal
// assert.strictEqual(hashes.length, 1)
// clearInterval(interval)
// resolve()
// } catch (e) {
// console.log('Repolling...')
// if (++polls > 5) {
// reject(e)
// }
// }
// }, 3000)
// })
// })
// it('no syncLocal option - Multiple tabs do not converge to same log', async () => {
// return new Promise((resolve, reject) => {
// const interval = setInterval(async () => {
// const logHashes = []
// await mapSeries(tabs, async (page) => {
// const hash = await page.evaluate(async () => await getInconsistentLogHash())
// logHashes.push(hash)
// })
// try {
// const hashes = Array.from(new Set(logHashes))
// // logs hash different hashes
// assert.strictEqual(hashes.length, numTabs)
// clearInterval(interval)
// resolve()
// } catch (e) {
// reject(e)
// }
// }, 3000)
// })
// })
// })
// })

View File

@ -1,28 +0,0 @@
// import path from 'path'
// import isNode from 'is-node'
// // This file will be picked up by webpack into the
// // tests bundle and the code here gets run when imported
// // into the browser tests index through browser/run.js
// if (!isNode) {
// const existingKey = (await import('./fixtures/keys/existing.json')).default
// const testKey1 = (await import('./fixtures/keys/QmPhnEjVkYE1Ym7F5MkRUfkD6NtuSptE7ugu1Ggr149W2X.json')).default
// const testKey2 = (await import('./fixtures/keys/0260baeaffa1de1e4135e5b395e0380563a622b9599d1b8e012a0f7603f516bdaa.json')).default
// // If in browser, put the fixture keys in local storage
// // so that Keystore can find them
// const levelup = (await import('levelup')).default
// const level = (await import('level-js')).default
// const storagePath = path.resolve('./test/fixtures/savedKeys')
// const signingStore = levelup(level(storagePath))
// const copyFixtures = []
// copyFixtures.push(signingStore)
// /* global localStorage */
// copyFixtures.push(localStorage.setItem('existing.json', JSON.stringify(existingKey)))
// copyFixtures.push(signingStore.put('QmPhnEjVkYE1Ym7F5MkRUfkD6NtuSptE7ugu1Ggr149W2X', JSON.stringify(testKey1)))
// copyFixtures.push(signingStore.put('0260baeaffa1de1e4135e5b395e0380563a622b9599d1b8e012a0f7603f516bdaa', JSON.stringify(testKey2)))
// Promise.all(copyFixtures)
// }

View File

@ -1,21 +0,0 @@
<html>
<head>
<meta charset="utf-8">
<title>Mocha Tests</title>
<link href="https://unpkg.com/mocha@4.0.1/mocha.css" rel="stylesheet" />
<script src="https://unpkg.com/mocha@5.2.0/mocha.js"></script>
</head>
<body>
<div id="mocha"></div>
<script>
mocha.setup("bdd");
</script>
<script src="./bundle.js"></script>
<script>
mocha.checkLeaks()
mocha.run();
</script>
</body>
</html>

View File

@ -1,158 +0,0 @@
// import assert from 'assert'
// import rmrf from 'rimraf'
// import KeyStore, { signMessage, verifyMessage } from '../../src/key-store.js'
// import Identities, { addIdentityProvider } from '../../src/identities/identities.js'
// import Identity from '../../src/identities/identity.js'
// import { Ed25519Provider } from 'key-did-provider-ed25519'
// import KeyDidResolver from 'key-did-resolver'
// import DIDIdentityProvider from '../../src/identities/providers/did.js'
// const seed = new Uint8Array([157, 94, 116, 198, 19, 248, 93, 239, 173, 82, 245, 222, 199, 7, 183, 177, 123, 238, 83, 240, 143, 188, 87, 191, 33, 95, 58, 136, 46, 218, 219, 245])
// const didStr = 'did:key:z6MkpnTJwrrVuphNh1uKb5DB7eRxvqniVaSDUHU6jtGVmn3r'
// const type = DIDIdentityProvider.type
// describe('DID Identity Provider', function () {
// let keystore
// let identities
// before(async () => {
// keystore = await KeyStore()
// DIDIdentityProvider.setDIDResolver(KeyDidResolver.getResolver())
// addIdentityProvider(DIDIdentityProvider)
// identities = await Identities({ keystore })
// })
// after(async () => {
// if (keystore) {
// await keystore.close()
// }
// rmrf.sync('./keystore')
// rmrf.sync('./orbitdb')
// })
// describe('create an DID identity', () => {
// let identity
// before(async () => {
// const didProvider = new Ed25519Provider(seed)
// identity = await identities.createIdentity({ type, keystore, didProvider })
// })
// it('has the correct id', async () => {
// assert.strictEqual(identity.id, didStr)
// })
// it('created a key for id in keystore', async () => {
// const key = await keystore.getKey(didStr)
// assert.notStrictEqual(key, undefined)
// })
// it('has the correct public key', async () => {
// const signingKey = await keystore.getKey(didStr)
// assert.notStrictEqual(signingKey, undefined)
// assert.strictEqual(identity.publicKey, keystore.getPublic(signingKey))
// })
// it('has a signature for the id', async () => {
// const signingKey = await keystore.getKey(didStr)
// const idSignature = await signMessage(signingKey, didStr)
// const verifies = await verifyMessage(idSignature, identity.publicKey, didStr)
// assert.strictEqual(verifies, true)
// assert.strictEqual(identity.signatures.id, idSignature)
// })
// it('has a signature for the publicKey', async () => {
// const signingKey = await keystore.getKey(didStr)
// const idSignature = await signMessage(signingKey, didStr)
// assert.notStrictEqual(idSignature, undefined)
// })
// })
// describe('verify identity', () => {
// let identity
// before(async () => {
// const didProvider = new Ed25519Provider(seed)
// identity = await identities.createIdentity({ type, keystore, didProvider })
// })
// it('DID identity verifies', async () => {
// const verified = await identities.verifyIdentity(identity)
// assert.strictEqual(verified, true)
// })
// it('DID identity with incorrect id does not verify', async () => {
// const { publicKey, signatures, type } = identity
// const identity2 = await Identity({
// id: 'NotAnId',
// publicKey,
// signatures,
// type
// })
// const verified = await identities.verifyIdentity(identity2)
// assert.strictEqual(verified, false)
// })
// })
// describe('sign data with an identity', () => {
// let identity
// const data = 'hello friend'
// before(async () => {
// const didProvider = new Ed25519Provider(seed)
// identity = await identities.createIdentity({ type, keystore, didProvider })
// })
// it('sign data', async () => {
// const signingKey = await keystore.getKey(identity.id)
// const expectedSignature = await signMessage(signingKey, data)
// const signature = await identities.sign(identity, data, keystore)
// assert.strictEqual(signature, expectedSignature)
// })
// it('throws an error if private key is not found from keystore', async () => {
// // Remove the key from the keystore (we're using a mock storage in these tests)
// const { publicKey, signatures, type } = identity
// const modifiedIdentity = await Identity({
// id: 'this id does not exist',
// publicKey,
// signatures: {
// id: '<sig>',
// publicKey: signatures.publicKey
// },
// type
// })
// let signature
// let err
// try {
// signature = await identities.sign(modifiedIdentity, data, keystore)
// } catch (e) {
// err = e.toString()
// }
// assert.strictEqual(signature, undefined)
// assert.strictEqual(err, 'Error: Private signing key not found from KeyStore')
// })
// describe('verify data signed by an identity', () => {
// const data = 'hello friend'
// let identity
// let signature
// before(async () => {
// const didProvider = new Ed25519Provider(seed)
// identity = await identities.createIdentity({ type, keystore, didProvider })
// signature = await identities.sign(identity, data, keystore)
// })
// it('verifies that the signature is valid', async () => {
// const verified = await identities.verify(signature, identity.publicKey, data)
// assert.strictEqual(verified, true)
// })
// it('doesn\'t verify invalid signature', async () => {
// const verified = await identities.verify('invalid', identity.publicKey, data)
// assert.strictEqual(verified, false)
// })
// })
// })
// })

View File

@ -1,154 +0,0 @@
// import assert from 'assert'
// import rmrf from 'rimraf'
// import KeyStore, { signMessage, verifyMessage } from '../../src/key-store.js'
// import Identities, { addIdentityProvider } from '../../src/identities/identities.js'
// import Identity from '../../src/identities/identity.js'
// import EthIdentityProvider from '../../src/identities/providers/ethereum.js'
// const type = EthIdentityProvider.type
// describe('Ethereum Identity Provider', function () {
// let keystore
// let identities
// before(async () => {
// keystore = await KeyStore()
// addIdentityProvider(EthIdentityProvider)
// identities = await Identities({ keystore })
// })
// after(async () => {
// if (keystore) {
// await keystore.close()
// }
// rmrf.sync('./keystore')
// rmrf.sync('./orbitdb')
// })
// describe('create an ethereum identity', () => {
// let identity
// let wallet
// before(async () => {
// const ethIdentityProvider = new EthIdentityProvider()
// wallet = await ethIdentityProvider._createWallet()
// identity = await identities.createIdentity({ type, keystore, wallet })
// })
// it('has the correct id', async () => {
// assert.strictEqual(identity.id, wallet.address)
// })
// it('created a key for id in keystore', async () => {
// const key = await keystore.getKey(wallet.address)
// assert.notStrictEqual(key, undefined)
// })
// it('has the correct public key', async () => {
// const signingKey = await keystore.getKey(wallet.address)
// assert.notStrictEqual(signingKey, undefined)
// assert.strictEqual(identity.publicKey, keystore.getPublic(signingKey))
// })
// it('has a signature for the id', async () => {
// const signingKey = await keystore.getKey(wallet.address)
// const idSignature = await signMessage(signingKey, wallet.address)
// const verifies = await verifyMessage(idSignature, Buffer.from(signingKey.public.marshal()).toString('hex'), wallet.address)
// assert.strictEqual(verifies, true)
// assert.strictEqual(identity.signatures.id, idSignature)
// })
// it('has a signature for the publicKey', async () => {
// const signingKey = await keystore.getKey(wallet.address)
// const idSignature = await signMessage(signingKey, wallet.address)
// const publicKeyAndIdSignature = await wallet.signMessage(identity.publicKey + idSignature)
// assert.strictEqual(identity.signatures.publicKey, publicKeyAndIdSignature)
// })
// })
// describe('verify identity', () => {
// let identity
// before(async () => {
// identity = await identities.createIdentity({ keystore, type })
// })
// it('ethereum identity verifies', async () => {
// const verified = await identities.verifyIdentity(identity)
// assert.strictEqual(verified, true)
// })
// it('ethereum identity with incorrect id does not verify', async () => {
// const { publicKey, signatures, type } = identity
// const identity2 = await Identity({
// id: 'NotAnId',
// publicKey,
// signatures,
// type
// })
// const verified = await identities.verifyIdentity(identity2)
// assert.strictEqual(verified, false)
// })
// })
// describe('sign data with an identity', () => {
// let identity
// const data = 'hello friend'
// before(async () => {
// identity = await identities.createIdentity({ keystore, type })
// })
// it('sign data', async () => {
// const signingKey = await keystore.getKey(identity.id)
// const expectedSignature = await signMessage(signingKey, data)
// const signature = await identities.sign(identity, data, keystore)
// assert.strictEqual(signature, expectedSignature)
// })
// it('throws an error if private key is not found from keystore', async () => {
// // Remove the key from the keystore (we're using a mock storage in these tests)
// const { publicKey, signatures, type } = identity
// const modifiedIdentity = await Identity({
// id: 'this id does not exist',
// publicKey,
// signatures: {
// id: '<sig>',
// publicKey: signatures.publicKey
// },
// type
// })
// let signature
// let err
// try {
// signature = await identities.sign(modifiedIdentity, data, keystore)
// } catch (e) {
// err = e.toString()
// }
// assert.strictEqual(signature, undefined)
// assert.strictEqual(err, 'Error: Private signing key not found from KeyStore')
// })
// describe('verify data signed by an identity', () => {
// const data = 'hello friend'
// let identity
// let signature
// before(async () => {
// identity = await identities.createIdentity({ type, keystore })
// signature = await identities.sign(identity, data, keystore)
// })
// it('verifies that the signature is valid', async () => {
// const verified = await identities.verify(signature, identity.publicKey, data)
// assert.strictEqual(verified, true)
// })
// it('doesn\'t verify invalid signature', async () => {
// const verified = await identities.verify('invalid', identity.publicKey, data)
// assert.strictEqual(verified, false)
// })
// })
// })
// })