Skip to content

Commit

Permalink
Merge pull request #3 from viksit/main
Browse files Browse the repository at this point in the history
Enhance CLI functionality by adding support for extracting a public key from an existing JWK file
  • Loading branch information
twilson63 authored Jan 31, 2025
2 parents 2f49b24 + 223d461 commit 9cae4d1
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 3 deletions.
13 changes: 11 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
# create arweave wallet file
# Create arweave wallet file

A command line program that creates a wallet json file.
A command line program that supports the following:
- creates a new arweave wallet json and prints to stdout
- parses an existing wallet json file and returns the pubkey

## Usage

```bash
node index.js
node index.js pubkey -f <path-to-wallet.json>
```
37 changes: 36 additions & 1 deletion index.js
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,3 +1,38 @@
#!/usr/bin/env node

require('arweave').init({}).wallets.generate().then(JSON.stringify).then(console.log.bind(console))
const fs = require('fs');
const { init } = require('arweave');

const arweave = init({});
const args = process.argv.slice(2);

if (args.length > 0) {
if (args[0] === 'pubkey') {
if (args[1] !== '-f' || !args[2]) {
console.error('Error: Please specify a wallet file with "-f <path-to-wallet.json>".');
process.exit(1);
}

// Read and parse the JWK file, then get its address
fs.promises.readFile(args[2], 'utf8')
.then(JSON.parse)
.then(jwk => arweave.wallets.jwkToAddress(jwk))
.then(console.log)
.catch(error => {
console.error('Error:', error.message);
process.exit(1);
});
} else {
console.error('Error: Unknown command. Use "pubkey -f <path-to-wallet.json>" or run without arguments to generate a new wallet.');
process.exit(1);
}
} else {
// Default behavior: Generate a new wallet
arweave.wallets.generate()
.then(JSON.stringify)
.then(console.log)
.catch(error => {
console.error('Error:', error.message);
process.exit(1);
});
}

0 comments on commit 9cae4d1

Please sign in to comment.