Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(sdk): Remove deprecated sdk wallet standard methods #3560

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
fde34da
refactor(sdk): Remove deprecated sdk wallet standard methods
marc2332 Oct 22, 2024
a766f38
prettier fix sdk
marc2332 Oct 22, 2024
eeb4741
prettier fix wallet standard
marc2332 Oct 22, 2024
4bfb083
clean up import
marc2332 Oct 22, 2024
9ac7e68
prettier fix dapp-kit
marc2332 Oct 22, 2024
ea8028b
prettier fix explorer
marc2332 Oct 22, 2024
c01617a
clean up
marc2332 Oct 22, 2024
7eb35f8
remove fallback test of deprecated feature
marc2332 Oct 22, 2024
918054c
Merge branch 'develop' into tooling-sdk/remove-deprecated-wallet-stan…
marc2332 Oct 23, 2024
68d4d46
Merge branch 'develop' into tooling-sdk/remove-deprecated-wallet-stan…
marc2332 Oct 23, 2024
105698f
fix test
marc2332 Oct 23, 2024
221387f
fix the actual test that is failing
marc2332 Oct 23, 2024
d1f265e
try-catch
marc2332 Oct 23, 2024
bea61e0
run apps-backend in wallet e2e tests
marc2332 Oct 24, 2024
82b3d5c
disable graphql tests for now
marc2332 Oct 24, 2024
d5d43c4
update start script of apps-backend in e2e
marc2332 Oct 24, 2024
beb1c34
Merge branch 'develop' into tooling-sdk/remove-deprecated-wallet-stan…
marc2332 Oct 25, 2024
9d7a98c
start apps backend
marc2332 Oct 25, 2024
d7ddc41
fix StakingCard.tsx
marc2332 Oct 29, 2024
04bae3a
fmt
marc2332 Oct 29, 2024
533acd3
revert experiments
marc2332 Oct 29, 2024
8eb0978
Merge branch 'develop' into tooling-sdk/remove-deprecated-wallet-stan…
marc2332 Oct 29, 2024
69688e4
Merge branch 'develop' into tooling-sdk/remove-deprecated-wallet-stan…
marc2332 Nov 4, 2024
6358b70
Merge branch 'develop' into tooling-sdk/remove-deprecated-wallet-stan…
msarcev Nov 4, 2024
984b52a
feat(tooling-sdk): Swap WaitForLocalExecution with .waitForTransactio…
msarcev Nov 4, 2024
ce2b810
Merge branch 'develop' into tooling-sdk/remove-deprecated-wallet-stan…
msarcev Nov 4, 2024
2c38cb7
Merge branch 'develop' into tooling-sdk/remove-deprecated-wallet-stan…
lucas-tortora Nov 4, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading