@sig-net/midnight 0.26.0-rc.8 → 0.27.0-rc.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.
Files changed (71) hide show
  1. package/README.md +6 -6
  2. package/dist/compact-descriptors.d.ts +8 -0
  3. package/dist/compact-descriptors.d.ts.map +1 -1
  4. package/dist/compact-descriptors.js +13 -1
  5. package/dist/compact-descriptors.js.map +1 -1
  6. package/dist/constants.d.ts +6 -8
  7. package/dist/constants.d.ts.map +1 -1
  8. package/dist/constants.js +29 -29
  9. package/dist/constants.js.map +1 -1
  10. package/dist/index.d.ts +5 -1
  11. package/dist/index.d.ts.map +1 -1
  12. package/dist/index.js +7 -2
  13. package/dist/index.js.map +1 -1
  14. package/dist/managed/compiler/contract-info.json +714 -5
  15. package/dist/managed/compiler/contract-manifest.json +8 -8
  16. package/dist/managed/contract/index.d.ts +168 -1
  17. package/dist/managed/contract/index.js +678 -312
  18. package/dist/managed/contract/index.js.map +1 -1
  19. package/dist/mpc-output-cache.d.ts +3 -3
  20. package/dist/mpc-output-cache.d.ts.map +1 -1
  21. package/dist/mpc-output-cache.js +2 -2
  22. package/dist/record-contract-address.d.ts +4 -4
  23. package/dist/record-contract-address.d.ts.map +1 -1
  24. package/dist/record-contract-address.js +4 -4
  25. package/dist/record-contract-address.js.map +1 -1
  26. package/dist/signature-requests-state-reader.d.ts +3 -3
  27. package/dist/signature-requests-state-reader.d.ts.map +1 -1
  28. package/dist/signature-requests-state-reader.js +6 -2
  29. package/dist/signature-requests-state-reader.js.map +1 -1
  30. package/dist/signature-response-verification.d.ts +24 -9
  31. package/dist/signature-response-verification.d.ts.map +1 -1
  32. package/dist/signature-response-verification.js +35 -12
  33. package/dist/signature-response-verification.js.map +1 -1
  34. package/dist/signet-contract-events.d.ts +8 -2
  35. package/dist/signet-contract-events.d.ts.map +1 -1
  36. package/dist/signet-contract-events.js +10 -8
  37. package/dist/signet-contract-events.js.map +1 -1
  38. package/dist/signet-evtype2tx-requests.d.ts.map +1 -1
  39. package/dist/signet-evtype2tx-requests.js +1 -7
  40. package/dist/signet-evtype2tx-requests.js.map +1 -1
  41. package/dist/signet-request-id.d.ts +2 -2
  42. package/dist/signet-request-id.d.ts.map +1 -1
  43. package/dist/signet-request-id.js +18 -8
  44. package/dist/signet-request-id.js.map +1 -1
  45. package/dist/signet-request-response-reader.d.ts +35 -11
  46. package/dist/signet-request-response-reader.d.ts.map +1 -1
  47. package/dist/signet-request-response-reader.js +76 -29
  48. package/dist/signet-request-response-reader.js.map +1 -1
  49. package/dist/signet-requests.d.ts +18 -10
  50. package/dist/signet-requests.d.ts.map +1 -1
  51. package/dist/signet-requests.js +19 -10
  52. package/dist/signet-requests.js.map +1 -1
  53. package/dist/signet-tron-record-decoding.d.ts +11 -0
  54. package/dist/signet-tron-record-decoding.d.ts.map +1 -0
  55. package/dist/signet-tron-record-decoding.js +29 -0
  56. package/dist/signet-tron-record-decoding.js.map +1 -0
  57. package/dist/signet-tron-requests.d.ts +36 -0
  58. package/dist/signet-tron-requests.d.ts.map +1 -0
  59. package/dist/signet-tron-requests.js +76 -0
  60. package/dist/signet-tron-requests.js.map +1 -0
  61. package/dist/tron-transactions.d.ts +52 -0
  62. package/dist/tron-transactions.d.ts.map +1 -0
  63. package/dist/tron-transactions.js +181 -0
  64. package/dist/tron-transactions.js.map +1 -0
  65. package/dist/url-redaction.d.ts +11 -0
  66. package/dist/url-redaction.d.ts.map +1 -0
  67. package/dist/url-redaction.js +21 -0
  68. package/dist/url-redaction.js.map +1 -0
  69. package/package.json +2 -2
  70. package/src/Signet.compact +78 -8
  71. package/src/circuits.compact +26 -0
@@ -7,7 +7,7 @@
7
7
  // - client contract(s): contracts on the Midnight blockchain that integrate with the Signet
8
8
  // Distributed MPC network to execute arbitrary transactions on foreign
9
9
  // blockchains.
10
- // - Signet singleton: a single contract on the Midnight blockchain through which clients notify
10
+ // - Signet signer: a single contract on the Midnight blockchain through which clients notify
11
11
  // the MPC of signature requests.
