Refactor dependencies to use cicnet packages.

This commit is contained in:
Spencer Ofwiti 2021-05-10 10:10:37 +03:00
parent 6ed07b4beb
commit 2be3d3bb73
17 changed files with 20297 additions and 1897 deletions

View File

@ -31,14 +31,11 @@
"styles": [
"./node_modules/@angular/material/prebuilt-themes/indigo-pink.css",
"src/styles.scss",
"node_modules/datatables.net-dt/css/jquery.dataTables.css",
"node_modules/bootstrap/dist/css/bootstrap.min.css"
],
"scripts": [
"node_modules/jquery/dist/jquery.js",
"node_modules/datatables.net/js/jquery.dataTables.js",
"node_modules/bootstrap/dist/js/bootstrap.js",
"node_modules/block-syncer/dist/worker_ondemand.js"
"node_modules/bootstrap/dist/js/bootstrap.js"
]
},
"configurations": {

21856
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -25,29 +25,19 @@
"@angular/platform-browser": "~10.2.0",
"@angular/platform-browser-dynamic": "~10.2.0",
"@angular/router": "~10.2.0",
"@cicnet/cic-client-meta": "^0.0.10",
"@cicnet/crdt-meta": "^0.0.10",
"@cicnet/schemas-data-validator": "^1.0.0-alpha.3",
"@popperjs/core": "^2.5.4",
"angular-datatables": "^9.0.2",
"block-syncer": "^0.2.4",
"bootstrap": "^4.5.3",
"chart.js": "^2.9.4",
"cic-client": "0.1.4",
"cic-client-meta": "0.0.7-alpha.6",
"cic-schemas-data-validator": "^1.0.0-alpha.3",
"datatables.net": "^1.10.22",
"datatables.net-dt": "^1.10.22",
"ethers": "^5.0.31",
"jquery": "^3.5.1",
"mocha": "^8.2.1",
"moolb": "^0.1.0",
"ng2-charts": "^2.4.2",
"ngx-logger": "^4.2.1",
"openpgp": "^4.10.10",
"popper.js": "^1.16.1",
"rxjs": "~6.6.0",
"sha3": "^2.1.4",
"tslib": "^2.0.0",
"vcard-parser": "^1.0.0",
"vcards-js": "^2.10.0",
"web3": "^1.3.0",
"zone.js": "~0.10.2"
},
@ -55,7 +45,6 @@
"@angular-devkit/build-angular": "~0.1002.0",
"@angular/cli": "~10.2.0",
"@angular/compiler-cli": "~10.2.0",
"@types/datatables.net": "^1.10.19",
"@types/jasmine": "~3.5.0",
"@types/jasminewd2": "~2.0.3",
"@types/jquery": "^3.5.4",

View File

