sliftutils 1.0.4 → 1.1.1

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.
package/.cursorrules CHANGED
@@ -29,6 +29,8 @@ The code automatically updates on save, so do not ever run commands to rerun the
29
29
  Use tool calls to read files and directories where possible, instead of running "ls", "dir", etc.
30
30
 
31
31
  Coding Styles
32
+ Times should almost always be in milliseconds, and if not told, you should assume a time is in milliseconds.
33
+
32
34
  Don't make functions that will never be reused and are short. This just makes the code too confusing. If the function is under five lines and it's not being reused, you shouldn't create it, unless instructed explicitly to create it.
33
35
 
34
36
  Comments should be used sparingly and only if it's required to explain what's being done. If you're calling a function called create imageName and the comment is called create imageName, you will be fired because that's just stupid. It's a waste of lines.
@@ -191,7 +193,7 @@ css
191
193
 
192
194
  However, there are some helper functions that will directly map to commonly used styles.
193
195
 
194
- If you want to make a NON-Button feel like a button, you can use "css.button", which makes the background color change on hover, and make the cursor a pointer. Only use this if the background color is set, otherwise you need to message it's a button in another way. And never use it for <Button> which already does this.
196
+ If you want to make a NON-Button feel like a button, you can use "css.button", which makes the background color change on hover, and make the cursor a pointer. Only use this if the background color is set, otherwise you need to message it's a button in another way. And never use it for <Button>/<button> which already does this.
195
197
 
196
198
  Generally use hbox/vbox to set the spacing between elements, instead of using margins.
197
199
 
package/.gitignore CHANGED
@@ -28,6 +28,7 @@ data
28
28
  *.gif
29
29
  *.bmp
30
30
  *.tiff
31
+ *.cert
31
32
  temp
32
33
  yarn-error.log
33
34
  pretrained_models
package/index.d.ts CHANGED
@@ -62,6 +62,149 @@ declare module "sliftutils/misc/helpers" {
62
62
 
63
63
  }
64
64
 
