@hiero-ledger/sdk 2.80.0 → 2.81.0-beta.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.
Files changed (182) hide show
  1. package/README.md +34 -7
  2. package/dist/umd.js +2213 -318
  3. package/dist/umd.js.map +1 -0
  4. package/dist/umd.min.js +6 -5
  5. package/dist/umd.min.js.map +1 -0
  6. package/lib/Executable.cjs +7 -4
  7. package/lib/Executable.js +1 -1
  8. package/lib/Executable.js.map +1 -1
  9. package/lib/PublicKey.cjs +45 -26
  10. package/lib/PublicKey.d.ts +12 -0
  11. package/lib/PublicKey.js +1 -1
  12. package/lib/PublicKey.js.map +1 -1
  13. package/lib/RequestType.cjs +19 -1
  14. package/lib/RequestType.d.ts +2 -0
  15. package/lib/RequestType.js +1 -1
  16. package/lib/RequestType.js.map +1 -1
  17. package/lib/Status.cjs +203 -252
  18. package/lib/Status.d.ts +8 -6
  19. package/lib/Status.js +1 -1
  20. package/lib/Status.js.map +1 -1
  21. package/lib/Transfer.cjs +25 -2
  22. package/lib/Transfer.d.ts +4 -0
  23. package/lib/Transfer.js +1 -1
  24. package/lib/Transfer.js.map +1 -1
  25. package/lib/account/AccountCreateTransaction.cjs +38 -0
  26. package/lib/account/AccountCreateTransaction.d.ts +21 -0
  27. package/lib/account/AccountCreateTransaction.js +1 -1
  28. package/lib/account/AccountCreateTransaction.js.map +1 -1
  29. package/lib/account/AccountUpdateTransaction.cjs +74 -1
  30. package/lib/account/AccountUpdateTransaction.d.ts +43 -0
  31. package/lib/account/AccountUpdateTransaction.js +1 -1
  32. package/lib/account/AccountUpdateTransaction.js.map +1 -1
  33. package/lib/account/TransferTransaction.cjs +57 -9
  34. package/lib/account/TransferTransaction.d.ts +31 -1
  35. package/lib/account/TransferTransaction.js +1 -1
  36. package/lib/account/TransferTransaction.js.map +1 -1
  37. package/lib/browser.js +1 -1
  38. package/lib/client/Client.cjs +38 -0
  39. package/lib/client/Client.d.ts +30 -0
  40. package/lib/client/Client.js +1 -1
  41. package/lib/client/Client.js.map +1 -1
  42. package/lib/client/addressbooks/mainnet.cjs +1 -1
  43. package/lib/client/addressbooks/mainnet.d.ts +1 -1
  44. package/lib/client/addressbooks/mainnet.js +1 -1
  45. package/lib/client/addressbooks/mainnet.js.map +1 -1
  46. package/lib/client/addressbooks/previewnet.cjs +1 -1
  47. package/lib/client/addressbooks/previewnet.d.ts +1 -1
  48. package/lib/client/addressbooks/previewnet.js +1 -1
  49. package/lib/client/addressbooks/previewnet.js.map +1 -1
  50. package/lib/client/addressbooks/testnet.cjs +1 -1
  51. package/lib/client/addressbooks/testnet.d.ts +1 -1
  52. package/lib/client/addressbooks/testnet.js +1 -1
  53. package/lib/client/addressbooks/testnet.js.map +1 -1
  54. package/lib/contract/ContractCreateTransaction.cjs +37 -1
  55. package/lib/contract/ContractCreateTransaction.d.ts +21 -0
  56. package/lib/contract/ContractCreateTransaction.js +1 -1
  57. package/lib/contract/ContractCreateTransaction.js.map +1 -1
  58. package/lib/contract/ContractUpdateTransaction.cjs +74 -1
  59. package/lib/contract/ContractUpdateTransaction.d.ts +43 -0
  60. package/lib/contract/ContractUpdateTransaction.js +1 -1
  61. package/lib/contract/ContractUpdateTransaction.js.map +1 -1
  62. package/lib/exports.cjs +103 -0
  63. package/lib/exports.d.ts +13 -0
  64. package/lib/exports.js +1 -1
  65. package/lib/exports.js.map +1 -1
  66. package/lib/hooks/EvmHook.cjs +84 -0
  67. package/lib/hooks/EvmHook.d.ts +51 -0
  68. package/lib/hooks/EvmHook.js +2 -0
  69. package/lib/hooks/EvmHook.js.map +1 -0
  70. package/lib/hooks/EvmHookCall.cjs +103 -0
  71. package/lib/hooks/EvmHookCall.d.ts +69 -0
  72. package/lib/hooks/EvmHookCall.js +2 -0
  73. package/lib/hooks/EvmHookCall.js.map +1 -0
  74. package/lib/hooks/EvmHookMappingEntry.cjs +135 -0
  75. package/lib/hooks/EvmHookMappingEntry.d.ts +84 -0
  76. package/lib/hooks/EvmHookMappingEntry.js +2 -0
  77. package/lib/hooks/EvmHookMappingEntry.js.map +1 -0
  78. package/lib/hooks/EvmHookStorageUpdate.cjs +238 -0
  79. package/lib/hooks/EvmHookStorageUpdate.d.ts +144 -0
  80. package/lib/hooks/EvmHookStorageUpdate.js +2 -0
  81. package/lib/hooks/EvmHookStorageUpdate.js.map +1 -0
  82. package/lib/hooks/FungibleHookCall.cjs +67 -0
  83. package/lib/hooks/FungibleHookCall.d.ts +50 -0
  84. package/lib/hooks/FungibleHookCall.js +2 -0
  85. package/lib/hooks/FungibleHookCall.js.map +1 -0
  86. package/lib/hooks/FungibleHookType.cjs +11 -0
  87. package/lib/hooks/FungibleHookType.d.ts +5 -0
  88. package/lib/hooks/FungibleHookType.js +2 -0
  89. package/lib/hooks/FungibleHookType.js.map +1 -0
  90. package/lib/hooks/HookCall.cjs +99 -0
  91. package/lib/hooks/HookCall.d.ts +64 -0
  92. package/lib/hooks/HookCall.js +2 -0
  93. package/lib/hooks/HookCall.js.map +1 -0
  94. package/lib/hooks/HookCreationDetails.cjs +149 -0
  95. package/lib/hooks/HookCreationDetails.d.ts +91 -0
  96. package/lib/hooks/HookCreationDetails.js +2 -0
  97. package/lib/hooks/HookCreationDetails.js.map +1 -0
  98. package/lib/hooks/HookEntityId.cjs +67 -0
  99. package/lib/hooks/HookEntityId.d.ts +41 -0
  100. package/lib/hooks/HookEntityId.js +2 -0
  101. package/lib/hooks/HookEntityId.js.map +1 -0
  102. package/lib/hooks/HookExtensionPoint.cjs +31 -0
  103. package/lib/hooks/HookExtensionPoint.d.ts +16 -0
  104. package/lib/hooks/HookExtensionPoint.js +2 -0
  105. package/lib/hooks/HookExtensionPoint.js.map +1 -0
  106. package/lib/hooks/HookId.cjs +101 -0
  107. package/lib/hooks/HookId.d.ts +63 -0
  108. package/lib/hooks/HookId.js +2 -0
  109. package/lib/hooks/HookId.js.map +1 -0
  110. package/lib/hooks/HookStoreTransaction.cjs +157 -0
  111. package/lib/hooks/HookStoreTransaction.d.ts +77 -0
  112. package/lib/hooks/HookStoreTransaction.js +2 -0
  113. package/lib/hooks/HookStoreTransaction.js.map +1 -0
  114. package/lib/hooks/NftHookCall.cjs +67 -0
  115. package/lib/hooks/NftHookCall.d.ts +50 -0
  116. package/lib/hooks/NftHookCall.js +2 -0
  117. package/lib/hooks/NftHookCall.js.map +1 -0
  118. package/lib/hooks/NftHookType.cjs +13 -0
  119. package/lib/hooks/NftHookType.d.ts +7 -0
  120. package/lib/hooks/NftHookType.js +2 -0
  121. package/lib/hooks/NftHookType.js.map +1 -0
  122. package/lib/index.js +1 -1
  123. package/lib/native.js +1 -1
  124. package/lib/token/AbstractTokenTransferTransaction.cjs +17 -5
  125. package/lib/token/AbstractTokenTransferTransaction.d.ts +13 -2
  126. package/lib/token/AbstractTokenTransferTransaction.js +1 -1
  127. package/lib/token/AbstractTokenTransferTransaction.js.map +1 -1
  128. package/lib/token/TokenAirdropTransaction.cjs +1 -1
  129. package/lib/token/TokenAirdropTransaction.js +1 -1
  130. package/lib/token/TokenAirdropTransaction.js.map +1 -1
  131. package/lib/token/TokenNftTransfer.cjs +51 -2
  132. package/lib/token/TokenNftTransfer.d.ts +7 -0
  133. package/lib/token/TokenNftTransfer.js +1 -1
  134. package/lib/token/TokenNftTransfer.js.map +1 -1
  135. package/lib/token/TokenTransfer.cjs +26 -2
  136. package/lib/token/TokenTransfer.d.ts +4 -0
  137. package/lib/token/TokenTransfer.js +1 -1
  138. package/lib/token/TokenTransfer.js.map +1 -1
  139. package/lib/transaction/Transaction.cjs +2 -1
  140. package/lib/transaction/Transaction.js +1 -1
  141. package/lib/transaction/Transaction.js.map +1 -1
  142. package/lib/transaction/TransactionResponse.cjs +82 -9
  143. package/lib/transaction/TransactionResponse.d.ts +33 -2
  144. package/lib/transaction/TransactionResponse.js +1 -1
  145. package/lib/transaction/TransactionResponse.js.map +1 -1
  146. package/lib/version.js +1 -1
  147. package/package.json +15 -13
  148. package/src/Executable.js +10 -7
  149. package/src/PublicKey.js +53 -36
  150. package/src/RequestType.js +18 -0
  151. package/src/Status.js +201 -252
  152. package/src/Transfer.js +33 -1
  153. package/src/account/AccountCreateTransaction.js +39 -0
  154. package/src/account/AccountUpdateTransaction.js +78 -0
  155. package/src/account/TransferTransaction.js +84 -8
  156. package/src/client/Client.js +38 -0
  157. package/src/client/addressbooks/mainnet.js +1 -1
  158. package/src/client/addressbooks/previewnet.js +1 -1
  159. package/src/client/addressbooks/testnet.js +1 -1
  160. package/src/contract/ContractCreateTransaction.js +37 -0
  161. package/src/contract/ContractUpdateTransaction.js +80 -0
  162. package/src/exports.js +17 -0
  163. package/src/hooks/EvmHook.js +83 -0
  164. package/src/hooks/EvmHookCall.js +100 -0
  165. package/src/hooks/EvmHookMappingEntry.js +140 -0
  166. package/src/hooks/EvmHookStorageUpdate.js +257 -0
  167. package/src/hooks/FungibleHookCall.js +65 -0
  168. package/src/hooks/FungibleHookType.js +6 -0
  169. package/src/hooks/HookCall.js +97 -0
  170. package/src/hooks/HookCreationDetails.js +155 -0
  171. package/src/hooks/HookEntityId.js +67 -0
  172. package/src/hooks/HookExtensionPoint.js +25 -0
  173. package/src/hooks/HookId.js +102 -0
  174. package/src/hooks/HookStoreTransaction.js +185 -0
  175. package/src/hooks/NftHookCall.js +64 -0
  176. package/src/hooks/NftHookType.js +8 -0
  177. package/src/token/AbstractTokenTransferTransaction.js +16 -1
  178. package/src/token/TokenAirdropTransaction.js +1 -0
  179. package/src/token/TokenNftTransfer.js +68 -1
  180. package/src/token/TokenTransfer.js +34 -1
  181. package/src/transaction/Transaction.js +3 -0
  182. package/src/transaction/TransactionResponse.js +98 -13
