@dynamic-labs/embedded-wallet-solana 3.0.0-alpha.9 → 3.0.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 +628 -0
- package/package.cjs +22 -0
- package/package.js +17 -0
- package/package.json +15 -12
- package/src/lib/TurnkeySolanaWalletConnector/TurnkeySolanaSigner.cjs +4 -7
- package/src/lib/TurnkeySolanaWalletConnector/TurnkeySolanaSigner.d.ts +6 -5
- package/src/lib/TurnkeySolanaWalletConnector/TurnkeySolanaSigner.js +4 -7
- package/src/lib/TurnkeySolanaWalletConnector/TurnkeySolanaWalletConnector.cjs +138 -39
- package/src/lib/TurnkeySolanaWalletConnector/TurnkeySolanaWalletConnector.d.ts +16 -11
- package/src/lib/TurnkeySolanaWalletConnector/TurnkeySolanaWalletConnector.js +136 -37
- package/src/lib/utils/api/api.cjs +38 -0
- package/src/lib/utils/api/api.d.ts +4 -0
- package/src/lib/utils/api/api.js +32 -0
- package/src/lib/utils/api/events/DynamicEvents.d.ts +6 -0
- package/src/lib/utils/api/events/auth.d.ts +49 -0
- package/src/lib/utils/api/utils/ApiEndpoint.cjs +41 -0
- package/src/lib/utils/api/utils/ApiEndpoint.d.ts +7 -0
- package/src/lib/utils/api/utils/ApiEndpoint.js +39 -0
- package/src/lib/utils/api/utils/SdkApi.cjs +35 -0
- package/src/lib/utils/api/utils/SdkApi.d.ts +2 -0
- package/src/lib/utils/api/utils/SdkApi.js +31 -0
- package/src/lib/utils/api/utils/helpers.cjs +92 -0
- package/src/lib/utils/api/utils/helpers.d.ts +12 -0
- package/src/lib/utils/api/utils/helpers.js +81 -0
- package/src/lib/utils/api/utils/version.cjs +12 -0
- package/src/lib/utils/api/utils/version.d.ts +2 -0
- package/src/lib/utils/api/utils/version.js +7 -0
- package/src/lib/utils/index.d.ts +1 -2
- package/src/lib/utils/transactionDecoder/index.d.ts +1 -1
- package/src/lib/utils/transactionDecoder/transactionDecoder.cjs +127 -71
- package/src/lib/utils/transactionDecoder/transactionDecoder.d.ts +8 -6
- package/src/lib/utils/transactionDecoder/transactionDecoder.js +127 -72
- package/src/lib/constants.cjs +0 -8
- package/src/lib/constants.d.ts +0 -1
- package/src/lib/constants.js +0 -4
- package/src/lib/utils/getGenesisHashLSKey/getGenesisHashLSKey.cjs +0 -10
- package/src/lib/utils/getGenesisHashLSKey/getGenesisHashLSKey.d.ts +0 -1
- package/src/lib/utils/getGenesisHashLSKey/getGenesisHashLSKey.js +0 -6
- package/src/lib/utils/getGenesisHashLSKey/index.d.ts +0 -1
package/package.cjs
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
5
|
+
|
|
6
|
+
var version = "3.0.1";
|
|
7
|
+
var dependencies = {
|
|
8
|
+
"@dynamic-labs/sdk-api-core": "0.0.529",
|
|
9
|
+
"@dynamic-labs/utils": "3.0.1",
|
|
10
|
+
"@dynamic-labs/logger": "3.0.1",
|
|
11
|
+
"@dynamic-labs/types": "3.0.1",
|
|
12
|
+
eventemitter3: "5.0.1",
|
|
13
|
+
"@solana/spl-token": "0.4.6",
|
|
14
|
+
"@solana/web3.js": "1.92.1",
|
|
15
|
+
"@turnkey/http": "2.12.2",
|
|
16
|
+
"@turnkey/iframe-stamper": "2.0.0",
|
|
17
|
+
"@turnkey/solana": "0.3.9",
|
|
18
|
+
"@turnkey/webauthn-stamper": "0.5.0"
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
exports.dependencies = dependencies;
|
|
22
|
+
exports.version = version;
|
package/package.js
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
var version = "3.0.1";
|
|
3
|
+
var dependencies = {
|
|
4
|
+
"@dynamic-labs/sdk-api-core": "0.0.529",
|
|
5
|
+
"@dynamic-labs/utils": "3.0.1",
|
|
6
|
+
"@dynamic-labs/logger": "3.0.1",
|
|
7
|
+
"@dynamic-labs/types": "3.0.1",
|
|
8
|
+
eventemitter3: "5.0.1",
|
|
9
|
+
"@solana/spl-token": "0.4.6",
|
|
10
|
+
"@solana/web3.js": "1.92.1",
|
|
11
|
+
"@turnkey/http": "2.12.2",
|
|
12
|
+
"@turnkey/iframe-stamper": "2.0.0",
|
|
13
|
+
"@turnkey/solana": "0.3.9",
|
|
14
|
+
"@turnkey/webauthn-stamper": "0.5.0"
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
export { dependencies, version };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dynamic-labs/embedded-wallet-solana",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.1",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "git+https://github.com/dynamic-labs/dynamic-auth.git",
|
|
@@ -26,21 +26,24 @@
|
|
|
26
26
|
"./package.json": "./package.json"
|
|
27
27
|
},
|
|
28
28
|
"dependencies": {
|
|
29
|
-
"@dynamic-labs/sdk-api-core": "0.0.
|
|
29
|
+
"@dynamic-labs/sdk-api-core": "0.0.529",
|
|
30
|
+
"@dynamic-labs/utils": "3.0.1",
|
|
31
|
+
"@dynamic-labs/logger": "3.0.1",
|
|
32
|
+
"@dynamic-labs/types": "3.0.1",
|
|
33
|
+
"eventemitter3": "5.0.1",
|
|
30
34
|
"@solana/spl-token": "0.4.6",
|
|
31
35
|
"@solana/web3.js": "1.92.1",
|
|
32
|
-
"@turnkey/http": "2.
|
|
36
|
+
"@turnkey/http": "2.12.2",
|
|
33
37
|
"@turnkey/iframe-stamper": "2.0.0",
|
|
34
|
-
"@turnkey/solana": "0.3.
|
|
38
|
+
"@turnkey/solana": "0.3.9",
|
|
35
39
|
"@turnkey/webauthn-stamper": "0.5.0",
|
|
36
|
-
"@dynamic-labs/embedded-wallet": "3.0.
|
|
37
|
-
"@dynamic-labs/rpc-
|
|
38
|
-
"@dynamic-labs/
|
|
39
|
-
"@dynamic-labs/
|
|
40
|
-
"@dynamic-labs/
|
|
41
|
-
"@dynamic-labs/
|
|
42
|
-
"
|
|
43
|
-
"@dynamic-labs/wallet-connector-core": "3.0.0-alpha.9",
|
|
40
|
+
"@dynamic-labs/embedded-wallet": "3.0.1",
|
|
41
|
+
"@dynamic-labs/rpc-providers": "3.0.1",
|
|
42
|
+
"@dynamic-labs/solana-core": "3.0.1",
|
|
43
|
+
"@dynamic-labs/wallet-book": "3.0.1",
|
|
44
|
+
"@dynamic-labs/wallet-connector-core": "3.0.1",
|
|
45
|
+
"@dynamic-labs/webauthn": "3.0.1",
|
|
46
|
+
"react-dom": "18.2.0",
|
|
44
47
|
"viem": "2.9.25"
|
|
45
48
|
},
|
|
46
49
|
"peerDependencies": {}
|
|
@@ -16,18 +16,15 @@ class TurnkeySolanaSigner {
|
|
|
16
16
|
? new web3_js.PublicKey(this.turnkeyAddress)
|
|
17
17
|
: undefined;
|
|
18
18
|
}
|
|
19
|
-
signMessage(
|
|
19
|
+
signMessage(encodedMessage) {
|
|
20
20
|
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
21
|
-
const signedMessage = yield this.walletConnector.
|
|
22
|
-
|
|
23
|
-
throw new Error('Failed to sign message');
|
|
24
|
-
}
|
|
25
|
-
return signedMessage;
|
|
21
|
+
const signedMessage = yield this.walletConnector.signUint8ArrayMessage(encodedMessage);
|
|
22
|
+
return { signature: signedMessage };
|
|
26
23
|
});
|
|
27
24
|
}
|
|
28
25
|
signTransaction(transaction) {
|
|
29
26
|
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
30
|
-
return this.walletConnector.signTransaction(
|
|
27
|
+
return this.walletConnector.signTransaction(transaction);
|
|
31
28
|
});
|
|
32
29
|
}
|
|
33
30
|
signAllTransactions(
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { PublicKey, SendOptions, Transaction, TransactionSignature, VersionedTransaction } from '@solana/web3.js';
|
|
2
|
+
import { SignedMessage } from '@dynamic-labs/solana-core';
|
|
2
3
|
import { TurnkeySolanaWalletConnector } from './TurnkeySolanaWalletConnector';
|
|
3
4
|
export type IEmbeddedWalletSolanaSigner = {
|
|
4
5
|
publicKey?: {
|
|
@@ -11,7 +12,7 @@ export type IEmbeddedWalletSolanaSigner = {
|
|
|
11
12
|
signAndSendTransaction<T extends Transaction | VersionedTransaction>(transaction: T, options?: SendOptions): Promise<{
|
|
12
13
|
signature: TransactionSignature;
|
|
13
14
|
}>;
|
|
14
|
-
signMessage(message:
|
|
15
|
+
signMessage(message: Uint8Array, encoding?: string): Promise<SignedMessage>;
|
|
15
16
|
connect: (args?: {
|
|
16
17
|
onlyIfTrusted: boolean;
|
|
17
18
|
}) => Promise<{
|
|
@@ -29,10 +30,10 @@ export declare class TurnkeySolanaSigner implements IEmbeddedWalletSolanaSigner
|
|
|
29
30
|
constructor({ walletConnector, }: {
|
|
30
31
|
walletConnector: TurnkeySolanaWalletConnector;
|
|
31
32
|
});
|
|
32
|
-
signMessage(
|
|
33
|
-
signTransaction
|
|
34
|
-
signAllTransactions
|
|
35
|
-
signAndSendTransaction
|
|
33
|
+
signMessage(encodedMessage: Uint8Array): Promise<SignedMessage>;
|
|
34
|
+
signTransaction<T extends Transaction | VersionedTransaction>(transaction: T): Promise<T>;
|
|
35
|
+
signAllTransactions<T extends Transaction | VersionedTransaction>(_transactions: T[]): Promise<T[]>;
|
|
36
|
+
signAndSendTransaction<T extends Transaction | VersionedTransaction>(transaction: T, options?: SendOptions): Promise<{
|
|
36
37
|
signature: TransactionSignature;
|
|
37
38
|
}>;
|
|
38
39
|
connect(_args?: {
|
|
@@ -12,18 +12,15 @@ class TurnkeySolanaSigner {
|
|
|
12
12
|
? new PublicKey(this.turnkeyAddress)
|
|
13
13
|
: undefined;
|
|
14
14
|
}
|
|
15
|
-
signMessage(
|
|
15
|
+
signMessage(encodedMessage) {
|
|
16
16
|
return __awaiter(this, void 0, void 0, function* () {
|
|
17
|
-
const signedMessage = yield this.walletConnector.
|
|
18
|
-
|
|
19
|
-
throw new Error('Failed to sign message');
|
|
20
|
-
}
|
|
21
|
-
return signedMessage;
|
|
17
|
+
const signedMessage = yield this.walletConnector.signUint8ArrayMessage(encodedMessage);
|
|
18
|
+
return { signature: signedMessage };
|
|
22
19
|
});
|
|
23
20
|
}
|
|
24
21
|
signTransaction(transaction) {
|
|
25
22
|
return __awaiter(this, void 0, void 0, function* () {
|
|
26
|
-
return this.walletConnector.signTransaction(
|
|
23
|
+
return this.walletConnector.signTransaction(transaction);
|
|
27
24
|
});
|
|
28
25
|
}
|
|
29
26
|
signAllTransactions(
|
|
@@ -9,13 +9,13 @@ var webauthnStamper = require('@turnkey/webauthn-stamper');
|
|
|
9
9
|
var http = require('@turnkey/http');
|
|
10
10
|
var solana = require('@turnkey/solana');
|
|
11
11
|
var iframeStamper = require('@turnkey/iframe-stamper');
|
|
12
|
-
var
|
|
12
|
+
var walletConnectorCore = require('@dynamic-labs/wallet-connector-core');
|
|
13
13
|
var utils = require('@dynamic-labs/utils');
|
|
14
|
-
var
|
|
14
|
+
var solanaCore = require('@dynamic-labs/solana-core');
|
|
15
15
|
var embeddedWallet = require('@dynamic-labs/embedded-wallet');
|
|
16
16
|
var createSolanaConnection = require('../utils/createSolanaConnection/createSolanaConnection.cjs');
|
|
17
|
-
var getGenesisHashLSKey = require('../utils/getGenesisHashLSKey/getGenesisHashLSKey.cjs');
|
|
18
17
|
var transactionDecoder = require('../utils/transactionDecoder/transactionDecoder.cjs');
|
|
18
|
+
var api = require('../utils/api/api.cjs');
|
|
19
19
|
var TurnkeySolanaSigner = require('./TurnkeySolanaSigner.cjs');
|
|
20
20
|
|
|
21
21
|
class TurnkeySolanaWalletConnector extends embeddedWallet.TurnkeyWalletConnectorBase {
|
|
@@ -23,9 +23,32 @@ class TurnkeySolanaWalletConnector extends embeddedWallet.TurnkeyWalletConnector
|
|
|
23
23
|
var _a;
|
|
24
24
|
super(nameAndKey, props);
|
|
25
25
|
// Public fields
|
|
26
|
+
this.ChainWallet = solanaCore.SolanaWallet;
|
|
26
27
|
this.connectedChain = 'SOL';
|
|
27
28
|
this.supportedChains = ['SOL'];
|
|
28
29
|
this.verifiedCredentialChain = 'solana';
|
|
30
|
+
this.getEnvId = () => {
|
|
31
|
+
const dynamicNonce = localStorage.getItem('dynamic_nonce');
|
|
32
|
+
if (dynamicNonce) {
|
|
33
|
+
const parsed = JSON.parse(dynamicNonce);
|
|
34
|
+
if (parsed && parsed.environmentId) {
|
|
35
|
+
return parsed.environmentId;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
const dynamicNonceDemo = localStorage.getItem('dynamic_nonce_demo');
|
|
39
|
+
if (dynamicNonceDemo) {
|
|
40
|
+
const parsed = JSON.parse(dynamicNonceDemo);
|
|
41
|
+
if (parsed && parsed.environmentId) {
|
|
42
|
+
return parsed.environmentId;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
throw new Error('Failed to get environment id');
|
|
46
|
+
};
|
|
47
|
+
this.stampCreateWalletAccountRequest = (_b) => _tslib.__awaiter(this, [_b], void 0, function* ({ request, }) {
|
|
48
|
+
yield this.createOrRestoreSession();
|
|
49
|
+
const turnkeyClient = this.getTurnkeyClient();
|
|
50
|
+
return turnkeyClient.stampCreateWalletAccounts(request);
|
|
51
|
+
});
|
|
29
52
|
this.solNetworks = props.solNetworks;
|
|
30
53
|
this.walletUiUtils = props.walletUiUtils;
|
|
31
54
|
this._turnkeyAccount = undefined;
|
|
@@ -57,10 +80,10 @@ class TurnkeySolanaWalletConnector extends embeddedWallet.TurnkeyWalletConnector
|
|
|
57
80
|
getNetwork() {
|
|
58
81
|
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
59
82
|
const connection = this.getConnection();
|
|
60
|
-
let genesisHash = localStorage.getItem(
|
|
83
|
+
let genesisHash = localStorage.getItem(solanaCore.getGenesisHashLSKey(connection.rpcEndpoint));
|
|
61
84
|
if (!genesisHash) {
|
|
62
85
|
genesisHash = yield connection.getGenesisHash();
|
|
63
|
-
localStorage.setItem(
|
|
86
|
+
localStorage.setItem(solanaCore.getGenesisHashLSKey(connection.rpcEndpoint), genesisHash);
|
|
64
87
|
}
|
|
65
88
|
genesisHash = genesisHash.substring(0, 32);
|
|
66
89
|
// see: https://github.com/ChainAgnostic/namespaces/blob/main/solana/caip2.md
|
|
@@ -96,21 +119,38 @@ class TurnkeySolanaWalletConnector extends embeddedWallet.TurnkeyWalletConnector
|
|
|
96
119
|
return false;
|
|
97
120
|
}
|
|
98
121
|
setVerifiedCredentials(verifiedCredentials) {
|
|
99
|
-
const
|
|
100
|
-
const
|
|
101
|
-
|
|
122
|
+
const turnkeyVerifiedCredentials = embeddedWallet.findTurnkeyVerifiedCredentials(verifiedCredentials, solanaCore.ProviderChain.SOLANA);
|
|
123
|
+
const [turnkeyVerifiedCredential] = turnkeyVerifiedCredentials;
|
|
124
|
+
const didTurnkeyVerifiedCredentialsChanged = JSON.stringify(this.verifiedCredentials) !==
|
|
125
|
+
JSON.stringify(turnkeyVerifiedCredentials);
|
|
102
126
|
if (!didTurnkeyVerifiedCredentialsChanged) {
|
|
103
127
|
return;
|
|
104
128
|
}
|
|
105
129
|
this.verifiedCredential = turnkeyVerifiedCredential;
|
|
130
|
+
this.verifiedCredentials = turnkeyVerifiedCredentials;
|
|
106
131
|
this.refreshTurnkeyAccount();
|
|
107
132
|
}
|
|
133
|
+
validateActiveWallet(expectedAddress) {
|
|
134
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
135
|
+
var _a, _b;
|
|
136
|
+
const activeAddress = ((_a = this.verifiedCredential) === null || _a === void 0 ? void 0 : _a.address) || '';
|
|
137
|
+
const isWalletActive = walletConnectorCore.isSameAddress(activeAddress, expectedAddress, this.connectedChain);
|
|
138
|
+
if (!isWalletActive) {
|
|
139
|
+
const targetActiveAccount = (_b = this.verifiedCredentials) === null || _b === void 0 ? void 0 : _b.find((vc) => (vc === null || vc === void 0 ? void 0 : vc.address) === expectedAddress);
|
|
140
|
+
if (!targetActiveAccount) {
|
|
141
|
+
throw new utils.DynamicError('Account not found');
|
|
142
|
+
}
|
|
143
|
+
this.verifiedCredential = targetActiveAccount;
|
|
144
|
+
this.refreshTurnkeyAccount();
|
|
145
|
+
}
|
|
146
|
+
});
|
|
147
|
+
}
|
|
108
148
|
getAccount() {
|
|
109
149
|
return this.turnkeyAddress;
|
|
110
150
|
}
|
|
111
151
|
endSession() {
|
|
112
152
|
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
113
|
-
localStorage.removeItem(
|
|
153
|
+
localStorage.removeItem(solanaCore.getGenesisHashLSKey(this.getRpcUrl()));
|
|
114
154
|
});
|
|
115
155
|
}
|
|
116
156
|
refreshTurnkeyAccount() {
|
|
@@ -162,23 +202,17 @@ class TurnkeySolanaWalletConnector extends embeddedWallet.TurnkeyWalletConnector
|
|
|
162
202
|
this._turnkeyAccount = yield this.createTurnkeyAccount({
|
|
163
203
|
organizationId: turnkeySubOrganizationId,
|
|
164
204
|
});
|
|
205
|
+
this.setLoggerMetadata();
|
|
165
206
|
return this._turnkeyAccount;
|
|
166
207
|
});
|
|
167
208
|
}
|
|
168
209
|
getSigner() {
|
|
169
210
|
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
170
|
-
if (this.isSessionKeyCompatible()) {
|
|
171
|
-
yield this.createOrRestoreSession();
|
|
172
|
-
}
|
|
173
211
|
return new TurnkeySolanaSigner.TurnkeySolanaSigner({ walletConnector: this });
|
|
174
212
|
});
|
|
175
213
|
}
|
|
176
|
-
getBalance() {
|
|
214
|
+
getBalance(address) {
|
|
177
215
|
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
178
|
-
const address = this.getAccount();
|
|
179
|
-
if (!address) {
|
|
180
|
-
return undefined;
|
|
181
|
-
}
|
|
182
216
|
const connectionClient = this.getConnection();
|
|
183
217
|
const publicKey = new web3_js.PublicKey(address);
|
|
184
218
|
const balance = yield connectionClient.getBalance(publicKey);
|
|
@@ -186,34 +220,72 @@ class TurnkeySolanaWalletConnector extends embeddedWallet.TurnkeyWalletConnector
|
|
|
186
220
|
return solBalance.toString();
|
|
187
221
|
});
|
|
188
222
|
}
|
|
189
|
-
|
|
223
|
+
signUint8ArrayMessage(encodedMessage) {
|
|
190
224
|
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
191
225
|
if (!this.turnkeyAddress) {
|
|
192
226
|
throw new utils.DynamicError('No turnkey account');
|
|
193
227
|
}
|
|
194
228
|
const address = this.turnkeyAddress;
|
|
195
|
-
|
|
229
|
+
let signedMessageRaw;
|
|
230
|
+
yield this.createOrRestoreSession();
|
|
231
|
+
yield this.walletUiUtils.signMessage({
|
|
196
232
|
handler: () => _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
233
|
+
let account = yield this.getTurnkeyAccount();
|
|
234
|
+
try {
|
|
235
|
+
signedMessageRaw = yield (account === null || account === void 0 ? void 0 : account.signMessage(encodedMessage, address));
|
|
236
|
+
}
|
|
237
|
+
catch (_a) {
|
|
238
|
+
yield this.removeSessionKeys();
|
|
239
|
+
yield this.createOrRestoreSession({
|
|
240
|
+
ignoreRestore: true,
|
|
241
|
+
});
|
|
242
|
+
account = yield this.getTurnkeyAccount();
|
|
243
|
+
signedMessageRaw = yield (account === null || account === void 0 ? void 0 : account.signMessage(encodedMessage, address));
|
|
244
|
+
}
|
|
201
245
|
return utils.bufferToBase64(signedMessageRaw || Buffer.from([]));
|
|
202
246
|
}),
|
|
203
|
-
message:
|
|
247
|
+
message: new TextDecoder().decode(encodedMessage),
|
|
204
248
|
});
|
|
205
|
-
|
|
249
|
+
if (!signedMessageRaw) {
|
|
250
|
+
throw new Error('Failed to sign message');
|
|
251
|
+
}
|
|
252
|
+
return signedMessageRaw;
|
|
206
253
|
});
|
|
207
254
|
}
|
|
208
|
-
|
|
209
|
-
return _tslib.__awaiter(this,
|
|
210
|
-
const
|
|
255
|
+
signMessage(messageToSign) {
|
|
256
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
257
|
+
const enc = new TextEncoder();
|
|
258
|
+
const encodedMessage = enc.encode(messageToSign);
|
|
259
|
+
const signedRawMessage = yield this.signUint8ArrayMessage(encodedMessage);
|
|
260
|
+
return utils.bufferToBase64(signedRawMessage);
|
|
261
|
+
});
|
|
262
|
+
}
|
|
263
|
+
signTransaction(transaction) {
|
|
264
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
265
|
+
yield this.createOrRestoreSession();
|
|
266
|
+
let account = yield this.getTurnkeyAccount();
|
|
211
267
|
const address = this.turnkeyAddress;
|
|
212
268
|
if (!account || !address) {
|
|
213
269
|
throw new Error('No turnkey account');
|
|
214
270
|
}
|
|
215
|
-
|
|
216
|
-
|
|
271
|
+
try {
|
|
272
|
+
yield account.addSignature(transaction, address);
|
|
273
|
+
}
|
|
274
|
+
catch (err) {
|
|
275
|
+
if (embeddedWallet.TURNKEY_SDK_SESSION_KEY_RETRYABLE_ERRORS.some((errorMsg) => err.message.includes(errorMsg))) {
|
|
276
|
+
yield this.removeSessionKeys();
|
|
277
|
+
yield this.createOrRestoreSession({
|
|
278
|
+
ignoreRestore: true,
|
|
279
|
+
});
|
|
280
|
+
account = (yield this.getTurnkeyAccount());
|
|
281
|
+
yield account.addSignature(transaction, address);
|
|
282
|
+
}
|
|
283
|
+
else {
|
|
284
|
+
embeddedWallet.logger.error('[TK] failed to perform SignTransaction activity', err);
|
|
285
|
+
throw err;
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
return transaction;
|
|
217
289
|
});
|
|
218
290
|
}
|
|
219
291
|
internalSignAndSendTransaction(transaction, options) {
|
|
@@ -232,8 +304,8 @@ class TurnkeySolanaWalletConnector extends embeddedWallet.TurnkeyWalletConnector
|
|
|
232
304
|
transaction.feePayer =
|
|
233
305
|
(_a = transaction.feePayer) !== null && _a !== void 0 ? _a : new web3_js.PublicKey(this.turnkeyAddress);
|
|
234
306
|
}
|
|
235
|
-
const signedTransaction = yield this.signTransaction(
|
|
236
|
-
const signature = yield currentConnection.sendRawTransaction(signedTransaction, options);
|
|
307
|
+
const signedTransaction = yield this.signTransaction(transaction);
|
|
308
|
+
const signature = yield currentConnection.sendRawTransaction(Buffer.from(signedTransaction.serialize()), options);
|
|
237
309
|
// listen for tx confirmation until 60 seconds, which is ~150 blocks expiration
|
|
238
310
|
return new Promise((resolve, reject) => {
|
|
239
311
|
const timeout = setTimeout(() => {
|
|
@@ -253,21 +325,45 @@ class TurnkeySolanaWalletConnector extends embeddedWallet.TurnkeyWalletConnector
|
|
|
253
325
|
}
|
|
254
326
|
signAndSendTransaction(transaction, options) {
|
|
255
327
|
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
328
|
+
var _a;
|
|
256
329
|
if (!this.turnkeyAddress)
|
|
257
330
|
throw new utils.DynamicError('Solana wallet not found');
|
|
258
|
-
|
|
331
|
+
let optimizedTransaction = transaction;
|
|
332
|
+
try {
|
|
333
|
+
if ((yield this.getNetwork()) === 'mainnet') {
|
|
334
|
+
optimizedTransaction = (yield api.optimizeSolanaTransaction(this.getEnvId(), transaction, (_a = this.turnkeyAddress) !== null && _a !== void 0 ? _a : ''));
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
catch (e) {
|
|
338
|
+
embeddedWallet.logger.warn('Failed to optimize transaction', e);
|
|
339
|
+
}
|
|
340
|
+
const transactionsData = yield transactionDecoder.decodeTransaction(optimizedTransaction, this.getConnection(), this.turnkeyAddress);
|
|
259
341
|
if (!(transactionsData === null || transactionsData === void 0 ? void 0 : transactionsData.length)) {
|
|
260
342
|
throw new utils.DynamicError('Incorrectly formatted transaction instructions');
|
|
261
343
|
}
|
|
262
|
-
|
|
263
|
-
|
|
344
|
+
let spent;
|
|
345
|
+
let insufficientFunds = false;
|
|
346
|
+
try {
|
|
347
|
+
spent = yield transactionDecoder.getTotalSolanaSpend(optimizedTransaction, this.getConnection(), this.turnkeyAddress);
|
|
348
|
+
}
|
|
349
|
+
catch (e) {
|
|
350
|
+
if (e.message === 'Insufficient funds') {
|
|
351
|
+
insufficientFunds = true;
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
const to = transactionDecoder.summarizeTransactionDecodedData(transactionsData);
|
|
355
|
+
const uiTransaction = new solanaCore.SolanaUiTransaction({
|
|
264
356
|
connection: this.getConnection(),
|
|
265
357
|
from: this.turnkeyAddress,
|
|
266
|
-
onSubmit: () => _tslib.__awaiter(this, void 0, void 0, function* () { return this.internalSignAndSendTransaction(
|
|
267
|
-
originalTransaction:
|
|
358
|
+
onSubmit: () => _tslib.__awaiter(this, void 0, void 0, function* () { return this.internalSignAndSendTransaction(optimizedTransaction, options); }),
|
|
359
|
+
originalTransaction: optimizedTransaction,
|
|
268
360
|
});
|
|
269
361
|
uiTransaction.to = to;
|
|
270
|
-
uiTransaction.value =
|
|
362
|
+
uiTransaction.value = spent;
|
|
363
|
+
if (insufficientFunds) {
|
|
364
|
+
uiTransaction.notEnoughFundsError = true;
|
|
365
|
+
}
|
|
366
|
+
// TODO: remove this. We should not be passing references to wallet connectors
|
|
271
367
|
return this.walletUiUtils.sendTransaction(this, uiTransaction);
|
|
272
368
|
});
|
|
273
369
|
}
|
|
@@ -311,11 +407,14 @@ class TurnkeySolanaWalletConnector extends embeddedWallet.TurnkeyWalletConnector
|
|
|
311
407
|
}
|
|
312
408
|
createUiTransaction(from) {
|
|
313
409
|
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
314
|
-
|
|
410
|
+
yield this.validateActiveWallet(from);
|
|
411
|
+
const transaction = new solanaCore.SolanaUiTransaction({
|
|
315
412
|
connection: this.getConnection(),
|
|
316
413
|
from,
|
|
317
414
|
onSubmit: (transaction) => _tslib.__awaiter(this, void 0, void 0, function* () { return this.internalSignAndSendTransaction(transaction); }),
|
|
318
415
|
});
|
|
416
|
+
transaction.feeDeducted = true;
|
|
417
|
+
return transaction;
|
|
319
418
|
});
|
|
320
419
|
}
|
|
321
420
|
}
|
|
@@ -1,23 +1,24 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
1
|
import { Commitment, Connection, ConnectionConfig, Transaction, VersionedTransaction, ConfirmOptions, Signer, SendOptions } from '@solana/web3.js';
|
|
2
|
+
import { TurnkeyApiTypes } from '@turnkey/http';
|
|
3
3
|
import { GenericNetwork, IUITransaction, WalletUiUtils } from '@dynamic-labs/types';
|
|
4
|
-
import { Chain, ISendBalanceWalletConnector,
|
|
4
|
+
import { Chain, ISendBalanceWalletConnector, InternalWalletConnector } from '@dynamic-labs/wallet-connector-core';
|
|
5
5
|
import { WalletBookSchema } from '@dynamic-labs/wallet-book';
|
|
6
6
|
import { JwtVerifiedCredential } from '@dynamic-labs/sdk-api-core';
|
|
7
|
-
import { IChainRpcProviders } from '@dynamic-labs/
|
|
7
|
+
import { IChainRpcProviders, SolanaWallet } from '@dynamic-labs/solana-core';
|
|
8
8
|
import { TurnkeyWalletConnectorBase, TurnkeyWalletConnectorNameAndKey } from '@dynamic-labs/embedded-wallet';
|
|
9
9
|
import { TurnkeySolanaSigner } from './TurnkeySolanaSigner';
|
|
10
10
|
type SendTransactionOptions = ConfirmOptions & {
|
|
11
11
|
signers?: Signer[];
|
|
12
12
|
};
|
|
13
13
|
export type TurnkeySolanaConnectorProps = {
|
|
14
|
-
walletUiUtils: WalletUiUtils<
|
|
14
|
+
walletUiUtils: WalletUiUtils<InternalWalletConnector>;
|
|
15
15
|
walletBook: WalletBookSchema;
|
|
16
16
|
solNetworks: GenericNetwork[];
|
|
17
17
|
appName?: string;
|
|
18
18
|
chainRpcProviders: IChainRpcProviders;
|
|
19
19
|
};
|
|
20
20
|
export declare class TurnkeySolanaWalletConnector extends TurnkeyWalletConnectorBase implements ISendBalanceWalletConnector {
|
|
21
|
+
ChainWallet: typeof SolanaWallet;
|
|
21
22
|
connectedChain: Chain;
|
|
22
23
|
supportedChains: Chain[];
|
|
23
24
|
solNetworks: GenericNetwork[];
|
|
@@ -34,6 +35,7 @@ export declare class TurnkeySolanaWalletConnector extends TurnkeyWalletConnector
|
|
|
34
35
|
getPublicClient(): Promise<Connection | undefined>;
|
|
35
36
|
supportsNetworkSwitching(): boolean;
|
|
36
37
|
setVerifiedCredentials(verifiedCredentials: JwtVerifiedCredential[]): void;
|
|
38
|
+
validateActiveWallet(expectedAddress: string): Promise<void>;
|
|
37
39
|
getAccount(): string | undefined;
|
|
38
40
|
endSession(): Promise<void>;
|
|
39
41
|
private refreshTurnkeyAccount;
|
|
@@ -41,15 +43,18 @@ export declare class TurnkeySolanaWalletConnector extends TurnkeyWalletConnector
|
|
|
41
43
|
private createTurnkeyAccount;
|
|
42
44
|
private getTurnkeyAccount;
|
|
43
45
|
getSigner(): Promise<TurnkeySolanaSigner | undefined>;
|
|
44
|
-
getBalance(): Promise<string | undefined>;
|
|
46
|
+
getBalance(address: string): Promise<string | undefined>;
|
|
47
|
+
signUint8ArrayMessage(encodedMessage: Uint8Array): Promise<Uint8Array>;
|
|
48
|
+
getEnvId: () => any;
|
|
45
49
|
signMessage(messageToSign: string): Promise<string | undefined>;
|
|
46
|
-
signTransaction(
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
signAndSendTransaction(transaction: Transaction | VersionedTransaction, options?: SendOptions): Promise<string>;
|
|
51
|
-
sendTransaction(transaction: Transaction | VersionedTransaction, connection: Connection, options?: SendTransactionOptions): Promise<string>;
|
|
50
|
+
signTransaction<T extends Transaction | VersionedTransaction>(transaction: T): Promise<T>;
|
|
51
|
+
internalSignAndSendTransaction<T extends Transaction | VersionedTransaction>(transaction: T, options?: SendOptions): Promise<string>;
|
|
52
|
+
signAndSendTransaction<T extends Transaction | VersionedTransaction>(transaction: T, options?: SendOptions): Promise<string>;
|
|
53
|
+
sendTransaction<T extends Transaction | VersionedTransaction>(transaction: T, connection: Connection, options?: SendTransactionOptions): Promise<string>;
|
|
52
54
|
private lamportsToSol;
|
|
53
55
|
createUiTransaction(from: string): Promise<IUITransaction>;
|
|
56
|
+
stampCreateWalletAccountRequest: ({ request, }: {
|
|
57
|
+
request: TurnkeyApiTypes['v1CreateWalletAccountsRequest'];
|
|
58
|
+
}) => Promise<import("@turnkey/http").TSignedRequest>;
|
|
54
59
|
}
|
|
55
60
|
export {};
|