Skip to content

Commit

Permalink
Fix file-not-found error when signing with the chel command
Browse files Browse the repository at this point in the history
  • Loading branch information
corrideat committed Feb 14, 2024
1 parent 0051dbf commit a585dd7
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 15 deletions.
5 changes: 5 additions & 0 deletions HISTORY.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# HISTORY

### v2.1.1

- Change the way signinig key files are read (from `import` to `readFile`) so
that the compiled `chel` command works.

### v2.1.0

- Implemented signing (`chel manifest`, `chel keygen`) and verified (`chel verifySignature`) contracts. (h/t [@corrideat](https://github.com/okTurtles/chel/pull/27))
Expand Down
4 changes: 2 additions & 2 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 package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@chelonia/cli",
"version": "2.1.0",
"version": "2.1.1",
"description": "Chelonia Command-line Interface",
"main": "src/main.ts",
"scripts": {
Expand Down
6 changes: 3 additions & 3 deletions src/manifest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import { flags, path, colors } from './deps.ts'
import { hash } from './hash.ts'
import { exit, importJsonFile, revokeNet } from './utils.ts'
import { exit, readJsonFile, revokeNet } from './utils.ts'
import { EDWARDS25519SHA512BATCH, deserializeKey, keyId, serializeKey, sign } from './lib/crypto.ts'

// import { writeAllSync } from "https://deno.land/[email protected]/streams/mod.ts"
Expand All @@ -24,15 +24,15 @@ export async function manifest (args: string[]) {
const outFilepath = path.join(contractDir, `${contractName}.${version}.manifest.json`)
if (!keyFile) exit('Missing signing key file')

const signingKeyDescriptor = await importJsonFile(keyFile)
const signingKeyDescriptor = await readJsonFile(keyFile)
const signingKey = deserializeKey(signingKeyDescriptor.privkey)

// Add all additional public keys in addition to the signing key
const publicKeys = Array.from(new Set(
[serializeKey(signingKey, false)]
.concat(...await Promise.all(parsedArgs.key?.map(
async (kf: number | string) => {
const descriptor = await importJsonFile(kf)
const descriptor = await readJsonFile(kf)
const key = deserializeKey(descriptor.pubkey)
if (key.type !== EDWARDS25519SHA512BATCH) {
exit(`Invalid key type ${key.type}; only ${EDWARDS25519SHA512BATCH} keys are supported.`)
Expand Down
9 changes: 3 additions & 6 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,10 +127,7 @@ export async function revokeNet () {
await Deno.permissions.revoke({ name: 'net' })
}

export const importJsonFile = async (file: unknown) => {
const data = await import(
path.toFileUrl(path.resolve(String(file))).toString(),
{ with: { type: 'json' }}
)
return data.default
export const readJsonFile = async (file: unknown) => {
const contents = await Deno.readTextFile(path.resolve(String(file)))
return JSON.parse(contents)
}
6 changes: 3 additions & 3 deletions src/verifySignature.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import { hash } from './commands.ts'
import { colors, flags, path } from './deps.ts'
import { verifySignature as cryptoVerifySignature, deserializeKey, keyId } from './lib/crypto.ts'
import { exit, importJsonFile, revokeNet } from './utils.ts'
import { exit, readJsonFile, revokeNet } from './utils.ts'

export const verifySignature = async (args: string[], internal = false) => {
await revokeNet()
const parsedArgs = flags.parse(args)
const [manifestFile] = parsedArgs._
const keyFile = parsedArgs.k
const [externalKeyDescriptor, manifest] = await Promise.all([
keyFile ? importJsonFile(keyFile) : null,
importJsonFile(manifestFile)
keyFile ? readJsonFile(keyFile) : null,
readJsonFile(manifestFile)
])
if (keyFile && !externalKeyDescriptor.pubkey) {
exit('Public key missing from key file', internal)
Expand Down

0 comments on commit a585dd7

Please sign in to comment.