@turnkey/core 1.0.0-beta.2 → 1.0.0-beta.4

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.
Files changed (77) hide show
  1. package/dist/__clients__/core.d.ts +75 -2
  2. package/dist/__clients__/core.d.ts.map +1 -1
  3. package/dist/__clients__/core.js +637 -503
  4. package/dist/__clients__/core.js.map +1 -1
  5. package/dist/__clients__/core.mjs +640 -506
  6. package/dist/__clients__/core.mjs.map +1 -1
  7. package/dist/__generated__/sdk-client-base.d.ts +1 -1
  8. package/dist/__generated__/sdk-client-base.d.ts.map +1 -1
  9. package/dist/__generated__/sdk-client-base.js +156 -250
  10. package/dist/__generated__/sdk-client-base.js.map +1 -1
  11. package/dist/__generated__/sdk-client-base.mjs +156 -250
  12. package/dist/__generated__/sdk-client-base.mjs.map +1 -1
  13. package/dist/__generated__/version.d.ts +1 -1
  14. package/dist/__generated__/version.js +1 -1
  15. package/dist/__generated__/version.mjs +1 -1
  16. package/dist/__types__/base.d.ts +1 -1
  17. package/dist/__wallet__/base.d.ts +11 -0
  18. package/dist/__wallet__/base.d.ts.map +1 -1
  19. package/dist/__wallet__/base.js +12 -1
  20. package/dist/__wallet__/base.js.map +1 -1
  21. package/dist/__wallet__/base.mjs +12 -1
  22. package/dist/__wallet__/base.mjs.map +1 -1
  23. package/dist/__wallet__/connector.d.ts +31 -4
  24. package/dist/__wallet__/connector.d.ts.map +1 -1
  25. package/dist/__wallet__/connector.js +35 -5
  26. package/dist/__wallet__/connector.js.map +1 -1
  27. package/dist/__wallet__/connector.mjs +35 -5
  28. package/dist/__wallet__/connector.mjs.map +1 -1
  29. package/dist/__wallet__/mobile/manager.d.ts +21 -5
  30. package/dist/__wallet__/mobile/manager.d.ts.map +1 -1
  31. package/dist/__wallet__/mobile/manager.js +28 -11
  32. package/dist/__wallet__/mobile/manager.js.map +1 -1
  33. package/dist/__wallet__/mobile/manager.mjs +28 -11
  34. package/dist/__wallet__/mobile/manager.mjs.map +1 -1
  35. package/dist/__wallet__/stamper.d.ts +73 -2
  36. package/dist/__wallet__/stamper.d.ts.map +1 -1
  37. package/dist/__wallet__/stamper.js +79 -13
  38. package/dist/__wallet__/stamper.js.map +1 -1
  39. package/dist/__wallet__/stamper.mjs +79 -13
  40. package/dist/__wallet__/stamper.mjs.map +1 -1
  41. package/dist/__wallet__/wallet-connect/base.d.ts +99 -19
  42. package/dist/__wallet__/wallet-connect/base.d.ts.map +1 -1
  43. package/dist/__wallet__/wallet-connect/base.js +172 -75
  44. package/dist/__wallet__/wallet-connect/base.js.map +1 -1
  45. package/dist/__wallet__/wallet-connect/base.mjs +172 -75
  46. package/dist/__wallet__/wallet-connect/base.mjs.map +1 -1
  47. package/dist/__wallet__/wallet-connect/client.d.ts +22 -14
  48. package/dist/__wallet__/wallet-connect/client.d.ts.map +1 -1
  49. package/dist/__wallet__/wallet-connect/client.js +22 -14
  50. package/dist/__wallet__/wallet-connect/client.js.map +1 -1
  51. package/dist/__wallet__/wallet-connect/client.mjs +22 -14
  52. package/dist/__wallet__/wallet-connect/client.mjs.map +1 -1
  53. package/dist/__wallet__/web/manager.d.ts +20 -12
  54. package/dist/__wallet__/web/manager.d.ts.map +1 -1
  55. package/dist/__wallet__/web/manager.js +29 -21
  56. package/dist/__wallet__/web/manager.js.map +1 -1
  57. package/dist/__wallet__/web/manager.mjs +29 -21
  58. package/dist/__wallet__/web/manager.mjs.map +1 -1
  59. package/dist/__wallet__/web/native/ethereum.d.ts +45 -11
  60. package/dist/__wallet__/web/native/ethereum.d.ts.map +1 -1
  61. package/dist/__wallet__/web/native/ethereum.js +58 -17
  62. package/dist/__wallet__/web/native/ethereum.js.map +1 -1
  63. package/dist/__wallet__/web/native/ethereum.mjs +58 -17
  64. package/dist/__wallet__/web/native/ethereum.mjs.map +1 -1
  65. package/dist/__wallet__/web/native/solana.d.ts +56 -3
  66. package/dist/__wallet__/web/native/solana.d.ts.map +1 -1
  67. package/dist/__wallet__/web/native/solana.js +95 -36
  68. package/dist/__wallet__/web/native/solana.js.map +1 -1
  69. package/dist/__wallet__/web/native/solana.mjs +95 -36
  70. package/dist/__wallet__/web/native/solana.mjs.map +1 -1
  71. package/dist/utils.d.ts +24 -1
  72. package/dist/utils.d.ts.map +1 -1
  73. package/dist/utils.js +54 -0
  74. package/dist/utils.js.map +1 -1
  75. package/dist/utils.mjs +54 -1
  76. package/dist/utils.mjs.map +1 -1
  77. package/package.json +7 -7
