1

If I have someone's signature and I want to use it in a mapping, is there a way to have it serve as the key in that mapping?

Would I need to use mapping (string => uint), or mapping (bytes32 => uint), or would I first need to hash the signature?

AlwaysQuestioning
  • 571
  • 1
  • 6
  • 15

1 Answers1

1

Using string or bytes (not bytes32) will work in the most recent version of solidity, but using the hash is more elegant as your mapping key will be 32 bytes exactly and then you can use mapping(bytes32 => uint).

Hope this helps

Jaime
  • 8,340
  • 1
  • 12
  • 20
  • I'm thinking about gas considerations here, as hashing is costly (is it not)?

    Would you still recommend that if I were accessing (storing) to this mapping frequently?

    – AlwaysQuestioning Jun 10 '18 at 13:24
  • Is not, taking the hash (keccak256) of a bytes variable of length 64 cost about 900 gas. See this question for the prices of keccak256 and other hash functions – Jaime Jun 10 '18 at 13:34