-
Why can't/don't we use the message ID (
messageCid
) of the initialRecordsWrite
as the record ID?(Last updated: 2023/05/16)
Because the initial
RecordsWrite
references the record ID in multiple places, so this would be a "chicken-and-egg" problem:recordId
property contains the record ID- If the initial
RecordsWrite
is for a root record in a DWN protocol, the record ID is the value of thecontextId
property - If the initial
RecordsWrite
is encrypted, the record ID is used in the final segment of the key derivation path
Because of the above constraints, we had to introduce a different algorithm (a.k.a as
entryId
generation) to deterministically compute therecordId
.See question why is
recordId
needed in theRecordsWrite
for more info. -
Why is
recordId
required in aRecordsWrite
?(Last updated: 2023/05/16)
This question should be further split into two:
- Why is
recordId
required in an initialRecordsWrite
(create)? - Why is
recordId
required in a subsequentRecordsWrite
(update)?
The latter question is much easier to answer: an update needs to reference the record that it is updating.
The answer to the first-part question is more complicated:
recordId
technically is not needed in an initialRecordsWrite
, but we chose to include it for data model consistency with subsequentRecordsWrite
, such that we can simply return the latest message of a record as the response toRecordsRead
andRecordsQuery
(for the most part, we still removeauthorization
) without needing to re-inject/rehydraterecordId
into any initialRecordsWrite
. It is also the same reason whycontextId
is required for the initialRecordsWrite
of a protocol-authorized record. - Why is
-
Why is
publicKeyId
required inKeyEncryptionInput
?(Last updated: 2023/05/19)
It is required because the ID of the public key (more precisely the ID of the asymmetric key pair) used to encrypt the symmetric key will need to be embedded as metadata (named
rootKeyId
), so that when a derived private key (which also contains the key ID) is given to the SDK to decrypt an encrypted record, the SDK is able to select the correct encrypted key for decryption. This is useful because if there are multiple encrypted keys attached to the record, the correct encrypted key will be selected immediately without the code needing to trial-and-error on every key until a correct key is found.Even if there is only one encrypted key attached to the encrypted record, there is no guarantee that the private key given is the correct corresponding private key, so it is still important to have the key ID so that the code can immediately reject the given private key if the ID does not match. There are a number of cases why a key ID mismatch can occur:
- The DWN owner might have published multiple encryption keys, and a wrong encryption key is chosen.
- The key used to encrypt the record might not be the DWN owner's key at all. For instance, a sender's encryption key is used instead.
-
Instead of introducing yet another property
publicKeyId
inKeyEncryptionInput
, why do we not just use thekid
property in the public JWK?(Last updated: 2023/05/19)
This is because:
kid
is an optional property of a JWK, there is no guarantee that the public JWK will contain it.- In the future public key may not always be given in JWK format. A key in raw bytes does not contain metadata such as key ID.
-
Why is
messageCid
mandated as the cursor for pagination?(Last updated: 2023/09/12)
The requirement for using
messageCid
as the cursor for pagination aims to ensure compatibility irrespective of DWN store implementations. The goal is for a query with the same cursor to yield identical results, regardless of which DWN is handling the query. This is useful because, if a DWN becomes unavailable after delivering a page of messages, the caller can switch to another DWN and resume fetching subsequent pages without interruption.
-
Can a record that is not protocol-authorized have
protocol
property in itsdescriptor
?(Last updated: 2023/05/23)
No.