mirror of
https://github.com/pezkuwichain/pezkuwi-wasm.git
synced 2026-11-01 07:59:49 +00:00
Ship the whole wasm-crypto again, not just sr25519
7.5.15-7.5.18 shipped a wasm built from a separate sr25519-only module
(4 exports) and replaced every other function in bundle.ts with a stub
that throws "not yet implemented": ed25519 pair/sign/verify, sr25519
agree and hard/soft derivation, VRF, and all of secp256k1. Because the
wasm still initialised, isReady() was true and @pezkuwi/util-crypto
called those stubs instead of falling back to JS, so ed25519 and
ethereum accounts and any // derivation failed at runtime wherever the
package is used. bip39Generate threw as well, and bip39ToSeed hashed with
SHA-256 where BIP39 specifies SHA-512.
The Rust in packages/wasm-crypto/src/rs already implemented all of it,
with sr25519 under the "bizinikiwi" context. This builds that crate and
binds it again:
- bundle.ts: the withWasm bindings for every ext_* export, as in
b61206c; getSigningContext() kept, returning "bizinikiwi".
- wasm-bridge: wasm-bindgen 0.2.90 passes an alignment to
__wbindgen_malloc/__wbindgen_free (without it Rust aborts with
`unreachable`); __wbindgen_memory returns a heap index; the two-argument
getRandomValues import takes the crypto object and a Uint8Array by heap
index, not a pointer and length.
- build-wasm.sh: source rust-version.sh relative to the script; strip the
`import * as wbg` line newer wasm2js emits and call asmFunc({ wbg }),
which is the shape its output expects.
- pack-wasm-base.mjs: also write build/bytes.js. The package exports
./bytes from there for ESM, and it was still the old sr25519-only wasm.
The committed src copies are now empty placeholders, so a build that
skips the wasm step fails instead of shipping a stale binary.
- Tests: the sr25519 known-signature vectors were substrate-context
vectors; they are replaced by vectors signed by 7.5.18, plus a test that
the same seed yields the same public key. A rename had changed the
substrate-bip39 vector's password to "Bizinikiwi"; it is "Substrate".
Compatibility with 7.5.18, measured in separate processes:
mnemonic -> mini secret -> public key is identical for every phrase with
an empty or ASCII password (12/12). It differs when the BIP39 password has
characters NFKD changes: 7.5.18 normalised it, while the Rust crate and
util-crypto's JS path do not, so this returns to the canonical result.
Rust 43/43, JS 55/55, wasm and asm.js runners pass. With this build in
place, pezkuwi-extension's suite goes from 19 failing to 3 (the 3 left
are unrelated sorting tests).
All wasm packages move to 7.5.19 and pin each other at 7.5.19.
This commit is contained in:
1 parent
c3b5de65ae
commit
f1eee23fdf
27 files changed
+353
-666
No files matched your search
@@ -64,7 +64,9 @@ export function bip39ToEntropy (wasm) {
|
||||
*/
|
||||
export function bip39ToMiniSecret (wasm) {
|
||||
it('creates the correct minisecret from a mnemonic', () => {
|
||||
const res = u8aToHex(wasm.bip39ToMiniSecret('legal winner thank year wave sausage worth useful legal winner thank yellow', 'Bizinikiwi'));
|
||||
// The published substrate-bip39 vector: its password is the literal string below,
|
||||
// not a product name, so a rename must not touch it.
|
||||
const res = u8aToHex(wasm.bip39ToMiniSecret('legal winner thank year wave sausage worth useful legal winner thank yellow', 'Substrate'));
|
||||
|
||||
// console.log('\tMIN', res);
|
||||
|
||||
|
||||
@@ -56,9 +56,11 @@ export function sr25519DevFromSeed (wasm) {
|
||||
*/
|
||||
export function sr25519VerifyExisting (wasm) {
|
||||
it('verifies a known signature', () => {
|
||||
const PK = hexToU8a('0xd43593c715fdd31c61141abd04a99fd6822c8558854ccde39a5684e7a56da27d');
|
||||
const MESSAGE = stringToU8a('I hereby verify that I control 5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY');
|
||||
const SIGNATURE = hexToU8a('0xb83881d3bd7302981ee1c504fe5b7b394682927131fc0846fd616bb40fa14d02640fd2aca785b4cb57904765c2e4e75f59a7dd30154c209964369912091f6981');
|
||||
// Signed by @pezkuwi/wasm-crypto 7.5.18 under the "bizinikiwi" context, the build
|
||||
// whose signatures the chain has been accepting. Same vector as src/rs/sr25519.rs.
|
||||
const PK = hexToU8a('0x3288fbbb40584c61d8ee04e176fa339a1f1f6273b2a66d2eb12aafd1eb7b5e19');
|
||||
const MESSAGE = stringToU8a('I hereby verify that I control this key');
|
||||
const SIGNATURE = hexToU8a('0x065565b3c4cd1f2ff097a6372a67a8f7b3153e703378bf0acde013dcda79221485b3e7bf8d45e356a5a0fbf9cc332be54bff10158970daa5a5c55b15fb834181');
|
||||
|
||||
const isValid = wasm.sr25519Verify(SIGNATURE, MESSAGE, PK);
|
||||
|
||||
|
||||
Reference in new issue
Block a user