Compare commits

..
241 Commits
Author SHA1 Message Date
Github Actions 6650a8e160 [CI Skip] release/stable 3.1.1
skip-checks: true
2020-12-19 13:12:57 +00:00
Jaco Greeff a3d1878453 3.1 (#163) 2020-12-19 14:07:09 +01:00
Github Actions 73b2109666 [CI Skip] release/beta 3.0.2-12
skip-checks: true
2020-12-19 10:31:03 +00:00
Jaco Greeff 3c13f266df Bundle unzlibSync (no worker requirement, stop-gap) (#162)
* Bundle unzlibSync (no worker requirement, stop-gap)

* Bump deps

* Pass uncompressedSize

* mjs fixes
2020-12-19 11:24:59 +01:00
Github Actions d9a4572c7c [CI Skip] release/beta 3.0.2-11
skip-checks: true
2020-12-18 10:10:13 +00:00
Jaco Greeff f6187ca00b Bump dev 2020-12-18 11:04:29 +01:00
Github Actions c0193ba4ad [CI Skip] release/beta 3.0.2-10
skip-checks: true
2020-12-18 09:44:19 +00:00
Jaco Greeff a96c6337a0 WP4 compat :( 2020-12-18 10:39:13 +01:00
Github Actions ba926e920d [CI Skip] release/beta 3.0.2-9
skip-checks: true
2020-12-18 09:22:16 +00:00
Jaco Greeff 29d1ac009a detectPackage test 2020-12-18 10:17:04 +01:00
Github Actions 74c7e05fed [CI Skip] release/beta 3.0.2-8
skip-checks: true
2020-12-17 17:27:18 +00:00
Jaco Greeff 8618b57ee8 __dirname fix 2020-12-17 18:22:13 +01:00
Github Actions bdf7fb55fb [CI Skip] release/beta 3.0.2-7
skip-checks: true
2020-12-17 16:43:10 +00:00
Jaco Greeff e7389c2f15 Remove non-working import.meta wrapper 2020-12-17 17:37:12 +01:00
Github Actions f176d0b733 [CI Skip] release/beta 3.0.2-6
skip-checks: true
2020-12-17 16:24:43 +00:00
Jaco Greeff 81101b69a3 detectPackage protection? 2020-12-17 17:18:57 +01:00
Github Actions 4625944ee4 [CI Skip] release/beta 3.0.2-5
skip-checks: true
2020-12-17 13:02:40 +00:00
Jaco Greeff 15d1166637 Mark detectPackage as sideEffect 2020-12-17 13:57:32 +01:00
Github Actions 40f2990895 [CI Skip] release/beta 3.0.2-4
skip-checks: true
2020-12-17 11:33:59 +00:00
Jaco Greeff 123bb2a09c detectPackage function 2020-12-17 12:28:28 +01:00
Github Actions f863cb418e [CI Skip] release/beta 3.0.2-3
skip-checks: true
2020-12-17 10:41:54 +00:00
Jaco Greeff 0510eb869a Dedupe 2020-12-17 11:36:38 +01:00
Github Actions 16226a1919 [CI Skip] release/beta 3.0.2-2
skip-checks: true
2020-12-16 14:42:41 +00:00
Jaco Greeff 836fa8fb5f Fix detectPackage import 2020-12-16 15:37:44 +01:00
Github Actions 97f02c2dc5 [CI Skip] release/beta 3.0.2-1
skip-checks: true
2020-12-16 14:22:43 +00:00
Jaco Greeff a3ed8293f8 esm detectPackage (#161) 2020-12-16 15:17:47 +01:00
Github Actions b12b73df85 [CI Skip] release/beta 3.0.2-0
skip-checks: true
2020-12-15 15:10:59 +00:00
Jaco Greeff f01a9b187e Single instance package detection (#160)
* Single instance package detection

* s/require/request/

* Internal isReady

* Revert unneeded from-build alias
2020-12-15 16:04:22 +01:00
Github Actions 7898d95844 [CI Skip] release/stable 3.0.1
skip-checks: true
2020-12-13 09:14:12 +00:00
Jaco Greeff 2c4f8bbe4e 3.0 (#158)
* 3.0

* CHANGELOG

* Rename content packages

* final dev bump
2020-12-13 10:09:24 +01:00
Github Actions ef1caeb94e [CI Skip] release/beta 2.0.2-16
skip-checks: true
2020-12-12 12:14:43 +00:00
Jaco Greeff 8837ec9386 Use lz4 on the WASM stream (#159)
* Use lz4 on the WASM stream

* Allow fflate tree-shaking

* Rewrite deps
2020-12-12 13:09:47 +01:00
Github Actions 653aa56f12 [CI Skip] release/beta 2.0.2-15
skip-checks: true
2020-12-11 22:14:28 +00:00
Jaco Greeff 9ece350f21 Bump dev 2020-12-11 23:08:40 +01:00
Github Actions bd6435053d [CI Skip] release/beta 2.0.2-14
skip-checks: true
2020-12-11 16:32:30 +00:00
Jaco Greeff 9c5c22ddbe Bump common x-randomvalues import 2020-12-11 17:27:28 +01:00
Github Actions 77622d8408 [CI Skip] release/beta 2.0.2-13
skip-checks: true
2020-12-11 15:51:42 +00:00
Jaco Greeff 3e1249ca2c Allow esm builds (#157) 2020-12-11 16:45:56 +01:00
Github Actions 9c09490f62 [CI Skip] release/beta 2.0.2-12
skip-checks: true
2020-12-11 08:38:04 +00:00
Jaco Greeff c46c08d296 Bump dev 2020-12-11 09:32:35 +01:00
Github Actions f4d4bb90f0 [CI Skip] release/beta 2.0.2-11
skip-checks: true
2020-12-10 16:04:44 +00:00
Jaco Greeff 45b51adfc7 Build esm (don't use) (#156) 2020-12-10 16:59:50 +01:00
Github Actions aa084bf11b [CI Skip] release/beta 2.0.2-10
skip-checks: true
2020-12-10 14:04:13 +00:00
Jaco Greeff 0a1aec2acf Add missing @babel/runtime dep 2020-12-10 14:59:19 +01:00
Github Actions 463626d75c [CI Skip] release/beta 2.0.2-9
skip-checks: true
2020-12-10 13:51:09 +00:00
Jaco Greeff dc4203fe7c Bump dev 2020-12-10 14:45:49 +01:00
Github Actions 0fa386b93a [CI Skip] release/beta 2.0.2-8
skip-checks: true
2020-12-10 13:13:47 +00:00
Jaco Greeff 5c563bb95f Split bytes packages for easier override (#155) 2020-12-10 14:07:11 +01:00
Github Actions 4a10b7b066 [CI Skip] release/beta 2.0.2-7
skip-checks: true
2020-12-09 17:38:08 +00:00
Jaco Greeff c31c8537be Babel config update (#154) 2020-12-09 18:32:56 +01:00
Github Actions 7aebad00eb [CI Skip] release/beta 2.0.2-6
skip-checks: true
2020-12-09 15:17:51 +00:00
Jaco Greeff 7af6734e26 Fix sr25519 soft derive signature (#153) 2020-12-09 16:11:56 +01:00
Github Actions edcdd48830 [CI Skip] release/beta 2.0.2-5
skip-checks: true
2020-12-09 14:57:56 +00:00
Jaco Greeff ad4ac2e101 Convert to TypeScript sources (#152) 2020-12-09 15:52:04 +01:00
Github Actions 2a44e076c2 [CI Skip] release/beta 2.0.2-4
skip-checks: true
2020-12-08 10:30:08 +00:00
Jaco Greeff 9ed88fe53a Remove --fix on CI (#151) 2020-12-08 11:25:18 +01:00
Github Actions 856bf68abd [CI Skip] release/beta 2.0.2-3
skip-checks: true
2020-12-07 14:05:32 +00:00
Jaco Greeff b36ad6fdf2 Bump dev (#150)
* Bump dev

* Rebump
2020-12-07 14:59:44 +01:00
Github Actions 78d56fa82e [CI Skip] release/beta 2.0.2-2
skip-checks: true
2020-12-05 09:57:02 +00:00
Jaco Greeff 294d30cb3b Bump deps (minor) (#149) 2020-12-05 10:51:49 +01:00
Github Actions 3185b23a97 [CI Skip] release/beta 2.0.2-1
skip-checks: true
2020-12-01 17:52:56 +00:00
Jaco Greeff a8df6878b8 Bump berry (#148)
* Bump berry

* rewrite
2020-12-01 18:33:20 +01:00
Github Actions 148b1c1f98 [CI Skip] release/beta 2.0.2-0
skip-checks: true
2020-11-24 11:46:09 +00:00
Jaco Greeff 355b225428 Bump dev deps (#147) 2020-11-24 12:41:05 +01:00
Jaco Greeff 7e0cfe73f1 Bump dev (#146)
* Bump dev

* Update babel config
2020-11-11 11:28:47 +01:00
Jaco Greeff 618d5ad6d6 Adjust CC excludes (#145) 2020-11-08 10:10:36 +01:00
Github Actions 23df722466 [CI Skip] release/stable 2.0.1
skip-checks: true
2020-11-08 09:05:25 +00:00
Jaco Greeff d3a90d7362 2.0 (#144) 2020-11-08 09:59:49 +01:00
Github Actions 2b8ee5f655 [CI Skip] release/beta 2.0.0-10
skip-checks: true
2020-11-07 14:47:09 +00:00
Jaco Greeff 1db2f57b8c Remove jest polyfill (#143) 2020-11-07 15:41:59 +01:00
Github Actions 8d93a4b665 [CI Skip] release/beta 2.0.0-9
skip-checks: true
2020-11-07 13:23:44 +00:00
Jaco Greeff 2fca9b83c1 Flatten JS (#142)
* Flatten JS

* JS locations in build
2020-11-07 14:18:41 +01:00
Jaco Greeff 5be84df651 Use x-randomvalues (#140)
* Use x-randomvalues

* Install
2020-11-07 13:46:27 +01:00
Github Actions 11997092c3 [CI Skip] release/beta 2.0.0-8
skip-checks: true
2020-11-07 09:47:26 +00:00
Jaco Greeff 15788efd34 Replace default crypto import, remove requires (#139)
* Replace default crypto import, remove requires

* TS 4.0.5
2020-11-07 10:42:14 +01:00
Github Actions cbb7e6f9e8 [CI Skip] release/beta 2.0.0-7
skip-checks: true
2020-11-05 13:54:17 +00:00
Jaco Greeff 141f5e6488 Fix binaryen binaries (mac with shared libs) (#137) 2020-11-05 14:47:38 +01:00
Github Actions 1c54650396 [CI Skip] release/beta 2.0.0-6
skip-checks: true
2020-11-05 13:29:12 +00:00
Jaco Greeff ae748a828d Build via xargo (#136)
* Build via xargo

* xargo as dev dep

* Install xargo explicitly

* Fix binaryen dep

* Update deps

* Remove unused wasm-pack section

* Uname
2020-11-05 14:23:27 +01:00
Github Actions 9d840d89e6 [CI Skip] release/beta 2.0.0-5
skip-checks: true
2020-11-03 11:26:56 +00:00
Jaco Greeff c03750d97c No rlib 2020-11-03 12:22:26 +01:00
Github Actions df579b6ab0 [CI Skip] release/beta 2.0.0-4
skip-checks: true
2020-11-03 09:03:39 +00:00
Jaco Greeff 5455b1bc8c Bump dev polyfill (#135) 2020-11-03 09:58:31 +01:00
Github Actions 4095777139 [CI Skip] release/beta 2.0.0-3
skip-checks: true
2020-11-03 08:47:10 +00:00
Jaco Greeff be0a41e4b0 Test for deterministic outputs (#134) 2020-11-03 09:42:53 +01:00
Github Actions bf9aceb4a9 [CI Skip] release/beta 2.0.0-2
skip-checks: true
2020-11-03 07:51:58 +00:00
Jaco Greeff c6135e28d4 2.0 (#133)
* 2.0

* prerelease

* Bumps

* CHANGELOG

* Don't init with no WASM bytes

* {asm,bytes}-empty

* asm-empty import

* WasmCryptoInstance
2020-11-03 08:46:57 +01:00
Github Actions 9f199fee77 [CI Skip] release/beta 1.5.0-beta.19
skip-checks: true
2020-11-02 21:16:28 +00:00
Jaco Greeff d937dda6ba Drop actual polyfill 2020-11-02 22:12:10 +01:00
Github Actions 5bdc33d0cd [CI Skip] release/beta 1.5.0-beta.18
skip-checks: true
2020-11-02 20:29:49 +00:00
Jaco Greeff 511986b7cf Update steps 2020-11-02 21:25:00 +01:00
Jaco Greeff 1d7addf6ef Remove auto-injected crypto polyfill (#132)
* Remove auto-injected crypto polyfill

* Update
2020-11-02 21:17:11 +01:00
Github Actions cc63edbd5c [CI Skip] release/beta 1.5.0-beta.17
skip-checks: true
2020-11-02 18:07:58 +00:00
Jaco Greeff f8efe32b43 Align stub.js with asm.js 2020-11-02 19:03:52 +01:00
Jaco Greeff bb748c0225 Simplify asm creation (#131) 2020-11-02 19:02:28 +01:00
Github Actions 9e9535cc2b [CI Skip] release/beta 1.5.0-beta.16
skip-checks: true
2020-11-02 17:37:55 +00:00
Jaco Greeff e2d0726608 Split js/wasm (#130)
* Split js/wasm

* require
2020-11-02 18:34:00 +01:00
Github Actions 5209c934a6 [CI Skip] release/beta 1.5.0-beta.15
skip-checks: true
2020-11-02 15:43:50 +00:00
Jaco Greeff da946b18ce Cleanup build, no sed mangling (#129)
* Polyfill require adjust

* Assert in promise for getRandomBytes

* Adjust jest

* Revert explicit overrides (from base)

* use typeof

* Re-add crypto-polyfill (backwards, direct imports)

* crypto log

* Fix dev

* Adjust

* Cleanups, no sed mangling

* Cleanup build folder

* Remove exports

* Cleanups

* Adjust env vs util

* Remove Buffer alloc

* Cleant ext vs int

* Rework naming

* Mapping rename

* Combine index & exports

* withWasm wrapper

* pass{String, U8a} -> alloc{String, U8a}

* Internal reuse

* Explict package-only test
2020-11-02 16:39:54 +01:00
Github Actions 2ac68bdb18 [CI Skip] release/beta 1.5.0-beta.14
skip-checks: true
2020-11-01 17:57:29 +00:00
Jaco Greeff 83762d9997 Polyfill require adjust (#128)
* Polyfill require adjust

* Assert in promise for getRandomBytes

* Adjust jest

* Revert explicit overrides (from base)

* use typeof

* Re-add crypto-polyfill (backwards, direct imports)

* crypto log

* Fix dev

* Adjust
2020-11-01 18:53:09 +01:00
Github Actions 311263ad83 [CI Skip] release/beta 1.5.0-beta.13
skip-checks: true
2020-10-27 08:28:27 +00:00
Jaco Greeff b3ae90f330 Stick to base64 2020-10-27 09:23:46 +01:00
Github Actions 327f35143d [CI Skip] release/beta 1.5.0-beta.12
skip-checks: true
2020-10-27 08:08:48 +00:00
Jaco Greeff 35b2bb2d13 Use base122 encoding for WASM buffer (#127) 2020-10-27 09:04:37 +01:00
Github Actions 08b72cc782 [CI Skip] release/beta 1.5.0-beta.11
skip-checks: true
2020-10-26 10:33:23 +00:00
Jaco Greeff f5c439cee4 Bump gh actions, cleanups (#126)
* Bump gh actions, cleanups

* Bumps
2020-10-26 11:29:15 +01:00
Github Actions 0eb440d93a [CI Skip] release/beta 1.5.0-beta.10
skip-checks: true
2020-10-25 12:31:09 +00:00
Jaco Greeff 5860c204e1 Bump berry (#125)
* Bump berry

* Bump dev
2020-10-25 13:27:00 +01:00
Github Actions 597ded7e79 [CI Skip] release/beta 1.5.0-beta.9
skip-checks: true
2020-10-23 10:42:21 +00:00
Jaco Greeff 1c5a9e8152 Bump deps (#124) 2020-10-23 12:37:57 +02:00
EvgenyandEvgeny Svirsky 6bdeda218c Fixed type (#121)
Co-authored-by: Evgeny Svirsky <evgeny@cere.io>
2020-10-23 12:28:56 +02:00
Github Actions e8cfce5ede [CI Skip] release/beta 1.5.0-beta.8
skip-checks: true
2020-10-23 09:37:41 +00:00
Jaco Greeff 2276c06826 Remove usused NIGHLTLY env (#123) 2020-10-23 11:33:10 +02:00
Github Actions bf1307fda2 [CI Skip] release/beta 1.5.0-beta.7
skip-checks: true
2020-10-23 09:19:01 +00:00
Jaco Greeff 696d369a29 Add docs root (#122) 2020-10-23 11:14:40 +02:00
Github Actions d419f2e919 [CI Skip] release/beta 1.5.0-beta.6
skip-checks: true
2020-10-17 08:10:48 +00:00
Jaco Greeff f966423808 Remove (unused) typedoc config (#120) 2020-10-17 10:06:25 +02:00
Github Actions 15a1020321 [CI Skip] release/beta 1.5.0-beta.5
skip-checks: true
2020-10-15 10:47:10 +00:00
Jaco Greeff 29ab5f2e50 Swap to stable Rustc (non-nightly) (#118)
* Swap to stable Rustc (non-nightly)

* Remove toolchain?

* cargo run?
2020-10-15 12:42:50 +02:00
Jaco Greeff 4ce48c701f Bump dev (no lerna) (#116) 2020-10-04 15:39:48 +02:00
Jaco Greeff 52c5a506ac SPDX (#114) 2020-09-17 16:13:19 +02:00
Github Actions ecf02ec26d [CI Skip] release/beta 1.5.0-beta.4
skip-checks: true
2020-09-13 11:14:13 +00:00
Jaco Greeff 6611c3d136 Bump deps (#112) 2020-09-13 13:09:26 +02:00
Github Actions e5a4d644ab [CI Skip] release/beta 1.5.0-beta.3
skip-checks: true
2020-09-08 08:39:46 +00:00
Jaco Greeff 90853435d8 Rewrite yarn.lock (#111) 2020-09-08 10:35:27 +02:00
Github Actions 5211b58995 [CI Skip] release/beta 1.5.0-beta.2
skip-checks: true
2020-09-06 16:10:52 +00:00
Jaco Greeff a68aaeceba Bump deps (#110) 2020-09-06 18:06:14 +02:00
Github Actions cfddf2bdb6 [CI Skip] release/beta 1.5.0-beta.1
skip-checks: true
2020-09-05 06:04:20 +00:00
Jaco Greeff 597c1bf0d0 Bump deps (#109) 2020-09-05 07:59:31 +02:00
Github Actions 25ecaf51bf [CI Skip] release/beta 1.5.0-beta.0
skip-checks: true
2020-09-03 12:48:48 +00:00
Jaco Greeff 445585309b Bump dev (#108) 2020-09-03 14:43:43 +02:00
Github Actions b139d44907 [CI Skip] release/stable 1.4.1
skip-checks: true
2020-08-27 10:11:37 +00:00
Jaco Greeff a81698c61c 1.4 (#107) 2020-08-27 12:07:17 +02:00
Github Actions 9e1d439c55 [CI Skip] release/beta 1.4.0-beta.7
skip-checks: true
2020-08-26 07:35:52 +00:00
Jaco Greeff a18d50f501 Bumps (#106) 2020-08-26 09:30:37 +02:00
Github Actions 55a3e96698 [CI Skip] release/beta 1.4.0-beta.6
skip-checks: true
2020-08-25 18:53:03 +00:00
Jaco Greeff c4ab178926 Re-add bip39ToSeed interface (#104)
* Re-add bip39ToSeed interface

* import
2020-08-25 20:48:28 +02:00
Github Actions be787021c7 [CI Skip] release/beta 1.4.0-beta.5
skip-checks: true
2020-08-19 13:54:11 +00:00
Jaco Greeff 037d857085 Adjust init message with possible fixes (#103) 2020-08-19 15:49:06 +02:00
Github Actions c140ac97e5 [CI Skip] release/beta 1.4.0-beta.4
skip-checks: true
2020-08-18 10:08:04 +00:00
Jaco Greeff 8e370e4c19 Bump deps (#102) 2020-08-18 12:03:01 +02:00
Github Actions 6ab362ea57 [CI Skip] release/beta 1.4.0-beta.3
skip-checks: true
2020-08-12 14:28:01 +00:00
Jaco Greeff 666d679b4e Bump deps (#101) 2020-08-12 16:23:25 +02:00
Github Actions 1228617330 [CI Skip] release/beta 1.4.0-beta.2
skip-checks: true
2020-08-11 12:28:35 +00:00
Jaco Greeff 5da4f3a324 Additional size-related cargo opts (#100) 2020-08-11 14:23:37 +02:00
Github Actions 07742c9d03 [CI Skip] release/beta 1.4.0-beta.1
skip-checks: true
2020-08-10 07:56:01 +00:00
Jaco Greeff af94d0d001 yarn node_modules 2020-08-10 09:51:17 +02:00
Github Actions 8d96c8aed4 [CI Skip] release/beta 1.4.0-beta.0
skip-checks: true
2020-08-09 13:47:00 +00:00
Jaco Greeff 2d48df8986 yarn pnp (#99) 2020-08-09 15:43:06 +02:00
Github Actions 2d07c0a6a3 [CI Skip] release/stable 1.3.1
skip-checks: true
2020-08-09 12:31:46 +00:00
Jaco Greeff 8b7c7e93af 1.3 (#98) 2020-08-09 14:27:39 +02:00
Github Actions 393d898dab [CI Skip] release/beta 1.3.0-beta.30
skip-checks: true
2020-08-08 06:54:58 +00:00
Jaco Greeff fcf6d439ef Bump deps (#97) 2020-08-08 08:50:31 +02:00
Github Actions 5ccb1b4982 [CI Skip] release/beta 1.3.0-beta.29
skip-checks: true
2020-08-06 12:05:34 +00:00
Jaco Greeff 7ee706a99f Bump berry (#96)
* Bump berry

* Rewrite
2020-08-06 14:00:58 +02:00
Github Actions da491efef6 [CI Skip] release/beta 1.3.0-beta.28
skip-checks: true
2020-08-05 10:35:37 +00:00
Jaco Greeff 2ff45e1ca6 De-dup & update Rust packages (#95)
* De-dup & update Rust packages

* Explicitly pass wasm-opt false (manual run)
2020-08-05 12:30:26 +02:00
Github Actions 6aac8e8771 [CI Skip] release/beta 1.3.0-beta.27
skip-checks: true
2020-08-03 16:21:37 +00:00
Jaco Greeff 6ebdfe9362 Bump deps (#94) 2020-08-03 18:16:01 +02:00
Github Actions de9bf473f1 [CI Skip] release/beta 1.3.0-beta.26
skip-checks: true
2020-08-03 13:31:27 +00:00
Jaco Greeff 735584aef9 Scrypt TS interface (#93) 2020-08-03 15:25:34 +02:00
Github Actions 7a33da9e53 [CI Skip] release/beta 1.3.0-beta.25
skip-checks: true
2020-08-03 12:52:58 +00:00
Jaco Greeff 0faca1b98e Add scrypt hashing (#92) 2020-08-03 14:47:17 +02:00
Github Actions ab867541d7 [CI Skip] release/beta 1.3.0-beta.24
skip-checks: true
2020-08-03 12:02:58 +00:00
Jaco Greeff f50d6af2bb Updates for latest wasm-pack formats (#91)
* Updates for latest wasm-pack formats

* Cleanup sed output
2020-08-03 13:57:34 +02:00
Github Actions 8c4bf9470a [CI Skip] release/beta 1.3.0-beta.23
skip-checks: true
2020-08-03 08:56:21 +00:00
Jaco Greeff e5875a73c3 Bumps (#90) 2020-08-03 10:51:08 +02:00
Github Actions e32e52a94c [CI Skip] release/beta 1.3.0-beta.22
skip-checks: true
2020-07-31 08:07:58 +00:00
Jaco Greeff 59673150ba Bump deps (#89) 2020-07-31 10:02:40 +02:00
Github Actions 9f84fc3250 [CI Skip] release/beta 1.3.0-beta.21
skip-checks: true
2020-07-17 11:43:46 +00:00
Jaco Greeff 678063e12a Cargo bumps (#86) 2020-07-17 13:38:05 +02:00
Github Actions 02324280e3 [CI Skip] release/beta 1.3.0-beta.20
skip-checks: true
2020-07-17 11:18:16 +00:00
Jaco Greeff 9bc97a4e1d Update ed25519-dalek (#85)
* Update ed25519-dalek

* Bump subtle
2020-07-17 13:12:21 +02:00
Github Actions 4cc1d4e515 [CI Skip] release/beta 1.3.0-beta.19
skip-checks: true
2020-07-17 06:40:47 +00:00
Jaco Greeff 8ae9bbd3b6 Bump deps (#84) 2020-07-17 08:35:00 +02:00
Github Actions 08c9e9e8ac [CI Skip] release/beta 1.3.0-beta.18
skip-checks: true
2020-07-02 05:14:32 +00:00
Jaco Greeff b3c32738e3 Bump deps (#83) 2020-07-02 07:08:58 +02:00
Github Actions 72ff8a13dc [CI Skip] release/beta 1.3.0-beta.17
skip-checks: true
2020-06-05 20:21:05 +00:00
Jaco Greeff 1d75701361 Bump deps (#81) 2020-06-05 22:14:56 +02:00
Github Actions 2fd1daf39a [CI Skip] release/beta 1.3.0-beta.16
skip-checks: true
2020-05-31 12:47:38 +00:00
Jaco Greeff ef6db82c52 Remove bip39ToSeed (#80)
* Cleanups, no mnemonic to seed (only minisecret)

* Remove bip39ToSeed
2020-05-31 14:42:13 +02:00
Github Actions 1e2caa35ce [CI Skip] 1.3.0-beta.15
skip-checks: true
2020-05-23 16:30:45 +00:00
Jaco Greeff 8c0aa030cf Bump deps (#79)
* Bump deps

* Rust bumps

* Rust bumps (again)

* Pin nightly

* Cleanup with new generation
2020-05-23 18:25:53 +02:00
Github Actions ff9fe99ca5 [CI Skip] 1.3.0-beta.14
skip-checks: true
2020-05-15 10:35:25 +00:00
Jaco Greeff e0feb7864d Bump deps (#78) 2020-05-15 12:30:58 +02:00
Jaco Greeff c8431fc3d1 Bump berry (#77)
* Bump berry

* .eslintrc.js into ignore
2020-05-11 11:54:35 +02:00
Github Actions 849285a35d [CI Skip] 1.3.0-beta.13
skip-checks: true
2020-04-30 06:24:28 +00:00
Jaco Greeff 5fe38fa47b Bump deps (#76)
* Bump deps

* linting
2020-04-30 08:19:36 +02:00
Github Actions 241bbe99c5 [CI Skip] 1.3.0-beta.12
skip-checks: true
2020-04-06 10:30:14 +00:00
Jaco Greeff 65d89a7b41 Use bundled node (#75) 2020-04-06 12:25:59 +02:00
Github Actions a0cbf8c531 [CI Skip] 1.3.0-beta.11
skip-checks: true
2020-04-05 07:59:24 +00:00
Jaco Greeff c50fe071cb Bump deps (#74) 2020-04-05 09:54:38 +02:00
Github Actions 526b79435e [CI Skip] 1.3.0-beta.10
skip-checks: true
2020-04-04 08:46:29 +00:00
Jaco Greeff b621b79bae Bump deps (#73) 2020-04-04 10:42:04 +02:00
Github Actions 37b04af274 [CI Skip] 1.3.0-beta.9
skip-checks: true
2020-04-02 06:07:16 +00:00
Jaco Greeff 84f0d27744 Rewrite yarn.lock (#72) 2020-04-02 08:02:17 +02:00
Github Actions ff2315bff8 [CI Skip] 1.3.0-beta.8
skip-checks: true
2020-03-21 09:12:23 +00:00
Jaco Greeff 6fa0e99141 Bump deps (#71) 2020-03-21 10:07:48 +01:00
Github Actions 7c9bbb05a6 [CI Skip] 1.3.0-beta.7
skip-checks: true
2020-03-16 14:35:50 +00:00
Jaco Greeff 3ef1b2073f Add yarn matrix (#70) 2020-03-16 15:31:06 +01:00
Github Actions b56924a5b3 [CI Skip] 1.3.0-beta.6
skip-checks: true
2020-03-16 13:37:50 +00:00
Jaco Greeff bf7feafaaa Remove actions matrix (#69) 2020-03-16 14:33:16 +01:00
Github Actions 184edb6e4e [CI Skip] 1.3.0-beta.5
skip-checks: true
2020-03-15 07:24:48 +00:00
Jaco Greeff d511310ba0 Remove non-working CI cache (#68) 2020-03-15 08:19:47 +01:00
Github Actions 7ad87c6ce2 [CI Skip] 1.3.0-beta.4
skip-checks: true
2020-03-14 16:46:54 +00:00
Jaco Greeff 01a5539c28 Bump berry (#67)
* Bump berry

* yarn
2020-03-14 17:41:41 +01:00
Github Actions dd107338e9 [CI Skip] 1.3.0-beta.3
skip-checks: true
2020-03-14 14:35:02 +00:00
Jaco Greeff 61ffef08e3 VSCode pnpify (#66) 2020-03-14 15:29:40 +01:00
Github Actions 76a436f22c [CI Skip] 1.3.0-beta.2
skip-checks: true
2020-03-14 08:33:56 +00:00
Jaco Greeff 86a66de726 Bump deps (#65) 2020-03-14 09:28:33 +01:00
Github Actions 7c4d2f7af5 [CI Skip] 1.3.0-beta.1
skip-checks: true
2020-03-04 12:32:34 +00:00
Jaco Greeff a20b14a8b7 Use yarn pnp (#64)
* Use yarn pnp

* Bump dev

* Bumps

* Attempt to fix build

* Move "override-require": "^1.1.1" dep

* Bump
2020-03-04 13:26:56 +01:00
Github Actions e5c31a0fe7 [CI Skip] 1.3.0-beta.0
skip-checks: true
2020-03-03 06:32:56 +00:00
Jaco Greeff 0fc0207bcb Remove preaudit_deprecated feature to schnorrkel (unused now) 2020-03-03 07:28:04 +01:00
Github Actions 645cf3dbf7 [CI Skip] 1.2.1
skip-checks: true
2020-02-29 12:50:25 +00:00
Jaco Greeff 0fd350f5d6 1.2 (#62) 2020-02-29 13:45:32 +01:00
Github Actions 5e85feae7b [CI Skip] 1.2.0-beta.7
skip-checks: true
2020-02-29 11:31:54 +00:00
Jaco Greeff 2a61459682 Remove yarn version plugin, bump dev (#61) 2020-02-29 12:27:28 +01:00
Github Actions 370d0de745 [CI Skip] 1.2.0-beta.6
skip-checks: true
2020-02-29 09:31:17 +00:00
Jaco Greeff 07dd07c9db yarn --immutable on CI (#60) 2020-02-29 10:26:21 +01:00
Github Actions e6b892df6f [CI Skip] 1.2.0-beta.5
skip-checks: true
2020-02-28 21:29:54 +00:00
Jaco Greeff e93e764a72 Merge branch 'master' of github.com:polkadot-js/wasm 2020-02-28 22:24:50 +01:00
Jaco Greeff 331111b895 opt-level z 2020-02-28 22:24:47 +01:00
Github Actions 31afd5143f [CI Skip] 1.2.0-beta.4
skip-checks: true
2020-02-28 21:23:55 +00:00
Jaco Greeff a0126f374e Add opt-level for (some) space savings (#59) 2020-02-28 22:19:11 +01:00
Github Actions f11be090e8 [CI Skip] 1.2.0-beta.3
skip-checks: true
2020-02-28 16:23:28 +00:00
Jaco Greeff f3dbf059b7 trigger 2020-02-28 17:16:32 +01:00
Jaco Greeff eba92df762 trigger 2019-04-28 19:32:10 +01:00
Jaco Greeff e4a717faa6 trigger 2019-05-05 19:32:10 +01:00
Github Actions 075ba8a365 [CI Skip] 1.2.0-beta.2
skip-checks: true
2020-02-28 12:05:13 +00:00
Jaco Greeff a9b2ac1240 Swap to yarn 2 (#58)
* Swap to yarn 2

* Use polkadot-dev-run-test for jest

* Try and fix JS tests via jest

* Try via @polkadot/dev
2020-02-28 12:58:57 +01:00
Github Actions d336b1f894 [CI Skip] 1.2.0-beta.1
skip-checks: true
2020-02-26 21:17:06 +00:00
Jaco Greeff c976f3ebf9 Use binaryen from GH releases (Linux) (#57)
* Use binaryen from GH releases (Linux)

* echo for downloading
2020-02-26 22:12:17 +01:00
Github Actions cdcfe2823d [CI Skip] 1.2.0-beta.0
skip-checks: true
2020-02-25 10:41:10 +00:00
Jaco Greeff 57030cb591 Unpin nightly (#56) 2020-02-25 11:29:10 +01:00
Github Actions 88ebaf650b [CI Skip] 1.1.1
skip-checks: true
2020-02-24 20:54:04 +00:00
Jaco Greeff 28bac70cfe 1.1 (#55) 2020-02-24 21:41:38 +01:00
Github Actions aaab1725b8 [CI Skip] 1.1.0-beta.0
skip-checks: true
2020-02-24 15:38:48 +00:00
Jaco Greeff 4c7a9609bd Drop sr25519 verify_simple_preaudit_deprecated (#54)
* Drop sr25519 verify_simple_preaudit_deprecated

* Add missing Signature import

* Update test-verctor, 0.8.5+ only signatures

* Trigger

* Pin Rust nightly

* Pin via run

* De-dup nightlies

* Update tests to use nightly-2020-02-17

* Update CHANGELOG

* Typo
2020-02-24 16:24:49 +01:00
Jaco Greeff e1c51d766f Add yarn cache (#53) 2020-02-17 15:18:15 +01:00
74 changed files with 12410 additions and 14987 deletions
+1
View File
@@ -0,0 +1 @@
4
-1
View File
@@ -1 +0,0 @@
module.exports = require('./babel.config.js');
+1
View File
@@ -2,3 +2,4 @@ exclude_patterns:
- "**/*.spec.js"
- "**/*.spec.ts"
- "docs/**/*.js"
- "**/test/**/*.js"
-4
View File
@@ -1,4 +0,0 @@
**/binaryen/*
**/build/*
**/coverage/*
**/node_modules/*
+16 -1
View File
@@ -1,7 +1,22 @@
const base = require('@polkadot/dev/config/eslint');
// Copyright 2019-2020 @polkadot/wasm-crypto authors & contributors
// SPDX-License-Identifier: Apache-2.0
const base = require('@polkadot/dev/config/eslint.cjs');
module.exports = {
...base,
ignorePatterns: [
'.eslintrc.js',
'.github/**',
'.vscode/**',
'.yarn/**',
'**/binaryen/*',
'**/build/*',
'**/coverage/*',
'**/node_modules/*',
'**/pkg/*',
'**/target/*'
],
parserOptions: {
...base.parserOptions,
project: [
+8 -47
View File
@@ -2,55 +2,16 @@ name: PR
on: [pull_request]
jobs:
lint:
name: Linting
runs-on: ubuntu-latest
pr:
strategy:
matrix:
node-version: [12.x]
steps:
- uses: actions/checkout@v1
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
- name: lint
run: |
yarn install --frozen-lockfile
yarn lint
test:
name: Testing
step: ['lint', 'test', 'build']
name: ${{ matrix.step }}
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [12.x]
steps:
- uses: actions/checkout@v1
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
- name: test
- uses: actions/checkout@v2
- name: ${{ matrix.step }}
run: |
rustup toolchain install nightly
yarn install --frozen-lockfile
yarn test
build_code:
name: Build Code
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [12.x]
steps:
- uses: actions/checkout@v1
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
- name: build
run: |
rustup toolchain install nightly
yarn install --frozen-lockfile
yarn build
yarn install --immutable | grep -v 'YN0013'
./scripts/install-build-deps.sh
yarn ${{ matrix.step }}
+10 -19
View File
@@ -5,39 +5,30 @@ on:
- master
jobs:
build_code:
name: Build Code
if: "! contains(github.event.head_commit.message, '[CI Skip]')"
runs-on: ubuntu-latest
master:
strategy:
matrix:
node-version: [12.x]
step: ['build:release']
name: ${{ matrix.step }}
if: "! startsWith(github.event.head_commit.message, '[CI Skip]') && github.repository == 'polkadot-js/wasm'"
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- uses: actions/checkout@v2
with:
token: ${{ secrets.GH_PAT }}
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
- name: build
env:
CC_TEST_REPORTER_ID: ${{ secrets.CC_TEST_REPORTER_ID }}
GH_PAT: ${{ secrets.GH_PAT }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GH_RELEASE_GITHUB_API_TOKEN: ${{ secrets.GH_PAT }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
run: |
rustup toolchain install nightly
yarn install --frozen-lockfile
yarn polkadot-ci-ghact-build
yarn install --immutable | grep -v 'YN0013'
./scripts/install-build-deps.sh
yarn ${{ matrix.step }}
dummy:
name: Dummy
if: "contains(github.event.head_commit.message, '[CI Skip]')"
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [12.x]
steps:
- name: dummy
run: |
+7 -3
View File
@@ -1,12 +1,15 @@
binaryen/
bindgen/
build/
build-docs/
bytes/
coverage/
docs/.vuepress/dist/
node_modules/
pkg/
target/
tmp/
wabt/
.DS_Store
.env.local
.env.development.local
@@ -14,9 +17,10 @@ tmp/
.env.production.local
.npmrc
.pnp.*
.yarn/cache
.yarn/unplugged
.yarn/build-state.yml
.yarn/*
!.yarn/releases
!.yarn/plugins
!.yarn/sdks
cc-test-reporter
lerna-debug.log*
npm-debug.log*
+1 -1
View File
@@ -1 +1 @@
10
12
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
+55
View File
File diff suppressed because one or more lines are too long
+13
View File
@@ -0,0 +1,13 @@
enableImmutableInstalls: false
enableProgressBars: false
nodeLinker: node-modules
plugins:
- path: .yarn/plugins/@yarnpkg/plugin-interactive-tools.cjs
spec: "@yarnpkg/plugin-interactive-tools"
- path: .yarn/plugins/@yarnpkg/plugin-version.cjs
spec: "@yarnpkg/plugin-version"
yarnPath: .yarn/releases/yarn-2.4.0.cjs
+132 -16
View File
@@ -1,71 +1,187 @@
# 1.0.1 Feb 15, 2020
# CHANGELOG
## 3.1.1 Dec 19, 2020
Changes:
- Single-instance package detection
- Adjust WASM inflate with localized methods
## 3.0.1 Dec 13, 2020
**Important** This assumes `@polkadot/util` 5+ peerDependencies
**Important** While this package contains no external interface changes, it doe now compile and ship both cjs and esm modules. This means that modern bundlers will have more information for tree-shaking available. Additionally when using Node with `.mjs` extensions, the esm version imports will be used on recent Node versions. Adding an export map, as here, may have some impacts so a major semver bump is advised. There may be (small) dragons hiding in the dark corners...
Changes:
- Build and expose both cjs and esm via exports map
- Split wasm and asmjs files into the `@polkadot/wasm-crypto-{wasm,asmjs}` packages
- Add fflate WASM compression, with 180K raw savings (37K over-the-wire)
- Convert the package to full TypeScript sources
## 2.0.1 Nov 8, 2020
Changes:
- Rework generation of WASM interfaces (proper cross-platform JS support)
- Remove explicit `crypto` dependency, this is now applied by `@polkadot/x-randomvalues`
- Build via xargo for panic abort, an overall small sizes without stack (Pinned nightly)
- Move Rust library sources in to `rs/` subfolder
## 1.4.1 Aug 27, 2020
Changes:
- Re-add the BTC/ETH compatible `bip39ToSeed` dropped in the previous version (ETH-compatible pairs)
## 1.3.1 Aug 9, 2020
Changes:
- Add `scrypt` function for KDF generation
- Remove `bip39ToSeed`, we only use the `bip39ToMiniSecret` variant in Substrate
- Update ed25519-dalek to 1.0.0-pre.4
- Rework generation based on latest wasm-pack generator
## 1.2.1 Feb 29, 2020
Changes:
- Adjust build process for smaller wasm bundle outputs (~50K dropped from base bundle)
- Unpin nightly from nightly-2020-02-17 version
- Swap to yarn 2 and add support for use by yarn 2 projects
## 1.1.1 Feb 24, 2020
- **Important** The sr25519 interface dropped the use of `verify_simple_preaudit_deprecated` for signature verification, instead it now uses `verify_simple`. Only schnorrkel 0.8+ signatures will now pass verification. This is a follow-up of the 0.1 signing support that was dropped in a previous version.
Changes:
- Rework schnorrkel signatures test vectors based on the above change (Rust, WASM and ASM.js tests)
- Rust nightly pinned to last-known-working 2020-02-17 on CI (compiler issues, should to be reverted in a future release)
## 1.0.1 Feb 15, 2020
Changes:
- No functionality changes from 0.20.1. The interfaces here are stable in the current iteration.
# 0.20.1 Jan 30, 2020
## 0.20.1 Jan 30, 2020
Changes:
- Pull in schnorrkel 0.8.5 for full Substrate 2.x compatibility
# 0.14.1 Sep 09, 2019
## 0.14.1 Sep 09, 2019
Changes:
- No functionality changes at all, everything done is "under the hood" to give the codebase better maintainability
# 0.13.1 Jul 20, 2019
## 0.13.1 Jul 20, 2019
Changes:
- Added an asm.js fallback which is active for React Native via the `"react-native"` entry in `package.json`. Ensure that you run the build step with the `NODE_OPTIONS=--max_old_space_size=8192` flags, since the asm.js bundle is large. (For RN the full command would therefore be `NODE_OPTIONS=--max_old_space_size=8192 npm start`)
# 0.12.1 Jul 17, 2019
## 0.12.1 Jul 17, 2019
Changes:
- Remove deprecated `@polkadot/wasm-schnorrkel` & `@polkadot/wasm-dalek-ed25519` source (all combined in `@polkadot/wasm-crypto`, was kept for historical purposes)
- Security dependency bumps
- Updated Rust `hex-literal` for recent versions of the compiler (used in tests only)
# 0.11.1 May 31, 2019
## 0.11.1 May 31, 2019
Changes:
- Security dependency bumps
# 0.10.1 May 09, 2019
## 0.10.1 May 09, 2019
Changes:
- w3f/schnorrkel updated to 0.1.1 as per substrate
- Added known subkey signature test (Rust & JS)
# 0.9.1 Apr 29, 2019
## 0.9.1 Apr 29, 2019
Changes:
- Dependency bumps
# 0.8.1 Mar 31, 2019
## 0.8.1 Mar 31, 2019
Changes:
- Pull ed25519 & sr25519 into `@polkadot/wasm-crypto` as well (smaller final size)
- Disable build/publish of `wasm-dalek-ed25519` & `wasm-schnorrkel`
- Improve error messaging, instead of `__wasm_malloc of null`
# 0.7.1 Mar 30, 2019
## 0.7.1 Mar 30, 2019
Changes:
- Fix build scripts to properly attach errors in the log (dropped in 0.6.1)
# 0.6.1 Mar 27, 2019
## 0.6.1 Mar 27, 2019
Changes:
- Log init errors for both non-WebAssembly usage as well as WebAssembly errors
# 0.5.1 Mar 23, 2019
## 0.5.1 Mar 23, 2019
Changes:
- Add password argument to bip39ToSeed
# 0.4.1 Mar 23, 2019
## 0.4.1 Mar 23, 2019
Changes:
- Add bip39ToSeed
# 0.3.1 Mar 23, 2019
## 0.3.1 Mar 23, 2019
Changes:
- Add wasm-dalek-ed25519 for all used crypto there
- Add keccak256
- Try secp256k1 (bloating code, not used atm)
# 0.2.1 Mar 20, 2019
## 0.2.1 Mar 20, 2019
Changes:
- Add basic crypto functions, creation of wasm-crypto package
- blake2, bip39, sha2, xxhash
# 0.1.1 Mar 18, 2019
## 0.1.1 Mar 18, 2019
Changes:
- Initial release
+4 -1
View File
@@ -1 +1,4 @@
module.exports = require('@polkadot/dev/config/babel');
// Copyright 2019-2020 @polkadot/wasm-crypto authors & contributors
// SPDX-License-Identifier: Apache-2.0
module.exports = require('@polkadot/dev/config/babel-config-cjs.cjs');
View File
+12
View File
@@ -0,0 +1,12 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="initial-scale=0.5, maximum-scale=1">
<meta http-equiv="refresh" content="0;URL='https://polkadot.js.org/docs/'" />
<title>Redirecting to https://polkadot.js.org/docs/</title>
</head>
<body>
Redirecting to <a href="https://polkadot.js.org/docs/">https://polkadot.js.org/docs/</a>
</body>
</html>
+12
View File
@@ -0,0 +1,12 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="initial-scale=0.5, maximum-scale=1">
<meta http-equiv="refresh" content="0;URL='https://polkadot.js.org/docs/'" />
<title>Redirecting to https://polkadot.js.org/docs/</title>
</head>
<body>
Redirecting to <a href="https://polkadot.js.org/docs/">https://polkadot.js.org/docs/</a>
</body>
</html>
+12 -5
View File
@@ -1,12 +1,19 @@
/* eslint-disable @typescript-eslint/no-var-requires */
const config = require('@polkadot/dev/config/jest');
// Copyright 2019-2020 @polkadot/wasm-crypto authors & contributors
// SPDX-License-Identifier: Apache-2.0
const config = require('@polkadot/dev/config/jest.cjs');
module.exports = Object.assign({}, config, {
moduleNameMapper: {
'@polkadot/wasm-(schnorrkel)(.*)$': '<rootDir>/packages/wasm-$1/src/$2'
'@polkadot/wasm-crypto-asmjs(.*)$': '<rootDir>/packages/wasm-crypto-asmjs/build/$1',
'@polkadot/wasm-crypto-wasm(.*)$': '<rootDir>/packages/wasm-crypto-wasm/build/$1',
// eslint-disable-next-line sort-keys
'@polkadot/wasm-crypto(.*)$': '<rootDir>/packages/wasm-crypto/src/$1'
},
modulePathIgnorePatterns: [
'<rootDir>/packages/wasm-schnorrkel/build'
'<rootDir>/packages/wasm-crypto-asmjs/build',
'<rootDir>/packages/wasm-crypto-wasm/build',
'<rootDir>/packages/wasm-crypto/build'
],
resolver: './jest.resolver.js'
resolver: '@polkadot/dev/config/jest-resolver.cjs'
});
-12
View File
@@ -1,12 +0,0 @@
// Copyright 2017-2020 @polkadot/util authors & contributors
// This software may be modified and distributed under the terms
// of the Apache-2.0 license. See the LICENSE file for details.
// eslint-disable-next-line @typescript-eslint/no-var-requires
const path = require('path');
module.exports = function resolver (file, config) {
return file.includes('package.json')
? path.join(config.basedir.replace('/src', '/'), file)
: config.defaultResolver(file, config);
};
-13
View File
@@ -1,13 +0,0 @@
{
"npmClient": "yarn",
"useWorkspaces": true,
"command": {
"publish": {
"allowBranch": "master"
}
},
"packages": [
"packages/*"
],
"version": "1.0.1"
}
+17 -13
View File
@@ -1,27 +1,31 @@
{
"version": "1.0.1",
"repository": "https://github.com/polkadot-js/wasm",
"author": "Jaco Greeff <jacogr@gmail.com>",
"license": "Apache-2",
"private": true,
"engines": {
"yarn": "^1.10.1"
},
"workspaces": [
"packages/*"
],
"resolutions": {
"babel-core": "^7.0.0-bridge.0",
"typescript": "^3.7.5"
"typescript": "^4.1.3"
},
"scripts": {
"build": "./scripts/build.sh",
"build": "yarn build:wasm",
"build:release": "polkadot-ci-ghact-build",
"build:wasm": "./scripts/build.sh",
"lint": "polkadot-dev-run-lint",
"clean": "./scripts/clean.sh",
"postinstall": "polkadot-dev-yarn-only",
"test": "./scripts/test-rust.sh"
"test": "yarn test:wasm:rust",
"test:wasm:js": "yarn test:wasm:js:jest && yarn test:wasm:js:node",
"test:wasm:js:jest": "polkadot-dev-run-test ./test/jest.spec.js",
"test:wasm:js:node": "cd packages/wasm-crypto && node ./test/wasm.js && node ./test/asm.js",
"test:wasm:rust": "cd packages/wasm-crypto && RUST_BACKTRACE=full cargo test --release -- --nocapture"
},
"devDependencies": {
"@babel/core": "^7.8.3",
"@polkadot/dev": "^0.40.16",
"@polkadot/util": "^2.3.0-beta.6",
"override-require": "^1.1.1"
}
"@babel/core": "^7.12.10",
"@polkadot/dev": "^0.61.13",
"fflate": "^0.4.3"
},
"version": "3.1.1"
}
+19
View File
@@ -0,0 +1,19 @@
{
"name": "@polkadot/wasm-crypto-asmjs",
"version": "3.1.1",
"description": "Asm.js content for wasm-crypto",
"browser": "empty.js",
"main": "empty.js",
"module": "empty.mjs",
"react-native": "data.js",
"sideEffects": false,
"author": "Jaco Greeff <jacogr@gmail.com>",
"maintainers": [],
"contributors": [],
"license": "Apache-2.0",
"bugs": "https://github.com/polkadot-js/wasm/issues",
"homepage": "https://github.com/polkadot-js/wasm",
"dependencies": {
"@babel/runtime": "^7.12.5"
}
}
+4
View File
@@ -0,0 +1,4 @@
// Copyright 2017-2020 @polkadot/wasm-crypto-asmjs authors & contributors
// SPDX-License-Identifier: Apache-2.0
export const asmJsInit = null;
+4
View File
@@ -0,0 +1,4 @@
// Copyright 2017-2020 @polkadot/wasm-crypto-asmjs authors & contributors
// SPDX-License-Identifier: Apache-2.0
export const asmJsInit = null;
+19
View File
@@ -0,0 +1,19 @@
{
"name": "@polkadot/wasm-crypto-wasm",
"version": "3.1.1",
"description": "Wasm content for wasm-crypto",
"browser": "data.js",
"main": "data.js",
"module": "data.mjs",
"react-native": "data.js",
"sideEffects": false,
"author": "Jaco Greeff <jacogr@gmail.com>",
"maintainers": [],
"contributors": [],
"license": "Apache-2.0",
"bugs": "https://github.com/polkadot-js/wasm/issues",
"homepage": "https://github.com/polkadot-js/wasm",
"dependencies": {
"@babel/runtime": "^7.12.5"
}
}
+8
View File
@@ -0,0 +1,8 @@
// Copyright 2017-2020 @polkadot/wasm-crypto-wasm authors & contributors
// SPDX-License-Identifier: Apache-2.0
export const buffer = Buffer.from([]);
export const sizeCompressed = 0;
export const sizeUncompressed = 0;
+7
View File
@@ -0,0 +1,7 @@
// Copyright 2017-2020 @polkadot/wasm-crypto-wasm authors & contributors
// SPDX-License-Identifier: Apache-2.0
import { buffer, sizeUncompressed } from './buffer';
import { unzlibSync } from './fflate';
export const wasmBytes = unzlibSync(buffer, new Uint8Array(sizeUncompressed));
+4
View File
@@ -0,0 +1,4 @@
// Copyright 2017-2020 @polkadot/wasm-crypto-wasm authors & contributors
// SPDX-License-Identifier: Apache-2.0
export const wasmBytes = null;
+342
View File
@@ -0,0 +1,342 @@
// Copyright 2017-2020 @polkadot/wasm-crypto authors & contributors
// SPDX-License-Identifier: Apache-2.0
// MIT License
//
// Copyright (c) 2020 Arjun Barrett
//
// Copied from https://github.com/101arrowz/fflate/blob/73c737941ec89d85cdf0ad39ee6f26c5fdc95fd7/src/index.ts
// This only contains the unzlibSync function, no compression, no async, no workers
//
// These 2 issues are addressed as a short-term, stop-gap solution
// - https://github.com/polkadot-js/api/issues/2963
// - https://github.com/101arrowz/fflate/issues/17
//
// Only tweaks make here are some TS adjustments (we use strict null checks), the code is otherwise as-is with
// only the single required function provided (compression is still being done in the build with fflate)
/* eslint-disable */
// inflate state
type InflateState = {
// lmap
l?: Uint16Array;
// dmap
d?: Uint16Array;
// lbits
m?: number;
// dbits
n?: number;
// final
f?: number;
// pos
p?: number;
// byte
b?: number;
// lstchk
i?: boolean;
};
// aliases for shorter compressed code (most minifers don't do this)
const u8 = Uint8Array, u16 = Uint16Array, u32 = Uint32Array;
// code length index map
const clim = new u8([16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15]);
// fixed length extra bits
const fleb = new u8([0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 0, /* unused */ 0, 0, /* impossible */ 0]);
// fixed distance extra bits
// see fleb note
const fdeb = new u8([0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10, 11, 11, 12, 12, 13, 13, /* unused */ 0, 0]);
// get base, reverse index map from extra bits
const freb = (eb: Uint8Array, start: number) => {
const b = new u16(31);
for (let i = 0; i < 31; ++i) {
b[i] = start += 1 << eb[i - 1];
}
// numbers here are at max 18 bits
const r = new u32(b[30]);
for (let i = 1; i < 30; ++i) {
for (let j = b[i]; j < b[i + 1]; ++j) {
r[j] = ((j - b[i]) << 5) | i;
}
}
return [b, r] as const;
}
const [fl, revfl] = freb(fleb, 2);
// we can ignore the fact that the other numbers are wrong; they never happen anyway
fl[28] = 258, revfl[258] = 28;
const [fd] = freb(fdeb, 0);
// map of value to reverse (assuming 16 bits)
const rev = new u16(32768);
for (let i = 0; i < 32768; ++i) {
// reverse table algorithm from SO
let x = ((i & 0xAAAA) >>> 1) | ((i & 0x5555) << 1);
x = ((x & 0xCCCC) >>> 2) | ((x & 0x3333) << 2);
x = ((x & 0xF0F0) >>> 4) | ((x & 0x0F0F) << 4);
rev[i] = (((x & 0xFF00) >>> 8) | ((x & 0x00FF) << 8)) >>> 1;
}
// create huffman tree from u8 "map": index -> code length for code index
// mb (max bits) must be at most 15
// TODO: optimize/split up?
const hMap = ((cd: Uint8Array, mb: number, r: 0 | 1) => {
const s = cd.length;
// index
let i = 0;
// u16 "map": index -> # of codes with bit length = index
const l = new u16(mb);
// length of cd must be 288 (total # of codes)
for (; i < s; ++i) ++l[cd[i] - 1];
// u16 "map": index -> minimum code for bit length = index
const le = new u16(mb);
for (i = 0; i < mb; ++i) {
le[i] = (le[i - 1] + l[i - 1]) << 1;
}
let co: Uint16Array;
if (r) {
// u16 "map": index -> number of actual bits, symbol for code
co = new u16(1 << mb);
// bits to remove for reverser
const rvb = 15 - mb;
for (i = 0; i < s; ++i) {
// ignore 0 lengths
if (cd[i]) {
// num encoding both symbol and bits read
const sv = (i << 4) | cd[i];
// free bits
const r = mb - cd[i];
// start value
let v = le[cd[i] - 1]++ << r;
// m is end value
for (const m = v | ((1 << r) - 1); v <= m; ++v) {
// every 16 bit value starting with the code yields the same result
co[rev[v] >>> rvb] = sv;
}
}
}
} else {
co = new u16(s);
for (i = 0; i < s; ++i) co[i] = rev[le[cd[i] - 1]++] >>> (15 - cd[i]);
}
return co;
});
// fixed length tree
const flt = new u8(288);
for (let i = 0; i < 144; ++i) flt[i] = 8;
for (let i = 144; i < 256; ++i) flt[i] = 9;
for (let i = 256; i < 280; ++i) flt[i] = 7;
for (let i = 280; i < 288; ++i) flt[i] = 8;
// fixed distance tree
const fdt = new u8(32);
for (let i = 0; i < 32; ++i) fdt[i] = 5;
// fixed length map
const flrm = hMap(flt, 9, 1);
// fixed distance map
const fdrm = hMap(fdt, 5, 1);
// read d, starting at bit p and mask with m
const bits = (d: Uint8Array, p: number, m: number) => {
const o = p >>> 3;
return ((d[o] | (d[o + 1] << 8)) >>> (p & 7)) & m;
}
// read d, starting at bit p continuing for at least 16 bits
const bits16 = (d: Uint8Array, p: number) => {
const o = p >>> 3;
return ((d[o] | (d[o + 1] << 8) | (d[o + 2] << 16)) >>> (p & 7));
}
// get end of byte
const shft = (p: number) => (p >>> 3) + (p & 7 && 1);
// typed array slice - allows garbage collector to free original reference,
// while being more compatible than .slice
const slc = <T extends Uint8Array | Uint16Array | Uint32Array>(v: T, s: number, e?: number): T => {
if (s == null || s < 0) s = 0;
if (e == null || e > v.length) e = v.length;
// can't use .constructor in case user-supplied
const n = new (v instanceof u16 ? u16 : v instanceof u32 ? u32 : u8)(e - s) as T;
n.set(v.subarray(s, e));
return n;
}
// find max of array
const max = (a: Uint8Array | number[]) => {
let m = a[0];
for (let i = 1; i < a.length; ++i) {
if (a[i] > m) m = a[i];
}
return m;
};
// expands raw DEFLATE data
const inflt = (dat: Uint8Array, buf?: Uint8Array, st?: InflateState) => {
const noSt = !st || st.i;
if (!st) st = {};
// source length
const sl = dat.length;
// have to estimate size
const noBuf = !buf || !noSt;
// Assumes roughly 33% compression ratio average
if (!buf) buf = new u8(sl * 3);
// ensure buffer can fit at least l elements
const cbuf = (l: number) => {
let bl = buf!.length;
// need to increase size to fit
if (l > bl) {
// Double or set to necessary, whichever is greater
const nbuf = new u8(Math.max(bl << 1, l));
nbuf.set(buf!);
buf = nbuf;
}
};
// last chunk bitpos bytes
let final = st.f || 0, pos = st.p || 0, bt = st.b || 0, lm = st.l, dm = st.d, lbt = st.m, dbt = st.n;
if (final && !lm) return buf;
// total bits
const tbts = sl << 3;
do {
if (!lm) {
// BFINAL - this is only 1 when last chunk is next
st.f = final = bits(dat, pos, 1);
// type: 0 = no compression, 1 = fixed huffman, 2 = dynamic huffman
const type = bits(dat, pos + 1, 3);
pos += 3;
if (!type) {
// go to end of byte boundary
const s = shft(pos) + 4, l = dat[s - 4] | (dat[s - 3] << 8), t = s + l;
if (t > sl) {
if (noSt) throw 'unexpected EOF';
break;
}
// ensure size
if (noBuf) cbuf(bt + l);
// Copy over uncompressed data
buf.set(dat.subarray(s, t), bt);
// Get new bitpos, update byte count
st.b = bt += l, st.p = pos = t << 3;
continue;
}
else if (type == 1) lm = flrm, dm = fdrm, lbt = 9, dbt = 5;
else if (type == 2) {
// literal lengths
const hLit = bits(dat, pos, 31) + 257, hcLen = bits(dat, pos + 10, 15) + 4;
const tl = hLit + bits(dat, pos + 5, 31) + 1;
pos += 14;
// length+distance tree
const ldt = new u8(tl);
// code length tree
const clt = new u8(19);
for (let i = 0; i < hcLen; ++i) {
// use index map to get real code
clt[clim[i]] = bits(dat, pos + i * 3, 7);
}
pos += hcLen * 3;
// code lengths bits
const clb = max(clt), clbmsk = (1 << clb) - 1;
if (!noSt && pos + tl * (clb + 7) > tbts) break;
// code lengths map
const clm = hMap(clt, clb, 1);
for (let i = 0; i < tl;) {
const r = clm[bits(dat, pos, clbmsk)];
// bits read
pos += r & 15;
// symbol
const s = r >>> 4;
// code length to copy
if (s < 16) {
ldt[i++] = s;
} else {
// copy count
let c = 0, n = 0;
if (s == 16) n = 3 + bits(dat, pos, 3), pos += 2, c = ldt[i - 1];
else if (s == 17) n = 3 + bits(dat, pos, 7), pos += 3;
else if (s == 18) n = 11 + bits(dat, pos, 127), pos += 7;
while (n--) ldt[i++] = c;
}
}
// length tree distance tree
const lt = ldt.subarray(0, hLit), dt = ldt.subarray(hLit);
// max length bits
lbt = max(lt)
// max dist bits
dbt = max(dt);
lm = hMap(lt, lbt, 1);
dm = hMap(dt, dbt, 1);
} else throw 'invalid block type';
if (pos > tbts) throw 'unexpected EOF';
}
// Make sure the buffer can hold this + the largest possible addition
// maximum chunk size (practically, theoretically infinite) is 2^17;
if (noBuf) cbuf(bt + 131072);
const lms = (1 << lbt!) - 1, dms = (1 << dbt!) - 1;
const mxa = lbt! + dbt! + 18;
while (noSt || pos + mxa < tbts) {
// bits read, code
const c = lm[bits16(dat, pos) & lms], sym = c >>> 4;
pos += c & 15;
if (pos > tbts) throw 'unexpected EOF';
if (!c) throw 'invalid length/literal';
if (sym < 256) buf[bt++] = sym;
else if (sym == 256) {
lm = undefined;
break;
}
else {
let add = sym - 254;
// no extra bits needed if less
if (sym > 264) {
// index
const i = sym - 257, b = fleb[i];
add = bits(dat, pos, (1 << b) - 1) + fl[i];
pos += b;
}
// dist
const d = dm![bits16(dat, pos) & dms], dsym = d >>> 4;
if (!d) throw 'invalid distance';
pos += d & 15;
let dt = fd[dsym];
if (dsym > 3) {
const b = fdeb[dsym];
dt += bits16(dat, pos) & ((1 << b) - 1), pos += b;
}
if (pos > tbts) throw 'unexpected EOF';
if (noBuf) cbuf(bt + 131072);
const end = bt + add;
for (; bt < end; bt += 4) {
buf[bt] = buf[bt - dt];
buf[bt + 1] = buf[bt + 1 - dt];
buf[bt + 2] = buf[bt + 2 - dt];
buf[bt + 3] = buf[bt + 3 - dt];
}
bt = end;
}
}
st.l = lm, st.p = pos, st.b = bt;
if (lm) final = 1, st.m = lbt, st.d = dm, st.n = dbt;
} while (!final)
return bt == buf.length ? buf : slc(buf, 0, bt);
}
// zlib valid
const zlv = (d: Uint8Array) => {
if ((d[0] & 15) != 8 || (d[0] >>> 4) > 7 || ((d[0] << 8 | d[1]) % 31)) throw 'invalid zlib data';
if (d[1] & 32) throw 'invalid zlib data: preset dictionaries not supported';
}
/**
* Expands Zlib data
* @param data The data to decompress
* @param out Where to write the data. Saves memory if you know the decompressed size and provide an output buffer of that length.
* @returns The decompressed version of the data
*/
export function unzlibSync(data: Uint8Array, out?: Uint8Array) {
return inflt((zlv(data), data.subarray(2, -4)), out);
}
+365 -481
View File
File diff suppressed because it is too large Load Diff
+16 -9
View File
@@ -3,7 +3,7 @@
[package]
authors = ["Jaco Greeff <jacogr@gmail.com>"]
description = "WASM bindings to Rust crypto libaries."
description = "WASM bindings to Rust crypto libraries."
edition = "2018"
license = "Apache-2.0"
name = "wasm"
@@ -12,27 +12,34 @@ repository = "https://github.com/polkadot-js/wasm/"
version = "0.0.0"
[lib]
crate-type = ["cdylib", "rlib"]
crate-type = ["cdylib"]
[dependencies]
backtrace = "0.3.38"
blake2-rfc = "0.2.18"
byteorder = "1.3.1"
ed25519-dalek = { version = "1.0.0-pre.3", features = ["nightly"] }
ed25519-dalek = { version = "1.0.0-pre.4", features = [] }
hmac = "0.7.0"
# libsecp256k1 = "0.2.2"
pbkdf2 = { version = "0.3.0", default-features = false }
schnorrkel = { version = "0.8.5", features = ["nightly", "preaudit_deprecated", "u64_backend"] }
sha2 = "0.8.0"
tiny-bip39 = { version = "0.6.2", default-features = false }
schnorrkel = { version = "0.9.1", features = ["preaudit_deprecated", "u64_backend"] }
scrypt = { version = "0.2", default-features = false }
sha2 = "0.8.1"
tiny-bip39 = { version = "0.7", default-features = false }
tiny-keccak = { version = "2.0.1", features = ["keccak"] }
twox-hash = "1.5.0"
wasm-bindgen = "0.2"
wasm-bindgen = "=0.2.65"
wee_alloc = "0.4.3"
[dev-dependencies]
hex-literal = "0.2.0"
rand = { version = "0.6.5", features = ["wasm-bindgen"] }
rand = { version = "0.7.3", features = ["wasm-bindgen"] }
[profile.release]
codegen-units = 1
debug = false
debug-assertions = false
incremental = false
lto = true
opt-level = "z"
panic = "abort"
rpath = false
+1 -1
View File
@@ -12,7 +12,7 @@ Use it -
```js
const { u8aToHex } = require('@polkadot/util');
const { bio39Generate, bip39ToSeed, waitReady } = require('@polkadot/wasm-crypto');
const { bip39Generate, bip39ToSeed, waitReady } = require('@polkadot/wasm-crypto');
async function main () {
// first wait until the WASM has been loaded (async init)
+2
View File
@@ -0,0 +1,2 @@
[dependencies]
std = { default-features = false, features = ["panic_immediate_abort"] }
+19 -18
View File
@@ -1,25 +1,26 @@
{
"name": "@polkadot/wasm-crypto",
"version": "1.0.1",
"version": "3.1.1",
"author": "Jaco Greeff <jacogr@gmail.com>",
"files": [
"crypto-polyfill.js",
"exports.js",
"index.d.ts",
"index.js",
"wasm.d.ts",
"wasm.js",
"wasm_asm.js",
"wasm_asm_stub.js",
"wasm_promise.js",
"wasm_wasm.js"
],
"react-native": {
"./wasm_asm_stub.js": "./wasm_asm.js"
},
"main": "index.js",
"types": "index.d.ts",
"module": "index.mjs",
"sideEffects": [
"./detectPackage.js",
"./detectPackage.mjs"
],
"dependencies": {
"@babel/runtime": "^7.12.5",
"@polkadot/wasm-crypto-asmjs": "^3.1.1",
"@polkadot/wasm-crypto-wasm": "^3.1.1"
},
"devDependencies": {
"@polkadot/dev": "^0.61.13",
"@polkadot/util": "^5.0.2-9",
"@polkadot/x-randomvalues": "^5.0.2-9",
"override-require": "^1.1.1"
},
"peerDependencies": {
"@polkadot/util": "*"
"@polkadot/util": "*",
"@polkadot/x-randomvalues": "*"
}
}
+96
View File
@@ -0,0 +1,96 @@
// Copyright 2019-2020 @polkadot/wasm-crypto authors & contributors
// SPDX-License-Identifier: Apache-2.0
/* eslint-disable @typescript-eslint/no-non-null-assertion */
import type { AsmCreator, WasmCryptoInstance } from './types';
import { assert, stringToU8a, u8aToString } from '@polkadot/util';
let wasm: WasmCryptoInstance | null = null;
let cachegetInt32: Int32Array | null = null;
let cachegetUint8: Uint8Array | null = null;
export async function initWasm (wasmBytes: Uint8Array | null, asmFn: AsmCreator | null, wbg: Record<string, WebAssembly.ImportValue>): Promise<void> {
try {
assert(typeof WebAssembly !== 'undefined' && wasmBytes && wasmBytes.length, 'WebAssembly is not available in your environment');
const source = await WebAssembly.instantiate(wasmBytes, { wbg });
wasm = source.instance.exports as unknown as WasmCryptoInstance;
} catch (error) {
// if we have a valid supplied asm.js, return that
if (asmFn) {
wasm = asmFn(wbg);
} else {
console.error('FATAL: Unable to initialize @polkadot/wasm-crypto');
console.error(error);
wasm = null;
}
}
}
// FIXME We really would love to clean this up and have a sign like (wasm, ...params) => T
// Alas, TypeScript foo is not that great today, so we sadly have an extra closure here
export function withWasm <T, F extends (...params: never[]) => T> (fn: (wasm: WasmCryptoInstance) => F): F {
return ((...params: never[]): T => {
assert(wasm, 'The WASM interface has not been initialized. Ensure that you wait for the initialization Promise with waitReady() from @polkadot/wasm-crypto (or cryptoWaitReady() from @polkadot/util-crypto) before attempting to use WASM-only interfaces.');
return fn(wasm)(...params);
}) as unknown as F;
}
export function getWasm (): WasmCryptoInstance {
return wasm!;
}
export function getInt32 (): Int32Array {
if (cachegetInt32 === null || cachegetInt32.buffer !== wasm!.memory.buffer) {
cachegetInt32 = new Int32Array(wasm!.memory.buffer);
}
return cachegetInt32;
}
export function getUint8 (): Uint8Array {
if (cachegetUint8 === null || cachegetUint8.buffer !== wasm!.memory.buffer) {
cachegetUint8 = new Uint8Array(wasm!.memory.buffer);
}
return cachegetUint8;
}
export function getU8a (ptr: number, len: number): Uint8Array {
return getUint8().subarray(ptr / 1, ptr / 1 + len);
}
export function getString (ptr: number, len: number): string {
return u8aToString(getU8a(ptr, len));
}
export function allocU8a (arg: Uint8Array): [number, number] {
const ptr = wasm!.__wbindgen_malloc(arg.length * 1);
getUint8().set(arg, ptr / 1);
return [ptr, arg.length];
}
export function allocString (arg: string): [number, number] {
return allocU8a(stringToU8a(arg));
}
export function resultU8a (): Uint8Array {
const r0 = getInt32()[8 / 4 + 0];
const r1 = getInt32()[8 / 4 + 1];
const ret = getU8a(r0, r1).slice();
wasm!.__wbindgen_free(r0, r1 * 1);
return ret;
}
export function resultString (): string {
return u8aToString(resultU8a());
}
+25
View File
@@ -0,0 +1,25 @@
// Copyright 2017-2020 @polkadot/wasm-crypto authors & contributors
// SPDX-License-Identifier: Apache-2.0
// For esm, this should be import.meta.url or to get the same behavior as __dirname, we can use
//
// new URL(import.meta.url).pathname)
//
// The issue is the WP4 has "some" issues with import.meta.url. So because of bundlers, we can't have
// nice things... In this case it is even worse since import.meta.url won't even make it compile, so
// there is a complete dead end with usage thereof
//
// When that is fixed, a solution is to have both .js & .mjs files, with the following content -
//
// cjs: util.detectPackage(packageInfo, () => __dirname);
// esm: detectPackage(packageInfo, () => import.meta.url);
//
// With the above we additionally need a .d.ts to just export the packageInfo
import { detectPackage } from '@polkadot/util';
import packageInfo from './package-info.json';
detectPackage(packageInfo, typeof __dirname !== 'undefined' && __dirname);
export { packageInfo };
+90
View File
@@ -0,0 +1,90 @@
// Copyright 2019-2020 @polkadot/wasm-crypto authors & contributors
// SPDX-License-Identifier: Apache-2.0
/* eslint-disable camelcase */
import { getRandomValues } from '@polkadot/x-randomvalues';
import { getString, getU8a } from './bridge';
const DEFAULT_CRYPTO = { getRandomValues };
const DEFAULT_SELF = { crypto: DEFAULT_CRYPTO };
const heap: Array<unknown> = new Array(32).fill(undefined).concat(undefined, null, true, false);
let heapNext = heap.length;
function getObject (idx: number): unknown {
return heap[idx];
}
function dropObject (idx: number) {
if (idx < 36) {
return;
}
heap[idx] = heapNext;
heapNext = idx;
}
function takeObject (idx: number): unknown {
const ret = getObject(idx);
dropObject(idx);
return ret;
}
function addObject (obj: unknown): number {
if (heapNext === heap.length) {
heap.push(heap.length + 1);
}
const idx = heapNext;
heapNext = heap[idx] as number;
heap[idx] = obj;
return idx;
}
export function __wbindgen_is_undefined (idx: number): boolean {
return getObject(idx) === undefined;
}
export function __wbg_self_1b7a39e3a92c949c (): number {
return addObject(DEFAULT_SELF);
}
export function __wbg_require_604837428532a733 (ptr: number, len: number): never {
throw new Error(`Unable to require ${getString(ptr, len)}`);
}
// eslint-disable-next-line @typescript-eslint/no-unused-vars
export function __wbg_crypto_968f1772287e2df0 (_idx: number): number {
return addObject(DEFAULT_CRYPTO);
}
// eslint-disable-next-line @typescript-eslint/no-unused-vars
export function __wbg_getRandomValues_a3d34b4fee3c2869 (_idx: number): number {
return addObject(DEFAULT_CRYPTO.getRandomValues);
}
// eslint-disable-next-line @typescript-eslint/no-unused-vars
export function __wbg_getRandomValues_f5e14ab7ac8e995d (_arg0: number, ptr: number, len: number): void {
DEFAULT_CRYPTO.getRandomValues(getU8a(ptr, len));
}
// eslint-disable-next-line @typescript-eslint/no-unused-vars
export function __wbg_randomFillSync_d5bd2d655fdf256a (_idx: number, _ptr: number, _len: number): never {
throw new Error('randomFillsync is not available');
// getObject(idx).randomFillSync(getU8a(ptr, len));
}
export function __wbindgen_object_drop_ref (idx: number): void {
takeObject(idx);
}
export function abort (): never {
throw new Error('abort');
}
+231
View File
@@ -0,0 +1,231 @@
// Copyright 2019-2020 @polkadot/wasm-crypto authors & contributors
// SPDX-License-Identifier: Apache-2.0
import './detectPackage';
import { asmJsInit } from '@polkadot/wasm-crypto-asmjs';
import { wasmBytes } from '@polkadot/wasm-crypto-wasm';
import { allocString, allocU8a, getWasm, initWasm, resultString, resultU8a, withWasm } from './bridge';
import * as imports from './imports';
const wasmPromise = initWasm(wasmBytes, asmJsInit, imports).catch(() => null);
export const bip39Generate = withWasm((wasm) =>
(words: 12 | 15 | 18 | 21 | 24): string => {
wasm.ext_bip39_generate(8, words);
return resultString();
}
);
export const bip39ToEntropy = withWasm((wasm) =>
(phrase: string): Uint8Array => {
const [ptr0, len0] = allocString(phrase);
wasm.ext_bip39_to_entropy(8, ptr0, len0);
return resultU8a();
}
);
export const bip39ToMiniSecret = withWasm((wasm) =>
(phrase: string, password: string): Uint8Array => {
const [ptr0, len0] = allocString(phrase);
const [ptr1, len1] = allocString(password);
wasm.ext_bip39_to_mini_secret(8, ptr0, len0, ptr1, len1);
return resultU8a();
}
);
export const bip39ToSeed = withWasm((wasm) =>
(phrase: string, password: string): Uint8Array => {
const [ptr0, len0] = allocString(phrase);
const [ptr1, len1] = allocString(password);
wasm.ext_bip39_to_seed(8, ptr0, len0, ptr1, len1);
return resultU8a();
}
);
export const bip39Validate = withWasm((wasm) =>
(phrase: string): boolean => {
const [ptr0, len0] = allocString(phrase);
const ret = wasm.ext_bip39_validate(ptr0, len0);
return ret !== 0;
}
);
export const ed25519KeypairFromSeed = withWasm((wasm) =>
(seed: Uint8Array): Uint8Array => {
const [ptr0, len0] = allocU8a(seed);
wasm.ext_ed_from_seed(8, ptr0, len0);
return resultU8a();
}
);
export const ed25519Sign = withWasm((wasm) =>
(pubkey: Uint8Array, seckey: Uint8Array, message: Uint8Array): Uint8Array => {
const [ptr0, len0] = allocU8a(pubkey);
const [ptr1, len1] = allocU8a(seckey);
const [ptr2, len2] = allocU8a(message);
wasm.ext_ed_sign(8, ptr0, len0, ptr1, len1, ptr2, len2);
return resultU8a();
}
);
export const ed25519Verify = withWasm((wasm) =>
(signature: Uint8Array, message: Uint8Array, pubkey: Uint8Array): boolean => {
const [ptr0, len0] = allocU8a(signature);
const [ptr1, len1] = allocU8a(message);
const [ptr2, len2] = allocU8a(pubkey);
const ret = wasm.ext_ed_verify(ptr0, len0, ptr1, len1, ptr2, len2);
return ret !== 0;
}
);
export const sr25519DeriveKeypairHard = withWasm((wasm) =>
(pair: Uint8Array, cc: Uint8Array): Uint8Array => {
const [ptr0, len0] = allocU8a(pair);
const [ptr1, len1] = allocU8a(cc);
wasm.ext_sr_derive_keypair_hard(8, ptr0, len0, ptr1, len1);
return resultU8a();
}
);
export const sr25519DeriveKeypairSoft = withWasm((wasm) =>
(pair: Uint8Array, cc: Uint8Array): Uint8Array => {
const [ptr0, len0] = allocU8a(pair);
const [ptr1, len1] = allocU8a(cc);
wasm.ext_sr_derive_keypair_soft(8, ptr0, len0, ptr1, len1);
return resultU8a();
}
);
export const sr25519DerivePublicSoft = withWasm((wasm) =>
(pubkey: Uint8Array, cc: Uint8Array): Uint8Array => {
const [ptr0, len0] = allocU8a(pubkey);
const [ptr1, len1] = allocU8a(cc);
wasm.ext_sr_derive_public_soft(8, ptr0, len0, ptr1, len1);
return resultU8a();
}
);
export const sr25519KeypairFromSeed = withWasm((wasm) =>
(seed: Uint8Array): Uint8Array => {
const [ptr0, len0] = allocU8a(seed);
wasm.ext_sr_from_seed(8, ptr0, len0);
return resultU8a();
}
);
export const sr25519Sign = withWasm((wasm) =>
(pubkey: Uint8Array, secret: Uint8Array, message: Uint8Array): Uint8Array => {
const [ptr0, len0] = allocU8a(pubkey);
const [ptr1, len1] = allocU8a(secret);
const [ptr2, len2] = allocU8a(message);
wasm.ext_sr_sign(8, ptr0, len0, ptr1, len1, ptr2, len2);
return resultU8a();
}
);
export const sr25519Verify = withWasm((wasm) =>
(signature: Uint8Array, message: Uint8Array, pubkey: Uint8Array): boolean => {
const [ptr0, len0] = allocU8a(signature);
const [ptr1, len1] = allocU8a(message);
const [ptr2, len2] = allocU8a(pubkey);
const ret = wasm.ext_sr_verify(ptr0, len0, ptr1, len1, ptr2, len2);
return ret !== 0;
}
);
export const blake2b = withWasm((wasm) =>
(data: Uint8Array, key: Uint8Array, size: number): Uint8Array => {
const [ptr0, len0] = allocU8a(data);
const [ptr1, len1] = allocU8a(key);
wasm.ext_blake2b(8, ptr0, len0, ptr1, len1, size);
return resultU8a();
}
);
export const keccak256 = withWasm((wasm) =>
(data: Uint8Array): Uint8Array => {
const [ptr0, len0] = allocU8a(data);
wasm.ext_keccak256(8, ptr0, len0);
return resultU8a();
}
);
export const pbkdf2 = withWasm((wasm) =>
(data: Uint8Array, salt: Uint8Array, rounds: number): Uint8Array => {
const [ptr0, len0] = allocU8a(data);
const [ptr1, len1] = allocU8a(salt);
wasm.ext_pbkdf2(8, ptr0, len0, ptr1, len1, rounds);
return resultU8a();
}
);
export const scrypt = withWasm((wasm) =>
(password: Uint8Array, salt: Uint8Array, log2n: number, r: number, p: number): Uint8Array => {
const [ptr0, len0] = allocU8a(password);
const [ptr1, len1] = allocU8a(salt);
wasm.ext_scrypt(8, ptr0, len0, ptr1, len1, log2n, r, p);
return resultU8a();
}
);
export const sha512 = withWasm((wasm) =>
(data: Uint8Array): Uint8Array => {
const [ptr0, len0] = allocU8a(data);
wasm.ext_sha512(8, ptr0, len0);
return resultU8a();
}
);
export const twox = withWasm((wasm) =>
(data: Uint8Array, rounds: number) => {
const [ptr0, len0] = allocU8a(data);
wasm.ext_twox(8, ptr0, len0, rounds);
return resultU8a();
}
);
export function isReady (): boolean {
return !!getWasm();
}
export function waitReady (): Promise<boolean> {
return wasmPromise.then(() => isReady());
}
@@ -1,22 +0,0 @@
/* eslint-disable @typescript-eslint/no-var-requires */
// Copyright 2019-2020 @polkadot/wasm-crypto authors & contributors
// This software may be modified and distributed under the terms
// of the Apache-2.0 license. See the LICENSE file for details.
const crypto = require('crypto');
if (!global.crypto) {
global.crypto = {};
}
if (!global.crypto.getRandomValues) {
global.crypto.getRandomValues = function (arr) {
const buffer = crypto.randomBytes(arr.length);
return buffer.reduce((arr, value, index) => {
arr[index] = value;
return arr;
}, arr);
};
}
-49
View File
@@ -1,49 +0,0 @@
/* eslint-disable @typescript-eslint/no-var-requires */
// Copyright 2019-2020 @polkadot/wasm-crypto authors & contributors
// This software may be modified and distributed under the terms
// of the Apache-2.0 license. See the LICENSE file for details.
const { assert } = require('@polkadot/util');
const INIT_ERRROR = '@polkadot/wasm-crypto has not been initialized';
module.exports = function (stubbed) {
const wrapReady = (fn) =>
(...params) => {
assert(stubbed.isReady(), INIT_ERRROR);
return fn(...params);
};
return {
bip39Generate: wrapReady(stubbed.ext_bip39_generate),
bip39ToEntropy: wrapReady(stubbed.ext_bip39_to_entropy),
bip39ToMiniSecret: wrapReady(stubbed.ext_bip39_to_mini_secret),
bip39ToSeed: wrapReady(stubbed.ext_bip39_to_seed),
bip39Validate: wrapReady(stubbed.ext_bip39_validate),
ed25519KeypairFromSeed: wrapReady(stubbed.ext_ed_from_seed),
ed25519Sign: wrapReady(stubbed.ext_ed_sign),
ed25519Verify: wrapReady(stubbed.ext_ed_verify),
sr25519DeriveKeypairHard: wrapReady(stubbed.ext_sr_derive_keypair_hard),
sr25519DeriveKeypairSoft: wrapReady(stubbed.ext_sr_derive_keypair_soft),
sr25519DerivePublicSoft: wrapReady(stubbed.ext_sr_derive_public_soft),
sr25519KeypairFromSeed: wrapReady(stubbed.ext_sr_from_seed),
sr25519Sign: wrapReady(stubbed.ext_sr_sign),
sr25519Verify: wrapReady(stubbed.ext_sr_verify),
blake2b: wrapReady(stubbed.ext_blake2b),
keccak256: wrapReady(stubbed.ext_keccak256),
pbkdf2: wrapReady(stubbed.ext_pbkdf2),
// secp256k1IsRecoverable: wrapReady(stubbed.ext_secp256k1_is_recoverable);
// secp256k1Recover: wrapReady(stubbed.ext_secp256k1_recover);
sha512: wrapReady(stubbed.ext_sha512),
twox: wrapReady(stubbed.ext_twox),
isReady: stubbed.isReady,
waitReady: stubbed.waitReady
};
};
-31
View File
@@ -1,31 +0,0 @@
// Copyright 2019-2020 @polkadot/wasm-crypto authors & contributors
// This software may be modified and distributed under the terms
// of the Apache-2.0 license. See the LICENSE file for details.
export function bip39Generate (words: 12 | 15 | 18 | 21 | 24): string;
export function bip39ToEntropy (phrase: string): Uint8Array;
export function bip39ToMiniSecret (phrase: string, password: string): Uint8Array;
export function bip39ToSeed (phrase: string, password: string): Uint8Array;
export function bip39Validate (phrase: string): boolean;
export function ed25519KeypairFromSeed (seed: Uint8Array): Uint8Array;
export function ed25519Sign (publicKey: Uint8Array, secretKey: Uint8Array, message: Uint8Array): Uint8Array;
export function ed25519Verify (signature: Uint8Array, message: Uint8Array, publicKey: Uint8Array): boolean;
export function sr25519DeriveKeypairHard (pair: Uint8Array, chainCode: Uint8Array): Uint8Array;
export function sr25519DeriveKeypairSoft (pair: Uint8Array, chainCode: Uint8Array): Uint8Array;
export function sr25519DerivePublicSoft (publicKey: Uint8Array, chainCode: Uint8Array): Uint8Array;
export function sr25519KeypairFromSeed (seed: Uint8Array): Uint8Array;
export function sr25519Sign (publicKey: Uint8Array, secretKey: Uint8Array, message: Uint8Array): Uint8Array;
export function sr25519Verify (signature: Uint8Array, message: Uint8Array, publicKey: Uint8Array): boolean;
export function blake2b (data: Uint8Array, key: Uint8Array, byteSize: number): Uint8Array;
export function keccak256 (data: Uint8Array): Uint8Array;
export function pbkdf2 (data: Uint8Array, salt: Uint8Array, rounds: number): Uint8Array;
// export function secp256k1IsRecoverable (message: Uint8Array, signature: Uint8Array): number;
// export function secp256k1Recover (message: Uint8Array, signature: Uint8Array): Uint8Array;
export function sha512 (data: Uint8Array): Uint8Array;
export function twox (data: Uint8Array, rounds: number): Uint8Array;
export function isReady (): boolean;
export function waitReady (): Promise<boolean>;
-8
View File
@@ -1,8 +0,0 @@
/* eslint-disable @typescript-eslint/no-var-requires */
// Copyright 2019-2020 @polkadot/wasm-crypto authors & contributors
// This software may be modified and distributed under the terms
// of the Apache-2.0 license. See the LICENSE file for details.
const stubbed = require('./wasm');
module.exports = require('./exports')(stubbed);
@@ -1,5 +0,0 @@
// Copyright 2019-2020 @polkadot/wasm-crypto authors & contributors
// This software may be modified and distributed under the terms
// of the Apache-2.0 license. See the LICENSE file for details.
module.exports = {};
@@ -1,27 +0,0 @@
/* eslint-disable @typescript-eslint/no-var-requires */
// Copyright 2019-2020 @polkadot/wasm-crypto authors & contributors
// This software may be modified and distributed under the terms
// of the Apache-2.0 license. See the LICENSE file for details.
const pkg = require('./package.json');
const asm = require('./wasm_asm_stub');
const bytes = require('./wasm_wasm');
const imports = require('./wasm');
module.exports = async function createExportPromise () {
try {
const { instance } = await WebAssembly.instantiate(bytes, { './wasm': imports });
return instance.exports;
} catch (error) {
// if we have a valid supplied asm.js, return that
if (asm && asm.ext_blake2b) {
return asm;
}
console.error(`ERROR: Unable to initialize ${pkg.name} ${pkg.version}`);
console.error(error);
return null;
}
};
+11
View File
@@ -0,0 +1,11 @@
// Copyright 2017-2020 @polkadot/wasm-crypto authors & contributors
// SPDX-License-Identifier: Apache-2.0
// Be able to import json in TS
// https://stackoverflow.com/questions/49996456/importing-json-file-in-typescript
declare module '*.json' {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const value: any;
export default value;
}
+8 -2
View File
@@ -1,12 +1,18 @@
// Copyright 2019-2020 @polkadot/wasm-crypto authors & contributors
// This software may be modified and distributed under the terms
// of the Apache-2.0 license. See the LICENSE file for details.
// SPDX-License-Identifier: Apache-2.0
// Use `wee_alloc` as the global allocator.
#[global_allocator]
static ALLOC: wee_alloc::WeeAlloc = wee_alloc::WeeAlloc::INIT;
#[path = "rs/bip39.rs"]
pub mod bip39;
#[path = "rs/ed25519.rs"]
pub mod ed25519;
#[path = "rs/hashing.rs"]
pub mod hashing;
#[path = "rs/sr25519.rs"]
pub mod sr25519;
@@ -1,6 +1,5 @@
// Copyright 2019-2020 @polkadot/wasm-crypto authors & contributors
// This software may be modified and distributed under the terms
// of the Apache-2.0 license. See the LICENSE file for details.
// SPDX-License-Identifier: Apache-2.0
use bip39::{Mnemonic, MnemonicType, Language, Seed};
use hmac::Hmac;
@@ -48,7 +47,7 @@ pub fn ext_bip39_to_mini_secret(phrase: &str, password: &str) -> Vec<u8> {
result[..32].to_vec()
}
/// Creates a see from a bip-39 phrase
/// Creates a BTC/ETH compatible seed from a bip-39 phrase
///
/// @phrase: mnemonic phrase
///
@@ -1,8 +1,8 @@
// Copyright 2019-2020 @polkadot/wasm-crypto authors & contributors
// This software may be modified and distributed under the terms
// of the Apache-2.0 license. See the LICENSE file for details.
// SPDX-License-Identifier: Apache-2.0
use ed25519_dalek::{Keypair, PublicKey, SecretKey, Signature};
use std::convert::TryFrom;
use ed25519_dalek::{Keypair, PublicKey, SecretKey, Signature, Signer as _, Verifier as _};
use wasm_bindgen::prelude::*;
/// Keypair helper function.
@@ -14,27 +14,27 @@ fn create_from_pair(pair: &[u8]) -> Keypair {
}
/// Keypair helper function
fn create_from_parts(public: &[u8], secret: &[u8]) -> Keypair {
fn create_from_parts(pubkey: &[u8], seckey: &[u8]) -> Keypair {
let mut pair = vec![];
pair.extend_from_slice(secret);
pair.extend_from_slice(public);
pair.extend_from_slice(seckey);
pair.extend_from_slice(pubkey);
create_from_pair(&pair)
}
/// Keypair helper function.
fn create_from_seed(seed: &[u8]) -> Keypair {
let secret = SecretKey::from_bytes(seed).unwrap();
let public: PublicKey = (&secret).into();
let seckey = SecretKey::from_bytes(seed).unwrap();
let pubkey: PublicKey = (&seckey).into();
create_from_parts(public.as_bytes(), seed)
create_from_parts(pubkey.as_bytes(), seed)
}
/// PublicKey helper
fn create_public(public: &[u8]) -> PublicKey {
match PublicKey::from_bytes(public) {
Ok(public) => return public,
fn create_public(pubkey: &[u8]) -> PublicKey {
match PublicKey::from_bytes(pubkey) {
Ok(pubkey) => return pubkey,
Err(_) => panic!("Provided public key is invalid.")
}
}
@@ -57,14 +57,14 @@ pub fn ext_ed_from_seed(seed: &[u8]) -> Vec<u8> {
/// The combination of both public and private key must be provided.
/// This is effectively equivalent to a keypair.
///
/// * public: UIntArray with 32 element
/// * pubkey: UIntArray with 32 element
/// * private: UIntArray with 64 element
/// * message: Arbitrary length UIntArray
///
/// * returned vector is the signature consisting of 64 bytes.
#[wasm_bindgen]
pub fn ext_ed_sign(public: &[u8], secret: &[u8], message: &[u8]) -> Vec<u8> {
create_from_parts(public, secret)
pub fn ext_ed_sign(pubkey: &[u8], seckey: &[u8], message: &[u8]) -> Vec<u8> {
create_from_parts(pubkey, seckey)
.sign(message)
.to_bytes()
.to_vec()
@@ -76,13 +76,13 @@ pub fn ext_ed_sign(public: &[u8], secret: &[u8], message: &[u8]) -> Vec<u8> {
/// * message: Arbitrary length UIntArray
/// * pubkey: UIntArray with 32 element
#[wasm_bindgen]
pub fn ext_ed_verify(signature: &[u8], message: &[u8], public: &[u8]) -> bool {
let signature = match Signature::from_bytes(signature) {
pub fn ext_ed_verify(signature: &[u8], message: &[u8], pubkey: &[u8]) -> bool {
let signature = match Signature::try_from(signature) {
Ok(signature) => signature,
Err(_) => return false
};
create_public(public)
create_public(pubkey)
.verify(message, &signature)
.is_ok()
}
@@ -1,11 +1,11 @@
// Copyright 2019-2020 @polkadot/wasm-crypto authors & contributors
// This software may be modified and distributed under the terms
// of the Apache-2.0 license. See the LICENSE file for details.
// SPDX-License-Identifier: Apache-2.0
use blake2_rfc::blake2b::blake2b;
use byteorder::{ByteOrder, LittleEndian};
use hmac::Hmac;
use pbkdf2::pbkdf2;
use scrypt::{ScryptParams, scrypt};
use sha2::{Digest, Sha512};
// use secp256k1;
use tiny_keccak::{Hasher, Keccak};
@@ -58,13 +58,13 @@ pub fn ext_keccak256(data: &[u8]) -> Vec<u8> {
result.to_vec()
}
/// pbkdf2 hash from an input, salt for the number of specified rounds
/// pbkdf2 kdf from an input, salt for the number of specified rounds
///
/// * data: Arbitrary data to be hashed
/// * salt: Salt for this hash
/// * rounds: The number of rounds to perform
///
/// Returns a vecor with the hash result
/// Returns a vector with the hashed result
#[wasm_bindgen]
pub fn ext_pbkdf2(data: &[u8], salt: &[u8], rounds: u32) -> Vec<u8> {
let mut result = [0u8; 64];
@@ -75,6 +75,26 @@ pub fn ext_pbkdf2(data: &[u8], salt: &[u8], rounds: u32) -> Vec<u8> {
result.to_vec()
}
/// scrypt kdf from input, salt and config
///
/// * password: Password to hash
/// * salt: Salt for this hash
/// * log2_n: log2(n)
/// * r: r
/// * p: p
///
/// Returns vector with the hashed result
#[wasm_bindgen]
pub fn ext_scrypt(password: &[u8], salt: &[u8], log2_n: u8, r: u32, p: u32) -> Vec<u8> {
let params = ScryptParams::new(log2_n, r, p).unwrap();
let mut result = [0u8; 64];
match scrypt(password, salt, &params, &mut result) {
Ok(_) => return result.to_vec(),
Err(_) => panic!("Invalid scrypt hash.")
}
}
// /// Checks for the recoverability of a signature from message
// ///
// /// * message: The message
@@ -131,7 +151,7 @@ pub fn ext_pbkdf2(data: &[u8], salt: &[u8], rounds: u32) -> Vec<u8> {
///
/// * data: Arbitrary data to be hashed
///
/// Returns a vecor with the hash result
/// Returns a vector with the hash result
#[wasm_bindgen]
pub fn ext_sha512(data: &[u8]) -> Vec<u8> {
let mut hasher = Sha512::new();
@@ -148,7 +168,7 @@ pub fn ext_sha512(data: &[u8]) -> Vec<u8> {
/// * data: Arbitrary data to be hashed
/// * rounds: Number of 8-byte rounds to add to the output
///
/// Returns a vecor with the hash result
/// Returns a vector with the hash result
#[wasm_bindgen]
pub fn ext_twox(data: &[u8], rounds: u32) -> Vec<u8> {
let mut vec = vec![];
@@ -166,7 +186,7 @@ pub mod tests {
use hex_literal::hex;
use super::*;
// // Constructs the message that Ethereum RPC's `personal_sign` and `eth_sign` would sign.
// // Constructs the message that Ethereum RPCs `personal_sign` and `eth_sign` would sign.
// fn ethereum_signable_message(data: &[u8]) -> Vec<u8> {
// let prefix = b"Pay DOTs to the Polkadot account:";
// let mut l = prefix.len() + data.len();
@@ -215,6 +235,16 @@ pub mod tests {
assert_eq!(hash[..], expected[..]);
}
#[test]
fn can_scrypt() {
let password = b"password";
let salt = b"salt";
let expected = hex!("745731af4484f323968969eda289aeee005b5903ac561e64a5aca121797bf7734ef9fd58422e2e22183bcacba9ec87ba0c83b7a2e788f03ce0da06463433cda6");
let hash = ext_scrypt(password, salt, 14, 8, 1);
assert_eq!(hash[..], expected[..]);
}
// #[test]
// fn can_secp256k1_real_eth_sig() {
// let sig = hex!("7505f2880114da51b3f5d535f8687953c0ab9af4ab81e592eaebebf53b728d2b6dfd9b5bcd70fee412b1f31360e7c2774009305cb84fc50c1d0ff8034dfa5fff1c");
@@ -1,14 +1,14 @@
// Copyright 2019 Paritytech via https://github.com/paritytech/schnorrkel-js/
// Copyright 2019-2020 @polkadot/wasm-crypto authors & contributors
// This software may be modified and distributed under the terms
// of the Apache-2.0 license. See the LICENSE file for details.
// SPDX-License-Identifier: Apache-2.0
// Copyright 2019 Paritytech via https://github.com/paritytech/schnorrkel-js/
//
// Originally developed (as a fork) in https://github.com/polkadot-js/schnorrkel-js/
// which was adpated from the initial https://github.com/paritytech/schnorrkel-js/
// forked at commit eff430ddc3090f56317c80654208b8298ef7ab3f
use schnorrkel::{
ExpansionMode, Keypair, MiniSecretKey, PublicKey, SecretKey,
ExpansionMode, Keypair, MiniSecretKey, PublicKey, SecretKey, Signature,
derive::{Derivation, ChainCode, CHAIN_CODE_LENGTH},
};
use wasm_bindgen::prelude::*;
@@ -64,8 +64,8 @@ pub fn ext_sr_derive_keypair_soft(pair: &[u8], cc: &[u8]) -> Vec<u8> {
///
/// returned vector is the derived publicKey as a array of 32 bytes
#[wasm_bindgen]
pub fn ext_sr_derive_public_soft(public: &[u8], cc: &[u8]) -> Vec<u8> {
PublicKey::from_bytes(public)
pub fn ext_sr_derive_public_soft(pubkey: &[u8], cc: &[u8]) -> Vec<u8> {
PublicKey::from_bytes(pubkey)
.unwrap()
.derived_key_simple(create_cc(cc), &[]).0
.to_bytes()
@@ -105,16 +105,16 @@ pub fn ext_sr_from_pair(pair: &[u8]) -> Vec<u8> {
/// The combination of both public and private key must be provided.
/// This is effectively equivalent to a keypair.
///
/// * public: UIntArray with 32 element
/// * pubkey: UIntArray with 32 element
/// * private: UIntArray with 64 element
/// * message: Arbitrary length UIntArray
///
/// * returned vector is the signature consisting of 64 bytes.
#[wasm_bindgen]
pub fn ext_sr_sign(public: &[u8], secret: &[u8], message: &[u8]) -> Vec<u8> {
pub fn ext_sr_sign(pubkey: &[u8], secret: &[u8], message: &[u8]) -> Vec<u8> {
SecretKey::from_ed25519_bytes(secret)
.unwrap()
.sign_simple(SIGNING_CTX, message, &PublicKey::from_bytes(public).unwrap())
.sign_simple(SIGNING_CTX, message, &PublicKey::from_bytes(pubkey).unwrap())
.to_bytes()
.to_vec()
}
@@ -125,20 +125,13 @@ pub fn ext_sr_sign(public: &[u8], secret: &[u8], message: &[u8]) -> Vec<u8> {
/// * message: Arbitrary length UIntArray
/// * pubkey: UIntArray with 32 element
#[wasm_bindgen]
pub fn ext_sr_verify(signature: &[u8], message: &[u8], public: &[u8]) -> bool {
// This is where we only verify 0.8.0+ signatures, replacing the code below
//
// match Signature::from_bytes(signature) {
// Ok(signature) => PublicKey::from_bytes(public).unwrap()
// .verify_simple(SIGNING_CTX, message, &signature)
// .is_ok(),
// Err(_) => false
// };
PublicKey::from_bytes(public)
.unwrap()
.verify_simple_preaudit_deprecated(SIGNING_CTX, message, &signature)
.is_ok()
pub fn ext_sr_verify(signature: &[u8], message: &[u8], pubkey: &[u8]) -> bool {
match Signature::from_bytes(signature) {
Ok(signature) => PublicKey::from_bytes(pubkey).unwrap()
.verify_simple(SIGNING_CTX, message, &signature)
.is_ok(),
Err(_) => false
}
}
#[cfg(test)]
@@ -209,9 +202,9 @@ pub mod tests {
#[test]
fn can_verify_known_message() {
let message = b"Verifying that I am the owner of 5G9hQLdsKQswNPgB499DeA5PkFBbgkLPJWkkS6FAM6xGQ8xD. Hash: 221455a3\n";
let public = hex!("b4bfa1f7a5166695eb75299fd1c4c03ea212871c342f2c5dfea0902b2c246918");
let signature = hex!("5a9755f069939f45d96aaf125cf5ce7ba1db998686f87f2fb3cbdea922078741a73891ba265f70c31436e18a9acd14d189d73c12317ab6c313285cd938453202");
let message = b"I hereby verify that I control 5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY";
let public = hex!("d43593c715fdd31c61141abd04a99fd6822c8558854ccde39a5684e7a56da27d");
let signature = hex!("1037eb7e51613d0dcf5930ae518819c87d655056605764840d9280984e1b7063c4566b55bf292fcab07b369d01095879b50517beca4d26e6a65866e25fec0d83");
let is_valid = ext_sr_verify(&signature, message, &public);
assert!(is_valid);
+37
View File
@@ -0,0 +1,37 @@
// Copyright 2019-2020 @polkadot/wasm-crypto authors & contributors
// SPDX-License-Identifier: Apache-2.0
/* eslint-disable camelcase */
// wasm-pack build output (formatted) from pkg/wasm_bg.d.ts
export interface WasmCryptoInstance {
memory: WebAssembly.Memory;
__wbindgen_free(a: number, b: number): void;
__wbindgen_malloc(a: number): number;
__wbindgen_realloc(a: number, b: number, c: number): number;
__wbindgen_exn_store(a: number): void;
ext_bip39_generate(a: number, b: number): void;
ext_bip39_to_entropy(a: number, b: number, c: number): void;
ext_bip39_to_mini_secret(a: number, b: number, c: number, d: number, e: number): void;
ext_bip39_to_seed(a: number, b: number, c: number, d: number, e: number): void;
ext_bip39_validate(a: number, b: number): number;
ext_ed_from_seed(a: number, b: number, c: number): void;
ext_ed_sign(a: number, b: number, c: number, d: number, e: number, f: number, g: number): void;
ext_ed_verify(a: number, b: number, c: number, d: number, e: number, f: number): number;
ext_blake2b(a: number, b: number, c: number, d: number, e: number, f: number): void;
ext_keccak256(a: number, b: number, c: number): void;
ext_pbkdf2(a: number, b: number, c: number, d: number, e: number, f: number): void;
ext_scrypt(a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number): void;
ext_sha512(a: number, b: number, c: number): void;
ext_twox(a: number, b: number, c: number, d: number): void;
ext_sr_derive_keypair_hard(a: number, b: number, c: number, d: number, e: number): void;
ext_sr_derive_keypair_soft(a: number, b: number, c: number, d: number, e: number): void;
ext_sr_derive_public_soft(a: number, b: number, c: number, d: number, e: number): void;
ext_sr_from_seed(a: number, b: number, c: number): void;
ext_sr_sign(a: number, b: number, c: number, d: number, e: number, f: number, g: number): void;
ext_sr_verify(a: number, b: number, c: number, d: number, e: number, f: number): number;
}
export type AsmCreator = (wbg: Record<string, WebAssembly.ImportValue>) => WasmCryptoInstance;
@@ -0,0 +1,12 @@
// Copyright 2019-2020 @polkadot/wasm-crypto authors & contributors
// SPDX-License-Identifier: Apache-2.0
require('override-require')(
(request) =>
request.endsWith('@polkadot/wasm-crypto-asmjs') ||
request.endsWith('@polkadot/wasm-crypto-wasm'),
(request) =>
request.endsWith('@polkadot/wasm-crypto-asmjs')
? require('../../wasm-crypto-asmjs/build/data')
: require('../../wasm-crypto-wasm/build/empty')
);
+31 -22
View File
@@ -1,56 +1,65 @@
/* eslint-disable @typescript-eslint/camelcase */
/* eslint-disable @typescript-eslint/no-var-requires */
// Copyright 2019-2020 @polkadot/wasm-crypto authors & contributors
// This software may be modified and distributed under the terms
// of the Apache-2.0 license. See the LICENSE file for details.
// @ts-check
// SPDX-License-Identifier: Apache-2.0
/* eslint-disable camelcase */
const { assert, u8aToHex } = require('@polkadot/util');
function bip39_generate (wasm) {
const RESULT = wasm.bip39Generate(21);
const res = wasm.bip39Generate(21);
console.log('\tPHR', RESULT);
console.log('\tPHR', res);
assert(RESULT.split(' ').length === 21, 'ERROR: Invalid bip39 Phase length');
assert(res.split(' ').length === 21, 'ERROR: Invalid bip39 Phase length');
}
function bip39_generate_subsequent (wasm) {
const val1 = wasm.bip39Generate(24);
const val2 = wasm.bip39Generate(24);
console.log('\tVL1', val1);
console.log('\tVL2', val2);
assert(val1 !== val2, 'ERROR: Subsequent mnemonics are the same');
}
function bip39_validate (wasm) {
const RESULT = wasm.bip39Validate(wasm.bip39Generate(12));
const res = wasm.bip39Validate(wasm.bip39Generate(12));
console.log('\tVAL', RESULT);
console.log('\tVAL', res);
assert(RESULT, 'ERROR: Invalid bip39 validation');
assert(res, 'ERROR: Invalid bip39 validation');
}
function bip39_toEntropy (wasm) {
const RESULT = u8aToHex(wasm.bip39ToEntropy('legal winner thank year wave sausage worth useful legal winner thank yellow'));
const res = u8aToHex(wasm.bip39ToEntropy('legal winner thank year wave sausage worth useful legal winner thank yellow'));
console.log('\tENT', RESULT);
console.log('\tENT', res);
assert(RESULT === '0x7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f', 'ERROR: Invalid bip39 entropy');
assert(res === '0x7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f', 'ERROR: Invalid bip39 entropy');
}
function bip39_toMiniSecret (wasm) {
const RESULT = u8aToHex(wasm.bip39ToMiniSecret('legal winner thank year wave sausage worth useful legal winner thank yellow', 'Substrate'));
const res = u8aToHex(wasm.bip39ToMiniSecret('legal winner thank year wave sausage worth useful legal winner thank yellow', 'Substrate'));
console.log('\tMIN', RESULT);
console.log('\tMIN', res);
assert(RESULT === '0x4313249608fe8ac10fd5886c92c4579007272cb77c21551ee5b8d60b78041685', 'ERROR: Invalid bip39 mini secret');
assert(res === '0x4313249608fe8ac10fd5886c92c4579007272cb77c21551ee5b8d60b78041685', 'ERROR: Invalid bip39 mini secret');
}
function bip39_toSeed (wasm) {
const RESULT = u8aToHex(wasm.bip39ToSeed('seed sock milk update focus rotate barely fade car face mechanic mercy', ''));
const res = u8aToHex(wasm.bip39ToSeed('seed sock milk update focus rotate barely fade car face mechanic mercy', ''));
console.log('\tSEE', RESULT);
console.log('\tSEE', res);
assert(RESULT === '0x3c121e20de068083b49c2315697fb59a2d9e8643c24e5ea7628132c58969a027', 'ERROR: Invalid bip39 mini secret');
assert(res === '0x3c121e20de068083b49c2315697fb59a2d9e8643c24e5ea7628132c58969a027', 'ERROR: Invalid bip39 mini secret');
}
module.exports = {
bip39_generate,
bip39_validate,
bip39_generate_subsequent,
bip39_toEntropy,
bip39_toMiniSecret,
bip39_toSeed
bip39_toSeed,
bip39_validate
};
+5 -7
View File
@@ -1,9 +1,7 @@
/* eslint-disable @typescript-eslint/camelcase */
/* eslint-disable @typescript-eslint/no-var-requires */
// Copyright 2019-2020 @polkadot/wasm-crypto authors & contributors
// This software may be modified and distributed under the terms
// of the Apache-2.0 license. See the LICENSE file for details.
// @ts-check
// SPDX-License-Identifier: Apache-2.0
/* eslint-disable camelcase */
const crypto = require('crypto');
const { assert, hexToU8a, stringToU8a, u8aToHex } = require('@polkadot/util');
@@ -55,8 +53,8 @@ function ed25519_benchmark (wasm) {
}
module.exports = {
ed25519_benchmark,
ed25519_pairFromSeed,
ed25519_signAndVerify,
ed25519_verifyExisting,
ed25519_benchmark
ed25519_verifyExisting
};
+12 -5
View File
@@ -1,9 +1,7 @@
/* eslint-disable @typescript-eslint/camelcase */
/* eslint-disable @typescript-eslint/no-var-requires */
// Copyright 2019-2020 @polkadot/wasm-crypto authors & contributors
// This software may be modified and distributed under the terms
// of the Apache-2.0 license. See the LICENSE file for details.
// @ts-check
// SPDX-License-Identifier: Apache-2.0
/* eslint-disable camelcase */
const { assert, stringToU8a, u8aToHex } = require('@polkadot/util');
@@ -42,6 +40,14 @@ function pbkdf2Hash (wasm) {
// assert(pk === '0x91d366769d44a7c7690428bfdf67ec7eae23d2459694685257b6fc59d1baa1fe', 'ERROR: secp256k1Recover does not match');
// }
function scryptHash (wasm) {
const hash = u8aToHex(wasm.scrypt(stringToU8a('password'), stringToU8a('salt'), 14, 8, 1));
console.log('\tRES', hash);
assert(hash === '0x745731af4484f323968969eda289aeee005b5903ac561e64a5aca121797bf7734ef9fd58422e2e22183bcacba9ec87ba0c83b7a2e788f03ce0da06463433cda6', 'ERROR: scryptHash does not match');
}
function sha512Hash (wasm) {
const hash = u8aToHex(wasm.sha512(stringToU8a('hello world')));
@@ -64,6 +70,7 @@ module.exports = {
blake2bHash,
keccak256,
pbkdf2Hash,
scryptHash,
// secp256k1Recover,
sha512Hash,
twoxHash
+1 -3
View File
@@ -1,7 +1,5 @@
/* eslint-disable @typescript-eslint/no-var-requires */
// Copyright 2019-2020 @polkadot/wasm-crypto authors & contributors
// This software may be modified and distributed under the terms
// of the Apache-2.0 license. See the LICENSE file for details.
// SPDX-License-Identifier: Apache-2.0
const wasm = require('../../build/index');
const bip39 = require('./bip39');
+22 -12
View File
@@ -1,9 +1,7 @@
/* eslint-disable @typescript-eslint/camelcase */
/* eslint-disable @typescript-eslint/no-var-requires */
// Copyright 2019-2020 @polkadot/wasm-crypto authors & contributors
// This software may be modified and distributed under the terms
// of the Apache-2.0 license. See the LICENSE file for details.
// @ts-check
// SPDX-License-Identifier: Apache-2.0
/* eslint-disable camelcase */
const crypto = require('crypto');
const { assert, hexToU8a, stringToU8a, u8aToHex } = require('@polkadot/util');
@@ -35,9 +33,9 @@ function sr25519_devFromSeed (wasm) {
}
function sr25519_verifyExisting (wasm) {
const PK = hexToU8a('0xb4bfa1f7a5166695eb75299fd1c4c03ea212871c342f2c5dfea0902b2c246918');
const MESSAGE = stringToU8a('Verifying that I am the owner of 5G9hQLdsKQswNPgB499DeA5PkFBbgkLPJWkkS6FAM6xGQ8xD. Hash: 221455a3\n');
const SIGNATURE = hexToU8a('0x5a9755f069939f45d96aaf125cf5ce7ba1db998686f87f2fb3cbdea922078741a73891ba265f70c31436e18a9acd14d189d73c12317ab6c313285cd938453202');
const PK = hexToU8a('0xd43593c715fdd31c61141abd04a99fd6822c8558854ccde39a5684e7a56da27d');
const MESSAGE = stringToU8a('I hereby verify that I control 5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY');
const SIGNATURE = hexToU8a('0xb83881d3bd7302981ee1c504fe5b7b394682927131fc0846fd616bb40fa14d02640fd2aca785b4cb57904765c2e4e75f59a7dd30154c209964369912091f6981');
const isValid = wasm.sr25519Verify(SIGNATURE, MESSAGE, PK);
@@ -46,6 +44,17 @@ function sr25519_verifyExisting (wasm) {
assert(isValid, 'ERROR: Unable to verify signature');
}
function sr25519_sign_deterministic (wasm) {
const [, pk, sk] = randomPair(wasm);
const sig1 = u8aToHex(wasm.sr25519Sign(pk, sk, stringToU8a('this is a message')));
const sig2 = u8aToHex(wasm.sr25519Sign(pk, sk, stringToU8a('this is a message')));
console.log('\tSG1', sig1);
console.log('\tSG2', sig2);
assert(sig1 !== sig2, 'ERROR: Signatures are deterministic');
}
function sr25519_signAndVerify (wasm) {
const [, pk, sk] = randomPair(wasm);
const signature = wasm.sr25519Sign(pk, sk, stringToU8a('this is a message'));
@@ -112,14 +121,15 @@ function sr25519_benchmark (wasm) {
}
module.exports = {
sr25519_pairFromSeed,
sr25519_devFromSeed,
sr25519_benchmark,
sr25519_deriveHard,
sr25519_deriveHardKnown,
sr25519_deriveSoft,
sr25519_deriveSoftKnown,
sr25519_deriveSoftPubkey,
sr25519_devFromSeed,
sr25519_pairFromSeed,
sr25519_signAndVerify,
sr25519_verifyExisting,
sr25519_benchmark
sr25519_sign_deterministic,
sr25519_verifyExisting
};
+2 -7
View File
@@ -1,14 +1,9 @@
/* eslint-disable @typescript-eslint/no-var-requires */
// Copyright 2019-2020 @polkadot/wasm-crypto authors & contributors
// This software may be modified and distributed under the terms
// of the Apache-2.0 license. See the LICENSE file for details.
// SPDX-License-Identifier: Apache-2.0
global.WebAssembly = null;
require('override-require')(
(request) => request === './wasm_asm_stub',
() => require('../build/wasm_asm')
);
require('./alias-imports');
const { runUnassisted } = require('./all');
+7 -5
View File
@@ -1,13 +1,15 @@
/* eslint-disable @typescript-eslint/no-var-requires */
// Copyright 2019-2020 @polkadot/wasm-crypto authors & contributors
// This software may be modified and distributed under the terms
// of the Apache-2.0 license. See the LICENSE file for details.
// SPDX-License-Identifier: Apache-2.0
require('../build/crypto-polyfill');
/**
* @jest-environment jsdom
*/
// override-require in jest.config.js
const { beforeAll, tests, wasm } = require('./all');
describe('schnorrkel-js', () => {
describe('wasm-crypto', () => {
beforeEach(async () => {
await beforeAll();
});
+3 -4
View File
@@ -1,8 +1,7 @@
/* eslint-disable @typescript-eslint/no-var-requires */
// Copyright 2019-2020 @polkadot/wasm-crypto authors & contributors
// This software may be modified and distributed under the terms
// of the Apache-2.0 license. See the LICENSE file for details.
// @ts-check
// SPDX-License-Identifier: Apache-2.0
require('./alias-imports');
const { runUnassisted } = require('./all');
@@ -5,13 +5,7 @@
set -e
echo "*** Testing package"
DEST=packages/wasm-crypto/build/esm
echo "*** Testing WASM"
node ./test/wasm.js
echo "*** Testing ASM.js"
node ./test/asm.js
echo "*** Testing via Jest"
yarn jest ./test/jest.spec.js
./scripts/clean-js.sh
yarn polkadot-dev-build-ts
-82
View File
@@ -1,82 +0,0 @@
#!/usr/bin/env bash
# Copyright 2019-2020 @polkadot/wasm authors & contributors
# This software may be modified and distributed under the terms
# of the Apache-2.0 license. See the LICENSE file for details.
set -e
BGJ=build/wasm_bg.js
SRC_WASM=build/wasm.js
DEF=build/wasm.d.ts
WSM=build/wasm_bg.wasm
OPT=build/wasm_opt.wasm
ASM=build/wasm_asm.js
echo "*** Building package"
# cleanup old
echo "*** Cleaning old builds"
rm -rf ./build ./pkg
# build new via nightly & wasm-pack
echo "*** Building WASM output"
rustup run nightly wasm-pack build --release --scope polkadot --target nodejs
mv pkg build
# optimise
echo "*** Optimising WASM output"
../../binaryen/bin/wasm-opt $WSM -Os -o $OPT
# convert wasm to base64 structure
echo "*** Packing WASM into base64"
node ../../scripts/pack-wasm-base64.js
# build asmjs version from the input (optimised) WASM
echo "*** Building asm.js version"
../../binaryen/bin/wasm2js --output $ASM $OPT
# cleanup the generated output, sadly there are no node-js outputs above
sed -i -e 's/import {/\/\/ import {/g' $ASM
sed -i -e 's/function asmFunc/var schnorrkel = require('\''\.\/wasm'\''); function asmFunc/g' $ASM
sed -i -e 's/{abort.*},memasmFunc/schnorrkel, memasmFunc/g' $ASM
sed -i -e 's/export var /module\.exports\./g' $ASM
# copy our package interfaces
echo "*** Copying package sources"
cp src/js/* build/
# we are swapping to a async interface for webpack support (wasm limits)
sed -i -e 's/wasm = require/\/\/ wasm = require/g' $SRC_WASM
# We don't want inline requires
sed -i -e 's/var wasm;/const crypto = require('\''crypto'\''); let wasm; const requires = { crypto };/g' $SRC_WASM
sed -i -e 's/return addHeapObject(require(varg0));/return addHeapObject(requires[varg0]);/g' $SRC_WASM
# this creates issues in both the browser and RN (@polkadot/util has a polyfill)
sed -i -e 's/const TextEncoder = require('\''util'\'')\.TextEncoder;/const { stringToU8a } = require('\''@polkadot\/util'\'');/g' $SRC_WASM
sed -i -e 's/let cachedTextEncoder = new /\/\/ let cachedTextEncoder = new /g' $SRC_WASM
sed -i -e 's/cachedTextEncoder\.encode/stringToU8a/g' $SRC_WASM
# this creates issues in both the browser and RN (@polkadot/util has a polyfill)
sed -i -e 's/const TextDecoder = require('\''util'\'')\.TextDecoder;/const { u8aToString } = require('\''@polkadot\/util'\'');/g' $SRC_WASM
sed -i -e 's/let cachedTextDecoder = new /\/\/ let cachedTextDecoder = new /g' $SRC_WASM
sed -i -e 's/cachedTextDecoder\.decode/u8aToString/g' $SRC_WASM
# construct our promise and add ready helpers (WASM)
echo "
module.exports.abort = function () { throw new Error('abort'); };
const createPromise = require('./wasm_promise');
const wasmPromise = createPromise().catch(() => null);
module.exports.isReady = function () { return !!wasm; }
module.exports.waitReady = function () { return wasmPromise.then(() => !!wasm); }
wasmPromise.then((_wasm) => { wasm = _wasm });
" >> $SRC_WASM
# add extra methods to type definitions
echo "
export function isReady(): boolean;
export function waitReady(): Promise<boolean>;
" >> $DEF
+48
View File
@@ -0,0 +1,48 @@
#!/usr/bin/env bash
# Copyright 2019-2020 @polkadot/wasm authors & contributors
# This software may be modified and distributed under the terms
# of the Apache-2.0 license. See the LICENSE file for details.
set -e
# also change in install-build-deps
RUST_VER=nightly-2020-10-25
WSM=bytes/wasm_bg.wasm
OPT=bytes/wasm_opt.wasm
ASM=wasm-crypto-asmjs/build/data.js
# build new via wasm-pack
echo "*** Building Rust sources"
cd wasm-crypto
rustup run $RUST_VER xargo build --target wasm32-unknown-unknown --release
# rustup run $RUST_VER cargo build --target wasm32-unknown-unknown --release -Z build-std=std,panic_abort
cd ..
echo "*** Converting to WASM"
../bindgen/wasm-bindgen wasm-crypto/target/wasm32-unknown-unknown/release/wasm.wasm --out-dir bytes --target web
# wasm-pack build --release --scope polkadot --target web
# optimise
echo "*** Optimising WASM output"
# ../../wabt/bin/wasm-strip $WSM
../binaryen/bin/wasm-opt $WSM -Os -o $OPT
# convert wasm to base64 structure
echo "*** Packing WASM into baseX"
node ../scripts/pack-wasm-base.js
# build asmjs version from the input (optimised) WASM
echo "*** Building asm.js version"
../binaryen/bin/wasm2js --output $ASM $OPT
# cleanup the generated asm, converting to cjs
sed -i -e '/import {/d' $ASM
sed -i -e '/export var /d' $ASM
sed -i -e 's/{abort.*},memasmFunc/wbg, memasmFunc/g' $ASM
sed -i -e 's/var retasmFunc = /const asmJsInit = (wbg) => /' $ASM
echo "module.exports = { asmJsInit };" >> $ASM
# cleanups
rm -rf wasm-crypto-asmjs/build/*-e
rm -rf wasm-crypto-wasm/build/*-e
+14 -16
View File
@@ -5,26 +5,24 @@
set -e
./scripts/install-build-deps.sh
echo "*** Building JavaScript"
./scripts/build-js.sh
echo "*** Building packages"
echo "*** Building WASM"
cd packages
PACKAGES=( $(ls -1d *) )
../scripts/build-wasm.sh
for PKG in "${PACKAGES[@]}"; do
if [ -f "$PKG/package.json" ]; then
echo "*** Building $PKG"
cd $PKG
yarn test:wasm:js
../../scripts/build-package.sh
../../scripts/test-package.sh
rm -rf build/*-e build/package.json build/README.md
ls -al build
cd ..
fi
done
echo ""
echo "*** wasm-crypto"
ls -alR wasm-crypto/build
echo ""
echo "*** wasm-crypto-asmjs"
ls -alR wasm-crypto-asmjs/build
echo ""
echo "*** wasm-crypto-wasm"
ls -alR wasm-crypto-wasm/build
cd ..
+10
View File
@@ -0,0 +1,10 @@
#!/usr/bin/env bash
# Copyright 2019-2020 @polkadot/wasm authors & contributors
# This software may be modified and distributed under the terms
# of the Apache-2.0 license. See the LICENSE file for details.
set -e
# cleanup old
echo "*** Cleaning old builds"
rm -rf packages/*/build packages/bytes
+5 -17
View File
@@ -5,23 +5,11 @@
set -e
./scripts/install-build-deps.sh
./scripts/clean-js.sh
echo "*** Cleaning packages"
cd packages
echo "*** Cleaning wasm"
cd packages/wasm-crypto
PACKAGES=( $(ls -1d *) )
cargo clean
for PKG in "${PACKAGES[@]}"; do
if [ -f "$PKG/package.json" ]; then
echo "*** Cleaning $PKG"
cd $PKG
rm -rf build
cargo clean
cd ..
fi
done
cd ..
cd ../..
+54 -18
View File
@@ -5,27 +5,63 @@
set -e
# wasm2js for wasm -> asm.js
BINARYEN=( "wasm-opt" "wasm2js" )
# also change in build-package
RUST_VER=nightly-2020-10-25
# install wasm-pack as required
if ! [ -x "$(command -v wasm-pack)" ]; then
echo "*** Installing wasm-pack"
curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh
BINARYEN_REPO=https://github.com/WebAssembly/binaryen
BINARYEN_VER=version_97
BINARYEN_ZIP=
BINDGEN_REPO=https://github.com/rustwasm/wasm-bindgen
BINDGEN_VER=0.2.65
BINDGEN_ZIP=
WABT_REPO=https://github.com/WebAssembly/wabt
WABT_VER=1.0.19
WABT_ZIP=
unamestr=`uname`
# toolchain with rust-src (for panic overrdides) and the right wasm32 toolchain
rustup toolchain install $RUST_VER -c rust-src -t wasm32-unknown-unknown
cargo install xargo
# if ! [ -x "$(command -v wasm-pack)" ]; then
# echo "*** Installing wasm-pack"
# curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh
# fi
if [[ "$unamestr" == 'Linux' ]]; then
echo "*** Detected Linux"
BINARYEN_ZIP=binaryen-$BINARYEN_VER-x86_64-linux
BINDGEN_ZIP=wasm-bindgen-$BINDGEN_VER-x86_64-unknown-linux-musl
WABT_ZIP=wabt-$WABT_VER-ubuntu
elif [[ "$unamestr" == "Darwin" ]]; then
echo "*** Detected Mac"
BINARYEN_ZIP=binaryen-$BINARYEN_VER-x86_64-macos
BINDGEN_ZIP=wasm-bindgen-$BINDGEN_VER-x86_64-apple-darwin
WABT_ZIP=wabt-$WABT_VER-macos
else
echo "*** Unknown platform $unamestr, unable to install wasm helper binaries"
exit 1
fi
# install binaryen as required
if [ ! -d "binaryen" ]; then
echo "*** Installing binaryen"
git clone --recursive https://github.com/WebAssembly/binaryen.git
rm -rf binaryen/test
echo "*** Downloading binaryen"
curl -L $BINARYEN_REPO/releases/download/$BINARYEN_VER/$BINARYEN_ZIP.tar.gz | tar xz
mv binaryen-$BINARYEN_VER binaryen
ls -alR binaryen
fi
for BIN in "${BINARYEN[@]}"; do
if [ ! -f "binaryen/bin/$BIN" ]; then
echo "*** Building $BIN"
cd binaryen
cmake . && make $BIN
cd ..
fi
done
if [ ! -d "bindgen" ]; then
echo "*** Downloading bindgen"
curl -L $BINDGEN_REPO/releases/download/$BINDGEN_VER/$BINDGEN_ZIP.tar.gz | tar xz
mv $BINDGEN_ZIP bindgen
ls -alR bindgen
fi
# if [ ! -d "wabt" ]; then
# echo "*** Downloading wabt"
# curl -L $WABT_REPO/releases/download/$WABT_VER/$WABT_ZIP.tar.gz | tar xz
# mv wabt-$WABT_VER wabt
# fi
+48
View File
@@ -0,0 +1,48 @@
// Copyright 2019-2020 @polkadot/wasm authors & contributors
// SPDX-License-Identifier: Apache-2.0
const fs = require('fs');
const { formatNumber } = require('@polkadot/util');
const A_NAME = 'wasm-crypto-asmjs';
const W_NAME = 'wasm-crypto-wasm';
function hdr (package) {
return `// Copyright 2019-2020 @polkadot/${package} authors & contributors
// SPDX-License-Identifier: Apache-2.0
// Generated as part of the build, do not edit
`;
}
// only one of the deps are included, here are the details for package.json -
// "fflate": "^0.4.2"
// "lz4js": "^0.2.0"
function getWasmBuffer (lib = 'fflate') {
const data = fs.readFileSync('./bytes/wasm_opt.wasm');
const compressed = lib === 'fflate'
? Buffer.from(require('fflate').zlibSync(data, { level: 9 }))
: Buffer.from(require('lz4js').compress(data));
console.log(`*** Compressed WASM via ${lib}: ${formatNumber(data.length)} -> ${formatNumber(compressed.length)} (${(100 * compressed.length / data.length).toFixed(2)}%)`);
return { compressed, sizeUncompressed: data.length };
}
fs.writeFileSync(`./${A_NAME}/build/data.mjs`, `${hdr(A_NAME)}
export { asmJsInit } from './data.js';
`);
fs.writeFileSync(`./${W_NAME}/build/buffer.mjs`, `${hdr(W_NAME)}
export { buffer, sizeCompressed, sizeUncompressed } from './buffer.js';
`);
const { compressed, sizeUncompressed } = getWasmBuffer();
fs.writeFileSync(`./${W_NAME}/build/buffer.js`, `${hdr(W_NAME)}
const sizeCompressed = ${compressed.length};
const sizeUncompressed = ${sizeUncompressed};
const buffer = Buffer.from('${compressed.toString('base64')}', 'base64');
module.exports = { buffer, sizeCompressed, sizeUncompressed };
`);
-11
View File
@@ -1,11 +0,0 @@
// Copyright 2019-2020 @polkadot/wasm authors & contributors
// This software may be modified and distributed under the terms
// of the Apache-2.0 license. See the LICENSE file for details.
/* eslint-disable @typescript-eslint/no-var-requires */
const fs = require('fs');
const buffer = fs.readFileSync('./build/wasm_opt.wasm');
fs.writeFileSync('./build/wasm_wasm.js', `
module.exports = Buffer.from('${buffer.toString('base64')}', 'base64');
`);
-25
View File
@@ -1,25 +0,0 @@
#!/usr/bin/env bash
# Copyright 2019-2020 @polkadot/wasm authors & contributors
# This software may be modified and distributed under the terms
# of the Apache-2.0 license. See the LICENSE file for details.
set -e
echo "*** Testing packages"
cd packages
PACKAGES=( $(ls -1d *) )
for PKG in "${PACKAGES[@]}"; do
if [ -f "$PKG/package.json" ]; then
echo "*** Testing $PKG"
cd $PKG
echo "*** Testing Rust"
RUST_BACKTRACE=full rustup run nightly cargo test --release -- --nocapture
cd ..
fi
done
cd ..
+4 -2
View File
@@ -1,5 +1,5 @@
{
"extends": "./node_modules/@polkadot/dev/config/tsconfig",
"extends": "@polkadot/dev/config/tsconfig.json",
"exclude": [
"build/**/*",
"**/build/**/*"
@@ -7,7 +7,9 @@
"compilerOptions": {
"baseUrl": ".",
"paths": {
"@polkadot/wasm-schnorrkel": [ "packages/wasm-schnorrkel/src" ]
"@polkadot/wasm-crypto-asmjs": [ "packages/wasm-crypto-asmjs/src/data" ],
"@polkadot/wasm-crypto-wasm": [ "packages/wasm-crypto-wasm/src/data" ],
"@polkadot/wasm-crypto": [ "packages/wasm-crypto/src" ]
},
"skipLibCheck": true,
"typeRoots": [
-16
View File
@@ -1,16 +0,0 @@
module.exports = {
name: 'Polkadot JS WASM',
exclude: '**/*+(index|e2e|spec).ts',
excludeExternals: true,
excludeNotExported: true,
excludeProtected: true,
excludePrivate: true,
hideGenerator: true,
includeDeclarations: false,
out: 'docs',
module: 'commonjs',
moduleResolution: 'node',
mdEngine: 'gitbook',
stripInternal: 'true',
theme: 'markdown'
};
+10290 -13883
View File
File diff suppressed because it is too large Load Diff