Skip to content

wasm-js!: Move all implementations into sdk-wasm-js#244

Merged
joncinque merged 1 commit into
anza-xyz:masterfrom
joncinque:move-wasm
Jul 28, 2025
Merged

wasm-js!: Move all implementations into sdk-wasm-js#244
joncinque merged 1 commit into
anza-xyz:masterfrom
joncinque:move-wasm

Conversation

@joncinque
Copy link
Copy Markdown
Collaborator

@joncinque joncinque commented Jul 23, 2025

Problem

As outlined in #118, the sdk incorrectly assumes that all wasm builds are targeting a js environment, which breaks builds in non-js targets.

Summary of changes

The wasm-js code isn't strictly needed to make things work, so instead, move all of the code into different modules. This causes some copy-pasta, but keeps wasm builds lean. If people are using wasm-js, most likely they'll roll their own code anyway.

As part of this, since solana-keypair now uses rand 0.8, we can upgrade the getrandom backend to 0.2.

NOTE: Leaving in draft until CI passes All good!

Closes #118 Fixes #117 Fixes #241

#### Problem

As outlined in anza-xyz#118, the sdk incorrectly assumes that all wasm builds
are targeting a js environment, which breaks builds in non-js targets.

#### Summary of changes

The wasm-js code isn't strictly needed to make things work, so instead,
move all of the code into different modules. This causes some
copy-pasta, but keeps wasm builds lean. If people are using wasm-js,
most likely they'll roll their own code anyway.

As part of this, since solana-keypair now uses rand 0.8, we can upgrade
the getrandom backend to 0.2.
@joncinque joncinque added the breaking PR contains breaking changes label Jul 23, 2025
@joncinque joncinque requested a review from grod220 July 23, 2025 21:58
@joncinque joncinque marked this pull request as ready for review July 23, 2025 21:58
@joncinque joncinque requested a review from a team as a code owner July 23, 2025 21:58
@joncinque joncinque changed the title wasm-js: Move all implementations into sdk-wasm-js wasm-js!: Move all implementations into sdk-wasm-js Jul 23, 2025
Copy link
Copy Markdown
Contributor

@grod220 grod220 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Small comments, up to you!

Comment thread sdk-wasm-js/src/hash.rs
.map_err(|err| format!("Invalid Hash value: {err:?}").into())
} else if let Some(array) = value.dyn_ref::<Array>() {
let mut bytes = vec![];
let iterator = js_sys::try_iter(&array.values())?.expect("array to be iterable");
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know this is copied over and this probably beyond the scope of this PR, but there are a few unwraps and expects in the code. A panic here can't be caught on the JS side of things and causes an abort which could crash a node/browser process.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see two unwrap()s:

  • console_log::init_with_level
  • bincode::serialize(...)

We can probably fix those, since I could imagine those being fallible.

And the expects are both from js_sys::try_iter, after checking the underlying type is an Array and passing in array.values(), which is an Iterator. I think the expect there makes more sense because it should likely be a programmer error if the conversion fails.

Since @febo is waiting on this, I'll fix the unwraps in a follow-up

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It doesn't seem like it existed before, but instruction.rs looks like the only file in sdk-wasm-js with missing tests.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's mostly tested through transaction.mjs, where it actually gets compiled and all that. We could certainly add more tests in the future though.

Copy link
Copy Markdown
Contributor

@apfitzge apfitzge left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tx-metadata: lgtm

@joncinque joncinque merged commit b14d647 into anza-xyz:master Jul 28, 2025
26 checks passed
@joncinque joncinque deleted the move-wasm branch July 28, 2025 19:31
febo pushed a commit to febo/solana-sdk that referenced this pull request Sep 21, 2025
wasm-js: Move all implementations into sdk-wasm-js

As outlined in anza-xyz#118, the sdk incorrectly assumes that all wasm builds
are targeting a js environment, which breaks builds in non-js targets.

The wasm-js code isn't strictly needed to make things work, so instead,
move all of the code into different modules. This causes some
copy-pasta, but keeps wasm builds lean. If people are using wasm-js,
most likely they'll roll their own code anyway.

As part of this, since solana-keypair now uses rand 0.8, we can upgrade
the getrandom backend to 0.2.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

breaking PR contains breaking changes

Projects

None yet

3 participants