@asseteragmbh/wallet-connector 0.1.0
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/README.md +103 -0
- package/dist/chunk-L7EBYABA.js +129 -0
- package/dist/chunk-L7EBYABA.js.map +1 -0
- package/dist/chunk-N6D53D3G.js +63 -0
- package/dist/chunk-N6D53D3G.js.map +1 -0
- package/dist/chunk-QPNIGEP4.js +259 -0
- package/dist/chunk-QPNIGEP4.js.map +1 -0
- package/dist/index.cjs +332 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +2 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +4 -0
- package/dist/index.js.map +1 -0
- package/dist/protocol.cjs +76 -0
- package/dist/protocol.cjs.map +1 -0
- package/dist/protocol.d.cts +118 -0
- package/dist/protocol.d.ts +118 -0
- package/dist/protocol.js +3 -0
- package/dist/protocol.js.map +1 -0
- package/dist/provider-BEIsX3q_.d.cts +46 -0
- package/dist/provider-BEIsX3q_.d.ts +46 -0
- package/dist/rainbowkit.cjs +446 -0
- package/dist/rainbowkit.cjs.map +1 -0
- package/dist/rainbowkit.d.cts +30 -0
- package/dist/rainbowkit.d.ts +30 -0
- package/dist/rainbowkit.js +22 -0
- package/dist/rainbowkit.js.map +1 -0
- package/dist/wagmi.cjs +434 -0
- package/dist/wagmi.cjs.map +1 -0
- package/dist/wagmi.d.cts +23 -0
- package/dist/wagmi.d.ts +23 -0
- package/dist/wagmi.js +5 -0
- package/dist/wagmi.js.map +1 -0
- package/package.json +95 -0
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,332 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// src/protocol.ts
|
|
4
|
+
var PROTOCOL_VERSION = 1;
|
|
5
|
+
var CONNECT_PATH = "/connect";
|
|
6
|
+
var MESSAGE_PREFIX = "assetera-wallet:";
|
|
7
|
+
var SUPPORTED_METHODS = [
|
|
8
|
+
"eth_requestAccounts",
|
|
9
|
+
"eth_accounts",
|
|
10
|
+
"eth_chainId",
|
|
11
|
+
"wallet_switchEthereumChain",
|
|
12
|
+
"personal_sign",
|
|
13
|
+
"eth_signTypedData_v4",
|
|
14
|
+
"eth_sendTransaction"
|
|
15
|
+
];
|
|
16
|
+
function isSupportedMethod(method) {
|
|
17
|
+
return SUPPORTED_METHODS.includes(method);
|
|
18
|
+
}
|
|
19
|
+
var RpcErrorCode = {
|
|
20
|
+
/** The client rejected the request in the pop-up. */
|
|
21
|
+
UserRejected: 4001,
|
|
22
|
+
/** Not connected yet (no `eth_requestAccounts` approved in this pop-up). */
|
|
23
|
+
Unauthorized: 4100,
|
|
24
|
+
/** The method is not in SUPPORTED_METHODS. */
|
|
25
|
+
UnsupportedMethod: 4200,
|
|
26
|
+
/** The pop-up closed, or the wallet session ended. */
|
|
27
|
+
Disconnected: 4900,
|
|
28
|
+
/** `wallet_switchEthereumChain` to a chain the wallet does not offer. */
|
|
29
|
+
UnrecognizedChain: 4902,
|
|
30
|
+
/** Malformed params. */
|
|
31
|
+
InvalidParams: -32602,
|
|
32
|
+
/** Anything unexpected inside the wallet. */
|
|
33
|
+
Internal: -32603
|
|
34
|
+
};
|
|
35
|
+
function isRecord(value) {
|
|
36
|
+
return typeof value === "object" && value !== null;
|
|
37
|
+
}
|
|
38
|
+
function hasType(value, suffix) {
|
|
39
|
+
return isRecord(value) && value.type === `${MESSAGE_PREFIX}${suffix}` && value.v === PROTOCOL_VERSION;
|
|
40
|
+
}
|
|
41
|
+
function isReadyMessage(value) {
|
|
42
|
+
return hasType(value, "ready");
|
|
43
|
+
}
|
|
44
|
+
function isResponseMessage(value) {
|
|
45
|
+
return hasType(value, "response") && typeof value.id === "string" && ("result" in value || isRecord(value.error) && typeof value.error.code === "number");
|
|
46
|
+
}
|
|
47
|
+
function isEventMessage(value) {
|
|
48
|
+
return hasType(value, "event") && (value.event === "accountsChanged" || value.event === "chainChanged" || value.event === "disconnect");
|
|
49
|
+
}
|
|
50
|
+
function isRequestMessage(value) {
|
|
51
|
+
return hasType(value, "request") && typeof value.id === "string" && typeof value.method === "string";
|
|
52
|
+
}
|
|
53
|
+
function isDisconnectMessage(value) {
|
|
54
|
+
return hasType(value, "disconnect");
|
|
55
|
+
}
|
|
56
|
+
function connectUrl(walletUrl, partnerOrigin) {
|
|
57
|
+
const url = new URL(CONNECT_PATH, walletUrl);
|
|
58
|
+
url.searchParams.set("origin", partnerOrigin);
|
|
59
|
+
url.searchParams.set("v", String(PROTOCOL_VERSION));
|
|
60
|
+
return url.toString();
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
// src/provider.ts
|
|
64
|
+
var ProviderRpcError = class extends Error {
|
|
65
|
+
code;
|
|
66
|
+
data;
|
|
67
|
+
constructor(code, message, data) {
|
|
68
|
+
super(message);
|
|
69
|
+
this.name = "ProviderRpcError";
|
|
70
|
+
this.code = code;
|
|
71
|
+
this.data = data;
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
var DEFAULT_POPUP_FEATURES = "popup,width=420,height=720";
|
|
75
|
+
var POPUP_NAME = "assetera-wallet";
|
|
76
|
+
var CLOSE_POLL_MS = 500;
|
|
77
|
+
var SIGNING_METHODS = /* @__PURE__ */ new Set([
|
|
78
|
+
"personal_sign",
|
|
79
|
+
"eth_signTypedData_v4",
|
|
80
|
+
"eth_sendTransaction"
|
|
81
|
+
]);
|
|
82
|
+
function createDeferred() {
|
|
83
|
+
let resolve;
|
|
84
|
+
let reject;
|
|
85
|
+
const promise = new Promise((res, rej) => {
|
|
86
|
+
resolve = res;
|
|
87
|
+
reject = rej;
|
|
88
|
+
});
|
|
89
|
+
void promise.catch(() => {
|
|
90
|
+
});
|
|
91
|
+
return { promise, resolve, reject };
|
|
92
|
+
}
|
|
93
|
+
function toHexChainId(chainId) {
|
|
94
|
+
return `0x${chainId.toString(16)}`;
|
|
95
|
+
}
|
|
96
|
+
function createAsseteraWalletProvider(options) {
|
|
97
|
+
const { defaultChainId } = options;
|
|
98
|
+
const walletOrigin = new URL(options.walletUrl).origin;
|
|
99
|
+
const popupFeatures = options.popupFeatures ?? DEFAULT_POPUP_FEATURES;
|
|
100
|
+
let popup = null;
|
|
101
|
+
let ready = createDeferred();
|
|
102
|
+
let accounts = [];
|
|
103
|
+
let chainIdHex = null;
|
|
104
|
+
let walletDisconnected = false;
|
|
105
|
+
const pending = /* @__PURE__ */ new Map();
|
|
106
|
+
const listeners = /* @__PURE__ */ new Map();
|
|
107
|
+
let closeTimer = null;
|
|
108
|
+
function currentChainId() {
|
|
109
|
+
return chainIdHex ?? toHexChainId(defaultChainId);
|
|
110
|
+
}
|
|
111
|
+
function blockedError() {
|
|
112
|
+
return new ProviderRpcError(
|
|
113
|
+
RpcErrorCode.Disconnected,
|
|
114
|
+
"The Assetera Wallet pop-up was blocked by the browser. The pop-up must be opened from a user click (for example a button press) and then the request retried."
|
|
115
|
+
);
|
|
116
|
+
}
|
|
117
|
+
function disconnectedError(message = "The Assetera Wallet pop-up was closed.") {
|
|
118
|
+
return new ProviderRpcError(RpcErrorCode.Disconnected, message);
|
|
119
|
+
}
|
|
120
|
+
function emit(event, ...args) {
|
|
121
|
+
const set = listeners.get(event);
|
|
122
|
+
if (!set) return;
|
|
123
|
+
for (const listener of set) {
|
|
124
|
+
try {
|
|
125
|
+
listener(...args);
|
|
126
|
+
} catch (error) {
|
|
127
|
+
console.error(`[assetera-wallet] listener for "${event}" threw`, error);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
function addListener(event, listener) {
|
|
132
|
+
let set = listeners.get(event);
|
|
133
|
+
if (!set) {
|
|
134
|
+
set = /* @__PURE__ */ new Set();
|
|
135
|
+
listeners.set(event, set);
|
|
136
|
+
}
|
|
137
|
+
set.add(listener);
|
|
138
|
+
}
|
|
139
|
+
function removeEventListener(event, listener) {
|
|
140
|
+
listeners.get(event)?.delete(listener);
|
|
141
|
+
}
|
|
142
|
+
function stopClosePolling() {
|
|
143
|
+
if (closeTimer !== null) {
|
|
144
|
+
clearInterval(closeTimer);
|
|
145
|
+
closeTimer = null;
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
function startClosePolling() {
|
|
149
|
+
if (closeTimer !== null) return;
|
|
150
|
+
closeTimer = setInterval(() => {
|
|
151
|
+
if (popup?.closed) handlePopupClosed();
|
|
152
|
+
}, CLOSE_POLL_MS);
|
|
153
|
+
}
|
|
154
|
+
function rejectAllPending(error) {
|
|
155
|
+
for (const request2 of pending.values()) request2.reject(error);
|
|
156
|
+
pending.clear();
|
|
157
|
+
}
|
|
158
|
+
function handlePopupClosed() {
|
|
159
|
+
const hadPending = pending.size > 0;
|
|
160
|
+
stopClosePolling();
|
|
161
|
+
const closedPopup = popup;
|
|
162
|
+
popup = null;
|
|
163
|
+
const closedReady = ready;
|
|
164
|
+
ready = createDeferred();
|
|
165
|
+
const error = disconnectedError();
|
|
166
|
+
if (closedPopup) closedReady.reject(error);
|
|
167
|
+
rejectAllPending(error);
|
|
168
|
+
const shouldEmit = hadPending || walletDisconnected;
|
|
169
|
+
walletDisconnected = false;
|
|
170
|
+
if (shouldEmit) emit("disconnect", error);
|
|
171
|
+
}
|
|
172
|
+
function openPopup() {
|
|
173
|
+
if (popup && !popup.closed) {
|
|
174
|
+
popup.focus();
|
|
175
|
+
return popup;
|
|
176
|
+
}
|
|
177
|
+
if (typeof window === "undefined") return null;
|
|
178
|
+
const opened = window.open(
|
|
179
|
+
connectUrl(options.walletUrl, window.location.origin),
|
|
180
|
+
POPUP_NAME,
|
|
181
|
+
popupFeatures
|
|
182
|
+
);
|
|
183
|
+
if (!opened) return null;
|
|
184
|
+
popup = opened;
|
|
185
|
+
ready = createDeferred();
|
|
186
|
+
walletDisconnected = false;
|
|
187
|
+
startClosePolling();
|
|
188
|
+
return opened;
|
|
189
|
+
}
|
|
190
|
+
function sendRequest(method, params) {
|
|
191
|
+
const active = popup;
|
|
192
|
+
if (!active || active.closed) return Promise.reject(disconnectedError());
|
|
193
|
+
const id = crypto.randomUUID();
|
|
194
|
+
const message = {
|
|
195
|
+
type: `${MESSAGE_PREFIX}request`,
|
|
196
|
+
v: PROTOCOL_VERSION,
|
|
197
|
+
id,
|
|
198
|
+
method,
|
|
199
|
+
...params === void 0 ? {} : { params }
|
|
200
|
+
};
|
|
201
|
+
return new Promise((resolve, reject) => {
|
|
202
|
+
pending.set(id, { resolve, reject });
|
|
203
|
+
active.postMessage(message, walletOrigin);
|
|
204
|
+
});
|
|
205
|
+
}
|
|
206
|
+
function handleResponse(message) {
|
|
207
|
+
const request2 = pending.get(message.id);
|
|
208
|
+
if (!request2) return;
|
|
209
|
+
pending.delete(message.id);
|
|
210
|
+
if ("error" in message) {
|
|
211
|
+
request2.reject(new ProviderRpcError(message.error.code, message.error.message, message.error.data));
|
|
212
|
+
} else {
|
|
213
|
+
request2.resolve(message.result);
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
function handleEventMessage(message) {
|
|
217
|
+
if (message.event === "accountsChanged") {
|
|
218
|
+
accounts = [...message.data];
|
|
219
|
+
emit("accountsChanged", [...accounts]);
|
|
220
|
+
return;
|
|
221
|
+
}
|
|
222
|
+
if (message.event === "chainChanged") {
|
|
223
|
+
chainIdHex = message.data;
|
|
224
|
+
emit("chainChanged", chainIdHex);
|
|
225
|
+
return;
|
|
226
|
+
}
|
|
227
|
+
walletDisconnected = true;
|
|
228
|
+
emit("disconnect", new ProviderRpcError(message.data.code, message.data.message, message.data.data));
|
|
229
|
+
}
|
|
230
|
+
function onWindowMessage(event) {
|
|
231
|
+
if (event.origin !== walletOrigin) return;
|
|
232
|
+
if (popup === null || event.source !== popup) return;
|
|
233
|
+
const data = event.data;
|
|
234
|
+
if (isReadyMessage(data)) {
|
|
235
|
+
ready.resolve(void 0);
|
|
236
|
+
return;
|
|
237
|
+
}
|
|
238
|
+
if (isResponseMessage(data)) {
|
|
239
|
+
handleResponse(data);
|
|
240
|
+
return;
|
|
241
|
+
}
|
|
242
|
+
if (isEventMessage(data)) handleEventMessage(data);
|
|
243
|
+
}
|
|
244
|
+
if (typeof window !== "undefined") window.addEventListener("message", onWindowMessage);
|
|
245
|
+
function request({ method, params }) {
|
|
246
|
+
if (typeof window === "undefined") {
|
|
247
|
+
return Promise.reject(
|
|
248
|
+
new ProviderRpcError(
|
|
249
|
+
RpcErrorCode.Disconnected,
|
|
250
|
+
"The Assetera Wallet provider can only run in a browser."
|
|
251
|
+
)
|
|
252
|
+
);
|
|
253
|
+
}
|
|
254
|
+
if (!isSupportedMethod(method)) {
|
|
255
|
+
return Promise.reject(
|
|
256
|
+
new ProviderRpcError(
|
|
257
|
+
RpcErrorCode.UnsupportedMethod,
|
|
258
|
+
`The Assetera Wallet pop-up does not support the method "${method}".`
|
|
259
|
+
)
|
|
260
|
+
);
|
|
261
|
+
}
|
|
262
|
+
if (method === "eth_accounts") return Promise.resolve([...accounts]);
|
|
263
|
+
if (method === "eth_chainId") return Promise.resolve(currentChainId());
|
|
264
|
+
if (method === "eth_requestAccounts") {
|
|
265
|
+
const active2 = openPopup();
|
|
266
|
+
if (!active2) return Promise.reject(blockedError());
|
|
267
|
+
return ready.promise.then(() => sendRequest("eth_requestAccounts", params)).then((result) => {
|
|
268
|
+
accounts = Array.isArray(result) ? result : [];
|
|
269
|
+
emit("accountsChanged", [...accounts]);
|
|
270
|
+
emit("connect", { chainId: currentChainId() });
|
|
271
|
+
return [...accounts];
|
|
272
|
+
});
|
|
273
|
+
}
|
|
274
|
+
if (accounts.length === 0) {
|
|
275
|
+
return Promise.reject(
|
|
276
|
+
new ProviderRpcError(
|
|
277
|
+
RpcErrorCode.Unauthorized,
|
|
278
|
+
"Connect to the Assetera Wallet first (eth_requestAccounts)."
|
|
279
|
+
)
|
|
280
|
+
);
|
|
281
|
+
}
|
|
282
|
+
const active = openPopup();
|
|
283
|
+
if (!active) return Promise.reject(blockedError());
|
|
284
|
+
if (SIGNING_METHODS.has(method)) active.focus();
|
|
285
|
+
return ready.promise.then(() => sendRequest(method, params));
|
|
286
|
+
}
|
|
287
|
+
function disconnect() {
|
|
288
|
+
const active = popup;
|
|
289
|
+
if (active && !active.closed) {
|
|
290
|
+
const message = {
|
|
291
|
+
type: `${MESSAGE_PREFIX}disconnect`,
|
|
292
|
+
v: PROTOCOL_VERSION
|
|
293
|
+
};
|
|
294
|
+
active.postMessage(message, walletOrigin);
|
|
295
|
+
active.close();
|
|
296
|
+
}
|
|
297
|
+
stopClosePolling();
|
|
298
|
+
popup = null;
|
|
299
|
+
const closedReady = ready;
|
|
300
|
+
ready = createDeferred();
|
|
301
|
+
closedReady.reject(disconnectedError("Disconnected from the Assetera Wallet."));
|
|
302
|
+
rejectAllPending(disconnectedError("Disconnected from the Assetera Wallet."));
|
|
303
|
+
accounts = [];
|
|
304
|
+
chainIdHex = null;
|
|
305
|
+
walletDisconnected = false;
|
|
306
|
+
emit("disconnect", disconnectedError("Disconnected from the Assetera Wallet."));
|
|
307
|
+
}
|
|
308
|
+
function on(event, listener) {
|
|
309
|
+
addListener(event, listener);
|
|
310
|
+
}
|
|
311
|
+
function removeListener(event, listener) {
|
|
312
|
+
removeEventListener(event, listener);
|
|
313
|
+
}
|
|
314
|
+
return { request, on, removeListener, disconnect };
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
exports.CONNECT_PATH = CONNECT_PATH;
|
|
318
|
+
exports.MESSAGE_PREFIX = MESSAGE_PREFIX;
|
|
319
|
+
exports.PROTOCOL_VERSION = PROTOCOL_VERSION;
|
|
320
|
+
exports.ProviderRpcError = ProviderRpcError;
|
|
321
|
+
exports.RpcErrorCode = RpcErrorCode;
|
|
322
|
+
exports.SUPPORTED_METHODS = SUPPORTED_METHODS;
|
|
323
|
+
exports.connectUrl = connectUrl;
|
|
324
|
+
exports.createAsseteraWalletProvider = createAsseteraWalletProvider;
|
|
325
|
+
exports.isDisconnectMessage = isDisconnectMessage;
|
|
326
|
+
exports.isEventMessage = isEventMessage;
|
|
327
|
+
exports.isReadyMessage = isReadyMessage;
|
|
328
|
+
exports.isRequestMessage = isRequestMessage;
|
|
329
|
+
exports.isResponseMessage = isResponseMessage;
|
|
330
|
+
exports.isSupportedMethod = isSupportedMethod;
|
|
331
|
+
//# sourceMappingURL=index.cjs.map
|
|
332
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/protocol.ts","../src/provider.ts"],"names":["request","active"],"mappings":";;;AAwBO,IAAM,gBAAA,GAAmB;AAGzB,IAAM,YAAA,GAAe;AAGrB,IAAM,cAAA,GAAiB;AAMvB,IAAM,iBAAA,GAAoB;AAAA,EAC/B,qBAAA;AAAA,EACA,cAAA;AAAA,EACA,aAAA;AAAA,EACA,4BAAA;AAAA,EACA,eAAA;AAAA,EACA,sBAAA;AAAA,EACA;AACF;AAIO,SAAS,kBAAkB,MAAA,EAA2C;AAC3E,EAAA,OAAQ,iBAAA,CAAwC,SAAS,MAAM,CAAA;AACjE;AAGO,IAAM,YAAA,GAAe;AAAA;AAAA,EAE1B,YAAA,EAAc,IAAA;AAAA;AAAA,EAEd,YAAA,EAAc,IAAA;AAAA;AAAA,EAEd,iBAAA,EAAmB,IAAA;AAAA;AAAA,EAEnB,YAAA,EAAc,IAAA;AAAA;AAAA,EAEd,iBAAA,EAAmB,IAAA;AAAA;AAAA,EAEnB,aAAA,EAAe,MAAA;AAAA;AAAA,EAEf,QAAA,EAAU;AACZ;AAqEA,SAAS,SAAS,KAAA,EAAkD;AAClE,EAAA,OAAO,OAAO,KAAA,KAAU,QAAA,IAAY,KAAA,KAAU,IAAA;AAChD;AAEA,SAAS,OAAA,CAAQ,OAAgB,MAAA,EAAkD;AACjF,EAAA,OAAO,QAAA,CAAS,KAAK,CAAA,IAAK,KAAA,CAAM,IAAA,KAAS,CAAA,EAAG,cAAc,CAAA,EAAG,MAAM,CAAA,CAAA,IAAM,KAAA,CAAM,CAAA,KAAM,gBAAA;AACvF;AAEO,SAAS,eAAe,KAAA,EAAuC;AACpE,EAAA,OA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,MAAA,EAAQ;AAC5B,MAAA,MAAM,OAAA,GAA6B;AAAA,QACjC,IAAA,EAAM,GAAG,cAAc,CAAA,UAAA,CAAA;AAAA,QACvB,CAAA,EAAG;AAAA,OACL;AACA,MAAA,MAAA,CAAO,WAAA,CAAY,SAAS,YAAY,CAAA;AACxC,MAAA,MAAA,CAAO,KAAA,EAAM;AAAA,IACf;AACA,IAAA,gBAAA,EAAiB;AACjB,IAAA,KAAA,GAAQ,IAAA;AACR,IAAA,MAAM,WAAA,GAAc,KAAA;AACpB,IAAA,KAAA,GAAQ,cAAA,EAAqB;AAC7B,IAAA,WAAA,CAAY,MAAA,CAAO,iBAAA,CAAkB,wCAAwC,CAAC,CAAA;AAC9E,IAAA,gBAAA,CAAiB,iBAAA,CAAkB,wCAAwC,CAAC,CAAA;AAC5E,IAAA,QAAA,GAAW,EAAC;AACZ,IAAA,UAAA,GAAa,IAAA;AACb,IAAA,kBAAA,GAAqB,KAAA;AACrB,IAAA,IAAA,CAAK,YAAA,EAAc,iBAAA,CAAkB,wCAAwC,CAAC,CAAA;AAAA,EAChF;AAEA,EAAA,SAAS,EAAA,CAAG,OAAsB,QAAA,EAAkC;AAClE,IAAA,WAAA,CAAY,OAAO,QAAQ,CAAA;AAAA,EAC7B;AAEA,EAAA,SAAS,cAAA,CAAe,OAAsB,QAAA,EAAkC;AAC9E,IAAA,mBAAA,CAAoB,OAAO,QAAQ,CAAA;AAAA,EACrC;AAEA,EAAA,OAAO,EAAE,OAAA,EAAS,EAAA,EAAI,cAAA,EAAgB,UAAA,EAAW;AACnD","file":"index.cjs","sourcesContent":["/**\n * The pop-up protocol between a partner page (the opener) and the Assetera Wallet (the pop-up) — ADR-0054 D3/D4.\n *\n * This file is the CONTRACT. The connector in this package speaks the opener side; AsseteraWalletFront's\n * `/connect` page speaks the pop-up side and imports these types from `@asseteragmbh/wallet-connector/protocol`.\n * Change it only in a backwards-compatible way, or bump `PROTOCOL_VERSION` and support both on the wallet side:\n * partner sites upgrade on their own schedule.\n *\n * ## The handshake\n *\n * 1. The partner opens `${walletUrl}${CONNECT_PATH}?origin=<partner origin>&v=<version>` from a user click.\n * 2. The pop-up checks the claimed origin against its allowlist (D4). If listed, it posts `ready` to\n * `window.opener` with `targetOrigin` = that origin. The browser delivers it ONLY if the opener really is\n * that origin, so a page cannot claim someone else's origin and still hear the answer.\n * 3. The opener waits for `ready` from the wallet origin, then sends `request`s with `targetOrigin` = the wallet\n * origin. The pop-up accepts a message only when `event.origin` is the allowed origin from step 2 AND\n * `event.source === window.opener`, and answers with `targetOrigin` = that origin. Nothing else is accepted.\n *\n * ## Lifetime\n *\n * The pop-up stays open while the partner uses the wallet (ADR-0054, \"the wallet tab must stay open\"). When it is\n * closed, the opener sees `disconnect` (or notices `popup.closed`) and must reconnect from a user click.\n */\n\nexport const PROTOCOL_VERSION = 1 as const;\n\n/** The pop-up route on the wallet origin. */\nexport const CONNECT_PATH = \"/connect\";\n\n/** Every message carries this prefix in `type`, so both sides can ignore unrelated `postMessage` traffic. */\nexport const MESSAGE_PREFIX = \"assetera-wallet:\" as const;\n\n/**\n * The EIP-1193 methods the pop-up answers (ADR-0054 D3). Anything else is refused with 4200. Read-only chain\n * calls (`eth_call`, `eth_getBalance`, …) do not go through the pop-up; wagmi sends them to its own transports.\n */\nexport const SUPPORTED_METHODS = [\n \"eth_requestAccounts\",\n \"eth_accounts\",\n \"eth_chainId\",\n \"wallet_switchEthereumChain\",\n \"personal_sign\",\n \"eth_signTypedData_v4\",\n \"eth_sendTransaction\",\n] as const;\n\nexport type SupportedMethod = (typeof SUPPORTED_METHODS)[number];\n\nexport function isSupportedMethod(method: string): method is SupportedMethod {\n return (SUPPORTED_METHODS as readonly string[]).includes(method);\n}\n\n/** EIP-1193 / EIP-1474 error codes the pop-up uses. */\nexport const RpcErrorCode = {\n /** The client rejected the request in the pop-up. */\n UserRejected: 4001,\n /** Not connected yet (no `eth_requestAccounts` approved in this pop-up). */\n Unauthorized: 4100,\n /** The method is not in SUPPORTED_METHODS. */\n UnsupportedMethod: 4200,\n /** The pop-up closed, or the wallet session ended. */\n Disconnected: 4900,\n /** `wallet_switchEthereumChain` to a chain the wallet does not offer. */\n UnrecognizedChain: 4902,\n /** Malformed params. */\n InvalidParams: -32602,\n /** Anything unexpected inside the wallet. */\n Internal: -32603,\n} as const;\n\nexport type RpcErrorCode = (typeof RpcErrorCode)[keyof typeof RpcErrorCode];\n\nexport interface RpcError {\n code: number;\n message: string;\n data?: unknown;\n}\n\n// --- pop-up → opener ---------------------------------------------------------------------------------\n\n/** The pop-up is loaded and accepts requests from this opener. */\nexport interface ReadyMessage {\n type: `${typeof MESSAGE_PREFIX}ready`;\n v: typeof PROTOCOL_VERSION;\n /** Shown to the partner for diagnostics only; the partner must not rely on it for anything. */\n walletVersion?: string;\n}\n\n/** The answer to one `request`, matched by `id`. Exactly one of `result` / `error`. */\nexport type ResponseMessage =\n | { type: `${typeof MESSAGE_PREFIX}response`; v: typeof PROTOCOL_VERSION; id: string; result: unknown }\n | { type: `${typeof MESSAGE_PREFIX}response`; v: typeof PROTOCOL_VERSION; id: string; error: RpcError };\n\n/** EIP-1193 provider events, forwarded to the partner. */\nexport type EventMessage =\n | {\n type: `${typeof MESSAGE_PREFIX}event`;\n v: typeof PROTOCOL_VERSION;\n event: \"accountsChanged\";\n data: `0x${string}`[];\n }\n | {\n type: `${typeof MESSAGE_PREFIX}event`;\n v: typeof PROTOCOL_VERSION;\n event: \"chainChanged\";\n data: `0x${string}`;\n }\n | {\n type: `${typeof MESSAGE_PREFIX}event`;\n v: typeof PROTOCOL_VERSION;\n event: \"disconnect\";\n data: RpcError;\n };\n\nexport type WalletToPartnerMessage = ReadyMessage | ResponseMessage | EventMessage;\n\n// --- opener → pop-up ---------------------------------------------------------------------------------\n\nexport interface RequestMessage {\n type: `${typeof MESSAGE_PREFIX}request`;\n v: typeof PROTOCOL_VERSION;\n /** Unique per request within one connection; the response carries it back. */\n id: string;\n method: string;\n params?: unknown[] | Record<string, unknown>;\n}\n\n/** The partner disconnects (for example the user clicked \"Disconnect\" in the partner page). */\nexport interface DisconnectMessage {\n type: `${typeof MESSAGE_PREFIX}disconnect`;\n v: typeof PROTOCOL_VERSION;\n}\n\nexport type PartnerToWalletMessage = RequestMessage | DisconnectMessage;\n\n// --- guards ------------------------------------------------------------------------------------------\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n return typeof value === \"object\" && value !== null;\n}\n\nfunction hasType(value: unknown, suffix: string): value is Record<string, unknown> {\n return isRecord(value) && value.type === `${MESSAGE_PREFIX}${suffix}` && value.v === PROTOCOL_VERSION;\n}\n\nexport function isReadyMessage(value: unknown): value is ReadyMessage {\n return hasType(value, \"ready\");\n}\n\nexport function isResponseMessage(value: unknown): value is ResponseMessage {\n return (\n hasType(value, \"response\") &&\n typeof value.id === \"string\" &&\n (\"result\" in value || (isRecord(value.error) && typeof value.error.code === \"number\"))\n );\n}\n\nexport function isEventMessage(value: unknown): value is EventMessage {\n return (\n hasType(value, \"event\") &&\n (value.event === \"accountsChanged\" || value.event === \"chainChanged\" || value.event === \"disconnect\")\n );\n}\n\nexport function isRequestMessage(value: unknown): value is RequestMessage {\n return hasType(value, \"request\") && typeof value.id === \"string\" && typeof value.method === \"string\";\n}\n\nexport function isDisconnectMessage(value: unknown): value is DisconnectMessage {\n return hasType(value, \"disconnect\");\n}\n\n/** The URL the partner opens. `partnerOrigin` is `window.location.origin` of the partner page. */\nexport function connectUrl(walletUrl: string, partnerOrigin: string): string {\n const url = new URL(CONNECT_PATH, walletUrl);\n url.searchParams.set(\"origin\", partnerOrigin);\n url.searchParams.set(\"v\", String(PROTOCOL_VERSION));\n return url.toString();\n}\n","/**\n * EIP-1193 provider for the Assetera Wallet pop-up — the opener side of the ADR-0054 D3/D4 protocol.\n *\n * The provider owns a single pop-up (`window.open(connectUrl(...), \"assetera-wallet\", ...)`) and speaks the\n * wire format defined in `./protocol`. It never touches Dynamic, React, wagmi or viem, so a partner can use it\n * on its own or through the wagmi / RainbowKit adapters in this package.\n */\nimport {\n MESSAGE_PREFIX,\n PROTOCOL_VERSION,\n RpcErrorCode,\n connectUrl,\n isEventMessage,\n isReadyMessage,\n isResponseMessage,\n isSupportedMethod,\n type DisconnectMessage,\n type EventMessage,\n type RequestMessage,\n type ResponseMessage,\n} from \"./protocol\";\n\n/** Arguments accepted by `request`, mirroring EIP-1193. */\nexport interface RequestArguments {\n method: string;\n params?: unknown[] | Record<string, unknown>;\n}\n\n/** EIP-1193 provider events emitted by the pop-up. */\nexport type ProviderEvent = \"accountsChanged\" | \"chainChanged\" | \"connect\" | \"disconnect\";\n\n/**\n * Listener shape for EIP-1193 provider events. `never[]` accepts a listener with any concrete parameter list\n * (for example wagmi's `(accounts: string[]) => void`), while internal emission stays type-safe via a cast.\n */\nexport type ProviderListener = (...args: never[]) => void;\n\n/** The EIP-1193 surface returned by {@link createAsseteraWalletProvider}. */\nexport interface AsseteraWalletProvider {\n request(args: RequestArguments): Promise<unknown>;\n on(event: ProviderEvent, listener: ProviderListener): void;\n removeListener(event: ProviderEvent, listener: ProviderListener): void;\n disconnect(): void;\n}\n\n/** Options for {@link createAsseteraWalletProvider}. */\nexport interface AsseteraWalletProviderOptions {\n /** Base URL of the wallet origin, e.g. `https://wallet.playground.assetera.com`. */\n walletUrl: string;\n /** Chain id used before the wallet reports one, and as the local `eth_chainId` fallback. */\n defaultChainId: number;\n /** `window.open` feature string. Defaults to `\"popup,width=420,height=720\"`. */\n popupFeatures?: string;\n}\n\n/**\n * EIP-1193 error carrying a JSON-RPC `code` (and optional `data`). This is what every rejected `request`\n * throws, so wagmi maps the wallet's `4001` / `4100` / `4200` / `4900` correctly.\n */\nexport class ProviderRpcError extends Error {\n readonly code: number;\n readonly data?: unknown;\n\n constructor(code: number, message: string, data?: unknown) {\n super(message);\n this.name = \"ProviderRpcError\";\n this.code = code;\n this.data = data;\n }\n}\n\nconst DEFAULT_POPUP_FEATURES = \"popup,width=420,height=720\";\nconst POPUP_NAME = \"assetera-wallet\";\nconst CLOSE_POLL_MS = 500;\n\n/** Methods that show the user a signature / transaction prompt, so the pop-up should be focused first. */\nconst SIGNING_METHODS: ReadonlySet<string> = new Set([\n \"personal_sign\",\n \"eth_signTypedData_v4\",\n \"eth_sendTransaction\",\n]);\n\ninterface PendingRequest {\n resolve: (value: unknown) => void;\n reject: (reason: unknown) => void;\n}\n\ninterface Deferred<T> {\n promise: Promise<T>;\n resolve: (value: T) => void;\n reject: (reason: unknown) => void;\n}\n\nfunction createDeferred<T>(): Deferred<T> {\n let resolve!: (value: T) => void;\n let reject!: (reason: unknown) => void;\n const promise = new Promise<T>((res, rej) => {\n resolve = res;\n reject = rej;\n });\n // The `ready` deferred is rejected when the pop-up closes even if no request is waiting on it; mark the\n // promise as handled so that rejection is not reported as an unhandled promise rejection.\n void promise.catch(() => {});\n return { promise, resolve, reject };\n}\n\nfunction toHexChainId(chainId: number): string {\n return `0x${chainId.toString(16)}`;\n}\n\n/**\n * Create the EIP-1193 provider that talks to the Assetera Wallet pop-up.\n *\n * Call `request` from a user gesture: `eth_requestAccounts` opens the pop-up synchronously (before any\n * `await`) so the browser treats it as part of the click and does not block it.\n */\nexport function createAsseteraWalletProvider(options: AsseteraWalletProviderOptions): AsseteraWalletProvider {\n const { defaultChainId } = options;\n const walletOrigin = new URL(options.walletUrl).origin;\n const popupFeatures = options.popupFeatures ?? DEFAULT_POPUP_FEATURES;\n\n let popup: Window | null = null;\n /** Resolves when the *current* pop-up posts `ready`. Replaced when a new pop-up is opened. */\n let ready = createDeferred<void>();\n let accounts: string[] = [];\n let chainIdHex: string | null = null;\n /** Set when the wallet itself told us the session ended (as opposed to the user merely closing the tab). */\n let walletDisconnected = false;\n const pending = new Map<string, PendingRequest>();\n const listeners = new Map<ProviderEvent, Set<(...args: unknown[]) => void>>();\n let closeTimer: ReturnType<typeof setInterval> | null = null;\n\n function currentChainId(): string {\n return chainIdHex ?? toHexChainId(defaultChainId);\n }\n\n function blockedError(): ProviderRpcError {\n return new ProviderRpcError(\n RpcErrorCode.Disconnected,\n \"The Assetera Wallet pop-up was blocked by the browser. The pop-up must be opened from a user click \" +\n \"(for example a button press) and then the request retried.\",\n );\n }\n\n function disconnectedError(message = \"The Assetera Wallet pop-up was closed.\"): ProviderRpcError {\n return new ProviderRpcError(RpcErrorCode.Disconnected, message);\n }\n\n function emit(event: ProviderEvent, ...args: unknown[]): void {\n const set = listeners.get(event);\n if (!set) return;\n for (const listener of set) {\n try {\n listener(...args);\n } catch (error) {\n console.error(`[assetera-wallet] listener for \"${event}\" threw`, error);\n }\n }\n }\n\n function addListener(event: ProviderEvent, listener: ProviderListener): void {\n let set = listeners.get(event);\n if (!set) {\n set = new Set<(...args: unknown[]) => void>();\n listeners.set(event, set);\n }\n set.add(listener as (...args: unknown[]) => void);\n }\n\n function removeEventListener(event: ProviderEvent, listener: ProviderListener): void {\n listeners.get(event)?.delete(listener as (...args: unknown[]) => void);\n }\n\n function stopClosePolling(): void {\n if (closeTimer !== null) {\n clearInterval(closeTimer);\n closeTimer = null;\n }\n }\n\n function startClosePolling(): void {\n if (closeTimer !== null) return;\n closeTimer = setInterval(() => {\n if (popup?.closed) handlePopupClosed();\n }, CLOSE_POLL_MS);\n }\n\n function rejectAllPending(error: ProviderRpcError): void {\n for (const request of pending.values()) request.reject(error);\n pending.clear();\n }\n\n /**\n * The pop-up was closed by the user (or the wallet app).\n *\n * We deliberately KEEP `accounts` / `chainIdHex` cached: the dApp stays \"connected\" in React state and does\n * not flicker back to a disconnected UI. Because a pop-up cannot be reopened without a user gesture, the next\n * signing request reopens it from the caller's click. `disconnect` is only emitted when the close actually\n * interrupted work (a request was pending) or when the wallet itself announced the disconnect.\n */\n function handlePopupClosed(): void {\n const hadPending = pending.size > 0;\n stopClosePolling();\n const closedPopup = popup;\n popup = null;\n const closedReady = ready;\n ready = createDeferred<void>();\n const error = disconnectedError();\n if (closedPopup) closedReady.reject(error);\n rejectAllPending(error);\n const shouldEmit = hadPending || walletDisconnected;\n walletDisconnected = false;\n if (shouldEmit) emit(\"disconnect\", error);\n }\n\n /**\n * Open the pop-up, or focus and reuse it when it is still around. Must stay synchronous (it is called before\n * any `await` in `request`) so it runs inside the caller's user activation.\n */\n function openPopup(): Window | null {\n if (popup && !popup.closed) {\n popup.focus();\n return popup;\n }\n if (typeof window === \"undefined\") return null;\n const opened = window.open(\n connectUrl(options.walletUrl, window.location.origin),\n POPUP_NAME,\n popupFeatures,\n );\n if (!opened) return null;\n popup = opened;\n ready = createDeferred<void>();\n walletDisconnected = false;\n startClosePolling();\n return opened;\n }\n\n function sendRequest(method: string, params?: RequestArguments[\"params\"]): Promise<unknown> {\n const active = popup;\n if (!active || active.closed) return Promise.reject(disconnectedError());\n const id = crypto.randomUUID();\n const message: RequestMessage = {\n type: `${MESSAGE_PREFIX}request`,\n v: PROTOCOL_VERSION,\n id,\n method,\n ...(params === undefined ? {} : { params }),\n };\n return new Promise<unknown>((resolve, reject) => {\n pending.set(id, { resolve, reject });\n active.postMessage(message, walletOrigin);\n });\n }\n\n function handleResponse(message: ResponseMessage): void {\n const request = pending.get(message.id);\n if (!request) return;\n pending.delete(message.id);\n if (\"error\" in message) {\n request.reject(new ProviderRpcError(message.error.code, message.error.message, message.error.data));\n } else {\n request.resolve(message.result);\n }\n }\n\n function handleEventMessage(message: EventMessage): void {\n if (message.event === \"accountsChanged\") {\n accounts = [...message.data];\n emit(\"accountsChanged\", [...accounts]);\n return;\n }\n if (message.event === \"chainChanged\") {\n chainIdHex = message.data;\n emit(\"chainChanged\", chainIdHex);\n return;\n }\n walletDisconnected = true;\n emit(\"disconnect\", new ProviderRpcError(message.data.code, message.data.message, message.data.data));\n }\n\n function onWindowMessage(event: MessageEvent): void {\n if (event.origin !== walletOrigin) return;\n if (popup === null || (event.source as unknown) !== popup) return;\n const data: unknown = event.data;\n if (isReadyMessage(data)) {\n ready.resolve(undefined);\n return;\n }\n if (isResponseMessage(data)) {\n handleResponse(data);\n return;\n }\n if (isEventMessage(data)) handleEventMessage(data);\n }\n\n if (typeof window !== \"undefined\") window.addEventListener(\"message\", onWindowMessage);\n\n function request({ method, params }: RequestArguments): Promise<unknown> {\n if (typeof window === \"undefined\") {\n return Promise.reject(\n new ProviderRpcError(\n RpcErrorCode.Disconnected,\n \"The Assetera Wallet provider can only run in a browser.\",\n ),\n );\n }\n // Read-only chain calls go through wagmi's own transports; the pop-up refuses everything else.\n if (!isSupportedMethod(method)) {\n return Promise.reject(\n new ProviderRpcError(\n RpcErrorCode.UnsupportedMethod,\n `The Assetera Wallet pop-up does not support the method \"${method}\".`,\n ),\n );\n }\n // Answered locally, without a pop-up, so wagmi can read the connection before the user clicks.\n if (method === \"eth_accounts\") return Promise.resolve([...accounts]);\n if (method === \"eth_chainId\") return Promise.resolve(currentChainId());\n\n // Opening the pop-up MUST happen synchronously, before the first `await`, to stay in the click.\n if (method === \"eth_requestAccounts\") {\n const active = openPopup();\n if (!active) return Promise.reject(blockedError());\n return ready.promise\n .then(() => sendRequest(\"eth_requestAccounts\", params))\n .then((result) => {\n accounts = Array.isArray(result) ? (result as string[]) : [];\n emit(\"accountsChanged\", [...accounts]);\n emit(\"connect\", { chainId: currentChainId() });\n return [...accounts];\n });\n }\n\n // Every other supported method needs an approved connection.\n if (accounts.length === 0) {\n return Promise.reject(\n new ProviderRpcError(\n RpcErrorCode.Unauthorized,\n \"Connect to the Assetera Wallet first (eth_requestAccounts).\",\n ),\n );\n }\n const active = openPopup();\n if (!active) return Promise.reject(blockedError());\n if (SIGNING_METHODS.has(method)) active.focus();\n return ready.promise.then(() => sendRequest(method, params));\n }\n\n function disconnect(): void {\n const active = popup;\n if (active && !active.closed) {\n const message: DisconnectMessage = {\n type: `${MESSAGE_PREFIX}disconnect`,\n v: PROTOCOL_VERSION,\n };\n active.postMessage(message, walletOrigin);\n active.close();\n }\n stopClosePolling();\n popup = null;\n const closedReady = ready;\n ready = createDeferred<void>();\n closedReady.reject(disconnectedError(\"Disconnected from the Assetera Wallet.\"));\n rejectAllPending(disconnectedError(\"Disconnected from the Assetera Wallet.\"));\n accounts = [];\n chainIdHex = null;\n walletDisconnected = false;\n emit(\"disconnect\", disconnectedError(\"Disconnected from the Assetera Wallet.\"));\n }\n\n function on(event: ProviderEvent, listener: ProviderListener): void {\n addListener(event, listener);\n }\n\n function removeListener(event: ProviderEvent, listener: ProviderListener): void {\n removeEventListener(event, listener);\n }\n\n return { request, on, removeListener, disconnect };\n}\n"]}
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
export { CONNECT_PATH, DisconnectMessage, EventMessage, MESSAGE_PREFIX, PROTOCOL_VERSION, PartnerToWalletMessage, ReadyMessage, RequestMessage, ResponseMessage, RpcError, RpcErrorCode, SUPPORTED_METHODS, SupportedMethod, WalletToPartnerMessage, connectUrl, isDisconnectMessage, isEventMessage, isReadyMessage, isRequestMessage, isResponseMessage, isSupportedMethod } from './protocol.cjs';
|
|
2
|
+
export { A as AsseteraWalletProvider, a as AsseteraWalletProviderOptions, P as ProviderEvent, b as ProviderListener, c as ProviderRpcError, R as RequestArguments, d as createAsseteraWalletProvider } from './provider-BEIsX3q_.cjs';
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
export { CONNECT_PATH, DisconnectMessage, EventMessage, MESSAGE_PREFIX, PROTOCOL_VERSION, PartnerToWalletMessage, ReadyMessage, RequestMessage, ResponseMessage, RpcError, RpcErrorCode, SUPPORTED_METHODS, SupportedMethod, WalletToPartnerMessage, connectUrl, isDisconnectMessage, isEventMessage, isReadyMessage, isRequestMessage, isResponseMessage, isSupportedMethod } from './protocol.js';
|
|
2
|
+
export { A as AsseteraWalletProvider, a as AsseteraWalletProviderOptions, P as ProviderEvent, b as ProviderListener, c as ProviderRpcError, R as RequestArguments, d as createAsseteraWalletProvider } from './provider-BEIsX3q_.js';
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { ProviderRpcError, createAsseteraWalletProvider } from './chunk-QPNIGEP4.js';
|
|
2
|
+
export { CONNECT_PATH, MESSAGE_PREFIX, PROTOCOL_VERSION, RpcErrorCode, SUPPORTED_METHODS, connectUrl, isDisconnectMessage, isEventMessage, isReadyMessage, isRequestMessage, isResponseMessage, isSupportedMethod } from './chunk-N6D53D3G.js';
|
|
3
|
+
//# sourceMappingURL=index.js.map
|
|
4
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"index.js"}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// src/protocol.ts
|
|
4
|
+
var PROTOCOL_VERSION = 1;
|
|
5
|
+
var CONNECT_PATH = "/connect";
|
|
6
|
+
var MESSAGE_PREFIX = "assetera-wallet:";
|
|
7
|
+
var SUPPORTED_METHODS = [
|
|
8
|
+
"eth_requestAccounts",
|
|
9
|
+
"eth_accounts",
|
|
10
|
+
"eth_chainId",
|
|
11
|
+
"wallet_switchEthereumChain",
|
|
12
|
+
"personal_sign",
|
|
13
|
+
"eth_signTypedData_v4",
|
|
14
|
+
"eth_sendTransaction"
|
|
15
|
+
];
|
|
16
|
+
function isSupportedMethod(method) {
|
|
17
|
+
return SUPPORTED_METHODS.includes(method);
|
|
18
|
+
}
|
|
19
|
+
var RpcErrorCode = {
|
|
20
|
+
/** The client rejected the request in the pop-up. */
|
|
21
|
+
UserRejected: 4001,
|
|
22
|
+
/** Not connected yet (no `eth_requestAccounts` approved in this pop-up). */
|
|
23
|
+
Unauthorized: 4100,
|
|
24
|
+
/** The method is not in SUPPORTED_METHODS. */
|
|
25
|
+
UnsupportedMethod: 4200,
|
|
26
|
+
/** The pop-up closed, or the wallet session ended. */
|
|
27
|
+
Disconnected: 4900,
|
|
28
|
+
/** `wallet_switchEthereumChain` to a chain the wallet does not offer. */
|
|
29
|
+
UnrecognizedChain: 4902,
|
|
30
|
+
/** Malformed params. */
|
|
31
|
+
InvalidParams: -32602,
|
|
32
|
+
/** Anything unexpected inside the wallet. */
|
|
33
|
+
Internal: -32603
|
|
34
|
+
};
|
|
35
|
+
function isRecord(value) {
|
|
36
|
+
return typeof value === "object" && value !== null;
|
|
37
|
+
}
|
|
38
|
+
function hasType(value, suffix) {
|
|
39
|
+
return isRecord(value) && value.type === `${MESSAGE_PREFIX}${suffix}` && value.v === PROTOCOL_VERSION;
|
|
40
|
+
}
|
|
41
|
+
function isReadyMessage(value) {
|
|
42
|
+
return hasType(value, "ready");
|
|
43
|
+
}
|
|
44
|
+
function isResponseMessage(value) {
|
|
45
|
+
return hasType(value, "response") && typeof value.id === "string" && ("result" in value || isRecord(value.error) && typeof value.error.code === "number");
|
|
46
|
+
}
|
|
47
|
+
function isEventMessage(value) {
|
|
48
|
+
return hasType(value, "event") && (value.event === "accountsChanged" || value.event === "chainChanged" || value.event === "disconnect");
|
|
49
|
+
}
|
|
50
|
+
function isRequestMessage(value) {
|
|
51
|
+
return hasType(value, "request") && typeof value.id === "string" && typeof value.method === "string";
|
|
52
|
+
}
|
|
53
|
+
function isDisconnectMessage(value) {
|
|
54
|
+
return hasType(value, "disconnect");
|
|
55
|
+
}
|
|
56
|
+
function connectUrl(walletUrl, partnerOrigin) {
|
|
57
|
+
const url = new URL(CONNECT_PATH, walletUrl);
|
|
58
|
+
url.searchParams.set("origin", partnerOrigin);
|
|
59
|
+
url.searchParams.set("v", String(PROTOCOL_VERSION));
|
|
60
|
+
return url.toString();
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
exports.CONNECT_PATH = CONNECT_PATH;
|
|
64
|
+
exports.MESSAGE_PREFIX = MESSAGE_PREFIX;
|
|
65
|
+
exports.PROTOCOL_VERSION = PROTOCOL_VERSION;
|
|
66
|
+
exports.RpcErrorCode = RpcErrorCode;
|
|
67
|
+
exports.SUPPORTED_METHODS = SUPPORTED_METHODS;
|
|
68
|
+
exports.connectUrl = connectUrl;
|
|
69
|
+
exports.isDisconnectMessage = isDisconnectMessage;
|
|
70
|
+
exports.isEventMessage = isEventMessage;
|
|
71
|
+
exports.isReadyMessage = isReadyMessage;
|
|
72
|
+
exports.isRequestMessage = isRequestMessage;
|
|
73
|
+
exports.isResponseMessage = isResponseMessage;
|
|
74
|
+
exports.isSupportedMethod = isSupportedMethod;
|
|
75
|
+
//# sourceMappingURL=protocol.cjs.map
|
|
76
|
+
//# sourceMappingURL=protocol.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/protocol.ts"],"names":[],"mappings":";;;AAwBO,IAAM,gBAAA,GAAmB;AAGzB,IAAM,YAAA,GAAe;AAGrB,IAAM,cAAA,GAAiB;AAMvB,IAAM,iBAAA,GAAoB;AAAA,EAC/B,qBAAA;AAAA,EACA,cAAA;AAAA,EACA,aAAA;AAAA,EACA,4BAAA;AAAA,EACA,eAAA;AAAA,EACA,sBAAA;AAAA,EACA;AACF;AAIO,SAAS,kBAAkB,MAAA,EAA2C;AAC3E,EAAA,OAAQ,iBAAA,CAAwC,SAAS,MAAM,CAAA;AACjE;AAGO,IAAM,YAAA,GAAe;AAAA;AAAA,EAE1B,YAAA,EAAc,IAAA;AAAA;AAAA,EAEd,YAAA,EAAc,IAAA;AAAA;AAAA,EAEd,iBAAA,EAAmB,IAAA;AAAA;AAAA,EAEnB,YAAA,EAAc,IAAA;AAAA;AAAA,EAEd,iBAAA,EAAmB,IAAA;AAAA;AAAA,EAEnB,aAAA,EAAe,MAAA;AAAA;AAAA,EAEf,QAAA,EAAU;AACZ;AAqEA,SAAS,SAAS,KAAA,EAAkD;AAClE,EAAA,OAAO,OAAO,KAAA,KAAU,QAAA,IAAY,KAAA,KAAU,IAAA;AAChD;AAEA,SAAS,OAAA,CAAQ,OAAgB,MAAA,EAAkD;AACjF,EAAA,OAAO,QAAA,CAAS,KAAK,CAAA,IAAK,KAAA,CAAM,IAAA,KAAS,CAAA,EAAG,cAAc,CAAA,EAAG,MAAM,CAAA,CAAA,IAAM,KAAA,CAAM,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3/D4.\n *\n * This file is the CONTRACT. The connector in this package speaks the opener side; AsseteraWalletFront's\n * `/connect` page speaks the pop-up side and imports these types from `@asseteragmbh/wallet-connector/protocol`.\n * Change it only in a backwards-compatible way, or bump `PROTOCOL_VERSION` and support both on the wallet side:\n * partner sites upgrade on their own schedule.\n *\n * ## The handshake\n *\n * 1. The partner opens `${walletUrl}${CONNECT_PATH}?origin=<partner origin>&v=<version>` from a user click.\n * 2. The pop-up checks the claimed origin against its allowlist (D4). If listed, it posts `ready` to\n * `window.opener` with `targetOrigin` = that origin. The browser delivers it ONLY if the opener really is\n * that origin, so a page cannot claim someone else's origin and still hear the answer.\n * 3. The opener waits for `ready` from the wallet origin, then sends `request`s with `targetOrigin` = the wallet\n * origin. The pop-up accepts a message only when `event.origin` is the allowed origin from step 2 AND\n * `event.source === window.opener`, and answers with `targetOrigin` = that origin. Nothing else is accepted.\n *\n * ## Lifetime\n *\n * The pop-up stays open while the partner uses the wallet (ADR-0054, \"the wallet tab must stay open\"). When it is\n * closed, the opener sees `disconnect` (or notices `popup.closed`) and must reconnect from a user click.\n */\n\nexport const PROTOCOL_VERSION = 1 as const;\n\n/** The pop-up route on the wallet origin. */\nexport const CONNECT_PATH = \"/connect\";\n\n/** Every message carries this prefix in `type`, so both sides can ignore unrelated `postMessage` traffic. */\nexport const MESSAGE_PREFIX = \"assetera-wallet:\" as const;\n\n/**\n * The EIP-1193 methods the pop-up answers (ADR-0054 D3). Anything else is refused with 4200. Read-only chain\n * calls (`eth_call`, `eth_getBalance`, …) do not go through the pop-up; wagmi sends them to its own transports.\n */\nexport const SUPPORTED_METHODS = [\n \"eth_requestAccounts\",\n \"eth_accounts\",\n \"eth_chainId\",\n \"wallet_switchEthereumChain\",\n \"personal_sign\",\n \"eth_signTypedData_v4\",\n \"eth_sendTransaction\",\n] as const;\n\nexport type SupportedMethod = (typeof SUPPORTED_METHODS)[number];\n\nexport function isSupportedMethod(method: string): method is SupportedMethod {\n return (SUPPORTED_METHODS as readonly string[]).includes(method);\n}\n\n/** EIP-1193 / EIP-1474 error codes the pop-up uses. */\nexport const RpcErrorCode = {\n /** The client rejected the request in the pop-up. */\n UserRejected: 4001,\n /** Not connected yet (no `eth_requestAccounts` approved in this pop-up). */\n Unauthorized: 4100,\n /** The method is not in SUPPORTED_METHODS. */\n UnsupportedMethod: 4200,\n /** The pop-up closed, or the wallet session ended. */\n Disconnected: 4900,\n /** `wallet_switchEthereumChain` to a chain the wallet does not offer. */\n UnrecognizedChain: 4902,\n /** Malformed params. */\n InvalidParams: -32602,\n /** Anything unexpected inside the wallet. */\n Internal: -32603,\n} as const;\n\nexport type RpcErrorCode = (typeof RpcErrorCode)[keyof typeof RpcErrorCode];\n\nexport interface RpcError {\n code: number;\n message: string;\n data?: unknown;\n}\n\n// --- pop-up → opener ---------------------------------------------------------------------------------\n\n/** The pop-up is loaded and accepts requests from this opener. */\nexport interface ReadyMessage {\n type: `${typeof MESSAGE_PREFIX}ready`;\n v: typeof PROTOCOL_VERSION;\n /** Shown to the partner for diagnostics only; the partner must not rely on it for anything. */\n walletVersion?: string;\n}\n\n/** The answer to one `request`, matched by `id`. Exactly one of `result` / `error`. */\nexport type ResponseMessage =\n | { type: `${typeof MESSAGE_PREFIX}response`; v: typeof PROTOCOL_VERSION; id: string; result: unknown }\n | { type: `${typeof MESSAGE_PREFIX}response`; v: typeof PROTOCOL_VERSION; id: string; error: RpcError };\n\n/** EIP-1193 provider events, forwarded to the partner. */\nexport type EventMessage =\n | {\n type: `${typeof MESSAGE_PREFIX}event`;\n v: typeof PROTOCOL_VERSION;\n event: \"accountsChanged\";\n data: `0x${string}`[];\n }\n | {\n type: `${typeof MESSAGE_PREFIX}event`;\n v: typeof PROTOCOL_VERSION;\n event: \"chainChanged\";\n data: `0x${string}`;\n }\n | {\n type: `${typeof MESSAGE_PREFIX}event`;\n v: typeof PROTOCOL_VERSION;\n event: \"disconnect\";\n data: RpcError;\n };\n\nexport type WalletToPartnerMessage = ReadyMessage | ResponseMessage | EventMessage;\n\n// --- opener → pop-up ---------------------------------------------------------------------------------\n\nexport interface RequestMessage {\n type: `${typeof MESSAGE_PREFIX}request`;\n v: typeof PROTOCOL_VERSION;\n /** Unique per request within one connection; the response carries it back. */\n id: string;\n method: string;\n params?: unknown[] | Record<string, unknown>;\n}\n\n/** The partner disconnects (for example the user clicked \"Disconnect\" in the partner page). */\nexport interface DisconnectMessage {\n type: `${typeof MESSAGE_PREFIX}disconnect`;\n v: typeof PROTOCOL_VERSION;\n}\n\nexport type PartnerToWalletMessage = RequestMessage | DisconnectMessage;\n\n// --- guards ------------------------------------------------------------------------------------------\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n return typeof value === \"object\" && value !== null;\n}\n\nfunction hasType(value: unknown, suffix: string): value is Record<string, unknown> {\n return isRecord(value) && value.type === `${MESSAGE_PREFIX}${suffix}` && value.v === PROTOCOL_VERSION;\n}\n\nexport function isReadyMessage(value: unknown): value is ReadyMessage {\n return hasType(value, \"ready\");\n}\n\nexport function isResponseMessage(value: unknown): value is ResponseMessage {\n return (\n hasType(value, \"response\") &&\n typeof value.id === \"string\" &&\n (\"result\" in value || (isRecord(value.error) && typeof value.error.code === \"number\"))\n );\n}\n\nexport function isEventMessage(value: unknown): value is EventMessage {\n return (\n hasType(value, \"event\") &&\n (value.event === \"accountsChanged\" || value.event === \"chainChanged\" || value.event === \"disconnect\")\n );\n}\n\nexport function isRequestMessage(value: unknown): value is RequestMessage {\n return hasType(value, \"request\") && typeof value.id === \"string\" && typeof value.method === \"string\";\n}\n\nexport function isDisconnectMessage(value: unknown): value is DisconnectMessage {\n return hasType(value, \"disconnect\");\n}\n\n/** The URL the partner opens. `partnerOrigin` is `window.location.origin` of the partner page. */\nexport function connectUrl(walletUrl: string, partnerOrigin: string): string {\n const url = new URL(CONNECT_PATH, walletUrl);\n url.searchParams.set(\"origin\", partnerOrigin);\n url.searchParams.set(\"v\", String(PROTOCOL_VERSION));\n return url.toString();\n}\n"]}
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The pop-up protocol between a partner page (the opener) and the Assetera Wallet (the pop-up) — ADR-0054 D3/D4.
|
|
3
|
+
*
|
|
4
|
+
* This file is the CONTRACT. The connector in this package speaks the opener side; AsseteraWalletFront's
|
|
5
|
+
* `/connect` page speaks the pop-up side and imports these types from `@asseteragmbh/wallet-connector/protocol`.
|
|
6
|
+
* Change it only in a backwards-compatible way, or bump `PROTOCOL_VERSION` and support both on the wallet side:
|
|
7
|
+
* partner sites upgrade on their own schedule.
|
|
8
|
+
*
|
|
9
|
+
* ## The handshake
|
|
10
|
+
*
|
|
11
|
+
* 1. The partner opens `${walletUrl}${CONNECT_PATH}?origin=<partner origin>&v=<version>` from a user click.
|
|
12
|
+
* 2. The pop-up checks the claimed origin against its allowlist (D4). If listed, it posts `ready` to
|
|
13
|
+
* `window.opener` with `targetOrigin` = that origin. The browser delivers it ONLY if the opener really is
|
|
14
|
+
* that origin, so a page cannot claim someone else's origin and still hear the answer.
|
|
15
|
+
* 3. The opener waits for `ready` from the wallet origin, then sends `request`s with `targetOrigin` = the wallet
|
|
16
|
+
* origin. The pop-up accepts a message only when `event.origin` is the allowed origin from step 2 AND
|
|
17
|
+
* `event.source === window.opener`, and answers with `targetOrigin` = that origin. Nothing else is accepted.
|
|
18
|
+
*
|
|
19
|
+
* ## Lifetime
|
|
20
|
+
*
|
|
21
|
+
* The pop-up stays open while the partner uses the wallet (ADR-0054, "the wallet tab must stay open"). When it is
|
|
22
|
+
* closed, the opener sees `disconnect` (or notices `popup.closed`) and must reconnect from a user click.
|
|
23
|
+
*/
|
|
24
|
+
declare const PROTOCOL_VERSION: 1;
|
|
25
|
+
/** The pop-up route on the wallet origin. */
|
|
26
|
+
declare const CONNECT_PATH = "/connect";
|
|
27
|
+
/** Every message carries this prefix in `type`, so both sides can ignore unrelated `postMessage` traffic. */
|
|
28
|
+
declare const MESSAGE_PREFIX: "assetera-wallet:";
|
|
29
|
+
/**
|
|
30
|
+
* The EIP-1193 methods the pop-up answers (ADR-0054 D3). Anything else is refused with 4200. Read-only chain
|
|
31
|
+
* calls (`eth_call`, `eth_getBalance`, …) do not go through the pop-up; wagmi sends them to its own transports.
|
|
32
|
+
*/
|
|
33
|
+
declare const SUPPORTED_METHODS: readonly ["eth_requestAccounts", "eth_accounts", "eth_chainId", "wallet_switchEthereumChain", "personal_sign", "eth_signTypedData_v4", "eth_sendTransaction"];
|
|
34
|
+
type SupportedMethod = (typeof SUPPORTED_METHODS)[number];
|
|
35
|
+
declare function isSupportedMethod(method: string): method is SupportedMethod;
|
|
36
|
+
/** EIP-1193 / EIP-1474 error codes the pop-up uses. */
|
|
37
|
+
declare const RpcErrorCode: {
|
|
38
|
+
/** The client rejected the request in the pop-up. */
|
|
39
|
+
readonly UserRejected: 4001;
|
|
40
|
+
/** Not connected yet (no `eth_requestAccounts` approved in this pop-up). */
|
|
41
|
+
readonly Unauthorized: 4100;
|
|
42
|
+
/** The method is not in SUPPORTED_METHODS. */
|
|
43
|
+
readonly UnsupportedMethod: 4200;
|
|
44
|
+
/** The pop-up closed, or the wallet session ended. */
|
|
45
|
+
readonly Disconnected: 4900;
|
|
46
|
+
/** `wallet_switchEthereumChain` to a chain the wallet does not offer. */
|
|
47
|
+
readonly UnrecognizedChain: 4902;
|
|
48
|
+
/** Malformed params. */
|
|
49
|
+
readonly InvalidParams: -32602;
|
|
50
|
+
/** Anything unexpected inside the wallet. */
|
|
51
|
+
readonly Internal: -32603;
|
|
52
|
+
};
|
|
53
|
+
type RpcErrorCode = (typeof RpcErrorCode)[keyof typeof RpcErrorCode];
|
|
54
|
+
interface RpcError {
|
|
55
|
+
code: number;
|
|
56
|
+
message: string;
|
|
57
|
+
data?: unknown;
|
|
58
|
+
}
|
|
59
|
+
/** The pop-up is loaded and accepts requests from this opener. */
|
|
60
|
+
interface ReadyMessage {
|
|
61
|
+
type: `${typeof MESSAGE_PREFIX}ready`;
|
|
62
|
+
v: typeof PROTOCOL_VERSION;
|
|
63
|
+
/** Shown to the partner for diagnostics only; the partner must not rely on it for anything. */
|
|
64
|
+
walletVersion?: string;
|
|
65
|
+
}
|
|
66
|
+
/** The answer to one `request`, matched by `id`. Exactly one of `result` / `error`. */
|
|
67
|
+
type ResponseMessage = {
|
|
68
|
+
type: `${typeof MESSAGE_PREFIX}response`;
|
|
69
|
+
v: typeof PROTOCOL_VERSION;
|
|
70
|
+
id: string;
|
|
71
|
+
result: unknown;
|
|
72
|
+
} | {
|
|
73
|
+
type: `${typeof MESSAGE_PREFIX}response`;
|
|
74
|
+
v: typeof PROTOCOL_VERSION;
|
|
75
|
+
id: string;
|
|
76
|
+
error: RpcError;
|
|
77
|
+
};
|
|
78
|
+
/** EIP-1193 provider events, forwarded to the partner. */
|
|
79
|
+
type EventMessage = {
|
|
80
|
+
type: `${typeof MESSAGE_PREFIX}event`;
|
|
81
|
+
v: typeof PROTOCOL_VERSION;
|
|
82
|
+
event: "accountsChanged";
|
|
83
|
+
data: `0x${string}`[];
|
|
84
|
+
} | {
|
|
85
|
+
type: `${typeof MESSAGE_PREFIX}event`;
|
|
86
|
+
v: typeof PROTOCOL_VERSION;
|
|
87
|
+
event: "chainChanged";
|
|
88
|
+
data: `0x${string}`;
|
|
89
|
+
} | {
|
|
90
|
+
type: `${typeof MESSAGE_PREFIX}event`;
|
|
91
|
+
v: typeof PROTOCOL_VERSION;
|
|
92
|
+
event: "disconnect";
|
|
93
|
+
data: RpcError;
|
|
94
|
+
};
|
|
95
|
+
type WalletToPartnerMessage = ReadyMessage | ResponseMessage | EventMessage;
|
|
96
|
+
interface RequestMessage {
|
|
97
|
+
type: `${typeof MESSAGE_PREFIX}request`;
|
|
98
|
+
v: typeof PROTOCOL_VERSION;
|
|
99
|
+
/** Unique per request within one connection; the response carries it back. */
|
|
100
|
+
id: string;
|
|
101
|
+
method: string;
|
|
102
|
+
params?: unknown[] | Record<string, unknown>;
|
|
103
|
+
}
|
|
104
|
+
/** The partner disconnects (for example the user clicked "Disconnect" in the partner page). */
|
|
105
|
+
interface DisconnectMessage {
|
|
106
|
+
type: `${typeof MESSAGE_PREFIX}disconnect`;
|
|
107
|
+
v: typeof PROTOCOL_VERSION;
|
|
108
|
+
}
|
|
109
|
+
type PartnerToWalletMessage = RequestMessage | DisconnectMessage;
|
|
110
|
+
declare function isReadyMessage(value: unknown): value is ReadyMessage;
|
|
111
|
+
declare function isResponseMessage(value: unknown): value is ResponseMessage;
|
|
112
|
+
declare function isEventMessage(value: unknown): value is EventMessage;
|
|
113
|
+
declare function isRequestMessage(value: unknown): value is RequestMessage;
|
|
114
|
+
declare function isDisconnectMessage(value: unknown): value is DisconnectMessage;
|
|
115
|
+
/** The URL the partner opens. `partnerOrigin` is `window.location.origin` of the partner page. */
|
|
116
|
+
declare function connectUrl(walletUrl: string, partnerOrigin: string): string;
|
|
117
|
+
|
|
118
|
+
export { CONNECT_PATH, type DisconnectMessage, type EventMessage, MESSAGE_PREFIX, PROTOCOL_VERSION, type PartnerToWalletMessage, type ReadyMessage, type RequestMessage, type ResponseMessage, type RpcError, RpcErrorCode, SUPPORTED_METHODS, type SupportedMethod, type WalletToPartnerMessage, connectUrl, isDisconnectMessage, isEventMessage, isReadyMessage, isRequestMessage, isResponseMessage, isSupportedMethod };
|