A library that calculates the CSP hash for amp-script
npm install @ampproject/toolbox-script-csp

Calculates the Content Security Policy (CSP)
hash for the given script in the format expected by amp-script.
CSP is required when using amp-script with inline or cross-origin scripts.
Install via:
```
$ npm install @ampproject/toolbox-script-csp
The module exposes a single function, calculateHash(src, options?).
src can be either a string (in which case UTF8 encoding is assumed) or aDataViewBuffer
such as a .
options is used to override the default options.
#### Options
* algorithm overrides the hashing algorithm to use. Currently, the onlyamp-script
algorithm supported by is sha384 which is the default value.
Here is an example on how to use the calculateHash function to generate anamp-script CSP header.
Note that both leading and trailing whitespace is included in calculating the
hash and must exactly match the whitespace used in the inline script.
`javascript
const {calculateHash} = require('@ampproject/toolbox-script-csp');
const script =
const subject = 'world';
console.log('Hello, ' + subject);
;
const hash = calculateHash(script);
console.log(hash); // sha384-xRxb5sv13at6tVgZET4JLmf89TSZP10HjCGXVqO9bKWVXB0asV2jLrsDN8v4zX6j
`
The generated hash can be used in a tag this way:
`html
...
``