diff --git a/apps/explorer/tests/utils/localnet.ts b/apps/explorer/tests/utils/localnet.ts index a87ab04e61f..a03f865afa3 100644 --- a/apps/explorer/tests/utils/localnet.ts +++ b/apps/explorer/tests/utils/localnet.ts @@ -36,7 +36,6 @@ export async function split_coin(address: string) { showEffects: true, showEvents: true, }, - requestType: 'WaitForLocalExecution', }); return result; diff --git a/apps/wallet/src/background/Transactions.ts b/apps/wallet/src/background/Transactions.ts index 95590bf8c0f..c7182567c1e 100644 --- a/apps/wallet/src/background/Transactions.ts +++ b/apps/wallet/src/background/Transactions.ts @@ -10,9 +10,8 @@ import type { IotaSignTransactionSerialized } from '_payloads/transactions/Execu import { type SignMessageRequest } from '_payloads/transactions/SignMessage'; import type { TransactionRequestResponse } from '_payloads/transactions/ui/TransactionRequestResponse'; import type { ContentScriptConnection } from '_src/background/connections/ContentScriptConnection'; -import { type SignedTransaction } from '_src/ui/app/WalletSigner'; import { type IotaTransactionBlockResponse } from '@iota/iota-sdk/client'; -import { type IotaSignMessageOutput } from '@iota/wallet-standard'; +import { type SignedTransaction, type IotaSignPersonalMessageOutput } from '@iota/wallet-standard'; import { filter, lastValueFrom, map, race, Subject, take } from 'rxjs'; import { v4 as uuidV4 } from 'uuid'; import Browser from 'webextension-polyfill'; @@ -68,12 +67,12 @@ class Transactions { return txSigned!; } - public async signMessage( + public async signPersonalMessage( { accountAddress, message }: Required>['args'], connection: ContentScriptConnection, - ): Promise { + ): Promise { const { txResult, txResultError } = await this.requestApproval( - { type: 'sign-message', accountAddress, message }, + { type: 'sign-personal-message', accountAddress, message }, connection.origin, connection.originFavIcon, ); @@ -86,7 +85,7 @@ class Transactions { if (!('messageBytes' in txResult)) { throw new Error('Sign message error, unknown result'); } - return txResult; + return txResult as IotaSignPersonalMessageOutput; } public async getTransactionRequests(): Promise> { diff --git a/apps/wallet/src/background/connections/ContentScriptConnection.ts b/apps/wallet/src/background/connections/ContentScriptConnection.ts index 2cb2f454717..8067c3ee7e5 100644 --- a/apps/wallet/src/background/connections/ContentScriptConnection.ts +++ b/apps/wallet/src/background/connections/ContentScriptConnection.ts @@ -29,9 +29,9 @@ import { isSignMessageRequest, type SignMessageRequest, } from '_src/shared/messaging/messages/payloads/transactions/SignMessage'; -import { type SignedTransaction } from '_src/ui/app/WalletSigner'; import { type IotaTransactionBlockResponse } from '@iota/iota-sdk/client'; import type { Runtime } from 'webextension-polyfill'; +import { type SignedTransaction } from '@iota/wallet-standard'; import { getAccountsStatusData } from '../accounts'; import NetworkEnv from '../NetworkEnv'; @@ -137,10 +137,10 @@ export class ContentScriptConnection extends Connection { ['viewAccount', 'suggestTransactions'], payload.args.accountAddress, ); - const result = await Transactions.signMessage(payload.args, this); + const result = await Transactions.signPersonalMessage(payload.args, this); this.send( createMessage( - { type: 'sign-message-request', return: result }, + { type: 'sign-personal-message-request', return: result }, msg.id, ), ); diff --git a/apps/wallet/src/dapp-interface/WalletStandardInterface.ts b/apps/wallet/src/dapp-interface/WalletStandardInterface.ts index 1902099b3f0..29429b238dd 100644 --- a/apps/wallet/src/dapp-interface/WalletStandardInterface.ts +++ b/apps/wallet/src/dapp-interface/WalletStandardInterface.ts @@ -25,7 +25,6 @@ import { getCustomNetwork, type NetworkEnvType } from '_src/shared/api-env'; import { type SignMessageRequest } from '_src/shared/messaging/messages/payloads/transactions/SignMessage'; import { isWalletStatusChangePayload } from '_src/shared/messaging/messages/payloads/wallet-status-change'; import { getNetwork, Network, type ChainType } from '@iota/iota-sdk/client'; -import { isTransaction } from '@iota/iota-sdk/transactions'; import { fromB64, toB64 } from '@iota/iota-sdk/utils'; import { ReadonlyWalletAccount, @@ -36,10 +35,7 @@ import { type StandardEventsListeners, type StandardEventsOnMethod, type IotaFeatures, - type IotaSignAndExecuteTransactionBlockMethod, - type IotaSignMessageMethod, type IotaSignPersonalMessageMethod, - type IotaSignTransactionBlockMethod, type Wallet, type IotaSignTransactionMethod, type IotaSignAndExecuteTransactionMethod, @@ -94,26 +90,14 @@ export class IotaWallet implements Wallet { version: '1.0.0', on: this.#on, }, - 'iota:signTransactionBlock': { - version: '1.0.0', - signTransactionBlock: this.#signTransactionBlock, - }, 'iota:signTransaction': { version: '2.0.0', signTransaction: this.#signTransaction, }, - 'iota:signAndExecuteTransactionBlock': { - version: '1.0.0', - signAndExecuteTransactionBlock: this.#signAndExecuteTransactionBlock, - }, 'iota:signAndExecuteTransaction': { version: '2.0.0', signAndExecuteTransaction: this.#signAndExecuteTransaction, }, - 'iota:signMessage': { - version: '1.0.0', - signMessage: this.#signMessage, - }, 'iota:signPersonalMessage': { version: '1.0.0', signPersonalMessage: this.#signPersonalMessage, @@ -205,32 +189,6 @@ export class IotaWallet implements Wallet { return { accounts: this.accounts }; }; - #signTransactionBlock: IotaSignTransactionBlockMethod = async ({ - transactionBlock, - account, - ...input - }) => { - if (!isTransaction(transactionBlock)) { - throw new Error( - 'Unexpected transaction format found. Ensure that you are using the `Transaction` class.', - ); - } - - return mapToPromise( - this.#send({ - type: 'sign-transaction-request', - transaction: { - ...input, - // account might be undefined if previous version of adapters is used - // in that case use the first account address - account: account?.address || this.#accounts[0]?.address || '', - transaction: transactionBlock.serialize(), - }, - }), - (response) => response.result, - ); - }; - #signTransaction: IotaSignTransactionMethod = async ({ transaction, account, ...input }) => { return mapToPromise( this.#send({ @@ -243,36 +201,13 @@ export class IotaWallet implements Wallet { transaction: await transaction.toJSON(), }, }), - ({ result: { signature, transactionBlockBytes: bytes } }) => ({ + ({ result: { signature, bytes } }) => ({ signature, bytes, }), ); }; - #signAndExecuteTransactionBlock: IotaSignAndExecuteTransactionBlockMethod = async (input) => { - if (!isTransaction(input.transactionBlock)) { - throw new Error( - 'Unexpected transaction format found. Ensure that you are using the `Transaction` class.', - ); - } - - return mapToPromise( - this.#send({ - type: 'execute-transaction-request', - transaction: { - type: 'transaction', - data: input.transactionBlock.serialize(), - options: input.options, - // account might be undefined if previous version of adapters is used - // in that case use the first account address - account: input.account?.address || this.#accounts[0]?.address || '', - }, - }), - (response) => response.result, - ); - }; - #signAndExecuteTransaction: IotaSignAndExecuteTransactionMethod = async (input) => { return mapToPromise( this.#send({ @@ -309,28 +244,10 @@ export class IotaWallet implements Wallet { ); }; - #signMessage: IotaSignMessageMethod = async ({ message, account }) => { - return mapToPromise( - this.#send({ - type: 'sign-message-request', - args: { - message: toB64(message), - accountAddress: account.address, - }, - }), - (response) => { - if (!response.return) { - throw new Error('Invalid sign message response'); - } - return response.return; - }, - ); - }; - #signPersonalMessage: IotaSignPersonalMessageMethod = async ({ message, account }) => { return mapToPromise( this.#send({ - type: 'sign-message-request', + type: 'sign-personal-message-request', args: { message: toB64(message), accountAddress: account.address, @@ -340,10 +257,7 @@ export class IotaWallet implements Wallet { if (!response.return) { throw new Error('Invalid sign message response'); } - return { - bytes: response.return.messageBytes, - signature: response.return.signature, - }; + return response.return; }, ); }; diff --git a/apps/wallet/src/shared/messaging/messages/payloads/BasePayload.ts b/apps/wallet/src/shared/messaging/messages/payloads/BasePayload.ts index 904cdb290aa..4de18c06bdc 100644 --- a/apps/wallet/src/shared/messaging/messages/payloads/BasePayload.ts +++ b/apps/wallet/src/shared/messaging/messages/payloads/BasePayload.ts @@ -30,7 +30,7 @@ export type PayloadType = | 'features-response' | 'get-network' | 'set-network' - | 'sign-message-request' + | 'sign-personal-message-request' | 'method-payload' | 'derive-bip-path-accounts-finder' | 'derive-bip-path-accounts-finder-response' diff --git a/apps/wallet/src/shared/messaging/messages/payloads/transactions/ApprovalRequest.ts b/apps/wallet/src/shared/messaging/messages/payloads/transactions/ApprovalRequest.ts index 49782caec47..80685dd2aa6 100644 --- a/apps/wallet/src/shared/messaging/messages/payloads/transactions/ApprovalRequest.ts +++ b/apps/wallet/src/shared/messaging/messages/payloads/transactions/ApprovalRequest.ts @@ -5,8 +5,8 @@ import { type SignedTransaction } from '_src/ui/app/WalletSigner'; import type { IotaTransactionBlockResponse } from '@iota/iota-sdk/client'; import { - type IotaSignAndExecuteTransactionBlockInput, - type IotaSignMessageOutput, + type IotaSignAndExecuteTransactionInput, + type IotaSignPersonalMessageOutput, } from '@iota/wallet-standard'; export type TransactionDataType = { @@ -14,12 +14,11 @@ export type TransactionDataType = { data: string; account: string; justSign?: boolean; - requestType?: IotaSignAndExecuteTransactionBlockInput['requestType']; - options?: IotaSignAndExecuteTransactionBlockInput['options']; + options?: IotaSignAndExecuteTransactionInput['options']; }; export type SignMessageDataType = { - type: 'sign-message'; + type: 'sign-personal-message'; message: string; accountAddress: string; }; @@ -29,16 +28,17 @@ export type ApprovalRequest = { approved: boolean | null; origin: string; originFavIcon?: string; - txResult?: IotaTransactionBlockResponse | IotaSignMessageOutput; + txResult?: IotaTransactionBlockResponse | IotaSignPersonalMessageOutput; txResultError?: string; txSigned?: SignedTransaction; createdDate: string; tx: TransactionDataType | SignMessageDataType; }; -export interface SignMessageApprovalRequest extends Omit { +export interface SignPersonalMessageApprovalRequest + extends Omit { tx: SignMessageDataType; - txResult?: IotaSignMessageOutput; + txResult?: IotaSignPersonalMessageOutput; } export interface TransactionApprovalRequest extends Omit { @@ -46,14 +46,14 @@ export interface TransactionApprovalRequest extends Omit & { transaction: string; account: string; diff --git a/apps/wallet/src/shared/messaging/messages/payloads/transactions/ExecuteTransactionResponse.ts b/apps/wallet/src/shared/messaging/messages/payloads/transactions/ExecuteTransactionResponse.ts index b685c9007f5..02953d0f89c 100644 --- a/apps/wallet/src/shared/messaging/messages/payloads/transactions/ExecuteTransactionResponse.ts +++ b/apps/wallet/src/shared/messaging/messages/payloads/transactions/ExecuteTransactionResponse.ts @@ -5,7 +5,7 @@ import { isBasePayload } from '_payloads'; import type { BasePayload, Payload } from '_payloads'; import type { IotaTransactionBlockResponse } from '@iota/iota-sdk/client'; -import { type IotaSignTransactionBlockOutput } from '@iota/wallet-standard'; +import { type IotaSignTransactionOutput } from '@iota/wallet-standard'; export interface ExecuteTransactionResponse extends BasePayload { type: 'execute-transaction-response'; @@ -20,7 +20,7 @@ export function isExecuteTransactionResponse( export interface SignTransactionResponse extends BasePayload { type: 'sign-transaction-response'; - result: IotaSignTransactionBlockOutput; + result: IotaSignTransactionOutput; } export function isSignTransactionResponse(payload: Payload): payload is SignTransactionResponse { diff --git a/apps/wallet/src/shared/messaging/messages/payloads/transactions/SignMessage.ts b/apps/wallet/src/shared/messaging/messages/payloads/transactions/SignMessage.ts index 6e88039c7f3..4dd520639b1 100644 --- a/apps/wallet/src/shared/messaging/messages/payloads/transactions/SignMessage.ts +++ b/apps/wallet/src/shared/messaging/messages/payloads/transactions/SignMessage.ts @@ -2,20 +2,20 @@ // Modifications Copyright (c) 2024 IOTA Stiftung // SPDX-License-Identifier: Apache-2.0 -import { type IotaSignMessageOutput } from '@iota/wallet-standard'; +import { type IotaSignPersonalMessageOutput } from '@iota/wallet-standard'; import { isBasePayload, type BasePayload } from '../BasePayload'; import { type Payload } from '../Payload'; export interface SignMessageRequest extends BasePayload { - type: 'sign-message-request'; + type: 'sign-personal-message-request'; args?: { message: string; // base64 accountAddress: string; }; - return?: IotaSignMessageOutput; + return?: IotaSignPersonalMessageOutput; } export function isSignMessageRequest(payload: Payload): payload is SignMessageRequest { - return isBasePayload(payload) && payload.type === 'sign-message-request'; + return isBasePayload(payload) && payload.type === 'sign-personal-message-request'; } diff --git a/apps/wallet/src/shared/messaging/messages/payloads/transactions/ui/TransactionRequestResponse.ts b/apps/wallet/src/shared/messaging/messages/payloads/transactions/ui/TransactionRequestResponse.ts index 8b04454b22e..ccfc53a55c3 100644 --- a/apps/wallet/src/shared/messaging/messages/payloads/transactions/ui/TransactionRequestResponse.ts +++ b/apps/wallet/src/shared/messaging/messages/payloads/transactions/ui/TransactionRequestResponse.ts @@ -6,13 +6,13 @@ import { isBasePayload } from '_payloads'; import type { BasePayload, Payload } from '_payloads'; import { type SignedTransaction } from '_src/ui/app/WalletSigner'; import type { IotaTransactionBlockResponse } from '@iota/iota-sdk/client'; -import { type IotaSignMessageOutput } from '@iota/wallet-standard'; +import { type IotaSignPersonalMessageOutput } from '@iota/wallet-standard'; export interface TransactionRequestResponse extends BasePayload { type: 'transaction-request-response'; txID: string; approved: boolean; - txResult?: IotaTransactionBlockResponse | IotaSignMessageOutput; + txResult?: IotaTransactionBlockResponse | IotaSignPersonalMessageOutput; txResultError?: string; txSigned?: SignedTransaction; } diff --git a/apps/wallet/src/ui/app/WalletSigner.ts b/apps/wallet/src/ui/app/WalletSigner.ts index fdf8d9ee07a..2be83cb253e 100644 --- a/apps/wallet/src/ui/app/WalletSigner.ts +++ b/apps/wallet/src/ui/app/WalletSigner.ts @@ -5,7 +5,6 @@ import { bcs } from '@iota/iota-sdk/bcs'; import { type DryRunTransactionBlockResponse, - type ExecuteTransactionRequestType, type IotaClient, type IotaTransactionBlockResponse, type IotaTransactionBlockResponseOptions, @@ -14,13 +13,13 @@ import { messageWithIntent } from '@iota/iota-sdk/cryptography'; import { isTransaction, type Transaction } from '@iota/iota-sdk/transactions'; import { fromB64, toB64 } from '@iota/iota-sdk/utils'; -export type SignedTransaction = { - transactionBlockBytes: string; +export interface SignedTransaction { + bytes: string; signature: string; -}; +} export type SignedMessage = { - messageBytes: string; + bytes: string; signature: string; }; @@ -31,14 +30,11 @@ export abstract class WalletSigner { this.client = client; } - abstract signData(data: Uint8Array, clientIdentifier?: string): Promise; + abstract signData(data: Uint8Array): Promise; abstract getAddress(): Promise; - async signMessage( - input: { message: Uint8Array }, - clientIdentifier?: string, - ): Promise { + async signMessage(input: { message: Uint8Array }): Promise { const signature = await this.signData( messageWithIntent( 'PersonalMessage', @@ -47,64 +43,56 @@ export abstract class WalletSigner { ); return { - messageBytes: toB64(input.message), + bytes: toB64(input.message), signature, }; } - protected async prepareTransactionBlock(transactionBlock: Uint8Array | Transaction | string) { - if (isTransaction(transactionBlock)) { + protected async prepareTransaction(transaction: Uint8Array | Transaction | string) { + if (isTransaction(transaction)) { // If the sender has not yet been set on the transaction, then set it. // NOTE: This allows for signing transactions with mismatched senders, which is important for sponsored transactions. - transactionBlock.setSenderIfNotSet(await this.getAddress()); - return await transactionBlock.build({ + transaction.setSenderIfNotSet(await this.getAddress()); + return await transaction.build({ client: this.client, }); } - if (typeof transactionBlock === 'string') { - return fromB64(transactionBlock); + if (typeof transaction === 'string') { + return fromB64(transaction); } - if (transactionBlock instanceof Uint8Array) { - return transactionBlock; + if (transaction instanceof Uint8Array) { + return transaction; } throw new Error('Unknown transaction format'); } - async signTransactionBlock( - input: { - transactionBlock: Uint8Array | Transaction; - }, - clientIdentifier?: string, - ): Promise { - const bytes = await this.prepareTransactionBlock(input.transactionBlock); + async signTransaction(input: { + transaction: Uint8Array | Transaction; + }): Promise { + const bytes = await this.prepareTransaction(input.transaction); const signature = await this.signData(messageWithIntent('TransactionData', bytes)); return { - transactionBlockBytes: toB64(bytes), + bytes: toB64(bytes), signature, }; } - async signAndExecuteTransaction( - input: { - transactionBlock: Uint8Array | Transaction; - options?: IotaTransactionBlockResponseOptions; - requestType?: ExecuteTransactionRequestType; - }, - clientIdentifier?: string, - ): Promise { - const bytes = await this.prepareTransactionBlock(input.transactionBlock); - const signed = await this.signTransactionBlock({ - transactionBlock: bytes, + async signAndExecuteTransaction(input: { + transactionBlock: Uint8Array | Transaction; + options?: IotaTransactionBlockResponseOptions; + }): Promise { + const bytes = await this.prepareTransaction(input.transactionBlock); + const signed = await this.signTransaction({ + transaction: bytes, }); return this.client.executeTransactionBlock({ transactionBlock: bytes, signature: signed.signature, options: input.options, - requestType: input.requestType, }); } @@ -112,7 +100,7 @@ export abstract class WalletSigner { transactionBlock: Transaction | string | Uint8Array; }): Promise { return this.client.dryRunTransactionBlock({ - transactionBlock: await this.prepareTransactionBlock(input.transactionBlock), + transactionBlock: await this.prepareTransaction(input.transactionBlock), }); } } diff --git a/apps/wallet/src/ui/app/pages/approval-request/SignMessageRequest.tsx b/apps/wallet/src/ui/app/pages/approval-request/SignMessageRequest.tsx index 72b880f9e51..b30ac753ffc 100644 --- a/apps/wallet/src/ui/app/pages/approval-request/SignMessageRequest.tsx +++ b/apps/wallet/src/ui/app/pages/approval-request/SignMessageRequest.tsx @@ -2,7 +2,7 @@ // Modifications Copyright (c) 2024 IOTA Stiftung // SPDX-License-Identifier: Apache-2.0 -import { type SignMessageApprovalRequest } from '_payloads/transactions/ApprovalRequest'; +import { type SignPersonalMessageApprovalRequest } from '_payloads/transactions/ApprovalRequest'; import { toUtf8OrB64 } from '_src/shared/utils'; import { useMemo } from 'react'; import { UserApproveContainer } from '_components'; @@ -14,7 +14,7 @@ import { PageMainLayoutTitle } from '../../shared/page-main-layout/PageMainLayou import { Panel } from '@iota/apps-ui-kit'; export interface SignMessageRequestProps { - request: SignMessageApprovalRequest; + request: SignPersonalMessageApprovalRequest; } export function SignMessageRequest({ request }: SignMessageRequestProps) { diff --git a/apps/wallet/src/ui/app/pages/approval-request/index.tsx b/apps/wallet/src/ui/app/pages/approval-request/index.tsx index 7528680d6ff..14c7dafa767 100644 --- a/apps/wallet/src/ui/app/pages/approval-request/index.tsx +++ b/apps/wallet/src/ui/app/pages/approval-request/index.tsx @@ -3,7 +3,7 @@ // SPDX-License-Identifier: Apache-2.0 import { - isSignMessageApprovalRequest, + isSignPersonalMessageApprovalRequest, isTransactionApprovalRequest, } from '_payloads/transactions/ApprovalRequest'; import { useEffect, useMemo } from 'react'; @@ -35,7 +35,7 @@ export function ApprovalRequestPage() { return ( {request ? ( - isSignMessageApprovalRequest(request) ? ( + isSignPersonalMessageApprovalRequest(request) ? ( ) : isTransactionApprovalRequest(request) ? ( diff --git a/apps/wallet/src/ui/app/pages/home/nft-transfer/useTransferKioskItem.tsx b/apps/wallet/src/ui/app/pages/home/nft-transfer/useTransferKioskItem.tsx index e853d772f25..f4edd7930bc 100644 --- a/apps/wallet/src/ui/app/pages/home/nft-transfer/useTransferKioskItem.tsx +++ b/apps/wallet/src/ui/app/pages/home/nft-transfer/useTransferKioskItem.tsx @@ -37,7 +37,7 @@ export function useTransferKioskItem({ const kioskClient = useKioskClient(); return useMutation({ - mutationFn: async ({ to, clientIdentifier }: { to: string; clientIdentifier?: string }) => { + mutationFn: async ({ to }: { to: string }) => { if (!to || !signer || !objectType) { throw new Error('Missing data'); } @@ -60,17 +60,14 @@ export function useTransferKioskItem({ }) .finalize(); - return signer.signAndExecuteTransaction( - { - transactionBlock: txb, - options: { - showInput: true, - showEffects: true, - showEvents: true, - }, + return signer.signAndExecuteTransaction({ + transactionBlock: txb, + options: { + showInput: true, + showEffects: true, + showEvents: true, }, - clientIdentifier, - ); + }); } if (kiosk.type === KioskTypes.ORIGINBYTE && objectData?.data?.data?.type) { @@ -102,17 +99,14 @@ export function useTransferKioskItem({ arguments: [tx.object(kioskId), tx.pure.address(to), tx.pure.id(objectId)], }); } - return signer.signAndExecuteTransaction( - { - transactionBlock: tx, - options: { - showInput: true, - showEffects: true, - showEvents: true, - }, + return signer.signAndExecuteTransaction({ + transactionBlock: tx, + options: { + showInput: true, + showEffects: true, + showEvents: true, }, - clientIdentifier, - ); + }); } throw new Error('Failed to transfer object'); }, diff --git a/apps/wallet/src/ui/app/redux/slices/transaction-requests/index.ts b/apps/wallet/src/ui/app/redux/slices/transaction-requests/index.ts index 1c06ca460e5..3b5e0ee7fdc 100644 --- a/apps/wallet/src/ui/app/redux/slices/transaction-requests/index.ts +++ b/apps/wallet/src/ui/app/redux/slices/transaction-requests/index.ts @@ -35,15 +35,11 @@ export const respondToTransactionRequest = createAsyncThunk< txRequestID: string; approved: boolean; signer: WalletSigner; - clientIdentifier?: string; }, AppThunkConfig >( 'respond-to-transaction-request', - async ( - { txRequestID, approved, signer, clientIdentifier }, - { extra: { background }, getState }, - ) => { + async ({ txRequestID, approved, signer }, { extra: { background }, getState }) => { const state = getState(); const txRequest = txRequestsSelectors.selectById(state, txRequestID); if (!txRequest) { @@ -54,32 +50,22 @@ export const respondToTransactionRequest = createAsyncThunk< let txResultError: string | undefined; if (approved) { try { - if (txRequest.tx.type === 'sign-message') { - txResult = await signer.signMessage( - { - message: fromB64(txRequest.tx.message), - }, - clientIdentifier, - ); + if (txRequest.tx.type === 'sign-personal-message') { + txResult = await signer.signMessage({ + message: fromB64(txRequest.tx.message), + }); } else if (txRequest.tx.type === 'transaction') { const tx = Transaction.from(txRequest.tx.data); if (txRequest.tx.justSign) { // Just a signing request, do not submit - txSigned = await signer.signTransactionBlock( - { - transactionBlock: tx, - }, - clientIdentifier, - ); + txSigned = await signer.signTransaction({ + transaction: tx, + }); } else { - txResult = await signer.signAndExecuteTransaction( - { - transactionBlock: tx, - options: txRequest.tx.options, - requestType: txRequest.tx.requestType, - }, - clientIdentifier, - ); + txResult = await signer.signAndExecuteTransaction({ + transactionBlock: tx, + options: txRequest.tx.options, + }); } } else { throw new Error( diff --git a/apps/wallet/src/ui/app/staking/stake/StakingCard.tsx b/apps/wallet/src/ui/app/staking/stake/StakingCard.tsx index f451fdc3790..4e368f8c723 100644 --- a/apps/wallet/src/ui/app/staking/stake/StakingCard.tsx +++ b/apps/wallet/src/ui/app/staking/stake/StakingCard.tsx @@ -6,9 +6,7 @@ import { Loading } from '_components'; import { Coin } from '_redux/slices/iota-objects/Coin'; import { ampli } from '_src/shared/analytics/ampli'; import { MIN_NUMBER_IOTA_TO_STAKE } from '_src/shared/constants'; -import { useFeatureIsOn } from '@growthbook/growthbook-react'; import { - Feature, createStakeTransaction, createUnstakeTransaction, parseAmount, @@ -63,9 +61,6 @@ function StakingCard() { staleTime: DELEGATED_STAKES_QUERY_STALE_TIME, refetchInterval: DELEGATED_STAKES_QUERY_REFETCH_INTERVAL, }); - const effectsOnlySharedTransactions = useFeatureIsOn( - Feature.WalletEffectsOnlySharedTransaction as string, - ); const { data: system, isPending: validatorsIsPending } = useIotaClientQuery( 'getLatestIotaSystemState', @@ -126,17 +121,18 @@ function StakingCard() { // }); try { const transactionBlock = createStakeTransaction(amount, validatorAddress); - return await signer.signAndExecuteTransaction({ + const tx = await signer.signAndExecuteTransaction({ transactionBlock, - requestType: effectsOnlySharedTransactions - ? 'WaitForEffectsCert' - : 'WaitForLocalExecution', options: { showInput: true, showEffects: true, showEvents: true, }, }); + await signer.client.waitForTransaction({ + digest: tx.digest, + }); + return tx; } finally { // sentryTransaction.finish(); } @@ -159,17 +155,18 @@ function StakingCard() { // name: 'stake', // }); const transactionBlock = createUnstakeTransaction(stakedIotaId); - return await signer.signAndExecuteTransaction({ + const tx = await signer.signAndExecuteTransaction({ transactionBlock, - requestType: effectsOnlySharedTransactions - ? 'WaitForEffectsCert' - : 'WaitForLocalExecution', options: { showInput: true, showEffects: true, showEvents: true, }, }); + await signer.client.waitForTransaction({ + digest: tx.digest, + }); + return tx; // finally { // sentryTransaction.finish(); // } diff --git a/apps/wallet/tests/demo-app/src/index.tsx b/apps/wallet/tests/demo-app/src/index.tsx index 0f9f2cc3de1..8ee934abd37 100644 --- a/apps/wallet/tests/demo-app/src/index.tsx +++ b/apps/wallet/tests/demo-app/src/index.tsx @@ -131,7 +131,7 @@ function App() { onClick={async () => { setError(null); try { - await iotaWallet.features['iota:signMessage']?.signMessage({ + await iotaWallet.features['iota:signPersonalMessage']?.signPersonalMessage({ account: getAccount(accounts[0], useWrongAccounts), message: new TextEncoder().encode('Test message'), }); diff --git a/apps/wallet/tests/sites-to-cs-messaging.spec.ts b/apps/wallet/tests/sites-to-cs-messaging.spec.ts index ec33dcd6ac0..69ef27883a7 100644 --- a/apps/wallet/tests/sites-to-cs-messaging.spec.ts +++ b/apps/wallet/tests/sites-to-cs-messaging.spec.ts @@ -61,7 +61,7 @@ test.describe('site to content script messages', () => { [ 'sign message no account', { - type: 'sign-message-request', + type: 'sign-personal-message-request', }, false, ], diff --git a/examples/trading/frontend/src/hooks/useTransactionExecution.ts b/examples/trading/frontend/src/hooks/useTransactionExecution.ts index 5218f9c7671..02a8b76aa7f 100644 --- a/examples/trading/frontend/src/hooks/useTransactionExecution.ts +++ b/examples/trading/frontend/src/hooks/useTransactionExecution.ts @@ -14,13 +14,13 @@ import toast from "react-hot-toast"; */ export function useTransactionExecution() { const client = useIotaClient(); - const { mutateAsync: signTransactionBlock } = useSignTransaction(); + const { mutateAsync: signTransaction } = useSignTransaction(); const executeTransaction = async ( txb: Transaction, ): Promise => { try { - const signature = await signTransactionBlock({ + const signature = await signTransaction({ transactionBlock: txb, }); diff --git a/sdk/dapp-kit/src/constants/walletDefaults.ts b/sdk/dapp-kit/src/constants/walletDefaults.ts index a043801736b..57ded2ec1e6 100644 --- a/sdk/dapp-kit/src/constants/walletDefaults.ts +++ b/sdk/dapp-kit/src/constants/walletDefaults.ts @@ -13,10 +13,7 @@ export const DEFAULT_STORAGE = export const DEFAULT_STORAGE_KEY = 'iota-dapp-kit:wallet-connection-info'; -const SIGN_FEATURES = [ - 'iota:signTransaction', - 'iota:signTransactionBlock', -] satisfies (keyof IotaWalletFeatures)[]; +const SIGN_FEATURES = ['iota:signTransaction'] satisfies (keyof IotaWalletFeatures)[]; export const DEFAULT_WALLET_FILTER = (wallet: WalletWithRequiredFeatures) => SIGN_FEATURES.some((feature) => wallet.features[feature]); diff --git a/sdk/dapp-kit/src/hooks/wallet/useSignAndExecuteTransaction.ts b/sdk/dapp-kit/src/hooks/wallet/useSignAndExecuteTransaction.ts index 2f5ce3c9433..0ac594c962c 100644 --- a/sdk/dapp-kit/src/hooks/wallet/useSignAndExecuteTransaction.ts +++ b/sdk/dapp-kit/src/hooks/wallet/useSignAndExecuteTransaction.ts @@ -122,10 +122,7 @@ export function useSignAndExecuteTransaction< } const chain = signTransactionArgs.chain ?? signerAccount?.chains[0]; - if ( - !currentWallet.features['iota:signTransaction'] && - !currentWallet.features['iota:signTransactionBlock'] - ) { + if (!currentWallet.features['iota:signTransaction']) { throw new WalletFeatureNotSupportedError( "This wallet doesn't support the `signTransaction` feature.", ); diff --git a/sdk/dapp-kit/src/hooks/wallet/useSignPersonalMessage.ts b/sdk/dapp-kit/src/hooks/wallet/useSignPersonalMessage.ts index da25a6f4bb8..f50a3b2e0c1 100644 --- a/sdk/dapp-kit/src/hooks/wallet/useSignPersonalMessage.ts +++ b/sdk/dapp-kit/src/hooks/wallet/useSignPersonalMessage.ts @@ -60,6 +60,13 @@ export function useSignPersonalMessage({ throw new WalletNotConnectedError('No wallet is connected.'); } + const signPersonalMessageFeature = currentWallet.features['iota:signPersonalMessage']; + if (!signPersonalMessageFeature) { + throw new WalletFeatureNotSupportedError( + "This wallet doesn't support the `signPersonalMessage` feature.", + ); + } + const signerAccount = signPersonalMessageArgs.account ?? currentAccount; if (!signerAccount) { throw new WalletNoAccountSelectedError( @@ -67,31 +74,10 @@ export function useSignPersonalMessage({ ); } - const signPersonalMessageFeature = currentWallet.features['iota:signPersonalMessage']; - if (signPersonalMessageFeature) { - return await signPersonalMessageFeature.signPersonalMessage({ - ...signPersonalMessageArgs, - account: signerAccount, - }); - } - - // TODO: Remove this once we officially discontinue iota:signMessage in the wallet standard - const signMessageFeature = currentWallet.features['iota:signMessage']; - if (signMessageFeature) { - console.warn( - "This wallet doesn't support the `signPersonalMessage` feature... falling back to `signMessage`.", - ); - - const { messageBytes, signature } = await signMessageFeature.signMessage({ - ...signPersonalMessageArgs, - account: signerAccount, - }); - return { bytes: messageBytes, signature }; - } - - throw new WalletFeatureNotSupportedError( - "This wallet doesn't support the `signPersonalMessage` feature.", - ); + return await signPersonalMessageFeature.signPersonalMessage({ + ...signPersonalMessageArgs, + account: signerAccount, + }); }, ...mutationOptions, }); diff --git a/sdk/dapp-kit/src/hooks/wallet/useSignTransaction.ts b/sdk/dapp-kit/src/hooks/wallet/useSignTransaction.ts index d09a781ee01..ffb53ed150e 100644 --- a/sdk/dapp-kit/src/hooks/wallet/useSignTransaction.ts +++ b/sdk/dapp-kit/src/hooks/wallet/useSignTransaction.ts @@ -78,10 +78,7 @@ export function useSignTransaction({ ); } - if ( - !currentWallet.features['iota:signTransaction'] && - !currentWallet.features['iota:signTransactionBlock'] - ) { + if (!currentWallet.features['iota:signTransaction']) { throw new WalletFeatureNotSupportedError( "This wallet doesn't support the `signTransaction` feature.", ); diff --git a/sdk/dapp-kit/src/hooks/wallet/useUnsafeBurnerWallet.ts b/sdk/dapp-kit/src/hooks/wallet/useUnsafeBurnerWallet.ts index 946eff3fd5d..fd464c63a2a 100644 --- a/sdk/dapp-kit/src/hooks/wallet/useUnsafeBurnerWallet.ts +++ b/sdk/dapp-kit/src/hooks/wallet/useUnsafeBurnerWallet.ts @@ -12,10 +12,8 @@ import type { StandardEventsFeature, StandardEventsOnMethod, IotaFeatures, - IotaSignAndExecuteTransactionBlockMethod, IotaSignAndExecuteTransactionMethod, IotaSignPersonalMessageMethod, - IotaSignTransactionBlockMethod, IotaSignTransactionMethod, Wallet, } from '@iota/wallet-standard'; @@ -58,12 +56,7 @@ function registerUnsafeBurnerWallet(iotaClient: IotaClient) { address: keypair.getPublicKey().toIotaAddress(), publicKey: keypair.getPublicKey().toIotaBytes(), chains: ['iota:unknown'], - features: [ - 'iota:signAndExecuteTransactionBlock', - 'iota:signTransactionBlock', - 'iota:signTransaction', - 'iota:signAndExecuteTransaction', - ], + features: ['iota:signTransaction', 'iota:signAndExecuteTransaction'], }); class UnsafeBurnerWallet implements Wallet { @@ -102,14 +95,6 @@ function registerUnsafeBurnerWallet(iotaClient: IotaClient) { version: '1.0.0', signPersonalMessage: this.#signPersonalMessage, }, - 'iota:signTransactionBlock': { - version: '1.0.0', - signTransactionBlock: this.#signTransactionBlock, - }, - 'iota:signAndExecuteTransactionBlock': { - version: '1.0.0', - signAndExecuteTransactionBlock: this.#signAndExecuteTransactionBlock, - }, 'iota:signTransaction': { version: '2.0.0', signTransaction: this.#signTransaction, @@ -134,18 +119,6 @@ function registerUnsafeBurnerWallet(iotaClient: IotaClient) { return { bytes, signature }; }; - #signTransactionBlock: IotaSignTransactionBlockMethod = async (transactionInput) => { - const { bytes, signature } = await transactionInput.transactionBlock.sign({ - client: iotaClient, - signer: keypair, - }); - - return { - transactionBlockBytes: bytes, - signature: signature, - }; - }; - #signTransaction: IotaSignTransactionMethod = async (transactionInput) => { const { bytes, signature } = await Transaction.from( await transactionInput.transaction.toJSON(), @@ -162,21 +135,6 @@ function registerUnsafeBurnerWallet(iotaClient: IotaClient) { }; }; - #signAndExecuteTransactionBlock: IotaSignAndExecuteTransactionBlockMethod = async ( - transactionInput, - ) => { - const { bytes, signature } = await transactionInput.transactionBlock.sign({ - client: iotaClient, - signer: keypair, - }); - - return iotaClient.executeTransactionBlock({ - signature, - transactionBlock: bytes, - options: transactionInput.options, - }); - }; - #signAndExecuteTransaction: IotaSignAndExecuteTransactionMethod = async ( transactionInput, ) => { diff --git a/sdk/dapp-kit/test/hooks/useSignPersonalMessage.test.tsx b/sdk/dapp-kit/test/hooks/useSignPersonalMessage.test.tsx index f00fdb4dbea..765a3e5ad88 100644 --- a/sdk/dapp-kit/test/hooks/useSignPersonalMessage.test.tsx +++ b/sdk/dapp-kit/test/hooks/useSignPersonalMessage.test.tsx @@ -10,7 +10,7 @@ import { WalletNotConnectedError, } from '../../src/errors/walletErrors.js'; import { useConnectWallet, useSignPersonalMessage } from '../../src/index.js'; -import { signMessageFeature, iotaFeatures } from '../mocks/mockFeatures.js'; +import { iotaFeatures } from '../mocks/mockFeatures.js'; import { createWalletProviderContextWrapper, registerMockWallet } from '../test-utils.js'; describe('useSignPersonalMessage', () => { @@ -50,42 +50,6 @@ describe('useSignPersonalMessage', () => { act(() => unregister()); }); - test('falls back to the `iota:signMessage` feature with a wallet that lacks support for `iota:signPersonalMessage`.', async () => { - const { unregister, mockWallet } = registerMockWallet({ - walletName: 'Mock Wallet 1', - features: signMessageFeature, - }); - - const wrapper = createWalletProviderContextWrapper(); - const { result } = renderHook( - () => ({ - connectWallet: useConnectWallet(), - signPersonalMessage: useSignPersonalMessage(), - }), - { wrapper }, - ); - - result.current.connectWallet.mutate({ wallet: mockWallet }); - await waitFor(() => expect(result.current.connectWallet.isSuccess).toBe(true)); - - const mockSignMessageFeature = mockWallet.features['iota:signMessage']; - const signMessageMock = mockSignMessageFeature!.signMessage as Mock; - - signMessageMock.mockReturnValueOnce({ messageBytes: 'abc', signature: '123' }); - - result.current.signPersonalMessage.mutate({ - message: new Uint8Array().fill(123), - }); - - await waitFor(() => expect(result.current.signPersonalMessage.isSuccess).toBe(true)); - expect(result.current.signPersonalMessage.data).toStrictEqual({ - bytes: 'abc', - signature: '123', - }); - - act(() => unregister()); - }); - test('signing a personal message from the currently connected account works successfully', async () => { const { unregister, mockWallet } = registerMockWallet({ walletName: 'Mock Wallet 1', diff --git a/sdk/dapp-kit/test/mocks/mockAccount.ts b/sdk/dapp-kit/test/mocks/mockAccount.ts index 6989e3a8fff..8091c3fe244 100644 --- a/sdk/dapp-kit/test/mocks/mockAccount.ts +++ b/sdk/dapp-kit/test/mocks/mockAccount.ts @@ -12,12 +12,7 @@ export function createMockAccount(accountOverrides: Partial = {}) address: keypair.getPublicKey().toIotaAddress(), publicKey: keypair.getPublicKey().toIotaBytes(), chains: ['iota:unknown'], - features: [ - 'iota:signAndExecuteTransactionBlock', - 'iota:signTransactionBlock', - 'iota:signAndExecuteTransaction', - 'iota:signTransaction', - ], + features: ['iota:signAndExecuteTransaction', 'iota:signTransaction'], ...accountOverrides, }); } diff --git a/sdk/dapp-kit/test/mocks/mockFeatures.ts b/sdk/dapp-kit/test/mocks/mockFeatures.ts index 6059d3bf8f4..f65aeebc6e8 100644 --- a/sdk/dapp-kit/test/mocks/mockFeatures.ts +++ b/sdk/dapp-kit/test/mocks/mockFeatures.ts @@ -2,14 +2,7 @@ // Modifications Copyright (c) 2024 IOTA Stiftung // SPDX-License-Identifier: Apache-2.0 -import type { IdentifierRecord, IotaFeatures, IotaSignMessageFeature } from '@iota/wallet-standard'; - -export const signMessageFeature: IotaSignMessageFeature = { - 'iota:signMessage': { - version: '1.0.0', - signMessage: vi.fn(), - }, -}; +import type { IdentifierRecord, IotaFeatures } from '@iota/wallet-standard'; export const superCoolFeature: IdentifierRecord = { 'my-dapp:super-cool-feature': { @@ -19,23 +12,14 @@ export const superCoolFeature: IdentifierRecord = { }; export const iotaFeatures: IotaFeatures = { - ...signMessageFeature, 'iota:signPersonalMessage': { version: '1.0.0', signPersonalMessage: vi.fn(), }, - 'iota:signTransactionBlock': { - version: '1.0.0', - signTransactionBlock: vi.fn(), - }, 'iota:signTransaction': { version: '2.0.0', signTransaction: vi.fn(), }, - 'iota:signAndExecuteTransactionBlock': { - version: '1.0.0', - signAndExecuteTransactionBlock: vi.fn(), - }, 'iota:signAndExecuteTransaction': { version: '2.0.0', signAndExecuteTransaction: vi.fn(), diff --git a/sdk/graphql-transport/src/methods.ts b/sdk/graphql-transport/src/methods.ts index 60e39b15542..4ec6566bdad 100644 --- a/sdk/graphql-transport/src/methods.ts +++ b/sdk/graphql-transport/src/methods.ts @@ -1069,8 +1069,7 @@ export const RPC_METHODS: { }, }; }, - async executeTransactionBlock(transport, [txBytes, signatures, options, _requestType]) { - // TODO: requestType + async executeTransactionBlock(transport, [txBytes, signatures, options]) { const { effects, errors } = await transport.graphqlQuery( { query: ExecuteTransactionBlockDocument, diff --git a/sdk/kiosk/test/e2e/setup.ts b/sdk/kiosk/test/e2e/setup.ts index 4271feaf61e..37b4dfead95 100644 --- a/sdk/kiosk/test/e2e/setup.ts +++ b/sdk/kiosk/test/e2e/setup.ts @@ -235,8 +235,12 @@ export async function executeTransaction( showEvents: true, showObjectChanges: true, }, - requestType: 'WaitForLocalExecution', }); + + await toolbox.client.waitForTransaction({ + digest: resp.digest, + }); + expect(resp.effects?.status.status).toEqual('success'); return resp; } diff --git a/sdk/typescript/README.md b/sdk/typescript/README.md index e0c0ff6b387..9aae6026a27 100644 --- a/sdk/typescript/README.md +++ b/sdk/typescript/README.md @@ -179,7 +179,7 @@ For a primer for building transactions, refer to ```typescript import { getFullnodeUrl, IotaClient } from '@iota/iota-sdk/client'; import { Ed25519Keypair } from '@iota/iota-sdk/keypairs/ed25519'; -import { TransactionBlock } from '@iota/iota-sdk/transactions'; +import { Transaction } from '@iota/iota-sdk/transactions'; // Generate a new Ed25519 Keypair const keypair = new Ed25519Keypair(); @@ -187,14 +187,14 @@ const client = new IotaClient({ url: getFullnodeUrl('testnet'), }); -const tx = new TransactionBlock(); +const tx = new Transaction(); tx.transferObjects( ['0xe19739da1a701eadc21683c5b127e62b553e833e8a15a4f292f4f48b4afea3f2'], '0x1d20dcdb2bca4f508ea9613994683eb4e76e9c4ed371169677c1be02aaf0b12a', ); -const result = await client.signAndExecuteTransactionBlock({ +const result = await client.signAndExecuteTransaction({ signer: keypair, - transactionBlock: tx, + transaction: tx, }); console.log({ result }); ``` @@ -206,7 +206,7 @@ To transfer `1000` NANOS to another address: ```typescript import { getFullnodeUrl, IotaClient } from '@iota/iota-sdk/client'; import { Ed25519Keypair } from '@iota/iota-sdk/keypairs/ed25519'; -import { TransactionBlock } from '@iota/iota-sdk/transactions'; +import { Transaction } from '@iota/iota-sdk/transactions'; // Generate a new Ed25519 Keypair const keypair = new Ed25519Keypair(); @@ -214,12 +214,12 @@ const client = new IotaClient({ url: getFullnodeUrl('testnet'), }); -const tx = new TransactionBlock(); +const tx = new Transaction(); const [coin] = tx.splitCoins(tx.gas, [1000]); tx.transferObjects([coin], keypair.getPublicKey().toIotaAddress()); -const result = await client.signAndExecuteTransactionBlock({ +const result = await client.signAndExecuteTransaction({ signer: keypair, - transactionBlock: tx, + transaction: tx, }); console.log({ result }); ``` @@ -229,7 +229,7 @@ console.log({ result }); ```typescript import { getFullnodeUrl, IotaClient } from '@iota/iota-sdk/client'; import { Ed25519Keypair } from '@iota/iota-sdk/keypairs/ed25519'; -import { TransactionBlock } from '@iota/iota-sdk/transactions'; +import { Transaction } from '@iota/iota-sdk/transactions'; // Generate a new Ed25519 Keypair const keypair = new Ed25519Keypair(); @@ -237,13 +237,13 @@ const client = new IotaClient({ url: getFullnodeUrl('testnet'), }); -const tx = new TransactionBlock(); +const tx = new Transaction(); tx.mergeCoins('0xe19739da1a701eadc21683c5b127e62b553e833e8a15a4f292f4f48b4afea3f2', [ '0x127a8975134a4824d9288722c4ee4fc824cd22502ab4ad9f6617f3ba19229c1b', ]); -const result = await client.signAndExecuteTransactionBlock({ +const result = await client.signAndExecuteTransaction({ signer: keypair, - transactionBlock: tx, + transaction: tx, }); console.log({ result }); ``` @@ -253,7 +253,7 @@ console.log({ result }); ```typescript import { getFullnodeUrl, IotaClient } from '@iota/iota-sdk/client'; import { Ed25519Keypair } from '@iota/iota-sdk/keypairs/ed25519'; -import { TransactionBlock } from '@iota/iota-sdk/transactions'; +import { Transaction } from '@iota/iota-sdk/transactions'; // Generate a new Ed25519 Keypair const keypair = new Ed25519Keypair(); @@ -261,14 +261,14 @@ const client = new IotaClient({ url: getFullnodeUrl('testnet'), }); const packageObjectId = '0x...'; -const tx = new TransactionBlock(); +const tx = new Transaction(); tx.moveCall({ target: `${packageObjectId}::nft::mint`, arguments: [tx.pure.string('Example NFT')], }); -const result = await client.signAndExecuteTransactionBlock({ +const result = await client.signAndExecuteTransaction({ signer: keypair, - transactionBlock: tx, + transaction: tx, }); console.log({ result }); ``` @@ -280,7 +280,7 @@ To publish a package: ```typescript import { getFullnodeUrl, IotaClient } from '@iota/iota-sdk/client'; import { Ed25519Keypair } from '@iota/iota-sdk/keypairs/ed25519'; -import { TransactionBlock } from '@iota/iota-sdk/transactions'; +import { Transaction } from '@iota/iota-sdk/transactions'; const { execSync } = require('child_process'); // Generate a new Ed25519 Keypair @@ -293,15 +293,15 @@ const { modules, dependencies } = JSON.parse( encoding: 'utf-8', }), ); -const tx = new TransactionBlock(); +const tx = new Transaction(); const [upgradeCap] = tx.publish({ modules, dependencies, }); tx.transferObjects([upgradeCap], await client.getAddress()); -const result = await client.signAndExecuteTransactionBlock({ +const result = await client.signAndExecuteTransaction({ signer: keypair, - transactionBlock: tx, + transaction: tx, }); console.log({ result }); ``` @@ -361,7 +361,7 @@ import { getFullnodeUrl, IotaClient } from '@iota/iota-sdk/client'; const client = new IotaClient({ url: getFullnodeUrl('testnet'), }); -const txn = await client.getTransactionBlock({ +const txn = await client.getTransaction({ digest: '9XFneskU8tW7UxQf7tE5qFRfcN4FadtC2Z3HAZkgeETd=', // only fetch the effects field options: { @@ -374,7 +374,7 @@ const txn = await client.getTransactionBlock({ }); // You can also fetch multiple transactions in one batch request -const txns = await client.multiGetTransactionBlocks({ +const txns = await client.multiGetTransactions({ digests: [ '9XFneskU8tW7UxQf7tE5qFRfcN4FadtC2Z3HAZkgeETd=', '17mn5W1CczLwitHCO9OIUbqirNrQ0cuKdyxaNe16SAME=', diff --git a/sdk/typescript/src/client/client.ts b/sdk/typescript/src/client/client.ts index ab709b764d2..e1fd627a2bc 100644 --- a/sdk/typescript/src/client/client.ts +++ b/sdk/typescript/src/client/client.ts @@ -413,7 +413,6 @@ export class IotaClient { transactionBlock, signature, options, - requestType, }: ExecuteTransactionBlockParams): Promise { const result: IotaTransactionBlockResponse = await this.transport.request({ method: 'iota_executeTransactionBlock', @@ -424,16 +423,6 @@ export class IotaClient { ], }); - if (requestType === 'WaitForLocalExecution') { - try { - await this.waitForTransaction({ - digest: result.digest, - }); - } catch (_) { - // Ignore error while waiting for transaction - } - } - return result; } diff --git a/sdk/typescript/test/e2e/read-transactions.test.ts b/sdk/typescript/test/e2e/read-transactions.test.ts index d7d91c19840..57489004ab8 100644 --- a/sdk/typescript/test/e2e/read-transactions.test.ts +++ b/sdk/typescript/test/e2e/read-transactions.test.ts @@ -35,7 +35,6 @@ describe('Transaction Reading API', () => { return toolbox.client.signAndExecuteTransaction({ signer: toolbox.keypair, transaction: tx, - requestType: 'WaitForEffectsCert', }); } diff --git a/sdk/typescript/test/e2e/utils/setup.ts b/sdk/typescript/test/e2e/utils/setup.ts index 6867ebb4d16..192aba48fc5 100644 --- a/sdk/typescript/test/e2e/utils/setup.ts +++ b/sdk/typescript/test/e2e/utils/setup.ts @@ -326,9 +326,16 @@ export async function payIota( showEffects: true, showObjectChanges: true, }, - requestType: 'WaitForLocalExecution', }); + try { + await client.waitForTransaction({ + digest: txn.digest, + }); + } catch (_) { + // Ignore error while waiting for transaction + } + expect(txn.effects?.status.status).toEqual('success'); return txn; } diff --git a/sdk/wallet-standard/src/features/index.ts b/sdk/wallet-standard/src/features/index.ts index ad97f8d891b..dcf4efdd6dd 100644 --- a/sdk/wallet-standard/src/features/index.ts +++ b/sdk/wallet-standard/src/features/index.ts @@ -12,22 +12,15 @@ import type { import type { IotaReportTransactionEffectsFeature } from './iotaReportTransactionEffects.js'; import type { IotaSignAndExecuteTransactionFeature } from './iotaSignAndExecuteTransaction.js'; -import type { IotaSignAndExecuteTransactionBlockFeature } from './iotaSignAndExecuteTransactionBlock.js'; -import type { IotaSignMessageFeature } from './iotaSignMessage.js'; import type { IotaSignPersonalMessageFeature } from './iotaSignPersonalMessage.js'; import type { IotaSignTransactionFeature } from './iotaSignTransaction.js'; -import type { IotaSignTransactionBlockFeature } from './iotaSignTransactionBlock.js'; /** * Wallet Standard features that are unique to IOTA, and that all IOTA wallets are expected to implement. */ -export type IotaFeatures = Partial & - Partial & - IotaSignPersonalMessageFeature & +export type IotaFeatures = IotaSignPersonalMessageFeature & IotaSignAndExecuteTransactionFeature & IotaSignTransactionFeature & - // This deprecated feature should be removed once wallets update to the new method: - Partial & Partial; export type IotaWalletFeatures = StandardConnectFeature & @@ -50,10 +43,7 @@ export type WalletWithRequiredFeatures = WalletWithFeatures< export type MinimallyRequiredFeatures = StandardConnectFeature & StandardEventsFeature; -export * from './iotaSignMessage.js'; -export * from './iotaSignTransactionBlock.js'; export * from './iotaSignTransaction.js'; -export * from './iotaSignAndExecuteTransactionBlock.js'; export * from './iotaSignAndExecuteTransaction.js'; export * from './iotaSignPersonalMessage.js'; export * from './iotaReportTransactionEffects.js'; diff --git a/sdk/wallet-standard/src/features/iotaSignAndExecuteTransaction.ts b/sdk/wallet-standard/src/features/iotaSignAndExecuteTransaction.ts index a2eb60b9d52..fd759c1ba4a 100644 --- a/sdk/wallet-standard/src/features/iotaSignAndExecuteTransaction.ts +++ b/sdk/wallet-standard/src/features/iotaSignAndExecuteTransaction.ts @@ -2,6 +2,7 @@ // Modifications Copyright (c) 2024 IOTA Stiftung // SPDX-License-Identifier: Apache-2.0 +import type { IotaTransactionBlockResponseOptions } from '@iota/iota-sdk/client'; import type { SignedTransaction, IotaSignTransactionInput } from './iotaSignTransaction.js'; /** The latest API version of the signAndExecuteTransactionBlock API. */ @@ -26,7 +27,10 @@ export type IotaSignAndExecuteTransactionMethod = ( ) => Promise; /** Input for signing and sending transactions. */ -export interface IotaSignAndExecuteTransactionInput extends IotaSignTransactionInput {} +export interface IotaSignAndExecuteTransactionInput extends IotaSignTransactionInput { + /** specify which fields to return (e.g., transaction, effects, events, etc). By default, only the transaction digest will be returned. */ + options?: IotaTransactionBlockResponseOptions; +} /** Output of signing and sending transactions. */ export interface IotaSignAndExecuteTransactionOutput extends SignedTransaction { diff --git a/sdk/wallet-standard/src/features/iotaSignAndExecuteTransactionBlock.ts b/sdk/wallet-standard/src/features/iotaSignAndExecuteTransactionBlock.ts deleted file mode 100644 index 5d25085c625..00000000000 --- a/sdk/wallet-standard/src/features/iotaSignAndExecuteTransactionBlock.ts +++ /dev/null @@ -1,49 +0,0 @@ -// Copyright (c) Mysten Labs, Inc. -// Modifications Copyright (c) 2024 IOTA Stiftung -// SPDX-License-Identifier: Apache-2.0 - -import type { - ExecuteTransactionRequestType, - IotaTransactionBlockResponse, - IotaTransactionBlockResponseOptions, -} from '@iota/iota-sdk/client'; - -import type { IotaSignTransactionBlockInput } from './iotaSignTransactionBlock.js'; - -/** The latest API version of the signAndExecuteTransactionBlock API. */ -export type IotaSignAndExecuteTransactionBlockVersion = '1.0.0'; - -/** - * @deprecated Use `iota:signAndExecuteTransaction` instead. - * - * A Wallet Standard feature for signing a transaction, and submitting it to the - * network. The wallet is expected to submit the transaction to the network via RPC, - * and return the transaction response. - */ -export type IotaSignAndExecuteTransactionBlockFeature = { - /** Namespace for the feature. */ - 'iota:signAndExecuteTransactionBlock': { - /** Version of the feature API. */ - version: IotaSignAndExecuteTransactionBlockVersion; - /** @deprecated Use `iota:signAndExecuteTransaction` instead. */ - signAndExecuteTransactionBlock: IotaSignAndExecuteTransactionBlockMethod; - }; -}; - -/** @deprecated Use `iota:signAndExecuteTransaction` instead. */ -export type IotaSignAndExecuteTransactionBlockMethod = ( - input: IotaSignAndExecuteTransactionBlockInput, -) => Promise; - -/** Input for signing and sending transactions. */ -export interface IotaSignAndExecuteTransactionBlockInput extends IotaSignTransactionBlockInput { - /** - * @deprecated requestType will be ignored by JSON RPC in the future - */ - requestType?: ExecuteTransactionRequestType; - /** specify which fields to return (e.g., transaction, effects, events, etc). By default, only the transaction digest will be returned. */ - options?: IotaTransactionBlockResponseOptions; -} - -/** Output of signing and sending transactions. */ -export interface IotaSignAndExecuteTransactionBlockOutput extends IotaTransactionBlockResponse {} diff --git a/sdk/wallet-standard/src/features/iotaSignMessage.ts b/sdk/wallet-standard/src/features/iotaSignMessage.ts deleted file mode 100644 index 3689589e6cb..00000000000 --- a/sdk/wallet-standard/src/features/iotaSignMessage.ts +++ /dev/null @@ -1,49 +0,0 @@ -// Copyright (c) Mysten Labs, Inc. -// Modifications Copyright (c) 2024 IOTA Stiftung -// SPDX-License-Identifier: Apache-2.0 - -import type { WalletAccount } from '@wallet-standard/core'; - -/** - * The latest API version of the signMessage API. - * @deprecated Wallets can still implement this method for compatibility, but this has been replaced by the `iota:signPersonalMessage` feature - */ -export type IotaSignMessageVersion = '1.0.0'; - -/** - * A Wallet Standard feature for signing a personal message, and returning the - * message bytes that were signed, and message signature. - * - * @deprecated Wallets can still implement this method for compatibility, but this has been replaced by the `iota:signPersonalMessage` feature - */ -export type IotaSignMessageFeature = { - /** Namespace for the feature. */ - 'iota:signMessage': { - /** Version of the feature API. */ - version: IotaSignMessageVersion; - signMessage: IotaSignMessageMethod; - }; -}; - -/** @deprecated Wallets can still implement this method for compatibility, but this has been replaced by the `iota:signPersonalMessage` feature */ -export type IotaSignMessageMethod = (input: IotaSignMessageInput) => Promise; - -/** - * Input for signing messages. - * @deprecated Wallets can still implement this method for compatibility, but this has been replaced by the `iota:signPersonalMessage` feature - */ -export interface IotaSignMessageInput { - message: Uint8Array; - account: WalletAccount; -} - -/** - * Output of signing messages. - * @deprecated Wallets can still implement this method for compatibility, but this has been replaced by the `iota:signPersonalMessage` feature - */ -export interface IotaSignMessageOutput { - /** Base64 message bytes. */ - messageBytes: string; - /** Base64 encoded signature */ - signature: string; -} diff --git a/sdk/wallet-standard/src/features/iotaSignTransaction.ts b/sdk/wallet-standard/src/features/iotaSignTransaction.ts index 7451cb778ca..d4dd0d4fef8 100644 --- a/sdk/wallet-standard/src/features/iotaSignTransaction.ts +++ b/sdk/wallet-standard/src/features/iotaSignTransaction.ts @@ -40,3 +40,5 @@ export interface SignedTransaction { /** Base64 encoded signature */ signature: string; } + +export interface IotaSignTransactionOutput extends SignedTransaction {} diff --git a/sdk/wallet-standard/src/features/iotaSignTransactionBlock.ts b/sdk/wallet-standard/src/features/iotaSignTransactionBlock.ts deleted file mode 100644 index 3deb8bebe9d..00000000000 --- a/sdk/wallet-standard/src/features/iotaSignTransactionBlock.ts +++ /dev/null @@ -1,47 +0,0 @@ -// Copyright (c) Mysten Labs, Inc. -// Modifications Copyright (c) 2024 IOTA Stiftung -// SPDX-License-Identifier: Apache-2.0 - -import type { Transaction } from '@iota/iota-sdk/transactions'; -import type { IdentifierString, WalletAccount } from '@wallet-standard/core'; - -/** The latest API version of the signTransactionBlock API. */ -export type IotaSignTransactionBlockVersion = '1.0.0'; - -/** - * @deprecated Use `iota:signTransaction` instead. - * - * A Wallet Standard feature for signing a transaction, and returning the - * serialized transaction and transaction signature. - */ -export type IotaSignTransactionBlockFeature = { - /** Namespace for the feature. */ - 'iota:signTransactionBlock': { - /** Version of the feature API. */ - version: IotaSignTransactionBlockVersion; - /** @deprecated Use `iota:signTransaction` instead. */ - signTransactionBlock: IotaSignTransactionBlockMethod; - }; -}; - -/** @deprecated Use `iota:signTransaction` instead. */ -export type IotaSignTransactionBlockMethod = ( - input: IotaSignTransactionBlockInput, -) => Promise; - -/** Input for signing transactions. */ -export interface IotaSignTransactionBlockInput { - transactionBlock: Transaction; - account: WalletAccount; - chain: IdentifierString; -} - -/** Output of signing transactions. */ -export interface IotaSignTransactionBlockOutput extends SignedTransactionBlock {} - -export interface SignedTransactionBlock { - /** Transaction as base64 encoded bcs. */ - transactionBlockBytes: string; - /** Base64 encoded signature */ - signature: string; -} diff --git a/sdk/wallet-standard/src/wallet.ts b/sdk/wallet-standard/src/wallet.ts index 6176dff2c0c..d427387664c 100644 --- a/sdk/wallet-standard/src/wallet.ts +++ b/sdk/wallet-standard/src/wallet.ts @@ -2,9 +2,6 @@ // Modifications Copyright (c) 2024 IOTA Stiftung // SPDX-License-Identifier: Apache-2.0 -import { bcs } from '@iota/iota-sdk/bcs'; -import { Transaction } from '@iota/iota-sdk/transactions'; -import { fromB64, toB64 } from '@iota/iota-sdk/utils'; import type { WalletWithFeatures } from '@wallet-standard/core'; import type { @@ -34,69 +31,24 @@ export async function signAndExecuteTransaction( wallet: WalletWithFeatures>, input: IotaSignAndExecuteTransactionInput, ) { - if (wallet.features['iota:signAndExecuteTransaction']) { - return wallet.features['iota:signAndExecuteTransaction'].signAndExecuteTransaction(input); - } - - if (!wallet.features['iota:signAndExecuteTransactionBlock']) { + if (!wallet.features['iota:signAndExecuteTransaction']) { throw new Error( `Provided wallet (${wallet.name}) does not support the signAndExecuteTransaction feature.`, ); } - const { signAndExecuteTransactionBlock } = - wallet.features['iota:signAndExecuteTransactionBlock']; - - const transactionBlock = Transaction.from(await input.transaction.toJSON()); - const { digest, rawEffects, rawTransaction } = await signAndExecuteTransactionBlock({ - account: input.account, - chain: input.chain, - transactionBlock, - options: { - showRawEffects: true, - showRawInput: true, - }, - }); - - const [ - { - txSignatures: [signature], - intentMessage: { value: bcsTransaction }, - }, - ] = bcs.SenderSignedData.parse(fromB64(rawTransaction!)); - - const bytes = bcs.TransactionData.serialize(bcsTransaction).toBase64(); - - return { - digest, - signature, - bytes, - effects: toB64(new Uint8Array(rawEffects!)), - }; + return wallet.features['iota:signAndExecuteTransaction'].signAndExecuteTransaction(input); } export async function signTransaction( wallet: WalletWithFeatures>, input: IotaSignTransactionInput, ) { - if (wallet.features['iota:signTransaction']) { - return wallet.features['iota:signTransaction'].signTransaction(input); - } - - if (!wallet.features['iota:signTransactionBlock']) { + if (!wallet.features['iota:signTransaction']) { throw new Error( `Provided wallet (${wallet.name}) does not support the signTransaction feature.`, ); } - const { signTransactionBlock } = wallet.features['iota:signTransactionBlock']; - - const transaction = Transaction.from(await input.transaction.toJSON()); - const { transactionBlockBytes, signature } = await signTransactionBlock({ - transactionBlock: transaction, - account: input.account, - chain: input.chain, - }); - - return { bytes: transactionBlockBytes, signature }; + return wallet.features['iota:signTransaction'].signTransaction(input); }