In #generateOperation(), the previous property is set for all non-create operations. Based on the name, my first assumption was that it's just a pointer to the previous operation. From the implementation I suppose that it's a pointer to the "relevant" previous operation, i.e.
- for update operations, it points to the last create/update/recover operation
- for recover operations, it points to the last create/recover operation
(so that we can access the relevant private key in generateRequest). Is this understanding correct?
The logic that is implemented there is non-trivial and should either be refactored or explained with a comment IMHO. Also, wouldn't it make more sense to iterate through the array from the end and stop once the relevant operation is found?
|
if (type !== 'create') { |
|
op.previous = this.#ops.reduce((last, op) => { |
|
return op.operation === type || (op.operation === 'recover' && (type === 'deactivate' || type === 'update')) ? op : last; |
|
}, this.#ops[0]); |
|
} |
If my understanding is correct and you agree, I can open a PR to suggest an improved implementation.
In
#generateOperation(), thepreviousproperty is set for all non-create operations. Based on the name, my first assumption was that it's just a pointer to the previous operation. From the implementation I suppose that it's a pointer to the "relevant" previous operation, i.e.(so that we can access the relevant private key in generateRequest). Is this understanding correct?
The logic that is implemented there is non-trivial and should either be refactored or explained with a comment IMHO. Also, wouldn't it make more sense to iterate through the array from the end and stop once the relevant operation is found?
ion-tools/src/did.js
Lines 38 to 42 in 02199dd
If my understanding is correct and you agree, I can open a PR to suggest an improved implementation.