mirror of
https://github.com/pezkuwichain/pezkuwi-wasm.git
synced 2026-11-02 08:11:06 +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
@@ -19,7 +19,7 @@
|
||||
],
|
||||
"type": "module",
|
||||
"types": "./build/index.d.ts",
|
||||
"version": "7.5.15",
|
||||
"version": "7.5.19",
|
||||
"main": "./build/cjs/index.js",
|
||||
"module": "./build/index.js",
|
||||
"exports": {
|
||||
@@ -154,7 +154,7 @@
|
||||
}
|
||||
},
|
||||
"dependencies": {
|
||||
"@pezkuwi/wasm-util": "7.5.15",
|
||||
"@pezkuwi/wasm-util": "7.5.19",
|
||||
"tslib": "^2.7.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
|
||||
@@ -175,7 +175,9 @@ export class Bridge<C extends WasmBaseInstance> implements BridgeBase<C> {
|
||||
* @description Allocates an Uint8Array in the WASM interface
|
||||
*/
|
||||
allocU8a (arg: Uint8Array): [number, number] {
|
||||
const ptr = this.#wasm!.__wbindgen_malloc(arg.length * 1);
|
||||
// wasm-bindgen >= 0.2.88 takes the alignment as a second argument; without it
|
||||
// the Rust side builds a zero-aligned Layout and aborts with `unreachable`.
|
||||
const ptr = this.#wasm!.__wbindgen_malloc(arg.length * 1, 1);
|
||||
|
||||
this.getUint8().set(arg, ptr / 1);
|
||||
|
||||
@@ -199,7 +201,7 @@ export class Bridge<C extends WasmBaseInstance> implements BridgeBase<C> {
|
||||
const r1 = this.getInt32()[8 / 4 + 1];
|
||||
const ret = this.getU8a(r0, r1).slice();
|
||||
|
||||
this.#wasm!.__wbindgen_free(r0, r1 * 1);
|
||||
this.#wasm!.__wbindgen_free(r0, r1 * 1, 1);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -3,4 +3,4 @@
|
||||
|
||||
// Do not edit, auto-generated by @pezkuwi/dev
|
||||
|
||||
export const packageInfo = { name: '@pezkuwi/wasm-bridge', path: 'auto', type: 'auto', version: '7.5.15' };
|
||||
export const packageInfo = { name: '@pezkuwi/wasm-bridge', path: 'auto', type: 'auto', version: '7.5.19' };
|
||||
@@ -37,9 +37,9 @@ export interface BridgeBase<C extends WasmBaseInstance> extends InitResult<C> {
|
||||
|
||||
export interface WasmBindGen {
|
||||
__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;
|
||||
__wbindgen_free (ptr: number, len: number, align: number): void;
|
||||
__wbindgen_malloc (len: number, align: number): number;
|
||||
__wbindgen_realloc (ptr: number, oldLen: number, newLen: number, align: number): number;
|
||||
}
|
||||
|
||||
export interface WasmBaseInstance extends WasmBindGen {
|
||||
|
||||
@@ -127,9 +127,13 @@ export class Wbg<C extends WasmBaseInstance> {
|
||||
DEFAULT_CRYPTO.getRandomValues(this.#bridge.getU8a(ptr, len));
|
||||
};
|
||||
|
||||
/** @internal - bizinikiwi wasm hash (2 arg version) */
|
||||
__wbg_getRandomValues_cd175915511f705e = (ptr: number, len: number): void => {
|
||||
DEFAULT_CRYPTO.getRandomValues(this.#bridge.getU8a(ptr, len));
|
||||
/**
|
||||
* @internal - wasm-bindgen 0.2.90: both arguments are heap indices, the crypto
|
||||
* object and a Uint8Array created on the JS side (__wbg_newwithlength), not a
|
||||
* pointer into wasm memory. getrandom copies the filled array in afterwards.
|
||||
*/
|
||||
__wbg_getRandomValues_cd175915511f705e = (cryptoIdx: number, arrIdx: number): void => {
|
||||
(this.#bridge.getObject(cryptoIdx) as typeof DEFAULT_CRYPTO).getRandomValues(this.#bridge.getObject(arrIdx) as Uint8Array);
|
||||
};
|
||||
|
||||
/** @internal - old hash for compatibility */
|
||||
@@ -208,9 +212,12 @@ export class Wbg<C extends WasmBaseInstance> {
|
||||
// No-op, externref table is initialized by the runtime
|
||||
};
|
||||
|
||||
/** @internal - bizinikiwi wasm: memory accessor */
|
||||
__wbindgen_memory = (): WebAssembly.Memory => {
|
||||
return this.#bridge.wasm?.memory as WebAssembly.Memory;
|
||||
/**
|
||||
* @internal - wasm-bindgen 0.2.90: returns a heap index, which the wasm side
|
||||
* passes back to __wbg_buffer. Returning the Memory itself coerces to 0.
|
||||
*/
|
||||
__wbindgen_memory = (): number => {
|
||||
return this.#bridge.addObject(this.#bridge.wasm?.memory);
|
||||
};
|
||||
|
||||
/** @internal - bizinikiwi wasm: buffer accessor */
|
||||
|
||||
Reference in new issue
Block a user