gun-eth 2.0.0 → 3.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (64) hide show
  1. package/README.md +386 -18
  2. package/dist/gun-eth.bundle.js +6806 -0
  3. package/dist/gun-eth.cjs +2465 -0
  4. package/dist/types/browser.d.ts +6 -0
  5. package/dist/types/config/local.d.ts +7 -0
  6. package/dist/types/constants/abis.d.ts +37 -0
  7. package/dist/types/constants/index.d.ts +1 -0
  8. package/dist/types/core/gun-eth.d.ts +419 -0
  9. package/dist/types/features/bubbles/client/bubble-client.d.ts +184 -0
  10. package/dist/types/features/bubbles/providers/base-bubble-provider.d.ts +303 -0
  11. package/dist/types/features/bubbles/providers/gun-bubble-provider.d.ts +173 -0
  12. package/dist/types/features/bubbles/providers/hybrid-bubble-provider.d.ts +124 -0
  13. package/dist/types/features/proof/ProofChain.d.ts +225 -0
  14. package/dist/types/features/stealth/StealthChain.d.ts +200 -0
  15. package/dist/types/index.d.ts +61 -0
  16. package/dist/types/utils/common.d.ts +11 -0
  17. package/dist/types/utils/encryption.d.ts +32 -0
  18. package/package.json +110 -26
  19. package/dist/gun-eth-protocol.cjs.js +0 -11528
  20. package/dist/gun-eth-protocol.esm.js +0 -11503
  21. package/dist/gun-eth-protocol.js +0 -18
  22. package/dist/gun-eth-protocol.react.js +0 -11503
  23. package/dist/gun-eth-protocol.umd.js +0 -18
  24. package/jsdoc.json +0 -7
  25. package/rollup.config.js +0 -80
  26. package/src/index.js +0 -181
  27. package/src/lib/authentication/index.js +0 -13
  28. package/src/lib/authentication/isAuthenticated.js +0 -20
  29. package/src/lib/authentication/login.js +0 -25
  30. package/src/lib/authentication/register.js +0 -58
  31. package/src/lib/blockchain/abis/SHINE.json +0 -262
  32. package/src/lib/blockchain/contracts/SHINE.sol +0 -52
  33. package/src/lib/blockchain/ethereum.js +0 -74
  34. package/src/lib/blockchain/shine.js +0 -204
  35. package/src/lib/certificates/friendsCertificates.js +0 -92
  36. package/src/lib/certificates/index.js +0 -44
  37. package/src/lib/certificates/messagingCertificates.js +0 -94
  38. package/src/lib/friends/acceptFriendRequest.js +0 -69
  39. package/src/lib/friends/addFriendRequest.js +0 -49
  40. package/src/lib/friends/friendRequests.js +0 -51
  41. package/src/lib/friends/friendsList.js +0 -57
  42. package/src/lib/friends/index.js +0 -36
  43. package/src/lib/friends/rejectFriendRequest.js +0 -31
  44. package/src/lib/messaging/chatsList.js +0 -42
  45. package/src/lib/messaging/createChat.js +0 -132
  46. package/src/lib/messaging/index.js +0 -36
  47. package/src/lib/messaging/messageList.js +0 -106
  48. package/src/lib/messaging/sendMessage.js +0 -132
  49. package/src/lib/messaging/sendVoiceMessage.js +0 -119
  50. package/src/lib/notes/createNote.js +0 -41
  51. package/src/lib/notes/deleteNote.js +0 -12
  52. package/src/lib/notes/getNote.js +0 -25
  53. package/src/lib/notes/getUserNote.js +0 -59
  54. package/src/lib/notes/index.js +0 -8
  55. package/src/lib/notes/updateNotes.js +0 -35
  56. package/src/lib/post/createPost.js +0 -17
  57. package/src/lib/post/decryptPost.js +0 -14
  58. package/src/lib/post/deletePost.js +0 -13
  59. package/src/lib/post/encryptPost,js +0 -16
  60. package/src/lib/post/getPost.js +0 -36
  61. package/src/lib/post/index.js +0 -9
  62. package/src/lib/post/updatePost.js +0 -16
  63. package/src/state/gun.js +0 -33
  64. package/types/types.d.ts +0 -244
