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 b986537
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 24 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
18 changes: 9 additions & 9 deletions build/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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);
};
}
});
Expand Down Expand Up @@ -773,10 +773,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.`);
Expand Down Expand Up @@ -871,8 +871,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);
Expand Down Expand Up @@ -935,7 +935,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
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 b986537

Please sign in to comment.