add vdk_colors and vdk_names libs
This commit is contained in:
@@ -8,9 +8,15 @@ export {
|
||||
// basic bytes functions
|
||||
bytes_eq,
|
||||
bytes_concat,
|
||||
bytes_concat_arr,
|
||||
strong_rand_bytes,
|
||||
bytes_to_bigint,
|
||||
bytes_to_bigint_little,
|
||||
bigint_to_bytes,
|
||||
bigint_to_bytes_little,
|
||||
encode_utf8,
|
||||
bytes_zeros,
|
||||
bytes_to_hex_str,
|
||||
// basic bits functions
|
||||
bits_null,
|
||||
bits_zeros,
|
||||
@@ -54,7 +60,7 @@ bytes_eq
|
||||
|
||||
|
||||
/**
|
||||
* Concatenate two arrays
|
||||
* Concatenate two byte arrays
|
||||
*/
|
||||
function
|
||||
bytes_concat
|
||||
@@ -91,6 +97,22 @@ bytes_concat
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Concatenate an arbitrary number of byte arrays
|
||||
*
|
||||
* Calling with the empty array as an argument returns an empty byte array
|
||||
*/
|
||||
function
|
||||
bytes_concat_arr
|
||||
(arrays : Array<Uint8Array>)
|
||||
: Uint8Array
|
||||
{
|
||||
// reduce is what js calls foldl
|
||||
return arrays.reduce(bytes_concat, new Uint8Array([]));
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Cryptographically random bytes
|
||||
*/
|
||||
@@ -110,6 +132,8 @@ strong_rand_bytes
|
||||
* Convert a byte array to a bigint
|
||||
*
|
||||
* Equivalent to `binary:decode_unsigned/1` from Erlang
|
||||
*
|
||||
* Big endian byte order
|
||||
*/
|
||||
function
|
||||
bytes_to_bigint
|
||||
@@ -129,11 +153,32 @@ bytes_to_bigint
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Convert a byte array to a bigint
|
||||
*
|
||||
* Equivalent to `binary:decode_unsigned/1` from Erlang
|
||||
*
|
||||
* Little endian byte order
|
||||
*/
|
||||
function
|
||||
bytes_to_bigint_little
|
||||
(bytes: Uint8Array)
|
||||
: bigint
|
||||
{
|
||||
// reverse bytes and then call bytes_to_bigint
|
||||
bytes.reverse();
|
||||
return bytes_to_bigint(bytes);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Convert a bigint to a byte array
|
||||
*
|
||||
* Equivalent to `binary:encode_unsigned/1` from Erlang
|
||||
*
|
||||
* Big endian byte order
|
||||
*
|
||||
* Requires input to be positive
|
||||
*/
|
||||
function
|
||||
@@ -151,12 +196,100 @@ bigint_to_bytes
|
||||
q /= 256n;
|
||||
arr_reverse.push(r);
|
||||
}
|
||||
// i wrote the big endian implementation first
|
||||
// so leaving as is
|
||||
// but if we wanted to be more l33t we would refactor this as calling
|
||||
// `bigint_to_bytes_little` and reversing the result
|
||||
arr_reverse.reverse();
|
||||
return new Uint8Array(arr_reverse);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Same as `bigint_to_bytes` but result array is reversed (i.e. little endian
|
||||
* byte order)
|
||||
*/
|
||||
function
|
||||
bigint_to_bytes_little
|
||||
(q: bigint)
|
||||
: Uint8Array
|
||||
{
|
||||
// copied from big endian implementation
|
||||
if (q < 0n) {
|
||||
throw new Error('q < 0n: ' + q);
|
||||
}
|
||||
|
||||
let arr_reverse = [];
|
||||
while (q > 0n) {
|
||||
let r = Number(q % 256n);
|
||||
q /= 256n;
|
||||
arr_reverse.push(r);
|
||||
}
|
||||
// ah: BIG endian notation reverses the array
|
||||
// we will just not do that
|
||||
// arr_reverse.reverse();
|
||||
return new Uint8Array(arr_reverse);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Encode a string in utf8
|
||||
*/
|
||||
function
|
||||
encode_utf8
|
||||
(str : string)
|
||||
: Uint8Array
|
||||
{
|
||||
return (new TextEncoder()).encode(str);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Given number of zero bytes
|
||||
*/
|
||||
function
|
||||
bytes_zeros
|
||||
(byte_length: number)
|
||||
: Uint8Array
|
||||
{
|
||||
let result : Uint8Array = new Uint8Array(byte_length);
|
||||
for (let i0=0; i0<byte_length; i0++) {
|
||||
result[i0] = 0;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Encode a byte string in hexadecimal
|
||||
*/
|
||||
function
|
||||
bytes_to_hex_str
|
||||
(bytes: Uint8Array)
|
||||
: string
|
||||
{
|
||||
// make sure each byte is a 2 digit string
|
||||
function byte_to_hex2(n: number): string {
|
||||
if (n < 16)
|
||||
return '0' + n.toString(16);
|
||||
else
|
||||
return n.toString(16);
|
||||
}
|
||||
|
||||
let result: string = '';
|
||||
|
||||
for (let n of bytes) {
|
||||
result += byte_to_hex2(n);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Oh no, bitstrings in a language that only has bytestrings
|
||||
*
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
dist
|
||||
jex_mindist
|
||||
jex_include
|
||||
*.beam
|
||||
*.swp
|
||||
*.swo
|
||||
test/testgen/b58_cases_2.eterms
|
||||
test/testgen/b58_cases_3.eterms
|
||||
__pycache__
|
||||
docs/
|
||||
@@ -0,0 +1,4 @@
|
||||
# vdk_names
|
||||
|
||||
This is a library for taking a bytestring and giving it a human name. There are
|
||||
4096 names. The use case is giving public keys human names in JR.
|
||||
@@ -0,0 +1,5 @@
|
||||
{type, library}.
|
||||
{realm, local}.
|
||||
{name, vdk_colors}.
|
||||
{version, "0.1.0"}.
|
||||
{deps, []}.
|
||||
@@ -0,0 +1,24 @@
|
||||
done:
|
||||
- base64/base58 encoding/decoding
|
||||
- rlp
|
||||
|
||||
today:
|
||||
- pull apart data
|
||||
|
||||
tomorrow:
|
||||
- basic easy serialization/deserialization
|
||||
- serialize/deserialize examples
|
||||
- (maybe) pull in awcp/sidekick
|
||||
- sidekick: sign/propagate and sign/noprop
|
||||
|
||||
later:
|
||||
|
||||
- general node querying with parasite (think about autogeneration)
|
||||
- simple aetto/ae/etc unit converter
|
||||
- ghetto sophia ide
|
||||
- general "send money to someone" page
|
||||
|
||||
GUI:
|
||||
|
||||
- simple testnet explorer
|
||||
- contract ide
|
||||
@@ -0,0 +1,38 @@
|
||||
/**
|
||||
* Miscellaneous helper functions for RGB/HSV color arithmetic
|
||||
*
|
||||
* Reference: https://en.wikipedia.org/wiki/HSL_and_HSV
|
||||
*
|
||||
* @module
|
||||
*/
|
||||
|
||||
export {
|
||||
};
|
||||
|
||||
export type {
|
||||
rgb
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* standard red-green-blue color representation
|
||||
*
|
||||
* attributes `r`, `g` and `b` each are integers ranging within `0..255` inclusive
|
||||
*/
|
||||
type rgb
|
||||
= {r : number,
|
||||
g : number,
|
||||
b : number};
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* hue-saturation-value color representation
|
||||
*
|
||||
- * `h` is an inte
|
||||
*/
|
||||
type hsv
|
||||
= {h : number,
|
||||
s : number,
|
||||
v : number};
|
||||
@@ -0,0 +1,16 @@
|
||||
{"compilerOptions" : {"target" : "es2022",
|
||||
"strict" : true,
|
||||
"esModuleInterop" : true,
|
||||
"skipLibCheck" : true,
|
||||
"forceConsistentCasingInFileNames" : true,
|
||||
"noImplicitAny" : true,
|
||||
"strictNullChecks" : true,
|
||||
"strictPropertyInitialization" : true,
|
||||
"sourceMap" : true,
|
||||
"outDir" : "dist",
|
||||
"declaration" : true},
|
||||
"$schema" : "https://json.schemastore.org/tsconfig",
|
||||
"display" : "Recommended",
|
||||
"include" : ["src/**/*"],
|
||||
"exclude" : ["src/jex_include"],
|
||||
"composite" : true}
|
||||
@@ -0,0 +1,10 @@
|
||||
dist
|
||||
jex_mindist
|
||||
jex_include
|
||||
*.beam
|
||||
*.swp
|
||||
*.swo
|
||||
test/testgen/b58_cases_2.eterms
|
||||
test/testgen/b58_cases_3.eterms
|
||||
__pycache__
|
||||
docs/
|
||||
@@ -0,0 +1,4 @@
|
||||
# vdk_names
|
||||
|
||||
This is a library for taking a bytestring and giving it a human name. There are
|
||||
4096 names. The use case is giving public keys human names in JR.
|
||||
@@ -0,0 +1,5 @@
|
||||
{type, library}.
|
||||
{realm, local}.
|
||||
{name, vdk_names}.
|
||||
{version, "0.1.0"}.
|
||||
{deps, []}.
|
||||
@@ -0,0 +1,24 @@
|
||||
done:
|
||||
- base64/base58 encoding/decoding
|
||||
- rlp
|
||||
|
||||
today:
|
||||
- pull apart data
|
||||
|
||||
tomorrow:
|
||||
- basic easy serialization/deserialization
|
||||
- serialize/deserialize examples
|
||||
- (maybe) pull in awcp/sidekick
|
||||
- sidekick: sign/propagate and sign/noprop
|
||||
|
||||
later:
|
||||
|
||||
- general node querying with parasite (think about autogeneration)
|
||||
- simple aetto/ae/etc unit converter
|
||||
- ghetto sophia ide
|
||||
- general "send money to someone" page
|
||||
|
||||
GUI:
|
||||
|
||||
- simple testnet explorer
|
||||
- contract ide
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,16 @@
|
||||
{"compilerOptions" : {"target" : "es2022",
|
||||
"strict" : true,
|
||||
"esModuleInterop" : true,
|
||||
"skipLibCheck" : true,
|
||||
"forceConsistentCasingInFileNames" : true,
|
||||
"noImplicitAny" : true,
|
||||
"strictNullChecks" : true,
|
||||
"strictPropertyInitialization" : true,
|
||||
"sourceMap" : true,
|
||||
"outDir" : "dist",
|
||||
"declaration" : true},
|
||||
"$schema" : "https://json.schemastore.org/tsconfig",
|
||||
"display" : "Recommended",
|
||||
"include" : ["src/**/*"],
|
||||
"exclude" : ["src/jex_include"],
|
||||
"composite" : true}
|
||||
Reference in New Issue
Block a user