@metamask/connect-multichain 0.5.3 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (60) hide show
  1. package/CHANGELOG.md +27 -1
  2. package/README.md +9 -3
  3. package/dist/browser/es/connect-multichain.d.mts +27 -4
  4. package/dist/browser/es/connect-multichain.mjs +603 -333
  5. package/dist/browser/es/connect-multichain.mjs.map +1 -1
  6. package/dist/browser/es/metafile-esm.json +1 -1
  7. package/dist/browser/iife/connect-multichain.d.ts +27 -4
  8. package/dist/browser/iife/connect-multichain.js +3363 -2993
  9. package/dist/browser/iife/connect-multichain.js.map +1 -1
  10. package/dist/browser/iife/metafile-iife.json +1 -1
  11. package/dist/browser/umd/connect-multichain.d.ts +27 -4
  12. package/dist/browser/umd/connect-multichain.js +603 -333
  13. package/dist/browser/umd/connect-multichain.js.map +1 -1
  14. package/dist/browser/umd/metafile-cjs.json +1 -1
  15. package/dist/node/cjs/connect-multichain.d.ts +27 -4
  16. package/dist/node/cjs/connect-multichain.js +421 -151
  17. package/dist/node/cjs/connect-multichain.js.map +1 -1
  18. package/dist/node/cjs/metafile-cjs.json +1 -1
  19. package/dist/node/es/connect-multichain.d.mts +27 -4
  20. package/dist/node/es/connect-multichain.mjs +421 -151
  21. package/dist/node/es/connect-multichain.mjs.map +1 -1
  22. package/dist/node/es/metafile-esm.json +1 -1
  23. package/dist/react-native/es/connect-multichain.d.mts +27 -4
  24. package/dist/react-native/es/connect-multichain.mjs +596 -326
  25. package/dist/react-native/es/connect-multichain.mjs.map +1 -1
  26. package/dist/react-native/es/metafile-esm.json +1 -1
  27. package/dist/src/domain/multichain/index.d.ts +15 -4
  28. package/dist/src/domain/multichain/index.d.ts.map +1 -1
  29. package/dist/src/domain/multichain/index.js +14 -0
  30. package/dist/src/domain/multichain/index.js.map +1 -1
  31. package/dist/src/domain/multichain/types.d.ts +12 -0
  32. package/dist/src/domain/multichain/types.d.ts.map +1 -1
  33. package/dist/src/multichain/index.d.ts +3 -2
  34. package/dist/src/multichain/index.d.ts.map +1 -1
  35. package/dist/src/multichain/index.js +158 -61
  36. package/dist/src/multichain/index.js.map +1 -1
  37. package/dist/src/multichain/transports/default/index.d.ts +3 -1
  38. package/dist/src/multichain/transports/default/index.d.ts.map +1 -1
  39. package/dist/src/multichain/transports/default/index.js +17 -11
  40. package/dist/src/multichain/transports/default/index.js.map +1 -1
  41. package/dist/src/multichain/transports/multichainApiClientWrapper/index.d.ts +3 -1
  42. package/dist/src/multichain/transports/multichainApiClientWrapper/index.d.ts.map +1 -1
  43. package/dist/src/multichain/transports/multichainApiClientWrapper/index.js +28 -31
  44. package/dist/src/multichain/transports/multichainApiClientWrapper/index.js.map +1 -1
  45. package/dist/src/multichain/transports/mwp/index.d.ts +15 -2
  46. package/dist/src/multichain/transports/mwp/index.d.ts.map +1 -1
  47. package/dist/src/multichain/transports/mwp/index.js +155 -38
  48. package/dist/src/multichain/transports/mwp/index.js.map +1 -1
  49. package/dist/src/multichain/utils/index.d.ts +23 -0
  50. package/dist/src/multichain/utils/index.d.ts.map +1 -1
  51. package/dist/src/multichain/utils/index.js +57 -4
  52. package/dist/src/multichain/utils/index.js.map +1 -1
  53. package/dist/src/polyfills/buffer-shim.js +4 -14
  54. package/dist/src/polyfills/buffer-shim.js.map +1 -1
  55. package/dist/src/store/adapters/web.d.ts +1 -1
  56. package/dist/src/store/adapters/web.d.ts.map +1 -1
  57. package/dist/src/store/adapters/web.js +1 -1
  58. package/dist/src/store/adapters/web.js.map +1 -1
  59. package/dist/types/connect-multichain.d.ts +27 -4
  60. package/package.json +1 -1
