orbitdb icon indicating copy to clipboard operation
orbitdb copied to clipboard

Custom Access Controller Example invalid?

Open CSDUMMI opened this issue 4 years ago • 6 comments

Isn't this custom access controller example is invalid, because identity is an undefined variable?

Specifically in the canAppend method from the Example:

    async canAppend(entry, identityProvider) {
      // logic to determine if entry can be added, for example:
      if (entry.payload === "hello world" && entry.identity.id === identity.id && identityProvider.verifyIdentity(entry.identity))
        return true

      return false
      }

What is identity? Where is it defined or is it even not defined?

CSDUMMI avatar Sep 21 '21 18:09 CSDUMMI

If I'm not mistaken it's an instance of Identity from the orbit-db-identity-provider package at https://github.com/orbitdb/orbit-db-identity-provider/blob/main/src/identity.js.

julienmalard avatar Sep 28 '21 15:09 julienmalard

But is the variable identity defined in this scope?

CSDUMMI avatar Sep 28 '21 16:09 CSDUMMI

No, if you're using typescript you'll have to import it as import Identity from "orbit-db-identity-provider/src/identity"

julienmalard avatar Sep 28 '21 17:09 julienmalard

Oh, I see what you mean. I think that on entry identity should be defined on each entry. If not it's probably an invalid entry.

julienmalard avatar Sep 28 '21 17:09 julienmalard

entry.identity.id === identity.id

Where is the latter part of this comparison defined within the example scope?

CSDUMMI avatar Sep 28 '21 17:09 CSDUMMI

Sorry, I see now. I think that in this example, it was meant to be compared to the identity of another entry. For instance, in the 3Box controller, identity is the identity used to sign the entry that is being deleted (https://github.com/3box/3box-orbitdb-plugins/blob/master/src/threadAccessController.js). I agree it's a bit confusing as is in the example.

julienmalard avatar Sep 28 '21 17:09 julienmalard

AC documentation has been updated to reflect changes made in the latest version. https://github.com/orbitdb/orbitdb/blob/main/docs/ACCESS_CONTROLLERS.md. If there is anything missing, please re-open this issue.

haydenyoung avatar Sep 17 '23 10:09 haydenyoung