Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature]: Add JS API for leveraging staticrypt in code #195

Open
bmcminn opened this issue Mar 14, 2024 · 2 comments
Open

[Feature]: Add JS API for leveraging staticrypt in code #195

bmcminn opened this issue Mar 14, 2024 · 2 comments

Comments

@bmcminn
Copy link

bmcminn commented Mar 14, 2024

I have a plugin based static site generator that I would like to be able to staticrypt with.

It currently uses top-down render pipeline via a series of callbacks similar to Grunt.js, and it would be excellent if there was a JS API I could leverage in my codebase to generate the encrypted artifact.

I have a workaround in mind where I can write a plugin to write the contents to the output path and then encrypt the resulting output document on disk.

Having briefly looked at the codebase, I'm not sure where to start with a PR on this functionality, but I am curious if this is something y'all have considered or roadmapped?

@robinmoisson
Copy link
Owner

robinmoisson commented Apr 17, 2024

Interesting! So basically the idea would be to be able to have a

import passwordProtect from 'staticrypt';

const passwordProtectedHtml = passwordProtect(plainTextHtml);

// write on disk, do whatever

Something like that?

A couple of places that can be used for inspiration are the index_template.html, which shows how to encrypt a file in-browser, or you can check-out how the encodeWithHashedPassword function from the codec.js file is used (with the await cryptoEngine.hashPassword(password, salt)).

As I'm writing this I'm realizing it might just be a matter of doing something like

const hashedPassword = await cryptoEngine.hashPassword(password, salt);
const passwordProtectedHtml = await codec.init(cryptoEngine).encodeWithHashedPassword(plainTextHtml, hashedPassword);

I guess there could be a wrapper with a simpler API if needed.

One footgun here is on the salt - the remember-me feature (or auto-decrypt link) is dependent on the salt staying constant if you encrypt the file multiple times. That's why staticrypt generates a .staticrypt.json config file with just the salt by default (see more here).

@bmcminn
Copy link
Author

bmcminn commented Apr 17, 2024

That points me in the right direction at least :)

I think this project needs more documented samples like this where the functionality I'm looking for technically exists, but it isn't surfaced very well in the existing documentation, and the gotchas (like the salt in .staticrypt.json) are noted but no remedies or boilerplate are suggested.

I would def be inclined to tinker with your suggestions and formulate some cookbook style snippets to accomplish my goals and submit them back to the project README.md :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants