Quantum
Quantum
DDeno
Created by Quantum on 1/28/2024 in #help
Hoping for a clean way to get an array of filenames in directory
Thanks everyone! Also, walk is awesome. 🙂
7 replies
DDeno
Created by Quantum on 12/18/2023 in #help
How to get the path to the compiled binary?
quite possibly. let me take a look at what Syhol suggested
11 replies
DDeno
Created by Quantum on 12/18/2023 in #help
How to get the path to the compiled binary?
seems like something that should be doable for any binary
11 replies
DDeno
Created by Quantum on 12/18/2023 in #help
How to get the path to the compiled binary?
off the relative path
11 replies
DDeno
Created by Quantum on 12/18/2023 in #help
How to get the path to the compiled binary?
The use case woud be, run the binary and the binary looks for a settings.json file right next to it or looks inside of /data folder for sqlite files, etc.
11 replies
DDeno
Created by Quantum on 11/14/2023 in #help
How do I make the crypto.subtle.digest algo flexible?
Oh nice! I wasn't even looking at the lower cased digestAlgorithms that allows you to call includes on it. Yes, your guard approach is excellent and works nicely. Thanks for this and the insights!
26 replies
DDeno
Created by Quantum on 11/14/2023 in #help
How do I make the crypto.subtle.digest algo flexible?
One way or another, I am hoping to get away from needing to have all those "if" statements and I am more than happy to adhere to best practices that you are sharing with me.
26 replies
DDeno
Created by Quantum on 11/14/2023 in #help
How do I make the crypto.subtle.digest algo flexible?
If it is recommended that the new method here only has algo as DigestAlgorithm, I could abide by that too, ok. But in any case, I'm getting that issue when attempting to use includes on DigestAlgorithm.
26 replies
DDeno
Created by Quantum on 11/14/2023 in #help
How do I make the crypto.subtle.digest algo flexible?
Yes, I understand and agree with casting being necessary when input is coming from untrusted source and should only live at outer edge of program or library. The new method is the outer edge of the library where the input comes in. I am attempting to work in the DigestAlgorithm.includes(algo) that you showed above, but I am getting this error here: 'DigestAlgorithm' only refers to a type, but is being used as a value here.deno-ts(2693)
26 replies
DDeno
Created by Quantum on 11/14/2023 in #help
How do I make the crypto.subtle.digest algo flexible?
Maybe the algo comes from the database or maybe it comes from user input or somewhere else. Something needs to check it against DigestAlgorithm somewhere and the best that I could see how to do that until now was with "if" statements or something. What @marvinh. seemed to indicate is there is a way to cast algo to a DigestAlgorithm in the method signature that could then be used with "DigestAlgorithm.includes", which is interesting and might be what is needed here.
26 replies
DDeno
Created by Quantum on 11/14/2023 in #help
How do I make the crypto.subtle.digest algo flexible?
The "str is DigestAlgorithm" is interesting and might be what allows DigestAlgorithm.includes(algo) to work. How would I implement that on my "new" method above? Something like this doesn't quite work: static async new({algo, seed}: {algo: string, seed: string}): Promise<Random>, algo is DigestAlgorithm {
26 replies
DDeno
Created by Quantum on 11/14/2023 in #help
How do I make the crypto.subtle.digest algo flexible?
That is true, but then the calling code would need to have the "if" statements.
26 replies
DDeno
Created by Quantum on 11/14/2023 in #help
How do I make the crypto.subtle.digest algo flexible?
I think I was hoping Deno and/or TypeScript would allow for something like the following so that there is no need for all the "if" statements, which is error prone and tedious. More importantly, whenever Deno adds a new one to DigestAlgorithm (they added "BLAKE2B-128" 2 months ago), I would also need to change the code to add another "if" statement. What I was hoping for is something kind of like this:
if (DigestAlgorithm.includes(algo)) {
da = algo;
}
if (DigestAlgorithm.includes(algo)) {
da = algo;
}
If something along those lines can't be accomplished, I'm seeing this as a wider language issue. DigestAlgorithm is just an example. The same problem would come up elsewhere.
26 replies
DDeno
Created by Quantum on 11/14/2023 in #help
How do I make the crypto.subtle.digest algo flexible?
import { crypto, DigestAlgorithm } from "https://deno.land/std@0.202.0/crypto/mod.ts";

