@nihilium/client-sdk 0.1.2 → 0.2.0

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.
@@ -0,0 +1,989 @@
1
+ declare type Element = string | number;
2
+ declare type ProofPath = {
3
+ pathElements: Element[];
4
+ pathIndices: number[];
5
+ pathPositions: number[];
6
+ pathRoot: Element;
7
+ };
8
+
9
+ interface ProofResult {
10
+ globalProof: ProofPath;
11
+ localProof: ProofPath;
12
+ timestamp: number;
13
+ globalIndex: number;
14
+ localIndex: number;
15
+ blockHash: string;
16
+ }
17
+ interface LatestGlobalLeafProofResult {
18
+ globalProof: ProofPath;
19
+ leafRoot: string;
20
+ timestamp: number;
21
+ globalIndex: number;
22
+ blockHash: string;
23
+ }
24
+ interface DualProofResult {
25
+ dualProof: ProofPath;
26
+ globalProof: ProofPath;
27
+ localProof: ProofPath;
28
+ timestamp: string;
29
+ globalIndex: number;
30
+ localIndex: number;
31
+ blockHash: string;
32
+ dualLeafValue: string;
33
+ }
34
+ interface DualLatestGlobalLeafProofResult {
35
+ dualProof: ProofPath;
36
+ globalProof: ProofPath;
37
+ leafRoot: string;
38
+ timestamp: string;
39
+ globalIndex: number;
40
+ blockHash: string;
41
+ }
42
+ interface IDataStream {
43
+ initialize: () => Promise<void>;
44
+ getAddress: () => string;
45
+ getUrl: () => string;
46
+ getLatestGlobalLeafProof: () => Promise<LatestGlobalLeafProofResult>;
47
+ postData: (data: HexString[]) => Promise<[number, number, string]>;
48
+ getProof: (value: HexString) => Promise<ProofResult>;
49
+ hasDataStreamRoot: (root: string) => Promise<boolean>;
50
+ isProvable: (value: HexString) => Promise<boolean>;
51
+ }
52
+ interface IDualDataStream extends Omit<IDataStream, 'getProof' | 'getLatestGlobalLeafProof'> {
53
+ getProof(value: HexString): Promise<DualProofResult>;
54
+ getLatestGlobalLeafProof(): Promise<DualLatestGlobalLeafProofResult>;
55
+ }
56
+
57
+ type UnsealProofAction = {
58
+ action: string;
59
+ params: any;
60
+ };
61
+
62
+ type Proof = {
63
+ proof: any;
64
+ public_signals: any[];
65
+ };
66
+ type UnsealConditionProofData = {
67
+ name: string;
68
+ addressMapKey: string;
69
+ description?: string;
70
+ version: string;
71
+ public_signals: {
72
+ [key: string]: [number, number];
73
+ };
74
+ /**
75
+ *
76
+ * @description The complexity score of the proof. Essentially the gas cost of the proof.
77
+ * Be generous when setting this score! A score too low will result a proof being unchallangable
78
+ *
79
+ * @default 250_000 General gasscost of a ZKProof
80
+
81
+ */
82
+ complexity_score: number;
83
+ };
84
+ declare class UnsealConditionProof {
85
+ data: UnsealConditionProofData;
86
+ constructor(data: UnsealConditionProofData);
87
+ getOutputSize(): number;
88
+ getSignalIndex(signal: string): [number, number];
89
+ getPublicSignals(): {
90
+ [key: string]: [number, number];
91
+ };
92
+ getVersion(): string;
93
+ getDescription(): string;
94
+ getName(): string;
95
+ compile(addresses: AddressMap, verifier_must_be_true?: boolean): CompiledProof;
96
+ }
97
+ type CompiledProof = {
98
+ prepare_action: UnsealProofAction;
99
+ validate_action: UnsealProofAction;
100
+ };
101
+
102
+ declare abstract class ProofLibraryType {
103
+ standard: {
104
+ [key: string]: UnsealConditionProof;
105
+ };
106
+ custom: {
107
+ [key: string]: UnsealConditionProof;
108
+ };
109
+ addCustomProof(name: string, proof: UnsealConditionProof): void;
110
+ getProof(name: string): UnsealConditionProof;
111
+ }
112
+
113
+ type IOType = "Timestamp" | "BigInt" | "Number" | "String" | "HexString" | "Randomness" | "Other" | "Boolean" | IOType[];
114
+ type IO = {
115
+ type_order: IOType[];
116
+ user_input: boolean;
117
+ description: string;
118
+ required: boolean;
119
+ };
120
+ type ModuleOutput = {
121
+ type_order: IOType[];
122
+ name: string;
123
+ description: string;
124
+ proof_key: string;
125
+ signal_key: string;
126
+ };
127
+ type IOMap = {
128
+ [key: string]: IO;
129
+ };
130
+ type ModuleOutputMap = {
131
+ [key: string]: ModuleOutput;
132
+ };
133
+ type CompiledModule = {
134
+ module_id: string;
135
+ module_name: string;
136
+ new_depth: number;
137
+ actions: UnsealProofAction[];
138
+ outputs: {
139
+ [key: string]: {
140
+ output_proof_index: number;
141
+ output_signal_index: [number, number];
142
+ };
143
+ };
144
+ };
145
+ declare class ModuleNode {
146
+ node_id: string;
147
+ proof: UnsealConditionProof;
148
+ public_inputs: any[];
149
+ constructor(node_id: string, proof: UnsealConditionProof, public_inputs: any[]);
150
+ get_outputs(): {
151
+ [key: string]: [number, number];
152
+ };
153
+ get_output_keys(): string[];
154
+ }
155
+ declare enum ModuleEdgeInput {
156
+ external_input = "external_input",
157
+ link = "link",//Simple link to define ordering
158
+ signal_pass = "signal_pass",
159
+ static_input = "static_input",
160
+ user_input = "user_input"
161
+ }
162
+ declare class WrappedProof {
163
+ proof: UnsealConditionProof;
164
+ id: string;
165
+ index: number;
166
+ constructor(proof: UnsealConditionProof, id: string, index: number);
167
+ get_outputs(): {
168
+ [key: string]: [number, number];
169
+ };
170
+ get_output_keys(): string[];
171
+ }
172
+ declare class SignalEdge {
173
+ edge_id: string;
174
+ from: WrappedProof | undefined;
175
+ to: WrappedProof;
176
+ mapping: [string, string | any];
177
+ input_type: ModuleEdgeInput;
178
+ constructor(from: WrappedProof | undefined, to: WrappedProof, mapping: [string, any], input_type: ModuleEdgeInput, edge_id?: string);
179
+ validate_inputs(): boolean;
180
+ }
181
+ declare class ModuleEdge {
182
+ edge_id: string;
183
+ from: ModuleNode | undefined;
184
+ to: ModuleNode;
185
+ mapping: [string, string | any];
186
+ input_type: ModuleEdgeInput;
187
+ constructor(from: ModuleNode | undefined, to: ModuleNode, mapping: [string, any], input_type: ModuleEdgeInput, edge_id?: string);
188
+ validate_inputs(): boolean;
189
+ }
190
+ /**
191
+ *
192
+ */
193
+ type ModuleProof = {
194
+ proofs: any[];
195
+ public_inputs: any[][];
196
+ outputs: {
197
+ [key: string]: string;
198
+ };
199
+ };
200
+ declare abstract class UnsealConditionModule {
201
+ name: string;
202
+ short_description: string;
203
+ description: string;
204
+ protected inputs: IOMap;
205
+ protected forkingProof: string | undefined;
206
+ protected dataStreamOutputFields: string[];
207
+ protected outputs: ModuleOutputMap;
208
+ protected proofLibrary: ProofLibraryType;
209
+ protected proofs: {
210
+ [key: string]: WrappedProof;
211
+ };
212
+ protected proofList: string[];
213
+ protected edges: {
214
+ [key: string]: SignalEdge;
215
+ };
216
+ constructor(name: string, short_description: string, proofLibrary: ProofLibraryType);
217
+ getProofByIndex(proof_index: number): WrappedProof;
218
+ getUserInputs(): IOMap;
219
+ getOutputs(): ModuleOutputMap;
220
+ canFork(): boolean;
221
+ addProof(proof: UnsealConditionProof, easyId?: boolean): string;
222
+ addSignalEdge(from: string | undefined, to: string, mapping: [string, any], input_type: ModuleEdgeInput): void;
223
+ private generateProofId;
224
+ validateInputs(inputs: IOMap): boolean;
225
+ getInputEdgesForProof(proof_id: string): SignalEdge[];
226
+ obtain_outputs(public_signals: any[][]): {
227
+ [key: string]: any;
228
+ };
229
+ /**
230
+ * Produces the proofs for the module
231
+ * @param args
232
+ */
233
+ produce_proofs(...args: any[]): Promise<ModuleProof>;
234
+ /**
235
+ * Prepares the module for proving, this can be publishing a value onto the
236
+ * data stream or call external functions that might take longer to complete.
237
+
238
+ * @param args
239
+ */
240
+ prepare_for_proving(...args: any[]): Promise<any>;
241
+ /**
242
+ * Checks if the module is eligible to prove
243
+ * @param args
244
+ */
245
+ eligible_to_prove(...args: any[]): Promise<boolean>;
246
+ transform_user_inputs(input_mapping: {
247
+ [key: string]: any;
248
+ }): Promise<{
249
+ [key: string]: any;
250
+ }>;
251
+ compile(external_node_id: string, address_map: AddressMap, input_mapping: {
252
+ [key: string]: {
253
+ output_proof_index: number;
254
+ output_signal_indexes: number[];
255
+ };
256
+ }, current_proof_depth: number, fork?: boolean): CompiledModule;
257
+ }
258
+
259
+ declare abstract class ModuleLibraryType {
260
+ standard: {
261
+ [key: string]: new (...args: any[]) => UnsealConditionModule;
262
+ };
263
+ custom: {
264
+ [key: string]: new (...args: any[]) => UnsealConditionModule;
265
+ };
266
+ addCustomModule(name: string, module: new (...args: any[]) => UnsealConditionModule): void;
267
+ getModule(name: string, proofLibrary: ProofLibraryType): UnsealConditionModule;
268
+ }
269
+
270
+ /**
271
+ * Describes the path you are planning to proof
272
+ * It is constructed as a 256 bit number with the first bit being the length of the proof path
273
+ * The remaining 248 bits are the proof path
274
+ * This means there is a limited to the amount of 'forks' you can take in a proof path
275
+ * Which is 248 and should be more than anyone would ever need
276
+ * The proof path is a boolean array of length 248
277
+
278
+ */
279
+ declare class UnsealConditionsProofPathDescriptor {
280
+ proof_path_length: number;
281
+ proof_path: boolean[];
282
+ constructor();
283
+ }
284
+ declare function import_collectionnode_from_json(data: any, moduleLibrary: ModuleLibraryType, proofLibrary: ProofLibraryType): CollectionNode;
285
+ declare class CollectionNode {
286
+ node_id: string;
287
+ module: UnsealConditionModule;
288
+ public_inputs: any[];
289
+ constructor(node_id: string, module: UnsealConditionModule, public_inputs: any[]);
290
+ export_to_json(): any;
291
+ get_outputs(): ModuleOutputMap;
292
+ get_output_keys(): string[];
293
+ get_input_keys(): string[];
294
+ validate_input_mapping(input_mapping: {
295
+ [key: string]: any;
296
+ }): boolean;
297
+ }
298
+ declare enum CollectionEdgeInput {
299
+ signal_pass = "signal_pass",
300
+ static_input = "static_input",
301
+ user_input = "user_input"
302
+ }
303
+ declare function import_collectionedge_from_json(data: any, nodes: {
304
+ [key: string]: CollectionNode;
305
+ }): CollectionEdge;
306
+ declare class CollectionDataStream {
307
+ datastream_id: string;
308
+ from: CollectionNode;
309
+ field_name: string;
310
+ constructor(datastream_id: string, from: CollectionNode, field_name: string);
311
+ export_to_json(): any;
312
+ }
313
+ declare class CollectionEdge {
314
+ edge_id: string;
315
+ from: CollectionNode | undefined;
316
+ to: CollectionNode;
317
+ mapping: [string, string | any];
318
+ input_type: CollectionEdgeInput;
319
+ constructor(from: CollectionNode | undefined, to: CollectionNode, mapping: [string, any], input_type: CollectionEdgeInput, edge_id?: string);
320
+ toShortNodeId(node_id: string | undefined): string;
321
+ toString(): string;
322
+ export_to_json(): any;
323
+ validate_inputs(): boolean;
324
+ }
325
+ declare enum ChangedType {
326
+ removed = "removed",
327
+ added = "added",
328
+ modified = "modified",
329
+ moved = "moved"
330
+ }
331
+ type ChangedCallback = (changes: {
332
+ action: ChangedType;
333
+ nodes?: CollectionNode[];
334
+ edges?: CollectionEdge[];
335
+ data_streams?: CollectionDataStream[];
336
+ starting_node?: CollectionNode | undefined;
337
+ comments?: {
338
+ [key: string]: string;
339
+ };
340
+ }) => void;
341
+ type RequiredUserInput = {
342
+ proof_index: number;
343
+ signal_indexes: [number, number];
344
+ name: string;
345
+ module_id: string;
346
+ description: string;
347
+ input_signal_name: string;
348
+ };
349
+ type DataStreamInput = {
350
+ datastream_id: string;
351
+ output_proof_index: number;
352
+ output_signal_index: number;
353
+ };
354
+ type CompiledCollectionExport = {
355
+ compiled_modules: CompiledModule[][];
356
+ user_inputs: RequiredUserInput[][];
357
+ data_stream_inputs: DataStreamInput[][];
358
+ collection_id: string;
359
+ collection_export: any;
360
+ };
361
+ interface AddressMap {
362
+ getAddress(key: string): string;
363
+ }
364
+ declare class BasicAddressMap implements AddressMap {
365
+ address_map: {
366
+ [key: string]: string;
367
+ };
368
+ constructor(address_map: {
369
+ [key: string]: string;
370
+ });
371
+ getAddress(key: string): string;
372
+ addAddress(key: string, address: string): void;
373
+ }
374
+ declare class AddressMapWithDefault implements AddressMap {
375
+ address_map: {
376
+ [key: string]: string;
377
+ };
378
+ default_address: string;
379
+ constructor(address_map: {
380
+ [key: string]: string;
381
+ }, default_address: string);
382
+ getAddress(key: string): string;
383
+ }
384
+
385
+ type HexString = string;
386
+ type PaymentProof = string;
387
+ type OpeningCondition = {
388
+ address: string;
389
+ };
390
+ type RequestPackageStageOne = {
391
+ public_key: string;
392
+ payment_proof?: PaymentProof;
393
+ };
394
+ type RequestPackageStageTwo = {
395
+ encrypted_payment_proof: string;
396
+ };
397
+ declare enum RevealConditions {
398
+ TOP_LEVEL = "top_level",
399
+ TIMELOCK = "timelock",
400
+ IDENTITY_PROOF = "identity_proof",
401
+ NON_INTERVENTION_PROOF = "non_intervention_proof"
402
+ }
403
+ declare const PROTOCOL_PROCESSOR_PATHS: {
404
+ REQUEST_SEAL: string;
405
+ REQUEST_UNSEAL: string;
406
+ GET_PUBLIC_KEYS: string;
407
+ };
408
+ declare const PROTOCOL_DATA_STREAM_PATHS: {
409
+ POST_DATA: string;
410
+ GET_PROOF: string;
411
+ IS_PROVABLE: string;
412
+ GET_GLOBAL_TREE_INDEX: string;
413
+ GET_ADDRESS: string;
414
+ GET_LATEST_GLOBAL_LEAF_PROOF: string;
415
+ };
416
+ type ProcessorEndpoint = {
417
+ url: string;
418
+ is_tor: boolean;
419
+ public_verification_key: [bigint, bigint];
420
+ public_he_encryption_key: [bigint, bigint];
421
+ server_address: HexString;
422
+ };
423
+ declare enum ClientProcessorSealingPhase {
424
+ NOT_STARTED = -1,
425
+ GENERATING_SECRETS = 0,
426
+ REQUEST_COMMITMENT = 1,
427
+ PROCESSING_COMMITMENT = 2,
428
+ PROCESSING_INDIVIDUAL_REVEAL_CONDITIONS = 3,
429
+ ENCRYPTING_SHAMIR_SECRET = 4,
430
+ DONE = 5,
431
+ ERROR = -99
432
+ }
433
+ interface IClientSingleShareSealingProcess {
434
+ initialize(secret: bigint, metadata_root: bigint, template_inputs: {
435
+ [key: string]: any;
436
+ }): Promise<void>;
437
+ request_commitment(call_processor: boolean): Promise<SingleSealRequest>;
438
+ process_seal_response(processor_response: SingleSealRequestResponse): Promise<SingleSealStoragePackage>;
439
+ get_phase(): ClientProcessorSealingPhase;
440
+ get_secret_throwaway_packages(): SecretThrowawayPackage[];
441
+ get_reveal_conditions(): RevealConditionRequest[];
442
+ }
443
+ interface IClientSingleShareUnsealingProcess {
444
+ initialize(seal: SingleSealStoragePackage): Promise<void>;
445
+ reveal_value_published(): Promise<boolean>;
446
+ get_unsealing_status(): Promise<UnsealingStatus>;
447
+ get_processor_status(): Promise<ProcessorStatus>;
448
+ display_reveal_conditions(): Promise<void>;
449
+ publish_reveal_value(data_stream_id: string): Promise<void>;
450
+ start_unsealing(proof_index: number, proofs: any[], public_inputs: any[][]): Promise<SingleUnsealRequest>;
451
+ process_unseal_response(processor_response: SingleSealUnsealRequestResponse): Promise<bigint>;
452
+ }
453
+ type SingleSealUnsealRequestResponse = {
454
+ unpacked_private_scalar: string;
455
+ };
456
+ declare enum UnsealingStatus {
457
+ NOT_STARTED = 0,
458
+ REVEALING_INITIAL_CONDITION = 1,
459
+ REVEAL_VALUE_SENT = 2,
460
+ REVEAL_VALUE_EXPOSED = 3,
461
+ AWAIT_OTHER_SEAL_CONDITIONS = 4,
462
+ UNSEAL_POSSIBLE = 5,
463
+ UNSEALING_IN_PROGRESS = 6,
464
+ DONE = 7,
465
+ ERROR = -99
466
+ }
467
+ declare enum ProcessorStatus {
468
+ AVAILABLE = 0,
469
+ WARN_STAKE_DECREASING = 1,
470
+ WARN_STAKE_LOW = 2,
471
+ WARN_STAKE_CRITICAL = 3,
472
+ UNAVAILABLE = 4,
473
+ NEW_PUBLIC_KEYS_REQUIRED = 5,
474
+ ERROR = -99
475
+ }
476
+ /**
477
+ * Throwaway packages are local to the client during the sealing phase.
478
+ * After the sealing phase is done, the throwaway packages/values are removed to secure unlinkability.
479
+ */
480
+ type SecretThrowawayPackage = {};
481
+ /**
482
+ * This is an abstract type for all public packages.
483
+ * Packages marked as public can be shared externally to watch for events that relate to
484
+ * initiation of the revealing phase. Can be sent to centralized services to notify them of events.
485
+ *
486
+ */
487
+ type PublicPackage = {};
488
+ /**
489
+ * This is an abstract type for all hidden packages.
490
+ * This meant to be stored behind a password, here might live potentially linkable information.
491
+ * There is no direct purpose for this package YET.
492
+ */
493
+ type HiddenPackage = {};
494
+ /**
495
+ * This is an abstract type for all local private packages.
496
+ * It is meant to be stored with the client to generate reveal proofs.
497
+ * Packages marked as private can be used to initiate the revealing phase
498
+ */
499
+ type PrivatePackage = {};
500
+ type StaticCircuitInput = {
501
+ circuit_id: HexString;
502
+ inputfield_name: string;
503
+ value: HexString;
504
+ };
505
+ type ChainedCircuitInput = {
506
+ source_circuit_id: HexString;
507
+ source_circuit_index: number;
508
+ target_circuit_id: HexString;
509
+ outputfield_index: number;
510
+ inputfield_name: string;
511
+ };
512
+ type RevealCondition = {
513
+ address: HexString;
514
+ circuit_id: HexString;
515
+ static_inputs: StaticCircuitInput[];
516
+ chained_inputs: ChainedCircuitInput[];
517
+ random_value: HexString;
518
+ proof: any;
519
+ public_signals: any;
520
+ };
521
+ /**
522
+ * This is an abstract type for all reveal condition request packages.
523
+ * The request packages will be signed separately if the processor supports the address and circuit.
524
+ *
525
+ */
526
+ type RevealConditionRequest = {
527
+ address: HexString;
528
+ circuit_id: HexString;
529
+ hashed_input_fields: HexString;
530
+ random_value: HexString;
531
+ proof: any;
532
+ public_signals: any;
533
+ };
534
+ type UnsealRevealConditionRequest = {
535
+ proof: HexString;
536
+ commitment: HexString;
537
+ public_signals: HexString[];
538
+ };
539
+ type RevealConditionRequestResponse = {
540
+ address: HexString;
541
+ circuit_id: HexString;
542
+ hashed_input_fields: HexString;
543
+ random_value: HexString;
544
+ signature_S: HexString;
545
+ signature_R8x: HexString;
546
+ signature_R8y: HexString;
547
+ };
548
+ type SingleSealRequest = {
549
+ address: HexString;
550
+ circuit_id: HexString;
551
+ hashed_reveal_value_preimage: HexString;
552
+ hashed_unseal_condition_root: HexString;
553
+ hashed_metadata_root: HexString;
554
+ require_proof: boolean;
555
+ };
556
+ type SingleSealRequestResponse = {
557
+ address: HexString;
558
+ circuit_id: HexString;
559
+ cyphertexts: [
560
+ HexString,
561
+ HexString,
562
+ HexString,
563
+ HexString,
564
+ HexString,
565
+ HexString,
566
+ HexString,
567
+ HexString,
568
+ HexString,
569
+ HexString,
570
+ HexString,
571
+ HexString,
572
+ HexString,
573
+ HexString,
574
+ HexString,
575
+ HexString
576
+ ];
577
+ empheral_keys: [
578
+ HexString,
579
+ HexString,
580
+ HexString,
581
+ HexString,
582
+ HexString,
583
+ HexString,
584
+ HexString,
585
+ HexString,
586
+ HexString,
587
+ HexString,
588
+ HexString,
589
+ HexString,
590
+ HexString,
591
+ HexString,
592
+ HexString,
593
+ HexString
594
+ ];
595
+ signature_S: HexString;
596
+ signature_R8x: HexString;
597
+ signature_R8y: HexString;
598
+ new_public_key: [HexString, HexString];
599
+ severed_commitment_random_value: HexString;
600
+ proof: HexString;
601
+ public_signals: HexString[];
602
+ hashed_unseal_condition_root: HexString;
603
+ hashed_metadata_root: HexString;
604
+ };
605
+ type SingleUnsealRequest = {
606
+ address: HexString;
607
+ circuit_id: HexString;
608
+ public_key: [HexString, HexString];
609
+ signature_S: HexString;
610
+ signature_R8x: HexString;
611
+ signature_R8y: HexString;
612
+ proof: HexString;
613
+ public_signals: HexString[][];
614
+ proofs: HexString[];
615
+ empheral_keys: HexString[];
616
+ cyphertexts: HexString[];
617
+ data_stream_address: HexString;
618
+ unseal_proof_actions: UnsealProofAction[];
619
+ unseal_root_proof: ProofPath;
620
+ };
621
+ type SingleSealStoragePackage = {
622
+ private_package: SingleShareSealPrivatePackage;
623
+ public_package: SingleShareSealPublicPackage;
624
+ hidden_package: SingleShareSealHiddenPackage;
625
+ };
626
+ type ECCEncryptedMessage = {
627
+ ciphertextHex: HexString;
628
+ R: {
629
+ x: HexString;
630
+ y: HexString;
631
+ };
632
+ };
633
+ type UnsealConditionTemplateExport = {
634
+ name: string;
635
+ description: string;
636
+ unseal_proof_actions: UnsealProofAction[][];
637
+ user_inputs: RequiredUserInput[][];
638
+ used_input_mapping: {
639
+ [key: string]: string;
640
+ };
641
+ compiled_collection: CompiledCollectionExport;
642
+ collection_id: string;
643
+ };
644
+ type SingleShareSealPrivatePackage = PrivatePackage & {
645
+ cyphertexts: HexString[];
646
+ empheral_keys: HexString[];
647
+ proof: any;
648
+ public_signals: any;
649
+ public_key_he: [HexString, HexString];
650
+ public_verification_key: [HexString, HexString];
651
+ encrypted_secret: ECCEncryptedMessage;
652
+ reveal_value: HexString;
653
+ unseal_condition_root: HexString;
654
+ metadata_root: HexString;
655
+ unseal_template: UnsealConditionTemplateExport;
656
+ proving_hints: any;
657
+ unseal_collection_id: string;
658
+ };
659
+ type SingleShareSealPublicPackage = PublicPackage & {
660
+ reveal_value: HexString;
661
+ address: HexString;
662
+ circuit_id: HexString;
663
+ data_stream_ids: HexString[];
664
+ proof: any;
665
+ public_signals: any;
666
+ data_stream_urls: string[];
667
+ processor_url: string;
668
+ };
669
+ type SingleShareSealHiddenPackage = HiddenPackage & {};
670
+ type ThrowAwayShamirSecret = {
671
+ shamir_secret: bigint;
672
+ secret_ecc_scalar: bigint;
673
+ ecc_public_key: [bigint, bigint];
674
+ };
675
+
676
+ declare const from_json: (json_object: UnsealConditionTemplateExport, proof_library: ProofLibraryType, module_library: ModuleLibraryType) => UnsealConditionTemplate;
677
+ declare class UnsealConditionTemplate {
678
+ name: string;
679
+ collection_id: string;
680
+ description: string;
681
+ proof_library: ProofLibraryType;
682
+ module_library: ModuleLibraryType;
683
+ compiled_collection: CompiledCollectionExport;
684
+ user_inputs: RequiredUserInput[][];
685
+ unsealProofActions: UnsealProofAction[][];
686
+ data_streams: DataStreamInput[][];
687
+ modules: UnsealConditionModule[];
688
+ used_input_mapping: {
689
+ [key: string]: any;
690
+ };
691
+ private proofs_cache;
692
+ constructor(name: string, description: string, proof_library: ProofLibraryType, module_library: ModuleLibraryType, compiled_collection: CompiledCollectionExport);
693
+ export_compiled_to_json(): UnsealConditionTemplateExport;
694
+ isCompiled(): boolean;
695
+ private getInputFromMapping;
696
+ compile(input_mapping: {
697
+ [key: string]: bigint;
698
+ }, data_stream_mapping: {
699
+ [key: string]: string;
700
+ }, optimize?: boolean): void;
701
+ address_to_proof(address: string): UnsealConditionProof;
702
+ /**
703
+ * Converts V1 unseal proof actions (2D output references via output_proof_index + output_signal_index)
704
+ * into V2 actions (flat output list with bitmask-based pruning at each chain_proof_verify).
705
+ *
706
+ * At each chain_proof_verify:
707
+ * 1. Append the new proof's outputs to the flat list
708
+ * 2. Look forward to find which flat entries are still referenced
709
+ * 3. Build a bitmask (1=keep, 0=remove) over the entire flat list
710
+ * 4. Prune dead entries
711
+ *
712
+ * PASS_SIGNAL and VALIDATE_DATA_ROOT actions are converted from 2D (proof_index, signal_index)
713
+ * to flat indices into the current output list.
714
+ */
715
+ optimize(unseal_proof_actions: UnsealProofAction[]): UnsealProofAction[];
716
+ /**
717
+ * Scans actions from startIdx onward to find which flat list entries
718
+ * are referenced by future PASS_SIGNAL and VALIDATE_DATA_ROOT actions.
719
+ * Returns the set of flat indices that are still needed.
720
+ */
721
+ private collectFutureReferences;
722
+ /**
723
+ * Finds an UnsealConditionProof by its on-chain verifier address.
724
+ * Searches through compiled modules to match the verifier_address
725
+ * in PREPARE_NEXT_PROOF actions to the corresponding proof.
726
+ */
727
+ private getProofByVerifierAddress;
728
+ getAllDataStreams(): string[];
729
+ getUnsealProofActions(): UnsealProofAction[][];
730
+ getExpectedInputs(): string[];
731
+ getUnsealRootForProof(proof_index: number): Promise<ProofPath>;
732
+ getUnsealRoot(): Promise<string>;
733
+ }
734
+
735
+ declare class UnsealConditionCollection {
736
+ nodes: {
737
+ [key: string]: CollectionNode;
738
+ };
739
+ edges: {
740
+ [key: string]: CollectionEdge;
741
+ };
742
+ comments: {
743
+ [key: string]: string;
744
+ };
745
+ data_streams: CollectionDataStream[];
746
+ name: string;
747
+ description: string;
748
+ starting_node: CollectionNode | undefined;
749
+ proofLibrary: ProofLibraryType;
750
+ moduleLibrary: ModuleLibraryType;
751
+ forks: {
752
+ [key: string]: string[];
753
+ };
754
+ fork_list: string[];
755
+ private node_to_fork_map;
756
+ private index_counter;
757
+ changed_callback: ChangedCallback;
758
+ constructor(name: string, description: string, proofLibrary: ProofLibraryType, moduleLibrary: ModuleLibraryType, changed_callback?: ChangedCallback);
759
+ visual_forks(): string[];
760
+ visual_edges_all(): string[][];
761
+ visual_edges(fork_id: string): string[];
762
+ comment(id: string, comment: string): void;
763
+ add_data_stream(datastream_id: string, from_node_id: string, field_name: string): void;
764
+ remove_data_stream(datastream_id: string): void;
765
+ get_data_stream(datastream_id: string): CollectionDataStream | undefined;
766
+ sort_fork_list(): void;
767
+ add_node(module: UnsealConditionModule, fork_from_node_id?: string): string;
768
+ move_node(node_id: string, new_fork_from_node_id: string, at_position?: number): CollectionEdge[];
769
+ remove_node(node_id: string): void;
770
+ remove_edge(edge_id: string): void;
771
+ all_nodes_for_fork(fork_id: string): {
772
+ nodes: string[];
773
+ forking: string[];
774
+ };
775
+ validate_edge(source_node_id: string | undefined, target_node_id: string | undefined, mapping: [string, any], input_type: CollectionEdgeInput): boolean;
776
+ add_edge(source_node_id: string | undefined, target_node_id: string | undefined, mapping: [string, any], input_type: CollectionEdgeInput): void;
777
+ export_to_json(): any;
778
+ import_from_json(data: any): void;
779
+ getEdgesToNode(node_id: string): CollectionEdge[];
780
+ getEdgesFromNode(node_id: string): CollectionEdge[];
781
+ getCollectionId(): string;
782
+ generateProofCode(fork_nr: number): string;
783
+ createTemplate(address_map: AddressMap): UnsealConditionTemplate;
784
+ createTemplatePerFork(address_map: AddressMap, sorted_nodes: string[], forking: string[]): {
785
+ compiled_modules: CompiledModule[];
786
+ user_inputs: RequiredUserInput[];
787
+ data_stream_inputs: DataStreamInput[];
788
+ };
789
+ }
790
+
791
+ /** Field is not always over prime: for example, Fp2 has ORDER(q)=p^m. */
792
+ interface IField<T> {
793
+ ORDER: bigint;
794
+ isLE: boolean;
795
+ BYTES: number;
796
+ BITS: number;
797
+ MASK: bigint;
798
+ ZERO: T;
799
+ ONE: T;
800
+ create: (num: T) => T;
801
+ isValid: (num: T) => boolean;
802
+ is0: (num: T) => boolean;
803
+ neg(num: T): T;
804
+ inv(num: T): T;
805
+ sqrt(num: T): T;
806
+ sqr(num: T): T;
807
+ eql(lhs: T, rhs: T): boolean;
808
+ add(lhs: T, rhs: T): T;
809
+ sub(lhs: T, rhs: T): T;
810
+ mul(lhs: T, rhs: T | bigint): T;
811
+ pow(lhs: T, power: bigint): T;
812
+ div(lhs: T, rhs: T | bigint): T;
813
+ addN(lhs: T, rhs: T): T;
814
+ subN(lhs: T, rhs: T): T;
815
+ mulN(lhs: T, rhs: T | bigint): T;
816
+ sqrN(num: T): T;
817
+ isOdd?(num: T): boolean;
818
+ pow(lhs: T, power: bigint): T;
819
+ invertBatch: (lst: T[]) => T[];
820
+ toBytes(num: T): Uint8Array;
821
+ fromBytes(bytes: Uint8Array): T;
822
+ cmov(a: T, b: T, c: boolean): T;
823
+ }
824
+
825
+ /**
826
+ * Methods for elliptic curve multiplication by scalars.
827
+ * Contains wNAF, pippenger
828
+ * @module
829
+ */
830
+ /*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
831
+
832
+ type AffinePoint<T> = {
833
+ x: T;
834
+ y: T;
835
+ } & {
836
+ z?: never;
837
+ t?: never;
838
+ };
839
+ interface Group<T extends Group<T>> {
840
+ double(): T;
841
+ negate(): T;
842
+ add(other: T): T;
843
+ subtract(other: T): T;
844
+ equals(other: T): boolean;
845
+ multiply(scalar: bigint): T;
846
+ }
847
+ type GroupConstructor<T> = {
848
+ BASE: T;
849
+ ZERO: T;
850
+ };
851
+ /**
852
+ * Generic BasicCurve interface: works even for polynomial fields (BLS): P, n, h would be ok.
853
+ * Though generator can be different (Fp2 / Fp6 for BLS).
854
+ */
855
+ type BasicCurve<T> = {
856
+ Fp: IField<T>;
857
+ n: bigint;
858
+ nBitLength?: number;
859
+ nByteLength?: number;
860
+ h: bigint;
861
+ hEff?: bigint;
862
+ Gx: T;
863
+ Gy: T;
864
+ allowInfinityPoint?: boolean;
865
+ };
866
+
867
+ /**
868
+ * Hex, bytes and number utilities.
869
+ * @module
870
+ */
871
+ /*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
872
+ type Hex = Uint8Array | string;
873
+ type FHash = (message: Uint8Array | string) => Uint8Array;
874
+
875
+ /**
876
+ * Twisted Edwards curve. The formula is: ax² + y² = 1 + dx²y².
877
+ * For design rationale of types / exports, see weierstrass module documentation.
878
+ * @module
879
+ */
880
+ /*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
881
+
882
+ /** Edwards curves must declare params a & d. */
883
+ type CurveType = BasicCurve<bigint> & {
884
+ a: bigint;
885
+ d: bigint;
886
+ hash: FHash;
887
+ randomBytes: (bytesLength?: number) => Uint8Array;
888
+ adjustScalarBytes?: (bytes: Uint8Array) => Uint8Array;
889
+ domain?: (data: Uint8Array, ctx: Uint8Array, phflag: boolean) => Uint8Array;
890
+ uvRatio?: (u: bigint, v: bigint) => {
891
+ isValid: boolean;
892
+ value: bigint;
893
+ };
894
+ prehash?: FHash;
895
+ mapToCurve?: (scalar: bigint[]) => AffinePoint<bigint>;
896
+ };
897
+ type CurveTypeWithLength = Readonly<CurveType & {
898
+ nByteLength: number;
899
+ nBitLength: number;
900
+ }>;
901
+ declare function validateOpts(curve: CurveType): CurveTypeWithLength;
902
+ /** Instance of Extended Point with coordinates in X, Y, Z, T. */
903
+ interface ExtPointType extends Group<ExtPointType> {
904
+ readonly ex: bigint;
905
+ readonly ey: bigint;
906
+ readonly ez: bigint;
907
+ readonly et: bigint;
908
+ get x(): bigint;
909
+ get y(): bigint;
910
+ assertValidity(): void;
911
+ multiply(scalar: bigint): ExtPointType;
912
+ multiplyUnsafe(scalar: bigint): ExtPointType;
913
+ isSmallOrder(): boolean;
914
+ isTorsionFree(): boolean;
915
+ clearCofactor(): ExtPointType;
916
+ toAffine(iz?: bigint): AffinePoint<bigint>;
917
+ toRawBytes(isCompressed?: boolean): Uint8Array;
918
+ toHex(isCompressed?: boolean): string;
919
+ _setWindowSize(windowSize: number): void;
920
+ }
921
+ /** Static methods of Extended Point with coordinates in X, Y, Z, T. */
922
+ interface ExtPointConstructor extends GroupConstructor<ExtPointType> {
923
+ new (x: bigint, y: bigint, z: bigint, t: bigint): ExtPointType;
924
+ fromAffine(p: AffinePoint<bigint>): ExtPointType;
925
+ fromHex(hex: Hex): ExtPointType;
926
+ fromPrivateKey(privateKey: Hex): ExtPointType;
927
+ msm(points: ExtPointType[], scalars: bigint[]): ExtPointType;
928
+ }
929
+ /**
930
+ * Edwards Curve interface.
931
+ * Main methods: `getPublicKey(priv)`, `sign(msg, priv)`, `verify(sig, msg, pub)`.
932
+ */
933
+ type CurveFn = {
934
+ CURVE: ReturnType<typeof validateOpts>;
935
+ getPublicKey: (privateKey: Hex) => Uint8Array;
936
+ sign: (message: Hex, privateKey: Hex, options?: {
937
+ context?: Hex;
938
+ }) => Uint8Array;
939
+ verify: (sig: Hex, message: Hex, publicKey: Hex, options?: {
940
+ context?: Hex;
941
+ zip215: boolean;
942
+ }) => boolean;
943
+ ExtendedPoint: ExtPointConstructor;
944
+ utils: {
945
+ randomPrivateKey: () => Uint8Array;
946
+ getExtendedPublicKey: (key: Hex) => {
947
+ head: Uint8Array;
948
+ prefix: Uint8Array;
949
+ scalar: bigint;
950
+ point: ExtPointType;
951
+ pointBytes: Uint8Array;
952
+ };
953
+ precompute: (windowSize?: number, point?: ExtPointType) => ExtPointType;
954
+ };
955
+ };
956
+
957
+ type SnarkBigInt = bigint;
958
+ type PrivKey = bigint;
959
+ type PubKey = ExtPointType;
960
+ type BabyJubAffinePoint = AffinePoint<bigint>;
961
+ type BabyJubExtPoint = ExtPointType;
962
+ declare const babyJubNoble: CurveFn;
963
+ /**
964
+ * A private key and a public key
965
+ */
966
+ interface Keypair {
967
+ privKey: PrivKey;
968
+ pubKey: PubKey;
969
+ }
970
+ declare const SNARK_FIELD_SIZE: SnarkBigInt;
971
+ declare const babyJub: ExtPointConstructor;
972
+
973
+ type SelectableProcessor = {
974
+ url: string;
975
+ is_tor: boolean;
976
+ jurisdiction: string;
977
+ stake: bigint;
978
+ name: string;
979
+ ethAddress: string;
980
+ };
981
+ type SelectableDataStream = {
982
+ url: string;
983
+ is_tor: boolean;
984
+ jurisdiction: string;
985
+ stake: bigint;
986
+ };
987
+
988
+ export { AddressMapWithDefault, BasicAddressMap, ChangedType, ClientProcessorSealingPhase, CollectionDataStream, CollectionEdge, CollectionEdgeInput, CollectionNode, ModuleEdge, ModuleEdgeInput, ModuleNode, PROTOCOL_DATA_STREAM_PATHS, PROTOCOL_PROCESSOR_PATHS, ProcessorStatus, RevealConditions, SNARK_FIELD_SIZE, SignalEdge, UnsealConditionCollection, UnsealConditionModule, UnsealConditionProof, UnsealConditionTemplate, UnsealConditionsProofPathDescriptor, UnsealingStatus, WrappedProof, babyJub, babyJubNoble, from_json, import_collectionedge_from_json, import_collectionnode_from_json };
989
+ export type { AddressMap, BabyJubAffinePoint, BabyJubExtPoint, ChainedCircuitInput, ChangedCallback, CompiledCollectionExport, CompiledModule, CompiledProof, DataStreamInput, DualLatestGlobalLeafProofResult, DualProofResult, ECCEncryptedMessage, HexString, HiddenPackage, IClientSingleShareSealingProcess, IClientSingleShareUnsealingProcess, IDataStream, IDualDataStream, IO, IOMap, IOType, Keypair, LatestGlobalLeafProofResult, ModuleOutput, ModuleOutputMap, ModuleProof, OpeningCondition, PaymentProof, PrivKey, PrivatePackage, ProcessorEndpoint, Proof, ProofResult, PubKey, PublicPackage, RequestPackageStageOne, RequestPackageStageTwo, RequiredUserInput, RevealCondition, RevealConditionRequest, RevealConditionRequestResponse, SecretThrowawayPackage, SelectableDataStream, SelectableProcessor, SingleSealRequest, SingleSealRequestResponse, SingleSealStoragePackage, SingleSealUnsealRequestResponse, SingleShareSealHiddenPackage, SingleShareSealPrivatePackage, SingleShareSealPublicPackage, SingleUnsealRequest, SnarkBigInt, StaticCircuitInput, ThrowAwayShamirSecret, UnsealConditionProofData, UnsealConditionTemplateExport, UnsealRevealConditionRequest };