@rango-dev/provider-walletconnect-2 0.57.0 → 0.57.1-next.1
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/CHANGELOG.md +4 -0
- package/dist/adapter/adapter.d.ts +39 -0
- package/dist/adapter/adapter.d.ts.map +1 -0
- package/dist/adapter/index.d.ts +3 -0
- package/dist/adapter/index.d.ts.map +1 -0
- package/dist/adapter/modal-cache.d.ts +14 -0
- package/dist/adapter/modal-cache.d.ts.map +1 -0
- package/dist/adapter/modal.d.ts +25 -0
- package/dist/adapter/modal.d.ts.map +1 -0
- package/dist/adapter/networks.d.ts +60 -0
- package/dist/adapter/networks.d.ts.map +1 -0
- package/dist/adapter/provider-client.d.ts +3 -0
- package/dist/adapter/provider-client.d.ts.map +1 -0
- package/dist/adapter/registry.d.ts +4 -0
- package/dist/adapter/registry.d.ts.map +1 -0
- package/dist/adapter/session-cache.d.ts +17 -0
- package/dist/adapter/session-cache.d.ts.map +1 -0
- package/dist/adapter/task-queue.d.ts +11 -0
- package/dist/adapter/task-queue.d.ts.map +1 -0
- package/dist/chunk-GEAT645O.js +2 -0
- package/dist/chunk-GEAT645O.js.map +7 -0
- package/dist/constants.d.ts +4 -48
- package/dist/constants.d.ts.map +1 -0
- package/dist/evm-3KFL5N77.js +2 -0
- package/dist/evm-3KFL5N77.js.map +7 -0
- package/dist/mod.d.ts +4 -0
- package/dist/mod.d.ts.map +1 -0
- package/dist/mod.js +2 -0
- package/dist/mod.js.map +7 -0
- package/dist/namespaces/evm/hooks.d.ts +18 -0
- package/dist/namespaces/evm/hooks.d.ts.map +1 -0
- package/dist/namespaces/evm/namespace.d.ts +4 -0
- package/dist/namespaces/evm/namespace.d.ts.map +1 -0
- package/dist/namespaces/subscriber.d.ts +24 -0
- package/dist/namespaces/subscriber.d.ts.map +1 -0
- package/dist/provider.d.ts +3 -0
- package/dist/provider.d.ts.map +1 -0
- package/dist/session/accounts.d.ts +17 -0
- package/dist/session/accounts.d.ts.map +1 -0
- package/dist/session/bip122.d.ts +23 -0
- package/dist/session/bip122.d.ts.map +1 -0
- package/dist/session/chain-state.d.ts +6 -0
- package/dist/session/chain-state.d.ts.map +1 -0
- package/dist/session/evm-chain.d.ts +29 -0
- package/dist/session/evm-chain.d.ts.map +1 -0
- package/dist/session/evm.d.ts +25 -0
- package/dist/session/evm.d.ts.map +1 -0
- package/dist/session/lifecycle.d.ts +30 -0
- package/dist/session/lifecycle.d.ts.map +1 -0
- package/dist/session/lookup.d.ts +6 -0
- package/dist/session/lookup.d.ts.map +1 -0
- package/dist/session/proposals.d.ts +27 -0
- package/dist/session/proposals.d.ts.map +1 -0
- package/dist/session/restore-cache.d.ts +6 -0
- package/dist/session/restore-cache.d.ts.map +1 -0
- package/dist/session/teardown.d.ts +24 -0
- package/dist/session/teardown.d.ts.map +1 -0
- package/dist/signer.d.ts +2 -2
- package/dist/signer.d.ts.map +1 -0
- package/dist/signers/evm.d.ts +6 -4
- package/dist/signers/evm.d.ts.map +1 -0
- package/dist/types.d.ts +28 -11
- package/dist/types.d.ts.map +1 -0
- package/dist/utils.d.ts +17 -0
- package/dist/utils.d.ts.map +1 -0
- package/dist/wcConstants.d.ts +61 -0
- package/dist/wcConstants.d.ts.map +1 -0
- package/package.json +18 -13
- package/readme.md +14 -2
- package/src/adapter/adapter.ts +289 -0
- package/src/adapter/index.ts +2 -0
- package/src/adapter/modal-cache.ts +23 -0
- package/src/adapter/modal.ts +121 -0
- package/src/adapter/networks.ts +85 -0
- package/src/adapter/provider-client.ts +13 -0
- package/src/adapter/registry.ts +17 -0
- package/src/adapter/session-cache.ts +38 -0
- package/src/adapter/task-queue.ts +32 -0
- package/src/constants.ts +41 -76
- package/src/mod.ts +10 -0
- package/src/namespaces/evm/hooks.ts +148 -0
- package/src/namespaces/evm/namespace.ts +102 -0
- package/src/namespaces/subscriber.ts +106 -0
- package/src/provider.ts +35 -0
- package/src/session/accounts.ts +44 -0
- package/src/session/bip122.ts +225 -0
- package/src/session/chain-state.ts +38 -0
- package/src/session/evm-chain.ts +185 -0
- package/src/session/evm.ts +198 -0
- package/src/session/lifecycle.ts +241 -0
- package/src/session/lookup.ts +54 -0
- package/src/session/proposals.ts +96 -0
- package/src/session/restore-cache.ts +38 -0
- package/src/session/teardown.ts +181 -0
- package/src/signer.ts +9 -17
- package/src/signers/evm.ts +19 -17
- package/src/types.ts +31 -12
- package/src/utils.ts +68 -0
- package/src/wcConstants.ts +94 -0
- package/dist/chunk-6V3WUFOU.js +0 -2
- package/dist/chunk-6V3WUFOU.js.map +0 -7
- package/dist/chunk-BPSEZJUF.js +0 -2
- package/dist/chunk-BPSEZJUF.js.map +0 -7
- package/dist/chunk-DXVBX5XQ.js +0 -2
- package/dist/chunk-DXVBX5XQ.js.map +0 -7
- package/dist/dist-6GI3ECE5.js +0 -139
- package/dist/dist-6GI3ECE5.js.map +0 -7
- package/dist/evm-3ID4XY4Y.js +0 -2
- package/dist/evm-3ID4XY4Y.js.map +0 -7
- package/dist/helpers.d.ts +0 -31
- package/dist/index.d.ts +0 -21
- package/dist/index.js +0 -2
- package/dist/index.js.map +0 -7
- package/dist/session.d.ts +0 -63
- package/dist/signers/solana.d.ts +0 -14
- package/dist/solana-MFA7C5XI.js +0 -2
- package/dist/solana-MFA7C5XI.js.map +0 -7
- package/src/helpers.ts +0 -238
- package/src/index.ts +0 -234
- package/src/session.ts +0 -376
- package/src/signers/solana.ts +0 -160
- package/src/wc-types.d.ts +0 -31
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
# [0.57.0](https://github.com/rango-exchange/rango-client/compare/provider-walletconnect-2@0.56.0...provider-walletconnect-2@0.57.0) (2026-08-18)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
|
|
1
5
|
# [0.56.0](https://github.com/rango-exchange/rango-client/compare/provider-walletconnect-2@0.55.0...provider-walletconnect-2@0.56.0) (2026-07-28)
|
|
2
6
|
|
|
3
7
|
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type { WalletConnectNamespace } from '../types.js';
|
|
2
|
+
import type { Chain } from '@hub3js/evm';
|
|
3
|
+
import type { SessionTypes } from '@walletconnect/types';
|
|
4
|
+
import type UniversalProvider from '@walletconnect/universal-provider';
|
|
5
|
+
import type { BlockchainMeta } from 'rango-types';
|
|
6
|
+
/**
|
|
7
|
+
* Central coordinator for WalletConnect sessions used by hub EVM/UTXO namespaces.
|
|
8
|
+
*
|
|
9
|
+
* Owns provider state (client, session cache, modal) and delegates protocol/domain
|
|
10
|
+
* logic to `session/*` helpers.
|
|
11
|
+
*/
|
|
12
|
+
export interface WalletConnectAdapterConfig {
|
|
13
|
+
projectId: string;
|
|
14
|
+
meta: BlockchainMeta[];
|
|
15
|
+
disableModalLink?: string;
|
|
16
|
+
themeMode?: 'light' | 'dark';
|
|
17
|
+
modalZIndex?: number;
|
|
18
|
+
}
|
|
19
|
+
export declare class WalletConnectAdapter {
|
|
20
|
+
#private;
|
|
21
|
+
constructor(config: WalletConnectAdapterConfig);
|
|
22
|
+
getUniversalProvider(): Promise<UniversalProvider>;
|
|
23
|
+
getClient(): Promise<import("@walletconnect/sign-client").default>;
|
|
24
|
+
getSession(namespace: WalletConnectNamespace): SessionTypes.Struct | null;
|
|
25
|
+
cacheSession(namespace: WalletConnectNamespace, session: SessionTypes.Struct): void;
|
|
26
|
+
clearSession(namespace: WalletConnectNamespace): void;
|
|
27
|
+
clearAllSessions(): void;
|
|
28
|
+
tryRestoreEagerSession(namespace: WalletConnectNamespace): Promise<boolean>;
|
|
29
|
+
ensureSession(options: {
|
|
30
|
+
namespace: WalletConnectNamespace;
|
|
31
|
+
chainReference?: string;
|
|
32
|
+
}): Promise<SessionTypes.Struct>;
|
|
33
|
+
disconnectSession(namespace: WalletConnectNamespace): Promise<void>;
|
|
34
|
+
resolveActiveChainReference(): Promise<string | undefined>;
|
|
35
|
+
getCurrentChainId(): Promise<`0x${string}`>;
|
|
36
|
+
ensureConnectedToChain(chain?: string | Chain): Promise<SessionTypes.Struct>;
|
|
37
|
+
switchEvmNetwork(requestedChainId: string, currentChainId: string): Promise<void>;
|
|
38
|
+
}
|
|
39
|
+
//# sourceMappingURL=adapter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"adapter.d.ts","sourceRoot":"","sources":["../../src/adapter/adapter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,aAAa,CAAC;AAC1D,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AACzD,OAAO,KAAK,iBAAiB,MAAM,mCAAmC,CAAC;AACvE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAuBlD;;;;;GAKG;AACH,MAAM,WAAW,0BAA0B;IACzC,SAAS,EAAE,MAAM,CAAC;IAClB,IAAI,EAAE,cAAc,EAAE,CAAC;IACvB,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,SAAS,CAAC,EAAE,OAAO,GAAG,MAAM,CAAC;IAC7B,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAED,qBAAa,oBAAoB;;gBAkCnB,MAAM,EAAE,0BAA0B;IAQxC,oBAAoB,IAAI,OAAO,CAAC,iBAAiB,CAAC;IA0BlD,SAAS;IAIf,UAAU,CAAC,SAAS,EAAE,sBAAsB,GAAG,YAAY,CAAC,MAAM,GAAG,IAAI;IAIzE,YAAY,CACV,SAAS,EAAE,sBAAsB,EACjC,OAAO,EAAE,YAAY,CAAC,MAAM;IAK9B,YAAY,CAAC,SAAS,EAAE,sBAAsB;IAI9C,gBAAgB;IAIV,sBAAsB,CAC1B,SAAS,EAAE,sBAAsB,GAChC,OAAO,CAAC,OAAO,CAAC;IAcb,aAAa,CAAC,OAAO,EAAE;QAC3B,SAAS,EAAE,sBAAsB,CAAC;QAClC,cAAc,CAAC,EAAE,MAAM,CAAC;KACzB,GAAG,OAAO,CAAC,YAAY,CAAC,MAAM,CAAC;IAM1B,iBAAiB,CAAC,SAAS,EAAE,sBAAsB;IAMnD,2BAA2B,IAAI,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC;IAS1D,iBAAiB,IAAI,OAAO,CAAC,KAAK,MAAM,EAAE,CAAC;IAW3C,sBAAsB,CAC1B,KAAK,CAAC,EAAE,MAAM,GAAG,KAAK,GACrB,OAAO,CAAC,YAAY,CAAC,MAAM,CAAC;IAIzB,gBAAgB,CACpB,gBAAgB,EAAE,MAAM,EACxB,cAAc,EAAE,MAAM,GACrB,OAAO,CAAC,IAAI,CAAC;CAgGjB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/adapter/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAC;AACpD,OAAO,EAAE,KAAK,WAAW,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { AppKitModal, ModalParams } from './modal.js';
|
|
2
|
+
/**
|
|
3
|
+
* Holds the single AppKit modal for the adapter's lifetime.
|
|
4
|
+
*
|
|
5
|
+
* One instance serves every namespace - all its networks are registered up front
|
|
6
|
+
* and the active one is chosen per connect with `switchNetwork`. It is built once
|
|
7
|
+
* and reused: rebuilding per namespace re-ran AppKit init against its shared
|
|
8
|
+
* singleton controllers and left stale router/filter state behind.
|
|
9
|
+
*/
|
|
10
|
+
export declare class ModalCache {
|
|
11
|
+
#private;
|
|
12
|
+
getModal(params: ModalParams): AppKitModal;
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=modal-cache.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"modal-cache.d.ts","sourceRoot":"","sources":["../../src/adapter/modal-cache.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAI3D;;;;;;;GAOG;AACH,qBAAa,UAAU;;IAGrB,QAAQ,CAAC,MAAM,EAAE,WAAW,GAAG,WAAW;CAO3C"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { WalletConnectNamespace } from '../types.js';
|
|
2
|
+
import type UniversalProvider from '@walletconnect/universal-provider';
|
|
3
|
+
export type AppKitModal = ReturnType<typeof createAppKitModal>;
|
|
4
|
+
export type ModalParams = {
|
|
5
|
+
projectId: string;
|
|
6
|
+
universalProvider: UniversalProvider;
|
|
7
|
+
themeMode?: 'light' | 'dark';
|
|
8
|
+
zIndex?: number;
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* Make a namespace's network active before opening the shared modal.
|
|
12
|
+
*
|
|
13
|
+
* `open()` compares the requested namespace against AppKit's active chain: if
|
|
14
|
+
* they differ it treats the open as a network switch and pushes an extra step
|
|
15
|
+
* onto the router, which leaves a stray back button in the modal header. One
|
|
16
|
+
* shared instance keeps whatever chain the previous connect left active, so we
|
|
17
|
+
* switch it to the target here first - then `open()` sees a matching chain and
|
|
18
|
+
* takes its clean, non-switching path.
|
|
19
|
+
*
|
|
20
|
+
* `ready()` first so AppKit init has registered the networks `switchNetwork`
|
|
21
|
+
* looks up.
|
|
22
|
+
*/
|
|
23
|
+
export declare function prepareModalForNamespace(web3Modal: AppKitModal, namespace: WalletConnectNamespace): Promise<void>;
|
|
24
|
+
export declare function createAppKitModal({ projectId, universalProvider, themeMode, zIndex, }: ModalParams): import("@reown/appkit/core").AppKit;
|
|
25
|
+
//# sourceMappingURL=modal.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"modal.d.ts","sourceRoot":"","sources":["../../src/adapter/modal.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,aAAa,CAAC;AAE1D,OAAO,KAAK,iBAAiB,MAAM,mCAAmC,CAAC;AAMvE,MAAM,MAAM,WAAW,GAAG,UAAU,CAAC,OAAO,iBAAiB,CAAC,CAAC;AAI/D,MAAM,MAAM,WAAW,GAAG;IACxB,SAAS,EAAE,MAAM,CAAC;IAClB,iBAAiB,EAAE,iBAAiB,CAAC;IACrC,SAAS,CAAC,EAAE,OAAO,GAAG,MAAM,CAAC;IAC7B,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB,CAAC;AA0BF;;;;;;;;;;;;GAYG;AACH,wBAAsB,wBAAwB,CAC5C,SAAS,EAAE,WAAW,EACtB,SAAS,EAAE,sBAAsB,GAChC,OAAO,CAAC,IAAI,CAAC,CAGf;AAED,wBAAgB,iBAAiB,CAAC,EAChC,SAAS,EACT,iBAAiB,EACjB,SAAmB,EACnB,MAA8B,GAC/B,EAAE,WAAW,uCAmDb"}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/** viem's `mainnet`, the only EVM network we register. */
|
|
2
|
+
export declare const mainnet: {
|
|
3
|
+
formatters: undefined;
|
|
4
|
+
fees: undefined;
|
|
5
|
+
serializers: undefined;
|
|
6
|
+
} & {
|
|
7
|
+
id: number;
|
|
8
|
+
caipNetworkId: "eip155:1";
|
|
9
|
+
chainNamespace: "eip155";
|
|
10
|
+
name: string;
|
|
11
|
+
nativeCurrency: {
|
|
12
|
+
name: string;
|
|
13
|
+
symbol: string;
|
|
14
|
+
decimals: number;
|
|
15
|
+
};
|
|
16
|
+
rpcUrls: {
|
|
17
|
+
default: {
|
|
18
|
+
http: string[];
|
|
19
|
+
};
|
|
20
|
+
};
|
|
21
|
+
blockExplorers: {
|
|
22
|
+
default: {
|
|
23
|
+
name: string;
|
|
24
|
+
url: string;
|
|
25
|
+
apiUrl: string;
|
|
26
|
+
};
|
|
27
|
+
};
|
|
28
|
+
contracts: {
|
|
29
|
+
ensUniversalResolver: {
|
|
30
|
+
address: "0xeeeeeeee14d718c2b47d9923deab1335e144eeee";
|
|
31
|
+
blockCreated: number;
|
|
32
|
+
};
|
|
33
|
+
multicall3: {
|
|
34
|
+
address: "0xca11bde05977b3631167028862be2a173976ca11";
|
|
35
|
+
blockCreated: number;
|
|
36
|
+
};
|
|
37
|
+
};
|
|
38
|
+
};
|
|
39
|
+
/** AppKit's `bitcoin`, the only UTXO network we register. */
|
|
40
|
+
export declare const bitcoin: {
|
|
41
|
+
formatters: undefined;
|
|
42
|
+
fees: undefined;
|
|
43
|
+
serializers: undefined;
|
|
44
|
+
} & {
|
|
45
|
+
id: string;
|
|
46
|
+
caipNetworkId: "bip122:000000000019d6689c085ae165831e93";
|
|
47
|
+
chainNamespace: "bip122";
|
|
48
|
+
name: string;
|
|
49
|
+
nativeCurrency: {
|
|
50
|
+
name: string;
|
|
51
|
+
symbol: string;
|
|
52
|
+
decimals: number;
|
|
53
|
+
};
|
|
54
|
+
rpcUrls: {
|
|
55
|
+
default: {
|
|
56
|
+
http: string[];
|
|
57
|
+
};
|
|
58
|
+
};
|
|
59
|
+
};
|
|
60
|
+
//# sourceMappingURL=networks.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"networks.d.ts","sourceRoot":"","sources":["../../src/adapter/networks.ts"],"names":[],"mappings":"AAuCA,0DAA0D;AAC1D,eAAO,MAAM,OAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA4BI,CAAC;AAEzB,6DAA6D;AAC7D,eAAO,MAAM,OAAO;;;;;;;;;;;;;;;;;;;CAaI,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"provider-client.d.ts","sourceRoot":"","sources":["../../src/adapter/provider-client.ts"],"names":[],"mappings":"AAAA,OAAO,iBAAiB,MAAM,mCAAmC,CAAC;AAIlE,wBAAsB,uBAAuB,CAC3C,SAAS,EAAE,MAAM,GAChB,OAAO,CAAC,iBAAiB,CAAC,CAM5B"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"registry.d.ts","sourceRoot":"","sources":["../../src/adapter/registry.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAC;AAYzD,eAAO,MAAM,UAAU,4BAAgB,CAAC;AAExC,eAAO,MAAM,UAAU,aAAc,oBAAoB,SAExD,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { WalletConnectNamespace } from '../types.js';
|
|
2
|
+
import type { SessionTypes } from '@walletconnect/types';
|
|
3
|
+
export type SessionCache = {
|
|
4
|
+
get(namespace: WalletConnectNamespace): SessionTypes.Struct | null;
|
|
5
|
+
set(namespace: WalletConnectNamespace, session: SessionTypes.Struct): void;
|
|
6
|
+
clear(namespace: WalletConnectNamespace): void;
|
|
7
|
+
/**
|
|
8
|
+
* Drops every namespace holding `topic`. A wallet may approve more than was
|
|
9
|
+
* proposed, so one settled session can back both namespaces - tearing its topic
|
|
10
|
+
* down under one of them would otherwise leave the other pointing at a topic
|
|
11
|
+
* the relay has already dropped.
|
|
12
|
+
*/
|
|
13
|
+
clearTopic(topic: string): void;
|
|
14
|
+
clearAll(): void;
|
|
15
|
+
};
|
|
16
|
+
export declare function createSessionCache(): SessionCache;
|
|
17
|
+
//# sourceMappingURL=session-cache.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"session-cache.d.ts","sourceRoot":"","sources":["../../src/adapter/session-cache.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,aAAa,CAAC;AAC1D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAEzD,MAAM,MAAM,YAAY,GAAG;IACzB,GAAG,CAAC,SAAS,EAAE,sBAAsB,GAAG,YAAY,CAAC,MAAM,GAAG,IAAI,CAAC;IACnE,GAAG,CAAC,SAAS,EAAE,sBAAsB,EAAE,OAAO,EAAE,YAAY,CAAC,MAAM,GAAG,IAAI,CAAC;IAC3E,KAAK,CAAC,SAAS,EAAE,sBAAsB,GAAG,IAAI,CAAC;IAC/C;;;;;OAKG;IACH,UAAU,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IAChC,QAAQ,IAAI,IAAI,CAAC;CAClB,CAAC;AAEF,wBAAgB,kBAAkB,IAAI,YAAY,CAoBjD"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Runs tasks one at a time, in the order `run` was called.
|
|
3
|
+
*
|
|
4
|
+
* A task that rejects passes its rejection to its own caller and does not block
|
|
5
|
+
* the tasks behind it.
|
|
6
|
+
*/
|
|
7
|
+
export declare class TaskQueue {
|
|
8
|
+
#private;
|
|
9
|
+
run<T>(task: () => Promise<T>): Promise<T>;
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=task-queue.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"task-queue.d.ts","sourceRoot":"","sources":["../../src/adapter/task-queue.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,qBAAa,SAAS;;IAId,GAAG,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC;CAqBjD"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
var i=Object.defineProperty;var t=(e,n)=>i(e,"name",{value:n,configurable:!0});var T={evm:"eip155",utxo:"bip122"},_="wc@2:client//namespaces";var A=["chainChanged","accountsChanged"],N=["personal_sign","eth_sendTransaction","eth_signTransaction","wallet_switchEthereumChain","wallet_addEthereumChain","eth_chainId"];var c=["bip122_addressesChanged"],I=["signPsbt","getAccountAddresses"],S={name:"Rango Exchange",description:"The Ultimate Cross-Chain Solution",url:"https://app.rango.exchange/",icons:["https://app.rango.exchange/logo-rounded.png"]},C="wss://relay.walletconnect.com";import{isEvmBlockchain as a}from"rango-types";var s=16;function u(e,n=!1){let r=Array.from(new TextEncoder().encode(e)).map(o=>o.toString(s).padStart(2,"0")).join("");return n?`0x${r}`:r}t(u,"utf8ToHex");function p(e){if(e)return typeof e=="string"?e.startsWith("0x")?String(parseInt(e)):String(parseInt(e,10)||e):String(parseInt(e.chainId))}t(p,"parseChainReference");function x(e,n){let r=p(e??void 0);if(r)return n.find(o=>a(o)&&String(parseInt(o.chainId))===r)?.name}t(x,"resolveNetworkName");function f(e){return`0x${parseInt(e).toString(s)}`}t(f,"chainReferenceToHex");function l(e){return e.filter(a).map(n=>({namespace:"eip155",reference:String(parseInt(n.chainId))}))}t(l,"evmMetaToCaipChainIds");export{t as a,T as b,_ as c,A as d,N as e,c as f,I as g,S as h,C as i,u as j,p as k,x as l,f as m,l as n};
|
|
2
|
+
//# sourceMappingURL=chunk-GEAT645O.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/wcConstants.ts", "../src/utils.ts"],
|
|
4
|
+
"sourcesContent": ["/**\n * WalletConnect protocol constants shared across the hub path (session/,\n * adapter/, signers/, namespaces/). Kept separate from `constants.ts` (which\n * holds the hub provider identity/metadata) so this module stays a dependency\n * leaf and importing it never pulls in the signer/provider graph (the\n * `WalletConnectNamespace` import below is type-only, so it is erased at runtime).\n */\nimport type { WalletConnectNamespace } from './types.js';\n\nexport const PING_TIMEOUT = 10_000;\n\nexport enum NAMESPACES {\n ETHEREUM = 'eip155',\n BITCOIN = 'bip122',\n POLKADOT = 'polkadot',\n CARDANO = 'cip34',\n ERLOND = 'elrond',\n MULTIVERSX = 'multiversx',\n}\n\n/**\n * Single source of truth for the namespace-alias -> CAIP-2 prefix relationship\n * (`evm -> eip155`, `utxo -> bip122`). `proposals` and `lookup` read from this\n * instead of re-encoding it. `Record<WalletConnectNamespace, \u2026>` makes a new\n * alias a compile error until it's mapped.\n */\nexport const WC_NAMESPACE_TO_CAIP: Record<WalletConnectNamespace, string> = {\n evm: NAMESPACES.ETHEREUM,\n utxo: NAMESPACES.BITCOIN,\n};\n\nexport const CHAIN_ID_STORAGE = 'wc@2:client//namespaces';\n\n// Refrence: https://docs.walletconnect.com/2.0/advanced/rpc-reference/ethereum-rpc\nexport enum EthereumRPCMethods {\n PERSONAL_SIGN = 'personal_sign',\n SIGN = 'eth_sign',\n SIGN_TYPED_DATA = 'eth_signTypedData',\n SIGN_TRANSACTION = 'eth_signTransaction',\n SEND_TRANSACTION = 'eth_sendTransaction',\n SEND_RAW_TRANSACTION = 'eth_sendRawTransaction',\n SWITCH_CHAIN = 'wallet_switchEthereumChain',\n ADD_CHAIN = 'wallet_addEthereumChain',\n GET_CHAIN = 'eth_chainId',\n}\n\nexport enum EthereumEvents {\n CHAIN_CHANGED = 'chainChanged',\n ACCOUNTS_CHANGED = 'accountsChanged',\n}\n\nexport const DEFAULT_ETHEREUM_EVENTS: EthereumEvents[] = [\n EthereumEvents.CHAIN_CHANGED,\n EthereumEvents.ACCOUNTS_CHANGED,\n];\n\nexport const DEFAULT_ETHEREUM_METHODS = [\n EthereumRPCMethods.PERSONAL_SIGN,\n EthereumRPCMethods.SEND_TRANSACTION,\n EthereumRPCMethods.SIGN_TRANSACTION,\n EthereumRPCMethods.SWITCH_CHAIN,\n EthereumRPCMethods.ADD_CHAIN,\n EthereumRPCMethods.GET_CHAIN,\n];\n\n// Reference: https://docs.reown.com/advanced/multichain/rpc-reference/bitcoin-rpc\nexport enum BitcoinRPCMethods {\n SIGN_PSBT = 'signPsbt',\n GET_ACCOUNT_ADDRESSES = 'getAccountAddresses',\n SIGN_MESSAGE = 'signMessage',\n SEND_TRANSFER = 'sendTransfer',\n}\n\nexport enum BitcoinEvents {\n ADDRESSES_CHANGED = 'bip122_addressesChanged',\n}\n\nexport const DEFAULT_BITCOIN_EVENTS: BitcoinEvents[] = [\n BitcoinEvents.ADDRESSES_CHANGED,\n];\n\nexport const DEFAULT_BITCOIN_METHODS = [\n BitcoinRPCMethods.SIGN_PSBT,\n BitcoinRPCMethods.GET_ACCOUNT_ADDRESSES,\n];\n\nexport const DEFAULT_APP_METADATA = {\n name: 'Rango Exchange',\n description: 'The Ultimate Cross-Chain Solution',\n url: 'https://app.rango.exchange/',\n icons: ['https://app.rango.exchange/logo-rounded.png'],\n};\n\nexport const RELAY_URL = 'wss://relay.walletconnect.com';\n", "import type { Chain } from '@hub3js/evm';\nimport type { ChainIdParams } from 'caip';\nimport type { BlockchainMeta } from 'rango-types';\n\nimport { isEvmBlockchain } from 'rango-types';\n\nimport { NAMESPACES } from './wcConstants.js';\n\nconst HEX_RADIX = 16;\n\nexport function utf8ToHex(value: string, prefixed = false): string {\n const hex = Array.from(new TextEncoder().encode(value))\n .map((byte) => byte.toString(HEX_RADIX).padStart(2, '0'))\n .join('');\n\n return prefixed ? `0x${hex}` : hex;\n}\n\n/** Normalizes hub chain input (hex, decimal, or AddEthereumChainParameter) to a decimal reference. */\nexport function parseChainReference(\n chain?: string | Chain\n): string | undefined {\n if (!chain) {\n return undefined;\n }\n\n if (typeof chain === 'string') {\n return chain.startsWith('0x')\n ? String(parseInt(chain))\n : String(parseInt(chain, 10) || chain);\n }\n\n return String(parseInt(chain.chainId));\n}\n\n/** Maps a chain reference to a Rango network name using blockchain meta. */\nexport function resolveNetworkName(\n chain: string | Chain | null | undefined,\n meta: BlockchainMeta[]\n): string | undefined {\n const reference = parseChainReference(chain ?? undefined);\n if (!reference) {\n return undefined;\n }\n\n return meta.find(\n (blockchain) =>\n isEvmBlockchain(blockchain) &&\n String(parseInt(blockchain.chainId)) === reference\n )?.name;\n}\n\n/** Converts a decimal EVM chain reference to the `0x`-prefixed hex expected by hub EVM actions. */\nexport function chainReferenceToHex(reference: string): `0x${string}` {\n return `0x${parseInt(reference).toString(HEX_RADIX)}`;\n}\n\n/**\n * Converts rango EVM blockchain meta to CAIP-2 chain ids - the only chain data the\n * connect/proposal path needs. This is the single boundary where rango-types' chain\n * shape is translated; everything downstream uses caip's ChainIdParams.\n */\nexport function evmMetaToCaipChainIds(meta: BlockchainMeta[]): ChainIdParams[] {\n return meta.filter(isEvmBlockchain).map((blockchain) => ({\n namespace: NAMESPACES.ETHEREUM,\n reference: String(parseInt(blockchain.chainId)),\n }));\n}\n"],
|
|
5
|
+
"mappings": "+EA0BO,IAAMA,EAA+D,CAC1E,IAAK,SACL,KAAM,QACR,EAEaC,EAAmB,0BAoBzB,IAAMC,EAA4C,CACvD,eACA,iBACF,EAEaC,EAA2B,CACtC,gBACA,sBACA,sBACA,6BACA,0BACA,aACF,EAcO,IAAMC,EAA0C,CACrD,yBACF,EAEaC,EAA0B,CACrC,WACA,qBACF,EAEaC,EAAuB,CAClC,KAAM,iBACN,YAAa,oCACb,IAAK,8BACL,MAAO,CAAC,6CAA6C,CACvD,EAEaC,EAAY,gCCzFzB,OAAS,mBAAAC,MAAuB,cAIhC,IAAMC,EAAY,GAEX,SAASC,EAAUC,EAAeC,EAAW,GAAe,CACjE,IAAMC,EAAM,MAAM,KAAK,IAAI,YAAY,EAAE,OAAOF,CAAK,CAAC,EACnD,IAAKG,GAASA,EAAK,SAASL,CAAS,EAAE,SAAS,EAAG,GAAG,CAAC,EACvD,KAAK,EAAE,EAEV,OAAOG,EAAW,KAAKC,CAAG,GAAKA,CACjC,CANgBE,EAAAL,EAAA,aAST,SAASM,EACdC,EACoB,CACpB,GAAKA,EAIL,OAAI,OAAOA,GAAU,SACZA,EAAM,WAAW,IAAI,EACxB,OAAO,SAASA,CAAK,CAAC,EACtB,OAAO,SAASA,EAAO,EAAE,GAAKA,CAAK,EAGlC,OAAO,SAASA,EAAM,OAAO,CAAC,CACvC,CAdgBF,EAAAC,EAAA,uBAiBT,SAASE,EACdD,EACAE,EACoB,CACpB,IAAMC,EAAYJ,EAAoBC,GAAS,MAAS,EACxD,GAAKG,EAIL,OAAOD,EAAK,KACTE,GACCC,EAAgBD,CAAU,GAC1B,OAAO,SAASA,EAAW,OAAO,CAAC,IAAMD,CAC7C,GAAG,IACL,CAdgBL,EAAAG,EAAA,sBAiBT,SAASK,EAAoBH,EAAkC,CACpE,MAAO,KAAK,SAASA,CAAS,EAAE,SAASX,CAAS,CAAC,EACrD,CAFgBM,EAAAQ,EAAA,uBAST,SAASC,EAAsBL,EAAyC,CAC7E,OAAOA,EAAK,OAAOG,CAAe,EAAE,IAAKD,IAAgB,CACvD,mBACA,UAAW,OAAO,SAASA,EAAW,OAAO,CAAC,CAChD,EAAE,CACJ,CALgBN,EAAAS,EAAA",
|
|
6
|
+
"names": ["WC_NAMESPACE_TO_CAIP", "CHAIN_ID_STORAGE", "DEFAULT_ETHEREUM_EVENTS", "DEFAULT_ETHEREUM_METHODS", "DEFAULT_BITCOIN_EVENTS", "DEFAULT_BITCOIN_METHODS", "DEFAULT_APP_METADATA", "RELAY_URL", "isEvmBlockchain", "HEX_RADIX", "utf8ToHex", "value", "prefixed", "hex", "byte", "__name", "parseChainReference", "chain", "resolveNetworkName", "meta", "reference", "blockchain", "isEvmBlockchain", "chainReferenceToHex", "evmMetaToCaipChainIds"]
|
|
7
|
+
}
|
package/dist/constants.d.ts
CHANGED
|
@@ -1,48 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export declare const
|
|
3
|
-
export declare const
|
|
4
|
-
|
|
5
|
-
ETHEREUM = "eip155",
|
|
6
|
-
SOLANA = "solana",
|
|
7
|
-
POLKADOT = "polkadot",
|
|
8
|
-
CARDANO = "cip34",
|
|
9
|
-
ERLOND = "elrond",
|
|
10
|
-
MULTIVERSX = "multiversx"
|
|
11
|
-
}
|
|
12
|
-
export declare const CHAIN_ID_STORAGE = "wc@2:client//namespaces";
|
|
13
|
-
export declare enum SolanaRPCMethods {
|
|
14
|
-
GET_ACCOUNTS = "solana_getAccounts",
|
|
15
|
-
REQUEST_ACCOUNTS = "solana_requestAccounts",
|
|
16
|
-
SIGN_TRANSACTION = "solana_signTransaction",
|
|
17
|
-
SIGN_MESSAGE = "solana_signMessage"
|
|
18
|
-
}
|
|
19
|
-
export declare enum EthereumRPCMethods {
|
|
20
|
-
PERSONAL_SIGN = "personal_sign",
|
|
21
|
-
SIGN = "eth_sign",
|
|
22
|
-
SIGN_TYPED_DATA = "eth_signTypedData",
|
|
23
|
-
SIGN_TRANSACTION = "eth_signTransaction",
|
|
24
|
-
SEND_TRANSACTION = "eth_sendTransaction",
|
|
25
|
-
SEND_RAW_TRANSACTION = "eth_sendRawTransaction",
|
|
26
|
-
SWITCH_CHAIN = "wallet_switchEthereumChain",
|
|
27
|
-
ADD_CHAIN = "wallet_addEthereumChain",
|
|
28
|
-
GET_CHAIN = "eth_chainId"
|
|
29
|
-
}
|
|
30
|
-
export declare enum StarknetRPCMethods {
|
|
31
|
-
REQUEST_ADD_INVOKE_TRANSACTION = "starknet_requestAddInvokeTransaction",
|
|
32
|
-
SIGN_TYPED_DATA = "starknet_signTypedData"
|
|
33
|
-
}
|
|
34
|
-
export declare enum EthereumEvents {
|
|
35
|
-
CHAIN_CHANGED = "chainChanged",
|
|
36
|
-
ACCOUNTS_CHANGED = "accountsChanged"
|
|
37
|
-
}
|
|
38
|
-
export declare const DEFAULT_ETHEREUM_EVENTS: EthereumEvents[];
|
|
39
|
-
export declare const DEFAULT_ETHEREUM_METHODS: EthereumRPCMethods[];
|
|
40
|
-
export declare const DEFAULT_SOLANA_METHODS: SolanaRPCMethods[];
|
|
41
|
-
export declare const DEFAULT_SOLANA_CHAIN_ID = "4sGjMW1sUnHzSxGspuhpqLDx6wiyjNtZ";
|
|
42
|
-
export declare const DEFAULT_APP_METADATA: {
|
|
43
|
-
name: string;
|
|
44
|
-
description: string;
|
|
45
|
-
url: string;
|
|
46
|
-
icons: string[];
|
|
47
|
-
};
|
|
48
|
-
export declare const RELAY_URL = "wss://relay.walletconnect.com";
|
|
1
|
+
import type { ProviderMetadata } from '@hub3js/core';
|
|
2
|
+
export declare const WALLET_ID = "wallet-connect-2";
|
|
3
|
+
export declare const metadata: ProviderMetadata;
|
|
4
|
+
//# sourceMappingURL=constants.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAMrD,eAAO,MAAM,SAAS,qBAAqB,CAAC;AAE5C,eAAO,MAAM,QAAQ,EAAE,gBAiCtB,CAAC"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{a as d,j as l}from"./chunk-GEAT645O.js";import{cleanEvmError as p,toHexQuantity as o}from"@rango-dev/signer-evm";import{AccountId as f,ChainId as u}from"caip";import"rango-types";var g="eip155",h=class m{static{d(this,"EVMSigner")}client;getSession;constructor(t,e){this.client=t,this.getSession=e}get session(){let t=this.getSession();if(!t)throw new Error("EVM WalletConnect session is not available.");return t}static buildTx(t){let e={data:t.data||"0x",value:t.value?o(t.value):"0x0"};return t.from&&(e.from=t.from),t.to&&(e.to=t.to),t.nonce&&(e.nonce=o(t.nonce)),t.gasLimit&&(e.gas=o(t.gasLimit)),t.maxFeePerGas&&t.maxPriorityFeePerGas?(e.maxFeePerGas=o(t.maxFeePerGas),e.maxPriorityFeePerGas=o(t.maxPriorityFeePerGas)):t.gasPrice&&(e.gasPrice=o(t.gasPrice)),e}async signMessage(t,e,i){let s=this.isNetworkAndAccountExistInSession({address:e,chainId:i}),r=new u({namespace:g,reference:s.chainId}),a=[l(t,!0),e],c;try{c=await this.client.request({topic:this.session.topic,chainId:r.toString(),request:{method:"personal_sign",params:a}})}catch(S){throw p(S)}return c}async signAndSendTx(t,e,i){try{let s=this.isNetworkAndAccountExistInSession({address:e,chainId:i}),r=m.buildTx(t),n=await this.client.request({topic:this.session.topic,chainId:s.caipChainId,request:{method:"eth_sendTransaction",params:[r]}});if(!n?.startsWith("0x"))throw new Error(`Received an invalid hash on signing the transaction. (hash=${n})`);return{hash:n}}catch(s){let r=p(s),n=this.session,a={namspaces:n?.namespaces,peering:n?.peer?.metadata,code:s?.code};throw r.context=a,r}}isNetworkAndAccountExistInSession(t){let{address:e,chainId:i}=t;if(!i)throw new Error("You need to set your chain for signing message/transaction.");let s=i.startsWith("0x")?String(parseInt(i)):i,r=new f({chainId:{namespace:g,reference:s},address:e}),n=this.session.namespaces[g]?.accounts.map(c=>c.toLowerCase());if(!n||!n.includes(r.toString()))throw new Error("Your requested address doesn't exist on your wallect connect session. Please reconnect your wallet.");let a=new u({namespace:g,reference:s});return{chainId:s,address:e,caipChainId:a.toString()}}},x=h;export{x as default};
|
|
2
|
+
//# sourceMappingURL=evm-3KFL5N77.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/signers/evm.ts"],
|
|
4
|
+
"sourcesContent": ["import type { ISignClient, SessionTypes } from '@walletconnect/types';\nimport type { EvmTransaction } from 'rango-types/mainApi';\n\nimport { cleanEvmError, toHexQuantity } from '@rango-dev/signer-evm';\nimport { AccountId, ChainId } from 'caip';\nimport { type GenericSigner } from 'rango-types';\n\nimport { utf8ToHex } from '../utils.js';\nimport { EthereumRPCMethods, NAMESPACES } from '../wcConstants.js';\n\nconst NAMESPACE_NAME = NAMESPACES.ETHEREUM;\n\ntype SessionGetter = () => SessionTypes.Struct | null;\n\ntype WalletConnectEvmTx = {\n from?: string;\n to?: string;\n data: string;\n value: string;\n gas?: string;\n gasPrice?: string;\n maxFeePerGas?: string;\n maxPriorityFeePerGas?: string;\n nonce?: string;\n};\n\nclass EVMSigner implements GenericSigner<EvmTransaction> {\n private client: ISignClient;\n private getSession: SessionGetter;\n\n constructor(client: ISignClient, getSession: SessionGetter) {\n this.client = client;\n this.getSession = getSession;\n }\n\n private get session(): SessionTypes.Struct {\n const session = this.getSession();\n if (!session) {\n throw new Error('EVM WalletConnect session is not available.');\n }\n return session;\n }\n\n /**\n * Map Rango's EvmTransaction to WalletConnect eth_sendTransaction params.\n *\n * Unlike DefaultEvmSigner.buildTx (ethers TransactionRequest with gasLimit +\n * decimal fee strings), WC sends params raw over the relay. Wallets like\n * Ledger Live parse QUANTITY as hex, so decimal fees get inflated (~40x+).\n *\n * This builder:\n * - uses `gas` (JSON-RPC), not ethers' `gasLimit`\n * - hex-encodes gas, fees, value, and nonce\n */\n static buildTx(evmTx: EvmTransaction): WalletConnectEvmTx {\n const tx: WalletConnectEvmTx = {\n data: evmTx.data || '0x',\n /*\n * Approvals and many contract calls have value=null from the API.\n * Some WC wallets reject missing value; send 0x0 explicitly.\n */\n value: evmTx.value ? toHexQuantity(evmTx.value) : '0x0',\n };\n\n if (evmTx.from) {\n tx.from = evmTx.from;\n }\n if (evmTx.to) {\n tx.to = evmTx.to;\n }\n if (evmTx.nonce) {\n tx.nonce = toHexQuantity(evmTx.nonce);\n }\n if (evmTx.gasLimit) {\n tx.gas = toHexQuantity(evmTx.gasLimit);\n }\n if (evmTx.maxFeePerGas && evmTx.maxPriorityFeePerGas) {\n tx.maxFeePerGas = toHexQuantity(evmTx.maxFeePerGas);\n tx.maxPriorityFeePerGas = toHexQuantity(evmTx.maxPriorityFeePerGas);\n } else if (evmTx.gasPrice) {\n tx.gasPrice = toHexQuantity(evmTx.gasPrice);\n }\n\n return tx;\n }\n\n public async signMessage(\n msg: string,\n address: string,\n chainId: string | null\n ): Promise<string> {\n const requestedFor = this.isNetworkAndAccountExistInSession({\n address,\n chainId,\n });\n\n const caipChainId = new ChainId({\n namespace: NAMESPACE_NAME,\n reference: requestedFor.chainId,\n });\n const hexMsg = utf8ToHex(msg, true);\n\n const params = [hexMsg, address];\n\n let signature: string;\n try {\n // Send message to wallet (using relayer)\n signature = await this.client.request({\n topic: this.session.topic,\n chainId: caipChainId.toString(),\n request: {\n method: EthereumRPCMethods.PERSONAL_SIGN,\n params,\n },\n });\n } catch (error) {\n throw cleanEvmError(error);\n }\n\n /*\n * TODO: We can also verify the signature here\n * Check web-examples: dapps/react-dapp-v2/src/contexts/JsonRpcContext.tsx\n */\n\n return signature;\n }\n\n async signAndSendTx(\n tx: EvmTransaction,\n address: string,\n chainId: string | null\n ): Promise<{ hash: string }> {\n try {\n const requestedFor = this.isNetworkAndAccountExistInSession({\n address,\n chainId,\n });\n const transaction = EVMSigner.buildTx(tx);\n const hash: string = await this.client.request({\n topic: this.session.topic,\n chainId: requestedFor.caipChainId,\n request: {\n method: EthereumRPCMethods.SEND_TRANSACTION,\n params: [transaction],\n },\n });\n // Some wallets e.g. Rainbow wallet are returning invalid hash (e.g. 'null') in case of the rejection\n if (!hash?.startsWith('0x')) {\n throw new Error(\n `Received an invalid hash on signing the transaction. (hash=${hash})`\n );\n }\n\n return {\n hash,\n };\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n } catch (error: any) {\n const modifiedError = cleanEvmError(error);\n const session = this.session;\n const context = {\n namspaces: session?.namespaces,\n peering: session?.peer?.metadata,\n code: error?.code,\n };\n modifiedError.context = context;\n throw modifiedError;\n }\n }\n\n private isNetworkAndAccountExistInSession(requestedFor: {\n address: string;\n chainId: string | null;\n }) {\n const { address, chainId } = requestedFor;\n\n if (!chainId) {\n throw new Error(\n 'You need to set your chain for signing message/transaction.'\n );\n }\n\n /*\n * TODO: We need to make sure we are using a single format for chain ids, it should be hex or number.\n * This is a quick fix for evm.\n */\n const chainIdNumber = chainId.startsWith('0x')\n ? String(parseInt(chainId))\n : chainId;\n\n const caipAddress = new AccountId({\n chainId: {\n namespace: NAMESPACE_NAME,\n reference: chainIdNumber,\n },\n address,\n });\n const addresses = this.session.namespaces[NAMESPACE_NAME]?.accounts.map(\n (address) => address.toLowerCase()\n );\n\n if (!addresses || !addresses.includes(caipAddress.toString())) {\n throw new Error(\n `Your requested address doesn't exist on your wallect connect session. Please reconnect your wallet.`\n );\n }\n\n const caipChainId = new ChainId({\n namespace: NAMESPACE_NAME,\n reference: chainIdNumber,\n });\n\n return {\n chainId: chainIdNumber,\n address,\n caipChainId: caipChainId.toString(),\n };\n }\n}\n\nexport default EVMSigner;\n"],
|
|
5
|
+
"mappings": "+CAGA,OAAS,iBAAAA,EAAe,iBAAAC,MAAqB,wBAC7C,OAAS,aAAAC,EAAW,WAAAC,MAAe,OACnC,MAAmC,cAKnC,IAAMC,WAgBAC,EAAN,MAAMC,CAAmD,CA1BzD,MA0ByD,CAAAC,EAAA,kBAC/C,OACA,WAER,YAAYC,EAAqBC,EAA2B,CAC1D,KAAK,OAASD,EACd,KAAK,WAAaC,CACpB,CAEA,IAAY,SAA+B,CACzC,IAAMC,EAAU,KAAK,WAAW,EAChC,GAAI,CAACA,EACH,MAAM,IAAI,MAAM,6CAA6C,EAE/D,OAAOA,CACT,CAaA,OAAO,QAAQC,EAA2C,CACxD,IAAMC,EAAyB,CAC7B,KAAMD,EAAM,MAAQ,KAKpB,MAAOA,EAAM,MAAQE,EAAcF,EAAM,KAAK,EAAI,KACpD,EAEA,OAAIA,EAAM,OACRC,EAAG,KAAOD,EAAM,MAEdA,EAAM,KACRC,EAAG,GAAKD,EAAM,IAEZA,EAAM,QACRC,EAAG,MAAQC,EAAcF,EAAM,KAAK,GAElCA,EAAM,WACRC,EAAG,IAAMC,EAAcF,EAAM,QAAQ,GAEnCA,EAAM,cAAgBA,EAAM,sBAC9BC,EAAG,aAAeC,EAAcF,EAAM,YAAY,EAClDC,EAAG,qBAAuBC,EAAcF,EAAM,oBAAoB,GACzDA,EAAM,WACfC,EAAG,SAAWC,EAAcF,EAAM,QAAQ,GAGrCC,CACT,CAEA,MAAa,YACXE,EACAC,EACAC,EACiB,CACjB,IAAMC,EAAe,KAAK,kCAAkC,CAC1D,QAAAF,EACA,QAAAC,CACF,CAAC,EAEKE,EAAc,IAAIC,EAAQ,CAC9B,UAAWf,EACX,UAAWa,EAAa,OAC1B,CAAC,EAGKG,EAAS,CAFAC,EAAUP,EAAK,EAAI,EAEVC,CAAO,EAE3BO,EACJ,GAAI,CAEFA,EAAY,MAAM,KAAK,OAAO,QAAQ,CACpC,MAAO,KAAK,QAAQ,MACpB,QAASJ,EAAY,SAAS,EAC9B,QAAS,CACP,uBACA,OAAAE,CACF,CACF,CAAC,CACH,OAASG,EAAO,CACd,MAAMC,EAAcD,CAAK,CAC3B,CAOA,OAAOD,CACT,CAEA,MAAM,cACJV,EACAG,EACAC,EAC2B,CAC3B,GAAI,CACF,IAAMC,EAAe,KAAK,kCAAkC,CAC1D,QAAAF,EACA,QAAAC,CACF,CAAC,EACKS,EAAcnB,EAAU,QAAQM,CAAE,EAClCc,EAAe,MAAM,KAAK,OAAO,QAAQ,CAC7C,MAAO,KAAK,QAAQ,MACpB,QAAST,EAAa,YACtB,QAAS,CACP,6BACA,OAAQ,CAACQ,CAAW,CACtB,CACF,CAAC,EAED,GAAI,CAACC,GAAM,WAAW,IAAI,EACxB,MAAM,IAAI,MACR,8DAA8DA,CAAI,GACpE,EAGF,MAAO,CACL,KAAAA,CACF,CAEF,OAASH,EAAY,CACnB,IAAMI,EAAgBH,EAAcD,CAAK,EACnCb,EAAU,KAAK,QACfkB,EAAU,CACd,UAAWlB,GAAS,WACpB,QAASA,GAAS,MAAM,SACxB,KAAMa,GAAO,IACf,EACA,MAAAI,EAAc,QAAUC,EAClBD,CACR,CACF,CAEQ,kCAAkCV,EAGvC,CACD,GAAM,CAAE,QAAAF,EAAS,QAAAC,CAAQ,EAAIC,EAE7B,GAAI,CAACD,EACH,MAAM,IAAI,MACR,6DACF,EAOF,IAAMa,EAAgBb,EAAQ,WAAW,IAAI,EACzC,OAAO,SAASA,CAAO,CAAC,EACxBA,EAEEc,EAAc,IAAIC,EAAU,CAChC,QAAS,CACP,UAAW3B,EACX,UAAWyB,CACb,EACA,QAAAd,CACF,CAAC,EACKiB,EAAY,KAAK,QAAQ,WAAW5B,CAAc,GAAG,SAAS,IACjEW,GAAYA,EAAQ,YAAY,CACnC,EAEA,GAAI,CAACiB,GAAa,CAACA,EAAU,SAASF,EAAY,SAAS,CAAC,EAC1D,MAAM,IAAI,MACR,qGACF,EAGF,IAAMZ,EAAc,IAAIC,EAAQ,CAC9B,UAAWf,EACX,UAAWyB,CACb,CAAC,EAED,MAAO,CACL,QAASA,EACT,QAAAd,EACA,YAAaG,EAAY,SAAS,CACpC,CACF,CACF,EAEOe,EAAQ5B",
|
|
6
|
+
"names": ["cleanEvmError", "toHexQuantity", "AccountId", "ChainId", "NAMESPACE_NAME", "EVMSigner", "_EVMSigner", "__name", "client", "getSession", "session", "evmTx", "tx", "toHexQuantity", "msg", "address", "chainId", "requestedFor", "caipChainId", "ChainId", "params", "utf8ToHex", "signature", "error", "cleanEvmError", "transaction", "hash", "modifiedError", "context", "chainIdNumber", "caipAddress", "AccountId", "addresses", "evm_default"]
|
|
7
|
+
}
|
package/dist/mod.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../src/mod.ts"],"names":[],"mappings":"AAIA,YAAY,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAE/C,QAAA,MAAM,QAAQ,uHAC8C,CAAC;AAE7D,OAAO,EAAE,QAAQ,EAAE,CAAC"}
|
package/dist/mod.js
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{a as r,b as y,c as D,d as ee,e as te,f as ne,g as se,h as re,i as oe,k as E,l as H,m as S,n as ie}from"./chunk-GEAT645O.js";import{defineVersions as Kt}from"@hub3js/core/utils";import{ProviderBuilder as Ft}from"@hub3js/core";import{debug as At}from"@rango-dev/logging-core";import{error as F}from"@rango-dev/logging-core";import{ChainId as Je}from"caip";import{AccountId as L}from"caip";function ae(t){return t.includes(":")?new L(t).address:t}r(ae,"extractAddress");function T(t){return Object.values(t.namespaces).map(n=>n.accounts).flat().map(n=>{let{address:s,chainId:o}=new L(n);return{address:s,chainId:o.reference}})}r(T,"getAccountsFromSession");function ce(t){return Object.values(t.params.namespaces).map(n=>n.accounts).flat().map(n=>{let{address:s,chainId:o}=new L(n);return{accounts:[s],chainId:o.reference}})}r(ce,"getAccountsFromEvent");async function A(t,e){return t.core.storage.setItem(D,{defaultChainId:e?parseInt(e):""})}r(A,"persistCurrentChainId");async function I(t){try{let e=(await t.core.storage.getItem(D))?.defaultChainId;return e?String(e):void 0}catch{return}}r(I,"getPersistedChainId");function j(t,e){let s=e.find(o=>o.name===t)?.chainId;if(s)return String(parseInt(s))}r(j,"getChainIdByNetworkName");import{debug as ze}from"@rango-dev/logging-core";import{convertEvmBlockchainMetaToEvmChainInfo as qe,isEvmAddress as me}from"@rango-dev/wallets-shared";import{AccountId as le,ChainId as $e}from"caip";import{isEvmBlockchain as Ge}from"rango-types";function Ze(t){return t.namespaces.eip155?.accounts?.map(e=>new le(e).address)?.filter(e=>me(e))?.[0]}r(Ze,"getCurrentEvmAccountAddress");function pe(t,e,n){let s=j(t,n);if(s)return le.format({chainId:{namespace:"eip155",reference:s},address:e})}r(pe,"getEvmAccount");function C(t,e){let n=!1;return t.filter(({address:s,chainId:o})=>{if(!me(s)||e&&o!==e)return!1;if(!e){if(n)return!1;n=!0}return!0}).map(({address:s,chainId:o})=>({accounts:[s],chainId:o}))}r(C,"filterEvmAccounts");async function ue(t,e,n,s,o){let i=n.filter(Ge),c=qe(i)[s],m=n.find(h=>h.name===s)?.chainId,l=j(o,n),f=$e.format({namespace:"eip155",reference:String(l)});try{await t.request({topic:e.topic,request:{method:"wallet_switchEthereumChain",params:[{chainId:m}]},chainId:f})}catch(h){let{code:u,message:x}=h??{};if(u===4902||x?.includes(String(4902)))await t.request({topic:e.topic,request:{method:"wallet_addEthereumChain",params:[c]},chainId:f});else throw h}}r(ue,"switchOrAddEvmChain");async function de(t,e,n,s,o){let i=e.namespaces.eip155,a=Ze(e);if(!i||!a)return e;let c=i.accounts??[],p=[pe(n,a,o),pe(s,a,o)].filter(l=>!!l&&!c.includes(l));if(!p.length)return e;let m={...e,namespaces:{...e.namespaces,eip155:{...i,accounts:[...c,...new Set(p)]}}};try{await t.session.update(e.topic,{namespaces:m.namespaces})}catch(l){return ze(l instanceof Error?l:new Error(String(l))),e}return m}r(de,"updateSessionAccounts");function fe(t){let e=["trust","1inch"],n=t.peer?.metadata?.name;return e.some(s=>n?.toLowerCase()?.includes(s))}r(fe,"ignoreNamespaceMethods");async function b(t,e){let n=await I(t);if(n)return n;let s=T(e);return C(s)[0]?.chainId}r(b,"resolveActiveChainReference");async function he(t,e){let n=await b(t,e);if(!n)throw new Error("Unable to determine EVM chain id from WalletConnect session.");return S(n)}r(he,"getCurrentChainId");async function K(t){let{client:e,session:n,meta:s,requestedChainId:o,currentChainId:i}=t,a=E(o);if(!a){let u=new Error(`There is no match for ${o}`);throw F(u),u}let c=new Je({namespace:"eip155",reference:a}).toString(),p=H(o,s),m=H(i,s),l=n.namespaces.eip155,f=l?.chains||[],h=l?.methods||[],d=n;if(h.includes("wallet_switchEthereumChain")&&!fe(n)){if(!p||!m){let u=new Error(`Chain ${a} is not configured.`);throw F(u),u}d=await de(e,n,p,m,s),await ue(e,d,s,p,m)}else if(!f.includes(c)){let u=new Error(`Chain ${a} is not configured.`);throw F(u),u}return await A(e,a),d}r(K,"switchEvmNetwork");async function Qe(t,e){let n=t.getSession("evm");if(!n)throw new Error("WalletConnect session is not available.");let s=await t.getClient(),o=await b(s,n);if(o===e){await A(s,e);return}let i=o?S(o):S(e);t.cacheSession("evm",await K({client:s,session:n,meta:t.meta,requestedChainId:e,currentChainId:i}))}r(Qe,"switchToChainIfNeeded");async function ge(t,e){let n=e?E(e):void 0;t.getSession("evm")||await t.ensureSession({namespace:"evm",chainReference:n}),n&&await Qe(t,n);let s=t.getSession("evm");if(!s)throw new Error("WalletConnect session is not available.");return s}r(ge,"ensureConnectedToChain");import{debug as ht}from"@rango-dev/logging-core";import{timeout as gt}from"@rango-dev/wallets-shared";import{createAppKit as Xe}from"@reown/appkit/core";function Se(t){return{formatters:void 0,fees:void 0,serializers:void 0,...t}}r(Se,"defineChain");var M=Se({id:1,caipNetworkId:"eip155:1",chainNamespace:"eip155",name:"Ethereum",nativeCurrency:{name:"Ether",symbol:"ETH",decimals:18},rpcUrls:{default:{http:["https://eth.merkle.io"]}},blockExplorers:{default:{name:"Etherscan",url:"https://etherscan.io",apiUrl:"https://api.etherscan.io/api"}},contracts:{ensUniversalResolver:{address:"0xeeeeeeee14d718c2b47d9923deab1335e144eeee",blockCreated:23085558},multicall3:{address:"0xca11bde05977b3631167028862be2a173976ca11",blockCreated:14353601}}}),V=Se({id:"000000000019d6689c085ae165831e93",caipNetworkId:"bip122:000000000019d6689c085ae165831e93",chainNamespace:"bip122",name:"Bitcoin",nativeCurrency:{name:"Bitcoin",symbol:"BTC",decimals:8},rpcUrls:{default:{http:["https://rpc.walletconnect.org/v1"]}}});var Ye=999999999,et=[M,V],tt={evm:M,utxo:V};async function Ce(t,e){await t.ready(),await t.switchNetwork(tt[e])}r(Ce,"prepareModalForNamespace");function ye({projectId:t,universalProvider:e,themeMode:n="light",zIndex:s=Ye}){return Xe({projectId:t,networks:et,universalProvider:e,enableReconnect:!1,defaultNetwork:M,defaultAccountTypes:{bip122:"payment"},manualWCControl:!0,allowUnsupportedChain:!0,themeMode:n,themeVariables:{"--apkt-z-index":s}})}r(ye,"createAppKitModal");import{debug as nt}from"@rango-dev/logging-core";import{CAIP_BITCOIN_CHAIN_ID as st}from"@rango-dev/wallets-core/namespaces/utxo";import{AccountId as z}from"caip";function rt(t){return t.namespaces.bip122?.accounts??[]}r(rt,"getBip122AccountsFromSession");function N(t){return rt(t).map(e=>({address:new z(e).address}))}r(N,"filterBip122Accounts");function ot(t){if(!t?.length)return;let e=t[0];if(typeof e=="string")return e;let n=t;return n.find(s=>s.intention==="payment")?.address??n[0]?.address}r(ot,"pickPaymentAddress");function it(t,e){let n=t.namespaces.bip122;if(!n)return t;let s=new z({chainId:{namespace:"bip122",reference:st},address:e}).toString(),o=n.accounts??[];return o.some(a=>new z(a).address.toLowerCase()===e.toLowerCase())?t:{...t,namespaces:{...t.namespaces,bip122:{...n,accounts:[...o,s]}}}}r(it,"patchBip122SessionAccount");var at=15e3;async function ve(t,e){if(N(e).length)return e;let s=t.session.get(e.topic)??e;if(N(s).length)return s;let{address:i,session:a}=await pt(t,s),c=it(a,i);return await ct(t,c),c}r(ve,"resolveBip122Session");async function ct(t,e){try{await t.session.update(e.topic,{namespaces:e.namespaces})}catch(n){nt(n instanceof Error?n:new Error(String(n)))}}r(ct,"persistSessionNamespaces");async function pt(t,e,n=at){return await new Promise((s,o)=>{let i=e.topic,a=!1,c=r((d,u)=>{a||(a=!0,l(),s({address:d,session:u}))},"finish"),p=r(d=>{a||(a=!0,l(),o(d))},"fail"),m=setTimeout(()=>{p(new Error("Timed out waiting for Bitcoin account from wallet. Please try reconnecting."))},n),l=r(()=>{clearTimeout(m),t.off("session_event",f),t.off("session_update",h)},"cleanup"),f=r(d=>{if(d.topic!==i||d.params.event.name!=="bip122_addressesChanged")return;let u=ot(d.params.event.data);u&&c(u,t.session.get(i)??e)},"onEvent"),h=r(d=>{if(d.topic!==i)return;let u=t.session.get(i)??e,x=N(u);x.length&&c(x[0].address,u)},"onUpdate");t.on("session_event",f),t.on("session_update",h)})}r(pt,"waitForBip122PaymentAddress");function mt(t){return y[t]}r(mt,"getCaipNamespace");function q(t,e){let n=mt(e);return t.session.getAll().find(s=>{let o=s.namespaces[n];return(o?.accounts?.length??0)>0?!0:e==="utxo"&&(o?.chains?.length??0)>0})}r(q,"findSessionByNamespace");function $(t){let e=r(s=>(t.namespaces[y[s]]?.accounts?.length??0)>0,"hasAccounts"),n=r(s=>(t.namespaces[y[s]]?.chains?.length??0)>0,"hasChains");if(e("evm"))return"evm";if(e("utxo")||n("utxo"))return"utxo";if(n("evm"))return"evm"}r($,"getSessionNamespace");import{CAIP_BITCOIN_CHAIN_ID as lt}from"@rango-dev/wallets-core/namespaces/utxo";import{ChainId as ut}from"caip";var dt={evm:{methods:te,events:ee,resolveChains:(t,e)=>e?[{namespace:"eip155",reference:e}]:t.length>0?t:[{namespace:"eip155",reference:"1"}]},utxo:{methods:se,events:ne,resolveChains:()=>[{namespace:"bip122",reference:lt}]}};function Ee(t,e,n){let s={};for(let o of e){let i=dt[o];s[y[o]]={methods:i.methods,events:i.events,chains:i.resolveChains(t,n).map(a=>new ut(a).toString())}}return Object.keys(s).length>0?s:void 0}r(Ee,"generateOptionalNamespace");import{debug as G}from"@rango-dev/logging-core";import{getSdkError as Z}from"@walletconnect/utils";function Ae(t){return(t instanceof Error?t.message:String(t)).includes("No matching key")}r(Ae,"isNoMatchingKeyError");function _(t,e){try{return!!t.session.get(e)}catch{return!1}}r(_,"hasActiveSession");function J(t,e){return t.pairing.getAll().some(n=>n.topic===e)}r(J,"hasActivePairing");async function w(t,e){let n=t.session.getAll(),s=t.pairing.getAll();n.forEach(o=>{if(o.topic===e||o.pairingTopic===e){let i=o.pairingTopic===e?o.pairingTopic:o.topic;t.core.expirer.set(i,0)}}),s.forEach(o=>{o.topic===e&&t.core.expirer.set(e,0)})}r(w,"expireWalletConnectTopic");async function v(t,e){let n=$(e),s=e.pairingTopic;if(_(t,e.topic))try{await t.disconnect({topic:e.topic,reason:Z("USER_DISCONNECTED")})}catch(i){G(i instanceof Error?i:new Error(String(i))),Ae(i)&&await w(t,e.topic)}else await w(t,e.topic);if(!t.session.getAll().filter(i=>i.pairingTopic===s).length&&s)if(J(t,s))try{await t.disconnect({topic:s,reason:Z("USER_DISCONNECTED")})}catch(i){G(i instanceof Error?i:new Error(String(i))),Ae(i)&&await w(t,s)}else await w(t,s);n==="evm"&&A(t,void 0)}r(v,"removeSessionRecord");async function we(t){let e=new Set(t.pairing.getAll().map(n=>n.topic));for(let n of[...t.session.getAll()]){let s=!!n.pairingTopic&&!e.has(n.pairingTopic),o=!_(t,n.topic);(s||o)&&await v(t,n)}}r(we,"purgeOrphanedSessions");async function Te(t){let e=new Set(t.session.getAll().map(n=>n.pairingTopic).filter(n=>!!n));for(let n of[...t.pairing.getAll()])if(!e.has(n.topic))try{await t.disconnect({topic:n.topic,reason:Z("USER_DISCONNECTED")})}catch(s){G(s instanceof Error?s:new Error(String(s))),await w(t,n.topic)}}r(Te,"purgeOrphanedPairings");async function Ie(t,e){for(let n of t.session.getAll()){if($(n)!==e)continue;let s=n.namespaces.bip122;s&&(s.chains?.length??0)>0&&(s.accounts?.length??0)===0&&await v(t,n)}}r(Ie,"cleanupStaleSessionsForNamespace");async function Q(t,e,n={}){let s=await Ct(t,e);if(s&&!(e==="utxo"&&N(s).length===0)&&!(n.validateAccounts&&!await St(t,e,s)))return s}r(Q,"restoreWalletConnectSession");async function St(t,e,n){if(e==="utxo")return N(n).length>0;let s=T(n),o=await I(t);return C(s,o).length>0}r(St,"hasNamespaceAccounts");async function Ct(t,e){let n=q(t,e);if(n?.topic){if(!_(t,n.topic)){await v(t,n);return}if(n.pairingTopic&&!J(t,n.pairingTopic)){await v(t,n);return}try{await gt(t.ping({topic:n.topic}),1e4)}catch(s){ht(s instanceof Error?s:new Error(String(s))),await v(t,n);return}return q(t,e)??n}}r(Ct,"restoreNamespaceSession");async function Ne(t,e){await we(t),await Ie(t,e),await Te(t)}r(Ne,"prepareWalletConnectNamespace");async function Pe(t,e,n){let{chains:s,namespace:o,chainReference:i}=n,a=await Q(t,o);if(a)return a;let c=Ee(s,[o],i),p=await yt(t,e,{optionalNamespaces:c??{}},{envs:n.envs,namespace:o});return o==="utxo"?ve(t,p):p}r(Pe,"connectWalletConnectSession");async function yt(t,e,n,s){let{optionalNamespaces:o,pairingTopic:i}=n;try{let{uri:a,approval:c}=await t.connect({optionalNamespaces:o,pairingTopic:i}),p;if(a){let l=s.envs.DISABLE_MODAL_AND_OPEN_LINK;if(l){let f=`${l}/wc?uri=${encodeURIComponent(a)}`;window.open(f,"_blank","noreferrer noopener")}else{await Ce(e,s.namespace);let f={uri:a,namespace:y[s.namespace]};await e.open(f),p=new Promise((h,d)=>{e.subscribeState(u=>{u.open||d(new Error("Modal has been closed."))})})}}let m=c();return p?await Promise.race([m,p]):await m}finally{e.close()}}r(yt,"createSession");import{debug as vt}from"@rango-dev/logging-core";async function X(t,e,n,s,o){try{let i=await Q(t,e,s);return i?(n.set(e,i),i):null}catch(i){return vt(i instanceof Error?i:new Error(String(i))),n.get(e)&&await o?.(e),null}}r(X,"restoreAndCacheSession");var W=class{static{r(this,"ModalCache")}#e=null;getModal(e){return this.#e||(this.#e=ye(e)),this.#e}};import Et from"@walletconnect/universal-provider";async function xe(t){return Et.init({relayUrl:oe,projectId:t,metadata:re})}r(xe,"createUniversalProvider");function be(){let t=new Map;return{get:e=>t.get(e)??null,set:(e,n)=>void t.set(e,n),clear:e=>void t.delete(e),clearTopic:e=>{for(let[n,s]of t)s.topic===e&&t.delete(n)},clearAll:()=>t.clear()}}r(be,"createSessionCache");var k=class{static{r(this,"TaskQueue")}#e=Promise.resolve();async run(e){let n=this.#e,s;this.#e=new Promise(o=>{s=o}),await n;try{return await e()}finally{s()}}};var R=class{static{r(this,"WalletConnectAdapter")}#e;#a;#c;#p;#n;#r=null;#s=null;#t=be();#m=new W;#o=new k;constructor(e){this.#e=e.projectId,this.#n=e.meta,this.#a=e.disableModalLink,this.#c=e.themeMode,this.#p=e.modalZIndex}async getUniversalProvider(){return this.#s||(this.#s=xe(this.#e).then(e=>(this.#r=e,e)).catch(e=>{throw this.#s=null,e})),this.#s}async getClient(){return(await this.getUniversalProvider()).client}getSession(e){return this.#t.get(e)}cacheSession(e,n){this.#t.set(e,n)}clearSession(e){this.#t.clear(e)}clearAllSessions(){this.#t.clearAll()}async tryRestoreEagerSession(e){return this.#o.run(async()=>{let n=await this.getClient();return!!await X(n,e,this.#t,{validateAccounts:!0},async s=>this.#i(s))})}async ensureSession(e){return this.#o.run(async()=>this.#l(e))}async disconnectSession(e){return this.#o.run(async()=>this.#i(e))}async resolveActiveChainReference(){let e=this.getSession("evm");if(e)return b(await this.getClient(),e)}async getCurrentChainId(){let e=this.getSession("evm");if(!e)throw new Error("Unable to determine EVM chain id from WalletConnect session.");return he(await this.getClient(),e)}async ensureConnectedToChain(e){return ge(this.#u(),e)}async switchEvmNetwork(e,n){let s=this.getSession("evm");if(!s)throw new Error("WalletConnect session is not available.");this.cacheSession("evm",await K({client:await this.getClient(),session:s,meta:this.#n,requestedChainId:e,currentChainId:n}))}async#l(e){let{namespace:n,chainReference:s}=e,o=await this.getClient(),i=await X(o,n,this.#t,void 0,async p=>this.#i(p));if(i)return i;await Ne(o,n);let a=await this.getUniversalProvider();await a.cleanupPendingPairings().catch(()=>{});let c=await Pe(o,this.#m.getModal({projectId:this.#e,universalProvider:a,themeMode:this.#c,zIndex:this.#p}),{chains:ie(this.#n),envs:{WC_PROJECT_ID:this.#e,DISABLE_MODAL_AND_OPEN_LINK:this.#a},namespace:n,chainReference:s});return this.#t.set(n,c),c}async#i(e){let n=this.getSession(e);this.#r?.client&&n&&await v(this.#r.client,n).catch(s=>At(s)),this.clearSession(e),n&&this.#t.clearTopic(n.topic)}#u(){return{meta:this.#n,getSession:e=>this.getSession(e),cacheSession:(e,n)=>this.cacheSession(e,n),getClient:async()=>this.getClient(),ensureSession:async e=>this.ensureSession(e)}}};var Me,g=r(()=>Me,"getAdapter"),_e=r(t=>{Me=t},"setAdapter");import{isEvmNamespace as Nt}from"@hub3js/evm";import{dynamicImportWithRefinedError as wt}from"@rango-dev/wallets-shared";import{DefaultSignerFactory as Tt,TransactionType as It}from"rango-types";async function Y(){let t=g();if(!t)throw new Error("WalletConnect provider has not been initialized.");let e=await t.getClient(),n=new Tt,s=(await wt(async()=>await import("./evm-3KFL5N77.js"))).default;return n.registerSigner(It.EVM,new s(e,()=>t.getSession("evm"))),n}r(Y,"getSigners");var U="wallet-connect-2",We={name:"WalletConnect",icon:"https://raw.githubusercontent.com/rango-exchange/assets/main/wallets/walletconnect/icon.svg",extensions:{homepage:"https://walletconnect.com/"},properties:[{name:"namespaces",value:{selection:"single",data:[{label:"EVM",value:"EVM",id:"ETH",isChainSupported:Nt}]}},{name:"signers",value:{getSigners:async()=>Y()}},{name:"details",value:{mobileWallet:!0,showOnMobile:!0}}]};import{NamespaceBuilder as Mt}from"@hub3js/core";import{actions as _t,builders as O,utils as Wt}from"@hub3js/evm";import*as De from"@hub3js/std/builders";import{standardizeAndThrowError as kt}from"@hub3js/std/operators";import{utils as Re}from"@hub3js/evm";import{ChainId as xt}from"caip";import{debug as Pt}from"@rango-dev/logging-core";function ke(t){Pt(t instanceof Error?t:new Error(String(t)))}r(ke,"logHandlerError");function B(t,e,n){let s=null;return[async o=>{let i=g(),a=await i.getClient();s&&a.off(e,s),s=r(c=>{let p=i.getSession(t);if(!(!p||c.topic!==p.topic))try{let m=n({args:c,session:p,adapter:i,context:o});m instanceof Promise&&m.catch(ke)}catch(m){ke(m)}},"handler"),a.on(e,s)},(o,i)=>{let a=s;return a&&(s=null,g().getClient().then(c=>c.off(e,a))),i}]}r(B,"createSessionSubscriber");function Ue(){return B("evm","session_update",async({args:t,session:e,adapter:n,context:s})=>{t.params.namespaces.eip155&&n.cacheSession("evm",{...e,namespaces:t.params.namespaces});let o=ce(t);if(!o.length)return;let i=o.map(d=>({address:d.accounts[0],chainId:d.chainId})),[a,c]=s.state(),p=a().network,m=await I(await n.getClient()),l=E(p??void 0)??m,f=C(i,l);if(f.length||(f=C(i)),!f.length)return;let h=S(f[0].chainId);c("accounts",Re.formatAccountsToCAIP([f[0].accounts[0]],h)),c("network",h)})}r(Ue,"sessionUpdateSubscriber");function bt(t){return(Array.isArray(t)?t:[t]).filter(e=>typeof e=="string"&&!!e).map(ae)}r(bt,"eventAccounts");function Be(){return B("evm","session_event",({args:t,adapter:e,context:n})=>{let[,s]=n.state();if(t.params.event.name==="accountsChanged"){let o=bt(t.params.event.data);if(!o.length){n.action("disconnect");return}let i=S(xt.parse(t.params.chainId).reference);s("network",i),s("accounts",Re.formatAccountsToCAIP(o,i));return}if(t.params.event.name==="chainChanged"){let o=S(t.params.event.data);s("network",o),e.getClient().then(async i=>A(i,o))}})}r(Be,"sessionEventSubscriber");function Oe(){return B("evm","session_delete",({args:t,adapter:e,context:n})=>{e.clearSession("evm"),e.getClient().then(async s=>w(s,t.topic)),n.action("disconnect")})}r(Oe,"sessionDeleteSubscriber");var[Rt,He]=Ue(),[Ut,Le]=Be(),[Bt,je]=Oe(),Ot=O.connect().action(async function(t,e){let n=g(),s=e?E(e):void 0,o=await n.ensureConnectedToChain(e),i=s??await n.resolveActiveChainReference();if(!i)throw new Error("Unable to determine EVM chain id from WalletConnect session.");let a=T(o),c=C(a,i);if(!c.length)throw new Error("No EVM accounts found in WalletConnect session.");return{accounts:Wt.formatAccountsToCAIP(c.map(p=>p.accounts[0]),i),network:S(i)}}).before(Rt).before(Ut).before(Bt).or(He).or(Le).or(je).or((t,e)=>(g().disconnectSession("evm"),e)).or(kt).build(),Dt=O.canEagerConnect().action(async()=>g().tryRestoreEagerSession("evm")).build(),Ht=O.canSwitchNetwork().action(_t.canSwitchNetwork()).build(),Lt=De.disconnect().before(async()=>{await g().disconnectSession("evm")}).after(He).after(Le).after(je).build(),jt=O.getChainId().action(async()=>g().getCurrentChainId()).build(),Fe=new Mt("EVM",U).action(Ot).action(Dt).action(Ht).action(Lt).action(jt).build();var Ke=r(()=>new Ft(U).init(function(t,e){let[,n]=t.state();e.WC_PROJECT_ID&&(_e(new R({projectId:e.WC_PROJECT_ID,meta:e.meta||[],disableModalLink:e.DISABLE_MODAL_AND_OPEN_LINK,themeMode:e.themeMode,modalZIndex:e.modalZIndex})),n("installed",!0),console.debug("[wallet-connect-2] provider initialized.",t))}).config("metadata",We).add("evm",Fe).build(),"buildProvider");var yr=r(()=>Kt().version("1.0.0",Ke()).build(),"versions");export{yr as versions};
|
|
2
|
+
//# sourceMappingURL=mod.js.map
|