Skip to content

Commit

Permalink
[core] Added transaction input support for signTransaction (#414)
Browse files Browse the repository at this point in the history
* [core] Bumped `@aptos-labs/wallet-standard` to 0.2.0 to add transaction input support

* Added changeset
  • Loading branch information
hardsetting authored Sep 6, 2024
1 parent 309edb2 commit 3795c56
Show file tree
Hide file tree
Showing 7 changed files with 441 additions and 154 deletions.
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
17 changes: 14 additions & 3 deletions packages/wallet-adapter-core/src/LegacyWalletPlugins/conversion.ts
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

0 comments on commit 3795c56

Please sign in to comment.