@tezos-x/octez.connect-core 5.0.3 → 5.0.5

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,6 +1,6 @@
1
1
  {
2
2
  "name": "@tezos-x/octez.connect-core",
3
- "version": "5.0.3",
3
+ "version": "5.0.5",
4
4
  "description": "This package contains internal methods that are used by both the dApp and wallet client.",
5
5
  "author": "Blockchain Infra <blockchain.infra@trili.tech>",
6
6
  "homepage": "https://octez-connect.tezos.com",
@@ -38,8 +38,8 @@
38
38
  "@stablelib/nacl": "^2.0.1",
39
39
  "@stablelib/utf8": "^2.1.0",
40
40
  "@stablelib/x25519-session": "^2.0.1",
41
- "@tezos-x/octez.connect-types": "5.0.3",
42
- "@tezos-x/octez.connect-utils": "5.0.3",
41
+ "@tezos-x/octez.connect-types": "5.0.5",
42
+ "@tezos-x/octez.connect-utils": "5.0.5",
43
43
  "broadcast-channel": "^7.3.0",
44
44
  "bs58check": "4.0.0"
45
45
  }
@@ -27,7 +27,14 @@ export declare abstract class Client extends BeaconClient {
27
27
  */
28
28
  protected requestCounter: number[];
29
29
  protected readonly matrixNodes: NodeDistributions;
30
- private transportListeners;
30
+ /**
31
+ * One subscription per transport type, together with the transport instance
32
+ * it is attached to. The instance is needed to detach: a replaced transport
33
+ * outlives the client's reference to it (`disconnect()` and
34
+ * `handleDisconnect()` only null the reference), so removing the listener
35
+ * from the *incoming* transport would leave the old one subscribed.
36
+ */
37
+ private readonly transportListeners;
31
38
  protected _transport: ExposedPromise<Transport<any>>;
32
39
  protected get transport(): Promise<Transport<any>>;
33
40
  /**
@@ -99,7 +106,24 @@ export declare abstract class Client extends BeaconClient {
99
106
  protected setTransport(transport?: Transport<any>): Promise<void>;
100
107
  protected addListener(transport: Transport<any>): Promise<void>;
101
108
  protected sendDisconnectToPeer(peer: PeerInfo, transport?: Transport<any>): Promise<void>;
102
- protected findPeer(publicKey?: string): Promise<PeerInfo | undefined>;
109
+ /**
110
+ * Look a peer up by the id the transport attached to a message, on the
111
+ * transport that delivered it.
112
+ *
113
+ * The transport is a parameter rather than a lookup because every caller
114
+ * already has one: a message can only have been delivered by a transport
115
+ * that exists. Reaching for `this.transport` instead parked every arrival
116
+ * between a disconnection and the next pairing -- setTransport(undefined)
117
+ * leaves `_transport` unsettled, so the await only returned once a later
118
+ * pairing resolved it, and the message was replayed into that connection.
119
+ *
120
+ * `connectionInfo.id` is the peer's public key over P2P, but the browser
121
+ * extension's id over postMessage, where the transport cannot tell which
122
+ * peer's key decrypted the message. Match either: only a postMessage
123
+ * pairing response carries an `extensionId`, so the fallback is inert for
124
+ * every other peer.
125
+ */
126
+ protected findPeer(id: string | undefined, transport: Transport<any>): Promise<PeerInfo | undefined>;
103
127
  private getLocalProtocolVersion;
104
128
  private extractPeerProtocolVersion;
105
129
  protected getPeerProtocolVersion(peer?: PeerInfo): number;
@@ -60,6 +60,13 @@ class Client extends BeaconClient_1.BeaconClient {
60
60
  * Stores the times when requests have been made to determine if the rate limit has been reached
61
61
  */
62
62
  this.requestCounter = [];
63
+ /**
64
+ * One subscription per transport type, together with the transport instance
65
+ * it is attached to. The instance is needed to detach: a replaced transport
66
+ * outlives the client's reference to it (`disconnect()` and
67
+ * `handleDisconnect()` only null the reference), so removing the listener
68
+ * from the *incoming* transport would leave the old one subscribed.
69
+ */
63
70
  this.transportListeners = new Map();
64
71
  this._transport = new octez_connect_utils_1.ExposedPromise();
65
72
  this.accountManager = new AccountManager_1.AccountManager(config.storage);
@@ -73,11 +80,12 @@ class Client extends BeaconClient_1.BeaconClient {
73
80
  if (!this.transportListeners.size) {
74
81
  return;
75
82
  }
76
- if (this._transport.isResolved()) {
77
- const transport = yield this.transport;
78
- yield Promise.all(Array.from(this.transportListeners.values()).map((listener) => transport.removeListener(listener)));
79
- this.transportListeners.clear();
80
- }
83
+ // Each subscription is removed from the transport it is attached to.
84
+ // Going through `this.transport` removed them all from whichever transport
85
+ // was active, and removed none when no transport was resolved -- the state
86
+ // `disconnect()` leaves behind.
87
+ yield Promise.all(Array.from(this.transportListeners.values()).map(({ transport, listener }) => transport.removeListener(listener)));
88
+ this.transportListeners.clear();
81
89
  });
82
90
  }
