pyrote
pyrote
DDeno
Created by Leokuma on 6/28/2024 in #help
Running multiple Deno versions at the same time
What about having a user account per Deno version? Then all the caches and dependencies would be confined to that home directory or User Profile.
7 replies
DDeno
Created by Klimenty on 6/24/2024 in #help
BadCertificate error using deno 1.25.4
Yes deno.land is using a Let's Encrypt certificate. I installed 1.25.4 on a Ubuntu 22.04.4 LTS machine and can load that cliffy module. Just running a file with,
import * as cliffy from "https://deno.land/x/cliffy@v0.20.1/command/mod.ts"
import * as cliffy from "https://deno.land/x/cliffy@v0.20.1/command/mod.ts"
downloads the module correctly. Try running that as a test and see if it downloads the module in your environment.
7 replies
DDeno
Created by Klimenty on 6/24/2024 in #help
BadCertificate error using deno 1.25.4
Have you ran, sudo apt-get upgrade ca-certificates The UnknownIssuer message makes it seem like Deno can't find a valid certificate and you may not have the latest one for Let's Encrypt. Can you upgrade your version of Deno? That version is a few years old.
7 replies
DDeno
Created by TheCarpetMerchant on 6/7/2024 in #help
How do I use crypto.subtle.importKey to verify the signature sent by Admob SSV ?
It looks like that JSON file is using a P-256 key. It matches what OpenSSL generates for prime256v1. So to load the key, this is what you would do.
import { decodeBase64 } from "jsr:@std/encoding/base64";

const VERIFIER_KEYS_URL = 'https://gstatic.com/admob/reward/verifier-keys.json';

const verifier_keys_response = await fetch(VERIFIER_KEYS_URL);

// parse the response as JSON.
const key_data = await verifier_keys_response.json();

// load the key data from the base64 property in the JSON data.
const key_buffer = decodeBase64(key_data.keys[0].base64);

const imported_key = await crypto.subtle.importKey(
'spki',
key_buffer,
{ name: 'ECDSA', namedCurve: 'P-256' },
false,
['verify']
);
import { decodeBase64 } from "jsr:@std/encoding/base64";

const VERIFIER_KEYS_URL = 'https://gstatic.com/admob/reward/verifier-keys.json';

const verifier_keys_response = await fetch(VERIFIER_KEYS_URL);

// parse the response as JSON.
const key_data = await verifier_keys_response.json();

// load the key data from the base64 property in the JSON data.
const key_buffer = decodeBase64(key_data.keys[0].base64);

