@aztec/stdlib 0.82.3 → 0.83.1-alpha-testnet.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.
Files changed (129) hide show
  1. package/dest/avm/avm.d.ts +3889 -382
  2. package/dest/avm/avm.d.ts.map +1 -1
  3. package/dest/avm/avm.js +64 -18
  4. package/dest/avm/avm_proving_request.d.ts +1610 -66
  5. package/dest/avm/avm_proving_request.d.ts.map +1 -1
  6. package/dest/block/l2_block_downloader/l2_block_stream.d.ts +9 -12
  7. package/dest/block/l2_block_downloader/l2_block_stream.d.ts.map +1 -1
  8. package/dest/block/l2_block_downloader/l2_block_stream.js +39 -11
  9. package/dest/config/config.d.ts +2 -2
  10. package/dest/config/config.d.ts.map +1 -1
  11. package/dest/config/config.js +4 -5
  12. package/dest/contract/interfaces/node-info.d.ts +2 -2
  13. package/dest/contract/interfaces/node-info.d.ts.map +1 -1
  14. package/dest/contract/interfaces/node-info.js +1 -1
  15. package/dest/interfaces/prover-client.d.ts +3 -3
  16. package/dest/interfaces/prover-client.d.ts.map +1 -1
  17. package/dest/interfaces/prover-client.js +6 -4
  18. package/dest/interfaces/proving-job.d.ts +1610 -66
  19. package/dest/interfaces/proving-job.d.ts.map +1 -1
  20. package/dest/interfaces/pxe.d.ts +7 -6
  21. package/dest/interfaces/pxe.d.ts.map +1 -1
  22. package/dest/interfaces/pxe.js +1 -1
  23. package/dest/keys/derivation.d.ts +1 -1
  24. package/dest/keys/derivation.d.ts.map +1 -1
  25. package/dest/keys/derivation.js +10 -2
  26. package/dest/logs/index.d.ts +2 -1
  27. package/dest/logs/index.d.ts.map +1 -1
  28. package/dest/logs/index.js +2 -1
  29. package/dest/logs/pending_tagged_log.d.ts +17 -0
  30. package/dest/logs/pending_tagged_log.d.ts.map +1 -0
  31. package/dest/logs/pending_tagged_log.js +45 -0
  32. package/dest/logs/{l1_payload/shared_secret_derivation.d.ts → shared_secret_derivation.d.ts} +4 -3
  33. package/dest/logs/shared_secret_derivation.d.ts.map +1 -0
  34. package/dest/logs/{l1_payload/shared_secret_derivation.js → shared_secret_derivation.js} +3 -5
  35. package/dest/logs/tx_scoped_l2_log.d.ts +6 -1
  36. package/dest/logs/tx_scoped_l2_log.d.ts.map +1 -1
  37. package/dest/logs/tx_scoped_l2_log.js +12 -4
  38. package/dest/note/note.d.ts +45 -4
  39. package/dest/note/note.d.ts.map +1 -1
  40. package/dest/note/note.js +51 -4
  41. package/dest/proofs/proof.d.ts.map +1 -1
  42. package/dest/proofs/proof.js +33 -7
  43. package/dest/snapshots/download.js +1 -1
  44. package/dest/snapshots/types.d.ts +4 -4
  45. package/dest/snapshots/types.d.ts.map +1 -1
  46. package/dest/snapshots/types.js +1 -1
  47. package/dest/snapshots/upload.d.ts +1 -1
  48. package/dest/snapshots/upload.d.ts.map +1 -1
  49. package/dest/snapshots/upload.js +1 -1
  50. package/dest/tests/factories.d.ts +10 -2
  51. package/dest/tests/factories.d.ts.map +1 -1
  52. package/dest/tests/factories.js +42 -6
  53. package/dest/tests/mocks.d.ts +2 -1
  54. package/dest/tests/mocks.d.ts.map +1 -1
  55. package/dest/tests/mocks.js +5 -1
  56. package/dest/trees/nullifier_leaf.d.ts +46 -21
  57. package/dest/trees/nullifier_leaf.d.ts.map +1 -1
  58. package/dest/trees/nullifier_leaf.js +48 -30
  59. package/dest/trees/nullifier_membership_witness.d.ts +28 -12
  60. package/dest/trees/nullifier_membership_witness.d.ts.map +1 -1
  61. package/dest/trees/protocol_contract_leaf.d.ts +0 -1
  62. package/dest/trees/protocol_contract_leaf.d.ts.map +1 -1
  63. package/dest/trees/protocol_contract_leaf.js +0 -3
  64. package/dest/trees/public_data_leaf.d.ts +46 -25
  65. package/dest/trees/public_data_leaf.d.ts.map +1 -1
  66. package/dest/trees/public_data_leaf.js +35 -30
  67. package/dest/trees/public_data_witness.d.ts +36 -18
  68. package/dest/trees/public_data_witness.d.ts.map +1 -1
  69. package/dest/trees/public_data_witness.js +6 -6
  70. package/dest/versioning/versioning.d.ts +1 -1
  71. package/dest/versioning/versioning.d.ts.map +1 -1
  72. package/dest/versioning/versioning.js +6 -6
  73. package/package.json +6 -7
  74. package/src/avm/avm.ts +74 -20
  75. package/src/block/l2_block_downloader/l2_block_stream.ts +58 -29
  76. package/src/config/config.ts +6 -6
  77. package/src/contract/interfaces/node-info.ts +3 -3
  78. package/src/interfaces/prover-client.ts +9 -7
  79. package/src/interfaces/pxe.ts +14 -7
  80. package/src/keys/derivation.ts +12 -6
  81. package/src/logs/index.ts +2 -1
  82. package/src/logs/pending_tagged_log.ts +43 -0
  83. package/src/logs/{l1_payload/shared_secret_derivation.ts → shared_secret_derivation.ts} +4 -11
  84. package/src/logs/tx_scoped_l2_log.ts +13 -4
  85. package/src/note/note.ts +61 -5
  86. package/src/proofs/proof.ts +39 -5
  87. package/src/snapshots/download.ts +1 -1
  88. package/src/snapshots/types.ts +2 -2
  89. package/src/snapshots/upload.ts +5 -3
  90. package/src/tests/factories.ts +72 -8
  91. package/src/tests/mocks.ts +7 -0
  92. package/src/trees/nullifier_leaf.ts +49 -26
  93. package/src/trees/protocol_contract_leaf.ts +0 -4
  94. package/src/trees/public_data_leaf.ts +31 -29
  95. package/src/trees/public_data_witness.ts +6 -6
  96. package/src/versioning/versioning.ts +8 -14
  97. package/dest/event/event.d.ts +0 -24
  98. package/dest/event/event.d.ts.map +0 -1
  99. package/dest/event/event.js +0 -13
  100. package/dest/event/event_metadata.d.ts +0 -38
  101. package/dest/event/event_metadata.d.ts.map +0 -1
  102. package/dest/event/event_metadata.js +0 -45
  103. package/dest/event/index.d.ts +0 -4
  104. package/dest/event/index.d.ts.map +0 -1
  105. package/dest/event/index.js +0 -3
  106. package/dest/event/l1_event_payload.d.ts +0 -52
  107. package/dest/event/l1_event_payload.d.ts.map +0 -1
  108. package/dest/event/l1_event_payload.js +0 -64
  109. package/dest/logs/l1_payload/encrypted_log_payload.d.ts +0 -50
  110. package/dest/logs/l1_payload/encrypted_log_payload.d.ts.map +0 -1
  111. package/dest/logs/l1_payload/encrypted_log_payload.js +0 -140
  112. package/dest/logs/l1_payload/encryption_util.d.ts +0 -24
  113. package/dest/logs/l1_payload/encryption_util.d.ts.map +0 -1
  114. package/dest/logs/l1_payload/encryption_util.js +0 -46
  115. package/dest/logs/l1_payload/index.d.ts +0 -3
  116. package/dest/logs/l1_payload/index.d.ts.map +0 -1
  117. package/dest/logs/l1_payload/index.js +0 -2
  118. package/dest/logs/l1_payload/payload.d.ts +0 -60
  119. package/dest/logs/l1_payload/payload.d.ts.map +0 -1
  120. package/dest/logs/l1_payload/payload.js +0 -61
  121. package/dest/logs/l1_payload/shared_secret_derivation.d.ts.map +0 -1
  122. package/src/event/event.ts +0 -16
  123. package/src/event/event_metadata.ts +0 -56
  124. package/src/event/index.ts +0 -3
  125. package/src/event/l1_event_payload.ts +0 -87
  126. package/src/logs/l1_payload/encrypted_log_payload.ts +0 -202
  127. package/src/logs/l1_payload/encryption_util.ts +0 -54
  128. package/src/logs/l1_payload/index.ts +0 -2
  129. package/src/logs/l1_payload/payload.ts +0 -73
