Correct phone key generation
This commit is contained in:
parent
a498835d08
commit
876f73b792
@ -1,6 +1,6 @@
|
||||
{
|
||||
"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",
|
||||
"main": "dist/index.js",
|
||||
"types": "dist/index.d.ts",
|
||||
|
@ -1,12 +1,12 @@
|
||||
import { ArgPair, Syncable } from '../sync';
|
||||
import { Addressable, addressToBytes, bytesToHex, toKey } from '../digest';
|
||||
import { Addressable, mergeKey } from '../digest';
|
||||
|
||||
class Phone extends Syncable implements Addressable {
|
||||
|
||||
address: string
|
||||
value: number
|
||||
|
||||
constructor(address:string, v:number) {
|
||||
constructor(address:string, v:string) {
|
||||
const o = {
|
||||
msisdn: v,
|
||||
}
|
||||
@ -17,8 +17,8 @@ class Phone extends Syncable implements Addressable {
|
||||
});
|
||||
}
|
||||
|
||||
public static async toKey(msisdn:number) {
|
||||
return await toKey(msisdn.toString(), ':cic.phone');
|
||||
public static async toKey(msisdn:string) {
|
||||
return await mergeKey(Buffer.from(msisdn), Buffer.from(':cic.phone'));
|
||||
}
|
||||
|
||||
public key(): string {
|
||||
|
@ -61,6 +61,7 @@ function addressToBytes(s:string) {
|
||||
export {
|
||||
toKey,
|
||||
toAddressKey,
|
||||
mergeKey,
|
||||
bytesToHex,
|
||||
addressToBytes,
|
||||
Addressable,
|
||||
|
@ -3,6 +3,7 @@ const path = require('path');
|
||||
const http = require('http');
|
||||
|
||||
const cic = require('cic-client-meta');
|
||||
const vcfp = require('vcard-parser');
|
||||
|
||||
//const conf = JSON.parse(fs.readFileSync('./cic.conf'));
|
||||
|
||||
@ -40,15 +41,18 @@ function sendit(uid, envelope) {
|
||||
req.end();
|
||||
}
|
||||
|
||||
function doOne(keystore, filePath) {
|
||||
function doOne(keystore, filePath, address) {
|
||||
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 = JSON.parse(d);
|
||||
//console.log(o);
|
||||
fs.unlinkSync(filePath);
|
||||
|
||||
const s = new cic.Syncable(uid, o);
|
||||
@ -77,7 +81,9 @@ new cic.PGPKeyStore(
|
||||
const batchSize = 16;
|
||||
const batchDelay = 1000;
|
||||
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 batchCount = 0;
|
||||
|
||||
@ -90,7 +96,7 @@ function importMetaPhone(keystore) {
|
||||
err, files = fs.readdirSync(workDir);
|
||||
} catch {
|
||||
console.error('source directory not yet ready', workDir);
|
||||
setTimeout(importMeta, batchDelay, keystore);
|
||||
setTimeout(importMetaPhone, batchDelay, keystore);
|
||||
return;
|
||||
}
|
||||
let limit = batchSize;
|
||||
@ -103,7 +109,16 @@ function importMetaPhone(keystore) {
|
||||
console.debug('skipping file', 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++;
|
||||
batchCount++;
|
||||
if (batchCount == batchSize) {
|
||||
|
@ -24,6 +24,7 @@ from cic_types.models.person import (
|
||||
get_contact_data_from_vcard,
|
||||
)
|
||||
from chainlib.eth.address import to_checksum_address
|
||||
import phonenumbers
|
||||
|
||||
logging.basicConfig(level=logging.WARNING)
|
||||
logg = logging.getLogger()
|
||||
@ -103,8 +104,9 @@ def genDate():
|
||||
|
||||
|
||||
def genPhone():
|
||||
#return fake.msisdn()
|
||||
return '+254' + str(random.randint(100000000, 999999999))
|
||||
phone_str = '+254' + str(random.randint(100000000, 999999999))
|
||||
phone_object = phonenumbers.parse(phone_str)
|
||||
return phonenumbers.format_number(phone_object, phonenumbers.PhoneNumberFormat.E164)
|
||||
|
||||
|
||||
def genPersonal(phone):
|
||||
|
@ -179,6 +179,7 @@ if __name__ == '__main__':
|
||||
|
||||
phone_object = phonenumbers.parse(u.tel)
|
||||
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_filepath = os.path.join(phone_dir, 'meta', meta_phone_key)
|
||||
|
||||
|
2111
apps/contract-migration/scripts/package-lock.json
generated
2111
apps/contract-migration/scripts/package-lock.json
generated
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user