Skip to content

Commit

Permalink
Merge branch '2.0' into feat/key-source
Browse files Browse the repository at this point in the history
  • Loading branch information
DaughterOfMars authored Nov 30, 2023
2 parents 91f762b + d58d964 commit be38602
Show file tree
Hide file tree
Showing 9 changed files with 4,634 additions and 4,649 deletions.
4 changes: 3 additions & 1 deletion bindings/core/src/method/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ use iota_sdk::{
protocol::ProtocolParameters,
signature::Ed25519Signature,
slot::SlotCommitment,
unlock::Unlock,
BlockDto,
},
};
Expand Down Expand Up @@ -166,7 +167,8 @@ pub enum UtilsMethod {
OutputHexBytes { output: Output },
/// Verifies the semantic of a transaction.
VerifyTransactionSemantic {
transaction: TransactionDto,
inputs: Vec<InputSigningDataDto>,
transaction: SignedTransactionPayloadDto,
unlocks: Option<Vec<Unlock>>,
},
}
36 changes: 22 additions & 14 deletions bindings/core/src/method_handler/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@
use crypto::keys::bip39::Mnemonic;
use iota_sdk::{
client::{
api::verify_semantic, hex_public_key_to_bech32_address, hex_to_bech32, secret::types::InputSigningData,
verify_mnemonic, Client,
hex_public_key_to_bech32_address, hex_to_bech32, secret::types::InputSigningData, verify_mnemonic, Client,
},
types::{
block::{
address::{AccountAddress, Address, ToBech32Ext},
input::UtxoInput,
output::{AccountId, FoundryId, MinimumOutputAmount, NftId, OutputId, TokenId},
output::{AccountId, FoundryId, MinimumOutputAmount, NftId, Output, OutputId, TokenId},
payload::{signed_transaction::Transaction, SignedTransactionPayload},
semantic::SemanticValidationContext,
Block,
},
TryFromDto,
Expand Down Expand Up @@ -105,18 +105,26 @@ pub(crate) fn call_utils_method_internal(method: UtilsMethod) -> Result<Response
UtilsMethod::OutputIdToUtxoInput { output_id } => Response::Input(UtxoInput::from(output_id)),
UtilsMethod::ComputeSlotCommitmentId { slot_commitment } => Response::SlotCommitmentId(slot_commitment.id()),
UtilsMethod::OutputHexBytes { output } => Response::HexBytes(prefix_hex::encode(output.pack_to_vec())),
UtilsMethod::VerifyTransactionSemantic { inputs, transaction } => {
let conflict = verify_semantic(
&inputs
.into_iter()
.map(InputSigningData::try_from)
.collect::<iota_sdk::client::Result<Vec<InputSigningData>>>()?,
&SignedTransactionPayload::try_from_dto(transaction)?,
)?;
// TODO conflict reason is an Option now
todo!();
// Response::TransactionFailureReason(conflict)
UtilsMethod::VerifyTransactionSemantic {
transaction,
inputs,
unlocks,
} => {
let transaction = Transaction::try_from_dto(transaction)?;
let inputs = &inputs
.into_iter()
.map(InputSigningData::try_from)
.collect::<iota_sdk::client::Result<Vec<InputSigningData>>>()?;
let inputs = inputs
.iter()
.map(|input| (input.output_id(), &input.output))
.collect::<Vec<(&OutputId, &Output)>>();

let context = SemanticValidationContext::new(&transaction, &inputs, unlocks.as_deref());

Response::TransactionFailureReason(context.validate()?)
}
};

Ok(response)
}
2 changes: 1 addition & 1 deletion bindings/core/src/response.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ pub enum Response {
/// Response for [`ComputeSlotCommitmentId`](crate::method::UtilsMethod::ComputeSlotCommitmentId)
SlotCommitmentId(SlotCommitmentId),
/// Response for [`VerifyTransactionSemantic`](crate::method::UtilsMethod::VerifyTransactionSemantic).
TransactionFailureReason(TransactionFailureReason),
TransactionFailureReason(Option<TransactionFailureReason>),

// Responses in client and wallet
/// Response for:
Expand Down
5 changes: 3 additions & 2 deletions bindings/nodejs/lib/types/utils/bridge/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
OutputId,
NftId,
Bech32Address,
Unlock,
} from '../../';
import { AccountId } from '../../block/id';
import { SlotCommitment } from '../../block/slot';
Expand Down Expand Up @@ -211,8 +212,8 @@ export interface __ComputeSlotCommitmentId__ {
export interface __VerifyTransactionSemantic__ {
name: 'verifyTransactionSemantic';
data: {
inputs: InputSigningData[];
transaction: SignedTransactionPayload;
time: number;
inputs: InputSigningData[];
unlocks?: Unlock[];
};
}
14 changes: 8 additions & 6 deletions bindings/nodejs/lib/utils/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
ProtocolParameters,
Bech32Address,
InputSigningData,
Unlock,
} from '../types';
import {
AccountId,
Expand Down Expand Up @@ -430,22 +431,23 @@ export class Utils {
/**
* 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.
* @param inputs The inputs data.
* @param unlocks The unlocks.
*
* @returns The conflict reason.
*/
static verifyTransactionSemantic(
inputs: InputSigningData[],
transaction: SignedTransactionPayload,
time: number,
inputs: InputSigningData[],
unlocks?: Unlock[],
): string {
const conflictReason = callUtilsMethod({
name: 'verifyTransactionSemantic',
data: {
inputs,
transaction,
time,
inputs,
unlocks,
},
});
return conflictReason;
Expand Down
Loading

0 comments on commit be38602

Please sign in to comment.