Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b29f959dda | ||
|
|
7a5ec9d347 | ||
|
|
28ddad0549 | ||
|
|
615746a323 | ||
|
|
e49d5a3219 | ||
|
|
a31f7cac0d | ||
|
|
9b65fe6c86 | ||
|
|
3b5dcd41d9 | ||
|
|
f4db1385fc | ||
|
|
1b844254fe | ||
|
|
bf924e5da0 | ||
|
|
da37be391e | ||
|
|
2a44054387 | ||
|
|
4c85c4d336 | ||
|
|
03030ae93f | ||
|
|
ed438e8877 | ||
|
|
e7700787b2 | ||
|
|
6cccb7b9b0 | ||
|
|
f8678ed024 | ||
|
|
9b48e3dd36 | ||
|
|
f5db698705 | ||
|
|
2a24642220 | ||
|
|
5cd8ea6926 | ||
|
|
633b33430a | ||
|
|
341e57eeb5 | ||
|
|
2a9b79f086 | ||
|
|
fc5a7bf9ce | ||
|
|
fbb57dc9ca | ||
|
|
2358984605 | ||
|
|
28ae0b8963 | ||
|
|
4e316440b9 | ||
|
|
f9c65c8fb2 | ||
|
|
d3c5d1a617 | ||
|
|
b57cdaef14 | ||
|
|
1f2ad4ea36 | ||
|
|
4c3537d869 | ||
|
|
6f1ff9f276 | ||
|
|
34ab9d3354 | ||
|
|
635aeb1465 | ||
|
|
adf9b57dd6 | ||
|
|
669aa9f53b | ||
|
|
399d439aa7 | ||
|
|
29ecaa46c2 | ||
|
|
614c88e6c3 | ||
|
|
49ab036894 | ||
|
|
c552006b38 | ||
|
|
b01f35cde5 | ||
|
|
a85615f12b | ||
|
|
04285faf55 | ||
|
|
962b880fa6 | ||
|
|
e75ebd07a0 | ||
|
|
a601a8d034 | ||
|
|
13826c371e | ||
|
|
0355bb4769 | ||
|
|
2e14af5693 | ||
|
|
135b99ee63 | ||
|
|
f4851dc4d8 | ||
|
|
8f31b00608 | ||
|
|
0ac2977788 | ||
|
|
ef30070360 | ||
|
|
3b9ac03b70 | ||
|
|
84f2e0da77 | ||
|
|
b0a5eaf20e | ||
|
|
1fec165bac | ||
|
|
5838ac1e69 | ||
|
|
dfd83c2463 | ||
|
|
b25d8dfd4b | ||
|
|
21ee330e9b | ||
|
|
599f6300c0 | ||
|
|
1916a4e10c | ||
|
|
0fd619c4f7 | ||
|
|
54c600a676 | ||
|
|
763cd473b4 | ||
|
|
e435c1e7b8 | ||
|
|
59bf7495b4 | ||
|
|
ec36f55ed8 | ||
|
|
03f38cb07b | ||
|
|
36719449c2 | ||
|
|
efb0c51648 | ||
|
|
2faf907296 | ||
|
|
33b77fed37 | ||
|
|
8cc2a167e1 | ||
|
|
09f33968b9 |
@@ -6,3 +6,6 @@
|
|||||||
|
|
||||||
4.0.2
|
4.0.2
|
||||||
4.1.2
|
4.1.2
|
||||||
|
|
||||||
|
6.1.2
|
||||||
|
6.1.3
|
||||||
+1
-1
@@ -8,7 +8,7 @@ module.exports = {
|
|||||||
ignorePatterns: [
|
ignorePatterns: [
|
||||||
...base.ignorePatterns,
|
...base.ignorePatterns,
|
||||||
'**/target/*',
|
'**/target/*',
|
||||||
'packages/bytes/*'
|
'**/build-wasm/*'
|
||||||
],
|
],
|
||||||
parserOptions: {
|
parserOptions: {
|
||||||
...base.parserOptions,
|
...base.parserOptions,
|
||||||
|
|||||||
@@ -0,0 +1,50 @@
|
|||||||
|
<!--
|
||||||
|
|
||||||
|
For general support, howto, coding and bundling questions, please use the Substrate & Polkadot StackExchange at https://substrate.stackexchange.com/ and get other ecosystem developers involved. This issues in this repository are meant for the tracking of feature requests and bug reports.
|
||||||
|
|
||||||
|
While all issues are looked at non-bug and non-features would take quite a bit longer to get to and may yield less than satisfactory responses in this format.
|
||||||
|
|
||||||
|
Additionally, please ensure you have done a search on the existing and closed issues before logging a new request. This saves time on all sides.
|
||||||
|
|
||||||
|
-->
|
||||||
|
|
||||||
|
|
||||||
|
* **I'm submitting a ...**
|
||||||
|
|
||||||
|
<!--- Try and classify your actual report -->
|
||||||
|
|
||||||
|
- [ ] Bug report
|
||||||
|
- [ ] Feature request
|
||||||
|
- [ ] Support request (please bear the comments above in mind)
|
||||||
|
- [ ] Other
|
||||||
|
|
||||||
|
|
||||||
|
* **What is the current behavior and expected behavior?**
|
||||||
|
|
||||||
|
<!--- If you're describing a bug, tell us what should happen -->
|
||||||
|
<!--- If you're suggesting a change/improvement, tell us how it should work -->
|
||||||
|
|
||||||
|
|
||||||
|
* **What is the motivation for changing the behavior?**
|
||||||
|
|
||||||
|
<!--- Not obligatory, but suggest a motivation for the request -->
|
||||||
|
<!--- or ideas how to implement the addition or change -->
|
||||||
|
|
||||||
|
|
||||||
|
* **Please tell us about your environment:**
|
||||||
|
|
||||||
|
<!--- Include as many relevant details about the environment you experienced the issue in -->
|
||||||
|
<!--- Also snsure that you have tested against the latest stable releases if a bug -->
|
||||||
|
|
||||||
|
- Version:
|
||||||
|
- Environment:
|
||||||
|
|
||||||
|
- [ ] Node.js
|
||||||
|
- [ ] Browser
|
||||||
|
- [ ] Other (limited support for other environments available)
|
||||||
|
|
||||||
|
- Language:
|
||||||
|
|
||||||
|
- [ ] JavaScript
|
||||||
|
- [ ] TypeScript
|
||||||
|
- [ ] Other
|
||||||
@@ -1,7 +1,11 @@
|
|||||||
binaryen/
|
binaryen/
|
||||||
bindgen/
|
bindgen/
|
||||||
build/
|
build/
|
||||||
|
build-cjs/
|
||||||
|
build-esm/
|
||||||
|
build-deno/
|
||||||
build-docs/
|
build-docs/
|
||||||
|
build-wasm/
|
||||||
bytes/
|
bytes/
|
||||||
coverage/
|
coverage/
|
||||||
docs/.vuepress/dist/
|
docs/.vuepress/dist/
|
||||||
|
|||||||
@@ -1,5 +1,38 @@
|
|||||||
# CHANGELOG
|
# CHANGELOG
|
||||||
|
|
||||||
|
## 6.1.3 Jun 21, 2022
|
||||||
|
|
||||||
|
Changes:
|
||||||
|
|
||||||
|
- Fix bundle publish (from dev bump)
|
||||||
|
|
||||||
|
|
||||||
|
## 6.1.2 Jun 21, 2022
|
||||||
|
|
||||||
|
Changes:
|
||||||
|
|
||||||
|
- Adjust assert usage in all internal non-test code
|
||||||
|
- Additional comments where missing
|
||||||
|
|
||||||
|
|
||||||
|
## 6.1.1 May 13, 2022
|
||||||
|
|
||||||
|
Changes:
|
||||||
|
|
||||||
|
- Adjust init, allow RN with default ASM.js-only fallback
|
||||||
|
- Split `wasm-{bridge, util}` packages for internal re-use
|
||||||
|
|
||||||
|
|
||||||
|
## 6.0.1 Apr 9, 2022
|
||||||
|
|
||||||
|
- **Breaking change** In this major version the commonjs outputs are moved to a sub-folder. Since the `export` map and `main` field in `package.json` does reflect this change, there should be no usage changes. However the packages here will all need to be on the same version for internal linkage.
|
||||||
|
|
||||||
|
Changes:
|
||||||
|
|
||||||
|
- Update ed25519 secret key format return description
|
||||||
|
- Output commonjs files under the `cjs/**` root
|
||||||
|
|
||||||
|
|
||||||
## 5.1.1 Mar 27, 2022
|
## 5.1.1 Mar 27, 2022
|
||||||
|
|
||||||
Changes:
|
Changes:
|
||||||
|
|||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
394 Jaco 5.1.1 (#322)
|
436 Jaco 6.1.3 (#371)
|
||||||
1 Evgeny Fixed type (#121)
|
1 Evgeny Fixed type (#121)
|
||||||
1 Shunfan Zhou Support sr25519 agreement (#209)
|
1 Shunfan Zhou Support sr25519 agreement (#209)
|
||||||
1 Steve Degosserie Expose Schnorrkel's VRF capabilities (#170)
|
1 Steve Degosserie Expose Schnorrkel's VRF capabilities (#170)
|
||||||
|
|||||||
+2
-2
@@ -6,8 +6,8 @@ const config = require('@polkadot/dev/config/jest.cjs');
|
|||||||
module.exports = {
|
module.exports = {
|
||||||
...config,
|
...config,
|
||||||
moduleNameMapper: {
|
moduleNameMapper: {
|
||||||
'@polkadot/wasm-crypto-(asmjs|wasm)(.*)$': '<rootDir>/packages/wasm-crypto-$1/build/$2',
|
'@polkadot/wasm-crypto-(init|asmjs|wasm)(.*)$': '<rootDir>/packages/wasm-crypto-$1/build/$2',
|
||||||
// eslint-disable-next-line sort-keys
|
// eslint-disable-next-line sort-keys
|
||||||
'@polkadot/wasm-crypto(.*)$': '<rootDir>/packages/wasm-crypto/src/$1'
|
'@polkadot/wasm-(bridge|crypto|util)(.*)$': '<rootDir>/packages/wasm-$1/build/$2'
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
+9
-9
@@ -10,7 +10,7 @@
|
|||||||
"url": "https://github.com/polkadot-js/wasm.git"
|
"url": "https://github.com/polkadot-js/wasm.git"
|
||||||
},
|
},
|
||||||
"sideEffects": false,
|
"sideEffects": false,
|
||||||
"version": "5.1.1",
|
"version": "6.1.3",
|
||||||
"workspaces": [
|
"workspaces": [
|
||||||
"packages/*"
|
"packages/*"
|
||||||
],
|
],
|
||||||
@@ -24,19 +24,19 @@
|
|||||||
"clean": "./scripts/clean.sh",
|
"clean": "./scripts/clean.sh",
|
||||||
"lint": "polkadot-dev-run-lint",
|
"lint": "polkadot-dev-run-lint",
|
||||||
"postinstall": "polkadot-dev-yarn-only",
|
"postinstall": "polkadot-dev-yarn-only",
|
||||||
"test": "yarn test:wasm:rust",
|
"test": "yarn test:wasm-crypto:rust",
|
||||||
"test:wasm:js": "yarn test:wasm:js:jest && yarn test:wasm:js:node",
|
"test:wasm-crypto:js": "yarn test:wasm-crypto:js:jest && yarn test:wasm-crypto:js:node",
|
||||||
"test:wasm:js:jest": "polkadot-dev-run-test ./test/jest.spec.js",
|
"test:wasm-crypto:js:jest": "polkadot-dev-run-test ./test/jest.spec.js",
|
||||||
"test:wasm:js:node": "cd packages/wasm-crypto && node ./test/wasm.cjs && node ./test/asm.cjs",
|
"test:wasm-crypto: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 -- --test-threads=1 --nocapture"
|
"test:wasm-crypto:rust": "cd packages/wasm-crypto && RUST_BACKTRACE=full cargo test --release -- --test-threads=1 --nocapture"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@babel/core": "^7.17.8",
|
"@babel/core": "^7.18.5",
|
||||||
"@polkadot/dev": "^0.65.101",
|
"@polkadot/dev": "^0.67.20",
|
||||||
"fflate": "^0.7.3",
|
"fflate": "^0.7.3",
|
||||||
"override-require": "^1.1.1"
|
"override-require": "^1.1.1"
|
||||||
},
|
},
|
||||||
"resolutions": {
|
"resolutions": {
|
||||||
"typescript": "^4.6.3"
|
"typescript": "^4.7.4"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,201 @@
|
|||||||
|
Apache License
|
||||||
|
Version 2.0, January 2004
|
||||||
|
http://www.apache.org/licenses/
|
||||||
|
|
||||||
|
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||||
|
|
||||||
|
1. Definitions.
|
||||||
|
|
||||||
|
"License" shall mean the terms and conditions for use, reproduction,
|
||||||
|
and distribution as defined by Sections 1 through 9 of this document.
|
||||||
|
|
||||||
|
"Licensor" shall mean the copyright owner or entity authorized by
|
||||||
|
the copyright owner that is granting the License.
|
||||||
|
|
||||||
|
"Legal Entity" shall mean the union of the acting entity and all
|
||||||
|
other entities that control, are controlled by, or are under common
|
||||||
|
control with that entity. For the purposes of this definition,
|
||||||
|
"control" means (i) the power, direct or indirect, to cause the
|
||||||
|
direction or management of such entity, whether by contract or
|
||||||
|
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||||
|
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||||
|
|
||||||
|
"You" (or "Your") shall mean an individual or Legal Entity
|
||||||
|
exercising permissions granted by this License.
|
||||||
|
|
||||||
|
"Source" form shall mean the preferred form for making modifications,
|
||||||
|
including but not limited to software source code, documentation
|
||||||
|
source, and configuration files.
|
||||||
|
|
||||||
|
"Object" form shall mean any form resulting from mechanical
|
||||||
|
transformation or translation of a Source form, including but
|
||||||
|
not limited to compiled object code, generated documentation,
|
||||||
|
and conversions to other media types.
|
||||||
|
|
||||||
|
"Work" shall mean the work of authorship, whether in Source or
|
||||||
|
Object form, made available under the License, as indicated by a
|
||||||
|
copyright notice that is included in or attached to the work
|
||||||
|
(an example is provided in the Appendix below).
|
||||||
|
|
||||||
|
"Derivative Works" shall mean any work, whether in Source or Object
|
||||||
|
form, that is based on (or derived from) the Work and for which the
|
||||||
|
editorial revisions, annotations, elaborations, or other modifications
|
||||||
|
represent, as a whole, an original work of authorship. For the purposes
|
||||||
|
of this License, Derivative Works shall not include works that remain
|
||||||
|
separable from, or merely link (or bind by name) to the interfaces of,
|
||||||
|
the Work and Derivative Works thereof.
|
||||||
|
|
||||||
|
"Contribution" shall mean any work of authorship, including
|
||||||
|
the original version of the Work and any modifications or additions
|
||||||
|
to that Work or Derivative Works thereof, that is intentionally
|
||||||
|
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||||
|
or by an individual or Legal Entity authorized to submit on behalf of
|
||||||
|
the copyright owner. For the purposes of this definition, "submitted"
|
||||||
|
means any form of electronic, verbal, or written communication sent
|
||||||
|
to the Licensor or its representatives, including but not limited to
|
||||||
|
communication on electronic mailing lists, source code control systems,
|
||||||
|
and issue tracking systems that are managed by, or on behalf of, the
|
||||||
|
Licensor for the purpose of discussing and improving the Work, but
|
||||||
|
excluding communication that is conspicuously marked or otherwise
|
||||||
|
designated in writing by the copyright owner as "Not a Contribution."
|
||||||
|
|
||||||
|
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||||
|
on behalf of whom a Contribution has been received by Licensor and
|
||||||
|
subsequently incorporated within the Work.
|
||||||
|
|
||||||
|
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||||
|
this License, each Contributor hereby grants to You a perpetual,
|
||||||
|
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||||
|
copyright license to reproduce, prepare Derivative Works of,
|
||||||
|
publicly display, publicly perform, sublicense, and distribute the
|
||||||
|
Work and such Derivative Works in Source or Object form.
|
||||||
|
|
||||||
|
3. Grant of Patent License. Subject to the terms and conditions of
|
||||||
|
this License, each Contributor hereby grants to You a perpetual,
|
||||||
|
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||||
|
(except as stated in this section) patent license to make, have made,
|
||||||
|
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||||
|
where such license applies only to those patent claims licensable
|
||||||
|
by such Contributor that are necessarily infringed by their
|
||||||
|
Contribution(s) alone or by combination of their Contribution(s)
|
||||||
|
with the Work to which such Contribution(s) was submitted. If You
|
||||||
|
institute patent litigation against any entity (including a
|
||||||
|
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||||
|
or a Contribution incorporated within the Work constitutes direct
|
||||||
|
or contributory patent infringement, then any patent licenses
|
||||||
|
granted to You under this License for that Work shall terminate
|
||||||
|
as of the date such litigation is filed.
|
||||||
|
|
||||||
|
4. Redistribution. You may reproduce and distribute copies of the
|
||||||
|
Work or Derivative Works thereof in any medium, with or without
|
||||||
|
modifications, and in Source or Object form, provided that You
|
||||||
|
meet the following conditions:
|
||||||
|
|
||||||
|
(a) You must give any other recipients of the Work or
|
||||||
|
Derivative Works a copy of this License; and
|
||||||
|
|
||||||
|
(b) You must cause any modified files to carry prominent notices
|
||||||
|
stating that You changed the files; and
|
||||||
|
|
||||||
|
(c) You must retain, in the Source form of any Derivative Works
|
||||||
|
that You distribute, all copyright, patent, trademark, and
|
||||||
|
attribution notices from the Source form of the Work,
|
||||||
|
excluding those notices that do not pertain to any part of
|
||||||
|
the Derivative Works; and
|
||||||
|
|
||||||
|
(d) If the Work includes a "NOTICE" text file as part of its
|
||||||
|
distribution, then any Derivative Works that You distribute must
|
||||||
|
include a readable copy of the attribution notices contained
|
||||||
|
within such NOTICE file, excluding those notices that do not
|
||||||
|
pertain to any part of the Derivative Works, in at least one
|
||||||
|
of the following places: within a NOTICE text file distributed
|
||||||
|
as part of the Derivative Works; within the Source form or
|
||||||
|
documentation, if provided along with the Derivative Works; or,
|
||||||
|
within a display generated by the Derivative Works, if and
|
||||||
|
wherever such third-party notices normally appear. The contents
|
||||||
|
of the NOTICE file are for informational purposes only and
|
||||||
|
do not modify the License. You may add Your own attribution
|
||||||
|
notices within Derivative Works that You distribute, alongside
|
||||||
|
or as an addendum to the NOTICE text from the Work, provided
|
||||||
|
that such additional attribution notices cannot be construed
|
||||||
|
as modifying the License.
|
||||||
|
|
||||||
|
You may add Your own copyright statement to Your modifications and
|
||||||
|
may provide additional or different license terms and conditions
|
||||||
|
for use, reproduction, or distribution of Your modifications, or
|
||||||
|
for any such Derivative Works as a whole, provided Your use,
|
||||||
|
reproduction, and distribution of the Work otherwise complies with
|
||||||
|
the conditions stated in this License.
|
||||||
|
|
||||||
|
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||||
|
any Contribution intentionally submitted for inclusion in the Work
|
||||||
|
by You to the Licensor shall be under the terms and conditions of
|
||||||
|
this License, without any additional terms or conditions.
|
||||||
|
Notwithstanding the above, nothing herein shall supersede or modify
|
||||||
|
the terms of any separate license agreement you may have executed
|
||||||
|
with Licensor regarding such Contributions.
|
||||||
|
|
||||||
|
6. Trademarks. This License does not grant permission to use the trade
|
||||||
|
names, trademarks, service marks, or product names of the Licensor,
|
||||||
|
except as required for reasonable and customary use in describing the
|
||||||
|
origin of the Work and reproducing the content of the NOTICE file.
|
||||||
|
|
||||||
|
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||||
|
agreed to in writing, Licensor provides the Work (and each
|
||||||
|
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||||
|
implied, including, without limitation, any warranties or conditions
|
||||||
|
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||||
|
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||||
|
appropriateness of using or redistributing the Work and assume any
|
||||||
|
risks associated with Your exercise of permissions under this License.
|
||||||
|
|
||||||
|
8. Limitation of Liability. In no event and under no legal theory,
|
||||||
|
whether in tort (including negligence), contract, or otherwise,
|
||||||
|
unless required by applicable law (such as deliberate and grossly
|
||||||
|
negligent acts) or agreed to in writing, shall any Contributor be
|
||||||
|
liable to You for damages, including any direct, indirect, special,
|
||||||
|
incidental, or consequential damages of any character arising as a
|
||||||
|
result of this License or out of the use or inability to use the
|
||||||
|
Work (including but not limited to damages for loss of goodwill,
|
||||||
|
work stoppage, computer failure or malfunction, or any and all
|
||||||
|
other commercial damages or losses), even if such Contributor
|
||||||
|
has been advised of the possibility of such damages.
|
||||||
|
|
||||||
|
9. Accepting Warranty or Additional Liability. While redistributing
|
||||||
|
the Work or Derivative Works thereof, You may choose to offer,
|
||||||
|
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||||
|
or other liability obligations and/or rights consistent with this
|
||||||
|
License. However, in accepting such obligations, You may act only
|
||||||
|
on Your own behalf and on Your sole responsibility, not on behalf
|
||||||
|
of any other Contributor, and only if You agree to indemnify,
|
||||||
|
defend, and hold each Contributor harmless for any liability
|
||||||
|
incurred by, or claims asserted against, such Contributor by reason
|
||||||
|
of your accepting any such warranty or additional liability.
|
||||||
|
|
||||||
|
END OF TERMS AND CONDITIONS
|
||||||
|
|
||||||
|
APPENDIX: How to apply the Apache License to your work.
|
||||||
|
|
||||||
|
To apply the Apache License to your work, attach the following
|
||||||
|
boilerplate notice, with the fields enclosed by brackets "[]"
|
||||||
|
replaced with your own identifying information. (Don't include
|
||||||
|
the brackets!) The text should be enclosed in the appropriate
|
||||||
|
comment syntax for the file format. We also recommend that a
|
||||||
|
file or class name and description of purpose be included on the
|
||||||
|
same "printed page" as the copyright notice for easier
|
||||||
|
identification within third-party archives.
|
||||||
|
|
||||||
|
Copyright [yyyy] [name of copyright owner]
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
# @polkadot/wasm-bridge
|
||||||
@@ -0,0 +1,36 @@
|
|||||||
|
{
|
||||||
|
"author": "Jaco Greeff <jacogr@gmail.com>",
|
||||||
|
"bugs": "https://github.com/polkadot-js/wasm/issues",
|
||||||
|
"contributors": [],
|
||||||
|
"description": "A bridge layer between JS and Wasm",
|
||||||
|
"engines": {
|
||||||
|
"node": ">=14.0.0"
|
||||||
|
},
|
||||||
|
"homepage": "https://github.com/polkadot-js/wasm/tree/master/packages/wasm-bridge#readme",
|
||||||
|
"license": "Apache-2.0",
|
||||||
|
"maintainers": [],
|
||||||
|
"name": "@polkadot/wasm-bridge",
|
||||||
|
"repository": {
|
||||||
|
"directory": "packages/wasm-bridge",
|
||||||
|
"type": "git",
|
||||||
|
"url": "https://github.com/polkadot-js/wasm.git"
|
||||||
|
},
|
||||||
|
"sideEffects": [
|
||||||
|
"./detectPackage.js",
|
||||||
|
"./detectPackage.cjs"
|
||||||
|
],
|
||||||
|
"type": "module",
|
||||||
|
"version": "6.1.3",
|
||||||
|
"main": "index.js",
|
||||||
|
"dependencies": {
|
||||||
|
"@babel/runtime": "^7.18.3"
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"@polkadot/util": "^9.5.1",
|
||||||
|
"@polkadot/x-randomvalues": "^9.5.1"
|
||||||
|
},
|
||||||
|
"peerDependencies": {
|
||||||
|
"@polkadot/util": "*",
|
||||||
|
"@polkadot/x-randomvalues": "*"
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,218 @@
|
|||||||
|
// Copyright 2019-2022 @polkadot/wasm-bridge authors & contributors
|
||||||
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
|
// A number of functions are "unsafe" and purposefully so - it is
|
||||||
|
// assumed that where the bridge is used, it is correctly wrapped
|
||||||
|
// in a safeguard (see withWasm in the wasm-crypto package) which
|
||||||
|
// then ensures that the internal wasm instance here is available
|
||||||
|
/* eslint-disable @typescript-eslint/no-non-null-assertion */
|
||||||
|
|
||||||
|
import type { BridgeBase, InitFn, InitPromise, WasmBaseInstance } from './types';
|
||||||
|
|
||||||
|
import { stringToU8a, u8aToString } from '@polkadot/util';
|
||||||
|
|
||||||
|
import { Wbg } from './wbg';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @name Bridge
|
||||||
|
* @description
|
||||||
|
* Creates a bridge between the JS and WASM environments.
|
||||||
|
*
|
||||||
|
* For any bridge it is passed an function white is then called internally at the
|
||||||
|
* time of initialization. This affectively implements the layer between WASM and
|
||||||
|
* the native environment, providing all the plumbing needed for the Wbg classes.
|
||||||
|
*/
|
||||||
|
export class Bridge<C extends WasmBaseInstance> implements BridgeBase<C> {
|
||||||
|
#cachegetInt32: Int32Array | null;
|
||||||
|
#cachegetUint8: Uint8Array | null;
|
||||||
|
#createWasm: InitFn<C>;
|
||||||
|
#heap: unknown[];
|
||||||
|
#heapNext: number;
|
||||||
|
#wasm: C | null;
|
||||||
|
#wasmError: string | null;
|
||||||
|
#wasmPromise: InitPromise<C> | null;
|
||||||
|
#wbg: WebAssembly.ModuleImports;
|
||||||
|
#type: 'asm' | 'wasm' | 'none';
|
||||||
|
|
||||||
|
constructor (createWasm: InitFn<C>) {
|
||||||
|
this.#createWasm = createWasm;
|
||||||
|
this.#cachegetInt32 = null;
|
||||||
|
this.#cachegetUint8 = null;
|
||||||
|
this.#heap = new Array(32)
|
||||||
|
.fill(undefined)
|
||||||
|
.concat(undefined, null, true, false);
|
||||||
|
this.#heapNext = this.#heap.length;
|
||||||
|
this.#type = 'none';
|
||||||
|
this.#wasm = null;
|
||||||
|
this.#wasmError = null;
|
||||||
|
this.#wasmPromise = null;
|
||||||
|
this.#wbg = { ...new Wbg(this) };
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @description Returns the init error */
|
||||||
|
get error (): string | null {
|
||||||
|
return this.#wasmError;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @description Returns the init type */
|
||||||
|
get type (): 'asm' | 'wasm' | 'none' {
|
||||||
|
return this.#type;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @description Returns the created wbg interface */
|
||||||
|
get wbg (): WebAssembly.ModuleImports {
|
||||||
|
return this.#wbg;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @description Returns the created wasm interface */
|
||||||
|
get wasm (): C | null {
|
||||||
|
return this.#wasm;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @description Performs the wasm initialization */
|
||||||
|
async init (createWasm?: InitFn<C>): Promise<C | null> {
|
||||||
|
if (!this.#wasmPromise || createWasm) {
|
||||||
|
this.#wasmPromise = (createWasm || this.#createWasm)(this.#wbg);
|
||||||
|
}
|
||||||
|
|
||||||
|
const { error, type, wasm } = await this.#wasmPromise;
|
||||||
|
|
||||||
|
this.#type = type;
|
||||||
|
this.#wasm = wasm;
|
||||||
|
this.#wasmError = error;
|
||||||
|
|
||||||
|
return this.#wasm;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @internal
|
||||||
|
* @description Gets an object from the heap
|
||||||
|
*/
|
||||||
|
getObject (idx: number): unknown {
|
||||||
|
return this.#heap[idx];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @internal
|
||||||
|
* @description Removes an object from the heap
|
||||||
|
*/
|
||||||
|
dropObject (idx: number) {
|
||||||
|
if (idx < 36) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.#heap[idx] = this.#heapNext;
|
||||||
|
this.#heapNext = idx;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @internal
|
||||||
|
* @description Retrieves and removes an object to the heap
|
||||||
|
*/
|
||||||
|
takeObject (idx: number): unknown {
|
||||||
|
const ret = this.getObject(idx);
|
||||||
|
|
||||||
|
this.dropObject(idx);
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @internal
|
||||||
|
* @description Adds an object to the heap
|
||||||
|
*/
|
||||||
|
addObject (obj: unknown): number {
|
||||||
|
if (this.#heapNext === this.#heap.length) {
|
||||||
|
this.#heap.push(this.#heap.length + 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
const idx = this.#heapNext;
|
||||||
|
|
||||||
|
this.#heapNext = this.#heap[idx] as number;
|
||||||
|
this.#heap[idx] = obj;
|
||||||
|
|
||||||
|
return idx;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @internal
|
||||||
|
* @description Retrieve an Int32 in the WASM interface
|
||||||
|
*/
|
||||||
|
getInt32 (): Int32Array {
|
||||||
|
if (this.#cachegetInt32 === null || this.#cachegetInt32.buffer !== this.#wasm!.memory.buffer) {
|
||||||
|
this.#cachegetInt32 = new Int32Array(this.#wasm!.memory.buffer);
|
||||||
|
}
|
||||||
|
|
||||||
|
return this.#cachegetInt32;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @internal
|
||||||
|
* @description Retrieve an Uint8Array in the WASM interface
|
||||||
|
*/
|
||||||
|
getUint8 (): Uint8Array {
|
||||||
|
if (this.#cachegetUint8 === null || this.#cachegetUint8.buffer !== this.#wasm!.memory.buffer) {
|
||||||
|
this.#cachegetUint8 = new Uint8Array(this.#wasm!.memory.buffer);
|
||||||
|
}
|
||||||
|
|
||||||
|
return this.#cachegetUint8;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @internal
|
||||||
|
* @description Retrieves an Uint8Array in the WASM interface
|
||||||
|
*/
|
||||||
|
getU8a (ptr: number, len: number): Uint8Array {
|
||||||
|
return this.getUint8().subarray(ptr / 1, ptr / 1 + len);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @internal
|
||||||
|
* @description Retrieves a string in the WASM interface
|
||||||
|
*/
|
||||||
|
getString (ptr: number, len: number): string {
|
||||||
|
return u8aToString(this.getU8a(ptr, len));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @internal
|
||||||
|
* @description Allocates an Uint8Array in the WASM interface
|
||||||
|
*/
|
||||||
|
allocU8a (arg: Uint8Array): [number, number] {
|
||||||
|
const ptr = this.#wasm!.__wbindgen_malloc(arg.length * 1);
|
||||||
|
|
||||||
|
this.getUint8().set(arg, ptr / 1);
|
||||||
|
|
||||||
|
return [ptr, arg.length];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @internal
|
||||||
|
* @description Allocates a string in the WASM interface
|
||||||
|
*/
|
||||||
|
allocString (arg: string): [number, number] {
|
||||||
|
return this.allocU8a(stringToU8a(arg));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @internal
|
||||||
|
* @description Retrieves an Uint8Array from the WASM interface
|
||||||
|
*/
|
||||||
|
resultU8a (): Uint8Array {
|
||||||
|
const r0 = this.getInt32()[8 / 4 + 0];
|
||||||
|
const r1 = this.getInt32()[8 / 4 + 1];
|
||||||
|
const ret = this.getU8a(r0, r1).slice();
|
||||||
|
|
||||||
|
this.#wasm!.__wbindgen_free(r0, r1 * 1);
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @internal
|
||||||
|
* @description Retrieve a string from the WASM interface
|
||||||
|
*/
|
||||||
|
resultString (): string {
|
||||||
|
return u8aToString(this.resultU8a());
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
// Copyright 2019-2022 @polkadot/wasm-bridge authors & contributors
|
||||||
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
|
export * from './bridge';
|
||||||
|
export * from './init';
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
// Copyright 2017-2022 @polkadot/wasm-bridge authors & contributors
|
||||||
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
|
export default [];
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
// Copyright 2017-2022 @polkadot/wasm-bridge authors & contributors
|
||||||
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
|
// Do not edit, auto-generated by @polkadot/dev
|
||||||
|
|
||||||
|
import { detectPackage } from '@polkadot/util';
|
||||||
|
|
||||||
|
import others from './detectOther';
|
||||||
|
import { packageInfo } from './packageInfo';
|
||||||
|
|
||||||
|
detectPackage(packageInfo, null, others);
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
// Copyright 2019-2022 @polkadot/wasm-bridge authors & contributors
|
||||||
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
|
import './detectPackage';
|
||||||
|
|
||||||
|
export * from './bundle';
|
||||||
@@ -0,0 +1,47 @@
|
|||||||
|
// Copyright 2019-2022 @polkadot/wasm-bundle authors & contributors
|
||||||
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
|
import type { InitFn, InitPromise, InitResult, WasmBaseInstance } from './types';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @name createWasmFn
|
||||||
|
* @description
|
||||||
|
* Create a WASM (or ASM.js) creator interface based on the supplied information.
|
||||||
|
*
|
||||||
|
* It will attempt to create a WASM interface first and if this fails or is not available in
|
||||||
|
* the environment, will fallback to attempting to create an ASM.js interface.
|
||||||
|
*/
|
||||||
|
export function createWasmFn <C extends WasmBaseInstance> (root: string, wasmBytes: null | Uint8Array, asmFn: null | ((wbg: WebAssembly.ModuleImports) => C)): InitFn<C> {
|
||||||
|
return async (wbg: WebAssembly.ModuleImports): InitPromise<C> => {
|
||||||
|
const result: InitResult<C> = {
|
||||||
|
error: null,
|
||||||
|
type: 'none',
|
||||||
|
wasm: null
|
||||||
|
};
|
||||||
|
|
||||||
|
try {
|
||||||
|
if (!wasmBytes || !wasmBytes.length) {
|
||||||
|
throw new Error('No WebAssembly provided for initialization');
|
||||||
|
} else if (typeof WebAssembly !== 'object' || typeof WebAssembly.instantiate !== 'function') {
|
||||||
|
throw new Error('WebAssembly is not available in your environment');
|
||||||
|
}
|
||||||
|
|
||||||
|
const source = await WebAssembly.instantiate(wasmBytes, { wbg });
|
||||||
|
|
||||||
|
result.wasm = source.instance.exports as unknown as C;
|
||||||
|
result.type = 'wasm';
|
||||||
|
} catch (error) {
|
||||||
|
// if we have a valid supplied asm.js, return that
|
||||||
|
if (typeof asmFn === 'function') {
|
||||||
|
result.wasm = asmFn(wbg);
|
||||||
|
result.type = 'asm';
|
||||||
|
} else {
|
||||||
|
result.error = `FATAL: Unable to initialize @polkadot/wasm-${root}:: ${(error as Error).message}`;
|
||||||
|
|
||||||
|
console.error(result.error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
};
|
||||||
|
}
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
// Copyright 2019-2022 @polkadot/wasm-bridge authors & contributors
|
||||||
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
|
export * from './index';
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
// Copyright 2017-2022 @polkadot/wasm-bridge authors & contributors
|
||||||
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
|
// Do not edit, auto-generated by @polkadot/dev
|
||||||
|
|
||||||
|
export const packageInfo = { name: '@polkadot/wasm-bridge', path: 'auto', type: 'auto', version: '6.1.3' };
|
||||||
@@ -0,0 +1,41 @@
|
|||||||
|
// Copyright 2019-2022 @polkadot/wasm-bridge authors & contributors
|
||||||
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
|
export declare interface InitResult<C extends WasmBaseInstance> {
|
||||||
|
error: string | null;
|
||||||
|
type: 'asm' | 'wasm' | 'none';
|
||||||
|
wasm: C | null;
|
||||||
|
}
|
||||||
|
|
||||||
|
export type InitPromise <C extends WasmBaseInstance> = Promise<InitResult<C>>;
|
||||||
|
|
||||||
|
export type InitFn <C extends WasmBaseInstance> = (wbg: WebAssembly.ModuleImports) => InitPromise<C>;
|
||||||
|
|
||||||
|
export interface BridgeBase<C extends WasmBaseInstance> extends InitResult<C> {
|
||||||
|
wbg: WebAssembly.ModuleImports;
|
||||||
|
|
||||||
|
init (createWasm?: InitFn<C>): Promise<C | null>;
|
||||||
|
getObject (idx: number): unknown;
|
||||||
|
dropObject (idx: number): void;
|
||||||
|
takeObject (idx: number): unknown;
|
||||||
|
addObject (obj: unknown): number;
|
||||||
|
getInt32 (): Int32Array;
|
||||||
|
getUint8 (): Uint8Array;
|
||||||
|
getU8a (ptr: number, len: number): Uint8Array;
|
||||||
|
getString (ptr: number, len: number): string;
|
||||||
|
allocU8a (arg: Uint8Array): [number, number];
|
||||||
|
allocString (arg: string): [number, number];
|
||||||
|
resultU8a (): Uint8Array;
|
||||||
|
resultString (): string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface WasmBaseInstance {
|
||||||
|
memory: WebAssembly.Memory;
|
||||||
|
|
||||||
|
// wbindgen functions (required and used internally)
|
||||||
|
|
||||||
|
__wbindgen_exn_store (a: number): void;
|
||||||
|
__wbindgen_free (a: number, b: number): void;
|
||||||
|
__wbindgen_malloc (a: number): number;
|
||||||
|
__wbindgen_realloc (a: number, b: number, c: number): number;
|
||||||
|
}
|
||||||
@@ -0,0 +1,84 @@
|
|||||||
|
// Copyright 2019-2022 @polkadot/wasm-bridge authors & contributors
|
||||||
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
|
import type { BridgeBase, WasmBaseInstance } from './types';
|
||||||
|
|
||||||
|
import { getRandomValues } from '@polkadot/x-randomvalues';
|
||||||
|
|
||||||
|
const DEFAULT_CRYPTO = { getRandomValues };
|
||||||
|
const DEFAULT_SELF = { crypto: DEFAULT_CRYPTO };
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @name Wbg
|
||||||
|
* @description
|
||||||
|
* This defines the internal interfaces that wasm-bindgen used to communicate
|
||||||
|
* with the host layer. None of these functions are available to the user, rather
|
||||||
|
* they are called internally from the WASM code itself.
|
||||||
|
*
|
||||||
|
* The interfaces here are exposed in the imports on the created WASM interfaces.
|
||||||
|
*
|
||||||
|
* Internally the implementation does a thin layer into the supplied bridge.
|
||||||
|
*/
|
||||||
|
export class Wbg<C extends WasmBaseInstance> {
|
||||||
|
#bridge: BridgeBase<C>;
|
||||||
|
|
||||||
|
constructor (bridge: BridgeBase<C>) {
|
||||||
|
this.#bridge = bridge;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @internal */
|
||||||
|
abort = (): never => {
|
||||||
|
throw new Error('abort');
|
||||||
|
};
|
||||||
|
|
||||||
|
/** @internal */
|
||||||
|
__wbindgen_is_undefined = (idx: number): boolean => {
|
||||||
|
return this.#bridge.getObject(idx) === undefined;
|
||||||
|
};
|
||||||
|
|
||||||
|
/** @internal */
|
||||||
|
__wbindgen_throw = (ptr: number, len: number): boolean => {
|
||||||
|
throw new Error(this.#bridge.getString(ptr, len));
|
||||||
|
};
|
||||||
|
|
||||||
|
/** @internal */
|
||||||
|
__wbg_self_1b7a39e3a92c949c = (): number => {
|
||||||
|
return this.#bridge.addObject(DEFAULT_SELF);
|
||||||
|
};
|
||||||
|
|
||||||
|
/** @internal */
|
||||||
|
__wbg_require_604837428532a733 = (ptr: number, len: number): never => {
|
||||||
|
throw new Error(`Unable to require ${this.#bridge.getString(ptr, len)}`);
|
||||||
|
};
|
||||||
|
|
||||||
|
/** @internal */
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||||
|
__wbg_crypto_968f1772287e2df0 = (_idx: number): number => {
|
||||||
|
return this.#bridge.addObject(DEFAULT_CRYPTO);
|
||||||
|
};
|
||||||
|
|
||||||
|
/** @internal */
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||||
|
__wbg_getRandomValues_a3d34b4fee3c2869 = (_idx: number): number => {
|
||||||
|
return this.#bridge.addObject(DEFAULT_CRYPTO.getRandomValues);
|
||||||
|
};
|
||||||
|
|
||||||
|
/** @internal */
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||||
|
__wbg_getRandomValues_f5e14ab7ac8e995d = (_arg0: number, ptr: number, len: number): void => {
|
||||||
|
DEFAULT_CRYPTO.getRandomValues(this.#bridge.getU8a(ptr, len));
|
||||||
|
};
|
||||||
|
|
||||||
|
/** @internal */
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||||
|
__wbg_randomFillSync_d5bd2d655fdf256a = (_idx: number, _ptr: number, _len: number): never => {
|
||||||
|
throw new Error('randomFillsync is not available');
|
||||||
|
|
||||||
|
// getObject(idx).randomFillSync(getU8a(ptr, len));
|
||||||
|
};
|
||||||
|
|
||||||
|
/** @internal */
|
||||||
|
__wbindgen_object_drop_ref = (idx: number): void => {
|
||||||
|
this.#bridge.takeObject(idx);
|
||||||
|
};
|
||||||
|
}
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
{
|
||||||
|
"extends": "../../tsconfig.base.json",
|
||||||
|
"compilerOptions": {
|
||||||
|
"baseUrl": "..",
|
||||||
|
"outDir": "./build",
|
||||||
|
"rootDir": "./src"
|
||||||
|
},
|
||||||
|
"references": [
|
||||||
|
]
|
||||||
|
}
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
## @polkadot/wasm-crypto-asmjs
|
||||||
@@ -17,13 +17,13 @@
|
|||||||
},
|
},
|
||||||
"sideEffects": false,
|
"sideEffects": false,
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"version": "5.1.1",
|
"version": "6.1.3",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@babel/runtime": "^7.17.8"
|
"@babel/runtime": "^7.18.3"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@polkadot/util": "^8.6.1"
|
"@polkadot/util": "^9.5.1"
|
||||||
},
|
},
|
||||||
"peerDependencies": {
|
"peerDependencies": {
|
||||||
"@polkadot/util": "*"
|
"@polkadot/util": "*"
|
||||||
|
|||||||
@@ -0,0 +1,6 @@
|
|||||||
|
// Copyright 2019-2022 @polkadot/wasm-crypto-wasm authors & contributors
|
||||||
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
|
const data = require('../data');
|
||||||
|
|
||||||
|
module.exports = data;
|
||||||
@@ -3,4 +3,4 @@
|
|||||||
|
|
||||||
const asmJsInit = null;
|
const asmJsInit = null;
|
||||||
|
|
||||||
exports.asmJsInit = asmJsInit;
|
module.exports.asmJsInit = asmJsInit;
|
||||||
|
|||||||
@@ -0,0 +1,4 @@
|
|||||||
|
// Copyright 2019-2022 @polkadot/wasm-crypto-asmjs authors & contributors
|
||||||
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
|
export declare const asmJsInit: null;
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
// Copyright 2019-2022 @polkadot/wasm-crypto-asmjs authors & contributors
|
||||||
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
|
export const asmJsInit = null;
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
// Copyright 2019-2022 @polkadot/wasm-crypto-wasm authors & contributors
|
||||||
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
|
export * from '../data.js';
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
// Copyright 2019-2022 @polkadot/wasm-crypto-asmjs authors & contributors
|
||||||
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
|
export { asmJsInit } from './deno/data.js';
|
||||||
|
export { packageInfo } from './packageInfo';
|
||||||
@@ -3,4 +3,4 @@
|
|||||||
|
|
||||||
// Do not edit, auto-generated by @polkadot/dev
|
// Do not edit, auto-generated by @polkadot/dev
|
||||||
|
|
||||||
export const packageInfo = { name: '@polkadot/wasm-crypto-asmjs', path: 'auto', type: 'auto', version: '5.1.1' };
|
export const packageInfo = { name: '@polkadot/wasm-crypto-asmjs', path: 'auto', type: 'auto', version: '6.1.3' };
|
||||||
|
|||||||
@@ -0,0 +1 @@
|
|||||||
|
## @polkadot/wasm-crypto-init
|
||||||
@@ -0,0 +1,39 @@
|
|||||||
|
{
|
||||||
|
"author": "Jaco Greeff <jacogr@gmail.com>",
|
||||||
|
"bugs": "https://github.com/polkadot-js/wasm/issues",
|
||||||
|
"contributors": [],
|
||||||
|
"description": "Init handlers for wasm-crypto",
|
||||||
|
"engines": {
|
||||||
|
"node": ">=14.0.0"
|
||||||
|
},
|
||||||
|
"homepage": "https://github.com/polkadot-js/wasm/tree/master/packages/wasm-crypto-init#readme",
|
||||||
|
"license": "Apache-2.0",
|
||||||
|
"maintainers": [],
|
||||||
|
"name": "@polkadot/wasm-crypto-init",
|
||||||
|
"repository": {
|
||||||
|
"directory": "packages/wasm-crypto-init",
|
||||||
|
"type": "git",
|
||||||
|
"url": "https://github.com/polkadot-js/wasm.git"
|
||||||
|
},
|
||||||
|
"sideEffects": [
|
||||||
|
"./detectPackage.js",
|
||||||
|
"./detectPackage.cjs"
|
||||||
|
],
|
||||||
|
"type": "module",
|
||||||
|
"version": "6.1.3",
|
||||||
|
"browser": "wasm.js",
|
||||||
|
"main": "wasm.js",
|
||||||
|
"react-native": "asm.js",
|
||||||
|
"dependencies": {
|
||||||
|
"@babel/runtime": "^7.18.3",
|
||||||
|
"@polkadot/wasm-bridge": "6.1.3",
|
||||||
|
"@polkadot/wasm-crypto-asmjs": "6.1.3",
|
||||||
|
"@polkadot/wasm-crypto-wasm": "6.1.3"
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"@polkadot/util": "^9.5.1"
|
||||||
|
},
|
||||||
|
"peerDependencies": {
|
||||||
|
"@polkadot/util": "*"
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
// Copyright 2019-2022 @polkadot/wasm-crypto-init authors & contributors
|
||||||
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
|
import type { InitFn } from '@polkadot/wasm-bridge/types';
|
||||||
|
import type { WasmCryptoInstance } from './types';
|
||||||
|
|
||||||
|
import { createWasmFn } from '@polkadot/wasm-bridge';
|
||||||
|
import { asmJsInit } from '@polkadot/wasm-crypto-asmjs';
|
||||||
|
|
||||||
|
export { packageInfo } from './packageInfo';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @name createWasm
|
||||||
|
* @description
|
||||||
|
* Creates an interface using only ASM.js
|
||||||
|
*/
|
||||||
|
export const createWasm: InitFn<WasmCryptoInstance> = createWasmFn('crypto', null, asmJsInit);
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
// Copyright 2019-2022 @polkadot/wasm-crypto-init authors & contributors
|
||||||
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
|
import type { InitFn } from '@polkadot/wasm-bridge/types';
|
||||||
|
import type { WasmCryptoInstance } from './types';
|
||||||
|
|
||||||
|
import { createWasmFn } from '@polkadot/wasm-bridge';
|
||||||
|
import { asmJsInit } from '@polkadot/wasm-crypto-asmjs';
|
||||||
|
import { wasmBytes } from '@polkadot/wasm-crypto-wasm';
|
||||||
|
|
||||||
|
export { packageInfo } from './packageInfo';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @name createWasm
|
||||||
|
* @description
|
||||||
|
* Creates an interface using WASM and a fallback ASM.js
|
||||||
|
*/
|
||||||
|
export const createWasm: InitFn<WasmCryptoInstance> = createWasmFn('crypto', wasmBytes, asmJsInit);
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
// Copyright 2019-2022 @polkadot/wasm-crypto-init authors & contributors
|
||||||
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
|
export * from './wasm';
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
// Copyright 2017-2022 @polkadot/wasm-crypto-init authors & contributors
|
||||||
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
|
import { packageInfo as bridgeInfo } from '@polkadot/wasm-bridge/packageInfo';
|
||||||
|
import { packageInfo as asmInfo } from '@polkadot/wasm-crypto-asmjs/packageInfo';
|
||||||
|
import { packageInfo as wasmInfo } from '@polkadot/wasm-crypto-wasm/packageInfo';
|
||||||
|
|
||||||
|
export default [bridgeInfo, asmInfo, wasmInfo];
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
// Copyright 2017-2022 @polkadot/wasm-crypto-init authors & contributors
|
||||||
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
|
// Do not edit, auto-generated by @polkadot/dev
|
||||||
|
|
||||||
|
import { detectPackage } from '@polkadot/util';
|
||||||
|
|
||||||
|
import others from './detectOther';
|
||||||
|
import { packageInfo } from './packageInfo';
|
||||||
|
|
||||||
|
detectPackage(packageInfo, null, others);
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
// Copyright 2019-2022 @polkadot/wasm-crypto-init authors & contributors
|
||||||
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
|
export * from './wasm';
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
// Copyright 2019-2022 @polkadot/wasm-crypto-init authors & contributors
|
||||||
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
|
import type { InitFn } from '@polkadot/wasm-bridge/types';
|
||||||
|
import type { WasmCryptoInstance } from './types';
|
||||||
|
|
||||||
|
import { createWasmFn } from '@polkadot/wasm-bridge';
|
||||||
|
|
||||||
|
export { packageInfo } from './packageInfo';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @name createWasm
|
||||||
|
* @description
|
||||||
|
* Creates an interface using no WASM and no ASM.js
|
||||||
|
*/
|
||||||
|
export const createWasm: InitFn<WasmCryptoInstance> = createWasmFn('crypto', null, null);
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
// Copyright 2017-2022 @polkadot/wasm-crypto-init authors & contributors
|
||||||
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
|
// Do not edit, auto-generated by @polkadot/dev
|
||||||
|
|
||||||
|
export const packageInfo = { name: '@polkadot/wasm-crypto-init', path: 'auto', type: 'auto', version: '6.1.3' };
|
||||||
@@ -1,22 +1,12 @@
|
|||||||
// Copyright 2019-2022 @polkadot/wasm-crypto authors & contributors
|
// Copyright 2019-2022 @polkadot/wasm-crypto-init authors & contributors
|
||||||
// SPDX-License-Identifier: Apache-2.0
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
|
import type { WasmBaseInstance } from '@polkadot/wasm-bridge/types';
|
||||||
|
|
||||||
/* eslint-disable camelcase */
|
/* eslint-disable camelcase */
|
||||||
|
|
||||||
// wasm-pack build output (formatted) from pkg/wasm_bg.d.ts
|
// wasm-pack build output (formatted) from pkg/wasm_bg.d.ts
|
||||||
export interface WasmCryptoInstance {
|
export interface WasmCryptoInstance extends WasmBaseInstance {
|
||||||
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
|
// exposed functions
|
||||||
|
|
||||||
ext_bip39_generate(resLen: 8, words: number): void;
|
ext_bip39_generate(resLen: 8, words: number): void;
|
||||||
@@ -83,5 +73,3 @@ export interface WasmCryptoInstance {
|
|||||||
|
|
||||||
ext_vrf_verify(ptrPub: number, lenPub: number, ptrCtx: number, lenCtx: number, ptrMsg: number, lenMsg: number, ptrExtra: number, lenExtra: number, ptrProof: number, lenProof: number): number;
|
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;
|
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
// Copyright 2019-2022 @polkadot/wasm-crypto-init authors & contributors
|
||||||
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
|
import type { InitFn } from '@polkadot/wasm-bridge/types';
|
||||||
|
import type { WasmCryptoInstance } from './types';
|
||||||
|
|
||||||
|
import { createWasmFn } from '@polkadot/wasm-bridge';
|
||||||
|
import { wasmBytes } from '@polkadot/wasm-crypto-wasm';
|
||||||
|
|
||||||
|
export { packageInfo } from './packageInfo';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @name createWasm
|
||||||
|
* @description
|
||||||
|
* Creates an interface using only WASM
|
||||||
|
*/
|
||||||
|
export const createWasm: InitFn<WasmCryptoInstance> = createWasmFn('crypto', wasmBytes, null);
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
{
|
||||||
|
"extends": "../../tsconfig.base.json",
|
||||||
|
"compilerOptions": {
|
||||||
|
"baseUrl": "..",
|
||||||
|
"outDir": "./build",
|
||||||
|
"rootDir": "./src"
|
||||||
|
},
|
||||||
|
"references": [
|
||||||
|
{ "path": "../wasm-bridge/tsconfig.build.json" },
|
||||||
|
{ "path": "../wasm-crypto-asmjs/tsconfig.build.json" },
|
||||||
|
{ "path": "../wasm-crypto-wasm/tsconfig.build.json" }
|
||||||
|
]
|
||||||
|
}
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
## @polkadot/wasm-crypto-wasm
|
||||||
@@ -17,13 +17,14 @@
|
|||||||
},
|
},
|
||||||
"sideEffects": false,
|
"sideEffects": false,
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"version": "5.1.1",
|
"version": "6.1.3",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@babel/runtime": "^7.17.8"
|
"@babel/runtime": "^7.18.3",
|
||||||
|
"@polkadot/wasm-util": "6.1.3"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@polkadot/util": "^8.6.1"
|
"@polkadot/util": "^9.5.1"
|
||||||
},
|
},
|
||||||
"peerDependencies": {
|
"peerDependencies": {
|
||||||
"@polkadot/util": "*"
|
"@polkadot/util": "*"
|
||||||
|
|||||||
@@ -1,10 +1,19 @@
|
|||||||
// Copyright 2019-2022 @polkadot/wasm-crypto-wasm authors & contributors
|
// Copyright 2019-2022 @polkadot/wasm-crypto-wasm authors & contributors
|
||||||
// SPDX-License-Identifier: Apache-2.0
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
|
import { base64Decode, unzlibSync } from '@polkadot/wasm-util';
|
||||||
|
|
||||||
import { bytes, sizeUncompressed } from './cjs/bytes';
|
import { bytes, sizeUncompressed } from './cjs/bytes';
|
||||||
import { base64Decode } from './base64';
|
|
||||||
import { unzlibSync } from './fflate';
|
|
||||||
|
|
||||||
export { packageInfo } from './packageInfo';
|
export { packageInfo } from './packageInfo';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @name wasmBytes
|
||||||
|
* @description
|
||||||
|
* The decoded WASM interface as exposed by this package.
|
||||||
|
*
|
||||||
|
* The build process will output into cjs/* into a compressed base64 format.
|
||||||
|
* Upon loading the exposed bytes will be decoded and decompressed form this
|
||||||
|
* specific format and returned.
|
||||||
|
*/
|
||||||
export const wasmBytes = unzlibSync(base64Decode(bytes), new Uint8Array(sizeUncompressed));
|
export const wasmBytes = unzlibSync(base64Decode(bytes), new Uint8Array(sizeUncompressed));
|
||||||
|
|||||||
+5
-3
@@ -1,6 +1,8 @@
|
|||||||
// Copyright 2019-2022 @polkadot/wasm-crypto-wasm authors & contributors
|
// Copyright 2019-2022 @polkadot/wasm-crypto-wasm authors & contributors
|
||||||
// SPDX-License-Identifier: Apache-2.0
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
export declare const bytes = '';
|
export declare const bytes: string;
|
||||||
export declare const sizeCompressed = 0;
|
|
||||||
export declare const sizeUncompressed = 0;
|
export declare const sizeCompressed: number;
|
||||||
|
|
||||||
|
export declare const sizeUncompressed: number;
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
// Copyright 2019-2022 @polkadot/wasm-crypto-wasm authors & contributors
|
// Copyright 2019-2022 @polkadot/wasm-crypto-wasm authors & contributors
|
||||||
// SPDX-License-Identifier: Apache-2.0
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
exports.bytes = '';
|
module.exports.bytes = '';
|
||||||
|
|
||||||
exports.sizeCompressed = 0;
|
module.exports.sizeCompressed = 0;
|
||||||
|
|
||||||
exports.sizeUncompressed = 0;
|
module.exports.sizeUncompressed = 0;
|
||||||
|
|||||||
@@ -0,0 +1,6 @@
|
|||||||
|
// Copyright 2019-2022 @polkadot/wasm-crypto-wasm authors & contributors
|
||||||
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
|
const bytes = require('../bytes');
|
||||||
|
|
||||||
|
module.exports = bytes;
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
// Copyright 2019-2022 @polkadot/wasm-crypto-wasm authors & contributors
|
||||||
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
|
export declare const bytes: string;
|
||||||
|
|
||||||
|
export declare const sizeCompressed: number;
|
||||||
|
|
||||||
|
export declare const sizeUncompressed: number;
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
// Copyright 2019-2022 @polkadot/wasm-crypto-wasm authors & contributors
|
||||||
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
|
export const bytes = '';
|
||||||
|
|
||||||
|
export const sizeCompressed = 0;
|
||||||
|
|
||||||
|
export const sizeUncompressed = 0;
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
// Copyright 2019-2022 @polkadot/wasm-crypto-wasm authors & contributors
|
||||||
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
|
export * from '../bytes.js';
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
// Copyright 2019-2022 @polkadot/wasm-crypto-wasm authors & contributors
|
||||||
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
|
import './detectPackage';
|
||||||
|
|
||||||
|
import { base64Decode, unzlibSync } from '@polkadot/wasm-util';
|
||||||
|
|
||||||
|
import { bytes, sizeUncompressed } from './deno/bytes.js';
|
||||||
|
|
||||||
|
export { packageInfo } from './packageInfo';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @name wasmBytes
|
||||||
|
* @description
|
||||||
|
* The decoded WASM interface as exposed by this package.
|
||||||
|
*
|
||||||
|
* The build process will output into cjs/* into a compressed base64 format.
|
||||||
|
* Upon loading the exposed bytes will be decoded and decompressed form this
|
||||||
|
* specific format and returned.
|
||||||
|
*/
|
||||||
|
export const wasmBytes = unzlibSync(base64Decode(bytes), new Uint8Array(sizeUncompressed));
|
||||||
@@ -3,4 +3,4 @@
|
|||||||
|
|
||||||
// Do not edit, auto-generated by @polkadot/dev
|
// Do not edit, auto-generated by @polkadot/dev
|
||||||
|
|
||||||
export const packageInfo = { name: '@polkadot/wasm-crypto-wasm', path: 'auto', type: 'auto', version: '5.1.1' };
|
export const packageInfo = { name: '@polkadot/wasm-crypto-wasm', path: 'auto', type: 'auto', version: '6.1.3' };
|
||||||
|
|||||||
@@ -5,5 +5,7 @@
|
|||||||
"outDir": "./build",
|
"outDir": "./build",
|
||||||
"rootDir": "./src"
|
"rootDir": "./src"
|
||||||
},
|
},
|
||||||
"references": []
|
"references": [
|
||||||
|
{ "path": "../wasm-util/tsconfig.build.json" }
|
||||||
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -28,19 +28,20 @@
|
|||||||
"./initWasmAsm.cjs"
|
"./initWasmAsm.cjs"
|
||||||
],
|
],
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"version": "5.1.1",
|
"version": "6.1.3",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@babel/runtime": "^7.17.8",
|
"@babel/runtime": "^7.18.3",
|
||||||
"@polkadot/wasm-crypto-asmjs": "^5.1.1",
|
"@polkadot/wasm-bridge": "6.1.3",
|
||||||
"@polkadot/wasm-crypto-wasm": "^5.1.1"
|
"@polkadot/wasm-crypto-asmjs": "6.1.3",
|
||||||
|
"@polkadot/wasm-crypto-init": "6.1.3",
|
||||||
|
"@polkadot/wasm-crypto-wasm": "6.1.3",
|
||||||
|
"@polkadot/wasm-util": "6.1.3"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@polkadot/util": "^8.6.1",
|
"@polkadot/util": "^9.5.1"
|
||||||
"@polkadot/x-randomvalues": "^8.6.1"
|
|
||||||
},
|
},
|
||||||
"peerDependencies": {
|
"peerDependencies": {
|
||||||
"@polkadot/util": "*",
|
"@polkadot/util": "*"
|
||||||
"@polkadot/x-randomvalues": "*"
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,93 +0,0 @@
|
|||||||
// Copyright 2019-2022 @polkadot/wasm-crypto authors & contributors
|
|
||||||
// SPDX-License-Identifier: Apache-2.0
|
|
||||||
|
|
||||||
/* eslint-disable @typescript-eslint/no-non-null-assertion */
|
|
||||||
|
|
||||||
import type { WasmCryptoInstance } from './types';
|
|
||||||
|
|
||||||
import { assert, stringToU8a, u8aToString } from '@polkadot/util';
|
|
||||||
|
|
||||||
type PopFirst<T extends unknown[]> =
|
|
||||||
T extends [WasmCryptoInstance, ...infer N]
|
|
||||||
? N
|
|
||||||
: [];
|
|
||||||
|
|
||||||
interface Bridge {
|
|
||||||
cachegetInt32: Int32Array | null;
|
|
||||||
cachegetUint8: Uint8Array | null;
|
|
||||||
type: 'wasm' | 'asm';
|
|
||||||
wasm: WasmCryptoInstance | null;
|
|
||||||
wasmPromise: Promise<void> | null;
|
|
||||||
wasmPromiseFn: null | (() => Promise<void>);
|
|
||||||
}
|
|
||||||
|
|
||||||
export const __bridge: Bridge = {
|
|
||||||
cachegetInt32: null,
|
|
||||||
cachegetUint8: null,
|
|
||||||
type: 'wasm',
|
|
||||||
wasm: null,
|
|
||||||
wasmPromise: null,
|
|
||||||
wasmPromiseFn: 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(__bridge.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(__bridge.wasm, ...params) as ReturnType<F>;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
export function getWasm (): WasmCryptoInstance {
|
|
||||||
return __bridge.wasm!;
|
|
||||||
}
|
|
||||||
|
|
||||||
export function getInt32 (): Int32Array {
|
|
||||||
if (__bridge.cachegetInt32 === null || __bridge.cachegetInt32.buffer !== __bridge.wasm!.memory.buffer) {
|
|
||||||
__bridge.cachegetInt32 = new Int32Array(__bridge.wasm!.memory.buffer);
|
|
||||||
}
|
|
||||||
|
|
||||||
return __bridge.cachegetInt32;
|
|
||||||
}
|
|
||||||
|
|
||||||
export function getUint8 (): Uint8Array {
|
|
||||||
if (__bridge.cachegetUint8 === null || __bridge.cachegetUint8.buffer !== __bridge.wasm!.memory.buffer) {
|
|
||||||
__bridge.cachegetUint8 = new Uint8Array(__bridge.wasm!.memory.buffer);
|
|
||||||
}
|
|
||||||
|
|
||||||
return __bridge.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 = __bridge.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();
|
|
||||||
|
|
||||||
__bridge.wasm!.__wbindgen_free(r0, r1 * 1);
|
|
||||||
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
export function resultString (): string {
|
|
||||||
return u8aToString(resultU8a());
|
|
||||||
}
|
|
||||||
@@ -1,220 +1,246 @@
|
|||||||
// Copyright 2019-2022 @polkadot/wasm-crypto authors & contributors
|
// Copyright 2019-2022 @polkadot/wasm-crypto authors & contributors
|
||||||
// SPDX-License-Identifier: Apache-2.0
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
import { __bridge, allocString, allocU8a, getWasm, resultString, resultU8a, withWasm } from './bridge';
|
import type { WasmCryptoInstance } from '@polkadot/wasm-crypto-init/types';
|
||||||
import { initWasm } from './init';
|
|
||||||
|
import { bridge, initBridge } from './init';
|
||||||
|
|
||||||
export { packageInfo } from './packageInfo';
|
export { packageInfo } from './packageInfo';
|
||||||
|
export { bridge };
|
||||||
|
|
||||||
|
// Removes the first parameter (expected as WasmCryptoInstance) and leaves the
|
||||||
|
// rest of the parameters in-tack. This allows us to dynamically create a function
|
||||||
|
// return from the withWasm helper
|
||||||
|
type PopFirst<T extends unknown[]> =
|
||||||
|
T extends [WasmCryptoInstance, ...infer N]
|
||||||
|
? N
|
||||||
|
: [];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @internal
|
||||||
|
* @description
|
||||||
|
* This create an extenal interface function from the signature, all the while checking
|
||||||
|
* the actual bridge wasm interface to ensure it has been initialized.
|
||||||
|
*
|
||||||
|
* This means that we can call it
|
||||||
|
*
|
||||||
|
* withWasm(wasm: WasmCryptoInstance, a: number, b: string) => Uint8Array
|
||||||
|
*
|
||||||
|
* and in this case it will create an interface function with the signarure
|
||||||
|
*
|
||||||
|
* (a: number, b: string) => Uint8Array
|
||||||
|
*/
|
||||||
|
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> => {
|
||||||
|
if (!bridge.wasm) {
|
||||||
|
throw new Error('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(bridge.wasm, ...params) as ReturnType<F>;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
export const bip39Generate = withWasm((wasm, words: 12 | 15 | 18 | 21 | 24): string => {
|
export const bip39Generate = withWasm((wasm, words: 12 | 15 | 18 | 21 | 24): string => {
|
||||||
wasm.ext_bip39_generate(8, words);
|
wasm.ext_bip39_generate(8, words);
|
||||||
|
|
||||||
return resultString();
|
return bridge.resultString();
|
||||||
});
|
});
|
||||||
|
|
||||||
export const bip39ToEntropy = withWasm((wasm, phrase: string): Uint8Array => {
|
export const bip39ToEntropy = withWasm((wasm, phrase: string): Uint8Array => {
|
||||||
wasm.ext_bip39_to_entropy(8, ...allocString(phrase));
|
wasm.ext_bip39_to_entropy(8, ...bridge.allocString(phrase));
|
||||||
|
|
||||||
return resultU8a();
|
return bridge.resultU8a();
|
||||||
});
|
});
|
||||||
|
|
||||||
export const bip39ToMiniSecret = withWasm((wasm, phrase: string, password: string): Uint8Array => {
|
export const bip39ToMiniSecret = withWasm((wasm, phrase: string, password: string): Uint8Array => {
|
||||||
wasm.ext_bip39_to_mini_secret(8, ...allocString(phrase), ...allocString(password));
|
wasm.ext_bip39_to_mini_secret(8, ...bridge.allocString(phrase), ...bridge.allocString(password));
|
||||||
|
|
||||||
return resultU8a();
|
return bridge.resultU8a();
|
||||||
});
|
});
|
||||||
|
|
||||||
export const bip39ToSeed = withWasm((wasm, phrase: string, password: string): Uint8Array => {
|
export const bip39ToSeed = withWasm((wasm, phrase: string, password: string): Uint8Array => {
|
||||||
wasm.ext_bip39_to_seed(8, ...allocString(phrase), ...allocString(password));
|
wasm.ext_bip39_to_seed(8, ...bridge.allocString(phrase), ...bridge.allocString(password));
|
||||||
|
|
||||||
return resultU8a();
|
return bridge.resultU8a();
|
||||||
});
|
});
|
||||||
|
|
||||||
export const bip39Validate = withWasm((wasm, phrase: string): boolean => {
|
export const bip39Validate = withWasm((wasm, phrase: string): boolean => {
|
||||||
const ret = wasm.ext_bip39_validate(...allocString(phrase));
|
const ret = wasm.ext_bip39_validate(...bridge.allocString(phrase));
|
||||||
|
|
||||||
return ret !== 0;
|
return ret !== 0;
|
||||||
});
|
});
|
||||||
|
|
||||||
export const ed25519KeypairFromSeed = withWasm((wasm, seed: Uint8Array): Uint8Array => {
|
export const ed25519KeypairFromSeed = withWasm((wasm, seed: Uint8Array): Uint8Array => {
|
||||||
wasm.ext_ed_from_seed(8, ...allocU8a(seed));
|
wasm.ext_ed_from_seed(8, ...bridge.allocU8a(seed));
|
||||||
|
|
||||||
return resultU8a();
|
return bridge.resultU8a();
|
||||||
});
|
});
|
||||||
|
|
||||||
export const ed25519Sign = withWasm((wasm, pubkey: Uint8Array, seckey: Uint8Array, message: Uint8Array): Uint8Array => {
|
export const ed25519Sign = withWasm((wasm, pubkey: Uint8Array, seckey: Uint8Array, message: Uint8Array): Uint8Array => {
|
||||||
wasm.ext_ed_sign(8, ...allocU8a(pubkey), ...allocU8a(seckey), ...allocU8a(message));
|
wasm.ext_ed_sign(8, ...bridge.allocU8a(pubkey), ...bridge.allocU8a(seckey), ...bridge.allocU8a(message));
|
||||||
|
|
||||||
return resultU8a();
|
return bridge.resultU8a();
|
||||||
});
|
});
|
||||||
|
|
||||||
export const ed25519Verify = withWasm((wasm, signature: Uint8Array, message: Uint8Array, pubkey: Uint8Array): boolean => {
|
export const ed25519Verify = withWasm((wasm, signature: Uint8Array, message: Uint8Array, pubkey: Uint8Array): boolean => {
|
||||||
const ret = wasm.ext_ed_verify(...allocU8a(signature), ...allocU8a(message), ...allocU8a(pubkey));
|
const ret = wasm.ext_ed_verify(...bridge.allocU8a(signature), ...bridge.allocU8a(message), ...bridge.allocU8a(pubkey));
|
||||||
|
|
||||||
return ret !== 0;
|
return ret !== 0;
|
||||||
});
|
});
|
||||||
|
|
||||||
export const secp256k1FromSeed = withWasm((wasm, seckey: Uint8Array): Uint8Array => {
|
export const secp256k1FromSeed = withWasm((wasm, seckey: Uint8Array): Uint8Array => {
|
||||||
wasm.ext_secp_from_seed(8, ...allocU8a(seckey));
|
wasm.ext_secp_from_seed(8, ...bridge.allocU8a(seckey));
|
||||||
|
|
||||||
return resultU8a();
|
return bridge.resultU8a();
|
||||||
});
|
});
|
||||||
|
|
||||||
export const secp256k1Compress = withWasm((wasm, pubkey: Uint8Array): Uint8Array => {
|
export const secp256k1Compress = withWasm((wasm, pubkey: Uint8Array): Uint8Array => {
|
||||||
wasm.ext_secp_pub_compress(8, ...allocU8a(pubkey));
|
wasm.ext_secp_pub_compress(8, ...bridge.allocU8a(pubkey));
|
||||||
|
|
||||||
return resultU8a();
|
return bridge.resultU8a();
|
||||||
});
|
});
|
||||||
|
|
||||||
export const secp256k1Expand = withWasm((wasm, pubkey: Uint8Array): Uint8Array => {
|
export const secp256k1Expand = withWasm((wasm, pubkey: Uint8Array): Uint8Array => {
|
||||||
wasm.ext_secp_pub_expand(8, ...allocU8a(pubkey));
|
wasm.ext_secp_pub_expand(8, ...bridge.allocU8a(pubkey));
|
||||||
|
|
||||||
return resultU8a();
|
return bridge.resultU8a();
|
||||||
});
|
});
|
||||||
|
|
||||||
export const secp256k1Recover = withWasm((wasm, msgHash: Uint8Array, sig: Uint8Array, recovery: number): Uint8Array => {
|
export const secp256k1Recover = withWasm((wasm, msgHash: Uint8Array, sig: Uint8Array, recovery: number): Uint8Array => {
|
||||||
wasm.ext_secp_recover(8, ...allocU8a(msgHash), ...allocU8a(sig), recovery);
|
wasm.ext_secp_recover(8, ...bridge.allocU8a(msgHash), ...bridge.allocU8a(sig), recovery);
|
||||||
|
|
||||||
return resultU8a();
|
return bridge.resultU8a();
|
||||||
});
|
});
|
||||||
|
|
||||||
export const secp256k1Sign = withWasm((wasm, msgHash: Uint8Array, seckey: Uint8Array): Uint8Array => {
|
export const secp256k1Sign = withWasm((wasm, msgHash: Uint8Array, seckey: Uint8Array): Uint8Array => {
|
||||||
wasm.ext_secp_sign(8, ...allocU8a(msgHash), ...allocU8a(seckey));
|
wasm.ext_secp_sign(8, ...bridge.allocU8a(msgHash), ...bridge.allocU8a(seckey));
|
||||||
|
|
||||||
return resultU8a();
|
return bridge.resultU8a();
|
||||||
});
|
});
|
||||||
|
|
||||||
export const sr25519DeriveKeypairHard = withWasm((wasm, pair: Uint8Array, cc: Uint8Array): Uint8Array => {
|
export const sr25519DeriveKeypairHard = withWasm((wasm, pair: Uint8Array, cc: Uint8Array): Uint8Array => {
|
||||||
wasm.ext_sr_derive_keypair_hard(8, ...allocU8a(pair), ...allocU8a(cc));
|
wasm.ext_sr_derive_keypair_hard(8, ...bridge.allocU8a(pair), ...bridge.allocU8a(cc));
|
||||||
|
|
||||||
return resultU8a();
|
return bridge.resultU8a();
|
||||||
});
|
});
|
||||||
|
|
||||||
export const sr25519DeriveKeypairSoft = withWasm((wasm, pair: Uint8Array, cc: Uint8Array): Uint8Array => {
|
export const sr25519DeriveKeypairSoft = withWasm((wasm, pair: Uint8Array, cc: Uint8Array): Uint8Array => {
|
||||||
wasm.ext_sr_derive_keypair_soft(8, ...allocU8a(pair), ...allocU8a(cc));
|
wasm.ext_sr_derive_keypair_soft(8, ...bridge.allocU8a(pair), ...bridge.allocU8a(cc));
|
||||||
|
|
||||||
return resultU8a();
|
return bridge.resultU8a();
|
||||||
});
|
});
|
||||||
|
|
||||||
export const sr25519DerivePublicSoft = withWasm((wasm, pubkey: Uint8Array, cc: Uint8Array): Uint8Array => {
|
export const sr25519DerivePublicSoft = withWasm((wasm, pubkey: Uint8Array, cc: Uint8Array): Uint8Array => {
|
||||||
wasm.ext_sr_derive_public_soft(8, ...allocU8a(pubkey), ...allocU8a(cc));
|
wasm.ext_sr_derive_public_soft(8, ...bridge.allocU8a(pubkey), ...bridge.allocU8a(cc));
|
||||||
|
|
||||||
return resultU8a();
|
return bridge.resultU8a();
|
||||||
});
|
});
|
||||||
|
|
||||||
export const sr25519KeypairFromSeed = withWasm((wasm, seed: Uint8Array): Uint8Array => {
|
export const sr25519KeypairFromSeed = withWasm((wasm, seed: Uint8Array): Uint8Array => {
|
||||||
wasm.ext_sr_from_seed(8, ...allocU8a(seed));
|
wasm.ext_sr_from_seed(8, ...bridge.allocU8a(seed));
|
||||||
|
|
||||||
return resultU8a();
|
return bridge.resultU8a();
|
||||||
});
|
});
|
||||||
|
|
||||||
export const sr25519Sign = withWasm((wasm, pubkey: Uint8Array, secret: Uint8Array, message: Uint8Array): Uint8Array => {
|
export const sr25519Sign = withWasm((wasm, pubkey: Uint8Array, secret: Uint8Array, message: Uint8Array): Uint8Array => {
|
||||||
wasm.ext_sr_sign(8, ...allocU8a(pubkey), ...allocU8a(secret), ...allocU8a(message));
|
wasm.ext_sr_sign(8, ...bridge.allocU8a(pubkey), ...bridge.allocU8a(secret), ...bridge.allocU8a(message));
|
||||||
|
|
||||||
return resultU8a();
|
return bridge.resultU8a();
|
||||||
});
|
});
|
||||||
|
|
||||||
export const sr25519Verify = withWasm((wasm, signature: Uint8Array, message: Uint8Array, pubkey: Uint8Array): boolean => {
|
export const sr25519Verify = withWasm((wasm, signature: Uint8Array, message: Uint8Array, pubkey: Uint8Array): boolean => {
|
||||||
const ret = wasm.ext_sr_verify(...allocU8a(signature), ...allocU8a(message), ...allocU8a(pubkey));
|
const ret = wasm.ext_sr_verify(...bridge.allocU8a(signature), ...bridge.allocU8a(message), ...bridge.allocU8a(pubkey));
|
||||||
|
|
||||||
return ret !== 0;
|
return ret !== 0;
|
||||||
});
|
});
|
||||||
|
|
||||||
export const sr25519Agree = withWasm((wasm, pubkey: Uint8Array, secret: Uint8Array): Uint8Array => {
|
export const sr25519Agree = withWasm((wasm, pubkey: Uint8Array, secret: Uint8Array): Uint8Array => {
|
||||||
wasm.ext_sr_agree(8, ...allocU8a(pubkey), ...allocU8a(secret));
|
wasm.ext_sr_agree(8, ...bridge.allocU8a(pubkey), ...bridge.allocU8a(secret));
|
||||||
|
|
||||||
return resultU8a();
|
return bridge.resultU8a();
|
||||||
});
|
});
|
||||||
|
|
||||||
export const vrfSign = withWasm((wasm, secret: Uint8Array, context: Uint8Array, message: Uint8Array, extra: Uint8Array): Uint8Array => {
|
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));
|
wasm.ext_vrf_sign(8, ...bridge.allocU8a(secret), ...bridge.allocU8a(context), ...bridge.allocU8a(message), ...bridge.allocU8a(extra));
|
||||||
|
|
||||||
return resultU8a();
|
return bridge.resultU8a();
|
||||||
});
|
});
|
||||||
|
|
||||||
export const vrfVerify = withWasm((wasm, pubkey: Uint8Array, context: Uint8Array, message: Uint8Array, extra: Uint8Array, outAndProof: Uint8Array): boolean => {
|
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));
|
const ret = wasm.ext_vrf_verify(...bridge.allocU8a(pubkey), ...bridge.allocU8a(context), ...bridge.allocU8a(message), ...bridge.allocU8a(extra), ...bridge.allocU8a(outAndProof));
|
||||||
|
|
||||||
return ret !== 0;
|
return ret !== 0;
|
||||||
});
|
});
|
||||||
|
|
||||||
export const blake2b = withWasm((wasm, data: Uint8Array, key: Uint8Array, size: number): Uint8Array => {
|
export const blake2b = withWasm((wasm, data: Uint8Array, key: Uint8Array, size: number): Uint8Array => {
|
||||||
wasm.ext_blake2b(8, ...allocU8a(data), ...allocU8a(key), size);
|
wasm.ext_blake2b(8, ...bridge.allocU8a(data), ...bridge.allocU8a(key), size);
|
||||||
|
|
||||||
return resultU8a();
|
return bridge.resultU8a();
|
||||||
});
|
});
|
||||||
|
|
||||||
export const hmacSha256 = withWasm((wasm, key: Uint8Array, data: Uint8Array): Uint8Array => {
|
export const hmacSha256 = withWasm((wasm, key: Uint8Array, data: Uint8Array): Uint8Array => {
|
||||||
wasm.ext_hmac_sha256(8, ...allocU8a(key), ...allocU8a(data));
|
wasm.ext_hmac_sha256(8, ...bridge.allocU8a(key), ...bridge.allocU8a(data));
|
||||||
|
|
||||||
return resultU8a();
|
return bridge.resultU8a();
|
||||||
});
|
});
|
||||||
|
|
||||||
export const hmacSha512 = withWasm((wasm, key: Uint8Array, data: Uint8Array): Uint8Array => {
|
export const hmacSha512 = withWasm((wasm, key: Uint8Array, data: Uint8Array): Uint8Array => {
|
||||||
wasm.ext_hmac_sha512(8, ...allocU8a(key), ...allocU8a(data));
|
wasm.ext_hmac_sha512(8, ...bridge.allocU8a(key), ...bridge.allocU8a(data));
|
||||||
|
|
||||||
return resultU8a();
|
return bridge.resultU8a();
|
||||||
});
|
});
|
||||||
|
|
||||||
export const keccak256 = withWasm((wasm, data: Uint8Array): Uint8Array => {
|
export const keccak256 = withWasm((wasm, data: Uint8Array): Uint8Array => {
|
||||||
wasm.ext_keccak256(8, ...allocU8a(data));
|
wasm.ext_keccak256(8, ...bridge.allocU8a(data));
|
||||||
|
|
||||||
return resultU8a();
|
return bridge.resultU8a();
|
||||||
});
|
});
|
||||||
|
|
||||||
export const keccak512 = withWasm((wasm, data: Uint8Array): Uint8Array => {
|
export const keccak512 = withWasm((wasm, data: Uint8Array): Uint8Array => {
|
||||||
wasm.ext_keccak512(8, ...allocU8a(data));
|
wasm.ext_keccak512(8, ...bridge.allocU8a(data));
|
||||||
|
|
||||||
return resultU8a();
|
return bridge.resultU8a();
|
||||||
});
|
});
|
||||||
|
|
||||||
export const pbkdf2 = withWasm((wasm, data: Uint8Array, salt: Uint8Array, rounds: number): Uint8Array => {
|
export const pbkdf2 = withWasm((wasm, data: Uint8Array, salt: Uint8Array, rounds: number): Uint8Array => {
|
||||||
wasm.ext_pbkdf2(8, ...allocU8a(data), ...allocU8a(salt), rounds);
|
wasm.ext_pbkdf2(8, ...bridge.allocU8a(data), ...bridge.allocU8a(salt), rounds);
|
||||||
|
|
||||||
return resultU8a();
|
return bridge.resultU8a();
|
||||||
});
|
});
|
||||||
|
|
||||||
export const scrypt = withWasm((wasm, password: Uint8Array, salt: Uint8Array, log2n: number, r: number, p: number): Uint8Array => {
|
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);
|
wasm.ext_scrypt(8, ...bridge.allocU8a(password), ...bridge.allocU8a(salt), log2n, r, p);
|
||||||
|
|
||||||
return resultU8a();
|
return bridge.resultU8a();
|
||||||
});
|
});
|
||||||
|
|
||||||
export const sha256 = withWasm((wasm, data: Uint8Array): Uint8Array => {
|
export const sha256 = withWasm((wasm, data: Uint8Array): Uint8Array => {
|
||||||
wasm.ext_sha256(8, ...allocU8a(data));
|
wasm.ext_sha256(8, ...bridge.allocU8a(data));
|
||||||
|
|
||||||
return resultU8a();
|
return bridge.resultU8a();
|
||||||
});
|
});
|
||||||
|
|
||||||
export const sha512 = withWasm((wasm, data: Uint8Array): Uint8Array => {
|
export const sha512 = withWasm((wasm, data: Uint8Array): Uint8Array => {
|
||||||
wasm.ext_sha512(8, ...allocU8a(data));
|
wasm.ext_sha512(8, ...bridge.allocU8a(data));
|
||||||
|
|
||||||
return resultU8a();
|
return bridge.resultU8a();
|
||||||
});
|
});
|
||||||
|
|
||||||
export const twox = withWasm((wasm, data: Uint8Array, rounds: number) => {
|
export const twox = withWasm((wasm, data: Uint8Array, rounds: number) => {
|
||||||
wasm.ext_twox(8, ...allocU8a(data), rounds);
|
wasm.ext_twox(8, ...bridge.allocU8a(data), rounds);
|
||||||
|
|
||||||
return resultU8a();
|
return bridge.resultU8a();
|
||||||
});
|
});
|
||||||
|
|
||||||
export function isReady (): boolean {
|
export function isReady (): boolean {
|
||||||
return !!getWasm();
|
return !!bridge.wasm;
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function waitReady (): Promise<boolean> {
|
export async function waitReady (): Promise<boolean> {
|
||||||
try {
|
try {
|
||||||
if (!__bridge.wasmPromise) {
|
const wasm = await initBridge();
|
||||||
if (!__bridge.wasmPromiseFn) {
|
|
||||||
__bridge.wasmPromiseFn = initWasm;
|
|
||||||
}
|
|
||||||
|
|
||||||
__bridge.wasmPromise = __bridge.wasmPromiseFn();
|
return !!wasm;
|
||||||
}
|
|
||||||
|
|
||||||
await __bridge.wasmPromise;
|
|
||||||
|
|
||||||
return isReady();
|
|
||||||
} catch {
|
} catch {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,10 @@
|
|||||||
// Copyright 2017-2022 @polkadot/wasm-crypto authors & contributors
|
// Copyright 2017-2022 @polkadot/wasm-crypto authors & contributors
|
||||||
// SPDX-License-Identifier: Apache-2.0
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
|
import { packageInfo as bridgeInfo } from '@polkadot/wasm-bridge/packageInfo';
|
||||||
import { packageInfo as asmInfo } from '@polkadot/wasm-crypto-asmjs/packageInfo';
|
import { packageInfo as asmInfo } from '@polkadot/wasm-crypto-asmjs/packageInfo';
|
||||||
|
import { packageInfo as initInfo } from '@polkadot/wasm-crypto-init/packageInfo';
|
||||||
import { packageInfo as wasmInfo } from '@polkadot/wasm-crypto-wasm/packageInfo';
|
import { packageInfo as wasmInfo } from '@polkadot/wasm-crypto-wasm/packageInfo';
|
||||||
|
import { packageInfo as utilInfo } from '@polkadot/wasm-util/packageInfo';
|
||||||
|
|
||||||
export default [asmInfo, wasmInfo];
|
export default [bridgeInfo, asmInfo, initInfo, wasmInfo, utilInfo];
|
||||||
|
|||||||
@@ -1,94 +0,0 @@
|
|||||||
// Copyright 2019-2022 @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');
|
|
||||||
}
|
|
||||||
@@ -1,44 +1,25 @@
|
|||||||
// Copyright 2019-2022 @polkadot/wasm-crypto authors & contributors
|
// Copyright 2019-2022 @polkadot/wasm-crypto authors & contributors
|
||||||
// SPDX-License-Identifier: Apache-2.0
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
import type { AsmCreator, WasmCryptoInstance } from './types';
|
import type { InitFn } from '@polkadot/wasm-bridge/types';
|
||||||
|
import type { WasmCryptoInstance } from '@polkadot/wasm-crypto-init/types';
|
||||||
|
|
||||||
import { assert } from '@polkadot/util';
|
import { Bridge } from '@polkadot/wasm-bridge';
|
||||||
import { wasmBytes } from '@polkadot/wasm-crypto-wasm';
|
import { createWasm } from '@polkadot/wasm-crypto-init';
|
||||||
|
|
||||||
import { __bridge } from './bridge';
|
/**
|
||||||
import * as wbg from './imports';
|
* @name bridge
|
||||||
|
* @description
|
||||||
|
* The JS <-> WASM bridge that is in operation. For the specific package
|
||||||
|
* it is a global, i.e. all operations happens on this specific bridge
|
||||||
|
*/
|
||||||
|
export const bridge = new Bridge<WasmCryptoInstance>(createWasm);
|
||||||
|
|
||||||
async function createPromise (wasmBytes: Uint8Array | null, asmFn: AsmCreator | null): Promise<void> {
|
/**
|
||||||
try {
|
* @name initBridge
|
||||||
assert(typeof WebAssembly === 'object' && typeof WebAssembly.instantiate === 'function' && wasmBytes && wasmBytes.length, 'WebAssembly is not available in your environment');
|
* @description
|
||||||
|
* Creates a new bridge interface with the (optional) initialization function
|
||||||
const source = await WebAssembly.instantiate(wasmBytes, { wbg });
|
*/
|
||||||
|
export async function initBridge (createWasm?: InitFn<WasmCryptoInstance>): Promise<WasmCryptoInstance | null> {
|
||||||
__bridge.wasm = (source.instance.exports as unknown as WasmCryptoInstance);
|
return bridge.init(createWasm);
|
||||||
} catch (error) {
|
|
||||||
// if we have a valid supplied asm.js, return that
|
|
||||||
if (asmFn) {
|
|
||||||
__bridge.type = 'asm';
|
|
||||||
__bridge.wasm = asmFn(wbg);
|
|
||||||
} else {
|
|
||||||
console.error(`FATAL: Unable to initialize @polkadot/wasm-crypto:: ${(error as Error).message}`);
|
|
||||||
|
|
||||||
__bridge.wasm = null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export function setWasmPromise (wasmBytes: Uint8Array | null, asmFn: AsmCreator | null): Promise<void> {
|
|
||||||
__bridge.wasmPromise = createPromise(wasmBytes, asmFn);
|
|
||||||
|
|
||||||
return __bridge.wasmPromise;
|
|
||||||
}
|
|
||||||
|
|
||||||
export function setWasmPromiseFn (fn: () => Promise<void>): void {
|
|
||||||
__bridge.wasmPromiseFn = fn;
|
|
||||||
}
|
|
||||||
|
|
||||||
export function initWasm (): Promise<void> {
|
|
||||||
return setWasmPromise(wasmBytes, null);
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,27 +1,23 @@
|
|||||||
// Copyright 2019-2022 @polkadot/wasm-crypto authors & contributors
|
// Copyright 2019-2022 @polkadot/wasm-crypto authors & contributors
|
||||||
// SPDX-License-Identifier: Apache-2.0
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
import type { AsmCreator } from './types';
|
import { createWasm } from '@polkadot/wasm-crypto-init/none';
|
||||||
|
|
||||||
import { __bridge } from './bridge';
|
import { initBridge } from './init';
|
||||||
|
|
||||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
/**
|
||||||
export function setWasmPromise (_wasmBytes: Uint8Array | null, _asmFn: AsmCreator | null): Promise<void> {
|
* @name initWasm
|
||||||
__bridge.wasmPromise = Promise.resolve();
|
* @description
|
||||||
|
* For historic purposes and for tighter control on init, specifically performing
|
||||||
return __bridge.wasmPromise;
|
* a WASM initialization with no interface whatsoever (no WASM, no ASM.js)
|
||||||
|
*
|
||||||
|
* Generally should not be used unless you want explicit control over which
|
||||||
|
* interfaces are initialized.
|
||||||
|
*/
|
||||||
|
export async function initWasm (): Promise<void> {
|
||||||
|
await initBridge(createWasm);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function setWasmPromiseFn (fn: () => Promise<void>): void {
|
initWasm().catch((): void => {
|
||||||
__bridge.wasmPromiseFn = fn;
|
// cannot happen, initWasm doesn't throw
|
||||||
}
|
});
|
||||||
|
|
||||||
export function setWasmOnlyPromise (): Promise<void> {
|
|
||||||
return setWasmPromise(null, null);
|
|
||||||
}
|
|
||||||
|
|
||||||
export function initWasm (): Promise<void> {
|
|
||||||
return setWasmOnlyPromise();
|
|
||||||
}
|
|
||||||
|
|
||||||
setWasmPromiseFn(initWasm);
|
|
||||||
|
|||||||
@@ -1,12 +1,23 @@
|
|||||||
// Copyright 2019-2022 @polkadot/wasm-crypto authors & contributors
|
// Copyright 2019-2022 @polkadot/wasm-crypto authors & contributors
|
||||||
// SPDX-License-Identifier: Apache-2.0
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
import { asmJsInit } from '@polkadot/wasm-crypto-asmjs';
|
import { createWasm } from '@polkadot/wasm-crypto-init/asm';
|
||||||
|
|
||||||
import { setWasmPromise, setWasmPromiseFn } from './init';
|
import { initBridge } from './init';
|
||||||
|
|
||||||
export function initWasm (): Promise<void> {
|
/**
|
||||||
return setWasmPromise(null, asmJsInit);
|
* @name initWasm
|
||||||
|
* @description
|
||||||
|
* For historic purposes and for tighter control on init, specifically performing
|
||||||
|
* a WASM initialization with only ASM.js
|
||||||
|
*
|
||||||
|
* Generally should not be used unless you want explicit control over which
|
||||||
|
* interfaces are initialized.
|
||||||
|
*/
|
||||||
|
export async function initWasm (): Promise<void> {
|
||||||
|
await initBridge(createWasm);
|
||||||
}
|
}
|
||||||
|
|
||||||
setWasmPromiseFn(initWasm);
|
initWasm().catch((): void => {
|
||||||
|
// cannot happen, initWasm doesn't throw
|
||||||
|
});
|
||||||
|
|||||||
@@ -1,10 +1,23 @@
|
|||||||
// Copyright 2019-2022 @polkadot/wasm-crypto authors & contributors
|
// Copyright 2019-2022 @polkadot/wasm-crypto authors & contributors
|
||||||
// SPDX-License-Identifier: Apache-2.0
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
import { initWasm as baseInitWasm, setWasmPromiseFn } from './init';
|
import { createWasm } from '@polkadot/wasm-crypto-init/wasm';
|
||||||
|
|
||||||
export function initWasm (): Promise<void> {
|
import { initBridge } from './init';
|
||||||
return baseInitWasm();
|
|
||||||
|
/**
|
||||||
|
* @name initWasm
|
||||||
|
* @description
|
||||||
|
* For historic purposes and for tighter control on init, specifically performing
|
||||||
|
* a WASM initialization with only WASM (generally the default for most platforms)
|
||||||
|
*
|
||||||
|
* Generally should not be used unless you want explicit control over which
|
||||||
|
* interfaces are initialized.
|
||||||
|
*/
|
||||||
|
export async function initWasm (): Promise<void> {
|
||||||
|
await initBridge(createWasm);
|
||||||
}
|
}
|
||||||
|
|
||||||
setWasmPromiseFn(initWasm);
|
initWasm().catch((): void => {
|
||||||
|
// cannot happen, initWasm doesn't throw
|
||||||
|
});
|
||||||
|
|||||||
@@ -1,13 +1,23 @@
|
|||||||
// Copyright 2019-2022 @polkadot/wasm-crypto authors & contributors
|
// Copyright 2019-2022 @polkadot/wasm-crypto authors & contributors
|
||||||
// SPDX-License-Identifier: Apache-2.0
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
import { asmJsInit } from '@polkadot/wasm-crypto-asmjs';
|
import { createWasm } from '@polkadot/wasm-crypto-init/both';
|
||||||
import { wasmBytes } from '@polkadot/wasm-crypto-wasm';
|
|
||||||
|
|
||||||
import { setWasmPromise, setWasmPromiseFn } from './init';
|
import { initBridge } from './init';
|
||||||
|
|
||||||
export function initWasm (): Promise<void> {
|
/**
|
||||||
return setWasmPromise(wasmBytes, asmJsInit);
|
* @name initWasm
|
||||||
|
* @description
|
||||||
|
* For historic purposes and for tighter control on init, specifically performing
|
||||||
|
* a WASM initialization with ASM and an ASM.js fallback
|
||||||
|
*
|
||||||
|
* Generally should not be used unless you want explicit control over which
|
||||||
|
* interfaces are initialized.
|
||||||
|
*/
|
||||||
|
export async function initWasm (): Promise<void> {
|
||||||
|
await initBridge(createWasm);
|
||||||
}
|
}
|
||||||
|
|
||||||
setWasmPromiseFn(initWasm);
|
initWasm().catch((): void => {
|
||||||
|
// cannot happen, initWasm doesn't throw
|
||||||
|
});
|
||||||
|
|||||||
@@ -0,0 +1,4 @@
|
|||||||
|
// Copyright 2019-2022 @polkadot/wasm-crypto authors & contributors
|
||||||
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
|
export * from './index';
|
||||||
@@ -3,4 +3,4 @@
|
|||||||
|
|
||||||
// Do not edit, auto-generated by @polkadot/dev
|
// Do not edit, auto-generated by @polkadot/dev
|
||||||
|
|
||||||
export const packageInfo = { name: '@polkadot/wasm-crypto', path: 'auto', type: 'auto', version: '5.1.1' };
|
export const packageInfo = { name: '@polkadot/wasm-crypto', path: 'auto', type: 'auto', version: '6.1.3' };
|
||||||
|
|||||||
@@ -22,8 +22,8 @@ fn new_from_parts(pubkey: &[u8], seckey: &[u8]) -> Keypair {
|
|||||||
///
|
///
|
||||||
/// * seed: UIntArray with 32 element
|
/// * seed: UIntArray with 32 element
|
||||||
///
|
///
|
||||||
/// returned vector is the concatenation of first the private key (64 bytes)
|
/// returned vector is the concatenation of first the seed (32 bytes)
|
||||||
/// followed by the public key (32) bytes.
|
/// followed by the public key (32) bytes, as the full secret keys.
|
||||||
#[wasm_bindgen]
|
#[wasm_bindgen]
|
||||||
pub fn ext_ed_from_seed(seed: &[u8]) -> Vec<u8> {
|
pub fn ext_ed_from_seed(seed: &[u8]) -> Vec<u8> {
|
||||||
match &SecretKey::from_bytes(seed) {
|
match &SecretKey::from_bytes(seed) {
|
||||||
|
|||||||
@@ -1,11 +1,19 @@
|
|||||||
// Copyright 2019-2022 @polkadot/wasm-crypto authors & contributors
|
// Copyright 2019-2022 @polkadot/wasm-crypto authors & contributors
|
||||||
// SPDX-License-Identifier: Apache-2.0
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
const rootIncl = ['@polkadot/wasm-crypto', '@polkadot/wasm-crypto-asmjs', '@polkadot/wasm-crypto-wasm'];
|
const rootIncl = [
|
||||||
|
'@polkadot/wasm-bridge',
|
||||||
|
'@polkadot/wasm-crypto',
|
||||||
|
'@polkadot/wasm-crypto-init',
|
||||||
|
'@polkadot/wasm-crypto-asmjs',
|
||||||
|
'@polkadot/wasm-crypto-wasm',
|
||||||
|
'@polkadot/wasm-util'
|
||||||
|
];
|
||||||
|
|
||||||
const detcIncl = [
|
const detcIncl = [
|
||||||
...rootIncl.map((p) => `${p}/initOnlyAsm.cjs`),
|
...rootIncl.map((p) => `${p}/initOnlyAsm`),
|
||||||
...rootIncl.map((p) => `${p}/initOnlyWasm.cjs`),
|
...rootIncl.map((p) => `${p}/cjs/asm`),
|
||||||
...rootIncl.map((p) => `${p}/packageInfo.cjs`)
|
...rootIncl.map((p) => `${p}/cjs/packageInfo`)
|
||||||
];
|
];
|
||||||
|
|
||||||
require('override-require')(
|
require('override-require')(
|
||||||
@@ -14,10 +22,12 @@ require('override-require')(
|
|||||||
detcIncl.some((p) => request.endsWith(p)),
|
detcIncl.some((p) => request.endsWith(p)),
|
||||||
(request) =>
|
(request) =>
|
||||||
rootIncl.some((p) => request.endsWith(p))
|
rootIncl.some((p) => request.endsWith(p))
|
||||||
? require(`${rootIncl.find((p) => request.endsWith(p))}/build/index.cjs`)
|
? rootIncl.find((p) => request.endsWith(p)) === '@polkadot/wasm-crypto-init'
|
||||||
|
? require('@polkadot/wasm-crypto-init/build/cjs/wasm')
|
||||||
|
: require(`${rootIncl.find((p) => request.endsWith(p))}/build/cjs`)
|
||||||
: require(`${detcIncl.find((p) => request.endsWith(p))
|
: require(`${detcIncl.find((p) => request.endsWith(p))
|
||||||
.replace('initOnlyAsm.cjs', 'build/initOnlyAsm.cjs')
|
.replace('/initOnlyAsm', '/build/cjs/initOnlyAsm.js')
|
||||||
.replace('initOnlyWasm.cjs', 'build/initOnlyWasm.cjs')
|
.replace('/cjs/asm', '/build/cjs/asm.js')
|
||||||
.replace('packageInfo.cjs', 'build/packageInfo.cjs')
|
.replace('/cjs/packageInfo', '/build/cjs/packageInfo.js')
|
||||||
}`)
|
}`)
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -1,7 +1,9 @@
|
|||||||
// Copyright 2019-2022 @polkadot/wasm-crypto authors & contributors
|
// Copyright 2019-2022 @polkadot/wasm-crypto authors & contributors
|
||||||
// SPDX-License-Identifier: Apache-2.0
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
const wasm = require('../../build/index.cjs');
|
const { assert } = require('@polkadot/util');
|
||||||
|
|
||||||
|
const wasm = require('../../build');
|
||||||
const bip39 = require('./bip39.cjs');
|
const bip39 = require('./bip39.cjs');
|
||||||
const ed25519 = require('./ed25519.cjs');
|
const ed25519 = require('./ed25519.cjs');
|
||||||
const hashing = require('./hashing.cjs');
|
const hashing = require('./hashing.cjs');
|
||||||
@@ -21,8 +23,14 @@ const tests = {
|
|||||||
...hashing
|
...hashing
|
||||||
};
|
};
|
||||||
|
|
||||||
function beforeAll () {
|
async function beforeAll (name) {
|
||||||
return wasm.waitReady();
|
const result = await wasm.waitReady();
|
||||||
|
|
||||||
|
console.log(`*** waitReady()=${result} for ${wasm.bridge.type}`);
|
||||||
|
|
||||||
|
assert(name.toLowerCase() === wasm.bridge.type, `Incorrect environment laucnhed, expected ${name.toLowerCase()}, found ${wasm.bridge.type}`);
|
||||||
|
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
function runAll (name) {
|
function runAll (name) {
|
||||||
@@ -30,16 +38,18 @@ function runAll (name) {
|
|||||||
let count = 0;
|
let count = 0;
|
||||||
|
|
||||||
Object.keys(tests).forEach((name) => {
|
Object.keys(tests).forEach((name) => {
|
||||||
|
const timerId = `\t${name}`;
|
||||||
|
|
||||||
count++;
|
count++;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
console.time(name);
|
console.time(timerId);
|
||||||
console.log();
|
console.log();
|
||||||
console.log(name);
|
console.log(timerId);
|
||||||
|
|
||||||
tests[name](wasm);
|
tests[name](wasm);
|
||||||
|
|
||||||
console.timeEnd(name);
|
console.timeEnd(timerId);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error();
|
console.error();
|
||||||
console.error(error);
|
console.error(error);
|
||||||
@@ -56,7 +66,7 @@ function runAll (name) {
|
|||||||
function runUnassisted (name) {
|
function runUnassisted (name) {
|
||||||
console.log(`\n*** ${name}: Running tests`);
|
console.log(`\n*** ${name}: Running tests`);
|
||||||
|
|
||||||
beforeAll()
|
beforeAll(name)
|
||||||
.then(() => runAll(name))
|
.then(() => runAll(name))
|
||||||
.then(() => {
|
.then(() => {
|
||||||
console.log(`\n*** ${name}: All passed`);
|
console.log(`\n*** ${name}: All passed`);
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
// SPDX-License-Identifier: Apache-2.0
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
require('./alias-imports.cjs');
|
require('./alias-imports.cjs');
|
||||||
require('@polkadot/wasm-crypto/initOnlyAsm.cjs');
|
require('@polkadot/wasm-crypto/initOnlyAsm');
|
||||||
|
|
||||||
const { runUnassisted } = require('./all/index.cjs');
|
const { runUnassisted } = require('./all/index.cjs');
|
||||||
|
|
||||||
|
|||||||
@@ -5,11 +5,11 @@
|
|||||||
* @jest-environment jsdom
|
* @jest-environment jsdom
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { beforeAll, tests, wasm } from './all/index.cjs';
|
import { beforeAll as beforeAllFn, tests, wasm } from './all/index.cjs';
|
||||||
|
|
||||||
describe('wasm-crypto', () => {
|
describe('wasm-crypto', () => {
|
||||||
beforeEach(async () => {
|
beforeAll(async () => {
|
||||||
await beforeAll();
|
await beforeAllFn('wasm');
|
||||||
});
|
});
|
||||||
|
|
||||||
Object.keys(tests).forEach((name) => {
|
Object.keys(tests).forEach((name) => {
|
||||||
|
|||||||
@@ -6,7 +6,10 @@
|
|||||||
"rootDir": "./src"
|
"rootDir": "./src"
|
||||||
},
|
},
|
||||||
"references": [
|
"references": [
|
||||||
|
{ "path": "../wasm-bridge/tsconfig.build.json" },
|
||||||
|
{ "path": "../wasm-crypto-init/tsconfig.build.json" },
|
||||||
{ "path": "../wasm-crypto-asmjs/tsconfig.build.json" },
|
{ "path": "../wasm-crypto-asmjs/tsconfig.build.json" },
|
||||||
{ "path": "../wasm-crypto-wasm/tsconfig.build.json" }
|
{ "path": "../wasm-crypto-wasm/tsconfig.build.json" },
|
||||||
|
{ "path": "../wasm-util/tsconfig.build.json" }
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1 @@
|
|||||||
|
## @polkadot/wasm-util
|
||||||
@@ -0,0 +1,34 @@
|
|||||||
|
{
|
||||||
|
"author": "Jaco Greeff <jacogr@gmail.com>",
|
||||||
|
"bugs": "https://github.com/polkadot-js/wasm/issues",
|
||||||
|
"contributors": [],
|
||||||
|
"description": "Utilities used exclusively inside Wasm decoding",
|
||||||
|
"engines": {
|
||||||
|
"node": ">=14.0.0"
|
||||||
|
},
|
||||||
|
"homepage": "https://github.com/polkadot-js/wasm/tree/master/packages/wasm-util#readme",
|
||||||
|
"license": "Apache-2.0",
|
||||||
|
"maintainers": [],
|
||||||
|
"name": "@polkadot/wasm-util",
|
||||||
|
"repository": {
|
||||||
|
"directory": "packages/wasm-util",
|
||||||
|
"type": "git",
|
||||||
|
"url": "https://github.com/polkadot-js/wasm.git"
|
||||||
|
},
|
||||||
|
"sideEffects": [
|
||||||
|
"./detectPackage.js",
|
||||||
|
"./detectPackage.cjs"
|
||||||
|
],
|
||||||
|
"type": "module",
|
||||||
|
"version": "6.1.3",
|
||||||
|
"main": "index.js",
|
||||||
|
"dependencies": {
|
||||||
|
"@babel/runtime": "^7.18.3"
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"@polkadot/util": "^9.5.1"
|
||||||
|
},
|
||||||
|
"peerDependencies": {
|
||||||
|
"@polkadot/util": "*"
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,9 +1,18 @@
|
|||||||
// Copyright 2019-2022 @polkadot/wasm-crypto authors & contributors
|
// Copyright 2019-2022 @polkadot/wasm-util authors & contributors
|
||||||
// SPDX-License-Identifier: Apache-2.0
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
const chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
|
const chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @name base64Decode
|
||||||
|
* @description
|
||||||
|
* A fail-safe base64Decoding function that operates in all environments. Unlike
|
||||||
|
* decoding from Buffer (Node.js only) or atob (browser-only) this implementation
|
||||||
|
* is slightly slower, but it is platform independent.
|
||||||
|
*/
|
||||||
export function base64Decode (data: string): Uint8Array {
|
export function base64Decode (data: string): Uint8Array {
|
||||||
|
// TODO: For Node.js speedups, we could add an explicit base64Node.ts implementation
|
||||||
|
// that would be (via export maps) be available in that environment only
|
||||||
const bytes = [];
|
const bytes = [];
|
||||||
let byte = 0;
|
let byte = 0;
|
||||||
let bits = 0;
|
let bits = 0;
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
// Copyright 2019-2022 @polkadot/wasm-util authors & contributors
|
||||||
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
|
export { base64Decode } from './base64';
|
||||||
|
export { unzlibSync } from './fflate';
|
||||||
|
export { packageInfo } from './packageInfo';
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
// Copyright 2019-2022 @polkadot/wasm-util authors & contributors
|
||||||
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
|
import { packageInfo as utilInfo } from '@polkadot/wasm-util/packageInfo';
|
||||||
|
|
||||||
|
export default [utilInfo];
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
// Copyright 2017-2022 @polkadot/wasm-util authors & contributors
|
||||||
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
|
// Do not edit, auto-generated by @polkadot/dev
|
||||||
|
|
||||||
|
import { detectPackage } from '@polkadot/util';
|
||||||
|
|
||||||
|
import others from './detectOther';
|
||||||
|
import { packageInfo } from './packageInfo';
|
||||||
|
|
||||||
|
detectPackage(packageInfo, null, others);
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
// Copyright 2019-2022 @polkadot/wasm-crypto authors & contributors
|
// Copyright 2019-2022 @polkadot/wasm-util authors & contributors
|
||||||
// SPDX-License-Identifier: Apache-2.0
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
// MIT License
|
// MIT License
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
// Copyright 2019-2022 @polkadot/wasm-util authors & contributors
|
||||||
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
|
import './detectPackage';
|
||||||
|
|
||||||
|
export * from './bundle';
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
// Copyright 2019-2022 @polkadot/wasm-util authors & contributors
|
||||||
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
|
export * from './index';
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
// Copyright 2017-2022 @polkadot/wasm-util authors & contributors
|
||||||
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
|
// Do not edit, auto-generated by @polkadot/dev
|
||||||
|
|
||||||
|
export const packageInfo = { name: '@polkadot/wasm-util', path: 'auto', type: 'auto', version: '6.1.3' };
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
{
|
||||||
|
"extends": "../../tsconfig.base.json",
|
||||||
|
"compilerOptions": {
|
||||||
|
"baseUrl": "..",
|
||||||
|
"outDir": "./build",
|
||||||
|
"rootDir": "./src"
|
||||||
|
},
|
||||||
|
"references": []
|
||||||
|
}
|
||||||
+15
-8
@@ -12,14 +12,21 @@ const external = [
|
|||||||
'@polkadot/util'
|
'@polkadot/util'
|
||||||
];
|
];
|
||||||
|
|
||||||
const overrides = {
|
const overrides = pkgs
|
||||||
'@polkadot/wasm-crypto': {
|
.map((n) => n.replace('@polkadot/wasm-', ''))
|
||||||
entries: ['asmjs', 'wasm'].map((p) => `wasm-crypto-${p}`).reduce((all, p) => ({
|
.reduce((map, n) => ({
|
||||||
...all,
|
...map,
|
||||||
[`@polkadot/${p}`]: `../../${p}/build`
|
[`@polkadot/wasm-${n}`]: {
|
||||||
}), {})
|
entries: [
|
||||||
}
|
'bridge',
|
||||||
};
|
'util',
|
||||||
|
...['init', 'asmjs', 'wasm'].map((p) => `${n}-${p}`)
|
||||||
|
].reduce((all, p) => ({
|
||||||
|
...all,
|
||||||
|
[`@polkadot/wasm-${p}`]: `../../wasm-${p}/build/bundle.js`
|
||||||
|
}), {})
|
||||||
|
}
|
||||||
|
}), {});
|
||||||
|
|
||||||
export default pkgs.map((pkg) =>
|
export default pkgs.map((pkg) =>
|
||||||
createBundle({
|
createBundle({
|
||||||
|
|||||||
@@ -5,7 +5,5 @@
|
|||||||
|
|
||||||
set -e
|
set -e
|
||||||
|
|
||||||
DEST=packages/wasm-crypto/build/esm
|
|
||||||
|
|
||||||
./scripts/clean-js.sh
|
./scripts/clean-js.sh
|
||||||
yarn polkadot-dev-build-ts
|
yarn polkadot-dev-build-ts
|
||||||
|
|||||||
+20
-7
@@ -7,13 +7,15 @@ set -e
|
|||||||
|
|
||||||
source ../scripts/rust-version.sh
|
source ../scripts/rust-version.sh
|
||||||
|
|
||||||
WSM=bytes/wasm_bg.wasm
|
WSM=$PKG_NAME/build-wasm/wasm_bg.wasm
|
||||||
OPT=bytes/wasm_opt.wasm
|
OPT=$PKG_NAME/build-wasm/wasm_opt.wasm
|
||||||
ASM=wasm-crypto-asmjs/build/cjs/data.js
|
ASM=$PKG_NAME-asmjs/build/cjs/data.js
|
||||||
|
DENO_DIR=$PKG_NAME-asmjs/build-deno/deno
|
||||||
|
DENO_ASM=$DENO_DIR/data.js
|
||||||
|
|
||||||
# build new via wasm-pack
|
# build new via wasm-pack
|
||||||
echo "*** Building Rust sources"
|
echo "*** Building Rust sources"
|
||||||
cd wasm-crypto
|
cd $PKG_NAME
|
||||||
if [ "$RUST_VER" == "stable" ]; then
|
if [ "$RUST_VER" == "stable" ]; then
|
||||||
RUSTC_BOOTSTRAP=1 cargo build --target wasm32-unknown-unknown --release -Z build-std=std,panic_abort
|
RUSTC_BOOTSTRAP=1 cargo build --target wasm32-unknown-unknown --release -Z build-std=std,panic_abort
|
||||||
else
|
else
|
||||||
@@ -22,7 +24,7 @@ fi
|
|||||||
cd ..
|
cd ..
|
||||||
|
|
||||||
echo "*** Converting to WASM"
|
echo "*** Converting to WASM"
|
||||||
../bindgen/wasm-bindgen wasm-crypto/target/wasm32-unknown-unknown/release/wasm.wasm --out-dir bytes --target web
|
../bindgen/wasm-bindgen $PKG_NAME/target/wasm32-unknown-unknown/release/wasm.wasm --out-dir $PKG_NAME/build-wasm --target web
|
||||||
|
|
||||||
# optimise
|
# optimise
|
||||||
echo "*** Optimising WASM output"
|
echo "*** Optimising WASM output"
|
||||||
@@ -36,11 +38,22 @@ node ../scripts/pack-wasm-base.cjs
|
|||||||
echo "*** Building asm.js version"
|
echo "*** Building asm.js version"
|
||||||
../binaryen/bin/wasm2js -Oz --output $ASM $OPT
|
../binaryen/bin/wasm2js -Oz --output $ASM $OPT
|
||||||
|
|
||||||
|
# copy the deno version
|
||||||
|
mkdir -p $DENO_DIR
|
||||||
|
cp $ASM $DENO_ASM
|
||||||
|
|
||||||
# cleanup the generated asm, converting to cjs
|
# cleanup the generated asm, converting to cjs
|
||||||
sed -i -e '/import {/d' $ASM
|
sed -i -e '/import {/d' $ASM
|
||||||
sed -i -e '1,/var retasmFunc = /!d' $ASM
|
sed -i -e '1,/var retasmFunc = /!d' $ASM
|
||||||
sed -i -e 's/var retasmFunc = .*/const asmJsInit = (wbg) => asmFunc(wbg);\n\nmodule.exports = { asmJsInit };/g' $ASM
|
sed -i -e 's/var retasmFunc = .*/const asmJsInit = (wbg) => asmFunc(wbg);\n\nmodule.exports = { asmJsInit };/g' $ASM
|
||||||
|
|
||||||
|
# same as the cjs version, this time for deno
|
||||||
|
sed -i -e '/import {/d' $DENO_ASM
|
||||||
|
sed -i -e '1,/var retasmFunc = /!d' $DENO_ASM
|
||||||
|
sed -i -e 's/var retasmFunc = .*/export const asmJsInit = (wbg) => asmFunc(wbg);/g' $DENO_ASM
|
||||||
|
|
||||||
# cleanups
|
# cleanups
|
||||||
rm -rf wasm-crypto-asmjs/build/cjs/*-e
|
rm -rf $PKG_NAME-asmjs/build/cjs/*-e
|
||||||
rm -rf wasm-crypto-wasm/build/cjs/*-e
|
rm -rf $PKG_NAME-asmjs/build-deno/deno/*-e
|
||||||
|
rm -rf $PKG_NAME-wasm/build/cjs/*-e
|
||||||
|
rm -rf $PKG_NAME-wasm/build-deno/deno/*-e
|
||||||
|
|||||||
+2
-2
@@ -11,9 +11,9 @@ echo "*** Building JavaScript"
|
|||||||
echo "*** Building WASM"
|
echo "*** Building WASM"
|
||||||
cd packages
|
cd packages
|
||||||
|
|
||||||
../scripts/build-wasm.sh
|
PKG_NAME=wasm-crypto ../scripts/build-wasm.sh
|
||||||
|
|
||||||
yarn test:wasm:js
|
yarn test:wasm-crypto:js
|
||||||
|
|
||||||
echo ""
|
echo ""
|
||||||
echo "*** wasm-crypto"
|
echo "*** wasm-crypto"
|
||||||
|
|||||||
+1
-1
@@ -7,4 +7,4 @@ set -e
|
|||||||
|
|
||||||
# cleanup old
|
# cleanup old
|
||||||
echo "*** Cleaning old builds"
|
echo "*** Cleaning old builds"
|
||||||
rm -rf build packages/*/build packages/bytes
|
rm -rf build packages/*/build*
|
||||||
|
|||||||
@@ -3,16 +3,18 @@
|
|||||||
|
|
||||||
const fflate = require('fflate/node');
|
const fflate = require('fflate/node');
|
||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
|
const mkdirp = require('mkdirp');
|
||||||
const { formatNumber } = require('@polkadot/util');
|
const { formatNumber } = require('@polkadot/util');
|
||||||
|
|
||||||
const W_NAME = 'wasm-crypto-wasm';
|
const data = fs.readFileSync(`./${process.env.PKG_NAME}/build-wasm/wasm_opt.wasm`);
|
||||||
|
|
||||||
const data = fs.readFileSync('./bytes/wasm_opt.wasm');
|
|
||||||
const compressed = Buffer.from(fflate.zlibSync(data, { level: 9 }));
|
const compressed = Buffer.from(fflate.zlibSync(data, { level: 9 }));
|
||||||
|
const denoDir = `./${process.env.PKG_NAME}-wasm/build-deno/deno`;
|
||||||
|
|
||||||
console.log(`*** Compressed WASM: ${formatNumber(data.length)} -> ${formatNumber(compressed.length)} (${(100 * compressed.length / data.length).toFixed(2)}%)`);
|
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-2022 @polkadot/${W_NAME} authors & contributors
|
mkdirp.sync(denoDir);
|
||||||
|
|
||||||
|
fs.writeFileSync(`./${process.env.PKG_NAME}-wasm/build/cjs/bytes.js`, `// Copyright 2019-${new Date().getFullYear()} @polkadot/${process.env.PKG_NAME}-wasm authors & contributors
|
||||||
// SPDX-License-Identifier: Apache-2.0
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
// Generated as part of the build, do not edit
|
// Generated as part of the build, do not edit
|
||||||
@@ -23,3 +25,15 @@ const bytes = '${compressed.toString('base64')}';
|
|||||||
|
|
||||||
module.exports = { bytes, sizeCompressed, sizeUncompressed };
|
module.exports = { bytes, sizeCompressed, sizeUncompressed };
|
||||||
`);
|
`);
|
||||||
|
|
||||||
|
fs.writeFileSync(`${denoDir}/bytes.js`, `// Copyright 2019-${new Date().getFullYear()} @polkadot/${process.env.PKG_NAME}-wasm authors & contributors
|
||||||
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
|
// Generated as part of the build, do not edit
|
||||||
|
|
||||||
|
export const sizeCompressed = ${compressed.length};
|
||||||
|
|
||||||
|
export const sizeUncompressed = ${data.length};
|
||||||
|
|
||||||
|
export const bytes = '${compressed.toString('base64')}';
|
||||||
|
`);
|
||||||
|
|||||||
+9
-3
@@ -3,11 +3,17 @@
|
|||||||
"compilerOptions": {
|
"compilerOptions": {
|
||||||
"composite": true,
|
"composite": true,
|
||||||
"paths": {
|
"paths": {
|
||||||
"@polkadot/wasm-crypto-asmjs/packageInfo": ["wasm-crypto-asmjs/src/packageInfo"],
|
"@polkadot/wasm-bridge": ["wasm-bridge/src"],
|
||||||
|
"@polkadot/wasm-bridge/*": ["wasm-bridge/src/*"],
|
||||||
"@polkadot/wasm-crypto-asmjs": ["wasm-crypto-asmjs/src"],
|
"@polkadot/wasm-crypto-asmjs": ["wasm-crypto-asmjs/src"],
|
||||||
"@polkadot/wasm-crypto-wasm/packageInfo": ["wasm-crypto-wasm/src/packageInfo"],
|
"@polkadot/wasm-crypto-asmjs/*": ["wasm-crypto-asmjs/src/*"],
|
||||||
"@polkadot/wasm-crypto-wasm": ["wasm-crypto-wasm/src"],
|
"@polkadot/wasm-crypto-wasm": ["wasm-crypto-wasm/src"],
|
||||||
"@polkadot/wasm-crypto": ["wasm-crypto/src"]
|
"@polkadot/wasm-crypto-wasm/*": ["wasm-crypto-wasm/src/*"],
|
||||||
|
"@polkadot/wasm-crypto-init": ["wasm-crypto-init/src/wasm"],
|
||||||
|
"@polkadot/wasm-crypto-init/*": ["wasm-crypto-init/src/*"],
|
||||||
|
"@polkadot/wasm-crypto": ["wasm-crypto/src"],
|
||||||
|
"@polkadot/wasm-util": ["wasm-util/src"],
|
||||||
|
"@polkadot/wasm-util/*": ["wasm-util/src/*"],
|
||||||
},
|
},
|
||||||
"skipLibCheck": true
|
"skipLibCheck": true
|
||||||
}
|
}
|
||||||
|
|||||||
+3
-1
@@ -5,7 +5,9 @@
|
|||||||
"files": [],
|
"files": [],
|
||||||
"references": [
|
"references": [
|
||||||
{ "path": "./packages/wasm-crypto/tsconfig.build.json" },
|
{ "path": "./packages/wasm-crypto/tsconfig.build.json" },
|
||||||
|
{ "path": "./packages/wasm-crypto-init/tsconfig.build.json" },
|
||||||
{ "path": "./packages/wasm-crypto-asmjs/tsconfig.build.json" },
|
{ "path": "./packages/wasm-crypto-asmjs/tsconfig.build.json" },
|
||||||
{ "path": "./packages/wasm-crypto-wasm/tsconfig.build.json" }
|
{ "path": "./packages/wasm-crypto-wasm/tsconfig.build.json" },
|
||||||
|
{ "path": "./packages/wasm-util/tsconfig.build.json" }
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user