diff --git a/crypto/keypair.ts b/crypto/keypair.ts index acefb40..5290094 100644 --- a/crypto/keypair.ts +++ b/crypto/keypair.ts @@ -13,10 +13,10 @@ export class BlahKeyPair { publicKey: BlahPublicKey; private privateKey: CryptoKey; - get id() { + get id(): string { return this.publicKey.id; } - get name() { + get name(): string { return this.publicKey.name; } diff --git a/crypto/mod.ts b/crypto/mod.ts index 5a3ba3c..d952766 100644 --- a/crypto/mod.ts +++ b/crypto/mod.ts @@ -1,4 +1,4 @@ export * from "./keypair.ts"; export * from "./publicKey.ts"; -export * from "./signedPayload.ts"; +export type { BlahPayloadSignee, BlahSignedPayload } from "./signedPayload.ts"; export * from "./utils.ts"; diff --git a/crypto/signedPayload.test.ts b/crypto/signedPayload.test.ts new file mode 100644 index 0000000..c3466b0 --- /dev/null +++ b/crypto/signedPayload.test.ts @@ -0,0 +1,25 @@ +import z from "zod"; +import type { BlahSignedPayload } from "./mod.ts"; +import { + type BlahPayloadSignee, + blahPayloadSigneeSchemaOf, + blahSignedPayloadSchemaOf, +} from "./signedPayload.ts"; +import { assertTypeMatchesZodSchema } from "../test/utils.ts"; + +const testPayloadSchema = z.object({ + foo: z.string(), +}); +type TestPayload = z.infer; + +Deno.test("type BlahPayloadSignee is accurate", () => { + assertTypeMatchesZodSchema>( + blahPayloadSigneeSchemaOf(testPayloadSchema), + ); +}); + +Deno.test("type BlahSignedPayload is accurate", () => { + assertTypeMatchesZodSchema>( + blahSignedPayloadSchemaOf(testPayloadSchema), + ); +}); diff --git a/crypto/signedPayload.ts b/crypto/signedPayload.ts index 5eed005..22ec36e 100644 --- a/crypto/signedPayload.ts +++ b/crypto/signedPayload.ts @@ -17,10 +17,15 @@ export function blahSignedPayloadSchemaOf

(schema: P) { }); } -export type BlahPayloadSignee

= z.infer< - ReturnType> ->; +export type BlahPayloadSignee

= { + nonce: number; + payload: P; + timestamp: number; + id_key: string; + act_key?: string; +}; -export type BlahSignedPayload

= z.infer< - ReturnType> ->; +export type BlahSignedPayload

= { + sig: string; + signee: BlahPayloadSignee

; +}; diff --git a/deno.json b/deno.json index 0ae46f9..cbf43a5 100644 --- a/deno.json +++ b/deno.json @@ -8,6 +8,10 @@ "imports": { "@deno/dnt": "jsr:@deno/dnt@^0.41.3", "@std/expect": "jsr:@std/expect@^1.0.3", + "@std/testing": "jsr:@std/testing@^1.0.3", "zod": "https://deno.land/x/zod@v3.23.8/mod.ts" + }, + "tasks": { + "build:npm": "deno run ./scripts/build_npm.ts" } } diff --git a/deno.lock b/deno.lock index b4009a9..f10b2d2 100644 --- a/deno.lock +++ b/deno.lock @@ -9,20 +9,26 @@ "jsr:@std/assert@^0.223.0": "jsr:@std/assert@0.223.0", "jsr:@std/assert@^0.226.0": "jsr:@std/assert@0.226.0", "jsr:@std/assert@^1.0.5": "jsr:@std/assert@1.0.5", + "jsr:@std/assert@^1.0.6": "jsr:@std/assert@1.0.6", "jsr:@std/bytes@^0.223.0": "jsr:@std/bytes@0.223.0", - "jsr:@std/expect@^1.0.3": "jsr:@std/expect@1.0.3", + "jsr:@std/data-structures@^1.0.4": "jsr:@std/data-structures@1.0.4", + "jsr:@std/expect@^1.0.3": "jsr:@std/expect@1.0.4", "jsr:@std/fmt@1": "jsr:@std/fmt@1.0.2", "jsr:@std/fmt@^0.223": "jsr:@std/fmt@0.223.0", - "jsr:@std/fs@1": "jsr:@std/fs@1.0.3", + "jsr:@std/fs@1": "jsr:@std/fs@1.0.4", "jsr:@std/fs@^0.223": "jsr:@std/fs@0.223.0", "jsr:@std/fs@^0.229.3": "jsr:@std/fs@0.229.3", + "jsr:@std/fs@^1.0.4": "jsr:@std/fs@1.0.4", "jsr:@std/internal@^1.0.3": "jsr:@std/internal@1.0.3", + "jsr:@std/internal@^1.0.4": "jsr:@std/internal@1.0.4", "jsr:@std/io@^0.223": "jsr:@std/io@0.223.0", "jsr:@std/path@1": "jsr:@std/path@1.0.6", "jsr:@std/path@1.0.0-rc.1": "jsr:@std/path@1.0.0-rc.1", "jsr:@std/path@^0.223": "jsr:@std/path@0.223.0", "jsr:@std/path@^0.225.2": "jsr:@std/path@0.225.2", "jsr:@std/path@^1.0.4": "jsr:@std/path@1.0.6", + "jsr:@std/path@^1.0.6": "jsr:@std/path@1.0.6", + "jsr:@std/testing@^1.0.3": "jsr:@std/testing@1.0.3", "jsr:@ts-morph/bootstrap@^0.24.0": "jsr:@ts-morph/bootstrap@0.24.0", "jsr:@ts-morph/common@^0.24.0": "jsr:@ts-morph/common@0.24.0" }, @@ -66,9 +72,18 @@ "jsr:@std/internal@^1.0.3" ] }, + "@std/assert@1.0.6": { + "integrity": "1904c05806a25d94fe791d6d883b685c9e2dcd60e4f9fc30f4fc5cf010c72207", + "dependencies": [ + "jsr:@std/internal@^1.0.4" + ] + }, "@std/bytes@0.223.0": { "integrity": "84b75052cd8680942c397c2631318772b295019098f40aac5c36cead4cba51a8" }, + "@std/data-structures@1.0.4": { + "integrity": "fa0e20c11eb9ba673417450915c750a0001405a784e2a4e0c3725031681684a0" + }, "@std/expect@1.0.3": { "integrity": "d9cbd03323ef7feafd1e969ed85d5edb04ebbd9937b0fe7a52d5ff53be8e913a", "dependencies": [ @@ -76,6 +91,13 @@ "jsr:@std/internal@^1.0.3" ] }, + "@std/expect@1.0.4": { + "integrity": "97f68a445a9de0d9670200d2b7a19a7505a01b2cb390a983ba8d97d90ce30c4f", + "dependencies": [ + "jsr:@std/assert@^1.0.6", + "jsr:@std/internal@^1.0.4" + ] + }, "@std/fmt@0.223.0": { "integrity": "6deb37794127dfc7d7bded2586b9fc6f5d50e62a8134846608baf71ffc1a5208" }, @@ -97,9 +119,18 @@ "jsr:@std/path@^1.0.4" ] }, + "@std/fs@1.0.4": { + "integrity": "2907d32d8d1d9e540588fd5fe0ec21ee638134bd51df327ad4e443aaef07123c", + "dependencies": [ + "jsr:@std/path@^1.0.6" + ] + }, "@std/internal@1.0.3": { "integrity": "208e9b94a3d5649bd880e9ca38b885ab7651ab5b5303a56ed25de4755fb7b11e" }, + "@std/internal@1.0.4": { + "integrity": "62e8e4911527e5e4f307741a795c0b0a9e6958d0b3790716ae71ce085f755422" + }, "@std/io@0.223.0": { "integrity": "2d8c3c2ab3a515619b90da2c6ff5ea7b75a94383259ef4d02116b228393f84f1", "dependencies": [ @@ -125,6 +156,16 @@ "@std/path@1.0.6": { "integrity": "ab2c55f902b380cf28e0eec501b4906e4c1960d13f00e11cfbcd21de15f18fed" }, + "@std/testing@1.0.3": { + "integrity": "f98c2bee53860a5916727d7e7d3abe920dd6f9edace022e2d059f00d05c2cf42", + "dependencies": [ + "jsr:@std/assert@^1.0.6", + "jsr:@std/data-structures@^1.0.4", + "jsr:@std/fs@^1.0.4", + "jsr:@std/internal@^1.0.4", + "jsr:@std/path@^1.0.6" + ] + }, "@ts-morph/bootstrap@0.24.0": { "integrity": "a826a2ef7fa8a7c3f1042df2c034d20744d94da2ee32bf29275bcd4dffd3c060", "dependencies": [ @@ -158,7 +199,8 @@ "workspace": { "dependencies": [ "jsr:@deno/dnt@^0.41.3", - "jsr:@std/expect@^1.0.3" + "jsr:@std/expect@^1.0.3", + "jsr:@std/testing@^1.0.3" ] } } diff --git a/identity/actKey.test.ts b/identity/actKey.test.ts new file mode 100644 index 0000000..831c230 --- /dev/null +++ b/identity/actKey.test.ts @@ -0,0 +1,6 @@ +import { type BlahActKeyRecord, blahActKeyRecordSchema } from "./actKey.ts"; +import { assertTypeMatchesZodSchema } from "../test/utils.ts"; + +Deno.test("type BlahActKeyRecord is accurate", () => { + assertTypeMatchesZodSchema(blahActKeyRecordSchema); +}); diff --git a/identity/actKey.ts b/identity/actKey.ts index 18a4753..9314b85 100644 --- a/identity/actKey.ts +++ b/identity/actKey.ts @@ -1,11 +1,15 @@ import z from "zod"; export const blahActKeyRecordSchema = z.object({ - typ: z.literal("use_act_key"), + typ: z.literal("user_act_key"), act_key: z.string(), expire_time: z.number().int(), comment: z.string(), }); -export type BlahActKeyRecord = z.input; -export type BlahParsedActKeyRecord = z.infer; +export type BlahActKeyRecord = { + typ: "user_act_key"; + act_key: string; + expire_time: number; + comment: string; +}; diff --git a/identity/identity.ts b/identity/identity.ts new file mode 100644 index 0000000..1dfb49f --- /dev/null +++ b/identity/identity.ts @@ -0,0 +1,9 @@ +import type { BlahSignedPayload } from "../crypto/mod.ts"; +import type { BlahActKeyRecord } from "./actKey.ts"; +import type { BlahProfile } from "./profile.ts"; + +export class BlahIdentity { + idKeyId: string; + actKeys: BlahSignedPayload[]; + profile: BlahSignedPayload; +} diff --git a/identity/identityFile.test.ts b/identity/identityFile.test.ts new file mode 100644 index 0000000..328da65 --- /dev/null +++ b/identity/identityFile.test.ts @@ -0,0 +1,9 @@ +import { + type BlahIdentityFile, + blahIdentityFileSchema, +} from "./identityFile.ts"; +import { assertTypeMatchesZodSchema } from "../test/utils.ts"; + +Deno.test("type BlahIdentityFile is accurate", () => { + assertTypeMatchesZodSchema(blahIdentityFileSchema); +}); diff --git a/identity/identityFile.ts b/identity/identityFile.ts index cec2f2c..fb7355e 100644 --- a/identity/identityFile.ts +++ b/identity/identityFile.ts @@ -1,7 +1,8 @@ import { z } from "zod"; -import { blahSignedPayloadSchemaOf } from "../crypto/mod.ts"; -import { blahActKeyRecordSchema } from "./actKey.ts"; -import { blahProfileSchema } from "./profile.ts"; +import { blahSignedPayloadSchemaOf } from "../crypto/signedPayload.ts"; +import { type BlahActKeyRecord, blahActKeyRecordSchema } from "./actKey.ts"; +import { type BlahProfile, blahProfileSchema } from "./profile.ts"; +import type { BlahSignedPayload } from "../crypto/mod.ts"; export const blahIdentityFileSchema = z.object({ id_key: z.string(), @@ -9,5 +10,8 @@ export const blahIdentityFileSchema = z.object({ profile: blahSignedPayloadSchemaOf(blahProfileSchema), }); -export type BlahIdentityFile = z.input; -export type BlahParsedIdentityFile = z.infer; +export type BlahIdentityFile = { + id_key: string; + act_keys: Array>; + profile: BlahSignedPayload; +}; diff --git a/identity/mod.ts b/identity/mod.ts index face16d..a909596 100644 --- a/identity/mod.ts +++ b/identity/mod.ts @@ -1,3 +1,3 @@ -export * from "./actKey.ts"; -export * from "./identityFile.ts"; -export * from "./profile.ts"; +export type { BlahActKeyRecord } from "./actKey.ts"; +export type { BlahIdentityFile } from "./identityFile.ts"; +export type { BlahProfile } from "./profile.ts"; diff --git a/identity/profile.test.ts b/identity/profile.test.ts new file mode 100644 index 0000000..ad0dda5 --- /dev/null +++ b/identity/profile.test.ts @@ -0,0 +1,6 @@ +import { type BlahProfile, blahProfileSchema } from "./profile.ts"; +import { assertTypeMatchesZodSchema } from "../test/utils.ts"; + +Deno.test("type BlahProfile is accurate", () => { + assertTypeMatchesZodSchema(blahProfileSchema); +}); diff --git a/identity/profile.ts b/identity/profile.ts index b814378..c61a9bf 100644 --- a/identity/profile.ts +++ b/identity/profile.ts @@ -8,5 +8,10 @@ export const blahProfileSchema = z.object({ bio: z.string().optional(), }); -export type BlahProfile = z.input; -export type BlahParsedProfile = z.infer; +export type BlahProfile = { + typ: "profile"; + preferred_chat_server_urls: string[]; + id_urls: string[]; + name: string; + bio?: string; +}; diff --git a/test/utils.ts b/test/utils.ts new file mode 100644 index 0000000..0f7784e --- /dev/null +++ b/test/utils.ts @@ -0,0 +1,10 @@ +import { assertType, type IsExact } from "@std/testing/types"; +import type { z } from "zod"; + +export function assertTypeMatchesZodSchema( + schema: z.ZodTypeAny, +) { + assertType>>( + true as IsExact>, + ); +}