@@ -605,10 +605,13 @@ class Executable {
605
605
  if (!node.isHealthy()) {
606
606
  const isLastNode = this._nodeAccountIds.index === this._nodeAccountIds.list.length - 1;
607
607
 
608
- // Check if the request is a transaction receipt or record
609
- // request to retry 10 times, because getReceiptQuery/getRecordQuery
610
- // are single node requests
611
- if (isTransactionReceiptOrRecordRequest(request) || isLocalNode) {
608
+ // Check if the request is a transaction receipt or record request
609
+ // with a single node (traditional behavior), or if it's a local node.
610
+ // For single-node receipt queries, we retry the same node with backoff.
611
+ // For multi-node receipt queries (when failover is enabled), we allow
612
+ // advancing to the next node like other queries.
613
+ const isSingleNodeReceiptOrRecordRequest = isTransactionReceiptOrRecordRequest(request) && this._nodeAccountIds.length <= 1;
614
+ if (isSingleNodeReceiptOrRecordRequest || isLocalNode) {
612
615
  await delayForAttempt(isLocalNode, attempt, this._minBackoff, this._maxBackoff);
613
616
  continue;
614
617
  }
package/lib/Executable.js CHANGED
@@ -1,2 +1,2 @@
1
- import t from"./grpc/GrpcServiceError.js";import e from"./grpc/GrpcStatus.js";import o from"./transaction/List.js";import{encode as n}from"./encoding/hex.js";import r from"./http/HttpError.js";import i from"./Status.js";import s from"./MaxAttemptsOrTimeoutError.js";const a={Finished:"Finished",Retry:"Retry",Error:"Error"},c=/\brst[^0-9a-zA-Z]stream\b/i,h=10;class d{constructor(){this._maxAttempts=10,this._nodeAccountIds=new o,this.transactionNodeIds=[],this._signOnDemand=!1,this._minBackoff=null,this._maxBackoff=8e3,this._operator=null,this._requestTimeout=null,this._grpcDeadline=null,this._logger=null}get nodeAccountIds(){return this._nodeAccountIds.isEmpty?null:(this._nodeAccountIds.setLocked(),this._nodeAccountIds.list)}setNodeAccountIds(t){return this._nodeAccountIds.setList(t).setLocked(),this}get maxRetries(){return console.warn("Deprecated: use maxAttempts instead"),this.maxAttempts}setMaxRetries(t){return console.warn("Deprecated: use setMaxAttempts() instead"),this.setMaxAttempts(t)}get maxAttempts(){return this._maxAttempts}setMaxAttempts(t){return this._maxAttempts=t,this}get grpcDeadline(){return this._grpcDeadline}setGrpcDeadline(t){return this._grpcDeadline=t,this}setMinBackoff(t){if(null==t)throw new Error("minBackoff cannot be null.");if(null!=this._maxBackoff&&t>this._maxBackoff)throw new Error("minBackoff cannot be larger than maxBackoff.");return this._minBackoff=t,this}get minBackoff(){return this._minBackoff}setMaxBackoff(t){if(null==t)throw new Error("maxBackoff cannot be null.");if(null!=this._minBackoff&&t<this._minBackoff)throw new Error("maxBackoff cannot be smaller than minBackoff.");return this._maxBackoff=t,this}get maxBackoff(){return this._maxBackoff}_beforeExecute(t){throw new Error("not implemented")}_makeRequestAsync(){throw new Error("not implemented")}_mapStatusError(t,e,o){throw new Error("not implemented")}_mapResponse(t,e,o){throw new Error("not implemented")}_execute(t,e){throw new Error("not implemented")}_getTransactionId(){throw new Error("not implemented")}_getLogId(){throw new Error("not implemented")}_requestToBytes(t){throw new Error("not implemented")}_responseToBytes(t){throw new Error("not implemented")}_shouldRetry(t,e){throw new Error("not implemented")}_shouldRetryExceptionally(o){return!(o instanceof t)||(o.status._code===e.Timeout._code||o.status._code===e.DeadlineExceeded._code||o.status._code===e.Unavailable._code||o.status._code===e.ResourceExhausted._code||o.status._code===e.GrpcWeb._code||o.status._code===e.Internal._code&&c.test(o.message))}_setOperatorWith(t,e,o){return this._operator={transactionSigner:o,accountId:t,publicKey:e},this}async executeWithSigner(t){return t.call(this)}isBatchedAndNotBatchTransaction(){return!1}async execute(o,c){const h=null!=o.network["127.0.0.1:50211"];if(this.isBatchedAndNotBatchTransaction())throw new Error("Cannot execute batchified transaction outside of BatchTransaction");this._logger=null==this._logger?null!=o._logger?o._logger:null:this._logger,null==this._requestTimeout&&(this._requestTimeout=null!=c?c:o.requestTimeout),null==this._grpcDeadline&&(this._grpcDeadline=o.grpcDeadline),await this._beforeExecute(o),null==this._maxBackoff&&(this._maxBackoff=o.maxBackoff),null==this._minBackoff&&(this._minBackoff=o.minBackoff);const d=Date.now();let g=null;const _=h?1e3:o._maxAttempts??this._maxAttempts;if(this.transactionNodeIds.length){const t=this._nodeAccountIds.list.map(t=>t.toString());if(!this.transactionNodeIds.some(e=>t.includes(e))){const e=t.length>2?`${t.slice(0,2).join(", ")} ...`:t.join(", "),o=1===t.length;throw new Error(`Attempting to execute a transaction against node${o?"":"s"} ${e}, which ${o?"is":"are"} not included in the Client's node list. Please review your Client configuration.`)}}for(let c=1;c<=_;c+=1){if(null!=this._requestTimeout&&d+this._requestTimeout<=Date.now())throw new s("timeout exceeded",this._nodeAccountIds.isEmpty?"No node account ID set":this._nodeAccountIds.current.toString());let m,f;if(this._nodeAccountIds.isEmpty?(f=o._network.getNode(),m=f.accountId,this._nodeAccountIds.setList([m])):(m=this._nodeAccountIds.current,f=o._network.getNode(m)),null==f)throw new Error(`NodeAccountId not recognized: ${m.toString()}`);if(this.transactionNodeIds.length){if(!this.transactionNodeIds.includes(m.toString())){console.error(`Attempting to execute a transaction against node ${m.toString()}, which is not included in the Client's node list. Please review your Client configuration.`),this._nodeAccountIds.advance();continue}}const p=this._getLogId();this._logger&&this._logger.debug(`[${p}] Node AccountID: ${f.accountId.toString()}, IP: ${f.address.toString()}`);const w=f.getChannel();null!=this._grpcDeadline&&w.setGrpcDeadline(this._grpcDeadline);const x=await this._makeRequestAsync();let k;if(!f.isHealthy()){const t=this._nodeAccountIds.index===this._nodeAccountIds.list.length-1;if(u(x)||h){await l(h,c,this._minBackoff,this._maxBackoff);continue}if(t||this._nodeAccountIds.length<=1)throw new Error(`Network connectivity issue: All nodes are unhealthy. Original node list: ${this._nodeAccountIds.list.join(", ")}`);this._logger&&this._logger.debug(`[${p}] Node is not healthy, trying the next node.`),this._nodeAccountIds.advance();continue}this._nodeAccountIds.advance();try{const o=[];null!=this._grpcDeadline&&o.push(new Promise((o,n)=>setTimeout(()=>n(new t(e.DeadlineExceeded)),this._grpcDeadline))),this._logger&&this._logger.trace(`[${this._getLogId()}] sending protobuf ${n(this._requestToBytes(x))}`),o.push(this._execute(w,x)),k=await Promise.race(o)}catch(e){const n=t._fromResponse(e);if(g=n,this._logger&&this._logger.debug(`[${p}] received error ${JSON.stringify(n)}`),(n instanceof t||n instanceof r)&&this._shouldRetryExceptionally(n)&&c<=_){this._logger&&this._logger.debug(`[${this._getLogId()}] node with accountId: ${f.accountId.toString()} and proxy IP: ${f.address.toString()} is unhealthy`),f.isHealthy()&&o._network.increaseBackoff(f);continue}throw e}this._logger&&this._logger.trace(`[${this._getLogId()}] sending protobuf ${n(this._responseToBytes(k))}`),o._network.decreaseBackoff(f);const[I,A]=this._shouldRetry(x,k);switch(I.toString()!==i.Ok.toString()&&I.toString()!==i.Success.toString()&&(g=I),A){case a.Retry:if(I===i.InvalidNodeAccount){this._logger&&this._logger.debug(`[${this._getLogId()}] node with accountId: ${f.accountId.toString()} and proxy IP: ${f.address.toString()} has invalid node account ID, marking as unhealthy and updating network`),o._network.increaseBackoff(f);try{o.mirrorNetwork.length>0?await o.updateNetwork():this._logger&&this._logger.warn("Cannot update address book: no mirror network configured. Retrying with existing network configuration.")}catch(t){if(this._logger){const e=t instanceof Error?t.message:String(t);this._logger.trace(`failed to update client address book after INVALID_NODE_ACCOUNT_ID: ${e}`)}}}await l(h,c,this._minBackoff,this._maxBackoff);continue;case a.Finished:return this._mapResponse(k,m,x);case a.Error:throw this._mapStatusError(x,k,m);default:throw new Error("(BUG) non-exhaustive switch statement for `ExecutionState`")}}throw new s(`max attempts of ${_.toString()} was reached for request with last error being: ${null!=g?g.toString():""}`,this._nodeAccountIds.current.toString())}toBytes(){throw new Error("not implemented")}setLogger(t){return this._logger=t,this}get logger(){return this._logger}}function u(t){return"object"==typeof t&&null!==t&&("transactionGetReceipt"in t||"transactionGetRecord"in t)}function l(t,e,o,n){if(t)return new Promise(t=>setTimeout(t,o));const r=Math.min(Math.floor(o*Math.pow(2,e)),n);return new Promise(t=>setTimeout(t,r))}export{h as DEFAULT_MAX_ATTEMPTS,a as ExecutionState,c as RST_STREAM,d as default};
1
+ import t from"./grpc/GrpcServiceError.js";import e from"./grpc/GrpcStatus.js";import n from"./transaction/List.js";import{encode as o}from"./encoding/hex.js";import r from"./http/HttpError.js";import s from"./Status.js";import i from"./MaxAttemptsOrTimeoutError.js";const a={Finished:"Finished",Retry:"Retry",Error:"Error"},c=/\brst[^0-9a-zA-Z]stream\b/i,h=10;class d{constructor(){this._maxAttempts=10,this._nodeAccountIds=new n,this.transactionNodeIds=[],this._signOnDemand=!1,this._minBackoff=null,this._maxBackoff=8e3,this._operator=null,this._requestTimeout=null,this._grpcDeadline=null,this._logger=null}get nodeAccountIds(){return this._nodeAccountIds.isEmpty?null:(this._nodeAccountIds.setLocked(),this._nodeAccountIds.list)}setNodeAccountIds(t){return this._nodeAccountIds.setList(t).setLocked(),this}get maxRetries(){return console.warn("Deprecated: use maxAttempts instead"),this.maxAttempts}setMaxRetries(t){return console.warn("Deprecated: use setMaxAttempts() instead"),this.setMaxAttempts(t)}get maxAttempts(){return this._maxAttempts}setMaxAttempts(t){return this._maxAttempts=t,this}get grpcDeadline(){return this._grpcDeadline}setGrpcDeadline(t){return this._grpcDeadline=t,this}setMinBackoff(t){if(null==t)throw new Error("minBackoff cannot be null.");if(null!=this._maxBackoff&&t>this._maxBackoff)throw new Error("minBackoff cannot be larger than maxBackoff.");return this._minBackoff=t,this}get minBackoff(){return this._minBackoff}setMaxBackoff(t){if(null==t)throw new Error("maxBackoff cannot be null.");if(null!=this._minBackoff&&t<this._minBackoff)throw new Error("maxBackoff cannot be smaller than minBackoff.");return this._maxBackoff=t,this}get maxBackoff(){return this._maxBackoff}_beforeExecute(t){throw new Error("not implemented")}_makeRequestAsync(){throw new Error("not implemented")}_mapStatusError(t,e,n){throw new Error("not implemented")}_mapResponse(t,e,n){throw new Error("not implemented")}_execute(t,e){throw new Error("not implemented")}_getTransactionId(){throw new Error("not implemented")}_getLogId(){throw new Error("not implemented")}_requestToBytes(t){throw new Error("not implemented")}_responseToBytes(t){throw new Error("not implemented")}_shouldRetry(t,e){throw new Error("not implemented")}_shouldRetryExceptionally(n){return!(n instanceof t)||(n.status._code===e.Timeout._code||n.status._code===e.DeadlineExceeded._code||n.status._code===e.Unavailable._code||n.status._code===e.ResourceExhausted._code||n.status._code===e.GrpcWeb._code||n.status._code===e.Internal._code&&c.test(n.message))}_setOperatorWith(t,e,n){return this._operator={transactionSigner:n,accountId:t,publicKey:e},this}async executeWithSigner(t){return t.call(this)}isBatchedAndNotBatchTransaction(){return!1}async execute(n,c){const h=null!=n.network["127.0.0.1:50211"];if(this.isBatchedAndNotBatchTransaction())throw new Error("Cannot execute batchified transaction outside of BatchTransaction");this._logger=null==this._logger?null!=n._logger?n._logger:null:this._logger,null==this._requestTimeout&&(this._requestTimeout=null!=c?c:n.requestTimeout),null==this._grpcDeadline&&(this._grpcDeadline=n.grpcDeadline),await this._beforeExecute(n),null==this._maxBackoff&&(this._maxBackoff=n.maxBackoff),null==this._minBackoff&&(this._minBackoff=n.minBackoff);const d=Date.now();let g=null;const _=h?1e3:n._maxAttempts??this._maxAttempts;if(this.transactionNodeIds.length){const t=this._nodeAccountIds.list.map(t=>t.toString());if(!this.transactionNodeIds.some(e=>t.includes(e))){const e=t.length>2?`${t.slice(0,2).join(", ")} ...`:t.join(", "),n=1===t.length;throw new Error(`Attempting to execute a transaction against node${n?"":"s"} ${e}, which ${n?"is":"are"} not included in the Client's node list. Please review your Client configuration.`)}}for(let c=1;c<=_;c+=1){if(null!=this._requestTimeout&&d+this._requestTimeout<=Date.now())throw new i("timeout exceeded",this._nodeAccountIds.isEmpty?"No node account ID set":this._nodeAccountIds.current.toString());let m,f;if(this._nodeAccountIds.isEmpty?(f=n._network.getNode(),m=f.accountId,this._nodeAccountIds.setList([m])):(m=this._nodeAccountIds.current,f=n._network.getNode(m)),null==f)throw new Error(`NodeAccountId not recognized: ${m.toString()}`);if(this.transactionNodeIds.length){if(!this.transactionNodeIds.includes(m.toString())){console.error(`Attempting to execute a transaction against node ${m.toString()}, which is not included in the Client's node list. Please review your Client configuration.`),this._nodeAccountIds.advance();continue}}const p=this._getLogId();this._logger&&this._logger.debug(`[${p}] Node AccountID: ${f.accountId.toString()}, IP: ${f.address.toString()}`);const w=f.getChannel();null!=this._grpcDeadline&&w.setGrpcDeadline(this._grpcDeadline);const x=await this._makeRequestAsync();let k;if(!f.isHealthy()){const t=this._nodeAccountIds.index===this._nodeAccountIds.list.length-1;if(u(x)&&this._nodeAccountIds.length<=1||h){await l(h,c,this._minBackoff,this._maxBackoff);continue}if(t||this._nodeAccountIds.length<=1)throw new Error(`Network connectivity issue: All nodes are unhealthy. Original node list: ${this._nodeAccountIds.list.join(", ")}`);this._logger&&this._logger.debug(`[${p}] Node is not healthy, trying the next node.`),this._nodeAccountIds.advance();continue}this._nodeAccountIds.advance();try{const n=[];null!=this._grpcDeadline&&n.push(new Promise((n,o)=>setTimeout(()=>o(new t(e.DeadlineExceeded)),this._grpcDeadline))),this._logger&&this._logger.trace(`[${this._getLogId()}] sending protobuf ${o(this._requestToBytes(x))}`),n.push(this._execute(w,x)),k=await Promise.race(n)}catch(e){const o=t._fromResponse(e);if(g=o,this._logger&&this._logger.debug(`[${p}] received error ${JSON.stringify(o)}`),(o instanceof t||o instanceof r)&&this._shouldRetryExceptionally(o)&&c<=_){this._logger&&this._logger.debug(`[${this._getLogId()}] node with accountId: ${f.accountId.toString()} and proxy IP: ${f.address.toString()} is unhealthy`),f.isHealthy()&&n._network.increaseBackoff(f);continue}throw e}this._logger&&this._logger.trace(`[${this._getLogId()}] sending protobuf ${o(this._responseToBytes(k))}`),n._network.decreaseBackoff(f);const[I,A]=this._shouldRetry(x,k);switch(I.toString()!==s.Ok.toString()&&I.toString()!==s.Success.toString()&&(g=I),A){case a.Retry:if(I===s.InvalidNodeAccount){this._logger&&this._logger.debug(`[${this._getLogId()}] node with accountId: ${f.accountId.toString()} and proxy IP: ${f.address.toString()} has invalid node account ID, marking as unhealthy and updating network`),n._network.increaseBackoff(f);try{n.mirrorNetwork.length>0?await n.updateNetwork():this._logger&&this._logger.warn("Cannot update address book: no mirror network configured. Retrying with existing network configuration.")}catch(t){if(this._logger){const e=t instanceof Error?t.message:String(t);this._logger.trace(`failed to update client address book after INVALID_NODE_ACCOUNT_ID: ${e}`)}}}await l(h,c,this._minBackoff,this._maxBackoff);continue;case a.Finished:return this._mapResponse(k,m,x);case a.Error:throw this._mapStatusError(x,k,m);default:throw new Error("(BUG) non-exhaustive switch statement for `ExecutionState`")}}throw new i(`max attempts of ${_.toString()} was reached for request with last error being: ${null!=g?g.toString():""}`,this._nodeAccountIds.current.toString())}toBytes(){throw new Error("not implemented")}setLogger(t){return this._logger=t,this}get logger(){return this._logger}}function u(t){return"object"==typeof t&&null!==t&&("transactionGetReceipt"in t||"transactionGetRecord"in t)}function l(t,e,n,o){if(t)return new Promise(t=>setTimeout(t,n));const r=Math.min(Math.floor(n*Math.pow(2,e)),o);return new Promise(t=>setTimeout(t,r))}export{h as DEFAULT_MAX_ATTEMPTS,a as ExecutionState,c as RST_STREAM,d as default};
2
2
  //# sourceMappingURL=Executable.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"Executable.js","sources":["../src/Executable.js"],"sourcesContent":["// SPDX-License-Identifier: Apache-2.0\n\nimport GrpcServiceError from \"./grpc/GrpcServiceError.js\";\nimport GrpcStatus from \"./grpc/GrpcStatus.js\";\nimport List from \"./transaction/List.js\";\nimport * as hex from \"./encoding/hex.js\";\nimport HttpError from \"./http/HttpError.js\";\nimport Status from \"./Status.js\";\nimport MaxAttemptsOrTimeoutError from \"./MaxAttemptsOrTimeoutError.js\";\n\n/**\n * @typedef {import(\"./account/AccountId.js\").default} AccountId\n * @typedef {import(\"./channel/Channel.js\").default} Channel\n * @typedef {import(\"./channel/MirrorChannel.js\").default} MirrorChannel\n * @typedef {import(\"./transaction/TransactionId.js\").default} TransactionId\n * @typedef {import(\"./client/Client.js\").ClientOperator} ClientOperator\n * @typedef {import(\"./Signer.js\").Signer} Signer\n * @typedef {import(\"./PublicKey.js\").default} PublicKey\n * @typedef {import(\"./logger/Logger.js\").default} Logger\n */\n\n/**\n * @enum {string}\n */\nexport const ExecutionState = {\n Finished: \"Finished\",\n Retry: \"Retry\",\n Error: \"Error\",\n};\n\nexport const RST_STREAM = /\\brst[^0-9a-zA-Z]stream\\b/i;\nexport const DEFAULT_MAX_ATTEMPTS = 10;\n\n/**\n * @abstract\n * @internal\n * @template RequestT\n * @template ResponseT\n * @template OutputT\n */\nexport default class Executable {\n constructor() {\n /**\n * The number of times we can retry the grpc call\n *\n * @internal\n * @type {number}\n */\n this._maxAttempts = DEFAULT_MAX_ATTEMPTS;\n\n /**\n * List of node account IDs for each transaction that has been\n * built.\n *\n * @internal\n * @type {List<AccountId>}\n */\n this._nodeAccountIds = new List();\n\n /**\n * List of the transaction node account IDs to check if\n * the node account ID of the request is in the list\n *\n * @protected\n * @type {Array<string>}\n */\n this.transactionNodeIds = [];\n\n /**\n * @internal\n */\n this._signOnDemand = false;\n\n /**\n * This is the request's min backoff\n *\n * @internal\n * @type {number | null}\n */\n this._minBackoff = null;\n\n /**\n * This is the request's max backoff\n *\n * @internal\n * @type {number}\n */\n this._maxBackoff = 8000;\n\n /**\n * The operator that was used to execute this request.\n * The reason we save the operator in the request is because of the signing on\n * demand feature. This feature requires us to sign new request on each attempt\n * meaning if a client with an operator was used we'd need to sign with the operator\n * on each attempt.\n *\n * @internal\n * @type {ClientOperator | null}\n */\n this._operator = null;\n\n /**\n * The complete timeout for running the `execute()` method\n *\n * @internal\n * @type {number | null}\n */\n this._requestTimeout = null;\n\n /**\n * The grpc request timeout aka deadline.\n *\n * The reason we have this is because there were times that consensus nodes held the grpc\n * connection, but didn't return anything; not error nor regular response. This resulted\n * in some weird behavior in the SDKs. To fix this we've added a grpc deadline to prevent\n * nodes from stalling the executing of a request.\n *\n * @internal\n * @type {number | null}\n */\n this._grpcDeadline = null;\n\n /**\n * Logger\n *\n * @protected\n * @type {Logger | null}\n */\n this._logger = null;\n }\n\n /**\n * Get the list of node account IDs on the request. If no nodes are set, then null is returned.\n * The reasoning for this is simply \"legacy behavior\".\n *\n * @returns {?AccountId[]}\n */\n get nodeAccountIds() {\n if (this._nodeAccountIds.isEmpty) {\n return null;\n } else {\n this._nodeAccountIds.setLocked();\n return this._nodeAccountIds.list;\n }\n }\n\n /**\n * Set the node account IDs on the request\n *\n * @param {AccountId[]} nodeIds\n * @returns {this}\n */\n setNodeAccountIds(nodeIds) {\n // Set the node account IDs, and lock the list. This will require `execute`\n // to use these nodes instead of random nodes from the network.\n this._nodeAccountIds.setList(nodeIds).setLocked();\n return this;\n }\n\n /**\n * @deprecated\n * @returns {number}\n */\n get maxRetries() {\n console.warn(\"Deprecated: use maxAttempts instead\");\n return this.maxAttempts;\n }\n\n /**\n * @param {number} maxRetries\n * @returns {this}\n */\n setMaxRetries(maxRetries) {\n console.warn(\"Deprecated: use setMaxAttempts() instead\");\n return this.setMaxAttempts(maxRetries);\n }\n\n /**\n * Get the max attempts on the request\n *\n * @returns {number}\n */\n get maxAttempts() {\n return this._maxAttempts;\n }\n\n /**\n * Set the max attempts on the request\n *\n * @param {number} maxAttempts\n * @returns {this}\n */\n setMaxAttempts(maxAttempts) {\n this._maxAttempts = maxAttempts;\n\n return this;\n }\n\n /**\n * Get the grpc deadline\n *\n * @returns {?number}\n */\n get grpcDeadline() {\n return this._grpcDeadline;\n }\n\n /**\n * Set the grpc deadline\n *\n * @param {number} grpcDeadline\n * @returns {this}\n */\n setGrpcDeadline(grpcDeadline) {\n this._grpcDeadline = grpcDeadline;\n\n return this;\n }\n\n /**\n * Set the min backoff for the request\n *\n * @param {number} minBackoff\n * @returns {this}\n */\n setMinBackoff(minBackoff) {\n // Honestly we shouldn't be checking for null since that should be TypeScript's job.\n // Also verify that min backoff is not greater than max backoff.\n if (minBackoff == null) {\n throw new Error(\"minBackoff cannot be null.\");\n } else if (this._maxBackoff != null && minBackoff > this._maxBackoff) {\n throw new Error(\"minBackoff cannot be larger than maxBackoff.\");\n }\n this._minBackoff = minBackoff;\n return this;\n }\n\n /**\n * Get the min backoff\n *\n * @returns {number | null}\n */\n get minBackoff() {\n return this._minBackoff;\n }\n\n /**\n * Set the max backoff for the request\n *\n * @param {?number} maxBackoff\n * @returns {this}\n */\n setMaxBackoff(maxBackoff) {\n // Honestly we shouldn't be checking for null since that should be TypeScript's job.\n // Also verify that max backoff is not less than min backoff.\n if (maxBackoff == null) {\n throw new Error(\"maxBackoff cannot be null.\");\n } else if (this._minBackoff != null && maxBackoff < this._minBackoff) {\n throw new Error(\"maxBackoff cannot be smaller than minBackoff.\");\n }\n this._maxBackoff = maxBackoff;\n return this;\n }\n\n /**\n * Get the max backoff\n *\n * @returns {number}\n */\n get maxBackoff() {\n return this._maxBackoff;\n }\n\n /**\n * This method is responsible for doing any work before the executing process begins.\n * For paid queries this will result in executing a cost query, for transactions this\n * will make sure we save the operator and sign any requests that need to be signed\n * in case signing on demand is disabled.\n *\n * @abstract\n * @protected\n * @param {import(\"./client/Client.js\").default<Channel, *>} client\n * @returns {Promise<void>}\n */\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n _beforeExecute(client) {\n throw new Error(\"not implemented\");\n }\n\n /**\n * Create a protobuf request which will be passed into the `_execute()` method\n *\n * @abstract\n * @protected\n * @returns {Promise<RequestT>}\n */\n _makeRequestAsync() {\n throw new Error(\"not implemented\");\n }\n\n /**\n * This name is a bit wrong now, but the purpose of this method is to map the\n * request and response into an error. This method will only be called when\n * `_shouldRetry` returned `ExecutionState.Error`\n *\n * @abstract\n * @internal\n * @param {RequestT} request\n * @param {ResponseT} response\n * @param {AccountId} nodeId\n * @returns {Error}\n */\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n _mapStatusError(request, response, nodeId) {\n throw new Error(\"not implemented\");\n }\n\n /**\n * Map the request, response, and the node account ID used for this attempt into a response.\n * This method will only be called when `_shouldRetry` returned `ExecutionState.Finished`\n *\n * @abstract\n * @protected\n * @param {ResponseT} response\n * @param {AccountId} nodeAccountId\n * @param {RequestT} request\n * @returns {Promise<OutputT>}\n */\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n _mapResponse(response, nodeAccountId, request) {\n throw new Error(\"not implemented\");\n }\n\n /**\n * Perform a single grpc call with the given request. Each request has it's own\n * required service so we just pass in channel, and it'$ the request's responsiblity\n * to use the right service and call the right grpc method.\n *\n * @abstract\n * @internal\n * @param {Channel} channel\n * @param {RequestT} request\n * @returns {Promise<ResponseT>}\n */\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n _execute(channel, request) {\n throw new Error(\"not implemented\");\n }\n\n /**\n * Return the current transaction ID for the request. All requests which are\n * use the same transaction ID for each node, but the catch is that `Transaction`\n * implicitly supports chunked transactions. Meaning there could be multiple\n * transaction IDs stored in the request, and a different transaction ID will be used\n * on subsequent calls to `execute()`\n *\n * FIXME: This method can most likely be removed, although some further inspection\n * is required.\n *\n * @abstract\n * @protected\n * @returns {TransactionId}\n */\n _getTransactionId() {\n throw new Error(\"not implemented\");\n }\n\n /**\n * Return the log ID for this particular request\n *\n * Log IDs are simply a string constructed to make it easy to track each request's\n * execution even when mulitple requests are executing in parallel. Typically, this\n * method returns the format of `[<request type>.<timestamp of the transaction ID>]`\n *\n * Maybe we should deduplicate this using ${this.consturtor.name}\n *\n * @abstract\n * @internal\n * @returns {string}\n */\n _getLogId() {\n throw new Error(\"not implemented\");\n }\n\n /**\n * Serialize the request into bytes\n *\n * @abstract\n * @param {RequestT} request\n * @returns {Uint8Array}\n */\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n _requestToBytes(request) {\n throw new Error(\"not implemented\");\n }\n\n /**\n * Serialize the response into bytes\n *\n * @abstract\n * @param {ResponseT} response\n * @returns {Uint8Array}\n */\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n _responseToBytes(response) {\n throw new Error(\"not implemented\");\n }\n\n /**\n * Determine if we should continue the execution process, error, or finish.\n *\n * FIXME: This method should really be called something else. Initially it returned\n * a boolean so `shouldRetry` made sense, but now it returns an enum, so the name\n * no longer makes sense.\n *\n * @abstract\n * @protected\n * @param {RequestT} request\n * @param {ResponseT} response\n * @returns {[Status, ExecutionState]}\n */\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n _shouldRetry(request, response) {\n throw new Error(\"not implemented\");\n }\n\n /**\n * Determine if we should error based on the gRPC status\n *\n * Unlike `shouldRetry` this method does in fact still return a boolean\n *\n * @protected\n * @param {Error} error\n * @returns {boolean}\n */\n _shouldRetryExceptionally(error) {\n if (error instanceof GrpcServiceError) {\n return (\n error.status._code === GrpcStatus.Timeout._code ||\n error.status._code === GrpcStatus.DeadlineExceeded._code ||\n error.status._code === GrpcStatus.Unavailable._code ||\n error.status._code === GrpcStatus.ResourceExhausted._code ||\n error.status._code === GrpcStatus.GrpcWeb._code ||\n (error.status._code === GrpcStatus.Internal._code &&\n RST_STREAM.test(error.message))\n );\n } else {\n // if we get to the 'else' statement, the 'error' is instanceof 'HttpError'\n // and in this case, we have to retry always\n return true;\n }\n }\n\n /**\n * A helper method for setting the operator on the request\n *\n * @internal\n * @param {AccountId} accountId\n * @param {PublicKey} publicKey\n * @param {(message: Uint8Array) => Promise<Uint8Array>} transactionSigner\n * @returns {this}\n */\n _setOperatorWith(accountId, publicKey, transactionSigner) {\n this._operator = {\n transactionSigner,\n accountId,\n publicKey,\n };\n return this;\n }\n\n /**\n * Execute this request using the signer\n *\n * This method is part of the signature providers feature\n * https://hips.hedera.com/hip/hip-338\n *\n * @param {Signer} signer\n * @returns {Promise<OutputT>}\n */\n async executeWithSigner(signer) {\n return signer.call(this);\n }\n\n /**\n * @returns {boolean}\n * @abstract\n * @protected\n */\n isBatchedAndNotBatchTransaction() {\n return false;\n }\n\n /**\n * Execute the request using a client and an optional request timeout\n *\n * @template {Channel} ChannelT\n * @template {MirrorChannel} MirrorChannelT\n * @param {import(\"./client/Client.js\").default<ChannelT, MirrorChannelT>} client\n * @param {number=} requestTimeout\n * @returns {Promise<OutputT>}\n */\n async execute(client, requestTimeout) {\n // we check if its local node then backoff mechanism should be disabled\n // and we increase the retry attempts\n const isLocalNode = client.network[\"127.0.0.1:50211\"] != null;\n\n if (this.isBatchedAndNotBatchTransaction()) {\n throw new Error(\n \"Cannot execute batchified transaction outside of BatchTransaction\",\n );\n }\n\n // If the logger on the request is not set, use the logger in client\n // (if set, otherwise do not use logger)\n this._logger =\n this._logger == null\n ? client._logger != null\n ? client._logger\n : null\n : this._logger;\n\n // If the request timeout is set on the request we'll prioritize that instead\n // of the parameter provided, and if the parameter isn't provided we'll\n // use the default request timeout on client\n if (this._requestTimeout == null) {\n this._requestTimeout =\n requestTimeout != null ? requestTimeout : client.requestTimeout;\n }\n\n // If the grpc deadline is not set on the request, use the default value from client\n if (this._grpcDeadline == null) {\n this._grpcDeadline = client.grpcDeadline;\n }\n\n // Some request need to perform additional requests before the executing\n // such as paid queries need to fetch the cost of the query before\n // finally executing the actual query.\n await this._beforeExecute(client);\n\n // If the max backoff on the request is not set, use the default value in client\n if (this._maxBackoff == null) {\n this._maxBackoff = client.maxBackoff;\n }\n\n // If the min backoff on the request is not set, use the default value in client\n if (this._minBackoff == null) {\n this._minBackoff = client.minBackoff;\n }\n\n // Save the start time to be used later with request timeout\n const startTime = Date.now();\n\n // Saves each error we get so when we err due to max attempts exceeded we'll have\n // the last error that was returned by the consensus node\n let persistentError = null;\n\n // If the max attempts on the request is not set, use the default value in client\n // If the default value in client is not set, use a default of 10.\n //\n // FIXME: current implementation is wrong, update to follow comment above.\n // ... existing code ...\n const LOCAL_NODE_ATTEMPTS = 1000;\n const maxAttempts = isLocalNode\n ? LOCAL_NODE_ATTEMPTS\n : client._maxAttempts ?? this._maxAttempts;\n\n // Checks if has a valid nodes to which the TX can be sent\n if (this.transactionNodeIds.length) {\n const nodeAccountIds = this._nodeAccountIds.list.map((nodeId) =>\n nodeId.toString(),\n );\n\n const hasValidNodes = this.transactionNodeIds.some((nodeId) =>\n nodeAccountIds.includes(nodeId),\n );\n\n if (!hasValidNodes) {\n const displayNodeAccountIds =\n nodeAccountIds.length > 2\n ? `${nodeAccountIds.slice(0, 2).join(\", \")} ...`\n : nodeAccountIds.join(\", \");\n const isSingleNode = nodeAccountIds.length === 1;\n\n throw new Error(\n `Attempting to execute a transaction against node${\n isSingleNode ? \"\" : \"s\"\n } ${displayNodeAccountIds}, ` +\n `which ${\n isSingleNode ? \"is\" : \"are\"\n } not included in the Client's node list. Please review your Client configuration.`,\n );\n }\n }\n\n // The retry loop\n for (let attempt = 1; attempt <= maxAttempts; attempt += 1) {\n // Determine if we've exceeded request timeout\n if (\n this._requestTimeout != null &&\n startTime + this._requestTimeout <= Date.now()\n ) {\n throw new MaxAttemptsOrTimeoutError(\n `timeout exceeded`,\n this._nodeAccountIds.isEmpty\n ? \"No node account ID set\"\n : this._nodeAccountIds.current.toString(),\n );\n }\n\n let nodeAccountId;\n let node;\n\n if (this._nodeAccountIds.isEmpty) {\n node = client._network.getNode();\n nodeAccountId = node.accountId;\n this._nodeAccountIds.setList([nodeAccountId]);\n } else {\n nodeAccountId = this._nodeAccountIds.current;\n node = client._network.getNode(nodeAccountId);\n }\n\n if (node == null) {\n throw new Error(\n `NodeAccountId not recognized: ${nodeAccountId.toString()}`,\n );\n }\n\n if (this.transactionNodeIds.length) {\n const isNodeAccountIdValid = this.transactionNodeIds.includes(\n nodeAccountId.toString(),\n );\n\n if (!isNodeAccountIdValid) {\n console.error(\n `Attempting to execute a transaction against node ${nodeAccountId.toString()}, which is not included in the Client's node list. Please review your Client configuration.`,\n );\n\n this._nodeAccountIds.advance();\n continue;\n }\n }\n\n // Get the log ID for the request.\n const logId = this._getLogId();\n if (this._logger) {\n this._logger.debug(\n `[${logId}] Node AccountID: ${node.accountId.toString()}, IP: ${node.address.toString()}`,\n );\n }\n\n const channel = node.getChannel();\n\n // Set the gRPC deadline on the channel if this query has a custom deadline\n if (this._grpcDeadline != null) {\n channel.setGrpcDeadline(this._grpcDeadline);\n }\n\n const request = await this._makeRequestAsync();\n\n let response;\n\n if (!node.isHealthy()) {\n const isLastNode =\n this._nodeAccountIds.index ===\n this._nodeAccountIds.list.length - 1;\n\n // Check if the request is a transaction receipt or record\n // request to retry 10 times, because getReceiptQuery/getRecordQuery\n // are single node requests\n if (\n isTransactionReceiptOrRecordRequest(request) ||\n isLocalNode\n ) {\n await delayForAttempt(\n isLocalNode,\n attempt,\n this._minBackoff,\n this._maxBackoff,\n );\n continue;\n }\n\n if (isLastNode || this._nodeAccountIds.length <= 1) {\n throw new Error(\n `Network connectivity issue: All nodes are unhealthy. Original node list: ${this._nodeAccountIds.list.join(\n \", \",\n )}`,\n );\n }\n\n if (this._logger) {\n this._logger.debug(\n `[${logId}] Node is not healthy, trying the next node.`,\n );\n }\n\n this._nodeAccountIds.advance();\n continue;\n }\n\n this._nodeAccountIds.advance();\n\n try {\n // Race the execution promise against the grpc timeout to prevent grpc connections\n // from blocking this request\n const promises = [];\n\n // If a grpc deadline is set, we should race it, otherwise the only thing in the\n // list of promises will be the execution promise.\n if (this._grpcDeadline != null) {\n promises.push(\n // eslint-disable-next-line ie11/no-loop-func\n new Promise((_, reject) =>\n setTimeout(\n // eslint-disable-next-line ie11/no-loop-func\n () =>\n reject(\n new GrpcServiceError(\n GrpcStatus.DeadlineExceeded,\n ),\n ),\n /** @type {number=} */ (this._grpcDeadline),\n ),\n ),\n );\n }\n if (this._logger) {\n this._logger.trace(\n `[${this._getLogId()}] sending protobuf ${hex.encode(\n this._requestToBytes(request),\n )}`,\n );\n }\n\n promises.push(this._execute(channel, request));\n // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment\n response = /** @type {ResponseT} */ (\n await Promise.race(promises)\n );\n } catch (err) {\n // If we received a grpc status error we need to determine if\n // we should retry on this error, or err from the request entirely.\n const error = GrpcServiceError._fromResponse(\n /** @type {Error} */ (err),\n );\n\n // Save the error in case we retry\n persistentError = error;\n if (this._logger) {\n this._logger.debug(\n `[${logId}] received error ${JSON.stringify(error)}`,\n );\n }\n\n if (\n (error instanceof GrpcServiceError ||\n error instanceof HttpError) &&\n this._shouldRetryExceptionally(error) &&\n attempt <= maxAttempts\n ) {\n // Increase the backoff for the particular node and remove it from\n // the healthy node list\n if (this._logger) {\n this._logger.debug(\n `[${this._getLogId()}] node with accountId: ${node.accountId.toString()} and proxy IP: ${node.address.toString()} is unhealthy`,\n );\n }\n\n if (node.isHealthy()) {\n client._network.increaseBackoff(node);\n }\n continue;\n }\n\n throw err;\n }\n if (this._logger) {\n this._logger.trace(\n `[${this._getLogId()}] sending protobuf ${hex.encode(\n this._responseToBytes(response),\n )}`,\n );\n }\n\n // If we didn't receive an error we should decrease the current nodes backoff\n // in case it is a recovering node\n client._network.decreaseBackoff(node);\n\n // Determine what execution state we're in by the response\n // For transactions this would be as simple as checking the response status is `OK`\n // while for _most_ queries it would check if the response status is `SUCCESS`\n // The only odd balls are `TransactionReceiptQuery` and `TransactionRecordQuery`\n const [status, shouldRetry] = this._shouldRetry(request, response);\n if (\n status.toString() !== Status.Ok.toString() &&\n status.toString() !== Status.Success.toString()\n ) {\n persistentError = status;\n }\n\n // Determine by the executing state what we should do\n switch (shouldRetry) {\n case ExecutionState.Retry:\n // Special handling for INVALID_NODE_ACCOUNT: mark node as unusable\n // and update network to get latest node account IDs\n if (status === Status.InvalidNodeAccount) {\n if (this._logger) {\n this._logger.debug(\n `[${this._getLogId()}] node with accountId: ${node.accountId.toString()} and proxy IP: ${node.address.toString()} has invalid node account ID, marking as unhealthy and updating network`,\n );\n }\n\n // Mark the node as unusable by increasing its backoff and removing it from the healthy nodes list\n client._network.increaseBackoff(node);\n\n // Initiate addressbook query and update the client's network\n // This will make the SDK client have the latest node account IDs for subsequent transactions\n try {\n if (client.mirrorNetwork.length > 0) {\n await client.updateNetwork();\n } else {\n if (this._logger) {\n this._logger.warn(\n \"Cannot update address book: no mirror network configured. Retrying with existing network configuration.\",\n );\n }\n }\n } catch (error) {\n if (this._logger) {\n const errorMessage =\n error instanceof Error\n ? error.message\n : String(error);\n this._logger.trace(\n `failed to update client address book after INVALID_NODE_ACCOUNT_ID: ${errorMessage}`,\n );\n }\n }\n }\n\n await delayForAttempt(\n isLocalNode,\n attempt,\n this._minBackoff,\n this._maxBackoff,\n );\n continue;\n case ExecutionState.Finished:\n return this._mapResponse(response, nodeAccountId, request);\n case ExecutionState.Error:\n throw this._mapStatusError(\n request,\n response,\n nodeAccountId,\n );\n default:\n throw new Error(\n \"(BUG) non-exhaustive switch statement for `ExecutionState`\",\n );\n }\n }\n\n // We'll only get here if we've run out of attempts, so we return an error wrapping the\n // persistent error we saved before.\n\n throw new MaxAttemptsOrTimeoutError(\n `max attempts of ${maxAttempts.toString()} was reached for request with last error being: ${\n persistentError != null ? persistentError.toString() : \"\"\n }`,\n this._nodeAccountIds.current.toString(),\n );\n }\n\n /**\n * The current purpose of this method is to easily support signature providers since\n * signature providers need to serialize _any_ request into bytes. `Query` and `Transaction`\n * already implement `toBytes()` so it only made sense to make it available here too.\n *\n * @abstract\n * @returns {Uint8Array}\n */\n toBytes() {\n throw new Error(\"not implemented\");\n }\n\n /**\n * Set logger\n *\n * @param {Logger} logger\n * @returns {this}\n */\n setLogger(logger) {\n this._logger = logger;\n return this;\n }\n\n /**\n * Get logger if set\n *\n * @returns {?Logger}\n */\n get logger() {\n return this._logger;\n }\n}\n\n/**\n * Checks if the request is a transaction receipt or record request\n *\n * @template T\n * @param {T} request - The request to check\n * @returns {boolean} - True if the request is a transaction receipt or record\n */\nfunction isTransactionReceiptOrRecordRequest(request) {\n if (typeof request !== \"object\" || request === null) {\n return false;\n }\n\n return (\n \"transactionGetReceipt\" in request || \"transactionGetRecord\" in request\n );\n}\n\n/**\n * A simple function that returns a promise timeout for a specific period of time\n *\n * @param {boolean} isLocalNode\n * @param {number} attempt\n * @param {number} minBackoff\n * @param {number} maxBackoff\n * @returns {Promise<void>}\n */\nfunction delayForAttempt(isLocalNode, attempt, minBackoff, maxBackoff) {\n if (isLocalNode) {\n return new Promise((resolve) => setTimeout(resolve, minBackoff));\n }\n\n // 0.1s, 0.2s, 0.4s, 0.8s, ...\n const ms = Math.min(\n Math.floor(minBackoff * Math.pow(2, attempt)),\n maxBackoff,\n );\n return new Promise((resolve) => setTimeout(resolve, ms));\n}\n"],"names":["ExecutionState","Finished","Retry","Error","RST_STREAM","DEFAULT_MAX_ATTEMPTS","Executable","constructor","this","_maxAttempts","_nodeAccountIds","List","transactionNodeIds","_signOnDemand","_minBackoff","_maxBackoff","_operator","_requestTimeout","_grpcDeadline","_logger","nodeAccountIds","isEmpty","setLocked","list","setNodeAccountIds","nodeIds","setList","maxRetries","console","warn","maxAttempts","setMaxRetries","setMaxAttempts","grpcDeadline","setGrpcDeadline","setMinBackoff","minBackoff","setMaxBackoff","maxBackoff","_beforeExecute","client","_makeRequestAsync","_mapStatusError","request","response","nodeId","_mapResponse","nodeAccountId","_execute","channel","_getTransactionId","_getLogId","_requestToBytes","_responseToBytes","_shouldRetry","_shouldRetryExceptionally","error","GrpcServiceError","status","_code","GrpcStatus","Timeout","DeadlineExceeded","Unavailable","ResourceExhausted","GrpcWeb","Internal","test","message","_setOperatorWith","accountId","publicKey","transactionSigner","executeWithSigner","signer","call","isBatchedAndNotBatchTransaction","execute","requestTimeout","isLocalNode","network","startTime","Date","now","persistentError","length","map","toString","some","includes","displayNodeAccountIds","slice","join","isSingleNode","attempt","MaxAttemptsOrTimeoutError","current","node","_network","getNode","advance","logId","debug","address","getChannel","isHealthy","isLastNode","index","isTransactionReceiptOrRecordRequest","delayForAttempt","promises","push","Promise","_","reject","setTimeout","trace","hex.encode","race","err","_fromResponse","JSON","stringify","HttpError","increaseBackoff","decreaseBackoff","shouldRetry","Status","Ok","Success","InvalidNodeAccount","mirrorNetwork","updateNetwork","errorMessage","String","toBytes","setLogger","logger","resolve","ms","Math","min","floor","pow"],"mappings":"0QAwBY,MAACA,EAAiB,CAC1BC,SAAU,WACVC,MAAO,QACPC,MAAO,SAGEC,EAAa,6BACbC,EAAuB,GASrB,MAAMC,EACjB,WAAAC,GAOIC,KAAKC,aAjBuB,GA0B5BD,KAAKE,gBAAkB,IAAIC,EAS3BH,KAAKI,mBAAqB,GAK1BJ,KAAKK,eAAgB,EAQrBL,KAAKM,YAAc,KAQnBN,KAAKO,YAAc,IAYnBP,KAAKQ,UAAY,KAQjBR,KAAKS,gBAAkB,KAavBT,KAAKU,cAAgB,KAQrBV,KAAKW,QAAU,IACvB,CAQI,kBAAIC,GACA,OAAIZ,KAAKE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KAAKkC,gBACPC,EACAC,EACAG,GAER,QACI,MAAM,IAAI5C,MACN,8DAGxB,CAKQ,MAAM,IAAI4F,EACN,mBAAmBjE,EAAYyD,6DACR,MAAnBH,EAA0BA,EAAgBG,WAAa,KAE3D/E,KAAKE,gBAAgBsF,QAAQT,WAEzC,CAUI,OAAAgD,GACI,MAAM,IAAIpI,MAAM,kBACxB,CAQI,SAAAqI,CAAUC,GAEN,OADAjI,KAAKW,QAAUsH,EACRjI,IACf,CAOI,UAAIiI,GACA,OAAOjI,KAAKW,OACpB,EAUA,SAASyF,EAAoCjE,GACzC,MAAuB,iBAAZA,GAAoC,OAAZA,IAK/B,0BAA2BA,GAAW,yBAA0BA,EAExE,CAWA,SAASkE,EAAgB9B,EAAae,EAAS1D,EAAYE,GACvD,GAAIyC,EACA,OAAO,IAAIiC,QAAS0B,GAAYvB,WAAWuB,EAAStG,IAIxD,MAAMuG,EAAKC,KAAKC,IACZD,KAAKE,MAAM1G,EAAawG,KAAKG,IAAI,EAAGjD,IACpCxD,GAEJ,OAAO,IAAI0E,QAAS0B,GAAYvB,WAAWuB,EAASC,GACxD"}
1
+ {"version":3,"file":"Executable.js","sources":["../src/Executable.js"],"sourcesContent":["// SPDX-License-Identifier: Apache-2.0\n\nimport GrpcServiceError from \"./grpc/GrpcServiceError.js\";\nimport GrpcStatus from \"./grpc/GrpcStatus.js\";\nimport List from \"./transaction/List.js\";\nimport * as hex from \"./encoding/hex.js\";\nimport HttpError from \"./http/HttpError.js\";\nimport Status from \"./Status.js\";\nimport MaxAttemptsOrTimeoutError from \"./MaxAttemptsOrTimeoutError.js\";\n\n/**\n * @typedef {import(\"./account/AccountId.js\").default} AccountId\n * @typedef {import(\"./channel/Channel.js\").default} Channel\n * @typedef {import(\"./channel/MirrorChannel.js\").default} MirrorChannel\n * @typedef {import(\"./transaction/TransactionId.js\").default} TransactionId\n * @typedef {import(\"./client/Client.js\").ClientOperator} ClientOperator\n * @typedef {import(\"./Signer.js\").Signer} Signer\n * @typedef {import(\"./PublicKey.js\").default} PublicKey\n * @typedef {import(\"./logger/Logger.js\").default} Logger\n */\n\n/**\n * @enum {string}\n */\nexport const ExecutionState = {\n Finished: \"Finished\",\n Retry: \"Retry\",\n Error: \"Error\",\n};\n\nexport const RST_STREAM = /\\brst[^0-9a-zA-Z]stream\\b/i;\nexport const DEFAULT_MAX_ATTEMPTS = 10;\n\n/**\n * @abstract\n * @internal\n * @template RequestT\n * @template ResponseT\n * @template OutputT\n */\nexport default class Executable {\n constructor() {\n /**\n * The number of times we can retry the grpc call\n *\n * @internal\n * @type {number}\n */\n this._maxAttempts = DEFAULT_MAX_ATTEMPTS;\n\n /**\n * List of node account IDs for each transaction that has been\n * built.\n *\n * @internal\n * @type {List<AccountId>}\n */\n this._nodeAccountIds = new List();\n\n /**\n * List of the transaction node account IDs to check if\n * the node account ID of the request is in the list\n *\n * @protected\n * @type {Array<string>}\n */\n this.transactionNodeIds = [];\n\n /**\n * @internal\n */\n this._signOnDemand = false;\n\n /**\n * This is the request's min backoff\n *\n * @internal\n * @type {number | null}\n */\n this._minBackoff = null;\n\n /**\n * This is the request's max backoff\n *\n * @internal\n * @type {number}\n */\n this._maxBackoff = 8000;\n\n /**\n * The operator that was used to execute this request.\n * The reason we save the operator in the request is because of the signing on\n * demand feature. This feature requires us to sign new request on each attempt\n * meaning if a client with an operator was used we'd need to sign with the operator\n * on each attempt.\n *\n * @internal\n * @type {ClientOperator | null}\n */\n this._operator = null;\n\n /**\n * The complete timeout for running the `execute()` method\n *\n * @internal\n * @type {number | null}\n */\n this._requestTimeout = null;\n\n /**\n * The grpc request timeout aka deadline.\n *\n * The reason we have this is because there were times that consensus nodes held the grpc\n * connection, but didn't return anything; not error nor regular response. This resulted\n * in some weird behavior in the SDKs. To fix this we've added a grpc deadline to prevent\n * nodes from stalling the executing of a request.\n *\n * @internal\n * @type {number | null}\n */\n this._grpcDeadline = null;\n\n /**\n * Logger\n *\n * @protected\n * @type {Logger | null}\n */\n this._logger = null;\n }\n\n /**\n * Get the list of node account IDs on the request. If no nodes are set, then null is returned.\n * The reasoning for this is simply \"legacy behavior\".\n *\n * @returns {?AccountId[]}\n */\n get nodeAccountIds() {\n if (this._nodeAccountIds.isEmpty) {\n return null;\n } else {\n this._nodeAccountIds.setLocked();\n return this._nodeAccountIds.list;\n }\n }\n\n /**\n * Set the node account IDs on the request\n *\n * @param {AccountId[]} nodeIds\n * @returns {this}\n */\n setNodeAccountIds(nodeIds) {\n // Set the node account IDs, and lock the list. This will require `execute`\n // to use these nodes instead of random nodes from the network.\n this._nodeAccountIds.setList(nodeIds).setLocked();\n return this;\n }\n\n /**\n * @deprecated\n * @returns {number}\n */\n get maxRetries() {\n console.warn(\"Deprecated: use maxAttempts instead\");\n return this.maxAttempts;\n }\n\n /**\n * @param {number} maxRetries\n * @returns {this}\n */\n setMaxRetries(maxRetries) {\n console.warn(\"Deprecated: use setMaxAttempts() instead\");\n return this.setMaxAttempts(maxRetries);\n }\n\n /**\n * Get the max attempts on the request\n *\n * @returns {number}\n */\n get maxAttempts() {\n return this._maxAttempts;\n }\n\n /**\n * Set the max attempts on the request\n *\n * @param {number} maxAttempts\n * @returns {this}\n */\n setMaxAttempts(maxAttempts) {\n this._maxAttempts = maxAttempts;\n\n return this;\n }\n\n /**\n * Get the grpc deadline\n *\n * @returns {?number}\n */\n get grpcDeadline() {\n return this._grpcDeadline;\n }\n\n /**\n * Set the grpc deadline\n *\n * @param {number} grpcDeadline\n * @returns {this}\n */\n setGrpcDeadline(grpcDeadline) {\n this._grpcDeadline = grpcDeadline;\n\n return this;\n }\n\n /**\n * Set the min backoff for the request\n *\n * @param {number} minBackoff\n * @returns {this}\n */\n setMinBackoff(minBackoff) {\n // Honestly we shouldn't be checking for null since that should be TypeScript's job.\n // Also verify that min backoff is not greater than max backoff.\n if (minBackoff == null) {\n throw new Error(\"minBackoff cannot be null.\");\n } else if (this._maxBackoff != null && minBackoff > this._maxBackoff) {\n throw new Error(\"minBackoff cannot be larger than maxBackoff.\");\n }\n this._minBackoff = minBackoff;\n return this;\n }\n\n /**\n * Get the min backoff\n *\n * @returns {number | null}\n */\n get minBackoff() {\n return this._minBackoff;\n }\n\n /**\n * Set the max backoff for the request\n *\n * @param {?number} maxBackoff\n * @returns {this}\n */\n setMaxBackoff(maxBackoff) {\n // Honestly we shouldn't be checking for null since that should be TypeScript's job.\n // Also verify that max backoff is not less than min backoff.\n if (maxBackoff == null) {\n throw new Error(\"maxBackoff cannot be null.\");\n } else if (this._minBackoff != null && maxBackoff < this._minBackoff) {\n throw new Error(\"maxBackoff cannot be smaller than minBackoff.\");\n }\n this._maxBackoff = maxBackoff;\n return this;\n }\n\n /**\n * Get the max backoff\n *\n * @returns {number}\n */\n get maxBackoff() {\n return this._maxBackoff;\n }\n\n /**\n * This method is responsible for doing any work before the executing process begins.\n * For paid queries this will result in executing a cost query, for transactions this\n * will make sure we save the operator and sign any requests that need to be signed\n * in case signing on demand is disabled.\n *\n * @abstract\n * @protected\n * @param {import(\"./client/Client.js\").default<Channel, *>} client\n * @returns {Promise<void>}\n */\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n _beforeExecute(client) {\n throw new Error(\"not implemented\");\n }\n\n /**\n * Create a protobuf request which will be passed into the `_execute()` method\n *\n * @abstract\n * @protected\n * @returns {Promise<RequestT>}\n */\n _makeRequestAsync() {\n throw new Error(\"not implemented\");\n }\n\n /**\n * This name is a bit wrong now, but the purpose of this method is to map the\n * request and response into an error. This method will only be called when\n * `_shouldRetry` returned `ExecutionState.Error`\n *\n * @abstract\n * @internal\n * @param {RequestT} request\n * @param {ResponseT} response\n * @param {AccountId} nodeId\n * @returns {Error}\n */\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n _mapStatusError(request, response, nodeId) {\n throw new Error(\"not implemented\");\n }\n\n /**\n * Map the request, response, and the node account ID used for this attempt into a response.\n * This method will only be called when `_shouldRetry` returned `ExecutionState.Finished`\n *\n * @abstract\n * @protected\n * @param {ResponseT} response\n * @param {AccountId} nodeAccountId\n * @param {RequestT} request\n * @returns {Promise<OutputT>}\n */\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n _mapResponse(response, nodeAccountId, request) {\n throw new Error(\"not implemented\");\n }\n\n /**\n * Perform a single grpc call with the given request. Each request has it's own\n * required service so we just pass in channel, and it'$ the request's responsiblity\n * to use the right service and call the right grpc method.\n *\n * @abstract\n * @internal\n * @param {Channel} channel\n * @param {RequestT} request\n * @returns {Promise<ResponseT>}\n */\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n _execute(channel, request) {\n throw new Error(\"not implemented\");\n }\n\n /**\n * Return the current transaction ID for the request. All requests which are\n * use the same transaction ID for each node, but the catch is that `Transaction`\n * implicitly supports chunked transactions. Meaning there could be multiple\n * transaction IDs stored in the request, and a different transaction ID will be used\n * on subsequent calls to `execute()`\n *\n * FIXME: This method can most likely be removed, although some further inspection\n * is required.\n *\n * @abstract\n * @protected\n * @returns {TransactionId}\n */\n _getTransactionId() {\n throw new Error(\"not implemented\");\n }\n\n /**\n * Return the log ID for this particular request\n *\n * Log IDs are simply a string constructed to make it easy to track each request's\n * execution even when mulitple requests are executing in parallel. Typically, this\n * method returns the format of `[<request type>.<timestamp of the transaction ID>]`\n *\n * Maybe we should deduplicate this using ${this.consturtor.name}\n *\n * @abstract\n * @internal\n * @returns {string}\n */\n _getLogId() {\n throw new Error(\"not implemented\");\n }\n\n /**\n * Serialize the request into bytes\n *\n * @abstract\n * @param {RequestT} request\n * @returns {Uint8Array}\n */\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n _requestToBytes(request) {\n throw new Error(\"not implemented\");\n }\n\n /**\n * Serialize the response into bytes\n *\n * @abstract\n * @param {ResponseT} response\n * @returns {Uint8Array}\n */\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n _responseToBytes(response) {\n throw new Error(\"not implemented\");\n }\n\n /**\n * Determine if we should continue the execution process, error, or finish.\n *\n * FIXME: This method should really be called something else. Initially it returned\n * a boolean so `shouldRetry` made sense, but now it returns an enum, so the name\n * no longer makes sense.\n *\n * @abstract\n * @protected\n * @param {RequestT} request\n * @param {ResponseT} response\n * @returns {[Status, ExecutionState]}\n */\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n _shouldRetry(request, response) {\n throw new Error(\"not implemented\");\n }\n\n /**\n * Determine if we should error based on the gRPC status\n *\n * Unlike `shouldRetry` this method does in fact still return a boolean\n *\n * @protected\n * @param {Error} error\n * @returns {boolean}\n */\n _shouldRetryExceptionally(error) {\n if (error instanceof GrpcServiceError) {\n return (\n error.status._code === GrpcStatus.Timeout._code ||\n error.status._code === GrpcStatus.DeadlineExceeded._code ||\n error.status._code === GrpcStatus.Unavailable._code ||\n error.status._code === GrpcStatus.ResourceExhausted._code ||\n error.status._code === GrpcStatus.GrpcWeb._code ||\n (error.status._code === GrpcStatus.Internal._code &&\n RST_STREAM.test(error.message))\n );\n } else {\n // if we get to the 'else' statement, the 'error' is instanceof 'HttpError'\n // and in this case, we have to retry always\n return true;\n }\n }\n\n /**\n * A helper method for setting the operator on the request\n *\n * @internal\n * @param {AccountId} accountId\n * @param {PublicKey} publicKey\n * @param {(message: Uint8Array) => Promise<Uint8Array>} transactionSigner\n * @returns {this}\n */\n _setOperatorWith(accountId, publicKey, transactionSigner) {\n this._operator = {\n transactionSigner,\n accountId,\n publicKey,\n };\n return this;\n }\n\n /**\n * Execute this request using the signer\n *\n * This method is part of the signature providers feature\n * https://hips.hedera.com/hip/hip-338\n *\n * @param {Signer} signer\n * @returns {Promise<OutputT>}\n */\n async executeWithSigner(signer) {\n return signer.call(this);\n }\n\n /**\n * @returns {boolean}\n * @abstract\n * @protected\n */\n isBatchedAndNotBatchTransaction() {\n return false;\n }\n\n /**\n * Execute the request using a client and an optional request timeout\n *\n * @template {Channel} ChannelT\n * @template {MirrorChannel} MirrorChannelT\n * @param {import(\"./client/Client.js\").default<ChannelT, MirrorChannelT>} client\n * @param {number=} requestTimeout\n * @returns {Promise<OutputT>}\n */\n async execute(client, requestTimeout) {\n // we check if its local node then backoff mechanism should be disabled\n // and we increase the retry attempts\n const isLocalNode = client.network[\"127.0.0.1:50211\"] != null;\n\n if (this.isBatchedAndNotBatchTransaction()) {\n throw new Error(\n \"Cannot execute batchified transaction outside of BatchTransaction\",\n );\n }\n\n // If the logger on the request is not set, use the logger in client\n // (if set, otherwise do not use logger)\n this._logger =\n this._logger == null\n ? client._logger != null\n ? client._logger\n : null\n : this._logger;\n\n // If the request timeout is set on the request we'll prioritize that instead\n // of the parameter provided, and if the parameter isn't provided we'll\n // use the default request timeout on client\n if (this._requestTimeout == null) {\n this._requestTimeout =\n requestTimeout != null ? requestTimeout : client.requestTimeout;\n }\n\n // If the grpc deadline is not set on the request, use the default value from client\n if (this._grpcDeadline == null) {\n this._grpcDeadline = client.grpcDeadline;\n }\n\n // Some request need to perform additional requests before the executing\n // such as paid queries need to fetch the cost of the query before\n // finally executing the actual query.\n await this._beforeExecute(client);\n\n // If the max backoff on the request is not set, use the default value in client\n if (this._maxBackoff == null) {\n this._maxBackoff = client.maxBackoff;\n }\n\n // If the min backoff on the request is not set, use the default value in client\n if (this._minBackoff == null) {\n this._minBackoff = client.minBackoff;\n }\n\n // Save the start time to be used later with request timeout\n const startTime = Date.now();\n\n // Saves each error we get so when we err due to max attempts exceeded we'll have\n // the last error that was returned by the consensus node\n let persistentError = null;\n\n // If the max attempts on the request is not set, use the default value in client\n // If the default value in client is not set, use a default of 10.\n //\n // FIXME: current implementation is wrong, update to follow comment above.\n // ... existing code ...\n const LOCAL_NODE_ATTEMPTS = 1000;\n const maxAttempts = isLocalNode\n ? LOCAL_NODE_ATTEMPTS\n : client._maxAttempts ?? this._maxAttempts;\n\n // Checks if has a valid nodes to which the TX can be sent\n if (this.transactionNodeIds.length) {\n const nodeAccountIds = this._nodeAccountIds.list.map((nodeId) =>\n nodeId.toString(),\n );\n\n const hasValidNodes = this.transactionNodeIds.some((nodeId) =>\n nodeAccountIds.includes(nodeId),\n );\n\n if (!hasValidNodes) {\n const displayNodeAccountIds =\n nodeAccountIds.length > 2\n ? `${nodeAccountIds.slice(0, 2).join(\", \")} ...`\n : nodeAccountIds.join(\", \");\n const isSingleNode = nodeAccountIds.length === 1;\n\n throw new Error(\n `Attempting to execute a transaction against node${\n isSingleNode ? \"\" : \"s\"\n } ${displayNodeAccountIds}, ` +\n `which ${\n isSingleNode ? \"is\" : \"are\"\n } not included in the Client's node list. Please review your Client configuration.`,\n );\n }\n }\n\n // The retry loop\n for (let attempt = 1; attempt <= maxAttempts; attempt += 1) {\n // Determine if we've exceeded request timeout\n if (\n this._requestTimeout != null &&\n startTime + this._requestTimeout <= Date.now()\n ) {\n throw new MaxAttemptsOrTimeoutError(\n `timeout exceeded`,\n this._nodeAccountIds.isEmpty\n ? \"No node account ID set\"\n : this._nodeAccountIds.current.toString(),\n );\n }\n\n let nodeAccountId;\n let node;\n\n if (this._nodeAccountIds.isEmpty) {\n node = client._network.getNode();\n nodeAccountId = node.accountId;\n this._nodeAccountIds.setList([nodeAccountId]);\n } else {\n nodeAccountId = this._nodeAccountIds.current;\n node = client._network.getNode(nodeAccountId);\n }\n\n if (node == null) {\n throw new Error(\n `NodeAccountId not recognized: ${nodeAccountId.toString()}`,\n );\n }\n\n if (this.transactionNodeIds.length) {\n const isNodeAccountIdValid = this.transactionNodeIds.includes(\n nodeAccountId.toString(),\n );\n\n if (!isNodeAccountIdValid) {\n console.error(\n `Attempting to execute a transaction against node ${nodeAccountId.toString()}, which is not included in the Client's node list. Please review your Client configuration.`,\n );\n\n this._nodeAccountIds.advance();\n continue;\n }\n }\n\n // Get the log ID for the request.\n const logId = this._getLogId();\n if (this._logger) {\n this._logger.debug(\n `[${logId}] Node AccountID: ${node.accountId.toString()}, IP: ${node.address.toString()}`,\n );\n }\n\n const channel = node.getChannel();\n\n // Set the gRPC deadline on the channel if this query has a custom deadline\n if (this._grpcDeadline != null) {\n channel.setGrpcDeadline(this._grpcDeadline);\n }\n\n const request = await this._makeRequestAsync();\n\n let response;\n\n if (!node.isHealthy()) {\n const isLastNode =\n this._nodeAccountIds.index ===\n this._nodeAccountIds.list.length - 1;\n\n // Check if the request is a transaction receipt or record request\n // with a single node (traditional behavior), or if it's a local node.\n // For single-node receipt queries, we retry the same node with backoff.\n // For multi-node receipt queries (when failover is enabled), we allow\n // advancing to the next node like other queries.\n const isSingleNodeReceiptOrRecordRequest =\n isTransactionReceiptOrRecordRequest(request) &&\n this._nodeAccountIds.length <= 1;\n\n if (isSingleNodeReceiptOrRecordRequest || isLocalNode) {\n await delayForAttempt(\n isLocalNode,\n attempt,\n this._minBackoff,\n this._maxBackoff,\n );\n continue;\n }\n\n if (isLastNode || this._nodeAccountIds.length <= 1) {\n throw new Error(\n `Network connectivity issue: All nodes are unhealthy. Original node list: ${this._nodeAccountIds.list.join(\n \", \",\n )}`,\n );\n }\n\n if (this._logger) {\n this._logger.debug(\n `[${logId}] Node is not healthy, trying the next node.`,\n );\n }\n\n this._nodeAccountIds.advance();\n continue;\n }\n\n this._nodeAccountIds.advance();\n\n try {\n // Race the execution promise against the grpc timeout to prevent grpc connections\n // from blocking this request\n const promises = [];\n\n // If a grpc deadline is set, we should race it, otherwise the only thing in the\n // list of promises will be the execution promise.\n if (this._grpcDeadline != null) {\n promises.push(\n // eslint-disable-next-line ie11/no-loop-func\n new Promise((_, reject) =>\n setTimeout(\n // eslint-disable-next-line ie11/no-loop-func\n () =>\n reject(\n new GrpcServiceError(\n GrpcStatus.DeadlineExceeded,\n ),\n ),\n /** @type {number=} */ (this._grpcDeadline),\n ),\n ),\n );\n }\n if (this._logger) {\n this._logger.trace(\n `[${this._getLogId()}] sending protobuf ${hex.encode(\n this._requestToBytes(request),\n )}`,\n );\n }\n\n promises.push(this._execute(channel, request));\n // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment\n response = /** @type {ResponseT} */ (\n await Promise.race(promises)\n );\n } catch (err) {\n // If we received a grpc status error we need to determine if\n // we should retry on this error, or err from the request entirely.\n const error = GrpcServiceError._fromResponse(\n /** @type {Error} */ (err),\n );\n\n // Save the error in case we retry\n persistentError = error;\n if (this._logger) {\n this._logger.debug(\n `[${logId}] received error ${JSON.stringify(error)}`,\n );\n }\n\n if (\n (error instanceof GrpcServiceError ||\n error instanceof HttpError) &&\n this._shouldRetryExceptionally(error) &&\n attempt <= maxAttempts\n ) {\n // Increase the backoff for the particular node and remove it from\n // the healthy node list\n if (this._logger) {\n this._logger.debug(\n `[${this._getLogId()}] node with accountId: ${node.accountId.toString()} and proxy IP: ${node.address.toString()} is unhealthy`,\n );\n }\n\n if (node.isHealthy()) {\n client._network.increaseBackoff(node);\n }\n continue;\n }\n\n throw err;\n }\n if (this._logger) {\n this._logger.trace(\n `[${this._getLogId()}] sending protobuf ${hex.encode(\n this._responseToBytes(response),\n )}`,\n );\n }\n\n // If we didn't receive an error we should decrease the current nodes backoff\n // in case it is a recovering node\n client._network.decreaseBackoff(node);\n\n // Determine what execution state we're in by the response\n // For transactions this would be as simple as checking the response status is `OK`\n // while for _most_ queries it would check if the response status is `SUCCESS`\n // The only odd balls are `TransactionReceiptQuery` and `TransactionRecordQuery`\n const [status, shouldRetry] = this._shouldRetry(request, response);\n if (\n status.toString() !== Status.Ok.toString() &&\n status.toString() !== Status.Success.toString()\n ) {\n persistentError = status;\n }\n\n // Determine by the executing state what we should do\n switch (shouldRetry) {\n case ExecutionState.Retry:\n // Special handling for INVALID_NODE_ACCOUNT: mark node as unusable\n // and update network to get latest node account IDs\n if (status === Status.InvalidNodeAccount) {\n if (this._logger) {\n this._logger.debug(\n `[${this._getLogId()}] node with accountId: ${node.accountId.toString()} and proxy IP: ${node.address.toString()} has invalid node account ID, marking as unhealthy and updating network`,\n );\n }\n\n // Mark the node as unusable by increasing its backoff and removing it from the healthy nodes list\n client._network.increaseBackoff(node);\n\n // Initiate addressbook query and update the client's network\n // This will make the SDK client have the latest node account IDs for subsequent transactions\n try {\n if (client.mirrorNetwork.length > 0) {\n await client.updateNetwork();\n } else {\n if (this._logger) {\n this._logger.warn(\n \"Cannot update address book: no mirror network configured. Retrying with existing network configuration.\",\n );\n }\n }\n } catch (error) {\n if (this._logger) {\n const errorMessage =\n error instanceof Error\n ? error.message\n : String(error);\n this._logger.trace(\n `failed to update client address book after INVALID_NODE_ACCOUNT_ID: ${errorMessage}`,\n );\n }\n }\n }\n\n await delayForAttempt(\n isLocalNode,\n attempt,\n this._minBackoff,\n this._maxBackoff,\n );\n continue;\n case ExecutionState.Finished:\n return this._mapResponse(response, nodeAccountId, request);\n case ExecutionState.Error:\n throw this._mapStatusError(\n request,\n response,\n nodeAccountId,\n );\n default:\n throw new Error(\n \"(BUG) non-exhaustive switch statement for `ExecutionState`\",\n );\n }\n }\n\n // We'll only get here if we've run out of attempts, so we return an error wrapping the\n // persistent error we saved before.\n\n throw new MaxAttemptsOrTimeoutError(\n `max attempts of ${maxAttempts.toString()} was reached for request with last error being: ${\n persistentError != null ? persistentError.toString() : \"\"\n }`,\n this._nodeAccountIds.current.toString(),\n );\n }\n\n /**\n * The current purpose of this method is to easily support signature providers since\n * signature providers need to serialize _any_ request into bytes. `Query` and `Transaction`\n * already implement `toBytes()` so it only made sense to make it available here too.\n *\n * @abstract\n * @returns {Uint8Array}\n */\n toBytes() {\n throw new Error(\"not implemented\");\n }\n\n /**\n * Set logger\n *\n * @param {Logger} logger\n * @returns {this}\n */\n setLogger(logger) {\n this._logger = logger;\n return this;\n }\n\n /**\n * Get logger if set\n *\n * @returns {?Logger}\n */\n get logger() {\n return this._logger;\n }\n}\n\n/**\n * Checks if the request is a transaction receipt or record request\n *\n * @template T\n * @param {T} request - The request to check\n * @returns {boolean} - True if the request is a transaction receipt or record\n */\nfunction isTransactionReceiptOrRecordRequest(request) {\n if (typeof request !== \"object\" || request === null) {\n return false;\n }\n\n return (\n \"transactionGetReceipt\" in request || \"transactionGetRecord\" in request\n );\n}\n\n/**\n * A simple function that returns a promise timeout for a specific period of time\n *\n * @param {boolean} isLocalNode\n * @param {number} attempt\n * @param {number} minBackoff\n * @param {number} maxBackoff\n * @returns {Promise<void>}\n */\nfunction delayForAttempt(isLocalNode, attempt, minBackoff, maxBackoff) {\n if (isLocalNode) {\n return new Promise((resolve) => setTimeout(resolve, minBackoff));\n }\n\n // 0.1s, 0.2s, 0.4s, 0.8s, ...\n const ms = Math.min(\n Math.floor(minBackoff * Math.pow(2, attempt)),\n maxBackoff,\n );\n return new Promise((resolve) => setTimeout(resolve, ms));\n}\n"],"names":["ExecutionState","Finished","Retry","Error","RST_STREAM","DEFAULT_MAX_ATTEMPTS","Executable","constructor","this","_maxAttempts","_nodeAccountIds","List","transactionNodeIds","_signOnDemand","_minBackoff","_maxBackoff","_operator","_requestTimeout","_grpcDeadline","_logger","nodeAccountIds","isEmpty","setLocked","list","setNodeAccountIds","nodeIds","setList","maxRetries","console","warn","maxAttempts","setMaxRetries","setMaxAttempts","grpcDeadline","setGrpcDeadline","setMinBackoff","minBackoff","setMaxBackoff","maxBackoff","_beforeExecute","client","_makeRequestAsync","_mapStatusError","request","response","nodeId","_mapResponse","nodeAccountId","_execute","channel","_getTransactionId","_getLogId","_requestToBytes","_responseToBytes","_shouldRetry","_shouldRetryExceptionally","error","GrpcServiceError","status","_code","GrpcStatus","Timeout","DeadlineExceeded","Unavailable","ResourceExhausted","GrpcWeb","Internal","test","message","_setOperatorWith","accountId","publicKey","transactionSigner","executeWithSigner","signer","call","isBatchedAndNotBatchTransaction","execute","requestTimeout","isLocalNode","network","startTime","Date","now","persistentError","length","map","toString","some","includes","displayNodeAccountIds","slice","join","isSingleNode","attempt","MaxAttemptsOrTimeoutError","current","node","_network","getNode","advance","logId","debug","address","getChannel","isHealthy","isLastNode","index","isTransactionReceiptOrRecordRequest","delayForAttempt","promises","push","Promise","_","reject","setTimeout","trace","hex.encode","race","err","_fromResponse","JSON","stringify","HttpError","increaseBackoff","decreaseBackoff","shouldRetry","Status","Ok","Success","InvalidNodeAccount","mirrorNetwork","updateNetwork","errorMessage","String","toBytes","setLogger","logger","resolve","ms","Math","min","floor","pow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SAAS0B,gBAAgB3B,GAIhC,IACQzD,EAAO2F,cAAc9C,OAAS,QACxB7C,EAAO4F,gBAET5H,KAAKW,SACLX,KAAKW,QAAQU,KACT,0GAIf,CAAC,MAAO2B,GACL,GAAIhD,KAAKW,QAAS,CACd,MAAMkH,EACF7E,aAAiBrD,MACXqD,EAAMY,QACNkE,OAAO9E,GACjBhD,KAAKW,QAAQiG,MACT,uEAAuEiB,IAE3G,CACA,CACA,OAE0BxB,EACF9B,EACAe,EACAtF,KAAKM,YACLN,KAAKO,aAET,SACJ,KAAKf,EAAeC,SAChB,OAAOO,KAAKsC,aAAaF,EAAUG,EAAeJ,GACtD,KAAK3C,EAAeG,MAChB,MAAMK,KAAKkC,gBACPC,EACAC,EACAG,GAER,QACI,MAAM,IAAI5C,MACN,8DAGxB,CAKQ,MAAM,IAAI4F,EACN,mBAAmBjE,EAAYyD,6DACR,MAAnBH,EAA0BA,EAAgBG,WAAa,KAE3D/E,KAAKE,gBAAgBsF,QAAQT,WAEzC,CAUI,OAAAgD,GACI,MAAM,IAAIpI,MAAM,kBACxB,CAQI,SAAAqI,CAAUC,GAEN,OADAjI,KAAKW,QAAUsH,EACRjI,IACf,CAOI,UAAIiI,GACA,OAAOjI,KAAKW,OACpB,EAUA,SAASyF,EAAoCjE,GACzC,MAAuB,iBAAZA,GAAoC,OAAZA,IAK/B,0BAA2BA,GAAW,yBAA0BA,EAExE,CAWA,SAASkE,EAAgB9B,EAAae,EAAS1D,EAAYE,GACvD,GAAIyC,EACA,OAAO,IAAIiC,QAAS0B,GAAYvB,WAAWuB,EAAStG,IAIxD,MAAMuG,EAAKC,KAAKC,IACZD,KAAKE,MAAM1G,EAAawG,KAAKG,IAAI,EAAGjD,IACpCxD,GAEJ,OAAO,IAAI0E,QAAS0B,GAAYvB,WAAWuB,EAASC,GACxD"}
package/lib/PublicKey.cjs CHANGED
@@ -118,37 +118,56 @@ class PublicKey extends _Key.default {
118
118
  // before we execute the transaction (execute -> makeRequest -> buildTransaction -> signTransaction).
119
119
  // However, in JavaScript, we build the `_signedTransactions` list while signing the transaction.
120
120
  for (const signedTransaction of transaction._signedTransactions.list) {
121
- if (signedTransaction.sigMap != null && signedTransaction.sigMap.sigPair != null) {
122
- let found = false;
123
- for (const sigPair of signedTransaction.sigMap.sigPair) {
124
- const pubKeyPrefix = /** @type {Uint8Array} */
125
- sigPair.pubKeyPrefix;
126
- if ((0, _array.arrayEqual)(pubKeyPrefix, this.toBytesRaw())) {
127
- found = true;
128
- const bodyBytes = /** @type {Uint8Array} */
129
- signedTransaction.bodyBytes;
130
- let signature = null;
131
- if (sigPair.ed25519 != null) {
132
- signature = sigPair.ed25519;
133
- } else if (sigPair.ECDSASecp256k1 != null) {
134
- signature = sigPair.ECDSASecp256k1;
135
- }
136
- if (signature == null) {
137
- continue;
138
- }
139
- if (!this.verify(bodyBytes, signature)) {
140
- return false;
141
- }
142
- }
143
- }
144
- if (!found) {
145
- return false;
146
- }
121
+ if (!this._verifySignedTransaction(signedTransaction)) {
122
+ return false;
147
123
  }
148
124
  }
149
125
  return true;
150
126
  }
151
127
 
128
+ /**
129
+ * @private
130
+ * @param {HieroProto.proto.ISignedTransaction} signedTransaction
131
+ * @returns {boolean}
132
+ */
133
+ _verifySignedTransaction(signedTransaction) {
134
+ const sigMap = signedTransaction.sigMap;
135
+ if (sigMap == null || sigMap.sigPair == null) {
136
+ return false;
137
+ }
138
+ const bodyBytes = /** @type {Uint8Array} */
139
+ signedTransaction.bodyBytes;
140
+ const publicKeyBytes = this.toBytesRaw();
141
+ for (const sigPair of sigMap.sigPair) {
142
+ const pubKeyPrefix = /** @type {Uint8Array} */
143
+ sigPair.pubKeyPrefix;
144
+ if (!(0, _array.arrayEqual)(pubKeyPrefix, publicKeyBytes)) {
145
+ continue;
146
+ }
147
+ const signature = this._extractSignature(sigPair);
148
+ if (signature == null) {
149
+ return false;
150
+ }
151
+ return this.verify(bodyBytes, signature);
152
+ }
153
+ return false;
154
+ }
155
+
156
+ /**
157
+ * @private
158
+ * @param {HieroProto.proto.ISignaturePair} sigPair
159
+ * @returns {Uint8Array | null}
160
+ */
161
+ _extractSignature(sigPair) {
162
+ if (sigPair.ed25519 != null) {
163
+ return sigPair.ed25519;
164
+ }
165
+ if (sigPair.ECDSASecp256k1 != null) {
166
+ return sigPair.ECDSASecp256k1;
167
+ }
168
+ return null;
169
+ }
170
+
152
171
  /**
153
172
  * @returns {Uint8Array}
154
173
  */
@@ -78,6 +78,18 @@ export default class PublicKey extends Key {
78
78
  * @returns {boolean}
79
79
  */
80
80
  verifyTransaction(transaction: Transaction): boolean;
81
+ /**
82
+ * @private
83
+ * @param {HieroProto.proto.ISignedTransaction} signedTransaction
84
+ * @returns {boolean}
85
+ */
86
+ private _verifySignedTransaction;
87
+ /**
88
+ * @private
89
+ * @param {HieroProto.proto.ISignaturePair} sigPair
90
+ * @returns {Uint8Array | null}
91
+ */
92
+ private _extractSignature;
81
93
  /**
82
94
  * @returns {Uint8Array}
83
95
  */
package/lib/PublicKey.js CHANGED
@@ -1,2 +1,2 @@
1
- import{PublicKey as t}from"@hiero-ledger/cryptography";import{arrayEqual as e}from"./array.js";import r from"./Key.js";import s from"./Cache.js";class i extends r{constructor(t){super(),this._key=t}static fromBytes(e){return new i(t.fromBytes(e))}static fromBytesED25519(e){return new i(t.fromBytesED25519(e))}static fromBytesECDSA(e){return new i(t.fromBytesECDSA(e))}static fromString(e){return new i(t.fromString(e))}static fromStringECDSA(e){return new i(t.fromStringECDSA(e))}static fromStringED25519(e){return new i(t.fromStringED25519(e))}verify(t,e){return this._key.verify(t,e)}verifyTransaction(t){t._requireFrozen(),t.isFrozen()||t.freeze();for(const r of t._signedTransactions.list)if(null!=r.sigMap&&null!=r.sigMap.sigPair){let t=!1;for(const s of r.sigMap.sigPair){const i=s.pubKeyPrefix;if(e(i,this.toBytesRaw())){t=!0;const e=r.bodyBytes;let i=null;if(null!=s.ed25519?i=s.ed25519:null!=s.ECDSASecp256k1&&(i=s.ECDSASecp256k1),null==i)continue;if(!this.verify(e,i))return!1}}if(!t)return!1}return!0}toBytes(){return this._key.toBytes()}toBytesDer(){return this._key.toBytesDer()}toBytesRaw(){return this._key.toBytesRaw()}toEthereumAddress(){return this._key.toEthereumAddress()}toEvmAddress(){return this._key.toEthereumAddress()}toString(){return this._key.toString()}toStringDer(){return this._key.toStringDer()}toStringRaw(){return this._key.toStringRaw()}equals(t){return this._key.equals(t._key)}_toProtobufKey(){switch(this._key._type){case"ED25519":return{ed25519:this._key.toBytesRaw()};case"secp256k1":return{ECDSASecp256k1:this._key.toBytesRaw()};default:throw new Error(`unrecognized key type ${this._key._type}`)}}_toProtobufSignature(t){switch(this._key._type){case"ED25519":return{pubKeyPrefix:this._key.toBytesRaw(),ed25519:t};case"secp256k1":return{pubKeyPrefix:this._key.toBytesRaw(),ECDSASecp256k1:t};default:throw new Error(`unrecognized key type ${this._key._type}`)}}get type(){return this._key._type}toAccountId(t,e){return s.accountIdConstructor(t,e,this)}static unusableKey(){return i.fromStringED25519("0000000000000000000000000000000000000000000000000000000000000000")}}s.setPublicKeyED25519(t=>i.fromBytesED25519(t)),s.setPublicKeyECDSA(t=>i.fromBytesECDSA(t));export{i as default};
1
+ import{PublicKey as t}from"@hiero-ledger/cryptography";import{arrayEqual as e}from"./array.js";import r from"./Key.js";import s from"./Cache.js";class n extends r{constructor(t){super(),this._key=t}static fromBytes(e){return new n(t.fromBytes(e))}static fromBytesED25519(e){return new n(t.fromBytesED25519(e))}static fromBytesECDSA(e){return new n(t.fromBytesECDSA(e))}static fromString(e){return new n(t.fromString(e))}static fromStringECDSA(e){return new n(t.fromStringECDSA(e))}static fromStringED25519(e){return new n(t.fromStringED25519(e))}verify(t,e){return this._key.verify(t,e)}verifyTransaction(t){t._requireFrozen(),t.isFrozen()||t.freeze();for(const e of t._signedTransactions.list)if(!this._verifySignedTransaction(e))return!1;return!0}_verifySignedTransaction(t){const r=t.sigMap;if(null==r||null==r.sigPair)return!1;const s=t.bodyBytes,n=this.toBytesRaw();for(const t of r.sigPair){const r=t.pubKeyPrefix;if(!e(r,n))continue;const i=this._extractSignature(t);return null!=i&&this.verify(s,i)}return!1}_extractSignature(t){return null!=t.ed25519?t.ed25519:null!=t.ECDSASecp256k1?t.ECDSASecp256k1:null}toBytes(){return this._key.toBytes()}toBytesDer(){return this._key.toBytesDer()}toBytesRaw(){return this._key.toBytesRaw()}toEthereumAddress(){return this._key.toEthereumAddress()}toEvmAddress(){return this._key.toEthereumAddress()}toString(){return this._key.toString()}toStringDer(){return this._key.toStringDer()}toStringRaw(){return this._key.toStringRaw()}equals(t){return this._key.equals(t._key)}_toProtobufKey(){switch(this._key._type){case"ED25519":return{ed25519:this._key.toBytesRaw()};case"secp256k1":return{ECDSASecp256k1:this._key.toBytesRaw()};default:throw new Error(`unrecognized key type ${this._key._type}`)}}_toProtobufSignature(t){switch(this._key._type){case"ED25519":return{pubKeyPrefix:this._key.toBytesRaw(),ed25519:t};case"secp256k1":return{pubKeyPrefix:this._key.toBytesRaw(),ECDSASecp256k1:t};default:throw new Error(`unrecognized key type ${this._key._type}`)}}get type(){return this._key._type}toAccountId(t,e){return s.accountIdConstructor(t,e,this)}static unusableKey(){return n.fromStringED25519("0000000000000000000000000000000000000000000000000000000000000000")}}s.setPublicKeyED25519(t=>n.fromBytesED25519(t)),s.setPublicKeyECDSA(t=>n.fromBytesECDSA(t));export{n as default};
2
2
  //# sourceMappingURL=PublicKey.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"PublicKey.js","sources":["../src/PublicKey.js"],"sourcesContent":["// SPDX-License-Identifier: Apache-2.0\n\nimport { PublicKey as PublicKeyCrypto } from \"@hiero-ledger/cryptography\";\nimport { arrayEqual } from \"./array.js\";\nimport Key from \"./Key.js\";\nimport CACHE from \"./Cache.js\";\n\n/**\n * @typedef {import(\"./transaction/Transaction.js\").default} Transaction\n * @typedef {import(\"./account/AccountId.js\").default} AccountId\n */\n\n/**\n * @namespace proto\n * @typedef {import(\"@hiero-ledger/proto\").proto.IKey} HieroProto.proto.IKey\n * @typedef {import(\"@hiero-ledger/proto\").proto.ITransaction} HieroProto.proto.ITransaction\n * @typedef {import(\"@hiero-ledger/proto\").proto.ISignaturePair} HieroProto.proto.ISignaturePair\n * @typedef {import(\"@hiero-ledger/proto\").proto.ISignedTransaction} HieroProto.proto.ISignedTransaction\n */\n\nexport default class PublicKey extends Key {\n /**\n * @internal\n * @hideconstructor\n * @param {PublicKeyCrypto} key\n */\n constructor(key) {\n super();\n\n this._key = key;\n }\n\n /**\n * @param {Uint8Array} data\n * @returns {PublicKey}\n */\n static fromBytes(data) {\n return new PublicKey(PublicKeyCrypto.fromBytes(data));\n }\n\n /**\n * @param {Uint8Array} data\n * @returns {PublicKey}\n */\n static fromBytesED25519(data) {\n return new PublicKey(PublicKeyCrypto.fromBytesED25519(data));\n }\n\n /**\n * @param {Uint8Array} data\n * @returns {PublicKey}\n */\n static fromBytesECDSA(data) {\n return new PublicKey(PublicKeyCrypto.fromBytesECDSA(data));\n }\n\n /**\n * Parse a public key from a string of hexadecimal digits.\n *\n * The public key may optionally be prefixed with\n * the DER header.\n *\n * @param {string} text\n * @returns {PublicKey}\n */\n static fromString(text) {\n return new PublicKey(PublicKeyCrypto.fromString(text));\n }\n\n /**\n * Parse an ECDSA public key from a string of hexadecimal digits.\n *\n * @param {string} text\n * @returns {PublicKey}\n */\n static fromStringECDSA(text) {\n return new PublicKey(PublicKeyCrypto.fromStringECDSA(text));\n }\n\n /**\n * Parse an ED25519 public key from a string of hexadecimal digits.\n *\n * @param {string} text\n * @returns {PublicKey}\n */\n static fromStringED25519(text) {\n return new PublicKey(PublicKeyCrypto.fromStringED25519(text));\n }\n\n /**\n * Verify a signature on a message with this public key.\n *\n * @param {Uint8Array} message\n * @param {Uint8Array} signature\n * @returns {boolean}\n */\n verify(message, signature) {\n return this._key.verify(message, signature);\n }\n\n /**\n * Reports whether this key signed the given transaction.\n * @param {Transaction} transaction\n * @returns {boolean}\n */\n verifyTransaction(transaction) {\n transaction._requireFrozen();\n\n if (!transaction.isFrozen()) {\n transaction.freeze();\n }\n\n // Note: in other SDKs, we need to check the transaction's `_signerPublicKeys` since we don't build the `_signedTransactions` list\n // before we execute the transaction (execute -> makeRequest -> buildTransaction -> signTransaction).\n // However, in JavaScript, we build the `_signedTransactions` list while signing the transaction.\n for (const signedTransaction of transaction._signedTransactions.list) {\n if (\n signedTransaction.sigMap != null &&\n signedTransaction.sigMap.sigPair != null\n ) {\n let found = false;\n for (const sigPair of signedTransaction.sigMap.sigPair) {\n const pubKeyPrefix = /** @type {Uint8Array} */ (\n sigPair.pubKeyPrefix\n );\n if (arrayEqual(pubKeyPrefix, this.toBytesRaw())) {\n found = true;\n\n const bodyBytes = /** @type {Uint8Array} */ (\n signedTransaction.bodyBytes\n );\n\n let signature = null;\n if (sigPair.ed25519 != null) {\n signature = sigPair.ed25519;\n } else if (sigPair.ECDSASecp256k1 != null) {\n signature = sigPair.ECDSASecp256k1;\n }\n\n if (signature == null) {\n continue;\n }\n\n if (!this.verify(bodyBytes, signature)) {\n return false;\n }\n }\n }\n\n if (!found) {\n return false;\n }\n }\n }\n\n return true;\n }\n\n /**\n * @returns {Uint8Array}\n */\n toBytes() {\n return this._key.toBytes();\n }\n\n /**\n * @returns {Uint8Array}\n */\n toBytesDer() {\n return this._key.toBytesDer();\n }\n\n /**\n * @returns {Uint8Array}\n */\n toBytesRaw() {\n return this._key.toBytesRaw();\n }\n\n /**\n * @deprecated Use `toEvmAddress()` instead.\n * @returns {string}\n */\n toEthereumAddress() {\n return this._key.toEthereumAddress();\n }\n\n /**\n * @returns {string}\n */\n toEvmAddress() {\n return this._key.toEthereumAddress();\n }\n\n /**\n * @returns {string}\n */\n toString() {\n return this._key.toString();\n }\n\n /**\n * @returns {string}\n */\n toStringDer() {\n return this._key.toStringDer();\n }\n\n /**\n * @returns {string}\n */\n toStringRaw() {\n return this._key.toStringRaw();\n }\n\n /**\n * @param {PublicKey} other\n * @returns {boolean}\n */\n equals(other) {\n return this._key.equals(other._key);\n }\n\n /**\n * @returns {HieroProto.proto.IKey}\n */\n _toProtobufKey() {\n switch (this._key._type) {\n case \"ED25519\":\n return {\n ed25519: this._key.toBytesRaw(),\n };\n case \"secp256k1\":\n return {\n ECDSASecp256k1: this._key.toBytesRaw(),\n };\n default:\n throw new Error(`unrecognized key type ${this._key._type}`);\n }\n }\n\n /**\n * @param {Uint8Array} signature\n * @returns {HieroProto.proto.ISignaturePair}\n */\n _toProtobufSignature(signature) {\n switch (this._key._type) {\n case \"ED25519\":\n return {\n pubKeyPrefix: this._key.toBytesRaw(),\n ed25519: signature,\n };\n case \"secp256k1\":\n return {\n pubKeyPrefix: this._key.toBytesRaw(),\n ECDSASecp256k1: signature,\n };\n default:\n throw new Error(`unrecognized key type ${this._key._type}`);\n }\n }\n\n /**\n * @returns {string}\n */\n get type() {\n return this._key._type;\n }\n\n /**\n * @param {Long | number} shard\n * @param {Long | number} realm\n * @returns {AccountId}\n */\n toAccountId(shard, realm) {\n return CACHE.accountIdConstructor(shard, realm, this);\n }\n\n /**\n * Returns an \"unusable\" public key.\n * “Unusable” refers to a key such as an Ed25519 0x00000... public key,\n * since it is (presumably) impossible to find the 32-byte string whose SHA-512 hash begins with 32 bytes of zeros.\n *\n * @returns {PublicKey}\n */\n static unusableKey() {\n return PublicKey.fromStringED25519(\n \"0000000000000000000000000000000000000000000000000000000000000000\",\n );\n }\n}\n\nCACHE.setPublicKeyED25519((key) => PublicKey.fromBytesED25519(key));\nCACHE.setPublicKeyECDSA((key) => PublicKey.fromBytesECDSA(key));\n"],"names":["PublicKey","Key","constructor","key","super","this","_key","fromBytes","data","PublicKeyCrypto","fromBytesED25519","fromBytesECDSA","fromString","text","fromStringECDSA","fromStringED25519","verify","message","signature","verifyTransaction","transaction","_requireFrozen","isFrozen","freeze","signedTransaction","_signedTransactions","list","sigMap","sigPair","found","pubKeyPrefix","arrayEqual","toBytesRaw","bodyBytes","ed25519","ECDSASecp256k1","toBytes","toBytesDer","toEthereumAddress","toEvmAddress","toString","toStringDer","toStringRaw","equals","other","_toProtobufKey","_type","Error","_toProtobufSignature","type","toAccountId","shard","realm","CACHE","accountIdConstructor","unusableKey","setPublicKeyED25519","setPublicKeyECDSA"],"mappings":"iJAoBe,MAAMA,UAAkBC,EAMnC,WAAAC,CAAYC,GACRC,QAEAC,KAAKC,KAAOH,CACpB,CAMI,gBAAOI,CAAUC,GACb,OAAO,IAAIR,EAAUS,EAAgBF,UAAUC,GACvD,CAMI,uBAAOE,CAAiBF,GACpB,OAAO,IAAIR,EAAUS,EAAgBC,iBAAiBF,GAC9D,CAMI,qBAAOG,CAAeH,GAClB,OAAO,IAAIR,EAAUS,EAAgBE,eAAeH,GAC5D,CAWI,iBAAOI,CAAWC,GACd,OAAO,IAAIb,EAAUS,EAAgBG,WAAWC,GACxD,CAQI,sBAAOC,CAAgBD,GACnB,OAAO,IAAIb,EAAUS,EAAgBK,gBAAgBD,GAC7D,CAQI,wBAAOE,CAAkBF,GACrB,OAAO,IAAIb,EAAUS,EAAgBM,kBAAkBF,GAC/D,CASI,MAAAG,CAAOC,EAASC,GACZ,OAAOb,KAAKC,KAAKU,OAAOC,EAASC,EACzC,CAOI,iBAAAC,CAAkBC,GACdA,EAAYC,iBAEPD,EAAYE,YACbF,EAAYG,SAMhB,IAAK,MAAMC,KAAqBJ,EAAYK,oBAAoBC,KAC5D,GACgC,MAA5BF,EAAkBG,QACkB,MAApCH,EAAkBG,OAAOC,QAC3B,CACE,IAAIC,GAAQ,EACZ,IAAK,MAAMD,KAAWJ,EAAkBG,OAAOC,QAAS,CACpD,MAAME,EACFF,EACH,aACD,GAAIG,EAAWD,EAAczB,KAAK2B,cAAe,CAC7CH,GAAQ,EAER,MAAMI,EACFT,EACH,UAED,IAAIN,EAAY,KAOhB,GANuB,MAAnBU,EAAQM,QACRhB,EAAYU,EAAQM,QACa,MAA1BN,EAAQO,iBACfjB,EAAYU,EAAQO,gBAGP,MAAbjB,EACA,SAGJ,IAAKb,KAAKW,O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U,iBAAiBP,IAC9DkD,EAAMI,kBAAmBtD,GAAQH,EAAUW,eAAeR"}
1
+ {"version":3,"file":"PublicKey.js","sources":["../src/PublicKey.js"],"sourcesContent":["// SPDX-License-Identifier: Apache-2.0\n\nimport { PublicKey as PublicKeyCrypto } from \"@hiero-ledger/cryptography\";\nimport { arrayEqual } from \"./array.js\";\nimport Key from \"./Key.js\";\nimport CACHE from \"./Cache.js\";\n\n/**\n * @typedef {import(\"./transaction/Transaction.js\").default} Transaction\n * @typedef {import(\"./account/AccountId.js\").default} AccountId\n */\n\n/**\n * @namespace proto\n * @typedef {import(\"@hiero-ledger/proto\").proto.IKey} HieroProto.proto.IKey\n * @typedef {import(\"@hiero-ledger/proto\").proto.ITransaction} HieroProto.proto.ITransaction\n * @typedef {import(\"@hiero-ledger/proto\").proto.ISignaturePair} HieroProto.proto.ISignaturePair\n * @typedef {import(\"@hiero-ledger/proto\").proto.ISignedTransaction} HieroProto.proto.ISignedTransaction\n */\n\nexport default class PublicKey extends Key {\n /**\n * @internal\n * @hideconstructor\n * @param {PublicKeyCrypto} key\n */\n constructor(key) {\n super();\n\n this._key = key;\n }\n\n /**\n * @param {Uint8Array} data\n * @returns {PublicKey}\n */\n static fromBytes(data) {\n return new PublicKey(PublicKeyCrypto.fromBytes(data));\n }\n\n /**\n * @param {Uint8Array} data\n * @returns {PublicKey}\n */\n static fromBytesED25519(data) {\n return new PublicKey(PublicKeyCrypto.fromBytesED25519(data));\n }\n\n /**\n * @param {Uint8Array} data\n * @returns {PublicKey}\n */\n static fromBytesECDSA(data) {\n return new PublicKey(PublicKeyCrypto.fromBytesECDSA(data));\n }\n\n /**\n * Parse a public key from a string of hexadecimal digits.\n *\n * The public key may optionally be prefixed with\n * the DER header.\n *\n * @param {string} text\n * @returns {PublicKey}\n */\n static fromString(text) {\n return new PublicKey(PublicKeyCrypto.fromString(text));\n }\n\n /**\n * Parse an ECDSA public key from a string of hexadecimal digits.\n *\n * @param {string} text\n * @returns {PublicKey}\n */\n static fromStringECDSA(text) {\n return new PublicKey(PublicKeyCrypto.fromStringECDSA(text));\n }\n\n /**\n * Parse an ED25519 public key from a string of hexadecimal digits.\n *\n * @param {string} text\n * @returns {PublicKey}\n */\n static fromStringED25519(text) {\n return new PublicKey(PublicKeyCrypto.fromStringED25519(text));\n }\n\n /**\n * Verify a signature on a message with this public key.\n *\n * @param {Uint8Array} message\n * @param {Uint8Array} signature\n * @returns {boolean}\n */\n verify(message, signature) {\n return this._key.verify(message, signature);\n }\n\n /**\n * Reports whether this key signed the given transaction.\n * @param {Transaction} transaction\n * @returns {boolean}\n */\n verifyTransaction(transaction) {\n transaction._requireFrozen();\n\n if (!transaction.isFrozen()) {\n transaction.freeze();\n }\n\n // Note: in other SDKs, we need to check the transaction's `_signerPublicKeys` since we don't build the `_signedTransactions` list\n // before we execute the transaction (execute -> makeRequest -> buildTransaction -> signTransaction).\n // However, in JavaScript, we build the `_signedTransactions` list while signing the transaction.\n for (const signedTransaction of transaction._signedTransactions.list) {\n if (!this._verifySignedTransaction(signedTransaction)) {\n return false;\n }\n }\n\n return true;\n }\n\n /**\n * @private\n * @param {HieroProto.proto.ISignedTransaction} signedTransaction\n * @returns {boolean}\n */\n _verifySignedTransaction(signedTransaction) {\n const sigMap = signedTransaction.sigMap;\n if (sigMap == null || sigMap.sigPair == null) {\n return false;\n }\n\n const bodyBytes = /** @type {Uint8Array} */ (\n signedTransaction.bodyBytes\n );\n const publicKeyBytes = this.toBytesRaw();\n\n for (const sigPair of sigMap.sigPair) {\n const pubKeyPrefix = /** @type {Uint8Array} */ (\n sigPair.pubKeyPrefix\n );\n\n if (!arrayEqual(pubKeyPrefix, publicKeyBytes)) {\n continue;\n }\n\n const signature = this._extractSignature(sigPair);\n if (signature == null) {\n return false;\n }\n\n return this.verify(bodyBytes, signature);\n }\n\n return false;\n }\n\n /**\n * @private\n * @param {HieroProto.proto.ISignaturePair} sigPair\n * @returns {Uint8Array | null}\n */\n _extractSignature(sigPair) {\n if (sigPair.ed25519 != null) {\n return sigPair.ed25519;\n }\n if (sigPair.ECDSASecp256k1 != null) {\n return sigPair.ECDSASecp256k1;\n }\n return null;\n }\n\n /**\n * @returns {Uint8Array}\n */\n toBytes() {\n return this._key.toBytes();\n }\n\n /**\n * @returns {Uint8Array}\n */\n toBytesDer() {\n return this._key.toBytesDer();\n }\n\n /**\n * @returns {Uint8Array}\n */\n toBytesRaw() {\n return this._key.toBytesRaw();\n }\n\n /**\n * @deprecated Use `toEvmAddress()` instead.\n * @returns {string}\n */\n toEthereumAddress() {\n return this._key.toEthereumAddress();\n }\n\n /**\n * @returns {string}\n */\n toEvmAddress() {\n return this._key.toEthereumAddress();\n }\n\n /**\n * @returns {string}\n */\n toString() {\n return this._key.toString();\n }\n\n /**\n * @returns {string}\n */\n toStringDer() {\n return this._key.toStringDer();\n }\n\n /**\n * @returns {string}\n */\n toStringRaw() {\n return this._key.toStringRaw();\n }\n\n /**\n * @param {PublicKey} other\n * @returns {boolean}\n */\n equals(other) {\n return this._key.equals(other._key);\n }\n\n /**\n * @returns {HieroProto.proto.IKey}\n */\n _toProtobufKey() {\n switch (this._key._type) {\n case \"ED25519\":\n return {\n ed25519: this._key.toBytesRaw(),\n };\n case \"secp256k1\":\n return {\n ECDSASecp256k1: this._key.toBytesRaw(),\n };\n default:\n throw new Error(`unrecognized key type ${this._key._type}`);\n }\n }\n\n /**\n * @param {Uint8Array} signature\n * @returns {HieroProto.proto.ISignaturePair}\n */\n _toProtobufSignature(signature) {\n switch (this._key._type) {\n case \"ED25519\":\n return {\n pubKeyPrefix: this._key.toBytesRaw(),\n ed25519: signature,\n };\n case \"secp256k1\":\n return {\n pubKeyPrefix: this._key.toBytesRaw(),\n ECDSASecp256k1: signature,\n };\n default:\n throw new Error(`unrecognized key type ${this._key._type}`);\n }\n }\n\n /**\n * @returns {string}\n */\n get type() {\n return this._key._type;\n }\n\n /**\n * @param {Long | number} shard\n * @param {Long | number} realm\n * @returns {AccountId}\n */\n toAccountId(shard, realm) {\n return CACHE.accountIdConstructor(shard, realm, this);\n }\n\n /**\n * Returns an \"unusable\" public key.\n * “Unusable” refers to a key such as an Ed25519 0x00000... public key,\n * since it is (presumably) impossible to find the 32-byte string whose SHA-512 hash begins with 32 bytes of zeros.\n *\n * @returns {PublicKey}\n */\n static unusableKey() {\n return PublicKey.fromStringED25519(\n \"0000000000000000000000000000000000000000000000000000000000000000\",\n );\n }\n}\n\nCACHE.setPublicKeyED25519((key) => PublicKey.fromBytesED25519(key));\nCACHE.setPublicKeyECDSA((key) => PublicKey.fromBytesECDSA(key));\n"],"names":["PublicKey","Key","constructor","key","super","this","_key","fromBytes","data","PublicKeyCrypto","fromBytesED25519","fromBytesECDSA","fromString","text","fromStringECDSA","fromStringED25519","verify","message","signature","verifyTransaction","transaction","_requireFrozen","isFrozen","freeze","signedTransaction","_signedTransactions","list","_verifySignedTransaction","sigMap","sigPair","bodyBytes","publicKeyBytes","toBytesRaw","pubKeyPrefix","arrayEqual","_extractSignature","ed25519","ECDSASecp256k1","toBytes","toBytesDer","toEthereumAddress","toEvmAddress","toString","toStringDer","toStringRaw","equals","other","_toProtobufKey","_type","Error","_toProtobufSignature","type","toAccountId","shard","realm","CACHE","accountIdConstructor","unusableKey","setPublicKeyED25519","setPublicKeyECDSA"],"mappings":"iJAoBe,MAAMA,UAAkBC,EAMnC,WAAAC,CAAYC,GACRC,QAEAC,KAAKC,KAAOH,CACpB,CAMI,gBAAOI,CAAUC,GACb,OAAO,IAAIR,EAAUS,EAAgBF,UAAUC,GACvD,CAMI,uBAAOE,CAAiBF,GACpB,OAAO,IAAIR,EAAUS,EAAgBC,iBAAiBF,GAC9D,CAMI,qBAAOG,CAAeH,GAClB,OAAO,IAAIR,EAAUS,EAAgBE,eAAeH,GAC5D,CAWI,iBAAOI,CAAWC,GACd,OAAO,IAAIb,EAAUS,EAAgBG,WAAWC,GACxD,CAQI,sBAAOC,CAAgBD,GACnB,OAAO,IAAIb,EAAUS,EAAgBK,gBAAgBD,GA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C,KAAKC,KAAKuC,OAAOC,EAAMxC,KACtC,CAKI,cAAAyC,GACI,OAAQ1C,KAAKC,KAAK0C,OACd,IAAK,UACD,MAAO,CACHZ,QAAS/B,KAAKC,KAAK0B,cAE3B,IAAK,YACD,MAAO,CACHK,eAAgBhC,KAAKC,KAAK0B,cAElC,QACI,MAAM,IAAIiB,MAAM,yBAAyB5C,KAAKC,KAAK0C,SAEnE,CAMI,oBAAAE,CAAqBhC,GACjB,OAAQb,KAAKC,KAAK0C,OACd,IAAK,UACD,MAAO,CACHf,aAAc5B,KAAKC,KAAK0B,aACxBI,QAASlB,GAEjB,IAAK,YACD,MAAO,CACHe,aAAc5B,KAAKC,KAAK0B,aACxBK,eAAgBnB,GAExB,QACI,MAAM,IAAI+B,MAAM,yBAAyB5C,KAAKC,KAAK0C,SAEnE,CAKI,QAAIG,GACA,OAAO9C,KAAKC,KAAK0C,KACzB,CAOI,WAAAI,CAAYC,EAAOC,GACf,OAAOC,EAAMC,qBAAqBH,EAAOC,EAAOjD,KACxD,CASI,kBAAOoD,GACH,OAAOzD,EAAUe,kBACb,mEAEZ,EAGAwC,EAAMG,oBAAqBvD,GAAQH,EAAUU,iBAAiBP,IAC9DoD,EAAMI,kBAAmBxD,GAAQH,EAAUW,eAAeR"}
@@ -222,6 +222,10 @@ class RequestType {
222
222
  return "LambdaSStore";
223
223
  case RequestType.HookDispatch:
224
224
  return "HookDispatch";
225
+ case RequestType.HookStore:
226
+ return "HookStore";
227
+ case RequestType.LedgerIdPublication:
228
+ return "LedgerIdPublication";
225
229
  default:
226
230
  return `UNKNOWN (${this._code})`;
227
231
  }
@@ -428,6 +432,10 @@ class RequestType {
428
432
  return RequestType.LambdaSStore;
429
433
  case 110:
430
434
  return RequestType.HookDispatch;
435
+ case 111:
436
+ return RequestType.HookStore;
437
+ case 112:
438
+ return RequestType.LedgerIdPublication;
431
439
  }
432
440
  throw new Error(`(BUG) RequestType.fromCode() does not handle code: ${code}`);
433
441
  }
@@ -937,4 +945,14 @@ RequestType.LambdaSStore = new RequestType(109);
937
945
  /**
938
946
  * hook dispatch
939
947
  */
940
- RequestType.HookDispatch = new RequestType(110);
948
+ RequestType.HookDispatch = new RequestType(110);
949
+
950
+ /**
951
+ * Update one or more storage slots in an EVM hook.
952
+ */
953
+ RequestType.HookStore = new RequestType(111);
954
+
955
+ /**
956
+ * (Internal-only) Publish a new ledger id and chain-of-trust key.
957
+ */
958
+ RequestType.LedgerIdPublication = new RequestType(112);
@@ -124,6 +124,8 @@ declare namespace RequestType {
124
124
  let AtomicBatch: RequestType;
125
125
  let LambdaSStore: RequestType;
126
126
  let HookDispatch: RequestType;
127
+ let HookStore: RequestType;
128
+ let LedgerIdPublication: RequestType;
127
129
  }
128
130
  export default RequestType;
129
131
  export namespace HieroProto {
@@ -1,2 +1,2 @@
1
- class e{constructor(e){this._code=e,Object.freeze(this)}toString(){switch(this){case e.None:return"NONE";case e.CryptoTransfer:return"CryptoTransfer";case e.CryptoUpdate:return"CryptoUpdate";case e.CryptoDelete:return"CryptoDelete";case e.CryptoAddLiveHash:return"CryptoAddLiveHash";case e.CryptoDeleteLiveHash:return"CryptoDeleteLiveHash";case e.ContractCall:return"ContractCall";case e.ContractCreate:return"ContractCreate";case e.ContractUpdate:return"ContractUpdate";case e.FileCreate:return"FileCreate";case e.FileAppend:return"FileAppend";case e.FileUpdate:return"FileUpdate";case e.FileDelete:return"FileDelete";case e.CryptoGetAccountBalance:return"CryptoGetAccountBalance";case e.CryptoGetAccountRecords:return"CryptoGetAccountRecords";case e.CryptoGetInfo:return"CryptoGetInfo";case e.ContractCallLocal:return"ContractCallLocal";case e.ContractGetInfo:return"ContractGetInfo";case e.ContractGetBytecode:return"ContractGetBytecode";case e.GetBySolidityID:return"GetBySolidityID";case e.GetByKey:return"GetByKey";case e.CryptoGetLiveHash:return"CryptoGetLiveHash";case e.CryptoGetStakers:return"CryptoGetStakers";case e.FileGetContents:return"FileGetContents";case e.FileGetInfo:return"FileGetInfo";case e.TransactionGetRecord:return"TransactionGetRecord";case e.ContractGetRecords:return"ContractGetRecords";case e.CryptoCreate:return"CryptoCreate";case e.SystemDelete:return"SystemDelete";case e.SystemUndelete:return"SystemUndelete";case e.ContractDelete:return"ContractDelete";case e.Freeze:return"Freeze";case e.CreateTransactionRecord:return"CreateTransactionRecord";case e.CryptoAccountAutoRenew:return"CryptoAccountAutoRenew";case e.ContractAutoRenew:return"ContractAutoRenew";case e.GetVersionInfo:return"GetVersionInfo";case e.TransactionGetReceipt:return"TransactionGetReceipt";case e.ConsensusCreateTopic:return"ConsensusCreateTopic";case e.ConsensusUpdateTopic:return"ConsensusUpdateTopic";case e.ConsensusDeleteTopic:return"ConsensusDeleteTopic";case e.ConsensusGetTopicInfo:return"ConsensusGetTopicInfo";case e.ConsensusSubmitMessage:return"ConsensusSubmitMessage";case e.UncheckedSubmit:return"UncheckedSubmit";case e.TokenCreate:return"TokenCreate";case e.TokenGetInfo:return"TokenGetInfo";case e.TokenFreezeAccount:return"TokenFreezeAccount";case e.TokenUnfreezeAccount:return"TokenUnfreezeAccount";case e.TokenGrantKycToAccount:return"TokenGrantKycToAccount";case e.TokenRevokeKycFromAccount:return"TokenRevokeKycFromAccount";case e.TokenDelete:return"TokenDelete";case e.TokenUpdate:return"TokenUpdate";case e.TokenMint:return"TokenMint";case e.TokenBurn:return"TokenBurn";case e.TokenAccountWipe:return"TokenAccountWipe";case e.TokenAssociateToAccount:return"TokenAssociateToAccount";case e.TokenDissociateFromAccount:return"TokenDissociateFromAccount";case e.ScheduleCreate:return"ScheduleCreate";case e.ScheduleDelete:return"ScheduleDelete";case e.ScheduleSign:return"ScheduleSign";case e.ScheduleGetInfo:return"ScheduleGetInfo";case e.TokenGetAccountNftInfos:return"TokenGetAccountNftInfos";case e.TokenGetNftInfo:return"TokenGetNftInfo";case e.TokenGetNftInfos:return"TokenGetNftInfos";case e.TokenFeeScheduleUpdate:return"TokenFeeScheduleUpdate";case e.NetworkGetExecutionTime:return"NetworkGetExecutionTime";case e.TokenPause:return"TokenPause";case e.TokenUnpause:return"TokenUnpause";case e.CryptoApproveAllowance:return"CryptoApproveAllowance";case e.CryptoDeleteAllowance:return"CryptoDeleteAllowance";case e.GetAccountDetails:return"GetAccountDetails";case e.EthereumTransaction:return"EthereumTransaction";case e.NodeStakeUpdate:return"NodeStakeUpdate";case e.Prng:return"UtilPrng";case e.TransactionGetFastRecord:return"TransactionGetFastRecord";case e.TokenUpdateNfts:return"TokenUpdateNfts";case e.NodeCreate:return"NodeCreate";case e.NodeUpdate:return"NodeUpdate";case e.NodeDelete:return"NodeDelete";case e.TokenReject:return"TokenReject";case e.TokenAirdrop:return"TokenAirdrop";case e.TokenCancelAirdrop:return"TokenCancelAirdrop";case e.TokenClaimAirdrop:return"TokenClaimAirdrop";case e.TssMessage:return"TssMessage";case e.TssVote:return"TssVote";case e.TssShareSignature:return"TssShareSignature";case e.TssEncryptionKey:return"TssEncryptionKey";case e.StateSignatureTransaction:return"StateSignatureTransaction";case e.HistoryAssemblySignature:return"HistoryAssemblySignature";case e.HistoryProofKeyPublication:return"HistoryProofKeyPublication";case e.HistoryProofVote:return"HistoryProofVote";case e.HintsKeyPublication:return"HintsKeyPublication";case e.HintsPreprocessingVote:return"HintsPreprocessingVote";case e.HintsPartialSignature:return"HintsPartialSignature";case e.CrsPublication:return"CrsPublication";case e.AtomicBatch:return"AtomicBatch";case e.LambdaSStore:return"LambdaSStore";case e.HookDispatch:return"HookDispatch";default:return`UNKNOWN (${this._code})`}}static _fromCode(t){switch(t){case 0:return e.None;case 1:return e.CryptoTransfer;case 2:return e.CryptoUpdate;case 3:return e.CryptoDelete;case 4:return e.CryptoAddLiveHash;case 5:return e.CryptoDeleteLiveHash;case 6:return e.ContractCall;case 7:return e.ContractCreate;case 8:return e.ContractUpdate;case 9:return e.FileCreate;case 10:return e.FileAppend;case 11:return e.FileUpdate;case 12:return e.FileDelete;case 13:return e.CryptoGetAccountBalance;case 14:return e.CryptoGetAccountRecords;case 15:return e.CryptoGetInfo;case 16:return e.ContractCallLocal;case 17:return e.ContractGetInfo;case 18:return e.ContractGetBytecode;case 19:return e.GetBySolidityID;case 20:return e.GetByKey;case 21:return e.CryptoGetLiveHash;case 22:return e.CryptoGetStakers;case 23:return e.FileGetContents;case 24:return e.FileGetInfo;case 25:return e.TransactionGetRecord;case 26:return e.ContractGetRecords;case 27:return e.CryptoCreate;case 28:return e.SystemDelete;case 29:return e.SystemUndelete;case 30:return e.ContractDelete;case 31:return e.Freeze;case 32:return e.CreateTransactionRecord;case 33:return e.CryptoAccountAutoRenew;case 34:return e.ContractAutoRenew;case 35:return e.GetVersionInfo;case 36:return e.TransactionGetReceipt;case 50:return e.ConsensusCreateTopic;case 51:return e.ConsensusUpdateTopic;case 52:return e.ConsensusDeleteTopic;case 53:return e.ConsensusGetTopicInfo;case 54:return e.ConsensusSubmitMessage;case 55:return e.UncheckedSubmit;case 56:return e.TokenCreate;case 58:return e.TokenGetInfo;case 59:return e.TokenFreezeAccount;case 60:return e.TokenUnfreezeAccount;case 61:return e.TokenGrantKycToAccount;case 62:return e.TokenRevokeKycFromAccount;case 63:return e.TokenDelete;case 64:return e.TokenUpdate;case 65:return e.TokenMint;case 66:return e.TokenBurn;case 67:return e.TokenAccountWipe;case 68:return e.TokenAssociateToAccount;case 69:return e.TokenDissociateFromAccount;case 70:return e.ScheduleCreate;case 71:return e.ScheduleDelete;case 72:return e.ScheduleSign;case 73:return e.ScheduleGetInfo;case 74:return e.TokenGetAccountNftInfos;case 75:return e.TokenGetNftInfo;case 76:return e.TokenGetNftInfos;case 77:return e.TokenFeeScheduleUpdate;case 78:return e.NetworkGetExecutionTime;case 79:return e.TokenPause;case 80:return e.TokenUnpause;case 81:return e.CryptoApproveAllowance;case 82:return e.CryptoDeleteAllowance;case 83:return e.GetAccountDetails;case 84:return e.EthereumTransaction;case 85:return e.NodeStakeUpdate;case 86:return e.Prng;case 87:return e.TransactionGetFastRecord;case 88:return e.TokenUpdateNfts;case 89:return e.NodeCreate;case 90:return e.NodeUpdate;case 91:return e.NodeDelete;case 92:return e.TokenReject;case 93:return e.TokenAirdrop;case 94:return e.TokenCancelAirdrop;case 95:return e.TokenClaimAirdrop;case 96:return e.TssMessage;case 97:return e.TssVote;case 98:return e.TssShareSignature;case 99:return e.TssEncryptionKey;case 100:return e.StateSignatureTransaction;case 101:return e.HintsKeyPublication;case 102:return e.HintsPreprocessingVote;case 103:return e.HintsPartialSignature;case 104:return e.HistoryAssemblySignature;case 105:return e.HistoryProofKeyPublication;case 106:return e.HistoryProofVote;case 107:return e.CrsPublication;case 108:return e.AtomicBatch;case 109:return e.LambdaSStore;case 110:return e.HookDispatch}throw new Error(`(BUG) RequestType.fromCode() does not handle code: ${t}`)}valueOf(){return this._code}}e.None=new e(0),e.CryptoTransfer=new e(1),e.CryptoUpdate=new e(2),e.CryptoDelete=new e(3),e.CryptoAddLiveHash=new e(4),e.CryptoDeleteLiveHash=new e(5),e.ContractCall=new e(6),e.ContractCreate=new e(7),e.ContractUpdate=new e(8),e.FileCreate=new e(9),e.FileAppend=new e(10),e.FileUpdate=new e(11),e.FileDelete=new e(12),e.CryptoGetAccountBalance=new e(13),e.CryptoGetAccountRecords=new e(14),e.CryptoGetInfo=new e(15),e.ContractCallLocal=new e(16),e.ContractGetInfo=new e(17),e.ContractGetBytecode=new e(18),e.GetBySolidityID=new e(19),e.GetByKey=new e(20),e.CryptoGetLiveHash=new e(21),e.CryptoGetStakers=new e(22),e.FileGetContents=new e(23),e.FileGetInfo=new e(24),e.TransactionGetRecord=new e(25),e.ContractGetRecords=new e(26),e.CryptoCreate=new e(27),e.SystemDelete=new e(28),e.SystemUndelete=new e(29),e.ContractDelete=new e(30),e.Freeze=new e(31),e.CreateTransactionRecord=new e(32),e.CryptoAccountAutoRenew=new e(33),e.ContractAutoRenew=new e(34),e.GetVersionInfo=new e(35),e.TransactionGetReceipt=new e(36),e.ConsensusCreateTopic=new e(50),e.ConsensusUpdateTopic=new e(51),e.ConsensusDeleteTopic=new e(52),e.ConsensusGetTopicInfo=new e(53),e.ConsensusSubmitMessage=new e(54),e.UncheckedSubmit=new e(55),e.TokenCreate=new e(56),e.TokenGetInfo=new e(58),e.TokenFreezeAccount=new e(59),e.TokenUnfreezeAccount=new e(60),e.TokenGrantKycToAccount=new e(61),e.TokenRevokeKycFromAccount=new e(62),e.TokenDelete=new e(63),e.TokenUpdate=new e(64),e.TokenMint=new e(65),e.TokenBurn=new e(66),e.TokenAccountWipe=new e(67),e.TokenAssociateToAccount=new e(68),e.TokenDissociateFromAccount=new e(69),e.ScheduleCreate=new e(70),e.ScheduleDelete=new e(71),e.ScheduleSign=new e(72),e.ScheduleGetInfo=new e(73),e.TokenGetAccountNftInfos=new e(74),e.TokenGetNftInfo=new e(75),e.TokenGetNftInfos=new e(76),e.TokenFeeScheduleUpdate=new e(77),e.NetworkGetExecutionTime=new e(78),e.TokenPause=new e(79),e.TokenUnpause=new e(80),e.CryptoApproveAllowance=new e(81),e.CryptoDeleteAllowance=new e(82),e.GetAccountDetails=new e(83),e.EthereumTransaction=new e(84),e.NodeStakeUpdate=new e(85),e.Prng=new e(86),e.TransactionGetFastRecord=new e(87),e.TokenUpdateNfts=new e(88),e.NodeCreate=new e(89),e.NodeUpdate=new e(90),e.NodeDelete=new e(91),e.TokenReject=new e(92),e.TokenAirdrop=new e(93),e.TokenCancelAirdrop=new e(94),e.TokenClaimAirdrop=new e(95),e.TssMessage=new e(96),e.TssVote=new e(97),e.TssShareSignature=new e(98),e.TssEncryptionKey=new e(99),e.StateSignatureTransaction=new e(100),e.HintsKeyPublication=new e(101),e.HintsPreprocessingVote=new e(102),e.HintsPartialSignature=new e(103),e.HistoryAssemblySignature=new e(104),e.HistoryProofKeyPublication=new e(105),e.HistoryProofVote=new e(106),e.CrsPublication=new e(107),e.HistoryAssemblySignature=new e(104),e.HistoryProofKeyPublication=new e(105),e.HistoryProofVote=new e(106),e.AtomicBatch=new e(108),e.LambdaSStore=new e(109),e.HookDispatch=new e(110);export{e as default};
1
+ class e{constructor(e){this._code=e,Object.freeze(this)}toString(){switch(this){case e.None:return"NONE";case e.CryptoTransfer:return"CryptoTransfer";case e.CryptoUpdate:return"CryptoUpdate";case e.CryptoDelete:return"CryptoDelete";case e.CryptoAddLiveHash:return"CryptoAddLiveHash";case e.CryptoDeleteLiveHash:return"CryptoDeleteLiveHash";case e.ContractCall:return"ContractCall";case e.ContractCreate:return"ContractCreate";case e.ContractUpdate:return"ContractUpdate";case e.FileCreate:return"FileCreate";case e.FileAppend:return"FileAppend";case e.FileUpdate:return"FileUpdate";case e.FileDelete:return"FileDelete";case e.CryptoGetAccountBalance:return"CryptoGetAccountBalance";case e.CryptoGetAccountRecords:return"CryptoGetAccountRecords";case e.CryptoGetInfo:return"CryptoGetInfo";case e.ContractCallLocal:return"ContractCallLocal";case e.ContractGetInfo:return"ContractGetInfo";case e.ContractGetBytecode:return"ContractGetBytecode";case e.GetBySolidityID:return"GetBySolidityID";case e.GetByKey:return"GetByKey";case e.CryptoGetLiveHash:return"CryptoGetLiveHash";case e.CryptoGetStakers:return"CryptoGetStakers";case e.FileGetContents:return"FileGetContents";case e.FileGetInfo:return"FileGetInfo";case e.TransactionGetRecord:return"TransactionGetRecord";case e.ContractGetRecords:return"ContractGetRecords";case e.CryptoCreate:return"CryptoCreate";case e.SystemDelete:return"SystemDelete";case e.SystemUndelete:return"SystemUndelete";case e.ContractDelete:return"ContractDelete";case e.Freeze:return"Freeze";case e.CreateTransactionRecord:return"CreateTransactionRecord";case e.CryptoAccountAutoRenew:return"CryptoAccountAutoRenew";case e.ContractAutoRenew:return"ContractAutoRenew";case e.GetVersionInfo:return"GetVersionInfo";case e.TransactionGetReceipt:return"TransactionGetReceipt";case e.ConsensusCreateTopic:return"ConsensusCreateTopic";case e.ConsensusUpdateTopic:return"ConsensusUpdateTopic";case e.ConsensusDeleteTopic:return"ConsensusDeleteTopic";case e.ConsensusGetTopicInfo:return"ConsensusGetTopicInfo";case e.ConsensusSubmitMessage:return"ConsensusSubmitMessage";case e.UncheckedSubmit:return"UncheckedSubmit";case e.TokenCreate:return"TokenCreate";case e.TokenGetInfo:return"TokenGetInfo";case e.TokenFreezeAccount:return"TokenFreezeAccount";case e.TokenUnfreezeAccount:return"TokenUnfreezeAccount";case e.TokenGrantKycToAccount:return"TokenGrantKycToAccount";case e.TokenRevokeKycFromAccount:return"TokenRevokeKycFromAccount";case e.TokenDelete:return"TokenDelete";case e.TokenUpdate:return"TokenUpdate";case e.TokenMint:return"TokenMint";case e.TokenBurn:return"TokenBurn";case e.TokenAccountWipe:return"TokenAccountWipe";case e.TokenAssociateToAccount:return"TokenAssociateToAccount";case e.TokenDissociateFromAccount:return"TokenDissociateFromAccount";case e.ScheduleCreate:return"ScheduleCreate";case e.ScheduleDelete:return"ScheduleDelete";case e.ScheduleSign:return"ScheduleSign";case e.ScheduleGetInfo:return"ScheduleGetInfo";case e.TokenGetAccountNftInfos:return"TokenGetAccountNftInfos";case e.TokenGetNftInfo:return"TokenGetNftInfo";case e.TokenGetNftInfos:return"TokenGetNftInfos";case e.TokenFeeScheduleUpdate:return"TokenFeeScheduleUpdate";case e.NetworkGetExecutionTime:return"NetworkGetExecutionTime";case e.TokenPause:return"TokenPause";case e.TokenUnpause:return"TokenUnpause";case e.CryptoApproveAllowance:return"CryptoApproveAllowance";case e.CryptoDeleteAllowance:return"CryptoDeleteAllowance";case e.GetAccountDetails:return"GetAccountDetails";case e.EthereumTransaction:return"EthereumTransaction";case e.NodeStakeUpdate:return"NodeStakeUpdate";case e.Prng:return"UtilPrng";case e.TransactionGetFastRecord:return"TransactionGetFastRecord";case e.TokenUpdateNfts:return"TokenUpdateNfts";case e.NodeCreate:return"NodeCreate";case e.NodeUpdate:return"NodeUpdate";case e.NodeDelete:return"NodeDelete";case e.TokenReject:return"TokenReject";case e.TokenAirdrop:return"TokenAirdrop";case e.TokenCancelAirdrop:return"TokenCancelAirdrop";case e.TokenClaimAirdrop:return"TokenClaimAirdrop";case e.TssMessage:return"TssMessage";case e.TssVote:return"TssVote";case e.TssShareSignature:return"TssShareSignature";case e.TssEncryptionKey:return"TssEncryptionKey";case e.StateSignatureTransaction:return"StateSignatureTransaction";case e.HistoryAssemblySignature:return"HistoryAssemblySignature";case e.HistoryProofKeyPublication:return"HistoryProofKeyPublication";case e.HistoryProofVote:return"HistoryProofVote";case e.HintsKeyPublication:return"HintsKeyPublication";case e.HintsPreprocessingVote:return"HintsPreprocessingVote";case e.HintsPartialSignature:return"HintsPartialSignature";case e.CrsPublication:return"CrsPublication";case e.AtomicBatch:return"AtomicBatch";case e.LambdaSStore:return"LambdaSStore";case e.HookDispatch:return"HookDispatch";case e.HookStore:return"HookStore";case e.LedgerIdPublication:return"LedgerIdPublication";default:return`UNKNOWN (${this._code})`}}static _fromCode(t){switch(t){case 0:return e.None;case 1:return e.CryptoTransfer;case 2:return e.CryptoUpdate;case 3:return e.CryptoDelete;case 4:return e.CryptoAddLiveHash;case 5:return e.CryptoDeleteLiveHash;case 6:return e.ContractCall;case 7:return e.ContractCreate;case 8:return e.ContractUpdate;case 9:return e.FileCreate;case 10:return e.FileAppend;case 11:return e.FileUpdate;case 12:return e.FileDelete;case 13:return e.CryptoGetAccountBalance;case 14:return e.CryptoGetAccountRecords;case 15:return e.CryptoGetInfo;case 16:return e.ContractCallLocal;case 17:return e.ContractGetInfo;case 18:return e.ContractGetBytecode;case 19:return e.GetBySolidityID;case 20:return e.GetByKey;case 21:return e.CryptoGetLiveHash;case 22:return e.CryptoGetStakers;case 23:return e.FileGetContents;case 24:return e.FileGetInfo;case 25:return e.TransactionGetRecord;case 26:return e.ContractGetRecords;case 27:return e.CryptoCreate;case 28:return e.SystemDelete;case 29:return e.SystemUndelete;case 30:return e.ContractDelete;case 31:return e.Freeze;case 32:return e.CreateTransactionRecord;case 33:return e.CryptoAccountAutoRenew;case 34:return e.ContractAutoRenew;case 35:return e.GetVersionInfo;case 36:return e.TransactionGetReceipt;case 50:return e.ConsensusCreateTopic;case 51:return e.ConsensusUpdateTopic;case 52:return e.ConsensusDeleteTopic;case 53:return e.ConsensusGetTopicInfo;case 54:return e.ConsensusSubmitMessage;case 55:return e.UncheckedSubmit;case 56:return e.TokenCreate;case 58:return e.TokenGetInfo;case 59:return e.TokenFreezeAccount;case 60:return e.TokenUnfreezeAccount;case 61:return e.TokenGrantKycToAccount;case 62:return e.TokenRevokeKycFromAccount;case 63:return e.TokenDelete;case 64:return e.TokenUpdate;case 65:return e.TokenMint;case 66:return e.TokenBurn;case 67:return e.TokenAccountWipe;case 68:return e.TokenAssociateToAccount;case 69:return e.TokenDissociateFromAccount;case 70:return e.ScheduleCreate;case 71:return e.ScheduleDelete;case 72:return e.ScheduleSign;case 73:return e.ScheduleGetInfo;case 74:return e.TokenGetAccountNftInfos;case 75:return e.TokenGetNftInfo;case 76:return e.TokenGetNftInfos;case 77:return e.TokenFeeScheduleUpdate;case 78:return e.NetworkGetExecutionTime;case 79:return e.TokenPause;case 80:return e.TokenUnpause;case 81:return e.CryptoApproveAllowance;case 82:return e.CryptoDeleteAllowance;case 83:return e.GetAccountDetails;case 84:return e.EthereumTransaction;case 85:return e.NodeStakeUpdate;case 86:return e.Prng;case 87:return e.TransactionGetFastRecord;case 88:return e.TokenUpdateNfts;case 89:return e.NodeCreate;case 90:return e.NodeUpdate;case 91:return e.NodeDelete;case 92:return e.TokenReject;case 93:return e.TokenAirdrop;case 94:return e.TokenCancelAirdrop;case 95:return e.TokenClaimAirdrop;case 96:return e.TssMessage;case 97:return e.TssVote;case 98:return e.TssShareSignature;case 99:return e.TssEncryptionKey;case 100:return e.StateSignatureTransaction;case 101:return e.HintsKeyPublication;case 102:return e.HintsPreprocessingVote;case 103:return e.HintsPartialSignature;case 104:return e.HistoryAssemblySignature;case 105:return e.HistoryProofKeyPublication;case 106:return e.HistoryProofVote;case 107:return e.CrsPublication;case 108:return e.AtomicBatch;case 109:return e.LambdaSStore;case 110:return e.HookDispatch;case 111:return e.HookStore;case 112:return e.LedgerIdPublication}throw new Error(`(BUG) RequestType.fromCode() does not handle code: ${t}`)}valueOf(){return this._code}}e.None=new e(0),e.CryptoTransfer=new e(1),e.CryptoUpdate=new e(2),e.CryptoDelete=new e(3),e.CryptoAddLiveHash=new e(4),e.CryptoDeleteLiveHash=new e(5),e.ContractCall=new e(6),e.ContractCreate=new e(7),e.ContractUpdate=new e(8),e.FileCreate=new e(9),e.FileAppend=new e(10),e.FileUpdate=new e(11),e.FileDelete=new e(12),e.CryptoGetAccountBalance=new e(13),e.CryptoGetAccountRecords=new e(14),e.CryptoGetInfo=new e(15),e.ContractCallLocal=new e(16),e.ContractGetInfo=new e(17),e.ContractGetBytecode=new e(18),e.GetBySolidityID=new e(19),e.GetByKey=new e(20),e.CryptoGetLiveHash=new e(21),e.CryptoGetStakers=new e(22),e.FileGetContents=new e(23),e.FileGetInfo=new e(24),e.TransactionGetRecord=new e(25),e.ContractGetRecords=new e(26),e.CryptoCreate=new e(27),e.SystemDelete=new e(28),e.SystemUndelete=new e(29),e.ContractDelete=new e(30),e.Freeze=new e(31),e.CreateTransactionRecord=new e(32),e.CryptoAccountAutoRenew=new e(33),e.ContractAutoRenew=new e(34),e.GetVersionInfo=new e(35),e.TransactionGetReceipt=new e(36),e.ConsensusCreateTopic=new e(50),e.ConsensusUpdateTopic=new e(51),e.ConsensusDeleteTopic=new e(52),e.ConsensusGetTopicInfo=new e(53),e.ConsensusSubmitMessage=new e(54),e.UncheckedSubmit=new e(55),e.TokenCreate=new e(56),e.TokenGetInfo=new e(58),e.TokenFreezeAccount=new e(59),e.TokenUnfreezeAccount=new e(60),e.TokenGrantKycToAccount=new e(61),e.TokenRevokeKycFromAccount=new e(62),e.TokenDelete=new e(63),e.TokenUpdate=new e(64),e.TokenMint=new e(65),e.TokenBurn=new e(66),e.TokenAccountWipe=new e(67),e.TokenAssociateToAccount=new e(68),e.TokenDissociateFromAccount=new e(69),e.ScheduleCreate=new e(70),e.ScheduleDelete=new e(71),e.ScheduleSign=new e(72),e.ScheduleGetInfo=new e(73),e.TokenGetAccountNftInfos=new e(74),e.TokenGetNftInfo=new e(75),e.TokenGetNftInfos=new e(76),e.TokenFeeScheduleUpdate=new e(77),e.NetworkGetExecutionTime=new e(78),e.TokenPause=new e(79),e.TokenUnpause=new e(80),e.CryptoApproveAllowance=new e(81),e.CryptoDeleteAllowance=new e(82),e.GetAccountDetails=new e(83),e.EthereumTransaction=new e(84),e.NodeStakeUpdate=new e(85),e.Prng=new e(86),e.TransactionGetFastRecord=new e(87),e.TokenUpdateNfts=new e(88),e.NodeCreate=new e(89),e.NodeUpdate=new e(90),e.NodeDelete=new e(91),e.TokenReject=new e(92),e.TokenAirdrop=new e(93),e.TokenCancelAirdrop=new e(94),e.TokenClaimAirdrop=new e(95),e.TssMessage=new e(96),e.TssVote=new e(97),e.TssShareSignature=new e(98),e.TssEncryptionKey=new e(99),e.StateSignatureTransaction=new e(100),e.HintsKeyPublication=new e(101),e.HintsPreprocessingVote=new e(102),e.HintsPartialSignature=new e(103),e.HistoryAssemblySignature=new e(104),e.HistoryProofKeyPublication=new e(105),e.HistoryProofVote=new e(106),e.CrsPublication=new e(107),e.HistoryAssemblySignature=new e(104),e.HistoryProofKeyPublication=new e(105),e.HistoryProofVote=new e(106),e.AtomicBatch=new e(108),e.LambdaSStore=new e(109),e.HookDispatch=new e(110),e.HookStore=new e(111),e.LedgerIdPublication=new e(112);export{e as default};
2
2
  //# sourceMappingURL=RequestType.js.map