@sig-net/midnight 0.27.0-rc.4 → 0.27.0-rc.6

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.
Files changed (45) hide show
  1. package/dist/abi-serde.d.ts +18 -0
  2. package/dist/abi-serde.d.ts.map +1 -1
  3. package/dist/abi-serde.js +28 -0
  4. package/dist/abi-serde.js.map +1 -1
  5. package/dist/index.d.ts +3 -2
  6. package/dist/index.d.ts.map +1 -1
  7. package/dist/index.js +3 -2
  8. package/dist/index.js.map +1 -1
  9. package/dist/managed/compiler/contract-info.json +202 -21
  10. package/dist/managed/compiler/contract-manifest.json +16 -8
  11. package/dist/managed/contract/index.d.ts +320 -264
  12. package/dist/managed/contract/index.js +596 -392
  13. package/dist/managed/contract/index.js.map +2 -2
  14. package/dist/managed/zkir/assertTronExpirationWindowV1.zkir +63 -0
  15. package/dist/signature-requests-state-reader.js +3 -3
  16. package/dist/signature-requests-state-reader.js.map +1 -1
  17. package/dist/signet-request-id.js +5 -5
  18. package/dist/signet-request-id.js.map +1 -1
  19. package/dist/signet-request-response-reader.d.ts +2 -2
  20. package/dist/signet-request-response-reader.d.ts.map +1 -1
  21. package/dist/signet-request-response-reader.js +4 -4
  22. package/dist/signet-request-response-reader.js.map +1 -1
  23. package/dist/signet-requests.d.ts +5 -5
  24. package/dist/signet-requests.d.ts.map +1 -1
  25. package/dist/signet-requests.js +3 -3
  26. package/dist/signet-requests.js.map +1 -1
  27. package/dist/signet-tron-record-decoding.d.ts +2 -2
  28. package/dist/signet-tron-record-decoding.d.ts.map +1 -1
  29. package/dist/signet-tron-record-decoding.js +2 -2
  30. package/dist/signet-tron-record-decoding.js.map +1 -1
  31. package/dist/signet-tron-requests.d.ts +7 -7
  32. package/dist/signet-tron-requests.d.ts.map +1 -1
  33. package/dist/signet-tron-requests.js +11 -7
  34. package/dist/signet-tron-requests.js.map +1 -1
  35. package/dist/tron-node-api.d.ts +83 -0
  36. package/dist/tron-node-api.d.ts.map +1 -0
  37. package/dist/tron-node-api.js +134 -0
  38. package/dist/tron-node-api.js.map +1 -0
  39. package/dist/tron-transactions.d.ts +23 -2
  40. package/dist/tron-transactions.d.ts.map +1 -1
  41. package/dist/tron-transactions.js +19 -0
  42. package/dist/tron-transactions.js.map +1 -1
  43. package/package.json +2 -2
  44. package/src/Signet.compact +79 -12
  45. package/src/circuits.compact +29 -18
@@ -4,12 +4,12 @@ import { HashDomain } from "./managed/contract/index.js";
4
4
  import { evmCalldataDescriptor } from "./signet-evtype2tx-requests.js";
5
5
  import { signBidirectionalEventDescriptorWith, } from "./signet-requests.js";
6
6
  /**
7
- * Runtime descriptor of {@link TronTxParams} at a calldata word capacity.
7
+ * Runtime descriptor of {@link TronTriggerSmartContractTxParams} at a calldata word capacity.
8
8
  *
9
9
  * @param maxCalldataWords - Calldata word capacity
10
10
  * @returns The tx-params descriptor
11
11
  */
