-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from viksit/main
Enhance CLI functionality by adding support for extracting a public key from an existing JWK file
- Loading branch information
Showing
2 changed files
with
47 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}); | ||
} |