12
12
  // - Signet responder: the contract through which the MPC posts back signatures and signed
13
13
  // attestations of foreign executions, each emitted as a contract event
@@ -22,7 +22,7 @@
22
22
  // - RequestId: 32-byte id derived by calculateRequestIdV1.
23
23
  // - SignBidirectionalEventMapV1: the RequestId -> SignBidirectionalEventV1 map a client contract
24
24
  // declares in its own ledger for the MPC to read requests from.
25
- // - SignetSigner: the contract interface client contracts call to notify the Signet singleton.
25
+ // - SignetSigner: the contract interface client contracts call to notify the Signet signer.
26
26
  // - SignBidirectionalEventNotification: the notification delivered through that call, versioned by
27
27
  // the version byte it carries.
28
28
  // - SignatureRespondedEventV1: the MPC's posted signature answering a request.
@@ -37,9 +37,9 @@
37
37
  // These key types are best understood within the sign bidirectional flow that they enable:
38
38
  // 1. Client contract stores a SignBidirectionalEvent in a SignBidirectionalEventMap in its own ledger
39
39
  // (against the calculated RequestId) and requests a signature from the MPC via a cross contract call
40
- // against the SignetSigner interface. The Signet singleton emits the SignBidirectionalEventNotification
40
+ // against the SignetSigner interface. The Signet signer emits the SignBidirectionalEventNotification
41
41
  // as a contract event.
42
- // 2. MPC polls the Signet singleton contract's events for SignBidirectionalEventNotifications and
42
+ // 2. MPC polls the Signet signer's events for SignBidirectionalEventNotifications and
43
43
  // uses each one to look the declared SignBidirectionalEvent signature request up in the named
44
44
  // client's own ledger. It generates the signature and posts a SignatureRespondedEvent (the requested
45
45
  // signature) through the Signet responder, which emits it as a contract event.
@@ -77,6 +77,8 @@ module Signet {
77
77
  evmType2TxAccessEntry,
78
78
  evmType2TxStorageKey,
79
79
  attestedOutput,
80
+ tronTxHeader,
81
+ tronTxWord,
80
82
  }
81
83
 
82
84
  // ---- SignBidirectionalEvent ------------------------------------------------------------------------
