@aptos-labs/wallet-adapter-core
Advanced tools
Comparing version 2.6.0 to 3.0.0
# @aptos-labs/wallet-adapter-core | ||
## 3.0.0 | ||
### Major Changes | ||
- 31e0084: Support TypeScript SDK V2. Fully compatible with existing SDK V1 and Wallet Adapter V1 | ||
but with a full SDK V2 support for the dapp. | ||
- Add support for SDK V2 input types | ||
- `signAndSubmitTransaction()` accept only SDK V2 transaction input type | ||
- Implement a `submitTransaction()` function for multi signers transactions | ||
- `signTransaction()` to support both SDK V1 and V2 versions | ||
- Convert wallet `SignedTransaction` response from `signTransaction()` to TS SDK V2 `AccountAuthenticator` | ||
- Demo app to demonstrate different trnsaction flows - single signer, sponsor and multi agent transactions | ||
- Reject promise on core and/or provider errors instead of just returning `false` | ||
- Use `@aptos-labs/ts-sdk@experimental` version `0.0.7` | ||
## 2.6.0 | ||
@@ -4,0 +20,0 @@ |
@@ -1,5 +0,5 @@ | ||
import { Types, TxnBuilderTypes } from 'aptos'; | ||
import { Types } from 'aptos'; | ||
export { TxnBuilderTypes, Types } from 'aptos'; | ||
import { InputGenerateTransactionData } from '@aptos-labs/ts-sdk'; | ||
export { InputGenerateTransactionData } from '@aptos-labs/ts-sdk'; | ||
import { Network, InputGenerateTransactionData, InputGenerateTransactionOptions, PendingTransactionResponse, InputSubmitTransactionData, AnyRawTransaction, AccountAuthenticator } from '@aptos-labs/ts-sdk'; | ||
export { AccountAuthenticator, AnyRawTransaction, InputGenerateTransactionData, InputGenerateTransactionOptions, InputSubmitTransactionData, PendingTransactionResponse } from '@aptos-labs/ts-sdk'; | ||
import EventEmitter from 'eventemitter3'; | ||
@@ -36,6 +36,11 @@ | ||
type NetworkInfo = { | ||
name: NetworkName; | ||
name: Network; | ||
chainId?: string; | ||
url?: string; | ||
}; | ||
type WalletInfo = { | ||
name: WalletName; | ||
icon: string; | ||
url: string; | ||
}; | ||
type AccountInfo = { | ||
@@ -52,46 +57,2 @@ address: string; | ||
} | ||
type OnNetworkChange = (callBack: (networkInfo: NetworkInfo) => Promise<void>) => Promise<void>; | ||
interface PluginProvider { | ||
connect: () => Promise<AccountInfo>; | ||
account: () => Promise<AccountInfo>; | ||
disconnect: () => Promise<void>; | ||
signAndSubmitTransaction: (transaction: any, options?: any) => Promise<{ | ||
hash: Types.HexEncodedBytes; | ||
} | AptosWalletErrorResult>; | ||
signMessage: (message: SignMessagePayload) => Promise<SignMessageResponse>; | ||
network: () => Promise<NetworkName>; | ||
onAccountChange: (listener: (newAddress: AccountInfo) => Promise<void>) => Promise<void>; | ||
onNetworkChange: OnNetworkChange; | ||
signMultiAgentTransaction: (rawTxn: TxnBuilderTypes.MultiAgentRawTransaction | TxnBuilderTypes.FeePayerRawTransaction) => Promise<string>; | ||
} | ||
interface AdapterPluginEvents { | ||
onNetworkChange: OnNetworkChange; | ||
onAccountChange(callback: any): Promise<any>; | ||
} | ||
interface AdapterPluginProps<Name extends string = string> { | ||
name: WalletName<Name>; | ||
url: string; | ||
icon: `data:image/${"svg+xml" | "webp" | "png" | "gif"};base64,${string}`; | ||
providerName?: string; | ||
provider: any; | ||
deeplinkProvider?: (data: { | ||
url: string; | ||
}) => string; | ||
connect(): Promise<any>; | ||
disconnect: () => Promise<any>; | ||
network: () => Promise<any>; | ||
signAndSubmitTransaction<T extends Types.TransactionPayload, V>(transaction: T, options?: V): Promise<{ | ||
hash: Types.HexEncodedBytes; | ||
}>; | ||
signMessage<T extends SignMessagePayload>(message: T): Promise<SignMessageResponse>; | ||
} | ||
type AdapterPlugin<Name extends string = string> = AdapterPluginProps<Name> & AdapterPluginEvents; | ||
type Wallet<Name extends string = string> = AdapterPlugin<Name> & { | ||
readyState?: WalletReadyState; | ||
}; | ||
type WalletInfo = { | ||
name: WalletName; | ||
icon: string; | ||
url: string; | ||
}; | ||
declare interface WalletCoreEvents { | ||
@@ -122,2 +83,32 @@ connect(account: AccountInfo | null): void; | ||
} | ||
type OnNetworkChange = (callBack: (networkInfo: NetworkInfo) => Promise<void>) => Promise<void>; | ||
type OnAccountChange = (callBack: (accountInfo: AccountInfo) => Promise<any>) => Promise<void>; | ||
interface AdapterPluginEvents { | ||
onNetworkChange: OnNetworkChange; | ||
onAccountChange: OnAccountChange; | ||
} | ||
interface AdapterPluginProps<Name extends string = string> { | ||
name: WalletName<Name>; | ||
url: string; | ||
icon: `data:image/${"svg+xml" | "webp" | "png" | "gif"};base64,${string}`; | ||
version?: "v1" | "v2"; | ||
providerName?: string; | ||
provider: any; | ||
deeplinkProvider?: (data: { | ||
url: string; | ||
}) => string; | ||
connect(): Promise<any>; | ||
disconnect: () => Promise<any>; | ||
network: () => Promise<any>; | ||
signAndSubmitTransaction<V>(transaction: Types.TransactionPayload | InputGenerateTransactionData, options?: InputGenerateTransactionOptions): Promise<{ | ||
hash: Types.HexEncodedBytes; | ||
output?: any; | ||
} | PendingTransactionResponse>; | ||
submitTransaction?(transaction: InputSubmitTransactionData): Promise<PendingTransactionResponse>; | ||
signMessage<T extends SignMessagePayload>(message: T): Promise<SignMessageResponse>; | ||
} | ||
type AdapterPlugin<Name extends string = string> = AdapterPluginProps<Name> & AdapterPluginEvents; | ||
type Wallet<Name extends string = string> = AdapterPlugin<Name> & { | ||
readyState?: WalletReadyState; | ||
}; | ||
interface TransactionOptions { | ||
@@ -133,2 +124,3 @@ max_gas_amount?: bigint; | ||
private _network; | ||
private readonly waletCoreV1; | ||
private _connecting; | ||
@@ -169,3 +161,3 @@ private _connected; | ||
*/ | ||
connect(walletName: WalletName): Promise<void | string>; | ||
connect(walletName: string): Promise<void | string>; | ||
/** | ||
@@ -189,25 +181,23 @@ * Connects a wallet to the dapp. | ||
/** | ||
Sign and submit an entry (not bcs serialized) transaction type to chain. | ||
@param transaction a non-bcs serialized transaction | ||
@param options max_gas_amount and gas_unit_limit | ||
@return response from the wallet's signAndSubmitTransaction function | ||
@throws WalletSignAndSubmitMessageError | ||
*/ | ||
signAndSubmitTransaction(transaction: Types.TransactionPayload, options?: TransactionOptions): Promise<any>; | ||
/** | ||
Sign and submit a bsc serialized transaction type to chain. | ||
@param transaction a bcs serialized transaction | ||
@param options max_gas_amount and gas_unit_limit | ||
@return response from the wallet's signAndSubmitBCSTransaction function | ||
@throws WalletSignAndSubmitMessageError | ||
* Signs and submits a transaction to chain | ||
* | ||
* @param transactionInput InputGenerateTransactionData | ||
* @param options optional. A configuration object to generate a transaction by | ||
* @returns The pending transaction hash (V1 output) | PendingTransactionResponse (V2 output) | ||
*/ | ||
signAndSubmitBCSTransaction(transaction: TxnBuilderTypes.TransactionPayload, options?: TransactionOptions): Promise<any>; | ||
signAndSubmitTransaction(transactionInput: InputGenerateTransactionData, options?: InputGenerateTransactionOptions): Promise<{ | ||
hash: Types.HexEncodedBytes; | ||
output?: any; | ||
} | PendingTransactionResponse>; | ||
/** | ||
Sign transaction (doesnt submit to chain). | ||
@param transaction | ||
@param options max_gas_amount and gas_unit_limit | ||
@return response from the wallet's signTransaction function | ||
@throws WalletSignTransactionError | ||
* Signs a transaction | ||
* | ||
* To support both existing wallet adapter V1 and V2, we support 2 input types | ||
* | ||
* @param transactionOrPayload AnyRawTransaction - V2 input | Types.TransactionPayload - V1 input | ||
* @param options optional. V1 input | ||
* | ||
* @returns AccountAuthenticator | ||
*/ | ||
signTransaction(transaction: Types.TransactionPayload, options?: TransactionOptions): Promise<Uint8Array | null>; | ||
signTransaction(transactionOrPayload: AnyRawTransaction | Types.TransactionPayload, asFeePayer?: boolean, options?: InputGenerateTransactionOptions): Promise<AccountAuthenticator>; | ||
/** | ||
@@ -219,18 +209,5 @@ Sign message (doesnt submit to chain). | ||
*/ | ||
signMessage(message: SignMessagePayload): Promise<SignMessageResponse | null>; | ||
signMessage(message: SignMessagePayload): Promise<SignMessageResponse>; | ||
submitTransaction(transaction: InputSubmitTransactionData): Promise<PendingTransactionResponse>; | ||
/** | ||
* This function is for signing and submitting a transaction using the `@aptos-labs/ts-sdk` (aka the v2 SDK) | ||
* input types. It's internally converting the input types to the old SDK input types and then calling | ||
* the v1 SDK's `signAndSubmitBCSTransaction` with it. | ||
* | ||
* @param transactionInput the transaction input | ||
* @param options max_gas_amount and gas_unit_limit | ||
* @returns the response from the wallet's signAndSubmitBCSTransaction function | ||
*/ | ||
submitTransaction(transactionInput: InputGenerateTransactionData, options?: TransactionOptions): Promise<{ | ||
hash: string; | ||
output?: any; | ||
}>; | ||
signMultiAgentTransaction(transaction: TxnBuilderTypes.MultiAgentRawTransaction | TxnBuilderTypes.FeePayerRawTransaction): Promise<string | null>; | ||
/** | ||
Event for when account has changed on the wallet | ||
@@ -247,2 +224,7 @@ @return the new account info | ||
onNetworkChange(): Promise<void>; | ||
/** | ||
* Signs a message and verifies the signer | ||
* @param message SignMessagePayload | ||
* @returns boolean | ||
*/ | ||
signMessageAndVerify(message: SignMessagePayload): Promise<boolean>; | ||
@@ -260,3 +242,4 @@ } | ||
declare function isRedirectable(): boolean; | ||
declare function generalizedErrorMessage(error: any): string; | ||
export { AccountInfo, AdapterPlugin, AdapterPluginEvents, AdapterPluginProps, AptosWalletErrorResult, NetworkInfo, NetworkName, OnNetworkChange, PluginProvider, SignMessagePayload, SignMessageResponse, TransactionOptions, Wallet, WalletCore, WalletCoreEvents, WalletInfo, WalletName, WalletReadyState, getLocalStorage, isInAppBrowser, isMobile, isRedirectable, removeLocalStorage, scopePollingDetectionStrategy, setLocalStorage }; | ||
export { AccountInfo, AdapterPlugin, AdapterPluginEvents, AdapterPluginProps, AptosWalletErrorResult, NetworkInfo, NetworkName, OnAccountChange, OnNetworkChange, SignMessagePayload, SignMessageResponse, TransactionOptions, Wallet, WalletCore, WalletCoreEvents, WalletInfo, WalletName, WalletReadyState, generalizedErrorMessage, getLocalStorage, isInAppBrowser, isMobile, isRedirectable, removeLocalStorage, scopePollingDetectionStrategy, setLocalStorage }; |
@@ -34,2 +34,3 @@ "use strict"; | ||
WalletReadyState: () => WalletReadyState, | ||
generalizedErrorMessage: () => generalizedErrorMessage, | ||
getLocalStorage: () => getLocalStorage, | ||
@@ -48,3 +49,3 @@ isInAppBrowser: () => isInAppBrowser, | ||
var import_ts_sdk2 = require("@aptos-labs/ts-sdk"); | ||
var import_eventemitter3 = __toESM(require("eventemitter3")); | ||
var import_eventemitter32 = __toESM(require("eventemitter3")); | ||
var import_tweetnacl = __toESM(require("tweetnacl")); | ||
@@ -222,2 +223,5 @@ var import_buffer = require("buffer"); | ||
} | ||
function generalizedErrorMessage(error) { | ||
return typeof error === "object" && "message" in error ? error.message : error; | ||
} | ||
@@ -259,9 +263,72 @@ // src/ans.ts | ||
} | ||
function convertToBCSPayload(payload) { | ||
function convertV2TransactionPayloadToV1BCSPayload(payload) { | ||
const deserializer = new import_aptos.BCS.Deserializer(payload.bcsToBytes()); | ||
return import_aptos.TxnBuilderTypes.TransactionPayload.deserialize(deserializer); | ||
} | ||
function convertV2PayloadToV1JSONPayload(payload) { | ||
var _a; | ||
if ("bytecode" in payload) { | ||
throw new Error("script payload not supported"); | ||
} else { | ||
const stringTypeTags = (_a = payload.typeArguments) == null ? void 0 : _a.map( | ||
(typeTag) => { | ||
if (typeTag instanceof import_ts_sdk.TypeTag) { | ||
return typeTag.toString(); | ||
} | ||
return typeTag; | ||
} | ||
); | ||
const newPayload = { | ||
type: "entry_function_payload", | ||
function: payload.function, | ||
type_arguments: stringTypeTags || [], | ||
arguments: payload.functionArguments | ||
}; | ||
return newPayload; | ||
} | ||
} | ||
// src/WalletCoreV1.ts | ||
var import_eventemitter3 = __toESM(require("eventemitter3")); | ||
var WalletCoreV1 = class extends import_eventemitter3.default { | ||
async signAndSubmitTransaction(transaction, wallet, options) { | ||
try { | ||
const response = await wallet.signAndSubmitTransaction( | ||
transaction, | ||
options | ||
); | ||
return response; | ||
} catch (error) { | ||
const errMsg = typeof error == "object" && "message" in error ? error.message : error; | ||
throw new WalletSignAndSubmitMessageError(errMsg).message; | ||
} | ||
} | ||
async signAndSubmitBCSTransaction(transaction, wallet, options) { | ||
try { | ||
const response = await wallet.signAndSubmitBCSTransaction( | ||
transaction, | ||
options | ||
); | ||
return response; | ||
} catch (error) { | ||
const errMsg = typeof error == "object" && "message" in error ? error.message : error; | ||
throw new WalletSignAndSubmitMessageError(errMsg).message; | ||
} | ||
} | ||
async signTransaction(transaction, wallet, options) { | ||
try { | ||
const response = await wallet.signTransaction( | ||
transaction, | ||
options | ||
); | ||
return response; | ||
} catch (error) { | ||
const errMsg = typeof error == "object" && "message" in error ? error.message : error; | ||
throw new WalletSignTransactionError(errMsg).message; | ||
} | ||
} | ||
}; | ||
// src/WalletCore.ts | ||
var WalletCore = class extends import_eventemitter3.default { | ||
var WalletCore = class extends import_eventemitter32.default { | ||
constructor(plugins) { | ||
@@ -273,2 +340,3 @@ super(); | ||
this._network = null; | ||
this.waletCoreV1 = new WalletCoreV1(); | ||
this._connecting = false; | ||
@@ -404,3 +472,3 @@ this._connected = false; | ||
this.clearData(); | ||
const errMsg = typeof error == "object" && "message" in error ? error.message : error; | ||
const errMsg = generalizedErrorMessage(error); | ||
throw new WalletConnectionError(errMsg).message; | ||
@@ -419,55 +487,98 @@ } finally { | ||
} catch (error) { | ||
const errMsg = typeof error == "object" && "message" in error ? error.message : error; | ||
const errMsg = generalizedErrorMessage(error); | ||
throw new WalletDisconnectionError(errMsg).message; | ||
} | ||
} | ||
async signAndSubmitTransaction(transaction, options) { | ||
async signAndSubmitTransaction(transactionInput, options) { | ||
var _a; | ||
try { | ||
this.doesWalletExist(); | ||
const response = await ((_a = this._wallet) == null ? void 0 : _a.signAndSubmitTransaction( | ||
transaction, | ||
options | ||
)); | ||
return response; | ||
} catch (error) { | ||
const errMsg = typeof error == "object" && "message" in error ? error.message : error; | ||
throw new WalletSignAndSubmitMessageError(errMsg).message; | ||
} | ||
} | ||
async signAndSubmitBCSTransaction(transaction, options) { | ||
var _a; | ||
if (this._wallet && !("signAndSubmitBCSTransaction" in this._wallet)) { | ||
throw new WalletNotSupportedMethod( | ||
`Submit a BCS Transaction is not supported by ${(_a = this.wallet) == null ? void 0 : _a.name}` | ||
).message; | ||
} | ||
try { | ||
this.doesWalletExist(); | ||
const response = await this._wallet.signAndSubmitBCSTransaction( | ||
transaction, | ||
options | ||
if (((_a = this._wallet) == null ? void 0 : _a.version) === "v2") { | ||
const response2 = await this._wallet.signAndSubmitTransaction( | ||
transactionInput, | ||
options | ||
); | ||
return response2; | ||
} | ||
const payloadData = transactionInput.data; | ||
if (typeof payloadData.functionArguments[0] === "object") { | ||
const aptosConfig = new import_ts_sdk2.AptosConfig({ | ||
network: convertNetwork(this._network) | ||
}); | ||
const newPayload = await (0, import_ts_sdk2.generateTransactionPayload)({ | ||
...payloadData, | ||
aptosConfig | ||
}); | ||
const oldTransactionPayload2 = convertV2TransactionPayloadToV1BCSPayload(newPayload); | ||
const response2 = await this.waletCoreV1.signAndSubmitBCSTransaction( | ||
oldTransactionPayload2, | ||
this._wallet, | ||
{ | ||
max_gas_amount: (options == null ? void 0 : options.maxGasAmount) ? BigInt(options == null ? void 0 : options.maxGasAmount) : void 0, | ||
gas_unit_price: (options == null ? void 0 : options.gasUnitPrice) ? BigInt(options == null ? void 0 : options.gasUnitPrice) : void 0 | ||
} | ||
); | ||
const { hash: hash2, ...output2 } = response2; | ||
return { hash: hash2, output: output2 }; | ||
} | ||
const oldTransactionPayload = convertV2PayloadToV1JSONPayload(payloadData); | ||
const response = await this.waletCoreV1.signAndSubmitTransaction( | ||
oldTransactionPayload, | ||
this._wallet, | ||
{ | ||
max_gas_amount: (options == null ? void 0 : options.maxGasAmount) ? BigInt(options == null ? void 0 : options.maxGasAmount) : void 0, | ||
gas_unit_price: (options == null ? void 0 : options.gasUnitPrice) ? BigInt(options == null ? void 0 : options.gasUnitPrice) : void 0 | ||
} | ||
); | ||
return response; | ||
const { hash, ...output } = response; | ||
return { hash, output }; | ||
} catch (error) { | ||
const errMsg = typeof error == "object" && "message" in error ? error.message : error; | ||
const errMsg = generalizedErrorMessage(error); | ||
throw new WalletSignAndSubmitMessageError(errMsg).message; | ||
} | ||
} | ||
async signTransaction(transaction, options) { | ||
var _a; | ||
if (this._wallet && !("signTransaction" in this._wallet)) { | ||
throw new WalletNotSupportedMethod( | ||
`Sign Transaction is not supported by ${(_a = this.wallet) == null ? void 0 : _a.name}` | ||
).message; | ||
} | ||
async signTransaction(transactionOrPayload, asFeePayer, options) { | ||
var _a, _b, _c; | ||
try { | ||
this.doesWalletExist(); | ||
const response = await this._wallet.signTransaction( | ||
transaction, | ||
options | ||
if ("rawTransaction" in transactionOrPayload) { | ||
if (((_a = this._wallet) == null ? void 0 : _a.version) !== "v2") { | ||
throw new WalletNotSupportedMethod( | ||
`Sign Transaction V2 is not supported by ${(_b = this.wallet) == null ? void 0 : _b.name}` | ||
).message; | ||
} | ||
const accountAuthenticator2 = this._wallet.signTransaction( | ||
transactionOrPayload, | ||
asFeePayer | ||
); | ||
return accountAuthenticator2; | ||
} | ||
if (this._wallet && !("signTransaction" in this._wallet)) { | ||
throw new WalletNotSupportedMethod( | ||
`Sign Transaction is not supported by ${(_c = this.wallet) == null ? void 0 : _c.name}` | ||
).message; | ||
} | ||
const response = await this.waletCoreV1.signTransaction( | ||
transactionOrPayload, | ||
this._wallet, | ||
{ | ||
max_gas_amount: (options == null ? void 0 : options.maxGasAmount) ? BigInt(options == null ? void 0 : options.maxGasAmount) : void 0, | ||
gas_unit_price: (options == null ? void 0 : options.gasUnitPrice) ? BigInt(options == null ? void 0 : options.gasUnitPrice) : void 0 | ||
} | ||
); | ||
return response; | ||
if (!response) { | ||
throw new Error("error"); | ||
} | ||
const deserializer1 = new import_aptos2.BCS.Deserializer(response); | ||
const deserializedSignature = import_aptos2.TxnBuilderTypes.SignedTransaction.deserialize(deserializer1); | ||
const transactionAuthenticator = deserializedSignature.authenticator; | ||
const publicKey = transactionAuthenticator.public_key.value; | ||
const signature = transactionAuthenticator.signature.value; | ||
const accountAuthenticator = new import_ts_sdk2.AccountAuthenticatorEd25519( | ||
new import_ts_sdk2.Ed25519PublicKey(publicKey), | ||
new import_ts_sdk2.Ed25519Signature(signature) | ||
); | ||
return accountAuthenticator; | ||
} catch (error) { | ||
const errMsg = typeof error == "object" && "message" in error ? error.message : error; | ||
const errMsg = generalizedErrorMessage(error); | ||
throw new WalletSignTransactionError(errMsg).message; | ||
@@ -477,28 +588,16 @@ } | ||
async signMessage(message) { | ||
var _a; | ||
try { | ||
this.doesWalletExist(); | ||
if (!this._wallet) | ||
return null; | ||
const response = await ((_a = this._wallet) == null ? void 0 : _a.signMessage(message)); | ||
const response = await this._wallet.signMessage(message); | ||
return response; | ||
} catch (error) { | ||
const errMsg = typeof error == "object" && "message" in error ? error.message : error; | ||
const errMsg = generalizedErrorMessage(error); | ||
throw new WalletSignMessageError(errMsg).message; | ||
} | ||
} | ||
async submitTransaction(transactionInput, options) { | ||
const payloadData = transactionInput.data; | ||
const aptosConfig = new import_ts_sdk2.AptosConfig({ network: convertNetwork(this._network) }); | ||
const newPayload = await (0, import_ts_sdk2.generateTransactionPayload)({ ...payloadData, aptosConfig }); | ||
const oldTransactionPayload = convertToBCSPayload(newPayload); | ||
const response = await this.signAndSubmitBCSTransaction(oldTransactionPayload, options); | ||
const { hash, ...output } = response; | ||
return { hash, output }; | ||
} | ||
async signMultiAgentTransaction(transaction) { | ||
async submitTransaction(transaction) { | ||
var _a; | ||
if (this._wallet && !("signMultiAgentTransaction" in this._wallet)) { | ||
if (this._wallet && !("submitTransaction" in this._wallet)) { | ||
throw new WalletNotSupportedMethod( | ||
`Multi-agent & sponsored transactions are not supported by ${(_a = this.wallet) == null ? void 0 : _a.name}` | ||
`Submit Transaction is not supported by ${(_a = this.wallet) == null ? void 0 : _a.name}` | ||
).message; | ||
@@ -508,8 +607,8 @@ } | ||
this.doesWalletExist(); | ||
const response = await this._wallet.signMultiAgentTransaction( | ||
const pendingTransaction = this._wallet.submitTransaction( | ||
transaction | ||
); | ||
return response; | ||
return pendingTransaction; | ||
} catch (error) { | ||
const errMsg = typeof error == "object" && "message" in error ? error.message : error; | ||
const errMsg = generalizedErrorMessage(error); | ||
throw new WalletSignTransactionError(errMsg).message; | ||
@@ -528,3 +627,3 @@ } | ||
} catch (error) { | ||
const errMsg = typeof error == "object" && "message" in error ? error.message : error; | ||
const errMsg = generalizedErrorMessage(error); | ||
throw new WalletAccountChangeError(errMsg).message; | ||
@@ -543,3 +642,3 @@ } | ||
} catch (error) { | ||
const errMsg = typeof error == "object" && "message" in error ? error.message : error; | ||
const errMsg = generalizedErrorMessage(error); | ||
throw new WalletNetworkChangeError(errMsg).message; | ||
@@ -602,3 +701,3 @@ } | ||
} catch (error) { | ||
const errMsg = typeof error == "object" && "message" in error ? error.message : error; | ||
const errMsg = generalizedErrorMessage(error); | ||
throw new WalletSignMessageAndVerifyError(errMsg).message; | ||
@@ -618,2 +717,3 @@ } | ||
WalletReadyState, | ||
generalizedErrorMessage, | ||
getLocalStorage, | ||
@@ -620,0 +720,0 @@ isInAppBrowser, |
{ | ||
"name": "@aptos-labs/wallet-adapter-core", | ||
"version": "2.6.0", | ||
"version": "3.0.0", | ||
"description": "Aptos Wallet Adapter Core", | ||
@@ -41,3 +41,2 @@ "main": "./dist/index.js", | ||
"dependencies": { | ||
"@aptos-labs/ts-sdk": "^0.0.3", | ||
"buffer": "^6.0.3", | ||
@@ -48,3 +47,4 @@ "eventemitter3": "^4.0.7", | ||
"peerDependencies": { | ||
"aptos": "^1.19.0" | ||
"aptos": "^1.19.0", | ||
"@aptos-labs/ts-sdk": "^0.0.7" | ||
}, | ||
@@ -51,0 +51,0 @@ "scripts": { |
@@ -1,24 +0,57 @@ | ||
import { Network, AnyTransactionPayloadInstance } from "@aptos-labs/ts-sdk" | ||
import { BCS, TxnBuilderTypes } from "aptos" | ||
import { | ||
Network, | ||
TransactionPayload, | ||
InputGenerateTransactionPayloadData, | ||
TypeTag, | ||
} from "@aptos-labs/ts-sdk"; | ||
import { BCS, TxnBuilderTypes, Types } from "aptos"; | ||
import { NetworkInfo } from "./types"; | ||
import { NetworkName } from "./constants"; | ||
// old => new | ||
export function convertNetwork(networkInfo: NetworkInfo | null): Network { | ||
switch(networkInfo?.name.toLowerCase()) { | ||
case "mainnet" as NetworkName: | ||
return Network.MAINNET; | ||
case "testnet" as NetworkName: | ||
return Network.TESTNET; | ||
case "devnet" as NetworkName: | ||
return Network.DEVNET; | ||
default: | ||
throw new Error("Invalid network name") | ||
} | ||
switch (networkInfo?.name.toLowerCase()) { | ||
case "mainnet" as Network: | ||
return Network.MAINNET; | ||
case "testnet" as Network: | ||
return Network.TESTNET; | ||
case "devnet" as Network: | ||
return Network.DEVNET; | ||
default: | ||
throw new Error("Invalid network name"); | ||
} | ||
} | ||
// new => old | ||
export function convertToBCSPayload(payload: AnyTransactionPayloadInstance): TxnBuilderTypes.TransactionPayload { | ||
const deserializer = new BCS.Deserializer(payload.bcsToBytes()); | ||
return TxnBuilderTypes.TransactionPayload.deserialize(deserializer); | ||
export function convertV2TransactionPayloadToV1BCSPayload( | ||
payload: TransactionPayload | ||
): TxnBuilderTypes.TransactionPayload { | ||
const deserializer = new BCS.Deserializer(payload.bcsToBytes()); | ||
return TxnBuilderTypes.TransactionPayload.deserialize(deserializer); | ||
} | ||
export function convertV2PayloadToV1JSONPayload( | ||
payload: InputGenerateTransactionPayloadData | ||
): Types.TransactionPayload { | ||
if ("bytecode" in payload) { | ||
// is a script payload | ||
throw new Error("script payload not supported"); | ||
} else { | ||
// is entry function payload | ||
const stringTypeTags: string[] | undefined = payload.typeArguments?.map( | ||
(typeTag) => { | ||
if (typeTag instanceof TypeTag) { | ||
return typeTag.toString(); | ||
} | ||
return typeTag; | ||
} | ||
); | ||
const newPayload: Types.TransactionPayload = { | ||
type: "entry_function_payload", | ||
function: payload.function, | ||
type_arguments: stringTypeTags || [], | ||
arguments: payload.functionArguments, | ||
}; | ||
return newPayload; | ||
} | ||
} |
130
src/types.ts
@@ -1,6 +0,21 @@ | ||
import { TxnBuilderTypes, Types } from "aptos"; | ||
import { NetworkName, WalletReadyState } from "./constants"; | ||
import { Types } from "aptos"; | ||
import { | ||
Network, | ||
InputGenerateTransactionData, | ||
InputGenerateTransactionOptions, | ||
InputSubmitTransactionData, | ||
PendingTransactionResponse, | ||
} from "@aptos-labs/ts-sdk"; | ||
import { WalletReadyState } from "./constants"; | ||
export { TxnBuilderTypes, Types } from "aptos"; | ||
export type { InputGenerateTransactionData } from "@aptos-labs/ts-sdk"; | ||
export type { | ||
InputGenerateTransactionData, | ||
InputGenerateTransactionOptions, | ||
AnyRawTransaction, | ||
InputSubmitTransactionData, | ||
PendingTransactionResponse, | ||
AccountAuthenticator, | ||
} from "@aptos-labs/ts-sdk"; | ||
// WalletName is a nominal type that wallet adapters should use, e.g. `'MyCryptoWallet' as WalletName<'MyCryptoWallet'>` | ||
@@ -10,4 +25,5 @@ export type WalletName<T extends string = string> = T & { | ||
}; | ||
export type NetworkInfo = { | ||
name: NetworkName; | ||
name: Network; | ||
chainId?: string; | ||
@@ -17,2 +33,8 @@ url?: string; | ||
export type WalletInfo = { | ||
name: WalletName; | ||
icon: string; | ||
url: string; | ||
}; | ||
export type AccountInfo = { | ||
@@ -31,2 +53,30 @@ address: string; | ||
export declare interface WalletCoreEvents { | ||
connect(account: AccountInfo | null): void; | ||
disconnect(): void; | ||
readyStateChange(wallet: Wallet): void; | ||
networkChange(network: NetworkInfo | null): void; | ||
accountChange(account: AccountInfo | null): void; | ||
} | ||
export interface SignMessagePayload { | ||
address?: boolean; // Should we include the address of the account in the message | ||
application?: boolean; // Should we include the domain of the dapp | ||
chainId?: boolean; // Should we include the current chain id the wallet is connected to | ||
message: string; // The message to be signed and displayed to the user | ||
nonce: string; // A nonce the dapp should generate | ||
} | ||
export interface SignMessageResponse { | ||
address?: string; | ||
application?: string; | ||
chainId?: number; | ||
fullMessage: string; // The message that was generated to sign | ||
message: string; // The message passed in by the user | ||
nonce: string; | ||
prefix: "APTOS"; // Should always be APTOS | ||
signature: string | string[]; // The signed full message | ||
bitmap?: Uint8Array; // a 4-byte (32 bits) bit-vector of length N | ||
} | ||
export type OnNetworkChange = ( | ||
@@ -36,26 +86,12 @@ callBack: (networkInfo: NetworkInfo) => Promise<void> | ||
export interface PluginProvider { | ||
connect: () => Promise<AccountInfo>; | ||
account: () => Promise<AccountInfo>; | ||
disconnect: () => Promise<void>; | ||
signAndSubmitTransaction: ( | ||
transaction: any, | ||
options?: any | ||
) => Promise<{ hash: Types.HexEncodedBytes } | AptosWalletErrorResult>; | ||
signMessage: (message: SignMessagePayload) => Promise<SignMessageResponse>; | ||
network: () => Promise<NetworkName>; | ||
onAccountChange: ( | ||
listener: (newAddress: AccountInfo) => Promise<void> | ||
) => Promise<void>; | ||
onNetworkChange: OnNetworkChange; | ||
signMultiAgentTransaction: ( | ||
rawTxn: TxnBuilderTypes.MultiAgentRawTransaction | TxnBuilderTypes.FeePayerRawTransaction | ||
) => Promise<string>; | ||
} | ||
export type OnAccountChange = ( | ||
callBack: (accountInfo: AccountInfo) => Promise<any> | ||
) => Promise<void>; | ||
export interface AdapterPluginEvents { | ||
onNetworkChange: OnNetworkChange; | ||
onAccountChange(callback: any): Promise<any>; | ||
onAccountChange: OnAccountChange; | ||
} | ||
// TODO add signTransaction() | ||
export interface AdapterPluginProps<Name extends string = string> { | ||
@@ -65,2 +101,3 @@ name: WalletName<Name>; | ||
icon: `data:image/${"svg+xml" | "webp" | "png" | "gif"};base64,${string}`; | ||
version?: "v1" | "v2"; | ||
providerName?: string; | ||
@@ -72,6 +109,11 @@ provider: any; | ||
network: () => Promise<any>; | ||
signAndSubmitTransaction<T extends Types.TransactionPayload, V>( | ||
transaction: T, | ||
options?: V | ||
): Promise<{ hash: Types.HexEncodedBytes }>; | ||
signAndSubmitTransaction<V>( | ||
transaction: Types.TransactionPayload | InputGenerateTransactionData, | ||
options?: InputGenerateTransactionOptions | ||
): Promise< | ||
{ hash: Types.HexEncodedBytes; output?: any } | PendingTransactionResponse | ||
>; | ||
submitTransaction?( | ||
transaction: InputSubmitTransactionData | ||
): Promise<PendingTransactionResponse>; | ||
signMessage<T extends SignMessagePayload>( | ||
@@ -89,36 +131,2 @@ message: T | ||
export type WalletInfo = { | ||
name: WalletName; | ||
icon: string; | ||
url: string; | ||
}; | ||
export declare interface WalletCoreEvents { | ||
connect(account: AccountInfo | null): void; | ||
disconnect(): void; | ||
readyStateChange(wallet: Wallet): void; | ||
networkChange(network: NetworkInfo | null): void; | ||
accountChange(account: AccountInfo | null): void; | ||
} | ||
export interface SignMessagePayload { | ||
address?: boolean; // Should we include the address of the account in the message | ||
application?: boolean; // Should we include the domain of the dapp | ||
chainId?: boolean; // Should we include the current chain id the wallet is connected to | ||
message: string; // The message to be signed and displayed to the user | ||
nonce: string; // A nonce the dapp should generate | ||
} | ||
export interface SignMessageResponse { | ||
address?: string; | ||
application?: string; | ||
chainId?: number; | ||
fullMessage: string; // The message that was generated to sign | ||
message: string; // The message passed in by the user | ||
nonce: string; | ||
prefix: "APTOS"; // Should always be APTOS | ||
signature: string | string[]; // The signed full message | ||
bitmap?: Uint8Array; // a 4-byte (32 bits) bit-vector of length N | ||
} | ||
export interface TransactionOptions { | ||
@@ -125,0 +133,0 @@ max_gas_amount?: bigint; |
@@ -21,3 +21,3 @@ export function isMobile(): boolean { | ||
// SSR: return false | ||
if (typeof navigator === 'undefined' || !navigator) return false; | ||
if (typeof navigator === "undefined" || !navigator) return false; | ||
@@ -28,1 +28,7 @@ // if we are on mobile and NOT in a in-app browser we will redirect to a wallet app | ||
} | ||
export function generalizedErrorMessage(error: any): string { | ||
return typeof error === "object" && "message" in error | ||
? error.message | ||
: error; | ||
} |
@@ -1,3 +0,16 @@ | ||
import { HexString, TxnBuilderTypes, Types } from "aptos"; | ||
import { AptosConfig, InputGenerateTransactionData, generateTransactionPayload } from "@aptos-labs/ts-sdk"; | ||
import { HexString, TxnBuilderTypes, Types, BCS } from "aptos"; | ||
import { | ||
InputGenerateTransactionData, | ||
AnyRawTransaction, | ||
AccountAuthenticator, | ||
AccountAuthenticatorEd25519, | ||
Ed25519PublicKey, | ||
InputGenerateTransactionOptions, | ||
Ed25519Signature, | ||
AptosConfig, | ||
generateTransactionPayload, | ||
InputSubmitTransactionData, | ||
PendingTransactionResponse, | ||
InputEntryFunctionDataWithRemoteABI, | ||
} from "@aptos-labs/ts-sdk"; | ||
import EventEmitter from "eventemitter3"; | ||
@@ -27,9 +40,7 @@ import nacl from "tweetnacl"; | ||
NetworkInfo, | ||
WalletName, | ||
SignMessagePayload, | ||
SignMessageResponse, | ||
Wallet, | ||
WalletInfo, | ||
WalletCoreEvents, | ||
TransactionOptions, | ||
SignMessageResponse, | ||
} from "./types"; | ||
@@ -41,6 +52,11 @@ import { | ||
isRedirectable, | ||
generalizedErrorMessage, | ||
} from "./utils"; | ||
import { getNameByAddress } from "./ans"; | ||
import { AccountAuthenticator } from "@aptos-labs/ts-sdk"; | ||
import { convertNetwork, convertToBCSPayload } from "./conversion"; | ||
import { | ||
convertNetwork, | ||
convertV2TransactionPayloadToV1BCSPayload, | ||
convertV2PayloadToV1JSONPayload, | ||
} from "./conversion"; | ||
import { WalletCoreV1 } from "./WalletCoreV1"; | ||
@@ -52,2 +68,3 @@ export class WalletCore extends EventEmitter<WalletCoreEvents> { | ||
private _network: NetworkInfo | null = null; | ||
private readonly waletCoreV1: WalletCoreV1 = new WalletCoreV1(); | ||
@@ -186,3 +203,3 @@ private _connecting: boolean = false; | ||
*/ | ||
async connect(walletName: WalletName): Promise<void | string> { | ||
async connect(walletName: string): Promise<void | string> { | ||
const selectedWallet = this._wallets?.find( | ||
@@ -246,4 +263,4 @@ (wallet: Wallet) => wallet.name === walletName | ||
this.clearData(); | ||
const errMsg = | ||
typeof error == "object" && "message" in error ? error.message : error; | ||
const errMsg = generalizedErrorMessage(error); | ||
throw new WalletConnectionError(errMsg).message; | ||
@@ -268,4 +285,3 @@ } finally { | ||
} catch (error: any) { | ||
const errMsg = | ||
typeof error == "object" && "message" in error ? error.message : error; | ||
const errMsg = generalizedErrorMessage(error); | ||
throw new WalletDisconnectionError(errMsg).message; | ||
@@ -276,53 +292,78 @@ } | ||
/** | ||
Sign and submit an entry (not bcs serialized) transaction type to chain. | ||
@param transaction a non-bcs serialized transaction | ||
@param options max_gas_amount and gas_unit_limit | ||
@return response from the wallet's signAndSubmitTransaction function | ||
@throws WalletSignAndSubmitMessageError | ||
*/ | ||
* Signs and submits a transaction to chain | ||
* | ||
* @param transactionInput InputGenerateTransactionData | ||
* @param options optional. A configuration object to generate a transaction by | ||
* @returns The pending transaction hash (V1 output) | PendingTransactionResponse (V2 output) | ||
*/ | ||
async signAndSubmitTransaction( | ||
transaction: Types.TransactionPayload, | ||
options?: TransactionOptions | ||
): Promise<any> { | ||
transactionInput: InputGenerateTransactionData, | ||
options?: InputGenerateTransactionOptions | ||
): Promise< | ||
{ hash: Types.HexEncodedBytes; output?: any } | PendingTransactionResponse | ||
> { | ||
try { | ||
this.doesWalletExist(); | ||
const response = await this._wallet?.signAndSubmitTransaction( | ||
transaction, | ||
options | ||
); | ||
return response; | ||
} catch (error: any) { | ||
const errMsg = | ||
typeof error == "object" && "message" in error ? error.message : error; | ||
throw new WalletSignAndSubmitMessageError(errMsg).message; | ||
} | ||
} | ||
/** | ||
Sign and submit a bsc serialized transaction type to chain. | ||
@param transaction a bcs serialized transaction | ||
@param options max_gas_amount and gas_unit_limit | ||
@return response from the wallet's signAndSubmitBCSTransaction function | ||
@throws WalletSignAndSubmitMessageError | ||
*/ | ||
async signAndSubmitBCSTransaction( | ||
transaction: TxnBuilderTypes.TransactionPayload, | ||
options?: TransactionOptions | ||
): Promise<any> { | ||
if (this._wallet && !("signAndSubmitBCSTransaction" in this._wallet)) { | ||
throw new WalletNotSupportedMethod( | ||
`Submit a BCS Transaction is not supported by ${this.wallet?.name}` | ||
).message; | ||
} | ||
// wallet supports sdk v2 | ||
if (this._wallet?.version === "v2") { | ||
const response = await this._wallet.signAndSubmitTransaction( | ||
transactionInput, | ||
options | ||
); | ||
// response should be PendingTransactionResponse | ||
return response; | ||
} | ||
try { | ||
this.doesWalletExist(); | ||
const response = await (this._wallet as any).signAndSubmitBCSTransaction( | ||
transaction, | ||
options | ||
// get the payload piece from the input | ||
const payloadData = transactionInput.data; | ||
// if first function arguments is an object (i.e a bcs serialized argument) | ||
// we assume the transaction should be a bcs serialized transaction | ||
if (typeof payloadData.functionArguments[0] === "object") { | ||
const aptosConfig = new AptosConfig({ | ||
network: convertNetwork(this._network), | ||
}); | ||
const newPayload = await generateTransactionPayload({ | ||
...(payloadData as InputEntryFunctionDataWithRemoteABI), | ||
aptosConfig: aptosConfig, | ||
}); | ||
const oldTransactionPayload = | ||
convertV2TransactionPayloadToV1BCSPayload(newPayload); | ||
const response = await this.waletCoreV1.signAndSubmitBCSTransaction( | ||
oldTransactionPayload, | ||
this._wallet!, | ||
{ | ||
max_gas_amount: options?.maxGasAmount | ||
? BigInt(options?.maxGasAmount) | ||
: undefined, | ||
gas_unit_price: options?.gasUnitPrice | ||
? BigInt(options?.gasUnitPrice) | ||
: undefined, | ||
} | ||
); | ||
const { hash, ...output } = response; | ||
return { hash, output }; | ||
} | ||
// if it is not a bcs serialized arguments transaction, convert to the old | ||
// json format | ||
const oldTransactionPayload = | ||
convertV2PayloadToV1JSONPayload(payloadData); | ||
const response = await this.waletCoreV1.signAndSubmitTransaction( | ||
oldTransactionPayload, | ||
this._wallet!, | ||
{ | ||
max_gas_amount: options?.maxGasAmount | ||
? BigInt(options?.maxGasAmount) | ||
: undefined, | ||
gas_unit_price: options?.gasUnitPrice | ||
? BigInt(options?.gasUnitPrice) | ||
: undefined, | ||
} | ||
); | ||
return response; | ||
const { hash, ...output } = response; | ||
return { hash, output }; | ||
} catch (error: any) { | ||
const errMsg = | ||
typeof error == "object" && "message" in error ? error.message : error; | ||
const errMsg = generalizedErrorMessage(error); | ||
throw new WalletSignAndSubmitMessageError(errMsg).message; | ||
@@ -333,28 +374,73 @@ } | ||
/** | ||
Sign transaction (doesnt submit to chain). | ||
@param transaction | ||
@param options max_gas_amount and gas_unit_limit | ||
@return response from the wallet's signTransaction function | ||
@throws WalletSignTransactionError | ||
* Signs a transaction | ||
* | ||
* To support both existing wallet adapter V1 and V2, we support 2 input types | ||
* | ||
* @param transactionOrPayload AnyRawTransaction - V2 input | Types.TransactionPayload - V1 input | ||
* @param options optional. V1 input | ||
* | ||
* @returns AccountAuthenticator | ||
*/ | ||
async signTransaction( | ||
transaction: Types.TransactionPayload, | ||
options?: TransactionOptions | ||
): Promise<Uint8Array | null> { | ||
if (this._wallet && !("signTransaction" in this._wallet)) { | ||
throw new WalletNotSupportedMethod( | ||
`Sign Transaction is not supported by ${this.wallet?.name}` | ||
).message; | ||
} | ||
transactionOrPayload: AnyRawTransaction | Types.TransactionPayload, | ||
asFeePayer?: boolean, | ||
options?: InputGenerateTransactionOptions | ||
): Promise<AccountAuthenticator> { | ||
try { | ||
this.doesWalletExist(); | ||
const response = await (this._wallet as any).signTransaction( | ||
transaction, | ||
options | ||
// if input is AnyRawTransaction, i.e V2 | ||
if ("rawTransaction" in transactionOrPayload) { | ||
if (this._wallet?.version !== "v2") { | ||
throw new WalletNotSupportedMethod( | ||
`Sign Transaction V2 is not supported by ${this.wallet?.name}` | ||
).message; | ||
} | ||
const accountAuthenticator = (this._wallet as any).signTransaction( | ||
transactionOrPayload, | ||
asFeePayer | ||
); | ||
return accountAuthenticator; | ||
} | ||
// check current signTransaction function exists | ||
if (this._wallet && !("signTransaction" in this._wallet)) { | ||
throw new WalletNotSupportedMethod( | ||
`Sign Transaction is not supported by ${this.wallet?.name}` | ||
).message; | ||
} | ||
const response = await this.waletCoreV1.signTransaction( | ||
transactionOrPayload as Types.TransactionPayload, | ||
this._wallet!, | ||
{ | ||
max_gas_amount: options?.maxGasAmount | ||
? BigInt(options?.maxGasAmount) | ||
: undefined, | ||
gas_unit_price: options?.gasUnitPrice | ||
? BigInt(options?.gasUnitPrice) | ||
: undefined, | ||
} | ||
); | ||
return response; | ||
if (!response) { | ||
throw new Error("error"); | ||
} | ||
// Convert retuned bcs serialized SignedTransaction into V2 AccountAuthenticator | ||
const deserializer1 = new BCS.Deserializer(response); | ||
const deserializedSignature = | ||
TxnBuilderTypes.SignedTransaction.deserialize(deserializer1); | ||
const transactionAuthenticator = | ||
deserializedSignature.authenticator as TxnBuilderTypes.TransactionAuthenticatorEd25519; | ||
const publicKey = transactionAuthenticator.public_key.value; | ||
const signature = transactionAuthenticator.signature.value; | ||
const accountAuthenticator = new AccountAuthenticatorEd25519( | ||
new Ed25519PublicKey(publicKey), | ||
new Ed25519Signature(signature) | ||
); | ||
return accountAuthenticator; | ||
} catch (error: any) { | ||
const errMsg = | ||
typeof error == "object" && "message" in error ? error.message : error; | ||
const errMsg = generalizedErrorMessage(error); | ||
throw new WalletSignTransactionError(errMsg).message; | ||
@@ -370,13 +456,9 @@ } | ||
*/ | ||
async signMessage( | ||
message: SignMessagePayload | ||
): Promise<SignMessageResponse | null> { | ||
async signMessage(message: SignMessagePayload): Promise<SignMessageResponse> { | ||
try { | ||
this.doesWalletExist(); | ||
if (!this._wallet) return null; | ||
const response = await this._wallet?.signMessage(message); | ||
const response = await this._wallet!.signMessage(message); | ||
return response; | ||
} catch (error: any) { | ||
const errMsg = | ||
typeof error == "object" && "message" in error ? error.message : error; | ||
const errMsg = generalizedErrorMessage(error); | ||
throw new WalletSignMessageError(errMsg).message; | ||
@@ -386,31 +468,8 @@ } | ||
/** | ||
* This function is for signing and submitting a transaction using the `@aptos-labs/ts-sdk` (aka the v2 SDK) | ||
* input types. It's internally converting the input types to the old SDK input types and then calling | ||
* the v1 SDK's `signAndSubmitBCSTransaction` with it. | ||
* | ||
* @param transactionInput the transaction input | ||
* @param options max_gas_amount and gas_unit_limit | ||
* @returns the response from the wallet's signAndSubmitBCSTransaction function | ||
*/ | ||
async submitTransaction( | ||
transactionInput: InputGenerateTransactionData, | ||
options?: TransactionOptions, | ||
): Promise<{ hash: string, output?: any }> { | ||
const payloadData = transactionInput.data; | ||
const aptosConfig = new AptosConfig({network: convertNetwork(this._network)}); | ||
// TODO: Refactor this any, and remove the need for it by fixing the if ("bytecode" in data) stuff in `generateTransaction` in the v2 SDK | ||
const newPayload = await generateTransactionPayload({ ...payloadData as any, aptosConfig: aptosConfig }); | ||
const oldTransactionPayload = convertToBCSPayload(newPayload); | ||
const response = await this.signAndSubmitBCSTransaction(oldTransactionPayload, options); | ||
const { hash, ...output } = response; | ||
return { hash, output }; | ||
} | ||
async signMultiAgentTransaction( | ||
transaction: TxnBuilderTypes.MultiAgentRawTransaction | TxnBuilderTypes.FeePayerRawTransaction | ||
): Promise<string | null> { | ||
if (this._wallet && !("signMultiAgentTransaction" in this._wallet)) { | ||
transaction: InputSubmitTransactionData | ||
): Promise<PendingTransactionResponse> { | ||
if (this._wallet && !("submitTransaction" in this._wallet)) { | ||
throw new WalletNotSupportedMethod( | ||
`Multi-agent & sponsored transactions are not supported by ${this.wallet?.name}` | ||
`Submit Transaction is not supported by ${this.wallet?.name}` | ||
).message; | ||
@@ -420,9 +479,9 @@ } | ||
this.doesWalletExist(); | ||
const response = await (this._wallet as any).signMultiAgentTransaction( | ||
const pendingTransaction = (this._wallet as any).submitTransaction( | ||
transaction | ||
); | ||
return response; | ||
return pendingTransaction; | ||
} catch (error: any) { | ||
const errMsg = | ||
typeof error == "object" && "message" in error ? error.message : error; | ||
const errMsg = generalizedErrorMessage(error); | ||
throw new WalletSignTransactionError(errMsg).message; | ||
@@ -446,4 +505,3 @@ } | ||
} catch (error: any) { | ||
const errMsg = | ||
typeof error == "object" && "message" in error ? error.message : error; | ||
const errMsg = generalizedErrorMessage(error); | ||
throw new WalletAccountChangeError(errMsg).message; | ||
@@ -467,4 +525,3 @@ } | ||
} catch (error: any) { | ||
const errMsg = | ||
typeof error == "object" && "message" in error ? error.message : error; | ||
const errMsg = generalizedErrorMessage(error); | ||
throw new WalletNetworkChangeError(errMsg).message; | ||
@@ -474,2 +531,7 @@ } | ||
/** | ||
* Signs a message and verifies the signer | ||
* @param message SignMessagePayload | ||
* @returns boolean | ||
*/ | ||
async signMessageAndVerify(message: SignMessagePayload): Promise<boolean> { | ||
@@ -539,4 +601,3 @@ try { | ||
} catch (error: any) { | ||
const errMsg = | ||
typeof error == "object" && "message" in error ? error.message : error; | ||
const errMsg = generalizedErrorMessage(error); | ||
throw new WalletSignMessageAndVerifyError(errMsg).message; | ||
@@ -543,0 +604,0 @@ } |
Sorry, the diff of this file is not supported yet
96413
20
2704
+ Added@aptos-labs/ts-sdk@0.0.7(transitive)
+ Added@scure/base@1.2.4(transitive)
+ Added@scure/bip32@1.6.2(transitive)
+ Added@scure/bip39@1.5.4(transitive)
+ Addedcall-bind-apply-helpers@1.0.2(transitive)
+ Addeddunder-proto@1.0.1(transitive)
+ Addedes-define-property@1.0.1(transitive)
+ Addedes-errors@1.3.0(transitive)
+ Addedes-object-atoms@1.1.1(transitive)
+ Addedes-set-tostringtag@2.1.0(transitive)
+ Addedform-data@4.0.2(transitive)
+ Addedfunction-bind@1.1.2(transitive)
+ Addedget-intrinsic@1.3.0(transitive)
+ Addedget-proto@1.0.1(transitive)
+ Addedgopd@1.2.0(transitive)
+ Addedhas-symbols@1.1.0(transitive)
+ Addedhas-tostringtag@1.0.2(transitive)
+ Addedhasown@2.0.2(transitive)
+ Addedmath-intrinsics@1.1.0(transitive)
- Removed@aptos-labs/ts-sdk@^0.0.3
- Removed@aptos-labs/ts-sdk@0.0.3(transitive)
- Removed@noble/hashes@1.1.3(transitive)
- Removed@scure/bip39@1.1.0(transitive)