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
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ jobs:
- run:
working_directory: create-leo-app/template-node
command: |
yarn start
yarn dev

template-node-ts:
executor: rust-node
Expand All @@ -108,7 +108,7 @@ jobs:
- run:
working_directory: create-leo-app/template-node-ts
command: |
yarn start
yarn dev

template-extension:
executor: rust-node
Expand Down
2 changes: 1 addition & 1 deletion create-leo-app/template-node-ts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"type": "module",
"scripts": {
"build": "rimraf dist/js && rollup --config",
"start": "npm run build && node dist/index.js"
"dev": "npm run build && node dist/index.js"
},
"dependencies": {
"@provablehq/sdk": "^0.7.0"
Expand Down
2 changes: 1 addition & 1 deletion create-leo-app/template-node/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"version": "0.0.0",
"type": "module",
"scripts": {
"start": "node index.js"
"dev": "node index.js"
},
"dependencies": {
"@provablehq/sdk": "^0.7.0"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"type": "module",
"scripts": {
"build": "rimraf dist/js && rollup --config",
"start": "npm run build && node dist/index.js"
"dev": "npm run build && node dist/index.js"
},
"dependencies": {
"@provablehq/sdk": "^0.7.0"
Expand Down
6 changes: 3 additions & 3 deletions sdk/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,11 @@
},
"homepage": "https://github.com/ProvableHQ/sdk#readme",
"dependencies": {
"@provablehq/wasm": "^0.7.0",
"@provablehq/wasm": "^0.7.2",
"comlink": "^4.4.1",
"mime": "^3.0.0",
"sync-request": "^6.1.0"
"sync-request": "^6.1.0",
"core-js": "^3.38.1"
},
"devDependencies": {
"@rollup/plugin-replace": "^5.0.5",
Expand All @@ -63,7 +64,6 @@
"better-docs": "^2.7.2",
"chai": "^5.1.1",
"clean-jsdoc-theme": "^4.1.8",
"core-js": "^3.38.1",
"cpr": "^3.0.1",
"eslint": "^8.26.0",
"eslint-config-prettier": "^8.5.0",
Expand Down
43 changes: 31 additions & 12 deletions sdk/src/browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,20 @@ import "./polyfill/shared";

import { Account } from "./account";
import { AleoNetworkClient, ProgramImports } from "./network-client";
import { Block } from "./models/block";
import { Execution } from "./models/execution";
import { Input } from "./models/input";
import { Output } from "./models/output";
import { TransactionModel } from "./models/transactionModel";
import { Transition } from "./models/transition";
import { BlockJSON } from "./models/blockJSON";
import { ExecutionJSON } from "./models/executionJSON";
import { FunctionObject } from "./models/functionObject";
import { InputJSON } from "./models/input/inputJSON";
import { InputObject } from "./models/input/inputObject";
import { OutputJSON } from "./models/output/outputJSON";
import { OutputObject } from "./models/output/outputObject";
import { PlaintextArray} from "./models/plaintext/array";
import { PlaintextLiteral} from "./models/plaintext/literal";
import { PlaintextStruct} from "./models/plaintext/struct";
import { TransactionJSON } from "./models/transaction/transactionJSON";
import { TransactionSummary } from "./models/transaction/transactionSummary";
import { TransitionJSON } from "./models/transition/transitionJSON";
import { TransitionObject } from "./models/transition/transitionObject";
import {
AleoKeyProvider,
AleoKeyProviderParams,
Expand Down Expand Up @@ -41,10 +49,13 @@ export { logAndThrow } from "./utils";

export {
Address,
Ciphertext,
Execution as FunctionExecution,
ExecutionResponse,
Field,
Group,
OfflineQuery,
Plaintext,
PrivateKey,
PrivateKeyCiphertext,
Program,
Expand All @@ -53,7 +64,9 @@ export {
RecordCiphertext,
RecordPlaintext,
Signature,
Scalar,
Transaction,
Transition,
VerifyingKey,
ViewKey,
initThreadPool,
Expand Down Expand Up @@ -81,21 +94,27 @@ export {
AleoKeyProviderParams,
AleoKeyProviderInitParams,
AleoNetworkClient,
Block,
BlockJSON,
BlockHeightSearch,
CachedKeyPair,
Execution,
ExecutionJSON,
FunctionObject,
FunctionKeyPair,
FunctionKeyProvider,
Input,
InputJSON,
InputObject,
KeySearchParams,
NetworkRecordProvider,
ProgramImports,
OfflineKeyProvider,
OfflineSearchParams,
Output,
PlaintextArray,
PlaintextLiteral,
PlaintextStruct,
OutputJSON,
OutputObject,
RecordProvider,
RecordSearchParams,
TransactionModel,
Transition,
TransactionJSON,
TransactionSummary,
};
2 changes: 1 addition & 1 deletion sdk/src/models/block.ts → sdk/src/models/blockJSON.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ConfirmedTransaction } from "./confirmed_transaction";

export type Block = {
export type BlockJSON = {
block_hash: string;
previous_hash: string;
header: Header;
Expand Down
4 changes: 2 additions & 2 deletions sdk/src/models/confirmed_transaction.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { TransactionModel } from "./transactionModel";
import { TransactionJSON } from "./transaction/transactionJSON";

export type ConfirmedTransaction = {
type: string;
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

id: string;
transaction: TransactionModel;
transaction: TransactionJSON;
}
6 changes: 6 additions & 0 deletions sdk/src/models/deploy.ts
Original file line number Diff line number Diff line change
@@ -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

"programId" : string,
"functions" : FunctionObject[]
}
6 changes: 0 additions & 6 deletions sdk/src/models/execution.ts

This file was deleted.

6 changes: 6 additions & 0 deletions sdk/src/models/executionJSON.ts
Original file line number Diff line number Diff line change
@@ -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

edition: number;
transitions?: (TransitionJSON)[];
}
8 changes: 8 additions & 0 deletions sdk/src/models/functionObject.ts
Original file line number Diff line number Diff line change
@@ -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

"name" : string,
"constraints" : number,
"variables" : number,
"verifyingKey" : string | VerifyingKey,
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
export type Input = {
/**
* Object representation of an Input as raw JSON returned from a SnarkOS node.
*/
export type InputJSON = {
type: string;
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

id: string;
tag?: string;
Expand Down
16 changes: 16 additions & 0 deletions sdk/src/models/input/inputObject.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/**
* Aleo function Input represented as a typed typescript object.
*/
import { Ciphertext, Field } 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 ../../wasm instead of @provablehq/wasm

import { Plaintext } from "@provablehq/wasm/mainnet.js";
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why is this importing mainnet?

import { PlaintextObject } from "../plaintext/plaintext";

/**
* Object representation of an Input as raw JSON returned from a SnarkOS node.
*/
export type InputObject = {
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

type: "string",
id: "string" | Field,
tag?: string | Field,
value?: Ciphertext | Plaintext | PlaintextObject,
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export type Output = {
export type OutputJSON = {
type: string;
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

id: string;
checksum: string;
Expand Down
18 changes: 18 additions & 0 deletions sdk/src/models/output/outputObject.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/**
* Aleo function Input represented as a typed typescript object.
*/
import { Field, Ciphertext, Plaintext } 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 import ../../wasm instead.

import { PlaintextObject } from "../plaintext/plaintext";

/**
* Object representation of an Input as raw JSON returned from a SnarkOS node.
*/
export type OutputObject = {
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

type: string,
id: string | Field,
value?: Ciphertext | Plaintext | PlaintextObject,
checksum?: string | Field,
programId?: string,
functionName?: string,
arguments?: Array<Plaintext> | Array<OutputObject>
}
4 changes: 4 additions & 0 deletions sdk/src/models/plaintext/array.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { PlaintextLiteral } from "./literal";
import { PlaintextStruct } from "./struct";

export type PlaintextArray = PlaintextLiteral[] | PlaintextStruct[] | PlaintextArray[];
1 change: 1 addition & 0 deletions sdk/src/models/plaintext/literal.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export type PlaintextLiteral = boolean | bigint | number | string;
5 changes: 5 additions & 0 deletions sdk/src/models/plaintext/plaintext.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { PlaintextArray } from "./array";
import { PlaintextLiteral } from "./literal";
import { PlaintextStruct } from "./struct";

export type PlaintextObject = PlaintextArray| PlaintextLiteral | PlaintextStruct
6 changes: 6 additions & 0 deletions sdk/src/models/plaintext/struct.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { PlaintextArray } from "./array";
import { PlaintextLiteral } from "./literal";

export type PlaintextStruct = {
[key: string]: PlaintextArray | PlaintextLiteral | PlaintextStruct;
}
7 changes: 7 additions & 0 deletions sdk/src/models/transaction/transactionJSON.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { ExecutionJSON } from "../executionJSON";

export type TransactionJSON = {
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

type: string;
id: string;
execution: ExecutionJSON;
}
12 changes: 12 additions & 0 deletions sdk/src/models/transaction/transactionSummary.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { TransitionObject } from "../transition/transitionObject";
import { DeploymentMetadata } from "../deploy";

export type TransactionSummary = {
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

id : string;
type : string;
fee : bigint;
baseFee : bigint;
priorityFee : bigint;
transitions : TransitionObject[];
deployment?: DeploymentMetadata;
}
7 changes: 0 additions & 7 deletions sdk/src/models/transactionModel.ts

This file was deleted.

14 changes: 0 additions & 14 deletions sdk/src/models/transition.ts

This file was deleted.

14 changes: 14 additions & 0 deletions sdk/src/models/transition/transitionJSON.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { InputJSON } from "../input/inputJSON";
import { OutputJSON } from "../output/outputJSON";

export type TransitionJSON = {
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

id: string;
program: string;
function: string;
inputs?: (InputJSON)[];
outputs?: (OutputJSON)[];
proof: string;
tpk: string;
tcm: string;
fee: bigint;
}
16 changes: 16 additions & 0 deletions sdk/src/models/transition/transitionObject.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { InputObject } from "../input/inputObject";
import { OutputObject } from "../output/outputObject";
import { Field, Group } 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 import ../../wasm


export type TransitionObject = {
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

id: string;
program: string;
functionName: string;
inputs?: (InputObject)[];
outputs?: (OutputObject)[];
proof: string;
tpk: string | Group;
tcm: string | Field;
scm: string | Field;
fee: bigint;
}
Loading
Loading