diff --git a/bindings/core/src/method/utils.rs b/bindings/core/src/method/utils.rs index 8ebf932b81..fc4ba5c0c6 100644 --- a/bindings/core/src/method/utils.rs +++ b/bindings/core/src/method/utils.rs @@ -2,18 +2,21 @@ // SPDX-License-Identifier: Apache-2.0 use derivative::Derivative; -use iota_sdk::types::block::{ - address::{Bech32Address, Hrp}, - output::{dto::OutputDto, AliasId, NftId, OutputId, RentStructure}, - payload::{ - dto::MilestonePayloadDto, - transaction::{ - dto::{TransactionEssenceDto, TransactionPayloadDto}, - TransactionId, +use iota_sdk::{ + client::secret::types::InputSigningDataDto, + types::block::{ + address::{Bech32Address, Hrp}, + output::{dto::OutputDto, AliasId, NftId, OutputId, RentStructure}, + payload::{ + dto::MilestonePayloadDto, + transaction::{ + dto::{TransactionEssenceDto, TransactionPayloadDto}, + TransactionId, + }, }, + signature::dto::Ed25519SignatureDto, + BlockDto, }, - signature::dto::Ed25519SignatureDto, - BlockDto, }; use serde::{Deserialize, Serialize}; @@ -159,4 +162,10 @@ pub enum UtilsMethod { /// Returns the hex representation of the serialized output bytes. #[serde(rename_all = "camelCase")] OutputHexBytes { output: OutputDto }, + /// Verifies the semantic of a transaction. + VerifyTransactionSemantic { + inputs: Vec, + transaction: TransactionPayloadDto, + time: u32, + }, } diff --git a/bindings/core/src/method_handler/utils.rs b/bindings/core/src/method_handler/utils.rs index cc316bae05..70a93d1ec4 100644 --- a/bindings/core/src/method_handler/utils.rs +++ b/bindings/core/src/method_handler/utils.rs @@ -3,7 +3,10 @@ use crypto::keys::bip39::Mnemonic; use iota_sdk::{ - client::{hex_public_key_to_bech32_address, hex_to_bech32, verify_mnemonic, Client}, + client::{ + api::verify_semantic, hex_public_key_to_bech32_address, hex_to_bech32, secret::types::InputSigningData, + verify_mnemonic, Client, + }, types::{ block::{ address::{dto::AddressDto, Address, AliasAddress, ToBech32Ext}, @@ -114,6 +117,21 @@ pub(crate) fn call_utils_method_internal(method: UtilsMethod) -> Result { + let conflict = verify_semantic( + &inputs + .into_iter() + .map(InputSigningData::try_from_dto) + .collect::>>()?, + &TransactionPayload::try_from_dto(transaction)?, + time, + )?; + Response::ConflictReason(conflict) + } }; Ok(response) } diff --git a/bindings/core/src/response.rs b/bindings/core/src/response.rs index c5d2b6f05e..69022b0d56 100644 --- a/bindings/core/src/response.rs +++ b/bindings/core/src/response.rs @@ -32,6 +32,7 @@ use iota_sdk::{ transaction::TransactionId, }, protocol::ProtocolParameters, + semantic::ConflictReason, signature::dto::Ed25519SignatureDto, unlock::dto::UnlockDto, BlockDto, BlockId, @@ -232,6 +233,8 @@ pub enum Response { HexBytes(String), /// Response for [`CallPluginRoute`](crate::method::ClientMethod::CallPluginRoute) CustomJson(serde_json::Value), + /// Response for [`VerifyTransactionSemantic`](crate::method::UtilsMethod::VerifyTransactionSemantic). + ConflictReason(ConflictReason), // Responses in client and wallet /// Response for: diff --git a/bindings/nodejs/CHANGELOG.md b/bindings/nodejs/CHANGELOG.md index 20f8b39bf0..262b03f24b 100644 --- a/bindings/nodejs/CHANGELOG.md +++ b/bindings/nodejs/CHANGELOG.md @@ -21,6 +21,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## 1.1.4 - 2023-MM-DD +### Added + +- `Utils:verifyTransactionSemantic()`; + ### Fixed - `StateMetadataOutput`'s constructor not setting the `stateMetadata` field; diff --git a/bindings/nodejs/lib/types/utils/bridge/index.ts b/bindings/nodejs/lib/types/utils/bridge/index.ts index fd3574dbe7..989a73c4a4 100644 --- a/bindings/nodejs/lib/types/utils/bridge/index.ts +++ b/bindings/nodejs/lib/types/utils/bridge/index.ts @@ -25,6 +25,7 @@ import type { __FaucetMethod__, __OutputIdToUtxoInput__, __OutputHexBytes__, + __VerifyTransactionSemantic__, } from './utils'; export type __UtilsMethods__ = @@ -53,4 +54,5 @@ export type __UtilsMethods__ = | __VerifyMnemonicMethod__ | __FaucetMethod__ | __OutputIdToUtxoInput__ - | __OutputHexBytes__; + | __OutputHexBytes__ + | __VerifyTransactionSemantic__; diff --git a/bindings/nodejs/lib/types/utils/bridge/utils.ts b/bindings/nodejs/lib/types/utils/bridge/utils.ts index 6eff28d30e..e14b747f41 100644 --- a/bindings/nodejs/lib/types/utils/bridge/utils.ts +++ b/bindings/nodejs/lib/types/utils/bridge/utils.ts @@ -14,6 +14,7 @@ import { Bech32Address, } from '../../'; import { AliasId } from '../../block/id'; +import { InputSigningData } from '../../client'; export interface __GenerateMnemonicMethod__ { name: 'generateMnemonic'; @@ -205,3 +206,12 @@ export interface __OutputHexBytes__ { output: Output; }; } + +export interface __VerifyTransactionSemantic__ { + name: 'verifyTransactionSemantic'; + data: { + inputs: InputSigningData[]; + transaction: TransactionPayload; + time: number; + }; +} diff --git a/bindings/nodejs/lib/utils/utils.ts b/bindings/nodejs/lib/utils/utils.ts index c4cfc62ec8..22c10a322a 100644 --- a/bindings/nodejs/lib/utils/utils.ts +++ b/bindings/nodejs/lib/utils/utils.ts @@ -17,6 +17,7 @@ import { IRent, OutputId, Bech32Address, + InputSigningData, } from '../types'; import { AliasId, BlockId, FoundryId, NftId, TokenId } from '../types/block/id'; @@ -420,4 +421,28 @@ export class Utils { }); return hexBytes; } + + /** + * Verifies the semantic of a transaction. + * + * @param inputs The inputs data. + * @param transaction The transaction payload. + * @param time The unix time for which to do the validation, should be roughly the one of the milestone that will reference the transaction. + * @returns The conflict reason. + */ + static verifyTransactionSemantic( + inputs: InputSigningData[], + transaction: TransactionPayload, + time: number, + ): string { + const conflictReason = callUtilsMethod({ + name: 'verifyTransactionSemantic', + data: { + inputs, + transaction, + time, + }, + }); + return conflictReason; + } } diff --git a/bindings/python/CHANGELOG.md b/bindings/python/CHANGELOG.md index cc2fe08cf3..2e4d292eb3 100644 --- a/bindings/python/CHANGELOG.md +++ b/bindings/python/CHANGELOG.md @@ -19,6 +19,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Security --> +## 1.1.2 - 2023-MM-DD + +### Added + +- `Utils:verify_transaction_semantic()`; + ## 1.1.1 - 2023-10-31 ### Added diff --git a/bindings/python/iota_sdk/utils.py b/bindings/python/iota_sdk/utils.py index 8c18f3e7e4..531654e5df 100644 --- a/bindings/python/iota_sdk/utils.py +++ b/bindings/python/iota_sdk/utils.py @@ -11,6 +11,7 @@ from iota_sdk.types.common import HexStr from iota_sdk.types.output_id import OutputId from iota_sdk.types.output import Output +from iota_sdk.types.transaction_data import InputSigningData from iota_sdk.external import call_utils_method from iota_sdk.types.payload import TransactionPayload @@ -218,6 +219,17 @@ def verify_secp256k1_ecdsa_signature( 'message': message, }) + @staticmethod + def verify_transaction_semantic( + inputs: List[InputSigningData], transaction: TransactionPayload, time: int) -> str: + """Verifies the semantic of a transaction. + """ + return _call_method('verifyTransactionSemantic', { + 'inputs': [i.as_dict() for i in inputs], + 'transaction': transaction.as_dict(), + 'time': time, + }) + class UtilsError(Exception): """A utils error.""" diff --git a/bindings/wasm/CHANGELOG.md b/bindings/wasm/CHANGELOG.md index 89082904b7..2f0865665c 100644 --- a/bindings/wasm/CHANGELOG.md +++ b/bindings/wasm/CHANGELOG.md @@ -19,6 +19,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Security --> +## 1.1.2 - 2023-MM-DD + +Same changes as https://github.com/iotaledger/iota-sdk/blob/develop/bindings/nodejs/CHANGELOG.md. + ## 1.1.1 - 2023-10-16 ### Fixed