-
Notifications
You must be signed in to change notification settings - Fork 53
feat(wasm-sdk): add shielded pool WASM bindings and query methods #3235
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
QuantumExplorer
wants to merge
18
commits into
v3.1-dev
Choose a base branch
from
feat/zk-wasm-js-bindings
base: v3.1-dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
c5325c9
feat(wasm-dpp2,js-sdk): add shielded pool WASM bindings and JS SDK me…
QuantumExplorer 65c02a6
revert: remove js-dash-sdk and wasm-dpp changes from shielded PR
QuantumExplorer 8b71f68
feat(wasm-sdk): add shielded pool query methods
QuantumExplorer 3256346
feat(wasm-dpp2): implement shielded proof result wrappers
QuantumExplorer d08e087
fix(wasm-sdk): correct computePlatformSighash doc for extraData format
QuantumExplorer 98a20b6
fix(wasm-sdk): remove needless borrow in computePlatformSighash
QuantumExplorer 5d4ee20
fix(wasm): address PR review feedback for shielded bindings
QuantumExplorer 35b7ba4
fix(wasm-sdk): reject nullifiers that are not exactly 32 bytes
QuantumExplorer a87c6ad
Merge branch 'v3.1-dev' into feat/zk-wasm-js-bindings
QuantumExplorer 0b48cd3
Merge branch 'v3.1-dev' into feat/zk-wasm-js-bindings
QuantumExplorer 74e9290
feat(wasm): address all review feedback on shielded WASM bindings
QuantumExplorer 7f216ec
feat(wasm): improve TypeScript interface definitions per shumkov review
QuantumExplorer c6a73b7
fix(wasm): use base64 string for all byte fields in OrchardActionJSON
QuantumExplorer 4e29ccd
fix(wasm): use number | string for BigInt fields in JSON interfaces
QuantumExplorer fd850e1
fix(wasm): use typed parameters in shielded transition constructors
QuantumExplorer 2db3796
fix(wasm): correct TS types to match actual serde output
QuantumExplorer c55a943
Merge branch 'v3.1-dev' into feat/zk-wasm-js-bindings
QuantumExplorer c6a2b3f
fix(wasm): change $version to $formatVersion, add Options constructor
QuantumExplorer File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
packages/js-dash-sdk/src/SDK/Client/Platform/methods/shielded/shield.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| import broadcastStateTransition from '../../broadcastStateTransition'; | ||
| import { Platform } from '../../Platform'; | ||
| import { IStateTransitionResult } from '../../IStateTransitionResult'; | ||
|
|
||
| /** | ||
| * Broadcast a shield transition (transparent platform addresses -> shielded pool). | ||
| * | ||
| * The Orchard bundle, platform address witnesses, and full state transition | ||
| * must be built externally (e.g., via rs-sdk's `shield_funds()` or a native | ||
| * wallet library) and serialized to platform binary format. | ||
| * | ||
| * @param serializedTransition - Platform-serialized ShieldTransition bytes | ||
| * @returns Broadcast result | ||
| */ | ||
| export async function shield( | ||
| this: Platform, | ||
| serializedTransition: Uint8Array, | ||
| ): Promise<IStateTransitionResult> { | ||
| this.logger.debug('[Shielded#shield] Broadcasting shield transition'); | ||
| await this.initialize(); | ||
|
|
||
| const { dpp } = this; | ||
|
|
||
| const transition = dpp.stateTransition.createFromBuffer( | ||
| serializedTransition, | ||
| {}, | ||
| ); | ||
|
|
||
| const result = await broadcastStateTransition(this, await transition, { | ||
| skipValidation: true, | ||
| }); | ||
|
coderabbitai[bot] marked this conversation as resolved.
Outdated
|
||
|
|
||
| this.logger.silly('[Shielded#shield] Broadcasted ShieldTransition'); | ||
|
|
||
| return result; | ||
| } | ||
|
|
||
| export default shield; | ||
39 changes: 39 additions & 0 deletions
39
packages/js-dash-sdk/src/SDK/Client/Platform/methods/shielded/shieldFromAssetLock.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| import broadcastStateTransition from '../../broadcastStateTransition'; | ||
| import { Platform } from '../../Platform'; | ||
| import { IStateTransitionResult } from '../../IStateTransitionResult'; | ||
|
|
||
| /** | ||
| * Broadcast a shield-from-asset-lock transition (core asset lock -> shielded pool). | ||
| * | ||
| * The Orchard bundle, asset lock proof, ECDSA signature, and full state | ||
| * transition must be built externally (e.g., via rs-sdk's | ||
| * `shield_from_asset_lock()` or a native wallet library) and serialized | ||
| * to platform binary format. | ||
| * | ||
| * @param serializedTransition - Platform-serialized ShieldFromAssetLockTransition bytes | ||
| * @returns Broadcast result | ||
| */ | ||
| export async function shieldFromAssetLock( | ||
| this: Platform, | ||
| serializedTransition: Uint8Array, | ||
| ): Promise<IStateTransitionResult> { | ||
| this.logger.debug('[Shielded#shieldFromAssetLock] Broadcasting shield from asset lock'); | ||
| await this.initialize(); | ||
|
|
||
| const { dpp } = this; | ||
|
|
||
| const transition = dpp.stateTransition.createFromBuffer( | ||
| serializedTransition, | ||
| {}, | ||
| ); | ||
|
|
||
| const result = await broadcastStateTransition(this, await transition, { | ||
| skipValidation: true, | ||
| }); | ||
|
|
||
| this.logger.silly('[Shielded#shieldFromAssetLock] Broadcasted ShieldFromAssetLockTransition'); | ||
|
|
||
| return result; | ||
| } | ||
|
|
||
| export default shieldFromAssetLock; |
41 changes: 41 additions & 0 deletions
41
packages/js-dash-sdk/src/SDK/Client/Platform/methods/shielded/shieldedTransfer.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| import broadcastStateTransition from '../../broadcastStateTransition'; | ||
| import { Platform } from '../../Platform'; | ||
| import { IStateTransitionResult } from '../../IStateTransitionResult'; | ||
|
|
||
| /** | ||
| * Broadcast a shielded transfer (shielded-to-shielded) transition. | ||
| * | ||
| * The Orchard bundle and full state transition must be built externally | ||
| * (e.g., via rs-sdk's `transfer_shielded()` or a native wallet library) | ||
| * and serialized to platform binary format before passing here. | ||
| * | ||
| * Authentication is provided entirely by Orchard spend authorization | ||
| * signatures within the bundle — no identity signing needed. | ||
| * | ||
| * @param serializedTransition - Platform-serialized ShieldedTransferTransition bytes | ||
| * @returns Broadcast result | ||
| */ | ||
| export async function shieldedTransfer( | ||
| this: Platform, | ||
| serializedTransition: Uint8Array, | ||
| ): Promise<IStateTransitionResult> { | ||
| this.logger.debug('[Shielded#shieldedTransfer] Broadcasting shielded transfer'); | ||
| await this.initialize(); | ||
|
|
||
| const { dpp } = this; | ||
|
|
||
| const transition = dpp.stateTransition.createFromBuffer( | ||
| serializedTransition, | ||
| {}, | ||
| ); | ||
|
|
||
| const result = await broadcastStateTransition(this, await transition, { | ||
| skipValidation: true, | ||
| }); | ||
|
|
||
| this.logger.silly('[Shielded#shieldedTransfer] Broadcasted ShieldedTransferTransition'); | ||
|
|
||
| return result; | ||
| } | ||
|
|
||
| export default shieldedTransfer; |
41 changes: 41 additions & 0 deletions
41
packages/js-dash-sdk/src/SDK/Client/Platform/methods/shielded/shieldedWithdrawal.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| import broadcastStateTransition from '../../broadcastStateTransition'; | ||
| import { Platform } from '../../Platform'; | ||
| import { IStateTransitionResult } from '../../IStateTransitionResult'; | ||
|
|
||
| /** | ||
| * Broadcast a shielded withdrawal transition (shielded pool -> core L1 address). | ||
| * | ||
| * The Orchard bundle and full state transition must be built externally | ||
| * (e.g., via rs-sdk's `withdraw_shielded()` or a native wallet library) | ||
| * and serialized to platform binary format. | ||
| * | ||
| * The platform sighash binds `outputScript || amount` to prevent | ||
| * an attacker from substituting a different L1 destination or amount. | ||
| * | ||
| * @param serializedTransition - Platform-serialized ShieldedWithdrawalTransition bytes | ||
| * @returns Broadcast result | ||
| */ | ||
| export async function shieldedWithdrawal( | ||
| this: Platform, | ||
| serializedTransition: Uint8Array, | ||
| ): Promise<IStateTransitionResult> { | ||
| this.logger.debug('[Shielded#shieldedWithdrawal] Broadcasting shielded withdrawal'); | ||
| await this.initialize(); | ||
|
|
||
| const { dpp } = this; | ||
|
|
||
| const transition = dpp.stateTransition.createFromBuffer( | ||
| serializedTransition, | ||
| {}, | ||
| ); | ||
|
|
||
| const result = await broadcastStateTransition(this, await transition, { | ||
| skipValidation: true, | ||
| }); | ||
|
|
||
| this.logger.silly('[Shielded#shieldedWithdrawal] Broadcasted ShieldedWithdrawalTransition'); | ||
|
|
||
| return result; | ||
| } | ||
|
|
||
| export default shieldedWithdrawal; |
41 changes: 41 additions & 0 deletions
41
packages/js-dash-sdk/src/SDK/Client/Platform/methods/shielded/unshield.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| import broadcastStateTransition from '../../broadcastStateTransition'; | ||
| import { Platform } from '../../Platform'; | ||
| import { IStateTransitionResult } from '../../IStateTransitionResult'; | ||
|
|
||
| /** | ||
| * Broadcast an unshield transition (shielded pool -> platform address). | ||
| * | ||
| * The Orchard bundle and full state transition must be built externally | ||
| * (e.g., via rs-sdk's `unshield_funds()` or a native wallet library) | ||
| * and serialized to platform binary format. | ||
| * | ||
| * The platform sighash binds `outputAddress || amount` to prevent | ||
| * an attacker from substituting a different destination or amount. | ||
| * | ||
| * @param serializedTransition - Platform-serialized UnshieldTransition bytes | ||
| * @returns Broadcast result | ||
| */ | ||
| export async function unshield( | ||
| this: Platform, | ||
| serializedTransition: Uint8Array, | ||
| ): Promise<IStateTransitionResult> { | ||
| this.logger.debug('[Shielded#unshield] Broadcasting unshield transition'); | ||
| await this.initialize(); | ||
|
|
||
| const { dpp } = this; | ||
|
|
||
| const transition = dpp.stateTransition.createFromBuffer( | ||
| serializedTransition, | ||
| {}, | ||
| ); | ||
|
|
||
| const result = await broadcastStateTransition(this, await transition, { | ||
| skipValidation: true, | ||
| }); | ||
|
|
||
| this.logger.silly('[Shielded#unshield] Broadcasted UnshieldTransition'); | ||
|
|
||
| return result; | ||
| } | ||
|
|
||
| export default unshield; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| pub mod shield_from_asset_lock_transition; | ||
| pub mod shield_transition; | ||
| pub mod shielded_transfer_transition; | ||
| pub mod shielded_withdrawal_transition; | ||
| pub mod unshield_transition; | ||
|
|
||
| pub use shield_from_asset_lock_transition::ShieldFromAssetLockTransitionWasm; | ||
| pub use shield_transition::ShieldTransitionWasm; | ||
| pub use shielded_transfer_transition::ShieldedTransferTransitionWasm; | ||
| pub use shielded_withdrawal_transition::ShieldedWithdrawalTransitionWasm; | ||
| pub use unshield_transition::UnshieldTransitionWasm; | ||
|
|
||
| use crate::error::WasmDppResult; | ||
| use wasm_bindgen::prelude::wasm_bindgen; | ||
|
|
||
| /// Compute the platform sighash from an Orchard bundle commitment and extra data. | ||
| /// | ||
| /// `sighash = SHA-256("DashPlatformSighash" || bundleCommitment || extraData)` | ||
| /// | ||
| /// - For shield and shielded_transfer transitions, `extraData` should be empty. | ||
| /// - For unshield transitions, `extraData` = `outputAddress || amount (LE u64)`. | ||
| /// - For shielded withdrawal transitions, `extraData` = `outputScript || amount (LE u64)`. | ||
| #[wasm_bindgen(js_name = computePlatformSighash)] | ||
| pub fn compute_platform_sighash_wasm( | ||
| bundle_commitment: &[u8], | ||
| extra_data: &[u8], | ||
| ) -> WasmDppResult<Vec<u8>> { | ||
| if bundle_commitment.len() != 32 { | ||
| return Err(crate::error::WasmDppError::invalid_argument(&format!( | ||
| "bundleCommitment must be exactly 32 bytes, got {}", | ||
| bundle_commitment.len() | ||
| ))); | ||
|
Check failure on line 32 in packages/wasm-dpp2/src/shielded/mod.rs
|
||
| } | ||
| let commitment: &[u8; 32] = bundle_commitment.try_into().expect("checked length above"); | ||
| let result = dpp::shielded::compute_platform_sighash(commitment, extra_data); | ||
| Ok(result.to_vec()) | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.