Skip to content

Commit f04b7e8

Browse files
shesekjgriffiths
authored andcommitted
wasm: Exclude BIP38-related functions from WASM builds
Scrypt with the BIP38 parameters can't work due to WASM's memory restrictions. Also, remove excluded functions from the .wasm build itself by excluding them from wasm_exports.sh (previously they were only excluded from the JavaScript code generation).
1 parent cf5b900 commit f04b7e8

File tree

5 files changed

+12
-19
lines changed

5 files changed

+12
-19
lines changed

src/wasm_package/README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,5 +40,9 @@ WallyInit.then(wally => {
4040
</script>
4141
```
4242

43+
## Limitations
44+
45+
- BIP38 (passphrase-protected keys) [related functions](https://wally.readthedocs.io/en/latest/bip38/) are disabled due to WASM memory restrictions, which are insufficient for running Scrypt with the BIP38 parameters.
46+
4347
## License
4448
[BSD/MIT](https://github.com/ElementsProject/libwally-core/blob/master/LICENSE)

src/wasm_package/src/functions.js

Lines changed: 0 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/wasm_package/src/index.d.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,12 +90,8 @@ export function bip32_key_unserialize_noalloc(bytes: Buffer|Uint8Array, output:
9090
export function bip32_key_with_tweak_from_parent_path(hdkey: Ref_ext_key, child_path: Uint32Array|number[], flags: number): Ref_ext_key;
9191
export function bip32_key_with_tweak_from_parent_path_noalloc(hdkey: Ref_ext_key, child_path: Uint32Array|number[], flags: number, output: Ref_ext_key): void;
9292
export function bip340_tagged_hash(bytes: Buffer|Uint8Array, tag: string): Buffer;
93-
export function bip38_from_private_key(bytes: Buffer|Uint8Array, pass: Buffer|Uint8Array, flags: number): string;
9493
export function bip38_get_flags(bip38: string): number;
95-
export function bip38_raw_from_private_key(bytes: Buffer|Uint8Array, pass: Buffer|Uint8Array, flags: number): Buffer;
9694
export function bip38_raw_get_flags(bytes: Buffer|Uint8Array): number;
97-
export function bip38_raw_to_private_key(bytes: Buffer|Uint8Array, pass: Buffer|Uint8Array, flags: number): Buffer;
98-
export function bip38_to_private_key(bip38: string, pass: Buffer|Uint8Array, flags: number): Buffer;
9995
export function bip39_get_languages(): string;
10096
export function bip39_get_word(w: Ref_words, index: number): string;
10197
export function bip39_get_wordlist(lang: string): Ref_words;

tools/build_wrappers.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,12 @@
1616
'wally_map_get', 'wally_map_get_integer',
1717
}
1818

19+
# BIP38's Scrypt can't work due to WASM's memory restrictions
20+
WASM_EXCLUDED_FUNCS = EXCLUDED_FUNCS | {
21+
'bip38_from_private_key', 'bip38_raw_from_private_key',
22+
'bip38_raw_to_private_key', 'bip38_to_private_key',
23+
}
24+
1925
# Output buffer length functions that aren't yet part of the API
2026
# The boolean is whether the length function is a maximum length,
2127
# True = Yes, False = Exact length
@@ -347,7 +353,7 @@ def gen_wally_hpp(funcs, all_funcs):
347353

348354

349355
def gen_wasm_exports(funcs, all_funcs):
350-
funcs = sorted(funcs)
356+
funcs = sorted(filter(lambda f: f.name not in WASM_EXCLUDED_FUNCS, funcs))
351357
exports = ','.join([f"'_{func.name}' \\\n" for func in funcs if not func.is_elements])
352358
elements_exports = ','.join([f"'_{func.name}' \\\n" for func in funcs if func.is_elements])
353359

@@ -362,7 +368,6 @@ def gen_wasm_exports(funcs, all_funcs):
362368
[u'# BEGIN AUTOGENERATED', u'# END AUTOGENERATED'])
363369

364370
def gen_wasm_package(funcs, all_funcs):
365-
366371
# Simple single-argument types that can be identified without inspecting the next arguments
367372
# map of C type -> (JS type, TypeScript argument type, TypeScript return type)
368373
typemap_simple = {
@@ -501,7 +506,7 @@ def map_args(func):
501506
return (js_args, ts_args, ts_returns)
502507

503508
# Drop excluded functions
504-
fn_included = filter(lambda f: f.name not in EXCLUDED_FUNCS, funcs)
509+
fn_included = filter(lambda f: f.name not in WASM_EXCLUDED_FUNCS, funcs)
505510
# Place functions that depend on the buffer length utility functions last, so that the utility
506511
# functions are available to them. Then sort by name.
507512
key_fn = lambda f: (f.buffer_len_fn is not None, get_export_name(f.name, all_funcs))

tools/wasm_exports.sh

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,18 +36,13 @@ EXPORTED_FUNCTIONS="['_malloc','_free','_bip32_key_free' \
3636
,'_bip32_key_to_base58' \
3737
,'_bip32_key_unserialize' \
3838
,'_bip32_key_unserialize_alloc' \
39-
,'_bip38_from_private_key' \
4039
,'_bip38_get_flags' \
41-
,'_bip38_raw_from_private_key' \
4240
,'_bip38_raw_get_flags' \
43-
,'_bip38_raw_to_private_key' \
44-
,'_bip38_to_private_key' \
4541
,'_bip39_get_languages' \
4642
,'_bip39_get_word' \
4743
,'_bip39_get_wordlist' \
4844
,'_bip39_mnemonic_from_bytes' \
4945
,'_bip39_mnemonic_to_bytes' \
50-
,'_bip39_mnemonic_to_seed' \
5146
,'_bip39_mnemonic_to_seed512' \
5247
,'_bip39_mnemonic_validate' \
5348
,'_wally_addr_segwit_from_bytes' \
@@ -81,11 +76,8 @@ EXPORTED_FUNCTIONS="['_malloc','_free','_bip32_key_free' \
8176
,'_wally_ec_public_key_negate' \
8277
,'_wally_ec_public_key_verify' \
8378
,'_wally_ec_scalar_add' \
84-
,'_wally_ec_scalar_add_to' \
8579
,'_wally_ec_scalar_multiply' \
86-
,'_wally_ec_scalar_multiply_by' \
8780
,'_wally_ec_scalar_subtract' \
88-
,'_wally_ec_scalar_subtract_from' \
8981
,'_wally_ec_scalar_verify' \
9082
,'_wally_ec_sig_from_bytes' \
9183
,'_wally_ec_sig_from_bytes_len' \

0 commit comments

Comments
 (0)