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

Adds Cosmos support to Orbis SDK #2

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 77 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import { CeramicClient } from '@ceramicnetwork/http-client';
import { TileDocument } from '@ceramicnetwork/stream-tile';
import { DIDSession } from 'did-session'
import { SolanaAuthProvider } from '@ceramicnetwork/blockchain-utils-linking'
import { SolanaAuthProvider, CosmosAuthProvider } from '@ceramicnetwork/blockchain-utils-linking'
import { EthereumWebAuth, getAccountId } from '@didtools/pkh-ethereum'

/** To generate dids from a Seed */
Expand Down Expand Up @@ -357,6 +357,82 @@ export class Orbis {
}
}


async testConnectCosmos() {
let provider;
if ('keplr' in window) {
provider = window.keplr;
} else {
console.log("You're out of space, I'm out of time");
}

const resp = await provider.connect();
let address = resp.publicKey.toString();
console.log("Connected to Keplr with address: " + address);

/** Step 2: Create a Cosmic authProvider object using the address connected */
let authProvider;
try {
authProvider = new CosmosAuthProvider(provider, address);
} catch(e) {
console.log("Error creating CosmosAuthProvider: " + e);
return {
status: 300,
error: e,
result: "Error creating Cosmos provider object for Ceramic."
}
}

/** Step 3: Create a new session for Cosmic DID */
let did;
try {
/** Expire session in 30 days by default */
const oneMonth = 60 * 60 * 24 * 31;

this.session = await DIDSession.authorize(
authProvider,
{
resources: [`ceramic://*`],
expiresInSecs: oneMonth
}
);
did = this.session.did;
} catch(e) {
return {
status: 300,
error: e,
result: "Error creating a session for the DiD."
}
}
/** Step 4: Assign did to Ceramic object */
this.ceramic.did = did;
console.log("Connected to Ceramic using: " + this.session.id);

/** Step 6: Force index did to retrieve blockchain details automatically */
let _resDid = await forceIndexDid(this.session.id);

/** Step 7: Get user profile details */
let { data, error, status } = await this.getProfile(this.session.id);

let details;
if(data) {
details = data.details;
} else {
details = {
did: this.session.id,
profile: null
}
}

/** Return result */
return {
status: 200,
did: this.session.id,
details: details,
result: "Success connecting to the DiD."
}
}

/** Test function to check the status of the Solana provider */
async testConnectSolana() {
let provider;
Expand Down
2 changes: 1 addition & 1 deletion utils/EthereumAuthProviderDefault.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { EthereumAuthProvider, SolanaAuthProvider } from '@ceramicnetwork/blockchain-utils-linking'
import { EthereumAuthProvider, SolanaAuthProvider, CosmosAuthProvider } from '@ceramicnetwork/blockchain-utils-linking'


/** Replacing default EthereumAuthProvider class to force connection to an existing did if any. */
Expand Down