-
Notifications
You must be signed in to change notification settings - Fork 325
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: Lazy loading artifacts everywhere (#12285)
This PR adds the *option* to lazily load JSON artifacts in all the packages that were missing that functionality, further improving bundle sizes for the browser and allowing us to finally put limits on our example apps bundle sizes: * `noir-protocol-circuits-types/vks`: now allow vk lazy imports via the `LazyArtifactProvider` in the `/client` export, while maintaining the bundled version for the server under `/server/vks` * `accounts`: Now all exports provide a lazy version, e.g: `@aztec/accounts/schnorr/lazy`. This has proven to be complicated due to the testing import leaking into the browser (where type assertions are not widely supported). Now there's also `/testing/lazy`. This testing package is needed in the browser for the prefunded accounts. * `protocol-contracts`: Now with a lazy version and exporting `ProtocolContractProviders` so that PXE can be configured with bundled and lazy versions. Besides the type assertion issue, we absolutely want to keep bundled and lazy versions because some environments don't play well with `await import` (namely service workers in firefox) --------- Co-authored-by: esau <152162806+sklppy88@users.noreply.github.com>
- Loading branch information
Showing
98 changed files
with
1,130 additions
and
369 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
playground/src/components/sidebar/components/createAccountDialog.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
/** | ||
* The `@aztec/accounts/ecdsa` export provides an ECDSA account contract implementation, that uses an ECDSA private key for authentication, and a Grumpkin key for encryption. | ||
* Consider using this account type when working with integrations with Ethereum wallets. | ||
* | ||
* @packageDocumentation | ||
*/ | ||
import { AccountManager, type Salt } from '@aztec/aztec.js/account'; | ||
import { type AccountWallet, getWallet } from '@aztec/aztec.js/wallet'; | ||
import { Fr } from '@aztec/foundation/fields'; | ||
import type { ContractArtifact } from '@aztec/stdlib/abi'; | ||
import { loadContractArtifact } from '@aztec/stdlib/abi'; | ||
import { AztecAddress } from '@aztec/stdlib/aztec-address'; | ||
import type { PXE } from '@aztec/stdlib/interfaces/client'; | ||
|
||
import { EcdsaKBaseAccountContract } from './account_contract.js'; | ||
|
||
/** | ||
* Lazily loads the contract artifact | ||
* @returns The contract artifact for the ecdsa K account contract | ||
*/ | ||
export async function getEcdsaKAccountContractArtifact() { | ||
const { default: ecdsaKAccountContractJson } = await import('../../../artifacts/EcdsaKAccount.json'); | ||
return loadContractArtifact(ecdsaKAccountContractJson); | ||
} | ||
|
||
/** | ||
* Account contract that authenticates transactions using ECDSA signatures | ||
* verified against a secp256k1 public key stored in an immutable encrypted note. | ||
* Lazily loads the contract artifact | ||
*/ | ||
export class EcdsaKAccountContract extends EcdsaKBaseAccountContract { | ||
constructor(signingPrivateKey: Buffer) { | ||
super(signingPrivateKey); | ||
} | ||
|
||
override getContractArtifact(): Promise<ContractArtifact> { | ||
return getEcdsaKAccountContractArtifact(); | ||
} | ||
} | ||
/** | ||
* Creates an Account that relies on an ECDSA signing key for authentication. | ||
* @param pxe - An PXE server instance. | ||
* @param secretKey - Secret key used to derive all the keystore keys. | ||
* @param signingPrivateKey - Secp256k1 key used for signing transactions. | ||
* @param salt - Deployment salt. | ||
* @returns An account manager initialized with the account contract and its deployment params | ||
*/ | ||
export function getEcdsaKAccount( | ||
pxe: PXE, | ||
secretKey: Fr, | ||
signingPrivateKey: Buffer, | ||
salt?: Salt, | ||
): Promise<AccountManager> { | ||
return AccountManager.create(pxe, secretKey, new EcdsaKAccountContract(signingPrivateKey), salt); | ||
} | ||
|
||
/** | ||
* Gets a wallet for an already registered account using ECDSA signatures. | ||
* @param pxe - An PXE server instance. | ||
* @param address - Address for the account. | ||
* @param signingPrivateKey - ECDSA key used for signing transactions. | ||
* @returns A wallet for this account that can be used to interact with a contract instance. | ||
*/ | ||
export function getEcdsaKWallet(pxe: PXE, address: AztecAddress, signingPrivateKey: Buffer): Promise<AccountWallet> { | ||
return getWallet(pxe, address, new EcdsaKAccountContract(signingPrivateKey)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export * from './ecdsa_k/lazy.js'; | ||
export * from './ssh_ecdsa_r/lazy.js'; |
Oops, something went wrong.
3cb6920
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Possible performance regression was detected for benchmark 'P2P Testbench'.
Benchmark result of this commit is worse than the previous benchmark result exceeding threshold
1.05
.normal-degree-50-nodes - minDelay
206
ms123
ms1.67
This comment was automatically generated by workflow using github-action-benchmark.
CC: @Maddiaa0