Skip to content

Commit

Permalink
[wallet-adapter] Wire through options for request type (MystenLabs#7944)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jordan-Mysten authored Feb 1, 2023
1 parent fe574ee commit 96e883f
Show file tree
Hide file tree
Showing 9 changed files with 59 additions and 13 deletions.
8 changes: 8 additions & 0 deletions .changeset/hungry-rabbits-fetch.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
"@mysten/wallet-adapter-wallet-standard": minor
"@mysten/wallet-adapter-unsafe-burner": minor
"@mysten/wallet-adapter-base": minor
"@mysten/wallet-standard": minor
---

Update wallet adapter and wallet standard to support passing through the desired request type.
3 changes: 2 additions & 1 deletion apps/wallet/src/dapp-interface/WalletStandardInterface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ export class SuiWallet implements Wallet {
on: this.#on,
},
'sui:signAndExecuteTransaction': {
version: '1.0.0',
version: '1.1.0',
signAndExecuteTransaction: this.#signAndExecuteTransaction,
},
'suiWallet:stake': {
Expand Down Expand Up @@ -216,6 +216,7 @@ export class SuiWallet implements Wallet {
transaction: {
type: 'v2',
data: input.transaction,
options: input.options,
},
}),
(response) => response.result
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
// Copyright (c) Mysten Labs, Inc.
// SPDX-License-Identifier: Apache-2.0

import { type SuiSignAndExecuteTransactionOptions } from '@mysten/wallet-standard';

import { isBasePayload } from '_payloads';

import type { MoveCallTransaction, SignableTransaction } from '@mysten/sui.js';
import type { BasePayload, Payload } from '_payloads';

export type TransactionDataType =
| { type: 'v2'; data: SignableTransaction }
| {
type: 'v2';
data: SignableTransaction;
options?: SuiSignAndExecuteTransactionOptions;
}
| { type: 'move-call'; data: MoveCallTransaction }
| { type: 'serialized-move-call'; data: string };

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,12 @@ export const respondToTransactionRequest = createAsyncThunk<
}
: txRequest.tx.data;

response = await signer.signAndExecuteTransaction(txn);
response = await signer.signAndExecuteTransaction(
txn,
txRequest.tx.type === 'v2'
? txRequest.tx.options?.requestType
: undefined
);
} else if (txRequest.tx.type === 'serialized-move-call') {
const txBytes = new Base64DataBuffer(txRequest.tx.data);
response = await signer.signAndExecuteTransaction(txBytes);
Expand Down
6 changes: 5 additions & 1 deletion sdk/wallet-adapter/adapters/base-adapter/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// SPDX-License-Identifier: Apache-2.0

import {
ExecuteTransactionRequestType,
SignableTransaction,
SuiAddress,
SuiTransactionResponse,
Expand Down Expand Up @@ -29,7 +30,10 @@ export interface WalletAdapter {
* Suggest a transaction for the user to sign. Supports all valid transaction types.
*/
signAndExecuteTransaction(
transaction: SignableTransaction
transaction: SignableTransaction,
options?: {
requestType?: ExecuteTransactionRequestType;
}
): Promise<SuiTransactionResponse>;

getAccounts: () => Promise<SuiAddress[]>;
Expand Down
11 changes: 9 additions & 2 deletions sdk/wallet-adapter/adapters/unsafe-burner/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

import {
Ed25519Keypair,
ExecuteTransactionRequestType,
getCertifiedTransaction,
getTransactionEffects,
JsonRpcProvider,
Expand Down Expand Up @@ -48,8 +49,14 @@ export class UnsafeBurnerWalletAdapter implements WalletAdapter {
return [this.#keypair.getPublicKey().toSuiAddress()];
}

async signAndExecuteTransaction(transaction: SignableTransaction) {
const response = await this.#signer.signAndExecuteTransaction(transaction);
async signAndExecuteTransaction(
transaction: SignableTransaction,
options?: { requestType?: ExecuteTransactionRequestType }
) {
const response = await this.#signer.signAndExecuteTransaction(
transaction,
options?.requestType
);

return {
certificate: getCertifiedTransaction(response)!,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
// Copyright (c) Mysten Labs, Inc.
// SPDX-License-Identifier: Apache-2.0

import { SignableTransaction } from "@mysten/sui.js";
import {
ExecuteTransactionRequestType,
SignableTransaction,
} from "@mysten/sui.js";
import {
WalletAdapter,
WalletAdapterEvents,
Expand Down Expand Up @@ -86,11 +89,15 @@ export class StandardWalletAdapter implements WalletAdapter {
}
}

async signAndExecuteTransaction(transaction: SignableTransaction) {
async signAndExecuteTransaction(
transaction: SignableTransaction,
options?: { requestType?: ExecuteTransactionRequestType }
) {
return this.#wallet.features[
"sui:signAndExecuteTransaction"
].signAndExecuteTransaction({
transaction,
options,
});
}

Expand Down
11 changes: 8 additions & 3 deletions sdk/wallet-adapter/wallet-kit-core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// SPDX-License-Identifier: Apache-2.0

import {
ExecuteTransactionRequestType,
SignableTransaction,
SuiAddress,
SuiTransactionResponse,
Expand Down Expand Up @@ -46,7 +47,8 @@ export interface WalletKitCore {
connect(walletName: string): Promise<void>;
disconnect(): Promise<void>;
signAndExecuteTransaction(
transaction: SignableTransaction
transaction: SignableTransaction,
options?: { requestType?: ExecuteTransactionRequestType }
): Promise<SuiTransactionResponse>;
}

Expand Down Expand Up @@ -198,14 +200,17 @@ export function createWalletKitCore({
disconnected();
},

signAndExecuteTransaction(transaction) {
signAndExecuteTransaction(transaction, options) {
if (!internalState.currentWallet) {
throw new Error(
"No wallet is currently connected, cannot call `signAndExecuteTransaction`."
);
}

return internalState.currentWallet.signAndExecuteTransaction(transaction);
return internalState.currentWallet.signAndExecuteTransaction(
transaction,
options
);
},
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@
// SPDX-License-Identifier: Apache-2.0

import type {
ExecuteTransactionRequestType,
SignableTransaction,
SuiTransactionResponse,
} from "@mysten/sui.js";

/** The latest API version of the signAndExecuteTransaction API. */
export type SuiSignAndExecuteTransactionVersion = "1.0.0";
export type SuiSignAndExecuteTransactionVersion = "1.1.0";

/**
* A Wallet Standard feature for signing a transaction, and submitting it to the
Expand Down Expand Up @@ -38,4 +39,6 @@ export interface SuiSignAndExecuteTransactionOutput
extends SuiTransactionResponse {}

/** Options for signing and sending transactions. */
export interface SuiSignAndExecuteTransactionOptions {}
export interface SuiSignAndExecuteTransactionOptions {
requestType?: ExecuteTransactionRequestType;
}

0 comments on commit 96e883f

Please sign in to comment.