@keetanetwork/keetanet-client 0.14.11 → 0.14.13

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 (137) hide show
  1. package/client/index-browser.d.ts +35 -3
  2. package/client/index-browser.js +751 -34
  3. package/client/index.d.ts +35 -3
  4. package/client/index.js +688 -56
  5. package/docs/assets/hierarchy.js +1 -1
  6. package/docs/assets/search.js +1 -1
  7. package/docs/classes/KeetaNetSDK.Referenced.BaseSet.html +1 -1
  8. package/docs/classes/KeetaNetSDK.Referenced.BaseVoteBuilder.html +1 -1
  9. package/docs/classes/KeetaNetSDK.Referenced.Block.html +1 -1
  10. package/docs/classes/KeetaNetSDK.Referenced.BlockHash.html +1 -1
  11. package/docs/classes/KeetaNetSDK.Referenced.BlockOperation.html +1 -1
  12. package/docs/classes/KeetaNetSDK.Referenced.BlockOperationCREATE_IDENTIFIER.html +1 -1
  13. package/docs/classes/KeetaNetSDK.Referenced.BlockOperationMANAGE_CERTIFICATE.html +1 -1
  14. package/docs/classes/KeetaNetSDK.Referenced.BlockOperationMODIFY_PERMISSIONS.html +1 -1
  15. package/docs/classes/KeetaNetSDK.Referenced.BlockOperationRECEIVE.html +1 -1
  16. package/docs/classes/KeetaNetSDK.Referenced.BlockOperationSEND.html +1 -1
  17. package/docs/classes/KeetaNetSDK.Referenced.BlockOperationSET_INFO.html +1 -1
  18. package/docs/classes/KeetaNetSDK.Referenced.BlockOperationSET_REP.html +1 -1
  19. package/docs/classes/KeetaNetSDK.Referenced.BlockOperationTOKEN_ADMIN_MODIFY_BALANCE.html +1 -1
  20. package/docs/classes/KeetaNetSDK.Referenced.BlockOperationTOKEN_ADMIN_SUPPLY.html +1 -1
  21. package/docs/classes/KeetaNetSDK.Referenced.CertificateHash.html +1 -1
  22. package/docs/classes/KeetaNetSDK.Referenced.ECDSAKeyPair.html +1 -1
  23. package/docs/classes/KeetaNetSDK.Referenced.ECDSASECP256K1KeyPair.html +1 -1
  24. package/docs/classes/KeetaNetSDK.Referenced.ECDSASECP256K1PrivateKey.html +1 -1
  25. package/docs/classes/KeetaNetSDK.Referenced.ECDSASECP256K1PublicKey.html +1 -1
  26. package/docs/classes/KeetaNetSDK.Referenced.ECDSASECP256K1Signature.html +1 -1
  27. package/docs/classes/KeetaNetSDK.Referenced.ECDSASECP256R1KeyPair.html +1 -1
  28. package/docs/classes/KeetaNetSDK.Referenced.ECDSASECP256R1PrivateKey.html +1 -1
  29. package/docs/classes/KeetaNetSDK.Referenced.ECDSASECP256R1PublicKey.html +1 -1
  30. package/docs/classes/KeetaNetSDK.Referenced.ECDSASECP256R1Signature.html +1 -1
  31. package/docs/classes/KeetaNetSDK.Referenced.ED25519KeyPair.html +1 -1
  32. package/docs/classes/KeetaNetSDK.Referenced.ED25519PrivateKey.html +1 -1
  33. package/docs/classes/KeetaNetSDK.Referenced.ED25519PublicKey.html +1 -1
  34. package/docs/classes/KeetaNetSDK.Referenced.ED25519Signature.html +1 -1
  35. package/docs/classes/KeetaNetSDK.Referenced.ExternalKeyPair.html +1 -1
  36. package/docs/classes/KeetaNetSDK.Referenced.ExternalSet.html +1 -1
  37. package/docs/classes/KeetaNetSDK.Referenced.IdempotentKey.html +1 -1
  38. package/docs/classes/KeetaNetSDK.Referenced.IdentifierKey.html +1 -1
  39. package/docs/classes/KeetaNetSDK.Referenced.IdentifierKeyPair.html +1 -1
  40. package/docs/classes/KeetaNetSDK.Referenced.KeetaNetError.html +2 -2
  41. package/docs/classes/KeetaNetSDK.Referenced.KeetaNetErrorBase.html +1 -1
  42. package/docs/classes/KeetaNetSDK.Referenced.KeetaNetLedgerError.html +1 -1
  43. package/docs/classes/KeetaNetSDK.Referenced.KeetaNetLedgerIdempotentKeyError.html +1 -1
  44. package/docs/classes/KeetaNetSDK.Referenced.KeetaNetLedgerVoteError.html +1 -1
  45. package/docs/classes/KeetaNetSDK.Referenced.KeyInterface.html +1 -1
  46. package/docs/classes/KeetaNetSDK.Referenced.KeyStorage.html +1 -1
  47. package/docs/classes/KeetaNetSDK.Referenced.Log.html +6 -4
  48. package/docs/classes/KeetaNetSDK.Referenced.PermissionSetHolder.html +1 -1
  49. package/docs/classes/KeetaNetSDK.Referenced.PossiblyExpiredVote.html +1 -1
  50. package/docs/classes/KeetaNetSDK.Referenced.RequestTiming.html +1 -1
  51. package/docs/classes/KeetaNetSDK.Referenced.SignatureStorage.html +1 -1
  52. package/docs/classes/KeetaNetSDK.Referenced.Stats.html +1 -1
  53. package/docs/classes/KeetaNetSDK.Referenced.StatsPending.html +1 -1
  54. package/docs/classes/KeetaNetSDK.Referenced.VoteBlockBundle.html +1 -1
  55. package/docs/classes/KeetaNetSDK.Referenced.VoteBlockHash.html +1 -1
  56. package/docs/classes/KeetaNetSDK.Referenced.VoteBuilder.html +1 -1
  57. package/docs/classes/KeetaNetSDK.Referenced.VoteHash.html +1 -1
  58. package/docs/classes/KeetaNetSDK.Referenced.VoteLikeBase.html +1 -1
  59. package/docs/classes/KeetaNetSDK.Referenced.VoteQuoteBuilder.html +1 -1
  60. package/docs/classes/KeetaNetSDK.Referenced.VoteStapleHash.html +1 -1
  61. package/docs/classes/KeetaNetSDK.Referenced.src_lib_utils_asn1.ValidateASN1.html +32 -4
  62. package/docs/classes/KeetaNetSDK.Referenced.src_lib_utils_buffer.BufferStorage.html +1 -1
  63. package/docs/hierarchy.html +1 -1
  64. package/docs/interfaces/KeetaNetSDK.Referenced.ACLEntry.html +1 -1
  65. package/docs/interfaces/KeetaNetSDK.Referenced.ACLUpdate.html +1 -1
  66. package/docs/interfaces/KeetaNetSDK.Referenced.ASN1ExplicitContextTag.html +1 -1
  67. package/docs/interfaces/KeetaNetSDK.Referenced.ASN1ImplicitContextTag.html +1 -1
  68. package/docs/interfaces/KeetaNetSDK.Referenced.ASN1Object.html +1 -1
  69. package/docs/interfaces/KeetaNetSDK.Referenced.AcceptSwapRequest.html +7 -2
  70. package/docs/interfaces/KeetaNetSDK.Referenced.BaseExternalKeyPairFunctions.html +1 -1
  71. package/docs/interfaces/KeetaNetSDK.Referenced.BaseGenerationConfig.html +1 -1
  72. package/docs/interfaces/KeetaNetSDK.Referenced.BaseIdentifierCreateArguments.html +1 -1
  73. package/docs/interfaces/KeetaNetSDK.Referenced.BlockJSONOperation.html +1 -1
  74. package/docs/interfaces/KeetaNetSDK.Referenced.BlockJSONOperationCREATE_IDENTIFIER.html +1 -1
  75. package/docs/interfaces/KeetaNetSDK.Referenced.BlockJSONOperationMANAGE_CERTIFICATE.html +1 -1
  76. package/docs/interfaces/KeetaNetSDK.Referenced.BlockJSONOperationMANAGE_CERTIFICATESerializable.html +1 -1
  77. package/docs/interfaces/KeetaNetSDK.Referenced.BlockJSONOperationMODIFY_PERMISSIONS.html +1 -1
  78. package/docs/interfaces/KeetaNetSDK.Referenced.BlockJSONOperationRECEIVE.html +1 -1
  79. package/docs/interfaces/KeetaNetSDK.Referenced.BlockJSONOperationSEND.html +1 -1
  80. package/docs/interfaces/KeetaNetSDK.Referenced.BlockJSONOperationSET_INFO.html +1 -1
  81. package/docs/interfaces/KeetaNetSDK.Referenced.BlockJSONOperationSET_REP.html +1 -1
  82. package/docs/interfaces/KeetaNetSDK.Referenced.BlockJSONOperationTOKEN_ADMIN_MODIFY_BALANCE.html +1 -1
  83. package/docs/interfaces/KeetaNetSDK.Referenced.BlockJSONOperationTOKEN_ADMIN_SUPPLY.html +1 -1
  84. package/docs/interfaces/KeetaNetSDK.Referenced.BlockV1Canonical.html +1 -1
  85. package/docs/interfaces/KeetaNetSDK.Referenced.BlockV2Canonical.html +1 -1
  86. package/docs/interfaces/KeetaNetSDK.Referenced.Constructor.html +1 -1
  87. package/docs/interfaces/KeetaNetSDK.Referenced.CreateSwapRequest.html +3 -2
  88. package/docs/interfaces/KeetaNetSDK.Referenced.DisposableTimingHandle.html +1 -1
  89. package/docs/interfaces/KeetaNetSDK.Referenced.ExternalKeyPairFunctionsNoEncryption.html +1 -1
  90. package/docs/interfaces/KeetaNetSDK.Referenced.ExternalKeyPairFunctionsSupportsEncryption.html +1 -1
  91. package/docs/interfaces/KeetaNetSDK.Referenced.InitialConfigSupply.html +1 -1
  92. package/docs/interfaces/KeetaNetSDK.Referenced.InstanceSet.html +1 -1
  93. package/docs/interfaces/KeetaNetSDK.Referenced.KVGenericOptionsType.html +1 -1
  94. package/docs/interfaces/KeetaNetSDK.Referenced.KVSetOptionsType.html +1 -1
  95. package/docs/interfaces/KeetaNetSDK.Referenced.Logger.html +4 -2
  96. package/docs/interfaces/KeetaNetSDK.Referenced.ModifyTokenBalanceEntry.html +1 -1
  97. package/docs/interfaces/KeetaNetSDK.Referenced.MultiSigIdentifierCreateArguments.html +1 -1
  98. package/docs/interfaces/KeetaNetSDK.Referenced.MultisigConfig.html +1 -1
  99. package/docs/interfaces/KeetaNetSDK.Referenced.NumericValueEntry.html +1 -1
  100. package/docs/interfaces/KeetaNetSDK.Referenced.P2PPeerBase.html +1 -1
  101. package/docs/interfaces/KeetaNetSDK.Referenced.P2PPeerListener.html +1 -1
  102. package/docs/interfaces/KeetaNetSDK.Referenced.P2PPeerRepBase.html +1 -1
  103. package/docs/interfaces/KeetaNetSDK.Referenced.PublicKeyStorage.html +1 -1
  104. package/docs/interfaces/KeetaNetSDK.Referenced.PublishOptions.html +1 -1
  105. package/docs/interfaces/KeetaNetSDK.Referenced.RequestTokenReceiveEntry.html +1 -1
  106. package/docs/interfaces/KeetaNetSDK.Referenced.TokenNumericEntry.html +1 -1
  107. package/docs/interfaces/KeetaNetSDK.Referenced.UserClientConfig.html +1 -1
  108. package/docs/interfaces/KeetaNetSDK.Referenced.UserClientOptions.html +1 -1
  109. package/docs/interfaces/KeetaNetSDK.Referenced.WithIsInstance.html +1 -1
  110. package/docs/interfaces/KeetaNetSDK.Referenced.src_lib_utils_asn1.ASN1BitString.html +1 -1
  111. package/docs/interfaces/KeetaNetSDK.Referenced.src_lib_utils_asn1.ASN1Date.html +1 -1
  112. package/docs/interfaces/KeetaNetSDK.Referenced.src_lib_utils_asn1.ASN1OID.html +1 -1
  113. package/docs/interfaces/KeetaNetSDK.Referenced.src_lib_utils_asn1.ASN1Set.html +1 -1
  114. package/docs/interfaces/KeetaNetSDK.Referenced.src_lib_utils_asn1.ASN1String.html +1 -1
  115. package/docs/interfaces/KeetaNetSDK.Referenced.src_lib_utils_asn1.ASN1Struct.html +1 -1
  116. package/docs/modules/KeetaNetSDK.Referenced.html +1 -1
  117. package/docs/modules/KeetaNetSDK.Referenced.src_lib_utils_asn1.ValidateASN1.html +1 -1
  118. package/docs/types/KeetaNetSDK.Referenced.AcceptSwapRequestExpectedDeprecated.html +4 -0
  119. package/docs/types/KeetaNetSDK.Referenced.BasicSchemaMapJS.html +14 -0
  120. package/docs/types/KeetaNetSDK.Referenced.src_lib_utils_asn1.ValidateASN1.Schema.html +1 -1
  121. package/docs/types/KeetaNetSDK.Referenced.src_lib_utils_asn1.ValidateASN1.SchemaMap.html +1 -1
  122. package/docs/types/KeetaNetSDK.Referenced.src_lib_utils_asn1.ValidateASN1.SchemaMapJS.html +5 -0
  123. package/docs/variables/KeetaNetSDK.Referenced.allFullErrorCodes.html +1 -1
  124. package/lib/block/index.d.ts +1 -1
  125. package/lib/error/block.d.ts +2 -2
  126. package/lib/error/client.d.ts +2 -2
  127. package/lib/error/index.d.ts +1 -1
  128. package/lib/kv/kv_redis.d.ts +3 -3
  129. package/lib/log/common.d.ts +4 -0
  130. package/lib/log/index.d.ts +4 -0
  131. package/lib/log/target_gcp.d.ts +1 -1
  132. package/lib/log/target_gcp.js +2 -2
  133. package/lib/node/timing.d.ts +4 -3
  134. package/lib/utils/asn1.d.ts +139 -5
  135. package/npm-shrinkwrap.json +2 -2
  136. package/package.json +1 -1
  137. package/version.d.ts +1 -1
