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

[Feature] Add arithmetic types, plaintext, and conversion of plaintext & records to JS objects #944

Open
wants to merge 5 commits into
base: mainnet
Choose a base branch
from

Conversation

iamalwaysuncomfortable
Copy link
Collaborator

@iamalwaysuncomfortable iamalwaysuncomfortable commented Nov 26, 2024

Motivation

From several requests and issues surrounding the SDK, the following features have been flagged as important to add.

Addition Field, Scalar, and Group Types

Addition of Field, Group, and Scalar types and core arithmetic methods on those types allowing useful work to be done using algebraic types.

Accessible Plaintext and Record Data + Conversion of Aleo types to JS type.

This PR adds the ability to access:

  • Methods to access the field of of a Record directly
  • Methods to access Struct fields
  • Methods for converting Plaintext types into JS objects. This includes Aleo Literal ( i.e. address, boolean, i8/i16/i32/i64/i128/u8/u16/u32/u64/u128, field, scalar, signature), Struct, and Array types) into JS types.

Transition and Transaction Data Accessor Methods

The ability to search for records, and get the inputs and outputs of Transitions and Transactions.

Addition of GraphKey and ComputeKey

This PR adds both the GraphKey and ComputeKey to the sdk, allowing GraphKeys to be used directly to determine ownership records.

Test Plan

  • This PR adds unit tests for all new features.

@iamalwaysuncomfortable iamalwaysuncomfortable marked this pull request as ready for review December 3, 2024 04:56
@iamalwaysuncomfortable iamalwaysuncomfortable changed the title [Feature] Add arithmetic types, plaintext, and conversion of Plaintext & Records to JS objects [Feature] Add arithmetic types, plaintext, and conversion of plaintext & records to JS objects Dec 3, 2024
Copy link
Collaborator

@Pauan Pauan left a comment

Choose a reason for hiding this comment

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

There's various small nits that need to be fixed, otherwise it looks good to me.

wasm/src/ledger/transaction.rs Outdated Show resolved Hide resolved
wasm/src/ledger/transaction.rs Outdated Show resolved Hide resolved
wasm/src/ledger/transaction.rs Outdated Show resolved Hide resolved
wasm/src/ledger/transaction.rs Outdated Show resolved Hide resolved
wasm/src/ledger/transaction.rs Outdated Show resolved Hide resolved
wasm/src/programs/data/plaintext.rs Outdated Show resolved Hide resolved
wasm/src/programs/program.rs Show resolved Hide resolved
wasm/src/types/field.rs Show resolved Hide resolved
wasm/src/types/scalar.rs Show resolved Hide resolved
@@ -418,5 +418,7 @@ self.addEventListener("message", (ev) => {
programManager.setHost(defaultHost);
}
})();
} else if (ev.data.type === "PROPOSE_GAME") {
Copy link
Collaborator

Choose a reason for hiding this comment

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

What's the purpose of this?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This is a mistake, I shall remove.

Copy link
Collaborator Author

@iamalwaysuncomfortable iamalwaysuncomfortable left a comment

Choose a reason for hiding this comment

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

Feedback addressed, @Pauan - when there's time to double check, let me know.

wasm/src/types/field.rs Show resolved Hide resolved
wasm/src/types/group.rs Show resolved Hide resolved
wasm/src/types/scalar.rs Show resolved Hide resolved
@@ -418,5 +418,7 @@ self.addEventListener("message", (ev) => {
programManager.setHost(defaultHost);
}
})();
} else if (ev.data.type === "PROPOSE_GAME") {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This is a mistake, I shall remove.

let tpk = Group::from(transition.tpk());
let tcm = Field::from(transition.tcm());
let scm = Field::from(transition.scm());
if convert_to_js {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This will only work if its first wrapped in JsValue, which seems acceptable.

Copy link
Collaborator

@Pauan Pauan left a comment

Choose a reason for hiding this comment

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

Couple more minor issues to fix, otherwise it looks good to me.

wasm/src/lib.rs Show resolved Hide resolved
wasm/src/programs/data/helpers/future.rs Show resolved Hide resolved
wasm/src/programs/data/helpers/input.rs Show resolved Hide resolved
wasm/src/programs/data/helpers/input.rs Show resolved Hide resolved
wasm/src/programs/data/helpers/output.rs Show resolved Hide resolved
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 this pull request may close these issues.

2 participants