Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
purescript-gargantext
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Grégoire Locqueville
purescript-gargantext
Commits
874bc571
Verified
Commit
874bc571
authored
Sep 07, 2023
by
Przemyslaw Kaminski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[crypto] fix tests
parent
56b10f97
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
18 additions
and
5 deletions
+18
-5
Crypto.js
src/Gargantext/Utils/Crypto.js
+2
-2
Crypto.purs
src/Gargantext/Utils/Crypto.purs
+3
-2
crypto.js
src/external-deps/crypto.js
+12
-0
Spec.purs
test/Test/Gargantext/Utils/Spec.purs
+1
-1
No files found.
src/Gargantext/Utils/Crypto.js
View file @
874bc571
//import crypto from 'crypto
';
import
{
subtle
}
from
'../../src/external-deps/crypto.js
'
;
async
function
getSHA256Hash
(
input
)
{
const
textAsBuffer
=
new
TextEncoder
().
encode
(
input
);
const
hashBuffer
=
await
globalThis
.
crypto
.
subtle
.
digest
(
"SHA-256"
,
textAsBuffer
);
const
hashBuffer
=
await
subtle
.
digest
(
"SHA-256"
,
textAsBuffer
);
const
hashArray
=
Array
.
from
(
new
Uint8Array
(
hashBuffer
));
const
hash
=
hashArray
.
map
((
item
)
=>
item
.
toString
(
16
).
padStart
(
2
,
"0"
))
...
...
src/Gargantext/Utils/Crypto.purs
View file @
874bc571
module Gargantext.Utils.Crypto where
import Control.Promise (Promise, toAffE)
import Data.Array as Array
import Data.Set (Set)
import Data.Set as Set
import Data.
Array as Array
import Data.
String (joinWith)
import Effect (Effect)
import Effect.Aff (Aff)
...
...
@@ -39,7 +40,7 @@ instance IsHashable (Array String) where
hash = hash <<< concat
where
concat :: Array Hash -> String
concat =
Array.foldl (<>) ""
concat =
joinWith "" <<< Array.sort
instance IsHashable (Set String) where
...
...
src/external-deps/crypto.js
0 → 100644
View file @
874bc571
// https://siteultra.com/blog/using-subtle-in-a-javascript-module-from-both-the-browser-and-nodejs
let
subtle
=
undefined
;
if
(
typeof
window
!==
'undefined'
&&
window
.
crypto
&&
window
.
crypto
.
subtle
)
{
subtle
=
window
.
crypto
.
subtle
;
}
else
{
// Import 'crypto' module in Node.js environment
subtle
=
require
(
'crypto'
).
subtle
;
}
exports
.
subtle
=
subtle
;
test/Test/Gargantext/Utils/Spec.purs
View file @
874bc571
...
...
@@ -124,7 +124,7 @@ spec =
it "Hash List with backend works" do
let list = ["a","b"]
let hashed = "
ab19ec537f09499b26f0f62eed7aefad46ab9f498e06a7328ce8e8ef90da6d86
"
let hashed = "
fb8e20fc2e4c3f248c60c39bd652f3c1347298bb977b8b4d5903b85055620603
"
-- ^ hash from backend with text above
h <- Crypto.hash list
h`shouldEqual` hashed
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment