zkcloudworker 0.19.0 → 0.20.2

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.
@@ -1,6 +1,50 @@
1
1
  import { Field, PublicKey, Transaction, Mina, UInt64 } from "o1js";
2
+ import { TransactionPayloads } from "@minatokens/api";
2
3
  import { fieldToBase64, fieldFromBase64 } from "../utils/base64.js";
3
4
 
5
+ export function createTransactionPayloads(
6
+ tx: Mina.Transaction<false, false> | Mina.Transaction<false, true>
7
+ ): TransactionPayloads {
8
+ const transaction = tx.toJSON();
9
+ const txJSON = JSON.parse(transaction);
10
+ const signedData = JSON.stringify({ zkappCommand: txJSON });
11
+ const proverPayload = serializeTransaction(tx);
12
+ const fee = tx.transaction.feePayer.body.fee.toJSON();
13
+ const sender = tx.transaction.feePayer.body.publicKey.toBase58();
14
+ const nonce = Number(tx.transaction.feePayer.body.nonce.toBigint());
15
+ const memo = tx.transaction.memo;
16
+ const minaSignerPayload = {
17
+ zkappCommand: txJSON,
18
+ feePayer: {
19
+ feePayer: sender,
20
+ fee,
21
+ nonce,
22
+ memo,
23
+ },
24
+ };
25
+ const walletPayload = {
26
+ transaction,
27
+ nonce,
28
+ onlySign: true,
29
+ feePayer: {
30
+ fee,
31
+ memo,
32
+ },
33
+ };
34
+
35
+ return {
36
+ sender,
37
+ nonce,
38
+ memo,
39
+ fee,
40
+ walletPayload,
41
+ minaSignerPayload,
42
+ proverPayload,
43
+ signedData,
44
+ transaction,
45
+ };
46
+ }
47
+
4
48
  interface ForestSerialized {
5
49
  length: number;
6
50
  restoredItems?: number;
@@ -13,15 +57,21 @@ interface ForestSerialized {
13
57
  }
14
58
 
15
59
  export function transactionParams(
16
- serializedTransaction: string,
17
- signedJson: any
60
+ params:
61
+ | {
62
+ proverPayload: string;
63
+ signedData: string;
64
+ }
65
+ | TransactionPayloads
18
66
  ): {
19
67
  fee: UInt64;
20
68
  sender: PublicKey;
21
69
  nonce: number;
22
70
  memo: string;
23
71
  } {
24
- const { sender, nonce, tx } = JSON.parse(serializedTransaction);
72
+ const { proverPayload, signedData } = params;
73
+ const signedJson = JSON.parse(signedData);
74
+ const { sender, tx } = JSON.parse(proverPayload);
25
75
  const transaction = Mina.Transaction.fromJSON(JSON.parse(tx));
26
76
  const memo = transaction.transaction.memo;
27
77
  return {
@@ -32,20 +82,30 @@ export function transactionParams(
32
82
  };
33
83
  }
34
84
 
35
- export function deserializeTransaction(
36
- serializedTransaction: string,
37
- txNew: Mina.Transaction<false, false>,
38
- signedJson: any
85
+ export function parseTransactionPayloads(
86
+ params:
87
+ | {
88
+ proverPayload: string;
89
+ signedData: string;
90
+ txNew: Mina.Transaction<false, false> | Mina.Transaction<false, true>;
91
+ }
92
+ | {
93
+ payloads: TransactionPayloads;
94
+ txNew: Mina.Transaction<false, false> | Mina.Transaction<false, true>;
95
+ }
39
96
  ): Transaction<false, true> {
40
- //console.log("new transaction", txNew);
41
- const { tx, blindingValues, length, forestJSONs } = JSON.parse(
42
- serializedTransaction
43
- );
97
+ const { txNew } = params;
98
+ const proverPayload =
99
+ "payloads" in params ? params.payloads.proverPayload : params.proverPayload;
100
+ const signedData =
101
+ "payloads" in params ? params.payloads.signedData : params.signedData;
102
+ const signedJson = JSON.parse(signedData);
103
+ const { tx, blindingValues, length, forestJSONs } = JSON.parse(proverPayload);
44
104
  const transaction = Mina.Transaction.fromJSON(JSON.parse(tx));
45
105
  const forests: ForestSerialized[] = forestJSONs.map(
46
106
  (f: string) => JSON.parse(f) as ForestSerialized
47
107
  );
48
- //console.log("transaction", transaction);
108
+
49
109
  if (length !== txNew.transaction.accountUpdates.length) {
50
110
  throw new Error("New Transaction length mismatch");
51
111
  }
@@ -106,7 +166,7 @@ export function deserializeTransaction(
106
166
  }
107
167
 
108
168
  export function serializeTransaction(
109
- tx: Mina.Transaction<false, false>
169
+ tx: Mina.Transaction<false, false> | Mina.Transaction<false, true>
110
170
  ): string {
111
171
  const length = tx.transaction.accountUpdates.length;
112
172
  let i;