Skip to content
Next
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Switch to GitLab Next
Sign in / Register
Toggle navigation
T
t3
Project
Project
Details
Activity
Releases
Cycle Analytics
Insights
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Security & Compliance
Security & Compliance
Dependency List
Packages
Packages
List
Container Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Minds
t3
Commits
97502083
Commit
97502083
authored
24 minutes ago
by
Mark Harding
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
(feat): working trust contract
parent
31d733e7
master
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
145 additions
and
20 deletions
+145
-20
Trust.sol
blockchain/contracts/Trust.sol
+60
-0
package-lock.json
blockchain/package-lock.json
+11
-0
trust.js
blockchain/test/trust.js
+57
-0
truffle-config.js
blockchain/truffle-config.js
+17
-20
No files found.
blockchain/contracts/Trust.sol
0 → 100644
View file @
97502083
pragma solidity >=0.4.21 <0.6.0;
import '../node_modules/ethr-did-registry/contracts/EthereumDIDRegistry.sol';
contract Trust {
EthereumDIDRegistry didRegistry;
struct TrustScore {
address from;
address to;
int8 score;
}
mapping(address => mapping(address => TrustScore)) public scores;
constructor(address didRegistryAddress) public {
didRegistry = EthereumDIDRegistry(didRegistryAddress);
}
// Test function REMOVE THIS
function sayHello() public view returns (string) {
return "hello";
}
function issueTrustViaDelegate(address from, address to, int8 score) public returns (bool) {
bool validated = didRegistry.validDelegate(from, 'DID-JWT', msg.sender);
require(validated);
_issueTrust(from, to, score);
}
function issueTrust(address to, int8 score) {
require(didRegistry.identityOwner(msg.sender) == msg.sender);
_issueTrust(msg.sender, to, score);
}
/**
* Issue trust (internal)
* @param from address
* @param to address
* @param score int8
* @return bool
*/
function _issueTrust(address from, address to, int8 score) internal returns (bool) {
TrustScore memory _trustScore = TrustScore(
from,
to,
score
);
scores[from][to] = _trustScore;
return true;
}
function getTrust(address from, address to) public view returns (int8) {
return scores[from][to].score;
}
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
blockchain/package-lock.json
0 → 100644
View file @
97502083
{
"requires"
:
true
,
"lockfileVersion"
:
1
,
"dependencies"
:
{
"ethr-did-registry"
:
{
"version"
:
"0.0.3"
,
"resolved"
:
"https://registry.npmjs.org/ethr-did-registry/-/ethr-did-registry-0.0.3.tgz"
,
"integrity"
:
"sha512-4BPvMGkxAK9vTduCq6D5b8ZqjteD2cvDIPPriXP6nnmPhWKFSxypo+AFvyQ0omJGa0cGTR+dkdI/8jiF7U/qaw=="
}
}
}
This diff is collapsed.
Click to expand it.
blockchain/test/trust.js
0 → 100644
View file @
97502083
const
Trust
=
artifacts
.
require
(
"
Trust
"
);
const
EthereumDIDRegistry
=
artifacts
.
require
(
"
EthereumDIDRegistry
"
);
contract
(
"
Trust
"
,
accounts
=>
{
let
trust
;
let
didRegistry
;
beforeEach
(
async
()
=>
{
didRegistry
=
await
EthereumDIDRegistry
.
new
();
trust
=
await
Trust
.
new
(
didRegistry
.
address
);
});
it
(
"
should say hello
"
,
async
()
=>
{
const
say
=
await
trust
.
sayHello
.
call
();
assert
.
equal
(
say
,
"
hello
"
);
});
it
(
"
should issue trust score
"
,
async
()
=>
{
await
trust
.
issueTrust
(
accounts
[
2
],
1
);
assert
.
equal
(
await
trust
.
getTrust
(
accounts
[
0
],
accounts
[
2
]),
1
);
});
it
(
"
should issue a negative trust score
"
,
async
()
=>
{
await
trust
.
issueTrust
(
accounts
[
3
],
-
1
);
assert
.
equal
(
await
trust
.
getTrust
(
accounts
[
0
],
accounts
[
3
]),
-
1
);
});
it
(
"
should issue multiple trust scores
"
,
async
()
=>
{
await
trust
.
issueTrust
(
accounts
[
2
],
1
);
await
trust
.
issueTrust
(
accounts
[
3
],
1
);
await
trust
.
issueTrust
(
accounts
[
4
],
-
1
);
await
trust
.
issueTrust
(
accounts
[
5
],
-
1
);
assert
.
equal
(
await
trust
.
getTrust
(
accounts
[
0
],
accounts
[
2
]),
1
);
assert
.
equal
(
await
trust
.
getTrust
(
accounts
[
0
],
accounts
[
3
]),
1
);
assert
.
equal
(
await
trust
.
getTrust
(
accounts
[
0
],
accounts
[
4
]),
-
1
);
assert
.
equal
(
await
trust
.
getTrust
(
accounts
[
0
],
accounts
[
5
]),
-
1
);
});
it
(
"
should issue trust score via a delegate
"
,
async
()
=>
{
// accounts[1] is the identity
// accounts[1] is also the owner
// accounts[2] will become the delegate
await
didRegistry
.
addDelegate
(
accounts
[
1
],
web3
.
utils
.
fromAscii
(
"
DID-JWT
"
),
accounts
[
2
],
86400
*
365
,
{
from
:
accounts
[
1
]
}
);
await
trust
.
issueTrustViaDelegate
(
accounts
[
1
],
accounts
[
3
],
1
,
{
from
:
accounts
[
2
]
});
assert
.
equal
(
await
trust
.
getTrust
(
accounts
[
1
],
accounts
[
3
]),
1
);
});
});
This diff is collapsed.
Click to expand it.
blockchain/truffle-config.js
View file @
97502083
...
...
@@ -47,33 +47,30 @@ module.exports = {
// port: 8545, // Standard Ethereum port (default: none)
// network_id: "*", // Any network (default: none)
// },
// Another network with more advanced options...
// advanced: {
// port: 8777, // Custom port
// network_id: 1342, // Custom network
// gas: 8500000, // Gas sent with each transaction (default: ~6700000)
// gasPrice: 20000000000, // 20 gwei (in wei) (default: 100 gwei)
// from: <address>, // Account to send txs from (default: accounts[0])
// websockets: true // Enable EventEmitter interface for web3 (default: false)
// port: 8777, // Custom port
// network_id: 1342, // Custom network
// gas: 8500000, // Gas sent with each transaction (default: ~6700000)
// gasPrice: 20000000000, // 20 gwei (in wei) (default: 100 gwei)
// from: <address>, // Account to send txs from (default: accounts[0])
// websockets: true // Enable EventEmitter interface for web3 (default: false)
// },
// Useful for deploying to a public network.
// NB: It's important to wrap the provider as a function.
// ropsten: {
// provider: () => new HDWalletProvider(mnemonic, `https://ropsten.infura.io/v3/YOUR-PROJECT-ID`),
// network_id: 3, // Ropsten's id
// gas: 5500000, // Ropsten has a lower block limit than mainnet
// confirmations: 2, // # of confs to wait between deployments. (default: 0)
// timeoutBlocks: 200, // # of blocks before a deployment times out (minimum/default: 50)
// skipDryRun: true // Skip dry run before migrations? (default: false for public nets )
// provider: () => new HDWalletProvider(mnemonic, `https://ropsten.infura.io/v3/YOUR-PROJECT-ID`),
// network_id: 3, // Ropsten's id
// gas: 5500000, // Ropsten has a lower block limit than mainnet
// confirmations: 2, // # of confs to wait between deployments. (default: 0)
// timeoutBlocks: 200, // # of blocks before a deployment times out (minimum/default: 50)
// skipDryRun: true // Skip dry run before migrations? (default: false for public nets )
// },
// Useful for private networks
// private: {
// provider: () => new HDWalletProvider(mnemonic, `https://network.io`),
// network_id: 2111, // This network is yours, in the cloud.
// production: true // Treats this network as if it was a public net. (default: false)
// provider: () => new HDWalletProvider(mnemonic, `https://network.io`),
// network_id: 2111, // This network is yours, in the cloud.
// production: true // Treats this network as if it was a public net. (default: false)
// }
},
...
...
@@ -85,7 +82,7 @@ module.exports = {
// Configure your compilers
compilers
:
{
solc
:
{
// version: "0.5.1",
// Fetch exact version from solc-bin (default: truffle's version)
version
:
"
0.4.24
"
// Fetch exact version from solc-bin (default: truffle's version)
// docker: true, // Use "0.5.1" you've installed locally with docker (default: false)
// settings: { // See the solidity docs for advice about optimization and evmVersion
// optimizer: {
...
...
@@ -96,4 +93,4 @@ module.exports = {
// }
}
}
}
}
;
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment