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

[core] Added transaction input support for signTransaction #414

Merged
merged 2 commits into from
Sep 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
5 changes: 5 additions & 0 deletions .changeset/nervous-bats-jog.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@aptos-labs/wallet-adapter-core": minor
---

Added transaction input support for `signTransaction`
4 changes: 2 additions & 2 deletions packages/wallet-adapter-core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@
"typescript": "^4.5.3"
},
"dependencies": {
"@aptos-connect/wallet-adapter-plugin": "^1.0.1",
"@aptos-labs/wallet-standard": "^0.1.0",
"@aptos-connect/wallet-adapter-plugin": "^2.0.0",
"@aptos-labs/wallet-standard": "^0.2.0",
"@atomrigslab/aptos-wallet-adapter": "^0.1.20",
"@mizuwallet-sdk/aptos-wallet-adapter": "^0.2.3",
"buffer": "^6.0.3",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {
UserResponse,
AptosSignTransactionInputV1_1,
AptosSignTransactionOutput,
AptosSignMessageOutput,
AptosSignMessageInput,
Expand All @@ -8,6 +9,7 @@ import {
AptosSignAndSubmitTransactionOutput,
AccountInfo as StandardAccountInfo,
AptosConnectOutput,
AptosSignTransactionOutputV1_1,
} from "@aptos-labs/wallet-standard";
import {
AnyPublicKey,
Expand Down Expand Up @@ -128,9 +130,18 @@ export class WalletStandardCore {
transaction: AnyRawTransaction,
wallet: Wallet,
asFeePayer?: boolean
): Promise<AptosSignTransactionOutput> {
): Promise<AptosSignTransactionOutput>
async signTransaction(
input: AptosSignTransactionInputV1_1,
wallet: Wallet,
): Promise<AptosSignTransactionOutputV1_1>
async signTransaction(
transactionOrInput: AnyRawTransaction | AptosSignTransactionInputV1_1,
wallet: Wallet,
asFeePayer?: boolean
): Promise<AptosSignTransactionOutput | AptosSignTransactionOutputV1_1> {
const response = (await wallet.signTransaction!(
transaction,
transactionOrInput,
asFeePayer
)) as UserResponse<AptosSignTransactionOutput>;
if (response.status === UserResponseStatus.REJECTED) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,16 +86,27 @@ export function convertV2PayloadToV1JSONPayload(
}
}

export async function generateTransactionPayloadFromV1Input(
aptosConfig: AptosConfig,
export function convertPayloadInputV1ToV2(
inputV1: Types.TransactionPayload
): Promise<TransactionPayloadEntryFunction> {
) {
if ("function" in inputV1) {
const inputV2: InputEntryFunctionData | InputMultiSigData = {
function: inputV1.function as MoveFunctionId,
functionArguments: inputV1.arguments,
typeArguments: inputV1.type_arguments,
};
return inputV2;
}

throw new Error("Payload type not supported");
}

export async function generateTransactionPayloadFromV1Input(
aptosConfig: AptosConfig,
inputV1: Types.TransactionPayload
): Promise<TransactionPayloadEntryFunction> {
if ("function" in inputV1) {
const inputV2 = convertPayloadInputV1ToV2(inputV1);
return generateTransactionPayload({ ...inputV2, aptosConfig });
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ export type AdapterPlugin<Name extends string = string> =
export type Wallet<Name extends string = string> = AdapterPlugin<Name> & {
readyState?: WalletReadyState;
isAIP62Standard?: boolean;
isSignTransactionV1_1?: boolean;
};

export interface TransactionOptions {
Expand Down
Loading
Loading