@provablehq/sdk 0.9.0 → 0.9.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.
@@ -1,8 +1,8 @@
1
1
  import 'core-js/proposals/json-parse-with-source.js';
2
2
  import { ViewKey, ComputeKey, Address, PrivateKeyCiphertext, PrivateKey, RecordCiphertext, ProvingKey, VerifyingKey } from '@provablehq/wasm/mainnet.js';
3
3
  export { Address, BHP1024, BHP256, BHP512, BHP768, Ciphertext, ComputeKey, ExecutionResponse, Field, Execution as FunctionExecution, Group, OfflineQuery, Pedersen128, Pedersen64, Plaintext, Poseidon2, Poseidon4, Poseidon8, PrivateKey, PrivateKeyCiphertext, Program, ProgramManager as ProgramManagerBase, ProvingKey, RecordCiphertext, RecordPlaintext, Scalar, Signature, Transaction, Transition, VerifyingKey, ViewKey, initThreadPool, verifyFunctionExecution } from '@provablehq/wasm/mainnet.js';
4
- import { C as CREDITS_PROGRAM_KEYS, c as PRIVATE_TRANSFER, d as PRIVATE_TO_PUBLIC_TRANSFER, f as PUBLIC_TRANSFER, g as PUBLIC_TRANSFER_AS_SIGNER, h as PUBLIC_TO_PRIVATE_TRANSFER, l as logAndThrow } from './program-manager-C1m8QHkg.js';
5
- export { A as AleoKeyProvider, a as AleoKeyProviderParams, b as AleoNetworkClient, K as KEY_STORE, e as PRIVATE_TRANSFER_TYPES, P as ProgramManager, V as VALID_TRANSFER_TYPES } from './program-manager-C1m8QHkg.js';
4
+ import { C as CREDITS_PROGRAM_KEYS, c as PRIVATE_TRANSFER, d as PRIVATE_TO_PUBLIC_TRANSFER, f as PUBLIC_TRANSFER, g as PUBLIC_TRANSFER_AS_SIGNER, h as PUBLIC_TO_PRIVATE_TRANSFER, l as logAndThrow } from './program-manager-DMDKstZ8.js';
5
+ export { A as AleoKeyProvider, a as AleoKeyProviderParams, b as AleoNetworkClient, K as KEY_STORE, e as PRIVATE_TRANSFER_TYPES, P as ProgramManager, V as VALID_TRANSFER_TYPES } from './program-manager-DMDKstZ8.js';
6
6
  import { wrap } from 'comlink';
7
7
 