@@ -1,140 +0,0 @@
1
- import { PRIVATE_LOG_SIZE_IN_FIELDS } from '@aztec/constants';
2
- import { randomBytes } from '@aztec/foundation/crypto';
3
- import { Fr, NotOnCurveError, Point } from '@aztec/foundation/fields';
4
- import { BufferReader, numToUInt16BE, serializeToBuffer } from '@aztec/foundation/serialize';
5
- import { AztecAddress } from '../../aztec-address/index.js';
6
- import { derivePublicKeyFromSecretKey } from '../../keys/derivation.js';
7
- import { PrivateLog } from '../private_log.js';
8
- import { aes128Decrypt, aes128Encrypt, deriveAesSymmetricKeyAndIvFromEcdhSharedSecretUsingSha256 } from './encryption_util.js';
9
- import { deriveEcdhSharedSecret, deriveEcdhSharedSecretUsingAztecAddress } from './shared_secret_derivation.js';
10
- // Below constants should match the values defined in aztec-nr/aztec/src/encrypted_logs/log_assembly_strategies/default_aes128/note.nr.
11
- // Note: we will soon be 'abstracting' log processing: apps will process their own logs, instead of the PXE processing all apps' logs. Therefore, this file will imminently change considerably.
12
- const TAG_SIZE_IN_FIELDS = 1;
13
- const EPK_SIZE_IN_FIELDS = 1;
14
- const USABLE_PRIVATE_LOG_SIZE_IN_FIELDS = PRIVATE_LOG_SIZE_IN_FIELDS - TAG_SIZE_IN_FIELDS - EPK_SIZE_IN_FIELDS;
15
- const USABLE_PRIVATE_LOG_SIZE_IN_BYTES = USABLE_PRIVATE_LOG_SIZE_IN_FIELDS * 31 / 16 * 16;
16
- // The incoming header ciphertext is 48 bytes
17
- // 32 bytes for the address, and 16 bytes padding to follow PKCS#7
18
- const HEADER_CIPHERTEXT_SIZE_IN_BYTES = 48;
19
- const USABLE_PLAINTEXT_SIZE_IN_BYTES = USABLE_PRIVATE_LOG_SIZE_IN_BYTES - HEADER_CIPHERTEXT_SIZE_IN_BYTES;
20
- const CONTRACT_ADDRESS_SIZE_IN_BYTES = 32;
21
- const SIZE_OF_ENCODING_OF_CIPHERTEXT_SIZE_IN_BYTES = 2;
22
- function beBytes31ToFields(bytes) {
23
- const fields = [];
24
- const numFields = Math.ceil(bytes.length / 31);
25
- for(let i = 0; i < numFields; i++){
26
- fields.push(new Fr(bytes.subarray(i * 31, (i + 1) * 31)));
27
- }
28
- return fields;
29
- }
30
- function fieldsToBEBytes31(fields) {
31
- return Buffer.concat(fields.map((f)=>f.toBuffer().subarray(1)));
32
- }
33
- /**
34
- * Encrypted log payload with a tag used for retrieval by clients.
35
- */ export class EncryptedLogPayload {
36
- tag;
37
- contractAddress;
38
- incomingBodyPlaintext;
39
- constructor(/**
40
- * Note discovery tag.
41
- */ tag, /**
42
- * Address of a contract that emitted the log.
43
- */ contractAddress, /**
44
- * Decrypted incoming body.
45
- */ incomingBodyPlaintext){
46
- this.tag = tag;
47
- this.contractAddress = contractAddress;
48
- this.incomingBodyPlaintext = incomingBodyPlaintext;
49
- }
50
- // NB: Only appears to be used in tests
51
- // See noir-projects/aztec-nr/aztec/src/encrypted_logs/log_assembly_strategies/default_aes128/note.nr
52
- async generatePayload(ephSk, recipient, rand = randomBytes) {
53
- const ephPk = await derivePublicKeyFromSecretKey(ephSk);
54
- const [ephPkX, ephPkSignBool] = ephPk.toXAndSign();
55
- const ephPkSignU8 = Buffer.from([
56
- Number(ephPkSignBool)
57
- ]);
58
- const ciphertextSharedSecret = await deriveEcdhSharedSecretUsingAztecAddress(ephSk, recipient); // not to be confused with the tagging shared secret
59
- const [symKey, iv] = deriveAesSymmetricKeyAndIvFromEcdhSharedSecretUsingSha256(ciphertextSharedSecret);
60
- if (this.incomingBodyPlaintext.length > USABLE_PLAINTEXT_SIZE_IN_BYTES) {
61
- throw new Error(`Incoming body plaintext cannot be more than ${USABLE_PLAINTEXT_SIZE_IN_BYTES} bytes.`);
62
- }
63
- const finalPlaintext = this.incomingBodyPlaintext;
64
- const ciphertextBytes = await aes128Encrypt(finalPlaintext, iv, symKey);
65
- const headerPlaintext = serializeToBuffer(this.contractAddress.toBuffer(), numToUInt16BE(ciphertextBytes.length));
66
- // TODO: it is unsafe to re-use the same iv and symKey. We'll need to do something cleverer.
67
- const headerCiphertextBytes = await aes128Encrypt(headerPlaintext, iv, symKey);
68
- if (headerCiphertextBytes.length !== HEADER_CIPHERTEXT_SIZE_IN_BYTES) {
69
- throw new Error(`Invalid header ciphertext size: ${headerCiphertextBytes.length}`);
70
- }
71
- const properLogBytesLength = 1 /* ephPkSignU8 */ + HEADER_CIPHERTEXT_SIZE_IN_BYTES + ciphertextBytes.length;
72
- const logBytesPaddingToMult31 = rand(31 * Math.ceil(properLogBytesLength / 31) - properLogBytesLength);
73
- const logBytes = serializeToBuffer(ephPkSignU8, headerCiphertextBytes, ciphertextBytes, logBytesPaddingToMult31);
74
- if (logBytes.length % 31 !== 0) {
75
- throw new Error(`logBytes.length should be divisible by 31, got: ${logBytes.length}`);
76
- }
77
- const fieldsPadding = Array.from({
78
- length: USABLE_PRIVATE_LOG_SIZE_IN_FIELDS - logBytes.length / 31
79
- }, ()=>Fr.fromBuffer(rand(32))); // we use the randomBytes function instead of `Fr.random()`, so that we can use deterministic randomness in tests, through the rand() function.
80
- const logFields = [
81
- this.tag,
82
- ephPkX,
83
- ...beBytes31ToFields(logBytes),
84
- ...fieldsPadding
85
- ];
86
- if (logFields.length !== PRIVATE_LOG_SIZE_IN_FIELDS) {
87
- throw new Error(`Expected private log payload to have ${PRIVATE_LOG_SIZE_IN_FIELDS} fields. Got ${logFields.length}.`);
88
- }
89
- return new PrivateLog(logFields);
90
- }
91
- /**
92
- * Decrypts a ciphertext as an incoming log.
93
- *
94
- * This is executable by the recipient of the note, and uses the addressSecret to decrypt the payload.
95
- *
96
- * @param payload - The payload for the log
97
- * @param addressSecret - The address secret, used to decrypt the logs
98
- * @param ciphertextLength - Optionally supply the ciphertext length (see trimCiphertext())
99
- * @returns The decrypted log payload
100
- */ static async decryptAsIncoming(payload, addressSecret) {
101
- try {
102
- const logFields = payload;
103
- const tag = logFields[0];
104
- const ephPkX = logFields[1];
105
- const reader = BufferReader.asReader(fieldsToBEBytes31(logFields.slice(TAG_SIZE_IN_FIELDS + EPK_SIZE_IN_FIELDS)));
106
- const ephPkSigBuf = reader.readBytes(1);
107
- const ephPkSignBool = !!ephPkSigBuf[0];
108
- const ephPk = await Point.fromXAndSign(ephPkX, ephPkSignBool);
109
- const headerCiphertextBytes = reader.readBytes(HEADER_CIPHERTEXT_SIZE_IN_BYTES);
110
- let contractAddress = AztecAddress.ZERO;
111
- if (!addressSecret) {
112
- throw new Error('Cannot decrypt without an address secret.');
113
- }
114
- const ciphertextSharedSecret = await deriveEcdhSharedSecret(addressSecret, ephPk);
115
- const [symKey, iv] = deriveAesSymmetricKeyAndIvFromEcdhSharedSecretUsingSha256(ciphertextSharedSecret);
116
- const headerPlaintextBytes = await aes128Decrypt(headerCiphertextBytes, iv, symKey);
117
- const headerReader = BufferReader.asReader(headerPlaintextBytes);
118
- const contractAddressBuf = headerReader.readBytes(CONTRACT_ADDRESS_SIZE_IN_BYTES);
119
- contractAddress = AztecAddress.fromBuffer(contractAddressBuf);
120
- const ciphertextBytesLengthBuf = headerReader.readBytes(SIZE_OF_ENCODING_OF_CIPHERTEXT_SIZE_IN_BYTES);
121
- const ciphertextBytesLength = (ciphertextBytesLengthBuf[0] << 8) + ciphertextBytesLengthBuf[1];
122
- const ciphertextBytes = reader.readBytes(ciphertextBytesLength);
123
- const plaintextBytes = await aes128Decrypt(ciphertextBytes, iv, symKey);
124
- return new EncryptedLogPayload(tag, contractAddress, plaintextBytes);
125
- } catch (e) {
126
- // Following error messages are expected to occur when decryption fails
127
- if (!this.isAcceptableError(e)) {
128
- // If we encounter an unexpected error, we rethrow it
129
- throw e;
130
- }
131
- return;
132
- }
133
- }
134
- static isAcceptableError(e) {
135
- return e instanceof NotOnCurveError || e.message.endsWith('is greater or equal to field modulus.') || e.message.startsWith('Invalid AztecAddress length') || e.message.startsWith('Selector must fit in') || e.message.startsWith('Attempted to read beyond buffer length') || e.message.startsWith('RangeError [ERR_BUFFER_OUT_OF_BOUNDS]:');
136
- }
137
- toBuffer() {
138
- return serializeToBuffer(this.tag, this.contractAddress.toBuffer(), this.incomingBodyPlaintext);
139
- }
140
- }
@@ -1,24 +0,0 @@
1
- /// <reference types="node" resolution-mode="require"/>
2
- /// <reference types="node" resolution-mode="require"/>
3
- import type { Point } from '@aztec/foundation/fields';
4
- export declare function deriveAesSymmetricKeyAndIvFromEcdhSharedSecretUsingSha256(sharedSecret: Point): [Buffer, Buffer];
5
- /**
6
- * Encrypts the plaintext using the secret key and public key
7
- *
8
- * @param plaintext - The plaintext buffer
9
- * @param secret - The secret key used to derive the AES secret
10
- * @param publicKey - Public key used to derived the AES secret
11
- * @param deriveSecret - Function to derive the AES secret from the ephemeral secret key and public key
12
- * @returns The ciphertext
13
- */
14
- export declare function aes128Encrypt(plaintext: Buffer, iv: Buffer, symKey: Buffer): Promise<Buffer>;
15
- /**
16
- * Decrypts the ciphertext using the secret key and public key
17
- * @param ciphertext - The ciphertext buffer
18
- * @param secret - The secret key used to derive the AES secret
19
- * @param publicKey - The public key used to derive the AES secret
20
- * @param deriveSecret - Function to derive the AES secret from the ephemeral secret key and public key
21
- * @returns
22
- */
23
- export declare function aes128Decrypt(ciphertext: Buffer, iv: Buffer, symKey: Buffer): Promise<Buffer>;
24
- //# sourceMappingURL=encryption_util.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"encryption_util.d.ts","sourceRoot":"","sources":["../../../src/logs/l1_payload/encryption_util.ts"],"names":[],"mappings":";;AAEA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,0BAA0B,CAAC;AAmBtD,wBAAgB,yDAAyD,CAAC,YAAY,EAAE,KAAK,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAK/G;AAED;;;;;;;;GAQG;AACH,wBAAgB,aAAa,CAAC,SAAS,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAG5F;AAED;;;;;;;GAOG;AACH,wBAAgB,aAAa,CAAC,UAAU,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAG7F"}
@@ -1,46 +0,0 @@
1
- import { GeneratorIndex } from '@aztec/constants';
2
- import { Aes128, sha256 } from '@aztec/foundation/crypto';
3
- import { numToUInt8 } from '@aztec/foundation/serialize';
4
- function extractCloseToUniformlyRandom256BitsFromEcdhSharedSecretUsingSha256(sharedSecret) {
5
- const secretBuffer = Buffer.concat([
6
- sharedSecret.toCompressedBuffer(),
7
- numToUInt8(GeneratorIndex.SYMMETRIC_KEY)
8
- ]);
9
- const hash = sha256(secretBuffer);
10
- return hash;
11
- }
12
- function deriveAesSymmetricKeyAndIvFromEcdhSharedSecret(sharedSecret, randomnessExtractionFunction) {
13
- const random256Bits = randomnessExtractionFunction(sharedSecret);
14
- const symKey = random256Bits.subarray(0, 16);
15
- const iv = random256Bits.subarray(16, 32);
16
- return [
17
- symKey,
18
- iv
19
- ];
20
- }
21
- export function deriveAesSymmetricKeyAndIvFromEcdhSharedSecretUsingSha256(sharedSecret) {
22
- return deriveAesSymmetricKeyAndIvFromEcdhSharedSecret(sharedSecret, extractCloseToUniformlyRandom256BitsFromEcdhSharedSecretUsingSha256);
23
- }
24
- /**
25
- * Encrypts the plaintext using the secret key and public key
26
- *
27
- * @param plaintext - The plaintext buffer
28
- * @param secret - The secret key used to derive the AES secret
29
- * @param publicKey - Public key used to derived the AES secret
30
- * @param deriveSecret - Function to derive the AES secret from the ephemeral secret key and public key
31
- * @returns The ciphertext
32
- */ export function aes128Encrypt(plaintext, iv, symKey) {
33
- const aes128 = new Aes128();
34
- return aes128.encryptBufferCBC(plaintext, iv, symKey);
35
- }
36
- /**
37
- * Decrypts the ciphertext using the secret key and public key
38
- * @param ciphertext - The ciphertext buffer
39
- * @param secret - The secret key used to derive the AES secret
40
- * @param publicKey - The public key used to derive the AES secret
41
- * @param deriveSecret - Function to derive the AES secret from the ephemeral secret key and public key
42
- * @returns
43
- */ export function aes128Decrypt(ciphertext, iv, symKey) {
44
- const aes128 = new Aes128();
45
- return aes128.decryptBufferCBC(ciphertext, iv, symKey);
46
- }
@@ -1,3 +0,0 @@
1
- export * from './encrypted_log_payload.js';
2
- export * from './shared_secret_derivation.js';
3
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/logs/l1_payload/index.ts"],"names":[],"mappings":"AAAA,cAAc,4BAA4B,CAAC;AAC3C,cAAc,+BAA+B,CAAC"}
@@ -1,2 +0,0 @@
1
- export * from './encrypted_log_payload.js';
2
- export * from './shared_secret_derivation.js';
@@ -1,60 +0,0 @@
1
- /// <reference types="node" resolution-mode="require"/>
2
- /// <reference types="node" resolution-mode="require"/>
3
- import { Fr } from '@aztec/foundation/fields';
4
- import { BufferReader } from '@aztec/foundation/serialize';
5
- import { Vector } from '../../types/index.js';
6
- /**
7
- * The Note class represents a Note emitted from a Noir contract as a vector of Fr (finite field) elements.
8
- * This data also represents a preimage to a note hash. This class extends the Vector class, which allows for
9
- * additional operations on the underlying field elements.
10
- */
11
- export declare class Payload extends Vector<Fr> {
12
- toJSON(): Buffer;
13
- static get schema(): import("zod").ZodEffects<import("zod").ZodUnion<[import("zod").ZodEffects<import("zod").ZodEffects<import("zod").ZodString, string, string>, Buffer, string>, import("zod").ZodEffects<import("zod").ZodObject<{
14
- type: import("zod").ZodLiteral<"Buffer">;
15
- data: import("zod").ZodArray<import("zod").ZodNumber, "many">;
16
- }, "strip", import("zod").ZodTypeAny, {
17
- type: "Buffer";
18
- data: number[];
19
- }, {
20
- type: "Buffer";
21
- data: number[];
22
- }>, Buffer, {
23
- type: "Buffer";
24
- data: number[];
25
- }>]>, Payload, string | {
26
- type: "Buffer";
27
- data: number[];
28
- }>;
29
- /**
30
- * Create a Note instance from a Buffer or BufferReader.
31
- * The input 'buffer' can be either a Buffer containing the serialized Fr elements or a BufferReader instance.
32
- * This function reads the Fr elements in the buffer and constructs a Note with them.
33
- *
34
- * @param buffer - The Buffer or BufferReader containing the serialized Fr elements.
35
- * @returns A Note instance containing the deserialized Fr elements.
36
- */
37
- static fromBuffer(buffer: Buffer | BufferReader): Payload;
38
- /**
39
- * Generates a random Note instance with a variable number of items.
40
- * The number of items is determined by a random value between 1 and 10 (inclusive).
41
- * Each item in the Note is generated using the Fr.random() method.
42
- *
43
- * @returns A randomly generated Note instance.
44
- */
45
- static random(): Payload;
46
- /**
47
- * Returns a hex representation of the note.
48
- * @returns A hex string with the vector length as first element.
49
- */
50
- toString(): `0x${string}`;
51
- /**
52
- * Creates a new Note instance from a hex string.
53
- * @param str - Hex representation.
54
- * @returns A Note instance.
55
- */
56
- static fromString(str: string): Payload;
57
- get length(): number;
58
- equals(other: Payload): boolean;
59
- }
60
- //# sourceMappingURL=payload.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"payload.d.ts","sourceRoot":"","sources":["../../../src/logs/l1_payload/payload.ts"],"names":[],"mappings":";;AACA,OAAO,EAAE,EAAE,EAAE,MAAM,0BAA0B,CAAC;AAC9C,OAAO,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAI3D,OAAO,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAC;AAE9C;;;;GAIG;AACH,qBAAa,OAAQ,SAAQ,MAAM,CAAC,EAAE,CAAC;IACrC,MAAM;IAIN,MAAM,KAAK,MAAM;;;;;;;;;;;;;;;OAEhB;IAED;;;;;;;OAOG;IACH,MAAM,CAAC,UAAU,CAAC,MAAM,EAAE,MAAM,GAAG,YAAY;IAK/C;;;;;;OAMG;IACH,MAAM,CAAC,MAAM;IAMb;;;OAGG;IACM,QAAQ;IAIjB;;;;OAIG;IACH,MAAM,CAAC,UAAU,CAAC,GAAG,EAAE,MAAM;IAI7B,IAAI,MAAM,WAET;IAED,MAAM,CAAC,KAAK,EAAE,OAAO;CAGtB"}
@@ -1,61 +0,0 @@
1
- import { randomInt } from '@aztec/foundation/crypto';
2
- import { Fr } from '@aztec/foundation/fields';
3
- import { BufferReader } from '@aztec/foundation/serialize';
4
- import { bufferToHex, hexToBuffer } from '@aztec/foundation/string';
5
- import { schemas } from '../../schemas/index.js';
6
- import { Vector } from '../../types/index.js';
7
- /**
8
- * The Note class represents a Note emitted from a Noir contract as a vector of Fr (finite field) elements.
9
- * This data also represents a preimage to a note hash. This class extends the Vector class, which allows for
10
- * additional operations on the underlying field elements.
11
- */ export class Payload extends Vector {
12
- toJSON() {
13
- return this.toBuffer();
14
- }
15
- static get schema() {
16
- return schemas.Buffer.transform(Payload.fromBuffer);
17
- }
18
- /**
19
- * Create a Note instance from a Buffer or BufferReader.
20
- * The input 'buffer' can be either a Buffer containing the serialized Fr elements or a BufferReader instance.
21
- * This function reads the Fr elements in the buffer and constructs a Note with them.
22
- *
23
- * @param buffer - The Buffer or BufferReader containing the serialized Fr elements.
24
- * @returns A Note instance containing the deserialized Fr elements.
25
- */ static fromBuffer(buffer) {
26
- const reader = BufferReader.asReader(buffer);
27
- return new Payload(reader.readVector(Fr));
28
- }
29
- /**
30
- * Generates a random Note instance with a variable number of items.
31
- * The number of items is determined by a random value between 1 and 10 (inclusive).
32
- * Each item in the Note is generated using the Fr.random() method.
33
- *
34
- * @returns A randomly generated Note instance.
35
- */ static random() {
36
- const numItems = randomInt(10) + 1;
37
- const items = Array.from({
38
- length: numItems
39
- }, ()=>Fr.random());
40
- return new Payload(items);
41
- }
42
- /**
43
- * Returns a hex representation of the note.
44
- * @returns A hex string with the vector length as first element.
45
- */ toString() {
46
- return bufferToHex(this.toBuffer());
47
- }
48
- /**
49
- * Creates a new Note instance from a hex string.
50
- * @param str - Hex representation.
51
- * @returns A Note instance.
52
- */ static fromString(str) {
53
- return Payload.fromBuffer(hexToBuffer(str));
54
- }
55
- get length() {
56
- return this.items.length;
57
- }
58
- equals(other) {
59
- return this.items.every((item, index)=>item.equals(other.items[index]));
60
- }
61
- }
@@ -1 +0,0 @@
1
- {"version":3,"file":"shared_secret_derivation.d.ts","sourceRoot":"","sources":["../../../src/logs/l1_payload/shared_secret_derivation.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,cAAc,EAAE,KAAK,EAAE,MAAM,0BAA0B,CAAC;AAEtE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,8BAA8B,CAAC;AACjE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAC;AAE1D;;;;;;;;;GASG;AACH,wBAAsB,sBAAsB,CAAC,SAAS,EAAE,cAAc,EAAE,SAAS,EAAE,SAAS,GAAG,OAAO,CAAC,KAAK,CAAC,CAS5G;AAED,wBAAsB,uCAAuC,CAC3D,SAAS,EAAE,cAAc,EACzB,OAAO,EAAE,YAAY,GACpB,OAAO,CAAC,KAAK,CAAC,CAIhB"}
@@ -1,16 +0,0 @@
1
- import { Fr } from '@aztec/foundation/fields';
2
- import { BufferReader } from '@aztec/foundation/serialize';
3
-
4
- import { Payload } from '../logs/l1_payload/payload.js';
5
- import { schemas } from '../schemas/schemas.js';
6
-
7
- export class Event extends Payload {
8
- static override get schema() {
9
- return schemas.Buffer.transform(Event.fromBuffer);
10
- }
11
-
12
- static override fromBuffer(buffer: Buffer | BufferReader) {
13
- const reader = BufferReader.asReader(buffer);
14
- return new Event(reader.readVector(Fr));
15
- }
16
- }
@@ -1,56 +0,0 @@
1
- import { z } from 'zod';
2
-
3
- import { type AbiType, AbiTypeSchema } from '../abi/abi.js';
4
- import { decodeFromAbi } from '../abi/decoder.js';
5
- import type { EventSelector } from '../abi/event_selector.js';
6
- import type { PublicLog } from '../logs/public_log.js';
7
- import { schemas } from '../schemas/index.js';
8
- import { L1EventPayload } from './l1_event_payload.js';
9
-
10
- /**
11
- * Represents metadata for an event decoder, including all information needed to reconstruct it.
12
- */
13
- export class EventMetadata<T> {
14
- public readonly decode: (payload: L1EventPayload | PublicLog) => T | undefined;
15
-
16
- public readonly eventSelector: EventSelector;
17
- public readonly abiType: AbiType;
18
- public readonly fieldNames: string[];
19
-
20
- constructor(event: { eventSelector: EventSelector; abiType: AbiType; fieldNames: string[] }) {
21
- this.eventSelector = event.eventSelector;
22
- this.abiType = event.abiType;
23
- this.fieldNames = event.fieldNames;
24
- this.decode = EventMetadata.decodeEvent<T>(event.eventSelector, event.abiType);
25
- }
26
-
27
- public static decodeEvent<T>(
28
- eventSelector: EventSelector,
29
- abiType: AbiType,
30
- ): (payload: L1EventPayload | PublicLog | undefined) => T | undefined {
31
- return (payload: L1EventPayload | PublicLog | undefined): T | undefined => {
32
- if (payload === undefined) {
33
- return undefined;
34
- }
35
-
36
- if (payload instanceof L1EventPayload) {
37
- if (!eventSelector.equals(payload.eventTypeId)) {
38
- return undefined;
39
- }
40
- return decodeFromAbi([abiType], payload.event.items) as T;
41
- } else {
42
- return decodeFromAbi([abiType], payload.log) as T;
43
- }
44
- };
45
- }
46
-
47
- static get schema() {
48
- return z
49
- .object({
50
- eventSelector: schemas.EventSelector,
51
- abiType: AbiTypeSchema,
52
- fieldNames: z.array(z.string()),
53
- })
54
- .transform(obj => new EventMetadata(obj));
55
- }
56
- }
@@ -1,3 +0,0 @@
1
- export * from './event.js';
2
- export * from './event_metadata.js';
3
- export * from './l1_event_payload.js';
@@ -1,87 +0,0 @@
1
- import { type Fq, Fr } from '@aztec/foundation/fields';
2
- import { BufferReader, serializeToBuffer } from '@aztec/foundation/serialize';
3
-
4
- import { EventSelector } from '../abi/event_selector.js';
5
- import { AztecAddress } from '../aztec-address/index.js';
6
- import { EncryptedLogPayload } from '../logs/l1_payload/encrypted_log_payload.js';
7
- import type { PrivateLog } from '../logs/private_log.js';
8
- import { Event } from './event.js';
9
-
10
- /**
11
- * A class which wraps event data which is pushed on L1.
12
- */
13
- export class L1EventPayload {
14
- constructor(
15
- /**
16
- * A event as emitted from Noir contract. Can be used along with private key to compute nullifier.
17
- */
18
- public event: Event,
19
- /**
20
- * Address of the contract this tx is interacting with.
21
- */
22
- public contractAddress: AztecAddress,
23
- /**
24
- * Type identifier for the underlying event, required to determine how to compute its hash and nullifier.
25
- */
26
- public eventTypeId: EventSelector,
27
- ) {}
28
-
29
- static #fromIncomingBodyPlaintextAndContractAddress(
30
- plaintext: Buffer,
31
- contractAddress: AztecAddress,
32
- ): L1EventPayload | undefined {
33
- let payload: L1EventPayload;
34
- try {
35
- const reader = BufferReader.asReader(plaintext);
36
- const fields = reader.readArray(plaintext.length / Fr.SIZE_IN_BYTES, Fr);
37
-
38
- const eventTypeId = EventSelector.fromField(fields[0]);
39
-
40
- const event = new Event(fields.slice(1));
41
-
42
- payload = new L1EventPayload(event, contractAddress, eventTypeId);
43
- } catch (e) {
44
- return undefined;
45
- }
46
-
47
- return payload;
48
- }
49
-
50
- static async decryptAsIncoming(log: PrivateLog, sk: Fq): Promise<L1EventPayload | undefined> {
51
- const decryptedLog = await EncryptedLogPayload.decryptAsIncoming(log.fields, sk);
52
- if (!decryptedLog) {
53
- return undefined;
54
- }
55
-
56
- return this.#fromIncomingBodyPlaintextAndContractAddress(
57
- decryptedLog.incomingBodyPlaintext,
58
- decryptedLog.contractAddress,
59
- );
60
- }
61
-
62
- /**
63
- * Serializes the L1EventPayload object into a Buffer.
64
- * @returns Buffer representation of the L1EventPayload object.
65
- */
66
- toIncomingBodyPlaintext() {
67
- const fields = [this.eventTypeId.toField(), ...this.event.items];
68
- return serializeToBuffer(fields);
69
- }
70
-
71
- /**
72
- * Create a random L1EventPayload object (useful for testing purposes).
73
- * @param contract - The address of a contract the event was emitted from.
74
- * @returns A random L1EventPayload object.
75
- */
76
- static async random(contract?: AztecAddress) {
77
- return new L1EventPayload(Event.random(), contract ?? (await AztecAddress.random()), EventSelector.random());
78
- }
79
-
80
- public equals(other: L1EventPayload) {
81
- return (
82
- this.event.equals(other.event) &&
83
- this.contractAddress.equals(other.contractAddress) &&
84
- this.eventTypeId.equals(other.eventTypeId)
85
- );
86
- }
87
- }