-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix env files and add signing CLI command to Flux package (#1260)
* Fix template env files for production * Add signing function to flux package * Update README
- Loading branch information
Showing
10 changed files
with
137 additions
and
79 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
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
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
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 |
---|---|---|
@@ -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: [], | ||
} | ||
} |
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
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,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 |
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 |
---|---|---|
@@ -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 |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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