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 Field, Group, Scalar, Plaintext, Ciphertext, Transitions, and Transactions to JS SDK. #948

Open
wants to merge 13 commits into
base: feat/record-scanning-and-arithmetic
Choose a base branch
from

Conversation

iamalwaysuncomfortable
Copy link
Collaborator

Motivation

Several feature requests have requested that the ability to the following be added to the SDK.

  • Be able to do Field, Group, and Scalar arithmetic and be generally able to work with those types
  • Easily peer into Transaction and Transition data and associated inputs and outputs
  • Work with Ciphertexts and get items from Struct and Array types

This PR adds these types to the SDK with the ability to turn them into JavaScript/TypeScript objects for convenient extraction of data into a front or backend app as well as api methods that allow these new types to be directly instantiated when calling api endpoints.

It also provides several new typescript types that allow typescript users to work with the JS representation of these objects.

Once this PR is approved, it will constitute the release candidate for the next major version bump.

Test Plan

This PR adds the following unit tests for the new objects:

  • Field, Scalar, and Group arithmetic.
  • Conversion of Transitions and Transactions to JS objects.

Related PRs

#944 - this PR adds the exports of SnarkVM types to wasm and provides code that

@iamalwaysuncomfortable iamalwaysuncomfortable changed the base branch from testnet3 to feat/record-scanning-and-arithmetic December 10, 2024 15:02
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.

Some minor nits, but generally looks good.

@@ -1,7 +1,7 @@
import { TransactionModel } from "./transactionModel";
import { TransactionJSON } from "./transaction/transactionJSON";

export type ConfirmedTransaction = {
Copy link
Collaborator

Choose a reason for hiding this comment

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

For objects, it's better to use an interface instead of type

@@ -0,0 +1,6 @@
import { FunctionObject } from "./functionObject";

export type DeploymentMetadata = {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Same as above, this should be an interface

@@ -0,0 +1,6 @@
import { TransitionJSON } from "./transition/transitionJSON";

export type ExecutionJSON = {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Same as above, this should be an interface

@@ -0,0 +1,8 @@
import { VerifyingKey } from "@provablehq/wasm";

export type FunctionObject = {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Same as above, this should be an interface

/**
* Object representation of an Input as raw JSON returned from a SnarkOS node.
*/
export type InputJSON = {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Same as above, this should be an interface

async getTransactionObjectsInMempool(): Promise<Array<Transaction>> {
try {
return (await this.fetchData<Array<string>>("/memoryPool/transactions"))
.reduce<Array<Transaction>>((acc, transaction) => {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Similarly, why is this using reduce?

expect(unbondPublicProverLocal.isUnbondPublicProver()).equal(true);
expect(unbondPublicVerifierLocal.isUnbondPublicVerifier()).equal(true);
});
// it('should not fetch invalid transfer keys', async () => {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think it's cleaner to use describe.skip or it.skip to skip the tests, instead of commenting it out.


import { Account, BlockJSON, AleoNetworkClient, TransactionSummary, InputObject, OutputObject } from "../src/node";
import {beaconPrivateKeyString} from "./data/account-data";
import { Plaintext, Transition } from "@provablehq/wasm";
Copy link
Collaborator

Choose a reason for hiding this comment

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

This should be importing from ../src/node instead of @provablehq/wasm.

import { Account, BlockJSON, AleoNetworkClient, TransactionSummary, InputObject, OutputObject } from "../src/node";
import {beaconPrivateKeyString} from "./data/account-data";
import { Plaintext, Transition } from "@provablehq/wasm";
import { TransitionObject } from "../src/models/transition/transitionObject";
Copy link
Collaborator

Choose a reason for hiding this comment

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

This should probably also be importing from ../src/node

import {beaconPrivateKeyString} from "./data/account-data";
import { Plaintext, Transition } from "@provablehq/wasm";
import { TransitionObject } from "../src/models/transition/transitionObject";
import { PlaintextObject } from "../src/models/plaintext/plaintext";
Copy link
Collaborator

Choose a reason for hiding this comment

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

This should probably also be importing from ../src/node

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