@dynamic-labs/wallet-connector-core 3.0.0-alpha.4 → 3.0.0-alpha.41
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 +373 -0
- package/_virtual/_tslib.cjs +21 -0
- package/_virtual/_tslib.js +20 -1
- package/package.json +7 -7
- package/src/index.cjs +4 -0
- package/src/index.js +2 -0
- package/src/lib/IAccountAbstractionWalletConnector.d.ts +6 -2
- package/src/lib/ISessionKeyCompatibleWalletConnector.d.ts +6 -2
- package/src/lib/ITurnkeyWalletConnectorStamper.d.ts +18 -0
- package/src/lib/WalletConnector.cjs +75 -15
- package/src/lib/WalletConnector.d.ts +33 -24
- package/src/lib/WalletConnector.js +75 -15
- package/src/lib/index.d.ts +2 -0
- package/src/lib/wallets/Wallet/Wallet.cjs +160 -0
- package/src/lib/wallets/Wallet/Wallet.d.ts +87 -0
- package/src/lib/wallets/Wallet/Wallet.js +156 -0
- package/src/lib/wallets/Wallet/index.d.ts +1 -0
- package/src/lib/wallets/index.d.ts +1 -0
- package/src/utils/getMobileExperience/getMobileExperience.cjs +24 -0
- package/src/utils/getMobileExperience/getMobileExperience.d.ts +7 -0
- package/src/utils/getMobileExperience/getMobileExperience.js +20 -0
- package/src/utils/getMobileExperience/index.d.ts +1 -0
- package/src/utils/index.d.ts +1 -0
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
import { __rest, __classPrivateFieldSet, __classPrivateFieldGet, __awaiter } from '../../../../_virtual/_tslib.js';
|
|
3
|
+
import { BaseWallet } from '@dynamic-labs/types';
|
|
4
|
+
import { logger } from '../../../utils/logger.js';
|
|
5
|
+
import '@dynamic-labs/utils';
|
|
6
|
+
import '@dynamic-labs/wallet-book';
|
|
7
|
+
|
|
8
|
+
var _Wallet_connector;
|
|
9
|
+
class Wallet extends BaseWallet {
|
|
10
|
+
constructor(_a) {
|
|
11
|
+
var { connector } = _a, props = __rest(_a, ["connector"]);
|
|
12
|
+
super(props);
|
|
13
|
+
_Wallet_connector.set(this, void 0);
|
|
14
|
+
__classPrivateFieldSet(this, _Wallet_connector, connector, "f");
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Gets the wallet connector.
|
|
18
|
+
*/
|
|
19
|
+
get connector() {
|
|
20
|
+
return __classPrivateFieldGet(this, _Wallet_connector, "f");
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Retrieves the balance of the wallet.
|
|
24
|
+
* @returns A promise that resolves to the balance of the wallet as a string,
|
|
25
|
+
* or undefined if the balance cannot be retrieved.
|
|
26
|
+
*/
|
|
27
|
+
getBalance() {
|
|
28
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
29
|
+
return __classPrivateFieldGet(this, _Wallet_connector, "f").getBalance(this.address);
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Retrieves the name service data associated with the wallet.
|
|
34
|
+
* @returns A promise that resolves to the name service data of the wallet,
|
|
35
|
+
* or undefined if the data cannot be retrieved.
|
|
36
|
+
*/
|
|
37
|
+
getNameService() {
|
|
38
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
39
|
+
return __classPrivateFieldGet(this, _Wallet_connector, "f").getNameService(this.address);
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Retrieves the network that the wallet is connected to.
|
|
44
|
+
* @returns A promise that resolves to the network value as a string or number,
|
|
45
|
+
* or undefined if the network cannot be retrieved.
|
|
46
|
+
*/
|
|
47
|
+
getNetwork() {
|
|
48
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
49
|
+
return __classPrivateFieldGet(this, _Wallet_connector, "f").getNetwork();
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Retrieves the rpc provider for the wallet.
|
|
54
|
+
* @returns A promise that resolves to the provider,
|
|
55
|
+
* or undefined if the provider cannot be retrieved.
|
|
56
|
+
*/
|
|
57
|
+
getPublicClient() {
|
|
58
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
59
|
+
return __classPrivateFieldGet(this, _Wallet_connector, "f").getPublicClient();
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Retrieves the signer for the wallet.
|
|
64
|
+
* @returns A promise that resolves to the signer,
|
|
65
|
+
* or undefined if the signer cannot be retrieved.
|
|
66
|
+
*/
|
|
67
|
+
getSigner() {
|
|
68
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
69
|
+
yield this.sync();
|
|
70
|
+
return __classPrivateFieldGet(this, _Wallet_connector, "f").getSigner();
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Retrieves the wallet client.
|
|
75
|
+
* @param chainId - (optional) Chain id to be used by the wallet client.
|
|
76
|
+
* @returns A promise that resolves to the wallet client,
|
|
77
|
+
* or undefined if the wallet client cannot be retrieved.
|
|
78
|
+
*/
|
|
79
|
+
getWalletClient(chainId) {
|
|
80
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
81
|
+
yield this.sync();
|
|
82
|
+
return __classPrivateFieldGet(this, _Wallet_connector, "f").getWalletClient(chainId);
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* If the wallet is availble to use. A wallet is available if its provider is available.
|
|
87
|
+
* @returns True if the wallet is available, false otherwise.
|
|
88
|
+
*/
|
|
89
|
+
isAvailable() {
|
|
90
|
+
return __classPrivateFieldGet(this, _Wallet_connector, "f").isAvailable;
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* If the wallet is connected.
|
|
94
|
+
* @returns A promise that resolves to true the wallet is connected or false if it's not connected.
|
|
95
|
+
*/
|
|
96
|
+
isConnected() {
|
|
97
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
98
|
+
try {
|
|
99
|
+
const connectedAccounts = yield __classPrivateFieldGet(this, _Wallet_connector, "f").getConnectedAccounts();
|
|
100
|
+
return connectedAccounts.includes(this.address);
|
|
101
|
+
}
|
|
102
|
+
catch (error) {
|
|
103
|
+
logger.error('[Wallet] isConnected - Error detecting if wallet is connected', error);
|
|
104
|
+
return false;
|
|
105
|
+
}
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Proves ownership of the wallet by signing a message.
|
|
110
|
+
* @param messageToSign - The message to sign.
|
|
111
|
+
* @returns A promise that resolves to the signature of the message as a string,
|
|
112
|
+
* or undefined if the message cannot be signed.
|
|
113
|
+
*/
|
|
114
|
+
proveOwnership(messageToSign) {
|
|
115
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
116
|
+
yield this.sync();
|
|
117
|
+
return __classPrivateFieldGet(this, _Wallet_connector, "f").proveOwnership(messageToSign);
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Signs a message using the wallet.
|
|
122
|
+
* @param messageToSign - The message to sign.
|
|
123
|
+
* @returns A promise that resolves to the signature of the message as a string,
|
|
124
|
+
* or undefined if the message cannot be signed.
|
|
125
|
+
*/
|
|
126
|
+
signMessage(messageToSign) {
|
|
127
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
128
|
+
yield this.sync();
|
|
129
|
+
return __classPrivateFieldGet(this, _Wallet_connector, "f").signMessage(messageToSign);
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Switches the network that the wallet is connected to.
|
|
134
|
+
* @param networkChainId - The chain id of the network to switch to.
|
|
135
|
+
* @returns A promise that resolves when the network is switched.
|
|
136
|
+
*/
|
|
137
|
+
switchNetwork(networkChainId) {
|
|
138
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
139
|
+
return __classPrivateFieldGet(this, _Wallet_connector, "f").switchNetwork({
|
|
140
|
+
networkChainId,
|
|
141
|
+
});
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* Synchronizes the wallet with the connector.
|
|
146
|
+
* @returns A promise that resolves when the wallet is connected and active.
|
|
147
|
+
*/
|
|
148
|
+
sync() {
|
|
149
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
150
|
+
return __classPrivateFieldGet(this, _Wallet_connector, "f").validateActiveWallet(this.address);
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
_Wallet_connector = new WeakMap();
|
|
155
|
+
|
|
156
|
+
export { Wallet };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './Wallet';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './Wallet';
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
5
|
+
|
|
6
|
+
var walletBook = require('@dynamic-labs/wallet-book');
|
|
7
|
+
|
|
8
|
+
const getMobileExperience = ({ mobileExperienceProp, walletBook: walletBook$1, walletKey, }) => {
|
|
9
|
+
// if the legacy prop is set, use that
|
|
10
|
+
if (mobileExperienceProp && typeof mobileExperienceProp === 'string')
|
|
11
|
+
return mobileExperienceProp;
|
|
12
|
+
// if the wallet has a deeplink preference set from the DynamicContext, use that
|
|
13
|
+
if (mobileExperienceProp === null || mobileExperienceProp === void 0 ? void 0 : mobileExperienceProp[walletKey])
|
|
14
|
+
return mobileExperienceProp[walletKey];
|
|
15
|
+
// if the wallet has a deeplink preference set in the wallet book, use that
|
|
16
|
+
const walletRecord = walletBook.findWalletBookWallet(walletBook$1, walletKey);
|
|
17
|
+
if (walletRecord === null || walletRecord === void 0 ? void 0 : walletRecord.mobileExperience)
|
|
18
|
+
return walletRecord.mobileExperience;
|
|
19
|
+
if (mobileExperienceProp === null || mobileExperienceProp === void 0 ? void 0 : mobileExperienceProp.default)
|
|
20
|
+
return mobileExperienceProp.default;
|
|
21
|
+
return 'in-app-browser';
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
exports.getMobileExperience = getMobileExperience;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { MobileExperience } from '@dynamic-labs/types';
|
|
2
|
+
import { WalletBookSchema } from '@dynamic-labs/wallet-book';
|
|
3
|
+
export declare const getMobileExperience: ({ mobileExperienceProp, walletBook, walletKey, }: {
|
|
4
|
+
mobileExperienceProp?: MobileExperience;
|
|
5
|
+
walletBook: WalletBookSchema;
|
|
6
|
+
walletKey: string;
|
|
7
|
+
}) => MobileExperience;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
import { findWalletBookWallet } from '@dynamic-labs/wallet-book';
|
|
3
|
+
|
|
4
|
+
const getMobileExperience = ({ mobileExperienceProp, walletBook, walletKey, }) => {
|
|
5
|
+
// if the legacy prop is set, use that
|
|
6
|
+
if (mobileExperienceProp && typeof mobileExperienceProp === 'string')
|
|
7
|
+
return mobileExperienceProp;
|
|
8
|
+
// if the wallet has a deeplink preference set from the DynamicContext, use that
|
|
9
|
+
if (mobileExperienceProp === null || mobileExperienceProp === void 0 ? void 0 : mobileExperienceProp[walletKey])
|
|
10
|
+
return mobileExperienceProp[walletKey];
|
|
11
|
+
// if the wallet has a deeplink preference set in the wallet book, use that
|
|
12
|
+
const walletRecord = findWalletBookWallet(walletBook, walletKey);
|
|
13
|
+
if (walletRecord === null || walletRecord === void 0 ? void 0 : walletRecord.mobileExperience)
|
|
14
|
+
return walletRecord.mobileExperience;
|
|
15
|
+
if (mobileExperienceProp === null || mobileExperienceProp === void 0 ? void 0 : mobileExperienceProp.default)
|
|
16
|
+
return mobileExperienceProp.default;
|
|
17
|
+
return 'in-app-browser';
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
export { getMobileExperience };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './getMobileExperience';
|
package/src/utils/index.d.ts
CHANGED