@provablehq/wasm 0.9.3 → 0.9.4

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.
@@ -13,7 +13,7 @@
13
13
  * @param {Object} import_verifying_keys The verifying keys for the imports in the form of { "program_id.aleo": [["function, "verifying_key"], ...], ...}
14
14
  * @returns {boolean} True if the execution is valid, false otherwise
15
15
  */
16
- export function verifyFunctionExecution(execution: Execution, verifying_key: VerifyingKey, program: Program, function_id: string, imports?: object | null, imported_verifying_keys?: object | null): boolean;
16
+ export function verifyFunctionExecution(execution: Execution, verifying_key: VerifyingKey, program: Program, function_id: string, imports: object | null | undefined, imported_verifying_keys: object | null | undefined, block_height: number): boolean;
17
17
  export function runRayonThread(receiver: number): void;
18
18
  export function initThreadPool(url: URL, num_threads: number): Promise<void>;
19
19
  /**
@@ -305,6 +305,80 @@ export class BHP768 {
305
305
  */
306
306
  commitToGroup(input: Array<any>, randomizer: Scalar): Group;
307
307
  }
308
+ /**
309
+ * Boolean element.
310
+ */
311
+ export class Boolean {
312
+ free(): void;
313
+ /**
314
+ * Creates a Boolean from a native JS bool.
315
+ */
316
+ constructor(value: boolean);
317
+ /**
318
+ * Creates a boolean object from a string representation ("true"/"false").
319
+ */
320
+ static fromString(boolean: string): Boolean;
321
+ /**
322
+ * Returns the string representation of the boolean element.
323
+ */
324
+ toString(): string;
325
+ /**
326
+ * Create a boolean element from a Uint8Array of left endian bytes.
327
+ */
328
+ static fromBytesLe(bytes: Uint8Array): Boolean;
329
+ /**
330
+ * Encode the boolean element as a Uint8Array of left endian bytes.
331
+ */
332
+ toBytesLe(): Uint8Array;
333
+ /**
334
+ * Reconstruct a boolean element from a boolean array representation.
335
+ */
336
+ static fromBitsLe(bits: Array<any>): Boolean;
337
+ /**
338
+ * Get the left endian boolean array representation of the boolean element.
339
+ */
340
+ toBitsLe(): Array<any>;
341
+ /**
342
+ * Create a plaintext from the boolean element.
343
+ */
344
+ toPlaintext(): Plaintext;
345
+ /**
346
+ * Clone the boolean element.
347
+ */
348
+ clone(): Boolean;
349
+ /**
350
+ * Generate a random boolean element.
351
+ */
352
+ static random(): Boolean;
353
+ /**
354
+ * Logical NOT.
355
+ */
356
+ not(): Boolean;
357
+ /**
358
+ * Logical AND.
359
+ */
360
+ and(other: Boolean): Boolean;
361
+ /**
362
+ * Logical OR.
363
+ */
364
+ or(other: Boolean): Boolean;
365
+ /**
366
+ * Logical XOR.
367
+ */
368
+ xor(other: Boolean): Boolean;
369
+ /**
370
+ * Logical NAND.
371
+ */
372
+ nand(other: Boolean): Boolean;
373
+ /**
374
+ * Logical NOR.
375
+ */
376
+ nor(other: Boolean): Boolean;
377
+ /**
378
+ * Check if one boolean element equals another.
379
+ */
380
+ equals(other: Boolean): boolean;
381
+ }
308
382
  /**
309
383
  * SnarkVM Ciphertext object. A Ciphertext represents an symmetrically encrypted plaintext. This
310
384
  * object provides decryption methods to recover the plaintext from the ciphertext (given the
@@ -325,10 +399,25 @@ export class Ciphertext {
325
399
  /**
326
400
  * Decrypt a ciphertext using the view key of the transition signer, transition public key, and
327
401
  * (program, function, index) tuple.
402
+ *
403
+ * @param {ViewKey} view_key The view key of the transition signer.
404
+ * @param {Group} transition_public_key The transition public key used to encrypt the ciphertext.
405
+ * @param {string} program The program ID associated with the ciphertext.
406
+ * @param {string} function_name The name of the function associated with the encrypted inputs and outputs.
407
+ * @param {u16} index The index of the input or output parameter that was encrypted.
408
+ *
409
+ * @returns {Plaintext} The decrypted plaintext.
328
410
  */
329
411
  decryptWithTransitionInfo(view_key: ViewKey, transition_public_key: Group, program: string, function_name: string, index: number): Plaintext;
330
412
  /**
331
413
  * Decrypt a ciphertext using the transition view key and a (program, function, index) tuple.
414
+ *
415
+ * @param {Field} transition_view_key The transition view key that was used to encrypt the ciphertext.
416
+ * @param {string} program The program ID associated with the ciphertext.
417
+ * @param {string} function_name The name of the function associated with the encrypted inputs and outputs.
418
+ * @param {u16} index The index of the input or output parameter that was encrypted.
419
+ *
420
+ * @returns {Plaintext} The decrypted plaintext.
332
421
  */
333
422
  decryptWithTransitionViewKey(transition_view_key: Field, program: string, function_name: string, index: number): Plaintext;
334
423
  /**
@@ -437,20 +526,40 @@ export class EncryptionToolkit {
437
526
  free(): void;
438
527
  /**
439
528
  * Generates a transition view key from the view key and the transition public key.
529
+ *
530
+ * @param {ViewKey} view_key The view key of the account that generated the transition.
531
+ * @param {Group} tpk The transition public key.
532
+ *
533
+ * @returns {Field} The transition view key.
440
534
  */
441
535
  static generateTvk(view_key: ViewKey, tpk: Group): Field;
442
536
  /**
443
537
  * Creates a record view key from the view key. This can be later be used to decrypt a
538
+ *
539
+ * @param {ViewKey} view_key The view key of the owner of the record.
540
+ * @param {RecordCiphertext} record_ciphertext The record ciphertext used to derive the record view key.
541
+ *
542
+ * @returns {Field} The record view key.
444
543
  */
445
544
  static generateRecordViewKey(view_key: ViewKey, record_ciphertext: RecordCiphertext): Field;
446
545
  /**
447
546
  * Decrypts a record ciphertext using the record view key. Decryption only succeeds
448
547
  * if the record view key was generated from the view key of the record owner.
548
+ *
549
+ * @param {Field} record_vk The record view key.
550
+ * @param {RecordCiphertext} record_ciphertext The record ciphertext to decrypt.
551
+ *
552
+ * @returns {RecordPlaintext} The decrypted record plaintext.
449
553
  */
450
554
  static decryptRecordWithRVk(record_vk: Field, record_ciphertext: RecordCiphertext): RecordPlaintext;
451
555
  /**
452
556
  * Decrypts a transition using the transition view key. The ciphertext inputs and outputs
453
557
  * can only be decrypted if the transition view key was generated by the transaction signer.
558
+ *
559
+ * @param {Transition} transition The transition to decrypt.
560
+ * @param {Field} transition_vk The transition view key.
561
+ *
562
+ * @returns {Transition} The decrypted transition.
454
563
  */
455
564
  static decryptTransitionWithVk(transition: Transition, transition_vk: Field): Transition;
456
565
  }
@@ -496,10 +605,14 @@ export class ExecutionRequest {
496
605
  free(): void;
497
606
  /**
498
607
  * Returns the request as a string.
608
+ *
609
+ * @returns {string} String representation of the request.
499
610
  */
500
611
  toString(): string;
501
612
  /**
502
613
  * Builds a request object from a string representation of a request.
614
+ *
615
+ * @param {string} request String representation of the request.
503
616
  */
504
617
  static fromString(request: string): ExecutionRequest;
505
618
  /**
@@ -880,25 +993,36 @@ export class OfflineQuery {
880
993
  free(): void;
881
994
  /**
882
995
  * Creates a new offline query object. The state root is required to be passed in as a string
996
+ *
997
+ * @param {u32} block_height The block height.
998
+ * @param {string} state_root The state root of the current network.
999
+ *
1000
+ * @returns {OfflineQuery} The newly created offline query object.
883
1001
  */
884
1002
  constructor(block_height: number, state_root: string);
885
1003
  /**
886
1004
  * Add a new block height to the offline query object.
1005
+ *
1006
+ * @param {u32} block_height The block height to add.
887
1007
  */
888
1008
  addBlockHeight(block_height: number): void;
889
1009
  /**
890
1010
  * Add a new state path to the offline query object.
891
1011
  *
892
- * @param {string} commitment: The commitment corresponding to a record inpout
893
- * @param {string} state_path: The state path corresponding to the commitment
1012
+ * @param {string} commitment: The commitment corresponding to a record input.
1013
+ * @param {string} state_path: The state path corresponding to the commitment.
894
1014
  */
895
1015
  addStatePath(commitment: string, state_path: string): void;
896
1016
  /**
897
- * Get a json string representation of the offline query object
1017
+ * Get a json string representation of the offline query object.
1018
+ *
1019
+ * @returns {string} JSON string representation of the offline query object.
898
1020
  */
899
1021
  toString(): string;
900
1022
  /**
901
- * Create an offline query object from a json string representation
1023
+ * Create an offline query object from a json string representation.
1024
+ *
1025
+ * @param {string} JSON string representation of the offline query object.
902
1026
  */
903
1027
  static fromString(s: string): OfflineQuery;
904
1028
  }
@@ -982,10 +1106,20 @@ export class Plaintext {
982
1106
  find(name: string): Plaintext;
983
1107
  /**
984
1108
  * Encrypt a plaintext with an address and randomizer.
1109
+ *
1110
+ * @param {Address} address The address to encrypt the plaintext for.
1111
+ * @param {Scalar} randomizer The randomizer to use for encryption.
1112
+ *
1113
+ * @returns {Ciphertext} The encrypted ciphertext.
985
1114
  */
986
1115
  encrypt(address: Address, randomizer: Scalar): Ciphertext;
987
1116
  /**
988
1117
  * Encrypt a plaintext with a transition view key.
1118
+ *
1119
+ * @param {Field} transition_view_key The transition view key of the transition
1120
+ * associated with the plaintext.
1121
+ *
1122
+ * @returns {Ciphertext} The encrypted ciphertext.
989
1123
  */
990
1124
  encryptSymmetric(transition_view_key: Field): Ciphertext;
991
1125
  /**
@@ -1006,6 +1140,8 @@ export class Plaintext {
1006
1140
  static fromBytesLe(bytes: Uint8Array): Plaintext;
1007
1141
  /**
1008
1142
  * Get the left endian byte array representation of the plaintext.
1143
+ *
1144
+ * @returns {Uint8Array} The left endian byte array representation of the plaintext.
1009
1145
  */
1010
1146
  toBytesLe(): Uint8Array;
1011
1147
  /**
@@ -1018,6 +1154,8 @@ export class Plaintext {
1018
1154
  static fromBitsLe(bits: Array<any>): Plaintext;
1019
1155
  /**
1020
1156
  * Get the left endian boolean array representation of the bits of the plaintext.
1157
+ *
1158
+ * @returns {Array} The left endian boolean array representation of the bits of the plaintext.
1021
1159
  */
1022
1160
  toBitsLe(): Array<any>;
1023
1161
  /**
@@ -1030,6 +1168,8 @@ export class Plaintext {
1030
1168
  static fromFields(fields: Array<any>): Plaintext;
1031
1169
  /**
1032
1170
  * Get the field array representation of the plaintext.
1171
+ *
1172
+ * @returns {Array} The field array representation of the plaintext.
1033
1173
  */
1034
1174
  toFields(): Array<any>;
1035
1175
  /**
@@ -1495,6 +1635,17 @@ export class ProgramManager {
1495
1635
  * @param imports The imports to the program in the format {"programname.aleo":"aleo instructions source code"}.
1496
1636
  */
1497
1637
  static authorize(private_key: PrivateKey, program: string, function_name: string, inputs: Array<any>, imports?: object | null): Promise<Authorization>;
1638
+ /**
1639
+ * Create an execution `Authorization` without generating a circuit. Use this function when
1640
+ * fast delegated proving is needed.
1641
+ *
1642
+ * @param private_key The private key of the signer.
1643
+ * @param program The program source code containing the function to authorize.
1644
+ * @param function_name The function to authorize.
1645
+ * @param inputs A javascript array of inputs to the function.
1646
+ * @param imports The imports to the program in the format {"programname.aleo":"aleo instructions source code"}.
1647
+ */
1648
+ static buildAuthorizationUnchecked(private_key: PrivateKey, program: string, function_name: string, inputs: Array<any>, imports?: object | null): Promise<Authorization>;
1498
1649
  /**
1499
1650
  * Create an `Authorization` for `credits.aleo/fee_public` or `credits.aleo/fee_private`.
1500
1651
  * This object requires an associated execution or deployment ID. This can be gained from
@@ -1645,6 +1796,24 @@ export class ProgramManager {
1645
1796
  * @returns {Transaction} Transaction object
1646
1797
  */
1647
1798
  static buildJoinTransaction(private_key: PrivateKey, record_1: RecordPlaintext, record_2: RecordPlaintext, priority_fee_credits: number, fee_record?: RecordPlaintext | null, url?: string | null, join_proving_key?: ProvingKey | null, join_verifying_key?: VerifyingKey | null, fee_proving_key?: ProvingKey | null, fee_verifying_key?: VerifyingKey | null, offline_query?: OfflineQuery | null): Promise<Transaction>;
1799
+ /**
1800
+ * Create a `ProvingRequest` object. This object creates authorizations for the top level
1801
+ * function and associated fee function. This object can be sent directly to a remote prover
1802
+ * OR used to extract both execution and fee authorizations.
1803
+ *
1804
+ * @param private_key The private key of the signer.
1805
+ * @param program The program source code containing the function to authorize.
1806
+ * @param function_name The function to authorize.
1807
+ * @param inputs A javascript array of inputs to the function.
1808
+ * @param base_fee_credits The base fee to be paid for the authorization
1809
+ * @param priority_fee_credits The optional priority fee to be paid for the transaction
1810
+ * @param fee_record The record to spend the fee from
1811
+ * @param imports The imports to the program in the format {"programname.aleo":"aleo instructions source code"}.
1812
+ * @param url The url of the Aleo network node to send the transaction to
1813
+ * @param broadcast (optional) Flag to indicate if the transaction should be broadcast
1814
+ * @returns {Authorization}
1815
+ */
1816
+ static buildProvingRequest(private_key: PrivateKey, program: string, function_name: string, inputs: Array<any>, base_fee_credits: number, priority_fee_credits: number, fee_record: RecordPlaintext | null | undefined, imports: object | null | undefined, broadcast: boolean, unchecked: boolean): Promise<ProvingRequest>;
1648
1817
  /**
1649
1818
  * Split an Aleo credits record into two separate records. This function does not require a fee.
1650
1819
  *
@@ -1880,6 +2049,57 @@ export class ProvingKey {
1880
2049
  */
1881
2050
  toString(): string;
1882
2051
  }
2052
+ /**
2053
+ * Represents a proving request to a prover.
2054
+ */
2055
+ export class ProvingRequest {
2056
+ private constructor();
2057
+ free(): void;
2058
+ /**
2059
+ * Creates a new ProvingRequest from a function Authorization and an optional fee Authorization.
2060
+ *
2061
+ * @param {Authorization} authorization An Authorization for a function.
2062
+ * @param {Authorization} fee_authorization The authorization for the `credits.aleo/fee_public` or `credits.aleo/fee_private` function that pays the fee for the execution of the main function.
2063
+ * @param {boolean} broadcast Flag that indicates whether the remote proving service should attempt to submit the transaction on the caller's behalf.
2064
+ */
2065
+ static new(authorization: Authorization, fee_authorization: Authorization | null | undefined, broadcast: boolean): ProvingRequest;
2066
+ /**
2067
+ * Creates a ProvingRequest from a string representation.
2068
+ *
2069
+ * @param {Uint8Array} request String representation of the ProvingRequest.
2070
+ */
2071
+ static fromString(request: string): ProvingRequest;
2072
+ /**
2073
+ * Creates a string representation of the ProvingRequest.
2074
+ */
2075
+ toString(): string;
2076
+ /**
2077
+ * Creates a ProvingRequest from a left-endian byte representation of the ProvingRequest.
2078
+ *
2079
+ * @param {Uint8Array} bytes Left-endian bytes representing the proving request.
2080
+ */
2081
+ static fromBytesLe(bytes: Uint8Array): ProvingRequest;
2082
+ /**
2083
+ * Creates a left-endian byte representation of the ProvingRequest.
2084
+ */
2085
+ toBytesLe(): Uint8Array;
2086
+ /**
2087
+ * Get the Authorization of the main function in the ProvingRequest.
2088
+ */
2089
+ authorization(): Authorization;
2090
+ /**
2091
+ * Get the fee Authorization in the ProvingRequest.
2092
+ */
2093
+ feeAuthorization(): Authorization | undefined;
2094
+ /**
2095
+ * Get the broadcast flag set in the ProvingRequest.
2096
+ */
2097
+ broadcast(): boolean;
2098
+ /**
2099
+ * Check if a ProvingRequest is the same as another ProvingRequest.
2100
+ */
2101
+ equals(other: ProvingRequest): boolean;
2102
+ }
1883
2103
  /**
1884
2104
  * Encrypted Aleo record
1885
2105
  */
@@ -1942,14 +2162,20 @@ export class RecordCiphertext {
1942
2162
  static fromBytesLe(bytes: Uint8Array): RecordCiphertext;
1943
2163
  /**
1944
2164
  * Get the left endian byte array representation of the record ciphertext.
2165
+ *
2166
+ * @returns {Uint8Array} Left endian byte array representation of the record ciphertext.
1945
2167
  */
1946
2168
  toBytesLe(): Uint8Array;
1947
2169
  /**
1948
2170
  * Get the left endian boolean array representation of the record ciphertext bits.
2171
+ *
2172
+ * returns {Array} Left endian boolean array representation of the bits of the record ciphertext.
1949
2173
  */
1950
2174
  toBitsLe(): Array<any>;
1951
2175
  /**
1952
2176
  * Get the field array representation of the record ciphertext.
2177
+ *
2178
+ * @returns {Array} Field array representation of the record ciphertext.
1953
2179
  */
1954
2180
  toFields(): Array<any>;
1955
2181
  /**
@@ -1962,6 +2188,8 @@ export class RecordCiphertext {
1962
2188
  decryptWithRecordViewKey(record_vk: Field): RecordPlaintext;
1963
2189
  /**
1964
2190
  * Get the record nonce.
2191
+ *
2192
+ * @returns {Group} The record nonce.
1965
2193
  */
1966
2194
  nonce(): Group;
1967
2195
  }
@@ -1971,17 +2199,27 @@ export class RecordCiphertext {
1971
2199
  export class RecordPlaintext {
1972
2200
  private constructor();
1973
2201
  free(): void;
1974
- commitment(program_id: string, record_name: string): Field;
2202
+ commitment(program_id: string, record_name: string, record_view_key: string): Field;
1975
2203
  /**
1976
2204
  * Return a record plaintext from a string.
1977
2205
  *
1978
- * @param {string} record String representation of a plaintext representation of an Aleo record
2206
+ * @param {string} record String representation of a plaintext representation of an Aleo record.
2207
+ *
1979
2208
  * @returns {RecordPlaintext} Record plaintext
1980
2209
  */
1981
2210
  static fromString(record: string): RecordPlaintext;
2211
+ /**
2212
+ * Get the record entry matching a key.
2213
+ *
2214
+ * @param {string} input The key to retrieve the value in the record data field.
2215
+ *
2216
+ * @returns {Plaintext} The plaintext value corresponding to the key.
2217
+ */
1982
2218
  getMember(input: string): Plaintext;
1983
2219
  /**
1984
2220
  * Get the owner of the record.
2221
+ *
2222
+ * @returns {Address} Address of the owner of the record.
1985
2223
  */
1986
2224
  owner(): Address;
1987
2225
  /**
@@ -2084,14 +2322,24 @@ export class RecordPlaintext {
2084
2322
  * @param {PrivateKey} private_key Private key of the account that owns the record
2085
2323
  * @param {string} program_id Program ID of the program that the record is associated with
2086
2324
  * @param {string} record_name Name of the record
2325
+ * @param {string} record_view_key The string representation of the record view key.
2087
2326
  *
2088
2327
  * @returns {string} Serial number of the record
2089
2328
  */
2090
- serialNumberString(private_key: PrivateKey, program_id: string, record_name: string): string;
2329
+ serialNumberString(private_key: PrivateKey, program_id: string, record_name: string, record_view_key: string): string;
2091
2330
  /**
2092
2331
  * Get the tag of the record using the graph key.
2093
2332
  */
2094
2333
  tag(graph_key: GraphKey, commitment: Field): Field;
2334
+ /**
2335
+ * Generate the record view key. The record view key can only decrypt record if the
2336
+ * supplied view key belongs to the record owner.
2337
+ *
2338
+ * @param {ViewKey} view_key View key used to generate the record view key
2339
+ *
2340
+ * @returns {Group} record view key
2341
+ */
2342
+ recordViewKey(view_key: ViewKey): Field;
2095
2343
  }
2096
2344
  /**
2097
2345
  * Scalar field element.
@@ -2509,18 +2757,28 @@ export class Transition {
2509
2757
  outputs(convert_to_js: boolean): Array<any>;
2510
2758
  /**
2511
2759
  * Get the transition public key of the transition.
2760
+ *
2761
+ * @returns {Group} Transition public key
2512
2762
  */
2513
2763
  tpk(): Group;
2514
2764
  /**
2515
2765
  * Get the transition view key of the transition.
2766
+ *
2767
+ * @param {ViewKey} view_key The view key of the transition signer.
2768
+ *
2769
+ * @returns {Field} Transition view key
2516
2770
  */
2517
2771
  tvk(view_key: ViewKey): Field;
2518
2772
  /**
2519
2773
  * Get the transition commitment of the transition.
2774
+ *
2775
+ * @returns {Field} Transition commitment
2520
2776
  */
2521
2777
  tcm(): Field;
2522
2778
  /**
2523
2779
  * Get the transition signer commitment of the transition.
2780
+ *
2781
+ * @returns {Field} Transition signer commitment
2524
2782
  */
2525
2783
  scm(): Field;
2526
2784
  /**
Binary file