@aztec/wallet-sdk 0.0.1-commit.fffb133c → 0.0.1-private.d0bedffd

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.
@@ -109,7 +109,7 @@ export class ExtensionWallet {
109
109
  sharedKey: CryptoKey,
110
110
  chainInfo: ChainInfo,
111
111
  appId: string,
112
- ): Wallet {
112
+ ): ExtensionWallet {
113
113
  const wallet = new ExtensionWallet(chainInfo, appId, extensionId, port, sharedKey);
114
114
 
115
115
  // Set up message handler for encrypted responses and unencrypted control messages
@@ -127,8 +127,10 @@ export class ExtensionWallet {
127
127
  wallet.port.start();
128
128
 
129
129
  return new Proxy(wallet, {
130
- get: (target, prop) => {
131
- if (schemaHasMethod(WalletSchema, prop.toString())) {
130
+ get: (target, prop, receiver) => {
131
+ if (prop === 'asWallet') {
132
+ return () => receiver as unknown as Wallet;
133
+ } else if (schemaHasMethod(WalletSchema, prop.toString())) {
132
134
  return async (...args: unknown[]) => {
133
135
  const result = await target.postMessage({
134
136
  type: prop.toString() as keyof FunctionsOf<Wallet>,
@@ -140,7 +142,13 @@ export class ExtensionWallet {
140
142
  return target[prop as keyof ExtensionWallet];
141
143
  }
142
144
  },
143
- }) as unknown as Wallet;
145
+ });
146
+ }
147
+
148
+ asWallet(): Wallet {
149
+ // Overridden by the proxy in create() to return the proxy itself.
150
+ // This body is never reached when accessed through create().
151
+ return this as unknown as Wallet;
144
152
  }
145
153
 
146
154
  /**
@@ -116,18 +116,18 @@ export interface WalletProvider {
116
116
  * After calling this, the wallet returned from confirm() should no longer be used.
117
117
  * @returns A promise that resolves when disconnection is complete
118
118
  */
119
- disconnect?(): Promise<void>;
119
+ disconnect(): Promise<void>;
120
120
  /**
121
121
  * Registers a callback to be invoked when the wallet disconnects unexpectedly.
122
122
  * @param callback - Function to call when wallet disconnects
123
123
  * @returns A function to unregister the callback
124
124
  */
125
- onDisconnect?(callback: ProviderDisconnectionCallback): () => void;
125
+ onDisconnect(callback: ProviderDisconnectionCallback): () => void;
126
126
  /**
127
127
  * Returns whether the provider's wallet connection has been disconnected.
128
128
  * @returns true if the wallet is no longer connected
129
129
  */
130
- isDisconnected?(): boolean;
130
+ isDisconnected(): boolean;
131
131
  }
132
132
 
133
133
  /**
@@ -196,15 +196,14 @@ export class WalletManager {
196
196
  return {
197
197
  verificationHash: connection.info.verificationHash!,
198
198
  confirm: () => {
199
- return Promise.resolve(
200
- ExtensionWallet.create(
201
- connection.info.id,
202
- connection.port,
203
- connection.sharedKey,
204
- chainInfo,
205
- connectAppId,
206
- ),
199
+ extensionWallet = ExtensionWallet.create(
200
+ connection.info.id,
201
+ connection.port,
202
+ connection.sharedKey,
203
+ chainInfo,
204
+ connectAppId,
207
205
  );
206
+ return Promise.resolve(extensionWallet.asWallet());
208
207
  },
209
208
  cancel: () => {
210
209
  // Send disconnect to terminate the session on the extension side
@@ -213,7 +212,6 @@ export class WalletManager {
213
212
  type: WalletMessageType.DISCONNECT,
214
213
  requestId: discoveredWallet.requestId,
215
214
  });
216
- // Don't close the port - allow retry with fresh key exchange
217
215
  },
218
216
  };
219
217
  },