ctes-models-ts 0.0.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/README.md +9 -0
- package/generate.sh +11 -0
- package/index.ts +394 -0
- package/package.json +13 -0
package/README.md
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
# Ciphertext Ecosystem TypeScript Models
|
|
2
|
+
|
|
3
|
+
This dependency defines the models for the ciphertext ecosystem, used for building tools that will help solve unsolved ciphers.
|
|
4
|
+
|
|
5
|
+
## Generating the model
|
|
6
|
+
|
|
7
|
+
Requires installing the [Protoc CLI](https://protobuf.dev/installation/).
|
|
8
|
+
|
|
9
|
+
Run `npm install` then `npm run generate` to generate the latest version of the model.
|
package/generate.sh
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
git clone git@github.com:irebased/CiphertextEcosystemProtobuf.git
|
|
2
|
+
cd CiphertextEcosystemProtobuf
|
|
3
|
+
protoc \
|
|
4
|
+
--plugin=protoc-gen-ts_proto=../node_modules/.bin/protoc-gen-ts_proto \
|
|
5
|
+
--ts_proto_out=../ \
|
|
6
|
+
--ts_proto_opt=esModuleInterop=true,forceLong=string,useOptionals=true \
|
|
7
|
+
./model/ciphertext.proto
|
|
8
|
+
cd ..
|
|
9
|
+
mv model/ciphertext.ts index.ts
|
|
10
|
+
rm -rf model
|
|
11
|
+
rm -rf CiphertextEcosystemProtobuf
|
package/index.ts
ADDED
|
@@ -0,0 +1,394 @@
|
|
|
1
|
+
// Code generated by protoc-gen-ts_proto. DO NOT EDIT.
|
|
2
|
+
// versions:
|
|
3
|
+
// protoc-gen-ts_proto v2.11.0
|
|
4
|
+
// protoc v6.33.4
|
|
5
|
+
// source: model/ciphertext.proto
|
|
6
|
+
|
|
7
|
+
/* eslint-disable */
|
|
8
|
+
import { BinaryReader, BinaryWriter } from "@bufbuild/protobuf/wire";
|
|
9
|
+
|
|
10
|
+
export const protobufPackage = "model.ciphertext";
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Enum for representing encoding types.
|
|
14
|
+
* Can be extended for additional encoding support.
|
|
15
|
+
*/
|
|
16
|
+
export enum Encoding {
|
|
17
|
+
ENCODING_UNSPECIFIED = 0,
|
|
18
|
+
BASE_CONVERSION = 1,
|
|
19
|
+
ASCII = 2,
|
|
20
|
+
LATIN1 = 3,
|
|
21
|
+
UTF8 = 4,
|
|
22
|
+
UTF16 = 5,
|
|
23
|
+
UTF32 = 6,
|
|
24
|
+
UNRECOGNIZED = -1,
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export function encodingFromJSON(object: any): Encoding {
|
|
28
|
+
switch (object) {
|
|
29
|
+
case 0:
|
|
30
|
+
case "ENCODING_UNSPECIFIED":
|
|
31
|
+
return Encoding.ENCODING_UNSPECIFIED;
|
|
32
|
+
case 1:
|
|
33
|
+
case "BASE_CONVERSION":
|
|
34
|
+
return Encoding.BASE_CONVERSION;
|
|
35
|
+
case 2:
|
|
36
|
+
case "ASCII":
|
|
37
|
+
return Encoding.ASCII;
|
|
38
|
+
case 3:
|
|
39
|
+
case "LATIN1":
|
|
40
|
+
return Encoding.LATIN1;
|
|
41
|
+
case 4:
|
|
42
|
+
case "UTF8":
|
|
43
|
+
return Encoding.UTF8;
|
|
44
|
+
case 5:
|
|
45
|
+
case "UTF16":
|
|
46
|
+
return Encoding.UTF16;
|
|
47
|
+
case 6:
|
|
48
|
+
case "UTF32":
|
|
49
|
+
return Encoding.UTF32;
|
|
50
|
+
case -1:
|
|
51
|
+
case "UNRECOGNIZED":
|
|
52
|
+
default:
|
|
53
|
+
return Encoding.UNRECOGNIZED;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export function encodingToJSON(object: Encoding): string {
|
|
58
|
+
switch (object) {
|
|
59
|
+
case Encoding.ENCODING_UNSPECIFIED:
|
|
60
|
+
return "ENCODING_UNSPECIFIED";
|
|
61
|
+
case Encoding.BASE_CONVERSION:
|
|
62
|
+
return "BASE_CONVERSION";
|
|
63
|
+
case Encoding.ASCII:
|
|
64
|
+
return "ASCII";
|
|
65
|
+
case Encoding.LATIN1:
|
|
66
|
+
return "LATIN1";
|
|
67
|
+
case Encoding.UTF8:
|
|
68
|
+
return "UTF8";
|
|
69
|
+
case Encoding.UTF16:
|
|
70
|
+
return "UTF16";
|
|
71
|
+
case Encoding.UTF32:
|
|
72
|
+
return "UTF32";
|
|
73
|
+
case Encoding.UNRECOGNIZED:
|
|
74
|
+
default:
|
|
75
|
+
return "UNRECOGNIZED";
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/** Represents a ciphertext input and its metadata. */
|
|
80
|
+
export interface Ciphertext {
|
|
81
|
+
/**
|
|
82
|
+
* The ciphertext must always be transmitted in binary format.
|
|
83
|
+
* If the ciphertext is encoded, please decode it to a bitstream first.
|
|
84
|
+
*/
|
|
85
|
+
bytes: Uint8Array;
|
|
86
|
+
metadata?: CiphertextMetadata | undefined;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Metadata associated with the ciphertext.
|
|
91
|
+
* This structure is designed to be extensible.
|
|
92
|
+
*/
|
|
93
|
+
export interface CiphertextMetadata {
|
|
94
|
+
/**
|
|
95
|
+
* Generic type tagging so downstream tools can handle custom types of data,
|
|
96
|
+
* e.g. "Semaphore" for tools designed to interface with semaphore ciphers.
|
|
97
|
+
*/
|
|
98
|
+
type: string;
|
|
99
|
+
/** Metadata about how the bytes should be encoded. */
|
|
100
|
+
encoding?: EncodingMetadata | undefined;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/** Metadata about how the bytes should be encoded. */
|
|
104
|
+
export interface EncodingMetadata {
|
|
105
|
+
/** How a given ciphertext blob should be encoded. */
|
|
106
|
+
encoding: Encoding;
|
|
107
|
+
/**
|
|
108
|
+
* If the Encoding is BASE_CONVERSION, the base will specify which base to convert to;
|
|
109
|
+
* e.g., 2 for binary, 8 for octal, 10 for decimal, 16 for hexadecimal, 64 for base64.
|
|
110
|
+
*/
|
|
111
|
+
base: number;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
function createBaseCiphertext(): Ciphertext {
|
|
115
|
+
return { bytes: new Uint8Array(0), metadata: undefined };
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
export const Ciphertext: MessageFns<Ciphertext> = {
|
|
119
|
+
encode(message: Ciphertext, writer: BinaryWriter = new BinaryWriter()): BinaryWriter {
|
|
120
|
+
if (message.bytes.length !== 0) {
|
|
121
|
+
writer.uint32(10).bytes(message.bytes);
|
|
122
|
+
}
|
|
123
|
+
if (message.metadata !== undefined) {
|
|
124
|
+
CiphertextMetadata.encode(message.metadata, writer.uint32(18).fork()).join();
|
|
125
|
+
}
|
|
126
|
+
return writer;
|
|
127
|
+
},
|
|
128
|
+
|
|
129
|
+
decode(input: BinaryReader | Uint8Array, length?: number): Ciphertext {
|
|
130
|
+
const reader = input instanceof BinaryReader ? input : new BinaryReader(input);
|
|
131
|
+
const end = length === undefined ? reader.len : reader.pos + length;
|
|
132
|
+
const message = createBaseCiphertext();
|
|
133
|
+
while (reader.pos < end) {
|
|
134
|
+
const tag = reader.uint32();
|
|
135
|
+
switch (tag >>> 3) {
|
|
136
|
+
case 1: {
|
|
137
|
+
if (tag !== 10) {
|
|
138
|
+
break;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
message.bytes = reader.bytes();
|
|
142
|
+
continue;
|
|
143
|
+
}
|
|
144
|
+
case 2: {
|
|
145
|
+
if (tag !== 18) {
|
|
146
|
+
break;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
message.metadata = CiphertextMetadata.decode(reader, reader.uint32());
|
|
150
|
+
continue;
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
if ((tag & 7) === 4 || tag === 0) {
|
|
154
|
+
break;
|
|
155
|
+
}
|
|
156
|
+
reader.skip(tag & 7);
|
|
157
|
+
}
|
|
158
|
+
return message;
|
|
159
|
+
},
|
|
160
|
+
|
|
161
|
+
fromJSON(object: any): Ciphertext {
|
|
162
|
+
return {
|
|
163
|
+
bytes: isSet(object.bytes) ? bytesFromBase64(object.bytes) : new Uint8Array(0),
|
|
164
|
+
metadata: isSet(object.metadata) ? CiphertextMetadata.fromJSON(object.metadata) : undefined,
|
|
165
|
+
};
|
|
166
|
+
},
|
|
167
|
+
|
|
168
|
+
toJSON(message: Ciphertext): unknown {
|
|
169
|
+
const obj: any = {};
|
|
170
|
+
if (message.bytes.length !== 0) {
|
|
171
|
+
obj.bytes = base64FromBytes(message.bytes);
|
|
172
|
+
}
|
|
173
|
+
if (message.metadata !== undefined) {
|
|
174
|
+
obj.metadata = CiphertextMetadata.toJSON(message.metadata);
|
|
175
|
+
}
|
|
176
|
+
return obj;
|
|
177
|
+
},
|
|
178
|
+
|
|
179
|
+
create<I extends Exact<DeepPartial<Ciphertext>, I>>(base?: I): Ciphertext {
|
|
180
|
+
return Ciphertext.fromPartial(base ?? ({} as any));
|
|
181
|
+
},
|
|
182
|
+
fromPartial<I extends Exact<DeepPartial<Ciphertext>, I>>(object: I): Ciphertext {
|
|
183
|
+
const message = createBaseCiphertext();
|
|
184
|
+
message.bytes = object.bytes ?? new Uint8Array(0);
|
|
185
|
+
message.metadata = (object.metadata !== undefined && object.metadata !== null)
|
|
186
|
+
? CiphertextMetadata.fromPartial(object.metadata)
|
|
187
|
+
: undefined;
|
|
188
|
+
return message;
|
|
189
|
+
},
|
|
190
|
+
};
|
|
191
|
+
|
|
192
|
+
function createBaseCiphertextMetadata(): CiphertextMetadata {
|
|
193
|
+
return { type: "", encoding: undefined };
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
export const CiphertextMetadata: MessageFns<CiphertextMetadata> = {
|
|
197
|
+
encode(message: CiphertextMetadata, writer: BinaryWriter = new BinaryWriter()): BinaryWriter {
|
|
198
|
+
if (message.type !== "") {
|
|
199
|
+
writer.uint32(10).string(message.type);
|
|
200
|
+
}
|
|
201
|
+
if (message.encoding !== undefined) {
|
|
202
|
+
EncodingMetadata.encode(message.encoding, writer.uint32(18).fork()).join();
|
|
203
|
+
}
|
|
204
|
+
return writer;
|
|
205
|
+
},
|
|
206
|
+
|
|
207
|
+
decode(input: BinaryReader | Uint8Array, length?: number): CiphertextMetadata {
|
|
208
|
+
const reader = input instanceof BinaryReader ? input : new BinaryReader(input);
|
|
209
|
+
const end = length === undefined ? reader.len : reader.pos + length;
|
|
210
|
+
const message = createBaseCiphertextMetadata();
|
|
211
|
+
while (reader.pos < end) {
|
|
212
|
+
const tag = reader.uint32();
|
|
213
|
+
switch (tag >>> 3) {
|
|
214
|
+
case 1: {
|
|
215
|
+
if (tag !== 10) {
|
|
216
|
+
break;
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
message.type = reader.string();
|
|
220
|
+
continue;
|
|
221
|
+
}
|
|
222
|
+
case 2: {
|
|
223
|
+
if (tag !== 18) {
|
|
224
|
+
break;
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
message.encoding = EncodingMetadata.decode(reader, reader.uint32());
|
|
228
|
+
continue;
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
if ((tag & 7) === 4 || tag === 0) {
|
|
232
|
+
break;
|
|
233
|
+
}
|
|
234
|
+
reader.skip(tag & 7);
|
|
235
|
+
}
|
|
236
|
+
return message;
|
|
237
|
+
},
|
|
238
|
+
|
|
239
|
+
fromJSON(object: any): CiphertextMetadata {
|
|
240
|
+
return {
|
|
241
|
+
type: isSet(object.type) ? globalThis.String(object.type) : "",
|
|
242
|
+
encoding: isSet(object.encoding) ? EncodingMetadata.fromJSON(object.encoding) : undefined,
|
|
243
|
+
};
|
|
244
|
+
},
|
|
245
|
+
|
|
246
|
+
toJSON(message: CiphertextMetadata): unknown {
|
|
247
|
+
const obj: any = {};
|
|
248
|
+
if (message.type !== "") {
|
|
249
|
+
obj.type = message.type;
|
|
250
|
+
}
|
|
251
|
+
if (message.encoding !== undefined) {
|
|
252
|
+
obj.encoding = EncodingMetadata.toJSON(message.encoding);
|
|
253
|
+
}
|
|
254
|
+
return obj;
|
|
255
|
+
},
|
|
256
|
+
|
|
257
|
+
create<I extends Exact<DeepPartial<CiphertextMetadata>, I>>(base?: I): CiphertextMetadata {
|
|
258
|
+
return CiphertextMetadata.fromPartial(base ?? ({} as any));
|
|
259
|
+
},
|
|
260
|
+
fromPartial<I extends Exact<DeepPartial<CiphertextMetadata>, I>>(object: I): CiphertextMetadata {
|
|
261
|
+
const message = createBaseCiphertextMetadata();
|
|
262
|
+
message.type = object.type ?? "";
|
|
263
|
+
message.encoding = (object.encoding !== undefined && object.encoding !== null)
|
|
264
|
+
? EncodingMetadata.fromPartial(object.encoding)
|
|
265
|
+
: undefined;
|
|
266
|
+
return message;
|
|
267
|
+
},
|
|
268
|
+
};
|
|
269
|
+
|
|
270
|
+
function createBaseEncodingMetadata(): EncodingMetadata {
|
|
271
|
+
return { encoding: 0, base: 0 };
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
export const EncodingMetadata: MessageFns<EncodingMetadata> = {
|
|
275
|
+
encode(message: EncodingMetadata, writer: BinaryWriter = new BinaryWriter()): BinaryWriter {
|
|
276
|
+
if (message.encoding !== 0) {
|
|
277
|
+
writer.uint32(8).int32(message.encoding);
|
|
278
|
+
}
|
|
279
|
+
if (message.base !== 0) {
|
|
280
|
+
writer.uint32(16).int32(message.base);
|
|
281
|
+
}
|
|
282
|
+
return writer;
|
|
283
|
+
},
|
|
284
|
+
|
|
285
|
+
decode(input: BinaryReader | Uint8Array, length?: number): EncodingMetadata {
|
|
286
|
+
const reader = input instanceof BinaryReader ? input : new BinaryReader(input);
|
|
287
|
+
const end = length === undefined ? reader.len : reader.pos + length;
|
|
288
|
+
const message = createBaseEncodingMetadata();
|
|
289
|
+
while (reader.pos < end) {
|
|
290
|
+
const tag = reader.uint32();
|
|
291
|
+
switch (tag >>> 3) {
|
|
292
|
+
case 1: {
|
|
293
|
+
if (tag !== 8) {
|
|
294
|
+
break;
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
message.encoding = reader.int32() as any;
|
|
298
|
+
continue;
|
|
299
|
+
}
|
|
300
|
+
case 2: {
|
|
301
|
+
if (tag !== 16) {
|
|
302
|
+
break;
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
message.base = reader.int32();
|
|
306
|
+
continue;
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
if ((tag & 7) === 4 || tag === 0) {
|
|
310
|
+
break;
|
|
311
|
+
}
|
|
312
|
+
reader.skip(tag & 7);
|
|
313
|
+
}
|
|
314
|
+
return message;
|
|
315
|
+
},
|
|
316
|
+
|
|
317
|
+
fromJSON(object: any): EncodingMetadata {
|
|
318
|
+
return {
|
|
319
|
+
encoding: isSet(object.encoding) ? encodingFromJSON(object.encoding) : 0,
|
|
320
|
+
base: isSet(object.base) ? globalThis.Number(object.base) : 0,
|
|
321
|
+
};
|
|
322
|
+
},
|
|
323
|
+
|
|
324
|
+
toJSON(message: EncodingMetadata): unknown {
|
|
325
|
+
const obj: any = {};
|
|
326
|
+
if (message.encoding !== 0) {
|
|
327
|
+
obj.encoding = encodingToJSON(message.encoding);
|
|
328
|
+
}
|
|
329
|
+
if (message.base !== 0) {
|
|
330
|
+
obj.base = Math.round(message.base);
|
|
331
|
+
}
|
|
332
|
+
return obj;
|
|
333
|
+
},
|
|
334
|
+
|
|
335
|
+
create<I extends Exact<DeepPartial<EncodingMetadata>, I>>(base?: I): EncodingMetadata {
|
|
336
|
+
return EncodingMetadata.fromPartial(base ?? ({} as any));
|
|
337
|
+
},
|
|
338
|
+
fromPartial<I extends Exact<DeepPartial<EncodingMetadata>, I>>(object: I): EncodingMetadata {
|
|
339
|
+
const message = createBaseEncodingMetadata();
|
|
340
|
+
message.encoding = object.encoding ?? 0;
|
|
341
|
+
message.base = object.base ?? 0;
|
|
342
|
+
return message;
|
|
343
|
+
},
|
|
344
|
+
};
|
|
345
|
+
|
|
346
|
+
function bytesFromBase64(b64: string): Uint8Array {
|
|
347
|
+
if ((globalThis as any).Buffer) {
|
|
348
|
+
return Uint8Array.from(globalThis.Buffer.from(b64, "base64"));
|
|
349
|
+
} else {
|
|
350
|
+
const bin = globalThis.atob(b64);
|
|
351
|
+
const arr = new Uint8Array(bin.length);
|
|
352
|
+
for (let i = 0; i < bin.length; ++i) {
|
|
353
|
+
arr[i] = bin.charCodeAt(i);
|
|
354
|
+
}
|
|
355
|
+
return arr;
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
function base64FromBytes(arr: Uint8Array): string {
|
|
360
|
+
if ((globalThis as any).Buffer) {
|
|
361
|
+
return globalThis.Buffer.from(arr).toString("base64");
|
|
362
|
+
} else {
|
|
363
|
+
const bin: string[] = [];
|
|
364
|
+
arr.forEach((byte) => {
|
|
365
|
+
bin.push(globalThis.String.fromCharCode(byte));
|
|
366
|
+
});
|
|
367
|
+
return globalThis.btoa(bin.join(""));
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
type Builtin = Date | Function | Uint8Array | string | number | boolean | undefined;
|
|
372
|
+
|
|
373
|
+
export type DeepPartial<T> = T extends Builtin ? T
|
|
374
|
+
: T extends globalThis.Array<infer U> ? globalThis.Array<DeepPartial<U>>
|
|
375
|
+
: T extends ReadonlyArray<infer U> ? ReadonlyArray<DeepPartial<U>>
|
|
376
|
+
: T extends {} ? { [K in keyof T]?: DeepPartial<T[K]> }
|
|
377
|
+
: Partial<T>;
|
|
378
|
+
|
|
379
|
+
type KeysOfUnion<T> = T extends T ? keyof T : never;
|
|
380
|
+
export type Exact<P, I extends P> = P extends Builtin ? P
|
|
381
|
+
: P & { [K in keyof P]: Exact<P[K], I[K]> } & { [K in Exclude<keyof I, KeysOfUnion<P>>]: never };
|
|
382
|
+
|
|
383
|
+
function isSet(value: any): boolean {
|
|
384
|
+
return value !== null && value !== undefined;
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
export interface MessageFns<T> {
|
|
388
|
+
encode(message: T, writer?: BinaryWriter): BinaryWriter;
|
|
389
|
+
decode(input: BinaryReader | Uint8Array, length?: number): T;
|
|
390
|
+
fromJSON(object: any): T;
|
|
391
|
+
toJSON(message: T): unknown;
|
|
392
|
+
create<I extends Exact<DeepPartial<T>, I>>(base?: I): T;
|
|
393
|
+
fromPartial<I extends Exact<DeepPartial<T>, I>>(object: I): T;
|
|
394
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "ctes-models-ts",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "Ciphertext Ecosystem models.",
|
|
5
|
+
"author": "irebased <rebased.again@gmail.com>",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"scripts": {
|
|
8
|
+
"generate": ". ./generate.sh"
|
|
9
|
+
},
|
|
10
|
+
"devDependencies": {
|
|
11
|
+
"ts-proto": "^2.11.0"
|
|
12
|
+
}
|
|
13
|
+
}
|