@aztec/accounts 0.0.0-test.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +41 -0
- package/artifacts/EcdsaKAccount.d.json.ts +3 -0
- package/artifacts/EcdsaKAccount.json +6257 -0
- package/artifacts/EcdsaRAccount.d.json.ts +3 -0
- package/artifacts/EcdsaRAccount.json +6257 -0
- package/artifacts/SchnorrAccount.d.json.ts +3 -0
- package/artifacts/SchnorrAccount.json +6354 -0
- package/artifacts/SchnorrSingleKeyAccount.d.json.ts +3 -0
- package/artifacts/SchnorrSingleKeyAccount.json +3937 -0
- package/dest/dapp/dapp_interface.d.ts +10 -0
- package/dest/dapp/dapp_interface.d.ts.map +1 -0
- package/dest/dapp/dapp_interface.js +16 -0
- package/dest/dapp/index.d.ts +2 -0
- package/dest/dapp/index.d.ts.map +1 -0
- package/dest/dapp/index.js +1 -0
- package/dest/defaults/account_contract.d.ts +15 -0
- package/dest/defaults/account_contract.d.ts.map +1 -0
- package/dest/defaults/account_contract.js +10 -0
- package/dest/defaults/account_interface.d.ts +27 -0
- package/dest/defaults/account_interface.d.ts.map +1 -0
- package/dest/defaults/account_interface.js +37 -0
- package/dest/defaults/index.d.ts +10 -0
- package/dest/defaults/index.d.ts.map +1 -0
- package/dest/defaults/index.js +8 -0
- package/dest/ecdsa/ecdsa_k/account_contract.d.ts +18 -0
- package/dest/ecdsa/ecdsa_k/account_contract.d.ts.map +1 -0
- package/dest/ecdsa/ecdsa_k/account_contract.js +38 -0
- package/dest/ecdsa/ecdsa_k/index.d.ts +43 -0
- package/dest/ecdsa/ecdsa_k/index.d.ts.map +1 -0
- package/dest/ecdsa/ecdsa_k/index.js +44 -0
- package/dest/ecdsa/ecdsa_k/lazy.d.ts +47 -0
- package/dest/ecdsa/ecdsa_k/lazy.d.ts.map +1 -0
- package/dest/ecdsa/ecdsa_k/lazy.js +52 -0
- package/dest/ecdsa/index.d.ts +3 -0
- package/dest/ecdsa/index.d.ts.map +1 -0
- package/dest/ecdsa/index.js +2 -0
- package/dest/ecdsa/lazy.d.ts +3 -0
- package/dest/ecdsa/lazy.d.ts.map +1 -0
- package/dest/ecdsa/lazy.js +2 -0
- package/dest/ecdsa/ssh_ecdsa_r/account_contract.d.ts +21 -0
- package/dest/ecdsa/ssh_ecdsa_r/account_contract.d.ts.map +1 -0
- package/dest/ecdsa/ssh_ecdsa_r/account_contract.js +80 -0
- package/dest/ecdsa/ssh_ecdsa_r/index.d.ts +46 -0
- package/dest/ecdsa/ssh_ecdsa_r/index.d.ts.map +1 -0
- package/dest/ecdsa/ssh_ecdsa_r/index.js +47 -0
- package/dest/ecdsa/ssh_ecdsa_r/lazy.d.ts +49 -0
- package/dest/ecdsa/ssh_ecdsa_r/lazy.d.ts.map +1 -0
- package/dest/ecdsa/ssh_ecdsa_r/lazy.js +57 -0
- package/dest/schnorr/account_contract.d.ts +24 -0
- package/dest/schnorr/account_contract.d.ts.map +1 -0
- package/dest/schnorr/account_contract.js +37 -0
- package/dest/schnorr/index.d.ts +57 -0
- package/dest/schnorr/index.d.ts.map +1 -0
- package/dest/schnorr/index.js +66 -0
- package/dest/schnorr/lazy.d.ts +61 -0
- package/dest/schnorr/lazy.d.ts.map +1 -0
- package/dest/schnorr/lazy.js +74 -0
- package/dest/single_key/account_contract.d.ts +17 -0
- package/dest/single_key/account_contract.d.ts.map +1 -0
- package/dest/single_key/account_contract.js +42 -0
- package/dest/single_key/index.d.ts +39 -0
- package/dest/single_key/index.d.ts.map +1 -0
- package/dest/single_key/index.js +45 -0
- package/dest/single_key/lazy.d.ts +43 -0
- package/dest/single_key/lazy.d.ts.map +1 -0
- package/dest/single_key/lazy.js +53 -0
- package/dest/testing/configuration.d.ts +28 -0
- package/dest/testing/configuration.d.ts.map +1 -0
- package/dest/testing/configuration.js +15 -0
- package/dest/testing/create_account.d.ts +43 -0
- package/dest/testing/create_account.d.ts.map +1 -0
- package/dest/testing/create_account.js +58 -0
- package/dest/testing/index.d.ts +35 -0
- package/dest/testing/index.d.ts.map +1 -0
- package/dest/testing/index.js +47 -0
- package/dest/testing/lazy.d.ts +34 -0
- package/dest/testing/lazy.d.ts.map +1 -0
- package/dest/testing/lazy.js +46 -0
- package/dest/utils/index.d.ts +2 -0
- package/dest/utils/index.d.ts.map +1 -0
- package/dest/utils/index.js +1 -0
- package/dest/utils/ssh_agent.d.ts +36 -0
- package/dest/utils/ssh_agent.d.ts.map +1 -0
- package/dest/utils/ssh_agent.js +153 -0
- package/package.json +106 -0
- package/src/dapp/dapp_interface.ts +38 -0
- package/src/dapp/index.ts +1 -0
- package/src/defaults/account_contract.ts +21 -0
- package/src/defaults/account_interface.ts +59 -0
- package/src/defaults/index.ts +10 -0
- package/src/ecdsa/ecdsa_k/account_contract.ts +39 -0
- package/src/ecdsa/ecdsa_k/index.ts +63 -0
- package/src/ecdsa/ecdsa_k/lazy.ts +71 -0
- package/src/ecdsa/index.ts +2 -0
- package/src/ecdsa/lazy.ts +2 -0
- package/src/ecdsa/ssh_ecdsa_r/account_contract.ts +89 -0
- package/src/ecdsa/ssh_ecdsa_r/index.ts +67 -0
- package/src/ecdsa/ssh_ecdsa_r/lazy.ts +78 -0
- package/src/schnorr/account_contract.ts +39 -0
- package/src/schnorr/index.ts +97 -0
- package/src/schnorr/lazy.ts +107 -0
- package/src/single_key/account_contract.ts +43 -0
- package/src/single_key/index.ts +63 -0
- package/src/single_key/lazy.ts +71 -0
- package/src/testing/configuration.ts +39 -0
- package/src/testing/create_account.ts +93 -0
- package/src/testing/index.ts +92 -0
- package/src/testing/lazy.ts +86 -0
- package/src/utils/index.ts +1 -0
- package/src/utils/ssh_agent.ts +136 -0
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
import { Buffer } from 'buffer';
|
|
2
|
+
import net from 'net';
|
|
3
|
+
const SSH_AGENT_IDENTITIES_REQUEST = 11;
|
|
4
|
+
const SSH_AGENT_IDENTITIES_RESPONSE = 12;
|
|
5
|
+
const SSH_AGENT_SIGN_REQUEST = 13;
|
|
6
|
+
const SSH_AGENT_SIGN_RESPONSE = 14;
|
|
7
|
+
/**
|
|
8
|
+
* Connect to the SSH agent via a TCP socket using the standard env variable
|
|
9
|
+
*/ export function connectToAgent() {
|
|
10
|
+
const socketPath = process.env.SSH_AUTH_SOCK;
|
|
11
|
+
if (!socketPath) {
|
|
12
|
+
throw new Error('SSH_AUTH_SOCK is not set');
|
|
13
|
+
}
|
|
14
|
+
return net.connect(socketPath);
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Retrieve the identities stored in the SSH agent.
|
|
18
|
+
*/ export function getIdentities() {
|
|
19
|
+
return new Promise((resolve, reject)=>{
|
|
20
|
+
const stream = connectToAgent();
|
|
21
|
+
stream.on('connect', ()=>{
|
|
22
|
+
const request = Buffer.concat([
|
|
23
|
+
Buffer.from([
|
|
24
|
+
0,
|
|
25
|
+
0,
|
|
26
|
+
0,
|
|
27
|
+
5 + 4
|
|
28
|
+
]),
|
|
29
|
+
Buffer.from([
|
|
30
|
+
SSH_AGENT_IDENTITIES_REQUEST
|
|
31
|
+
]),
|
|
32
|
+
Buffer.from([
|
|
33
|
+
0,
|
|
34
|
+
0,
|
|
35
|
+
0,
|
|
36
|
+
0
|
|
37
|
+
])
|
|
38
|
+
]);
|
|
39
|
+
stream.write(request);
|
|
40
|
+
});
|
|
41
|
+
stream.on('data', (data)=>{
|
|
42
|
+
const responseType = data[4];
|
|
43
|
+
if (responseType === SSH_AGENT_IDENTITIES_RESPONSE) {
|
|
44
|
+
let offset = 5;
|
|
45
|
+
const numKeys = data.readUInt32BE(offset);
|
|
46
|
+
offset += 4;
|
|
47
|
+
const keys = [];
|
|
48
|
+
for(let i = 0; i < numKeys; i++){
|
|
49
|
+
const keyLength = data.readUInt32BE(offset);
|
|
50
|
+
offset += 4;
|
|
51
|
+
const key = data.subarray(offset, offset + keyLength);
|
|
52
|
+
offset += keyLength;
|
|
53
|
+
const commentLength = data.readUInt32BE(offset);
|
|
54
|
+
offset += 4;
|
|
55
|
+
const comment = data.subarray(offset, offset + commentLength);
|
|
56
|
+
offset += commentLength;
|
|
57
|
+
let keyOffset = 0;
|
|
58
|
+
const typeLen = key.readUInt32BE(keyOffset);
|
|
59
|
+
keyOffset += 4;
|
|
60
|
+
const type = key.subarray(keyOffset, keyOffset + typeLen);
|
|
61
|
+
keys.push({
|
|
62
|
+
type: type.toString('ascii'),
|
|
63
|
+
publicKey: key.toString('base64'),
|
|
64
|
+
comment: comment.toString('utf8')
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
stream.end();
|
|
68
|
+
resolve(keys);
|
|
69
|
+
} else {
|
|
70
|
+
stream.end();
|
|
71
|
+
reject(`Unexpected response type: ${responseType}`);
|
|
72
|
+
}
|
|
73
|
+
});
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Sign data using a key stored in the SSH agent. The private signing key is identified by its corresponding public key.
|
|
78
|
+
*/ export function signWithAgent(keyType, curveName, publicKey, data) {
|
|
79
|
+
return new Promise((resolve, reject)=>{
|
|
80
|
+
const stream = connectToAgent();
|
|
81
|
+
stream.on('connect', ()=>{
|
|
82
|
+
// Construct the key blob
|
|
83
|
+
const keyBlob = Buffer.concat([
|
|
84
|
+
Buffer.from([
|
|
85
|
+
0,
|
|
86
|
+
0,
|
|
87
|
+
0,
|
|
88
|
+
keyType.length
|
|
89
|
+
]),
|
|
90
|
+
keyType,
|
|
91
|
+
Buffer.from([
|
|
92
|
+
0,
|
|
93
|
+
0,
|
|
94
|
+
0,
|
|
95
|
+
curveName.length
|
|
96
|
+
]),
|
|
97
|
+
curveName,
|
|
98
|
+
Buffer.from([
|
|
99
|
+
0,
|
|
100
|
+
0,
|
|
101
|
+
0,
|
|
102
|
+
publicKey.length + 1,
|
|
103
|
+
4
|
|
104
|
+
]),
|
|
105
|
+
publicKey
|
|
106
|
+
]);
|
|
107
|
+
const request = Buffer.concat([
|
|
108
|
+
Buffer.from([
|
|
109
|
+
0,
|
|
110
|
+
0,
|
|
111
|
+
0,
|
|
112
|
+
5 + keyBlob.length + 4 + data.length + 4
|
|
113
|
+
]),
|
|
114
|
+
Buffer.from([
|
|
115
|
+
SSH_AGENT_SIGN_REQUEST
|
|
116
|
+
]),
|
|
117
|
+
Buffer.from([
|
|
118
|
+
0,
|
|
119
|
+
0,
|
|
120
|
+
0,
|
|
121
|
+
keyBlob.length
|
|
122
|
+
]),
|
|
123
|
+
keyBlob,
|
|
124
|
+
Buffer.from([
|
|
125
|
+
0,
|
|
126
|
+
0,
|
|
127
|
+
0,
|
|
128
|
+
data.length
|
|
129
|
+
]),
|
|
130
|
+
data,
|
|
131
|
+
Buffer.from([
|
|
132
|
+
0,
|
|
133
|
+
0,
|
|
134
|
+
0,
|
|
135
|
+
0
|
|
136
|
+
])
|
|
137
|
+
]);
|
|
138
|
+
stream.write(request);
|
|
139
|
+
});
|
|
140
|
+
stream.on('data', (data)=>{
|
|
141
|
+
const type = data[4];
|
|
142
|
+
if (type === SSH_AGENT_SIGN_RESPONSE) {
|
|
143
|
+
const signatureLength = data.readUInt32BE(5);
|
|
144
|
+
const signature = data.subarray(9, 9 + signatureLength);
|
|
145
|
+
stream.end();
|
|
146
|
+
resolve(signature);
|
|
147
|
+
} else {
|
|
148
|
+
stream.end();
|
|
149
|
+
reject(`Unexpected response type: ${type}`);
|
|
150
|
+
}
|
|
151
|
+
});
|
|
152
|
+
});
|
|
153
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@aztec/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": "0.0.0-test.0",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"exports": {
|
|
8
|
+
"./dapp": "./dest/dapp/index.js",
|
|
9
|
+
"./defaults": "./dest/defaults/index.js",
|
|
10
|
+
"./ecdsa": "./dest/ecdsa/index.js",
|
|
11
|
+
"./ecdsa/lazy": "./dest/ecdsa/lazy.js",
|
|
12
|
+
"./schnorr": "./dest/schnorr/index.js",
|
|
13
|
+
"./schnorr/lazy": "./dest/schnorr/lazy.js",
|
|
14
|
+
"./single_key": "./dest/single_key/index.js",
|
|
15
|
+
"./single_key/lazy": "./dest/single_key/lazy.js",
|
|
16
|
+
"./testing": "./dest/testing/index.js",
|
|
17
|
+
"./testing/lazy": "./dest/testing/lazy.js",
|
|
18
|
+
"./utils": "./dest/utils/index.js"
|
|
19
|
+
},
|
|
20
|
+
"typedocOptions": {
|
|
21
|
+
"entryPoints": [
|
|
22
|
+
"./src/defaults/index.ts",
|
|
23
|
+
"./src/ecdsa/index.ts",
|
|
24
|
+
"./src/schnorr/index.ts",
|
|
25
|
+
"./src/single_key/index.ts",
|
|
26
|
+
"./src/testing/index.ts"
|
|
27
|
+
],
|
|
28
|
+
"name": "Accounts",
|
|
29
|
+
"tsconfig": "./tsconfig.json"
|
|
30
|
+
},
|
|
31
|
+
"scripts": {
|
|
32
|
+
"build": "yarn clean && yarn generate && tsc -b",
|
|
33
|
+
"generate": "yarn generate:noir-contracts",
|
|
34
|
+
"generate:noir-contracts": "./scripts/copy-contracts.sh",
|
|
35
|
+
"build:dev": "tsc -b --watch",
|
|
36
|
+
"build:ts": "tsc -b",
|
|
37
|
+
"clean": "rm -rf ./dest .tsbuildinfo ./artifacts",
|
|
38
|
+
"formatting": "run -T prettier --check ./src && run -T eslint ./src",
|
|
39
|
+
"formatting:fix": "run -T eslint --fix ./src && run -T prettier -w ./src",
|
|
40
|
+
"test": "NODE_NO_WARNINGS=1 node --experimental-vm-modules ../node_modules/.bin/jest --passWithNoTests --maxWorkers=${JEST_MAX_WORKERS:-8}"
|
|
41
|
+
},
|
|
42
|
+
"inherits": [
|
|
43
|
+
"../package.common.json",
|
|
44
|
+
"./package.local.json"
|
|
45
|
+
],
|
|
46
|
+
"jest": {
|
|
47
|
+
"moduleNameMapper": {
|
|
48
|
+
"^(\\.{1,2}/.*)\\.[cm]?js$": "$1"
|
|
49
|
+
},
|
|
50
|
+
"testRegex": "./src/.*\\.test\\.(js|mjs|ts)$",
|
|
51
|
+
"rootDir": "./src",
|
|
52
|
+
"transform": {
|
|
53
|
+
"^.+\\.tsx?$": [
|
|
54
|
+
"@swc/jest",
|
|
55
|
+
{
|
|
56
|
+
"jsc": {
|
|
57
|
+
"parser": {
|
|
58
|
+
"syntax": "typescript",
|
|
59
|
+
"decorators": true
|
|
60
|
+
},
|
|
61
|
+
"transform": {
|
|
62
|
+
"decoratorVersion": "2022-03"
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
]
|
|
67
|
+
},
|
|
68
|
+
"extensionsToTreatAsEsm": [
|
|
69
|
+
".ts"
|
|
70
|
+
],
|
|
71
|
+
"reporters": [
|
|
72
|
+
"default"
|
|
73
|
+
],
|
|
74
|
+
"testTimeout": 120000,
|
|
75
|
+
"setupFiles": [
|
|
76
|
+
"../../foundation/src/jest/setup.mjs"
|
|
77
|
+
]
|
|
78
|
+
},
|
|
79
|
+
"dependencies": {
|
|
80
|
+
"@aztec/aztec.js": "0.0.0-test.0",
|
|
81
|
+
"@aztec/entrypoints": "0.0.0-test.0",
|
|
82
|
+
"@aztec/ethereum": "0.0.0-test.0",
|
|
83
|
+
"@aztec/foundation": "0.0.0-test.0",
|
|
84
|
+
"@aztec/stdlib": "0.0.0-test.0",
|
|
85
|
+
"tslib": "^2.4.0"
|
|
86
|
+
},
|
|
87
|
+
"devDependencies": {
|
|
88
|
+
"@jest/globals": "^29.5.0",
|
|
89
|
+
"@types/jest": "^29.5.0",
|
|
90
|
+
"@types/node": "^18.7.23",
|
|
91
|
+
"jest": "^29.5.0",
|
|
92
|
+
"jest-mock-extended": "^3.0.3",
|
|
93
|
+
"ts-loader": "^9.4.4",
|
|
94
|
+
"ts-node": "^10.9.1",
|
|
95
|
+
"typescript": "^5.0.4"
|
|
96
|
+
},
|
|
97
|
+
"files": [
|
|
98
|
+
"dest",
|
|
99
|
+
"src",
|
|
100
|
+
"!*.test.*",
|
|
101
|
+
"artifacts"
|
|
102
|
+
],
|
|
103
|
+
"engines": {
|
|
104
|
+
"node": ">=18"
|
|
105
|
+
}
|
|
106
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import {
|
|
2
|
+
type AccountWallet,
|
|
3
|
+
type AuthWitnessProvider,
|
|
4
|
+
AztecAddress,
|
|
5
|
+
CompleteAddress,
|
|
6
|
+
type NodeInfo,
|
|
7
|
+
} from '@aztec/aztec.js';
|
|
8
|
+
import { DefaultDappEntrypoint } from '@aztec/entrypoints/dapp';
|
|
9
|
+
|
|
10
|
+
import { DefaultAccountInterface } from '../defaults/account_interface.js';
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Default implementation for an account interface that uses a dapp entrypoint.
|
|
14
|
+
*/
|
|
15
|
+
export class DefaultDappInterface extends DefaultAccountInterface {
|
|
16
|
+
constructor(
|
|
17
|
+
authWitnessProvider: AuthWitnessProvider,
|
|
18
|
+
userAddress: CompleteAddress,
|
|
19
|
+
dappAddress: AztecAddress,
|
|
20
|
+
nodeInfo: Pick<NodeInfo, 'l1ChainId' | 'protocolVersion'>,
|
|
21
|
+
) {
|
|
22
|
+
super(authWitnessProvider, userAddress, nodeInfo);
|
|
23
|
+
this.entrypoint = new DefaultDappEntrypoint(
|
|
24
|
+
userAddress.address,
|
|
25
|
+
authWitnessProvider,
|
|
26
|
+
dappAddress,
|
|
27
|
+
nodeInfo.l1ChainId,
|
|
28
|
+
nodeInfo.protocolVersion,
|
|
29
|
+
);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
static createFromUserWallet(wallet: AccountWallet, dappAddress: AztecAddress): DefaultDappInterface {
|
|
33
|
+
return new DefaultDappInterface(wallet, wallet.getCompleteAddress(), dappAddress, {
|
|
34
|
+
l1ChainId: wallet.getChainId().toNumber(),
|
|
35
|
+
protocolVersion: wallet.getVersion().toNumber(),
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './dapp_interface.js';
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { AccountContract, AccountInterface, AuthWitnessProvider } from '@aztec/aztec.js/account';
|
|
2
|
+
import type { ContractArtifact } from '@aztec/stdlib/abi';
|
|
3
|
+
import type { CompleteAddress, NodeInfo } from '@aztec/stdlib/contract';
|
|
4
|
+
|
|
5
|
+
import { DefaultAccountInterface } from '../defaults/account_interface.js';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Base class for implementing an account contract. Requires that the account uses the
|
|
9
|
+
* default entrypoint method signature.
|
|
10
|
+
*/
|
|
11
|
+
export abstract class DefaultAccountContract implements AccountContract {
|
|
12
|
+
abstract getAuthWitnessProvider(address: CompleteAddress): AuthWitnessProvider;
|
|
13
|
+
abstract getDeploymentArgs(): Promise<any[] | undefined>;
|
|
14
|
+
abstract getContractArtifact(): Promise<ContractArtifact>;
|
|
15
|
+
|
|
16
|
+
constructor() {}
|
|
17
|
+
|
|
18
|
+
getInterface(address: CompleteAddress, nodeInfo: NodeInfo): AccountInterface {
|
|
19
|
+
return new DefaultAccountInterface(this.getAuthWitnessProvider(address), address, nodeInfo);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import type { AccountInterface, AuthWitnessProvider } from '@aztec/aztec.js/account';
|
|
2
|
+
import type { EntrypointInterface, ExecutionRequestInit } from '@aztec/aztec.js/entrypoint';
|
|
3
|
+
import { DefaultAccountEntrypoint } from '@aztec/entrypoints/account';
|
|
4
|
+
import { Fr } from '@aztec/foundation/fields';
|
|
5
|
+
import type { AuthWitness } from '@aztec/stdlib/auth-witness';
|
|
6
|
+
import type { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
7
|
+
import { CompleteAddress } from '@aztec/stdlib/contract';
|
|
8
|
+
import type { NodeInfo } from '@aztec/stdlib/contract';
|
|
9
|
+
import type { TxExecutionRequest } from '@aztec/stdlib/tx';
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Default implementation for an account interface. Requires that the account uses the default
|
|
13
|
+
* entrypoint signature, which accept an AppPayload and a FeePayload as defined in noir-libs/aztec-noir/src/entrypoint module
|
|
14
|
+
*/
|
|
15
|
+
export class DefaultAccountInterface implements AccountInterface {
|
|
16
|
+
protected entrypoint: EntrypointInterface;
|
|
17
|
+
|
|
18
|
+
private chainId: Fr;
|
|
19
|
+
private version: Fr;
|
|
20
|
+
|
|
21
|
+
constructor(
|
|
22
|
+
private authWitnessProvider: AuthWitnessProvider,
|
|
23
|
+
private address: CompleteAddress,
|
|
24
|
+
nodeInfo: Pick<NodeInfo, 'l1ChainId' | 'protocolVersion'>,
|
|
25
|
+
) {
|
|
26
|
+
this.entrypoint = new DefaultAccountEntrypoint(
|
|
27
|
+
address.address,
|
|
28
|
+
authWitnessProvider,
|
|
29
|
+
nodeInfo.l1ChainId,
|
|
30
|
+
nodeInfo.protocolVersion,
|
|
31
|
+
);
|
|
32
|
+
this.chainId = new Fr(nodeInfo.l1ChainId);
|
|
33
|
+
this.version = new Fr(nodeInfo.protocolVersion);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
createTxExecutionRequest(execution: ExecutionRequestInit): Promise<TxExecutionRequest> {
|
|
37
|
+
return this.entrypoint.createTxExecutionRequest(execution);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
createAuthWit(messageHash: Fr): Promise<AuthWitness> {
|
|
41
|
+
return this.authWitnessProvider.createAuthWit(messageHash);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
getCompleteAddress(): CompleteAddress {
|
|
45
|
+
return this.address;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
getAddress(): AztecAddress {
|
|
49
|
+
return this.address.address;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
getChainId(): Fr {
|
|
53
|
+
return this.chainId;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
getVersion(): Fr {
|
|
57
|
+
return this.version;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The `@aztec/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/codealong/contract_tutorials/write_accounts_contract | Writing an account contract}.
|
|
5
|
+
*
|
|
6
|
+
* @packageDocumentation
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
export * from './account_interface.js';
|
|
10
|
+
export * from './account_contract.js';
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type { AuthWitnessProvider } from '@aztec/aztec.js/account';
|
|
2
|
+
import { Ecdsa } from '@aztec/foundation/crypto';
|
|
3
|
+
import type { Fr } from '@aztec/foundation/fields';
|
|
4
|
+
import { AuthWitness } from '@aztec/stdlib/auth-witness';
|
|
5
|
+
import { CompleteAddress } from '@aztec/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 getDeploymentArgs() {
|
|
21
|
+
const signingPublicKey = await new Ecdsa().computePublicKey(this.signingPrivateKey);
|
|
22
|
+
return [signingPublicKey.subarray(0, 32), signingPublicKey.subarray(32, 64)];
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
getAuthWitnessProvider(_address: CompleteAddress): AuthWitnessProvider {
|
|
26
|
+
return new EcdsaKAuthWitnessProvider(this.signingPrivateKey);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/** Creates auth witnesses using ECDSA signatures. */
|
|
31
|
+
class EcdsaKAuthWitnessProvider implements AuthWitnessProvider {
|
|
32
|
+
constructor(private signingPrivateKey: Buffer) {}
|
|
33
|
+
|
|
34
|
+
async createAuthWit(messageHash: Fr): Promise<AuthWitness> {
|
|
35
|
+
const ecdsa = new Ecdsa();
|
|
36
|
+
const signature = await ecdsa.constructSignature(messageHash.toBuffer(), this.signingPrivateKey);
|
|
37
|
+
return Promise.resolve(new AuthWitness(messageHash, [...signature.r, ...signature.s]));
|
|
38
|
+
}
|
|
39
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 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.
|
|
3
|
+
* Consider using this account type when working with integrations with Ethereum wallets.
|
|
4
|
+
*
|
|
5
|
+
* @packageDocumentation
|
|
6
|
+
*/
|
|
7
|
+
import { AccountManager, type Salt } from '@aztec/aztec.js/account';
|
|
8
|
+
import { type AccountWallet, getWallet } from '@aztec/aztec.js/wallet';
|
|
9
|
+
import { Fr } from '@aztec/foundation/fields';
|
|
10
|
+
import type { ContractArtifact } from '@aztec/stdlib/abi';
|
|
11
|
+
import { loadContractArtifact } from '@aztec/stdlib/abi';
|
|
12
|
+
import { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
13
|
+
import type { PXE } from '@aztec/stdlib/interfaces/client';
|
|
14
|
+
import type { NoirCompiledContract } from '@aztec/stdlib/noir';
|
|
15
|
+
|
|
16
|
+
import EcdsaKAccountContractJson from '../../../artifacts/EcdsaKAccount.json' assert { type: 'json' };
|
|
17
|
+
import { EcdsaKBaseAccountContract } from './account_contract.js';
|
|
18
|
+
|
|
19
|
+
export const EcdsaKAccountContractArtifact: ContractArtifact = loadContractArtifact(
|
|
20
|
+
EcdsaKAccountContractJson as NoirCompiledContract,
|
|
21
|
+
);
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Account contract that authenticates transactions using ECDSA signatures
|
|
25
|
+
* verified against a secp256k1 public key stored in an immutable encrypted note.
|
|
26
|
+
* Eagerly loads the contract artifact
|
|
27
|
+
*/
|
|
28
|
+
export class EcdsaKAccountContract extends EcdsaKBaseAccountContract {
|
|
29
|
+
constructor(signingPrivateKey: Buffer) {
|
|
30
|
+
super(signingPrivateKey);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
override getContractArtifact(): Promise<ContractArtifact> {
|
|
34
|
+
return Promise.resolve(EcdsaKAccountContractArtifact);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Creates an Account that relies on an ECDSA signing key for authentication.
|
|
39
|
+
* @param pxe - An PXE server instance.
|
|
40
|
+
* @param secretKey - Secret key used to derive all the keystore keys.
|
|
41
|
+
* @param signingPrivateKey - Secp256k1 key used for signing transactions.
|
|
42
|
+
* @param salt - Deployment salt.
|
|
43
|
+
* @returns An account manager initialized with the account contract and its deployment params
|
|
44
|
+
*/
|
|
45
|
+
export function getEcdsaKAccount(
|
|
46
|
+
pxe: PXE,
|
|
47
|
+
secretKey: Fr,
|
|
48
|
+
signingPrivateKey: Buffer,
|
|
49
|
+
salt?: Salt,
|
|
50
|
+
): Promise<AccountManager> {
|
|
51
|
+
return AccountManager.create(pxe, secretKey, new EcdsaKAccountContract(signingPrivateKey), salt);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Gets a wallet for an already registered account using ECDSA signatures.
|
|
56
|
+
* @param pxe - An PXE server instance.
|
|
57
|
+
* @param address - Address for the account.
|
|
58
|
+
* @param signingPrivateKey - ECDSA key used for signing transactions.
|
|
59
|
+
* @returns A wallet for this account that can be used to interact with a contract instance.
|
|
60
|
+
*/
|
|
61
|
+
export function getEcdsaKWallet(pxe: PXE, address: AztecAddress, signingPrivateKey: Buffer): Promise<AccountWallet> {
|
|
62
|
+
return getWallet(pxe, address, new EcdsaKAccountContract(signingPrivateKey));
|
|
63
|
+
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 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.
|
|
3
|
+
* Consider using this account type when working with integrations with Ethereum wallets.
|
|
4
|
+
*
|
|
5
|
+
* @packageDocumentation
|
|
6
|
+
*/
|
|
7
|
+
import { AccountManager, type Salt } from '@aztec/aztec.js/account';
|
|
8
|
+
import { type AccountWallet, getWallet } from '@aztec/aztec.js/wallet';
|
|
9
|
+
import { Fr } from '@aztec/foundation/fields';
|
|
10
|
+
import type { ContractArtifact } from '@aztec/stdlib/abi';
|
|
11
|
+
import { loadContractArtifact } from '@aztec/stdlib/abi';
|
|
12
|
+
import { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
13
|
+
import type { PXE } from '@aztec/stdlib/interfaces/client';
|
|
14
|
+
|
|
15
|
+
import { EcdsaKBaseAccountContract } from './account_contract.js';
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Lazily loads the contract artifact
|
|
19
|
+
* @returns The contract artifact for the ecdsa K account contract
|
|
20
|
+
*/
|
|
21
|
+
export async function getEcdsaKAccountContractArtifact() {
|
|
22
|
+
// Cannot assert this import as it's incompatible with browsers
|
|
23
|
+
// https://caniuse.com/mdn-javascript_statements_import_import_assertions_type_json
|
|
24
|
+
// Use the new "with" syntax once supported by firefox
|
|
25
|
+
// https://caniuse.com/mdn-javascript_statements_import_import_attributes_type_json
|
|
26
|
+
// In the meantime, this lazy import is INCOMPATIBLE WITH NODEJS
|
|
27
|
+
const { default: ecdsaKAccountContractJson } = await import('../../../artifacts/EcdsaKAccount.json');
|
|
28
|
+
return loadContractArtifact(ecdsaKAccountContractJson);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Account contract that authenticates transactions using ECDSA signatures
|
|
33
|
+
* verified against a secp256k1 public key stored in an immutable encrypted note.
|
|
34
|
+
* Lazily loads the contract artifact
|
|
35
|
+
*/
|
|
36
|
+
export class EcdsaKAccountContract extends EcdsaKBaseAccountContract {
|
|
37
|
+
constructor(signingPrivateKey: Buffer) {
|
|
38
|
+
super(signingPrivateKey);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
override getContractArtifact(): Promise<ContractArtifact> {
|
|
42
|
+
return getEcdsaKAccountContractArtifact();
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Creates an Account that relies on an ECDSA signing key for authentication.
|
|
47
|
+
* @param pxe - An PXE server instance.
|
|
48
|
+
* @param secretKey - Secret key used to derive all the keystore keys.
|
|
49
|
+
* @param signingPrivateKey - Secp256k1 key used for signing transactions.
|
|
50
|
+
* @param salt - Deployment salt.
|
|
51
|
+
* @returns An account manager initialized with the account contract and its deployment params
|
|
52
|
+
*/
|
|
53
|
+
export function getEcdsaKAccount(
|
|
54
|
+
pxe: PXE,
|
|
55
|
+
secretKey: Fr,
|
|
56
|
+
signingPrivateKey: Buffer,
|
|
57
|
+
salt?: Salt,
|
|
58
|
+
): Promise<AccountManager> {
|
|
59
|
+
return AccountManager.create(pxe, secretKey, new EcdsaKAccountContract(signingPrivateKey), salt);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Gets a wallet for an already registered account using ECDSA signatures.
|
|
64
|
+
* @param pxe - An PXE server instance.
|
|
65
|
+
* @param address - Address for the account.
|
|
66
|
+
* @param signingPrivateKey - ECDSA key used for signing transactions.
|
|
67
|
+
* @returns A wallet for this account that can be used to interact with a contract instance.
|
|
68
|
+
*/
|
|
69
|
+
export function getEcdsaKWallet(pxe: PXE, address: AztecAddress, signingPrivateKey: Buffer): Promise<AccountWallet> {
|
|
70
|
+
return getWallet(pxe, address, new EcdsaKAccountContract(signingPrivateKey));
|
|
71
|
+
}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import type { AuthWitnessProvider } from '@aztec/aztec.js/account';
|
|
2
|
+
import { EcdsaSignature } from '@aztec/foundation/crypto';
|
|
3
|
+
import type { Fr } from '@aztec/foundation/fields';
|
|
4
|
+
import { AuthWitness } from '@aztec/stdlib/auth-witness';
|
|
5
|
+
import { CompleteAddress } from '@aztec/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
|
+
getDeploymentArgs() {
|
|
26
|
+
return Promise.resolve([this.signingPublicKey.subarray(0, 32), this.signingPublicKey.subarray(32, 64)]);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
getAuthWitnessProvider(_address: CompleteAddress): AuthWitnessProvider {
|
|
30
|
+
return new SSHEcdsaRAuthWitnessProvider(this.signingPublicKey);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/** Creates auth witnesses using ECDSA signatures. */
|
|
35
|
+
class SSHEcdsaRAuthWitnessProvider implements AuthWitnessProvider {
|
|
36
|
+
constructor(private signingPublicKey: Buffer) {}
|
|
37
|
+
|
|
38
|
+
#parseECDSASignature(data: Buffer) {
|
|
39
|
+
// Extract ECDSA signature components
|
|
40
|
+
let offset = 0;
|
|
41
|
+
const sigTypeLen = data.readUInt32BE(offset);
|
|
42
|
+
offset += 4;
|
|
43
|
+
const sigType = data.subarray(offset, offset + sigTypeLen).toString();
|
|
44
|
+
offset += sigTypeLen;
|
|
45
|
+
|
|
46
|
+
if (sigType !== 'ecdsa-sha2-nistp256') {
|
|
47
|
+
throw new Error(`Unexpected signature type: ${sigType}`);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
offset += 4;
|
|
51
|
+
const rLen = data.readUInt32BE(offset);
|
|
52
|
+
offset += 4;
|
|
53
|
+
let r = data.subarray(offset, offset + rLen);
|
|
54
|
+
offset += rLen;
|
|
55
|
+
|
|
56
|
+
const sLen = data.readUInt32BE(offset);
|
|
57
|
+
offset += 4;
|
|
58
|
+
let s = data.subarray(offset, offset + sLen);
|
|
59
|
+
|
|
60
|
+
// R and S are encoded using ASN.1 DER format, which may include a leading zero byte to avoid interpreting the value as negative
|
|
61
|
+
if (r.length > 32) {
|
|
62
|
+
r = Buffer.from(Uint8Array.prototype.slice.call(r, 1));
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
if (s.length > 32) {
|
|
66
|
+
s = Buffer.from(Uint8Array.prototype.slice.call(s, 1));
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
const maybeHighS = BigInt(`0x${s.toString('hex')}`);
|
|
70
|
+
|
|
71
|
+
// 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
|
|
72
|
+
// only one PublicKey can verify the signature (and not its negated counterpart) https://ethereum.stackexchange.com/a/55728
|
|
73
|
+
if (maybeHighS > secp256r1N / 2n + 1n) {
|
|
74
|
+
s = Buffer.from((secp256r1N - maybeHighS).toString(16), 'hex');
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
return new EcdsaSignature(r, s, Buffer.from([0]));
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
async createAuthWit(messageHash: Fr): Promise<AuthWitness> {
|
|
81
|
+
// Key type and curve name
|
|
82
|
+
const keyType = Buffer.from('ecdsa-sha2-nistp256');
|
|
83
|
+
const curveName = Buffer.from('nistp256');
|
|
84
|
+
const data = await signWithAgent(keyType, curveName, this.signingPublicKey, messageHash.toBuffer());
|
|
85
|
+
const signature = this.#parseECDSASignature(data);
|
|
86
|
+
|
|
87
|
+
return new AuthWitness(messageHash, [...signature.r, ...signature.s]);
|
|
88
|
+
}
|
|
89
|
+
}
|