65
+ declare module "sliftutils/misc/https/certs" {
66
+ /// <reference path="node-forge-ed25519.d.ts" />
67
+ /// <reference path="../../storage/storage.d.ts" />
68
+ /// <reference types="node" />
69
+ /// <reference types="node" />
70
+ import * as forge from "node-forge";
71
+ import { MaybePromise } from "socket-function/src/types";
72
+ export declare const CA_NOT_FOUND_ERROR = "18aa7318-f88f-4d2d-b41f-3daf4a433827";
73
+ export declare const identityStorageKey = "machineCA_10";
74
+ export type IdentityStorageType = {
75
+ domain: string;
76
+ certB64: string;
77
+ keyB64: string;
78
+ };
79
+ export interface X509KeyPair {
80
+ domain: string;
81
+ cert: Buffer;
82
+ key: Buffer;
83
+ }
84
+ export declare function getCommonName(cert: Buffer | string): string;
85
+ export declare function createX509(config: {
86
+ domain: string;
87
+ issuer: X509KeyPair | "self";
88
+ lifeSpan: number;
89
+ keyPair: {
90
+ publicKey: forge.Ed25519PublicKey;
91
+ privateKey: forge.Ed25519PrivateKey;
92
+ } | forge.pki.KeyPair;
93
+ }): X509KeyPair;
94
+ export declare function privateKeyToPem(buffer: forge.pki.PrivateKey | forge.Ed25519PrivateKey): string;
95
+ export declare function parseCert(PEMorDER: string | Buffer): forge.pki.Certificate;
96
+ export declare function getPublicIdentifier(PEMorDER: string | Buffer): Buffer;
97
+ export declare const sign: (keyPair: {
98
+ key: string | Buffer;
99
+ }, data: unknown) => string;
100
+ export declare function verify(cert: string, signature: string, data: unknown): boolean;
101
+ export declare function validateCACert(domain: string, cert: string | Buffer): void;
102
+ export declare function validateCertificate(domain: string, cert: Buffer | string, issuerCert: Buffer | string): void;
103
+ export declare function generateKeyPair(): forge.pki.rsa.KeyPair;
104
+ export declare function generateRSAKeyPair(): forge.pki.rsa.KeyPair;
105
+ export declare function generateTestCA(domain: string): X509KeyPair;
106
+ export declare function createCertFromCA(config: {
107
+ CAKeyPair: X509KeyPair;
108
+ }): X509KeyPair;
109
+ export declare function getMachineId(domainName: string): string;
110
+ export type NodeIdParts = {
111
+ threadId: string;
112
+ machineId: string;
113
+ domain: string;
114
+ port: number;
115
+ };
116
+ export declare function decodeNodeId(nodeId: string): NodeIdParts | undefined;
117
+ export declare function decodeNodeIdAssert(nodeId: string): NodeIdParts;
118
+ export declare function encodeNodeId(parts: NodeIdParts): string;
119
+ export declare function setIdentityCARaw(domain: string, json: string): Promise<void>;
120
+ export declare function loadIdentityCA(domain: string): Promise<void>;
121
+ export declare function getIdentityCA(domain: string): X509KeyPair;
122
+ export declare function getIdentityCAPromise(domain: string): MaybePromise<X509KeyPair>;
123
+ export declare function getOwnMachineId(domain: string): string;
124
+ /** Part of the machineId comes from the publicKey, so we can use it to verify */
125
+ export declare function verifyMachineIdForPublicKey(config: {
126
+ machineId: string;
127
+ publicKey: Buffer;
128
+ }): boolean;
129
+ export declare function getThreadKeyCert(domain: string): X509KeyPair;
130
+ export declare const createTestBrowserKeyCert: {
131
+ (): Promise<X509KeyPair>;
132
+ reset(): void;
133
+ set(newValue: Promise<X509KeyPair>): void;
134
+ };
135
+ export declare function getOwnNodeId(): string;
136
+ export declare function getOwnNodeIdAllowUndefined(): string;
137
+
138
+ }
139
+
140
+ declare module "sliftutils/misc/https/dns" {
141
+ export declare function getRecordsRaw(type: string, key: string): Promise<{
142
+ id: string;
143
+ type: string;
144
+ name: string;
145
+ content: string;
146
+ proxied: boolean;
147
+ }[]>;
148
+ export declare function getRecords(type: string, key: string): Promise<string[]>;
149
+ export declare function deleteRecord(type: string, key: string, value: string): Promise<void>;
150
+ /** Removes all existing records (unless the record is already present) */
151
+ export declare function setRecord(type: string, key: string, value: string, proxied?: "proxied"): Promise<void>;
152
+ /** Keeps existing records */
153
+ export declare function addRecord(type: string, key: string, value: string, proxied?: "proxied"): Promise<void>;
154
+
155
+ }
156
+
157
+ declare module "sliftutils/misc/https/httpsCerts" {
158
+ /** NOTE: We also generate the domain *.domain */
159
+ export declare const getHTTPSCert: {
160
+ (key: string): Promise<{
161
+ key: string;
162
+ cert: string;
163
+ }>;
164
+ clear(key: string): void;
165
+ clearAll(): void;
166
+ forceSet(key: string, value: Promise<{
167
+ key: string;
168
+ cert: string;
169
+ }>): void;
170
+ getAllKeys(): string[];
171
+ get(key: string): Promise<{
172
+ key: string;
173
+ cert: string;
174
+ }> | undefined;
175
+ };
176
+
177
+ }
178
+
179
+ declare module "sliftutils/misc/https/node-forge-ed25519" {
180
+
181
+
182
+ declare module "node-forge" {
183
+ declare type Ed25519PublicKey = {
184
+ publicKeyBytes: Buffer;
185
+ } & Buffer;
186
+ declare type Ed25519PrivateKey = {
187
+ privateKeyBytes: Buffer;
188
+ } & Buffer;
189
+ class ed25519 {
190
+ static generateKeyPair(): { publicKey: Ed25519PublicKey, privateKey: Ed25519PrivateKey };
191
+ static privateKeyToPem(key: Ed25519PrivateKey): string;
192
+ static privateKeyFromPem(pem: string): Ed25519PrivateKey;
193
+ static publicKeyToPem(key: Ed25519PublicKey): string;
194
+ static publicKeyFromPem(pem: string): Ed25519PublicKey;
195
+ }
196
+ }
197
+ }
198
+
199
+ declare module "sliftutils/misc/https/persistentLocalStorage" {
200
+ import { MaybePromise } from "socket-function/src/types";
201
+ export declare function getKeyStore<T>(appName: string, key: string): {
202
+ get(): MaybePromise<T | undefined>;
203
+ set(value: T | null): MaybePromise<void>;
204
+ };
205
+
206
+ }
207
+
65
208
  declare module "sliftutils/misc/matchFilter" {
66
209
  export declare function matchFilter(filter: {
67
210
  value: string;
@@ -0,0 +1,71 @@
1
+ /// <reference path="node-forge-ed25519.d.ts" />
2
+ /// <reference path="../../storage/storage.d.ts" />
3
+ /// <reference types="node" />
4
+ /// <reference types="node" />
5
+ import * as forge from "node-forge";
6
+ import { MaybePromise } from "socket-function/src/types";
7
+ export declare const CA_NOT_FOUND_ERROR = "18aa7318-f88f-4d2d-b41f-3daf4a433827";
8
+ export declare const identityStorageKey = "machineCA_10";
9
+ export type IdentityStorageType = {
10
+ domain: string;
11
+ certB64: string;
12
+ keyB64: string;
13
+ };
14
+ export interface X509KeyPair {
15
+ domain: string;
16
+ cert: Buffer;
17
+ key: Buffer;
18
+ }
19
+ export declare function getCommonName(cert: Buffer | string): string;
20
+ export declare function createX509(config: {
21
+ domain: string;
22
+ issuer: X509KeyPair | "self";
23
+ lifeSpan: number;
24
+ keyPair: {
25
+ publicKey: forge.Ed25519PublicKey;
26
+ privateKey: forge.Ed25519PrivateKey;
27
+ } | forge.pki.KeyPair;
28
+ }): X509KeyPair;
29
+ export declare function privateKeyToPem(buffer: forge.pki.PrivateKey | forge.Ed25519PrivateKey): string;
30
+ export declare function parseCert(PEMorDER: string | Buffer): forge.pki.Certificate;
31
+ export declare function getPublicIdentifier(PEMorDER: string | Buffer): Buffer;
32
+ export declare const sign: (keyPair: {
33
+ key: string | Buffer;
34
+ }, data: unknown) => string;
35
+ export declare function verify(cert: string, signature: string, data: unknown): boolean;
36
+ export declare function validateCACert(domain: string, cert: string | Buffer): void;
37
+ export declare function validateCertificate(domain: string, cert: Buffer | string, issuerCert: Buffer | string): void;
38
+ export declare function generateKeyPair(): forge.pki.rsa.KeyPair;
39
+ export declare function generateRSAKeyPair(): forge.pki.rsa.KeyPair;
40
+ export declare function generateTestCA(domain: string): X509KeyPair;
41
+ export declare function createCertFromCA(config: {
42
+ CAKeyPair: X509KeyPair;
43
+ }): X509KeyPair;
44
+ export declare function getMachineId(domainName: string): string;
45
+ export type NodeIdParts = {
46
+ threadId: string;
47
+ machineId: string;
48
+ domain: string;
49
+ port: number;
50
+ };
51
+ export declare function decodeNodeId(nodeId: string): NodeIdParts | undefined;
52
+ export declare function decodeNodeIdAssert(nodeId: string): NodeIdParts;
53
+ export declare function encodeNodeId(parts: NodeIdParts): string;
54
+ export declare function setIdentityCARaw(domain: string, json: string): Promise<void>;
55
+ export declare function loadIdentityCA(domain: string): Promise<void>;
56
+ export declare function getIdentityCA(domain: string): X509KeyPair;
57
+ export declare function getIdentityCAPromise(domain: string): MaybePromise<X509KeyPair>;
58
+ export declare function getOwnMachineId(domain: string): string;
59
+ /** Part of the machineId comes from the publicKey, so we can use it to verify */
60
+ export declare function verifyMachineIdForPublicKey(config: {
61
+ machineId: string;
62
+ publicKey: Buffer;
63
+ }): boolean;
64
+ export declare function getThreadKeyCert(domain: string): X509KeyPair;
65
+ export declare const createTestBrowserKeyCert: {
66
+ (): Promise<X509KeyPair>;
67
+ reset(): void;
68
+ set(newValue: Promise<X509KeyPair>): void;
69
+ };
70
+ export declare function getOwnNodeId(): string;
71
+ export declare function getOwnNodeIdAllowUndefined(): string;