export default class Random {
algo: DigestAlgorithm;
index: number;
random256!: Uint8Array;

constructor(algo: DigestAlgorithm) {
this.algo = algo;
this.index = 0;
}

static async new({algo, seed}: {algo: string, seed: string}): Promise<Random> {
let da: DigestAlgorithm = "BLAKE2B"; //default
if (algo == "BLAKE2B-224") da = "BLAKE2B-224";
if (algo == "BLAKE2B-256") da = "BLAKE2B-256";
if (algo == "BLAKE2B-384") da = "BLAKE2B-384";
if (algo == "BLAKE2B") da = "BLAKE2B";
if (algo == "BLAKE2S") da = "BLAKE2S";
if (algo == "BLAKE3") da = "BLAKE3";
if (algo == "KECCAK-224") da = "KECCAK-224";
if (algo == "KECCAK-256") da = "KECCAK-256";
if (algo == "KECCAK-384") da = "KECCAK-384";
if (algo == "KECCAK-512") da = "KECCAK-512";
if (algo == "SHA-384") da = "SHA-384";
if (algo == "SHA3-224") da = "SHA3-224";
if (algo == "SHA3-256") da = "SHA3-256";
if (algo == "SHA3-384") da = "SHA3-384";
if (algo == "SHA3-512") da = "SHA3-512";
if (algo == "SHAKE128") da = "SHAKE128";
if (algo == "SHAKE256") da = "SHAKE256";
if (algo == "TIGER") da = "TIGER";
if (algo == "RIPEMD-160") da = "RIPEMD-160";
if (algo == "SHA-224") da = "SHA-224";
if (algo == "SHA-256") da = "SHA-256";
if (algo == "SHA-512") da = "SHA-512";
if (algo == "MD4") da = "MD4";
if (algo == "MD5") da = "MD5";
if (algo == "SHA-1") da = "SHA-1";

const random = new Random(da);

random.random256 = new Uint8Array(
await crypto.subtle.digest(
random.algo, new TextEncoder().encode(seed)
)
);

return random;
}
}
import { crypto, DigestAlgorithm } from "https://deno.land/std@0.202.0/crypto/mod.ts";

export default class Random {
algo: DigestAlgorithm;
index: number;
random256!: Uint8Array;

constructor(algo: DigestAlgorithm) {
this.algo = algo;
this.index = 0;
}

static async new({algo, seed}: {algo: string, seed: string}): Promise<Random> {
let da: DigestAlgorithm = "BLAKE2B"; //default
if (algo == "BLAKE2B-224") da = "BLAKE2B-224";
if (algo == "BLAKE2B-256") da = "BLAKE2B-256";
if (algo == "BLAKE2B-384") da = "BLAKE2B-384";
if (algo == "BLAKE2B") da = "BLAKE2B";
if (algo == "BLAKE2S") da = "BLAKE2S";
if (algo == "BLAKE3") da = "BLAKE3";
if (algo == "KECCAK-224") da = "KECCAK-224";
if (algo == "KECCAK-256") da = "KECCAK-256";
if (algo == "KECCAK-384") da = "KECCAK-384";
if (algo == "KECCAK-512") da = "KECCAK-512";
if (algo == "SHA-384") da = "SHA-384";
if (algo == "SHA3-224") da = "SHA3-224";
if (algo == "SHA3-256") da = "SHA3-256";
if (algo == "SHA3-384") da = "SHA3-384";
if (algo == "SHA3-512") da = "SHA3-512";
if (algo == "SHAKE128") da = "SHAKE128";
if (algo == "SHAKE256") da = "SHAKE256";
if (algo == "TIGER") da = "TIGER";
if (algo == "RIPEMD-160") da = "RIPEMD-160";
if (algo == "SHA-224") da = "SHA-224";
if (algo == "SHA-256") da = "SHA-256";
if (algo == "SHA-512") da = "SHA-512";
if (algo == "MD4") da = "MD4";
if (algo == "MD5") da = "MD5";
if (algo == "SHA-1") da = "SHA-1";

const random = new Random(da);

random.random256 = new Uint8Array(
await crypto.subtle.digest(
random.algo, new TextEncoder().encode(seed)
)
);

return random;
}
}
26 replies
DDeno
Created by Quantum on 11/14/2023 in #help
How do I make the crypto.subtle.digest algo flexible?
@cknight I am writing the beginnings of a deterministic pseudo random library that allows the user of the library to specify what algorithm to use. It would be a separate issue to discuss the merits of such a library. (Very happy to discuss!) The best that I can do to make this flexible is by doing the following:
26 replies
DDeno
Created by Quantum on 11/14/2023 in #help
How do I make the crypto.subtle.digest algo flexible?
I agree and understand why. My goal is to understand how to make it flexible. Am I forced to hard code this value?
26 replies
DDeno
Created by Quantum on 11/12/2023 in #help
Is there a built-in parser for the string that Deno.inspect produces?
Ah well, very inspiring though. I think I might create my own serializer/deserializer based on these ideas. Thanks so much for the insights!
4 replies
DDeno
Created by Quantum on 11/12/2023 in #help
How to get the nice Deno console.log format into a string?
Oh my goodness, that is so incredibly awesome. Thank you so much!
6 replies