@cowprotocol/iframe-transport 2.0.7 → 2.0.9
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 +23 -0
- package/package.json +25 -3
- package/src/IframeTransport.d.ts +11 -0
- package/src/IframeTransport.js +42 -0
- package/src/IframeTransport.js.map +1 -0
- package/src/iframeRpcProvider/IframeRpcProviderBridge.d.ts +45 -0
- package/src/iframeRpcProvider/IframeRpcProviderBridge.js +143 -0
- package/src/iframeRpcProvider/IframeRpcProviderBridge.js.map +1 -0
- package/src/iframeRpcProvider/WidgetEthereumProvider.d.ts +134 -0
- package/src/iframeRpcProvider/WidgetEthereumProvider.js +300 -0
- package/src/iframeRpcProvider/WidgetEthereumProvider.js.map +1 -0
- package/src/iframeRpcProvider/iframeRpcProviderEvents.d.ts +31 -0
- package/src/iframeRpcProvider/iframeRpcProviderEvents.js +11 -0
- package/src/iframeRpcProvider/iframeRpcProviderEvents.js.map +1 -0
- package/src/iframeRpcProvider/utils.d.ts +4 -0
- package/src/iframeRpcProvider/utils.js +11 -0
- package/src/iframeRpcProvider/utils.js.map +1 -0
- package/src/index.d.ts +5 -0
- package/src/index.js +6 -0
- package/src/index.js.map +1 -0
- package/src/types.d.ts +59 -0
- package/src/types.js +2 -0
- package/src/types.js.map +1 -0
- package/.babelrc +0 -20
- package/jest.config.ts +0 -11
- package/project.json +0 -42
- package/src/IframeTransport.ts +0 -73
- package/src/iframeRpcProvider/IframeRpcProviderBridge.ts +0 -192
- package/src/iframeRpcProvider/WidgetEthereumProvider.ts +0 -489
- package/src/iframeRpcProvider/iframeRpcProviderEvents.ts +0 -40
- package/src/iframeRpcProvider/utils.ts +0 -18
- package/src/index.ts +0 -5
- package/src/types.ts +0 -75
- package/tsconfig.json +0 -21
- package/tsconfig.lib.json +0 -10
- package/tsconfig.spec.json +0 -20
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,28 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [2.0.9](https://github.com/cowprotocol/cowswap/compare/iframe-transport-v2.0.8...iframe-transport-v2.0.9) (2026-03-18)
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
### 🐛 Bug Fixes
|
|
7
|
+
|
|
8
|
+
* update libs publising and bundling ([#7173](https://github.com/cowprotocol/cowswap/issues/7173)) ([e3bc5f1](https://github.com/cowprotocol/cowswap/commit/e3bc5f179124c11590a992789db43d912f8ee4a6))
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
### Dependencies
|
|
12
|
+
|
|
13
|
+
* The following workspace dependencies were updated
|
|
14
|
+
* dependencies
|
|
15
|
+
* @cowprotocol/types bumped to 4.0.1
|
|
16
|
+
|
|
17
|
+
## [2.0.8](https://github.com/cowprotocol/cowswap/compare/iframe-transport-v2.0.7...iframe-transport-v2.0.8) (2026-03-11)
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
### Dependencies
|
|
21
|
+
|
|
22
|
+
* The following workspace dependencies were updated
|
|
23
|
+
* dependencies
|
|
24
|
+
* @cowprotocol/types bumped to 4.0.0
|
|
25
|
+
|
|
3
26
|
## [2.0.7](https://github.com/cowprotocol/cowswap/compare/iframe-transport-v2.0.6...iframe-transport-v2.0.7) (2026-03-10)
|
|
4
27
|
|
|
5
28
|
|
package/package.json
CHANGED
|
@@ -1,16 +1,38 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cowprotocol/iframe-transport",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.9",
|
|
4
4
|
"description": "CoW Swap iframe-transport",
|
|
5
|
+
"repository": {
|
|
6
|
+
"type": "git",
|
|
7
|
+
"url": "https://github.com/cowprotocol/cowswap.git",
|
|
8
|
+
"directory": "libs/iframe-transport"
|
|
9
|
+
},
|
|
5
10
|
"type": "commonjs",
|
|
6
|
-
"main": "./src/index.
|
|
11
|
+
"main": "./src/index.js",
|
|
7
12
|
"types": "./src/index.d.ts",
|
|
8
13
|
"license": "ISC",
|
|
9
14
|
"publishConfig": {
|
|
10
15
|
"access": "public"
|
|
11
16
|
},
|
|
12
17
|
"dependencies": {
|
|
18
|
+
"@cowprotocol/cow-sdk": "8.0.0",
|
|
19
|
+
"@cowprotocol/sdk-bridging": "3.0.0",
|
|
20
|
+
"@cowprotocol/types": "^4.0.1",
|
|
21
|
+
"@uniswap/sdk-core": "3.2.6",
|
|
22
|
+
"@web3-react/types": "8.2.3",
|
|
13
23
|
"eventemitter3": "^4.0.0",
|
|
14
|
-
"
|
|
24
|
+
"tslib": "1.14.1"
|
|
25
|
+
},
|
|
26
|
+
"resolutions": {
|
|
27
|
+
"@safe-global/safe-apps-sdk": "^9.1.0",
|
|
28
|
+
"@types/react": "19.1.3",
|
|
29
|
+
"@types/react-dom": "19.1.3",
|
|
30
|
+
"stylus": "npm:empty-npm-package@1.0.0",
|
|
31
|
+
"@babel/traverse": "^7.23.2",
|
|
32
|
+
"@walletconnect/ethereum-provider": "2.18.0",
|
|
33
|
+
"@walletconnect/sign-client": "2.18.0",
|
|
34
|
+
"@walletconnect/universal-provider": "2.18.0",
|
|
35
|
+
"@walletconnect/utils": "2.18.0",
|
|
36
|
+
"@walletconnect/types": "2.18.0"
|
|
15
37
|
}
|
|
16
38
|
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { WindowListener } from './types';
|
|
2
|
+
type AbstractRecord = Record<unknown, unknown>;
|
|
3
|
+
export declare class IframeTransport<MethodsEmitPayloadMap extends AbstractRecord> {
|
|
4
|
+
readonly key: string;
|
|
5
|
+
constructor(key: string);
|
|
6
|
+
postMessageToWindow<T extends keyof MethodsEmitPayloadMap>(contentWindow: Window, method: T, payload: MethodsEmitPayloadMap[T]): void;
|
|
7
|
+
listenToMessageFromWindow<T extends keyof MethodsEmitPayloadMap>(contentWindow: Window, method: T, callback: (payload: MethodsEmitPayloadMap[T]) => void): (payload: MessageEvent<unknown>) => void;
|
|
8
|
+
stopListeningToMessageFromWindow<T extends keyof MethodsEmitPayloadMap>(contentWindow: Window, _method: T, callback: (payload: MethodsEmitPayloadMap[T]) => void): void;
|
|
9
|
+
stopListeningWindowListener(contentWindow: Window, callback: WindowListener): void;
|
|
10
|
+
}
|
|
11
|
+
export {};
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
export class IframeTransport {
|
|
2
|
+
key;
|
|
3
|
+
constructor(key) {
|
|
4
|
+
this.key = key;
|
|
5
|
+
}
|
|
6
|
+
postMessageToWindow(contentWindow, method, payload) {
|
|
7
|
+
const data = typeof payload === 'object' ? payload : {};
|
|
8
|
+
const postPayload = {
|
|
9
|
+
key: this.key,
|
|
10
|
+
method,
|
|
11
|
+
...data,
|
|
12
|
+
};
|
|
13
|
+
contentWindow.postMessage(postPayload, '*');
|
|
14
|
+
}
|
|
15
|
+
listenToMessageFromWindow(contentWindow, method, callback) {
|
|
16
|
+
const listener = (event) => {
|
|
17
|
+
if (!isEventData(event.data) || event.data.key !== this.key || event.data.method !== method) {
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
callback(event.data);
|
|
21
|
+
};
|
|
22
|
+
contentWindow.addEventListener('message', listener);
|
|
23
|
+
return listener;
|
|
24
|
+
}
|
|
25
|
+
stopListeningToMessageFromWindow(contentWindow, _method, callback) {
|
|
26
|
+
// TODO: Replace any with proper type definitions
|
|
27
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
28
|
+
contentWindow.removeEventListener('message', callback);
|
|
29
|
+
}
|
|
30
|
+
stopListeningWindowListener(contentWindow, callback) {
|
|
31
|
+
contentWindow.removeEventListener('message', callback);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
function isEventData(obj) {
|
|
35
|
+
return (typeof obj === 'object' &&
|
|
36
|
+
obj !== null &&
|
|
37
|
+
'key' in obj &&
|
|
38
|
+
'method' in obj &&
|
|
39
|
+
typeof obj.key === 'string' &&
|
|
40
|
+
typeof obj.method === 'string');
|
|
41
|
+
}
|
|
42
|
+
//# sourceMappingURL=IframeTransport.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"IframeTransport.js","sourceRoot":"","sources":["../../../../libs/iframe-transport/src/IframeTransport.ts"],"names":[],"mappings":"AAMA,MAAM,OAAO,eAAe;IACE;IAA5B,YAA4B,GAAW;QAAX,QAAG,GAAH,GAAG,CAAQ;IAAG,CAAC;IAE3C,mBAAmB,CACjB,aAAqB,EACrB,MAAS,EACT,OAAiC;QAEjC,MAAM,IAAI,GAAG,OAAO,OAAO,KAAK,QAAQ,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,CAAA;QACvD,MAAM,WAAW,GAAG;YAClB,GAAG,EAAE,IAAI,CAAC,GAAG;YACb,MAAM;YACN,GAAG,IAAI;SACR,CAAA;QACD,aAAa,CAAC,WAAW,CACvB,WAAW,EACX,GAAG,CACJ,CAAA;IACH,CAAC;IAED,yBAAyB,CACvB,aAAqB,EACrB,MAAS,EACT,QAAqD;QAErD,MAAM,QAAQ,GAAG,CAAC,KAA4B,EAAQ,EAAE;YACtD,IAAI,CAAC,WAAW,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,KAAK,CAAC,IAAI,CAAC,GAAG,KAAK,IAAI,CAAC,GAAG,IAAI,KAAK,CAAC,IAAI,CAAC,MAAM,KAAK,MAAM,EAAE,CAAC;gBAC5F,OAAM;YACR,CAAC;YAED,QAAQ,CAAC,KAAK,CAAC,IAAgC,CAAC,CAAA;QAClD,CAAC,CAAA;QACD,aAAa,CAAC,gBAAgB,CAAC,SAAS,EAAE,QAAQ,CAAC,CAAA;QAEnD,OAAO,QAAQ,CAAA;IACjB,CAAC;IAED,gCAAgC,CAC9B,aAAqB,EACrB,OAAU,EACV,QAAqD;QAErD,iDAAiD;QACjD,8DAA8D;QAC9D,aAAa,CAAC,mBAAmB,CAAC,SAAS,EAAE,QAAe,CAAC,CAAA;IAC/D,CAAC;IAED,2BAA2B,CAAC,aAAqB,EAAE,QAAwB;QACzE,aAAa,CAAC,mBAAmB,CAAC,SAAS,EAAE,QAAQ,CAAC,CAAA;IACxD,CAAC;CACF;AAOD,SAAS,WAAW,CAAC,GAAY;IAC/B,OAAO,CACL,OAAO,GAAG,KAAK,QAAQ;QACvB,GAAG,KAAK,IAAI;QACZ,KAAK,IAAI,GAAG;QACZ,QAAQ,IAAI,GAAG;QACf,OAAO,GAAG,CAAC,GAAG,KAAK,QAAQ;QAC3B,OAAO,GAAG,CAAC,MAAM,KAAK,QAAQ,CAC/B,CAAA;AACH,CAAC"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import type { EthereumProvider, JsonRpcRequestMessage } from '../types';
|
|
2
|
+
/**
|
|
3
|
+
* Handles JSON-RPC request coming from an iFrame by delegating to a given Ethereum provider.
|
|
4
|
+
* The result will be passed back to the iFrame.
|
|
5
|
+
*
|
|
6
|
+
* Additionally, it will forward some special events from the wallet, to the iFrame window, for example connect/disconnect/chainChanged
|
|
7
|
+
*/
|
|
8
|
+
export declare class IframeRpcProviderBridge {
|
|
9
|
+
private iframeWidow;
|
|
10
|
+
/**
|
|
11
|
+
* The Ethereum provider instance.
|
|
12
|
+
* When is null the JSON-RPC bridge is disconnected from the Ethereum provider.
|
|
13
|
+
* */
|
|
14
|
+
private ethereumProvider;
|
|
15
|
+
/** Stored JSON-RPC requests, to queue them when disconnected. */
|
|
16
|
+
private requestWaitingForConnection;
|
|
17
|
+
/**
|
|
18
|
+
* Creates an instance of IframeRpcProviderBridge.
|
|
19
|
+
* @param iframeWidow - The iFrame window that will post up general RPC messages and to which the IframeRpcProviderBridge will forward the RPC result.
|
|
20
|
+
* Also it will receive some special RPC events coming from the wallet, like connect/chainChanged,accountChanged
|
|
21
|
+
*/
|
|
22
|
+
constructor(iframeWidow: Window);
|
|
23
|
+
/**
|
|
24
|
+
* Disconnects the JSON-RPC bridge from the Ethereum provider.
|
|
25
|
+
*/
|
|
26
|
+
disconnect(): void;
|
|
27
|
+
/**
|
|
28
|
+
* Handles the 'connect' event and sets up event listeners for Ethereum provider events.
|
|
29
|
+
* @param newProvider - The Ethereum provider to connect.
|
|
30
|
+
*/
|
|
31
|
+
onConnect(newProvider: EthereumProvider): void;
|
|
32
|
+
private processPendingRequests;
|
|
33
|
+
/**
|
|
34
|
+
* Processes a JSON-RPC request and sends appropriate response or error via the content window.
|
|
35
|
+
* @param request - The JSON-RPC request to be processed.
|
|
36
|
+
*/
|
|
37
|
+
processRpcRequest(request: JsonRpcRequestMessage): void;
|
|
38
|
+
private processRpcCallFromWindow;
|
|
39
|
+
private processProviderMetaInfoRequest;
|
|
40
|
+
private onProviderEvent;
|
|
41
|
+
/**
|
|
42
|
+
* Forward a JSON-RPC message to the content window.
|
|
43
|
+
*/
|
|
44
|
+
private forwardRpcResponseToIframe;
|
|
45
|
+
}
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
import { IframeRpcProviderEvents, iframeRpcProviderTransport, } from './iframeRpcProviderEvents';
|
|
2
|
+
import { getEip6963ProviderInfo, getProviderWcMetadata } from './utils';
|
|
3
|
+
const EVENTS_TO_FORWARD_TO_IFRAME = ['connect', 'disconnect', 'close', 'chainChanged', 'accountsChanged'];
|
|
4
|
+
const eip6963Providers = [];
|
|
5
|
+
if (typeof window !== 'undefined') {
|
|
6
|
+
window.addEventListener('eip6963:announceProvider', (event) => {
|
|
7
|
+
const providerEvent = event;
|
|
8
|
+
eip6963Providers.push(providerEvent.detail);
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Handles JSON-RPC request coming from an iFrame by delegating to a given Ethereum provider.
|
|
13
|
+
* The result will be passed back to the iFrame.
|
|
14
|
+
*
|
|
15
|
+
* Additionally, it will forward some special events from the wallet, to the iFrame window, for example connect/disconnect/chainChanged
|
|
16
|
+
*/
|
|
17
|
+
export class IframeRpcProviderBridge {
|
|
18
|
+
iframeWidow;
|
|
19
|
+
/**
|
|
20
|
+
* The Ethereum provider instance.
|
|
21
|
+
* When is null the JSON-RPC bridge is disconnected from the Ethereum provider.
|
|
22
|
+
* */
|
|
23
|
+
ethereumProvider = null;
|
|
24
|
+
/** Stored JSON-RPC requests, to queue them when disconnected. */
|
|
25
|
+
requestWaitingForConnection = {};
|
|
26
|
+
/**
|
|
27
|
+
* Creates an instance of IframeRpcProviderBridge.
|
|
28
|
+
* @param iframeWidow - The iFrame window that will post up general RPC messages and to which the IframeRpcProviderBridge will forward the RPC result.
|
|
29
|
+
* Also it will receive some special RPC events coming from the wallet, like connect/chainChanged,accountChanged
|
|
30
|
+
*/
|
|
31
|
+
constructor(iframeWidow) {
|
|
32
|
+
this.iframeWidow = iframeWidow;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Disconnects the JSON-RPC bridge from the Ethereum provider.
|
|
36
|
+
*/
|
|
37
|
+
disconnect() {
|
|
38
|
+
if (typeof window === 'undefined')
|
|
39
|
+
return;
|
|
40
|
+
// Disconnect provider
|
|
41
|
+
this.ethereumProvider = null;
|
|
42
|
+
iframeRpcProviderTransport.stopListeningToMessageFromWindow(window, IframeRpcProviderEvents.PROVIDER_RPC_REQUEST, this.processRpcCallFromWindow);
|
|
43
|
+
iframeRpcProviderTransport.stopListeningToMessageFromWindow(window, IframeRpcProviderEvents.REQUEST_PROVIDER_META_INFO, this.processProviderMetaInfoRequest);
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Handles the 'connect' event and sets up event listeners for Ethereum provider events.
|
|
47
|
+
* @param newProvider - The Ethereum provider to connect.
|
|
48
|
+
*/
|
|
49
|
+
onConnect(newProvider) {
|
|
50
|
+
if (typeof window === 'undefined')
|
|
51
|
+
return;
|
|
52
|
+
// Disconnect the previous provider
|
|
53
|
+
if (this.ethereumProvider) {
|
|
54
|
+
this.disconnect();
|
|
55
|
+
}
|
|
56
|
+
else {
|
|
57
|
+
// Listen for messages coming to the main window (from the iFrame window)
|
|
58
|
+
iframeRpcProviderTransport.listenToMessageFromWindow(window, IframeRpcProviderEvents.PROVIDER_RPC_REQUEST, this.processRpcCallFromWindow);
|
|
59
|
+
}
|
|
60
|
+
// Save the provider
|
|
61
|
+
this.ethereumProvider = newProvider;
|
|
62
|
+
// Process pending requests
|
|
63
|
+
this.processPendingRequests();
|
|
64
|
+
// Register in the provider, the events that needs to be forwarded to the iFrame window
|
|
65
|
+
EVENTS_TO_FORWARD_TO_IFRAME.forEach((event) => {
|
|
66
|
+
newProvider.on(event, (params) => this.onProviderEvent(event, params));
|
|
67
|
+
});
|
|
68
|
+
// Listen for provider meta info request
|
|
69
|
+
iframeRpcProviderTransport.listenToMessageFromWindow(window, IframeRpcProviderEvents.REQUEST_PROVIDER_META_INFO, this.processProviderMetaInfoRequest);
|
|
70
|
+
}
|
|
71
|
+
// TODO: Add proper return type annotation
|
|
72
|
+
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
|
|
73
|
+
processPendingRequests() {
|
|
74
|
+
// Process pending requests
|
|
75
|
+
Object.keys(this.requestWaitingForConnection).forEach((key) => {
|
|
76
|
+
this.processRpcRequest(this.requestWaitingForConnection[key]);
|
|
77
|
+
});
|
|
78
|
+
// Clear pending requests
|
|
79
|
+
this.requestWaitingForConnection = {};
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Processes a JSON-RPC request and sends appropriate response or error via the content window.
|
|
83
|
+
* @param request - The JSON-RPC request to be processed.
|
|
84
|
+
*/
|
|
85
|
+
// TODO: Add proper return type annotation
|
|
86
|
+
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
|
|
87
|
+
processRpcRequest(request) {
|
|
88
|
+
const { id, jsonrpc, method } = request;
|
|
89
|
+
if (!this.ethereumProvider || !id) {
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
const requestPromise =
|
|
93
|
+
// Keep the legacy "enable" method for backward compatibility
|
|
94
|
+
method === 'enable'
|
|
95
|
+
? this.ethereumProvider.request({ method: 'eth_requestAccounts', id })
|
|
96
|
+
: this.ethereumProvider.request({ ...request, id });
|
|
97
|
+
// Do request, and forward the result or error to the iFrame window
|
|
98
|
+
requestPromise
|
|
99
|
+
.then((result) => this.forwardRpcResponseToIframe({
|
|
100
|
+
rpcResponse: { jsonrpc, id, result },
|
|
101
|
+
}))
|
|
102
|
+
.catch((error) => this.forwardRpcResponseToIframe({
|
|
103
|
+
rpcResponse: { jsonrpc, id, error },
|
|
104
|
+
}));
|
|
105
|
+
}
|
|
106
|
+
processRpcCallFromWindow = ({ rpcRequest }) => {
|
|
107
|
+
// If disconnected, ignore the message. Also persist the request
|
|
108
|
+
if (!this.ethereumProvider) {
|
|
109
|
+
if (rpcRequest.id) {
|
|
110
|
+
this.requestWaitingForConnection[rpcRequest.id] = rpcRequest;
|
|
111
|
+
}
|
|
112
|
+
return;
|
|
113
|
+
}
|
|
114
|
+
this.processRpcRequest(rpcRequest);
|
|
115
|
+
};
|
|
116
|
+
processProviderMetaInfoRequest = () => {
|
|
117
|
+
if (!this.ethereumProvider)
|
|
118
|
+
return;
|
|
119
|
+
// We assume, that all EIP-6963 providers are already announced
|
|
120
|
+
const providerEip6963Info = getEip6963ProviderInfo(this.ethereumProvider, eip6963Providers);
|
|
121
|
+
const providerWcMetadata = getProviderWcMetadata(this.ethereumProvider);
|
|
122
|
+
// Send the provider meta info to the iFrame window
|
|
123
|
+
iframeRpcProviderTransport.postMessageToWindow(this.iframeWidow, IframeRpcProviderEvents.SEND_PROVIDER_META_INFO, {
|
|
124
|
+
providerEip6963Info,
|
|
125
|
+
providerWcMetadata,
|
|
126
|
+
});
|
|
127
|
+
};
|
|
128
|
+
onProviderEvent(event, params) {
|
|
129
|
+
iframeRpcProviderTransport.postMessageToWindow(this.iframeWidow, IframeRpcProviderEvents.PROVIDER_ON_EVENT, {
|
|
130
|
+
event,
|
|
131
|
+
params,
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Forward a JSON-RPC message to the content window.
|
|
136
|
+
*/
|
|
137
|
+
// TODO: Add proper return type annotation
|
|
138
|
+
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
|
|
139
|
+
forwardRpcResponseToIframe(params) {
|
|
140
|
+
iframeRpcProviderTransport.postMessageToWindow(this.iframeWidow, IframeRpcProviderEvents.PROVIDER_RPC_RESPONSE, params);
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
//# sourceMappingURL=IframeRpcProviderBridge.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"IframeRpcProviderBridge.js","sourceRoot":"","sources":["../../../../../libs/iframe-transport/src/iframeRpcProvider/IframeRpcProviderBridge.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,uBAAuB,EACvB,0BAA0B,GAG3B,MAAM,2BAA2B,CAAA;AAClC,OAAO,EAAE,sBAAsB,EAAE,qBAAqB,EAAE,MAAM,SAAS,CAAA;AAIvE,MAAM,2BAA2B,GAAG,CAAC,SAAS,EAAE,YAAY,EAAE,OAAO,EAAE,cAAc,EAAE,iBAAiB,CAAC,CAAA;AACzG,MAAM,gBAAgB,GAA4B,EAAE,CAAA;AAEpD,IAAI,OAAO,MAAM,KAAK,WAAW,EAAE,CAAC;IAClC,MAAM,CAAC,gBAAgB,CAAC,0BAA0B,EAAE,CAAC,KAAY,EAAE,EAAE;QACnE,MAAM,aAAa,GAAG,KAAqC,CAAA;QAC3D,gBAAgB,CAAC,IAAI,CAAC,aAAa,CAAC,MAAM,CAAC,CAAA;IAC7C,CAAC,CAAC,CAAA;AACJ,CAAC;AAED;;;;;GAKG;AACH,MAAM,OAAO,uBAAuB;IAed;IAdpB;;;SAGK;IACG,gBAAgB,GAA4B,IAAI,CAAA;IAExD,iEAAiE;IACzD,2BAA2B,GAA6C,EAAE,CAAA;IAElF;;;;OAIG;IACH,YAAoB,WAAmB;QAAnB,gBAAW,GAAX,WAAW,CAAQ;IAAG,CAAC;IAE3C;;OAEG;IACH,UAAU;QACR,IAAI,OAAO,MAAM,KAAK,WAAW;YAAE,OAAM;QAEzC,sBAAsB;QACtB,I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,CAAC,UAAU,CAAC,EAAE,CAAC,GAAG,UAAU,CAAA;YAC9D,CAAC;YACD,OAAM;QACR,CAAC;QAED,IAAI,CAAC,iBAAiB,CAAC,UAAU,CAAC,CAAA;IACpC,CAAC,CAAA;IAEO,8BAA8B,GAAG,GAAS,EAAE;QAClD,IAAI,CAAC,IAAI,CAAC,gBAAgB;YAAE,OAAM;QAClC,+DAA+D;QAC/D,MAAM,mBAAmB,GAAG,sBAAsB,CAAC,IAAI,CAAC,gBAAgB,EAAE,gBAAgB,CAAC,CAAA;QAC3F,MAAM,kBAAkB,GAAG,qBAAqB,CAAC,IAAI,CAAC,gBAAgB,CAAC,CAAA;QAEvE,mDAAmD;QACnD,0BAA0B,CAAC,mBAAmB,CAAC,IAAI,CAAC,WAAW,EAAE,uBAAuB,CAAC,uBAAuB,EAAE;YAChH,mBAAmB;YACnB,kBAAkB;SACnB,CAAC,CAAA;IACJ,CAAC,CAAA;IAEO,eAAe,CAAC,KAAa,EAAE,MAAe;QACpD,0BAA0B,CAAC,mBAAmB,CAAC,IAAI,CAAC,WAAW,EAAE,uBAAuB,CAAC,iBAAiB,EAAE;YAC1G,KAAK;YACL,MAAM;SACP,CAAC,CAAA;IACJ,CAAC;IAED;;OAEG;IACH,0CAA0C;IAC1C,4EAA4E;IACpE,0BAA0B,CAAC,MAAkC;QACnE,0BAA0B,CAAC,mBAAmB,CAC5C,IAAI,CAAC,WAAW,EAChB,uBAAuB,CAAC,qBAAqB,EAC7C,MAAM,CACP,CAAA;IACH,CAAC;CACF"}
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ===========================================================================
|
|
3
|
+
* This is a modified version of the original iframe-provider library.
|
|
4
|
+
*
|
|
5
|
+
* The original had some deprecated methods and events, and it was hard to debug for the format used in the messages.
|
|
6
|
+
* This modified version makes use of the Widget library typed subscriptions
|
|
7
|
+
*
|
|
8
|
+
* https://github.com/ethvault/iframe-provider/blob/master/src/index.ts
|
|
9
|
+
*
|
|
10
|
+
* ===========================================================================
|
|
11
|
+
*/
|
|
12
|
+
import { EventEmitter } from 'eventemitter3';
|
|
13
|
+
import { ProviderMetaInfoPayload } from './iframeRpcProviderEvents';
|
|
14
|
+
import { JsonRpcRequest } from '../types';
|
|
15
|
+
interface ProviderConnectInfo {
|
|
16
|
+
readonly chainId: string;
|
|
17
|
+
}
|
|
18
|
+
interface ProviderRpcError extends Error {
|
|
19
|
+
message: string;
|
|
20
|
+
code: number;
|
|
21
|
+
data?: unknown;
|
|
22
|
+
}
|
|
23
|
+
interface ProviderMessage {
|
|
24
|
+
type: string;
|
|
25
|
+
data: unknown;
|
|
26
|
+
}
|
|
27
|
+
type RpcCallback = (error: any, response: any) => void;
|
|
28
|
+
/**
|
|
29
|
+
* Options for constructing the iframe ethereum provider.
|
|
30
|
+
*/
|
|
31
|
+
interface IFrameEthereumProviderOptions {
|
|
32
|
+
targetOrigin?: string;
|
|
33
|
+
timeoutMilliseconds?: number;
|
|
34
|
+
eventSource?: Window;
|
|
35
|
+
eventTarget?: Window;
|
|
36
|
+
}
|
|
37
|
+
export type IFrameEthereumProviderEventTypes = 'message' | 'connect' | 'disconnect' | 'chainChanged' | 'close' | 'notification' | 'networkChanged' | 'accountsChanged';
|
|
38
|
+
/**
|
|
39
|
+
* Export the type information about the different events that are emitted.
|
|
40
|
+
*/
|
|
41
|
+
export interface IFrameEthereumProviderEvents {
|
|
42
|
+
on(event: 'message', handler: (message: ProviderMessage) => void): this;
|
|
43
|
+
on(event: 'connect', handler: (connectInfo: ProviderConnectInfo) => void): this;
|
|
44
|
+
on(event: 'disconnect', handler: (error: ProviderRpcError) => void): this;
|
|
45
|
+
on(event: 'close', handler: (code: number, reason: string) => void): this;
|
|
46
|
+
on(event: 'notification', handler: (result: any) => void): this;
|
|
47
|
+
on(event: 'chainChanged', handler: (chainId: string) => void): this;
|
|
48
|
+
on(event: 'networkChanged', handler: (networkId: string) => void): this;
|
|
49
|
+
on(event: 'accountsChanged', handler: (accounts: string[]) => void): this;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Represents an error in an RPC returned from the event source. Always contains a code and a reason. The message
|
|
53
|
+
* is constructed from both.
|
|
54
|
+
*/
|
|
55
|
+
export declare class RpcError extends Error {
|
|
56
|
+
readonly isRpcError = true;
|
|
57
|
+
readonly code: number;
|
|
58
|
+
readonly reason: string;
|
|
59
|
+
constructor(code: number, reason: string);
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* This is the primary artifact of this library.
|
|
63
|
+
*/
|
|
64
|
+
export declare class WidgetEthereumProvider extends EventEmitter<IFrameEthereumProviderEventTypes> {
|
|
65
|
+
request({ method, params }: JsonRpcRequest): Promise<any>;
|
|
66
|
+
isConnected(): true;
|
|
67
|
+
/**
|
|
68
|
+
* Differentiate this provider from other providers by providing an isIFrame property that always returns true.
|
|
69
|
+
*/
|
|
70
|
+
get isIFrame(): true;
|
|
71
|
+
/**
|
|
72
|
+
* Always return this for currentProvider.
|
|
73
|
+
*/
|
|
74
|
+
get currentProvider(): WidgetEthereumProvider;
|
|
75
|
+
private enabled;
|
|
76
|
+
private readonly timeoutMilliseconds;
|
|
77
|
+
private readonly eventSource;
|
|
78
|
+
private readonly eventTarget;
|
|
79
|
+
private readonly completers;
|
|
80
|
+
private providerMetaInfo;
|
|
81
|
+
private providerMetaInfoCallback?;
|
|
82
|
+
constructor({ timeoutMilliseconds, eventSource, eventTarget, }?: IFrameEthereumProviderOptions);
|
|
83
|
+
/**
|
|
84
|
+
* Helper method that handles transport and request wrapping
|
|
85
|
+
* @param method method to execute
|
|
86
|
+
* @param params params to pass the method
|
|
87
|
+
*/
|
|
88
|
+
private execute;
|
|
89
|
+
/**
|
|
90
|
+
* Send the JSON RPC and return the result.
|
|
91
|
+
*/
|
|
92
|
+
send<TResult = any>(request: JsonRpcRequest, callback: RpcCallback): Promise<TResult>;
|
|
93
|
+
send<TResult = any>(method: string, params: unknown[] | undefined): Promise<TResult>;
|
|
94
|
+
/**
|
|
95
|
+
* Request the parent window to enable access to the user's web3 provider. Return accounts list immediately if already enabled.
|
|
96
|
+
* Keep the legacy method for backward compatibility.
|
|
97
|
+
*/
|
|
98
|
+
enable(): Promise<string[]>;
|
|
99
|
+
/**
|
|
100
|
+
* Backwards compatibility method for web3.
|
|
101
|
+
* @param payload payload to send to the provider
|
|
102
|
+
* @param callback callback to be called when the provider resolves
|
|
103
|
+
*/
|
|
104
|
+
sendAsync(payload: JsonRpcRequest, callback: (error: string | null, result: {
|
|
105
|
+
method: string;
|
|
106
|
+
params?: any[];
|
|
107
|
+
result: any;
|
|
108
|
+
} | any) => void): Promise<void>;
|
|
109
|
+
/**
|
|
110
|
+
* Subscribe to provider meta info
|
|
111
|
+
* @param callback
|
|
112
|
+
*/
|
|
113
|
+
onProviderMetaInfo(callback: (data: ProviderMetaInfoPayload) => void): void;
|
|
114
|
+
/**
|
|
115
|
+
* Handle a Rpc Request
|
|
116
|
+
*/
|
|
117
|
+
private handleRpcRequests;
|
|
118
|
+
private handleOnEvent;
|
|
119
|
+
private emitNotification;
|
|
120
|
+
private emitConnect;
|
|
121
|
+
/**
|
|
122
|
+
* @deprecated See https://eips.ethereum.org/EIPS/eip-1193
|
|
123
|
+
*/
|
|
124
|
+
private emitClose;
|
|
125
|
+
private emitDisconnect;
|
|
126
|
+
private emitChainChanged;
|
|
127
|
+
/**
|
|
128
|
+
* @deprecated See https://eips.ethereum.org/EIPS/eip-1193
|
|
129
|
+
*/
|
|
130
|
+
private emitNetworkChanged;
|
|
131
|
+
private emitAccountsChanged;
|
|
132
|
+
private emitMessage;
|
|
133
|
+
}
|
|
134
|
+
export {};
|