83
91
  /**
@@ -197,9 +205,12 @@ class Client extends BeaconClient_1.BeaconClient {
197
205
  destroy: { get: () => super.destroy }
198
206
  });
199
207
  return __awaiter(this, void 0, void 0, function* () {
208
+ // Subscriptions are detached from their own transports, so this no longer
209
+ // needs an active one -- after disconnect() there is none, and that is
210
+ // precisely when the orphaned subscriptions have to go.
211
+ yield this.cleanup();
200
212
  if (this._transport.isResolved()) {
201
213
  const transport = yield this.transport;
202
- yield this.cleanup();
203
214
  yield transport.disconnect();
204
215
  if (transport.type === octez_connect_types_1.TransportType.WALLETCONNECT) {
205
216
  yield transport.doClientCleanup(); // any because I cannot import the type definition
@@ -237,19 +248,25 @@ class Client extends BeaconClient_1.BeaconClient {
237
248
  // a single page dApp.
238
249
  // However, while running a multiple tabs setup, if one of the dApps disconnects
239
250
  // the others wont't recover until after a page refresh
240
- if (this.transportListeners.has(transport.type)) {
241
- yield transport.removeListener(this.transportListeners.get(transport.type));
251
+ // Detach the previous subscription from the transport it is actually
252
+ // attached to. Calling removeListener on the incoming transport, which never
253
+ // had it, left every replaced transport subscribed: they share the client's
254
+ // key pair, so each one kept decrypting wallet messages and routing them into
255
+ // handleResponse -- once per past connection.
256
+ const previous = this.transportListeners.get(transport.type);
257
+ if (previous) {
258
+ yield previous.transport.removeListener(previous.listener);
242
259
  }
243
260
  const subscription = (message, connectionInfo) => __awaiter(this, void 0, void 0, function* () {
244
261
  if (typeof message !== 'string') {
245
262
  return;
246
263
  }
247
- const peer = yield this.findPeer(connectionInfo.id);
264
+ const peer = yield this.findPeer(connectionInfo.id, transport);
248
265
  const protocolVersion = this.getPeerProtocolVersion(peer);
249
266
  const deserializedMessage = (yield new Serializer_1.Serializer(protocolVersion).deserialize(message));
250
267
  this.handleResponse(deserializedMessage, connectionInfo);
251
268
  });
252
- this.transportListeners.set(transport.type, subscription);
269
+ this.transportListeners.set(transport.type, { transport, listener: subscription });
253
270
  transport.addListener(subscription).catch((error) => logger.error('addListener', error));
254
271
  });
255
272
  }
@@ -267,14 +284,40 @@ class Client extends BeaconClient_1.BeaconClient {
267
284
  yield selectedTransport.send(payload, peer);
268
285
  });
269
286
  }
270
- findPeer(publicKey) {
287
+ /**
288
+ * Look a peer up by the id the transport attached to a message, on the
289
+ * transport that delivered it.
290
+ *
291
+ * The transport is a parameter rather than a lookup because every caller
292
+ * already has one: a message can only have been delivered by a transport
293
+ * that exists. Reaching for `this.transport` instead parked every arrival
294
+ * between a disconnection and the next pairing -- setTransport(undefined)
295
+ * leaves `_transport` unsettled, so the await only returned once a later
296
+ * pairing resolved it, and the message was replayed into that connection.
297
+ *
298
+ * `connectionInfo.id` is the peer's public key over P2P, but the browser
299
+ * extension's id over postMessage, where the transport cannot tell which
300
+ * peer's key decrypted the message. Match either: only a postMessage
301
+ * pairing response carries an `extensionId`, so the fallback is inert for
302
+ * every other peer.
303
+ */
304
+ findPeer(id,
305
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
306
+ transport) {
271
307
  return __awaiter(this, void 0, void 0, function* () {
272
- if (!publicKey) {
308
+ var _a;
309
+ if (!id) {
273
310
  return undefined;
274
311
  }
275
- const transport = yield this.transport;
276
312
  const peers = yield transport.getPeers();
277
- return peers.find((peerInfo) => peerInfo.publicKey === publicKey);
313
+ return ((_a = peers.find((peerInfo) => peerInfo.publicKey === id)) !== null && _a !== void 0 ? _a :
314
+ // Newest first. `addPeer` dedupes by public key, so a wallet that rotated
315
+ // its beacon key -- a reinstall, a reset -- leaves the stale peer in place
316
+ // beside the new one, both carrying the same extension id. A fresh pairing
317
+ // has to shadow the stale peer, not the other way round.
318
+ [...peers]
319
+ .reverse()
320
+ .find((peerInfo) => 'extensionId' in peerInfo && peerInfo.extensionId === id));
278
321
  });
279
322
  }
280
323
  getLocalProtocolVersion() {
@@ -1 +1 @@
1
- {"version":3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C,CAAA;QACtE,OAAO,MAAM,CAAC,QAAQ,CAAC,iBAAiB,CAAC,IAAI,iBAAiB,IAAI,oCAAwB;YACxF,CAAC,CAAC,iBAAiB;YACnB,CAAC,CAAC,oCAAwB,CAAA;IAC9B,CAAC;IAEO,0BAA0B,CAAC,IAAe;QAChD,IAAI,CAAC,IAAI,EAAE,CAAC;YACV,OAAO,oCAAwB,CAAA;QACjC,CAAC;QAED,MAAM,eAAe,GACnB,OAAO,IAAI,CAAC,eAAe,KAAK,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,eAAe,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,eAAe,CAAC,CAAA;QAEhG,OAAO,MAAM,CAAC,QAAQ,CAAC,eAAe,CAAC,IAAI,eAAe,IAAI,oCAAwB;YACpF,CAAC,CAAC,eAAe;YACjB,CAAC,CAAC,oCAAwB,CAAA;IAC9B,CAAC;IAES,sBAAsB,CAAC,IAAe;QAC9C,MAAM,YAAY,GAAG,IAAI,CAAC,uBAAuB,EAAE,CAAA;QACnD,MAAM,WAAW,GAAG,IAAI,CAAC,0BAA0B,CAAC,IAAI,CAAC,CAAA;QACzD,OAAO,IAAI,CAAC,GAAG,CAAC,WAAW,EAAE,YAAY,CAAC,CAAA;IAC5C,CAAC;CACF;AA7SD,wBA6SC","sourcesContent":["import { ExposedPromise, generateGUID } from '@tezos-x/octez.connect-utils'\nimport {\n ConnectionContext,\n TransportType,\n TransportStatus,\n BeaconBaseMessage,\n AccountInfo,\n PeerInfo,\n AppMetadata,\n BeaconRequestMessage,\n BeaconMessageWrapper,\n NodeDistributions,\n Blockchain\n} from '@tezos-x/octez.connect-types'\nimport { DEFAULT_PROTOCOL_VERSION } from '../../constants'\nimport { BeaconClient } from '../beacon-client/BeaconClient'\nimport { AccountManager } from '../../managers/AccountManager'\nimport { getSenderId } from '../../utils/get-sender-id'\nimport { Logger } from '../../utils/Logger'\nimport { ClientOptions } from './ClientOptions'\nimport { Transport } from '../../transports/Transport'\nimport { Serializer } from '../../Serializer'\nimport { buildDisconnectMessage, effectivePeerVersion } from '../../utils/message-utils'\nimport { getPreferredMessageProtocolVersion } from '../../message-protocol'\n\nconst logger = new Logger('Client')\n\n/**\n * @internalapi\n *\n * This abstract class handles the a big part of the logic that is shared between the dapp and wallet client.\n * For example, it selects and manages the transport and accounts.\n */\nexport abstract class Client extends BeaconClient {\n protected readonly accountManager: AccountManager\n protected readonly blockchains: Map<string, Blockchain> = new Map()\n\n protected handleResponse: (\n _event: BeaconRequestMessage | BeaconMessageWrapper<BeaconBaseMessage>,\n connectionInfo: ConnectionContext\n ) => void\n\n /**\n * How many requests can be sent after another\n */\n protected readonly rateLimit: number = 2\n /**\n * The time window in seconds in which the \"rateLimit\" is checked\n */\n protected readonly rateLimitWindowInSeconds: number = 5\n\n /**\n * Stores the times when requests have been made to determine if the rate limit has been reached\n */\n protected requestCounter: number[] = []\n\n protected readonly matrixNodes: NodeDistributions\n\n private transportListeners: Map<\n TransportType,\n (message: any, connectionInfo: ConnectionContext) => Promise<void>\n > = new Map()\n\n protected _transport: ExposedPromise<Transport<any>> = new ExposedPromise()\n protected get transport(): Promise<Transport<any>> {\n return this._transport.promise\n }\n\n /**\n * Returns the connection status of the Client\n */\n public get connectionStatus(): TransportStatus {\n return this._transport.promiseResult?.connectionStatus ?? TransportStatus.NOT_CONNECTED\n }\n\n /**\n * Returns whether or not the transaport is ready\n */\n public get ready(): Promise<void> {\n return this.transport.then(() => undefined)\n }\n\n constructor(config: ClientOptions) {\n super(config)\n\n this.accountManager = new AccountManager(config.storage)\n this.matrixNodes = config.matrixNodes ?? {}\n\n this.handleResponse = (\n message: BeaconBaseMessage | BeaconMessageWrapper<BeaconBaseMessage>,\n connectionInfo: ConnectionContext\n ): void => {\n throw new Error(\n `not overwritten${JSON.stringify(message)} - ${JSON.stringify(connectionInfo)}`\n )\n }\n }\n protected async cleanup() {\n if (!this.transportListeners.size) {\n return\n }\n\n if (this._transport.isResolved()) {\n const transport = await this.transport\n await Promise.all(\n Array.from(this.transportListeners.values()).map((listener) =>\n transport.removeListener(listener)\n )\n )\n this.transportListeners.clear()\n }\n }\n\n /**\n * Register a blockchain to the client\n * @param chain The blockchain to register\n */\n public addBlockchain(chain: Blockchain) {\n this.blockchains.set(chain.identifier, chain)\n for (const legacyIdentifier of chain.legacyIdentifiers ?? []) {\n this.blockchains.set(legacyIdentifier, chain)\n }\n }\n\n /**\n * Remove a blockchain from the client by its identifier\n * @param chainIdentifier The identifier of the blockchain to remove\n */\n public removeBlockchain(chainIdentifier: string) {\n const chain = this.blockchains.get(chainIdentifier)\n this.blockchains.delete(chainIdentifier)\n for (const legacyIdentifier of chain?.legacyIdentifiers ?? []) {\n this.blockchains.delete(legacyIdentifier)\n }\n }\n\n /**\n * Return all locally known accounts\n */\n public async getAccounts(): Promise<AccountInfo[]> {\n return this.accountManager.getAccounts()\n }\n\n /**\n * Return the account by ID\n * @param accountIdentifier The ID of an account\n */\n public async getAccount(accountIdentifier: string): Promise<AccountInfo | undefined> {\n return this.accountManager.getAccount(accountIdentifier)\n }\n\n /**\n * Remove the account by ID\n * @param accountIdentifier The ID of an account\n */\n public async removeAccount(accountIdentifier: string): Promise<void> {\n return this.accountManager.removeAccount(accountIdentifier)\n }\n\n /**\n * Remove all locally stored accounts\n */\n public async removeAllAccounts(): Promise<void> {\n return this.accountManager.removeAllAccounts()\n }\n\n /**\n * Add a new request (current timestamp) to the pending requests, remove old ones and check if we are above the limit\n */\n public async addRequestAndCheckIfRateLimited(): Promise<boolean> {\n const now: number = new Date().getTime()\n this.requestCounter = this.requestCounter.filter(\n (date) => date + this.rateLimitWindowInSeconds * 1000 > now\n )\n\n this.requestCounter.push(now)\n\n return this.requestCounter.length > this.rateLimit\n }\n\n /**\n * This method initializes the client. It will check if the connection should be established to a\n * browser extension or if the P2P transport should be used.\n *\n * @param transport A transport that can be provided by the user\n */\n public async init(transport: Transport<any, any, any>): Promise<TransportType> {\n if (this._transport.isResolved()) {\n return (await this.transport).type\n }\n\n await this.setTransport(transport) // Let users define their own transport\n\n return transport.type\n }\n\n /**\n * Returns the metadata of this DApp\n */\n public async getOwnAppMetadata(): Promise<AppMetadata> {\n return {\n senderId: await getSenderId(await this.beaconId),\n name: this.name,\n icon: this.iconUrl\n }\n }\n\n /**\n * Return all known peers\n */\n public async getPeers(): Promise<PeerInfo[]> {\n return (await this.transport).getPeers()\n }\n\n /**\n * Add a new peer to the known peers\n * @param peer The new peer to add\n */\n public async addPeer(peer: PeerInfo): Promise<void> {\n return (await this.transport).addPeer(peer)\n }\n\n public async destroy(): Promise<void> {\n if (this._transport.isResolved()) {\n const transport = await this.transport\n await this.cleanup()\n await transport.disconnect()\n if (transport.type === TransportType.WALLETCONNECT) {\n await (transport as any).doClientCleanup() // any because I cannot import the type definition\n }\n }\n await super.destroy()\n }\n\n /**\n * A \"setter\" for when the transport needs to be changed.\n */\n protected async setTransport(transport?: Transport<any>): Promise<void> {\n if (transport) {\n if (this._transport.isSettled()) {\n // If the promise has already been resolved we need to create a new one.\n this._transport = ExposedPromise.resolve(transport)\n } else {\n this._transport.resolve(transport)\n }\n } else {\n if (this._transport.isSettled()) {\n // If the promise has already been resolved we need to create a new one.\n this._transport = new ExposedPromise()\n }\n }\n }\n\n protected async addListener(transport: Transport<any>): Promise<void> {\n // in beacon we subscribe to the transport on client init only\n // unsubscribing from the transport is only beneficial when running\n // a single page dApp.\n // However, while running a multiple tabs setup, if one of the dApps disconnects\n // the others wont't recover until after a page refresh\n\n if (this.transportListeners.has(transport.type)) {\n await transport.removeListener(this.transportListeners.get(transport.type)!)\n }\n\n const subscription = async (message: any, connectionInfo: ConnectionContext) => {\n if (typeof message !== 'string') {\n return\n }\n\n const peer = await this.findPeer(connectionInfo.id)\n const protocolVersion = this.getPeerProtocolVersion(peer)\n\n const deserializedMessage = (await new Serializer(protocolVersion).deserialize(\n message\n )) as BeaconRequestMessage\n this.handleResponse(deserializedMessage, connectionInfo)\n }\n\n this.transportListeners.set(transport.type, subscription)\n\n transport.addListener(subscription).catch((error) => logger.error('addListener', error))\n }\n\n protected async sendDisconnectToPeer(peer: PeerInfo, transport?: Transport<any>): Promise<void> {\n const id = await generateGUID()\n const senderId = await getSenderId(await this.beaconId)\n\n // The disconnect ships in the peer's negotiated dialect: wrapped for\n // v3+ peers, the flat legacy shape for v2 peers (which would silently\n // ignore a wrapped envelope).\n const request = buildDisconnectMessage({ id, senderId }, effectivePeerVersion(peer))\n\n const protocolVersion = this.getPeerProtocolVersion(peer)\n const payload = await new Serializer(protocolVersion).serialize(request)\n const selectedTransport = transport ?? (await this.transport)\n\n await selectedTransport.send(payload, peer)\n }\n\n protected async findPeer(publicKey?: string): Promise<PeerInfo | undefined> {\n if (!publicKey) {\n return undefined\n }\n\n const transport = await this.transport\n const peers = await transport.getPeers()\n return peers.find((peerInfo) => peerInfo.publicKey === publicKey)\n }\n\n private getLocalProtocolVersion(): number {\n const localPreferredRaw = Number(getPreferredMessageProtocolVersion())\n return Number.isFinite(localPreferredRaw) && localPreferredRaw >= DEFAULT_PROTOCOL_VERSION\n ? localPreferredRaw\n : DEFAULT_PROTOCOL_VERSION\n }\n\n private extractPeerProtocolVersion(peer?: PeerInfo): number {\n if (!peer) {\n return DEFAULT_PROTOCOL_VERSION\n }\n\n const peerProtocolRaw =\n typeof peer.protocolVersion === 'number' ? peer.protocolVersion : Number(peer.protocolVersion)\n\n return Number.isFinite(peerProtocolRaw) && peerProtocolRaw >= DEFAULT_PROTOCOL_VERSION\n ? peerProtocolRaw\n : DEFAULT_PROTOCOL_VERSION\n }\n\n protected getPeerProtocolVersion(peer?: PeerInfo): number {\n const localVersion = this.getLocalProtocolVersion()\n const peerVersion = this.extractPeerProtocolVersion(peer)\n return Math.min(peerVersion, localVersion)\n }\n}\n"]}
1
+ {"version":3,"file":"Client.js","sourceRoot":"","sources":["../../../../../src/clients/client/Client.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,sEAA2E;AAC3E,sEAYqC;AACrC,+CAA0D;AAC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yD;YACzD,CAAC,GAAG,KAAK,CAAC;iBACP,OAAO,EAAE;iBACT,IAAI,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,aAAa,IAAI,QAAQ,IAAI,QAAQ,CAAC,WAAW,KAAK,EAAE,CAAC,CAChF,CAAA;QACH,CAAC;KAAA;IAEO,uBAAuB;QAC7B,MAAM,iBAAiB,GAAG,MAAM,CAAC,IAAA,qDAAkC,GAAE,CAAC,CAAA;QACtE,OAAO,MAAM,CAAC,QAAQ,CAAC,iBAAiB,CAAC,IAAI,iBAAiB,IAAI,oCAAwB;YACxF,CAAC,CAAC,iBAAiB;YACnB,CAAC,CAAC,oCAAwB,CAAA;IAC9B,CAAC;IAEO,0BAA0B,CAAC,IAAe;QAChD,IAAI,CAAC,IAAI,EAAE,CAAC;YACV,OAAO,oCAAwB,CAAA;QACjC,CAAC;QAED,MAAM,eAAe,GACnB,OAAO,IAAI,CAAC,eAAe,KAAK,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,eAAe,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,eAAe,CAAC,CAAA;QAChG,OAAO,MAAM,CAAC,QAAQ,CAAC,eAAe,CAAC,IAAI,eAAe,IAAI,oCAAwB;YACpF,CAAC,CAAC,eAAe;YACjB,CAAC,CAAC,oCAAwB,CAAA;IAC9B,CAAC;IAES,sBAAsB,CAAC,IAAe;QAC9C,MAAM,YAAY,GAAG,IAAI,CAAC,uBAAuB,EAAE,CAAA;QACnD,MAAM,WAAW,GAAG,IAAI,CAAC,0BAA0B,CAAC,IAAI,CAAC,CAAA;QAEzD,OAAO,IAAI,CAAC,GAAG,CAAC,WAAW,EAAE,YAAY,CAAC,CAAA;IAC5C,CAAC;CACF;AAhWD,wBAgWC","sourcesContent":["import { ExposedPromise, generateGUID } from '@tezos-x/octez.connect-utils'\nimport {\n ConnectionContext,\n TransportType,\n TransportStatus,\n BeaconBaseMessage,\n AccountInfo,\n PeerInfo,\n AppMetadata,\n BeaconRequestMessage,\n BeaconMessageWrapper,\n NodeDistributions,\n Blockchain\n} from '@tezos-x/octez.connect-types'\nimport { DEFAULT_PROTOCOL_VERSION } from '../../constants'\nimport { BeaconClient } from '../beacon-client/BeaconClient'\nimport { AccountManager } from '../../managers/AccountManager'\nimport { getSenderId } from '../../utils/get-sender-id'\nimport { Logger } from '../../utils/Logger'\nimport { ClientOptions } from './ClientOptions'\nimport { Transport } from '../../transports/Transport'\nimport { Serializer } from '../../Serializer'\nimport { buildDisconnectMessage, effectivePeerVersion } from '../../utils/message-utils'\nimport { getPreferredMessageProtocolVersion } from '../../message-protocol'\n\nconst logger = new Logger('Client')\n\n/**\n * @internalapi\n *\n * This abstract class handles the a big part of the logic that is shared between the dapp and wallet client.\n * For example, it selects and manages the transport and accounts.\n */\nexport abstract class Client extends BeaconClient {\n protected readonly accountManager: AccountManager\n protected readonly blockchains: Map<string, Blockchain> = new Map()\n\n protected handleResponse: (\n _event: BeaconRequestMessage | BeaconMessageWrapper<BeaconBaseMessage>,\n connectionInfo: ConnectionContext\n ) => void\n\n /**\n * How many requests can be sent after another\n */\n protected readonly rateLimit: number = 2\n /**\n * The time window in seconds in which the \"rateLimit\" is checked\n */\n protected readonly rateLimitWindowInSeconds: number = 5\n\n /**\n * Stores the times when requests have been made to determine if the rate limit has been reached\n */\n protected requestCounter: number[] = []\n\n protected readonly matrixNodes: NodeDistributions\n\n /**\n * One subscription per transport type, together with the transport instance\n * it is attached to. The instance is needed to detach: a replaced transport\n * outlives the client's reference to it (`disconnect()` and\n * `handleDisconnect()` only null the reference), so removing the listener\n * from the *incoming* transport would leave the old one subscribed.\n */\n private readonly transportListeners: Map<\n TransportType,\n {\n transport: Transport\n listener: (message: unknown, connectionInfo: ConnectionContext) => Promise<void>\n }\n > = new Map()\n\n protected _transport: ExposedPromise<Transport<any>> = new ExposedPromise()\n protected get transport(): Promise<Transport<any>> {\n return this._transport.promise\n }\n\n /**\n * Returns the connection status of the Client\n */\n public get connectionStatus(): TransportStatus {\n return this._transport.promiseResult?.connectionStatus ?? TransportStatus.NOT_CONNECTED\n }\n\n /**\n * Returns whether or not the transaport is ready\n */\n public get ready(): Promise<void> {\n return this.transport.then(() => undefined)\n }\n\n constructor(config: ClientOptions) {\n super(config)\n\n this.accountManager = new AccountManager(config.storage)\n this.matrixNodes = config.matrixNodes ?? {}\n\n this.handleResponse = (\n message: BeaconBaseMessage | BeaconMessageWrapper<BeaconBaseMessage>,\n connectionInfo: ConnectionContext\n ): void => {\n throw new Error(\n `not overwritten${JSON.stringify(message)} - ${JSON.stringify(connectionInfo)}`\n )\n }\n }\n protected async cleanup() {\n if (!this.transportListeners.size) {\n return\n }\n\n // Each subscription is removed from the transport it is attached to.\n // Going through `this.transport` removed them all from whichever transport\n // was active, and removed none when no transport was resolved -- the state\n // `disconnect()` leaves behind.\n await Promise.all(\n Array.from(this.transportListeners.values()).map(({ transport, listener }) =>\n transport.removeListener(listener)\n )\n )\n this.transportListeners.clear()\n }\n\n /**\n * Register a blockchain to the client\n * @param chain The blockchain to register\n */\n public addBlockchain(chain: Blockchain) {\n this.blockchains.set(chain.identifier, chain)\n for (const legacyIdentifier of chain.legacyIdentifiers ?? []) {\n this.blockchains.set(legacyIdentifier, chain)\n }\n }\n\n /**\n * Remove a blockchain from the client by its identifier\n * @param chainIdentifier The identifier of the blockchain to remove\n */\n public removeBlockchain(chainIdentifier: string) {\n const chain = this.blockchains.get(chainIdentifier)\n this.blockchains.delete(chainIdentifier)\n for (const legacyIdentifier of chain?.legacyIdentifiers ?? []) {\n this.blockchains.delete(legacyIdentifier)\n }\n }\n\n /**\n * Return all locally known accounts\n */\n public async getAccounts(): Promise<AccountInfo[]> {\n return this.accountManager.getAccounts()\n }\n\n /**\n * Return the account by ID\n * @param accountIdentifier The ID of an account\n */\n public async getAccount(accountIdentifier: string): Promise<AccountInfo | undefined> {\n return this.accountManager.getAccount(accountIdentifier)\n }\n\n /**\n * Remove the account by ID\n * @param accountIdentifier The ID of an account\n */\n public async removeAccount(accountIdentifier: string): Promise<void> {\n return this.accountManager.removeAccount(accountIdentifier)\n }\n\n /**\n * Remove all locally stored accounts\n */\n public async removeAllAccounts(): Promise<void> {\n return this.accountManager.removeAllAccounts()\n }\n\n /**\n * Add a new request (current timestamp) to the pending requests, remove old ones and check if we are above the limit\n */\n public async addRequestAndCheckIfRateLimited(): Promise<boolean> {\n const now: number = new Date().getTime()\n this.requestCounter = this.requestCounter.filter(\n (date) => date + this.rateLimitWindowInSeconds * 1000 > now\n )\n\n this.requestCounter.push(now)\n\n return this.requestCounter.length > this.rateLimit\n }\n\n /**\n * This method initializes the client. It will check if the connection should be established to a\n * browser extension or if the P2P transport should be used.\n *\n * @param transport A transport that can be provided by the user\n */\n public async init(transport: Transport<any, any, any>): Promise<TransportType> {\n if (this._transport.isResolved()) {\n return (await this.transport).type\n }\n\n await this.setTransport(transport) // Let users define their own transport\n\n return transport.type\n }\n\n /**\n * Returns the metadata of this DApp\n */\n public async getOwnAppMetadata(): Promise<AppMetadata> {\n return {\n senderId: await getSenderId(await this.beaconId),\n name: this.name,\n icon: this.iconUrl\n }\n }\n\n /**\n * Return all known peers\n */\n public async getPeers(): Promise<PeerInfo[]> {\n return (await this.transport).getPeers()\n }\n\n /**\n * Add a new peer to the known peers\n * @param peer The new peer to add\n */\n public async addPeer(peer: PeerInfo): Promise<void> {\n return (await this.transport).addPeer(peer)\n }\n\n public async destroy(): Promise<void> {\n // Subscriptions are detached from their own transports, so this no longer\n // needs an active one -- after disconnect() there is none, and that is\n // precisely when the orphaned subscriptions have to go.\n await this.cleanup()\n\n if (this._transport.isResolved()) {\n const transport = await this.transport\n await transport.disconnect()\n if (transport.type === TransportType.WALLETCONNECT) {\n await (transport as any).doClientCleanup() // any because I cannot import the type definition\n }\n }\n await super.destroy()\n }\n\n /**\n * A \"setter\" for when the transport needs to be changed.\n */\n protected async setTransport(transport?: Transport<any>): Promise<void> {\n if (transport) {\n if (this._transport.isSettled()) {\n // If the promise has already been resolved we need to create a new one.\n this._transport = ExposedPromise.resolve(transport)\n } else {\n this._transport.resolve(transport)\n }\n } else {\n if (this._transport.isSettled()) {\n // If the promise has already been resolved we need to create a new one.\n this._transport = new ExposedPromise()\n }\n }\n }\n\n protected async addListener(transport: Transport<any>): Promise<void> {\n // in beacon we subscribe to the transport on client init only\n // unsubscribing from the transport is only beneficial when running\n // a single page dApp.\n // However, while running a multiple tabs setup, if one of the dApps disconnects\n // the others wont't recover until after a page refresh\n\n // Detach the previous subscription from the transport it is actually\n // attached to. Calling removeListener on the incoming transport, which never\n // had it, left every replaced transport subscribed: they share the client's\n // key pair, so each one kept decrypting wallet messages and routing them into\n // handleResponse -- once per past connection.\n const previous = this.transportListeners.get(transport.type)\n if (previous) {\n await previous.transport.removeListener(previous.listener)\n }\n\n const subscription = async (message: any, connectionInfo: ConnectionContext) => {\n if (typeof message !== 'string') {\n return\n }\n\n const peer = await this.findPeer(connectionInfo.id, transport)\n const protocolVersion = this.getPeerProtocolVersion(peer)\n\n const deserializedMessage = (await new Serializer(protocolVersion).deserialize(\n message\n )) as BeaconRequestMessage\n this.handleResponse(deserializedMessage, connectionInfo)\n }\n\n this.transportListeners.set(transport.type, { transport, listener: subscription })\n\n transport.addListener(subscription).catch((error) => logger.error('addListener', error))\n }\n\n protected async sendDisconnectToPeer(peer: PeerInfo, transport?: Transport<any>): Promise<void> {\n const id = await generateGUID()\n const senderId = await getSenderId(await this.beaconId)\n\n // The disconnect ships in the peer's negotiated dialect: wrapped for\n // v3+ peers, the flat legacy shape for v2 peers (which would silently\n // ignore a wrapped envelope).\n const request = buildDisconnectMessage({ id, senderId }, effectivePeerVersion(peer))\n\n const protocolVersion = this.getPeerProtocolVersion(peer)\n const payload = await new Serializer(protocolVersion).serialize(request)\n const selectedTransport = transport ?? (await this.transport)\n\n await selectedTransport.send(payload, peer)\n }\n\n /**\n * Look a peer up by the id the transport attached to a message, on the\n * transport that delivered it.\n *\n * The transport is a parameter rather than a lookup because every caller\n * already has one: a message can only have been delivered by a transport\n * that exists. Reaching for `this.transport` instead parked every arrival\n * between a disconnection and the next pairing -- setTransport(undefined)\n * leaves `_transport` unsettled, so the await only returned once a later\n * pairing resolved it, and the message was replayed into that connection.\n *\n * `connectionInfo.id` is the peer's public key over P2P, but the browser\n * extension's id over postMessage, where the transport cannot tell which\n * peer's key decrypted the message. Match either: only a postMessage\n * pairing response carries an `extensionId`, so the fallback is inert for\n * every other peer.\n */\n protected async findPeer(\n id: string | undefined,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n transport: Transport<any>\n ): Promise<PeerInfo | undefined> {\n if (!id) {\n return undefined\n }\n\n const peers = await transport.getPeers()\n\n return (\n peers.find((peerInfo) => peerInfo.publicKey === id) ??\n // Newest first. `addPeer` dedupes by public key, so a wallet that rotated\n // its beacon key -- a reinstall, a reset -- leaves the stale peer in place\n // beside the new one, both carrying the same extension id. A fresh pairing\n // has to shadow the stale peer, not the other way round.\n [...peers]\n .reverse()\n .find((peerInfo) => 'extensionId' in peerInfo && peerInfo.extensionId === id)\n )\n }\n\n private getLocalProtocolVersion(): number {\n const localPreferredRaw = Number(getPreferredMessageProtocolVersion())\n return Number.isFinite(localPreferredRaw) && localPreferredRaw >= DEFAULT_PROTOCOL_VERSION\n ? localPreferredRaw\n : DEFAULT_PROTOCOL_VERSION\n }\n\n private extractPeerProtocolVersion(peer?: PeerInfo): number {\n if (!peer) {\n return DEFAULT_PROTOCOL_VERSION\n }\n\n const peerProtocolRaw =\n typeof peer.protocolVersion === 'number' ? peer.protocolVersion : Number(peer.protocolVersion)\n return Number.isFinite(peerProtocolRaw) && peerProtocolRaw >= DEFAULT_PROTOCOL_VERSION\n ? peerProtocolRaw\n : DEFAULT_PROTOCOL_VERSION\n }\n\n protected getPeerProtocolVersion(peer?: PeerInfo): number {\n const localVersion = this.getLocalProtocolVersion()\n const peerVersion = this.extractPeerProtocolVersion(peer)\n\n return Math.min(peerVersion, localVersion)\n }\n}\n"]}
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.DEFAULT_WALLETCONNECT_PROJECT_ID = exports.BACKEND_URL = exports.NOTIFICATION_ORACLE_URL = exports.DEFAULT_PROTOCOL_VERSION = exports.LATEST_PROTOCOL_VERSION = exports.PROTOCOL_VERSION_V2 = exports.PROTOCOL_VERSION_V1 = exports.BEACON_VERSION = exports.SDK_VERSION = void 0;
4
- exports.SDK_VERSION = '5.0.3';
4
+ exports.SDK_VERSION = '5.0.5';
5
5
  exports.BEACON_VERSION = '4';
6
6
  exports.PROTOCOL_VERSION_V1 = 1;
7
7
  exports.PROTOCOL_VERSION_V2 = 2;
@@ -1 +1 @@
1
- {"version":3,"file":"constants.js","sourceRoot":"","sources":["../../../src/constants.ts"],"names":[],"mappings":";;;AAAa,QAAA,WAAW,GAAW,OAAO,CAAA;AAC7B,QAAA,cAAc,GAAW,GAAG,CAAA;AAC5B,QAAA,mBAAmB,GAAG,CAAC,CAAA;AACvB,QAAA,mBAAmB,GAAG,CAAC,CAAA;AACvB,QAAA,uBAAuB,GAAG,2BAAmB,CAAA;AAC7C,QAAA,wBAAwB,GAAG,2BAAmB,CAAA;AAE9C,QAAA,uBAAuB,GAClC,wDAAwD,CAAA;AAE7C,QAAA,WAAW,GAAW,6CAA6C,CAAA;AAEhF;;;;;;;GAOG;AACU,QAAA,gCAAgC,GAAG,kCAAkC,CAAA","sourcesContent":["export const SDK_VERSION: string = '5.0.3'\nexport const BEACON_VERSION: string = '4'\nexport const PROTOCOL_VERSION_V1 = 1\nexport const PROTOCOL_VERSION_V2 = 2\nexport const LATEST_PROTOCOL_VERSION = PROTOCOL_VERSION_V2\nexport const DEFAULT_PROTOCOL_VERSION = PROTOCOL_VERSION_V1\n\nexport const NOTIFICATION_ORACLE_URL: string =\n 'https://beacon-notification-oracle.dev.gke.papers.tech'\n\nexport const BACKEND_URL: string = 'https://beacon-backend.prod.gke.papers.tech'\n\n/**\n * Shared ecosystem WalletConnect Cloud projectId, applied by default so dApps\n * can offer WalletConnect wallets (e.g. Kukai Mobile) without registering\n * their own project — WalletConnect's free tier comfortably covers the Tezos\n * ecosystem's volume. Override per dApp via\n * `DAppClientOptions.walletConnectOptions.projectId`; opt out entirely via\n * `disableWalletConnect`. Same id that 4.8.x shipped as its built-in default.\n */\nexport const DEFAULT_WALLETCONNECT_PROJECT_ID = '24469fd0a06df227b6e5f7dc7de0ff4f'\n"]}
1
+ {"version":3,"file":"constants.js","sourceRoot":"","sources":["../../../src/constants.ts"],"names":[],"mappings":";;;AAAa,QAAA,WAAW,GAAW,OAAO,CAAA;AAC7B,QAAA,cAAc,GAAW,GAAG,CAAA;AAC5B,QAAA,mBAAmB,GAAG,CAAC,CAAA;AACvB,QAAA,mBAAmB,GAAG,CAAC,CAAA;AACvB,QAAA,uBAAuB,GAAG,2BAAmB,CAAA;AAC7C,QAAA,wBAAwB,GAAG,2BAAmB,CAAA;AAE9C,QAAA,uBAAuB,GAClC,wDAAwD,CAAA;AAE7C,QAAA,WAAW,GAAW,6CAA6C,CAAA;AAEhF;;;;;;;GAOG;AACU,QAAA,gCAAgC,GAAG,kCAAkC,CAAA","sourcesContent":["export const SDK_VERSION: string = '5.0.5'\nexport const BEACON_VERSION: string = '4'\nexport const PROTOCOL_VERSION_V1 = 1\nexport const PROTOCOL_VERSION_V2 = 2\nexport const LATEST_PROTOCOL_VERSION = PROTOCOL_VERSION_V2\nexport const DEFAULT_PROTOCOL_VERSION = PROTOCOL_VERSION_V1\n\nexport const NOTIFICATION_ORACLE_URL: string =\n 'https://beacon-notification-oracle.dev.gke.papers.tech'\n\nexport const BACKEND_URL: string = 'https://beacon-backend.prod.gke.papers.tech'\n\n/**\n * Shared ecosystem WalletConnect Cloud projectId, applied by default so dApps\n * can offer WalletConnect wallets (e.g. Kukai Mobile) without registering\n * their own project — WalletConnect's free tier comfortably covers the Tezos\n * ecosystem's volume. Override per dApp via\n * `DAppClientOptions.walletConnectOptions.projectId`; opt out entirely via\n * `disableWalletConnect`. Same id that 4.8.x shipped as its built-in default.\n */\nexport const DEFAULT_WALLETCONNECT_PROJECT_ID = '24469fd0a06df227b6e5f7dc7de0ff4f'\n"]}
@@ -40,6 +40,7 @@ import { InvalidBeaconVersionError } from './errors/InvalidBeaconVersionError';
40
40
  import { getLogger, Logger, setLogger } from './utils/Logger';
41
41
  import { windowRef } from './MockWindow';
42
42
  import { CommunicationClient } from './transports/clients/CommunicationClient';
43
+ import { PendingPairingRequests } from './transports/clients/PendingPairingRequests';
43
44
  import { ClientEvents } from './transports/clients/ClientEvents';
44
45
  import { WCStorage } from './storage/WCStorage';
45
46
  import { IndexedDBStorage } from './storage/IndexedDBStorage';
@@ -48,7 +49,7 @@ import { MultiTabChannel } from './utils/multi-tab-channel';
48
49
  import getError from './errors/get-error';
49
50
  export { BeaconClient, BeaconClientOptions, Client, ClientOptions, ClientEvents };
50
51
  export { getError, BeaconError, AbortedBeaconError, BroadcastBeaconError, NetworkNotSupportedBeaconError, NoAddressBeaconError, NoPrivateKeyBeaconError, NotGrantedBeaconError, ParametersInvalidBeaconError, TooManyOperationsBeaconError, TransactionInvalidBeaconError, SignatureTypeNotSupportedBeaconError, UnknownBeaconError, VersionUnsupportedBeaconError, InvalidRequiredMinimumVersionError, NetworksUnsupportedBeaconError, InvalidBeaconVersionError };
51
- export { Transport, MessageBasedClient, CommunicationClient };
52
+ export { Transport, MessageBasedClient, CommunicationClient, PendingPairingRequests };
52
53
  export { ChromeStorage, LocalStorage, WCStorage, IndexedDBStorage, StorageValidator, getStorage };
53
54
  export { PeerManager, AccountManager, AppMetadataManager, PermissionManager };
54
55
  export { SDK_VERSION, DEFAULT_WALLETCONNECT_PROJECT_ID, BEACON_VERSION, PROTOCOL_VERSION_V1, PROTOCOL_VERSION_V2, LATEST_PROTOCOL_VERSION, DEFAULT_PROTOCOL_VERSION, getPreferredMessageProtocolVersion, setPreferredMessageProtocolVersion };
@@ -3,8 +3,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.isAtLeastVersion = exports.compareBeaconVersion = exports.MULTI_NETWORK_FROM_VERSION = exports.MESSAGE_WRAPPED_FROM_VERSION = exports.usesWrappedMessages = exports.MultiTabChannel = exports.windowRef = exports.getAccountIdentifier = exports.getSenderId = exports.setPreferredMessageProtocolVersion = exports.getPreferredMessageProtocolVersion = exports.DEFAULT_PROTOCOL_VERSION = exports.LATEST_PROTOCOL_VERSION = exports.PROTOCOL_VERSION_V2 = exports.PROTOCOL_VERSION_V1 = exports.BEACON_VERSION = exports.DEFAULT_WALLETCONNECT_PROJECT_ID = exports.SDK_VERSION = exports.PermissionManager = exports.AppMetadataManager = exports.AccountManager = exports.PeerManager = exports.getStorage = exports.StorageValidator = exports.IndexedDBStorage = exports.WCStorage = exports.LocalStorage = exports.ChromeStorage = exports.CommunicationClient = exports.MessageBasedClient = exports.Transport = exports.InvalidBeaconVersionError = exports.NetworksUnsupportedBeaconError = exports.InvalidRequiredMinimumVersionError = exports.VersionUnsupportedBeaconError = exports.UnknownBeaconError = exports.SignatureTypeNotSupportedBeaconError = exports.TransactionInvalidBeaconError = exports.TooManyOperationsBeaconError = exports.ParametersInvalidBeaconError = exports.NotGrantedBeaconError = exports.NoPrivateKeyBeaconError = exports.NoAddressBeaconError = exports.NetworkNotSupportedBeaconError = exports.BroadcastBeaconError = exports.AbortedBeaconError = exports.BeaconError = exports.getError = exports.Client = exports.BeaconClient = void 0;
7
- exports.BACKEND_URL = exports.NOTIFICATION_ORACLE_URL = exports.getDebugEnabled = exports.setDebugEnabled = exports.getLogger = exports.setLogger = exports.Logger = exports.Serializer = exports.BEACON_ERROR_CODES = exports.BLOCKCHAIN_ERROR_CODES = exports.PM_ERROR_CODES = exports.MATRIX_ERROR_CODES = exports.WC_ERROR_CODES = exports.ERROR_CODES = exports.SENSITIVE_STORAGE_KEYS = exports.copyErrorContextToClipboard = exports.serializeErrorContext = exports.buildErrorContext = exports.gatherDiagnostics = exports.resolveRequiredMinimumVersion = exports.assertNever = exports.networkTypeFromTezosCaip2 = exports.tezosCaip2FromNetworkType = exports.TEZOS_NETWORK_GENESIS_IDS = exports.networkFromTezosCaip2 = exports.isValidTezosCaip2 = exports.normalizeTezosCaip2 = exports.unwrapBeaconMessage = exports.wrapBeaconMessage = exports.effectivePeerVersion = exports.negotiateEnvelopeVersion = exports.isMultiNetworkVersion = void 0;
6
+ exports.compareBeaconVersion = exports.MULTI_NETWORK_FROM_VERSION = exports.MESSAGE_WRAPPED_FROM_VERSION = exports.usesWrappedMessages = exports.MultiTabChannel = exports.windowRef = exports.getAccountIdentifier = exports.getSenderId = exports.setPreferredMessageProtocolVersion = exports.getPreferredMessageProtocolVersion = exports.DEFAULT_PROTOCOL_VERSION = exports.LATEST_PROTOCOL_VERSION = exports.PROTOCOL_VERSION_V2 = exports.PROTOCOL_VERSION_V1 = exports.BEACON_VERSION = exports.DEFAULT_WALLETCONNECT_PROJECT_ID = exports.SDK_VERSION = exports.PermissionManager = exports.AppMetadataManager = exports.AccountManager = exports.PeerManager = exports.getStorage = exports.StorageValidator = exports.IndexedDBStorage = exports.WCStorage = exports.LocalStorage = exports.ChromeStorage = exports.PendingPairingRequests = exports.CommunicationClient = exports.MessageBasedClient = exports.Transport = exports.InvalidBeaconVersionError = exports.NetworksUnsupportedBeaconError = exports.InvalidRequiredMinimumVersionError = exports.VersionUnsupportedBeaconError = exports.UnknownBeaconError = exports.SignatureTypeNotSupportedBeaconError = exports.TransactionInvalidBeaconError = exports.TooManyOperationsBeaconError = exports.ParametersInvalidBeaconError = exports.NotGrantedBeaconError = exports.NoPrivateKeyBeaconError = exports.NoAddressBeaconError = exports.NetworkNotSupportedBeaconError = exports.BroadcastBeaconError = exports.AbortedBeaconError = exports.BeaconError = exports.getError = exports.Client = exports.BeaconClient = void 0;
7
+ exports.BACKEND_URL = exports.NOTIFICATION_ORACLE_URL = exports.getDebugEnabled = exports.setDebugEnabled = exports.getLogger = exports.setLogger = exports.Logger = exports.Serializer = exports.BEACON_ERROR_CODES = exports.BLOCKCHAIN_ERROR_CODES = exports.PM_ERROR_CODES = exports.MATRIX_ERROR_CODES = exports.WC_ERROR_CODES = exports.ERROR_CODES = exports.SENSITIVE_STORAGE_KEYS = exports.copyErrorContextToClipboard = exports.serializeErrorContext = exports.buildErrorContext = exports.gatherDiagnostics = exports.resolveRequiredMinimumVersion = exports.assertNever = exports.networkTypeFromTezosCaip2 = exports.tezosCaip2FromNetworkType = exports.TEZOS_NETWORK_GENESIS_IDS = exports.networkFromTezosCaip2 = exports.isValidTezosCaip2 = exports.normalizeTezosCaip2 = exports.unwrapBeaconMessage = exports.wrapBeaconMessage = exports.effectivePeerVersion = exports.negotiateEnvelopeVersion = exports.isMultiNetworkVersion = exports.isAtLeastVersion = void 0;
8
8
  /**
9
9
  * General docs
10
10
  * @module public
@@ -94,6 +94,8 @@ const MockWindow_1 = require("./MockWindow");
94
94
  Object.defineProperty(exports, "windowRef", { enumerable: true, get: function () { return MockWindow_1.windowRef; } });
95
95
  const CommunicationClient_1 = require("./transports/clients/CommunicationClient");
96
96
  Object.defineProperty(exports, "CommunicationClient", { enumerable: true, get: function () { return CommunicationClient_1.CommunicationClient; } });
97
+ const PendingPairingRequests_1 = require("./transports/clients/PendingPairingRequests");
98
+ Object.defineProperty(exports, "PendingPairingRequests", { enumerable: true, get: function () { return PendingPairingRequests_1.PendingPairingRequests; } });
97
99
  const WCStorage_1 = require("./storage/WCStorage");
98
100
  Object.defineProperty(exports, "WCStorage", { enumerable: true, get: function () { return WCStorage_1.WCStorage; } });
99
101
  const IndexedDBStorage_1 = require("./storage/IndexedDBStorage");
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":";;;;;;;AAAA;;;GAGG;AACH,oDAAgD;AA+DJ,uFA/DnC,eAAM,OA+DmC;AA9DlD,sDAAkD;AAmEhD,4FA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xB,qHAAA,oBAAoB,OAAA;AACpB,kHAAA,iBAAiB,OAAA;AACjB,oHAAA,mBAAmB,OAAA;AAErB,uCAOsB;AANpB,4GAAA,mBAAmB,OAAA;AACnB,0GAAA,iBAAiB,OAAA;AACjB,8GAAA,qBAAqB,OAAA;AACrB,kHAAA,yBAAyB,OAAA;AACzB,kHAAA,yBAAyB,OAAA;AACzB,kHAAA,yBAAyB,OAAA;AAE3B,qDAAkD;AAAzC,2GAAA,WAAW,OAAA;AACpB,6EAAgF;AAAvE,yIAAA,6BAA6B,OAAA;AAEtC,cAAc;AACd,mDAM4B;AAL1B,gHAAA,iBAAiB,OAAA;AACjB,gHAAA,iBAAiB,OAAA;AACjB,oHAAA,qBAAqB,OAAA;AACrB,0HAAA,2BAA2B,OAAA;AAC3B,qHAAA,sBAAsB,OAAA;AAGxB,cAAc;AACd,oDAAkJ;AAAzI,0GAAA,WAAW,OAAA;AAAE,6GAAA,cAAc,OAAA;AAAE,iHAAA,kBAAkB,OAAA;AAAE,6GAAA,cAAc,OAAA;AAAE,qHAAA,sBAAsB,OAAA;AAAE,iHAAA,kBAAkB,OAAA;AASpH,yCAAkE;AAAzD,oHAAA,uBAAuB,OAAA;AAAE,wGAAA,WAAW,OAAA","sourcesContent":["/**\n * General docs\n * @module public\n */\nimport { Client } from './clients/client/Client'\nimport { BeaconError } from './errors/BeaconError'\nimport { BroadcastBeaconError } from './errors/BroadcastBeaconError'\nimport { NetworkNotSupportedBeaconError } from './errors/NetworkNotSupportedBeaconError'\nimport { NoAddressBeaconError } from './errors/NoAddressBeaconError'\nimport { NoPrivateKeyBeaconError } from './errors/NoPrivateKeyBeaconError'\nimport { NotGrantedBeaconError } from './errors/NotGrantedBeaconError'\nimport { ParametersInvalidBeaconError } from './errors/ParametersInvalidBeaconError'\nimport { TooManyOperationsBeaconError } from './errors/TooManyOperationsBeaconError'\nimport { TransactionInvalidBeaconError } from './errors/TransactionInvalidBeaconError'\nimport { UnknownBeaconError } from './errors/UnknownBeaconError'\nimport { Transport } from './transports/Transport'\nimport { ChromeStorage } from './storage/ChromeStorage'\nimport { LocalStorage } from './storage/LocalStorage'\nimport { getStorage } from './storage/getStorage'\nimport { Serializer } from './Serializer'\n// import { RequestEncryptPayloadInput } from './types/RequestEncryptPayloadInput'\nimport { ClientOptions } from './clients/client/ClientOptions'\nimport {\n SDK_VERSION,\n DEFAULT_WALLETCONNECT_PROJECT_ID,\n BEACON_VERSION,\n PROTOCOL_VERSION_V1,\n PROTOCOL_VERSION_V2,\n LATEST_PROTOCOL_VERSION,\n DEFAULT_PROTOCOL_VERSION\n} from './constants'\nimport {\n getPreferredMessageProtocolVersion,\n setPreferredMessageProtocolVersion\n} from './message-protocol'\nimport { AccountManager } from './managers/AccountManager'\nimport { AppMetadataManager } from './managers/AppMetadataManager'\nimport { PermissionManager } from './managers/PermissionManager'\nimport { BeaconClient } from './clients/beacon-client/BeaconClient'\nimport { BeaconClientOptions } from './clients/beacon-client/BeaconClientOptions'\nimport { getAccountIdentifier } from './utils/get-account-identifier'\nimport { AbortedBeaconError } from './errors/AbortedBeaconError'\nimport { getSenderId } from './utils/get-sender-id'\nimport { PeerManager } from './managers/PeerManager'\nimport { MessageBasedClient } from './transports/clients/MessageBasedClient'\nimport { setDebugEnabled, getDebugEnabled } from './debug'\n// import { EncryptPayloadRequest } from './types/beacon/messages/EncryptPayloadRequest'\n// import { EncryptPayloadResponse } from './types/beacon/messages/EncryptPayloadResponse'\n// import { EncryptionTypeNotSupportedBeaconError } from './errors/EncryptionTypeNotSupportedBeaconError'\nimport { SignatureTypeNotSupportedBeaconError } from './errors/SignatureTypeNotSupportedBeaconError'\nimport { VersionUnsupportedBeaconError } from './errors/VersionUnsupportedBeaconError'\nimport { InvalidRequiredMinimumVersionError } from './errors/InvalidRequiredMinimumVersionError'\nimport { NetworksUnsupportedBeaconError } from './errors/NetworksUnsupportedBeaconError'\nimport { InvalidBeaconVersionError } from './errors/InvalidBeaconVersionError'\nimport { getLogger, Logger, setLogger } from './utils/Logger'\nimport { windowRef } from './MockWindow'\nimport { CommunicationClient } from './transports/clients/CommunicationClient'\nimport { ClientEvents } from './transports/clients/ClientEvents'\nimport { WCStorage } from './storage/WCStorage'\nimport { IndexedDBStorage } from './storage/IndexedDBStorage'\nimport { StorageValidator } from './storage/StorageValidator'\nimport { MultiTabChannel } from './utils/multi-tab-channel'\nimport getError from './errors/get-error'\n// import { EncryptionType } from './types/EncryptionType'\n// import { EncryptionOperation } from './types/EncryptionOperation'\n\n// Clients\nexport { BeaconClient, BeaconClientOptions, Client, ClientOptions, ClientEvents }\n\n// Errors\nexport {\n getError,\n BeaconError,\n AbortedBeaconError,\n BroadcastBeaconError,\n NetworkNotSupportedBeaconError,\n NoAddressBeaconError,\n NoPrivateKeyBeaconError,\n NotGrantedBeaconError,\n ParametersInvalidBeaconError,\n TooManyOperationsBeaconError,\n TransactionInvalidBeaconError,\n SignatureTypeNotSupportedBeaconError,\n // EncryptionTypeNotSupportedBeaconError,\n UnknownBeaconError,\n VersionUnsupportedBeaconError,\n InvalidRequiredMinimumVersionError,\n NetworksUnsupportedBeaconError,\n InvalidBeaconVersionError\n}\n\n// Transport\nexport { Transport, MessageBasedClient, CommunicationClient }\n\n// Storage\nexport { ChromeStorage, LocalStorage, WCStorage, IndexedDBStorage, StorageValidator, getStorage }\n\n// Managers\nexport { PeerManager, AccountManager, AppMetadataManager, PermissionManager }\n\n// Constants\nexport {\n SDK_VERSION,\n DEFAULT_WALLETCONNECT_PROJECT_ID,\n BEACON_VERSION,\n PROTOCOL_VERSION_V1,\n PROTOCOL_VERSION_V2,\n LATEST_PROTOCOL_VERSION,\n DEFAULT_PROTOCOL_VERSION,\n getPreferredMessageProtocolVersion,\n setPreferredMessageProtocolVersion\n}\n\n// Utils\nexport { getSenderId, getAccountIdentifier, windowRef, MultiTabChannel }\nexport {\n usesWrappedMessages,\n MESSAGE_WRAPPED_FROM_VERSION,\n MULTI_NETWORK_FROM_VERSION,\n compareBeaconVersion,\n isAtLeastVersion,\n isMultiNetworkVersion,\n negotiateEnvelopeVersion,\n effectivePeerVersion,\n wrapBeaconMessage,\n unwrapBeaconMessage\n} from './utils/message-utils'\nexport {\n normalizeTezosCaip2,\n isValidTezosCaip2,\n networkFromTezosCaip2,\n TEZOS_NETWORK_GENESIS_IDS,\n tezosCaip2FromNetworkType,\n networkTypeFromTezosCaip2\n} from './utils/caip2'\nexport { assertNever } from './utils/assert-never'\nexport { resolveRequiredMinimumVersion } from './utils/required-minimum-version'\n\n// Diagnostics\nexport {\n gatherDiagnostics,\n buildErrorContext,\n serializeErrorContext,\n copyErrorContextToClipboard,\n SENSITIVE_STORAGE_KEYS\n} from './utils/diagnostics'\n\n// Error codes\nexport { ERROR_CODES, WC_ERROR_CODES, MATRIX_ERROR_CODES, PM_ERROR_CODES, BLOCKCHAIN_ERROR_CODES, BEACON_ERROR_CODES } from './errors/error-codes'\nexport type { ErrorCode } from './errors/error-codes'\n\n// Others\nexport { Serializer, Logger, setLogger, getLogger }\n\n// Debug\nexport { setDebugEnabled, getDebugEnabled }\n\nexport { NOTIFICATION_ORACLE_URL, BACKEND_URL } from './constants'\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":";;;;;;;AAAA;;;GAGG;AACH,oDAAgD;AAgEJ,uFAhEnC,eAAM,OAgEmC;AA/DlD,sDAAkD;AAoEhD,4FApEO,yBAAW,OAoEP;AAnEb,wEAAoE;AAqElE,qGArEO,2CAAoB,OAqEP;AApEtB,4FAAwF;AAqEtF,+GArEO,+DAA8B,OAqEP;AApEhC,wEAAoE;AAqElE,qGArEO,2CAAoB,OAqEP;AApEtB,8EAA0E;AAqExE,wGArEO,iDAAuB,OAqEP;AApEzB,0EAAsE;AAqEpE,sGArEO,6CAAqB,OAqEP;AApEvB,wFAAoF;AAqElF,6GArEO,2DAA4B,OAqEP;AApE9B,wFAAoF;AAqElF,6GArEO,2DAA4B,OAqEP;AApE9B,0FAAsF;AAqEp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IAAA,6BAA6B,OAAA;AAEtC,cAAc;AACd,mDAM4B;AAL1B,gHAAA,iBAAiB,OAAA;AACjB,gHAAA,iBAAiB,OAAA;AACjB,oHAAA,qBAAqB,OAAA;AACrB,0HAAA,2BAA2B,OAAA;AAC3B,qHAAA,sBAAsB,OAAA;AAGxB,cAAc;AACd,oDAAkJ;AAAzI,0GAAA,WAAW,OAAA;AAAE,6GAAA,cAAc,OAAA;AAAE,iHAAA,kBAAkB,OAAA;AAAE,6GAAA,cAAc,OAAA;AAAE,qHAAA,sBAAsB,OAAA;AAAE,iHAAA,kBAAkB,OAAA;AASpH,yCAAkE;AAAzD,oHAAA,uBAAuB,OAAA;AAAE,wGAAA,WAAW,OAAA","sourcesContent":["/**\n * General docs\n * @module public\n */\nimport { Client } from './clients/client/Client'\nimport { BeaconError } from './errors/BeaconError'\nimport { BroadcastBeaconError } from './errors/BroadcastBeaconError'\nimport { NetworkNotSupportedBeaconError } from './errors/NetworkNotSupportedBeaconError'\nimport { NoAddressBeaconError } from './errors/NoAddressBeaconError'\nimport { NoPrivateKeyBeaconError } from './errors/NoPrivateKeyBeaconError'\nimport { NotGrantedBeaconError } from './errors/NotGrantedBeaconError'\nimport { ParametersInvalidBeaconError } from './errors/ParametersInvalidBeaconError'\nimport { TooManyOperationsBeaconError } from './errors/TooManyOperationsBeaconError'\nimport { TransactionInvalidBeaconError } from './errors/TransactionInvalidBeaconError'\nimport { UnknownBeaconError } from './errors/UnknownBeaconError'\nimport { Transport } from './transports/Transport'\nimport { ChromeStorage } from './storage/ChromeStorage'\nimport { LocalStorage } from './storage/LocalStorage'\nimport { getStorage } from './storage/getStorage'\nimport { Serializer } from './Serializer'\n// import { RequestEncryptPayloadInput } from './types/RequestEncryptPayloadInput'\nimport { ClientOptions } from './clients/client/ClientOptions'\nimport {\n SDK_VERSION,\n DEFAULT_WALLETCONNECT_PROJECT_ID,\n BEACON_VERSION,\n PROTOCOL_VERSION_V1,\n PROTOCOL_VERSION_V2,\n LATEST_PROTOCOL_VERSION,\n DEFAULT_PROTOCOL_VERSION\n} from './constants'\nimport {\n getPreferredMessageProtocolVersion,\n setPreferredMessageProtocolVersion\n} from './message-protocol'\nimport { AccountManager } from './managers/AccountManager'\nimport { AppMetadataManager } from './managers/AppMetadataManager'\nimport { PermissionManager } from './managers/PermissionManager'\nimport { BeaconClient } from './clients/beacon-client/BeaconClient'\nimport { BeaconClientOptions } from './clients/beacon-client/BeaconClientOptions'\nimport { getAccountIdentifier } from './utils/get-account-identifier'\nimport { AbortedBeaconError } from './errors/AbortedBeaconError'\nimport { getSenderId } from './utils/get-sender-id'\nimport { PeerManager } from './managers/PeerManager'\nimport { MessageBasedClient } from './transports/clients/MessageBasedClient'\nimport { setDebugEnabled, getDebugEnabled } from './debug'\n// import { EncryptPayloadRequest } from './types/beacon/messages/EncryptPayloadRequest'\n// import { EncryptPayloadResponse } from './types/beacon/messages/EncryptPayloadResponse'\n// import { EncryptionTypeNotSupportedBeaconError } from './errors/EncryptionTypeNotSupportedBeaconError'\nimport { SignatureTypeNotSupportedBeaconError } from './errors/SignatureTypeNotSupportedBeaconError'\nimport { VersionUnsupportedBeaconError } from './errors/VersionUnsupportedBeaconError'\nimport { InvalidRequiredMinimumVersionError } from './errors/InvalidRequiredMinimumVersionError'\nimport { NetworksUnsupportedBeaconError } from './errors/NetworksUnsupportedBeaconError'\nimport { InvalidBeaconVersionError } from './errors/InvalidBeaconVersionError'\nimport { getLogger, Logger, setLogger } from './utils/Logger'\nimport { windowRef } from './MockWindow'\nimport { CommunicationClient } from './transports/clients/CommunicationClient'\nimport { PendingPairingRequests } from './transports/clients/PendingPairingRequests'\nimport { ClientEvents } from './transports/clients/ClientEvents'\nimport { WCStorage } from './storage/WCStorage'\nimport { IndexedDBStorage } from './storage/IndexedDBStorage'\nimport { StorageValidator } from './storage/StorageValidator'\nimport { MultiTabChannel } from './utils/multi-tab-channel'\nimport getError from './errors/get-error'\n// import { EncryptionType } from './types/EncryptionType'\n// import { EncryptionOperation } from './types/EncryptionOperation'\n\n// Clients\nexport { BeaconClient, BeaconClientOptions, Client, ClientOptions, ClientEvents }\n\n// Errors\nexport {\n getError,\n BeaconError,\n AbortedBeaconError,\n BroadcastBeaconError,\n NetworkNotSupportedBeaconError,\n NoAddressBeaconError,\n NoPrivateKeyBeaconError,\n NotGrantedBeaconError,\n ParametersInvalidBeaconError,\n TooManyOperationsBeaconError,\n TransactionInvalidBeaconError,\n SignatureTypeNotSupportedBeaconError,\n // EncryptionTypeNotSupportedBeaconError,\n UnknownBeaconError,\n VersionUnsupportedBeaconError,\n InvalidRequiredMinimumVersionError,\n NetworksUnsupportedBeaconError,\n InvalidBeaconVersionError\n}\n\n// Transport\nexport { Transport, MessageBasedClient, CommunicationClient, PendingPairingRequests }\n\n// Storage\nexport { ChromeStorage, LocalStorage, WCStorage, IndexedDBStorage, StorageValidator, getStorage }\n\n// Managers\nexport { PeerManager, AccountManager, AppMetadataManager, PermissionManager }\n\n// Constants\nexport {\n SDK_VERSION,\n DEFAULT_WALLETCONNECT_PROJECT_ID,\n BEACON_VERSION,\n PROTOCOL_VERSION_V1,\n PROTOCOL_VERSION_V2,\n LATEST_PROTOCOL_VERSION,\n DEFAULT_PROTOCOL_VERSION,\n getPreferredMessageProtocolVersion,\n setPreferredMessageProtocolVersion\n}\n\n// Utils\nexport { getSenderId, getAccountIdentifier, windowRef, MultiTabChannel }\nexport {\n usesWrappedMessages,\n MESSAGE_WRAPPED_FROM_VERSION,\n MULTI_NETWORK_FROM_VERSION,\n compareBeaconVersion,\n isAtLeastVersion,\n isMultiNetworkVersion,\n negotiateEnvelopeVersion,\n effectivePeerVersion,\n wrapBeaconMessage,\n unwrapBeaconMessage\n} from './utils/message-utils'\nexport {\n normalizeTezosCaip2,\n isValidTezosCaip2,\n networkFromTezosCaip2,\n TEZOS_NETWORK_GENESIS_IDS,\n tezosCaip2FromNetworkType,\n networkTypeFromTezosCaip2\n} from './utils/caip2'\nexport { assertNever } from './utils/assert-never'\nexport { resolveRequiredMinimumVersion } from './utils/required-minimum-version'\n\n// Diagnostics\nexport {\n gatherDiagnostics,\n buildErrorContext,\n serializeErrorContext,\n copyErrorContextToClipboard,\n SENSITIVE_STORAGE_KEYS\n} from './utils/diagnostics'\n\n// Error codes\nexport { ERROR_CODES, WC_ERROR_CODES, MATRIX_ERROR_CODES, PM_ERROR_CODES, BLOCKCHAIN_ERROR_CODES, BEACON_ERROR_CODES } from './errors/error-codes'\nexport type { ErrorCode } from './errors/error-codes'\n\n// Others\nexport { Serializer, Logger, setLogger, getLogger }\n\n// Debug\nexport { setDebugEnabled, getDebugEnabled }\n\nexport { NOTIFICATION_ORACLE_URL, BACKEND_URL } from './constants'\n"]}
@@ -0,0 +1,20 @@
1
+ /**
2
+ * Pairing request ids this dApp has handed out (QR code, deep link, extension).
3
+ * A pairing reply is only accepted if it answers one of them, once.
4
+ *
5
+ * In memory on purpose (same as the ECAD 4.8.5 fix): storage cannot make
6
+ * "use once" hold across tabs, so a reload while a pairing is still open
7
+ * needs a fresh QR code or deep link. Already-paired sessions are unaffected.
8
+ *
9
+ * @internalapi
10
+ */
11
+ export declare class PendingPairingRequests {
12
+ private readonly requests;
13
+ add(id: string): void;
14
+ hasPending(): boolean;
15
+ /** True if `id` was pending. Clears every pending request, so only one reply wins. */
16
+ consume(id: string): boolean;
17
+ /** Forget every pending request, e.g. when the pairing popup closes. */
18
+ clear(): void;
19
+ private prune;
20
+ }
@@ -0,0 +1,55 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PendingPairingRequests = void 0;
4
+ const TTL_MS = 30 * 60 * 1000;
5
+ const MAX_PENDING = 32;
6
+ /**
7
+ * Pairing request ids this dApp has handed out (QR code, deep link, extension).
8
+ * A pairing reply is only accepted if it answers one of them, once.
9
+ *
10
+ * In memory on purpose (same as the ECAD 4.8.5 fix): storage cannot make
11
+ * "use once" hold across tabs, so a reload while a pairing is still open
12
+ * needs a fresh QR code or deep link. Already-paired sessions are unaffected.
13
+ *
14
+ * @internalapi
15
+ */
16
+ class PendingPairingRequests {
17
+ constructor() {
18
+ this.requests = new Map(); // id -> expiry
19
+ }
20
+ add(id) {
21
+ this.prune();
22
+ this.requests.set(id, Date.now() + TTL_MS);
23
+ // Map keeps insertion order, so the first key is the oldest.
24
+ while (this.requests.size > MAX_PENDING) {
25
+ this.requests.delete(this.requests.keys().next().value);
26
+ }
27
+ }
28
+ hasPending() {
29
+ this.prune();
30
+ return this.requests.size > 0;
31
+ }
32
+ /** True if `id` was pending. Clears every pending request, so only one reply wins. */
33
+ consume(id) {
34
+ this.prune();
35
+ if (!this.requests.has(id)) {
36
+ return false;
37
+ }
38
+ this.clear();
39
+ return true;
40
+ }
41
+ /** Forget every pending request, e.g. when the pairing popup closes. */
42
+ clear() {
43
+ this.requests.clear();
44
+ }
45
+ prune() {
46
+ const now = Date.now();
47
+ for (const [id, expiry] of this.requests) {
48
+ if (expiry <= now) {
49
+ this.requests.delete(id);
50
+ }
51
+ }
52
+ }
53
+ }
54
+ exports.PendingPairingRequests = PendingPairingRequests;
55
+ //# sourceMappingURL=PendingPairingRequests.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PendingPairingRequests.js","sourceRoot":"","sources":["../../../../../src/transports/clients/PendingPairingRequests.ts"],"names":[],"mappings":";;;AAAA,MAAM,MAAM,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI,CAAA;AAC7B,MAAM,WAAW,GAAG,EAAE,CAAA;AAEtB;;;;;;;;;GASG;AACH,MAAa,sBAAsB;IAAnC;QACmB,aAAQ,GAAG,IAAI,GAAG,EAAkB,CAAA,CAAC,eAAe;IAyCvE,CAAC;IAvCQ,GAAG,CAAC,EAAU;QACnB,IAAI,CAAC,KAAK,EAAE,CAAA;QACZ,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,EAAE,IAAI,CAAC,GAAG,EAAE,GAAG,MAAM,CAAC,CAAA;QAC1C,6DAA6D;QAC7D,OAAO,IAAI,CAAC,QAAQ,CAAC,IAAI,GAAG,WAAW,EAAE,CAAC;YACxC,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,EAAE,CAAC,IAAI,EAAE,CAAC,KAAe,CAAC,CAAA;QACnE,CAAC;IACH,CAAC;IAEM,UAAU;QACf,IAAI,CAAC,KAAK,EAAE,CAAA;QAEZ,OAAO,IAAI,CAAC,QAAQ,CAAC,IAAI,GAAG,CAAC,CAAA;IAC/B,CAAC;IAED,sFAAsF;IAC/E,OAAO,CAAC,EAAU;QACvB,IAAI,CAAC,KAAK,EAAE,CAAA;QACZ,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,CAAC;YAC3B,OAAO,KAAK,CAAA;QACd,CAAC;QACD,IAAI,CAAC,KAAK,EAAE,CAAA;QAEZ,OAAO,IAAI,CAAA;IACb,CAAC;IAED,wEAAwE;IACjE,KAAK;QACV,IAAI,CAAC,QAAQ,CAAC,KAAK,EAAE,CAAA;IACvB,CAAC;IAEO,KAAK;QACX,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,EAAE,CAAA;QACtB,KAAK,MAAM,CAAC,EAAE,EAAE,MAAM,CAAC,IAAI,IAAI,CAAC,QAAQ,EAAE,CAAC;YACzC,IAAI,MAAM,IAAI,GAAG,EAAE,CAAC;gBAClB,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,EAAE,CAAC,CAAA;YAC1B,CAAC;QACH,CAAC;IACH,CAAC;CACF;AA1CD,wDA0CC","sourcesContent":["const TTL_MS = 30 * 60 * 1000\nconst MAX_PENDING = 32\n\n/**\n * Pairing request ids this dApp has handed out (QR code, deep link, extension).\n * A pairing reply is only accepted if it answers one of them, once.\n *\n * In memory on purpose (same as the ECAD 4.8.5 fix): storage cannot make\n * \"use once\" hold across tabs, so a reload while a pairing is still open\n * needs a fresh QR code or deep link. Already-paired sessions are unaffected.\n *\n * @internalapi\n */\nexport class PendingPairingRequests {\n private readonly requests = new Map<string, number>() // id -> expiry\n\n public add(id: string): void {\n this.prune()\n this.requests.set(id, Date.now() + TTL_MS)\n // Map keeps insertion order, so the first key is the oldest.\n while (this.requests.size > MAX_PENDING) {\n this.requests.delete(this.requests.keys().next().value as string)\n }\n }\n\n public hasPending(): boolean {\n this.prune()\n\n return this.requests.size > 0\n }\n\n /** True if `id` was pending. Clears every pending request, so only one reply wins. */\n public consume(id: string): boolean {\n this.prune()\n if (!this.requests.has(id)) {\n return false\n }\n this.clear()\n\n return true\n }\n\n /** Forget every pending request, e.g. when the pairing popup closes. */\n public clear(): void {\n this.requests.clear()\n }\n\n private prune(): void {\n const now = Date.now()\n for (const [id, expiry] of this.requests) {\n if (expiry <= now) {\n this.requests.delete(id)\n }\n }\n }\n}\n"]}
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tezos-x/octez.connect-core",
3
- "version": "5.0.3",
3
+ "version": "5.0.5",
4
4
  "description": "This package contains internal methods that are used by both the dApp and wallet client.",
5
5
  "author": "Blockchain Infra <blockchain.infra@trili.tech>",
6
6
  "homepage": "https://octez-connect.tezos.com",
@@ -38,8 +38,8 @@
38
38
  "@stablelib/nacl": "^2.0.1",
39
39
  "@stablelib/utf8": "^2.1.0",
40
40
  "@stablelib/x25519-session": "^2.0.1",
41
- "@tezos-x/octez.connect-types": "5.0.3",
42
- "@tezos-x/octez.connect-utils": "5.0.3",
41
+ "@tezos-x/octez.connect-types": "5.0.5",
42
+ "@tezos-x/octez.connect-utils": "5.0.5",
43
43
  "broadcast-channel": "^7.3.0",
44
44
  "bs58check": "4.0.0"
45
45
  }
@@ -27,7 +27,14 @@ export declare abstract class Client extends BeaconClient {
27
27
  */
28
28
  protected requestCounter: number[];
29
29
  protected readonly matrixNodes: NodeDistributions;
30
- private transportListeners;
30
+ /**
31
+ * One subscription per transport type, together with the transport instance
32
+ * it is attached to. The instance is needed to detach: a replaced transport
33
+ * outlives the client's reference to it (`disconnect()` and
34
+ * `handleDisconnect()` only null the reference), so removing the listener
35
+ * from the *incoming* transport would leave the old one subscribed.
36
+ */
37
+ private readonly transportListeners;
31
38
  protected _transport: ExposedPromise<Transport<any>>;
32
39
  protected get transport(): Promise<Transport<any>>;
33
40
  /**
@@ -99,7 +106,24 @@ export declare abstract class Client extends BeaconClient {
99
106
  protected setTransport(transport?: Transport<any>): Promise<void>;
100
107
  protected addListener(transport: Transport<any>): Promise<void>;
101
108
  protected sendDisconnectToPeer(peer: PeerInfo, transport?: Transport<any>): Promise<void>;
102
- protected findPeer(publicKey?: string): Promise<PeerInfo | undefined>;
109
+ /**
110
+ * Look a peer up by the id the transport attached to a message, on the
111
+ * transport that delivered it.
112
+ *
113
+ * The transport is a parameter rather than a lookup because every caller
114
+ * already has one: a message can only have been delivered by a transport
115
+ * that exists. Reaching for `this.transport` instead parked every arrival
116
+ * between a disconnection and the next pairing -- setTransport(undefined)
117
+ * leaves `_transport` unsettled, so the await only returned once a later
118
+ * pairing resolved it, and the message was replayed into that connection.
119
+ *
120
+ * `connectionInfo.id` is the peer's public key over P2P, but the browser
121
+ * extension's id over postMessage, where the transport cannot tell which
122
+ * peer's key decrypted the message. Match either: only a postMessage
123
+ * pairing response carries an `extensionId`, so the fallback is inert for
124
+ * every other peer.
125
+ */
126
+ protected findPeer(id: string | undefined, transport: Transport<any>): Promise<PeerInfo | undefined>;
103
127
  private getLocalProtocolVersion;
104
128
  private extractPeerProtocolVersion;
105
129
  protected getPeerProtocolVersion(peer?: PeerInfo): number;
@@ -32,6 +32,13 @@ export class Client extends BeaconClient {
32
32
  */
33
33
  requestCounter = [];
34
34
  matrixNodes;
35
+ /**
36
+ * One subscription per transport type, together with the transport instance
37
+ * it is attached to. The instance is needed to detach: a replaced transport
38
+ * outlives the client's reference to it (`disconnect()` and
39
+ * `handleDisconnect()` only null the reference), so removing the listener
40
+ * from the *incoming* transport would leave the old one subscribed.
41
+ */
35
42
  transportListeners = new Map();
36
43
  _transport = new ExposedPromise();
37
44
  get transport() {
@@ -61,11 +68,12 @@ export class Client extends BeaconClient {
61
68
  if (!this.transportListeners.size) {
62
69
  return;
63
70
  }
64
- if (this._transport.isResolved()) {
65
- const transport = await this.transport;
66
- await Promise.all(Array.from(this.transportListeners.values()).map((listener) => transport.removeListener(listener)));
67
- this.transportListeners.clear();
68
- }
71
+ // Each subscription is removed from the transport it is attached to.
72
+ // Going through `this.transport` removed them all from whichever transport
73
+ // was active, and removed none when no transport was resolved -- the state
74
+ // `disconnect()` leaves behind.
75
+ await Promise.all(Array.from(this.transportListeners.values()).map(({ transport, listener }) => transport.removeListener(listener)));
76
+ this.transportListeners.clear();
69
77
  }
70
78
  /**
71
79
  * Register a blockchain to the client
@@ -160,9 +168,12 @@ export class Client extends BeaconClient {
160
168
  return (await this.transport).addPeer(peer);
161
169
  }
162
170
  async destroy() {
171
+ // Subscriptions are detached from their own transports, so this no longer
172
+ // needs an active one -- after disconnect() there is none, and that is
173
+ // precisely when the orphaned subscriptions have to go.
174
+ await this.cleanup();
163
175
  if (this._transport.isResolved()) {
164
176
  const transport = await this.transport;
165
- await this.cleanup();
166
177
  await transport.disconnect();
167
178
  if (transport.type === TransportType.WALLETCONNECT) {
168
179
  await transport.doClientCleanup(); // any because I cannot import the type definition
@@ -196,19 +207,25 @@ export class Client extends BeaconClient {
196
207
  // a single page dApp.
197
208
  // However, while running a multiple tabs setup, if one of the dApps disconnects
198
209
  // the others wont't recover until after a page refresh
199
- if (this.transportListeners.has(transport.type)) {
200
- await transport.removeListener(this.transportListeners.get(transport.type));
210
+ // Detach the previous subscription from the transport it is actually
211
+ // attached to. Calling removeListener on the incoming transport, which never
212
+ // had it, left every replaced transport subscribed: they share the client's
213
+ // key pair, so each one kept decrypting wallet messages and routing them into
214
+ // handleResponse -- once per past connection.
215
+ const previous = this.transportListeners.get(transport.type);
216
+ if (previous) {
217
+ await previous.transport.removeListener(previous.listener);
201
218
  }
202
219
  const subscription = async (message, connectionInfo) => {
203
220
  if (typeof message !== 'string') {
204
221
  return;
205
222
  }
206
- const peer = await this.findPeer(connectionInfo.id);
223
+ const peer = await this.findPeer(connectionInfo.id, transport);
207
224
  const protocolVersion = this.getPeerProtocolVersion(peer);
208
225
  const deserializedMessage = (await new Serializer(protocolVersion).deserialize(message));
209
226
  this.handleResponse(deserializedMessage, connectionInfo);
210
227
  };
211
- this.transportListeners.set(transport.type, subscription);
228
+ this.transportListeners.set(transport.type, { transport, listener: subscription });
212
229
  transport.addListener(subscription).catch((error) => logger.error('addListener', error));
213
230
  }
214
231
  async sendDisconnectToPeer(peer, transport) {
@@ -223,13 +240,38 @@ export class Client extends BeaconClient {
223
240
  const selectedTransport = transport ?? (await this.transport);
224
241
  await selectedTransport.send(payload, peer);
225
242
  }
226
- async findPeer(publicKey) {
227
- if (!publicKey) {
243
+ /**
244
+ * Look a peer up by the id the transport attached to a message, on the
245
+ * transport that delivered it.
246
+ *
247
+ * The transport is a parameter rather than a lookup because every caller
248
+ * already has one: a message can only have been delivered by a transport
249
+ * that exists. Reaching for `this.transport` instead parked every arrival
250
+ * between a disconnection and the next pairing -- setTransport(undefined)
251
+ * leaves `_transport` unsettled, so the await only returned once a later
252
+ * pairing resolved it, and the message was replayed into that connection.
253
+ *
254
+ * `connectionInfo.id` is the peer's public key over P2P, but the browser
255
+ * extension's id over postMessage, where the transport cannot tell which
256
+ * peer's key decrypted the message. Match either: only a postMessage
257
+ * pairing response carries an `extensionId`, so the fallback is inert for
258
+ * every other peer.
259
+ */
260
+ async findPeer(id,
261
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
262
+ transport) {
263
+ if (!id) {
228
264
  return undefined;
229
265
  }
230
- const transport = await this.transport;
231
266
  const peers = await transport.getPeers();
232
- return peers.find((peerInfo) => peerInfo.publicKey === publicKey);
267
+ return (peers.find((peerInfo) => peerInfo.publicKey === id) ??
268
+ // Newest first. `addPeer` dedupes by public key, so a wallet that rotated
269
+ // its beacon key -- a reinstall, a reset -- leaves the stale peer in place
270
+ // beside the new one, both carrying the same extension id. A fresh pairing
271
+ // has to shadow the stale peer, not the other way round.
272
+ [...peers]
273
+ .reverse()
274
+ .find((peerInfo) => 'extensionId' in peerInfo && peerInfo.extensionId === id));
233
275
  }
234
276
  getLocalProtocolVersion() {
235
277
  const localPreferredRaw = Number(getPreferredMessageProtocolVersion());
@@ -1 +1 @@
1
- {"version":3,"file":"Client.js","sourceRoot":"","sources":["../../../../../src/clients/client/Client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,8BAA8B,CAAA;AAC3E,OAAO,EAEL,aAAa,EACb,eAAe,EAShB,MAAM,8BAA8B,CAAA;AACrC,OAAO,EAAE,wBAAwB,EAAE,MAAM,iBAAiB,CAAA;AAC1D,OAAO,EAAE,YAAY,EAAE,MAAM,+BAA+B,CAAA;AAC5D,OAAO,EAAE,cAAc,EAAE,MAAM,+BAA+B,CAAA;AAC9D,OAAO,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAA;AACvD,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAA;AAG3C,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAA;AAC7C,OAAO,EAAE,sBAAsB,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAA;AACxF,OAAO,EAAE,kCAAkC,EAAE,MAAM,wBAAwB,CAAA;AAE3E,MAAM,MAAM,GAAG,IAAI,MAAM,CAAC,QAAQ,CAAC,CAAA;AAEnC;;;;;GAKG;AACH,MAAM,OAAgB,MAAO,SAAQ,YAAY;IAC5B,cAAc,CAAgB;IAC9B,WAAW,GAA4B,IAAI,GAAG,EAAE,CAAA;IAEzD,cAAc,CAGf;IAET;;OAEG;IACgB,SAAS,GAAW,CAAC,CAAA;IACxC;;OAEG;IACgB,wBAAwB,GAAW,CAAC,CAAA;IAEvD;;OAEG;IACO,cAAc,GAAa,EAAE,CAAA;IAEpB,WAAW,CAAmB;IAEzC,kBAAkB,GAGtB,IAAI,GAAG,EA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,GAAG,IAAI,CAAC,0BAA0B,CAAC,IAAI,CAAC,CAAA;QACzD,OAAO,IAAI,CAAC,GAAG,CAAC,WAAW,EAAE,YAAY,CAAC,CAAA;IAC5C,CAAC;CACF","sourcesContent":["import { ExposedPromise, generateGUID } from '@tezos-x/octez.connect-utils'\nimport {\n ConnectionContext,\n TransportType,\n TransportStatus,\n BeaconBaseMessage,\n AccountInfo,\n PeerInfo,\n AppMetadata,\n BeaconRequestMessage,\n BeaconMessageWrapper,\n NodeDistributions,\n Blockchain\n} from '@tezos-x/octez.connect-types'\nimport { DEFAULT_PROTOCOL_VERSION } from '../../constants'\nimport { BeaconClient } from '../beacon-client/BeaconClient'\nimport { AccountManager } from '../../managers/AccountManager'\nimport { getSenderId } from '../../utils/get-sender-id'\nimport { Logger } from '../../utils/Logger'\nimport { ClientOptions } from './ClientOptions'\nimport { Transport } from '../../transports/Transport'\nimport { Serializer } from '../../Serializer'\nimport { buildDisconnectMessage, effectivePeerVersion } from '../../utils/message-utils'\nimport { getPreferredMessageProtocolVersion } from '../../message-protocol'\n\nconst logger = new Logger('Client')\n\n/**\n * @internalapi\n *\n * This abstract class handles the a big part of the logic that is shared between the dapp and wallet client.\n * For example, it selects and manages the transport and accounts.\n */\nexport abstract class Client extends BeaconClient {\n protected readonly accountManager: AccountManager\n protected readonly blockchains: Map<string, Blockchain> = new Map()\n\n protected handleResponse: (\n _event: BeaconRequestMessage | BeaconMessageWrapper<BeaconBaseMessage>,\n connectionInfo: ConnectionContext\n ) => void\n\n /**\n * How many requests can be sent after another\n */\n protected readonly rateLimit: number = 2\n /**\n * The time window in seconds in which the \"rateLimit\" is checked\n */\n protected readonly rateLimitWindowInSeconds: number = 5\n\n /**\n * Stores the times when requests have been made to determine if the rate limit has been reached\n */\n protected requestCounter: number[] = []\n\n protected readonly matrixNodes: NodeDistributions\n\n private transportListeners: Map<\n TransportType,\n (message: any, connectionInfo: ConnectionContext) => Promise<void>\n > = new Map()\n\n protected _transport: ExposedPromise<Transport<any>> = new ExposedPromise()\n protected get transport(): Promise<Transport<any>> {\n return this._transport.promise\n }\n\n /**\n * Returns the connection status of the Client\n */\n public get connectionStatus(): TransportStatus {\n return this._transport.promiseResult?.connectionStatus ?? TransportStatus.NOT_CONNECTED\n }\n\n /**\n * Returns whether or not the transaport is ready\n */\n public get ready(): Promise<void> {\n return this.transport.then(() => undefined)\n }\n\n constructor(config: ClientOptions) {\n super(config)\n\n this.accountManager = new AccountManager(config.storage)\n this.matrixNodes = config.matrixNodes ?? {}\n\n this.handleResponse = (\n message: BeaconBaseMessage | BeaconMessageWrapper<BeaconBaseMessage>,\n connectionInfo: ConnectionContext\n ): void => {\n throw new Error(\n `not overwritten${JSON.stringify(message)} - ${JSON.stringify(connectionInfo)}`\n )\n }\n }\n protected async cleanup() {\n if (!this.transportListeners.size) {\n return\n }\n\n if (this._transport.isResolved()) {\n const transport = await this.transport\n await Promise.all(\n Array.from(this.transportListeners.values()).map((listener) =>\n transport.removeListener(listener)\n )\n )\n this.transportListeners.clear()\n }\n }\n\n /**\n * Register a blockchain to the client\n * @param chain The blockchain to register\n */\n public addBlockchain(chain: Blockchain) {\n this.blockchains.set(chain.identifier, chain)\n for (const legacyIdentifier of chain.legacyIdentifiers ?? []) {\n this.blockchains.set(legacyIdentifier, chain)\n }\n }\n\n /**\n * Remove a blockchain from the client by its identifier\n * @param chainIdentifier The identifier of the blockchain to remove\n */\n public removeBlockchain(chainIdentifier: string) {\n const chain = this.blockchains.get(chainIdentifier)\n this.blockchains.delete(chainIdentifier)\n for (const legacyIdentifier of chain?.legacyIdentifiers ?? []) {\n this.blockchains.delete(legacyIdentifier)\n }\n }\n\n /**\n * Return all locally known accounts\n */\n public async getAccounts(): Promise<AccountInfo[]> {\n return this.accountManager.getAccounts()\n }\n\n /**\n * Return the account by ID\n * @param accountIdentifier The ID of an account\n */\n public async getAccount(accountIdentifier: string): Promise<AccountInfo | undefined> {\n return this.accountManager.getAccount(accountIdentifier)\n }\n\n /**\n * Remove the account by ID\n * @param accountIdentifier The ID of an account\n */\n public async removeAccount(accountIdentifier: string): Promise<void> {\n return this.accountManager.removeAccount(accountIdentifier)\n }\n\n /**\n * Remove all locally stored accounts\n */\n public async removeAllAccounts(): Promise<void> {\n return this.accountManager.removeAllAccounts()\n }\n\n /**\n * Add a new request (current timestamp) to the pending requests, remove old ones and check if we are above the limit\n */\n public async addRequestAndCheckIfRateLimited(): Promise<boolean> {\n const now: number = new Date().getTime()\n this.requestCounter = this.requestCounter.filter(\n (date) => date + this.rateLimitWindowInSeconds * 1000 > now\n )\n\n this.requestCounter.push(now)\n\n return this.requestCounter.length > this.rateLimit\n }\n\n /**\n * This method initializes the client. It will check if the connection should be established to a\n * browser extension or if the P2P transport should be used.\n *\n * @param transport A transport that can be provided by the user\n */\n public async init(transport: Transport<any, any, any>): Promise<TransportType> {\n if (this._transport.isResolved()) {\n return (await this.transport).type\n }\n\n await this.setTransport(transport) // Let users define their own transport\n\n return transport.type\n }\n\n /**\n * Returns the metadata of this DApp\n */\n public async getOwnAppMetadata(): Promise<AppMetadata> {\n return {\n senderId: await getSenderId(await this.beaconId),\n name: this.name,\n icon: this.iconUrl\n }\n }\n\n /**\n * Return all known peers\n */\n public async getPeers(): Promise<PeerInfo[]> {\n return (await this.transport).getPeers()\n }\n\n /**\n * Add a new peer to the known peers\n * @param peer The new peer to add\n */\n public async addPeer(peer: PeerInfo): Promise<void> {\n return (await this.transport).addPeer(peer)\n }\n\n public async destroy(): Promise<void> {\n if (this._transport.isResolved()) {\n const transport = await this.transport\n await this.cleanup()\n await transport.disconnect()\n if (transport.type === TransportType.WALLETCONNECT) {\n await (transport as any).doClientCleanup() // any because I cannot import the type definition\n }\n }\n await super.destroy()\n }\n\n /**\n * A \"setter\" for when the transport needs to be changed.\n */\n protected async setTransport(transport?: Transport<any>): Promise<void> {\n if (transport) {\n if (this._transport.isSettled()) {\n // If the promise has already been resolved we need to create a new one.\n this._transport = ExposedPromise.resolve(transport)\n } else {\n this._transport.resolve(transport)\n }\n } else {\n if (this._transport.isSettled()) {\n // If the promise has already been resolved we need to create a new one.\n this._transport = new ExposedPromise()\n }\n }\n }\n\n protected async addListener(transport: Transport<any>): Promise<void> {\n // in beacon we subscribe to the transport on client init only\n // unsubscribing from the transport is only beneficial when running\n // a single page dApp.\n // However, while running a multiple tabs setup, if one of the dApps disconnects\n // the others wont't recover until after a page refresh\n\n if (this.transportListeners.has(transport.type)) {\n await transport.removeListener(this.transportListeners.get(transport.type)!)\n }\n\n const subscription = async (message: any, connectionInfo: ConnectionContext) => {\n if (typeof message !== 'string') {\n return\n }\n\n const peer = await this.findPeer(connectionInfo.id)\n const protocolVersion = this.getPeerProtocolVersion(peer)\n\n const deserializedMessage = (await new Serializer(protocolVersion).deserialize(\n message\n )) as BeaconRequestMessage\n this.handleResponse(deserializedMessage, connectionInfo)\n }\n\n this.transportListeners.set(transport.type, subscription)\n\n transport.addListener(subscription).catch((error) => logger.error('addListener', error))\n }\n\n protected async sendDisconnectToPeer(peer: PeerInfo, transport?: Transport<any>): Promise<void> {\n const id = await generateGUID()\n const senderId = await getSenderId(await this.beaconId)\n\n // The disconnect ships in the peer's negotiated dialect: wrapped for\n // v3+ peers, the flat legacy shape for v2 peers (which would silently\n // ignore a wrapped envelope).\n const request = buildDisconnectMessage({ id, senderId }, effectivePeerVersion(peer))\n\n const protocolVersion = this.getPeerProtocolVersion(peer)\n const payload = await new Serializer(protocolVersion).serialize(request)\n const selectedTransport = transport ?? (await this.transport)\n\n await selectedTransport.send(payload, peer)\n }\n\n protected async findPeer(publicKey?: string): Promise<PeerInfo | undefined> {\n if (!publicKey) {\n return undefined\n }\n\n const transport = await this.transport\n const peers = await transport.getPeers()\n return peers.find((peerInfo) => peerInfo.publicKey === publicKey)\n }\n\n private getLocalProtocolVersion(): number {\n const localPreferredRaw = Number(getPreferredMessageProtocolVersion())\n return Number.isFinite(localPreferredRaw) && localPreferredRaw >= DEFAULT_PROTOCOL_VERSION\n ? localPreferredRaw\n : DEFAULT_PROTOCOL_VERSION\n }\n\n private extractPeerProtocolVersion(peer?: PeerInfo): number {\n if (!peer) {\n return DEFAULT_PROTOCOL_VERSION\n }\n\n const peerProtocolRaw =\n typeof peer.protocolVersion === 'number' ? peer.protocolVersion : Number(peer.protocolVersion)\n\n return Number.isFinite(peerProtocolRaw) && peerProtocolRaw >= DEFAULT_PROTOCOL_VERSION\n ? peerProtocolRaw\n : DEFAULT_PROTOCOL_VERSION\n }\n\n protected getPeerProtocolVersion(peer?: PeerInfo): number {\n const localVersion = this.getLocalProtocolVersion()\n const peerVersion = this.extractPeerProtocolVersion(peer)\n return Math.min(peerVersion, localVersion)\n }\n}\n"]}
1
+ {"version":3,"file":"Client.js","sourceRoot":"","sources":["../../../../../src/clients/client/Client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,8BAA8B,CAAA;AAC3E,OAAO,EAEL,aAAa,EACb,eAAe,EAShB,MAAM,8BAA8B,CAAA;AACrC,OAAO,EAAE,wBAAwB,EAAE,MAAM,iBAAiB,CAAA;AAC1D,OAAO,EAAE,YAAY,EAAE,MAAM,+BAA+B,CAAA;AAC5D,OAAO,EAAE,cAAc,EAAE,MAAM,+BAA+B,CAAA;AAC9D,OAAO,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAA;AACvD,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAA;AAG3C,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAA;AAC7C,OAAO,EAAE,sBAAsB,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAA;AACxF,OAAO,EAAE,kCAAkC,EAAE,MAAM,wBAAwB,CAAA;AAE3E,MAAM,MAAM,GAAG,IAAI,MAAM,CAAC,QAAQ,CAAC,CAAA;AAEnC;;;;;GAKG;AACH,MAAM,OAAgB,MAAO,SAAQ,YAAY;IAC5B,cAAc,CAAgB;IAC9B,WAAW,GAA4B,IAAI,GAAG,EAAE,CAAA;I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AI,iBAAiB,IAAI,wBAAwB;YACxF,CAAC,CAAC,iBAAiB;YACnB,CAAC,CAAC,wBAAwB,CAAA;IAC9B,CAAC;IAEO,0BAA0B,CAAC,IAAe;QAChD,IAAI,CAAC,IAAI,EAAE,CAAC;YACV,OAAO,wBAAwB,CAAA;QACjC,CAAC;QAED,MAAM,eAAe,GACnB,OAAO,IAAI,CAAC,eAAe,KAAK,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,eAAe,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,eAAe,CAAC,CAAA;QAChG,OAAO,MAAM,CAAC,QAAQ,CAAC,eAAe,CAAC,IAAI,eAAe,IAAI,wBAAwB;YACpF,CAAC,CAAC,eAAe;YACjB,CAAC,CAAC,wBAAwB,CAAA;IAC9B,CAAC;IAES,sBAAsB,CAAC,IAAe;QAC9C,MAAM,YAAY,GAAG,IAAI,CAAC,uBAAuB,EAAE,CAAA;QACnD,MAAM,WAAW,GAAG,IAAI,CAAC,0BAA0B,CAAC,IAAI,CAAC,CAAA;QAEzD,OAAO,IAAI,CAAC,GAAG,CAAC,WAAW,EAAE,YAAY,CAAC,CAAA;IAC5C,CAAC;CACF","sourcesContent":["import { ExposedPromise, generateGUID } from '@tezos-x/octez.connect-utils'\nimport {\n ConnectionContext,\n TransportType,\n TransportStatus,\n BeaconBaseMessage,\n AccountInfo,\n PeerInfo,\n AppMetadata,\n BeaconRequestMessage,\n BeaconMessageWrapper,\n NodeDistributions,\n Blockchain\n} from '@tezos-x/octez.connect-types'\nimport { DEFAULT_PROTOCOL_VERSION } from '../../constants'\nimport { BeaconClient } from '../beacon-client/BeaconClient'\nimport { AccountManager } from '../../managers/AccountManager'\nimport { getSenderId } from '../../utils/get-sender-id'\nimport { Logger } from '../../utils/Logger'\nimport { ClientOptions } from './ClientOptions'\nimport { Transport } from '../../transports/Transport'\nimport { Serializer } from '../../Serializer'\nimport { buildDisconnectMessage, effectivePeerVersion } from '../../utils/message-utils'\nimport { getPreferredMessageProtocolVersion } from '../../message-protocol'\n\nconst logger = new Logger('Client')\n\n/**\n * @internalapi\n *\n * This abstract class handles the a big part of the logic that is shared between the dapp and wallet client.\n * For example, it selects and manages the transport and accounts.\n */\nexport abstract class Client extends BeaconClient {\n protected readonly accountManager: AccountManager\n protected readonly blockchains: Map<string, Blockchain> = new Map()\n\n protected handleResponse: (\n _event: BeaconRequestMessage | BeaconMessageWrapper<BeaconBaseMessage>,\n connectionInfo: ConnectionContext\n ) => void\n\n /**\n * How many requests can be sent after another\n */\n protected readonly rateLimit: number = 2\n /**\n * The time window in seconds in which the \"rateLimit\" is checked\n */\n protected readonly rateLimitWindowInSeconds: number = 5\n\n /**\n * Stores the times when requests have been made to determine if the rate limit has been reached\n */\n protected requestCounter: number[] = []\n\n protected readonly matrixNodes: NodeDistributions\n\n /**\n * One subscription per transport type, together with the transport instance\n * it is attached to. The instance is needed to detach: a replaced transport\n * outlives the client's reference to it (`disconnect()` and\n * `handleDisconnect()` only null the reference), so removing the listener\n * from the *incoming* transport would leave the old one subscribed.\n */\n private readonly transportListeners: Map<\n TransportType,\n {\n transport: Transport\n listener: (message: unknown, connectionInfo: ConnectionContext) => Promise<void>\n }\n > = new Map()\n\n protected _transport: ExposedPromise<Transport<any>> = new ExposedPromise()\n protected get transport(): Promise<Transport<any>> {\n return this._transport.promise\n }\n\n /**\n * Returns the connection status of the Client\n */\n public get connectionStatus(): TransportStatus {\n return this._transport.promiseResult?.connectionStatus ?? TransportStatus.NOT_CONNECTED\n }\n\n /**\n * Returns whether or not the transaport is ready\n */\n public get ready(): Promise<void> {\n return this.transport.then(() => undefined)\n }\n\n constructor(config: ClientOptions) {\n super(config)\n\n this.accountManager = new AccountManager(config.storage)\n this.matrixNodes = config.matrixNodes ?? {}\n\n this.handleResponse = (\n message: BeaconBaseMessage | BeaconMessageWrapper<BeaconBaseMessage>,\n connectionInfo: ConnectionContext\n ): void => {\n throw new Error(\n `not overwritten${JSON.stringify(message)} - ${JSON.stringify(connectionInfo)}`\n )\n }\n }\n protected async cleanup() {\n if (!this.transportListeners.size) {\n return\n }\n\n // Each subscription is removed from the transport it is attached to.\n // Going through `this.transport` removed them all from whichever transport\n // was active, and removed none when no transport was resolved -- the state\n // `disconnect()` leaves behind.\n await Promise.all(\n Array.from(this.transportListeners.values()).map(({ transport, listener }) =>\n transport.removeListener(listener)\n )\n )\n this.transportListeners.clear()\n }\n\n /**\n * Register a blockchain to the client\n * @param chain The blockchain to register\n */\n public addBlockchain(chain: Blockchain) {\n this.blockchains.set(chain.identifier, chain)\n for (const legacyIdentifier of chain.legacyIdentifiers ?? []) {\n this.blockchains.set(legacyIdentifier, chain)\n }\n }\n\n /**\n * Remove a blockchain from the client by its identifier\n * @param chainIdentifier The identifier of the blockchain to remove\n */\n public removeBlockchain(chainIdentifier: string) {\n const chain = this.blockchains.get(chainIdentifier)\n this.blockchains.delete(chainIdentifier)\n for (const legacyIdentifier of chain?.legacyIdentifiers ?? []) {\n this.blockchains.delete(legacyIdentifier)\n }\n }\n\n /**\n * Return all locally known accounts\n */\n public async getAccounts(): Promise<AccountInfo[]> {\n return this.accountManager.getAccounts()\n }\n\n /**\n * Return the account by ID\n * @param accountIdentifier The ID of an account\n */\n public async getAccount(accountIdentifier: string): Promise<AccountInfo | undefined> {\n return this.accountManager.getAccount(accountIdentifier)\n }\n\n /**\n * Remove the account by ID\n * @param accountIdentifier The ID of an account\n */\n public async removeAccount(accountIdentifier: string): Promise<void> {\n return this.accountManager.removeAccount(accountIdentifier)\n }\n\n /**\n * Remove all locally stored accounts\n */\n public async removeAllAccounts(): Promise<void> {\n return this.accountManager.removeAllAccounts()\n }\n\n /**\n * Add a new request (current timestamp) to the pending requests, remove old ones and check if we are above the limit\n */\n public async addRequestAndCheckIfRateLimited(): Promise<boolean> {\n const now: number = new Date().getTime()\n this.requestCounter = this.requestCounter.filter(\n (date) => date + this.rateLimitWindowInSeconds * 1000 > now\n )\n\n this.requestCounter.push(now)\n\n return this.requestCounter.length > this.rateLimit\n }\n\n /**\n * This method initializes the client. It will check if the connection should be established to a\n * browser extension or if the P2P transport should be used.\n *\n * @param transport A transport that can be provided by the user\n */\n public async init(transport: Transport<any, any, any>): Promise<TransportType> {\n if (this._transport.isResolved()) {\n return (await this.transport).type\n }\n\n await this.setTransport(transport) // Let users define their own transport\n\n return transport.type\n }\n\n /**\n * Returns the metadata of this DApp\n */\n public async getOwnAppMetadata(): Promise<AppMetadata> {\n return {\n senderId: await getSenderId(await this.beaconId),\n name: this.name,\n icon: this.iconUrl\n }\n }\n\n /**\n * Return all known peers\n */\n public async getPeers(): Promise<PeerInfo[]> {\n return (await this.transport).getPeers()\n }\n\n /**\n * Add a new peer to the known peers\n * @param peer The new peer to add\n */\n public async addPeer(peer: PeerInfo): Promise<void> {\n return (await this.transport).addPeer(peer)\n }\n\n public async destroy(): Promise<void> {\n // Subscriptions are detached from their own transports, so this no longer\n // needs an active one -- after disconnect() there is none, and that is\n // precisely when the orphaned subscriptions have to go.\n await this.cleanup()\n\n if (this._transport.isResolved()) {\n const transport = await this.transport\n await transport.disconnect()\n if (transport.type === TransportType.WALLETCONNECT) {\n await (transport as any).doClientCleanup() // any because I cannot import the type definition\n }\n }\n await super.destroy()\n }\n\n /**\n * A \"setter\" for when the transport needs to be changed.\n */\n protected async setTransport(transport?: Transport<any>): Promise<void> {\n if (transport) {\n if (this._transport.isSettled()) {\n // If the promise has already been resolved we need to create a new one.\n this._transport = ExposedPromise.resolve(transport)\n } else {\n this._transport.resolve(transport)\n }\n } else {\n if (this._transport.isSettled()) {\n // If the promise has already been resolved we need to create a new one.\n this._transport = new ExposedPromise()\n }\n }\n }\n\n protected async addListener(transport: Transport<any>): Promise<void> {\n // in beacon we subscribe to the transport on client init only\n // unsubscribing from the transport is only beneficial when running\n // a single page dApp.\n // However, while running a multiple tabs setup, if one of the dApps disconnects\n // the others wont't recover until after a page refresh\n\n // Detach the previous subscription from the transport it is actually\n // attached to. Calling removeListener on the incoming transport, which never\n // had it, left every replaced transport subscribed: they share the client's\n // key pair, so each one kept decrypting wallet messages and routing them into\n // handleResponse -- once per past connection.\n const previous = this.transportListeners.get(transport.type)\n if (previous) {\n await previous.transport.removeListener(previous.listener)\n }\n\n const subscription = async (message: any, connectionInfo: ConnectionContext) => {\n if (typeof message !== 'string') {\n return\n }\n\n const peer = await this.findPeer(connectionInfo.id, transport)\n const protocolVersion = this.getPeerProtocolVersion(peer)\n\n const deserializedMessage = (await new Serializer(protocolVersion).deserialize(\n message\n )) as BeaconRequestMessage\n this.handleResponse(deserializedMessage, connectionInfo)\n }\n\n this.transportListeners.set(transport.type, { transport, listener: subscription })\n\n transport.addListener(subscription).catch((error) => logger.error('addListener', error))\n }\n\n protected async sendDisconnectToPeer(peer: PeerInfo, transport?: Transport<any>): Promise<void> {\n const id = await generateGUID()\n const senderId = await getSenderId(await this.beaconId)\n\n // The disconnect ships in the peer's negotiated dialect: wrapped for\n // v3+ peers, the flat legacy shape for v2 peers (which would silently\n // ignore a wrapped envelope).\n const request = buildDisconnectMessage({ id, senderId }, effectivePeerVersion(peer))\n\n const protocolVersion = this.getPeerProtocolVersion(peer)\n const payload = await new Serializer(protocolVersion).serialize(request)\n const selectedTransport = transport ?? (await this.transport)\n\n await selectedTransport.send(payload, peer)\n }\n\n /**\n * Look a peer up by the id the transport attached to a message, on the\n * transport that delivered it.\n *\n * The transport is a parameter rather than a lookup because every caller\n * already has one: a message can only have been delivered by a transport\n * that exists. Reaching for `this.transport` instead parked every arrival\n * between a disconnection and the next pairing -- setTransport(undefined)\n * leaves `_transport` unsettled, so the await only returned once a later\n * pairing resolved it, and the message was replayed into that connection.\n *\n * `connectionInfo.id` is the peer's public key over P2P, but the browser\n * extension's id over postMessage, where the transport cannot tell which\n * peer's key decrypted the message. Match either: only a postMessage\n * pairing response carries an `extensionId`, so the fallback is inert for\n * every other peer.\n */\n protected async findPeer(\n id: string | undefined,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n transport: Transport<any>\n ): Promise<PeerInfo | undefined> {\n if (!id) {\n return undefined\n }\n\n const peers = await transport.getPeers()\n\n return (\n peers.find((peerInfo) => peerInfo.publicKey === id) ??\n // Newest first. `addPeer` dedupes by public key, so a wallet that rotated\n // its beacon key -- a reinstall, a reset -- leaves the stale peer in place\n // beside the new one, both carrying the same extension id. A fresh pairing\n // has to shadow the stale peer, not the other way round.\n [...peers]\n .reverse()\n .find((peerInfo) => 'extensionId' in peerInfo && peerInfo.extensionId === id)\n )\n }\n\n private getLocalProtocolVersion(): number {\n const localPreferredRaw = Number(getPreferredMessageProtocolVersion())\n return Number.isFinite(localPreferredRaw) && localPreferredRaw >= DEFAULT_PROTOCOL_VERSION\n ? localPreferredRaw\n : DEFAULT_PROTOCOL_VERSION\n }\n\n private extractPeerProtocolVersion(peer?: PeerInfo): number {\n if (!peer) {\n return DEFAULT_PROTOCOL_VERSION\n }\n\n const peerProtocolRaw =\n typeof peer.protocolVersion === 'number' ? peer.protocolVersion : Number(peer.protocolVersion)\n return Number.isFinite(peerProtocolRaw) && peerProtocolRaw >= DEFAULT_PROTOCOL_VERSION\n ? peerProtocolRaw\n : DEFAULT_PROTOCOL_VERSION\n }\n\n protected getPeerProtocolVersion(peer?: PeerInfo): number {\n const localVersion = this.getLocalProtocolVersion()\n const peerVersion = this.extractPeerProtocolVersion(peer)\n\n return Math.min(peerVersion, localVersion)\n }\n}\n"]}
@@ -1,4 +1,4 @@
1
- export const SDK_VERSION = '5.0.3';
1
+ export const SDK_VERSION = '5.0.5';
2
2
  export const BEACON_VERSION = '4';
3
3
  export const PROTOCOL_VERSION_V1 = 1;
4
4
  export const PROTOCOL_VERSION_V2 = 2;
@@ -1 +1 @@
1
- {"version":3,"file":"constants.js","sourceRoot":"","sources":["../../../src/constants.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,WAAW,GAAW,OAAO,CAAA;AAC1C,MAAM,CAAC,MAAM,cAAc,GAAW,GAAG,CAAA;AACzC,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAAC,CAAA;AACpC,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAAC,CAAA;AACpC,MAAM,CAAC,MAAM,uBAAuB,GAAG,mBAAmB,CAAA;AAC1D,MAAM,CAAC,MAAM,wBAAwB,GAAG,mBAAmB,CAAA;AAE3D,MAAM,CAAC,MAAM,uBAAuB,GAClC,wDAAwD,CAAA;AAE1D,MAAM,CAAC,MAAM,WAAW,GAAW,6CAA6C,CAAA;AAEhF;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,gCAAgC,GAAG,kCAAkC,CAAA","sourcesContent":["export const SDK_VERSION: string = '5.0.3'\nexport const BEACON_VERSION: string = '4'\nexport const PROTOCOL_VERSION_V1 = 1\nexport const PROTOCOL_VERSION_V2 = 2\nexport const LATEST_PROTOCOL_VERSION = PROTOCOL_VERSION_V2\nexport const DEFAULT_PROTOCOL_VERSION = PROTOCOL_VERSION_V1\n\nexport const NOTIFICATION_ORACLE_URL: string =\n 'https://beacon-notification-oracle.dev.gke.papers.tech'\n\nexport const BACKEND_URL: string = 'https://beacon-backend.prod.gke.papers.tech'\n\n/**\n * Shared ecosystem WalletConnect Cloud projectId, applied by default so dApps\n * can offer WalletConnect wallets (e.g. Kukai Mobile) without registering\n * their own project — WalletConnect's free tier comfortably covers the Tezos\n * ecosystem's volume. Override per dApp via\n * `DAppClientOptions.walletConnectOptions.projectId`; opt out entirely via\n * `disableWalletConnect`. Same id that 4.8.x shipped as its built-in default.\n */\nexport const DEFAULT_WALLETCONNECT_PROJECT_ID = '24469fd0a06df227b6e5f7dc7de0ff4f'\n"]}
1
+ {"version":3,"file":"constants.js","sourceRoot":"","sources":["../../../src/constants.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,WAAW,GAAW,OAAO,CAAA;AAC1C,MAAM,CAAC,MAAM,cAAc,GAAW,GAAG,CAAA;AACzC,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAAC,CAAA;AACpC,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAAC,CAAA;AACpC,MAAM,CAAC,MAAM,uBAAuB,GAAG,mBAAmB,CAAA;AAC1D,MAAM,CAAC,MAAM,wBAAwB,GAAG,mBAAmB,CAAA;AAE3D,MAAM,CAAC,MAAM,uBAAuB,GAClC,wDAAwD,CAAA;AAE1D,MAAM,CAAC,MAAM,WAAW,GAAW,6CAA6C,CAAA;AAEhF;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,gCAAgC,GAAG,kCAAkC,CAAA","sourcesContent":["export const SDK_VERSION: string = '5.0.5'\nexport const BEACON_VERSION: string = '4'\nexport const PROTOCOL_VERSION_V1 = 1\nexport const PROTOCOL_VERSION_V2 = 2\nexport const LATEST_PROTOCOL_VERSION = PROTOCOL_VERSION_V2\nexport const DEFAULT_PROTOCOL_VERSION = PROTOCOL_VERSION_V1\n\nexport const NOTIFICATION_ORACLE_URL: string =\n 'https://beacon-notification-oracle.dev.gke.papers.tech'\n\nexport const BACKEND_URL: string = 'https://beacon-backend.prod.gke.papers.tech'\n\n/**\n * Shared ecosystem WalletConnect Cloud projectId, applied by default so dApps\n * can offer WalletConnect wallets (e.g. Kukai Mobile) without registering\n * their own project — WalletConnect's free tier comfortably covers the Tezos\n * ecosystem's volume. Override per dApp via\n * `DAppClientOptions.walletConnectOptions.projectId`; opt out entirely via\n * `disableWalletConnect`. Same id that 4.8.x shipped as its built-in default.\n */\nexport const DEFAULT_WALLETCONNECT_PROJECT_ID = '24469fd0a06df227b6e5f7dc7de0ff4f'\n"]}
@@ -40,6 +40,7 @@ import { InvalidBeaconVersionError } from './errors/InvalidBeaconVersionError';
40
40
  import { getLogger, Logger, setLogger } from './utils/Logger';
41
41
  import { windowRef } from './MockWindow';
42
42
  import { CommunicationClient } from './transports/clients/CommunicationClient';
43
+ import { PendingPairingRequests } from './transports/clients/PendingPairingRequests';
43
44
  import { ClientEvents } from './transports/clients/ClientEvents';
44
45
  import { WCStorage } from './storage/WCStorage';
45
46
  import { IndexedDBStorage } from './storage/IndexedDBStorage';
@@ -48,7 +49,7 @@ import { MultiTabChannel } from './utils/multi-tab-channel';
48
49
  import getError from './errors/get-error';
49
50
  export { BeaconClient, BeaconClientOptions, Client, ClientOptions, ClientEvents };
50
51
  export { getError, BeaconError, AbortedBeaconError, BroadcastBeaconError, NetworkNotSupportedBeaconError, NoAddressBeaconError, NoPrivateKeyBeaconError, NotGrantedBeaconError, ParametersInvalidBeaconError, TooManyOperationsBeaconError, TransactionInvalidBeaconError, SignatureTypeNotSupportedBeaconError, UnknownBeaconError, VersionUnsupportedBeaconError, InvalidRequiredMinimumVersionError, NetworksUnsupportedBeaconError, InvalidBeaconVersionError };
51
- export { Transport, MessageBasedClient, CommunicationClient };
52
+ export { Transport, MessageBasedClient, CommunicationClient, PendingPairingRequests };
52
53
  export { ChromeStorage, LocalStorage, WCStorage, IndexedDBStorage, StorageValidator, getStorage };
53
54
  export { PeerManager, AccountManager, AppMetadataManager, PermissionManager };
54
55
  export { SDK_VERSION, DEFAULT_WALLETCONNECT_PROJECT_ID, BEACON_VERSION, PROTOCOL_VERSION_V1, PROTOCOL_VERSION_V2, LATEST_PROTOCOL_VERSION, DEFAULT_PROTOCOL_VERSION, getPreferredMessageProtocolVersion, setPreferredMessageProtocolVersion };
@@ -41,6 +41,7 @@ import { InvalidBeaconVersionError } from './errors/InvalidBeaconVersionError';
41
41
  import { getLogger, Logger, setLogger } from './utils/Logger';
42
42
  import { windowRef } from './MockWindow';
43
43
  import { CommunicationClient } from './transports/clients/CommunicationClient';
44
+ import { PendingPairingRequests } from './transports/clients/PendingPairingRequests';
44
45
  import { WCStorage } from './storage/WCStorage';
45
46
  import { IndexedDBStorage } from './storage/IndexedDBStorage';
46
47
  import { StorageValidator } from './storage/StorageValidator';
@@ -55,7 +56,7 @@ export { getError, BeaconError, AbortedBeaconError, BroadcastBeaconError, Networ
55
56
  // EncryptionTypeNotSupportedBeaconError,
56
57
  UnknownBeaconError, VersionUnsupportedBeaconError, InvalidRequiredMinimumVersionError, NetworksUnsupportedBeaconError, InvalidBeaconVersionError };
57
58
  // Transport
58
- export { Transport, MessageBasedClient, CommunicationClient };
59
+ export { Transport, MessageBasedClient, CommunicationClient, PendingPairingRequests };
59
60
  // Storage
60
61
  export { ChromeStorage, LocalStorage, WCStorage, IndexedDBStorage, StorageValidator, getStorage };
61
62
  // Managers
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAA;AAChD,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAA;AAClD,OAAO,EAAE,oBAAoB,EAAE,MAAM,+BAA+B,CAAA;AACpE,OAAO,EAAE,8BAA8B,EAAE,MAAM,yCAAyC,CAAA;AACxF,OAAO,EAAE,oBAAoB,EAAE,MAAM,+BAA+B,CAAA;AACpE,OAAO,EAAE,uBAAuB,EAAE,MAAM,kCAAkC,CAAA;AAC1E,OAAO,EAAE,qBAAqB,EAAE,MAAM,gCAAgC,CAAA;AACtE,OAAO,EAAE,4BAA4B,EAAE,MAAM,uCAAuC,CAAA;AACpF,OAAO,EAAE,4BAA4B,EAAE,MAAM,uCAAuC,CAAA;AACpF,OAAO,EAAE,6BAA6B,EAAE,MAAM,wCAAwC,CAAA;AACtF,OAAO,EAAE,kBAAkB,EAAE,MAAM,6BAA6B,CAAA;AAChE,OAAO,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAA;AAClD,OAAO,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAA;AACvD,OAAO,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAA;AACrD,OAAO,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAA;AACjD,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAA;AAGzC,OAAO,EACL,WAAW,EACX,gCAAgC,EAChC,cAAc,EACd,mBAAmB,EACnB,mBAAmB,EACnB,uBAAuB,EACvB,wBAAwB,EACzB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AO,EACL,mBAAmB,EACnB,iBAAiB,EACjB,qBAAqB,EACrB,yBAAyB,EACzB,yBAAyB,EACzB,yBAAyB,EAC1B,MAAM,eAAe,CAAA;AACtB,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAA;AAClD,OAAO,EAAE,6BAA6B,EAAE,MAAM,kCAAkC,CAAA;AAEhF,cAAc;AACd,OAAO,EACL,iBAAiB,EACjB,iBAAiB,EACjB,qBAAqB,EACrB,2BAA2B,EAC3B,sBAAsB,EACvB,MAAM,qBAAqB,CAAA;AAE5B,cAAc;AACd,OAAO,EAAE,WAAW,EAAE,cAAc,EAAE,kBAAkB,EAAE,cAAc,EAAE,sBAAsB,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAA;AAGlJ,SAAS;AACT,OAAO,EAAE,UAAU,EAAE,MAAM,EAAE,SAAS,EAAE,SAAS,EAAE,CAAA;AAEnD,QAAQ;AACR,OAAO,EAAE,eAAe,EAAE,eAAe,EAAE,CAAA;AAE3C,OAAO,EAAE,uBAAuB,EAAE,WAAW,EAAE,MAAM,aAAa,CAAA","sourcesContent":["/**\n * General docs\n * @module public\n */\nimport { Client } from './clients/client/Client'\nimport { BeaconError } from './errors/BeaconError'\nimport { BroadcastBeaconError } from './errors/BroadcastBeaconError'\nimport { NetworkNotSupportedBeaconError } from './errors/NetworkNotSupportedBeaconError'\nimport { NoAddressBeaconError } from './errors/NoAddressBeaconError'\nimport { NoPrivateKeyBeaconError } from './errors/NoPrivateKeyBeaconError'\nimport { NotGrantedBeaconError } from './errors/NotGrantedBeaconError'\nimport { ParametersInvalidBeaconError } from './errors/ParametersInvalidBeaconError'\nimport { TooManyOperationsBeaconError } from './errors/TooManyOperationsBeaconError'\nimport { TransactionInvalidBeaconError } from './errors/TransactionInvalidBeaconError'\nimport { UnknownBeaconError } from './errors/UnknownBeaconError'\nimport { Transport } from './transports/Transport'\nimport { ChromeStorage } from './storage/ChromeStorage'\nimport { LocalStorage } from './storage/LocalStorage'\nimport { getStorage } from './storage/getStorage'\nimport { Serializer } from './Serializer'\n// import { RequestEncryptPayloadInput } from './types/RequestEncryptPayloadInput'\nimport { ClientOptions } from './clients/client/ClientOptions'\nimport {\n SDK_VERSION,\n DEFAULT_WALLETCONNECT_PROJECT_ID,\n BEACON_VERSION,\n PROTOCOL_VERSION_V1,\n PROTOCOL_VERSION_V2,\n LATEST_PROTOCOL_VERSION,\n DEFAULT_PROTOCOL_VERSION\n} from './constants'\nimport {\n getPreferredMessageProtocolVersion,\n setPreferredMessageProtocolVersion\n} from './message-protocol'\nimport { AccountManager } from './managers/AccountManager'\nimport { AppMetadataManager } from './managers/AppMetadataManager'\nimport { PermissionManager } from './managers/PermissionManager'\nimport { BeaconClient } from './clients/beacon-client/BeaconClient'\nimport { BeaconClientOptions } from './clients/beacon-client/BeaconClientOptions'\nimport { getAccountIdentifier } from './utils/get-account-identifier'\nimport { AbortedBeaconError } from './errors/AbortedBeaconError'\nimport { getSenderId } from './utils/get-sender-id'\nimport { PeerManager } from './managers/PeerManager'\nimport { MessageBasedClient } from './transports/clients/MessageBasedClient'\nimport { setDebugEnabled, getDebugEnabled } from './debug'\n// import { EncryptPayloadRequest } from './types/beacon/messages/EncryptPayloadRequest'\n// import { EncryptPayloadResponse } from './types/beacon/messages/EncryptPayloadResponse'\n// import { EncryptionTypeNotSupportedBeaconError } from './errors/EncryptionTypeNotSupportedBeaconError'\nimport { SignatureTypeNotSupportedBeaconError } from './errors/SignatureTypeNotSupportedBeaconError'\nimport { VersionUnsupportedBeaconError } from './errors/VersionUnsupportedBeaconError'\nimport { InvalidRequiredMinimumVersionError } from './errors/InvalidRequiredMinimumVersionError'\nimport { NetworksUnsupportedBeaconError } from './errors/NetworksUnsupportedBeaconError'\nimport { InvalidBeaconVersionError } from './errors/InvalidBeaconVersionError'\nimport { getLogger, Logger, setLogger } from './utils/Logger'\nimport { windowRef } from './MockWindow'\nimport { CommunicationClient } from './transports/clients/CommunicationClient'\nimport { ClientEvents } from './transports/clients/ClientEvents'\nimport { WCStorage } from './storage/WCStorage'\nimport { IndexedDBStorage } from './storage/IndexedDBStorage'\nimport { StorageValidator } from './storage/StorageValidator'\nimport { MultiTabChannel } from './utils/multi-tab-channel'\nimport getError from './errors/get-error'\n// import { EncryptionType } from './types/EncryptionType'\n// import { EncryptionOperation } from './types/EncryptionOperation'\n\n// Clients\nexport { BeaconClient, BeaconClientOptions, Client, ClientOptions, ClientEvents }\n\n// Errors\nexport {\n getError,\n BeaconError,\n AbortedBeaconError,\n BroadcastBeaconError,\n NetworkNotSupportedBeaconError,\n NoAddressBeaconError,\n NoPrivateKeyBeaconError,\n NotGrantedBeaconError,\n ParametersInvalidBeaconError,\n TooManyOperationsBeaconError,\n TransactionInvalidBeaconError,\n SignatureTypeNotSupportedBeaconError,\n // EncryptionTypeNotSupportedBeaconError,\n UnknownBeaconError,\n VersionUnsupportedBeaconError,\n InvalidRequiredMinimumVersionError,\n NetworksUnsupportedBeaconError,\n InvalidBeaconVersionError\n}\n\n// Transport\nexport { Transport, MessageBasedClient, CommunicationClient }\n\n// Storage\nexport { ChromeStorage, LocalStorage, WCStorage, IndexedDBStorage, StorageValidator, getStorage }\n\n// Managers\nexport { PeerManager, AccountManager, AppMetadataManager, PermissionManager }\n\n// Constants\nexport {\n SDK_VERSION,\n DEFAULT_WALLETCONNECT_PROJECT_ID,\n BEACON_VERSION,\n PROTOCOL_VERSION_V1,\n PROTOCOL_VERSION_V2,\n LATEST_PROTOCOL_VERSION,\n DEFAULT_PROTOCOL_VERSION,\n getPreferredMessageProtocolVersion,\n setPreferredMessageProtocolVersion\n}\n\n// Utils\nexport { getSenderId, getAccountIdentifier, windowRef, MultiTabChannel }\nexport {\n usesWrappedMessages,\n MESSAGE_WRAPPED_FROM_VERSION,\n MULTI_NETWORK_FROM_VERSION,\n compareBeaconVersion,\n isAtLeastVersion,\n isMultiNetworkVersion,\n negotiateEnvelopeVersion,\n effectivePeerVersion,\n wrapBeaconMessage,\n unwrapBeaconMessage\n} from './utils/message-utils'\nexport {\n normalizeTezosCaip2,\n isValidTezosCaip2,\n networkFromTezosCaip2,\n TEZOS_NETWORK_GENESIS_IDS,\n tezosCaip2FromNetworkType,\n networkTypeFromTezosCaip2\n} from './utils/caip2'\nexport { assertNever } from './utils/assert-never'\nexport { resolveRequiredMinimumVersion } from './utils/required-minimum-version'\n\n// Diagnostics\nexport {\n gatherDiagnostics,\n buildErrorContext,\n serializeErrorContext,\n copyErrorContextToClipboard,\n SENSITIVE_STORAGE_KEYS\n} from './utils/diagnostics'\n\n// Error codes\nexport { ERROR_CODES, WC_ERROR_CODES, MATRIX_ERROR_CODES, PM_ERROR_CODES, BLOCKCHAIN_ERROR_CODES, BEACON_ERROR_CODES } from './errors/error-codes'\nexport type { ErrorCode } from './errors/error-codes'\n\n// Others\nexport { Serializer, Logger, setLogger, getLogger }\n\n// Debug\nexport { setDebugEnabled, getDebugEnabled }\n\nexport { NOTIFICATION_ORACLE_URL, BACKEND_URL } from './constants'\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAA;AAChD,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAA;AAClD,OAAO,EAAE,oBAAoB,EAAE,MAAM,+BAA+B,CAAA;AACpE,OAAO,EAAE,8BAA8B,EAAE,MAAM,yCAAyC,CAAA;AACxF,OAAO,EAAE,oBAAoB,EAAE,MAAM,+BAA+B,CAAA;AACpE,OAAO,EAAE,uBAAuB,EAAE,MAAM,kCAAkC,CAAA;AAC1E,OAAO,EAAE,qBAAqB,EAAE,MAAM,gCAAgC,CAAA;AACtE,OAAO,EAAE,4BAA4B,EAAE,MAAM,uCAAuC,CAAA;AACpF,OAAO,EAAE,4BAA4B,EAAE,MAAM,uCAAuC,CAAA;AACpF,OAAO,EAAE,6BAA6B,EAAE,MAAM,wCAAwC,CAAA;AACtF,OA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kBAAkB,EAAE,iBAAiB,EAAE,CAAA;AAE7E,YAAY;AACZ,OAAO,EACL,WAAW,EACX,gCAAgC,EAChC,cAAc,EACd,mBAAmB,EACnB,mBAAmB,EACnB,uBAAuB,EACvB,wBAAwB,EACxB,kCAAkC,EAClC,kCAAkC,EACnC,CAAA;AAED,QAAQ;AACR,OAAO,EAAE,WAAW,EAAE,oBAAoB,EAAE,SAAS,EAAE,eAAe,EAAE,CAAA;AACxE,OAAO,EACL,mBAAmB,EACnB,4BAA4B,EAC5B,0BAA0B,EAC1B,oBAAoB,EACpB,gBAAgB,EAChB,qBAAqB,EACrB,wBAAwB,EACxB,oBAAoB,EACpB,iBAAiB,EACjB,mBAAmB,EACpB,MAAM,uBAAuB,CAAA;AAC9B,OAAO,EACL,mBAAmB,EACnB,iBAAiB,EACjB,qBAAqB,EACrB,yBAAyB,EACzB,yBAAyB,EACzB,yBAAyB,EAC1B,MAAM,eAAe,CAAA;AACtB,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAA;AAClD,OAAO,EAAE,6BAA6B,EAAE,MAAM,kCAAkC,CAAA;AAEhF,cAAc;AACd,OAAO,EACL,iBAAiB,EACjB,iBAAiB,EACjB,qBAAqB,EACrB,2BAA2B,EAC3B,sBAAsB,EACvB,MAAM,qBAAqB,CAAA;AAE5B,cAAc;AACd,OAAO,EAAE,WAAW,EAAE,cAAc,EAAE,kBAAkB,EAAE,cAAc,EAAE,sBAAsB,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAA;AAGlJ,SAAS;AACT,OAAO,EAAE,UAAU,EAAE,MAAM,EAAE,SAAS,EAAE,SAAS,EAAE,CAAA;AAEnD,QAAQ;AACR,OAAO,EAAE,eAAe,EAAE,eAAe,EAAE,CAAA;AAE3C,OAAO,EAAE,uBAAuB,EAAE,WAAW,EAAE,MAAM,aAAa,CAAA","sourcesContent":["/**\n * General docs\n * @module public\n */\nimport { Client } from './clients/client/Client'\nimport { BeaconError } from './errors/BeaconError'\nimport { BroadcastBeaconError } from './errors/BroadcastBeaconError'\nimport { NetworkNotSupportedBeaconError } from './errors/NetworkNotSupportedBeaconError'\nimport { NoAddressBeaconError } from './errors/NoAddressBeaconError'\nimport { NoPrivateKeyBeaconError } from './errors/NoPrivateKeyBeaconError'\nimport { NotGrantedBeaconError } from './errors/NotGrantedBeaconError'\nimport { ParametersInvalidBeaconError } from './errors/ParametersInvalidBeaconError'\nimport { TooManyOperationsBeaconError } from './errors/TooManyOperationsBeaconError'\nimport { TransactionInvalidBeaconError } from './errors/TransactionInvalidBeaconError'\nimport { UnknownBeaconError } from './errors/UnknownBeaconError'\nimport { Transport } from './transports/Transport'\nimport { ChromeStorage } from './storage/ChromeStorage'\nimport { LocalStorage } from './storage/LocalStorage'\nimport { getStorage } from './storage/getStorage'\nimport { Serializer } from './Serializer'\n// import { RequestEncryptPayloadInput } from './types/RequestEncryptPayloadInput'\nimport { ClientOptions } from './clients/client/ClientOptions'\nimport {\n SDK_VERSION,\n DEFAULT_WALLETCONNECT_PROJECT_ID,\n BEACON_VERSION,\n PROTOCOL_VERSION_V1,\n PROTOCOL_VERSION_V2,\n LATEST_PROTOCOL_VERSION,\n DEFAULT_PROTOCOL_VERSION\n} from './constants'\nimport {\n getPreferredMessageProtocolVersion,\n setPreferredMessageProtocolVersion\n} from './message-protocol'\nimport { AccountManager } from './managers/AccountManager'\nimport { AppMetadataManager } from './managers/AppMetadataManager'\nimport { PermissionManager } from './managers/PermissionManager'\nimport { BeaconClient } from './clients/beacon-client/BeaconClient'\nimport { BeaconClientOptions } from './clients/beacon-client/BeaconClientOptions'\nimport { getAccountIdentifier } from './utils/get-account-identifier'\nimport { AbortedBeaconError } from './errors/AbortedBeaconError'\nimport { getSenderId } from './utils/get-sender-id'\nimport { PeerManager } from './managers/PeerManager'\nimport { MessageBasedClient } from './transports/clients/MessageBasedClient'\nimport { setDebugEnabled, getDebugEnabled } from './debug'\n// import { EncryptPayloadRequest } from './types/beacon/messages/EncryptPayloadRequest'\n// import { EncryptPayloadResponse } from './types/beacon/messages/EncryptPayloadResponse'\n// import { EncryptionTypeNotSupportedBeaconError } from './errors/EncryptionTypeNotSupportedBeaconError'\nimport { SignatureTypeNotSupportedBeaconError } from './errors/SignatureTypeNotSupportedBeaconError'\nimport { VersionUnsupportedBeaconError } from './errors/VersionUnsupportedBeaconError'\nimport { InvalidRequiredMinimumVersionError } from './errors/InvalidRequiredMinimumVersionError'\nimport { NetworksUnsupportedBeaconError } from './errors/NetworksUnsupportedBeaconError'\nimport { InvalidBeaconVersionError } from './errors/InvalidBeaconVersionError'\nimport { getLogger, Logger, setLogger } from './utils/Logger'\nimport { windowRef } from './MockWindow'\nimport { CommunicationClient } from './transports/clients/CommunicationClient'\nimport { PendingPairingRequests } from './transports/clients/PendingPairingRequests'\nimport { ClientEvents } from './transports/clients/ClientEvents'\nimport { WCStorage } from './storage/WCStorage'\nimport { IndexedDBStorage } from './storage/IndexedDBStorage'\nimport { StorageValidator } from './storage/StorageValidator'\nimport { MultiTabChannel } from './utils/multi-tab-channel'\nimport getError from './errors/get-error'\n// import { EncryptionType } from './types/EncryptionType'\n// import { EncryptionOperation } from './types/EncryptionOperation'\n\n// Clients\nexport { BeaconClient, BeaconClientOptions, Client, ClientOptions, ClientEvents }\n\n// Errors\nexport {\n getError,\n BeaconError,\n AbortedBeaconError,\n BroadcastBeaconError,\n NetworkNotSupportedBeaconError,\n NoAddressBeaconError,\n NoPrivateKeyBeaconError,\n NotGrantedBeaconError,\n ParametersInvalidBeaconError,\n TooManyOperationsBeaconError,\n TransactionInvalidBeaconError,\n SignatureTypeNotSupportedBeaconError,\n // EncryptionTypeNotSupportedBeaconError,\n UnknownBeaconError,\n VersionUnsupportedBeaconError,\n InvalidRequiredMinimumVersionError,\n NetworksUnsupportedBeaconError,\n InvalidBeaconVersionError\n}\n\n// Transport\nexport { Transport, MessageBasedClient, CommunicationClient, PendingPairingRequests }\n\n// Storage\nexport { ChromeStorage, LocalStorage, WCStorage, IndexedDBStorage, StorageValidator, getStorage }\n\n// Managers\nexport { PeerManager, AccountManager, AppMetadataManager, PermissionManager }\n\n// Constants\nexport {\n SDK_VERSION,\n DEFAULT_WALLETCONNECT_PROJECT_ID,\n BEACON_VERSION,\n PROTOCOL_VERSION_V1,\n PROTOCOL_VERSION_V2,\n LATEST_PROTOCOL_VERSION,\n DEFAULT_PROTOCOL_VERSION,\n getPreferredMessageProtocolVersion,\n setPreferredMessageProtocolVersion\n}\n\n// Utils\nexport { getSenderId, getAccountIdentifier, windowRef, MultiTabChannel }\nexport {\n usesWrappedMessages,\n MESSAGE_WRAPPED_FROM_VERSION,\n MULTI_NETWORK_FROM_VERSION,\n compareBeaconVersion,\n isAtLeastVersion,\n isMultiNetworkVersion,\n negotiateEnvelopeVersion,\n effectivePeerVersion,\n wrapBeaconMessage,\n unwrapBeaconMessage\n} from './utils/message-utils'\nexport {\n normalizeTezosCaip2,\n isValidTezosCaip2,\n networkFromTezosCaip2,\n TEZOS_NETWORK_GENESIS_IDS,\n tezosCaip2FromNetworkType,\n networkTypeFromTezosCaip2\n} from './utils/caip2'\nexport { assertNever } from './utils/assert-never'\nexport { resolveRequiredMinimumVersion } from './utils/required-minimum-version'\n\n// Diagnostics\nexport {\n gatherDiagnostics,\n buildErrorContext,\n serializeErrorContext,\n copyErrorContextToClipboard,\n SENSITIVE_STORAGE_KEYS\n} from './utils/diagnostics'\n\n// Error codes\nexport { ERROR_CODES, WC_ERROR_CODES, MATRIX_ERROR_CODES, PM_ERROR_CODES, BLOCKCHAIN_ERROR_CODES, BEACON_ERROR_CODES } from './errors/error-codes'\nexport type { ErrorCode } from './errors/error-codes'\n\n// Others\nexport { Serializer, Logger, setLogger, getLogger }\n\n// Debug\nexport { setDebugEnabled, getDebugEnabled }\n\nexport { NOTIFICATION_ORACLE_URL, BACKEND_URL } from './constants'\n"]}
@@ -0,0 +1,20 @@
1
+ /**
2
+ * Pairing request ids this dApp has handed out (QR code, deep link, extension).
3
+ * A pairing reply is only accepted if it answers one of them, once.
4
+ *
5
+ * In memory on purpose (same as the ECAD 4.8.5 fix): storage cannot make
6
+ * "use once" hold across tabs, so a reload while a pairing is still open
7
+ * needs a fresh QR code or deep link. Already-paired sessions are unaffected.
8
+ *
9
+ * @internalapi
10
+ */
11
+ export declare class PendingPairingRequests {
12
+ private readonly requests;
13
+ add(id: string): void;
14
+ hasPending(): boolean;
15
+ /** True if `id` was pending. Clears every pending request, so only one reply wins. */
16
+ consume(id: string): boolean;
17
+ /** Forget every pending request, e.g. when the pairing popup closes. */
18
+ clear(): void;
19
+ private prune;
20
+ }
@@ -0,0 +1,49 @@
1
+ const TTL_MS = 30 * 60 * 1000;
2
+ const MAX_PENDING = 32;
3
+ /**
4
+ * Pairing request ids this dApp has handed out (QR code, deep link, extension).
5
+ * A pairing reply is only accepted if it answers one of them, once.
6
+ *
7
+ * In memory on purpose (same as the ECAD 4.8.5 fix): storage cannot make
8
+ * "use once" hold across tabs, so a reload while a pairing is still open
9
+ * needs a fresh QR code or deep link. Already-paired sessions are unaffected.
10
+ *
11
+ * @internalapi
12
+ */
13
+ export class PendingPairingRequests {
14
+ requests = new Map(); // id -> expiry
15
+ add(id) {
16
+ this.prune();
17
+ this.requests.set(id, Date.now() + TTL_MS);
18
+ // Map keeps insertion order, so the first key is the oldest.
19
+ while (this.requests.size > MAX_PENDING) {
20
+ this.requests.delete(this.requests.keys().next().value);
21
+ }
22
+ }
23
+ hasPending() {
24
+ this.prune();
25
+ return this.requests.size > 0;
26
+ }
27
+ /** True if `id` was pending. Clears every pending request, so only one reply wins. */
28
+ consume(id) {
29
+ this.prune();
30
+ if (!this.requests.has(id)) {
31
+ return false;
32
+ }
33
+ this.clear();
34
+ return true;
35
+ }
36
+ /** Forget every pending request, e.g. when the pairing popup closes. */
37
+ clear() {
38
+ this.requests.clear();
39
+ }
40
+ prune() {
41
+ const now = Date.now();
42
+ for (const [id, expiry] of this.requests) {
43
+ if (expiry <= now) {
44
+ this.requests.delete(id);
45
+ }
46
+ }
47
+ }
48
+ }
49
+ //# sourceMappingURL=PendingPairingRequests.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PendingPairingRequests.js","sourceRoot":"","sources":["../../../../../src/transports/clients/PendingPairingRequests.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI,CAAA;AAC7B,MAAM,WAAW,GAAG,EAAE,CAAA;AAEtB;;;;;;;;;GASG;AACH,MAAM,OAAO,sBAAsB;IAChB,QAAQ,GAAG,IAAI,GAAG,EAAkB,CAAA,CAAC,eAAe;IAE9D,GAAG,CAAC,EAAU;QACnB,IAAI,CAAC,KAAK,EAAE,CAAA;QACZ,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,EAAE,IAAI,CAAC,GAAG,EAAE,GAAG,MAAM,CAAC,CAAA;QAC1C,6DAA6D;QAC7D,OAAO,IAAI,CAAC,QAAQ,CAAC,IAAI,GAAG,WAAW,EAAE,CAAC;YACxC,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,EAAE,CAAC,IAAI,EAAE,CAAC,KAAe,CAAC,CAAA;QACnE,CAAC;IACH,CAAC;IAEM,UAAU;QACf,IAAI,CAAC,KAAK,EAAE,CAAA;QAEZ,OAAO,IAAI,CAAC,QAAQ,CAAC,IAAI,GAAG,CAAC,CAAA;IAC/B,CAAC;IAED,sFAAsF;IAC/E,OAAO,CAAC,EAAU;QACvB,IAAI,CAAC,KAAK,EAAE,CAAA;QACZ,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,CAAC;YAC3B,OAAO,KAAK,CAAA;QACd,CAAC;QACD,IAAI,CAAC,KAAK,EAAE,CAAA;QAEZ,OAAO,IAAI,CAAA;IACb,CAAC;IAED,wEAAwE;IACjE,KAAK;QACV,IAAI,CAAC,QAAQ,CAAC,KAAK,EAAE,CAAA;IACvB,CAAC;IAEO,KAAK;QACX,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,EAAE,CAAA;QACtB,KAAK,MAAM,CAAC,EAAE,EAAE,MAAM,CAAC,IAAI,IAAI,CAAC,QAAQ,EAAE,CAAC;YACzC,IAAI,MAAM,IAAI,GAAG,EAAE,CAAC;gBAClB,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,EAAE,CAAC,CAAA;YAC1B,CAAC;QACH,CAAC;IACH,CAAC;CACF","sourcesContent":["const TTL_MS = 30 * 60 * 1000\nconst MAX_PENDING = 32\n\n/**\n * Pairing request ids this dApp has handed out (QR code, deep link, extension).\n * A pairing reply is only accepted if it answers one of them, once.\n *\n * In memory on purpose (same as the ECAD 4.8.5 fix): storage cannot make\n * \"use once\" hold across tabs, so a reload while a pairing is still open\n * needs a fresh QR code or deep link. Already-paired sessions are unaffected.\n *\n * @internalapi\n */\nexport class PendingPairingRequests {\n private readonly requests = new Map<string, number>() // id -> expiry\n\n public add(id: string): void {\n this.prune()\n this.requests.set(id, Date.now() + TTL_MS)\n // Map keeps insertion order, so the first key is the oldest.\n while (this.requests.size > MAX_PENDING) {\n this.requests.delete(this.requests.keys().next().value as string)\n }\n }\n\n public hasPending(): boolean {\n this.prune()\n\n return this.requests.size > 0\n }\n\n /** True if `id` was pending. Clears every pending request, so only one reply wins. */\n public consume(id: string): boolean {\n this.prune()\n if (!this.requests.has(id)) {\n return false\n }\n this.clear()\n\n return true\n }\n\n /** Forget every pending request, e.g. when the pairing popup closes. */\n public clear(): void {\n this.requests.clear()\n }\n\n private prune(): void {\n const now = Date.now()\n for (const [id, expiry] of this.requests) {\n if (expiry <= now) {\n this.requests.delete(id)\n }\n }\n }\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tezos-x/octez.connect-core",
3
- "version": "5.0.3",
3
+ "version": "5.0.5",
4
4
  "description": "This package contains internal methods that are used by both the dApp and wallet client.",
5
5
  "author": "Blockchain Infra <blockchain.infra@trili.tech>",
6
6
  "homepage": "https://octez-connect.tezos.com",
@@ -38,8 +38,8 @@
38
38
  "@stablelib/nacl": "^2.0.1",
39
39
  "@stablelib/utf8": "^2.1.0",
40
40
  "@stablelib/x25519-session": "^2.0.1",
41
- "@tezos-x/octez.connect-types": "5.0.3",
42
- "@tezos-x/octez.connect-utils": "5.0.3",
41
+ "@tezos-x/octez.connect-types": "5.0.5",
42
+ "@tezos-x/octez.connect-utils": "5.0.5",
43
43
  "broadcast-channel": "^7.3.0",
44
44
  "bs58check": "4.0.0"
45
45
  }