@@ -160,7 +162,7 @@ module Signet {
160
162
  // contains so an off-chain consumer (e.g. the MPC) knows how to re-assemble it.
161
163
  export enum TxParamType {
162
164
  evmType2, // EvmType2TxParams: an EIP-1559 EVM transaction (envelope + calldata)
163
- reserved, // Reserved for future use. Exists to keep enum >= 2 (proof server bug).
165
+ tron,
164
166
  }
165
167
 
166
168
  // Construction helper for the canonical Signet SignBidirectionalEventV1.
@@ -237,14 +239,14 @@ module Signet {
237
239
 
238
240
  // Named mapping of RequestId to SignBidirectionalEvent. Declared by client contracts
239
241
  // in their ledger. Client contract tells MPC field location of this map when making a cross
240
- // contract call, via SignetSigner, to the Signet singleton. The MPC looks here to find
242
+ // contract call, via SignetSigner, to the Signet signer. The MPC looks here to find
241
243
  // SignBidirectionalEvents.
242
244
  export new type SignBidirectionalEventMapV1<TxParams, #LenOutputDeserialization> = Map<RequestId, SignBidirectionalEventV1<TxParams, LenOutputDeserialization, 0>>;
243
245
 
244
246
  // ---- Cross Contract SignBidirectionalEventNotification ---------------------------------------------
245
247
 
246
248
  // Contract interface used by client contract to make cross contract calls to
247
- // Signet singleton to notify the MPC of a SignBidirectionalEvent.
249
+ // Signet signer to notify the MPC of a SignBidirectionalEvent.
248
250
  export contract SignetSigner {
249
251
  // Called by client contracts to notify the MPC of a SignBidirectionalEvent.
250
252
  circuit signBidirectional(
@@ -258,7 +260,7 @@ module Signet {
258
260
  ): [];
259
261
  }
260
262
 
261
- // Notification delivered by client contracts via cross contract call to Signet singleton
263
+ // Notification delivered by client contracts via cross contract call to Signet signer
262
264
  // (via SignetSigner interface) to notify the MPC of a SignBidirectionalEvent.
263
265
  export struct SignBidirectionalEventNotification {
264
266
  // Notification payload layout version.
@@ -679,6 +681,74 @@ module Signet {
679
681
  return calculateRequestIdV1(preimage);
680
682
  }
681
683
 
684
+ export pure circuit tronCaip2Id(): Bytes<64> {
685
+ return pad(64, "tron:mainnet");
686
+ }
687
+
688
+ export pure circuit tronAddress(evmAddress: Bytes<20>): Bytes<21> {
689
+ return Bytes[0x41, ...evmAddress];
690
+ }
691
+
692
+ export struct TronTxParams<#maxCalldataWords> {
693
+ refBlockBytes: Bytes<2>;
694
+ refBlockHash: Bytes<8>;
695
+ timestamp: Uint<64>;
696
+ expiration: Uint<64>;
697
+ feeLimit: Uint<64>;
698
+ contractAddress: Bytes<21>;
699
+ callValue: Uint<64>;
700
+ calldata: Maybe<EvmCalldata<maxCalldataWords>>;
701
+ }
702
+
703
+ export pure circuit calculateTronTxParamsDigestV1<#maxCalldataWords>(
704
+ txParams: TronTxParams<maxCalldataWords>
705
+ ): Bytes<32> {
706
+ const calldata = txParams.calldata;
707
+ const noWords = calldata.is_some ? calldata.value.noWords : 0 as Uint<16>;
708
+ const selector = calldata.is_some ? calldata.value.selector : default<Bytes<4>>;
709
+
710
+ assert(noWords <= maxCalldataWords, "calldata noWords exceeds capacity");
711
+
712
+ const head = transientHash<[HashDomain, Bytes<2>, Bytes<8>, Uint<64>, Uint<64>, Uint<64>, Bytes<21>, Uint<64>, Boolean, Bytes<4>, Uint<16>]>([
713
+ HashDomain.tronTxHeader,
714
+ txParams.refBlockBytes,
715
+ txParams.refBlockHash,
716
+ txParams.timestamp,
717
+ txParams.expiration,
718
+ txParams.feeLimit,
719
+ txParams.contractAddress,
720
+ txParams.callValue,
721
+ calldata.is_some,
722
+ selector,
723
+ noWords
724
+ ]);
725
+
726
+ const wordsScan = fold(
727
+ (acc: [Uint<16>, Field], word: Bytes<32>): [Uint<16>, Field] =>
728
+ [(acc[0] + 1) as Uint<16>, acc[0] < noWords ? transientHash<[HashDomain, Field, Bytes<32>]>([HashDomain.tronTxWord, acc[1], word]) : acc[1]],
729
+ [0 as Uint<16>, head],
730
+ calldata.value.words
731
+ );
732
+
733
+ return upgradeFromTransient(wordsScan[1]);
734
+ }
735
+
736
+ export pure circuit calculateTronRequestIdV1<#maxCalldataWords, #LenOutputDeserialization>(
737
+ request: SignBidirectionalEventV1<TronTxParams<maxCalldataWords>, LenOutputDeserialization, 0>
738
+ ): RequestId {
739
+ assert(request.txParamType == TxParamType.tron, "txParamType must tag txParams as tron");
740
+ const preimage = RequestIdPreimageV1 {
741
+ keyVersion: request.keyVersion,
742
+ sender: request.sender,
743
+ path: request.path,
744
+ algo: request.algo,
745
+ txParamType: request.txParamType,
746
+ txParamsDigest: calculateTronTxParamsDigestV1<maxCalldataWords>(request.txParams),
747
+ executionDest: request.executionDest,
748
+ };
749
+ return calculateRequestIdV1(preimage);
750
+ }
751
+
682
752
  // ---- ABI Calldata Word Construction Utilities ------------------------------------------------------
683
753
  // Canonical ABI word builders and readers. Words MUST be stored in canonical
684
754
  // ABI form (big-endian, per the ABI spec). These utilities help construct
@@ -16,6 +16,8 @@ export {
16
16
  verifyRespondBidirectionalAttestationV1,
17
17
  constructSignBidirectionalEventNotificationV1,
18
18
  ethereumCaip2Id,
19
+ tronCaip2Id,
20
+ tronAddress,
19
21
  evmAddressAbiWord,
20
22
  numericAbiWord,
21
23
  boolAbiWord,
@@ -154,3 +156,27 @@ export pure circuit constructSignBidirectionalEventV1_1_0_0_34(
154
156
  request.outputDeserializationSchema
155
157
  );
156
158
  }
159
+
160
+ export pure circuit calculateTronTxParamsDigestV1_1(
161
+ txParams: TronTxParams<1>
162
+ ): Bytes<32> {
163
+ return calculateTronTxParamsDigestV1<1>(txParams);
164
+ }
165
+
166
+ export pure circuit calculateTronTxParamsDigestV1_2(
167
+ txParams: TronTxParams<2>
168
+ ): Bytes<32> {
169
+ return calculateTronTxParamsDigestV1<2>(txParams);
170
+ }
171
+
172
+ export pure circuit calculateTronRequestIdV1_1_0(
173
+ request: SignBidirectionalEventV1<TronTxParams<1>, 0, 0>
174
+ ): RequestId {
175
+ return calculateTronRequestIdV1<1, 0>(request);
176
+ }
177
+
178
+ export pure circuit calculateTronRequestIdV1_2_0(
179
+ request: SignBidirectionalEventV1<TronTxParams<2>, 0, 0>
180
+ ): RequestId {
181
+ return calculateTronRequestIdV1<2, 0>(request);
182
+ }