8
8
  /**
@@ -30,6 +30,9 @@ declare class AleoNetworkClient {
30
30
  [key: string]: string;
31
31
  };
32
32
  account: Account | undefined;
33
+ ctx: {
34
+ [key: string]: string;
35
+ };
33
36
  readonly network: string;
34
37
  constructor(host: string, options?: AleoNetworkClientOptions);
35
38
  /**
@@ -1,6 +1,6 @@
1
1
  import './node-polyfill.js';
2
2
  export { Account, BlockHeightSearch, NetworkRecordProvider, OfflineKeyProvider, OfflineSearchParams, createAleoWorker, initializeWasm } from './browser.js';
3
- export { A as AleoKeyProvider, a as AleoKeyProviderParams, b as AleoNetworkClient, C as CREDITS_PROGRAM_KEYS, K as KEY_STORE, d as PRIVATE_TO_PUBLIC_TRANSFER, c as PRIVATE_TRANSFER, e as PRIVATE_TRANSFER_TYPES, h as PUBLIC_TO_PRIVATE_TRANSFER, f as PUBLIC_TRANSFER, g as PUBLIC_TRANSFER_AS_SIGNER, P as ProgramManager, V as VALID_TRANSFER_TYPES, l as logAndThrow } from './program-manager-C1m8QHkg.js';
3
+ export { A as AleoKeyProvider, a as AleoKeyProviderParams, b as AleoNetworkClient, C as CREDITS_PROGRAM_KEYS, K as KEY_STORE, d as PRIVATE_TO_PUBLIC_TRANSFER, c as PRIVATE_TRANSFER, e as PRIVATE_TRANSFER_TYPES, h as PUBLIC_TO_PRIVATE_TRANSFER, f as PUBLIC_TRANSFER, g as PUBLIC_TRANSFER_AS_SIGNER, P as ProgramManager, V as VALID_TRANSFER_TYPES, l as logAndThrow } from './program-manager-DMDKstZ8.js';
4
4
  export { Address, BHP1024, BHP256, BHP512, BHP768, Ciphertext, ComputeKey, ExecutionResponse, Field, Execution as FunctionExecution, Group, OfflineQuery, Pedersen128, Pedersen64, Plaintext, Poseidon2, Poseidon4, Poseidon8, PrivateKey, PrivateKeyCiphertext, Program, ProgramManager as ProgramManagerBase, ProvingKey, RecordCiphertext, RecordPlaintext, Scalar, Signature, Transaction, Transition, VerifyingKey, ViewKey, initThreadPool, verifyFunctionExecution } from '@provablehq/wasm/mainnet.js';
5
5
  import 'core-js/proposals/json-parse-with-source.js';
6
6
  import 'node:crypto';
@@ -1,5 +1,38 @@
1
1
  import { PrivateKey, RecordCiphertext, Program, Plaintext, Address, Transaction, Metadata, VerifyingKey, ProvingKey, ProgramManager as ProgramManager$1, RecordPlaintext, verifyFunctionExecution } from '@provablehq/wasm/mainnet.js';
2
2
 
3
+ function detectBrowser() {
4
+ const userAgent = navigator.userAgent;
5
+ if (/chrome|crios|crmo/i.test(userAgent) && !/edge|edg|opr/i.test(userAgent)) {
6
+ return "chrome";
7
+ }
8
+ else if (/firefox|fxios/i.test(userAgent)) {
9
+ return "firefox";
10
+ }
11
+ else if (/safari/i.test(userAgent) && !/chrome|crios|crmo|android/i.test(userAgent)) {
12
+ return "safari";
13
+ }
14
+ else if (/edg/i.test(userAgent)) {
15
+ return "edge";
16
+ }
17
+ else if (/opr\//i.test(userAgent)) {
18
+ return "opera";
19
+ }
20
+ else {
21
+ return "browser";
22
+ }
23
+ }
24
+ function environment() {
25
+ if ((typeof process !== 'undefined') &&
26
+ (process.release?.name === 'node')) {
27
+ return 'node';
28
+ }
29
+ else if (typeof window !== 'undefined') {
30
+ return detectBrowser();
31
+ }
32
+ else {
33
+ return 'unknown';
34
+ }
35
+ }
3
36
  function logAndThrow(message) {
4
37
  console.error(message);
5
38
  throw new Error(message);
@@ -79,17 +112,20 @@ class AleoNetworkClient {
79
112
  host;
80
113
  headers;
81
114
  account;
115
+ ctx;
82
116
  network;
83
117
  constructor(host, options) {
84
118
  this.host = host + "/mainnet";
85
119
  this.network = "mainnet";
120
+ this.ctx = {};
86
121
  if (options && options.headers) {
87
122
  this.headers = options.headers;
88
123
  }
89
124
  else {
90
125
  this.headers = {
91
126
  // This is replaced by the actual version by a Rollup plugin
92
- "X-Aleo-SDK-Version": "0.9.0",
127
+ "X-Aleo-SDK-Version": "0.9.1",
128
+ "X-Aleo-environment": environment(),
93
129
  };
94
130
  }
95
131
  }
@@ -193,9 +229,13 @@ class AleoNetworkClient {
193
229
  */
