@aztec-labs/standard-contracts 6.0.0-nightly.20260829

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 (87) hide show
  1. package/artifacts/AuthRegistry.d.json.ts +5 -0
  2. package/artifacts/AuthRegistry.json +6588 -0
  3. package/artifacts/HandshakeRegistry.d.json.ts +5 -0
  4. package/artifacts/HandshakeRegistry.json +13319 -0
  5. package/artifacts/MultiCallEntrypoint.d.json.ts +5 -0
  6. package/artifacts/MultiCallEntrypoint.json +4383 -0
  7. package/artifacts/PublicChecks.d.json.ts +5 -0
  8. package/artifacts/PublicChecks.json +3067 -0
  9. package/dest/auth-registry/constants.d.ts +5 -0
  10. package/dest/auth-registry/constants.d.ts.map +1 -0
  11. package/dest/auth-registry/constants.js +7 -0
  12. package/dest/auth-registry/index.d.ts +6 -0
  13. package/dest/auth-registry/index.d.ts.map +1 -0
  14. package/dest/auth-registry/index.js +14 -0
  15. package/dest/auth-registry/lazy.d.ts +7 -0
  16. package/dest/auth-registry/lazy.d.ts.map +1 -0
  17. package/dest/auth-registry/lazy.js +24 -0
  18. package/dest/contract_data.d.ts +63 -0
  19. package/dest/contract_data.d.ts.map +1 -0
  20. package/dest/contract_data.js +105 -0
  21. package/dest/drift.d.ts +54 -0
  22. package/dest/drift.d.ts.map +1 -0
  23. package/dest/drift.js +167 -0
  24. package/dest/handshake-registry/constants.d.ts +11 -0
  25. package/dest/handshake-registry/constants.d.ts.map +1 -0
  26. package/dest/handshake-registry/constants.js +17 -0
  27. package/dest/handshake-registry/index.d.ts +6 -0
  28. package/dest/handshake-registry/index.d.ts.map +1 -0
  29. package/dest/handshake-registry/index.js +14 -0
  30. package/dest/handshake-registry/lazy.d.ts +7 -0
  31. package/dest/handshake-registry/lazy.d.ts.map +1 -0
  32. package/dest/handshake-registry/lazy.js +24 -0
  33. package/dest/index.d.ts +6 -0
  34. package/dest/index.d.ts.map +1 -0
  35. package/dest/index.js +5 -0
  36. package/dest/make_standard_contract.d.ts +9 -0
  37. package/dest/make_standard_contract.d.ts.map +1 -0
  38. package/dest/make_standard_contract.js +40 -0
  39. package/dest/multi-call-entrypoint/constants.d.ts +5 -0
  40. package/dest/multi-call-entrypoint/constants.d.ts.map +1 -0
  41. package/dest/multi-call-entrypoint/constants.js +7 -0
  42. package/dest/multi-call-entrypoint/index.d.ts +6 -0
  43. package/dest/multi-call-entrypoint/index.d.ts.map +1 -0
  44. package/dest/multi-call-entrypoint/index.js +14 -0
  45. package/dest/multi-call-entrypoint/lazy.d.ts +7 -0
  46. package/dest/multi-call-entrypoint/lazy.d.ts.map +1 -0
  47. package/dest/multi-call-entrypoint/lazy.js +24 -0
  48. package/dest/public-checks/constants.d.ts +5 -0
  49. package/dest/public-checks/constants.d.ts.map +1 -0
  50. package/dest/public-checks/constants.js +7 -0
  51. package/dest/public-checks/index.d.ts +6 -0
  52. package/dest/public-checks/index.d.ts.map +1 -0
  53. package/dest/public-checks/index.js +14 -0
  54. package/dest/public-checks/lazy.d.ts +7 -0
  55. package/dest/public-checks/lazy.d.ts.map +1 -0
  56. package/dest/public-checks/lazy.js +24 -0
  57. package/dest/publishable_standard_contracts.d.ts +17 -0
  58. package/dest/publishable_standard_contracts.d.ts.map +1 -0
  59. package/dest/publishable_standard_contracts.js +23 -0
  60. package/dest/scripts/cleanup_artifacts.js +16 -0
  61. package/dest/scripts/generate_data.js +136 -0
  62. package/dest/standard_contract.d.ts +15 -0
  63. package/dest/standard_contract.d.ts.map +1 -0
  64. package/dest/standard_contract.js +1 -0
  65. package/dest/standard_contract_data.d.ts +19 -0
  66. package/dest/standard_contract_data.d.ts.map +1 -0
  67. package/dest/standard_contract_data.js +85 -0
  68. package/package.json +104 -0
  69. package/src/auth-registry/constants.ts +10 -0
  70. package/src/auth-registry/index.ts +24 -0
  71. package/src/auth-registry/lazy.ts +35 -0
  72. package/src/contract_data.ts +125 -0
  73. package/src/drift.ts +200 -0
  74. package/src/handshake-registry/constants.ts +23 -0
  75. package/src/handshake-registry/index.ts +25 -0
  76. package/src/handshake-registry/lazy.ts +35 -0
  77. package/src/index.ts +5 -0
  78. package/src/make_standard_contract.ts +51 -0
  79. package/src/multi-call-entrypoint/constants.ts +10 -0
  80. package/src/multi-call-entrypoint/index.ts +24 -0
  81. package/src/multi-call-entrypoint/lazy.ts +35 -0
  82. package/src/public-checks/constants.ts +10 -0
  83. package/src/public-checks/index.ts +24 -0
  84. package/src/public-checks/lazy.ts +35 -0
  85. package/src/publishable_standard_contracts.ts +22 -0
  86. package/src/standard_contract.ts +19 -0
  87. package/src/standard_contract_data.ts +114 -0
