Skip to content

Commit ef1ddfe

Browse files
committed
Move JS wrappers & exports to fluree.crypto-js ns
1 parent fd8ae1d commit ef1ddfe

File tree

4 files changed

+105
-105
lines changed

4 files changed

+105
-105
lines changed

deps.edn

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
{:deps {org.clojure/clojure {:mvn/version "1.11.1"}
1+
{:deps {org.clojure/clojure {:mvn/version "1.11.2"}
22
org.clojure/clojurescript {:mvn/version "1.11.132"}
33
com.fluree/alphabase {:mvn/version "3.3.0"}
44
org.bouncycastle/bcprov-jdk15on {:mvn/version "1.70"}
@@ -7,14 +7,14 @@
77
:paths ["src" "resources"]
88
:aliases
99
{:build
10-
{:deps {io.github.clojure/tools.build {:git/tag "v0.9.6"
11-
:git/sha "8e78bcc"}
10+
{:deps {io.github.clojure/tools.build {:git/tag "v0.10.0"
11+
:git/sha "3a2c484"}
1212
slipset/deps-deploy {:mvn/version "0.2.2"}}
1313
:ns-default build}
1414

1515
:dev
1616
{:extra-paths ["dev", "test"]
17-
:extra-deps {thheller/shadow-cljs {:mvn/version "2.27.4"}}}
17+
:extra-deps {thheller/shadow-cljs {:mvn/version "2.27.5"}}}
1818

1919
:test-clj
2020
{:extra-paths ["test"]
@@ -41,5 +41,5 @@
4141
:main-opts ["-m" "antq.core"]}
4242

4343
:clj-kondo
44-
{:extra-deps {clj-kondo/clj-kondo {:mvn/version "2024.02.12"}}
44+
{:extra-deps {clj-kondo/clj-kondo {:mvn/version "2024.03.13"}}
4545
:main-opts ["-m" "clj-kondo.main" "--lint" "src" "--config" ".clj-kondo/config.edn"]}}}

shadow-cljs.edn

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
:compiler-options {:infer-externs true ; prevents "could not infer" compiler warnings
2525
:optimizations :simple
2626
:externs ["sjcl-externs.js"]}
27-
:exports-var fluree.crypto/js-exports}
27+
:exports-var fluree.crypto-js/exports}
2828

2929
:browser
3030
{:target :esm
@@ -34,21 +34,22 @@
3434
:externs ["sjcl-externs.js"]}
3535
:modules {:fluree-crypto
3636
{:exports
37+
;; wish we didn't have to repeat this here, but we do
3738
{normalizeString fluree.crypto/normalize-string
3839
stringToByteArray fluree.crypto/string->byte-array
3940
byteArrayToString fluree.crypto/byte-array->string
40-
sha2_256 fluree.crypto/sha2-256
41-
sha2_256_normalize fluree.crypto/sha2-256-normalize
42-
sha2_512 fluree.crypto/sha2-512
43-
sha2_512_normalize fluree.crypto/sha2-512-normalize
44-
sha3_256 fluree.crypto/sha3-256
45-
sha3_256_normalize fluree.crypto/sha3-256-normalize
46-
sha3_512 fluree.crypto/sha3-512
47-
sha3_512_normalize fluree.crypto/sha3-512-normalize
48-
ripemd_160 fluree.crypto/ripemd-160
49-
aesEncrypt fluree.crypto/aes-encrypt
50-
aesDecrypt fluree.crypto/aes-decrypt
51-
generateKeyPair fluree.crypto/generateKeyPair
41+
sha2_256 fluree.crypto-js/sha2-256
42+
sha2_256_normalize fluree.crypto-js/sha2-256-normalize
43+
sha2_512 fluree.crypto-js/sha2-512
44+
sha2_512_normalize fluree.crypto-js/sha2-512-normalize
45+
sha3_256 fluree.crypto-js/sha3-256
46+
sha3_256_normalize fluree.crypto-js/sha3-256-normalize
47+
sha3_512 fluree.crypto-js/sha3-512
48+
sha3_512_normalize fluree.crypto-js/sha3-512-normalize
49+
ripemd_160 fluree.crypto-js/ripemd-160
50+
aesEncrypt fluree.crypto-js/aes-encrypt
51+
aesDecrypt fluree.crypto-js/aes-decrypt
52+
generateKeyPair fluree.crypto-js/generate-key-pair
5253
pubKeyFromPrivate fluree.crypto/pub-key-from-private
5354
accountIdFromPublic fluree.crypto/account-id-from-public
5455
accountIdFromPrivate fluree.crypto/account-id-from-private
@@ -60,4 +61,4 @@
6061
scryptCheck fluree.crypto/scrypt-check
6162
randomBytes fluree.crypto/random-bytes
6263
createJWS fluree.crypto/create-jws
63-
verifyJWS fluree.crypto/verify-jws}}}}}}
64+
verifyJWS fluree.crypto-js/verify-jws}}}}}}