package/CHANGELOG.md CHANGED
@@ -7,6 +7,28 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [0.6.0]
11
+
12
+ ### Added
13
+
14
+ - When `ConnectMultichain.connect()` is called while a connection is already pending, the user is re-prompted with the pending connection deeplink. ([#176](https://github.com/MetaMask/connect-monorepo/pull/176))
15
+
16
+ ### Changed
17
+
18
+ - **BREAKING** `createMultichainClient()` now returns a singleton. Any incoming constructor params on subsequent calls to `createMultichainClient()` will be applied to the existing singleton instance except for the `dapp`, `storage`, and `ui.factory` param options. ([#157](https://github.com/MetaMask/connect-monorepo/pull/157))
19
+ - **BREAKING** `ConnectMultichain.openDeeplinkIfNeeded()` is renamed to `openSimpleDeeplinkIfNeeded()` ([#176](https://github.com/MetaMask/connect-monorepo/pull/176))
20
+ - `ConnectMultichain.connect()` now throws an `'Existing connection is pending. Please check your MetaMask Mobile app to continue.'` error if there is already an pending connection attempt. Previously it would abort that ongoing connection in favor of a new one. ([#157](https://github.com/MetaMask/connect-monorepo/pull/157))
21
+ - `ConnectMultichain.connect()` adds newly requested scopes and accounts onto any existing permissions rather than fully replacing them. ([#157](https://github.com/MetaMask/connect-monorepo/pull/157))
22
+ - `ConnectMultichain.disconnect()` accepts an optional array of scopes. When provided, only those scopes will be revoked from the existing permissions. If no scopes remain after a partial revoke, then the underly connection is fully discarded. If no scopes are specified ()`[]`), then all scopes will be removed. By default all scopes will be removed. ([#157](https://github.com/MetaMask/connect-monorepo/pull/157))
23
+
24
+ ### Fixed
25
+
26
+ - `ConnectMultichain` now waits 10 seconds (rather than 2 minutes) when attempting to resume a pending connection on initial instantiation via `createMultichainClient()` ([#175](https://github.com/MetaMask/connect-monorepo/pull/175))
27
+ - Fix `beforeunload` event listener not being properly removed on disconnect due to `.bind()` creating different function references, causing a listener leak on each connect/disconnect cycle ([#170](https://github.com/MetaMask/connect-monorepo/pull/170))
28
+ - Rename `StoreAdapterWeb.DB_NAME` from `mmsdk` to `mmconnect` to prevent IndexedDB collisions when the legacy MetaMask SDK and MM Connect run in the same browser context ([#177](https://github.com/MetaMask/connect-monorepo/pull/177))
29
+ - Clean up stale MWP session from KVStore on connection rejection so subsequent QR code connection attempts are not blocked ([#180](https://github.com/MetaMask/connect-monorepo/pull/180))
30
+ - Fix bug with JSON-RPC requests where previously used `id` value could be re-used causing the wallet to ignore the request when a dapp was refreshed/reloaded. ([#183](https://github.com/MetaMask/connect-monorepo/pull/183))
31
+
10
32
  ## [0.5.3]
11
33
 
12
34
  ### Added
@@ -15,6 +37,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
15
37
 
16
38
  ### Fixed
17
39
 
40
+ - Fix QR rejection handling: properly propagate user rejection errors from MetaMask Mobile to the dApp ([#156](https://github.com/MetaMask/connect-monorepo/pull/156))
41
+ - Close QR modal automatically when user rejects connection ([#156](https://github.com/MetaMask/connect-monorepo/pull/156))
42
+ - Use `@metamask/rpc-errors` for EIP-1193 compliant error handling ([#156](https://github.com/MetaMask/connect-monorepo/pull/156))
18
43
  - Fix `sessionProperties` not being passed to `wallet_createSession` when recreating a session after scope/account changes ([#123](https://github.com/MetaMask/connect-monorepo/pull/123))
19
44
 
20
45
  ## [0.5.2]
@@ -132,7 +157,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
132
157
 
133
158
  - Initial release
134
159
 
135
- [Unreleased]: https://github.com/MetaMask/connect-monorepo/compare/@metamask/connect-multichain@0.5.3...HEAD
160
+ [Unreleased]: https://github.com/MetaMask/connect-monorepo/compare/@metamask/connect-multichain@0.6.0...HEAD
161
+ [0.6.0]: https://github.com/MetaMask/connect-monorepo/compare/@metamask/connect-multichain@0.5.3...@metamask/connect-multichain@0.6.0
136
162
  [0.5.3]: https://github.com/MetaMask/connect-monorepo/compare/@metamask/connect-multichain@0.5.2...@metamask/connect-multichain@0.5.3
137
163
  [0.5.2]: https://github.com/MetaMask/connect-monorepo/compare/@metamask/connect-multichain@0.5.1...@metamask/connect-multichain@0.5.2
138
164
  [0.5.1]: https://github.com/MetaMask/connect-monorepo/compare/@metamask/connect-multichain@0.5.0...@metamask/connect-multichain@0.5.1
package/README.md CHANGED
@@ -203,20 +203,26 @@ await client.connect(
203
203
  );
204
204
  ```
205
205
 
206
- ##### `disconnect()`
206
+ ##### `disconnect(scopes?)`
207
207
 
208
- Disconnects from the wallet and cleans up resources.
208
+ Disconnects from the wallet. If `scopes` are provided, only the specified scopes are revoked; if there are remaining scopes, the connection stays alive. If omitted or empty, all scopes are revoked and the connection is fully torn down.
209
209
 
210
210
  **Parameters**
211
211
 
212
- None.
212
+ | Name | Type | Required | Description |
213
+ | -------- | --------- | -------- | -------------------------------------------------------------------- |
214
+ | `scopes` | `Scope[]` | No | Array of CAIP-2 chain identifiers to revoke (defaults to all scopes) |
213
215
 
214
216
  **Returns**
215
217
 
216
218
  `Promise<void>`
217
219
 
218
220
  ```typescript
221
+ // Fully disconnect
219
222
  await client.disconnect();
223
+
224
+ // Disconnect only specific scopes
225
+ await client.disconnect(['eip155:1']);
220
226
  ```
221
227
 
222
228
  ##### `invokeMethod(options)`
@@ -435,6 +435,16 @@ type MultiChainFNOptions = Omit<MultichainOptions, 'storage' | 'ui'> & {
435
435
  } & {
436
436
  storage?: StoreClient;
437
437
  };
438
+ /**
439
+ * Options that can be merged/overwritten when createMultichainClient is called
440
+ * with an existing singleton.
441
+ */
442
+ type MergeableMultichainOptions = Omit<MultichainOptions, 'dapp' | 'analytics' | 'storage' | 'api' | 'ui' | 'transport'> & {
443
+ api?: MultichainOptions['api'];
444
+ ui?: Pick<MultichainOptions['ui'], 'headless' | 'preferExtension' | 'showInstallModal'>;
445
+ transport?: Pick<NonNullable<MultichainOptions['transport']>, 'extensionId'>;
446
+ debug?: boolean;
447
+ };
438
448
  /**
439
449
  * Complete options for Multichain SDK configuration.
440
450
  *
@@ -453,6 +463,8 @@ type ExtendedTransport = Omit<Transport, 'connect'> & {
453
463
  timeout?: number;
454
464
  }) => Promise<TResponse>;
455
465
  getActiveSession: () => Promise<Session | undefined>;
466
+ getStoredPendingSessionRequest: () => Promise<SessionRequest | null>;
467
+ disconnect: (scopes: Scope[]) => Promise<void>;
456
468
  };
457
469
 
458
470
  declare const infuraRpcUrls: RpcUrlsMap;
@@ -474,7 +486,7 @@ declare enum TransportType {
474
486
  * must provide, including session management, connection handling, and method invocation.
475
487
  */
476
488
  declare abstract class MultichainCore extends EventEmitter<SDKEvents> {
477
- protected readonly options: MultichainOptions;
489
+ protected options: MultichainOptions;
478
490
  abstract storage: StoreClient;
479
491
  abstract status: ConnectionStatus;
480
492
  abstract provider: MultichainApiClient<RPCAPI>;
@@ -491,7 +503,7 @@ declare abstract class MultichainCore extends EventEmitter<SDKEvents> {
491
503
  *
492
504
  * @returns Promise that resolves when disconnection is complete
493
505
  */
494
- abstract disconnect(): Promise<void>;
506
+ abstract disconnect(scopes?: Scope[]): Promise<void>;
495
507
  /**
496
508
  * Invokes an RPC method with the specified options.
497
509
  *
@@ -499,8 +511,19 @@ declare abstract class MultichainCore extends EventEmitter<SDKEvents> {
499
511
  * @returns Promise that resolves to the method result
500
512
  */
501
513
  abstract invokeMethod(options: InvokeMethodOptions): Promise<Json>;
502
- abstract openDeeplinkIfNeeded(): void;
514
+ abstract openSimpleDeeplinkIfNeeded(): void;
515
+ abstract emitSessionChanged(): Promise<void>;
503
516
  constructor(options: MultichainOptions);
517
+ /**
518
+ * Merges the given options into the current instance options.
519
+ * Only the mergeable keys are updated (api.supportedNetworks, ui.*, mobile.*, transport.extensionId, debug).
520
+ * The main thing to note is that the value for `dapp` is not merged as it does not make sense for
521
+ * subsequent calls to `createMultichainClient` to have a different `dapp` value.
522
+ * Used when createMultichainClient is called with an existing singleton.
523
+ *
524
+ * @param partial - Options to merge/overwrite onto the current instance
525
+ */
526
+ mergeOptions(partial: MergeableMultichainOptions): void;
504
527
  }
505
528
  declare function getTransportType(type: string): TransportType;
506
529
 
@@ -652,4 +675,4 @@ declare function getVersion(): string;
652
675
 
653
676
  declare const createMultichainClient: CreateMultichainFN;
654
677
 
655
- export { type ConnectionRequest, type ConnectionStatus, type CreateMultichainFN, type DappSettings, type DataType, type DomainErrorCodes, type Enumerate, type ErrorCodeRange, type ErrorCodes, EventEmitter, type EventTypes, type ExtendedTransport, type InstallWidgetProps, type InvokeMethodOptions, type LoggerNameSpaces, Modal, type ModalFactoryConnectOptions, type ModalFactoryOptions, MultichainCore, type MultichainOptions, type NotificationCallback, type OTPCode, type OTPCodeWidgetProps, PlatformType, type QRLink, type RPCAPI, type RPCErrorCodes, RPCHttpErr, RPCInvokeMethodErr, RPCReadonlyRequestErr, RPCReadonlyResponseErr, type RPCResponse, RPC_HANDLED_METHODS, type RpcMethod, type RpcUrlsMap, type SDKEvents, SDK_HANDLED_METHODS, type Scope, type StorageErrorCodes, StoreAdapter, StoreClient, type StoreOptions, TransportType, createLogger, createMultichainClient, enableDebug, getInfuraRpcUrls, getPlatformType, getTransportType, getVersion, getWalletActionAnalyticsProperties, hasExtension, infuraRpcUrls, isEnabled, isMetamaskExtensionInstalled, isRejectionError, isSecure };
678
+ export { type ConnectionRequest, type ConnectionStatus, type CreateMultichainFN, type DappSettings, type DataType, type DomainErrorCodes, type Enumerate, type ErrorCodeRange, type ErrorCodes, EventEmitter, type EventTypes, type ExtendedTransport, type InstallWidgetProps, type InvokeMethodOptions, type LoggerNameSpaces, type MergeableMultichainOptions, Modal, type ModalFactoryConnectOptions, type ModalFactoryOptions, MultichainCore, type MultichainOptions, type NotificationCallback, type OTPCode, type OTPCodeWidgetProps, PlatformType, type QRLink, type RPCAPI, type RPCErrorCodes, RPCHttpErr, RPCInvokeMethodErr, RPCReadonlyRequestErr, RPCReadonlyResponseErr, type RPCResponse, RPC_HANDLED_METHODS, type RpcMethod, type RpcUrlsMap, type SDKEvents, SDK_HANDLED_METHODS, type Scope, type StorageErrorCodes, StoreAdapter, StoreClient, type StoreOptions, TransportType, createLogger, createMultichainClient, enableDebug, getInfuraRpcUrls, getPlatformType, getTransportType, getVersion, getWalletActionAnalyticsProperties, hasExtension, infuraRpcUrls, isEnabled, isMetamaskExtensionInstalled, isRejectionError, isSecure };