Skip to content

Commit d1b96f6

Browse files
committed
create Wallet CLI updates
wallet changes
1 parent 4237c0d commit d1b96f6

File tree

5 files changed

+43
-30
lines changed

5 files changed

+43
-30
lines changed

components/cryptoID/index.js

Lines changed: 22 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -48,58 +48,55 @@ export class CryptoID {
4848
return this;
4949
}
5050
async initializeKeypairs() {
51-
if (isBuffer(this.signatureKeypair)) {
51+
if (await this.cipherSuite.signature.isKeypairInitialized(this.signatureKeypair) === false) {
5252
this.signatureKeypair = await this.cipherSuite.signature.initializeKeypair(this.signatureKeypair);
5353
}
54-
if (isBuffer(this.keyExchangeKeypair)) {
54+
if (await this.cipherSuite.keyExchange.isKeypairInitialized(this.keyExchangeKeypair) === false) {
5555
this.keyExchangeKeypair = await this.cipherSuite.keyExchange.initializeKeypair(this.keyExchangeKeypair);
5656
}
5757
}
58-
async importKeypairs(config) {
58+
async importKeypairs(core) {
5959
const {
60-
version,
6160
signatureKeypair,
6261
keyExchangeKeypair,
63-
cipherSuite
64-
} = config;
62+
} = core;
6563
if (signatureKeypair) {
6664
this.signatureKeypair = signatureKeypair;
6765
}
6866
if (keyExchangeKeypair) {
6967
this.keyExchangeKeypair = keyExchangeKeypair;
7068
}
71-
if (version) {
72-
this.version = version;
73-
}
74-
if (cipherSuite?.id) {
75-
this.cipherSuiteId = cipherSuite.id;
76-
}
7769
await this.initializeKeypairs();
70+
return this;
7871
}
7972
async generate(options) {
8073
this.signatureKeypair = await this.cipherSuite.signature.signatureKeypair();
8174
this.keyExchangeKeypair = await this.cipherSuite.keyExchange.keyExchangeKeypair();
82-
console.log('KEY EXCHANGE', this.keyExchangeKeypair);
75+
// console.log('KEY EXCHANGE', this.keyExchangeKeypair);
8376
}
8477
async importFromBinary(data, encryptionKey) {
8578
const password = (isString(encryptionKey)) ? await this.cipherSuite.hash.hash256(Buffer.from(encryptionKey)) : encryptionKey;
86-
const decodedData = (password) ? await this.decryptBinary(data, password) : await decode(data);
87-
await this.importFromObject(decodedData, password);
79+
const encodedData = decode(data);
80+
const decodedCore = (password) ? await this.decryptBinary(encodedData.core, password) : encodedData.core;
81+
encodedData.core = decodedCore;
82+
await this.importFromObject(encodedData, password);
8883
return this;
8984
}
9085
async importFromObject(decodedData, encryptionKey) {
9186
const password = (isString(encryptionKey)) ? await this.cipherSuite.hash.hash256(Buffer.from(encryptionKey)) : encryptionKey;
9287
const data = (password) ? await this.decryptBinary(decodedData.encrypted, password) : decodedData;
9388
const {
9489
version,
95-
keyExchangeKeypair,
96-
signatureKeypair,
97-
cipherSuiteId
90+
cipherID,
91+
core: {
92+
keyExchangeKeypair,
93+
signatureKeypair,
94+
},
9895
} = data;
9996
this.version = version;
10097
this.keyExchangeKeypair = keyExchangeKeypair;
10198
this.signatureKeypair = signatureKeypair;
102-
this.cipherSuiteId = cipherSuiteId;
99+
this.cipherID = cipherID;
103100
await this.initializeKeypairs();
104101
return this;
105102
}
@@ -108,7 +105,7 @@ export class CryptoID {
108105
return decode(decrypted);
109106
}
110107
async exportKeypairs() {
111-
console.log('keyExchangeKeypair', this.keyExchangeKeypair);
108+
// console.log('keyExchangeKeypair', this.keyExchangeKeypair);
112109
const keyExchangeKeypair = await this.cipherSuite.keyExchange.exportKeypair(this.keyExchangeKeypair);
113110
const signatureKeypair = await this.cipherSuite.signature.exportKeypair(this.signatureKeypair);
114111
return {
@@ -117,16 +114,14 @@ export class CryptoID {
117114
};
118115
}
119116
async exportBinary(encryptionKey) {
120-
const {
121-
version,
122-
cipherSuiteId
123-
} = this;
117+
const { version, } = this;
124118
const data = {
125119
version,
126-
cipherSuiteId,
127120
date: Date.now(),
121+
cipherID: this.cipherSuite.id,
122+
core: {}
128123
};
129-
assign(data, await this.exportKeypairs());
124+
assign(data.core, await this.exportKeypairs());
130125
const dataEncoded = await encodeStrict(data);
131126
if (encryptionKey) {
132127
const password = (isString(encryptionKey)) ? await this.cipherSuite.hash.hash256(Buffer.from(encryptionKey)) : encryptionKey;
@@ -144,9 +139,8 @@ export class CryptoID {
144139
async importFile(filePath, encryptionPassword) {
145140
const data = await readStructured(filePath);
146141
if (data) {
147-
return this.importFromObject(data, encryptionPassword);
142+
const loadedFile = await this.importFromObject(data, encryptionPassword);
148143
}
149-
console.log('Error Importing Profile', filePath);
150144
return false;
151145
}
152146
async saveToKeychain(accountName = 'profile', encryptionPassword) {

utilities/cryptography/keyExchange/kyber768_x25519.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,12 @@ async function initializeKeypair(keypair, target) {
110110
kyberKeypair
111111
};
112112
}
113+
async function isKeypairInitialized(source) {
114+
if (source.x25519Keypair && source.kyberKeypair) {
115+
return true;
116+
}
117+
return false;
118+
}
113119
async function initializeCertificateKeypair(keypair, target) {
114120
const result = await initializeKeypair(keypair, target);
115121
return result;
@@ -134,6 +140,7 @@ export const kyber768_x25519 = keyExchange({
134140
initializeCertificateKeypair,
135141
exportKeypair,
136142
initializeKeypair,
143+
isKeypairInitialized,
137144
// partial initial encryption on first packet
138145
async clientInitializeSession(source, destination) {
139146
source.x25519Keypair.sharedSecret = await x25519.getSharedSecret(source.x25519Keypair, destination.x25519Keypair);

utilities/cryptography/signature/viat.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,12 @@ export async function initializeKeypair(sourceArg) {
103103
target.sphincs = sphincs;
104104
return target;
105105
}
106+
async function isKeypairInitialized(source) {
107+
if (source.ed25519 && source.dilithium && source.sphincs) {
108+
return true;
109+
}
110+
return false;
111+
}
106112
export async function signMethod(message, source) {
107113
const signatureArray = [];
108114
const {
@@ -219,6 +225,7 @@ export const viat = signatureScheme({
219225
privateKeySize,
220226
signatureSize,
221227
seedSize,
228+
isKeypairInitialized,
222229
createKeypair,
223230
verifyMethod,
224231
signMethod,

viat/createWalletCLI.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,11 @@ program
1818
const result = await createWallet(filename, filepath, key);
1919
// console.log(await decode(await result.exportBinary()));
2020
});
21+
program.addHelpText('after', `
22+
Example Commands:
23+
./createWalletCLI.js walletFileName.bin /FILE/PATH/TO/SAVE/TO
24+
`);
2125
program.option('-v, --verbose', 'Enable verbose output');
2226
// Parse command-line arguments
2327
program.parse(process.argv);
24-
// ./createWalletCLI.js walletFileName.bin /FILE/PATH/TO/SAVE/TO
28+
// CLI COMMAND ./createWalletCLI.js walletFileName.bin /FILE/PATH/TO/SAVE/TO

viat/wallet/wallet.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,5 @@ export function wallet(config) {
1616
const source = new Wallet(config);
1717
return source;
1818
}
19-
// console.log('Wallet:', (await wallet()));
19+
// (await wallet('/Users/thomasmarchi/MEGA/Github/Network/viat/wallet.bin'));
20+
// console.log('Wallet:', (await wallet('/Users/thomasmarchi/MEGA/Github/Network/viat/wallet.bin')));

0 commit comments

Comments
 (0)