Skip to content

Commit

Permalink
Fix env files and add signing CLI command to Flux package (#1260)
Browse files Browse the repository at this point in the history
* Fix template env files for production

* Add signing function to flux package

* Update README
  • Loading branch information
forgetso authored Jun 2, 2024
1 parent ab5efce commit adb2894
Show file tree
Hide file tree
Showing 10 changed files with 137 additions and 79 deletions.
9 changes: 9 additions & 0 deletions dev/flux/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -159,3 +159,12 @@ Use this command to get the logs of the app from a specific node.
# get logs of a specific dapp and save them to a file. The log format will be `host | log` with the logs separated by a newline
npx flux getLogs --app <app_name> --file <file_name>
```
#### Sign a Message
Use this command to sign a message with the private key of the node.
```bash
# sign a message
npx flux sign --msg <message>
```
2 changes: 1 addition & 1 deletion dev/flux/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
"qs": "^6.11.2",
"socket.io-client": "^4.7.4",
"varuint-bitcoin": "^1.1.2",
"yargs": "^17.5.1",
"yargs": "^17.7.2",
"yargs-parser": "^21.0.1",
"zod": "^3.22.4"
},
Expand Down
1 change: 1 addition & 0 deletions dev/flux/src/commands/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,5 @@ export { default as commandAuth } from './auth.js'
export { default as commandGetDapps } from './getDapps.js'
export { default as commandGetDapp } from './getDapp.js'
export { default as commandLogs } from './logs.js'
export { default as commandSign } from './sign.js'
export { default as commandTerminal } from './terminal.js'
59 changes: 59 additions & 0 deletions dev/flux/src/commands/sign.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
// Copyright 2021-2024 Prosopo (UK) Ltd.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
import * as z from 'zod'
import { ArgumentsCamelCase, Argv } from 'yargs'
import { Keypair } from '@polkadot/util-crypto/types'
import { LogLevel, Logger, getLogger } from '@prosopo/common'
import { base58Decode, base64Encode } from '@polkadot/util-crypto'
import { sign, wifToPrivateKey } from '../lib/sep256k1Sign.js'
import { u8aToHex } from '@polkadot/util'
const msgSpec = z.string()

export default (cmdArgs?: { logger?: Logger }) => {
const logger = cmdArgs?.logger || getLogger(LogLevel.enum.info, 'flux.cli.auth')

return {
command: 'sign',
describe: 'Sign a message with a private key',
builder: (yargs: Argv) =>
yargs.option('msg', {
type: 'string',
demandOption: true,
desc: 'Message to sign',
} as const),
handler: async (argv: ArgumentsCamelCase) => {
const secretKey = wifToPrivateKey(process.env.PROSOPO_ZELCORE_PRIVATE_KEY || '')
const publicKey: Uint8Array = base58Decode(process.env.PROSOPO_ZELCORE_PUBLIC_KEY || '')
const keypair: Keypair = { secretKey, publicKey }
const message = msgSpec.parse(argv.msg)
if (message.length === 0) {
console.error('No message provided')
process.exit()
}
sign(message, keypair)
.then((sig) => {
const hexSig = u8aToHex(sig)
logger.info(`Hex Signature : ${hexSig}`)
logger.info(`Public Key: ${publicKey}`)
logger.info(`Base64 Signature: ${base64Encode(hexSig)}`)
process.exit()
})
.catch((error) => {
console.error(error)
process.exit()
})
},
middlewares: [],
}
}
2 changes: 2 additions & 0 deletions dev/flux/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {
commandGetDapps,
commandLogs,
commandRedeploy,
commandSign,
commandTerminal,
} from './commands/index.js'
import { hideBin } from 'yargs/helpers'
Expand All @@ -34,6 +35,7 @@ export default async function processArgs(args: string[]) {
.command(commandGetDapp({ logger }))
.command(commandGetDapps({ logger }))
.command(commandLogs({ logger }))
.command(commandSign({ logger }))
.command(commandTerminal({ logger }))
.parse()
}
Expand Down
4 changes: 1 addition & 3 deletions dev/scripts/env.production
Original file line number Diff line number Diff line change
@@ -1,4 +1,2 @@
PROSOPO_SUBSTRATE_ENDPOINT=wss://rococo-contracts-rpc.polkadot.io:443
PROSOPO_CONTRACT_ADDRESS=5HiVWQhJrysNcFNEWf2crArKht16zrhro3FcekVWocyQjx5u
PROSOPO_DEFAULT_ENVIRONMENT=production
PROSOPO_DEFAULT_NETWORK=rococo
PROSOPO_DEFAULT_NETWORK=astar
4 changes: 4 additions & 0 deletions dev/scripts/env.rococo
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
PROSOPO_SUBSTRATE_ENDPOINT=wss://rococo-contracts-rpc.polkadot.io:443
PROSOPO_CONTRACT_ADDRESS=5HiVWQhJrysNcFNEWf2crArKht16zrhro3FcekVWocyQjx5u
PROSOPO_DEFAULT_ENVIRONMENT=production
PROSOPO_DEFAULT_NETWORK=rococo
131 changes: 58 additions & 73 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion packages/provider/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
"@types/node": "^18.0.6",
"@types/sinon": "^10.0.15",
"@types/yargs": "^17.0.10",
"c8": "^7.11.3",
"c8": "^9.1.0",
"chai": "^4.3.6",
"chai-as-promised": "^7.1.1",
"dotenv": "^16.0.1",
Expand Down
2 changes: 1 addition & 1 deletion protocol/dev/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"glob": "^10.0.0",
"path": "^0.12.7",
"process": "^0.11.10",
"yargs": "^17.5.1",
"yargs": "^17.7.2",
"yargs-parser": "^21.0.1"
},
"devDependencies": {
Expand Down

0 comments on commit adb2894

Please sign in to comment.