@aztec/stdlib 0.82.2 → 0.82.3-nightly.20250403
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.
- package/dest/avm/avm.d.ts +4648 -1474
- package/dest/avm/avm.d.ts.map +1 -1
- package/dest/avm/avm.js +182 -109
- package/dest/avm/avm_proving_request.d.ts +1867 -498
- package/dest/avm/avm_proving_request.d.ts.map +1 -1
- package/dest/block/l2_block_downloader/l2_block_stream.d.ts +10 -12
- package/dest/block/l2_block_downloader/l2_block_stream.d.ts.map +1 -1
- package/dest/block/l2_block_downloader/l2_block_stream.js +45 -11
- package/dest/config/config.d.ts +2 -2
- package/dest/config/config.d.ts.map +1 -1
- package/dest/config/config.js +4 -5
- package/dest/contract/interfaces/node-info.d.ts +2 -2
- package/dest/contract/interfaces/node-info.d.ts.map +1 -1
- package/dest/contract/interfaces/node-info.js +1 -1
- package/dest/database-version/version_manager.d.ts +4 -2
- package/dest/database-version/version_manager.d.ts.map +1 -1
- package/dest/database-version/version_manager.js +13 -9
- package/dest/epoch-helpers/index.d.ts +2 -0
- package/dest/epoch-helpers/index.d.ts.map +1 -1
- package/dest/epoch-helpers/index.js +3 -0
- package/dest/file-store/factory.d.ts +7 -0
- package/dest/file-store/factory.d.ts.map +1 -0
- package/dest/file-store/factory.js +46 -0
- package/dest/file-store/gcs.d.ts +22 -0
- package/dest/file-store/gcs.d.ts.map +1 -0
- package/dest/file-store/gcs.js +115 -0
- package/dest/file-store/http.d.ts +15 -0
- package/dest/file-store/http.d.ts.map +1 -0
- package/dest/file-store/http.js +53 -0
- package/dest/file-store/index.d.ts +3 -0
- package/dest/file-store/index.d.ts.map +1 -0
- package/dest/file-store/index.js +2 -0
- package/dest/file-store/interface.d.ts +24 -0
- package/dest/file-store/interface.d.ts.map +1 -0
- package/dest/file-store/interface.js +1 -0
- package/dest/file-store/local.d.ts +16 -0
- package/dest/file-store/local.d.ts.map +1 -0
- package/dest/file-store/local.js +40 -0
- package/dest/interfaces/aztec-node-admin.d.ts +9 -1
- package/dest/interfaces/aztec-node-admin.d.ts.map +1 -1
- package/dest/interfaces/aztec-node-admin.js +2 -1
- package/dest/interfaces/aztec-node.d.ts +3 -0
- package/dest/interfaces/aztec-node.d.ts.map +1 -1
- package/dest/interfaces/aztec-node.js +2 -0
- package/dest/interfaces/p2p.d.ts +2 -0
- package/dest/interfaces/p2p.d.ts.map +1 -1
- package/dest/interfaces/p2p.js +2 -1
- package/dest/interfaces/prover-client.d.ts +3 -3
- package/dest/interfaces/prover-client.d.ts.map +1 -1
- package/dest/interfaces/prover-client.js +6 -4
- package/dest/interfaces/prover-node.d.ts +4 -0
- package/dest/interfaces/prover-node.d.ts.map +1 -1
- package/dest/interfaces/prover-node.js +5 -1
- package/dest/interfaces/proving-job.d.ts +1866 -497
- package/dest/interfaces/proving-job.d.ts.map +1 -1
- package/dest/interfaces/pxe.d.ts +7 -6
- package/dest/interfaces/pxe.d.ts.map +1 -1
- package/dest/interfaces/pxe.js +1 -1
- package/dest/interfaces/service.d.ts +3 -0
- package/dest/interfaces/service.d.ts.map +1 -1
- package/dest/interfaces/service.js +7 -0
- package/dest/interfaces/world_state.d.ts +13 -15
- package/dest/interfaces/world_state.d.ts.map +1 -1
- package/dest/keys/derivation.d.ts +1 -1
- package/dest/keys/derivation.d.ts.map +1 -1
- package/dest/keys/derivation.js +10 -2
- package/dest/logs/index.d.ts +2 -1
- package/dest/logs/index.d.ts.map +1 -1
- package/dest/logs/index.js +2 -1
- package/dest/logs/pending_tagged_log.d.ts +17 -0
- package/dest/logs/pending_tagged_log.d.ts.map +1 -0
- package/dest/logs/pending_tagged_log.js +45 -0
- package/dest/logs/{l1_payload/shared_secret_derivation.d.ts → shared_secret_derivation.d.ts} +4 -3
- package/dest/logs/shared_secret_derivation.d.ts.map +1 -0
- package/dest/logs/{l1_payload/shared_secret_derivation.js → shared_secret_derivation.js} +3 -5
- package/dest/logs/tx_scoped_l2_log.d.ts +6 -1
- package/dest/logs/tx_scoped_l2_log.d.ts.map +1 -1
- package/dest/logs/tx_scoped_l2_log.js +12 -4
- package/dest/note/note.d.ts +45 -4
- package/dest/note/note.d.ts.map +1 -1
- package/dest/note/note.js +51 -4
- package/dest/proofs/proof.d.ts.map +1 -1
- package/dest/proofs/proof.js +33 -7
- package/dest/snapshots/download.d.ts +9 -0
- package/dest/snapshots/download.d.ts.map +1 -0
- package/dest/snapshots/download.js +37 -0
- package/dest/snapshots/index.d.ts +4 -0
- package/dest/snapshots/index.d.ts.map +1 -0
- package/dest/snapshots/index.js +3 -0
- package/dest/snapshots/types.d.ts +97 -0
- package/dest/snapshots/types.d.ts.map +1 -0
- package/dest/snapshots/types.js +27 -0
- package/dest/snapshots/upload.d.ts +5 -0
- package/dest/snapshots/upload.d.ts.map +1 -0
- package/dest/snapshots/upload.js +37 -0
- package/dest/tests/factories.d.ts +21 -7
- package/dest/tests/factories.d.ts.map +1 -1
- package/dest/tests/factories.js +78 -30
- package/dest/tests/mocks.d.ts +2 -1
- package/dest/tests/mocks.d.ts.map +1 -1
- package/dest/tests/mocks.js +5 -1
- package/dest/trees/merkle_tree_id.d.ts +8 -0
- package/dest/trees/merkle_tree_id.d.ts.map +1 -1
- package/dest/trees/merkle_tree_id.js +10 -0
- package/dest/trees/nullifier_leaf.d.ts +49 -15
- package/dest/trees/nullifier_leaf.d.ts.map +1 -1
- package/dest/trees/nullifier_leaf.js +45 -22
- package/dest/trees/nullifier_membership_witness.d.ts +34 -18
- package/dest/trees/nullifier_membership_witness.d.ts.map +1 -1
- package/dest/trees/protocol_contract_leaf.d.ts +0 -1
- package/dest/trees/protocol_contract_leaf.d.ts.map +1 -1
- package/dest/trees/protocol_contract_leaf.js +0 -3
- package/dest/trees/public_data_leaf.d.ts +59 -25
- package/dest/trees/public_data_leaf.d.ts.map +1 -1
- package/dest/trees/public_data_leaf.js +41 -30
- package/dest/trees/public_data_witness.d.ts +42 -24
- package/dest/trees/public_data_witness.d.ts.map +1 -1
- package/dest/trees/public_data_witness.js +6 -6
- package/dest/validators/index.d.ts +3 -0
- package/dest/validators/index.d.ts.map +1 -0
- package/dest/validators/index.js +1 -0
- package/dest/validators/schemas.d.ts +342 -0
- package/dest/validators/schemas.d.ts.map +1 -0
- package/dest/validators/schemas.js +40 -0
- package/dest/validators/types.d.ts +39 -0
- package/dest/validators/types.d.ts.map +1 -0
- package/dest/validators/types.js +1 -0
- package/dest/versioning/versioning.d.ts +1 -1
- package/dest/versioning/versioning.d.ts.map +1 -1
- package/dest/versioning/versioning.js +6 -6
- package/package.json +11 -8
- package/src/avm/avm.ts +183 -104
- package/src/block/l2_block_downloader/l2_block_stream.ts +64 -29
- package/src/config/config.ts +6 -6
- package/src/contract/interfaces/node-info.ts +3 -3
- package/src/database-version/version_manager.ts +12 -8
- package/src/epoch-helpers/index.ts +8 -0
- package/src/file-store/factory.ts +61 -0
- package/src/file-store/gcs.ts +121 -0
- package/src/file-store/http.ts +58 -0
- package/src/file-store/index.ts +2 -0
- package/src/file-store/interface.ts +19 -0
- package/src/file-store/local.ts +46 -0
- package/src/interfaces/aztec-node-admin.ts +11 -1
- package/src/interfaces/aztec-node.ts +7 -0
- package/src/interfaces/p2p.ts +4 -0
- package/src/interfaces/prover-client.ts +9 -7
- package/src/interfaces/prover-node.ts +10 -0
- package/src/interfaces/pxe.ts +14 -7
- package/src/interfaces/service.ts +13 -0
- package/src/interfaces/world_state.ts +17 -15
- package/src/keys/derivation.ts +12 -6
- package/src/logs/index.ts +2 -1
- package/src/logs/pending_tagged_log.ts +43 -0
- package/src/logs/{l1_payload/shared_secret_derivation.ts → shared_secret_derivation.ts} +4 -11
- package/src/logs/tx_scoped_l2_log.ts +13 -4
- package/src/note/note.ts +61 -5
- package/src/proofs/proof.ts +39 -5
- package/src/snapshots/download.ts +60 -0
- package/src/snapshots/index.ts +3 -0
- package/src/snapshots/types.ts +58 -0
- package/src/snapshots/upload.ts +55 -0
- package/src/tests/factories.ts +137 -53
- package/src/tests/mocks.ts +7 -0
- package/src/trees/merkle_tree_id.ts +12 -0
- package/src/trees/nullifier_leaf.ts +48 -21
- package/src/trees/protocol_contract_leaf.ts +0 -4
- package/src/trees/public_data_leaf.ts +40 -29
- package/src/trees/public_data_witness.ts +6 -6
- package/src/validators/index.ts +3 -0
- package/src/validators/schemas.ts +53 -0
- package/src/validators/types.ts +37 -0
- package/src/versioning/versioning.ts +8 -14
- package/dest/event/event.d.ts +0 -24
- package/dest/event/event.d.ts.map +0 -1
- package/dest/event/event.js +0 -13
- package/dest/event/event_metadata.d.ts +0 -38
- package/dest/event/event_metadata.d.ts.map +0 -1
- package/dest/event/event_metadata.js +0 -45
- package/dest/event/index.d.ts +0 -4
- package/dest/event/index.d.ts.map +0 -1
- package/dest/event/index.js +0 -3
- package/dest/event/l1_event_payload.d.ts +0 -52
- package/dest/event/l1_event_payload.d.ts.map +0 -1
- package/dest/event/l1_event_payload.js +0 -64
- package/dest/logs/l1_payload/encrypted_log_payload.d.ts +0 -50
- package/dest/logs/l1_payload/encrypted_log_payload.d.ts.map +0 -1
- package/dest/logs/l1_payload/encrypted_log_payload.js +0 -140
- package/dest/logs/l1_payload/encryption_util.d.ts +0 -24
- package/dest/logs/l1_payload/encryption_util.d.ts.map +0 -1
- package/dest/logs/l1_payload/encryption_util.js +0 -46
- package/dest/logs/l1_payload/index.d.ts +0 -3
- package/dest/logs/l1_payload/index.d.ts.map +0 -1
- package/dest/logs/l1_payload/index.js +0 -2
- package/dest/logs/l1_payload/payload.d.ts +0 -60
- package/dest/logs/l1_payload/payload.d.ts.map +0 -1
- package/dest/logs/l1_payload/payload.js +0 -61
- package/dest/logs/l1_payload/shared_secret_derivation.d.ts.map +0 -1
- package/src/event/event.ts +0 -16
- package/src/event/event_metadata.ts +0 -56
- package/src/event/index.ts +0 -3
- package/src/event/l1_event_payload.ts +0 -87
- package/src/logs/l1_payload/encrypted_log_payload.ts +0 -202
- package/src/logs/l1_payload/encryption_util.ts +0 -54
- package/src/logs/l1_payload/index.ts +0 -2
- package/src/logs/l1_payload/payload.ts +0 -73
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { type ZodFor, schemas } from '@aztec/foundation/schemas';
|
|
2
|
+
|
|
3
|
+
import { z } from 'zod';
|
|
4
|
+
|
|
5
|
+
import type { ValidatorStats, ValidatorStatusHistory, ValidatorStatusInSlot, ValidatorsStats } from './types.js';
|
|
6
|
+
|
|
7
|
+
export const ValidatorStatusInSlotSchema = z.enum([
|
|
8
|
+
'block-mined',
|
|
9
|
+
'block-proposed',
|
|
10
|
+
'block-missed',
|
|
11
|
+
'attestation-sent',
|
|
12
|
+
'attestation-missed',
|
|
13
|
+
]) satisfies ZodFor<ValidatorStatusInSlot>;
|
|
14
|
+
|
|
15
|
+
export const ValidatorStatusHistorySchema = z.array(
|
|
16
|
+
z.object({
|
|
17
|
+
slot: schemas.BigInt,
|
|
18
|
+
status: ValidatorStatusInSlotSchema,
|
|
19
|
+
}),
|
|
20
|
+
) satisfies ZodFor<ValidatorStatusHistory>;
|
|
21
|
+
|
|
22
|
+
export const ValidatorStatusHistorySchemaArray = z.array(ValidatorStatusHistorySchema);
|
|
23
|
+
|
|
24
|
+
export const ValidatorStatusHistorySchemaMap = z.record(ValidatorStatusHistorySchemaArray);
|
|
25
|
+
|
|
26
|
+
const ValidatorTimeStatSchema = z.object({
|
|
27
|
+
timestamp: schemas.BigInt,
|
|
28
|
+
slot: schemas.BigInt,
|
|
29
|
+
date: z.string(),
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
const ValidatorFilteredHistorySchema = z.object({
|
|
33
|
+
currentStreak: schemas.Integer,
|
|
34
|
+
rate: z.number(),
|
|
35
|
+
count: schemas.Integer,
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
export const ValidatorStatsSchema = z.object({
|
|
39
|
+
address: schemas.EthAddress,
|
|
40
|
+
lastProposal: ValidatorTimeStatSchema.optional(),
|
|
41
|
+
lastAttestation: ValidatorTimeStatSchema.optional(),
|
|
42
|
+
totalSlots: schemas.Integer,
|
|
43
|
+
missedProposals: ValidatorFilteredHistorySchema,
|
|
44
|
+
missedAttestations: ValidatorFilteredHistorySchema,
|
|
45
|
+
history: ValidatorStatusHistorySchema,
|
|
46
|
+
}) satisfies ZodFor<ValidatorStats>;
|
|
47
|
+
|
|
48
|
+
export const ValidatorsStatsSchema = z.object({
|
|
49
|
+
stats: z.record(ValidatorStatsSchema),
|
|
50
|
+
lastProcessedSlot: schemas.BigInt.optional(),
|
|
51
|
+
initialSlot: schemas.BigInt.optional(),
|
|
52
|
+
slotWindow: schemas.Integer,
|
|
53
|
+
}) satisfies ZodFor<ValidatorsStats>;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type { EthAddress } from '@aztec/foundation/eth-address';
|
|
2
|
+
|
|
3
|
+
export type ValidatorStatusType = 'block' | 'attestation';
|
|
4
|
+
|
|
5
|
+
export type ValidatorStatusInSlot =
|
|
6
|
+
| 'block-mined'
|
|
7
|
+
| 'block-proposed'
|
|
8
|
+
| 'block-missed'
|
|
9
|
+
| 'attestation-sent'
|
|
10
|
+
| 'attestation-missed';
|
|
11
|
+
|
|
12
|
+
export type ValidatorStatusHistory = { slot: bigint; status: ValidatorStatusInSlot }[];
|
|
13
|
+
|
|
14
|
+
export type ValidatorStats = {
|
|
15
|
+
address: EthAddress;
|
|
16
|
+
lastProposal?: { timestamp: bigint; slot: bigint; date: string };
|
|
17
|
+
lastAttestation?: { timestamp: bigint; slot: bigint; date: string };
|
|
18
|
+
totalSlots: number;
|
|
19
|
+
missedProposals: {
|
|
20
|
+
currentStreak: number;
|
|
21
|
+
rate: number;
|
|
22
|
+
count: number;
|
|
23
|
+
};
|
|
24
|
+
missedAttestations: {
|
|
25
|
+
currentStreak: number;
|
|
26
|
+
rate: number;
|
|
27
|
+
count: number;
|
|
28
|
+
};
|
|
29
|
+
history: ValidatorStatusHistory;
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
export type ValidatorsStats = {
|
|
33
|
+
stats: Record<string, ValidatorStats>;
|
|
34
|
+
lastProcessedSlot?: bigint;
|
|
35
|
+
initialSlot?: bigint;
|
|
36
|
+
slotWindow: number;
|
|
37
|
+
};
|
|
@@ -16,7 +16,7 @@ export type ComponentsVersions = {
|
|
|
16
16
|
// Note that we are using the rollup address as identifier in multiple places
|
|
17
17
|
// such as the keystore, we need to change it so we can handle updates.
|
|
18
18
|
l1RollupAddress: EthAddress;
|
|
19
|
-
|
|
19
|
+
rollupVersion: number;
|
|
20
20
|
l2ProtocolContractsTreeRoot: string;
|
|
21
21
|
l2CircuitsVkTreeRoot: string;
|
|
22
22
|
};
|
|
@@ -30,7 +30,7 @@ export function getComponentsVersionsFromConfig(
|
|
|
30
30
|
return {
|
|
31
31
|
l1ChainId: config.l1ChainId,
|
|
32
32
|
l1RollupAddress: config.l1Contracts?.rollupAddress, // This should not be undefined, but sometimes the config lies to us and it is...
|
|
33
|
-
|
|
33
|
+
rollupVersion: config.rollupVersion,
|
|
34
34
|
l2ProtocolContractsTreeRoot: l2ProtocolContractsTreeRoot.toString(),
|
|
35
35
|
l2CircuitsVkTreeRoot: l2CircuitsVkTreeRoot.toString(),
|
|
36
36
|
};
|
|
@@ -50,7 +50,7 @@ export function compressComponentVersions(versions: ComponentsVersions): string
|
|
|
50
50
|
'00',
|
|
51
51
|
versions.l1ChainId,
|
|
52
52
|
versions.l1RollupAddress.toString().slice(2, 10),
|
|
53
|
-
versions.
|
|
53
|
+
versions.rollupVersion,
|
|
54
54
|
versions.l2ProtocolContractsTreeRoot.toString().slice(2, 10),
|
|
55
55
|
versions.l2CircuitsVkTreeRoot.toString().slice(2, 10),
|
|
56
56
|
].join('-');
|
|
@@ -65,14 +65,8 @@ export class ComponentsVersionsError extends Error {
|
|
|
65
65
|
|
|
66
66
|
/** Checks if the compressed string matches against the expected versions. Throws on mismatch. */
|
|
67
67
|
export function checkCompressedComponentVersion(compressed: string, expected: ComponentsVersions) {
|
|
68
|
-
const [
|
|
69
|
-
|
|
70
|
-
l1ChainId,
|
|
71
|
-
l1RollupAddress,
|
|
72
|
-
l2ChainVersion,
|
|
73
|
-
l2ProtocolContractsTreeRoot,
|
|
74
|
-
l2CircuitsVkTreeRoot,
|
|
75
|
-
] = compressed.split('-');
|
|
68
|
+
const [versionVersion, l1ChainId, l1RollupAddress, rollupVersion, l2ProtocolContractsTreeRoot, l2CircuitsVkTreeRoot] =
|
|
69
|
+
compressed.split('-');
|
|
76
70
|
if (versionVersion !== '00') {
|
|
77
71
|
throw new ComponentsVersionsError('version', '00', versionVersion);
|
|
78
72
|
}
|
|
@@ -82,8 +76,8 @@ export function checkCompressedComponentVersion(compressed: string, expected: Co
|
|
|
82
76
|
if (l1RollupAddress !== expected.l1RollupAddress.toString().slice(2, 10)) {
|
|
83
77
|
throw new ComponentsVersionsError(`L1 address`, expected.l1RollupAddress.toString(), l1RollupAddress);
|
|
84
78
|
}
|
|
85
|
-
if (
|
|
86
|
-
throw new ComponentsVersionsError('L2 chain version', expected.
|
|
79
|
+
if (rollupVersion !== expected.rollupVersion.toString()) {
|
|
80
|
+
throw new ComponentsVersionsError('L2 chain version', expected.rollupVersion.toString(), rollupVersion);
|
|
87
81
|
}
|
|
88
82
|
if (l2ProtocolContractsTreeRoot !== expected.l2ProtocolContractsTreeRoot.toString().slice(2, 10)) {
|
|
89
83
|
throw new ComponentsVersionsError(
|
|
@@ -111,7 +105,7 @@ export function validatePartialComponentVersionsMatch(
|
|
|
111
105
|
'l2ProtocolContractsTreeRoot',
|
|
112
106
|
'l2CircuitsVkTreeRoot',
|
|
113
107
|
'l1ChainId',
|
|
114
|
-
'
|
|
108
|
+
'rollupVersion',
|
|
115
109
|
] as const) {
|
|
116
110
|
const actualValue = actual[key];
|
|
117
111
|
const expectedValue = expected[key];
|
package/dest/event/event.d.ts
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
/// <reference types="node" resolution-mode="require"/>
|
|
2
|
-
/// <reference types="node" resolution-mode="require"/>
|
|
3
|
-
import { BufferReader } from '@aztec/foundation/serialize';
|
|
4
|
-
import { Payload } from '../logs/l1_payload/payload.js';
|
|
5
|
-
export declare class Event extends Payload {
|
|
6
|
-
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<{
|
|
7
|
-
type: import("zod").ZodLiteral<"Buffer">;
|
|
8
|
-
data: import("zod").ZodArray<import("zod").ZodNumber, "many">;
|
|
9
|
-
}, "strip", import("zod").ZodTypeAny, {
|
|
10
|
-
type: "Buffer";
|
|
11
|
-
data: number[];
|
|
12
|
-
}, {
|
|
13
|
-
type: "Buffer";
|
|
14
|
-
data: number[];
|
|
15
|
-
}>, Buffer, {
|
|
16
|
-
type: "Buffer";
|
|
17
|
-
data: number[];
|
|
18
|
-
}>]>, Event, string | {
|
|
19
|
-
type: "Buffer";
|
|
20
|
-
data: number[];
|
|
21
|
-
}>;
|
|
22
|
-
static fromBuffer(buffer: Buffer | BufferReader): Event;
|
|
23
|
-
}
|
|
24
|
-
//# sourceMappingURL=event.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"event.d.ts","sourceRoot":"","sources":["../../src/event/event.ts"],"names":[],"mappings":";;AACA,OAAO,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAE3D,OAAO,EAAE,OAAO,EAAE,MAAM,+BAA+B,CAAC;AAGxD,qBAAa,KAAM,SAAQ,OAAO;IAChC,WAAoB,MAAM;;;;;;;;;;;;;;;OAEzB;WAEe,UAAU,CAAC,MAAM,EAAE,MAAM,GAAG,YAAY;CAIzD"}
|
package/dest/event/event.js
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { Fr } from '@aztec/foundation/fields';
|
|
2
|
-
import { BufferReader } from '@aztec/foundation/serialize';
|
|
3
|
-
import { Payload } from '../logs/l1_payload/payload.js';
|
|
4
|
-
import { schemas } from '../schemas/schemas.js';
|
|
5
|
-
export class Event extends Payload {
|
|
6
|
-
static get schema() {
|
|
7
|
-
return schemas.Buffer.transform(Event.fromBuffer);
|
|
8
|
-
}
|
|
9
|
-
static fromBuffer(buffer) {
|
|
10
|
-
const reader = BufferReader.asReader(buffer);
|
|
11
|
-
return new Event(reader.readVector(Fr));
|
|
12
|
-
}
|
|
13
|
-
}
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import { z } from 'zod';
|
|
2
|
-
import { type AbiType } from '../abi/abi.js';
|
|
3
|
-
import type { EventSelector } from '../abi/event_selector.js';
|
|
4
|
-
import type { PublicLog } from '../logs/public_log.js';
|
|
5
|
-
import { L1EventPayload } from './l1_event_payload.js';
|
|
6
|
-
/**
|
|
7
|
-
* Represents metadata for an event decoder, including all information needed to reconstruct it.
|
|
8
|
-
*/
|
|
9
|
-
export declare class EventMetadata<T> {
|
|
10
|
-
readonly decode: (payload: L1EventPayload | PublicLog) => T | undefined;
|
|
11
|
-
readonly eventSelector: EventSelector;
|
|
12
|
-
readonly abiType: AbiType;
|
|
13
|
-
readonly fieldNames: string[];
|
|
14
|
-
constructor(event: {
|
|
15
|
-
eventSelector: EventSelector;
|
|
16
|
-
abiType: AbiType;
|
|
17
|
-
fieldNames: string[];
|
|
18
|
-
});
|
|
19
|
-
static decodeEvent<T>(eventSelector: EventSelector, abiType: AbiType): (payload: L1EventPayload | PublicLog | undefined) => T | undefined;
|
|
20
|
-
static get schema(): z.ZodEffects<z.ZodObject<{
|
|
21
|
-
eventSelector: z.ZodType<EventSelector, any, string>;
|
|
22
|
-
abiType: z.ZodType<AbiType, z.ZodTypeDef, AbiType>;
|
|
23
|
-
fieldNames: z.ZodArray<z.ZodString, "many">;
|
|
24
|
-
}, "strip", z.ZodTypeAny, {
|
|
25
|
-
eventSelector: EventSelector;
|
|
26
|
-
abiType: AbiType;
|
|
27
|
-
fieldNames: string[];
|
|
28
|
-
}, {
|
|
29
|
-
eventSelector: string;
|
|
30
|
-
abiType: AbiType;
|
|
31
|
-
fieldNames: string[];
|
|
32
|
-
}>, EventMetadata<unknown>, {
|
|
33
|
-
eventSelector: string;
|
|
34
|
-
abiType: AbiType;
|
|
35
|
-
fieldNames: string[];
|
|
36
|
-
}>;
|
|
37
|
-
}
|
|
38
|
-
//# sourceMappingURL=event_metadata.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"event_metadata.d.ts","sourceRoot":"","sources":["../../src/event/event_metadata.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,EAAE,KAAK,OAAO,EAAiB,MAAM,eAAe,CAAC;AAE5D,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AAC9D,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAEvD,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAEvD;;GAEG;AACH,qBAAa,aAAa,CAAC,CAAC;IAC1B,SAAgB,MAAM,EAAE,CAAC,OAAO,EAAE,cAAc,GAAG,SAAS,KAAK,CAAC,GAAG,SAAS,CAAC;IAE/E,SAAgB,aAAa,EAAE,aAAa,CAAC;IAC7C,SAAgB,OAAO,EAAE,OAAO,CAAC;IACjC,SAAgB,UAAU,EAAE,MAAM,EAAE,CAAC;gBAEzB,KAAK,EAAE;QAAE,aAAa,EAAE,aAAa,CAAC;QAAC,OAAO,EAAE,OAAO,CAAC;QAAC,UAAU,EAAE,MAAM,EAAE,CAAA;KAAE;WAO7E,WAAW,CAAC,CAAC,EACzB,aAAa,EAAE,aAAa,EAC5B,OAAO,EAAE,OAAO,GACf,CAAC,OAAO,EAAE,cAAc,GAAG,SAAS,GAAG,SAAS,KAAK,CAAC,GAAG,SAAS;IAiBrE,MAAM,KAAK,MAAM;;;;;;;;;;;;;;;;OAQhB;CACF"}
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
import { z } from 'zod';
|
|
2
|
-
import { AbiTypeSchema } from '../abi/abi.js';
|
|
3
|
-
import { decodeFromAbi } from '../abi/decoder.js';
|
|
4
|
-
import { schemas } from '../schemas/index.js';
|
|
5
|
-
import { L1EventPayload } from './l1_event_payload.js';
|
|
6
|
-
/**
|
|
7
|
-
* Represents metadata for an event decoder, including all information needed to reconstruct it.
|
|
8
|
-
*/ export class EventMetadata {
|
|
9
|
-
decode;
|
|
10
|
-
eventSelector;
|
|
11
|
-
abiType;
|
|
12
|
-
fieldNames;
|
|
13
|
-
constructor(event){
|
|
14
|
-
this.eventSelector = event.eventSelector;
|
|
15
|
-
this.abiType = event.abiType;
|
|
16
|
-
this.fieldNames = event.fieldNames;
|
|
17
|
-
this.decode = EventMetadata.decodeEvent(event.eventSelector, event.abiType);
|
|
18
|
-
}
|
|
19
|
-
static decodeEvent(eventSelector, abiType) {
|
|
20
|
-
return (payload)=>{
|
|
21
|
-
if (payload === undefined) {
|
|
22
|
-
return undefined;
|
|
23
|
-
}
|
|
24
|
-
if (payload instanceof L1EventPayload) {
|
|
25
|
-
if (!eventSelector.equals(payload.eventTypeId)) {
|
|
26
|
-
return undefined;
|
|
27
|
-
}
|
|
28
|
-
return decodeFromAbi([
|
|
29
|
-
abiType
|
|
30
|
-
], payload.event.items);
|
|
31
|
-
} else {
|
|
32
|
-
return decodeFromAbi([
|
|
33
|
-
abiType
|
|
34
|
-
], payload.log);
|
|
35
|
-
}
|
|
36
|
-
};
|
|
37
|
-
}
|
|
38
|
-
static get schema() {
|
|
39
|
-
return z.object({
|
|
40
|
-
eventSelector: schemas.EventSelector,
|
|
41
|
-
abiType: AbiTypeSchema,
|
|
42
|
-
fieldNames: z.array(z.string())
|
|
43
|
-
}).transform((obj)=>new EventMetadata(obj));
|
|
44
|
-
}
|
|
45
|
-
}
|
package/dest/event/index.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/event/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,qBAAqB,CAAC;AACpC,cAAc,uBAAuB,CAAC"}
|
package/dest/event/index.js
DELETED
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
/// <reference types="node" resolution-mode="require"/>
|
|
2
|
-
/// <reference types="node" resolution-mode="require"/>
|
|
3
|
-
import { type Fq } from '@aztec/foundation/fields';
|
|
4
|
-
import { EventSelector } from '../abi/event_selector.js';
|
|
5
|
-
import { AztecAddress } from '../aztec-address/index.js';
|
|
6
|
-
import type { PrivateLog } from '../logs/private_log.js';
|
|
7
|
-
import { Event } from './event.js';
|
|
8
|
-
/**
|
|
9
|
-
* A class which wraps event data which is pushed on L1.
|
|
10
|
-
*/
|
|
11
|
-
export declare class L1EventPayload {
|
|
12
|
-
#private;
|
|
13
|
-
/**
|
|
14
|
-
* A event as emitted from Noir contract. Can be used along with private key to compute nullifier.
|
|
15
|
-
*/
|
|
16
|
-
event: Event;
|
|
17
|
-
/**
|
|
18
|
-
* Address of the contract this tx is interacting with.
|
|
19
|
-
*/
|
|
20
|
-
contractAddress: AztecAddress;
|
|
21
|
-
/**
|
|
22
|
-
* Type identifier for the underlying event, required to determine how to compute its hash and nullifier.
|
|
23
|
-
*/
|
|
24
|
-
eventTypeId: EventSelector;
|
|
25
|
-
constructor(
|
|
26
|
-
/**
|
|
27
|
-
* A event as emitted from Noir contract. Can be used along with private key to compute nullifier.
|
|
28
|
-
*/
|
|
29
|
-
event: Event,
|
|
30
|
-
/**
|
|
31
|
-
* Address of the contract this tx is interacting with.
|
|
32
|
-
*/
|
|
33
|
-
contractAddress: AztecAddress,
|
|
34
|
-
/**
|
|
35
|
-
* Type identifier for the underlying event, required to determine how to compute its hash and nullifier.
|
|
36
|
-
*/
|
|
37
|
-
eventTypeId: EventSelector);
|
|
38
|
-
static decryptAsIncoming(log: PrivateLog, sk: Fq): Promise<L1EventPayload | undefined>;
|
|
39
|
-
/**
|
|
40
|
-
* Serializes the L1EventPayload object into a Buffer.
|
|
41
|
-
* @returns Buffer representation of the L1EventPayload object.
|
|
42
|
-
*/
|
|
43
|
-
toIncomingBodyPlaintext(): Buffer;
|
|
44
|
-
/**
|
|
45
|
-
* Create a random L1EventPayload object (useful for testing purposes).
|
|
46
|
-
* @param contract - The address of a contract the event was emitted from.
|
|
47
|
-
* @returns A random L1EventPayload object.
|
|
48
|
-
*/
|
|
49
|
-
static random(contract?: AztecAddress): Promise<L1EventPayload>;
|
|
50
|
-
equals(other: L1EventPayload): boolean;
|
|
51
|
-
}
|
|
52
|
-
//# sourceMappingURL=l1_event_payload.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"l1_event_payload.d.ts","sourceRoot":"","sources":["../../src/event/l1_event_payload.ts"],"names":[],"mappings":";;AAAA,OAAO,EAAE,KAAK,EAAE,EAAM,MAAM,0BAA0B,CAAC;AAGvD,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AACzD,OAAO,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AAEzD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AACzD,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AAEnC;;GAEG;AACH,qBAAa,cAAc;;IAEvB;;OAEG;IACI,KAAK,EAAE,KAAK;IACnB;;OAEG;IACI,eAAe,EAAE,YAAY;IACpC;;OAEG;IACI,WAAW,EAAE,aAAa;;IAXjC;;OAEG;IACI,KAAK,EAAE,KAAK;IACnB;;OAEG;IACI,eAAe,EAAE,YAAY;IACpC;;OAEG;IACI,WAAW,EAAE,aAAa;WAwBtB,iBAAiB,CAAC,GAAG,EAAE,UAAU,EAAE,EAAE,EAAE,EAAE,GAAG,OAAO,CAAC,cAAc,GAAG,SAAS,CAAC;IAY5F;;;OAGG;IACH,uBAAuB;IAKvB;;;;OAIG;WACU,MAAM,CAAC,QAAQ,CAAC,EAAE,YAAY;IAIpC,MAAM,CAAC,KAAK,EAAE,cAAc;CAOpC"}
|
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
import { Fr } from '@aztec/foundation/fields';
|
|
2
|
-
import { BufferReader, serializeToBuffer } from '@aztec/foundation/serialize';
|
|
3
|
-
import { EventSelector } from '../abi/event_selector.js';
|
|
4
|
-
import { AztecAddress } from '../aztec-address/index.js';
|
|
5
|
-
import { EncryptedLogPayload } from '../logs/l1_payload/encrypted_log_payload.js';
|
|
6
|
-
import { Event } from './event.js';
|
|
7
|
-
/**
|
|
8
|
-
* A class which wraps event data which is pushed on L1.
|
|
9
|
-
*/ export class L1EventPayload {
|
|
10
|
-
event;
|
|
11
|
-
contractAddress;
|
|
12
|
-
eventTypeId;
|
|
13
|
-
constructor(/**
|
|
14
|
-
* A event as emitted from Noir contract. Can be used along with private key to compute nullifier.
|
|
15
|
-
*/ event, /**
|
|
16
|
-
* Address of the contract this tx is interacting with.
|
|
17
|
-
*/ contractAddress, /**
|
|
18
|
-
* Type identifier for the underlying event, required to determine how to compute its hash and nullifier.
|
|
19
|
-
*/ eventTypeId){
|
|
20
|
-
this.event = event;
|
|
21
|
-
this.contractAddress = contractAddress;
|
|
22
|
-
this.eventTypeId = eventTypeId;
|
|
23
|
-
}
|
|
24
|
-
static #fromIncomingBodyPlaintextAndContractAddress(plaintext, contractAddress) {
|
|
25
|
-
let payload;
|
|
26
|
-
try {
|
|
27
|
-
const reader = BufferReader.asReader(plaintext);
|
|
28
|
-
const fields = reader.readArray(plaintext.length / Fr.SIZE_IN_BYTES, Fr);
|
|
29
|
-
const eventTypeId = EventSelector.fromField(fields[0]);
|
|
30
|
-
const event = new Event(fields.slice(1));
|
|
31
|
-
payload = new L1EventPayload(event, contractAddress, eventTypeId);
|
|
32
|
-
} catch (e) {
|
|
33
|
-
return undefined;
|
|
34
|
-
}
|
|
35
|
-
return payload;
|
|
36
|
-
}
|
|
37
|
-
static async decryptAsIncoming(log, sk) {
|
|
38
|
-
const decryptedLog = await EncryptedLogPayload.decryptAsIncoming(log.fields, sk);
|
|
39
|
-
if (!decryptedLog) {
|
|
40
|
-
return undefined;
|
|
41
|
-
}
|
|
42
|
-
return this.#fromIncomingBodyPlaintextAndContractAddress(decryptedLog.incomingBodyPlaintext, decryptedLog.contractAddress);
|
|
43
|
-
}
|
|
44
|
-
/**
|
|
45
|
-
* Serializes the L1EventPayload object into a Buffer.
|
|
46
|
-
* @returns Buffer representation of the L1EventPayload object.
|
|
47
|
-
*/ toIncomingBodyPlaintext() {
|
|
48
|
-
const fields = [
|
|
49
|
-
this.eventTypeId.toField(),
|
|
50
|
-
...this.event.items
|
|
51
|
-
];
|
|
52
|
-
return serializeToBuffer(fields);
|
|
53
|
-
}
|
|
54
|
-
/**
|
|
55
|
-
* Create a random L1EventPayload object (useful for testing purposes).
|
|
56
|
-
* @param contract - The address of a contract the event was emitted from.
|
|
57
|
-
* @returns A random L1EventPayload object.
|
|
58
|
-
*/ static async random(contract) {
|
|
59
|
-
return new L1EventPayload(Event.random(), contract ?? await AztecAddress.random(), EventSelector.random());
|
|
60
|
-
}
|
|
61
|
-
equals(other) {
|
|
62
|
-
return this.event.equals(other.event) && this.contractAddress.equals(other.contractAddress) && this.eventTypeId.equals(other.eventTypeId);
|
|
63
|
-
}
|
|
64
|
-
}
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
/// <reference types="node" resolution-mode="require"/>
|
|
2
|
-
/// <reference types="node" resolution-mode="require"/>
|
|
3
|
-
import { Fr, type GrumpkinScalar } from '@aztec/foundation/fields';
|
|
4
|
-
import { AztecAddress } from '../../aztec-address/index.js';
|
|
5
|
-
import { PrivateLog } from '../private_log.js';
|
|
6
|
-
/**
|
|
7
|
-
* Encrypted log payload with a tag used for retrieval by clients.
|
|
8
|
-
*/
|
|
9
|
-
export declare class EncryptedLogPayload {
|
|
10
|
-
/**
|
|
11
|
-
* Note discovery tag.
|
|
12
|
-
*/
|
|
13
|
-
readonly tag: Fr;
|
|
14
|
-
/**
|
|
15
|
-
* Address of a contract that emitted the log.
|
|
16
|
-
*/
|
|
17
|
-
readonly contractAddress: AztecAddress;
|
|
18
|
-
/**
|
|
19
|
-
* Decrypted incoming body.
|
|
20
|
-
*/
|
|
21
|
-
readonly incomingBodyPlaintext: Buffer;
|
|
22
|
-
constructor(
|
|
23
|
-
/**
|
|
24
|
-
* Note discovery tag.
|
|
25
|
-
*/
|
|
26
|
-
tag: Fr,
|
|
27
|
-
/**
|
|
28
|
-
* Address of a contract that emitted the log.
|
|
29
|
-
*/
|
|
30
|
-
contractAddress: AztecAddress,
|
|
31
|
-
/**
|
|
32
|
-
* Decrypted incoming body.
|
|
33
|
-
*/
|
|
34
|
-
incomingBodyPlaintext: Buffer);
|
|
35
|
-
generatePayload(ephSk: GrumpkinScalar, recipient: AztecAddress, rand?: (len: number) => Buffer): Promise<PrivateLog>;
|
|
36
|
-
/**
|
|
37
|
-
* Decrypts a ciphertext as an incoming log.
|
|
38
|
-
*
|
|
39
|
-
* This is executable by the recipient of the note, and uses the addressSecret to decrypt the payload.
|
|
40
|
-
*
|
|
41
|
-
* @param payload - The payload for the log
|
|
42
|
-
* @param addressSecret - The address secret, used to decrypt the logs
|
|
43
|
-
* @param ciphertextLength - Optionally supply the ciphertext length (see trimCiphertext())
|
|
44
|
-
* @returns The decrypted log payload
|
|
45
|
-
*/
|
|
46
|
-
static decryptAsIncoming(payload: Fr[], addressSecret: GrumpkinScalar): Promise<EncryptedLogPayload | undefined>;
|
|
47
|
-
private static isAcceptableError;
|
|
48
|
-
toBuffer(): Buffer;
|
|
49
|
-
}
|
|
50
|
-
//# sourceMappingURL=encrypted_log_payload.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"encrypted_log_payload.d.ts","sourceRoot":"","sources":["../../../src/logs/l1_payload/encrypted_log_payload.ts"],"names":[],"mappings":";;AAEA,OAAO,EAAE,EAAE,EAAE,KAAK,cAAc,EAA0B,MAAM,0BAA0B,CAAC;AAG3F,OAAO,EAAE,YAAY,EAAE,MAAM,8BAA8B,CAAC;AAE5D,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAuC/C;;GAEG;AACH,qBAAa,mBAAmB;IAE5B;;OAEG;aACa,GAAG,EAAE,EAAE;IACvB;;OAEG;aACa,eAAe,EAAE,YAAY;IAC7C;;OAEG;aACa,qBAAqB,EAAE,MAAM;;IAX7C;;OAEG;IACa,GAAG,EAAE,EAAE;IACvB;;OAEG;IACa,eAAe,EAAE,YAAY;IAC7C;;OAEG;IACa,qBAAqB,EAAE,MAAM;IAKlC,eAAe,CAC1B,KAAK,EAAE,cAAc,EACrB,SAAS,EAAE,YAAY,EACvB,IAAI,GAAE,CAAC,GAAG,EAAE,MAAM,KAAK,MAAoB,GAC1C,OAAO,CAAC,UAAU,CAAC;IAsDtB;;;;;;;;;OASG;WACiB,iBAAiB,CACnC,OAAO,EAAE,EAAE,EAAE,EACb,aAAa,EAAE,cAAc,GAC5B,OAAO,CAAC,mBAAmB,GAAG,SAAS,CAAC;IAiD3C,OAAO,CAAC,MAAM,CAAC,iBAAiB;IAWzB,QAAQ;CAGhB"}
|
|
@@ -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"}
|