@aztec/key-store 5.0.0-nightly.20260521 → 5.0.0-nightly.20260522

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.
@@ -84,13 +84,13 @@ export declare class KeyStore {
84
84
  */
85
85
  getAppOutgoingViewingSecretKey(account: AztecAddress, app: AztecAddress): Promise<Fr>;
86
86
  /**
87
- * Retrieves the sk_m corresponding to the pk_m.
88
- * @throws If the provided public key is not associated with any of the registered accounts.
89
- * @param pkM - The master public key to get secret key for.
87
+ * Retrieves the sk_m corresponding to the given pk_m hash.
88
+ * @throws If the provided hash is not associated with any of the registered accounts.
89
+ * @param pkMHash - The master public key hash to get secret key for.
90
90
  * @returns A Promise that resolves to sk_m.
91
91
  * @dev Used when feeding the sk_m to the kernel circuit for keys verification.
92
92
  */
93
- getMasterSecretKey(pkM: PublicKey): Promise<GrumpkinScalar>;
93
+ getMasterSecretKey(pkMHash: Fr): Promise<GrumpkinScalar>;
94
94
  /**
95
95
  * Checks whether a given account has a key matching the provided master public key hash.
96
96
  * @param account - The account address to check.
@@ -106,4 +106,4 @@ export declare class KeyStore {
106
106
  */
107
107
  getKeyPrefixAndAccount(value: Bufferable): Promise<[KeyPrefix, AztecAddress]>;
108
108
  }
109
- //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoia2V5X3N0b3JlLmQudHMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi9zcmMva2V5X3N0b3JlLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUVBLE9BQU8sRUFBRSxFQUFFLEVBQUUsTUFBTSxnQ0FBZ0MsQ0FBQztBQUNwRCxPQUFPLEVBQUUsY0FBYyxFQUFTLE1BQU0sbUNBQW1DLENBQUM7QUFFMUUsT0FBTyxFQUFFLEtBQUssVUFBVSxFQUFxQixNQUFNLDZCQUE2QixDQUFDO0FBQ2pGLE9BQU8sS0FBSyxFQUFFLGlCQU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C,CAQ7F;IAED;;;;;;OAMG;IACU,8BAA8B,CAAC,OAAO,EAAE,YAAY,EAAE,GAAG,EAAE,YAAY,GAAG,OAAO,CAAC,EAAE,CAAC,CAajG;IAED;;;;;;OAMG;IACI,kBAAkB,CAAC,OAAO,EAAE,EAAE,GAAG,OAAO,CAAC,cAAc,CAAC,CA6B9D;IAED;;;;;OAKG;IACI,aAAa,CAAC,OAAO,EAAE,YAAY,EAAE,OAAO,EAAE,EAAE,GAAG,OAAO,CAAC,OAAO,CAAC,CAWzE;IAED;;;;;OAKG;IACU,sBAAsB,CAAC,KAAK,EAAE,UAAU,GAAG,OAAO,CAAC,CAAC,SAAS,EAAE,YAAY,CAAC,CAAC,CAczF;CACF"}
package/dest/key_store.js CHANGED
@@ -7,7 +7,7 @@ import { serializeToBuffer } from '@aztec/foundation/serialize';
7
7
  import { AztecAddress } from '@aztec/stdlib/aztec-address';
8
8
  import { CompleteAddress } from '@aztec/stdlib/contract';
9
9
  import { KeyValidationRequest } from '@aztec/stdlib/kernel';
10
- import { KEY_PREFIXES, computeAppSecretKey, deriveKeys, derivePublicKeyFromSecretKey } from '@aztec/stdlib/keys';
10
+ import { KEY_PREFIXES, computeAppSecretKey, deriveKeys, derivePublicKeyFromSecretKey, hashPublicKey } from '@aztec/stdlib/keys';
11
11
  /** Maps a key prefix to the storage suffix for the corresponding master secret key. */ function secretKeyStorageSuffix(prefix) {
12
12
  return prefix === 'n' ? 'nhk_m' : `${prefix}sk_m`;
13
13
  }
