TiddlyWiki5 icon indicating copy to clipboard operation
TiddlyWiki5 copied to clipboard

[BUG] sha256 filter fails on node.js

Open rmunn opened this issue 2 years ago • 1 comments

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

  1. Install TiddlyDesktop
  2. Create a new wiki folder
  3. Open it
  4. Hit F12 to open the developer console
  5. 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.

rmunn avatar Feb 24 '24 08:02 rmunn

Thanks @rmunn that's excellent sleuthing, would you like to prepare a PR?

Jermolene avatar Feb 24 '24 09:02 Jermolene

@Jermolene - Sure. https://github.com/Jermolene/TiddlyWiki5/pull/8007

rmunn avatar Feb 25 '24 23:02 rmunn