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

refine error handling #91

Open
wants to merge 47 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
d71e3ea
fix instances array to allow input multiple instance
yymone Mar 14, 2024
b8a1c54
shadow instances
rhaoio Mar 16, 2024
46d6d00
build
rhaoio Mar 16, 2024
7d0382a
Merge pull request #58 from DelphinusLab/zkwas-221
yymone Mar 25, 2024
dfd3a00
export image status string
yymone Mar 25, 2024
e0c4228
ZKWAS-228: add metadata param into interface for 'Creator Paid Proof'…
qozymandias Apr 4, 2024
875132b
Merge branch 'main' into feature/ScrollNetworkSupport
yymone Apr 5, 2024
dc1868d
Merge branch 'main' into feature/ScrollNetworkSupport
yymone Apr 8, 2024
258653d
add types
qozymandias Apr 9, 2024
8c18e3e
fix
qozymandias Apr 9, 2024
955b2f4
update message
qozymandias Apr 11, 2024
10e2f52
remove queued
qozymandias Apr 11, 2024
c75c0b1
Merge pull request #62 from DelphinusLab/ZKWAS-235-proof-submit-mode-…
yymone Apr 11, 2024
2feefa3
Merge branch 'main' into feature/ScrollNetworkSupport
yymone Apr 13, 2024
32695cf
Merge branch 'feature/ScrollNetworkSupport' into feature/BatchProofs
yymone Apr 13, 2024
b035d5e
Merge branch 'main' into feature/ScrollNetworkSupport
yymone Apr 21, 2024
e45d1d3
Merge branch 'feature/ScrollNetworkSupport' into feature/BatchProofs
yymone Apr 21, 2024
27e1154
ZKWAS-257 (#65)
rhaoio Apr 30, 2024
1c42feb
ZKWAS-259 (#67)
rhaoio May 9, 2024
7773ffa
ZKWAS-261 (#68)
rhaoio May 13, 2024
b94be82
ZKWAS-264: auto submit networks selection options (#69)
qozymandias May 14, 2024
909ccc9
ZKWAS-266: add new fee for auto submit proof (#70)
qozymandias May 20, 2024
dddeaad
ZKWAS-263 (#71)
rhaoio May 22, 2024
935f758
ZKWAS-270 (#72)
rhaoio May 24, 2024
4d61095
update readme (#74)
rhaoio May 24, 2024
4e0183a
Merge pull request #73 from DelphinusLab/feature/BatchProofs
yymone May 25, 2024
bed7505
Update README.md
yymone May 31, 2024
6432ff5
add import assertions to mjs
akayi07 Jun 1, 2024
d1dea9d
ZKWAS-283 (#76)
rhaoio Jun 3, 2024
34f4824
try with blob
rhaoio Jun 12, 2024
0f0205d
try import blob for nodejs
rhaoio Jun 12, 2024
b3c3ae0
try as buffer
rhaoio Jun 12, 2024
9bdddaa
readme + extra fn
rhaoio Jun 12, 2024
8b961dd
Merge pull request #77 from DelphinusLab/zkwas-291
yymone Jun 12, 2024
0b8000b
Merge pull request #75 from DelphinusLab/akayi/bugfix
xgaozoyoe Jun 14, 2024
7cc8c2b
Revert wrongly add unsupported assert {type} feature for typescript 4.x
yymone Jun 17, 2024
ac5aaaa
use file read
yymone Jun 17, 2024
11ecb56
change json to string
yymone Jun 17, 2024
40a29a1
fix path
yymone Jun 17, 2024
f62d5b4
Merge pull request #79 from DelphinusLab/yyu/TestImportERC20
yymone Jun 17, 2024
211f177
ZKWAS-306 (#80)
rhaoio Jun 27, 2024
58d5c9a
ZKWAS-289 (#81)
rhaoio Jul 2, 2024
d3d0ee4
ZKWAS-289 (#82)
rhaoio Jul 2, 2024
8873e35
ZKWAS-301 & ZKWAS-304: Update inteface for node list improvements (#84)
qozymandias Jul 17, 2024
78e35d8
Revert "ZKWAS-301 & ZKWAS-304: Update inteface for node list improvem…
qozymandias Jul 17, 2024
a8eec55
Feature/july refine (#89)
yymone Jul 31, 2024
aa16351
refine error handling
akayi07 Aug 9, 2024
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
188 changes: 20 additions & 168 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,183 +16,35 @@ like:
- async addNewWasmImage(task: WithSignature<AddImageParams>);
- async addProvingTask(task: WithSignature<ProvingParams>);

### A example to add new wasm image
## Examples

This example typescript code will add the wasm image to the zkwasm service.
There are several examples of how to use this lib in the `examples` folder.

```
import {
AddImageParams,
WithSignature,
ZkWasmUtil,
zkWasmServiceHelper
} from "zkwasm-service-helper";

const endpoint = ""https://rpc.zkwasmhub.com:8090";
let helper = new ZkWasmServiceHelper(endpoint, "", "");
let imagePath = "/home/user/a.wasm";
let fileSelected: Buffer = fs.readFileSync(imagePath);
let md5 = ZkWasmUtil.convertToMd5(
fileSelected as Uint8Array
);

let info: AddImageParams = {
name: fileSelected.name,
image_md5: md5,
image: fileSelected,
user_address: account!.address.toLowerCase(),
description_url: "",
avator_url: "",
circuit_size: circuitSize,
};

// Optional Initial Context information

// Upload a binary file first
let contextFile = await ZkWasmUtil.loadContexFileAsBytes("<YourFilePath>");

if (contextFile) {
let context_info: WithInitialContext = {
initial_context: contextFile,
initial_context_md5: ZkWasmUtil.convertToMd5(contextFile),
};
info = { ...info, ...context_info };
}

let msg = ZkWasmUtil.createAddImageSignMessage(info);
let signature: string = await ZkWasmUtil.signMessage(msgString, priv); //Need user private key to sign the msg
let task: WithSignature<AddImageParams> = {
...info,
signature,
};

let response = await helper.addNewWasmImage(task);
## How to run the examples

```
### 0. Change to the examples directory as the current working directory

### A example to add proving tasks
```bash
cd examples
```

This example typescript code will add proving tasks to the zkwasm service.
### 1. Install dependencies

```
import {
ProvingParams,
WithSignature,
ZkWasmUtil,
zkWasmServiceHelper
} from "zkwasm-service-helper";

const endpoint = ""https://rpc.zkwasmhub.com:8090";
const image_md5 = "xxxx";
const public_inputs = "0x22:i64 0x21:i64";
const private_inputs = "";
const user_addr = "0xaaaaaa";

let helper = new ZkWasmServiceHelper(endpoint, "", "");
let pb_inputs: Array<string> = helper.parseProvingTaskInput(public_inputs);
let priv_inputs: Array<string> = helper.parseProvingTaskInput(private_inputs);

let info: ProvingParams = {
user_address: user_addr.toLowerCase(),
md5: image_md5,
public_inputs: pb_inputs,
private_inputs: priv_inputs,
};

// Context type for proof task. If none provided, will default to InputContextType.ImageCurrent in the server and use the image's current context
let selectedInputContextType = InputContextType.ImageCurrent;

// For Custom Context, upload a binary file first containing the context.
if (selectedInputContextType === InputContextType.Custom) {

let contextFile = await ZkWasmUtil.loadContexFileAsBytes("<YourFilePath>");

let context_info: WithCustomInputContextType = {
input_context: contextFile,
input_context_md5: ZkWasmUtil.convertToMd5(contextFile),
input_context_type: selectedInputContextType,
};
info = { ...info, ...context_info };
} else {
info = { ...info, input_context_type: selectedInputContextType };
}
let msgString = ZkWasmUtil.createProvingSignMessage(info);

let signature: string;
try {
signature = await ZkWasmUtil.signMessage(msgString, priv);
} catch (e: unknown) {
console.log("error signing message", e);
return;
}

let task: WithSignature<ProvingParams> = {
...info,
signature: signature,
};

let response = await helper.addProvingTask(task);
```bash
npm install
```

### A example to query task details
### 2. Use your own values for the following:

This example typescript code will query task details:
- Update your data in the `config.ts` file with your private key and address of the zkwasm playground service.
- Update the `config.ts` with web3 information you want to use such as chain id and provider url etc.

```
import {
ZkWasmServiceHelper,
ZkWasmUtil,
QueryParams,
PaginationResult,
Task,
} from "zkwasm-service-helper";
import BN from "bn.js";

const endpoint = ""https://rpc.zkwasmhub.com:8090";
const taskid = "xxxx"

let helper = new ZkWasmServiceHelper(endpoint, "", "");
let args: QueryParams = {
id: taskid!,
user_address: null, // null can also be empty string "" to ignore fields in the query filter
tasktype: null,
taskstatus: null,
};
helper.loadTasks(args).then((res) => {
const tasks = res as PaginationResult<Task[]>;
const task: Task = tasks.data[0];
let aggregate_proof = ZkWasmUtil.bytesToBN(task.proof);
let instances = ZkWasmUtil.bytesToBN(task.instances);
let batchInstances = ZkWasmUtil.bytesToBN(task.batch_instances);
let aux = ZkWasmUtil.bytesToBN(task.aux);
let fee = task.task_fee && ZkWasmUtil.convertAmount(task.task_fee);

console.log("Task details: ");
console.log(" ", task);
console.log(" proof:");
aggregate_proof.map((proof: BN, index) => {
console.log(" 0x", proof.toString("hex"));
});
console.log(" batch_instacne:");
batchInstances.map((ins: BN, index) => {
console.log(" 0x", ins.toString("hex"));
});
console.log(" instacne:");
instances.map((ins: BN, index) => {
console.log(" 0x", ins.toString("hex"));
});
console.log(" aux:");
aux.map((aux: BN, index) => {
console.log(" 0x", aux.toString("hex"));
});
console.log(" fee:", fee);
}).catch((err) => {
console.log("queryTask Error", err);
}).finally(() =>
console.log("Finish queryTask.")
);
```
- Within each script you want to run, you will also need to update values for querying and submitting tasks such as task ids.

### Notes:
### 3. Run the example you want to run.

md5 is case insensitive when communicate with our zkwasm service
Currently only the scripts under `src/tasks` and `src/verify` are runnable. The `queries` are merely examples which are used in these executable scripts.

```bash
npx tsx src/tasks/addNewImage.ts
```
2 changes: 1 addition & 1 deletion addhybridpackage.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@ find src -name '*.d.ts' -exec cp {} dist/cjs \;
mkdir -p dist/cjs/abi
mkdir -p dist/mjs/abi
find src/abi -name '*.json' -exec cp {} dist/cjs/abi \;
find src/abi -name '*.json' -exec cp {} dist/mjs/abi \;
find src/abi -name '*.json' -exec cp {} dist/mjs/abi \;
4 changes: 4 additions & 0 deletions dist/cjs/abi/ERC20.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export declare class ERC20Lib {
static ERC20String: string;
static ERC20: any;
}
Loading