mirror of
https://github.com/simplex-chat/simplex-chat.git
synced 2026-11-04 10:47:32 +00:00
store: take a 32-byte node in resolver digests
This commit is contained in:
1 parent
7436713776
commit
240d9401f9
2 files changed
+14
-9
No files matched your search
@@ -4,6 +4,8 @@
|
||||
module StoreService.Names.Registration
|
||||
( Registration (..),
|
||||
RegisterIntent (..),
|
||||
Node,
|
||||
namehash,
|
||||
sponsorDomain,
|
||||
resolverDomain,
|
||||
makeCommitment,
|
||||
@@ -44,6 +46,9 @@ data Registration = Registration
|
||||
rChannelLink :: Maybe Text
|
||||
}
|
||||
|
||||
-- | Only built by 'namehash', so it always holds 32 bytes.
|
||||
newtype Node = Node ByteString
|
||||
|
||||
data RegisterIntent = RegisterIntent
|
||||
{ riRegistration :: Registration,
|
||||
riNonce :: Word64,
|
||||
@@ -94,22 +99,22 @@ verifyRegisterIntent domain now RegisterIntent {riRegistration = r@Registration
|
||||
signer <- ExceptT $ recoverAddress riSignature $ registerIntentDigest domain r riNonce riDeadline
|
||||
unless (signer == rOwner) $ throwError "intent is not signed by the owner"
|
||||
|
||||
setTextDigest :: Eip712Domain -> ByteString -> Text -> Text -> Word64 -> Word64 -> ByteString
|
||||
setTextDigest :: Eip712Domain -> Node -> Text -> Text -> Word64 -> Word64 -> ByteString
|
||||
setTextDigest domain node key value nonce deadline =
|
||||
hashTypedData
|
||||
domain
|
||||
"SetText(bytes32 node,string key,string value,uint256 nonce,uint256 deadline)"
|
||||
[bytes32 node, VBytes $ encodeUtf8 key, VBytes $ encodeUtf8 value, VUint $ fromIntegral nonce, VUint $ fromIntegral deadline]
|
||||
|
||||
clearRecordsDigest :: Eip712Domain -> ByteString -> Word64 -> Word64 -> ByteString
|
||||
clearRecordsDigest :: Eip712Domain -> Node -> Word64 -> Word64 -> ByteString
|
||||
clearRecordsDigest domain node nonce deadline =
|
||||
hashTypedData
|
||||
domain
|
||||
"ClearRecords(bytes32 node,uint256 nonce,uint256 deadline)"
|
||||
[bytes32 node, VUint $ fromIntegral nonce, VUint $ fromIntegral deadline]
|
||||
|
||||
bytes32 :: ByteString -> Eip712Value
|
||||
bytes32 = VUint . fromInteger . os2ip
|
||||
bytes32 :: Node -> Eip712Value
|
||||
bytes32 (Node node) = VUint $ fromInteger $ os2ip node
|
||||
|
||||
registrationTuple :: Registration -> ByteString
|
||||
registrationTuple r@Registration {rLabel, rOwner, rDuration, rSecret, rResolver} =
|
||||
@@ -134,9 +139,9 @@ recordCalls Registration {rLabel, rTLD, rContactLink, rChannelLink} =
|
||||
setText key link =
|
||||
selector "setText(bytes32,string,string)"
|
||||
<> abiTuple [Static node, Dynamic $ abiBytes key, Dynamic $ abiBytes $ encodeUtf8 link]
|
||||
node = namehash rTLD rLabel
|
||||
Node node = namehash rTLD rLabel
|
||||
|
||||
namehash :: SimplexTLD -> Text -> ByteString
|
||||
namehash tld label = keccak256 $ tldNode <> keccak256 (encodeUtf8 label)
|
||||
namehash :: SimplexTLD -> Text -> Node
|
||||
namehash tld label = Node $ keccak256 $ tldNode <> keccak256 (encodeUtf8 label)
|
||||
where
|
||||
tldNode = keccak256 $ B.replicate 32 0 <> keccak256 (B.drop 1 $ strEncode tld)
|
||||
@@ -30,9 +30,9 @@ namesSignatureTests = describe "StoreService names: signatures" $ do
|
||||
it "hashes RegisterName" $
|
||||
registerIntentDigest (sponsorDomain chainId sponsor) dynamis 0 1800000000 `shouldBe` hx "0x4b0bcc282db581446f6c25e0e3fbe2839409acbc011bb3e082523dd9eab85a6a"
|
||||
it "hashes SetText" $
|
||||
setTextDigest (resolverDomain chainId resolver) node "simplex.contact" "https://x" 3 99 `shouldBe` hx "0xa62d4320889eed3713462d725dc298cd96885572b8e6b424e93a205a96b96fb5"
|
||||
setTextDigest (resolverDomain chainId resolver) (namehash TLDSimplex "dynamis") "simplex.contact" "https://x" 3 99 `shouldBe` hx "0xa62d4320889eed3713462d725dc298cd96885572b8e6b424e93a205a96b96fb5"
|
||||
it "hashes ClearRecords" $
|
||||
clearRecordsDigest (resolverDomain chainId resolver) node 4 99 `shouldBe` hx "0xca4bd243288f27f38e3b45384ba36ce685ff155352cf8125f031e6fb189a46dd"
|
||||
clearRecordsDigest (resolverDomain chainId resolver) (namehash TLDSimplex "dynamis") 4 99 `shouldBe` hx "0xca4bd243288f27f38e3b45384ba36ce685ff155352cf8125f031e6fb189a46dd"
|
||||
describe "EIP-191 messages" $ do
|
||||
it "signs an order" $
|
||||
testMessage
|
||||
|
||||
Reference in new issue
Block a user