@silvana-one/mina-prover 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +201 -0
- package/README.md +1 -0
- package/dist/node/api/api.d.ts +211 -0
- package/dist/node/api/api.js +472 -0
- package/dist/node/api/api.js.map +1 -0
- package/dist/node/index.cjs +1161 -0
- package/dist/node/index.d.ts +4 -0
- package/dist/node/index.js +5 -0
- package/dist/node/index.js.map +1 -0
- package/dist/node/local/local.d.ts +292 -0
- package/dist/node/local/local.js +528 -0
- package/dist/node/local/local.js.map +1 -0
- package/dist/node/tokens/index.d.ts +2 -0
- package/dist/node/tokens/index.js +3 -0
- package/dist/node/tokens/index.js.map +1 -0
- package/dist/node/tokens/nft.d.ts +29 -0
- package/dist/node/tokens/nft.js +107 -0
- package/dist/node/tokens/nft.js.map +1 -0
- package/dist/node/tokens/token.d.ts +29 -0
- package/dist/node/tokens/token.js +99 -0
- package/dist/node/tokens/token.js.map +1 -0
- package/dist/node/verification/index.d.ts +1 -0
- package/dist/node/verification/index.js +2 -0
- package/dist/node/verification/index.js.map +1 -0
- package/dist/node/verification/verification.d.ts +21 -0
- package/dist/node/verification/verification.js +2 -0
- package/dist/node/verification/verification.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/dist/tsconfig.web.tsbuildinfo +1 -0
- package/dist/web/api/api.d.ts +211 -0
- package/dist/web/api/api.js +472 -0
- package/dist/web/api/api.js.map +1 -0
- package/dist/web/index.d.ts +4 -0
- package/dist/web/index.js +5 -0
- package/dist/web/index.js.map +1 -0
- package/dist/web/local/local.d.ts +292 -0
- package/dist/web/local/local.js +528 -0
- package/dist/web/local/local.js.map +1 -0
- package/dist/web/tokens/index.d.ts +2 -0
- package/dist/web/tokens/index.js +3 -0
- package/dist/web/tokens/index.js.map +1 -0
- package/dist/web/tokens/nft.d.ts +29 -0
- package/dist/web/tokens/nft.js +107 -0
- package/dist/web/tokens/nft.js.map +1 -0
- package/dist/web/tokens/token.d.ts +29 -0
- package/dist/web/tokens/token.js +99 -0
- package/dist/web/tokens/token.js.map +1 -0
- package/dist/web/verification/index.d.ts +1 -0
- package/dist/web/verification/index.js +2 -0
- package/dist/web/verification/index.js.map +1 -0
- package/dist/web/verification/verification.d.ts +21 -0
- package/dist/web/verification/verification.js +2 -0
- package/dist/web/verification/verification.js.map +1 -0
- package/package.json +68 -0
- package/src/api/api.ts +613 -0
- package/src/index.ts +4 -0
- package/src/local/local.ts +651 -0
- package/src/tokens/index.ts +2 -0
- package/src/tokens/nft.ts +147 -0
- package/src/tokens/token.ts +140 -0
- package/src/verification/index.ts +1 -0
- package/src/verification/verification.ts +23 -0
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
import {
|
|
2
|
+
blockchain,
|
|
3
|
+
Cloud,
|
|
4
|
+
JobStatus,
|
|
5
|
+
zkCloudWorker,
|
|
6
|
+
} from "@silvana-one/prover";
|
|
7
|
+
import { zkCloudWorkerClient } from "../api/api.js";
|
|
8
|
+
import { NftTransaction, JobResult } from "@silvana-one/api";
|
|
9
|
+
|
|
10
|
+
export class NftAPI {
|
|
11
|
+
readonly client: zkCloudWorkerClient;
|
|
12
|
+
|
|
13
|
+
constructor(params: {
|
|
14
|
+
jwt: string;
|
|
15
|
+
zkcloudworker?: (cloud: Cloud) => Promise<zkCloudWorker>;
|
|
16
|
+
chain: blockchain;
|
|
17
|
+
}) {
|
|
18
|
+
const { jwt, zkcloudworker, chain } = params;
|
|
19
|
+
if (jwt === undefined) throw new Error("jwt is undefined");
|
|
20
|
+
|
|
21
|
+
this.client = new zkCloudWorkerClient({
|
|
22
|
+
jwt,
|
|
23
|
+
chain,
|
|
24
|
+
zkcloudworker,
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
async proveTransaction(params: NftTransaction): Promise<string | undefined> {
|
|
29
|
+
return this.proveTransactions([params]);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
async proveTransactions(
|
|
33
|
+
params: NftTransaction[],
|
|
34
|
+
name?: string
|
|
35
|
+
): Promise<string | undefined> {
|
|
36
|
+
const transactions: string[] = [];
|
|
37
|
+
for (const tx of params) {
|
|
38
|
+
const transaction = JSON.stringify(tx, null, 2);
|
|
39
|
+
transactions.push(transaction);
|
|
40
|
+
}
|
|
41
|
+
const { request, symbol } = params[0];
|
|
42
|
+
const { txType } = request;
|
|
43
|
+
|
|
44
|
+
const answer = await this.client.execute({
|
|
45
|
+
developer: "DFST",
|
|
46
|
+
repo: "nft-agent",
|
|
47
|
+
transactions,
|
|
48
|
+
task: "prove",
|
|
49
|
+
args: JSON.stringify({
|
|
50
|
+
collectionAddress: params[0].request.collectionAddress,
|
|
51
|
+
}),
|
|
52
|
+
metadata: `${params.length > 1 ? "mint" : txType.replace(/^nft:/, "")} ${
|
|
53
|
+
symbol ? ` ${symbol}` : ""
|
|
54
|
+
} ${
|
|
55
|
+
params.length > 1
|
|
56
|
+
? `(${params.length} txs)`
|
|
57
|
+
: txType === "nft:launch"
|
|
58
|
+
? "Collection " + request.collectionName
|
|
59
|
+
: txType === "nft:mint"
|
|
60
|
+
? request.nftMintParams.name
|
|
61
|
+
: name ?? ""
|
|
62
|
+
}`,
|
|
63
|
+
});
|
|
64
|
+
const jobId = answer.jobId;
|
|
65
|
+
if (jobId === undefined)
|
|
66
|
+
console.error("Job ID is undefined", { answer, txType, symbol });
|
|
67
|
+
return jobId;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
// Warning: this function will block the thread until the job is done and will print logs to the console
|
|
71
|
+
// Do not use it in "use server" functions, use getResults instead
|
|
72
|
+
async waitForJobResults(params: {
|
|
73
|
+
jobId: string;
|
|
74
|
+
maxAttempts?: number;
|
|
75
|
+
interval?: number;
|
|
76
|
+
maxErrors?: number;
|
|
77
|
+
printLogs?: boolean;
|
|
78
|
+
}): Promise<(string | undefined)[]> {
|
|
79
|
+
const deployResult = await this.client.waitForJobResult(params);
|
|
80
|
+
console.log(
|
|
81
|
+
"waitForJobResult result:",
|
|
82
|
+
deployResult?.result?.result?.slice(0, 50)
|
|
83
|
+
);
|
|
84
|
+
return deployResult?.result?.result ?? "error";
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
async getResults(
|
|
88
|
+
jobId: string
|
|
89
|
+
): Promise<
|
|
90
|
+
| { success: true; results?: JobResult[]; jobStatus?: JobStatus }
|
|
91
|
+
| { success: false; error?: string; jobStatus?: JobStatus }
|
|
92
|
+
> {
|
|
93
|
+
try {
|
|
94
|
+
const callResult = await this.client.jobResult({ jobId });
|
|
95
|
+
|
|
96
|
+
// TODO: filter the repo and developer
|
|
97
|
+
const jobStatus: JobStatus | undefined =
|
|
98
|
+
typeof callResult?.result === "string"
|
|
99
|
+
? undefined
|
|
100
|
+
: callResult?.result?.jobStatus;
|
|
101
|
+
if (!callResult.success) {
|
|
102
|
+
return {
|
|
103
|
+
success: false,
|
|
104
|
+
error: callResult?.error,
|
|
105
|
+
jobStatus,
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
const jobResult = callResult.result?.result;
|
|
109
|
+
if (callResult.error)
|
|
110
|
+
return {
|
|
111
|
+
success: false,
|
|
112
|
+
error: callResult.error,
|
|
113
|
+
jobStatus,
|
|
114
|
+
};
|
|
115
|
+
if (!jobResult) return { success: true, jobStatus };
|
|
116
|
+
|
|
117
|
+
if (jobResult.toLowerCase().startsWith("error"))
|
|
118
|
+
return {
|
|
119
|
+
success: false,
|
|
120
|
+
error: jobResult,
|
|
121
|
+
jobStatus,
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
try {
|
|
125
|
+
const { proofs } = JSON.parse(jobResult);
|
|
126
|
+
const results: JobResult[] = [];
|
|
127
|
+
for (const proof of proofs) {
|
|
128
|
+
const { success, tx, hash, error } = JSON.parse(proof);
|
|
129
|
+
results.push({ success, tx, hash, error });
|
|
130
|
+
}
|
|
131
|
+
return { success: true, results, jobStatus };
|
|
132
|
+
} catch (e: any) {
|
|
133
|
+
return {
|
|
134
|
+
success: false,
|
|
135
|
+
error: `Error parsing job result: ${jobResult} ${e?.message ?? ""}`,
|
|
136
|
+
jobStatus,
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
} catch (e: any) {
|
|
140
|
+
return {
|
|
141
|
+
success: false,
|
|
142
|
+
error: `Error getting job result: ${e?.message ?? ""}`,
|
|
143
|
+
jobStatus: undefined,
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
}
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
import {
|
|
2
|
+
blockchain,
|
|
3
|
+
Cloud,
|
|
4
|
+
JobStatus,
|
|
5
|
+
zkCloudWorker,
|
|
6
|
+
} from "@silvana-one/prover";
|
|
7
|
+
import { zkCloudWorkerClient } from "../api/api.js";
|
|
8
|
+
import { TokenTransaction, JobResult } from "@silvana-one/api";
|
|
9
|
+
|
|
10
|
+
export class TokenAPI {
|
|
11
|
+
readonly client: zkCloudWorkerClient;
|
|
12
|
+
|
|
13
|
+
constructor(params: {
|
|
14
|
+
jwt: string;
|
|
15
|
+
zkcloudworker?: (cloud: Cloud) => Promise<zkCloudWorker>;
|
|
16
|
+
chain: blockchain;
|
|
17
|
+
}) {
|
|
18
|
+
const { jwt, zkcloudworker, chain } = params;
|
|
19
|
+
if (jwt === undefined) throw new Error("jwt is undefined");
|
|
20
|
+
|
|
21
|
+
this.client = new zkCloudWorkerClient({
|
|
22
|
+
jwt,
|
|
23
|
+
chain,
|
|
24
|
+
zkcloudworker,
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
async proveTransaction(
|
|
29
|
+
params: TokenTransaction
|
|
30
|
+
): Promise<string | undefined> {
|
|
31
|
+
return this.proveTransactions([params]);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
async proveTransactions(
|
|
35
|
+
params: TokenTransaction[]
|
|
36
|
+
): Promise<string | undefined> {
|
|
37
|
+
const transactions: string[] = [];
|
|
38
|
+
for (const tx of params) {
|
|
39
|
+
const transaction = JSON.stringify(tx, null, 2);
|
|
40
|
+
transactions.push(transaction);
|
|
41
|
+
}
|
|
42
|
+
const { request, symbol } = params[0];
|
|
43
|
+
const { txType } = request;
|
|
44
|
+
|
|
45
|
+
const answer = await this.client.execute({
|
|
46
|
+
developer: "DFST",
|
|
47
|
+
repo: "token-launchpad",
|
|
48
|
+
transactions,
|
|
49
|
+
task: "prove",
|
|
50
|
+
args: JSON.stringify({ tokenAddress: params[0].request.tokenAddress }),
|
|
51
|
+
metadata: `${
|
|
52
|
+
params.length > 1 ? "airdrop" : txType.replace(/^token:/, "")
|
|
53
|
+
} token${symbol ? ` ${symbol}` : ""}${
|
|
54
|
+
params.length > 1 ? ` (${params.length} txs)` : ""
|
|
55
|
+
}`,
|
|
56
|
+
});
|
|
57
|
+
const jobId = answer.jobId;
|
|
58
|
+
if (jobId === undefined)
|
|
59
|
+
console.error("Job ID is undefined", { answer, txType, symbol });
|
|
60
|
+
return jobId;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
// Warning: this function will block the thread until the job is done and will print logs to the console
|
|
64
|
+
// Do not use it in "use server" functions, use getResults instead
|
|
65
|
+
async waitForJobResults(params: {
|
|
66
|
+
jobId: string;
|
|
67
|
+
maxAttempts?: number;
|
|
68
|
+
interval?: number;
|
|
69
|
+
maxErrors?: number;
|
|
70
|
+
printLogs?: boolean;
|
|
71
|
+
}): Promise<(string | undefined)[]> {
|
|
72
|
+
const deployResult = await this.client.waitForJobResult(params);
|
|
73
|
+
console.log(
|
|
74
|
+
"waitForJobResult result:",
|
|
75
|
+
deployResult?.result?.result?.slice(0, 50)
|
|
76
|
+
);
|
|
77
|
+
return deployResult?.result?.result ?? "error";
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
async getResults(
|
|
81
|
+
jobId: string
|
|
82
|
+
): Promise<
|
|
83
|
+
| { success: true; results?: JobResult[]; jobStatus?: JobStatus }
|
|
84
|
+
| { success: false; error?: string; jobStatus?: JobStatus }
|
|
85
|
+
> {
|
|
86
|
+
try {
|
|
87
|
+
const callResult = await this.client.jobResult({ jobId });
|
|
88
|
+
|
|
89
|
+
// TODO: filter the repo and developer
|
|
90
|
+
const jobStatus: JobStatus | undefined =
|
|
91
|
+
typeof callResult?.result === "string"
|
|
92
|
+
? undefined
|
|
93
|
+
: callResult?.result?.jobStatus;
|
|
94
|
+
if (!callResult.success) {
|
|
95
|
+
return {
|
|
96
|
+
success: false,
|
|
97
|
+
error: callResult?.error,
|
|
98
|
+
jobStatus,
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
const jobResult = callResult.result?.result;
|
|
102
|
+
if (callResult.error)
|
|
103
|
+
return {
|
|
104
|
+
success: false,
|
|
105
|
+
error: callResult.error,
|
|
106
|
+
jobStatus,
|
|
107
|
+
};
|
|
108
|
+
if (!jobResult) return { success: true, jobStatus };
|
|
109
|
+
|
|
110
|
+
if (jobResult.toLowerCase().startsWith("error"))
|
|
111
|
+
return {
|
|
112
|
+
success: false,
|
|
113
|
+
error: jobResult,
|
|
114
|
+
jobStatus,
|
|
115
|
+
};
|
|
116
|
+
|
|
117
|
+
try {
|
|
118
|
+
const { proofs } = JSON.parse(jobResult);
|
|
119
|
+
const results: JobResult[] = [];
|
|
120
|
+
for (const proof of proofs) {
|
|
121
|
+
const { success, tx, hash, error } = JSON.parse(proof);
|
|
122
|
+
results.push({ success, tx, hash, error });
|
|
123
|
+
}
|
|
124
|
+
return { success: true, results, jobStatus };
|
|
125
|
+
} catch (e: any) {
|
|
126
|
+
return {
|
|
127
|
+
success: false,
|
|
128
|
+
error: `Error parsing job result: ${jobResult} ${e?.message ?? ""}`,
|
|
129
|
+
jobStatus,
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
} catch (e: any) {
|
|
133
|
+
return {
|
|
134
|
+
success: false,
|
|
135
|
+
error: `Error getting job result: ${e?.message ?? ""}`,
|
|
136
|
+
jobStatus: undefined,
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./verification.js";
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { blockchain } from "@silvana-one/prover";
|
|
2
|
+
import { SmartContract } from "o1js";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* VerificationData is a data structure that contains all the information needed to verify a smart contract on a blockchain.
|
|
6
|
+
* contract: The smart contract that needs to be verified.
|
|
7
|
+
* contractDependencies: The smart contracts that need to be compiled before verification.
|
|
8
|
+
* programDependencies: The zk programs that need to be compiled before verification.
|
|
9
|
+
* address: The address of the smart contract on the blockchain.
|
|
10
|
+
* chain: The blockchain on which the smart contract is deployed.
|
|
11
|
+
* image: The logo of the smart contract (public url)
|
|
12
|
+
*
|
|
13
|
+
* Contract, contractDependencies, and programDependencies should be exported from the repo
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
export interface VerificationData {
|
|
17
|
+
contract: typeof SmartContract;
|
|
18
|
+
contractDependencies?: (typeof SmartContract)[];
|
|
19
|
+
programDependencies?: any[]; // ZkProgram[];
|
|
20
|
+
address: string;
|
|
21
|
+
chain: blockchain;
|
|
22
|
+
image?: string;
|
|
23
|
+
}
|