@@ -10,15 +10,18 @@ var encoding = require('@turnkey/encoding');
10
10
  * Abstract base class for Ethereum wallet implementations.
11
11
  *
12
12
  * Provides shared logic for:
13
- * - Provider discovery via EIP-6963
14
- * - Connecting and disconnecting wallets
15
- * - Recovering compressed public keys
13
+ * - Provider discovery via EIP-6963 (request/announce events)
14
+ * - Connecting/disconnecting via EIP-1193
15
+ * - Recovering compressed secp256k1 public keys from EIP-191 signatures
16
16
  */
17
17
  class BaseEthereumWallet {
18
18
  constructor() {
19
19
  this.interfaceType = base.WalletInterfaceType.Ethereum;
20
20
  /**
21
- * Retrieves the compressed public key by signing a known message.
21
+ * Retrieves the compressed secp256k1 public key by signing a known message.
22
+ *
23
+ * - Signs the fixed string "GET_PUBLIC_KEY" (EIP-191) and recovers the key.
24
+ * - Returns the compressed public key as a hex string (no 0x prefix).
22
25
  *
23
26
  * @param provider - The wallet provider to use.
24
27
  * @returns A promise that resolves to the compressed public key (hex-encoded).
@@ -31,6 +34,11 @@ class BaseEthereumWallet {
31
34
  /**
32
35
  * Discovers EIP-1193 providers using the EIP-6963 standard.
33
36
  *
37
+ * - Dispatches "eip6963:requestProvider" and listens for "eip6963:announceProvider".
38
+ * - For each discovered provider, attempts to read `eth_accounts` and `eth_chainId`
39
+ * (silently ignored if unavailable), defaulting to chainId "0x1".
40
+ * - Returns providers discovered during this discovery cycle; may be empty.
41
+ *
34
42
  * @returns A promise that resolves to a list of available wallet providers.
35
43
  */
36
44
  this.getProviders = async () => {
@@ -75,20 +83,28 @@ class BaseEthereumWallet {
75
83
  return discovered;
76
84
  };
77
85
  /**
78
- * Ensures the wallet account is connected.
86
+ * Requests or verifies account connection via `eth_requestAccounts`.
87
+ *
88
+ * - If the wallet is already connected, resolves immediately (no prompt).
89
+ * - If not connected, the wallet will typically prompt the user to authorize.
79
90
  *
80
91
  * @param provider - The wallet provider to use.
81
- * @returns A promise that resolves once the account is connected.
92
+ * @returns A promise that resolves once at least one account is connected.
93
+ * @throws {Error} If the wallet returns no accounts after the request.
82
94
  */
83
95
  this.connectWalletAccount = async (provider) => {
84
96
  const wallet = asEip1193(provider);
85
97
  await getAccount(wallet);
86
98
  };
87
99
  /**
88
- * Disconnects the wallet account by revoking permissions.
100
+ * Attempts to disconnect the wallet by revoking `eth_accounts` permission.
101
+ *
102
+ * - Calls `wallet_revokePermissions` with `{ eth_accounts: {} }`.
103
+ * - Provider behavior is wallet-specific: some implement it, some ignore it,
104
+ * and others (e.g., Phantom) throw “method not supported”.
89
105
  *
90
106
  * @param provider - The wallet provider to disconnect.
91
- * @returns A promise that resolves once the permissions are revoked.
107
+ * @returns A promise that resolves once the request completes (or rejects if the provider errors).
92
108
  */
93
109
  this.disconnectWalletAccount = async (provider) => {
94
110
  const wallet = asEip1193(provider);
@@ -98,6 +114,18 @@ class BaseEthereumWallet {
98
114
  });
99
115
  };
100
116
  }
117
+ /**
118
+ * Switches to a new EVM chain, with add-then-switch fallback.
119
+ *
120
+ * - Tries `wallet_switchEthereumChain` first.
121
+ * - If the wallet returns error code 4902 (unknown chain):
122
+ * - If `chainOrId` is a string (hex chainId), throws and asks the caller to pass metadata.
123
+ * - If `chainOrId` is a `SwitchableChain`, calls `wallet_addEthereumChain` and then retries the switch.
124
+ *
125
+ * @param provider - The wallet provider to use.
126
+ * @param chainOrId - Hex chain ID string or full `SwitchableChain` metadata.
127
+ * @throws {Error} If provider is non-EVM, adding/switching fails, or metadata is missing.
128
+ */
101
129
  async switchChain(provider, chainOrId) {
102
130
  if (provider.chainInfo.namespace !== base.Chain.Ethereum) {
103
131
  throw new Error("Only EVM wallets can switch chains");
@@ -158,22 +186,28 @@ class EthereumWallet extends BaseEthereumWallet {
158
186
  /**
159
187
  * Signs a message or sends a transaction depending on intent.
160
188
  *
161
- * @param message - The message or raw transaction to be signed.
189
+ * - `SignMessage` `personal_sign` (hex signature).
190
+ * - `SignAndSendTransaction` → `eth_sendTransaction` (tx hash).
191
+ * - For transactions, `message` must be a raw tx that `Transaction.from(...)` can parse.
192
+ * - May prompt the user (account access, signing, or send).
193
+ *
194
+ * @param payload - The payload or raw transaction to be signed/sent.
162
195
  * @param provider - The wallet provider to use.
163
196
  * @param intent - Signing intent (SignMessage or SignAndSendTransaction).
164
197
  * @returns A promise that resolves to a hex string (signature or tx hash).
198
+ * @throws {Error} If the intent is unsupported or the wallet rejects the request.
165
199
  */
166
- this.sign = async (message, provider, intent) => {
200
+ this.sign = async (payload, provider, intent) => {
167
201
  const selectedProvider = asEip1193(provider);
168
202
  const account = await getAccount(selectedProvider);
169
203
  switch (intent) {
170
204
  case base.SignIntent.SignMessage:
171
205
  return await selectedProvider.request({
172
206
  method: "personal_sign",
173
- params: [message, account],
207
+ params: [payload, account],
174
208
  });
175
209
  case base.SignIntent.SignAndSendTransaction:
176
- const tx = ethers.Transaction.from(message);
210
+ const tx = ethers.Transaction.from(payload);
177
211
  const txParams = {
178
212
  from: account,
179
213
  to: tx.to?.toString(),
@@ -198,9 +232,11 @@ class EthereumWallet extends BaseEthereumWallet {
198
232
  /**
199
233
  * Retrieves the active Ethereum account from a provider.
200
234
  *
235
+ * - Calls `eth_requestAccounts` (usually no prompt).
236
+ *
201
237
  * @param provider - EIP-1193 compliant provider.
202
238
  * @returns A promise resolving to the connected Ethereum address.
203
- * @throws If no connected account is found.
239
+ * @throws {Error} If no connected account is found.
204
240
  */
205
241
  const getAccount = async (provider) => {
206
242
  const [connectedAccount] = await provider.request({
@@ -213,6 +249,9 @@ const getAccount = async (provider) => {
213
249
  /**
214
250
  * Recovers and compresses the public key from a signed message.
215
251
  *
252
+ * - Recovers the secp256k1 public key from an EIP-191 signature and compresses it.
253
+ * - Returns a hex string with no 0x prefix.
254
+ *
216
255
  * @param signature - The signature as a hex string.
217
256
  * @param message - The original signed message.
218
257
  * @returns A promise resolving to the compressed public key (hex-encoded).
@@ -230,11 +269,13 @@ const getCompressedPublicKey = async (signature, message) => {
230
269
  return encoding.uint8ArrayToHexString(publicKeyBytesCompressed);
231
270
  };
232
271
  /**
233
- * Validates and casts a WalletRpcProvider to an EIP-1193 provider.
272
+ * Validates and casts a `WalletProvider` to an EIP-1193 provider.
273
+ *
274
+ * - Expects `provider.request` to be a function.
234
275
  *
235
- * @param p - The wallet RPC provider.
236
- * @returns A valid EIP1193 provider.
237
- * @throws If the provider does not implement the request() method.
276
+ * @param p - The wallet provider to validate.
277
+ * @returns An EIP-1193 provider.
278
+ * @throws {Error} If the provider does not implement `request()`.
238
279
  */
239
280
  const asEip1193 = (p) => {
240
281
  if (p.provider && typeof p.provider.request === "function") {
@@ -1 +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;;;;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AI,EAAEC,gBAAW,CAAC,OAAO,CAAC;AAC1B,QAAA,SAAS,EAAE,SAAgB;AAC5B,KAAA,CAAC;AACF,IAAA,MAAM,YAAY,GAAG,kBAAkB,CAAC,UAAU,CAAC,IAAI;AACrD,UAAE,kBAAkB,CAAC,KAAK,CAAC,CAAC;UAC1B,kBAAkB;AAEtB,IAAA,MAAM,cAAc,GAAGC,gCAAuB,CAAC,YAAY,CAAC;AAC5D,IAAA,MAAM,wBAAwB,GAAGC,2BAAoB,CAAC,cAAc,CAAC;AAErE,IAAA,OAAOC,8BAAqB,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;;;;;"}
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;;;;;;;;AAQG;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,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OAAe,KACI;AACnB,IAAA,MAAM,kBAAkB,GAAG,MAAMC,qBAAgB,CAAC;AAChD,QAAA,IAAI,EAAEC,gBAAW,CAAC,OAAO,CAAC;AAC1B,QAAA,SAAS,EAAE,SAAgB;AAC5B,KAAA,CAAC;AACF,IAAA,MAAM,YAAY,GAAG,kBAAkB,CAAC,UAAU,CAAC,IAAI;AACrD,UAAE,kBAAkB,CAAC,KAAK,CAAC,CAAC;UAC1B,kBAAkB;AAEtB,IAAA,MAAM,cAAc,GAAGC,gCAAuB,CAAC,YAAY,CAAC;AAC5D,IAAA,MAAM,wBAAwB,GAAGC,2BAAoB,CAAC,cAAc,CAAC;AAErE,IAAA,OAAOC,8BAAqB,CAAC,wBAAwB,CAAC;AACxD,CAAC;AAED;;;;;;;;AAQG;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;;;;;"}
@@ -8,15 +8,18 @@ import { uint8ArrayFromHexString, uint8ArrayToHexString } from '@turnkey/encodin
8
8
  * Abstract base class for Ethereum wallet implementations.
9
9
  *
10
10
  * Provides shared logic for:
11
- * - Provider discovery via EIP-6963
12
- * - Connecting and disconnecting wallets
13
- * - Recovering compressed public keys
11
+ * - Provider discovery via EIP-6963 (request/announce events)
12
+ * - Connecting/disconnecting via EIP-1193
13
+ * - Recovering compressed secp256k1 public keys from EIP-191 signatures
14
14
  */
15
15
  class BaseEthereumWallet {
16
16
  constructor() {
17
17
  this.interfaceType = WalletInterfaceType.Ethereum;
18
18
  /**
19
- * Retrieves the compressed public key by signing a known message.
19
+ * Retrieves the compressed secp256k1 public key by signing a known message.
20
+ *
21
+ * - Signs the fixed string "GET_PUBLIC_KEY" (EIP-191) and recovers the key.
22
+ * - Returns the compressed public key as a hex string (no 0x prefix).
20
23
  *
21
24
  * @param provider - The wallet provider to use.
22
25
  * @returns A promise that resolves to the compressed public key (hex-encoded).
@@ -29,6 +32,11 @@ class BaseEthereumWallet {
29
32
  /**
30
33
  * Discovers EIP-1193 providers using the EIP-6963 standard.
31
34
  *
35
+ * - Dispatches "eip6963:requestProvider" and listens for "eip6963:announceProvider".
36
+ * - For each discovered provider, attempts to read `eth_accounts` and `eth_chainId`
37
+ * (silently ignored if unavailable), defaulting to chainId "0x1".
38
+ * - Returns providers discovered during this discovery cycle; may be empty.
39
+ *
32
40
  * @returns A promise that resolves to a list of available wallet providers.
33
41
  */
34
42
  this.getProviders = async () => {
@@ -73,20 +81,28 @@ class BaseEthereumWallet {
73
81
  return discovered;
74
82
  };
75
83
  /**
76
- * Ensures the wallet account is connected.
84
+ * Requests or verifies account connection via `eth_requestAccounts`.
85
+ *
86
+ * - If the wallet is already connected, resolves immediately (no prompt).
87
+ * - If not connected, the wallet will typically prompt the user to authorize.
77
88
  *
78
89
  * @param provider - The wallet provider to use.
79
- * @returns A promise that resolves once the account is connected.
90
+ * @returns A promise that resolves once at least one account is connected.
91
+ * @throws {Error} If the wallet returns no accounts after the request.
80
92
  */
81
93
  this.connectWalletAccount = async (provider) => {
82
94
  const wallet = asEip1193(provider);
83
95
  await getAccount(wallet);
84
96
  };
85
97
  /**
86
- * Disconnects the wallet account by revoking permissions.
98
+ * Attempts to disconnect the wallet by revoking `eth_accounts` permission.
99
+ *
100
+ * - Calls `wallet_revokePermissions` with `{ eth_accounts: {} }`.
101
+ * - Provider behavior is wallet-specific: some implement it, some ignore it,
102
+ * and others (e.g., Phantom) throw “method not supported”.
87
103
  *
88
104
  * @param provider - The wallet provider to disconnect.
89
- * @returns A promise that resolves once the permissions are revoked.
105
+ * @returns A promise that resolves once the request completes (or rejects if the provider errors).
90
106
  */
91
107
  this.disconnectWalletAccount = async (provider) => {
92
108
  const wallet = asEip1193(provider);
@@ -96,6 +112,18 @@ class BaseEthereumWallet {
96
112
  });
97
113
  };
98
114
  }
115
+ /**
116
+ * Switches to a new EVM chain, with add-then-switch fallback.
117
+ *
118
+ * - Tries `wallet_switchEthereumChain` first.
119
+ * - If the wallet returns error code 4902 (unknown chain):
120
+ * - If `chainOrId` is a string (hex chainId), throws and asks the caller to pass metadata.
121
+ * - If `chainOrId` is a `SwitchableChain`, calls `wallet_addEthereumChain` and then retries the switch.
122
+ *
123
+ * @param provider - The wallet provider to use.
124
+ * @param chainOrId - Hex chain ID string or full `SwitchableChain` metadata.
125
+ * @throws {Error} If provider is non-EVM, adding/switching fails, or metadata is missing.
126
+ */
99
127
  async switchChain(provider, chainOrId) {
100
128
  if (provider.chainInfo.namespace !== Chain.Ethereum) {
101
129
  throw new Error("Only EVM wallets can switch chains");
@@ -156,22 +184,28 @@ class EthereumWallet extends BaseEthereumWallet {
156
184
  /**
157
185
  * Signs a message or sends a transaction depending on intent.
158
186
  *
159
- * @param message - The message or raw transaction to be signed.
187
+ * - `SignMessage` `personal_sign` (hex signature).
188
+ * - `SignAndSendTransaction` → `eth_sendTransaction` (tx hash).
189
+ * - For transactions, `message` must be a raw tx that `Transaction.from(...)` can parse.
190
+ * - May prompt the user (account access, signing, or send).
191
+ *
192
+ * @param payload - The payload or raw transaction to be signed/sent.
160
193
  * @param provider - The wallet provider to use.
161
194
  * @param intent - Signing intent (SignMessage or SignAndSendTransaction).
162
195
  * @returns A promise that resolves to a hex string (signature or tx hash).
196
+ * @throws {Error} If the intent is unsupported or the wallet rejects the request.
163
197
  */
164
- this.sign = async (message, provider, intent) => {
198
+ this.sign = async (payload, provider, intent) => {
165
199
  const selectedProvider = asEip1193(provider);
166
200
  const account = await getAccount(selectedProvider);
167
201
  switch (intent) {
168
202
  case SignIntent.SignMessage:
169
203
  return await selectedProvider.request({
170
204
  method: "personal_sign",
171
- params: [message, account],
205
+ params: [payload, account],
172
206
  });
173
207
  case SignIntent.SignAndSendTransaction:
174
- const tx = Transaction.from(message);
208
+ const tx = Transaction.from(payload);
175
209
  const txParams = {
176
210
  from: account,
177
211
  to: tx.to?.toString(),
@@ -196,9 +230,11 @@ class EthereumWallet extends BaseEthereumWallet {
196
230
  /**
197
231
  * Retrieves the active Ethereum account from a provider.
198
232
  *
233
+ * - Calls `eth_requestAccounts` (usually no prompt).
234
+ *
199
235
  * @param provider - EIP-1193 compliant provider.
200
236
  * @returns A promise resolving to the connected Ethereum address.
201
- * @throws If no connected account is found.
237
+ * @throws {Error} If no connected account is found.
202
238
  */
203
239
  const getAccount = async (provider) => {
204
240
  const [connectedAccount] = await provider.request({
@@ -211,6 +247,9 @@ const getAccount = async (provider) => {
211
247
  /**
212
248
  * Recovers and compresses the public key from a signed message.
213
249
  *
250
+ * - Recovers the secp256k1 public key from an EIP-191 signature and compresses it.
251
+ * - Returns a hex string with no 0x prefix.
252
+ *
214
253
  * @param signature - The signature as a hex string.
215
254
  * @param message - The original signed message.
216
255
  * @returns A promise resolving to the compressed public key (hex-encoded).
@@ -228,11 +267,13 @@ const getCompressedPublicKey = async (signature, message) => {
228
267
  return uint8ArrayToHexString(publicKeyBytesCompressed);
229
268
  };
230
269
  /**
231
- * Validates and casts a WalletRpcProvider to an EIP-1193 provider.
270
+ * Validates and casts a `WalletProvider` to an EIP-1193 provider.
271
+ *
272
+ * - Expects `provider.request` to be a function.
232
273
  *
233
- * @param p - The wallet RPC provider.
234
- * @returns A valid EIP1193 provider.
235
- * @throws If the provider does not implement the request() method.
274
+ * @param p - The wallet provider to validate.
275
+ * @returns An EIP-1193 provider.
276
+ * @throws {Error} If the provider does not implement `request()`.
236
277
  */
237
278
  const asEip1193 = (p) => {
238
279
  if (p.provider && typeof p.provider.request === "function") {
@@ -1 +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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,EAAE,qBAAqB;AAC9B,KAAA,CAAC;AACF,IAAA,IAAI,CAAC,gBAAgB;AAAE,QAAA,MAAM,IAAI,KAAK,CAAC,4BAA4B,CAAC;AACpE,IAAA,OAAO,gBAAgB;AACzB,CAAC;AAED;;;;;;;;;AASG;AACH,MAAM,sBAAsB,GAAG,OAC7B,SAAiB,EACjB,OAAe,KACI;AACnB,IAAA,MAAM,kBAAkB,GAAG,MAAM,gBAAgB,CAAC;AAChD,QAAA,IAAI,EAAE,WAAW,CAAC,OAAO,CAAC;AAC1B,QAAA,SAAS,EAAE,SAAgB;AAC5B,KAAA,CAAC;AACF,IAAA,MAAM,YAAY,GAAG,kBAAkB,CAAC,UAAU,CAAC,IAAI;AACrD,UAAE,kBAAkB,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;;;;;;;;AAQG;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;;;;"}
@@ -1,19 +1,72 @@
1
1
  import { SignIntent, SolanaWalletInterface, WalletInterfaceType, WalletProvider } from "@types";
2
2
  /**
3
- * Abstract class representing a base Solana wallet.
3
+ * Abstract base class for Solana wallet implementations using Wallet Standard.
4
+ *
5
+ * Provides shared logic for:
6
+ * - Provider discovery via `@wallet-standard/app` (`getWallets()`).
7
+ * - Connecting via `standard:connect` and disconnecting via `standard:disconnect`.
8
+ * - Public key retrieval from the wallet's account address (base58 → hex).
4
9
  */
5
10
  export declare abstract class BaseSolanaWallet implements SolanaWalletInterface {
6
11
  readonly interfaceType = WalletInterfaceType.Solana;
7
12
  abstract sign(message: string | Uint8Array, provider: WalletProvider, intent: SignIntent): Promise<string>;
13
+ /**
14
+ * Retrieves the ed25519 public key for the active account as hex (no 0x prefix).
15
+ *
16
+ * - Ensures the wallet is connected (calls `standard:connect` if needed).
17
+ * - Decodes the Wallet Standard account address (base58) to raw bytes.
18
+ *
19
+ * @param provider - The wallet provider to use.
20
+ * @returns Hex-encoded ed25519 public key (no 0x prefix).
21
+ * @throws {Error} If no account is available.
22
+ */
8
23
  getPublicKey: (provider: WalletProvider) => Promise<string>;
24
+ /**
25
+ * Discovers Solana-capable Wallet Standard providers.
26
+ *
27
+ * - Uses `getWallets().get()` and filters wallets with at least one `chains` entry
28
+ * starting with `"solana:"`.
29
+ * - For each wallet, collects branding info and any currently connected addresses.
30
+ *
31
+ * @returns A list of discovered Solana `WalletProvider`s (may be empty).
32
+ */
9
33
  getProviders: () => Promise<WalletProvider[]>;
34
+ /**
35
+ * Connects the wallet account, prompting the user if necessary.
36
+ *
37
+ * - Calls `standard:connect` only if no accounts are present. This will prompt the user to connect their wallet.
38
+ *
39
+ * @param provider - The wallet provider to connect.
40
+ * @returns A promise that resolves once the wallet has ≥ 1 account.
41
+ * @throws {Error} If the wallet does not implement `standard:connect`.
42
+ */
10
43
  connectWalletAccount: (provider: WalletProvider) => Promise<void>;
44
+ /**
45
+ * Disconnects the wallet account using Wallet Standard.
46
+ *
47
+ * - Calls `standard:disconnect` if implemented.
48
+ * - Throws if the wallet does not implement `standard:disconnect`.
49
+ *
50
+ * @param provider - The wallet provider to disconnect.
51
+ * @returns A promise that resolves once the wallet disconnects.
52
+ * @throws {Error} If `standard:disconnect` is not supported by the wallet.
53
+ */
11
54
  disconnectWalletAccount: (provider: WalletProvider) => Promise<void>;
12
55
  }
13
56
  /**
14
- * SolanaWallet class implementing signing logic for Solana wallets.
57
+ * Signs a message or transaction with the connected Solana wallet.
58
+ *
59
+ * - Ensures the wallet is connected (may prompt via `standard:connect` if its not).
60
+ * - `SignMessage` → `solana:signMessage` (returns hex signature).
61
+ * - `SignTransaction` → `solana:signTransaction` (returns hex signature).
62
+ *
63
+ * @param payload - UTF-8 string (for message) or hex string (for transaction bytes).
64
+ * @param provider - The wallet provider to use.
65
+ * @param intent - The signing intent.
66
+ * @returns Hex-encoded signature (no 0x prefix).
67
+ * @throws {Error} If the provider lacks required features or intent is unsupported.
15
68
  */
16
69
  export declare class SolanaWallet extends BaseSolanaWallet {
17
- sign: (message: string, provider: WalletProvider, intent: SignIntent) => Promise<string>;
70
+ sign: (payload: string, provider: WalletProvider, intent: SignIntent) => Promise<string>;
18
71
  }
19
72
  //# sourceMappingURL=solana.d.ts.map
@@ -1 +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"}
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;AAEhB;;;;;;;GAOG;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;;;;;;;;;OASG;IACH,YAAY,aAAoB,cAAc,KAAG,QAAQ,MAAM,CAAC,CAS9D;IAEF;;;;;;;;OAQG;IACH,YAAY,QAAa,QAAQ,cAAc,EAAE,CAAC,CA8BhD;IAEF;;;;;;;;OAQG;IACH,oBAAoB,aAAoB,cAAc,KAAG,QAAQ,IAAI,CAAC,CAGpE;IAEF;;;;;;;;;OASG;IACH,uBAAuB,aAAoB,cAAc,KAAG,QAAQ,IAAI,CAAC,CAUvE;CACH;AAED;;;;;;;;;;;;GAYG;AACH,qBAAa,YAAa,SAAQ,gBAAgB;IAChD,IAAI,YACO,MAAM,YACL,cAAc,UAChB,UAAU,KACjB,QAAQ,MAAM,CAAC,CA8DhB;CACH"}
@@ -6,43 +6,26 @@ var encoding = require('@turnkey/encoding');
6
6
  var base = require('../../../__types__/base.js');
7
7
 
8
8
  /**
9
- * Casts a WalletRpcProvider to a Wallet Standard Solana provider.
9
+ * Abstract base class for Solana wallet implementations using Wallet Standard.
10
10
  *
11
- * @param p - The wallet provider to cast.
12
- * @returns The casted Wallet Standard wallet.
13
- * @throws If the provider is not a Wallet Standard Solana wallet.
14
- */
15
- const asSolana = (p) => {
16
- if (p.provider &&
17
- "features" in p.provider &&
18
- "solana:signMessage" in p.provider.features) {
19
- return p.provider;
20
- }
21
- throw new Error("Expected a Wallet-Standard provider (Solana wallet)");
22
- };
23
- /**
24
- * Connects the given Solana wallet account.
25
- *
26
- * @param w - The wallet to connect.
27
- * @returns A promise that resolves once the wallet is connected.
28
- * @throws If the wallet does not support standard:connect.
29
- */
30
- const connectAccount = async (w) => {
31
- if (w.accounts.length)
32
- return;
33
- const stdConnect = w.features["standard:connect"];
34
- if (stdConnect) {
35
- await stdConnect.connect();
36
- return;
37
- }
38
- throw new Error("Wallet is not connected and does not implement standard:connect");
39
- };
40
- /**
41
- * Abstract class representing a base Solana wallet.
11
+ * Provides shared logic for:
12
+ * - Provider discovery via `@wallet-standard/app` (`getWallets()`).
13
+ * - Connecting via `standard:connect` and disconnecting via `standard:disconnect`.
14
+ * - Public key retrieval from the wallet's account address (base58 → hex).
42
15
  */
43
16
  class BaseSolanaWallet {
44
17
  constructor() {
45
18
  this.interfaceType = base.WalletInterfaceType.Solana;
19
+ /**
20
+ * Retrieves the ed25519 public key for the active account as hex (no 0x prefix).
21
+ *
22
+ * - Ensures the wallet is connected (calls `standard:connect` if needed).
23
+ * - Decodes the Wallet Standard account address (base58) to raw bytes.
24
+ *
25
+ * @param provider - The wallet provider to use.
26
+ * @returns Hex-encoded ed25519 public key (no 0x prefix).
27
+ * @throws {Error} If no account is available.
28
+ */
46
29
  this.getPublicKey = async (provider) => {
47
30
  const wallet = asSolana(provider);
48
31
  await connectAccount(wallet);
@@ -53,6 +36,15 @@ class BaseSolanaWallet {
53
36
  const rawBytes = bs58.decode(account.address);
54
37
  return encoding.uint8ArrayToHexString(rawBytes);
55
38
  };
39
+ /**
40
+ * Discovers Solana-capable Wallet Standard providers.
41
+ *
42
+ * - Uses `getWallets().get()` and filters wallets with at least one `chains` entry
43
+ * starting with `"solana:"`.
44
+ * - For each wallet, collects branding info and any currently connected addresses.
45
+ *
46
+ * @returns A list of discovered Solana `WalletProvider`s (may be empty).
47
+ */
56
48
  this.getProviders = async () => {
57
49
  const discovered = [];
58
50
  const walletsApi = app.getWallets();
@@ -80,10 +72,29 @@ class BaseSolanaWallet {
80
72
  }));
81
73
  return discovered;
82
74
  };
75
+ /**
76
+ * Connects the wallet account, prompting the user if necessary.
77
+ *
78
+ * - Calls `standard:connect` only if no accounts are present. This will prompt the user to connect their wallet.
79
+ *
80
+ * @param provider - The wallet provider to connect.
81
+ * @returns A promise that resolves once the wallet has ≥ 1 account.
82
+ * @throws {Error} If the wallet does not implement `standard:connect`.
83
+ */
83
84
  this.connectWalletAccount = async (provider) => {
84
85
  const wallet = asSolana(provider);
85
86
  await connectAccount(wallet);
86
87
  };
88
+ /**
89
+ * Disconnects the wallet account using Wallet Standard.
90
+ *
91
+ * - Calls `standard:disconnect` if implemented.
92
+ * - Throws if the wallet does not implement `standard:disconnect`.
93
+ *
94
+ * @param provider - The wallet provider to disconnect.
95
+ * @returns A promise that resolves once the wallet disconnects.
96
+ * @throws {Error} If `standard:disconnect` is not supported by the wallet.
97
+ */
87
98
  this.disconnectWalletAccount = async (provider) => {
88
99
  const wallet = asSolana(provider);
89
100
  const disconnectFeature = wallet.features["standard:disconnect"];
@@ -97,12 +108,22 @@ class BaseSolanaWallet {
97
108
  }
98
109
  }
99
110
  /**
100
- * SolanaWallet class implementing signing logic for Solana wallets.
111
+ * Signs a message or transaction with the connected Solana wallet.
112
+ *
113
+ * - Ensures the wallet is connected (may prompt via `standard:connect` if its not).
114
+ * - `SignMessage` → `solana:signMessage` (returns hex signature).
115
+ * - `SignTransaction` → `solana:signTransaction` (returns hex signature).
116
+ *
117
+ * @param payload - UTF-8 string (for message) or hex string (for transaction bytes).
118
+ * @param provider - The wallet provider to use.
119
+ * @param intent - The signing intent.
120
+ * @returns Hex-encoded signature (no 0x prefix).
121
+ * @throws {Error} If the provider lacks required features or intent is unsupported.
101
122
  */
102
123
  class SolanaWallet extends BaseSolanaWallet {
103
124
  constructor() {
104
125
  super(...arguments);
105
- this.sign = async (message, provider, intent) => {
126
+ this.sign = async (payload, provider, intent) => {
106
127
  const wallet = asSolana(provider);
107
128
  await connectAccount(wallet);
108
129
  const account = wallet.accounts[0];
@@ -113,7 +134,7 @@ class SolanaWallet extends BaseSolanaWallet {
113
134
  const signFeature = wallet.features["solana:signMessage"];
114
135
  if (!signFeature)
115
136
  throw new Error("Provider does not support solana:signMessage");
116
- const data = new TextEncoder().encode(message);
137
+ const data = new TextEncoder().encode(payload);
117
138
  const results = await signFeature.signMessage({
118
139
  account,
119
140
  message: data,
@@ -127,7 +148,7 @@ class SolanaWallet extends BaseSolanaWallet {
127
148
  const signFeature = wallet.features["solana:signTransaction"];
128
149
  if (!signFeature)
129
150
  throw new Error("Provider does not support solana:signTransaction");
130
- const data = encoding.uint8ArrayFromHexString(message);
151
+ const data = encoding.uint8ArrayFromHexString(payload);
131
152
  const results = await signFeature.signTransaction({
132
153
  account,
133
154
  transaction: data,
@@ -143,6 +164,44 @@ class SolanaWallet extends BaseSolanaWallet {
143
164
  };
144
165
  }
145
166
  }
167
+ /**
168
+ * Casts a WalletRpcProvider to a Wallet Standard Solana wallet.
169
+ *
170
+ * - Validates presence of the Wallet Standard `features` map and `solana:signMessage`.
171
+ * - Use this before calling Solana-specific features (signMessage, signTransaction, etc.).
172
+ *
173
+ * @param provider - The wallet provider to cast.
174
+ * @returns The Wallet Standard wallet object.
175
+ * @throws {Error} If the provider is not a Wallet Standard Solana wallet.
176
+ */
177
+ const asSolana = (provider) => {
178
+ if (provider.provider &&
179
+ "features" in provider.provider &&
180
+ "solana:signMessage" in provider.provider.features) {
181
+ return provider.provider;
182
+ }
183
+ throw new Error("Expected a Wallet-Standard provider (Solana wallet)");
184
+ };
185
+ /**
186
+ * Ensures the given Wallet Standard wallet has at least one connected account.
187
+ *
188
+ * - If accounts already exist, resolves immediately.
189
+ * - If not, attempts `standard:connect`, which may prompt the user.
190
+ *
191
+ * @param wallet - The Wallet Standard wallet to connect.
192
+ * @returns A promise that resolves once the wallet has ≥ 1 account.
193
+ * @throws {Error} If the wallet does not implement `standard:connect`.
194
+ */
195
+ const connectAccount = async (wallet) => {
196
+ if (wallet.accounts.length)
197
+ return;
198
+ const stdConnect = wallet.features["standard:connect"];
199
+ if (stdConnect) {
200
+ await stdConnect.connect();
201
+ return;
202
+ }
203
+ throw new Error("Wallet is not connected and does not implement standard:connect");
204
+ };
146
205
 
147
206
  exports.BaseSolanaWallet = BaseSolanaWallet;
148
207
  exports.SolanaWallet = SolanaWallet;