@dynamic-labs/aptos 4.38.0 → 4.39.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +8 -0
- package/_virtual/_tslib.cjs +36 -0
- package/_virtual/_tslib.js +32 -0
- package/package.cjs +1 -1
- package/package.js +1 -1
- package/package.json +5 -3
- package/src/connectors/AptosWalletConnector/AptosWalletConnector.cjs +208 -0
- package/src/connectors/AptosWalletConnector/AptosWalletConnector.d.ts +71 -0
- package/src/connectors/AptosWalletConnector/AptosWalletConnector.js +204 -0
- package/src/connectors/AptosWalletConnector/index.d.ts +1 -0
- package/src/consts/index.cjs +19 -0
- package/src/consts/index.js +15 -0
- package/src/index.cjs +19 -5
- package/src/index.d.ts +9 -0
- package/src/index.js +11 -5
- package/src/types.d.ts +13 -114
- package/src/utils/assertProvider/assertProvider.cjs +36 -0
- package/src/utils/assertProvider/assertProvider.d.ts +6 -5
- package/src/utils/assertProvider/assertProvider.js +32 -0
- package/src/utils/getWalletStandardWallets/getWalletStandardWallets.cjs +49 -0
- package/src/utils/getWalletStandardWallets/getWalletStandardWallets.js +45 -0
- package/src/utils/invokeWalletMethod/invokeWalletMethod.cjs +61 -0
- package/src/utils/invokeWalletMethod/invokeWalletMethod.d.ts +6 -7
- package/src/utils/invokeWalletMethod/invokeWalletMethod.js +57 -0
- package/src/utils/isWalletWithRequiredFeatureSet/isWalletWithRequiredFeatureSet.cjs +10 -0
- package/src/utils/isWalletWithRequiredFeatureSet/isWalletWithRequiredFeatureSet.js +6 -0
- package/src/utils/parseConnectionResult/parseConnectionResult.cjs +40 -0
- package/src/utils/parseConnectionResult/parseConnectionResult.d.ts +7 -10
- package/src/utils/parseConnectionResult/parseConnectionResult.js +36 -0
- package/src/utils/parseTransactionResponse/parseTransactionResponse.cjs +53 -0
- package/src/utils/parseTransactionResponse/parseTransactionResponse.d.ts +3 -3
- package/src/utils/parseTransactionResponse/parseTransactionResponse.js +49 -0
- package/src/wallet/AptosWallet.cjs +138 -0
- package/src/wallet/AptosWallet.d.ts +76 -0
- package/src/wallet/AptosWallet.js +134 -0
- package/src/wallet/index.d.ts +1 -0
- package/src/connectors/index.d.ts +0 -0
|
@@ -1,18 +1,15 @@
|
|
|
1
1
|
import type { AccountInfo } from '@aptos-labs/wallet-standard';
|
|
2
2
|
import type { AptosConnectionResult } from '../../types';
|
|
3
3
|
/**
|
|
4
|
-
* Parsed account information
|
|
4
|
+
* Parsed account information from wallet-standard response
|
|
5
5
|
*/
|
|
6
|
-
export type ParsedAccountInfo = AccountInfo
|
|
7
|
-
address: string;
|
|
8
|
-
publicKey?: string | Uint8Array;
|
|
9
|
-
};
|
|
6
|
+
export type ParsedAccountInfo = AccountInfo;
|
|
10
7
|
/**
|
|
11
|
-
* Parses wallet connection result into
|
|
12
|
-
*
|
|
8
|
+
* Parses wallet-standard connection result into AccountInfo.
|
|
9
|
+
* Only handles AIP-62 compliant wallet-standard responses.
|
|
13
10
|
*
|
|
14
|
-
* @param result - Connection result
|
|
15
|
-
* @returns
|
|
16
|
-
* @throws {DynamicError} When result format is not supported
|
|
11
|
+
* @param result - Connection result from wallet-standard (UserResponse<AccountInfo>)
|
|
12
|
+
* @returns AccountInfo from the approved response
|
|
13
|
+
* @throws {DynamicError} When result format is not supported or user rejected
|
|
17
14
|
*/
|
|
18
15
|
export declare const parseConnectionResult: (result: AptosConnectionResult) => ParsedAccountInfo;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
import { UserResponseStatus } from '@aptos-labs/wallet-standard';
|
|
3
|
+
import { DynamicError } from '@dynamic-labs/utils';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Type guard to check if an object is a UserResponse with AccountInfo
|
|
7
|
+
*/
|
|
8
|
+
const isUserResponse = (obj) => {
|
|
9
|
+
if (typeof obj !== 'object' || obj === null)
|
|
10
|
+
return false;
|
|
11
|
+
const candidate = obj;
|
|
12
|
+
return ('status' in candidate &&
|
|
13
|
+
'args' in candidate &&
|
|
14
|
+
Object.values(UserResponseStatus).includes(candidate.status));
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* Parses wallet-standard connection result into AccountInfo.
|
|
18
|
+
* Only handles AIP-62 compliant wallet-standard responses.
|
|
19
|
+
*
|
|
20
|
+
* @param result - Connection result from wallet-standard (UserResponse<AccountInfo>)
|
|
21
|
+
* @returns AccountInfo from the approved response
|
|
22
|
+
* @throws {DynamicError} When result format is not supported or user rejected
|
|
23
|
+
*/
|
|
24
|
+
const parseConnectionResult = (result) => {
|
|
25
|
+
// Handle wallet-standard UserResponse format (only format we support)
|
|
26
|
+
if (isUserResponse(result) && result.status === UserResponseStatus.APPROVED) {
|
|
27
|
+
return result.args;
|
|
28
|
+
}
|
|
29
|
+
// If it's a rejected response, throw appropriate error
|
|
30
|
+
if (isUserResponse(result) && result.status === UserResponseStatus.REJECTED) {
|
|
31
|
+
throw new DynamicError('User rejected connection request');
|
|
32
|
+
}
|
|
33
|
+
throw new DynamicError('Invalid wallet-standard connection response');
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
export { parseConnectionResult };
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
5
|
+
|
|
6
|
+
var walletStandard = require('@aptos-labs/wallet-standard');
|
|
7
|
+
var utils = require('@dynamic-labs/utils');
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Type guard to check if an object is a UserResponse with hash in args
|
|
11
|
+
*/
|
|
12
|
+
const isUserResponseWithHash = (obj) => {
|
|
13
|
+
if (typeof obj !== 'object' || obj === null)
|
|
14
|
+
return false;
|
|
15
|
+
const candidate = obj;
|
|
16
|
+
// Must have status and args properties
|
|
17
|
+
if (!('status' in candidate) ||
|
|
18
|
+
!('args' in candidate) ||
|
|
19
|
+
!Object.values(walletStandard.UserResponseStatus).includes(candidate.status)) {
|
|
20
|
+
return false;
|
|
21
|
+
}
|
|
22
|
+
// Args must be an object with a valid hash string
|
|
23
|
+
const { args } = candidate;
|
|
24
|
+
if (typeof args !== 'object' || args === null)
|
|
25
|
+
return false;
|
|
26
|
+
const argsObj = args;
|
|
27
|
+
return ('hash' in argsObj &&
|
|
28
|
+
typeof argsObj.hash === 'string' &&
|
|
29
|
+
argsObj.hash.length > 0);
|
|
30
|
+
};
|
|
31
|
+
/**
|
|
32
|
+
* Parses wallet-standard transaction response into a transaction hash.
|
|
33
|
+
* Only handles AIP-62 compliant wallet-standard responses.
|
|
34
|
+
*
|
|
35
|
+
* @param response - Transaction response from wallet-standard (UserResponse<{hash: string}>)
|
|
36
|
+
* @returns Transaction hash as string
|
|
37
|
+
* @throws {DynamicError} When response format is not supported or user rejected
|
|
38
|
+
*/
|
|
39
|
+
const parseTransactionResponse = (response) => {
|
|
40
|
+
// Handle wallet-standard UserResponse format (only format we support)
|
|
41
|
+
if (isUserResponseWithHash(response) &&
|
|
42
|
+
response.status === walletStandard.UserResponseStatus.APPROVED) {
|
|
43
|
+
return response.args.hash;
|
|
44
|
+
}
|
|
45
|
+
// If it's a rejected response, throw appropriate error
|
|
46
|
+
if (isUserResponseWithHash(response) &&
|
|
47
|
+
response.status === walletStandard.UserResponseStatus.REJECTED) {
|
|
48
|
+
throw new utils.DynamicError('User rejected transaction');
|
|
49
|
+
}
|
|
50
|
+
throw new utils.DynamicError('Invalid wallet-standard transaction response');
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
exports.parseTransactionResponse = parseTransactionResponse;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Parses transaction response
|
|
3
|
-
*
|
|
2
|
+
* Parses wallet-standard transaction response into a transaction hash.
|
|
3
|
+
* Only handles AIP-62 compliant wallet-standard responses.
|
|
4
4
|
*
|
|
5
|
-
* @param response - Transaction response from wallet
|
|
5
|
+
* @param response - Transaction response from wallet-standard (UserResponse<{hash: string}>)
|
|
6
6
|
* @returns Transaction hash as string
|
|
7
7
|
* @throws {DynamicError} When response format is not supported or user rejected
|
|
8
8
|
*/
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
import { UserResponseStatus } from '@aptos-labs/wallet-standard';
|
|
3
|
+
import { DynamicError } from '@dynamic-labs/utils';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Type guard to check if an object is a UserResponse with hash in args
|
|
7
|
+
*/
|
|
8
|
+
const isUserResponseWithHash = (obj) => {
|
|
9
|
+
if (typeof obj !== 'object' || obj === null)
|
|
10
|
+
return false;
|
|
11
|
+
const candidate = obj;
|
|
12
|
+
// Must have status and args properties
|
|
13
|
+
if (!('status' in candidate) ||
|
|
14
|
+
!('args' in candidate) ||
|
|
15
|
+
!Object.values(UserResponseStatus).includes(candidate.status)) {
|
|
16
|
+
return false;
|
|
17
|
+
}
|
|
18
|
+
// Args must be an object with a valid hash string
|
|
19
|
+
const { args } = candidate;
|
|
20
|
+
if (typeof args !== 'object' || args === null)
|
|
21
|
+
return false;
|
|
22
|
+
const argsObj = args;
|
|
23
|
+
return ('hash' in argsObj &&
|
|
24
|
+
typeof argsObj.hash === 'string' &&
|
|
25
|
+
argsObj.hash.length > 0);
|
|
26
|
+
};
|
|
27
|
+
/**
|
|
28
|
+
* Parses wallet-standard transaction response into a transaction hash.
|
|
29
|
+
* Only handles AIP-62 compliant wallet-standard responses.
|
|
30
|
+
*
|
|
31
|
+
* @param response - Transaction response from wallet-standard (UserResponse<{hash: string}>)
|
|
32
|
+
* @returns Transaction hash as string
|
|
33
|
+
* @throws {DynamicError} When response format is not supported or user rejected
|
|
34
|
+
*/
|
|
35
|
+
const parseTransactionResponse = (response) => {
|
|
36
|
+
// Handle wallet-standard UserResponse format (only format we support)
|
|
37
|
+
if (isUserResponseWithHash(response) &&
|
|
38
|
+
response.status === UserResponseStatus.APPROVED) {
|
|
39
|
+
return response.args.hash;
|
|
40
|
+
}
|
|
41
|
+
// If it's a rejected response, throw appropriate error
|
|
42
|
+
if (isUserResponseWithHash(response) &&
|
|
43
|
+
response.status === UserResponseStatus.REJECTED) {
|
|
44
|
+
throw new DynamicError('User rejected transaction');
|
|
45
|
+
}
|
|
46
|
+
throw new DynamicError('Invalid wallet-standard transaction response');
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
export { parseTransactionResponse };
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
5
|
+
|
|
6
|
+
var _tslib = require('../../_virtual/_tslib.cjs');
|
|
7
|
+
var walletConnectorCore = require('@dynamic-labs/wallet-connector-core');
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Aptos wallet implementation that provides chain-specific functionality
|
|
11
|
+
* for interacting with the Aptos blockchain.
|
|
12
|
+
*
|
|
13
|
+
* This class extends the base Wallet class and provides Aptos-specific
|
|
14
|
+
* methods for transactions, signing, and network operations.
|
|
15
|
+
*/
|
|
16
|
+
class AptosWallet extends walletConnectorCore.Wallet {
|
|
17
|
+
/**
|
|
18
|
+
* Sends balance to another address.
|
|
19
|
+
* @param amount - Amount to send (in APT for native transfers)
|
|
20
|
+
* @param toAddress - Recipient address
|
|
21
|
+
* @param token - Optional token information for non-APT transfers
|
|
22
|
+
* @returns Transaction hash
|
|
23
|
+
*/
|
|
24
|
+
sendBalance(_a) {
|
|
25
|
+
return _tslib.__awaiter(this, arguments, void 0, function* ({ amount, toAddress, token, }) {
|
|
26
|
+
yield this._connector.connect();
|
|
27
|
+
// Get the Aptos client to create the transaction
|
|
28
|
+
const aptosClient = yield this.getAptosClient();
|
|
29
|
+
if (!aptosClient) {
|
|
30
|
+
throw new Error('Aptos client not available');
|
|
31
|
+
}
|
|
32
|
+
// Get current account info
|
|
33
|
+
const accountInfo = yield this.getAccountInfo();
|
|
34
|
+
if (!accountInfo) {
|
|
35
|
+
throw new Error('No account connected');
|
|
36
|
+
}
|
|
37
|
+
try {
|
|
38
|
+
// Calculate amount with proper decimals (APT has 8 decimals by default)
|
|
39
|
+
const decimals = (token === null || token === void 0 ? void 0 : token.decimals) || 8;
|
|
40
|
+
const transferAmount = parseFloat(amount) * Math.pow(10, decimals);
|
|
41
|
+
// Create the transfer transaction
|
|
42
|
+
const transaction = yield aptosClient.transferCoinTransaction({
|
|
43
|
+
amount: transferAmount,
|
|
44
|
+
coinType: token === null || token === void 0 ? void 0 : token.address,
|
|
45
|
+
recipient: toAddress,
|
|
46
|
+
sender: accountInfo.address, // If undefined, defaults to APT (0x1::aptos_coin::AptosCoin)
|
|
47
|
+
});
|
|
48
|
+
// Sign and submit the transaction using the wallet provider
|
|
49
|
+
const txHash = yield this.signAndSubmitTransaction(transaction);
|
|
50
|
+
return txHash;
|
|
51
|
+
}
|
|
52
|
+
catch (error) {
|
|
53
|
+
throw new Error(`Failed to send balance: ${error instanceof Error ? error.message : 'Unknown error'}`);
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Returns the Aptos client configured for the wallet's current network.
|
|
59
|
+
*
|
|
60
|
+
* @returns The Aptos client instance or undefined if not available
|
|
61
|
+
*/
|
|
62
|
+
getAptosClient() {
|
|
63
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
64
|
+
return this._connector.getAptosClient();
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Returns the wallet's current account information.
|
|
69
|
+
*
|
|
70
|
+
* @returns The current account info or undefined if not connected
|
|
71
|
+
*/
|
|
72
|
+
getAccountInfo() {
|
|
73
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
74
|
+
return this._connector.getAccountInfo();
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Returns the wallet's current network information.
|
|
79
|
+
*
|
|
80
|
+
* @returns The current network info or undefined if not available
|
|
81
|
+
*/
|
|
82
|
+
getNetworkInfo() {
|
|
83
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
84
|
+
return this._connector.getNetworkInfo();
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Signs a transaction for the Aptos blockchain.
|
|
89
|
+
*
|
|
90
|
+
* @param transaction - The transaction to sign
|
|
91
|
+
* @param asFeePayer - Whether to sign as fee payer (optional)
|
|
92
|
+
* @returns The signed transaction or user response
|
|
93
|
+
*/
|
|
94
|
+
signTransaction(transaction, asFeePayer) {
|
|
95
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
96
|
+
yield this._connector.connect();
|
|
97
|
+
return this._connector.signTransaction(transaction, asFeePayer);
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Signs a message for authentication purposes.
|
|
102
|
+
*
|
|
103
|
+
* @param input - The message signing input parameters
|
|
104
|
+
* @returns The signature result or user response
|
|
105
|
+
*/
|
|
106
|
+
signAptosMessage(input) {
|
|
107
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
108
|
+
yield this._connector.connect();
|
|
109
|
+
return this._connector.signAptosMessage(input);
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Signs and submits a transaction to the Aptos network.
|
|
114
|
+
*
|
|
115
|
+
* @param transaction - The transaction to sign and submit
|
|
116
|
+
* @returns The transaction hash
|
|
117
|
+
*/
|
|
118
|
+
signAndSubmitTransaction(transaction) {
|
|
119
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
120
|
+
yield this._connector.connect();
|
|
121
|
+
return this._connector.signAndSubmitTransaction(transaction);
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Submits a pre-signed transaction to the network.
|
|
126
|
+
*
|
|
127
|
+
* @param signedTransaction - The signed transaction to submit
|
|
128
|
+
* @returns The transaction hash
|
|
129
|
+
*/
|
|
130
|
+
submitTransaction(signedTransaction) {
|
|
131
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
132
|
+
yield this._connector.connect();
|
|
133
|
+
return this._connector.submitTransaction(signedTransaction);
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
exports.AptosWallet = AptosWallet;
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import type { AccountAuthenticator, AnyRawTransaction } from '@aptos-labs/ts-sdk';
|
|
2
|
+
import { Aptos } from '@aptos-labs/ts-sdk';
|
|
3
|
+
import type { AccountInfo, AptosSignMessageInput, AptosSignMessageOutput, NetworkInfo, UserResponse } from '@aptos-labs/wallet-standard';
|
|
4
|
+
import { Wallet } from '@dynamic-labs/wallet-connector-core';
|
|
5
|
+
import type { AptosWalletConnector } from '../connectors/AptosWalletConnector/AptosWalletConnector';
|
|
6
|
+
/**
|
|
7
|
+
* Aptos wallet implementation that provides chain-specific functionality
|
|
8
|
+
* for interacting with the Aptos blockchain.
|
|
9
|
+
*
|
|
10
|
+
* This class extends the base Wallet class and provides Aptos-specific
|
|
11
|
+
* methods for transactions, signing, and network operations.
|
|
12
|
+
*/
|
|
13
|
+
export declare class AptosWallet extends Wallet<AptosWalletConnector> {
|
|
14
|
+
/**
|
|
15
|
+
* Sends balance to another address.
|
|
16
|
+
* @param amount - Amount to send (in APT for native transfers)
|
|
17
|
+
* @param toAddress - Recipient address
|
|
18
|
+
* @param token - Optional token information for non-APT transfers
|
|
19
|
+
* @returns Transaction hash
|
|
20
|
+
*/
|
|
21
|
+
sendBalance({ amount, toAddress, token, }: {
|
|
22
|
+
amount: string;
|
|
23
|
+
toAddress: string;
|
|
24
|
+
token?: {
|
|
25
|
+
address: string;
|
|
26
|
+
decimals?: number;
|
|
27
|
+
};
|
|
28
|
+
}): Promise<string>;
|
|
29
|
+
/**
|
|
30
|
+
* Returns the Aptos client configured for the wallet's current network.
|
|
31
|
+
*
|
|
32
|
+
* @returns The Aptos client instance or undefined if not available
|
|
33
|
+
*/
|
|
34
|
+
getAptosClient(): Promise<Aptos | undefined>;
|
|
35
|
+
/**
|
|
36
|
+
* Returns the wallet's current account information.
|
|
37
|
+
*
|
|
38
|
+
* @returns The current account info or undefined if not connected
|
|
39
|
+
*/
|
|
40
|
+
getAccountInfo(): Promise<AccountInfo | undefined>;
|
|
41
|
+
/**
|
|
42
|
+
* Returns the wallet's current network information.
|
|
43
|
+
*
|
|
44
|
+
* @returns The current network info or undefined if not available
|
|
45
|
+
*/
|
|
46
|
+
getNetworkInfo(): Promise<NetworkInfo | undefined>;
|
|
47
|
+
/**
|
|
48
|
+
* Signs a transaction for the Aptos blockchain.
|
|
49
|
+
*
|
|
50
|
+
* @param transaction - The transaction to sign
|
|
51
|
+
* @param asFeePayer - Whether to sign as fee payer (optional)
|
|
52
|
+
* @returns The signed transaction or user response
|
|
53
|
+
*/
|
|
54
|
+
signTransaction(transaction: AnyRawTransaction, asFeePayer?: boolean): Promise<UserResponse<AccountAuthenticator> | AccountAuthenticator>;
|
|
55
|
+
/**
|
|
56
|
+
* Signs a message for authentication purposes.
|
|
57
|
+
*
|
|
58
|
+
* @param input - The message signing input parameters
|
|
59
|
+
* @returns The signature result or user response
|
|
60
|
+
*/
|
|
61
|
+
signAptosMessage(input: AptosSignMessageInput): Promise<UserResponse<AptosSignMessageOutput> | AptosSignMessageOutput>;
|
|
62
|
+
/**
|
|
63
|
+
* Signs and submits a transaction to the Aptos network.
|
|
64
|
+
*
|
|
65
|
+
* @param transaction - The transaction to sign and submit
|
|
66
|
+
* @returns The transaction hash
|
|
67
|
+
*/
|
|
68
|
+
signAndSubmitTransaction(transaction: AnyRawTransaction): Promise<string>;
|
|
69
|
+
/**
|
|
70
|
+
* Submits a pre-signed transaction to the network.
|
|
71
|
+
*
|
|
72
|
+
* @param signedTransaction - The signed transaction to submit
|
|
73
|
+
* @returns The transaction hash
|
|
74
|
+
*/
|
|
75
|
+
submitTransaction(signedTransaction: AccountAuthenticator): Promise<string>;
|
|
76
|
+
}
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
import { __awaiter } from '../../_virtual/_tslib.js';
|
|
3
|
+
import { Wallet } from '@dynamic-labs/wallet-connector-core';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Aptos wallet implementation that provides chain-specific functionality
|
|
7
|
+
* for interacting with the Aptos blockchain.
|
|
8
|
+
*
|
|
9
|
+
* This class extends the base Wallet class and provides Aptos-specific
|
|
10
|
+
* methods for transactions, signing, and network operations.
|
|
11
|
+
*/
|
|
12
|
+
class AptosWallet extends Wallet {
|
|
13
|
+
/**
|
|
14
|
+
* Sends balance to another address.
|
|
15
|
+
* @param amount - Amount to send (in APT for native transfers)
|
|
16
|
+
* @param toAddress - Recipient address
|
|
17
|
+
* @param token - Optional token information for non-APT transfers
|
|
18
|
+
* @returns Transaction hash
|
|
19
|
+
*/
|
|
20
|
+
sendBalance(_a) {
|
|
21
|
+
return __awaiter(this, arguments, void 0, function* ({ amount, toAddress, token, }) {
|
|
22
|
+
yield this._connector.connect();
|
|
23
|
+
// Get the Aptos client to create the transaction
|
|
24
|
+
const aptosClient = yield this.getAptosClient();
|
|
25
|
+
if (!aptosClient) {
|
|
26
|
+
throw new Error('Aptos client not available');
|
|
27
|
+
}
|
|
28
|
+
// Get current account info
|
|
29
|
+
const accountInfo = yield this.getAccountInfo();
|
|
30
|
+
if (!accountInfo) {
|
|
31
|
+
throw new Error('No account connected');
|
|
32
|
+
}
|
|
33
|
+
try {
|
|
34
|
+
// Calculate amount with proper decimals (APT has 8 decimals by default)
|
|
35
|
+
const decimals = (token === null || token === void 0 ? void 0 : token.decimals) || 8;
|
|
36
|
+
const transferAmount = parseFloat(amount) * Math.pow(10, decimals);
|
|
37
|
+
// Create the transfer transaction
|
|
38
|
+
const transaction = yield aptosClient.transferCoinTransaction({
|
|
39
|
+
amount: transferAmount,
|
|
40
|
+
coinType: token === null || token === void 0 ? void 0 : token.address,
|
|
41
|
+
recipient: toAddress,
|
|
42
|
+
sender: accountInfo.address, // If undefined, defaults to APT (0x1::aptos_coin::AptosCoin)
|
|
43
|
+
});
|
|
44
|
+
// Sign and submit the transaction using the wallet provider
|
|
45
|
+
const txHash = yield this.signAndSubmitTransaction(transaction);
|
|
46
|
+
return txHash;
|
|
47
|
+
}
|
|
48
|
+
catch (error) {
|
|
49
|
+
throw new Error(`Failed to send balance: ${error instanceof Error ? error.message : 'Unknown error'}`);
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Returns the Aptos client configured for the wallet's current network.
|
|
55
|
+
*
|
|
56
|
+
* @returns The Aptos client instance or undefined if not available
|
|
57
|
+
*/
|
|
58
|
+
getAptosClient() {
|
|
59
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
60
|
+
return this._connector.getAptosClient();
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Returns the wallet's current account information.
|
|
65
|
+
*
|
|
66
|
+
* @returns The current account info or undefined if not connected
|
|
67
|
+
*/
|
|
68
|
+
getAccountInfo() {
|
|
69
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
70
|
+
return this._connector.getAccountInfo();
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Returns the wallet's current network information.
|
|
75
|
+
*
|
|
76
|
+
* @returns The current network info or undefined if not available
|
|
77
|
+
*/
|
|
78
|
+
getNetworkInfo() {
|
|
79
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
80
|
+
return this._connector.getNetworkInfo();
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Signs a transaction for the Aptos blockchain.
|
|
85
|
+
*
|
|
86
|
+
* @param transaction - The transaction to sign
|
|
87
|
+
* @param asFeePayer - Whether to sign as fee payer (optional)
|
|
88
|
+
* @returns The signed transaction or user response
|
|
89
|
+
*/
|
|
90
|
+
signTransaction(transaction, asFeePayer) {
|
|
91
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
92
|
+
yield this._connector.connect();
|
|
93
|
+
return this._connector.signTransaction(transaction, asFeePayer);
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Signs a message for authentication purposes.
|
|
98
|
+
*
|
|
99
|
+
* @param input - The message signing input parameters
|
|
100
|
+
* @returns The signature result or user response
|
|
101
|
+
*/
|
|
102
|
+
signAptosMessage(input) {
|
|
103
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
104
|
+
yield this._connector.connect();
|
|
105
|
+
return this._connector.signAptosMessage(input);
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Signs and submits a transaction to the Aptos network.
|
|
110
|
+
*
|
|
111
|
+
* @param transaction - The transaction to sign and submit
|
|
112
|
+
* @returns The transaction hash
|
|
113
|
+
*/
|
|
114
|
+
signAndSubmitTransaction(transaction) {
|
|
115
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
116
|
+
yield this._connector.connect();
|
|
117
|
+
return this._connector.signAndSubmitTransaction(transaction);
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Submits a pre-signed transaction to the network.
|
|
122
|
+
*
|
|
123
|
+
* @param signedTransaction - The signed transaction to submit
|
|
124
|
+
* @returns The transaction hash
|
|
125
|
+
*/
|
|
126
|
+
submitTransaction(signedTransaction) {
|
|
127
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
128
|
+
yield this._connector.connect();
|
|
129
|
+
return this._connector.submitTransaction(signedTransaction);
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
export { AptosWallet };
|
package/src/wallet/index.d.ts
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { AptosWallet } from './AptosWallet';
|
|
File without changes
|