@meshconnect/uwc-core 0.2.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.
- package/dist/connection-manager.d.ts +18 -0
- package/dist/connection-manager.d.ts.map +1 -0
- package/dist/connection-manager.js +54 -0
- package/dist/connection-manager.js.map +1 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +4 -0
- package/dist/index.js.map +1 -0
- package/dist/managers/event-manager.d.ts +10 -0
- package/dist/managers/event-manager.d.ts.map +1 -0
- package/dist/managers/event-manager.js +19 -0
- package/dist/managers/event-manager.js.map +1 -0
- package/dist/managers/index.d.ts +3 -0
- package/dist/managers/index.d.ts.map +1 -0
- package/dist/managers/index.js +3 -0
- package/dist/managers/index.js.map +1 -0
- package/dist/managers/session-manager.d.ts +11 -0
- package/dist/managers/session-manager.d.ts.map +1 -0
- package/dist/managers/session-manager.js +36 -0
- package/dist/managers/session-manager.js.map +1 -0
- package/dist/services/connection-service.d.ts +24 -0
- package/dist/services/connection-service.d.ts.map +1 -0
- package/dist/services/connection-service.js +176 -0
- package/dist/services/connection-service.js.map +1 -0
- package/dist/services/index.d.ts +4 -0
- package/dist/services/index.d.ts.map +1 -0
- package/dist/services/index.js +4 -0
- package/dist/services/index.js.map +1 -0
- package/dist/services/network-switch-service.d.ts +20 -0
- package/dist/services/network-switch-service.d.ts.map +1 -0
- package/dist/services/network-switch-service.js +130 -0
- package/dist/services/network-switch-service.js.map +1 -0
- package/dist/services/signature-service.d.ts +18 -0
- package/dist/services/signature-service.d.ts.map +1 -0
- package/dist/services/signature-service.js +53 -0
- package/dist/services/signature-service.js.map +1 -0
- package/dist/services/transaction-service.d.ts +18 -0
- package/dist/services/transaction-service.d.ts.map +1 -0
- package/dist/services/transaction-service.js +53 -0
- package/dist/services/transaction-service.js.map +1 -0
- package/dist/universal-wallet-connector.d.ts +56 -0
- package/dist/universal-wallet-connector.d.ts.map +1 -0
- package/dist/universal-wallet-connector.js +302 -0
- package/dist/universal-wallet-connector.js.map +1 -0
- package/dist/utils/network-rpc-utils.d.ts +10 -0
- package/dist/utils/network-rpc-utils.d.ts.map +1 -0
- package/dist/utils/network-rpc-utils.js +20 -0
- package/dist/utils/network-rpc-utils.js.map +1 -0
- package/package.json +36 -0
- package/src/index.ts +3 -0
- package/src/managers/event-manager.ts +25 -0
- package/src/managers/index.ts +2 -0
- package/src/managers/session-manager.ts +43 -0
- package/src/services/connection-service.ts +248 -0
- package/src/services/index.ts +3 -0
- package/src/services/network-switch-service.ts +182 -0
- package/src/services/signature-service.ts +77 -0
- package/src/services/transaction-service.ts +79 -0
- package/src/universal-wallet-connector.ts +426 -0
- package/src/utils/network-rpc-utils.ts +27 -0
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Service for handling signature operations across different connector types
|
|
3
|
+
*/
|
|
4
|
+
export class SignatureService {
|
|
5
|
+
sessionManager;
|
|
6
|
+
connectors;
|
|
7
|
+
constructor(sessionManager, connectors) {
|
|
8
|
+
this.sessionManager = sessionManager;
|
|
9
|
+
this.connectors = connectors;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Sign a message with the currently connected wallet
|
|
13
|
+
* @param message The message to sign
|
|
14
|
+
* @param provider The wallet provider to use for signing (required for injected connector)
|
|
15
|
+
* @returns A promise that resolves to the signature
|
|
16
|
+
*/
|
|
17
|
+
async signMessage(message, provider) {
|
|
18
|
+
const session = this.sessionManager.getSession();
|
|
19
|
+
if (!session.connectionMode) {
|
|
20
|
+
throw new Error('No active connection');
|
|
21
|
+
}
|
|
22
|
+
if (!session.activeAddress) {
|
|
23
|
+
throw new Error('No active wallet address');
|
|
24
|
+
}
|
|
25
|
+
// Get the appropriate connector
|
|
26
|
+
const connector = this.connectors.get(session.connectionMode);
|
|
27
|
+
if (!connector) {
|
|
28
|
+
throw new Error(`No connector found for connection mode: ${session.connectionMode}`);
|
|
29
|
+
}
|
|
30
|
+
// Check if the connector supports signing
|
|
31
|
+
if (!connector.signMessage) {
|
|
32
|
+
throw new Error(`Connector does not support message signing`);
|
|
33
|
+
}
|
|
34
|
+
// Call the connector's signMessage method with the appropriate provider
|
|
35
|
+
if (session.connectionMode === 'injected') {
|
|
36
|
+
if (!provider) {
|
|
37
|
+
throw new Error('Provider is required for injected connector');
|
|
38
|
+
}
|
|
39
|
+
return await connector.signMessage(message, provider);
|
|
40
|
+
}
|
|
41
|
+
else if (session.connectionMode === 'walletConnect') {
|
|
42
|
+
if (!provider) {
|
|
43
|
+
throw new Error('Provider is required for WalletConnect connector');
|
|
44
|
+
}
|
|
45
|
+
return await connector.signMessage(message, provider);
|
|
46
|
+
}
|
|
47
|
+
else {
|
|
48
|
+
// For other connectors that might not need the provider
|
|
49
|
+
return await connector.signMessage(message);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
//# sourceMappingURL=signature-service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"signature-service.js","sourceRoot":"","sources":["../../src/services/signature-service.ts"],"names":[],"mappings":"AAUA;;GAEG;AACH,MAAM,OAAO,gBAAgB;IAEjB;IACA;IAFV,YACU,cAA8B,EAC9B,UAA0C;QAD1C,mBAAc,GAAd,cAAc,CAAgB;QAC9B,eAAU,GAAV,UAAU,CAAgC;IACjD,CAAC;IAEJ;;;;;OAKG;IACH,KAAK,CAAC,WAAW,CACf,OAAe,EACf,QAA4B;QAE5B,MAAM,OAAO,GAAG,IAAI,CAAC,cAAc,CAAC,UAAU,EAAE,CAAA;QAEhD,IAAI,CAAC,OAAO,CAAC,cAAc,EAAE,CAAC;YAC5B,MAAM,IAAI,KAAK,CAAC,sBAAsB,CAAC,CAAA;QACzC,CAAC;QAED,IAAI,CAAC,OAAO,CAAC,aAAa,EAAE,CAAC;YAC3B,MAAM,IAAI,KAAK,CAAC,0BAA0B,CAAC,CAAA;QAC7C,CAAC;QAED,gCAAgC;QAChC,MAAM,SAAS,GAAG,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,OAAO,CAAC,cAAc,CAAC,CAAA;QAC7D,IAAI,CAAC,SAAS,EAAE,CAAC;YACf,MAAM,IAAI,KAAK,CACb,2CAA2C,OAAO,CAAC,cAAc,EAAE,CACpE,CAAA;QACH,CAAC;QAED,0CAA0C;QAC1C,IAAI,CAAC,SAAS,CAAC,WAAW,EAAE,CAAC;YAC3B,MAAM,IAAI,KAAK,CAAC,4CAA4C,CAAC,CAAA;QAC/D,CAAC;QAED,wEAAwE;QACxE,IAAI,OAAO,CAAC,cAAc,KAAK,UAAU,EAAE,CAAC;YAC1C,IAAI,CAAC,QAAQ,EAAE,CAAC;gBACd,MAAM,IAAI,KAAK,CAAC,6CAA6C,CAAC,CAAA;YAChE,CAAC;YACD,OAAO,MAAM,SAAS,CAAC,WAAW,CAChC,OAAO,EACP,QAEqC,CACtC,CAAA;QACH,CAAC;aAAM,IAAI,OAAO,CAAC,cAAc,KAAK,eAAe,EAAE,CAAC;YACtD,IAAI,CAAC,QAAQ,EAAE,CAAC;gBACd,MAAM,IAAI,KAAK,CAAC,kDAAkD,CAAC,CAAA;YACrE,CAAC;YACD,OAAO,MAAM,SAAS,CAAC,WAAW,CAChC,OAAO,EACP,QAAiC,CAClC,CAAA;QACH,CAAC;aAAM,CAAC;YACN,wDAAwD;YACxD,OAAO,MAAM,SAAS,CAAC,WAAW,CAAC,OAAO,CAAC,CAAA;QAC7C,CAAC;IACH,CAAC;CACF"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { ConnectionMode, Connector, SupportedProvider, TransactionRequest, TransactionResult } from '@meshconnect/uwc-types';
|
|
2
|
+
import type { SessionManager } from '../managers/session-manager';
|
|
3
|
+
/**
|
|
4
|
+
* Service for handling transaction operations across different connector types
|
|
5
|
+
*/
|
|
6
|
+
export declare class TransactionService {
|
|
7
|
+
private sessionManager;
|
|
8
|
+
private connectors;
|
|
9
|
+
constructor(sessionManager: SessionManager, connectors: Map<ConnectionMode, Connector>);
|
|
10
|
+
/**
|
|
11
|
+
* Send a transaction with the currently connected wallet
|
|
12
|
+
* @param request The transaction request parameters
|
|
13
|
+
* @param provider The wallet provider to use for sending (required for injected connector)
|
|
14
|
+
* @returns A promise that resolves to the transaction result
|
|
15
|
+
*/
|
|
16
|
+
sendTransaction(request: TransactionRequest, provider?: SupportedProvider): Promise<TransactionResult>;
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=transaction-service.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transaction-service.d.ts","sourceRoot":"","sources":["../../src/services/transaction-service.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,cAAc,EACd,SAAS,EAIT,iBAAiB,EACjB,kBAAkB,EAClB,iBAAiB,EAClB,MAAM,wBAAwB,CAAA;AAC/B,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAA;AAEjE;;GAEG;AACH,qBAAa,kBAAkB;IAE3B,OAAO,CAAC,cAAc;IACtB,OAAO,CAAC,UAAU;gBADV,cAAc,EAAE,cAAc,EAC9B,UAAU,EAAE,GAAG,CAAC,cAAc,EAAE,SAAS,CAAC;IAGpD;;;;;OAKG;IACG,eAAe,CACnB,OAAO,EAAE,kBAAkB,EAC3B,QAAQ,CAAC,EAAE,iBAAiB,GAC3B,OAAO,CAAC,iBAAiB,CAAC;CAgD9B"}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Service for handling transaction operations across different connector types
|
|
3
|
+
*/
|
|
4
|
+
export class TransactionService {
|
|
5
|
+
sessionManager;
|
|
6
|
+
connectors;
|
|
7
|
+
constructor(sessionManager, connectors) {
|
|
8
|
+
this.sessionManager = sessionManager;
|
|
9
|
+
this.connectors = connectors;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Send a transaction with the currently connected wallet
|
|
13
|
+
* @param request The transaction request parameters
|
|
14
|
+
* @param provider The wallet provider to use for sending (required for injected connector)
|
|
15
|
+
* @returns A promise that resolves to the transaction result
|
|
16
|
+
*/
|
|
17
|
+
async sendTransaction(request, provider) {
|
|
18
|
+
const session = this.sessionManager.getSession();
|
|
19
|
+
if (!session.connectionMode) {
|
|
20
|
+
throw new Error('No active connection');
|
|
21
|
+
}
|
|
22
|
+
if (!session.activeAddress) {
|
|
23
|
+
throw new Error('No active wallet address');
|
|
24
|
+
}
|
|
25
|
+
// Get the appropriate connector
|
|
26
|
+
const connector = this.connectors.get(session.connectionMode);
|
|
27
|
+
if (!connector) {
|
|
28
|
+
throw new Error(`No connector found for connection mode: ${session.connectionMode}`);
|
|
29
|
+
}
|
|
30
|
+
// Check if the connector supports transactions
|
|
31
|
+
if (!connector.sendTransaction) {
|
|
32
|
+
throw new Error(`Connector does not support transactions`);
|
|
33
|
+
}
|
|
34
|
+
// Call the connector's sendTransaction method with the appropriate provider
|
|
35
|
+
if (session.connectionMode === 'injected') {
|
|
36
|
+
if (!provider) {
|
|
37
|
+
throw new Error('Provider is required for injected connector');
|
|
38
|
+
}
|
|
39
|
+
return await connector.sendTransaction(request, provider);
|
|
40
|
+
}
|
|
41
|
+
else if (session.connectionMode === 'walletConnect') {
|
|
42
|
+
if (!provider) {
|
|
43
|
+
throw new Error('Provider is required for WalletConnect connector');
|
|
44
|
+
}
|
|
45
|
+
return await connector.sendTransaction(request, provider);
|
|
46
|
+
}
|
|
47
|
+
else {
|
|
48
|
+
// For other connectors that might not need the provider
|
|
49
|
+
return await connector.sendTransaction(request);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
//# sourceMappingURL=transaction-service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transaction-service.js","sourceRoot":"","sources":["../../src/services/transaction-service.ts"],"names":[],"mappings":"AAYA;;GAEG;AACH,MAAM,OAAO,kBAAkB;IAEnB;IACA;IAFV,YACU,cAA8B,EAC9B,UAA0C;QAD1C,mBA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EACP,QAAiC,CAClC,CAAA;QACH,CAAC;aAAM,CAAC;YACN,wDAAwD;YACxD,OAAO,MAAM,SAAS,CAAC,eAAe,CAAC,OAAO,CAAC,CAAA;QACjD,CAAC;IACH,CAAC;CACF"}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import type { UniversalWalletConnectorState, Network, WalletMetadata, NetworkId, ConnectionMode, WalletConnectConfig, TransactionRequest, TransactionResult } from '@meshconnect/uwc-types';
|
|
2
|
+
export declare class UniversalWalletConnector {
|
|
3
|
+
private static instanceCount;
|
|
4
|
+
private static hasWarnedAboutMultipleInstances;
|
|
5
|
+
private sessionManager;
|
|
6
|
+
private eventManager;
|
|
7
|
+
private connectionService;
|
|
8
|
+
private networkSwitchService;
|
|
9
|
+
private signatureService;
|
|
10
|
+
private transactionService;
|
|
11
|
+
private connectors;
|
|
12
|
+
private injectedConnector;
|
|
13
|
+
private wallets;
|
|
14
|
+
private usingIntegratedBrowser;
|
|
15
|
+
private detectionComplete;
|
|
16
|
+
private networkRpcMap;
|
|
17
|
+
constructor(networks: Network[], wallets?: WalletMetadata[], usingIntegratedBrowser?: boolean, walletConnectConfig?: WalletConnectConfig);
|
|
18
|
+
/**
|
|
19
|
+
* Discovers available wallets and updates the wallet metadata
|
|
20
|
+
*/
|
|
21
|
+
private initializeDetectedWallets;
|
|
22
|
+
getSession(): import("@meshconnect/uwc-types").Session;
|
|
23
|
+
isReady(): boolean;
|
|
24
|
+
subscribe(listener: () => void): () => void;
|
|
25
|
+
getState(): UniversalWalletConnectorState;
|
|
26
|
+
getWallets(): WalletMetadata[];
|
|
27
|
+
getNetworks(): Network[];
|
|
28
|
+
connect(connectionMode: ConnectionMode, walletId: string, networkId?: NetworkId): Promise<void>;
|
|
29
|
+
getConnectionURI(): string | undefined;
|
|
30
|
+
disconnect(): Promise<void>;
|
|
31
|
+
switchNetwork(networkId: NetworkId): Promise<void>;
|
|
32
|
+
getNetworkSwitchLoadingState(): {
|
|
33
|
+
isLoading: boolean;
|
|
34
|
+
isWaitingForUserApproval: boolean;
|
|
35
|
+
};
|
|
36
|
+
/**
|
|
37
|
+
* Sign a message with the connected wallet
|
|
38
|
+
* @param message The message to sign
|
|
39
|
+
* @returns A promise that resolves to the signature
|
|
40
|
+
*/
|
|
41
|
+
signMessage(message: string): Promise<string>;
|
|
42
|
+
/**
|
|
43
|
+
* Send a transaction with the connected wallet
|
|
44
|
+
* @param request The transaction request parameters
|
|
45
|
+
* @returns A promise that resolves to the transaction result
|
|
46
|
+
*/
|
|
47
|
+
sendTransaction(request: TransactionRequest): Promise<TransactionResult>;
|
|
48
|
+
/**
|
|
49
|
+
* Check if a connection mode is available for a specific wallet
|
|
50
|
+
* @param connectionMode The connection mode to check
|
|
51
|
+
* @param walletId The wallet ID to check availability for
|
|
52
|
+
* @returns True if the connection mode is available, false otherwise
|
|
53
|
+
*/
|
|
54
|
+
isConnectionModeAvailable(connectionMode: ConnectionMode, walletId: string): boolean;
|
|
55
|
+
}
|
|
56
|
+
//# sourceMappingURL=universal-wallet-connector.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"universal-wallet-connector.d.ts","sourceRoot":"","sources":["../src/universal-wallet-connector.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,6BAA6B,EAC7B,OAAO,EACP,cAAc,EACd,SAAS,EACT,cAAc,EACd,mBAAmB,EAKnB,kBAAkB,EAClB,iBAAiB,EAElB,MAAM,wBAAwB,CAAA;AAW/B,qBAAa,wBAAwB;IACnC,OAAO,CAAC,MAAM,CAAC,aAAa,CAAI;IAChC,OAAO,CAAC,MAAM,CAAC,+BAA+B,CAAQ;IAEtD,OAAO,CAAC,cAAc,CAAgB;IACtC,OAAO,CAAC,YAAY,CAAc;IAClC,OAAO,CAAC,iBAAiB,CAAmB;IAC5C,OAAO,CAAC,oBAAoB,CAAsB;IAClD,OAAO,CAAC,gBAAgB,CAAkB;IAC1C,OAAO,CAAC,kBAAkB,CAAoB;IAC9C,OAAO,CAAC,UAAU,CAAgC;IAClD,OAAO,CAAC,iBAAiB,CAAmB;IAC5C,OAAO,CAAC,OAAO,CAAkB;IACjC,OAAO,CAAC,sBAAsB,CAAS;IACvC,OAAO,CAAC,iBAAiB,CAAQ;IACjC,OAAO,CAAC,aAAa,CAAe;gBAGlC,QAAQ,EAAE,OAAO,EAAE,EACnB,OAAO,GAAE,cAAc,EAAO,EAC9B,sBAAsB,UAAQ,EAC9B,mBAAmB,CAAC,EAAE,mBAAmB;IAiF3C;;OAEG;YACW,yBAAyB;IA+HvC,UAAU;IAIV,OAAO;IAIP,SAAS,CAAC,QAAQ,EAAE,MAAM,IAAI,GAAG,MAAM,IAAI;IAI3C,QAAQ,IAAI,6BAA6B;IAMzC,UAAU,IAAI,cAAc,EAAE;IAI9B,WAAW,IAAI,OAAO,EAAE;IAIlB,OAAO,CACX,cAAc,EAAE,cAAc,EAC9B,QAAQ,EAAE,MAAM,EAChB,SAAS,CAAC,EAAE,SAAS,GACpB,OAAO,CAAC,IAAI,CAAC;IAKhB,gBAAgB,IAAI,MAAM,GAAG,SAAS;IAIhC,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;IAK3B,aAAa,CAAC,SAAS,EAAE,SAAS,GAAG,OAAO,CAAC,IAAI,CAAC;IAKxD,4BAA4B;;;;IAI5B;;;;OAIG;IACG,WAAW,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IA4BnD;;;;OAIG;IACG,eAAe,CACnB,OAAO,EAAE,kBAAkB,GAC1B,OAAO,CAAC,iBAAiB,CAAC;IA4B7B;;;;;OAKG;IACH,yBAAyB,CACvB,cAAc,EAAE,cAAc,EAC9B,QAAQ,EAAE,MAAM,GACf,OAAO;CAsCX"}
|
|
@@ -0,0 +1,302 @@
|
|
|
1
|
+
import { InjectedConnector } from '@meshconnect/uwc-injected-connector';
|
|
2
|
+
import { WalletConnectConnector } from '@meshconnect/uwc-wallet-connect-connector';
|
|
3
|
+
import { SessionManager } from './managers/session-manager';
|
|
4
|
+
import { EventManager } from './managers/event-manager';
|
|
5
|
+
import { ConnectionService } from './services/connection-service';
|
|
6
|
+
import { NetworkSwitchService } from './services/network-switch-service';
|
|
7
|
+
import { SignatureService } from './services/signature-service';
|
|
8
|
+
import { TransactionService } from './services/transaction-service';
|
|
9
|
+
import { createNetworkRpcMap } from './utils/network-rpc-utils';
|
|
10
|
+
export class UniversalWalletConnector {
|
|
11
|
+
static instanceCount = 0;
|
|
12
|
+
static hasWarnedAboutMultipleInstances = false;
|
|
13
|
+
sessionManager;
|
|
14
|
+
eventManager;
|
|
15
|
+
connectionService;
|
|
16
|
+
networkSwitchService;
|
|
17
|
+
signatureService;
|
|
18
|
+
transactionService;
|
|
19
|
+
connectors;
|
|
20
|
+
injectedConnector;
|
|
21
|
+
wallets;
|
|
22
|
+
usingIntegratedBrowser;
|
|
23
|
+
detectionComplete = false;
|
|
24
|
+
networkRpcMap;
|
|
25
|
+
constructor(networks, wallets = [], usingIntegratedBrowser = false, walletConnectConfig) {
|
|
26
|
+
// Track instance creation
|
|
27
|
+
UniversalWalletConnector.instanceCount++;
|
|
28
|
+
// Warn about multiple instances
|
|
29
|
+
if (UniversalWalletConnector.instanceCount > 1 &&
|
|
30
|
+
!UniversalWalletConnector.hasWarnedAboutMultipleInstances) {
|
|
31
|
+
// eslint-disable-next-line no-console
|
|
32
|
+
console.error(`⚠️ WARNING: Multiple instances of UniversalWalletConnector detected (${UniversalWalletConnector.instanceCount} instances). ` +
|
|
33
|
+
'This can lead to state inconsistencies and unexpected behavior. ' +
|
|
34
|
+
'Please ensure you create only one instance and reuse it throughout your application. ' +
|
|
35
|
+
'Consider using a singleton pattern or a context provider. ' +
|
|
36
|
+
'You can ignore this warning if you are using React Strict Mode, which intentionally mounts components twice in development to help identify side effects.');
|
|
37
|
+
UniversalWalletConnector.hasWarnedAboutMultipleInstances = true;
|
|
38
|
+
}
|
|
39
|
+
if (!networks || networks.length === 0) {
|
|
40
|
+
throw new Error('Universal Wallet Connector must be initialized with at least one network');
|
|
41
|
+
}
|
|
42
|
+
if (!wallets || wallets.length === 0) {
|
|
43
|
+
throw new Error('Universal Wallet Connector must be initialized with at least one wallet');
|
|
44
|
+
}
|
|
45
|
+
this.wallets = wallets;
|
|
46
|
+
this.usingIntegratedBrowser = usingIntegratedBrowser;
|
|
47
|
+
// Create RPC map from networks
|
|
48
|
+
this.networkRpcMap = createNetworkRpcMap(networks);
|
|
49
|
+
// Initialize connectors with RPC map
|
|
50
|
+
this.connectors = new Map();
|
|
51
|
+
this.injectedConnector = new InjectedConnector(this.networkRpcMap);
|
|
52
|
+
this.connectors.set('injected', this.injectedConnector);
|
|
53
|
+
// Only add WalletConnect connector if config is provided
|
|
54
|
+
if (walletConnectConfig) {
|
|
55
|
+
this.connectors.set('walletConnect', new WalletConnectConnector(walletConnectConfig, this.networkRpcMap));
|
|
56
|
+
}
|
|
57
|
+
this.sessionManager = new SessionManager();
|
|
58
|
+
this.eventManager = new EventManager();
|
|
59
|
+
this.connectionService = new ConnectionService(networks, this.wallets, this.sessionManager, this.connectors, usingIntegratedBrowser, this.eventManager);
|
|
60
|
+
this.networkSwitchService = new NetworkSwitchService(networks, this.sessionManager, this.connectors, usingIntegratedBrowser, this.eventManager);
|
|
61
|
+
this.signatureService = new SignatureService(this.sessionManager, this.connectors);
|
|
62
|
+
this.transactionService = new TransactionService(this.sessionManager, this.connectors);
|
|
63
|
+
// Initialize detected wallets after services are created
|
|
64
|
+
this.initializeDetectedWallets();
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Discovers available wallets and updates the wallet metadata
|
|
68
|
+
*/
|
|
69
|
+
async initializeDetectedWallets() {
|
|
70
|
+
try {
|
|
71
|
+
// Collect all unique namespaces from all wallets
|
|
72
|
+
const namespaces = new Set();
|
|
73
|
+
this.wallets.forEach(wallet => {
|
|
74
|
+
const provider = this.usingIntegratedBrowser
|
|
75
|
+
? wallet.integratedBrowserInjectedProvider
|
|
76
|
+
: wallet.extensionInjectedProvider;
|
|
77
|
+
if (provider?.namespaceMetaData) {
|
|
78
|
+
Object.keys(provider.namespaceMetaData).forEach(ns => {
|
|
79
|
+
namespaces.add(ns);
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
// Check available wallets for each namespace across all connectors
|
|
84
|
+
for (const namespace of namespaces) {
|
|
85
|
+
for (const [, connector] of this.connectors) {
|
|
86
|
+
// Check if connector supports getAvailableWallets
|
|
87
|
+
if (typeof connector.getAvailableWallets === 'function') {
|
|
88
|
+
try {
|
|
89
|
+
const detectedWallets = await connector.getAvailableWallets(namespace);
|
|
90
|
+
// Update wallets with detected information
|
|
91
|
+
detectedWallets.forEach(detected => {
|
|
92
|
+
// Find matching wallet based on namespace-specific naming
|
|
93
|
+
let wallet;
|
|
94
|
+
if (namespace === 'eip155') {
|
|
95
|
+
// For EIP155, match by eip155Name
|
|
96
|
+
wallet = this.wallets.find(w => {
|
|
97
|
+
const provider = this.usingIntegratedBrowser
|
|
98
|
+
? w.integratedBrowserInjectedProvider
|
|
99
|
+
: w.extensionInjectedProvider;
|
|
100
|
+
return (provider?.namespaceMetaData?.eip155?.eip155Name?.toLowerCase() ===
|
|
101
|
+
detected.name.toLowerCase());
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
else if (namespace === 'solana') {
|
|
105
|
+
// For Solana, match by walletStandardName
|
|
106
|
+
wallet = this.wallets.find(w => {
|
|
107
|
+
const provider = this.usingIntegratedBrowser
|
|
108
|
+
? w.integratedBrowserInjectedProvider
|
|
109
|
+
: w.extensionInjectedProvider;
|
|
110
|
+
return (provider?.namespaceMetaData?.solana?.walletStandardName?.toLowerCase() ===
|
|
111
|
+
detected.name.toLowerCase());
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
else {
|
|
115
|
+
// For other namespaces, fall back to wallet name
|
|
116
|
+
wallet = this.wallets.find(w => w.name.toLowerCase() === detected.name.toLowerCase());
|
|
117
|
+
}
|
|
118
|
+
if (wallet) {
|
|
119
|
+
// Determine which provider to update based on usingIntegratedBrowser
|
|
120
|
+
const provider = this.usingIntegratedBrowser
|
|
121
|
+
? wallet.integratedBrowserInjectedProvider
|
|
122
|
+
: wallet.extensionInjectedProvider;
|
|
123
|
+
// Update the appropriate namespace metadata
|
|
124
|
+
if (provider?.namespaceMetaData) {
|
|
125
|
+
const nsMetadata = provider.namespaceMetaData[namespace];
|
|
126
|
+
if (nsMetadata && namespace === 'eip155') {
|
|
127
|
+
// For EIP155, we have specific fields
|
|
128
|
+
const eip155Metadata = nsMetadata;
|
|
129
|
+
eip155Metadata.installed = true;
|
|
130
|
+
const eip155Detected = detected;
|
|
131
|
+
eip155Metadata.detectedWallet = {
|
|
132
|
+
uuid: eip155Detected.uuid,
|
|
133
|
+
name: eip155Detected.name,
|
|
134
|
+
icon: eip155Detected.icon,
|
|
135
|
+
rdns: eip155Detected.rdns
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
else if (namespace === 'solana') {
|
|
139
|
+
// For Solana, we have different fields
|
|
140
|
+
const solanaMetadata = nsMetadata;
|
|
141
|
+
solanaMetadata.installed = true;
|
|
142
|
+
const solanaDetected = detected;
|
|
143
|
+
solanaMetadata.detectedWallet = {
|
|
144
|
+
uuid: solanaDetected.uuid,
|
|
145
|
+
name: solanaDetected.name,
|
|
146
|
+
features: solanaDetected.features
|
|
147
|
+
};
|
|
148
|
+
}
|
|
149
|
+
// For other namespaces, we could add different handling if needed
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
catch {
|
|
155
|
+
// Silently handle errors for individual connector/namespace combinations
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
// Notify the connection service to update its internal wallets reference
|
|
161
|
+
this.connectionService.updateWallets(this.wallets);
|
|
162
|
+
// Mark detection as complete
|
|
163
|
+
this.detectionComplete = true;
|
|
164
|
+
// Notify listeners about the update
|
|
165
|
+
this.eventManager.notify();
|
|
166
|
+
}
|
|
167
|
+
catch {
|
|
168
|
+
// Silently handle error during initialization
|
|
169
|
+
this.detectionComplete = true;
|
|
170
|
+
this.eventManager.notify();
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
getSession() {
|
|
174
|
+
return this.sessionManager.getSession();
|
|
175
|
+
}
|
|
176
|
+
isReady() {
|
|
177
|
+
return this.detectionComplete;
|
|
178
|
+
}
|
|
179
|
+
subscribe(listener) {
|
|
180
|
+
return this.eventManager.subscribe(listener);
|
|
181
|
+
}
|
|
182
|
+
getState() {
|
|
183
|
+
return {
|
|
184
|
+
session: this.sessionManager.getSession()
|
|
185
|
+
};
|
|
186
|
+
}
|
|
187
|
+
getWallets() {
|
|
188
|
+
return this.connectionService.getWallets();
|
|
189
|
+
}
|
|
190
|
+
getNetworks() {
|
|
191
|
+
return this.connectionService.getNetworks();
|
|
192
|
+
}
|
|
193
|
+
async connect(connectionMode, walletId, networkId) {
|
|
194
|
+
await this.connectionService.connect(connectionMode, walletId, networkId);
|
|
195
|
+
this.eventManager.notify();
|
|
196
|
+
}
|
|
197
|
+
getConnectionURI() {
|
|
198
|
+
return this.connectionService.getConnectionURI();
|
|
199
|
+
}
|
|
200
|
+
async disconnect() {
|
|
201
|
+
await this.connectionService.disconnect();
|
|
202
|
+
this.eventManager.notify();
|
|
203
|
+
}
|
|
204
|
+
async switchNetwork(networkId) {
|
|
205
|
+
await this.networkSwitchService.switchNetwork(networkId);
|
|
206
|
+
this.eventManager.notify();
|
|
207
|
+
}
|
|
208
|
+
getNetworkSwitchLoadingState() {
|
|
209
|
+
return this.networkSwitchService.getLoadingState();
|
|
210
|
+
}
|
|
211
|
+
/**
|
|
212
|
+
* Sign a message with the connected wallet
|
|
213
|
+
* @param message The message to sign
|
|
214
|
+
* @returns A promise that resolves to the signature
|
|
215
|
+
*/
|
|
216
|
+
async signMessage(message) {
|
|
217
|
+
const session = this.sessionManager.getSession();
|
|
218
|
+
if (!session.activeWallet) {
|
|
219
|
+
throw new Error('No active wallet');
|
|
220
|
+
}
|
|
221
|
+
if (!session.connectionMode) {
|
|
222
|
+
throw new Error('No active connection');
|
|
223
|
+
}
|
|
224
|
+
// Get the provider from the active wallet based on connection mode
|
|
225
|
+
let provider;
|
|
226
|
+
if (session.connectionMode === 'injected') {
|
|
227
|
+
provider = this.usingIntegratedBrowser
|
|
228
|
+
? session.activeWallet.integratedBrowserInjectedProvider
|
|
229
|
+
: session.activeWallet.extensionInjectedProvider;
|
|
230
|
+
}
|
|
231
|
+
else if (session.connectionMode === 'walletConnect') {
|
|
232
|
+
provider = session.activeWallet.walletConnectProvider;
|
|
233
|
+
}
|
|
234
|
+
if (!provider) {
|
|
235
|
+
throw new Error('No provider available for the active wallet');
|
|
236
|
+
}
|
|
237
|
+
return await this.signatureService.signMessage(message, provider);
|
|
238
|
+
}
|
|
239
|
+
/**
|
|
240
|
+
* Send a transaction with the connected wallet
|
|
241
|
+
* @param request The transaction request parameters
|
|
242
|
+
* @returns A promise that resolves to the transaction result
|
|
243
|
+
*/
|
|
244
|
+
async sendTransaction(request) {
|
|
245
|
+
const session = this.sessionManager.getSession();
|
|
246
|
+
if (!session.activeWallet) {
|
|
247
|
+
throw new Error('No active wallet');
|
|
248
|
+
}
|
|
249
|
+
if (!session.connectionMode) {
|
|
250
|
+
throw new Error('No active connection');
|
|
251
|
+
}
|
|
252
|
+
// Get the provider from the active wallet based on connection mode
|
|
253
|
+
let provider;
|
|
254
|
+
if (session.connectionMode === 'injected') {
|
|
255
|
+
provider = this.usingIntegratedBrowser
|
|
256
|
+
? session.activeWallet.integratedBrowserInjectedProvider
|
|
257
|
+
: session.activeWallet.extensionInjectedProvider;
|
|
258
|
+
}
|
|
259
|
+
else if (session.connectionMode === 'walletConnect') {
|
|
260
|
+
provider = session.activeWallet.walletConnectProvider;
|
|
261
|
+
}
|
|
262
|
+
if (!provider) {
|
|
263
|
+
throw new Error('No provider available for the active wallet');
|
|
264
|
+
}
|
|
265
|
+
return await this.transactionService.sendTransaction(request, provider);
|
|
266
|
+
}
|
|
267
|
+
/**
|
|
268
|
+
* Check if a connection mode is available for a specific wallet
|
|
269
|
+
* @param connectionMode The connection mode to check
|
|
270
|
+
* @param walletId The wallet ID to check availability for
|
|
271
|
+
* @returns True if the connection mode is available, false otherwise
|
|
272
|
+
*/
|
|
273
|
+
isConnectionModeAvailable(connectionMode, walletId) {
|
|
274
|
+
// Find the wallet
|
|
275
|
+
const wallet = this.wallets.find(w => w.id === walletId);
|
|
276
|
+
if (!wallet) {
|
|
277
|
+
return false;
|
|
278
|
+
}
|
|
279
|
+
if (connectionMode === 'walletConnect') {
|
|
280
|
+
// WalletConnect is available if the connector exists and wallet has WalletConnect provider
|
|
281
|
+
return (this.connectors.has('walletConnect') &&
|
|
282
|
+
wallet.walletConnectProvider !== undefined);
|
|
283
|
+
}
|
|
284
|
+
if (connectionMode === 'injected') {
|
|
285
|
+
// Check the appropriate provider based on browser type
|
|
286
|
+
const provider = this.usingIntegratedBrowser
|
|
287
|
+
? wallet.integratedBrowserInjectedProvider
|
|
288
|
+
: wallet.extensionInjectedProvider;
|
|
289
|
+
if (!provider) {
|
|
290
|
+
return false;
|
|
291
|
+
}
|
|
292
|
+
// Check if at least one namespace is installed
|
|
293
|
+
const hasInstalledNamespace = provider.namespaceMetaData
|
|
294
|
+
? Object.values(provider.namespaceMetaData).some(namespace => namespace?.installed === true)
|
|
295
|
+
: false;
|
|
296
|
+
// Injected is available if provider exists and wallet is installed
|
|
297
|
+
return hasInstalledNamespace;
|
|
298
|
+
}
|
|
299
|
+
return false;
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
//# sourceMappingURL=universal-wallet-connector.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"universal-wallet-connector.js","sourceRoot":"","sources":["../src/universal-wallet-connector.ts"],"names":[],"mappings":"AAeA,OAAO,EAAE,iBAAiB,EAAE,MAAM,qCAAqC,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,cAAc,KAAK,eAAe,EAAE,CAAC;YACvC,2FAA2F;YAC3F,OAAO,CACL,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,eAAe,CAAC;gBACpC,MAAM,CAAC,qBAAqB,KAAK,SAAS,CAC3C,CAAA;QACH,CAAC;QAED,IAAI,cAAc,KAAK,UAAU,EAAE,CAAC;YAClC,uDAAuD;YACvD,MAAM,QAAQ,GAAG,IAAI,CAAC,sBAAsB;gBAC1C,CAAC,CAAC,MAAM,CAAC,iCAAiC;gBAC1C,CAAC,CAAC,MAAM,CAAC,yBAAyB,CAAA;YAEpC,IAAI,CAAC,QAAQ,EAAE,CAAC;gBACd,OAAO,KAAK,CAAA;YACd,CAAC;YAED,+CAA+C;YAC/C,MAAM,qBAAqB,GAAG,QAAQ,CAAC,iBAAiB;gBACtD,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,QAAQ,CAAC,iBAAiB,CAAC,CAAC,IAAI,CAC5C,SAAS,CAAC,EAAE,CAAC,SAAS,EAAE,SAAS,KAAK,IAAI,CAC3C;gBACH,CAAC,CAAC,KAAK,CAAA;YAET,mEAAmE;YACnE,OAAO,qBAAqB,CAAA;QAC9B,CAAC;QAED,OAAO,KAAK,CAAA;IACd,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { Network, NetworkId, NetworkRpcMap } from '@meshconnect/uwc-types';
|
|
2
|
+
/**
|
|
3
|
+
* Extract RPC URLs from networks array and create a mapping
|
|
4
|
+
*/
|
|
5
|
+
export declare function createNetworkRpcMap(networks: Network[]): NetworkRpcMap;
|
|
6
|
+
/**
|
|
7
|
+
* Get RPC URL for a specific network from the map
|
|
8
|
+
*/
|
|
9
|
+
export declare function getRpcUrlForNetwork(rpcMap: NetworkRpcMap, networkId: NetworkId): string | undefined;
|
|
10
|
+
//# sourceMappingURL=network-rpc-utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"network-rpc-utils.d.ts","sourceRoot":"","sources":["../../src/utils/network-rpc-utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAA;AAE/E;;GAEG;AACH,wBAAgB,mBAAmB,CAAC,QAAQ,EAAE,OAAO,EAAE,GAAG,aAAa,CAWtE;AAED;;GAEG;AACH,wBAAgB,mBAAmB,CACjC,MAAM,EAAE,aAAa,EACrB,SAAS,EAAE,SAAS,GACnB,MAAM,GAAG,SAAS,CAEpB"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Extract RPC URLs from networks array and create a mapping
|
|
3
|
+
*/
|
|
4
|
+
export function createNetworkRpcMap(networks) {
|
|
5
|
+
const rpcMap = {};
|
|
6
|
+
for (const network of networks) {
|
|
7
|
+
if (network.rpcUrls?.default?.http?.[0]) {
|
|
8
|
+
// Use the first HTTP RPC URL as the default
|
|
9
|
+
rpcMap[network.id] = network.rpcUrls.default.http[0];
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
return rpcMap;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Get RPC URL for a specific network from the map
|
|
16
|
+
*/
|
|
17
|
+
export function getRpcUrlForNetwork(rpcMap, networkId) {
|
|
18
|
+
return rpcMap[networkId];
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=network-rpc-utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"network-rpc-utils.js","sourceRoot":"","sources":["../../src/utils/network-rpc-utils.ts"],"names":[],"mappings":"AAEA;;GAEG;AACH,MAAM,UAAU,mBAAmB,CAAC,QAAmB;IACrD,MAAM,MAAM,GAAkB,EAAE,CAAA;IAEhC,KAAK,MAAM,OAAO,IAAI,QAAQ,EAAE,CAAC;QAC/B,IAAI,OAAO,CAAC,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;YACxC,4CAA4C;YAC5C,MAAM,CAAC,OAAO,CAAC,EAAE,CAAC,GAAG,OAAO,CAAC,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;QACtD,CAAC;IACH,CAAC;IAED,OAAO,MAAM,CAAA;AACf,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,mBAAmB,CACjC,MAAqB,EACrB,SAAoB;IAEpB,OAAO,MAAM,CAAC,SAAS,CAAC,CAAA;AAC1B,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@meshconnect/uwc-core",
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"description": "Core functionality for Universal Wallet Connector",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "dist/index.js",
|
|
7
|
+
"types": "dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"import": "./dist/index.js",
|
|
11
|
+
"types": "./dist/index.d.ts"
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
"files": [
|
|
15
|
+
"dist",
|
|
16
|
+
"src"
|
|
17
|
+
],
|
|
18
|
+
"dependencies": {
|
|
19
|
+
"@meshconnect/uwc-injected-connector": "0.2.0",
|
|
20
|
+
"@meshconnect/uwc-wallet-connect-connector": "0.2.0",
|
|
21
|
+
"@meshconnect/uwc-types": "0.2.0"
|
|
22
|
+
},
|
|
23
|
+
"devDependencies": {
|
|
24
|
+
"typescript": "^5.9.2"
|
|
25
|
+
},
|
|
26
|
+
"publishConfig": {
|
|
27
|
+
"access": "public"
|
|
28
|
+
},
|
|
29
|
+
"scripts": {
|
|
30
|
+
"build": "tsc",
|
|
31
|
+
"dev": "tsc --watch",
|
|
32
|
+
"lint": "eslint src --ext .ts,.tsx",
|
|
33
|
+
"lint:fix": "eslint src --ext .ts,.tsx --fix",
|
|
34
|
+
"type-check": "tsc --noEmit"
|
|
35
|
+
}
|
|
36
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
export type Listener = () => void
|
|
2
|
+
export type Unsubscribe = () => void
|
|
3
|
+
|
|
4
|
+
export class EventManager {
|
|
5
|
+
private listeners: Set<Listener> = new Set()
|
|
6
|
+
|
|
7
|
+
subscribe(listener: Listener): Unsubscribe {
|
|
8
|
+
this.listeners.add(listener)
|
|
9
|
+
return () => {
|
|
10
|
+
this.listeners.delete(listener)
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
notify(): void {
|
|
15
|
+
this.listeners.forEach(listener => listener())
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
getListenerCount(): number {
|
|
19
|
+
return this.listeners.size
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
clearAllListeners(): void {
|
|
23
|
+
this.listeners.clear()
|
|
24
|
+
}
|
|
25
|
+
}
|