@keetanetwork/keetanet-client 0.14.12 → 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 (121) hide show
  1. package/client/index-browser.d.ts +35 -3
  2. package/client/index-browser.js +96 -26
  3. package/client/index.d.ts +35 -3
  4. package/client/index.js +116 -49
  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.PermissionSetHolder.html +1 -1
  48. package/docs/classes/KeetaNetSDK.Referenced.PossiblyExpiredVote.html +1 -1
  49. package/docs/classes/KeetaNetSDK.Referenced.SignatureStorage.html +1 -1
  50. package/docs/classes/KeetaNetSDK.Referenced.Stats.html +1 -1
  51. package/docs/classes/KeetaNetSDK.Referenced.StatsPending.html +1 -1
  52. package/docs/classes/KeetaNetSDK.Referenced.VoteBlockBundle.html +1 -1
  53. package/docs/classes/KeetaNetSDK.Referenced.VoteBlockHash.html +1 -1
  54. package/docs/classes/KeetaNetSDK.Referenced.VoteBuilder.html +1 -1
  55. package/docs/classes/KeetaNetSDK.Referenced.VoteHash.html +1 -1
  56. package/docs/classes/KeetaNetSDK.Referenced.VoteLikeBase.html +1 -1
  57. package/docs/classes/KeetaNetSDK.Referenced.VoteQuoteBuilder.html +1 -1
  58. package/docs/classes/KeetaNetSDK.Referenced.VoteStapleHash.html +1 -1
  59. package/docs/classes/KeetaNetSDK.Referenced.src_lib_utils_buffer.BufferStorage.html +1 -1
  60. package/docs/hierarchy.html +1 -1
  61. package/docs/interfaces/KeetaNetSDK.Referenced.ACLEntry.html +1 -1
  62. package/docs/interfaces/KeetaNetSDK.Referenced.ACLUpdate.html +1 -1
  63. package/docs/interfaces/KeetaNetSDK.Referenced.ASN1ExplicitContextTag.html +1 -1
  64. package/docs/interfaces/KeetaNetSDK.Referenced.ASN1ImplicitContextTag.html +1 -1
  65. package/docs/interfaces/KeetaNetSDK.Referenced.ASN1Object.html +1 -1
  66. package/docs/interfaces/KeetaNetSDK.Referenced.AcceptSwapRequest.html +7 -2
  67. package/docs/interfaces/KeetaNetSDK.Referenced.BaseExternalKeyPairFunctions.html +1 -1
  68. package/docs/interfaces/KeetaNetSDK.Referenced.BaseGenerationConfig.html +1 -1
  69. package/docs/interfaces/KeetaNetSDK.Referenced.BaseIdentifierCreateArguments.html +1 -1
  70. package/docs/interfaces/KeetaNetSDK.Referenced.BlockJSONOperation.html +1 -1
  71. package/docs/interfaces/KeetaNetSDK.Referenced.BlockJSONOperationCREATE_IDENTIFIER.html +1 -1
  72. package/docs/interfaces/KeetaNetSDK.Referenced.BlockJSONOperationMANAGE_CERTIFICATE.html +1 -1
  73. package/docs/interfaces/KeetaNetSDK.Referenced.BlockJSONOperationMANAGE_CERTIFICATESerializable.html +1 -1
  74. package/docs/interfaces/KeetaNetSDK.Referenced.BlockJSONOperationMODIFY_PERMISSIONS.html +1 -1
  75. package/docs/interfaces/KeetaNetSDK.Referenced.BlockJSONOperationRECEIVE.html +1 -1
  76. package/docs/interfaces/KeetaNetSDK.Referenced.BlockJSONOperationSEND.html +1 -1
  77. package/docs/interfaces/KeetaNetSDK.Referenced.BlockJSONOperationSET_INFO.html +1 -1
  78. package/docs/interfaces/KeetaNetSDK.Referenced.BlockJSONOperationSET_REP.html +1 -1
  79. package/docs/interfaces/KeetaNetSDK.Referenced.BlockJSONOperationTOKEN_ADMIN_MODIFY_BALANCE.html +1 -1
  80. package/docs/interfaces/KeetaNetSDK.Referenced.BlockJSONOperationTOKEN_ADMIN_SUPPLY.html +1 -1
  81. package/docs/interfaces/KeetaNetSDK.Referenced.BlockV1Canonical.html +1 -1
  82. package/docs/interfaces/KeetaNetSDK.Referenced.BlockV2Canonical.html +1 -1
  83. package/docs/interfaces/KeetaNetSDK.Referenced.Constructor.html +1 -1
  84. package/docs/interfaces/KeetaNetSDK.Referenced.CreateSwapRequest.html +3 -2
  85. package/docs/interfaces/KeetaNetSDK.Referenced.DisposableTimingHandle.html +1 -1
  86. package/docs/interfaces/KeetaNetSDK.Referenced.ExternalKeyPairFunctionsNoEncryption.html +1 -1
  87. package/docs/interfaces/KeetaNetSDK.Referenced.ExternalKeyPairFunctionsSupportsEncryption.html +1 -1
  88. package/docs/interfaces/KeetaNetSDK.Referenced.InitialConfigSupply.html +1 -1
  89. package/docs/interfaces/KeetaNetSDK.Referenced.InstanceSet.html +1 -1
  90. package/docs/interfaces/KeetaNetSDK.Referenced.KVGenericOptionsType.html +1 -1
  91. package/docs/interfaces/KeetaNetSDK.Referenced.KVSetOptionsType.html +1 -1
  92. package/docs/interfaces/KeetaNetSDK.Referenced.ModifyTokenBalanceEntry.html +1 -1
  93. package/docs/interfaces/KeetaNetSDK.Referenced.MultiSigIdentifierCreateArguments.html +1 -1
  94. package/docs/interfaces/KeetaNetSDK.Referenced.MultisigConfig.html +1 -1
  95. package/docs/interfaces/KeetaNetSDK.Referenced.NumericValueEntry.html +1 -1
  96. package/docs/interfaces/KeetaNetSDK.Referenced.P2PPeerBase.html +1 -1
  97. package/docs/interfaces/KeetaNetSDK.Referenced.P2PPeerListener.html +1 -1
  98. package/docs/interfaces/KeetaNetSDK.Referenced.P2PPeerRepBase.html +1 -1
  99. package/docs/interfaces/KeetaNetSDK.Referenced.PublicKeyStorage.html +1 -1
  100. package/docs/interfaces/KeetaNetSDK.Referenced.PublishOptions.html +1 -1
  101. package/docs/interfaces/KeetaNetSDK.Referenced.RequestTokenReceiveEntry.html +1 -1
  102. package/docs/interfaces/KeetaNetSDK.Referenced.TokenNumericEntry.html +1 -1
  103. package/docs/interfaces/KeetaNetSDK.Referenced.UserClientConfig.html +1 -1
  104. package/docs/interfaces/KeetaNetSDK.Referenced.UserClientOptions.html +1 -1
  105. package/docs/interfaces/KeetaNetSDK.Referenced.WithIsInstance.html +1 -1
  106. package/docs/interfaces/KeetaNetSDK.Referenced.src_lib_utils_asn1.ASN1BitString.html +1 -1
  107. package/docs/interfaces/KeetaNetSDK.Referenced.src_lib_utils_asn1.ASN1Date.html +1 -1
  108. package/docs/interfaces/KeetaNetSDK.Referenced.src_lib_utils_asn1.ASN1OID.html +1 -1
  109. package/docs/interfaces/KeetaNetSDK.Referenced.src_lib_utils_asn1.ASN1Set.html +1 -1
  110. package/docs/interfaces/KeetaNetSDK.Referenced.src_lib_utils_asn1.ASN1String.html +1 -1
  111. package/docs/interfaces/KeetaNetSDK.Referenced.src_lib_utils_asn1.ASN1Struct.html +1 -1
  112. package/docs/modules/KeetaNetSDK.Referenced.html +1 -1
  113. package/docs/types/KeetaNetSDK.Referenced.AcceptSwapRequestExpectedDeprecated.html +4 -0
  114. package/docs/variables/KeetaNetSDK.Referenced.allFullErrorCodes.html +1 -1
  115. package/lib/block/index.d.ts +1 -1
  116. package/lib/error/block.d.ts +2 -2
  117. package/lib/error/client.d.ts +2 -2
  118. package/lib/error/index.d.ts +1 -1
  119. package/npm-shrinkwrap.json +2 -2
  120. package/package.json +1 -1
  121. package/version.d.ts +1 -1
