Skip to content

Commit

Permalink
support new signAndSubmitTransaction standard function (#304)
Browse files Browse the repository at this point in the history
* support new signAndSubmitTransaction standard function

* address feedback

* upgrade wallet-standard version

* minor version upgrade
  • Loading branch information
0xmaayan authored Jun 5, 2024
1 parent d0e4862 commit fa16215
Show file tree
Hide file tree
Showing 7 changed files with 67 additions and 13 deletions.
5 changes: 5 additions & 0 deletions .changeset/happy-pens-speak.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@aptos-labs/wallet-adapter-core": minor
---

Support signAndSubmitTransaction standard function feature version 1.1.0
2 changes: 1 addition & 1 deletion packages/wallet-adapter-core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
"typescript": "^4.5.3"
},
"dependencies": {
"@aptos-labs/wallet-standard": "^0.0.11",
"@aptos-labs/wallet-standard": "^0.1.0",
"buffer": "^6.0.3",
"eventemitter3": "^4.0.7",
"tweetnacl": "^1.0.3",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,17 +56,50 @@ export class WalletStandardCore {
transactionInput: InputTransactionData,
aptos: Aptos,
account: AccountInfo,
wallet: Wallet
): Promise<PendingTransactionResponse> {
wallet: Wallet,
standardWallets: ReadonlyArray<AptosStandardWallet>
): Promise<AptosSignAndSubmitTransactionOutput> {
try {
const transaction = await aptos.transaction.build.simple({
sender: account.address.toString(),
data: transactionInput.data,
options: transactionInput.options,
});
// need to find the standard wallet type to do the
// next features check
const standardWallet = standardWallets.find(
(standardWallet: AptosStandardWallet) =>
wallet.name === standardWallet.name
);

// check for backward compatibility. before version 1.1.0 the standard expected
// AnyRawTransaction input so the adapter built the transaction before sending it to the wallet
if (
standardWallet?.features["aptos:signAndSubmitTransaction"]?.version !==
"1.1.0"
) {
const transaction = await aptos.transaction.build.simple({
sender: account.address.toString(),
data: transactionInput.data,
options: transactionInput.options,
});
const response = (await wallet.signAndSubmitTransaction!(
transaction
)) as UserResponse<AptosSignAndSubmitTransactionOutput>;

if (response.status === UserResponseStatus.REJECTED) {
throw new WalletConnectionError("User has rejected the request")
.message;
}

return response.args;
}

// build standard json format
const transaction = {
gasUnitPrice: transactionInput.options?.gasUnitPrice,
maxGasAmount: transactionInput.options?.maxGasAmount,
payload: transactionInput.data,
};
const response = (await wallet.signAndSubmitTransaction!(
transaction
)) as UserResponse<AptosSignAndSubmitTransactionOutput>;

if (response.status === UserResponseStatus.REJECTED) {
throw new WalletConnectionError("User has rejected the request")
.message;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import { AptosStandardWallet } from "./WalletStandard";

const sdkWallets: AptosStandardWallet[] = [];

sdkWallets.push(new TWallet());
// TODO twallet uses @aptos-labs/wallet-standard at version 0.0.11 while adapter uses
// a newer version (0.1.0) - this causes type mismatch. We should figure out how to handle it.
sdkWallets.push(new TWallet() as any);

export default sdkWallets;
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
InputGenerateTransactionPayloadData,
AnyRawTransaction,
Signature,
AccountAuthenticator,
} from "@aptos-labs/ts-sdk";
import { WalletReadyState } from "../constants";
import {
Expand All @@ -17,6 +18,7 @@ import {
AccountInfo as StandardAccountInfo,
NetworkInfo as StandardNetworkInfo,
AptosChangeNetworkMethod,
AptosSignAndSubmitTransactionInput,
} from "@aptos-labs/wallet-standard";
import { AptosStandardSupportedWallet } from "../AIP62StandardWallets/types";

Expand Down Expand Up @@ -126,7 +128,8 @@ export interface AdapterPluginProps<Name extends string = string> {
transaction:
| Types.TransactionPayload
| InputTransactionData
| AnyRawTransaction,
| AnyRawTransaction
| AptosSignAndSubmitTransactionInput,
options?: InputGenerateTransactionOptions
): Promise<
| { hash: Types.HexEncodedBytes; output?: any }
Expand Down
3 changes: 2 additions & 1 deletion packages/wallet-adapter-core/src/WalletCore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -732,7 +732,8 @@ export class WalletCore extends EventEmitter<WalletCoreEvents> {
transactionInput,
aptos,
this._account,
this._wallet
this._wallet,
this._standard_wallets
);
return { hash, output };
} else {
Expand Down
14 changes: 12 additions & 2 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit fa16215

Please sign in to comment.