194
230
  async fetchRaw(url = "/") {
195
231
  try {
232
+ const ctx = { ...this.ctx };
196
233
  return await retryWithBackoff(async () => {
197
234
  const response = await get(this.host + url, {
198
- headers: this.headers,
235
+ headers: {
236
+ ...this.headers,
237
+ ...ctx,
238
+ },
199
239
  });
200
240
  return await response.text();
201
241
  });
@@ -470,7 +510,16 @@ class AleoNetworkClient {
470
510
  * const records = networkClient.findUnspentRecords(startHeight, undefined, ["credits.aleo"], undefined, maxMicrocredits);
471
511
  */
472
512
  async findUnspentRecords(startHeight, endHeight, programs, amounts, maxMicrocredits, nonces, privateKey) {
473
- return await this.findRecords(startHeight, endHeight, true, programs, amounts, maxMicrocredits, nonces, privateKey);
513
+ try {
514
+ this.ctx = { "X-ALEO-METHOD": "findUnspentRecords" };
515
+ return await this.findRecords(startHeight, endHeight, true, programs, amounts, maxMicrocredits, nonces, privateKey);
516
+ }
517
+ catch (error) {
518
+ throw new Error("Error finding unspent records: " + error);
519
+ }
520
+ finally {
521
+ this.ctx = {};
522
+ }
474
523
  }
475
524
  /**
476
525
  * Returns the contents of the block at the specified block height.
@@ -483,12 +532,16 @@ class AleoNetworkClient {
483
532
  */
484
533
  async getBlock(blockHeight) {
485
534
  try {
535
+ this.ctx = { "X-ALEO-METHOD": "getBlock" };
486
536
  const block = await this.fetchData("/block/" + blockHeight);
487
537
  return block;
488
538
  }
489
539
  catch (error) {
490
540
  throw new Error(`Error fetching block ${blockHeight}: ${error}`);
491
541
  }
542
+ finally {
543
+ this.ctx = {};
544
+ }
492
545
  }
493
546
  /**
494
547
  * Returns the contents of the block with the specified hash.
@@ -504,12 +557,16 @@ class AleoNetworkClient {
504
557
  */
505
558
  async getBlockByHash(blockHash) {
506
559
  try {
560
+ this.ctx = { "X-ALEO-METHOD": "getBlockByHash" };
507
561
  const block = await this.fetchData(`/block/${blockHash}`);
508
562
  return block;
509
563
  }
510
564
  catch (error) {
511
565
  throw new Error(`Error fetching block ${blockHash}: ${error}`);
512
566
  }
567
+ finally {
568
+ this.ctx = {};
569
+ }
513
570
  }
514
571
  /**
515
572
  * Returns a range of blocks between the specified block heights. A maximum of 50 blocks can be fetched at a time.
@@ -533,11 +590,15 @@ class AleoNetworkClient {
533
590
  */
534
591
  async getBlockRange(start, end) {
535
592
  try {
593
+ this.ctx = { "X-ALEO-METHOD": "getBlockRange" };
536
594
  return await this.fetchData("/blocks?start=" + start + "&end=" + end);
537
595
  }
538
596
  catch (error) {
539
597
  throw new Error(`Error fetching blocks between ${start} and ${end}: ${error}`);
540
598
  }
599
+ finally {
600
+ this.ctx = {};
601
+ }
541
602
  }
542
603
  /**
543
604
  * Returns the deployment transaction id associated with the specified program.
@@ -559,6 +620,7 @@ class AleoNetworkClient {
559
620
  * const verifyingKeys = transaction.verifyingKeys();
560
621
  */
561
622
  async getDeploymentTransactionIDForProgram(program) {
623
+ this.ctx = { "X-ALEO-METHOD": "getDeploymentTransactionIDForProgram" };
562
624
  if (program instanceof Program) {
563
625
  program = program.id();
564
626
  }
@@ -569,6 +631,9 @@ class AleoNetworkClient {
569
631
  catch (error) {
570
632
  throw new Error(`Error fetching deployment transaction for program ${program}: ${error}`);
571
633
  }
634
+ finally {
635
+ this.ctx = {};
636
+ }
572
637
  }
573
638
  /**
574
639
  * Returns the deployment transaction associated with a specified program as a JSON object.
@@ -592,12 +657,16 @@ class AleoNetworkClient {
592
657
  program = program.id();
593
658
  }
594
659
  try {
660
+ this.ctx = { "X-ALEO-METHOD": "getDeploymentTransactionForProgram" };
595
661
  const transaction_id = (await this.getDeploymentTransactionIDForProgram(program));
596
662
  return await this.getTransaction(transaction_id);
597
663
  }
598
664
  catch (error) {
599
665
  throw new Error(`Error fetching deployment transaction for program ${program}: ${error}`);
600
666
  }
667
+ finally {
668
+ this.ctx = {};
669
+ }
601
670
  }
602
671
  /**
603
672
  * Returns the deployment transaction associated with a specified program as a wasm object.
@@ -620,12 +689,16 @@ class AleoNetworkClient {
620
689
  */
621
690
  async getDeploymentTransactionObjectForProgram(program) {
622
691
  try {
692
+ this.ctx = { "X-ALEO-METHOD": "getDeploymentTransactionObjectForProgram" };
623
693
  const transaction_id = (await this.getDeploymentTransactionIDForProgram(program));
624
694
  return await this.getTransactionObject(transaction_id);
625
695
  }
626
696
  catch (error) {
627
697
  throw new Error(`Error fetching deployment transaction for program ${program}: ${error}`);
628
698
  }
699
+ finally {
700
+ this.ctx = {};
701
+ }
629
702
  }
630
703
  /**
631
704
  * Returns the contents of the latest block as JSON.
@@ -642,11 +715,15 @@ class AleoNetworkClient {
642
715
  */
643
716
  async getLatestBlock() {
644
717
  try {
718
+ this.ctx = { "X-ALEO-METHOD": "getLatestBlock" };
645
719
  return (await this.fetchData("/block/latest"));
646
720
  }
647
721
  catch (error) {
648
722
  throw new Error(`Error fetching latest block: ${error}`);
649
723
  }
724
+ finally {
725
+ this.ctx = {};
726
+ }
650
727
  }
651
728
  /**
652
729
  * Returns the latest committee.
@@ -665,11 +742,15 @@ class AleoNetworkClient {
665
742
  */
666
743
  async getLatestCommittee() {
667
744
  try {
745
+ this.ctx = { "X-ALEO-METHOD": "getLatestCommittee" };
668
746
  return await this.fetchData("/committee/latest");
669
747
  }
670
748
  catch (error) {
671
749
  throw new Error(`Error fetching latest committee: ${error}`);
672
750
  }
751
+ finally {
752
+ this.ctx = {};
753
+ }
673
754
  }
674
755
  /**
675
756
  * Returns the committee at the specified block height.
@@ -689,11 +770,15 @@ class AleoNetworkClient {
689
770
  */
690
771
  async getCommitteeByBlockHeight(blockHeight) {
691
772
  try {
773
+ this.ctx = { "X-ALEO-METHOD": "getCommitteeByBlockHeight" };
692
774
  return await this.fetchData(`/committee/${blockHeight}`);
693
775
  }
694
776
  catch (error) {
695
777
  throw new Error(`Error fetching committee at height ${blockHeight}: ${error}`);
696
778
  }
779
+ finally {
780
+ this.ctx = {};
781
+ }
697
782
  }
698
783
  /**
699
784
  * Returns the latest block height.
@@ -710,11 +795,15 @@ class AleoNetworkClient {
710
795
  */
711
796
  async getLatestHeight() {
712
797
  try {
798
+ this.ctx = { "X-ALEO-METHOD": "getLatestHeight" };
713
799
  return Number(await this.fetchData("/block/height/latest"));
714
800
  }
715
801
  catch (error) {
716
802
  throw new Error(`Error fetching latest height: ${error}`);
717
803
  }
804
+ finally {
805
+ this.ctx = {};
806
+ }
718
807
  }
719
808
  /**
720
809
  * Returns the latest block hash.
@@ -732,11 +821,15 @@ class AleoNetworkClient {
732
821
  */
733
822
  async getLatestBlockHash() {
734
823
  try {
824
+ this.ctx = { "X-ALEO-METHOD": "getLatestBlockHash" };
735
825
  return String(await this.fetchData("/block/hash/latest"));
736
826
  }
737
827
  catch (error) {
738
828
  throw new Error(`Error fetching latest hash: ${error}`);
739
829
  }
830
+ finally {
831
+ this.ctx = {};
832
+ }
740
833
  }
741
834
  /**
742
835
  * Returns the source code of a program given a program ID.
@@ -756,11 +849,15 @@ class AleoNetworkClient {
756
849
  */
757
850
  async getProgram(programId) {
758
851
  try {
852
+ this.ctx = { "X-ALEO-METHOD": "getProgram" };
759
853
  return await this.fetchData("/program/" + programId);
760
854
  }
761
855
  catch (error) {
762
856
  throw new Error(`Error fetching program ${programId}: ${error}`);
763
857
  }
858
+ finally {
859
+ this.ctx = {};
860
+ }
764
861
  }
765
862
  /**
766
863
  * Returns a program object from a program ID or program source code.
@@ -786,6 +883,7 @@ class AleoNetworkClient {
786
883
  */
787
884
  async getProgramObject(inputProgram) {
788
885
  try {
886
+ this.ctx = { "X-ALEO-METHOD": "getProgramObject" };
789
887
  return Program.fromString(inputProgram);
790
888
  }
791
889
  catch (error) {
@@ -796,6 +894,9 @@ class AleoNetworkClient {
796
894
  throw new Error(`${inputProgram} is neither a program name or a valid program: ${error}`);
797
895
  }
798
896
  }
897
+ finally {
898
+ this.ctx = {};
899
+ }
799
900
  }
800
901
  /**
801
902
  * Returns an object containing the source code of a program and the source code of all programs it imports
@@ -829,6 +930,7 @@ class AleoNetworkClient {
829
930
  */
830
931
  async getProgramImports(inputProgram) {
831
932
  try {
933
+ this.ctx = { "X-ALEO-METHOD": "getProgramImports" };
832
934
  const imports = {};
833
935
  // Get the program object or fail if the program is not valid or does not exist
834
936
  const program = inputProgram instanceof Program
@@ -855,6 +957,9 @@ class AleoNetworkClient {
855
957
  catch (error) {
856
958
  logAndThrow("Error fetching program imports: " + error.message);
857
959
  }
960
+ finally {
961
+ this.ctx = {};
962
+ }
858
963
  }
859
964
  /**
860
965
  * Get a list of the program names that a program imports.
@@ -874,6 +979,7 @@ class AleoNetworkClient {
874
979
  */
875
980
  async getProgramImportNames(inputProgram) {
876
981
  try {
982
+ this.ctx = { "X-ALEO-METHOD": "getProgramImportNames" };
877
983
  const program = inputProgram instanceof Program
878
984
  ? inputProgram
879
985
  : await this.getProgramObject(inputProgram);
@@ -882,6 +988,9 @@ class AleoNetworkClient {
882
988
  catch (error) {
883
989
  throw new Error(`Error fetching imports for program ${inputProgram instanceof Program ? inputProgram.id() : inputProgram}: ${error.message}`);
884
990
  }
991
+ finally {
992
+ this.ctx = {};
993
+ }
885
994
  }
886
995
  /**
887
996
  * Returns the names of the mappings of a program.
@@ -909,11 +1018,15 @@ class AleoNetworkClient {
909
1018
  */
910
1019
  async getProgramMappingNames(programId) {
911
1020
  try {
1021
+ this.ctx = { "X-ALEO-METHOD": "getProgramMappingNames" };
912
1022
  return await this.fetchData(`/program/${programId}/mappings`);
913
1023
  }
914
1024
  catch (error) {
915
1025
  throw new Error(`Error fetching mappings for program ${programId} - ensure the program exists on chain before trying again`);
916
1026
  }
1027
+ finally {
1028
+ this.ctx = {};
1029
+ }
917
1030
  }
918
1031
  /**
919
1032
  * Returns the value of a program's mapping for a specific key.
@@ -936,12 +1049,16 @@ class AleoNetworkClient {
936
1049
  */
937
1050
  async getProgramMappingValue(programId, mappingName, key) {
938
1051
  try {
1052
+ this.ctx = { "X-ALEO-METHOD": "getProgramMappingValue" };
939
1053
  const keyString = key instanceof Plaintext ? key.toString() : key;
940
1054
  return await this.fetchData(`/program/${programId}/mapping/${mappingName}/${keyString}`);
941
1055
  }
942
1056
  catch (error) {
943
1057
  throw new Error(`Error fetching value for key '${key}' in mapping '${mappingName}' in program '${programId}' - ensure the mapping exists and the key is correct`);
944
1058
  }
1059
+ finally {
1060
+ this.ctx = {};
1061
+ }
945
1062
  }
946
1063
  /**
947
1064
  * Returns the value of a mapping as a wasm Plaintext object. Returning an object in this format allows it to be converted to a Js type and for its internal members to be inspected if it's a struct or array.
@@ -979,6 +1096,7 @@ class AleoNetworkClient {
979
1096
  */
980
1097
  async getProgramMappingPlaintext(programId, mappingName, key) {
981
1098
  try {
1099
+ this.ctx = { "X-ALEO-METHOD": "getProgramMappingPlaintext" };
982
1100
  const keyString = key instanceof Plaintext ? key.toString() : key;
983
1101
  const value = await this.fetchRaw(`/program/${programId}/mapping/${mappingName}/${keyString}`);
984
1102
  return Plaintext.fromString(JSON.parse(value));
@@ -986,6 +1104,9 @@ class AleoNetworkClient {
986
1104
  catch (error) {
987
1105
  throw new Error("Failed to fetch mapping value." + error);
988
1106
  }
1107
+ finally {
1108
+ this.ctx = {};
1109
+ }
989
1110
  }
990
1111
  /**
991
1112
  * Returns the public balance of an address from the account mapping in credits.aleo
@@ -1007,6 +1128,7 @@ class AleoNetworkClient {
1007
1128
  */
1008
1129
  async getPublicBalance(address) {
1009
1130
  try {
1131
+ this.ctx = { "X-ALEO-METHOD": "getPublicBalance" };
1010
1132
  const addressString = address instanceof Address ? address.to_string() : address;
1011
1133
  const balanceStr = await this.getProgramMappingValue("credits.aleo", "account", addressString);
1012
1134
  return balanceStr ? parseInt(balanceStr) : 0;
@@ -1014,6 +1136,9 @@ class AleoNetworkClient {
1014
1136
  catch (error) {
1015
1137
  throw new Error(`Error fetching public balance for ${address}: ${error}`);
1016
1138
  }
1139
+ finally {
1140
+ this.ctx = {};
1141
+ }
1017
1142
  }
1018
1143
  /**
1019
1144
  * Returns the latest state/merkle root of the Aleo blockchain.
@@ -1031,11 +1156,15 @@ class AleoNetworkClient {
1031
1156
  */
1032
1157
  async getStateRoot() {
1033
1158
  try {
1159
+ this.ctx = { "X-ALEO-METHOD": "getStateRoot" };
1034
1160
  return await this.fetchData("/stateRoot/latest");
1035
1161
  }
1036
1162
  catch (error) {
1037
1163
  throw new Error(`Error fetching latest state root: ${error}`);
1038
1164
  }
1165
+ finally {
1166
+ this.ctx = {};
1167
+ }
1039
1168
  }
1040
1169
  /**
1041
1170
  * Returns a transaction by its unique identifier.
@@ -1053,11 +1182,15 @@ class AleoNetworkClient {
1053
1182
  */
1054
1183
  async getTransaction(transactionId) {
1055
1184
  try {
1185
+ this.ctx = { "X-ALEO-METHOD": "getTransaction" };
1056
1186
  return await this.fetchData("/transaction/" + transactionId);
1057
1187
  }
1058
1188
  catch (error) {
1059
1189
  throw new Error(`Error fetching transaction ${transactionId}: ${error}`);
1060
1190
  }
1191
+ finally {
1192
+ this.ctx = {};
1193
+ }
1061
1194
  }
1062
1195
  /**
1063
1196
  * Returns a confirmed transaction by its unique identifier.
@@ -1076,11 +1209,15 @@ class AleoNetworkClient {
1076
1209
  */
1077
1210
  async getConfirmedTransaction(transactionId) {
1078
1211
  try {
1212
+ this.ctx = { "X-ALEO-METHOD": "getConfirmedTransaction" };
1079
1213
  return await this.fetchData(`/transaction/confirmed/${transactionId}`);
1080
1214
  }
1081
1215
  catch (error) {
1082
1216
  throw new Error(`Error fetching confirmed transaction ${transactionId}: ${error}`);
1083
1217
  }
1218
+ finally {
1219
+ this.ctx = {};
1220
+ }
1084
1221
  }
1085
1222
  /**
1086
1223
  * Returns a transaction as a wasm object. Getting a transaction of this type will allow the ability for the inputs,
@@ -1109,12 +1246,16 @@ class AleoNetworkClient {
1109
1246
  */
1110
1247
  async getTransactionObject(transactionId) {
1111
1248
  try {
1249
+ this.ctx = { "X-ALEO-METHOD": "getTransactionObject" };
1112
1250
  const transaction = await this.fetchRaw("/transaction/" + transactionId);
1113
1251
  return Transaction.fromString(transaction);
1114
1252
  }
1115
1253
  catch (error) {
1116
1254
  throw new Error(`Error fetching transaction object ${transactionId}: ${error}`);
1117
1255
  }
1256
+ finally {
1257
+ this.ctx = {};
1258
+ }
1118
1259
  }
1119
1260
  /**
1120
1261
  * Returns the transactions present at the specified block height.
@@ -1132,11 +1273,15 @@ class AleoNetworkClient {
1132
1273
  */
1133
1274
  async getTransactions(blockHeight) {
1134
1275
  try {
1276
+ this.ctx = { "X-ALEO-METHOD": "getTransactions" };
1135
1277
  return await this.fetchData("/block/" + blockHeight.toString() + "/transactions");
1136
1278
  }
1137
1279
  catch (error) {
1138
1280
  throw new Error(`Error fetching transactions: ${error}`);
1139
1281
  }
1282
+ finally {
1283
+ this.ctx = {};
1284
+ }
1140
1285
  }
1141
1286
  /**
1142
1287
  * Returns the confirmed transactions present in the block with the specified block hash.
@@ -1154,6 +1299,7 @@ class AleoNetworkClient {
1154
1299
  */
1155
1300
  async getTransactionsByBlockHash(blockHash) {
1156
1301
  try {
1302
+ this.ctx = { "X-ALEO-METHOD": "getTransactionsByBlockHash" };
1157
1303
  const block = await this.fetchData(`/block/${blockHash}`);
1158
1304
  const height = block.header.metadata.height;
1159
1305
  return await this.getTransactions(Number(height));
@@ -1161,6 +1307,9 @@ class AleoNetworkClient {
1161
1307
  catch (error) {
1162
1308
  throw new Error(`Error fetching transactions for block ${blockHash}: ${error}`);
1163
1309
  }
1310
+ finally {
1311
+ this.ctx = {};
1312
+ }
1164
1313
  }
1165
1314
  /**
1166
1315
  * Returns the transactions in the memory pool. This method requires access to a validator's REST API.
@@ -1178,11 +1327,15 @@ class AleoNetworkClient {
1178
1327
  */
1179
1328
  async getTransactionsInMempool() {
1180
1329
  try {
1330
+ this.ctx = { "X-ALEO-METHOD": "getTransactionsInMempool" };
1181
1331
  return await this.fetchData("/memoryPool/transactions");
1182
1332
  }
1183
1333
  catch (error) {
1184
1334
  throw new Error(`Error fetching transactions from mempool: ${error}`);
1185
1335
  }
1336
+ finally {
1337
+ this.ctx = {};
1338
+ }
1186
1339
  }
1187
1340
  /**
1188
1341
  * Returns the transition ID of the transition corresponding to the ID of the input or output.
@@ -1194,11 +1347,15 @@ class AleoNetworkClient {
1194
1347
  */
1195
1348
  async getTransitionId(inputOrOutputID) {
1196
1349
  try {
1350
+ this.ctx = { "X-ALEO-METHOD": "getTransitionId" };
1197
1351
  return await this.fetchData("/find/transitionID/" + inputOrOutputID);
1198
1352
  }
1199
1353
  catch (error) {
1200
1354
  throw new Error(`Error fetching transition ID for input/output ${inputOrOutputID}: ${error}`);
1201
1355
  }
1356
+ finally {
1357
+ this.ctx = {};
1358
+ }
1202
1359
  }
1203
1360
  /**
1204
1361
  * Submit an execute or deployment transaction to the Aleo network.
@@ -1207,13 +1364,13 @@ class AleoNetworkClient {
1207
1364
  * @returns {Promise<string>} - The transaction id of the submitted transaction or the resulting error
1208
1365
  */
1209
1366
  async submitTransaction(transaction) {
1210
- const transaction_string = transaction instanceof Transaction
1367
+ const transactionString = transaction instanceof Transaction
1211
1368
  ? transaction.toString()
1212
1369
  : transaction;
1213
1370
  try {
1214
1371
  const response = await retryWithBackoff(() => this._sendPost(this.host + "/transaction/broadcast", {
1215
- body: transaction_string,
1216
- headers: Object.assign({}, this.headers, {
1372
+ body: transactionString,
1373
+ headers: Object.assign({}, { ...this.headers, "X-ALEO-METHOD": "submitTransaction" }, {
1217
1374
  "Content-Type": "application/json",
1218
1375
  }),
1219
1376
  }));
@@ -1239,7 +1396,7 @@ class AleoNetworkClient {
1239
1396
  try {
1240
1397
  const response = await retryWithBackoff(() => post(this.host + "/solution/broadcast", {
1241
1398
  body: solution,
1242
- headers: Object.assign({}, this.headers, {
1399
+ headers: Object.assign({}, { ...this.headers, "X-ALEO-METHOD": "submitSolution" }, {
1243
1400
  "Content-Type": "application/json",
1244
1401
  }),
1245
1402
  }));
@@ -1293,7 +1450,10 @@ class AleoNetworkClient {
1293
1450
  }
1294
1451
  try {
1295
1452
  const res = await fetch(`${this.host}/transaction/confirmed/${transactionId}`, {
1296
- headers: this.headers,
1453
+ headers: {
1454
+ ...this.headers,
1455
+ "X-ALEO-METHOD": "waitForTransactionConfirmation",
1456
+ },
1297
1457
  });
1298
1458
  if (!res.ok) {
1299
1459
  let text = "";
@@ -3295,4 +3455,4 @@ function validateTransferType(transferType) {
3295
3455
  }
3296
3456
 
3297
3457
  export { AleoKeyProvider as A, CREDITS_PROGRAM_KEYS as C, KEY_STORE as K, ProgramManager as P, VALID_TRANSFER_TYPES as V, AleoKeyProviderParams as a, AleoNetworkClient as b, PRIVATE_TRANSFER as c, PRIVATE_TO_PUBLIC_TRANSFER as d, PRIVATE_TRANSFER_TYPES as e, PUBLIC_TRANSFER as f, PUBLIC_TRANSFER_AS_SIGNER as g, PUBLIC_TO_PRIVATE_TRANSFER as h, logAndThrow as l };
3298
- //# sourceMappingURL=program-manager-C1m8QHkg.js.map
3458
+ //# sourceMappingURL=program-manager-DMDKstZ8.js.map