[BUG] sha256 filter fails on node.js
Describe the bug
The sha256 filter contains the following code:
return sjcl.codec.hex.fromBits(sjcl.hash.sha256.hash(text)).substr(0,length);
But on node.js (for example, when running in TiddlyDesktop with a wiki folder) there's no global sjcl object available until it's been require()d.
Expected behavior
This can be solved by going into boot.js and adding $tw.sjcl = sjcl; right before the this.setPassword = ... line. Then edit core/modules/filters/crypto.js and change the two occurrences of sjcl to $tw.sjcl.
To Reproduce
- Install TiddlyDesktop
- Create a new wiki folder
- Open it
- Hit F12 to open the developer console
- Create a new tiddler
You'll see errors about sjcl not being found in the developer console.
Screenshots
No response
TiddlyWiki Configuration
- Version: v5.3.3
- Saving mechanism: TiddlyDesktop 0.18.0
- Plugins installed: None, default wiki folder in TiddlyDesktop
Desktop (please complete the following information):
- OS: Linux
- Browser NW.js from TiddlyDesktop
- Version NW.js 0.84.0 (bug also occurs in NW.js 0.77.0 which is included in TiddlyDesktop 0.18.0)
Additional context
I believe this may be the cause of https://github.com/TiddlyWiki/TiddlyDesktop/issues/285. I was experiencing that issue as well, but once I solved the sjcl issue, I was able to create new tiddlers just fine.
Thanks @rmunn that's excellent sleuthing, would you like to prepare a PR?
@Jermolene - Sure. https://github.com/Jermolene/TiddlyWiki5/pull/8007