Skip to content

Commit

Permalink
Add VerifySemantic to bindings (#1608)
Browse files Browse the repository at this point in the history
* Add verify semantic to bindings

* VerifyTransactionSemantic

* Fix return type
  • Loading branch information
Thoralf-M authored Nov 13, 2023
1 parent a492ad6 commit 097f22e
Show file tree
Hide file tree
Showing 10 changed files with 105 additions and 12 deletions.
29 changes: 19 additions & 10 deletions bindings/core/src/method/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};

Expand Down Expand Up @@ -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<InputSigningDataDto>,
transaction: TransactionPayloadDto,
time: u32,
},
}
20 changes: 19 additions & 1 deletion bindings/core/src/method_handler/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down Expand Up @@ -114,6 +117,21 @@ pub(crate) fn call_utils_method_internal(method: UtilsMethod) -> Result<Response
let output = Output::try_from_dto(output)?;
Response::HexBytes(prefix_hex::encode(output.pack_to_vec()))
}
UtilsMethod::VerifyTransactionSemantic {
inputs,
transaction,
time,
} => {
let conflict = verify_semantic(
&inputs
.into_iter()
.map(InputSigningData::try_from_dto)
.collect::<iota_sdk::client::Result<Vec<InputSigningData>>>()?,
&TransactionPayload::try_from_dto(transaction)?,
time,
)?;
Response::ConflictReason(conflict)
}
};
Ok(response)
}
3 changes: 3 additions & 0 deletions bindings/core/src/response.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ use iota_sdk::{
transaction::TransactionId,
},
protocol::ProtocolParameters,
semantic::ConflictReason,
signature::dto::Ed25519SignatureDto,
unlock::dto::UnlockDto,
BlockDto, BlockId,
Expand Down Expand Up @@ -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:
Expand Down
4 changes: 4 additions & 0 deletions bindings/nodejs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 3 additions & 1 deletion bindings/nodejs/lib/types/utils/bridge/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import type {
__FaucetMethod__,
__OutputIdToUtxoInput__,
__OutputHexBytes__,
__VerifyTransactionSemantic__,
} from './utils';

export type __UtilsMethods__ =
Expand Down Expand Up @@ -53,4 +54,5 @@ export type __UtilsMethods__ =
| __VerifyMnemonicMethod__
| __FaucetMethod__
| __OutputIdToUtxoInput__
| __OutputHexBytes__;
| __OutputHexBytes__
| __VerifyTransactionSemantic__;
10 changes: 10 additions & 0 deletions bindings/nodejs/lib/types/utils/bridge/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
Bech32Address,
} from '../../';
import { AliasId } from '../../block/id';
import { InputSigningData } from '../../client';

export interface __GenerateMnemonicMethod__ {
name: 'generateMnemonic';
Expand Down Expand Up @@ -205,3 +206,12 @@ export interface __OutputHexBytes__ {
output: Output;
};
}

export interface __VerifyTransactionSemantic__ {
name: 'verifyTransactionSemantic';
data: {
inputs: InputSigningData[];
transaction: TransactionPayload;
time: number;
};
}
25 changes: 25 additions & 0 deletions bindings/nodejs/lib/utils/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
IRent,
OutputId,
Bech32Address,
InputSigningData,
} from '../types';
import { AliasId, BlockId, FoundryId, NftId, TokenId } from '../types/block/id';

Expand Down Expand Up @@ -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;
}
}
6 changes: 6 additions & 0 deletions bindings/python/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 12 additions & 0 deletions bindings/python/iota_sdk/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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."""
Expand Down
4 changes: 4 additions & 0 deletions bindings/wasm/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 097f22e

Please sign in to comment.