@turnkey/core 1.0.0-beta.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/LICENSE +201 -0
- package/README.MD +5 -0
- package/dist/__clients__/core.d.ts +1010 -0
- package/dist/__clients__/core.d.ts.map +1 -0
- package/dist/__clients__/core.js +2358 -0
- package/dist/__clients__/core.js.map +1 -0
- package/dist/__clients__/core.mjs +2356 -0
- package/dist/__clients__/core.mjs.map +1 -0
- package/dist/__generated__/sdk-client-base.d.ts +211 -0
- package/dist/__generated__/sdk-client-base.d.ts.map +1 -0
- package/dist/__generated__/sdk-client-base.js +3219 -0
- package/dist/__generated__/sdk-client-base.js.map +1 -0
- package/dist/__generated__/sdk-client-base.mjs +3217 -0
- package/dist/__generated__/sdk-client-base.mjs.map +1 -0
- package/dist/__generated__/version.d.ts +2 -0
- package/dist/__generated__/version.d.ts.map +1 -0
- package/dist/__generated__/version.js +6 -0
- package/dist/__generated__/version.js.map +1 -0
- package/dist/__generated__/version.mjs +4 -0
- package/dist/__generated__/version.mjs.map +1 -0
- package/dist/__inputs__/public_api.types.d.ts +5170 -0
- package/dist/__inputs__/public_api.types.d.ts.map +1 -0
- package/dist/__polyfills__/window.d.ts +15 -0
- package/dist/__polyfills__/window.d.ts.map +1 -0
- package/dist/__polyfills__/window.js +30 -0
- package/dist/__polyfills__/window.js.map +1 -0
- package/dist/__polyfills__/window.mjs +28 -0
- package/dist/__polyfills__/window.mjs.map +1 -0
- package/dist/__stampers__/api/base.d.ts +20 -0
- package/dist/__stampers__/api/base.d.ts.map +1 -0
- package/dist/__stampers__/api/base.js +67 -0
- package/dist/__stampers__/api/base.js.map +1 -0
- package/dist/__stampers__/api/base.mjs +65 -0
- package/dist/__stampers__/api/base.mjs.map +1 -0
- package/dist/__stampers__/api/mobile/stamper.d.ts +13 -0
- package/dist/__stampers__/api/mobile/stamper.d.ts.map +1 -0
- package/dist/__stampers__/api/mobile/stamper.js +69 -0
- package/dist/__stampers__/api/mobile/stamper.js.map +1 -0
- package/dist/__stampers__/api/mobile/stamper.mjs +67 -0
- package/dist/__stampers__/api/mobile/stamper.mjs.map +1 -0
- package/dist/__stampers__/api/web/stamper.d.ts +14 -0
- package/dist/__stampers__/api/web/stamper.d.ts.map +1 -0
- package/dist/__stampers__/api/web/stamper.js +212 -0
- package/dist/__stampers__/api/web/stamper.js.map +1 -0
- package/dist/__stampers__/api/web/stamper.mjs +210 -0
- package/dist/__stampers__/api/web/stamper.mjs.map +1 -0
- package/dist/__stampers__/passkey/base.d.ts +18 -0
- package/dist/__stampers__/passkey/base.d.ts.map +1 -0
- package/dist/__stampers__/passkey/base.js +138 -0
- package/dist/__stampers__/passkey/base.js.map +1 -0
- package/dist/__stampers__/passkey/base.mjs +134 -0
- package/dist/__stampers__/passkey/base.mjs.map +1 -0
- package/dist/__storage__/base.d.ts +3 -0
- package/dist/__storage__/base.d.ts.map +1 -0
- package/dist/__storage__/base.js +27 -0
- package/dist/__storage__/base.js.map +1 -0
- package/dist/__storage__/base.mjs +25 -0
- package/dist/__storage__/base.mjs.map +1 -0
- package/dist/__storage__/mobile/storage.d.ts +18 -0
- package/dist/__storage__/mobile/storage.d.ts.map +1 -0
- package/dist/__storage__/mobile/storage.js +74 -0
- package/dist/__storage__/mobile/storage.js.map +1 -0
- package/dist/__storage__/mobile/storage.mjs +72 -0
- package/dist/__storage__/mobile/storage.mjs.map +1 -0
- package/dist/__storage__/web/storage.d.ts +19 -0
- package/dist/__storage__/web/storage.d.ts.map +1 -0
- package/dist/__storage__/web/storage.js +79 -0
- package/dist/__storage__/web/storage.js.map +1 -0
- package/dist/__storage__/web/storage.mjs +77 -0
- package/dist/__storage__/web/storage.mjs.map +1 -0
- package/dist/__types__/base.d.ts +407 -0
- package/dist/__types__/base.d.ts.map +1 -0
- package/dist/__types__/base.js +88 -0
- package/dist/__types__/base.js.map +1 -0
- package/dist/__types__/base.mjs +84 -0
- package/dist/__types__/base.mjs.map +1 -0
- package/dist/__wallet__/base.d.ts +3 -0
- package/dist/__wallet__/base.d.ts.map +1 -0
- package/dist/__wallet__/base.js +24 -0
- package/dist/__wallet__/base.js.map +1 -0
- package/dist/__wallet__/base.mjs +22 -0
- package/dist/__wallet__/base.mjs.map +1 -0
- package/dist/__wallet__/connector.d.ts +33 -0
- package/dist/__wallet__/connector.d.ts.map +1 -0
- package/dist/__wallet__/connector.js +63 -0
- package/dist/__wallet__/connector.js.map +1 -0
- package/dist/__wallet__/connector.mjs +61 -0
- package/dist/__wallet__/connector.mjs.map +1 -0
- package/dist/__wallet__/mobile/manager.d.ts +35 -0
- package/dist/__wallet__/mobile/manager.d.ts.map +1 -0
- package/dist/__wallet__/mobile/manager.js +95 -0
- package/dist/__wallet__/mobile/manager.js.map +1 -0
- package/dist/__wallet__/mobile/manager.mjs +93 -0
- package/dist/__wallet__/mobile/manager.mjs.map +1 -0
- package/dist/__wallet__/stamper.d.ts +19 -0
- package/dist/__wallet__/stamper.d.ts.map +1 -0
- package/dist/__wallet__/stamper.js +116 -0
- package/dist/__wallet__/stamper.js.map +1 -0
- package/dist/__wallet__/stamper.mjs +113 -0
- package/dist/__wallet__/stamper.mjs.map +1 -0
- package/dist/__wallet__/wallet-connect/base.d.ts +83 -0
- package/dist/__wallet__/wallet-connect/base.d.ts.map +1 -0
- package/dist/__wallet__/wallet-connect/base.js +362 -0
- package/dist/__wallet__/wallet-connect/base.js.map +1 -0
- package/dist/__wallet__/wallet-connect/base.mjs +360 -0
- package/dist/__wallet__/wallet-connect/base.mjs.map +1 -0
- package/dist/__wallet__/wallet-connect/client.d.ts +78 -0
- package/dist/__wallet__/wallet-connect/client.d.ts.map +1 -0
- package/dist/__wallet__/wallet-connect/client.js +139 -0
- package/dist/__wallet__/wallet-connect/client.js.map +1 -0
- package/dist/__wallet__/wallet-connect/client.mjs +137 -0
- package/dist/__wallet__/wallet-connect/client.mjs.map +1 -0
- package/dist/__wallet__/web/manager.d.ts +41 -0
- package/dist/__wallet__/web/manager.d.ts.map +1 -0
- package/dist/__wallet__/web/manager.js +115 -0
- package/dist/__wallet__/web/manager.js.map +1 -0
- package/dist/__wallet__/web/manager.mjs +113 -0
- package/dist/__wallet__/web/manager.mjs.map +1 -0
- package/dist/__wallet__/web/native/ethereum.d.ts +67 -0
- package/dist/__wallet__/web/native/ethereum.d.ts.map +1 -0
- package/dist/__wallet__/web/native/ethereum.js +248 -0
- package/dist/__wallet__/web/native/ethereum.js.map +1 -0
- package/dist/__wallet__/web/native/ethereum.mjs +245 -0
- package/dist/__wallet__/web/native/ethereum.mjs.map +1 -0
- package/dist/__wallet__/web/native/solana.d.ts +19 -0
- package/dist/__wallet__/web/native/solana.d.ts.map +1 -0
- package/dist/__wallet__/web/native/solana.js +149 -0
- package/dist/__wallet__/web/native/solana.js.map +1 -0
- package/dist/__wallet__/web/native/solana.mjs +146 -0
- package/dist/__wallet__/web/native/solana.mjs.map +1 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +78 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +8 -0
- package/dist/index.mjs.map +1 -0
- package/dist/turnkey-helpers.d.ts +68 -0
- package/dist/turnkey-helpers.d.ts.map +1 -0
- package/dist/turnkey-helpers.js +466 -0
- package/dist/turnkey-helpers.js.map +1 -0
- package/dist/turnkey-helpers.mjs +399 -0
- package/dist/turnkey-helpers.mjs.map +1 -0
- package/dist/utils.d.ts +54 -0
- package/dist/utils.d.ts.map +1 -0
- package/dist/utils.js +596 -0
- package/dist/utils.js.map +1 -0
- package/dist/utils.mjs +574 -0
- package/dist/utils.mjs.map +1 -0
- package/package.json +67 -0
|
@@ -0,0 +1,248 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var viem = require('viem');
|
|
4
|
+
var ethers = require('ethers');
|
|
5
|
+
var crypto = require('@turnkey/crypto');
|
|
6
|
+
var base = require('../../../__types__/base.js');
|
|
7
|
+
var encoding = require('@turnkey/encoding');
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Abstract base class for Ethereum wallet implementations.
|
|
11
|
+
*
|
|
12
|
+
* Provides shared logic for:
|
|
13
|
+
* - Provider discovery via EIP-6963
|
|
14
|
+
* - Connecting and disconnecting wallets
|
|
15
|
+
* - Recovering compressed public keys
|
|
16
|
+
*/
|
|
17
|
+
class BaseEthereumWallet {
|
|
18
|
+
constructor() {
|
|
19
|
+
this.interfaceType = base.WalletInterfaceType.Ethereum;
|
|
20
|
+
/**
|
|
21
|
+
* Retrieves the compressed public key by signing a known message.
|
|
22
|
+
*
|
|
23
|
+
* @param provider - The wallet provider to use.
|
|
24
|
+
* @returns A promise that resolves to the compressed public key (hex-encoded).
|
|
25
|
+
*/
|
|
26
|
+
this.getPublicKey = async (provider) => {
|
|
27
|
+
const message = "GET_PUBLIC_KEY";
|
|
28
|
+
const signature = await this.sign(message, provider, base.SignIntent.SignMessage);
|
|
29
|
+
return getCompressedPublicKey(signature, message);
|
|
30
|
+
};
|
|
31
|
+
/**
|
|
32
|
+
* Discovers EIP-1193 providers using the EIP-6963 standard.
|
|
33
|
+
*
|
|
34
|
+
* @returns A promise that resolves to a list of available wallet providers.
|
|
35
|
+
*/
|
|
36
|
+
this.getProviders = async () => {
|
|
37
|
+
const discovered = [];
|
|
38
|
+
const providerPromises = [];
|
|
39
|
+
const handler = (ev) => {
|
|
40
|
+
const { provider, info } = ev.detail;
|
|
41
|
+
const promise = (async () => {
|
|
42
|
+
let connectedAddresses = [];
|
|
43
|
+
// we default to Ethereum mainnet
|
|
44
|
+
let chainId = "0x1";
|
|
45
|
+
try {
|
|
46
|
+
const accounts = await provider.request?.({
|
|
47
|
+
method: "eth_accounts",
|
|
48
|
+
});
|
|
49
|
+
if (Array.isArray(accounts))
|
|
50
|
+
connectedAddresses = accounts;
|
|
51
|
+
chainId = await provider.request({
|
|
52
|
+
method: "eth_chainId",
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
catch {
|
|
56
|
+
// fail silently
|
|
57
|
+
}
|
|
58
|
+
discovered.push({
|
|
59
|
+
interfaceType: base.WalletInterfaceType.Ethereum,
|
|
60
|
+
chainInfo: {
|
|
61
|
+
namespace: base.Chain.Ethereum,
|
|
62
|
+
chainId,
|
|
63
|
+
},
|
|
64
|
+
info,
|
|
65
|
+
provider,
|
|
66
|
+
connectedAddresses,
|
|
67
|
+
});
|
|
68
|
+
})();
|
|
69
|
+
providerPromises.push(promise);
|
|
70
|
+
};
|
|
71
|
+
window.addEventListener("eip6963:announceProvider", handler);
|
|
72
|
+
window.dispatchEvent(new Event("eip6963:requestProvider"));
|
|
73
|
+
window.removeEventListener("eip6963:announceProvider", handler);
|
|
74
|
+
await Promise.all(providerPromises);
|
|
75
|
+
return discovered;
|
|
76
|
+
};
|
|
77
|
+
/**
|
|
78
|
+
* Ensures the wallet account is connected.
|
|
79
|
+
*
|
|
80
|
+
* @param provider - The wallet provider to use.
|
|
81
|
+
* @returns A promise that resolves once the account is connected.
|
|
82
|
+
*/
|
|
83
|
+
this.connectWalletAccount = async (provider) => {
|
|
84
|
+
const wallet = asEip1193(provider);
|
|
85
|
+
await getAccount(wallet);
|
|
86
|
+
};
|
|
87
|
+
/**
|
|
88
|
+
* Disconnects the wallet account by revoking permissions.
|
|
89
|
+
*
|
|
90
|
+
* @param provider - The wallet provider to disconnect.
|
|
91
|
+
* @returns A promise that resolves once the permissions are revoked.
|
|
92
|
+
*/
|
|
93
|
+
this.disconnectWalletAccount = async (provider) => {
|
|
94
|
+
const wallet = asEip1193(provider);
|
|
95
|
+
await wallet.request({
|
|
96
|
+
method: "wallet_revokePermissions",
|
|
97
|
+
params: [{ eth_accounts: {} }],
|
|
98
|
+
});
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
async switchChain(provider, chainOrId) {
|
|
102
|
+
if (provider.chainInfo.namespace !== base.Chain.Ethereum) {
|
|
103
|
+
throw new Error("Only EVM wallets can switch chains");
|
|
104
|
+
}
|
|
105
|
+
const wallet = asEip1193(provider);
|
|
106
|
+
const chainId = typeof chainOrId === "string" ? chainOrId : chainOrId.id;
|
|
107
|
+
try {
|
|
108
|
+
// first we just try switching
|
|
109
|
+
await wallet.request({
|
|
110
|
+
method: "wallet_switchEthereumChain",
|
|
111
|
+
params: [{ chainId }],
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
catch (err) {
|
|
115
|
+
// if the error is not “chain not found”
|
|
116
|
+
// we just re-throw it
|
|
117
|
+
if (err.code !== 4902) {
|
|
118
|
+
throw err;
|
|
119
|
+
}
|
|
120
|
+
// no metadata was provided so we throw an error
|
|
121
|
+
// telling them to pass it in
|
|
122
|
+
if (typeof chainOrId === "string") {
|
|
123
|
+
throw new Error(`Chain ${chainId} not recognized. ` +
|
|
124
|
+
`If you want to add it, call switchChain with a SwitchableChain object.`);
|
|
125
|
+
}
|
|
126
|
+
// we have full metadata and can add the chain and switch
|
|
127
|
+
const { name, rpcUrls, blockExplorerUrls, iconUrls, nativeCurrency } = chainOrId;
|
|
128
|
+
// add the chain
|
|
129
|
+
await wallet.request({
|
|
130
|
+
method: "wallet_addEthereumChain",
|
|
131
|
+
params: [
|
|
132
|
+
{
|
|
133
|
+
chainId,
|
|
134
|
+
chainName: name,
|
|
135
|
+
rpcUrls,
|
|
136
|
+
blockExplorerUrls,
|
|
137
|
+
iconUrls,
|
|
138
|
+
nativeCurrency,
|
|
139
|
+
},
|
|
140
|
+
],
|
|
141
|
+
});
|
|
142
|
+
// then switch again
|
|
143
|
+
await wallet.request({
|
|
144
|
+
method: "wallet_switchEthereumChain",
|
|
145
|
+
params: [{ chainId }],
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* EthereumWallet implementation using EIP-1193 compatible providers.
|
|
152
|
+
*
|
|
153
|
+
* Handles message signing and transaction submission.
|
|
154
|
+
*/
|
|
155
|
+
class EthereumWallet extends BaseEthereumWallet {
|
|
156
|
+
constructor() {
|
|
157
|
+
super(...arguments);
|
|
158
|
+
/**
|
|
159
|
+
* Signs a message or sends a transaction depending on intent.
|
|
160
|
+
*
|
|
161
|
+
* @param message - The message or raw transaction to be signed.
|
|
162
|
+
* @param provider - The wallet provider to use.
|
|
163
|
+
* @param intent - Signing intent (SignMessage or SignAndSendTransaction).
|
|
164
|
+
* @returns A promise that resolves to a hex string (signature or tx hash).
|
|
165
|
+
*/
|
|
166
|
+
this.sign = async (message, provider, intent) => {
|
|
167
|
+
const selectedProvider = asEip1193(provider);
|
|
168
|
+
const account = await getAccount(selectedProvider);
|
|
169
|
+
switch (intent) {
|
|
170
|
+
case base.SignIntent.SignMessage:
|
|
171
|
+
return await selectedProvider.request({
|
|
172
|
+
method: "personal_sign",
|
|
173
|
+
params: [message, account],
|
|
174
|
+
});
|
|
175
|
+
case base.SignIntent.SignAndSendTransaction:
|
|
176
|
+
const tx = ethers.Transaction.from(message);
|
|
177
|
+
const txParams = {
|
|
178
|
+
from: account,
|
|
179
|
+
to: tx.to?.toString(),
|
|
180
|
+
value: viem.toHex(tx.value),
|
|
181
|
+
gas: viem.toHex(tx.gasLimit),
|
|
182
|
+
maxFeePerGas: viem.toHex(tx.maxFeePerGas ?? 0n),
|
|
183
|
+
maxPriorityFeePerGas: viem.toHex(tx.maxPriorityFeePerGas ?? 0n),
|
|
184
|
+
nonce: viem.toHex(tx.nonce),
|
|
185
|
+
chainId: viem.toHex(tx.chainId),
|
|
186
|
+
data: tx.data?.toString() ?? "0x",
|
|
187
|
+
};
|
|
188
|
+
return await selectedProvider.request({
|
|
189
|
+
method: "eth_sendTransaction",
|
|
190
|
+
params: [txParams],
|
|
191
|
+
});
|
|
192
|
+
default:
|
|
193
|
+
throw new Error(`Unsupported sign intent: ${intent}`);
|
|
194
|
+
}
|
|
195
|
+
};
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
/**
|
|
199
|
+
* Retrieves the active Ethereum account from a provider.
|
|
200
|
+
*
|
|
201
|
+
* @param provider - EIP-1193 compliant provider.
|
|
202
|
+
* @returns A promise resolving to the connected Ethereum address.
|
|
203
|
+
* @throws If no connected account is found.
|
|
204
|
+
*/
|
|
205
|
+
const getAccount = async (provider) => {
|
|
206
|
+
const [connectedAccount] = await provider.request({
|
|
207
|
+
method: "eth_requestAccounts",
|
|
208
|
+
});
|
|
209
|
+
if (!connectedAccount)
|
|
210
|
+
throw new Error("No connected account found");
|
|
211
|
+
return connectedAccount;
|
|
212
|
+
};
|
|
213
|
+
/**
|
|
214
|
+
* Recovers and compresses the public key from a signed message.
|
|
215
|
+
*
|
|
216
|
+
* @param signature - The signature as a hex string.
|
|
217
|
+
* @param message - The original signed message.
|
|
218
|
+
* @returns A promise resolving to the compressed public key (hex-encoded).
|
|
219
|
+
*/
|
|
220
|
+
const getCompressedPublicKey = async (signature, message) => {
|
|
221
|
+
const secp256k1PublicKey = await viem.recoverPublicKey({
|
|
222
|
+
hash: viem.hashMessage(message),
|
|
223
|
+
signature: signature,
|
|
224
|
+
});
|
|
225
|
+
const publicKeyHex = secp256k1PublicKey.startsWith("0x")
|
|
226
|
+
? secp256k1PublicKey.slice(2)
|
|
227
|
+
: secp256k1PublicKey;
|
|
228
|
+
const publicKeyBytes = encoding.uint8ArrayFromHexString(publicKeyHex);
|
|
229
|
+
const publicKeyBytesCompressed = crypto.compressRawPublicKey(publicKeyBytes);
|
|
230
|
+
return encoding.uint8ArrayToHexString(publicKeyBytesCompressed);
|
|
231
|
+
};
|
|
232
|
+
/**
|
|
233
|
+
* Validates and casts a WalletRpcProvider to an EIP-1193 provider.
|
|
234
|
+
*
|
|
235
|
+
* @param p - The wallet RPC provider.
|
|
236
|
+
* @returns A valid EIP1193 provider.
|
|
237
|
+
* @throws If the provider does not implement the request() method.
|
|
238
|
+
*/
|
|
239
|
+
const asEip1193 = (p) => {
|
|
240
|
+
if (p.provider && typeof p.provider.request === "function") {
|
|
241
|
+
return p.provider;
|
|
242
|
+
}
|
|
243
|
+
throw new Error("Expected an EIP-1193 provider (Ethereum wallet)");
|
|
244
|
+
};
|
|
245
|
+
|
|
246
|
+
exports.BaseEthereumWallet = BaseEthereumWallet;
|
|
247
|
+
exports.EthereumWallet = EthereumWallet;
|
|
248
|
+
//# sourceMappingURL=ethereum.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ethereum.js","sources":["../../../../src/__wallet__/web/native/ethereum.ts"],"sourcesContent":[null],"names":["WalletInterfaceType","SignIntent","Chain","Transaction","toHex","recoverPublicKey","hashMessage","uint8ArrayFromHexString","compressRawPublicKey","uint8ArrayToHexString"],"mappings":";;;;;;;;AAyBA;;;;;;;AAOG;MACmB,kBAAkB,CAAA;AAAxC,IAAA,WAAA,GAAA;AACW,QAAA,IAAA,CAAA,aAAa,GAAGA,wBAAmB,CAAC,QAAQ;AAgBrD;;;;;AAKG;AACH,QAAA,IAAA,CAAA,YAAY,GAAG,OAAO,QAAwB,KAAqB;YACjE,MAAM,OAAO,GAAG,gBAAgB;AAChC,YAAA,MAAM,SAAS,GAAG,MAAM,IAAI,CAAC,IAAI,CAC/B,OAAO,EACP,QAAQ,EACRC,eAAU,CAAC,WAAW,CACvB;AACD,YAAA,OAAO,sBAAsB,CAAC,SAAS,EAAE,OAAO,CAAC;AACnD,SAAC;AAED;;;;AAIG;QACH,IAAY,CAAA,YAAA,GAAG,YAAsC;YACnD,MAAM,UAAU,GAAqB,EAAE;YAOvC,MAAM,gBAAgB,GAAoB,EAAE;AAE5C,YAAA,MAAM,OAAO,GAAG,CAAC,EAAiB,KAAU;gBAC1C,MAAM,EAAE,QAAQ,EAAE,IAAI,EAAE,GAAG,EAAE,CAAC,MAAM;AAEpC,gBAAA,MAAM,OAAO,GAAG,CAAC,YAAW;oBAC1B,IAAI,kBAAkB,GAAa,EAAE;;oBAGrC,IAAI,OAAO,GAAG,KAAK;AAEnB,oBAAA,IAAI;AACF,wBAAA,MAAM,QAAQ,GAAG,MAAO,QAAgB,CAAC,OAAO,GAAG;AACjD,4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AC,CAAiB,KAAqB;AACvD,IAAA,IAAI,CAAC,CAAC,QAAQ,IAAI,OAAQ,CAAC,CAAC,QAAgB,CAAC,OAAO,KAAK,UAAU,EAAE;QACnE,OAAO,CAAC,CAAC,QAA2B;;AAEtC,IAAA,MAAM,IAAI,KAAK,CAAC,iDAAiD,CAAC;AACpE,CAAC;;;;;"}
|
|
@@ -0,0 +1,245 @@
|
|
|
1
|
+
import { toHex, recoverPublicKey, hashMessage } from 'viem';
|
|
2
|
+
import { Transaction } from 'ethers';
|
|
3
|
+
import { compressRawPublicKey } from '@turnkey/crypto';
|
|
4
|
+
import { SignIntent, WalletInterfaceType, Chain } from '../../../__types__/base.mjs';
|
|
5
|
+
import { uint8ArrayFromHexString, uint8ArrayToHexString } from '@turnkey/encoding';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Abstract base class for Ethereum wallet implementations.
|
|
9
|
+
*
|
|
10
|
+
* Provides shared logic for:
|
|
11
|
+
* - Provider discovery via EIP-6963
|
|
12
|
+
* - Connecting and disconnecting wallets
|
|
13
|
+
* - Recovering compressed public keys
|
|
14
|
+
*/
|
|
15
|
+
class BaseEthereumWallet {
|
|
16
|
+
constructor() {
|
|
17
|
+
this.interfaceType = WalletInterfaceType.Ethereum;
|
|
18
|
+
/**
|
|
19
|
+
* Retrieves the compressed public key by signing a known message.
|
|
20
|
+
*
|
|
21
|
+
* @param provider - The wallet provider to use.
|
|
22
|
+
* @returns A promise that resolves to the compressed public key (hex-encoded).
|
|
23
|
+
*/
|
|
24
|
+
this.getPublicKey = async (provider) => {
|
|
25
|
+
const message = "GET_PUBLIC_KEY";
|
|
26
|
+
const signature = await this.sign(message, provider, SignIntent.SignMessage);
|
|
27
|
+
return getCompressedPublicKey(signature, message);
|
|
28
|
+
};
|
|
29
|
+
/**
|
|
30
|
+
* Discovers EIP-1193 providers using the EIP-6963 standard.
|
|
31
|
+
*
|
|
32
|
+
* @returns A promise that resolves to a list of available wallet providers.
|
|
33
|
+
*/
|
|
34
|
+
this.getProviders = async () => {
|
|
35
|
+
const discovered = [];
|
|
36
|
+
const providerPromises = [];
|
|
37
|
+
const handler = (ev) => {
|
|
38
|
+
const { provider, info } = ev.detail;
|
|
39
|
+
const promise = (async () => {
|
|
40
|
+
let connectedAddresses = [];
|
|
41
|
+
// we default to Ethereum mainnet
|
|
42
|
+
let chainId = "0x1";
|
|
43
|
+
try {
|
|
44
|
+
const accounts = await provider.request?.({
|
|
45
|
+
method: "eth_accounts",
|
|
46
|
+
});
|
|
47
|
+
if (Array.isArray(accounts))
|
|
48
|
+
connectedAddresses = accounts;
|
|
49
|
+
chainId = await provider.request({
|
|
50
|
+
method: "eth_chainId",
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
catch {
|
|
54
|
+
// fail silently
|
|
55
|
+
}
|
|
56
|
+
discovered.push({
|
|
57
|
+
interfaceType: WalletInterfaceType.Ethereum,
|
|
58
|
+
chainInfo: {
|
|
59
|
+
namespace: Chain.Ethereum,
|
|
60
|
+
chainId,
|
|
61
|
+
},
|
|
62
|
+
info,
|
|
63
|
+
provider,
|
|
64
|
+
connectedAddresses,
|
|
65
|
+
});
|
|
66
|
+
})();
|
|
67
|
+
providerPromises.push(promise);
|
|
68
|
+
};
|
|
69
|
+
window.addEventListener("eip6963:announceProvider", handler);
|
|
70
|
+
window.dispatchEvent(new Event("eip6963:requestProvider"));
|
|
71
|
+
window.removeEventListener("eip6963:announceProvider", handler);
|
|
72
|
+
await Promise.all(providerPromises);
|
|
73
|
+
return discovered;
|
|
74
|
+
};
|
|
75
|
+
/**
|
|
76
|
+
* Ensures the wallet account is connected.
|
|
77
|
+
*
|
|
78
|
+
* @param provider - The wallet provider to use.
|
|
79
|
+
* @returns A promise that resolves once the account is connected.
|
|
80
|
+
*/
|
|
81
|
+
this.connectWalletAccount = async (provider) => {
|
|
82
|
+
const wallet = asEip1193(provider);
|
|
83
|
+
await getAccount(wallet);
|
|
84
|
+
};
|
|
85
|
+
/**
|
|
86
|
+
* Disconnects the wallet account by revoking permissions.
|
|
87
|
+
*
|
|
88
|
+
* @param provider - The wallet provider to disconnect.
|
|
89
|
+
* @returns A promise that resolves once the permissions are revoked.
|
|
90
|
+
*/
|
|
91
|
+
this.disconnectWalletAccount = async (provider) => {
|
|
92
|
+
const wallet = asEip1193(provider);
|
|
93
|
+
await wallet.request({
|
|
94
|
+
method: "wallet_revokePermissions",
|
|
95
|
+
params: [{ eth_accounts: {} }],
|
|
96
|
+
});
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
async switchChain(provider, chainOrId) {
|
|
100
|
+
if (provider.chainInfo.namespace !== Chain.Ethereum) {
|
|
101
|
+
throw new Error("Only EVM wallets can switch chains");
|
|
102
|
+
}
|
|
103
|
+
const wallet = asEip1193(provider);
|
|
104
|
+
const chainId = typeof chainOrId === "string" ? chainOrId : chainOrId.id;
|
|
105
|
+
try {
|
|
106
|
+
// first we just try switching
|
|
107
|
+
await wallet.request({
|
|
108
|
+
method: "wallet_switchEthereumChain",
|
|
109
|
+
params: [{ chainId }],
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
catch (err) {
|
|
113
|
+
// if the error is not “chain not found”
|
|
114
|
+
// we just re-throw it
|
|
115
|
+
if (err.code !== 4902) {
|
|
116
|
+
throw err;
|
|
117
|
+
}
|
|
118
|
+
// no metadata was provided so we throw an error
|
|
119
|
+
// telling them to pass it in
|
|
120
|
+
if (typeof chainOrId === "string") {
|
|
121
|
+
throw new Error(`Chain ${chainId} not recognized. ` +
|
|
122
|
+
`If you want to add it, call switchChain with a SwitchableChain object.`);
|
|
123
|
+
}
|
|
124
|
+
// we have full metadata and can add the chain and switch
|
|
125
|
+
const { name, rpcUrls, blockExplorerUrls, iconUrls, nativeCurrency } = chainOrId;
|
|
126
|
+
// add the chain
|
|
127
|
+
await wallet.request({
|
|
128
|
+
method: "wallet_addEthereumChain",
|
|
129
|
+
params: [
|
|
130
|
+
{
|
|
131
|
+
chainId,
|
|
132
|
+
chainName: name,
|
|
133
|
+
rpcUrls,
|
|
134
|
+
blockExplorerUrls,
|
|
135
|
+
iconUrls,
|
|
136
|
+
nativeCurrency,
|
|
137
|
+
},
|
|
138
|
+
],
|
|
139
|
+
});
|
|
140
|
+
// then switch again
|
|
141
|
+
await wallet.request({
|
|
142
|
+
method: "wallet_switchEthereumChain",
|
|
143
|
+
params: [{ chainId }],
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* EthereumWallet implementation using EIP-1193 compatible providers.
|
|
150
|
+
*
|
|
151
|
+
* Handles message signing and transaction submission.
|
|
152
|
+
*/
|
|
153
|
+
class EthereumWallet extends BaseEthereumWallet {
|
|
154
|
+
constructor() {
|
|
155
|
+
super(...arguments);
|
|
156
|
+
/**
|
|
157
|
+
* Signs a message or sends a transaction depending on intent.
|
|
158
|
+
*
|
|
159
|
+
* @param message - The message or raw transaction to be signed.
|
|
160
|
+
* @param provider - The wallet provider to use.
|
|
161
|
+
* @param intent - Signing intent (SignMessage or SignAndSendTransaction).
|
|
162
|
+
* @returns A promise that resolves to a hex string (signature or tx hash).
|
|
163
|
+
*/
|
|
164
|
+
this.sign = async (message, provider, intent) => {
|
|
165
|
+
const selectedProvider = asEip1193(provider);
|
|
166
|
+
const account = await getAccount(selectedProvider);
|
|
167
|
+
switch (intent) {
|
|
168
|
+
case SignIntent.SignMessage:
|
|
169
|
+
return await selectedProvider.request({
|
|
170
|
+
method: "personal_sign",
|
|
171
|
+
params: [message, account],
|
|
172
|
+
});
|
|
173
|
+
case SignIntent.SignAndSendTransaction:
|
|
174
|
+
const tx = Transaction.from(message);
|
|
175
|
+
const txParams = {
|
|
176
|
+
from: account,
|
|
177
|
+
to: tx.to?.toString(),
|
|
178
|
+
value: toHex(tx.value),
|
|
179
|
+
gas: toHex(tx.gasLimit),
|
|
180
|
+
maxFeePerGas: toHex(tx.maxFeePerGas ?? 0n),
|
|
181
|
+
maxPriorityFeePerGas: toHex(tx.maxPriorityFeePerGas ?? 0n),
|
|
182
|
+
nonce: toHex(tx.nonce),
|
|
183
|
+
chainId: toHex(tx.chainId),
|
|
184
|
+
data: tx.data?.toString() ?? "0x",
|
|
185
|
+
};
|
|
186
|
+
return await selectedProvider.request({
|
|
187
|
+
method: "eth_sendTransaction",
|
|
188
|
+
params: [txParams],
|
|
189
|
+
});
|
|
190
|
+
default:
|
|
191
|
+
throw new Error(`Unsupported sign intent: ${intent}`);
|
|
192
|
+
}
|
|
193
|
+
};
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
/**
|
|
197
|
+
* Retrieves the active Ethereum account from a provider.
|
|
198
|
+
*
|
|
199
|
+
* @param provider - EIP-1193 compliant provider.
|
|
200
|
+
* @returns A promise resolving to the connected Ethereum address.
|
|
201
|
+
* @throws If no connected account is found.
|
|
202
|
+
*/
|
|
203
|
+
const getAccount = async (provider) => {
|
|
204
|
+
const [connectedAccount] = await provider.request({
|
|
205
|
+
method: "eth_requestAccounts",
|
|
206
|
+
});
|
|
207
|
+
if (!connectedAccount)
|
|
208
|
+
throw new Error("No connected account found");
|
|
209
|
+
return connectedAccount;
|
|
210
|
+
};
|
|
211
|
+
/**
|
|
212
|
+
* Recovers and compresses the public key from a signed message.
|
|
213
|
+
*
|
|
214
|
+
* @param signature - The signature as a hex string.
|
|
215
|
+
* @param message - The original signed message.
|
|
216
|
+
* @returns A promise resolving to the compressed public key (hex-encoded).
|
|
217
|
+
*/
|
|
218
|
+
const getCompressedPublicKey = async (signature, message) => {
|
|
219
|
+
const secp256k1PublicKey = await recoverPublicKey({
|
|
220
|
+
hash: hashMessage(message),
|
|
221
|
+
signature: signature,
|
|
222
|
+
});
|
|
223
|
+
const publicKeyHex = secp256k1PublicKey.startsWith("0x")
|
|
224
|
+
? secp256k1PublicKey.slice(2)
|
|
225
|
+
: secp256k1PublicKey;
|
|
226
|
+
const publicKeyBytes = uint8ArrayFromHexString(publicKeyHex);
|
|
227
|
+
const publicKeyBytesCompressed = compressRawPublicKey(publicKeyBytes);
|
|
228
|
+
return uint8ArrayToHexString(publicKeyBytesCompressed);
|
|
229
|
+
};
|
|
230
|
+
/**
|
|
231
|
+
* Validates and casts a WalletRpcProvider to an EIP-1193 provider.
|
|
232
|
+
*
|
|
233
|
+
* @param p - The wallet RPC provider.
|
|
234
|
+
* @returns A valid EIP1193 provider.
|
|
235
|
+
* @throws If the provider does not implement the request() method.
|
|
236
|
+
*/
|
|
237
|
+
const asEip1193 = (p) => {
|
|
238
|
+
if (p.provider && typeof p.provider.request === "function") {
|
|
239
|
+
return p.provider;
|
|
240
|
+
}
|
|
241
|
+
throw new Error("Expected an EIP-1193 provider (Ethereum wallet)");
|
|
242
|
+
};
|
|
243
|
+
|
|
244
|
+
export { BaseEthereumWallet, EthereumWallet };
|
|
245
|
+
//# sourceMappingURL=ethereum.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ethereum.mjs","sources":["../../../../src/__wallet__/web/native/ethereum.ts"],"sourcesContent":[null],"names":[],"mappings":";;;;;;AAyBA;;;;;;;AAOG;MACmB,kBAAkB,CAAA;AAAxC,IAAA,WAAA,GAAA;AACW,QAAA,IAAA,CAAA,aAAa,GAAG,mBAAmB,CAAC,QAAQ;AAgBrD;;;;;AAKG;AACH,QAAA,IAAA,CAAA,YAAY,GAAG,OAAO,QAAwB,KAAqB;YACjE,MAAM,OAAO,GAAG,gBAAgB;AAChC,YAAA,MAAM,SAAS,GAAG,MAAM,IAAI,CAAC,IAAI,CAC/B,OAAO,EACP,QAAQ,EACR,UAAU,CAAC,WAAW,CACvB;AACD,YAAA,OAAO,sBAAsB,CAAC,SAAS,EAAE,OAAO,CAAC;AACnD,SAAC;AAED;;;;AAIG;QACH,IAAY,CAAA,YAAA,GAAG,YAAsC;YACnD,MAAM,UAAU,GAAqB,EAAE;YAOvC,MAAM,gBAAgB,GAAoB,EAAE;AAE5C,YAAA,MAAM,OAAO,GAAG,CAAC,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AAkB,CAAC,KAAK,CAAC,CAAC;UAC1B,kBAAkB;AAEtB,IAAA,MAAM,cAAc,GAAG,uBAAuB,CAAC,YAAY,CAAC;AAC5D,IAAA,MAAM,wBAAwB,GAAG,oBAAoB,CAAC,cAAc,CAAC;AAErE,IAAA,OAAO,qBAAqB,CAAC,wBAAwB,CAAC;AACxD,CAAC;AAED;;;;;;AAMG;AACH,MAAM,SAAS,GAAG,CAAC,CAAiB,KAAqB;AACvD,IAAA,IAAI,CAAC,CAAC,QAAQ,IAAI,OAAQ,CAAC,CAAC,QAAgB,CAAC,OAAO,KAAK,UAAU,EAAE;QACnE,OAAO,CAAC,CAAC,QAA2B;;AAEtC,IAAA,MAAM,IAAI,KAAK,CAAC,iDAAiD,CAAC;AACpE,CAAC;;;;"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { SignIntent, SolanaWalletInterface, WalletInterfaceType, WalletProvider } from "@types";
|
|
2
|
+
/**
|
|
3
|
+
* Abstract class representing a base Solana wallet.
|
|
4
|
+
*/
|
|
5
|
+
export declare abstract class BaseSolanaWallet implements SolanaWalletInterface {
|
|
6
|
+
readonly interfaceType = WalletInterfaceType.Solana;
|
|
7
|
+
abstract sign(message: string | Uint8Array, provider: WalletProvider, intent: SignIntent): Promise<string>;
|
|
8
|
+
getPublicKey: (provider: WalletProvider) => Promise<string>;
|
|
9
|
+
getProviders: () => Promise<WalletProvider[]>;
|
|
10
|
+
connectWalletAccount: (provider: WalletProvider) => Promise<void>;
|
|
11
|
+
disconnectWalletAccount: (provider: WalletProvider) => Promise<void>;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* SolanaWallet class implementing signing logic for Solana wallets.
|
|
15
|
+
*/
|
|
16
|
+
export declare class SolanaWallet extends BaseSolanaWallet {
|
|
17
|
+
sign: (message: string, provider: WalletProvider, intent: SignIntent) => Promise<string>;
|
|
18
|
+
}
|
|
19
|
+
//# sourceMappingURL=solana.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"solana.d.ts","sourceRoot":"","sources":["../../../../src/__wallet__/web/native/solana.ts"],"names":[],"mappings":"AAQA,OAAO,EAEL,UAAU,EACV,qBAAqB,EACrB,mBAAmB,EACnB,cAAc,EAEf,MAAM,QAAQ,CAAC;AA4ChB;;GAEG;AACH,8BAAsB,gBAAiB,YAAW,qBAAqB;IACrE,QAAQ,CAAC,aAAa,8BAA8B;IAEpD,QAAQ,CAAC,IAAI,CACX,OAAO,EAAE,MAAM,GAAG,UAAU,EAC5B,QAAQ,EAAE,cAAc,EACxB,MAAM,EAAE,UAAU,GACjB,OAAO,CAAC,MAAM,CAAC;IAElB,YAAY,aAAoB,cAAc,KAAG,QAAQ,MAAM,CAAC,CAS9D;IAEF,YAAY,QAAa,QAAQ,cAAc,EAAE,CAAC,CA8BhD;IAEF,oBAAoB,aAAoB,cAAc,KAAG,QAAQ,IAAI,CAAC,CAGpE;IAEF,uBAAuB,aAAoB,cAAc,KAAG,QAAQ,IAAI,CAAC,CAUvE;CACH;AAED;;GAEG;AACH,qBAAa,YAAa,SAAQ,gBAAgB;IAChD,IAAI,YACO,MAAM,YACL,cAAc,UAChB,UAAU,KACjB,QAAQ,MAAM,CAAC,CA8DhB;CACH"}
|