Created
October 22, 2020 17:37
-
-
Save aditya-vijaykumar/900d036e6051195a2a9a395a4a3ea918 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
import web3Modal from './providers.js' | |
import { DID } from 'dids' | |
import CeramicClient from '@ceramicnetwork/ceramic-http-client' | |
import { IDXWeb } from '@ceramicstudio/idx-web' | |
import { publishIDXConfig } from '@ceramicstudio/idx-tools' | |
const { ThreeIdConnect, EthereumAuthProvider } = require('./../src/index') | |
const THREEID_CONNECT_URL = 'https://3idconnect.org/index.html' | |
const DEFAULT_API_URL = 'https://ceramic.3boxlabs.com' | |
const API_URL = "http://localhost:7007" | |
const threeIdConnect = new ThreeIdConnect(THREEID_CONNECT_URL) | |
const ceramic = new CeramicClient(DEFAULT_API_URL) | |
const set = async () => { | |
const doc = await idx.set('profile', { name: 'Aditya' }) | |
console.log('doc created: ' + doc) | |
} | |
const retrieve = async () => { | |
const MyProfile = await idx.get('profile', idx.id) | |
} | |
const explore = async () => { | |
const bobClient = new IDXWeb({ ceramic, definitions: appDefinitions, connect: threeIdConnect }) | |
const MyProfile = await bobClient.get('profile', idx.id) | |
console.log('My Profile: ') | |
console.dir(MyProfile) | |
} | |
const authenticate = async () => { | |
const ethProvider = await web3Modal.connect() | |
const addresses = await ethProvider.request({ method: 'eth_accounts' }) | |
console.log(addresses) | |
console.log('Got the address') | |
const authProvider = new EthereumAuthProvider(ethProvider, addresses[0]) | |
await threeIdConnect.connect(authProvider) | |
console.log('3id connect func executed') | |
const didProvider = await threeIdConnect.getDidProvider() | |
console.log('didProvider: ' + didProvider) | |
console.dir(didProvider) | |
const did = new DID({ provider: didProvider }) | |
console.dir(did) | |
await did.authenticate() | |
console.log('This is the did ' + did.id) | |
const jwstest = await did.createJWS({ hello: 'world' }) | |
console.log(jwstest) | |
const { definitions } = await publishIDXConfig(ceramic) | |
console.log('The Definitions') | |
console.log(definitions) | |
await ceramic.setDIDProvider(didProvider) | |
const appDefinitions = { | |
profile: definitions.basicProfile | |
} | |
const idx = new IDXWeb({ ceramic, definitions: appDefinitions, connect: threeIdConnect }) | |
console.log('new instance created') | |
const ethereum = { provider: ethProvider, address: addresses[0] } | |
await idx.authenticate(ethereum) | |
if (idx.authenticated) { | |
console.log('authenticated IDX!!') | |
} | |
} | |
bauth.addEventListener('click', authenticate) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment