@aztec/stdlib 0.85.0-alpha-testnet.4 → 0.85.0-alpha-testnet.5
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/block/published_l2_block.d.ts +2 -1
- package/dest/block/published_l2_block.d.ts.map +1 -1
- package/dest/block/published_l2_block.js +5 -18
- package/dest/tests/mocks.d.ts +4 -0
- package/dest/tests/mocks.d.ts.map +1 -1
- package/dest/tests/mocks.js +23 -0
- package/package.json +7 -7
- package/src/block/published_l2_block.ts +6 -16
- package/src/tests/mocks.ts +29 -0
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Signature } from '@aztec/foundation/eth-signature';
|
|
2
2
|
import { L2Block } from '@aztec/stdlib/block';
|
|
3
3
|
import { z } from 'zod';
|
|
4
|
+
import { BlockAttestation } from '../p2p/block_attestation.js';
|
|
4
5
|
export type L1PublishedData = {
|
|
5
6
|
blockNumber: bigint;
|
|
6
7
|
timestamp: bigint;
|
|
@@ -85,5 +86,5 @@ export declare const PublishedL2BlockSchema: z.ZodObject<{
|
|
|
85
86
|
};
|
|
86
87
|
signatures: string[];
|
|
87
88
|
}>;
|
|
88
|
-
export declare function
|
|
89
|
+
export declare function getAttestationsFromPublishedL2Block(block: PublishedL2Block): BlockAttestation[];
|
|
89
90
|
//# sourceMappingURL=published_l2_block.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"published_l2_block.d.ts","sourceRoot":"","sources":["../../src/block/published_l2_block.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"published_l2_block.d.ts","sourceRoot":"","sources":["../../src/block/published_l2_block.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iCAAiC,CAAC;AAE5D,OAAO,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AAE9C,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,EAAE,gBAAgB,EAAE,MAAM,6BAA6B,CAAC;AAG/D,MAAM,MAAM,eAAe,GAAG;IAC5B,WAAW,EAAE,MAAM,CAAC;IACpB,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;CACnB,CAAC;AAEF,MAAM,MAAM,gBAAgB,GAAG;IAC7B,KAAK,EAAE,OAAO,CAAC;IACf,EAAE,EAAE,eAAe,CAAC;IACpB,UAAU,EAAE,SAAS,EAAE,CAAC;CACzB,CAAC;AAEF,eAAO,MAAM,sBAAsB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAQjC,CAAC;AAEH,wBAAgB,mCAAmC,CAAC,KAAK,EAAE,gBAAgB,sBAG1E"}
|
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
import { Buffer32 } from '@aztec/foundation/buffer';
|
|
2
|
-
import { times } from '@aztec/foundation/collection';
|
|
3
|
-
import { Secp256k1Signer } from '@aztec/foundation/crypto';
|
|
4
1
|
import { Signature } from '@aztec/foundation/eth-signature';
|
|
5
2
|
import { schemas } from '@aztec/foundation/schemas';
|
|
6
3
|
import { L2Block } from '@aztec/stdlib/block';
|
|
7
4
|
import { z } from 'zod';
|
|
5
|
+
import { BlockAttestation } from '../p2p/block_attestation.js';
|
|
6
|
+
import { ConsensusPayload } from '../p2p/consensus_payload.js';
|
|
8
7
|
export const PublishedL2BlockSchema = z.object({
|
|
9
8
|
block: L2Block.schema,
|
|
10
9
|
l1: z.object({
|
|
@@ -14,19 +13,7 @@ export const PublishedL2BlockSchema = z.object({
|
|
|
14
13
|
}),
|
|
15
14
|
signatures: z.array(Signature.schema)
|
|
16
15
|
});
|
|
17
|
-
export
|
|
18
|
-
const
|
|
19
|
-
|
|
20
|
-
blockNumber: BigInt(block.number),
|
|
21
|
-
timestamp: block.header.globalVariables.timestamp.toBigInt(),
|
|
22
|
-
blockHash: Buffer32.random().toString()
|
|
23
|
-
};
|
|
24
|
-
// Create valid signatures
|
|
25
|
-
const signers = times(3, ()=>Secp256k1Signer.random());
|
|
26
|
-
const signatures = await Promise.all(times(3, async (i)=>signers[i].signMessage(Buffer32.fromField(await block.hash()))));
|
|
27
|
-
return {
|
|
28
|
-
block,
|
|
29
|
-
l1,
|
|
30
|
-
signatures
|
|
31
|
-
};
|
|
16
|
+
export function getAttestationsFromPublishedL2Block(block) {
|
|
17
|
+
const payload = ConsensusPayload.fromBlock(block.block);
|
|
18
|
+
return block.signatures.filter((sig)=>!sig.isEmpty).map((signature)=>new BlockAttestation(payload, signature));
|
|
32
19
|
}
|
package/dest/tests/mocks.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ import { Secp256k1Signer } from '@aztec/foundation/crypto';
|
|
|
2
2
|
import { Fr } from '@aztec/foundation/fields';
|
|
3
3
|
import type { ContractArtifact } from '../abi/abi.js';
|
|
4
4
|
import { AztecAddress } from '../aztec-address/index.js';
|
|
5
|
+
import type { PublishedL2Block } from '../block/published_l2_block.js';
|
|
5
6
|
import type { ContractInstanceWithAddress } from '../contract/index.js';
|
|
6
7
|
import { GasFees } from '../gas/gas_fees.js';
|
|
7
8
|
import { ExtendedNote, UniqueNote } from '../note/extended_note.js';
|
|
@@ -46,4 +47,7 @@ export interface MakeConsensusPayloadOptions {
|
|
|
46
47
|
}
|
|
47
48
|
export declare const makeBlockProposal: (options?: MakeConsensusPayloadOptions) => Promise<BlockProposal>;
|
|
48
49
|
export declare const makeBlockAttestation: (options?: MakeConsensusPayloadOptions) => Promise<BlockAttestation>;
|
|
50
|
+
export declare function randomPublishedL2Block(l2BlockNumber: number, opts?: {
|
|
51
|
+
signers?: Secp256k1Signer[];
|
|
52
|
+
}): Promise<PublishedL2Block>;
|
|
49
53
|
//# sourceMappingURL=mocks.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mocks.d.ts","sourceRoot":"","sources":["../../src/tests/mocks.ts"],"names":[],"mappings":"
|
|
1
|
+
{"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2
|
+
import { Buffer32 } from '@aztec/foundation/buffer';
|
|
2
3
|
import { times } from '@aztec/foundation/collection';
|
|
3
4
|
import { Secp256k1Signer, randomBytes } from '@aztec/foundation/crypto';
|
|
4
5
|
import { Fr } from '@aztec/foundation/fields';
|
|
5
6
|
import { AztecAddress } from '../aztec-address/index.js';
|
|
7
|
+
import { L2Block } from '../block/l2_block.js';
|
|
6
8
|
import { computeContractAddressFromInstance } from '../contract/contract_address.js';
|
|
7
9
|
import { getContractClassFromArtifact } from '../contract/contract_class.js';
|
|
8
10
|
import { SerializableContractInstance } from '../contract/contract_instance.js';
|
|
@@ -152,3 +154,24 @@ export const makeBlockAttestation = async (options)=>{
|
|
|
152
154
|
const { payload, signature } = await makeAndSignConsensusPayload(SignatureDomainSeparator.blockAttestation, options);
|
|
153
155
|
return new BlockAttestation(payload, signature);
|
|
154
156
|
};
|
|
157
|
+
export async function randomPublishedL2Block(l2BlockNumber, opts = {}) {
|
|
158
|
+
const block = await L2Block.random(l2BlockNumber);
|
|
159
|
+
const l1 = {
|
|
160
|
+
blockNumber: BigInt(block.number),
|
|
161
|
+
timestamp: block.header.globalVariables.timestamp.toBigInt(),
|
|
162
|
+
blockHash: Buffer32.random().toString()
|
|
163
|
+
};
|
|
164
|
+
const signers = opts.signers ?? times(3, ()=>Secp256k1Signer.random());
|
|
165
|
+
const attestations = await Promise.all(signers.map((signer)=>makeBlockAttestation({
|
|
166
|
+
signer,
|
|
167
|
+
header: block.header,
|
|
168
|
+
archive: block.archive.root,
|
|
169
|
+
txHashes: block.body.txEffects.map((tx)=>tx.txHash)
|
|
170
|
+
})));
|
|
171
|
+
const signatures = attestations.map((attestation)=>attestation.signature);
|
|
172
|
+
return {
|
|
173
|
+
block,
|
|
174
|
+
l1,
|
|
175
|
+
signatures
|
|
176
|
+
};
|
|
177
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aztec/stdlib",
|
|
3
|
-
"version": "0.85.0-alpha-testnet.
|
|
3
|
+
"version": "0.85.0-alpha-testnet.5",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"inherits": [
|
|
6
6
|
"../package.common.json",
|
|
@@ -68,12 +68,12 @@
|
|
|
68
68
|
"test": "NODE_NO_WARNINGS=1 node --experimental-vm-modules ../node_modules/.bin/jest --passWithNoTests --maxWorkers=${JEST_MAX_WORKERS:-8}"
|
|
69
69
|
},
|
|
70
70
|
"dependencies": {
|
|
71
|
-
"@aztec/bb.js": "0.85.0-alpha-testnet.
|
|
72
|
-
"@aztec/blob-lib": "0.85.0-alpha-testnet.
|
|
73
|
-
"@aztec/constants": "0.85.0-alpha-testnet.
|
|
74
|
-
"@aztec/ethereum": "0.85.0-alpha-testnet.
|
|
75
|
-
"@aztec/foundation": "0.85.0-alpha-testnet.
|
|
76
|
-
"@aztec/noir-noirc_abi": "0.85.0-alpha-testnet.
|
|
71
|
+
"@aztec/bb.js": "0.85.0-alpha-testnet.5",
|
|
72
|
+
"@aztec/blob-lib": "0.85.0-alpha-testnet.5",
|
|
73
|
+
"@aztec/constants": "0.85.0-alpha-testnet.5",
|
|
74
|
+
"@aztec/ethereum": "0.85.0-alpha-testnet.5",
|
|
75
|
+
"@aztec/foundation": "0.85.0-alpha-testnet.5",
|
|
76
|
+
"@aztec/noir-noirc_abi": "0.85.0-alpha-testnet.5",
|
|
77
77
|
"@google-cloud/storage": "^7.15.0",
|
|
78
78
|
"lodash.chunk": "^4.2.0",
|
|
79
79
|
"lodash.isequal": "^4.5.0",
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import { Buffer32 } from '@aztec/foundation/buffer';
|
|
2
|
-
import { times } from '@aztec/foundation/collection';
|
|
3
|
-
import { Secp256k1Signer } from '@aztec/foundation/crypto';
|
|
4
1
|
import { Signature } from '@aztec/foundation/eth-signature';
|
|
5
2
|
import { schemas } from '@aztec/foundation/schemas';
|
|
6
3
|
import { L2Block } from '@aztec/stdlib/block';
|
|
7
4
|
|
|
8
5
|
import { z } from 'zod';
|
|
9
6
|
|
|
7
|
+
import { BlockAttestation } from '../p2p/block_attestation.js';
|
|
8
|
+
import { ConsensusPayload } from '../p2p/consensus_payload.js';
|
|
9
|
+
|
|
10
10
|
export type L1PublishedData = {
|
|
11
11
|
blockNumber: bigint;
|
|
12
12
|
timestamp: bigint;
|
|
@@ -29,17 +29,7 @@ export const PublishedL2BlockSchema = z.object({
|
|
|
29
29
|
signatures: z.array(Signature.schema),
|
|
30
30
|
});
|
|
31
31
|
|
|
32
|
-
export
|
|
33
|
-
const
|
|
34
|
-
|
|
35
|
-
blockNumber: BigInt(block.number),
|
|
36
|
-
timestamp: block.header.globalVariables.timestamp.toBigInt(),
|
|
37
|
-
blockHash: Buffer32.random().toString(),
|
|
38
|
-
};
|
|
39
|
-
// Create valid signatures
|
|
40
|
-
const signers = times(3, () => Secp256k1Signer.random());
|
|
41
|
-
const signatures = await Promise.all(
|
|
42
|
-
times(3, async i => signers[i].signMessage(Buffer32.fromField(await block.hash()))),
|
|
43
|
-
);
|
|
44
|
-
return { block, l1, signatures };
|
|
32
|
+
export function getAttestationsFromPublishedL2Block(block: PublishedL2Block) {
|
|
33
|
+
const payload = ConsensusPayload.fromBlock(block.block);
|
|
34
|
+
return block.signatures.filter(sig => !sig.isEmpty).map(signature => new BlockAttestation(payload, signature));
|
|
45
35
|
}
|
package/src/tests/mocks.ts
CHANGED
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
import { MAX_ENQUEUED_CALLS_PER_TX } from '@aztec/constants';
|
|
2
|
+
import { Buffer32 } from '@aztec/foundation/buffer';
|
|
2
3
|
import { times } from '@aztec/foundation/collection';
|
|
3
4
|
import { Secp256k1Signer, randomBytes } from '@aztec/foundation/crypto';
|
|
4
5
|
import { Fr } from '@aztec/foundation/fields';
|
|
5
6
|
|
|
6
7
|
import type { ContractArtifact } from '../abi/abi.js';
|
|
7
8
|
import { AztecAddress } from '../aztec-address/index.js';
|
|
9
|
+
import { L2Block } from '../block/l2_block.js';
|
|
10
|
+
import type { PublishedL2Block } from '../block/published_l2_block.js';
|
|
8
11
|
import { computeContractAddressFromInstance } from '../contract/contract_address.js';
|
|
9
12
|
import { getContractClassFromArtifact } from '../contract/contract_class.js';
|
|
10
13
|
import { SerializableContractInstance } from '../contract/contract_instance.js';
|
|
@@ -266,3 +269,29 @@ export const makeBlockAttestation = async (options?: MakeConsensusPayloadOptions
|
|
|
266
269
|
const { payload, signature } = await makeAndSignConsensusPayload(SignatureDomainSeparator.blockAttestation, options);
|
|
267
270
|
return new BlockAttestation(payload, signature);
|
|
268
271
|
};
|
|
272
|
+
|
|
273
|
+
export async function randomPublishedL2Block(
|
|
274
|
+
l2BlockNumber: number,
|
|
275
|
+
opts: { signers?: Secp256k1Signer[] } = {},
|
|
276
|
+
): Promise<PublishedL2Block> {
|
|
277
|
+
const block = await L2Block.random(l2BlockNumber);
|
|
278
|
+
const l1 = {
|
|
279
|
+
blockNumber: BigInt(block.number),
|
|
280
|
+
timestamp: block.header.globalVariables.timestamp.toBigInt(),
|
|
281
|
+
blockHash: Buffer32.random().toString(),
|
|
282
|
+
};
|
|
283
|
+
|
|
284
|
+
const signers = opts.signers ?? times(3, () => Secp256k1Signer.random());
|
|
285
|
+
const attestations = await Promise.all(
|
|
286
|
+
signers.map(signer =>
|
|
287
|
+
makeBlockAttestation({
|
|
288
|
+
signer,
|
|
289
|
+
header: block.header,
|
|
290
|
+
archive: block.archive.root,
|
|
291
|
+
txHashes: block.body.txEffects.map(tx => tx.txHash),
|
|
292
|
+
}),
|
|
293
|
+
),
|
|
294
|
+
);
|
|
295
|
+
const signatures = attestations.map(attestation => attestation.signature);
|
|
296
|
+
return { block, l1, signatures };
|
|
297
|
+
}
|