Skip to content

Clarify intention of op.previous #48

Description

@nikolockenvitz

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions