fix: remove circular dependencies form keychain package

This commit is contained in:
AhsanJavaid
2021-11-08 20:31:57 +05:00
committed by Reed Rosenbluth
parent 4a29e42cea
commit 140f62ddbf
4 changed files with 58 additions and 33 deletions

View File

@@ -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;
}

View File

@@ -3,8 +3,8 @@ 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,
@@ -12,7 +12,7 @@ import {
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 {
@@ -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;
@@ -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) {

View File

@@ -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,

View File

@@ -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',