mirror of
https://github.com/alexgo-io/stacks.js.git
synced 2026-01-12 22:52:34 +08:00
fix: remove circular dependencies form keychain package
This commit is contained in:
committed by
Reed Rosenbluth
parent
4a29e42cea
commit
140f62ddbf
51
packages/keychain/src/common.ts
Normal file
51
packages/keychain/src/common.ts
Normal 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;
|
||||
}
|
||||
@@ -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) {
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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',
|
||||
|
||||
Reference in New Issue
Block a user