@ -29,7 +29,7 @@ export const environment = {
function setConfigs(configs): void {
writeFile(targetPath, configs, err => {
if (err) {
throw console.error(err);
console.error(err);
} else {
console.log(colors.green(`Wrote variables to '${targetPath}`));
}

View File

@ -1,4 +1,4 @@
import { validatePerson, validateVcard } from 'cic-schemas-data-validator';
import { validatePerson, validateVcard } from '@cicnet/schemas-data-validator';
async function personValidation(person: any): Promise<void> {
const personValidationErrors: any = await validatePerson(person);

View File

@ -1,2 +0,0 @@
export * from '@app/_pgp/pgp-key-store';
export * from '@app/_pgp/pgp-signer';

View File

@ -1,7 +0,0 @@
import { MutablePgpKeyStore } from '@app/_pgp/pgp-key-store';
describe('PgpKeyStore', () => {
it('should create an instance', () => {
expect(new MutablePgpKeyStore()).toBeTruthy();
});
});

View File

@ -1,165 +0,0 @@
import { KeyStore } from 'cic-client-meta';
// TODO should we put this on the mutable key store object
import * as openpgp from 'openpgp';
const keyring = new openpgp.Keyring();
interface MutableKeyStore extends KeyStore {
loadKeyring(): void;
importKeyPair(publicKey: any, privateKey: any): Promise<void>;
importPublicKey(publicKey: any): void;
importPrivateKey(privateKey: any): Promise<void>;
getPublicKeys(): Array<any>;
getTrustedKeys(): Array<any>;
getTrustedActiveKeys(): Array<any>;
getEncryptKeys(): Array<any>;
getPrivateKeys(): Array<any>;
getPrivateKey(): any;
isValidKey(key: any): Promise<boolean>;
isEncryptedPrivateKey(privateKey: any): Promise<boolean>;
getFingerprint(): string;
getKeyId(key: any): string;
getPrivateKeyId(): string;
getKeysForId(keyId: string): Array<any>;
getPublicKeyForId(keyId: string): any;
getPrivateKeyForId(keyId: string): any;
getPublicKeyForSubkeyId(subkeyId: string): any;
getPublicKeysForAddress(address: string): Array<any>;
removeKeysForId(keyId: string): Array<any>;
removePublicKeyForId(keyId: string): any;
removePublicKey(publicKey: any): any;
clearKeysInKeyring(): void;
sign(plainText: string): Promise<any>;
}
class MutablePgpKeyStore implements MutableKeyStore{
async loadKeyring(): Promise<void> {
await keyring.load();
await keyring.store();
}
async importKeyPair(publicKey: any, privateKey: any): Promise<void> {
await keyring.publicKeys.importKey(publicKey);
await keyring.privateKeys.importKey(privateKey);
}
importPublicKey(publicKey: any): void {
keyring.publicKeys.importKey(publicKey);
}
async importPrivateKey(privateKey: any): Promise<void> {
await keyring.privateKeys.importKey(privateKey);
}
getPublicKeys(): Array<any> {
return keyring.publicKeys.keys;
}
getTrustedKeys(): Array<any> {
return keyring.publicKeys.keys;
}
getTrustedActiveKeys(): Array<any> {
return keyring.publicKeys.keys;
}
getEncryptKeys(): Array<any> {
return [];
}
getPrivateKeys(): Array<any> {
return keyring.privateKeys.keys;
}
getPrivateKey(): any {
return keyring.privateKeys && keyring.privateKeys.keys[0];
}
async isValidKey(key): Promise<boolean> {
// There is supposed to be an openpgp.readKey() method but I can't find it?
const _key = await openpgp.key.readArmored(key);
return !_key.err;
}
async isEncryptedPrivateKey(privateKey: any): Promise<boolean> {
const imported = await openpgp.key.readArmored(privateKey);
for (const key of imported.keys) {
if (key.isDecrypted()) {
return false;
}
}
return true;
}
getFingerprint(): string {
// TODO Handle multiple keys
return keyring.privateKeys && keyring.privateKeys.keys[0] && keyring.privateKeys.keys[0].keyPacket &&
keyring.privateKeys.keys[0].keyPacket.fingerprint;
}
getKeyId(key: any): string {
return key.getKeyId().toHex();
}
getPrivateKeyId(): string {
// TODO is there a library that comes with angular for doing this?
return keyring.privateKeys && keyring.privateKeys.keys[0] && keyring.privateKeys.keys[0].getKeyId().toHex();
}
getKeysForId(keyId: string): Array<any> {
return keyring.getKeysForId(keyId);
}
getPublicKeyForId(keyId): any {
return keyring.publicKeys.getForId(keyId);
}
getPrivateKeyForId(keyId): any {
return keyring.privateKeys.getForId(keyId);
}
getPublicKeyForSubkeyId(subkeyId): any {
return keyring.publicKeys.getForId(subkeyId, true);
}
getPublicKeysForAddress(address): Array<any> {
return keyring.publicKeys.getForAddress(address);
}
removeKeysForId(keyId): Array<any> {
return keyring.removeKeysForId(keyId);
}
removePublicKeyForId(keyId): any {
return keyring.publicKeys.removeForId(keyId);
}
removePublicKey(publicKey: any): any {
const keyId = publicKey.getKeyId().toHex();
return keyring.publicKeys.removeForId(keyId);
}
clearKeysInKeyring(): void {
keyring.clear();
}
async sign(plainText): Promise<any> {
const privateKey = this.getPrivateKey();
if (!privateKey.isDecrypted()) {
const password = window.prompt('password');
await privateKey.decrypt(password);
}
const opts = {
message: openpgp.message.fromText(plainText),
privateKeys: [privateKey],
detached: true,
};
const signatureObject = await openpgp.sign(opts);
return signatureObject.signature;
}
}
export {
MutablePgpKeyStore,
MutableKeyStore
};

View File

@ -1,9 +0,0 @@
import { PGPSigner } from '@app/_pgp/pgp-signer';
import {MutableKeyStore, MutablePgpKeyStore} from '@app/_pgp/pgp-key-store';
const keystore: MutableKeyStore = new MutablePgpKeyStore();
describe('PgpSigner', () => {
it('should create an instance', () => {
expect(new PGPSigner(keystore)).toBeTruthy();
});
});

View File

@ -1,110 +0,0 @@
import {MutableKeyStore} from '@app/_pgp/pgp-key-store';
import {LoggingService} from '@app/_services/logging.service';
const openpgp = require('openpgp');
interface Signable {
digest(): string;
}
type Signature = {
engine: string
algo: string
data: string
digest: string;
};
interface Signer {
onsign(signature: Signature): void;
onverify(flag: boolean): void;
fingerprint(): string;
prepare(material: Signable): boolean;
verify(digest: string, signature: Signature): void;
sign(digest: string): Promise<void>;
}
class PGPSigner implements Signer {
engine = 'pgp';
algo = 'sha256';
dgst: string;
signature: Signature;
keyStore: MutableKeyStore;
onsign: (signature: Signature) => void;
onverify: (flag: boolean) => void;
loggingService: LoggingService;
constructor(keyStore: MutableKeyStore) {
this.keyStore = keyStore;
this.onsign = (signature: Signature) => {};
this.onverify = (flag: boolean) => {};
}
public fingerprint(): string {
return this.keyStore.getFingerprint();
}
public prepare(material: Signable): boolean {
this.dgst = material.digest();
return true;
}
public verify(digest: string, signature: Signature): void {
openpgp.signature.readArmored(signature.data).then((sig) => {
const opts = {
message: openpgp.cleartext.fromText(digest),
publicKeys: this.keyStore.getTrustedKeys(),
signature: sig,
};
openpgp.verify(opts).then((v) => {
let i = 0;
for (i = 0; i < v.signatures.length; i++) {
const s = v.signatures[i];
if (s.valid) {
this.onverify(s);
return;
}
}
this.loggingService.sendErrorLevelMessage(`Checked ${i} signature(s) but none valid`, this, {error: '404 Not found!'});
this.onverify(false);
});
}).catch((e) => {
this.loggingService.sendErrorLevelMessage(e.message, this, {error: e});
this.onverify(false);
});
}
public async sign(digest: string): Promise<void> {
const m = openpgp.cleartext.fromText(digest);
const pk = this.keyStore.getPrivateKey();
if (!pk.isDecrypted()) {
const password = window.prompt('password');
await pk.decrypt(password);
}
const opts = {
message: m,
privateKeys: [pk],
detached: true,
};
openpgp.sign(opts).then((s) => {
this.signature = {
engine: this.engine,
algo: this.algo,
data: s.signature,
// TODO: fix for browser later
digest,
};
this.onsign(this.signature);
}).catch((e) => {
this.loggingService.sendErrorLevelMessage(e.message, this, {error: e});
this.onsign(undefined);
});
}
}
export {
Signable,
Signature,
Signer,
PGPSigner
};

View File

@ -3,7 +3,7 @@ import {hobaParseChallengeHeader} from '@src/assets/js/hoba.js';
import {signChallenge} from '@src/assets/js/hoba-pgp.js';
import {environment} from '@src/environments/environment';
import {LoggingService} from '@app/_services/logging.service';
import {MutableKeyStore, MutablePgpKeyStore} from '@app/_pgp';
import {MutableKeyStore, MutablePgpKeyStore} from '@cicnet/crdt-meta';
import {ErrorDialogService} from '@app/_services/error-dialog.service';
import {HttpClient} from '@angular/common/http';
import {HttpError} from '@app/_helpers/global-error-handler';

View File

@ -2,7 +2,8 @@ import { Injectable } from '@angular/core';
import {first} from 'rxjs/operators';
import {BehaviorSubject, Observable} from 'rxjs';
import {environment} from '@src/environments/environment';
import {Envelope, User} from 'cic-client-meta';
import {User} from '@cicnet/cic-client-meta';
import {Envelope} from '@cicnet/crdt-meta';
import {UserService} from '@app/_services/user.service';
import { Keccak } from 'sha3';
import { utils } from 'ethers';

View File

@ -3,12 +3,12 @@ import {BehaviorSubject, Observable, Subject} from 'rxjs';
import {HttpClient, HttpHeaders, HttpParams} from '@angular/common/http';
import {environment} from '@src/environments/environment';
import {first} from 'rxjs/operators';
import {ArgPair, Envelope, Phone, Syncable, User} from 'cic-client-meta';
import {Phone, User} from '@cicnet/cic-client-meta';
import {ArgPair, Envelope, Syncable, MutableKeyStore, PGPSigner, Signer} from '@cicnet/crdt-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 'cic-client';
import {AuthService} from '@app/_services/auth.service';

View File

@ -9,14 +9,13 @@ import {
GlobalErrorHandler,
MockBackendProvider,
} from '@app/_helpers';
import {DataTablesModule} from 'angular-datatables';
import {SharedModule} from '@app/shared/shared.module';
import {MatTableModule} from '@angular/material/table';
import {AuthGuard} from '@app/_guards';
import {LoggerModule} from 'ngx-logger';
import {environment} from '@src/environments/environment';
import {ErrorInterceptor, HttpConfigInterceptor, LoggingInterceptor} from '@app/_interceptors';
import {MutablePgpKeyStore} from '@app/_pgp';
import {MutablePgpKeyStore} from '@cicnet/crdt-meta';
@NgModule({
declarations: [
@ -27,7 +26,6 @@ import {MutablePgpKeyStore} from '@app/_pgp';
AppRoutingModule,
BrowserAnimationsModule,
HttpClientModule,
DataTablesModule,
SharedModule,
MatTableModule,
LoggerModule.forRoot({

View File

@ -5,7 +5,6 @@ import { AccountsRoutingModule } from '@pages/accounts/accounts-routing.module';
import { AccountsComponent } from '@pages/accounts/accounts.component';
import {SharedModule} from '@app/shared/shared.module';
import { AccountDetailsComponent } from '@pages/accounts/account-details/account-details.component';
import {DataTablesModule} from 'angular-datatables';
import { CreateAccountComponent } from '@pages/accounts/create-account/create-account.component';
import {MatTableModule} from '@angular/material/table';
import {MatSortModule} from '@angular/material/sort';
@ -37,7 +36,6 @@ import {MatSnackBarModule} from '@angular/material/snack-bar';
CommonModule,
AccountsRoutingModule,
SharedModule,
DataTablesModule,
MatTableModule,
MatSortModule,
MatCheckboxModule,

View File

@ -4,7 +4,6 @@ import { CommonModule } from '@angular/common';
import { PagesRoutingModule } from '@pages/pages-routing.module';
import { PagesComponent } from '@pages/pages.component';
import {SharedModule} from '@app/shared/shared.module';
import {ChartsModule} from 'ng2-charts';
import {MatButtonModule} from '@angular/material/button';
import {MatFormFieldModule} from '@angular/material/form-field';
import {MatSelectModule} from '@angular/material/select';
@ -18,7 +17,6 @@ import {MatCardModule} from '@angular/material/card';
CommonModule,
PagesRoutingModule,
SharedModule,
ChartsModule,
MatButtonModule,
MatFormFieldModule,
MatSelectModule,

View File

@ -4,7 +4,6 @@ import { CommonModule } from '@angular/common';
import { TransactionsRoutingModule } from '@pages/transactions/transactions-routing.module';
import { TransactionsComponent } from '@pages/transactions/transactions.component';
import { TransactionDetailsComponent } from '@pages/transactions/transaction-details/transaction-details.component';
import {DataTablesModule} from 'angular-datatables';
import {SharedModule} from '@app/shared/shared.module';
import {MatTableModule} from '@angular/material/table';
import {MatCheckboxModule} from '@angular/material/checkbox';
@ -28,7 +27,6 @@ import {MatSnackBarModule} from '@angular/material/snack-bar';
imports: [
CommonModule,
TransactionsRoutingModule,
DataTablesModule,
SharedModule,
MatTableModule,
MatCheckboxModule,