package/client/index.js CHANGED
@@ -59991,7 +59991,7 @@ class UserClient {
59991
59991
  }
59992
59992
  const builder = userClient.initBuilder({ ...options, account: request.from.account });
59993
59993
  builder.send(to.account, from.amount, from.token);
59994
- builder.receive(to.account, to.amount, to.token, true);
59994
+ builder.receive(to.account, to.amount, to.token, request.to.exact ?? false);
59995
59995
  const blocks = await builder.computeBlocks();
59996
59996
  if (blocks.blocks.length !== 1) {
59997
59997
  throw (new Error('Compute Swap Request Generated more than 1 block'));
@@ -60009,7 +60009,7 @@ class UserClient {
60009
60009
  let userClient;
60010
60010
  if (UserClient.isInstance(builderOrUserClient)) {
60011
60011
  userClient = builderOrUserClient;
60012
- account = builderOrUserClient.account;
60012
+ account = options?.account ?? builderOrUserClient.account;
60013
60013
  }
60014
60014
  else {
60015
60015
  const env_1 = { stack: [], error: void 0, hasError: false };
@@ -60051,13 +60051,41 @@ class UserClient {
60051
60051
  if (!sendOperation.to.comparePublicKey(account)) {
60052
60052
  throw (new client_1.default('CLIENT_SWAP_SEND_ACCOUNT_MISMATCH', 'Swap Request send account does not match'));
60053
60053
  }
60054
- if (request.expected?.token !== undefined && !sendOperation.token.comparePublicKey(request.expected?.token)) {
60055
- throw (new client_1.default('CLIENT_SWAP_REQUEST_TOKEN_MISMATCH', 'Swap Request send token does not match expected'));
60056
- }
60057
- if (request.expected?.amount !== undefined && sendOperation.amount !== request.expected?.amount) {
60058
- throw (new client_1.default('CLIENT_SWAP_REQUEST_AMOUNT_MISMATCH', 'Swap Request send amount does not match expected'));
60054
+ let sendAmount = receiveOperation.amount;
60055
+ if (request.expected) {
60056
+ let expectedReceive;
60057
+ let expectedSend;
60058
+ if ('receive' in request.expected || 'send' in request.expected) {
60059
+ expectedReceive = request.expected?.receive;
60060
+ expectedSend = request.expected?.send;
60061
+ }
60062
+ else if ('token' in request.expected || 'amount' in request.expected) {
60063
+ expectedReceive = request.expected;
60064
+ }
60065
+ if (expectedReceive) {
60066
+ if (expectedReceive.token !== undefined && !sendOperation.token.comparePublicKey(expectedReceive.token)) {
60067
+ throw (new client_1.default('CLIENT_SWAP_REQUEST_TOKEN_MISMATCH', 'Swap Request send token does not match expected'));
60068
+ }
60069
+ if (expectedReceive.amount !== undefined && sendOperation.amount !== expectedReceive.amount) {
60070
+ throw (new client_1.default('CLIENT_SWAP_REQUEST_AMOUNT_MISMATCH', 'Swap Request send amount does not match expected'));
60071
+ }
60072
+ }
60073
+ if (expectedSend) {
60074
+ if (expectedSend.token !== undefined && !(expectedSend.token.comparePublicKey(receiveOperation.token))) {
60075
+ throw (new client_1.default('CLIENT_SWAP_SEND_TOKEN_MISMATCH', 'Swap acceptance send token does not match swap request receive token'));
60076
+ }
60077
+ if (expectedSend.amount !== undefined) {
60078
+ if (expectedSend.amount < receiveOperation.amount) {
60079
+ throw (new client_1.default('CLIENT_SWAP_SEND_AMOUNT_TOO_LOW', 'Send amount must be at least the receive amount specified in the swap request'));
60080
+ }
60081
+ if (receiveOperation.exact && receiveOperation.amount !== expectedSend.amount) {
60082
+ throw (new client_1.default('CLIENT_SWAP_SEND_AMOUNT_RECEIVE_EXACT_MISMATCH', 'Send value is not allowed to differ from expected receive amount for exact receives'));
60083
+ }
60084
+ sendAmount = expectedSend.amount;
60085
+ }
60086
+ }
60059
60087
  }
60060
- builder.send(request.block.account, receiveOperation.amount, receiveOperation.token);
60088
+ builder.send(request.block.account, sendAmount, receiveOperation.token);
60061
60089
  const blocks = await builder.computeBlocks();
60062
60090
  return ([...blocks.blocks, request.block]);
60063
60091
  }
@@ -62822,7 +62850,7 @@ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (
62822
62850
  var __importDefault = (this && this.__importDefault) || function (mod) {
62823
62851
  return (mod && mod.__esModule) ? mod : { "default": mod };
62824
62852
  };
62825
- var _Block_instances, _a, _Block_valueBytes, _Block_valueHash, _Block_getSortedRequiredSigners, _Block_validateOperationsPurpose, _Block_validateSignerField, _Block_validateSignatures, _BlockBuilder_block;
62853
+ var _Block_instances, _a, _Block_valueBytes, _Block_valueHash, _Block_getSortedRequiredSigners, _Block_validateBytes, _Block_validateOperationsPurpose, _Block_validateSignerField, _Block_validateSignatures, _BlockBuilder_block;
62826
62854
  Object.defineProperty(exports, "__esModule", ({ value: true }));
62827
62855
  exports.BlockBuilder = exports.Block = exports.BlockHash = exports.AdjustMethod = exports.BlockPurpose = void 0;
62828
62856
  exports.toAdjustMethod = toAdjustMethod;
@@ -63501,6 +63529,7 @@ class Block {
63501
63529
  if (this.account.isMultisig()) {
63502
63530
  throw (new block_1.default('BLOCK_NO_MULTISIG_OP', 'Cannot create a block for a multisig account'));
63503
63531
  }
63532
+ __classPrivateFieldGet(this, _Block_instances, "m", _Block_validateBytes).call(this);
63504
63533
  __classPrivateFieldGet(this, _Block_instances, "m", _Block_validateSignerField).call(this);
63505
63534
  __classPrivateFieldGet(this, _Block_instances, "m", _Block_validateOperationsPurpose).call(this);
63506
63535
  __classPrivateFieldGet(this, _Block_instances, "m", _Block_validateSignatures).call(this);
@@ -63508,9 +63537,11 @@ class Block {
63508
63537
  static getAccountOpeningHash(account) {
63509
63538
  return (BlockHash.getAccountOpeningHash(account));
63510
63539
  }
63511
- toBytes(includeSignatures = true) {
63512
- if (__classPrivateFieldGet(this, _Block_valueBytes, "f") !== undefined && includeSignatures) {
63513
- return (__classPrivateFieldGet(this, _Block_valueBytes, "f"));
63540
+ toBytes(includeSignatures = true, useCached = true) {
63541
+ if (useCached) {
63542
+ if (__classPrivateFieldGet(this, _Block_valueBytes, "f") !== undefined && includeSignatures) {
63543
+ return (__classPrivateFieldGet(this, _Block_valueBytes, "f"));
63544
+ }
63514
63545
  }
63515
63546
  const sharedBlockValues = {
63516
63547
  previous: this.previous,
@@ -63712,6 +63743,18 @@ _a = Block, _Block_valueBytes = new WeakMap(), _Block_valueHash = new WeakMap(),
63712
63743
  }
63713
63744
  }
63714
63745
  return (out);
63746
+ }, _Block_validateBytes = function _Block_validateBytes() {
63747
+ const existingBytes = __classPrivateFieldGet(this, _Block_valueBytes, "f");
63748
+ if (existingBytes === undefined) {
63749
+ return;
63750
+ }
63751
+ const recalculatedBytesBuffer = Buffer.from(this.toBytes(true, false));
63752
+ const existingBytesBuffer = Buffer.from(existingBytes);
63753
+ if (!recalculatedBytesBuffer.equals(existingBytesBuffer)) {
63754
+ const existingBytesHash = Buffer.from((0, hash_1.Hash)(existingBytesBuffer)).toString('hex').toUpperCase();
63755
+ const recalculatedBytesHash = Buffer.from((0, hash_1.Hash)(recalculatedBytesBuffer)).toString('hex').toUpperCase();
63756
+ throw (new block_1.default('BLOCK_INVALID_SIGNATURE', `Block signed bytes (${existingBytesHash}) do not match calculated bytes (${recalculatedBytesHash})`));
63757
+ }
63715
63758
  }, _Block_validateOperationsPurpose = function _Block_validateOperationsPurpose() {
63716
63759
  /**
63717
63760
  * Do not allow blocks to contain invalid constructions
@@ -63767,7 +63810,7 @@ _a = Block, _Block_valueBytes = new WeakMap(), _Block_valueHash = new WeakMap(),
63767
63810
  const signature = new buffer_1.BufferStorage(this.signatures[i], 64);
63768
63811
  const valid = signers[i].verify(this.hash.get(), signature.get());
63769
63812
  if (valid !== true) {
63770
- throw (new Error(`Unable to validate signature of ${this.hash.toString()} against signature ${this.signatures[i]} for account ${signers[i].publicKeyString.get()}`));
63813
+ throw (new block_1.default('BLOCK_INVALID_SIGNATURE', `Unable to validate signature of ${this.hash.toString()} against signature ${this.signatures[i].toString('hex')} for account ${signers[i].publicKeyString.get()}`));
63771
63814
  }
63772
63815
  }
63773
63816
  };
@@ -64354,7 +64397,11 @@ class BlockOperation {
64354
64397
  if (amount === undefined || amount === null) {
64355
64398
  throw (new Error('internal error: "amount" is invalid'));
64356
64399
  }
64357
- return (BigInt(amount));
64400
+ const bigintAmount = BigInt(amount);
64401
+ if (bigintAmount < 0n) {
64402
+ throw (new block_1.default('BLOCK_AMOUNT_BELOW_ZERO', 'value cannot be negative'));
64403
+ }
64404
+ return (bigintAmount);
64358
64405
  }
64359
64406
  }
64360
64407
  BlockOperation.isInstance = (0, helper_1.checkableGenerator)(BlockOperation);
@@ -64550,7 +64597,7 @@ class BlockOperationTOKEN_ADMIN_MODIFY_BALANCE extends BlockOperation {
64550
64597
  }
64551
64598
  __classPrivateFieldSet(this, _BlockOperationTOKEN_ADMIN_MODIFY_BALANCE_token, __classPrivateFieldGet(this, _BlockOperationTOKEN_ADMIN_MODIFY_BALANCE_instances, "m", _BlockOperationTOKEN_ADMIN_MODIFY_BALANCE_computeToken).call(this, input.token), "f");
64552
64599
  __classPrivateFieldSet(this, _BlockOperationTOKEN_ADMIN_MODIFY_BALANCE_amount, this.computeAmount(input.amount), "f");
64553
- __classPrivateFieldSet(this, _BlockOperationTOKEN_ADMIN_MODIFY_BALANCE_method, input.method, "f");
64600
+ __classPrivateFieldSet(this, _BlockOperationTOKEN_ADMIN_MODIFY_BALANCE_method, (0, _1.toAdjustMethod)(input.method), "f");
64554
64601
  }
64555
64602
  set token(token) {
64556
64603
  __classPrivateFieldSet(this, _BlockOperationTOKEN_ADMIN_MODIFY_BALANCE_token, __classPrivateFieldGet(this, _BlockOperationTOKEN_ADMIN_MODIFY_BALANCE_instances, "m", _BlockOperationTOKEN_ADMIN_MODIFY_BALANCE_computeToken).call(this, token), "f");
@@ -64559,7 +64606,7 @@ class BlockOperationTOKEN_ADMIN_MODIFY_BALANCE extends BlockOperation {
64559
64606
  return (__classPrivateFieldGet(this, _BlockOperationTOKEN_ADMIN_MODIFY_BALANCE_token, "f"));
64560
64607
  }
64561
64608
  set method(newMethod) {
64562
- __classPrivateFieldSet(this, _BlockOperationTOKEN_ADMIN_MODIFY_BALANCE_method, newMethod, "f");
64609
+ __classPrivateFieldSet(this, _BlockOperationTOKEN_ADMIN_MODIFY_BALANCE_method, (0, _1.toAdjustMethod)(newMethod), "f");
64563
64610
  }
64564
64611
  get method() {
64565
64612
  return (Number(__classPrivateFieldGet(this, _BlockOperationTOKEN_ADMIN_MODIFY_BALANCE_method, "f")));
@@ -64846,7 +64893,7 @@ class BlockOperationMODIFY_PERMISSIONS extends BlockOperation {
64846
64893
  }
64847
64894
  __classPrivateFieldSet(this, _BlockOperationMODIFY_PERMISSIONS_principal, this.computeTo(input.principal), "f");
64848
64895
  __classPrivateFieldSet(this, _BlockOperationMODIFY_PERMISSIONS_target, account_1.default.toAccount(input.target), "f");
64849
- __classPrivateFieldSet(this, _BlockOperationMODIFY_PERMISSIONS_method, input.method, "f");
64896
+ __classPrivateFieldSet(this, _BlockOperationMODIFY_PERMISSIONS_method, (0, _1.toAdjustMethod)(input.method), "f");
64850
64897
  __classPrivateFieldSet(this, _BlockOperationMODIFY_PERMISSIONS_permissions, __classPrivateFieldGet(this, _BlockOperationMODIFY_PERMISSIONS_instances, "m", _BlockOperationMODIFY_PERMISSIONS_computePermissions).call(this, input.permissions), "f");
64851
64898
  }
64852
64899
  set principal(principal) {
@@ -64868,7 +64915,7 @@ class BlockOperationMODIFY_PERMISSIONS extends BlockOperation {
64868
64915
  return (__classPrivateFieldGet(this, _BlockOperationMODIFY_PERMISSIONS_target, "f"));
64869
64916
  }
64870
64917
  set method(method) {
64871
- __classPrivateFieldSet(this, _BlockOperationMODIFY_PERMISSIONS_method, method, "f");
64918
+ __classPrivateFieldSet(this, _BlockOperationMODIFY_PERMISSIONS_method, (0, _1.toAdjustMethod)(method), "f");
64872
64919
  }
64873
64920
  get method() {
64874
64921
  return (Number(__classPrivateFieldGet(this, _BlockOperationMODIFY_PERMISSIONS_method, "f")));
@@ -65495,47 +65542,49 @@ const base_1 = __webpack_require__(1096);
65495
65542
  const helper_1 = __webpack_require__(3208);
65496
65543
  const BlockErrorType = 'BLOCK';
65497
65544
  exports.BlockErrorCodes = [
65498
- 'INVALID_TYPE',
65499
- 'INVALID_VERSION',
65500
- 'NO_MULTIPLE_SET_REP',
65501
- 'IDENTIFIER_NEED_DEFAULT_PERMISSIONS',
65545
+ 'AMOUNT_BELOW_ZERO',
65546
+ 'CANNOT_FORWARD_TO_SELF',
65502
65547
  'CANNOT_SEND_NON_TOKEN',
65503
- 'TOKEN_RECEIVE_DIFFERS',
65504
- 'ONLY_TOKEN_OP',
65505
- 'ONLY_IDENTIFIER_OP',
65506
- 'NO_TOKEN_OP',
65507
- 'NO_IDENTIFIER_OP',
65508
- 'INVALID_SIGNER',
65509
- 'INVALID_PURPOSE_VALIDATION',
65548
+ 'CERTIFICATE_SUBJECT_MISMATCH',
65549
+ 'EXACT_TRUE_WHEN_FORWARDING',
65550
+ 'EXTERNAL_INVALID',
65551
+ 'EXTERNAL_MISSING',
65552
+ 'EXTERNAL_TOO_LONG',
65553
+ 'GENERAL_FIELD_INVALID',
65554
+ 'IDENTIFIER_INVALID',
65555
+ 'IDENTIFIER_NEED_DEFAULT_PERMISSIONS',
65556
+ 'INTERMEDIATE_CERTIFICATES_ONLY_ADD',
65557
+ 'INVALID_ACCOUNT_TYPE',
65558
+ 'INVALID_CERTIFICATE_VALUE',
65559
+ 'INVALID_CREATE_IDENTIFIER_ARGS',
65560
+ 'INVALID_IDEMPOTENT_FORMAT',
65561
+ 'INVALID_IDEMPOTENT_LENGTH',
65510
65562
  'INVALID_MULTISIG_QUORUM',
65511
- 'INVALID_MULTISIG_SIGNER_DEPTH',
65512
65563
  'INVALID_MULTISIG_SIGNER_COUNT',
65564
+ 'INVALID_MULTISIG_SIGNER_DEPTH',
65513
65565
  'INVALID_MULTISIG_SIGNER_DUPLICATE',
65514
- 'INVALID_CREATE_IDENTIFIER_ARGS',
65566
+ 'INVALID_PURPOSE_VALIDATION',
65567
+ 'INVALID_SIGNATURE',
65568
+ 'INVALID_SIGNER',
65569
+ 'INVALID_TYPE',
65570
+ 'INVALID_VERSION',
65571
+ 'NO_ADMIN_ON_TARGET',
65572
+ 'NO_DELEGATE_ADMIN',
65573
+ 'NO_DUPLICATE_CERTIFICATE_OPERATION',
65574
+ 'NO_IDENTIFIER_OP',
65575
+ 'NO_MODIFY_PERMISSION_DUPE',
65576
+ 'NO_MULTIPLE_SET_REP',
65515
65577
  'NO_MULTISIG_OP',
65516
- 'IDENTIFIER_INVALID',
65517
- 'GENERAL_FIELD_INVALID',
65578
+ 'NO_TOKEN_OP',
65579
+ 'ONLY_IDENTIFIER_OP',
65580
+ 'ONLY_TOKEN_OP',
65518
65581
  'PERMISSIONS_INVALID_DEFAULT',
65519
65582
  'PERMISSIONS_INVALID_ENTITY',
65520
65583
  'PERMISSIONS_INVALID_PRINCIPAL',
65521
65584
  'PERMISSIONS_INVALID_TARGET',
65522
- 'INVALID_ACCOUNT_TYPE',
65523
- 'NO_ADMIN_ON_TARGET',
65524
65585
  'PREVIOUS_SELF',
65525
- 'NO_DELEGATE_ADMIN',
65526
- 'NO_MODIFY_PERMISSION_DUPE',
65527
- 'CANNOT_FORWARD_TO_SELF',
65528
- 'EXACT_TRUE_WHEN_FORWARDING',
65529
- 'CERTIFICATE_SUBJECT_MISMATCH',
65530
- 'NO_DUPLICATE_CERTIFICATE_OPERATION',
65531
- 'INTERMEDIATE_CERTIFICATES_ONLY_ADD',
65532
- 'INVALID_CERTIFICATE_VALUE',
65533
- 'EXTERNAL_TOO_LONG',
65534
- 'EXTERNAL_INVALID',
65535
- 'EXTERNAL_MISSING',
65536
65586
  'SUPPLY_INVALID',
65537
- 'INVALID_IDEMPOTENT_FORMAT',
65538
- 'INVALID_IDEMPOTENT_LENGTH'
65587
+ 'TOKEN_RECEIVE_DIFFERS'
65539
65588
  ];
65540
65589
  exports.FullBlockErrorCodes = exports.BlockErrorCodes.map(code => `${BlockErrorType}_${code}`);
65541
65590
  class KeetaNetBlockError extends base_1.KeetaNetErrorBase {
@@ -65611,6 +65660,9 @@ exports.ClientErrorCodes = [
65611
65660
  'SWAP_MISSING_RECEIVE',
65612
65661
  'SWAP_SEND_RECEIVE_ACCOUNT_MISMATCH',
65613
65662
  'SWAP_SEND_ACCOUNT_MISMATCH',
65663
+ 'SWAP_SEND_TOKEN_MISMATCH',
65664
+ 'SWAP_SEND_AMOUNT_TOO_LOW',
65665
+ 'SWAP_SEND_AMOUNT_RECEIVE_EXACT_MISMATCH',
65614
65666
  'SWAP_REQUEST_TOKEN_MISMATCH',
65615
65667
  'SWAP_REQUEST_AMOUNT_MISMATCH'
65616
65668
  ];
@@ -67334,6 +67386,9 @@ function updateAccountInfoInState(state, account, info) {
67334
67386
  * Compute the effect of a SEND operation
67335
67387
  */
67336
67388
  function computeEffectOfOperationSEND(state, block, operation) {
67389
+ if (operation.amount < 0n) {
67390
+ throw (new Error('Internal error: SEND operation with negative amount'));
67391
+ }
67337
67392
  // Decrement sender balance
67338
67393
  const senderChange = {
67339
67394
  state,
@@ -67361,6 +67416,9 @@ function computeEffectOfOperationSEND(state, block, operation) {
67361
67416
  * Compute the effect of a RECEIVE operation
67362
67417
  */
67363
67418
  function computeEffectOfOperationRECEIVE(state, block, operation) {
67419
+ if (operation.amount < 0n) {
67420
+ throw (new Error('Internal error: RECEIVE operation with negative amount'));
67421
+ }
67364
67422
  // Increment recipient balance
67365
67423
  const recipientChange = {
67366
67424
  state,
@@ -67396,6 +67454,9 @@ function computeEffectOfOperationRECEIVE(state, block, operation) {
67396
67454
  }
67397
67455
  }
67398
67456
  function computeEffectOfOperationTOKEN_ADMIN_MODIFY_BALANCE(state, block, operation) {
67457
+ if (operation.amount < 0n) {
67458
+ throw (new Error('Internal error: TOKEN_ADMIN_MODIFY_BALANCE operation with negative amount'));
67459
+ }
67399
67460
  if (operation.method === block_1.Block.AdjustMethod.SET) {
67400
67461
  const setChange = {
67401
67462
  state,
@@ -67465,6 +67526,9 @@ function computeEffectOfOperationCREATE_IDENTIFIER(state, block, operation, cont
67465
67526
  throw (new Error('Invalid identifier creation arguments'));
67466
67527
  }
67467
67528
  updateAccountInfoInState(state, operation.identifier, { multisigQuorum: operation.createArguments.quorum });
67529
+ if (operation.createArguments.quorum < 1n || operation.createArguments.quorum > BigInt(operation.createArguments.signers.length)) {
67530
+ throw (new Error('Internal error: operation.createArguments.quorum is invalid'));
67531
+ }
67468
67532
  for (const multisigSigner of operation.createArguments.signers) {
67469
67533
  state.possibleNewAccounts.add(multisigSigner);
67470
67534
  addPermission(state, {
@@ -67506,6 +67570,9 @@ function computeEffectOfOperationMODIFY_PERMISSIONS(state, block, operation) {
67506
67570
  });
67507
67571
  }
67508
67572
  function computeEffectOfOperationTOKEN_ADMIN_SUPPLY(state, block, operation) {
67573
+ if (operation.amount < 0n) {
67574
+ throw (new Error('Internal error: TOKEN_ADMIN_SUPPLY operation with negative amount'));
67575
+ }
67509
67576
  const tokenPubKey = block.account.publicKeyString.get();
67510
67577
  let value = 0n;
67511
67578
  switch (operation.method) {
@@ -69783,6 +69850,9 @@ class Log {
69783
69850
  * Register a new logging target (sink) to send logs to
69784
69851
  */
69785
69852
  registerTarget(target) {
69853
+ if (__classPrivateFieldGet(this, _Log_destroyed, "f")) {
69854
+ throw (new Error('Cannot register target on destroyed Log instance'));
69855
+ }
69786
69856
  // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
69787
69857
  const id = Symbol('LogTargetID');
69788
69858
  __classPrivateFieldGet(this, _Log_targets, "f").set(id, target);
@@ -69802,6 +69872,9 @@ class Log {
69802
69872
  * Unregister a logging target (sink) to stop sending logs to
69803
69873
  */
69804
69874
  unregisterTarget(id) {
69875
+ if (__classPrivateFieldGet(this, _Log_destroyed, "f")) {
69876
+ return;
69877
+ }
69805
69878
  __classPrivateFieldGet(this, _Log_targets, "f").delete(id);
69806
69879
  }
69807
69880
  /**
@@ -69816,6 +69889,9 @@ class Log {
69816
69889
  * Start a timer to periodically sync logs to all targets
69817
69890
  */
69818
69891
  startAutoSync(rate = 100) {
69892
+ if (__classPrivateFieldGet(this, _Log_destroyed, "f")) {
69893
+ throw (new Error('Cannot start auto sync on destroyed Log instance'));
69894
+ }
69819
69895
  this.stopAutoSync();
69820
69896
  __classPrivateFieldSet(this, _Log_autoSyncInterval, setInterval(async () => {
69821
69897
  try {
@@ -69887,6 +69963,9 @@ class Log {
69887
69963
  * Dispose of the logger instance, clearing all logs and targets
69888
69964
  */
69889
69965
  [(_Log_logs = new WeakMap(), _Log_autoSyncInterval = new WeakMap(), _Log_isSyncing = new WeakMap(), _Log_shouldSyncAgain = new WeakMap(), _Log_destroyed = new WeakMap(), _Log_emitOnLog = new WeakMap(), _Log_logDebugTracing = new WeakMap(), _Log_targets = new WeakMap(), _Log_instances = new WeakSet(), _Log_log = function _Log_log(level, options, from, ...args) {
69966
+ if (__classPrivateFieldGet(this, _Log_destroyed, "f")) {
69967
+ return;
69968
+ }
69890
69969
  const log = { options, level, from, args };
69891
69970
  if (__classPrivateFieldGet(this, _Log_logDebugTracing, "f")) {
69892
69971
  log.trace = new Error().stack?.split('\n').slice(2).join('\n') ?? '[No stack trace available]';
@@ -69911,6 +69990,14 @@ class Log {
69911
69990
  }, Symbol.dispose)]() {
69912
69991
  this.destroy();
69913
69992
  }
69993
+ /**
69994
+ * Dispose of the logger instance, syncing all logs, and clearing targets
69995
+ */
69996
+ async [Symbol.asyncDispose]() {
69997
+ __classPrivateFieldSet(this, _Log_destroyed, true, "f");
69998
+ await this.sync();
69999
+ this.destroy();
70000
+ }
69914
70001
  /**
69915
70002
  * Terminate the logger instance, clearing all logs and targets
69916
70003
  */
@@ -70288,7 +70375,12 @@ class RequestTiming {
70288
70375
  constructor() {
70289
70376
  _RequestTiming_timing.set(this, new Map());
70290
70377
  _RequestTiming_counter.set(this, 0);
70291
- this.log = RequestTiming.defaultLogger;
70378
+ if (RequestTiming.defaultLogger === '@legacy') {
70379
+ this.log = log_1.default.Legacy();
70380
+ }
70381
+ else {
70382
+ this.log = RequestTiming.defaultLogger;
70383
+ }
70292
70384
  }
70293
70385
  /**
70294
70386
  * Start timing a section of code
@@ -70303,12 +70395,17 @@ class RequestTiming {
70303
70395
  start: Date.now()
70304
70396
  };
70305
70397
  __classPrivateFieldGet(this, _RequestTiming_timing, "f").set(id, data);
70398
+ let endCalled = false;
70306
70399
  return ({
70307
- id,
70400
+ id: id,
70308
70401
  end: () => {
70402
+ endCalled = true;
70309
70403
  this.endTime(id);
70310
70404
  },
70311
70405
  [Symbol.dispose]: () => {
70406
+ if (endCalled) {
70407
+ return;
70408
+ }
70312
70409
  this.endTime(id);
70313
70410
  }
70314
70411
  });
@@ -70323,11 +70420,11 @@ class RequestTiming {
70323
70420
  if (typeof section === 'symbol') {
70324
70421
  const timingInfo = __classPrivateFieldGet(this, _RequestTiming_timing, "f").get(section);
70325
70422
  if (timingInfo === undefined) {
70326
- this.log.error(`Timing section ${String(section)} does not exist but "end" was called on it!`);
70423
+ this.log.error('timing::endTime', `Timing section ${String(section)} does not exist but "end" was called on it!`);
70327
70424
  return;
70328
70425
  }
70329
70426
  if (timingInfo.end !== undefined) {
70330
- this.log.error(`Timing section ${timingInfo.id} already ended but "end" was called on it again!`);
70427
+ this.log.error('timing::endTime', `Timing section ${timingInfo.id} already ended but "end" was called on it again!`);
70331
70428
  return;
70332
70429
  }
70333
70430
  timingInfo.end = Date.now();
@@ -70425,7 +70522,7 @@ class RequestTiming {
70425
70522
  }
70426
70523
  exports.RequestTiming = RequestTiming;
70427
70524
  _RequestTiming_timing = new WeakMap(), _RequestTiming_counter = new WeakMap();
70428
- RequestTiming.defaultLogger = log_1.default.Legacy();
70525
+ RequestTiming.defaultLogger = '@legacy';
70429
70526
  exports["default"] = RequestTiming;
70430
70527
 
70431
70528
 
@@ -74006,7 +74103,8 @@ exports.ASN1BigIntToBuffer = ASN1BigIntToBuffer;
74006
74103
  * - {@link ValidateASN1.IsNull}
74007
74104
  *
74008
74105
  * More complex types are defined as:
74009
- * - Choice: `{ choice: [ schema1, schema2, ... ] }`
74106
+ * - Choice (named): `{ choice: { name1: schema1, name2: schema2, ... } }` - Converts to `{ name1: value }` or `{ name2: value }`
74107
+ * - Choice (legacy array): `{ choice: [ schema1, schema2, ... ] }` - Converts to union type (ambiguous for re-encoding)
74010
74108
  * - Sequence of: `{ sequenceOf: schema }`
74011
74109
  * - Optional: `{ optional: schema }`
74012
74110
  * - Context Tag: `{ type: 'context'; kind: 'implicit' | 'explicit'; contains: schema; value: number }`
@@ -74330,6 +74428,7 @@ class ValidateASN1 {
74330
74428
  case 'struct': {
74331
74429
  const outputStruct = {
74332
74430
  type: 'struct',
74431
+ // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
74333
74432
  fieldNames: schema.fieldNames,
74334
74433
  contains: {}
74335
74434
  };
@@ -74362,6 +74461,47 @@ class ValidateASN1 {
74362
74461
  }
74363
74462
  }
74364
74463
  else if ('choice' in schema) {
74464
+ // Handle named choices: { choice: { a: schema1, b: schema2 } }
74465
+ if (!Array.isArray(schema.choice)) {
74466
+ // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
74467
+ const choiceObj = schema.choice;
74468
+ // For context tags, match by value and kind
74469
+ if (isASN1ContextTag(input)) {
74470
+ const inputAsChoice = input;
74471
+ for (const choiceName in choiceObj) {
74472
+ const choice = choiceObj[choiceName];
74473
+ if (choice === undefined) {
74474
+ continue;
74475
+ }
74476
+ if (!isASN1ContextTag(choice)) {
74477
+ continue;
74478
+ }
74479
+ if (choice.value !== inputAsChoice.value) {
74480
+ continue;
74481
+ }
74482
+ if (choice.kind !== inputAsChoice.kind) {
74483
+ continue;
74484
+ }
74485
+ return (ValidateASN1.againstSchema(input, choice));
74486
+ }
74487
+ throw (new Error('No valid choice found'));
74488
+ }
74489
+ // Try each choice
74490
+ for (const choiceName in choiceObj) {
74491
+ const choice = choiceObj[choiceName];
74492
+ if (choice === undefined) {
74493
+ continue;
74494
+ }
74495
+ try {
74496
+ return (ValidateASN1.againstSchema(input, choice));
74497
+ }
74498
+ catch (_ignored_checkError) {
74499
+ /* Ignored error */
74500
+ }
74501
+ }
74502
+ throw (new Error('No valid choice found'));
74503
+ }
74504
+ // Handle array choices (legacy)
74365
74505
  if (isASN1ContextTag(input)) {
74366
74506
  const inputAsChoice = input;
74367
74507
  const matchingSchema = schema.choice.find(function (choice) {
@@ -74383,7 +74523,6 @@ class ValidateASN1 {
74383
74523
  }
74384
74524
  for (const choice of schema.choice) {
74385
74525
  try {
74386
- // @ts-ignore
74387
74526
  return (ValidateASN1.againstSchema(input, choice));
74388
74527
  }
74389
74528
  catch (_ignored_checkError) {
@@ -74472,6 +74611,499 @@ class ValidateASN1 {
74472
74611
  validate(input) {
74473
74612
  return (ValidateASN1.againstSchema(input, __classPrivateFieldGet(this, _ValidateASN1_schema, "f")));
74474
74613
  }
74614
+ /**
74615
+ * Convert an ASN.1 object to a JavaScript object (including primitives)
74616
+ * based on the schema.
74617
+ *
74618
+ * Converts ASN1 objects to plain JavaScript objects according to the schema:
74619
+ * - Structs are converted to plain objects with field names as keys
74620
+ * - For ambiguous types (IsAnyString, IsAnyDate), returns ASN.1-like objects: { type: 'string', kind: 'utf8', value: 'text' }
74621
+ * - Arrays/sequences are preserved as arrays
74622
+ * - Primitive types (bigint, string, boolean, null, Buffer, Date) are preserved
74623
+ *
74624
+ * Example schema: { type: 'struct', fieldNames: ['name', 'age'], contains: { name: ValidateASN1.IsAnyString, age: ValidateASN1.IsInteger } }
74625
+ * Input: { type: 'struct', fieldNames: ['name', 'age'], contains: { name: { type: 'string', kind: 'utf8', value: 'John Doe' }, age: 30n } }
74626
+ * Output: { name: { type: 'string', kind: 'utf8', value: 'John Doe' }, age: 30n }
74627
+ */
74628
+ toJavaScriptObject(input) {
74629
+ this.validate(input);
74630
+ // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
74631
+ return ValidateASN1.toPlainObject(input, __classPrivateFieldGet(this, _ValidateASN1_schema, "f"));
74632
+ }
74633
+ /**
74634
+ * Convert a plain JavaScript object back to an ASN.1 object based on the schema.
74635
+ *
74636
+ * Converts plain JavaScript objects back to ASN1 representation according to the schema:
74637
+ * - Plain objects with field names are converted to ASN1Struct
74638
+ * - For ambiguous schemas, recognizes ASN.1-like objects: { type: 'string', kind: 'utf8', value: 'text' }
74639
+ * - Arrays are preserved as sequences
74640
+ * - Primitive types are preserved or wrapped in appropriate ASN1 types
74641
+ *
74642
+ * Example schema: { type: 'struct', fieldNames: ['name', 'age'], contains: { name: ValidateASN1.IsAnyString, age: ValidateASN1.IsInteger } }
74643
+ * Input: { name: { type: 'string', kind: 'utf8', value: 'John Doe' }, age: 30n }
74644
+ * Output: { type: 'struct', fieldNames: ['name', 'age'], contains: { name: { type: 'string', kind: 'utf8', value: 'John Doe' }, age: 30n } }
74645
+ */
74646
+ fromJavaScriptObject(input) {
74647
+ const retval = ValidateASN1.fromPlainObject(input, __classPrivateFieldGet(this, _ValidateASN1_schema, "f"));
74648
+ this.validate(retval);
74649
+ return (retval);
74650
+ }
74651
+ /**
74652
+ * Convert an ASN.1 object to a plain JavaScript object based on a schema
74653
+ */
74654
+ static toPlainObject(input, schemaIn) {
74655
+ let schema = schemaIn;
74656
+ if (typeof schema === 'function') {
74657
+ schema = schema();
74658
+ }
74659
+ // Handle choice schemas first (before primitive checks)
74660
+ // This ensures named choices wrap their values correctly
74661
+ if (typeof schema === 'object' && schema !== null && 'choice' in schema) {
74662
+ // Handle named choices: { choice: { a: schema1, b: schema2 } }
74663
+ if (!Array.isArray(schema.choice)) {
74664
+ // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
74665
+ const choiceObj = schema.choice;
74666
+ for (const choiceName in choiceObj) {
74667
+ const choiceSchema = choiceObj[choiceName];
74668
+ if (choiceSchema === undefined) {
74669
+ continue;
74670
+ }
74671
+ try {
74672
+ // Validate that the input matches this choice schema
74673
+ ValidateASN1.againstSchema(input, choiceSchema);
74674
+ // If validation passes, convert and wrap in named object
74675
+ const converted = ValidateASN1.toPlainObject(input, choiceSchema);
74676
+ return ({ [choiceName]: converted });
74677
+ }
74678
+ catch {
74679
+ // Try next choice
74680
+ }
74681
+ }
74682
+ throw (new Error('No valid choice found'));
74683
+ }
74684
+ // Handle array choices (legacy): { choice: [schema1, schema2] }
74685
+ // For choices, recursively convert the selected choice
74686
+ for (const choice of schema.choice) {
74687
+ try {
74688
+ return (ValidateASN1.toPlainObject(input, choice));
74689
+ }
74690
+ catch {
74691
+ // Try next choice
74692
+ }
74693
+ }
74694
+ throw (new Error('No valid choice found'));
74695
+ }
74696
+ // Handle primitives that don't need conversion
74697
+ if (typeof input === 'bigint' || typeof input === 'boolean' || input === null || (0, helper_1.isBuffer)(input) || util_1.types.isDate(input)) {
74698
+ return (input);
74699
+ }
74700
+ // Handle plain strings
74701
+ if (typeof input === 'string') {
74702
+ return (input);
74703
+ }
74704
+ // Handle basic schema types
74705
+ if (typeof schema === 'symbol') {
74706
+ switch (schema) {
74707
+ case ValidateASN1.IsInteger:
74708
+ case ValidateASN1.IsBoolean:
74709
+ case ValidateASN1.IsNull:
74710
+ case ValidateASN1.IsOctetString:
74711
+ case ValidateASN1.IsString:
74712
+ case ValidateASN1.IsDate:
74713
+ return (input);
74714
+ case ValidateASN1.IsAnyString:
74715
+ if (isASN1String(input)) {
74716
+ // For ambiguous schemas, return ASN.1-like object
74717
+ return ({ type: 'string', kind: input.kind, value: input.value });
74718
+ }
74719
+ return (input);
74720
+ case ValidateASN1.IsAnyDate:
74721
+ if (isASN1Date(input)) {
74722
+ // For ambiguous schemas, return ASN.1-like object
74723
+ return ({ type: 'date', kind: input.kind, value: input.date });
74724
+ }
74725
+ return (input);
74726
+ case ValidateASN1.IsBitString:
74727
+ if (isASN1BitString(input)) {
74728
+ // Use expanded form to preserve unusedBits information
74729
+ // This distinguishes between bit strings like 111 and 0111
74730
+ return ({ type: 'bitstring', value: input.value, unusedBits: input.unusedBits });
74731
+ }
74732
+ return (input);
74733
+ case ValidateASN1.IsOID:
74734
+ if (isASN1OID(input)) {
74735
+ return (input.oid);
74736
+ }
74737
+ return (input);
74738
+ case ValidateASN1.IsSet:
74739
+ return (input);
74740
+ case ValidateASN1.IsAny:
74741
+ case ValidateASN1.IsUnknown:
74742
+ return (input);
74743
+ }
74744
+ }
74745
+ // Handle bigint schema (fixed value)
74746
+ if (typeof schema === 'bigint') {
74747
+ return (input);
74748
+ }
74749
+ // Handle object schemas
74750
+ if (typeof schema === 'object' && schema !== null) {
74751
+ if ('type' in schema) {
74752
+ switch (schema.type) {
74753
+ case 'struct': {
74754
+ if (!isASN1Struct(input)) {
74755
+ throw (new Error('Expected ASN1Struct'));
74756
+ }
74757
+ const result = {};
74758
+ for (const fieldName of schema.fieldNames) {
74759
+ const fieldValue = input.contains[fieldName];
74760
+ if (fieldValue === undefined) {
74761
+ continue;
74762
+ }
74763
+ const fieldSchema = schema.contains[fieldName];
74764
+ if (isASN1ContextTag(fieldValue)) {
74765
+ // Context tags are metadata like optional - unwrap them completely
74766
+ // Need to unwrap optional and get the context tag schema
74767
+ let contextSchema = fieldSchema;
74768
+ if (typeof contextSchema === 'object' && contextSchema !== null && 'optional' in contextSchema) {
74769
+ contextSchema = contextSchema.optional;
74770
+ }
74771
+ // For implicit context tags with ArrayBuffer, can't convert further
74772
+ if (fieldValue.kind === 'implicit' && util_1.types.isArrayBuffer(fieldValue.contains)) {
74773
+ result[fieldName] = fieldValue.contains;
74774
+ }
74775
+ else if (typeof contextSchema === 'object' && contextSchema !== null && 'type' in contextSchema && contextSchema.type === 'context' && 'contains' in contextSchema) {
74776
+ // Unwrap the context tag - just convert the inner value
74777
+ // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
74778
+ result[fieldName] = ValidateASN1.toPlainObject(fieldValue.contains, contextSchema.contains);
74779
+ }
74780
+ else {
74781
+ // Fallback: convert the inner value with full field schema
74782
+ // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
74783
+ result[fieldName] = ValidateASN1.toPlainObject(fieldValue.contains, fieldSchema);
74784
+ }
74785
+ }
74786
+ else {
74787
+ // For all other types (including strings and dates), recursively convert
74788
+ const plainValue = ValidateASN1.toPlainObject(fieldValue, fieldSchema);
74789
+ result[fieldName] = plainValue;
74790
+ }
74791
+ }
74792
+ return (result);
74793
+ }
74794
+ case 'string':
74795
+ if (isASN1String(input)) {
74796
+ return (input.value);
74797
+ }
74798
+ return (input);
74799
+ case 'date':
74800
+ if (isASN1Date(input)) {
74801
+ return (input.date);
74802
+ }
74803
+ return (input);
74804
+ case 'oid':
74805
+ if (isASN1OID(input)) {
74806
+ return (input.oid);
74807
+ }
74808
+ return (input);
74809
+ case 'context':
74810
+ if (isASN1ContextTag(input)) {
74811
+ // For implicit context tags with ArrayBuffer, we can't convert further
74812
+ if (input.kind === 'implicit' && util_1.types.isArrayBuffer(input.contains)) {
74813
+ return (input.contains);
74814
+ }
74815
+ // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
74816
+ return (ValidateASN1.toPlainObject(input.contains, schema.contains));
74817
+ }
74818
+ return (input);
74819
+ }
74820
+ }
74821
+ if ('sequenceOf' in schema) {
74822
+ if (!Array.isArray(input)) {
74823
+ throw (new Error('Expected array for sequenceOf'));
74824
+ }
74825
+ return (input.map(item => ValidateASN1.toPlainObject(item, schema.sequenceOf)));
74826
+ }
74827
+ if ('optional' in schema) {
74828
+ if (input === undefined) {
74829
+ return (undefined);
74830
+ }
74831
+ return (ValidateASN1.toPlainObject(input, schema.optional));
74832
+ }
74833
+ if (Array.isArray(schema)) {
74834
+ if (!Array.isArray(input)) {
74835
+ throw (new Error('Expected array'));
74836
+ }
74837
+ const result = [];
74838
+ for (let i = 0; i < Math.min(input.length, schema.length); i++) {
74839
+ const item = input[i];
74840
+ if (item === undefined) {
74841
+ result.push(undefined);
74842
+ }
74843
+ else {
74844
+ result.push(ValidateASN1.toPlainObject(item, schema[i]));
74845
+ }
74846
+ }
74847
+ return (result);
74848
+ }
74849
+ }
74850
+ return (input);
74851
+ }
74852
+ /**
74853
+ * Convert a plain JavaScript object to an ASN.1 object based on a schema
74854
+ */
74855
+ static fromPlainObject(input, schemaIn) {
74856
+ let schema = schemaIn;
74857
+ if (typeof schema === 'function') {
74858
+ schema = schema();
74859
+ }
74860
+ // Handle null/undefined
74861
+ if (input === null || input === undefined) {
74862
+ /* Verify that the schema for this is actually is nullable */
74863
+ let nullable = false;
74864
+ if (schema === ValidateASN1.IsNull) {
74865
+ nullable = true;
74866
+ }
74867
+ else if (typeof schema === 'object' && schema !== null) {
74868
+ if ('optional' in schema) {
74869
+ nullable = true;
74870
+ }
74871
+ }
74872
+ if (!nullable) {
74873
+ throw (new Error(`Expected non-null value, got ${input}`));
74874
+ }
74875
+ // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
74876
+ return input;
74877
+ }
74878
+ // For ambiguous schemas (IsAnyString, IsAnyDate), check if input is already in ASN.1-like format
74879
+ // These are objects like { type: 'string', kind: 'utf8', value: 'text' } or { type: 'date', kind: 'general', value: Date }
74880
+ // Also handle expanded bitstring format: { type: 'bitstring', value: Buffer, unusedBits: number }
74881
+ if (typeof input === 'object' && input !== null && !(0, helper_1.isBuffer)(input) && !util_1.types.isDate(input) && !Array.isArray(input)) {
74882
+ // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
74883
+ const inputObj = input;
74884
+ // Check for string-like format: { type: 'string', kind, value }
74885
+ if (inputObj.type === 'string' && typeof inputObj.kind === 'string' && 'value' in inputObj) {
74886
+ const kind = inputObj.kind;
74887
+ if (kind === 'printable' || kind === 'ia5' || kind === 'utf8') {
74888
+ if (typeof inputObj.value === 'string') {
74889
+ return ({ type: 'string', kind, value: inputObj.value });
74890
+ }
74891
+ }
74892
+ }
74893
+ // Check for date-like format: { type: 'date', kind, value }
74894
+ if (inputObj.type === 'date' && typeof inputObj.kind === 'string' && 'value' in inputObj) {
74895
+ const kind = inputObj.kind;
74896
+ if (kind === 'utc' || kind === 'general') {
74897
+ if (util_1.types.isDate(inputObj.value)) {
74898
+ return ({ type: 'date', kind, date: inputObj.value });
74899
+ }
74900
+ }
74901
+ }
74902
+ // Check for bitstring format: { type: 'bitstring', value, unusedBits }
74903
+ if (inputObj.type === 'bitstring' && 'value' in inputObj && 'unusedBits' in inputObj) {
74904
+ if ((0, helper_1.isBuffer)(inputObj.value) && typeof inputObj.unusedBits === 'number') {
74905
+ return ({ type: 'bitstring', value: inputObj.value, unusedBits: inputObj.unusedBits });
74906
+ }
74907
+ }
74908
+ }
74909
+ // Check schema FIRST before doing any primitive handling
74910
+ // This is important for context tags and other wrappers
74911
+ // Handle object schemas
74912
+ if (typeof schema === 'object' && schema !== null) {
74913
+ if ('type' in schema) {
74914
+ switch (schema.type) {
74915
+ case 'context': {
74916
+ // Context tags: reconstruct from schema definition (metadata like optional)
74917
+ // Schema has the kind and value, input is the plain value
74918
+ // At this point we know schema.type === 'context', so it must have kind, value, contains
74919
+ // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
74920
+ const contextTagSchema = schema;
74921
+ return ({
74922
+ type: 'context',
74923
+ kind: contextTagSchema.kind,
74924
+ value: contextTagSchema.value,
74925
+ contains: ValidateASN1.fromPlainObject(input, contextTagSchema.contains)
74926
+ });
74927
+ }
74928
+ case 'struct': {
74929
+ if (typeof input !== 'object' || input === null) {
74930
+ throw (new Error('Expected object for struct'));
74931
+ }
74932
+ // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
74933
+ const inputObj = input;
74934
+ const result = {
74935
+ type: 'struct',
74936
+ // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
74937
+ fieldNames: schema.fieldNames,
74938
+ contains: {}
74939
+ };
74940
+ for (const fieldName of schema.fieldNames) {
74941
+ const fieldValue = inputObj[fieldName];
74942
+ if (fieldValue === undefined) {
74943
+ continue;
74944
+ }
74945
+ const fieldSchema = schema.contains[fieldName];
74946
+ result.contains[fieldName] = ValidateASN1.fromPlainObject(fieldValue, fieldSchema);
74947
+ }
74948
+ return (result);
74949
+ }
74950
+ case 'string':
74951
+ if (typeof input === 'string') {
74952
+ return ({ type: 'string', kind: schema.kind, value: input });
74953
+ }
74954
+ // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
74955
+ return input;
74956
+ case 'date':
74957
+ if (util_1.types.isDate(input)) {
74958
+ return ({ type: 'date', kind: schema.kind, date: input });
74959
+ }
74960
+ // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
74961
+ return input;
74962
+ case 'oid':
74963
+ if (typeof input === 'string') {
74964
+ return ({ type: 'oid', oid: input });
74965
+ }
74966
+ // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
74967
+ return input;
74968
+ }
74969
+ }
74970
+ if ('choice' in schema) {
74971
+ // Handle named choices: { choice: { a: schema1, b: schema2 } }
74972
+ if (!Array.isArray(schema.choice)) {
74973
+ if (typeof input === 'object' && input !== null && !(0, helper_1.isBuffer)(input) && !util_1.types.isDate(input)) {
74974
+ // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
74975
+ const inputObj = input;
74976
+ // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
74977
+ const choiceObj = schema.choice;
74978
+ // Find which choice name is present in the input
74979
+ for (const choiceName in choiceObj) {
74980
+ if (choiceName in inputObj) {
74981
+ const choiceSchema = choiceObj[choiceName];
74982
+ if (choiceSchema === undefined) {
74983
+ continue;
74984
+ }
74985
+ const choiceValue = inputObj[choiceName];
74986
+ return (ValidateASN1.fromPlainObject(choiceValue, choiceSchema));
74987
+ }
74988
+ }
74989
+ }
74990
+ throw (new Error('No valid choice found for input - expected object with one of: ' + Object.keys(schema.choice).join(', ')));
74991
+ }
74992
+ // Handle array choices (legacy): { choice: [schema1, schema2] }
74993
+ // For choices, try to convert with each choice schema
74994
+ for (const choice of schema.choice) {
74995
+ try {
74996
+ return (ValidateASN1.fromPlainObject(input, choice));
74997
+ }
74998
+ catch {
74999
+ // Try next choice
75000
+ }
75001
+ }
75002
+ throw (new Error('No valid choice found for input'));
75003
+ }
75004
+ if ('sequenceOf' in schema) {
75005
+ if (!Array.isArray(input)) {
75006
+ throw (new Error('Expected array for sequenceOf'));
75007
+ }
75008
+ return (input.map(item => ValidateASN1.fromPlainObject(item, schema.sequenceOf)));
75009
+ }
75010
+ if ('optional' in schema) {
75011
+ return (ValidateASN1.fromPlainObject(input, schema.optional));
75012
+ }
75013
+ if (Array.isArray(schema)) {
75014
+ if (!Array.isArray(input)) {
75015
+ throw (new Error('Expected array'));
75016
+ }
75017
+ const result = [];
75018
+ for (let i = 0; i < schema.length; i++) {
75019
+ if (i < input.length && input[i] !== undefined) {
75020
+ result.push(ValidateASN1.fromPlainObject(input[i], schema[i]));
75021
+ }
75022
+ else if (isASN1ModifierOptional(schema[i])) {
75023
+ result.push(undefined);
75024
+ }
75025
+ else {
75026
+ throw (new Error(`Missing required field at index ${i}`));
75027
+ }
75028
+ }
75029
+ return (result);
75030
+ }
75031
+ }
75032
+ // Handle symbol schemas (basic types)
75033
+ if (typeof schema === 'symbol') {
75034
+ switch (schema) {
75035
+ case ValidateASN1.IsInteger:
75036
+ case ValidateASN1.IsBoolean:
75037
+ case ValidateASN1.IsNull:
75038
+ case ValidateASN1.IsDate:
75039
+ // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
75040
+ return input;
75041
+ case ValidateASN1.IsOctetString:
75042
+ // OctetString can accept a Buffer directly
75043
+ if ((0, helper_1.isBuffer)(input)) {
75044
+ return (input);
75045
+ }
75046
+ // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
75047
+ return input;
75048
+ case ValidateASN1.IsString:
75049
+ if (typeof input === 'string') {
75050
+ return (input);
75051
+ }
75052
+ throw (new Error('Expected string'));
75053
+ case ValidateASN1.IsAnyString:
75054
+ if (typeof input === 'string') {
75055
+ // Determine appropriate string kind
75056
+ if (isStringValidForKind(input, 'printable')) {
75057
+ return ({ type: 'string', kind: 'printable', value: input });
75058
+ }
75059
+ else if (isStringValidForKind(input, 'ia5')) {
75060
+ return ({ type: 'string', kind: 'ia5', value: input });
75061
+ }
75062
+ else {
75063
+ return ({ type: 'string', kind: 'utf8', value: input });
75064
+ }
75065
+ }
75066
+ // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
75067
+ return input;
75068
+ case ValidateASN1.IsAnyDate:
75069
+ if (util_1.types.isDate(input)) {
75070
+ if (input.getUTCFullYear() < 2050) {
75071
+ return ({ type: 'date', kind: 'utc', date: input });
75072
+ }
75073
+ else {
75074
+ return ({ type: 'date', kind: 'general', date: input });
75075
+ }
75076
+ }
75077
+ // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
75078
+ return input;
75079
+ case ValidateASN1.IsBitString:
75080
+ if ((0, helper_1.isBuffer)(input)) {
75081
+ return ({ type: 'bitstring', value: input, unusedBits: 0 });
75082
+ }
75083
+ // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
75084
+ return input;
75085
+ case ValidateASN1.IsOID:
75086
+ if (typeof input === 'string') {
75087
+ return ({ type: 'oid', oid: input });
75088
+ }
75089
+ // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
75090
+ return input;
75091
+ case ValidateASN1.IsSet:
75092
+ case ValidateASN1.IsAny:
75093
+ case ValidateASN1.IsUnknown:
75094
+ // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
75095
+ return input;
75096
+ }
75097
+ }
75098
+ // Handle bigint schema (fixed value)
75099
+ if (typeof schema === 'bigint') {
75100
+ // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
75101
+ return input;
75102
+ }
75103
+ // Default: return input as-is
75104
+ // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
75105
+ return input;
75106
+ }
74475
75107
  }
74476
75108
  exports.ValidateASN1 = ValidateASN1;
74477
75109
  _ValidateASN1_schema = new WeakMap();
@@ -79134,7 +79766,7 @@ exports.Testing = { findRDN, blockHashesFromVote, feeFromVote };
79134
79766
 
79135
79767
  Object.defineProperty(exports, "__esModule", ({ value: true }));
79136
79768
  exports.version = void 0;
79137
- exports.version = '0.14.11+gfb27e304d06f586fd5f3532fae4f1504a46d359b';
79769
+ exports.version = '0.14.13+g566b8de2c01660608e6eb5257113db271d7fc075';
79138
79770
  exports["default"] = exports.version;
79139
79771
 
79140
79772