Cic meta builds
This commit is contained in:
parent
1eeff6dc83
commit
77077fe044
@ -4,6 +4,7 @@ include:
|
||||
- local: 'apps/cic-eth/.gitlab-ci.yml'
|
||||
- local: 'apps/cic-ussd/.gitlab-ci.yml'
|
||||
- local: 'apps/cic-notify/.gitlab-ci.yml'
|
||||
- local: 'apps/cic-meta/.gitlab-ci.yml'
|
||||
|
||||
stages:
|
||||
- build
|
||||
|
@ -1 +0,0 @@
|
||||
Subproject commit 76e8b80965ccedbc59790248050fa598a747f85a
|
14
apps/cic-meta/.config/database.ini
Normal file
14
apps/cic-meta/.config/database.ini
Normal file
@ -0,0 +1,14 @@
|
||||
[database]
|
||||
#name = cic-meta
|
||||
#engine = postgres
|
||||
#user = postgres
|
||||
#password = password
|
||||
#host = localhost
|
||||
#port = 5432
|
||||
name = /tmp/cicmeta.sqlite
|
||||
engine = sqlite
|
||||
user =
|
||||
password =
|
||||
host =
|
||||
port =
|
||||
schema_sql_path = server.sqlite.sql
|
7
apps/cic-meta/.config/pgp.ini
Normal file
7
apps/cic-meta/.config/pgp.ini
Normal file
@ -0,0 +1,7 @@
|
||||
[pgp]
|
||||
exports_dir = pgp
|
||||
privatekey_file = privatekeys.asc
|
||||
passphrase = merman
|
||||
publickey_trusted_file = publickeys.asc
|
||||
publickey_active_file = publickeys.asc
|
||||
publickey_encrypt_file = publickeys.asc
|
3
apps/cic-meta/.config/server.ini
Normal file
3
apps/cic-meta/.config/server.ini
Normal file
@ -0,0 +1,3 @@
|
||||
[server]
|
||||
address = 0.0.0.0
|
||||
port = 7777
|
5
apps/cic-meta/.gitignore
vendored
Normal file
5
apps/cic-meta/.gitignore
vendored
Normal file
@ -0,0 +1,5 @@
|
||||
node_modules
|
||||
dist
|
||||
dist-web
|
||||
scratch
|
||||
tests
|
24
apps/cic-meta/.gitlab-ci.yml
Normal file
24
apps/cic-meta/.gitlab-ci.yml
Normal file
@ -0,0 +1,24 @@
|
||||
|
||||
.cic_meta_variables:
|
||||
variables:
|
||||
APP_NAME: cic-meta
|
||||
DOCKERFILE_PATH: $APP_NAME/docker/Dockerfile
|
||||
|
||||
.this_changes_target:
|
||||
rules:
|
||||
- changes:
|
||||
- $CONTEXT/$APP_NAME/*
|
||||
|
||||
build-mr-cic-meta:
|
||||
extends:
|
||||
- .this_changes_target
|
||||
- .py_build_merge_request
|
||||
- .cic_meta_variables
|
||||
|
||||
build-push-cic-meta:
|
||||
extends:
|
||||
- .this_changes_target
|
||||
- .py_build_push
|
||||
- .cic_meta_variables
|
||||
|
||||
|
10
apps/cic-meta/CHANGELOG
Normal file
10
apps/cic-meta/CHANGELOG
Normal file
@ -0,0 +1,10 @@
|
||||
* 0.0.6
|
||||
- Add server build
|
||||
* 0.0.5
|
||||
- Set build on install
|
||||
* 0.0.4
|
||||
- Change phone key generator to arbitrary value input
|
||||
* 0.0.3
|
||||
- Add asset key generator
|
||||
- Add crypto polyfill (node uses native crypto, web uses webcrypto)
|
||||
- Add phone asset
|
28
apps/cic-meta/docker/Dockerfile
Normal file
28
apps/cic-meta/docker/Dockerfile
Normal file
@ -0,0 +1,28 @@
|
||||
FROM node:15.3.0-alpine3.10
|
||||
|
||||
WORKDIR /tmp/src/cic-meta
|
||||
|
||||
COPY cic-meta/package.json \
|
||||
cic-meta/package-lock.json \
|
||||
./
|
||||
|
||||
RUN npm install
|
||||
|
||||
COPY cic-meta/src/ src/
|
||||
COPY cic-meta/tests/ tests/
|
||||
COPY cic-meta/scripts/ scripts/
|
||||
#COPY docker/*.sh /root/
|
||||
|
||||
RUN alias tsc=node_modules/typescript/bin/tsc
|
||||
|
||||
COPY cic-meta/.config/ /usr/local/etc/cic-meta/
|
||||
COPY cic-meta/scripts/server/server.postgres.sql /usr/local/share/cic-meta/sql/server.sql
|
||||
|
||||
COPY cic-meta/docker/db.sh ./db.sh
|
||||
RUN chmod 755 ./db.sh
|
||||
|
||||
RUN alias ts-node=/tmp/src/cic-meta/node_modules/ts-node/dist/bin.js
|
||||
ENTRYPOINT [ "./node_modules/ts-node/dist/bin.js", "./scripts/server/server.ts" ]
|
||||
|
||||
# COPY cic-meta/docker/start_server.sh ./start_server.sh
|
||||
# RUN chmod 755 ./start_server.sh
|
3
apps/cic-meta/docker/db.sh
Normal file
3
apps/cic-meta/docker/db.sh
Normal file
@ -0,0 +1,3 @@
|
||||
#!/bin/bash
|
||||
|
||||
PGPASSWORD=$DATABASE_PASSWORD psql -U $DATABASE_USER -h $DATABASE_HOST -p $DATABASE_PORT -d $DATABASE_NAME /usr/local/share/cic-meta/sql/server.sql
|
3
apps/cic-meta/docker/start_server.sh
Normal file
3
apps/cic-meta/docker/start_server.sh
Normal file
@ -0,0 +1,3 @@
|
||||
sh ./db.sh
|
||||
|
||||
/usr/local/bin/node /usr/local/bin/cic-meta-server $@
|
98
apps/cic-meta/example/client.py
Normal file
98
apps/cic-meta/example/client.py
Normal file
@ -0,0 +1,98 @@
|
||||
import sys
|
||||
import os
|
||||
import json
|
||||
import logging
|
||||
from urllib.request import Request, urlopen
|
||||
|
||||
import gnupg
|
||||
|
||||
logging.basicConfig(level=logging.DEBUG)
|
||||
logg = logging.getLogger()
|
||||
|
||||
host = os.environ.get('CIC_META_URL', 'http://localhost:63380')
|
||||
|
||||
if len(sys.argv) < 2:
|
||||
sys.stderr.write('Usage: {} <path-to-gpg-private-key>\n'.format(sys.argv[0]))
|
||||
sys.exit(1)
|
||||
|
||||
|
||||
# Import PGP key used to sign the data submission
|
||||
gpg = gnupg.GPG(gnupghome='/tmp/.gpg')
|
||||
f = open(sys.argv[1], 'r')
|
||||
key_data = f.read()
|
||||
f.close()
|
||||
|
||||
gpg.import_keys(key_data)
|
||||
gpgk = gpg.list_keys()
|
||||
algo = gpgk[0]['algo']
|
||||
logg.info('using signing key {} algo {}'.format(gpgk[0]['keyid'], algo))
|
||||
|
||||
|
||||
def main():
|
||||
|
||||
# Random key to associate with value
|
||||
# (typically this is some deterministic identifier like sha256(<ethaddress>:cic-person)
|
||||
k = os.urandom(32).hex()
|
||||
url = os.path.join(host, k)
|
||||
|
||||
# Headers required for server-assisted merge operations
|
||||
headers = {
|
||||
'X-CIC-AUTOMERGE': 'server',
|
||||
'Content-Type': 'application/json',
|
||||
}
|
||||
|
||||
# Data to merge
|
||||
data_dict = {
|
||||
'foo': 'bar',
|
||||
'xyzzy': 42,
|
||||
}
|
||||
|
||||
# Send request to server to get initial automerge object and signing material
|
||||
# Server will reply with current state of object merged with ours, but (obviously)
|
||||
# still without a signature.
|
||||
data = json.dumps(data_dict).encode('utf-8')
|
||||
req = Request(url, headers=headers, data=data, method='POST')
|
||||
rs = urlopen(req)
|
||||
logg.info('get sign material response status: {}'.format(rs.status))
|
||||
if rs.status != 200:
|
||||
raise RuntimeError('request failed: {}'.format(rs.reason))
|
||||
|
||||
|
||||
# Sign the provided digest
|
||||
data = rs.read()
|
||||
e = json.loads(data)
|
||||
sig = gpg.sign(e['digest'], passphrase='ge', keyid=gpgk[0]['keyid'])
|
||||
|
||||
# Format data for the content storage request
|
||||
data = {
|
||||
'm': data.decode('utf-8'),
|
||||
's': {
|
||||
'engine': 'pgp',
|
||||
'algo': algo,
|
||||
'data': str(sig),
|
||||
'digest': e['digest'],
|
||||
},
|
||||
}
|
||||
|
||||
# Send storage request to server
|
||||
data = json.dumps(data).encode('utf-8')
|
||||
req = Request(url, headers=headers, data=data, method='PUT')
|
||||
rs = urlopen(req)
|
||||
|
||||
logg.info('signed content submissionstatus: {}'.format(rs.status))
|
||||
if rs.status != 200:
|
||||
raise RuntimeError('request failed: {}'.format(rs.reason))
|
||||
|
||||
|
||||
# Get the latest stored version of the data (without the merge graph)
|
||||
req = Request(url, method='GET')
|
||||
rs = urlopen(req)
|
||||
logg.info('get latest data status: {}'.format(rs.status))
|
||||
if rs.status != 200:
|
||||
raise RuntimeError('request failed: {}'.format(rs.reason))
|
||||
|
||||
print(rs.read().decode('utf-8'))
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
3309
apps/cic-meta/package-lock.json
generated
Normal file
3309
apps/cic-meta/package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
41
apps/cic-meta/package.json
Normal file
41
apps/cic-meta/package.json
Normal file
@ -0,0 +1,41 @@
|
||||
{
|
||||
"name": "cic-client-meta",
|
||||
"version": "0.0.6",
|
||||
"description": "Signed CRDT metadata graphs for the CIC network",
|
||||
"main": "dist/index.js",
|
||||
"types": "dist/index.d.ts",
|
||||
"scripts": {
|
||||
"test": "mocha -r node_modules/node-localstorage/register -r ts-node/register tests/*.ts",
|
||||
"build": "node_modules/typescript/bin/tsc -d --outDir dist",
|
||||
"build-server": "tsc -d --outDir dist-server scripts/server/*.ts",
|
||||
"pack": "node_modules/typescript/bin/tsc -d --outDir dist && webpack",
|
||||
"clean": "rm -rf dist"
|
||||
},
|
||||
"bin": {
|
||||
"cic-meta-server": "./dist-server/scripts/server/server.js"
|
||||
},
|
||||
"dependencies": {
|
||||
"@ethereumjs/tx": "^3.0.0-beta.1",
|
||||
"automerge": "^0.14.1",
|
||||
"ethereumjs-wallet": "^1.0.1",
|
||||
"ini": "^1.3.5",
|
||||
"openpgp": "^4.10.8",
|
||||
"pg": "^8.4.2",
|
||||
"sqlite3": "^5.0.0",
|
||||
"yargs": "^16.1.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/mocha": "^8.0.3",
|
||||
"mocha": "^8.2.0",
|
||||
"node-localstorage": "^2.1.6",
|
||||
"ts-node": "^9.0.0",
|
||||
"typescript": "^4.0.5",
|
||||
"webpack": "^5.4.0",
|
||||
"webpack-cli": "^4.2.0"
|
||||
},
|
||||
"author": "Louis Holbrook <dev@holbrook.no>",
|
||||
"license": "GPL-3.0-or-later",
|
||||
"engines": {
|
||||
"node": "~15.3.0"
|
||||
}
|
||||
}
|
20
apps/cic-meta/scripts/dumpconfig.js
Normal file
20
apps/cic-meta/scripts/dumpconfig.js
Normal file
@ -0,0 +1,20 @@
|
||||
const config = require('./src/config');
|
||||
const fs = require('fs');
|
||||
|
||||
if (process.argv[2] === undefined) {
|
||||
process.stderr.write('Usage: node dumpConfig.js <configdir>\n');
|
||||
process.exit(1);
|
||||
}
|
||||
try {
|
||||
const stat = fs.statSync(process.argv[2]);
|
||||
if (!stat.isDirectory()) {
|
||||
throw 'not a directory';
|
||||
}
|
||||
} catch {
|
||||
process.stderr.write('Not a directory: ' + process.argv[2] + '\n');
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
const c = new config.Config(process.argv[2], process.env['CONFINI_ENV_PREFIX']);
|
||||
c.process();
|
||||
process.stdout.write(c.toString());
|
28
apps/cic-meta/scripts/server/args.ts
Normal file
28
apps/cic-meta/scripts/server/args.ts
Normal file
@ -0,0 +1,28 @@
|
||||
const args = require('yargs');
|
||||
|
||||
const standardArgs = args.option('config', {
|
||||
alias: 'c',
|
||||
type: 'string',
|
||||
description: 'absolute path to configuation files directory',
|
||||
|
||||
}).option('env-prefix', {
|
||||
type: 'string',
|
||||
description: 'prefix to add to environment variables to match configuration directives',
|
||||
|
||||
}).option('database-engine', {
|
||||
type: 'string',
|
||||
description: 'database engines to use',
|
||||
|
||||
}).option('address', {
|
||||
alias: 'a',
|
||||
type: 'string',
|
||||
description: 'ip address to bind server to',
|
||||
|
||||
}).option('server-address', {
|
||||
alias: 'p',
|
||||
type: 'number',
|
||||
description: 'port to bind server to',
|
||||
|
||||
});
|
||||
|
||||
export { standardArgs };
|
211
apps/cic-meta/scripts/server/handlers.ts
Normal file
211
apps/cic-meta/scripts/server/handlers.ts
Normal file
@ -0,0 +1,211 @@
|
||||
import * as Automerge from 'automerge';
|
||||
import * as pgp from 'openpgp';
|
||||
import * as pg from 'pg';
|
||||
|
||||
import { Envelope, Syncable } from '../../src/sync';
|
||||
|
||||
|
||||
function handleNoMergeGet(db, digest, keystore) {
|
||||
const sql = "SELECT content FROM store WHERE hash = '" + digest + "'";
|
||||
return new Promise<string|boolean>((whohoo, doh) => {
|
||||
db.query(sql, (e, rs) => {
|
||||
if (e !== null && e !== undefined) {
|
||||
doh(e);
|
||||
return;
|
||||
} else if (rs.rowCount == 0) {
|
||||
whohoo(false);
|
||||
return;
|
||||
}
|
||||
|
||||
const cipherText = rs.rows[0]['content'];
|
||||
pgp.message.readArmored(cipherText).then((m) => {
|
||||
const opts = {
|
||||
message: m,
|
||||
privateKeys: [keystore.getPrivateKey()],
|
||||
};
|
||||
pgp.decrypt(opts).then((plainText) => {
|
||||
const o = Syncable.fromJSON(plainText.data);
|
||||
const r = JSON.stringify(o.m['data']);
|
||||
whohoo(r);
|
||||
}).catch((e) => {
|
||||
console.error('decrypt', e);
|
||||
doh(e);
|
||||
});
|
||||
}).catch((e) => {
|
||||
console.error('mesage', e);
|
||||
doh(e);
|
||||
});
|
||||
})
|
||||
});
|
||||
}
|
||||
|
||||
// TODO: add input for change description
|
||||
function handleServerMergePost(data, db, digest, keystore, signer) {
|
||||
return new Promise<string>((whohoo, doh) => {
|
||||
const o = JSON.parse(data);
|
||||
const cipherText = handleClientMergeGet(db, digest, keystore).then(async (v) => {
|
||||
let e = undefined;
|
||||
let s = undefined;
|
||||
if (v === undefined) {
|
||||
s = new Syncable(digest, data);
|
||||
s.onwrap = (e) => {
|
||||
whohoo(e.toJSON());
|
||||
};
|
||||
digest = s.digest();
|
||||
s.wrap({
|
||||
digest: digest,
|
||||
});
|
||||
} else {
|
||||
e = Envelope.fromJSON(v);
|
||||
s = e.unwrap();
|
||||
s.replace(o, 'server merge');
|
||||
e.set(s);
|
||||
s.onwrap = (e) => {
|
||||
whohoo(e.toJSON());
|
||||
}
|
||||
digest = s.digest();
|
||||
s.wrap({
|
||||
digest: digest,
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
// TODO: this still needs to merge with the stored version
|
||||
function handleServerMergePut(data, db, digest, keystore, signer) {
|
||||
return new Promise<boolean>((whohoo, doh) => {
|
||||
const wrappedData = JSON.parse(data);
|
||||
|
||||
if (wrappedData.s === undefined) {
|
||||
doh('signature missing');
|
||||
return;
|
||||
}
|
||||
|
||||
const e = Envelope.fromJSON(wrappedData.m);
|
||||
let s = undefined;
|
||||
try {
|
||||
s = e.unwrap();
|
||||
} catch(e) {
|
||||
console.error(e)
|
||||
whohoo(undefined);
|
||||
}
|
||||
// TODO: we probably should expose method for replacing the signature, this is too intrusive
|
||||
s.m = Automerge.change(s.m, 'sign', (doc) => {
|
||||
doc['signature'] = wrappedData.s;
|
||||
});
|
||||
s.setSigner(signer);
|
||||
s.onauthenticate = (v) => {
|
||||
console.log('vvv', v);
|
||||
if (!v) {
|
||||
whohoo(undefined);
|
||||
return;
|
||||
}
|
||||
const opts = {
|
||||
message: pgp.message.fromText(s.toJSON()),
|
||||
publicKeys: keystore.getEncryptKeys(),
|
||||
};
|
||||
pgp.encrypt(opts).then((cipherText) => {
|
||||
const sql = "INSERT INTO store (owner_fingerprint, hash, content) VALUES ('" + signer.fingerprint() + "', '" + digest + "', '" + cipherText.data + "') ON CONFLICT (hash) DO UPDATE SET content = EXCLUDED.content;";
|
||||
db.query(sql, (e, rs) => {
|
||||
if (e !== null && e !== undefined) {
|
||||
doh(e);
|
||||
return;
|
||||
}
|
||||
whohoo(true);
|
||||
});
|
||||
});
|
||||
};
|
||||
s.authenticate(true)
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
function handleClientMergeGet(db, digest, keystore) {
|
||||
const sql = "SELECT content FROM store WHERE hash = '" + digest + "'";
|
||||
return new Promise<string>((whohoo, doh) => {
|
||||
db.query(sql, (e, rs) => {
|
||||
console.log('rs', e, rs);
|
||||
if (e !== null && e !== undefined) {
|
||||
doh(e);
|
||||
return;
|
||||
} else if (rs.rowCount == 0) { // TODO fix the postgres/sqlite method name issues, this will now break on postgres
|
||||
whohoo(undefined);
|
||||
return;
|
||||
}
|
||||
const cipherText = rs.rows[0]['content'];
|
||||
pgp.message.readArmored(cipherText).then((m) => {
|
||||
const opts = {
|
||||
message: m,
|
||||
privateKeys: [keystore.getPrivateKey()],
|
||||
};
|
||||
pgp.decrypt(opts).then((plainText) => {
|
||||
const o = Syncable.fromJSON(plainText.data);
|
||||
const e = new Envelope(o);
|
||||
whohoo(e.toJSON());
|
||||
}).catch((e) => {
|
||||
console.error('decrypt', e);
|
||||
doh(e);
|
||||
});
|
||||
}).catch((e) => {
|
||||
console.error('mesage', e);
|
||||
doh(e);
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
// TODO: this still needs to merge with the stored version
|
||||
function handleClientMergePut(data, db, digest, keystore, signer) {
|
||||
return new Promise<boolean>((whohoo, doh) => {
|
||||
let s = undefined;
|
||||
try {
|
||||
const e = Envelope.fromJSON(data);
|
||||
s = e.unwrap();
|
||||
} catch(e) {
|
||||
whohoo(false);
|
||||
console.error(e)
|
||||
return;
|
||||
}
|
||||
|
||||
s.setSigner(signer);
|
||||
s.onauthenticate = (v) => {
|
||||
if (!v) {
|
||||
whohoo(false);
|
||||
return;
|
||||
}
|
||||
|
||||
handleClientMergeGet(db, digest, keystore).then((v) => {
|
||||
if (v !== undefined) {
|
||||
const env = Envelope.fromJSON(v);
|
||||
s.merge(env.unwrap());
|
||||
}
|
||||
const opts = {
|
||||
message: pgp.message.fromText(s.toJSON()),
|
||||
publicKeys: keystore.getEncryptKeys(),
|
||||
};
|
||||
pgp.encrypt(opts).then((cipherText) => {
|
||||
const sql = "INSERT INTO store (owner_fingerprint, hash, content) VALUES ('" + signer.fingerprint() + "', '" + digest + "', '" + cipherText.data + "') ON CONFLICT (hash) DO UPDATE SET content = EXCLUDED.content;";
|
||||
db.query(sql, (e, rs) => {
|
||||
if (e !== null && e !== undefined) {
|
||||
doh(e);
|
||||
return;
|
||||
}
|
||||
whohoo(true);
|
||||
});
|
||||
}).catch((e) => {
|
||||
doh(e);
|
||||
});
|
||||
});
|
||||
};
|
||||
s.authenticate(true)
|
||||
});
|
||||
}
|
||||
|
||||
export {
|
||||
handleClientMergePut,
|
||||
handleClientMergeGet,
|
||||
handleServerMergePost,
|
||||
handleServerMergePut,
|
||||
handleNoMergeGet,
|
||||
};
|
8
apps/cic-meta/scripts/server/server.postgres.sql
Normal file
8
apps/cic-meta/scripts/server/server.postgres.sql
Normal file
@ -0,0 +1,8 @@
|
||||
create table if not exists store (
|
||||
id serial primary key not null,
|
||||
owner_fingerprint text not null,
|
||||
hash char(64) not null unique,
|
||||
content text not null
|
||||
);
|
||||
|
||||
create index if not exists idx_fp on store ((lower(owner_fingerprint)));
|
9
apps/cic-meta/scripts/server/server.sql
Normal file
9
apps/cic-meta/scripts/server/server.sql
Normal file
@ -0,0 +1,9 @@
|
||||
create table if not exists store (
|
||||
/*id serial primary key not null,*/
|
||||
id integer primary key autoincrement,
|
||||
owner_fingerprint text not null,
|
||||
hash char(64) not null unique,
|
||||
content text not null
|
||||
);
|
||||
|
||||
create index if not exists idx_fp on store ((lower(owner_fingerprint)));
|
9
apps/cic-meta/scripts/server/server.sqlite.sql
Normal file
9
apps/cic-meta/scripts/server/server.sqlite.sql
Normal file
@ -0,0 +1,9 @@
|
||||
create table if not exists store (
|
||||
/*id serial primary key not null,*/
|
||||
id integer primary key autoincrement,
|
||||
owner_fingerprint text not null,
|
||||
hash char(64) not null unique,
|
||||
content text not null
|
||||
);
|
||||
|
||||
create index if not exists idx_fp on store ((lower(owner_fingerprint)));
|
207
apps/cic-meta/scripts/server/server.ts
Executable file
207
apps/cic-meta/scripts/server/server.ts
Executable file
@ -0,0 +1,207 @@
|
||||
import * as http from 'http';
|
||||
import * as fs from 'fs';
|
||||
import * as path from 'path';
|
||||
import * as pgp from 'openpgp';
|
||||
|
||||
import * as handlers from './handlers';
|
||||
import { Envelope, Syncable } from '../../src/sync';
|
||||
import { PGPKeyStore, PGPSigner } from '../../src/auth';
|
||||
|
||||
import { standardArgs } from './args';
|
||||
import { Config } from '../../src/config';
|
||||
import { SqliteAdapter, PostgresAdapter } from '../../src/db';
|
||||
|
||||
let configPath = '/usr/local/etc/cic-meta';
|
||||
|
||||
const argv = standardArgs.argv;
|
||||
|
||||
if (argv['config'] !== undefined) {
|
||||
configPath = argv['config'];
|
||||
}
|
||||
|
||||
const config = new Config(configPath, argv['env-prefix']);
|
||||
config.process();
|
||||
console.debug(config.toString());
|
||||
|
||||
let fp = path.join(config.get('PGP_EXPORTS_DIR'), config.get('PGP_PUBLICKEY_ACTIVE_FILE'));
|
||||
const pubksa = fs.readFileSync(fp, 'utf-8');
|
||||
fp = path.join(config.get('PGP_EXPORTS_DIR'), config.get('PGP_PRIVATEKEY_FILE'));
|
||||
const pksa = fs.readFileSync(fp, 'utf-8');
|
||||
|
||||
const dbConfig = {
|
||||
'name': config.get('DATABASE_NAME'),
|
||||
'user': config.get('DATABASE_USER'),
|
||||
'password': config.get('DATABASE_PASSWORD'),
|
||||
'host': config.get('DATABASE_HOST'),
|
||||
'port': config.get('DATABASE_PORT'),
|
||||
'engine': config.get('DATABASE_ENGINE'),
|
||||
};
|
||||
let db = undefined;
|
||||
if (config.get('DATABASE_ENGINE') == 'sqlite') {
|
||||
db = new SqliteAdapter(dbConfig);
|
||||
} else if (config.get('DATABASE_ENGINE') == 'postgres') {
|
||||
db = new PostgresAdapter(dbConfig);
|
||||
} else {
|
||||
throw 'database engine ' + config.get('DATABASE_ENGINE') + 'not implemented';
|
||||
}
|
||||
|
||||
|
||||
let signer = undefined;
|
||||
const keystore = new PGPKeyStore(config.get('PGP_PASSPHRASE'), pksa, pubksa, pubksa, pubksa, () => {
|
||||
keysLoaded();
|
||||
});
|
||||
|
||||
function keysLoaded() {
|
||||
signer = new PGPSigner(keystore);
|
||||
prepareServer();
|
||||
}
|
||||
|
||||
async function migrateDatabase(cb) {
|
||||
try {
|
||||
const sql = "SELECT 1 FROM store;"
|
||||
db.query(sql, (e, rs) => {
|
||||
if (e === null || e === undefined) {
|
||||
cb();
|
||||
return;
|
||||
}
|
||||
console.warn('db check for table "store" fail', e);
|
||||
|
||||
console.debug('using schema path', config.get('DATABASE_SCHEMA_SQL_PATH'));
|
||||
const sql = fs.readFileSync(config.get('DATABASE_SCHEMA_SQL_PATH'), 'utf-8');
|
||||
db.query(sql, (e, rs) => {
|
||||
if (e !== undefined && e !== null) {
|
||||
console.error('db initialization fail', e);
|
||||
return;
|
||||
}
|
||||
cb();
|
||||
});
|
||||
|
||||
});
|
||||
} catch(e) {
|
||||
console.warn('table store does not exist', e);
|
||||
}
|
||||
}
|
||||
|
||||
async function prepareServer() {
|
||||
await migrateDatabase(startServer);
|
||||
}
|
||||
|
||||
async function startServer() {
|
||||
http.createServer(processRequest).listen(config.get('SERVER_PORT'));
|
||||
}
|
||||
|
||||
const re_digest = /^\/([a-fA-F0-9]{64})\/?$/;
|
||||
function parseDigest(url) {
|
||||
const digest_test = url.match(re_digest);
|
||||
if (digest_test === null) {
|
||||
throw 'invalid digest';
|
||||
}
|
||||
return digest_test[1].toLowerCase();
|
||||
}
|
||||
|
||||
async function processRequest(req, res) {
|
||||
let digest = undefined;
|
||||
|
||||
if (!['PUT', 'GET', 'POST'].includes(req.method)) {
|
||||
res.writeHead(405, {"Content-Type": "text/plain"});
|
||||
res.end();
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
digest = parseDigest(req.url);
|
||||
} catch(e) {
|
||||
res.writeHead(400, {"Content-Type": "text/plain"});
|
||||
res.end();
|
||||
return;
|
||||
}
|
||||
|
||||
const mergeHeader = req.headers['x-cic-automerge'];
|
||||
let mod = req.method.toLowerCase() + ":automerge:";
|
||||
switch (mergeHeader) {
|
||||
case "client":
|
||||
mod += "client"; // client handles merges
|
||||
break;
|
||||
case "server":
|
||||
mod += "server"; // server handles merges
|
||||
break;
|
||||
default:
|
||||
mod += "none"; // merged object only (get only)
|
||||
}
|
||||
|
||||
let data = '';
|
||||
req.on('data', (d) => {
|
||||
data += d;
|
||||
});
|
||||
req.on('end', async () => {
|
||||
console.debug('mode', mod);
|
||||
let content = '';
|
||||
let contentType = 'application/json';
|
||||
let r:any = undefined;
|
||||
try {
|
||||
switch (mod) {
|
||||
case 'put:automerge:client':
|
||||
r = await handlers.handleClientMergePut(data, db, digest, keystore, signer);
|
||||
if (r == false) {
|
||||
res.writeHead(403, {"Content-Type": "text/plain"});
|
||||
res.end();
|
||||
return;
|
||||
}
|
||||
break;
|
||||
|
||||
case 'get:automerge:client':
|
||||
content = await handlers.handleClientMergeGet(db, digest, keystore);
|
||||
break;
|
||||
|
||||
case 'post:automerge:server':
|
||||
content = await handlers.handleServerMergePost(data, db, digest, keystore, signer);
|
||||
break;
|
||||
|
||||
case 'put:automerge:server':
|
||||
r = await handlers.handleServerMergePut(data, db, digest, keystore, signer);
|
||||
if (r == false) {
|
||||
res.writeHead(403, {"Content-Type": "text/plain"});
|
||||
res.end();
|
||||
return;
|
||||
}
|
||||
break;
|
||||
//case 'get:automerge:server':
|
||||
// content = await handlers.handleServerMergeGet(db, digest, keystore);
|
||||
// break;
|
||||
|
||||
case 'get:automerge:none':
|
||||
r = await handlers.handleNoMergeGet(db, digest, keystore);
|
||||
if (r == false) {
|
||||
res.writeHead(404, {"Content-Type": "text/plain"});
|
||||
res.end();
|
||||
return;
|
||||
}
|
||||
content = r;
|
||||
break;
|
||||
|
||||
default:
|
||||
res.writeHead(400, {"Content-Type": "text/plain"});
|
||||
res.end();
|
||||
return;
|
||||
}
|
||||
} catch(e) {
|
||||
console.error('fail', mod, digest, e);
|
||||
res.writeHead(500, {"Content-Type": "text/plain"});
|
||||
res.end();
|
||||
return;
|
||||
}
|
||||
|
||||
if (content === undefined) {
|
||||
res.writeHead(400, {"Content-Type": "text/plain"});
|
||||
res.end();
|
||||
return;
|
||||
}
|
||||
|
||||
res.writeHead(200, {
|
||||
"Content-Type": contentType,
|
||||
"Content-Length": content.length,
|
||||
});
|
||||
res.write(content);
|
||||
res.end();
|
||||
});
|
||||
}
|
31
apps/cic-meta/src/assets/phone.ts
Normal file
31
apps/cic-meta/src/assets/phone.ts
Normal file
@ -0,0 +1,31 @@
|
||||
import { ArgPair, Syncable } from '../sync';
|
||||
import { Addressable, addressToBytes, bytesToHex, toKey } from '../digest';
|
||||
|
||||
class Phone extends Syncable implements Addressable {
|
||||
|
||||
address: string
|
||||
value: number
|
||||
|
||||
constructor(address:string, v:number) {
|
||||
const o = {
|
||||
msisdn: v,
|
||||
}
|
||||
super('', o);
|
||||
Phone.toKey(v).then((phid) => {
|
||||
this.id = phid;
|
||||
this.address = address;
|
||||
});
|
||||
}
|
||||
|
||||
public static async toKey(msisdn:number) {
|
||||
return await toKey(msisdn.toString(), ':cic.msisdn');
|
||||
}
|
||||
|
||||
public key(): string {
|
||||
return this.id;
|
||||
}
|
||||
}
|
||||
|
||||
export {
|
||||
Phone,
|
||||
}
|
47
apps/cic-meta/src/assets/user.ts
Normal file
47
apps/cic-meta/src/assets/user.ts
Normal file
@ -0,0 +1,47 @@
|
||||
import { ArgPair, Syncable } from '../sync';
|
||||
import { Addressable, addressToBytes, bytesToHex, toAddressKey } from '../digest';
|
||||
|
||||
const keySalt = new TextEncoder().encode(':cic.person');
|
||||
class User extends Syncable implements Addressable {
|
||||
|
||||
address: string
|
||||
firstName: string
|
||||
lastName: string
|
||||
|
||||
constructor(address:string, v:Object={}) {
|
||||
if (v['user'] === undefined) {
|
||||
v['user'] = {
|
||||
firstName: '',
|
||||
lastName: '',
|
||||
}
|
||||
}
|
||||
User.toKey(address).then((uid) => {
|
||||
this.id = uid;
|
||||
this.address = address;
|
||||
});
|
||||
super('', v);
|
||||
}
|
||||
|
||||
public static async toKey(address:string) {
|
||||
return await toAddressKey(address, ':cic.person');
|
||||
}
|
||||
|
||||
public key(): string {
|
||||
return this.id;
|
||||
}
|
||||
|
||||
public setName(firstName:string, lastName:string) {
|
||||
//const fn = new ArgPair('user.firstName', firstName)
|
||||
//const ln = new ArgPair('user.lastName', lastName)
|
||||
const n = {
|
||||
'user': {
|
||||
'firstName': firstName,
|
||||
'lastName': lastName,
|
||||
},
|
||||
}
|
||||
//this.update([fn, ln], 'update name');
|
||||
this.replace(n, 'update name');
|
||||
}
|
||||
}
|
||||
|
||||
export { User };
|
191
apps/cic-meta/src/auth.ts
Normal file
191
apps/cic-meta/src/auth.ts
Normal file
@ -0,0 +1,191 @@
|
||||
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(boolean):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) {
|
||||
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) {
|
||||
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: (boolean) => 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) {
|
||||
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) {
|
||||
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,
|
||||
};
|
71
apps/cic-meta/src/config.ts
Normal file
71
apps/cic-meta/src/config.ts
Normal file
@ -0,0 +1,71 @@
|
||||
import * as fs from 'fs';
|
||||
import * as ini from 'ini';
|
||||
import * as path from 'path';
|
||||
|
||||
class Config {
|
||||
|
||||
filepath: string
|
||||
store: Object
|
||||
censor: Array<string>
|
||||
require: Array<string>
|
||||
env_prefix: string
|
||||
|
||||
constructor(filepath:string, env_prefix?:string) {
|
||||
this.filepath = filepath;
|
||||
this.store = {};
|
||||
this.censor = [];
|
||||
this.require = [];
|
||||
this.env_prefix = '';
|
||||
if (env_prefix !== undefined) {
|
||||
this.env_prefix = env_prefix + "_";
|
||||
}
|
||||
}
|
||||
|
||||
public process() {
|
||||
const d = fs.readdirSync(this.filepath);
|
||||
|
||||
const r = /.*\.ini$/;
|
||||
for (let i = 0; i < d.length; i++) {
|
||||
const f = d[i];
|
||||
if (!f.match(r)) {
|
||||
return;
|
||||
}
|
||||
|
||||
const fp = path.join(this.filepath, f);
|
||||
const v = fs.readFileSync(fp, 'utf-8');
|
||||
const inid = ini.decode(v);
|
||||
const inik = Object.keys(inid);
|
||||
for (let j = 0; j < inik.length; j++) {
|
||||
const k_section = inik[j]
|
||||
const k = k_section.toUpperCase();
|
||||
Object.keys(inid[k_section]).forEach((k_directive) => {
|
||||
const kk = k_directive.toUpperCase();
|
||||
const kkk = k + '_' + kk;
|
||||
|
||||
let r = inid[k_section][k_directive];
|
||||
const k_env = this.env_prefix + kkk
|
||||
const env = process.env[k_env];
|
||||
if (env !== undefined) {
|
||||
console.debug('Environment variable ' + k_env + ' overrides ' + kkk);
|
||||
r = env;
|
||||
}
|
||||
this.store[kkk] = r;
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public get(s:string) {
|
||||
return this.store[s];
|
||||
}
|
||||
|
||||
public toString() {
|
||||
let s = '';
|
||||
Object.keys(this.store).forEach((k) => {
|
||||
s += k + '=' + this.store[k] + '\n';
|
||||
});
|
||||
return s;
|
||||
}
|
||||
}
|
||||
|
||||
export { Config };
|
38
apps/cic-meta/src/constants.ts
Normal file
38
apps/cic-meta/src/constants.ts
Normal file
@ -0,0 +1,38 @@
|
||||
import { JSONSerializable } from './format';
|
||||
|
||||
const ENGINE_NAME = 'automerge';
|
||||
const ENGINE_VERSION = '0.14.1';
|
||||
|
||||
const NETWORK_NAME = 'cic';
|
||||
const NETWORK_VERSION = '1';
|
||||
|
||||
const CRYPTO_NAME = 'pgp';
|
||||
const CRYPTO_VERSION = '2';
|
||||
|
||||
type VersionedSpec = {
|
||||
name: string
|
||||
version: string
|
||||
ext?: Object
|
||||
}
|
||||
|
||||
const engineSpec:VersionedSpec = {
|
||||
name: ENGINE_NAME,
|
||||
version: ENGINE_VERSION,
|
||||
}
|
||||
|
||||
const cryptoSpec:VersionedSpec = {
|
||||
name: CRYPTO_NAME,
|
||||
version: CRYPTO_VERSION,
|
||||
}
|
||||
|
||||
const networkSpec:VersionedSpec = {
|
||||
name: NETWORK_NAME,
|
||||
version: NETWORK_VERSION,
|
||||
}
|
||||
|
||||
export {
|
||||
engineSpec,
|
||||
cryptoSpec,
|
||||
networkSpec,
|
||||
VersionedSpec,
|
||||
};
|
27
apps/cic-meta/src/crypto.ts
Normal file
27
apps/cic-meta/src/crypto.ts
Normal file
@ -0,0 +1,27 @@
|
||||
import * as crypto from 'crypto';
|
||||
|
||||
const _algs = {
|
||||
'SHA-256': 'sha256',
|
||||
}
|
||||
|
||||
function cryptoWrapper() {
|
||||
}
|
||||
|
||||
cryptoWrapper.prototype.digest = async function(s, d) {
|
||||
const h = crypto.createHash(_algs[s]);
|
||||
h.update(d);
|
||||
return h.digest();
|
||||
}
|
||||
|
||||
let subtle = undefined;
|
||||
if (typeof window !== 'undefined') {
|
||||
subtle = window.crypto.subtle;
|
||||
} else {
|
||||
subtle = new cryptoWrapper();
|
||||
}
|
||||
|
||||
|
||||
export {
|
||||
subtle,
|
||||
}
|
||||
|
90
apps/cic-meta/src/db.ts
Normal file
90
apps/cic-meta/src/db.ts
Normal file
@ -0,0 +1,90 @@
|
||||
import * as pg from 'pg';
|
||||
import * as sqlite from 'sqlite3';
|
||||
|
||||
type DbConfig = {
|
||||
name: string
|
||||
host: string
|
||||
port: number
|
||||
user: string
|
||||
password: string
|
||||
}
|
||||
|
||||
interface DbAdapter {
|
||||
query: (s:string, callback:(e:any, rs:any) => void) => void
|
||||
close: () => void
|
||||
}
|
||||
|
||||
const re_creatematch = /^(CREATE)/i
|
||||
const re_getmatch = /^(SELECT)/i;
|
||||
const re_setmatch = /^(INSERT|UPDATE)/i;
|
||||
|
||||
class SqliteAdapter implements DbAdapter {
|
||||
|
||||
db: any
|
||||
|
||||
constructor(dbConfig:DbConfig, callback?:(any) => void) {
|
||||
this.db = new sqlite.Database(dbConfig.name); //, callback);
|
||||
}
|
||||
|
||||
public query(s:string, callback:(e:any, rs?:any) => void): void {
|
||||
const local_callback = (e, rs) => {
|
||||
let r = undefined;
|
||||
if (rs !== undefined) {
|
||||
r = {
|
||||
rowCount: rs.length,
|
||||
rows: rs,
|
||||
}
|
||||
}
|
||||
callback(e, r);
|
||||
};
|
||||
if (s.match(re_getmatch)) {
|
||||
this.db.all(s, local_callback);
|
||||
} else if (s.match(re_setmatch)) {
|
||||
this.db.run(s, local_callback);
|
||||
} else if (s.match(re_creatematch)) {
|
||||
this.db.run(s, callback);
|
||||
} else {
|
||||
throw 'unhandled query';
|
||||
}
|
||||
}
|
||||
|
||||
public close() {
|
||||
this.db.close();
|
||||
}
|
||||
}
|
||||
|
||||
class PostgresAdapter implements DbAdapter {
|
||||
|
||||
db: any
|
||||
|
||||
constructor(dbConfig:DbConfig) {
|
||||
let o = dbConfig;
|
||||
o['database'] = o.name;
|
||||
this.db = new pg.Pool(o);
|
||||
return this.db;
|
||||
}
|
||||
|
||||
public query(s:string, callback:(e:any, rs:any) => void): void {
|
||||
this.db.query(s, (e, rs) => {
|
||||
let r = {
|
||||
length: rs.rowCount,
|
||||
}
|
||||
rs.length = rs.rowCount;
|
||||
if (e === undefined) {
|
||||
e = null;
|
||||
}
|
||||
console.debug(e, rs);
|
||||
callback(e, rs);
|
||||
});
|
||||
}
|
||||
|
||||
public close() {
|
||||
this.db.end();
|
||||
}
|
||||
}
|
||||
|
||||
export {
|
||||
DbConfig,
|
||||
SqliteAdapter,
|
||||
PostgresAdapter,
|
||||
}
|
67
apps/cic-meta/src/digest.ts
Normal file
67
apps/cic-meta/src/digest.ts
Normal file
@ -0,0 +1,67 @@
|
||||
import * as crypto from './crypto';
|
||||
|
||||
interface Addressable {
|
||||
key(): string
|
||||
digest(): string
|
||||
}
|
||||
|
||||
function stringToBytes(s:string) {
|
||||
const a = new Uint8Array(20);
|
||||
let j = 2;
|
||||
for (let i = 0; i < a.byteLength; i++) {
|
||||
const n = parseInt(s.substring(j, j+2), 16);
|
||||
a[i] = n;
|
||||
j += 2;
|
||||
}
|
||||
return a;
|
||||
}
|
||||
|
||||
function bytesToHex(a:Uint8Array) {
|
||||
let s = '';
|
||||
for (let i = 0; i < a.byteLength; i++) {
|
||||
const h = '00' + a[i].toString(16);
|
||||
s += h.slice(-2);
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
async function mergeKey(a:Uint8Array, s:Uint8Array) {
|
||||
const y = new Uint8Array(a.byteLength + s.byteLength);
|
||||
for (let i = 0; i < a.byteLength; i++) {
|
||||
y[i] = a[i];
|
||||
}
|
||||
for (let i = 0; i < s.byteLength; i++) {
|
||||
y[a.byteLength + i] = s[i];
|
||||
}
|
||||
const z = await crypto.subtle.digest('SHA-256', y);
|
||||
return bytesToHex(new Uint8Array(z));
|
||||
}
|
||||
|
||||
async function toKey(v:string, salt:string) {
|
||||
const a = stringToBytes(v);
|
||||
const s = new TextEncoder().encode(salt);
|
||||
return await mergeKey(a, s);
|
||||
}
|
||||
|
||||
|
||||
async function toAddressKey(zeroExHex:string, salt:string) {
|
||||
const a = addressToBytes(zeroExHex);
|
||||
const s = new TextEncoder().encode(salt);
|
||||
return await mergeKey(a, s);
|
||||
}
|
||||
|
||||
const re_addrHex = /^0[xX][a-fA-F0-9]{40}$/;
|
||||
function addressToBytes(s:string) {
|
||||
if (!s.match(re_addrHex)) {
|
||||
throw 'invalid address hex';
|
||||
}
|
||||
return stringToBytes(s);
|
||||
}
|
||||
|
||||
export {
|
||||
toKey,
|
||||
toAddressKey,
|
||||
bytesToHex,
|
||||
addressToBytes,
|
||||
Addressable,
|
||||
}
|
58
apps/cic-meta/src/dispatch.ts
Normal file
58
apps/cic-meta/src/dispatch.ts
Normal file
@ -0,0 +1,58 @@
|
||||
import { v4 as uuidv4 } from 'uuid';
|
||||
import { Syncable } from './sync';
|
||||
import { Store } from './store';
|
||||
import { PubSub } from './transport';
|
||||
|
||||
function toIndexKey(id:string):string {
|
||||
const d = Date.now();
|
||||
return d + '_' + id + '_' + uuidv4();
|
||||
}
|
||||
|
||||
const _re_indexKey = /^\d+_(.+)_[-\d\w]+$/;
|
||||
function fromIndexKey(s:string):string {
|
||||
const m = s.match(_re_indexKey);
|
||||
if (m === null) {
|
||||
throw 'Invalid index key';
|
||||
}
|
||||
return m[1];
|
||||
}
|
||||
|
||||
class Dispatcher {
|
||||
|
||||
idx: Array<string>
|
||||
syncer: PubSub
|
||||
store: Store
|
||||
|
||||
constructor(store:Store, syncer:PubSub) {
|
||||
this.idx = new Array<string>()
|
||||
this.syncer = syncer;
|
||||
this.store = store;
|
||||
}
|
||||
|
||||
public isDirty(): boolean {
|
||||
return this.idx.length > 0;
|
||||
}
|
||||
|
||||
public add(id:string, item:Syncable): string {
|
||||
const v = item.toJSON();
|
||||
const k = toIndexKey(id);
|
||||
this.store.put(k, v, true);
|
||||
localStorage.setItem(k, v);
|
||||
this.idx.push(k);
|
||||
return k;
|
||||
}
|
||||
|
||||
public sync(offset:number): number {
|
||||
let i = 0;
|
||||
this.idx.forEach((k) => {
|
||||
const v = localStorage.getItem(k);
|
||||
const k_id = fromIndexKey(k);
|
||||
this.syncer.pub(v); // this must block until guaranteed delivery
|
||||
localStorage.removeItem(k);
|
||||
i++;
|
||||
});
|
||||
return i;
|
||||
}
|
||||
}
|
||||
|
||||
export { Dispatcher, toIndexKey, fromIndexKey }
|
5
apps/cic-meta/src/format.ts
Normal file
5
apps/cic-meta/src/format.ts
Normal file
@ -0,0 +1,5 @@
|
||||
interface JSONSerializable {
|
||||
toJSON(): string
|
||||
}
|
||||
|
||||
export { JSONSerializable };
|
4
apps/cic-meta/src/index.ts
Normal file
4
apps/cic-meta/src/index.ts
Normal file
@ -0,0 +1,4 @@
|
||||
export { PGPSigner, PGPKeyStore } from './auth';
|
||||
export { Envelope, Syncable } from './sync';
|
||||
export { User } from './assets/user';
|
||||
export { Phone } from './assets/phone';
|
9
apps/cic-meta/src/store.ts
Normal file
9
apps/cic-meta/src/store.ts
Normal file
@ -0,0 +1,9 @@
|
||||
import { Syncable } from './sync';
|
||||
|
||||
interface Store {
|
||||
put(string, Syncable, boolean?)
|
||||
get(string):Syncable
|
||||
delete(string)
|
||||
}
|
||||
|
||||
export { Store };
|
266
apps/cic-meta/src/sync.ts
Normal file
266
apps/cic-meta/src/sync.ts
Normal file
@ -0,0 +1,266 @@
|
||||
import * as Automerge from 'automerge';
|
||||
|
||||
import { JSONSerializable } from './format';
|
||||
|
||||
import { Authoritative, Signer, PGPSigner, Signable, Signature } from './auth';
|
||||
|
||||
import { engineSpec, cryptoSpec, networkSpec, VersionedSpec } from './constants';
|
||||
|
||||
const fullSpec:VersionedSpec = {
|
||||
name: 'cic',
|
||||
version: '1',
|
||||
ext: {
|
||||
network: cryptoSpec,
|
||||
engine: engineSpec,
|
||||
},
|
||||
}
|
||||
|
||||
class Envelope {
|
||||
|
||||
o = fullSpec
|
||||
|
||||
constructor(payload:Object) {
|
||||
this.set(payload);
|
||||
}
|
||||
|
||||
public set(payload:Object) {
|
||||
this.o['payload'] = payload
|
||||
}
|
||||
|
||||
public get():string {
|
||||
return this.o['payload'];
|
||||
}
|
||||
|
||||
public toJSON() {
|
||||
return JSON.stringify(this.o);
|
||||
}
|
||||
|
||||
public static fromJSON(s:string): Envelope {
|
||||
const e = new Envelope(undefined);
|
||||
e.o = JSON.parse(s);
|
||||
return e;
|
||||
}
|
||||
|
||||
public unwrap(): Syncable {
|
||||
return Syncable.fromJSON(this.o['payload']);
|
||||
}
|
||||
}
|
||||
|
||||
class ArgPair {
|
||||
|
||||
k:string
|
||||
v:any
|
||||
|
||||
constructor(k:string, v:any) {
|
||||
this.k = k;
|
||||
this.v = v;
|
||||
}
|
||||
}
|
||||
|
||||
class SignablePart implements Signable {
|
||||
|
||||
s: string
|
||||
|
||||
constructor(s:string) {
|
||||
this.s = s;
|
||||
}
|
||||
|
||||
public digest():string {
|
||||
return this.s;
|
||||
}
|
||||
}
|
||||
|
||||
function orderDict(src) {
|
||||
let dst;
|
||||
if (Array.isArray(src)) {
|
||||
dst = [];
|
||||
src.forEach((v) => {
|
||||
if (typeof(v) == 'object') {
|
||||
v = orderDict(v);
|
||||
}
|
||||
dst.push(v);
|
||||
});
|
||||
} else {
|
||||
dst = {}
|
||||
Object.keys(src).sort().forEach((k) => {
|
||||
let v = src[k];
|
||||
if (typeof(v) == 'object') {
|
||||
v = orderDict(v);
|
||||
}
|
||||
dst[k] = v;
|
||||
});
|
||||
}
|
||||
return dst;
|
||||
}
|
||||
|
||||
class Syncable implements JSONSerializable, Authoritative {
|
||||
|
||||
id: string
|
||||
timestamp: number
|
||||
m: any // automerge object
|
||||
e: Envelope
|
||||
signer: Signer
|
||||
onwrap: (string) => void
|
||||
onauthenticate: (boolean) => void
|
||||
|
||||
// TODO: Move data to sub-object so timestamp, id, signature don't collide
|
||||
constructor(id:string, v:Object) {
|
||||
this.id = id;
|
||||
const o = {
|
||||
'id': id,
|
||||
'timestamp': Math.floor(Date.now() / 1000),
|
||||
'data': v,
|
||||
}
|
||||
//this.m = Automerge.from(v)
|
||||
this.m = Automerge.from(o)
|
||||
}
|
||||
|
||||
public setSigner(signer:Signer) {
|
||||
this.signer = signer;
|
||||
this.signer.onsign = (s) => {
|
||||
this.wrap(s);
|
||||
};
|
||||
}
|
||||
|
||||
// TODO: To keep integrity, the non-link key/value pairs for each step also need to be hashed
|
||||
public digest(): string {
|
||||
const links = [];
|
||||
Automerge.getAllChanges(this.m).forEach((ch:Object) => {
|
||||
const op:Array<any> = ch['ops'];
|
||||
ch['ops'].forEach((op:Array<Object>) => {
|
||||
if (op['action'] == 'link') {
|
||||
//console.log('op link', op);
|
||||
links.push([op['obj'], op['value']]);
|
||||
}
|
||||
});
|
||||
});
|
||||
//return JSON.stringify(links);
|
||||
const j = JSON.stringify(links);
|
||||
return Buffer.from(j).toString('base64');
|
||||
}
|
||||
|
||||
private wrap(s:any) {
|
||||
this.m = Automerge.change(this.m, 'sign', (doc) => {
|
||||
doc['signature'] = s;
|
||||
});
|
||||
this.e = new Envelope(this.toJSON());
|
||||
console.log('wrappin s', s, typeof(s));
|
||||
this.e.o['digest'] = s.digest;
|
||||
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);
|
||||
// }
|
||||
|
||||
public authenticate(full:boolean=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 = (v) => {
|
||||
//this._verifyLoop(i, history, signable, v)
|
||||
this.onauthenticate(v);
|
||||
}
|
||||
this.signer.verify(this.m.signature.digest, this.m.signature);
|
||||
}
|
||||
|
||||
|
||||
public sign() {
|
||||
//this.signer.prepare(this);
|
||||
this.signer.sign(this.digest());
|
||||
}
|
||||
|
||||
public update(changes:Array<ArgPair>, changesDescription:string) {
|
||||
this.m = Automerge.change(this.m, changesDescription, (m) => {
|
||||
changes.forEach((c) => {
|
||||
let path = c.k.split('.');
|
||||
let target = m['data'];
|
||||
while (path.length > 1) {
|
||||
const part = path.shift();
|
||||
target = target[part];
|
||||
}
|
||||
target[path[0]] = c.v;
|
||||
});
|
||||
m['timestamp'] = Math.floor(Date.now() / 1000);
|
||||
});
|
||||
}
|
||||
|
||||
public replace(o:Object, changesDescription:string) {
|
||||
this.m = Automerge.change(this.m, changesDescription, (m) => {
|
||||
Object.keys(o).forEach((k) => {
|
||||
m['data'][k] = o[k];
|
||||
});
|
||||
Object.keys(m).forEach((k) => {
|
||||
if (o[k] == undefined) {
|
||||
delete m['data'][k];
|
||||
}
|
||||
});
|
||||
m['timestamp'] = Math.floor(Date.now() / 1000);
|
||||
});
|
||||
}
|
||||
|
||||
public merge(s:Syncable) {
|
||||
this.m = Automerge.merge(s.m, this.m);
|
||||
}
|
||||
|
||||
public toJSON(): string {
|
||||
const s = Automerge.save(this.m);
|
||||
const o = JSON.parse(s);
|
||||
const oo = orderDict(o)
|
||||
return JSON.stringify(oo);
|
||||
|
||||
}
|
||||
|
||||
public static fromJSON(s:string): Syncable {
|
||||
const doc = Automerge.load(s);
|
||||
let y = new Syncable(doc['id'], {});
|
||||
y.m = doc
|
||||
return y
|
||||
}
|
||||
}
|
||||
|
||||
export { JSONSerializable, Syncable, ArgPair, Envelope };
|
11
apps/cic-meta/src/transport.ts
Normal file
11
apps/cic-meta/src/transport.ts
Normal file
@ -0,0 +1,11 @@
|
||||
interface SubConsumer {
|
||||
post(string)
|
||||
}
|
||||
|
||||
interface PubSub {
|
||||
pub(v:string):boolean
|
||||
close()
|
||||
}
|
||||
|
||||
export { PubSub, SubConsumer };
|
||||
|
50
apps/cic-meta/tests/1_basic.ts
Normal file
50
apps/cic-meta/tests/1_basic.ts
Normal file
@ -0,0 +1,50 @@
|
||||
import * as Automerge from 'automerge';
|
||||
import assert = require('assert');
|
||||
|
||||
import { Dispatcher, toIndexKey, fromIndexKey } from '../src/dispatch';
|
||||
import { User } from '../src/assets/user';
|
||||
import { Syncable, ArgPair } from '../src/sync';
|
||||
|
||||
import { MockSigner, MockStore } from './mock';
|
||||
|
||||
describe('basic', () => {
|
||||
|
||||
it('store', () => {
|
||||
const store = new MockStore('s');
|
||||
assert.equal(store.name, 's');
|
||||
|
||||
const mockSigner = new MockSigner();
|
||||
const v = new Syncable('foo', {baz: 42});
|
||||
v.setSigner(mockSigner);
|
||||
store.put('foo', v);
|
||||
const one = store.get('foo').toJSON();
|
||||
const vv = new Syncable('bar', {baz: 666});
|
||||
vv.setSigner(mockSigner);
|
||||
assert.throws(() => {
|
||||
store.put('foo', vv)
|
||||
});
|
||||
store.put('foo', vv, true);
|
||||
const other = store.get('foo').toJSON();
|
||||
assert.notEqual(one, other);
|
||||
store.delete('foo');
|
||||
assert.equal(store.get('foo'), undefined);
|
||||
});
|
||||
|
||||
it('add_doc_to_dispatcher', () => {
|
||||
const store = new MockStore('s');
|
||||
//const syncer = new MockSyncer();
|
||||
const dispatcher = new Dispatcher(store, undefined);
|
||||
const user = new User('foo');
|
||||
dispatcher.add(user.id, user);
|
||||
assert(dispatcher.isDirty());
|
||||
});
|
||||
|
||||
it('dispatch_keyindex', () => {
|
||||
const s = 'foo';
|
||||
const k = toIndexKey(s);
|
||||
const v = fromIndexKey(k);
|
||||
assert.equal(s, v);
|
||||
});
|
||||
|
||||
|
||||
});
|
212
apps/cic-meta/tests/2_sync.ts
Normal file
212
apps/cic-meta/tests/2_sync.ts
Normal file
@ -0,0 +1,212 @@
|
||||
import * as Automerge from 'automerge';
|
||||
import assert = require('assert');
|
||||
|
||||
import * as pgp from 'openpgp';
|
||||
import * as fs from 'fs';
|
||||
|
||||
import { PGPSigner } from '../src/auth';
|
||||
|
||||
import { Syncable, ArgPair } from '../src/sync';
|
||||
|
||||
import { MockKeyStore, MockSigner } from './mock';
|
||||
|
||||
|
||||
describe('sync', async () => {
|
||||
it('sync_merge', () => {
|
||||
const mockSigner = new MockSigner();
|
||||
const s = new Syncable('foo', {
|
||||
bar: 'baz',
|
||||
});
|
||||
s.setSigner(mockSigner);
|
||||
const changePair = new ArgPair('xyzzy', 42);
|
||||
s.update([changePair], 'ch-ch-cha-changes');
|
||||
assert.equal(s.m.data['xyzzy'], 42)
|
||||
assert.equal(s.m.data['bar'], 'baz')
|
||||
assert.equal(s.m['id'], 'foo')
|
||||
assert.equal(Automerge.getHistory(s.m).length, 2);
|
||||
});
|
||||
|
||||
it('sync_serialize', () => {
|
||||
const mockSigner = new MockSigner();
|
||||
const s = new Syncable('foo', {
|
||||
bar: 'baz',
|
||||
});
|
||||
s.setSigner(mockSigner);
|
||||
const j = s.toJSON();
|
||||
const ss = Syncable.fromJSON(j);
|
||||
assert.equal(ss.m['id'], 'foo');
|
||||
assert.equal(ss.m['data']['bar'], 'baz');
|
||||
assert.equal(Automerge.getHistory(ss.m).length, 1);
|
||||
});
|
||||
|
||||
it('sync_sign_and_wrap', () => {
|
||||
const mockSigner = new MockSigner();
|
||||
const s = new Syncable('foo', {
|
||||
bar: 'baz',
|
||||
});
|
||||
s.setSigner(mockSigner);
|
||||
s.onwrap = (e) => {
|
||||
const j = e.toJSON();
|
||||
const v = JSON.parse(j);
|
||||
assert.deepEqual(v.payload, e.o.payload);
|
||||
|
||||
}
|
||||
s.sign();
|
||||
});
|
||||
it('sync_verify_success', async () => {
|
||||
const pksa = fs.readFileSync(__dirname + '/privatekeys.asc');
|
||||
const pks = await pgp.key.readArmored(pksa);
|
||||
await pks.keys[0].decrypt('merman');
|
||||
await pks.keys[1].decrypt('beastman');
|
||||
|
||||
const pubksa = fs.readFileSync(__dirname + '/publickeys.asc');
|
||||
const pubks = await pgp.key.readArmored(pubksa);
|
||||
|
||||
const oneStore = new MockKeyStore(pks.keys[0], pubks.keys);
|
||||
const twoStore = new MockKeyStore(pks.keys[1], pubks.keys);
|
||||
const threeStore = new MockKeyStore(pks.keys[2], [pubks.keys[0], pubks.keys[2]]);
|
||||
|
||||
const oneSigner = new PGPSigner(oneStore);
|
||||
const twoSigner = new PGPSigner(twoStore);
|
||||
const threeSigner = new PGPSigner(threeStore);
|
||||
|
||||
const x = new Syncable('foo', {
|
||||
bar: 'baz',
|
||||
});
|
||||
x.setSigner(oneSigner);
|
||||
|
||||
// TODO: make this look better
|
||||
x.onwrap = (e) => {
|
||||
let updateData = new ArgPair('bar', 'xyzzy');
|
||||
x.update([updateData], 'change one');
|
||||
|
||||
x.onwrap = (e) => {
|
||||
x.setSigner(twoSigner);
|
||||
updateData = new ArgPair('bar', 42);
|
||||
x.update([updateData], 'change two');
|
||||
|
||||
x.onwrap = (e) => {
|
||||
const p = e.unwrap();
|
||||
p.setSigner(twoSigner);
|
||||
p.onauthenticate = (v) => {
|
||||
assert(v);
|
||||
}
|
||||
p.authenticate();
|
||||
}
|
||||
|
||||
x.sign();
|
||||
};
|
||||
|
||||
x.sign();
|
||||
}
|
||||
|
||||
x.sign();
|
||||
|
||||
});
|
||||
|
||||
it('sync_verify_fail', async () => {
|
||||
const pksa = fs.readFileSync(__dirname + '/privatekeys.asc');
|
||||
const pks = await pgp.key.readArmored(pksa);
|
||||
await pks.keys[0].decrypt('merman');
|
||||
await pks.keys[1].decrypt('beastman');
|
||||
|
||||
const pubksa = fs.readFileSync(__dirname + '/publickeys.asc');
|
||||
const pubks = await pgp.key.readArmored(pubksa);
|
||||
|
||||
const oneStore = new MockKeyStore(pks.keys[0], pubks.keys);
|
||||
const twoStore = new MockKeyStore(pks.keys[1], pubks.keys);
|
||||
const threeStore = new MockKeyStore(pks.keys[2], [pubks.keys[0], pubks.keys[2]]);
|
||||
|
||||
const oneSigner = new PGPSigner(oneStore);
|
||||
const twoSigner = new PGPSigner(twoStore);
|
||||
const threeSigner = new PGPSigner(threeStore);
|
||||
|
||||
const x = new Syncable('foo', {
|
||||
bar: 'baz',
|
||||
});
|
||||
x.setSigner(oneSigner);
|
||||
|
||||
// TODO: make this look better
|
||||
x.onwrap = (e) => {
|
||||
let updateData = new ArgPair('bar', 'xyzzy');
|
||||
x.update([updateData], 'change one');
|
||||
|
||||
x.onwrap = (e) => {
|
||||
x.setSigner(twoSigner);
|
||||
updateData = new ArgPair('bar', 42);
|
||||
x.update([updateData], 'change two');
|
||||
|
||||
x.onwrap = (e) => {
|
||||
const p = e.unwrap();
|
||||
p.setSigner(threeSigner);
|
||||
p.onauthenticate = (v) => {
|
||||
assert(!v);
|
||||
}
|
||||
p.authenticate();
|
||||
}
|
||||
|
||||
x.sign();
|
||||
};
|
||||
|
||||
x.sign();
|
||||
}
|
||||
|
||||
x.sign();
|
||||
|
||||
});
|
||||
|
||||
xit('sync_verify_shallow_tricked', async () => {
|
||||
const pksa = fs.readFileSync(__dirname + '/privatekeys.asc');
|
||||
const pks = await pgp.key.readArmored(pksa);
|
||||
await pks.keys[0].decrypt('merman');
|
||||
await pks.keys[1].decrypt('beastman');
|
||||
|
||||
const pubksa = fs.readFileSync(__dirname + '/publickeys.asc');
|
||||
const pubks = await pgp.key.readArmored(pubksa);
|
||||
|
||||
const oneStore = new MockKeyStore(pks.keys[0], pubks.keys);
|
||||
const twoStore = new MockKeyStore(pks.keys[1], pubks.keys);
|
||||
const threeStore = new MockKeyStore(pks.keys[2], [pubks.keys[0], pubks.keys[2]]);
|
||||
|
||||
const oneSigner = new PGPSigner(oneStore);
|
||||
const twoSigner = new PGPSigner(twoStore);
|
||||
const threeSigner = new PGPSigner(threeStore);
|
||||
|
||||
const x = new Syncable('foo', {
|
||||
bar: 'baz',
|
||||
});
|
||||
x.setSigner(twoSigner);
|
||||
|
||||
// TODO: make this look better
|
||||
x.onwrap = (e) => {
|
||||
let updateData = new ArgPair('bar', 'xyzzy');
|
||||
x.update([updateData], 'change one');
|
||||
|
||||
x.onwrap = (e) => {
|
||||
updateData = new ArgPair('bar', 42);
|
||||
x.update([updateData], 'change two');
|
||||
x.setSigner(oneSigner);
|
||||
|
||||
x.onwrap = (e) => {
|
||||
const p = e.unwrap();
|
||||
p.setSigner(threeSigner);
|
||||
p.onauthenticate = (v) => {
|
||||
assert(v);
|
||||
p.onauthenticate = (v) => {
|
||||
assert(!v);
|
||||
}
|
||||
p.authenticate(true);
|
||||
}
|
||||
p.authenticate();
|
||||
}
|
||||
|
||||
x.sign();
|
||||
};
|
||||
|
||||
x.sign();
|
||||
}
|
||||
|
||||
x.sign();
|
||||
|
||||
});
|
||||
});
|
14
apps/cic-meta/tests/3_transport.ts
Normal file
14
apps/cic-meta/tests/3_transport.ts
Normal file
@ -0,0 +1,14 @@
|
||||
import * as assert from 'assert';
|
||||
|
||||
import { MockPubSub, MockConsumer } from './mock';
|
||||
|
||||
describe('transport', () => {
|
||||
it('pub_sub', () => {
|
||||
const c = new MockConsumer();
|
||||
const ps = new MockPubSub('foo', c);
|
||||
ps.pub('foo');
|
||||
ps.pub('bar');
|
||||
ps.flush();
|
||||
assert.deepEqual(c.omnoms, ['foo', 'bar']);
|
||||
});
|
||||
});
|
46
apps/cic-meta/tests/4_auth.ts
Normal file
46
apps/cic-meta/tests/4_auth.ts
Normal file
@ -0,0 +1,46 @@
|
||||
import assert = require('assert');
|
||||
import pgp = require('openpgp');
|
||||
import crypto = require('crypto');
|
||||
|
||||
import { Syncable, ArgPair } from '../src/sync';
|
||||
|
||||
import { MockKeyStore, MockSignable } from './mock';
|
||||
|
||||
import { PGPSigner } from '../src/auth';
|
||||
|
||||
|
||||
describe('auth', async () => {
|
||||
await it('digest', async () => {
|
||||
const opts = {
|
||||
userIds: [
|
||||
{
|
||||
name: 'John Marston',
|
||||
email: 'red@dead.com',
|
||||
},
|
||||
],
|
||||
numBits: 2048,
|
||||
passphrase: 'foo',
|
||||
};
|
||||
const pkgen = await pgp.generateKey(opts);
|
||||
const pka = pkgen.privateKeyArmored;
|
||||
const pks = await pgp.key.readArmored(pka);
|
||||
await pks.keys[0].decrypt('foo');
|
||||
const pubka = pkgen.publicKeyArmored;
|
||||
const pubks = await pgp.key.readArmored(pubka);
|
||||
const keyStore = new MockKeyStore(pks.keys[0], pubks.keys);
|
||||
const s = new PGPSigner(keyStore);
|
||||
|
||||
const message = await pgp.cleartext.fromText('foo');
|
||||
s.onverify = (ok) => {
|
||||
assert(ok);
|
||||
}
|
||||
s.onsign = (signature) => {
|
||||
s.onverify((v) => {
|
||||
console.log('bar', v);
|
||||
});
|
||||
s.verify('foo', signature);
|
||||
}
|
||||
|
||||
await s.sign('foo');
|
||||
});
|
||||
});
|
47
apps/cic-meta/tests/999_functional.ts
Normal file
47
apps/cic-meta/tests/999_functional.ts
Normal file
@ -0,0 +1,47 @@
|
||||
import * as assert from 'assert';
|
||||
import * as pgp from 'openpgp';
|
||||
|
||||
import { Dispatcher } from '../src/dispatch';
|
||||
import { User } from '../src/assets/user';
|
||||
import { PGPSigner, KeyStore } from '../src/auth';
|
||||
import { SubConsumer } from '../src/transport';
|
||||
|
||||
import { MockStore, MockPubSub, MockConsumer, MockKeyStore } from './mock';
|
||||
|
||||
async function createKeyStore() {
|
||||
const opts = {
|
||||
userIds: [
|
||||
{
|
||||
name: 'John Marston',
|
||||
email: 'red@dead.com',
|
||||
},
|
||||
],
|
||||
numBits: 2048,
|
||||
passphrase: 'foo',
|
||||
};
|
||||
const pkgen = await pgp.generateKey(opts);
|
||||
const pka = pkgen.privateKeyArmored;
|
||||
const pks = await pgp.key.readArmored(pka);
|
||||
await pks.keys[0].decrypt('foo');
|
||||
return new MockKeyStore(pks.keys[0], []);
|
||||
}
|
||||
|
||||
describe('fullchain', async () => {
|
||||
it('dispatch_and_publish_user', async () => {
|
||||
const g = await createKeyStore();
|
||||
const n = new PGPSigner(g);
|
||||
const u = new User('u1', {});
|
||||
u.setSigner(n);
|
||||
u.setName('Nico', 'Bellic');
|
||||
const s = new MockStore('fooStore');
|
||||
const c = new MockConsumer();
|
||||
const p = new MockPubSub('fooPubSub', c);
|
||||
const d = new Dispatcher(s, p);
|
||||
u.onwrap = (e) => {
|
||||
d.add(u.id, e);
|
||||
d.sync(0);
|
||||
assert.equal(p.pubs.length, 1);
|
||||
};
|
||||
u.sign();
|
||||
});
|
||||
});
|
150
apps/cic-meta/tests/mock.ts
Normal file
150
apps/cic-meta/tests/mock.ts
Normal file
@ -0,0 +1,150 @@
|
||||
import * as crypto from 'crypto';
|
||||
|
||||
import { Signable, Signature, KeyStore } from '../src/auth';
|
||||
import { Store } from '../src/store';
|
||||
import { PubSub, SubConsumer } from '../src/transport';
|
||||
import { Syncable } from '../src/sync';
|
||||
|
||||
class MockStore implements Store {
|
||||
|
||||
contents: Object
|
||||
name: string
|
||||
|
||||
constructor(name:string) {
|
||||
this.name = name;
|
||||
this.contents = {};
|
||||
}
|
||||
|
||||
public put(k:string, v:Syncable, existsOk = false) {
|
||||
if (!existsOk && this.contents[k] !== undefined) {
|
||||
throw '"' + k + '" already exists in store ' + this.name;
|
||||
}
|
||||
this.contents[k] = v;
|
||||
}
|
||||
|
||||
public get(k:string): Syncable {
|
||||
return this.contents[k];
|
||||
}
|
||||
|
||||
public delete(k:string) {
|
||||
delete this.contents[k];
|
||||
}
|
||||
}
|
||||
|
||||
class MockSigner {
|
||||
onsign: (string) => void
|
||||
onverify: (boolean) => void
|
||||
public verify(src:string, signature:Signature) {
|
||||
return true;
|
||||
}
|
||||
|
||||
public sign(s:string):boolean {
|
||||
this.onsign('there would be a signature here');
|
||||
return true;
|
||||
}
|
||||
|
||||
public prepare(m:Signable):boolean {
|
||||
return true;
|
||||
}
|
||||
|
||||
public fingerprint():string {
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
class MockConsumer implements SubConsumer {
|
||||
|
||||
omnoms: Array<string>
|
||||
|
||||
constructor() {
|
||||
this.omnoms = Array<string>();
|
||||
}
|
||||
|
||||
public post(v:string) {
|
||||
this.omnoms.push(v);
|
||||
}
|
||||
}
|
||||
|
||||
class MockPubSub implements PubSub {
|
||||
|
||||
pubs: Array<string>
|
||||
consumer: SubConsumer
|
||||
|
||||
constructor(name:string, consumer:SubConsumer) {
|
||||
this.pubs = Array<string>();
|
||||
this.consumer = consumer;
|
||||
}
|
||||
|
||||
public pub(v:string): boolean {
|
||||
this.pubs.push(v);
|
||||
return true;
|
||||
}
|
||||
|
||||
public flush() {
|
||||
while (this.pubs.length > 0) {
|
||||
const s = this.pubs.shift();
|
||||
this.consumer.post(s);
|
||||
}
|
||||
}
|
||||
|
||||
public close() {
|
||||
}
|
||||
}
|
||||
|
||||
class MockSignable implements Signable {
|
||||
|
||||
src: string
|
||||
dst: string
|
||||
|
||||
constructor(src:string) {
|
||||
this.src = src;
|
||||
}
|
||||
|
||||
public digest():string {
|
||||
const h = crypto.createHash('sha256');
|
||||
h.update(this.src);
|
||||
this.dst= h.digest('hex');
|
||||
return this.dst;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class MockKeyStore implements KeyStore {
|
||||
|
||||
pk: any
|
||||
pubks: Array<any>
|
||||
|
||||
constructor(pk:any, pubks:Array<any>) {
|
||||
this.pk = pk;
|
||||
this.pubks = pubks;
|
||||
}
|
||||
|
||||
public getPrivateKey(): any {
|
||||
return this.pk;
|
||||
}
|
||||
|
||||
public getTrustedKeys(): Array<any> {
|
||||
return this.pubks;
|
||||
}
|
||||
|
||||
public getTrustedActiveKeys(): Array<any> {
|
||||
return [];
|
||||
}
|
||||
|
||||
public getEncryptKeys(): Array<any> {
|
||||
return [];
|
||||
}
|
||||
|
||||
public getFingerprint(): string {
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
export {
|
||||
MockStore,
|
||||
MockPubSub,
|
||||
MockConsumer,
|
||||
MockSignable,
|
||||
MockKeyStore,
|
||||
MockSigner,
|
||||
};
|
241
apps/cic-meta/tests/privatekeys.asc
Normal file
241
apps/cic-meta/tests/privatekeys.asc
Normal file
@ -0,0 +1,241 @@
|
||||
-----BEGIN PGP PRIVATE KEY BLOCK-----
|
||||
|
||||
lQWGB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iyDGXYc7nG3uPvho7/cOCUUg5P/EG5z0CDX
|
||||
zLbmBrk2WlRnREmK/5NTcisCyezRMXHOxpya4pmExVMqSPGA0QbKGwdHqfbHQv2O
|
||||
yI3PYBKvlN+eu6e5SEbT76AQijj5RSPcgbko24/sSqJylD1lnRocQK1p4XelosBr
|
||||
aty4wzYSvQY9dRD4nafxPHI3YjKiAG0I7nJDQ0d1jDaW5FP0BkMvn51SmfGsuSg1
|
||||
s46h9JlGRZvS0enjBb1Ic9oBmHAWGQhlD1hvILlqIZOCdj8oWVjwmpZ7BK3/82wO
|
||||
dVkUxy09IdIot+AIH+F/LA3KKgfDmjldyhXjI/HDrpmXwSUkJOBHebNLz5t1Edau
|
||||
F+4DY5BHMsgtyyiYJBzRGT5pgrXMt4yCqZP+0jZwKt1Ech/Q6djIKjt+9wOGe9UB
|
||||
1VrzRbOS5ymseDJcjejtMxuCOuSTN9R5KuQ=
|
||||
=VqO+
|
||||
-----END PGP PRIVATE KEY BLOCK-----
|
151
apps/cic-meta/tests/publickeys.asc
Normal file
151
apps/cic-meta/tests/publickeys.asc
Normal file
@ -0,0 +1,151 @@
|
||||
-----BEGIN PGP PUBLIC KEY BLOCK-----
|
||||
|
||||
mQGNBF+hSOgBDACpkPQEjADjnQtjmAsdPYpx5N+OMJBYj1DAoIYsDtV6vbcBJQt9
|
||||
4Om3xl7RBhv9m2oLgzPsiRwjCEFRWyNSu0BUp5CFjcXfm0S4K2egx4erFnTnSSC9
|
||||
S6tmVNrVNEXvScE6sKAnmJ7JNX1ExJuEiWPbUDRWJ1hoI9+AR+8EONeJRLo/j0Np
|
||||
+S4IFDn0PsxdT+SB0GY0z2cEgjvjoPr4lW9IAb8Ft9TDYp+mOzejn1Fg7CuIrlBR
|
||||
SAv+sj7bVQw15dh1SpbwtS5xxubCa8ExEGI4ByXmeXdR0KZJ+EA5ksO0iSsQ/6ip
|
||||
SOdSg+i0niOClFNm1P/OhbUsYAxCUfiX654FMn2zoxVBEjJ3e7l0pH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571K+4TUUpaPCqEeoBBg6O3T29DH1AxpWpEPGXlOrRDHYgVziEpLdUNahAj
|
||||
F53auNWvya+Vc2qZwM4NFt608LLf7J5yIA2vbsvf6+gVopPE3whXESKXo08B2hC1
|
||||
f3Pr9/Tgt6oIvy9/dAcTMalxRyyc42E2wX5kyzDlfhY9kqaNNfaGMZJO5g//gB7B
|
||||
dtrAfo/LhWtary/YfAOtbbnMYkf+HODAPZItaIjMZngBM0c0m78YoCetAQE8uBFK
|
||||
6aXmht3BZGPOwgyZpK5QT6ClYst2N9ca3tPUEfnddotKySmCEk/JWtu5/0lFl75W
|
||||
zHulc7iUNGJmnUffVZyH12CjBWsTtqombHDkdEKFocavqpVcCCbKbtW5GZhuZC65
|
||||
mQGNBF+hSUIBDADStlWquV7SdREZtxXBVVzdCkV1xkeHYfo2Z244W0LTwmvpbO+o
|
||||
6P5GCAW2c336qWElsMO9ujeV2nuUZy3k3AtJLx19iWC+ywYVzJ8f878XAxq0ya1V
|
||||
BBnfsBc7iRI3umf2JSi+fHXf9l+rJ8Zr5AkLrUo3tQoxX8xWQIfUVY481nlkOvuM
|
||||
txEI6h1t+z7PWjAJsdKKdevRPApPIBGXX0iGE/98ATsLYtvh9ln26j1SrSdtKpPk
|
||||
tuYve3zkphlZAdf5ReViicik6gpEdyEfIxNab6nyV8LTbSeCHe+6/cz+AEqA+cr3
|
||||
K3MwriaapPzNhRV8izzGnIWChIZptGBKH5nLivfIAB/hbOgU6tM+YgUKrpJCXXA1
|
||||
My2q68o2kARJxh6s0tuuT6pFEAG9RmzS3ywrPz4PAgkwrJA1uUa9fy9ngkOnQN3C
|
||||
EeVQTUU55b+6zVhW1Qq8PII6AGqj1lSY9jLpjxEr3q227OlTaxfgg19x5o9rcycc
|
||||
AZlQqzL2p3Z7HZ0AEQEAAbQcSGUgTWFuIDxoZW1hbkBncmV5c2t1bGwuY29tPokB
|
||||
1AQTAQgAPhYhBIYPcR68MZb6cOhv9wDz8yhlQWZrBQJfoUlCAhsD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GLs/3yfelr1XXLwYXzKlioNDu7k4rggwN3td1122p3U1vfVY4qb2eTyjDPizb
|
||||
NdtbiWRXKFibzG0OoiAaq0ZC8nZsP6xy7vmI05hN7PocAWllJVdpaXVh75OViGaj
|
||||
KuNFGWsKI1qTd1aEMRQzT4s+JJM=
|
||||
=8257
|
||||
-----END PGP PUBLIC KEY BLOCK-----
|
317
apps/cic-meta/tests/server.ts
Normal file
317
apps/cic-meta/tests/server.ts
Normal file
@ -0,0 +1,317 @@
|
||||
import Automerge = require('automerge');
|
||||
import assert = require('assert');
|
||||
import fs = require('fs');
|
||||
import pgp = require('openpgp');
|
||||
import sqlite = require('sqlite3');
|
||||
|
||||
import * as handlers from '../scripts/server/handlers';
|
||||
import { Envelope, Syncable, ArgPair } from '../src/sync';
|
||||
import { PGPKeyStore, PGPSigner, KeyStore, Signer } from '../src/auth';
|
||||
import { SqliteAdapter } from '../src/db';
|
||||
|
||||
function createKeystore() {
|
||||
const pksa = fs.readFileSync(__dirname + '/privatekeys.asc', 'utf-8');
|
||||
const pubksa = fs.readFileSync(__dirname + '/publickeys.asc', 'utf-8');
|
||||
return new Promise<PGPKeyStore>((whohoo, doh) => {
|
||||
let keystore = undefined;
|
||||
try {
|
||||
keystore = new PGPKeyStore('merman', pksa, pubksa, pubksa, pubksa, () => {
|
||||
whohoo(keystore);
|
||||
});
|
||||
} catch(e) {
|
||||
doh(e);
|
||||
}
|
||||
if (keystore === undefined) {
|
||||
doh();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function createDatabase(sqlite_file:string):Promise<any> {
|
||||
try {
|
||||
fs.unlinkSync(sqlite_file);
|
||||
} catch {
|
||||
}
|
||||
return new Promise((whohoo, doh) => {
|
||||
//const db = new sqlite.Database(sqlite_file, (e) => {
|
||||
const dbconf = {
|
||||
name: sqlite_file,
|
||||
port: undefined,
|
||||
host: undefined,
|
||||
user: undefined,
|
||||
password: undefined,
|
||||
}
|
||||
const db = new SqliteAdapter(dbconf);//, (e) => {
|
||||
// if (e) {
|
||||
// doh(e);
|
||||
// return;
|
||||
// }
|
||||
const sql = `CREATE TABLE store (
|
||||
id integer primary key autoincrement,
|
||||
owner_fingerprint text not null,
|
||||
hash char(64) not null unique,
|
||||
content text not null
|
||||
);
|
||||
`
|
||||
|
||||
console.log(sql);
|
||||
db.query(sql, (e) => {
|
||||
if (e) {
|
||||
doh(e);
|
||||
return;
|
||||
}
|
||||
whohoo(db);
|
||||
});
|
||||
// });
|
||||
});
|
||||
}
|
||||
|
||||
function wrap(s:Syncable, signer:Signer) {
|
||||
return new Promise<Envelope>((whohoo, doh) => {
|
||||
s.setSigner(signer);
|
||||
s.onwrap = async (env) => {
|
||||
if (env === undefined) {
|
||||
doh();
|
||||
return;
|
||||
}
|
||||
whohoo(env);
|
||||
}
|
||||
s.sign();
|
||||
});
|
||||
}
|
||||
|
||||
async function signData(d:string, keyStore:KeyStore) {
|
||||
const digest = await pgp.message.fromText(d);
|
||||
const opts = {
|
||||
message: digest,
|
||||
privateKeys: [keyStore.getPrivateKey()],
|
||||
detached: true,
|
||||
};
|
||||
const signature = await pgp.sign(opts);
|
||||
return {
|
||||
data: signature.signature,
|
||||
engine: 'pgp',
|
||||
algo: 'sha256',
|
||||
digest: d,
|
||||
};
|
||||
}
|
||||
|
||||
describe('server', async () => {
|
||||
await it('put_client_then_retrieve', async () => {
|
||||
const keystore = await createKeystore();
|
||||
|
||||
const signer = new PGPSigner(keystore);
|
||||
|
||||
const digest = 'deadbeef';
|
||||
const s = new Syncable(digest, {
|
||||
bar: 'baz',
|
||||
});
|
||||
|
||||
const db = await createDatabase(__dirname + '/db.one.sqlite');
|
||||
|
||||
let env = await wrap(s, signer);
|
||||
let j = env.toJSON();
|
||||
const content = await handlers.handleClientMergePut(j, db, digest, keystore, signer);
|
||||
assert(content); // true-ish
|
||||
|
||||
let v = await handlers.handleNoMergeGet(db, digest, keystore);
|
||||
if (v === undefined) {
|
||||
db.close();
|
||||
assert.fail('');
|
||||
}
|
||||
|
||||
v = await handlers.handleClientMergeGet(db, digest, keystore);
|
||||
if (v === undefined) {
|
||||
db.close();
|
||||
assert.fail('');
|
||||
}
|
||||
|
||||
db.close();
|
||||
});
|
||||
|
||||
await it('client_merge', async () => {
|
||||
const keystore = await createKeystore();
|
||||
const signer = new PGPSigner(keystore);
|
||||
|
||||
const db = await createDatabase(__dirname + '/db.two.sqlite');
|
||||
|
||||
// create new, sign, wrap
|
||||
const digest = 'deadbeef';
|
||||
let s = new Syncable(digest, {
|
||||
bar: 'baz',
|
||||
});
|
||||
await wrap(s, signer)
|
||||
|
||||
// create client branch, sign, wrap, and serialize
|
||||
let update = new ArgPair('baz', 666)
|
||||
s.update([update], 'client branch');
|
||||
let env = await wrap(s, signer)
|
||||
const j_client = env.toJSON();
|
||||
|
||||
// create server branch, sign, wrap, and serialize
|
||||
update = new ArgPair('baz', [1,2,3]);
|
||||
s.update([update], 'client branch');
|
||||
env = await wrap(s, signer)
|
||||
const j_server = env.toJSON();
|
||||
|
||||
assert.notDeepEqual(j_client, j_server);
|
||||
|
||||
let v = await handlers.handleClientMergePut(j_server, db, digest, keystore, signer);
|
||||
assert(v); // true-ish
|
||||
|
||||
v = await handlers.handleClientMergePut(j_client, db, digest, keystore, signer);
|
||||
assert(v); // true-ish
|
||||
|
||||
const j = await handlers.handleClientMergeGet(db, digest, keystore);
|
||||
|
||||
env = Envelope.fromJSON(j);
|
||||
s = env.unwrap();
|
||||
|
||||
db.close();
|
||||
});
|
||||
|
||||
await it('server_merge', async () => {
|
||||
const keystore = await createKeystore();
|
||||
const signer = new PGPSigner(keystore);
|
||||
|
||||
const db = await createDatabase(__dirname + '/db.three.sqlite');
|
||||
|
||||
const digest = 'deadbeef';
|
||||
let s = new Syncable(digest, {
|
||||
bar: 'baz',
|
||||
});
|
||||
let env = await wrap(s, signer)
|
||||
let j:any = env.toJSON();
|
||||
|
||||
let v = await handlers.handleClientMergePut(j, db, digest, keystore, signer);
|
||||
assert(v); // true-ish
|
||||
|
||||
j = await handlers.handleNoMergeGet(db, digest, keystore);
|
||||
assert(v); // true-ish
|
||||
|
||||
let o = JSON.parse(j);
|
||||
o.bar = 'xyzzy';
|
||||
j = JSON.stringify(o);
|
||||
|
||||
let signMaterial = await handlers.handleServerMergePost(j, db, digest, keystore, signer);
|
||||
assert(signMaterial)
|
||||
|
||||
env = Envelope.fromJSON(signMaterial);
|
||||
const w = env.unwrap();
|
||||
|
||||
console.log('jjjj', w, env);
|
||||
|
||||
const signedData = await signData(w.m.signature.digest, keystore);
|
||||
|
||||
o = {
|
||||
'm': env,
|
||||
's': signedData,
|
||||
}
|
||||
j = JSON.stringify(o);
|
||||
|
||||
v = await handlers.handleServerMergePut(j, db, digest, keystore, signer);
|
||||
assert(v);
|
||||
|
||||
j = await handlers.handleNoMergeGet(db, digest, keystore);
|
||||
assert(j); // true-ish
|
||||
o = JSON.parse(j);
|
||||
console.log(o);
|
||||
|
||||
db.close();
|
||||
});
|
||||
|
||||
await it('server_merge', async () => {
|
||||
const keystore = await createKeystore();
|
||||
const signer = new PGPSigner(keystore);
|
||||
|
||||
const db = await createDatabase(__dirname + '/db.three.sqlite');
|
||||
|
||||
const digest = 'deadbeef';
|
||||
let s = new Syncable(digest, {
|
||||
bar: 'baz',
|
||||
});
|
||||
let env = await wrap(s, signer)
|
||||
let j:any = env.toJSON();
|
||||
|
||||
let v = await handlers.handleClientMergePut(j, db, digest, keystore, signer);
|
||||
assert(v); // true-ish
|
||||
|
||||
j = await handlers.handleNoMergeGet(db, digest, keystore);
|
||||
assert(v); // true-ish
|
||||
|
||||
let o = JSON.parse(j);
|
||||
o.bar = 'xyzzy';
|
||||
j = JSON.stringify(o);
|
||||
|
||||
let signMaterial = await handlers.handleServerMergePost(j, db, digest, keystore, signer);
|
||||
assert(signMaterial)
|
||||
|
||||
env = Envelope.fromJSON(signMaterial);
|
||||
|
||||
console.log('envvvv', env);
|
||||
|
||||
const signedData = await signData(env.o['digest'], keystore);
|
||||
console.log('signed', signedData);
|
||||
|
||||
o = {
|
||||
'm': env,
|
||||
's': signedData,
|
||||
}
|
||||
j = JSON.stringify(o);
|
||||
console.log(j);
|
||||
|
||||
v = await handlers.handleServerMergePut(j, db, digest, keystore, signer);
|
||||
assert(v);
|
||||
|
||||
j = await handlers.handleNoMergeGet(db, digest, keystore);
|
||||
assert(j); // true-ish
|
||||
o = JSON.parse(j);
|
||||
console.log(o);
|
||||
|
||||
db.close();
|
||||
});
|
||||
|
||||
|
||||
|
||||
// await it('server_merge_empty', async () => {
|
||||
// const keystore = await createKeystore();
|
||||
// const signer = new PGPSigner(keystore);
|
||||
//
|
||||
// const db = await createDatabase(__dirname + '/db.three.sqlite');
|
||||
//
|
||||
// const digest = '0xdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef';
|
||||
// let o:any = {
|
||||
// foo: 'bar',
|
||||
// xyzzy: 42,
|
||||
// }
|
||||
// let j:any = JSON.stringify(o);
|
||||
//
|
||||
// let signMaterial = await handlers.handleServerMergePost(j, db, digest, keystore, signer);
|
||||
// assert(signMaterial)
|
||||
//
|
||||
// const env = Envelope.fromJSON(signMaterial);
|
||||
//
|
||||
// console.log('envvvv', env);
|
||||
//
|
||||
// const signedData = await signData(env.o['digest'], keystore);
|
||||
// console.log('signed', signedData);
|
||||
//
|
||||
// o = {
|
||||
// 'm': env,
|
||||
// 's': signedData,
|
||||
// }
|
||||
// j = JSON.stringify(o);
|
||||
// console.log(j);
|
||||
//
|
||||
// let v = await handlers.handleServerMergePut(j, db, digest, keystore, signer);
|
||||
// assert(v);
|
||||
//
|
||||
// j = await handlers.handleNoMergeGet(db, digest, keystore);
|
||||
// assert(j); // true-ish
|
||||
// o = JSON.parse(j);
|
||||
// console.log(o);
|
||||
//
|
||||
// db.close();
|
||||
// });
|
||||
});
|
||||
|
24
apps/cic-meta/tsconfig.json
Normal file
24
apps/cic-meta/tsconfig.json
Normal file
@ -0,0 +1,24 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"baseUrl": ".",
|
||||
"outDir": "./dist.browser",
|
||||
"target": "es5",
|
||||
"module": "commonjs",
|
||||
"moduleResolution": "node",
|
||||
"lib": ["es2016", "dom", "es5"],
|
||||
"esModuleInterop": true,
|
||||
"allowJs": true,
|
||||
"resolveJsonModule": true
|
||||
},
|
||||
"exclude": [
|
||||
"node_modules",
|
||||
"dist",
|
||||
"scripts",
|
||||
"tests"
|
||||
],
|
||||
"include": [
|
||||
"src/**/*",
|
||||
"scripts/server/*",
|
||||
"index.ts"
|
||||
]
|
||||
}
|
24
apps/cic-meta/webpack.config.js
Normal file
24
apps/cic-meta/webpack.config.js
Normal file
@ -0,0 +1,24 @@
|
||||
var webpack = require('webpack');
|
||||
const path = require('path');
|
||||
|
||||
module.exports = {
|
||||
entry: {
|
||||
index: './dist/index.js',
|
||||
},
|
||||
output: {
|
||||
path: path.resolve(__dirname, 'dist-web'),
|
||||
filename: 'cic-meta.web.js',
|
||||
library: 'cicMeta',
|
||||
libraryTarget: 'window'
|
||||
},
|
||||
mode: 'development',
|
||||
performance: {
|
||||
hints: false
|
||||
},
|
||||
stats: 'errors-only',
|
||||
resolve: {
|
||||
fallback: {
|
||||
"crypto": false,
|
||||
},
|
||||
},
|
||||
};
|
Loading…
Reference in New Issue
Block a user