src/fluree/crypto.cljc

Lines changed: 1 addition & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,6 @@
5252
sha2/sha2-256
5353
(alphabase/byte-array-to-base (keyword output-format)))))
5454

55-
(defn ^:export sha2-256-js
56-
[& args] ; TS types don't work well with multi-arity fns
57-
(apply sha2-256 args))
58-
5955
(defn ^:export sha2-256-normalize
6056
"sha2-256 hash of provided string after normalizing string."
6157
([s] (sha2-256-normalize s :hex))
@@ -64,10 +60,6 @@
6460
normalize-string
6561
(sha2-256 output-format :string))))
6662

67-
(defn ^:export sha2-256-normalize-js
68-
[& args] ; TS types don't work well with multi-arity fns
69-
(apply sha2-256-normalize args))
70-
7163
(defn ^:export sha2-512
7264
([x] (sha2-512 x :hex))
7365
([x output-format] (sha2-512 x output-format (coerce-input-format x)))
@@ -77,10 +69,6 @@
7769
sha2/sha2-512
7870
(alphabase/byte-array-to-base (keyword output-format)))))
7971

80-
(defn ^:export sha2-512-js
81-
[& args] ; TS types don't work well with multi-arity fns
82-
(apply sha2-512 args))
83-
8472
(defn ^:export sha2-512-normalize
8573
"sha2-512 hash of provided string after normalizing string."
8674
([s] (sha2-512-normalize s :hex))
@@ -89,10 +77,6 @@
8977
normalize-string
9078
(sha2-512 output-format :string))))
9179

92-
(defn ^:export sha2-512-normalize-js
93-
[& args] ; TS types don't work well with multi-arity fns
94-
(apply sha2-512-normalize args))
95-
9680
(defn ^:export sha3-256
9781
([x] (sha3-256 x :hex))
9882
([x output-format] (sha3-256 x output-format (coerce-input-format x)))
@@ -102,10 +86,6 @@
10286
sha3/sha3-256
10387
(alphabase/byte-array-to-base (keyword output-format)))))
10488

105-
(defn ^:export sha3-256-js
106-
[& args] ; TS types don't work well with multi-arity fns
107-
(apply sha3-256 args))
108-
10989
(defn ^:export sha3-256-normalize
11090
"sha3-256 hash of provided string after normalizing string."
11191
([s] (sha3-256-normalize s :hex))
@@ -114,10 +94,6 @@
11494
normalize-string
11595
(sha3-256 output-format :string))))
11696

117-
(defn ^:export sha3-256-normalize-js
118-
[& args] ; TS types don't work well with multi-arity fns
119-
(apply sha3-256-normalize args))
120-
12197
(defn ^:export sha3-512
12298
([x] (sha3-512 x :hex))
12399
([x output-format] (sha3-512 x output-format (coerce-input-format x)))
@@ -127,10 +103,6 @@
127103
sha3/sha3-512
128104
(alphabase/byte-array-to-base (keyword output-format)))))
129105

