Correct phone key generation

This commit is contained in:
nolash 2021-04-08 16:13:32 +02:00
parent a498835d08
commit 876f73b792
Signed by untrusted user who does not match committer: lash
GPG Key ID: 21D2E7BB88C2A746
7 changed files with 2134 additions and 28 deletions

View File

@ -1,6 +1,6 @@
{ {
"name": "cic-client-meta", "name": "cic-client-meta",
"version": "0.0.7-alpha.3", "version": "0.0.7-alpha.4",
"description": "Signed CRDT metadata graphs for the CIC network", "description": "Signed CRDT metadata graphs for the CIC network",
"main": "dist/index.js", "main": "dist/index.js",
"types": "dist/index.d.ts", "types": "dist/index.d.ts",

View File

@ -1,12 +1,12 @@
import { ArgPair, Syncable } from '../sync'; import { ArgPair, Syncable } from '../sync';
import { Addressable, addressToBytes, bytesToHex, toKey } from '../digest'; import { Addressable, mergeKey } from '../digest';
class Phone extends Syncable implements Addressable { class Phone extends Syncable implements Addressable {
address: string address: string
value: number value: number
constructor(address:string, v:number) { constructor(address:string, v:string) {
const o = { const o = {
msisdn: v, msisdn: v,
} }
@ -17,8 +17,8 @@ class Phone extends Syncable implements Addressable {
}); });
} }
public static async toKey(msisdn:number) { public static async toKey(msisdn:string) {
return await toKey(msisdn.toString(), ':cic.phone'); return await mergeKey(Buffer.from(msisdn), Buffer.from(':cic.phone'));
} }
public key(): string { public key(): string {

View File

@ -61,6 +61,7 @@ function addressToBytes(s:string) {
export { export {
toKey, toKey,
toAddressKey, toAddressKey,
mergeKey,
bytesToHex, bytesToHex,
addressToBytes, addressToBytes,
Addressable, Addressable,

View File

@ -3,6 +3,7 @@ const path = require('path');
const http = require('http'); const http = require('http');
const cic = require('cic-client-meta'); const cic = require('cic-client-meta');
const vcfp = require('vcard-parser');
//const conf = JSON.parse(fs.readFileSync('./cic.conf')); //const conf = JSON.parse(fs.readFileSync('./cic.conf'));
@ -40,15 +41,18 @@ function sendit(uid, envelope) {
req.end(); req.end();
} }
function doOne(keystore, filePath) { function doOne(keystore, filePath, address) {
const signer = new cic.PGPSigner(keystore); const signer = new cic.PGPSigner(keystore);
const parts = path.basename(filePath).split('.');
const ethereum_address = path.basename(parts[0]);
cic.Phone.toKey('0x' + ethereum_address).then((uid) => { const j = JSON.parse(fs.readFileSync(filePath).toString());
const b = Buffer.from(j['vcard'], 'base64');
const s = b.toString();
const o = vcfp.parse(s);
const phone = o.tel[0].value;
cic.Phone.toKey(address, phone).then((uid) => {
const o = fs.readFileSync(filePath, 'utf-8'); const o = fs.readFileSync(filePath, 'utf-8');
//const o = JSON.parse(d);
//console.log(o);
fs.unlinkSync(filePath); fs.unlinkSync(filePath);
const s = new cic.Syncable(uid, o); const s = new cic.Syncable(uid, o);
@ -77,7 +81,9 @@ new cic.PGPKeyStore(
const batchSize = 16; const batchSize = 16;
const batchDelay = 1000; const batchDelay = 1000;
const total = parseInt(process.argv[3]); const total = parseInt(process.argv[3]);
const workDir = path.join(process.argv[2], 'phone/meta'); const dataDir = process.argv[2];
const workDir = path.join(dataDir, 'phone/meta');
const userDir = path.join(dataDir, 'new');
let count = 0; let count = 0;
let batchCount = 0; let batchCount = 0;
@ -90,7 +96,7 @@ function importMetaPhone(keystore) {
err, files = fs.readdirSync(workDir); err, files = fs.readdirSync(workDir);
} catch { } catch {
console.error('source directory not yet ready', workDir); console.error('source directory not yet ready', workDir);
setTimeout(importMeta, batchDelay, keystore); setTimeout(importMetaPhone, batchDelay, keystore);
return; return;
} }
let limit = batchSize; let limit = batchSize;
@ -103,7 +109,16 @@ function importMetaPhone(keystore) {
console.debug('skipping file', file); console.debug('skipping file', file);
} }
const filePath = path.join(workDir, file); const filePath = path.join(workDir, file);
doOne(keystore, filePath);
const address = fs.readFileSync(filePath).toString().substring(2).toUpperCase();
const metaFilePath = path.join(
userDir,
address.substring(0, 2),
address.substring(2, 4),
address + '.json',
);
doOne(keystore, metaFilePath, address);
count++; count++;
batchCount++; batchCount++;
if (batchCount == batchSize) { if (batchCount == batchSize) {

View File

@ -24,6 +24,7 @@ from cic_types.models.person import (
get_contact_data_from_vcard, get_contact_data_from_vcard,
) )
from chainlib.eth.address import to_checksum_address from chainlib.eth.address import to_checksum_address
import phonenumbers
logging.basicConfig(level=logging.WARNING) logging.basicConfig(level=logging.WARNING)
logg = logging.getLogger() logg = logging.getLogger()
@ -103,8 +104,9 @@ def genDate():
def genPhone(): def genPhone():
#return fake.msisdn() phone_str = '+254' + str(random.randint(100000000, 999999999))
return '+254' + str(random.randint(100000000, 999999999)) phone_object = phonenumbers.parse(phone_str)
return phonenumbers.format_number(phone_object, phonenumbers.PhoneNumberFormat.E164)
def genPersonal(phone): def genPersonal(phone):

View File

@ -179,6 +179,7 @@ if __name__ == '__main__':
phone_object = phonenumbers.parse(u.tel) phone_object = phonenumbers.parse(u.tel)
phone = phonenumbers.format_number(phone_object, phonenumbers.PhoneNumberFormat.E164) phone = phonenumbers.format_number(phone_object, phonenumbers.PhoneNumberFormat.E164)
logg.debug('>>>>> Using phone {}'.format(phone))
meta_phone_key = generate_metadata_pointer(phone.encode('utf-8'), ':cic.phone') meta_phone_key = generate_metadata_pointer(phone.encode('utf-8'), ':cic.phone')
meta_phone_filepath = os.path.join(phone_dir, 'meta', meta_phone_key) meta_phone_filepath = os.path.join(phone_dir, 'meta', meta_phone_key)

File diff suppressed because it is too large Load Diff