Skip to content
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

Client-side JS to SCALE conversion #7

Closed
jmg-duarte opened this issue Nov 26, 2024 · 2 comments · Fixed by #10
Closed

Client-side JS to SCALE conversion #7

jmg-duarte opened this issue Nov 26, 2024 · 2 comments · Fixed by #10
Assignees
Milestone

Comments

@jmg-duarte
Copy link
Collaborator

jmg-duarte commented Nov 26, 2024

The signature for signed deals is built on top of the SCALE encoded deal proposal (more or less like so):

fn sign(deal_proposal: DealProposal) -> SignedDealProposal {
  return sign(deal_proposal.to_scale())

Currently, we send the proposal to the SP to encode, which is far from ideal:

const encodingResponse = await fetch(`http://${providerUrl}:${HTTP_PORT}/encode_proposal`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(dealProposal),
});

The SCALE library is no_std compatible and so is serde, so we can probably get a WASM function for the encoding working.

Maybe we won't need the WASM — https://github.com/polkadot-js/api/tree/f96e8c42a06b934d7e512c6427b81a995faa417a/packages/types-codec

@jmg-duarte jmg-duarte changed the title JS to SCALE browser native conversion Client-side JS to SCALE conversion Nov 26, 2024
@jmg-duarte
Copy link
Collaborator Author

I did some additional research and we should be able to copy the Rust structs to TS using the types-codec and it's friends.

https://grep.app/search?q=%40polkadot/types-codec

The following guide should be helpful:

Seems to me that the approach revolves around using the type registry to create the types:

import { TypeRegistry } from '@polkadot/types';

const registry = new TypeRegistry();
registry.register(...);
registry.createType("DealProposal", ...);

However, I don't understand Typescript enough to understand the source of CodecClass

@jmg-duarte
Copy link
Collaborator Author

This has been implemented and is working but hasn't reached the main tree yet

@jmg-duarte jmg-duarte added this to the Phase 3 milestone Mar 7, 2025
@jmg-duarte jmg-duarte self-assigned this Mar 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant