zkcloudworker 0.17.3 → 0.17.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (65) hide show
  1. package/lib/ts/src/mina/index.d.ts +1 -0
  2. package/lib/ts/src/mina/index.js +1 -0
  3. package/lib/ts/src/mina/storage/index.d.ts +3 -0
  4. package/lib/ts/src/mina/storage/index.js +19 -0
  5. package/lib/ts/src/mina/storage/pinata.d.ts +6 -0
  6. package/lib/ts/src/mina/storage/pinata.js +36 -0
  7. package/lib/ts/src/mina/storage/storage.d.ts +75 -0
  8. package/lib/ts/src/mina/storage/storage.js +55 -0
  9. package/lib/ts/src/mina/transactions/account.d.ts +4 -0
  10. package/lib/ts/src/mina/transactions/account.js +48 -0
  11. package/lib/ts/src/mina/transactions/index.d.ts +2 -0
  12. package/lib/ts/src/mina/transactions/index.js +2 -0
  13. package/lib/ts/src/mina/transactions/nonce.d.ts +7 -0
  14. package/lib/ts/src/mina/transactions/nonce.js +33 -0
  15. package/lib/ts/src/mina/transactions/send.d.ts +29 -0
  16. package/lib/ts/src/mina/transactions/send.js +131 -0
  17. package/lib/ts/src/mina/transactions/txstatus.d.ts +1 -1
  18. package/lib/ts/src/mina/transactions/txstatus.js +2 -2
  19. package/lib/ts/src/mina/utils/index.d.ts +0 -1
  20. package/lib/ts/src/mina/utils/index.js +0 -1
  21. package/lib/ts/src/mina/utils/indexed-map.d.ts +9 -0
  22. package/lib/ts/src/mina/utils/indexed-map.js +13 -0
  23. package/lib/ts/tsconfig.tsbuildinfo +1 -1
  24. package/lib/web/src/mina/index.d.ts +1 -0
  25. package/lib/web/src/mina/index.js +1 -0
  26. package/lib/web/src/mina/index.js.map +1 -1
  27. package/lib/web/src/mina/storage/index.d.ts +3 -0
  28. package/lib/web/src/mina/storage/index.js +4 -0
  29. package/lib/web/src/mina/storage/index.js.map +1 -0
  30. package/lib/web/src/mina/storage/ipfs.js.map +1 -0
  31. package/lib/web/src/mina/storage/pinata.d.ts +6 -0
  32. package/lib/web/src/mina/storage/pinata.js +34 -0
  33. package/lib/web/src/mina/storage/pinata.js.map +1 -0
  34. package/lib/web/src/mina/storage/storage.d.ts +75 -0
  35. package/lib/web/src/mina/storage/storage.js +52 -0
  36. package/lib/web/src/mina/storage/storage.js.map +1 -0
  37. package/lib/web/src/mina/token/FungibleTokenAdmin.js.map +1 -1
  38. package/lib/web/src/mina/transactions/account.d.ts +4 -0
  39. package/lib/web/src/mina/transactions/account.js +44 -0
  40. package/lib/web/src/mina/transactions/account.js.map +1 -0
  41. package/lib/web/src/mina/transactions/index.d.ts +2 -0
  42. package/lib/web/src/mina/transactions/index.js +2 -0
  43. package/lib/web/src/mina/transactions/index.js.map +1 -1
  44. package/lib/web/src/mina/transactions/nonce.d.ts +7 -0
  45. package/lib/web/src/mina/transactions/nonce.js +32 -0
  46. package/lib/web/src/mina/transactions/nonce.js.map +1 -1
  47. package/lib/web/src/mina/transactions/send.d.ts +29 -0
  48. package/lib/web/src/mina/transactions/send.js +128 -0
  49. package/lib/web/src/mina/transactions/send.js.map +1 -0
  50. package/lib/web/src/mina/transactions/txstatus.d.ts +1 -1
  51. package/lib/web/src/mina/transactions/txstatus.js +1 -1
  52. package/lib/web/src/mina/transactions/txstatus.js.map +1 -1
  53. package/lib/web/src/mina/utils/index.d.ts +0 -1
  54. package/lib/web/src/mina/utils/index.js +0 -1
  55. package/lib/web/src/mina/utils/index.js.map +1 -1
  56. package/lib/web/src/mina/utils/indexed-map.d.ts +9 -0
  57. package/lib/web/src/mina/utils/indexed-map.js +12 -0
  58. package/lib/web/src/mina/utils/indexed-map.js.map +1 -1
  59. package/lib/web/tsconfig.web.tsbuildinfo +1 -1
  60. package/package.json +1 -1
  61. package/lib/web/src/mina/utils/ipfs.js.map +0 -1
  62. /package/lib/ts/src/mina/{utils → storage}/ipfs.d.ts +0 -0
  63. /package/lib/ts/src/mina/{utils → storage}/ipfs.js +0 -0
  64. /package/lib/web/src/mina/{utils → storage}/ipfs.d.ts +0 -0
  65. /package/lib/web/src/mina/{utils → storage}/ipfs.js +0 -0
@@ -4,3 +4,4 @@ export * from "./local/local";
4
4
  export * from "./verification";
5
5
  export * from "./token";
6
6
  export * from "./transactions";
7
+ export * from "./storage";
@@ -21,3 +21,4 @@ __exportStar(require("./local/local"), exports);
21
21
  __exportStar(require("./verification"), exports);
22
22
  __exportStar(require("./token"), exports);
23
23
  __exportStar(require("./transactions"), exports);
24
+ __exportStar(require("./storage"), exports);
@@ -0,0 +1,3 @@
1
+ export * from "./ipfs";
2
+ export * from "./pinata";
3
+ export * from "./storage";
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./ipfs"), exports);
18
+ __exportStar(require("./pinata"), exports);
19
+ __exportStar(require("./storage"), exports);
@@ -0,0 +1,6 @@
1
+ export declare function pinJSON(params: {
2
+ data: string | object;
3
+ name: string;
4
+ keyvalues?: object;
5
+ auth: string;
6
+ }): Promise<string | undefined>;
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.pinJSON = pinJSON;
4
+ async function pinJSON(params) {
5
+ const { data, name, keyvalues, auth } = params;
6
+ try {
7
+ const pinataData = {
8
+ pinataOptions: {
9
+ cidVersion: 1,
10
+ },
11
+ pinataMetadata: {
12
+ name,
13
+ keyvalues,
14
+ },
15
+ pinataContent: data,
16
+ };
17
+ const res = await fetch("https://api.pinata.cloud/pinning/pinJSONToIPFS", {
18
+ method: "POST",
19
+ headers: {
20
+ "Content-Type": "application/json",
21
+ Authorization: "Bearer " + auth,
22
+ },
23
+ body: JSON.stringify(pinataData),
24
+ });
25
+ if (!res.ok) {
26
+ throw new Error(`Pinata error: status: ${res.status} ${res.statusText}`);
27
+ }
28
+ const responseData = await res.json();
29
+ console.log("saveToIPFS result:", responseData);
30
+ return responseData?.IpfsHash;
31
+ }
32
+ catch (error) {
33
+ console.error("saveToIPFS error:", error?.message);
34
+ return undefined;
35
+ }
36
+ }
@@ -0,0 +1,75 @@
1
+ import { Field, Bool } from "o1js";
2
+ declare const Storage_base: (new (value: {
3
+ url: import("o1js/dist/node/lib/provable/field").Field[];
4
+ }) => {
5
+ url: import("o1js/dist/node/lib/provable/field").Field[];
6
+ }) & {
7
+ _isStruct: true;
8
+ } & Omit<import("o1js/dist/node/lib/provable/types/provable-intf").Provable<{
9
+ url: import("o1js/dist/node/lib/provable/field").Field[];
10
+ }, {
11
+ url: bigint[];
12
+ }>, "fromFields"> & {
13
+ fromFields: (fields: import("o1js/dist/node/lib/provable/field").Field[]) => {
14
+ url: import("o1js/dist/node/lib/provable/field").Field[];
15
+ };
16
+ } & {
17
+ fromValue: (value: {
18
+ url: import("o1js/dist/node/lib/provable/field").Field[] | bigint[];
19
+ }) => {
20
+ url: import("o1js/dist/node/lib/provable/field").Field[];
21
+ };
22
+ toInput: (x: {
23
+ url: import("o1js/dist/node/lib/provable/field").Field[];
24
+ }) => {
25
+ fields?: Field[] | undefined;
26
+ packed?: [Field, number][] | undefined;
27
+ };
28
+ toJSON: (x: {
29
+ url: import("o1js/dist/node/lib/provable/field").Field[];
30
+ }) => {
31
+ url: string[];
32
+ };
33
+ fromJSON: (x: {
34
+ url: string[];
35
+ }) => {
36
+ url: import("o1js/dist/node/lib/provable/field").Field[];
37
+ };
38
+ empty: () => {
39
+ url: import("o1js/dist/node/lib/provable/field").Field[];
40
+ };
41
+ };
42
+ /**
43
+ * Represents the off-chain storage information,
44
+ * such as an IPFS hash.
45
+ */
46
+ export declare class Storage extends Storage_base {
47
+ constructor(value: {
48
+ url: [Field, Field];
49
+ });
50
+ /**
51
+ * Asserts that two Storage instances are equal.
52
+ * @param a The first Storage instance.
53
+ * @param b The second Storage instance.
54
+ */
55
+ static assertEquals(a: Storage, b: Storage): void;
56
+ /**
57
+ * Checks if two Storage instances are equal.
58
+ * @param a The first Storage instance.
59
+ * @param b The second Storage instance.
60
+ * @returns A Bool indicating whether the two instances are equal.
61
+ */
62
+ static equals(a: Storage, b: Storage): Bool;
63
+ /**
64
+ * Creates a Storage instance from a string.
65
+ * @param url The string representing the storage URL.
66
+ * @returns A new Storage instance.
67
+ */
68
+ static fromString(url: string): Storage;
69
+ /**
70
+ * Converts the Storage instance to a string.
71
+ * @returns The string representation of the storage URL.
72
+ */
73
+ toString(): string;
74
+ }
75
+ export {};
@@ -0,0 +1,55 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Storage = void 0;
4
+ const o1js_1 = require("o1js");
5
+ /**
6
+ * Represents the off-chain storage information,
7
+ * such as an IPFS hash.
8
+ */
9
+ class Storage extends (0, o1js_1.Struct)({
10
+ url: o1js_1.Provable.Array(o1js_1.Field, 2),
11
+ }) {
12
+ constructor(value) {
13
+ super(value);
14
+ }
15
+ /**
16
+ * Asserts that two Storage instances are equal.
17
+ * @param a The first Storage instance.
18
+ * @param b The second Storage instance.
19
+ */
20
+ static assertEquals(a, b) {
21
+ a.url[0].assertEquals(b.url[0]);
22
+ a.url[1].assertEquals(b.url[1]);
23
+ }
24
+ /**
25
+ * Checks if two Storage instances are equal.
26
+ * @param a The first Storage instance.
27
+ * @param b The second Storage instance.
28
+ * @returns A Bool indicating whether the two instances are equal.
29
+ */
30
+ static equals(a, b) {
31
+ return a.url[0].equals(b.url[0]).and(a.url[1].equals(b.url[1]));
32
+ }
33
+ /**
34
+ * Creates a Storage instance from a string.
35
+ * @param url The string representing the storage URL.
36
+ * @returns A new Storage instance.
37
+ */
38
+ static fromString(url) {
39
+ const fields = o1js_1.Encoding.stringToFields(url);
40
+ if (fields.length !== 2)
41
+ throw new Error("Invalid string length");
42
+ return new Storage({ url: [fields[0], fields[1]] });
43
+ }
44
+ /**
45
+ * Converts the Storage instance to a string.
46
+ * @returns The string representation of the storage URL.
47
+ */
48
+ toString() {
49
+ if (this.url[0].toBigInt() === 0n && this.url[1].toBigInt() === 0n) {
50
+ throw new Error("Invalid string");
51
+ }
52
+ return o1js_1.Encoding.stringFromFields([this.url[0], this.url[1]]);
53
+ }
54
+ }
55
+ exports.Storage = Storage;
@@ -0,0 +1,4 @@
1
+ import { PublicKey, Field } from "o1js";
2
+ export declare function accountExists(address: string | PublicKey, tokenId?: Field): Promise<boolean>;
3
+ export declare function tokenBalance(address: string | PublicKey, tokenId?: Field): Promise<number | undefined>;
4
+ export declare function checkAddress(address: string | undefined): Promise<boolean>;
@@ -0,0 +1,48 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.accountExists = accountExists;
4
+ exports.tokenBalance = tokenBalance;
5
+ exports.checkAddress = checkAddress;
6
+ const __1 = require("..");
7
+ const o1js_1 = require("o1js");
8
+ async function accountExists(address, tokenId) {
9
+ try {
10
+ const publicKey = typeof address === "string" ? o1js_1.PublicKey.fromBase58(address) : address;
11
+ await (0, __1.fetchMinaAccount)({ publicKey, tokenId, force: false });
12
+ return o1js_1.Mina.hasAccount(publicKey, tokenId);
13
+ }
14
+ catch (error) {
15
+ return false;
16
+ }
17
+ }
18
+ async function tokenBalance(address, tokenId) {
19
+ try {
20
+ const publicKey = typeof address === "string" ? o1js_1.PublicKey.fromBase58(address) : address;
21
+ await (0, __1.fetchMinaAccount)({ publicKey, tokenId, force: false });
22
+ return o1js_1.Mina.hasAccount(publicKey, tokenId)
23
+ ? Number(o1js_1.Mina.getAccount(publicKey, tokenId).balance.toBigInt())
24
+ : undefined;
25
+ }
26
+ catch (error) {
27
+ console.error("Cannot fetch account balance", error);
28
+ return undefined;
29
+ }
30
+ }
31
+ async function checkAddress(address) {
32
+ if (!address || typeof address !== "string") {
33
+ console.error("checkAddress params are invalid:", address);
34
+ return false;
35
+ }
36
+ try {
37
+ const publicKey = o1js_1.PublicKey.fromBase58(address);
38
+ if (address !== publicKey.toBase58()) {
39
+ console.log("checkAddress: address is not valid", address, publicKey.toBase58());
40
+ return false;
41
+ }
42
+ return true;
43
+ }
44
+ catch (error) {
45
+ console.error("checkAddress catch", { address, error });
46
+ return false;
47
+ }
48
+ }
@@ -4,3 +4,5 @@ export * from "./txstatus";
4
4
  export * from "./chain";
5
5
  export * from "./blockberry";
6
6
  export * from "./tiny-contract";
7
+ export * from "./send";
8
+ export * from "./account";
@@ -20,3 +20,5 @@ __exportStar(require("./txstatus"), exports);
20
20
  __exportStar(require("./chain"), exports);
21
21
  __exportStar(require("./blockberry"), exports);
22
22
  __exportStar(require("./tiny-contract"), exports);
23
+ __exportStar(require("./send"), exports);
24
+ __exportStar(require("./account"), exports);
@@ -1,4 +1,5 @@
1
1
  import { BlockBerryChain } from "./chain";
2
+ import { blockchain } from "../../cloud";
2
3
  export declare function getNonce(params: {
3
4
  account: string;
4
5
  chain: BlockBerryChain;
@@ -8,3 +9,9 @@ export declare function getNonce(params: {
8
9
  nonce: number;
9
10
  message?: string;
10
11
  }>;
12
+ export declare function getAccountNonce(params: {
13
+ account: string;
14
+ chain?: blockchain;
15
+ blockBerryApiKey?: string;
16
+ verbose?: boolean;
17
+ }): Promise<number>;
@@ -1,7 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getNonce = getNonce;
4
+ exports.getAccountNonce = getAccountNonce;
4
5
  const blockberry_1 = require("./blockberry");
6
+ const __1 = require("..");
7
+ const o1js_1 = require("o1js");
5
8
  async function getNonce(params) {
6
9
  const { account, chain, blockBerryApiKey } = params;
7
10
  try {
@@ -58,3 +61,33 @@ async function getNonce(params) {
58
61
  };
59
62
  }
60
63
  }
64
+ async function getAccountNonce(params) {
65
+ const { account, chain = (0, __1.getCurrentNetwork)().network.chainId, blockBerryApiKey, verbose = true, } = params;
66
+ const canUseBlockBerry = blockBerryApiKey !== undefined &&
67
+ (chain === "devnet" || chain === "mainnet");
68
+ if (chain === "zeko") {
69
+ const publicKey = o1js_1.PublicKey.fromBase58(account);
70
+ await (0, __1.fetchMinaAccount)({ publicKey });
71
+ const nonce = Number(o1js_1.Mina.getAccount(publicKey).nonce.toBigint());
72
+ return nonce;
73
+ }
74
+ else {
75
+ const blockberryNoncePromise = canUseBlockBerry
76
+ ? getNonce({
77
+ account,
78
+ blockBerryApiKey,
79
+ chain,
80
+ })
81
+ : undefined;
82
+ const publicKey = o1js_1.PublicKey.fromBase58(account);
83
+ await (0, __1.fetchMinaAccount)({ publicKey });
84
+ const senderNonce = Number(o1js_1.Mina.getAccount(publicKey).nonce.toBigint());
85
+ const blockberryNonce = blockberryNoncePromise
86
+ ? (await blockberryNoncePromise).nonce ?? -1
87
+ : -1;
88
+ const nonce = Math.max(senderNonce, blockberryNonce + 1);
89
+ if (verbose && nonce > senderNonce)
90
+ console.log(`Nonce changed from ${senderNonce} to ${nonce} for ${account}`);
91
+ return nonce;
92
+ }
93
+ }
@@ -0,0 +1,29 @@
1
+ import { Mina } from "o1js";
2
+ import { blockchain } from "../../cloud";
3
+ /**
4
+ * The function `sendTx` sends a transaction, checks account updates, and waits for
5
+ * confirmation on the blockchain.
6
+ * @param params The parameters object
7
+ * @param params.tx The transaction to send
8
+ * @param params.description A description of the transaction
9
+ * @param params.verbose Whether to log verbose information
10
+ * @param params.wait Whether to wait for the transaction to be included in a block
11
+ * @param params.chain The blockchain to send the transaction on
12
+ * @returns The `sendTx` function returns a `Mina.IncludedTransaction`, `Mina.PendingTransaction`,
13
+ * `Mina.RejectedTransaction`, or `undefined` if there was an error during the process.
14
+ */
15
+ export declare function sendTx(params: {
16
+ tx: Mina.Transaction<false, true> | Mina.Transaction<true, true>;
17
+ description?: string;
18
+ verbose?: boolean;
19
+ wait?: boolean;
20
+ chain?: blockchain;
21
+ }): Promise<Mina.IncludedTransaction | Mina.PendingTransaction | Mina.RejectedTransaction | undefined>;
22
+ export declare function getTxStatusFast(params: {
23
+ hash: string;
24
+ chain?: blockchain;
25
+ }): Promise<{
26
+ success: boolean;
27
+ result?: boolean;
28
+ error?: string;
29
+ }>;
@@ -0,0 +1,131 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.sendTx = sendTx;
4
+ exports.getTxStatusFast = getTxStatusFast;
5
+ const o1js_1 = require("o1js");
6
+ const cloud_1 = require("../../cloud");
7
+ const __1 = require("..");
8
+ /**
9
+ * The function `sendTx` sends a transaction, checks account updates, and waits for
10
+ * confirmation on the blockchain.
11
+ * @param params The parameters object
12
+ * @param params.tx The transaction to send
13
+ * @param params.description A description of the transaction
14
+ * @param params.verbose Whether to log verbose information
15
+ * @param params.wait Whether to wait for the transaction to be included in a block
16
+ * @param params.chain The blockchain to send the transaction on
17
+ * @returns The `sendTx` function returns a `Mina.IncludedTransaction`, `Mina.PendingTransaction`,
18
+ * `Mina.RejectedTransaction`, or `undefined` if there was an error during the process.
19
+ */
20
+ async function sendTx(params) {
21
+ const { tx, description = "", verbose = true, wait = true, chain = (0, __1.getCurrentNetwork)().network.chainId, } = params;
22
+ // flatten accountUpdates
23
+ const accountUpdates = JSON.parse(tx.toJSON()).accountUpdates;
24
+ const auCount = [];
25
+ let proofAuthorizationCount = 0;
26
+ // Calculate the number of account updates for each { publicKey, tokenId }
27
+ for (const au of accountUpdates) {
28
+ const { publicKey, tokenId, authorizationKind } = au.body;
29
+ if (au.authorization.proof) {
30
+ proofAuthorizationCount++;
31
+ if (authorizationKind.isProved === false)
32
+ console.error("Proof authorization exists but isProved is false");
33
+ }
34
+ else if (authorizationKind.isProved === true)
35
+ console.error("isProved is true but no proof authorization");
36
+ const index = auCount.findIndex((item) => item.publicKey === publicKey && item.tokenId === tokenId);
37
+ if (index === -1)
38
+ auCount.push({ publicKey, tokenId, count: 1 });
39
+ else
40
+ auCount[index].count++;
41
+ }
42
+ if (verbose)
43
+ console.log(`Account updates for ${description ?? "tx"}: ${auCount.length}, proof authorizations: ${proofAuthorizationCount}`);
44
+ for (const au of auCount) {
45
+ if (au.count > 1)
46
+ if (verbose)
47
+ console.log(`DUPLICATE AU ${description ?? ""}: ${au.publicKey} ${au.tokenId !== "wSHV2S4qX9jFsLjQo8r1BsMLH2ZRKsZx6EJd1sbozGPieEC4Jf"
48
+ ? "tokenId: " + au.tokenId
49
+ : ""} count: ${au.count}`);
50
+ }
51
+ try {
52
+ let txSent;
53
+ let sent = false;
54
+ while (!sent) {
55
+ txSent = await tx.safeSend();
56
+ if (txSent.status == "pending") {
57
+ sent = true;
58
+ if (verbose)
59
+ console.log(`${description ?? ""} tx sent: hash: ${txSent.hash} status: ${txSent.status}`);
60
+ }
61
+ else if (chain === "zeko") {
62
+ if (verbose)
63
+ console.log("Retrying Zeko tx");
64
+ await (0, cloud_1.sleep)(10000);
65
+ }
66
+ else {
67
+ console.error(`${description} tx NOT sent: hash: ${txSent?.hash} status: ${txSent?.status}`, txSent.errors);
68
+ return txSent;
69
+ }
70
+ }
71
+ if (txSent === undefined)
72
+ throw new Error("txSent is undefined");
73
+ if (txSent.errors.length > 0) {
74
+ console.error(`${description ?? ""} tx error: hash: ${txSent.hash} status: ${txSent.status} errors: ${txSent.errors}`);
75
+ }
76
+ if (txSent.status === "pending" && wait !== false && chain !== "zeko") {
77
+ if (verbose)
78
+ console.log(`Waiting for tx inclusion...`);
79
+ const txIncluded = await txSent.safeWait();
80
+ if (txIncluded.status === "included")
81
+ if (verbose)
82
+ console.log(`${description ?? ""} tx included into block: hash: ${txIncluded.hash} status: ${txIncluded.status}`);
83
+ else
84
+ console.error(`${description ?? ""} tx NOT included into block: hash: ${txIncluded.hash} status: ${txIncluded.status}`);
85
+ if (chain !== "local") {
86
+ // we still wait for the tx to be included in the block by checking the nonce
87
+ // even in the case of tx NOT included
88
+ // because the tx might still be included in the block in the case of devnet instability
89
+ const { publicKey, nonce } = tx.transaction.feePayer.body;
90
+ const started = Date.now();
91
+ while (Date.now() - started < 1000 * 60 * 10) {
92
+ const newNonce = (await (0, __1.fetchMinaAccount)({
93
+ publicKey,
94
+ force: true,
95
+ })).account?.nonce;
96
+ if (newNonce &&
97
+ Number(newNonce.toBigint()) > Number(nonce.toBigint()))
98
+ return txIncluded;
99
+ if (verbose)
100
+ console.log(`Waiting for ${chain} to update state for ${Math.floor((Date.now() - started) / 1000)} sec...`);
101
+ await (0, cloud_1.sleep)(10000);
102
+ }
103
+ // finally, if the tx is still not included, show an error
104
+ console.error(`${chain} do not reflect nonce update for tx ${txIncluded.hash} with status ${txIncluded.status}`);
105
+ }
106
+ return txIncluded;
107
+ }
108
+ else
109
+ return txSent;
110
+ }
111
+ catch (error) {
112
+ if (chain !== "zeko")
113
+ console.error("Error sending tx", error);
114
+ }
115
+ }
116
+ async function getTxStatusFast(params) {
117
+ const { hash, chain = (0, __1.getCurrentNetwork)().network.chainId } = params;
118
+ if (chain === "local" || chain === "zeko")
119
+ return { success: true, result: true };
120
+ try {
121
+ const txStatus = await (0, o1js_1.checkZkappTransaction)(hash);
122
+ return {
123
+ success: true,
124
+ result: txStatus?.success ?? false,
125
+ };
126
+ }
127
+ catch (error) {
128
+ console.error("getTxStatusFast error while getting tx status - catch", hash, error);
129
+ return { success: false, error: error?.message ?? "Cannot get tx status" };
130
+ }
131
+ }
@@ -1,5 +1,5 @@
1
1
  import { BlockBerryChain } from "./chain";
2
- export declare function txStatus(params: {
2
+ export declare function txStatusBlockberry(params: {
3
3
  hash: string;
4
4
  time: number;
5
5
  chain: BlockBerryChain;
@@ -1,9 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.txStatus = txStatus;
3
+ exports.txStatusBlockberry = txStatusBlockberry;
4
4
  const blockberry_1 = require("./blockberry");
5
5
  const TIMEOUT = 1000 * 60 * 21;
6
- async function txStatus(params) {
6
+ async function txStatusBlockberry(params) {
7
7
  const { hash, chain, time, blockBerryApiKey } = params;
8
8
  const tx = await (0, blockberry_1.getZkAppTxFromBlockBerry)({ hash, chain, blockBerryApiKey });
9
9
  if (tx?.txStatus)
@@ -3,5 +3,4 @@ export * from "./fetch";
3
3
  export * from "./fields";
4
4
  export * from "./fee";
5
5
  export * from "./mina";
6
- export * from "./ipfs";
7
6
  export * from "./indexed-map";
@@ -19,5 +19,4 @@ __exportStar(require("./fetch"), exports);
19
19
  __exportStar(require("./fields"), exports);
20
20
  __exportStar(require("./fee"), exports);
21
21
  __exportStar(require("./mina"), exports);
22
- __exportStar(require("./ipfs"), exports);
23
22
  __exportStar(require("./indexed-map"), exports);
@@ -12,6 +12,15 @@ export declare function loadIndexedMerkleMap(params: {
12
12
  url: string;
13
13
  type: ReturnType<typeof IndexedMerkleMap>;
14
14
  }): Promise<import("o1js/dist/node/lib/provable/merkle-tree-indexed").IndexedMerkleMapBase>;
15
+ export declare function saveIndexedMerkleMap(params: {
16
+ map: IndexedMerkleMap;
17
+ name?: string;
18
+ keyvalues?: {
19
+ key: string;
20
+ value: string;
21
+ }[];
22
+ auth: string;
23
+ }): Promise<string | undefined>;
15
24
  export declare function serializeIndexedMap(map: IndexedMerkleMap): IndexedMapSerialized;
16
25
  export declare function deserializeIndexedMerkleMap(params: {
17
26
  serializedIndexedMap: IndexedMapSerialized;
@@ -1,11 +1,13 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.loadIndexedMerkleMap = loadIndexedMerkleMap;
4
+ exports.saveIndexedMerkleMap = saveIndexedMerkleMap;
4
5
  exports.serializeIndexedMap = serializeIndexedMap;
5
6
  exports.deserializeIndexedMerkleMap = deserializeIndexedMerkleMap;
6
7
  exports.parseIndexedMapSerialized = parseIndexedMapSerialized;
7
8
  const o1js_1 = require("o1js");
8
9
  const cloud_1 = require("../../cloud");
10
+ const pinata_1 = require("../storage/pinata");
9
11
  const { IndexedMerkleMap } = o1js_1.Experimental;
10
12
  async function loadIndexedMerkleMap(params) {
11
13
  const { url, type } = params;
@@ -23,6 +25,17 @@ async function loadIndexedMerkleMap(params) {
23
25
  }
24
26
  return map;
25
27
  }
28
+ async function saveIndexedMerkleMap(params) {
29
+ const { map, name = "indexed-map", keyvalues, auth } = params;
30
+ const serialized = serializeIndexedMap(map);
31
+ const ipfsHash = await (0, pinata_1.pinJSON)({
32
+ data: serialized,
33
+ name,
34
+ keyvalues,
35
+ auth,
36
+ });
37
+ return ipfsHash;
38
+ }
26
39
  function serializeIndexedMap(map) {
27
40
  return {
28
41
  height: map.height,