Last active
July 22, 2019 16:58
-
-
Save ptoner/ed4b0a46805c218170b76aaa77ea421c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//This seems to be how ethers wants you to connect to web3. | |
let provider = new ethers.providers.Web3Provider(web3.currentProvider) | |
let signer = provider.getSigner(0) | |
//Ok now I have this signers object...what do I do with it? Orbit seems to want a Wallet instead. | |
//I can't seem to find a way to create the actual "Wallet" object. | |
let keystore = Keystore.create(keypath) | |
const type = EthIdentityProvider.type | |
const options = { | |
type: type, | |
keystore: keystore, | |
signer: signer //This sort of works in that it successfull returns an Identity object that seems correct, but it won't actually let me write anything to a store that I give permissions to. I've also tried calling this "wallet" like in the test. | |
} | |
let identity = await Identities.createIdentity(options) | |
const orbitdb = await OrbitDB.createInstance(ipfs, { | |
directory: "./orbitdb", | |
identity: identity | |
}) | |
console.log(JSON.stringify(orbitdb.identity)) | |
//actually prints out things that appear correct-ish | |
{ | |
"id": "0x3c2EB33A71A4A5E8e2A25dfEe8bebD64BBD9404e", | |
"publicKey": "04bf2560d196b1533903cf0a11f2828b2a00a6ca5d80c48f39f79066d74bbc12143ef54fc076afb37cbdc1c209fe23e3130fdbb6fd61a2da159c3a41a979777728", | |
"signatures": { | |
"id": "3044022058688d54fb3f64538aa256ae7ac133cb7da2aa8d4a81efa0d404a3545bf0dbfa02200a27b0678b702fced9931aafbd867bba0faccc7ad685c477697d02a5d285f1de", | |
"publicKey": "0x50c026658d50504f4e4cf70ace12ff7dbd85e567322b9cc55deba169b58e0d041ae2d44e5d0961fd97768bb17cf0b123375528f0c770ffb4d2531595b06686271b" | |
}, | |
"type": "ethereum" | |
} | |
let store = await orbitdb.feed("test-post", { | |
accessController: { | |
write: [orbitdb.identity.publicKey] | |
} | |
}) | |
await this.store.add(post) | |
//prints "Error: Could not append entry, key "0x3c2EB33A71A4A5E8e2A25dfEe8bebD64BBD9404e" is not allowed to write to the log" | |
//Do I need to pass the identity to the feed store too somehow? | |
//If I change the accessController to be | |
//write: [orbitdb.identity.id] | |
//it actually does work. But this was from trial and error and not from any documentation I can find. So I worry it's not correct. | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@ptoner lgtm except I think line 14 should be:
and line 40: