Skip to content

Commit

Permalink
fix: remove circular dependencies form keychain package
Browse files Browse the repository at this point in the history
  • Loading branch information
ahsan-javaid authored and reedrosenbluth committed Nov 19, 2021
1 parent 4a29e42 commit 140f62d
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 33 deletions.
51 changes: 51 additions & 0 deletions packages/keychain/src/common.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import { IdentityKeyPair } from './utils';

interface RefreshOptions {
gaiaUrl: string;
}

export interface Identity {
keyPair: IdentityKeyPair;
address: string;
usernames: string[];
defaultUsername?: string;
profile?: Profile;
profileUrl(gaiaUrl: string): Promise<string>;
appPrivateKey(appDomain: string): string;
fetchNames(): Promise<string[]>;
refresh(opts: RefreshOptions): void;
makeAuthResponse(options: {
appDomain: string;
gaiaUrl: string;
transitPublicKey: string;
scopes: string[] | undefined;
stxAddress: string | undefined;
}): Promise<string>;
}

const PERSON_TYPE = 'Person';
const CONTEXT = 'http://schema.org';
const IMAGE_TYPE = 'ImageObject';

export interface ProfileImage {
'@type': typeof IMAGE_TYPE;
name: string;
contentUrl: string;
}

export interface Profile {
'@type': typeof PERSON_TYPE;
'@context': typeof CONTEXT;
apps?: {
[origin: string]: string;
};
appsMeta?: {
[origin: string]: {
publicKey: string;
storage: string;
};
};
name?: string;
image?: ProfileImage[];
[key: string]: any;
}
10 changes: 5 additions & 5 deletions packages/keychain/src/identity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@ import { bip32, ECPair } from 'bitcoinjs-lib';
import { getPublicKeyFromPrivate } from '@stacks/encryption';
import { makeAuthResponse } from '@stacks/auth';
import { getProfileURLFromZoneFile } from './utils';

import { IdentityKeyPair } from './utils/index';
import { Profile, Identity as IdentifyInterface } from './common';
import { IdentityKeyPair } from './utils';
import {
makeGaiaAssociationToken,
DEFAULT_GAIA_HUB,
getHubInfo,
connectToGaiaHubWithConfig,
} from './utils/gaia';
import IdentityAddressOwnerNode from './nodes/identity-address-owner-node';
import { Profile, fetchProfile, DEFAULT_PROFILE, signAndUploadProfile } from './profiles';
import { fetchProfile, DEFAULT_PROFILE, signAndUploadProfile } from './profiles';
import { ecPairToAddress } from '@stacks/encryption';

interface IdentityConstructorOptions {
Expand All @@ -27,7 +27,7 @@ interface RefreshOptions {
gaiaUrl: string;
}

export class Identity {
export class Identity implements IdentifyInterface {
public keyPair: IdentityKeyPair;
public address: string;
public defaultUsername?: string;
Expand Down Expand Up @@ -64,7 +64,7 @@ export class Identity {
const appPrivateKey = this.appPrivateKey(appDomain);
const hubInfo = await getHubInfo(gaiaUrl);
const profileUrl = await this.profileUrl(hubInfo.read_url_prefix);
const profile =
const profile: Profile =
(await fetchProfile({ identity: this, gaiaUrl: hubInfo.read_url_prefix })) || DEFAULT_PROFILE;
if (scopes.includes('publish_data')) {
if (!profile.apps) {
Expand Down
1 change: 1 addition & 0 deletions packages/keychain/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export { decrypt } from './encryption/decrypt';
export { encrypt } from './encryption/encrypt';
export * from './profiles';
export * from './identity';
export { Profile } from './common';

export default {
Wallet,
Expand Down
29 changes: 1 addition & 28 deletions packages/keychain/src/profiles.ts
Original file line number Diff line number Diff line change
@@ -1,37 +1,10 @@
import { connectToGaiaHub } from '@stacks/storage';
import { signProfileToken, wrapProfileToken, makeProfileZoneFile } from '@stacks/profile';
import { Identity, Profile } from './common';
import { IdentityKeyPair } from './utils';
import { uploadToGaiaHub } from './utils/gaia';
import Identity from './identity';
import { GaiaHubConfig } from '@stacks/storage';

const PERSON_TYPE = 'Person';
const CONTEXT = 'http://schema.org';
const IMAGE_TYPE = 'ImageObject';

export interface ProfileImage {
'@type': typeof IMAGE_TYPE;
name: string;
contentUrl: string;
}

export interface Profile {
'@type': typeof PERSON_TYPE;
'@context': typeof CONTEXT;
apps?: {
[origin: string]: string;
};
appsMeta?: {
[origin: string]: {
publicKey: string;
storage: string;
};
};
name?: string;
image?: ProfileImage[];
[key: string]: any;
}

export const DEFAULT_PROFILE: Profile = {
'@type': 'Person',
'@context': 'http://schema.org',
Expand Down

1 comment on commit 140f62d

@vercel
Copy link

@vercel vercel bot commented on 140f62d Nov 19, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.