@etherplay/connect 0.0.34 → 0.0.36

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,14 +0,0 @@
1
- import type { EIP1193WindowWalletProvider, Methods } from 'eip-1193';
2
- import { CurriedRPC } from 'remote-procedure-call';
3
- export declare function createProvider(params: {
4
- endpoint: string;
5
- chainId: string;
6
- prioritizeWalletProvider?: boolean;
7
- requestsPerSecond?: number;
8
- }): CurriedRPC<Methods> & {
9
- setWalletProvider: (walletProvider: EIP1193WindowWalletProvider | undefined) => void;
10
- setWalletStatus: (newStatus: 'connected' | 'locked' | 'disconnected') => void;
11
- } & {
12
- chainId: string;
13
- };
14
- //# sourceMappingURL=provider.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"provider.d.ts","sourceRoot":"","sources":["../src/provider.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAwB,2BAA2B,EAAE,OAAO,EAAC,MAAM,UAAU,CAAC;AAC1F,OAAO,EAAuB,UAAU,EAAC,MAAM,uBAAuB,CAAC;AAgBvE,wBAAgB,cAAc,CAAC,MAAM,EAAE;IACtC,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,MAAM,CAAC;IAChB,wBAAwB,CAAC,EAAE,OAAO,CAAC;IACnC,iBAAiB,CAAC,EAAE,MAAM,CAAC;CAC3B,GAAG,UAAU,CAAC,OAAO,CAAC,GAAG;IACzB,iBAAiB,EAAE,CAAC,cAAc,EAAE,2BAA2B,GAAG,SAAS,KAAK,IAAI,CAAC;IACrF,eAAe,EAAE,CAAC,SAAS,EAAE,WAAW,GAAG,QAAQ,GAAG,cAAc,KAAK,IAAI,CAAC;CAC9E,GAAG;IACH,OAAO,EAAE,MAAM,CAAC;CAChB,CAwEA"}
package/dist/provider.js DELETED
@@ -1,77 +0,0 @@
1
- import { createCurriedJSONRPC } from 'remote-procedure-call';
2
- import { withTimeout } from './utils.js';
3
- const signerMethods = [
4
- 'eth_accounts',
5
- 'eth_sign',
6
- 'eth_signTransaction',
7
- 'personal_sign',
8
- 'eth_signTypedData_v4',
9
- 'eth_signTypedData',
10
- ];
11
- const connectedAccountMethods = ['eth_sendTransaction'];
12
- const walletOnlyMethods = ['eth_requestAccounts', 'wallet_switchEthereumChain', 'wallet_addEthereumChain'];
13
- export function createProvider(params) {
14
- const { endpoint, chainId, prioritizeWalletProvider, requestsPerSecond } = params;
15
- const jsonRPC = createCurriedJSONRPC(endpoint);
16
- let walletProvider;
17
- let status = 'disconnected';
18
- function setWalletProvider(newWalletProvider) {
19
- walletProvider = newWalletProvider;
20
- }
21
- function setWalletStatus(newStatus) {
22
- status = newStatus;
23
- }
24
- const provider = {
25
- async request(req) {
26
- const signingMethod = signerMethods.includes(req.method) ||
27
- connectedAccountMethods.includes(req.method) ||
28
- walletOnlyMethods.includes(req.method) ||
29
- req.method.indexOf('sign') != -1;
30
- if (walletProvider) {
31
- if (prioritizeWalletProvider || signingMethod) {
32
- if (signingMethod) {
33
- if (status !== 'connected') {
34
- return Promise.reject({ message: 'wallet provider is not connected', code: 4001 });
35
- }
36
- }
37
- let currentChainIdAsHex;
38
- try {
39
- currentChainIdAsHex = await withTimeout(walletProvider.request({
40
- method: 'eth_chainId',
41
- }));
42
- }
43
- catch (err) {
44
- if (signingMethod) {
45
- return Promise.reject(err);
46
- }
47
- else {
48
- // we fallback on jsonRPc if error while getting chain and not a signing method
49
- return jsonRPC.request(req);
50
- }
51
- }
52
- const currentChainId = Number(currentChainIdAsHex).toString();
53
- if (chainId !== currentChainId) {
54
- if (signingMethod) {
55
- return Promise.reject({
56
- message: `wallet provider is connected to a different chain, expected ${chainId} but got ${currentChainId}`,
57
- code: 4001,
58
- });
59
- }
60
- else {
61
- // we fallback on jsonRPc if invalid chain and not a signing method
62
- return jsonRPC.request(req);
63
- }
64
- }
65
- return walletProvider.request(req);
66
- }
67
- }
68
- if (signingMethod) {
69
- return Promise.reject(new Error('wallet provider is not connected'));
70
- }
71
- return jsonRPC.request(req);
72
- },
73
- };
74
- const curriedRPC = createCurriedJSONRPC(provider, { requestsPerSecond });
75
- return { ...curriedRPC, setWalletProvider, setWalletStatus, chainId };
76
- }
77
- //# sourceMappingURL=provider.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"provider.js","sourceRoot":"","sources":["../src/provider.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,oBAAoB,EAAa,MAAM,uBAAuB,CAAC;AACvE,OAAO,EAAC,WAAW,EAAC,MAAM,YAAY,CAAC;AAEvC,MAAM,aAAa,GAAG;IACrB,cAAc;IACd,UAAU;IACV,qBAAqB;IACrB,eAAe;IACf,sBAAsB;IACtB,mBAAmB;CACnB,CAAC;AAEF,MAAM,uBAAuB,GAAG,CAAC,qBAAqB,CAAC,CAAC;AAExD,MAAM,iBAAiB,GAAG,CAAC,qBAAqB,EAAE,4BAA4B,EAAE,yBAAyB,CAAC,CAAC;AAE3G,MAAM,UAAU,cAAc,CAAC,MAK9B;IAMA,MAAM,EAAC,QAAQ,EAAE,OAAO,EAAE,wBAAwB,EAAE,iBAAiB,EAAC,GAAG,MAAM,CAAC;IAChF,MAAM,OAAO,GAAG,oBAAoB,CAAC,QAAQ,CAAC,CAAC;IAE/C,IAAI,cAAuD,CAAC;IAC5D,IAAI,MAAM,GAA4C,cAAc,CAAC;IAErE,SAAS,iBAAiB,CAAC,iBAA0D;QACpF,cAAc,GAAG,iBAAiB,CAAC;IACpC,CAAC;IACD,SAAS,eAAe,CAAC,SAAkD;QAC1E,MAAM,GAAG,SAAS,CAAC;IACpB,CAAC;IAED,MAAM,QAAQ,GAAG;QAChB,KAAK,CAAC,OAAO,CAAC,GAAqC;YAClD,MAAM,aAAa,GAClB,aAAa,CAAC,QAAQ,CAAC,GAAG,CAAC,MAAM,CAAC;gBAClC,uBAAuB,CAAC,QAAQ,CAAC,GAAG,CAAC,MAAM,CAAC;gBAC5C,iBAAiB,CAAC,QAAQ,CAAC,GAAG,CAAC,MAAM,CAAC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