Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clarify intention of op.previous #48

Open
nikolockenvitz opened this issue Feb 22, 2023 · 0 comments
Open

Clarify intention of op.previous #48

nikolockenvitz opened this issue Feb 22, 2023 · 0 comments

Comments

@nikolockenvitz
Copy link
Contributor

nikolockenvitz commented Feb 22, 2023

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?

ion-tools/src/did.js

Lines 38 to 42 in 02199dd

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant