Skip to content

Commit 4237c0d

Browse files
committed
Viat Wallet CLI SCRIPT
1 parent b2d026b commit 4237c0d

File tree

7 files changed

+44
-4
lines changed

7 files changed

+44
-4
lines changed

components/cryptoID/index.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import {
2020
} from '#utilities/logs/classLogMethods';
2121
import { read, readStructured, write } from '#utilities/file';
2222
import { cryptoIDVersion } from '#components/cryptoID/defaults';
23+
import path from 'node:path';
2324
import viat from '#crypto/cipherSuite/viat.js';
2425
export class CryptoID {
2526
constructor(config, optionalArg) {
@@ -107,6 +108,7 @@ export class CryptoID {
107108
return decode(decrypted);
108109
}
109110
async exportKeypairs() {
111+
console.log('keyExchangeKeypair', this.keyExchangeKeypair);
110112
const keyExchangeKeypair = await this.cipherSuite.keyExchange.exportKeypair(this.keyExchangeKeypair);
111113
const signatureKeypair = await this.cipherSuite.signature.exportKeypair(this.signatureKeypair);
112114
return {
@@ -135,7 +137,8 @@ export class CryptoID {
135137
}
136138
async saveToFile(fileName, fileLocation, encryptionPassword) {
137139
const binaryData = await this.exportBinary(encryptionPassword);
138-
const fullPath = `${fileLocation}/${fileName}`;
140+
const fullPath = path.join(fileLocation, fileName);
141+
// console.log('FILE WRITE', fullPath, binaryData, encryptionPassword);
139142
return write(fullPath, binaryData, 'binary', true);
140143
}
141144
async importFile(filePath, encryptionPassword) {
@@ -208,9 +211,9 @@ export async function cryptoID(config, optionalArg) {
208211
}
209212
export default cryptoID;
210213
// const dirname = currentPath(import.meta);
211-
const exampleCryptoIDExample = await cryptoID();
214+
// const exampleCryptoIDExample = await cryptoID();
212215
// const encryptionPasswordExample = 'password';
213-
console.log(await exampleCryptoIDExample.exportBinary('password'));
216+
// console.log(await exampleCryptoIDExample.exportBinary());
214217
// const exportedKeypairs = await exampleCryptoIDExample.exportKeypairs();
215218
// console.log(exportedKeypairs);
216219
// console.log(`Version: ${exampleProfileExample.version}`);

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
"@noble/hashes": "^1.8.0",
2121
"@universalweb/acid": "^3.0.74",
2222
"cbor-x": "^1.6.0",
23+
"commander": "^13.1.0",
2324
"electron": "latest",
2425
"hash-wasm": "^4.12.0",
2526
"ip": "^2.0.1",

pnpm-lock.yaml

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

viat/blocks/receipt.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@
33
// Then include the block's hash as part of the TX Block Hashlink
44
// Both are signed meaning they are all linked and contents can be trusted even based on the hash link alone
55
// Hash link as the ID of this block
6+
// Block Hash (TX DATA || Receipt NONCE || Receipt Meta?)

viat/blocks/transaction.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ class TransactionBlock extends Block {
1414
return this;
1515
}
1616
// Receipt Hash Link
17+
// Block Hash (TX DATA || Receipt NONCE || Receipt Meta?)
1718
async createHashLink(...blocks) {
1819
const blockHashes = await mapAsyncArray(blocks, async (item) => {
1920
return item.getHash();

viat/createWalletCLI.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#!/usr/bin/env node
2+
import { Command, program } from 'commander';
3+
import { decode } from '#utilities/serialize';
4+
import { wallet } from './wallet/wallet.js';
5+
async function createWallet(filename, filepath, key) {
6+
const walletInstance = await wallet();
7+
// console.log(filename, filepath);
8+
await walletInstance.saveToFile(filename, filepath, key);
9+
return walletInstance;
10+
}
11+
program
12+
.description('CLI VIAT WALLET SCRIPT')
13+
.argument('<filename>', 'Wallet File Name')
14+
.argument('<filepath>', 'File Directory to save the Wallet')
15+
.argument('[key]', 'File Directory to save the Wallet')
16+
.action(async (filename, filepath, key) => {
17+
// Execute the function
18+
const result = await createWallet(filename, filepath, key);
19+
// console.log(await decode(await result.exportBinary()));
20+
});
21+
program.option('-v, --verbose', 'Enable verbose output');
22+
// Parse command-line arguments
23+
program.parse(process.argv);
24+
// ./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
@@ -3,7 +3,7 @@ import { decode, encode } from '#utilities/serialize';
33
import { CryptoID } from '#components/cryptoID/index';
44
import { isBuffer } from '@universalweb/acid';
55
export class Wallet extends CryptoID {
6-
constructor(config = {}, optionalArg) {
6+
constructor(config, optionalArg) {
77
super(false);
88
return this.walletInitialize(config, optionalArg);
99
}
@@ -16,3 +16,4 @@ export function wallet(config) {
1616
const source = new Wallet(config);
1717
return source;
1818
}
19+
// console.log('Wallet:', (await wallet()));

0 commit comments

Comments
 (0)