package/package.json ADDED
@@ -0,0 +1,104 @@
1
+ {
2
+ "name": "@aztec-labs/standard-contracts",
3
+ "homepage": "https://github.com/AztecProtocol/aztec-packages/tree/master/yarn-project/standard-contracts",
4
+ "description": "Standard non-protocol contracts for the Aztec Network",
5
+ "version": "6.0.0-nightly.20260829",
6
+ "type": "module",
7
+ "exports": {
8
+ ".": "./dest/index.js",
9
+ "./*": "./dest/*/index.js",
10
+ "./*/lazy": "./dest/*/lazy.js",
11
+ "./data": "./dest/standard_contract_data.js",
12
+ "./auth-registry/constants": "./dest/auth-registry/constants.js",
13
+ "./public-checks/constants": "./dest/public-checks/constants.js",
14
+ "./multi-call-entrypoint/constants": "./dest/multi-call-entrypoint/constants.js",
15
+ "./handshake-registry/constants": "./dest/handshake-registry/constants.js"
16
+ },
17
+ "typedocOptions": {
18
+ "entryPoints": [
19
+ "./src/index.ts",
20
+ "./src/auth-registry/index.ts"
21
+ ],
22
+ "name": "Standard Contracts",
23
+ "tsconfig": "./tsconfig.json"
24
+ },
25
+ "scripts": {
26
+ "build": "yarn clean && yarn generate && yarn generate:cleanup-artifacts && ../scripts/tsc.sh",
27
+ "build:keep-debug-symbols": "yarn clean && yarn generate && ../scripts/tsc.sh",
28
+ "generate": "yarn generate:data",
29
+ "generate:cleanup-artifacts": "node --no-warnings --loader @swc-node/register/esm src/scripts/cleanup_artifacts.ts",
30
+ "generate:data": "node --no-warnings --loader @swc-node/register/esm src/scripts/generate_data.ts",
31
+ "build:dev": "../scripts/tsc.sh --watch",
32
+ "build:ts": "../scripts/tsc.sh",
33
+ "clean": "rm -rf ./dest .tsbuildinfo ./artifacts",
34
+ "test": "NODE_NO_WARNINGS=1 node --experimental-vm-modules ../node_modules/.bin/jest --passWithNoTests --maxWorkers=${JEST_MAX_WORKERS:-8}"
35
+ },
36
+ "inherits": [
37
+ "../package.common.json",
38
+ "./package.local.json"
39
+ ],
40
+ "jest": {
41
+ "moduleNameMapper": {
42
+ "^(\\.{1,2}/.*)\\.[cm]?js$": "$1"
43
+ },
44
+ "testRegex": "./src/.*\\.test\\.(js|mjs|ts)$",
45
+ "rootDir": "./src",
46
+ "transform": {
47
+ "^.+\\.tsx?$": [
48
+ "@swc/jest",
49
+ {
50
+ "jsc": {
51
+ "parser": {
52
+ "syntax": "typescript",
53
+ "decorators": true
54
+ },
55
+ "transform": {
56
+ "decoratorVersion": "2022-03"
57
+ }
58
+ }
59
+ }
60
+ ]
61
+ },
62
+ "extensionsToTreatAsEsm": [
63
+ ".ts"
64
+ ],
65
+ "reporters": [
66
+ "default"
67
+ ],
68
+ "testTimeout": 120000,
69
+ "setupFiles": [
70
+ "../../foundation/src/jest/setup.mjs"
71
+ ],
72
+ "testEnvironment": "../../foundation/src/jest/env.mjs",
73
+ "setupFilesAfterEnv": [
74
+ "../../foundation/src/jest/setupAfterEnv.mjs"
75
+ ]
76
+ },
77
+ "dependencies": {
78
+ "@aztec-labs/foundation": "6.0.0-nightly.20260829",
79
+ "@aztec-labs/stdlib": "6.0.0-nightly.20260829",
80
+ "tslib": "^2.4.0"
81
+ },
82
+ "devDependencies": {
83
+ "@jest/globals": "^30.0.0",
84
+ "@types/jest": "^30.0.0",
85
+ "@types/node": "^22.15.17",
86
+ "@typescript/native-preview": "7.0.0-dev.20260113.1",
87
+ "jest": "^30.0.0",
88
+ "jest-mock-extended": "^4.0.0",
89
+ "prettier": "^3.5.3",
90
+ "ts-loader": "^9.5.4",
91
+ "ts-node": "^10.9.1",
92
+ "typescript": "^5.3.3"
93
+ },
94
+ "files": [
95
+ "dest",
96
+ "src",
97
+ "!*.test.*",
98
+ "artifacts",
99
+ "!src/scripts/*"
100
+ ],
101
+ "engines": {
102
+ "node": ">=20.10"
103
+ }
104
+ }
@@ -0,0 +1,10 @@
1
+ // Address-only leaf export for browser bundles: importing from
2
+ // `@aztec-labs/standard-contracts/auth-registry/constants` avoids dragging in the
3
+ // `AuthRegistry.json` static import.
4
+ import type { AztecAddress } from '@aztec-labs/stdlib/aztec-address';
5
+
6
+ import { StandardContractAddress, StandardContractClassId, StandardContractSalt } from '../standard_contract_data.js';
7
+
8
+ export const STANDARD_AUTH_REGISTRY_ADDRESS: AztecAddress = StandardContractAddress.AuthRegistry;
9
+ export const STANDARD_AUTH_REGISTRY_CLASS_ID = StandardContractClassId.AuthRegistry;
10
+ export const STANDARD_AUTH_REGISTRY_SALT = StandardContractSalt.AuthRegistry;
@@ -0,0 +1,24 @@
1
+ import { loadContractArtifact } from '@aztec-labs/stdlib/abi';
2
+ import type { NoirCompiledContract } from '@aztec-labs/stdlib/noir';
3
+
4
+ import AuthRegistryJson from '../../artifacts/AuthRegistry.json' with { type: 'json' };
5
+ import { makeStandardContract } from '../make_standard_contract.js';
6
+ import type { StandardContract } from '../standard_contract.js';
7
+
8
+ export {
9
+ STANDARD_AUTH_REGISTRY_ADDRESS,
10
+ STANDARD_AUTH_REGISTRY_CLASS_ID,
11
+ STANDARD_AUTH_REGISTRY_SALT,
12
+ } from './constants.js';
13
+
14
+ export const AuthRegistryArtifact = loadContractArtifact(AuthRegistryJson as NoirCompiledContract);
15
+
16
+ let standardContract: StandardContract;
17
+
18
+ /** Returns the standard deployment of the auth registry. */
19
+ export function getStandardAuthRegistry(): Promise<StandardContract> {
20
+ if (!standardContract) {
21
+ standardContract = makeStandardContract('AuthRegistry', AuthRegistryArtifact);
22
+ }
23
+ return Promise.resolve(standardContract);
24
+ }
@@ -0,0 +1,35 @@
1
+ import { type ContractArtifact, loadContractArtifact } from '@aztec-labs/stdlib/abi';
2
+
3
+ import { makeStandardContract } from '../make_standard_contract.js';
4
+ import type { StandardContract } from '../standard_contract.js';
5
+
6
+ export {
7
+ STANDARD_AUTH_REGISTRY_ADDRESS,
8
+ STANDARD_AUTH_REGISTRY_CLASS_ID,
9
+ STANDARD_AUTH_REGISTRY_SALT,
10
+ } from './constants.js';
11
+
12
+ let standardContract: StandardContract;
13
+ let standardContractArtifact: ContractArtifact;
14
+
15
+ export async function getAuthRegistryArtifact(): Promise<ContractArtifact> {
16
+ if (!standardContractArtifact) {
17
+ // Cannot assert this import as it's incompatible with bundlers like vite
18
+ // https://github.com/vitejs/vite/issues/19095#issuecomment-2566074352
19
+ // Even if now supported by all major browsers, the MIME type is replaced with
20
+ // "text/javascript"
21
+ // In the meantime, this lazy import is INCOMPATIBLE WITH NODEJS
22
+ const { default: authRegistryJson } = await import('../../artifacts/AuthRegistry.json');
23
+ standardContractArtifact = loadContractArtifact(authRegistryJson);
24
+ }
25
+ return standardContractArtifact;
26
+ }
27
+
28
+ /** Returns the standard deployment of the auth registry. */
29
+ export async function getStandardAuthRegistry(): Promise<StandardContract> {
30
+ if (!standardContract) {
31
+ const artifact = await getAuthRegistryArtifact();
32
+ standardContract = makeStandardContract('AuthRegistry', artifact);
33
+ }
34
+ return standardContract;
35
+ }
@@ -0,0 +1,125 @@
1
+ // Shared core for the standard-contracts data generator (`scripts/generate_data.ts`) and its
2
+ // drift-detection test (`standard_contract_data.test.ts`). Keeping the `standardContracts[]`
3
+ // list, paths, and the `computeContractData` derivation in one module ensures the generator
4
+ // (which writes the data) and the test (which checks the committed data is fresh) run the exact
5
+ // same code path. Adding a new standard contract is a one-row change in the array below — both
6
+ // the generator and the drift test pick it up automatically.
7
+ //
8
+ // The rendering and write-if-changed plumbing lives in `drift.ts`, a build-time-only sibling
9
+ // module — keeping `prettier` out of this module avoids pulling a formatter into the published
10
+ // package's transitive imports.
11
+ //
12
+ // Paths below are relative to `yarn-project/standard-contracts` (the cwd when scripts run).
13
+ import { Fr } from '@aztec-labs/foundation/curves/bn254';
14
+ import { FunctionSelector, loadContractArtifact } from '@aztec-labs/stdlib/abi';
15
+ import { AztecAddress } from '@aztec-labs/stdlib/aztec-address';
16
+ import {
17
+ computeContractAddressFromInstance,
18
+ computeInitializationHash,
19
+ getContractClassFromArtifact,
20
+ } from '@aztec-labs/stdlib/contract';
21
+ import { PublicKeys } from '@aztec-labs/stdlib/keys';
22
+ import type { NoirCompiledContract } from '@aztec-labs/stdlib/noir';
23
+ import { promises as fs } from 'fs';
24
+ import path from 'path';
25
+
26
+ /** Root of the noir-contracts package relative to `yarn-project/standard-contracts`. */
27
+ export const NOIR_CONTRACTS_ROOT = '../../noir-projects/noir-contracts';
28
+ /** Directory holding the freshly-compiled Noir artifacts the generator reads from. */
29
+ export const NOIR_ARTIFACTS_SRC_PATH = path.join(NOIR_CONTRACTS_ROOT, './target');
30
+ /** Output directory inside this package where the trimmed artifacts get copied. */
31
+ export const STANDARD_ARTIFACTS_DEST_DIR = './artifacts';
32
+ /** Path of the generated TS data file (addresses, class IDs, etc.). */
33
+ export const STANDARD_CONTRACT_DATA_OUTPUT_PATH = './src/standard_contract_data.ts';
34
+ // The `aztec` crate in aztec-nr needs a twin of the generated addresses module stamped into its
35
+ // source so circuits can reference standard-contract addresses at compile time (e.g. authwit and
36
+ // public_checks) without re-hashing at runtime.
37
+ export const NOIR_STANDARD_ADDRESSES_PATHS = ['../../noir-projects/aztec-nr/aztec/src/standard_addresses.nr'];
38
+
39
+ /** The deployment salt baked into every standard contract instance. */
40
+ export const STANDARD_CONTRACT_SALT = new Fr(1);
41
+ /** Every standard contract is deployed by the zero address (universal deploy). */
42
+ export const STANDARD_CONTRACT_DEPLOYER = AztecAddress.zero();
43
+
44
+ /**
45
+ * Single source of truth for which contracts are "standard" (non-protocol, but with deterministic
46
+ * addresses baked into circuits via `standard_addresses.nr`).
47
+ *
48
+ * - `name`: TS-side name used as the key in the generated `StandardContractAddress` map.
49
+ * - `src`: artifact filename (without `.json`) inside `noir-contracts/target/`.
50
+ * - `nrConst`: Noir-side constant to emit in `standard_addresses.nr`, or `null` to skip the Noir
51
+ * stamp (used for account-side entrypoints with no Noir consumer).
52
+ *
53
+ * Adding a new standard contract is a one-row change here. The drift-detection check in the
54
+ * generator and the backup jest test both iterate this list, so coverage is automatic.
55
+ */
56
+ export const standardContracts: { name: string; src: string; nrConst: string | null }[] = [
57
+ { name: 'AuthRegistry', src: 'auth_registry_contract-AuthRegistry', nrConst: 'STANDARD_AUTH_REGISTRY_ADDRESS' },
58
+ {
59
+ name: 'MultiCallEntrypoint',
60
+ src: 'multi_call_entrypoint_contract-MultiCallEntrypoint',
61
+ nrConst: 'STANDARD_MULTI_CALL_ENTRYPOINT_ADDRESS',
62
+ },
63
+ { name: 'PublicChecks', src: 'public_checks_contract-PublicChecks', nrConst: 'STANDARD_PUBLIC_CHECKS_ADDRESS' },
64
+ {
65
+ name: 'HandshakeRegistry',
66
+ src: 'handshake_registry_contract-HandshakeRegistry',
67
+ nrConst: 'STANDARD_HANDSHAKE_REGISTRY_ADDRESS',
68
+ },
69
+ ];
70
+
71
+ /** Everything derived from a compiled standard-contract artifact that the generator emits. */
72
+ export type ContractData = {
73
+ address: AztecAddress;
74
+ classId: Fr;
75
+ artifactHash: Fr;
76
+ privateFunctionsRoot: Fr;
77
+ publicBytecodeCommitment: Fr;
78
+ initializationHash: Fr;
79
+ privateFunctions: { selector: FunctionSelector; vkHash: Fr }[];
80
+ };
81
+
82
+ /**
83
+ * Loads a compiled Noir contract artifact from `noir-contracts/target/` by its source name.
84
+ * Throws with `ENOENT` if the artifact isn't built yet — callers may catch this to provide a
85
+ * friendlier "run the build first" message.
86
+ */
87
+ export async function loadArtifact(srcName: string): Promise<NoirCompiledContract> {
88
+ const src = path.join(NOIR_ARTIFACTS_SRC_PATH, `${srcName}.json`);
89
+ return JSON.parse(await fs.readFile(src, 'utf8')) as NoirCompiledContract;
90
+ }
91
+
92
+ /**
93
+ * Derives the address, class ID, and other deployment data for a standard contract from its
94
+ * compiled artifact. Used by both the generator (to write `standard_contract_data.ts`) and the
95
+ * drift test (to verify the committed data matches).
96
+ *
97
+ * Standard contracts come from a trusted source (the build pipeline), so no class verifications
98
+ * are performed.
99
+ */
100
+ export async function computeContractData(artifact: NoirCompiledContract): Promise<ContractData> {
101
+ const loaded = loadContractArtifact(artifact);
102
+ const contractClass = await getContractClassFromArtifact(loaded);
103
+ const constructorArtifact = loaded.functions.find(f => f.name === 'constructor');
104
+ const initializationHash = await computeInitializationHash(constructorArtifact, []);
105
+ const instance = {
106
+ version: 2 as const,
107
+ currentContractClassId: contractClass.id,
108
+ originalContractClassId: contractClass.id,
109
+ initializationHash,
110
+ immutablesHash: Fr.ZERO,
111
+ publicKeys: PublicKeys.default(),
112
+ salt: STANDARD_CONTRACT_SALT,
113
+ deployer: STANDARD_CONTRACT_DEPLOYER,
114
+ };
115
+ const address = await computeContractAddressFromInstance(instance);
116
+ return {
117
+ address,
118
+ classId: contractClass.id,
119
+ artifactHash: contractClass.artifactHash,
120
+ privateFunctionsRoot: contractClass.privateFunctionsRoot,
121
+ publicBytecodeCommitment: contractClass.publicBytecodeCommitment,
122
+ initializationHash,
123
+ privateFunctions: contractClass.privateFunctions,
124
+ };
125
+ }
package/src/drift.ts ADDED
@@ -0,0 +1,200 @@
1
+ // Build-time-only rendering and drift-detection plumbing shared by the generator
2
+ // (`scripts/generate_data.ts`) and the backup jest test (`standard_contract_data.test.ts`). Lives
3
+ // outside `contract_data.ts` so that `prettier` (a devDependency used only here) does not become a
4
+ // transitive runtime import of the published package.
5
+ import { AztecAddress } from '@aztec-labs/stdlib/aztec-address';
6
+ import { promises as fs } from 'fs';
7
+ import path from 'path';
8
+ import * as prettier from 'prettier';
9
+
10
+ import {
11
+ type ContractData,
12
+ NOIR_STANDARD_ADDRESSES_PATHS,
13
+ STANDARD_CONTRACT_DATA_OUTPUT_PATH,
14
+ STANDARD_CONTRACT_SALT,
15
+ standardContracts,
16
+ } from './contract_data.js';
17
+
18
+ function generateNames(names: string[]) {
19
+ return `
20
+ export const standardContractNames = [
21
+ ${names.map(name => `'${name}'`).join(',\n')}
22
+ ] as const;
23
+
24
+ export type StandardContractName = typeof standardContractNames[number];
25
+ `;
26
+ }
27
+
28
+ function generateSalts(names: string[]) {
29
+ return `
30
+ export const StandardContractSalt: Record<StandardContractName, Fr> = {
31
+ ${names.map(name => `${name}: new Fr(${STANDARD_CONTRACT_SALT.toNumber()})`).join(',\n')}
32
+ };
33
+ `;
34
+ }
35
+
36
+ function generateAddresses(names: string[], contractData: ContractData[]) {
37
+ return `
38
+ export const StandardContractAddress: Record<StandardContractName, AztecAddress> = {
39
+ ${contractData.map((d, i) => `${names[i]}: AztecAddress.fromStringUnsafe('${d.address.toString()}')`).join(',\n')}
40
+ };
41
+ `;
42
+ }
43
+
44
+ function generateClassIdPreimages(names: string[], contractData: ContractData[]) {
45
+ return `
46
+ export const StandardContractClassId: Record<StandardContractName, Fr> = {
47
+ ${contractData.map((d, i) => `${names[i]}: Fr.fromString('${d.classId.toString()}')`).join(',\n')}
48
+ };
49
+
50
+ export const StandardContractClassIdPreimage: Record<StandardContractName, { artifactHash: Fr; privateFunctionsRoot: Fr; publicBytecodeCommitment: Fr }> = {
51
+ ${contractData
52
+ .map(
53
+ (d, i) => `${names[i]}: {
54
+ artifactHash: Fr.fromString('${d.artifactHash.toString()}'),
55
+ privateFunctionsRoot: Fr.fromString('${d.privateFunctionsRoot.toString()}'),
56
+ publicBytecodeCommitment: Fr.fromString('${d.publicBytecodeCommitment.toString()}'),
57
+ }`,
58
+ )
59
+ .join(',\n')}
60
+ };
61
+
62
+ export const StandardContractInitializationHash: Record<StandardContractName, Fr> = {
63
+ ${contractData.map((d, i) => `${names[i]}: Fr.fromString('${d.initializationHash.toString()}')`).join(',\n')}
64
+ };
65
+
66
+ export const StandardContractPrivateFunctions: Record<StandardContractName, { selector: FunctionSelector; vkHash: Fr }[]> = {
67
+ ${contractData
68
+ .map(
69
+ (d, i) =>
70
+ `${names[i]}: [${d.privateFunctions
71
+ .map(
72
+ fn =>
73
+ `{ selector: FunctionSelector.fromField(Fr.fromString('${fn.selector.toField().toString()}')), vkHash: Fr.fromString('${fn.vkHash.toString()}') }`,
74
+ )
75
+ .join(', ')}]`,
76
+ )
77
+ .join(',\n')}
78
+ };
79
+ `;
80
+ }
81
+
82
+ /**
83
+ * Renders the unformatted TypeScript content for `standard_contract_data.ts`. Run {@link formatTs}
84
+ * on the result before comparing against the committed file — the committed file has been
85
+ * prettier-formatted, so unformatted bytes will not byte-match.
86
+ */
87
+ export function renderOutputFile(names: string[], contractData: ContractData[]): string {
88
+ return `
89
+ // GENERATED FILE - DO NOT EDIT. RUN \`yarn generate\` or \`yarn generate:data\`
90
+ import { Fr } from '@aztec-labs/foundation/curves/bn254';
91
+ import { FunctionSelector } from '@aztec-labs/stdlib/abi';
92
+ import { AztecAddress } from '@aztec-labs/stdlib/aztec-address';
93
+
94
+ ${generateNames(names)}
95
+
96
+ ${generateSalts(names)}
97
+
98
+ ${generateAddresses(names, contractData)}
99
+
100
+ ${generateClassIdPreimages(names, contractData)}
101
+ `;
102
+ }
103
+
104
+ /**
105
+ * Renders the content for each `standard_addresses.nr` twin. Format-stable — `nargo fmt` will not
106
+ * rewrite the output, so the bytes returned here are byte-equal to what should be on disk.
107
+ */
108
+ export function renderNoirAddresses(rows: { nrConst: string; address: AztecAddress }[]): string {
109
+ // Pre-wrapped to survive `nargo fmt`'s line-width pass without diff churn.
110
+ const globals = rows
111
+ .map(
112
+ r => `pub global ${r.nrConst}: AztecAddress = AztecAddress::from_field(
113
+ ${r.address.toField().toString()},
114
+ );`,
115
+ )
116
+ .join('\n\n');
117
+ return `// GENERATED FILE - DO NOT EDIT. RUN \`yarn workspace @aztec-labs/standard-contracts run generate\`.
118
+ use protocol_types::{address::AztecAddress, traits::FromField};
119
+
120
+ ${globals}
121
+ `;
122
+ }
123
+
124
+ /**
125
+ * Formats TypeScript content with the repo's prettier config so the bytes emitted by the generator
126
+ * (and the expected bytes used by the drift test) match what the eventual `format` step in
127
+ * bootstrap.sh produces. Without this normalization the drift check would false-positive on every
128
+ * run since the raw template-string output differs from the prettier-formatted committed content.
129
+ *
130
+ * The typescript/estree plugins are loaded eagerly and passed explicitly: prettier 3's default
131
+ * lazy-loading via ESM dynamic import is unreliable under jest's `experimental-vm-modules` (the
132
+ * VM context can tear down before the dynamic import resolves), which causes intermittent
133
+ * `Cannot read properties of undefined (reading 'estree')` failures.
134
+ */
135
+ export async function formatTs(filePath: string, content: string): Promise<string> {
136
+ const [typescriptPlugin, estreePlugin] = await Promise.all([
137
+ import('prettier/plugins/typescript.js'),
138
+ import('prettier/plugins/estree.js'),
139
+ ]);
140
+ const config = (await prettier.resolveConfig(path.resolve(filePath))) ?? {};
141
+ return prettier.format(content, {
142
+ ...config,
143
+ filepath: filePath,
144
+ parser: 'typescript',
145
+ plugins: [typescriptPlugin.default ?? typescriptPlugin, estreePlugin.default ?? estreePlugin],
146
+ });
147
+ }
148
+
149
+ /** A rendered target file: the destination path and the exact bytes that should be on disk. */
150
+ export type RenderedTarget = { path: string; content: string };
151
+
152
+ /**
153
+ * Renders every generator output target (the TS data file plus each `standard_addresses.nr` twin)
154
+ * from a list of derived `ContractData`. The TS output is prettier-formatted so the result is
155
+ * byte-comparable against the committed file. Both the generator and the drift test build their
156
+ * comparison against this single function.
157
+ */
158
+ export async function renderAllTargets(names: string[], contractData: ContractData[]): Promise<RenderedTarget[]> {
159
+ const tsContent = await formatTs(STANDARD_CONTRACT_DATA_OUTPUT_PATH, renderOutputFile(names, contractData));
160
+ const noirRows = standardContracts
161
+ .map((c, i) => ({ nrConst: c.nrConst, address: contractData[i].address }))
162
+ .filter((row): row is { nrConst: string; address: AztecAddress } => row.nrConst !== null);
163
+ const noirContent = renderNoirAddresses(noirRows);
164
+ return [
165
+ { path: STANDARD_CONTRACT_DATA_OUTPUT_PATH, content: tsContent },
166
+ ...NOIR_STANDARD_ADDRESSES_PATHS.map(p => ({ path: p, content: noirContent })),
167
+ ];
168
+ }
169
+
170
+ /**
171
+ * Reads a file's current content, or returns `null` if it doesn't exist. Used by the generator to
172
+ * compare against freshly rendered output before deciding to overwrite, and by the drift test to
173
+ * compare the committed file's bytes against the expected bytes.
174
+ */
175
+ export async function readIfExists(filePath: string): Promise<string | null> {
176
+ try {
177
+ return await fs.readFile(filePath, 'utf8');
178
+ } catch (err: any) {
179
+ if (err.code === 'ENOENT') {
180
+ return null;
181
+ }
182
+ throw err;
183
+ }
184
+ }
185
+
186
+ /**
187
+ * Compares `content` against the bytes currently at `filePath`. If they differ (including the file
188
+ * not existing), writes the new content and returns `true`. If they match, leaves the file
189
+ * untouched and returns `false`. Skipping the write when the content is identical avoids mtime
190
+ * churn that would otherwise re-trigger downstream build steps on every generator run.
191
+ */
192
+ export async function writeIfChanged(filePath: string, content: string): Promise<boolean> {
193
+ const existing = await readIfExists(filePath);
194
+ if (existing === content) {
195
+ return false;
196
+ }
197
+ await fs.mkdir(path.dirname(filePath), { recursive: true });
198
+ await fs.writeFile(filePath, content);
199
+ return true;
200
+ }
@@ -0,0 +1,23 @@
1
+ // Lightweight metadata leaf export for browser bundles: importing from
2
+ // `@aztec-labs/standard-contracts/handshake-registry/constants` avoids dragging in the
3
+ // `HandshakeRegistry.json` static import.
4
+ import { sha256ToField } from '@aztec-labs/foundation/crypto/sha256';
5
+ import type { Fr } from '@aztec-labs/foundation/curves/bn254';
6
+ import type { AztecAddress } from '@aztec-labs/stdlib/aztec-address';
7
+
8
+ import { StandardContractAddress, StandardContractClassId, StandardContractSalt } from '../standard_contract_data.js';
9
+
10
+ export const STANDARD_HANDSHAKE_REGISTRY_ADDRESS: AztecAddress = StandardContractAddress.HandshakeRegistry;
11
+ export const STANDARD_HANDSHAKE_REGISTRY_CLASS_ID = StandardContractClassId.HandshakeRegistry;
12
+ export const STANDARD_HANDSHAKE_REGISTRY_SALT = StandardContractSalt.HandshakeRegistry;
13
+
14
+ /**
15
+ * Request kind under which the HandshakeRegistry asks for a recipient's interactive-handshake signature through the
16
+ * `resolveCustomRequest` hook. Mirrors `INTERACTIVE_HANDSHAKE_REQUEST_KIND` in the registry contract.
17
+ */
18
+ // TODO: remove this mirrored constant and read the value from the HandshakeRegistry artifact once the contract
19
+ // global can be `#[abi]`-exported. Fixed upstream but not yet released:
20
+ // https://github.com/noir-lang/noir/pull/12714 and https://github.com/noir-lang/noir/issues/12620.
21
+ export const INTERACTIVE_HANDSHAKE_REQUEST_KIND: Fr = sha256ToField([
22
+ Buffer.from('HANDSHAKE_REGISTRY::INTERACTIVE_HANDSHAKE_REQUEST'),
23
+ ]);
@@ -0,0 +1,25 @@
1
+ import { loadContractArtifact } from '@aztec-labs/stdlib/abi';
2
+ import type { NoirCompiledContract } from '@aztec-labs/stdlib/noir';
3
+
4
+ import HandshakeRegistryJson from '../../artifacts/HandshakeRegistry.json' with { type: 'json' };
5
+ import { makeStandardContract } from '../make_standard_contract.js';
6
+ import type { StandardContract } from '../standard_contract.js';
7
+
8
+ export {
9
+ INTERACTIVE_HANDSHAKE_REQUEST_KIND,
10
+ STANDARD_HANDSHAKE_REGISTRY_ADDRESS,
11
+ STANDARD_HANDSHAKE_REGISTRY_CLASS_ID,
12
+ STANDARD_HANDSHAKE_REGISTRY_SALT,
13
+ } from './constants.js';
14
+
15
+ export const HandshakeRegistryArtifact = loadContractArtifact(HandshakeRegistryJson as NoirCompiledContract);
16
+
17
+ let standardContract: StandardContract;
18
+
19
+ /** Returns the standard deployment of the handshake registry. */
20
+ export function getStandardHandshakeRegistry(): Promise<StandardContract> {
21
+ if (!standardContract) {
22
+ standardContract = makeStandardContract('HandshakeRegistry', HandshakeRegistryArtifact);
23
+ }
24
+ return Promise.resolve(standardContract);
25
+ }
@@ -0,0 +1,35 @@
1
+ import { type ContractArtifact, loadContractArtifact } from '@aztec-labs/stdlib/abi';
2
+
3
+ import { makeStandardContract } from '../make_standard_contract.js';
4
+ import type { StandardContract } from '../standard_contract.js';
5
+
6
+ export {
7
+ STANDARD_HANDSHAKE_REGISTRY_ADDRESS,
8
+ STANDARD_HANDSHAKE_REGISTRY_CLASS_ID,
9
+ STANDARD_HANDSHAKE_REGISTRY_SALT,
10
+ } from './constants.js';
11
+
12
+ let standardContract: StandardContract;
13
+ let standardContractArtifact: ContractArtifact;
14
+
15
+ export async function getHandshakeRegistryArtifact(): Promise<ContractArtifact> {
16
+ if (!standardContractArtifact) {
17
+ // Cannot assert this import as it's incompatible with bundlers like vite
18
+ // https://github.com/vitejs/vite/issues/19095#issuecomment-2566074352
19
+ // Even if now supported by all major browsers, the MIME type is replaced with
20
+ // "text/javascript"
21
+ // In the meantime, this lazy import is INCOMPATIBLE WITH NODEJS
22
+ const { default: handshakeRegistryJson } = await import('../../artifacts/HandshakeRegistry.json');
23
+ standardContractArtifact = loadContractArtifact(handshakeRegistryJson);
24
+ }
25
+ return standardContractArtifact;
26
+ }
27
+
28
+ /** Returns the standard deployment of the handshake registry. */
29
+ export async function getStandardHandshakeRegistry(): Promise<StandardContract> {
30
+ if (!standardContract) {
31
+ const artifact = await getHandshakeRegistryArtifact();
32
+ standardContract = makeStandardContract('HandshakeRegistry', artifact);
33
+ }
34
+ return standardContract;
35
+ }
package/src/index.ts ADDED
@@ -0,0 +1,5 @@
1
+ export * from './auth-registry/index.js';
2
+ export * from './handshake-registry/index.js';
3
+ export * from './multi-call-entrypoint/index.js';
4
+ export * from './public-checks/index.js';
5
+ export * from './publishable_standard_contracts.js';
@@ -0,0 +1,51 @@
1
+ import { Fr } from '@aztec-labs/foundation/curves/bn254';
2
+ import type { ContractArtifact } from '@aztec-labs/stdlib/abi';
3
+ import { AztecAddress } from '@aztec-labs/stdlib/aztec-address';
4
+ import { PublicKeys } from '@aztec-labs/stdlib/keys';
5
+
6
+ import type { StandardContract } from './standard_contract.js';
7
+ import {
8
+ StandardContractAddress,
9
+ StandardContractClassId,
10
+ StandardContractClassIdPreimage,
11
+ StandardContractInitializationHash,
12
+ type StandardContractName,
13
+ StandardContractPrivateFunctions,
14
+ StandardContractSalt,
15
+ } from './standard_contract_data.js';
16
+
17
+ /**
18
+ * Reconstructs a StandardContract from precomputed data without performing any hash computations.
19
+ * Internal to the standard-contracts package — not part of the public API.
20
+ */
21
+ export function makeStandardContract(name: StandardContractName, artifact: ContractArtifact): StandardContract {
22
+ const address = StandardContractAddress[name];
23
+ const salt = StandardContractSalt[name];
24
+ const classId = StandardContractClassId[name];
25
+ const { artifactHash, privateFunctionsRoot, publicBytecodeCommitment } = StandardContractClassIdPreimage[name];
26
+ const initializationHash = StandardContractInitializationHash[name];
27
+
28
+ const contractClass = {
29
+ id: classId,
30
+ version: 1 as const,
31
+ artifactHash,
32
+ privateFunctionsRoot,
33
+ publicBytecodeCommitment,
34
+ packedBytecode: artifact.functions.find(f => f.name === 'public_dispatch')?.bytecode ?? Buffer.alloc(0),
35
+ privateFunctions: StandardContractPrivateFunctions[name],
36
+ };
37
+
38
+ const instance = {
39
+ version: 2 as const,
40
+ currentContractClassId: classId,
41
+ originalContractClassId: classId,
42
+ initializationHash,
43
+ immutablesHash: Fr.ZERO,
44
+ publicKeys: PublicKeys.default(),
45
+ salt,
46
+ deployer: AztecAddress.ZERO,
47
+ address,
48
+ };
49
+
50
+ return { instance, contractClass, artifact, address };
51
+ }
@@ -0,0 +1,10 @@
1
+ // Lightweight metadata leaf export for browser bundles: importing from
2
+ // `@aztec-labs/standard-contracts/multi-call-entrypoint/constants` avoids dragging in the
3
+ // `MultiCallEntrypoint.json` static import.
4
+ import type { AztecAddress } from '@aztec-labs/stdlib/aztec-address';
5
+
6
+ import { StandardContractAddress, StandardContractClassId, StandardContractSalt } from '../standard_contract_data.js';
7
+
8
+ export const STANDARD_MULTI_CALL_ENTRYPOINT_ADDRESS: AztecAddress = StandardContractAddress.MultiCallEntrypoint;
9
+ export const STANDARD_MULTI_CALL_ENTRYPOINT_CLASS_ID = StandardContractClassId.MultiCallEntrypoint;
10
+ export const STANDARD_MULTI_CALL_ENTRYPOINT_SALT = StandardContractSalt.MultiCallEntrypoint;