orbitdb-archive / orbit-db-identity-provider Goto Github PK
View Code? Open in Web Editor NEWDefault identity provider for OrbitDB
License: MIT License
Default identity provider for OrbitDB
License: MIT License
Hi,
I am trying to find a way to have an identity that is linked to an Ethereum wallet. I tried the EthereumIdentityProvider, but whenever I connect with the same wallet address, I still get different identities (which makes impossible for a user to access the same app from different devices).
Then I tried to create a custom provider, did the addIdentityProvider, but when I run the createIdentity with the new provider, I consistently get the error "Class constructor Identities cannot be invoked without 'new'". Any idea what am I doing wrong? Or how can I achieve the same result some other way (users being able to connect from multiple devices)?
Also, why isn't the latest version of this package being used in the main orbit-db?
Thanks
We need a distribution build to be used in browser code with eg:
<script type="text/javascript" src="./node_modules/orbit-db-identity-provider/dist/index.min.js" charset="utf-8"></script>
We should prolly do the same for this as we do in https://github.com/orbitdb/orbit-db-keystore.
Following the step-by-step, I can connect to my Metamask provider and sign Identity. However, if I try to connect to Orbit-DB using this identity, this is the error I get in Orbit-DB.
2022-01-25T08:08:11.186Z [ERROR] orbit-db: Error: IdentityProvider type 'ethereum' is not supported
at getHandlerFor (/root/services/orbitDB/node_modules/orbit-db-identity-provider/src/identities.js:19:11)
at Identities.verifyIdentity (/root/services/orbitDB/node_modules/orbit-db-identity-provider/src/identities.js:92:30)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
at async saveToIpfs (/root/services/orbitDB/node_modules/orbit-db-store/src/Store.js:317:25)
at async pEachSeries (/root/services/orbitDB/node_modules/p-each-series/index.js:8:23)
at async OrbitDB._onMessage (/root/services/orbitDB/node_modules/orbit-db/src/OrbitDB.js:263:11)
orbit-db: 0.28.1
orbit-db-identity-provider: 0.4.0
Implemented with Node.JS
I have a need to be able to cache the signatures once an identity is initially created, and recreate the identity later without the user having to resign. It appears the only way to create an instance of the Identity class is by using Identities.createIdentity() which causes the IdentityProvider to sign the publicKey+id-signature.
Is there any reason why the Identity class can't be exported along with Identities and the providers? This would allow more flexibility for creating an identity using other methods.
Thanks!
npm audit
is showing a lot of security warnings, I don't know if any of them would affect this project, but it would be nice to have the npm audit
clean.
Considering that the constructor of identity requires the provider as the last argument, shouldn't the last argument here be identityProvider instead of this
?
I was looking at the feat/identity
PR again. This is how the Identity
looks now on the left and how I imagine it could look on the right (sorry for the horrible handwriting):
Key
publicKey : String | Buffer
privateKey : String | Buffer
encoding : String (e.g: hex)
The basic Identity object would look like this:
id: String
key: Key
provider : IdentityProvider (?)
type: String
(eg. ColonyIdentity, Ethereum address, IPFS PeerID, Dat address, DID, even Twitter can be an IdentityProvider)sign: (e: Object) => { key: Key, signature: String }
verify : (e: Entry) => boolean
(signature) orbitKeyOwnershipProof : String
(pkSignature) externalIdentityOwnershipProof : String
sign
and verify
would be provided by the IdentityProvider
so when we create an identity the object get a hold on whatever the implementation is.
This way we don't need to pass the provider to the log but just the identity object which will be responsible for signing and verifying entries (and to provide the necessary info for the AccessController canAppend
method).
How does it sound?
Right now every call to verifyIdentity verifies the signature done by the particular identity. In an ipfs-log with a lot of entries done by the same identity this creates a lot of computational overhead.
An easy way to mitigate this is to maintain a cache of identities that have been verified so that each identity (identity + key) only needs to be verified once.
I was working through getting Metamask to connect to orbit and ran into some issues connecting the ethereum-identity-provider.
Here's the code I started with based on some examples I found on the ethers.js project. The provider seems to want a "Wallet" object and I couldn't find any examples on how to get one from a web3 provider.
https://gist.github.com/ptoner/ed4b0a46805c218170b76aaa77ea421c
@shamb0t Helped me in the chat room and I found a solution that worked:
let signer = provider.getSigner(0)
signer.address = await signer.getAddress() // the provider is expecting a variable named 'wallet' that has an address property. Signer only has getAddress() and it's async.
let keystore = Keystore.create(keypath)
const type = EthIdentityProvider.type
const options = {
type: type,
keystore: keystore,
wallet: signer
}
let identity = await Identities.createIdentity(options)
const orbitdb = await OrbitDB.createInstance(ipfs, {
directory: "./orbitdb",
identity: identity
})
let store = await orbitdb.feed("test-post", {
accessController: {
write: [orbitdb.identity.id] //the examples say this should be "publicKey" instead but I think that might be outdated. This works.
}
})
The main thing that needed to change is 'this.wallet.address' to 'this.wallet.getAddress()' here
I'll put together a PR with this change. I'm unsure if the "orbitdb.identity.id" change would impact other identity providers though.
I have had problems in the last days, to run the OrbitDB examples.
The problem that appears in the web browser is the following:
Uncaught ReferenceError: Ipfs is not defined
Specifically in the file "example.js"
// Create IPFS instance const ipfs = new Ipfs({ repo: '/orbitdb/examples/browser/new/ipfs/0.33.1', start: true, preload: { enabled: false }, EXPERIMENTAL: { pubsub: true, }, config: { Addresses: { Swarm: [ // Use IPFS dev signal server // '/dns4/star-signal.cloud.ipfs.team/wss/p2p-webrtc-star', '/dns4/ws-star.discovery.libp2p.io/tcp/443/wss/p2p-websocket-star', // Use local signal server // '/ip4/0.0.0.0/tcp/9090/wss/p2p-webrtc-star', ] }, } })
You can see the problem in the following image:
The problem is due to the fact that there is a new version of the IPFS library, therefore the way to create the IPFS class instance has changed.
Solution:
To solve the problem, the example has been modified to be able to run the program correctly in the browser.
To solve the problem it is necessary to follow the following steps:
1)Modify the file "browser.html", with the dependencies in the correct path.
Before:
After:
Before:
After:
Once the previous steps have been carried out, we can now correctly run the example with the latest version of IPFS.
Have a nice day :)
./node_modules/did-jwt/lib/index.module.js 1720:17
Module parse failed: Unexpected token (1720:17)
File was processed with these loaders:
* ./node_modules/babel-loader/lib/index.js
You may need an additional loader to handle the result of these loaders.
| // TODO: should be able to use non base58 keys too
| return key.type === 'X25519KeyAgreementKey2019' && Boolean(key.publicKeyBase58);
> })) ?? [];
| if (!pks.length && !controllerEncrypters.length) throw new Error(`no_suitable_keys: Could not find x25519 key for ${did}`);
| return pks.map(pk => x25519Encrypter(base58ToBytes(pk.publicKeyBase58), pk.id)).concat(...controllerEncrypters);
I am trying to import orbit-db-identity-provider in a create-react-app app but did-jwt module parse fail when I import it.
Does anyone have an idea?
We can't access options from verifyIdentity
Hey,
I have an array of strings, each string is unique identifier, based on those as id I want to create identity.
My code looks like this:
for (let index = 0; index < array.length; index++) {
const string = array[index];
await IdentityProvider.createIdentity({ id })
}
The first iteration passed, but the second one throws:
/home/app/node_modules/level-packager/node_modules/levelup/lib/levelup.js:119
return callback(new OpenError(err))
Error [OpenError]: IO error: lock orbitdb/identity/identitykeys/LOCK: already held by process
at /home/app/node_modules/level-packager/node_modules/levelup/lib/levelup.js:119:23
at /home/app/node_modules/level-packager/node_modules/abstract-leveldown/abstract-leveldown.js:38:14
at /home/app/node_modules/level-packager/node_modules/deferred-leveldown/deferred-leveldown.js:31:21
at /home/app/node_modules/encoding-down/node_modules/abstract-leveldown/abstract-leveldown.js:38:14
at /home/app/node_modules/leveldown/node_modules/abstract-leveldown/abstract-leveldown.js:38:14
Emitted 'error' event on LevelUP instance at:
at /home/app/node_modules/level-packager/node_modules/levelup/lib/levelup.js:60:19
at /home/app/node_modules/level-packager/node_modules/levelup/lib/levelup.js:119:14
at /home/app/node_modules/level-packager/node_modules/abstract-leveldown/abstract-leveldown.js:38:14
My goal is to use this identity with ipfs-log, to store additional data, then at later point to get the identity, then the ipfs-log and my data.
I saw Level/levelup#667 but still cant figure out how to fix this one. Any ideas?
I can't use orbitdb local keystore for stoarge
so I serialize the identity to JSON and save it on another storage
How can I import the saved identity back to orbitdb every time my server starts?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.