-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
36 changed files
with
1,355 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1 @@ | ||
node_modules/ | ||
build/ | ||
node_modules/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
/src/ | ||
/test_runner.js | ||
yarn.lock | ||
pnpm-lock.yaml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# Common | ||
|
||
This is code shared between the other parts of the repo. | ||
|
||
To initialise it, or after updates, ensure you have deno installed and then run: | ||
|
||
deno task cache |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
export declare const DERIVED_EVENT_PLUS_CODE_PREFIX_MINIMUM_LENGTH: 2; | ||
export declare const MAP_NOTE_KIND: 30397; | ||
export declare const MAP_NOTE_REPOST_KIND: 30398; | ||
export declare const OPEN_LOCATION_CODE_TAG_NAME: "open-location-code"; | ||
export declare const OPEN_LOCATION_CODE_PREFIX_TAG_NAME: "open-location-code-prefix"; | ||
export declare const DEFAULT_RELAY_URL = "wss://relay.trustroots.org"; | ||
export declare const DEV_PUBKEY: "80789235a71a388074abfa5c482e270456d2357425266270f82071cf2b1de74a"; | ||
export declare const NOSTROOTS_VALIDATION_PUBKEY: "f5bc71692fc08ea52c0d1c8bcfb87579584106b5feb4ea542b1b8a95612f257b"; | ||
export declare const HITCHMAPS_AUTHOR_PUBLIC_KEY: "53055ee011e96a00a705b38253b9cbc6614ccbd37df4dad42ec69bbe608c4209"; | ||
export declare const HITCHWIKI_AUTHOR_PUBLIC_KEY: "16db5234c1dd8082897bd2d21bbec4b8051d2cd03e24b819aa5232077d443da9"; | ||
export declare const TIMESAFARI_AUTHOR_PUBLIC_KEY: "76e88d2e653fc3655f8e0b97f6bc85f5468eaffc5d64522b584ce13eedbd8af7"; | ||
export type MapLayer = { | ||
title: string; | ||
rootUrl: string; | ||
kind: 30399 | 30398 | 30397; | ||
pubkey: string; | ||
markerColor: string; | ||
rectangleColor: string; | ||
}; | ||
export declare const MAP_LAYERS: { | ||
readonly hitchmap: MapLayer; | ||
readonly hitchwiki: MapLayer; | ||
readonly timesafari: MapLayer; | ||
readonly triphopping: MapLayer; | ||
readonly unverified: MapLayer; | ||
}; | ||
export type MAP_LAYER_KEY = keyof typeof MAP_LAYERS; | ||
//# sourceMappingURL=constants.d.ts.map |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
export const DERIVED_EVENT_PLUS_CODE_PREFIX_MINIMUM_LENGTH = 2; | ||
export const MAP_NOTE_KIND = 30397; | ||
export const MAP_NOTE_REPOST_KIND = 30398; | ||
export const OPEN_LOCATION_CODE_TAG_NAME = "open-location-code"; | ||
export const OPEN_LOCATION_CODE_PREFIX_TAG_NAME = "open-location-code-prefix"; | ||
export const DEFAULT_RELAY_URL = "wss://relay.trustroots.org"; | ||
export const DEV_PUBKEY = "80789235a71a388074abfa5c482e270456d2357425266270f82071cf2b1de74a"; | ||
export const NOSTROOTS_VALIDATION_PUBKEY = "f5bc71692fc08ea52c0d1c8bcfb87579584106b5feb4ea542b1b8a95612f257b"; | ||
export const HITCHMAPS_AUTHOR_PUBLIC_KEY = "53055ee011e96a00a705b38253b9cbc6614ccbd37df4dad42ec69bbe608c4209"; | ||
export const HITCHWIKI_AUTHOR_PUBLIC_KEY = "16db5234c1dd8082897bd2d21bbec4b8051d2cd03e24b819aa5232077d443da9"; | ||
export const TIMESAFARI_AUTHOR_PUBLIC_KEY = "76e88d2e653fc3655f8e0b97f6bc85f5468eaffc5d64522b584ce13eedbd8af7"; | ||
const hitchmap = { | ||
title: "Hitchmap", | ||
rootUrl: "https://hitchmap.com", | ||
kind: 30399, | ||
pubkey: HITCHMAPS_AUTHOR_PUBLIC_KEY, | ||
markerColor: "yellow", | ||
rectangleColor: "rgba(255, 255, 0, 0.5)", | ||
}; | ||
const hitchwiki = { | ||
title: "Hitchwiki", | ||
rootUrl: "https://hitchwiki.org", | ||
kind: 30399, | ||
pubkey: HITCHWIKI_AUTHOR_PUBLIC_KEY, | ||
markerColor: "gold", | ||
rectangleColor: "rgba(255, 215, 0, 0.5)", | ||
}; | ||
const timesafari = { | ||
title: "Time Safari", | ||
rootUrl: "https://www.timesafari.app", | ||
kind: 30399, | ||
pubkey: TIMESAFARI_AUTHOR_PUBLIC_KEY, | ||
markerColor: "blue", | ||
rectangleColor: "rgba(0, 0, 255, 0.5)", | ||
}; | ||
const triphopping = { | ||
title: "Trip Hopping", | ||
rootUrl: "https://www.triphopping.com", | ||
kind: 30398, | ||
pubkey: DEV_PUBKEY, | ||
markerColor: "brown", | ||
rectangleColor: "rgba(0, 0, 255, 0.5)", | ||
}; | ||
const unverified = { | ||
title: "Unverified", | ||
rootUrl: "https://notes.trustroots.org", | ||
kind: 30397, | ||
pubkey: "", | ||
markerColor: "red", | ||
rectangleColor: "rgba(255, 0, 0, 0.5)", | ||
}; | ||
export const MAP_LAYERS = { | ||
hitchmap, | ||
hitchwiki, | ||
timesafari, | ||
triphopping, | ||
unverified, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import { z } from "zod"; | ||
export { z }; | ||
//# sourceMappingURL=deps.d.ts.map |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
import { z } from "zod"; | ||
export { z }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
import { z } from "./deps.js"; | ||
export * from "./utils.js"; | ||
export * from "./constants.js"; | ||
export declare const CONTENT_MINIMUM_LENGTH = 3; | ||
export declare const CONTENT_MAXIMUM_LENGTH = 300; | ||
export declare const eventSchema: z.ZodObject<{ | ||
id: z.ZodString; | ||
pubkey: z.ZodString; | ||
kind: z.ZodNumber; | ||
created_at: z.ZodNumber; | ||
tags: z.ZodArray<z.ZodArray<z.ZodString, "many">, "many">; | ||
content: z.ZodString; | ||
sig: z.ZodString; | ||
}, "strict", z.ZodTypeAny, { | ||
id: string; | ||
pubkey: string; | ||
kind: number; | ||
created_at: number; | ||
tags: string[][]; | ||
content: string; | ||
sig: string; | ||
}, { | ||
id: string; | ||
pubkey: string; | ||
kind: number; | ||
created_at: number; | ||
tags: string[][]; | ||
content: string; | ||
sig: string; | ||
}>; | ||
export type Event = z.infer<typeof eventSchema>; | ||
export declare const tagsIncludingPlusCodeSchema: z.ZodEffects<z.ZodArray<z.ZodArray<z.ZodString, "many">, "many">, string[][], string[][]>; | ||
export declare const contentSchema: z.ZodString; | ||
export declare const kind30398EventSchema: z.ZodObject<z.objectUtil.extendShape<{ | ||
id: z.ZodString; | ||
pubkey: z.ZodString; | ||
kind: z.ZodNumber; | ||
created_at: z.ZodNumber; | ||
tags: z.ZodArray<z.ZodArray<z.ZodString, "many">, "many">; | ||
content: z.ZodString; | ||
sig: z.ZodString; | ||
}, { | ||
kind: z.ZodLiteral<30398>; | ||
tags: z.ZodEffects<z.ZodArray<z.ZodArray<z.ZodString, "many">, "many">, string[][], string[][]>; | ||
content: z.ZodString; | ||
}>, "strict", z.ZodTypeAny, { | ||
id: string; | ||
pubkey: string; | ||
kind: 30398; | ||
created_at: number; | ||
tags: string[][]; | ||
content: string; | ||
sig: string; | ||
}, { | ||
id: string; | ||
pubkey: string; | ||
kind: 30398; | ||
created_at: number; | ||
tags: string[][]; | ||
content: string; | ||
sig: string; | ||
}>; | ||
export type Kind30398Event = z.infer<typeof kind30398EventSchema>; | ||
export declare const kind30397EventSchema: z.ZodObject<z.objectUtil.extendShape<{ | ||
id: z.ZodString; | ||
pubkey: z.ZodString; | ||
kind: z.ZodNumber; | ||
created_at: z.ZodNumber; | ||
tags: z.ZodArray<z.ZodArray<z.ZodString, "many">, "many">; | ||
content: z.ZodString; | ||
sig: z.ZodString; | ||
}, { | ||
kind: z.ZodLiteral<30397>; | ||
tags: z.ZodEffects<z.ZodArray<z.ZodArray<z.ZodString, "many">, "many">, string[][], string[][]>; | ||
content: z.ZodString; | ||
}>, "strict", z.ZodTypeAny, { | ||
id: string; | ||
pubkey: string; | ||
kind: 30397; | ||
created_at: number; | ||
tags: string[][]; | ||
content: string; | ||
sig: string; | ||
}, { | ||
id: string; | ||
pubkey: string; | ||
kind: 30397; | ||
created_at: number; | ||
tags: string[][]; | ||
content: string; | ||
sig: string; | ||
}>; | ||
export declare function isValidEvent(event: Event): boolean; | ||
//# sourceMappingURL=mod.d.ts.map |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
import { OPEN_LOCATION_CODE_TAG_NAME } from "./constants.js"; | ||
import { z } from "./deps.js"; | ||
import { getFirstLabelValueFromTags, isPlusCode, } from "./utils.js"; | ||
export * from "./utils.js"; | ||
export * from "./constants.js"; | ||
// import { version as PACKAGE_VERSION } from "./deno.json" with { type: "json" }; | ||
export const CONTENT_MINIMUM_LENGTH = 3; | ||
export const CONTENT_MAXIMUM_LENGTH = 300; | ||
const PACKAGE_VERSION = "0.0.1"; | ||
export const eventSchema = z | ||
.object({ | ||
id: z.string().length(64), | ||
pubkey: z.string().length(64), | ||
kind: z.number(), | ||
created_at: z.number(), | ||
tags: z.string().array().array(), | ||
content: z.string(), | ||
sig: z.string(), | ||
}) | ||
.strict(); | ||
function hasOpenLocationCode(tags) { | ||
const namespaces = tags | ||
.filter((tag) => tag[0] === "L") | ||
.map((tag) => tag.slice(1)) | ||
.flat(); | ||
const hasOpenLocationCodeNamespace = namespaces.includes(OPEN_LOCATION_CODE_TAG_NAME); | ||
if (!hasOpenLocationCodeNamespace) | ||
return false; | ||
const plusCodeTags = tags.filter((tag) => tag.length > 3 && tag[0] === "l" && tag[2] === OPEN_LOCATION_CODE_TAG_NAME); | ||
if (plusCodeTags.length === 0) | ||
return false; | ||
const plusCodes = plusCodeTags.map((plusCodeTag) => plusCodeTag[1]); | ||
const validPlusCodes = plusCodes.every(isPlusCode); | ||
if (!validPlusCodes) | ||
return false; | ||
return true; | ||
} | ||
function hasVersion(tags) { | ||
const versionTags = tags.filter((tag) => tag[0] === "kind30398_version"); | ||
if (versionTags.length !== 1) | ||
return false; | ||
const versionTag = versionTags[0]; | ||
if (versionTag.length !== 2) | ||
return false; | ||
const version = versionTag[1]; | ||
if (version !== PACKAGE_VERSION) | ||
return false; | ||
return true; | ||
} | ||
export const tagsIncludingPlusCodeSchema = z | ||
.string() | ||
.array() | ||
.array() | ||
.refine((tags) => { | ||
const plusCode = getFirstLabelValueFromTags(tags, OPEN_LOCATION_CODE_TAG_NAME); | ||
if (typeof plusCode === "undefined" || !isPlusCode(plusCode)) { | ||
return false; | ||
} | ||
return true; | ||
}, { message: "Tags have invalid or missing plus code" }); | ||
export const contentSchema = z | ||
.string() | ||
.max(CONTENT_MAXIMUM_LENGTH, `content is above max length of ${CONTENT_MAXIMUM_LENGTH}`) | ||
.min(CONTENT_MINIMUM_LENGTH, `content is below min length of ${CONTENT_MINIMUM_LENGTH}`); | ||
export const kind30398EventSchema = eventSchema.extend({ | ||
kind: z.literal(30398), | ||
// TODO Enable version check | ||
tags: tagsIncludingPlusCodeSchema, | ||
// tags: tagsIncludingPlusCodeSchema.refine(hasVersion, { | ||
// message: "no valid kind30398_version", | ||
// }), | ||
content: contentSchema, | ||
}); | ||
export const kind30397EventSchema = eventSchema.extend({ | ||
kind: z.literal(30397), | ||
// TODO Enable version check | ||
tags: tagsIncludingPlusCodeSchema, | ||
// tags: tagsIncludingPlusCodeSchema.refine(hasVersion, { | ||
// message: "no valid kind30397_version", | ||
// }), | ||
content: contentSchema, | ||
}); | ||
export function isValidEvent(event) { | ||
const { kind } = event; | ||
switch (kind) { | ||
case 30397: { | ||
const { success } = kind30397EventSchema.safeParse(event); | ||
return success; | ||
} | ||
case 30398: { | ||
const { success } = kind30398EventSchema.safeParse(event); | ||
return success; | ||
} | ||
} | ||
const { success } = eventSchema.safeParse(event); | ||
return success; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"type": "module" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { type Event } from "./mod.js"; | ||
export declare function isHex(s: string): boolean; | ||
export declare function isHexKey(key: string): boolean; | ||
export declare function isPlusCode(code: string): boolean; | ||
export declare function getCurrentTimestamp(): number; | ||
export declare function getFirstTagValueFromEvent(nostrEvent: Event, tagName: string): string | undefined; | ||
export declare function getFirstLabelValueFromTags(tags: string[][], labelName: string): string | undefined; | ||
export declare function createLabelTags(labelName: string, labelValue: string | string[]): string[][]; | ||
export declare function getFirstLabelValueFromEvent(nostrEvent: Event, labelName: string): string | undefined; | ||
export declare function getPlusCodePrefix(plusCode: string, length: number): string; | ||
export declare function getAllPlusCodePrefixes(plusCode: string, minimumLength: number): string[]; | ||
export declare function getPlusCodeAndPlusCodePrefixTags(plusCode: string): string[][]; | ||
//# sourceMappingURL=utils.d.ts.map |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.