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

Code Sample Issues in OrbitDB Documentation for Access Controllers #1182

Open
orwithout opened this issue May 9, 2024 · 2 comments
Open

Comments

@orwithout
Copy link

orwithout commented May 9, 2024

I encountered several issues while following the example code in the Access Controllers section of the OrbitDB documentation. Here's the problematic part of the code snippet as found in the documentation:

image

The example code includes an import statement:

import { Libp2pOptions } from './config/libp2p.js'

which appears to reference a local module configuration. Upon revisiting the documentation on the Helia project's GitHub page at Helia's GitHub, I noticed that we could directly use

const orbitdb = await createOrbitDB()

to create a node instead. After making this adjustment, I was able to run the example code. However, I encountered some errors in the browser's console as follows:
image
Error log text:

test_odb_id.js:16  Uncaught TypeError: Cannot read properties of undefined (reading 'grant')
    at test_odb_id.js:16:11
(anonymous) @ test_odb_id.js:16
IndexedDB (async)
_open @ index.js:77
open @ abstract-level.js:153
LevelStorage @ level.js:30
KeyStore @ key-store.js:126
await in KeyStore (async)
Identities @ identities.js:40
(anonymous) @ test_odb_id.js:11
Show 5 more frames
Show less

identities.js:73  Uncaught (in promise) TypeError: Cannot create property 'keystore' on string 'userB'
    at Object.createIdentity (identities.js:73:13)
    at test_odb_id.js:12:36
createIdentity @ identities.js:73
(anonymous) @ test_odb_id.js:12
Show 1 more frame
Show less

index.js:64  Uncaught (in promise) Error: `undefined` is not supported by the IPLD Data Model and cannot be encoded
    at undefinedEncoder (index.js:64:9)
    at objectToTokens (encode.js:289:20)
    at Array (encode.js:228:22)
    at objectToTokens (encode.js:289:20)
    at Object (encode.js:262:9)
    at objectToTokens (encode.js:298:10)
    at encodeCustom (encode.js:430:18)
    at encode (encode.js:461:10)
    at Object.encode2 (index.js:140:39)
    at encode (block.js:181:23)

Environment

  • Browser Version: Google Chrome 123.0.6312, Microsoft Edge 123.2420
  • Operating System: Windows 2022
  • helia Version: 4.2.1
  • @Orbitdb/core Version: 2.2.0

Code Source to Run

html:

<!-- odb_test.html -->
<!DOCTYPE html>
<html lang="en">
<head><meta charset="UTF-8"></head>
<body>
    <h2>ODB Test</h2>
    <script type="module" crossorigin src="./odb_test.js"></script>
</body>
</html>

javascritp:

// odb_test.js
import { createLibp2p } from 'libp2p';
import { createHelia } from 'helia';
import { LevelBlockstore } from 'blockstore-level';
import { createOrbitDB, Identities, OrbitDBAccessController } from '@orbitdb/core';
// import { Libp2pOptions } from './config/libp2p.js'

// const blockstore = new LevelBlockstore('./ipfs')  //This line was not used in the original text
// const libp2p = await createLibp2p(Libp2pOptions)
// const ipfs = await createHelia({ libp2p })
const ipfs = await createHelia();

const orbitdb = await createOrbitDB({ ipfs });

const identities = await Identities({ ipfs });
const anotherIdentity = identities.createIdentity('userB');

const db = orbitdb.open('my-db', { AccessController: OrbitDBAccessController({ write: [orbitdb.identity.id, anotherIdentity.id]})}); // This line in the original text is missing a closing `}`

db.access.grant('write', anotherIdentity.id);
// db.access.revoke('write', anotherIdentity.id)
console.log('access.type:',db.access.type);
console.log('access.write',db.access.write);
@haydenyoung
Copy link
Member

Thanks for bringing this to our attention as this is not entirely clear.

./config/libp2p.js is Libp2p configuration which you create and then import into your OrbitDB implementation. See this section for an explanation of what ./config/libp2p.js entails.

We'll try and update the documentation to be clearer.

If the problem persists, please add a comment to this issue.

@orwithout
Copy link
Author

orwithout commented May 19, 2024

Thank you for your response. It seems the configuration provided is for a Node.js environment:
image
However, I am trying to run this in a browser environment and follow the example to add users and configure permissions. Despite adapting the configuration to be browser-compatible, I still encounter the error "Cannot create property 'keystore' on string 'userB'". If you could provide a complete configuration example for the browser environment, I would greatly appreciate it. Thank you.

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

2 participants