const imported_key = await crypto.subtle.importKey(
'spki',
key_buffer,
{ name: 'ECDSA', namedCurve: 'P-256' },
false,
['verify']
);
I don't have any signatures to test it with so can't be sure. Google should really include the algorithm in that verifier-keys.json file.
4 replies
DDeno
Created by babakfp on 4/5/2024 in #help
Deno Oak doesnt work when compiled to `.exe`
I tried your example and some Oak code with a route and error handler. Neither runs correctly when compiled. Tried Deno 1.41.3 and 1.42.1 on Linux Devuan 5.10.0-28-amd64 #1 SMP Debian 5.10.209-2 (2024-01-31) x86_64 GNU/Linux Tried deno compile -r to reload the cache. When you run the compiled binaries under strace they are looking for files in the .cache directory of the user's home directory which seems odd. Other compiled Deno code doesn't do that. Then the binary is just hung on a epoll_wait() call.
stat("/home/deno_user/.cache/deno/node_analysis_cache_v1-journal", {st_mode=S_IFREG|0644, st_size=0, ...}) = 0
stat("/home/deno_user/.cache/deno/node_analysis_cache_v1-wal", 0x7ffcee483b20) = -1 ENOENT (No such file or directory)
fstat(10, {st_mode=S_IFREG|0644, st_size=36864, ...}) = 0
fcntl(10, F_SETLK, {l_type=F_UNLCK, l_whence=SEEK_SET, l_start=0, l_len=0}) = 0
...
epoll_wait(4, [{EPOLLIN, {u32=0, u64=0}}], 1024, -1) = 1
clock_gettime(CLOCK_MONOTONIC, {tv_sec=610859, tv_nsec=163549894}) = 0
clock_gettime(CLOCK_MONOTONIC, {tv_sec=610859, tv_nsec=163926609}) = 0
clock_gettime(CLOCK_MONOTONIC, {tv_sec=610859, tv_nsec=164308969}) = 0
epoll_wait(4,
stat("/home/deno_user/.cache/deno/node_analysis_cache_v1-journal", {st_mode=S_IFREG|0644, st_size=0, ...}) = 0
stat("/home/deno_user/.cache/deno/node_analysis_cache_v1-wal", 0x7ffcee483b20) = -1 ENOENT (No such file or directory)
fstat(10, {st_mode=S_IFREG|0644, st_size=36864, ...}) = 0
fcntl(10, F_SETLK, {l_type=F_UNLCK, l_whence=SEEK_SET, l_start=0, l_len=0}) = 0
...
epoll_wait(4, [{EPOLLIN, {u32=0, u64=0}}], 1024, -1) = 1
clock_gettime(CLOCK_MONOTONIC, {tv_sec=610859, tv_nsec=163549894}) = 0
clock_gettime(CLOCK_MONOTONIC, {tv_sec=610859, tv_nsec=163926609}) = 0
clock_gettime(CLOCK_MONOTONIC, {tv_sec=610859, tv_nsec=164308969}) = 0
epoll_wait(4,
8 replies
DDeno
Created by DNA on 3/16/2024 in #help
Setting Deno.Command priority and affinity (on windows)
You can use the windows "start" cmd to set priority and affinity. https://learn.microsoft.com/en-us/windows-server/administration/windows-commands/start cmd /c start "" /high /affinity 3 "ffmpeg.exe" (args go here) The affinity is a Hex number representing a bitmask for the CPU cores. Right most bit is the first CPU core. So 3 is CPU core 0 and 1. F would be cores 0,1,2,3.
3 replies
DDeno
Created by fro.profesional on 3/6/2024 in #help
How to encrypt and decrypt files from S3 without loading the hole content into memory?
The Web Crypto API that Deno uses has no support for streams so I don't think its possible with the basic crypto.subtle. You could break the data into chunks and encrypt each chunk separately but then you are basically creating your own file format that only your code understands. Chunking can also potentially weaken the encryption if you don't handle IV generation and auth tags properly. I would look for a encryption library that can handle streams. Node's crypto module has support for ReadStreams so maybe Deno's Node compatibility is far enough along that it supports streams.
4 replies
DDeno
Created by TangJieHao on 2/13/2024 in #help
deno command stdin, stdout continous reading
If I replace config.EXE with "echo" the Deno code behaves correctly and prints stdout. Also tried a mock bash script too so the issue seems to be with that exe. Have you tried printing result.stderr to see if the exe is outputting any error messages?
4 replies
DDeno
Created by Kay on 1/13/2024 in #help
how to compress string into string
Using base91 to encode the raw compressed data would be a little more space efficient than base64. https://deno.land/x/base91@v1.1 The length a composition of your strings is going to dictate if compression will help or not. Compression works well with long repetitive data so if the strings are short and basically random, the compressed size may be larger than the string alone. Zstd and brotli are two popular compression algorithms to try. https://deno.land/x/zstd_wasm@0.0.21 https://deno.land/x/brotli@0.1.7
6 replies
DDeno
Created by venego on 1/10/2024 in #help
Can't spawn a shell properly using Deno!
If you only care about stdout and stderr and you can wait for the process to complete you could use something like this,
const bash = (cmd: string) => {

const output = new Deno.Command("bash", { args: ["-c", cmd] }).outputSync();

const decoder = new TextDecoder();

console.log("stdout:",decoder.decode(output.stdout));
console.error("stderr:",decoder.decode(output.stderr));

};

bash('echo lll');
const bash = (cmd: string) => {

const output = new Deno.Command("bash", { args: ["-c", cmd] }).outputSync();

const decoder = new TextDecoder();

console.log("stdout:",decoder.decode(output.stdout));
console.error("stderr:",decoder.decode(output.stderr));

};

bash('echo lll');
Calling spawn() creates a subprocess that has to be accessed with readable streams. Thus the ^^^ getWriter()/getReader() needs to be used. If you need to interact with the command while its running you would use spawn().
38 replies
DDeno
Created by sz on 1/3/2024 in #help
`RangeError: Offset is outside the bounds of the DataView` when trying to encrypt with AES-CRT
I'm not sure if that modules CTR implementation is supposed to be very low level or isn't finished yet. Its expecting the input data to be in blocks of 16 bytes. If you data isn't a multiple of 16 bytes you get that error. Which shouldn't be a requirement for CTR. You may want to look at the standard JavaScript crypto.subtle API. Its built into Deno. https://deno.land/api@v1.39.1?s=SubtleCrypto The Mozilla docs provide some good examples of how to use it. https://developer.mozilla.org/en-US/docs/Web/API/SubtleCrypto/encrypt#aes-ctr
6 replies
DDeno
Created by ash on 9/18/2023 in #help
Problem with parsing `base64url` from a `Buffer (node)`
I'm seeing the same bug with Buffer.from and base64url. Its returning a buffer that is mostly zeros. The AI doesn't know that Deno has a module for Base64URL.
import { encode as encodeBase64url, decode as decodeBase64url } from "https://deno.land/std/encoding/base64url.ts";

const text_decode = (d) => new TextDecoder().decode(new Uint8Array(d));

const url_str = 'IntcImhlbGxvXCI6XCJoZGQvZStpXCJ9Ig';
const buffer = decodeBase64url(url_str);
const buffer_str = text_decode(buffer);
console.log(`Text ${buffer_str}`);

const text = '"{\\"hello\\":\\"hdd/e+i\\"}"';
const base64_text = encodeBase64url(text);
console.log(`Base64URL ${base64_text}`);
import { encode as encodeBase64url, decode as decodeBase64url } from "https://deno.land/std/encoding/base64url.ts";

const text_decode = (d) => new TextDecoder().decode(new Uint8Array(d));

const url_str = 'IntcImhlbGxvXCI6XCJoZGQvZStpXCJ9Ig';
const buffer = decodeBase64url(url_str);
const buffer_str = text_decode(buffer);
console.log(`Text ${buffer_str}`);

const text = '"{\\"hello\\":\\"hdd/e+i\\"}"';
const base64_text = encodeBase64url(text);
console.log(`Base64URL ${base64_text}`);
10 replies
DDeno
Created by groendahl on 8/30/2023 in #help
Simple Deno program on Windows quits after 20 seconds
I would check the Windows Event Viewer to see if anything was logged about your program. Then you could use Process Monitor https://learn.microsoft.com/en-us/sysinternals/downloads/procmon To watch your program and see if anything its doing is failing for some reason.
4 replies
DDeno
Created by Timo Martinson on 8/21/2023 in #help
Property 'params' does not exist on type 'Context<State, Record<string, any>> ... what to do?
I've fought with this when Oak made major updates. Try importing the RouterContext from oak. change the function to (context: RouterContext<string> ) Also there is a helper for grabbing query params that can help too. Import helpers from oak,
const query_params: Record<string, string> = helpers.getQuery(context, { mergeParams: true });
const query_params: Record<string, string> = helpers.getQuery(context, { mergeParams: true });
3 replies
DDeno
Created by ly on 8/17/2023 in #help
bad resource id with node:crypto
crypto.subtle isn't quite as user friendly since you have to handle all the Buffer conversions yourself. Here's an example of your original code rewritten with crypto.subtle.
import {
decode as base64Decode,
encode as base64Encode,
} from "https://deno.land/std/encoding/base64.ts";

const text_decode = (d) => new TextDecoder().decode(new Uint8Array(d));
const text_encode = (e) => new TextEncoder().encode(e);

async function test() {
const key = await crypto.subtle.generateKey(
{
name: "AES-CBC",
length: 256,
},
false,
[
"encrypt",
"decrypt",
],
);

const iv = await crypto.getRandomValues(new Uint8Array(16));
const data = "Hello World";
const encoded = text_encode(data);

const encrypted = await crypto.subtle.encrypt(
{
name: "AES-CBC",
iv,
},
key,
encoded,
).then((buffer) => base64Encode(buffer)).catch((err) => {
throw new Error(`Error encrypting ${err}`);
});

const decrypted = await crypto.subtle.decrypt(
{
name: "AES-CBC",
iv,
},
key,
base64Decode(encrypted),
).then((buffer) => text_decode(buffer)).catch((err) => {
throw new Error(`Error decrypting ${err}`);
});

console.dir({ data, encrypted, decrypted });
}

test();
import {
decode as base64Decode,
encode as base64Encode,
} from "https://deno.land/std/encoding/base64.ts";

const text_decode = (d) => new TextDecoder().decode(new Uint8Array(d));
const text_encode = (e) => new TextEncoder().encode(e);

async function test() {
const key = await crypto.subtle.generateKey(
{
name: "AES-CBC",
length: 256,
},
false,
[
"encrypt",
"decrypt",
],
);

const iv = await crypto.getRandomValues(new Uint8Array(16));
const data = "Hello World";
const encoded = text_encode(data);

const encrypted = await crypto.subtle.encrypt(
{
name: "AES-CBC",
iv,
},
key,
encoded,
).then((buffer) => base64Encode(buffer)).catch((err) => {
throw new Error(`Error encrypting ${err}`);
});

const decrypted = await crypto.subtle.decrypt(
{
name: "AES-CBC",
iv,
},
key,
base64Decode(encrypted),
).then((buffer) => text_decode(buffer)).catch((err) => {
throw new Error(`Error decrypting ${err}`);
});

console.dir({ data, encrypted, decrypted });
}

test();
10 replies
DDeno
Created by ly on 8/17/2023 in #help
bad resource id with node:crypto
It looks like its a bug/unfinished feature in Deno's node:crypto implementation. If you change your code to use 'aes-128-cbc' and the key to randomBytes(16) it will run. Can you use Deno's native crypto.subtle encryption/decryption?
10 replies
DDeno
Created by Zidan on 8/10/2023 in #help
Serving multiple static files to an HTTP request
What is your use case? Browser to server or API client to server? Is returning a ZIP file with all the requested files an option?
37 replies
DDeno
Created by Bradford1802 on 7/25/2023 in #help
Dates don't increment correctly
It could be because of the local system's time zone. newDate.getDate() will return the date based on the local time. Which can be one day less than the UTC date depending on the time of day. You could use newDate.getUTCDate() if you want to keep everything in UTC.
3 replies