@@ -35,30 +35,30 @@ import { KEY_PREFIXES, computeAppSecretKey, deriveKeys, derivePublicKeyFromSecre
35
35
  * @param partialAddress - The partial address of the account.
36
36
  * @returns The account's complete address.
37
37
  */ async addAccount(sk, partialAddress) {
38
- const { masterNullifierHidingKey, masterIncomingViewingSecretKey, masterOutgoingViewingSecretKey, masterTaggingSecretKey, publicKeys } = await deriveKeys(sk);
39
- const completeAddress = await CompleteAddress.fromSecretKeyAndPartialAddress(sk, partialAddress);
38
+ const { masterNullifierHidingKey, masterIncomingViewingSecretKey, masterOutgoingViewingSecretKey, masterTaggingSecretKey, masterNullifierPublicKey, masterOutgoingViewingPublicKey, masterTaggingPublicKey, publicKeys } = await deriveKeys(sk);
39
+ const completeAddress = await CompleteAddress.fromPublicKeysAndPartialAddress(publicKeys, partialAddress);
40
40
  const { address: account } = completeAddress;
41
- // Compute hashes before transaction
42
- const masterNullifierPublicKeyHash = await publicKeys.masterNullifierPublicKey.hash();
43
- const masterIncomingViewingPublicKeyHash = await publicKeys.masterIncomingViewingPublicKey.hash();
44
- const masterOutgoingViewingPublicKeyHash = await publicKeys.masterOutgoingViewingPublicKey.hash();
45
- const masterTaggingPublicKeyHash = await publicKeys.masterTaggingPublicKey.hash();
41
+ // The kernel cannot check that nhpk/ovpk/tpk are on-curve or non-infinity, so the PXE/key-store
42
+ // must guarantee it before persistence. By design, the above derivation produces points that are on
43
+ // the curve and not at infinity.
44
+ // The npk/ovpk/tpk hashes are already in publicKeys; ivpk_m_hash is computed for indexing.
45
+ const masterIncomingViewingPublicKeyHash = await hashPublicKey(publicKeys.ivpkM);
46
46
  await this.#db.transactionAsync(async ()=>{
47
47
  // Naming of keys is as follows ${account}-${n/iv/ov/t}${sk/pk}_m
48
48
  await this.#keys.set(`${account.toString()}-ivsk_m`, masterIncomingViewingSecretKey.toBuffer());
49
49
  await this.#keys.set(`${account.toString()}-ovsk_m`, masterOutgoingViewingSecretKey.toBuffer());
50
50
  await this.#keys.set(`${account.toString()}-tsk_m`, masterTaggingSecretKey.toBuffer());
51
51
  await this.#keys.set(`${account.toString()}-nhk_m`, masterNullifierHidingKey.toBuffer());
52
- await this.#keys.set(`${account.toString()}-npk_m`, publicKeys.masterNullifierPublicKey.toBuffer());
53
- await this.#keys.set(`${account.toString()}-ivpk_m`, publicKeys.masterIncomingViewingPublicKey.toBuffer());
54
- await this.#keys.set(`${account.toString()}-ovpk_m`, publicKeys.masterOutgoingViewingPublicKey.toBuffer());
55
- await this.#keys.set(`${account.toString()}-tpk_m`, publicKeys.masterTaggingPublicKey.toBuffer());
52
+ await this.#keys.set(`${account.toString()}-npk_m`, masterNullifierPublicKey.toBuffer());
53
+ await this.#keys.set(`${account.toString()}-ivpk_m`, publicKeys.ivpkM.toBuffer());
54
+ await this.#keys.set(`${account.toString()}-ovpk_m`, masterOutgoingViewingPublicKey.toBuffer());
55
+ await this.#keys.set(`${account.toString()}-tpk_m`, masterTaggingPublicKey.toBuffer());
56
56
  // We store pk_m_hash under `account-{n/iv/ov/t}pk_m_hash` key to be able to obtain address and key prefix
57
57
  // using the #getKeyPrefixAndAccount function later on
58
- await this.#keys.set(`${account.toString()}-npk_m_hash`, masterNullifierPublicKeyHash.toBuffer());
58
+ await this.#keys.set(`${account.toString()}-npk_m_hash`, publicKeys.npkMHash.toBuffer());
59
59
  await this.#keys.set(`${account.toString()}-ivpk_m_hash`, masterIncomingViewingPublicKeyHash.toBuffer());
60
- await this.#keys.set(`${account.toString()}-ovpk_m_hash`, masterOutgoingViewingPublicKeyHash.toBuffer());
61
- await this.#keys.set(`${account.toString()}-tpk_m_hash`, masterTaggingPublicKeyHash.toBuffer());
60
+ await this.#keys.set(`${account.toString()}-ovpk_m_hash`, publicKeys.ovpkMHash.toBuffer());
61
+ await this.#keys.set(`${account.toString()}-tpk_m_hash`, publicKeys.tpkMHash.toBuffer());
62
62
  });
