@aztec-labs/accounts 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 (138) hide show
  1. package/README.md +40 -0
  2. package/artifacts/EcdsaKAccount.d.json.ts +3 -0
  3. package/artifacts/EcdsaKAccount.json +12861 -0
  4. package/artifacts/EcdsaRAccount.d.json.ts +3 -0
  5. package/artifacts/EcdsaRAccount.json +12861 -0
  6. package/artifacts/SchnorrAccount.d.json.ts +3 -0
  7. package/artifacts/SchnorrAccount.json +12914 -0
  8. package/artifacts/SchnorrInitializerlessAccount.d.json.ts +3 -0
  9. package/artifacts/SchnorrInitializerlessAccount.json +8530 -0
  10. package/artifacts/SimulatedEcdsaAccount.d.json.ts +3 -0
  11. package/artifacts/SimulatedEcdsaAccount.json +10980 -0
  12. package/artifacts/SimulatedSchnorrAccount.d.json.ts +3 -0
  13. package/artifacts/SimulatedSchnorrAccount.json +11092 -0
  14. package/dest/defaults/account_contract.d.ts +26 -0
  15. package/dest/defaults/account_contract.d.ts.map +1 -0
  16. package/dest/defaults/account_contract.js +18 -0
  17. package/dest/defaults/index.d.ts +9 -0
  18. package/dest/defaults/index.d.ts.map +1 -0
  19. package/dest/defaults/index.js +7 -0
  20. package/dest/defaults/stub_account_contract.d.ts +29 -0
  21. package/dest/defaults/stub_account_contract.d.ts.map +1 -0
  22. package/dest/defaults/stub_account_contract.js +30 -0
  23. package/dest/ecdsa/ecdsa_k/account_contract.d.ts +19 -0
  24. package/dest/ecdsa/ecdsa_k/account_contract.d.ts.map +1 -0
  25. package/dest/ecdsa/ecdsa_k/account_contract.js +45 -0
  26. package/dest/ecdsa/ecdsa_k/index.d.ts +19 -0
  27. package/dest/ecdsa/ecdsa_k/index.d.ts.map +1 -0
  28. package/dest/ecdsa/ecdsa_k/index.js +23 -0
  29. package/dest/ecdsa/ecdsa_k/lazy.d.ts +23 -0
  30. package/dest/ecdsa/ecdsa_k/lazy.d.ts.map +1 -0
  31. package/dest/ecdsa/ecdsa_k/lazy.js +31 -0
  32. package/dest/ecdsa/ecdsa_r/account_contract.d.ts +19 -0
  33. package/dest/ecdsa/ecdsa_r/account_contract.d.ts.map +1 -0
  34. package/dest/ecdsa/ecdsa_r/account_contract.js +45 -0
  35. package/dest/ecdsa/ecdsa_r/index.d.ts +19 -0
  36. package/dest/ecdsa/ecdsa_r/index.d.ts.map +1 -0
  37. package/dest/ecdsa/ecdsa_r/index.js +23 -0
  38. package/dest/ecdsa/ecdsa_r/lazy.d.ts +23 -0
  39. package/dest/ecdsa/ecdsa_r/lazy.d.ts.map +1 -0
  40. package/dest/ecdsa/ecdsa_r/lazy.js +31 -0
  41. package/dest/ecdsa/index.d.ts +4 -0
  42. package/dest/ecdsa/index.d.ts.map +1 -0
  43. package/dest/ecdsa/index.js +3 -0
  44. package/dest/ecdsa/lazy.d.ts +4 -0
  45. package/dest/ecdsa/lazy.d.ts.map +1 -0
  46. package/dest/ecdsa/lazy.js +3 -0
  47. package/dest/ecdsa/ssh_ecdsa_r/account_contract.d.ts +22 -0
  48. package/dest/ecdsa/ssh_ecdsa_r/account_contract.d.ts.map +1 -0
  49. package/dest/ecdsa/ssh_ecdsa_r/account_contract.js +87 -0
  50. package/dest/ecdsa/ssh_ecdsa_r/index.d.ts +21 -0
  51. package/dest/ecdsa/ssh_ecdsa_r/index.d.ts.map +1 -0
  52. package/dest/ecdsa/ssh_ecdsa_r/index.js +22 -0
  53. package/dest/ecdsa/ssh_ecdsa_r/lazy.d.ts +21 -0
  54. package/dest/ecdsa/ssh_ecdsa_r/lazy.d.ts.map +1 -0
  55. package/dest/ecdsa/ssh_ecdsa_r/lazy.js +22 -0
  56. package/dest/ecdsa/stub/index.d.ts +11 -0
  57. package/dest/ecdsa/stub/index.d.ts.map +1 -0
  58. package/dest/ecdsa/stub/index.js +18 -0
  59. package/dest/ecdsa/stub/lazy.d.ts +14 -0
  60. package/dest/ecdsa/stub/lazy.d.ts.map +1 -0
  61. package/dest/ecdsa/stub/lazy.js +22 -0
  62. package/dest/schnorr/account_contract.d.ts +32 -0
  63. package/dest/schnorr/account_contract.d.ts.map +1 -0
  64. package/dest/schnorr/account_contract.js +41 -0
  65. package/dest/schnorr/index.d.ts +3 -0
  66. package/dest/schnorr/index.d.ts.map +1 -0
  67. package/dest/schnorr/index.js +2 -0
  68. package/dest/schnorr/initializerless/index.d.ts +25 -0
  69. package/dest/schnorr/initializerless/index.d.ts.map +1 -0
  70. package/dest/schnorr/initializerless/index.js +46 -0
  71. package/dest/schnorr/initializerless/lazy.d.ts +29 -0
  72. package/dest/schnorr/initializerless/lazy.d.ts.map +1 -0
  73. package/dest/schnorr/initializerless/lazy.js +54 -0
  74. package/dest/schnorr/lazy.d.ts +3 -0
  75. package/dest/schnorr/lazy.d.ts.map +1 -0
  76. package/dest/schnorr/lazy.js +2 -0
  77. package/dest/schnorr/private_immutable/index.d.ts +23 -0
  78. package/dest/schnorr/private_immutable/index.d.ts.map +1 -0
  79. package/dest/schnorr/private_immutable/index.js +35 -0
  80. package/dest/schnorr/private_immutable/lazy.d.ts +27 -0
  81. package/dest/schnorr/private_immutable/lazy.d.ts.map +1 -0
  82. package/dest/schnorr/private_immutable/lazy.js +43 -0
  83. package/dest/schnorr/stub/index.d.ts +11 -0
  84. package/dest/schnorr/stub/index.d.ts.map +1 -0
  85. package/dest/schnorr/stub/index.js +18 -0
  86. package/dest/schnorr/stub/lazy.d.ts +14 -0
  87. package/dest/schnorr/stub/lazy.d.ts.map +1 -0
  88. package/dest/schnorr/stub/lazy.js +22 -0
  89. package/dest/testing/configuration.d.ts +37 -0
  90. package/dest/testing/configuration.d.ts.map +1 -0
  91. package/dest/testing/configuration.js +19 -0
  92. package/dest/testing/index.d.ts +11 -0
  93. package/dest/testing/index.d.ts.map +1 -0
  94. package/dest/testing/index.js +43 -0
  95. package/dest/testing/lazy.d.ts +11 -0
  96. package/dest/testing/lazy.d.ts.map +1 -0
  97. package/dest/testing/lazy.js +43 -0
  98. package/dest/utils/index.d.ts +3 -0
  99. package/dest/utils/index.d.ts.map +1 -0
  100. package/dest/utils/index.js +2 -0
  101. package/dest/utils/key_derivation.d.ts +9 -0
  102. package/dest/utils/key_derivation.d.ts.map +1 -0
  103. package/dest/utils/key_derivation.js +19 -0
  104. package/dest/utils/ssh_agent.d.ts +33 -0
  105. package/dest/utils/ssh_agent.d.ts.map +1 -0
  106. package/dest/utils/ssh_agent.js +155 -0
  107. package/package.json +108 -0
  108. package/src/defaults/account_contract.ts +47 -0
  109. package/src/defaults/index.ts +9 -0
  110. package/src/defaults/stub_account_contract.ts +39 -0
  111. package/src/ecdsa/ecdsa_k/account_contract.ts +42 -0
  112. package/src/ecdsa/ecdsa_k/index.ts +31 -0
  113. package/src/ecdsa/ecdsa_k/lazy.ts +39 -0
  114. package/src/ecdsa/ecdsa_r/account_contract.ts +42 -0
  115. package/src/ecdsa/ecdsa_r/index.ts +31 -0
  116. package/src/ecdsa/ecdsa_r/lazy.ts +39 -0
  117. package/src/ecdsa/index.ts +3 -0
  118. package/src/ecdsa/lazy.ts +3 -0
  119. package/src/ecdsa/ssh_ecdsa_r/account_contract.ts +92 -0
  120. package/src/ecdsa/ssh_ecdsa_r/index.ts +28 -0
  121. package/src/ecdsa/ssh_ecdsa_r/lazy.ts +28 -0
  122. package/src/ecdsa/stub/index.ts +28 -0
  123. package/src/ecdsa/stub/lazy.ts +34 -0
  124. package/src/schnorr/account_contract.ts +53 -0
  125. package/src/schnorr/index.ts +2 -0
  126. package/src/schnorr/initializerless/index.ts +62 -0
  127. package/src/schnorr/initializerless/lazy.ts +70 -0
  128. package/src/schnorr/lazy.ts +2 -0
  129. package/src/schnorr/private_immutable/index.ts +50 -0
  130. package/src/schnorr/private_immutable/lazy.ts +60 -0
  131. package/src/schnorr/stub/index.ts +30 -0
  132. package/src/schnorr/stub/lazy.ts +34 -0
  133. package/src/testing/configuration.ts +53 -0
  134. package/src/testing/index.ts +76 -0
  135. package/src/testing/lazy.ts +69 -0
  136. package/src/utils/index.ts +2 -0
  137. package/src/utils/key_derivation.ts +18 -0
  138. package/src/utils/ssh_agent.ts +138 -0
