Revert "Merge branch 'bvander/loading-registries' into 'master'"
This reverts merge request !29
This commit is contained in:
parent
a93be027c6
commit
06ddf4cb0f
1469
package-lock.json
generated
1469
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@ -33,10 +33,10 @@
|
||||
"@angular/platform-browser-dynamic": "~10.2.0",
|
||||
"@angular/router": "~10.2.0",
|
||||
"@angular/service-worker": "~10.2.0",
|
||||
"@cicnet/cic-client": "^0.1.6",
|
||||
"@cicnet/schemas-data-validator": "*",
|
||||
"@popperjs/core": "^2.5.4",
|
||||
"bootstrap": "^4.5.3",
|
||||
"cic-client": "0.1.4",
|
||||
"cic-client-meta": "0.0.7-alpha.6",
|
||||
"ethers": "^5.0.31",
|
||||
"http-server": "^0.12.3",
|
||||
|
@ -1,4 +1,3 @@
|
||||
import { AuthService } from '@app/_services';
|
||||
import { Injectable } from '@angular/core';
|
||||
import { HttpRequest, HttpHandler, HttpEvent, HttpInterceptor } from '@angular/common/http';
|
||||
import { Observable } from 'rxjs';
|
||||
@ -9,11 +8,10 @@ export class HttpConfigInterceptor implements HttpInterceptor {
|
||||
|
||||
intercept(request: HttpRequest<unknown>, next: HttpHandler): Observable<HttpEvent<unknown>> {
|
||||
// const token: string = sessionStorage.getItem(btoa('CICADA_SESSION_TOKEN'));
|
||||
const token: string = AuthService.getSessionToken();
|
||||
|
||||
if (token) {
|
||||
request = request.clone({ headers: request.headers.set('Authorization', 'Bearer ' + token) });
|
||||
}
|
||||
// if (token) {
|
||||
// request = request.clone({headers: request.headers.set('Authorization', 'Bearer ' + token)});
|
||||
// }
|
||||
|
||||
return next.handle(request);
|
||||
}
|
||||
|
@ -14,13 +14,6 @@ import { BehaviorSubject, Observable } from 'rxjs';
|
||||
providedIn: 'root',
|
||||
})
|
||||
export class AuthService {
|
||||
constructor(
|
||||
private httpClient: HttpClient,
|
||||
private loggingService: LoggingService,
|
||||
private errorDialogService: ErrorDialogService
|
||||
) {
|
||||
this.mutableKeyStore = new MutablePgpKeyStore();
|
||||
}
|
||||
mutableKeyStore: MutableKeyStore;
|
||||
trustedUsers: Array<Staff> = [];
|
||||
private trustedUsersList: BehaviorSubject<Array<Staff>> = new BehaviorSubject<Array<Staff>>(
|
||||
@ -28,8 +21,12 @@ export class AuthService {
|
||||
);
|
||||
trustedUsersSubject: Observable<Array<Staff>> = this.trustedUsersList.asObservable();
|
||||
|
||||
public static getSessionToken(): string {
|
||||
return sessionStorage.getItem(btoa('CICADA_SESSION_TOKEN'));
|
||||
constructor(
|
||||
private httpClient: HttpClient,
|
||||
private loggingService: LoggingService,
|
||||
private errorDialogService: ErrorDialogService
|
||||
) {
|
||||
this.mutableKeyStore = new MutablePgpKeyStore();
|
||||
}
|
||||
|
||||
async init(): Promise<void> {
|
||||
@ -39,6 +36,10 @@ export class AuthService {
|
||||
}
|
||||
}
|
||||
|
||||
getSessionToken(): string {
|
||||
return sessionStorage.getItem(btoa('CICADA_SESSION_TOKEN'));
|
||||
}
|
||||
|
||||
setSessionToken(token): void {
|
||||
sessionStorage.setItem(btoa('CICADA_SESSION_TOKEN'), token);
|
||||
}
|
||||
@ -49,7 +50,7 @@ export class AuthService {
|
||||
|
||||
getWithToken(): Promise<boolean> {
|
||||
const headers = {
|
||||
Authorization: 'Bearer ' + AuthService.getSessionToken,
|
||||
Authorization: 'Bearer ' + this.getSessionToken,
|
||||
'Content-Type': 'application/json;charset=utf-8',
|
||||
'x-cic-automerge': 'none',
|
||||
};
|
||||
@ -58,9 +59,9 @@ export class AuthService {
|
||||
};
|
||||
return fetch(environment.cicMetaUrl, options).then((response) => {
|
||||
if (!response.ok) {
|
||||
this.loggingService.sendErrorLevelMessage('failed to get with auth token.', this, {
|
||||
error: '',
|
||||
});
|
||||
this.loggingService.sendErrorLevelMessage('failed to get with auth token.',
|
||||
this,
|
||||
{ error: "" });
|
||||
|
||||
return false;
|
||||
}
|
||||
@ -78,11 +79,12 @@ export class AuthService {
|
||||
const options = {
|
||||
headers,
|
||||
};
|
||||
return fetch(environment.cicMetaUrl, options);
|
||||
return fetch(environment.cicMetaUrl, options)
|
||||
}
|
||||
|
||||
getChallenge(): Promise<any> {
|
||||
return fetch(environment.cicMetaUrl).then((response) => {
|
||||
return fetch(environment.cicMetaUrl)
|
||||
.then(response => {
|
||||
if (response.status === 401) {
|
||||
const authHeader: string = response.headers.get('WWW-Authenticate');
|
||||
return hobaParseChallengeHeader(authHeader);
|
||||
@ -91,9 +93,9 @@ export class AuthService {
|
||||
}
|
||||
|
||||
async login(): Promise<boolean> {
|
||||
if (AuthService.getSessionToken()) {
|
||||
if (this.getSessionToken()) {
|
||||
sessionStorage.removeItem(btoa('CICADA_SESSION_TOKEN'));
|
||||
}
|
||||
} else {
|
||||
const o = await this.getChallenge();
|
||||
|
||||
const r = await signChallenge(
|
||||
@ -103,25 +105,29 @@ export class AuthService {
|
||||
this.mutableKeyStore
|
||||
);
|
||||
|
||||
const tokenResponse = await this.sendSignedChallenge(r).then((response) => {
|
||||
const token = response.headers.get('Token');
|
||||
const tokenResponse = await this.sendSignedChallenge(r)
|
||||
.then(response => {
|
||||
const token = response.headers.get('Token')
|
||||
if (token) {
|
||||
return token;
|
||||
return token
|
||||
}
|
||||
if (response.status === 401) {
|
||||
throw new HttpError('You are not authorized to use this system', response.status);
|
||||
let e = new HttpError("You are not authorized to use this system", response.status)
|
||||
throw e
|
||||
}
|
||||
if (!response.ok) {
|
||||
throw new HttpError('Unknown error from authentication server', response.status);
|
||||
let e = new HttpError("Unknown error from authentication server", response.status)
|
||||
throw e
|
||||
}
|
||||
});
|
||||
})
|
||||
|
||||
if (tokenResponse) {
|
||||
this.setSessionToken(tokenResponse);
|
||||
this.setState('Click button to log in');
|
||||
return true;
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
loginView(): void {
|
||||
|
@ -1,6 +1,6 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { Settings } from '@app/_models';
|
||||
import { TransactionHelper } from '@cicnet/cic-client';
|
||||
import { TransactionHelper } from 'cic-client';
|
||||
import { first } from 'rxjs/operators';
|
||||
import { TransactionService } from '@app/_services/transaction.service';
|
||||
import { environment } from '@src/environments/environment';
|
||||
|
@ -1,10 +1,8 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { environment } from '@src/environments/environment';
|
||||
import { CICRegistry, FileGetter } from '@cicnet/cic-client';
|
||||
import { AccountIndex, TokenRegistry } from '@app/_eth';
|
||||
import { CICRegistry, FileGetter } from 'cic-client';
|
||||
import { HttpGetter } from '@app/_helpers';
|
||||
import { Web3Service } from '@app/_services/web3.service';
|
||||
import { BehaviorSubject } from 'rxjs';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root',
|
||||
@ -12,9 +10,8 @@ import { BehaviorSubject } from 'rxjs';
|
||||
export class RegistryService {
|
||||
static fileGetter: FileGetter = new HttpGetter();
|
||||
private static registry: CICRegistry;
|
||||
private static tokenRegistry: TokenRegistry;
|
||||
private static accountRegistry: AccountIndex;
|
||||
private static load: BehaviorSubject<boolean> = new BehaviorSubject<boolean>(false);
|
||||
|
||||
constructor() {}
|
||||
|
||||
public static async getRegistry(): Promise<CICRegistry> {
|
||||
if (!RegistryService.registry) {
|
||||
@ -27,43 +24,7 @@ export class RegistryService {
|
||||
);
|
||||
RegistryService.registry.declaratorHelper.addTrust(environment.trustedDeclaratorAddress);
|
||||
await RegistryService.registry.load();
|
||||
RegistryService.load.next(true);
|
||||
return RegistryService.registry;
|
||||
}
|
||||
return RegistryService.registry;
|
||||
}
|
||||
|
||||
public static async getTokenRegistry(): Promise<TokenRegistry> {
|
||||
if (!RegistryService.tokenRegistry) {
|
||||
// then initial it
|
||||
const registry = await RegistryService.getRegistry();
|
||||
RegistryService.load.subscribe(async (status: boolean) => {
|
||||
if (status) {
|
||||
const tokenRegistryAddress = await registry.getContractAddressByName('TokenRegistry');
|
||||
RegistryService.tokenRegistry = new TokenRegistry(tokenRegistryAddress);
|
||||
return RegistryService.tokenRegistry;
|
||||
}
|
||||
});
|
||||
// return new Promise((resolve, reject) => {
|
||||
// resolve(RegistryService.tokenRegistry);
|
||||
// });
|
||||
}
|
||||
return RegistryService.tokenRegistry;
|
||||
}
|
||||
|
||||
public static async getAccountRegistry(): Promise<AccountIndex> {
|
||||
if (!RegistryService.accountRegistry) {
|
||||
const registry = await RegistryService.getRegistry();
|
||||
RegistryService.load.subscribe(async (status: boolean) => {
|
||||
if (status) {
|
||||
const accountIndexAddress: string = await registry.getContractAddressByName(
|
||||
'AccountRegistry'
|
||||
);
|
||||
RegistryService.accountRegistry = new AccountIndex(accountIndexAddress);
|
||||
return RegistryService.accountRegistry;
|
||||
}
|
||||
});
|
||||
}
|
||||
return RegistryService.accountRegistry;
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { CICRegistry } from '@cicnet/cic-client';
|
||||
import { CICRegistry } from 'cic-client';
|
||||
import { TokenRegistry } from '@app/_eth';
|
||||
import { HttpClient } from '@angular/common/http';
|
||||
import { RegistryService } from '@app/_services/registry.service';
|
||||
import { Token } from '@app/_models';
|
||||
import {BehaviorSubject, Observable, Subject} from 'rxjs';
|
||||
@ -11,19 +12,21 @@ import { BehaviorSubject, Observable, Subject } from 'rxjs';
|
||||
export class TokenService {
|
||||
registry: CICRegistry;
|
||||
tokenRegistry: TokenRegistry;
|
||||
onload: (status: boolean) => void;
|
||||
tokens: Array<Token> = [];
|
||||
private tokensList: BehaviorSubject<Array<Token>> = new BehaviorSubject<Array<Token>>(
|
||||
this.tokens
|
||||
);
|
||||
private tokensList: BehaviorSubject<Array<Token>> = new BehaviorSubject<Array<Token>>(this.tokens);
|
||||
tokensSubject: Observable<Array<Token>> = this.tokensList.asObservable();
|
||||
load: BehaviorSubject<boolean> = new BehaviorSubject<boolean>(false);
|
||||
|
||||
constructor() {}
|
||||
constructor(private httpClient: HttpClient) {}
|
||||
|
||||
async init(): Promise<void> {
|
||||
this.registry = await RegistryService.getRegistry();
|
||||
this.tokenRegistry = await RegistryService.getTokenRegistry();
|
||||
this.load.next(true);
|
||||
this.registry.onload = async (address: string): Promise<void> => {
|
||||
this.tokenRegistry = new TokenRegistry(
|
||||
await this.registry.getContractAddressByName('TokenRegistry')
|
||||
);
|
||||
this.onload(this.tokenRegistry !== undefined);
|
||||
};
|
||||
}
|
||||
|
||||
addToken(token: Token): void {
|
||||
|
@ -14,7 +14,7 @@ import { AuthService } from '@app/_services/auth.service';
|
||||
import { defaultAccount } from '@app/_models';
|
||||
import { LoggingService } from '@app/_services/logging.service';
|
||||
import { HttpClient } from '@angular/common/http';
|
||||
import { CICRegistry } from '@cicnet/cic-client';
|
||||
import { CICRegistry } from 'cic-client';
|
||||
import { RegistryService } from '@app/_services/registry.service';
|
||||
import Web3 from 'web3';
|
||||
import { Web3Service } from '@app/_services/web3.service';
|
||||
|
@ -7,9 +7,10 @@ import { ArgPair, Envelope, Phone, Syncable, User } from 'cic-client-meta';
|
||||
import { AccountDetails } from '@app/_models';
|
||||
import { LoggingService } from '@app/_services/logging.service';
|
||||
import { TokenService } from '@app/_services/token.service';
|
||||
import { AccountIndex } from '@app/_eth';
|
||||
import { MutableKeyStore, PGPSigner, Signer } from '@app/_pgp';
|
||||
import { RegistryService } from '@app/_services/registry.service';
|
||||
import { CICRegistry } from '@cicnet/cic-client';
|
||||
import { CICRegistry } from 'cic-client';
|
||||
import { AuthService } from '@app/_services/auth.service';
|
||||
import { personValidation, vcardValidation } from '@app/_helpers';
|
||||
import { add0x } from '@src/assets/js/ethtx/dist/hex';
|
||||
@ -42,7 +43,7 @@ export class UserService {
|
||||
) {}
|
||||
|
||||
async init(): Promise<void> {
|
||||
// await this.authService.init();
|
||||
await this.authService.init();
|
||||
await this.tokenService.init();
|
||||
this.keystore = this.authService.mutableKeyStore;
|
||||
this.signer = new PGPSigner(this.keystore);
|
||||
@ -178,8 +179,11 @@ export class UserService {
|
||||
|
||||
async loadAccounts(limit: number = 100, offset: number = 0): Promise<void> {
|
||||
this.resetAccountsList();
|
||||
const accountRegistry = await RegistryService.getAccountRegistry();
|
||||
const accountAddresses: Array<string> = await accountRegistry.last(limit);
|
||||
const accountIndexAddress: string = await this.registry.getContractAddressByName(
|
||||
'AccountRegistry'
|
||||
);
|
||||
const accountIndexQuery = new AccountIndex(accountIndexAddress);
|
||||
const accountAddresses: Array<string> = await accountIndexQuery.last(limit);
|
||||
this.loggingService.sendInfoLevelMessage(accountAddresses);
|
||||
for (const accountAddress of accountAddresses.slice(offset, offset + limit)) {
|
||||
await this.getAccountByAddress(accountAddress, limit);
|
||||
@ -197,13 +201,11 @@ export class UserService {
|
||||
const account: Syncable = Envelope.fromJSON(JSON.stringify(res)).unwrap();
|
||||
const accountInfo = account.m.data;
|
||||
await personValidation(accountInfo);
|
||||
this.tokenService.load.subscribe(async (status: boolean) => {
|
||||
if (status) {
|
||||
this.tokenService.onload = async (status: boolean): Promise<void> => {
|
||||
accountInfo.balance = await this.tokenService.getTokenBalance(
|
||||
accountInfo.identities.evm[`bloxberg:${environment.bloxbergChainId}`][0]
|
||||
);
|
||||
}
|
||||
});
|
||||
};
|
||||
accountInfo.vcard = vCard.parse(atob(accountInfo.vcard));
|
||||
await vcardValidation(accountInfo.vcard);
|
||||
this.addAccount(accountInfo, limit);
|
||||
|
@ -22,7 +22,7 @@ export class AuthComponent implements OnInit {
|
||||
private authService: AuthService,
|
||||
private formBuilder: FormBuilder,
|
||||
private router: Router,
|
||||
private errorDialogService: ErrorDialogService
|
||||
private errorDialogService: ErrorDialogService,
|
||||
) {}
|
||||
|
||||
async ngOnInit(): Promise<void> {
|
||||
@ -49,7 +49,7 @@ export class AuthComponent implements OnInit {
|
||||
|
||||
async login(): Promise<void> {
|
||||
try {
|
||||
const loginResult = await this.authService.login();
|
||||
const loginResult = await this.authService.login()
|
||||
if (loginResult) {
|
||||
this.router.navigate(['/home']);
|
||||
}
|
||||
|
@ -29,11 +29,9 @@ export class TokensComponent implements OnInit {
|
||||
|
||||
async ngOnInit(): Promise<void> {
|
||||
await this.tokenService.init();
|
||||
this.tokenService.load.subscribe(async (status: boolean) => {
|
||||
if (status) {
|
||||
this.tokenService.onload = async (status: boolean): Promise<void> => {
|
||||
await this.tokenService.getTokens();
|
||||
}
|
||||
});
|
||||
};
|
||||
this.tokenService.tokensSubject.subscribe((tokens) => {
|
||||
this.loggingService.sendInfoLevelMessage(tokens);
|
||||
this.dataSource = new MatTableDataSource(tokens);
|
||||
|
@ -6,7 +6,7 @@ export const environment = {
|
||||
logLevel: NgxLoggerLevel.ERROR,
|
||||
serverLogLevel: NgxLoggerLevel.OFF,
|
||||
loggingUrl: 'http://localhost:8000',
|
||||
cicMetaUrl: 'https://meta-auth.dev.grassrootseconomics.net',
|
||||
cicMetaUrl: 'https://meta.dev.grassrootseconomics.net',
|
||||
publicKeysUrl: 'https://dev.grassrootseconomics.net/.well-known/publickeys/',
|
||||
cicCacheUrl: 'https://cache.dev.grassrootseconomics.net',
|
||||
web3Provider: 'wss://bloxberg-ws.dev.grassrootseconomics.net',
|
||||
|
Loading…
Reference in New Issue
Block a user