@@ -783,13 +783,45 @@ interface CreateSwapRequest {
783
783
  account: GenericAccount;
784
784
  token: TokenAddress;
785
785
  amount: bigint;
786
+ /**
787
+ * Indication of whether or not the received amount must be exact, defaults to false
788
+ */
789
+ exact?: boolean;
786
790
  };
787
791
  }
792
+ /**
793
+ * @deprecated Use the new structure with `receive` and `send` fields instead
794
+ */
795
+ type AcceptSwapRequestExpectedDeprecated = {
796
+ token?: TokenAddress;
797
+ amount?: bigint;
798
+ };
788
799
  interface AcceptSwapRequest {
789
800
  block: Block;
790
- expected?: {
791
- token?: TokenAddress;
792
- amount?: bigint;
801
+ /**
802
+ * The expected parameters for the swap acceptance, to validate the swap, or to modify the send parameters
803
+ */
804
+ expected?: AcceptSwapRequestExpectedDeprecated | {
805
+ /**
806
+ * Validate the receive parameters (what the other party is sending) for the swap acceptance
807
+ */
808
+ receive?: {
809
+ token?: TokenAddress;
810
+ amount?: bigint;
811
+ };
812
+ /**
813
+ * Validate or change the send parameters for the swap acceptance
814
+ */
815
+ send?: {
816
+ /**
817
+ * If provided, will assert that the other party is expecting to receive this token
818
+ */
819
+ token?: TokenAddress;
820
+ /**
821
+ * If provided, will attempt to send this amount instead of the minimum required amount
822
+ */
823
+ amount?: bigint;
824
+ };
793
825
  };
794
826
  }
795
827
  interface UserClientListenerTypes {
@@ -116013,7 +116013,7 @@ function client_block_toPrimitive(t, r) { if ("object" != typeof t || !t) return
116013
116013
 
116014
116014
 
116015
116015
  const client_BlockErrorType = 'BLOCK';
116016
- const client_BlockErrorCodes = ['INVALID_TYPE', 'INVALID_VERSION', 'NO_MULTIPLE_SET_REP', 'IDENTIFIER_NEED_DEFAULT_PERMISSIONS', 'CANNOT_SEND_NON_TOKEN', 'TOKEN_RECEIVE_DIFFERS', 'ONLY_TOKEN_OP', 'ONLY_IDENTIFIER_OP', 'NO_TOKEN_OP', 'NO_IDENTIFIER_OP', 'INVALID_SIGNER', 'INVALID_PURPOSE_VALIDATION', 'INVALID_MULTISIG_QUORUM', 'INVALID_MULTISIG_SIGNER_DEPTH', 'INVALID_MULTISIG_SIGNER_COUNT', 'INVALID_MULTISIG_SIGNER_DUPLICATE', 'INVALID_CREATE_IDENTIFIER_ARGS', 'NO_MULTISIG_OP', 'IDENTIFIER_INVALID', 'GENERAL_FIELD_INVALID', 'PERMISSIONS_INVALID_DEFAULT', 'PERMISSIONS_INVALID_ENTITY', 'PERMISSIONS_INVALID_PRINCIPAL', 'PERMISSIONS_INVALID_TARGET', 'INVALID_ACCOUNT_TYPE', 'NO_ADMIN_ON_TARGET', 'PREVIOUS_SELF', 'NO_DELEGATE_ADMIN', 'NO_MODIFY_PERMISSION_DUPE', 'CANNOT_FORWARD_TO_SELF', 'EXACT_TRUE_WHEN_FORWARDING', 'CERTIFICATE_SUBJECT_MISMATCH', 'NO_DUPLICATE_CERTIFICATE_OPERATION', 'INTERMEDIATE_CERTIFICATES_ONLY_ADD', 'INVALID_CERTIFICATE_VALUE', 'EXTERNAL_TOO_LONG', 'EXTERNAL_INVALID', 'EXTERNAL_MISSING', 'SUPPLY_INVALID', 'INVALID_IDEMPOTENT_FORMAT', 'INVALID_IDEMPOTENT_LENGTH'];
116016
+ const client_BlockErrorCodes = ['AMOUNT_BELOW_ZERO', 'CANNOT_FORWARD_TO_SELF', 'CANNOT_SEND_NON_TOKEN', 'CERTIFICATE_SUBJECT_MISMATCH', 'EXACT_TRUE_WHEN_FORWARDING', 'EXTERNAL_INVALID', 'EXTERNAL_MISSING', 'EXTERNAL_TOO_LONG', 'GENERAL_FIELD_INVALID', 'IDENTIFIER_INVALID', 'IDENTIFIER_NEED_DEFAULT_PERMISSIONS', 'INTERMEDIATE_CERTIFICATES_ONLY_ADD', 'INVALID_ACCOUNT_TYPE', 'INVALID_CERTIFICATE_VALUE', 'INVALID_CREATE_IDENTIFIER_ARGS', 'INVALID_IDEMPOTENT_FORMAT', 'INVALID_IDEMPOTENT_LENGTH', 'INVALID_MULTISIG_QUORUM', 'INVALID_MULTISIG_SIGNER_COUNT', 'INVALID_MULTISIG_SIGNER_DEPTH', 'INVALID_MULTISIG_SIGNER_DUPLICATE', 'INVALID_PURPOSE_VALIDATION', 'INVALID_SIGNATURE', 'INVALID_SIGNER', 'INVALID_TYPE', 'INVALID_VERSION', 'NO_ADMIN_ON_TARGET', 'NO_DELEGATE_ADMIN', 'NO_DUPLICATE_CERTIFICATE_OPERATION', 'NO_IDENTIFIER_OP', 'NO_MODIFY_PERMISSION_DUPE', 'NO_MULTIPLE_SET_REP', 'NO_MULTISIG_OP', 'NO_TOKEN_OP', 'ONLY_IDENTIFIER_OP', 'ONLY_TOKEN_OP', 'PERMISSIONS_INVALID_DEFAULT', 'PERMISSIONS_INVALID_ENTITY', 'PERMISSIONS_INVALID_PRINCIPAL', 'PERMISSIONS_INVALID_TARGET', 'PREVIOUS_SELF', 'SUPPLY_INVALID', 'TOKEN_RECEIVE_DIFFERS'];
116017
116017
  const client_FullBlockErrorCodes = client_BlockErrorCodes.map(code => `${client_BlockErrorType}_${code}`);
116018
116018
  class src_client_KeetaNetBlockError extends src_client_KeetaNetErrorBase {
116019
116019
  constructor(code, message) {
@@ -118623,7 +118623,11 @@ class src_client_BlockOperation {
118623
118623
  if (amount === undefined || amount === null) {
118624
118624
  throw new Error('internal error: "amount" is invalid');
118625
118625
  }
118626
- return BigInt(amount);
118626
+ const bigintAmount = BigInt(amount);
118627
+ if (bigintAmount < 0n) {
118628
+ throw new src_client_KeetaNetBlockError('BLOCK_AMOUNT_BELOW_ZERO', 'value cannot be negative');
118629
+ }
118630
+ return bigintAmount;
118627
118631
  }
118628
118632
  }
118629
118633
  client_BlockOperation = src_client_BlockOperation;
@@ -118842,7 +118846,7 @@ class src_client_BlockOperationTOKEN_ADMIN_MODIFY_BALANCE extends src_client_Blo
118842
118846
  }
118843
118847
  client_operations_classPrivateFieldSet(client_token3, this, client_operations_assertClassBrand(client_BlockOperationTOKEN_ADMIN_MODIFY_BALANCE_brand, this, client_computeToken3).call(this, input.token));
118844
118848
  client_operations_classPrivateFieldSet(client_amount3, this, this.computeAmount(input.amount));
118845
- client_operations_classPrivateFieldSet(client_method, this, input.method);
118849
+ client_operations_classPrivateFieldSet(client_method, this, client_toAdjustMethod(input.method));
118846
118850
  }
118847
118851
  set token(token) {
118848
118852
  client_operations_classPrivateFieldSet(client_token3, this, client_operations_assertClassBrand(client_BlockOperationTOKEN_ADMIN_MODIFY_BALANCE_brand, this, client_computeToken3).call(this, token));
@@ -118851,7 +118855,7 @@ class src_client_BlockOperationTOKEN_ADMIN_MODIFY_BALANCE extends src_client_Blo
118851
118855
  return client_operations_classPrivateFieldGet(client_token3, this);
118852
118856
  }
118853
118857
  set method(newMethod) {
118854
- client_operations_classPrivateFieldSet(client_method, this, newMethod);
118858
+ client_operations_classPrivateFieldSet(client_method, this, client_toAdjustMethod(newMethod));
118855
118859
  }
118856
118860
  get method() {
118857
118861
  return Number(client_operations_classPrivateFieldGet(client_method, this));
@@ -119189,7 +119193,7 @@ class src_client_BlockOperationMODIFY_PERMISSIONS extends src_client_BlockOperat
119189
119193
  }
119190
119194
  client_operations_classPrivateFieldSet(client_principal, this, this.computeTo(input.principal));
119191
119195
  client_operations_classPrivateFieldSet(client_target, this, client_lib_account.toAccount(input.target));
119192
- client_operations_classPrivateFieldSet(client_method2, this, input.method);
119196
+ client_operations_classPrivateFieldSet(client_method2, this, client_toAdjustMethod(input.method));
119193
119197
  client_operations_classPrivateFieldSet(client_permissions, this, client_operations_assertClassBrand(client_BlockOperationMODIFY_PERMISSIONS_brand, this, client_computePermissions).call(this, input.permissions));
119194
119198
  }
119195
119199
  set principal(principal) {
@@ -119211,7 +119215,7 @@ class src_client_BlockOperationMODIFY_PERMISSIONS extends src_client_BlockOperat
119211
119215
  return client_operations_classPrivateFieldGet(client_target, this);
119212
119216
  }
119213
119217
  set method(method) {
119214
- client_operations_classPrivateFieldSet(client_method2, this, method);
119218
+ client_operations_classPrivateFieldSet(client_method2, this, client_toAdjustMethod(method));
119215
119219
  }
119216
119220
  get method() {
119217
119221
  return Number(client_operations_classPrivateFieldGet(client_method2, this));
@@ -120493,6 +120497,7 @@ class src_client_Block {
120493
120497
  if (this.account.isMultisig()) {
120494
120498
  throw new src_client_KeetaNetBlockError('BLOCK_NO_MULTISIG_OP', 'Cannot create a block for a multisig account');
120495
120499
  }
120500
+ client_block_assertClassBrand(client_Block_brand, this, client_validateBytes).call(this);
120496
120501
  client_block_assertClassBrand(client_Block_brand, this, client_validateSignerField).call(this);
120497
120502
  client_block_assertClassBrand(client_Block_brand, this, client_validateOperationsPurpose).call(this);
120498
120503
  client_block_assertClassBrand(client_Block_brand, this, client_validateSignatures).call(this);
@@ -120502,8 +120507,11 @@ class src_client_Block {
120502
120507
  }
120503
120508
  toBytes() {
120504
120509
  let includeSignatures = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
120505
- if (client_block_classPrivateFieldGet(client_valueBytes, this) !== undefined && includeSignatures) {
120506
- return client_block_classPrivateFieldGet(client_valueBytes, this);
120510
+ let useCached = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
120511
+ if (useCached) {
120512
+ if (client_block_classPrivateFieldGet(client_valueBytes, this) !== undefined && includeSignatures) {
120513
+ return client_block_classPrivateFieldGet(client_valueBytes, this);
120514
+ }
120507
120515
  }
120508
120516
  const sharedBlockValues = {
120509
120517
  previous: this.previous,
@@ -120693,6 +120701,19 @@ function client_getSortedRequiredSigners(input) {
120693
120701
  }
120694
120702
  return out;
120695
120703
  }
120704
+ function client_validateBytes() {
120705
+ const existingBytes = client_block_classPrivateFieldGet(client_valueBytes, this);
120706
+ if (existingBytes === undefined) {
120707
+ return;
120708
+ }
120709
+ const recalculatedBytesBuffer = client_block_Buffer.from(this.toBytes(true, false));
120710
+ const existingBytesBuffer = client_block_Buffer.from(existingBytes);
120711
+ if (!recalculatedBytesBuffer.equals(existingBytesBuffer)) {
120712
+ const existingBytesHash = client_block_Buffer.from(client_hash_Hash(existingBytesBuffer)).toString('hex').toUpperCase();
120713
+ const recalculatedBytesHash = client_block_Buffer.from(client_hash_Hash(recalculatedBytesBuffer)).toString('hex').toUpperCase();
120714
+ throw new src_client_KeetaNetBlockError('BLOCK_INVALID_SIGNATURE', `Block signed bytes (${existingBytesHash}) do not match calculated bytes (${recalculatedBytesHash})`);
120715
+ }
120716
+ }
120696
120717
  function client_validateOperationsPurpose() {
120697
120718
  /**
120698
120719
  * Do not allow blocks to contain invalid constructions
@@ -120750,7 +120771,7 @@ function client_validateSignatures() {
120750
120771
  const signature = new src_client_BufferStorage(this.signatures[i], 64);
120751
120772
  const valid = signers[i].verify(this.hash.get(), signature.get());
120752
120773
  if (valid !== true) {
120753
- throw new Error(`Unable to validate signature of ${this.hash.toString()} against signature ${this.signatures[i]} for account ${signers[i].publicKeyString.get()}`);
120774
+ throw new src_client_KeetaNetBlockError('BLOCK_INVALID_SIGNATURE', `Unable to validate signature of ${this.hash.toString()} against signature ${this.signatures[i].toString('hex')} for account ${signers[i].publicKeyString.get()}`);
120754
120775
  }
120755
120776
  }
120756
120777
  }
@@ -125208,6 +125229,10 @@ function client_updateAccountInfoInState(state, account, info) {
125208
125229
  * Compute the effect of a SEND operation
125209
125230
  */
125210
125231
  function client_computeEffectOfOperationSEND(state, block, operation) {
125232
+ if (operation.amount < 0n) {
125233
+ throw new Error('Internal error: SEND operation with negative amount');
125234
+ }
125235
+
125211
125236
  // Decrement sender balance
125212
125237
  const senderChange = {
125213
125238
  state,
@@ -125237,6 +125262,10 @@ function client_computeEffectOfOperationSEND(state, block, operation) {
125237
125262
  * Compute the effect of a RECEIVE operation
125238
125263
  */
125239
125264
  function client_computeEffectOfOperationRECEIVE(state, block, operation) {
125265
+ if (operation.amount < 0n) {
125266
+ throw new Error('Internal error: RECEIVE operation with negative amount');
125267
+ }
125268
+
125240
125269
  // Increment recipient balance
125241
125270
  const recipientChange = {
125242
125271
  state,
@@ -125272,6 +125301,9 @@ function client_computeEffectOfOperationRECEIVE(state, block, operation) {
125272
125301
  }
125273
125302
  }
125274
125303
  function client_computeEffectOfOperationTOKEN_ADMIN_MODIFY_BALANCE(state, block, operation) {
125304
+ if (operation.amount < 0n) {
125305
+ throw new Error('Internal error: TOKEN_ADMIN_MODIFY_BALANCE operation with negative amount');
125306
+ }
125275
125307
  if (operation.method === src_client_Block.AdjustMethod.SET) {
125276
125308
  const setChange = {
125277
125309
  state,
@@ -125348,6 +125380,9 @@ function client_computeEffectOfOperationCREATE_IDENTIFIER(state, block, operatio
125348
125380
  client_updateAccountInfoInState(state, operation.identifier, {
125349
125381
  multisigQuorum: operation.createArguments.quorum
125350
125382
  });
125383
+ if (operation.createArguments.quorum < 1n || operation.createArguments.quorum > BigInt(operation.createArguments.signers.length)) {
125384
+ throw new Error('Internal error: operation.createArguments.quorum is invalid');
125385
+ }
125351
125386
  for (const multisigSigner of operation.createArguments.signers) {
125352
125387
  state.possibleNewAccounts.add(multisigSigner);
125353
125388
  client_addPermission(state, {
@@ -125389,6 +125424,9 @@ function client_computeEffectOfOperationMODIFY_PERMISSIONS(state, block, operati
125389
125424
  }
125390
125425
  function client_computeEffectOfOperationTOKEN_ADMIN_SUPPLY(state, block, operation) {
125391
125426
  var _state$accounts$token;
125427
+ if (operation.amount < 0n) {
125428
+ throw new Error('Internal error: TOKEN_ADMIN_SUPPLY operation with negative amount');
125429
+ }
125392
125430
  const tokenPubKey = block.account.publicKeyString.get();
125393
125431
  let value = 0n;
125394
125432
  switch (operation.method) {
@@ -128797,7 +128835,7 @@ client_lib_ledger_defineProperty(src_client_Ledger, "isInstance", client_checkab
128797
128835
  // EXTERNAL MODULE: ws (ignored)
128798
128836
  var client_ws_ignored_ = __webpack_require__(4708);
128799
128837
  ;// ./src/version.ts
128800
- const client_version = '0.14.12+g091eeeea12610658c71c9ee6a7c5e2eac6aabdde';
128838
+ const client_version = '0.14.13+g566b8de2c01660608e6eb5257113db271d7fc075';
128801
128839
  /* harmony default export */ const client_src_version = ((/* unused pure expression or super */ null && (client_version)));
128802
128840
  ;// ./src/lib/p2p.ts
128803
128841
  /* provided dependency */ var client_p2p_Buffer = __webpack_require__(8287)["Buffer"];
@@ -131032,7 +131070,7 @@ function client_client_toPrimitive(t, r) { if ("object" != typeof t || !t) retur
131032
131070
 
131033
131071
 
131034
131072
  const client_ClientErrorType = 'CLIENT';
131035
- const client_ClientErrorCodes = ['BUILDER_AMOUNT_IS_ZERO', 'BUILDER_CANNOT_READ_BEFORE_RENDER', 'BUILDER_REQUIRES_PRIVATE_KEY', 'BUILDER_USER_CLIENT_REQUIRED', 'PUBLISH_AID_NOT_AVAILABLE', 'SIGNER_REQUIRES_PRIVATE_KEY', 'SYNC_PUBLISH_FAILED', 'SWAP_INVALID_ACCOUNT_OPTION', 'SWAP_OPTIONS_INVALID', 'SWAP_MISSING_SEND', 'SWAP_MISSING_RECEIVE', 'SWAP_SEND_RECEIVE_ACCOUNT_MISMATCH', 'SWAP_SEND_ACCOUNT_MISMATCH', 'SWAP_REQUEST_TOKEN_MISMATCH', 'SWAP_REQUEST_AMOUNT_MISMATCH'];
131073
+ const client_ClientErrorCodes = ['BUILDER_AMOUNT_IS_ZERO', 'BUILDER_CANNOT_READ_BEFORE_RENDER', 'BUILDER_REQUIRES_PRIVATE_KEY', 'BUILDER_USER_CLIENT_REQUIRED', 'PUBLISH_AID_NOT_AVAILABLE', 'SIGNER_REQUIRES_PRIVATE_KEY', 'SYNC_PUBLISH_FAILED', 'SWAP_INVALID_ACCOUNT_OPTION', 'SWAP_OPTIONS_INVALID', 'SWAP_MISSING_SEND', 'SWAP_MISSING_RECEIVE', 'SWAP_SEND_RECEIVE_ACCOUNT_MISMATCH', 'SWAP_SEND_ACCOUNT_MISMATCH', 'SWAP_SEND_TOKEN_MISMATCH', 'SWAP_SEND_AMOUNT_TOO_LOW', 'SWAP_SEND_AMOUNT_RECEIVE_EXACT_MISMATCH', 'SWAP_REQUEST_TOKEN_MISMATCH', 'SWAP_REQUEST_AMOUNT_MISMATCH'];
131036
131074
  const client_FullClientErrorCodes = client_ClientErrorCodes.map(code => `${client_ClientErrorType}_${code}`);
131037
131075
  class src_client_KeetaNetClientError extends src_client_KeetaNetErrorBase {
131038
131076
  constructor(code, message) {
@@ -134333,6 +134371,9 @@ client_src_client_defineProperty(src_client_Client, "Config", client_config_name
134333
134371
  client_src_client_defineProperty(src_client_Client, "DefaultLogger", console);
134334
134372
  client_src_client_defineProperty(src_client_Client, "updateRepsInterval", 5 * 60 * 1000);
134335
134373
  client_src_client_defineProperty(src_client_Client, "isInstance", client_checkableGenerator(client_Client));
134374
+ /**
134375
+ * @deprecated Use the new structure with `receive` and `send` fields instead
134376
+ */
134336
134377
  const client_defaultListenerOptions = {
134337
134378
  change: {
134338
134379
  fallbackFrequency: 60 * 1000
@@ -134470,6 +134511,7 @@ class src_client_UserClient {
134470
134511
  * @returns Swap {@link Block}
134471
134512
  */
134472
134513
  static async createSwapRequest(request, client, options) {
134514
+ var _request$to$exact;
134473
134515
  let userClient;
134474
134516
  if (src_client_UserClient.isInstance(client)) {
134475
134517
  userClient = client;
@@ -134491,7 +134533,7 @@ class src_client_UserClient {
134491
134533
  account: request.from.account
134492
134534
  });
134493
134535
  builder.send(to.account, from.amount, from.token);
134494
- builder.receive(to.account, to.amount, to.token, true);
134536
+ builder.receive(to.account, to.amount, to.token, (_request$to$exact = request.to.exact) !== null && _request$to$exact !== void 0 ? _request$to$exact : false);
134495
134537
  const blocks = await builder.computeBlocks();
134496
134538
  if (blocks.blocks.length !== 1) {
134497
134539
  throw new Error('Compute Swap Request Generated more than 1 block');
@@ -134508,7 +134550,6 @@ class src_client_UserClient {
134508
134550
  */
134509
134551
 
134510
134552
  static async acceptSwapRequest(request, builderOrUserClient, options) {
134511
- var _request$expected, _request$expected2, _request$expected3, _request$expected4;
134512
134553
  let builder;
134513
134554
  let account;
134514
134555
  if (src_client_UserClientBuilder.isInstance(builderOrUserClient)) {
@@ -134517,15 +134558,16 @@ class src_client_UserClient {
134517
134558
  } else {
134518
134559
  let userClient;
134519
134560
  if (src_client_UserClient.isInstance(builderOrUserClient)) {
134561
+ var _options$account;
134520
134562
  userClient = builderOrUserClient;
134521
- account = builderOrUserClient.account;
134563
+ account = (_options$account = options === null || options === void 0 ? void 0 : options.account) !== null && _options$account !== void 0 ? _options$account : builderOrUserClient.account;
134522
134564
  } else try {
134523
- var _options$account;
134565
+ var _options$account2;
134524
134566
  var _usingCtx = client_client_usingCtx2();
134525
134567
  // Use await using so this temporary client gets cleaned up
134526
134568
  const temporaryClient = _usingCtx.a(this.fromNetwork(builderOrUserClient.network, builderOrUserClient.signer, options));
134527
134569
  userClient = temporaryClient;
134528
- account = (_options$account = options === null || options === void 0 ? void 0 : options.account) !== null && _options$account !== void 0 ? _options$account : builderOrUserClient.signer;
134570
+ account = (_options$account2 = options === null || options === void 0 ? void 0 : options.account) !== null && _options$account2 !== void 0 ? _options$account2 : builderOrUserClient.signer;
134529
134571
  if (account === null) {
134530
134572
  throw new src_client_KeetaNetClientError('CLIENT_SWAP_INVALID_ACCOUNT_OPTION', 'Signer is required for building swap block');
134531
134573
  }
@@ -134563,13 +134605,41 @@ class src_client_UserClient {
134563
134605
  if (!sendOperation.to.comparePublicKey(account)) {
134564
134606
  throw new src_client_KeetaNetClientError('CLIENT_SWAP_SEND_ACCOUNT_MISMATCH', 'Swap Request send account does not match');
134565
134607
  }
134566
- if (((_request$expected = request.expected) === null || _request$expected === void 0 ? void 0 : _request$expected.token) !== undefined && !sendOperation.token.comparePublicKey((_request$expected2 = request.expected) === null || _request$expected2 === void 0 ? void 0 : _request$expected2.token)) {
134567
- throw new src_client_KeetaNetClientError('CLIENT_SWAP_REQUEST_TOKEN_MISMATCH', 'Swap Request send token does not match expected');
134568
- }
134569
- if (((_request$expected3 = request.expected) === null || _request$expected3 === void 0 ? void 0 : _request$expected3.amount) !== undefined && sendOperation.amount !== ((_request$expected4 = request.expected) === null || _request$expected4 === void 0 ? void 0 : _request$expected4.amount)) {
134570
- throw new src_client_KeetaNetClientError('CLIENT_SWAP_REQUEST_AMOUNT_MISMATCH', 'Swap Request send amount does not match expected');
134608
+ let sendAmount = receiveOperation.amount;
134609
+ if (request.expected) {
134610
+ let expectedReceive;
134611
+ let expectedSend;
134612
+ if ('receive' in request.expected || 'send' in request.expected) {
134613
+ var _request$expected, _request$expected2;
134614
+ expectedReceive = (_request$expected = request.expected) === null || _request$expected === void 0 ? void 0 : _request$expected.receive;
134615
+ expectedSend = (_request$expected2 = request.expected) === null || _request$expected2 === void 0 ? void 0 : _request$expected2.send;
134616
+ } else if ('token' in request.expected || 'amount' in request.expected) {
134617
+ expectedReceive = request.expected;
134618
+ }
134619
+ if (expectedReceive) {
134620
+ if (expectedReceive.token !== undefined && !sendOperation.token.comparePublicKey(expectedReceive.token)) {
134621
+ throw new src_client_KeetaNetClientError('CLIENT_SWAP_REQUEST_TOKEN_MISMATCH', 'Swap Request send token does not match expected');
134622
+ }
134623
+ if (expectedReceive.amount !== undefined && sendOperation.amount !== expectedReceive.amount) {
134624
+ throw new src_client_KeetaNetClientError('CLIENT_SWAP_REQUEST_AMOUNT_MISMATCH', 'Swap Request send amount does not match expected');
134625
+ }
134626
+ }
134627
+ if (expectedSend) {
134628
+ if (expectedSend.token !== undefined && !expectedSend.token.comparePublicKey(receiveOperation.token)) {
134629
+ throw new src_client_KeetaNetClientError('CLIENT_SWAP_SEND_TOKEN_MISMATCH', 'Swap acceptance send token does not match swap request receive token');
134630
+ }
134631
+ if (expectedSend.amount !== undefined) {
134632
+ if (expectedSend.amount < receiveOperation.amount) {
134633
+ throw new src_client_KeetaNetClientError('CLIENT_SWAP_SEND_AMOUNT_TOO_LOW', 'Send amount must be at least the receive amount specified in the swap request');
134634
+ }
134635
+ if (receiveOperation.exact && receiveOperation.amount !== expectedSend.amount) {
134636
+ throw new src_client_KeetaNetClientError('CLIENT_SWAP_SEND_AMOUNT_RECEIVE_EXACT_MISMATCH', 'Send value is not allowed to differ from expected receive amount for exact receives');
134637
+ }
134638
+ sendAmount = expectedSend.amount;
134639
+ }
134640
+ }
134571
134641
  }
134572
- builder.send(request.block.account, receiveOperation.amount, receiveOperation.token);
134642
+ builder.send(request.block.account, sendAmount, receiveOperation.token);
134573
134643
  const blocks = await builder.computeBlocks();
134574
134644
  return [...blocks.blocks, request.block];
134575
134645
  }
@@ -134951,9 +135021,9 @@ class src_client_UserClient {
134951
135021
  */
134952
135022
 
134953
135023
  async getCertificates(certificateHash) {
134954
- var _options$account2;
135024
+ var _options$account3;
134955
135025
  let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
134956
- const account = (_options$account2 = options.account) !== null && _options$account2 !== void 0 ? _options$account2 : this.account;
135026
+ const account = (_options$account3 = options.account) !== null && _options$account3 !== void 0 ? _options$account3 : this.account;
134957
135027
  if (certificateHash !== undefined) {
134958
135028
  return await client_client_classPrivateFieldGet(client_client, this).getCertificateByHash(account, certificateHash);
134959
135029
  }
@@ -135457,9 +135527,9 @@ class src_client_UserClient {
135457
135527
  /** @hidden */
135458
135528
  client_UserClient = src_client_UserClient;
135459
135529
  function client_getAccount() {
135460
- var _ref3, _options$account3;
135530
+ var _ref3, _options$account4;
135461
135531
  let options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
135462
- const retval = (_ref3 = (_options$account3 = options.account) !== null && _options$account3 !== void 0 ? _options$account3 : client_client_classPrivateFieldGet(client_client_config, this).account) !== null && _ref3 !== void 0 ? _ref3 : this.signer;
135532
+ const retval = (_ref3 = (_options$account4 = options.account) !== null && _options$account4 !== void 0 ? _options$account4 : client_client_classPrivateFieldGet(client_client_config, this).account) !== null && _ref3 !== void 0 ? _ref3 : this.signer;
135463
135533
  if (retval === null) {
135464
135534
  throw new Error('No signer available in a read-only UserClient');
135465
135535
  }
package/client/index.d.ts CHANGED
@@ -783,13 +783,45 @@ interface CreateSwapRequest {
783
783
  account: GenericAccount;
784
784
  token: TokenAddress;
785
785
  amount: bigint;
786
+ /**
787
+ * Indication of whether or not the received amount must be exact, defaults to false
788
+ */
789
+ exact?: boolean;
786
790
  };
787
791
  }
792
+ /**
793
+ * @deprecated Use the new structure with `receive` and `send` fields instead
794
+ */
795
+ type AcceptSwapRequestExpectedDeprecated = {
796
+ token?: TokenAddress;
797
+ amount?: bigint;
798
+ };
788
799
  interface AcceptSwapRequest {
789
800
  block: Block;
790
- expected?: {
791
- token?: TokenAddress;
792
- amount?: bigint;
801
+ /**
802
+ * The expected parameters for the swap acceptance, to validate the swap, or to modify the send parameters
803
+ */
804
+ expected?: AcceptSwapRequestExpectedDeprecated | {
805
+ /**
806
+ * Validate the receive parameters (what the other party is sending) for the swap acceptance
807
+ */
808
+ receive?: {
809
+ token?: TokenAddress;
810
+ amount?: bigint;
811
+ };
812
+ /**
813
+ * Validate or change the send parameters for the swap acceptance
814
+ */
815
+ send?: {
816
+ /**
817
+ * If provided, will assert that the other party is expecting to receive this token
818
+ */
819
+ token?: TokenAddress;
820
+ /**
821
+ * If provided, will attempt to send this amount instead of the minimum required amount
822
+ */
823
+ amount?: bigint;
824
+ };
793
825
  };
794
826
  }
795
827
  interface UserClientListenerTypes {