gun-eth 1.0.1 → 1.1.1
Sign up to get free protection for your applications and to get access to all the features.
- package/SHINE.json +300 -0
- package/SHINE.sol +65 -0
- package/index.js +107 -0
- package/package.json +1 -1
package/SHINE.json
ADDED
@@ -0,0 +1,300 @@
|
|
1
|
+
{
|
2
|
+
"address": "0x21f5C4f2a0898Aa3EaFfdcb644dFeF30e95cC359",
|
3
|
+
"abi": [
|
4
|
+
{
|
5
|
+
"anonymous": false,
|
6
|
+
"inputs": [
|
7
|
+
{
|
8
|
+
"indexed": true,
|
9
|
+
"internalType": "bytes",
|
10
|
+
"name": "nodeId",
|
11
|
+
"type": "bytes"
|
12
|
+
},
|
13
|
+
{
|
14
|
+
"indexed": true,
|
15
|
+
"internalType": "bytes32",
|
16
|
+
"name": "key",
|
17
|
+
"type": "bytes32"
|
18
|
+
},
|
19
|
+
{
|
20
|
+
"indexed": false,
|
21
|
+
"internalType": "bytes32",
|
22
|
+
"name": "contentHash",
|
23
|
+
"type": "bytes32"
|
24
|
+
},
|
25
|
+
{
|
26
|
+
"indexed": false,
|
27
|
+
"internalType": "address",
|
28
|
+
"name": "updater",
|
29
|
+
"type": "address"
|
30
|
+
}
|
31
|
+
],
|
32
|
+
"name": "DataUpdated",
|
33
|
+
"type": "event"
|
34
|
+
},
|
35
|
+
{
|
36
|
+
"inputs": [
|
37
|
+
{
|
38
|
+
"internalType": "bytes[]",
|
39
|
+
"name": "nodeIds",
|
40
|
+
"type": "bytes[]"
|
41
|
+
},
|
42
|
+
{
|
43
|
+
"internalType": "bytes32[]",
|
44
|
+
"name": "keys",
|
45
|
+
"type": "bytes32[]"
|
46
|
+
},
|
47
|
+
{
|
48
|
+
"internalType": "bytes32[]",
|
49
|
+
"name": "contentHashes",
|
50
|
+
"type": "bytes32[]"
|
51
|
+
}
|
52
|
+
],
|
53
|
+
"name": "batchUpdateData",
|
54
|
+
"outputs": [],
|
55
|
+
"stateMutability": "nonpayable",
|
56
|
+
"type": "function"
|
57
|
+
},
|
58
|
+
{
|
59
|
+
"inputs": [
|
60
|
+
{
|
61
|
+
"internalType": "bytes",
|
62
|
+
"name": "nodeId",
|
63
|
+
"type": "bytes"
|
64
|
+
},
|
65
|
+
{
|
66
|
+
"internalType": "bytes32",
|
67
|
+
"name": "key",
|
68
|
+
"type": "bytes32"
|
69
|
+
}
|
70
|
+
],
|
71
|
+
"name": "getLatestRecord",
|
72
|
+
"outputs": [
|
73
|
+
{
|
74
|
+
"internalType": "bytes32",
|
75
|
+
"name": "",
|
76
|
+
"type": "bytes32"
|
77
|
+
},
|
78
|
+
{
|
79
|
+
"internalType": "uint256",
|
80
|
+
"name": "",
|
81
|
+
"type": "uint256"
|
82
|
+
},
|
83
|
+
{
|
84
|
+
"internalType": "address",
|
85
|
+
"name": "",
|
86
|
+
"type": "address"
|
87
|
+
}
|
88
|
+
],
|
89
|
+
"stateMutability": "view",
|
90
|
+
"type": "function"
|
91
|
+
},
|
92
|
+
{
|
93
|
+
"inputs": [
|
94
|
+
{
|
95
|
+
"internalType": "bytes",
|
96
|
+
"name": "",
|
97
|
+
"type": "bytes"
|
98
|
+
},
|
99
|
+
{
|
100
|
+
"internalType": "bytes32",
|
101
|
+
"name": "",
|
102
|
+
"type": "bytes32"
|
103
|
+
}
|
104
|
+
],
|
105
|
+
"name": "nodeData",
|
106
|
+
"outputs": [
|
107
|
+
{
|
108
|
+
"internalType": "bytes32",
|
109
|
+
"name": "contentHash",
|
110
|
+
"type": "bytes32"
|
111
|
+
},
|
112
|
+
{
|
113
|
+
"internalType": "uint256",
|
114
|
+
"name": "timestamp",
|
115
|
+
"type": "uint256"
|
116
|
+
},
|
117
|
+
{
|
118
|
+
"internalType": "address",
|
119
|
+
"name": "updater",
|
120
|
+
"type": "address"
|
121
|
+
}
|
122
|
+
],
|
123
|
+
"stateMutability": "view",
|
124
|
+
"type": "function"
|
125
|
+
},
|
126
|
+
{
|
127
|
+
"inputs": [
|
128
|
+
{
|
129
|
+
"internalType": "bytes",
|
130
|
+
"name": "nodeId",
|
131
|
+
"type": "bytes"
|
132
|
+
},
|
133
|
+
{
|
134
|
+
"internalType": "bytes32",
|
135
|
+
"name": "key",
|
136
|
+
"type": "bytes32"
|
137
|
+
},
|
138
|
+
{
|
139
|
+
"internalType": "bytes32",
|
140
|
+
"name": "contentHash",
|
141
|
+
"type": "bytes32"
|
142
|
+
}
|
143
|
+
],
|
144
|
+
"name": "updateData",
|
145
|
+
"outputs": [],
|
146
|
+
"stateMutability": "nonpayable",
|
147
|
+
"type": "function"
|
148
|
+
},
|
149
|
+
{
|
150
|
+
"inputs": [
|
151
|
+
{
|
152
|
+
"internalType": "bytes",
|
153
|
+
"name": "nodeId",
|
154
|
+
"type": "bytes"
|
155
|
+
},
|
156
|
+
{
|
157
|
+
"internalType": "bytes32",
|
158
|
+
"name": "key",
|
159
|
+
"type": "bytes32"
|
160
|
+
},
|
161
|
+
{
|
162
|
+
"internalType": "bytes32",
|
163
|
+
"name": "contentHash",
|
164
|
+
"type": "bytes32"
|
165
|
+
}
|
166
|
+
],
|
167
|
+
"name": "verifyData",
|
168
|
+
"outputs": [
|
169
|
+
{
|
170
|
+
"internalType": "bool",
|
171
|
+
"name": "",
|
172
|
+
"type": "bool"
|
173
|
+
},
|
174
|
+
{
|
175
|
+
"internalType": "uint256",
|
176
|
+
"name": "",
|
177
|
+
"type": "uint256"
|
178
|
+
},
|
179
|
+
{
|
180
|
+
"internalType": "address",
|
181
|
+
"name": "",
|
182
|
+
"type": "address"
|
183
|
+
}
|
184
|
+
],
|
185
|
+
"stateMutability": "view",
|
186
|
+
"type": "function"
|
187
|
+
}
|
188
|
+
],
|
189
|
+
"transactionHash": "0x1443c497e2f29a9854ee5e1eeaf6a4b9749a02da8814538cc34517cbb9d0be7e",
|
190
|
+
"receipt": {
|
191
|
+
"to": null,
|
192
|
+
"from": "0x8aA5F726d9F868a21a8bd748E2f1E43bA31eb670",
|
193
|
+
"contractAddress": "0x21f5C4f2a0898Aa3EaFfdcb644dFeF30e95cC359",
|
194
|
+
"transactionIndex": 4,
|
195
|
+
"gasUsed": "450179",
|
196
|
+
"logsBloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
|
197
|
+
"blockHash": "0xefa0944e3578d4275ec0321cb139c007b4d908b6852ebd376333899bd3b1d296",
|
198
|
+
"transactionHash": "0x1443c497e2f29a9854ee5e1eeaf6a4b9749a02da8814538cc34517cbb9d0be7e",
|
199
|
+
"logs": [],
|
200
|
+
"blockNumber": 17722535,
|
201
|
+
"cumulativeGasUsed": "1569514",
|
202
|
+
"status": 1,
|
203
|
+
"byzantium": true
|
204
|
+
},
|
205
|
+
"args": [],
|
206
|
+
"numDeployments": 3,
|
207
|
+
"solcInputHash": "e7a76cb3f8f61c89b3e2cabe29f25758",
|
208
|
+
"metadata": "{\"compiler\":{\"version\":\"0.8.17+commit.8df45f5f\"},\"language\":\"Solidity\",\"output\":{\"abi\":[{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"internalType\":\"bytes\",\"name\":\"nodeId\",\"type\":\"bytes\"},{\"indexed\":true,\"internalType\":\"bytes32\",\"name\":\"key\",\"type\":\"bytes32\"},{\"indexed\":false,\"internalType\":\"bytes32\",\"name\":\"contentHash\",\"type\":\"bytes32\"},{\"indexed\":false,\"internalType\":\"address\",\"name\":\"updater\",\"type\":\"address\"}],\"name\":\"DataUpdated\",\"type\":\"event\"},{\"inputs\":[{\"internalType\":\"bytes[]\",\"name\":\"nodeIds\",\"type\":\"bytes[]\"},{\"internalType\":\"bytes32[]\",\"name\":\"keys\",\"type\":\"bytes32[]\"},{\"internalType\":\"bytes32[]\",\"name\":\"contentHashes\",\"type\":\"bytes32[]\"}],\"name\":\"batchUpdateData\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"bytes\",\"name\":\"nodeId\",\"type\":\"bytes\"},{\"internalType\":\"bytes32\",\"name\":\"key\",\"type\":\"bytes32\"}],\"name\":\"getLatestRecord\",\"outputs\":[{\"internalType\":\"bytes32\",\"name\":\"\",\"type\":\"bytes32\"},{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"},{\"internalType\":\"address\",\"name\":\"\",\"type\":\"address\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"bytes\",\"name\":\"\",\"type\":\"bytes\"},{\"internalType\":\"bytes32\",\"name\":\"\",\"type\":\"bytes32\"}],\"name\":\"nodeData\",\"outputs\":[{\"internalType\":\"bytes32\",\"name\":\"contentHash\",\"type\":\"bytes32\"},{\"internalType\":\"uint256\",\"name\":\"timestamp\",\"type\":\"uint256\"},{\"internalType\":\"address\",\"name\":\"updater\",\"type\":\"address\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"bytes\",\"name\":\"nodeId\",\"type\":\"bytes\"},{\"internalType\":\"bytes32\",\"name\":\"key\",\"type\":\"bytes32\"},{\"internalType\":\"bytes32\",\"name\":\"contentHash\",\"type\":\"bytes32\"}],\"name\":\"updateData\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"bytes\",\"name\":\"nodeId\",\"type\":\"bytes\"},{\"internalType\":\"bytes32\",\"name\":\"key\",\"type\":\"bytes32\"},{\"internalType\":\"bytes32\",\"name\":\"contentHash\",\"type\":\"bytes32\"}],\"name\":\"verifyData\",\"outputs\":[{\"internalType\":\"bool\",\"name\":\"\",\"type\":\"bool\"},{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"},{\"internalType\":\"address\",\"name\":\"\",\"type\":\"address\"}],\"stateMutability\":\"view\",\"type\":\"function\"}],\"devdoc\":{\"kind\":\"dev\",\"methods\":{},\"version\":1},\"userdoc\":{\"kind\":\"user\",\"methods\":{},\"version\":1}},\"settings\":{\"compilationTarget\":{\"contracts/SHINE.sol\":\"SHINE\"},\"evmVersion\":\"london\",\"libraries\":{},\"metadata\":{\"bytecodeHash\":\"ipfs\",\"useLiteralContent\":true},\"optimizer\":{\"enabled\":true,\"runs\":200},\"remappings\":[]},\"sources\":{\"contracts/SHINE.sol\":{\"content\":\"// SPDX-License-Identifier: MIT\\r\\npragma solidity ^0.8.0;\\r\\n\\r\\ncontract SHINE {\\r\\n\\tstruct DataRecord {\\r\\n\\t\\tbytes32 contentHash;\\r\\n\\t\\tuint256 timestamp;\\r\\n\\t\\taddress updater;\\r\\n\\t}\\r\\n\\r\\n\\tmapping(bytes => mapping(bytes32 => DataRecord)) public nodeData;\\r\\n\\r\\n\\tevent DataUpdated(\\r\\n\\t\\tbytes indexed nodeId,\\r\\n\\t\\tbytes32 indexed key,\\r\\n\\t\\tbytes32 contentHash,\\r\\n\\t\\taddress updater\\r\\n\\t);\\r\\n\\r\\n\\tfunction updateData(\\r\\n\\t\\tbytes memory nodeId,\\r\\n\\t\\tbytes32 key,\\r\\n\\t\\tbytes32 contentHash\\r\\n\\t) public {\\r\\n\\t\\tnodeData[nodeId][key] = DataRecord(\\r\\n\\t\\t\\tcontentHash,\\r\\n\\t\\t\\tblock.timestamp,\\r\\n\\t\\t\\tmsg.sender\\r\\n\\t\\t);\\r\\n\\t\\temit DataUpdated(nodeId, key, contentHash, msg.sender);\\r\\n\\t}\\r\\n\\r\\n\\tfunction verifyData(\\r\\n\\t\\tbytes memory nodeId,\\r\\n\\t\\tbytes32 key,\\r\\n\\t\\tbytes32 contentHash\\r\\n\\t) public view returns (bool, uint256, address) {\\r\\n\\t\\tDataRecord memory record = nodeData[nodeId][key];\\r\\n\\t\\tbool isValid = record.contentHash == contentHash;\\r\\n\\t\\treturn (isValid, record.timestamp, record.updater);\\r\\n\\t}\\r\\n\\r\\n\\tfunction getLatestRecord(\\r\\n\\t\\tbytes memory nodeId,\\r\\n\\t\\tbytes32 key\\r\\n\\t) public view returns (bytes32, uint256, address) {\\r\\n\\t\\tDataRecord memory record = nodeData[nodeId][key];\\r\\n\\t\\treturn (record.contentHash, record.timestamp, record.updater);\\r\\n\\t}\\r\\n\\r\\n\\tfunction batchUpdateData(\\r\\n\\t\\tbytes[] memory nodeIds,\\r\\n\\t\\tbytes32[] memory keys,\\r\\n\\t\\tbytes32[] memory contentHashes\\r\\n\\t) public {\\r\\n\\t\\trequire(\\r\\n\\t\\t\\tnodeIds.length == keys.length &&\\r\\n\\t\\t\\t\\tkeys.length == contentHashes.length,\\r\\n\\t\\t\\t\\\"Arrays length mismatch\\\"\\r\\n\\t\\t);\\r\\n\\t\\tfor (uint i = 0; i < nodeIds.length; i++) {\\r\\n\\t\\t\\tupdateData(nodeIds[i], keys[i], contentHashes[i]);\\r\\n\\t\\t}\\r\\n\\t}\\r\\n}\\r\\n\",\"keccak256\":\"0xfd8eaa9c1661afb4543233422e06478eef0a247b1910695f2e0357f92642b8d5\",\"license\":\"MIT\"}},\"version\":1}",
|
209
|
+
"bytecode": "0x608060405234801561001057600080fd5b5061072e806100206000396000f3fe608060405234801561001057600080fd5b50600436106100575760003560e01c80631dabc0611461005c5780632f707e6d146100715780637248a88d146100eb578063b8ca21ec146100fe578063e6039af314610111575b600080fd5b61006f61006a366004610472565b61014a565b005b6100c261007f3660046104c0565b815160208184018101805160008083529383019583019590952094905292909252815260409020805460018201546002909201549091906001600160a01b031683565b6040805193845260208401929092526001600160a01b0316908201526060015b60405180910390f35b6100c26100f93660046104c0565b610211565b61006f61010c366004610594565b61027a565b61012461011f366004610472565b61034f565b60408051931515845260208401929092526001600160a01b0316908201526060016100e2565b604080516060810182528281524260208201523381830152905160009061017290869061068c565b9081526040805160209281900383018120600087815290845282902084518155928401516001840155920151600290910180546001600160a01b0319166001600160a01b0390921691909117905582906101cd90859061068c565b60408051918290038220848352336020840152917fc351bb5aebb2727af44600cc5ecd675ba56fe055624fab7916e602f59ce8d620910160405180910390a3505050565b600080600080600086604051610227919061068c565b90815260408051602092819003830181206000988952835296819020606088018252805480895260018201549389018490526002909101546001600160a01b031697909101879052979096509350505050565b8151835114801561028c575080518251145b6102d55760405162461bcd60e51b8152602060048201526016602482015275082e4e4c2f2e640d8cadccee8d040dad2e6dac2e8c6d60531b604482015260640160405180910390fd5b60005b8351811015610349576103378482815181106102f6576102f66106bb565b6020026020010151848381518110610310576103106106bb565b602002602001015184848151811061032a5761032a6106bb565b602002602001015161014a565b80610341816106d1565b9150506102d8565b50505050565b600080600080600087604051610365919061068c565b90815260408051602092819003830181206000998a528352978190206060890182528054808a526001820154938a018490526002909101546001600160a01b031698909101889052959095149794965050505050565b634e487b7160e01b600052604160045260246000fd5b604051601f8201601f1916810167ffffffffffffffff811182821017156103fa576103fa6103bb565b604052919050565b600082601f83011261041357600080fd5b813567ffffffffffffffff81111561042d5761042d6103bb565b610440601f8201601f19166020016103d1565b81815284602083860101111561045557600080fd5b816020850160208301376000918101602001919091529392505050565b60008060006060848603121561048757600080fd5b833567ffffffffffffffff81111561049e57600080fd5b6104aa86828701610402565b9660208601359650604090950135949350505050565b600080604083850312156104d357600080fd5b823567ffffffffffffffff8111156104ea57600080fd5b6104f685828601610402565b95602094909401359450505050565b600067ffffffffffffffff82111561051f5761051f6103bb565b5060051b60200190565b600082601f83011261053a57600080fd5b8135602061054f61054a83610505565b6103d1565b82815260059290921b8401810191818101908684111561056e57600080fd5b8286015b848110156105895780358352918301918301610572565b509695505050505050565b6000806000606084860312156105a957600080fd5b833567ffffffffffffffff808211156105c157600080fd5b818601915086601f8301126105d557600080fd5b813560206105e561054a83610505565b82815260059290921b8401810191818101908a84111561060457600080fd5b8286015b8481101561063c578035868111156106205760008081fd5b61062e8d86838b0101610402565b845250918301918301610608565b509750508701359250508082111561065357600080fd5b61065f87838801610529565b9350604086013591508082111561067557600080fd5b5061068286828701610529565b9150509250925092565b6000825160005b818110156106ad5760208186018101518583015201610693565b506000920191825250919050565b634e487b7160e01b600052603260045260246000fd5b6000600182016106f157634e487b7160e01b600052601160045260246000fd5b506001019056fea2646970667358221220d03f124930aab649f69a63261935e3b1264f0c18e4dd77b81ea19feb30808ee964736f6c63430008110033",
|
210
|
+
"deployedBytecode": "0x608060405234801561001057600080fd5b50600436106100575760003560e01c80631dabc0611461005c5780632f707e6d146100715780637248a88d146100eb578063b8ca21ec146100fe578063e6039af314610111575b600080fd5b61006f61006a366004610472565b61014a565b005b6100c261007f3660046104c0565b815160208184018101805160008083529383019583019590952094905292909252815260409020805460018201546002909201549091906001600160a01b031683565b6040805193845260208401929092526001600160a01b0316908201526060015b60405180910390f35b6100c26100f93660046104c0565b610211565b61006f61010c366004610594565b61027a565b61012461011f366004610472565b61034f565b60408051931515845260208401929092526001600160a01b0316908201526060016100e2565b604080516060810182528281524260208201523381830152905160009061017290869061068c565b9081526040805160209281900383018120600087815290845282902084518155928401516001840155920151600290910180546001600160a01b0319166001600160a01b0390921691909117905582906101cd90859061068c565b60408051918290038220848352336020840152917fc351bb5aebb2727af44600cc5ecd675ba56fe055624fab7916e602f59ce8d620910160405180910390a3505050565b600080600080600086604051610227919061068c565b90815260408051602092819003830181206000988952835296819020606088018252805480895260018201549389018490526002909101546001600160a01b031697909101879052979096509350505050565b8151835114801561028c575080518251145b6102d55760405162461bcd60e51b8152602060048201526016602482015275082e4e4c2f2e640d8cadccee8d040dad2e6dac2e8c6d60531b604482015260640160405180910390fd5b60005b8351811015610349576103378482815181106102f6576102f66106bb565b6020026020010151848381518110610310576103106106bb565b602002602001015184848151811061032a5761032a6106bb565b602002602001015161014a565b80610341816106d1565b9150506102d8565b50505050565b600080600080600087604051610365919061068c565b90815260408051602092819003830181206000998a528352978190206060890182528054808a526001820154938a018490526002909101546001600160a01b031698909101889052959095149794965050505050565b634e487b7160e01b600052604160045260246000fd5b604051601f8201601f1916810167ffffffffffffffff811182821017156103fa576103fa6103bb565b604052919050565b600082601f83011261041357600080fd5b813567ffffffffffffffff81111561042d5761042d6103bb565b610440601f8201601f19166020016103d1565b81815284602083860101111561045557600080fd5b816020850160208301376000918101602001919091529392505050565b60008060006060848603121561048757600080fd5b833567ffffffffffffffff81111561049e57600080fd5b6104aa86828701610402565b9660208601359650604090950135949350505050565b600080604083850312156104d357600080fd5b823567ffffffffffffffff8111156104ea57600080fd5b6104f685828601610402565b95602094909401359450505050565b600067ffffffffffffffff82111561051f5761051f6103bb565b5060051b60200190565b600082601f83011261053a57600080fd5b8135602061054f61054a83610505565b6103d1565b82815260059290921b8401810191818101908684111561056e57600080fd5b8286015b848110156105895780358352918301918301610572565b509695505050505050565b6000806000606084860312156105a957600080fd5b833567ffffffffffffffff808211156105c157600080fd5b818601915086601f8301126105d557600080fd5b813560206105e561054a83610505565b82815260059290921b8401810191818101908a84111561060457600080fd5b8286015b8481101561063c578035868111156106205760008081fd5b61062e8d86838b0101610402565b845250918301918301610608565b509750508701359250508082111561065357600080fd5b61065f87838801610529565b9350604086013591508082111561067557600080fd5b5061068286828701610529565b9150509250925092565b6000825160005b818110156106ad5760208186018101518583015201610693565b506000920191825250919050565b634e487b7160e01b600052603260045260246000fd5b6000600182016106f157634e487b7160e01b600052601160045260246000fd5b506001019056fea2646970667358221220d03f124930aab649f69a63261935e3b1264f0c18e4dd77b81ea19feb30808ee964736f6c63430008110033",
|
211
|
+
"devdoc": {
|
212
|
+
"kind": "dev",
|
213
|
+
"methods": {},
|
214
|
+
"version": 1
|
215
|
+
},
|
216
|
+
"userdoc": {
|
217
|
+
"kind": "user",
|
218
|
+
"methods": {},
|
219
|
+
"version": 1
|
220
|
+
},
|
221
|
+
"storageLayout": {
|
222
|
+
"storage": [
|
223
|
+
{
|
224
|
+
"astId": 15,
|
225
|
+
"contract": "contracts/SHINE.sol:SHINE",
|
226
|
+
"label": "nodeData",
|
227
|
+
"offset": 0,
|
228
|
+
"slot": "0",
|
229
|
+
"type": "t_mapping(t_bytes_memory_ptr,t_mapping(t_bytes32,t_struct(DataRecord)8_storage))"
|
230
|
+
}
|
231
|
+
],
|
232
|
+
"types": {
|
233
|
+
"t_address": {
|
234
|
+
"encoding": "inplace",
|
235
|
+
"label": "address",
|
236
|
+
"numberOfBytes": "20"
|
237
|
+
},
|
238
|
+
"t_bytes32": {
|
239
|
+
"encoding": "inplace",
|
240
|
+
"label": "bytes32",
|
241
|
+
"numberOfBytes": "32"
|
242
|
+
},
|
243
|
+
"t_bytes_memory_ptr": {
|
244
|
+
"encoding": "bytes",
|
245
|
+
"label": "bytes",
|
246
|
+
"numberOfBytes": "32"
|
247
|
+
},
|
248
|
+
"t_mapping(t_bytes32,t_struct(DataRecord)8_storage)": {
|
249
|
+
"encoding": "mapping",
|
250
|
+
"key": "t_bytes32",
|
251
|
+
"label": "mapping(bytes32 => struct SHINE.DataRecord)",
|
252
|
+
"numberOfBytes": "32",
|
253
|
+
"value": "t_struct(DataRecord)8_storage"
|
254
|
+
},
|
255
|
+
"t_mapping(t_bytes_memory_ptr,t_mapping(t_bytes32,t_struct(DataRecord)8_storage))": {
|
256
|
+
"encoding": "mapping",
|
257
|
+
"key": "t_bytes_memory_ptr",
|
258
|
+
"label": "mapping(bytes => mapping(bytes32 => struct SHINE.DataRecord))",
|
259
|
+
"numberOfBytes": "32",
|
260
|
+
"value": "t_mapping(t_bytes32,t_struct(DataRecord)8_storage)"
|
261
|
+
},
|
262
|
+
"t_struct(DataRecord)8_storage": {
|
263
|
+
"encoding": "inplace",
|
264
|
+
"label": "struct SHINE.DataRecord",
|
265
|
+
"members": [
|
266
|
+
{
|
267
|
+
"astId": 3,
|
268
|
+
"contract": "contracts/SHINE.sol:SHINE",
|
269
|
+
"label": "contentHash",
|
270
|
+
"offset": 0,
|
271
|
+
"slot": "0",
|
272
|
+
"type": "t_bytes32"
|
273
|
+
},
|
274
|
+
{
|
275
|
+
"astId": 5,
|
276
|
+
"contract": "contracts/SHINE.sol:SHINE",
|
277
|
+
"label": "timestamp",
|
278
|
+
"offset": 0,
|
279
|
+
"slot": "1",
|
280
|
+
"type": "t_uint256"
|
281
|
+
},
|
282
|
+
{
|
283
|
+
"astId": 7,
|
284
|
+
"contract": "contracts/SHINE.sol:SHINE",
|
285
|
+
"label": "updater",
|
286
|
+
"offset": 0,
|
287
|
+
"slot": "2",
|
288
|
+
"type": "t_address"
|
289
|
+
}
|
290
|
+
],
|
291
|
+
"numberOfBytes": "96"
|
292
|
+
},
|
293
|
+
"t_uint256": {
|
294
|
+
"encoding": "inplace",
|
295
|
+
"label": "uint256",
|
296
|
+
"numberOfBytes": "32"
|
297
|
+
}
|
298
|
+
}
|
299
|
+
}
|
300
|
+
}
|
package/SHINE.sol
ADDED
@@ -0,0 +1,65 @@
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
2
|
+
pragma solidity ^0.8.0;
|
3
|
+
|
4
|
+
contract SHINE {
|
5
|
+
struct DataRecord {
|
6
|
+
bytes32 contentHash;
|
7
|
+
uint256 timestamp;
|
8
|
+
address updater;
|
9
|
+
}
|
10
|
+
|
11
|
+
mapping(bytes => mapping(bytes32 => DataRecord)) public nodeData;
|
12
|
+
|
13
|
+
event DataUpdated(
|
14
|
+
bytes indexed nodeId,
|
15
|
+
bytes32 indexed key,
|
16
|
+
bytes32 contentHash,
|
17
|
+
address updater
|
18
|
+
);
|
19
|
+
|
20
|
+
function updateData(
|
21
|
+
bytes memory nodeId,
|
22
|
+
bytes32 key,
|
23
|
+
bytes32 contentHash
|
24
|
+
) public {
|
25
|
+
nodeData[nodeId][key] = DataRecord(
|
26
|
+
contentHash,
|
27
|
+
block.timestamp,
|
28
|
+
msg.sender
|
29
|
+
);
|
30
|
+
emit DataUpdated(nodeId, key, contentHash, msg.sender);
|
31
|
+
}
|
32
|
+
|
33
|
+
function verifyData(
|
34
|
+
bytes memory nodeId,
|
35
|
+
bytes32 key,
|
36
|
+
bytes32 contentHash
|
37
|
+
) public view returns (bool, uint256, address) {
|
38
|
+
DataRecord memory record = nodeData[nodeId][key];
|
39
|
+
bool isValid = record.contentHash == contentHash;
|
40
|
+
return (isValid, record.timestamp, record.updater);
|
41
|
+
}
|
42
|
+
|
43
|
+
function getLatestRecord(
|
44
|
+
bytes memory nodeId,
|
45
|
+
bytes32 key
|
46
|
+
) public view returns (bytes32, uint256, address) {
|
47
|
+
DataRecord memory record = nodeData[nodeId][key];
|
48
|
+
return (record.contentHash, record.timestamp, record.updater);
|
49
|
+
}
|
50
|
+
|
51
|
+
function batchUpdateData(
|
52
|
+
bytes[] memory nodeIds,
|
53
|
+
bytes32[] memory keys,
|
54
|
+
bytes32[] memory contentHashes
|
55
|
+
) public {
|
56
|
+
require(
|
57
|
+
nodeIds.length == keys.length &&
|
58
|
+
keys.length == contentHashes.length,
|
59
|
+
"Arrays length mismatch"
|
60
|
+
);
|
61
|
+
for (uint i = 0; i < nodeIds.length; i++) {
|
62
|
+
updateData(nodeIds[i], keys[i], contentHashes[i]);
|
63
|
+
}
|
64
|
+
}
|
65
|
+
}
|
package/index.js
CHANGED
@@ -2,6 +2,12 @@ const Gun = require("gun/gun");
|
|
2
2
|
const SEA = require("gun/sea");
|
3
3
|
const ethers = require("ethers");
|
4
4
|
|
5
|
+
const SHINE = require("./SHINE.json");
|
6
|
+
const SHINE_ABI = SHINE.abi;
|
7
|
+
const SHINE_OPTIMISM_SEPOLIA = SHINE.address;
|
8
|
+
|
9
|
+
let SHINE_CONTRACT_ADDRESS;
|
10
|
+
|
5
11
|
// Aggiungi il metodo alla catena di Gun
|
6
12
|
Gun.chain.verifySignature = async function (message, signature) {
|
7
13
|
try {
|
@@ -86,3 +92,104 @@ Gun.chain.getAndDecryptPair = async function (address, signature) {
|
|
86
92
|
return null;
|
87
93
|
}
|
88
94
|
};
|
95
|
+
|
96
|
+
Gun.chain.shine = function (chain, data, callback) {
|
97
|
+
const gun = this;
|
98
|
+
|
99
|
+
// select address based on chain
|
100
|
+
if (chain === "optimismSepolia") {
|
101
|
+
SHINE_CONTRACT_ADDRESS = SHINE_OPTIMISM_SEPOLIA;
|
102
|
+
} else {
|
103
|
+
throw new Error("Chain not supported");
|
104
|
+
}
|
105
|
+
|
106
|
+
// Funzione per ottenere il signer
|
107
|
+
const getSigner = async () => {
|
108
|
+
if (typeof window.ethereum !== "undefined") {
|
109
|
+
await window.ethereum.request({ method: "eth_requestAccounts" });
|
110
|
+
const provider = new ethers.BrowserProvider(window.ethereum);
|
111
|
+
return provider.getSigner();
|
112
|
+
} else {
|
113
|
+
throw new Error("Ethereum provider not found");
|
114
|
+
}
|
115
|
+
};
|
116
|
+
|
117
|
+
// Funzione per scrivere on-chain
|
118
|
+
const writeOnChain = async (nodeId, key, contentHash) => {
|
119
|
+
const signer = await getSigner();
|
120
|
+
const contract = new ethers.Contract(
|
121
|
+
SHINE_CONTRACT_ADDRESS,
|
122
|
+
SHINE_ABI,
|
123
|
+
signer
|
124
|
+
);
|
125
|
+
const tx = await contract.updateData(
|
126
|
+
ethers.toUtf8Bytes(nodeId),
|
127
|
+
key,
|
128
|
+
contentHash
|
129
|
+
);
|
130
|
+
await tx.wait();
|
131
|
+
return tx;
|
132
|
+
};
|
133
|
+
|
134
|
+
// Funzione per verificare on-chain
|
135
|
+
const verifyOnChain = async (nodeId, key, contentHash) => {
|
136
|
+
const signer = await getSigner();
|
137
|
+
const contract = new ethers.Contract(
|
138
|
+
SHINE_CONTRACT_ADDRESS,
|
139
|
+
SHINE_ABI,
|
140
|
+
signer
|
141
|
+
);
|
142
|
+
return await contract.verifyData(
|
143
|
+
ethers.toUtf8Bytes(nodeId),
|
144
|
+
key,
|
145
|
+
contentHash
|
146
|
+
);
|
147
|
+
};
|
148
|
+
|
149
|
+
// Processo SHINE
|
150
|
+
gun.put(data, async (ack) => {
|
151
|
+
if (ack.err) {
|
152
|
+
if (callback) callback({ err: ack.err });
|
153
|
+
return;
|
154
|
+
}
|
155
|
+
|
156
|
+
try {
|
157
|
+
// Calcola l'hash del dato
|
158
|
+
const dataString = JSON.stringify(data);
|
159
|
+
const contentHash = ethers.keccak256(ethers.toUtf8Bytes(dataString));
|
160
|
+
|
161
|
+
// Ottieni l'ID del nodo corrente
|
162
|
+
const nodeId = gun.back("opt.pid") || "unknown";
|
163
|
+
|
164
|
+
// Genera una chiave unica per questo dato
|
165
|
+
const key = ethers.keccak256(ethers.toUtf8Bytes(ack.get));
|
166
|
+
|
167
|
+
// Scrivi on-chain
|
168
|
+
const writeTx = await writeOnChain(nodeId, key, contentHash);
|
169
|
+
|
170
|
+
// Verifica GunDB e chain
|
171
|
+
const gunData = await gun.get(ack.get).then();
|
172
|
+
const [isValid, timestamp, updater] = await verifyOnChain(
|
173
|
+
nodeId,
|
174
|
+
key,
|
175
|
+
contentHash
|
176
|
+
);
|
177
|
+
|
178
|
+
if (JSON.stringify(gunData) === dataString && isValid) {
|
179
|
+
if (callback)
|
180
|
+
callback({
|
181
|
+
ok: true,
|
182
|
+
message: "Data verified on GunDB and blockchain",
|
183
|
+
updater: updater,
|
184
|
+
timestamp: timestamp.toString(),
|
185
|
+
});
|
186
|
+
} else {
|
187
|
+
if (callback) callback({ err: "Data verification failed" });
|
188
|
+
}
|
189
|
+
} catch (error) {
|
190
|
+
if (callback) callback({ err: error.message });
|
191
|
+
}
|
192
|
+
});
|
193
|
+
|
194
|
+
return gun;
|
195
|
+
};
|