@calimero-network/mero-js 24.4.0 → 24.4.1

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.
@@ -34,9 +34,9 @@
34
34
  * - the credential certifies **the key this app asked about** — otherwise the
35
35
  * app stores a credential it cannot sign for, and every warrant it mints is
36
36
  * refused somewhere far from here;
37
- * - the credential is **internally consistent** — the root signed it and the
38
- * account it names is the one that root derives ({@link
39
- * verifyDeviceCredential});
37
+ * - the credential is **internally consistent** — the root signed it, the
38
+ * account it names is the one that root derives, and its device id was
39
+ * minted for that account ({@link verifyDeviceCredential});
40
40
  * - the account reported beside it is **the account the credential names** —
41
41
  * the app shows that id to a person and keys state by it, so a mismatch is a
42
42
  * credential filed under someone else's name.
@@ -34,9 +34,9 @@
34
34
  * - the credential certifies **the key this app asked about** — otherwise the
35
35
  * app stores a credential it cannot sign for, and every warrant it mints is
36
36
  * refused somewhere far from here;
37
- * - the credential is **internally consistent** — the root signed it and the
38
- * account it names is the one that root derives ({@link
39
- * verifyDeviceCredential});
37
+ * - the credential is **internally consistent** — the root signed it, the
38
+ * account it names is the one that root derives, and its device id was
39
+ * minted for that account ({@link verifyDeviceCredential});
40
40
  * - the account reported beside it is **the account the credential names** —
41
41
  * the app shows that id to a person and keys state by it, so a mismatch is a
42
42
  * credential filed under someone else's name.
@@ -155,14 +155,16 @@ export interface DeviceCredential {
155
155
  */
156
156
  export declare function parseDeviceCredential(credential: string): DeviceCredential;
157
157
  /**
158
- * Check that a credential says what it claims: the root signed it, and the
159
- * account it names is the one that root derives.
158
+ * Check that a credential says what it claims: the root signed it, the
159
+ * account it names is the one that root derives, and the device id was minted
160
+ * for that account.
160
161
  *
161
- * Both halves matter and neither implies the other. The signature says the
162
+ * The first two matter and neither implies the other. The signature says the
162
163
  * genesis root consented to these exact keys; the account derivation says the
163
164
  * certificate cannot have been re-pointed at a different account while keeping a
164
165
  * signature that verifies. A caller that checked only the first would accept a
165
- * certificate naming an account whose root never signed anything.
166
+ * certificate naming an account whose root never signed anything. The third
167
+ * stops a root claiming a device id minted for another account.
166
168
  *
167
169
  * What it does **not** establish is that the account is one the caller wanted.
168
170
  * Anyone can mint a root offline and certify any public key with it, so a
@@ -182,14 +182,16 @@ export function parseDeviceCredential(credential) {
182
182
  };
183
183
  }
184
184
  /**
185
- * Check that a credential says what it claims: the root signed it, and the
186
- * account it names is the one that root derives.
185
+ * Check that a credential says what it claims: the root signed it, the
186
+ * account it names is the one that root derives, and the device id was minted
187
+ * for that account.
187
188
  *
188
- * Both halves matter and neither implies the other. The signature says the
189
+ * The first two matter and neither implies the other. The signature says the
189
190
  * genesis root consented to these exact keys; the account derivation says the
190
191
  * certificate cannot have been re-pointed at a different account while keeping a
191
192
  * signature that verifies. A caller that checked only the first would accept a
192
- * certificate naming an account whose root never signed anything.
193
+ * certificate naming an account whose root never signed anything. The third
194
+ * stops a root claiming a device id minted for another account.
193
195
  *
194
196
  * What it does **not** establish is that the account is one the caller wanted.
195
197
  * Anyone can mint a root offline and certify any public key with it, so a
@@ -206,6 +208,11 @@ export async function verifyDeviceCredential(credential) {
206
208
  throw new Error(`this credential names account ${parsed.account}, but its root key ` +
207
209
  `derives ${derived} — the certificate was re-pointed at another account`);
208
210
  }
211
+ const nonce = fromHex(parsed.device, 'device', 32).subarray(0, 16);
212
+ if ((await mintDeviceId(parsed.account, nonce)) !== parsed.device) {
213
+ throw new Error(`this credential names device ${parsed.device}, which was not minted for ` +
214
+ `account ${parsed.account}; core refuses it`);
215
+ }
209
216
  const signed = await verifySignature(parsed.rootPublicKey, fromHex(parsed.signature, 'signature', 64), await deviceCertPayload(parsed));
210
217
  if (!signed) {
211
218
  throw new Error(`the root key of account ${parsed.account} did not sign this certificate`);