@turnkey/core 1.0.0-beta.2 → 1.0.0-beta.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.
- package/dist/__clients__/core.d.ts +92 -9
- package/dist/__clients__/core.d.ts.map +1 -1
- package/dist/__clients__/core.js +699 -535
- package/dist/__clients__/core.js.map +1 -1
- package/dist/__clients__/core.mjs +702 -538
- package/dist/__clients__/core.mjs.map +1 -1
- package/dist/__generated__/sdk-client-base.d.ts +1 -1
- package/dist/__generated__/sdk-client-base.d.ts.map +1 -1
- package/dist/__generated__/sdk-client-base.js +156 -253
- package/dist/__generated__/sdk-client-base.js.map +1 -1
- package/dist/__generated__/sdk-client-base.mjs +156 -253
- package/dist/__generated__/sdk-client-base.mjs.map +1 -1
- package/dist/__generated__/version.d.ts +1 -1
- package/dist/__generated__/version.js +1 -1
- package/dist/__generated__/version.mjs +1 -1
- package/dist/__inputs__/public_api.types.d.ts +377 -504
- package/dist/__inputs__/public_api.types.d.ts.map +1 -1
- package/dist/__types__/base.d.ts +193 -75
- package/dist/__types__/base.d.ts.map +1 -1
- package/dist/__types__/base.js +14 -13
- package/dist/__types__/base.js.map +1 -1
- package/dist/__types__/base.mjs +15 -14
- package/dist/__types__/base.mjs.map +1 -1
- package/dist/__wallet__/base.d.ts +11 -0
- package/dist/__wallet__/base.d.ts.map +1 -1
- package/dist/__wallet__/base.js +12 -1
- package/dist/__wallet__/base.js.map +1 -1
- package/dist/__wallet__/base.mjs +12 -1
- package/dist/__wallet__/base.mjs.map +1 -1
- package/dist/__wallet__/connector.d.ts +31 -4
- package/dist/__wallet__/connector.d.ts.map +1 -1
- package/dist/__wallet__/connector.js +35 -5
- package/dist/__wallet__/connector.js.map +1 -1
- package/dist/__wallet__/connector.mjs +35 -5
- package/dist/__wallet__/connector.mjs.map +1 -1
- package/dist/__wallet__/mobile/manager.d.ts +21 -5
- package/dist/__wallet__/mobile/manager.d.ts.map +1 -1
- package/dist/__wallet__/mobile/manager.js +28 -11
- package/dist/__wallet__/mobile/manager.js.map +1 -1
- package/dist/__wallet__/mobile/manager.mjs +28 -11
- package/dist/__wallet__/mobile/manager.mjs.map +1 -1
- package/dist/__wallet__/stamper.d.ts +73 -2
- package/dist/__wallet__/stamper.d.ts.map +1 -1
- package/dist/__wallet__/stamper.js +81 -15
- package/dist/__wallet__/stamper.js.map +1 -1
- package/dist/__wallet__/stamper.mjs +82 -16
- package/dist/__wallet__/stamper.mjs.map +1 -1
- package/dist/__wallet__/wallet-connect/base.d.ts +102 -19
- package/dist/__wallet__/wallet-connect/base.d.ts.map +1 -1
- package/dist/__wallet__/wallet-connect/base.js +198 -77
- package/dist/__wallet__/wallet-connect/base.js.map +1 -1
- package/dist/__wallet__/wallet-connect/base.mjs +198 -77
- package/dist/__wallet__/wallet-connect/base.mjs.map +1 -1
- package/dist/__wallet__/wallet-connect/client.d.ts +50 -17
- package/dist/__wallet__/wallet-connect/client.d.ts.map +1 -1
- package/dist/__wallet__/wallet-connect/client.js +76 -19
- package/dist/__wallet__/wallet-connect/client.js.map +1 -1
- package/dist/__wallet__/wallet-connect/client.mjs +76 -19
- package/dist/__wallet__/wallet-connect/client.mjs.map +1 -1
- package/dist/__wallet__/web/manager.d.ts +20 -12
- package/dist/__wallet__/web/manager.d.ts.map +1 -1
- package/dist/__wallet__/web/manager.js +29 -21
- package/dist/__wallet__/web/manager.js.map +1 -1
- package/dist/__wallet__/web/manager.mjs +29 -21
- package/dist/__wallet__/web/manager.mjs.map +1 -1
- package/dist/__wallet__/web/native/ethereum.d.ts +45 -11
- package/dist/__wallet__/web/native/ethereum.d.ts.map +1 -1
- package/dist/__wallet__/web/native/ethereum.js +58 -17
- package/dist/__wallet__/web/native/ethereum.js.map +1 -1
- package/dist/__wallet__/web/native/ethereum.mjs +58 -17
- package/dist/__wallet__/web/native/ethereum.mjs.map +1 -1
- package/dist/__wallet__/web/native/solana.d.ts +56 -3
- package/dist/__wallet__/web/native/solana.d.ts.map +1 -1
- package/dist/__wallet__/web/native/solana.js +95 -36
- package/dist/__wallet__/web/native/solana.js.map +1 -1
- package/dist/__wallet__/web/native/solana.mjs +95 -36
- package/dist/__wallet__/web/native/solana.mjs.map +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -10
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +2 -2
- package/dist/utils.d.ts +59 -13
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +105 -30
- package/dist/utils.js.map +1 -1
- package/dist/utils.mjs +103 -29
- package/dist/utils.mjs.map +1 -1
- package/package.json +8 -8
|
@@ -2,32 +2,82 @@
|
|
|
2
2
|
|
|
3
3
|
var SignClient = require('@walletconnect/sign-client');
|
|
4
4
|
|
|
5
|
+
/**
|
|
6
|
+
* WalletConnectClient is a low-level wrapper around the WalletConnect SignClient.
|
|
7
|
+
*
|
|
8
|
+
* - Used internally by `WalletConnectWallet` to manage connections and sessions.
|
|
9
|
+
* - Handles pairing, approval, session tracking, RPC requests, and disconnects.
|
|
10
|
+
* - Exposes a minimal API for lifecycle control; higher-level logic lives in `WalletConnectWallet`.
|
|
11
|
+
*/
|
|
5
12
|
class WalletConnectClient {
|
|
6
13
|
constructor() {
|
|
7
14
|
// tracks the pending approval callback returned from `connect()`
|
|
8
15
|
this.pendingApproval = null;
|
|
9
|
-
//
|
|
16
|
+
// these are subscribers we forward from the underlying WalletConnect SignClient:
|
|
17
|
+
//
|
|
18
|
+
// - sessionUpdateHandlers: fired on 'session_update' when session namespaces
|
|
19
|
+
// (accounts/chains/permissions) change
|
|
20
|
+
//
|
|
21
|
+
// - sessionEventHandlers: fired on 'session_event' for ephemeral wallet events
|
|
22
|
+
// like { event: { name: 'chainChanged' | 'accountsChanged', data }, chainId, topic }
|
|
23
|
+
//
|
|
24
|
+
// - sessionDeleteHandlers: fired on 'session_delete' when the session is terminated
|
|
25
|
+
this.sessionUpdateHandlers = [];
|
|
26
|
+
this.sessionEventHandlers = [];
|
|
10
27
|
this.sessionDeleteHandlers = [];
|
|
11
28
|
}
|
|
12
29
|
/**
|
|
13
|
-
* Registers a callback
|
|
30
|
+
* Registers a callback for WalletConnect `session_delete`.
|
|
14
31
|
*
|
|
15
|
-
* -
|
|
32
|
+
* - Fired from the underlying SignClient when a session is terminated.
|
|
33
|
+
* - Useful for clearing UI state or internal session data after a disconnect.
|
|
16
34
|
*
|
|
17
|
-
* @param fn -
|
|
35
|
+
* @param fn - Callback to invoke when the session is deleted.
|
|
18
36
|
*/
|
|
19
37
|
onSessionDelete(fn) {
|
|
20
38
|
this.sessionDeleteHandlers.push(fn);
|
|
21
39
|
}
|
|
40
|
+
/**
|
|
41
|
+
* Registers a callback for WalletConnect `session_update`.
|
|
42
|
+
*
|
|
43
|
+
* - Triggered when the wallet updates the session namespaces
|
|
44
|
+
* (e.g., accounts/chains/permissions). Use this to refresh providers.
|
|
45
|
+
* - Returns an unsubscribe function to remove the listener.
|
|
46
|
+
*
|
|
47
|
+
* @param fn - Callback invoked when a `session_update` occurs.
|
|
48
|
+
* @returns A function that unsubscribes this listener.
|
|
49
|
+
*/
|
|
50
|
+
onSessionUpdate(fn) {
|
|
51
|
+
this.sessionUpdateHandlers.push(fn);
|
|
52
|
+
return () => {
|
|
53
|
+
this.sessionUpdateHandlers = this.sessionUpdateHandlers.filter((h) => h !== fn);
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Registers a callback for WalletConnect `session_event`.
|
|
58
|
+
*
|
|
59
|
+
* - Emits ephemeral wallet events such as `chainChanged` or `accountsChanged`.
|
|
60
|
+
* - The raw event payload is forwarded so callers can inspect `{ event, chainId, topic }`.
|
|
61
|
+
* - Returns an unsubscribe function to remove the listener.
|
|
62
|
+
*
|
|
63
|
+
* @param fn - Callback receiving the raw session event args.
|
|
64
|
+
* @returns A function that unsubscribes this listener.
|
|
65
|
+
*/
|
|
66
|
+
onSessionEvent(fn) {
|
|
67
|
+
this.sessionEventHandlers.push(fn);
|
|
68
|
+
return () => {
|
|
69
|
+
this.sessionEventHandlers = this.sessionEventHandlers.filter((h) => h !== fn);
|
|
70
|
+
};
|
|
71
|
+
}
|
|
22
72
|
/**
|
|
23
73
|
* Initializes the WalletConnect SignClient with your project credentials.
|
|
24
74
|
*
|
|
25
|
-
* - Must be called before
|
|
26
|
-
* - Configures metadata and
|
|
75
|
+
* - Must be called before `pair()`, `approve()`, or `request()`.
|
|
76
|
+
* - Configures app metadata and an optional custom relay server.
|
|
27
77
|
*
|
|
28
78
|
* @param opts.projectId - WalletConnect project ID.
|
|
29
|
-
* @param opts.
|
|
30
|
-
* @param opts.relayUrl - (Optional)
|
|
79
|
+
* @param opts.appMetadata - Metadata about your app (name, URL, icons).
|
|
80
|
+
* @param opts.relayUrl - (Optional) custom relay server URL.
|
|
31
81
|
* @returns A promise that resolves once the client is initialized.
|
|
32
82
|
*/
|
|
33
83
|
async init(opts) {
|
|
@@ -36,20 +86,27 @@ class WalletConnectClient {
|
|
|
36
86
|
metadata: opts.appMetadata,
|
|
37
87
|
...(opts.relayUrl ? { relayUrl: opts.relayUrl } : {}),
|
|
38
88
|
});
|
|
39
|
-
//
|
|
89
|
+
// fan out WalletConnect SignClient events to our subscribers
|
|
40
90
|
this.client.on("session_delete", () => {
|
|
41
91
|
this.sessionDeleteHandlers.forEach((h) => h());
|
|
42
92
|
});
|
|
93
|
+
this.client.on("session_update", () => {
|
|
94
|
+
this.sessionUpdateHandlers.forEach((h) => h());
|
|
95
|
+
});
|
|
96
|
+
this.client.on("session_event", (args) => {
|
|
97
|
+
this.sessionEventHandlers.forEach((h) => h(args));
|
|
98
|
+
});
|
|
43
99
|
}
|
|
44
100
|
/**
|
|
45
101
|
* Initiates a pairing request and returns a URI to be scanned or deep-linked.
|
|
46
102
|
*
|
|
47
|
-
* -
|
|
103
|
+
* - Requires `init()` to have been called.
|
|
104
|
+
* - Must be followed by `approve()` after the wallet approves.
|
|
48
105
|
* - Throws if a pairing is already in progress.
|
|
49
106
|
*
|
|
50
|
-
* @param namespaces -
|
|
107
|
+
* @param namespaces - Optional namespaces requesting capabilities.
|
|
51
108
|
* @returns A WalletConnect URI for the wallet to connect with.
|
|
52
|
-
* @throws {Error} If a pairing is already in progress or URI is
|
|
109
|
+
* @throws {Error} If a pairing is already in progress or no URI is returned.
|
|
53
110
|
*/
|
|
54
111
|
async pair(namespaces) {
|
|
55
112
|
if (this.pendingApproval) {
|
|
@@ -67,10 +124,10 @@ class WalletConnectClient {
|
|
|
67
124
|
/**
|
|
68
125
|
* Completes the pairing approval process after the wallet approves the request.
|
|
69
126
|
*
|
|
70
|
-
* -
|
|
127
|
+
* - Requires `init()` and a pending pairing started via `pair()`.
|
|
71
128
|
*
|
|
72
129
|
* @returns A promise that resolves to the established session.
|
|
73
|
-
* @throws {Error} If called before `pair()` or approval fails.
|
|
130
|
+
* @throws {Error} If called before `pair()` or if approval fails.
|
|
74
131
|
*/
|
|
75
132
|
async approve() {
|
|
76
133
|
if (!this.pendingApproval) {
|
|
@@ -97,13 +154,13 @@ class WalletConnectClient {
|
|
|
97
154
|
/**
|
|
98
155
|
* Sends a JSON-RPC request over the active WalletConnect session.
|
|
99
156
|
*
|
|
100
|
-
* -
|
|
157
|
+
* - Requires `init()` and an active session.
|
|
101
158
|
*
|
|
102
|
-
* @param chainId -
|
|
103
|
-
* @param method -
|
|
104
|
-
* @param params -
|
|
159
|
+
* @param chainId - Target chain ID (e.g. `eip155:1`).
|
|
160
|
+
* @param method - RPC method name.
|
|
161
|
+
* @param params - Parameters for the RPC method.
|
|
105
162
|
* @returns A promise that resolves with the RPC response.
|
|
106
|
-
* @throws {Error} If no active session
|
|
163
|
+
* @throws {Error} If no active session exists.
|
|
107
164
|
*/
|
|
108
165
|
async request(chainId, method, params) {
|
|
109
166
|
const session = this.getSession();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.js","sources":["../../../src/__wallet__/wallet-connect/client.ts"],"sourcesContent":[null],"names":[],"mappings":";;;;
|
|
1
|
+
{"version":3,"file":"client.js","sources":["../../../src/__wallet__/wallet-connect/client.ts"],"sourcesContent":[null],"names":[],"mappings":";;;;AAOA;;;;;;AAMG;MACU,mBAAmB,CAAA;AAAhC,IAAA,WAAA,GAAA;;QAIU,IAAe,CAAA,eAAA,GAAgD,IAAI;;;;;;;;;;QAWnE,IAAqB,CAAA,qBAAA,GAAsB,EAAE;QAC7C,IAAoB,CAAA,oBAAA,GAA+B,EAAE;QACrD,IAAqB,CAAA,qBAAA,GAAsB,EAAE;;AAErD;;;;;;;AAOG;AACI,IAAA,eAAe,CAAC,EAAc,EAAA;AACnC,QAAA,IAAI,CAAC,qBAAqB,CAAC,IAAI,CAAC,EAAE,CAAC;;AAGrC;;;;;;;;;AASG;AACI,IAAA,eAAe,CAAC,EAAc,EAAA;AACnC,QAAA,IAAI,CAAC,qBAAqB,CAAC,IAAI,CAAC,EAAE,CAAC;AACnC,QAAA,OAAO,MAAK;AACV,YAAA,IAAI,CAAC,qBAAqB,GAAG,IAAI,CAAC,qBAAqB,CAAC,MAAM,CAC5D,CAAC,CAAC,KAAK,CAAC,KAAK,EAAE,CAChB;AACH,SAAC;;AAGH;;;;;;;;;AASG;AACI,IAAA,cAAc,CAAC,EAAuB,EAAA;AAC3C,QAAA,IAAI,CAAC,oBAAoB,CAAC,IAAI,CAAC,EAAE,CAAC;AAClC,QAAA,OAAO,MAAK;AACV,YAAA,IAAI,CAAC,oBAAoB,GAAG,IAAI,CAAC,oBAAoB,CAAC,MAAM,CAC1D,CAAC,CAAC,KAAK,CAAC,KAAK,EAAE,CAChB;AACH,SAAC;;AAGH;;;;;;;;;;AAUG;IACH,MAAM,IAAI,CAAC,IAIV,EAAA;AACC,QAAA,IAAI,CAAC,MAAM,GAAG,MAAM,UAAU,CAAC,IAAI,CAAC;YAClC,SAAS,EAAE,IAAI,CAAC,SAAS;YACzB,QAAQ,EAAE,IAAI,CAAC,WAAW;AAC1B,YAAA,IAAI,IAAI,CAAC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SignClient.
|
|
5
|
+
*
|
|
6
|
+
* - Used internally by `WalletConnectWallet` to manage connections and sessions.
|
|
7
|
+
* - Handles pairing, approval, session tracking, RPC requests, and disconnects.
|
|
8
|
+
* - Exposes a minimal API for lifecycle control; higher-level logic lives in `WalletConnectWallet`.
|
|
9
|
+
*/
|
|
3
10
|
class WalletConnectClient {
|
|
4
11
|
constructor() {
|
|
5
12
|
// tracks the pending approval callback returned from `connect()`
|
|
6
13
|
this.pendingApproval = null;
|
|
7
|
-
//
|
|
14
|
+
// these are subscribers we forward from the underlying WalletConnect SignClient:
|
|
15
|
+
//
|
|
16
|
+
// - sessionUpdateHandlers: fired on 'session_update' when session namespaces
|
|
17
|
+
// (accounts/chains/permissions) change
|
|
18
|
+
//
|
|
19
|
+
// - sessionEventHandlers: fired on 'session_event' for ephemeral wallet events
|
|
20
|
+
// like { event: { name: 'chainChanged' | 'accountsChanged', data }, chainId, topic }
|
|
21
|
+
//
|
|
22
|
+
// - sessionDeleteHandlers: fired on 'session_delete' when the session is terminated
|
|
23
|
+
this.sessionUpdateHandlers = [];
|
|
24
|
+
this.sessionEventHandlers = [];
|
|
8
25
|
this.sessionDeleteHandlers = [];
|
|
9
26
|
}
|
|
10
27
|
/**
|
|
11
|
-
* Registers a callback
|
|
28
|
+
* Registers a callback for WalletConnect `session_delete`.
|
|
12
29
|
*
|
|
13
|
-
* -
|
|
30
|
+
* - Fired from the underlying SignClient when a session is terminated.
|
|
31
|
+
* - Useful for clearing UI state or internal session data after a disconnect.
|
|
14
32
|
*
|
|
15
|
-
* @param fn -
|
|
33
|
+
* @param fn - Callback to invoke when the session is deleted.
|
|
16
34
|
*/
|
|
17
35
|
onSessionDelete(fn) {
|
|
18
36
|
this.sessionDeleteHandlers.push(fn);
|
|
19
37
|
}
|
|
38
|
+
/**
|
|
39
|
+
* Registers a callback for WalletConnect `session_update`.
|
|
40
|
+
*
|
|
41
|
+
* - Triggered when the wallet updates the session namespaces
|
|
42
|
+
* (e.g., accounts/chains/permissions). Use this to refresh providers.
|
|
43
|
+
* - Returns an unsubscribe function to remove the listener.
|
|
44
|
+
*
|
|
45
|
+
* @param fn - Callback invoked when a `session_update` occurs.
|
|
46
|
+
* @returns A function that unsubscribes this listener.
|
|
47
|
+
*/
|
|
48
|
+
onSessionUpdate(fn) {
|
|
49
|
+
this.sessionUpdateHandlers.push(fn);
|
|
50
|
+
return () => {
|
|
51
|
+
this.sessionUpdateHandlers = this.sessionUpdateHandlers.filter((h) => h !== fn);
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Registers a callback for WalletConnect `session_event`.
|
|
56
|
+
*
|
|
57
|
+
* - Emits ephemeral wallet events such as `chainChanged` or `accountsChanged`.
|
|
58
|
+
* - The raw event payload is forwarded so callers can inspect `{ event, chainId, topic }`.
|
|
59
|
+
* - Returns an unsubscribe function to remove the listener.
|
|
60
|
+
*
|
|
61
|
+
* @param fn - Callback receiving the raw session event args.
|
|
62
|
+
* @returns A function that unsubscribes this listener.
|
|
63
|
+
*/
|
|
64
|
+
onSessionEvent(fn) {
|
|
65
|
+
this.sessionEventHandlers.push(fn);
|
|
66
|
+
return () => {
|
|
67
|
+
this.sessionEventHandlers = this.sessionEventHandlers.filter((h) => h !== fn);
|
|
68
|
+
};
|
|
69
|
+
}
|
|
20
70
|
/**
|
|
21
71
|
* Initializes the WalletConnect SignClient with your project credentials.
|
|
22
72
|
*
|
|
23
|
-
* - Must be called before
|
|
24
|
-
* - Configures metadata and
|
|
73
|
+
* - Must be called before `pair()`, `approve()`, or `request()`.
|
|
74
|
+
* - Configures app metadata and an optional custom relay server.
|
|
25
75
|
*
|
|
26
76
|
* @param opts.projectId - WalletConnect project ID.
|
|
27
|
-
* @param opts.
|
|
28
|
-
* @param opts.relayUrl - (Optional)
|
|
77
|
+
* @param opts.appMetadata - Metadata about your app (name, URL, icons).
|
|
78
|
+
* @param opts.relayUrl - (Optional) custom relay server URL.
|
|
29
79
|
* @returns A promise that resolves once the client is initialized.
|
|
30
80
|
*/
|
|
31
81
|
async init(opts) {
|
|
@@ -34,20 +84,27 @@ class WalletConnectClient {
|
|
|
34
84
|
metadata: opts.appMetadata,
|
|
35
85
|
...(opts.relayUrl ? { relayUrl: opts.relayUrl } : {}),
|
|
36
86
|
});
|
|
37
|
-
//
|
|
87
|
+
// fan out WalletConnect SignClient events to our subscribers
|
|
38
88
|
this.client.on("session_delete", () => {
|
|
39
89
|
this.sessionDeleteHandlers.forEach((h) => h());
|
|
40
90
|
});
|
|
91
|
+
this.client.on("session_update", () => {
|
|
92
|
+
this.sessionUpdateHandlers.forEach((h) => h());
|
|
93
|
+
});
|
|
94
|
+
this.client.on("session_event", (args) => {
|
|
95
|
+
this.sessionEventHandlers.forEach((h) => h(args));
|
|
96
|
+
});
|
|
41
97
|
}
|
|
42
98
|
/**
|
|
43
99
|
* Initiates a pairing request and returns a URI to be scanned or deep-linked.
|
|
44
100
|
*
|
|
45
|
-
* -
|
|
101
|
+
* - Requires `init()` to have been called.
|
|
102
|
+
* - Must be followed by `approve()` after the wallet approves.
|
|
46
103
|
* - Throws if a pairing is already in progress.
|
|
47
104
|
*
|
|
48
|
-
* @param namespaces -
|
|
105
|
+
* @param namespaces - Optional namespaces requesting capabilities.
|
|
49
106
|
* @returns A WalletConnect URI for the wallet to connect with.
|
|
50
|
-
* @throws {Error} If a pairing is already in progress or URI is
|
|
107
|
+
* @throws {Error} If a pairing is already in progress or no URI is returned.
|
|
51
108
|
*/
|
|
52
109
|
async pair(namespaces) {
|
|
53
110
|
if (this.pendingApproval) {
|
|
@@ -65,10 +122,10 @@ class WalletConnectClient {
|
|
|
65
122
|
/**
|
|
66
123
|
* Completes the pairing approval process after the wallet approves the request.
|
|
67
124
|
*
|
|
68
|
-
* -
|
|
125
|
+
* - Requires `init()` and a pending pairing started via `pair()`.
|
|
69
126
|
*
|
|
70
127
|
* @returns A promise that resolves to the established session.
|
|
71
|
-
* @throws {Error} If called before `pair()` or approval fails.
|
|
128
|
+
* @throws {Error} If called before `pair()` or if approval fails.
|
|
72
129
|
*/
|
|
73
130
|
async approve() {
|
|
74
131
|
if (!this.pendingApproval) {
|
|
@@ -95,13 +152,13 @@ class WalletConnectClient {
|
|
|
95
152
|
/**
|
|
96
153
|
* Sends a JSON-RPC request over the active WalletConnect session.
|
|
97
154
|
*
|
|
98
|
-
* -
|
|
155
|
+
* - Requires `init()` and an active session.
|
|
99
156
|
*
|
|
100
|
-
* @param chainId -
|
|
101
|
-
* @param method -
|
|
102
|
-
* @param params -
|
|
157
|
+
* @param chainId - Target chain ID (e.g. `eip155:1`).
|
|
158
|
+
* @param method - RPC method name.
|
|
159
|
+
* @param params - Parameters for the RPC method.
|
|
103
160
|
* @returns A promise that resolves with the RPC response.
|
|
104
|
-
* @throws {Error} If no active session
|
|
161
|
+
* @throws {Error} If no active session exists.
|
|
105
162
|
*/
|
|
106
163
|
async request(chainId, method, params) {
|
|
107
164
|
const session = this.getSession();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.mjs","sources":["../../../src/__wallet__/wallet-connect/client.ts"],"sourcesContent":[null],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"client.mjs","sources":["../../../src/__wallet__/wallet-connect/client.ts"],"sourcesContent":[null],"names":[],"mappings":";;AAOA;;;;;;AAMG;MACU,mBAAmB,CAAA;AAAhC,IAAA,WAAA,GAAA;;QAIU,IAAe,CAAA,eAAA,GAAgD,IAAI;;;;;;;;;;QAWnE,IAAqB,CAAA,qBAAA,GAAsB,EAAE;QAC7C,IAAoB,CAAA,oBAAA,GAA+B,EAAE;QACrD,IAAqB,CAAA,qBAAA,GAAsB,EAAE;;AAErD;;;;;;;AAOG;AACI,IAAA,eAAe,CAAC,EAAc,EAAA;AACnC,QAAA,IAAI,CAAC,qBAAqB,CAAC,IAAI,CAAC,EAAE,CAAC;;AAGrC;;;;;;;;;AASG;AACI,IAAA,eAAe,CAAC,EAAc,EAAA;AACnC,QAAA,IAAI,CAAC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Z,YAAA,MAAM,IAAI,KAAK,CAAC,kCAAkC,CAAC;;AAGrD,QAAA,OAAO,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC;YACzB,KAAK,EAAE,OAAO,CAAC,KAAK;YACpB,OAAO;AACP,YAAA,OAAO,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE;AAC5B,SAAA,CAAC;;AAGJ;;;;;;;AAOG;AACH,IAAA,MAAM,UAAU,GAAA;AACd,QAAA,MAAM,OAAO,GAAG,IAAI,CAAC,UAAU,EAAE;AACjC,QAAA,IAAI,CAAC,OAAO;YAAE;AAEd,QAAA,MAAM,IAAI,CAAC,MAAM,CAAC,UAAU,CAAC;YAC3B,KAAK,EAAE,OAAO,CAAC,KAAK;YACpB,MAAM,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,OAAO,EAAE,mBAAmB,EAAE;AACrD,SAAA,CAAC;;AAEL;;;;"}
|
|
@@ -10,31 +10,39 @@ export declare class WebWalletManager {
|
|
|
10
10
|
readonly connector?: CrossPlatformWalletConnector;
|
|
11
11
|
/**
|
|
12
12
|
* Constructs a WebWalletManager instance based on the provided configuration.
|
|
13
|
-
* Sets up native wallets and WalletConnect support.
|
|
14
13
|
*
|
|
15
|
-
*
|
|
14
|
+
* - Enables native Ethereum and/or Solana wallet support if configured.
|
|
15
|
+
* - Enables WalletConnect support for Ethereum and/or Solana chains if namespaces are provided.
|
|
16
|
+
* - Sets up `CrossPlatformWalletStamper` and `CrossPlatformWalletConnector` if auth or connecting features are enabled.
|
|
17
|
+
*
|
|
18
|
+
* @param cfg - Wallet manager configuration.
|
|
16
19
|
*/
|
|
17
20
|
constructor(cfg: TWalletManagerConfig);
|
|
18
21
|
/**
|
|
19
|
-
* Initializes
|
|
22
|
+
* Initializes WalletConnect components and any registered wallet interfaces.
|
|
20
23
|
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
24
|
+
* - Initializes the low-level WalletConnect client with the provided config.
|
|
25
|
+
* - Runs any registered async wallet initializers (currently only `WalletConnectWallet`).
|
|
26
|
+
*
|
|
27
|
+
* @param cfg - Wallet manager configuration used for initializing the WalletConnect client.
|
|
23
28
|
*/
|
|
24
29
|
init(cfg: TWalletManagerConfig): Promise<void>;
|
|
25
30
|
/**
|
|
26
|
-
* Retrieves available wallet providers
|
|
31
|
+
* Retrieves available wallet providers, optionally filtered by chain.
|
|
32
|
+
*
|
|
33
|
+
* - If a chain is specified, filters wallet interfaces that support that chain.
|
|
34
|
+
* - Aggregates providers across all wallet interfaces and filters WalletConnect results accordingly.
|
|
27
35
|
*
|
|
28
|
-
* @param chain - Optional chain to filter providers by.
|
|
29
|
-
* @returns A promise that resolves to an array of
|
|
30
|
-
* @throws If no wallet interface is registered for the given chain.
|
|
36
|
+
* @param chain - Optional chain to filter providers by (e.g., Ethereum, Solana).
|
|
37
|
+
* @returns A promise that resolves to an array of `WalletProvider` objects.
|
|
38
|
+
* @throws {Error} If no wallet interface is registered for the given chain.
|
|
31
39
|
*/
|
|
32
40
|
getProviders(chain?: Chain): Promise<WalletProvider[]>;
|
|
33
41
|
/**
|
|
34
|
-
* Registers a wallet interface as supporting a specific blockchain chain.
|
|
42
|
+
* Registers a wallet interface type as supporting a specific blockchain chain.
|
|
35
43
|
*
|
|
36
|
-
* @param chain -
|
|
37
|
-
* @param
|
|
44
|
+
* @param chain - Chain (e.g., Ethereum, Solana).
|
|
45
|
+
* @param interfaceType - Wallet interface type to associate with the chain.
|
|
38
46
|
*/
|
|
39
47
|
private addChainInterface;
|
|
40
48
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"manager.d.ts","sourceRoot":"","sources":["../../../src/__wallet__/web/manager.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,0BAA0B,EAAE,MAAM,YAAY,CAAC;AACxD,OAAO,EAAE,4BAA4B,EAAE,MAAM,cAAc,CAAC;AAG5D,OAAO,EACL,oBAAoB,EACpB,eAAe,EACf,cAAc,EACd,mBAAmB,EACnB,KAAK,EACN,MA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AO,CAAC,iBAAiB,CAMvB;CACH"}
|
|
@@ -11,9 +11,12 @@ var base$1 = require('../wallet-connect/base.js');
|
|
|
11
11
|
class WebWalletManager {
|
|
12
12
|
/**
|
|
13
13
|
* Constructs a WebWalletManager instance based on the provided configuration.
|
|
14
|
-
* Sets up native wallets and WalletConnect support.
|
|
15
14
|
*
|
|
16
|
-
*
|
|
15
|
+
* - Enables native Ethereum and/or Solana wallet support if configured.
|
|
16
|
+
* - Enables WalletConnect support for Ethereum and/or Solana chains if namespaces are provided.
|
|
17
|
+
* - Sets up `CrossPlatformWalletStamper` and `CrossPlatformWalletConnector` if auth or connecting features are enabled.
|
|
18
|
+
*
|
|
19
|
+
* @param cfg - Wallet manager configuration.
|
|
17
20
|
*/
|
|
18
21
|
constructor(cfg) {
|
|
19
22
|
// queue of async initialization functions
|
|
@@ -23,18 +26,18 @@ class WebWalletManager {
|
|
|
23
26
|
// maps a blockchain chain to its corresponding wallet interface types
|
|
24
27
|
this.chainToInterfaces = {};
|
|
25
28
|
/**
|
|
26
|
-
* Registers a wallet interface as supporting a specific blockchain chain.
|
|
29
|
+
* Registers a wallet interface type as supporting a specific blockchain chain.
|
|
27
30
|
*
|
|
28
|
-
* @param chain -
|
|
29
|
-
* @param
|
|
31
|
+
* @param chain - Chain (e.g., Ethereum, Solana).
|
|
32
|
+
* @param interfaceType - Wallet interface type to associate with the chain.
|
|
30
33
|
*/
|
|
31
|
-
this.addChainInterface = (chain,
|
|
34
|
+
this.addChainInterface = (chain, interfaceType) => {
|
|
32
35
|
if (!this.chainToInterfaces[chain])
|
|
33
36
|
this.chainToInterfaces[chain] = [];
|
|
34
|
-
this.chainToInterfaces[chain].push(
|
|
37
|
+
this.chainToInterfaces[chain].push(interfaceType);
|
|
35
38
|
};
|
|
36
|
-
const enableNativeEvm = cfg.chains.ethereum ?? false;
|
|
37
|
-
const enableNativeSol = cfg.chains.solana ?? false;
|
|
39
|
+
const enableNativeEvm = cfg.chains.ethereum?.native ?? false;
|
|
40
|
+
const enableNativeSol = cfg.chains.solana?.native ?? false;
|
|
38
41
|
const ethereumNamespaces = cfg.chains.ethereum?.walletConnectNamespaces ?? [];
|
|
39
42
|
const solanaNamespaces = cfg.chains.solana?.walletConnectNamespaces ?? [];
|
|
40
43
|
const enableWalletConnectEvm = ethereumNamespaces.length > 0;
|
|
@@ -71,32 +74,37 @@ class WebWalletManager {
|
|
|
71
74
|
}
|
|
72
75
|
}
|
|
73
76
|
/**
|
|
74
|
-
* Initializes
|
|
77
|
+
* Initializes WalletConnect components and any registered wallet interfaces.
|
|
75
78
|
*
|
|
76
|
-
*
|
|
77
|
-
*
|
|
79
|
+
* - Initializes the low-level WalletConnect client with the provided config.
|
|
80
|
+
* - Runs any registered async wallet initializers (currently only `WalletConnectWallet`).
|
|
81
|
+
*
|
|
82
|
+
* @param cfg - Wallet manager configuration used for initializing the WalletConnect client.
|
|
78
83
|
*/
|
|
79
84
|
async init(cfg) {
|
|
80
85
|
if (this.wcClient) {
|
|
81
86
|
await this.wcClient.init(cfg.walletConnect);
|
|
82
87
|
}
|
|
83
|
-
//
|
|
88
|
+
// we initialize the high-level WalletConnectWallet
|
|
89
|
+
// we do this because we can't init this inside the constructor since it's async
|
|
84
90
|
await Promise.all(this.initializers.map((fn) => fn()));
|
|
85
|
-
await this.stamper?.init();
|
|
86
91
|
}
|
|
87
92
|
/**
|
|
88
|
-
* Retrieves available wallet providers
|
|
93
|
+
* Retrieves available wallet providers, optionally filtered by chain.
|
|
94
|
+
*
|
|
95
|
+
* - If a chain is specified, filters wallet interfaces that support that chain.
|
|
96
|
+
* - Aggregates providers across all wallet interfaces and filters WalletConnect results accordingly.
|
|
89
97
|
*
|
|
90
|
-
* @param chain - Optional chain to filter providers by.
|
|
91
|
-
* @returns A promise that resolves to an array of
|
|
92
|
-
* @throws If no wallet interface is registered for the given chain.
|
|
98
|
+
* @param chain - Optional chain to filter providers by (e.g., Ethereum, Solana).
|
|
99
|
+
* @returns A promise that resolves to an array of `WalletProvider` objects.
|
|
100
|
+
* @throws {Error} If no wallet interface is registered for the given chain.
|
|
93
101
|
*/
|
|
94
102
|
async getProviders(chain) {
|
|
95
103
|
if (chain) {
|
|
96
|
-
const
|
|
97
|
-
if (!
|
|
104
|
+
const interfaceTypes = this.chainToInterfaces[chain];
|
|
105
|
+
if (!interfaceTypes || interfaceTypes.length === 0)
|
|
98
106
|
throw new Error(`No wallet supports chain: ${chain}`);
|
|
99
|
-
const walletsToQuery =
|
|
107
|
+
const walletsToQuery = interfaceTypes
|
|
100
108
|
.map((iface) => this.wallets[iface])
|
|
101
109
|
.filter(Boolean);
|
|
102
110
|
const providersArrays = await Promise.all(walletsToQuery.map((wallet) => wallet.getProviders()));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"manager.js","sources":["../../../src/__wallet__/web/manager.ts"],"sourcesContent":[null],"names":["WalletInterfaceType","EthereumWallet","Chain","SolanaWallet","WalletConnectClient","WalletConnectWallet","CrossPlatformWalletStamper","CrossPlatformWalletConnector"],"mappings":";;;;;;;;;;MAca,gBAAgB,CAAA;AAmB3B
|
|
1
|
+
{"version":3,"file":"manager.js","sources":["../../../src/__wallet__/web/manager.ts"],"sourcesContent":[null],"names":["WalletInterfaceType","EthereumWallet","Chain","SolanaWallet","WalletConnectClient","WalletConnectWallet","CrossPlatformWalletStamper","CrossPlatformWalletConnector"],"mappings":";;;;;;;;;;MAca,gBAAgB,CAAA;AAmB3B;;;;;;;;AAQG;AACH,IAAA,WAAA,CAAY,GAAyB,EAAA;;QA1B7B,IAAY,CAAA,YAAA,GAA+B,EAAE;;QAM5C,IAAO,CAAA,OAAA,GAA0D,EAAE;;QAGpE,IAAiB,CAAA,iBAAA,GAAkD,EAAE;AAkI7E;;;;;AAKG;AACK,QAAA,IAAA,CAAA,iBAAiB,GAAG,CAC1B,KAAY,EACZ,aAAkC,KAChC;AACF,YAAA,IAAI,CAAC,IAAI,CAAC,iBAAiB,CAAC,KAAK,CAAC;AAAE,gBAAA,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AK,CAAC,6BAA6B,KAAK,CAAA,CAAE,CAAC;YAEvD,MAAM,cAAc,GAAG;AACpB,iBAAA,GAAG,CAAC,CAAC,KAAK,KAAK,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC;iBAClC,MAAM,CAAC,OAAO,CAAsB;YAEvC,MAAM,eAAe,GAAG,MAAM,OAAO,CAAC,GAAG,CACvC,cAAc,CAAC,GAAG,CAAC,CAAC,MAAM,KAAK,MAAM,CAAC,YAAY,EAAE,CAAC,CACtD;;AAGD,YAAA,OAAO;AACJ,iBAAA,IAAI;AACJ,iBAAA,MAAM,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,SAAS,CAAC,SAAS,KAAK,KAAK,CAAC;;;AAInD,QAAA,MAAM,eAAe,GAAG,MAAM,OAAO,CAAC,GAAG,CACvC,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,GAAG,CAAC,CAAC,MAAM,KAAK,MAAM,CAAC,YAAY,EAAE,CAAC,CACnE;AAED,QAAA,OAAO,eAAe,CAAC,IAAI,EAAE;;AAgBhC;;;;"}
|
|
@@ -9,9 +9,12 @@ import { WalletConnectWallet } from '../wallet-connect/base.mjs';
|
|
|
9
9
|
class WebWalletManager {
|
|
10
10
|
/**
|
|
11
11
|
* Constructs a WebWalletManager instance based on the provided configuration.
|
|
12
|
-
* Sets up native wallets and WalletConnect support.
|
|
13
12
|
*
|
|
14
|
-
*
|
|
13
|
+
* - Enables native Ethereum and/or Solana wallet support if configured.
|
|
14
|
+
* - Enables WalletConnect support for Ethereum and/or Solana chains if namespaces are provided.
|
|
15
|
+
* - Sets up `CrossPlatformWalletStamper` and `CrossPlatformWalletConnector` if auth or connecting features are enabled.
|
|
16
|
+
*
|
|
17
|
+
* @param cfg - Wallet manager configuration.
|
|
15
18
|
*/
|
|
16
19
|
constructor(cfg) {
|
|
17
20
|
// queue of async initialization functions
|
|
@@ -21,18 +24,18 @@ class WebWalletManager {
|
|
|
21
24
|
// maps a blockchain chain to its corresponding wallet interface types
|
|
22
25
|
this.chainToInterfaces = {};
|
|
23
26
|
/**
|
|
24
|
-
* Registers a wallet interface as supporting a specific blockchain chain.
|
|
27
|
+
* Registers a wallet interface type as supporting a specific blockchain chain.
|
|
25
28
|
*
|
|
26
|
-
* @param chain -
|
|
27
|
-
* @param
|
|
29
|
+
* @param chain - Chain (e.g., Ethereum, Solana).
|
|
30
|
+
* @param interfaceType - Wallet interface type to associate with the chain.
|
|
28
31
|
*/
|
|
29
|
-
this.addChainInterface = (chain,
|
|
32
|
+
this.addChainInterface = (chain, interfaceType) => {
|
|
30
33
|
if (!this.chainToInterfaces[chain])
|
|
31
34
|
this.chainToInterfaces[chain] = [];
|
|
32
|
-
this.chainToInterfaces[chain].push(
|
|
35
|
+
this.chainToInterfaces[chain].push(interfaceType);
|
|
33
36
|
};
|
|
34
|
-
const enableNativeEvm = cfg.chains.ethereum ?? false;
|
|
35
|
-
const enableNativeSol = cfg.chains.solana ?? false;
|
|
37
|
+
const enableNativeEvm = cfg.chains.ethereum?.native ?? false;
|
|
38
|
+
const enableNativeSol = cfg.chains.solana?.native ?? false;
|
|
36
39
|
const ethereumNamespaces = cfg.chains.ethereum?.walletConnectNamespaces ?? [];
|
|
37
40
|
const solanaNamespaces = cfg.chains.solana?.walletConnectNamespaces ?? [];
|
|
38
41
|
const enableWalletConnectEvm = ethereumNamespaces.length > 0;
|
|
@@ -69,32 +72,37 @@ class WebWalletManager {
|
|
|
69
72
|
}
|
|
70
73
|
}
|
|
71
74
|
/**
|
|
72
|
-
* Initializes
|
|
75
|
+
* Initializes WalletConnect components and any registered wallet interfaces.
|
|
73
76
|
*
|
|
74
|
-
*
|
|
75
|
-
*
|
|
77
|
+
* - Initializes the low-level WalletConnect client with the provided config.
|
|
78
|
+
* - Runs any registered async wallet initializers (currently only `WalletConnectWallet`).
|
|
79
|
+
*
|
|
80
|
+
* @param cfg - Wallet manager configuration used for initializing the WalletConnect client.
|
|
76
81
|
*/
|
|
77
82
|
async init(cfg) {
|
|
78
83
|
if (this.wcClient) {
|
|
79
84
|
await this.wcClient.init(cfg.walletConnect);
|
|
80
85
|
}
|
|
81
|
-
//
|
|
86
|
+
// we initialize the high-level WalletConnectWallet
|
|
87
|
+
// we do this because we can't init this inside the constructor since it's async
|
|
82
88
|
await Promise.all(this.initializers.map((fn) => fn()));
|
|
83
|
-
await this.stamper?.init();
|
|
84
89
|
}
|
|
85
90
|
/**
|
|
86
|
-
* Retrieves available wallet providers
|
|
91
|
+
* Retrieves available wallet providers, optionally filtered by chain.
|
|
92
|
+
*
|
|
93
|
+
* - If a chain is specified, filters wallet interfaces that support that chain.
|
|
94
|
+
* - Aggregates providers across all wallet interfaces and filters WalletConnect results accordingly.
|
|
87
95
|
*
|
|
88
|
-
* @param chain - Optional chain to filter providers by.
|
|
89
|
-
* @returns A promise that resolves to an array of
|
|
90
|
-
* @throws If no wallet interface is registered for the given chain.
|
|
96
|
+
* @param chain - Optional chain to filter providers by (e.g., Ethereum, Solana).
|
|
97
|
+
* @returns A promise that resolves to an array of `WalletProvider` objects.
|
|
98
|
+
* @throws {Error} If no wallet interface is registered for the given chain.
|
|
91
99
|
*/
|
|
92
100
|
async getProviders(chain) {
|
|
93
101
|
if (chain) {
|
|
94
|
-
const
|
|
95
|
-
if (!
|
|
102
|
+
const interfaceTypes = this.chainToInterfaces[chain];
|
|
103
|
+
if (!interfaceTypes || interfaceTypes.length === 0)
|
|
96
104
|
throw new Error(`No wallet supports chain: ${chain}`);
|
|
97
|
-
const walletsToQuery =
|
|
105
|
+
const walletsToQuery = interfaceTypes
|
|
98
106
|
.map((iface) => this.wallets[iface])
|
|
99
107
|
.filter(Boolean);
|
|
100
108
|
const providersArrays = await Promise.all(walletsToQuery.map((wallet) => wallet.getProviders()));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"manager.mjs","sources":["../../../src/__wallet__/web/manager.ts"],"sourcesContent":[null],"names":[],"mappings":";;;;;;;;MAca,gBAAgB,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