Compare commits
No commits in common. "e55a84564259410a5ddbe9881931f701d3812148" and "6d68e6a3be4f7e17e9a906187d40c1af3a154ca8" have entirely different histories.
e55a845642
...
6d68e6a3be
40
src/parse.js
40
src/parse.js
|
@ -1,40 +0,0 @@
|
|||
var baseUrl = "https://0x0.st";
|
||||
var id = "a0eiaje"; // < unicode >
|
||||
var key = "LhBRttf+oI/PNHyTBrPa7HGDK/uC9fcMkGGgz63zT4Y="; // 32 bytes b64
|
||||
var completeUrl = baseUrl + "/" + id + "#" + key;
|
||||
console.log(completeUrl);
|
||||
var urlObj = new URL(completeUrl);
|
||||
/** will return a tuple of the key and id if valid
|
||||
* 1 if no id ( creator )
|
||||
* 2 if encryption key is missing / wrong length
|
||||
* 3 if key is malformed
|
||||
*/
|
||||
function validUrl(url) {
|
||||
var key;
|
||||
try {
|
||||
key = atob(url.hash.substring(1));
|
||||
}
|
||||
catch (e) {
|
||||
return 3;
|
||||
}
|
||||
var id = url.pathname.substring(1);
|
||||
if (id === "/") {
|
||||
return 1;
|
||||
}
|
||||
var binKey = binaryToArray(key);
|
||||
if (key.length === 32) {
|
||||
return [id, binKey];
|
||||
}
|
||||
else {
|
||||
return 2;
|
||||
}
|
||||
}
|
||||
function binaryToArray(raw) {
|
||||
var rawLength = raw.length;
|
||||
var array = new Uint8Array(new ArrayBuffer(rawLength));
|
||||
for (var i = 0; i < rawLength; i++) {
|
||||
array[i] = raw.charCodeAt(i);
|
||||
}
|
||||
return array;
|
||||
}
|
||||
console.log(validUrl(urlObj));
|
43
src/parse.ts
43
src/parse.ts
|
@ -1,43 +0,0 @@
|
|||
const baseUrl: string = "https://0x0.st"
|
||||
const id: string = "a0eiaje" // < unicode >
|
||||
const key: string = "LhBRttf+oI/PNHyTBrPa7HGDK/uC9fcMkGGgz63zT4Y=" // 32 bytes b64
|
||||
const completeUrl: string = baseUrl + "/" + id + "#" + key
|
||||
console.log(completeUrl);
|
||||
const urlObj:URL = new URL(completeUrl);
|
||||
|
||||
/** will return a tuple of the key and id if valid
|
||||
* 1 if no id ( creator )
|
||||
* 2 if encryption key is missing / wrong length
|
||||
* 3 if key is malformed
|
||||
*/
|
||||
function validUrl(url: URL): [string,Uint8Array] | number {
|
||||
var key: string
|
||||
try {
|
||||
key = atob(url.hash.substring(1))
|
||||
} catch(e) {
|
||||
return 3
|
||||
}
|
||||
const id: string = url.pathname.substring(1);
|
||||
if ( id === "/" ) {
|
||||
return 1
|
||||
}
|
||||
const binKey = binaryToArray(key)
|
||||
if ( key.length === 32 ) {
|
||||
return [id,binKey]
|
||||
}
|
||||
else {
|
||||
return 2
|
||||
}
|
||||
}
|
||||
|
||||
function binaryToArray(raw: string): Uint8Array {
|
||||
var rawLength = raw.length;
|
||||
var array = new Uint8Array(new ArrayBuffer(rawLength));
|
||||
|
||||
for(var i = 0; i < rawLength; i++) {
|
||||
array[i] = raw.charCodeAt(i);
|
||||
}
|
||||
return array;
|
||||
}
|
||||
|
||||
console.log(validUrl(urlObj));
|
11
todo.md
11
todo.md
|
@ -1,11 +0,0 @@
|
|||
- [x] baseurl / id # < 32 bytes of b64 ( key ) >
|
||||
- parse handling happypath and stormypath
|
||||
- no id < no creator >
|
||||
- < key missing / malformed / wrong length >
|
||||
- if malformed re-request the url
|
||||
- test :
|
||||
Valid: `LhBRttf+oI/PNHyTBrPa7HGDK/uC9fcMkGGgz63zT4Y=`
|
||||
Short: `bi83sPUmUNknOITgXStHuCfimOjpELmizvVnW8LL2Q==`
|
||||
Long: `Yj3ryVkyOzDg6UbEHkWiNkNZcbbR5wTwtm6TZ6F7OLCI`
|
||||
Invalid: `bZLMOC157NAlKtFP3wHXkXj0eLAu6E/Bv6rGL4HLQ===`
|
||||
|
5
todo.txt
Normal file
5
todo.txt
Normal file
|
@ -0,0 +1,5 @@
|
|||
- baseurl / id # < 32 bytes of b64 ( key ) >
|
||||
- parse handling happypath and stormypath
|
||||
- no id < no creator >
|
||||
- < key missing / malformed / wrong length >
|
||||
- if malformed re-request the url
|
|
@ -1,5 +0,0 @@
|
|||
{
|
||||
"files": [
|
||||
"src/parse.ts"
|
||||
]
|
||||
}
|
Loading…
Reference in a new issue