MoralisWeb3 / docs

Official documentation of Moralis Web3
https://docs.moralis.io
28 stars 123 forks source link

Documentation improvements for: /streams-api/evm/webhook-security #140

Closed lemonyatko closed 1 year ago

lemonyatko commented 1 year ago

Is your feature request related to a problem? Please describe. outdated docs or not matching with another doc

Describe the solution you'd like replace js code example with native method of your package

import Moralis from "moralis";

const { headers, body } = request;

Moralis.Streams.verifySignature({
  body,
  signature: headers["x-signature"],
}); // throws error if not valid

Describe alternatives you've considered or just add this code as alternative

Additional context

YosephKS commented 1 year ago

Hey @lemonyatko,

Thanks for creating an issue here 😄

Can you clarify what is outdated on the docs? The code should have been up-to-date and looks like it's all using the SDK methods.

If you can point to the details of individual pages, let me know about it and I can work on it

lemonyatko commented 1 year ago

here there is this code:

const verifySignature = (req, secret) => {

    const providedSignature = req.headers["x-signature"]
    if(!providedSignature) throw new Error("Signature not provided")
    const generatedSignature= web3.utils.sha3(JSON.stringify(req.body)+secret)
    if(generatedSignature !== providedSignature) throw new Error("Invalid Signature")

}

as i can see 'web3' is a separated npm package, but you have built-in verifySignature method in your package. i chose a bit wrong word (outdated). It just would be great to see verifySignature method from your package here as replacement or alternative of code above.

btw same code here

YosephKS commented 1 year ago

Hey @lemonyatko,

Thanks for the details! Understood.

Let me get back to the devs and see whether this is equivalent to our verifySignature API. If so, we can make the changes to instead use Moralis API for this.

I'll get back to you once I have a reply.

YosephKS commented 1 year ago

Hey @lemonyatko

I just got word from our devs and looks like while the function has the same name as our API, they are not equivalent and therefore not replaceable to our verifySignature API.

For now, I'm going to close this issue, but feel free to create a new one if you found any other issue arises~

Have a nice day!

lemonyatko commented 1 year ago

So what is better, to use the native method or to use web3 lib?