Skip to content

Commit 2701a04

Browse files
committed
get key from params in pdp
1 parent fd8dabe commit 2701a04

File tree

1 file changed

+53
-4
lines changed

1 file changed

+53
-4
lines changed

contracts/PDP.sol

Lines changed: 53 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import "./type.sol";
77
import "./interface.sol";
88

99
contract PDP is Initializable, IPDP, IFsEvent {
10-
1110
using IterableMapping for ProofsPool;
1211
ProofsPool proofsPool;
1312

@@ -117,9 +116,13 @@ contract PDP is Initializable, IPDP, IFsEvent {
117116
return pReturns;
118117
}
119118

120-
function VerifyProofWithMerklePathForFile(
121-
ProofParams memory vParams
122-
) public view virtual override returns (bool) {
119+
function VerifyProofWithMerklePathForFile(ProofParams memory vParams)
120+
public
121+
view
122+
virtual
123+
override
124+
returns (bool)
125+
{
123126
// TODO
124127
console.log(vParams.Version);
125128
return true;
@@ -136,6 +139,51 @@ contract PDP is Initializable, IPDP, IFsEvent {
136139
console.log(vParams.Index);
137140
return true;
138141
}
142+
143+
function GetKeyByProofParams(ProofParams memory vParams)
144+
public
145+
pure
146+
returns (bytes memory)
147+
{
148+
bytes memory ids;
149+
for (uint32 i = 0; i < vParams.FileIds.length; i++) {
150+
ids = abi.encodePacked(ids, vParams.FileIds[i]);
151+
}
152+
bytes memory tags;
153+
for (uint32 i = 0; i < vParams.Tags.length; i++) {
154+
tags = abi.encodePacked(tags, vParams.Tags[i]);
155+
}
156+
bytes memory challenges;
157+
for (uint32 i = 0; i < vParams.Challenges.length; i++) {
158+
challenges = abi.encodePacked(
159+
challenges,
160+
vParams.Challenges[i].Index,
161+
vParams.Challenges[i].Rand
162+
);
163+
}
164+
bytes memory merklePath;
165+
for (uint32 i = 0; i < vParams.MerklePath_.length; i++) {
166+
merklePath = abi.encodePacked(
167+
merklePath,
168+
vParams.MerklePath_[i].PathLen
169+
);
170+
}
171+
string memory keyStr = string(
172+
abi.encodePacked(
173+
vParams.Version,
174+
vParams.Proofs,
175+
ids,
176+
tags,
177+
challenges,
178+
merklePath,
179+
vParams.RootHashes
180+
)
181+
);
182+
bytes memory keyBytes = bytes(keyStr);
183+
bytes32 key32 = keccak256(keyBytes);
184+
bytes memory key = abi.encodePacked(key32);
185+
return key;
186+
}
139187
}
140188

141189
// map
@@ -152,6 +200,7 @@ struct ProofsPool {
152200
KeyFlag[] keys;
153201
uint256 size;
154202
}
203+
155204
library IterableMapping {
156205
function insert(
157206
ProofsPool storage self,

0 commit comments

Comments
 (0)