Skip to content

Instantly share code, notes, and snippets.

@rumkin
Created May 6, 2020 16:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rumkin/51bc6a346b40e6a303d1e1eba1f38199 to your computer and use it in GitHub Desktop.
Save rumkin/51bc6a346b40e6a303d1e1eba1f38199 to your computer and use it in GitHub Desktop.
Utils for LibP2P example
// Usage is node exec.js app.js
// app.js should export default function
import path from 'path'
async function execute(filename) {
const {default: main} = await import(
path.resolve(filename)
)
return main({
argv: process.argv.slice(3),
parsedArgv: process.argv.slice(0, 3),
})
}
execute(process.argv[2])
.catch(err => {
console.error(err)
return 1
})
.then((code = 0) => process.exit(code))
import PeerId from 'peer-id'
PeerId.create()
async function main() {
const peer = await PeerId.create({
keyType: 'secp256k1',
})
console.log(JSON.stringify(
peer.toJSON(),
null,
4
))
}
main()
.catch(err => {
console.error(err)
return 1
})
.then((code = 0) => process.exit(code))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment