@dynamic-labs/aptos 4.39.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 +13 -0
- package/package.cjs +1 -1
- package/package.js +1 -1
- package/package.json +7 -5
- package/src/index.cjs +12 -5
- package/src/index.d.ts +1 -1
- package/src/index.js +11 -4
- 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 +22 -1
- package/src/utils/getWalletStandardWallets/getWalletStandardWallets.cjs +30 -11
- package/src/utils/getWalletStandardWallets/getWalletStandardWallets.js +31 -12
- 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
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { WalletBookSchema } from '@dynamic-labs/wallet-book';
|
|
2
|
+
import { WalletConnectorConstructor } from '@dynamic-labs/wallet-connector-core';
|
|
3
|
+
/**
|
|
4
|
+
* Array of wallet connector constructors that have custom implementations.
|
|
5
|
+
* These wallets override the default wallet-standard behavior.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```typescript
|
|
9
|
+
* export const injectedWalletOverrides: WalletConnectorConstructor[] = [
|
|
10
|
+
* PetraWallet,
|
|
11
|
+
* OKXAptosWallet,
|
|
12
|
+
* ];
|
|
13
|
+
* ```
|
|
14
|
+
*/
|
|
15
|
+
export declare const injectedWalletOverrides: WalletConnectorConstructor[];
|
|
16
|
+
/**
|
|
17
|
+
* Fetches all available injected Aptos wallet connectors.
|
|
18
|
+
*
|
|
19
|
+
* This function discovers and creates wallet connector constructors from two sources:
|
|
20
|
+
* 1. Wallet book entries - Traditional wallets defined in the wallet book
|
|
21
|
+
* 2. Wallet-standard wallets - AIP-62 compliant wallets discovered via wallet-standard
|
|
22
|
+
*
|
|
23
|
+
* The function automatically filters out wallets that:
|
|
24
|
+
* - Have custom connector implementations
|
|
25
|
+
* - Are already handled by wallet-standard connectors
|
|
26
|
+
* - Don't support the required Aptos feature set
|
|
27
|
+
*
|
|
28
|
+
* @param options - Configuration options
|
|
29
|
+
* @param options.walletBook - The wallet book schema containing wallet metadata
|
|
30
|
+
* @param options.authMode - The authentication mode for filtering wallet features
|
|
31
|
+
* @returns Array of wallet connector constructor classes
|
|
32
|
+
*
|
|
33
|
+
* @example
|
|
34
|
+
* ```typescript
|
|
35
|
+
* const connectors = fetchInjectedWalletConnectors({
|
|
36
|
+
* walletBook,
|
|
37
|
+
* authMode: 'connect-and-sign'
|
|
38
|
+
* });
|
|
39
|
+
*
|
|
40
|
+
* // Instantiate connectors
|
|
41
|
+
* connectors.forEach(Connector => {
|
|
42
|
+
* const instance = new Connector(aptosWalletConnectorProps);
|
|
43
|
+
* });
|
|
44
|
+
* ```
|
|
45
|
+
*/
|
|
46
|
+
export declare const fetchInjectedWalletConnectors: ({ walletBook, }: {
|
|
47
|
+
walletBook: WalletBookSchema;
|
|
48
|
+
}) => WalletConnectorConstructor[];
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
import { findWalletBookWalletByNameAndChain } from '@dynamic-labs/wallet-book';
|
|
3
|
+
import { getWalletMetadataFromWalletBook } from '@dynamic-labs/wallet-connector-core';
|
|
4
|
+
import { sanitizeName } from '@dynamic-labs/utils';
|
|
5
|
+
import { Logger } from '@dynamic-labs/logger';
|
|
6
|
+
import { getWalletStandardWallets } from '../utils/getWalletStandardWallets/getWalletStandardWallets.js';
|
|
7
|
+
import { isWalletWithRequiredFeatureSet } from '../utils/isWalletWithRequiredFeatureSet/isWalletWithRequiredFeatureSet.js';
|
|
8
|
+
import { REQUIRED_FEATURES } from '../consts/index.js';
|
|
9
|
+
import { getConnectorConstructorForWalletStandardWallet } from '../walletStandard/getConnectorConstructorForWalletStandardWallet.js';
|
|
10
|
+
import { InjectedWalletBase } from './InjectedWalletBase.js';
|
|
11
|
+
|
|
12
|
+
const logger = new Logger('fetchInjectedWalletConnectors');
|
|
13
|
+
/**
|
|
14
|
+
* List of wallet keys that have custom connector implementations.
|
|
15
|
+
* These wallets will not use the automatic wallet-standard connector.
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```typescript
|
|
19
|
+
* const walletsWithCustomConnectors: string[] = [
|
|
20
|
+
* 'petra',
|
|
21
|
+
* 'okxaptos',
|
|
22
|
+
* ];
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
25
|
+
const walletsWithCustomConnectors = [
|
|
26
|
+
// Add wallet keys here that need custom connectors
|
|
27
|
+
];
|
|
28
|
+
/**
|
|
29
|
+
* Determines whether a wallet-standard wallet should have a connector created for it.
|
|
30
|
+
*
|
|
31
|
+
* @param wallet - The wallet-standard wallet to check
|
|
32
|
+
* @param walletBook - The wallet book schema containing wallet metadata
|
|
33
|
+
* @param authMode - The authentication mode (optional, for future feature filtering)
|
|
34
|
+
* @returns True if a wallet-standard connector should be created
|
|
35
|
+
*/
|
|
36
|
+
const shouldAddWalletStandardConnector = (wallet, walletBook) => {
|
|
37
|
+
var _a;
|
|
38
|
+
const { name } = wallet;
|
|
39
|
+
const chain = 'aptos';
|
|
40
|
+
const connectorKey = `${sanitizeName(name)}${chain}`;
|
|
41
|
+
logger.logVerboseTroubleshootingMessage('[APTOS shouldAddWalletStandardConnector] Checking wallet:', { chain, connectorKey, features: Object.keys(wallet.features), name });
|
|
42
|
+
const shouldHandleWalletFromWalletBook = ([key, walletEntry]) => {
|
|
43
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
|
|
44
|
+
const hasMatchingKey = key === connectorKey;
|
|
45
|
+
const needsCustomConnector = walletsWithCustomConnectors.includes(connectorKey);
|
|
46
|
+
const hasMatchingNameAndChain = walletEntry.name === name &&
|
|
47
|
+
((_b = (_a = walletEntry.injectedConfig) === null || _a === void 0 ? void 0 : _a[0]) === null || _b === void 0 ? void 0 : _b.chain) === chain;
|
|
48
|
+
// If the wallet supports wallet-standard, we want to add the wallet-standard connector
|
|
49
|
+
// and not handle it as a default wallet-book wallet
|
|
50
|
+
const isNotWalletStandard = !((_f = (_e = (_d = (_c = walletEntry.injectedConfig) === null || _c === void 0 ? void 0 : _c[0]) === null || _d === void 0 ? void 0 : _d.walletStandard) === null || _e === void 0 ? void 0 : _e.features) === null || _f === void 0 ? void 0 : _f.length);
|
|
51
|
+
// If injectedConfig is missing, it's not a traditional wallet book entry
|
|
52
|
+
const hasInjectedConfig = Boolean((_g = walletEntry.injectedConfig) === null || _g === void 0 ? void 0 : _g.length);
|
|
53
|
+
// If the chain doesn't match, it should be handled by wallet-standard
|
|
54
|
+
const hasMatchingChain = ((_j = (_h = walletEntry.injectedConfig) === null || _h === void 0 ? void 0 : _h[0]) === null || _j === void 0 ? void 0 : _j.chain) === chain;
|
|
55
|
+
return ((hasMatchingKey || needsCustomConnector || hasMatchingNameAndChain) &&
|
|
56
|
+
hasInjectedConfig &&
|
|
57
|
+
hasMatchingChain &&
|
|
58
|
+
isNotWalletStandard);
|
|
59
|
+
};
|
|
60
|
+
const shouldHandleFromWalletBook = Object.entries((_a = walletBook === null || walletBook === void 0 ? void 0 : walletBook.wallets) !== null && _a !== void 0 ? _a : {}).find(shouldHandleWalletFromWalletBook);
|
|
61
|
+
// Check if wallet has all required features based on auth mode
|
|
62
|
+
const additionalFeatures = [];
|
|
63
|
+
const hasAllFeatures = isWalletWithRequiredFeatureSet(wallet, additionalFeatures);
|
|
64
|
+
logger.logVerboseTroubleshootingMessage('[APTOS shouldAddWalletStandardConnector] Decision:', {
|
|
65
|
+
hasAllFeatures,
|
|
66
|
+
requiredFeatures: [...REQUIRED_FEATURES, ...additionalFeatures],
|
|
67
|
+
shouldAdd: !shouldHandleFromWalletBook && hasAllFeatures,
|
|
68
|
+
shouldHandleFromWalletBook: Boolean(shouldHandleFromWalletBook),
|
|
69
|
+
});
|
|
70
|
+
return !shouldHandleFromWalletBook && hasAllFeatures;
|
|
71
|
+
};
|
|
72
|
+
/**
|
|
73
|
+
* Fetches all available injected Aptos wallet connectors.
|
|
74
|
+
*
|
|
75
|
+
* This function discovers and creates wallet connector constructors from two sources:
|
|
76
|
+
* 1. Wallet book entries - Traditional wallets defined in the wallet book
|
|
77
|
+
* 2. Wallet-standard wallets - AIP-62 compliant wallets discovered via wallet-standard
|
|
78
|
+
*
|
|
79
|
+
* The function automatically filters out wallets that:
|
|
80
|
+
* - Have custom connector implementations
|
|
81
|
+
* - Are already handled by wallet-standard connectors
|
|
82
|
+
* - Don't support the required Aptos feature set
|
|
83
|
+
*
|
|
84
|
+
* @param options - Configuration options
|
|
85
|
+
* @param options.walletBook - The wallet book schema containing wallet metadata
|
|
86
|
+
* @param options.authMode - The authentication mode for filtering wallet features
|
|
87
|
+
* @returns Array of wallet connector constructor classes
|
|
88
|
+
*
|
|
89
|
+
* @example
|
|
90
|
+
* ```typescript
|
|
91
|
+
* const connectors = fetchInjectedWalletConnectors({
|
|
92
|
+
* walletBook,
|
|
93
|
+
* authMode: 'connect-and-sign'
|
|
94
|
+
* });
|
|
95
|
+
*
|
|
96
|
+
* // Instantiate connectors
|
|
97
|
+
* connectors.forEach(Connector => {
|
|
98
|
+
* const instance = new Connector(aptosWalletConnectorProps);
|
|
99
|
+
* });
|
|
100
|
+
* ```
|
|
101
|
+
*/
|
|
102
|
+
const fetchInjectedWalletConnectors = ({ walletBook, }) => {
|
|
103
|
+
var _a;
|
|
104
|
+
// Get wallet book connectors for traditional Aptos wallets
|
|
105
|
+
const walletBookConnectors = Object.entries((_a = walletBook === null || walletBook === void 0 ? void 0 : walletBook.wallets) !== null && _a !== void 0 ? _a : {})
|
|
106
|
+
.filter(([key, wallet]) => {
|
|
107
|
+
var _a, _b, _c;
|
|
108
|
+
const injectedConfig = (_a = wallet.injectedConfig) === null || _a === void 0 ? void 0 : _a.find((config) => config.chain === 'aptos');
|
|
109
|
+
const isAptosWallet = Boolean(injectedConfig);
|
|
110
|
+
// Filter out wallets that require a custom connector or wallets that support wallet-standard,
|
|
111
|
+
// since they are already handled automatically with the wallet-standard connector
|
|
112
|
+
const shouldBeFiltered = walletsWithCustomConnectors.includes(key) ||
|
|
113
|
+
((_c = (_b = injectedConfig === null || injectedConfig === void 0 ? void 0 : injectedConfig.walletStandard) === null || _b === void 0 ? void 0 : _b.features) === null || _c === void 0 ? void 0 : _c.length);
|
|
114
|
+
return isAptosWallet && !shouldBeFiltered;
|
|
115
|
+
})
|
|
116
|
+
.map(([key, wallet]) => {
|
|
117
|
+
const { shortName } = wallet;
|
|
118
|
+
const name = shortName || wallet.name;
|
|
119
|
+
return class extends InjectedWalletBase {
|
|
120
|
+
constructor() {
|
|
121
|
+
super(...arguments);
|
|
122
|
+
this.name = name;
|
|
123
|
+
// This is the key from the wallet book entry so that we don't purely rely on the normalized name
|
|
124
|
+
this.overrideKey = key;
|
|
125
|
+
}
|
|
126
|
+
getProvider() {
|
|
127
|
+
return this.findProvider();
|
|
128
|
+
}
|
|
129
|
+
};
|
|
130
|
+
});
|
|
131
|
+
// Get wallet-standard wallets
|
|
132
|
+
const { aptosWallets } = getWalletStandardWallets();
|
|
133
|
+
logger.logVerboseTroubleshootingMessage('[APTOS fetchInjectedWalletConnectors] Found wallet-standard wallets:', aptosWallets.map((w) => ({
|
|
134
|
+
features: Object.keys(w.features),
|
|
135
|
+
name: w.name,
|
|
136
|
+
})));
|
|
137
|
+
// Create connectors for wallet-standard wallets
|
|
138
|
+
const walletStandardConnectors = aptosWallets
|
|
139
|
+
.filter((wallet) =>
|
|
140
|
+
// Type incompatibility between @wallet-standard versions, casting is safe here
|
|
141
|
+
shouldAddWalletStandardConnector(
|
|
142
|
+
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
143
|
+
wallet, walletBook))
|
|
144
|
+
.map((wallet) => {
|
|
145
|
+
const walletBookWallet = findWalletBookWalletByNameAndChain(walletBook, wallet.name, 'aptos');
|
|
146
|
+
// If the wallet book wallet is found, we want to use it to get the metadata
|
|
147
|
+
// to merge with the wallet-standard metadata, especially for additional properties
|
|
148
|
+
const walletBookMetadata = walletBookWallet &&
|
|
149
|
+
getWalletMetadataFromWalletBook({
|
|
150
|
+
walletBook,
|
|
151
|
+
walletBookWallet,
|
|
152
|
+
walletKey: `${sanitizeName(wallet.name)}aptos`,
|
|
153
|
+
});
|
|
154
|
+
// Type incompatibility between @wallet-standard versions, casting is safe here
|
|
155
|
+
return getConnectorConstructorForWalletStandardWallet(
|
|
156
|
+
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
157
|
+
wallet, walletBookMetadata);
|
|
158
|
+
});
|
|
159
|
+
logger.logVerboseTroubleshootingMessage('[APTOS fetchInjectedWalletConnectors] Created wallet-standard connectors:', walletStandardConnectors.map((w) => w.name));
|
|
160
|
+
logger.logVerboseTroubleshootingMessage('[APTOS fetchInjectedWalletConnectors] Created wallet-book connectors:', walletBookConnectors.map((w) => w.name));
|
|
161
|
+
return [
|
|
162
|
+
...walletBookConnectors,
|
|
163
|
+
...walletStandardConnectors,
|
|
164
|
+
];
|
|
165
|
+
};
|
|
166
|
+
|
|
167
|
+
export { fetchInjectedWalletConnectors };
|
package/src/types.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { AccountAuthenticator, AnyRawTransaction } from '@aptos-labs/ts-sdk';
|
|
2
2
|
import type { AccountInfo, AptosSignMessageInput, AptosSignMessageOutput, NetworkInfo, UserResponse } from '@aptos-labs/wallet-standard';
|
|
3
|
+
import { ProviderCondition } from '@dynamic-labs/wallet-connector-core';
|
|
3
4
|
/**
|
|
4
5
|
* Interface for AIP-62 compliant Aptos wallet providers.
|
|
5
6
|
*
|
|
@@ -30,7 +31,7 @@ import type { AccountInfo, AptosSignMessageInput, AptosSignMessageOutput, Networ
|
|
|
30
31
|
*/
|
|
31
32
|
export interface IAptosProvider {
|
|
32
33
|
/** Wallet-standard features (AIP-62 compliant wallets) */
|
|
33
|
-
features
|
|
34
|
+
features?: {
|
|
34
35
|
'aptos:connect'?: {
|
|
35
36
|
version: string;
|
|
36
37
|
connect(): Promise<UserResponse<AccountInfo>>;
|
|
@@ -78,6 +79,19 @@ export interface IAptosProvider {
|
|
|
78
79
|
getNetwork(): Promise<NetworkInfo>;
|
|
79
80
|
};
|
|
80
81
|
};
|
|
82
|
+
account: () => Promise<AccountInfo>;
|
|
83
|
+
connect: () => Promise<UserResponse<AccountInfo>>;
|
|
84
|
+
disconnect: () => Promise<void>;
|
|
85
|
+
signTransaction(transaction: AnyRawTransaction, asFeePayer?: boolean): Promise<UserResponse<AccountAuthenticator>>;
|
|
86
|
+
signMessage(input: AptosSignMessageInput): Promise<UserResponse<AptosSignMessageOutput>>;
|
|
87
|
+
signAndSubmitTransaction(transaction: AnyRawTransaction): Promise<UserResponse<{
|
|
88
|
+
hash: string;
|
|
89
|
+
}>>;
|
|
90
|
+
getNetwork?: () => Promise<NetworkInfo>;
|
|
91
|
+
onAccountChange?: (callback: (account: AccountInfo | null) => void) => void;
|
|
92
|
+
onNetworkChange?: (callback: (network: NetworkInfo) => void) => void;
|
|
93
|
+
onDisconnect?: (callback: () => void) => void;
|
|
94
|
+
isConnected?: () => Promise<boolean>;
|
|
81
95
|
}
|
|
82
96
|
/**
|
|
83
97
|
* Result from wallet connection (wallet-standard only)
|
|
@@ -112,3 +126,10 @@ export interface AptosWalletConnectorProps {
|
|
|
112
126
|
}
|
|
113
127
|
export type AptosFeatureName = keyof NonNullable<IAptosProvider['features']>;
|
|
114
128
|
export type AptosMethodName = 'connect' | 'disconnect' | 'signTransaction' | 'signMessage' | 'signAndSubmitTransaction' | 'submitTransaction' | 'getNetwork' | 'network' | 'account' | 'onAccountChange' | 'onNetworkChange';
|
|
129
|
+
/**
|
|
130
|
+
* Extension locators for identifying Aptos wallet browser extensions.
|
|
131
|
+
* These flags are typically set on the injected provider object to identify
|
|
132
|
+
* which wallet extension is present.
|
|
133
|
+
*/
|
|
134
|
+
export type ExtensionLocator = 'isPetraWallet' | 'isNightlyWallet' | 'isPontemWallet' | 'isMartianWallet' | 'isFewchaWallet' | 'isRiseWallet' | 'isMSafeWallet' | 'isOkxWallet' | 'isBitgetWallet' | 'isBackpackWallet';
|
|
135
|
+
export type AptosProviderCondition = ProviderCondition<ExtensionLocator>;
|
|
@@ -3,9 +3,10 @@
|
|
|
3
3
|
|
|
4
4
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
5
5
|
|
|
6
|
-
var core = require('@wallet-standard/core');
|
|
7
6
|
var walletStandard = require('@aptos-labs/wallet-standard');
|
|
7
|
+
var logger$1 = require('@dynamic-labs/logger');
|
|
8
8
|
|
|
9
|
+
const logger = new logger$1.Logger('getWalletStandardWallets');
|
|
9
10
|
/**
|
|
10
11
|
* Retrieves all available Aptos-compatible wallets from the wallet standard registry.
|
|
11
12
|
*
|
|
@@ -34,16 +35,34 @@ var walletStandard = require('@aptos-labs/wallet-standard');
|
|
|
34
35
|
* ```
|
|
35
36
|
*/
|
|
36
37
|
const getWalletStandardWallets = () => {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
38
|
+
try {
|
|
39
|
+
const { aptosWallets } = walletStandard.getAptosWallets();
|
|
40
|
+
const foundAptosWallets = [];
|
|
41
|
+
aptosWallets.map((wallet) => {
|
|
42
|
+
try {
|
|
43
|
+
const isAptos = walletStandard.isWalletWithRequiredFeatureSet(wallet);
|
|
44
|
+
if (isAptos) {
|
|
45
|
+
foundAptosWallets.push(wallet);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
catch (error) {
|
|
49
|
+
// Log error for individual wallet but continue processing others
|
|
50
|
+
logger.debug('[getWalletStandardWallets] Error checking wallet features:', error);
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
return {
|
|
54
|
+
aptosWallets: foundAptosWallets,
|
|
55
|
+
on: () => () => { },
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
catch (error) {
|
|
59
|
+
// If wallet discovery fails completely, return empty array
|
|
60
|
+
logger.error('[getWalletStandardWallets] Failed to discover wallets:', error);
|
|
61
|
+
return {
|
|
62
|
+
aptosWallets: [],
|
|
63
|
+
on: () => () => { },
|
|
64
|
+
};
|
|
65
|
+
}
|
|
47
66
|
};
|
|
48
67
|
|
|
49
68
|
exports.getWalletStandardWallets = getWalletStandardWallets;
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
'use client'
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
2
|
+
import { getAptosWallets, isWalletWithRequiredFeatureSet } from '@aptos-labs/wallet-standard';
|
|
3
|
+
import { Logger } from '@dynamic-labs/logger';
|
|
4
4
|
|
|
5
|
+
const logger = new Logger('getWalletStandardWallets');
|
|
5
6
|
/**
|
|
6
7
|
* Retrieves all available Aptos-compatible wallets from the wallet standard registry.
|
|
7
8
|
*
|
|
@@ -30,16 +31,34 @@ import { isWalletWithRequiredFeatureSet } from '@aptos-labs/wallet-standard';
|
|
|
30
31
|
* ```
|
|
31
32
|
*/
|
|
32
33
|
const getWalletStandardWallets = () => {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
34
|
+
try {
|
|
35
|
+
const { aptosWallets } = getAptosWallets();
|
|
36
|
+
const foundAptosWallets = [];
|
|
37
|
+
aptosWallets.map((wallet) => {
|
|
38
|
+
try {
|
|
39
|
+
const isAptos = isWalletWithRequiredFeatureSet(wallet);
|
|
40
|
+
if (isAptos) {
|
|
41
|
+
foundAptosWallets.push(wallet);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
catch (error) {
|
|
45
|
+
// Log error for individual wallet but continue processing others
|
|
46
|
+
logger.debug('[getWalletStandardWallets] Error checking wallet features:', error);
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
return {
|
|
50
|
+
aptosWallets: foundAptosWallets,
|
|
51
|
+
on: () => () => { },
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
catch (error) {
|
|
55
|
+
// If wallet discovery fails completely, return empty array
|
|
56
|
+
logger.error('[getWalletStandardWallets] Failed to discover wallets:', error);
|
|
57
|
+
return {
|
|
58
|
+
aptosWallets: [],
|
|
59
|
+
on: () => () => { },
|
|
60
|
+
};
|
|
61
|
+
}
|
|
43
62
|
};
|
|
44
63
|
|
|
45
64
|
export { getWalletStandardWallets };
|
|
@@ -0,0 +1,244 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
5
|
+
|
|
6
|
+
var _tslib = require('../../_virtual/_tslib.cjs');
|
|
7
|
+
var walletStandard = require('@aptos-labs/wallet-standard');
|
|
8
|
+
var logger$1 = require('@dynamic-labs/logger');
|
|
9
|
+
|
|
10
|
+
const logger = new logger$1.Logger('AptosWalletStandardConnector');
|
|
11
|
+
const createAptosSignerFromWalletStandard = ({ wallet, walletConnector, }) => {
|
|
12
|
+
const features = wallet.features;
|
|
13
|
+
const hasAutoConnectedAccounts = () => {
|
|
14
|
+
var _a, _b, _c;
|
|
15
|
+
return Boolean(((_a = wallet.accounts) === null || _a === void 0 ? void 0 : _a.length) > 0 &&
|
|
16
|
+
((_b = wallet.accounts[0]) === null || _b === void 0 ? void 0 : _b.publicKey) &&
|
|
17
|
+
((_c = wallet.accounts[0]) === null || _c === void 0 ? void 0 : _c.address));
|
|
18
|
+
};
|
|
19
|
+
const getCurrentAccount = () => _tslib.__awaiter(void 0, void 0, void 0, function* () {
|
|
20
|
+
var _a, _b;
|
|
21
|
+
const accountMethod = (_a = features['aptos:account']) === null || _a === void 0 ? void 0 : _a.account;
|
|
22
|
+
if (accountMethod) {
|
|
23
|
+
return accountMethod();
|
|
24
|
+
}
|
|
25
|
+
if (((_b = wallet.accounts) === null || _b === void 0 ? void 0 : _b.length) > 0) {
|
|
26
|
+
const [account] = wallet.accounts;
|
|
27
|
+
// Validate that the account has valid address and publicKey
|
|
28
|
+
if (account.address && account.publicKey) {
|
|
29
|
+
const addressStr = account.address.toString();
|
|
30
|
+
if (addressStr && addressStr !== '0x' && addressStr.length > 2) {
|
|
31
|
+
return new walletStandard.AccountInfo({
|
|
32
|
+
address: account.address,
|
|
33
|
+
// using this typing since account.publicKey is a ReadonlyUint8Array
|
|
34
|
+
publicKey: account.publicKey,
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
throw new Error('Account not found');
|
|
40
|
+
});
|
|
41
|
+
const connect = () => _tslib.__awaiter(void 0, void 0, void 0, function* () {
|
|
42
|
+
var _c;
|
|
43
|
+
const autoConnectedAccounts = wallet.accounts || [];
|
|
44
|
+
if (hasAutoConnectedAccounts()) {
|
|
45
|
+
const [account] = autoConnectedAccounts;
|
|
46
|
+
return {
|
|
47
|
+
args: new walletStandard.AccountInfo({
|
|
48
|
+
address: account.address,
|
|
49
|
+
publicKey: account.publicKey,
|
|
50
|
+
}),
|
|
51
|
+
status: walletStandard.UserResponseStatus.APPROVED,
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
const connectMethod = (_c = features['aptos:connect']) === null || _c === void 0 ? void 0 : _c.connect;
|
|
55
|
+
if (!connectMethod) {
|
|
56
|
+
throw new Error('Connect method not implemented by wallet');
|
|
57
|
+
}
|
|
58
|
+
const result = yield connectMethod();
|
|
59
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
60
|
+
const resultArgs = result.args;
|
|
61
|
+
if (!(resultArgs === null || resultArgs === void 0 ? void 0 : resultArgs.address)) {
|
|
62
|
+
throw new Error('No account connected');
|
|
63
|
+
}
|
|
64
|
+
return {
|
|
65
|
+
args: new walletStandard.AccountInfo({
|
|
66
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
67
|
+
address: resultArgs.address,
|
|
68
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
69
|
+
publicKey: resultArgs.publicKey,
|
|
70
|
+
}),
|
|
71
|
+
status: walletStandard.UserResponseStatus.APPROVED,
|
|
72
|
+
};
|
|
73
|
+
});
|
|
74
|
+
const disconnect = () => _tslib.__awaiter(void 0, void 0, void 0, function* () {
|
|
75
|
+
var _d;
|
|
76
|
+
const disconnectMethod = (_d = features['aptos:disconnect']) === null || _d === void 0 ? void 0 : _d.disconnect;
|
|
77
|
+
if (!disconnectMethod) {
|
|
78
|
+
logger.debug('[AptosWalletStandardConnector] Disconnect method not implemented');
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
yield disconnectMethod();
|
|
82
|
+
});
|
|
83
|
+
const account = () => _tslib.__awaiter(void 0, void 0, void 0, function* () {
|
|
84
|
+
const currentAccount = yield getCurrentAccount();
|
|
85
|
+
const address = typeof currentAccount === 'string'
|
|
86
|
+
? currentAccount
|
|
87
|
+
: currentAccount.address;
|
|
88
|
+
return new walletStandard.AccountInfo({
|
|
89
|
+
address: address,
|
|
90
|
+
publicKey: currentAccount.publicKey,
|
|
91
|
+
});
|
|
92
|
+
});
|
|
93
|
+
const network = () => _tslib.__awaiter(void 0, void 0, void 0, function* () {
|
|
94
|
+
try {
|
|
95
|
+
// Try to get network info from the wallet connector
|
|
96
|
+
const networkInfo = yield walletConnector.getNetworkInfo();
|
|
97
|
+
if (networkInfo) {
|
|
98
|
+
return networkInfo;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
catch (err) {
|
|
102
|
+
logger.debug('[AptosWalletStandardConnector] Failed to get network info from connector:', err);
|
|
103
|
+
}
|
|
104
|
+
// Return a default mainnet if not available
|
|
105
|
+
return {
|
|
106
|
+
chainId: 1,
|
|
107
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
108
|
+
name: 'Mainnet',
|
|
109
|
+
url: 'https://fullnode.mainnet.aptoslabs.com/v1',
|
|
110
|
+
};
|
|
111
|
+
});
|
|
112
|
+
const signTransaction = (transaction, asFeePayer) => _tslib.__awaiter(void 0, void 0, void 0, function* () {
|
|
113
|
+
const signTransactionMethod = features['aptos:signTransaction'];
|
|
114
|
+
if (!(signTransactionMethod === null || signTransactionMethod === void 0 ? void 0 : signTransactionMethod.signTransaction)) {
|
|
115
|
+
logger.error('[AptosWalletStandardConnector] Sign transaction not implemented by wallet');
|
|
116
|
+
throw new Error('Sign transaction not implemented by wallet');
|
|
117
|
+
}
|
|
118
|
+
const result = yield signTransactionMethod.signTransaction(transaction, asFeePayer);
|
|
119
|
+
return result;
|
|
120
|
+
});
|
|
121
|
+
const signMessage = (input) => _tslib.__awaiter(void 0, void 0, void 0, function* () {
|
|
122
|
+
const signMessageMethod = features['aptos:signMessage'];
|
|
123
|
+
if (!(signMessageMethod === null || signMessageMethod === void 0 ? void 0 : signMessageMethod.signMessage)) {
|
|
124
|
+
logger.error('[AptosWalletStandardConnector] Sign message not implemented by wallet');
|
|
125
|
+
throw new Error('Sign message not implemented by wallet');
|
|
126
|
+
}
|
|
127
|
+
const result = yield signMessageMethod.signMessage(input);
|
|
128
|
+
return result;
|
|
129
|
+
});
|
|
130
|
+
const signAndSubmitTransaction = (transaction) => _tslib.__awaiter(void 0, void 0, void 0, function* () {
|
|
131
|
+
const signAndSubmitMethod = features['aptos:signAndSubmitTransaction'];
|
|
132
|
+
if (!(signAndSubmitMethod === null || signAndSubmitMethod === void 0 ? void 0 : signAndSubmitMethod.signAndSubmitTransaction)) {
|
|
133
|
+
logger.error('[AptosWalletStandardConnector] Sign and submit transaction not implemented by wallet');
|
|
134
|
+
throw new Error('Sign and submit transaction not implemented by wallet');
|
|
135
|
+
}
|
|
136
|
+
const result = yield signAndSubmitMethod.signAndSubmitTransaction({
|
|
137
|
+
transaction,
|
|
138
|
+
});
|
|
139
|
+
return result;
|
|
140
|
+
});
|
|
141
|
+
const onAccountChange = (callback) => {
|
|
142
|
+
var _a;
|
|
143
|
+
const onMethod = (_a = features['standard:events']) === null || _a === void 0 ? void 0 : _a.on;
|
|
144
|
+
if (!onMethod) {
|
|
145
|
+
logger.debug('[AptosWalletStandardConnector] Events not implemented by wallet');
|
|
146
|
+
return () => { };
|
|
147
|
+
}
|
|
148
|
+
logger.debug('[AptosWalletStandardConnector] Setting up account change listener');
|
|
149
|
+
const wrappedCallback = (prop) => {
|
|
150
|
+
var _a;
|
|
151
|
+
const account = (_a = prop.accounts) === null || _a === void 0 ? void 0 : _a[0];
|
|
152
|
+
if (account) {
|
|
153
|
+
callback(new walletStandard.AccountInfo({
|
|
154
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
155
|
+
address: account.address,
|
|
156
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
157
|
+
publicKey: account.publicKey,
|
|
158
|
+
}));
|
|
159
|
+
}
|
|
160
|
+
else {
|
|
161
|
+
callback(null);
|
|
162
|
+
}
|
|
163
|
+
};
|
|
164
|
+
// 'change' is the only event that is supported by the wallet standard
|
|
165
|
+
return onMethod('change', wrappedCallback);
|
|
166
|
+
};
|
|
167
|
+
const onNetworkChange = (callback) => {
|
|
168
|
+
var _a;
|
|
169
|
+
const onMethod = (_a = features['standard:events']) === null || _a === void 0 ? void 0 : _a.on;
|
|
170
|
+
if (!onMethod) {
|
|
171
|
+
logger.debug('[AptosWalletStandardConnector] Events not implemented by wallet');
|
|
172
|
+
return () => { };
|
|
173
|
+
}
|
|
174
|
+
logger.debug('[AptosWalletStandardConnector] Setting up network change listener');
|
|
175
|
+
const wrappedCallback = (prop) => {
|
|
176
|
+
// Network changes might be indicated through feature changes
|
|
177
|
+
// This is wallet-specific and may need adjustment
|
|
178
|
+
if (prop.features) {
|
|
179
|
+
// Trigger network check
|
|
180
|
+
network()
|
|
181
|
+
.then((networkInfo) => {
|
|
182
|
+
if (networkInfo) {
|
|
183
|
+
callback(networkInfo);
|
|
184
|
+
}
|
|
185
|
+
})
|
|
186
|
+
.catch((err) => {
|
|
187
|
+
logger.debug('[AptosWalletStandardConnector] Failed to get network info:', err);
|
|
188
|
+
});
|
|
189
|
+
}
|
|
190
|
+
};
|
|
191
|
+
// 'change' is the only event that is supported by the wallet standard
|
|
192
|
+
return onMethod('change', wrappedCallback);
|
|
193
|
+
};
|
|
194
|
+
return {
|
|
195
|
+
account,
|
|
196
|
+
connect,
|
|
197
|
+
disconnect,
|
|
198
|
+
features: {
|
|
199
|
+
'aptos:account': {
|
|
200
|
+
account,
|
|
201
|
+
version: '1.0.0',
|
|
202
|
+
},
|
|
203
|
+
'aptos:connect': {
|
|
204
|
+
connect,
|
|
205
|
+
version: '1.0.0',
|
|
206
|
+
},
|
|
207
|
+
'aptos:disconnect': {
|
|
208
|
+
disconnect,
|
|
209
|
+
version: '1.0.0',
|
|
210
|
+
},
|
|
211
|
+
'aptos:network': {
|
|
212
|
+
network,
|
|
213
|
+
version: '1.0.0',
|
|
214
|
+
},
|
|
215
|
+
'aptos:onAccountChange': {
|
|
216
|
+
onAccountChange,
|
|
217
|
+
version: '1.0.0',
|
|
218
|
+
},
|
|
219
|
+
'aptos:onNetworkChange': {
|
|
220
|
+
onNetworkChange,
|
|
221
|
+
version: '1.0.0',
|
|
222
|
+
},
|
|
223
|
+
'aptos:signAndSubmitTransaction': {
|
|
224
|
+
signAndSubmitTransaction,
|
|
225
|
+
version: '1.0.0',
|
|
226
|
+
},
|
|
227
|
+
'aptos:signMessage': {
|
|
228
|
+
signMessage,
|
|
229
|
+
version: '1.0.0',
|
|
230
|
+
},
|
|
231
|
+
'aptos:signTransaction': {
|
|
232
|
+
signTransaction,
|
|
233
|
+
version: '1.0.0',
|
|
234
|
+
},
|
|
235
|
+
},
|
|
236
|
+
onAccountChange,
|
|
237
|
+
onNetworkChange,
|
|
238
|
+
signAndSubmitTransaction,
|
|
239
|
+
signMessage,
|
|
240
|
+
signTransaction,
|
|
241
|
+
};
|
|
242
|
+
};
|
|
243
|
+
|
|
244
|
+
exports.createAptosSignerFromWalletStandard = createAptosSignerFromWalletStandard;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { Wallet } from '@aptos-labs/wallet-standard';
|
|
2
|
+
import type { IAptosProvider } from '../types';
|
|
3
|
+
import { AptosWalletConnector } from '../connectors/AptosWalletConnector';
|
|
4
|
+
type CreateAptosSignerFromWalletStandardProps = {
|
|
5
|
+
wallet: Wallet;
|
|
6
|
+
walletConnector: AptosWalletConnector;
|
|
7
|
+
};
|
|
8
|
+
export declare const createAptosSignerFromWalletStandard: ({ wallet, walletConnector, }: CreateAptosSignerFromWalletStandardProps) => IAptosProvider;
|
|
9
|
+
export {};
|