@keytrace/runner 0.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (142) hide show
  1. package/README.md +139 -0
  2. package/dist/actions/css-select.d.ts +6 -0
  3. package/dist/actions/css-select.d.ts.map +1 -0
  4. package/dist/actions/css-select.js +14 -0
  5. package/dist/actions/css-select.js.map +1 -0
  6. package/dist/actions/dns-txt.d.ts +6 -0
  7. package/dist/actions/dns-txt.d.ts.map +1 -0
  8. package/dist/actions/dns-txt.js +17 -0
  9. package/dist/actions/dns-txt.js.map +1 -0
  10. package/dist/actions/http-get.d.ts +6 -0
  11. package/dist/actions/http-get.d.ts.map +1 -0
  12. package/dist/actions/http-get.js +19 -0
  13. package/dist/actions/http-get.js.map +1 -0
  14. package/dist/actions/index.d.ts +6 -0
  15. package/dist/actions/index.d.ts.map +1 -0
  16. package/dist/actions/index.js +6 -0
  17. package/dist/actions/index.js.map +1 -0
  18. package/dist/actions/json-path.d.ts +12 -0
  19. package/dist/actions/json-path.d.ts.map +1 -0
  20. package/dist/actions/json-path.js +26 -0
  21. package/dist/actions/json-path.js.map +1 -0
  22. package/dist/actions/regex-match.d.ts +6 -0
  23. package/dist/actions/regex-match.d.ts.map +1 -0
  24. package/dist/actions/regex-match.js +14 -0
  25. package/dist/actions/regex-match.js.map +1 -0
  26. package/dist/claim.d.ts +38 -0
  27. package/dist/claim.d.ts.map +1 -0
  28. package/dist/claim.js +253 -0
  29. package/dist/claim.js.map +1 -0
  30. package/dist/constants.d.ts +17 -0
  31. package/dist/constants.d.ts.map +1 -0
  32. package/dist/constants.js +17 -0
  33. package/dist/constants.js.map +1 -0
  34. package/dist/expect.d.ts +12 -0
  35. package/dist/expect.d.ts.map +1 -0
  36. package/dist/expect.js +33 -0
  37. package/dist/expect.js.map +1 -0
  38. package/dist/fetchers/activitypub.d.ts +25 -0
  39. package/dist/fetchers/activitypub.d.ts.map +1 -0
  40. package/dist/fetchers/activitypub.js +32 -0
  41. package/dist/fetchers/activitypub.js.map +1 -0
  42. package/dist/fetchers/dns.d.ts +21 -0
  43. package/dist/fetchers/dns.d.ts.map +1 -0
  44. package/dist/fetchers/dns.js +61 -0
  45. package/dist/fetchers/dns.js.map +1 -0
  46. package/dist/fetchers/http.d.ts +10 -0
  47. package/dist/fetchers/http.d.ts.map +1 -0
  48. package/dist/fetchers/http.js +30 -0
  49. package/dist/fetchers/http.js.map +1 -0
  50. package/dist/fetchers/index.d.ts +16 -0
  51. package/dist/fetchers/index.d.ts.map +1 -0
  52. package/dist/fetchers/index.js +22 -0
  53. package/dist/fetchers/index.js.map +1 -0
  54. package/dist/index.d.ts +21 -0
  55. package/dist/index.d.ts.map +1 -0
  56. package/dist/index.js +26 -0
  57. package/dist/index.js.map +1 -0
  58. package/dist/interpolate.d.ts +12 -0
  59. package/dist/interpolate.d.ts.map +1 -0
  60. package/dist/interpolate.js +23 -0
  61. package/dist/interpolate.js.map +1 -0
  62. package/dist/profile.d.ts +42 -0
  63. package/dist/profile.d.ts.map +1 -0
  64. package/dist/profile.js +176 -0
  65. package/dist/profile.js.map +1 -0
  66. package/dist/recipes/dns-txt.d.ts +9 -0
  67. package/dist/recipes/dns-txt.d.ts.map +1 -0
  68. package/dist/recipes/dns-txt.js +45 -0
  69. package/dist/recipes/dns-txt.js.map +1 -0
  70. package/dist/recipes/github-gist.d.ts +9 -0
  71. package/dist/recipes/github-gist.d.ts.map +1 -0
  72. package/dist/recipes/github-gist.js +52 -0
  73. package/dist/recipes/github-gist.js.map +1 -0
  74. package/dist/recipes/index.d.ts +3 -0
  75. package/dist/recipes/index.d.ts.map +1 -0
  76. package/dist/recipes/index.js +3 -0
  77. package/dist/recipes/index.js.map +1 -0
  78. package/dist/runner.d.ts +7 -0
  79. package/dist/runner.d.ts.map +1 -0
  80. package/dist/runner.js +100 -0
  81. package/dist/runner.js.map +1 -0
  82. package/dist/serviceProviders/activitypub.d.ts +10 -0
  83. package/dist/serviceProviders/activitypub.d.ts.map +1 -0
  84. package/dist/serviceProviders/activitypub.js +73 -0
  85. package/dist/serviceProviders/activitypub.js.map +1 -0
  86. package/dist/serviceProviders/bsky.d.ts +10 -0
  87. package/dist/serviceProviders/bsky.d.ts.map +1 -0
  88. package/dist/serviceProviders/bsky.js +63 -0
  89. package/dist/serviceProviders/bsky.js.map +1 -0
  90. package/dist/serviceProviders/dns.d.ts +10 -0
  91. package/dist/serviceProviders/dns.d.ts.map +1 -0
  92. package/dist/serviceProviders/dns.js +65 -0
  93. package/dist/serviceProviders/dns.js.map +1 -0
  94. package/dist/serviceProviders/github.d.ts +10 -0
  95. package/dist/serviceProviders/github.d.ts.map +1 -0
  96. package/dist/serviceProviders/github.js +100 -0
  97. package/dist/serviceProviders/github.js.map +1 -0
  98. package/dist/serviceProviders/index.d.ts +26 -0
  99. package/dist/serviceProviders/index.d.ts.map +1 -0
  100. package/dist/serviceProviders/index.js +55 -0
  101. package/dist/serviceProviders/index.js.map +1 -0
  102. package/dist/serviceProviders/npm.d.ts +10 -0
  103. package/dist/serviceProviders/npm.d.ts.map +1 -0
  104. package/dist/serviceProviders/npm.js +99 -0
  105. package/dist/serviceProviders/npm.js.map +1 -0
  106. package/dist/serviceProviders/types.d.ts +106 -0
  107. package/dist/serviceProviders/types.d.ts.map +1 -0
  108. package/dist/serviceProviders/types.js +2 -0
  109. package/dist/serviceProviders/types.js.map +1 -0
  110. package/dist/types.d.ts +165 -0
  111. package/dist/types.d.ts.map +1 -0
  112. package/dist/types.js +12 -0
  113. package/dist/types.js.map +1 -0
  114. package/package.json +37 -0
  115. package/src/actions/css-select.ts +14 -0
  116. package/src/actions/dns-txt.ts +16 -0
  117. package/src/actions/http-get.ts +19 -0
  118. package/src/actions/index.ts +5 -0
  119. package/src/actions/json-path.ts +29 -0
  120. package/src/actions/regex-match.ts +13 -0
  121. package/src/claim.ts +293 -0
  122. package/src/constants.ts +19 -0
  123. package/src/expect.ts +36 -0
  124. package/src/fetchers/activitypub.ts +53 -0
  125. package/src/fetchers/dns.ts +82 -0
  126. package/src/fetchers/http.ts +38 -0
  127. package/src/fetchers/index.ts +30 -0
  128. package/src/index.ts +57 -0
  129. package/src/interpolate.ts +20 -0
  130. package/src/profile.ts +229 -0
  131. package/src/recipes/dns-txt.ts +46 -0
  132. package/src/recipes/github-gist.ts +53 -0
  133. package/src/recipes/index.ts +2 -0
  134. package/src/runner.ts +116 -0
  135. package/src/serviceProviders/activitypub.ts +84 -0
  136. package/src/serviceProviders/bsky.ts +73 -0
  137. package/src/serviceProviders/dns.ts +75 -0
  138. package/src/serviceProviders/github.ts +112 -0
  139. package/src/serviceProviders/index.ts +65 -0
  140. package/src/serviceProviders/npm.ts +116 -0
  141. package/src/serviceProviders/types.ts +121 -0
  142. package/src/types.ts +181 -0
@@ -0,0 +1,121 @@
1
+ /**
2
+ * A match between a URI and a service provider
3
+ */
4
+ export interface ServiceProviderMatch {
5
+ provider: ServiceProvider;
6
+ match: RegExpMatchArray;
7
+ isAmbiguous: boolean;
8
+ }
9
+
10
+ /**
11
+ * Where to look for proof in the fetched response
12
+ */
13
+ export interface ProofTarget {
14
+ /** JSON path to search for proof (e.g., ['description'], ['files', '*', 'content']) */
15
+ path: string[];
16
+ /** How to match: 'contains', 'equals', 'startsWith' */
17
+ relation: "contains" | "equals" | "startsWith";
18
+ /** Format of data at path */
19
+ format: "text" | "uri" | "json";
20
+ }
21
+
22
+ /**
23
+ * How to fetch the proof
24
+ */
25
+ export interface ProofRequest {
26
+ /** URL template with {placeholders} */
27
+ uri: string;
28
+ /** Fetcher to use: 'http', 'dns', 'activitypub' */
29
+ fetcher: string;
30
+ /** Expected response format */
31
+ format: "json" | "text";
32
+ /** Additional fetch options */
33
+ options?: {
34
+ headers?: Record<string, string>;
35
+ };
36
+ }
37
+
38
+ /**
39
+ * Result of processing a URI
40
+ */
41
+ export interface ProcessedURI {
42
+ /** Profile display info */
43
+ profile: {
44
+ /** Display name for the identity (e.g., username, domain) */
45
+ display: string;
46
+ /** URL to the identity's profile page */
47
+ uri: string;
48
+ };
49
+ /** How to fetch and verify the proof */
50
+ proof: {
51
+ request: ProofRequest;
52
+ target: ProofTarget[];
53
+ };
54
+ }
55
+
56
+ /**
57
+ * UI configuration for the add claim wizard
58
+ */
59
+ export interface ServiceProviderUI {
60
+ /** Short description for service picker (e.g., "Link via a public gist") */
61
+ description: string;
62
+ /** Lucide icon name (e.g., "github", "globe") */
63
+ icon: string;
64
+ /** Label for the claim URI input field */
65
+ inputLabel: string;
66
+ /** Placeholder text for the claim URI input */
67
+ inputPlaceholder: string;
68
+ /** Default value template for input. Supports {did}, {handle}, {slugHandle} placeholders */
69
+ inputDefaultTemplate?: string;
70
+ /** Step-by-step instructions (markdown supported) */
71
+ instructions: string[];
72
+ /** Template for proof content. Supports {did} and {handle} placeholders */
73
+ proofTemplate: string;
74
+ }
75
+
76
+ /**
77
+ * A service provider that can verify identity claims
78
+ */
79
+ export interface ServiceProvider {
80
+ /** Unique identifier */
81
+ id: string;
82
+ /** Display name */
83
+ name: string;
84
+ /** Homepage URL */
85
+ homepage: string;
86
+
87
+ /** Regex to match claim URIs */
88
+ reUri: RegExp;
89
+
90
+ /** Whether matches are potentially ambiguous (could match multiple providers) */
91
+ isAmbiguous?: boolean;
92
+
93
+ /** UI configuration for the add claim wizard */
94
+ ui: ServiceProviderUI;
95
+
96
+ /** Process matched URI into verification config */
97
+ processURI(uri: string, match: RegExpMatchArray): ProcessedURI;
98
+
99
+ /** Optional post-processing after fetch to extract identity metadata */
100
+ postprocess?(
101
+ data: unknown,
102
+ match: RegExpMatchArray,
103
+ ): {
104
+ subject?: string;
105
+ avatarUrl?: string;
106
+ profileUrl?: string;
107
+ displayName?: string;
108
+ };
109
+
110
+ /** Generate proof text for user to add to their profile */
111
+ getProofText(did: string, handle?: string): string;
112
+
113
+ /** Human-readable instructions for where to place the proof */
114
+ getProofLocation?(match: RegExpMatchArray): string;
115
+
116
+ /** Test cases for validation */
117
+ tests: {
118
+ uri: string;
119
+ shouldMatch: boolean;
120
+ }[];
121
+ }
package/src/types.ts ADDED
@@ -0,0 +1,181 @@
1
+ /**
2
+ * Identity metadata extracted during verification
3
+ */
4
+ export interface IdentityMetadata {
5
+ /** Display name / username */
6
+ subject?: string;
7
+ /** Avatar/profile image URL */
8
+ avatarUrl?: string;
9
+ /** Profile page URL */
10
+ profileUrl?: string;
11
+ /** Display name if different from subject */
12
+ displayName?: string;
13
+ }
14
+
15
+ /**
16
+ * Details about a single proof target check
17
+ */
18
+ export interface ProofTargetResult {
19
+ path: string[];
20
+ relation: string;
21
+ valuesFound: string[];
22
+ matched: boolean;
23
+ }
24
+
25
+ /**
26
+ * Details about the proof fetching and matching process
27
+ */
28
+ export interface ProofDetails {
29
+ /** The URL that was fetched */
30
+ fetchUrl: string;
31
+ /** The fetcher used (http, dns, etc.) */
32
+ fetcher: string;
33
+ /** Raw content that was fetched (truncated if large) */
34
+ content: string;
35
+ /** The proof targets that were checked */
36
+ targets: ProofTargetResult[];
37
+ /** The patterns used for matching (DID variations) */
38
+ patterns: string[];
39
+ }
40
+
41
+ /**
42
+ * Result of verifying a claim
43
+ */
44
+ export interface ClaimVerificationResult {
45
+ status: ClaimStatus;
46
+ errors: string[];
47
+ timestamp: Date;
48
+ /** Identity metadata extracted from the proof source */
49
+ identity?: IdentityMetadata;
50
+ /** Details about the proof fetching and verification process */
51
+ proofDetails?: ProofDetails;
52
+ }
53
+
54
+ /**
55
+ * Profile data from ATProto
56
+ */
57
+ export interface ProfileData {
58
+ did: string;
59
+ handle: string;
60
+ displayName?: string;
61
+ avatar?: string;
62
+ claims: ClaimData[];
63
+ }
64
+
65
+ /**
66
+ * Individual claim data from ATProto record
67
+ */
68
+ export interface ClaimData {
69
+ uri: string;
70
+ did: string;
71
+ type?: string;
72
+ comment?: string;
73
+ createdAt: string;
74
+ rkey: string;
75
+ identity?: IdentityMetadata;
76
+ }
77
+
78
+ /**
79
+ * Options for verification operations
80
+ */
81
+ export interface VerifyOptions {
82
+ /** Timeout for fetcher operations in ms */
83
+ timeout?: number;
84
+ /** Skip cache and force fresh verification */
85
+ skipCache?: boolean;
86
+ /** Proxy URL for browser-based DNS/HTTP requests */
87
+ proxyUrl?: string;
88
+ }
89
+
90
+ /**
91
+ * Claim status enum
92
+ */
93
+ export enum ClaimStatus {
94
+ INIT = "init",
95
+ MATCHED = "matched",
96
+ VERIFIED = "verified",
97
+ FAILED = "failed",
98
+ ERROR = "error",
99
+ }
100
+
101
+ /** Injected fetch function - allows caller to provide proxy, auth, etc. */
102
+ export type FetchFn = (url: string, init?: RequestInit) => Promise<Response>;
103
+
104
+ /** Configuration for the recipe runner */
105
+ export interface RunnerConfig {
106
+ /** Custom fetch function (defaults to global fetch) */
107
+ fetch?: FetchFn;
108
+ /** Request timeout in ms (default: 10000) */
109
+ timeout?: number;
110
+ }
111
+
112
+ /** Context for a claim verification attempt */
113
+ export interface ClaimContext {
114
+ /** Unique claim ID for this verification attempt */
115
+ claimId: string;
116
+ /** User's ATProto DID */
117
+ did: string;
118
+ /** User's ATProto handle */
119
+ handle: string;
120
+ /** User-provided params from recipe (e.g., { gistUrl: "..." }) */
121
+ params: Record<string, string>;
122
+ }
123
+
124
+ /** Result of running a full recipe verification */
125
+ export interface VerificationResult {
126
+ success: boolean;
127
+ steps: StepResult[];
128
+ /** Extracted subject from params (e.g., "github:octocat") */
129
+ subject?: string;
130
+ error?: string;
131
+ }
132
+
133
+ /** Result of a single verification step */
134
+ export interface StepResult {
135
+ action: string;
136
+ success: boolean;
137
+ data?: unknown;
138
+ error?: string;
139
+ }
140
+
141
+ /** A recipe parameter definition */
142
+ export interface RecipeParam {
143
+ key: string;
144
+ label: string;
145
+ type: "url" | "text" | "domain";
146
+ placeholder?: string;
147
+ pattern?: string;
148
+ extractFrom?: string;
149
+ }
150
+
151
+ /** User-facing instructions for how to set up a claim */
152
+ export interface RecipeInstructions {
153
+ steps: string[];
154
+ proofTemplate?: string;
155
+ proofLocation?: string;
156
+ }
157
+
158
+ /** A single verification step in a recipe */
159
+ export interface VerificationStep {
160
+ action: "http-get" | "json-path" | "css-select" | "regex-match" | "dns-txt";
161
+ url?: string;
162
+ selector?: string;
163
+ pattern?: string;
164
+ expect?: string;
165
+ }
166
+
167
+ /** Machine-readable verification definition */
168
+ export interface RecipeVerification {
169
+ steps: VerificationStep[];
170
+ }
171
+
172
+ /** A claim verification recipe */
173
+ export interface Recipe {
174
+ $type?: string;
175
+ type: string;
176
+ version: number;
177
+ displayName: string;
178
+ params?: RecipeParam[];
179
+ instructions: RecipeInstructions;
180
+ verification: RecipeVerification;
181
+ }