@aztec/pxe 0.16.4 → 0.16.5
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/dest/bin/index.js +0 -0
- package/dest/database/memory_db.js +3 -3
- package/dest/pxe_http/pxe_http_server.d.ts.map +1 -1
- package/dest/pxe_http/pxe_http_server.js +2 -2
- package/dest/simulator_oracle/index.js +3 -3
- package/dest/synchronizer/synchronizer.js +2 -2
- package/package.json +9 -9
- package/src/bin/index.ts +0 -39
- package/src/config/index.ts +0 -37
- package/src/contract_data_oracle/index.ts +0 -163
- package/src/contract_database/index.ts +0 -1
- package/src/contract_database/memory_contract_database.ts +0 -58
- package/src/contract_tree/index.ts +0 -241
- package/src/database/database.ts +0 -140
- package/src/database/index.ts +0 -2
- package/src/database/memory_db.ts +0 -181
- package/src/database/note_dao.ts +0 -90
- package/src/index.ts +0 -11
- package/src/kernel_oracle/index.ts +0 -39
- package/src/kernel_prover/index.ts +0 -2
- package/src/kernel_prover/kernel_prover.ts +0 -325
- package/src/kernel_prover/proof_creator.ts +0 -155
- package/src/kernel_prover/proving_data_oracle.ts +0 -69
- package/src/note_processor/index.ts +0 -1
- package/src/note_processor/note_processor.ts +0 -286
- package/src/pxe_http/index.ts +0 -1
- package/src/pxe_http/pxe_http_server.ts +0 -78
- package/src/pxe_service/create_pxe_service.ts +0 -52
- package/src/pxe_service/index.ts +0 -3
- package/src/pxe_service/pxe_service.ts +0 -679
- package/src/pxe_service/test/pxe_test_suite.ts +0 -132
- package/src/simulator/index.ts +0 -24
- package/src/simulator_oracle/index.ts +0 -186
- package/src/synchronizer/index.ts +0 -1
- package/src/synchronizer/synchronizer.ts +0 -296
|
@@ -1,286 +0,0 @@
|
|
|
1
|
-
import { MAX_NEW_COMMITMENTS_PER_TX, MAX_NEW_NULLIFIERS_PER_TX, PublicKey } from '@aztec/circuits.js';
|
|
2
|
-
import { computeCommitmentNonce, siloNullifier } from '@aztec/circuits.js/abis';
|
|
3
|
-
import { Grumpkin } from '@aztec/circuits.js/barretenberg';
|
|
4
|
-
import { Fr } from '@aztec/foundation/fields';
|
|
5
|
-
import { createDebugLogger } from '@aztec/foundation/log';
|
|
6
|
-
import { Timer } from '@aztec/foundation/timer';
|
|
7
|
-
import { AztecNode, KeyStore, L1NotePayload, L2BlockContext, L2BlockL2Logs } from '@aztec/types';
|
|
8
|
-
import { NoteProcessorStats } from '@aztec/types/stats';
|
|
9
|
-
|
|
10
|
-
import { Database } from '../database/index.js';
|
|
11
|
-
import { NoteDao } from '../database/note_dao.js';
|
|
12
|
-
import { getAcirSimulator } from '../simulator/index.js';
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* Contains all the decrypted data in this array so that we can later batch insert it all into the database.
|
|
16
|
-
*/
|
|
17
|
-
interface ProcessedData {
|
|
18
|
-
/**
|
|
19
|
-
* Holds L2 block and a cache of already requested tx hashes.
|
|
20
|
-
*/
|
|
21
|
-
blockContext: L2BlockContext;
|
|
22
|
-
/**
|
|
23
|
-
* DAOs of processed notes.
|
|
24
|
-
*/
|
|
25
|
-
noteDaos: NoteDao[];
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* NoteProcessor is responsible for decrypting logs and converting them to notes via their originating contracts
|
|
30
|
-
* before storing them against their owner.
|
|
31
|
-
*/
|
|
32
|
-
export class NoteProcessor {
|
|
33
|
-
/** The latest L2 block number that the note processor has synchronized to. */
|
|
34
|
-
private syncedToBlock = 0;
|
|
35
|
-
|
|
36
|
-
/** Keeps track of processing time since an instance is created. */
|
|
37
|
-
public readonly timer: Timer = new Timer();
|
|
38
|
-
|
|
39
|
-
/** Stats accumulated for this processor. */
|
|
40
|
-
public readonly stats: NoteProcessorStats = { seen: 0, decrypted: 0, failed: 0, blocks: 0, txs: 0 };
|
|
41
|
-
|
|
42
|
-
constructor(
|
|
43
|
-
/**
|
|
44
|
-
* The public counterpart to the private key to be used in note decryption.
|
|
45
|
-
*/
|
|
46
|
-
public readonly publicKey: PublicKey,
|
|
47
|
-
private keyStore: KeyStore,
|
|
48
|
-
private db: Database,
|
|
49
|
-
private node: AztecNode,
|
|
50
|
-
private startingBlock: number,
|
|
51
|
-
private simulator = getAcirSimulator(db, node, keyStore),
|
|
52
|
-
private log = createDebugLogger('aztec:note_processor'),
|
|
53
|
-
) {
|
|
54
|
-
this.syncedToBlock = this.startingBlock - 1;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
/**
|
|
58
|
-
* Check if the NoteProcessor is synchronized with the remote block number.
|
|
59
|
-
* The function queries the remote block number from the AztecNode and compares it with the syncedToBlock value in the NoteProcessor.
|
|
60
|
-
* If the values are equal, then the NoteProcessor is considered to be synchronized, otherwise not.
|
|
61
|
-
*
|
|
62
|
-
* @returns A boolean indicating whether the NoteProcessor is synchronized with the remote block number or not.
|
|
63
|
-
*/
|
|
64
|
-
public async isSynchronized() {
|
|
65
|
-
const remoteBlockNumber = await this.node.getBlockNumber();
|
|
66
|
-
return this.syncedToBlock === remoteBlockNumber;
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
/**
|
|
70
|
-
* Returns synchronization status (ie up to which block has been synced ) for this note processor.
|
|
71
|
-
*/
|
|
72
|
-
public get status() {
|
|
73
|
-
return { syncedToBlock: this.syncedToBlock };
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
/**
|
|
77
|
-
* Process the given L2 block contexts and encrypted logs to update the note processor.
|
|
78
|
-
* It synchronizes the user's account by decrypting the encrypted logs and processing
|
|
79
|
-
* the transactions and auxiliary data associated with them.
|
|
80
|
-
* Throws an error if the number of block contexts and encrypted logs do not match.
|
|
81
|
-
*
|
|
82
|
-
* @param l2BlockContexts - An array of L2 block contexts to be processed.
|
|
83
|
-
* @param encryptedL2BlockLogs - An array of encrypted logs associated with the L2 block contexts.
|
|
84
|
-
* @returns A promise that resolves once the processing is completed.
|
|
85
|
-
*/
|
|
86
|
-
public async process(l2BlockContexts: L2BlockContext[], encryptedL2BlockLogs: L2BlockL2Logs[]): Promise<void> {
|
|
87
|
-
if (l2BlockContexts.length !== encryptedL2BlockLogs.length) {
|
|
88
|
-
throw new Error(
|
|
89
|
-
`Number of blocks and EncryptedLogs is not equal. Received ${l2BlockContexts.length} blocks, ${encryptedL2BlockLogs.length} encrypted logs.`,
|
|
90
|
-
);
|
|
91
|
-
}
|
|
92
|
-
if (!l2BlockContexts.length) {
|
|
93
|
-
return;
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
const blocksAndNotes: ProcessedData[] = [];
|
|
97
|
-
const curve = new Grumpkin();
|
|
98
|
-
|
|
99
|
-
// Iterate over both blocks and encrypted logs.
|
|
100
|
-
for (let blockIndex = 0; blockIndex < encryptedL2BlockLogs.length; ++blockIndex) {
|
|
101
|
-
this.stats.blocks++;
|
|
102
|
-
const { txLogs } = encryptedL2BlockLogs[blockIndex];
|
|
103
|
-
const blockContext = l2BlockContexts[blockIndex];
|
|
104
|
-
const block = blockContext.block;
|
|
105
|
-
const dataStartIndexForBlock = block.startNoteHashTreeSnapshot.nextAvailableLeafIndex;
|
|
106
|
-
|
|
107
|
-
// We are using set for `userPertainingTxIndices` to avoid duplicates. This would happen in case there were
|
|
108
|
-
// multiple encrypted logs in a tx pertaining to a user.
|
|
109
|
-
const noteDaos: NoteDao[] = [];
|
|
110
|
-
const privateKey = await this.keyStore.getAccountPrivateKey(this.publicKey);
|
|
111
|
-
|
|
112
|
-
// Iterate over all the encrypted logs and try decrypting them. If successful, store the note.
|
|
113
|
-
for (let indexOfTxInABlock = 0; indexOfTxInABlock < txLogs.length; ++indexOfTxInABlock) {
|
|
114
|
-
this.stats.txs++;
|
|
115
|
-
const dataStartIndexForTx = dataStartIndexForBlock + indexOfTxInABlock * MAX_NEW_COMMITMENTS_PER_TX;
|
|
116
|
-
const newCommitments = block.newCommitments.slice(
|
|
117
|
-
indexOfTxInABlock * MAX_NEW_COMMITMENTS_PER_TX,
|
|
118
|
-
(indexOfTxInABlock + 1) * MAX_NEW_COMMITMENTS_PER_TX,
|
|
119
|
-
);
|
|
120
|
-
const newNullifiers = block.newNullifiers.slice(
|
|
121
|
-
indexOfTxInABlock * MAX_NEW_NULLIFIERS_PER_TX,
|
|
122
|
-
(indexOfTxInABlock + 1) * MAX_NEW_NULLIFIERS_PER_TX,
|
|
123
|
-
);
|
|
124
|
-
// Note: Each tx generates a `TxL2Logs` object and for this reason we can rely on its index corresponding
|
|
125
|
-
// to the index of a tx in a block.
|
|
126
|
-
const txFunctionLogs = txLogs[indexOfTxInABlock].functionLogs;
|
|
127
|
-
const excludedIndices: Set<number> = new Set();
|
|
128
|
-
for (const functionLogs of txFunctionLogs) {
|
|
129
|
-
for (const logs of functionLogs.logs) {
|
|
130
|
-
this.stats.seen++;
|
|
131
|
-
const payload = L1NotePayload.fromEncryptedBuffer(logs, privateKey, curve);
|
|
132
|
-
if (payload) {
|
|
133
|
-
// We have successfully decrypted the data.
|
|
134
|
-
try {
|
|
135
|
-
const { commitmentIndex, nonce, innerNoteHash, siloedNullifier } = await this.findNoteIndexAndNullifier(
|
|
136
|
-
newCommitments,
|
|
137
|
-
newNullifiers[0],
|
|
138
|
-
payload,
|
|
139
|
-
excludedIndices,
|
|
140
|
-
);
|
|
141
|
-
const index = BigInt(dataStartIndexForTx + commitmentIndex);
|
|
142
|
-
excludedIndices.add(commitmentIndex);
|
|
143
|
-
noteDaos.push(
|
|
144
|
-
new NoteDao(
|
|
145
|
-
payload.note,
|
|
146
|
-
payload.contractAddress,
|
|
147
|
-
payload.storageSlot,
|
|
148
|
-
blockContext.getTxHash(indexOfTxInABlock),
|
|
149
|
-
nonce,
|
|
150
|
-
innerNoteHash,
|
|
151
|
-
siloedNullifier,
|
|
152
|
-
index,
|
|
153
|
-
this.publicKey,
|
|
154
|
-
),
|
|
155
|
-
);
|
|
156
|
-
this.stats.decrypted++;
|
|
157
|
-
} catch (e) {
|
|
158
|
-
this.stats.failed++;
|
|
159
|
-
this.log.warn(`Could not process note because of "${e}". Skipping note...`);
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
blocksAndNotes.push({
|
|
167
|
-
blockContext: l2BlockContexts[blockIndex],
|
|
168
|
-
noteDaos,
|
|
169
|
-
});
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
await this.processBlocksAndNotes(blocksAndNotes);
|
|
173
|
-
|
|
174
|
-
this.syncedToBlock = l2BlockContexts[l2BlockContexts.length - 1].block.number;
|
|
175
|
-
this.log(`Synched block ${this.syncedToBlock}`);
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
/**
|
|
179
|
-
* Find the index of the note in the note hash tree by computing the note hash with different nonce and see which
|
|
180
|
-
* commitment for the current tx matches this value.
|
|
181
|
-
* Compute a nullifier for a given l1NotePayload.
|
|
182
|
-
* The nullifier is calculated using the private key of the account,
|
|
183
|
-
* contract address, and the note associated with the l1NotePayload.
|
|
184
|
-
* This method assists in identifying spent commitments in the private state.
|
|
185
|
-
* @param commitments - Commitments in the tx. One of them should be the note's commitment.
|
|
186
|
-
* @param firstNullifier - First nullifier in the tx.
|
|
187
|
-
* @param l1NotePayload - An instance of l1NotePayload.
|
|
188
|
-
* @param excludedIndices - Indices that have been assigned a note in the same tx. Notes in a tx can have the same
|
|
189
|
-
* l1NotePayload. We need to find a different index for each replicate.
|
|
190
|
-
* @returns Information for a decrypted note, including the index of its commitment, nonce, inner note
|
|
191
|
-
* hash, and the siloed nullifier. Throw if cannot find the nonce for the note.
|
|
192
|
-
*/
|
|
193
|
-
private async findNoteIndexAndNullifier(
|
|
194
|
-
commitments: Fr[],
|
|
195
|
-
firstNullifier: Fr,
|
|
196
|
-
{ contractAddress, storageSlot, note }: L1NotePayload,
|
|
197
|
-
excludedIndices: Set<number>,
|
|
198
|
-
) {
|
|
199
|
-
let commitmentIndex = 0;
|
|
200
|
-
let nonce: Fr | undefined;
|
|
201
|
-
let innerNoteHash: Fr | undefined;
|
|
202
|
-
let siloedNoteHash: Fr | undefined;
|
|
203
|
-
let uniqueSiloedNoteHash: Fr | undefined;
|
|
204
|
-
let innerNullifier: Fr | undefined;
|
|
205
|
-
for (; commitmentIndex < commitments.length; ++commitmentIndex) {
|
|
206
|
-
if (excludedIndices.has(commitmentIndex)) {
|
|
207
|
-
continue;
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
const commitment = commitments[commitmentIndex];
|
|
211
|
-
if (commitment.equals(Fr.ZERO)) {
|
|
212
|
-
break;
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
const expectedNonce = computeCommitmentNonce(firstNullifier, commitmentIndex);
|
|
216
|
-
({ innerNoteHash, siloedNoteHash, uniqueSiloedNoteHash, innerNullifier } =
|
|
217
|
-
await this.simulator.computeNoteHashAndNullifier(contractAddress, expectedNonce, storageSlot, note));
|
|
218
|
-
if (commitment.equals(uniqueSiloedNoteHash)) {
|
|
219
|
-
nonce = expectedNonce;
|
|
220
|
-
break;
|
|
221
|
-
}
|
|
222
|
-
}
|
|
223
|
-
|
|
224
|
-
if (!nonce) {
|
|
225
|
-
let errorString;
|
|
226
|
-
if (siloedNoteHash == undefined) {
|
|
227
|
-
errorString = 'Cannot find a matching commitment for the note.';
|
|
228
|
-
} else {
|
|
229
|
-
errorString = `We decrypted a log, but couldn't find a corresponding note in the tree.
|
|
230
|
-
This might be because the note was nullified in the same tx which created it.
|
|
231
|
-
In that case, everything is fine. To check whether this is the case, look back through
|
|
232
|
-
the logs for a notification
|
|
233
|
-
'important: chopped commitment for siloed inner hash note
|
|
234
|
-
${siloedNoteHash.toString()}'.
|
|
235
|
-
If you can see that notification. Everything's fine.
|
|
236
|
-
If that's not the case, and you can't find such a notification, something has gone wrong.
|
|
237
|
-
There could be a problem with the way you've defined a custom note, or with the way you're
|
|
238
|
-
serializing / deserializing / hashing / encrypting / decrypting that note.
|
|
239
|
-
Please see the following github issue to track an improvement that we're working on:
|
|
240
|
-
https://github.com/AztecProtocol/aztec-packages/issues/1641`;
|
|
241
|
-
}
|
|
242
|
-
|
|
243
|
-
throw new Error(errorString);
|
|
244
|
-
}
|
|
245
|
-
|
|
246
|
-
return {
|
|
247
|
-
commitmentIndex,
|
|
248
|
-
nonce,
|
|
249
|
-
innerNoteHash: innerNoteHash!,
|
|
250
|
-
siloedNullifier: siloNullifier(contractAddress, innerNullifier!),
|
|
251
|
-
};
|
|
252
|
-
}
|
|
253
|
-
|
|
254
|
-
/**
|
|
255
|
-
* Process the given blocks and their associated transaction auxiliary data.
|
|
256
|
-
* This function updates the database with information about new transactions,
|
|
257
|
-
* user-pertaining transaction indices, and auxiliary data. It also removes nullified
|
|
258
|
-
* transaction auxiliary data from the database. This function keeps track of new nullifiers
|
|
259
|
-
* and ensures all other transactions are updated with newly settled block information.
|
|
260
|
-
*
|
|
261
|
-
* @param blocksAndNotes - Array of objects containing L2BlockContexts, user-pertaining transaction indices, and NoteDaos.
|
|
262
|
-
*/
|
|
263
|
-
private async processBlocksAndNotes(blocksAndNotes: ProcessedData[]) {
|
|
264
|
-
const noteDaos = blocksAndNotes.flatMap(b => b.noteDaos);
|
|
265
|
-
if (noteDaos.length) {
|
|
266
|
-
await this.db.addNotes(noteDaos);
|
|
267
|
-
noteDaos.forEach(noteDao => {
|
|
268
|
-
this.log(
|
|
269
|
-
`Added note for contract ${noteDao.contractAddress} at slot ${
|
|
270
|
-
noteDao.storageSlot
|
|
271
|
-
} with nullifier ${noteDao.siloedNullifier.toString()}`,
|
|
272
|
-
);
|
|
273
|
-
});
|
|
274
|
-
}
|
|
275
|
-
|
|
276
|
-
const newNullifiers: Fr[] = blocksAndNotes.flatMap(b => b.blockContext.block.newNullifiers);
|
|
277
|
-
const removedNotes = await this.db.removeNullifiedNotes(newNullifiers, this.publicKey);
|
|
278
|
-
removedNotes.forEach(noteDao => {
|
|
279
|
-
this.log(
|
|
280
|
-
`Removed note for contract ${noteDao.contractAddress} at slot ${
|
|
281
|
-
noteDao.storageSlot
|
|
282
|
-
} with nullifier ${noteDao.siloedNullifier.toString()}`,
|
|
283
|
-
);
|
|
284
|
-
});
|
|
285
|
-
}
|
|
286
|
-
}
|
package/src/pxe_http/index.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './pxe_http_server.js';
|
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
import { FunctionSelector } from '@aztec/circuits.js';
|
|
2
|
-
import { AztecAddress } from '@aztec/foundation/aztec-address';
|
|
3
|
-
import { Fr, GrumpkinScalar, Point } from '@aztec/foundation/fields';
|
|
4
|
-
import { JsonRpcServer } from '@aztec/foundation/json-rpc/server';
|
|
5
|
-
import {
|
|
6
|
-
AuthWitness,
|
|
7
|
-
CompleteAddress,
|
|
8
|
-
ContractData,
|
|
9
|
-
ExtendedContractData,
|
|
10
|
-
ExtendedNote,
|
|
11
|
-
ExtendedUnencryptedL2Log,
|
|
12
|
-
L2Block,
|
|
13
|
-
L2BlockL2Logs,
|
|
14
|
-
L2Tx,
|
|
15
|
-
LogId,
|
|
16
|
-
Note,
|
|
17
|
-
PXE,
|
|
18
|
-
Tx,
|
|
19
|
-
TxExecutionRequest,
|
|
20
|
-
TxHash,
|
|
21
|
-
TxReceipt,
|
|
22
|
-
} from '@aztec/types';
|
|
23
|
-
|
|
24
|
-
import http from 'http';
|
|
25
|
-
import { foundry } from 'viem/chains';
|
|
26
|
-
|
|
27
|
-
import { EthAddress } from '../index.js';
|
|
28
|
-
|
|
29
|
-
export const localAnvil = foundry;
|
|
30
|
-
|
|
31
|
-
/**
|
|
32
|
-
* Wraps an instance of Private eXecution Environment (PXE) implementation to a JSON RPC HTTP interface.
|
|
33
|
-
* @returns A new instance of the HTTP server.
|
|
34
|
-
*/
|
|
35
|
-
export function createPXERpcServer(pxeService: PXE): JsonRpcServer {
|
|
36
|
-
return new JsonRpcServer(
|
|
37
|
-
pxeService,
|
|
38
|
-
{
|
|
39
|
-
CompleteAddress,
|
|
40
|
-
AztecAddress,
|
|
41
|
-
TxExecutionRequest,
|
|
42
|
-
ContractData,
|
|
43
|
-
ExtendedContractData,
|
|
44
|
-
ExtendedUnencryptedL2Log,
|
|
45
|
-
FunctionSelector,
|
|
46
|
-
TxHash,
|
|
47
|
-
EthAddress,
|
|
48
|
-
Point,
|
|
49
|
-
Fr,
|
|
50
|
-
GrumpkinScalar,
|
|
51
|
-
Note,
|
|
52
|
-
ExtendedNote,
|
|
53
|
-
AuthWitness,
|
|
54
|
-
L2Block,
|
|
55
|
-
L2Tx,
|
|
56
|
-
LogId,
|
|
57
|
-
},
|
|
58
|
-
{ Tx, TxReceipt, L2BlockL2Logs },
|
|
59
|
-
false,
|
|
60
|
-
['start', 'stop'],
|
|
61
|
-
);
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
/**
|
|
65
|
-
* Creates an http server that forwards calls to the PXE and starts it on the given port.
|
|
66
|
-
* @param pxeService - PXE that answers queries to the created HTTP server.
|
|
67
|
-
* @param port - Port to listen in.
|
|
68
|
-
* @returns A running http server.
|
|
69
|
-
*/
|
|
70
|
-
export function startPXEHttpServer(pxeService: PXE, port: string | number): http.Server {
|
|
71
|
-
const rpcServer = createPXERpcServer(pxeService);
|
|
72
|
-
|
|
73
|
-
const app = rpcServer.getApp();
|
|
74
|
-
const httpServer = http.createServer(app.callback());
|
|
75
|
-
httpServer.listen(port);
|
|
76
|
-
|
|
77
|
-
return httpServer;
|
|
78
|
-
}
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
import { Grumpkin } from '@aztec/circuits.js/barretenberg';
|
|
2
|
-
import { TestKeyStore } from '@aztec/key-store';
|
|
3
|
-
import { AztecNode, KeyStore } from '@aztec/types';
|
|
4
|
-
|
|
5
|
-
import { PXEServiceConfig } from '../config/index.js';
|
|
6
|
-
import { Database, MemoryDB } from '../database/index.js';
|
|
7
|
-
import { PXEService } from './pxe_service.js';
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* Optional information for creating an PXEService.
|
|
11
|
-
*/
|
|
12
|
-
interface CreatePXEServiceOptions {
|
|
13
|
-
/**
|
|
14
|
-
* A secure storage for cryptographic keys.
|
|
15
|
-
*/
|
|
16
|
-
keyStore?: KeyStore;
|
|
17
|
-
/**
|
|
18
|
-
* Storage for the PXE.
|
|
19
|
-
*/
|
|
20
|
-
db?: Database;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* Create and start an PXEService instance with the given AztecNode.
|
|
25
|
-
* If no keyStore or database is provided, it will use TestKeyStore and MemoryDB as default values.
|
|
26
|
-
* Returns a Promise that resolves to the started PXEService instance.
|
|
27
|
-
*
|
|
28
|
-
* @param aztecNode - The AztecNode instance to be used by the server.
|
|
29
|
-
* @param config - The PXE Service Config to use
|
|
30
|
-
* @param options - (Optional) Optional information for creating an PXEService.
|
|
31
|
-
* @returns A Promise that resolves to the started PXEService instance.
|
|
32
|
-
*/
|
|
33
|
-
export async function createPXEService(
|
|
34
|
-
aztecNode: AztecNode,
|
|
35
|
-
config: PXEServiceConfig,
|
|
36
|
-
{ keyStore, db }: CreatePXEServiceOptions = {},
|
|
37
|
-
useLogSuffix: string | boolean | undefined = undefined,
|
|
38
|
-
) {
|
|
39
|
-
const logSuffix =
|
|
40
|
-
typeof useLogSuffix === 'boolean'
|
|
41
|
-
? useLogSuffix
|
|
42
|
-
? Math.random().toString(16).slice(2, 8)
|
|
43
|
-
: undefined
|
|
44
|
-
: useLogSuffix;
|
|
45
|
-
|
|
46
|
-
keyStore = keyStore || new TestKeyStore(new Grumpkin());
|
|
47
|
-
db = db || new MemoryDB(logSuffix);
|
|
48
|
-
|
|
49
|
-
const server = new PXEService(keyStore, aztecNode, db, config, logSuffix);
|
|
50
|
-
await server.start();
|
|
51
|
-
return server;
|
|
52
|
-
}
|
package/src/pxe_service/index.ts
DELETED