Skip to content

Commit

Permalink
docs: mi/466/hash-verification
Browse files Browse the repository at this point in the history
Added Max's JS example for verifying the hash
  • Loading branch information
hajjimo committed Dec 19, 2024
1 parent 0040ace commit 48bcf4e
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions docs/src/content/docs/introduction/hash-verification.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,27 @@ x-gguKWTj8rQf7d7i3w3UhzvuJ5bpOlKyAlVpLxBffY

When the client receives a redirect from the AS, the AS will include the hash parameter in the response. The client must calculate this exact value by concatenating the fields referenced above and then applying the `sha-256` hashing algorithm. If the hash value matches the parameter sent by the AS, then the client can be certain the redirect emanated from the AS.

The example below demonstrates how to verify the hash received from the AS using a function in Javascript.

<CodeBlock title="JavaScript example">

```javascript
function verifyHash(
clientNonce,
interactNonce,
interactRef,
authServerUrl,
receivedHash
) {
const data = `${clientNonce}\n${interactNonce}\n${interactRef}\n${authServerUrl}/`
const hash = createHash('sha-256').update(data).digest('base64')

return hash === receivedHash
}
```

</CodeBlock>

## Further reading

For more information refer to the <LinkOut href='https://datatracker.ietf.org/doc/html/draft-ietf-gnap-core-protocol-20#name-calculating-the-interaction'>Calculating the interaction hash</LinkOut> section of the GNAP specification.

0 comments on commit 48bcf4e

Please sign in to comment.