Bug fix.
- Refactor HttpGetter function. - Remove redundant asset files. - Fix BlockSync dependency issues.
This commit is contained in:
@@ -1,19 +1,18 @@
|
||||
function HttpGetter(): void {}
|
||||
|
||||
HttpGetter.prototype.get = filename => new Promise((whohoo, doh) => {
|
||||
const xhr = new XMLHttpRequest();
|
||||
xhr.addEventListener('load', (e) => {
|
||||
if (xhr.status === 200) {
|
||||
whohoo(xhr.responseText);
|
||||
return;
|
||||
}
|
||||
doh('failed with status ' + xhr.status + ': ' + xhr.statusText);
|
||||
});
|
||||
xhr.open('GET', filename);
|
||||
xhr.send();
|
||||
});
|
||||
|
||||
class HttpGetter {
|
||||
async get(filename: string): Promise<any> {
|
||||
const xhr = new XMLHttpRequest();
|
||||
xhr.addEventListener('load', (e) => {
|
||||
if (xhr.status === 200) {
|
||||
console.log(xhr.responseText);
|
||||
return;
|
||||
}
|
||||
console.log('failed with status ' + xhr.status + ': ' + xhr.statusText);
|
||||
});
|
||||
xhr.open('GET', filename);
|
||||
xhr.send();
|
||||
}
|
||||
}
|
||||
export {
|
||||
HttpGetter
|
||||
};
|
||||
|
||||
@@ -7,4 +7,3 @@ export * from '@app/_helpers/array-sum';
|
||||
export * from '@app/_helpers/accountIndex';
|
||||
export * from '@app/_helpers/http-getter';
|
||||
export * from '@app/_helpers/pgp-signer';
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { KeyStore } from 'cic-client-meta';
|
||||
const openpgp = require('openpgp');
|
||||
const keyring = new openpgp.Keyring();
|
||||
import { KeyStore } from '@src/assets/js/cic-meta/auth';
|
||||
|
||||
interface MutableKeyStore extends KeyStore {
|
||||
loadKeyring(): Promise<void>;
|
||||
|
||||
@@ -1,33 +1,32 @@
|
||||
import {Injectable} from '@angular/core';
|
||||
import {Settings} from '@app/_models';
|
||||
import Web3 from 'web3';
|
||||
import {abi, Registry, TransactionHelper} from 'cic-client';
|
||||
import {CICRegistry, TransactionHelper} from 'cic-client';
|
||||
import {first} from 'rxjs/operators';
|
||||
import {TransactionService} from '@app/_services/transaction.service';
|
||||
import {environment} from '@src/environments/environment';
|
||||
const cic = require('@src/assets/js/block-sync/cic-client.web');
|
||||
import {HttpGetter} from '@app/_helpers';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class BlockSyncService {
|
||||
trustedDeclaratorAddress: string = '0x5567139c7a1C2977A391f51D8cA45B1D6700f5F6';
|
||||
readyStateTarget: number = 2;
|
||||
readyState: number = 0;
|
||||
fileGetter = new HttpGetter();
|
||||
|
||||
constructor(private transactionService: TransactionService) { }
|
||||
|
||||
blockSync(): any {
|
||||
const settings = new Settings(this.scan);
|
||||
const provider = environment.web3Provider;
|
||||
const readyStateElements = {
|
||||
token: 1,
|
||||
network: 2,
|
||||
};
|
||||
const readyStateElements = { network: 2 };
|
||||
settings.w3.provider = provider;
|
||||
settings.w3.engine = new Web3(provider);
|
||||
settings.registry = new Registry(settings.w3.engine, environment.registryAddress, abi);
|
||||
settings.txHelper = new TransactionHelper(settings.registry);
|
||||
settings.registry = new CICRegistry(settings.w3.engine, environment.registryAddress, this.fileGetter,
|
||||
['../../assets/js/block-sync/data']);
|
||||
settings.registry.declaratorHelper.addTrust(environment.trustedDeclaratorAddress);
|
||||
settings.txHelper = new TransactionHelper(settings.w3.engine, settings.registry);
|
||||
|
||||
settings.txHelper.ontransfer = async (transaction: any): Promise<void> => {
|
||||
window.dispatchEvent(this.newTransferEvent(transaction));
|
||||
@@ -35,12 +34,8 @@ export class BlockSyncService {
|
||||
settings.txHelper.onconversion = async (transaction: any): Promise<any> => {
|
||||
window.dispatchEvent(this.newConversionEvent(transaction));
|
||||
};
|
||||
settings.registry.ontokensload = (tokenCount: number): void => {
|
||||
// console.debug('loaded tokens', tokenCount);
|
||||
this.readyStateProcessor(settings, readyStateElements.token);
|
||||
};
|
||||
settings.registry.onregistryload = (addressReturned: number): void => {
|
||||
// console.debug('loaded network contracts', addressReturned);
|
||||
settings.registry.onload = (addressReturned: number): void => {
|
||||
console.log('loaded network contracts', addressReturned);
|
||||
this.readyStateProcessor(settings, readyStateElements.network);
|
||||
};
|
||||
|
||||
@@ -79,7 +74,7 @@ export class BlockSyncService {
|
||||
}
|
||||
|
||||
async scan(settings, lo, hi, bloomBlockBytes, bloomBlocktxBytes, bloomRounds): Promise<void> {
|
||||
const w = new Worker('./../assets/js/worker.js');
|
||||
const w = new Worker('./../assets/js/block-sync/ondemand.js');
|
||||
w.onmessage = (m) => {
|
||||
settings.txHelper.processReceipt(m.data);
|
||||
};
|
||||
@@ -114,14 +109,4 @@ export class BlockSyncService {
|
||||
settings.scanFilter(settings, data.low, data.high, bOne, bTwo, data.filter_rounds);
|
||||
});
|
||||
}
|
||||
|
||||
headWorker(): void {
|
||||
const wHeadSync = new Worker('./../assets/js/block-sync/head.js', {type: 'module'});
|
||||
wHeadSync.onmessage = (m) => {
|
||||
console.log(m.data);
|
||||
};
|
||||
wHeadSync.postMessage({
|
||||
w3_provider: environment.web3Provider,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,9 +3,8 @@ import {BehaviorSubject, Observable} from 'rxjs';
|
||||
import {HttpClient, HttpHeaders, HttpParams} from '@angular/common/http';
|
||||
import {environment} from '@src/environments/environment';
|
||||
import {first} from 'rxjs/operators';
|
||||
import {ArgPair, Envelope, Syncable} from '@src/assets/js/cic-meta/sync.js';
|
||||
import {MutableKeyStore, MutablePgpKeyStore, PGPSigner, Signer} from '@app/_helpers';
|
||||
import {User} from 'cic-client-meta';
|
||||
import {ArgPair, Envelope, Syncable, User} from 'cic-client-meta';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
@@ -64,8 +63,7 @@ export class UserService {
|
||||
await this.updateMeta(syncableAccount, accountKey, this.headers);
|
||||
}, async error => {
|
||||
console.error('There is an error!', error);
|
||||
const refName = accountKey + ':cic.person';
|
||||
const syncableAccount: Syncable = new Syncable(refName, accountDetails);
|
||||
const syncableAccount: Syncable = new Syncable(accountKey, accountDetails);
|
||||
await this.updateMeta(syncableAccount, accountKey, this.headers);
|
||||
});
|
||||
return accountKey;
|
||||
|
||||
@@ -26,7 +26,6 @@ export class AppComponent implements OnInit {
|
||||
}
|
||||
|
||||
ngOnInit(): void {
|
||||
this.blockSyncService.headWorker();
|
||||
this.mediaQuery.addListener(this.onResize);
|
||||
this.onResize(this.mediaQuery);
|
||||
this.queryAccountsIndex(20).then();
|
||||
|
||||
@@ -8,8 +8,7 @@ import {ActivatedRoute, Params, Router} from '@angular/router';
|
||||
import {first} from 'rxjs/operators';
|
||||
import {FormBuilder, FormGroup, Validators} from '@angular/forms';
|
||||
import {CustomErrorStateMatcher} from '@app/_helpers';
|
||||
import {User} from 'cic-client-meta';
|
||||
import {Envelope} from '@src/assets/js/cic-meta/sync';
|
||||
import {Envelope, User} from 'cic-client-meta';
|
||||
|
||||
@Component({
|
||||
selector: 'app-account-details',
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import {AfterViewInit, Component, OnInit, ViewChild} from '@angular/core';
|
||||
import {BlockSyncService, TransactionService} from '@app/_services';
|
||||
import {TransactionService} from '@app/_services';
|
||||
import {MatTableDataSource} from '@angular/material/table';
|
||||
import {SelectionModel} from '@angular/cdk/collections';
|
||||
import {MatPaginator} from '@angular/material/paginator';
|
||||
@@ -25,10 +25,7 @@ export class TransactionsComponent implements OnInit, AfterViewInit {
|
||||
|
||||
constructor(
|
||||
private transactionService: TransactionService,
|
||||
private blockSyncService: BlockSyncService
|
||||
) {
|
||||
this.blockSyncService.blockSync();
|
||||
}
|
||||
) { }
|
||||
|
||||
ngOnInit(): void {
|
||||
this.transactionService.transactionsSubject.subscribe(transactions => {
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -20,7 +20,6 @@ function sync_by_filter_block(block, count, buf, bloom_blocktx, result_callback)
|
||||
}
|
||||
|
||||
function sync_by_filter(lo, hi, bloom_block, bloom_blocktx, tx_count_getter, result_callback) {
|
||||
|
||||
for (let i = lo; i <= hi; i++) {
|
||||
let a = new ArrayBuffer(8);
|
||||
let w = new DataView(a);
|
||||
@@ -33,7 +32,7 @@ function sync_by_filter(lo, hi, bloom_block, bloom_blocktx, tx_count_getter, res
|
||||
sync_by_filter_block(i, n, a, bloom_blocktx, result_callback);
|
||||
}).catch((e) => {
|
||||
console.error('get count fail', e);
|
||||
});;
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1,199 +0,0 @@
|
||||
import * as pgp from 'openpgp';
|
||||
import * as crypto from 'crypto';
|
||||
|
||||
interface Signable {
|
||||
digest(): string;
|
||||
}
|
||||
|
||||
type KeyGetter = () => any;
|
||||
|
||||
type Signature = {
|
||||
engine: string
|
||||
algo: string
|
||||
data: string
|
||||
digest: string
|
||||
};
|
||||
|
||||
interface Signer {
|
||||
prepare(Signable): boolean;
|
||||
|
||||
onsign(Signature): void;
|
||||
|
||||
onverify(bool): void;
|
||||
|
||||
sign(digest: string): void;
|
||||
|
||||
verify(digest: string, signature: Signature): void;
|
||||
|
||||
fingerprint(): string;
|
||||
}
|
||||
|
||||
|
||||
interface Authoritative {
|
||||
}
|
||||
|
||||
interface KeyStore {
|
||||
getPrivateKey: KeyGetter;
|
||||
getFingerprint: () => string;
|
||||
getTrustedKeys: () => Array<any>;
|
||||
getTrustedActiveKeys: () => Array<any>;
|
||||
getEncryptKeys: () => Array<any>;
|
||||
}
|
||||
|
||||
class PGPKeyStore implements KeyStore {
|
||||
|
||||
fingerprint: string;
|
||||
pk: any;
|
||||
|
||||
pubk = {
|
||||
active: [],
|
||||
trusted: [],
|
||||
encrypt: [],
|
||||
};
|
||||
loads = 0x00;
|
||||
loadsTarget = 0x0f;
|
||||
onload: (k: KeyStore) => void;
|
||||
|
||||
constructor(passphrase: string, pkArmor: string, pubkActiveArmor: string, pubkTrustedArmor: string, pubkEncryptArmor: string,
|
||||
onload = (ks: KeyStore) => {
|
||||
}) {
|
||||
this._readKey(pkArmor, undefined, 1, passphrase);
|
||||
this._readKey(pubkActiveArmor, 'active', 2);
|
||||
this._readKey(pubkTrustedArmor, 'trusted', 4);
|
||||
this._readKey(pubkEncryptArmor, 'encrypt', 8);
|
||||
this.onload = onload;
|
||||
}
|
||||
|
||||
private _readKey(a: string, x: any, n: number, pass?: string): void {
|
||||
pgp.key.readArmored(a).then((k) => {
|
||||
if (pass !== undefined) {
|
||||
this.pk = k.keys[0];
|
||||
this.pk.decrypt(pass).then(() => {
|
||||
this.fingerprint = this.pk.getFingerprint();
|
||||
console.log('private key (sign)', this.fingerprint);
|
||||
this._registerLoad(n);
|
||||
});
|
||||
} else {
|
||||
this.pubk[x] = k.keys;
|
||||
k.keys.forEach((pubk) => {
|
||||
console.log('public key (' + x + ')', pubk.getFingerprint());
|
||||
});
|
||||
this._registerLoad(n);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private _registerLoad(b: number): void {
|
||||
this.loads |= b;
|
||||
if (this.loads == this.loadsTarget) {
|
||||
this.onload(this);
|
||||
}
|
||||
}
|
||||
|
||||
public getTrustedKeys(): Array<any> {
|
||||
return this.pubk.trusted;
|
||||
}
|
||||
|
||||
public getTrustedActiveKeys(): Array<any> {
|
||||
return this.pubk.active;
|
||||
}
|
||||
|
||||
public getEncryptKeys(): Array<any> {
|
||||
return this.pubk.encrypt;
|
||||
}
|
||||
|
||||
public getPrivateKey(): any {
|
||||
return this.pk;
|
||||
}
|
||||
|
||||
public getFingerprint(): string {
|
||||
return this.fingerprint;
|
||||
}
|
||||
}
|
||||
|
||||
class PGPSigner implements Signer {
|
||||
|
||||
engine = 'pgp';
|
||||
algo = 'sha256';
|
||||
dgst: string;
|
||||
signature: Signature;
|
||||
keyStore: KeyStore;
|
||||
onsign: (Signature) => void;
|
||||
onverify: (bool) => void;
|
||||
|
||||
constructor(keyStore: KeyStore) {
|
||||
this.keyStore = keyStore;
|
||||
this.onsign = (string) => {
|
||||
};
|
||||
this.onverify = (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 {
|
||||
pgp.signature.readArmored(signature.data).then((s) => {
|
||||
const opts = {
|
||||
message: pgp.cleartext.fromText(digest),
|
||||
publicKeys: this.keyStore.getTrustedKeys(),
|
||||
signature: s,
|
||||
};
|
||||
pgp.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;
|
||||
}
|
||||
}
|
||||
console.error('checked ' + i + ' signature(s) but none valid');
|
||||
this.onverify(false);
|
||||
});
|
||||
}).catch((e) => {
|
||||
console.error(e);
|
||||
this.onverify(false);
|
||||
});
|
||||
}
|
||||
|
||||
public sign(digest: string): void {
|
||||
const m = pgp.cleartext.fromText(digest);
|
||||
const pk = this.keyStore.getPrivateKey();
|
||||
const opts = {
|
||||
message: m,
|
||||
privateKeys: [pk],
|
||||
detached: true,
|
||||
};
|
||||
pgp.sign(opts).then((s) => {
|
||||
this.signature = {
|
||||
engine: this.engine,
|
||||
algo: this.algo,
|
||||
data: s.signature,
|
||||
// TODO: fix for browser later
|
||||
digest: digest,
|
||||
};
|
||||
this.onsign(this.signature);
|
||||
}).catch((e) => {
|
||||
console.error(e);
|
||||
this.onsign(undefined);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
export {
|
||||
Signature,
|
||||
Authoritative,
|
||||
Signer,
|
||||
KeyGetter,
|
||||
Signable,
|
||||
KeyStore,
|
||||
PGPSigner,
|
||||
PGPKeyStore,
|
||||
};
|
||||
@@ -1,24 +0,0 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.networkSpec = exports.cryptoSpec = exports.engineSpec = void 0;
|
||||
var ENGINE_NAME = 'automerge';
|
||||
var ENGINE_VERSION = '0.14.1';
|
||||
var NETWORK_NAME = 'cic';
|
||||
var NETWORK_VERSION = '1';
|
||||
var CRYPTO_NAME = 'pgp';
|
||||
var CRYPTO_VERSION = '2';
|
||||
var engineSpec = {
|
||||
name: ENGINE_NAME,
|
||||
version: ENGINE_VERSION,
|
||||
};
|
||||
exports.engineSpec = engineSpec;
|
||||
var cryptoSpec = {
|
||||
name: CRYPTO_NAME,
|
||||
version: CRYPTO_VERSION,
|
||||
};
|
||||
exports.cryptoSpec = cryptoSpec;
|
||||
var networkSpec = {
|
||||
name: NETWORK_NAME,
|
||||
version: NETWORK_VERSION,
|
||||
};
|
||||
exports.networkSpec = networkSpec;
|
||||
@@ -1,246 +0,0 @@
|
||||
"use strict";
|
||||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
||||
}) : (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
o[k2] = m[k];
|
||||
}));
|
||||
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
||||
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
||||
}) : function(o, v) {
|
||||
o["default"] = v;
|
||||
});
|
||||
var __importStar = (this && this.__importStar) || function (mod) {
|
||||
if (mod && mod.__esModule) return mod;
|
||||
var result = {};
|
||||
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
||||
__setModuleDefault(result, mod);
|
||||
return result;
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.Envelope = exports.ArgPair = exports.Syncable = void 0;
|
||||
var Automerge = __importStar(require("automerge"));
|
||||
var constants_1 = require("./constants");
|
||||
var fullSpec = {
|
||||
name: 'cic',
|
||||
version: '1',
|
||||
ext: {
|
||||
network: constants_1.cryptoSpec,
|
||||
engine: constants_1.engineSpec,
|
||||
},
|
||||
};
|
||||
var Envelope = /** @class */ (function () {
|
||||
function Envelope(payload) {
|
||||
this.o = fullSpec;
|
||||
this.set(payload);
|
||||
}
|
||||
Envelope.prototype.set = function (payload) {
|
||||
this.o['payload'] = payload;
|
||||
};
|
||||
Envelope.prototype.get = function () {
|
||||
return this.o['payload'];
|
||||
};
|
||||
Envelope.prototype.toJSON = function () {
|
||||
return JSON.stringify(this.o);
|
||||
};
|
||||
Envelope.fromJSON = function (s) {
|
||||
var e = new Envelope(undefined);
|
||||
e.o = JSON.parse(s);
|
||||
return e;
|
||||
};
|
||||
Envelope.prototype.unwrap = function () {
|
||||
return Syncable.fromJSON(this.o['payload']);
|
||||
};
|
||||
return Envelope;
|
||||
}());
|
||||
exports.Envelope = Envelope;
|
||||
var ArgPair = /** @class */ (function () {
|
||||
function ArgPair(k, v) {
|
||||
this.k = k;
|
||||
this.v = v;
|
||||
}
|
||||
return ArgPair;
|
||||
}());
|
||||
exports.ArgPair = ArgPair;
|
||||
var SignablePart = /** @class */ (function () {
|
||||
function SignablePart(s) {
|
||||
this.s = s;
|
||||
}
|
||||
SignablePart.prototype.digest = function () {
|
||||
return this.s;
|
||||
};
|
||||
return SignablePart;
|
||||
}());
|
||||
function orderDict(src) {
|
||||
var dst;
|
||||
if (Array.isArray(src)) {
|
||||
dst = [];
|
||||
src.forEach(function (v) {
|
||||
if (typeof (v) == 'object') {
|
||||
v = orderDict(v);
|
||||
}
|
||||
dst.push(v);
|
||||
});
|
||||
}
|
||||
else {
|
||||
dst = {};
|
||||
Object.keys(src).sort().forEach(function (k) {
|
||||
var v = src[k];
|
||||
if (typeof (v) == 'object') {
|
||||
v = orderDict(v);
|
||||
}
|
||||
dst[k] = v;
|
||||
});
|
||||
}
|
||||
return dst;
|
||||
}
|
||||
var Syncable = /** @class */ (function () {
|
||||
// TODO: Move data to sub-object so timestamp, id, signature don't collide
|
||||
function Syncable(id, v) {
|
||||
this.id = id;
|
||||
var o = {
|
||||
'id': id,
|
||||
'timestamp': Math.floor(Date.now() / 1000),
|
||||
'data': v,
|
||||
};
|
||||
//this.m = Automerge.from(v)
|
||||
this.m = Automerge.from(o);
|
||||
}
|
||||
Syncable.prototype.setSigner = function (signer) {
|
||||
var _this = this;
|
||||
this.signer = signer;
|
||||
this.signer.onsign = function (s) {
|
||||
_this.wrap(s);
|
||||
};
|
||||
};
|
||||
// TODO: To keep integrity, the non-link key/value pairs for each step also need to be hashed
|
||||
Syncable.prototype.digest = function () {
|
||||
var links = [];
|
||||
Automerge.getAllChanges(this.m).forEach(function (ch) {
|
||||
var op = ch['ops'];
|
||||
ch['ops'].forEach(function (op) {
|
||||
if (op['action'] == 'link') {
|
||||
//console.log('op link', op);
|
||||
links.push([op['obj'], op['value']]);
|
||||
}
|
||||
});
|
||||
});
|
||||
//return JSON.stringify(links);
|
||||
var j = JSON.stringify(links);
|
||||
return Buffer.from(j).toString('base64');
|
||||
};
|
||||
Syncable.prototype.wrap = function (s) {
|
||||
this.m = Automerge.change(this.m, 'sign', function (doc) {
|
||||
doc['signature'] = s;
|
||||
});
|
||||
this.e = new Envelope(this.toJSON());
|
||||
if (this.onwrap !== undefined) {
|
||||
this.onwrap(this.e);
|
||||
}
|
||||
};
|
||||
// private _verifyLoop(i:number, history:Array<any>, signable:Signable, result:boolean) {
|
||||
// if (!result) {
|
||||
// this.onauthenticate(false);
|
||||
// return;
|
||||
// } else if (history.length == 0) {
|
||||
// this.onauthenticate(true);
|
||||
// return;
|
||||
// }
|
||||
// const h = history.shift()
|
||||
// if (i % 2 == 0) {
|
||||
// i++;
|
||||
// signable = {
|
||||
// digest: () => {
|
||||
// return Automerge.save(h.snapshot)
|
||||
// },
|
||||
// };
|
||||
// this._verifyLoop(i, history, signable, true);
|
||||
// } else {
|
||||
// i++;
|
||||
// const signature = h.snapshot['signature'];
|
||||
// console.debug('signature', signature, signable.digest());
|
||||
// this.signer.onverify = (v) => {
|
||||
// this._verifyLoop(i, history, signable, v)
|
||||
// }
|
||||
// this.signer.verify(signable, signature);
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// // TODO: This should replay the graph and check signatures on each step
|
||||
// public _authenticate(full:boolean=false) {
|
||||
// let h = Automerge.getHistory(this.m);
|
||||
// h.forEach((m) => {
|
||||
// //console.debug(m.snapshot);
|
||||
// });
|
||||
// const signable = {
|
||||
// digest: () => { return '' },
|
||||
// }
|
||||
// if (!full) {
|
||||
// h = h.slice(h.length-2);
|
||||
// }
|
||||
// this._verifyLoop(0, h, signable, true);
|
||||
// }
|
||||
Syncable.prototype.authenticate = function (full) {
|
||||
var _this = this;
|
||||
if (full === void 0) { full = false; }
|
||||
if (full) {
|
||||
console.warn('only doing shallow authentication for now, sorry');
|
||||
}
|
||||
//console.log('authenticating', signable.digest());
|
||||
//console.log('signature', this.m.signature);
|
||||
this.signer.onverify = function (v) {
|
||||
//this._verifyLoop(i, history, signable, v)
|
||||
_this.onauthenticate(v);
|
||||
};
|
||||
this.signer.verify(this.m.signature.digest, this.m.signature);
|
||||
};
|
||||
Syncable.prototype.sign = function () {
|
||||
//this.signer.prepare(this);
|
||||
this.signer.sign(this.digest());
|
||||
};
|
||||
Syncable.prototype.update = function (changes, changesDescription) {
|
||||
this.m = Automerge.change(this.m, changesDescription, function (m) {
|
||||
changes.forEach(function (c) {
|
||||
var path = c.k.split('.');
|
||||
var target = m['data'];
|
||||
while (path.length > 1) {
|
||||
var part = path.shift();
|
||||
target = target[part];
|
||||
}
|
||||
target[path[0]] = c.v;
|
||||
});
|
||||
m['timestamp'] = Math.floor(Date.now() / 1000);
|
||||
});
|
||||
};
|
||||
Syncable.prototype.replace = function (o, changesDescription) {
|
||||
this.m = Automerge.change(this.m, changesDescription, function (m) {
|
||||
Object.keys(o).forEach(function (k) {
|
||||
m['data'][k] = o[k];
|
||||
});
|
||||
Object.keys(m).forEach(function (k) {
|
||||
if (o[k] == undefined) {
|
||||
delete m['data'][k];
|
||||
}
|
||||
});
|
||||
m['timestamp'] = Math.floor(Date.now() / 1000);
|
||||
});
|
||||
};
|
||||
Syncable.prototype.merge = function (s) {
|
||||
this.m = Automerge.merge(s.m, this.m);
|
||||
};
|
||||
Syncable.prototype.toJSON = function () {
|
||||
var s = Automerge.save(this.m);
|
||||
var o = JSON.parse(s);
|
||||
var oo = orderDict(o);
|
||||
return JSON.stringify(oo);
|
||||
};
|
||||
Syncable.fromJSON = function (s) {
|
||||
var doc = Automerge.load(s);
|
||||
var y = new Syncable(doc['id'], {});
|
||||
y.m = doc;
|
||||
return y;
|
||||
};
|
||||
return Syncable;
|
||||
}());
|
||||
exports.Syncable = Syncable;
|
||||
1
src/assets/js/eth_account_index/index.d.ts
vendored
1
src/assets/js/eth_account_index/index.d.ts
vendored
@@ -1 +0,0 @@
|
||||
export { AccountRegistry } from './registry';
|
||||
@@ -1,5 +0,0 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.AccountRegistry = void 0;
|
||||
var registry_1 = require("./registry");
|
||||
Object.defineProperty(exports, "AccountRegistry", { enumerable: true, get: function () { return registry_1.AccountRegistry; } });
|
||||
10
src/assets/js/eth_account_index/registry.d.ts
vendored
10
src/assets/js/eth_account_index/registry.d.ts
vendored
@@ -1,10 +0,0 @@
|
||||
declare class AccountRegistry {
|
||||
contract: any;
|
||||
signerAccount: any;
|
||||
constructor(w3: any, abi: object, address: string, signerAddress?: string);
|
||||
count(): Promise<number>;
|
||||
have(address: string): Promise<boolean>;
|
||||
last(n: number): Promise<Array<string>>;
|
||||
add(address: string): Promise<boolean>;
|
||||
}
|
||||
export { AccountRegistry, };
|
||||
@@ -1,109 +0,0 @@
|
||||
"use strict";
|
||||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
||||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
||||
return new (P || (P = Promise))(function (resolve, reject) {
|
||||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
||||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
||||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
||||
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
||||
});
|
||||
};
|
||||
var __generator = (this && this.__generator) || function (thisArg, body) {
|
||||
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
||||
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
||||
function verb(n) { return function (v) { return step([n, v]); }; }
|
||||
function step(op) {
|
||||
if (f) throw new TypeError("Generator is already executing.");
|
||||
while (_) try {
|
||||
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
||||
if (y = 0, t) op = [op[0] & 2, t.value];
|
||||
switch (op[0]) {
|
||||
case 0: case 1: t = op; break;
|
||||
case 4: _.label++; return { value: op[1], done: false };
|
||||
case 5: _.label++; y = op[1]; op = [0]; continue;
|
||||
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
||||
default:
|
||||
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
||||
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
||||
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
||||
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
||||
if (t[2]) _.ops.pop();
|
||||
_.trys.pop(); continue;
|
||||
}
|
||||
op = body.call(thisArg, _);
|
||||
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
||||
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
||||
}
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.AccountRegistry = void 0;
|
||||
var AccountRegistry = /** @class */ (function () {
|
||||
function AccountRegistry(w3, abi, address, signerAddress) {
|
||||
this.contract = new w3.eth.Contract(abi, address);
|
||||
if (signerAddress) {
|
||||
this.signerAccount = signerAddress;
|
||||
}
|
||||
else {
|
||||
this.signerAccount = w3.eth.accounts[0];
|
||||
}
|
||||
}
|
||||
AccountRegistry.prototype.count = function () {
|
||||
return __awaiter(this, void 0, void 0, function () {
|
||||
return __generator(this, function (_a) {
|
||||
return [2 /*return*/, this.contract.methods.count().call()];
|
||||
});
|
||||
});
|
||||
};
|
||||
AccountRegistry.prototype.have = function (address) {
|
||||
return __awaiter(this, void 0, void 0, function () {
|
||||
return __generator(this, function (_a) {
|
||||
switch (_a.label) {
|
||||
case 0: return [4 /*yield*/, this.contract.methods.accountsIndex(address).call()];
|
||||
case 1: return [2 /*return*/, (_a.sent()) != 0];
|
||||
}
|
||||
});
|
||||
});
|
||||
};
|
||||
AccountRegistry.prototype.last = function (n) {
|
||||
return __awaiter(this, void 0, void 0, function () {
|
||||
var c, lo, accounts, i, a;
|
||||
return __generator(this, function (_a) {
|
||||
switch (_a.label) {
|
||||
case 0: return [4 /*yield*/, this.count()];
|
||||
case 1:
|
||||
c = _a.sent();
|
||||
lo = c - n - 1;
|
||||
if (lo < 0) {
|
||||
lo = 0;
|
||||
}
|
||||
accounts = [];
|
||||
i = c - 1;
|
||||
_a.label = 2;
|
||||
case 2:
|
||||
if (!(i > lo)) return [3 /*break*/, 5];
|
||||
return [4 /*yield*/, this.contract.methods.accounts(i).call()];
|
||||
case 3:
|
||||
a = _a.sent();
|
||||
accounts.push(a);
|
||||
_a.label = 4;
|
||||
case 4:
|
||||
i--;
|
||||
return [3 /*break*/, 2];
|
||||
case 5: return [2 /*return*/, accounts];
|
||||
}
|
||||
});
|
||||
});
|
||||
};
|
||||
AccountRegistry.prototype.add = function (address) {
|
||||
return __awaiter(this, void 0, void 0, function () {
|
||||
return __generator(this, function (_a) {
|
||||
switch (_a.label) {
|
||||
case 0: return [4 /*yield*/, this.contract.methods.add(address).send({ from: this.signerAccount })];
|
||||
case 1: return [2 /*return*/, _a.sent()];
|
||||
}
|
||||
});
|
||||
});
|
||||
};
|
||||
return AccountRegistry;
|
||||
}());
|
||||
exports.AccountRegistry = AccountRegistry;
|
||||
@@ -1,165 +0,0 @@
|
||||
let crypto = undefined;
|
||||
|
||||
(function() {
|
||||
if (typeof module !== 'undefined' && typeof exports !== 'undefined') {
|
||||
const nodeCrypto = require('crypto');
|
||||
function hashWrapper(nodeCrypto, alg) {
|
||||
this.alg = alg;
|
||||
this.crypto = nodeCrypto.createHash(alg);
|
||||
}
|
||||
hashWrapper.prototype.update = function(d) {
|
||||
this.crypto.update(d);
|
||||
}
|
||||
hashWrapper.prototype.digest = async function() {
|
||||
const z = this.crypto.digest(this.data);
|
||||
return new Uint8Array(z);
|
||||
}
|
||||
|
||||
function cryptoWrapper(nodeCrypto) {
|
||||
this.crypto = nodeCrypto
|
||||
}
|
||||
cryptoWrapper.prototype.createHash = function(alg) {
|
||||
return new hashWrapper(this.crypto, alg);
|
||||
}
|
||||
module.exports = {
|
||||
Bloom: Bloom,
|
||||
fromBytes: fromBytes,
|
||||
};
|
||||
crypto = new cryptoWrapper(nodeCrypto);
|
||||
} else {
|
||||
function hashWrapper(webCrypto, alg) {
|
||||
this.alg = alg;
|
||||
this.crypto = webCrypto;
|
||||
this.data = undefined;
|
||||
}
|
||||
hashWrapper.prototype.update = function(d) {
|
||||
if (this.data != undefined) {
|
||||
throw "cannot append";
|
||||
}
|
||||
this.data = d;
|
||||
}
|
||||
hashWrapper.prototype.digest = async function() {
|
||||
const z = await this.crypto.subtle.digest('SHA-256', this.data);
|
||||
return new Uint8Array(z);
|
||||
}
|
||||
|
||||
function cryptoWrapper(webCrypto) {
|
||||
this.crypto = webCrypto
|
||||
}
|
||||
cryptoWrapper.prototype.createHash = function(alg) {
|
||||
return new hashWrapper(this.crypto, alg);
|
||||
}
|
||||
|
||||
crypto = new cryptoWrapper(window.crypto);
|
||||
window.Bloom = Bloom;
|
||||
window.bloomFromBytes = fromBytes;
|
||||
}
|
||||
})()
|
||||
|
||||
|
||||
// block numbers 6000000
|
||||
// false positive probability 2%
|
||||
//
|
||||
// m = ceil((n * log(p)) / log(1 / pow(2, log(2))));
|
||||
// m = ceil((6000000 * log(0.1)) / log(1 / pow(2, log(2))))
|
||||
// = 3917675
|
||||
|
||||
// Creates a new bloom object.
|
||||
// \param size of filter in bits, aligned to byte boundary
|
||||
// \param number of rounds to hash
|
||||
// \param hasher function, which must take two Uint8Array parameters 'data' and 'salt'. If not sef, hashBloomDefault will be used.
|
||||
function Bloom(bits, rounds, hasher) {
|
||||
this.bits = bits;
|
||||
this.bytes = parseInt(bits / 8, 10);
|
||||
this.rounds = rounds;
|
||||
if (this.hasher === undefined) {
|
||||
this.hasher = hashBloomDefault;
|
||||
}
|
||||
if (this.bytes * 8 != this.bits) {
|
||||
console.error('number of bits must be on byte boundary');
|
||||
return false;
|
||||
} else {
|
||||
this.filter = new Uint8Array(this.bytes);
|
||||
}
|
||||
}
|
||||
|
||||
// add entry to bloom filter
|
||||
// \param value to add
|
||||
Bloom.prototype.add = async function(v) {
|
||||
let a = new ArrayBuffer(v.byteLength + 4);
|
||||
let iw = new DataView(a);
|
||||
for (let i = 0; i < v.byteLength; i++) {
|
||||
iw.setUint8(i, v[i]);
|
||||
}
|
||||
//console.debug(iw, v);
|
||||
for (var i = 0; i < this.rounds; i++) {
|
||||
iw.setInt32(v.byteLength, i);
|
||||
let result = await this.hasher(iw);
|
||||
let resultHex = Array.prototype.map.call(new Uint8Array(result), x => ('00' + x.toString(16)).slice(-2)).join('');
|
||||
let resultInt = parseInt(BigInt('0x'+resultHex) % BigInt(this.bits), 10);
|
||||
let bytepos = parseInt(resultInt / 8, 10);
|
||||
let bitpos = parseInt(resultInt, 10) % 8;
|
||||
this.filter[bytepos] |= 1 << bitpos;
|
||||
//console.log("setpos ", bytepos, bitpos);
|
||||
}
|
||||
};
|
||||
|
||||
// checks if the block number has been added to the bloom filter
|
||||
// \param value to check for
|
||||
// \return false if not found in filter
|
||||
Bloom.prototype.check = async function(v) {
|
||||
let a = new ArrayBuffer(v.byteLength + 4);
|
||||
let iw = new DataView(a);
|
||||
for (let i = 0; i < v.byteLength; i++) {
|
||||
iw.setUint8(i, v[i]);
|
||||
}
|
||||
for (let j = 0; j < this.filter.byteLength; j++) {
|
||||
if (v[3] == 20 && this.filter[j] > 0) {
|
||||
// console.log('filter ', j, this.filter[j]);
|
||||
}
|
||||
}
|
||||
for (let i = 0; i < this.rounds; i++) {
|
||||
iw.setInt32(v.byteLength, i);
|
||||
let result = await this.hasher(iw);
|
||||
//console.log('result', result);
|
||||
let resultHex = Array.prototype.map.call(new Uint8Array(result), x => ('00' + x.toString(16)).slice(-2)).join('');
|
||||
let resultInt = parseInt(BigInt('0x'+resultHex) % BigInt(this.bits), 10);
|
||||
let bytepos = parseInt(resultInt / 8, 10);
|
||||
//console.log("setpos ", v, bytepos, resultInt % 8);
|
||||
if (this.filter[bytepos] === undefined) {
|
||||
// console.error('byte pos ' + bytepos + ' is undefined (filter length ' + this.filter.byteLength + ')');
|
||||
return false;
|
||||
} else {
|
||||
let test = 1 << (0xff & (resultInt % 8));
|
||||
if ((this.filter[bytepos] & test) == 0) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
};
|
||||
|
||||
// return the verbatim filter
|
||||
// \return Uint8Array filter
|
||||
Bloom.prototype.bytes = function() {
|
||||
return this.filter;
|
||||
};
|
||||
|
||||
|
||||
// Default hashing function used in Bloom.add() - sha256
|
||||
// \param data to insert in filter
|
||||
// \param salt, typically a sequence number
|
||||
// \return Uint8Array digest
|
||||
async function hashBloomDefault(data, salt) {
|
||||
const h = crypto.createHash('sha256');
|
||||
h.update(data);
|
||||
const z = await h.digest();
|
||||
return Uint8Array.from(z);
|
||||
}
|
||||
|
||||
function fromBytes(bytes, rounds, hasher) {
|
||||
const bits = bytes.byteLength * 8;
|
||||
let b = new Bloom(bits, rounds, hasher);
|
||||
b.filter = bytes;
|
||||
return b;
|
||||
}
|
||||
2
src/assets/js/openpgp.min.js
vendored
2
src/assets/js/openpgp.min.js
vendored
File diff suppressed because one or more lines are too long
@@ -1,30 +0,0 @@
|
||||
function sync_by_filter_block(block, count, buf, bloom_blocktx, result_callback) {
|
||||
for (let j = 0; j < count; j++) {
|
||||
let w = new DataView(buf);
|
||||
w.setInt32(4, j);
|
||||
const r = new Uint8Array(buf);
|
||||
bloom_blocktx.check(r).then(function(ok) {
|
||||
if (ok) {
|
||||
// console.debug('match in block' + block + ' tx ' + j);
|
||||
result_callback(block, j);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function sync_by_filter(caller, lo, hi, bloom_block, bloom_blocktx, tx_count_getter, result_callback) {
|
||||
for (let i = lo; i <= hi; i++) {
|
||||
let a = new ArrayBuffer(8);
|
||||
let w = new DataView(a);
|
||||
w.setInt32(0, i);
|
||||
const r = new Uint8Array(a.slice(0, 4));
|
||||
bloom_block.check(r).then(function(ok) {
|
||||
if (ok) {
|
||||
// console.debug('match in block ' + i);
|
||||
tx_count_getter(i).then(function(n) {
|
||||
sync_by_filter_block(i, n, a, bloom_blocktx, result_callback);
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
1
src/assets/js/web3.min.js
vendored
1
src/assets/js/web3.min.js
vendored
File diff suppressed because one or more lines are too long
@@ -1,63 +0,0 @@
|
||||
let window = self;
|
||||
|
||||
importScripts('moolb.js');
|
||||
importScripts('sync.js');
|
||||
importScripts('web3.min.js');
|
||||
|
||||
let s = undefined;
|
||||
|
||||
// TODO: as worker has its own scope we don't need the object
|
||||
function Driver(messager, provider, lo, filters, syncer) {
|
||||
this.w3 = new Web3(provider);
|
||||
this.lo = lo;
|
||||
this.hi = lo;
|
||||
this.filters = filters;
|
||||
this.syncer = syncer;
|
||||
this.messager = messager;
|
||||
}
|
||||
|
||||
Driver.prototype.start = function(hi) {
|
||||
let self = this;
|
||||
if (hi !== undefined) {
|
||||
self.sync(hi);
|
||||
return;
|
||||
}
|
||||
s.w3.eth.getBlockNumber().then(function(n) {
|
||||
self.sync(n);
|
||||
});
|
||||
};
|
||||
|
||||
Driver.prototype.sync = function(n) {
|
||||
this.hi = n;
|
||||
this.syncer(this, this.lo, this.hi, this.filters[0], this.filters[1], this.getCount, this.process);
|
||||
};
|
||||
|
||||
|
||||
Driver.prototype.process = function(b, t) {
|
||||
s.w3.eth.getTransactionFromBlock(b, t).then((t) => {
|
||||
s.w3.eth.getTransactionReceipt(t.hash).then((r) => {
|
||||
this.postMessage(r);
|
||||
});
|
||||
}).catch(function(e) {
|
||||
//this.postMessage(['failed getTransactionFromBlock(' + b + ', ' + t + ')']);
|
||||
console.error('failed getTransactionFromBlock(' + b + ', ' + t + ')');
|
||||
});
|
||||
}
|
||||
|
||||
Driver.prototype.getCount = async function (b) {
|
||||
const n = s.w3.eth.getBlockTransactionCount(b);
|
||||
return n;
|
||||
};
|
||||
|
||||
onmessage = function(o) {
|
||||
const filters = [
|
||||
bloomFromBytes(o.data.filters[0], o.data.filter_rounds),
|
||||
bloomFromBytes(o.data.filters[1], o.data.filter_rounds),
|
||||
];
|
||||
s = new Driver(postMessage, o.data.w3_provider, o.data.lo, filters, sync_by_filter);
|
||||
let hi = undefined;
|
||||
if (o.data.hi > 0) {
|
||||
hi = o.data.hi;
|
||||
}
|
||||
s.start(hi);
|
||||
};
|
||||
@@ -9,5 +9,6 @@ export const environment = {
|
||||
cicUssdUrl: 'http://localhost:63315',
|
||||
cicEthUrl: 'http://localhost:63314',
|
||||
contractAddress: '0xd0097a901AF4ac2E63A5b6E86be8Ad91f10b05d7',
|
||||
registryAddress: '0xf374d7B507767101a4bf3bA2a6B99AC737A44f6d'
|
||||
registryAddress: '0xf374d7B507767101a4bf3bA2a6B99AC737A44f6d',
|
||||
trustedDeclaratorAddress: '0xEb3907eCad74a0013c259D5874AE7f22DcBcC95C'
|
||||
};
|
||||
|
||||
@@ -13,7 +13,8 @@ export const environment = {
|
||||
cicUssdUrl: 'http://localhost:63315',
|
||||
cicEthUrl: 'http://localhost:63314',
|
||||
contractAddress: '0xd0097a901AF4ac2E63A5b6E86be8Ad91f10b05d7',
|
||||
registryAddress: '0xf374d7B507767101a4bf3bA2a6B99AC737A44f6d'
|
||||
registryAddress: '0xf374d7B507767101a4bf3bA2a6B99AC737A44f6d',
|
||||
trustedDeclaratorAddress: '0xEb3907eCad74a0013c259D5874AE7f22DcBcC95C'
|
||||
};
|
||||
|
||||
/*
|
||||
|
||||
@@ -18,6 +18,5 @@
|
||||
<script src="https://code.jquery.com/jquery-3.5.1.slim.min.js" integrity="sha384-DfXdz2htPH0lsSSs5nCTpuj/zy4C+OGpamoFVy38MVBnE+IbbVYUew+OrCXaRkfj" crossorigin="anonymous"></script>
|
||||
<script async src="https://cdn.jsdelivr.net/npm/popper.js@1.16.1/dist/umd/popper.min.js" integrity="sha384-9/reFTGAW83EW2RDu2S0VKaIzap3H66lZH81PoYlFhbGU+6BZp6G7niu735Sk7lN" crossorigin="anonymous"></script>
|
||||
<script async src="https://cdn.jsdelivr.net/npm/bootstrap@4.5.3/dist/js/bootstrap.min.js" integrity="sha384-w1Q4orYjBQndcko6MimVbzY0tgp4pWB4lZ7lr30WKz0vr/aWKhXdBNmNb5D92v7s" crossorigin="anonymous"></script>
|
||||
<script async src="assets/js/openpgp.min.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
Reference in New Issue
Block a user