Skip to content

Commit 77181a0

Browse files
JanKuczmaCopilot
andauthored
Restructure TypeScript SDK as publishable npm package (#43)
* support mixed data structures in migration events * Move L1 archive migration to test utils (#45) * Move l1 archive migration to test utils * Publishable SDK (#46) * reorg scopes * npm publish ready * publish workflow * Update e2e-tests/test-utils.ts Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update ts/aztec-state-migration/noir-contracts/MigrationKeyRegistry.lazy.ts Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update ts/aztec-state-migration/noir-contracts/MigrationArchiveRegistry.lazy.ts Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * add build step in readme --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * add build sdk step * fix publish wf * nit picks * add concurrency policy to publish wf --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent 0a4984c commit 77181a0

41 files changed

Lines changed: 1877 additions & 650 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/ci.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ jobs:
5656
run: yarn noir:compile && yarn noir:codegen
5757
- name: Compile Solidity contracts
5858
run: yarn sol:compile
59+
- name: Build TypeScript SDK
60+
run: yarn ts:build
5961
- name: Run hash compatibility check
6062
run: bash e2e-tests/hash-compatibility.sh
6163
- name: Run noir/aztec unit tests

.github/workflows/publish.yml

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
name: Publish SDK to npm
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
version:
7+
description: 'Version to publish (e.g., 0.2.0). Leave empty to use package.json version.'
8+
required: false
9+
type: string
10+
dry_run:
11+
description: 'Dry run (no actual publish)'
12+
required: false
13+
type: boolean
14+
default: true
15+
16+
permissions:
17+
contents: read
18+
19+
env:
20+
NODE_VERSION: '24.12.0'
21+
AZTEC_VERSION: 4.0.0-devnet.2-patch.0
22+
23+
jobs:
24+
publish:
25+
name: Build & Publish
26+
runs-on: ubuntu-latest
27+
timeout-minutes: 15
28+
concurrency:
29+
group: publish-sdk-npm
30+
cancel-in-progress: false
31+
steps:
32+
- uses: actions/checkout@v4
33+
34+
- uses: actions/setup-node@v4
35+
with:
36+
node-version: ${{ env.NODE_VERSION }}
37+
registry-url: 'https://registry.npmjs.org'
38+
39+
- uses: ./.github/actions/setup-aztec
40+
with:
41+
version: ${{ env.AZTEC_VERSION }}
42+
43+
- name: Install dependencies
44+
run: corepack enable && yarn install --frozen-lockfile
45+
46+
- name: Compile Noir contracts & generate bindings
47+
run: yarn noir
48+
49+
- name: Build SDK
50+
run: yarn ts:build
51+
52+
- name: Set version
53+
if: inputs.version != ''
54+
working-directory: ts/aztec-state-migration
55+
env:
56+
VERSION: ${{ inputs.version }}
57+
run: |
58+
[[ "$VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+([-.][0-9A-Za-z.]+)?$ ]] || { echo "Invalid semver: $VERSION"; exit 1; }
59+
npm version "$VERSION" --no-git-tag-version
60+
61+
- name: Publish (dry run)
62+
if: inputs.dry_run
63+
working-directory: ts/aztec-state-migration
64+
run: npm publish --access public --dry-run
65+
env:
66+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
67+
68+
- name: Publish
69+
if: ${{ !inputs.dry_run }}
70+
working-directory: ts/aztec-state-migration
71+
run: npm publish --access public
72+
env:
73+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ dependencies
2121
target
2222
codegenCache.json
2323
cache
24-
ts/aztec-state-migration/noir-contracts
2524
ts/aztec-state-migration/artifacts
2625
e2e-tests/artifacts
2726

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,8 @@ yarn sol:deps
5757
yarn noir:compile # Compile Noir contracts
5858
yarn noir:codegen # Generate TypeScript bindings
5959
yarn sol:compile # Compile Solidity contracts
60-
yarn clean # Remove all compiled artifacts
60+
yarn ts:build # Build typescript SDK
61+
yarn clean # Remove all compiled and built artifacts
6162
```
6263

6364
## Formatting

e2e-tests/deploy-types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import type {
99
import type { AztecNode } from "@aztec/aztec.js/node";
1010
import type { EmbeddedWallet } from "@aztec/wallets/embedded";
1111
import type { AccountManager } from "@aztec/aztec.js/wallet";
12-
import { MigrationEmbeddedWallet } from "../ts/aztec-state-migration/wallet/migration-embedded-wallet.js";
12+
import { MigrationEmbeddedWallet } from "aztec-state-migration/wallet/base";
1313

1414
export interface DeploymentResult {
1515
[rollupVersion: number]: {

e2e-tests/deploy.ts

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import { fileURLToPath } from "url";
1818
import { getPXEConfig } from "@aztec/pxe/server";
1919
import { getInitialTestAccountsData } from "@aztec/accounts/testing";
2020
import type { DeploymentResult } from "./deploy-types.js";
21-
import { NodeMigrationEmbeddedWallet } from "../ts/aztec-state-migration/wallet/index.js";
21+
import { NodeMigrationEmbeddedWallet } from "aztec-state-migration/wallet";
2222

2323
const __dirname = dirname(fileURLToPath(import.meta.url));
2424

@@ -32,23 +32,6 @@ const ETHEREUM_RPC_URL =
3232
const ANVIL_PRIVATE_KEY =
3333
"0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80";
3434

35-
// ============================================================
36-
// L1 ABIs (exported for event parsing in tests)
37-
// ============================================================
38-
export const L1MigratorAbi = parseAbi([
39-
"constructor(address _registry, address _poseidon2)",
40-
"function migrateArchiveRoot(uint256 oldVersion, (bytes32 actor, uint256 version) l2Migrator) external returns (bytes32 leaf, uint256 leafIndex)",
41-
"function getArchiveInfo(uint256 version) external view returns (bytes32 archiveRoot, uint256 provenBlockNumber)",
42-
"function REGISTRY() external view returns (address)",
43-
"function POSEIDON2() external view returns (address)",
44-
"function SECRET_HASH_FOR_ZERO() external view returns (bytes32)",
45-
"event ArchiveRootMigrated(uint256 indexed oldVersion, uint256 indexed newVersion, bytes32 indexed l2Migrator, bytes32 archiveRoot, uint256 provenBlockNumber, bytes32 messageLeaf, uint256 messageLeafIndex)",
46-
]);
47-
48-
export const InboxAbi = parseAbi([
49-
"event MessageSent(uint256 indexed checkpointNumber, uint256 index, bytes32 indexed hash, bytes16 rollingHash)",
50-
]);
51-
5235
// ============================================================
5336
// Bytecode loaders
5437
// ============================================================

e2e-tests/migration-key-registry.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { EmbeddedWallet } from "@aztec/wallets/embedded";
22
import { createAztecNodeClient } from "@aztec/aztec.js/node";
3-
import { MigrationKeyRegistryContract } from "../ts/aztec-state-migration/noir-contracts/MigrationKeyRegistry.js";
3+
import { MigrationKeyRegistryContract } from "aztec-state-migration/noir-contracts";
44
import { Fq, Fr } from "@aztec/foundation/curves/bn254";
55
import { getInitialTestAccountsData } from "@aztec/accounts/testing";
66
import { generatePublicKey } from "@aztec/aztec.js/keys";

e2e-tests/migration-mode-a.test.ts

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { ExampleMigrationAppV1Contract } from "./artifacts/ExampleMigrationAppV1.js";
22
import { ExampleMigrationAppV2Contract } from "./artifacts/ExampleMigrationAppV2.js";
33
import { Fr } from "@aztec/foundation/curves/bn254";
4-
import { signMigrationModeA } from "../ts/aztec-state-migration/index.js";
4+
import { signMigrationModeA } from "aztec-state-migration/mode-a";
55
import { deploy } from "./deploy.js";
66
import {
77
deployAppPair,
@@ -106,12 +106,11 @@ async function main() {
106106
// Step 5: Bridge archive root
107107
// ============================================================
108108
console.log("Step 5. Bridging archive root...");
109-
const { l1Result, provenBlockNumber, blockHeader } = await bridgeBlock(
109+
const { provenBlockNumber, blockHeader } = await bridgeBlock(
110110
env,
111111
newArchiveRegistry,
112112
);
113-
console.log(` Proven block: ${l1Result.provenBlockNumber}`);
114-
console.log(` Archive root: ${l1Result.provenArchiveRoot}\n`);
113+
console.log(` Proven block: ${provenBlockNumber}`);
115114

116115
// ============================================================
117116
// Steps 6-7: Prepare migration args and call migrate on NEW rollup
@@ -129,11 +128,12 @@ async function main() {
129128
`Expected exactly 1 migration note, but found ${lockNotesAndData.length}`,
130129
);
131130
}
131+
const lockNoteAndData = lockNotesAndData[0];
132132

133133
// Build proofs via wallet, combining note proofs with event data
134-
const [migrationNoteProof] = await oldUserWallet.buildMigrationNoteProofs(
134+
const migrationNoteProof = await oldUserWallet.buildMigrationNoteProof(
135135
provenBlockNumber,
136-
lockNotesAndData,
136+
lockNoteAndData,
137137
);
138138

139139
// Sign via standalone function
@@ -248,12 +248,10 @@ async function main() {
248248
console.log("Step 10. Bridging archive root for public lock note...");
249249

250250
const {
251-
l1Result: l1ResultPublic,
252251
provenBlockNumber: publicProvenBlockNumber,
253252
blockHeader: publicBlockHeader,
254253
} = await bridgeBlock(env, newArchiveRegistry);
255-
console.log(` Proven block: ${l1ResultPublic.provenBlockNumber}`);
256-
console.log(` Archive root: ${l1ResultPublic.provenArchiveRoot}\n`);
254+
console.log(` Proven block: ${publicProvenBlockNumber}`);
257255

258256
// ============================================================
259257
// Step 11: Get public lock note and merkle proofs
@@ -287,12 +285,12 @@ async function main() {
287285
`Expected exactly 1 migration note for the public lock, but found ${filteredNotes.length}`,
288286
);
289287
}
288+
const migrationNote = filteredNotes[0];
290289

291-
const [publicMigrationNoteProof] =
292-
await oldUserWallet.buildMigrationNoteProofs(
293-
publicProvenBlockNumber,
294-
filteredNotes,
295-
);
290+
const publicMigrationNoteProof = await oldUserWallet.buildMigrationNoteProof(
291+
publicProvenBlockNumber,
292+
migrationNote,
293+
);
296294

297295
// Sign via standalone function
298296
const publicSignature = await signMigrationModeA(

e2e-tests/migration-mode-b.test.ts

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Fr } from "@aztec/foundation/curves/bn254";
2-
import { signMigrationModeB } from "../ts/aztec-state-migration/index.js";
2+
import { signMigrationModeB } from "aztec-state-migration/mode-b";
33
import { deploy } from "./deploy.js";
44
import {
55
deployAppPair,
@@ -12,8 +12,8 @@ import {
1212
} from "./test-utils.js";
1313
import { ExampleMigrationAppV1Contract } from "./artifacts/ExampleMigrationAppV1.js";
1414
import { ExampleMigrationAppV2Contract } from "./artifacts/ExampleMigrationAppV2.js";
15-
import { MigrationKeyRegistryContract } from "../ts/aztec-state-migration/noir-contracts/MigrationKeyRegistry.js";
16-
import { UintNote } from "../ts/aztec-state-migration/common-notes.js";
15+
import { MigrationKeyRegistryContract } from "aztec-state-migration/noir-contracts";
16+
import { UintNote } from "aztec-state-migration/common-notes";
1717
import { NoteStatus } from "@aztec/stdlib/note";
1818

1919
async function main() {
@@ -204,12 +204,12 @@ async function main() {
204204
}
205205

206206
// The ExampleMigrationApp currently only creates one note per call.
207-
const balanceNotes = balanceNotesActive.slice(0, 1);
207+
const balanceNote = balanceNotesActive[0];
208208

209209
// Build proofs via wallet
210-
const fullProofs = await oldUserWallet.buildFullNoteProofs(
210+
const fullProof = await oldUserWallet.buildFullNoteProof(
211211
provenBlockNumber,
212-
balanceNotes,
212+
balanceNote,
213213
(note) => UintNote.fromNote(note),
214214
);
215215

@@ -227,7 +227,7 @@ async function main() {
227227
oldMigrationSigner,
228228
blockHeader.global_variables.version,
229229
new Fr(env.newRollupVersion),
230-
balanceNotes,
230+
[balanceNote],
231231
newUserManager.address,
232232
newApp.address,
233233
);
@@ -240,8 +240,7 @@ async function main() {
240240
console.log("Step 10. Calling migrate_mode_b on NEW rollup...");
241241

242242
// The ExampleMigrationApp currently only supports migrating one note at a time.
243-
const noteProof = fullProofs[0];
244-
const migrateAmount = noteProof.note_proof_data.data.value;
243+
const migrateAmount = fullProof.note_proof_data.data.value;
245244
console.log(` Migrating amount: ${migrateAmount}`);
246245

247246
const newBalanceBefore = await newAppUser.methods
@@ -252,7 +251,7 @@ async function main() {
252251
await newAppUser.methods
253252
.migrate_mode_b(
254253
signature,
255-
noteProof,
254+
fullProof,
256255
blockHeader,
257256
oldUserManager.address,
258257
publicKeys,
@@ -290,9 +289,9 @@ async function main() {
290289
// Take one nullified note
291290
const nullifiedNote = balanceNotesNullified[0];
292291

293-
const [nullifiedNoteProof] = await oldUserWallet.buildFullNoteProofs(
292+
const nullifiedNoteProof = await oldUserWallet.buildFullNoteProof(
294293
provenBlockNumber,
295-
[nullifiedNote],
294+
nullifiedNote,
296295
(note) => UintNote.fromNote(note),
297296
);
298297

e2e-tests/migration-public-mode-b.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@ import {
1313
ExampleMigrationAppV2Contract,
1414
ExampleMigrationAppV2ContractArtifact,
1515
} from "./artifacts/ExampleMigrationAppV2.js";
16-
import { MigrationKeyRegistryContract } from "../ts/aztec-state-migration/noir-contracts/MigrationKeyRegistry.js";
16+
import { MigrationKeyRegistryContract } from "aztec-state-migration/noir-contracts";
1717
import { AztecAddress } from "@aztec/stdlib/aztec-address";
1818
import {
1919
buildPublicDataProof,
2020
buildPublicMapDataProof,
21-
} from "../ts/aztec-state-migration/mode-b/proofs.js";
21+
} from "aztec-state-migration/mode-b";
2222
import { randomBigInt } from "@aztec/foundation/crypto/random";
2323

2424
// Define a struct that matches the one used in the example app contract,

0 commit comments

Comments
 (0)