63
63
  // At last, we return the newly derived account address
64
64
  return completeAddress;
@@ -84,7 +84,9 @@ import { KEY_PREFIXES, computeAppSecretKey, deriveKeys, derivePublicKeyFromSecre
84
84
  */ getKeyValidationRequest(pkMHash, contractAddress) {
85
85
  return this.#db.transactionAsync(async ()=>{
86
86
  const [keyPrefix, account] = await this.getKeyPrefixAndAccount(pkMHash);
87
- // Now we find the master public key for the account
87
+ // Load the stored master public key point. The returned KVR carries only the hash, but we
88
+ // use the point here as a witness for two integrity checks below: (1) it matches the supplied
89
+ // hash, and (2) it matches the value derived from the stored secret key.
88
90
  const pkMBuffer = await this.#keys.getAsync(`${account.toString()}-${keyPrefix}pk_m`);
89
91
  if (!pkMBuffer) {
90
92
  throw new Error(`Could not find ${keyPrefix}pk_m for account ${account.toString()} whose address was successfully obtained with ${keyPrefix}pk_m_hash ${pkMHash.toString()}.`);
@@ -98,7 +100,7 @@ import { KEY_PREFIXES, computeAppSecretKey, deriveKeys, derivePublicKeyFromSecre
98
100
  }
99
101
  const skM = GrumpkinScalar.fromBuffer(skMBuffer);
100
102
  // The remaining awaits are non-DB computations. They are safe because no further IDB operations follow them.
101
- const computedPkMHash = await pkM.hash();
103
+ const computedPkMHash = await hashPublicKey(pkM);
102
104
  if (!computedPkMHash.equals(pkMHash)) {
103
105
  throw new Error(`Could not find ${keyPrefix}pkM for ${keyPrefix}pk_m_hash ${pkMHash.toString()}.`);
104
106
  }
@@ -107,7 +109,7 @@ import { KEY_PREFIXES, computeAppSecretKey, deriveKeys, derivePublicKeyFromSecre
107
109
  throw new Error(`Could not derive ${keyPrefix}pkM from ${keyPrefix}skM.`);
108
110
  }
109
111
  const skApp = await computeAppSecretKey(skM, contractAddress, keyPrefix);
110
- return new KeyValidationRequest(pkM, skApp);
112
+ return new KeyValidationRequest(pkMHash, skApp);
111
113
  });
112
114
  }
