@dynamic-labs/aptos 4.39.0 → 4.40.1
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 +19 -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,240 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
import { __awaiter } from '../../_virtual/_tslib.js';
|
|
3
|
+
import { AccountInfo, UserResponseStatus } from '@aptos-labs/wallet-standard';
|
|
4
|
+
import { Logger } from '@dynamic-labs/logger';
|
|
5
|
+
|
|
6
|
+
const logger = new Logger('AptosWalletStandardConnector');
|
|
7
|
+
const createAptosSignerFromWalletStandard = ({ wallet, walletConnector, }) => {
|
|
8
|
+
const features = wallet.features;
|
|
9
|
+
const hasAutoConnectedAccounts = () => {
|
|
10
|
+
var _a, _b, _c;
|
|
11
|
+
return Boolean(((_a = wallet.accounts) === null || _a === void 0 ? void 0 : _a.length) > 0 &&
|
|
12
|
+
((_b = wallet.accounts[0]) === null || _b === void 0 ? void 0 : _b.publicKey) &&
|
|
13
|
+
((_c = wallet.accounts[0]) === null || _c === void 0 ? void 0 : _c.address));
|
|
14
|
+
};
|
|
15
|
+
const getCurrentAccount = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
16
|
+
var _a, _b;
|
|
17
|
+
const accountMethod = (_a = features['aptos:account']) === null || _a === void 0 ? void 0 : _a.account;
|
|
18
|
+
if (accountMethod) {
|
|
19
|
+
return accountMethod();
|
|
20
|
+
}
|
|
21
|
+
if (((_b = wallet.accounts) === null || _b === void 0 ? void 0 : _b.length) > 0) {
|
|
22
|
+
const [account] = wallet.accounts;
|
|
23
|
+
// Validate that the account has valid address and publicKey
|
|
24
|
+
if (account.address && account.publicKey) {
|
|
25
|
+
const addressStr = account.address.toString();
|
|
26
|
+
if (addressStr && addressStr !== '0x' && addressStr.length > 2) {
|
|
27
|
+
return new AccountInfo({
|
|
28
|
+
address: account.address,
|
|
29
|
+
// using this typing since account.publicKey is a ReadonlyUint8Array
|
|
30
|
+
publicKey: account.publicKey,
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
throw new Error('Account not found');
|
|
36
|
+
});
|
|
37
|
+
const connect = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
38
|
+
var _c;
|
|
39
|
+
const autoConnectedAccounts = wallet.accounts || [];
|
|
40
|
+
if (hasAutoConnectedAccounts()) {
|
|
41
|
+
const [account] = autoConnectedAccounts;
|
|
42
|
+
return {
|
|
43
|
+
args: new AccountInfo({
|
|
44
|
+
address: account.address,
|
|
45
|
+
publicKey: account.publicKey,
|
|
46
|
+
}),
|
|
47
|
+
status: UserResponseStatus.APPROVED,
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
const connectMethod = (_c = features['aptos:connect']) === null || _c === void 0 ? void 0 : _c.connect;
|
|
51
|
+
if (!connectMethod) {
|
|
52
|
+
throw new Error('Connect method not implemented by wallet');
|
|
53
|
+
}
|
|
54
|
+
const result = yield connectMethod();
|
|
55
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
56
|
+
const resultArgs = result.args;
|
|
57
|
+
if (!(resultArgs === null || resultArgs === void 0 ? void 0 : resultArgs.address)) {
|
|
58
|
+
throw new Error('No account connected');
|
|
59
|
+
}
|
|
60
|
+
return {
|
|
61
|
+
args: new AccountInfo({
|
|
62
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
63
|
+
address: resultArgs.address,
|
|
64
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
65
|
+
publicKey: resultArgs.publicKey,
|
|
66
|
+
}),
|
|
67
|
+
status: UserResponseStatus.APPROVED,
|
|
68
|
+
};
|
|
69
|
+
});
|
|
70
|
+
const disconnect = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
71
|
+
var _d;
|
|
72
|
+
const disconnectMethod = (_d = features['aptos:disconnect']) === null || _d === void 0 ? void 0 : _d.disconnect;
|
|
73
|
+
if (!disconnectMethod) {
|
|
74
|
+
logger.debug('[AptosWalletStandardConnector] Disconnect method not implemented');
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
yield disconnectMethod();
|
|
78
|
+
});
|
|
79
|
+
const account = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
80
|
+
const currentAccount = yield getCurrentAccount();
|
|
81
|
+
const address = typeof currentAccount === 'string'
|
|
82
|
+
? currentAccount
|
|
83
|
+
: currentAccount.address;
|
|
84
|
+
return new AccountInfo({
|
|
85
|
+
address: address,
|
|
86
|
+
publicKey: currentAccount.publicKey,
|
|
87
|
+
});
|
|
88
|
+
});
|
|
89
|
+
const network = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
90
|
+
try {
|
|
91
|
+
// Try to get network info from the wallet connector
|
|
92
|
+
const networkInfo = yield walletConnector.getNetworkInfo();
|
|
93
|
+
if (networkInfo) {
|
|
94
|
+
return networkInfo;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
catch (err) {
|
|
98
|
+
logger.debug('[AptosWalletStandardConnector] Failed to get network info from connector:', err);
|
|
99
|
+
}
|
|
100
|
+
// Return a default mainnet if not available
|
|
101
|
+
return {
|
|
102
|
+
chainId: 1,
|
|
103
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
104
|
+
name: 'Mainnet',
|
|
105
|
+
url: 'https://fullnode.mainnet.aptoslabs.com/v1',
|
|
106
|
+
};
|
|
107
|
+
});
|
|
108
|
+
const signTransaction = (transaction, asFeePayer) => __awaiter(void 0, void 0, void 0, function* () {
|
|
109
|
+
const signTransactionMethod = features['aptos:signTransaction'];
|
|
110
|
+
if (!(signTransactionMethod === null || signTransactionMethod === void 0 ? void 0 : signTransactionMethod.signTransaction)) {
|
|
111
|
+
logger.error('[AptosWalletStandardConnector] Sign transaction not implemented by wallet');
|
|
112
|
+
throw new Error('Sign transaction not implemented by wallet');
|
|
113
|
+
}
|
|
114
|
+
const result = yield signTransactionMethod.signTransaction(transaction, asFeePayer);
|
|
115
|
+
return result;
|
|
116
|
+
});
|
|
117
|
+
const signMessage = (input) => __awaiter(void 0, void 0, void 0, function* () {
|
|
118
|
+
const signMessageMethod = features['aptos:signMessage'];
|
|
119
|
+
if (!(signMessageMethod === null || signMessageMethod === void 0 ? void 0 : signMessageMethod.signMessage)) {
|
|
120
|
+
logger.error('[AptosWalletStandardConnector] Sign message not implemented by wallet');
|
|
121
|
+
throw new Error('Sign message not implemented by wallet');
|
|
122
|
+
}
|
|
123
|
+
const result = yield signMessageMethod.signMessage(input);
|
|
124
|
+
return result;
|
|
125
|
+
});
|
|
126
|
+
const signAndSubmitTransaction = (transaction) => __awaiter(void 0, void 0, void 0, function* () {
|
|
127
|
+
const signAndSubmitMethod = features['aptos:signAndSubmitTransaction'];
|
|
128
|
+
if (!(signAndSubmitMethod === null || signAndSubmitMethod === void 0 ? void 0 : signAndSubmitMethod.signAndSubmitTransaction)) {
|
|
129
|
+
logger.error('[AptosWalletStandardConnector] Sign and submit transaction not implemented by wallet');
|
|
130
|
+
throw new Error('Sign and submit transaction not implemented by wallet');
|
|
131
|
+
}
|
|
132
|
+
const result = yield signAndSubmitMethod.signAndSubmitTransaction({
|
|
133
|
+
transaction,
|
|
134
|
+
});
|
|
135
|
+
return result;
|
|
136
|
+
});
|
|
137
|
+
const onAccountChange = (callback) => {
|
|
138
|
+
var _a;
|
|
139
|
+
const onMethod = (_a = features['standard:events']) === null || _a === void 0 ? void 0 : _a.on;
|
|
140
|
+
if (!onMethod) {
|
|
141
|
+
logger.debug('[AptosWalletStandardConnector] Events not implemented by wallet');
|
|
142
|
+
return () => { };
|
|
143
|
+
}
|
|
144
|
+
logger.debug('[AptosWalletStandardConnector] Setting up account change listener');
|
|
145
|
+
const wrappedCallback = (prop) => {
|
|
146
|
+
var _a;
|
|
147
|
+
const account = (_a = prop.accounts) === null || _a === void 0 ? void 0 : _a[0];
|
|
148
|
+
if (account) {
|
|
149
|
+
callback(new AccountInfo({
|
|
150
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
151
|
+
address: account.address,
|
|
152
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
153
|
+
publicKey: account.publicKey,
|
|
154
|
+
}));
|
|
155
|
+
}
|
|
156
|
+
else {
|
|
157
|
+
callback(null);
|
|
158
|
+
}
|
|
159
|
+
};
|
|
160
|
+
// 'change' is the only event that is supported by the wallet standard
|
|
161
|
+
return onMethod('change', wrappedCallback);
|
|
162
|
+
};
|
|
163
|
+
const onNetworkChange = (callback) => {
|
|
164
|
+
var _a;
|
|
165
|
+
const onMethod = (_a = features['standard:events']) === null || _a === void 0 ? void 0 : _a.on;
|
|
166
|
+
if (!onMethod) {
|
|
167
|
+
logger.debug('[AptosWalletStandardConnector] Events not implemented by wallet');
|
|
168
|
+
return () => { };
|
|
169
|
+
}
|
|
170
|
+
logger.debug('[AptosWalletStandardConnector] Setting up network change listener');
|
|
171
|
+
const wrappedCallback = (prop) => {
|
|
172
|
+
// Network changes might be indicated through feature changes
|
|
173
|
+
// This is wallet-specific and may need adjustment
|
|
174
|
+
if (prop.features) {
|
|
175
|
+
// Trigger network check
|
|
176
|
+
network()
|
|
177
|
+
.then((networkInfo) => {
|
|
178
|
+
if (networkInfo) {
|
|
179
|
+
callback(networkInfo);
|
|
180
|
+
}
|
|
181
|
+
})
|
|
182
|
+
.catch((err) => {
|
|
183
|
+
logger.debug('[AptosWalletStandardConnector] Failed to get network info:', err);
|
|
184
|
+
});
|
|
185
|
+
}
|
|
186
|
+
};
|
|
187
|
+
// 'change' is the only event that is supported by the wallet standard
|
|
188
|
+
return onMethod('change', wrappedCallback);
|
|
189
|
+
};
|
|
190
|
+
return {
|
|
191
|
+
account,
|
|
192
|
+
connect,
|
|
193
|
+
disconnect,
|
|
194
|
+
features: {
|
|
195
|
+
'aptos:account': {
|
|
196
|
+
account,
|
|
197
|
+
version: '1.0.0',
|
|
198
|
+
},
|
|
199
|
+
'aptos:connect': {
|
|
200
|
+
connect,
|
|
201
|
+
version: '1.0.0',
|
|
202
|
+
},
|
|
203
|
+
'aptos:disconnect': {
|
|
204
|
+
disconnect,
|
|
205
|
+
version: '1.0.0',
|
|
206
|
+
},
|
|
207
|
+
'aptos:network': {
|
|
208
|
+
network,
|
|
209
|
+
version: '1.0.0',
|
|
210
|
+
},
|
|
211
|
+
'aptos:onAccountChange': {
|
|
212
|
+
onAccountChange,
|
|
213
|
+
version: '1.0.0',
|
|
214
|
+
},
|
|
215
|
+
'aptos:onNetworkChange': {
|
|
216
|
+
onNetworkChange,
|
|
217
|
+
version: '1.0.0',
|
|
218
|
+
},
|
|
219
|
+
'aptos:signAndSubmitTransaction': {
|
|
220
|
+
signAndSubmitTransaction,
|
|
221
|
+
version: '1.0.0',
|
|
222
|
+
},
|
|
223
|
+
'aptos:signMessage': {
|
|
224
|
+
signMessage,
|
|
225
|
+
version: '1.0.0',
|
|
226
|
+
},
|
|
227
|
+
'aptos:signTransaction': {
|
|
228
|
+
signTransaction,
|
|
229
|
+
version: '1.0.0',
|
|
230
|
+
},
|
|
231
|
+
},
|
|
232
|
+
onAccountChange,
|
|
233
|
+
onNetworkChange,
|
|
234
|
+
signAndSubmitTransaction,
|
|
235
|
+
signMessage,
|
|
236
|
+
signTransaction,
|
|
237
|
+
};
|
|
238
|
+
};
|
|
239
|
+
|
|
240
|
+
export { createAptosSignerFromWalletStandard };
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
5
|
+
|
|
6
|
+
var utils = require('@dynamic-labs/utils');
|
|
7
|
+
var InjectedWalletBase = require('../injected/InjectedWalletBase.cjs');
|
|
8
|
+
var createAptosSignerFromWalletStandard = require('./createAptosSignerFromWalletStandard.cjs');
|
|
9
|
+
|
|
10
|
+
const getConnectorConstructorForWalletStandardWallet = (wallet, walletBookMetadata = {}) => {
|
|
11
|
+
const sanitizedName = utils.sanitizeName(wallet.name);
|
|
12
|
+
return class extends InjectedWalletBase.InjectedWalletBase {
|
|
13
|
+
constructor(props) {
|
|
14
|
+
super(wallet.name, Object.assign(Object.assign({}, props), { metadata: Object.assign(Object.assign({}, walletBookMetadata), { groupKey: sanitizedName, icon: wallet.icon, id: sanitizedName, name: wallet.name }) }));
|
|
15
|
+
this.name = wallet.name;
|
|
16
|
+
this.overrideKey = `${sanitizedName}aptos`;
|
|
17
|
+
this._provider = createAptosSignerFromWalletStandard.createAptosSignerFromWalletStandard({
|
|
18
|
+
wallet,
|
|
19
|
+
walletConnector: this,
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
findProvider() {
|
|
23
|
+
return this._provider;
|
|
24
|
+
}
|
|
25
|
+
getProvider() {
|
|
26
|
+
return this._provider;
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
exports.getConnectorConstructorForWalletStandardWallet = getConnectorConstructorForWalletStandardWallet;
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { Wallet } from '@aptos-labs/wallet-standard';
|
|
2
|
+
import { WalletConnectorConstructor, WalletMetadata } from '@dynamic-labs/wallet-connector-core';
|
|
3
|
+
export declare const getConnectorConstructorForWalletStandardWallet: (wallet: Wallet, walletBookMetadata?: Partial<WalletMetadata>) => WalletConnectorConstructor;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
import { sanitizeName } from '@dynamic-labs/utils';
|
|
3
|
+
import { InjectedWalletBase } from '../injected/InjectedWalletBase.js';
|
|
4
|
+
import { createAptosSignerFromWalletStandard } from './createAptosSignerFromWalletStandard.js';
|
|
5
|
+
|
|
6
|
+
const getConnectorConstructorForWalletStandardWallet = (wallet, walletBookMetadata = {}) => {
|
|
7
|
+
const sanitizedName = sanitizeName(wallet.name);
|
|
8
|
+
return class extends InjectedWalletBase {
|
|
9
|
+
constructor(props) {
|
|
10
|
+
super(wallet.name, Object.assign(Object.assign({}, props), { metadata: Object.assign(Object.assign({}, walletBookMetadata), { groupKey: sanitizedName, icon: wallet.icon, id: sanitizedName, name: wallet.name }) }));
|
|
11
|
+
this.name = wallet.name;
|
|
12
|
+
this.overrideKey = `${sanitizedName}aptos`;
|
|
13
|
+
this._provider = createAptosSignerFromWalletStandard({
|
|
14
|
+
wallet,
|
|
15
|
+
walletConnector: this,
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
findProvider() {
|
|
19
|
+
return this._provider;
|
|
20
|
+
}
|
|
21
|
+
getProvider() {
|
|
22
|
+
return this._provider;
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
export { getConnectorConstructorForWalletStandardWallet };
|