Skip to content

Commit

Permalink
refactor(sdk): Remove deprecated sdk wallet standard methods (#3560)
Browse files Browse the repository at this point in the history
* refactor(sdk): Remove deprecated sdk wallet standard methods

* prettier fix sdk

* prettier fix wallet standard

* clean up import

* prettier fix dapp-kit

* prettier fix explorer

* clean up

* remove fallback test of deprecated feature

* fix test

* fix the actual test that is failing

* try-catch

* run apps-backend in wallet e2e tests

* disable graphql tests for now

* update start script of  apps-backend in e2e

* start apps backend

* fix StakingCard.tsx

* fmt

* revert experiments

* feat(tooling-sdk): Swap WaitForLocalExecution with .waitForTransaction in kiosk e2e

---------

Co-authored-by: Mario <[email protected]>
Co-authored-by: Lucas Tortora <[email protected]>
  • Loading branch information
3 people authored Nov 4, 2024
1 parent 6eabd18 commit 4ccd89d
Show file tree
Hide file tree
Showing 40 changed files with 174 additions and 618 deletions.
1 change: 0 additions & 1 deletion apps/explorer/tests/utils/localnet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ export async function split_coin(address: string) {
showEffects: true,
showEvents: true,
},
requestType: 'WaitForLocalExecution',
});

return result;
Expand Down
11 changes: 5 additions & 6 deletions apps/wallet/src/background/Transactions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -68,12 +67,12 @@ class Transactions {
return txSigned!;
}

public async signMessage(
public async signPersonalMessage(
{ accountAddress, message }: Required<Pick<SignMessageRequest, 'args'>>['args'],
connection: ContentScriptConnection,
): Promise<IotaSignMessageOutput> {
): Promise<IotaSignPersonalMessageOutput> {
const { txResult, txResultError } = await this.requestApproval(
{ type: 'sign-message', accountAddress, message },
{ type: 'sign-personal-message', accountAddress, message },
connection.origin,
connection.originFavIcon,
);
Expand All @@ -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<Record<string, ApprovalRequest>> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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<SignMessageRequest>(
{ type: 'sign-message-request', return: result },
{ type: 'sign-personal-message-request', return: result },
msg.id,
),
);
Expand Down
92 changes: 3 additions & 89 deletions apps/wallet/src/dapp-interface/WalletStandardInterface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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<SignTransactionRequest, SignTransactionResponse>({
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<SignTransactionRequest, SignTransactionResponse>({
Expand All @@ -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<ExecuteTransactionRequest, ExecuteTransactionResponse>({
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<ExecuteTransactionRequest, ExecuteTransactionResponse>({
Expand Down Expand Up @@ -309,28 +244,10 @@ export class IotaWallet implements Wallet {
);
};

#signMessage: IotaSignMessageMethod = async ({ message, account }) => {
return mapToPromise(
this.#send<SignMessageRequest, SignMessageRequest>({
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<SignMessageRequest, SignMessageRequest>({
type: 'sign-message-request',
type: 'sign-personal-message-request',
args: {
message: toB64(message),
accountAddress: account.address,
Expand All @@ -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;
},
);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,20 @@
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 = {
type: 'transaction';
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;
};
Expand All @@ -29,31 +28,32 @@ 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<ApprovalRequest, 'txResult' | 'tx'> {
export interface SignPersonalMessageApprovalRequest
extends Omit<ApprovalRequest, 'txResult' | 'tx'> {
tx: SignMessageDataType;
txResult?: IotaSignMessageOutput;
txResult?: IotaSignPersonalMessageOutput;
}

export interface TransactionApprovalRequest extends Omit<ApprovalRequest, 'txResult' | 'tx'> {
tx: TransactionDataType;
txResult?: IotaTransactionBlockResponse;
}

export function isSignMessageApprovalRequest(
export function isSignPersonalMessageApprovalRequest(
request: ApprovalRequest,
): request is SignMessageApprovalRequest {
return request.tx.type === 'sign-message';
): request is SignPersonalMessageApprovalRequest {
return request.tx.type === 'sign-personal-message';
}

export function isTransactionApprovalRequest(
request: ApprovalRequest,
): request is TransactionApprovalRequest {
return request.tx.type !== 'sign-message';
return request.tx.type === 'transaction';
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import { isBasePayload } from '_payloads';
import type { BasePayload, Payload } from '_payloads';
import { type IotaSignTransactionBlockInput } from '@iota/wallet-standard';
import { type IotaSignTransactionInput } from '@iota/wallet-standard';

import { type TransactionDataType } from './ApprovalRequest';

Expand All @@ -20,8 +20,8 @@ export function isExecuteTransactionRequest(
}

export type IotaSignTransactionSerialized = Omit<
IotaSignTransactionBlockInput,
'transactionBlock' | 'account'
IotaSignTransactionInput,
'transaction' | 'account'
> & {
transaction: string;
account: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Loading

0 comments on commit 4ccd89d

Please sign in to comment.