130-
(defn ^:export sha3-512-js
131-
[& args] ; TS types don't work well with multi-arity fns
132-
(apply sha3-512 args))
133-
134106
(defn ^:export sha3-512-normalize
135107
"sha3-512 hash of provided string after normalizing string."
136108
([s] (sha3-512-normalize s :hex))
@@ -139,10 +111,6 @@
139111
normalize-string
140112
(sha3-512 output-format :string))))
141113

142-
(defn ^:export sha3-512-normalize-js
143-
[& args] ; TS types don't work well with multi-arity fns
144-
(apply sha3-512-normalize args))
145-
146114
(defn ^:export ripemd-160
147115
([x] (ripemd-160 x :hex))
148116
([x output-format] (ripemd-160 x output-format (coerce-input-format x)))
@@ -152,39 +120,22 @@
152120
ripemd/ripemd-160
153121
(alphabase/byte-array-to-base (keyword output-format)))))
154122

155-
(defn ^:export ripemd-160-js
156-
[& args] ; TS types don't work well with multi-arity fns
157-
(apply ripemd-160 args))
158-
159123
(defn ^:export aes-encrypt
160124
([x iv key] (aes-encrypt x iv key :hex))
161125
([x iv key output-format]
162126
(aes/encrypt x key {:iv iv :output-format output-format})))
163127

164-
(defn ^:export aesEncrypt
165-
[& args]
166-
(apply aes-encrypt args))
167-
168128
(defn ^:export aes-decrypt
169129
([x iv key] (aes-decrypt x iv key :string :hex))
170130
([x iv key output-format] (aes-decrypt x iv key output-format :hex))
171131
([x iv key output-format input-format]
172132
(aes/decrypt x key {:iv iv :input-format input-format :output-format output-format})))
173133

174-
(defn ^:export aesDecrypt
175-
[& args] ; TS types don't work well with multi-arity fns
176-
(apply aes-decrypt args))
177-
178134
(defn ^:export generate-key-pair
179135
([] (secp256k1/generate-key-pair))
180136
([private]
181137
(secp256k1/generate-key-pair private)))
182138

183-
#?(:cljs
184-
(defn ^:export generateKeyPair
185-
[& args] ; multi-arity fns don't play well with TS types
186-
(clj->js (apply generate-key-pair args))))
187-
188139
(defn ^:export pub-key-from-private
189140
"Take a private key as either a hex string or BigInteger (clj) bignumber (cljs), returns as a hex string."
190141
[private-key]
@@ -252,41 +203,6 @@
252203
[jws]
253204
(jws/verify jws))
254205

255-
#?(:cljs
256-
(defn ^:export verifyJWS
257-
[jws] (clj->js (jws/verify jws))))
258-
259-
260-
#?(:cljs
261-
(def ^:export js-exports
262-
#js {:normalizeString normalize-string
263-
:stringToByteArray string->byte-array
264-
:byteArrayToString byte-array->string
265-
:sha2_256 sha2-256-js
266-
:sha2_256_normalize sha2-256-normalize-js
267-
:sha2_512 sha2-512-js
268-
:sha2_512_normalize sha2-512-normalize-js
269-
:sha3_256 sha3-256-js
270-
:sha3_256_normalize sha3-256-normalize-js
271-
:sha3_512 sha3-512-js
272-
:sha3_512_normalize sha3-512-normalize-js
273-
:ripemd_160 ripemd-160-js
274-
:aesEncrypt aesEncrypt
275-
:aesDecrypt aesDecrypt
276-
:generateKeyPair generateKeyPair
277-
:pubKeyFromPrivate pub-key-from-private
278-
:accountIdFromPublic account-id-from-public
279-
:accountIdFromPrivate account-id-from-private
280-
:signMessage sign-message
281-
:verifySignature verify-signature
282-
:pubKeyFromMessage pub-key-from-message
283-
:accountIdFromMessage account-id-from-message
284-
:scryptEncrypt scrypt-encrypt
285-
:scryptCheck scrypt-check
286-
:randomBytes random-bytes
287-
:createJWS create-jws
288-
:verifyJWS verifyJWS}))
289-
290206
(comment
291207

292208
(def kp (generate-key-pair))
@@ -380,6 +296,5 @@
380296
;; CLJ + CLJS
381297
;; "57f93bcf926c31a9e2d2129da84bfca51eb9447dfe1749b62598feacaad657d4"
382298

383-
(scrypt-check "hi" scrypt-hex mysalt 32768 8 1)
299+
(scrypt-check "hi" scrypt-hex mysalt 32768 8 1))
384300
;; CLJ + CLJS
385-
)

