-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathkyc.sol
108 lines (78 loc) · 4.25 KB
/
kyc.sol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
pragma solidity ^0.4.0;
contract kyc {
address private verifier;
mapping (address => bool) private bank;
struct customer {
uint lastUsedBank;
mapping (address => uint) bankStatus;
mapping(string => string) Documents; // symmetric key encryption of documents ipfs newhash
mapping (address => string) key; // the key which encrypts the ipfs hash, is encrypted with the public key of the bank. so banks can decrypt this key and using it, it can also decrypt the ipfs hash.
}
event AskDocument(address askingBank, address customerAddress, address originalBank);
mapping(address => customer) customers;
constructor () public {
verifier=msg.sender;
}
function addBank(address newBank) public {
require(msg.sender == verifier,
"Only verifier can add the new bank");
bank[newBank]= true;
}
function checkBankRegistration( address bankAddress) private view returns (bool){
return bank[bankAddress];
}
function checkBankStatus( address bankAddress, address customerAddress) private view returns (uint){
return customers[customerAddress].bankStatus[bankAddress];
}
function consentConfirmation(address customerAddress) public{
require(checkBankRegistration(msg.sender),
"Only registered bank should be allowed to enter the consent");
require(checkBankStatus(msg.sender, customerAddress)==2,
"The bank should be in pending state for that particular customer");
customers[customerAddress].bankStatus[msg.sender]=1;
}
function consentInitiation(address bankAddress) public{
require(checkBankRegistration(bankAddress),
"Only registered bank should be allowed to enter the consent");
customers[msg.sender].bankStatus[bankAddress]=2;
}
function revokeConsent(address bankAddress) public {
require(checkBankRegistration(bankAddress),
"Only registered bank should be allowed to enter the consent");
customers[msg.sender].bankStatus[bankAddress]=0;
}
function recordData(address customerAddress, string keyhash , string documentType, string documentAddresshash ) public{
require(checkBankRegistration(msg.sender),
"Only registered bank should be allowed to record the data");
require(checkBankStatus(msg.sender, customerAddress)==1,
"The bank should be allowed to record data");
require(customers[customerAddress].lastUsedBank==0,
"this function should be called by home bank");
customers[customerAddress].Documents[documentType]=documentAddresshash;
customers[customerAddress].lastUsedBank++;
customers[customerAddress].key[msg.sender]=keyhash;
}
function requestTransfer(address originalBank, address customerAddress) public{
require(checkBankRegistration(msg.sender),
"Only registered bank should be allowed to ask for kyc reports");
require(checkBankRegistration(originalBank),
"kyc report should be asked only from registered banks");
require(checkBankStatus(msg.sender,customerAddress)==1,
"the bank should be allowed to access kyc record");
require(customers[customerAddress].lastUsedBank!=0,
"since this is a request of transfer, asking banking should not be home bank");
emit AskDocument(msg.sender, customerAddress, originalBank);
}
function GiveRecord(address receiverBank, address customerAddress, string keyhash) public{
require(checkBankRegistration(msg.sender),
"Only registered bank should be allowed to ask for kyc reports");
require(checkBankRegistration(receiverBank),
"kyc report should be asked only from registered banks");
require(checkBankStatus(msg.sender,customerAddress)==1,
"the bank should be allowed to access kyc record");
require(checkBankStatus(receiverBank,customerAddress)==1,
"the bank should be allowed to access kyc record");
customers[customerAddress].lastUsedBank++;
customers[customerAddress].key[receiverBank]=keyhash;
}
}