Skip to content

Commit

Permalink
wip: finished off last changes for raw sign but need to test
Browse files Browse the repository at this point in the history
  • Loading branch information
rh0delta committed Aug 22, 2024
1 parent c7d3584 commit aa8102a
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 19 deletions.
17 changes: 15 additions & 2 deletions src/signing/command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ import Entropy from "@entropyxyz/sdk"
import { u8aToHex } from '@polkadot/util'
import { BaseCommand } from "../common/base-command";
import { print } from "../common/utils";
import { filePathInputQuestions, getMsgFromInputOrFile, getMsgFromUser, interactionChoiceQuestions, messageActionQuestions, rawSign, signWithAdapters, userInputQuestions } from "./utils";
import { getMsgFromInputOrFile, getMsgFromUser, interactionChoiceQuestions, rawSign, rawSignParamsQuestions, signWithAdapters } from "./utils";
import { SignResult } from "./types";
import { FLOW_CONTEXT } from "./constants";
import { readFileSync } from "node:fs";

export class SigningCommand extends BaseCommand {
constructor (entropy: Entropy, endpoint: string) {
Expand Down Expand Up @@ -56,7 +57,19 @@ export class SigningCommand extends BaseCommand {
const { interactionChoice } = await inquirer.prompt(interactionChoiceQuestions)
switch (interactionChoice) {
case 'Raw Sign': {
const msg = await getMsgFromUser(inquirer)
const { msg, msgPath } = await getMsgFromUser(inquirer)
const { hashingAlgorithm, auxiliaryDataFile } = await inquirer.prompt(rawSignParamsQuestions)
let hash = hashingAlgorithm
const auxiliaryData = JSON.parse(readFileSync(auxiliaryDataFile).toString())
if (JSON.parse(hashingAlgorithm)) {
hash = JSON.parse(hashingAlgorithm)
}

const { signature, verifyingKey } = await this.rawSignMessage({ msg, msgPath, hashingAlgorithm: hash, auxiliaryData })
print('msg to be signed:', msg)
print('verifying key:', verifyingKey)
print('signature:', signature)
return
}
case 'Sign With Adapter': {
const { msg, msgPath } = await getMsgFromUser(inquirer)
Expand Down
39 changes: 22 additions & 17 deletions src/signing/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,29 +44,34 @@ export const auxiliaryDataQuestions = [{
message: SIGNING_CONTENT.auxiliaryDataInput.message,
}]

export const rawSignParamsQuestions = [
...hashingAlgorithmQuestions,
...auxiliaryDataQuestions
]

export async function getMsgFromUser (inquirer) {
let msg: string
let msgPath: string
const { messageAction } = await inquirer.prompt(messageActionQuestions)
switch (messageAction) {
case 'Text Input': {
const { userInput } = await inquirer.prompt(userInputQuestions)
msg = userInput
break
}
case 'From a File': {
const { pathToFile } = await inquirer.prompt(filePathInputQuestions)
// TODO: relative/absolute path? encoding?
msgPath = pathToFile
break
}
default: {
const error = new Error('SigningError: Unsupported User Input Action')
this.logger.error('Error signing with adapter', error)
return
}
case 'Text Input': {
const { userInput } = await inquirer.prompt(userInputQuestions)
msg = userInput
break
}
case 'From a File': {
const { pathToFile } = await inquirer.prompt(filePathInputQuestions)
// TODO: relative/absolute path? encoding?
msgPath = pathToFile
break
}
default: {
const error = new Error('SigningError: Unsupported User Input Action')
this.logger.error('Error signing with adapter', error)
return
}
}
return {msg, msgPath};
return { msg, msgPath };
}

export function getMsgFromInputOrFile (msg?: string, msgPath?: string) {
Expand Down

0 comments on commit aa8102a

Please sign in to comment.