From a585dd70e4baa99e7efec56cb21fce949237a6c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ricardo=20Iv=C3=A1n=20Vieitez=20Parra?= <3857362+corrideat@users.noreply.github.com> Date: Wed, 14 Feb 2024 14:08:03 +0100 Subject: [PATCH] Fix file-not-found error when signing with the chel command --- HISTORY.md | 5 +++++ package-lock.json | 4 ++-- package.json | 2 +- src/manifest.ts | 6 +++--- src/utils.ts | 9 +++------ src/verifySignature.ts | 6 +++--- 6 files changed, 17 insertions(+), 15 deletions(-) diff --git a/HISTORY.md b/HISTORY.md index 106726b..fe8645f 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -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)) diff --git a/package-lock.json b/package-lock.json index 19eac6c..338683e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@chelonia/cli", - "version": "1.1.3", + "version": "2.1.1", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@chelonia/cli", - "version": "1.1.3", + "version": "2.1.1", "hasInstallScript": true, "license": "AGPL-3.0", "dependencies": { diff --git a/package.json b/package.json index 1087079..a4cb5b5 100644 --- a/package.json +++ b/package.json @@ -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": { diff --git a/src/manifest.ts b/src/manifest.ts index 93a5c10..4e61218 100644 --- a/src/manifest.ts +++ b/src/manifest.ts @@ -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/std@0.141.0/streams/mod.ts" @@ -24,7 +24,7 @@ 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 @@ -32,7 +32,7 @@ export async function manifest (args: string[]) { [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.`) diff --git a/src/utils.ts b/src/utils.ts index 00a06bc..926a0fe 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -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) } \ No newline at end of file diff --git a/src/verifySignature.ts b/src/verifySignature.ts index 2b4fdf8..880b790 100644 --- a/src/verifySignature.ts +++ b/src/verifySignature.ts @@ -1,7 +1,7 @@ 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() @@ -9,8 +9,8 @@ export const verifySignature = async (args: string[], internal = false) => { 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)