zkcloudworker 0.24.3 → 0.25.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/dist/node/index.cjs +99 -1
- package/dist/node/mina/index.d.ts +1 -1
- package/dist/node/mina/index.js +1 -1
- package/dist/node/mina/index.js.map +1 -1
- package/dist/node/mina/tokens/index.d.ts +2 -0
- package/dist/node/mina/tokens/index.js +3 -0
- package/dist/node/mina/tokens/index.js.map +1 -0
- package/dist/node/mina/tokens/nft.d.ts +30 -0
- package/dist/node/mina/tokens/nft.js +101 -0
- package/dist/node/mina/tokens/nft.js.map +1 -0
- package/dist/node/mina/tokens/token.d.ts +30 -0
- package/dist/node/mina/tokens/token.js +99 -0
- package/dist/node/mina/tokens/token.js.map +1 -0
- package/dist/node/mina/transactions/transaction.d.ts +1 -1
- package/dist/tsconfig.web.tsbuildinfo +1 -1
- package/dist/web/mina/index.d.ts +1 -1
- package/dist/web/mina/index.js +1 -1
- package/dist/web/mina/index.js.map +1 -1
- package/dist/web/mina/tokens/index.d.ts +2 -0
- package/dist/web/mina/tokens/index.js +3 -0
- package/dist/web/mina/tokens/index.js.map +1 -0
- package/dist/web/mina/tokens/nft.d.ts +30 -0
- package/dist/web/mina/tokens/nft.js +101 -0
- package/dist/web/mina/tokens/nft.js.map +1 -0
- package/dist/web/mina/tokens/token.d.ts +30 -0
- package/dist/web/mina/tokens/token.js +99 -0
- package/dist/web/mina/tokens/token.js.map +1 -0
- package/dist/web/mina/transactions/transaction.d.ts +1 -1
- package/package.json +3 -3
- package/src/mina/index.ts +1 -1
- package/src/mina/tokens/index.ts +2 -0
- package/src/mina/tokens/nft.ts +136 -0
- package/src/mina/{token/api.ts → tokens/token.ts} +6 -4
- package/src/mina/transactions/transaction.ts +1 -1
- package/src/mina/token/index.ts +0 -1
package/dist/node/index.cjs
CHANGED
|
@@ -38,6 +38,7 @@ __export(index_exports, {
|
|
|
38
38
|
LocalStorage: () => LocalStorage,
|
|
39
39
|
Mainnet: () => Mainnet,
|
|
40
40
|
Memory: () => Memory,
|
|
41
|
+
NftAPI: () => NftAPI,
|
|
41
42
|
Storage: () => Storage,
|
|
42
43
|
TinyContract: () => TinyContract,
|
|
43
44
|
TokenAPI: () => TokenAPI,
|
|
@@ -1876,7 +1877,7 @@ function deserializeIndexedMerkleMapInternal(params) {
|
|
|
1876
1877
|
return map;
|
|
1877
1878
|
}
|
|
1878
1879
|
|
|
1879
|
-
// dist/node/mina/token
|
|
1880
|
+
// dist/node/mina/tokens/token.js
|
|
1880
1881
|
var TokenAPI = class {
|
|
1881
1882
|
constructor(params) {
|
|
1882
1883
|
const { jwt, zkcloudworker, chain } = params;
|
|
@@ -1970,6 +1971,102 @@ var TokenAPI = class {
|
|
|
1970
1971
|
}
|
|
1971
1972
|
};
|
|
1972
1973
|
|
|
1974
|
+
// dist/node/mina/tokens/nft.js
|
|
1975
|
+
var NftAPI = class {
|
|
1976
|
+
constructor(params) {
|
|
1977
|
+
const { jwt, zkcloudworker, chain } = params;
|
|
1978
|
+
if (jwt === void 0)
|
|
1979
|
+
throw new Error("jwt is undefined");
|
|
1980
|
+
this.client = new zkCloudWorkerClient({
|
|
1981
|
+
jwt,
|
|
1982
|
+
chain,
|
|
1983
|
+
zkcloudworker
|
|
1984
|
+
});
|
|
1985
|
+
}
|
|
1986
|
+
async proveTransaction(params) {
|
|
1987
|
+
return this.proveTransactions([params]);
|
|
1988
|
+
}
|
|
1989
|
+
async proveTransactions(params) {
|
|
1990
|
+
const transactions = [];
|
|
1991
|
+
for (const tx of params) {
|
|
1992
|
+
const transaction = JSON.stringify(tx, null, 2);
|
|
1993
|
+
transactions.push(transaction);
|
|
1994
|
+
}
|
|
1995
|
+
const { request, symbol } = params[0];
|
|
1996
|
+
const { txType } = request;
|
|
1997
|
+
const answer = await this.client.execute({
|
|
1998
|
+
developer: "DFST",
|
|
1999
|
+
repo: "nft-agent",
|
|
2000
|
+
transactions,
|
|
2001
|
+
task: "prove",
|
|
2002
|
+
args: JSON.stringify({
|
|
2003
|
+
collectionAddress: params[0].request.collectionAddress
|
|
2004
|
+
}),
|
|
2005
|
+
metadata: `${params.length > 1 ? "airdrop" : txType.replace(/^token:/, "")} token${symbol ? ` ${symbol}` : ""}${params.length > 1 ? ` (${params.length} txs)` : ""}`
|
|
2006
|
+
});
|
|
2007
|
+
const jobId = answer.jobId;
|
|
2008
|
+
if (jobId === void 0)
|
|
2009
|
+
console.error("Job ID is undefined", { answer, txType, symbol });
|
|
2010
|
+
return jobId;
|
|
2011
|
+
}
|
|
2012
|
+
// Warning: this function will block the thread until the job is done and will print logs to the console
|
|
2013
|
+
// Do not use it in "use server" functions, use getResults instead
|
|
2014
|
+
async waitForJobResults(params) {
|
|
2015
|
+
const deployResult = await this.client.waitForJobResult(params);
|
|
2016
|
+
console.log("waitForJobResult result:", deployResult?.result?.result?.slice(0, 50));
|
|
2017
|
+
return deployResult?.result?.result ?? "error";
|
|
2018
|
+
}
|
|
2019
|
+
async getResults(jobId) {
|
|
2020
|
+
try {
|
|
2021
|
+
const callResult = await this.client.jobResult({ jobId });
|
|
2022
|
+
const jobStatus = typeof callResult?.result === "string" ? void 0 : callResult?.result?.jobStatus;
|
|
2023
|
+
if (!callResult.success) {
|
|
2024
|
+
return {
|
|
2025
|
+
success: false,
|
|
2026
|
+
error: callResult?.error,
|
|
2027
|
+
jobStatus
|
|
2028
|
+
};
|
|
2029
|
+
}
|
|
2030
|
+
const jobResult = callResult.result?.result;
|
|
2031
|
+
if (callResult.error)
|
|
2032
|
+
return {
|
|
2033
|
+
success: false,
|
|
2034
|
+
error: callResult.error,
|
|
2035
|
+
jobStatus
|
|
2036
|
+
};
|
|
2037
|
+
if (!jobResult)
|
|
2038
|
+
return { success: true, jobStatus };
|
|
2039
|
+
if (jobResult.toLowerCase().startsWith("error"))
|
|
2040
|
+
return {
|
|
2041
|
+
success: false,
|
|
2042
|
+
error: jobResult,
|
|
2043
|
+
jobStatus
|
|
2044
|
+
};
|
|
2045
|
+
try {
|
|
2046
|
+
const { proofs } = JSON.parse(jobResult);
|
|
2047
|
+
const results = [];
|
|
2048
|
+
for (const proof of proofs) {
|
|
2049
|
+
const { success, tx, hash, error } = JSON.parse(proof);
|
|
2050
|
+
results.push({ success, tx, hash, error });
|
|
2051
|
+
}
|
|
2052
|
+
return { success: true, results, jobStatus };
|
|
2053
|
+
} catch (e) {
|
|
2054
|
+
return {
|
|
2055
|
+
success: false,
|
|
2056
|
+
error: `Error parsing job result: ${jobResult} ${e?.message ?? ""}`,
|
|
2057
|
+
jobStatus
|
|
2058
|
+
};
|
|
2059
|
+
}
|
|
2060
|
+
} catch (e) {
|
|
2061
|
+
return {
|
|
2062
|
+
success: false,
|
|
2063
|
+
error: `Error getting job result: ${e?.message ?? ""}`,
|
|
2064
|
+
jobStatus: void 0
|
|
2065
|
+
};
|
|
2066
|
+
}
|
|
2067
|
+
}
|
|
2068
|
+
};
|
|
2069
|
+
|
|
1973
2070
|
// dist/node/mina/transactions/blockberry.js
|
|
1974
2071
|
async function getZkAppTxsFromBlockBerry(params) {
|
|
1975
2072
|
const { account, chain, blockBerryApiKey } = params;
|
|
@@ -2646,6 +2743,7 @@ var Storage = class _Storage extends (0, import_o1js12.Struct)({
|
|
|
2646
2743
|
LocalStorage,
|
|
2647
2744
|
Mainnet,
|
|
2648
2745
|
Memory,
|
|
2746
|
+
NftAPI,
|
|
2649
2747
|
Storage,
|
|
2650
2748
|
TinyContract,
|
|
2651
2749
|
TokenAPI,
|
|
@@ -2,6 +2,6 @@ export * from "./api/api.js";
|
|
|
2
2
|
export * from "./utils/index.js";
|
|
3
3
|
export * from "./local/local.js";
|
|
4
4
|
export * from "./verification/index.js";
|
|
5
|
-
export * from "./
|
|
5
|
+
export * from "./tokens/index.js";
|
|
6
6
|
export * from "./transactions/index.js";
|
|
7
7
|
export * from "./storage/index.js";
|
package/dist/node/mina/index.js
CHANGED
|
@@ -3,7 +3,7 @@ export * from "./api/api.js";
|
|
|
3
3
|
export * from "./utils/index.js";
|
|
4
4
|
export * from "./local/local.js";
|
|
5
5
|
export * from "./verification/index.js";
|
|
6
|
-
export * from "./
|
|
6
|
+
export * from "./tokens/index.js";
|
|
7
7
|
export * from "./transactions/index.js";
|
|
8
8
|
export * from "./storage/index.js";
|
|
9
9
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/mina/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAC7B,+BAA+B;AAC/B,cAAc,kBAAkB,CAAC;AACjC,cAAc,kBAAkB,CAAC;AACjC,cAAc,yBAAyB,CAAC;AACxC,cAAc,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/mina/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAC7B,+BAA+B;AAC/B,cAAc,kBAAkB,CAAC;AACjC,cAAc,kBAAkB,CAAC;AACjC,cAAc,yBAAyB,CAAC;AACxC,cAAc,mBAAmB,CAAC;AAClC,cAAc,yBAAyB,CAAC;AACxC,cAAc,oBAAoB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/mina/tokens/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,UAAU,CAAC"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { blockchain, Cloud, JobStatus } from "../../cloud/index.js";
|
|
2
|
+
import { zkCloudWorkerClient } from "../api/api.js";
|
|
3
|
+
import { zkCloudWorker } from "../../cloud/worker/index.js";
|
|
4
|
+
import { NftTransaction, JobResult } from "@silvana-one/api";
|
|
5
|
+
export declare class NftAPI {
|
|
6
|
+
readonly client: zkCloudWorkerClient;
|
|
7
|
+
constructor(params: {
|
|
8
|
+
jwt: string;
|
|
9
|
+
zkcloudworker?: (cloud: Cloud) => Promise<zkCloudWorker>;
|
|
10
|
+
chain: blockchain;
|
|
11
|
+
});
|
|
12
|
+
proveTransaction(params: NftTransaction): Promise<string | undefined>;
|
|
13
|
+
proveTransactions(params: NftTransaction[]): Promise<string | undefined>;
|
|
14
|
+
waitForJobResults(params: {
|
|
15
|
+
jobId: string;
|
|
16
|
+
maxAttempts?: number;
|
|
17
|
+
interval?: number;
|
|
18
|
+
maxErrors?: number;
|
|
19
|
+
printLogs?: boolean;
|
|
20
|
+
}): Promise<(string | undefined)[]>;
|
|
21
|
+
getResults(jobId: string): Promise<{
|
|
22
|
+
success: true;
|
|
23
|
+
results?: JobResult[];
|
|
24
|
+
jobStatus?: JobStatus;
|
|
25
|
+
} | {
|
|
26
|
+
success: false;
|
|
27
|
+
error?: string;
|
|
28
|
+
jobStatus?: JobStatus;
|
|
29
|
+
}>;
|
|
30
|
+
}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import { zkCloudWorkerClient } from "../api/api.js";
|
|
2
|
+
export class NftAPI {
|
|
3
|
+
constructor(params) {
|
|
4
|
+
const { jwt, zkcloudworker, chain } = params;
|
|
5
|
+
if (jwt === undefined)
|
|
6
|
+
throw new Error("jwt is undefined");
|
|
7
|
+
this.client = new zkCloudWorkerClient({
|
|
8
|
+
jwt,
|
|
9
|
+
chain,
|
|
10
|
+
zkcloudworker,
|
|
11
|
+
});
|
|
12
|
+
}
|
|
13
|
+
async proveTransaction(params) {
|
|
14
|
+
return this.proveTransactions([params]);
|
|
15
|
+
}
|
|
16
|
+
async proveTransactions(params) {
|
|
17
|
+
const transactions = [];
|
|
18
|
+
for (const tx of params) {
|
|
19
|
+
const transaction = JSON.stringify(tx, null, 2);
|
|
20
|
+
transactions.push(transaction);
|
|
21
|
+
}
|
|
22
|
+
const { request, symbol } = params[0];
|
|
23
|
+
const { txType } = request;
|
|
24
|
+
const answer = await this.client.execute({
|
|
25
|
+
developer: "DFST",
|
|
26
|
+
repo: "nft-agent",
|
|
27
|
+
transactions,
|
|
28
|
+
task: "prove",
|
|
29
|
+
args: JSON.stringify({
|
|
30
|
+
collectionAddress: params[0].request.collectionAddress,
|
|
31
|
+
}),
|
|
32
|
+
metadata: `${params.length > 1 ? "airdrop" : txType.replace(/^token:/, "")} token${symbol ? ` ${symbol}` : ""}${params.length > 1 ? ` (${params.length} txs)` : ""}`,
|
|
33
|
+
});
|
|
34
|
+
const jobId = answer.jobId;
|
|
35
|
+
if (jobId === undefined)
|
|
36
|
+
console.error("Job ID is undefined", { answer, txType, symbol });
|
|
37
|
+
return jobId;
|
|
38
|
+
}
|
|
39
|
+
// Warning: this function will block the thread until the job is done and will print logs to the console
|
|
40
|
+
// Do not use it in "use server" functions, use getResults instead
|
|
41
|
+
async waitForJobResults(params) {
|
|
42
|
+
const deployResult = await this.client.waitForJobResult(params);
|
|
43
|
+
console.log("waitForJobResult result:", deployResult?.result?.result?.slice(0, 50));
|
|
44
|
+
return deployResult?.result?.result ?? "error";
|
|
45
|
+
}
|
|
46
|
+
async getResults(jobId) {
|
|
47
|
+
try {
|
|
48
|
+
const callResult = await this.client.jobResult({ jobId });
|
|
49
|
+
// TODO: filter the repo and developer
|
|
50
|
+
const jobStatus = typeof callResult?.result === "string"
|
|
51
|
+
? undefined
|
|
52
|
+
: callResult?.result?.jobStatus;
|
|
53
|
+
if (!callResult.success) {
|
|
54
|
+
return {
|
|
55
|
+
success: false,
|
|
56
|
+
error: callResult?.error,
|
|
57
|
+
jobStatus,
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
const jobResult = callResult.result?.result;
|
|
61
|
+
if (callResult.error)
|
|
62
|
+
return {
|
|
63
|
+
success: false,
|
|
64
|
+
error: callResult.error,
|
|
65
|
+
jobStatus,
|
|
66
|
+
};
|
|
67
|
+
if (!jobResult)
|
|
68
|
+
return { success: true, jobStatus };
|
|
69
|
+
if (jobResult.toLowerCase().startsWith("error"))
|
|
70
|
+
return {
|
|
71
|
+
success: false,
|
|
72
|
+
error: jobResult,
|
|
73
|
+
jobStatus,
|
|
74
|
+
};
|
|
75
|
+
try {
|
|
76
|
+
const { proofs } = JSON.parse(jobResult);
|
|
77
|
+
const results = [];
|
|
78
|
+
for (const proof of proofs) {
|
|
79
|
+
const { success, tx, hash, error } = JSON.parse(proof);
|
|
80
|
+
results.push({ success, tx, hash, error });
|
|
81
|
+
}
|
|
82
|
+
return { success: true, results, jobStatus };
|
|
83
|
+
}
|
|
84
|
+
catch (e) {
|
|
85
|
+
return {
|
|
86
|
+
success: false,
|
|
87
|
+
error: `Error parsing job result: ${jobResult} ${e?.message ?? ""}`,
|
|
88
|
+
jobStatus,
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
catch (e) {
|
|
93
|
+
return {
|
|
94
|
+
success: false,
|
|
95
|
+
error: `Error getting job result: ${e?.message ?? ""}`,
|
|
96
|
+
jobStatus: undefined,
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
//# sourceMappingURL=nft.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"nft.js","sourceRoot":"","sources":["../../../../src/mina/tokens/nft.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAC;AAIpD,MAAM,OAAO,MAAM;IAGjB,YAAY,MAIX;QACC,MAAM,EAAE,GAAG,EAAE,aAAa,EAAE,KAAK,EAAE,GAAG,MAAM,CAAC;QAC7C,IAAI,GAAG,KAAK,SAAS;YAAE,MAAM,IAAI,KAAK,CAAC,kBAAkB,CAAC,CAAC;QAE3D,IAAI,CAAC,MAAM,GAAG,IAAI,mBAAmB,CAAC;YACpC,GAAG;YACH,KAAK;YACL,aAAa;SACd,CAAC,CAAC;IACL,CAAC;IAED,KAAK,CAAC,gBAAgB,CAAC,MAAsB;QAC3C,OAAO,IAAI,CAAC,iBAAiB,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC;IAC1C,CAAC;IAED,KAAK,CAAC,iBAAiB,CACr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AAC;gBACH,MAAM,EAAE,MAAM,EAAE,GAAG,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC;gBACzC,MAAM,OAAO,GAAgB,EAAE,CAAC;gBAChC,KAAK,MAAM,KAAK,IAAI,MAAM,EAAE,CAAC;oBAC3B,MAAM,EAAE,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE,GAAG,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;oBACvD,OAAO,CAAC,IAAI,CAAC,EAAE,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC,CAAC;gBAC7C,CAAC;gBACD,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,SAAS,EAAE,CAAC;YAC/C,CAAC;YAAC,OAAO,CAAM,EAAE,CAAC;gBAChB,OAAO;oBACL,OAAO,EAAE,KAAK;oBACd,KAAK,EAAE,6BAA6B,SAAS,IAAI,CAAC,EAAE,OAAO,IAAI,EAAE,EAAE;oBACnE,SAAS;iBACV,CAAC;YACJ,CAAC;QACH,CAAC;QAAC,OAAO,CAAM,EAAE,CAAC;YAChB,OAAO;gBACL,OAAO,EAAE,KAAK;gBACd,KAAK,EAAE,6BAA6B,CAAC,EAAE,OAAO,IAAI,EAAE,EAAE;gBACtD,SAAS,EAAE,SAAS;aACrB,CAAC;QACJ,CAAC;IACH,CAAC;CACF"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { blockchain, Cloud, JobStatus } from "../../cloud/index.js";
|
|
2
|
+
import { zkCloudWorkerClient } from "../api/api.js";
|
|
3
|
+
import { zkCloudWorker } from "../../cloud/worker/index.js";
|
|
4
|
+
import { TokenTransaction, JobResult } from "@silvana-one/api";
|
|
5
|
+
export declare class TokenAPI {
|
|
6
|
+
readonly client: zkCloudWorkerClient;
|
|
7
|
+
constructor(params: {
|
|
8
|
+
jwt: string;
|
|
9
|
+
zkcloudworker?: (cloud: Cloud) => Promise<zkCloudWorker>;
|
|
10
|
+
chain: blockchain;
|
|
11
|
+
});
|
|
12
|
+
proveTransaction(params: TokenTransaction): Promise<string | undefined>;
|
|
13
|
+
proveTransactions(params: TokenTransaction[]): Promise<string | undefined>;
|
|
14
|
+
waitForJobResults(params: {
|
|
15
|
+
jobId: string;
|
|
16
|
+
maxAttempts?: number;
|
|
17
|
+
interval?: number;
|
|
18
|
+
maxErrors?: number;
|
|
19
|
+
printLogs?: boolean;
|
|
20
|
+
}): Promise<(string | undefined)[]>;
|
|
21
|
+
getResults(jobId: string): Promise<{
|
|
22
|
+
success: true;
|
|
23
|
+
results?: JobResult[];
|
|
24
|
+
jobStatus?: JobStatus;
|
|
25
|
+
} | {
|
|
26
|
+
success: false;
|
|
27
|
+
error?: string;
|
|
28
|
+
jobStatus?: JobStatus;
|
|
29
|
+
}>;
|
|
30
|
+
}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { zkCloudWorkerClient } from "../api/api.js";
|
|
2
|
+
export class TokenAPI {
|
|
3
|
+
constructor(params) {
|
|
4
|
+
const { jwt, zkcloudworker, chain } = params;
|
|
5
|
+
if (jwt === undefined)
|
|
6
|
+
throw new Error("jwt is undefined");
|
|
7
|
+
this.client = new zkCloudWorkerClient({
|
|
8
|
+
jwt,
|
|
9
|
+
chain,
|
|
10
|
+
zkcloudworker,
|
|
11
|
+
});
|
|
12
|
+
}
|
|
13
|
+
async proveTransaction(params) {
|
|
14
|
+
return this.proveTransactions([params]);
|
|
15
|
+
}
|
|
16
|
+
async proveTransactions(params) {
|
|
17
|
+
const transactions = [];
|
|
18
|
+
for (const tx of params) {
|
|
19
|
+
const transaction = JSON.stringify(tx, null, 2);
|
|
20
|
+
transactions.push(transaction);
|
|
21
|
+
}
|
|
22
|
+
const { request, symbol } = params[0];
|
|
23
|
+
const { txType } = request;
|
|
24
|
+
const answer = await this.client.execute({
|
|
25
|
+
developer: "DFST",
|
|
26
|
+
repo: "token-launchpad",
|
|
27
|
+
transactions,
|
|
28
|
+
task: "prove",
|
|
29
|
+
args: JSON.stringify({ tokenAddress: params[0].request.tokenAddress }),
|
|
30
|
+
metadata: `${params.length > 1 ? "airdrop" : txType.replace(/^token:/, "")} token${symbol ? ` ${symbol}` : ""}${params.length > 1 ? ` (${params.length} txs)` : ""}`,
|
|
31
|
+
});
|
|
32
|
+
const jobId = answer.jobId;
|
|
33
|
+
if (jobId === undefined)
|
|
34
|
+
console.error("Job ID is undefined", { answer, txType, symbol });
|
|
35
|
+
return jobId;
|
|
36
|
+
}
|
|
37
|
+
// Warning: this function will block the thread until the job is done and will print logs to the console
|
|
38
|
+
// Do not use it in "use server" functions, use getResults instead
|
|
39
|
+
async waitForJobResults(params) {
|
|
40
|
+
const deployResult = await this.client.waitForJobResult(params);
|
|
41
|
+
console.log("waitForJobResult result:", deployResult?.result?.result?.slice(0, 50));
|
|
42
|
+
return deployResult?.result?.result ?? "error";
|
|
43
|
+
}
|
|
44
|
+
async getResults(jobId) {
|
|
45
|
+
try {
|
|
46
|
+
const callResult = await this.client.jobResult({ jobId });
|
|
47
|
+
// TODO: filter the repo and developer
|
|
48
|
+
const jobStatus = typeof callResult?.result === "string"
|
|
49
|
+
? undefined
|
|
50
|
+
: callResult?.result?.jobStatus;
|
|
51
|
+
if (!callResult.success) {
|
|
52
|
+
return {
|
|
53
|
+
success: false,
|
|
54
|
+
error: callResult?.error,
|
|
55
|
+
jobStatus,
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
const jobResult = callResult.result?.result;
|
|
59
|
+
if (callResult.error)
|
|
60
|
+
return {
|
|
61
|
+
success: false,
|
|
62
|
+
error: callResult.error,
|
|
63
|
+
jobStatus,
|
|
64
|
+
};
|
|
65
|
+
if (!jobResult)
|
|
66
|
+
return { success: true, jobStatus };
|
|
67
|
+
if (jobResult.toLowerCase().startsWith("error"))
|
|
68
|
+
return {
|
|
69
|
+
success: false,
|
|
70
|
+
error: jobResult,
|
|
71
|
+
jobStatus,
|
|
72
|
+
};
|
|
73
|
+
try {
|
|
74
|
+
const { proofs } = JSON.parse(jobResult);
|
|
75
|
+
const results = [];
|
|
76
|
+
for (const proof of proofs) {
|
|
77
|
+
const { success, tx, hash, error } = JSON.parse(proof);
|
|
78
|
+
results.push({ success, tx, hash, error });
|
|
79
|
+
}
|
|
80
|
+
return { success: true, results, jobStatus };
|
|
81
|
+
}
|
|
82
|
+
catch (e) {
|
|
83
|
+
return {
|
|
84
|
+
success: false,
|
|
85
|
+
error: `Error parsing job result: ${jobResult} ${e?.message ?? ""}`,
|
|
86
|
+
jobStatus,
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
catch (e) {
|
|
91
|
+
return {
|
|
92
|
+
success: false,
|
|
93
|
+
error: `Error getting job result: ${e?.message ?? ""}`,
|
|
94
|
+
jobStatus: undefined,
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
//# sourceMappingURL=token.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"token.js","sourceRoot":"","sources":["../../../../src/mina/tokens/token.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAC;AAIpD,MAAM,OAAO,QAAQ;IAGnB,YAAY,MAIX;QACC,MAAM,EAAE,GAAG,EAAE,aAAa,EAAE,KAAK,EAAE,GAAG,MAAM,CAAC;QAC7C,IAAI,GAAG,KAAK,SAAS;YAAE,MAAM,IAAI,KAAK,CAAC,kBAAkB,CAAC,CAAC;QAE3D,IAAI,CAAC,MAAM,GAAG,IAAI,mBAAmB,CAAC;YACpC,GAAG;YACH,KAAK;YACL,aAAa;SACd,CAAC,CAAC;IACL,CAAC;IAED,KAAK,CAAC,gBAAgB,CACpB,MAAwB;QAExB,OAAO,IAAI,CAAC,iBAAiB,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC;IAC1C,CAAC;IAED,KAAK,CAAC,iBAAiB,CACrB,MAA0B;QAE1B,MA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E,MAAM,EAAE,GAAG,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC;gBACzC,MAAM,OAAO,GAAgB,EAAE,CAAC;gBAChC,KAAK,MAAM,KAAK,IAAI,MAAM,EAAE,CAAC;oBAC3B,MAAM,EAAE,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE,GAAG,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;oBACvD,OAAO,CAAC,IAAI,CAAC,EAAE,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC,CAAC;gBAC7C,CAAC;gBACD,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,SAAS,EAAE,CAAC;YAC/C,CAAC;YAAC,OAAO,CAAM,EAAE,CAAC;gBAChB,OAAO;oBACL,OAAO,EAAE,KAAK;oBACd,KAAK,EAAE,6BAA6B,SAAS,IAAI,CAAC,EAAE,OAAO,IAAI,EAAE,EAAE;oBACnE,SAAS;iBACV,CAAC;YACJ,CAAC;QACH,CAAC;QAAC,OAAO,CAAM,EAAE,CAAC;YAChB,OAAO;gBACL,OAAO,EAAE,KAAK;gBACd,KAAK,EAAE,6BAA6B,CAAC,EAAE,OAAO,IAAI,EAAE,EAAE;gBACtD,SAAS,EAAE,SAAS;aACrB,CAAC;QACJ,CAAC;IACH,CAAC;CACF"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { PublicKey, Transaction, Mina, UInt64 } from "o1js";
|
|
2
|
-
import { TransactionPayloads } from "@
|
|
2
|
+
import { TransactionPayloads } from "@silvana-one/api";
|
|
3
3
|
export declare function createTransactionPayloads(tx: Mina.Transaction<false, false> | Mina.Transaction<false, true>): TransactionPayloads;
|
|
4
4
|
export declare function transactionParams(params: {
|
|
5
5
|
proverPayload: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"root":["../src/index.ts","../src/cloud/config.ts","../src/cloud/index.ts","../src/cloud/networks.ts","../src/cloud/utils/base64.ts","../src/cloud/utils/graphql.ts","../src/cloud/utils/index.ts","../src/cloud/utils/utils.ts","../src/cloud/worker/cloud.ts","../src/cloud/worker/index.ts","../src/cloud/worker/job.ts","../src/cloud/worker/task.ts","../src/cloud/worker/transaction.ts","../src/cloud/worker/worker.ts","../src/mina/index.ts","../src/mina/api/api.ts","../src/mina/local/local.ts","../src/mina/storage/index.ts","../src/mina/storage/ipfs.ts","../src/mina/storage/pinata.ts","../src/mina/storage/storage.ts","../src/mina/
|
|
1
|
+
{"root":["../src/index.ts","../src/cloud/config.ts","../src/cloud/index.ts","../src/cloud/networks.ts","../src/cloud/utils/base64.ts","../src/cloud/utils/graphql.ts","../src/cloud/utils/index.ts","../src/cloud/utils/utils.ts","../src/cloud/worker/cloud.ts","../src/cloud/worker/index.ts","../src/cloud/worker/job.ts","../src/cloud/worker/task.ts","../src/cloud/worker/transaction.ts","../src/cloud/worker/worker.ts","../src/mina/index.ts","../src/mina/api/api.ts","../src/mina/local/local.ts","../src/mina/storage/index.ts","../src/mina/storage/ipfs.ts","../src/mina/storage/pinata.ts","../src/mina/storage/storage.ts","../src/mina/tokens/index.ts","../src/mina/tokens/nft.ts","../src/mina/tokens/token.ts","../src/mina/transactions/account.ts","../src/mina/transactions/blockberry.ts","../src/mina/transactions/chain.ts","../src/mina/transactions/index.ts","../src/mina/transactions/nonce.ts","../src/mina/transactions/send.ts","../src/mina/transactions/tiny-contract.ts","../src/mina/transactions/transaction.ts","../src/mina/transactions/txstatus.ts","../src/mina/utils/base64.ts","../src/mina/utils/fee.ts","../src/mina/utils/fetch.ts","../src/mina/utils/fields.ts","../src/mina/utils/index.ts","../src/mina/utils/indexed-map.ts","../src/mina/utils/mina.ts","../src/mina/verification/index.ts","../src/mina/verification/verification.ts"],"version":"5.7.3"}
|
package/dist/web/mina/index.d.ts
CHANGED
|
@@ -2,6 +2,6 @@ export * from "./api/api.js";
|
|
|
2
2
|
export * from "./utils/index.js";
|
|
3
3
|
export * from "./local/local.js";
|
|
4
4
|
export * from "./verification/index.js";
|
|
5
|
-
export * from "./
|
|
5
|
+
export * from "./tokens/index.js";
|
|
6
6
|
export * from "./transactions/index.js";
|
|
7
7
|
export * from "./storage/index.js";
|
package/dist/web/mina/index.js
CHANGED
|
@@ -3,7 +3,7 @@ export * from "./api/api.js";
|
|
|
3
3
|
export * from "./utils/index.js";
|
|
4
4
|
export * from "./local/local.js";
|
|
5
5
|
export * from "./verification/index.js";
|
|
6
|
-
export * from "./
|
|
6
|
+
export * from "./tokens/index.js";
|
|
7
7
|
export * from "./transactions/index.js";
|
|
8
8
|
export * from "./storage/index.js";
|
|
9
9
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/mina/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAC7B,+BAA+B;AAC/B,cAAc,kBAAkB,CAAC;AACjC,cAAc,kBAAkB,CAAC;AACjC,cAAc,yBAAyB,CAAC;AACxC,cAAc,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/mina/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAC7B,+BAA+B;AAC/B,cAAc,kBAAkB,CAAC;AACjC,cAAc,kBAAkB,CAAC;AACjC,cAAc,yBAAyB,CAAC;AACxC,cAAc,mBAAmB,CAAC;AAClC,cAAc,yBAAyB,CAAC;AACxC,cAAc,oBAAoB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/mina/tokens/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,UAAU,CAAC"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { blockchain, Cloud, JobStatus } from "../../cloud/index.js";
|
|
2
|
+
import { zkCloudWorkerClient } from "../api/api.js";
|
|
3
|
+
import { zkCloudWorker } from "../../cloud/worker/index.js";
|
|
4
|
+
import { NftTransaction, JobResult } from "@silvana-one/api";
|
|
5
|
+
export declare class NftAPI {
|
|
6
|
+
readonly client: zkCloudWorkerClient;
|
|
7
|
+
constructor(params: {
|
|
8
|
+
jwt: string;
|
|
9
|
+
zkcloudworker?: (cloud: Cloud) => Promise<zkCloudWorker>;
|
|
10
|
+
chain: blockchain;
|
|
11
|
+
});
|
|
12
|
+
proveTransaction(params: NftTransaction): Promise<string | undefined>;
|
|
13
|
+
proveTransactions(params: NftTransaction[]): Promise<string | undefined>;
|
|
14
|
+
waitForJobResults(params: {
|
|
15
|
+
jobId: string;
|
|
16
|
+
maxAttempts?: number;
|
|
17
|
+
interval?: number;
|
|
18
|
+
maxErrors?: number;
|
|
19
|
+
printLogs?: boolean;
|
|
20
|
+
}): Promise<(string | undefined)[]>;
|
|
21
|
+
getResults(jobId: string): Promise<{
|
|
22
|
+
success: true;
|
|
23
|
+
results?: JobResult[];
|
|
24
|
+
jobStatus?: JobStatus;
|
|
25
|
+
} | {
|
|
26
|
+
success: false;
|
|
27
|
+
error?: string;
|
|
28
|
+
jobStatus?: JobStatus;
|
|
29
|
+
}>;
|
|
30
|
+
}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import { zkCloudWorkerClient } from "../api/api.js";
|
|
2
|
+
export class NftAPI {
|
|
3
|
+
constructor(params) {
|
|
4
|
+
const { jwt, zkcloudworker, chain } = params;
|
|
5
|
+
if (jwt === undefined)
|
|
6
|
+
throw new Error("jwt is undefined");
|
|
7
|
+
this.client = new zkCloudWorkerClient({
|
|
8
|
+
jwt,
|
|
9
|
+
chain,
|
|
10
|
+
zkcloudworker,
|
|
11
|
+
});
|
|
12
|
+
}
|
|
13
|
+
async proveTransaction(params) {
|
|
14
|
+
return this.proveTransactions([params]);
|
|
15
|
+
}
|
|
16
|
+
async proveTransactions(params) {
|
|
17
|
+
const transactions = [];
|
|
18
|
+
for (const tx of params) {
|
|
19
|
+
const transaction = JSON.stringify(tx, null, 2);
|
|
20
|
+
transactions.push(transaction);
|
|
21
|
+
}
|
|
22
|
+
const { request, symbol } = params[0];
|
|
23
|
+
const { txType } = request;
|
|
24
|
+
const answer = await this.client.execute({
|
|
25
|
+
developer: "DFST",
|
|
26
|
+
repo: "nft-agent",
|
|
27
|
+
transactions,
|
|
28
|
+
task: "prove",
|
|
29
|
+
args: JSON.stringify({
|
|
30
|
+
collectionAddress: params[0].request.collectionAddress,
|
|
31
|
+
}),
|
|
32
|
+
metadata: `${params.length > 1 ? "airdrop" : txType.replace(/^token:/, "")} token${symbol ? ` ${symbol}` : ""}${params.length > 1 ? ` (${params.length} txs)` : ""}`,
|
|
33
|
+
});
|
|
34
|
+
const jobId = answer.jobId;
|
|
35
|
+
if (jobId === undefined)
|
|
36
|
+
console.error("Job ID is undefined", { answer, txType, symbol });
|
|
37
|
+
return jobId;
|
|
38
|
+
}
|
|
39
|
+
// Warning: this function will block the thread until the job is done and will print logs to the console
|
|
40
|
+
// Do not use it in "use server" functions, use getResults instead
|
|
41
|
+
async waitForJobResults(params) {
|
|
42
|
+
const deployResult = await this.client.waitForJobResult(params);
|
|
43
|
+
console.log("waitForJobResult result:", deployResult?.result?.result?.slice(0, 50));
|
|
44
|
+
return deployResult?.result?.result ?? "error";
|
|
45
|
+
}
|
|
46
|
+
async getResults(jobId) {
|
|
47
|
+
try {
|
|
48
|
+
const callResult = await this.client.jobResult({ jobId });
|
|
49
|
+
// TODO: filter the repo and developer
|
|
50
|
+
const jobStatus = typeof callResult?.result === "string"
|
|
51
|
+
? undefined
|
|
52
|
+
: callResult?.result?.jobStatus;
|
|
53
|
+
if (!callResult.success) {
|
|
54
|
+
return {
|
|
55
|
+
success: false,
|
|
56
|
+
error: callResult?.error,
|
|
57
|
+
jobStatus,
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
const jobResult = callResult.result?.result;
|
|
61
|
+
if (callResult.error)
|
|
62
|
+
return {
|
|
63
|
+
success: false,
|
|
64
|
+
error: callResult.error,
|
|
65
|
+
jobStatus,
|
|
66
|
+
};
|
|
67
|
+
if (!jobResult)
|
|
68
|
+
return { success: true, jobStatus };
|
|
69
|
+
if (jobResult.toLowerCase().startsWith("error"))
|
|
70
|
+
return {
|
|
71
|
+
success: false,
|
|
72
|
+
error: jobResult,
|
|
73
|
+
jobStatus,
|
|
74
|
+
};
|
|
75
|
+
try {
|
|
76
|
+
const { proofs } = JSON.parse(jobResult);
|
|
77
|
+
const results = [];
|
|
78
|
+
for (const proof of proofs) {
|
|
79
|
+
const { success, tx, hash, error } = JSON.parse(proof);
|
|
80
|
+
results.push({ success, tx, hash, error });
|
|
81
|
+
}
|
|
82
|
+
return { success: true, results, jobStatus };
|
|
83
|
+
}
|
|
84
|
+
catch (e) {
|
|
85
|
+
return {
|
|
86
|
+
success: false,
|
|
87
|
+
error: `Error parsing job result: ${jobResult} ${e?.message ?? ""}`,
|
|
88
|
+
jobStatus,
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
catch (e) {
|
|
93
|
+
return {
|
|
94
|
+
success: false,
|
|
95
|
+
error: `Error getting job result: ${e?.message ?? ""}`,
|
|
96
|
+
jobStatus: undefined,
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
//# sourceMappingURL=nft.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"nft.js","sourceRoot":"","sources":["../../../../src/mina/tokens/nft.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAC;AAIpD,MAAM,OAAO,MAAM;IAGjB,YAAY,MAIX;QACC,MAAM,EAAE,GAAG,EAAE,aAAa,EAAE,KAAK,EAAE,GAAG,MAAM,CAAC;QAC7C,IAAI,GAAG,KAAK,SAAS;YAAE,MAAM,IAAI,KAAK,CAAC,kBAAkB,CAAC,CAAC;QAE3D,IAAI,CAAC,MAAM,GAAG,IAAI,mBAAmB,CAAC;YACp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O,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC;YAEpD,IAAI,SAAS,CAAC,WAAW,EAAE,CAAC,UAAU,CAAC,OAAO,CAAC;gBAC7C,OAAO;oBACL,OAAO,EAAE,KAAK;oBACd,KAAK,EAAE,SAAS;oBAChB,SAAS;iBACV,CAAC;YAEJ,IAAI,CAAC;gBACH,MAAM,EAAE,MAAM,EAAE,GAAG,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC;gBACzC,MAAM,OAAO,GAAgB,EAAE,CAAC;gBAChC,KAAK,MAAM,KAAK,IAAI,MAAM,EAAE,CAAC;oBAC3B,MAAM,EAAE,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE,GAAG,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;oBACvD,OAAO,CAAC,IAAI,CAAC,EAAE,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC,CAAC;gBAC7C,CAAC;gBACD,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,SAAS,EAAE,CAAC;YAC/C,CAAC;YAAC,OAAO,CAAM,EAAE,CAAC;gBAChB,OAAO;oBACL,OAAO,EAAE,KAAK;oBACd,KAAK,EAAE,6BAA6B,SAAS,IAAI,CAAC,EAAE,OAAO,IAAI,EAAE,EAAE;oBACnE,SAAS;iBACV,CAAC;YACJ,CAAC;QACH,CAAC;QAAC,OAAO,CAAM,EAAE,CAAC;YAChB,OAAO;gBACL,OAAO,EAAE,KAAK;gBACd,KAAK,EAAE,6BAA6B,CAAC,EAAE,OAAO,IAAI,EAAE,EAAE;gBACtD,SAAS,EAAE,SAAS;aACrB,CAAC;QACJ,CAAC;IACH,CAAC;CACF"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { blockchain, Cloud, JobStatus } from "../../cloud/index.js";
|
|
2
|
+
import { zkCloudWorkerClient } from "../api/api.js";
|
|
3
|
+
import { zkCloudWorker } from "../../cloud/worker/index.js";
|
|
4
|
+
import { TokenTransaction, JobResult } from "@silvana-one/api";
|
|
5
|
+
export declare class TokenAPI {
|
|
6
|
+
readonly client: zkCloudWorkerClient;
|
|
7
|
+
constructor(params: {
|
|
8
|
+
jwt: string;
|
|
9
|
+
zkcloudworker?: (cloud: Cloud) => Promise<zkCloudWorker>;
|
|
10
|
+
chain: blockchain;
|
|
11
|
+
});
|
|
12
|
+
proveTransaction(params: TokenTransaction): Promise<string | undefined>;
|
|
13
|
+
proveTransactions(params: TokenTransaction[]): Promise<string | undefined>;
|
|
14
|
+
waitForJobResults(params: {
|
|
15
|
+
jobId: string;
|
|
16
|
+
maxAttempts?: number;
|
|
17
|
+
interval?: number;
|
|
18
|
+
maxErrors?: number;
|
|
19
|
+
printLogs?: boolean;
|
|
20
|
+
}): Promise<(string | undefined)[]>;
|
|
21
|
+
getResults(jobId: string): Promise<{
|
|
22
|
+
success: true;
|
|
23
|
+
results?: JobResult[];
|
|
24
|
+
jobStatus?: JobStatus;
|
|
25
|
+
} | {
|
|
26
|
+
success: false;
|
|
27
|
+
error?: string;
|
|
28
|
+
jobStatus?: JobStatus;
|
|
29
|
+
}>;
|
|
30
|
+
}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { zkCloudWorkerClient } from "../api/api.js";
|
|
2
|
+
export class TokenAPI {
|
|
3
|
+
constructor(params) {
|
|
4
|
+
const { jwt, zkcloudworker, chain } = params;
|
|
5
|
+
if (jwt === undefined)
|
|
6
|
+
throw new Error("jwt is undefined");
|
|
7
|
+
this.client = new zkCloudWorkerClient({
|
|
8
|
+
jwt,
|
|
9
|
+
chain,
|
|
10
|
+
zkcloudworker,
|
|
11
|
+
});
|
|
12
|
+
}
|
|
13
|
+
async proveTransaction(params) {
|
|
14
|
+
return this.proveTransactions([params]);
|
|
15
|
+
}
|
|
16
|
+
async proveTransactions(params) {
|
|
17
|
+
const transactions = [];
|
|
18
|
+
for (const tx of params) {
|
|
19
|
+
const transaction = JSON.stringify(tx, null, 2);
|
|
20
|
+
transactions.push(transaction);
|
|
21
|
+
}
|
|
22
|
+
const { request, symbol } = params[0];
|
|
23
|
+
const { txType } = request;
|
|
24
|
+
const answer = await this.client.execute({
|
|
25
|
+
developer: "DFST",
|
|
26
|
+
repo: "token-launchpad",
|
|
27
|
+
transactions,
|
|
28
|
+
task: "prove",
|
|
29
|
+
args: JSON.stringify({ tokenAddress: params[0].request.tokenAddress }),
|
|
30
|
+
metadata: `${params.length > 1 ? "airdrop" : txType.replace(/^token:/, "")} token${symbol ? ` ${symbol}` : ""}${params.length > 1 ? ` (${params.length} txs)` : ""}`,
|
|
31
|
+
});
|
|
32
|
+
const jobId = answer.jobId;
|
|
33
|
+
if (jobId === undefined)
|
|
34
|
+
console.error("Job ID is undefined", { answer, txType, symbol });
|
|
35
|
+
return jobId;
|
|
36
|
+
}
|
|
37
|
+
// Warning: this function will block the thread until the job is done and will print logs to the console
|
|
38
|
+
// Do not use it in "use server" functions, use getResults instead
|
|
39
|
+
async waitForJobResults(params) {
|
|
40
|
+
const deployResult = await this.client.waitForJobResult(params);
|
|
41
|
+
console.log("waitForJobResult result:", deployResult?.result?.result?.slice(0, 50));
|
|
42
|
+
return deployResult?.result?.result ?? "error";
|
|
43
|
+
}
|
|
44
|
+
async getResults(jobId) {
|
|
45
|
+
try {
|
|
46
|
+
const callResult = await this.client.jobResult({ jobId });
|
|
47
|
+
// TODO: filter the repo and developer
|
|
48
|
+
const jobStatus = typeof callResult?.result === "string"
|
|
49
|
+
? undefined
|
|
50
|
+
: callResult?.result?.jobStatus;
|
|
51
|
+
if (!callResult.success) {
|
|
52
|
+
return {
|
|
53
|
+
success: false,
|
|
54
|
+
error: callResult?.error,
|
|
55
|
+
jobStatus,
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
const jobResult = callResult.result?.result;
|
|
59
|
+
if (callResult.error)
|
|
60
|
+
return {
|
|
61
|
+
success: false,
|
|
62
|
+
error: callResult.error,
|
|
63
|
+
jobStatus,
|
|
64
|
+
};
|
|
65
|
+
if (!jobResult)
|
|
66
|
+
return { success: true, jobStatus };
|
|
67
|
+
if (jobResult.toLowerCase().startsWith("error"))
|
|
68
|
+
return {
|
|
69
|
+
success: false,
|
|
70
|
+
error: jobResult,
|
|
71
|
+
jobStatus,
|
|
72
|
+
};
|
|
73
|
+
try {
|
|
74
|
+
const { proofs } = JSON.parse(jobResult);
|
|
75
|
+
const results = [];
|
|
76
|
+
for (const proof of proofs) {
|
|
77
|
+
const { success, tx, hash, error } = JSON.parse(proof);
|
|
78
|
+
results.push({ success, tx, hash, error });
|
|
79
|
+
}
|
|
80
|
+
return { success: true, results, jobStatus };
|
|
81
|
+
}
|
|
82
|
+
catch (e) {
|
|
83
|
+
return {
|
|
84
|
+
success: false,
|
|
85
|
+
error: `Error parsing job result: ${jobResult} ${e?.message ?? ""}`,
|
|
86
|
+
jobStatus,
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
catch (e) {
|
|
91
|
+
return {
|
|
92
|
+
success: false,
|
|
93
|
+
error: `Error getting job result: ${e?.message ?? ""}`,
|
|
94
|
+
jobStatus: undefined,
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
//# sourceMappingURL=token.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"token.js","sourceRoot":"","sources":["../../../../src/mina/tokens/token.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAC;AAIpD,MAAM,OAAO,QAAQ;IAGnB,YAAY,MAIX;QACC,MAAM,EAAE,GAAG,EAAE,aAAa,EAAE,KAAK,EAAE,GAAG,MAAM,CAAC;QAC7C,IAAI,GAAG,KAAK,SAAS;YAAE,MAAM,IAAI,KAAK,CAAC,kBAAkB,CAAC,CAAC;QAE3D,IAAI,CAAC,MAAM,GAAG,IAAI,mBAAmB,CAAC;YACpC,GAAG;YACH,KAAK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SAAS,EAAE,CAAC;YAEpD,IAAI,SAAS,CAAC,WAAW,EAAE,CAAC,UAAU,CAAC,OAAO,CAAC;gBAC7C,OAAO;oBACL,OAAO,EAAE,KAAK;oBACd,KAAK,EAAE,SAAS;oBAChB,SAAS;iBACV,CAAC;YAEJ,IAAI,CAAC;gBACH,MAAM,EAAE,MAAM,EAAE,GAAG,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC;gBACzC,MAAM,OAAO,GAAgB,EAAE,CAAC;gBAChC,KAAK,MAAM,KAAK,IAAI,MAAM,EAAE,CAAC;oBAC3B,MAAM,EAAE,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE,GAAG,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;oBACvD,OAAO,CAAC,IAAI,CAAC,EAAE,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC,CAAC;gBAC7C,CAAC;gBACD,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,SAAS,EAAE,CAAC;YAC/C,CAAC;YAAC,OAAO,CAAM,EAAE,CAAC;gBAChB,OAAO;oBACL,OAAO,EAAE,KAAK;oBACd,KAAK,EAAE,6BAA6B,SAAS,IAAI,CAAC,EAAE,OAAO,IAAI,EAAE,EAAE;oBACnE,SAAS;iBACV,CAAC;YACJ,CAAC;QACH,CAAC;QAAC,OAAO,CAAM,EAAE,CAAC;YAChB,OAAO;gBACL,OAAO,EAAE,KAAK;gBACd,KAAK,EAAE,6BAA6B,CAAC,EAAE,OAAO,IAAI,EAAE,EAAE;gBACtD,SAAS,EAAE,SAAS;aACrB,CAAC;QACJ,CAAC;IACH,CAAC;CACF"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { PublicKey, Transaction, Mina, UInt64 } from "o1js";
|
|
2
|
-
import { TransactionPayloads } from "@
|
|
2
|
+
import { TransactionPayloads } from "@silvana-one/api";
|
|
3
3
|
export declare function createTransactionPayloads(tx: Mina.Transaction<false, false> | Mina.Transaction<false, true>): TransactionPayloads;
|
|
4
4
|
export declare function transactionParams(params: {
|
|
5
5
|
proverPayload: string;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "zkcloudworker",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.25.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "zkCloudWorker library",
|
|
6
6
|
"author": "zkCloudWorker",
|
|
@@ -49,7 +49,7 @@
|
|
|
49
49
|
"node": ">=20.0.0"
|
|
50
50
|
},
|
|
51
51
|
"dependencies": {
|
|
52
|
-
"@
|
|
52
|
+
"@silvana-one/api": "^0.1.2",
|
|
53
53
|
"chalk": "^4.1.2"
|
|
54
54
|
},
|
|
55
55
|
"peerDependencies": {
|
|
@@ -61,5 +61,5 @@
|
|
|
61
61
|
"o1js": "^2.2.0",
|
|
62
62
|
"typescript": "^5.7.3"
|
|
63
63
|
},
|
|
64
|
-
"packageManager": "yarn@4.
|
|
64
|
+
"packageManager": "yarn@4.6.0"
|
|
65
65
|
}
|
package/src/mina/index.ts
CHANGED
|
@@ -3,6 +3,6 @@ export * from "./api/api.js";
|
|
|
3
3
|
export * from "./utils/index.js";
|
|
4
4
|
export * from "./local/local.js";
|
|
5
5
|
export * from "./verification/index.js";
|
|
6
|
-
export * from "./
|
|
6
|
+
export * from "./tokens/index.js";
|
|
7
7
|
export * from "./transactions/index.js";
|
|
8
8
|
export * from "./storage/index.js";
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
import { blockchain, Cloud, JobStatus } from "../../cloud/index.js";
|
|
2
|
+
import { zkCloudWorkerClient } from "../api/api.js";
|
|
3
|
+
import { zkCloudWorker } from "../../cloud/worker/index.js";
|
|
4
|
+
import { NftTransaction, JobResult } from "@silvana-one/api";
|
|
5
|
+
|
|
6
|
+
export class NftAPI {
|
|
7
|
+
readonly client: zkCloudWorkerClient;
|
|
8
|
+
|
|
9
|
+
constructor(params: {
|
|
10
|
+
jwt: string;
|
|
11
|
+
zkcloudworker?: (cloud: Cloud) => Promise<zkCloudWorker>;
|
|
12
|
+
chain: blockchain;
|
|
13
|
+
}) {
|
|
14
|
+
const { jwt, zkcloudworker, chain } = params;
|
|
15
|
+
if (jwt === undefined) throw new Error("jwt is undefined");
|
|
16
|
+
|
|
17
|
+
this.client = new zkCloudWorkerClient({
|
|
18
|
+
jwt,
|
|
19
|
+
chain,
|
|
20
|
+
zkcloudworker,
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
async proveTransaction(params: NftTransaction): Promise<string | undefined> {
|
|
25
|
+
return this.proveTransactions([params]);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
async proveTransactions(
|
|
29
|
+
params: NftTransaction[]
|
|
30
|
+
): Promise<string | undefined> {
|
|
31
|
+
const transactions: string[] = [];
|
|
32
|
+
for (const tx of params) {
|
|
33
|
+
const transaction = JSON.stringify(tx, null, 2);
|
|
34
|
+
transactions.push(transaction);
|
|
35
|
+
}
|
|
36
|
+
const { request, symbol } = params[0];
|
|
37
|
+
const { txType } = request;
|
|
38
|
+
|
|
39
|
+
const answer = await this.client.execute({
|
|
40
|
+
developer: "DFST",
|
|
41
|
+
repo: "nft-agent",
|
|
42
|
+
transactions,
|
|
43
|
+
task: "prove",
|
|
44
|
+
args: JSON.stringify({
|
|
45
|
+
collectionAddress: params[0].request.collectionAddress,
|
|
46
|
+
}),
|
|
47
|
+
metadata: `${
|
|
48
|
+
params.length > 1 ? "airdrop" : txType.replace(/^token:/, "")
|
|
49
|
+
} token${symbol ? ` ${symbol}` : ""}${
|
|
50
|
+
params.length > 1 ? ` (${params.length} txs)` : ""
|
|
51
|
+
}`,
|
|
52
|
+
});
|
|
53
|
+
const jobId = answer.jobId;
|
|
54
|
+
if (jobId === undefined)
|
|
55
|
+
console.error("Job ID is undefined", { answer, txType, symbol });
|
|
56
|
+
return jobId;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// Warning: this function will block the thread until the job is done and will print logs to the console
|
|
60
|
+
// Do not use it in "use server" functions, use getResults instead
|
|
61
|
+
async waitForJobResults(params: {
|
|
62
|
+
jobId: string;
|
|
63
|
+
maxAttempts?: number;
|
|
64
|
+
interval?: number;
|
|
65
|
+
maxErrors?: number;
|
|
66
|
+
printLogs?: boolean;
|
|
67
|
+
}): Promise<(string | undefined)[]> {
|
|
68
|
+
const deployResult = await this.client.waitForJobResult(params);
|
|
69
|
+
console.log(
|
|
70
|
+
"waitForJobResult result:",
|
|
71
|
+
deployResult?.result?.result?.slice(0, 50)
|
|
72
|
+
);
|
|
73
|
+
return deployResult?.result?.result ?? "error";
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
async getResults(
|
|
77
|
+
jobId: string
|
|
78
|
+
): Promise<
|
|
79
|
+
| { success: true; results?: JobResult[]; jobStatus?: JobStatus }
|
|
80
|
+
| { success: false; error?: string; jobStatus?: JobStatus }
|
|
81
|
+
> {
|
|
82
|
+
try {
|
|
83
|
+
const callResult = await this.client.jobResult({ jobId });
|
|
84
|
+
|
|
85
|
+
// TODO: filter the repo and developer
|
|
86
|
+
const jobStatus: JobStatus | undefined =
|
|
87
|
+
typeof callResult?.result === "string"
|
|
88
|
+
? undefined
|
|
89
|
+
: callResult?.result?.jobStatus;
|
|
90
|
+
if (!callResult.success) {
|
|
91
|
+
return {
|
|
92
|
+
success: false,
|
|
93
|
+
error: callResult?.error,
|
|
94
|
+
jobStatus,
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
const jobResult = callResult.result?.result;
|
|
98
|
+
if (callResult.error)
|
|
99
|
+
return {
|
|
100
|
+
success: false,
|
|
101
|
+
error: callResult.error,
|
|
102
|
+
jobStatus,
|
|
103
|
+
};
|
|
104
|
+
if (!jobResult) return { success: true, jobStatus };
|
|
105
|
+
|
|
106
|
+
if (jobResult.toLowerCase().startsWith("error"))
|
|
107
|
+
return {
|
|
108
|
+
success: false,
|
|
109
|
+
error: jobResult,
|
|
110
|
+
jobStatus,
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
try {
|
|
114
|
+
const { proofs } = JSON.parse(jobResult);
|
|
115
|
+
const results: JobResult[] = [];
|
|
116
|
+
for (const proof of proofs) {
|
|
117
|
+
const { success, tx, hash, error } = JSON.parse(proof);
|
|
118
|
+
results.push({ success, tx, hash, error });
|
|
119
|
+
}
|
|
120
|
+
return { success: true, results, jobStatus };
|
|
121
|
+
} catch (e: any) {
|
|
122
|
+
return {
|
|
123
|
+
success: false,
|
|
124
|
+
error: `Error parsing job result: ${jobResult} ${e?.message ?? ""}`,
|
|
125
|
+
jobStatus,
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
} catch (e: any) {
|
|
129
|
+
return {
|
|
130
|
+
success: false,
|
|
131
|
+
error: `Error getting job result: ${e?.message ?? ""}`,
|
|
132
|
+
jobStatus: undefined,
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { blockchain, Cloud, JobStatus } from "../../cloud/index.js";
|
|
2
2
|
import { zkCloudWorkerClient } from "../api/api.js";
|
|
3
3
|
import { zkCloudWorker } from "../../cloud/worker/index.js";
|
|
4
|
-
import { TokenTransaction, JobResult } from "@
|
|
4
|
+
import { TokenTransaction, JobResult } from "@silvana-one/api";
|
|
5
5
|
|
|
6
6
|
export class TokenAPI {
|
|
7
7
|
readonly client: zkCloudWorkerClient;
|
|
@@ -44,9 +44,11 @@ export class TokenAPI {
|
|
|
44
44
|
transactions,
|
|
45
45
|
task: "prove",
|
|
46
46
|
args: JSON.stringify({ tokenAddress: params[0].request.tokenAddress }),
|
|
47
|
-
metadata: `${
|
|
48
|
-
|
|
49
|
-
}${
|
|
47
|
+
metadata: `${
|
|
48
|
+
params.length > 1 ? "airdrop" : txType.replace(/^token:/, "")
|
|
49
|
+
} token${symbol ? ` ${symbol}` : ""}${
|
|
50
|
+
params.length > 1 ? ` (${params.length} txs)` : ""
|
|
51
|
+
}`,
|
|
50
52
|
});
|
|
51
53
|
const jobId = answer.jobId;
|
|
52
54
|
if (jobId === undefined)
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Field, PublicKey, Transaction, Mina, UInt64 } from "o1js";
|
|
2
|
-
import { TransactionPayloads } from "@
|
|
2
|
+
import { TransactionPayloads } from "@silvana-one/api";
|
|
3
3
|
import { fieldToBase64, fieldFromBase64 } from "../utils/base64.js";
|
|
4
4
|
|
|
5
5
|
export function createTransactionPayloads(
|
package/src/mina/token/index.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from "./api.js";
|