113
115
  /**
@@ -189,24 +191,29 @@ import { KEY_PREFIXES, computeAppSecretKey, deriveKeys, derivePublicKeyFromSecre
189
191
  ], DomainSeparator.OVSK_M);
190
192
  }
191
193
  /**
192
- * Retrieves the sk_m corresponding to the pk_m.
193
- * @throws If the provided public key is not associated with any of the registered accounts.
194
- * @param pkM - The master public key to get secret key for.
194
+ * Retrieves the sk_m corresponding to the given pk_m hash.
195
+ * @throws If the provided hash is not associated with any of the registered accounts.
196
+ * @param pkMHash - The master public key hash to get secret key for.
195
197
  * @returns A Promise that resolves to sk_m.
196
198
  * @dev Used when feeding the sk_m to the kernel circuit for keys verification.
197
- */ getMasterSecretKey(pkM) {
199
+ */ getMasterSecretKey(pkMHash) {
198
200
  return this.#db.transactionAsync(async ()=>{
199
- const [keyPrefix, account] = await this.getKeyPrefixAndAccount(pkM);
201
+ const [keyPrefix, account] = await this.getKeyPrefixAndAccount(pkMHash);
200
202
  const skStorageSuffix = secretKeyStorageSuffix(keyPrefix);
201
203
  const secretKeyBuffer = await this.#keys.getAsync(`${account.toString()}-${skStorageSuffix}`);
202
204
  if (!secretKeyBuffer) {
203
- throw new Error(`Could not find ${skStorageSuffix} for ${keyPrefix}pk_m ${pkM.toString()}. This should not happen.`);
205
+ throw new Error(`Could not find ${skStorageSuffix} for ${keyPrefix}pk_m_hash ${pkMHash.toString()}. This should not happen.`);
204
206
  }
205
207
  const skM = GrumpkinScalar.fromBuffer(secretKeyBuffer);
206
208
  // Non-DB computation — safe because no further IDB operations follow.
207
- const derivedpkM = await derivePublicKeyFromSecretKey(skM);
208
- if (!derivedpkM.equals(pkM)) {
209
- throw new Error(`Could not find ${skStorageSuffix} for ${keyPrefix}pkM ${pkM.toString()} in secret keys buffer.`);
209
+ // Integrity check: confirm the stored secret key still derives the requested hash. The check
210
+ // is hash-based rather than point-equal because the on-disk identifier is `pk_m_hash`;
211
+ // cryptographic collision resistance of `hashPublicKey` makes this equivalent to a
212
+ // direct point comparison in practice.
213
+ const derivedPkM = await derivePublicKeyFromSecretKey(skM);
214
+ const derivedPkMHash = await hashPublicKey(derivedPkM);
215
+ if (!derivedPkMHash.equals(pkMHash)) {
216
+ throw new Error(`Could not find ${skStorageSuffix} for ${keyPrefix}pk_m_hash ${pkMHash.toString()} in secret keys buffer.`);
210
217
  }
211
218
  return skM;
212
219
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aztec/key-store",
3
- "version": "5.0.0-nightly.20260521",
3
+ "version": "5.0.0-nightly.20260522",
4
4
  "type": "module",
5
5
  "exports": "./dest/index.js",
6
6
  "typedocOptions": {
@@ -57,10 +57,10 @@
57
57
  ]
58
58
  },
59
59
  "dependencies": {
60
- "@aztec/constants": "5.0.0-nightly.20260521",
61
- "@aztec/foundation": "5.0.0-nightly.20260521",
62
- "@aztec/kv-store": "5.0.0-nightly.20260521",
63
- "@aztec/stdlib": "5.0.0-nightly.20260521",
60
+ "@aztec/constants": "5.0.0-nightly.20260522",
61
+ "@aztec/foundation": "5.0.0-nightly.20260522",
62
+ "@aztec/kv-store": "5.0.0-nightly.20260522",
63
+ "@aztec/stdlib": "5.0.0-nightly.20260522",
64
64
  "tslib": "^2.4.0"
65
65
  },
66
66
  "devDependencies": {
package/src/key_store.ts CHANGED
@@ -15,6 +15,7 @@ import {
15
15
  computeAppSecretKey,
16
16
  deriveKeys,
17
17
  derivePublicKeyFromSecretKey,
18
+ hashPublicKey,
18
19
  } from '@aztec/stdlib/keys';
19
20
 
20
21
  /** Maps a key prefix to the storage suffix for the corresponding master secret key. */
@@ -57,17 +58,21 @@ export class KeyStore {
57
58
  masterIncomingViewingSecretKey,
58
59
  masterOutgoingViewingSecretKey,
59
60
  masterTaggingSecretKey,
61
+ masterNullifierPublicKey,
62
+ masterOutgoingViewingPublicKey,
63
+ masterTaggingPublicKey,
60
64
  publicKeys,
61
65
  } = await deriveKeys(sk);
62
66
 
63
- const completeAddress = await CompleteAddress.fromSecretKeyAndPartialAddress(sk, partialAddress);
67
+ const completeAddress = await CompleteAddress.fromPublicKeysAndPartialAddress(publicKeys, partialAddress);
64
68
  const { address: account } = completeAddress;
65
69
 
66
- // Compute hashes before transaction
67
- const masterNullifierPublicKeyHash = await publicKeys.masterNullifierPublicKey.hash();
68
- const masterIncomingViewingPublicKeyHash = await publicKeys.masterIncomingViewingPublicKey.hash();
69
- const masterOutgoingViewingPublicKeyHash = await publicKeys.masterOutgoingViewingPublicKey.hash();
70
- const masterTaggingPublicKeyHash = await publicKeys.masterTaggingPublicKey.hash();
70
+ // The kernel cannot check that nhpk/ovpk/tpk are on-curve or non-infinity, so the PXE/key-store
71
+ // must guarantee it before persistence. By design, the above derivation produces points that are on
72
+ // the curve and not at infinity.
73
+
74
+ // The npk/ovpk/tpk hashes are already in publicKeys; ivpk_m_hash is computed for indexing.
75
+ const masterIncomingViewingPublicKeyHash = await hashPublicKey(publicKeys.ivpkM);
71
76
 
72
77
  await this.#db.transactionAsync(async () => {
73
78
  // Naming of keys is as follows ${account}-${n/iv/ov/t}${sk/pk}_m
@@ -76,17 +81,17 @@ export class KeyStore {
76
81
  await this.#keys.set(`${account.toString()}-tsk_m`, masterTaggingSecretKey.toBuffer());
77
82
  await this.#keys.set(`${account.toString()}-nhk_m`, masterNullifierHidingKey.toBuffer());
78
83
 
79
- await this.#keys.set(`${account.toString()}-npk_m`, publicKeys.masterNullifierPublicKey.toBuffer());
80
- await this.#keys.set(`${account.toString()}-ivpk_m`, publicKeys.masterIncomingViewingPublicKey.toBuffer());
81
- await this.#keys.set(`${account.toString()}-ovpk_m`, publicKeys.masterOutgoingViewingPublicKey.toBuffer());
82
- await this.#keys.set(`${account.toString()}-tpk_m`, publicKeys.masterTaggingPublicKey.toBuffer());
84
+ await this.#keys.set(`${account.toString()}-npk_m`, masterNullifierPublicKey.toBuffer());
85
+ await this.#keys.set(`${account.toString()}-ivpk_m`, publicKeys.ivpkM.toBuffer());
86
+ await this.#keys.set(`${account.toString()}-ovpk_m`, masterOutgoingViewingPublicKey.toBuffer());
87
+ await this.#keys.set(`${account.toString()}-tpk_m`, masterTaggingPublicKey.toBuffer());
83
88
 
84
89
  // We store pk_m_hash under `account-{n/iv/ov/t}pk_m_hash` key to be able to obtain address and key prefix
85
90
  // using the #getKeyPrefixAndAccount function later on
86
- await this.#keys.set(`${account.toString()}-npk_m_hash`, masterNullifierPublicKeyHash.toBuffer());
91
+ await this.#keys.set(`${account.toString()}-npk_m_hash`, publicKeys.npkMHash.toBuffer());
87
92
  await this.#keys.set(`${account.toString()}-ivpk_m_hash`, masterIncomingViewingPublicKeyHash.toBuffer());
88
- await this.#keys.set(`${account.toString()}-ovpk_m_hash`, masterOutgoingViewingPublicKeyHash.toBuffer());
89
- await this.#keys.set(`${account.toString()}-tpk_m_hash`, masterTaggingPublicKeyHash.toBuffer());
93
+ await this.#keys.set(`${account.toString()}-ovpk_m_hash`, publicKeys.ovpkMHash.toBuffer());
94
+ await this.#keys.set(`${account.toString()}-tpk_m_hash`, publicKeys.tpkMHash.toBuffer());
90
95
  });
91
96
 
92
97
  // At last, we return the newly derived account address
@@ -120,7 +125,9 @@ export class KeyStore {
120
125
  return this.#db.transactionAsync(async () => {
121
126
  const [keyPrefix, account] = await this.getKeyPrefixAndAccount(pkMHash);
122
127
 
123
- // Now we find the master public key for the account
128
+ // Load the stored master public key point. The returned KVR carries only the hash, but we
129
+ // use the point here as a witness for two integrity checks below: (1) it matches the supplied
130
+ // hash, and (2) it matches the value derived from the stored secret key.
124
131
  const pkMBuffer = await this.#keys.getAsync(`${account.toString()}-${keyPrefix}pk_m`);
125
132
  if (!pkMBuffer) {
126
133
  throw new Error(
@@ -142,7 +149,7 @@ export class KeyStore {
142
149
  const skM = GrumpkinScalar.fromBuffer(skMBuffer);
143
150
 
144
151
  // The remaining awaits are non-DB computations. They are safe because no further IDB operations follow them.
145
- const computedPkMHash = await pkM.hash();
152
+ const computedPkMHash = await hashPublicKey(pkM);
146
153
  if (!computedPkMHash.equals(pkMHash)) {
147
154
  throw new Error(`Could not find ${keyPrefix}pkM for ${keyPrefix}pk_m_hash ${pkMHash.toString()}.`);
148
155
  }
@@ -154,7 +161,7 @@ export class KeyStore {
154
161
 
155
162
  const skApp = await computeAppSecretKey(skM, contractAddress, keyPrefix!);
156
163
 
157
- return new KeyValidationRequest(pkM, skApp);
164
+ return new KeyValidationRequest(pkMHash, skApp);
158
165
  });
159
166
  }
160
167
 
@@ -261,31 +268,36 @@ export class KeyStore {
261
268
  }
262
269
 
263
270
  /**
264
- * Retrieves the sk_m corresponding to the pk_m.
265
- * @throws If the provided public key is not associated with any of the registered accounts.
266
- * @param pkM - The master public key to get secret key for.
271
+ * Retrieves the sk_m corresponding to the given pk_m hash.
272
+ * @throws If the provided hash is not associated with any of the registered accounts.
273
+ * @param pkMHash - The master public key hash to get secret key for.
267
274
  * @returns A Promise that resolves to sk_m.
268
275
  * @dev Used when feeding the sk_m to the kernel circuit for keys verification.
269
276
  */
270
- public getMasterSecretKey(pkM: PublicKey): Promise<GrumpkinScalar> {
277
+ public getMasterSecretKey(pkMHash: Fr): Promise<GrumpkinScalar> {
271
278
  return this.#db.transactionAsync(async () => {
272
- const [keyPrefix, account] = await this.getKeyPrefixAndAccount(pkM);
279
+ const [keyPrefix, account] = await this.getKeyPrefixAndAccount(pkMHash);
273
280
 
274
281
  const skStorageSuffix = secretKeyStorageSuffix(keyPrefix);
275
282
  const secretKeyBuffer = await this.#keys.getAsync(`${account.toString()}-${skStorageSuffix}`);
276
283
  if (!secretKeyBuffer) {
277
284
  throw new Error(
278
- `Could not find ${skStorageSuffix} for ${keyPrefix}pk_m ${pkM.toString()}. This should not happen.`,
285
+ `Could not find ${skStorageSuffix} for ${keyPrefix}pk_m_hash ${pkMHash.toString()}. This should not happen.`,
279
286
  );
280
287
  }
281
288
 
282
289
  const skM = GrumpkinScalar.fromBuffer(secretKeyBuffer);
283
290
 
284
291
  // Non-DB computation — safe because no further IDB operations follow.
285
- const derivedpkM = await derivePublicKeyFromSecretKey(skM);
286
- if (!derivedpkM.equals(pkM)) {
292
+ // Integrity check: confirm the stored secret key still derives the requested hash. The check
293
+ // is hash-based rather than point-equal because the on-disk identifier is `pk_m_hash`;
294
+ // cryptographic collision resistance of `hashPublicKey` makes this equivalent to a
295
+ // direct point comparison in practice.
296
+ const derivedPkM = await derivePublicKeyFromSecretKey(skM);
297
+ const derivedPkMHash = await hashPublicKey(derivedPkM);
298
+ if (!derivedPkMHash.equals(pkMHash)) {
287
299
  throw new Error(
288
- `Could not find ${skStorageSuffix} for ${keyPrefix}pkM ${pkM.toString()} in secret keys buffer.`,
300
+ `Could not find ${skStorageSuffix} for ${keyPrefix}pk_m_hash ${pkMHash.toString()} in secret keys buffer.`,
289
301
  );
290
302
  }
291
303