@aptos-labs/wallet-adapter-core
Advanced tools
Comparing version 2.5.1 to 2.6.0
# @aptos-labs/wallet-adapter-core | ||
## 2.6.0 | ||
### Minor Changes | ||
- 7acfa69: Adding support for the new Typescript SDK in the package `@aptos-labs/ts-sdk`. The wallet adapter now supports submitting a basic transaction with the new SDK types. | ||
### Patch Changes | ||
- dd6e1ed: Moves dependencies to peer dependencies as needed | ||
## 2.5.1 | ||
@@ -4,0 +14,0 @@ |
import { Types, TxnBuilderTypes } from 'aptos'; | ||
export { TxnBuilderTypes, Types } from 'aptos'; | ||
import { InputGenerateTransactionData } from '@aptos-labs/ts-sdk'; | ||
export { InputGenerateTransactionData } from '@aptos-labs/ts-sdk'; | ||
import EventEmitter from 'eventemitter3'; | ||
@@ -30,6 +32,6 @@ | ||
declare type WalletName<T extends string = string> = T & { | ||
type WalletName<T extends string = string> = T & { | ||
__brand__: "WalletName"; | ||
}; | ||
declare type NetworkInfo = { | ||
type NetworkInfo = { | ||
name: NetworkName; | ||
@@ -39,3 +41,3 @@ chainId?: string; | ||
}; | ||
declare type AccountInfo = { | ||
type AccountInfo = { | ||
address: string; | ||
@@ -51,3 +53,3 @@ publicKey: string | string[]; | ||
} | ||
declare type OnNetworkChange = (callBack: (networkInfo: NetworkInfo) => Promise<void>) => Promise<void>; | ||
type OnNetworkChange = (callBack: (networkInfo: NetworkInfo) => Promise<void>) => Promise<void>; | ||
interface PluginProvider { | ||
@@ -64,2 +66,3 @@ connect: () => Promise<AccountInfo>; | ||
onNetworkChange: OnNetworkChange; | ||
signMultiAgentTransaction: (rawTxn: TxnBuilderTypes.MultiAgentRawTransaction | TxnBuilderTypes.FeePayerRawTransaction) => Promise<string>; | ||
} | ||
@@ -87,7 +90,7 @@ interface AdapterPluginEvents { | ||
} | ||
declare type AdapterPlugin<Name extends string = string> = AdapterPluginProps<Name> & AdapterPluginEvents; | ||
declare type Wallet<Name extends string = string> = AdapterPlugin<Name> & { | ||
type AdapterPlugin<Name extends string = string> = AdapterPluginProps<Name> & AdapterPluginEvents; | ||
type Wallet<Name extends string = string> = AdapterPlugin<Name> & { | ||
readyState?: WalletReadyState; | ||
}; | ||
declare type WalletInfo = { | ||
type WalletInfo = { | ||
name: WalletName; | ||
@@ -194,25 +197,39 @@ icon: string; | ||
/** | ||
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 | ||
*/ | ||
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 | ||
*/ | ||
signAndSubmitBCSTransaction(transaction: TxnBuilderTypes.TransactionPayload, options?: TransactionOptions): Promise<any>; | ||
/** | ||
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 | ||
*/ | ||
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 | ||
*/ | ||
signTransaction(transaction: Types.TransactionPayload, options?: TransactionOptions): Promise<Uint8Array | null>; | ||
/** | ||
Sign message (doesnt submit to chain). | ||
@param message | ||
@return response from the wallet's signMessage function | ||
@throws WalletSignMessageError | ||
*/ | ||
Sign message (doesnt submit to chain). | ||
@param message | ||
@return response from the wallet's signMessage function | ||
@throws WalletSignMessageError | ||
*/ | ||
signMessage(message: SignMessagePayload): Promise<SignMessageResponse | null>; | ||
/** | ||
* 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 | ||
@@ -219,0 +236,0 @@ @return the new account info |
@@ -30,4 +30,4 @@ "use strict"; | ||
NetworkName: () => NetworkName, | ||
TxnBuilderTypes: () => import_aptos2.TxnBuilderTypes, | ||
Types: () => import_aptos2.Types, | ||
TxnBuilderTypes: () => import_aptos3.TxnBuilderTypes, | ||
Types: () => import_aptos3.Types, | ||
WalletCore: () => WalletCore, | ||
@@ -46,3 +46,4 @@ WalletReadyState: () => WalletReadyState, | ||
// src/WalletCore.ts | ||
var import_aptos = require("aptos"); | ||
var import_aptos2 = require("aptos"); | ||
var import_ts_sdk2 = require("@aptos-labs/ts-sdk"); | ||
var import_eventemitter3 = __toESM(require("eventemitter3")); | ||
@@ -242,2 +243,22 @@ var import_tweetnacl = __toESM(require("tweetnacl")); | ||
// src/conversion.ts | ||
var import_ts_sdk = require("@aptos-labs/ts-sdk"); | ||
var import_aptos = require("aptos"); | ||
function convertNetwork(networkInfo) { | ||
switch (networkInfo == null ? void 0 : networkInfo.name.toLowerCase()) { | ||
case "mainnet": | ||
return import_ts_sdk.Network.MAINNET; | ||
case "testnet": | ||
return import_ts_sdk.Network.TESTNET; | ||
case "devnet": | ||
return import_ts_sdk.Network.DEVNET; | ||
default: | ||
throw new Error("Invalid network name"); | ||
} | ||
} | ||
function convertToBCSPayload(payload) { | ||
const deserializer = new import_aptos.BCS.Deserializer(payload.bcsToBytes()); | ||
return import_aptos.TxnBuilderTypes.TransactionPayload.deserialize(deserializer); | ||
} | ||
// src/WalletCore.ts | ||
@@ -464,2 +485,29 @@ var WalletCore = class extends import_eventemitter3.default { | ||
} | ||
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) { | ||
var _a; | ||
if (this._wallet && !("signMultiAgentTransaction" in this._wallet)) { | ||
throw new WalletNotSupportedMethod( | ||
`Multi-agent & sponsored transactions are not supported by ${(_a = this.wallet) == null ? void 0 : _a.name}` | ||
).message; | ||
} | ||
try { | ||
this.doesWalletExist(); | ||
const response = await this._wallet.signMultiAgentTransaction( | ||
transaction | ||
); | ||
return response; | ||
} catch (error) { | ||
const errMsg = typeof error == "object" && "message" in error ? error.message : error; | ||
throw new WalletSignTransactionError(errMsg).message; | ||
} | ||
} | ||
async onAccountChange() { | ||
@@ -535,6 +583,6 @@ var _a; | ||
} else { | ||
const currentAccountPublicKey = new import_aptos.HexString( | ||
const currentAccountPublicKey = new import_aptos2.HexString( | ||
this._account.publicKey | ||
); | ||
const signature = new import_aptos.HexString(response.signature); | ||
const signature = new import_aptos2.HexString(response.signature); | ||
verified = import_tweetnacl.default.sign.detached.verify( | ||
@@ -555,3 +603,3 @@ import_buffer.Buffer.from(response.fullMessage), | ||
// src/types.ts | ||
var import_aptos2 = require("aptos"); | ||
var import_aptos3 = require("aptos"); | ||
// Annotate the CommonJS export names for ESM import in node: | ||
@@ -558,0 +606,0 @@ 0 && (module.exports = { |
{ | ||
"name": "@aptos-labs/wallet-adapter-core", | ||
"version": "2.5.1", | ||
"version": "2.6.0", | ||
"description": "Aptos Wallet Adapter Core", | ||
@@ -41,3 +41,3 @@ "main": "./dist/index.js", | ||
"dependencies": { | ||
"aptos": "^1.14.0", | ||
"@aptos-labs/ts-sdk": "^0.0.3", | ||
"buffer": "^6.0.3", | ||
@@ -47,2 +47,5 @@ "eventemitter3": "^4.0.7", | ||
}, | ||
"peerDependencies": { | ||
"aptos": "^1.19.0" | ||
}, | ||
"scripts": { | ||
@@ -49,0 +52,0 @@ "build": "tsup src/index.ts --format esm,cjs --dts", |
@@ -1,5 +0,6 @@ | ||
import { Types } from "aptos"; | ||
import { TxnBuilderTypes, Types } from "aptos"; | ||
import { NetworkName, WalletReadyState } from "./constants"; | ||
export { TxnBuilderTypes, Types } from "aptos"; | ||
export type { InputGenerateTransactionData } from "@aptos-labs/ts-sdk"; | ||
// WalletName is a nominal type that wallet adapters should use, e.g. `'MyCryptoWallet' as WalletName<'MyCryptoWallet'>` | ||
@@ -46,2 +47,5 @@ export type WalletName<T extends string = string> = T & { | ||
onNetworkChange: OnNetworkChange; | ||
signMultiAgentTransaction: ( | ||
rawTxn: TxnBuilderTypes.MultiAgentRawTransaction | TxnBuilderTypes.FeePayerRawTransaction | ||
) => Promise<string>; | ||
} | ||
@@ -48,0 +52,0 @@ |
import { HexString, TxnBuilderTypes, Types } from "aptos"; | ||
import { AptosConfig, InputGenerateTransactionData, generateTransactionPayload } from "@aptos-labs/ts-sdk"; | ||
import EventEmitter from "eventemitter3"; | ||
@@ -41,2 +42,4 @@ import nacl from "tweetnacl"; | ||
import { getNameByAddress } from "./ans"; | ||
import { AccountAuthenticator } from "@aptos-labs/ts-sdk"; | ||
import { convertNetwork, convertToBCSPayload } from "./conversion"; | ||
@@ -248,4 +251,4 @@ export class WalletCore extends EventEmitter<WalletCoreEvents> { | ||
/** | ||
Disconnect the exisitng wallet. On success, we clear the | ||
/** | ||
Disconnect the exisitng wallet. On success, we clear the | ||
current account, current network and LocalStorage data. | ||
@@ -268,3 +271,3 @@ @emit emits "disconnect" event | ||
/** | ||
/** | ||
Sign and submit an entry (not bcs serialized) transaction type to chain. | ||
@@ -294,9 +297,9 @@ @param transaction a non-bcs serialized transaction | ||
/** | ||
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 | ||
*/ | ||
/** | ||
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( | ||
@@ -326,9 +329,9 @@ transaction: TxnBuilderTypes.TransactionPayload, | ||
/** | ||
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 | ||
*/ | ||
/** | ||
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 | ||
*/ | ||
async signTransaction( | ||
@@ -358,8 +361,8 @@ transaction: Types.TransactionPayload, | ||
/** | ||
Sign message (doesnt submit to chain). | ||
@param message | ||
@return response from the wallet's signMessage function | ||
@throws WalletSignMessageError | ||
*/ | ||
/** | ||
Sign message (doesnt submit to chain). | ||
@param message | ||
@return response from the wallet's signMessage function | ||
@throws WalletSignMessageError | ||
*/ | ||
async signMessage( | ||
@@ -380,3 +383,47 @@ message: SignMessagePayload | ||
/** | ||
/** | ||
* 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)) { | ||
throw new WalletNotSupportedMethod( | ||
`Multi-agent & sponsored transactions are not supported by ${this.wallet?.name}` | ||
).message; | ||
} | ||
try { | ||
this.doesWalletExist(); | ||
const response = await (this._wallet as any).signMultiAgentTransaction( | ||
transaction | ||
); | ||
return response; | ||
} catch (error: any) { | ||
const errMsg = | ||
typeof error == "object" && "message" in error ? error.message : error; | ||
throw new WalletSignTransactionError(errMsg).message; | ||
} | ||
} | ||
/** | ||
Event for when account has changed on the wallet | ||
@@ -401,3 +448,3 @@ @return the new account info | ||
/** | ||
/** | ||
Event for when network has changed on the wallet | ||
@@ -404,0 +451,0 @@ @return the new network info |
Sorry, the diff of this file is not supported yet
83933
19
2339
5
+ Added@aptos-labs/ts-sdk@^0.0.3
+ Added@aptos-labs/aptos-client@0.0.2(transitive)
+ Added@aptos-labs/ts-sdk@0.0.3(transitive)
+ Added@noble/curves@1.8.1(transitive)
+ Added@noble/hashes@1.1.31.7.1(transitive)
+ Added@scure/bip39@1.1.0(transitive)
+ Addedaxios@0.27.2(transitive)
- Removedaptos@^1.14.0