Compare commits

..
270 Commits
Author SHA1 Message Date
github-actions[bot] 27bef46818 [CI Skip] release/stable 4.5.1
skip-checks: true
2021-12-03 11:48:36 +00:00
Jaco 2b4ed56dcb 4.5.1 (#245)
* 4.5.1

* Bump deps
2021-12-03 13:43:15 +02:00
github-actions[bot] e167eba7d8 [CI Skip] release/beta 4.4.2-9
skip-checks: true
2021-12-03 09:54:40 +00:00
Jaco 272050938f Local variable cleanups (#244)
* Local variable cleanups

* Fixup

* Revert res moves
2021-12-03 11:49:41 +02:00
github-actions[bot] 3ee381512b [CI Skip] release/beta 4.4.2-8
skip-checks: true
2021-12-03 07:11:06 +00:00
Jaco a2d5affb88 Adjust formatting (#243)
* Adjust formatting

* Remove all unwrap

* Err(_) => _
2021-12-03 09:05:43 +02:00
github-actions[bot] 2b759aab12 [CI Skip] release/beta 4.4.2-7
skip-checks: true
2021-12-03 04:54:44 +00:00
Jaco 223d7bf514 publicKey from slice in secp256k1 compress/expand (#242) 2021-12-03 06:48:02 +02:00
github-actions[bot] fa2eb4e214 [CI Skip] release/beta 4.4.2-6
skip-checks: true
2021-12-02 12:24:51 +00:00
Jaco 7689afb616 Add secp256k1 interfaces (#241)
* Add secp256k1 functions

* features for rand

* JS tests

* signing

* CHANGELOG

* Add secp256k1 seed
2021-12-02 14:19:33 +02:00
github-actions[bot] 10002e9ec5 [CI Skip] release/beta 4.4.2-5
skip-checks: true
2021-12-01 08:12:11 +00:00
Jaco b2a0af0df4 Adjust stale cron (#240) 2021-12-01 10:07:03 +02:00
github-actions[bot] 4966fd2837 [CI Skip] release/beta 4.4.2-4
skip-checks: true
2021-11-30 11:24:34 +00:00
Jaco 421d36d159 Simplify base64 bytes decoding (#239) 2021-11-30 13:19:24 +02:00
github-actions[bot] 74270adba7 [CI Skip] release/beta 4.4.2-3
skip-checks: true
2021-11-30 09:23:58 +00:00
Jaco 2b97759fa7 WASM function JS interface construction (#238) 2021-11-30 11:17:08 +02:00
github-actions[bot] b8b9784763 [CI Skip] release/beta 4.4.2-2
skip-checks: true
2021-11-28 07:17:05 +00:00
Jaco 8439d5c668 Bump common (#237) 2021-11-28 09:12:15 +02:00
Github Actions cb3a0f667a [CI Skip] release/beta 4.4.2-1
skip-checks: true
2021-11-24 14:57:49 +00:00
Jaco adf21a5fc2 Adjust stale schedule (#236) 2021-11-24 16:52:47 +02:00
Github Actions 4c28fadc07 [CI Skip] release/beta 4.4.2-0
skip-checks: true
2021-11-22 06:27:27 +00:00
Jaco 2849a05507 Bump dev & common (#235) 2021-11-22 08:22:24 +02:00
Github Actions 801ed235cf [CI Skip] release/stable 4.4.1
skip-checks: true
2021-11-22 05:03:50 +00:00
Jaco 98433c7399 4.4.1 (#234) 2021-11-22 06:58:30 +02:00
Github Actions b537dcf3f4 [CI Skip] release/beta 4.3.2-0
skip-checks: true
2021-11-21 05:54:49 +00:00
Jaco eaf8ecf2c1 Add hmacSha{256, 512} functions (#233)
* Add hmacSha{256, 512} functions

* type

* Adjust

* Apply suggestions from code review

* Update packages/wasm-crypto/src/rs/hashing.rs

* Update packages/wasm-crypto/src/rs/hashing.rs

* Update packages/wasm-crypto/src/rs/hashing.rs

* Fix Rust side

* naming for wasm interfaces

* Remove type

* Bump common
2021-11-21 07:49:53 +02:00
Github Actions 9f232459d9 [CI Skip] release/stable 4.3.1
skip-checks: true
2021-11-19 13:14:30 +00:00
Jaco b92661cfe0 4.3.1 (#232) 2021-11-19 15:08:46 +02:00
Github Actions 6ca4470752 [CI Skip] release/beta 4.2.2-17
skip-checks: true
2021-11-19 12:34:40 +00:00
Jaco 6cecb67edd keccak512 & sha256 (#231)
* keccak512 & sha256

* Update interface

* Correct test
2021-11-19 14:28:44 +02:00
Github Actions 91388ca10d [CI Skip] release/beta 4.2.2-16
skip-checks: true
2021-11-18 08:28:57 +00:00
Jaco 11e2acbdb5 Bump deps (#230) 2021-11-18 10:24:03 +02:00
Github Actions 4e3d1b631c [CI Skip] release/beta 4.2.2-15
skip-checks: true
2021-11-12 07:39:59 +00:00
Jaco 4f06de4844 Bump deps (#229) 2021-11-12 09:34:30 +02:00
Github Actions affb3c57e3 [CI Skip] release/beta 4.2.2-14
skip-checks: true
2021-11-07 10:44:51 +00:00
Jaco 39e762a419 Bump @polkadot deps (#227) 2021-11-07 12:38:53 +02:00
Github Actions fe966c8576 [CI Skip] release/beta 4.2.2-13
skip-checks: true
2021-11-06 11:42:08 +00:00
Jaco 12c90dfb53 Bump deps (#226) 2021-11-06 13:37:22 +02:00
Github Actions 03aabfd6d1 [CI Skip] release/beta 4.2.2-12
skip-checks: true
2021-11-03 12:50:00 +00:00
Jaco 49b3cf552b Bump dev (#225) 2021-11-03 14:45:06 +02:00
Github Actions 6300012c32 [CI Skip] release/beta 4.2.2-11
skip-checks: true
2021-10-26 07:25:50 +00:00
Jaco 9d0773c185 Bump dev (#224) 2021-10-26 10:20:33 +03:00
Github Actions 96bd2f466e [CI Skip] release/beta 4.2.2-10
skip-checks: true
2021-10-25 13:28:49 +00:00
Jaco c6151e1a7d Bump dev deps (#223) 2021-10-25 16:22:19 +03:00
Github Actions c0c6671bd0 [CI Skip] release/beta 4.2.2-9
skip-checks: true
2021-10-25 11:38:15 +00:00
Jaco 2b9d90ff49 Bump dev (#222) 2021-10-25 14:32:37 +03:00
Github Actions 2caa6fb41a [CI Skip] release/beta 4.2.2-8
skip-checks: true
2021-10-25 09:13:13 +00:00
Jaco df00473ae2 Adjust package.json consistency (#221)
* Adjust package.json consistency

* Bump deps
2021-10-25 12:08:38 +03:00
Github Actions 2acce9283f [CI Skip] release/beta 4.2.2-7
skip-checks: true
2021-10-25 08:52:12 +00:00
Zhongpeng Zhouandmsftenanceprovenance 7971624cf9 Update package.json to include the repository (#220)
* Update package.json to include the repository

Hi there!
This change adds the repository property to your package.json file(s). Having this available provides a number of benefits to security tooling. For example, it allows for greater trust by checking for signed commits, contributors to a release and validating history with the project. It also allows for comparison between the source code and the published artifact in order to detect attacks on authors during the publication process.
We validate that we're making a PR against the correct repository by comparing the metadata for the published artifact on [npmjs.com](www.npmjs.com) against the metadata in the package.json file in the repository.
This change is provided by a team at Microsoft -- we're happy to answer any questions you may have. (Members of this team include [@s-tuli](https://github.com/s-tuli), [@iarna](https://github.com/iarna), [@v-rr](https://github.com/v-rr), [@v-jiepeng](https://github.com/v-jiepeng), [@v-zhzhou](https://github.com/v-zhzhou) and [@v-gjy](https://github.com/v-gjy)). If you would prefer that we not make these sorts of PRs to projects you maintain, please just say. If you'd like to learn more about what we're doing here, we've prepared a document talking about both this project and some of our other activities around supply chain security here: [microsoft/Secure-Supply-Chain](https://github.com/microsoft/Secure-Supply-Chain)
This PR provides repository metadata for the following packages:
* @polkadot/wasm-crypto
* @polkadot/wasm-crypto-asmjs
* @polkadot/wasm-crypto-wasm

* update

* update

Co-authored-by: msftenanceprovenance <msftenanceprovenance@microsoft.com>
2021-10-25 11:45:36 +03:00
Github Actions e353fe7f2c [CI Skip] release/beta 4.2.2-6
skip-checks: true
2021-10-17 09:37:46 +00:00
Jaco e797e7a7e4 Bump dev (#219)
* Bump dev

* Bump
2021-10-17 12:32:50 +03:00
Github Actions cb91f766c7 [CI Skip] release/beta 4.2.2-5
skip-checks: true
2021-10-16 06:46:50 +00:00
Jaco c983de54f6 Bump deps (#218) 2021-10-16 09:40:31 +03:00
Github Actions 9d9b983694 [CI Skip] release/beta 4.2.2-4
skip-checks: true
2021-09-27 05:45:44 +00:00
Jaco 6db930d03d Bump deps (#217) 2021-09-27 07:39:52 +02:00
Github Actions 0233a868ab [CI Skip] release/beta 4.2.2-3
skip-checks: true
2021-09-20 08:39:48 +00:00
Jaco ed98d4820e Bump util (#216) 2021-09-20 10:33:18 +02:00
Github Actions 971d40ba18 [CI Skip] release/beta 4.2.2-2
skip-checks: true
2021-09-14 11:29:28 +00:00
Jaco f3e1e30838 Bump deps (#215) 2021-09-14 13:24:17 +02:00
Github Actions bff8604c8a [CI Skip] release/beta 4.2.2-1
skip-checks: true
2021-09-05 08:28:45 +00:00
Jaco 6cf4fc0989 Bump deps (#214) 2021-09-05 10:22:39 +02:00
Github Actions 308374c7da [CI Skip] release/beta 4.2.2-0
skip-checks: true
2021-09-01 16:49:58 +00:00
Jaco 06bb7ae090 Jest config cleanup (#213)
* Jest config cleanup

* Bump
2021-09-01 18:43:16 +02:00
Github Actions b236d50c3c [CI Skip] release/stable 4.2.1
skip-checks: true
2021-08-28 05:30:23 +00:00
Jaco e2ac301993 4.2.1 (#212) 2021-08-28 07:24:12 +02:00
Github Actions d6bdcaccd7 [CI Skip] release/beta 4.1.3-7
skip-checks: true
2021-08-26 07:36:51 +00:00
Jaco Greeff a7f0e68443 Bump deps 2021-08-26 10:31:04 +03:00
Github Actions dc24ab5804 [CI Skip] release/beta 4.1.3-6
skip-checks: true
2021-08-25 10:01:34 +00:00
Jaco d5512418d2 Use stable as nightly compiler (#192)
* Use stable as nightly compiler

* detect stable

* Apply suggestions from code review

* CHANGELOG

* De-dupe Rust version

* Adjust script location

* Script cleanups

* trigger

* Script location
2021-08-25 11:55:17 +02:00
Github Actions 7a8e570dfa [CI Skip] release/beta 4.1.3-5
skip-checks: true
2021-08-25 08:58:11 +00:00
Jaco 3794a30b4b Adjust JS tests (#211) 2021-08-25 10:53:04 +02:00
Github Actions 700acfe764 [CI Skip] release/beta 4.1.3-4
skip-checks: true
2021-08-24 11:07:21 +00:00
Shunfan ZhouandJaco 9b8d6e0b64 Support sr25519 agreement (#209)
* Support sr25519 ecdh agreement

* Align version of curve25519-dalek

Co-authored-by: Jaco <jacogr@gmail.com>

* Reduce code size

Co-authored-by: Jaco <jacogr@gmail.com>

* Add explicit tests on sr25519 key agreement

* Fix linting issues

* Fix sr25519 key_agreement test

Co-authored-by: Jaco <jacogr@gmail.com>
2021-08-24 13:00:54 +02:00
Github Actions 3575f57a2a [CI Skip] release/beta 4.1.3-3
skip-checks: true
2021-08-24 07:05:13 +00:00
Jaco 8838651405 Bump deps (#210) 2021-08-24 08:59:29 +02:00
Github Actions 6cb8f2254a [CI Skip] release/beta 4.1.3-2
skip-checks: true
2021-08-16 06:04:41 +00:00
Jaco 72c2a70a32 Bump deps (#208) 2021-08-16 07:58:49 +02:00
Github Actions 51b1d12aab [CI Skip] release/beta 4.1.3-1
skip-checks: true
2021-08-13 11:52:29 +00:00
Jaco Greeff 93159192bb berry 3.0.1 2021-08-13 14:46:26 +03:00
Github Actions d208694d05 [CI Skip] release/beta 4.1.3-0
skip-checks: true
2021-08-13 11:40:39 +00:00
Jaco e7cb8a4907 Bump deps (#207) 2021-08-13 13:35:19 +02:00
Github Actions 01dfe6e35c [CI Skip] release/stable 4.1.2
skip-checks: true
2021-07-09 05:54:46 +00:00
Jaco a5d4c4b43c 4.1.2 (#206) 2021-07-09 07:49:27 +02:00
Github Actions 9a5107534d [CI Skip] release/stable 4.1.1
skip-checks: true
2021-07-07 16:04:14 +00:00
Jaco d50d04318e 4.1 (#205) 2021-07-07 17:59:17 +02:00
Github Actions a0afa3cef6 [CI Skip] release/beta 4.0.3-35
skip-checks: true
2021-07-07 15:40:39 +00:00
Jaco cf20e027af Single module bundle via rollup (#203)
* Single module bundle via rollup

* Adjust naming

* Allow multiple bundles (consistency)

* Remove unused rollup plugins

* Update rollup.config.js

* preferConst

* Rollup with dev build

* Use createBundle

* Update rollup.config.mjs

* Add bundle entrypoint

* Bump dev

* Bump dev

* Remove x-* overrides
2021-07-07 17:34:32 +02:00
Github Actions b68ab94939 [CI Skip] release/beta 4.0.3-34
skip-checks: true
2021-07-06 11:16:52 +00:00
Jaco Greeff af94bc472d Bump dev 2021-07-06 14:11:15 +03:00
Github Actions 289b102b38 [CI Skip] release/beta 4.0.3-33
skip-checks: true
2021-07-06 07:13:57 +00:00
Jaco Greeff ba6cbc2247 Bump deps 2021-07-06 10:08:04 +03:00
Jaco Greeff 379b574b84 Bump dev 2021-07-06 09:56:08 +03:00
Github Actions f1c44a65b1 [CI Skip] release/beta 4.0.3-32
skip-checks: true
2021-07-06 05:52:17 +00:00
Jaco Greeff 7ddb5ebbe5 Bump dev 2021-07-06 08:46:29 +03:00
Github Actions afd2fe3228 [CI Skip] release/beta 4.0.3-31
skip-checks: true
2021-07-05 15:00:16 +00:00
Jaco 292197a3a2 Bump dev (#204) 2021-07-05 16:54:53 +02:00
Github Actions 8fac7feabd [CI Skip] release/beta 4.0.3-30
skip-checks: true
2021-07-02 07:12:59 +00:00
Jaco ca69955332 Bump TS (#202) 2021-07-02 09:08:21 +02:00
Github Actions eacb24a133 [CI Skip] release/beta 4.0.3-29
skip-checks: true
2021-06-27 08:19:12 +00:00
Jaco 21b3dbbb94 Bump deps (#201) 2021-06-27 10:14:23 +02:00
Github Actions 57ff683121 [CI Skip] release/beta 4.0.3-28
skip-checks: true
2021-06-22 13:51:08 +00:00
Jaco 8b7e35ad0b Bump deps (#200) 2021-06-22 15:45:31 +02:00
Github Actions 0732f053b8 [CI Skip] release/beta 4.0.3-27
skip-checks: true
2021-06-08 15:09:51 +00:00
Jaco 831a72b519 Prettier ignore all (#199)
* Prettier ignore all

* Add scripts
2021-06-08 17:04:07 +02:00
Github Actions a5dad40521 [CI Skip] release/beta 4.0.3-26
skip-checks: true
2021-06-07 14:05:43 +00:00
Jaco Greeff e8263b2597 Adjust cron locks 2021-06-07 16:59:58 +03:00
Github Actions 9d6c0afc8e [CI Skip] release/beta 4.0.3-25
skip-checks: true
2021-06-06 19:30:29 +00:00
Jaco Greeff 6393d078e8 Adjust semgrep check 2021-06-06 22:25:08 +03:00
Github Actions c62f6493d9 [CI Skip] release/beta 4.0.3-24
skip-checks: true
2021-06-05 11:13:51 +00:00
Jaco Greeff e8737c403e No semgrep.yml on forks 2021-06-05 14:07:33 +03:00
Github Actions f279a89dc7 [CI Skip] release/beta 4.0.3-23
skip-checks: true
2021-06-05 06:43:12 +00:00
Jaco Greeff 30463cfe75 push-master.yml adjust skip 2021-06-05 09:38:11 +03:00
Github Actions c1405bbe2e [CI Skip] release/beta 4.0.3-22
skip-checks: true
2021-06-05 06:28:05 +00:00
Jaco 7d9dafd9e1 semgrep.yml on PR (#198)
* semgrep.yml on PR

* if

* if adjust

* if test

* Check
2021-06-05 08:22:35 +02:00
Github Actions e0e3634714 [CI Skip] release/beta 4.0.3-21
skip-checks: true
2021-06-04 14:38:13 +00:00
Jaco Greeff a5818af5fe Update semgrep.yml 2021-06-04 17:32:21 +03:00
Github Actions 6ebec52ffc [CI Skip] release/beta 4.0.3-20
skip-checks: true
2021-06-04 10:50:23 +00:00
Jaco Greeff ebd96dea49 semgrep skip 2021-06-04 13:44:52 +03:00
Github Actions d692383d80 [CI Skip] release/beta 4.0.3-19
skip-checks: true
2021-06-04 08:44:52 +00:00
Jaco Greeff cefc8c97ec semgrep on master only 2021-06-04 11:38:32 +03:00
Github Actions 8ce18ff065 [CI Skip] release/beta 4.0.3-18
skip-checks: true
2021-06-04 05:41:43 +00:00
Jaco Greeff 40a97d2206 semgrep only for non-forked 2021-06-04 08:35:56 +03:00
Github Actions e111d9e91d [CI Skip] release/beta 4.0.3-17
skip-checks: true
2021-06-02 16:09:06 +00:00
Jaco Greeff faf407d62d fix stale.yml 2021-06-02 19:03:33 +03:00
Github Actions cf5759a324 [CI Skip] release/beta 4.0.3-16
skip-checks: true
2021-06-02 07:11:39 +00:00
Jaco Greeff d220a69ab1 cron workflows 2021-06-02 10:05:48 +03:00
Github Actions 4d8dde58dc [CI Skip] release/beta 4.0.3-15
skip-checks: true
2021-06-01 10:04:28 +00:00
Jaco Greeff c5b98fcd5b semgrep.yml 2021-06-01 12:58:33 +03:00
Github Actions 482576be81 [CI Skip] release/beta 4.0.3-14
skip-checks: true
2021-06-01 06:08:44 +00:00
Jaco Greeff fdea2aa4dc cron daily only 2021-06-01 09:03:50 +03:00
Github Actions e4dbdc570d [CI Skip] release/beta 4.0.3-13
skip-checks: true
2021-05-31 20:21:54 +00:00
Jaco Greeff 7f3146ce64 cron locks 2021-05-31 23:15:39 +03:00
Github Actions 1bf001b2f3 [CI Skip] release/beta 4.0.3-12
skip-checks: true
2021-05-31 07:55:52 +00:00
Jaco 2a99496e9a Update .123trigger 2021-05-31 09:49:34 +02:00
Github Actions 59ba89a032 [CI Skip] release/beta 4.0.3-11
skip-checks: true
2021-05-31 07:48:52 +00:00
Jaco Greeff be9786fc4c Bump dev 2021-05-31 10:42:50 +03:00
Jaco 629140e6c3 Bump dev (#197) 2021-05-31 09:15:12 +02:00
Jaco Greeff 5f46f9e698 lock.yml 2021-05-30 22:22:16 +03:00
Github Actions d4daf14c77 [CI Skip] release/beta 4.0.3-11
skip-checks: true
2021-05-30 09:38:55 +00:00
Jaco cfdaab8f86 Bump berry (#196)
* Bump berry

* Bumps
2021-05-30 11:33:41 +02:00
Github Actions 70ca570a66 [CI Skip] release/beta 4.0.3-10
skip-checks: true
2021-05-29 08:24:22 +00:00
Jaco Greeff ab7e12a30d Update stale.yml 2021-05-29 11:18:37 +03:00
Github Actions 87a95b9ab2 [CI Skip] release/beta 4.0.3-9
skip-checks: true
2021-05-28 08:45:18 +00:00
Jaco Greeff 9aff03c5b6 Update stale.yml 2021-05-28 11:39:36 +03:00
Github Actions adfa4fb099 [CI Skip] release/beta 4.0.3-8
skip-checks: true
2021-05-28 08:11:42 +00:00
Jaco 5e8b3c1c24 Add stale.yml (#195) 2021-05-28 10:06:59 +02:00
Github Actions 714b9ebf48 [CI Skip] release/beta 4.0.3-7
skip-checks: true
2021-05-28 06:45:01 +00:00
Jaco c93dbd2d2e Apply lgtm alert fixes (#194) 2021-05-28 08:40:18 +02:00
Github Actions 7139f1fe42 [CI Skip] release/beta 4.0.3-6
skip-checks: true
2021-05-26 20:20:07 +00:00
Jaco 7e490f1f96 Bump deps (#193) 2021-05-26 22:15:16 +02:00
Github Actions b6aa432b26 [CI Skip] release/beta 4.0.3-5
skip-checks: true
2021-05-07 05:26:26 +00:00
Jaco 547e31ffef Bump dev (#191) 2021-05-07 07:20:53 +02:00
Github Actions 092ee15603 [CI Skip] release/beta 4.0.3-4
skip-checks: true
2021-04-30 05:55:01 +00:00
Jaco dd52d5158e Bump deps (#190) 2021-04-30 07:47:21 +02:00
Github Actions 88d8f79e3c [CI Skip] release/beta 4.0.3-3
skip-checks: true
2021-04-24 07:39:11 +00:00
Jaco 3a1a75f99f Add engines field to package.json (#189) 2021-04-24 09:32:52 +02:00
Github Actions 422c23dbbd [CI Skip] release/beta 4.0.3-2
skip-checks: true
2021-04-21 07:20:11 +00:00
Jaco 13fd02d455 Bump deps (#188) 2021-04-21 09:13:36 +02:00
Github Actions b75e2e4778 [CI Skip] release/beta 4.0.3-1
skip-checks: true
2021-04-08 08:22:23 +00:00
Jaco Greeff 43222700be Bump deps (#187) 2021-04-08 10:16:07 +02:00
Github Actions 05abb02b64 [CI Skip] release/beta 4.0.3-0
skip-checks: true
2021-03-08 15:27:35 +00:00
Jaco Greeff bf1590ab70 Bump TS (#186) 2021-03-08 16:21:16 +01:00
Github Actions f9b5b9f55f [CI Skip] release/stable 4.0.2
skip-checks: true
2021-03-05 22:01:17 +00:00
Jaco Greeff 25d9e21b38 Adjust esm -> cjs imports (4.0.2) (#185)
* Adjust esm -> cjs impors

* cleanups

* CHANGELOG

* Apply suggestions from code review

* Apply suggestions from code review

* Apply suggestions from code review

* Update packages/wasm-crypto-wasm/src/empty.ts

* Apply suggestions from code review

* Update packages/wasm-crypto-wasm/src/cjs/bytes.d.ts
2021-03-05 22:55:19 +01:00
Github Actions 77641fc43d [CI Skip] release/stable 4.0.1
skip-checks: true
2021-03-04 18:04:12 +00:00
Jaco Greeff 90865fe9c1 4.0 (#184) 2021-03-04 18:56:54 +01:00
Github Actions 15fbfc3c51 [CI Skip] release/beta 4.0.1-7
skip-checks: true
2021-03-04 17:27:21 +00:00
Jaco Greeff 340b6a0cd6 packageInfo exports (#183) 2021-03-04 18:21:00 +01:00
Github Actions 064e13268a [CI Skip] release/beta 4.0.1-6
skip-checks: true
2021-03-04 17:06:29 +00:00
Jaco Greeff 641ea0f9d8 Small cleanups (#182)
* Small cleanups

* Detect wasm-crypt-* alongside detectPackage

* Adjust alias imports

* Adjust

* Adjust
2021-03-04 17:59:38 +01:00
Github Actions 98bc7147e3 [CI Skip] release/beta 4.0.1-5
skip-checks: true
2021-03-03 07:55:20 +00:00
Jaco Greeff 3d9e5d49b8 Bump TS 2021-03-03 08:48:38 +01:00
Github Actions 8bdcfbb049 [CI Skip] release/beta 4.0.1-4
skip-checks: true
2021-03-03 07:39:46 +00:00
Jaco Greeff 13dcd606ea Bump deps (& berry) (#181) 2021-03-03 08:33:29 +01:00
Github Actions 6576688f92 [CI Skip] release/beta 4.0.1-3
skip-checks: true
2021-03-02 17:03:46 +00:00
Jaco Greeff 33e63df4ad reset 2021-03-02 17:40:53 +01:00
Jaco Greeff e910e9fc77 Revert "[CI Skip] release/stable 4.0.0"
This reverts commit a00b36d50d.
2021-03-02 17:39:54 +01:00
Github Actions a00b36d50d [CI Skip] release/stable 4.0.0
skip-checks: true
2021-03-02 16:34:29 +00:00
Jaco Greeff 0f6e143a6f Default build to type: module (#180)
* Defaul build to type: module

* Add packageInfo

* 4.0

* pre

* Adjust tests

* jest js, rest cjs

* Bump dev
2021-03-02 17:27:41 +01:00
Github Actions 854d209be8 [CI Skip] release/beta 3.2.5-0
skip-checks: true
2021-03-01 20:33:12 +00:00
Jaco Greeff 3f50efb951 Bump deps (#179) 2021-03-01 21:27:10 +01:00
Github Actions aceaa90466 [CI Skip] release/stable 3.2.4
skip-checks: true
2021-02-24 16:14:52 +00:00
Jaco Greeff 63622edcf4 Cleanup implicit dependencies, perform base64 decoding using base64-js (#178)
* Cleanup implicit dependencies, perform base64 decoding using base64-js

* base64 decoding

* lint

* remove extra call

* adjust
2021-02-24 17:09:06 +01:00
Github Actions 4a1c0563cb [CI Skip] release/stable 3.2.3
skip-checks: true
2021-02-16 10:55:04 +00:00
Jaco Greeff b34181f104 3.2.3 (#176) 2021-02-16 11:48:28 +01:00
Github Actions 141a067b85 [CI Skip] release/stable 3.2.2
skip-checks: true
2021-01-24 11:00:54 +00:00
Jaco Greeff 4c48d91f8e 3.2.2 (#175) 2021-01-24 11:55:09 +01:00
Github Actions 9158d7c066 [CI Skip] release/stable 3.2.1
skip-checks: true
2021-01-22 08:49:35 +00:00
Jaco Greeff 135affe3e3 3.2 (#174) 2021-01-22 09:44:18 +01:00
Github Actions 1460ce9301 [CI Skip] release/beta 3.1.2-6
skip-checks: true
2021-01-21 12:04:54 +00:00
Jaco Greeff 8510120701 Bumps (#173)
* Bumps

* Update fflate imports
2021-01-21 12:59:06 +01:00
Github Actions 1e5b33413f [CI Skip] release/beta 3.1.2-5
skip-checks: true
2021-01-21 11:34:19 +00:00
Jaco Greeff 16d1b28f77 Cleanups (#172) 2021-01-21 12:28:11 +01:00
Github Actions 33a54be279 [CI Skip] release/beta 3.1.2-4
skip-checks: true
2021-01-20 11:13:40 +00:00
Jaco Greeff e6bc31ac5d Adjust vrf_{sign, verify} with one variant (#171) 2021-01-20 12:08:27 +01:00
Github Actions a7f8342458 [CI Skip] release/beta 3.1.2-3
skip-checks: true
2021-01-17 15:22:02 +00:00
Steve DegosserieandGithub Actions b1752ad001 Expose Schnorrkel's VRF capabilities (#170)
* Expose vrf_sign_extra function from Schnorrkel

* Document function, code cleanup

* Added vrf_sign, vrf_verify, vrf_verify_extra functions.

* Expose VRF functions to js

Co-authored-by: Github Actions <action@github.com>
2021-01-17 16:16:14 +01:00
Github Actions 28e3f6018d [CI Skip] release/beta 3.1.2-2
skip-checks: true
2021-01-03 10:25:39 +00:00
Jaco Greeff 1bb6db86f7 2021 (#167) 2021-01-03 11:20:26 +01:00
Github Actions 571cdabc78 [CI Skip] release/beta 3.1.2-1
skip-checks: true
2021-01-02 16:58:01 +00:00
Jaco Greeff 11c6315409 Bump dev/util deps (#166)
* Bump dev/util deps

* Move dev-only deps
2021-01-02 17:51:35 +01:00
Github Actions 3a1740a5a2 [CI Skip] release/beta 3.1.2-0
skip-checks: true
2020-12-22 09:20:51 +00:00
Jaco Greeff c725e8ee03 Bump deps (#165)
* Bump deps

* rewrite
2020-12-22 10:15:44 +01:00
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
94 changed files with 7022 additions and 5429 deletions
+6 -1
View File
@@ -1 +1,6 @@
4
6
3.2.2
3.2.3
3.2.4
4.0.2
4.1.2
+1
View File
@@ -2,3 +2,4 @@ exclude_patterns:
- "**/*.spec.js"
- "**/*.spec.ts"
- "docs/**/*.js"
- "**/test/**/*.js"
+5 -3
View File
@@ -1,7 +1,7 @@
// Copyright 2019-2020 @polkadot/wasm-crypto authors & contributors
// Copyright 2019-2021 @polkadot/wasm-crypto authors & contributors
// SPDX-License-Identifier: Apache-2.0
const base = require('@polkadot/dev/config/eslint');
const base = require('@polkadot/dev/config/eslint.cjs');
module.exports = {
...base,
@@ -13,7 +13,9 @@ module.exports = {
'**/binaryen/*',
'**/build/*',
'**/coverage/*',
'**/node_modules/*'
'**/node_modules/*',
'**/pkg/*',
'**/target/*'
],
parserOptions: {
...base.parserOptions,
+23
View File
@@ -0,0 +1,23 @@
name: 'Lock Threads'
on:
schedule:
- cron: '20 1/3 * * *'
jobs:
lock:
runs-on: ubuntu-latest
steps:
- uses: dessant/lock-threads@v2
with:
github-token: ${{ secrets.GH_PAT_BOT }}
issue-lock-inactive-days: '7'
issue-lock-comment: >
This thread has been automatically locked since there has not been
any recent activity after it was closed. Please open a new issue
if you think you have a related problem or query.
pr-lock-inactive-days: '2'
pr-lock-comment: >
This pull request has been automatically locked since there
has not been any recent activity after it was closed.
Please open a new issue for related bugs.
+1 -8
View File
@@ -6,11 +6,11 @@ on:
jobs:
master:
if: "! startsWith(github.event.head_commit.message, '[CI Skip]')"
strategy:
matrix:
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@v2
@@ -26,10 +26,3 @@ jobs:
yarn install --immutable | grep -v 'YN0013'
./scripts/install-build-deps.sh
yarn ${{ matrix.step }}
dummy:
runs-on: ubuntu-latest
steps:
- name: dummy
run: |
echo "Dummy skip step"
+18
View File
@@ -0,0 +1,18 @@
name: Semgrep
on:
pull_request: {}
push:
branches:
- master
jobs:
check:
if: "! startsWith(github.event.head_commit.message, '[CI Skip]') && (!github.event.pull_request || github.event.pull_request.head.repo.full_name == github.repository)"
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: returntocorp/semgrep-action@v1
with:
auditOn: push
publishToken: ${{ secrets.SEMGREP_APP_TOKEN }}
publishDeployment: 1395
+17
View File
@@ -0,0 +1,17 @@
name: 'Close stale issues and PRs'
on:
schedule:
- cron: '35 1/3 * * *'
jobs:
stale:
runs-on: ubuntu-latest
steps:
- uses: actions/stale@v3
with:
repo-token: ${{ secrets.GH_PAT_BOT }}
stale-issue-message: 'This issue has been open for 21 days with no activity and is not labelled as an enhancement. It will be closed in 7 days.'
stale-issue-label: 'stale'
exempt-issue-labels: '-size-l,-size-m,-size-s,-size-xl,-size-xs,[bug]'
days-before-stale: 21
days-before-close: 7
+1
View File
@@ -2,6 +2,7 @@ binaryen/
bindgen/
build/
build-docs/
bytes/
coverage/
docs/.vuepress/dist/
node_modules/
-1
View File
@@ -1 +0,0 @@
12
+4
View File
@@ -0,0 +1,4 @@
build
coverage
packages
scripts
+4
View File
@@ -0,0 +1,4 @@
// Copyright 2017-2021 @polkadot/dev authors & contributors
// SPDX-License-Identifier: Apache-2.0
module.exports = require('@polkadot/dev/config/prettier.cjs');
File diff suppressed because one or more lines are too long
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
+631
View File
File diff suppressed because one or more lines are too long
+1 -3
View File
@@ -9,7 +9,5 @@ plugins:
spec: "@yarnpkg/plugin-interactive-tools"
- path: .yarn/plugins/@yarnpkg/plugin-version.cjs
spec: "@yarnpkg/plugin-version"
- path: .yarn/plugins/@yarnpkg/plugin-workspace-tools.cjs
spec: "@yarnpkg/plugin-workspace-tools"
yarnPath: .yarn/releases/yarn-2.3.3.cjs
yarnPath: .yarn/releases/yarn-3.0.1.cjs
+127
View File
@@ -1,5 +1,132 @@
# CHANGELOG
## 4.5.1 Dec 3, 2021
Changes:
- Add `secp256k1{Compress, Expand, Recover, Sign}` functions
- Remove all occurences of `.unwrap()` (match everywhere)
- Adjust and optimize WASM function JS interface construction
- Simplify base64 bytes decoding on construction
## 4.4.1 Nov 22, 2021
Changes:
- Add `hmacSha256` & `hmacSha512` functions
## 4.3.1 Nov 19, 2021
Contributed:
- Updated package.json to include repo (Thanks to https://github.com/v-zhzhou)
Changes:
- Add `keccak512` function
- Add `sha256` function
## 4.2.1 Aug 28, 2021
Contributed:
- Add sr25519 agreement external (Thanks to https://github.com/shelvenzhou)
Changes:
- Adjust tests to align with JS coding standards
- Allow for optional build with Rust stable bootstrap
## 4.1.2 Jul 9, 2021
Changes:
- Bump `@polkadot/dev` to allow for bundles with new-format
## 4.1.1 Jul 7, 2021
Changes:
- Add an explicit `engines` field to `package.json`
- Allow building as a completely stand-alone browser bundle (experimental)
## 4.0.2 Mar 5, 2021
Changes:
- Add import indirection for both CJS & ESM (where generated source file is commonjs)
## 4.0.1 Mar 4, 2021
**Important** In the 4.0 version the default package type has been changed to ESM modules by default. This should not affect usage, however since the output formats changed, a new major version is required.
Changes:
- Build to ESM by default (with cjs versions via export map)
## 3.2.4 Feb 24, 2021
Changes:
- Cleanup implicit dependencies, perform base64 decoding using base64-js
## 3.2.3 Feb 16, 2021
Changes:
- Change package detect import to use `.js` source, not `.json`
## 3.2.2 Jan 24, 2021
Changes:
- Remove `module` field in `package.json`
## 3.2.1 Jan 22, 2021
Contributed:
- Expose sr25519 `ext_vrf_{sign, verify}` methods (Thanks to https://github.com/stiiifff)
Changes:
- Add explicit `.editorconfig` for Rust sources
- Remove unused code bundles (`vrf_{sign,verify}_extra`, `secp256k1` with tests)
- Test run wrapper cleanups
## 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:
+4
View File
@@ -0,0 +1,4 @@
// Copyright 2019-2021 @polkadot/wasm-crypto authors & contributors
// SPDX-License-Identifier: Apache-2.0
module.exports = require('@polkadot/dev/config/babel-config-cjs.cjs');
-4
View File
@@ -1,4 +0,0 @@
// Copyright 2019-2020 @polkadot/wasm-crypto authors & contributors
// SPDX-License-Identifier: Apache-2.0
module.exports = require('@polkadot/dev/config/babel');
+13
View File
@@ -0,0 +1,13 @@
// Copyright 2019-2021 @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-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'
}
});
-14
View File
@@ -1,14 +0,0 @@
// Copyright 2019-2020 @polkadot/wasm-crypto authors & contributors
// SPDX-License-Identifier: Apache-2.0
const config = require('@polkadot/dev/config/jest');
module.exports = Object.assign({}, config, {
moduleNameMapper: {
'@polkadot/wasm-(crypto)(.*)$': '<rootDir>/packages/wasm-$1/src/$2'
},
modulePathIgnorePatterns: [
'<rootDir>/packages/wasm-crypto/build'
],
resolver: '@polkadot/dev/config/jest-resolver'
});
+19 -9
View File
@@ -1,30 +1,40 @@
{
"repository": "https://github.com/polkadot-js/wasm",
"author": "Jaco Greeff <jacogr@gmail.com>",
"bugs": "https://github.com/polkadot-js/wasm/issues",
"homepage": "https://github.com/polkadot-js/wasm#readme",
"license": "Apache-2",
"packageManager": "yarn@3.0.1",
"private": true,
"repository": {
"type": "git",
"url": "https://github.com/polkadot-js/wasm.git"
},
"sideEffects": false,
"version": "4.5.1",
"workspaces": [
"packages/*"
],
"resolutions": {
"typescript": "^4.0.5"
},
"scripts": {
"build": "yarn build:wasm",
"build:release": "polkadot-ci-ghact-build",
"build:rollup": "polkadot-exec-rollup --config",
"build:wasm": "./scripts/build.sh",
"lint": "polkadot-dev-run-lint",
"clean": "./scripts/clean.sh",
"lint": "polkadot-dev-run-lint",
"postinstall": "polkadot-dev-yarn-only",
"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:js:node": "cd packages/wasm-crypto && node ./test/wasm.cjs && node ./test/asm.cjs",
"test:wasm:rust": "cd packages/wasm-crypto && RUST_BACKTRACE=full cargo test --release -- --nocapture"
},
"devDependencies": {
"@babel/core": "^7.12.3",
"@polkadot/dev": "^0.59.19"
"@babel/core": "^7.16.0",
"@polkadot/dev": "^0.63.35",
"fflate": "^0.7.1",
"override-require": "^1.1.1"
},
"version": "2.0.1"
"resolutions": {
"typescript": "^4.5.2"
}
}
+27
View File
@@ -0,0 +1,27 @@
{
"author": "Jaco Greeff <jacogr@gmail.com>",
"bugs": "https://github.com/polkadot-js/wasm/issues",
"contributors": [],
"description": "Asm.js content for wasm-crypto",
"engines": {
"node": ">=14.0.0"
},
"homepage": "https://github.com/polkadot-js/wasm/tree/master/packages/wasm-crypto-asmjs#readme",
"license": "Apache-2.0",
"maintainers": [],
"name": "@polkadot/wasm-crypto-asmjs",
"repository": {
"directory": "packages/wasm-crypto-asmjs",
"type": "git",
"url": "https://github.com/polkadot-js/wasm.git"
},
"sideEffects": false,
"type": "module",
"version": "4.5.1",
"browser": "empty.js",
"main": "empty.js",
"react-native": "data.js",
"dependencies": {
"@babel/runtime": "^7.16.3"
}
}
+4
View File
@@ -0,0 +1,4 @@
// Copyright 2019-2021 @polkadot/wasm-crypto-asmjs authors & contributors
// SPDX-License-Identifier: Apache-2.0
export declare const asmJsInit: null;
@@ -0,0 +1,6 @@
// Copyright 2019-2021 @polkadot/wasm-crypto-asmjs authors & contributors
// SPDX-License-Identifier: Apache-2.0
const asmJsInit = null;
exports.asmJsInit = asmJsInit;
@@ -0,0 +1,3 @@
{
"type": "commonjs"
}
+6
View File
@@ -0,0 +1,6 @@
// Copyright 2019-2021 @polkadot/wasm-crypto-asmjs authors & contributors
// SPDX-License-Identifier: Apache-2.0
import { asmJsInit as _asmJsInit } from './cjs/data.js';
export const asmJsInit = _asmJsInit;
+4
View File
@@ -0,0 +1,4 @@
// Copyright 2019-2021 @polkadot/wasm-crypto-asmjs authors & contributors
// SPDX-License-Identifier: Apache-2.0
export const asmJsInit = null;
@@ -0,0 +1,6 @@
// Copyright 2017-2021 @polkadot/wasm-crypto-asmjs authors & contributors
// SPDX-License-Identifier: Apache-2.0
// Auto-generated by @polkadot/dev, do not edit
export const packageInfo = { name: '@polkadot/wasm-crypto-asmjs', version: '4.5.1' };
+27
View File
@@ -0,0 +1,27 @@
{
"author": "Jaco Greeff <jacogr@gmail.com>",
"bugs": "https://github.com/polkadot-js/wasm/issues",
"contributors": [],
"description": "Wasm content for wasm-crypto",
"engines": {
"node": ">=14.0.0"
},
"homepage": "https://github.com/polkadot-js/wasm/tree/master/packages/wasm-crypto-wasm#readme",
"license": "Apache-2.0",
"maintainers": [],
"name": "@polkadot/wasm-crypto-wasm",
"repository": {
"directory": "packages/wasm-crypto-wasm",
"type": "git",
"url": "https://github.com/polkadot-js/wasm.git"
},
"sideEffects": false,
"type": "module",
"version": "4.5.1",
"browser": "data.js",
"main": "data.js",
"react-native": "data.js",
"dependencies": {
"@babel/runtime": "^7.16.3"
}
}
+22
View File
@@ -0,0 +1,22 @@
// Copyright 2019-2021 @polkadot/wasm-crypto authors & contributors
// SPDX-License-Identifier: Apache-2.0
const chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
export function base64Decode (data: string): Uint8Array {
const bytes = [];
let byte = 0;
let bits = 0;
for (let i = 0; i < data.length && data[i] !== '='; i++) {
// each character represents 6 bits
byte = (byte << 6) | chars.indexOf(data[i]);
// each byte needs to contain 8 bits
if ((bits += 6) >= 8) {
bytes.push((byte >>> (bits -= 8)) & 0xff);
}
}
return Uint8Array.from(bytes);
}
+10
View File
@@ -0,0 +1,10 @@
// Copyright 2019-2021 @polkadot/wasm-crypto-wasm authors & contributors
// SPDX-License-Identifier: Apache-2.0
import { bytes as _bytes, sizeCompressed as _sizeCompressed, sizeUncompressed as _sizeUncompressed } from './cjs/bytes';
export const bytes = _bytes;
export const sizeCompressed = _sizeCompressed;
export const sizeUncompressed = _sizeUncompressed;
+6
View File
@@ -0,0 +1,6 @@
// Copyright 2019-2021 @polkadot/wasm-crypto-wasm authors & contributors
// SPDX-License-Identifier: Apache-2.0
export declare const bytes = '';
export declare const sizeCompressed = 0;
export declare const sizeUncompressed = 0;
@@ -0,0 +1,8 @@
// Copyright 2019-2021 @polkadot/wasm-crypto-wasm authors & contributors
// SPDX-License-Identifier: Apache-2.0
exports.bytes = '';
exports.sizeCompressed = 0;
exports.sizeUncompressed = 0;
@@ -0,0 +1,3 @@
{
"type": "commonjs"
}
+8
View File
@@ -0,0 +1,8 @@
// Copyright 2019-2021 @polkadot/wasm-crypto-wasm authors & contributors
// SPDX-License-Identifier: Apache-2.0
import { base64Decode } from './base64';
import { bytes, sizeUncompressed } from './bytes';
import { unzlibSync } from './fflate';
export const wasmBytes = unzlibSync(base64Decode(bytes), new Uint8Array(sizeUncompressed));
+8
View File
@@ -0,0 +1,8 @@
// Copyright 2019-2021 @polkadot/wasm-crypto-wasm authors & contributors
// SPDX-License-Identifier: Apache-2.0
export const bytes = null;
export const sizeCompressed = 0;
export const sizeUncompressed = 0;
+342
View File
@@ -0,0 +1,342 @@
// Copyright 2019-2021 @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);
}
@@ -0,0 +1,6 @@
// Copyright 2017-2021 @polkadot/wasm-crypto-wasm authors & contributors
// SPDX-License-Identifier: Apache-2.0
// Auto-generated by @polkadot/dev, do not edit
export const packageInfo = { name: '@polkadot/wasm-crypto-wasm', version: '4.5.1' };
+274 -42
View File
@@ -1,5 +1,7 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 3
[[package]]
name = "addr2line"
version = "0.13.0"
@@ -43,13 +45,19 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "46254cf2fdcdf1badb5934448c1bcbe046a56537b3987d96c51a7afc5d03f293"
dependencies = [
"addr2line",
"cfg-if",
"cfg-if 0.1.10",
"libc",
"miniz_oxide",
"object",
"rustc-demangle",
]
[[package]]
name = "base64"
version = "0.13.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "904dfeac50f3cdaba28fc6f57fdcddb75f49ed61346676a78c4ffe55877802fd"
[[package]]
name = "bitflags"
version = "1.2.1"
@@ -75,7 +83,16 @@ dependencies = [
"block-padding",
"byte-tools",
"byteorder",
"generic-array",
"generic-array 0.12.3",
]
[[package]]
name = "block-buffer"
version = "0.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4152116fd6e9dadb291ae18fc1ec3575ed6d84c29642d97890f4b4a3417297e4"
dependencies = [
"generic-array 0.14.4",
]
[[package]]
@@ -111,6 +128,12 @@ version = "0.1.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822"
[[package]]
name = "cfg-if"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
[[package]]
name = "cloudabi"
version = "0.0.3"
@@ -126,6 +149,15 @@ version = "0.1.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "245097e9a4535ee1e3e3931fcfcd55a796a44c643e8596ff6566d68f09b87bbc"
[[package]]
name = "cpufeatures"
version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "95059428f66df56b63431fdb4e1947ed2190586af5c5a8a8b71122bdf5a7f469"
dependencies = [
"libc",
]
[[package]]
name = "crunchy"
version = "0.2.2"
@@ -138,10 +170,20 @@ version = "0.7.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4434400df11d95d556bac068ddfedd482915eb18fe8bea89bc80b6e4b1c179e5"
dependencies = [
"generic-array",
"generic-array 0.12.3",
"subtle 1.0.0",
]
[[package]]
name = "crypto-mac"
version = "0.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b584a330336237c1eecd3e94266efb216c56ed91225d634cb2991c5f3fd1aeab"
dependencies = [
"generic-array 0.14.4",
"subtle 2.2.3",
]
[[package]]
name = "curve25519-dalek"
version = "2.1.0"
@@ -149,8 +191,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5d85653f070353a16313d0046f173f70d1aadd5b42600a14de626f0dfb3473a5"
dependencies = [
"byteorder",
"digest",
"rand_core",
"digest 0.8.1",
"rand_core 0.5.1",
"subtle 2.2.3",
"zeroize",
]
@@ -161,7 +203,16 @@ version = "0.8.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f3d0c8c8752312f9713efd397ff63acb9f85585afbf179282e720e7704954dd5"
dependencies = [
"generic-array",
"generic-array 0.12.3",
]
[[package]]
name = "digest"
version = "0.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d3dd60d1080a57a05ab032377049e0591415d2b31afd7028356dbf3cc6dcb066"
dependencies = [
"generic-array 0.14.4",
]
[[package]]
@@ -181,9 +232,9 @@ checksum = "21a8a37f4e8b35af971e6db5e3897e7a6344caa3f92f6544f88125a1f5f0035a"
dependencies = [
"curve25519-dalek",
"ed25519",
"rand",
"rand 0.7.3",
"serde",
"sha2",
"sha2 0.8.2",
"zeroize",
]
@@ -224,15 +275,38 @@ dependencies = [
"typenum",
]
[[package]]
name = "generic-array"
version = "0.14.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "501466ecc8a30d1d3b7fc9229b122b2ce8ed6e9d9223f1138d4babb253e51817"
dependencies = [
"typenum",
"version_check",
]
[[package]]
name = "getrandom"
version = "0.1.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7abc8dd8451921606d809ba32e95b6111925cd2906060d2dcc29c070220503eb"
dependencies = [
"cfg-if",
"cfg-if 0.1.10",
"libc",
"wasi",
"wasi 0.9.0+wasi-snapshot-preview1",
"wasm-bindgen",
]
[[package]]
name = "getrandom"
version = "0.2.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7fcd999463524c52659517fe2cea98493cfe485d10565e7b0fb07dbba7ad2753"
dependencies = [
"cfg-if 1.0.0",
"js-sys",
"libc",
"wasi 0.10.2+wasi-snapshot-preview1",
"wasm-bindgen",
]
@@ -267,8 +341,38 @@ version = "0.7.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5dcb5e64cda4c23119ab41ba960d1e170a774c8e4b9d9e6a9bc18aabf5e59695"
dependencies = [
"crypto-mac",
"digest",
"crypto-mac 0.7.0",
"digest 0.8.1",
]
[[package]]
name = "hmac"
version = "0.8.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "126888268dcc288495a26bf004b38c5fdbb31682f992c84ceb046a1f0fe38840"
dependencies = [
"crypto-mac 0.8.0",
"digest 0.9.0",
]
[[package]]
name = "hmac-drbg"
version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "17ea0a1394df5b6574da6e0c1ade9e78868c9fb0a4e5ef4428e32da4676b85b1"
dependencies = [
"digest 0.9.0",
"generic-array 0.14.4",
"hmac 0.8.1",
]
[[package]]
name = "js-sys"
version = "0.3.42"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "52732a3d3ad72c58ad2dc70624f9c17b46ecd0943b9a4f1ee37c4c18c5d983e2"
dependencies = [
"wasm-bindgen",
]
[[package]]
@@ -285,9 +389,58 @@ checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
[[package]]
name = "libc"
version = "0.2.74"
version = "0.2.108"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a2f02823cf78b754822df5f7f268fb59822e7296276d3e069d8e8cb26a14bd10"
checksum = "8521a1b57e76b1ec69af7599e75e38e7b7fad6610f037db8c79b127201b5d119"
[[package]]
name = "libsecp256k1"
version = "0.7.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b0452aac8bab02242429380e9b2f94ea20cea2b37e2c1777a1358799bbe97f37"
dependencies = [
"arrayref",
"base64",
"digest 0.9.0",
"hmac-drbg",
"lazy_static",
"libsecp256k1-core",
"libsecp256k1-gen-ecmult",
"libsecp256k1-gen-genmult",
"rand 0.8.4",
"serde",
"sha2 0.9.8",
"typenum",
]
[[package]]
name = "libsecp256k1-core"
version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5be9b9bb642d8522a44d533eab56c16c738301965504753b03ad1de3425d5451"
dependencies = [
"crunchy",
"digest 0.9.0",
"subtle 2.2.3",
]
[[package]]
name = "libsecp256k1-gen-ecmult"
version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3038c808c55c87e8a172643a7d87187fc6c4174468159cb3090659d55bcb4809"
dependencies = [
"libsecp256k1-core",
]
[[package]]
name = "libsecp256k1-gen-genmult"
version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3db8d6ba2cec9eacc40e6e8ccc98931840301f1006e95647ceb2dd5c3aa06f7c"
dependencies = [
"libsecp256k1-core",
]
[[package]]
name = "lock_api"
@@ -304,7 +457,7 @@ version = "0.4.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4fabed175da42fed1fa0746b0ea71f412aa9d35e76e95e59b192c64b9dc2bf8b"
dependencies = [
"cfg-if",
"cfg-if 0.1.10",
]
[[package]]
@@ -321,7 +474,7 @@ checksum = "c6feca46f4fa3443a01769d768727f10c10a20fdb65e52dc16a81f0c8269bb78"
dependencies = [
"byteorder",
"keccak",
"rand_core",
"rand_core 0.5.1",
"zeroize",
]
@@ -361,6 +514,12 @@ version = "0.2.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2839e79665f131bdb5782e51f2c6c9599c133c6098982a54c794358bf432529c"
[[package]]
name = "opaque-debug"
version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "624a8340c38c1b80fd549087862da4ba43e08858af025b236e509b6649fc13d5"
[[package]]
name = "parking_lot"
version = "0.10.2"
@@ -377,7 +536,7 @@ version = "0.7.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d58c7c768d4ba344e3e8d72518ac13e259d7c7ade24167003b8488e10b6740a3"
dependencies = [
"cfg-if",
"cfg-if 0.1.10",
"cloudabi",
"libc",
"redox_syscall",
@@ -392,7 +551,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "006c038a43a45995a9670da19e67600114740e8511d4333bf97a56e66a7542d9"
dependencies = [
"byteorder",
"crypto-mac",
"crypto-mac 0.7.0",
]
[[package]]
@@ -431,13 +590,24 @@ version = "0.7.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6a6b1679d49b24bbfe0c803429aa1874472f50d9b363131f0e89fc356b544d03"
dependencies = [
"getrandom",
"getrandom 0.1.14",
"libc",
"rand_chacha",
"rand_core",
"rand_chacha 0.2.2",
"rand_core 0.5.1",
"rand_hc",
]
[[package]]
name = "rand"
version = "0.8.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2e7573632e6454cf6b99d7aac4ccca54be06da05aca2ef7423d22d27d4d4bcd8"
dependencies = [
"libc",
"rand_chacha 0.3.1",
"rand_core 0.6.3",
]
[[package]]
name = "rand_chacha"
version = "0.2.2"
@@ -445,7 +615,17 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f4c8ed856279c9737206bf725bf36935d8666ead7aa69b52be55af369d193402"
dependencies = [
"ppv-lite86",
"rand_core",
"rand_core 0.5.1",
]
[[package]]
name = "rand_chacha"
version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88"
dependencies = [
"ppv-lite86",
"rand_core 0.6.3",
]
[[package]]
@@ -454,7 +634,16 @@ version = "0.5.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "90bde5296fc891b0cef12a6d03ddccc162ce7b2aff54160af9338f8d40df6d19"
dependencies = [
"getrandom",
"getrandom 0.1.14",
]
[[package]]
name = "rand_core"
version = "0.6.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d34f1408f55294453790c48b2f1ebbb1c5b4b7563eb1f418bcfcfdbb06ebb4e7"
dependencies = [
"getrandom 0.2.3",
]
[[package]]
@@ -463,7 +652,7 @@ version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ca3129af7b92a17112d59ad498c6f81eaf463253766b90396d39ea7a39d6613c"
dependencies = [
"rand_core",
"rand_core 0.5.1",
]
[[package]]
@@ -493,11 +682,11 @@ dependencies = [
"arrayref",
"arrayvec 0.5.1",
"curve25519-dalek",
"getrandom",
"getrandom 0.1.14",
"merlin",
"rand",
"rand_core",
"sha2",
"rand 0.7.3",
"rand_core 0.5.1",
"sha2 0.8.2",
"subtle 2.2.3",
"zeroize",
]
@@ -516,9 +705,9 @@ checksum = "656c79d0e90d0ab28ac86bf3c3d10bfbbac91450d3f190113b4e76d9fec3cfdd"
dependencies = [
"byte-tools",
"byteorder",
"hmac",
"hmac 0.7.1",
"pbkdf2",
"sha2",
"sha2 0.8.2",
]
[[package]]
@@ -526,6 +715,20 @@ name = "serde"
version = "1.0.114"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5317f7588f0a5078ee60ef675ef96735a1442132dc645eb1d12c018620ed8cd3"
dependencies = [
"serde_derive",
]
[[package]]
name = "serde_derive"
version = "1.0.114"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2a0be94b04690fbaed37cddffc5c134bf537c8e3329d53e982fe04c374978f8e"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "sha2"
@@ -533,10 +736,23 @@ version = "0.8.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a256f46ea78a0c0d9ff00077504903ac881a1dafdc20da66545699e7776b3e69"
dependencies = [
"block-buffer",
"digest",
"block-buffer 0.7.3",
"digest 0.8.1",
"fake-simd",
"opaque-debug",
"opaque-debug 0.2.3",
]
[[package]]
name = "sha2"
version = "0.9.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b69f9a4c9740d74c5baa3fd2e547f9525fa8088a8a958e0ca2409a514e33f5fa"
dependencies = [
"block-buffer 0.9.0",
"cfg-if 1.0.0",
"cpufeatures",
"digest 0.9.0",
"opaque-debug 0.3.0",
]
[[package]]
@@ -593,12 +809,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b0165e045cc2ae1660270ca65e1676dbaab60feb0f91b10f7d0665e9b47e31f2"
dependencies = [
"failure",
"hmac",
"hmac 0.7.1",
"once_cell",
"pbkdf2",
"rand",
"rand 0.7.3",
"rustc-hash",
"sha2",
"sha2 0.8.2",
"unicode-normalization",
]
@@ -623,7 +839,7 @@ version = "1.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3bfd5b7557925ce778ff9b9ef90e3ade34c524b5ff10e239c69a42d546d2af56"
dependencies = [
"rand",
"rand 0.7.3",
]
[[package]]
@@ -647,26 +863,42 @@ version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f7fe0bb3479651439c9112f72b6c505038574c9fbb575ed1bf3b797fa39dd564"
[[package]]
name = "version_check"
version = "0.9.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5fecdca9a5291cc2b8dcf7dc02453fee791a280f3743cb0905f8822ae463b3fe"
[[package]]
name = "wasi"
version = "0.9.0+wasi-snapshot-preview1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cccddf32554fecc6acb585f82a32a72e28b48f8c4c1883ddfeeeaa96f7d8e519"
[[package]]
name = "wasi"
version = "0.10.2+wasi-snapshot-preview1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fd6fbd9a79829dd1ad0cc20627bf1ed606756a7f77edff7b66b7064f9cb327c6"
[[package]]
name = "wasm"
version = "0.0.0"
dependencies = [
"blake2-rfc",
"byteorder",
"curve25519-dalek",
"ed25519-dalek",
"getrandom 0.2.3",
"hex-literal",
"hmac",
"hmac 0.7.1",
"libsecp256k1",
"merlin",
"pbkdf2",
"rand",
"rand 0.7.3",
"schnorrkel",
"scrypt",
"sha2",
"sha2 0.8.2",
"tiny-bip39",
"tiny-keccak",
"twox-hash",
@@ -680,7 +912,7 @@ version = "0.2.65"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f3edbcc9536ab7eababcc6d2374a0b7bfe13a2b6d562c5e07f370456b1a8f33d"
dependencies = [
"cfg-if",
"cfg-if 0.1.10",
"wasm-bindgen-macro",
]
@@ -734,7 +966,7 @@ version = "0.4.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dbb3b5a6b2bb17cb6ad44a2e68a43e8d2722c997da10e928665c72ec6c0a0b8e"
dependencies = [
"cfg-if",
"cfg-if 0.1.10",
"libc",
"memory_units",
"winapi",
+6 -1
View File
@@ -9,6 +9,7 @@ license = "Apache-2.0"
name = "wasm"
publish = false
repository = "https://github.com/polkadot-js/wasm/"
resolver = "2"
version = "0.0.0"
[lib]
@@ -17,10 +18,14 @@ crate-type = ["cdylib"]
[dependencies]
blake2-rfc = "0.2.18"
byteorder = "1.3.1"
curve25519-dalek = { version = "2.1.0", default-features = false }
ed25519-dalek = { version = "1.0.0-pre.4", features = [] }
getrandom = { version="0.2.3", features = ["js"] }
hmac = "0.7.0"
# libsecp256k1 = "0.2.2"
libsecp256k1 = { version = "0.7.0", default-features = false, features=["hmac", "lazy-static-context"] }
merlin = { version = "2.0", default-features = false }
pbkdf2 = { version = "0.3.0", default-features = false }
rand = { version="0.7.3", default-features = false, features = ["wasm-bindgen"] }
schnorrkel = { version = "0.9.1", features = ["preaudit_deprecated", "u64_backend"] }
scrypt = { version = "0.2", default-features = false }
sha2 = "0.8.1"
+27 -9
View File
@@ -1,17 +1,35 @@
{
"name": "@polkadot/wasm-crypto",
"version": "2.0.1",
"author": "Jaco Greeff <jacogr@gmail.com>",
"react-native": {
"./wasm/asm-empty.js": "./wasm/asm.js"
"bugs": "https://github.com/polkadot-js/wasm/issues",
"contributors": [],
"description": "A wasm interface layer for use by @polkadot/util-crypto",
"engines": {
"node": ">=14.0.0"
},
"homepage": "https://github.com/polkadot-js/wasm/tree/master/packages/wasm-crypto#readme",
"license": "Apache-2.0",
"maintainers": [],
"name": "@polkadot/wasm-crypto",
"repository": {
"directory": "packages/wasm-crypto",
"type": "git",
"url": "https://github.com/polkadot-js/wasm.git"
},
"sideEffects": [
"./detectPackage.js",
"./detectPackage.cjs"
],
"type": "module",
"version": "4.5.1",
"main": "index.js",
"types": "index.d.ts",
"dependencies": {
"@babel/runtime": "^7.16.3",
"@polkadot/wasm-crypto-asmjs": "^4.5.1",
"@polkadot/wasm-crypto-wasm": "^4.5.1"
},
"devDependencies": {
"@polkadot/dev": "^0.59.19",
"@polkadot/util": "^4.0.0-7",
"@polkadot/x-randomvalues": "^4.0.0-7",
"override-require": "^1.1.1"
"@polkadot/util": "^8.0.5",
"@polkadot/x-randomvalues": "^8.0.5"
},
"peerDependencies": {
"@polkadot/util": "*",
-103
View File
@@ -1,103 +0,0 @@
// Copyright 2019-2020 @polkadot/wasm-crypto authors & contributors
// SPDX-License-Identifier: Apache-2.0
const { assert, stringToU8a, u8aToString } = require('@polkadot/util');
let wasm;
let cachegetInt32 = null;
let cachegetUint8 = null;
async function initWasm (wasmBytes, asmFn, wbg) {
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;
} catch (error) {
// if we have a valid supplied asm.js, return that
if (asmFn) {
wasm = asmFn(wbg);
} else {
console.error('ERROR: Unable to initialize @polkadot/wasm-crypto');
console.error(error);
wasm = null;
}
}
}
function withWasm (fn) {
return (...params) => {
assert(wasm, '@polkadot/wasm-crypto has not been initialized. Ensure that you wait for the initialization Promise with waitReady() (or cryptoWaitReady() from @polkadot/util-crypto) before attempting to use WASM-only interfaces.');
return fn(wasm, ...params);
};
}
function getWasm () {
return wasm;
}
function getInt32 () {
if (cachegetInt32 === null || cachegetInt32.buffer !== wasm.memory.buffer) {
cachegetInt32 = new Int32Array(wasm.memory.buffer);
}
return cachegetInt32;
}
function getUint8 () {
if (cachegetUint8 === null || cachegetUint8.buffer !== wasm.memory.buffer) {
cachegetUint8 = new Uint8Array(wasm.memory.buffer);
}
return cachegetUint8;
}
function getU8a (ptr, len) {
return getUint8().subarray(ptr / 1, ptr / 1 + len);
}
function getString (ptr, len) {
return u8aToString(getU8a(ptr, len));
}
function allocU8a (arg) {
const ptr = wasm.__wbindgen_malloc(arg.length * 1);
getUint8().set(arg, ptr / 1);
return [ptr, arg.length];
}
function allocString (arg) {
return allocU8a(stringToU8a(arg));
}
function resultU8a () {
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;
}
function resultString () {
return u8aToString(resultU8a());
}
module.exports = {
allocString,
allocU8a,
getInt32,
getString,
getU8a,
getWasm,
initWasm,
resultString,
resultU8a,
withWasm
};
+99
View File
@@ -0,0 +1,99 @@
// Copyright 2019-2021 @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';
type PopFirst<T extends unknown[]> =
T extends [WasmCryptoInstance, ...infer N]
? N
: [];
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;
}
}
}
export function withWasm <T, F extends (wasm: WasmCryptoInstance, ...params: never[]) => T> (fn: F): (...params: PopFirst<Parameters<F>>) => ReturnType<F> {
return (...params: PopFirst<Parameters<F>>): ReturnType<F> => {
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 ReturnType<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());
}
+212
View File
@@ -0,0 +1,212 @@
// Copyright 2019-2021 @polkadot/wasm-crypto authors & contributors
// SPDX-License-Identifier: Apache-2.0
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';
export { packageInfo } from './packageInfo';
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 => {
wasm.ext_bip39_to_entropy(8, ...allocString(phrase));
return resultU8a();
});
export const bip39ToMiniSecret = withWasm((wasm, phrase: string, password: string): Uint8Array => {
wasm.ext_bip39_to_mini_secret(8, ...allocString(phrase), ...allocString(password));
return resultU8a();
});
export const bip39ToSeed = withWasm((wasm, phrase: string, password: string): Uint8Array => {
wasm.ext_bip39_to_seed(8, ...allocString(phrase), ...allocString(password));
return resultU8a();
});
export const bip39Validate = withWasm((wasm, phrase: string): boolean => {
const ret = wasm.ext_bip39_validate(...allocString(phrase));
return ret !== 0;
});
export const ed25519KeypairFromSeed = withWasm((wasm, seed: Uint8Array): Uint8Array => {
wasm.ext_ed_from_seed(8, ...allocU8a(seed));
return resultU8a();
});
export const ed25519Sign = withWasm((wasm, pubkey: Uint8Array, seckey: Uint8Array, message: Uint8Array): Uint8Array => {
wasm.ext_ed_sign(8, ...allocU8a(pubkey), ...allocU8a(seckey), ...allocU8a(message));
return resultU8a();
});
export const ed25519Verify = withWasm((wasm, signature: Uint8Array, message: Uint8Array, pubkey: Uint8Array): boolean => {
const ret = wasm.ext_ed_verify(...allocU8a(signature), ...allocU8a(message), ...allocU8a(pubkey));
return ret !== 0;
});
export const secp256k1FromSeed = withWasm((wasm, seckey: Uint8Array): Uint8Array => {
wasm.ext_secp_from_seed(8, ...allocU8a(seckey));
return resultU8a();
});
export const secp256k1Compress = withWasm((wasm, pubkey: Uint8Array): Uint8Array => {
wasm.ext_secp_pub_compress(8, ...allocU8a(pubkey));
return resultU8a();
});
export const secp256k1Expand = withWasm((wasm, pubkey: Uint8Array): Uint8Array => {
wasm.ext_secp_pub_expand(8, ...allocU8a(pubkey));
return resultU8a();
});
export const secp256k1Recover = withWasm((wasm, msgHash: Uint8Array, sig: Uint8Array, recovery: number): Uint8Array => {
wasm.ext_secp_recover(8, ...allocU8a(msgHash), ...allocU8a(sig), recovery);
return resultU8a();
});
export const secp256k1Sign = withWasm((wasm, msgHash: Uint8Array, seckey: Uint8Array): Uint8Array => {
wasm.ext_secp_sign(8, ...allocU8a(msgHash), ...allocU8a(seckey));
return resultU8a();
});
export const sr25519DeriveKeypairHard = withWasm((wasm, pair: Uint8Array, cc: Uint8Array): Uint8Array => {
wasm.ext_sr_derive_keypair_hard(8, ...allocU8a(pair), ...allocU8a(cc));
return resultU8a();
});
export const sr25519DeriveKeypairSoft = withWasm((wasm, pair: Uint8Array, cc: Uint8Array): Uint8Array => {
wasm.ext_sr_derive_keypair_soft(8, ...allocU8a(pair), ...allocU8a(cc));
return resultU8a();
});
export const sr25519DerivePublicSoft = withWasm((wasm, pubkey: Uint8Array, cc: Uint8Array): Uint8Array => {
wasm.ext_sr_derive_public_soft(8, ...allocU8a(pubkey), ...allocU8a(cc));
return resultU8a();
});
export const sr25519KeypairFromSeed = withWasm((wasm, seed: Uint8Array): Uint8Array => {
wasm.ext_sr_from_seed(8, ...allocU8a(seed));
return resultU8a();
});
export const sr25519Sign = withWasm((wasm, pubkey: Uint8Array, secret: Uint8Array, message: Uint8Array): Uint8Array => {
wasm.ext_sr_sign(8, ...allocU8a(pubkey), ...allocU8a(secret), ...allocU8a(message));
return resultU8a();
});
export const sr25519Verify = withWasm((wasm, signature: Uint8Array, message: Uint8Array, pubkey: Uint8Array): boolean => {
const ret = wasm.ext_sr_verify(...allocU8a(signature), ...allocU8a(message), ...allocU8a(pubkey));
return ret !== 0;
});
export const sr25519Agree = withWasm((wasm, pubkey: Uint8Array, secret: Uint8Array): Uint8Array => {
wasm.ext_sr_agree(8, ...allocU8a(pubkey), ...allocU8a(secret));
return resultU8a();
});
export const vrfSign = withWasm((wasm, secret: Uint8Array, context: Uint8Array, message: Uint8Array, extra: Uint8Array): Uint8Array => {
wasm.ext_vrf_sign(8, ...allocU8a(secret), ...allocU8a(context), ...allocU8a(message), ...allocU8a(extra));
return resultU8a();
});
export const vrfVerify = withWasm((wasm, pubkey: Uint8Array, context: Uint8Array, message: Uint8Array, extra: Uint8Array, outAndProof: Uint8Array): boolean => {
const ret = wasm.ext_vrf_verify(...allocU8a(pubkey), ...allocU8a(context), ...allocU8a(message), ...allocU8a(extra), ...allocU8a(outAndProof));
return ret !== 0;
});
export const blake2b = withWasm((wasm, data: Uint8Array, key: Uint8Array, size: number): Uint8Array => {
wasm.ext_blake2b(8, ...allocU8a(data), ...allocU8a(key), size);
return resultU8a();
});
export const hmacSha256 = withWasm((wasm, key: Uint8Array, data: Uint8Array): Uint8Array => {
wasm.ext_hmac_sha256(8, ...allocU8a(key), ...allocU8a(data));
return resultU8a();
});
export const hmacSha512 = withWasm((wasm, key: Uint8Array, data: Uint8Array): Uint8Array => {
wasm.ext_hmac_sha512(8, ...allocU8a(key), ...allocU8a(data));
return resultU8a();
});
export const keccak256 = withWasm((wasm, data: Uint8Array): Uint8Array => {
wasm.ext_keccak256(8, ...allocU8a(data));
return resultU8a();
});
export const keccak512 = withWasm((wasm, data: Uint8Array): Uint8Array => {
wasm.ext_keccak512(8, ...allocU8a(data));
return resultU8a();
});
export const pbkdf2 = withWasm((wasm, data: Uint8Array, salt: Uint8Array, rounds: number): Uint8Array => {
wasm.ext_pbkdf2(8, ...allocU8a(data), ...allocU8a(salt), rounds);
return resultU8a();
});
export const scrypt = withWasm((wasm, password: Uint8Array, salt: Uint8Array, log2n: number, r: number, p: number): Uint8Array => {
wasm.ext_scrypt(8, ...allocU8a(password), ...allocU8a(salt), log2n, r, p);
return resultU8a();
});
export const sha256 = withWasm((wasm, data: Uint8Array): Uint8Array => {
wasm.ext_sha256(8, ...allocU8a(data));
return resultU8a();
});
export const sha512 = withWasm((wasm, data: Uint8Array): Uint8Array => {
wasm.ext_sha512(8, ...allocU8a(data));
return resultU8a();
});
export const twox = withWasm((wasm, data: Uint8Array, rounds: number) => {
wasm.ext_twox(8, ...allocU8a(data), rounds);
return resultU8a();
});
export function isReady (): boolean {
return !!getWasm();
}
export function waitReady (): Promise<boolean> {
return wasmPromise.then(() => isReady());
}
+10
View File
@@ -0,0 +1,10 @@
// Copyright 2017-2021 @polkadot/wasm-crypto authors & contributors
// SPDX-License-Identifier: Apache-2.0
import { detectPackage } from '@polkadot/util';
import { packageInfo as asmInfo } from '@polkadot/wasm-crypto-asmjs/packageInfo';
import { packageInfo as wasmInfo } from '@polkadot/wasm-crypto-wasm/packageInfo';
import { packageInfo } from './packageInfo';
detectPackage(packageInfo, typeof __dirname !== 'undefined' && __dirname, [asmInfo, wasmInfo]);
-81
View File
@@ -1,81 +0,0 @@
// Copyright 2019-2020 @polkadot/wasm-crypto authors & contributors
// SPDX-License-Identifier: Apache-2.0
const getRandomValues = require('@polkadot/x-randomvalues').default;
const { getString, getU8a } = require('./bridge');
const DEFAULT_SELF = { crypto: { getRandomValues } };
const heap = new Array(32).fill(undefined).concat(undefined, null, true, false);
let heapNext = heap.length;
function getObject (idx) {
return heap[idx];
}
function dropObject (idx) {
if (idx < 36) {
return;
}
heap[idx] = heapNext;
heapNext = idx;
}
function takeObject (idx) {
const ret = getObject(idx);
dropObject(idx);
return ret;
}
function addObject (obj) {
if (heapNext === heap.length) {
heap.push(heap.length + 1);
}
const idx = heapNext;
heapNext = heap[idx];
heap[idx] = obj;
return idx;
}
module.exports.__wbindgen_is_undefined = function (arg0) {
return getObject(arg0) === undefined;
};
module.exports.__wbg_self_1b7a39e3a92c949c = function () {
return addObject(DEFAULT_SELF);
};
module.exports.__wbg_require_604837428532a733 = function (arg0, arg1) {
throw new Error(`Unable to import ${getString(arg0, arg1)}`);
};
module.exports.__wbg_crypto_968f1772287e2df0 = function (arg0) {
return addObject(getObject(arg0).crypto);
};
module.exports.__wbg_getRandomValues_a3d34b4fee3c2869 = function (arg0) {
return addObject(getObject(arg0).getRandomValues);
};
module.exports.__wbg_getRandomValues_f5e14ab7ac8e995d = function (arg0, arg1, arg2) {
getObject(arg0).getRandomValues(getU8a(arg1, arg2));
};
module.exports.__wbg_randomFillSync_d5bd2d655fdf256a = function (arg0, arg1, arg2) {
getObject(arg0).randomFillSync(getU8a(arg1, arg2));
};
module.exports.__wbindgen_object_drop_ref = function (arg0) {
takeObject(arg0);
};
module.exports.abort = function () {
throw new Error('abort');
};
+94
View File
@@ -0,0 +1,94 @@
// Copyright 2019-2021 @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 __wbindgen_throw (ptr: number, len: number): boolean {
throw new Error(getString(ptr, len));
}
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');
}
-31
View File
@@ -1,31 +0,0 @@
// Copyright 2019-2020 @polkadot/wasm-crypto authors & contributors
// SPDX-License-Identifier: Apache-2.0
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 scrypt (password: Uint8Array, salt: Uint8Array, log2N: number, r: number, p: 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>;
-188
View File
@@ -1,188 +0,0 @@
// Copyright 2019-2020 @polkadot/wasm-crypto authors & contributors
// SPDX-License-Identifier: Apache-2.0
const asmFallback = require('./wasm/asm-empty');
const wasmBytes = require('./wasm/bytes');
const { allocString, allocU8a, getWasm, initWasm, resultString, resultU8a, withWasm } = require('./bridge');
const imports = require('./imports');
const wasmPromise = initWasm(wasmBytes, asmFallback, imports).catch(() => null);
module.exports.bip39Generate = withWasm((wasm, words) => {
wasm.ext_bip39_generate(8, words);
return resultString();
});
module.exports.bip39ToEntropy = withWasm((wasm, phrase) => {
const [ptr0, len0] = allocString(phrase);
wasm.ext_bip39_to_entropy(8, ptr0, len0);
return resultU8a();
});
module.exports.bip39ToMiniSecret = withWasm((wasm, phrase, password) => {
const [ptr0, len0] = allocString(phrase);
const [ptr1, len1] = allocString(password);
wasm.ext_bip39_to_mini_secret(8, ptr0, len0, ptr1, len1);
return resultU8a();
});
module.exports.bip39ToSeed = withWasm((wasm, phrase, password) => {
const [ptr0, len0] = allocString(phrase);
const [ptr1, len1] = allocString(password);
wasm.ext_bip39_to_seed(8, ptr0, len0, ptr1, len1);
return resultU8a();
});
module.exports.bip39Validate = withWasm((wasm, phrase) => {
const [ptr0, len0] = allocString(phrase);
const ret = wasm.ext_bip39_validate(ptr0, len0);
return ret !== 0;
});
module.exports.ed25519KeypairFromSeed = withWasm((wasm, seed) => {
const [ptr0, len0] = allocU8a(seed);
wasm.ext_ed_from_seed(8, ptr0, len0);
return resultU8a();
});
module.exports.ed25519Sign = withWasm((wasm, pubkey, seckey, message) => {
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();
});
module.exports.ed25519Verify = withWasm((wasm, signature, message, pubkey) => {
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;
});
module.exports.blake2b = withWasm((wasm, data, key, size) => {
const [ptr0, len0] = allocU8a(data);
const [ptr1, len1] = allocU8a(key);
wasm.ext_blake2b(8, ptr0, len0, ptr1, len1, size);
return resultU8a();
});
module.exports.keccak256 = withWasm((wasm, data) => {
const [ptr0, len0] = allocU8a(data);
wasm.ext_keccak256(8, ptr0, len0);
return resultU8a();
});
module.exports.pbkdf2 = withWasm((wasm, data, salt, rounds) => {
const [ptr0, len0] = allocU8a(data);
const [ptr1, len1] = allocU8a(salt);
wasm.ext_pbkdf2(8, ptr0, len0, ptr1, len1, rounds);
return resultU8a();
});
module.exports.scrypt = withWasm((wasm, password, salt, log2n, r, p) => {
const [ptr0, len0] = allocU8a(password);
const [ptr1, len1] = allocU8a(salt);
wasm.ext_scrypt(8, ptr0, len0, ptr1, len1, log2n, r, p);
return resultU8a();
});
module.exports.sha512 = withWasm((wasm, data) => {
const [ptr0, len0] = allocU8a(data);
wasm.ext_sha512(8, ptr0, len0);
return resultU8a();
});
module.exports.twox = withWasm((wasm, data, rounds) => {
const [ptr0, len0] = allocU8a(data);
wasm.ext_twox(8, ptr0, len0, rounds);
return resultU8a();
});
module.exports.sr25519DeriveKeypairHard = withWasm((wasm, pair, cc) => {
const [ptr0, len0] = allocU8a(pair);
const [ptr1, len1] = allocU8a(cc);
wasm.ext_sr_derive_keypair_hard(8, ptr0, len0, ptr1, len1);
return resultU8a();
});
module.exports.sr25519DeriveKeypairSoft = withWasm((wasm, pair, cc) => {
const [ptr0, len0] = allocU8a(pair);
const [ptr1, len1] = allocU8a(cc);
wasm.ext_sr_derive_keypair_soft(8, ptr0, len0, ptr1, len1);
return resultU8a();
});
module.exports.sr25519DerivePublicSoft = withWasm((wasm, pubkey, cc) => {
const [ptr0, len0] = allocU8a(pubkey);
const [ptr1, len1] = allocU8a(cc);
wasm.ext_sr_derive_public_soft(8, ptr0, len0, ptr1, len1);
return resultU8a();
});
module.exports.sr25519KeypairFromSeed = withWasm((wasm, seed) => {
const [ptr0, len0] = allocU8a(seed);
wasm.ext_sr_from_seed(8, ptr0, len0);
return resultU8a();
});
module.exports.sr25519Sign = withWasm((wasm, pubkey, secret, message) => {
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();
});
module.exports.sr25519Verify = withWasm((wasm, signature, message, pubkey) => {
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;
});
module.exports.isReady = function () {
return !!getWasm();
};
module.exports.waitReady = function () {
return wasmPromise.then(() => !!getWasm());
};
+6
View File
@@ -0,0 +1,6 @@
// Copyright 2019-2021 @polkadot/wasm-crypto authors & contributors
// SPDX-License-Identifier: Apache-2.0
import './detectPackage';
export * from './bundle';
+11
View File
@@ -0,0 +1,11 @@
// Copyright 2017-2021 @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;
}
+7 -1
View File
@@ -1,4 +1,4 @@
// Copyright 2019-2020 @polkadot/wasm-crypto authors & contributors
// Copyright 2019-2021 @polkadot/wasm-crypto authors & contributors
// SPDX-License-Identifier: Apache-2.0
// Use `wee_alloc` as the global allocator.
@@ -14,5 +14,11 @@ pub mod ed25519;
#[path = "rs/hashing.rs"]
pub mod hashing;
#[path = "rs/secp256k1.rs"]
pub mod secp256k1;
#[path = "rs/sr25519.rs"]
pub mod sr25519;
#[path = "rs/vrf.rs"]
pub mod vrf;
+6
View File
@@ -0,0 +1,6 @@
// Copyright 2017-2021 @polkadot/wasm-crypto authors & contributors
// SPDX-License-Identifier: Apache-2.0
// Auto-generated by @polkadot/dev, do not edit
export const packageInfo = { name: '@polkadot/wasm-crypto', version: '4.5.1' };
+10
View File
@@ -0,0 +1,10 @@
root = true
[*]
indent_style=tab
indent_size=tab
tab_width=4
end_of_line=lf
charset=utf-8
trim_trailing_whitespace=true
max_line_length=100
insert_final_newline=true
+38 -25
View File
@@ -1,4 +1,4 @@
// Copyright 2019-2020 @polkadot/wasm-crypto authors & contributors
// Copyright 2019-2021 @polkadot/wasm-crypto authors & contributors
// SPDX-License-Identifier: Apache-2.0
use bip39::{Mnemonic, MnemonicType, Language, Seed};
@@ -14,8 +14,11 @@ use wasm_bindgen::prelude::*;
/// Returns the bip 39 phrase
#[wasm_bindgen]
pub fn ext_bip39_generate(words: u32) -> String {
Mnemonic::new(MnemonicType::for_word_count(words as usize).unwrap(), Language::English)
.into_phrase()
match MnemonicType::for_word_count(words as usize) {
Ok(p) => Mnemonic::new(p, Language::English)
.into_phrase(),
_ => panic!("Invalid count provided.")
}
}
/// Create entropy from a bip39 phrase
@@ -25,10 +28,12 @@ pub fn ext_bip39_generate(words: u32) -> String {
/// Returns the entropy
#[wasm_bindgen]
pub fn ext_bip39_to_entropy(phrase: &str) -> Vec<u8> {
Mnemonic::from_phrase(phrase, Language::English)
.unwrap()
.entropy()
.to_vec()
match Mnemonic::from_phrase(phrase, Language::English) {
Ok(m) => m
.entropy()
.to_vec(),
_ => panic!("Invalid phrase provided.")
}
}
/// Create a mini-secret from a bip39 phrase
@@ -38,13 +43,20 @@ pub fn ext_bip39_to_entropy(phrase: &str) -> Vec<u8> {
/// Returns the 32-byte mini-secret via entropy
#[wasm_bindgen]
pub fn ext_bip39_to_mini_secret(phrase: &str, password: &str) -> Vec<u8> {
let salt = format!("mnemonic{}", password);
let mnemonic = Mnemonic::from_phrase(phrase, Language::English).unwrap();
let mut result = [0u8; 64];
match Mnemonic::from_phrase(phrase, Language::English) {
Ok(m) => {
let mut res = [0u8; 64];
let mut seed = vec![];
pbkdf2::<Hmac<Sha512>>(mnemonic.entropy(), salt.as_bytes(), 2048, &mut result);
seed.extend_from_slice(b"mnemonic");
seed.extend_from_slice(password.as_bytes());
result[..32].to_vec()
pbkdf2::<Hmac<Sha512>>(m.entropy(), &seed, 2048, &mut res);
res[..32].to_vec()
},
_ => panic!("Invalid phrase provided.")
}
}
/// Creates a BTC/ETH compatible seed from a bip-39 phrase
@@ -54,11 +66,12 @@ pub fn ext_bip39_to_mini_secret(phrase: &str, password: &str) -> Vec<u8> {
/// Returns a 32-byte seed
#[wasm_bindgen]
pub fn ext_bip39_to_seed(phrase: &str, password: &str) -> Vec<u8> {
let mnemonic = Mnemonic::from_phrase(phrase, Language::English).unwrap();
Seed::new(&mnemonic, password)
.as_bytes()[..32]
.to_vec()
match Mnemonic::from_phrase(phrase, Language::English) {
Ok(m) => Seed::new(&m, password)
.as_bytes()[..32]
.to_vec(),
_ => panic!("Invalid phrase provided.")
}
}
/// Validates a bip39 phrase
@@ -69,8 +82,8 @@ pub fn ext_bip39_to_seed(phrase: &str, password: &str) -> Vec<u8> {
#[wasm_bindgen]
pub fn ext_bip39_validate(phrase: &str) -> bool {
match Mnemonic::validate(phrase, Language::English) {
Err(_) => false,
_ => true
Ok(_) => true,
_ => false
}
}
@@ -83,9 +96,9 @@ pub mod tests {
fn can_bip39_entropy() {
let phrase = "legal winner thank year wave sausage worth useful legal winner thank yellow";
let entropy = hex!("7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f");
let result = ext_bip39_to_entropy(phrase);
let res = ext_bip39_to_entropy(phrase);
assert_eq!(result, entropy);
assert_eq!(res, entropy);
}
#[test]
@@ -93,18 +106,18 @@ pub mod tests {
let phrase = "legal winner thank year wave sausage worth useful legal winner thank yellow";
let password = "Substrate";
let mini = hex!("4313249608fe8ac10fd5886c92c4579007272cb77c21551ee5b8d60b78041685");
let result = ext_bip39_to_mini_secret(phrase, password);
let res = ext_bip39_to_mini_secret(phrase, password);
assert_eq!(result[..], mini[..]);
assert_eq!(res[..], mini[..]);
}
#[test]
fn can_bip39_seed() {
let phrase = "seed sock milk update focus rotate barely fade car face mechanic mercy";
let seed = hex!("3c121e20de068083b49c2315697fb59a2d9e8643c24e5ea7628132c58969a027");
let result = ext_bip39_to_seed(phrase, "");
let res = ext_bip39_to_seed(phrase, "");
assert_eq!(result[..], seed[..]);
assert_eq!(res[..], seed[..]);
}
#[test]
+26 -24
View File
@@ -1,4 +1,4 @@
// Copyright 2019-2020 @polkadot/wasm-crypto authors & contributors
// Copyright 2019-2021 @polkadot/wasm-crypto authors & contributors
// SPDX-License-Identifier: Apache-2.0
use std::convert::TryFrom;
@@ -6,36 +6,40 @@ use ed25519_dalek::{Keypair, PublicKey, SecretKey, Signature, Signer as _, Verif
use wasm_bindgen::prelude::*;
/// Keypair helper function.
fn create_from_pair(pair: &[u8]) -> Keypair {
fn new_from_pair(pair: &[u8]) -> Keypair {
match Keypair::from_bytes(pair) {
Ok(pair) => return pair,
Err(_) => panic!("Provided pair is invalid.")
Ok(p) => p,
_ => panic!("Provided pair is invalid.")
}
}
/// Keypair helper function
fn create_from_parts(pubkey: &[u8], seckey: &[u8]) -> Keypair {
fn new_from_parts(pubkey: &[u8], seckey: &[u8]) -> Keypair {
let mut pair = vec![];
pair.extend_from_slice(seckey);
pair.extend_from_slice(pubkey);
create_from_pair(&pair)
new_from_pair(&pair)
}
/// Keypair helper function.
fn create_from_seed(seed: &[u8]) -> Keypair {
let seckey = SecretKey::from_bytes(seed).unwrap();
let pubkey: PublicKey = (&seckey).into();
fn new_from_seed(seed: &[u8]) -> Keypair {
match &SecretKey::from_bytes(seed) {
Ok(s) => {
let pubkey: PublicKey = s.into();
create_from_parts(pubkey.as_bytes(), seed)
new_from_parts(pubkey.as_bytes(), seed)
},
_ => panic!("Invalid seed provided.")
}
}
/// PublicKey helper
fn create_public(pubkey: &[u8]) -> PublicKey {
fn new_public(pubkey: &[u8]) -> PublicKey {
match PublicKey::from_bytes(pubkey) {
Ok(pubkey) => return pubkey,
Err(_) => panic!("Provided public key is invalid.")
Ok(p) => p,
_ => panic!("Provided public key is invalid.")
}
}
@@ -47,7 +51,7 @@ fn create_public(pubkey: &[u8]) -> PublicKey {
/// followed by the public key (32) bytes.
#[wasm_bindgen]
pub fn ext_ed_from_seed(seed: &[u8]) -> Vec<u8> {
create_from_seed(seed)
new_from_seed(seed)
.to_bytes()
.to_vec()
}
@@ -64,7 +68,7 @@ pub fn ext_ed_from_seed(seed: &[u8]) -> Vec<u8> {
/// * returned vector is the signature consisting of 64 bytes.
#[wasm_bindgen]
pub fn ext_ed_sign(pubkey: &[u8], seckey: &[u8], message: &[u8]) -> Vec<u8> {
create_from_parts(pubkey, seckey)
new_from_parts(pubkey, seckey)
.sign(message)
.to_bytes()
.to_vec()
@@ -77,14 +81,12 @@ pub fn ext_ed_sign(pubkey: &[u8], seckey: &[u8], message: &[u8]) -> Vec<u8> {
/// * pubkey: UIntArray with 32 element
#[wasm_bindgen]
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(pubkey)
.verify(message, &signature)
.is_ok()
match Signature::try_from(signature) {
Ok(s) => new_public(pubkey)
.verify(message, &s)
.is_ok(),
_ => false
}
}
#[cfg(test)]
@@ -100,7 +102,7 @@ pub mod tests {
}
#[test]
fn can_create_keypair() {
fn can_new_keypair() {
let seed = generate_random_seed();
let keypair = ext_ed_from_seed(seed.as_slice());
+126 -109
View File
@@ -1,32 +1,16 @@
// Copyright 2019-2020 @polkadot/wasm-crypto authors & contributors
// Copyright 2019-2021 @polkadot/wasm-crypto authors & contributors
// SPDX-License-Identifier: Apache-2.0
use blake2_rfc::blake2b::blake2b;
use byteorder::{ByteOrder, LittleEndian};
use hmac::Hmac;
use hmac::{Hmac, Mac};
use pbkdf2::pbkdf2;
use scrypt::{ScryptParams, scrypt};
use sha2::{Digest, Sha512};
// use secp256k1;
use sha2::{Digest, Sha256, Sha512};
use tiny_keccak::{Hasher, Keccak};
use twox_hash::XxHash;
use wasm_bindgen::prelude::*;
/// helper function for a single twox round with a seed
fn create_twox(data: &[u8], seed: u64) -> [u8; 8] {
use ::std::hash::Hasher;
let mut hasher = XxHash::with_seed(seed);
hasher.write(data);
let hash64 = hasher.finish();
let mut result = [0u8; 8];
LittleEndian::write_u64(&mut result, hash64);
result
}
/// blake2b hash for the specified input
///
/// * data: Arbitrary data to be hashed
@@ -42,6 +26,39 @@ pub fn ext_blake2b(data: &[u8], key: &[u8], size: u32) -> Vec<u8> {
.to_vec()
}
/// hmac with sha256
#[wasm_bindgen]
pub fn ext_hmac_sha256(key: &[u8], data: &[u8]) -> Vec<u8> {
match Hmac::<Sha256>::new_varkey(key) {
Ok(mut m) => {
m.input(data);
m
.result()
.code()
.to_vec()
},
_ => panic!("Invalid key provided.")
}
}
/// hmac with sha512
#[wasm_bindgen]
pub fn ext_hmac_sha512(key: &[u8], data: &[u8]) -> Vec<u8> {
match Hmac::<Sha512>::new_varkey(key) {
Ok(mut m) => {
m.input(data);
m
.result()
.code()
.to_vec()
},
_ => panic!("Invalid key provided.")
}
}
/// Create a keccak256 hash for the specified input
///
// * data: Arbitrary data to be hashed
@@ -50,12 +67,28 @@ pub fn ext_blake2b(data: &[u8], key: &[u8], size: u32) -> Vec<u8> {
#[wasm_bindgen]
pub fn ext_keccak256(data: &[u8]) -> Vec<u8> {
let mut keccak = Keccak::v256();
let mut result = [0u8; 32];
let mut res = [0u8; 32];
keccak.update(data);
keccak.finalize(&mut result);
keccak.finalize(&mut res);
result.to_vec()
res.to_vec()
}
/// Create a keccak512 hash for the specified input
///
// * data: Arbitrary data to be hashed
///
/// Returns the hash as a vector
#[wasm_bindgen]
pub fn ext_keccak512(data: &[u8]) -> Vec<u8> {
let mut keccak = Keccak::v512();
let mut res = [0u8; 64];
keccak.update(data);
keccak.finalize(&mut res);
res.to_vec()
}
/// pbkdf2 kdf from an input, salt for the number of specified rounds
@@ -67,12 +100,12 @@ pub fn ext_keccak256(data: &[u8]) -> Vec<u8> {
/// 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];
let mut res = [0u8; 64];
// we cast to usize here - due to the WASM, we'd rather have u32 inputs
pbkdf2::<Hmac<Sha512>>(data, salt, rounds as usize, &mut result);
pbkdf2::<Hmac::<Sha512>>(data, salt, rounds as usize, &mut res);
result.to_vec()
res.to_vec()
}
/// scrypt kdf from input, salt and config
@@ -86,66 +119,35 @@ pub fn ext_pbkdf2(data: &[u8], salt: &[u8], rounds: u32) -> Vec<u8> {
/// 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 ScryptParams::new(log2_n, r, p) {
Ok(p) => {
let mut res = [0u8; 64];
match scrypt(password, salt, &params, &mut result) {
Ok(_) => return result.to_vec(),
Err(_) => panic!("Invalid scrypt hash.")
match scrypt(password, salt, &p, &mut res) {
Ok(_) => res.to_vec(),
_ => panic!("Invalid scrypt hash.")
}
},
_ => panic!("Invalid scrypt params.")
}
}
// /// Checks for the recoverability of a signature from message
// ///
// /// * message: The message
// /// * signature: The signature
// ///
// /// Returns 0 on success, or a specific error code
// #[wasm_bindgen]
// pub fn ext_secp256k1_is_recoverable(message: &[u8], signature: &[u8]) -> u32 {
// let rs = match secp256k1::Signature::parse_slice(&signature[0..64]) {
// Ok(rs) => rs,
// _ => return 1
// };
// let v = match secp256k1::RecoveryId::parse(if signature[64] > 26 { signature[64] - 27 } else { signature[64] } as u8) {
// Ok(v) => v,
// _ => return 2
// };
// let mut msg = [0u8; 32];
/// sha256 hash for the specified input
///
/// * data: Arbitrary data to be hashed
///
/// Returns a vector with the hash result
#[wasm_bindgen]
pub fn ext_sha256(data: &[u8]) -> Vec<u8> {
let mut hasher = Sha256::new();
// msg.copy_from_slice(&message);
hasher.input(data);
// match secp256k1::recover(&secp256k1::Message::parse(&msg), &rs, &v) {
// Ok(_) => 0,
// _ => 3
// }
// }
// /// Recovers the secp256k1 signature from the input
// ///
// /// * message: The message
// /// * signature: The signature
// ///
// /// Returns a vector with the recovered public key
// #[wasm_bindgen]
// pub fn ext_secp256k1_recover(message: &[u8], signature: &[u8]) -> Vec<u8> {
// let rs = match secp256k1::Signature::parse_slice(&signature[0..64]) {
// Ok(rs) => rs,
// _ => panic!("Unable to recover r,s")
// };
// let v = match secp256k1::RecoveryId::parse(if signature[64] > 26 { signature[64] - 27 } else { signature[64] } as u8) {
// Ok(v) => v,
// _ => panic!("Unable to recover v")
// };
// let mut msg = [0u8; 32];
// msg.copy_from_slice(&message);
// match secp256k1::recover(&secp256k1::Message::parse(&msg), &rs, &v) {
// Ok(pk) => return pk.serialize()[1..65].to_vec(),
// _ => panic!("Unable to recover publickey")
// }
// }
hasher
.result()
.to_vec()
}
/// sha512 hash for the specified input
///
@@ -171,14 +173,20 @@ pub fn ext_sha512(data: &[u8]) -> Vec<u8> {
/// Returns a vector with the hash result
#[wasm_bindgen]
pub fn ext_twox(data: &[u8], rounds: u32) -> Vec<u8> {
let mut vec = vec![];
use ::std::hash::Hasher;
let mut res = vec![];
let mut buf = [0u8; 8];
for round in 0..rounds {
// we cast to u64 here - due to the WASM, we'd rather have u32 inputs
vec.extend_from_slice(&create_twox(data, round as u64));
let mut hasher = XxHash::with_seed(round as u64);
hasher.write(data);
LittleEndian::write_u64(&mut buf, hasher.finish());
res.extend_from_slice(&buf);
}
vec
res
}
#[cfg(test)]
@@ -186,24 +194,6 @@ pub mod tests {
use hex_literal::hex;
use super::*;
// // 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();
// let mut rev = Vec::new();
// let mut v = b"\x19Ethereum Signed Message:\n".to_vec();
// while l > 0 {
// rev.push(b'0' + (l % 10) as u8);
// l /= 10;
// }
// v.extend(rev.into_iter().rev());
// v.extend_from_slice(&prefix[..]);
// v.extend_from_slice(data);
// v
// }
#[test]
fn can_blake2b() {
let data = b"abc";
@@ -225,6 +215,35 @@ pub mod tests {
assert_eq!(hash[..], expected[..]);
}
#[test]
fn can_hmac_sha256() {
let key = b"secret";
let data = b"some message";
let expected = hex!("f28a70b41263840e5c059a0a733336e0957efba87902aa8cca11441d4b0c96d7");
let hash = ext_hmac_sha256(key, data);
assert_eq!(hash[..], expected[..]);
}
#[test]
fn can_hmac_sha512() {
let key = b"secret";
let data = b"some message";
let expected = hex!("295832e97ed77be75a9fa98029497e4a722c4b9a2f21b39d34f1befa931a39ec520fd24711d6f5c03501384ea66b83066a01a82c57a0460f8cd1f471fcce5841");
let hash = ext_hmac_sha512(key, data);
assert_eq!(hash[..], expected[..]);
}
#[test]
fn can_keccak512() {
let data = b"test";
let expected = hex!("1e2e9fc2002b002d75198b7503210c05a1baac4560916a3c6d93bcce3a50d7f00fd395bf1647b9abb8d1afcc9c76c289b0c9383ba386a956da4b38934417789e");
let hash = ext_keccak512(data);
assert_eq!(hash[..], expected[..]);
}
#[test]
fn can_pbkdf2() {
let salt = b"this is a salt";
@@ -245,16 +264,14 @@ pub mod tests {
assert_eq!(hash[..], expected[..]);
}
// #[test]
// fn can_secp256k1_real_eth_sig() {
// let sig = hex!("7505f2880114da51b3f5d535f8687953c0ab9af4ab81e592eaebebf53b728d2b6dfd9b5bcd70fee412b1f31360e7c2774009305cb84fc50c1d0ff8034dfa5fff1c");
// let pk = hex!("DF67EC7EAe23D2459694685257b6FC59d1BAA1FE");
// let data = [42, 0, 0, 0, 0, 0, 0, 0];
// let msg = ext_keccak256(&ethereum_signable_message(&data));
// let result = ext_keccak256(&ext_secp256k1_recover(&msg[..], &sig[..]));
#[test]
fn can_sha256() {
let data = b"hello world";
let expected = hex!("b94d27b9934d3e08a52e52d7da7dabfac484efe37a5380ee9088f7ace2efcde9");
let hash = ext_sha256(data);
// assert_eq!(result[12..], pk[..]);
// }
assert_eq!(hash[..], expected[..]);
}
#[test]
fn can_sha512() {
+126
View File
@@ -0,0 +1,126 @@
// Copyright 2019-2021 @polkadot/wasm-crypto authors & contributors
// SPDX-License-Identifier: Apache-2.0
use libsecp256k1::{Message, PublicKey, RecoveryId, SecretKey, Signature, recover, sign};
use wasm_bindgen::prelude::*;
#[wasm_bindgen]
pub fn ext_secp_pub_compress(pubkey: &[u8]) -> Vec<u8> {
match PublicKey::parse_slice(&pubkey, None) {
Ok(p) => p
.serialize_compressed()
.to_vec(),
_ => panic!("Invalid pubkey provided.")
}
}
#[wasm_bindgen]
pub fn ext_secp_pub_expand(pubkey: &[u8]) -> Vec<u8> {
match PublicKey::parse_slice(&pubkey, None) {
Ok(p) => p
.serialize()
.to_vec(),
_ => panic!("Invalid pubkey provided.")
}
}
#[wasm_bindgen]
pub fn ext_secp_from_seed(seed: &[u8]) -> Vec<u8> {
match SecretKey::parse_slice(seed) {
Ok(s) => {
let mut res = vec![];
let pubkey = PublicKey::from_secret_key(&s);
res.extend_from_slice(&s.serialize());
res.extend_from_slice(&pubkey.serialize_compressed());
res
},
_ => panic!("Incalid seed provided.")
}
}
#[wasm_bindgen]
pub fn ext_secp_recover(hash: &[u8], sig: &[u8], rec: u8) -> Vec<u8> {
match (Message::parse_slice(hash), Signature::parse_standard_slice(sig), RecoveryId::parse(rec)) {
(Ok(m), Ok(s), Ok(r)) =>
match recover(&m, &s, &r) {
Ok(k) => k
.serialize_compressed()
.to_vec(),
_ => panic!("Invalid message provided.")
},
_ => panic!("Invalid recovery data provided.")
}
}
#[wasm_bindgen]
pub fn ext_secp_sign(hash: &[u8], seckey: &[u8]) -> Vec<u8> {
match (Message::parse_slice(hash), SecretKey::parse_slice(seckey)) {
(Ok(m), Ok(s)) => {
let mut res = vec![];
let (sig, rec) = sign(&m, &s);
res.extend_from_slice(&sig.serialize());
res.push(rec.into());
res
},
_ => panic!("Invalid message or secret provided.")
}
}
#[cfg(test)]
pub mod tests {
use hex_literal::hex;
use super::*;
#[test]
fn can_create_pair() {
let seckey = hex!("4380de832af797688026ce24f85204d508243f201650c1a134929e5458b7fbae");
let expected = hex!("4380de832af797688026ce24f85204d508243f201650c1a134929e5458b7fbae03fd8c74f795ced92064b86191cb2772b1e3a0947740aa0a5a6e379592471fd85b");
let res = ext_secp_from_seed(&seckey);
assert_eq!(res[..], expected[..]);
}
#[test]
fn can_pub_compress_full() {
let pubkey = hex!("04b9dc646dd71118e5f7fda681ad9eca36eb3ee96f344f582fbe7b5bcdebb1307763fe926c273235fd979a134076d00fd1683cbd35868cb485d4a3a640e52184af");
let expected = hex!("03b9dc646dd71118e5f7fda681ad9eca36eb3ee96f344f582fbe7b5bcdebb13077");
let res = ext_secp_pub_compress(&pubkey);
assert_eq!(res[..], expected[..]);
}
#[test]
fn can_pub_expand_comp() {
let pubkey = hex!("03b9dc646dd71118e5f7fda681ad9eca36eb3ee96f344f582fbe7b5bcdebb13077");
let expected = hex!("04b9dc646dd71118e5f7fda681ad9eca36eb3ee96f344f582fbe7b5bcdebb1307763fe926c273235fd979a134076d00fd1683cbd35868cb485d4a3a640e52184af");
let res = ext_secp_pub_expand(&pubkey);
assert_eq!(res[..], expected[..]);
}
#[test]
fn can_recover() {
let expected = hex!("028d13da15a02f3a70677339d51b14177ee9b49657662b35e56a9d9dee17db1d30");
let sig = hex!("7505f2880114da51b3f5d535f8687953c0ab9af4ab81e592eaebebf53b728d2b6dfd9b5bcd70fee412b1f31360e7c2774009305cb84fc50c1d0ff8034dfa5fff");
let msg = hex!("a30b64ce1eedf409c8afb801d72c05234e64849ea538c15dd3c8cf4ffcf166c9");
let res = ext_secp_recover(&msg, &sig, 0);
assert_eq!(res[..], expected[..]);
}
#[test]
fn can_sign() {
// JS expectiation - doesn't match?
// let expected = hex!("df92f73d9f060cefacf187b5414491cb992998ace017fa48839b5cda3e264ba8c4efa521361678d9b8582744d77aa4b8d886d7380b7808a683174afad9c4700300");
let expected = hex!("df92f73d9f060cefacf187b5414491cb992998ace017fa48839b5cda3e264ba83b105adec9e9872647a7d8bb28855b45e22805aea3d097953cbb1391f671d13e01");
let seckey = hex!("4380de832af797688026ce24f85204d508243f201650c1a134929e5458b7fbae");
let msg = hex!("68c731589a583d08b70861683b59ce3dd56284cb2f0da5b6cd83e6641dac3aab");
let res = ext_secp_sign(&msg, &seckey);
assert_eq!(res[..], expected[..]);
}
}
+108 -42
View File
@@ -1,4 +1,4 @@
// Copyright 2019-2020 @polkadot/wasm-crypto authors & contributors
// Copyright 2019-2021 @polkadot/wasm-crypto authors & contributors
// SPDX-License-Identifier: Apache-2.0
// Copyright 2019 Paritytech via https://github.com/paritytech/schnorrkel-js/
@@ -7,6 +7,7 @@
// which was adpated from the initial https://github.com/paritytech/schnorrkel-js/
// forked at commit eff430ddc3090f56317c80654208b8298ef7ab3f
use curve25519_dalek::scalar::Scalar;
use schnorrkel::{
ExpansionMode, Keypair, MiniSecretKey, PublicKey, SecretKey, Signature,
derive::{Derivation, ChainCode, CHAIN_CODE_LENGTH},
@@ -14,10 +15,10 @@ use schnorrkel::{
use wasm_bindgen::prelude::*;
// We must make sure that this is the same as declared in the substrate source code.
const SIGNING_CTX: &'static [u8] = b"substrate";
const CTX: &'static [u8] = b"substrate";
/// ChainCode construction helper
fn create_cc(data: &[u8]) -> ChainCode {
fn new_cc(data: &[u8]) -> ChainCode {
let mut cc = [0u8; CHAIN_CODE_LENGTH];
cc.copy_from_slice(&data);
@@ -33,13 +34,14 @@ fn create_cc(data: &[u8]) -> ChainCode {
/// returned vector the derived keypair as a array of 96 bytes
#[wasm_bindgen]
pub fn ext_sr_derive_keypair_hard(pair: &[u8], cc: &[u8]) -> Vec<u8> {
Keypair::from_half_ed25519_bytes(pair)
.unwrap()
.secret
.hard_derive_mini_secret_key(Some(create_cc(cc)), &[]).0
.expand_to_keypair(ExpansionMode::Ed25519)
.to_half_ed25519_bytes()
.to_vec()
match Keypair::from_half_ed25519_bytes(pair) {
Ok(p) => p.secret
.hard_derive_mini_secret_key(Some(new_cc(cc)), &[]).0
.expand_to_keypair(ExpansionMode::Ed25519)
.to_half_ed25519_bytes()
.to_vec(),
_ => panic!("Invalid pair provided.")
}
}
/// Perform a derivation on a secret
@@ -50,11 +52,13 @@ pub fn ext_sr_derive_keypair_hard(pair: &[u8], cc: &[u8]) -> Vec<u8> {
/// returned vector the derived keypair as a array of 96 bytes
#[wasm_bindgen]
pub fn ext_sr_derive_keypair_soft(pair: &[u8], cc: &[u8]) -> Vec<u8> {
Keypair::from_half_ed25519_bytes(pair)
.unwrap()
.derived_key_simple(create_cc(cc), &[]).0
.to_half_ed25519_bytes()
.to_vec()
match Keypair::from_half_ed25519_bytes(pair) {
Ok(p) => p
.derived_key_simple(new_cc(cc), &[]).0
.to_half_ed25519_bytes()
.to_vec(),
_ => panic!("Invalid pair provided.")
}
}
/// Perform a derivation on a publicKey
@@ -65,11 +69,13 @@ 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(pubkey: &[u8], cc: &[u8]) -> Vec<u8> {
PublicKey::from_bytes(pubkey)
.unwrap()
.derived_key_simple(create_cc(cc), &[]).0
.to_bytes()
.to_vec()
match PublicKey::from_bytes(pubkey) {
Ok(k) => k
.derived_key_simple(new_cc(cc), &[]).0
.to_bytes()
.to_vec(),
_ => panic!("Invalid pubkey provided.")
}
}
/// Generate a key pair.
@@ -80,11 +86,13 @@ pub fn ext_sr_derive_public_soft(pubkey: &[u8], cc: &[u8]) -> Vec<u8> {
/// followed by the public key (32) bytes.
#[wasm_bindgen]
pub fn ext_sr_from_seed(seed: &[u8]) -> Vec<u8> {
MiniSecretKey::from_bytes(seed)
.unwrap()
.expand_to_keypair(ExpansionMode::Ed25519)
.to_half_ed25519_bytes()
.to_vec()
match MiniSecretKey::from_bytes(seed) {
Ok(s) => s
.expand_to_keypair(ExpansionMode::Ed25519)
.to_half_ed25519_bytes()
.to_vec(),
_ => panic!("Invalid seed provided.")
}
}
/// Generate a key pair from a known pair. (This is not exposed via WASM)
@@ -94,10 +102,12 @@ pub fn ext_sr_from_seed(seed: &[u8]) -> Vec<u8> {
/// returned vector is the concatenation of first the private key (64 bytes)
/// followed by the public key (32) bytes.
pub fn ext_sr_from_pair(pair: &[u8]) -> Vec<u8> {
Keypair::from_half_ed25519_bytes(pair)
.unwrap()
.to_half_ed25519_bytes()
.to_vec()
match Keypair::from_half_ed25519_bytes(pair) {
Ok(p) => p
.to_half_ed25519_bytes()
.to_vec(),
_ => panic!("Invalid pair provided.")
}
}
/// Sign a message
@@ -112,11 +122,13 @@ pub fn ext_sr_from_pair(pair: &[u8]) -> Vec<u8> {
/// * returned vector is the signature consisting of 64 bytes.
#[wasm_bindgen]
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(pubkey).unwrap())
.to_bytes()
.to_vec()
match (SecretKey::from_ed25519_bytes(secret), PublicKey::from_bytes(pubkey)) {
(Ok(s), Ok(k)) => s
.sign_simple(CTX, message, &k)
.to_bytes()
.to_vec(),
_ => panic!("Invalid secret or pubkey provided.")
}
}
/// Verify a message and its corresponding against a public key;
@@ -126,11 +138,37 @@ pub fn ext_sr_sign(pubkey: &[u8], secret: &[u8], message: &[u8]) -> Vec<u8> {
/// * pubkey: UIntArray with 32 element
#[wasm_bindgen]
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)
match (Signature::from_bytes(signature), PublicKey::from_bytes(pubkey)) {
(Ok(s), Ok(k)) => k
.verify_simple(CTX, message, &s)
.is_ok(),
Err(_) => false
_ => false
}
}
/// Key agreement between other's public key and self secret key.
///
/// * pubkey: UIntArray with 32 element
/// * secret: UIntArray with 64 element
///
/// * returned vector is the generated secret of 32 bytes.
#[wasm_bindgen]
pub fn ext_sr_agree(pubkey: &[u8], secret: &[u8]) -> Vec<u8> {
match SecretKey::from_ed25519_bytes(secret) {
Ok(s) => {
// The first 32 bytes holds the canonical private key
let mut key = [0u8; 32];
key.copy_from_slice(&s.to_bytes()[0..32]);
match (Scalar::from_canonical_bytes(key), PublicKey::from_bytes(pubkey)) {
(Some(n), Ok(k)) => (&n * k.as_point())
.compress().0
.to_vec(),
_ => panic!("Invalid scalar or pubkey provided.")
}
},
_ => panic!("Invalid secret provided.")
}
}
@@ -139,16 +177,16 @@ pub mod tests {
extern crate rand;
extern crate schnorrkel;
use hex_literal::hex;
use super::*;
use hex_literal::hex;
use schnorrkel::{SIGNATURE_LENGTH, KEYPAIR_LENGTH, SECRET_KEY_LENGTH};
fn generate_random_seed() -> Vec<u8> {
(0..32).map(|_| rand::random::<u8>() ).collect()
(0..32).map(|_| rand::random::<u8>()).collect()
}
#[test]
fn can_create_keypair() {
fn can_new_keypair() {
let seed = generate_random_seed();
let keypair = ext_sr_from_seed(seed.as_slice());
@@ -166,7 +204,7 @@ pub mod tests {
}
#[test]
fn create_pair_from_known_pair() {
fn new_pair_from_known_pair() {
let input = hex!("28b0ae221c6bb06856b287f60d7ea0d98552ea5a16db16956849aa371db3eb51fd190cce74df356432b410bd64682309d6dedb27c76845daf388557cbac3ca3446ebddef8cd9bb167dc30878d7113b7e168e6f0646beffd77d69d39bad76b47a");
let keypair = ext_sr_from_pair(&input);
let expected = hex!("46ebddef8cd9bb167dc30878d7113b7e168e6f0646beffd77d69d39bad76b47a");
@@ -243,4 +281,32 @@ pub mod tests {
assert_eq!(public, expected);
}
#[test]
fn key_agreement() {
let self_seed = hex!("98b3d305d5a5eace562387e47e59badd4d77e3f72cabfb10a60f8a197059f0a8");
let other_seed = hex!("9732eea001851ff862d949a1699c9971f3a26edbede2ad7922cbbe9a0701f366");
let expected = hex!("b03a0b198c34c16f35cae933d88b16341b4cef3e84e851f20e664c6a30527f4e");
let self_pair = ext_sr_from_seed(&self_seed);
let self_sk = &self_pair[0..SECRET_KEY_LENGTH];
let self_pk = &self_pair[SECRET_KEY_LENGTH..KEYPAIR_LENGTH];
let other_pair = ext_sr_from_seed(&other_seed);
let other_sk = &other_pair[0..SECRET_KEY_LENGTH];
let other_pk = &other_pair[SECRET_KEY_LENGTH..KEYPAIR_LENGTH];
assert_eq!(ext_sr_agree(self_pk, other_sk), expected);
assert_eq!(ext_sr_agree(other_pk, self_sk), expected);
let seed = generate_random_seed();
let self_pair = ext_sr_from_seed(seed.as_slice());
let self_sk = &self_pair[0..SECRET_KEY_LENGTH];
let self_pk = &self_pair[SECRET_KEY_LENGTH..KEYPAIR_LENGTH];
let seed = generate_random_seed();
let other_pair = ext_sr_from_seed(seed.as_slice());
let other_sk = &other_pair[0..SECRET_KEY_LENGTH];
let other_pk = &other_pair[SECRET_KEY_LENGTH..KEYPAIR_LENGTH];
assert_eq!(ext_sr_agree(self_pk, other_sk), ext_sr_agree(other_pk, self_sk));
}
}
+144
View File
@@ -0,0 +1,144 @@
// Copyright 2019-2021 @polkadot/wasm-crypto authors & contributors
// 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 merlin::Transcript;
use schnorrkel::{signing_context, vrf::{VRFOutput, VRFProof}, PublicKey, SecretKey};
use wasm_bindgen::prelude::*;
/// Size of VRF output, bytes
pub const OUTPUT_SIZE: usize = 32;
/// Size of VRF proof, bytes
pub const PROOF_SIZE: usize = 64;
/// Size of VRF raw output, bytes
pub const RAW_OUTPUT_SIZE: usize = 16;
/// Size of VRF limit, bytes
pub const THRESHOLD_SIZE: usize = 16;
/// Size of the final full output
pub const RESULT_SIZE: usize = OUTPUT_SIZE + PROOF_SIZE;
pub fn new_transcript(extra: &[u8]) -> Transcript {
let mut transcript = Transcript::new(b"VRF");
// if is important that we don't append when empty, since the
// append in merging encodes length information
if extra.len() > 0 {
transcript.append_message(b"", extra);
}
transcript
}
// We don't use the non-extra sign and verify internally since in sr25519 they only wrap -
//
// https://github.com/w3f/schnorrkel/blob/8fa2ad3e9fbf0b652c724df6a87a4b3c5500f759/src/vrf.rs#L660
/// Run a Random Verifiable Function (VRF) on one single input
/// (message) transcript, and an extra message transcript,
/// producing the output signature and corresponding short proof.
///
/// * secret: UIntArray with 64 element
/// * context: Arbitrary length UIntArray
/// * message: Arbitrary length UIntArray
/// * extra: Arbitrary length UIntArray
///
/// * returned vector is the 32-byte output (signature) and 64-byte proof.
#[wasm_bindgen]
pub fn ext_vrf_sign(secret: &[u8], ctx: &[u8], msg: &[u8], extra: &[u8]) -> Vec<u8> {
match SecretKey::from_ed25519_bytes(secret) {
Ok(s) => {
let mut res: [u8; RESULT_SIZE] = [0u8; RESULT_SIZE];
let (io, proof, _) = s
.to_keypair()
.vrf_sign_extra(signing_context(ctx).bytes(msg), new_transcript(extra));
res[..OUTPUT_SIZE].copy_from_slice(io.as_output_bytes());
res[OUTPUT_SIZE..].copy_from_slice(&proof.to_bytes());
res.to_vec()
},
_ => panic!("Invalid secret provided.")
}
}
/// Verify VRF proof for one single input transcript, and an extra message transcript,
/// and corresponding output.
///
/// * pubkey: UIntArray with 32 element
/// * context: Arbitrary length UIntArray
/// * message: Arbitrary length UIntArray
/// * extra: Arbitrary length UIntArray
/// * out_and_proof: 96-byte output & proof array from the ext_sign function.
#[wasm_bindgen]
pub fn ext_vrf_verify(pubkey: &[u8], ctx: &[u8], msg: &[u8], extra: &[u8], out: &[u8]) -> bool {
match (PublicKey::from_bytes(pubkey), VRFOutput::from_bytes(&out[..OUTPUT_SIZE]), VRFProof::from_bytes(&out[OUTPUT_SIZE..RESULT_SIZE])) {
(Ok(k), Ok(o), Ok(p)) => k
.vrf_verify_extra(signing_context(ctx).bytes(msg), &o, &p, new_transcript(extra))
.is_ok(),
_ => false,
}
}
#[cfg(test)]
pub mod tests {
extern crate rand;
extern crate schnorrkel;
use super::*;
use crate::sr25519::ext_sr_from_seed;
use schnorrkel::{KEYPAIR_LENGTH, SECRET_KEY_LENGTH};
fn generate_random_seed() -> Vec<u8> {
(0..32).map(|_| rand::random::<u8>()).collect()
}
#[test]
fn sign_extra_and_verify() {
let seed = generate_random_seed();
let keypair = ext_sr_from_seed(seed.as_slice());
let private = &keypair[0..SECRET_KEY_LENGTH];
let public = &keypair[SECRET_KEY_LENGTH..KEYPAIR_LENGTH];
let context = b"my VRF context";
let message = b"this is a message";
let extra = b"this is an extra";
// Perform multiple sign_extra calls w/ same context, message, extra args
let out1 = ext_vrf_sign(private, context, message, extra);
let out2 = ext_vrf_sign(private, context, message, extra);
// Basic size checks
assert!(out1.len() == RESULT_SIZE);
assert!(out2.len() == RESULT_SIZE);
// Given the same context, message & extra, output should be deterministic
assert_eq!(&out1[..OUTPUT_SIZE], &out2[..OUTPUT_SIZE]);
// But proof is non-deterministic
assert_ne!(&out1[OUTPUT_SIZE..], &out2[OUTPUT_SIZE..]);
// VRF outputs can verified w/ original context, message & extra args
assert!(ext_vrf_verify(
public,
context,
message,
extra,
&out1
));
assert!(ext_vrf_verify(
public,
context,
message,
extra,
&out2
));
}
}
+87
View File
@@ -0,0 +1,87 @@
// Copyright 2019-2021 @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 functions (required and used internally)
__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;
// exposed functions
ext_bip39_generate(resLen: 8, words: number): void;
ext_bip39_to_entropy(resLen: 8, ptrPhrase: number, lenPhrase: number): void;
ext_bip39_to_mini_secret(resLen: 8, ptrPhrase: number, lenPhrase: number, ptrPass: number, lenPass: number): void;
ext_bip39_to_seed(resLen: 8, ptrPhrase: number, lenPhrase: number, ptrPass: number, lenPass: number): void;
ext_bip39_validate(ptrPhrase: number, lenPhrase: number): number;
ext_ed_from_seed(resLen: 8, ptrSeed: number, lenSeed: number): void;
ext_ed_sign(resLen: 8, ptrPub: number, lenPub: number, ptrSec: number, lenSec: number, ptrMsg: number, lenMsg: number): void;
ext_ed_verify(ptrSig: number, lenSig: number, ptrMsg: number, lenMsg: number, ptrPub: number, lenPub: number): number;
ext_blake2b(resLen: 8, ptrData: number, lenData: number, ptrKey: number, lenKey: number, size: number): void;
ext_hmac_sha256(resLen: 8, ptrKey: number, lenKey: number, ptrData: number, lenData: number): void;
ext_hmac_sha512(resLen: 8, ptrKey: number, lenKey: number, ptrData: number, lenData: number): void;
ext_keccak256(resLen: 8, ptrData: number, lenData: number): void;
ext_keccak512(resLen: 8, ptrData: number, lenData: number): void;
ext_pbkdf2(resLen: 8, ptrData: number, lenData: number, ptrSalt: number, lenSalt: number, rounds: number): void;
ext_scrypt(resLen: 8, ptrPass: number, lenPass: number, ptrSalt: number, lenSalt: number, log2n: number, r: number, p: number): void;
ext_sha256(resLen: 8, ptrData: number, lenData: number): void;
ext_sha512(resLen: 8, ptrData: number, lenData: number): void;
ext_twox(resLen: 8, ptrData: number, lenData: number, rounds: number): void;
ext_secp_from_seed(reslen: 8, ptrSec: number, lenSec: number): void;
ext_secp_pub_compress(resLen: 8, ptrPub: number, lenPub: number): void;
ext_secp_pub_expand(resLen: 8, ptrPub: number, lenPub: number): void;
ext_secp_recover(resLen: 8, ptrMsgHash: number, lenMsgHash: number, ptrSig: number, lenSig: number, recovery: number): void;
ext_secp_sign(resLen: 8, ptrMsgHash: number, lenMsgHash: number, ptrSec: number, lenSec: number): void;
ext_sr_derive_keypair_hard(resLen: 8, ptrPair: number, lenPair: number, ptrCc: number, lenCc: number): void;
ext_sr_derive_keypair_soft(resLen: 8, ptrPub: number, lenPub: number, ptrCc: number, lenCc: number): void;
ext_sr_derive_public_soft(resLen: 8, ptrPub: number, lenPub: number, ptrCc: number, lenCc: number): void;
ext_sr_from_seed(resLen: 8, ptrSeed: number, lenSeed: number): void;
ext_sr_sign(resLen: 8, ptrPub: number, lenPub: number, ptrSec: number, lenSec: number, ptrMsg: number, lenMsg: number): void;
ext_sr_verify(ptrSig: number, lenSig: number, ptrMsg: number, lenMsg: number, ptrPub: number, lenPub: number): number;
ext_sr_agree(resLen: 8, ptrPub: number, lenPub: number, ptrSec: number, lenSec: number): void;
ext_vrf_sign(resLen: 8, ptrSec: number, lenSec: number, ptrCtx: number, lenCtx: number, ptrMsg: number, lenMsg: number, ptrExtra: number, lenExtra: number): void;
ext_vrf_verify(ptrPub: number, lenPub: number, ptrCtx: number, lenCtx: number, ptrMsg: number, lenMsg: number, ptrExtra: number, lenExtra: number, ptrProof: number, lenProof: number): number;
}
export type AsmCreator = (wbg: Record<string, WebAssembly.ImportValue>) => WasmCryptoInstance;
@@ -1,4 +0,0 @@
// Copyright 2019-2020 @polkadot/wasm-crypto authors & contributors
// SPDX-License-Identifier: Apache-2.0
module.exports = null;
-6
View File
@@ -1,6 +0,0 @@
// Copyright 2019-2020 @polkadot/wasm-crypto authors & contributors
// SPDX-License-Identifier: Apache-2.0
// Stub replaced at build time
module.exports = require('./asm-empty');
@@ -1,4 +0,0 @@
// Copyright 2019-2020 @polkadot/wasm-crypto authors & contributors
// SPDX-License-Identifier: Apache-2.0
module.exports = null;
-6
View File
@@ -1,6 +0,0 @@
// Copyright 2019-2020 @polkadot/wasm-crypto authors & contributors
// SPDX-License-Identifier: Apache-2.0
// Stub replaced at build time
module.exports = require('./bytes-empty');
-35
View File
@@ -1,35 +0,0 @@
// 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;
}
@@ -0,0 +1,15 @@
// Copyright 2019-2021 @polkadot/wasm-crypto authors & contributors
// SPDX-License-Identifier: Apache-2.0
const rootIncl = ['@polkadot/wasm-crypto-asmjs', '@polkadot/wasm-crypto-wasm'];
const detcIncl = rootIncl.map((p) => `${p}/packageInfo`);
require('override-require')(
(request) =>
rootIncl.some((p) => request.endsWith(p)) ||
detcIncl.some((p) => request.endsWith(p)),
(request) =>
rootIncl.some((p) => request.endsWith(p))
? require(`${rootIncl.find((p) => request.endsWith(p))}/build/data.cjs`)
: require(`${detcIncl.find((p) => request.endsWith(p)).replace('packageInfo', 'build/packageInfo.cjs')}`)
);
@@ -1,12 +1,9 @@
// Copyright 2019-2020 @polkadot/wasm-crypto authors & contributors
// Copyright 2019-2021 @polkadot/wasm-crypto authors & contributors
// SPDX-License-Identifier: Apache-2.0
// @ts-check
/* eslint-disable camelcase */
const { assert, u8aToHex } = require('@polkadot/util');
function bip39_generate (wasm) {
function bip39Generate (wasm) {
const res = wasm.bip39Generate(21);
console.log('\tPHR', res);
@@ -14,7 +11,7 @@ function bip39_generate (wasm) {
assert(res.split(' ').length === 21, 'ERROR: Invalid bip39 Phase length');
}
function bip39_generate_subsequent (wasm) {
function bip39GenerateSubsequent (wasm) {
const val1 = wasm.bip39Generate(24);
const val2 = wasm.bip39Generate(24);
@@ -24,7 +21,7 @@ function bip39_generate_subsequent (wasm) {
assert(val1 !== val2, 'ERROR: Subsequent mnemonics are the same');
}
function bip39_validate (wasm) {
function bip39Validate (wasm) {
const res = wasm.bip39Validate(wasm.bip39Generate(12));
console.log('\tVAL', res);
@@ -32,7 +29,7 @@ function bip39_validate (wasm) {
assert(res, 'ERROR: Invalid bip39 validation');
}
function bip39_toEntropy (wasm) {
function bip39ToEntropy (wasm) {
const res = u8aToHex(wasm.bip39ToEntropy('legal winner thank year wave sausage worth useful legal winner thank yellow'));
console.log('\tENT', res);
@@ -40,7 +37,7 @@ function bip39_toEntropy (wasm) {
assert(res === '0x7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f', 'ERROR: Invalid bip39 entropy');
}
function bip39_toMiniSecret (wasm) {
function bip39ToMiniSecret (wasm) {
const res = u8aToHex(wasm.bip39ToMiniSecret('legal winner thank year wave sausage worth useful legal winner thank yellow', 'Substrate'));
console.log('\tMIN', res);
@@ -48,7 +45,7 @@ function bip39_toMiniSecret (wasm) {
assert(res === '0x4313249608fe8ac10fd5886c92c4579007272cb77c21551ee5b8d60b78041685', 'ERROR: Invalid bip39 mini secret');
}
function bip39_toSeed (wasm) {
function bip39ToSeed (wasm) {
const res = u8aToHex(wasm.bip39ToSeed('seed sock milk update focus rotate barely fade car face mechanic mercy', ''));
console.log('\tSEE', res);
@@ -57,10 +54,10 @@ function bip39_toSeed (wasm) {
}
module.exports = {
bip39_generate,
bip39_generate_subsequent,
bip39_toEntropy,
bip39_toMiniSecret,
bip39_toSeed,
bip39_validate
bip39Generate,
bip39GenerateSubsequent,
bip39ToEntropy,
bip39ToMiniSecret,
bip39ToSeed,
bip39Validate
};
@@ -1,8 +1,6 @@
// Copyright 2019-2020 @polkadot/wasm-crypto authors & contributors
// Copyright 2019-2021 @polkadot/wasm-crypto authors & contributors
// SPDX-License-Identifier: Apache-2.0
/* eslint-disable camelcase */
const crypto = require('crypto');
const { assert, hexToU8a, stringToU8a, u8aToHex } = require('@polkadot/util');
@@ -14,7 +12,7 @@ function randomPair (wasm) {
return extractKeys(wasm.ed25519KeypairFromSeed(crypto.randomBytes(32)));
}
function ed25519_pairFromSeed (wasm) {
function ed25519PairFromSeed (wasm) {
const [pair, pk, sk] = extractKeys(wasm.ed25519KeypairFromSeed(stringToU8a('12345678901234567890123456789012')));
console.log('\tSEC', u8aToHex(sk));
@@ -23,7 +21,7 @@ function ed25519_pairFromSeed (wasm) {
assert(u8aToHex(pair) === '0x31323334353637383930313233343536373839303132333435363738393031322f8c6129d816cf51c374bc7f08c3e63ed156cf78aefb4a6550d97b87997977ee', 'ERROR: pairFromSeed() does not match');
}
function ed25519_signAndVerify (wasm) {
function ed25519SignAndVerify (wasm) {
const [, pk, sk] = randomPair(wasm);
const signature = wasm.ed25519Sign(pk, sk, stringToU8a('this is a message'));
const isValid = wasm.ed25519Verify(signature, stringToU8a('this is a message'), pk);
@@ -34,7 +32,7 @@ function ed25519_signAndVerify (wasm) {
assert(isValid, 'ERROR: Unable to verify signature');
}
function ed25519_verifyExisting (wasm) {
function ed25519VerifyExisting (wasm) {
const isValid = wasm.ed25519Verify(hexToU8a('0x90588f3f512496f2dd40571d162e8182860081c74e2085316e7c4396918f07da412ee029978e4dd714057fe973bd9e7d645148bf7b66680d67c93227cde95202'), stringToU8a('this is a message'), hexToU8a('0x2f8c6129d816cf51c374bc7f08c3e63ed156cf78aefb4a6550d97b87997977ee'));
console.log('\tRES', isValid);
@@ -42,7 +40,7 @@ function ed25519_verifyExisting (wasm) {
assert(isValid, 'ERROR: Unable to verify signature');
}
function ed25519_benchmark (wasm) {
function ed25519Benchmark (wasm) {
const MESSAGE = stringToU8a('this is a message');
for (let i = 0; i < 256; i++) {
@@ -53,8 +51,8 @@ function ed25519_benchmark (wasm) {
}
module.exports = {
ed25519_benchmark,
ed25519_pairFromSeed,
ed25519_signAndVerify,
ed25519_verifyExisting
ed25519Benchmark,
ed25519PairFromSeed,
ed25519SignAndVerify,
ed25519VerifyExisting
};
@@ -1,8 +1,6 @@
// Copyright 2019-2020 @polkadot/wasm-crypto authors & contributors
// Copyright 2019-2021 @polkadot/wasm-crypto authors & contributors
// SPDX-License-Identifier: Apache-2.0
/* eslint-disable camelcase */
const { assert, stringToU8a, u8aToHex } = require('@polkadot/util');
function blake2bHash (wasm) {
@@ -13,6 +11,22 @@ function blake2bHash (wasm) {
assert(hash === '0xba80a53f981c4d0d6a2797b69f12f6e94c212f14685ac4b74b12bb6fdbffa2d17d87c5392aab792dc252d5de4533cc9518d38aa8dbf1925ab92386edd4009923', 'ERROR: blake2bHash does not match');
}
function hmacSha256 (wasm) {
const hash = u8aToHex(wasm.hmacSha256(stringToU8a('secret'), stringToU8a('some message')));
console.log('\tRES', hash);
assert(hash === '0xf28a70b41263840e5c059a0a733336e0957efba87902aa8cca11441d4b0c96d7', 'ERROR: hmacSha256 does not match');
}
function hmacSha512 (wasm) {
const hash = u8aToHex(wasm.hmacSha512(stringToU8a('secret'), stringToU8a('some message')));
console.log('\tRES', hash);
assert(hash === '0x295832e97ed77be75a9fa98029497e4a722c4b9a2f21b39d34f1befa931a39ec520fd24711d6f5c03501384ea66b83066a01a82c57a0460f8cd1f471fcce5841', 'ERROR: hmacSha512 does not match');
}
function keccak256 (wasm) {
const hash = u8aToHex(wasm.keccak256(stringToU8a('test value')));
@@ -21,6 +35,14 @@ function keccak256 (wasm) {
assert(hash === '0x2d07364b5c231c56ce63d49430e085ea3033c750688ba532b24029124c26ca5e', 'ERROR: keccak256 does not match');
}
function keccak512 (wasm) {
const hash = u8aToHex(wasm.keccak512(stringToU8a('test')));
console.log('\tRES', hash);
assert(hash === '0x1e2e9fc2002b002d75198b7503210c05a1baac4560916a3c6d93bcce3a50d7f00fd395bf1647b9abb8d1afcc9c76c289b0c9383ba386a956da4b38934417789e', 'ERROR: keccak512 does not match');
}
function pbkdf2Hash (wasm) {
const hash = u8aToHex(wasm.pbkdf2(stringToU8a('hello world'), stringToU8a('this is a salt'), 2048));
@@ -29,17 +51,6 @@ function pbkdf2Hash (wasm) {
assert(hash === '0x5fcbe04f05300a3ecc5c35d18ea0b78f3f6853d2ae5f3fca374f69a7d1f78b5def5c60dae1a568026c7492511e0c53521e8bb6e03a650e1263265fee92722270', 'ERROR: pbkdf2Hash does not match');
}
// function secp256k1Recover (wasm) {
// const pk = u8aToHex(wasm.keccak256(wasm.secp256k1Recover(
// hexToU8a('0x2bbfa926ee947dfac384d981f8913b4e0992e52d7b6711e0ec3d9f8b0f752648'),
// hexToU8a('0x7505f2880114da51b3f5d535f8687953c0ab9af4ab81e592eaebebf53b728d2b6dfd9b5bcd70fee412b1f31360e7c2774009305cb84fc50c1d0ff8034dfa5fff1c')
// )));
// console.log('\tPUB', pk);
// assert(pk === '0x91d366769d44a7c7690428bfdf67ec7eae23d2459694685257b6fc59d1baa1fe', 'ERROR: secp256k1Recover does not match');
// }
function scryptHash (wasm) {
const hash = u8aToHex(wasm.scrypt(stringToU8a('password'), stringToU8a('salt'), 14, 8, 1));
@@ -48,6 +59,14 @@ function scryptHash (wasm) {
assert(hash === '0x745731af4484f323968969eda289aeee005b5903ac561e64a5aca121797bf7734ef9fd58422e2e22183bcacba9ec87ba0c83b7a2e788f03ce0da06463433cda6', 'ERROR: scryptHash does not match');
}
function sha256Hash (wasm) {
const hash = u8aToHex(wasm.sha256(stringToU8a('hello world')));
console.log('\tRES', hash);
assert(hash === '0xb94d27b9934d3e08a52e52d7da7dabfac484efe37a5380ee9088f7ace2efcde9', 'ERROR: sha256Hash does not match');
}
function sha512Hash (wasm) {
const hash = u8aToHex(wasm.sha512(stringToU8a('hello world')));
@@ -68,10 +87,13 @@ function twoxHash (wasm) {
module.exports = {
blake2bHash,
hmacSha256,
hmacSha512,
keccak256,
keccak512,
pbkdf2Hash,
scryptHash,
// secp256k1Recover,
sha256Hash,
sha512Hash,
twoxHash
};
@@ -1,17 +1,21 @@
// Copyright 2019-2020 @polkadot/wasm-crypto authors & contributors
// Copyright 2019-2021 @polkadot/wasm-crypto authors & contributors
// SPDX-License-Identifier: Apache-2.0
const wasm = require('../../build/index');
const bip39 = require('./bip39');
const ed25519 = require('./ed25519');
const hashing = require('./hashing');
const sr25519 = require('./sr25519');
const wasm = require('../../build/index.cjs');
const bip39 = require('./bip39.cjs');
const ed25519 = require('./ed25519.cjs');
const hashing = require('./hashing.cjs');
const secp256k1 = require('./secp256k1.cjs');
const sr25519 = require('./sr25519.cjs');
const vrf = require('./vrf.cjs');
const tests = {
...bip39,
...ed25519,
...hashing,
...sr25519
...secp256k1,
...sr25519,
...vrf
};
function beforeAll () {
@@ -45,15 +49,14 @@ function runAll () {
}
function runUnassisted () {
(async () => {
await beforeAll();
beforeAll()
.then(() => runAll())
.then(() => process.exit(0))
.catch((error) => {
console.error(error);
runAll();
})().catch((error) => {
console.error(error);
process.exit(-1);
});
process.exit(-1);
});
}
module.exports = {
@@ -0,0 +1,59 @@
// Copyright 2019-2021 @polkadot/wasm-crypto authors & contributors
// SPDX-License-Identifier: Apache-2.0
const { assert, hexToU8a, u8aToHex } = require('@polkadot/util');
function secp256k1Compress (wasm) {
const pubkey = '0x04b9dc646dd71118e5f7fda681ad9eca36eb3ee96f344f582fbe7b5bcdebb1307763fe926c273235fd979a134076d00fd1683cbd35868cb485d4a3a640e52184af';
const result = u8aToHex(wasm.secp256k1Compress(hexToU8a(pubkey)));
console.log('\tRES', result);
assert(result === '0x03b9dc646dd71118e5f7fda681ad9eca36eb3ee96f344f582fbe7b5bcdebb13077', 'ERROR: secp256k1Compress does not match');
}
function secp256k1Expand (wasm) {
const pubkey = '0x03b9dc646dd71118e5f7fda681ad9eca36eb3ee96f344f582fbe7b5bcdebb13077';
const result = u8aToHex(wasm.secp256k1Expand(hexToU8a(pubkey)));
console.log('\tRES', result);
assert(result === '0x04b9dc646dd71118e5f7fda681ad9eca36eb3ee96f344f582fbe7b5bcdebb1307763fe926c273235fd979a134076d00fd1683cbd35868cb485d4a3a640e52184af', 'ERROR: secp256k1Expand does not match');
}
function secp256k1FromSeed (wasm) {
const seckey = '0x4380de832af797688026ce24f85204d508243f201650c1a134929e5458b7fbae';
const result = u8aToHex(wasm.secp256k1FromSeed(hexToU8a(seckey)));
console.log('\tRES', result);
assert(result === '0x4380de832af797688026ce24f85204d508243f201650c1a134929e5458b7fbae03fd8c74f795ced92064b86191cb2772b1e3a0947740aa0a5a6e379592471fd85b', 'ERROR: secp256k1FromSeed does not match');
}
function secp256k1Recover (wasm) {
const sig = '0x7505f2880114da51b3f5d535f8687953c0ab9af4ab81e592eaebebf53b728d2b6dfd9b5bcd70fee412b1f31360e7c2774009305cb84fc50c1d0ff8034dfa5fff';
const msg = '0xa30b64ce1eedf409c8afb801d72c05234e64849ea538c15dd3c8cf4ffcf166c9';
const result = u8aToHex(wasm.secp256k1Recover(hexToU8a(msg), hexToU8a(sig), 0));
console.log('\tRES', result);
assert(result === '0x028d13da15a02f3a70677339d51b14177ee9b49657662b35e56a9d9dee17db1d30', 'ERROR: secp256k1Recover does not match');
}
function secp256k1Sign (wasm) {
const sec = '0x4380de832af797688026ce24f85204d508243f201650c1a134929e5458b7fbae';
const msg = '0x68c731589a583d08b70861683b59ce3dd56284cb2f0da5b6cd83e6641dac3aab';
const result = u8aToHex(wasm.secp256k1Sign(hexToU8a(msg), hexToU8a(sec)));
console.log('\tRES', result);
assert(result === '0xdf92f73d9f060cefacf187b5414491cb992998ace017fa48839b5cda3e264ba83b105adec9e9872647a7d8bb28855b45e22805aea3d097953cbb1391f671d13e01', 'ERROR: secp256k1Sign does not match');
}
module.exports = {
secp256k1Compress,
secp256k1Expand,
secp256k1FromSeed,
secp256k1Recover,
secp256k1Sign
};
@@ -1,8 +1,6 @@
// Copyright 2019-2020 @polkadot/wasm-crypto authors & contributors
// Copyright 2019-2021 @polkadot/wasm-crypto authors & contributors
// SPDX-License-Identifier: Apache-2.0
/* eslint-disable camelcase */
const crypto = require('crypto');
const { assert, hexToU8a, stringToU8a, u8aToHex } = require('@polkadot/util');
@@ -14,7 +12,7 @@ function randomPair (wasm) {
return extractKeys(wasm.sr25519KeypairFromSeed(crypto.randomBytes(32)));
}
function sr25519_pairFromSeed (wasm) {
function sr25519PairFromSeed (wasm) {
const pair = wasm.sr25519KeypairFromSeed(stringToU8a('12345678901234567890123456789012'));
console.log('\tSEC', u8aToHex(pair.slice(0, 64)));
@@ -23,7 +21,7 @@ function sr25519_pairFromSeed (wasm) {
assert(u8aToHex(pair) === '0xf0106660c3dda23f16daa9ac5b811b963077f5bc0af89f85804f0de8e424f050f98d66f39442506ff947fd911f18c7a7a5da639a63e8d3b4e233f74143d951c1741c08a06f41c596608f6774259bd9043304adfa5d3eea62760bd9be97634d63', 'ERROR: pairFromSeed() does not match');
}
function sr25519_devFromSeed (wasm) {
function sr25519DevFromSeed (wasm) {
const pair = wasm.sr25519KeypairFromSeed(hexToU8a('0xfac7959dbfe72f052e5a0c3c8d6530f202b02fd8f9f5ca3580ec8deb7797479e'));
console.log('\tSEC', u8aToHex(pair.slice(0, 64)));
@@ -32,7 +30,7 @@ function sr25519_devFromSeed (wasm) {
assert(u8aToHex(pair) === '0x28b0ae221c6bb06856b287f60d7ea0d98552ea5a16db16956849aa371db3eb51fd190cce74df356432b410bd64682309d6dedb27c76845daf388557cbac3ca3446ebddef8cd9bb167dc30878d7113b7e168e6f0646beffd77d69d39bad76b47a', 'ERROR: devFromSeed() does not match');
}
function sr25519_verifyExisting (wasm) {
function sr25519VerifyExisting (wasm) {
const PK = hexToU8a('0xd43593c715fdd31c61141abd04a99fd6822c8558854ccde39a5684e7a56da27d');
const MESSAGE = stringToU8a('I hereby verify that I control 5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY');
const SIGNATURE = hexToU8a('0xb83881d3bd7302981ee1c504fe5b7b394682927131fc0846fd616bb40fa14d02640fd2aca785b4cb57904765c2e4e75f59a7dd30154c209964369912091f6981');
@@ -44,7 +42,7 @@ function sr25519_verifyExisting (wasm) {
assert(isValid, 'ERROR: Unable to verify signature');
}
function sr25519_sign_deterministic (wasm) {
function sr25519SignDeterministic (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')));
@@ -55,7 +53,7 @@ function sr25519_sign_deterministic (wasm) {
assert(sig1 !== sig2, 'ERROR: Signatures are deterministic');
}
function sr25519_signAndVerify (wasm) {
function sr25519SignAndVerify (wasm) {
const [, pk, sk] = randomPair(wasm);
const signature = wasm.sr25519Sign(pk, sk, stringToU8a('this is a message'));
const isValid = wasm.sr25519Verify(signature, stringToU8a('this is a message'), pk);
@@ -66,7 +64,7 @@ function sr25519_signAndVerify (wasm) {
assert(isValid, 'ERROR: Unable to verify signature');
}
function sr25519_deriveHard (wasm) {
function sr25519DeriveHard (wasm) {
const [pair] = randomPair(wasm);
const derived = wasm.sr25519DeriveKeypairHard(pair, hexToU8a('0x0c666f6f00000000000000000000000000000000000000000000000000000000'));
@@ -74,7 +72,7 @@ function sr25519_deriveHard (wasm) {
console.log('\tPUB', u8aToHex(derived.slice(64)));
}
function sr25519_deriveHardKnown (wasm) {
function sr25519DeriveHardKnown (wasm) {
const derived = wasm.sr25519DeriveKeypairHard(hexToU8a('0x28b0ae221c6bb06856b287f60d7ea0d98552ea5a16db16956849aa371db3eb51fd190cce74df356432b410bd64682309d6dedb27c76845daf388557cbac3ca3446ebddef8cd9bb167dc30878d7113b7e168e6f0646beffd77d69d39bad76b47a'), hexToU8a('0x14416c6963650000000000000000000000000000000000000000000000000000'));
const publicKey = u8aToHex(derived.slice(64));
@@ -84,7 +82,7 @@ function sr25519_deriveHardKnown (wasm) {
assert(publicKey === '0xd43593c715fdd31c61141abd04a99fd6822c8558854ccde39a5684e7a56da27d', 'Unmatched resulting public keys');
}
function sr25519_deriveSoft (wasm) {
function sr25519DeriveSoft (wasm) {
const [pair] = randomPair(wasm);
const derived = wasm.sr25519DeriveKeypairSoft(pair, hexToU8a('0x0c666f6f00000000000000000000000000000000000000000000000000000000'));
@@ -92,7 +90,7 @@ function sr25519_deriveSoft (wasm) {
console.log('\tPUB', u8aToHex(derived.slice(64)));
}
function sr25519_deriveSoftKnown (wasm) {
function sr25519DeriveSoftKnown (wasm) {
const derived = wasm.sr25519DeriveKeypairSoft(hexToU8a('0x28b0ae221c6bb06856b287f60d7ea0d98552ea5a16db16956849aa371db3eb51fd190cce74df356432b410bd64682309d6dedb27c76845daf388557cbac3ca3446ebddef8cd9bb167dc30878d7113b7e168e6f0646beffd77d69d39bad76b47a'), hexToU8a('0x0c666f6f00000000000000000000000000000000000000000000000000000000'));
const publicKey = u8aToHex(derived.slice(64));
@@ -102,7 +100,7 @@ function sr25519_deriveSoftKnown (wasm) {
assert(publicKey === '0x40b9675df90efa6069ff623b0fdfcf706cd47ca7452a5056c7ad58194d23440a', 'Unmatched resulting public keys');
}
function sr25519_deriveSoftPubkey (wasm) {
function sr25519DeriveSoftPubkey (wasm) {
const derived = u8aToHex(wasm.sr25519DerivePublicSoft(hexToU8a('0x46ebddef8cd9bb167dc30878d7113b7e168e6f0646beffd77d69d39bad76b47a'), hexToU8a('0x0c666f6f00000000000000000000000000000000000000000000000000000000')));
console.log('\tPUB', derived);
@@ -110,7 +108,24 @@ function sr25519_deriveSoftPubkey (wasm) {
assert(derived === '0x40b9675df90efa6069ff623b0fdfcf706cd47ca7452a5056c7ad58194d23440a', 'Unmatched resulting public keys');
}
function sr25519_benchmark (wasm) {
function sr25519KeyAgreement (wasm) {
const pair1 = wasm.sr25519KeypairFromSeed(hexToU8a('0x3b44c558f9a8f3dc9690d53088558c1ba2529b677e316c6054d1852595b004af'));
const pair2 = wasm.sr25519KeypairFromSeed(hexToU8a('0x923b80f79c6981fe756272128ec236eb510ae016dd20bdccbd77a9416b7ab94e'));
const [, pk1, sk1] = extractKeys(pair1);
const [, pk2, sk2] = extractKeys(pair2);
assert(u8aToHex(wasm.sr25519Agree(pk1, sk2)) === '0xfa7b90001b790fe42ff78b8cd86f6cf7a7c0a70b72f6b4c771b5d67536450222', 'Unmatched agreement keys');
assert(u8aToHex(wasm.sr25519Agree(pk2, sk1)) === '0xfa7b90001b790fe42ff78b8cd86f6cf7a7c0a70b72f6b4c771b5d67536450222', 'Unmatched agreement keys');
for (let i = 0; i < 256; i++) {
const [, pk1, sk1] = randomPair(wasm);
const [, pk2, sk2] = randomPair(wasm);
assert(u8aToHex(wasm.sr25519Agree(pk1, sk2)) === u8aToHex(wasm.sr25519Agree(pk2, sk1)), 'Unmatched agreement keys');
}
}
function sr25519Benchmark (wasm) {
const MESSAGE = stringToU8a('this is a message');
for (let i = 0; i < 256; i++) {
@@ -121,15 +136,16 @@ function sr25519_benchmark (wasm) {
}
module.exports = {
sr25519_benchmark,
sr25519_deriveHard,
sr25519_deriveHardKnown,
sr25519_deriveSoft,
sr25519_deriveSoftKnown,
sr25519_deriveSoftPubkey,
sr25519_devFromSeed,
sr25519_pairFromSeed,
sr25519_signAndVerify,
sr25519_sign_deterministic,
sr25519_verifyExisting
sr25519Benchmark,
sr25519DeriveHard,
sr25519DeriveHardKnown,
sr25519DeriveSoft,
sr25519DeriveSoftKnown,
sr25519DeriveSoftPubkey,
sr25519DevFromSeed,
sr25519KeyAgreement,
sr25519PairFromSeed,
sr25519SignAndVerify,
sr25519SignDeterministic,
sr25519VerifyExisting
};
+54
View File
@@ -0,0 +1,54 @@
// Copyright 2019-2021 @polkadot/wasm-crypto authors & contributors
// SPDX-License-Identifier: Apache-2.0
const crypto = require('crypto');
const { assert, stringToU8a, u8aToHex } = require('@polkadot/util');
function extractKeys (pair) {
return [pair, pair.slice(64), pair.slice(0, 64)];
}
function randomPair (wasm) {
return extractKeys(wasm.sr25519KeypairFromSeed(crypto.randomBytes(32)));
}
function vrfSignAndVerifyCompat (wasm) {
const [, pk, sk] = randomPair(wasm);
const outAndProof = wasm.vrfSign(sk, stringToU8a('my VRF context'), stringToU8a('this is a message'), new Uint8Array());
const isValid = wasm.vrfVerify(pk, stringToU8a('my VRF context'), stringToU8a('this is a message'), new Uint8Array(), outAndProof);
console.log('\tVRF', u8aToHex(outAndProof));
console.log('\tRES', isValid);
assert(isValid, 'ERROR: Unable to verify VRF output & proof');
}
function vrfSignAndVerify (wasm) {
const [, pk, sk] = randomPair(wasm);
const outAndProof = wasm.vrfSign(sk, stringToU8a('my VRF context'), stringToU8a('this is a message'), stringToU8a('extra param'));
const isValid = wasm.vrfVerify(pk, stringToU8a('my VRF context'), stringToU8a('this is a message'), stringToU8a('extra param'), outAndProof);
console.log('\tVRF', u8aToHex(outAndProof));
console.log('\tRES', isValid);
assert(isValid, 'ERROR: Unable to verify VRF extra output & proof');
}
function vrfSignAndVerifyDeterministic (wasm) {
const [,, sk] = randomPair(wasm);
const outAndProof1 = wasm.vrfSign(sk, stringToU8a('my VRF context'), stringToU8a('this is a message'), stringToU8a('extra param'));
const outAndProof2 = wasm.vrfSign(sk, stringToU8a('my VRF context'), stringToU8a('this is a message'), stringToU8a('extra param'));
const sig1 = u8aToHex(outAndProof1.slice(0, 32));
const sig2 = u8aToHex(outAndProof2.slice(0, 32));
console.log('\tSG1', sig1);
console.log('\tSG2', sig2);
assert(sig1 === sig2, 'ERROR: VRF extra outputs are non-deterministic');
}
module.exports = {
vrfSignAndVerify,
vrfSignAndVerifyCompat,
vrfSignAndVerifyDeterministic
};
+10
View File
@@ -0,0 +1,10 @@
// Copyright 2019-2021 @polkadot/wasm-crypto authors & contributors
// SPDX-License-Identifier: Apache-2.0
global.WebAssembly = null;
require('./alias-imports.cjs');
const { runUnassisted } = require('./all/index.cjs');
runUnassisted();
-13
View File
@@ -1,13 +0,0 @@
// Copyright 2019-2020 @polkadot/wasm-crypto authors & contributors
// SPDX-License-Identifier: Apache-2.0
global.WebAssembly = null;
require('override-require')(
(request) => request.endsWith('wasm/asm-empty'),
() => require('../build/wasm/asm')
);
const { runUnassisted } = require('./all');
runUnassisted();
+4 -2
View File
@@ -1,11 +1,13 @@
// Copyright 2019-2020 @polkadot/wasm-crypto authors & contributors
// Copyright 2019-2021 @polkadot/wasm-crypto authors & contributors
// SPDX-License-Identifier: Apache-2.0
/**
* @jest-environment jsdom
*/
const { beforeAll, tests, wasm } = require('./all');
// override-require in jest.config.js
import { beforeAll, tests, wasm } from './all/index.cjs';
describe('wasm-crypto', () => {
beforeEach(async () => {
+8
View File
@@ -0,0 +1,8 @@
// Copyright 2019-2021 @polkadot/wasm-crypto authors & contributors
// SPDX-License-Identifier: Apache-2.0
require('./alias-imports.cjs');
const { runUnassisted } = require('./all/index.cjs');
runUnassisted();
-6
View File
@@ -1,6 +0,0 @@
// Copyright 2019-2020 @polkadot/wasm-crypto authors & contributors
// SPDX-License-Identifier: Apache-2.0
const { runUnassisted } = require('./all');
runUnassisted();
+30
View File
@@ -0,0 +1,30 @@
// Copyright 2019-2021 @polkadot/wasm-crypto authors & contributors
// SPDX-License-Identifier: Apache-2.0
import { createBundle } from '@polkadot/dev/config/rollup';
const pkgs = [
'@polkadot/wasm-crypto'
];
const external = [
...pkgs,
'@polkadot/util'
];
const overrides = {
'@polkadot/wasm-crypto': {
entries: ['asmjs', 'wasm'].map((p) => `wasm-crypto-${p}`).reduce((all, p) => ({
...all,
[`@polkadot/${p}`]: `../../${p}/build`
}), {})
}
};
export default pkgs.map((pkg) =>
createBundle({
external,
pkg,
...(overrides[pkg] || {})
})
);
+11
View File
@@ -0,0 +1,11 @@
#!/usr/bin/env bash
# Copyright 2019-2021 @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
DEST=packages/wasm-crypto/build/esm
./scripts/clean-js.sh
yarn polkadot-dev-build-ts
-53
View File
@@ -1,53 +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
# also change in install-build-deps
RUST_VER=nightly-2020-10-25
WSM=pkg/wasm_bg.wasm
OPT=pkg/wasm_opt.wasm
ASM=build/wasm/asm.js
echo "*** Building package"
# cleanup old
echo "*** Cleaning old builds"
rm -rf ./build ./pkg
mkdir -p build/wasm
# copy our package interfaces
echo "*** Copying package sources"
cp package.json build/
cp src/index.d.ts src/*.js build/
cp src/wasm/* build/wasm/
# build new via wasm-pack
echo "*** Building WASM output"
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
../../bindgen/wasm-bindgen target/wasm32-unknown-unknown/release/wasm.wasm --out-dir pkg --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 = /module.exports = (wbg) => /' $ASM
rm -rf build/wasm/*-e
+48
View File
@@ -0,0 +1,48 @@
#!/usr/bin/env bash
# Copyright 2019-2021 @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
source ../scripts/rust-version.sh
WSM=bytes/wasm_bg.wasm
OPT=bytes/wasm_opt.wasm
ASM=wasm-crypto-asmjs/build/cjs/data.js
# build new via wasm-pack
echo "*** Building Rust sources"
cd wasm-crypto
if [ "$RUST_VER" == "stable" ]; then
RUSTC_BOOTSTRAP=1 cargo build --target wasm32-unknown-unknown --release -Z build-std=std,panic_abort
else
rustup run $RUST_VER xargo build --target wasm32-unknown-unknown --release
fi
cd ..
echo "*** Converting to WASM"
../bindgen/wasm-bindgen wasm-crypto/target/wasm32-unknown-unknown/release/wasm.wasm --out-dir bytes --target web
# optimise
echo "*** Optimising WASM output"
../binaryen/bin/wasm-opt $WSM -Os -o $OPT
# convert wasm to base64 structure
echo "*** Packing WASM into baseX"
node ../scripts/pack-wasm-base.cjs
# 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/cjs/*-e
rm -rf wasm-crypto-wasm/build/cjs/*-e
+19 -6
View File
@@ -1,17 +1,30 @@
#!/usr/bin/env bash
# Copyright 2019-2020 @polkadot/wasm authors & contributors
# Copyright 2019-2021 @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 "*** Building packages"
cd packages/wasm-crypto
echo "*** Building JavaScript"
./scripts/build-js.sh
../../scripts/build-package.sh
echo "*** Building WASM"
cd packages
../scripts/build-wasm.sh
yarn test:wasm:js
ls -alR build
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 ../..
cd ..
yarn build:rollup
+10
View File
@@ -0,0 +1,10 @@
#!/usr/bin/env bash
# Copyright 2019-2021 @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
+4 -3
View File
@@ -1,14 +1,15 @@
#!/usr/bin/env bash
# Copyright 2019-2020 @polkadot/wasm authors & contributors
# Copyright 2019-2021 @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 "*** Cleaning packages"
./scripts/clean-js.sh
echo "*** Cleaning wasm"
cd packages/wasm-crypto
rm -rf build
cargo clean
cd ../..
+5 -14
View File
@@ -1,12 +1,11 @@
#!/usr/bin/env bash
# Copyright 2019-2020 @polkadot/wasm authors & contributors
# Copyright 2019-2021 @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 build-package
RUST_VER=nightly-2020-10-25
source ./scripts/rust-version.sh
BINARYEN_REPO=https://github.com/WebAssembly/binaryen
BINARYEN_VER=version_97
@@ -24,12 +23,10 @@ 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 [ "$RUST_VER" != "stable" ]; then
cargo install xargo
fi
if [[ "$unamestr" == 'Linux' ]]; then
echo "*** Detected Linux"
@@ -59,9 +56,3 @@ if [ ! -d "bindgen" ]; then
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
+25
View File
@@ -0,0 +1,25 @@
// Copyright 2019-2021 @polkadot/wasm authors & contributors
// SPDX-License-Identifier: Apache-2.0
const fflate = require('fflate/node');
const fs = require('fs');
const { formatNumber } = require('@polkadot/util');
const W_NAME = 'wasm-crypto-wasm';
const data = fs.readFileSync('./bytes/wasm_opt.wasm');
const compressed = Buffer.from(fflate.zlibSync(data, { level: 9 }));
console.log(`*** Compressed WASM: ${formatNumber(data.length)} -> ${formatNumber(compressed.length)} (${(100 * compressed.length / data.length).toFixed(2)}%)`);
fs.writeFileSync(`./${W_NAME}/build/cjs/bytes.js`, `// Copyright 2019-2021 @polkadot/${W_NAME} authors & contributors
// SPDX-License-Identifier: Apache-2.0
// Generated as part of the build, do not edit
const sizeCompressed = ${compressed.length};
const sizeUncompressed = ${data.length};
const bytes = '${compressed.toString('base64')}';
module.exports = { bytes, sizeCompressed, sizeUncompressed };
`);
-11
View File
@@ -1,11 +0,0 @@
// Copyright 2019-2020 @polkadot/wasm authors & contributors
// SPDX-License-Identifier: Apache-2.0
const fs = require('fs');
const buffer = fs.readFileSync('./pkg/wasm_opt.wasm');
fs.writeFileSync('./build/wasm/bytes.js', `// Generated as part of the build, do not edit
module.exports = Buffer.from('${buffer.toString('base64')}', 'base64');
`);
+7
View File
@@ -0,0 +1,7 @@
#!/usr/bin/env bash
# Copyright 2019-2021 @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.
RUST_VER=nightly-2021-12-02
# RUST_VER=stable
+5 -1
View File
@@ -1,5 +1,5 @@
{
"extends": "@polkadot/dev/config/tsconfig",
"extends": "@polkadot/dev/config/tsconfig.json",
"exclude": [
"build/**/*",
"**/build/**/*"
@@ -7,6 +7,10 @@
"compilerOptions": {
"baseUrl": ".",
"paths": {
"@polkadot/wasm-crypto-asmjs/packageInfo": [ "packages/wasm-crypto-asmjs/src/packageInfo" ],
"@polkadot/wasm-crypto-asmjs": [ "packages/wasm-crypto-asmjs/src/data" ],
"@polkadot/wasm-crypto-wasm/packageInfo": [ "packages/wasm-crypto-wasm/src/packageInfo" ],
"@polkadot/wasm-crypto-wasm": [ "packages/wasm-crypto-wasm/src/data" ],
"@polkadot/wasm-crypto": [ "packages/wasm-crypto/src" ]
},
"skipLibCheck": true,
+3710 -4368
View File
File diff suppressed because it is too large Load Diff