@dynamic-labs/aptos 4.38.0 → 4.40.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 +21 -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 +7 -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 +27 -6
- package/src/index.d.ts +10 -1
- package/src/index.js +19 -6
- package/src/injected/AptosProviderHelper.cjs +317 -0
- package/src/injected/AptosProviderHelper.d.ts +106 -0
- package/src/injected/AptosProviderHelper.js +313 -0
- package/src/injected/InjectedWalletBase.cjs +87 -0
- package/src/injected/InjectedWalletBase.d.ts +28 -0
- package/src/injected/InjectedWalletBase.js +83 -0
- package/src/injected/fetchInjectedWalletConnectors.cjs +171 -0
- package/src/injected/fetchInjectedWalletConnectors.d.ts +48 -0
- package/src/injected/fetchInjectedWalletConnectors.js +167 -0
- package/src/injected/index.d.ts +3 -0
- package/src/types.d.ts +33 -113
- 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 +68 -0
- package/src/utils/getWalletStandardWallets/getWalletStandardWallets.js +64 -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/walletStandard/createAptosSignerFromWalletStandard.cjs +244 -0
- package/src/walletStandard/createAptosSignerFromWalletStandard.d.ts +9 -0
- package/src/walletStandard/createAptosSignerFromWalletStandard.js +240 -0
- package/src/walletStandard/getConnectorConstructorForWalletStandardWallet.cjs +31 -0
- package/src/walletStandard/getConnectorConstructorForWalletStandardWallet.d.ts +3 -0
- package/src/walletStandard/getConnectorConstructorForWalletStandardWallet.js +27 -0
- package/src/connectors/index.d.ts +0 -0
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
5
|
+
|
|
6
|
+
var _tslib = require('../../../_virtual/_tslib.cjs');
|
|
7
|
+
var utils = require('@dynamic-labs/utils');
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Invokes a method on AIP-62 compliant wallet-standard provider.
|
|
11
|
+
*
|
|
12
|
+
* This utility provides a clean interface for calling wallet-standard features
|
|
13
|
+
* on Aptos wallets that implement AIP-62. All major Aptos wallets now support
|
|
14
|
+
* this standard, making legacy provider support unnecessary.
|
|
15
|
+
*
|
|
16
|
+
* @template T - The expected return type of the wallet method
|
|
17
|
+
* @param provider - The AIP-62 compliant Aptos wallet provider
|
|
18
|
+
* @param featureName - The wallet-standard feature name (e.g., 'aptos:connect')
|
|
19
|
+
* @param methodName - The method name to call (e.g., 'connect', 'signTransaction')
|
|
20
|
+
* @param args - Arguments to pass to the wallet method
|
|
21
|
+
* @returns Promise resolving to the method's return value
|
|
22
|
+
* @throws {DynamicError} When the feature or method is not supported by the provider
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* ```typescript
|
|
26
|
+
* // Connect to wallet
|
|
27
|
+
* const result = await invokeWalletMethod(
|
|
28
|
+
* provider,
|
|
29
|
+
* 'aptos:connect',
|
|
30
|
+
* 'connect'
|
|
31
|
+
* );
|
|
32
|
+
*
|
|
33
|
+
* // Sign transaction
|
|
34
|
+
* const signature = await invokeWalletMethod(
|
|
35
|
+
* provider,
|
|
36
|
+
* 'aptos:signTransaction',
|
|
37
|
+
* 'signTransaction',
|
|
38
|
+
* transaction,
|
|
39
|
+
* false // asFeePayer
|
|
40
|
+
* );
|
|
41
|
+
* ```
|
|
42
|
+
*/
|
|
43
|
+
const invokeWalletMethod = (provider, featureName, methodName, ...args) => _tslib.__awaiter(void 0, void 0, void 0, function* () {
|
|
44
|
+
// Check if provider has features
|
|
45
|
+
if (!provider.features) {
|
|
46
|
+
throw new utils.DynamicError(`Feature ${featureName} not supported by wallet`);
|
|
47
|
+
}
|
|
48
|
+
// Get the wallet-standard feature
|
|
49
|
+
const feature = provider.features[featureName];
|
|
50
|
+
if (!feature || typeof feature !== 'object') {
|
|
51
|
+
throw new utils.DynamicError(`Feature ${featureName} not supported by wallet`);
|
|
52
|
+
}
|
|
53
|
+
// Get the method from the feature
|
|
54
|
+
const method = feature[methodName];
|
|
55
|
+
if (typeof method !== 'function') {
|
|
56
|
+
throw new utils.DynamicError(`Method ${methodName} not available in feature ${featureName}`);
|
|
57
|
+
}
|
|
58
|
+
return method(...args);
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
exports.invokeWalletMethod = invokeWalletMethod;
|
|
@@ -1,19 +1,18 @@
|
|
|
1
1
|
import type { IAptosProvider, AptosFeatureName, AptosMethodName } from '../../types';
|
|
2
2
|
/**
|
|
3
|
-
* Invokes a method on
|
|
3
|
+
* Invokes a method on AIP-62 compliant wallet-standard provider.
|
|
4
4
|
*
|
|
5
|
-
* This utility
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
* regardless of the underlying wallet implementation.
|
|
5
|
+
* This utility provides a clean interface for calling wallet-standard features
|
|
6
|
+
* on Aptos wallets that implement AIP-62. All major Aptos wallets now support
|
|
7
|
+
* this standard, making legacy provider support unnecessary.
|
|
9
8
|
*
|
|
10
9
|
* @template T - The expected return type of the wallet method
|
|
11
|
-
* @param provider - The Aptos wallet provider
|
|
10
|
+
* @param provider - The AIP-62 compliant Aptos wallet provider
|
|
12
11
|
* @param featureName - The wallet-standard feature name (e.g., 'aptos:connect')
|
|
13
12
|
* @param methodName - The method name to call (e.g., 'connect', 'signTransaction')
|
|
14
13
|
* @param args - Arguments to pass to the wallet method
|
|
15
14
|
* @returns Promise resolving to the method's return value
|
|
16
|
-
* @throws {DynamicError} When the method is not supported by the provider
|
|
15
|
+
* @throws {DynamicError} When the feature or method is not supported by the provider
|
|
17
16
|
*
|
|
18
17
|
* @example
|
|
19
18
|
* ```typescript
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
import { __awaiter } from '../../../_virtual/_tslib.js';
|
|
3
|
+
import { DynamicError } from '@dynamic-labs/utils';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Invokes a method on AIP-62 compliant wallet-standard provider.
|
|
7
|
+
*
|
|
8
|
+
* This utility provides a clean interface for calling wallet-standard features
|
|
9
|
+
* on Aptos wallets that implement AIP-62. All major Aptos wallets now support
|
|
10
|
+
* this standard, making legacy provider support unnecessary.
|
|
11
|
+
*
|
|
12
|
+
* @template T - The expected return type of the wallet method
|
|
13
|
+
* @param provider - The AIP-62 compliant Aptos wallet provider
|
|
14
|
+
* @param featureName - The wallet-standard feature name (e.g., 'aptos:connect')
|
|
15
|
+
* @param methodName - The method name to call (e.g., 'connect', 'signTransaction')
|
|
16
|
+
* @param args - Arguments to pass to the wallet method
|
|
17
|
+
* @returns Promise resolving to the method's return value
|
|
18
|
+
* @throws {DynamicError} When the feature or method is not supported by the provider
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* ```typescript
|
|
22
|
+
* // Connect to wallet
|
|
23
|
+
* const result = await invokeWalletMethod(
|
|
24
|
+
* provider,
|
|
25
|
+
* 'aptos:connect',
|
|
26
|
+
* 'connect'
|
|
27
|
+
* );
|
|
28
|
+
*
|
|
29
|
+
* // Sign transaction
|
|
30
|
+
* const signature = await invokeWalletMethod(
|
|
31
|
+
* provider,
|
|
32
|
+
* 'aptos:signTransaction',
|
|
33
|
+
* 'signTransaction',
|
|
34
|
+
* transaction,
|
|
35
|
+
* false // asFeePayer
|
|
36
|
+
* );
|
|
37
|
+
* ```
|
|
38
|
+
*/
|
|
39
|
+
const invokeWalletMethod = (provider, featureName, methodName, ...args) => __awaiter(void 0, void 0, void 0, function* () {
|
|
40
|
+
// Check if provider has features
|
|
41
|
+
if (!provider.features) {
|
|
42
|
+
throw new DynamicError(`Feature ${featureName} not supported by wallet`);
|
|
43
|
+
}
|
|
44
|
+
// Get the wallet-standard feature
|
|
45
|
+
const feature = provider.features[featureName];
|
|
46
|
+
if (!feature || typeof feature !== 'object') {
|
|
47
|
+
throw new DynamicError(`Feature ${featureName} not supported by wallet`);
|
|
48
|
+
}
|
|
49
|
+
// Get the method from the feature
|
|
50
|
+
const method = feature[methodName];
|
|
51
|
+
if (typeof method !== 'function') {
|
|
52
|
+
throw new DynamicError(`Method ${methodName} not available in feature ${featureName}`);
|
|
53
|
+
}
|
|
54
|
+
return method(...args);
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
export { invokeWalletMethod };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
5
|
+
|
|
6
|
+
var index = require('../../consts/index.cjs');
|
|
7
|
+
|
|
8
|
+
const isWalletWithRequiredFeatureSet = (wallet, additionalFeatures = []) => [...index.REQUIRED_FEATURES, ...additionalFeatures].every((feature) => feature in wallet.features);
|
|
9
|
+
|
|
10
|
+
exports.isWalletWithRequiredFeatureSet = isWalletWithRequiredFeatureSet;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
import { REQUIRED_FEATURES } from '../../consts/index.js';
|
|
3
|
+
|
|
4
|
+
const isWalletWithRequiredFeatureSet = (wallet, additionalFeatures = []) => [...REQUIRED_FEATURES, ...additionalFeatures].every((feature) => feature in wallet.features);
|
|
5
|
+
|
|
6
|
+
export { isWalletWithRequiredFeatureSet };
|
|
@@ -0,0 +1,40 @@
|
|
|
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 AccountInfo
|
|
11
|
+
*/
|
|
12
|
+
const isUserResponse = (obj) => {
|
|
13
|
+
if (typeof obj !== 'object' || obj === null)
|
|
14
|
+
return false;
|
|
15
|
+
const candidate = obj;
|
|
16
|
+
return ('status' in candidate &&
|
|
17
|
+
'args' in candidate &&
|
|
18
|
+
Object.values(walletStandard.UserResponseStatus).includes(candidate.status));
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* Parses wallet-standard connection result into AccountInfo.
|
|
22
|
+
* Only handles AIP-62 compliant wallet-standard responses.
|
|
23
|
+
*
|
|
24
|
+
* @param result - Connection result from wallet-standard (UserResponse<AccountInfo>)
|
|
25
|
+
* @returns AccountInfo from the approved response
|
|
26
|
+
* @throws {DynamicError} When result format is not supported or user rejected
|
|
27
|
+
*/
|
|
28
|
+
const parseConnectionResult = (result) => {
|
|
29
|
+
// Handle wallet-standard UserResponse format (only format we support)
|
|
30
|
+
if (isUserResponse(result) && result.status === walletStandard.UserResponseStatus.APPROVED) {
|
|
31
|
+
return result.args;
|
|
32
|
+
}
|
|
33
|
+
// If it's a rejected response, throw appropriate error
|
|
34
|
+
if (isUserResponse(result) && result.status === walletStandard.UserResponseStatus.REJECTED) {
|
|
35
|
+
throw new utils.DynamicError('User rejected connection request');
|
|
36
|
+
}
|
|
37
|
+
throw new utils.DynamicError('Invalid wallet-standard connection response');
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
exports.parseConnectionResult = parseConnectionResult;
|
|
@@ -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
|
+
}
|