@dynamic-labs/embedded-wallet-solana 0.0.0-exp20240808.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 +3746 -0
- package/LICENSE +21 -0
- package/README.md +11 -0
- package/_virtual/_tslib.cjs +49 -0
- package/_virtual/_tslib.js +44 -0
- package/package.json +47 -0
- package/src/TurnkeySolanaWalletConnectors.cjs +19 -0
- package/src/TurnkeySolanaWalletConnectors.d.ts +2 -0
- package/src/TurnkeySolanaWalletConnectors.js +15 -0
- package/src/index.cjs +10 -0
- package/src/index.d.ts +2 -0
- package/src/index.js +2 -0
- package/src/lib/TurnkeySolanaWalletConnector/TurnkeySolanaSigner.cjs +57 -0
- package/src/lib/TurnkeySolanaWalletConnector/TurnkeySolanaSigner.d.ts +49 -0
- package/src/lib/TurnkeySolanaWalletConnector/TurnkeySolanaSigner.js +53 -0
- package/src/lib/TurnkeySolanaWalletConnector/TurnkeySolanaWalletConnector.cjs +374 -0
- package/src/lib/TurnkeySolanaWalletConnector/TurnkeySolanaWalletConnector.d.ts +58 -0
- package/src/lib/TurnkeySolanaWalletConnector/TurnkeySolanaWalletConnector.js +370 -0
- package/src/lib/TurnkeySolanaWalletConnector/index.d.ts +1 -0
- package/src/lib/constants.cjs +8 -0
- package/src/lib/constants.d.ts +1 -0
- package/src/lib/constants.js +4 -0
- package/src/lib/utils/createSolanaConnection/createSolanaConnection.cjs +14 -0
- package/src/lib/utils/createSolanaConnection/createSolanaConnection.d.ts +2 -0
- package/src/lib/utils/createSolanaConnection/createSolanaConnection.js +10 -0
- package/src/lib/utils/createSolanaConnection/index.d.ts +1 -0
- package/src/lib/utils/getGenesisHashLSKey/getGenesisHashLSKey.cjs +10 -0
- package/src/lib/utils/getGenesisHashLSKey/getGenesisHashLSKey.d.ts +1 -0
- package/src/lib/utils/getGenesisHashLSKey/getGenesisHashLSKey.js +6 -0
- package/src/lib/utils/getGenesisHashLSKey/index.d.ts +1 -0
- package/src/lib/utils/index.d.ts +3 -0
- package/src/lib/utils/transactionDecoder/index.d.ts +1 -0
- package/src/lib/utils/transactionDecoder/transactionDecoder.cjs +151 -0
- package/src/lib/utils/transactionDecoder/transactionDecoder.d.ts +7 -0
- package/src/lib/utils/transactionDecoder/transactionDecoder.js +145 -0
|
@@ -0,0 +1,374 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
5
|
+
|
|
6
|
+
var _tslib = require('../../../_virtual/_tslib.cjs');
|
|
7
|
+
var web3_js = require('@solana/web3.js');
|
|
8
|
+
var webauthnStamper = require('@turnkey/webauthn-stamper');
|
|
9
|
+
var http = require('@turnkey/http');
|
|
10
|
+
var solana = require('@turnkey/solana');
|
|
11
|
+
var iframeStamper = require('@turnkey/iframe-stamper');
|
|
12
|
+
var walletConnectorCore = require('@dynamic-labs/wallet-connector-core');
|
|
13
|
+
var rpcProviderSolana = require('@dynamic-labs/rpc-provider-solana');
|
|
14
|
+
var utils = require('@dynamic-labs/utils');
|
|
15
|
+
var solanaUtils = require('@dynamic-labs/solana-utils');
|
|
16
|
+
var embeddedWallet = require('@dynamic-labs/embedded-wallet');
|
|
17
|
+
var createSolanaConnection = require('../utils/createSolanaConnection/createSolanaConnection.cjs');
|
|
18
|
+
var getGenesisHashLSKey = require('../utils/getGenesisHashLSKey/getGenesisHashLSKey.cjs');
|
|
19
|
+
var transactionDecoder = require('../utils/transactionDecoder/transactionDecoder.cjs');
|
|
20
|
+
var TurnkeySolanaSigner = require('./TurnkeySolanaSigner.cjs');
|
|
21
|
+
|
|
22
|
+
class TurnkeySolanaWalletConnector extends embeddedWallet.TurnkeyWalletConnectorBase {
|
|
23
|
+
constructor(nameAndKey, props) {
|
|
24
|
+
var _a;
|
|
25
|
+
super(nameAndKey, props);
|
|
26
|
+
// Public fields
|
|
27
|
+
this.ChainWallet = walletConnectorCore.Wallet;
|
|
28
|
+
this.connectedChain = 'SOL';
|
|
29
|
+
this.supportedChains = ['SOL'];
|
|
30
|
+
this.verifiedCredentialChain = 'solana';
|
|
31
|
+
this.stampCreateWalletAccountRequest = (_b) => _tslib.__awaiter(this, [_b], void 0, function* ({ request, }) {
|
|
32
|
+
const turnkeyClient = this.getTurnkeyClient();
|
|
33
|
+
return turnkeyClient.stampCreateWalletAccounts(request);
|
|
34
|
+
});
|
|
35
|
+
this.solNetworks = props.solNetworks;
|
|
36
|
+
this.walletUiUtils = props.walletUiUtils;
|
|
37
|
+
this._turnkeyAccount = undefined;
|
|
38
|
+
this._connectionClient = undefined;
|
|
39
|
+
this.chainRpcProviders = props.chainRpcProviders;
|
|
40
|
+
(_a = this.chainRpcProviders) === null || _a === void 0 ? void 0 : _a.registerSolanaProviders();
|
|
41
|
+
this.__turnkeyClient = this.getTurnkeyClient();
|
|
42
|
+
}
|
|
43
|
+
getRpcUrl() {
|
|
44
|
+
var _a;
|
|
45
|
+
const [network] = this.solNetworks;
|
|
46
|
+
if (!network) {
|
|
47
|
+
throw new utils.DynamicError('No enabled networks');
|
|
48
|
+
}
|
|
49
|
+
return ((_a = network.privateCustomerRpcUrls) === null || _a === void 0 ? void 0 : _a[0]) || network.rpcUrls[0];
|
|
50
|
+
}
|
|
51
|
+
getConnection(commitmentOrConfig) {
|
|
52
|
+
if (!this._connectionClient) {
|
|
53
|
+
const rpcUrl = this.getRpcUrl();
|
|
54
|
+
if (!rpcUrl)
|
|
55
|
+
throw new utils.DynamicError('No rpcUrl');
|
|
56
|
+
this._connectionClient = createSolanaConnection.createSolanaConnection(rpcUrl, commitmentOrConfig);
|
|
57
|
+
}
|
|
58
|
+
return this._connectionClient;
|
|
59
|
+
}
|
|
60
|
+
getWalletClient() {
|
|
61
|
+
return this.getConnection();
|
|
62
|
+
}
|
|
63
|
+
getNetwork() {
|
|
64
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
65
|
+
const connection = this.getConnection();
|
|
66
|
+
let genesisHash = localStorage.getItem(getGenesisHashLSKey.getGenesisHashLSKey(connection.rpcEndpoint));
|
|
67
|
+
if (!genesisHash) {
|
|
68
|
+
genesisHash = yield connection.getGenesisHash();
|
|
69
|
+
localStorage.setItem(getGenesisHashLSKey.getGenesisHashLSKey(connection.rpcEndpoint), genesisHash);
|
|
70
|
+
}
|
|
71
|
+
genesisHash = genesisHash.substring(0, 32);
|
|
72
|
+
// see: https://github.com/ChainAgnostic/namespaces/blob/main/solana/caip2.md
|
|
73
|
+
if (genesisHash === '5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp') {
|
|
74
|
+
return 'mainnet';
|
|
75
|
+
}
|
|
76
|
+
else if (genesisHash === 'EtWTRABZaYq6iMfeYKouRu166VU2xqa1') {
|
|
77
|
+
return 'devnet';
|
|
78
|
+
}
|
|
79
|
+
else {
|
|
80
|
+
return 'testnet';
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
getPublicClient() {
|
|
85
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
86
|
+
var _a;
|
|
87
|
+
if (this.solNetworks.length === 0)
|
|
88
|
+
return;
|
|
89
|
+
const configurations = {
|
|
90
|
+
cosmos: [],
|
|
91
|
+
evm: undefined,
|
|
92
|
+
solana: this.solNetworks,
|
|
93
|
+
starknet: undefined,
|
|
94
|
+
};
|
|
95
|
+
if (!this.chainRpcProviders)
|
|
96
|
+
return undefined;
|
|
97
|
+
const providers = this.chainRpcProviders.getProviders(configurations);
|
|
98
|
+
return (_a = this.chainRpcProviders.getSolanaProviderByChainId(providers, '101')) === null || _a === void 0 ? void 0 : _a.provider;
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
supportsNetworkSwitching() {
|
|
102
|
+
return false;
|
|
103
|
+
}
|
|
104
|
+
setVerifiedCredentials(verifiedCredentials) {
|
|
105
|
+
const turnkeyVerifiedCredential = embeddedWallet.findTurnkeyVerifiedCredential(verifiedCredentials, rpcProviderSolana.ProviderChain.SOLANA);
|
|
106
|
+
const didTurnkeyVerifiedCredentialsChanged = JSON.stringify(this.verifiedCredential) !==
|
|
107
|
+
JSON.stringify(turnkeyVerifiedCredential);
|
|
108
|
+
if (!didTurnkeyVerifiedCredentialsChanged) {
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
this.verifiedCredential = turnkeyVerifiedCredential;
|
|
112
|
+
this.refreshTurnkeyAccount();
|
|
113
|
+
}
|
|
114
|
+
getAccount() {
|
|
115
|
+
return this.turnkeyAddress;
|
|
116
|
+
}
|
|
117
|
+
endSession() {
|
|
118
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
119
|
+
localStorage.removeItem(getGenesisHashLSKey.getGenesisHashLSKey(this.getRpcUrl()));
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
refreshTurnkeyAccount() {
|
|
123
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
124
|
+
this._turnkeyAccount = undefined;
|
|
125
|
+
return this.getTurnkeyAccount();
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
getTurnkeyClient() {
|
|
129
|
+
var _a;
|
|
130
|
+
let rpId = utils.getTLD();
|
|
131
|
+
if (!rpId) {
|
|
132
|
+
rpId = utils.PlatformService.getHostname();
|
|
133
|
+
}
|
|
134
|
+
const passkeyStamper = embeddedWallet.PasskeyService.createWebauthnStamper({
|
|
135
|
+
rpId,
|
|
136
|
+
});
|
|
137
|
+
const apiKeyStamper = embeddedWallet.TurnkeyWalletConnectorBase === null || embeddedWallet.TurnkeyWalletConnectorBase === void 0 ? void 0 : embeddedWallet.TurnkeyWalletConnectorBase.apiKeyStamper;
|
|
138
|
+
const stamper = apiKeyStamper !== null && apiKeyStamper !== void 0 ? apiKeyStamper : passkeyStamper;
|
|
139
|
+
this.__turnkeyClient =
|
|
140
|
+
(_a = this.getAuthenticatorHandler().client) !== null && _a !== void 0 ? _a : new http.TurnkeyClient({
|
|
141
|
+
baseUrl: embeddedWallet.TURNKEY_API_BASE_URL,
|
|
142
|
+
}, stamper);
|
|
143
|
+
return this.__turnkeyClient;
|
|
144
|
+
}
|
|
145
|
+
createTurnkeyAccount(_a) {
|
|
146
|
+
return _tslib.__awaiter(this, arguments, void 0, function* ({ organizationId, }) {
|
|
147
|
+
const turnkeyClient = this.getTurnkeyClient();
|
|
148
|
+
const signer = new solana.TurnkeySigner({ client: turnkeyClient, organizationId });
|
|
149
|
+
return signer;
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
getTurnkeyAccount() {
|
|
153
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
154
|
+
var _a, _b, _c, _d;
|
|
155
|
+
if (this._turnkeyAccount &&
|
|
156
|
+
((this.getAuthenticatorHandler().recoveryType === 'passkey' &&
|
|
157
|
+
((_a = this.__turnkeyClient) === null || _a === void 0 ? void 0 : _a.stamper) instanceof webauthnStamper.WebauthnStamper) ||
|
|
158
|
+
(this.getAuthenticatorHandler().recoveryType === 'email' &&
|
|
159
|
+
((_b = this.__turnkeyClient) === null || _b === void 0 ? void 0 : _b.stamper) instanceof iframeStamper.IframeStamper)) &&
|
|
160
|
+
this.__turnkeyClient === this.getAuthenticatorHandler().client) {
|
|
161
|
+
return this._turnkeyAccount;
|
|
162
|
+
}
|
|
163
|
+
const { turnkeySubOrganizationId } = (_c = this.walletProperties) !== null && _c !== void 0 ? _c : {};
|
|
164
|
+
const { address } = (_d = this.verifiedCredential) !== null && _d !== void 0 ? _d : {};
|
|
165
|
+
if (!turnkeySubOrganizationId || !address) {
|
|
166
|
+
return;
|
|
167
|
+
}
|
|
168
|
+
this._turnkeyAccount = yield this.createTurnkeyAccount({
|
|
169
|
+
organizationId: turnkeySubOrganizationId,
|
|
170
|
+
});
|
|
171
|
+
this.setLoggerMetadata();
|
|
172
|
+
return this._turnkeyAccount;
|
|
173
|
+
});
|
|
174
|
+
}
|
|
175
|
+
getSigner() {
|
|
176
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
177
|
+
return new TurnkeySolanaSigner.TurnkeySolanaSigner({ walletConnector: this });
|
|
178
|
+
});
|
|
179
|
+
}
|
|
180
|
+
getBalance(address) {
|
|
181
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
182
|
+
const connectionClient = this.getConnection();
|
|
183
|
+
const publicKey = new web3_js.PublicKey(address);
|
|
184
|
+
const balance = yield connectionClient.getBalance(publicKey);
|
|
185
|
+
const solBalance = this.lamportsToSol(balance);
|
|
186
|
+
return solBalance.toString();
|
|
187
|
+
});
|
|
188
|
+
}
|
|
189
|
+
signUint8ArrayMessage(encodedMessage) {
|
|
190
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
191
|
+
if (!this.turnkeyAddress) {
|
|
192
|
+
throw new utils.DynamicError('No turnkey account');
|
|
193
|
+
}
|
|
194
|
+
const address = this.turnkeyAddress;
|
|
195
|
+
let signedMessageRaw;
|
|
196
|
+
yield this.createOrRestoreSession();
|
|
197
|
+
yield this.walletUiUtils.signMessage({
|
|
198
|
+
handler: () => _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
199
|
+
let account = yield this.getTurnkeyAccount();
|
|
200
|
+
try {
|
|
201
|
+
signedMessageRaw = yield (account === null || account === void 0 ? void 0 : account.signMessage(encodedMessage, address));
|
|
202
|
+
}
|
|
203
|
+
catch (_a) {
|
|
204
|
+
yield this.removeSessionKeys();
|
|
205
|
+
yield this.createOrRestoreSession({
|
|
206
|
+
ignoreRestore: true,
|
|
207
|
+
});
|
|
208
|
+
account = yield this.getTurnkeyAccount();
|
|
209
|
+
signedMessageRaw = yield (account === null || account === void 0 ? void 0 : account.signMessage(encodedMessage, address));
|
|
210
|
+
}
|
|
211
|
+
return utils.bufferToBase64(signedMessageRaw || Buffer.from([]));
|
|
212
|
+
}),
|
|
213
|
+
message: new TextDecoder().decode(encodedMessage),
|
|
214
|
+
});
|
|
215
|
+
if (!signedMessageRaw) {
|
|
216
|
+
throw new Error('Failed to sign message');
|
|
217
|
+
}
|
|
218
|
+
return signedMessageRaw;
|
|
219
|
+
});
|
|
220
|
+
}
|
|
221
|
+
signMessage(messageToSign) {
|
|
222
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
223
|
+
const enc = new TextEncoder();
|
|
224
|
+
const encodedMessage = enc.encode(messageToSign);
|
|
225
|
+
const signedRawMessage = yield this.signUint8ArrayMessage(encodedMessage);
|
|
226
|
+
return utils.bufferToBase64(signedRawMessage);
|
|
227
|
+
});
|
|
228
|
+
}
|
|
229
|
+
signTransaction(transaction) {
|
|
230
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
231
|
+
yield this.createOrRestoreSession();
|
|
232
|
+
let account = yield this.getTurnkeyAccount();
|
|
233
|
+
const address = this.turnkeyAddress;
|
|
234
|
+
if (!account || !address) {
|
|
235
|
+
throw new Error('No turnkey account');
|
|
236
|
+
}
|
|
237
|
+
try {
|
|
238
|
+
yield account.addSignature(transaction, address);
|
|
239
|
+
}
|
|
240
|
+
catch (err) {
|
|
241
|
+
if (embeddedWallet.TURNKEY_SDK_SESSION_KEY_RETRYABLE_ERRORS.some((errorMsg) => err.message.includes(errorMsg))) {
|
|
242
|
+
yield this.removeSessionKeys();
|
|
243
|
+
yield this.createOrRestoreSession({
|
|
244
|
+
ignoreRestore: true,
|
|
245
|
+
});
|
|
246
|
+
account = (yield this.getTurnkeyAccount());
|
|
247
|
+
yield account.addSignature(transaction, address);
|
|
248
|
+
}
|
|
249
|
+
else {
|
|
250
|
+
embeddedWallet.logger.error('[TK] failed to perform SignTransaction activity', err);
|
|
251
|
+
throw err;
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
return transaction;
|
|
255
|
+
});
|
|
256
|
+
}
|
|
257
|
+
internalSignAndSendTransaction(transaction, options) {
|
|
258
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
259
|
+
var _a;
|
|
260
|
+
if (!this.turnkeyAddress)
|
|
261
|
+
throw new utils.DynamicError('Solana wallet not found');
|
|
262
|
+
const currentConnection = this.getConnection('confirmed');
|
|
263
|
+
const blockhash = yield currentConnection.getLatestBlockhash();
|
|
264
|
+
if ('version' in transaction) {
|
|
265
|
+
transaction.message.recentBlockhash =
|
|
266
|
+
blockhash.blockhash;
|
|
267
|
+
}
|
|
268
|
+
else {
|
|
269
|
+
transaction.recentBlockhash = blockhash.blockhash;
|
|
270
|
+
transaction.feePayer =
|
|
271
|
+
(_a = transaction.feePayer) !== null && _a !== void 0 ? _a : new web3_js.PublicKey(this.turnkeyAddress);
|
|
272
|
+
}
|
|
273
|
+
const signedTransaction = yield this.signTransaction(transaction);
|
|
274
|
+
const signature = yield currentConnection.sendRawTransaction(Buffer.from(signedTransaction.serialize()), options);
|
|
275
|
+
// listen for tx confirmation until 60 seconds, which is ~150 blocks expiration
|
|
276
|
+
return new Promise((resolve, reject) => {
|
|
277
|
+
const timeout = setTimeout(() => {
|
|
278
|
+
reject(new utils.DynamicError('Transaction timed out'));
|
|
279
|
+
}, 60000);
|
|
280
|
+
currentConnection.onSignature(signature, (result) => {
|
|
281
|
+
clearTimeout(timeout);
|
|
282
|
+
if (result.err) {
|
|
283
|
+
reject(new utils.DynamicError('Transaction failed'));
|
|
284
|
+
}
|
|
285
|
+
else {
|
|
286
|
+
resolve(signature);
|
|
287
|
+
}
|
|
288
|
+
}, 'confirmed');
|
|
289
|
+
});
|
|
290
|
+
});
|
|
291
|
+
}
|
|
292
|
+
signAndSendTransaction(transaction, options) {
|
|
293
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
294
|
+
if (!this.turnkeyAddress)
|
|
295
|
+
throw new utils.DynamicError('Solana wallet not found');
|
|
296
|
+
const transactionsData = yield transactionDecoder.decodeTransaction(transaction, this.getConnection(), this.turnkeyAddress);
|
|
297
|
+
if (!(transactionsData === null || transactionsData === void 0 ? void 0 : transactionsData.length)) {
|
|
298
|
+
throw new utils.DynamicError('Incorrectly formatted transaction instructions');
|
|
299
|
+
}
|
|
300
|
+
let spent;
|
|
301
|
+
let insufficientFunds = false;
|
|
302
|
+
try {
|
|
303
|
+
spent = yield transactionDecoder.getTotalSolanaSpend(transaction, this.getConnection(), this.turnkeyAddress);
|
|
304
|
+
}
|
|
305
|
+
catch (e) {
|
|
306
|
+
if (e.message === 'Insufficient funds') {
|
|
307
|
+
insufficientFunds = true;
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
const to = transactionDecoder.summarizeTransactionDecodedData(transactionsData);
|
|
311
|
+
const uiTransaction = new solanaUtils.SolanaUiTransaction({
|
|
312
|
+
connection: this.getConnection(),
|
|
313
|
+
from: this.turnkeyAddress,
|
|
314
|
+
onSubmit: () => _tslib.__awaiter(this, void 0, void 0, function* () { return this.internalSignAndSendTransaction(transaction, options); }),
|
|
315
|
+
originalTransaction: transaction,
|
|
316
|
+
});
|
|
317
|
+
uiTransaction.to = to;
|
|
318
|
+
uiTransaction.value = spent;
|
|
319
|
+
if (insufficientFunds) {
|
|
320
|
+
uiTransaction.notEnoughFundsError = true;
|
|
321
|
+
}
|
|
322
|
+
return this.walletUiUtils.sendTransaction(this, uiTransaction);
|
|
323
|
+
});
|
|
324
|
+
}
|
|
325
|
+
sendTransaction(transaction_1, connection_1) {
|
|
326
|
+
return _tslib.__awaiter(this, arguments, void 0, function* (transaction, connection, options = {}) {
|
|
327
|
+
var _a;
|
|
328
|
+
if (!this.turnkeyAddress)
|
|
329
|
+
throw new utils.DynamicError('Solana wallet not found');
|
|
330
|
+
if (!transaction || !connection) {
|
|
331
|
+
throw new utils.DynamicError('Transaction and connection are required');
|
|
332
|
+
}
|
|
333
|
+
const { signers } = options, sendOptions = _tslib.__rest(options, ["signers"]);
|
|
334
|
+
const blockhash = yield connection.getLatestBlockhash({
|
|
335
|
+
commitment: options.preflightCommitment,
|
|
336
|
+
minContextSlot: options.minContextSlot,
|
|
337
|
+
});
|
|
338
|
+
if ('version' in transaction) {
|
|
339
|
+
(signers === null || signers === void 0 ? void 0 : signers.length) && transaction.sign(signers);
|
|
340
|
+
}
|
|
341
|
+
else {
|
|
342
|
+
transaction.feePayer =
|
|
343
|
+
transaction.feePayer || new web3_js.PublicKey(this.turnkeyAddress);
|
|
344
|
+
transaction.recentBlockhash =
|
|
345
|
+
transaction.recentBlockhash || blockhash.blockhash;
|
|
346
|
+
(signers === null || signers === void 0 ? void 0 : signers.length) && transaction.partialSign(...signers);
|
|
347
|
+
}
|
|
348
|
+
sendOptions.preflightCommitment =
|
|
349
|
+
sendOptions.preflightCommitment || connection.commitment;
|
|
350
|
+
const signature = yield connection.sendRawTransaction(transaction.serialize(), options);
|
|
351
|
+
const transactionConfirmationStrategy = {
|
|
352
|
+
blockhash: blockhash.blockhash,
|
|
353
|
+
lastValidBlockHeight: blockhash.lastValidBlockHeight,
|
|
354
|
+
signature,
|
|
355
|
+
};
|
|
356
|
+
const result = yield (connection === null || connection === void 0 ? void 0 : connection.confirmTransaction(transactionConfirmationStrategy));
|
|
357
|
+
return ((_a = result === null || result === void 0 ? void 0 : result.value) === null || _a === void 0 ? void 0 : _a.err) ? JSON.stringify(result.value.err) : signature;
|
|
358
|
+
});
|
|
359
|
+
}
|
|
360
|
+
lamportsToSol(lamports) {
|
|
361
|
+
return lamports / web3_js.LAMPORTS_PER_SOL;
|
|
362
|
+
}
|
|
363
|
+
createUiTransaction(from) {
|
|
364
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
365
|
+
return new solanaUtils.SolanaUiTransaction({
|
|
366
|
+
connection: this.getConnection(),
|
|
367
|
+
from,
|
|
368
|
+
onSubmit: (transaction) => _tslib.__awaiter(this, void 0, void 0, function* () { return this.internalSignAndSendTransaction(transaction); }),
|
|
369
|
+
});
|
|
370
|
+
});
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
exports.TurnkeySolanaWalletConnector = TurnkeySolanaWalletConnector;
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { Commitment, Connection, ConnectionConfig, Transaction, VersionedTransaction, ConfirmOptions, Signer, SendOptions } from '@solana/web3.js';
|
|
2
|
+
import { TurnkeyApiTypes } from '@turnkey/http';
|
|
3
|
+
import { GenericNetwork, IUITransaction, WalletUiUtils } from '@dynamic-labs/types';
|
|
4
|
+
import { Chain, ISendBalanceWalletConnector, Wallet, WalletConnector } from '@dynamic-labs/wallet-connector-core';
|
|
5
|
+
import { WalletBookSchema } from '@dynamic-labs/wallet-book';
|
|
6
|
+
import { JwtVerifiedCredential } from '@dynamic-labs/sdk-api-core';
|
|
7
|
+
import { IChainRpcProviders } from '@dynamic-labs/rpc-provider-solana';
|
|
8
|
+
import { TurnkeyWalletConnectorBase, TurnkeyWalletConnectorNameAndKey } from '@dynamic-labs/embedded-wallet';
|
|
9
|
+
import { TurnkeySolanaSigner } from './TurnkeySolanaSigner';
|
|
10
|
+
type SendTransactionOptions = ConfirmOptions & {
|
|
11
|
+
signers?: Signer[];
|
|
12
|
+
};
|
|
13
|
+
export type TurnkeySolanaConnectorProps = {
|
|
14
|
+
walletUiUtils: WalletUiUtils<WalletConnector>;
|
|
15
|
+
walletBook: WalletBookSchema;
|
|
16
|
+
solNetworks: GenericNetwork[];
|
|
17
|
+
appName?: string;
|
|
18
|
+
chainRpcProviders: IChainRpcProviders;
|
|
19
|
+
};
|
|
20
|
+
export declare class TurnkeySolanaWalletConnector extends TurnkeyWalletConnectorBase implements ISendBalanceWalletConnector {
|
|
21
|
+
ChainWallet: typeof Wallet;
|
|
22
|
+
connectedChain: Chain;
|
|
23
|
+
supportedChains: Chain[];
|
|
24
|
+
solNetworks: GenericNetwork[];
|
|
25
|
+
verifiedCredentialChain: string;
|
|
26
|
+
private walletUiUtils;
|
|
27
|
+
private _turnkeyAccount;
|
|
28
|
+
private _connectionClient;
|
|
29
|
+
private __turnkeyClient;
|
|
30
|
+
constructor(nameAndKey: TurnkeyWalletConnectorNameAndKey, props: TurnkeySolanaConnectorProps);
|
|
31
|
+
getRpcUrl(): string;
|
|
32
|
+
getConnection(commitmentOrConfig?: Commitment | ConnectionConfig): Connection;
|
|
33
|
+
getWalletClient(): Connection;
|
|
34
|
+
getNetwork(): Promise<string>;
|
|
35
|
+
getPublicClient(): Promise<Connection | undefined>;
|
|
36
|
+
supportsNetworkSwitching(): boolean;
|
|
37
|
+
setVerifiedCredentials(verifiedCredentials: JwtVerifiedCredential[]): void;
|
|
38
|
+
getAccount(): string | undefined;
|
|
39
|
+
endSession(): Promise<void>;
|
|
40
|
+
private refreshTurnkeyAccount;
|
|
41
|
+
private getTurnkeyClient;
|
|
42
|
+
private createTurnkeyAccount;
|
|
43
|
+
private getTurnkeyAccount;
|
|
44
|
+
getSigner(): Promise<TurnkeySolanaSigner | undefined>;
|
|
45
|
+
getBalance(address: string): Promise<string | undefined>;
|
|
46
|
+
signUint8ArrayMessage(encodedMessage: Uint8Array): Promise<Uint8Array>;
|
|
47
|
+
signMessage(messageToSign: string): Promise<string | undefined>;
|
|
48
|
+
signTransaction<T extends Transaction | VersionedTransaction>(transaction: T): Promise<T>;
|
|
49
|
+
internalSignAndSendTransaction<T extends Transaction | VersionedTransaction>(transaction: T, options?: SendOptions): Promise<string>;
|
|
50
|
+
signAndSendTransaction<T extends Transaction | VersionedTransaction>(transaction: T, options?: SendOptions): Promise<string>;
|
|
51
|
+
sendTransaction<T extends Transaction | VersionedTransaction>(transaction: T, connection: Connection, options?: SendTransactionOptions): Promise<string>;
|
|
52
|
+
private lamportsToSol;
|
|
53
|
+
createUiTransaction(from: string): Promise<IUITransaction>;
|
|
54
|
+
stampCreateWalletAccountRequest: ({ request, }: {
|
|
55
|
+
request: TurnkeyApiTypes['v1CreateWalletAccountsRequest'];
|
|
56
|
+
}) => Promise<import("@turnkey/http").TSignedRequest>;
|
|
57
|
+
}
|
|
58
|
+
export {};
|