src/fluree/crypto_js.cljs

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
(ns fluree.crypto-js
2+
(:require [fluree.crypto :as fc]
3+
[fluree.crypto.jws :as jws]))
4+
5+
(defn ^:export sha2-256
6+
[& args] ; TS types don't work well with multi-arity fns
7+
(apply fc/sha2-256 args))
8+
9+
(defn ^:export sha2-256-normalize
10+
[& args] ; TS types don't work well with multi-arity fns
11+
(apply fc/sha2-256-normalize args))
12+
13+
(defn ^:export sha2-512
14+
[& args] ; TS types don't work well with multi-arity fns
15+
(apply fc/sha2-512 args))
16+
17+
(defn ^:export sha2-512-normalize
18+
[& args] ; TS types don't work well with multi-arity fns
19+
(apply fc/sha2-512-normalize args))
20+
21+
(defn ^:export sha3-256
22+
[& args] ; TS types don't work well with multi-arity fns
23+
(apply fc/sha3-256 args))
24+
25+
(defn ^:export sha3-256-normalize
26+
[& args] ; TS types don't work well with multi-arity fns
27+
(apply fc/sha3-256-normalize args))
28+
29+
(defn ^:export sha3-512
30+
[& args] ; TS types don't work well with multi-arity fns
31+
(apply fc/sha3-512 args))
32+
33+
(defn ^:export sha3-512-normalize
34+
[& args] ; TS types don't work well with multi-arity fns
35+
(apply fc/sha3-512-normalize args))
36+
37+
(defn ^:export ripemd-160
38+
[& args] ; TS types don't work well with multi-arity fns
39+
(apply fc/ripemd-160 args))
40+
41+
(defn ^:export aes-encrypt
42+
[& args]
43+
(apply fc/aes-encrypt args))
44+
45+
(defn ^:export aes-decrypt
46+
[& args] ; TS types don't work well with multi-arity fns
47+
(apply fc/aes-decrypt args))
48+
49+
(defn ^:export generate-key-pair
50+
[& args] ; multi-arity fns don't play well with TS types
51+
(clj->js (apply fc/generate-key-pair args)))
52+
53+
(defn ^:export verify-jws
54+
[jws]
55+
(-> jws fc/verify-jws clj->js))
56+
57+
(def ^:export exports
58+
#js {:normalizeString fc/normalize-string
59+
:stringToByteArray fc/string->byte-array
60+
:byteArrayToString fc/byte-array->string
61+
:sha2_256 sha2-256
62+
:sha2_256_normalize sha2-256-normalize
63+
:sha2_512 sha2-512
64+
:sha2_512_normalize sha2-512-normalize
65+
:sha3_256 sha3-256
66+
:sha3_256_normalize sha3-256-normalize
67+
:sha3_512 sha3-512
68+
:sha3_512_normalize sha3-512-normalize
69+
:ripemd_160 ripemd-160
70+
:aesEncrypt aes-encrypt
71+
:aesDecrypt aes-decrypt
72+
:generateKeyPair generate-key-pair
73+
:pubKeyFromPrivate fc/pub-key-from-private
74+
:accountIdFromPublic fc/account-id-from-public
75+
:accountIdFromPrivate fc/account-id-from-private
76+
:signMessage fc/sign-message
77+
:verifySignature fc/verify-signature
78+
:pubKeyFromMessage fc/pub-key-from-message
79+
:accountIdFromMessage fc/account-id-from-message
80+
:scryptEncrypt fc/scrypt-encrypt
81+
:scryptCheck fc/scrypt-check
82+
:randomBytes fc/random-bytes
83+
:createJWS fc/create-jws
84+
:verifyJWS verify-jws})

0 commit comments

Comments
 (0)