12
- export function tronTxParamsDescriptor(maxCalldataWords) {
12
+ export function tronTriggerSmartContractTxParamsDescriptor(maxCalldataWords) {
13
13
  return compactStructDescriptor({
14
14
  refBlockBytes: BYTES_2,
15
15
  refBlockHash: BYTES_8,
@@ -30,7 +30,7 @@ export function tronTxParamsDescriptor(maxCalldataWords) {
30
30
  * @returns The event record descriptor
31
31
  */
32
32
  export function tronSignBidirectionalEventDescriptor(maxCalldataWords, lenOutputDeserialization, lenRespondSerialization) {
33
- return signBidirectionalEventDescriptorWith(tronTxParamsDescriptor(maxCalldataWords), lenOutputDeserialization, lenRespondSerialization);
33
+ return signBidirectionalEventDescriptorWith(tronTriggerSmartContractTxParamsDescriptor(maxCalldataWords), lenOutputDeserialization, lenRespondSerialization);
34
34
  }
35
35
  const TRON_DIGEST_HEAD = compactTupleDescriptor([
36
36
  HASH_DOMAIN,
@@ -46,13 +46,13 @@ const TRON_DIGEST_HEAD = compactTupleDescriptor([
46
46
  UINT_16,
47
47
  ]);
48
48
  /**
49
- * Digest a Tron decomposition over its used calldata words: the TS twin of the `calculateTronTxParamsDigestV1` circuit.
49
+ * Digest a Tron decomposition over its used calldata words: the TS twin of the `calculateTronTriggerSmartContractTxParamsDigestV1` circuit.
50
50
  *
51
51
  * @param txParams - The transaction decomposition to digest, at any capacity
52
52
  * @returns The 32-byte digest
53
53
  * @throws {Error} When the calldata word count exceeds its capacity
54
54
  */
55
- export function calculateTronTxParamsDigest(txParams) {
55
+ export function calculateTronTriggerSmartContractTxParamsDigest(txParams) {
56
56
  const { calldata } = txParams;
57
57
  const noWords = calldata.is_some ? calldata.value.noWords : 0n;
58
58
  const selector = calldata.is_some ? calldata.value.selector : new Uint8Array(4);
@@ -60,7 +60,7 @@ export function calculateTronTxParamsDigest(txParams) {
60
60
  throw new Error("calldata noWords exceeds capacity");
61
61
  }
62
62
  let acc = transientHash(TRON_DIGEST_HEAD, [
63
- HashDomain.tronTxHeader,
63
+ HashDomain.tronTriggerSmartContractTxHeader,
64
64
  txParams.refBlockBytes,
65
65
  txParams.refBlockHash,
66
66
  txParams.timestamp,
@@ -73,7 +73,11 @@ export function calculateTronTxParamsDigest(txParams) {
73
73
  noWords,
74
74
  ]);
75
75
  for (const word of calldata.value.words.slice(0, Number(noWords))) {
76
- acc = transientHash(DOMAIN_FIELD_BYTES_32, [HashDomain.tronTxWord, acc, word]);
76
+ acc = transientHash(DOMAIN_FIELD_BYTES_32, [
77
+ HashDomain.tronTriggerSmartContractTxWord,
78
+ acc,
79
+ word,
80
+ ]);
77
81
  }
78
82
  return upgradeFromTransient(acc);
79
83
  }
@@ -1 +1 @@
1
- {"version":3,"file":"signet-tron-requests.js","sourceRoot":"","sources":["../src/signet-tron-requests.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,aAAa,EACb,oBAAoB,GACrB,MAAM,iCAAiC,CAAC;AAEzC,OAAO,EACL,OAAO,EACP,OAAO,EACP,OAAO,EACP,OAAO,EACP,QAAQ,EACR,sBAAsB,EACtB,uBAAuB,EACvB,sBAAsB,EACtB,qBAAqB,EACrB,WAAW,EAEX,OAAO,EAC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ChF,IAAI,OAAO,GAAG,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,KAAK,CAAC,MAAM,CAAC,EAAE,CAAC;QAClD,MAAM,IAAI,KAAK,CAAC,mCAAmC,CAAC,CAAC;IACvD,CAAC;IACD,IAAI,GAAG,GAAG,aAAa,CAAC,gBAAgB,EAAE;QACxC,UAAU,CAAC,gCAAgC;QAC3C,QAAQ,CAAC,aAAa;QACtB,QAAQ,CAAC,YAAY;QACrB,QAAQ,CAAC,SAAS;QAClB,QAAQ,CAAC,UAAU;QACnB,QAAQ,CAAC,QAAQ;QACjB,QAAQ,CAAC,eAAe;QACxB,QAAQ,CAAC,SAAS;QAClB,QAAQ,CAAC,OAAO;QAChB,QAAQ;QACR,OAAO;KACR,CAAC,CAAC;IACH,KAAK,MAAM,IAAI,IAAI,QAAQ,CAAC,KAAK,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,EAAE,MAAM,CAAC,OAAO,CAAC,CAAC,EAAE,CAAC;QAClE,GAAG,GAAG,aAAa,CAAC,qBAAqB,EAAE;YACzC,UAAU,CAAC,8BAA8B;YACzC,GAAG;YACH,IAAI;SACL,CAAC,CAAC;IACL,CAAC;IACD,OAAO,oBAAoB,CAAC,GAAG,CAAC,CAAC;AACnC,CAAC"}
@@ -0,0 +1,83 @@
1
+ import type { JsonValue } from "./abi-serde.ts";
2
+ /** The TaPoS reference fields of a Tron transaction, naming the block it is built on. */
3
+ export interface TronTaposReference {
4
+ /** Bytes 6..8 of the block number, big-endian: the number modulo 65536. */
5
+ readonly refBlockBytes: Uint8Array;
6
+ /** Bytes 8..16 of the block id. */
7
+ readonly refBlockHash: Uint8Array;
8
+ }
9
+ /**
10
+ * The TaPoS reference to a block, as java-tron builds it and the MPC resolves it.
11
+ *
12
+ * @param blockNumber - The block's number
13
+ * @param blockId - The block's 32-byte id
14
+ * @returns The reference fields
15
+ * @throws {Error} If the block id is not 32 bytes or the number does not fit 64 bits
16
+ */
17
+ export declare function tronTaposReference(blockNumber: bigint, blockId: Uint8Array): TronTaposReference;
18
+ /** A solidified block a request can reference, with the time its timestamp field should follow. */
19
+ export interface TronReferenceBlock extends TronTaposReference {
20
+ readonly number: bigint;
21
+ readonly blockId: Uint8Array;
22
+ /** The block's timestamp in milliseconds. */
23
+ readonly timestamp: bigint;
24
+ }
25
+ /**
26
+ * The solidified head (`/walletsolidity/getnowblock`) as a reference block. A solidified block
27
+ * cannot be reorganised away, so a transaction referencing it stays includable until it expires;
28
+ * one referencing an unsolidified head can name a block the chain drops, which the MPC signs but
29
+ * never answers.
30
+ *
31
+ * @param rpcUrl - The java-tron HTTP API base URL
32
+ * @returns The solidified head and its TaPoS reference
33
+ * @throws {Error} If the node cannot be reached or answers without a block
34
+ */
35
+ export declare function getSolidifiedTronReferenceBlock(rpcUrl: string): Promise<TronReferenceBlock>;
36
+ /** How the node took a broadcast it did not refuse. */
37
+ export declare enum TronBroadcastOutcome {
38
+ /** The node accepted the transaction now. */
39
+ Accepted = 0,
40
+ /**
41
+ * `DUP_TRANSACTION_ERROR`: the node already holds a transaction with this id, so an earlier
42
+ * broadcast (by anyone: the bytes are the same) reached it.
43
+ */
44
+ AlreadyKnown = 1
45
+ }
46
+ /**
47
+ * Broadcasts a signed transaction (`/wallet/broadcasthex`). A duplicate is not an error: the
48
+ * signed bytes are public once the MPC posts the signature, so another client may have sent them.
49
+ *
50
+ * @param rpcUrl - The java-tron HTTP API base URL
51
+ * @param signedTransaction - The signed `Transaction` protobuf bytes
52
+ * @returns Whether this call submitted it or the node already had it
53
+ * @throws {Error} If the node refuses it (for example `TRANSACTION_EXPIRATION_ERROR` once its
54
+ * expiration has passed, or `SERVER_BUSY`, which a caller may retry with the same bytes)
55
+ */
56
+ export declare function broadcastTronTransaction(rpcUrl: string, signedTransaction: Uint8Array): Promise<TronBroadcastOutcome>;
57
+ /** A final (solidified) `TransactionInfo`, java-tron's transaction receipt: what the MPC attests from. */
58
+ export interface TronTransactionInfo {
59
+ readonly id: Uint8Array;
60
+ readonly blockNumber: bigint;
61
+ /** The block's timestamp in milliseconds. */
62
+ readonly blockTimestamp: bigint;
63
+ /** The total fee in sun. */
64
+ readonly fee: bigint;
65
+ /** `TransactionInfo.code`: java-tron prints it only on failure (`FAILED`). */
66
+ readonly result: string | undefined;
67
+ /** `receipt.result`, the VM's contract result (`SUCCESS`, `REVERT`, `OUT_OF_ENERGY`, ...). */
68
+ readonly receiptResult: string | undefined;
69
+ /** The top call's return data, the output the MPC attests. */
70
+ readonly contractResult: readonly Uint8Array[];
71
+ /** The node's answer as is, for `evmTraceOutputFromTronReceipt`. */
72
+ readonly body: JsonValue;
73
+ }
74
+ /**
75
+ * The final receipt of a transaction (`/walletsolidity/gettransactioninfobyid`).
76
+ *
77
+ * @param rpcUrl - The java-tron HTTP API base URL
78
+ * @param txId - The 32-byte transaction id
79
+ * @returns The receipt, or `undefined` while the transaction is not in a solidified block
80
+ * @throws {Error} If the node cannot be reached or answers a malformed receipt
81
+ */
82
+ export declare function getSolidifiedTronTransactionInfo(rpcUrl: string, txId: Uint8Array): Promise<TronTransactionInfo | undefined>;
83
+ //# sourceMappingURL=tron-node-api.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tron-node-api.d.ts","sourceRoot":"","sources":["../src/tron-node-api.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAoBhD,yFAAyF;AACzF,MAAM,WAAW,kBAAkB;IACjC,2EAA2E;IAC3E,QAAQ,CAAC,aAAa,EAAE,UAAU,CAAC;IACnC,mCAAmC;IACnC,QAAQ,CAAC,YAAY,EAAE,UAAU,CAAC;CACnC;AAED;;;;;;;GAOG;AACH,wBAAgB,kBAAkB,CAAC,WAAW,EAAE,MAAM,EAAE,OAAO,EAAE,UAAU,GAAG,kBAAkB,CAU/F;AAED,mGAAmG;AACnG,MAAM,WAAW,kBAAmB,SAAQ,kBAAkB;IAC5D,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,OAAO,EAAE,UAAU,CAAC;IAC7B,6CAA6C;IAC7C,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;CAC5B;AAOD;;;;;;;;;GASG;AACH,wBAAsB,+BAA+B,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,kBAAkB,CAAC,CAgBjG;AAED,uDAAuD;AACvD,oBAAY,oBAAoB;IAC9B,6CAA6C;IAC7C,QAAQ,IAAA;IACR;;;OAGG;IACH,YAAY,IAAA;CACb;AAiBD;;;;;;;;;GASG;AACH,wBAAsB,wBAAwB,CAC5C,MAAM,EAAE,MAAM,EACd,iBAAiB,EAAE,UAAU,GAC5B,OAAO,CAAC,oBAAoB,CAAC,CAY/B;AAED,0GAA0G;AAC1G,MAAM,WAAW,mBAAmB;IAClC,QAAQ,CAAC,EAAE,EAAE,UAAU,CAAC;IACxB,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,6CAA6C;IAC7C,QAAQ,CAAC,cAAc,EAAE,MAAM,CAAC;IAChC,4BAA4B;IAC5B,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,8EAA8E;IAC9E,QAAQ,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC;IACpC,8FAA8F;IAC9F,QAAQ,CAAC,aAAa,EAAE,MAAM,GAAG,SAAS,CAAC;IAC3C,8DAA8D;IAC9D,QAAQ,CAAC,cAAc,EAAE,SAAS,UAAU,EAAE,CAAC;IAC/C,oEAAoE;IACpE,QAAQ,CAAC,IAAI,EAAE,SAAS,CAAC;CAC1B;AAYD;;;;;;;GAOG;AACH,wBAAsB,gCAAgC,CACpD,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,UAAU,GACf,OAAO,CAAC,mBAAmB,GAAG,SAAS,CAAC,CAqB1C"}
@@ -0,0 +1,134 @@
1
+ // The java-tron HTTP calls a Tron request's client makes around the MPC: the reference block to
2
+ // build a request on, the broadcast of the signed transaction, and the final receipt. Reads go to
3
+ // the solidity router (`/walletsolidity/...`), the finality the MPC itself reads, so the client
4
+ // sees what the MPC will attest.
5
+ import { bytesToHex, hexToBytes } from "./byte-codecs.js";
6
+ import { redactUrlQuery } from "./url-redaction.js";
7
+ async function tronNodePost(rpcUrl, path, body) {
8
+ const url = `${rpcUrl.replace(/\/+$/, "")}${path}`;
9
+ const response = await fetch(url, {
10
+ method: "POST",
11
+ headers: { "content-type": "application/json" },
12
+ body: JSON.stringify(body),
13
+ });
14
+ const text = await response.text();
15
+ if (!response.ok) {
16
+ throw new Error(`Tron node ${redactUrlQuery(url)} answered HTTP ${String(response.status)}: ${text}`);
17
+ }
18
+ return text;
19
+ }
20
+ /**
21
+ * The TaPoS reference to a block, as java-tron builds it and the MPC resolves it.
22
+ *
23
+ * @param blockNumber - The block's number
24
+ * @param blockId - The block's 32-byte id
25
+ * @returns The reference fields
26
+ * @throws {Error} If the block id is not 32 bytes or the number does not fit 64 bits
27
+ */
28
+ export function tronTaposReference(blockNumber, blockId) {
29
+ if (blockId.length !== 32) {
30
+ throw new Error(`a Tron block id is 32 bytes, got ${String(blockId.length)}`);
31
+ }
32
+ if (blockNumber < 0n || blockNumber >= 2n ** 64n) {
33
+ throw new Error(`Tron block number ${String(blockNumber)} does not fit 64 bits`);
34
+ }
35
+ const number = new Uint8Array(8);
36
+ new DataView(number.buffer).setBigUint64(0, blockNumber);
37
+ return { refBlockBytes: number.slice(6, 8), refBlockHash: blockId.slice(8, 16) };
38
+ }
39
+ /**
40
+ * The solidified head (`/walletsolidity/getnowblock`) as a reference block. A solidified block
41
+ * cannot be reorganised away, so a transaction referencing it stays includable until it expires;
42
+ * one referencing an unsolidified head can name a block the chain drops, which the MPC signs but
43
+ * never answers.
44
+ *
45
+ * @param rpcUrl - The java-tron HTTP API base URL
46
+ * @returns The solidified head and its TaPoS reference
47
+ * @throws {Error} If the node cannot be reached or answers without a block
48
+ */
49
+ export async function getSolidifiedTronReferenceBlock(rpcUrl) {
50
+ const answer = JSON.parse(await tronNodePost(rpcUrl, "/walletsolidity/getnowblock", {}));
51
+ const raw = answer.block_header?.raw_data;
52
+ if (answer.blockID === undefined || raw?.number === undefined || raw.timestamp === undefined) {
53
+ throw new Error("Tron /walletsolidity/getnowblock answered no block id, number or timestamp");
54
+ }
55
+ const number = BigInt(raw.number);
56
+ const blockId = hexToBytes(answer.blockID);
57
+ return {
58
+ ...tronTaposReference(number, blockId),
59
+ number,
60
+ blockId,
61
+ timestamp: BigInt(raw.timestamp),
62
+ };
63
+ }
64
+ /** How the node took a broadcast it did not refuse. */
65
+ export var TronBroadcastOutcome;
66
+ (function (TronBroadcastOutcome) {
67
+ /** The node accepted the transaction now. */
68
+ TronBroadcastOutcome[TronBroadcastOutcome["Accepted"] = 0] = "Accepted";
69
+ /**
70
+ * `DUP_TRANSACTION_ERROR`: the node already holds a transaction with this id, so an earlier
71
+ * broadcast (by anyone: the bytes are the same) reached it.
72
+ */
73
+ TronBroadcastOutcome[TronBroadcastOutcome["AlreadyKnown"] = 1] = "AlreadyKnown";
74
+ })(TronBroadcastOutcome || (TronBroadcastOutcome = {}));
75
+ // java-tron hex-encodes the ASCII message of some refusals.
76
+ function decodeTronMessage(message) {
77
+ if (!/^(?:[0-9a-fA-F]{2})+$/.test(message))
78
+ return message;
79
+ const bytes = hexToBytes(message);
80
+ return bytes.every((byte) => byte >= 0x20 && byte < 0x7f)
81
+ ? new TextDecoder().decode(bytes)
82
+ : message;
83
+ }
84
+ /**
85
+ * Broadcasts a signed transaction (`/wallet/broadcasthex`). A duplicate is not an error: the
86
+ * signed bytes are public once the MPC posts the signature, so another client may have sent them.
87
+ *
88
+ * @param rpcUrl - The java-tron HTTP API base URL
89
+ * @param signedTransaction - The signed `Transaction` protobuf bytes
90
+ * @returns Whether this call submitted it or the node already had it
91
+ * @throws {Error} If the node refuses it (for example `TRANSACTION_EXPIRATION_ERROR` once its
92
+ * expiration has passed, or `SERVER_BUSY`, which a caller may retry with the same bytes)
93
+ */
94
+ export async function broadcastTronTransaction(rpcUrl, signedTransaction) {
95
+ const answer = JSON.parse(await tronNodePost(rpcUrl, "/wallet/broadcasthex", {
96
+ transaction: bytesToHex(signedTransaction),
97
+ }));
98
+ if (answer.result === true)
99
+ return TronBroadcastOutcome.Accepted;
100
+ if (answer.code === "DUP_TRANSACTION_ERROR")
101
+ return TronBroadcastOutcome.AlreadyKnown;
102
+ throw new Error(`Tron node refused the transaction: ${answer.code ?? "no code"}: ` +
103
+ decodeTronMessage(answer.message ?? ""));
104
+ }
105
+ /**
106
+ * The final receipt of a transaction (`/walletsolidity/gettransactioninfobyid`).
107
+ *
108
+ * @param rpcUrl - The java-tron HTTP API base URL
109
+ * @param txId - The 32-byte transaction id
110
+ * @returns The receipt, or `undefined` while the transaction is not in a solidified block
111
+ * @throws {Error} If the node cannot be reached or answers a malformed receipt
112
+ */
113
+ export async function getSolidifiedTronTransactionInfo(rpcUrl, txId) {
114
+ const body = JSON.parse(await tronNodePost(rpcUrl, "/walletsolidity/gettransactioninfobyid", {
115
+ value: bytesToHex(txId),
116
+ }));
117
+ const answer = body;
118
+ if (answer.id === undefined)
119
+ return undefined;
120
+ if (answer.blockNumber === undefined || answer.blockTimeStamp === undefined) {
121
+ throw new Error(`Tron receipt ${answer.id} names no block`);
122
+ }
123
+ return {
124
+ id: hexToBytes(answer.id),
125
+ blockNumber: BigInt(answer.blockNumber),
126
+ blockTimestamp: BigInt(answer.blockTimeStamp),
127
+ fee: BigInt(answer.fee ?? 0),
128
+ result: answer.result,
129
+ receiptResult: answer.receipt?.result,
130
+ contractResult: (answer.contractResult ?? []).map((data) => hexToBytes(data)),
131
+ body,
132
+ };
133
+ }
134
+ //# sourceMappingURL=tron-node-api.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tron-node-api.js","sourceRoot":"","sources":["../src/tron-node-api.ts"],"names":[],"mappings":"AAAA,gGAAgG;AAChG,kGAAkG;AAClG,gGAAgG;AAChG,iCAAiC;AAGjC,OAAO,EAAE,UAAU,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S,CAAC;IAC9C,IAAI,MAAM,CAAC,WAAW,KAAK,SAAS,IAAI,MAAM,CAAC,cAAc,KAAK,SAAS,EAAE,CAAC;QAC5E,MAAM,IAAI,KAAK,CAAC,gBAAgB,MAAM,CAAC,EAAE,iBAAiB,CAAC,CAAC;IAC9D,CAAC;IACD,OAAO;QACL,EAAE,EAAE,UAAU,CAAC,MAAM,CAAC,EAAE,CAAC;QACzB,WAAW,EAAE,MAAM,CAAC,MAAM,CAAC,WAAW,CAAC;QACvC,cAAc,EAAE,MAAM,CAAC,MAAM,CAAC,cAAc,CAAC;QAC7C,GAAG,EAAE,MAAM,CAAC,MAAM,CAAC,GAAG,IAAI,CAAC,CAAC;QAC5B,MAAM,EAAE,MAAM,CAAC,MAAM;QACrB,aAAa,EAAE,MAAM,CAAC,OAAO,EAAE,MAAM;QACrC,cAAc,EAAE,CAAC,MAAM,CAAC,cAAc,IAAI,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC;QAC7E,IAAI;KACL,CAAC;AACJ,CAAC"}
@@ -1,6 +1,7 @@
1
1
  import { type SignBidirectionalEventKeySelector } from "./epsilon-derivation.ts";
2
2
  import type { MpcSignature } from "./signet-contract-events.ts";
3
- import type { TronTxParams } from "./signet-tron-requests.ts";
3
+ import { type SignBidirectionalEvent } from "./signet-requests.ts";
4
+ import type { TronTriggerSmartContractTxParams } from "./signet-tron-requests.ts";
4
5
  /**
5
6
  * Turn a 20-byte EVM address into its 21-byte Tron address.
6
7
  *
@@ -55,7 +56,27 @@ export declare function deriveSignBidirectionalEventSignerTronAddress(mpcSecp256
55
56
  * @returns The raw transaction bytes
56
57
  * @throws {Error} If a field cannot be represented
57
58
  */
58
- export declare function buildTronRawTransaction(params: TronTxParams, owner: Uint8Array): Uint8Array;
59
+ export declare function buildTronRawTransaction(params: TronTriggerSmartContractTxParams, owner: Uint8Array): Uint8Array;
60
+ /** The unsigned Tron transaction the MPC signs for a request. */
61
+ export interface UnsignedTronTransaction {
62
+ /** The `raw` protobuf bytes. */
63
+ readonly raw: Uint8Array;
64
+ /** sha256 of `raw`: the transaction id, and the digest the MPC signs. */
65
+ readonly txId: Uint8Array;
66
+ /** The request's derived signer, the transaction's owner. */
67
+ readonly owner: TronAddress;
68
+ }
69
+ /**
70
+ * Rebuilds the exact unsigned transaction the MPC signs for an on-ledger Tron request record:
71
+ * its transaction parameters, owned by the key the MPC derives from the record's sender and path.
72
+ *
73
+ * @param request - The on-ledger request record
74
+ * @param mpcRootPublicKey - The MPC root secp256k1 public key of the record's `keyVersion`, in any
75
+ * spelling `parseSecp256k1PublicKey` accepts
76
+ * @returns The raw transaction, its id and its owner
77
+ * @throws {Error} If the record is not a Tron request or a field cannot be encoded
78
+ */
79
+ export declare function signBidirectionalEventToUnsignedTronTransaction(request: SignBidirectionalEvent<TronTriggerSmartContractTxParams>, mpcRootPublicKey: string): UnsignedTronTransaction;
59
80
  /**
60
81
  * The transaction id (sha256 of the raw bytes): the digest the MPC signs.
61
82
  *
@@ -1 +1 @@
1
- {"version":3,"file":"tron-transactions.d.ts","sourceRoot":"","sources":["../src/tron-transactions.ts"],"names":[],"mappings":"AAIA,OAAO,EAGL,KAAK,iCAAiC,EACvC,MAAM,yBAAyB,CAAC;AAEjC,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAChE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AAY9D;;;;;;GAMG;AACH,wBAAgB,kBAAkB,CAAC,GAAG,EAAE,MAAM,GAAG,UAAU,GAAG,UAAU,CAYvE;AAMD;;;;;;GAMG;AACH,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,UAAU,GAAG,MAAM,CAG/D;AAED;;;;;;GAMG;AACH,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,MAAM,GAAG,UAAU,CAoB9D;AAED,+DAA+D;AAC/D,MAAM,WAAW,WAAW;IAC1B,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EAAE,UAAU,CAAC;IAClB,MAAM,EAAE,MAAM,CAAC;CAChB;AAED;;;;;;;GAOG;AACH,wBAAgB,iBAAiB,CAC/B,qBAAqB,EAAE,MAAM,EAC7B,eAAe,EAAE,MAAM,EACvB,IAAI,EAAE,MAAM,GACX,WAAW,CAEb;AAED;;;;;;GAMG;AACH,wBAAgB,6CAA6C,CAC3D,qBAAqB,EAAE,MAAM,EAC7B,OAAO,EAAE,iCAAiC,GACzC,WAAW,CAIb;AAwDD;;;;;;;GAOG;AACH,wBAAgB,uBAAuB,CACrC,MAAM,EAAE,gCAAgC,EACxC,KAAK,EAAE,UAAU,GAChB,UAAU,CAkCZ;AAED,iEAAiE;AACjE,MAAM,WAAW,uBAAuB;IACtC,gCAAgC;IAChC,QAAQ,CAAC,GAAG,EAAE,UAAU,CAAC;IACzB,yEAAyE;IACzE,QAAQ,CAAC,IAAI,EAAE,UAAU,CAAC;IAC1B,6DAA6D;IAC7D,QAAQ,CAAC,KAAK,EAAE,WAAW,CAAC;CAC7B;AAED;;;;;;;;;GASG;AACH,wBAAgB,+CAA+C,CAC7D,OAAO,EAAE,sBAAsB,CAAC,gCAAgC,CAAC,EACjE,gBAAgB,EAAE,MAAM,GACvB,uBAAuB,CASzB;AAED;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,UAAU,GAAG,UAAU,CAE7D;AAED;;;;;;;GAOG;AACH,wBAAgB,0BAA0B,CAAC,GAAG,EAAE,UAAU,EAAE,SAAS,EAAE,YAAY,GAAG,UAAU,CAW/F"}
@@ -3,6 +3,7 @@ import { bigintToBytes32BE, hexToBytes, stripHexPrefix } from "./byte-codecs.js"
3
3
  import { mpcSignatureToEcdsaSignature } from "./ecdsa-attestation.js";
4
4
  import { deriveEvmAddress, deriveSignBidirectionalEventSignerEvmAddress, } from "./epsilon-derivation.js";
5
5
  import { pureCircuits } from "./managed/contract/index.js";
6
+ import { TxParamType } from "./signet-requests.js";
6
7
  const TRON_ADDRESS_PREFIX = 0x41;
7
8
  const TRON_ADDRESS_BYTES = 21;
8
9
  function assertTronAddress(address, name) {
@@ -179,6 +180,24 @@ export function buildTronRawTransaction(params, owner) {
179
180
  ...int64Field(18, params.feeLimit, "feeLimit"),
180
181
  ]);
181
182
  }
183
+ /**
184
+ * Rebuilds the exact unsigned transaction the MPC signs for an on-ledger Tron request record:
185
+ * its transaction parameters, owned by the key the MPC derives from the record's sender and path.
186
+ *
187
+ * @param request - The on-ledger request record
188
+ * @param mpcRootPublicKey - The MPC root secp256k1 public key of the record's `keyVersion`, in any
189
+ * spelling `parseSecp256k1PublicKey` accepts
190
+ * @returns The raw transaction, its id and its owner
191
+ * @throws {Error} If the record is not a Tron request or a field cannot be encoded
192
+ */
193
+ export function signBidirectionalEventToUnsignedTronTransaction(request, mpcRootPublicKey) {
194
+ if (request.txParamType !== TxParamType.tronTriggerSmartContract) {
195
+ throw new Error(`expected a Tron request record, got txParamType ${String(request.txParamType)}`);
196
+ }
197
+ const owner = deriveSignBidirectionalEventSignerTronAddress(mpcRootPublicKey, request);
198
+ const raw = buildTronRawTransaction(request.txParams, owner.bytes);
199
+ return { raw, txId: tronTransactionId(raw), owner };
200
+ }
182
201
  /**
183
202
  * The transaction id (sha256 of the raw bytes): the digest the MPC signs.
184
203
  *
@@ -1 +1 @@
1
- {"version":3,"file":"tron-transactions.js","sourceRoot":"","sources":["../src/tron-transactions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAC;AAEjF,OAAO,EAAE,iBAAiB,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AACjF,OAAO,EAAE,4BAA4B,EAAE,MAAM,wBAAwB,CAAC;AACtE,OAAO,EACL,gBAAgB,EAChB,4CAA4C,GAE7C,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;A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OAAO,CAAC,CAAC;IACvF,MAAM,GAAG,GAAG,uBAAuB,CAAC,OAAO,CAAC,QAAQ,EAAE,KAAK,CAAC,KAAK,CAAC,CAAC;IACnE,OAAO,EAAE,GAAG,EAAE,IAAI,EAAE,iBAAiB,CAAC,GAAG,CAAC,EAAE,KAAK,EAAE,CAAC;AACtD,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,iBAAiB,CAAC,GAAe;IAC/C,OAAO,QAAQ,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC;AAC/B,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,0BAA0B,CAAC,GAAe,EAAE,SAAuB;IACjF,MAAM,EAAE,CAAC,EAAE,CAAC,EAAE,UAAU,EAAE,GAAG,4BAA4B,CAAC,SAAS,CAAC,CAAC;IACrE,MAAM,cAAc,GAAG,UAAU,CAAC,IAAI,CAAC;QACrC,GAAG,iBAAiB,CAAC,CAAC,CAAC;QACvB,GAAG,iBAAiB,CAAC,CAAC,CAAC;QACvB,UAAU;KACX,CAAC,CAAC;IACH,OAAO,UAAU,CAAC,IAAI,CAAC;QACrB,GAAG,oBAAoB,CAAC,CAAC,EAAE,GAAG,CAAC;QAC/B,GAAG,oBAAoB,CAAC,CAAC,EAAE,cAAc,CAAC;KAC3C,CAAC,CAAC;AACL,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sig-net/midnight",
3
- "version": "0.27.0-rc.4",
3
+ "version": "0.27.0-rc.6",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/sig-net/midnight-integration",
@@ -49,7 +49,7 @@
49
49
  "@midnight-ntwrk/compact-runtime": "0.21.0",
50
50
  "@midnight-ntwrk/midnight-js-types": "5.0.0",
51
51
  "@noble/curves": "^2.2.0",
52
- "@sig-net/midnight-serde": "^0.27.0-rc.4",
52
+ "@sig-net/midnight-serde": "^0.27.0-rc.6",
53
53
  "ethers": "^6.17.0"
54
54
  },
55
55
  "devDependencies": {
@@ -77,8 +77,8 @@ module Signet {
77
77
  evmType2TxAccessEntry,
78
78
  evmType2TxStorageKey,
79
79
  attestedOutput,
80
- tronTxHeader,
81
- tronTxWord,
80
+ tronTriggerSmartContractTxHeader,
81
+ tronTriggerSmartContractTxWord,
82
82
  }
83
83
 
84
84
  // ---- SignBidirectionalEvent ------------------------------------------------------------------------
@@ -162,7 +162,7 @@ module Signet {
162
162
  // contains so an off-chain consumer (e.g. the MPC) knows how to re-assemble it.
163
163
  export enum TxParamType {
164
164
  evmType2, // EvmType2TxParams: an EIP-1559 EVM transaction (envelope + calldata)
165
- tron,
165
+ tronTriggerSmartContract,
166
166
  }
167
167
 
168
168
  // Construction helper for the canonical Signet SignBidirectionalEventV1.
@@ -691,7 +691,7 @@ module Signet {
691
691
  return Bytes[0x41, ...evmAddress];
692
692
  }
693
693
 
694
- export struct TronTxParams<#maxCalldataWords> {
694
+ export struct TronTriggerSmartContractTxParams<#maxCalldataWords> {
695
695
  refBlockBytes: Bytes<2>;
696
696
  refBlockHash: Bytes<8>;
697
697
  timestamp: Uint<64>;
@@ -702,8 +702,8 @@ module Signet {
702
702
  calldata: Maybe<EvmCalldata<maxCalldataWords>>;
703
703
  }
704
704
 
705
- export pure circuit calculateTronTxParamsDigestV1<#maxCalldataWords>(
706
- txParams: TronTxParams<maxCalldataWords>
705
+ export pure circuit calculateTronTriggerSmartContractTxParamsDigestV1<#maxCalldataWords>(
706
+ txParams: TronTriggerSmartContractTxParams<maxCalldataWords>
707
707
  ): Bytes<32> {
708
708
  const calldata = txParams.calldata;
709
709
  const noWords = calldata.is_some ? calldata.value.noWords : 0 as Uint<16>;
@@ -712,7 +712,7 @@ module Signet {
712
712
  assert(noWords <= maxCalldataWords, "calldata noWords exceeds capacity");
713
713
 
714
714
  const head = transientHash<[HashDomain, Bytes<2>, Bytes<8>, Uint<64>, Uint<64>, Uint<64>, Bytes<21>, Uint<64>, Boolean, Bytes<4>, Uint<16>]>([
715
- HashDomain.tronTxHeader,
715
+ HashDomain.tronTriggerSmartContractTxHeader,
716
716
  txParams.refBlockBytes,
717
717
  txParams.refBlockHash,
718
718
  txParams.timestamp,
@@ -727,7 +727,7 @@ module Signet {
727
727
 
728
728
  const wordsScan = fold(
729
729
  (acc: [Uint<16>, Field], word: Bytes<32>): [Uint<16>, Field] =>
730
- [(acc[0] + 1) as Uint<16>, acc[0] < noWords ? transientHash<[HashDomain, Field, Bytes<32>]>([HashDomain.tronTxWord, acc[1], word]) : acc[1]],
730
+ [(acc[0] + 1) as Uint<16>, acc[0] < noWords ? transientHash<[HashDomain, Field, Bytes<32>]>([HashDomain.tronTriggerSmartContractTxWord, acc[1], word]) : acc[1]],
731
731
  [0 as Uint<16>, head],
732
732
  calldata.value.words
733
733
  );
@@ -735,22 +735,89 @@ module Signet {
735
735
  return upgradeFromTransient(wordsScan[1]);
736
736
  }
737
737
 
738
- export pure circuit calculateTronRequestIdV1<#maxCalldataWords, #LenOutputDeserialization>(
739
- request: SignBidirectionalEventV1<TronTxParams<maxCalldataWords>, LenOutputDeserialization, 0>
738
+ export pure circuit calculateTronTriggerSmartContractRequestIdV1<#maxCalldataWords, #LenOutputDeserialization>(
739
+ request: SignBidirectionalEventV1<TronTriggerSmartContractTxParams<maxCalldataWords>, LenOutputDeserialization, 0>
740
740
  ): RequestId {
741
- assert(request.txParamType == TxParamType.tron, "txParamType must tag txParams as tron");
741
+ assert(request.txParamType == TxParamType.tronTriggerSmartContract, "txParamType must tag txParams as tronTriggerSmartContract");
742
742
  const preimage = RequestIdPreimageV1 {
743
743
  keyVersion: request.keyVersion,
744
744
  sender: request.sender,
745
745
  path: request.path,
746
746
  algo: request.algo,
747
747
  txParamType: request.txParamType,
748
- txParamsDigest: calculateTronTxParamsDigestV1<maxCalldataWords>(request.txParams),
748
+ txParamsDigest: calculateTronTriggerSmartContractTxParamsDigestV1<maxCalldataWords>(request.txParams),
749
749
  executionDest: request.executionDest,
750
750
  };
751
751
  return calculateRequestIdV1(preimage);
752
752
  }
753
753
 
754
+ // ---- Tron admission checks -------------------------------------------------------------------------
755
+ // The MPC drops a Tron request it cannot encode or whose validity window it does not admit at the
756
+ // source block (the block of the transaction that notifies it), and a dropped request is never
757
+ // answered: no signature and no attestation, so nothing can settle it. A client contract runs these
758
+ // checks so that such a request is refused on Midnight instead.
759
+
760
+ // The largest value of Tron's int64 wire fields (timestamp, expiration, fee_limit, call_value).
761
+ export pure circuit tronInt64Max(): Uint<64> {
762
+ return 9223372036854775807;
763
+ }
764
+
765
+ // The longest validity window the MPC admits, in seconds: an expiration at most 24 h past the
766
+ // source block, java-tron's own cap.
767
+ export pure circuit tronMaxExpirationSpanSeconds(): Uint<64> {
768
+ return 86400;
769
+ }
770
+
771
+ // Asserts every numeric field fits its int64 wire field, which the MPC needs to encode the
772
+ // transaction, and that the transaction expires after its own timestamp.
773
+ export pure circuit assertTronTriggerSmartContractTxParamsV1<#maxCalldataWords>(
774
+ txParams: TronTriggerSmartContractTxParams<maxCalldataWords>
775
+ ): [] {
776
+ assert(txParams.timestamp <= tronInt64Max(), "Tron timestamp exceeds int64");
777
+ assert(txParams.expiration <= tronInt64Max(), "Tron expiration exceeds int64");
778
+ assert(txParams.feeLimit <= tronInt64Max(), "Tron fee limit exceeds int64");
779
+ assert(txParams.callValue <= tronInt64Max(), "Tron call value exceeds int64");
780
+ assert(txParams.expiration > txParams.timestamp, "Tron expiration must follow its timestamp");
781
+ }
782
+
783
+ // Asserts the MPC admits a transaction expiring at `expiration` (milliseconds) from a request this
784
+ // block notifies: the window must still be open at the block time and close within the 24 h cap,
785
+ // with the caller's margins in seconds on both sides. The MPC reads the block time in whole
786
+ // seconds, and so does the ledger, so the checks compare whole seconds: `expirationSeconds` must
787
+ // be floor(expiration / 1000), which Compact cannot divide, so the caller computes it (a witness)
788
+ // and this circuit asserts it. Passing makes the expiration at least
789
+ // (minRemainingSeconds + 1) s after the block time and at least capMarginSeconds s inside the cap.
790
+ // The block time is the ledger's at the including block, not the prover's, so a transaction that
791
+ // passed here when proved fails if its block comes too late or too early.
792
+ export circuit assertTronExpirationWindowV1(
793
+ expiration: Uint<64>,
794
+ expirationSeconds: Uint<64>,
795
+ minRemainingSeconds: Uint<64>,
796
+ capMarginSeconds: Uint<64>
797
+ ): [] {
798
+ // The block-time comparisons disclose their bounds, so every input is disclosed: a request
799
+ // publishes its expiration anyway.
800
+ const ms = disclose(expiration);
801
+ const seconds = disclose(expirationSeconds);
802
+ const minRemaining = disclose(minRemainingSeconds);
803
+ assert(
804
+ seconds * 1000 <= ms && ms < seconds * 1000 + 1000,
805
+ "expirationSeconds is not the expiration in whole seconds"
806
+ );
807
+ // Block time < seconds - minRemaining.
808
+ assert(
809
+ seconds > minRemaining && blockTimeLt((seconds - minRemaining) as Uint<64>),
810
+ "Tron expiration too close to the block time"
811
+ );
812
+ // Block time >= seconds + 1 + capMargin - 24 h; trivially so when that is <= 0.
813
+ const earliest = seconds + 1 + disclose(capMarginSeconds);
814
+ assert(
815
+ earliest <= tronMaxExpirationSpanSeconds() ||
816
+ blockTimeGte((earliest - tronMaxExpirationSpanSeconds()) as Uint<64>),
817
+ "Tron expiration too far past the block time"
818
+ );
819
+ }
820
+
754
821
  // ---- ABI Calldata Word Construction Utilities ------------------------------------------------------
755
822
  // Canonical ABI word builders and readers. Words MUST be stored in canonical
756
823
  // ABI form (big-endian, per the ABI spec). These utilities help construct