package/src/index.js DELETED
@@ -1,181 +0,0 @@
1
- import * as authentication from "./lib/authentication";
2
- import * as certificates from "./lib/certificates";
3
- import * as friends from "./lib/friends";
4
- import * as messaging from "./lib/messaging";
5
- import { gun, user } from "./state/gun";
6
- import Gun from "gun";
7
-
8
- import {
9
- getEnsName,
10
- getSigner,
11
- getProvider,
12
- setStandaloneConfig,
13
- } from "./lib/blockchain/ethereum";
14
-
15
- Gun.chain.GunEth = function (gun, SEA, ethers) {
16
- console.log("gunEth called");
17
- console.log("gun in gunEth:", gun);
18
-
19
- return {
20
- shine: (chain, nodeId, data, callback) =>
21
- Gun.chain.shine.call(gun, chain, nodeId, data, callback),
22
-
23
- setStandaloneConfig: (newRpcUrl, newPrivateKey) => {
24
- console.log(
25
- "setStandaloneConfig called with:",
26
- newRpcUrl,
27
- newPrivateKey
28
- );
29
- setStandaloneConfig(newRpcUrl, newPrivateKey);
30
- console.log("Standalone configuration set");
31
- return this.gun;
32
- },
33
-
34
- verifySignature: async (message, signature) => {
35
- try {
36
- return ethers.verifyMessage(message, signature);
37
- } catch (error) {
38
- console.error("Error verifying signature:", error);
39
- return null;
40
- }
41
- },
42
-
43
- generatePassword: (signature) => {
44
- try {
45
- const hexSignature = ethers.hexlify(signature);
46
- const hash = ethers.keccak256(hexSignature);
47
- console.log("Generated password:", hash);
48
- return hash;
49
- } catch (error) {
50
- console.error("Error generating password:", error);
51
- return null;
52
- }
53
- },
54
-
55
- createSignature: async () => {
56
- try {
57
- const signer = await getSigner();
58
- const signature = await signer.signMessage(
59
- "GunDB access with Ethereum"
60
- );
61
- console.log("Signature created:", signature);
62
- return signature;
63
- } catch (error) {
64
- console.error("Error creating signature:", error);
65
- return null;
66
- }
67
- },
68
-
69
- createAndStoreEncryptedPair: async (address, password) => {
70
- try {
71
- const pair = await user._.sea;
72
- const encryptedPair = await SEA.encrypt(
73
- JSON.stringify(pair),
74
- password
75
- );
76
-
77
- // TODO: Add spending and viewing pairs implementation
78
- // const encryptedSpendingPair = await SEA.encrypt(JSON.stringify(pair), password + "_spending");
79
- // const encryptedViewingPair = await SEA.encrypt(JSON.stringify(pair), password + "_viewing");
80
-
81
- let ethAccount;
82
-
83
- try {
84
- const ensName = await getEnsName(address);
85
- ethAccount = ensName ? ensName : address;
86
- } catch (error) {
87
- console.error("Error getting ENS name:", error);
88
- ethAccount = address;
89
- }
90
-
91
- const data = {
92
- pub: encryptedPair.pub,
93
- address: address,
94
- ensName: ethAccount,
95
- };
96
-
97
- await gun
98
- .get("gun-eth")
99
- .get("users")
100
- .get(address)
101
- .put({ encryptedPair });
102
- await gun
103
- .get("gun-eth")
104
- .get("usersData")
105
- .get(encryptedPair.pub)
106
- .put({ data });
107
-
108
- await gun
109
- .get(`~${encryptedPair.pub}`)
110
- .get("safe")
111
- .get("enc")
112
- .put({ encryptedPair });
113
-
114
- console.log("Encrypted pair stored for:", address);
115
- } catch (error) {
116
- console.error("Error creating and storing encrypted pair:", error);
117
- }
118
- },
119
-
120
- getAndDecryptPair: async (address, password) => {
121
- try {
122
- const encryptedData = await gun
123
- .get("gun-eth")
124
- .get("users")
125
- .get(address)
126
- .get("encryptedPair")
127
- .then();
128
- if (!encryptedData) {
129
- throw new Error("No encrypted data found for this address");
130
- }
131
- const decryptedPair = await SEA.decrypt(encryptedData, password);
132
- console.log(decryptedPair);
133
- return decryptedPair;
134
- } catch (error) {
135
- console.error("Error retrieving and decrypting pair:", error);
136
- return null;
137
- }
138
- },
139
-
140
- gunToEthAccount: (gunPrivateKey) => {
141
- const base64UrlToHex = (base64url) => {
142
- const padding = "=".repeat((4 - (base64url.length % 4)) % 4);
143
- const base64 =
144
- base64url.replace(/-/g, "+").replace(/_/g, "/") + padding;
145
- const binaryString = atob(base64);
146
- return Array.from(binaryString, (char) =>
147
- char.charCodeAt(0).toString(16).padStart(2, "0")
148
- ).join("");
149
- };
150
-
151
- const hexPrivateKey = "0x" + base64UrlToHex(gunPrivateKey);
152
- const wallet = new ethers.Wallet(hexPrivateKey);
153
- const publicKey = wallet.address;
154
-
155
- return {
156
- account: wallet,
157
- publicKey: publicKey,
158
- };
159
- },
160
- };
161
- };
162
-
163
- const GunEthProtocol = () => {
164
- return {
165
- authentication,
166
- certificates,
167
- friends,
168
- messaging,
169
- gun,
170
- user
171
- }
172
- }
173
-
174
- if (typeof window !== "undefined") {
175
- window.Gun = gun;
176
- window.GunEthProtocol = GunEthProtocol();
177
- window.User = user;
178
- }
179
-
180
- export { authentication, certificates, friends, messaging, gun, user };
181
-
@@ -1,13 +0,0 @@
1
- import { gun } from "../../state/gun";
2
- import { checkAuth, isAuthenticated } from "./isAuthenticated";
3
- import loginUser from "./login";
4
- import registerUser from "./register";
5
-
6
- let logout = () => {
7
- gun.user().leave();
8
-
9
- isAuthenticated.next(false);
10
- };
11
-
12
- export { checkAuth, isAuthenticated, loginUser, registerUser, logout };
13
-
@@ -1,20 +0,0 @@
1
- import { Subject } from "rxjs";
2
- import { gun, user } from "../../state/gun";
3
-
4
- /**
5
- * This contains a subscribable function that will return a boolean of whether or not the user is authenticated or not.
6
- */
7
- let isAuthenticated = new Subject();
8
-
9
- /**
10
- * This function will check and see whether the user is authenticated or not.
11
- */
12
- let checkAuth = () => {
13
- if (user.is) return isAuthenticated.next(true);
14
- else return isAuthenticated.next(false);
15
- };
16
-
17
- gun.on("auth", () => isAuthenticated.next(true));
18
-
19
- export { isAuthenticated, checkAuth };
20
-
@@ -1,25 +0,0 @@
1
- import { user } from "../../state/gun";
2
-
3
- /**
4
- * This function will authenticate a user who has registered.
5
- *
6
- * @param {Object} credentials The users authentication credentials that they used when registering.
7
- * @param credentials.username
8
- * @param credentials.password
9
- *
10
- * @param {Function} callback The callback function returns error messages or a success message.
11
- */
12
- let loginUser = (credentials = {}, callback = () => {}) => {
13
- user.auth(credentials.username, credentials.password, ({ err, pub }) => {
14
- if (err) return callback({ errMessage: err, errCode: "gun-auth-error" });
15
- else
16
- return callback({
17
- errMessage: undefined,
18
- errCode: undefined,
19
- pub,
20
- message: "Successfully authenticated user.",
21
- });
22
- });
23
- };
24
-
25
- export default loginUser;
@@ -1,58 +0,0 @@
1
- import { gun, user } from "../../state/gun";
2
-
3
- /**
4
- * This function will check to see if the email is already in use.
5
- *
6
- * @param {string} username
7
- * @returns Promise<boolean>
8
- */
9
- let checkUsernameInUse = async (username) => {
10
- let user = await gun.get(`~@${username}`);
11
-
12
- return user !== undefined;
13
- };
14
-
15
- /**
16
- * This function will create a user.
17
- *
18
- * @param {Object} credentials The users authentication credentials that they want to use when logging in.
19
- * @param credentials.username
20
- * @param credentials.password
21
- *
22
- * @param {Function} callback The callback function returns error messages or a success message.
23
- */
24
- let registerUser = (credentials = {}, callback = () => {}) => {
25
- console.log("Credentials", credentials);
26
- console.log("Registering user...");
27
- (async () => {
28
- if (await checkUsernameInUse(credentials.username))
29
- return callback({
30
- errMessage: "Username in use.",
31
- errCode: "username-inuse",
32
- });
33
- else {
34
- user.create(credentials.username, credentials.password, ({ err, pub }) => {
35
- if (err)
36
- return callback({ errMessage: err, errCode: "gun-auth-error" });
37
- else
38
- return callback({
39
- errMessage: undefined,
40
- errCode: undefined,
41
- pub,
42
- message: "Successfully created user.",
43
- });
44
- });
45
- }
46
- })();
47
- };
48
-
49
- function str2ab(str) {
50
- var buf = new ArrayBuffer(str.length * 2); // 2 bytes for each char
51
- var bufView = new Uint16Array(buf);
52
- for (var i = 0, strLen = str.length; i < strLen; i++) {
53
- bufView[i] = str.charCodeAt(i);
54
- }
55
- return buf;
56
- }
57
-
58
- export default registerUser;
@@ -1,262 +0,0 @@
1
- {
2
- "address": "0x43D838b683F772F08f321E5FA265ad3e333BE9C2",
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": false,
15
- "internalType": "bytes32",
16
- "name": "contentHash",
17
- "type": "bytes32"
18
- },
19
- {
20
- "indexed": false,
21
- "internalType": "address",
22
- "name": "updater",
23
- "type": "address"
24
- }
25
- ],
26
- "name": "DataUpdated",
27
- "type": "event"
28
- },
29
- {
30
- "inputs": [
31
- {
32
- "internalType": "bytes[]",
33
- "name": "nodeIds",
34
- "type": "bytes[]"
35
- },
36
- {
37
- "internalType": "bytes32[]",
38
- "name": "contentHashes",
39
- "type": "bytes32[]"
40
- }
41
- ],
42
- "name": "batchUpdateData",
43
- "outputs": [],
44
- "stateMutability": "nonpayable",
45
- "type": "function"
46
- },
47
- {
48
- "inputs": [
49
- {
50
- "internalType": "bytes",
51
- "name": "nodeId",
52
- "type": "bytes"
53
- }
54
- ],
55
- "name": "getLatestRecord",
56
- "outputs": [
57
- {
58
- "internalType": "bytes32",
59
- "name": "",
60
- "type": "bytes32"
61
- },
62
- {
63
- "internalType": "uint256",
64
- "name": "",
65
- "type": "uint256"
66
- },
67
- {
68
- "internalType": "address",
69
- "name": "",
70
- "type": "address"
71
- }
72
- ],
73
- "stateMutability": "view",
74
- "type": "function"
75
- },
76
- {
77
- "inputs": [
78
- {
79
- "internalType": "bytes",
80
- "name": "",
81
- "type": "bytes"
82
- }
83
- ],
84
- "name": "nodeData",
85
- "outputs": [
86
- {
87
- "internalType": "bytes32",
88
- "name": "contentHash",
89
- "type": "bytes32"
90
- },
91
- {
92
- "internalType": "uint256",
93
- "name": "timestamp",
94
- "type": "uint256"
95
- },
96
- {
97
- "internalType": "address",
98
- "name": "updater",
99
- "type": "address"
100
- }
101
- ],
102
- "stateMutability": "view",
103
- "type": "function"
104
- },
105
- {
106
- "inputs": [
107
- {
108
- "internalType": "bytes",
109
- "name": "nodeId",
110
- "type": "bytes"
111
- },
112
- {
113
- "internalType": "bytes32",
114
- "name": "contentHash",
115
- "type": "bytes32"
116
- }
117
- ],
118
- "name": "updateData",
119
- "outputs": [],
120
- "stateMutability": "nonpayable",
121
- "type": "function"
122
- },
123
- {
124
- "inputs": [
125
- {
126
- "internalType": "bytes",
127
- "name": "nodeId",
128
- "type": "bytes"
129
- },
130
- {
131
- "internalType": "bytes32",
132
- "name": "contentHash",
133
- "type": "bytes32"
134
- }
135
- ],
136
- "name": "verifyData",
137
- "outputs": [
138
- {
139
- "internalType": "bool",
140
- "name": "",
141
- "type": "bool"
142
- },
143
- {
144
- "internalType": "uint256",
145
- "name": "",
146
- "type": "uint256"
147
- },
148
- {
149
- "internalType": "address",
150
- "name": "",
151
- "type": "address"
152
- }
153
- ],
154
- "stateMutability": "view",
155
- "type": "function"
156
- }
157
- ],
158
- "transactionHash": "0xc00b134812b2cb32d6a412fd1d1a4c9661777b0ee29ed0ff05b09c7c0b1f6f0d",
159
- "receipt": {
160
- "to": null,
161
- "from": "0x8aA5F726d9F868a21a8bd748E2f1E43bA31eb670",
162
- "contractAddress": "0x43D838b683F772F08f321E5FA265ad3e333BE9C2",
163
- "transactionIndex": 2,
164
- "gasUsed": "419514",
165
- "logsBloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
166
- "blockHash": "0xc8bd27a2f9bf4ec35e2c61c2c2e62b47b70aa10f587ea48d4802611c36116dd6",
167
- "transactionHash": "0xc00b134812b2cb32d6a412fd1d1a4c9661777b0ee29ed0ff05b09c7c0b1f6f0d",
168
- "logs": [],
169
- "blockNumber": 17723163,
170
- "cumulativeGasUsed": "551282",
171
- "status": 1,
172
- "byzantium": true
173
- },
174
- "args": [],
175
- "numDeployments": 4,
176
- "solcInputHash": "40cece70198a47ff2f958bd8d77d352d",
177
- "metadata": "{\"compiler\":{\"version\":\"0.8.17+commit.8df45f5f\"},\"language\":\"Solidity\",\"output\":{\"abi\":[{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"internalType\":\"bytes\",\"name\":\"nodeId\",\"type\":\"bytes\"},{\"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\":\"contentHashes\",\"type\":\"bytes32[]\"}],\"name\":\"batchUpdateData\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"bytes\",\"name\":\"nodeId\",\"type\":\"bytes\"}],\"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\"}],\"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\":\"contentHash\",\"type\":\"bytes32\"}],\"name\":\"updateData\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"bytes\",\"name\":\"nodeId\",\"type\":\"bytes\"},{\"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 => DataRecord) public nodeData;\\r\\n\\r\\n\\tevent DataUpdated(\\r\\n\\t\\tbytes indexed nodeId,\\r\\n\\t\\tbytes32 contentHash,\\r\\n\\t\\taddress updater\\r\\n\\t);\\r\\n\\r\\n\\tfunction updateData(bytes memory nodeId, bytes32 contentHash) public {\\r\\n\\t\\tnodeData[nodeId] = DataRecord(contentHash, block.timestamp, msg.sender);\\r\\n\\t\\temit DataUpdated(nodeId, contentHash, msg.sender);\\r\\n\\t}\\r\\n\\r\\n\\tfunction verifyData(\\r\\n\\t\\tbytes memory nodeId,\\r\\n\\t\\tbytes32 contentHash\\r\\n\\t) public view returns (bool, uint256, address) {\\r\\n\\t\\tDataRecord memory record = nodeData[nodeId];\\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) public view returns (bytes32, uint256, address) {\\r\\n\\t\\tDataRecord memory record = nodeData[nodeId];\\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 contentHashes\\r\\n\\t) public {\\r\\n\\t\\trequire(\\r\\n\\t\\t\\tnodeIds.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], contentHashes[i]);\\r\\n\\t\\t}\\r\\n\\t}\\r\\n}\\r\\n\",\"keccak256\":\"0x1ed77b1882586a77f3e6d5bf176009c5f00b9d91f71cfd6153ca2d57ef30831d\",\"license\":\"MIT\"}},\"version\":1}",
178
- "bytecode": "0x608060405234801561001057600080fd5b506106a0806100206000396000f3fe608060405234801561001057600080fd5b50600436106100575760003560e01c80630d36830e1461005c5780630f07e48514610071578063d236feda14610084578063d54193d7146100c2578063d58a3de3146100f9575b600080fd5b61006f61006a3660046104a8565b61013c565b005b61006f61007f36600461057c565b6101e9565b61009761009236600461057c565b6102a2565b60408051931515845260208401929092526001600160a01b0316908201526060015b60405180910390f35b6100d56100d03660046105c1565b610302565b6040805193845260208401929092526001600160a01b0316908201526060016100b9565b6100d56101073660046105c1565b80516020818301810180516000825292820191909301209152805460018201546002909201549091906001600160a01b031683565b805182511461018a5760405162461bcd60e51b8152602060048201526016602482015275082e4e4c2f2e640d8cadccee8d040dad2e6dac2e8c6d60531b604482015260640160405180910390fd5b60005b82518110156101e4576101d28382815181106101ab576101ab6105fe565b60200260200101518383815181106101c5576101c56105fe565b60200260200101516101e9565b806101dc81610614565b91505061018d565b505050565b604080516060810182528281524260208201523381830152905160009061021190859061063b565b908152604080516020928190038301812084518155928401516001840155920151600290910180546001600160a01b0319166001600160a01b0390921691909117905561025f90839061063b565b60408051918290038220838352336020840152917fac3d4f3cbf6818c9329b6b8c61e41d9dc52fc1cc580fff6af273be3ebc1d423f910160405180910390a25050565b6000806000806000866040516102b8919061063b565b9081526040805160209281900383018120606082018352805480835260018201549483018590526002909101546001600160a01b0316919092018190529614979096509350505050565b600080600080600085604051610318919061063b565b9081526040805160209281900383018120606082018352805480835260018201549483018590526002909101546001600160a01b0316919092018190529097919650945092505050565b634e487b7160e01b600052604160045260246000fd5b604051601f8201601f1916810167ffffffffffffffff811182821017156103a1576103a1610362565b604052919050565b600067ffffffffffffffff8211156103c3576103c3610362565b5060051b60200190565b600082601f8301126103de57600080fd5b813567ffffffffffffffff8111156103f8576103f8610362565b61040b601f8201601f1916602001610378565b81815284602083860101111561042057600080fd5b816020850160208301376000918101602001919091529392505050565b600082601f83011261044e57600080fd5b8135602061046361045e836103a9565b610378565b82815260059290921b8401810191818101908684111561048257600080fd5b8286015b8481101561049d5780358352918301918301610486565b509695505050505050565b600080604083850312156104bb57600080fd5b823567ffffffffffffffff808211156104d357600080fd5b818501915085601f8301126104e757600080fd5b813560206104f761045e836103a9565b82815260059290921b8401810191818101908984111561051657600080fd5b8286015b8481101561054e578035868111156105325760008081fd5b6105408c86838b01016103cd565b84525091830191830161051a565b509650508601359250508082111561056557600080fd5b506105728582860161043d565b9150509250929050565b6000806040838503121561058f57600080fd5b823567ffffffffffffffff8111156105a657600080fd5b6105b2858286016103cd565b95602094909401359450505050565b6000602082840312156105d357600080fd5b813567ffffffffffffffff8111156105ea57600080fd5b6105f6848285016103cd565b949350505050565b634e487b7160e01b600052603260045260246000fd5b60006001820161063457634e487b7160e01b600052601160045260246000fd5b5060010190565b6000825160005b8181101561065c5760208186018101518583015201610642565b50600092019182525091905056fea2646970667358221220c3ea212644c861f0e892deb0129df945a7fa2af5971e51e4b97810c73fc547f764736f6c63430008110033",
179
- "deployedBytecode": "0x608060405234801561001057600080fd5b50600436106100575760003560e01c80630d36830e1461005c5780630f07e48514610071578063d236feda14610084578063d54193d7146100c2578063d58a3de3146100f9575b600080fd5b61006f61006a3660046104a8565b61013c565b005b61006f61007f36600461057c565b6101e9565b61009761009236600461057c565b6102a2565b60408051931515845260208401929092526001600160a01b0316908201526060015b60405180910390f35b6100d56100d03660046105c1565b610302565b6040805193845260208401929092526001600160a01b0316908201526060016100b9565b6100d56101073660046105c1565b80516020818301810180516000825292820191909301209152805460018201546002909201549091906001600160a01b031683565b805182511461018a5760405162461bcd60e51b8152602060048201526016602482015275082e4e4c2f2e640d8cadccee8d040dad2e6dac2e8c6d60531b604482015260640160405180910390fd5b60005b82518110156101e4576101d28382815181106101ab576101ab6105fe565b60200260200101518383815181106101c5576101c56105fe565b60200260200101516101e9565b806101dc81610614565b91505061018d565b505050565b604080516060810182528281524260208201523381830152905160009061021190859061063b565b908152604080516020928190038301812084518155928401516001840155920151600290910180546001600160a01b0319166001600160a01b0390921691909117905561025f90839061063b565b60408051918290038220838352336020840152917fac3d4f3cbf6818c9329b6b8c61e41d9dc52fc1cc580fff6af273be3ebc1d423f910160405180910390a25050565b6000806000806000866040516102b8919061063b565b9081526040805160209281900383018120606082018352805480835260018201549483018590526002909101546001600160a01b0316919092018190529614979096509350505050565b600080600080600085604051610318919061063b565b9081526040805160209281900383018120606082018352805480835260018201549483018590526002909101546001600160a01b0316919092018190529097919650945092505050565b634e487b7160e01b600052604160045260246000fd5b604051601f8201601f1916810167ffffffffffffffff811182821017156103a1576103a1610362565b604052919050565b600067ffffffffffffffff8211156103c3576103c3610362565b5060051b60200190565b600082601f8301126103de57600080fd5b813567ffffffffffffffff8111156103f8576103f8610362565b61040b601f8201601f1916602001610378565b81815284602083860101111561042057600080fd5b816020850160208301376000918101602001919091529392505050565b600082601f83011261044e57600080fd5b8135602061046361045e836103a9565b610378565b82815260059290921b8401810191818101908684111561048257600080fd5b8286015b8481101561049d5780358352918301918301610486565b509695505050505050565b600080604083850312156104bb57600080fd5b823567ffffffffffffffff808211156104d357600080fd5b818501915085601f8301126104e757600080fd5b813560206104f761045e836103a9565b82815260059290921b8401810191818101908984111561051657600080fd5b8286015b8481101561054e578035868111156105325760008081fd5b6105408c86838b01016103cd565b84525091830191830161051a565b509650508601359250508082111561056557600080fd5b506105728582860161043d565b9150509250929050565b6000806040838503121561058f57600080fd5b823567ffffffffffffffff8111156105a657600080fd5b6105b2858286016103cd565b95602094909401359450505050565b6000602082840312156105d357600080fd5b813567ffffffffffffffff8111156105ea57600080fd5b6105f6848285016103cd565b949350505050565b634e487b7160e01b600052603260045260246000fd5b60006001820161063457634e487b7160e01b600052601160045260246000fd5b5060010190565b6000825160005b8181101561065c5760208186018101518583015201610642565b50600092019182525091905056fea2646970667358221220c3ea212644c861f0e892deb0129df945a7fa2af5971e51e4b97810c73fc547f764736f6c63430008110033",
180
- "devdoc": {
181
- "kind": "dev",
182
- "methods": {},
183
- "version": 1
184
- },
185
- "userdoc": {
186
- "kind": "user",
187
- "methods": {},
188
- "version": 1
189
- },
190
- "storageLayout": {
191
- "storage": [
192
- {
193
- "astId": 13,
194
- "contract": "contracts/SHINE.sol:SHINE",
195
- "label": "nodeData",
196
- "offset": 0,
197
- "slot": "0",
198
- "type": "t_mapping(t_bytes_memory_ptr,t_struct(DataRecord)8_storage)"
199
- }
200
- ],
201
- "types": {
202
- "t_address": {
203
- "encoding": "inplace",
204
- "label": "address",
205
- "numberOfBytes": "20"
206
- },
207
- "t_bytes32": {
208
- "encoding": "inplace",
209
- "label": "bytes32",
210
- "numberOfBytes": "32"
211
- },
212
- "t_bytes_memory_ptr": {
213
- "encoding": "bytes",
214
- "label": "bytes",
215
- "numberOfBytes": "32"
216
- },
217
- "t_mapping(t_bytes_memory_ptr,t_struct(DataRecord)8_storage)": {
218
- "encoding": "mapping",
219
- "key": "t_bytes_memory_ptr",
220
- "label": "mapping(bytes => struct SHINE.DataRecord)",
221
- "numberOfBytes": "32",
222
- "value": "t_struct(DataRecord)8_storage"
223
- },
224
- "t_struct(DataRecord)8_storage": {
225
- "encoding": "inplace",
226
- "label": "struct SHINE.DataRecord",
227
- "members": [
228
- {
229
- "astId": 3,
230
- "contract": "contracts/SHINE.sol:SHINE",
231
- "label": "contentHash",
232
- "offset": 0,
233
- "slot": "0",
234
- "type": "t_bytes32"
235
- },
236
- {
237
- "astId": 5,
238
- "contract": "contracts/SHINE.sol:SHINE",
239
- "label": "timestamp",
240
- "offset": 0,
241
- "slot": "1",
242
- "type": "t_uint256"
243
- },
244
- {
245
- "astId": 7,
246
- "contract": "contracts/SHINE.sol:SHINE",
247
- "label": "updater",
248
- "offset": 0,
249
- "slot": "2",
250
- "type": "t_address"
251
- }
252
- ],
253
- "numberOfBytes": "96"
254
- },
255
- "t_uint256": {
256
- "encoding": "inplace",
257
- "label": "uint256",
258
- "numberOfBytes": "32"
259
- }
260
- }
261
- }
262
- }
@@ -1,52 +0,0 @@
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 => DataRecord) public nodeData;
12
-
13
- event DataUpdated(
14
- bytes indexed nodeId,
15
- bytes32 contentHash,
16
- address updater
17
- );
18
-
19
- function updateData(bytes memory nodeId, bytes32 contentHash) public {
20
- nodeData[nodeId] = DataRecord(contentHash, block.timestamp, msg.sender);
21
- emit DataUpdated(nodeId, contentHash, msg.sender);
22
- }
23
-
24
- function verifyData(
25
- bytes memory nodeId,
26
- bytes32 contentHash
27
- ) public view returns (bool, uint256, address) {
28
- DataRecord memory record = nodeData[nodeId];
29
- bool isValid = record.contentHash == contentHash;
30
- return (isValid, record.timestamp, record.updater);
31
- }
32
-
33
- function getLatestRecord(
34
- bytes memory nodeId
35
- ) public view returns (bytes32, uint256, address) {
36
- DataRecord memory record = nodeData[nodeId];
37
- return (record.contentHash, record.timestamp, record.updater);
38
- }
39
-
40
- function batchUpdateData(
41
- bytes[] memory nodeIds,
42
- bytes32[] memory contentHashes
43
- ) public {
44
- require(
45
- nodeIds.length == contentHashes.length,
46
- "Arrays length mismatch"
47
- );
48
- for (uint i = 0; i < nodeIds.length; i++) {
49
- updateData(nodeIds[i], contentHashes[i]);
50
- }
51
- }
52
- }