Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix file-not-found error when signing with the chel command #30

Merged
merged 1 commit into from
Feb 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
19 changes: 9 additions & 10 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 @@ -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;
Expand All @@ -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.`);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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
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
7 changes: 3 additions & 4 deletions src/manifest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,14 @@

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"

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
Expand All @@ -24,15 +23,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
Loading