From 4b89cde5ee251d875b998bf32bc9c124ac45e62b 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 +++++ build/main.js | 19 +++++++++---------- package-lock.json | 4 ++-- package.json | 2 +- src/manifest.ts | 7 +++---- src/utils.ts | 9 +++------ src/verifySignature.ts | 6 +++--- 7 files changed, 26 insertions(+), 26 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/build/main.js b/build/main.js index cf0fad9..abaade7 100755 --- a/build/main.js +++ b/build/main.js @@ -251,7 +251,7 @@ async function readRemoteData(src, key) { async function revokeNet() { await Deno.permissions.revoke({ name: "net" }); } -var backends, multibase, multicodes, multihasher, importJsonFile; +var backends, multibase, multicodes, multihasher, readJsonFile; var init_utils = __esm({ "src/utils.ts"() { "use strict"; @@ -262,9 +262,9 @@ var init_utils = __esm({ multibase = base58btc; multicodes = { JSON: 512, RAW: 0 }; multihasher = default3.blake2b.blake2b256; - importJsonFile = async (file) => { - const data = await import(path.toFileUrl(path.resolve(String(file))).toString(), { with: { type: "json" } }); - return data.default; + readJsonFile = async (file) => { + const contents = await Deno.readTextFile(path.resolve(String(file))); + return JSON.parse(contents); }; } }); @@ -764,7 +764,6 @@ init_utils(); async function manifest(args) { await revokeNet(); const parsedArgs = flags.parse(args, { collect: ["key"], alias: { "key": "k" } }); - console.log(parsedArgs); const [keyFile, contractFile] = parsedArgs._; const parsedFilepath = path.parse(contractFile); const { name: contractName, base: contractBasename, dir: contractDir } = parsedFilepath; @@ -773,10 +772,10 @@ async function manifest(args) { const outFilepath = path.join(contractDir, `${contractName}.${version2}.manifest.json`); if (!keyFile) exit("Missing signing key file"); - const signingKeyDescriptor = await importJsonFile(keyFile); + const signingKeyDescriptor = await readJsonFile(keyFile); const signingKey = deserializeKey(signingKeyDescriptor.privkey); const publicKeys = Array.from(new Set([serializeKey(signingKey, false)].concat(...await Promise.all(parsedArgs.key?.map(async (kf) => { - 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.`); @@ -871,8 +870,8 @@ var verifySignature2 = async (args, internal = false) => { const [manifestFile] = parsedArgs._; const keyFile = parsedArgs.k; const [externalKeyDescriptor, manifest2] = 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); @@ -935,7 +934,7 @@ var verifySignature2 = async (args, internal = false) => { // src/version.ts function version() { - console.log("2.1.0"); + console.log("2.1.1"); } // src/main.ts 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..6a0687d 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" @@ -15,7 +15,6 @@ import { EDWARDS25519SHA512BATCH, deserializeKey, keyId, serializeKey, sign } fr export async function manifest (args: string[]) { await revokeNet() const parsedArgs = flags.parse(args, { collect: ['key'], alias: { 'key': 'k' } }) - console.log(parsedArgs) const [keyFile, contractFile] = parsedArgs._ const parsedFilepath = path.parse(contractFile as string) const { name: contractName, base: contractBasename, dir: contractDir } = parsedFilepath @@ -24,7 +23,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 +31,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)