package/package.json ADDED
@@ -0,0 +1,108 @@
1
+ {
2
+ "name": "@aztec-labs/accounts",
3
+ "homepage": "https://github.com/AztecProtocol/aztec-packages/tree/master/yarn-project/accounts",
4
+ "description": "Implementation of sample account contracts for Aztec Network",
5
+ "version": "6.0.0-nightly.20260829",
6
+ "type": "module",
7
+ "exports": {
8
+ "./defaults": "./dest/defaults/index.js",
9
+ "./ecdsa": "./dest/ecdsa/index.js",
10
+ "./ecdsa/lazy": "./dest/ecdsa/lazy.js",
11
+ "./ecdsa/stub": "./dest/ecdsa/stub/index.js",
12
+ "./ecdsa/stub/lazy": "./dest/ecdsa/stub/lazy.js",
13
+ "./schnorr": "./dest/schnorr/index.js",
14
+ "./schnorr/lazy": "./dest/schnorr/lazy.js",
15
+ "./schnorr/stub": "./dest/schnorr/stub/index.js",
16
+ "./schnorr/stub/lazy": "./dest/schnorr/stub/lazy.js",
17
+ "./testing": "./dest/testing/index.js",
18
+ "./testing/lazy": "./dest/testing/lazy.js",
19
+ "./utils": "./dest/utils/index.js"
20
+ },
21
+ "typedocOptions": {
22
+ "entryPoints": [
23
+ "./src/defaults/index.ts",
24
+ "./src/ecdsa/index.ts",
25
+ "./src/schnorr/index.ts",
26
+ "./src/testing/index.ts"
27
+ ],
28
+ "name": "Accounts",
29
+ "tsconfig": "./tsconfig.json"
30
+ },
31
+ "scripts": {
32
+ "build": "yarn clean && yarn generate && ../scripts/tsc.sh",
33
+ "generate": "yarn generate:noir-contracts",
34
+ "generate:noir-contracts": "./scripts/copy-contracts.sh",
35
+ "build:dev": "../scripts/tsc.sh --watch",
36
+ "build:ts": "../scripts/tsc.sh",
37
+ "clean": "rm -rf ./dest .tsbuildinfo ./artifacts",
38
+ "test": "NODE_NO_WARNINGS=1 node --experimental-vm-modules ../node_modules/.bin/jest --passWithNoTests --maxWorkers=${JEST_MAX_WORKERS:-8}"
39
+ },
40
+ "inherits": [
41
+ "../package.common.json",
42
+ "./package.local.json"
43
+ ],
44
+ "jest": {
45
+ "moduleNameMapper": {
46
+ "^(\\.{1,2}/.*)\\.[cm]?js$": "$1"
47
+ },
48
+ "testRegex": "./src/.*\\.test\\.(js|mjs|ts)$",
49
+ "rootDir": "./src",
50
+ "transform": {
51
+ "^.+\\.tsx?$": [
52
+ "@swc/jest",
53
+ {
54
+ "jsc": {
55
+ "parser": {
56
+ "syntax": "typescript",
57
+ "decorators": true
58
+ },
59
+ "transform": {
60
+ "decoratorVersion": "2022-03"
61
+ }
62
+ }
63
+ }
64
+ ]
65
+ },
66
+ "extensionsToTreatAsEsm": [
67
+ ".ts"
68
+ ],
69
+ "reporters": [
70
+ "default"
71
+ ],
72
+ "testTimeout": 120000,
73
+ "setupFiles": [
74
+ "../../foundation/src/jest/setup.mjs"
75
+ ],
76
+ "testEnvironment": "../../foundation/src/jest/env.mjs",
77
+ "setupFilesAfterEnv": [
78
+ "../../foundation/src/jest/setupAfterEnv.mjs"
79
+ ]
80
+ },
81
+ "dependencies": {
82
+ "@aztec-labs/aztec.js": "6.0.0-nightly.20260829",
83
+ "@aztec-labs/entrypoints": "6.0.0-nightly.20260829",
84
+ "@aztec-labs/foundation": "6.0.0-nightly.20260829",
85
+ "@aztec-labs/stdlib": "6.0.0-nightly.20260829",
86
+ "tslib": "^2.4.0"
87
+ },
88
+ "devDependencies": {
89
+ "@jest/globals": "^30.0.0",
90
+ "@types/jest": "^30.0.0",
91
+ "@types/node": "^22.15.17",
92
+ "@typescript/native-preview": "7.0.0-dev.20260113.1",
93
+ "jest": "^30.0.0",
94
+ "jest-mock-extended": "^4.0.0",
95
+ "ts-loader": "^9.5.4",
96
+ "ts-node": "^10.9.1",
97
+ "typescript": "^5.3.3"
98
+ },
99
+ "files": [
100
+ "dest",
101
+ "src",
102
+ "!*.test.*",
103
+ "artifacts"
104
+ ],
105
+ "engines": {
106
+ "node": ">=20.10"
107
+ }
108
+ }
@@ -0,0 +1,47 @@
1
+ import {
2
+ type Account,
3
+ type AccountContract,
4
+ type AuthWitnessProvider,
5
+ BaseAccount,
6
+ } from '@aztec-labs/aztec.js/account';
7
+ import { DefaultAccountEntrypoint } from '@aztec-labs/entrypoints/account';
8
+ import type { Fr } from '@aztec-labs/foundation/curves/bn254';
9
+ import type { ContractArtifact } from '@aztec-labs/stdlib/abi';
10
+ import type { CompleteAddress } from '@aztec-labs/stdlib/contract';
11
+
12
+ /**
13
+ * Base class for implementing an account contract. Requires that the account uses the
14
+ * default entrypoint method signature.
15
+ */
16
+ export abstract class DefaultAccountContract implements AccountContract {
17
+ abstract getAuthWitnessProvider(address: CompleteAddress): AuthWitnessProvider;
18
+ abstract getInitializationFunctionAndArgs(): Promise<
19
+ | {
20
+ /** The name of the function used to initialize the contract */
21
+ constructorName: string;
22
+ /** The args to the function used to initialize the contract */
23
+ constructorArgs: any[];
24
+ }
25
+ | undefined
26
+ >;
27
+ abstract getContractArtifact(): Promise<ContractArtifact>;
28
+
29
+ constructor() {}
30
+
31
+ /**
32
+ * Accounts without immutables (the default) contribute to their address via an on-chain
33
+ * initializer instead. Account contracts that commit immutables into their address override this.
34
+ */
35
+ getImmutablesHash(): Promise<Fr | undefined> {
36
+ return Promise.resolve(undefined);
37
+ }
38
+
39
+ getAccount(completeAddress: CompleteAddress): Account {
40
+ const authWitnessProvider = this.getAuthWitnessProvider(completeAddress);
41
+ return new BaseAccount(
42
+ new DefaultAccountEntrypoint(completeAddress.address, authWitnessProvider),
43
+ authWitnessProvider,
44
+ completeAddress,
45
+ );
46
+ }
47
+ }
@@ -0,0 +1,9 @@
1
+ /**
2
+ * The `@aztec-labs/accounts/defaults` export provides the base class {@link DefaultAccountContract} for implementing account contracts that use the default entrypoint payload module.
3
+ *
4
+ * Read more in {@link https://docs.aztec.network/developers/tutorials/contract_tutorials/counter_contract | Writing an account contract}.
5
+ *
6
+ * @packageDocumentation
7
+ */
8
+
9
+ export * from './account_contract.js';
@@ -0,0 +1,39 @@
1
+ import type { AuthWitnessProvider } from '@aztec-labs/aztec.js/account';
2
+ import { Fr } from '@aztec-labs/foundation/curves/bn254';
3
+ import { AuthWitness } from '@aztec-labs/stdlib/auth-witness';
4
+ import { CompleteAddress } from '@aztec-labs/stdlib/contract';
5
+
6
+ import { DefaultAccountContract } from '../defaults/account_contract.js';
7
+
8
+ /**
9
+ * An Account contract that does not perform any authentication of authwits
10
+ * (`is_valid` always returns `true`)
11
+ * It is used to capture authorization data during simulations
12
+ */
13
+ export abstract class StubBaseAccountContract extends DefaultAccountContract {
14
+ constructor() {
15
+ super();
16
+ }
17
+
18
+ getInitializationFunctionAndArgs() {
19
+ return Promise.resolve({ constructorName: 'constructor', constructorArgs: [] });
20
+ }
21
+
22
+ getAuthWitnessProvider(_address: CompleteAddress): AuthWitnessProvider {
23
+ return new StubAuthWitnessProvider();
24
+ }
25
+ }
26
+
27
+ /** Creates auth witnesses using Stub signatures. */
28
+ export class StubAuthWitnessProvider implements AuthWitnessProvider {
29
+ constructor() {}
30
+
31
+ /**
32
+ * A fake account always returns an empty authwitness, since it doesn't
33
+ * perform any verification whatsoever
34
+ * @param messageHash - The outer hash of the message for which the auth witness is created
35
+ */
36
+ createAuthWit(messageHash: Fr): Promise<AuthWitness> {
37
+ return Promise.resolve(new AuthWitness(messageHash, []));
38
+ }
39
+ }
@@ -0,0 +1,42 @@
1
+ import type { AuthWitnessProvider } from '@aztec-labs/aztec.js/account';
2
+ import { Ecdsa } from '@aztec-labs/foundation/crypto/ecdsa';
3
+ import type { Fr } from '@aztec-labs/foundation/curves/bn254';
4
+ import { AuthWitness } from '@aztec-labs/stdlib/auth-witness';
5
+ import { CompleteAddress } from '@aztec-labs/stdlib/contract';
6
+
7
+ import { DefaultAccountContract } from '../../defaults/account_contract.js';
8
+
9
+ /**
10
+ * Account contract that authenticates transactions using ECDSA signatures
11
+ * verified against a secp256k1 public key stored in an immutable encrypted note.
12
+ * This abstract version does not provide a way to retrieve the artifact, as it
13
+ * can be implemented with or without lazy loading.
14
+ */
15
+ export abstract class EcdsaKBaseAccountContract extends DefaultAccountContract {
16
+ constructor(private signingPrivateKey: Buffer) {
17
+ super();
18
+ }
19
+
20
+ async getInitializationFunctionAndArgs() {
21
+ const signingPublicKey = await new Ecdsa().computePublicKey(this.signingPrivateKey);
22
+ return {
23
+ constructorName: 'constructor',
24
+ constructorArgs: [[...signingPublicKey.subarray(0, 32)], [...signingPublicKey.subarray(32, 64)]],
25
+ };
26
+ }
27
+
28
+ getAuthWitnessProvider(_address: CompleteAddress): AuthWitnessProvider {
29
+ return new EcdsaKAuthWitnessProvider(this.signingPrivateKey);
30
+ }
31
+ }
32
+
33
+ /** Creates auth witnesses using ECDSA signatures. */
34
+ class EcdsaKAuthWitnessProvider implements AuthWitnessProvider {
35
+ constructor(private signingPrivateKey: Buffer) {}
36
+
37
+ async createAuthWit(messageHash: Fr): Promise<AuthWitness> {
38
+ const ecdsa = new Ecdsa();
39
+ const signature = await ecdsa.constructSignature(messageHash.toBuffer(), this.signingPrivateKey);
40
+ return Promise.resolve(new AuthWitness(messageHash, [...signature.r, ...signature.s]));
41
+ }
42
+ }
@@ -0,0 +1,31 @@
1
+ /**
2
+ * The `@aztec-labs/accounts/ecdsa` export provides an ECDSA account contract implementation, that uses an ECDSA private key for authentication, and a Grumpkin key for encryption.
3
+ * Consider using this account type when working with integrations with Ethereum wallets.
4
+ *
5
+ * @packageDocumentation
6
+ */
7
+ import type { ContractArtifact } from '@aztec-labs/stdlib/abi';
8
+ import { loadContractArtifact } from '@aztec-labs/stdlib/abi';
9
+ import type { NoirCompiledContract } from '@aztec-labs/stdlib/noir';
10
+
11
+ import EcdsaKAccountContractJson from '../../../artifacts/EcdsaKAccount.json' with { type: 'json' };
12
+ import { EcdsaKBaseAccountContract } from './account_contract.js';
13
+
14
+ export const EcdsaKAccountContractArtifact: ContractArtifact = loadContractArtifact(
15
+ EcdsaKAccountContractJson as NoirCompiledContract,
16
+ );
17
+
18
+ /**
19
+ * Account contract that authenticates transactions using ECDSA signatures
20
+ * verified against a secp256k1 public key stored in an immutable encrypted note.
21
+ * Eagerly loads the contract artifact
22
+ */
23
+ export class EcdsaKAccountContract extends EcdsaKBaseAccountContract {
24
+ constructor(signingPrivateKey: Buffer) {
25
+ super(signingPrivateKey);
26
+ }
27
+
28
+ override getContractArtifact(): Promise<ContractArtifact> {
29
+ return Promise.resolve(EcdsaKAccountContractArtifact);
30
+ }
31
+ }
@@ -0,0 +1,39 @@
1
+ /**
2
+ * The `@aztec-labs/accounts/ecdsa` export provides an ECDSA account contract implementation, that uses an ECDSA private key for authentication, and a Grumpkin key for encryption.
3
+ * Consider using this account type when working with integrations with Ethereum wallets.
4
+ *
5
+ * @packageDocumentation
6
+ */
7
+ import type { ContractArtifact } from '@aztec-labs/stdlib/abi';
8
+ import { loadContractArtifact } from '@aztec-labs/stdlib/abi';
9
+
10
+ import { EcdsaKBaseAccountContract } from './account_contract.js';
11
+
12
+ /**
13
+ * Lazily loads the contract artifact
14
+ * @returns The contract artifact for the ecdsa K account contract
15
+ */
16
+ export async function getEcdsaKAccountContractArtifact() {
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: ecdsaKAccountContractJson } = await import('../../../artifacts/EcdsaKAccount.json');
23
+ return loadContractArtifact(ecdsaKAccountContractJson);
24
+ }
25
+
26
+ /**
27
+ * Account contract that authenticates transactions using ECDSA signatures
28
+ * verified against a secp256k1 public key stored in an immutable encrypted note.
29
+ * Lazily loads the contract artifact
30
+ */
31
+ export class EcdsaKAccountContract extends EcdsaKBaseAccountContract {
32
+ constructor(signingPrivateKey: Buffer) {
33
+ super(signingPrivateKey);
34
+ }
35
+
36
+ override getContractArtifact(): Promise<ContractArtifact> {
37
+ return getEcdsaKAccountContractArtifact();
38
+ }
39
+ }
@@ -0,0 +1,42 @@
1
+ import type { AuthWitnessProvider } from '@aztec-labs/aztec.js/account';
2
+ import { Ecdsa } from '@aztec-labs/foundation/crypto/ecdsa';
3
+ import type { Fr } from '@aztec-labs/foundation/curves/bn254';
4
+ import { AuthWitness } from '@aztec-labs/stdlib/auth-witness';
5
+ import { CompleteAddress } from '@aztec-labs/stdlib/contract';
6
+
7
+ import { DefaultAccountContract } from '../../defaults/account_contract.js';
8
+
9
+ /**
10
+ * Account contract that authenticates transactions using ECDSA signatures
11
+ * verified against a secp256r1 public key stored in an immutable encrypted note.
12
+ * This abstract version does not provide a way to retrieve the artifact, as it
13
+ * can be implemented with or without lazy loading.
14
+ */
15
+ export abstract class EcdsaRBaseAccountContract extends DefaultAccountContract {
16
+ constructor(private signingPrivateKey: Buffer) {
17
+ super();
18
+ }
19
+
20
+ async getInitializationFunctionAndArgs() {
21
+ const signingPublicKey = await new Ecdsa('secp256r1').computePublicKey(this.signingPrivateKey);
22
+ return {
23
+ constructorName: 'constructor',
24
+ constructorArgs: [[...signingPublicKey.subarray(0, 32)], [...signingPublicKey.subarray(32, 64)]],
25
+ };
26
+ }
27
+
28
+ getAuthWitnessProvider(_address: CompleteAddress): AuthWitnessProvider {
29
+ return new EcdsaRAuthWitnessProvider(this.signingPrivateKey);
30
+ }
31
+ }
32
+
33
+ /** Creates auth witnesses using ECDSA signatures. */
34
+ class EcdsaRAuthWitnessProvider implements AuthWitnessProvider {
35
+ constructor(private signingPrivateKey: Buffer) {}
36
+
37
+ async createAuthWit(messageHash: Fr): Promise<AuthWitness> {
38
+ const ecdsa = new Ecdsa('secp256r1');
39
+ const signature = await ecdsa.constructSignature(messageHash.toBuffer(), this.signingPrivateKey);
40
+ return Promise.resolve(new AuthWitness(messageHash, [...signature.r, ...signature.s]));
41
+ }
42
+ }
@@ -0,0 +1,31 @@
1
+ /**
2
+ * The `@aztec-labs/accounts/ecdsa` export provides an ECDSA account contract implementation, that uses an ECDSA private key for authentication, and a Grumpkin key for encryption.
3
+ * Consider using this account type when working with integrations with Ethereum wallets.
4
+ *
5
+ * @packageDocumentation
6
+ */
7
+ import type { ContractArtifact } from '@aztec-labs/stdlib/abi';
8
+ import { loadContractArtifact } from '@aztec-labs/stdlib/abi';
9
+ import type { NoirCompiledContract } from '@aztec-labs/stdlib/noir';
10
+
11
+ import EcdsaRAccountContractJson from '../../../artifacts/EcdsaRAccount.json' with { type: 'json' };
12
+ import { EcdsaRBaseAccountContract } from './account_contract.js';
13
+
14
+ export const EcdsaRAccountContractArtifact: ContractArtifact = loadContractArtifact(
15
+ EcdsaRAccountContractJson as NoirCompiledContract,
16
+ );
17
+
18
+ /**
19
+ * Account contract that authenticates transactions using ECDSA signatures
20
+ * verified against a secp256k1 public key stored in an immutable encrypted note.
21
+ * Eagerly loads the contract artifact
22
+ */
23
+ export class EcdsaRAccountContract extends EcdsaRBaseAccountContract {
24
+ constructor(signingPrivateKey: Buffer) {
25
+ super(signingPrivateKey);
26
+ }
27
+
28
+ override getContractArtifact(): Promise<ContractArtifact> {
29
+ return Promise.resolve(EcdsaRAccountContractArtifact);
30
+ }
31
+ }
@@ -0,0 +1,39 @@
1
+ /**
2
+ * The `@aztec-labs/accounts/ecdsa` export provides an ECDSA account contract implementation, that uses an ECDSA private key for authentication, and a Grumpkin key for encryption.
3
+ * Consider using this account type when working with integrations with Ethereum wallets.
4
+ *
5
+ * @packageDocumentation
6
+ */
7
+ import type { ContractArtifact } from '@aztec-labs/stdlib/abi';
8
+ import { loadContractArtifact } from '@aztec-labs/stdlib/abi';
9
+
10
+ import { EcdsaRBaseAccountContract } from './account_contract.js';
11
+
12
+ /**
13
+ * Lazily loads the contract artifact
14
+ * @returns The contract artifact for the ecdsa K account contract
15
+ */
16
+ export async function getEcdsaRAccountContractArtifact() {
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: ecdsaKAccountContractJson } = await import('../../../artifacts/EcdsaRAccount.json');
23
+ return loadContractArtifact(ecdsaKAccountContractJson);
24
+ }
25
+
26
+ /**
27
+ * Account contract that authenticates transactions using ECDSA signatures
28
+ * verified against a secp256k1 public key stored in an immutable encrypted note.
29
+ * Lazily loads the contract artifact
30
+ */
31
+ export class EcdsaRAccountContract extends EcdsaRBaseAccountContract {
32
+ constructor(signingPrivateKey: Buffer) {
33
+ super(signingPrivateKey);
34
+ }
35
+
36
+ override getContractArtifact(): Promise<ContractArtifact> {
37
+ return getEcdsaRAccountContractArtifact();
38
+ }
39
+ }
@@ -0,0 +1,3 @@
1
+ export * from './ecdsa_k/index.js';
2
+ export * from './ecdsa_r/index.js';
3
+ export * from './ssh_ecdsa_r/index.js';
@@ -0,0 +1,3 @@
1
+ export * from './ecdsa_k/lazy.js';
2
+ export * from './ecdsa_r/lazy.js';
3
+ export * from './ssh_ecdsa_r/lazy.js';
@@ -0,0 +1,92 @@
1
+ import type { AuthWitnessProvider } from '@aztec-labs/aztec.js/account';
2
+ import { EcdsaSignature } from '@aztec-labs/foundation/crypto/ecdsa';
3
+ import type { Fr } from '@aztec-labs/foundation/curves/bn254';
4
+ import { AuthWitness } from '@aztec-labs/stdlib/auth-witness';
5
+ import { CompleteAddress } from '@aztec-labs/stdlib/contract';
6
+
7
+ import { DefaultAccountContract } from '../../defaults/account_contract.js';
8
+ import { signWithAgent } from '../../utils/ssh_agent.js';
9
+
10
+ const secp256r1N = 115792089210356248762697446949407573529996955224135760342422259061068512044369n;
11
+ /**
12
+ * Account contract that authenticates transactions using ECDSA signatures
13
+ * verified against a secp256r1 public key stored in an immutable encrypted note.
14
+ * Since this implementation relays signatures to an SSH agent, we provide the
15
+ * public key here not for signature verification, but to identify actual identity
16
+ * that will be used to sign authwitnesses.
17
+ * This abstract version does not provide a way to retrieve the artifact, as it
18
+ * can be implemented with or without lazy loading.
19
+ */
20
+ export abstract class EcdsaRSSHBaseAccountContract extends DefaultAccountContract {
21
+ constructor(private signingPublicKey: Buffer) {
22
+ super();
23
+ }
24
+
25
+ getInitializationFunctionAndArgs() {
26
+ return Promise.resolve({
27
+ constructorName: 'constructor',
28
+ constructorArgs: [[...this.signingPublicKey.subarray(0, 32)], [...this.signingPublicKey.subarray(32, 64)]],
29
+ });
30
+ }
31
+
32
+ getAuthWitnessProvider(_address: CompleteAddress): AuthWitnessProvider {
33
+ return new SSHEcdsaRAuthWitnessProvider(this.signingPublicKey);
34
+ }
35
+ }
36
+
37
+ /** Creates auth witnesses using ECDSA signatures. */
38
+ class SSHEcdsaRAuthWitnessProvider implements AuthWitnessProvider {
39
+ constructor(private signingPublicKey: Buffer) {}
40
+
41
+ #parseECDSASignature(data: Buffer) {
42
+ // Extract ECDSA signature components
43
+ let offset = 0;
44
+ const sigTypeLen = data.readUInt32BE(offset);
45
+ offset += 4;
46
+ const sigType = data.subarray(offset, offset + sigTypeLen).toString();
47
+ offset += sigTypeLen;
48
+
49
+ if (sigType !== 'ecdsa-sha2-nistp256') {
50
+ throw new Error(`Unexpected signature type: ${sigType}`);
51
+ }
52
+
53
+ offset += 4;
54
+ const rLen = data.readUInt32BE(offset);
55
+ offset += 4;
56
+ let r = data.subarray(offset, offset + rLen);
57
+ offset += rLen;
58
+
59
+ const sLen = data.readUInt32BE(offset);
60
+ offset += 4;
61
+ let s = data.subarray(offset, offset + sLen);
62
+
63
+ // R and S are encoded using ASN.1 DER format, which may include a leading zero byte to avoid interpreting the value as negative
64
+ if (r.length > 32) {
65
+ r = Buffer.from(Uint8Array.prototype.slice.call(r, 1));
66
+ }
67
+
68
+ if (s.length > 32) {
69
+ s = Buffer.from(Uint8Array.prototype.slice.call(s, 1));
70
+ }
71
+
72
+ const maybeHighS = BigInt(`0x${s.toString('hex')}`);
73
+
74
+ // ECDSA signatures must have a low S value so they can be used as a nullifier. BB forces a value of 27 for v, so
75
+ // only one PublicKey can verify the signature (and not its negated counterpart) https://ethereum.stackexchange.com/a/55728
76
+ if (maybeHighS > secp256r1N / 2n + 1n) {
77
+ s = Buffer.from((secp256r1N - maybeHighS).toString(16), 'hex');
78
+ }
79
+
80
+ return new EcdsaSignature(r, s, Buffer.from([0]));
81
+ }
82
+
83
+ async createAuthWit(messageHash: Fr): Promise<AuthWitness> {
84
+ // Key type and curve name
85
+ const keyType = Buffer.from('ecdsa-sha2-nistp256');
86
+ const curveName = Buffer.from('nistp256');
87
+ const data = await signWithAgent(keyType, curveName, this.signingPublicKey, messageHash.toBuffer());
88
+ const signature = this.#parseECDSASignature(data);
89
+
90
+ return new AuthWitness(messageHash, [...signature.r, ...signature.s]);
91
+ }
92
+ }
@@ -0,0 +1,28 @@
1
+ /**
2
+ * The `@aztec-labs/accounts/ecdsa` export provides an ECDSA account contract implementation, that uses an ECDSA private key for authentication, and a Grumpkin key for encryption.
3
+ * Consider using this account type when working with integrations with Ethereum wallets.
4
+ *
5
+ * @packageDocumentation
6
+ */
7
+ import type { ContractArtifact } from '@aztec-labs/stdlib/abi';
8
+
9
+ import { EcdsaRAccountContractArtifact } from '../ecdsa_r/index.js';
10
+ import { EcdsaRSSHBaseAccountContract } from './account_contract.js';
11
+
12
+ /**
13
+ * Account contract that authenticates transactions using ECDSA signatures
14
+ * verified against a secp256r1 public key stored in an immutable encrypted note.
15
+ * Since this implementation relays signatures to an SSH agent, we provide the
16
+ * public key here not for signature verification, but to identify actual identity
17
+ * that will be used to sign authwitnesses.
18
+ * Eagerly loads the contract artifact
19
+ */
20
+ export class EcdsaRSSHAccountContract extends EcdsaRSSHBaseAccountContract {
21
+ constructor(signingPublicKey: Buffer) {
22
+ super(signingPublicKey);
23
+ }
24
+
25
+ override getContractArtifact(): Promise<ContractArtifact> {
26
+ return Promise.resolve(EcdsaRAccountContractArtifact);
27
+ }
28
+ }
@@ -0,0 +1,28 @@
1
+ /**
2
+ * The `@aztec-labs/accounts/ecdsa` export provides an ECDSA account contract implementation, that uses an ECDSA private key for authentication, and a Grumpkin key for encryption.
3
+ * Consider using this account type when working with integrations with Ethereum wallets.
4
+ *
5
+ * @packageDocumentation
6
+ */
7
+ import type { ContractArtifact } from '@aztec-labs/stdlib/abi';
8
+
9
+ import { getEcdsaRAccountContractArtifact } from '../ecdsa_r/lazy.js';
10
+ import { EcdsaRSSHBaseAccountContract } from './account_contract.js';
11
+
12
+ /**
13
+ * Account contract that authenticates transactions using ECDSA signatures
14
+ * verified against a secp256r1 public key stored in an immutable encrypted note.
15
+ * Since this implementation relays signatures to an SSH agent, we provide the
16
+ * public key here not for signature verification, but to identify actual identity
17
+ * that will be used to sign authwitnesses.
18
+ * Lazily loads the contract artifact
19
+ */
20
+ export class EcdsaRSSHAccountContract extends EcdsaRSSHBaseAccountContract {
21
+ constructor(signingPublicKey: Buffer) {
22
+ super(signingPublicKey);
23
+ }
24
+
25
+ override getContractArtifact(): Promise<ContractArtifact> {
26
+ return getEcdsaRAccountContractArtifact();
27
+ }
28
+ }
@@ -0,0 +1,28 @@
1
+ import { BaseAccount } from '@aztec-labs/aztec.js/account';
2
+ import type { CompleteAddress } from '@aztec-labs/aztec.js/addresses';
3
+ import { DefaultAccountEntrypoint } from '@aztec-labs/entrypoints/account';
4
+ import { loadContractArtifact } from '@aztec-labs/stdlib/abi';
5
+ import type { NoirCompiledContract } from '@aztec-labs/stdlib/noir';
6
+
7
+ import SimulatedEcdsaAccountJson from '../../../artifacts/SimulatedEcdsaAccount.json' with { type: 'json' };
8
+ import { StubBaseAccountContract } from '../../defaults/stub_account_contract.js';
9
+
10
+ export const StubEcdsaAccountContractArtifact = loadContractArtifact(SimulatedEcdsaAccountJson as NoirCompiledContract);
11
+
12
+ /** Stub account contract for ECDSA accounts (secp256k1 and secp256r1). Eagerly loads the contract artifact. */
13
+ export class StubEcdsaAccountContract extends StubBaseAccountContract {
14
+ override getContractArtifact() {
15
+ return Promise.resolve(StubEcdsaAccountContractArtifact);
16
+ }
17
+ }
18
+
19
+ /** Creates an ECDSA stub account that impersonates the one with the provided address. */
20
+ export function createStubEcdsaAccount(originalAddress: CompleteAddress) {
21
+ const accountContract = new StubEcdsaAccountContract();
22
+ const authWitnessProvider = accountContract.getAuthWitnessProvider(originalAddress);
23
+ return new BaseAccount(
24
+ new DefaultAccountEntrypoint(originalAddress.address, authWitnessProvider),
25
+ authWitnessProvider,
26
+ originalAddress,
27
+ );
28
+ }
@@ -0,0 +1,34 @@
1
+ import { BaseAccount } from '@aztec-labs/aztec.js/account';
2
+ import type { CompleteAddress } from '@aztec-labs/aztec.js/addresses';
3
+ import { DefaultAccountEntrypoint } from '@aztec-labs/entrypoints/account';
4
+ import { loadContractArtifact } from '@aztec-labs/stdlib/abi';
5
+
6
+ import { StubBaseAccountContract } from '../../defaults/stub_account_contract.js';
7
+
8
+ /**
9
+ * Lazily loads the ECDSA stub contract artifact (browser-compatible).
10
+ */
11
+ export async function getStubEcdsaAccountContractArtifact() {
12
+ // Cannot assert this import as it's incompatible with bundlers like vite
13
+ // https://github.com/vitejs/vite/issues/19095#issuecomment-2566074352
14
+ const { default: json } = await import('../../../artifacts/SimulatedEcdsaAccount.json');
15
+ return loadContractArtifact(json);
16
+ }
17
+
18
+ /** Stub account contract for ECDSA accounts (secp256k1 and secp256r1). Lazily loads the contract artifact. */
19
+ export class StubEcdsaAccountContract extends StubBaseAccountContract {
20
+ override getContractArtifact() {
21
+ return getStubEcdsaAccountContractArtifact();
22
+ }
23
+ }
24
+
25
+ /** Creates an ECDSA stub account that impersonates the one with the provided address. */
26
+ export function createStubEcdsaAccount(originalAddress: CompleteAddress) {
27
+ const accountContract = new StubEcdsaAccountContract();
28
+ const authWitnessProvider = accountContract.getAuthWitnessProvider(originalAddress);
29
+ return new BaseAccount(
30
+ new DefaultAccountEntrypoint(originalAddress.address, authWitnessProvider),
31
+ authWitnessProvider,
32
+ originalAddress,
33
+ );
34
+ }