2021-10-12 14:59:34 +00:00
|
|
|
const { ethers } = require("hardhat")
|
|
|
|
|
2021-11-02 08:45:49 +00:00
|
|
|
function hashRequest({
|
2022-02-09 13:17:23 +00:00
|
|
|
duration,
|
|
|
|
size,
|
|
|
|
contentHash,
|
|
|
|
proofPeriod,
|
|
|
|
proofTimeout,
|
|
|
|
nonce,
|
2021-11-02 08:45:49 +00:00
|
|
|
}) {
|
2021-10-20 12:28:05 +00:00
|
|
|
const type = "[dagger.request.v1]"
|
2022-02-09 13:17:23 +00:00
|
|
|
return ethers.utils.keccak256(
|
|
|
|
ethers.utils.defaultAbiCoder.encode(
|
|
|
|
["string", "uint", "uint", "bytes32", "uint", "uint", "bytes32"],
|
|
|
|
[type, duration, size, contentHash, proofPeriod, proofTimeout, nonce]
|
|
|
|
)
|
|
|
|
)
|
2021-10-12 14:59:34 +00:00
|
|
|
}
|
|
|
|
|
2022-02-09 13:17:23 +00:00
|
|
|
function hashBid({ requestHash, bidExpiry, price }) {
|
2021-10-20 12:28:05 +00:00
|
|
|
const type = "[dagger.bid.v1]"
|
2022-02-09 13:17:23 +00:00
|
|
|
return ethers.utils.keccak256(
|
|
|
|
ethers.utils.defaultAbiCoder.encode(
|
|
|
|
["string", "bytes32", "uint", "uint"],
|
|
|
|
[type, requestHash, bidExpiry, price]
|
|
|
|
)
|
|
|
|
)
|
2021-10-12 14:59:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
async function sign(signer, hash) {
|
|
|
|
return await signer.signMessage(ethers.utils.arrayify(hash))
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = { hashRequest, hashBid, sign }
|