forked from veramolabs/did-eth
-
Notifications
You must be signed in to change notification settings - Fork 0
/
didETH.sol
85 lines (72 loc) · 3.05 KB
/
didETH.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
//SPDX-License-Identifier: BUSL-1.1
pragma solidity ^0.8.13;
import "../../Eip712/Eip712CheckerInternal.sol";
import "../../libraries/DocumentStorage.sol";
import "../../libraries/documents/didETHStorage.sol";
import {Document} from "../../shared/Types.sol";
import "@solidstate/contracts/access/access_control/AccessControlInternal.sol";
/// @title DID
/// @notice Contract that represents the DID Document storage
contract didETH {
bytes32 private constant Create_TYPEHASH =
keccak256("CreateDID(address owner, int256 documentId, string info)");
int256 private constant ResolverVersion = 1;
event DIDCreated(address owner, int256 documentId);
event DIDUpdatedInfo(int256 documentId);
event DIDUpdatedOwner(int256 documentId, address newOwner);
/* solhint-disable no-inline-assembly */
function getStorageAddress() external view returns (address proxyAddress) {
didETHStorage.Storage storage s = didETHStorage.getStorage();
proxyAddress = s.idProxyAddress;
}
/// @notice Creates a new DID document
/// @param owner The address of the owner
/// @param documentId the id of the document
/// @param info the string of the document info
function createDIDWithPointer(
address owner,
int256 documentId,
string calldata info
) external {
didETHStorage.Storage storage s = didETHStorage.getStorage();
address idProxyAddress = s.idProxyAddress;
mapping(int256 => Document) storage ns = DocumentStorage
.getStoragePointer(idProxyAddress);
ns[documentId].owner = owner;
ns[documentId].info = info;
ns[documentId].version = 1;
emit DIDCreated(owner, documentId);
}
/// @notice updates a DID document
/// @param documentId the id of the document
/// @param info the string of the document info
function updateDidInfoWithPointer(
int256 documentId,
string calldata info
) external {
didETHStorage.Storage storage s = didETHStorage.getStorage();
address idProxyAddress = s.idProxyAddress;
mapping(int256 => Document) storage ns = DocumentStorage
.getStoragePointer(idProxyAddress);
address owner = ns[documentId].owner;
require(msg.sender == owner, "Only document owner");
ns[documentId].info = info;
emit DIDUpdatedInfo(documentId);
}
/// @notice updates a DID document owner
/// @param documentId the id of the document
/// @param newOwner the adress of the document info
function updateDidOwnerWithPointer(
int256 documentId,
address newOwner
) external {
didETHStorage.Storage storage s = didETHStorage.getStorage();
address idProxyAddress = s.idProxyAddress;
mapping(int256 => Document) storage ns = DocumentStorage
.getStoragePointer(idProxyAddress);
address owner = ns[documentId].owner;
require(msg.sender == owner, "Only document owner");
ns[documentId].owner = newOwner;
emit DIDUpdatedOwner(documentId, newOwner);
}
}