@cowprotocol/iframe-transport 2.0.9 → 2.0.10
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/{src/iframeRpcProvider → iframeRpcProvider}/IframeRpcProviderBridge.d.ts +1 -1
- package/{src/iframeRpcProvider → iframeRpcProvider}/WidgetEthereumProvider.d.ts +18 -29
- package/{src/iframeRpcProvider → iframeRpcProvider}/iframeRpcProviderEvents.d.ts +1 -1
- package/{src/iframeRpcProvider → iframeRpcProvider}/utils.d.ts +1 -1
- package/index.cjs +1 -0
- package/index.js +395 -0
- package/package.json +12 -22
- package/CHANGELOG.md +0 -165
- package/src/IframeTransport.js +0 -42
- package/src/IframeTransport.js.map +0 -1
- package/src/iframeRpcProvider/IframeRpcProviderBridge.js +0 -143
- package/src/iframeRpcProvider/IframeRpcProviderBridge.js.map +0 -1
- package/src/iframeRpcProvider/WidgetEthereumProvider.js +0 -300
- package/src/iframeRpcProvider/WidgetEthereumProvider.js.map +0 -1
- package/src/iframeRpcProvider/iframeRpcProviderEvents.js +0 -11
- package/src/iframeRpcProvider/iframeRpcProviderEvents.js.map +0 -1
- package/src/iframeRpcProvider/utils.js +0 -11
- package/src/iframeRpcProvider/utils.js.map +0 -1
- package/src/index.js +0 -6
- package/src/index.js.map +0 -1
- package/src/types.js +0 -2
- package/src/types.js.map +0 -1
- /package/{src/IframeTransport.d.ts → IframeTransport.d.ts} +0 -0
- /package/{src/index.d.ts → index.d.ts} +0 -0
- /package/{src/types.d.ts → types.d.ts} +0 -0
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { EthereumProvider, JsonRpcRequestMessage } from '../types';
|
|
2
2
|
/**
|
|
3
3
|
* Handles JSON-RPC request coming from an iFrame by delegating to a given Ethereum provider.
|
|
4
4
|
* The result will be passed back to the iFrame.
|
|
@@ -1,40 +1,19 @@
|
|
|
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';
|
|
1
|
+
import { default as EventEmitter } from 'eventemitter3';
|
|
13
2
|
import { ProviderMetaInfoPayload } from './iframeRpcProviderEvents';
|
|
14
3
|
import { JsonRpcRequest } from '../types';
|
|
15
4
|
interface ProviderConnectInfo {
|
|
16
5
|
readonly chainId: string;
|
|
17
6
|
}
|
|
7
|
+
interface ProviderMessage {
|
|
8
|
+
type: string;
|
|
9
|
+
data: unknown;
|
|
10
|
+
}
|
|
18
11
|
interface ProviderRpcError extends Error {
|
|
19
12
|
message: string;
|
|
20
13
|
code: number;
|
|
21
14
|
data?: unknown;
|
|
22
15
|
}
|
|
23
|
-
interface ProviderMessage {
|
|
24
|
-
type: string;
|
|
25
|
-
data: unknown;
|
|
26
|
-
}
|
|
27
16
|
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
17
|
/**
|
|
39
18
|
* Export the type information about the different events that are emitted.
|
|
40
19
|
*/
|
|
@@ -48,6 +27,16 @@ export interface IFrameEthereumProviderEvents {
|
|
|
48
27
|
on(event: 'networkChanged', handler: (networkId: string) => void): this;
|
|
49
28
|
on(event: 'accountsChanged', handler: (accounts: string[]) => void): this;
|
|
50
29
|
}
|
|
30
|
+
export type IFrameEthereumProviderEventTypes = 'message' | 'connect' | 'disconnect' | 'chainChanged' | 'close' | 'notification' | 'networkChanged' | 'accountsChanged';
|
|
31
|
+
/**
|
|
32
|
+
* Options for constructing the iframe ethereum provider.
|
|
33
|
+
*/
|
|
34
|
+
interface IFrameEthereumProviderOptions {
|
|
35
|
+
targetOrigin?: string;
|
|
36
|
+
timeoutMilliseconds?: number;
|
|
37
|
+
eventSource?: Window;
|
|
38
|
+
eventTarget?: Window;
|
|
39
|
+
}
|
|
51
40
|
/**
|
|
52
41
|
* Represents an error in an RPC returned from the event source. Always contains a code and a reason. The message
|
|
53
42
|
* is constructed from both.
|
|
@@ -103,9 +92,9 @@ export declare class WidgetEthereumProvider extends EventEmitter<IFrameEthereumP
|
|
|
103
92
|
*/
|
|
104
93
|
sendAsync(payload: JsonRpcRequest, callback: (error: string | null, result: {
|
|
105
94
|
method: string;
|
|
106
|
-
params?:
|
|
107
|
-
result:
|
|
108
|
-
} |
|
|
95
|
+
params?: unknown[];
|
|
96
|
+
result: unknown;
|
|
97
|
+
} | unknown) => void): Promise<void>;
|
|
109
98
|
/**
|
|
110
99
|
* Subscribe to provider meta info
|
|
111
100
|
* @param callback
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { IframeTransport } from '../IframeTransport';
|
|
2
|
-
import
|
|
2
|
+
import { EIP6963ProviderInfo, JsonRpcRequestMessage, JsonRpcResponse, ProviderWcMetadata } from '../types';
|
|
3
3
|
export interface ProviderRpcRequestPayload {
|
|
4
4
|
rpcRequest: JsonRpcRequestMessage;
|
|
5
5
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { EIP6963ProviderDetail } from '@cowprotocol/types';
|
|
2
2
|
import { EIP6963ProviderInfo, ProviderWcMetadata } from '../types';
|
|
3
3
|
export declare function getProviderWcMetadata(provider: any): ProviderWcMetadata | undefined;
|
|
4
4
|
export declare function getEip6963ProviderInfo(provider: unknown, eip6963Providers: EIP6963ProviderDetail[]): EIP6963ProviderInfo | undefined;
|
package/index.cjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const m=require("eventemitter3");class d{constructor(e){this.key=e}postMessageToWindow(e,t,s){const r=typeof s=="object"?s:{},n={key:this.key,method:t,...r};e.postMessage(n,"*")}listenToMessageFromWindow(e,t,s){const r=n=>{!l(n.data)||n.data.key!==this.key||n.data.method!==t||s(n.data)};return e.addEventListener("message",r),r}stopListeningToMessageFromWindow(e,t,s){e.removeEventListener("message",s)}stopListeningWindowListener(e,t){e.removeEventListener("message",t)}}function l(i){return typeof i=="object"&&i!==null&&"key"in i&&"method"in i&&typeof i.key=="string"&&typeof i.method=="string"}var o=(i=>(i.PROVIDER_RPC_REQUEST="PROVIDER_RPC_REQUEST",i.PROVIDER_RPC_RESPONSE="PROVIDER_RPC_RESPONSE",i.PROVIDER_ON_EVENT="PROVIDER_ON_EVENT",i.SEND_PROVIDER_META_INFO="SEND_PROVIDER_META_INFO",i.REQUEST_PROVIDER_META_INFO="REQUEST_PROVIDER_META_INFO",i))(o||{});const a=new d("cowSwapIframeRpcProviderTransport");function E(i){if(i.isWalletConnect)return i?.session?.peer?.metadata}function R(i,e){return e.find(t=>t.provider===i)?.info}const f=["connect","disconnect","close","chainChanged","accountsChanged"],h=[];typeof window<"u"&&window.addEventListener("eip6963:announceProvider",i=>{const e=i;h.push(e.detail)});class p{constructor(e){this.iframeWidow=e}ethereumProvider=null;requestWaitingForConnection={};disconnect(){typeof window>"u"||(this.ethereumProvider=null,a.stopListeningToMessageFromWindow(window,o.PROVIDER_RPC_REQUEST,this.processRpcCallFromWindow),a.stopListeningToMessageFromWindow(window,o.REQUEST_PROVIDER_META_INFO,this.processProviderMetaInfoRequest))}onConnect(e){typeof window>"u"||(this.ethereumProvider?this.disconnect():a.listenToMessageFromWindow(window,o.PROVIDER_RPC_REQUEST,this.processRpcCallFromWindow),this.ethereumProvider=e,this.processPendingRequests(),f.forEach(t=>{e.on(t,s=>this.onProviderEvent(t,s))}),a.listenToMessageFromWindow(window,o.REQUEST_PROVIDER_META_INFO,this.processProviderMetaInfoRequest))}processPendingRequests(){Object.keys(this.requestWaitingForConnection).forEach(e=>{this.processRpcRequest(this.requestWaitingForConnection[e])}),this.requestWaitingForConnection={}}processRpcRequest(e){const{id:t,jsonrpc:s,method:r}=e;if(!this.ethereumProvider||!t)return;(r==="enable"?this.ethereumProvider.request({method:"eth_requestAccounts",id:t}):this.ethereumProvider.request({...e,id:t})).then(c=>this.forwardRpcResponseToIframe({rpcResponse:{jsonrpc:s,id:t,result:c}})).catch(c=>this.forwardRpcResponseToIframe({rpcResponse:{jsonrpc:s,id:t,error:c}}))}processRpcCallFromWindow=({rpcRequest:e})=>{if(!this.ethereumProvider){e.id&&(this.requestWaitingForConnection[e.id]=e);return}this.processRpcRequest(e)};processProviderMetaInfoRequest=()=>{if(!this.ethereumProvider)return;const e=R(this.ethereumProvider,h),t=E(this.ethereumProvider);a.postMessageToWindow(this.iframeWidow,o.SEND_PROVIDER_META_INFO,{providerEip6963Info:e,providerWcMetadata:t})};onProviderEvent(e,t){a.postMessageToWindow(this.iframeWidow,o.PROVIDER_ON_EVENT,{event:e,params:t})}forwardRpcResponseToIframe(e){a.postMessageToWindow(this.iframeWidow,o.PROVIDER_RPC_RESPONSE,e)}}const g=6e5,P="2.0";class _ extends Error{isRpcError=!0;code;reason;constructor(e,t){super(`${e}: ${t}`),this.code=e,this.reason=t}}class v extends m{request({method:e,params:t}){return this.send(e,t)}isConnected(){return!0}get isIFrame(){return!0}get currentProvider(){return this}enabled=null;timeoutMilliseconds;eventSource;eventTarget;completers={};providerMetaInfo=null;providerMetaInfoCallback;constructor({timeoutMilliseconds:e=g,eventSource:t=window,eventTarget:s=window.parent}={}){super(),this.timeoutMilliseconds=e,this.eventSource=t,this.eventTarget=s,a.listenToMessageFromWindow(this.eventSource,o.PROVIDER_RPC_RESPONSE,r=>{this.handleRpcRequests(r)}),a.listenToMessageFromWindow(this.eventSource,o.PROVIDER_ON_EVENT,r=>{this.handleOnEvent(r)}),a.listenToMessageFromWindow(this.eventSource,o.SEND_PROVIDER_META_INFO,r=>{this.providerMetaInfo=r,this.providerMetaInfoCallback&&this.providerMetaInfoCallback(this.providerMetaInfo)})}async execute(e,t){const s=w(),r={jsonrpc:P,id:s,method:e,params:t},n=new Promise((c,u)=>this.completers[s]={resolve:c,reject:u});return a.postMessageToWindow(this.eventTarget,o.PROVIDER_RPC_REQUEST,{rpcRequest:r}),setTimeout(()=>{this.completers[s]&&(this.completers[s].reject(new Error("Request timed out. Please try again and submit it faster.")),delete this.completers[s])},this.timeoutMilliseconds),n}async send(e,t){const{method:s,params:r}=typeof e=="string"?{method:e,params:t}:{method:e.method,params:e.params},n=await this.execute(s,r);if("error"in n)throw new _(n.error.code,n.error.message);return n.result}async enable(){if(this.enabled===null){const e=this.enabled=this.send("eth_requestAccounts",[]).catch(t=>{throw this.enabled===e&&(this.enabled=null),t})}return this.enabled}async sendAsync(e,t){try{const s=await this.execute(e.method,e.params);t(null,s)}catch(s){t(I(s),null)}}onProviderMetaInfo(e){this.providerMetaInfo?e(this.providerMetaInfo):(this.providerMetaInfoCallback=e,a.postMessageToWindow(this.eventTarget,o.REQUEST_PROVIDER_META_INFO,null))}handleRpcRequests=({rpcResponse:e})=>{if(e.id===void 0||e.id===null)return;const t=this.completers[""+e.id];t&&("error"in e||"result"in e?t.resolve(e):t.reject(new Error("Response from provider did not have error or result key")),delete this.completers[e.id])};handleOnEvent(e){const t=e.params;switch(e.event){case"notification":this.emitNotification(t);break;case"connect":this.emitConnect(t);break;case"disconnect":this.emitDisconnect(t);break;case"chainChanged":this.emitChainChanged(t);break;case"accountsChanged":this.emitAccountsChanged(t);break;case"message":this.emitMessage(t);break;case"networkChanged":this.emitNetworkChanged(t);break;case"close":this.emitClose(t);break;default:console.warn(`[WidgetEthereumProvider] Unknown event type: ${e.event}`);break}}emitNotification(e){this.emit("notification",e)}emitConnect(e){this.enabled===null&&(this.enabled=Promise.resolve([])),this.emit("connect",e)}emitClose(e){Array.isArray(e)&&e.length===2?this.emit("close",e[0],e[1]):this.emit("close")}emitDisconnect(e){this.emit("disconnect",e)}emitChainChanged(e){this.emit("chainChanged",e)}emitNetworkChanged(e){this.emit("networkChanged",e)}emitAccountsChanged(e){this.enabled=Promise.resolve(e),this.emit("accountsChanged",e)}emitMessage(e){this.emit("message",e)}}function w(){return Math.floor(Math.random()*Number.MAX_SAFE_INTEGER)}function I(i){if(!i)return null;if(typeof i=="string")return i;if(i instanceof Error||i.message)return i.message;try{return JSON.stringify(i)}catch{const e="Unknown WidgetEthereumProvider error";return console.error(e,i),e}}exports.IframeRpcProviderBridge=p;exports.IframeRpcProviderEvents=o;exports.IframeTransport=d;exports.WidgetEthereumProvider=v;exports.iframeRpcProviderTransport=a;
|
package/index.js
ADDED
|
@@ -0,0 +1,395 @@
|
|
|
1
|
+
import u from "eventemitter3";
|
|
2
|
+
class m {
|
|
3
|
+
constructor(e) {
|
|
4
|
+
this.key = e;
|
|
5
|
+
}
|
|
6
|
+
postMessageToWindow(e, t, i) {
|
|
7
|
+
const n = typeof i == "object" ? i : {}, o = {
|
|
8
|
+
key: this.key,
|
|
9
|
+
method: t,
|
|
10
|
+
...n
|
|
11
|
+
};
|
|
12
|
+
e.postMessage(
|
|
13
|
+
o,
|
|
14
|
+
"*"
|
|
15
|
+
// TODO: Change to CoW specific origin in production. https://github.com/cowprotocol/cowswap/issues/3828
|
|
16
|
+
);
|
|
17
|
+
}
|
|
18
|
+
listenToMessageFromWindow(e, t, i) {
|
|
19
|
+
const n = (o) => {
|
|
20
|
+
!l(o.data) || o.data.key !== this.key || o.data.method !== t || i(o.data);
|
|
21
|
+
};
|
|
22
|
+
return e.addEventListener("message", n), n;
|
|
23
|
+
}
|
|
24
|
+
stopListeningToMessageFromWindow(e, t, i) {
|
|
25
|
+
e.removeEventListener("message", i);
|
|
26
|
+
}
|
|
27
|
+
stopListeningWindowListener(e, t) {
|
|
28
|
+
e.removeEventListener("message", t);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
function l(s) {
|
|
32
|
+
return typeof s == "object" && s !== null && "key" in s && "method" in s && typeof s.key == "string" && typeof s.method == "string";
|
|
33
|
+
}
|
|
34
|
+
var r = /* @__PURE__ */ ((s) => (s.PROVIDER_RPC_REQUEST = "PROVIDER_RPC_REQUEST", s.PROVIDER_RPC_RESPONSE = "PROVIDER_RPC_RESPONSE", s.PROVIDER_ON_EVENT = "PROVIDER_ON_EVENT", s.SEND_PROVIDER_META_INFO = "SEND_PROVIDER_META_INFO", s.REQUEST_PROVIDER_META_INFO = "REQUEST_PROVIDER_META_INFO", s))(r || {});
|
|
35
|
+
const a = new m("cowSwapIframeRpcProviderTransport");
|
|
36
|
+
function E(s) {
|
|
37
|
+
if (s.isWalletConnect)
|
|
38
|
+
return s?.session?.peer?.metadata;
|
|
39
|
+
}
|
|
40
|
+
function R(s, e) {
|
|
41
|
+
return e.find((t) => t.provider === s)?.info;
|
|
42
|
+
}
|
|
43
|
+
const f = ["connect", "disconnect", "close", "chainChanged", "accountsChanged"], d = [];
|
|
44
|
+
typeof window < "u" && window.addEventListener("eip6963:announceProvider", (s) => {
|
|
45
|
+
const e = s;
|
|
46
|
+
d.push(e.detail);
|
|
47
|
+
});
|
|
48
|
+
class I {
|
|
49
|
+
/**
|
|
50
|
+
* Creates an instance of IframeRpcProviderBridge.
|
|
51
|
+
* @param iframeWidow - The iFrame window that will post up general RPC messages and to which the IframeRpcProviderBridge will forward the RPC result.
|
|
52
|
+
* Also it will receive some special RPC events coming from the wallet, like connect/chainChanged,accountChanged
|
|
53
|
+
*/
|
|
54
|
+
constructor(e) {
|
|
55
|
+
this.iframeWidow = e;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* The Ethereum provider instance.
|
|
59
|
+
* When is null the JSON-RPC bridge is disconnected from the Ethereum provider.
|
|
60
|
+
* */
|
|
61
|
+
ethereumProvider = null;
|
|
62
|
+
/** Stored JSON-RPC requests, to queue them when disconnected. */
|
|
63
|
+
requestWaitingForConnection = {};
|
|
64
|
+
/**
|
|
65
|
+
* Disconnects the JSON-RPC bridge from the Ethereum provider.
|
|
66
|
+
*/
|
|
67
|
+
disconnect() {
|
|
68
|
+
typeof window > "u" || (this.ethereumProvider = null, a.stopListeningToMessageFromWindow(window, r.PROVIDER_RPC_REQUEST, this.processRpcCallFromWindow), a.stopListeningToMessageFromWindow(window, r.REQUEST_PROVIDER_META_INFO, this.processProviderMetaInfoRequest));
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Handles the 'connect' event and sets up event listeners for Ethereum provider events.
|
|
72
|
+
* @param newProvider - The Ethereum provider to connect.
|
|
73
|
+
*/
|
|
74
|
+
onConnect(e) {
|
|
75
|
+
typeof window > "u" || (this.ethereumProvider ? this.disconnect() : a.listenToMessageFromWindow(window, r.PROVIDER_RPC_REQUEST, this.processRpcCallFromWindow), this.ethereumProvider = e, this.processPendingRequests(), f.forEach((t) => {
|
|
76
|
+
e.on(t, (i) => this.onProviderEvent(t, i));
|
|
77
|
+
}), a.listenToMessageFromWindow(window, r.REQUEST_PROVIDER_META_INFO, this.processProviderMetaInfoRequest));
|
|
78
|
+
}
|
|
79
|
+
// TODO: Add proper return type annotation
|
|
80
|
+
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
|
|
81
|
+
processPendingRequests() {
|
|
82
|
+
Object.keys(this.requestWaitingForConnection).forEach((e) => {
|
|
83
|
+
this.processRpcRequest(this.requestWaitingForConnection[e]);
|
|
84
|
+
}), this.requestWaitingForConnection = {};
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Processes a JSON-RPC request and sends appropriate response or error via the content window.
|
|
88
|
+
* @param request - The JSON-RPC request to be processed.
|
|
89
|
+
*/
|
|
90
|
+
// TODO: Add proper return type annotation
|
|
91
|
+
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
|
|
92
|
+
processRpcRequest(e) {
|
|
93
|
+
const {
|
|
94
|
+
id: t,
|
|
95
|
+
jsonrpc: i,
|
|
96
|
+
method: n
|
|
97
|
+
} = e;
|
|
98
|
+
if (!this.ethereumProvider || !t)
|
|
99
|
+
return;
|
|
100
|
+
// Keep the legacy "enable" method for backward compatibility
|
|
101
|
+
(n === "enable" ? this.ethereumProvider.request({
|
|
102
|
+
method: "eth_requestAccounts",
|
|
103
|
+
id: t
|
|
104
|
+
}) : this.ethereumProvider.request({
|
|
105
|
+
...e,
|
|
106
|
+
id: t
|
|
107
|
+
})).then((c) => this.forwardRpcResponseToIframe({
|
|
108
|
+
rpcResponse: {
|
|
109
|
+
jsonrpc: i,
|
|
110
|
+
id: t,
|
|
111
|
+
result: c
|
|
112
|
+
}
|
|
113
|
+
})).catch((c) => this.forwardRpcResponseToIframe({
|
|
114
|
+
rpcResponse: {
|
|
115
|
+
jsonrpc: i,
|
|
116
|
+
id: t,
|
|
117
|
+
error: c
|
|
118
|
+
}
|
|
119
|
+
}));
|
|
120
|
+
}
|
|
121
|
+
processRpcCallFromWindow = ({
|
|
122
|
+
rpcRequest: e
|
|
123
|
+
}) => {
|
|
124
|
+
if (!this.ethereumProvider) {
|
|
125
|
+
e.id && (this.requestWaitingForConnection[e.id] = e);
|
|
126
|
+
return;
|
|
127
|
+
}
|
|
128
|
+
this.processRpcRequest(e);
|
|
129
|
+
};
|
|
130
|
+
processProviderMetaInfoRequest = () => {
|
|
131
|
+
if (!this.ethereumProvider) return;
|
|
132
|
+
const e = R(this.ethereumProvider, d), t = E(this.ethereumProvider);
|
|
133
|
+
a.postMessageToWindow(this.iframeWidow, r.SEND_PROVIDER_META_INFO, {
|
|
134
|
+
providerEip6963Info: e,
|
|
135
|
+
providerWcMetadata: t
|
|
136
|
+
});
|
|
137
|
+
};
|
|
138
|
+
onProviderEvent(e, t) {
|
|
139
|
+
a.postMessageToWindow(this.iframeWidow, r.PROVIDER_ON_EVENT, {
|
|
140
|
+
event: e,
|
|
141
|
+
params: t
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* Forward a JSON-RPC message to the content window.
|
|
146
|
+
*/
|
|
147
|
+
// TODO: Add proper return type annotation
|
|
148
|
+
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
|
|
149
|
+
forwardRpcResponseToIframe(e) {
|
|
150
|
+
a.postMessageToWindow(this.iframeWidow, r.PROVIDER_RPC_RESPONSE, e);
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
const p = 6e5, g = "2.0";
|
|
154
|
+
class P extends Error {
|
|
155
|
+
isRpcError = !0;
|
|
156
|
+
code;
|
|
157
|
+
reason;
|
|
158
|
+
constructor(e, t) {
|
|
159
|
+
super(`${e}: ${t}`), this.code = e, this.reason = t;
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
class T extends u {
|
|
163
|
+
// TODO: Add proper return type annotation
|
|
164
|
+
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
|
|
165
|
+
request({
|
|
166
|
+
method: e,
|
|
167
|
+
params: t
|
|
168
|
+
}) {
|
|
169
|
+
return this.send(e, t);
|
|
170
|
+
}
|
|
171
|
+
isConnected() {
|
|
172
|
+
return !0;
|
|
173
|
+
}
|
|
174
|
+
/**
|
|
175
|
+
* Differentiate this provider from other providers by providing an isIFrame property that always returns true.
|
|
176
|
+
*/
|
|
177
|
+
get isIFrame() {
|
|
178
|
+
return !0;
|
|
179
|
+
}
|
|
180
|
+
/**
|
|
181
|
+
* Always return this for currentProvider.
|
|
182
|
+
*/
|
|
183
|
+
get currentProvider() {
|
|
184
|
+
return this;
|
|
185
|
+
}
|
|
186
|
+
enabled = null;
|
|
187
|
+
timeoutMilliseconds;
|
|
188
|
+
eventSource;
|
|
189
|
+
eventTarget;
|
|
190
|
+
completers = {};
|
|
191
|
+
providerMetaInfo = null;
|
|
192
|
+
providerMetaInfoCallback;
|
|
193
|
+
constructor({
|
|
194
|
+
timeoutMilliseconds: e = p,
|
|
195
|
+
eventSource: t = window,
|
|
196
|
+
eventTarget: i = window.parent
|
|
197
|
+
} = {}) {
|
|
198
|
+
super(), this.timeoutMilliseconds = e, this.eventSource = t, this.eventTarget = i, a.listenToMessageFromWindow(this.eventSource, r.PROVIDER_RPC_RESPONSE, (n) => {
|
|
199
|
+
this.handleRpcRequests(n);
|
|
200
|
+
}), a.listenToMessageFromWindow(this.eventSource, r.PROVIDER_ON_EVENT, (n) => {
|
|
201
|
+
this.handleOnEvent(n);
|
|
202
|
+
}), a.listenToMessageFromWindow(this.eventSource, r.SEND_PROVIDER_META_INFO, (n) => {
|
|
203
|
+
this.providerMetaInfo = n, this.providerMetaInfoCallback && this.providerMetaInfoCallback(this.providerMetaInfo);
|
|
204
|
+
});
|
|
205
|
+
}
|
|
206
|
+
/**
|
|
207
|
+
* Helper method that handles transport and request wrapping
|
|
208
|
+
* @param method method to execute
|
|
209
|
+
* @param params params to pass the method
|
|
210
|
+
*/
|
|
211
|
+
async execute(e, t) {
|
|
212
|
+
const i = _(), n = {
|
|
213
|
+
jsonrpc: g,
|
|
214
|
+
id: i,
|
|
215
|
+
method: e,
|
|
216
|
+
params: t
|
|
217
|
+
}, o = new Promise((c, h) => this.completers[i] = {
|
|
218
|
+
resolve: c,
|
|
219
|
+
reject: h
|
|
220
|
+
});
|
|
221
|
+
return a.postMessageToWindow(this.eventTarget, r.PROVIDER_RPC_REQUEST, {
|
|
222
|
+
rpcRequest: n
|
|
223
|
+
}), setTimeout(() => {
|
|
224
|
+
this.completers[i] && (this.completers[i].reject(new Error("Request timed out. Please try again and submit it faster.")), delete this.completers[i]);
|
|
225
|
+
}, this.timeoutMilliseconds), o;
|
|
226
|
+
}
|
|
227
|
+
// TODO: Replace any with proper type definitions
|
|
228
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
229
|
+
async send(e, t) {
|
|
230
|
+
const {
|
|
231
|
+
method: i,
|
|
232
|
+
params: n
|
|
233
|
+
} = typeof e == "string" ? {
|
|
234
|
+
method: e,
|
|
235
|
+
params: t
|
|
236
|
+
} : {
|
|
237
|
+
method: e.method,
|
|
238
|
+
params: e.params
|
|
239
|
+
}, o = await this.execute(i, n);
|
|
240
|
+
if ("error" in o)
|
|
241
|
+
throw new P(o.error.code, o.error.message);
|
|
242
|
+
return o.result;
|
|
243
|
+
}
|
|
244
|
+
/**
|
|
245
|
+
* Request the parent window to enable access to the user's web3 provider. Return accounts list immediately if already enabled.
|
|
246
|
+
* Keep the legacy method for backward compatibility.
|
|
247
|
+
*/
|
|
248
|
+
async enable() {
|
|
249
|
+
if (this.enabled === null) {
|
|
250
|
+
const e = this.enabled = this.send("eth_requestAccounts", []).catch((t) => {
|
|
251
|
+
throw this.enabled === e && (this.enabled = null), t;
|
|
252
|
+
});
|
|
253
|
+
}
|
|
254
|
+
return this.enabled;
|
|
255
|
+
}
|
|
256
|
+
/**
|
|
257
|
+
* Backwards compatibility method for web3.
|
|
258
|
+
* @param payload payload to send to the provider
|
|
259
|
+
* @param callback callback to be called when the provider resolves
|
|
260
|
+
*/
|
|
261
|
+
async sendAsync(e, t) {
|
|
262
|
+
try {
|
|
263
|
+
const i = await this.execute(e.method, e.params);
|
|
264
|
+
t(null, i);
|
|
265
|
+
} catch (i) {
|
|
266
|
+
t(w(i), null);
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
/**
|
|
270
|
+
* Subscribe to provider meta info
|
|
271
|
+
* @param callback
|
|
272
|
+
*/
|
|
273
|
+
// TODO: Add proper return type annotation
|
|
274
|
+
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
|
|
275
|
+
onProviderMetaInfo(e) {
|
|
276
|
+
this.providerMetaInfo ? e(this.providerMetaInfo) : (this.providerMetaInfoCallback = e, a.postMessageToWindow(this.eventTarget, r.REQUEST_PROVIDER_META_INFO, null));
|
|
277
|
+
}
|
|
278
|
+
/**
|
|
279
|
+
* Handle a Rpc Request
|
|
280
|
+
*/
|
|
281
|
+
// TODO: Add proper return type annotation
|
|
282
|
+
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
|
|
283
|
+
handleRpcRequests = ({
|
|
284
|
+
rpcResponse: e
|
|
285
|
+
}) => {
|
|
286
|
+
if (e.id === void 0 || e.id === null)
|
|
287
|
+
return;
|
|
288
|
+
const t = this.completers["" + e.id];
|
|
289
|
+
t && ("error" in e || "result" in e ? t.resolve(e) : t.reject(new Error("Response from provider did not have error or result key")), delete this.completers[e.id]);
|
|
290
|
+
};
|
|
291
|
+
// TODO: Add proper return type annotation
|
|
292
|
+
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
|
|
293
|
+
handleOnEvent(e) {
|
|
294
|
+
const t = e.params;
|
|
295
|
+
switch (e.event) {
|
|
296
|
+
case "notification":
|
|
297
|
+
this.emitNotification(t);
|
|
298
|
+
break;
|
|
299
|
+
case "connect":
|
|
300
|
+
this.emitConnect(t);
|
|
301
|
+
break;
|
|
302
|
+
case "disconnect":
|
|
303
|
+
this.emitDisconnect(t);
|
|
304
|
+
break;
|
|
305
|
+
case "chainChanged":
|
|
306
|
+
this.emitChainChanged(t);
|
|
307
|
+
break;
|
|
308
|
+
case "accountsChanged":
|
|
309
|
+
this.emitAccountsChanged(t);
|
|
310
|
+
break;
|
|
311
|
+
case "message":
|
|
312
|
+
this.emitMessage(t);
|
|
313
|
+
break;
|
|
314
|
+
// Deprecated events below 👇 --------------------------------------
|
|
315
|
+
case "networkChanged":
|
|
316
|
+
this.emitNetworkChanged(t);
|
|
317
|
+
break;
|
|
318
|
+
case "close":
|
|
319
|
+
this.emitClose(t);
|
|
320
|
+
break;
|
|
321
|
+
// END OF: Deprecated events --------------------------------------
|
|
322
|
+
default:
|
|
323
|
+
console.warn(`[WidgetEthereumProvider] Unknown event type: ${e.event}`);
|
|
324
|
+
break;
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
// TODO: Add proper return type annotation
|
|
328
|
+
// TODO: Replace any with proper type definitions
|
|
329
|
+
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type, @typescript-eslint/no-explicit-any
|
|
330
|
+
emitNotification(e) {
|
|
331
|
+
this.emit("notification", e);
|
|
332
|
+
}
|
|
333
|
+
// TODO: Add proper return type annotation
|
|
334
|
+
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
|
|
335
|
+
emitConnect(e) {
|
|
336
|
+
this.enabled === null && (this.enabled = Promise.resolve([])), this.emit("connect", e);
|
|
337
|
+
}
|
|
338
|
+
/**
|
|
339
|
+
* @deprecated See https://eips.ethereum.org/EIPS/eip-1193
|
|
340
|
+
*/
|
|
341
|
+
// TODO: Add proper return type annotation
|
|
342
|
+
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
|
|
343
|
+
emitClose(e) {
|
|
344
|
+
Array.isArray(e) && e.length === 2 ? this.emit("close", e[0], e[1]) : this.emit("close");
|
|
345
|
+
}
|
|
346
|
+
// TODO: Add proper return type annotation
|
|
347
|
+
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
|
|
348
|
+
emitDisconnect(e) {
|
|
349
|
+
this.emit("disconnect", e);
|
|
350
|
+
}
|
|
351
|
+
// TODO: Add proper return type annotation
|
|
352
|
+
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
|
|
353
|
+
emitChainChanged(e) {
|
|
354
|
+
this.emit("chainChanged", e);
|
|
355
|
+
}
|
|
356
|
+
/**
|
|
357
|
+
* @deprecated See https://eips.ethereum.org/EIPS/eip-1193
|
|
358
|
+
*/
|
|
359
|
+
// TODO: Add proper return type annotation
|
|
360
|
+
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
|
|
361
|
+
emitNetworkChanged(e) {
|
|
362
|
+
this.emit("networkChanged", e);
|
|
363
|
+
}
|
|
364
|
+
// TODO: Add proper return type annotation
|
|
365
|
+
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
|
|
366
|
+
emitAccountsChanged(e) {
|
|
367
|
+
this.enabled = Promise.resolve(e), this.emit("accountsChanged", e);
|
|
368
|
+
}
|
|
369
|
+
// TODO: Add proper return type annotation
|
|
370
|
+
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
|
|
371
|
+
emitMessage(e) {
|
|
372
|
+
this.emit("message", e);
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
function _() {
|
|
376
|
+
return Math.floor(Math.random() * Number.MAX_SAFE_INTEGER);
|
|
377
|
+
}
|
|
378
|
+
function w(s) {
|
|
379
|
+
if (!s) return null;
|
|
380
|
+
if (typeof s == "string") return s;
|
|
381
|
+
if (s instanceof Error || s.message) return s.message;
|
|
382
|
+
try {
|
|
383
|
+
return JSON.stringify(s);
|
|
384
|
+
} catch {
|
|
385
|
+
const e = "Unknown WidgetEthereumProvider error";
|
|
386
|
+
return console.error(e, s), e;
|
|
387
|
+
}
|
|
388
|
+
}
|
|
389
|
+
export {
|
|
390
|
+
I as IframeRpcProviderBridge,
|
|
391
|
+
r as IframeRpcProviderEvents,
|
|
392
|
+
m as IframeTransport,
|
|
393
|
+
T as WidgetEthereumProvider,
|
|
394
|
+
a as iframeRpcProviderTransport
|
|
395
|
+
};
|
package/package.json
CHANGED
|
@@ -1,38 +1,28 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cowprotocol/iframe-transport",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.10",
|
|
4
4
|
"description": "CoW Swap iframe-transport",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
7
7
|
"url": "https://github.com/cowprotocol/cowswap.git",
|
|
8
8
|
"directory": "libs/iframe-transport"
|
|
9
9
|
},
|
|
10
|
-
"type": "
|
|
11
|
-
"main": "./
|
|
12
|
-
"types": "./
|
|
10
|
+
"type": "module",
|
|
11
|
+
"main": "./index.js",
|
|
12
|
+
"types": "./index.d.ts",
|
|
13
13
|
"license": "ISC",
|
|
14
14
|
"publishConfig": {
|
|
15
15
|
"access": "public"
|
|
16
16
|
},
|
|
17
17
|
"dependencies": {
|
|
18
|
-
"@cowprotocol/
|
|
19
|
-
"
|
|
20
|
-
"@cowprotocol/types": "^4.0.1",
|
|
21
|
-
"@uniswap/sdk-core": "3.2.6",
|
|
22
|
-
"@web3-react/types": "8.2.3",
|
|
23
|
-
"eventemitter3": "^4.0.0",
|
|
24
|
-
"tslib": "1.14.1"
|
|
18
|
+
"@cowprotocol/types": "^4.1.0",
|
|
19
|
+
"eventemitter3": "^4.0.0"
|
|
25
20
|
},
|
|
26
|
-
"
|
|
27
|
-
"
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
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"
|
|
21
|
+
"exports": {
|
|
22
|
+
".": {
|
|
23
|
+
"types": "./index.d.ts",
|
|
24
|
+
"import": "./index.js",
|
|
25
|
+
"require": "./index.cjs"
|
|
26
|
+
}
|
|
37
27
|
}
|
|
38
28
|
}
|
package/CHANGELOG.md
DELETED
|
@@ -1,165 +0,0 @@
|
|
|
1
|
-
# Changelog
|
|
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
|
-
|
|
26
|
-
## [2.0.7](https://github.com/cowprotocol/cowswap/compare/iframe-transport-v2.0.6...iframe-transport-v2.0.7) (2026-03-10)
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
### Dependencies
|
|
30
|
-
|
|
31
|
-
* The following workspace dependencies were updated
|
|
32
|
-
* dependencies
|
|
33
|
-
* @cowprotocol/types bumped to 3.4.0
|
|
34
|
-
|
|
35
|
-
## [2.0.6](https://github.com/cowprotocol/cowswap/compare/iframe-transport-v2.0.5...iframe-transport-v2.0.6) (2026-02-25)
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
### 🔧 Miscellaneous
|
|
39
|
-
|
|
40
|
-
* main -> dev ([9c6611e](https://github.com/cowprotocol/cowswap/commit/9c6611e90a4b23e23f6aaadc513de3c6d7f3b562))
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
### Dependencies
|
|
44
|
-
|
|
45
|
-
* The following workspace dependencies were updated
|
|
46
|
-
* dependencies
|
|
47
|
-
* @cowprotocol/types bumped to 3.3.2
|
|
48
|
-
|
|
49
|
-
## [2.0.5](https://github.com/cowprotocol/cowswap/compare/iframe-transport-v2.0.4...iframe-transport-v2.0.5) (2026-02-24)
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
### 🔧 Miscellaneous
|
|
53
|
-
|
|
54
|
-
* merge main into dev 23 02 ([#7062](https://github.com/cowprotocol/cowswap/issues/7062)) ([ac48c9c](https://github.com/cowprotocol/cowswap/commit/ac48c9c83284c6228ba71392edc1c1e0483b53ff))
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
### Dependencies
|
|
58
|
-
|
|
59
|
-
* The following workspace dependencies were updated
|
|
60
|
-
* dependencies
|
|
61
|
-
* @cowprotocol/types bumped to 3.3.1
|
|
62
|
-
|
|
63
|
-
## [2.0.4](https://github.com/cowprotocol/cowswap/compare/iframe-transport-v2.0.3...iframe-transport-v2.0.4) (2026-02-20)
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
### Dependencies
|
|
67
|
-
|
|
68
|
-
* The following workspace dependencies were updated
|
|
69
|
-
* dependencies
|
|
70
|
-
* @cowprotocol/types bumped to 3.3.0
|
|
71
|
-
|
|
72
|
-
## [2.0.3](https://github.com/cowprotocol/cowswap/compare/iframe-transport-v2.0.2...iframe-transport-v2.0.3) (2026-02-13)
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
### Dependencies
|
|
76
|
-
|
|
77
|
-
* The following workspace dependencies were updated
|
|
78
|
-
* dependencies
|
|
79
|
-
* @cowprotocol/types bumped to 3.2.0
|
|
80
|
-
|
|
81
|
-
## [2.0.2](https://github.com/cowprotocol/cowswap/compare/iframe-transport-v2.0.1...iframe-transport-v2.0.2) (2026-02-05)
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
### Dependencies
|
|
85
|
-
|
|
86
|
-
* The following workspace dependencies were updated
|
|
87
|
-
* dependencies
|
|
88
|
-
* @cowprotocol/types bumped to 3.1.0
|
|
89
|
-
|
|
90
|
-
## [2.0.1](https://github.com/cowprotocol/cowswap/compare/iframe-transport-v2.0.0...iframe-transport-v2.0.1) (2026-02-02)
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
### Dependencies
|
|
94
|
-
|
|
95
|
-
* The following workspace dependencies were updated
|
|
96
|
-
* dependencies
|
|
97
|
-
* @cowprotocol/types bumped to 3.0.1
|
|
98
|
-
|
|
99
|
-
## [2.0.0](https://github.com/cowprotocol/cowswap/compare/iframe-transport-v1.2.0...iframe-transport-v2.0.0) (2026-01-28)
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
### ⚠ BREAKING CHANGES
|
|
103
|
-
|
|
104
|
-
* migrate from yarn to pnpm ([#6847](https://github.com/cowprotocol/cowswap/issues/6847))
|
|
105
|
-
|
|
106
|
-
### Features
|
|
107
|
-
|
|
108
|
-
* migrate from yarn to pnpm ([#6847](https://github.com/cowprotocol/cowswap/issues/6847)) ([1c5d115](https://github.com/cowprotocol/cowswap/commit/1c5d11516d0ddb997b0ebbb4eee4adcb491204a4))
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
### Dependencies
|
|
112
|
-
|
|
113
|
-
* The following workspace dependencies were updated
|
|
114
|
-
* dependencies
|
|
115
|
-
* @cowprotocol/types bumped to 3.0.0
|
|
116
|
-
|
|
117
|
-
## [1.2.0](https://github.com/cowprotocol/cowswap/compare/iframe-transport-v1.1.1...iframe-transport-v1.2.0) (2026-01-26)
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
### Features
|
|
121
|
-
|
|
122
|
-
* fix types in iframe-transport lib ([#6882](https://github.com/cowprotocol/cowswap/issues/6882)) ([f419e21](https://github.com/cowprotocol/cowswap/commit/f419e219fefdd007101ba61053dcce6c218eeee0))
|
|
123
|
-
|
|
124
|
-
## [1.1.1](https://github.com/cowprotocol/cowswap/compare/iframe-transport-v1.1.0...iframe-transport-v1.1.1) (2026-01-26)
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
### Bug Fixes
|
|
128
|
-
|
|
129
|
-
* add a guard for ssr in eip6963 listener ([#6849](https://github.com/cowprotocol/cowswap/issues/6849)) ([aeaf7e8](https://github.com/cowprotocol/cowswap/commit/aeaf7e810648214252359620f7bb63b0b207c227))
|
|
130
|
-
* **widget-lib:** add compatibility with server rendering ([#6813](https://github.com/cowprotocol/cowswap/issues/6813)) ([76bd736](https://github.com/cowprotocol/cowswap/commit/76bd736f17d722f0a639542d4fcbd5e3f0be57b2))
|
|
131
|
-
|
|
132
|
-
## [1.1.0](https://github.com/cowprotocol/cowswap/compare/iframe-transport-v1.0.3...iframe-transport-v1.1.0) (2025-08-12)
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
### Features
|
|
136
|
-
|
|
137
|
-
* rename Permit hook dapp id ([#6138](https://github.com/cowprotocol/cowswap/issues/6138)) ([41b0b18](https://github.com/cowprotocol/cowswap/commit/41b0b182d4a673bb1799a699ea83029ee8c6d73b))
|
|
138
|
-
|
|
139
|
-
## [1.0.3](https://github.com/cowprotocol/cowswap/compare/iframe-transport-v1.0.2...iframe-transport-v1.0.3) (2025-06-18)
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
### Bug Fixes
|
|
143
|
-
|
|
144
|
-
* make order progress bar UI more stable ([#5834](https://github.com/cowprotocol/cowswap/issues/5834)) ([80cebd1](https://github.com/cowprotocol/cowswap/commit/80cebd1104a0a2e30e12ce8a4b3d62c212559cec))
|
|
145
|
-
|
|
146
|
-
## [1.0.2](https://github.com/cowprotocol/cowswap/compare/iframe-transport-v1.0.1...iframe-transport-v1.0.2) (2025-05-19)
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
### Bug Fixes
|
|
150
|
-
|
|
151
|
-
* **dev-deps-update:** bump the dev-deps group with 76 updates ([#5663](https://github.com/cowprotocol/cowswap/issues/5663)) ([552b349](https://github.com/cowprotocol/cowswap/commit/552b349f53762a01ccf008e9a2083248424cbafa))
|
|
152
|
-
|
|
153
|
-
## [1.0.1](https://github.com/cowprotocol/cowswap/compare/iframe-transport-v1.0.0...iframe-transport-v1.0.1) (2025-02-03)
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
### Bug Fixes
|
|
157
|
-
|
|
158
|
-
* display Metamask warning only for extension/mobile wallets ([#5370](https://github.com/cowprotocol/cowswap/issues/5370)) ([abb5683](https://github.com/cowprotocol/cowswap/commit/abb56834b1e21029ca66362f3b721cd47e080547))
|
|
159
|
-
|
|
160
|
-
## 1.0.0 (2024-09-30)
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
### Features
|
|
164
|
-
|
|
165
|
-
* **hooks-store:** support iframe hook-dapps ([#4885](https://github.com/cowprotocol/cowswap/issues/4885)) ([5116f29](https://github.com/cowprotocol/cowswap/commit/5116f296a0e4866d0a51a806b7abe55e809d26e9))
|
package/src/IframeTransport.js
DELETED
|
@@ -1,42 +0,0 @@
|
|
|
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
|
|
@@ -1 +0,0 @@
|
|
|
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"}
|
|
@@ -1,143 +0,0 @@
|
|
|
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
|
|
@@ -1 +0,0 @@
|
|
|
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,IAAI,CAAC,gBAAgB,GAAG,IAAI,CAAA;QAC5B,0BAA0B,CAAC,gCAAgC,CACzD,MAAM,EACN,uBAAuB,CAAC,oBAAoB,EAC5C,IAAI,CAAC,wBAAwB,CAC9B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AAC,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"}
|
|
@@ -1,300 +0,0 @@
|
|
|
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 { IframeRpcProviderEvents, iframeRpcProviderTransport, } from './iframeRpcProviderEvents';
|
|
14
|
-
// By default timeout is 10 minutes
|
|
15
|
-
const DEFAULT_TIMEOUT_MILLISECONDS = 600000;
|
|
16
|
-
const JSON_RPC_VERSION = '2.0';
|
|
17
|
-
/**
|
|
18
|
-
* We return a random number between the 0 and the maximum safe integer so that we always generate a unique identifier,
|
|
19
|
-
* across all communication channels.
|
|
20
|
-
*/
|
|
21
|
-
function getUniqueId() {
|
|
22
|
-
return Math.floor(Math.random() * Number.MAX_SAFE_INTEGER);
|
|
23
|
-
}
|
|
24
|
-
/**
|
|
25
|
-
* Represents an error in an RPC returned from the event source. Always contains a code and a reason. The message
|
|
26
|
-
* is constructed from both.
|
|
27
|
-
*/
|
|
28
|
-
export class RpcError extends Error {
|
|
29
|
-
isRpcError = true;
|
|
30
|
-
code;
|
|
31
|
-
reason;
|
|
32
|
-
constructor(code, reason) {
|
|
33
|
-
super(`${code}: ${reason}`);
|
|
34
|
-
this.code = code;
|
|
35
|
-
this.reason = reason;
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
/**
|
|
39
|
-
* This is the primary artifact of this library.
|
|
40
|
-
*/
|
|
41
|
-
export class WidgetEthereumProvider extends EventEmitter {
|
|
42
|
-
// TODO: Add proper return type annotation
|
|
43
|
-
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
|
|
44
|
-
request({ method, params }) {
|
|
45
|
-
return this.send(method, params);
|
|
46
|
-
}
|
|
47
|
-
isConnected() {
|
|
48
|
-
return true;
|
|
49
|
-
}
|
|
50
|
-
/**
|
|
51
|
-
* Differentiate this provider from other providers by providing an isIFrame property that always returns true.
|
|
52
|
-
*/
|
|
53
|
-
get isIFrame() {
|
|
54
|
-
return true;
|
|
55
|
-
}
|
|
56
|
-
/**
|
|
57
|
-
* Always return this for currentProvider.
|
|
58
|
-
*/
|
|
59
|
-
get currentProvider() {
|
|
60
|
-
return this;
|
|
61
|
-
}
|
|
62
|
-
enabled = null;
|
|
63
|
-
timeoutMilliseconds;
|
|
64
|
-
eventSource;
|
|
65
|
-
eventTarget;
|
|
66
|
-
completers = {};
|
|
67
|
-
providerMetaInfo = null;
|
|
68
|
-
providerMetaInfoCallback;
|
|
69
|
-
constructor({ timeoutMilliseconds = DEFAULT_TIMEOUT_MILLISECONDS, eventSource = window, eventTarget = window.parent, } = {}) {
|
|
70
|
-
// Call super for `this` to be defined
|
|
71
|
-
super();
|
|
72
|
-
this.timeoutMilliseconds = timeoutMilliseconds;
|
|
73
|
-
this.eventSource = eventSource;
|
|
74
|
-
this.eventTarget = eventTarget;
|
|
75
|
-
iframeRpcProviderTransport.listenToMessageFromWindow(this.eventSource, IframeRpcProviderEvents.PROVIDER_RPC_RESPONSE, (message) => {
|
|
76
|
-
this.handleRpcRequests(message);
|
|
77
|
-
});
|
|
78
|
-
iframeRpcProviderTransport.listenToMessageFromWindow(this.eventSource, IframeRpcProviderEvents.PROVIDER_ON_EVENT, (message) => {
|
|
79
|
-
this.handleOnEvent(message);
|
|
80
|
-
});
|
|
81
|
-
iframeRpcProviderTransport.listenToMessageFromWindow(this.eventSource, IframeRpcProviderEvents.SEND_PROVIDER_META_INFO, (message) => {
|
|
82
|
-
this.providerMetaInfo = message;
|
|
83
|
-
if (this.providerMetaInfoCallback) {
|
|
84
|
-
this.providerMetaInfoCallback(this.providerMetaInfo);
|
|
85
|
-
}
|
|
86
|
-
});
|
|
87
|
-
}
|
|
88
|
-
/**
|
|
89
|
-
* Helper method that handles transport and request wrapping
|
|
90
|
-
* @param method method to execute
|
|
91
|
-
* @param params params to pass the method
|
|
92
|
-
*/
|
|
93
|
-
async execute(method, params) {
|
|
94
|
-
const id = getUniqueId();
|
|
95
|
-
const rpcRequest = {
|
|
96
|
-
jsonrpc: JSON_RPC_VERSION,
|
|
97
|
-
id,
|
|
98
|
-
method,
|
|
99
|
-
params,
|
|
100
|
-
};
|
|
101
|
-
const promise = new Promise((resolve, reject) => (this.completers[id] = { resolve, reject }));
|
|
102
|
-
// Send the JSON RPC to the event source.
|
|
103
|
-
iframeRpcProviderTransport.postMessageToWindow(this.eventTarget, IframeRpcProviderEvents.PROVIDER_RPC_REQUEST, {
|
|
104
|
-
rpcRequest,
|
|
105
|
-
});
|
|
106
|
-
// Delete the completer within the timeout and reject the promise.
|
|
107
|
-
setTimeout(() => {
|
|
108
|
-
if (this.completers[id]) {
|
|
109
|
-
this.completers[id].reject(new Error('Request timed out. Please try again and submit it faster.'));
|
|
110
|
-
delete this.completers[id];
|
|
111
|
-
}
|
|
112
|
-
}, this.timeoutMilliseconds);
|
|
113
|
-
return promise;
|
|
114
|
-
}
|
|
115
|
-
// TODO: Replace any with proper type definitions
|
|
116
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
117
|
-
async send(methodOrRequest, paramsOrCallback) {
|
|
118
|
-
const { method, params } = typeof methodOrRequest === 'string'
|
|
119
|
-
? { method: methodOrRequest, params: paramsOrCallback }
|
|
120
|
-
: { method: methodOrRequest.method, params: methodOrRequest.params };
|
|
121
|
-
// TODO: Replace any with proper type definitions
|
|
122
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
123
|
-
const response = await this.execute(method, params);
|
|
124
|
-
if ('error' in response) {
|
|
125
|
-
throw new RpcError(response.error.code, response.error.message);
|
|
126
|
-
}
|
|
127
|
-
else {
|
|
128
|
-
return response.result;
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
/**
|
|
132
|
-
* Request the parent window to enable access to the user's web3 provider. Return accounts list immediately if already enabled.
|
|
133
|
-
* Keep the legacy method for backward compatibility.
|
|
134
|
-
*/
|
|
135
|
-
async enable() {
|
|
136
|
-
if (this.enabled === null) {
|
|
137
|
-
const promise = (this.enabled = this.send('eth_requestAccounts', []).catch((error) => {
|
|
138
|
-
// Clear this.enabled if it's this promise so we try again next call.
|
|
139
|
-
// this.enabled might be set from elsewhere if, e.g. the accounts changed event is emitted
|
|
140
|
-
if (this.enabled === promise) {
|
|
141
|
-
this.enabled = null;
|
|
142
|
-
}
|
|
143
|
-
// Rethrow the error.
|
|
144
|
-
throw error;
|
|
145
|
-
}));
|
|
146
|
-
}
|
|
147
|
-
return this.enabled;
|
|
148
|
-
}
|
|
149
|
-
/**
|
|
150
|
-
* Backwards compatibility method for web3.
|
|
151
|
-
* @param payload payload to send to the provider
|
|
152
|
-
* @param callback callback to be called when the provider resolves
|
|
153
|
-
*/
|
|
154
|
-
async sendAsync(payload,
|
|
155
|
-
// TODO: Replace any with proper type definitions
|
|
156
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
157
|
-
callback) {
|
|
158
|
-
try {
|
|
159
|
-
const result = await this.execute(payload.method, payload.params);
|
|
160
|
-
callback(null, result);
|
|
161
|
-
}
|
|
162
|
-
catch (error) {
|
|
163
|
-
callback(error, null);
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
/**
|
|
167
|
-
* Subscribe to provider meta info
|
|
168
|
-
* @param callback
|
|
169
|
-
*/
|
|
170
|
-
// TODO: Add proper return type annotation
|
|
171
|
-
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
|
|
172
|
-
onProviderMetaInfo(callback) {
|
|
173
|
-
if (this.providerMetaInfo) {
|
|
174
|
-
callback(this.providerMetaInfo);
|
|
175
|
-
}
|
|
176
|
-
else {
|
|
177
|
-
this.providerMetaInfoCallback = callback;
|
|
178
|
-
iframeRpcProviderTransport.postMessageToWindow(this.eventTarget, IframeRpcProviderEvents.REQUEST_PROVIDER_META_INFO, null);
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
|
-
/**
|
|
182
|
-
* Handle a Rpc Request
|
|
183
|
-
*/
|
|
184
|
-
// TODO: Add proper return type annotation
|
|
185
|
-
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
|
|
186
|
-
handleRpcRequests = ({ rpcResponse }) => {
|
|
187
|
-
if (rpcResponse.id === undefined || rpcResponse.id === null) {
|
|
188
|
-
return;
|
|
189
|
-
}
|
|
190
|
-
const completer = this.completers['' + rpcResponse.id];
|
|
191
|
-
// True if we haven't timed out and this is a response to a message we sent.
|
|
192
|
-
if (completer) {
|
|
193
|
-
// Handle pending promise
|
|
194
|
-
if ('error' in rpcResponse || 'result' in rpcResponse) {
|
|
195
|
-
completer.resolve(rpcResponse);
|
|
196
|
-
}
|
|
197
|
-
else {
|
|
198
|
-
completer.reject(new Error('Response from provider did not have error or result key'));
|
|
199
|
-
}
|
|
200
|
-
delete this.completers[rpcResponse.id];
|
|
201
|
-
}
|
|
202
|
-
};
|
|
203
|
-
// TODO: Add proper return type annotation
|
|
204
|
-
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
|
|
205
|
-
handleOnEvent(message) {
|
|
206
|
-
// TODO: Replace any with proper type definitions
|
|
207
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
208
|
-
const params = message.params;
|
|
209
|
-
switch (message.event) {
|
|
210
|
-
case 'notification':
|
|
211
|
-
this.emitNotification(params);
|
|
212
|
-
break;
|
|
213
|
-
case 'connect':
|
|
214
|
-
this.emitConnect(params);
|
|
215
|
-
break;
|
|
216
|
-
case 'disconnect':
|
|
217
|
-
this.emitDisconnect(params);
|
|
218
|
-
break;
|
|
219
|
-
case 'chainChanged':
|
|
220
|
-
this.emitChainChanged(params);
|
|
221
|
-
break;
|
|
222
|
-
case 'accountsChanged':
|
|
223
|
-
this.emitAccountsChanged(params);
|
|
224
|
-
break;
|
|
225
|
-
case 'message':
|
|
226
|
-
this.emitMessage(params);
|
|
227
|
-
break;
|
|
228
|
-
// Deprecated events below 👇 --------------------------------------
|
|
229
|
-
case 'networkChanged':
|
|
230
|
-
this.emitNetworkChanged(params);
|
|
231
|
-
break;
|
|
232
|
-
case 'close':
|
|
233
|
-
this.emitClose(params);
|
|
234
|
-
break;
|
|
235
|
-
// END OF: Deprecated events --------------------------------------
|
|
236
|
-
default:
|
|
237
|
-
console.warn(`[WidgetEthereumProvider] Unknown event type: ${message.event}`);
|
|
238
|
-
break;
|
|
239
|
-
}
|
|
240
|
-
}
|
|
241
|
-
// TODO: Add proper return type annotation
|
|
242
|
-
// TODO: Replace any with proper type definitions
|
|
243
|
-
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type, @typescript-eslint/no-explicit-any
|
|
244
|
-
emitNotification(result) {
|
|
245
|
-
this.emit('notification', result);
|
|
246
|
-
}
|
|
247
|
-
// TODO: Add proper return type annotation
|
|
248
|
-
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
|
|
249
|
-
emitConnect(connectInfo) {
|
|
250
|
-
// If the provider isn't enabled but it emits a connect event, assume that it's enabled and initialize
|
|
251
|
-
// with an empty list of accounts.
|
|
252
|
-
if (this.enabled === null) {
|
|
253
|
-
this.enabled = Promise.resolve([]);
|
|
254
|
-
}
|
|
255
|
-
this.emit('connect', connectInfo);
|
|
256
|
-
}
|
|
257
|
-
/**
|
|
258
|
-
* @deprecated See https://eips.ethereum.org/EIPS/eip-1193
|
|
259
|
-
*/
|
|
260
|
-
// TODO: Add proper return type annotation
|
|
261
|
-
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
|
|
262
|
-
emitClose(params) {
|
|
263
|
-
if (Array.isArray(params) && params.length === 2) {
|
|
264
|
-
this.emit('close', params[0], params[1]);
|
|
265
|
-
}
|
|
266
|
-
else {
|
|
267
|
-
this.emit('close');
|
|
268
|
-
}
|
|
269
|
-
}
|
|
270
|
-
// TODO: Add proper return type annotation
|
|
271
|
-
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
|
|
272
|
-
emitDisconnect(error) {
|
|
273
|
-
this.emit('disconnect', error);
|
|
274
|
-
}
|
|
275
|
-
// TODO: Add proper return type annotation
|
|
276
|
-
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
|
|
277
|
-
emitChainChanged(chainId) {
|
|
278
|
-
this.emit('chainChanged', chainId);
|
|
279
|
-
}
|
|
280
|
-
/**
|
|
281
|
-
* @deprecated See https://eips.ethereum.org/EIPS/eip-1193
|
|
282
|
-
*/
|
|
283
|
-
// TODO: Add proper return type annotation
|
|
284
|
-
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
|
|
285
|
-
emitNetworkChanged(networkId) {
|
|
286
|
-
this.emit('networkChanged', networkId);
|
|
287
|
-
}
|
|
288
|
-
// TODO: Add proper return type annotation
|
|
289
|
-
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
|
|
290
|
-
emitAccountsChanged(accounts) {
|
|
291
|
-
this.enabled = Promise.resolve(accounts);
|
|
292
|
-
this.emit('accountsChanged', accounts);
|
|
293
|
-
}
|
|
294
|
-
// TODO: Add proper return type annotation
|
|
295
|
-
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
|
|
296
|
-
emitMessage(message) {
|
|
297
|
-
this.emit('message', message);
|
|
298
|
-
}
|
|
299
|
-
}
|
|
300
|
-
//# sourceMappingURL=WidgetEthereumProvider.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"WidgetEthereumProvider.js","sourceRoot":"","sources":["../../../../../libs/iframe-transport/src/iframeRpcProvider/WidgetEthereumProvider.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAA;AAE5C,OAAO,EACL,uBAAuB,EACvB,0BAA0B,GAI3B,MAAM,2BAA2B,CAAA;AA4BlC,mCAAmC;AACnC,MAAM,4BAA4B,GAAG,MAAM,CAAA;AAE3C,MAAM,gBAAgB,GAAG,KAAK,CAAA;AA+B9B;;;GAGG;AACH,SAAS,WAAW;IAClB,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,MAAM,CAAC,gBAAgB,CAAC,CAAA;AAC5D,CAAC;AAmCD;;;GAGG;AACH,MAAM,OAAO,QAAS,SAAQ,KAAK;IACjB,UAAU,GAAG,IAAI,CAAA;IAEjB,IAAI,CAAQ;IACZ,MAAM,CAAQ;IAE9B,YAAY,IAAY,EAAE,MAAc;QACtC,KAAK,CAAC,GAAG,IAAI,KAAK,MAAM,EAAE,CAA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AAI,CAAC,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAA;QACxC,IAAI,CAAC,IAAI,CAAC,iBAAiB,EAAE,QAAQ,CAAC,CAAA;IACxC,CAAC;IAED,0CAA0C;IAC1C,4EAA4E;IACpE,WAAW,CAAC,OAAwB;QAC1C,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,OAAO,CAAC,CAAA;IAC/B,CAAC;CACF"}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { IframeTransport } from '../IframeTransport';
|
|
2
|
-
export var IframeRpcProviderEvents;
|
|
3
|
-
(function (IframeRpcProviderEvents) {
|
|
4
|
-
IframeRpcProviderEvents["PROVIDER_RPC_REQUEST"] = "PROVIDER_RPC_REQUEST";
|
|
5
|
-
IframeRpcProviderEvents["PROVIDER_RPC_RESPONSE"] = "PROVIDER_RPC_RESPONSE";
|
|
6
|
-
IframeRpcProviderEvents["PROVIDER_ON_EVENT"] = "PROVIDER_ON_EVENT";
|
|
7
|
-
IframeRpcProviderEvents["SEND_PROVIDER_META_INFO"] = "SEND_PROVIDER_META_INFO";
|
|
8
|
-
IframeRpcProviderEvents["REQUEST_PROVIDER_META_INFO"] = "REQUEST_PROVIDER_META_INFO";
|
|
9
|
-
})(IframeRpcProviderEvents || (IframeRpcProviderEvents = {}));
|
|
10
|
-
export const iframeRpcProviderTransport = new IframeTransport('cowSwapIframeRpcProviderTransport');
|
|
11
|
-
//# sourceMappingURL=iframeRpcProviderEvents.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"iframeRpcProviderEvents.js","sourceRoot":"","sources":["../../../../../libs/iframe-transport/src/iframeRpcProvider/iframeRpcProviderEvents.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAA;AAqBpD,MAAM,CAAN,IAAY,uBAMX;AAND,WAAY,uBAAuB;IACjC,wEAA6C,CAAA;IAC7C,0EAA+C,CAAA;IAC/C,kEAAuC,CAAA;IACvC,8EAAmD,CAAA;IACnD,oFAAyD,CAAA;AAC3D,CAAC,EANW,uBAAuB,KAAvB,uBAAuB,QAMlC;AAUD,MAAM,CAAC,MAAM,0BAA0B,GAAG,IAAI,eAAe,CAC3D,mCAAmC,CACpC,CAAA"}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
// TODO: Replace any with proper type definitions
|
|
2
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
3
|
-
export function getProviderWcMetadata(provider) {
|
|
4
|
-
if (!provider.isWalletConnect)
|
|
5
|
-
return;
|
|
6
|
-
return provider?.session?.peer?.metadata;
|
|
7
|
-
}
|
|
8
|
-
export function getEip6963ProviderInfo(provider, eip6963Providers) {
|
|
9
|
-
return eip6963Providers.find((p) => p.provider === provider)?.info;
|
|
10
|
-
}
|
|
11
|
-
//# sourceMappingURL=utils.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../../../libs/iframe-transport/src/iframeRpcProvider/utils.ts"],"names":[],"mappings":"AAIA,iDAAiD;AACjD,8DAA8D;AAC9D,MAAM,UAAU,qBAAqB,CAAC,QAAa;IACjD,IAAI,CAAC,QAAQ,CAAC,eAAe;QAAE,OAAM;IAErC,OAAO,QAAQ,EAAE,OAAO,EAAE,IAAI,EAAE,QAAQ,CAAA;AAC1C,CAAC;AAED,MAAM,UAAU,sBAAsB,CACpC,QAAiB,EACjB,gBAAyC;IAEzC,OAAO,gBAAgB,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,QAAQ,KAAK,QAAQ,CAAC,EAAE,IAAI,CAAA;AACpE,CAAC"}
|
package/src/index.js
DELETED
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
export { IframeRpcProviderBridge } from './iframeRpcProvider/IframeRpcProviderBridge';
|
|
2
|
-
export { WidgetEthereumProvider } from './iframeRpcProvider/WidgetEthereumProvider';
|
|
3
|
-
export { IframeTransport } from './IframeTransport';
|
|
4
|
-
export * from './iframeRpcProvider/iframeRpcProviderEvents';
|
|
5
|
-
export * from './types';
|
|
6
|
-
//# sourceMappingURL=index.js.map
|
package/src/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../libs/iframe-transport/src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,uBAAuB,EAAE,MAAM,6CAA6C,CAAA;AACrF,OAAO,EAAE,sBAAsB,EAAE,MAAM,4CAA4C,CAAA;AACnF,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAA;AACnD,cAAc,6CAA6C,CAAA;AAC3D,cAAc,SAAS,CAAA"}
|
package/src/types.js
DELETED
package/src/types.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../libs/iframe-transport/src/types.ts"],"names":[],"mappings":""}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|