Skip to content

Commit

Permalink
Merge pull request #2 from jmagan/development
Browse files Browse the repository at this point in the history
feat: mockWalletSignatures cli
  • Loading branch information
jmagan authored Dec 1, 2022
2 parents b67172a + 872945c commit ba79a97
Show file tree
Hide file tree
Showing 3 changed files with 236 additions and 2 deletions.
118 changes: 118 additions & 0 deletions mockWalletSignatures.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
const prompt = require('prompt')
const {
createCOSEKey,
createRewardAddress,
createFakePrivateKey,
createCOSESign1Signature
} = require('./test/helpers/auth')
prompt.start()

prompt.message = ''
prompt.delimiter = ':'

const host = 'HOST'

const getPayload = async () => {
const actionPrompt = await prompt.get({
name: 'action',
description: 'Action',
message: 'Valid inputs: S, R or L',
pattern: '[SRLsrl]'
})

switch (actionPrompt.action) {
case 'S':
case 's':
console.log(`\u{1F916} Creating signup payload.`)
const signupPrompt = await prompt.get([
{
name: 'name',
description: 'User name'
},
{
name: 'email',
description: 'User email'
}
])

return {
host,
action: 'Sign up',
name: signupPrompt.name,
email: signupPrompt.email
}
case 'R':
case 'r':
console.log(`\u{1F916} Creating reset payload.`)
return {
host,
action: 'Reset'
}
case 'L':
case 'l':
console.log(`\u{1F916} Creating login payload.`)
const loginPrompt = await prompt.get([
{
name: 'email',
description: 'User email'
}
])
return {
host,
action: 'Login',
email: loginPrompt.email
}
}
}

const main = async () => {
console.log(
`\u{1F916} Please, select the action for the payload (S: Signup, R: Reset, L: Login)`
)

const payload = await getPayload()

console.log(
`\u{1F916} Choose a number between 0 and 254. Each number represents a unique address and private key. For example in the sample data, the number 0 is the wallet for admin and the number 1 for the simple user. `
)
const walletNumberPrompt = await prompt.get({
name: 'walletNumber',
description: 'Wallet number',
type: 'integer',
minimum: 0,
maximum: 254,
message: 'Integer between 0 and 254'
})

const walletNumber = walletNumberPrompt.walletNumber

const privateKey = createFakePrivateKey(walletNumber)
const stakeAddress = createRewardAddress(privateKey)
const coseKey = createCOSEKey(privateKey)
const adminResetCoseSign1 = createCOSESign1Signature(
payload,
stakeAddress,
privateKey
)

console.log(`\u{1F916} Generating wallet address, key and signature.\n`)

console.log(
`\u{1F4EA} Address: \x1b[34m${stakeAddress
.to_address()
.to_bech32()}\x1b[0m\n`
)

console.log(
`\u{1F511} Key: \x1b[36m${Buffer.from(coseKey.to_bytes()).toString(
'hex'
)} \x1b[0m\n`
)
console.log(
`\u{1F4DD} Signature: \x1b[35m${Buffer.from(
adminResetCoseSign1.to_bytes()
).toString('hex')} \x1b[0m`
)
}

main()
119 changes: 117 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@
"nyc": "^15.1.0",
"prettier": "^2.7.1",
"prettier-eslint": "^12.0.0",
"prompt": "^1.3.0",
"remark-cli": "^9.0.0"
},
"keywords": [
Expand Down

0 comments on commit ba79a97

Please sign in to comment.