@meshconnect/uwc-bridge-parent 1.0.0 → 1.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.
@@ -1,8 +1,8 @@
1
1
  import * as Comlink from 'comlink'
2
- import type { WalletAdapter } from '@solana/wallet-adapter-base'
3
2
  import type { Wallet } from '@wallet-standard/base'
4
3
  import { getWallets } from '@wallet-standard/app'
5
4
  import { isWalletAdapterCompatibleStandardWallet } from '@solana/wallet-adapter-base'
5
+ import { Connection, Transaction, VersionedTransaction } from '@solana/web3.js'
6
6
  import { StandardWalletAdapter } from '@solana/wallet-standard-wallet-adapter-base'
7
7
 
8
8
  export interface EthereumProvider {
@@ -14,12 +14,30 @@ export interface EthereumProvider {
14
14
  removeListener?: (event: string, handler: (...args: any[]) => void) => void
15
15
  }
16
16
 
17
+ interface ExtendedStandardWalletAdapter extends StandardWalletAdapter {
18
+ customFunctions: (
19
+ | 'sendSerializedTransaction'
20
+ | 'signSerializedTransaction'
21
+ | 'signAllSerializedTransactions'
22
+ )[]
23
+ sendSerializedTransaction: (
24
+ transaction: ArrayBufferLike,
25
+ rpcUrl: string
26
+ ) => Promise<string>
27
+ signSerializedTransaction: (
28
+ transaction: ArrayBufferLike
29
+ ) => Promise<Error | Transaction>
30
+ signAllSerializedTransactions: (
31
+ transactions: ArrayBufferLike[]
32
+ ) => Promise<Error | Transaction[]>
33
+ }
34
+
17
35
  export interface WalletStandardInfo {
18
36
  uuid: string
19
37
  name: string
20
38
  chains: string[]
21
39
  features: string[]
22
- adapter: WalletAdapter | undefined
40
+ adapter: ExtendedStandardWalletAdapter | undefined
23
41
  }
24
42
 
25
43
  export interface EIP6963ProviderInfo {
@@ -169,12 +187,177 @@ export class BridgeParent {
169
187
  name: wallet.name,
170
188
  chains: (wallet.chains || []) as string[],
171
189
  features: Object.keys(wallet.features),
190
+ // Expect a TS error, as not all adapter properties are implemented
191
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
192
+ // @ts-ignore
172
193
  adapter: adapter
194
+ ? {
195
+ name: adapter.name,
196
+ url: adapter.url,
197
+ icon: adapter.icon,
198
+ readyState: adapter.readyState,
199
+ publicKey: Comlink.proxy({
200
+ get value() {
201
+ return adapter.publicKey
202
+ },
203
+ toBase58: async () => {
204
+ return adapter.publicKey?.toBase58()
205
+ },
206
+ toJSON: async () => {
207
+ return adapter.publicKey?.toJSON()
208
+ },
209
+ toBytes: async () => {
210
+ return adapter.publicKey?.toBytes()
211
+ },
212
+ toBuffer: async () => {
213
+ return adapter.publicKey?.toBuffer()
214
+ },
215
+ toString: async () => {
216
+ return adapter.publicKey?.toString()
217
+ }
218
+ }),
219
+ connecting: adapter.connecting,
220
+ connected: adapter.connected,
221
+ supportedTransactionVersions:
222
+ adapter.supportedTransactionVersions,
223
+ wallet: adapter.wallet,
224
+ standard: adapter.standard,
225
+ destroy: async () => await adapter.destroy(),
226
+ autoConnect: async () => await adapter.autoConnect(),
227
+ connect: async () => await adapter.connect(),
228
+ disconnect: async () => await adapter.disconnect(),
229
+ sendTransaction: async (transaction, connection, options) =>
230
+ await adapter.sendTransaction(
231
+ transaction,
232
+ connection,
233
+ options
234
+ ),
235
+ signTransaction: async transaction => {
236
+ return adapter.signTransaction !== undefined
237
+ ? await adapter.signTransaction(transaction)
238
+ : new Error('Adapter does not support signTransaction')
239
+ },
240
+ signAllTransactions: async transactions => {
241
+ return adapter.signAllTransactions !== undefined
242
+ ? await adapter.signAllTransactions(transactions)
243
+ : new Error('Adapter does not support signAllTransactions')
244
+ },
245
+ signMessage: async message => {
246
+ return adapter.signMessage !== undefined
247
+ ? await adapter.signMessage(message)
248
+ : new Error('Adapter does not support signMessage')
249
+ },
250
+ signIn: async input => {
251
+ return adapter.signIn !== undefined
252
+ ? await adapter.signIn(input)
253
+ : new Error('Adapter does not support signIn')
254
+ },
255
+ customFunctions: [
256
+ 'sendSerializedTransaction',
257
+ 'signAllSerializedTransactions',
258
+ 'signSerializedTransaction'
259
+ ],
260
+ sendSerializedTransaction: async (
261
+ transaction: ArrayBufferLike,
262
+ rpcUrl: string
263
+ ) => {
264
+ const connection = new Connection(rpcUrl)
265
+ const uint8Array = new Uint8Array(transaction)
266
+
267
+ // Try to deserialize as VersionedTransaction first
268
+ let deserializedTx: Transaction | VersionedTransaction
269
+ try {
270
+ deserializedTx =
271
+ VersionedTransaction.deserialize(uint8Array)
272
+ } catch {
273
+ // If that fails, try as legacy Transaction
274
+ try {
275
+ deserializedTx = Transaction.from(uint8Array)
276
+ } catch {
277
+ throw new Error(
278
+ 'Failed to deserialize transaction as either versioned or legacy format'
279
+ )
280
+ }
281
+ }
282
+
283
+ return await adapter.sendTransaction(
284
+ deserializedTx,
285
+ connection
286
+ )
287
+ },
288
+ signSerializedTransaction: async (
289
+ transaction: ArrayBufferLike
290
+ ) => {
291
+ if (adapter.signTransaction === undefined) {
292
+ return new Error('Adapter does not support signTransaction')
293
+ }
294
+
295
+ const uint8Array = new Uint8Array(transaction)
296
+
297
+ // Try to deserialize as VersionedTransaction first
298
+ let deserializedTx: Transaction | VersionedTransaction
299
+ try {
300
+ deserializedTx =
301
+ VersionedTransaction.deserialize(uint8Array)
302
+ } catch {
303
+ // If that fails, try as legacy Transaction
304
+ try {
305
+ deserializedTx = Transaction.from(uint8Array)
306
+ } catch {
307
+ return new Error(
308
+ 'Failed to deserialize transaction as either versioned or legacy format'
309
+ )
310
+ }
311
+ }
312
+
313
+ return await adapter.signTransaction(deserializedTx)
314
+ },
315
+ signAllSerializedTransactions: async (
316
+ transactions: ArrayBufferLike[]
317
+ ) => {
318
+ if (adapter.signAllTransactions === undefined) {
319
+ return new Error(
320
+ 'Adapter does not support signAllTransactions'
321
+ )
322
+ }
323
+
324
+ const deserializedTransactions: (
325
+ | Transaction
326
+ | VersionedTransaction
327
+ )[] = []
328
+
329
+ for (const transaction of transactions) {
330
+ const uint8Array = new Uint8Array(transaction)
331
+
332
+ // Try to deserialize as VersionedTransaction first
333
+ let deserializedTx: Transaction | VersionedTransaction
334
+ try {
335
+ deserializedTx =
336
+ VersionedTransaction.deserialize(uint8Array)
337
+ } catch {
338
+ // If that fails, try as legacy Transaction
339
+ try {
340
+ deserializedTx = Transaction.from(uint8Array)
341
+ } catch {
342
+ return new Error(
343
+ 'Failed to deserialize one or more transactions'
344
+ )
345
+ }
346
+ }
347
+
348
+ deserializedTransactions.push(deserializedTx)
349
+ }
350
+
351
+ return await adapter.signAllTransactions(
352
+ deserializedTransactions
353
+ )
354
+ }
355
+ }
356
+ : undefined
173
357
  })
174
358
  walletNames.add(wallet.name)
175
359
  }
176
360
  }
177
- // Removed CBW integration see https://github.com/FrontFin/universal-wallet-connector/pull/19
178
361
  return solanaWallets
179
362
  }
180
363